Skip to content

Commit eddf058

Browse files
committed
arch: arm: be able to infer Z_ARCH_EXCEPT() for baseline SOCs
This commit makes it possible to infer Z_ARCH_EXCEPT() calls in SVCs that escalate to HardFault due to being invoked from priority level equal or higher to the interrupt priority level of the SVC Handler. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent a09d3d6 commit eddf058

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

arch/arm/core/cortex_m/fault.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,30 @@ static u32_t HardFault(z_arch_esf_t *esf, bool *recoverable)
609609
PR_FAULT_INFO("***** HARD FAULT *****");
610610

611611
#if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
612+
/* Workaround for #18712:
613+
* HardFault may be due to escalation, as a result of
614+
* an SVC instruction that could not be executed; this
615+
* can occur if Z_ARCH_EXCEPT() is called by an ISR,
616+
* which executes at priority equal to the SVC handler
617+
* priority. We handle the case of Kernel OOPS and Stack
618+
* Fail here.
619+
*/
620+
u16_t *ret_addr = (u16_t *)esf->basic.pc;
621+
/* SVC is a 16-bit instruction. On a synchronous SVC
622+
* escalated to Hard Fault, the return address is the
623+
* next instruction, i.e. after the SVC.
624+
*/
625+
#define _SVC_OPCODE 0xDF00
626+
627+
u16_t fault_insn = *(ret_addr - 1);
628+
if (((fault_insn & 0xff00) == _SVC_OPCODE) &&
629+
((fault_insn & 0x00ff) == _SVC_CALL_RUNTIME_EXCEPT)) {
630+
631+
PR_EXC("Z_ARCH_EXCEPT with reason %x\n", esf->basic.r0);
632+
reason = esf->basic.r0;
633+
}
634+
#undef _SVC_OPCODE
635+
612636
*recoverable = memory_fault_recoverable(esf);
613637
#elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
614638
*recoverable = false;

0 commit comments

Comments
 (0)