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.4 PSTATE

PSTATE (“process state”) is not a register. In AArch64 there is no CPSR that you can read or write as a whole. PSTATE is an architectural collection of independent fields. Some have their own access instructions, some can be reached only through SPSR_ELx, and two (SM, ZA) are not saved in SPSR at all. On exception entry, the PE copies the AArch64 PSTATE fields into SPSR_ELx of the target EL, and ERET restores them from it. The exact entry-time changes to each field are listed in 3.2.

The fields

The bit positions are the positions in SPSR_ELx for an exception taken from AArch64. PSTATE itself has no bit layout.

FieldSPSR bitsFeatureMeaning
N,Z,C,V[31:28]baseCondition flags
D,A,I,F[9:6]baseMask debug exceptions, SError, IRQ, FIQ, each for exceptions targeting the current EL (what “masked” means when the target is a higher EL is in 3.3)
ELM[3:2]baseCurrent Exception level. Read as CurrentEL
SPM[0]baseStack-pointer select at EL1+ (2.2)
nRWM[4]baseExecution state: 0 = AArch64. Only meaningful in SPSR
SS[21]baseSoftware step state (16.1)
IL[20]baseIllegal Execution state (3.2)
PAN[22]FEAT_PAN (v8.1)Privileged accesses to EL0-accessible memory fault (5.5)
UAO[23]FEAT_UAO (v8.2)LDTR/STTR at EL1/EL2 use the current EL’s permissions, not EL0’s
DIT[24]FEAT_DIT (v8.4)Data-independent timing for the instructions the Arm ARM lists
TCO[25]FEAT_MTE (v8.5)Tag Check Override: suppress MTE tag checks (13.5)
SSBS[12]FEAT_SSBS0 = hardware may not speculatively let a load bypass an earlier store to the same address (14.5)
BTYPE[11:10]FEAT_BTI (v8.5)Type of the last indirect branch, checked at the next instruction (13.1)
ALLINT[13]FEAT_NMI (v8.8)Masks all IRQ and FIQ, including those with Superpriority (4.3)
SM, ZAnot in SPSRFEAT_SME (v9.2)Streaming SVE mode, and ZA storage enabled (15.2)
PM[32]FEAT_EBEPMasks the PMU exception used for exception-based event profiling (16.3)
EXLOCK[34]FEAT_GCS (v9.4)Exception-return state lock: while set, the current EL’s changes to its own exception-return state (ELR, SPSR, GCS pointer) are restricted (13.2)
UINJ[36]FEAT_UINJ (v9.6, 2024 extensions)Undefined-instruction injection: set by a higher EL in SPSR, so that after the return the target takes an Undefined Instruction exception

SPSR bit [35] is PACM (FEAT_PAuth_LR), another SPSR-only bit. The SPSR layout grows upward from bit 32. SPSR_ELx has been a 64-bit register since v8.0, and save/restore code that keeps only the low 32 bits (str w1, [...] of a mrs x1, spsr_el3) silently drops PM, EXLOCK, PACM and UINJ on newer cores.

Access methods

Each field is reached in one or more of four ways:

  1. MSR (immediate), the op0 = 0 “PSTATE field” form msr <field>, #imm. It needs no scratch register and is the canonical way to flip a single bit.
  2. MRS/MSR (register) using a special-purpose register name (NZCV, DAIF, PAN, …). The value is presented at the field’s SPSR bit position.
  3. Via SVCR, for the SME bits only.
  4. SPSR only: no direct access, so the field can be changed only by an exception return.
FieldMSR immediateMRS/MSR registerLowest EL with direct accessNotes
NZCV—NZCVEL0Also written by flag-setting instructions
D,A,I,FDAIFSet, DAIFClrDAIFEL1 (EL0 if SCTLR_EL1.UMA = 1)
EL—CurrentEL (read-only)EL1UNDEFINED at EL0
SPSPSelSPSelEL1
PANPANPANEL1
UAOUAOUAOEL1
DITDITDITEL0
SSBSSSBSSSBSEL0Direct access needs FEAT_SSBS2. With FEAT_SSBS only, the field is SPSR-only plus the SCTLR_ELx.DSSBS entry default
TCOTCOTCOEL0
ALLINTALLINTALLINTEL1HCRX_EL2.TALLINT traps EL1’s MSR ALLINT, #1 to EL2
PMPMPMEL1
SM, ZASVCRSM, SVCRZA, SVCRSMZA (= SMSTART/SMSTOP)SVCREL0Subject to the SME enables in CPACR_EL1/CPTR_ELx/SMCR_ELx
nRW, SS, IL, BTYPE, EXLOCK, UINJ, PACM———SPSR only. BTYPE is also set implicitly by BR/BLR
    msr     pan, #1              // immediate form: no register needed
    mrs     x0, daif             // read all four masks (bits [9:6])
    msr     daifset, #0b0011     // set I and F (bit order D A I F = 8 4 2 1)
    mrs     x1, currentel
    lsr     x1, x1, #2           // x1 = EL number
    smstart sm                   // = msr svcrsm, #1

Visibility of a write. The Arm ARM guarantees that the side effects of a PSTATE write by MSR are visible to later instructions in program order and invisible to earlier ones, with no ISB needed. This is unlike most system-register writes (2.5). The guarantee covers the PE’s own interpretation, such as PAN checks on the next load. It does not make a newly unmasked pending interrupt arrive at a particular instruction boundary. That is the interrupt-taking model in 3.3, and the GIC’s PMR is a separate register with its own synchronization rules.

Fields that need particular care

SM and ZA are not saved on exception entry. They live in SVCR, are not copied into SPSR, and exception entry does not change them. A handler at a higher EL that may be entered in Streaming mode therefore runs with PSTATE.SM = 1. It must either avoid FP/SIMD entirely, rely on the SME traps to catch it, or execute SMSTOP and restore the state later. This is why EL3 context management must save and restore SVCR explicitly across worlds (15.3).

SPSR-only fields are policy in the hands of the higher EL. BTYPE and IL carry in-flight state across an exception: the interrupted code’s pending BTI check, or its illegal-state flag. An EL that fabricates an SPSR (for a first entry into a lower EL, or a signal frame) must set them deliberately, normally to 0. UINJ turns this into an explicit tool: rather than synthesising an Undefined Instruction exception into the lower EL by hand (writing the lower EL’s ESR, ELR and SPSR and redirecting to its vector), firmware sets SPSR_EL3.UINJ and returns.

SSBS has two kinds of default. SCTLR_ELx.DSSBS sets the value PSTATE.SSBS takes on exception entry to ELx. EL0 can change its own value only with FEAT_SSBS2. A kernel that wants the speculative-store-bypass mitigation everywhere sets DSSBS = 0 and sanitises SPSR.SSBS on return.

Security note: PAN, UAO, TCO and DIT have security meaning, and all four are saved and restored through SPSR on every exception. An EL1 kernel that runs with PAN = 1 relies on its own exception entry, controlled by SCTLR_EL1.SPAN, and on every ERET restoring the intended value. A higher EL that builds a return SPSR for EL1 by hand (a hypervisor injecting an exception, or EL3 resuming a world) must preserve these bits from the saved context rather than zeroing them. A zeroed PAN or DIT is a silent hardening loss that no test catches by crashing.

Bring-up note: When decoding an SPSR from a crash dump, decode at least bits [36:0]. A value like 0x4_0000_03c5 on a GCS-enabled system is “EL1h, all of DAIF masked, EXLOCK set”. That is not an exotic corruption, only a field older tools don’t print.

Checkpoint

Q2.4.1 A hypervisor runs at EL2 with Streaming SVE mode active (PSTATE.SM = 1) and takes an SMC to EL3. EL3’s handler is built with -mgeneral-regs-only. Which statement is correct?

  • A. The handler runs with PSTATE.SM = 1, because SM is not saved in SPSR_EL3 or changed on exception entry. Whether that matters depends on EL3’s SME traps and whether the handler touches FP/SIMD state
  • B. Exception entry clears SM, and SPSR_EL3 records the old value so ERET restores it
  • C. The SMC is UNDEFINED while PSTATE.SM = 1
  • D. Exception entry clears both SM and ZA, so ZA contents are lost
Answer

A. SM and ZA are held in SVCR. They are neither copied to SPSR nor modified by exception entry. A general-regs-only handler is unaffected in practice, but any EL3 code that does use FP/SIMD, or a world switch, must handle SVCR explicitly. B is the natural assumption from how every other PSTATE bit behaves.

Read more: Arm ARM (DDI0487), SVCR, and “Process state, PSTATE” in the AArch64 exception model; SME supplement chapters

Q2.4.2 Which pair of PSTATE fields can be changed only by an exception return, with no MSR or MRS form?

  • A. PAN and UAO
  • B. SSBS and TCO
  • C. BTYPE and IL
  • D. ALLINT and PM
Answer

C. BTYPE is written implicitly by indirect branches, and IL by illegal returns. Neither has a direct access instruction, so software can set them only through SPSR on ERET. All the others have MSR immediate and MRS/MSR register forms, although SSBS gets them only with FEAT_SSBS2, which makes B tempting on an SSBS-only core.

Read more: Arm ARM (DDI0487), “Process state, PSTATE” and SPSR_EL1

Q2.4.3 An EL1 kernel executes msr pan, #1 and on the very next instruction performs an ldr from a user page. Which statement is correct?

  • A. An ISB is required between them, or the load may still be checked with PAN = 0
  • B. No ISB is needed: a PSTATE write by MSR is architecturally visible to all later instructions
  • C. A DSB ISH is required to make the PAN change visible to the MMU
  • D. The write only takes effect at the next exception return
Answer

B. Writes to PSTATE fields are guaranteed to affect later instructions and not earlier ones, without a context synchronization event. This differs from writes to a system register such as SCTLR_EL1, which generally do need an ISB (7.8). Option A applies that system-register rule to PSTATE.

Read more: Arm ARM (DDI0487), “Process state, PSTATE” (writes to PSTATE fields); PAN