Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,7 @@ riscof_work/
.ammonite/
metals.sbt
mem_data/

.docs_venv/
docs/_build/

27 changes: 27 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version, and other tools you might need
build:
os: ubuntu-24.04
tools:
python: "3.11"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt

# Optionally, but recommended,
# declare the Python requirements required to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt

5 changes: 0 additions & 5 deletions docs/01_overview/index.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/02_user/index.rst

This file was deleted.

3 changes: 0 additions & 3 deletions docs/03_dev/images/if_module.svg

This file was deleted.

12 changes: 0 additions & 12 deletions docs/03_dev/index.rst

This file was deleted.

22 changes: 0 additions & 22 deletions docs/03_dev/instruction_fetch.rst

This file was deleted.

3 changes: 1 addition & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Minimal makefile for Sphinx documentation
#

Expand All @@ -7,7 +6,7 @@
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = build
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
Expand Down
51 changes: 51 additions & 0 deletions docs/concepts/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Configuring NucleusRV: Extensions and Core Options
==================================================

NucleusRV is highly configurable via the ``Configs`` case class in Scala/Chisel.

The Configs Case Class
----------------------

.. code-block:: scala

case class Configs(
XLEN : Int = 32,
M : Boolean = true,
F : Boolean = true,
C : Boolean = false,
A : Boolean = true,
Zicsr : Boolean = true,
TRACE : Boolean = true,
HARTID : Int = 1,
ARCHID : Int = 1
)
Comment on lines +11 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Configs example shows incorrect defaults for M, F, and Zicsr.

This snippet should match src/main/scala/components/Configs.scala defaults (false for M, F, Zicsr) to prevent incorrect baseline assumptions.

🛠️ Proposed doc fix
    case class Configs(
      XLEN : Int = 32,
-     M : Boolean = true,
-     F : Boolean = true,
+     M : Boolean = false,
+     F : Boolean = false,
      C : Boolean = false,
      A : Boolean = true,
-     Zicsr : Boolean = true,
+     Zicsr : Boolean = false,
      TRACE : Boolean = true,
      HARTID : Int = 1,
      ARCHID : Int = 1
    )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case class Configs(
XLEN : Int = 32,
M : Boolean = true,
F : Boolean = true,
C : Boolean = false,
A : Boolean = true,
Zicsr : Boolean = true,
TRACE : Boolean = true,
HARTID : Int = 1,
ARCHID : Int = 1
)
case class Configs(
XLEN : Int = 32,
M : Boolean = false,
F : Boolean = false,
C : Boolean = false,
A : Boolean = true,
Zicsr : Boolean = false,
TRACE : Boolean = true,
HARTID : Int = 1,
ARCHID : Int = 1
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/concepts/configuration.rst` around lines 11 - 21, The Configs example in
the docs sets M, F, and Zicsr to true but the canonical defaults in the code are
false; update the Configs case class example so the Boolean fields M, F, and
Zicsr are false to match the implementation in Configs.scala (i.e., change M :
Boolean = true, F : Boolean = true, Zicsr : Boolean = true to M : Boolean =
false, F : Boolean = false, Zicsr : Boolean = false).


Parameter Reference
-------------------

- ``XLEN``: Data width (currently only 32 is supported).
- ``M``: Enable/Disable Integer Multiply/Divide.
- ``F``: Enable/Disable Floating-Point Unit.
- ``C``: Enable/Disable Compressed instruction support.
- ``A``: Enable/Disable Atomic Memory Operations.
- ``Zicsr``: Enable/Disable CSR instructions.
- ``TRACE``: Enable/Disable RVFI tracing (useful for verification).
- ``HARTID``: Hardware Thread ID (drives ``mhartid`` CSR).
- ``ARCHID``: Architecture ID (drives ``marchid`` CSR).

Instantiating with Custom Configuration
--------------------------------------

In your top-level Chisel module, you can instantiate the core with a custom config:

.. code-block:: scala

implicit val config: Configs = Configs(M = true, C = true, TRACE = false)
val core = Module(new Core())

Common Configurations
---------------------

- **Minimal RV32I**: Disable all optional extensions to minimize area.
- **Full RV32IMAFC**: Enable all supported extensions.
- **Synthesis Config**: Disable ``TRACE`` when synthesizing for hardware to save area.
43 changes: 43 additions & 0 deletions docs/concepts/isa-support.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
RISC-V ISA Extensions Supported by NucleusRV
==========================================

NucleusRV implements the RV32IMAFC instruction set.

Supported Extensions
--------------------

- **I (Base Integer)**: Always enabled. Includes ALU, Load/Store, and Branch instructions.
- **M (Integer Multiply/Divide)**: Configurable. Implements multiplication and division.
- **A (Atomic Memory Operations)**: Configurable. Implements Load-Reserved/Store-Conditional and Atomic Memory Operations.
- **F (Single-Precision Floating-Point)**: Configurable. Implements IEEE 754 floating-point instructions.
- **C (Compressed Instructions)**: Configurable. Implements 16-bit compressed instructions to reduce code size.
- **Zicsr (CSR Instructions)**: Configurable. Enables access to Control and Status Registers.

Extension Details
-----------------

M Extension
~~~~~~~~~~~
- Multiplier: Single-cycle multiplication.
- Divider: Multi-cycle (up to 34 cycles) division/remainder unit.

A Extension
~~~~~~~~~~~
- LR.W / SC.W: Implemented using a reservation file.
- AMOs: Two-cycle read-modify-write sequence.

C Extension
~~~~~~~~~~~
- Realigner: Handles misaligned instruction boundaries.
- CompressedDecoder: Expands 16-bit instructions to 32-bit equivalents.

MISA Register
-------------

The ``misa`` register reports the supported extensions based on the core configuration.
The extensions bits are:
- Bit 8 (I): Base Integer.
- Bit 12 (M): Multiplication.
- Bit 0 (A): Atomics.
- Bit 5 (F): Floating-Point.
- Bit 2 (C): Compressed.
36 changes: 36 additions & 0 deletions docs/concepts/memory-interface.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
NucleusRV Memory Interface: Instruction and Data Ports
======================================================

NucleusRV uses separate instruction and data memory ports (Harvard architecture) based on a simple Decoupled request/response protocol.

Bundle Definitions
------------------

The memory interface uses ``MemRequestIO`` and ``MemResponseIO`` bundles wrapped in ``Decoupled`` interfaces.

MemRequestIO Fields
~~~~~~~~~~~~~~~~~~~

- ``addrRequest``: 32-bit byte address.
- ``dataRequest``: 32-bit write data (ignored on reads).
- ``activeByteLane``: 4-bit byte-enable mask.
- ``isWrite``: 1 for write, 0 for read.

MemResponseIO Fields
~~~~~~~~~~~~~~~~~~~~

- ``dataResponse``: 32-bit read data.

Handshake Protocol
------------------

A transaction occurs when both ``valid`` and ``ready`` are asserted on the same clock edge.

- **Request**: Core drives ``valid`` and request fields; Memory drives ``ready``.
- **Response**: Memory drives ``valid`` and ``dataResponse``; Core drives ``ready``.

Timing
------

- **Instruction Port**: Fetches occur every cycle unless stalled or waiting for response.
- **Data Port**: Stores and loads initiate in the EX/MEM stage transition and complete when ``dmemRsp.valid`` is asserted.
26 changes: 26 additions & 0 deletions docs/concepts/pipeline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
NucleusRV 5-Stage Pipeline Architecture
=======================================

NucleusRV uses a classic 5-stage pipeline to achieve balanced throughput and frequency.

Pipeline Stages
---------------

1. **Instruction Fetch (IF)**: Fetches instructions from instruction memory. Includes the PC unit, Realigner, and Compressed Decoder.
2. **Instruction Decode (ID)**: Decodes the instruction, reads the register file, and generates control signals. Includes the Immediate Generator and Hazard Unit.
3. **Execute (EX)**: Performs ALU operations, multiplication, division, and floating-point operations. Handles data forwarding.
4. **Memory (MEM)**: Accesses data memory for load and store instructions. Manages atomic memory operations.
5. **Write-Back (WB)**: Writes results back to the register file.

Hazard Handling
---------------

- **Data Hazards**: Handled via forwarding from EX and MEM stages to the ID stage.
- **Load-Use Hazards**: Handled by stalling the pipeline for one cycle.
- **Control Hazards**: Branches and jumps are resolved in the ID stage, resulting in a 1-cycle penalty for taken branches.
- **Atomic Hazards**: Special handling for read-modify-write sequences in the MEM stage.

Pipeline Registers
------------------

Inter-stage registers are named following the ``<stage>_reg_<signal>`` pattern (e.g., ``if_reg_pc``, ``ex_reg_result``).
24 changes: 8 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
# Configuration file for the Sphinx documentation builder.

# -- Project information

project = 'NucleusRV'
copyright = '2022, Usman Zain'
author = 'Usman Zain'
copyright = '2026, Kinza Fatima'
author = 'Kinza Fatima'

release = '0.1'
version = '0.1.0'

# -- General configuration

extensions = [
'sphinx.ext.duration',
'sphinx.ext.doctest',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
'sphinx_copybutton',
]

intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
}
intersphinx_disabled_domains = ['std']

templates_path = ['_templates']

# -- Options for HTML output
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

html_theme = 'sphinx_rtd_theme'

# -- Options for EPUB output
epub_show_urls = 'footnote'
intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
}
37 changes: 37 additions & 0 deletions docs/guides/arch-tests.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Run RISC-V Architecture Compliance Tests
========================================

Validate NucleusRV against official RISC-V architectural test suites using the ``riscof`` framework.

Setup the Environment
---------------------

1. Create a Python virtual environment:

.. code-block:: bash

python3 -m venv .venv
source .venv/bin/activate

2. Install ``riscof`` and required plugins:

.. code-block:: bash

pip3 install git+https://github.com/riscv/riscof.git
pip3 install -e riscof/riscv-arch-test/riscv-ctg riscof/riscv-arch-test/riscv-isac
Comment on lines +20 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the riscof plugin directories exist
echo "Checking riscof directory structure:"
fd -t d "riscv-ctg|riscv-isac" riscof/ 2>/dev/null || echo "Directories not found"
tree -L 3 riscof/ 2>/dev/null | head -30

Repository: merledu/nucleusrv

Length of output: 437


🏁 Script executed:

#!/bin/bash
# Check riscov-arch-test contents and submodule status
echo "=== Contents of riscof/riscv-arch-test/ ==="
ls -la riscof/riscv-arch-test/ 2>&1 || echo "Directory listing failed"

echo ""
echo "=== Checking for riscv-ctg and riscv-isac ==="
ls -ld riscof/riscv-arch-test/riscv-ctg 2>&1
ls -ld riscof/riscv-arch-test/riscv-isac 2>&1

echo ""
echo "=== Checking .gitmodules ==="
cat .gitmodules 2>&1 || echo "No .gitmodules file"

Repository: merledu/nucleusrv

Length of output: 697


Add submodule initialization to setup instructions.

The pip install command on lines 20-21 references riscof/riscv-arch-test/riscv-ctg and riscof/riscv-arch-test/riscv-isac, but these directories do not exist. The riscof/riscv-arch-test is a git submodule that must be initialized first. Add a step to initialize submodules before the pip install commands:

git submodule update --init --recursive

Alternatively, clarify in the documentation that users must initialize git submodules as part of the setup process.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/guides/arch-tests.rst` around lines 20 - 21, The docs currently run pip
installs referencing riscof/riscv-arch-test paths that live in a git submodule;
add a step to initialize submodules before those pip commands (run git submodule
update --init --recursive) or explicitly state that users must initialize the
riscof submodule first so the riscof/riscv-arch-test/riscv-ctg and riscof-isac
directories exist.


Run the Tests
-------------

Execute the test runner script:

.. code-block:: bash

python3 run_riscv_arch_tests.py

This script invokes ``riscof``, which runs tests on both NucleusRV (the DUT) and Spike (the reference), comparing their memory signatures.

Review Results
--------------

Results are stored in ``riscof/riscof_work/``. View the ``report.html`` file for a detailed pass/fail summary.
32 changes: 32 additions & 0 deletions docs/guides/building-c-programs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Build and Run C Programs on NucleusRV
=====================================

NucleusRV includes a build system to compile C programs for the core.

Create a Test Directory
-----------------------

Create a directory for your C project in ``tools/tests/``:

.. code-block:: bash

mkdir tools/tests/my_test

Add your C source files and a ``main.c``.

Build with Make
---------------

Run ``make`` from the ``tools/`` directory:

.. code-block:: bash

cd tools
make PROGRAM=my_test

This will generate ``out/program.hex``, which you can use for simulation.

Simulate
--------

Generate Verilog using ``NRVDriver`` and run with Verilator as described in the :doc:`../quickstart`.
Loading