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.2 PMSAv8 regions: MPU_RBAR, MPU_RLAR, MPU_MAIRn

The Armv8-M MPU (PMSAv8) describes each region with a base and an inclusive limit, both at 32-byte granularity. This replaces the Armv7-M (PMSAv7) scheme, in which a region was a power of two in size, aligned to its size, and split into eight subregions.

You select a region with MPU_RNR, then write two registers:

MPU_RBAR: BASE[31:5] | SH[4:3] | AP[2:1] | XN[0]
MPU_RLAR: LIMIT[31:5] | PXN[4] (v8.1-M) | AttrIndx[3:1] | EN[0]
  • Address range: The region covers BASE:00000 up to and including LIMIT:11111. A 200-byte buffer therefore takes 224 bytes at any 32-byte-aligned base. PMSAv7 would have needed 256 bytes aligned to 256.
  • AP[2:1]: AP[2] makes the region read-only. AP[1] allows unprivileged access. So 00 is privileged read/write, 01 is read/write at any privilege, 10 is privileged read-only, and 11 is read-only at any privilege. No encoding gives privileged read/write together with unprivileged read-only, which PMSAv7 did allow.
  • SH: 00 Non-shareable, 10 Outer Shareable, 11 Inner Shareable. 01 is reserved. SH has no effect for Device memory, which is always treated as Shareable.
  • AttrIndx: Selects one of eight attribute bytes in MPU_MAIR0 (Attr0-3) and MPU_MAIR1 (Attr4-7). These are encoded like AArch64 MAIR_ELx. 0b0000dd00 is Device, where dd = 00 nGnRnE, 01 nGnRE, 10 nGRE, 11 GRE. Otherwise the high nibble gives outer and the low nibble inner Normal attributes. For example, 0x44 is Normal Non-cacheable and 0xFF is Write-Back Non-transient Read/Write-Allocate.

On Mainline, the alias registers MPU_RBAR_A1..A3 and MPU_RLAR_A1..A3 access the region numbered MPU_RNR[7:2]:n. Within an aligned group of four regions, you can program all four with one block store and without rewriting MPU_RNR.

Coming from A-profile: Think of each region as one identity-mapped translation-table block descriptor with an arbitrary span at 32-byte granularity. AttrIndx into MAIR works just like the 3-bit AttrIndx in an AArch64 descriptor.

Checkpoint

Q3.2.1 A 1000-byte stack starts at 0x20001020. What is the smallest PMSAv8 region that covers it, and how is it programmed?

  • A. BASE=0x20001020, LIMIT=0x20001408, because LIMIT is the exclusive end of the stack
  • B. Not possible: the region must be 1024 bytes and aligned to 1024
  • C. BASE=0x20001020, LIMIT field=0x20001400 (inclusive end 0x2000141F), which gives 1024 bytes, 24 more than the stack, because 1000 is not a multiple of 32
  • D. BASE=0x20001000, LIMIT=0x200013FF, because BASE must be aligned to the region size
Answer

C. The stack’s last byte is 0x20001407. LIMIT is inclusive with bits[4:0] taken as 0x1F, so the 32-byte granule 0x20001400 must be the limit, and the region covers 1024 bytes. No alignment to the region size is needed. The power-of-two answer and the size-aligned answer both describe PMSAv7 rules, which Armv8-M dropped.

Read more: Armv8-M ARM (DDI0553), MPU_RBAR / MPU_RLAR register descriptions

Q3.2.2 MPU_MAIR0.Attr1 = 0x04 and a region uses AttrIndx=1 with SH=0b11. What is the effective memory type?

  • A. Device-nGnRE. SH has no effect for Device memory
  • B. Normal Inner Shareable, Inner Write-Through
  • C. Device-nGnRnE, Inner Shareable
  • D. Normal Non-cacheable
Answer

A. 0x04 is 0b0000_0100: the high nibble 0000 selects Device, and dd=01 selects nGnRE. SH has no effect for Device memory. Reading 0x04 as a pair of Normal nibbles is the usual mistake, but a high nibble of 0000 means Device.

Read more: Armv8-M ARM (DDI0553), MPU_MAIR0 / MPU_MAIR1 attribute encoding