5.1-5"Smcsrind/Sscsrind": Indirect CSR Access

Part II Linux boot: optional Vol. II (Privileged) pp. 80–84 · ~3 min read

  • indirect csr access

Twelve bits of CSR address space eventually run out — AIA alone wants register files bigger than the map allows. Indirect access multiplies the space: a select register picks a target, and six alias CSRs become windows onto it.

siselectWARL, 0..0xFFF mindecode routerunimplemented value→ illegal-instruction(recommended)sireg / sireg2 / sireg3sireg4 / sireg5 / sireg6extension stateIMSIC files (AIA)delegated counters(Smcdeleg)custom (MSB set)

One select, six windows. On RV32 the convention pairs sireg1-3 (low halves) with sireg4-6 (high halves) — 3 register arrays per select value either way.

The three CSR sets (Smcsrind = all; Sscsrind = S+VS only)
AddressesKey rules
miselect + mireg1-60x350-0x357 (0x354 skipped — it’s miph)May be read-only zero with no client extensions
siselect + sireg1-60x150-0x157Required with S-mode; select range 0..0xFFF minimum
vsiselect + vsireg1-60x250-0x257Required with H; substitute for the s-versions in VS/VU-mode. Width should match siselect (else a detectable virtualization hole)
CommonSelect-value space is SEPARATE from CSR numbers and tselect; MSB set = custom (MSB tracks XLEN changes); widths are CURRENT XLEN, not SXLEN/VSXLEN
Dotted-underlined cells have explanations — click one.

Exception matrix: unimplemented select value → UNSPECIFIED, with illegal-instruction recommended (that’s what makes firmware emulation work). Under H: VS/VU touching vsiselect/vsireg* directly → virtual-instruction; VU touching siselect/sireg* → virtual-instruction; VS touching sireg* transparently operates on vsireg*. And Smstateen’s bit 60 (CSRIND) gates the whole mechanism below M — with hstateen0[60]=0 ∧ mstateen0[60]=1, VS/VU attempts raise virtual-instruction regardless of select values.

Hardware Designer Notes

Implementation is a second-level CSR decode: iselect latches a value, and the six alias addresses index a router table into whatever register files your extensions expose. For the Linux-boot core in this book’s scope (no AIA), the whole chapter is a stub: RO-0 miselect, absent s-set — and one more line in your documented-choices list.

Minimal Linux-boot hart MUST

  • Trap unimplemented select values (the recommended UNSPECIFIED resolution) — emulators depend on it
  • Make select/alias widths follow the CURRENT XLEN
  • Wire the VS substitution and the virtual-instruction cases exactly if you implement H

MAY simplify / trap-and-emulate

  • Ship miselect read-only zero and omit s/vs sets entirely until AIA or counter delegation arrives — Linux without AIA never touches this
  • Implement the router as a small decode table in the CSR unit — no datapath cost

Check yourself — indirect CSR access

1.Why six alias registers (sireg through sireg6) instead of one?

2.Why must siselect support the range 0..0xFFF even on a hart implementing none of those values?

3.VS-mode code reads sireg while the H extension is active. Which register does it actually touch?

3 questions