Module 4 · Lesson 3 of 38

ARM architecture: registers, exception levels, TrustZone and TF-A, interrupts (GIC)

Registers, exception levels and the vector table, TrustZone and TF-A, and how the GIC delivers, prioritises and routes interrupts to Linux.

  • Beginner to advanced
  • 30 min read
  • 45 min lab
What you will need

An AArch64 or AArch32 cross toolchain (binutils objdump) or a native ARM Linux host for the disassembly; a running ARM Linux board such as an STM32MP1 Discovery or Raspberry Pi for /proc/interrupts; a TF-A source tree built for the STM32MP1 for the last part

By the end you can 7 objectives
  • Identify the three Cortex profiles and the AArch64 and AArch32 execution states, and state which one the STM32MP1 and the Raspberry Pi use.
  • Trace the role of x0-x30, SP, PC and the NZCV flags in a disassembled AArch64 function and explain who saves each register across a call.
  • Explain what runs at each exception level EL0-EL3 and why secure firmware lives at EL3.
  • List the four exception classes and locate the matching entry in the AArch64 vector table.
  • Describe how TrustZone separates the secure and normal worlds and how TF-A's BL1, BL2, BL31 and BL32 stages manage the secure side.
  • Explain how the GIC distributor and CPU interface deliver SPI, PPI and SGI interrupts and how priority, preemption and affinity decide what runs where.
  • Map a device interrupt from the device tree to its GIC SPI number and then to the Linux IRQ number shown in /proc/interrupts.
Read the lesson below; the video will appear here when published.
01

Why Arm, and its three processor families

2 min read

An is the interface a compiler targets. An SoC (system-on-chip) is a single chip that combines CPU cores with memory controllers, peripherals and buses, and it is the physical product built around the licensed core. Arm is unusual because it licenses the ISA and core designs but manufactures nothing, so the same Cortex-A72 core sits inside a Raspberry Pi 4 and many other products, each with different surrounding silicon.

The ISA families you will meet are ARMv7-A, ARMv8-A and ARMv9-A. ARMv7-A cores are 32-bit only. ARMv8-A added the 64-bit execution state, and ARMv9-A builds on it. The core names sit under the ISA: the Cortex-A7 used by the STM32MP1 is ARMv7-A, while the Cortex-A72 in the Pi 4 and the Cortex-A76 in the Pi 5 are ARMv8-A.

Within an ISA generation, Arm divides cores into three profiles that answer different needs.

Cortex-A (application). These run a full operating system. They have a memory management unit (MMU) for virtual memory, a generic interrupt controller (GIC), and the performance for Linux. The A7, A53, A72 and A76 are all Cortex-A cores. When you read a board manual that says a Linux-capable core, this is the profile it means.

Cortex-R (real-time). These target deterministic control, often in automotive or modem subsystems. They use a memory protection unit (MPU) rather than a full MMU, prioritise bounded latency over throughput, and usually run an RTOS or bare metal. Linux on them is rare and needs the MMU-less variant, so in practice you will not run Linux here.

Cortex-M (microcontroller). These are the small cores in sensors and companion controllers. They have no MMU, execute only the Thumb instruction set, use a nested vectored interrupt controller (NVIC) instead of a GIC, and run Zephyr, FreeRTOS or bare metal, never Linux.

The embedded angle matters immediately: the STM32MP157 used for this course contains a dual Cortex-A7 for Linux plus a Cortex-M4 for real-time work, both on one die. A single chip therefore contains two profiles, and part of board bring-up is deciding which core owns which peripheral.

Check the core before you assume

Before you trust a statement about registers or exception behaviour, check which core and ISA you have. Cortex-A7 is ARMv7-A and AArch32 only, so it has no exception levels; a Cortex-A53 or later is ARMv8-A and has them. The same word, such as Monitor, means slightly different things across the two.

Diagram in production
The three Cortex profiles and the jobs each one is designed for
02

Execution states: AArch64 and AArch32

2 min read

An is selected by the hardware when an exception is taken or returned from, not by a program flipping a bit at will.

AArch64 is the 64-bit state introduced by ARMv8-A. It has 31 general-purpose registers x0 through x30, each 64 bits wide, a fixed-length 32-bit instruction set called A64, 64-bit addresses, and the exception-level model you will meet in the next sections. It is the state Linux runs in on almost every 64-bit board.

AArch32 is the 32-bit state, backward compatible with ARMv7-A. It has 16 registers r0 through r15, two instruction sets (A32 and Thumb), 32-bit addresses, and the older privilege-mode model. It is what the Cortex-A7 in the STM32MP1 runs, because that core is ARMv7-A.

The two states can coexist on one core. The execution state is a property of each exception level, so an AArch64 kernel at EL1 can run AArch32 user applications at EL0. That is how a 64-bit Linux system still executes old 32-bit binaries. The reverse is not possible: an AArch32 kernel cannot run AArch64 applications.

ARMv8-A requires both states at EL0 and EL1. ARMv9-A keeps AArch64 as the only required state and no longer guarantees AArch32 at EL0, the level where user applications run, which is why 32-bit user programs are gradually disappearing from the newest chips.

32-bit does not mean old board

Raspberry Pi OS has offered a 64-bit release since 2022 (Bullseye), made it the default for the Pi 4 and Pi 5 with Bookworm in 2023, and the current release is Trixie; meanwhile the STM32MP1 remains a 32-bit AArch32 platform. Both are current products; the ISA width and the product age are unrelated.

The rest of this lesson teaches the AArch64 model in detail, because that is where most embedded Linux work happens today, and then returns to the AArch32 model where the STM32MP1 needs it.

Diagram in production
AArch64 against AArch32: registers, instructions and privilege model
03

The AArch64 register file and PSTATE

4 min read

The 31 general-purpose registers are x0 through x30, each 64 bits. Writing to the 32-bit form w0 through w30 zeroes the upper 32 bits of the matching x register, so w0 and x0 are two views of the same storage. Register 31 is special: in most instructions it is the zero register, written XZR for the 64-bit form and WZR for the 32-bit form. It always reads as zero and discards writes, which gives the architecture a cheap source of the constant zero and a sink for discarded results.

Two registers sit outside the general set. The stack pointer, the register holding the current top of the call stack, is not x31; there is one per exception level, named SP_EL0 through SP_EL3. Each exception level owns its own stack pointer, and software selects which one applies. The program counter (PC) is also not addressable as a general register; you read it indirectly, for example through the link register after a call or with the ADR and ADRP instructions.

Two general registers have fixed conventional roles. x30 is the . The BL instruction places the address of the next instruction into x30 and jumps, and RET branches to x30. x29 is the frame pointer by convention, used to walk stack frames in a debugger.

The procedure call standard, the ABI convention that assigns each register a role across function calls and says whether the caller or the callee must preserve it, is called AAPCS64 and fixes who saves what. x0 through x7 carry the first eight arguments, and x0 carries the return value (x8 for a large or indirect result). x9 through x15 are caller-saved scratch registers, meaning the callee may overwrite them and the caller must save any it needs. x16 and x17 are intra-procedure-call scratch, used by linker veneers and the dynamic linker, and x18 is the platform register, reserved for platform-specific use. x19 through x28 are callee-saved: the callee must restore them before returning, so they survive a call. x29 and x30 are the frame pointer and link register.

PSTATE holds the process state, including the four condition flags N, Z, C and V, which record the sign, zero, carry and overflow outcome of an operation and drive conditional branches. N is set when the result is negative, Z when it is zero, C on carry or borrow, and V on signed overflow. Compare instructions such as CMP and TST set these flags, and conditional branches and conditional selects use them. PSTATE also holds the DAIF mask bits that independently disable debug, SError, IRQ and FIQ.

Toggle each flag to see how the four NZCV bits pack together and what a comparison result means.

0x60 = binary 0110 0000: Z and C set, N and V clear — the comparison result was zero, so no borrow and no overflow.

  • fields: [{"name": "N", "lsb": 7, "width": 1}, {"name": "Z", "lsb": 6, "width": 1}, {"name": "C", "lsb": 5, "width": 1}, {"name": "V", "lsb": 4, "width": 1}]
  • value: 0x60
  • width: 8

A disassembly ties all of this together. The lab asks you to produce one like it; here is a small example to read first.

c
int helper(int x) { return x * 2; }

int compute(int x) {
    return helper(x) + 1;
}
asm
# aarch64-linux-gnu-gcc -O0 -c compute.c && objdump -d compute.o
# typical output, compiled at -O0 so the frame pointer is visible (yours will differ)
helper:
    sub     sp, sp, #16
    str     w0, [sp, #12]
    ldr     w0, [sp, #12]
    lsl     w0, w0, 1
    add     sp, sp, #16
    ret

compute:
    stp     x29, x30, [sp, #-16]!
    mov     x29, sp
    bl      helper
    add     w0, w0, 1
    ldp     x29, x30, [sp], #16
    ret

The argument arrives in w0. At -O0 the compiler spills it to the stack and reloads it, then LSL doubles it and RET returns through x30. In compute, STP saves x29 and x30 to the stack in one step (the ! updates the stack pointer), BL calls helper while placing the return address in x30, ADD adds one to the returned w0, LDP restores the two saved registers, and RET jumps back. The caller-saved registers are saved here because compute itself makes a call; a leaf function with no calls would not need to.

Diagram in production
The AArch64 general registers grouped by their procedure-call role
04

Exception levels EL0 to EL3

2 min read

An is the AArch64 answer to ring-based protection. There are four, and each has a conventional tenant.

EL0 is the least privileged, where user applications run. It cannot touch system registers or issue most privileged instructions.

EL1 runs the operating system kernel. Linux executes here on a system without a hypervisor, handling system calls, memory management and device drivers.

EL2 runs a hypervisor, software that can host multiple operating systems. KVM and Xen execute here. EL2 is optional: a board with no hypervisor boots Linux directly into EL1. On a system running KVM, Linux itself takes EL2 and its guests run at EL1.

EL3 is the most privileged and runs the secure firmware, such as Trusted Firmware-A. It is where the core starts at reset, and it is the only level that can see both the secure and the normal worlds, which is why the secure monitor lives here. The next section returns to this.

Movement between levels follows fixed rules. Taking an exception moves up to a higher or equal level; the hardware saves the return state and jumps into a vector table. ERET (exception return) moves back down. A program cannot simply branch into a higher level, and it cannot switch sideways between levels.

A few system registers steer this machinery. SCTLR_ELx controls system behaviour such as caches and endianness. HCR_EL2 controls the hypervisor view. SCR_EL3 configures the secure state, including the NS bit that decides whether lower levels run in the secure or normal world.

The AArch32 model that the STM32MP1's Cortex-A7 uses predates exception levels and works differently. Instead of four levels there are privileged modes: User, FIQ, IRQ, Supervisor (SVC), Abort, Undefined and System, plus Monitor for TrustZone and Hyp when virtualization extensions exist. Each mode has its own banked stack pointer and link register, and the FIQ mode banks several extra general registers so its handler can run without saving them. The CPSR register holds the NZCV flags, the current mode and the interrupt masks, and SPSR saves a copy across an exception. The rough mapping is User to EL0, Supervisor to EL1, Hyp to EL2, and Monitor to EL3, which is why the job for this lesson calls the modes the historical model: they are what AArch32 still uses today, and the exception levels are their AArch64 successor.

Diagram in production
The four exception levels and the software that runs at each
05

Exception classes and the vector table

4 min read

An exception is any event that makes the core stop its current flow, save state and execute handler code at a defined address, and interrupts, faults and system calls are all exceptions. They come in four classes in AArch64.

Synchronous exceptions are tied to a specific instruction: a system call issued with SVC, a data or instruction abort such as a page fault, an undefined instruction, or a debug breakpoint. IRQ is the ordinary interrupt request from devices. FIQ is the fast interrupt request, historically reserved for time-critical work and now usually routed to the secure world. SError is an asynchronous system error, for example a memory corruption reported by the platform. The first is synchronous; the last three are asynchronous, meaning they may arrive without a specific instruction to blame.

The handler address comes from a . Each exception level has its own table via its own VBAR_EL1, VBAR_EL2 or VBAR_EL3 register. The 16 entries fall into four groups of four: exceptions taken at the current level using the shared SP_EL0, those using the level's own SP_ELx, those taken from a lower level in AArch64, and those taken from a lower level in AArch32. Within each group the four entries are synchronous, IRQ, FIQ and SError, in that order.

When an exception is taken, the hardware performs a fixed sequence before jumping into the table. It saves the current PSTATE into SPSR_ELx, the address to return to into ELR_ELx, and a code describing the reason into ESR_ELx; for a data abort it also records the faulting address in FAR_ELx. It then sets the PSTATE mask bits to block further exceptions of the same kind, selects the target stack pointer, and loads the program counter from the matching table slot. ERET later restores the program counter from ELR_ELx and the state from SPSR_ELx.

The system call path shows this working. On AArch64 Linux a user program issues svc #0. The core takes a synchronous exception from EL0 in AArch64, lands in the table entry at offset 0x400 from VBAR_EL1, and the kernel reads the system call number from x8 and the arguments from x0 through x5.

Step by stepTaking and returning from an exception
  1. Event raised: a device asserts an interrupt, or an instruction faults or issues SVC; the core decides the exception class.

  2. State saved: PSTATE is copied to SPSR_ELx, the return address to ELR_ELx, and a reason code to ESR_ELx (and FAR_ELx for a data abort).

  3. Level raised: the core moves to the target exception level and switches to that level's stack pointer.

  4. Vector looked up: the class and the source state select one of the 16 slots at VBAR_ELx, and the core jumps there.

  5. Handler runs: kernel or firmware code services the event, possibly lowering the interrupt priority mask again.

  6. ERET returns: the program counter is restored from ELR_ELx and the state from SPSR_ELx, dropping back to the lower level.

Going deeperWhy the slots are 128 bytes apart

The 128-byte spacing (0x80) gives each slot room for a short branch or a small amount of inline handler code, and the whole table must be 2 KiB aligned so the hardware can derive an entry address by adding a fixed offset to the base in one step. On AArch32 the vector table is a plain list of branch instructions at a low or high vector base, without the per-level separation, which is another reason the AArch64 layout is cleaner to work with when you inspect kernel entry code.

Diagram in production
The 16-slot AArch64 vector table: four exception classes across four source states
06

TrustZone: the secure world and the normal world

3 min read

is not a separate chip but a property carried on every memory and peripheral transaction. The secure world can access both worlds; the normal world can reach only non-secure resources. A piece of memory or a peripheral is made secure by configuration, and any normal-world access to it is blocked by the bus.

The worlds reuse the exception levels. EL0 and EL1 exist in both worlds: normal EL1 runs Linux, while secure EL1 runs a trusted OS. EL2, the hypervisor, runs in the normal world on classic designs, with secure EL2 arriving only in ARMv8.4. EL3 exists only in the secure world, which is why the secure monitor lives there: it is the single most-privileged place that can see both sides and control the switch.

The switch is a world switch, not a normal function call. The normal world issues an (smc #0). The core traps into EL3, the secure monitor saves the normal-world context, flips the NS bit in SCR_EL3 to enter the secure world, performs the requested service, restores the context and returns. The NS bit selects the world for lower levels: set, they are normal; clear, they are secure.

The secure world holds a . On the STM32MP1 the secure side runs TF-A and optionally OP-TEE, while a stock Raspberry Pi ships with no meaningful use of TrustZone in its standard firmware flow.

Why place secure firmware at EL3 rather than EL1? Because EL3 is the highest privilege, runs first at reset before any untrusted code, and is the only level with simultaneous visibility of both worlds. That combination makes it the natural root of trust, and it is the design the next section turns into software.

Secure does not mean bug-free

TrustZone isolates the normal world from secure resources, but a bug in the secure-world code itself still compromises the keys it protects. Treat the TEE as a smaller, audited surface, not as an automatic guarantee.

Diagram in production
The secure and normal worlds sharing the exception levels, with EL3 as the bridge
07

TF-A: the secure world in stages

4 min read

, formerly Arm Trusted Firmware, is the standard secure firmware on Arm boards. The stages are named BL1 through BL33, and each has a fixed job.

BL1 is the first stage, running from on-chip ROM or SRAM before external memory works. It performs the minimum initialisation and loads BL2. On many boards, including the STM32MP1, the manufacturer's ROM code plays BL1's role and loads BL2 directly, so the TF-A build you inspect starts at BL2.

BL2 runs in internal SRAM. It brings up the DRAM controller, configures the clock tree where needed, verifies the next images when trusted boot is on, and loads them into DRAM.

BL31 is the EL3 runtime firmware, the secure monitor that stays resident. It provides the runtime services an OS needs, above all PSCI, and handles SMC calls from the normal world. On an AArch64 core BL31 runs at EL3; on the AArch32 Cortex-A7 of the STM32MP1 the same role is played by a minimal build called SP_MIN, running in Monitor mode.

BL32 is optional and holds a TEE, usually OP-TEE, in secure EL1. BL33 is the normal-world payload, typically U-Boot, which then loads Linux.

The images are bundled into a firmware image package (FIP), the TF-A container format that groups BL2, BL31, BL32 and BL33, with their configuration, into one binary for the loader. A boot chain on the STM32MP1 therefore runs: ROM code (as BL1) loads BL2 into SRAM; BL2 loads BL31 or SP_MIN, the optional BL32, and U-Boot as BL33; U-Boot loads Linux. This is the chain you will reconfigure and rebuild later in the module.

Walk the chain stage by stage; the BL32 step is only present when a TEE such as OP-TEE is built in.

STM32MP1 boot chain: ROM code (BL1) loads BL2 into SRAM; BL2 loads BL31 or SP_MIN, the optional BL32 (OP-TEE) and U-Boot as BL33; U-Boot loads Linux.

  • states: [{"id": "bl1", "label": "BL1 (ROM code)"}, {"id": "bl2", "label": "BL2 (SRAM)"}, {"id": "bl31", "label": "BL31 / SP_MIN (EL3 / Monitor)"}, {"id": "bl32", "label": "BL32 (OP-TEE, optional)"}, {"id": "bl33", "label": "BL33 (U-Boot)"}, {"id": "linux", "label": "Linux"}]
  • transitions: [{"from": "bl1", "to": "bl2", "event": "loads BL2"}, {"from": "bl2", "to": "bl31", "event": "loads BL31 / SP_MIN"}, {"from": "bl31", "to": "bl32", "event": "with TEE"}, {"from": "bl31", "to": "bl33", "event": "no TEE"}, {"from": "bl32", "to": "bl33", "event": "hands to BL33"}, {"from": "bl33", "to": "linux", "event": "loads Linux"}]

Building TF-A is ordinary Make, with the platform selected by variable rather than by Kconfig. A typical build for the STM32MP1, adapted from the ST and Bootlin documentation, looks like this.

bash
# typical TF-A build for the STM32MP1 (AArch32 Cortex-A7); paths and names vary by release
make CROSS_COMPILE=arm-none-eabi- \
     ARM_ARCH_MAJOR=7 \
     ARCH=aarch32 \
     PLAT=stm32mp1 \
     AARCH32_SP=sp_min \
     DTB_FILE_NAME=stm32mp157a-dk1.dtb \
     BL33=/path/to/u-boot/u-boot-nodtb.bin \
     BL33_CFG=/path/to/u-boot/u-boot.dtb

The key variables are CROSS_COMPILE for the toolchain prefix, ARCH for the execution state, ARM_ARCH_MAJOR for the ISA version, PLAT for the platform directory, AARCH32_SP to choose between the built-in SP_MIN and OP-TEE, and BL33 to name the normal-world bootloader to package. The lab asks you to run this, list the produced BL1, BL2, BL31 or SP_MIN and BL33 images, and describe what each does at boot, which is exactly the mapping this section gave you.

Going deeperTrusted boot turns the chain into a chain of trust

With secure boot enabled, each stage verifies the signature of the next before executing it, so the root of trust in ROM extends to BL2, then to BL31 and BL32, and finally to BL33. A corrupted U-Boot is then detected and refused rather than run. The verification uses a public key whose matching private key signs each image, and the keys live in the secure world, out of reach of the normal-world OS. This is why the secure firmware must load and verify the bootloader, rather than the other way around.

Diagram in production
The TF-A boot stages from ROM code through to U-Boot and Linux
08

The GIC: interrupts in silicon

4 min read

An is the standard interrupt controller on Cortex-A and Cortex-R. Every interrupt is identified by an ID in three ranges. A software-generated interrupt (SGI), IDs 0-15, is raised by software to signal other cores and is the basis of inter-processor interrupts. A private peripheral interrupt (PPI), IDs 16-31, is delivered only to the core it belongs to, such as the architecture timer. A shared peripheral interrupt (SPI), ID 32 and above, is raised by a peripheral and can be routed to one or more cores.

The distributor is the single central block: it gathers all shared interrupts, holds their priority, enable and target settings, and forwards them to the cores. It stores, for each interrupt, its priority, whether it is enabled, whether it is secure or non-secure, and which cores may receive it. The CPU interface, the per-core GIC component that applies the priority mask, raises IRQ or FIQ to its core, and hands the interrupt ID to the handler on acknowledgement, sits next to each core and does the delivery.

Priority and preemption follow simple rules. Each interrupt has an 8-bit priority where a lower number means higher priority. The CPU interface compares an incoming interrupt's priority against its priority mask and the priority of any interrupt already running; a sufficiently high-priority interrupt can preempt a lower-priority handler, and the GIC records the running priority so the handler knows its place. Handlers end an interrupt by acknowledging it (reading the ID from the interface) and then signalling end-of-interrupt when finished.

IRQ and FIQ are the two request lines into the core, and their division changed between generations. In AArch32, FIQ mode banks extra registers, so an FIQ handler can start without saving them, making FIQ the fast path. In AArch64, Linux runs its normal handlers on IRQ, and FIQ is typically routed to the secure world, which lets secure firmware receive a high-priority interrupt without the normal-world OS masking it. This is why you will see almost no FIQ use in a normal AArch64 Linux kernel.

Affinity decides which core a shared interrupt reaches. GICv2 gives each SPI a target list of up to eight cores. GICv3 replaced that with affinity routing: the distributor picks a target from the cores that expressed interest, using the same affinity hierarchy used to identify cores, and adds a per-core redistributor plus an interrupt translation service (ITS) for message-based LPIs, the mechanism behind PCIe MSI interrupts. GICv4 adds direct virtual interrupt injection for virtualised workloads. The STM32MP1 uses a GIC-400, a GICv2 part, and its device tree declares it with the compatible string arm,cortex-a7-gic.

Step by stepHow a device interrupt reaches a handler
  1. Device asserts the line: a peripheral such as a UART or MMC controller raises its interrupt output to the GIC.

  2. Distributor ranks it: the GIC looks up the interrupt's priority, group and target cores, and forwards it if enabled.

  3. CPU interface gates it: the target core's interface compares the priority against its mask and asserts IRQ or FIQ to the core.

  4. Core takes the exception: the core jumps through the IRQ entry of its vector table, saving state as described earlier.

  5. Handler acknowledges: software reads the interrupt ID from the CPU interface, which records the running priority.

  6. Handler finishes: the driver services the device and signals end-of-interrupt, dropping the running priority so lower-priority interrupts resume.

Cortex-M uses a different controller

Cortex-M microcontrollers have no GIC. They use a nested vectored interrupt controller (NVIC), where each interrupt has its own vector and priority and the hardware can tail-chain and preempt handlers automatically. The concepts of priority and preemption transfer, but the registers and model do not.

Diagram in production
The path of one interrupt from the peripheral to a handler on one core
09

PSCI, SMC and OP-TEE

3 min read

solves a coordination problem. Turning a core on means powering it, resetting it and setting its entry point, none of which an OS at EL1 can safely do by itself on a multicore SoC. PSCI standardises those requests so one kernel works across boards whose power controllers differ.

Each PSCI function has a fixed ID drawn from the secure monitor call calling convention (SMCCC), the Arm standard that assigns function IDs to SMC calls and fixes how arguments and return values pass between the OS and EL3. The IDs you will meet most are PSCI_VERSION (0x84000000), CPU_ON (0xC4000003), CPU_OFF (0x84000002), AFFINITY_INFO (0xC4000004), SYSTEM_OFF (0x84000008) and SYSTEM_RESET (0x84000009). The top bits distinguish a 32-bit function from its 64-bit form.

The call flow is mechanical. The OS places the function ID in x0 and the arguments in x1 through x3, then executes smc #0 (or hvc #0 under a hypervisor). The core traps to EL3, BL31 decodes the ID and does the work. For CPU_ON the arguments are the target core's affinity, its entry-point address and a context ID; BL31 powers the core, resets it into the entry point, and returns success or failure in x0.

Linux uses this on every Arm board. The kernel probes for PSCI during boot, registers a client in drivers/firmware/psci, and then brings secondary cores online, enters idle states and suspends through it. You can see the probe in the boot log with a line such as "psci: probing for conduit method from DT", and a reboot issued in Linux ends as a PSCI SYSTEM_RESET call into BL31. The boot-time optimisation work later in this module depends on exactly these calls.

The same SMC mechanism reaches the TEE. OP-TEE (open portable trusted execution environment), the open-source TEE that runs as BL32 in secure EL1 and hosts signed trusted applications, is the most common BL32. A normal-world client calls into OP-TEE through SMC; BL31 forwards the request to secure EL1, where OP-TEE runs the requested trusted application and returns. Trusted applications are signed, isolated from each other and from the normal world, and used for key storage, secure clocks and other small, sensitive services.

Going deeperThe SMC calling convention in detail

An SMC call carries a 32-bit function ID in w0. The top bit selects SMC64 versus SMC32, and the next bits encode whether it is a fast call or a yielding call that may sleep, plus the owning standard (PSCI, OP-TEE and others each have a range). Arguments travel in x1 through x6, results return in x0 through x3, and a negative return in x0 signals an error whose code is the PSCI or SMCCC error value. The convention is what lets one EL3 firmware serve PSCI, OP-TEE and vendor services from a single instruction.

Diagram in production
A PSCI CPU_ON call and a TEE call, both travelling through SMC into EL3
10

Linux and interrupts: /proc/interrupts and handlers

5 min read

The number a device uses in Linux is not the GIC ID. Linux works in a that translates the controller's own hardware IRQ (hwirq) into a Linux IRQ number. The GIC driver registers a domain, and when a device driver asks for its interrupt, the domain allocates a Linux IRQ number and records the mapping back to the GIC ID.

This separation is what the device tree describes. A peripheral node carries an interrupts property listing the controller, the hardware number and the trigger type. For a GIC the first cell says which type, usually GIC_SPI (0) or GIC_PPI (1), the second gives the ID, and the third the trigger, for example level-high.

dts
/* a peripheral wired to GIC SPI 61, active high level-triggered */
interrupts = <GIC_SPI 61 IRQ_TYPE_LEVEL_HIGH>;

A driver obtains its Linux IRQ number with the platform_get_irq helper or by parsing this property, then registers a handler. The registration call is request_irq, which takes the IRQ number, the handler function, flags, a name and a device pointer, or request_threaded_irq when the handler should run in a process context. A handler runs in interrupt context, where sleeping is forbidden and only a subset of kernel functions are safe to call, so anything slow is deferred to a bottom half such as a workqueue or a threaded handler.

/proc/interrupts is the system-wide record. Each line gives the Linux IRQ number, then one count per CPU, then the controller name, the hardware number on that controller, the trigger type and the device name. Typical output for a dual-core board looks like the following, and the exact numbers, controller name and device names differ on every board.

text
# typical output on a dual-core Cortex-A7 board (yours will differ)
           CPU0       CPU1
  3:      98765      98765     GIC-0  27 Level     arch_timer
 36:       1234          0     GIC-0  61 Level     40010000.serial
 39:        512          0     GIC-0  84 Level     58005000.mmc

The first column is the Linux IRQ number, the column after the CPU counts is the controller (here a GIC) and its hardware number (the GIC ID), then Level or Edge, then the device. The lab asks you to map a device back the other way: find it in /proc/interrupts, read the hardware number, and confirm it matches the GIC SPI number in the device tree, which is exactly the hwirq-to-Linux-IRQ translation this section describes.

Three mistakes recur in interrupt work, each with a symptom, cause, diagnosis and fix.

Sleeping in a handler. Symptom: the kernel logs a BUG such as "scheduling while atomic" and the system may hang. Cause: the handler called a function that may sleep, such as a mutex or memory allocation with certain flags, while running in interrupt context. Diagnose: read the backtrace, which names the offending call inside the handler. Fix: move the slow work to a workqueue or a threaded handler, or make the allocation non-sleeping.

Wrong trigger type. Symptom: a level-triggered interrupt configured as edge, or the reverse, produces either a storm of repeated interrupts or an interrupt that never fires. Cause: the trigger type in the device tree does not match the hardware. Diagnose: compare the interrupts property flags with the datasheet and with the line as wired. Fix: correct the trigger cell and rebuild the device tree.

Missing end-of-interrupt. Symptom: the interrupt fires once and then the device or a lower-priority interrupt stops. Cause: the driver never signalled end-of-interrupt to the GIC, so the running priority never dropped. Diagnose: check that the handler always reaches the EOI path on every exit, including error returns. Fix: restore the acknowledgement and end-of-interrupt calls in the right order, and be careful with shared IRQ lines, which need IRQF_SHARED so several handlers can register on one line and must each return IRQ_HANDLED or IRQ_NONE correctly.

Going deeperirq domains and why the numbers differ

Linux IRQ numbers are sparse and allocated at boot, which is why two identical boards can show different numbers for the same device if probe order changes. The hardware ID is stable; the Linux number is not. The domain also handles hierarchy: a GPIO controller can itself be an interrupt controller whose lines sit behind a parent GIC, so a pin's interrupt travels through the GPIO domain and then the GIC domain, with a different hwirq at each level. This is the machinery behind the interrupt numbers you will chase in the lab and in later driver work.

Diagram in production
How a device-tree interrupt becomes a Linux IRQ number and a line in /proc/interrupts
11

Try it

1 min read

Disassemble a short C function with objdump and identify the argument, return, frame-pointer and link registers and the BL, RET, STP and LDP instructions it uses, then explain who saves each register across the call. Dump /proc/interrupts on a running board and map one device line back to its GIC SPI number in the device tree, confirming the trigger type. Finally, build TF-A for the STM32MP1 and list the produced BL1, BL2, BL31 or SP_MIN and BL33 images, describing the job of each stage at boot. The practice pack checks these mappings and the exception-level and interrupt-flow reasoning against your own measurements.

Key takeaways

  • Arm sells core designs, not chips: Cortex-A runs Linux with an MMU, Cortex-M runs firmware without one, and Cortex-R targets deterministic real-time control.
  • AArch64 gives 31 general registers, a dedicated stack pointer and link register, and NZCV flags, and the procedure call standard fixes who saves which register.
  • The core moves to a higher exception level only by taking an exception and returns with ERET; EL3 is the highest level and runs secure firmware.
  • The vector table has 16 entries, 128 bytes apart, four classes per group, with the base address in VBAR_ELx.
  • TrustZone is a hardware split between secure and normal worlds, and the SMC instruction is the only door between them.
  • TF-A is a chain of stages, BL1, BL2, BL31 and an optional BL32, that ends by handing off to U-Boot as BL33.
  • The GIC gives every interrupt an ID, SGI 0-15, PPI 16-31 and SPI 32 upwards, and routes it to cores by priority and affinity.
  • Linux gives each device interrupt a software IRQ number through an irq domain and logs every delivery in /proc/interrupts.

Reflect

  1. Explain to a colleague, in two sentences: identify the three Cortex profiles and the AArch64 and AArch32 execution states, and state which one the STM32MP1 and the Raspberry Pi use.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?

On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

Practise this lessonExercises, quiz, interview preparation and spaced review

References and further reading

Official documentation first. Links checked when the lesson was published.

Find your next step

↑ ↓ to move · Enter to open · Esc to close