Skip to content

Implement basic CSR infrastructure and Zicsr instruction support#248

Open
Dazhou-20383 wants to merge 5 commits into
mainfrom
Zicsr
Open

Implement basic CSR infrastructure and Zicsr instruction support#248
Dazhou-20383 wants to merge 5 commits into
mainfrom
Zicsr

Conversation

@Dazhou-20383

Copy link
Copy Markdown
Contributor

Add initial Zicsr CSR support

Added:

  • A dedicated CSR register file
  • Support for csrrw, csrrs, and csrrc
  • CSR read-data propagation through the normal pipeline to writeback
  • Build-time gating via UTOSS_RISCV__ZICSR_ENABLED

Design notes:

  • CSRs are implemented separately from the GPR register file.
  • CSR instructions are decoded in the decode stage, where the CSR address and source operands are already available.
  • CSR read data flows through the existing pipeline datapath and is selected during writeback.
  • funct3 is used to distinguish CSR instruction variants.

Future work:

  • Immediate CSR forms (csrrwi, csrrsi, csrrci)
  • Trap and privilege-level handling
  • CSR-specific semantics and access restrictions
  • Dedicated CSR tests

funct3 = instr[14:12];

end
`ifdef UTOSS_RISCV__ZICSR_ENABLED

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for making sure to gate everything on this flag; can you add it to our build-config here:

risc-v/Makefile

Lines 18 to 25 in 2a95e8f

# =============
# Build config
# =============
UTOSS_RISCV_CONFIG ?= RV32I
UTOSS_RISCV_VERILATOR_DEFINES := $(if $(findstring B,$(UTOSS_RISCV_CONFIG)),-DUTOSS_RISCV_ENABLE_B_EXT)
UTOSS_RISCV_RISCOF_VERILATOR_DEFINES := -DUTOSS_PIPELINE_LOGGER

end
default: begin
csr_write_enable = 1'b0;
csr_write_data = data_t'(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directly determine csr_write_enable in decode could potentially cause hazards (update CSRfile too early). Maybe do something like csr_write_enable_D and pass it to the next stage?

`include "src/headers/types.svh"

module CSRFile
( input csr_addr_t addr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need separate read_addr and write_addr, since CSRfile reading and writing can be done in different addr if they are in different stages at the same time

@DanielTaoHuang123 DanielTaoHuang123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need to change csr_write_enable in decode and separate addr in CSRfile. read the comments for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Zicsr extension

3 participants