2.3 A64 instruction set essentials
This section is not an instruction reference. It covers the parts of the A64 design that explain what you see in a firmware disassembly, and why new architecture features are encoded where they are.
Fixed 32-bit encoding and the top-level groups
Every A64 instruction is 32 bits, little-endian in memory regardless of data endianness, and 4-byte aligned. Bits [28:25] (called op1 in the Arm ARM’s top-level table) select the main encoding group:
| bits [28:25] | Group |
|---|---|
0000 | Reserved (includes UDF #imm16). With bit [31] = 1: SME encodings |
0010 | SVE encodings |
100x | Data processing, immediate |
101x | Branches, exception generation, and system instructions |
x1x0 | Loads and stores |
x101 | Data processing, register |
x111 | Data processing, scalar FP and Advanced SIMD |
0001, 0011 | Unallocated |
Two consequences follow. First, an immediate operand has to fit inside 32 bits alongside the opcode. That is why MOV of an arbitrary 64-bit constant becomes a MOVZ/MOVK sequence (TF-A’s mov_imm macro), and why logical immediates use the compact “bitmask immediate” encoding, which cannot express every value. Second, the all-zero word 0x00000000 decodes as UDF #0. A branch into zero-filled memory therefore takes an Undefined Instruction exception (EC 0x00) at the first instruction, which is much easier to diagnose than running off into garbage.
Loads and stores
A64 is a load/store architecture. Only load and store instructions access memory, plus the atomics in 10.2 and the MOPS instructions below. The addressing modes:
| Mode | Syntax | Effective address | Base written back |
|---|---|---|---|
| Unsigned offset | ldr x0, [x1, #16] | x1 + 16 (scaled, 12-bit) | no |
| Unscaled offset | ldur x0, [x1, #-3] | x1 - 3 (signed 9-bit) | no |
| Pre-index | ldr x0, [x1, #16]! | x1 + 16 | yes, before the access |
| Post-index | ldr x0, [x1], #16 | x1 | yes, x1 + 16 after |
| Register offset | ldr x0, [x1, x2, lsl #3] / [x1, w2, sxtw] | x1 + (x2 << 3) | no |
| Literal | ldr x0, label / ldr x0, =const | PC + simm19*4 (±1 MiB) | n/a |
| Pair | ldp x0, x1, [sp], #16 / stp x29, x30, [sp, #-16]! | as above, two registers | per form |
LDP/STP are the workhorses of save/restore code. The assembler pseudo-instruction ldr x0, =const places the constant in a nearby literal pool and emits a PC-relative literal load. That is fine in firmware, provided the literal pool is in the same position-independent image.
Conditional execution without IT
A64 has no general predication and no IT blocks. Instead, a small set of instructions read the flags:
B.cond,CBZ/CBNZ,TBZ/TBNZfor branches.CB*andTB*test a register directly and leave the flags unchanged.CSEL,CSINC,CSINV,CSNEGfor branchless selects.CSET/CINCare aliases:cset w0, eq=csinc w0, wzr, wzr, ne.CCMP/CCMNfor compare chains: if the condition holds, compare; otherwise set NZCV to an immediate.
// x0 = (a == 1 && b == 2) ? 1 : 0, no branches
cmp x1, #1
ccmp x2, #2, #0b0000, eq // if a==1, compare b; else NZCV=0000 (=> "ne")
cset x0, eq
Branchless selects matter for speculation. CSEL on a bounds check is the basis of the Spectre-v1 masking pattern together with CSDB (14.3).
ADR, ADRP and position-independent firmware
ADR Xd, labelgivesPC + simm21, a range of ±1 MiB.ADRP Xd, labelgives(PC & ~0xFFF) + simm21 << 12, the 4 KiB page oflabelwithin ±4 GiB. Paired withadd Xd, Xd, :lo12:labelor a load with a:lo12:offset, it reaches any address in that range.
Both are PC-relative, so code built from them runs correctly at any load address with no relocation, as long as the code and data keep their relative offset. TF-A’s ENABLE_PIE build and the “relocate yourself” prologue of many bootloaders depend on this. Absolute addresses still enter through ldr x0, =sym literals and through C data containing pointers. A PIE image fixes those up at runtime from its .rela.dyn entries before turning the MMU on. Branches (B/BL, ±128 MiB) are PC-relative too.
The HINT space and NOP compatibility
HINT #imm (imm = CRm:op2, 7 bits) occupies a region of the system-instruction space that every Armv8.0 implementation executes as NOP when it does not recognise the hint. Arm places new instructions there when they must be safe to run on older cores:
HINT # | Instruction | Feature | On a core without the feature |
|---|---|---|---|
| 0 | NOP | base | — |
| 1 | YIELD | base | NOP |
| 2, 3 | WFE, WFI | base | (always implemented; architecturally permitted to complete immediately) |
| 4, 5 | SEV, SEVL | base | — |
| 16 | ESB | FEAT_RAS | NOP |
| 17 | PSB CSYNC | FEAT_SPE | NOP |
| 18 | TSB CSYNC | FEAT_TRF | NOP |
| 20 | CSDB | base (v8.0, later defined) | NOP |
| 25 | PACIASP | FEAT_PAuth | NOP |
| 29 | AUTIASP | FEAT_PAuth | NOP |
| 32, 34, 36, 38 | BTI, BTI c, BTI j, BTI jc | FEAT_BTI | NOP |
| 40 | CHKFEAT X16 | FEAT_CHK | NOP (X16 unchanged) |
This is how a distribution can ship one binary built with -mbranch-protection=standard that runs on a v8.0 core. PACIASP and BTI c cost nothing there and protect on a v8.5+ core. CHKFEAT was designed around the same property: software loads a mask into X16, and a core that does not know the hint leaves X16 untouched, which reads as “not enabled”. The non-hint PAC forms (PACIA Xd, Xn, RETAA, LDRAA) are not in HINT space and are UNDEFINED on cores without FEAT_PAuth. So are WFET/WFIT (FEAT_WFxT), which is why they need a feature check.
SYS, SYSL and SYSP: maintenance and translation operations
Cache, TLB and address-translation operations are not memory instructions. They are system instructions: SYS #op1, Cn, Cm, #op2, Xt with op0 = 1, and the assembler provides aliases:
| Alias | Underlying form | Example |
|---|---|---|
DC | SYS with CRn = 7 | dc civac, x0 = sys #3, c7, c14, #1, x0 |
IC | SYS with CRn = 7 | ic ivau, x0 = sys #3, c7, c5, #1, x0 |
AT | SYS with CRn = 7 | at s1e1r, x0 |
TLBI | SYS with CRn = 8 (and 9 for some newer variants) | tlbi vae1is, x0 |
SYSL is the read form (L = 1) and has few architected users. SYSP (FEAT_SYSINSTR128) is the 128-bit pair form behind TLBIP, used when descriptors are 128-bit (FEAT_D128). The encoding is shared with MRS/MSR, as 2.5 explains. That is why the same op1 field decides which EL may execute DC CIVAC (op1 = 3, permitted at EL0 if SCTLR_EL1.UCI = 1) versus DC CISW (op1 = 0, EL1 and above). The semantics of the operations are in 8.5, 9.1 and 5.9.
Optional instruction groups
- Cryptographic extension: FEAT_AES and FEAT_PMULL, FEAT_SHA1, FEAT_SHA256, FEAT_SHA512, FEAT_SHA3, FEAT_SM3 and FEAT_SM4 (Advanced SIMD instructions). Always optional, because some configurations are excluded for export-control reasons. Check
ID_AA64ISAR0_EL1per field. A “v9 core” may lack them. - FEAT_RNG (permitted from v8.5):
RNDRandRNDRRSare system registers read withMRS, not new opcodes. A read returns 64 random bits withNZCV = 0000, or returns 0 withNZCV = 0100(Z set) if no entropy is available in a reasonable time.RNDRRSreseeds first. Code must loop on the flags. With FEAT_RNG_TRAP,SCR_EL3.TRNDRlets EL3 trap them and emulate them, for example from a platform TRNG. - FEAT_CSSC (mandatory from v8.9): scalar
ABS,CNT,CTZ(register forms) andSMAX/SMIN/UMAX/UMIN(register and immediate forms). They are pure data processing and need no enable.
1: mrs x0, rndr
b.eq 1b // Z set: no entropy yet, retry (bound this in real code)
FEAT_MOPS: architected memcpy and memset
FEAT_MOPS (an Armv8.8/v9.3 feature; see DDI0487 A2 for its mandatory status) adds CPYP/CPYM/CPYE (memmove semantics; CPYF* is the forward-only memcpy variant) and SETP/SETM/SETE (memset; SETG* also sets MTE tags). Each operation is three instructions that must appear consecutively, with the same registers:
// memmove(x0 = dst, x1 = src, x2 = n)
cpyp [x0]!, [x1]!, x2! // prologue: validate, choose direction, may copy a little
cpym [x0]!, [x1]!, x2! // main: bulk of the copy, interruptible
cpye [x0]!, [x1]!, x2! // epilogue: the tail
All three update the destination, source and size registers as they make progress, so the operation can be interrupted and resumed after any instruction. The architecture permits two algorithms, and which one a core uses is IMPLEMENTATION DEFINED. The prologue records the choice in PSTATE.C:
Option A (C = 0) | Option B (C = 1) | |
|---|---|---|
Forward copy, after CPYP | Xd, Xs point past the end. Xn holds minus the bytes remaining. NZCV = 0000 | Xd, Xs point at the next byte to copy. Xn holds the bytes remaining. NZCV = 0010 |
Backward copy, after CPYP | Xd, Xs unchanged. Xn = bytes remaining. NZCV = 0000 | Xd, Xs point one past the highest byte still to copy. NZCV = 1010 (N = 1) |
Software never interprets these values. It only has to run the three instructions in order. The design has two architectural consequences.
The Memory Copy/Set exception (EC 0x27). If CPYM or CPYE finds register or PSTATE state that its own implementation would not have produced, it takes an exception instead of guessing. This happens most commonly because a thread was migrated between cores with different options (big and little cores in a cluster can differ) between CPYP and CPYM. Executing a main or epilogue instruction out of sequence has the same effect. The ESR ISS tells the handler which of the CPY/SET instructions faulted, whether it was the epilogue, the registers involved, and whether the cause was the option. The handler rewinds the registers into the form the current core expects and restarts from the prologue. Linux does this in arm64_mops_reset_regs(). Any EL that can migrate a context must handle EC 0x27, and that includes a hypervisor moving vCPUs.
Enables. MOPS at EL0/EL1 is UNDEFINED unless enabled:
SCTLR_EL1.MSCEn(bit [33]) enables the instructions at EL0. Its effective value is 1 whenHCR_EL2.{E2H,TGE} = {1,1}, in which caseSCTLR_EL2.MSCEngoverns EL0.HCRX_EL2.MSCEn(bit [11]) enables them at EL1 and EL0 when EL2 is enabled.HCRX_EL2.MCE2(bit [10]) routes EL1’s Memory Copy/Set exceptions to EL2.HCRX_EL2only has an effect if EL3 setsSCR_EL3.HXEn. With EL2 enabled andHXEn = 0, the effective value ofHCRX_EL2.MSCEnis 0, and MOPS is UNDEFINED at EL1 and EL0.
That chain (EL3 enables HCRX, EL2 enables MOPS, EL1 enables EL0) is the pattern in 2.6. Linux’s boot requirements state it explicitly.
Bring-up note: reading an objdump of BL31 entry code
Bring-up note: The listing below was assembled with GNU as and disassembled with
aarch64-linux-gnu-objdump -d(binutils 2.44). It is a condensed paraphrase of TF-A’sbl31_entrypointandel3_entrypoint_common, not a verbatim build. In a real tree, runaarch64-none-elf-objdump -d build/<plat>/<mode>/bl31/bl31.elf | lessand search forbl31_entrypoint.
0000000000000000 <bl31_entrypoint>:
0: d503245f bti c // HINT #34: NOP on pre-v8.5 cores
4: aa0003f4 mov x20, x0 // save BL2's arguments in callee-saved regs
8: aa0103f5 mov x21, x1
c: d2810600 mov x0, #0x830 // mov_imm: MOVZ + MOVK build
10: f2a618a0 movk x0, #0x30c5, lsl #16 // 0x30c50830 = SCTLR_EL3 RES1 bits
14: d51e1000 msr sctlr_el3, x0 // MMU, caches, alignment checks off
18: d5033fdf isb // make the SCTLR write take effect
1c: 10003f20 adr x0, 800 <runtime_exceptions>
20: d51ec000 msr vbar_el3, x0 // vectors: 2 KiB-aligned, PC-relative
24: d5033fdf isb
28: 940001f7 bl 804 <reset_handler> // per-CPU errata and IMP DEF setup
2c: d53e1000 mrs x0, sctlr_el3
30: d2820141 mov x1, #0x100a // I | SA | A
34: aa010000 orr x0, x0, x1
38: d51e1000 msr sctlr_el3, x0
3c: d5033fdf isb
40: d50344ff msr daifclr, #0x4 // unmask SError (A) at EL3
44: d538f180 mrs x0, s3_0_c15_c1_4 // IMP DEF register: objdump has no name
48: d5380401 mrs x1, id_aa64pfr0_el1
4c: d3482c21 ubfx x1, x1, #8, #4 // EL2 field
50: 90000000 adrp x0, 0 <...> // + relocation: page of __BSS_START__
54: 91000000 add x0, x0, #0x0 // :lo12: part
58: 58003d82 ldr x2, 808 <...> // literal-pool load (ldr x2, =const)
5c: d503233f paciasp
60: d503251f chkfeat x16 // HINT #40
64: d503403f msr ssbs, #0x0 // PSTATE immediate form (op0 = 0), see 2.4
68: d50b7520 ic ivau, x0 // SYS #3, C7, C5, #1 shown by its alias
How to read it:
- Encodings tell you the group.
d5xxxxxxwords are system instructions: MSR/MRS, hints, barriers, SYS.d503201fis NOP, and anythingd503 2xxxwithRt = 31is a HINT.d5033fdfisISB. - Unnamed system registers print as
s3_<op1>_c<n>_c<m>_<op2>.op0 = 3withCRn = 15(or 11) is the IMPLEMENTATION DEFINED space. Look the register up in the core TRM. This one isCPUECTLR_EL1on many Cortex cores (1.3). An older binutils prints even architected v9 registers this way, so decode them with 2.5 before assuming they are IMP DEF. - Hints print as their newest name. An older objdump shows
hint #0x22where this one showsbti c, andhint #0x28where this one showschkfeat x16. Both are the same instruction. adrp+add :lo12:in a.oshows zero offsets plus a relocation. Useobjdump -drto see the symbol, or disassemble the linked ELF.ISBafter eachMSR SCTLR_EL3/VBAR_EL3is the context-synchronization requirement, explained in 7.8.
Checkpoint
Q2.3.1 A Linux distribution builds its kernel with -mbranch-protection=pac-ret+bti. On a v8.2 core without FEAT_PAuth or FEAT_BTI, which instruction in the generated code would take an Undefined Instruction exception if it appeared?
- A.
paciaspat a function entry - B.
bti cat a function entry - C.
retaaat a function return - D.
autiaspbeforeret
Answer
C. PACIASP, AUTIASP and BTI are all allocated in the HINT space, so cores that lack the feature execute them as NOP. RETAA is a combined authenticate-and-return instruction encoded outside HINT space. It is UNDEFINED without FEAT_PAuth, which is why compilers emit it only when targeting v8.3+ explicitly. The most tempting wrong answer, A, assumes every PAC instruction is new opcode space.
Read more: Arm ARM (DDI0487), “Hint instructions” in the A64 system instruction class; RETAA, RETAB
Q2.3.2 A user-space memmove using CPYP/CPYM/CPYE is preempted between CPYP and CPYM and resumed on a different core. The new core takes an exception with EC 0x27 on CPYM. What does this most likely mean, and what should the kernel do?
- A. The destination buffer is unmapped. Deliver SIGSEGV
- B. The two cores implement different MOPS options. Rewrite the registers into a form the current core accepts and restart from
CPYP - C.
SCTLR_EL1.MSCEnis 0 on the new core. Set it and retryCPYM - D. The PE detected a torn copy. Fall back to a software memmove at the faulting PC
Answer
B. EC 0x27 is the Memory Copy and Memory Set exception. It is raised when the main or epilogue instruction sees register or PSTATE.C state inconsistent with its own algorithm, which is typical after migration between option-A and option-B implementations. The ISS gives enough information to reconstruct the registers so execution can restart at the prologue (Linux: arm64_mops_reset_regs). An unmapped buffer gives a Data Abort (EC 0x24/0x25), and a disabled MSCEn gives an Undefined Instruction exception (EC 0x00), not EC 0x27.
Read more: Arm ARM (DDI0487), “Memory Copy and Memory Set exceptions”; CPYP, CPYM, CPYE; Linux Documentation/arch/arm64/mops.rst
Q2.3.3 A hypervisor sets HCRX_EL2.MSCEn = 1 and a guest kernel sets SCTLR_EL1.MSCEn = 1, but MOPS instructions in the guest’s user space are still UNDEFINED. ID_AA64ISAR2_EL1 reports FEAT_MOPS. What is the most likely cause?
- A.
HCRX_EL2.MCE2must also be set - B. MOPS must also be enabled in
CPACR_EL1, like FP - C. The guest needs an
ISBafterSCTLR_EL1only on a core that uses option B - D. EL3 left
SCR_EL3.HXEn = 0, soHCRX_EL2has no effect andMSCEnis effectively 0
Answer
D. With EL2 enabled and SCR_EL3.HXEn = 0, HCRX_EL2.MSCEn has an effective value of 0, which makes MOPS UNDEFINED at EL1 and EL0 whatever the stored value. With HXEn = 0, the hypervisor’s MSR HCRX_EL2 itself traps to EL3 (EC 0x18). If EL3 treats that trap as write-ignored instead of reporting it, the hypervisor believes the write succeeded, which matches the symptom. MCE2 only routes EC 0x27 exceptions, and CPACR_EL1 has no MOPS control.
Read more: Arm ARM (DDI0487), HCRX_EL2.MSCEn and SCR_EL3.HXEn; Linux Documentation/arch/arm64/booting.rst