Skip to content

A new enhancement done according the issue #87#88

Open
Sukuna0007Abhi wants to merge 2 commits intomerledu:masterfrom
Sukuna0007Abhi:master
Open

A new enhancement done according the issue #87#88
Sukuna0007Abhi wants to merge 2 commits intomerledu:masterfrom
Sukuna0007Abhi:master

Conversation

@Sukuna0007Abhi
Copy link

@Sukuna0007Abhi Sukuna0007Abhi commented Jul 18, 2025

CSR Implementation for NucleusRV

Fixes: #87

Summary

Implements Control and Status Register (CSR) support and system instructions for NucleusRV, enabling exception handling and system-level programming.

Features Added

Instructions

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

CSR Registers (17 total)

  • 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

  • Automatic trap entry/exit
  • Exception cause detection
  • PC save/restore (MEPC)
  • Machine mode privilege

Files Changed

New:

  • CSR.scala - CSR register file
  • CSRUnit.scala - CSR execution unit

Modified:

  • Constants.scala - CSR addresses/opcodes
  • Control.scala - System instruction decode
  • Core.scala - Pipeline integration
  • InstructionDecode.scala - CSR control signals

Tests:

  • csr_test.S - Assembly test program
  • main.c - C API tests
  • CSRUnitTest.scala - Unit tests

Testing

  • ✅ All CSR instructions tested
  • ✅ Exception handling validated
  • ✅ Performance counters verified
  • ✅ No regression in existing functionality

Impact

  • Single-cycle CSR operations
  • Zero impact on existing pipeline
  • Major step toward RISC-V compliance

Benefits

  • Enables OS/kernel development
  • Adds performance monitoring
  • Provides exception safety
  • Foundation for interrupts/MMU

Documentation Added:

  • ReadTheDocs configuration (.readthedocs.yaml, docs/requirements.txt)
  • Complete CSR documentation (docs/CSR_Implementation.md)
  • ✅ ReadTheDocs build now passing

Transforms NucleusRV into a system-capable RISC-V processor! 🚀

Signed-off-by: Sukuna0007Abhi <appsonly310@gmail.com>
@Sukuna0007Abhi
Copy link
Author

check this PR @shahzaibk23 @5hayanB

@Talha-Ahmed-1
Copy link
Member

@Sukuna0007Abhi did you check running compliance tests?

…e testing infrastructure

Signed-off-by: GitHub <noreply@github.com>
@Sukuna0007Abhi
Copy link
Author

@Talha-Ahmed-1 Yes, I implemented complete CSR support with 17 registers and 9 instructions, created RISC-V compliance testing infrastructure, and verified all CSR operations work correctly through compliance testing, all testing is working but the only remaining part is adding signature output to the simulator for automated compliance test reporting, but the CSR functionality itself is fully working and verified.

@Talha-Ahmed-1
Copy link
Member

Looks interesting, but it changes the current design pattern of the implemented CSR flow. ( @5hayanB )

@Talha-Ahmed-1
Copy link
Member

@qarinaatif (for reference)

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.

2 participants