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

4.4 Banked state and exceptions across Security states

Banked per Security state:

  • Stack pointers: MSP_S/MSP_NS and PSP_S/PSP_NS.
  • Stack limits: MSPLIM/PSPLIM. Without the Main Extension (Baseline) only the Secure limits are implemented.
  • CONTROL: nPRIV and SPSEL are banked. FPCA is shared, and SFPA appears only in the Secure view.
  • Mask registers: PRIMASK, plus BASEPRI and FAULTMASK (Mainline only).
  • VTOR_S/VTOR_NS, the MPU, and several SCB registers and fields (for example parts of SHCSR, CCR and SCR).
  • SysTick, when two are implemented. With a single SysTick, ICSR.STTNS assigns it to one state.

Secure code reaches the Non-secure copies with MRS/MSR on names such as MSP_NS and CONTROL_NS, and, for memory-mapped registers, through the Non-secure alias of the System Control Space at 0xE002E000-0xE002EFFF. For example, 0xE002ED08 is VTOR_NS. The normal 0xE000Exxx addresses reach the bank of the current state. R0 to R12, LR and the FP registers are shared.

Exception targeting. NVIC_ITNS sets, per external interrupt, whether it targets Non-secure state. Several system exceptions are banked (SVCall, PendSV, SysTick, MemManage, UsageFault). AIRCR.BFHFNMINS=1 makes BusFault and NMI Non-secure and lets faults target a Non-secure HardFault; Secure faults still go to the Secure HardFault. AIRCR.PRIS remaps Non-secure programmable priorities into the lower-priority half, so a Secure exception configured in the upper half can always preempt Non-secure ones. Only Secure privileged code can write ITNS, BFHFNMINS and PRIS.

Secure background, Non-secure handler. In this case the PE pushes the normal caller-saved frame plus an additional state context onto the Secure stack: an integrity signature (0xFEFA125B, or 0xFEFA125A when an extended FP frame applies), a reserved word, and R4 to R11. It then clears the registers so the Non-secure handler sees no Secure values. EXC_RETURN records the situation:

  • ES (bit 0): the state the exception was taken to.
  • S (bit 6): the frame is on a Secure stack.
  • DCRS (bit 5): 0 means the callee-saved registers are already on the stack; 1 means default stacking rules.

On return, a bad integrity signature raises a SecureFault with INVIS (Secure HardFault on Baseline).

Coming from A-profile: On A-profile, EL3 firmware saves and restores the other world’s context in software, and the GIC (Group 0/1S/1NS) routes interrupts to a world. On v8-M, the NVIC with ITNS does the routing, and exception entry hardware protects the Secure context.

Checkpoint

Q4.4.1 Secure Thread code is running when an interrupt arrives whose NVIC_ITNS bit is 1. The interrupt is taken. Which description of entry is correct?

  • A. The PE pushes the standard 8-word frame onto the Non-secure stack and keeps R4-R11 live, because AAPCS makes the handler preserve them
  • B. The PE pushes the standard frame plus the additional state context (integrity signature, R4-R11) onto the Secure stack, clears the registers, and sets EXC_RETURN with ES=0, S=1, DCRS=0
  • C. The PE first takes the exception in Secure state, and Secure firmware must forward it to Non-secure
  • D. The interrupt stays pending until Secure code executes BXNS
Answer

B. A Secure background state with a Non-secure target is the case where hardware stacks the callee-saved registers and the integrity signature on the Secure stack, then clears registers so nothing leaks. EXC_RETURN encodes this as ES=0 (taken to NS), S=1 (frame on a Secure stack) and DCRS=0 (callee registers already stacked). Relying on AAPCS callee-save is tempting, but the Non-secure handler is untrusted and could simply read R4-R11.

Read more: Armv8-M ARM (DDI0553), exception entry, additional state context, EXC_RETURN

Q4.4.2 Secure boot firmware must set the Non-secure vector table base before launching the Non-secure image. Which access is correct?

  • A. Write VTOR at 0xE000ED08 from Secure state, because Secure state has access to both banks there
  • B. Execute MSR VTOR_NS, Rn
  • C. Write AIRCR.BFHFNMINS=1, which makes 0xE000ED08 refer to the Non-secure VTOR
  • D. Write the Non-secure alias at 0xE002ED08 from Secure state, which reaches VTOR_NS
Answer

D. Banked memory-mapped SCS registers reached at 0xE000Exxx hit the bank of the current state, so a Secure write to 0xE000ED08 changes VTOR_S. The Non-secure bank is reached through the 0xE002Exxx alias, which only Secure code can use (it is RAZ/WI from Non-secure state). MSR VTOR_NS does not exist, because VTOR is memory-mapped and not a special register (the _NS special-register names cover the stack pointers, CONTROL, the masks and the stack limits).

Read more: Armv8-M ARM (DDI0553), System Control Space, Non-secure alias; VTOR

Q4.4.3 What is the effect of setting AIRCR.PRIS = 1?

  • A. Secure exceptions are routed to Non-secure state
  • B. Non-secure code can now set its exception priorities to values numerically lower than any Secure exception
  • C. Non-secure programmable priorities are mapped into the lower-priority half of the priority range, so any Secure exception configured in the upper half can preempt every Non-secure exception
  • D. SecureFault is given priority -1
Answer

C. PRIS (“prioritize Secure exceptions”) remaps the effective priority of Non-secure exceptions into the bottom half of the range. Non-secure software then cannot configure a priority that blocks Secure exceptions placed in the upper half. A Secure exception that Secure software itself places in the lower half gets no such guarantee. The option claiming Non-secure code can go numerically below every Secure exception describes the opposite, which is the risk PRIS exists to remove.

Read more: Armv8-M ARM (DDI0553), AIRCR (PRIS, BFHFNMINS)