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.1 Exception levels, Security states and execution states

At any moment a PE is described by three separate properties:

AxisValuesChanges at
Exception levelEL0, EL1, EL2, EL3exception entry, exception return (and reset)
Security stateSecure, Non-secure, Realm (RME), Root (RME)exception entry to or return from EL3, or a change of SCR_EL3.{NSE,NS} followed by an exception return
Execution stateAArch64, AArch32exception entry and exception return only (and reset)

Keeping these apart prevents most of the common confusion. “Secure EL1” is one point in this space. “EL3” is not a Security state. Being in AArch32 says nothing about which EL you are at.

Exception levels

The EL sets the privilege of the current software and which system registers it can reach. A register suffixed _ELn is accessible at ELn and above, with the exceptions covered in 2.5.

  • EL0: unprivileged applications. Always implemented.
  • EL1: OS kernel or a Secure OS such as OP-TEE. Always implemented.
  • EL2: hypervisor. Optional. Present in the Secure state only with FEAT_SEL2 (permitted from v8.4) and SCR_EL3.EEL2 = 1.
  • EL3: the monitor. Optional architecturally, but every practical TrustZone or RME system has it.

Exceptions are taken to the same or a higher EL, and exception returns go to the same or a lower EL. There is no instruction that changes the EL except by these two routes. CurrentEL (bits [3:2]) reports the EL, and reading it from EL0 is UNDEFINED.

Security states and which combinations exist

Without FEAT_RME there are two Security states. EL3 is always Secure, and SCR_EL3.NS selects the state of EL2/EL1/EL0. With FEAT_RME (permitted from v9.2) there are four. EL3 runs in Root, and the pair SCR_EL3.{NSE,NS} selects the state of the lower ELs:

SCR_EL3.{NSE,NS}Lower-EL Security state
0,0Secure
0,1Non-secure
1,0Reserved
1,1Realm

The resulting combinations:

ELNon-secureSecureRealmRoot
EL3noyes (only without RME)noyes (only with RME)
EL2yeswith FEAT_SEL2 and SCR_EL3.EEL2=1yesno
EL1yesyesyesno
EL0yesyesyesno

SCR_EL3.{NSE,NS} takes effect for the lower ELs on the next exception return from EL3. While the PE is executing at EL3 they do not change the state EL3 itself runs in, but they do select which lower-EL translation regime EL3’s AT and TLBI operations target, and which Secure or Non-secure copy of the banked GICv3 CPU-interface registers (such as ICC_IGRPEN1_EL1) EL3 accesses. 12.1 and 12.4 cover the memory side: PA spaces, the TZASC and the GPT.

Security note: The Security state determines which physical address space the PE’s accesses are made to. The Exception level does not. Secure EL0 can reach Secure PA space that Non-secure EL2 cannot. Reviews that treat “higher EL” as “more trusted” go wrong for Realm vs Non-secure EL2 in particular: Non-secure EL2 cannot access the Realm PA space at all, while Realm EL0 can access Realm PA space and, where its stage 2 maps it, Non-secure PA space.

Execution states

AArch64 and AArch32 are execution states. They are not modes. The execution state of an EL is fixed while that EL runs, and it can change only:

  • on exception entry, to the state of the target EL, which is never AArch32 if any lower EL is AArch64;
  • on exception return, to the state encoded in SPSR_ELx.M[4] (0 for AArch64, 1 for AArch32), subject to the controls below;
  • at reset, to the state the implementation resets into (for EL3, see RMR_EL3 and the core’s IMP DEF reset configuration).

The rule that ties the ELs together is that if an EL uses AArch32, all lower ELs use AArch32. Equivalently, an AArch64 EL is never below an AArch32 EL. Moving between execution states when an exception crosses ELs is called interprocessing. An ERET that requests AArch32 at a level that cannot use it, or AArch64 under an AArch32 level, is an illegal exception return: PSTATE.IL is set and the next instruction takes an Illegal Execution state exception (see 3.2).

Who decides the state of the next lower EL

ControlDecidesNotes
SCR_EL3.RWState of the EL directly below EL3: EL2 if EL2 is implemented and enabled in the target Security state, otherwise EL11 = AArch64. RAO/WI if the lower EL cannot use AArch32
HCR_EL2.RWState of EL1 when EL2 is enabled1 = AArch64. RAO/WI if EL1 cannot use AArch32. Not used when HCR_EL2.{E2H,TGE} = {1,1}, because then there is no EL1 guest
SPSR_EL1.M[4] / SPSR_EL2.M[4] on ERET to EL0State of EL0EL0 has no RW bit. Its state is chosen on every return, so an AArch64 kernel can run AArch32 and AArch64 processes side by side

SCR_EL3.RW is the most common bring-up bug in this group. Several SCR_EL3 fields reset to architecturally UNKNOWN values, so EL3 firmware must write the whole register, RW included, before the first ERET to an AArch64 BL33 or hypervisor. TF-A’s context-management library (lib/el3_runtime/aarch64/context_mgmt.c) derives it from the next image’s entry-point information (SPSR and security attributes).

What the architecture versions permit

  • Armv8-A permits AArch32 at any EL, subject to the “lower ELs follow” rule. Examples include AArch32 EL0 under an AArch64 kernel, a whole AArch32 Non-secure world under an AArch64 EL3, and even AArch32-only cores such as Cortex-A32. Support at each EL is IMPLEMENTATION DEFINED, and ID registers report it.
  • Armv9-A permits AArch32 at EL0 only. EL1, EL2 and EL3 are AArch64-only. AArch32 at EL0 is still optional (see 1.2).
  • Implementations have gone further and dropped AArch32 entirely. Cortex-X2 has no AArch32 support at any EL, and Cortex-A715 and later big and mid cores (and Cortex-A520 among the little cores) are AArch64-only. Cortex-A710 and Cortex-A510 still provide AArch32 at EL0. A DynamIQ cluster that mixes them is therefore asymmetric. Linux handles this with the opt-in allow_mismatched_32bit_el0 mode, which restricts 32-bit tasks to capable CPUs. Firmware is not affected, since it has no AArch32 code.

Treat the core list as an example. The authority for a given part is its TRM and its ID registers.

Discovering support: ID_AA64PFR0_EL1.EL0–EL3

FieldBits0b00000b00010b0010
EL0[3:0](not used)AArch64 onlyAArch64 and AArch32
EL1[7:4](not used)AArch64 onlyAArch64 and AArch32
EL2[11:8]EL2 not implementedAArch64 onlyAArch64 and AArch32
EL3[15:12]EL3 not implementedAArch64 onlyAArch64 and AArch32

Other relevant fields are ID_AA64PFR0_EL1.SEL2 (Secure EL2) and ID_AA64PFR0_EL1.RME. For heterogeneous clusters, the system-wide value is the minimum across cores, which is what Linux’s cpufeature code computes (see 1.1). The AArch32 views of the same state (ID_PFR0/1 and the AArch32 register mappings) are tabulated in Appendix B.

    // Can EL1 run AArch32? (EL1 field, bits [7:4])
    mrs     x0, id_aa64pfr0_el1
    ubfx    x1, x0, #4, #4
    cmp     x1, #2
    b.eq    el1_has_aa32
    // otherwise: SCR_EL3.RW / HCR_EL2.RW are RAO/WI for EL1

Bring-up note: If a pre-silicon model or an early FPGA image reports ID_AA64PFR0_EL1.EL2 = 0 or EL3 = 0 unexpectedly, check the model’s configuration parameters before debugging firmware. On FVP and in RTL testbenches, whether EL2/EL3 is implemented, and which ELs have AArch32, are configuration options, and a mismatch shows up only as an UNDEF on the first msr hcr_el2 or a SCR_EL3 write that never sticks.

Checkpoint

Q2.1.1 On a core with ID_AA64PFR0_EL1.EL0 = 0b0001, an AArch64 guest kernel (SCR_EL3.RW = 1, HCR_EL2.RW = 1) tries to start a 32-bit process by executing ERET with SPSR_EL1.M[4] = 1 and a valid AArch32 User mode in M[3:0]. What happens?

  • A. The process starts in AArch32, because EL0’s execution state is chosen only by SPSR_EL1.M[4]
  • B. The ERET completes to EL0 in AArch64, with M[4] ignored because it is RES0 on this core
  • C. It is an illegal exception return: the PE stays at EL1 with PSTATE.IL = 1, and the next instruction takes an Illegal Execution state exception to EL1
  • D. The ERET traps to EL2, because HCR_EL2.RW controls EL0’s state as well
Answer

C. A return to an execution state the target EL does not support is one of the listed illegal exception return cases. PSTATE.EL, nRW and SP are left unchanged, PSTATE.IL is set, and execution resumes at ELR_EL1 in EL1, where the first instruction takes the Illegal Execution state exception (EC 0x0E). A is tempting: M[4] does select EL0’s state, but only within what the implementation and the level above permit. HCR_EL2.RW controls EL1, not EL0, and there is no ERET trap here, so D is wrong.

Read more: Arm ARM (DDI0487), “Illegal return events from AArch64 state”; “Interprocessing”; ID_AA64PFR0_EL1

Q2.1.2 On an RME system, EL3 sets SCR_EL3.{NSE,NS} = {1,1} and then, still at EL3, writes SCTLR_EL1. Which statement is correct?

  • A. EL3 is still in Root state. The values take effect for the lower ELs on the next ERET, which enters Realm state
  • B. EL3 is now in Realm state, so its own memory accesses go to the Realm PA space
  • C. The write is illegal: {NSE,NS} may only be changed with the MMU off
  • D. {1,1} is the reserved encoding, so the next ERET is an illegal exception return
Answer

A. EL3 always runs in Root when RME is implemented. {NSE,NS} selects the Security state of the lower ELs, which is entered on exception return, so EL3 typically programs the target world’s EL1/EL2 context and then ERETs. B confuses the “lower-EL state” field with EL3’s own state. {1,0} is the reserved encoding, not {1,1}, so D is wrong.

Read more: Arm ARM (DDI0487), SCR_EL3.NSE and SCR_EL3.NS; “Security states” in the AArch64 exception model; RME system architecture (DEN0129)

Q2.1.3 Linux on a big.LITTLE phone reports that only some CPUs can run a 32-bit app. Which ID-register observation explains this?

  • A. ID_AA64PFR0_EL1.EL1 = 0b0001 on all CPUs
  • B. ID_AA64PFR0_EL1.EL3 = 0b0000 on the big CPUs
  • C. ID_AA64PFR0_EL1.EL0 = 0b0010 on all CPUs, but HCR_EL2.RW = 1
  • D. ID_AA64PFR0_EL1.EL0 = 0b0010 on some CPUs and 0b0001 on others
Answer

D. The EL0 field reports per-CPU AArch32 support at EL0. A mix such as Cortex-A710 (AArch32 EL0) and Cortex-X2 (AArch64 only) gives an asymmetric system, so the sanitised system-wide value is “AArch64 only” unless the kernel opts into mismatched 32-bit EL0. C is tempting, but HCR_EL2.RW controls EL1’s state, not EL0’s, and setting it to 1 does not stop AArch32 EL0.

Read more: Arm ARM (DDI0487), ID_AA64PFR0_EL1; Linux Documentation/arch/arm64/asymmetric-32bit.rst