diff options
author | Nick Kossifidis <mickflemm@gmail.com> | 2019-04-16 20:21:55 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2019-04-22 09:56:20 +0530 |
commit | 804b997ed415001097803e4b537fd63d043874b9 (patch) | |
tree | be9c303a14d96cac2564b8c25e11e35c1e607efd | |
parent | 194dbbe5a13dff2255411c26d249f3ad4ef42c0b (diff) |
lib: Redirect unhandled traps from non-M modes to S mode
In case we didn't handle a trap with one of the available
handlers, check if the trap comes from S or U mode and
redirect it to S mode's trap handler.
Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>
-rw-r--r-- | lib/sbi_trap.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/sbi_trap.c b/lib/sbi_trap.c index ea5ba6b..a8c9b36 100644 --- a/lib/sbi_trap.c +++ b/lib/sbi_trap.c @@ -142,6 +142,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, const char *msg = "trap handler failed"; u32 hartid = sbi_current_hartid(); ulong mcause = csr_read(CSR_MCAUSE); + ulong mtval = csr_read(CSR_MTVAL); if (mcause & (1UL << (__riscv_xlen - 1))) { mcause &= ~(1UL << (__riscv_xlen - 1)); @@ -178,6 +179,8 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, msg = "ecall handler failed"; break; default: + /* If the trap came from S or U mode, redirect it there */ + rc = sbi_trap_redirect(regs, scratch, regs->mepc, mcause, mtval); break; }; |