1.6 Reset, the vector table and the system address map
Reset. The core reads the vector table at the address held in VTOR. Its reset value is IMPLEMENTATION DEFINED and is often a configuration input. With the Security Extension, the Secure VTOR (VTOR_S) is the one used at reset.
word 0 : initial value of SP_main (MSP; MSP_S with Security Ext)
word 1 : reset vector (bit[0] must be 1 -> EPSR.T)
word 2+: NMI, HardFault, ... , external interrupts
After reset the core is in Thread mode, privileged, using MSP (CONTROL = 0), and in Secure state if the Security Extension is implemented. PRIMASK, FAULTMASK and BASEPRI are 0. The MPU is disabled and the configurable faults are disabled. Caches, where present, are normally off until software enables them. Because the reset vector is just an address and MSP is already loaded, the reset handler can be a C function (it still has to initialise .data/.bss before relying on them).
On Baseline, VTOR is an implementation option; on the Cortex-M23 it is a configuration choice. Relocating the table at runtime is a privileged write to VTOR. If you first copied the table into RAM, put a DMB (or DSB) between the copy and the VTOR write, because the Normal-memory stores are not ordered against the Device store. Follow the VTOR write with DSB so that it has completed before a later exception entry.
Fixed address map (default attributes apply when the MPU is off):
| Range | Region |
|---|---|
| 0x00000000-0x1FFFFFFF | Code (Normal, executable) |
| 0x20000000-0x3FFFFFFF | SRAM (Normal, executable) |
| 0x40000000-0x5FFFFFFF | Peripheral (Device, XN) |
| 0x60000000-0x9FFFFFFF | External RAM (Normal, executable) |
| 0xA0000000-0xDFFFFFFF | External device (Device, XN) |
| 0xE0000000-0xE00FFFFF | PPB (SCS at 0xE000E000-0xE000EFFF; XN) |
| 0xE0100000-0xFFFFFFFF | Vendor_SYS (Device, XN) |
The SCS holds the SCB, NVIC, SysTick, MPU, SAU, the fault status registers and debug control. PPB accesses are always little-endian and always use the default memory map, whatever the MPU says. SCS accesses are privileged-only: an unprivileged access causes a BusFault, with narrow exceptions such as STIR when CCR.USERSETMPEND is set. (Some other PPB components, such as ITM stimulus ports, can be configured for unprivileged access.)
System control is memory-mapped for two reasons: C code can configure the system with plain loads and stores, and a debugger can access the same registers over the debug access port while the core runs. The PPB is Device-nGnRnE memory. To guarantee that a configuration change, such as enabling the MPU, is in effect for the following instructions, use DSB followed by ISB.
Coming from A-profile: Where AArch64 uses
MSR SCTLR_EL1/VBAR_EL1followed by an ISB, M-profile uses stores to the SCS. Because the change is now a memory store, you first need a DSB to guarantee that the Device store has completed, and only then the ISB to refetch. DSB then ISB is the pairing to remember.
Checkpoint
Q1.6.1 Which sequence correctly describes what an Armv8-M Mainline core with the Security Extension does on reset?
- A. It loads PC from word 0 and SP from word 1, then starts in Handler mode on MSP, Non-secure.
- B. It branches to address 0x00000000 in Thread mode, unprivileged on PSP, and software must load SP first.
- C. It loads PC from word 1 and starts in Handler mode with IPSR = 1 (Reset), on MSP, Secure.
- D. It loads MSP from word 0 and PC from word 1 (EPSR.T from bit[0]) of the table at the reset VTOR, then starts in Thread mode, privileged, on MSP, in Secure state.
Answer
D. Word 0 is the initial SP_main and word 1 is the reset vector. Execution starts in privileged Thread mode on MSP, in Secure state when TrustZone is present. Treating reset as an exception that leaves you in Handler mode is tempting, but the reset handler runs in Thread mode. The table is not executed as code at address 0 either.
Read more: Armv8-M ARM (DDI0553), Reset behavior; vector table
Q1.6.2 With the MPU disabled, a corrupted function pointer holding 0x40001001 makes a Mainline core execute BLX r3, so it branches to 0x40001000 (the Peripheral region) with EPSR.T = 1. What happens?
- A. The core executes whatever the peripheral returns as instructions.
- B. An instruction fetch from an execute-never region is attempted, which raises a MemManage fault (IACCVIOL). If MemManage is not enabled, it escalates to HardFault.
- C. It is undefined, because the default map gives no attributes when the MPU is off.
- D. An INVSTATE UsageFault is raised, because the Peripheral region cannot hold T32 code.
Answer
B. The default system address map applies when the MPU is off, and it marks the Peripheral, Device and system regions as execute-never. The fetch therefore faults as an instruction access violation (MemManage, which escalates if disabled). INVSTATE depends only on EPSR.T, which is 1 here because bit[0] of the target was set, so it is a distractor.
Read more: Armv8-M ARM (DDI0553), System address map and default memory attributes
Q1.6.3 Privileged code enables the MPU by writing MPU_CTRL in the SCS, and the next instruction relies on the new protection. Which sequence is architecturally sufficient?
- A. Store to MPU_CTRL, then DSB, then ISB
- B. Store to MPU_CTRL, then DMB
- C. Store to MPU_CTRL only, because SCS accesses are Device-nGnRnE and therefore immediately effective for the instruction stream
- D. Store to MPU_CTRL, then ISB, then DSB
Answer
A. The DSB ensures that the SCS store has completed, and the ISB then flushes and refetches subsequent instructions so that they see the new MPU configuration. Device-nGnRnE ordering does not make the side effect visible to instructions already fetched, and a DMB only orders memory accesses. ISB before DSB gets the order wrong, because the context synchronization could happen before the write completes.
Read more: Armv8-M ARM (DDI0553), Memory barriers (DSB, ISB) and SCS register side effects; MPU_CTRL