journal 2026-05-03

P48 - trap delegation CSR scaffolding

p48riscvmdelegcsrautonomous-mode

Autonomous-mode rung. Same scaffold-then-behavior split as P47: P48 lands the address-map for medeleg/mideleg; the actual trap delegation behavior comes later.

What landed

Two CSRs added to src/top.sv:

addrnamefuture role
0x302medelegexception delegation mask
0x303mideleginterrupt delegation mask

Two localparams, two 32-bit storage flops, entries in csr_known/csr_writable/csr_read()/reset/S_EXECUTE write. About 25 lines.

Probe writes 0xDEADC001 -> medeleg, 0xDEADC002 -> mideleg, reads each back. Error codes 90-91.

PASS at 5,101,647 clocks; FreeRTOS demo halts cleanly.

Why these specifically

Linux writes both medeleg and mideleg very early in boot to delegate page-fault, ecall-from-U, and the supervisor timer/external interrupt sources to S-mode. Without these addresses decoded, the kernel hits an illegal-CSR trap before it even sets up its own trap vector.

In P48 the bits only store. The chip’s trap entry still routes every trap to M-mode; mret still returns to whatever priv mode the chip was in (M). That’s the next rung.

Stop point

This is the 4th rung past P45 (P45=A, P46=Zba/Zbb, P47=S CSRs, P48=delegation CSRs). Per the autonomous wakeup plan, P48 is the stop. Remaining work is committing, not implementing.

Wart count

Zero new ones. P46’s gcc-zbb-auto-emit hang is still the outstanding open issue.