Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

2.5 Faults, escalation and fault status registers

Enabling. HardFault is always enabled. SHCSR.MEMFAULTENA, BUSFAULTENA, USGFAULTENA and, with the Security Extension, SECUREFAULTENA enable the configurable faults (Main Extension).

Escalation. A synchronous configurable fault escalates to HardFault, with HFSR.FORCED = 1, when either of these holds:

  • the fault is disabled;
  • its priority is not high enough to preempt the current execution priority, for example a UsageFault inside a handler of equal or higher priority, or with FAULTMASK set.

HFSR.VECTTBL indicates a BusFault on a vector table read during exception processing, which is always reported as HardFault. On Baseline, all of these fault conditions go to HardFault.

Status. The CFSR status bits are still set when a fault escalates, so always read them in a HardFault handler.

CFSR  0xE000ED28
  [31:16] UFSR  UNDEFINSTR INVSTATE INVPC NOCP
                STKOF UNALIGNED DIVBYZERO
  [15:8]  BFSR  IBUSERR PRECISERR IMPRECISERR
                UNSTKERR STKERR LSPERR BFARVALID
  [7:0]   MMFSR IACCVIOL DACCVIOL MUNSTKERR
                MSTKERR MLSPERR MMARVALID
MMFAR / BFAR: fault address, valid only
              when MMARVALID / BFARVALID = 1

The status bits are write-one-to-clear. UNALIGNED and DIVBYZERO trap ordinary unaligned accesses and divides by zero only when CCR.UNALIGN_TRP and CCR.DIV_0_TRP are set. Unaligned LDM/STM/LDRD/STRD, exclusive and load-acquire/store-release accesses always fault. STKOF reports a violation of the v8-M stack limit registers, MSPLIM and PSPLIM.

Precise vs imprecise BusFault.

  • A precise BusFault (PRECISERR) is synchronous. The stacked ReturnAddress identifies the faulting instruction, and BFAR is usually valid.
  • An imprecise BusFault (IMPRECISERR) is asynchronous, typically a buffered store whose bus error came back later. The stacked ReturnAddress points somewhere after the store, and BFAR is not valid.
  • An asynchronous BusFault becomes pending and is taken when its priority allows. It is not escalated on priority grounds the way a synchronous fault is. If BusFault is disabled, it is reported as HardFault instead.

Coming from A-profile: There is no ESR_ELx/FAR_ELx pair with an exception-class field. Status is split across CFSR’s three sub-registers plus HFSR, and an imprecise BusFault behaves like an asynchronous SError: the reported PC is not the faulting instruction.

Checkpoint

Q2.5.1 SHCSR.USGFAULTENA = 0. Thread code executes a UDF instruction. What does the HardFault handler observe?

  • A. Nothing, because a disabled UsageFault means the UDF executes as a NOP
  • B. CFSR is zero, because only HFSR records escalated faults
  • C. HFSR.DEBUGEVT = 1, because UDF is treated as a breakpoint
  • D. HardFault is taken with HFSR.FORCED = 1, and CFSR.UFSR.UNDEFINSTR = 1 identifies the original cause
Answer

D. A disabled configurable fault escalates to HardFault and sets HFSR.FORCED. The UFSR bit is still set, which is why a HardFault handler should always dump CFSR. ‘CFSR stays zero’ is the tempting assumption, but the sub-register status bits are recorded whether or not the fault escalated.

Read more: Armv8-M ARM (DDI0553), HFSR, CFSR, SHCSR; fault escalation

Q2.5.2 BFSR shows IMPRECISERR = 1 and BFARVALID = 0. What is the correct conclusion?

  • A. The stacked ReturnAddress identifies the faulting load or store
  • B. The fault was asynchronous, for example a buffered store. The stacked ReturnAddress is somewhere after the faulting access, and no fault address was recorded
  • C. The fault came from an instruction fetch
  • D. The MPU blocked the access, so MMFAR holds the address
Answer

B. IMPRECISERR means the bus error was reported asynchronously relative to the instruction that caused it, so neither the stacked PC nor BFAR pins it down. An instruction-fetch error sets IBUSERR, and an MPU violation is a MemManage fault, not a BusFault.

Read more: Armv8-M ARM (DDI0553), BFSR: PRECISERR, IMPRECISERR, BFARVALID