summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNick Kossifidis <mickflemm@gmail.com>2019-04-16 20:21:55 +0300
committerAnup Patel <anup@brainfault.org>2019-04-22 07:26:20 +0300
commit804b997ed415001097803e4b537fd63d043874b9 (patch)
treebe9c303a14d96cac2564b8c25e11e35c1e607efd /lib
parent194dbbe5a13dff2255411c26d249f3ad4ef42c0b (diff)
downloadopensbi-804b997ed415001097803e4b537fd63d043874b9.tar.xz
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/sbi_trap.c3
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;
};