Replace the switch statement with a static lookup table. With '-d int', unlisted exception codes are now logged as "unknown" instead of "???".
Suggested-by: Pierrick Bouvier <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Pierrick Bouvier <[email protected]> --- target/sh4/helper.c | 66 ++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/target/sh4/helper.c b/target/sh4/helper.c index 5856bab6983..96465dd94fb 100644 --- a/target/sh4/helper.c +++ b/target/sh4/helper.c @@ -18,6 +18,7 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "cpu.h" #include "exec/cputlb.h" @@ -49,54 +50,27 @@ const char *sh4_exception_name(int excp) { - const char *name; + /* Exception codes (EXPEVT) are multiples of 0x20 */ + static const char * const excp_names[] = { + [SH4_EXCP_ADDR_ERROR >> 5] = "addr_error", + [SH4_EXCP_TLB_MISS >> 5] = "tlb_miss", + [SH4_EXCP_TLB_VIOLATION >> 5] = "tlb_violation", + [SH4_EXCP_ILLEGAL_INSTRUCTION >> 5] = "illegal_instruction", + [SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION >> 5] = "slot_illegal_instruction", + [SH4_EXCP_FPU_DISABLE >> 5] = "fpu_disable", + [SH4_EXCP_SLOT_FPU_DISABLE >> 5] = "slot_fpu", + [SH4_EXCP_DATA_WRITE >> 5] = "data_write", + [SH4_EXCP_DTLB_MISS_WRITE >> 5] = "dtlb_miss_write", + [SH4_EXCP_DTLB_VIOLATION_WRITE >> 5] = "dtlb_violation_write", + [SH4_EXCP_FPU >> 5] = "fpu_exception", + [SH4_EXCP_INITIAL_PAGE_WRITE >> 5] = "initial_page_write", + [SH4_EXCP_TRAPA >> 5] = "trapa", + }; - switch (excp) { - case SH4_EXCP_ADDR_ERROR: - name = "addr_error"; - break; - case SH4_EXCP_TLB_MISS: - name = "tlb_miss"; - break; - case SH4_EXCP_TLB_VIOLATION: - name = "tlb_violation"; - break; - case SH4_EXCP_ILLEGAL_INSTRUCTION: - name = "illegal_instruction"; - break; - case SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION: - name = "slot_illegal_instruction"; - break; - case SH4_EXCP_FPU_DISABLE: - name = "fpu_disable"; - break; - case SH4_EXCP_SLOT_FPU_DISABLE: - name = "slot_fpu"; - break; - case SH4_EXCP_DATA_WRITE: - name = "data_write"; - break; - case SH4_EXCP_DTLB_MISS_WRITE: - name = "dtlb_miss_write"; - break; - case SH4_EXCP_DTLB_VIOLATION_WRITE: - name = "dtlb_violation_write"; - break; - case SH4_EXCP_FPU: - name = "fpu_exception"; - break; - case SH4_EXCP_INITIAL_PAGE_WRITE: - name = "initial_page_write"; - break; - case SH4_EXCP_TRAPA: - name = "trapa"; - break; - default: - name = "???"; - break; + if (excp & 0x1f) { + return "unknown"; } - - return name; + return STR_ARRAY_ELEM_OR_NULL(excp_names, excp >> 5) ?: "unknown"; } #if defined(CONFIG_USER_ONLY) -- 2.55.0
