Skip to content

[Feature] Implement CSR Support and System Instructions #87

@Sukuna0007Abhi

Description

@Sukuna0007Abhi

Problem

NucleusRV lacks support for RISC-V Control Status Registers (CSR) and system instructions (ECALL, EBREAK, MRET). This prevents:

  • Exception handling and system calls
  • Performance monitoring
  • Operating system development
  • Full RISC-V compliance

🎯 Proposed Solution

Implement complete CSR system including:

Instructions

  • CSR Instructions: CSRRW, CSRRS, CSRRC + immediate variants
  • System Instructions: ECALL, EBREAK, MRET

CSR Registers

  • Machine Info: MHARTID, MISA, MVENDORID, MARCHID, MIMPID
  • Trap Setup: MSTATUS, MIE, MTVEC
  • Trap Handling: MEPC, MCAUSE, MSCRATCH, MTVAL, MIP
  • Performance: MCYCLE, MINSTRET (64-bit counters)

Exception Handling

  • Trap entry/exit mechanism
  • Privilege mode management (Machine mode)
  • Exception cause detection

Implementation

Files to modify:

  • Add CSR.scala and CSRUnit.scala
  • Extend Control.scala for system instruction decode
  • Update Core.scala for pipeline integration
  • Add CSR constants to Constants.scala

Testing:

  • Unit tests for CSR operations
  • Assembly test programs
  • Exception handling validation

Benefits

  • ✅ Major step toward RISC-V compliance
  • ✅ Enables system software development
  • ✅ Adds performance monitoring capabilities
  • ✅ Foundation for future OS/interrupt support

🤝 Contribution

I can implement this...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions