chipsalliance / chipsalliance/rocket-chip

[Bug Report] Illegal CSR access to mtval2 does not raise exception in Rocket

Open
#3,778 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
3.9k
Forks
1.3k
Avg merge
5d 13m
Merged PRs (30d)
1

Description

Description

While performing differential testing against the Spike reference model, I observed a discrepancy in how Rocket handles accesses to unsupported CSRs.

Specifically, executing a CSR instruction targeting mtval2 does not raise an Illegal Instruction exception in Rocket, whereas Spike correctly traps with mcause = 0x2, as required by the RISC-V privileged specification.

This behavior violates the spec requirement that accesses to unimplemented or unsupported CSRs must raise an Illegal Instruction exception.

Environment
  • Core: Rocket
  • ISA: RV64IMCB + Zicsr + Zifencei + Zmmul + Zca/Zba/Zbb/Zbc/Zbs
  • Reference model: Spike
Reproduction Case

Instruction:

csrrs x20, mtval2, x20

No debug-related or advanced trap CSRs are enabled.

Observed Behavior
Implementation Instruction Register Result Exception
Spike csrrs x20, mtval2, x20 x20 = 0xa9944fc2181ddb84 Illegal Instruction (mcause = 0x2)
Rocket csrrs x20, mtval2, x20 x20 = 0xa9944fc2181ddb84 No exception
Expected Behavior

According to the RISC-V Privileged Specification:

  • mtval2 is not part of the base privileged CSRs
  • When a CSR is not implemented or not accessible in the current privilege mode, any CSR instruction accessing it must raise an Illegal Instruction exception

Therefore, Rocket should trap with:

mcause = 0x2 (Illegal Instruction)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by locating Rocket's CSR access and illegal-instruction handling, then reproduce csrrs x20, mtval2, x20 with the stated RV64 configuration. Done means the unsupported mtval2 access traps with mcause = 0x2, matching Spike and the RISC-V privileged specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.