cnlohr/mini-rv32ima
FreeA tiny C header-only risc-v emulator.
About cnlohr/mini-rv32ima
mini-rv32ima is a single-file-header RISC-V emulator (rv32ima) written in C, in the STB style. It implements the rv32ima instruction set with Zifencei and Zicsr extensions, partial supervisor mode, CLINT, and MMIO. The core emulator is about 400 lines of code with no dependencies (not even libc), making it trivially embeddable. It is performant, achieving ~450 CoreMark on a laptop (about half the speed of QEMU), and compiles to an ~18kB executable when paired with the included demo wrapper. The demo wrapper adds CLI, SYSCON, UART, DTB, and kernel image loading in about 250 lines of code. Designed to run Linux on RV32-NOMMU systems, it also supports running bare-metal programs and applications like Doom. The emulator is human-readable, extensible, and intentionally incomplete—it omits parts of the RISC-V spec not used by Linux to keep the code small and simple.
Key Features
Pros & Cons
- Extremely small and self-contained (single header, no dependencies)
- Fast enough for practical use (half QEMU speed)
- Easy to understand, modify, and extend due to simple C code
- Cross-platform: runs on Windows, Linux, and can be embedded anywhere
- Free and open source under a permissive license
- Active development with community support
- Incomplete implementation: omits many parts of the RISC-V spec not used by Linux
- Zifencei and RV32A are stubbed, limiting multiprocessor support
- No MMU (Memory Management Unit), so not suitable for full RISC-V environments
- Only supports 32-bit RISC-V (rv32), not rv64
- Not intended for production use; focused on simplicity and educational purposes