Course: Computer Architectures
Source lesson: ARM Exceptions and Interrupts
Fault diagnosis
A handler reads a fault-status register to learn what happened and may read a fault-address register for a precise memory fault:
LDR r0, =FSRaddress
LDR r1, [r0]
TST r1, #maskThe source distinguishes several faults:
- NMI: high-priority event such as a watchdog or voltage warning.
- Hard Fault: serious fault or escalation when a specific handler cannot run.
- Usage Fault: invalid instruction, invalid branch state, division by zero or unaligned access when trapping is enabled.
- Bus Fault: invalid instruction/data bus access, stacking/unstacking failure, or forbidden peripheral access.
- Memory Management Fault: violation of MPU access or execution permissions.
A precise fault can identify the offending address. An imprecise fault may be reported after the original access has completed, making the exact instruction harder to identify.
Supervisor calls
SVC is a deliberate software exception used to request a privileged operating-system service:
SVC #5An SVC handler can find the request by:
- Testing bit 2 of
LRto chooseMSPorPSP. - Reading the stacked
PCat[stack,#24]. - Reading the halfword immediately before that
PC. - Extracting the low byte containing the SVC immediate.
The immediate value selects the requested service.
SysTick
SysTick is a 24-bit countdown timer that can generate periodic interrupts. It is useful for timing, alarms, and task switching.
Configuration sequence:
- Disable the timer.
- Write the interval to the reload register.
- Clear the current counter.
- Enable the clock, interrupt, and timer.
The timer has control/status, reload, current-value, and calibration registers. Writing to the current-value register clears the counter.
Retrieval questions
- What does a fault-status register tell the handler? The cause bits for the exception.
- Why does an SVC handler read
[stack,#24]? That is the automatically stacked PC. - What happens when SysTick reaches zero? The counter reloads and can raise an interrupt if enabled.