CSR Decoder
The CSR Decoder is a processing stage inside the CSRBox RISC-V CSR generator tool. It implements a demultiplexer-style address-validation function written in Bluespec SystemVerilog.
Role in the CSRBox Pipeline
Within CSRBox's working flow, the CSR Decoder sits alongside other internal stages that consume a standardized ISA specification (produced from an ISA YAML passed through riscv-config) and a user-supplied Grouping YAML:
- Attribute YAML handling — automates internal checks for shadow CSRs, dependent CSRs, special-case action methods, and subfields.
- CSR Decoder — validates the supplied CSR address against all CSRBox-supported addresses.
- CSR Defines — automatically generated macros for each CSR, keyed to its address.
- WARL Support — parses WARL strings into condition/legalizing fragments using regular expressions and emits Bluespec code.
Function
The decoder compares a given CSR address with every address supported by CSRBox. The comparison produces a boolean validity signal:
- Match found — the boolean becomes
true, indicating the addressed CSR is supported and downstream CSR flow can proceed. - No match — the boolean becomes
false, indicating an unsupported or unimplemented address.
This is described in CSRBox documentation as a "bluespec demultiplexer like function that checks the validity of the given csr address" whose job is "to compare the given address with all the csrbox supported address. If it is able to match, a bool variable becomes valid, else is turned false."
Input Preconditions
For the decoder to operate, each CSR present in both the Grouping YAML and the standardized ISA specification is first checked for:
- Size of the CSR (or, if subfields exist, the highest MSB value)
- Description of the CSR
- Address of the CSR (consumed by the decoder)
- Shadow CSRs
CSR Set Coverage
The address set against which the decoder matches corresponds to the CSRs supported by CSRBox. In CSRBox 1.0.1, this includes:
- Machine-mode CSRs — e.g.,
MVENDORID,MARCHID,MIMPID,MHARTID,MISA,MTVEC,MEDELEG,MIDELEG,MIE,MCOUNTEREN,MSTATUS,MIP,MSCRATCH,MEPC,MCAUSE,MTVAL, thePMPCFG0–PMPCFG15range, thePMPADDR0–PMPADDR63range,MCYCLE,MINSTRET, theMHPMCOUNTER3–MHPMCOUNTER31range, theirH(high) counterparts,MCOUTNINHIBIT, and theMHPMEVENT3–MHPMEVENT31range. - User-mode CSRs —
USTATUS,UIP,UIE,UTVEC,UEPC,UTVAL,UCAUSE,USCRATCH,CYCLE,INSTRET, andHPMCOUNTER3and beyond.
Supervisor-mode and user-mode CSRs supported are those that depend only on the U extension.
Relation to the CSR Daisy-Chain Flow
After the decoder establishes address validity, the broader CSR flow propagates core requests between CSR groups in a daisy-chain manner: a request is forwarded group-to-group via an ActionValue method and a FIFO until it hits the correct group, at which point a CSR response is recorded. The decoder's boolean validity result gates whether a given group accepts responsibility for the request.
Implementation Language
The CSR Decoder is expressed in Bluespec SystemVerilog. Output Bluespec files produced by CSRBox are placed under a dedicated subfolder of the work directory and are validated through successful Bluesim and Verilog compilation.
See Also
- CSRBox — the generator tool that implements this decoder stage.
- Bluespec SystemVerilog — the HDL in which the decoder is written.