diff --git a/Kernel/Arch/riscv64/Processor.cpp b/Kernel/Arch/riscv64/Processor.cpp index dd24dff145..4ed0895ad3 100644 --- a/Kernel/Arch/riscv64/Processor.cpp +++ b/Kernel/Arch/riscv64/Processor.cpp @@ -276,6 +276,12 @@ ErrorOr> ProcessorBase::capture_stack_trace(Thread&, size return Vector {}; } +extern "C" void context_first_init(Thread* from_thread, Thread* to_thread); +extern "C" void context_first_init(Thread* from_thread, Thread* to_thread) +{ + do_context_first_init(from_thread, to_thread); +} + extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread); extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread) { @@ -304,9 +310,16 @@ extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread) load_fpu_state(&to_thread->fpu_state()); } -NAKED void thread_context_first_enter(void) +NAKED void thread_context_first_enter() { - asm("unimp"); + asm( + "ld a0, 0(sp) \n" + "ld a1, 8(sp) \n" + "addi sp, sp, 32 \n" + "call context_first_init \n" + "mv a0, sp \n" + "call exit_trap \n" + "tail restore_context_and_sret \n"); } NAKED void do_assume_context(Thread*, u32) diff --git a/Kernel/Arch/riscv64/trap_handler.S b/Kernel/Arch/riscv64/trap_handler.S index edee17fb51..87cc226da4 100644 --- a/Kernel/Arch/riscv64/trap_handler.S +++ b/Kernel/Arch/riscv64/trap_handler.S @@ -90,6 +90,9 @@ asm_trap_handler: call trap_handler +.global restore_context_and_sret +restore_context_and_sret: + // Remove TrapFrame from the stack addi sp, sp, 16 @@ -131,7 +134,5 @@ asm_trap_handler: ld x30, 29*8(sp) ld x31, 30*8(sp) - ld x2, 1*8(sp) - addi sp, sp, REGISTER_STATE_SIZE sret