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