3.1 Exception types and the vector table
The four exception classes
Every AArch64 exception has a type, which selects one of four vector offsets inside a vector-table quadrant:
| Class | Generated by | Examples |
|---|---|---|
| Synchronous | Execution or attempted execution of an instruction, or an instruction fetch | SVC/HVC/SMC, traps (EC 0x18 and others), instruction and data aborts, PC and SP alignment faults, BRK, breakpoints, watchpoints, software step, Illegal Execution state, synchronous External aborts |
| IRQ | A physical or virtual IRQ signal | GIC interrupt signalled as IRQ, HCR_EL2.VI |
| FIQ | A physical or virtual FIQ signal | GIC Group 0 (or “other Security state” Group 1) interrupt signalled as FIQ, HCR_EL2.VF |
| SError | A physical or virtual System Error | asynchronous External abort, RAS error reported asynchronously, HCR_EL2.VSE |
IRQ, FIQ and SError are asynchronous: they are not generated by the instruction stream, and the architecture only requires them to be taken “in finite time” once pending and unmasked. Synchronous External aborts are reported through the synchronous vector with a Data or Instruction Abort EC. They are not SErrors, even though both come from the memory system. Debug exceptions are synchronous, and PSTATE.D controls whether most of them are taken (see 16.1).
Precise and imprecise
The Arm ARM defines an exception as precise when the PE state presented to the handler is consistent with every instruction before the preferred return address having executed and none at or after it having executed. (For some synchronous exceptions, such as an abort on a multi-register load or store, the architecture permits the faulting instruction to have partially updated registers or memory; DDI0487 lists which.)
- Synchronous exceptions are precise. The preferred return address is the faulting instruction for aborts and traps. For
SVC,HVCandSMCit is the next instruction. A trappedSMC(for example viaHCR_EL2.TSC, EC0x17) is reported with theSMCitself as the preferred return address, because it did not execute. - Physical and virtual IRQ and FIQ are taken precisely at an instruction boundary.
ELR_ELxis the first instruction that did not execute. - An SError can be imprecise. It is taken at some instruction boundary, but the error that caused it may come from a store retired many instructions earlier, or from no instruction at all (a line eviction, a prefetch, a poison detected by a scrubber). Without RAS information the handler cannot say which architectural state was affected. With FEAT_RAS,
ESR_ELx.AETclassifies how much state is recoverable. 3.4 covers this, including when an SError is attributable.
ESR_ELx.IL has nothing to do with precision. It gives the instruction length (32-bit, or 16-bit T32) and is 1 for exceptions not associated with a specific instruction, such as SError.
“Taken to ELx”
The target Exception level is decided by routing controls (3.3), never by the handler. The rules that never change are these:
- An exception is never taken to EL0.
- An exception is never taken to an EL lower than the current EL. An asynchronous exception routed to a lower EL stays pending until the PE drops to an EL where it can be taken.
- A synchronous exception generated at ELx is taken to ELx or higher. EL0 exceptions go to EL1 by default, or to EL2 when
HCR_EL2.TGE == 1or another EL2 control routes them there. - The target EL’s Execution state is fixed. If the target is AArch64, the handler runs in AArch64 using
VBAR_ELxof the target EL.
“Taken from the current EL” means the target EL equals the EL that was executing. “Taken from a lower EL” means the target EL is higher than the EL that was executing.
VBAR_ELx and the 16-entry layout
VBAR_EL1, VBAR_EL2 and VBAR_EL3 hold the table base. Bits [10:0] are RES0, so the table is 2 KB aligned. It is divided into four 512-byte quadrants of four 128-byte (32-instruction) entries:
| Offset | Taken from | Synchronous | IRQ | FIQ | SError |
|---|---|---|---|---|---|
0x000 | Current EL, SP_EL0 (PSTATE.SP == 0) | 0x000 | 0x080 | 0x100 | 0x180 |
0x200 | Current EL, SP_ELx (PSTATE.SP == 1) | 0x200 | 0x280 | 0x300 | 0x380 |
0x400 | Lower EL, AArch64 | 0x400 | 0x480 | 0x500 | 0x580 |
0x600 | Lower EL, AArch32 | 0x600 | 0x680 | 0x700 | 0x780 |
Two selection rules are easy to misremember.
Current EL, SP0 vs SPx depends on PSTATE.SP at the moment the exception was taken, not on the SP the handler will use. Exception entry always sets PSTATE.SP = 1, so every handler starts on SP_ELx. The SP0 quadrant exists for software that runs its main code on SP_EL0 at an elevated EL. BL31 in TF-A does this: its C runtime runs at EL3 with SPSel == 0, while SP_EL3 points to the per-CPU cpu_context_t. An exception raised by BL31 itself therefore lands in the 0x000 quadrant. TF-A treats those entries as fatal (“unhandled exception at EL3”), which is a useful first fact when you decode an EL3 crash.
Lower EL AArch64 vs AArch32 is determined by the Execution state of the Exception level immediately below the target EL, not by the state of the EL where the exception occurred. Take an exception from AArch32 EL0 to EL2 when EL1 is AArch64 and HCR_EL2.{E2H,TGE} != {1,1}. It uses the 0x400 (AArch64) quadrant of VBAR_EL2, because EL1 is the “next lower” level. The AArch64.TakeException() pseudocode has two refinements: for a target of EL3, the “next lower” level is EL2 if EL2 is enabled in the current Security state and EL1 otherwise; and for an exception from EL0 to EL2 with {E2H,TGE} == {1,1} (VHE host), it is EL0 itself, so an AArch32 EL0 task under a VHE host uses VBAR_EL2 + 0x600. On Armv9-A cores that implement AArch32 only at EL0 (or not at all), the 0x600 quadrant of VBAR_EL3 can never be selected, and that of VBAR_EL2 only in the VHE-host case. See 2.1.
There is no vector for “taken to the same EL from a different Security state”. A Secure EL1 exception routed to EL3 and a Non-secure EL1 exception routed to EL3 both use VBAR_EL3 + 0x400. The handler reads SCR_EL3.NS (and SCR_EL3.NSE with RME) to find out which world it came from.
.section .vectors, "ax"
.balign 2048 // VBAR_ELx[10:0] are RES0
vectors:
.irp q, cur_sp0, cur_spx, low64, low32
.irp t, sync, irq, fiq, serror
.balign 128 // 32 instructions per entry
b \q\()_\t
.endr
.endr
// install
adr x0, vectors
msr VBAR_EL3, x0
isb // see 7.8: a VBAR write needs context synchronization
An entry is 32 instructions, which is enough for a short save sequence before branching out. TF-A and Linux use the space in place for Spectre-BHB mitigation sequences at the 0x400/0x600 entries. See 14.4.
Bring-up note:
VBAR_EL3resets to an UNKNOWN value. An exception taken before the firstMSR VBAR_EL3(for example a synchronous External abort from a not-yet-enabled DRAM controller) branches to an UNKNOWN address. That usually shows up as a core that “hangs” with no UART output. ProgramVBAR_EL3with a minimal “logESR_EL3/ELR_EL3and spin” table as the first few instructions after reset. A table whose base is not 2 KB aligned does not fault: the low bits are RES0 and are ignored, so the entries are silently misindexed, and a recursive exception atVBAR + 0x200is the classic symptom (18.3).
Security note: with
SCR_EL3.FIQ == 1and a Secure EL1 TEE maskingPSTATE.F, a Group 0 FIQ still reaches EL3 atVBAR_EL3 + 0x500(lower EL, AArch64), because PSTATE masking does not apply to an exception targeting a higher EL (the only exception is the VHE-host EL0 case in 3.3). An EL3 dispatcher that assumes “FIQ means from Non-secure” without checkingSCR_EL3.NShas a confused-deputy bug.
Checkpoint
Q3.1.1 EL1 is AArch64 and EL0 runs an AArch32 application. HCR_EL2.TGE == 0. The application executes an instruction trapped to EL2 by an HCR_EL2 control. Which VBAR_EL2 offset is used?
- A.
0x600, because the instruction that trapped was executing in AArch32 - B.
0x200, because the exception is taken to EL2 using SP_EL2 - C.
0x400, because the quadrant is selected by the Execution state of the EL immediately below the target, which is AArch64 EL1 - D.
0x000, because EL0 uses SP_EL0
Answer
C. For exceptions from a lower EL, the vector quadrant depends on the Execution state of the next lower EL than the target, here EL1, which is AArch64. A is the tempting misreading (“the state where it happened”), and it is only true when EL1 is also AArch32. B and D are current-EL quadrants, and this exception comes from a lower EL.
Read more: Arm ARM (DDI0487), Exception vectors, “Vector offsets from vector table base address”
Q3.1.2 BL31 runs its C code at EL3 with SPSel == 0. A NULL-pointer dereference in that C code causes a Data Abort. Where does the PE branch, and which stack pointer is in use at the first instruction of the handler?
- A.
VBAR_EL3 + 0x000, running onSP_EL3 - B.
VBAR_EL3 + 0x200, running onSP_EL3 - C.
VBAR_EL3 + 0x000, running onSP_EL0 - D.
VBAR_EL3 + 0x400, running onSP_EL3
Answer
A. The quadrant reflects PSTATE.SP at the time of the exception (0, so “current EL with SP0”), but exception entry always sets PSTATE.SP to 1, so the handler starts on SP_EL3. C confuses the selector with the handler’s stack. D would apply only if the abort came from a lower EL.
Read more: Arm ARM (DDI0487), Exception entry; SPSel; VBAR_EL3
Q3.1.3 A handler for an SError cannot reconstruct which store caused it, while a handler for an IRQ always sees a clean instruction boundary. Which statement captures the architectural distinction?
- A. SErrors have
ESR_ELx.IL == 1, which marks them imprecise - B. IRQs are synchronous to the instruction stream, SErrors are asynchronous
- C. SErrors are always taken at the instruction after the faulting store
- D. Both are asynchronous, but an SError may be imprecise: the state at
ELR_ELxneed not reflect the instruction that caused the error
Answer
D. IRQ, FIQ and SError are all asynchronous. Interrupts are taken precisely at an instruction boundary, but an SError can be imprecise because the error may come from an earlier retired access or from no instruction at all. IL gives the instruction length (A is wrong), and B misclassifies IRQ.
Read more: Arm ARM (DDI0487), Synchronous and asynchronous exceptions; precise and imprecise exceptions; SError exceptions