cpus: Add common CPUClass::exception_name() handler
v3 cover cpus: Add common CPUClass::exception_name() handler
Missing review: 1 (new), 2 (rewrite)
v3:
- Add STR_ARRAY_ELEM_OR_NULL() suggested by Pierrick
v2:
- Addressed Pierrick suggestions
- No change addressed wrt logging-prefix (patch 2) because not needed so far.
Add qemu_excp_name() to resolve QEMU internal exception values.
Add a common CPUClass::exception_name() callback so the generic exception logger can resolve architecture-specific exception values to human-readable names.
Re-use existing methods (expose prototype or refactor) when available otherwise implement new ones (AVR, X86, MicroBlaze, S390x, TriCore and Xtensa).
This series is the base for consolidating exception management in accel/tcg/ (more series to be posted on top).
Philippe Mathieu-Daudé (31):
qemu/osdep: Document ARRAY_SIZE() macro rejects pointers util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
cpus: Add helper to log raised exceptions with '-d int'
cpus: Introduce CPUClass::exception_name() handler target/alpha: Register CPUClass::exception_name() handler target/alpha: Use a static table in alpha_exception_name() target/arm: Register CPUClass::exception_name() handler target/avr: Implement and register CPUClass::exception_name() target/hexagon: Register CPUClass::exception_name() handler target/hppa: Register CPUClass::exception_name() handler target/i386: Replace magic value by proper EXCP0E_PAGE definition target/i386: Implement and register CPUClass::exception_name() target/loongarch: Register CPUClass::exception_name() handler target/m68k: Register CPUClass::exception_name() handler target/m68k: Use a static table in m68k_exception_name() target/microblaze: Implement and register CPUClass::exception_name() target/mips: Remove EXCP_LAST, use ARRAY_SIZE(excp_names) target/mips: Register CPUClass::exception_name() handler target/or1k: Register CPUClass::exception_name() handler target/ppc: Name the EBB exceptions
target/ppc: Use a static table in powerpc_excp_name() target/ppc: Register CPUClass::exception_name() handler target/riscv: Register CPUClass::exception_name() handler target/rx: Unify BRK and INT trap handling
target/rx: Register CPUClass::exception_name() handler target/s390x: Implement and register CPUClass::exception_name() target/sh4: Register CPUClass::exception_name() handler target/sh4: Use a static table in sh4_exception_name() target/sparc: Remove always-defined DEBUG_PCALL target/sparc: Register CPUClass::exception_name() handler target/xtensa: Implement and register CPUClass::exception_name()
Yonggang Luo (2):
target/rx: Define exception vector constants
target/sh4: Define exception vector constants
include/hw/core/cpu.h | 2 + include/qemu/cutils.h | 17 ++++ include/qemu/osdep.h | 9 ++ target/alpha/cpu.h | 1 + target/arm/cpu.h | 4 +- target/avr/cpu.h | 2 + target/hexagon/cpu_bits.h | 2 + target/hppa/cpu.h | 2 + target/i386/cpu.h | 2 + target/loongarch/internals.h | 2 + target/m68k/cpu.h | 2 + target/microblaze/cpu.h | 2 + target/mips/cpu.h | 4 +- target/mips/tcg/tcg-internal.h | 2 - target/or1k/cpu.h | 2 + target/ppc/cpu.h | 2 + target/riscv/cpu.h | 1 + target/rx/cpu.h | 14 +++ target/rx/helper.h | 3 +- target/s390x/cpu.h | 2 + target/sh4/cpu.h | 22 +++++ target/sparc/cpu.h | 1 + target/xtensa/cpu.h | 2 + accel/tcg/cpu-exec-common.c | 36 ++++++++ target/alpha/cpu.c | 1 + target/alpha/helper.c | 57 +++++------- target/arm/cpu.c | 1 + target/arm/helper.c | 77 ++++++++-------- target/avr/cpu.c | 17 ++++ target/hexagon/cpu.c | 35 ++++++++ target/hexagon/hexswi.c | 30 +------ target/hppa/cpu.c | 42 +++++++++ target/hppa/int_helper.c | 48 +--------- target/i386/cpu.c | 30 +++++++ target/i386/tcg/excp_helper.c | 7 +- target/i386/tcg/seg_helper.c | 11 ++- target/loongarch/cpu.c | 38 ++++++++ target/loongarch/tcg/tcg_cpu.c | 41 --------- target/m68k/cpu.c | 1 + target/m68k/op_helper.c | 159 ++++++++++++--------------------- target/microblaze/cpu.c | 15 ++++ target/mips/cpu.c | 1 + target/mips/tcg/exception.c | 10 +-- target/or1k/cpu.c | 1 + target/or1k/exception.c | 22 +++++ target/or1k/interrupt.c | 19 +--- target/ppc/cpu_init.c | 1 + target/ppc/excp_helper.c | 140 +++++++++++++++-------------- target/riscv/cpu.c | 20 ++--- target/riscv/tcg/op_helper.c | 2 +- target/rx/cpu.c | 1 + target/rx/helper.c | 62 +++++++------ target/rx/op_helper.c | 17 ++-- target/rx/translate.c | 23 +++-- target/s390x/cpu.c | 1 + target/s390x/interrupt.c | 16 ++++ target/s390x/tcg/excp_helper.c | 6 +- target/s390x/tcg/misc_helper.c | 3 +- target/sh4/cpu.c | 1 + target/sh4/helper.c | 109 ++++++++++------------ target/sh4/op_helper.c | 16 ++-- target/sparc/cpu.c | 1 + target/sparc/int32_helper.c | 22 ++--- target/sparc/int64_helper.c | 42 ++++----- target/xtensa/cpu.c | 24 +++++ target/xtensa/exc_helper.c | 3 +- util/cutils.c | 6 ++ 67 files changed, 750 insertions(+), 567 deletions(-)
Signature · 1 line
2.55.0
PATCH v3 1/33 qemu/osdep: Document ARRAY_SIZE() macro rejects pointers
Since commit ed63ec0d22c ("ARRAY_SIZE: check that argument is an array"), passing a pointer to ARRAY_SIZE() is a build error. Document that.
--- include/qemu/osdep.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/qemu/osdep.h +6 -0
@@ -528,6 +528,12 @@ void QEMU_ERROR("code path is reachable")*/ #define QEMU_IS_ARRAY (x) (!__builtin_types_compatible_p(typeof(x), \ typeof(&(x)[0]))) +/** +* ARRAY_SIZE() - Return the number of elements of an array +* @x: the array +* +* Note: fails to build if @x is a pointer. +*/ #ifndef ARRAY_SIZE #define ARRAY_SIZE (x) ((sizeof(x) / sizeof((x)[0])) + \ QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
Signature · 1 line
2.55.0
Re: [PATCH v3 01/33] qemu/osdep: Document ARRAY_SIZE() macro rejects pointers
Quoted 9 lines · Philippe Mathieu-Daudé
Since commit
ed63ec0d22c("ARRAY_SIZE: check that argument is an array"), passing a pointer toARRAY_SIZE()is a build error. Document that.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/osdep.h | 6 ++++++ 1 file changed, 6 insertions(+)
PATCH v3 2/33 util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
In reply to Philippe Mathieu-DaudéMany functions map an enum or exception number to a name, either with a switch statement or by indexing a string table after an open-coded bounds check. Add STR_ARRAY_ELEM_OR_NULL(array, index), which returns array[index], or NULL when index is out of bounds, so such code can use a static table and a single call.
The array is passed as 'const char *const *', so only arrays of strings are accepted; hence the STR_ prefix rather than a generic name.
Misuse is caught at build time:
- pointer instead of array: "negative width in bit-field" error, plus -Wsizeof-pointer-div (GCC);
- array of non-strings (int[], char[][N], int *[]):
-Wincompatible-pointer-types;
- array of non-const 'char *': -Wincompatible-pointer-types (GCC), -Wincompatible-pointer-types-discards-qualifiers (clang);
- pointer as index: -Wint-conversion.
--- include/qemu/cutils.h | 17 +++++++++++++++++ include/qemu/osdep.h | 3 +++ util/cutils.c | 6 ++++++ 3 files changed, 26 insertions(+)
include/qemu/cutils.h +17 -0
@@ -19,6 +19,23 @@ const char *si_prefix(unsigned int exp10);*/ const char *iec_binary_prefix (unsigned int exp2); +const char *str_array_elem_or_null (const char *const *array, +size_t nelem,uint64_t index); + +/** +* STR_ARRAY_ELEM_OR_NULL() - Return a string array element, or NULL if +* out of bounds +* @array: array of strings to index +* @index: index of the element to return +* +* Return @array[@index] if @index is a valid index, otherwise return +* NULL. @index is converted to uint64_t, so negative values of signed +* types are out of bounds and also yield NULL. Useful to look up entries +* in enum-indexed string tables without a prior bounds check. +*/ +#define STR_ARRAY_ELEM_OR_NULL (array, index) \ + str_array_elem_or_null(array, ARRAY_SIZE(array), index) +/** * pstrcpy: * @buf: buffer to copy string into
include/qemu/osdep.h +3 -0
@@ -532,6 +532,9 @@ void QEMU_ERROR("code path is reachable")* ARRAY_SIZE() - Return the number of elements of an array * @x: the array * +* For bounds-checked lookups in arrays of strings, see +* STR_ARRAY_ELEM_OR_NULL() in "qemu/cutils.h". +* * Note: fails to build if @x is a pointer. */ #ifndef ARRAY_SIZE
util/cutils.c +6 -0
@@ -954,6 +954,12 @@ const char *iec_binary_prefix(unsigned int exp2)return prefixes[exp2 /10 ]; } +const char *str_array_elem_or_null (const char *const *array, +size_t nelem,uint64_t index) +{ +return index >= nelem ?NULL : array[index]; +} +/* * Return human readable string for size @val. * @val can be anything that uint64_t allows (no more than "16 EiB").
Signature · 1 line
2.55.0
Re: [PATCH v3 02/33] util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
Quoted 19 lines · Philippe Mathieu-Daudé
Many functions map an enum or exception number to a name, either with a switch statement or by indexing a string table after an open-coded bounds check. Add
STR_ARRAY_ELEM_OR_NULL(array, index), which returns array[index], or NULL when index is out of bounds, so such code can use a static table and a single call.The array is passed as 'const char *const *', so only arrays of strings are accepted; hence the
STR_prefix rather than a generic name.Misuse is caught at build time:
- pointer instead of array: "negative width in bit-field" error, plus -Wsizeof-pointer-div (GCC);
- array of non-strings (int[], char[][N], int *[]):
-Wincompatible-pointer-types;
- array of non-const 'char *': -Wincompatible-pointer-types (GCC), -Wincompatible-pointer-types-discards-qualifiers (clang);
- pointer as index: -Wint-conversion.
Quoted 8 lines
Suggested-by Pierrick Bouvier <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/cutils.h | 17 +++++++++++++++++ include/qemu/osdep.h | 3 +++ util/cutils.c | 6 ++++++ 3 files changed, 26 insertions(+)
Re: [PATCH v3 02/33] util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
In reply to Philippe Mathieu-DaudéQuoted 74 lines · Philippe Mathieu-Daudé
Many functions map an enum or exception number to a name, either with a switch statement or by indexing a string table after an open-coded bounds check. Add
STR_ARRAY_ELEM_OR_NULL(array, index), which returns array[index], or NULL when index is out of bounds, so such code can use a static table and a single call.The array is passed as 'const char *const *', so only arrays of strings are accepted; hence the
STR_prefix rather than a generic name.Misuse is caught at build time:
- pointer instead of array: "negative width in bit-field" error, plus -Wsizeof-pointer-div (GCC);
- array of non-strings (int[], char[][N], int *[]):-Wincompatible-pointer-types;- array of non-const 'char *': -Wincompatible-pointer-types (GCC), -Wincompatible-pointer-types-discards-qualifiers (clang);
- pointer as index: -Wint-conversion.Suggested-by Pierrick Bouvier <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/cutils.h | 17 +++++++++++++++++ include/qemu/osdep.h | 3 +++ util/cutils.c | 6 ++++++ 3 files changed, 26 insertions(+)include/qemu/cutils.h +17
-0@@ -19,6 +19,23 @@ const char *si_prefix(unsigned int exp10);*/ const char *iec_binary_prefix (unsigned int exp2); +const char *str_array_elem_or_null (const char *const *array, +size_t nelem,uint64_t index); + +/** +* STR_ARRAY_ELEM_OR_NULL() - Return a string array element, or NULL if +* out of bounds +* @array: array of strings to index +* @index: index of the element to return +* +* Return @array[@index] if @index is a valid index, otherwise return +* NULL. @index is converted to uint64_t, so negative values of signed +* types are out of bounds and also yield NULL. Useful to look up entries +* in enum-indexed string tables without a prior bounds check. +*/ +#define STR_ARRAY_ELEM_OR_NULL (array, index) \ + str_array_elem_or_null(array, ARRAY_SIZE(array), index) +/** * pstrcpy: * @buf: buffer to copy string into include/qemu/osdep.h +3
-0@@ -532,6 +532,9 @@ void QEMU_ERROR("code path is reachable")* ARRAY_SIZE() - Return the number of elements of an array * @x: the array * +* For bounds-checked lookups in arrays of strings, see +* STR_ARRAY_ELEM_OR_NULL() in "qemu/cutils.h". +* * Note: fails to build if @x is a pointer. */ #ifndef ARRAY_SIZE util/cutils.c +0
-0
util/cutils.c const char *iec_binary_prefix(unsigned int exp2) · line 961
Quoted 8 lines
util/cutils.c +5
-0@@ -954,6 +954,12 @@ const char *iec_binary_prefix(unsigned int exp2)return prefixes[exp2 /10 ]; } +const char *str_array_elem_or_null (const char *const *array, +size_t nelem,uint64_t index) +{ +return index >= nelem ?NULL : array[index]; +}
Why is this trivial function out of line?
Otherwise,
r~
Re: [PATCH v3 02/33] util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
Quoted 75 lines · Richard Henderson
Quoted 74 lines · Philippe Mathieu-Daudé
Many functions map an enum or exception number to a name, either with a switch statement or by indexing a string table after an open-coded bounds check. Add
STR_ARRAY_ELEM_OR_NULL(array, index), which returns array[index], or NULL when index is out of bounds, so such code can use a static table and a single call.The array is passed as 'const char *const *', so only arrays of strings are accepted; hence the
STR_prefix rather than a generic name.Misuse is caught at build time:
- pointer instead of array: "negative width in bit-field" error, plus -Wsizeof-pointer-div (GCC);
- array of non-strings (int[], char[][N], int *[]):
-Wincompatible-pointer-types;
- array of non-const 'char *': -Wincompatible-pointer-types (GCC), -Wincompatible-pointer-types-discards-qualifiers (clang);
- pointer as index: -Wint-conversion.Suggested-by Pierrick Bouvier <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
include/qemu/cutils.h| 17 +++++++++++++++++
include/qemu/osdep.h | 3 +++
util/cutils.c | 6 ++++++3 files changed, 26 insertions(+)include/qemu/cutils.h +11
-0@@ -19,6 +19,23 @@ const char *si_prefix(unsigned int exp10);*/ const char *iec_binary_prefix(unsigned int exp2); +const char *str_array_elem_or_null(const char *const *array, + size_t nelem, uint64_t index); + +/** +* STR_ARRAY_ELEM_OR_NULL() - Return a string array element, or NULL if +* out of bounds +* @array: array of strings to index +* @index: index of the element to return +* +* Return @array[@index] if @index is a valid index, otherwise return +* NULL. @index is converted to uint64_t, so negative values of signed +* types are out of bounds and also yield NULL. Useful to look up entries
+ * in enum-indexed string tables without a prior bounds check.
+ */include/qemu/cutils.h +3
-0+#define STR_ARRAY_ELEM_OR_NULL (array, index) \ + str_array_elem_or_null(array, ARRAY_SIZE(array), index) +/**
* pstrcpy:
* @buf: buffer to copy string intoinclude/qemu/osdep.h +3
-0@@ -532,6 +532,9 @@ void QEMU_ERROR("code path is reachable")* ARRAY_SIZE() - Return the number of elements of an array * @x: the array * +* For bounds-checked lookups in arrays of strings, see +* STR_ARRAY_ELEM_OR_NULL() in "qemu/cutils.h". +* * Note: fails to build if @x is a pointer. */ #ifndef ARRAY_SIZEutil/cutils.c +0
-0@@ -954,6 +954,12 @@ const char *iec_binary_prefix(unsigned int exp2)
Quoted 9 lines
util/cutils.c const char *iec_binary_prefix(unsigned int exp2) · line 961
Quoted 7 lines
util/cutils.c +4
-0return prefixes[exp2 / 10]; } +const char *str_array_elem_or_null(const char *const *array, + size_t nelem, uint64_t index) +{ + return index >= nelem ? NULL : array[index]; +}Why is this trivial function out of line?
It ensures array is a string array, and not any other type. _Generic could probably catch this also, with a more clunky syntax.
Quoted 5 lines
Otherwise,
r~
Re: [PATCH v3 02/33] util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
Quoted 10 lines · Pierrick Bouvier
Quoted 7 lines
util/cutils.c const char *iec_binary_prefix(unsigned int exp2) · line 961
Quoted 5 lines
+const char *str_array_elem_or_null(const char *const *array,
+size_tnelem,uint64_tindex)util/cutils.c +3
-0+{ + return index >= nelem ? NULL : array[index]; +}Why is this trivial function out of line?
It ensures array is a string array, and not any other type.
_Genericcould probably catch this also, with a more clunky syntax.
You can get the same thing from a static inline, is my point.
r~
Re: [PATCH v3 02/33] util/cutils: Add STR_ARRAY_ELEM_OR_NULL() for string table lookups
Quoted 9 lines · Richard Henderson
Quoted 8 lines · Pierrick Bouvier
Quoted 7 lines
util/cutils.c const char *iec_binary_prefix(unsigned int exp2) · line 961
Quoted 5 lines
+const char *str_array_elem_or_null(const char *const *array, +
size_tnelem,uint64_tindex)util/cutils.c +3
-0+{ + return index >= nelem ? NULL : array[index]; +}Why is this trivial function out of line?
Quoted 4 lines
Quoted 2 lines
It ensures array is a string array, and not any other type.
_Genericcould probably catch this also, with a more clunky syntax.You can get the same thing from a static inline, is my point.
It was my initial suggestion:
https://lore.kernel.org/qemu-devel/[email protected]/
I guessed Philippe preferred it to be an extern function, I don't mind either way. Can be a static inline for perf.
Quoted 2 lines
r~
PATCH v3 3/33 cpus: Add helper to log raised exceptions with '-d int'
In reply to Philippe Mathieu-DaudéAdd log_raise_exception(), a common helper cpu_loop_*() can call to log a raised exception when '-d int' is used, and qemu_excp_name() to resolve QEMU-internal exceptions to names.
Use it in cpu_loop_exit_atomic() to log the EXCP_ATOMIC reason.
--- accel/tcg/cpu-exec-common.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
accel/tcg/cpu-exec-common.c +30 -0
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "exec/log.h" #include "system/tcg.h" #include "qemu/plugin.h"
@@ -89,6 +90,34 @@ void tcg_update_all_cflags(void) } } +#define EXCP_QEMU_INTERNAL 0x10000 + +static const char *qemu_excp_name (int excp) +{ +static const char *excp_name[] = { + [EXCP_INTERRUPT -EXCP_QEMU_INTERNAL ] ="async interruption" , + [EXCP_HLT -EXCP_QEMU_INTERNAL ] ="hlt instruction" , + [EXCP_DEBUG -EXCP_QEMU_INTERNAL ] ="debug" , + [EXCP_HALTED -EXCP_QEMU_INTERNAL ] ="halted" , + [EXCP_YIELD -EXCP_QEMU_INTERNAL ] ="yield" , + [EXCP_ATOMIC -EXCP_QEMU_INTERNAL ] ="emulate atomic" , + }; +assert (excp >=EXCP_QEMU_INTERNAL ); + excp -=EXCP_QEMU_INTERNAL ; +return STR_ARRAY_ELEM_OR_NULL (excp_name, excp) ?:"unknown" ; +} + +static void log_raise_exception (const CPUState *cpu,int excp) +{ +if (!qemu_loglevel_mask (CPU_LOG_INT )) { +return ; + } +if (excp >=EXCP_QEMU_INTERNAL ) { +qemu_log_mask (CPU_LOG_INT ,"raise exception: 0x%x (internal: %s)\n" , + excp,qemu_excp_name (excp)); + } +} +/* exit the current TB, but without causing any exception to be raised */ void cpu_loop_exit_noexc (CPUState *cpu) {
@@ -118,5 +147,6 @@ void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc)/* Prevent looping if already executing in a serial context. */ g_assert (!cpu_in_serial_context (cpu)); cpu->exception_index =EXCP_ATOMIC ; +log_raise_exception (cpu,EXCP_ATOMIC );cpu_loop_exit_restore (cpu, pc); }
Signature · 1 line
2.55.0
Re: [PATCH v3 03/33] cpus: Add helper to log raised exceptions with '-d int'
Quoted 1 line · Philippe Mathieu-Daudé
+ return
STR_ARRAY_ELEM_OR_NULL(excp_name, excp)?: "unknown";
Why STR_ARRAY_ELEM_OR_NULL and not STR_ARRAY_ELEM_OR_VAL, supplying "unknown"?
r~
PATCH v3 4/33 cpus: Introduce CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéHave targets register a helper to resolve their exceptions.
--- include/hw/core/cpu.h | 2 ++ accel/tcg/cpu-exec-common.c | 6 ++++++ 2 files changed, 8 insertions(+)
include/hw/core/cpu.h +2 -0
@@ -108,6 +108,7 @@ struct SemihostingCPUOps;* @list_cpus: list available CPU models and flags. * @parse_features: Callback to parse command line arguments. * @reset_dump_flags: #CPUDumpFlags to use for reset logging. +* @exception_name: Callback for getting architecture exception name. * @memory_rw_debug: Callback for GDB memory access. * @dump_state: Callback for dumping state. * @query_cpu_fast:
@@ -178,6 +179,7 @@ struct CPUClass {const char * (*gdb_arch_name)(CPUState *cpu);const char * (*gdb_get_core_xml_file)(CPUState *cpu); +const char *(*exception_name)(int exception);void (*disas_set_info)(const CPUState *cpu,disassemble_info *info);const char *deprecation_note;
accel/tcg/cpu-exec-common.c +6 -0
@@ -115,6 +115,12 @@ static void log_raise_exception(const CPUState *cpu, int excp)if (excp >=EXCP_QEMU_INTERNAL ) {qemu_log_mask (CPU_LOG_INT ,"raise exception: 0x%x (internal: %s)\n" , excp,qemu_excp_name (excp)); + }else { +const CPUClass *cc = cpu->cc; +const char *name = cc->exception_name ? cc->exception_name (excp) + :"unknown" ; + +qemu_log_mask (CPU_LOG_INT ,"raise exception: %d (%s)\n" , excp, name); } }
Signature · 1 line
2.55.0
Re: [PATCH v3 04/33] cpus: Introduce CPUClass::exception_name() handler
Quoted 22 lines · Philippe Mathieu-Daudé
Have targets register a helper to resolve their exceptions.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>--- include/hw/core/cpu.h | 2 ++ accel/tcg/cpu-exec-common.c | 6 ++++++ 2 files changed, 8 insertions(+)include/hw/core/cpu.h +1
-0@@ -108,6 +108,7 @@ struct SemihostingCPUOps;* @list_cpus: list available CPU models and flags. * @parse_features: Callback to parse command line arguments. * @reset_dump_flags: #CPUDumpFlags to use for reset logging. +* @exception_name: Callback for getting architecture exception name. * @memory_rw_debug: Callback for GDB memory access. * @dump_state: Callback for dumping state. * @query_cpu_fast:
include/hw/core/cpu.h struct CPUClass { · line 182
Quoted 4 lines
include/hw/core/cpu.h +1
-0@@ -178,6 +179,7 @@ struct CPUClass {const char * (*gdb_arch_name)(CPUState *cpu);const char * (*gdb_get_core_xml_file)(CPUState *cpu); +const char *(*exception_name)(int exception);
Not keen on "int" while you're standardizing on STR_ARRAY_ELEM_OR_NULL and thus an unsigned comparison vs ARRAY_SIZE.
r~
PATCH v3 5/33 target/alpha: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFactor alpha_exception_name() out of alpha_cpu_do_interrupt() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve Alpha exception codes to names.
--- target/alpha/cpu.h | 1 + target/alpha/cpu.c | 1 + target/alpha/helper.c | 82 ++++++++++++++++++++++++------------------- 3 files changed, 48 insertions(+), 36 deletions(-)
target/alpha/cpu.h +1 -0
@@ -284,6 +284,7 @@ void alpha_cpu_do_interrupt(CPUState *cpu);bool alpha_cpu_exec_interrupt (CPUState *cpu,int int_req);hwaddr alpha_cpu_get_phys_addr_debug (CPUState *cpu,vaddr addr);#endif /* !CONFIG_USER_ONLY */ +const char *alpha_exception_name (int exception);void alpha_cpu_dump_state (CPUState *cs,FILE *f,int flags);int alpha_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int alpha_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);
target/alpha/cpu.c +1 -0
@@ -283,6 +283,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, const void *data) &acc->parent_realize); cc->class_by_name = alpha_cpu_class_by_name; + cc->exception_name = alpha_exception_name; cc->dump_state = alpha_cpu_dump_state; cc->set_pc = alpha_cpu_set_pc; cc->get_pc = alpha_cpu_get_pc;
target/alpha/helper.c +46 -36
95 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v3 05/33] target/alpha: Register CPUClass::exception_name() handler
target/alpha/helper.c line 45
Quoted 8 lines · Philippe Mathieu-Daudé
target/alpha/helper.c +8
-0+const char *alpha_exception_name (int excp) +{ +const char *name; + +switch (excp) { +case EXCP_RESET : + name ="reset" ; +break ;
return "reset";
etc, or pop them into an array. The values come from an enumeration, so these are dense.
r~
PATCH v3 6/33 target/alpha: Use a static table in alpha_exception_name()
In reply to Philippe Mathieu-DaudéReplace the switch statement with a static lookup table.
With '-d int', unlisted exception codes are now logged as "unknown" instead of "<unknown>".
--- target/alpha/helper.c | 55 ++++++++++++------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-)
target/alpha/helper.c +15 -40
@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/cutils.h" #include "cpu.h" #include "exec/cputlb.h" #include "exec/page-protection.h"
@@ -37,47 +38,21 @@const char *alpha_exception_name (int excp) { -const char *name; +static const char *const excp_names[] = { + [EXCP_RESET ] ="reset" , + [EXCP_MCHK ] ="mchk" , + [EXCP_SMP_INTERRUPT ] ="smp_interrupt" , + [EXCP_CLK_INTERRUPT ] ="clk_interrupt" , + [EXCP_DEV_INTERRUPT ] ="dev_interrupt" , + [EXCP_MMFAULT ] ="mmfault" , + [EXCP_UNALIGN ] ="unalign" , + [EXCP_OPCDEC ] ="opcdec" , + [EXCP_ARITH ] ="arith" , + [EXCP_FEN ] ="fen" , + [EXCP_CALL_PAL ] ="call_pal" , + }; -switch (excp) { -case EXCP_RESET : - name ="reset" ; -break ; -case EXCP_MCHK : - name ="mchk" ; -break ; -case EXCP_SMP_INTERRUPT : - name ="smp_interrupt" ; -break ; -case EXCP_CLK_INTERRUPT : - name ="clk_interrupt" ; -break ; -case EXCP_DEV_INTERRUPT : - name ="dev_interrupt" ; -break ; -case EXCP_MMFAULT : - name ="mmfault" ; -break ; -case EXCP_UNALIGN : - name ="unalign" ; -break ; -case EXCP_OPCDEC : - name ="opcdec" ; -break ; -case EXCP_ARITH : - name ="arith" ; -break ; -case EXCP_FEN : - name ="fen" ; -break ; -case EXCP_CALL_PAL : - name ="call_pal" ; -break ; -default : - name ="<unknown>" ; -break ; - } -return name; +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; }uint64_t cpu_alpha_load_fpcr (CPUAlphaState *env)
Signature · 1 line
2.55.0
Re: [PATCH v3 06/33] target/alpha: Use a static table in alpha_exception_name()
Quoted 11 lines · Philippe Mathieu-Daudé
Replace the switch statement with a static lookup table.
With '-d int', unlisted exception codes are now logged as "unknown" instead of "<unknown>".
Suggested-by Pierrick Bouvier<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>Reviewed-by Pierrick Bouvier<[email protected]>--- target/alpha/helper.c | 55 ++++++++++++------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-)
Oh, two patches. Ok.
r~
PATCH v3 7/33 target/arm: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFactor arm_exception_name() out of arm_log_exception() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve ARM exception codes to names.
--- target/arm/cpu.h | 4 ++- target/arm/cpu.c | 1 + target/arm/helper.c | 77 ++++++++++++++++++++++----------------------- 3 files changed, 42 insertions(+), 40 deletions(-)
target/arm/cpu.h +3 -1
@@ -65,7 +65,9 @@#define EXCP_VINMI 27#define EXCP_VFNMI 28#define EXCP_MON_TRAP 29/* AArch32 trap to Monitor mode */ -/* NB: add new EXCP_ defines to the array in arm_log_exception() too */ +/* NB: add new EXCP_ defines to the array in arm_exception_name() too */ + +const char *arm_exception_name (int excp);#define ARMV7M_EXCP_RESET 1#define ARMV7M_EXCP_NMI 2
target/arm/cpu.c +1 -0
@@ -2647,6 +2647,7 @@ static void arm_cpu_class_init(ObjectClass *oc, const void *data) &acc->parent_phases); cc->class_by_name = arm_cpu_class_by_name; + cc->exception_name = arm_exception_name; cc->dump_state = arm_cpu_dump_state; cc->set_pc = arm_cpu_set_pc; cc->get_pc = arm_cpu_get_pc;
target/arm/helper.c +38 -39
96 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v3 07/33] target/arm: Register CPUClass::exception_name() handler
Quoted 5 lines · Philippe Mathieu-Daudé
Factor
arm_exception_name()out ofarm_log_exception()and register it as theCPUClass::exception_name()handler, so the common exception logging can resolve ARM exception codes to names.
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>Reviewed-by Pierrick Bouvier<[email protected]>--- target/arm/cpu.h | 4 ++- target/arm/cpu.c | 1 + target/arm/helper.c | 77 ++++++++++++++++++++++----------------------- 3 files changed, 42 insertions(+), 40 deletions(-)
r~
PATCH v3 8/33 target/avr: Implement and register CPUClass::exception_name()
In reply to Philippe Mathieu-DaudéImplement avr_exception_name() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve AVR exception codes to names.
--- target/avr/cpu.h | 2 ++ target/avr/cpu.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+)
target/avr/cpu.h +2 -0
@@ -44,6 +44,8 @@#define EXCP_RESET 1#define EXCP_INT (n) (EXCP_RESET + (n) + 1) +const char *avr_exception_name (int excp); +/* Number of CPU registers */ #define NUMBER_OF_CPU_REGISTERS 32
target/avr/cpu.c +17 -0
@@ -19,6 +19,7 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/qemu-print.h" #include "exec/translation-block.h"
@@ -258,6 +259,21 @@ static const TCGCPUOps avr_tcg_ops = { .pointer_wrap = cpu_pointer_wrap_uint32, }; +const char *avr_exception_name (int excp) +{ +static const char *const excp_names[] = { + [EXCP_RESET ] ="RESET" , + [EXCP_INT (0 )] ="INT#0" , + [EXCP_INT (1 )] ="INT#1" , + [EXCP_INT (2 )] ="INT#2" , + [EXCP_INT (3 )] ="INT#3" , + [EXCP_INT (4 )] ="INT#4" , + [EXCP_INT (5 )] ="INT#5" , + }; + +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; +} +static void avr_cpu_class_init (ObjectClass *oc,const void *data) {DeviceClass *dc =DEVICE_CLASS (oc);
@@ -273,6 +289,7 @@ static void avr_cpu_class_init(ObjectClass *oc, const void *data) &mcc->parent_phases); cc->class_by_name = avr_cpu_class_by_name; + cc->exception_name = avr_exception_name; cc->dump_state = avr_cpu_dump_state; cc->set_pc = avr_cpu_set_pc;
Signature · 1 line
2.55.0
PATCH v3 9/33 target/hexagon: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéExpose the hexagon event_name[] array via a hexagon_event_name() helper and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve Hexagon exception codes to names. Make the table 'const char * const' while moving it.
With '-d int', hexagon_cpu_do_interrupt() used to index event_name[] directly. Codes without an entry (table holes, or values past its end) are now logged as "unknown", instead of passing NULL to "%s" or reading past the array.
--- target/hexagon/cpu_bits.h | 2 ++ target/hexagon/cpu.c | 35 +++++++++++++++++++++++++++++++++++ target/hexagon/hexswi.c | 30 +----------------------------- 3 files changed, 38 insertions(+), 29 deletions(-)
target/hexagon/cpu_bits.h +2 -0
@@ -61,6 +61,8 @@ enum hex_event { HEX_EVENT_INTF = 0x1f, }; +const char *hexagon_event_name (int event); +enum hex_cause {HEX_CAUSE_NONE =-1 ,HEX_CAUSE_RESET =0x000 ,
target/hexagon/cpu.c +35 -0
@@ -18,6 +18,7 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/qemu-print.h" +#include "qemu/cutils.h" #include "cpu.h" #include "internal.h" #include "exec/cputlb.h"
@@ -318,6 +319,39 @@ void hexagon_debug(CPUHexagonState *env)hexagon_dump (env, stdout,CPU_DUMP_FPU ); } +const char *hexagon_event_name (int event) +{ +static const char *const event_name[] = { + [HEX_EVENT_RESET ] ="HEX_EVENT_RESET" , + [HEX_EVENT_IMPRECISE ] ="HEX_EVENT_IMPRECISE" , + [HEX_EVENT_PRECISE ] ="HEX_EVENT_PRECISE" , + [HEX_EVENT_TLB_MISS_X ] ="HEX_EVENT_TLB_MISS_X" , + [HEX_EVENT_TLB_MISS_RW ] ="HEX_EVENT_TLB_MISS_RW" , + [HEX_EVENT_TRAP0 ] ="HEX_EVENT_TRAP0" , + [HEX_EVENT_TRAP1 ] ="HEX_EVENT_TRAP1" , + [HEX_EVENT_FPTRAP ] ="HEX_EVENT_FPTRAP" , + [HEX_EVENT_DEBUG ] ="HEX_EVENT_DEBUG" , + [HEX_EVENT_INT0 ] ="HEX_EVENT_INT0" , + [HEX_EVENT_INT1 ] ="HEX_EVENT_INT1" , + [HEX_EVENT_INT2 ] ="HEX_EVENT_INT2" , + [HEX_EVENT_INT3 ] ="HEX_EVENT_INT3" , + [HEX_EVENT_INT4 ] ="HEX_EVENT_INT4" , + [HEX_EVENT_INT5 ] ="HEX_EVENT_INT5" , + [HEX_EVENT_INT6 ] ="HEX_EVENT_INT6" , + [HEX_EVENT_INT7 ] ="HEX_EVENT_INT7" , + [HEX_EVENT_INT8 ] ="HEX_EVENT_INT8" , + [HEX_EVENT_INT9 ] ="HEX_EVENT_INT9" , + [HEX_EVENT_INTA ] ="HEX_EVENT_INTA" , + [HEX_EVENT_INTB ] ="HEX_EVENT_INTB" , + [HEX_EVENT_INTC ] ="HEX_EVENT_INTC" , + [HEX_EVENT_INTD ] ="HEX_EVENT_INTD" , + [HEX_EVENT_INTE ] ="HEX_EVENT_INTE" , + [HEX_EVENT_INTF ] ="HEX_EVENT_INTF" , + }; + +return STR_ARRAY_ELEM_OR_NULL (event_name, event) ?:"unknown" ; +} +static void hexagon_cpu_set_pc (CPUState *cs,vaddr value) {cpu_env (cs)->gpr[HEX_REG_PC ] = value;
@@ -841,6 +875,7 @@ static void hexagon_cpu_class_init(ObjectClass *c, const void *data) &mcc->parent_phases); cc->class_by_name = hexagon_cpu_class_by_name; + cc->exception_name = hexagon_event_name; cc->dump_state = hexagon_dump_state; cc->set_pc = hexagon_cpu_set_pc; cc->get_pc = hexagon_cpu_get_pc;
target/hexagon/hexswi.c +1 -29
@@ -735,34 +735,6 @@ static void set_addresses(CPUHexagonState *env, uint32_t pc_offset, env->gpr[HEX_REG_PC ] = evb | (exception_index <<2 ); } -static const char *event_name[] = { - [HEX_EVENT_RESET ] ="HEX_EVENT_RESET" , - [HEX_EVENT_IMPRECISE ] ="HEX_EVENT_IMPRECISE" , - [HEX_EVENT_PRECISE ] ="HEX_EVENT_PRECISE" , - [HEX_EVENT_TLB_MISS_X ] ="HEX_EVENT_TLB_MISS_X" , - [HEX_EVENT_TLB_MISS_RW ] ="HEX_EVENT_TLB_MISS_RW" , - [HEX_EVENT_TRAP0 ] ="HEX_EVENT_TRAP0" , - [HEX_EVENT_TRAP1 ] ="HEX_EVENT_TRAP1" , - [HEX_EVENT_FPTRAP ] ="HEX_EVENT_FPTRAP" , - [HEX_EVENT_DEBUG ] ="HEX_EVENT_DEBUG" , - [HEX_EVENT_INT0 ] ="HEX_EVENT_INT0" , - [HEX_EVENT_INT1 ] ="HEX_EVENT_INT1" , - [HEX_EVENT_INT2 ] ="HEX_EVENT_INT2" , - [HEX_EVENT_INT3 ] ="HEX_EVENT_INT3" , - [HEX_EVENT_INT4 ] ="HEX_EVENT_INT4" , - [HEX_EVENT_INT5 ] ="HEX_EVENT_INT5" , - [HEX_EVENT_INT6 ] ="HEX_EVENT_INT6" , - [HEX_EVENT_INT7 ] ="HEX_EVENT_INT7" , - [HEX_EVENT_INT8 ] ="HEX_EVENT_INT8" , - [HEX_EVENT_INT9 ] ="HEX_EVENT_INT9" , - [HEX_EVENT_INTA ] ="HEX_EVENT_INTA" , - [HEX_EVENT_INTB ] ="HEX_EVENT_INTB" , - [HEX_EVENT_INTC ] ="HEX_EVENT_INTC" , - [HEX_EVENT_INTD ] ="HEX_EVENT_INTD" , - [HEX_EVENT_INTE ] ="HEX_EVENT_INTE" , - [HEX_EVENT_INTF ] ="HEX_EVENT_INTF" -}; -void hexagon_cpu_do_interrupt (CPUState *cs) {
@@ -775,7 +747,7 @@ void hexagon_cpu_do_interrupt(CPUState *cs)qemu_log_mask (CPU_LOG_INT ,"\t%s: event 0x%02x:%s, cause 0x%" PRIx32"(%" PRIu32")\n" , __func__, (unsigned )cs->exception_index, - event_name[cs->exception_index], env->cause_code, +hexagon_event_name (cs->exception_index), env->cause_code, env->cause_code); env->llsc_addr = ~0 ;
Signature · 1 line
2.55.0
PATCH v3 10/33 target/hppa: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFactor hppa_exception_name() out of hppa_cpu_do_interrupt() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve HPPA exception codes to names.
With '-d int', hppa_cpu_do_interrupt() now logs "INT: cpu N excp I (NAME)", NAME being "unknown" for unlisted codes, instead of "INT: cpu N NAME" or "INT: cpu N unknown I".
--- target/hppa/cpu.h | 2 ++ target/hppa/cpu.c | 42 +++++++++++++++++++++++++++++++++++ target/hppa/int_helper.c | 48 +++------------------------------------- 3 files changed, 47 insertions(+), 45 deletions(-)
target/hppa/cpu.h +2 -0
@@ -98,6 +98,8 @@/* Emulated hardware TOC button */ #define EXCP_TOC 32/* TOC = Transfer of control (NMI) */ +const char *hppa_exception_name (int excp); +#define CPU_INTERRUPT_NMI CPU_INTERRUPT_TGT_EXT_3/* TOC */ /* Taken from Linux kernel: arch/parisc/include/asm/psw.h */
target/hppa/cpu.c +42 -0
60 lines not on this page · raw message
target/hppa/int_helper.c +3 -45
56 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v3 11/33 target/i386: Replace magic value by proper EXCP0E_PAGE definition
In reply to Philippe Mathieu-DaudéNo functional change: EXCP0E_PAGE is the 0x0e page-fault vector.
--- target/i386/tcg/seg_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/seg_helper.c +1 -1
@@ -1215,7 +1215,7 @@ void do_interrupt_all(X86CPU *cpu, int intno, int is_int, env->segs[R_CS ].selector, env->eip, (int )env->segs[R_CS ].base + env->eip, env->segs[R_SS].selector, env->regs[R_ESP]); -if (intno ==0x0e ) { +if (intno ==EXCP0E_PAGE ) {qemu_log (" CR2=" TARGET_FMT_lx, env->cr[2 ]); }else {qemu_log (" env->regs[R_EAX]=" TARGET_FMT_lx, env->regs[R_EAX ]);
Signature · 1 line
2.55.0
PATCH v3 12/33 target/i386: Implement and register CPUClass::exception_name()
In reply to Philippe Mathieu-DaudéImplement x86_exception_name() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve X86 exception codes to names.
Use the new helper in check_exception() and do_interrupt_all().
With '-d int', both now print a name in parentheses after the vector number. do_interrupt_all() labels hardware interrupts "IRQ" and software INT n with n >= 0x20 "INT", instead of looking them up. check_exception() shows "none" when no exception is pending (old_exception == -1).
--- target/i386/cpu.h | 2 ++ target/i386/cpu.c | 30 ++++++++++++++++++++++++++++++ target/i386/tcg/excp_helper.c | 7 +++++-- target/i386/tcg/seg_helper.c | 9 +++++++-- 4 files changed, 44 insertions(+), 4 deletions(-)
target/i386/cpu.h +2 -0
@@ -1517,6 +1517,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);#define EXCP_SYSCALL 0x101/* only for user emulation */ #define EXCP_VSYSCALL 0x102/* only for user emulation */ +const char *x86_exception_name (int excp); +/* i386-specific interrupt pending bits. */ #define CPU_INTERRUPT_POLL CPU_INTERRUPT_TGT_EXT_1#define CPU_INTERRUPT_SMI CPU_INTERRUPT_TGT_EXT_2
target/i386/cpu.c +30 -0
@@ -9372,6 +9372,35 @@ static bool cpuid_has_xsave_feature(CPUX86State *env, const ExtSaveArea *esa)return false; } +const char *x86_exception_name (int excp) +{ +static const char *const excp_names[] = { + [EXCP00_DIVZ ] ="DIV#0" , + [EXCP01_DB ] ="DB" , + [EXCP02_NMI ] ="NMI" , + [EXCP03_INT3 ] ="INT3" , + [EXCP04_INTO ] ="INTO" , + [EXCP05_BOUND ] ="BOUND" , + [EXCP06_ILLOP ] ="ILLOP" , + [EXCP07_PREX ] ="PREX" , + [EXCP08_DBLE ] ="DBLE" , + [EXCP09_XERR ] ="XERR" , + [EXCP0A_TSS ] ="TSS" , + [EXCP0B_NOSEG ] ="NOSEG" , + [EXCP0C_STACK ] ="STACK" , + [EXCP0D_GPF ] ="GPF" , + [EXCP0E_PAGE ] ="PAGE" , + [EXCP10_COPR ] ="COPR" , + [EXCP11_ALGN ] ="ALGN" , + [EXCP12_MCHK ] ="MCHK" , + [EXCP_VMEXIT ] ="VMEXIT" , + [EXCP_SYSCALL ] ="SYSCALL" , + [EXCP_VSYSCALL ] ="VSYSCALL" , + }; + +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; +} +static void x86_cpu_reset_hold (Object *obj,ResetType type) {CPUState *cs =CPU (obj);
@@ -10946,6 +10975,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, const void *data) cc->reset_dump_flags =CPU_DUMP_FPU |CPU_DUMP_CCOP ; cc->class_by_name = x86_cpu_class_by_name; + cc->exception_name = x86_exception_name; cc->list_cpus = x86_cpu_list; cc->parse_features = x86_cpu_parse_featurestr; cc->dump_state = x86_cpu_dump_state;
target/i386/tcg/excp_helper.c +5 -2
@@ -56,8 +56,11 @@ static int check_exception(CPUX86State *env, int intno, int *error_code,int second_contributory = intno ==0 || (intno >=10 && intno <=13 ); -qemu_log_mask (CPU_LOG_INT ,"check_exception old: 0x%x new 0x%x\n" , - env->old_exception, intno); +qemu_log_mask (CPU_LOG_INT ,"check_exception old: 0x%x (%s) new 0x%x (%s)\n" , + env->old_exception, + env->old_exception ==-1 ?"none" + :x86_exception_name (env->old_exception), + intno,x86_exception_name (intno));#if !defined(CONFIG_USER_ONLY )if (env->old_exception ==EXCP08_DBLE ) {
target/i386/tcg/seg_helper.c +7 -2
@@ -1207,10 +1207,15 @@ void do_interrupt_all(X86CPU *cpu, int intno, int is_int,if (qemu_loglevel_mask (CPU_LOG_INT )) {if ((env->cr[0 ] &CR0_PE_MASK )) {static int count; +const char *name = is_hw ?"IRQ" + : is_int && intno >=0x20 ?"INT" + :x86_exception_name (intno); - qemu_log("%6d: v=%02x e=%04x i=%d cpl=%d IP=%04x:" TARGET_FMT_lx + qemu_log("%6d: v=%02x (%s) e=%04x i=%d" + " cpl=%d IP=%04x:" TARGET_FMT_lx " pc=" TARGET_FMT_lx " SP=%04x:" TARGET_FMT_lx, - count, intno, error_code, is_int, + count, intno, name, + error_code, is_int, env->hflags & HF_CPL_MASK, env->segs[R_CS].selector, env->eip, (int)env->segs[R_CS].base + env->eip,
Signature · 1 line
2.55.0
PATCH v3 13/33 target/loongarch: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéMove loongarch_exception_name() out of tcg_cpu.c and expose the prototype so non-TCG code path can access it. Register it as the CPUClass::exception_name() handler, so the common exception logging can resolve LoongArch exception codes to names.
With '-d int', unlisted codes are now logged as "unknown" instead of "Unknown".
--- target/loongarch/internals.h | 2 ++ target/loongarch/cpu.c | 38 +++++++++++++++++++++++++++++++ target/loongarch/tcg/tcg_cpu.c | 41 ---------------------------------- 3 files changed, 40 insertions(+), 41 deletions(-)
target/loongarch/internals.h +2 -0
@@ -42,6 +42,8 @@ bool loongarch_cpu_has_work(CPUState *cs);bool cpu_loongarch_hw_interrupts_pending (CPULoongArchState *env);#endif /* !CONFIG_USER_ONLY */ +const char *loongarch_exception_name (int exception); +uint64_t read_fcc (CPULoongArchState *env);void write_fcc (CPULoongArchState *env,uint64_t val);
target/loongarch/cpu.c +38 -0
@@ -835,6 +835,43 @@ static void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags) } } +static const struct { +int32_t exccode; +const char *const name; +} excp_names[] = { + {EXCCODE_INT ,"Interrupt" }, + {EXCCODE_PIL ,"Page invalid exception for load" }, + {EXCCODE_PIS ,"Page invalid exception for store" }, + {EXCCODE_PIF ,"Page invalid exception for fetch" }, + {EXCCODE_PME ,"Page modified exception" }, + {EXCCODE_PNR ,"Page Not Readable exception" }, + {EXCCODE_PNX ,"Page Not Executable exception" }, + {EXCCODE_PPI ,"Page Privilege error" }, + {EXCCODE_ADEF ,"Address error for instruction fetch" }, + {EXCCODE_ADEM ,"Address error for Memory access" }, + {EXCCODE_SYS ,"Syscall" }, + {EXCCODE_BRK ,"Break" }, + {EXCCODE_INE ,"Instruction Non-Existent" }, + {EXCCODE_IPE ,"Instruction privilege error" }, + {EXCCODE_FPD ,"Floating Point Disabled" }, + {EXCCODE_FPE ,"Floating Point Exception" }, + {EXCCODE_DBP ,"Debug breakpoint" }, + {EXCCODE_BCE ,"Bound Check Exception" }, + {EXCCODE_SXD ,"128 bit vector instructions Disable exception" }, + {EXCCODE_ASXD ,"256 bit vector instructions Disable exception" }, + {EXCP_HLT ,"EXCP_HLT" }, +}; + +const char *loongarch_exception_name (int exception) +{ +for (size_t i =0 ; i <ARRAY_SIZE (excp_names); i++) { +if (excp_names[i].exccode == exception) { +return excp_names[i].name; + } + } +return "unknown" ; +} +#ifndef CONFIG_USER_ONLY #include "hw/core/sysemu-cpu-ops.h"
@@ -875,6 +912,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, const void *data) &lacc->parent_phases); cc->class_by_name = loongarch_cpu_class_by_name; + cc->exception_name = loongarch_exception_name; cc->dump_state = loongarch_cpu_dump_state; cc->set_pc = loongarch_cpu_set_pc; cc->get_pc = loongarch_cpu_get_pc;
target/loongarch/tcg/tcg_cpu.c +0 -41
47 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v3 14/33 target/m68k: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéExpose m68k_exception_name() prototype and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve M68k exception codes to names.
--- target/m68k/cpu.h | 2 ++ target/m68k/cpu.c | 1 + target/m68k/op_helper.c | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-)
target/m68k/cpu.h +2 -0
@@ -69,6 +69,8 @@#define EXCP_RTE 0x100#define EXCP_SEMIHOSTING 0x101 +const char *m68k_exception_name (int excp); +#define M68K_DTTR0 0#define M68K_DTTR1 1#define M68K_ITTR0 2
target/m68k/cpu.c +1 -0
@@ -730,6 +730,7 @@ static void m68k_cpu_class_init(ObjectClass *c, const void *data) &mcc->parent_phases); cc->class_by_name = m68k_cpu_class_by_name; + cc->exception_name = m68k_exception_name; cc->dump_state = m68k_cpu_dump_state; cc->set_pc = m68k_cpu_set_pc; cc->get_pc = m68k_cpu_get_pc;
target/m68k/op_helper.c +6 -2
@@ -80,9 +80,11 @@ throwaway: cpu_m68k_set_sr(env, sr); } -static const char *m68k_exception_name (int index) +#endif /* !CONFIG_USER_ONLY */ + +const char *m68k_exception_name (int excp) { -switch (index) { +switch (excp) {case EXCP_ACCESS :return "Access Fault" ;case EXCP_ADDRESS :
@@ -185,6 +187,8 @@ static const char *m68k_exception_name(int index)return "Unassigned" ; } +#ifndef CONFIG_USER_ONLY +static void do_plugin_vcpu_interrupt_cb (CPUState *cs,uint64_t from) {switch (cs->exception_index) {
Signature · 1 line
2.55.0
PATCH v3 15/33 target/m68k: Use a static table in m68k_exception_name()
In reply to Philippe Mathieu-DaudéReplace the switch statement with a static lookup table.
--- target/m68k/op_helper.c | 153 ++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 99 deletions(-)
target/m68k/op_helper.c +54 -99
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/cutils.h" #include "cpu.h" #include "exec/helper-proto.h" #include "accel/tcg/cpu-ldst.h"
@@ -84,107 +85,61 @@ throwaway:const char *m68k_exception_name (int excp) { -switch (excp) { -case EXCP_ACCESS : -return "Access Fault" ; -case EXCP_ADDRESS : -return "Address Error" ; -case EXCP_ILLEGAL : -return "Illegal Instruction" ; -case EXCP_DIV0 : -return "Divide by Zero" ; -case EXCP_CHK : -return "CHK/CHK2" ; -case EXCP_TRAPCC : -return "FTRAPcc, TRAPcc, TRAPV" ; -case EXCP_PRIVILEGE : -return "Privilege Violation" ; -case EXCP_TRACE : -return "Trace" ; -case EXCP_LINEA : -return "A-Line" ; -case EXCP_LINEF : -return "F-Line" ; -case EXCP_DEBEGBP :/* 68020/030 only */ -return "Copro Protocol Violation" ; -case EXCP_FORMAT : -return "Format Error" ; -case EXCP_UNINITIALIZED : -return "Uninitialized Interrupt" ; -case EXCP_SPURIOUS : -return "Spurious Interrupt" ; -case EXCP_INT_LEVEL_1 : -return "Level 1 Interrupt" ; -case EXCP_INT_LEVEL_1 +1 : -return "Level 2 Interrupt" ; -case EXCP_INT_LEVEL_1 +2 : -return "Level 3 Interrupt" ; -case EXCP_INT_LEVEL_1 +3 : -return "Level 4 Interrupt" ; -case EXCP_INT_LEVEL_1 +4 : -return "Level 5 Interrupt" ; -case EXCP_INT_LEVEL_1 +5 : -return "Level 6 Interrupt" ; -case EXCP_INT_LEVEL_1 +6 : -return "Level 7 Interrupt" ; -case EXCP_TRAP0 : -return "TRAP #0" ; -case EXCP_TRAP0 +1 : -return "TRAP #1" ; -case EXCP_TRAP0 +2 : -return "TRAP #2" ; -case EXCP_TRAP0 +3 : -return "TRAP #3" ; -case EXCP_TRAP0 +4 : -return "TRAP #4" ; -case EXCP_TRAP0 +5 : -return "TRAP #5" ; -case EXCP_TRAP0 +6 : -return "TRAP #6" ; -case EXCP_TRAP0 +7 : -return "TRAP #7" ; -case EXCP_TRAP0 +8 : -return "TRAP #8" ; -case EXCP_TRAP0 +9 : -return "TRAP #9" ; -case EXCP_TRAP0 +10 : -return "TRAP #10" ; -case EXCP_TRAP0 +11 : -return "TRAP #11" ; -case EXCP_TRAP0 +12 : -return "TRAP #12" ; -case EXCP_TRAP0 +13 : -return "TRAP #13" ; -case EXCP_TRAP0 +14 : -return "TRAP #14" ; -case EXCP_TRAP0 +15 : -return "TRAP #15" ; -case EXCP_FP_BSUN : -return "FP Branch/Set on unordered condition" ; -case EXCP_FP_INEX : -return "FP Inexact Result" ; -case EXCP_FP_DZ : -return "FP Divide by Zero" ; -case EXCP_FP_UNFL : -return "FP Underflow" ; -case EXCP_FP_OPERR : -return "FP Operand Error" ; -case EXCP_FP_OVFL : -return "FP Overflow" ; -case EXCP_FP_SNAN : -return "FP Signaling NAN" ; -case EXCP_FP_UNIMP : -return "FP Unimplemented Data Type" ; -case EXCP_MMU_CONF :/* 68030/68851 only */ -return "MMU Configuration Error" ; -case EXCP_MMU_ILLEGAL :/* 68851 only */ -return "MMU Illegal Operation" ; -case EXCP_MMU_ACCESS :/* 68851 only */ -return "MMU Access Level Violation" ; - case 64 ... 255: +static const char *const excp_names[] = { + [EXCP_ACCESS ] ="Access Fault" , + [EXCP_ADDRESS ] ="Address Error" , + [EXCP_ILLEGAL ] ="Illegal Instruction" , + [EXCP_DIV0 ] ="Divide by Zero" , + [EXCP_CHK ] ="CHK/CHK2" , + [EXCP_TRAPCC ] ="FTRAPcc, TRAPcc, TRAPV" , + [EXCP_PRIVILEGE ] ="Privilege Violation" , + [EXCP_TRACE ] ="Trace" , + [EXCP_LINEA ] ="A-Line" , + [EXCP_LINEF ] ="F-Line" , + [EXCP_DEBEGBP ] ="Copro Protocol Violation" ,/* 68020/030 only */ + [EXCP_FORMAT ] ="Format Error" , + [EXCP_UNINITIALIZED ] ="Uninitialized Interrupt" , + [EXCP_SPURIOUS ] ="Spurious Interrupt" , + [EXCP_INT_LEVEL_1 ] ="Level 1 Interrupt" , + [EXCP_INT_LEVEL_1 +1 ] ="Level 2 Interrupt" , + [EXCP_INT_LEVEL_1 +2 ] ="Level 3 Interrupt" , + [EXCP_INT_LEVEL_1 +3 ] ="Level 4 Interrupt" , + [EXCP_INT_LEVEL_1 +4 ] ="Level 5 Interrupt" , + [EXCP_INT_LEVEL_1 +5 ] ="Level 6 Interrupt" , + [EXCP_INT_LEVEL_1 +6 ] ="Level 7 Interrupt" , + [EXCP_TRAP0 ] ="TRAP #0" , + [EXCP_TRAP0 +1 ] ="TRAP #1" , + [EXCP_TRAP0 +2 ] ="TRAP #2" , + [EXCP_TRAP0 +3 ] ="TRAP #3" , + [EXCP_TRAP0 +4 ] ="TRAP #4" , + [EXCP_TRAP0 +5 ] ="TRAP #5" , + [EXCP_TRAP0 +6 ] ="TRAP #6" , + [EXCP_TRAP0 +7 ] ="TRAP #7" , + [EXCP_TRAP0 +8 ] ="TRAP #8" , + [EXCP_TRAP0 +9 ] ="TRAP #9" , + [EXCP_TRAP0 +10 ] ="TRAP #10" , + [EXCP_TRAP0 +11 ] ="TRAP #11" , + [EXCP_TRAP0 +12 ] ="TRAP #12" , + [EXCP_TRAP0 +13 ] ="TRAP #13" , + [EXCP_TRAP0 +14 ] ="TRAP #14" , + [EXCP_TRAP0 +15 ] ="TRAP #15" , + [EXCP_FP_BSUN ] ="FP Branch/Set on unordered condition" , + [EXCP_FP_INEX ] ="FP Inexact Result" , + [EXCP_FP_DZ ] ="FP Divide by Zero" , + [EXCP_FP_UNFL ] ="FP Underflow" , + [EXCP_FP_OPERR ] ="FP Operand Error" , + [EXCP_FP_OVFL ] ="FP Overflow" , + [EXCP_FP_SNAN ] ="FP Signaling NAN" , + [EXCP_FP_UNIMP ] ="FP Unimplemented Data Type" , + [EXCP_MMU_CONF ] ="MMU Configuration Error" ,/* 68030/68851 only */ + [EXCP_MMU_ILLEGAL ] ="MMU Illegal Operation" ,/* 68851 only */ + [EXCP_MMU_ACCESS ] ="MMU Access Level Violation" ,/* 68851 only */ + }; + +if (excp >=64 && excp <=255 ) {return "User Defined Vector" ; } -return "Unassigned" ; +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"Unassigned" ; }#ifndef CONFIG_USER_ONLY
Signature · 1 line
2.55.0
PATCH v3 16/33 target/microblaze: Implement and register CPUClass::exception_name()
In reply to Philippe Mathieu-DaudéImplement microblaze_exception_name() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve MicroBlaze exception codes to names.
--- target/microblaze/cpu.h | 2 ++ target/microblaze/cpu.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+)
target/microblaze/cpu.h +2 -0
@@ -36,6 +36,8 @@ typedef struct CPUArchState CPUMBState;#define EXCP_HW_BREAK 4#define EXCP_HW_EXCP 5 +const char *microblaze_exception_name (int excp); +/* MicroBlaze-specific interrupt pending bits. */ #define CPU_INTERRUPT_NMI CPU_INTERRUPT_TGT_EXT_3
target/microblaze/cpu.c +15 -0
@@ -23,6 +23,7 @@#include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "cpu.h" #include "qemu/module.h"
@@ -79,6 +80,19 @@ static const struct {/* If no specific version gets selected, default to the following. */ #define DEFAULT_CPU_VERSION "10.0" +const char *microblaze_exception_name (int excp) +{ +static const char *const excp_names[] = { + [EXCP_MMU ] ="mmu" , + [EXCP_IRQ ] ="irq" , + [EXCP_SYSCALL ] ="syscall" , + [EXCP_HW_BREAK ] ="hw break" , + [EXCP_HW_EXCP ] ="hw excp" , + }; + +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; +} +static void mb_cpu_set_pc (CPUState *cs,vaddr value) {MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs);
@@ -469,6 +483,7 @@ static void mb_cpu_class_init(ObjectClass *oc, const void *data) &mcc->parent_phases); cc->class_by_name = mb_cpu_class_by_name; + cc->exception_name = microblaze_exception_name; cc->dump_state = mb_cpu_dump_state; cc->set_pc = mb_cpu_set_pc; cc->get_pc = mb_cpu_get_pc;
Signature · 1 line
2.55.0
PATCH v3 17/33 target/mips: Remove EXCP_LAST, use ARRAY_SIZE(excp_names)
In reply to Philippe Mathieu-DaudéEXCP_LAST was only used to size excp_names[] and to bound-check mips_exception_name(). Let the table size itself from its initializers and check the index with ARRAY_SIZE(), so adding an exception no longer requires updating EXCP_LAST.
--- target/mips/cpu.h | 2 -- target/mips/tcg/exception.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-)
target/mips/cpu.h +0 -2
@@ -1347,8 +1347,6 @@ enum {EXCP_TLBXI ,EXCP_TLBRI , EXCP_SEMIHOST, - - EXCP_LAST = EXCP_SEMIHOST, };/*
target/mips/tcg/exception.c +2 -2
@@ -88,7 +88,7 @@ void mips_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb) env->hflags |= tb->flags &MIPS_HFLAG_BMASK ; } -static const char *const excp_names[EXCP_LAST +1 ] = { +static const char *const excp_names[] = { [EXCP_RESET ] ="reset" , [EXCP_SRESET ] ="soft reset" , [EXCP_DSS ] ="debug single step" ,
@@ -131,7 +131,7 @@ static const char * const excp_names[EXCP_LAST + 1] = {const char *mips_exception_name (int32_t exception) { -if (exception <0 || exception >EXCP_LAST ) { +if (exception <0 || exception >=ARRAY_SIZE (excp_names)) {return "unknown" ; }return excp_names[exception];
Signature · 1 line
2.55.0
PATCH v3 18/33 target/mips: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéRegister mips_exception_name() as the CPUClass::exception_name() handler, so the common exception logging can resolve MIPS exception codes to names. Return "unknown" for missing array entries.
With '-d int', codes without an entry in excp_names[] are now logged as "unknown" instead of passing NULL to "%s".
--- target/mips/cpu.h | 2 ++ target/mips/tcg/tcg-internal.h | 2 -- target/mips/cpu.c | 1 + target/mips/tcg/exception.c | 8 +++----- 4 files changed, 6 insertions(+), 7 deletions(-)
target/mips/cpu.h +2 -0
@@ -1349,6 +1349,8 @@ enum { EXCP_SEMIHOST, }; +const char *mips_exception_name (int excp); +/* * This is an internally generated WAKE request line. * It is driven by the CPU itself. Raised when the MT
target/mips/tcg/tcg-internal.h +0 -2
@@ -27,8 +27,6 @@ void mips_restore_state_to_opc(CPUState *cs,const TranslationBlock *tb, const uint64_t *data); -const char *mips_exception_name (int32_t exception); - G_NORETURN void do_raise_exception_err(CPUMIPSState *env, uint32_t exception,int error_code,uintptr_t pc);
target/mips/cpu.c +1 -0
@@ -742,6 +742,7 @@ static void mips_cpu_class_init(ObjectClass *c, const void *data) &mcc->parent_phases); cc->class_by_name = mips_cpu_class_by_name; + cc->exception_name = mips_exception_name; cc->dump_state = mips_cpu_dump_state; cc->set_pc = mips_cpu_set_pc; cc->get_pc = mips_cpu_get_pc;
target/mips/tcg/exception.c +3 -5
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/cutils.h" #include "cpu.h" #include "internal.h" #include "exec/helper-proto.h"
@@ -129,12 +130,9 @@ static const char * const excp_names[] = { [EXCP_SEMIHOST] = "Semihosting", }; -const char *mips_exception_name (int32_t exception) +const char *mips_exception_name (int excp) { -if (exception <0 || exception >=ARRAY_SIZE (excp_names)) { -return "unknown" ; - } -return excp_names[exception]; +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; } void do_raise_exception_err(CPUMIPSState *env, uint32_t exception,
Signature · 1 line
2.55.0
PATCH v3 19/33 target/or1k: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFactor openrisc_excp_name() out of openrisc_cpu_do_interrupt() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve OpenRISC exception codes to names.
--- target/or1k/cpu.h | 2 ++ target/or1k/cpu.c | 1 + target/or1k/exception.c | 22 ++++++++++++++++++++++ target/or1k/interrupt.c | 19 +------------------ 4 files changed, 26 insertions(+), 18 deletions(-)
target/or1k/cpu.h +2 -0
@@ -155,6 +155,8 @@ enum { EXCP_NR, }; +const char *openrisc_excp_name (int excp); +/* Supervisor register */ enum {SR_SM = (1 <<0 ),
target/or1k/cpu.c +1 -0
@@ -285,6 +285,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, const void *data) &occ->parent_phases); cc->class_by_name = openrisc_cpu_class_by_name; + cc->exception_name = openrisc_excp_name; cc->dump_state = openrisc_cpu_dump_state; cc->set_pc = openrisc_cpu_set_pc; cc->get_pc = openrisc_cpu_get_pc;
target/or1k/exception.c +22 -0
@@ -18,10 +18,32 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "accel/tcg/cpu-loop.h" #include "cpu.h" #include "exception.h" +const char *openrisc_excp_name (int excp) +{ +static const char *const excp_name[EXCP_NR ] = { + [EXCP_RESET ] ="RESET" , + [EXCP_BUSERR ] ="BUSERR (bus error)" , + [EXCP_DPF ] ="DFP (data protection fault)" , + [EXCP_IPF ] ="IPF (code protection fault)" , + [EXCP_TICK ] ="TICK (timer interrupt)" , + [EXCP_ALIGN ] ="ALIGN" , + [EXCP_ILLEGAL ] ="ILLEGAL" , + [EXCP_INT ] ="INT (device interrupt)" , + [EXCP_DTLBMISS ] ="DTLBMISS (data tlb miss)" , + [EXCP_ITLBMISS ] ="ITLBMISS (code tlb miss)" , + [EXCP_RANGE ] ="RANGE" , + [EXCP_SYSCALL ] ="SYSCALL" , + [EXCP_FPE ] ="FPE" , + [EXCP_TRAP ] ="TRAP" , + }; +return STR_ARRAY_ELEM_OR_NULL (excp_name, excp) ?:"unknown" ; +} + G_NORETURN void or1k_raise_exception(OpenRISCCPU *cpu, uint32_t excp) {CPUState *cs =CPU (cpu);
target/or1k/interrupt.c +1 -18
@@ -66,26 +66,9 @@ void openrisc_cpu_do_interrupt(CPUState *cs) }if (exception >0 && exception <EXCP_NR ) { -static const char *const int_name[EXCP_NR ] = { - [EXCP_RESET ] ="RESET" , - [EXCP_BUSERR ] ="BUSERR (bus error)" , - [EXCP_DPF ] ="DFP (data protection fault)" , - [EXCP_IPF ] ="IPF (code protection fault)" , - [EXCP_TICK ] ="TICK (timer interrupt)" , - [EXCP_ALIGN ] ="ALIGN" , - [EXCP_ILLEGAL ] ="ILLEGAL" , - [EXCP_INT ] ="INT (device interrupt)" , - [EXCP_DTLBMISS ] ="DTLBMISS (data tlb miss)" , - [EXCP_ITLBMISS ] ="ITLBMISS (code tlb miss)" , - [EXCP_RANGE ] ="RANGE" , - [EXCP_SYSCALL ] ="SYSCALL" , - [EXCP_FPE ] ="FPE" , - [EXCP_TRAP ] ="TRAP" , - }; -qemu_log_mask (CPU_LOG_INT ,"CPU: %d INT: %s\n" , cs->cpu_index, - int_name[exception]); +openrisc_excp_name (exception));hwaddr vect_pc = exception <<8 ;if (env->cpucfgr &CPUCFGR_EVBARP ) {
Signature · 1 line
2.55.0
PATCH v3 20/33 target/ppc: Name the EBB exceptions
In reply to Philippe Mathieu-DaudéPOWERPC_EXCP_PERFM_EBB and POWERPC_EXCP_EXTERNAL_EBB are raised on POWER8+. With '-d int', powerpc_excp() logs them through powerpc_excp_name(), which has no entry for them and reaches g_assert_not_reached(), aborting QEMU. Add their names.
--- target/ppc/excp_helper.c | 2 ++ 1 file changed, 2 insertions(+)
target/ppc/excp_helper.c +2 -0
@@ -100,6 +100,8 @@ static const char *powerpc_excp_name(int excp)case POWERPC_EXCP_SDOOR_HV :return "SDOOR_HV" ;case POWERPC_EXCP_HVIRT :return "HVIRT" ;case POWERPC_EXCP_SYSCALL_VECTORED :return "SYSCALL_VECTORED" ; +case POWERPC_EXCP_PERFM_EBB :return "PERFM_EBB" ; +case POWERPC_EXCP_EXTERNAL_EBB :return "EXTERNAL_EBB" ;default :g_assert_not_reached (); }
Signature · 1 line
2.55.0
PATCH v3 21/33 target/ppc: Use a static table in powerpc_excp_name()
In reply to Philippe Mathieu-DaudéReplace the switch statement with a static lookup table.
Unlisted exception codes now return "unknown" instead of reaching g_assert_not_reached(), so with '-d int' they are logged instead of aborting QEMU. Do this before registering the function as the CPUClass::exception_name() handler, which must accept any code.
--- target/ppc/excp_helper.c | 137 ++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 68 deletions(-)
target/ppc/excp_helper.c +69 -68
@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qemu/log.h" +#include "qemu/cutils.h" #include "system/memory.h" #include "system/tcg.h" #include "system/system.h"
@@ -37,74 +38,74 @@static const char *powerpc_excp_name (int excp) { -switch (excp) { -case POWERPC_EXCP_CRITICAL :return "CRITICAL" ; -case POWERPC_EXCP_MCHECK :return "MCHECK" ; -case POWERPC_EXCP_DSI :return "DSI" ; -case POWERPC_EXCP_ISI :return "ISI" ; -case POWERPC_EXCP_EXTERNAL :return "EXTERNAL" ; -case POWERPC_EXCP_ALIGN :return "ALIGN" ; -case POWERPC_EXCP_PROGRAM :return "PROGRAM" ; -case POWERPC_EXCP_FPU :return "FPU" ; -case POWERPC_EXCP_SYSCALL :return "SYSCALL" ; -case POWERPC_EXCP_APU :return "APU" ; -case POWERPC_EXCP_DECR :return "DECR" ; -case POWERPC_EXCP_FIT :return "FIT" ; -case POWERPC_EXCP_WDT :return "WDT" ; -case POWERPC_EXCP_DTLB :return "DTLB" ; -case POWERPC_EXCP_ITLB :return "ITLB" ; -case POWERPC_EXCP_DEBUG :return "DEBUG" ; -case POWERPC_EXCP_SPEU :return "SPEU" ; -case POWERPC_EXCP_EFPDI :return "EFPDI" ; -case POWERPC_EXCP_EFPRI :return "EFPRI" ; -case POWERPC_EXCP_EPERFM :return "EPERFM" ; -case POWERPC_EXCP_DOORI :return "DOORI" ; -case POWERPC_EXCP_DOORCI :return "DOORCI" ; -case POWERPC_EXCP_GDOORI :return "GDOORI" ; -case POWERPC_EXCP_GDOORCI :return "GDOORCI" ; -case POWERPC_EXCP_HYPPRIV :return "HYPPRIV" ; -case POWERPC_EXCP_RESET :return "RESET" ; -case POWERPC_EXCP_DSEG :return "DSEG" ; -case POWERPC_EXCP_ISEG :return "ISEG" ; -case POWERPC_EXCP_HDECR :return "HDECR" ; -case POWERPC_EXCP_TRACE :return "TRACE" ; -case POWERPC_EXCP_HDSI :return "HDSI" ; -case POWERPC_EXCP_HISI :return "HISI" ; -case POWERPC_EXCP_HDSEG :return "HDSEG" ; -case POWERPC_EXCP_HISEG :return "HISEG" ; -case POWERPC_EXCP_VPU :return "VPU" ; -case POWERPC_EXCP_PIT :return "PIT" ; -case POWERPC_EXCP_EMUL :return "EMUL" ; -case POWERPC_EXCP_IFTLB :return "IFTLB" ; -case POWERPC_EXCP_DLTLB :return "DLTLB" ; -case POWERPC_EXCP_DSTLB :return "DSTLB" ; -case POWERPC_EXCP_FPA :return "FPA" ; -case POWERPC_EXCP_DABR :return "DABR" ; -case POWERPC_EXCP_IABR :return "IABR" ; -case POWERPC_EXCP_SMI :return "SMI" ; -case POWERPC_EXCP_PERFM :return "PERFM" ; -case POWERPC_EXCP_THERM :return "THERM" ; -case POWERPC_EXCP_VPUA :return "VPUA" ; -case POWERPC_EXCP_SOFTP :return "SOFTP" ; -case POWERPC_EXCP_MAINT :return "MAINT" ; -case POWERPC_EXCP_MEXTBR :return "MEXTBR" ; -case POWERPC_EXCP_NMEXTBR :return "NMEXTBR" ; -case POWERPC_EXCP_ITLBE :return "ITLBE" ; -case POWERPC_EXCP_DTLBE :return "DTLBE" ; -case POWERPC_EXCP_VSXU :return "VSXU" ; -case POWERPC_EXCP_FU :return "FU" ; -case POWERPC_EXCP_HV_EMU :return "HV_EMU" ; -case POWERPC_EXCP_HV_MAINT :return "HV_MAINT" ; -case POWERPC_EXCP_HV_FU :return "HV_FU" ; -case POWERPC_EXCP_SDOOR :return "SDOOR" ; -case POWERPC_EXCP_SDOOR_HV :return "SDOOR_HV" ; -case POWERPC_EXCP_HVIRT :return "HVIRT" ; -case POWERPC_EXCP_SYSCALL_VECTORED :return "SYSCALL_VECTORED" ; -case POWERPC_EXCP_PERFM_EBB :return "PERFM_EBB" ; -case POWERPC_EXCP_EXTERNAL_EBB :return "EXTERNAL_EBB" ; -default : -g_assert_not_reached (); - } +static const char *const excp_names[POWERPC_EXCP_NB ] = { + [POWERPC_EXCP_CRITICAL ] ="CRITICAL" , + [POWERPC_EXCP_MCHECK ] ="MCHECK" , + [POWERPC_EXCP_DSI ] ="DSI" , + [POWERPC_EXCP_ISI ] ="ISI" , + [POWERPC_EXCP_EXTERNAL ] ="EXTERNAL" , + [POWERPC_EXCP_ALIGN ] ="ALIGN" , + [POWERPC_EXCP_PROGRAM ] ="PROGRAM" , + [POWERPC_EXCP_FPU ] ="FPU" , + [POWERPC_EXCP_SYSCALL ] ="SYSCALL" , + [POWERPC_EXCP_APU ] ="APU" , + [POWERPC_EXCP_DECR ] ="DECR" , + [POWERPC_EXCP_FIT ] ="FIT" , + [POWERPC_EXCP_WDT ] ="WDT" , + [POWERPC_EXCP_DTLB ] ="DTLB" , + [POWERPC_EXCP_ITLB ] ="ITLB" , + [POWERPC_EXCP_DEBUG ] ="DEBUG" , + [POWERPC_EXCP_SPEU ] ="SPEU" , + [POWERPC_EXCP_EFPDI ] ="EFPDI" , + [POWERPC_EXCP_EFPRI ] ="EFPRI" , + [POWERPC_EXCP_EPERFM ] ="EPERFM" , + [POWERPC_EXCP_DOORI ] ="DOORI" , + [POWERPC_EXCP_DOORCI ] ="DOORCI" , + [POWERPC_EXCP_GDOORI ] ="GDOORI" , + [POWERPC_EXCP_GDOORCI ] ="GDOORCI" , + [POWERPC_EXCP_HYPPRIV ] ="HYPPRIV" , + [POWERPC_EXCP_RESET ] ="RESET" , + [POWERPC_EXCP_DSEG ] ="DSEG" , + [POWERPC_EXCP_ISEG ] ="ISEG" , + [POWERPC_EXCP_HDECR ] ="HDECR" , + [POWERPC_EXCP_TRACE ] ="TRACE" , + [POWERPC_EXCP_HDSI ] ="HDSI" , + [POWERPC_EXCP_HISI ] ="HISI" , + [POWERPC_EXCP_HDSEG ] ="HDSEG" , + [POWERPC_EXCP_HISEG ] ="HISEG" , + [POWERPC_EXCP_VPU ] ="VPU" , + [POWERPC_EXCP_PIT ] ="PIT" , + [POWERPC_EXCP_EMUL ] ="EMUL" , + [POWERPC_EXCP_IFTLB ] ="IFTLB" , + [POWERPC_EXCP_DLTLB ] ="DLTLB" , + [POWERPC_EXCP_DSTLB ] ="DSTLB" , + [POWERPC_EXCP_FPA ] ="FPA" , + [POWERPC_EXCP_DABR ] ="DABR" , + [POWERPC_EXCP_IABR ] ="IABR" , + [POWERPC_EXCP_SMI ] ="SMI" , + [POWERPC_EXCP_PERFM ] ="PERFM" , + [POWERPC_EXCP_THERM ] ="THERM" , + [POWERPC_EXCP_VPUA ] ="VPUA" , + [POWERPC_EXCP_SOFTP ] ="SOFTP" , + [POWERPC_EXCP_MAINT ] ="MAINT" , + [POWERPC_EXCP_MEXTBR ] ="MEXTBR" , + [POWERPC_EXCP_NMEXTBR ] ="NMEXTBR" , + [POWERPC_EXCP_ITLBE ] ="ITLBE" , + [POWERPC_EXCP_DTLBE ] ="DTLBE" , + [POWERPC_EXCP_VSXU ] ="VSXU" , + [POWERPC_EXCP_FU ] ="FU" , + [POWERPC_EXCP_HV_EMU ] ="HV_EMU" , + [POWERPC_EXCP_HV_MAINT ] ="HV_MAINT" , + [POWERPC_EXCP_HV_FU ] ="HV_FU" , + [POWERPC_EXCP_SDOOR ] ="SDOOR" , + [POWERPC_EXCP_SDOOR_HV ] ="SDOOR_HV" , + [POWERPC_EXCP_HVIRT ] ="HVIRT" , + [POWERPC_EXCP_SYSCALL_VECTORED ] ="SYSCALL_VECTORED" , + [POWERPC_EXCP_PERFM_EBB ] ="PERFM_EBB" , + [POWERPC_EXCP_EXTERNAL_EBB ] ="EXTERNAL_EBB" , + }; + +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; }static void dump_syscall (CPUPPCState *env)
Signature · 1 line
2.55.0
PATCH v3 22/33 target/ppc: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéExpose powerpc_excp_name() prototype and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve PPC exception codes to names.
--- target/ppc/cpu.h | 2 ++ target/ppc/cpu_init.c | 1 + target/ppc/excp_helper.c | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-)
target/ppc/cpu.h +2 -0
@@ -153,6 +153,8 @@ enum { POWERPC_EXCP_SYSCALL_USER = 0x203, /* System call in user mode only */ }; +const char *powerpc_excp_name (int excp); +/* Exceptions error codes */ enum {/* Exception subtypes for POWERPC_EXCP_ALIGN */
target/ppc/cpu_init.c +1 -0
@@ -7529,6 +7529,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, const void *data) &pcc->parent_phases); cc->class_by_name = ppc_cpu_class_by_name; + cc->exception_name = powerpc_excp_name; cc->list_cpus = ppc_cpu_list; cc->dump_state = ppc_cpu_dump_state; cc->set_pc = ppc_cpu_set_pc;
target/ppc/excp_helper.c +3 -2
@@ -34,9 +34,8 @@/*****************************************************************************/ /* Exception processing */ -#ifndef CONFIG_USER_ONLY -static const char *powerpc_excp_name(int excp) +const char *powerpc_excp_name (int excp) {static const char *const excp_names[POWERPC_EXCP_NB ] = { [POWERPC_EXCP_CRITICAL ] ="CRITICAL" ,
@@ -108,6 +107,8 @@ static const char *powerpc_excp_name(int excp)return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; } +#ifndef CONFIG_USER_ONLY +static void dump_syscall (CPUPPCState *env) { qemu_log_mask(CPU_LOG_INT, "syscall r0=%016" PRIx64
Signature · 1 line
2.55.0
PATCH v3 23/33 target/riscv: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFactor riscv_excp_name() and riscv_intr_name() out of riscv_cpu_get_trap_name(). Register riscv_excp_name() as the CPUClass::exception_name() handler, so the common exception logging can resolve RISCV exception codes to names.
--- target/riscv/cpu.h | 1 + target/riscv/cpu.c | 20 ++++++++++---------- target/riscv/tcg/op_helper.c | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-)
target/riscv/cpu.h +1 -0
@@ -672,6 +672,7 @@ G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr); +const char *riscv_excp_name (int excp);char *riscv_isa_string (RISCVCPU *cpu);int riscv_cpu_max_xlen (RISCVCPUClass *mcc);bool riscv_cpu_option_set (RISCVCPU *cpu,const char *optname);
target/riscv/cpu.c +10 -10
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/qemu-print.h" #include "qemu/ctype.h" #include "qemu/log.h"
@@ -398,6 +399,11 @@ static const char * const riscv_excp_names[] = { [RISCV_EXCP_SEMIHOST] = "semihost", }; +const char *riscv_excp_name (int excp) +{ +return STR_ARRAY_ELEM_OR_NULL (riscv_excp_names, excp) ?:"unknown" ; +} +static const char *const riscv_intr_names[] = { [IRQ_U_SOFT ] ="u_software" , [IRQ_S_SOFT ] ="s_software" ,
@@ -417,17 +423,10 @@ static const char * const riscv_intr_names[] = {const char *riscv_cpu_get_trap_name (uint64_t cause,bool async) { -if (async) { -if ((cause <ARRAY_SIZE (riscv_intr_names)) && riscv_intr_names[cause]) { -return riscv_intr_names[cause]; - } - }else { -if ((cause <ARRAY_SIZE (riscv_excp_names)) && riscv_excp_names[cause]) { -return riscv_excp_names[cause]; - } - } +const char *name = async ?STR_ARRAY_ELEM_OR_NULL (riscv_intr_names, cause) + :STR_ARRAY_ELEM_OR_NULL (riscv_excp_names, cause); -return "(unknown)" ; +return name ?:"unknown" ; }void riscv_cpu_set_misa_ext (CPURISCVState *env,uint32_t ext)
@@ -3128,6 +3127,7 @@ static void riscv_cpu_common_class_init(ObjectClass *c, const void *data) &mcc->parent_phases); cc->class_by_name = riscv_cpu_class_by_name; + cc->exception_name = riscv_excp_name; cc->dump_state = riscv_cpu_dump_state; cc->set_pc = riscv_cpu_set_pc; cc->get_pc = riscv_cpu_get_pc;
target/riscv/tcg/op_helper.c +1 -1
@@ -41,7 +41,7 @@ G_NORETURN void riscv_raise_exception(CPURISCVState *env,CPUState *cs =env_cpu (env);trace_riscv_exception (exception, -riscv_cpu_get_trap_name (exception, false), +riscv_excp_name (exception), env->pc); cs->exception_index = exception;
Signature · 1 line
2.55.0
Re: [PATCH v3 23/33] target/riscv: Register CPUClass::exception_name() handler
Quoted 7 lines · Philippe Mathieu-Daudé
Factor
riscv_excp_name()andriscv_intr_name()out ofriscv_cpu_get_trap_name(). Registerriscv_excp_name()as theCPUClass::exception_name()handler, so the common exception logging can resolve RISCV exception codes to names.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>
Thanks,
Chao
Quoted 87 lines
--- target/riscv/cpu.h | 1 + target/riscv/cpu.c | 20 ++++++++++---------- target/riscv/tcg/op_helper.c | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-)target/riscv/cpu.h +1
-0@@ -672,6 +672,7 @@ G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,bool riscv_cpu_tlb_fill (CPUState *cs,vaddr address,int size,MMUAccessType access_type,int mmu_idx,bool probe,uintptr_t retaddr); +const char *riscv_excp_name (int excp);char *riscv_isa_string (RISCVCPU *cpu);int riscv_cpu_max_xlen (RISCVCPUClass *mcc);bool riscv_cpu_option_set (RISCVCPU *cpu,const char *optname);target/riscv/cpu.c +10
-10@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/qemu-print.h" #include "qemu/ctype.h" #include "qemu/log.h" @@ -398,6 +399,11 @@ static const char * const riscv_excp_names[] = { [RISCV_EXCP_SEMIHOST] = "semihost", }; +const char *riscv_excp_name (int excp) +{ +return STR_ARRAY_ELEM_OR_NULL (riscv_excp_names, excp) ?:"unknown" ; +} +static const char *const riscv_intr_names[] = { [IRQ_U_SOFT ] ="u_software" , [IRQ_S_SOFT ] ="s_software" ,@@ -417,17 +423,10 @@ static const char * const riscv_intr_names[] = {const char *riscv_cpu_get_trap_name (uint64_t cause,bool async) { -if (async) { -if ((cause <ARRAY_SIZE (riscv_intr_names)) && riscv_intr_names[cause]) { -return riscv_intr_names[cause]; - } - }else { -if ((cause <ARRAY_SIZE (riscv_excp_names)) && riscv_excp_names[cause]) { -return riscv_excp_names[cause]; - } - } +const char *name = async ?STR_ARRAY_ELEM_OR_NULL (riscv_intr_names, cause) + :STR_ARRAY_ELEM_OR_NULL (riscv_excp_names, cause); -return "(unknown)" ; +return name ?:"unknown" ; }void riscv_cpu_set_misa_ext (CPURISCVState *env,uint32_t ext)@@ -3128,6 +3127,7 @@ static void riscv_cpu_common_class_init(ObjectClass *c, const void *data) &mcc->parent_phases); cc->class_by_name = riscv_cpu_class_by_name; + cc->exception_name = riscv_excp_name; cc->dump_state = riscv_cpu_dump_state; cc->set_pc = riscv_cpu_set_pc; cc->get_pc = riscv_cpu_get_pc;target/riscv/tcg/op_helper.c +1
-1@@ -41,7 +41,7 @@ G_NORETURN void riscv_raise_exception(CPURISCVState *env,CPUState *cs =env_cpu (env);trace_riscv_exception (exception, -riscv_cpu_get_trap_name (exception, false), +riscv_excp_name (exception), env->pc); cs->exception_index = exception;Signature · 1 line
2.55.0
PATCH v3 24/33 target/rx: Unify BRK and INT trap handling
In reply to Philippe Mathieu-DaudéBRK is equivalent to INT #0, so route both instructions through the same trap helper.
--- target/rx/helper.h | 3 +-- target/rx/op_helper.c | 7 +------ target/rx/translate.c | 21 ++++++++++----------- 3 files changed, 12 insertions(+), 19 deletions(-)
target/rx/helper.h +1 -2
@@ -2,8 +2,7 @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env) DEF_HELPER_1(raise_access_fault, noreturn, env) DEF_HELPER_1(raise_privilege_violation, noreturn, env) DEF_HELPER_1(wait, noreturn, env) -DEF_HELPER_2(rxint, noreturn, env, i32) -DEF_HELPER_1(rxbrk, noreturn, env) +DEF_HELPER_2(trap, noreturn, env, i32) DEF_HELPER_3(rx_fadd, f32, env, f32, f32) DEF_HELPER_3(rx_fsub, f32, env, f32, f32)DEF_HELPER_3 (rx_fmul, f32, env, f32, f32)
target/rx/op_helper.c +1 -6
@@ -455,12 +455,7 @@ G_NORETURN void helper_wait(CPURXState *env)raise_exception (env,EXCP_HLT ,0 ); } -G_NORETURN void helper_rxint(CPURXState *env, uint32_t vec) +G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) {raise_exception (env,0x100 + vec,0 ); } - -G_NORETURN void helper_rxbrk(CPURXState *env) -{ -raise_exception (env,0x100 ,0 ); -}
target/rx/translate.c +10 -11
@@ -2170,26 +2170,25 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a)return true; } +static bool do_trap (DisasContext *ctx,uint8_t vec) +{ +tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); +gen_helper_trap (tcg_env,tcg_constant_i32 (vec)); + ctx->base.is_jmp =DISAS_NORETURN ; +return true; +} +/* brk */ static bool trans_BRK (DisasContext *ctx,arg_BRK *a) { -tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxbrk (tcg_env); - ctx->base.is_jmp =DISAS_NORETURN ; -return true; +return do_trap (ctx,0 ); }/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -TCGv_i32 vec; -tcg_debug_assert (a->imm <0x100 ); - vec =tcg_constant_i32 (a->imm); -tcg_gen_movi_i32 (cpu_pc, ctx->base.pc_next); -gen_helper_rxint (tcg_env, vec); - ctx->base.is_jmp =DISAS_NORETURN ; -return true; +return do_trap (ctx, a->imm); }/* wait */
Signature · 1 line
2.55.0
PATCH v3 25/33 target/rx: Define exception vector constants
In reply to Philippe Mathieu-DaudéFrom: Yonggang Luo <[email protected]>
Name RX exception vectors and trap ranges, and use the definitions throughout exception handling and exception raising.
Assert that exception indexes remain within the defined range before accessing their vector tables.
--- target/rx/cpu.h | 13 +++++++++++++ target/rx/helper.c | 21 +++++++++++---------- target/rx/op_helper.c | 10 +++++----- target/rx/translate.c | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-)
target/rx/cpu.h +13 -0
@@ -71,6 +71,19 @@ enum { NUM_REGS = 16, }; +#define RX_EXCP_TRAP_COUNT 0x100 + +enum { +RX_EXCP_PRIVILEGE_VIOLATION =20 , +RX_EXCP_ACCESS =21 , +RX_EXCP_ILLEGAL_INSTRUCTION =23 , +RX_EXCP_FPU =25 , +RX_EXCP_NMI =30 , +RX_EXCP_TRAP_BASE =0x100 ,/* Up to RX_EXCP_TRAP_COUNT */ +}; + +#define RX_EXCP_COUNT (RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT) + typedef struct CPUArchState { /* CPU registers */ uint32_t regs[NUM_REGS]; /* general registers */
target/rx/helper.c +11 -10
@@ -86,13 +86,14 @@ void rx_cpu_do_interrupt(CPUState *cs) env->isp -=4 ;cpu_stl_le_data (env, env->isp, env->pc); -if (vec <0x100 ) { - env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); - }else { +assert (vec <RX_EXCP_COUNT ); +if (vec >=RX_EXCP_TRAP_BASE ) { env->pc =cpu_ldl_le_data (env, env->intb + (vec &0xff ) *4 ); + }else { + env->pc =cpu_ldl_le_data (env,0xffffff80 + vec *4 ); } -if (vec ==30 ) { +if (vec ==RX_EXCP_NMI ) {/* Non-maskable interrupt */ qemu_plugin_vcpu_interrupt_cb (cs, last_pc); }else {
@@ -100,22 +101,22 @@ void rx_cpu_do_interrupt(CPUState *cs) }switch (vec) { -case 20 : +case RX_EXCP_PRIVILEGE_VIOLATION : expname ="privilege violation" ;break ; -case 21 : +case RX_EXCP_ACCESS : expname ="access exception" ;break ; -case 23 : +case RX_EXCP_ILLEGAL_INSTRUCTION : expname ="illegal instruction" ;break ; -case 25 : +case RX_EXCP_FPU : expname ="fpu exception" ;break ; -case 30 : +case RX_EXCP_NMI : expname ="non-maskable interrupt" ;break ; - case 0x100 ... 0x1ff: + case RX_EXCP_TRAP_BASE ... RX_EXCP_TRAP_BASE + RX_EXCP_TRAP_COUNT - 1: expname ="unconditional trap" ; } qemu_log_mask(CPU_LOG_INT, "exception 0x%02x [%s] raised\n",
target/rx/op_helper.c +5 -5
@@ -115,7 +115,7 @@ static void update_fpsw(CPURXState *env, float32 ret, uintptr_t retaddr) enable =FIELD_EX32 (env->fpsw,FPSW ,ENABLE ); enable |=1 <<5 ;/* CE always enabled */ if (cause & enable) { -raise_exception (env,21 , retaddr); +raise_exception (env,RX_EXCP_ACCESS , retaddr); } } }
@@ -432,17 +432,17 @@ void raise_exception(CPURXState *env, int index, G_NORETURN void helper_raise_privilege_violation(CPURXState *env) { -raise_exception (env,20 ,GETPC ()); +raise_exception (env,RX_EXCP_PRIVILEGE_VIOLATION ,GETPC ()); } G_NORETURN void helper_raise_access_fault(CPURXState *env) { -raise_exception (env,21 ,GETPC ()); +raise_exception (env,RX_EXCP_ACCESS ,GETPC ()); } G_NORETURN void helper_raise_illegal_instruction(CPURXState *env) { -raise_exception (env,23 ,GETPC ()); +raise_exception (env,RX_EXCP_ILLEGAL_INSTRUCTION ,GETPC ()); } G_NORETURN void helper_wait(CPURXState *env)
@@ -457,5 +457,5 @@ G_NORETURN void helper_wait(CPURXState *env) G_NORETURN void helper_trap(CPURXState *env, uint32_t vec) { -raise_exception (env,0x100 + vec,0 ); +raise_exception (env,RX_EXCP_TRAP_BASE + vec,0 ); }
target/rx/translate.c +1 -1
@@ -2187,7 +2187,7 @@ static bool trans_BRK(DisasContext *ctx, arg_BRK *a)/* int #imm */ static bool trans_INT (DisasContext *ctx,arg_INT *a) { -tcg_debug_assert (a->imm <0x100 ); +tcg_debug_assert (a->imm <RX_EXCP_TRAP_COUNT );return do_trap (ctx, a->imm); }
Signature · 1 line
2.55.0
PATCH v3 26/33 target/rx: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFactor rx_exception_name() out of rx_cpu_do_interrupt() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve RX exception codes to names.
With '-d int', unlisted codes are now logged as "unknown" instead of "unknown exception".
--- target/rx/cpu.h | 1 + target/rx/cpu.c | 1 + target/rx/helper.c | 53 ++++++++++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 21 deletions(-)
target/rx/cpu.h +1 -0
@@ -147,6 +147,7 @@ struct RXCPUClass {#define CPU_RESOLVING_TYPE TYPE_RX_CPUconst char *rx_crname (uint8_t cr); +const char *rx_exception_name (int excp);void rx_cpu_do_interrupt (CPUState *cpu);bool rx_cpu_exec_interrupt (CPUState *cpu,int int_req);hwaddr rx_cpu_get_phys_addr_debug (CPUState *cpu,vaddr addr);
target/rx/cpu.c +1 -0
@@ -245,6 +245,7 @@ static void rx_cpu_class_init(ObjectClass *klass, const void *data) &rcc->parent_phases); cc->class_by_name = rx_cpu_class_by_name; + cc->exception_name = rx_exception_name; cc->dump_state = rx_cpu_dump_state; cc->set_pc = rx_cpu_set_pc; cc->get_pc = rx_cpu_get_pc;
target/rx/helper.c +32 -21
72 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v3 27/33 target/s390x: Implement and register CPUClass::exception_name()
In reply to Philippe Mathieu-DaudéImplement s390x_exception_name() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve s390x exception codes to names.
Use the new helper in s390_cpu_do_interrupt() and helper_exception().
With '-d int', s390_cpu_do_interrupt() now logs the exception name in parentheses after its number.
--- target/s390x/cpu.h | 2 ++ target/s390x/cpu.c | 1 + target/s390x/interrupt.c | 16 ++++++++++++++++ target/s390x/tcg/excp_helper.c | 6 ++++-- target/s390x/tcg/misc_helper.c | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-)
target/s390x/cpu.h +2 -0
@@ -437,6 +437,8 @@ QEMU_BUILD_BUG_ON(FLAG_MASK_PER_IFETCH_NULLIFY !=#define EXCP_IO 7/* I/O interrupt */ #define EXCP_MCHK 8/* machine check */ +const char *s390x_exception_name (int excp); +#define INTERRUPT_EXT_CPU_TIMER (1 << 3)#define INTERRUPT_EXT_CLOCK_COMPARATOR (1 << 4)#define INTERRUPT_EXTERNAL_CALL (1 << 5)
target/s390x/cpu.c +1 -0
@@ -408,6 +408,7 @@ static void s390_cpu_class_init(ObjectClass *oc, const void *data) &scc->parent_phases); cc->class_by_name = s390_cpu_class_by_name; + cc->exception_name = s390x_exception_name; cc->list_cpus = s390_cpu_list; cc->dump_state = s390_cpu_dump_state; cc->query_cpu_fast = s390_query_cpu_fast;
target/s390x/interrupt.c +16 -0
@@ -8,6 +8,7 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "cpu.h" #include "kvm/kvm_s390x.h" #include "s390x-internal.h"
@@ -19,6 +20,21 @@#include "hw/s390x/s390_flic.h" #endif +const char *s390x_exception_name (int excp) +{ +static const char *const excp_names[] = { + [EXCP_EXT ] ="external interrupt" , + [EXCP_SVC ] ="supervisor call" , + [EXCP_PGM ] ="program interruption" , + [EXCP_RESTART ] ="restart interrupt" , + [EXCP_STOP ] ="stop interrupt" , + [EXCP_IO ] ="I/O interrupt" , + [EXCP_MCHK ] ="machine check" , + }; + +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; +} +/* Ensure to exit the TB after this call! */ void trigger_pgm_exception (CPUS390XState *env,uint32_t code) {
target/s390x/tcg/excp_helper.c +4 -2
@@ -508,8 +508,10 @@ void s390_cpu_do_interrupt(CPUState *cs)bool stopped = false;uint64_t last_pc = cpu->env.psw.addr; -qemu_log_mask (CPU_LOG_INT ,"%s: %d at psw=%" PRIx64":%" PRIx64"\n" , - __func__, cs->exception_index, env->psw.mask, env->psw.addr); +qemu_log_mask (CPU_LOG_INT ,"%s: %d (%s) at psw=%" PRIx64":%" PRIx64"\n" , + __func__, cs->exception_index, +s390x_exception_name (cs->exception_index), + env->psw.mask, env->psw.addr); try_deliver:/* handle machine checks */
target/s390x/tcg/misc_helper.c +2 -1
@@ -61,7 +61,8 @@ void HELPER(exception)(CPUS390XState *env, uint32_t excp) {CPUState *cs =env_cpu (env); -HELPER_LOG ("%s: exception %d\n" , __func__, excp); +HELPER_LOG ("%s: exception %d (%s)\n" , __func__, excp, +s390x_exception_name (excp)); cs->exception_index = excp;cpu_loop_exit (cs); }
Signature · 1 line
2.55.0
Re: [PATCH v3 27/33] target/s390x: Implement and register CPUClass::exception_name()
Quoted 11 lines · Philippe Mathieu-Daudé
Implement
s390x_exception_name()and register it as theCPUClass::exception_name()handler, so the common exception logging can resolve s390x exception codes to names.Use the new helper in
s390_cpu_do_interrupt()andhelper_exception().With '-d int',
s390_cpu_do_interrupt()now logs the exception name in parentheses after its number.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>
Quoted 7 lines
--- target/s390x/cpu.h | 2 ++ target/s390x/cpu.c | 1 + target/s390x/interrupt.c | 16 ++++++++++++++++ target/s390x/tcg/excp_helper.c | 6 ++++-- target/s390x/tcg/misc_helper.c | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-)
PATCH v3 28/33 target/sh4: Define exception vector constants
In reply to Philippe Mathieu-DaudéFrom: Yonggang Luo <[email protected]>
Name SH4 exception vectors and use the definitions throughout exception handling and exception raising.
--- target/sh4/cpu.h | 21 +++++++++++++++ target/sh4/helper.c | 60 +++++++++++++++++++++--------------------- target/sh4/op_helper.c | 16 +++++------ 3 files changed, 59 insertions(+), 38 deletions(-)
target/sh4/cpu.h +21 -0
@@ -135,6 +135,27 @@ typedef struct memory_content {struct memory_content *next; } memory_content; +/* Guest trap numbers. */ +enum { +SH4_EXCP_RESET =0x000 , +SH4_EXCP_MANUAL_RESET =0x020 , +SH4_EXCP_TLB_MISS =0x040 , +SH4_EXCP_DTLB_MISS_WRITE =0x060 , +SH4_EXCP_INITIAL_PAGE_WRITE =0x080 , +SH4_EXCP_TLB_VIOLATION =0x0a0 , +SH4_EXCP_DTLB_VIOLATION_WRITE =0x0c0 , +SH4_EXCP_ADDR_ERROR =0x0e0 , +SH4_EXCP_DATA_WRITE =0x100 , +SH4_EXCP_FPU =0x120 , +SH4_EXCP_TLB_MULTIPLE =0x140 , +SH4_EXCP_TRAPA =0x160 , +SH4_EXCP_ILLEGAL_INSTRUCTION =0x180 , +SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION =0x1a0 , +SH4_EXCP_USER_BREAK =0x1e0 , +SH4_EXCP_FPU_DISABLE =0x800 , +SH4_EXCP_SLOT_FPU_DISABLE =0x820 , +}; + typedef struct CPUArchState { uint32_t flags; /* general execution flags */ uint32_t gregs[24]; /* general registers */
target/sh4/helper.c +30 -30
138 lines not on this page · raw message
target/sh4/op_helper.c +8 -8
@@ -33,10 +33,10 @@ void superh_cpu_do_unaligned_access(CPUState *cs, vaddr addr,switch (access_type) {case MMU_INST_FETCH :case MMU_DATA_LOAD : - cs->exception_index =0x0e0 ; + cs->exception_index =SH4_EXCP_ADDR_ERROR ;break ;case MMU_DATA_STORE : - cs->exception_index =0x100 ; + cs->exception_index =SH4_EXCP_DATA_WRITE ;break ;default :g_assert_not_reached ();
@@ -67,22 +67,22 @@ void raise_exception(CPUSH4State *env, int index,void helper_raise_illegal_instruction (CPUSH4State *env) { -raise_exception (env,0x180 ,0 ); +raise_exception (env,SH4_EXCP_ILLEGAL_INSTRUCTION ,0 ); }void helper_raise_slot_illegal_instruction (CPUSH4State *env) { -raise_exception (env,0x1a0 ,0 ); +raise_exception (env,SH4_EXCP_SLOT_ILLEGAL_INSTRUCTION ,0 ); }void helper_raise_fpu_disable (CPUSH4State *env) { -raise_exception (env,0x800 ,0 ); +raise_exception (env,SH4_EXCP_FPU_DISABLE ,0 ); }void helper_raise_slot_fpu_disable (CPUSH4State *env) { -raise_exception (env,0x820 ,0 ); +raise_exception (env,SH4_EXCP_SLOT_FPU_DISABLE ,0 ); }void helper_sleep (CPUSH4State *env)
@@ -97,7 +97,7 @@ void helper_sleep(CPUSH4State *env)void helper_trapa (CPUSH4State *env,uint32_t tra) { env->tra = tra <<2 ; -raise_exception (env,0x160 ,0 ); +raise_exception (env,SH4_EXCP_TRAPA ,0 ); }void helper_exclusive (CPUSH4State *env)
@@ -255,7 +255,7 @@ static void update_fpscr(CPUSH4State *env, uintptr_t retaddr) cause = (env->fpscr &FPSCR_CAUSE_MASK ) >>FPSCR_CAUSE_SHIFT ; enable = (env->fpscr &FPSCR_ENABLE_MASK ) >>FPSCR_ENABLE_SHIFT ;if (cause & enable) { -raise_exception (env,0x120 , retaddr); +raise_exception (env,SH4_EXCP_FPU , retaddr); } } }
Signature · 1 line
2.55.0
PATCH v3 29/33 target/sh4: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFactor sh4_exception_name() out of superh_cpu_do_interrupt() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve SH-4 exception codes to names.
--- target/sh4/cpu.h | 1 + target/sh4/cpu.c | 1 + target/sh4/helper.c | 101 +++++++++++++++++++++++--------------------- 3 files changed, 56 insertions(+), 47 deletions(-)
target/sh4/cpu.h +1 -0
@@ -258,6 +258,7 @@ struct SuperHCPUClass {uint32_t cvr; }; +const char *sh4_exception_name (int excp);void superh_cpu_dump_state (CPUState *cpu,FILE *f,int flags);int superh_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int superh_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);
target/sh4/cpu.c +1 -0
@@ -334,6 +334,7 @@ static void superh_cpu_class_init(ObjectClass *oc, const void *data) &scc->parent_phases); cc->class_by_name = superh_cpu_class_by_name; + cc->exception_name = sh4_exception_name; cc->dump_state = superh_cpu_dump_state; cc->set_pc = superh_cpu_set_pc; cc->get_pc = superh_cpu_get_pc;
target/sh4/helper.c +54 -47
113 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v3 30/33 target/sh4: Use a static table in sh4_exception_name()
In reply to Philippe Mathieu-DaudéReplace the switch statement with a static lookup table.
With '-d int', unlisted exception codes are now logged as "unknown" instead of "???".
--- target/sh4/helper.c | 66 ++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 46 deletions(-)
target/sh4/helper.c +20 -46
@@ -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 )
Signature · 1 line
2.55.0
PATCH v3 31/33 target/sparc: Remove always-defined DEBUG_PCALL
In reply to Philippe Mathieu-DaudéDEBUG_PCALL has been unconditionally defined for 14 years now (see commit b884fc5ecaa "target-sparc: Make CPU_LOG_INT useful by default"), so the #ifdef guards around the exception name table and the CPU_LOG_INT block are always taken. Remove the define and the now-redundant guards.
--- target/sparc/int64_helper.c | 6 ------ 1 file changed, 6 deletions(-)
target/sparc/int64_helper.c +0 -6
@@ -26,9 +26,6 @@#include "trace.h" #include "qemu/plugin.h" -#define DEBUG_PCALL - -#ifdef DEBUG_PCALL static const char *const excp_names[0x80 ] = { [TT_TFAULT ] ="Instruction Access Fault" , [TT_TMISS ] ="Instruction Access MMU Miss" ,
@@ -62,7 +59,6 @@ static const char * const excp_names[0x80] = { [TT_EXTINT | 0xe] = "External Interrupt 14", [TT_EXTINT | 0xf] = "External Interrupt 15", }; -#endif #if !defined(CONFIG_USER_ONLY )void cpu_check_irqs (CPUSPARCState *env)
@@ -138,7 +134,6 @@ void sparc_cpu_do_interrupt(CPUState *cs)int intno = cs->exception_index;trap_state *tsptr; -#ifdef DEBUG_PCALL if (qemu_loglevel_mask (CPU_LOG_INT )) {static int count;const char *name;
@@ -177,7 +172,6 @@ void sparc_cpu_do_interrupt(CPUState *cs)#endif count++; } -#endif #if !defined(CONFIG_USER_ONLY )if (env->tl >= env->maxtl) { cpu_abort(cs, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
Signature · 1 line
2.55.0
PATCH v3 32/33 target/sparc: Register CPUClass::exception_name() handler
In reply to Philippe Mathieu-DaudéFor each SPARC / SPARC64 target:
factor sparc_exception_name() out of sparc_cpu_do_interrupt() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve SPARC exception codes to names.
With '-d int', unlisted codes are now logged as "unknown" instead of "Unknown". On SPARC, the "Error state" abort message now names trap instructions (0x80-0xff) instead of calling them "Unknown". On SPARC64, trap 0x1ff is now named "Hyperprivileged Trap Instruction"; it was "Unknown" because of an off-by-one in the former range check.
--- target/sparc/cpu.h | 1 + target/sparc/cpu.c | 1 + target/sparc/int32_helper.c | 22 ++++++++-------------- target/sparc/int64_helper.c | 36 ++++++++++++++++++------------------ 4 files changed, 28 insertions(+), 32 deletions(-)
target/sparc/cpu.h +1 -0
@@ -583,6 +583,7 @@ extern const VMStateDescription vmstate_sparc_cpu;hwaddr sparc_cpu_get_phys_addr_debug (CPUState *cpu,vaddr addr);#endif +const char *sparc_exception_name (int excp);void sparc_cpu_do_interrupt (CPUState *cpu);int sparc_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int sparc_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);
target/sparc/cpu.c +1 -0
@@ -1098,6 +1098,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, const void *data) &scc->parent_phases); cc->class_by_name = sparc_cpu_class_by_name; + cc->exception_name = sparc_exception_name; cc->list_cpus = sparc_cpu_list, cc->parse_features = sparc_cpu_parse_features; cc->dump_state = sparc_cpu_dump_state;
target/sparc/int32_helper.c +8 -14
@@ -19,6 +19,7 @@#include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "qemu/cutils.h" #include "cpu.h" #include "trace.h" #include "accel/tcg/cpu-ldst.h"
@@ -58,12 +59,12 @@ static const char * const excp_names[0x80] = { [TT_NCP_INSN] = "Coprocessor Disabled", }; -static const char *excp_name_str (int32_t exception_index) +const char *sparc_exception_name (int excp) { -if (exception_index <0 || exception_index >=ARRAY_SIZE (excp_names)) { -return "Unknown" ; +if (excp >=0x80 && excp <0x100 ) { +return "Trap Instruction" ; } -return excp_names[exception_index]; +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; }#if !defined(CONFIG_USER_ONLY )
@@ -107,15 +108,7 @@ void sparc_cpu_do_interrupt(CPUState *cs)if (qemu_loglevel_mask (CPU_LOG_INT )) {static int count; -const char *name; - -if (intno <0 || intno >=0x100 ) { - name ="Unknown" ; - }else if (intno >=0x80 ) { - name ="Trap Instruction" ; - }else { - name =excp_name_str (intno); - } +const char *name =sparc_exception_name (intno);qemu_log ("%6d: %s (v=%02x)\n" , count, name, intno);log_cpu_state (cs,0 );
@@ -129,7 +122,8 @@ void sparc_cpu_do_interrupt(CPUState *cs) }else {cpu_abort (cs,"Trap 0x%02x (%s) while interrupts disabled, " "Error state" , - cs->exception_index,excp_name_str (cs->exception_index)); + cs->exception_index, +sparc_exception_name (cs->exception_index)); }return ; }
target/sparc/int64_helper.c +18 -18
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/main-loop.h" #include "cpu.h" #include "exec/cpu-common.h"
@@ -60,6 +61,22 @@ static const char * const excp_names[0x80] = { [TT_EXTINT | 0xf] = "External Interrupt 15", }; +const char *sparc_exception_name (int excp) +{ +if (excp <0 || excp >=0x200 ) { +return "unknown" ; + }else if (excp >=0x180 ) { +return "Hyperprivileged Trap Instruction" ; + }else if (excp >=0x100 ) { +return "Trap Instruction" ; + }else if (excp >=0xc0 ) { +return "Window Fill" ; + }else if (excp >=0x80 ) { +return "Window Spill" ; + } +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; +} +#if !defined(CONFIG_USER_ONLY )void cpu_check_irqs (CPUSPARCState *env) {
@@ -136,24 +153,7 @@ void sparc_cpu_do_interrupt(CPUState *cs)if (qemu_loglevel_mask (CPU_LOG_INT )) {static int count; -const char *name; - -if (intno <0 || intno >=0x1ff ) { - name ="Unknown" ; - }else if (intno >=0x180 ) { - name ="Hyperprivileged Trap Instruction" ; - }else if (intno >=0x100 ) { - name ="Trap Instruction" ; - }else if (intno >=0xc0 ) { - name ="Window Fill" ; - }else if (intno >=0x80 ) { - name ="Window Spill" ; - }else { - name = excp_names[intno]; -if (!name) { - name ="Unknown" ; - } - } +const char *name =sparc_exception_name (intno);qemu_log ("%6d: %s (v=%04x)\n" , count, name, intno);log_cpu_state (cs,0 );
Signature · 1 line
2.55.0
PATCH v3 33/33 target/xtensa: Implement and register CPUClass::exception_name()
In reply to Philippe Mathieu-DaudéImplement xtensa_exception_name() and register it as the CPUClass::exception_name() handler, so the common exception logging can resolve Xtensa exception codes to names.
Use the new helper in xtensa_cpu_do_interrupt().
With '-d int', xtensa_cpu_do_interrupt() now logs the exception name after its number.
--- target/xtensa/cpu.h | 2 ++ target/xtensa/cpu.c | 24 ++++++++++++++++++++++++ target/xtensa/exc_helper.c | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-)
target/xtensa/cpu.h +2 -0
@@ -262,6 +262,8 @@ enum {EXC_MAX }; +const char *xtensa_exception_name (int excp); +enum {ILLEGAL_INSTRUCTION_CAUSE =0 ,SYSCALL_CAUSE ,
target/xtensa/cpu.c +24 -0
@@ -29,6 +29,7 @@*/ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "exec/cpu-defs.h" #include "cpu.h"
@@ -239,6 +240,28 @@ static void xtensa_cpu_disas_set_info(const CPUState *cs, : BFD_ENDIAN_LITTLE; } +const char *xtensa_exception_name (int excp) +{ +static const char *const excp_names[] = { + [EXC_RESET0 ] ="reset" , + [EXC_RESET1 ] ="reset" , + [EXC_MEMORY_ERROR ] ="memory error" , + [EXC_WINDOW_OVERFLOW4 ] ="window overflow" , + [EXC_WINDOW_UNDERFLOW4 ] ="window underflow" , + [EXC_WINDOW_OVERFLOW8 ] ="window overflow" , + [EXC_WINDOW_UNDERFLOW8 ] ="window underflow" , + [EXC_WINDOW_OVERFLOW12 ] ="window overflow" , + [EXC_WINDOW_UNDERFLOW12 ] ="window underflow" , + [EXC_IRQ ] ="interrupt" , + [EXC_KERNEL ] ="kernel" , + [EXC_USER ] ="user" , + [EXC_DOUBLE ] ="double" , + [EXC_DEBUG ] ="debug" , + }; + +return STR_ARRAY_ELEM_OR_NULL (excp_names, excp) ?:"unknown" ; +} +static void xtensa_cpu_realizefn (DeviceState *dev,Error **errp) {CPUState *cs =CPU (dev);
@@ -348,6 +371,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, const void *data) &xcc->parent_phases); cc->class_by_name = xtensa_cpu_class_by_name; + cc->exception_name = xtensa_exception_name; cc->dump_state = xtensa_cpu_dump_state; cc->set_pc = xtensa_cpu_set_pc; cc->get_pc = xtensa_cpu_get_pc;
target/xtensa/exc_helper.c +2 -1
@@ -236,9 +236,10 @@ void xtensa_cpu_do_interrupt(CPUState *cs)case EXC_USER :case EXC_DOUBLE :case EXC_DEBUG : -qemu_log_mask (CPU_LOG_INT ,"%s(%d) " +qemu_log_mask (CPU_LOG_INT ,"%s(%d:%s) " "pc = %08x, a0 = %08x, ps = %08x, ccount = %08x\n" , __func__, cs->exception_index, +xtensa_exception_name (cs->exception_index), env->pc, env->regs[0 ], env->sregs[PS ], env->sregs[CCOUNT ]);if (env->config->exception_vector[cs->exception_index]) {
Signature · 1 line
2.55.0