3.2 Entry and return
What the PE writes on entry to AArch64 ELx
When an exception is taken to an AArch64 target ELx, the PE performs these steps, all as one atomic architectural action:
SPSR_ELx← PSTATE of the interrupted context (the AArch64 or AArch32 format, depending on where it came from).ELR_ELx← preferred return address (3.1). If the exception came from AArch32, bits[63:32]are zero.ESR_ELx← syndrome, for synchronous exceptions and SError. IRQ and FIQ report no syndrome, soESR_ELxholds nothing meaningful for them. It is not guaranteed to be “unchanged” either: the register description makesESR_ELxUNKNOWN on any exception return from ELx.FAR_ELx← faulting virtual address, only for the exception types listed below. OtherwiseFAR_ELxbecomes UNKNOWN.- PSTATE updated as in the table below, and the PC is set to the vector address.
Exception entry does not save or modify the general-purpose registers, and saving them is the handler’s job. On entry from AArch32, do not rely on the upper 32 bits of the X registers that held AArch32 state. The Arm ARM constrains what they may contain (see the AArch32-to-AArch64 register mapping rules), but software should treat them as not meaningful.
PSTATE on entry
| Field | Value after entry to ELx | Note |
|---|---|---|
EL | target EL | |
nRW | 0 (AArch64) | |
SP | 1 (use SP_ELx) | |
D, A, I, F | all set to 1 | regardless of which class was taken |
SS | 0 | software step state, see 16.1 |
IL | 0 | |
BTYPE | 0 | FEAT_BTI |
PAN | set to 1 if SCTLR_ELx.SPAN == 0, otherwise unchanged | FEAT_PAN. Applies to entry to EL1, and to EL2 when HCR_EL2.{E2H,TGE} == {1,1} |
UAO | 0 | FEAT_UAO |
SSBS | SCTLR_ELx.DSSBS | FEAT_SSBS |
TCO | 1 | FEAT_MTE. Tag checks are suppressed until software clears TCO |
ALLINT | NOT SCTLR_ELx.SPINTMASK (applied whenever FEAT_NMI is implemented, even if SCTLR_ELx.NMI == 0) | FEAT_NMI, see 4.3 |
EXLOCK | per GCSCR_ELx.EXLOCKEN | FEAT_GCS, see 13.2 |
DIT, NZCV, SM, ZA | unchanged | SME streaming mode survives exception entry |
For the newer fields (PM, UINJ and the like), see 2.4 and the Arm ARM pseudocode for AArch64.TakeException(), which is the authoritative list.
SPSR_ELx (AArch64 format)
| Bits | Field | Bits | Field |
|---|---|---|---|
[3:0] | M[3:0]: EL and SP (0b0000 EL0t, 0b0100 EL1t, 0b0101 EL1h, 0b1000 EL2t, 0b1001 EL2h, 0b1100 EL3t, 0b1101 EL3h) | [20] | IL |
[4] | M[4]: 0 = AArch64 | [21] | SS |
[9:6] | D A I F | [22] | PAN |
[11:10] | BTYPE | [23] | UAO |
[12] | SSBS | [24] | DIT |
[13] | ALLINT | [25] | TCO |
[31:28] | N Z C V | [63:32] | newer fields (PM, EXLOCK, …), see DDI0487 |
ESR_ELx: EC, IL, ISS
63 56 55 32 31 26 25 24 0
+----------+--------------+--------+---+------------------------+
| RES0 | ISS2 | EC |IL | ISS |
+----------+--------------+--------+---+------------------------+
EC [31:26]is the exception class. It decides how to parse ISS.IL [25]is the instruction length: 1 = 32-bit. It is 0 only for a 16-bit T32 instruction trap. It is also 1 for SError, Instruction Aborts, PC and SP alignment faults, Data Aborts withISV == 0, Illegal Execution state, debug exceptions other thanBRK/BKPT, and EC0x00.ISS [24:0]is class-specific. For Data Aborts,ISS[24]isISV(theSAS/SRT/… instruction-syndrome fields are valid). For many trap classes it isCV, which only says that theCONDfield (for a conditional AArch32 instruction) is valid.ISS2 [55:32]is used by FEAT_LS64 (Xs), FEAT_GCS, FEAT_THE and FEAT_S1POE/S2POE fault reporting, among others.
EC summary
| EC | Meaning | EC | Meaning |
|---|---|---|---|
0x00 | Unknown reason (UNDEFINED instruction) | 0x1F | IMPLEMENTATION DEFINED, to EL3 |
0x01 | Trapped WFI/WFE/WFIT/WFET | 0x20 | Instruction Abort, lower EL |
0x07 | Trapped SVE/SIMD/FP access (CPACR/CPTR) | 0x21 | Instruction Abort, same EL |
0x09 | Trapped PAuth instruction (HCR_EL2.API/SCR_EL3.API) | 0x22 | PC alignment fault |
0x0D | Branch Target exception (BTI) | 0x24 | Data Abort, lower EL |
0x0E | Illegal Execution state | 0x25 | Data Abort, same EL |
0x15 | SVC (AArch64) | 0x26 | SP alignment fault |
0x16 | HVC (AArch64) | 0x27 | Memory Operation exception (FEAT_MOPS) |
0x17 | SMC (AArch64) | 0x2C | Trapped floating-point exception (AArch64) |
0x18 | Trapped MSR/MRS/system instruction | 0x2D | GCS exception |
0x19 | Trapped SVE access | 0x2F | SError |
0x1C | PAC authentication failure (FEAT_FPAC) | 0x30/0x31 | Breakpoint, lower/same EL |
0x1D | Trapped SME access | 0x32/0x33 | Software step, lower/same EL |
0x1E | Granule Protection Check (FEAT_RME) | 0x34/0x35 | Watchpoint, lower/same EL |
0x11/0x12/0x13 | SVC/HVC/SMC from AArch32 | 0x3C | BRK (AArch64) |
The full table, with the ISS layout of each class and the DFSC/IFSC values, is Appendix D. Abort ISS fields (WnR, S1PTW, CM, FnV, ISV/SAS/SRT) are in 5.8.
FAR_ELx validity
FAR_ELx is written only on:
- Instruction Abort and Data Abort (EC
0x20,0x21,0x24,0x25); - PC alignment fault (
0x22); - Watchpoint (
0x34,0x35), where the recorded address is within the watched range but which byte is recorded is constrained, not exact; - Granule Protection Check exceptions on an instruction fetch or data access;
- SError with FEAT_RASv2, but only when
ISS.VFV == 1(3.4).
For every other exception, FAR_ELx is UNKNOWN. That means it is not even guaranteed to keep its old value. Even for aborts, three rules apply:
- For a synchronous External abort that is not on a translation table walk,
ISS.FnV == 1meansFAR_ELxis UNKNOWN. - When the address was tagged (TBI), the top byte of the reported address can be UNKNOWN for some fault types. Treat
FAR[63:56]as reliable only where DDI0487 says so for the implemented features (FEAT_MTE changes this). FAR_ELxholds a VA. For a stage-2 fault the IPA is inHPFAR_EL2, and with FEAT_PFAR a PA can be inPFAR_ELx. See 5.8.
ERET and exception return
ERET (and ERETAA/ERETAB with PAuth) at ELx restores PC ← ELR_ELx and PSTATE ← SPSR_ELx, subject to a legality check. It is UNDEFINED at EL0. A return is an illegal exception return if SPSR_ELx asks for any of the following:
- an EL higher than the current EL;
- an EL that is not implemented, or an
M[3:0]encoding that is reserved (for example0b0001, EL0 withSP_ELx); - EL2 when EL2 is not enabled in the current Security state (for example Secure EL2 with
SCR_EL3.EEL2 == 0); - EL1 when EL2 is enabled and
HCR_EL2.TGE == 1(EL1 is not in use); - AArch32 (
M[4] == 1) at a level thatSCR_EL3.RW/HCR_EL2.RWdefine as AArch64, or AArch64 at a level defined as AArch32, or AArch32 where AArch32 is not implemented.
On an illegal return, PSTATE.EL, PSTATE.nRW and PSTATE.SP are unchanged, PSTATE.IL is set to 1, the other PSTATE fields are restored from SPSR, and the PC is restored from ELR_ELx. The return itself does not fault. The next instruction the PE attempts to execute takes an Illegal Execution state exception (EC 0x0E) to the current EL, with ELR pointing at that instruction (unless a higher-priority synchronous exception on that instruction, such as a PC alignment fault or an Instruction Abort, is taken first). This design guarantees that software never runs at an EL or Execution state it could not legally reach. A mis-built SPSR therefore shows up as an EC 0x0E exception at the same EL as the ERET, at the address you were trying to return to.
A return to AArch64 with ELR[1:0] != 0 is not illegal. It produces a PC alignment fault at the target when the first instruction is fetched.
// EL3 -> Non-secure EL2h, AArch64, DAIF masked
mov x0, #(0b1001) // M = EL2h
orr x0, x0, #(0xF << 6) // D A I F
msr SPSR_EL3, x0
adr x1, ns_el2_entry
msr ELR_EL3, x1
// SCR_EL3.NS=1, RW=1, HCE=1 already programmed (see 17.2)
eret
Context synchronization, and FEAT_ExS
By default, exception entry and exception return are context synchronization events. System register writes made before them are visible to instructions after them, without an ISB. That is why “write SCTLR_EL1 at EL2, then ERET” works.
FEAT_ExS (permitted from v8.5) makes this configurable per EL:
| Control | Bit | 0 | 1 |
|---|---|---|---|
SCTLR_ELx.EIS | 22 | Exception entry to ELx is not a context synchronization event | Entry is a context synchronization event |
SCTLR_ELx.EOS | 11 | ERET from ELx is not a context synchronization event | ERET is a context synchronization event |
Without FEAT_ExS these bits are RES1. With FEAT_ExS they reset to an architecturally UNKNOWN value, so software must write them to 1 explicitly: firmware that writes the whole register with the v8.0 RES1 pattern (for example TF-A’s SCTLR_EL3 reset value) keeps the synchronizing behaviour, but code that only read-modify-writes SCTLR_ELx from reset does not get it guaranteed. Clearing them is an optimization for hypervisors and kernels with hot entry paths. Clearing them also means that any system register write whose effect the next context depends on, such as TTBR, TCR or SCTLR before an ERET, needs an explicit ISB. The PSTATE values that entry itself writes still apply to the handler. What is lost is the synchronization of earlier context-changing operations, such as system-register writes not yet followed by an ISB. See 7.8 for the full context-synchronization rules, and note that neither entry nor return is a DSB: outstanding memory accesses are not waited for.
Bring-up note: when you see EC
0x0Eimmediately after a hand-offERET, decodeSPSR_ELx.MagainstSCR_EL3.{RW,NS,EEL2}andHCR_EL2.{RW,E2H,TGE}before anything else.ELRwill equal the entry point you returned to, which makes the bug look like “the next image crashed on its first instruction”.
Checkpoint
Q3.2.1 On a core that implements AArch32 at EL1, EL3 firmware writes SPSR_EL3 = 0x3C5 (EL1h, DAIF set) and ERETs to a Non-secure kernel, but SCR_EL3.RW == 0. What happens?
- A. The
ERETitself takes a synchronous exception to EL3 with EC0x0E - B. The return is illegal: the PE stays at EL3 with
PSTATE.IL == 1, the PC becomesELR_EL3, and the first instruction there takes an EC0x0Eexception to EL3 - C. The PE enters Non-secure EL1 in AArch32 state, because
SCR_EL3.RWoverridesSPSR.M[4] - D. Behaviour is UNPREDICTABLE
Answer
B. SPSR.M[4] == 0 requests AArch64, which conflicts with SCR_EL3.RW == 0, so this is an illegal exception return. EL, nRW and SP are kept, IL is set, and the PC is loaded from ELR. The Illegal Execution state exception is taken when the next instruction is executed, not by the ERET (A). The architecture defines this behaviour exactly, so it is neither “silently fixed up” (C) nor UNPREDICTABLE (D).
Read more: Arm ARM (DDI0487), Illegal return events from AArch64 state; The Illegal Execution state exception
Q3.2.2 A hypervisor on a core with FEAT_ExS sets SCTLR_EL2.EOS = 0. Before ERET to a guest it writes VTTBR_EL2 and HCR_EL2. Which statement is correct?
- A. No change is needed, because
ERETalways synchronizes system-register writes made at the same EL - B. A
DSB SYbeforeERETis sufficient - C. Only the
HCR_EL2write needs anISB, becauseVTTBR_EL2is only used by the walker - D. An
ISBis required beforeERET, because withEOS == 0the return is no longer a context synchronization event
Answer
D. EOS == 0 removes the guarantee that the ERET synchronizes earlier context-changing writes, so the guest’s first instructions could run under the old HCR_EL2 or stage-2 base. An ISB restores the guarantee. A DSB waits for memory accesses, not for system-register context (B). The walker is part of the context that must be synchronized too (C).
Read more: Arm ARM (DDI0487), SCTLR_EL2.EOS; Context synchronization event
Q3.2.3 An IRQ handler at EL1 logs ESR_EL1 and FAR_EL1, and both contain plausible values from a page fault handled earlier. What can you conclude?
- A. Nothing: an IRQ writes no syndrome or address, and both registers are UNKNOWN by then, so stale-looking values carry no information
- B. The IRQ was raised by the earlier page fault
- C. The hardware preserved them, which is guaranteed for asynchronous exceptions
- D.
ESR_EL1.IL == 0would distinguish the two cases
Answer
A. The syndrome registers are written only for exception types that report a syndrome or address. IRQ and FIQ write neither, FAR_EL1 is UNKNOWN for any exception other than the listed abort, alignment and watchpoint types, and both registers are made UNKNOWN by every exception return from EL1, including the one that ended the earlier page-fault handler. An implementation may happen to leave the old value, but software must not rely on it (C). Logging them in an IRQ path, or comparing them, is a frequent source of misleading crash reports.
Read more: Arm ARM (DDI0487), ESR_EL1; FAR_EL1; Exception entry