Jonathan Neuschäfer (j.neuschaefer@gmx.net) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16016
-gerrit
commit 9bd8814c73599b25f027b6a955dd3a330ff20148 Author: Jonathan Neuschäfer j.neuschaefer@gmx.net Date: Mon Aug 1 19:42:27 2016 +0200
[WIP] arch/riscv: Better trap handling diagnostics
WIP: By now I should probably move the diagnistic prints into a function.
Change-Id: I57032f958c88ea83a420e93b459df4f620799d84 Signed-off-by: Jonathan Neuschäfer j.neuschaefer@gmx.net --- src/arch/riscv/trap_handler.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/src/arch/riscv/trap_handler.c b/src/arch/riscv/trap_handler.c index 193be61..afb02de 100644 --- a/src/arch/riscv/trap_handler.c +++ b/src/arch/riscv/trap_handler.c @@ -84,11 +84,24 @@ void handle_supervisor_call(trapframe *tf) { asm volatile("j supervisor_call_return"); }
+static const char *mstatus_to_previous_mode(uintptr_t ms) +{ + switch (ms & MSTATUS_MPP) { + case 0x00000000: return "user"; + case 0x00000800: return "supervisor"; + case 0x00001000: return "hypervisor"; + case 0x00001800: return "machine"; + } + + return "unknown"; +} + void trap_handler(trapframe *tf) { write_csr(mscratch, tf); uintptr_t cause; void *epc; void *badAddr; + const char *previous_mode;
// extract cause asm("csrr %0, mcause" : "=r"(cause)); @@ -99,6 +112,8 @@ void trap_handler(trapframe *tf) { // extract bad address asm("csrr %0, mbadaddr" : "=r"(badAddr));
+ previous_mode = mstatus_to_previous_mode(read_csr(mstatus)); + switch(cause) { case 0: printk(BIOS_DEBUG, "Trap: Instruction address misaligned\n"); @@ -107,23 +122,28 @@ void trap_handler(trapframe *tf) { printk(BIOS_DEBUG, "Trap: Instruction access fault\n"); printk(BIOS_DEBUG, "Bad instruction pc: %p\n", epc); printk(BIOS_DEBUG, "Address: %p\n", badAddr); + printk(BIOS_DEBUG, "Previous mode: %s\n", previous_mode); break; case 2: printk(BIOS_DEBUG, "Trap: Illegal instruction\n"); printk(BIOS_DEBUG, "Bad instruction pc: %p\n", epc); printk(BIOS_DEBUG, "Address: %p\n", badAddr); + printk(BIOS_DEBUG, "Previous mode: %s\n", previous_mode); break; case 3: printk(BIOS_DEBUG, "Trap: Breakpoint\n"); + printk(BIOS_DEBUG, "Bad instruction pc: %p\n", epc); break; case 4: printk(BIOS_DEBUG, "Trap: Load address misaligned\n"); + printk(BIOS_DEBUG, "Previous mode: %s\n", previous_mode); handle_misaligned_load(tf); break; case 5: printk(BIOS_DEBUG, "Trap: Load access fault\n"); printk(BIOS_DEBUG, "Bad instruction pc: %p\n", epc); printk(BIOS_DEBUG, "Load Address: %p\n", badAddr); + printk(BIOS_DEBUG, "Previous mode: %s\n", previous_mode); break; case 6: printk(BIOS_DEBUG, "Trap: Store address misaligned\n"); @@ -135,6 +155,7 @@ void trap_handler(trapframe *tf) { printk(BIOS_DEBUG, "Trap: Store access fault\n"); printk(BIOS_DEBUG, "Bad instruction pc: %p\n", epc); printk(BIOS_DEBUG, "Store Address: %p\n", badAddr); + printk(BIOS_DEBUG, "Previous mode: %s\n", previous_mode); break; case 8: printk(BIOS_DEBUG, "Trap: Environment call from U-mode\n");