RISC-V Target Guide

The MIRR compiler includes a RISC-V RV32I backend that translates R-SPU programs into RISC-V assembly suitable for soft-core FPGA implementations.

Overview

The RISC-V backend maps R-SPU instructions to RV32I assembly with:

  • Memory-mapped I/O at 0x1000_0000
  • Shift register emulation via data memory
  • Counter emulation via decrement-and-compare
  • Guard combination via AND/OR logic

Register Mapping

R-SPU RegisterRISC-V RegisterPurpose
R0–R63x0–x63Input ports
R64–R127x64–x127Output ports
R128–R191x128–x191Internal signals
R192–R255x192–x255Expression temporaries

Memory-Mapped I/O

AddressPurpose
0x1000_0000Input port 0
0x1000_0004Input port 1
0x1000_0008Output port 0
......

Compilation

# Compile MIRR to RISC-V assembly
cargo run --bin mirr-compile -- --emit rspu examples/neonatal_respirator.mirr

# The RISC-V backend is invoked automatically when targeting R-SPU

Instruction Mapping

R-SPU InstructionRISC-V Instruction
LOAD_INPUTlw from MMIO
STORE_OUTPUTsw to MMIO
MOVaddi rd, rs, 0
LOAD_IMMli rd, imm
ALU ADDadd rd, rs1, rs2
ALU SUBsub rd, rs1, rs2
ALU ANDand rd, rs1, rs2
ALU ORor rd, rs1, rs2
SR_INITla + sw loop
SR_TICKShift loop
CTR_INITla + li + sw
CTR_TICKlw + addi + sw
REFLEX_IFbeq conditional branch
HALTecall with a7=0

Example

# Compile neonatal respirator to RISC-V
cargo run --bin mirr-compile -- --emit rspu examples/neonatal_respirator.mirr

# Output includes .text and .data sections
# .text contains the main program
# .data contains signal storage and shift register buffers

See Also