Skip to content
STIMSMITH

CSR Decoder

Technique WIKI v1 · 9/21/2026

The CSR Decoder is a Bluespec-based demultiplexer-like function within the CSRBox generator pipeline that validates a given RISC-V CSR address against the set of CSRBox-supported addresses and emits a boolean valid signal indicating whether a match was found.

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, the PMPCFG0–PMPCFG15 range, the PMPADDR0–PMPADDR63 range, MCYCLE, MINSTRET, the MHPMCOUNTER3–MHPMCOUNTER31 range, their H (high) counterparts, MCOUTNINHIBIT, and the MHPMEVENT3–MHPMEVENT31 range.
  • User-mode CSRs — USTATUS, UIP, UIE, UTVEC, UEPC, UTVAL, UCAUSE, USCRATCH, CYCLE, INSTRET, and HPMCOUNTER3 and 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

CITATIONS

6 sources
6 citations
[1] The CSR Decoder is a Bluespec-based demultiplexer-like function that checks the validity of a given CSR address against all CSRBox-supported addresses and sets a boolean valid signal accordingly. 2. Overview — RISC-V CSRBox Generator 1.0.2 documentation
[2] The decoder sits in the CSRBox working flow alongside Attribute YAML handling, CSR Defines (auto-generated address macros), and WARL support processing. 2. Overview — RISC-V CSRBox Generator 1.0.2 documentation
[3] Preconditions for each CSR before decoder use include size/subfield MSB check, description, address (consumed by the decoder), and shadow CSR identification. 2. Overview — RISC-V CSRBox Generator 1.0.2 documentation
[4] CSRBox 1.0.1 supports all machine-mode CSRs and the supervisor/user-mode CSRs that depend only on the U extension, defining the address set the decoder matches against. 2. Overview — RISC-V CSRBox Generator 1.0.2 documentation
[5] Any additions to the CSRBox attributes YAML must be done in terms of Bluespec code rather than running commentary, consistent with the decoder's implementation in Bluespec. 2. Overview — RISC-V CSRBox Generator 1.0.2 documentation
[6] Generated Bluespec files (including decoder-related code) are placed in a dedicated subfolder of the work directory and validated via successful Bluesim and Verilog compilation. 2. Overview — RISC-V CSRBox Generator 1.0.2 documentation