arch: option to generate simplified error codes

Add an option to generate simplified error codes instead of more
specific architecture specific error codes. Enable this by default in
tests to make exception tests more generic across hardware.

Fixes #54053.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2023-01-26 10:10:57 +10:00 committed by Stephanos Ioannidis
commit a3774fd51a
3 changed files with 31 additions and 1 deletions

View file

@ -501,6 +501,18 @@ config EXTRA_EXCEPTION_INFO
register state, when a fault occurs. This information can be useful
to collect for post-mortem analysis and debug of issues.
config SIMPLIFIED_EXCEPTION_CODES
bool "Convert arch specific exception codes to K_ERR_CPU_EXCEPTION"
default y if ZTEST
help
The same piece of faulty code (NULL dereference, etc) can result in
a multitude of potential exception codes at the CPU level, depending
upon whether addresses exist, an MPU is configured, the particular
implementation of the CPU or any number of other reasons. Enabling
this option collapses all the architecture specific exception codes
down to the generic K_ERR_CPU_EXCEPTION, which makes testing code
much more portable.
endmenu # Interrupt configuration
config INIT_ARCH_HW_AT_BOOT

View file

@ -194,8 +194,12 @@ bool z_arm_fault_undef_instruction(z_arch_esf_t *esf)
/* Print fault information */
LOG_ERR("***** UNDEFINED INSTRUCTION ABORT *****");
uint32_t reason = IS_ENABLED(CONFIG_SIMPLIFIED_EXCEPTION_CODES) ?
K_ERR_CPU_EXCEPTION :
K_ERR_ARM_UNDEFINED_INSTRUCTION;
/* Invoke kernel fatal exception handler */
z_arm_fatal_error(K_ERR_ARM_UNDEFINED_INSTRUCTION, esf);
z_arm_fatal_error(reason, esf);
/* All undefined instructions are treated as fatal for now */
return true;
@ -223,6 +227,11 @@ bool z_arm_fault_prefetch(z_arch_esf_t *esf)
reason = dump_fault(fs, ifar);
}
/* Simplify exception codes if requested */
if (IS_ENABLED(CONFIG_SIMPLIFIED_EXCEPTION_CODES) && (reason >= K_ERR_ARCH_START)) {
reason = K_ERR_CPU_EXCEPTION;
}
/* Invoke kernel fatal exception handler */
z_arm_fatal_error(reason, esf);
@ -290,6 +299,11 @@ bool z_arm_fault_data(z_arch_esf_t *esf)
reason = dump_fault(fs, dfar);
}
/* Simplify exception codes if requested */
if (IS_ENABLED(CONFIG_SIMPLIFIED_EXCEPTION_CODES) && (reason >= K_ERR_ARCH_START)) {
reason = K_ERR_CPU_EXCEPTION;
}
/* Invoke kernel fatal exception handler */
z_arm_fatal_error(reason, esf);

View file

@ -1124,6 +1124,10 @@ void z_arm_fault(uint32_t msp, uint32_t psp, uint32_t exc_return,
esf_copy.basic.xpsr &= ~(IPSR_ISR_Msk);
}
if (IS_ENABLED(CONFIG_SIMPLIFIED_EXCEPTION_CODES) && (reason >= K_ERR_ARCH_START)) {
reason = K_ERR_CPU_EXCEPTION;
}
z_arm_fatal_error(reason, &esf_copy);
}