2.5 System registers
AArch64 has no coprocessor interface and no memory-mapped core control block. All PE control and identification state is reached through one encoding space, addressed by five fields. The same space is used by MRS/MSR (registers), MSR-immediate (PSTATE fields), and SYS (operations such as DC, TLBI, AT).
The encoding: op0, op1, CRn, CRm, op2
MRS Xt, <reg> and MSR <reg>, Xt encode the register as follows:
31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt
L=1: MRS (read) L=0: MSR (write)
The generic name S<op0>_<op1>_C<CRn>_C<CRm>_<op2> is accepted by GNU as and LLVM for any encoding, which is how you write a register your toolchain does not yet know. The disassembler prints the same form for registers it cannot name (see the objdump in 2.3).
| Register | Generic name | Word |
|---|---|---|
SCTLR_EL1 | S3_0_C1_C0_0 | d5381000 (mrs x0, …) |
SCTLR_EL2 | S3_4_C1_C0_0 | d53c1000 |
SCTLR_EL12 | S3_5_C1_C0_0 | d53d1000 |
SCTLR_EL3 | S3_6_C1_C0_0 | d53e1000 |
ID_AA64PFR0_EL1 | S3_0_C0_C4_0 | d5380400 |
MDSCR_EL1 | S2_0_C0_C2_2 | d5300240 |
How op0 partitions the space
op0 | Contents |
|---|---|
| 0 | Not registers: hints, barriers (DMB/DSB/ISB/SB), CLREX, and the PSTATE-field MSR-immediate forms (2.4) |
| 1 | System instructions: SYS/SYSL (DC, IC, AT, TLBI, prediction-restriction CFP/CPP/DVP, …) |
| 2 | Debug and legacy trace registers (MDSCR_EL1, DBGBCR<n>_EL1, OSLAR_EL1, …) |
| 3 | Everything else. CRn = 11 and CRn = 15 are reserved for IMPLEMENTATION DEFINED registers |
op1 hints at the owning EL
By convention, op1 indicates the lowest EL that normally owns the register. This is a naming convention, not an access rule: the authoritative access conditions are each register’s accessibility pseudocode.
op1 | Typical owner | Examples |
|---|---|---|
| 0 | EL1 | SCTLR_EL1, TCR_EL1, VBAR_EL1, ID registers |
| 1, 2 | EL1 (cache identification) | CCSIDR_EL1, CLIDR_EL1 (1), CSSELR_EL1 (2) |
| 3 | EL0 | CTR_EL0, TPIDR_EL0, CNTVCT_EL0, DCZID_EL0 |
| 4 | EL2 | HCR_EL2, SCTLR_EL2, VTTBR_EL2 |
| 5 | EL2 aliases of EL1/EL0 registers | SCTLR_EL12, CNTP_CTL_EL02 |
| 6 | EL3 | SCR_EL3, SCTLR_EL3, MDCR_EL3 |
The ID space is forward-compatible. Encodings S3_0_C0_C<m>_<op2> with CRm = 1 to 7 are the ID-register block. Unallocated encodings in it are RAZ, not UNDEFINED. Software can therefore probe a newer ID register, for example ID_AA64ISAR3_EL1, on an older core and read 0, meaning “nothing implemented”. FEAT_IDST makes EL0 accesses to this space trap as EC 0x18 instead of being UNDEFINED (1.1).
Access rules and what failure looks like
Every register access is checked in a fixed order, which the System Register XML expresses as accessibility pseudocode. The result is one of four outcomes: the access proceeds, it is UNDEFINED (Undefined Instruction exception, EC 0x00), it traps to a higher EL (usually EC 0x18), or, under FEAT_NV2, it is converted into a memory access. As an example, the pseudocode for MRS Xt, SCTLR_EL12 in the Arm XML reads, in outline:
if PSTATE.EL == EL0 then UNDEFINED
elsif PSTATE.EL == EL1 then
if EffectiveHCR_EL2_NVx() == '101' then X[t] = NVMem(0x110) // NV2: memory access
elsif EffectiveHCR_EL2_NVx() IN {'xx1'} then trap to EL2, EC 0x18
else UNDEFINED
elsif PSTATE.EL == EL2 then
if ELIsInHost(EL2) then X[t] = SCTLR_EL1 else UNDEFINED
elsif PSTATE.EL == EL3 then
if ELIsInHost(EL2) then X[t] = SCTLR_EL1 else UNDEFINED
A trap with EC 0x18 carries the encoding in its ISS, so the handler can decode exactly which register was accessed:
| ISS bits | [21:20] | [19:17] | [16:14] | [13:10] | [9:5] | [4:1] | [0] |
|---|---|---|---|---|---|---|---|
| Field | Op0 | Op2 | Op1 | CRn | Rt | CRm | Direction (1 = read) |
The fields are not in instruction order. Decoders that extract them in op0/op1/CRn/CRm/op2 order produce plausible but wrong register names. The full decode card is in Appendix D.
The _EL12 and _EL02 aliases (FEAT_VHE)
With FEAT_VHE (mandatory from v8.1) and HCR_EL2.E2H = 1, EL2 is a “host” EL that runs an unmodified OS kernel. That needs two mechanisms:
- Redirection. At EL2 with E2H = 1, the EL1 encodings of registers that have EL2 counterparts access the EL2 register.
mrs x0, sctlr_el1readsSCTLR_EL2, andmsr ttbr1_el1, x0writesTTBR1_EL2. The kernel’s EL1 code therefore runs at EL2 unchanged. - Aliases to reach the real EL1/EL0 registers. Because the plain EL1 names are redirected, the host uses
_EL12names (SCTLR_EL12,TCR_EL12,VBAR_EL12,CNTKCTL_EL12, …) to access a guest’s EL1 state, and_EL02names (CNTP_CTL_EL02,CNTV_CVAL_EL02, …) for its EL0 timer registers. All of them sit atop1 = 5.
As the pseudocode shows, _EL12 is UNDEFINED at EL2 and EL3 unless EL2 is in host mode, and at EL1 it exists only to be trapped or transformed by nested virtualization (11.2). EL3 firmware saving a Non-secure EL1 context must therefore use the plain _EL1 names (at EL3 there is no redirection) and must not use _EL12 unless it has checked E2H.
SYS: operations in the same space
SYS #op1, Cn, Cm, #op2{, Xt} is the op0 = 1 member of the same format, with L = 0. DC, IC, AT and TLBI are aliases, and their op1 follows the same EL convention: DC CVAC (EL0-capable) is op1 = 3, and TLBI ALLE2 is op1 = 4. Traps on them are also reported with EC 0x18, and HCR_EL2.TPCP/TPU/TTLB and the fine-grained trap registers apply (11.1).
128-bit system registers: MRRS and MSRR (FEAT_SYSREG128)
FEAT_D128 (an Armv9.4 extension) introduces 128-bit translation table descriptors, and with them some system registers become 128 bits wide: TTBR0_EL1, TTBR1_EL1, TTBR0_EL2, TTBR1_EL2, VTTBR_EL2, PAR_EL1, and the RCWMASK_EL1/RCWSMASK_EL1 masks. FEAT_SYSREG128 provides the access instructions:
mrrs x0, x1, ttbr0_el1 // x0 = bits[63:0], x1 = bits[127:64]
msrr ttbr0_el1, x2, x3 // write all 128 bits in one access
- The pair must start at an even register (
Xt,Xt+1). GNU as rejectsmrrs x1, x2, .... - The encoding is the MRS/MSR format with bit [22] set (
mrrs x0, x1, ttbr0_el1=d5782000). There is alsoSYSP(FEAT_SYSINSTR128) for 128-bit system instructions such asTLBIP. - Plain
MRS/MSRstill work on these registers but transfer only bits [63:0]. Check the register’s description for what a 64-bit write does to the upper half before mixing the two forms. - Traps:
SCR_EL3.D128En = 0makesMRRS/MSRRat EL1 and EL2 trap to EL3, andHCRX_EL2.D128En = 0traps them at EL1 to EL2. Both are reported with EC 0x14, not 0x18.
Bring-up note: A kernel or hypervisor built for D128 that dies on its very first
msrr ttbr0_el1with an exception to EL3 (EC 0x14) is not hitting a broken MMU. EL3 has not setSCR_EL3.D128En. This is the “new features arrive trapped” pattern in 2.6 and 17.3. Note also thatHCRX_EL2.D128Enbehaves as 0 when EL2 is enabled andSCR_EL3.HXEn = 0.
When does a write take effect? (pointer)
A direct write to a system register is not, in general, guaranteed to affect subsequent instructions until a context synchronization event (such as ISB, exception entry, or ERET) occurs. Direct reads of the same register by the same PE observe the write in program order, and writes that affect translation or cache maintenance carry additional TLB or barrier requirements. The exact rules (which effects need an ISB, which need a DSB first, and the exceptions that FEAT_ExS makes possible on entry and return) are the subject of 7.8. The working rule for firmware is: MSR to control state, then ISB, before relying on the change. The objdump of BL31’s entry code in 2.3 does exactly that.
Checkpoint
Q2.5.1 EL3 firmware saves a Non-secure context. The Normal-world hypervisor runs with HCR_EL2.E2H = 1. EL3 reads SCTLR_EL1 using the plain encoding S3_0_C1_C0_0. What does it get?
- A.
SCTLR_EL2, because E2H redirection applies to every EL above EL1 - B. An Undefined Instruction exception, because with E2H = 1 only
SCTLR_EL12is valid - C. A trap to EL2, because the access targets a VHE-managed register
- D.
SCTLR_EL1, because redirection applies only to accesses executed at EL2
Answer
D. Redirection of EL1 encodings to EL2 registers is a property of execution at EL2 in host mode. At EL3 the plain encoding names the EL1 register. SCTLR_EL12 would also be valid at EL3 when EL2 is in host mode, but it is not required. Option A generalises redirection to EL3, which is the usual mistake. A trap from EL3 to EL2 is impossible, so C is wrong.
Read more: Arm ARM (DDI0487), SCTLR_EL1 accessibility pseudocode; “Virtualization Host Extensions”
Q2.5.2 A hypervisor’s trap handler receives EC 0x18 with ISS = 0x340420. Which access trapped?
- A.
MSR CPACR_EL1, X1 - B.
MRS X1, CPACR_EL1 - C.
MSR SCTLR_EL1, X1 - D.
MSR S3_0_C1_C2_0, X1
Answer
A. Decode with the ISS layout, which is not instruction order: Op0[21:20] = 3, Op2[19:17] = 2, Op1[16:14] = 0, CRn[13:10] = 1, Rt[9:5] = 1, CRm[4:1] = 0, Direction[0] = 0 (write). That is S3_0_C1_C0_2, which is CPACR_EL1, written from X1. B inverts the direction bit (1 means read). C drops Op2, which sits between Op0 and Op1 in the ISS and is easy to miss. D is what you get if you take the fields in instruction order from the wrong bit positions.
Read more: Arm ARM (DDI0487), ESR_EL2, ISS encoding for an exception from MSR, MRS, or System instruction execution in AArch64 state; CPACR_EL1
Q2.5.3 Boot code on a pre-v8.4 core wants to detect FEAT_SEL2 by reading ID_AA64PFR0_EL1, and also probes ID_AA64MMFR4_EL1, a register newer than the core. What happens on the probe?
- A. Undefined Instruction exception, so the probe must be guarded by a version check
- B. A trap to EL3 with EC 0x18
- C. The read returns 0, because unallocated encodings in the ID-register block are RAZ
- D. The value is UNKNOWN, so the result must be masked with the fields known on that core
Answer
C. Unallocated encodings in S3_0_C0_C<1-7>_<op2> are reserved as RAZ precisely so that software can probe future ID registers on older cores and read “not implemented”. A is what happens for unallocated encodings outside the ID block. FEAT_IDST changes this only for EL0 accesses.
Read more: Arm ARM (DDI0487), “Reserved encodings in the ID register space” / System register encoding space for ID registers; FEAT_IDST