arch: riscv: use string array instead of switch statement for cause

Get rid of the switch statement and use an string array
for the cause instead. This saves about ~600 bytes.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
Yong Cong Sin 2024-09-05 12:57:43 +08:00 committed by Johan Hedberg
commit 5365421fa1

View file

@ -54,38 +54,27 @@ uintptr_t z_riscv_get_sp_before_exc(const struct arch_esf *esf)
const char *z_riscv_mcause_str(unsigned long cause) const char *z_riscv_mcause_str(unsigned long cause)
{ {
switch (cause) { static const char *const mcause_str[17] = {
case 0: [0] = "Instruction address misaligned",
return "Instruction address misaligned"; [1] = "Instruction Access fault",
case 1: [2] = "Illegal instruction",
return "Instruction Access fault"; [3] = "Breakpoint",
case 2: [4] = "Load address misaligned",
return "Illegal instruction"; [5] = "Load access fault",
case 3: [6] = "Store/AMO address misaligned",
return "Breakpoint"; [7] = "Store/AMO access fault",
case 4: [8] = "Environment call from U-mode",
return "Load address misaligned"; [9] = "Environment call from S-mode",
case 5: [10] = "unknown",
return "Load access fault"; [11] = "Environment call from M-mode",
case 6: [12] = "Instruction page fault",
return "Store/AMO address misaligned"; [13] = "Load page fault",
case 7: [14] = "unknown",
return "Store/AMO access fault"; [15] = "Store/AMO page fault",
case 8: [16] = "unknown",
return "Environment call from U-mode"; };
case 9:
return "Environment call from S-mode"; return mcause_str[MIN(cause, ARRAY_SIZE(mcause_str) - 1)];
case 11:
return "Environment call from M-mode";
case 12:
return "Instruction page fault";
case 13:
return "Load page fault";
case 15:
return "Store/AMO page fault";
default:
return "unknown";
}
} }
FUNC_NORETURN void z_riscv_fatal_error(unsigned int reason, FUNC_NORETURN void z_riscv_fatal_error(unsigned int reason,