Physical Memory Protection (PMP) is RISC-V's mechanism for restricting memory access from less-privileged modes. In Cerberus-OS, I use PMP to enforce task isolation at the hardware level: each task can only access its own stack and data regions. If it tries to access another task's memory, the hardware raises a trap — the kernel handles it, isolates the fault, and the system continues.
RISC-V has up to 16 PMP entries (RV32) or 64 (future extensions). Each entry defines a region via address and configuration register:
pmpcfg0: region 0 config — R/W/X permissions + address matching mode
pmpaddr0: region 0 addressAddress matching modes:
TOR(top of range): region is [pmpaddr(n-1), pmpaddr(n))NA4: naturally aligned 4-byte regionNAPOT: naturally aligned power-of-two region
In Cerberus-OS, the kernel runs in M-mode (machine mode, full access). Tasks run in U-mode (user mode, PMP-restricted). On task switch, the kernel reprograms the relevant PMP entries for the incoming task. Context switch overhead includes 2-4 CSR writes for PMP reconfiguration.
The critical invariant: a task in U-mode with PMP entries set to its own memory regions physically cannot read or write another task's memory. Not "the software prevents it" — the hardware prevents it. This is the difference between software isolation (bypassable) and hardware isolation (not bypassable without exploiting the kernel itself).