zephyr/arch
Chris Coleman 443f1cb58c arch: arm: aarch32: cortex_m: fault: Prevent BusFault from HardFault
A Cortex-M BusFault often arises from the execution of a function
pointer that got corrupted.

The Zephyr Cortex-M fault handler de-references the `$pc` in
`z_arm_is_synchronous_svc()` to determine if the fault was due to a
kernel oops (ARCH_EXCEPT). This can cause a BusFault if the pc itself
was corrupt. A BusFault from a HardFault will trigger ARM Cortex-M
"Lockup" preventing the Zephyr fault handler from running to
completion. This in turn, results in no fault handling information
getting dumped by the Zephyr fault handler.

To fix the issue, we can simply set the `CCR.BFHFNMIGN` bit prior to
the instruction address dereference which will cause the processor to
ignore the BusFault and return a value of 0x0 instead of entering
lockup. After the operation is complete, we clear `CCR.BFHFNMIGN` as
it would be unexpected for any other code in the fault handler to
trigger a fault.

The issue can be reproduced programmatically with:

```
  void (*unaligned_func)(void) = (void (*)(void))0x50000001;
  unaligned_func();
```

I bumped into this problem while debugging an issue on the nRF9160DK
(`west build --board nrf9160dk_nrf9160ns`) and confirmed that after
making this change I now see the full fault handler print:

```
[00:00:45.582,214] <err> os: Exception occurred in Secure State
[00:00:45.582,244] <err> os: ***** HARD FAULT *****
[...]
[00:00:45.583,984] <err> os: Current thread: 0x2000d340 (shell_uart)
[00:00:45.829,498] <err> fatal_error: Resetting system
```

Signed-off-by: Chris Coleman <chris@memfault.com>
2022-08-10 11:59:38 +02:00
..
arc arch: arc: remove unused <soc.h> 2022-08-03 07:46:14 -04:00
arm arch: arm: aarch32: cortex_m: fault: Prevent BusFault from HardFault 2022-08-10 11:59:38 +02:00
arm64 test,arch: fix few odd suffix include paths 2022-07-18 14:44:47 -04:00
common gen_isr_tables.py: Move to scripts directory 2022-07-07 17:58:34 +00:00
mips arch: mips: add mising braces to single line if statements 2022-07-06 11:00:45 -04:00
nios2 arch: comply to coding guidelines MISRA C:2012 Rule 14.4 2022-07-20 09:28:38 -05:00
posix scripts: move user_wordsize.py to scripts/build/user_wordsize.py 2022-07-12 10:03:45 +02:00
riscv arch: riscv: Align semihost_exec function at 16-byte boundary 2022-08-08 10:52:34 +02:00
sparc SPARC: reduce z_thread_entry_wrapper 2022-08-03 12:05:49 +02:00
x86 arch: x86: Fix wrong identation 2022-08-07 14:27:56 +01:00
xtensa intel_adsp: meteorlake: Initialize stack flush pointer SR 2022-07-25 16:00:22 -04:00
CMakeLists.txt
Kconfig arch: introduce config DCLS 2022-08-04 12:51:25 +09:00