From e7314f76d9edfbee2f676fad90ae6a727403263f Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Wed, 13 May 2026 16:22:01 +0800 Subject: feat: add ret_from_fork trampoline for newly forked processes --- na/arch/riscv/trap/swtch.S | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'na') diff --git a/na/arch/riscv/trap/swtch.S b/na/arch/riscv/trap/swtch.S index 8be7904..dbae43d 100644 --- a/na/arch/riscv/trap/swtch.S +++ b/na/arch/riscv/trap/swtch.S @@ -76,4 +76,21 @@ kthread_entry_trampoline: /* kthread_entry should never return, but if it does: */ wfi - j kthread_entry_trampoline + 12 /* loop on wfi */ \ No newline at end of file + j kthread_entry_trampoline + 12 /* loop on wfi */ + +/* ======================================================================== + * ret_from_fork + * + * Trampoline for newly forked processes. + * Context is set up by fork() so that s0 contains the TrapFrame pointer. + * + * Calls the MI-layer C++ function: + * void fork_child_entry(TrapFrame* tf); + * ======================================================================== */ + .globl ret_from_fork + .align 2 +ret_from_fork: + mv a0, s0 /* a0 = TrapFrame pointer */ + call fork_child_entry /* does not return, eventually calls userret */ + wfi + j ret_from_fork + 8 \ No newline at end of file -- cgit v1.2.3