From 44a73ecab6e91519627786a5101cd4f1a2f2b0d7 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 30 Oct 2024 00:57:33 +0200 Subject: most of the way to passing tests --- arch/riscv64/kernel/entry.S | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'arch/riscv64/kernel/entry.S') diff --git a/arch/riscv64/kernel/entry.S b/arch/riscv64/kernel/entry.S index 0bc999e..f894e0d 100644 --- a/arch/riscv64/kernel/entry.S +++ b/arch/riscv64/kernel/entry.S @@ -62,6 +62,7 @@ handle_trap: bnez tp, continue_trap /* the trap came from the kernel, should never happen so just panic * and abort or whatever */ + csrw CSR_SSCRATCH, x0 csrr a0, CSR_SEPC csrr a1, CSR_STVAL csrr a2, CSR_SCAUSE @@ -92,8 +93,16 @@ continue_trap: save_caller mv a0, s10 + /* get actual kernel stack into sp */ + mv sp, tp call riscv_handle_interrupt + lr sp, offsetof_regs(tp) + addi sp, sp, -sizeof_registers + /* set execution continuation */ + lr s10, offsetof_exec(tp) + csrw CSR_SEPC, s10 + j _load_context handle_exception: @@ -108,7 +117,14 @@ handle_exception: csrr a0, CSR_SEPC csrr a1, CSR_STVAL csrr a2, CSR_SCAUSE - call unhandled_panic + mv sp, tp + call riscv_handle_exception + + lr sp, offsetof_regs(tp) + addi sp, sp, -sizeof_registers + /* set execution continuation */ + lr s10, offsetof_exec(tp) + csrw CSR_SEPC, s10 j _load_context @@ -129,6 +145,7 @@ fast_dispatch: csrr s10, CSR_SEPC sr s10, offsetof_exec(tp) /* jump to C */ + mv sp, tp call dispatch /* if we had a thread switch, load kernel stack of current thread and * restore its context */ -- cgit v1.3