4.1 The Security Extension model: state follows the address
The Armv8-M Security Extension (TrustZone for Armv8-M) is optional in both Baseline and Mainline. When it is implemented, the PE is in one of two Security states, Secure or Non-secure. Both states have Thread mode and Handler mode. Handler mode is always privileged, and Thread mode is privileged or unprivileged according to that state’s banked CONTROL.nPRIV. There are no exception levels, no Monitor mode, no SMC, no EL3 and no SCR_EL3.NS.
The architecture ties the Security state to the security attribute of the address the instruction is fetched from. Secure code runs from Secure memory and Non-secure code from Non-secure memory. The state can change only through mechanisms the architecture defines:
- NS to S: a branch to an
SGinstruction placed in Non-secure-callable (NSC) memory. - S to NS:
BXNSorBLXNS. - Non-secure code returning to Secure code by branching to the
FNC_RETURNvalue left byBLXNS. - Exception entry and exception return (
EXC_RETURN).
Any other attempt to fetch across the boundary faults instead of switching state. In Mainline that fault is a SecureFault, recorded in SFSR (for example INVEP, invalid entry point, or INVTRAN, invalid transition). Baseline has no SecureFault exception, so these faults escalate to the Secure HardFault.
Because hardware performs the switch, a call across the boundary costs little more than a function call through a veneer. No monitor software saves and restores the other world’s state, because the registers that need separation are banked per state (see section 4). The general-purpose registers R0 to R12 and LR are not banked. Software has to clear them, which is why the CMSE toolchain rules in section 5 exist.
At reset, a PE with the Security Extension starts in Secure state and fetches its vector table through VTOR_S. SAU_CTRL resets with ENABLE=0 and ALLNS=0, so the SAU attributes all memory as Secure (apart from the address ranges the architecture exempts from attribution, such as most of the PPB). Secure boot code must program the SAU (and possibly the IDAU and the system’s memory and peripheral protection controllers) and set up Non-secure state before branching to it with BXNS or BLXNS.
Coming from A-profile: On A-profile, SCR_EL3.NS selects the Security state of the lower ELs and EL3 software flips it during a world switch, typically on SMC. On v8-M nothing like SCR exists: the memory map selects the world and the PE checks every crossing in hardware.
Checkpoint
Q4.1.1 You look for the Armv8-M equivalent of SCR_EL3.NS to find out how the PE decides it is in Secure state. Which statement is correct?
- A. CONTROL.NS selects the Security state, and only Secure privileged code can write it
- B. The Security state follows the security attribute of the address the instruction is fetched from, and it changes only through SG, BXNS/BLXNS, a return to FNC_RETURN, or exception entry and return
- C. A Secure monitor running in Handler mode changes the state when software executes SVC #0xFF
- D. xPSR has an NS bit that the PE updates on every exception return
Answer
B. Armv8-M has no software-writable world-select bit. Executing from Secure memory means Secure state, and the only ways to cross are SG in NSC memory, BXNS/BLXNS, a branch to FNC_RETURN, and exception entry and return. CONTROL is the tempting distractor because it is a system register with mode-like bits (nPRIV, SPSEL), but it has no Security-state bit.
Read more: Armv8-M ARM (DDI0553), Security Extension: Security states and Security state transitions
Q4.1.2 A Mainline core with the Security Extension leaves reset. Secure boot code has not touched the SAU yet. What is the state of the system?
- A. The PE is in Non-secure state, and all memory is Non-secure until Secure firmware enables the SAU
- B. The PE is in Secure state, and only the IDAU attribution applies because the SAU is disabled
- C. The PE is in Non-secure state, and it traps to Secure on the first SG
- D. The PE is in Secure state, and because SAU_CTRL resets with ENABLE=0 and ALLNS=0 the SAU marks all memory Secure, which outranks any less-secure IDAU result
Answer
D. The PE resets into Secure state. With the SAU disabled and ALLNS=0, the SAU reports every (non-exempt) address as Secure. The SAU and IDAU results combine with the more secure one winning, so everything is Secure. The tempting distractor says the IDAU alone decides, but that only happens when ALLNS=1, because then the SAU reports Non-secure everywhere and the IDAU result is the one that counts.
Read more: Armv8-M ARM (DDI0553), SAU_CTRL and security attribution