Overview
In the RISC-V Physical Memory Protection (PMP) architecture, address matching refers to the way boundaries of memory regions are calculated from the values stored in the PMP address registers (pmpaddrX). The address matching mode is encoded in bits [4:3] (A field) of the corresponding PMP configuration register (pmpcfgX), and determines how the address in pmpaddrX is interpreted when defining a region boundary.
Address Matching Modes
The RISC-V PMP specification defines three address matching modes for memory regions:
Top of Range (TOR) — In this mode, the value stored in
pmpaddrXrepresents the upper boundary of an arbitrary range. The lower boundary of the region is given by the previous PMP address register (or0for the first region), and the upper boundary is computed aspmpaddrX << 2. This effectively treats consecutivepmpaddrXentries as paired lower/upper bounds.Naturally Aligned Four-byte (NA4) — Indicates that the region is exactly four bytes long and is naturally aligned.
Naturally Aligned Power-of-2 (NAPOT) — Indicates a region whose size is a power of two and which is naturally aligned to that size. The size is encoded via the number of trailing 1 bits in the
pmpaddrXregister; the upper boundary is calculated as2^(n + 3)wherenis the number of set least-significant bits inpmpaddrX.
Operation
When PMP is enabled, the hardware performs an address matching check before each instruction fetch or memory access. The procedure is:
- Read the address matching mode (
Afield, bits [4:3]) from the relevantpmpcfgX. - Search the configured PMP regions for one that matches the target address, interpreting
pmpaddrXaccording to the selected mode (TOR, NA4, or NAPOT). - Once a matching region is found, decode the 3 least significant bits of the configuration register as permissions:
- Bit 2 (X) — Execute permission
- Bit 1 (W) — Write permission (store instructions)
- Bit 0 (R) — Read permission (load instructions)
If the requested access is not permitted by the region's permissions, a precisely trapped exception is raised.
Region Composition
Regions form a continuous address space: each region's upper boundary serves as the next region's lower boundary. A typical RISC-V PMP supports up to 64 such regions, defined by paired pmpaddrX/pmpcfgX registers. The smallest encodable region is 4 bytes (via NA4), while NAPOT supports arbitrarily large power-of-two sizes, and TOR supports arbitrarily positioned ranges.
Relationship to PMP
Address matching is a sub-mechanism of PMP that controls how region boundaries are computed. It does not by itself grant or deny accesses — that is determined by the X/W/R permission bits once a region match is found. Combined with PMP's lock bit (which prevents configuration writes until CPU reset), address matching and permissions together form the complete PMP protection model.
Other Contexts
The phrase "address matching" also appears in unrelated domains:
- In cryptocurrency privacy research, cross-chain address matching refers to techniques for identifying when seemingly incompatible address formats (e.g., Bitcoin vs. Ethereum) derive from the same underlying cryptographic public keys, enabling detection of key reuse across UTXO and account-based cryptocurrencies.
- In neuromorphic/parallel processor design, local target address matching describes a technique that eliminates the address bus between processor-memory nodes by matching destination addresses in situ, reducing data transport energy costs.
These uses are distinct from the RISC-V PMP context but share the underlying notion of comparing or resolving an address against one or more reference values.