RISC-V

RISC-V CPU Core in VHDL

Copyright (C) 2025 4137314

This file is part of the RISC-V CPU project.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Overview

This project implements a RISC-V CPU core in VHDL suitable for FPGA prototyping and educational purposes. The design currently supports the RV32I base integer instruction set, with modular architecture that allows easy extension to RV32IM (multiply/divide), pipeline stages, and peripheral interfaces.

Features

Usage

  1. Simulation (GHDL):
    • make hw — compile everything and run the default testbench (tb_riscv_core).
    • make hw TB=tb_alu — run a specific testbench (tb_alu, tb_regfile, …).
    • make wave TB=tb_alu — open the resulting waveform in GTKWave.
  2. Synthesis:
    • make synth-check — fast synthesizability check with ghdl --synth (no Vivado needed).
    • make synth [PART=xc7a35tcpg236-1] [TOP=riscv] — full Vivado batch flow (hw/scripts/synthesis.tcl): synthesis, place & route, bitstream in hw/build/vivado/.
    • Pin/timing constraints live in hw/constraints/board_top.xdc (Basys3 defaults).
  3. Program Loading:
    • The instruction memory is initialized from a hex file (one 32-bit word per line); the default image is sw/program.hex (source in sw/program.S).
    • Compile RISC-V assembly or C programs with a riscv32 toolchain and convert them with objcopy -O verilog --verilog-data-width=4.

Extensions

References