[arch][riscv] more interrupt cause debugging strings
#define LOCAL_TRACE 0
static const char *cause_to_string(long cause) {
+ if (cause >= 0) {
switch (cause) {
case RISCV_EXCEPTION_IADDR_MISALIGN:
return "Instruction address misaligned";
@@ -46,7 +47,30 @@ static const char *cause_to_string(long cause) {
case RISCV_EXCEPTION_STORE_PAGE_FAULT:
return "Store/AMO page fault";
}
- return "Unknown";
+ return "Unknown exception";
+ } else {
+ switch (cause & LONG_MAX) {
+ case RISCV_INTERRUPT_USWI:
+ return "User software interrupt";
+ case RISCV_INTERRUPT_SSWI:
+ return "Supervisor software interrupt";
+ case RISCV_INTERRUPT_MSWI:
+ return "Machine software interrupt";
+ case RISCV_INTERRUPT_UTIM:
+ return "User timer interrupt";
+ case RISCV_INTERRUPT_STIM:
+ return "Supervisor timer interrupt";
+ case RISCV_INTERRUPT_MTIM:
+ return "Machine timer interrupt";
+ case RISCV_INTERRUPT_UEXT:
+ return "User external interrupt";
+ case RISCV_INTERRUPT_SEXT:
+ return "Supervisor external interrupt";
+ case RISCV_INTERRUPT_MEXT:
+ return "Machine external interrupt";
+ }
+ return "Unknown interrupt";
+ }
}
static void dump_iframe(struct riscv_short_iframe *frame, bool kernel) {
@@ -62,8 +86,8 @@ static void dump_iframe(struct riscv_short_iframe *frame, bool kernel) {
__NO_RETURN __NO_INLINE
static void fatal_exception(long cause, ulong epc, struct riscv_short_iframe *frame, bool kernel) {
if (cause < 0) {
- printf("unhandled interrupt cause %#lx, epc %#lx, tval %#lx\n", cause, epc,
- riscv_csr_read(RISCV_CSR_XTVAL));
+ printf("unhandled interrupt cause %#lx (%s), epc %#lx, tval %#lx\n", cause,
+ cause_to_string(cause), epc, riscv_csr_read(RISCV_CSR_XTVAL));
} else {
printf("unhandled exception cause %#lx (%s), epc %#lx, tval %#lx\n", cause,
cause_to_string(cause), epc, riscv_csr_read(RISCV_CSR_XTVAL));
