How ucb-bar/riscv-mini works
Project type and purpose
• This is a hardware‐design project (“riscv-mini”), implemented in Chisel (Scala DSL) that generates a simple 3‐stage RISC-V CPU with instruction and data caches.
• It is intended as an educational / intermediate example (RV32I + machine‐level ISA) before moving on to a full rocket-chip implementation.
File structure
• Top level:
• build.sbt, Makefile, build‐scripts (.sh) → build & generate FIRRTL/Verilog & run simulations
• .github/workflows → CI for building, testing, installing toolchains
• src/main/scala → Chisel sources, organized by packages:
• mini: Config, Core, Datapath, Control, ALU, CSR, Cache, Tile, Main
• junctions: bus interface definitions (e.g., NASTI)
• src/main/cc → C++ test harness for Verilator (top.cc, mm.cc/.h)
• custom‐bmark → template for user benchmarks (C/assembly + Makefile)
• src/test/scala → unit and integration tests (ChiselTest/SBT)
• tests/*.hex → RISC-V test binaries for simulation
README for additional insights
• Build flow: make → generates FIRRTL & Verilog (generated-src), make verilator → builds VTile, make run-tests → runs Verilator sims on .hex files
• SBT tests drive Chisel testers for unit/integration tests.
• External dependency: RISC-V toolchain for custom benchmarks.
Main components and their interactions
a. Frontend (Chisel)
• Chisel source files → compiled by sbt → FIRRTL IR → Verilog
b. Backend (Simulation & Verification)
• Verilator + C++ harness (src/main/cc) → VTile simulation binary
• Test input: .hex instruction/data files → loaded into simulated memory
• Waveform dump (VCD) & execution trace logs
c. CPU Tile (Verilog module)
• Pipeline stages: Fetch, Decode, Execute
• Submodules: RegFile, ALU, ImmGen, Control, CSR, Cache (I$, D$)
• Bus interface: handles memory requests via NASTI-like protocol
d. Memory model / testbench
• Simple memory model in mm.cc reading hex files into arrays
• Interfaces to I$ and D$ ports of the Tile
e. Test & CI
• sbt-driven unit/integration tests → ChiselTest
• GitHub workflows orchestrate builds, simulations, and toolchain installs
Architectural patterns & design principles
• 3-stage pipeline (Fetch/Decode/Execute) with clear separation of datapath vs. control
• Module hierarchy reflecting hardware blocks (Tile → Core + Caches → submodules)
• Use of bundle interfaces (junctions.Nasti) for memory access
• Separation between hardware generator (Chisel) and simulation harness (Verilator + C++)
• Extensibility: custom‐bmark directory for user programs
Final advice
• Be comprehensive: capture both the hardware generator path and the simulation/test path.
• Drill into the Tile’s internal structure—separate datapath vs. control vs. memory subsystems.
• Interactions with external files (.hex) and outputs (dump.vcd, logs).