From 71bca532c568106a25a16154d83a5819ad314592 Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Sat, 29 Mar 2025 13:01:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20entry.S=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E4=B8=80=E4=BA=9B=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- startup/riscv3/src/entry.S | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/startup/riscv3/src/entry.S b/startup/riscv3/src/entry.S index 46d1a23..653868a 100755 --- a/startup/riscv3/src/entry.S +++ b/startup/riscv3/src/entry.S @@ -218,9 +218,12 @@ interrupt: .global entry_mip .global entry_mcause + +// cpu产生异常时会自动进入这个入口 trap_entry: /* Interrupt trap */ + // 把t0的值暂时保存到临时寄存器中 csrw mscratch, t0 /* 保存mcause && mip 到pmpaddr中 */ csrr t0, mcause @@ -228,11 +231,15 @@ trap_entry: csrr t0, mip csrw pmpaddr15, t0 + // 在线程栈中直接处理中断 andi t0, t0, -1912 // -1912 = 0x888 + // bnez不会更新返回地址 jal x1 会把返回地址更新到ra bnez t0, interrupt /* System call and other traps */ + // 把mscratch的值拷贝到t0中 然后把sp的值写入到mscratch csrrw t0, mscratch, sp + // 切到异常处理栈 la sp, _trap_sp #ifndef __riscv_float_abi_soft addi sp, sp, -REGBYTES*64