RHDL includes a RISC-V RV32 implementation featuring two core variants (single-cycle and 5-stage pipeline), a full privilege model, MMIO devices, and the ability to boot both xv6 and Linux.

Quick Start

# Build native backends
bundle exec rake native:build
 
# Run a raw RISC-V binary
rhdl examples riscv path/to/program.bin
 
# Boot xv6
rhdl examples riscv --xv6
 
# Boot Linux
rhdl examples riscv --linux
 
# Native RTL via Verilator
rhdl examples riscv --mode verilog --xv6
 
# Native RTL via CIRCT/MLIR (Arcilator)
rhdl examples riscv --mode circt --xv6

Core Variants

Single-Cycle Core

PC → IFetch → Decode → RegFile → ALU → Mem/MMIO → Writeback

Focused on determinism and debuggability. Default for all modes.

5-Stage Pipeline

StageFunction
IFInstruction fetch + next-PC
IDDecode + register read + immediate generation
EXALU / branch target / compare
MEMLoad/store + MMIO access
WBRegister writeback

Features forwarding for RAW dependencies, stalls for load-use hazards, and flush for taken branches.

rhdl examples riscv --core pipeline --xv6

ISA Support

Base + Extensions

ExtensionInstructions
RV32IFull base integer set (add, sub, loads, stores, branches, jumps)
MMultiply/divide (mul, div, rem families)
A + ZacasAtomic operations (lr.w, sc.w, AMO ops, amocas.w)
C subsetCompressed instructions
F subsetFloat load/store, move (flw, fsw, fmv)
V subsetVector (vsetvli, vmv, vadd)
ZicsrCSR read/write operations
ZifenceiInstruction fence
ZbaAddress generation (sh1add, sh2add, sh3add)
ZbbBasic bit manipulation (andn, orn, min, max)
ZbcCarry-less multiply (clmul, clmulh, clmulr)

Privilege Model

  • Machine and supervisor privilege modes
  • Trap delegation via CSR configuration
  • Sv32 virtual memory with satp and sfence.vma
  • Timer and external interrupts (CLINT + PLIC)

Platform / MMIO

The cores run with a virt-style MMIO layout:

DeviceDescription
CLINTTimer and software interrupt source
PLICExternal interrupt routing
UART16550-compatible console I/O
virtio-blkMMIO disk for filesystem boot

Booting xv6

# Build xv6 artifacts
./examples/riscv/software/build_xv6.sh
 
# Boot
rhdl examples riscv --xv6

Milestones: init: starting sh ~19.3M cycles, shell prompt ~22.5M cycles.

Booting Linux

# Build Linux kernel + BusyBox rootfs
./examples/riscv/software/build_linux.sh
 
# Boot
rhdl examples riscv --linux

The Linux build produces kernel, DTB, and initramfs artifacts. The runner loads them into memory, patches the DTB initrd bounds, and hands off to the kernel entry point.

Simulation Modes

ModeBackendDescription
rubyRuby HDLFull signal visibility
irInterpreter/JIT/CompilerDefault, best balance
verilogVerilatorNative RTL, fastest
circtArcilatorCIRCT/MLIR native RTL
rhdl examples riscv --mode ir --sim compile --xv6
rhdl examples riscv --mode verilog --linux

HDL Structure

BlockDescription
cpu.rbSingle-cycle CPU top
pipeline/cpu.rb5-stage pipeline top
decoder.rbInstruction decode + control
alu.rbInteger ALU (+ extension ops)
imm_gen.rbImmediate generation (I/S/B/U/J)
register_file.rbx0–x31 registers
csr_file.rbCSR / privilege state
memory.rbInstruction/data memory
clint.rb, plic.rbInterrupt controllers
uart.rbConsole I/O
virtio_blk.rbBlock device

Testing

# All RISC-V tests
bundle exec rake spec[riscv]
 
# Extension-specific
bundle exec rspec spec/examples/riscv/rv32c_extension_spec.rb
bundle exec rspec spec/examples/riscv/rv32f_extension_spec.rb
 
# Linux boot milestones
bundle exec rspec spec/examples/riscv/linux_boot_milestones_spec.rb
 
# xv6 boot
bundle exec rspec spec/examples/riscv/xv6_readiness_spec.rb

Next Steps