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/.
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.
PIPELINED generic):
core_single — single-cycle datapath (1 CPI for RV32I ops)core_pipeline — classic 5-stage pipeline (IF/ID/EX/MEM/WB) with
forwarding, load-use hazard stall and branch resolution in EXENABLE_M — full RV32M via a sequential mul/div unit (2-cycle multiply,
~35-cycle restoring divider, spec-compliant div-by-zero/overflow)ENABLE_ZICSR — machine CSRs (mstatus/misa/mie/mip/mtvec/mscratch/mepc/
mcause/mhartid/mcycle(h)/minstret(h)), CSRR* instructions, ECALL/EBREAK/
illegal traps to mtvec, MRET, WFI-as-NOP and machine interrupts
(software, timer, external) with cancel-and-reexecute semantics0x0000_0000 data RAM - 0x0200_0000 CLINT (msip, mtimecmp, mtime)0x1000_0000 UART (8N1 TX+RX, polled status), wired to the board’s
USB-serial bridge in board_top.xdcsw/arch_test/run_arch_tests.sh — plus a self-checking directed suite
(88 tests, sw/gen_tests.py) covering RV32IM, Zicsr, timer/software
interrupt round-trips and UART TX/RX loopback; both cores also verified
to produce identical memory signatures (hw/scripts/ci_compliance.sh)flake.nix + flake.lock): GHDL, GTKWave,
riscv32-none-elf GCC, LaTeX--synth) and Vivado (hw/scripts/synthesis.tcl)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.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/.hw/constraints/board_top.xdc (Basys3 defaults).sw/program.hex (source in sw/program.S).objcopy -O verilog --verilog-data-width=4.