@samitouri / QOSamiQemu / commits / 23fe1e5813

target/riscv: Initialize riscv_excp_names[] and riscv_intr_names[] using designated initializer

Use designated initializers to initialize riscv_excp_names[] and riscv_intr_names[] so that we don't have to explicitly add "reserved" items. Also, add the missing trap names: sw_check, hw_error, virt_illegal_instruction, semihost, s_guest_external, and counter_overflow. Signed-off-by: Frank Chang <frank.chang@sifive.com> Reviewed-by: Max Chou <max.chou@sifive.com> Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com> Reviewed-by: Nutty Liu <nutty.liu@hotmail.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20260421071107.2848439-1-frank.chang@sifive.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Frank Chang committed Apr 21, 2026 at 15:11 UTC 23fe1e581311d9eaba12621c7eec25d631b5560e
1 file changed +45 -44
target/riscv/cpu.c
+45 -44
@@ -328,60 +328,61 @@ const char * const riscv_rvv_regnames[] = {
328 };
329
330 static const char * const riscv_excp_names[] = {
331 - "misaligned_fetch",
332 - "fault_fetch",
333 - "illegal_instruction",
334 - "breakpoint",
335 - "misaligned_load",
336 - "fault_load",
337 - "misaligned_store",
338 - "fault_store",
339 - "user_ecall",
340 - "supervisor_ecall",
341 - "hypervisor_ecall",
342 - "machine_ecall",
343 - "exec_page_fault",
344 - "load_page_fault",
345 - "reserved",
346 - "store_page_fault",
347 - "double_trap",
348 - "reserved",
349 - "reserved",
350 - "reserved",
351 - "guest_exec_page_fault",
352 - "guest_load_page_fault",
353 - "reserved",
354 - "guest_store_page_fault",
331 + [RISCV_EXCP_INST_ADDR_MIS] = "misaligned_fetch",
332 + [RISCV_EXCP_INST_ACCESS_FAULT] = "fault_fetch",
333 + [RISCV_EXCP_ILLEGAL_INST] = "illegal_instruction",
334 + [RISCV_EXCP_BREAKPOINT] = "breakpoint",
335 + [RISCV_EXCP_LOAD_ADDR_MIS] = "misaligned_load",
336 + [RISCV_EXCP_LOAD_ACCESS_FAULT] = "fault_load",
337 + [RISCV_EXCP_STORE_AMO_ADDR_MIS] = "misaligned_store",
338 + [RISCV_EXCP_STORE_AMO_ACCESS_FAULT] = "fault_store",
339 + [RISCV_EXCP_U_ECALL] = "user_ecall",
340 + [RISCV_EXCP_S_ECALL] = "supervisor_ecall",
341 + [RISCV_EXCP_VS_ECALL] = "hypervisor_ecall",
342 + [RISCV_EXCP_M_ECALL] = "machine_ecall",
343 + [RISCV_EXCP_INST_PAGE_FAULT] = "exec_page_fault",
344 + [RISCV_EXCP_LOAD_PAGE_FAULT] = "load_page_fault",
345 + [RISCV_EXCP_STORE_PAGE_FAULT] = "store_page_fault",
346 + [RISCV_EXCP_DOUBLE_TRAP] = "double_trap",
347 + [RISCV_EXCP_SW_CHECK] = "sw_check",
348 + [RISCV_EXCP_HW_ERR] = "hw_error",
349 + [RISCV_EXCP_INST_GUEST_PAGE_FAULT] = "guest_exec_page_fault",
350 + [RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT] = "guest_load_page_fault",
351 + [RISCV_EXCP_VIRT_INSTRUCTION_FAULT] = "virt_illegal_instruction",
352 + [RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT] = "guest_store_page_fault",
353 + [RISCV_EXCP_SEMIHOST] = "semihost",
354 };
355
356 static const char * const riscv_intr_names[] = {
358 - "u_software",
359 - "s_software",
360 - "vs_software",
361 - "m_software",
362 - "u_timer",
363 - "s_timer",
364 - "vs_timer",
365 - "m_timer",
366 - "u_external",
367 - "s_external",
368 - "vs_external",
369 - "m_external",
370 - "reserved",
371 - "reserved",
372 - "reserved",
373 - "reserved"
357 + [IRQ_U_SOFT] = "u_software",
358 + [IRQ_S_SOFT] = "s_software",
359 + [IRQ_VS_SOFT] = "vs_software",
360 + [IRQ_M_SOFT] = "m_software",
361 + [IRQ_U_TIMER] = "u_timer",
362 + [IRQ_S_TIMER] = "s_timer",
363 + [IRQ_VS_TIMER] = "vs_timer",
364 + [IRQ_M_TIMER] = "m_timer",
365 + [IRQ_U_EXT] = "u_external",
366 + [IRQ_S_EXT] = "s_external",
367 + [IRQ_VS_EXT] = "vs_external",
368 + [IRQ_M_EXT] = "m_external",
369 + [IRQ_S_GEXT] = "s_guest_external",
370 + [IRQ_PMU_OVF] = "counter_overflow",
371 };
372
373 const char *riscv_cpu_get_trap_name(target_ulong cause, bool async)
374 {
375 if (async) {
379 - return (cause < ARRAY_SIZE(riscv_intr_names)) ?
380 - riscv_intr_names[cause] : "(unknown)";
376 + if ((cause < ARRAY_SIZE(riscv_intr_names)) && riscv_intr_names[cause]) {
377 + return riscv_intr_names[cause];
378 + }
379 } else {
382 - return (cause < ARRAY_SIZE(riscv_excp_names)) ?
383 - riscv_excp_names[cause] : "(unknown)";
380 + if ((cause < ARRAY_SIZE(riscv_excp_names)) && riscv_excp_names[cause]) {
381 + return riscv_excp_names[cause];
382 + }
383 }
384 +
385 + return "(unknown)";
386 }
387
388 void riscv_cpu_set_misa_ext(CPURISCVState *env, uint32_t ext)