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

3.1 The default memory map and v8-M memory types

On A-profile, memory attributes come from the translation tables. With stage 1 translation disabled, data accesses are treated as Device-nGnRnE. M-profile instead has a fixed system address map that gives every address a memory type, cacheability and execute permission. This map applies when the MPU is disabled. It is also the background map that the MPU can fall back to.

RangeRegionDefault attributes
0x00000000-0x1FFFFFFFCodeNormal, Write-Through, executable
0x20000000-0x3FFFFFFFSRAMNormal, Write-Back Write-Allocate, executable
0x40000000-0x5FFFFFFFPeripheralDevice-nGnRE, XN
0x60000000-0x9FFFFFFFRAMNormal (WBWA below 0x80000000, WT above), executable
0xA0000000-0xDFFFFFFFDeviceDevice-nGnRE, XN
0xE0000000-0xFFFFFFFFSystemPPB is Device-nGnRnE, Vendor_SYS is Device-nGnRE; the whole region is XN

Two rules about the System region matter later:

  • The System region is always execute-never, whatever the MPU says.
  • Accesses to the PPB (0xE0000000-0xE00FFFFF) always use the default map, and the MPU does not apply to them. The PPB holds the SCS, which contains the SCB, NVIC, SysTick and MPU registers. So an MPU region cannot lock privileged code out of the MPU registers. Most PPB accesses still require privilege.

The memory types are the same as in v8-A:

  • Normal memory has inner and outer cacheability (Non-cacheable, Write-Through, Write-Back, with allocation hints) and a shareability. The hardware may merge, reorder and speculatively access it.
  • Device memory comes in four types: Device-nGnRnE, Device-nGnRE, Device-nGRE and Device-GRE. G, R and E mean Gathering, Reordering and Early write acknowledgement. Speculative data accesses to Device memory are not permitted.

Do not plan on executing from Device memory. Every Device region in the default map is XN, and an MPU region that you give a Device attribute should be marked XN as well.

Coming from A-profile: With stage 1 translation off, an AArch64 core treats data accesses as Device-nGnRnE. An Armv8-M core with the MPU off still has cacheable Normal SRAM and code regions, because the default map gives them real attributes.

Checkpoint

Q3.1.1 The MPU is disabled. Firmware branches to a function that it copied to address 0x40001000 in a peripheral-region SRAM. What happens?

  • A. The code runs normally, because XN applies only when the MPU is enabled
  • B. The instruction fetch faults (MemManage on Mainline if it is enabled, otherwise HardFault; HardFault on Baseline), because the Peripheral region is XN in the default memory map
  • C. The code runs, but slowly, because Device memory cannot be prefetched
  • D. The fetch is treated as Normal Non-cacheable and succeeds
Answer

B. The default system address map makes the Peripheral region (0x40000000-0x5FFFFFFF) execute-never, with or without the MPU. If MemManage is disabled in SHCSR, the fault escalates to HardFault. The tempting wrong idea is that XN is only an MPU attribute, but the default map has its own XN regions.

Read more: Armv8-M ARM (DDI0553), the system address map / default memory map

Q3.1.2 A privileged task programs an MPU region over 0xE000E000 with privileged no-access, then enables the MPU. What happens on its next write to the NVIC?

  • A. MemManage fault, because the region denies access
  • B. The write succeeds only if PRIVDEFENA is 1
  • C. HardFault, because the MPU region overlaps the background region
  • D. The write succeeds, because accesses to the PPB always use the default memory map and the MPU does not check them
Answer

D. The MPU does not apply to PPB accesses. They always use the default map, which is how the SCS stays reachable for privileged code. PRIVDEFENA only matters for addresses that match no MPU region, and it does not decide this case.

Read more: Armv8-M ARM (DDI0553), the PPB and MPU interaction in the system address map