A high-performance RV32I (Base Integer Instruction Set) emulator written in C++ (for educational purposes). This project is designed to simulate a 32-bit RISC-V CPU, providing a sandboxed environment for running bare-metal RISC-V binaries and passing official architectural tests.
The emulator implements the fetch-decode-execute cycle for 32-bit instructions. It features a byte-addressable memory system within a 32-bit address space, supporting Little-Endian data storage.
- ISA: RV32I (Base Integer)
- Registers: 32 general-purpose integer registers (
x0hardwired to 0) - Memory: 32-bit addressable, byte-level access
- ABI: Supports both custom TUI-style syscalls and standard Linux-style
ecallinterfaces. - Load: Supports both binary and elf loading
The emulator is structured into three primary components:
- CPU: Handles the register file, program counter (PC), and the instruction pipeline.
- Memory: A virtualized 4GB address space (sparse or flat implementation) with 8-bit granularity.
- Bus/System: Manages the communication between the CPU and peripherals (like the System call handler).
This emulator is designed to pass the RISC-V Architectural Tests.
- RV32I Base: Passes all standard computational tests (ADD, SUB, SLT, etc.).
- Control Flow: Passes branch and jump (JAL, JALR) compliance.
- CSRs: (Planned) Control and Status Register support.
- C++17 or higher
riscv32-unknown-elf-toolchain
cmake -B build
cmake --build build
cd build
./rv32i {loadtype} {filepath}