How ultraembedded/biriscv works
Purpose and integration surface
biRISC-V is synthesizable Verilog-2001 RTL for a configurable RV32IMZicsr dual-issue, in-order CPU. It supports user/supervisor/machine privilege, basic MMU operation, branch prediction, cache-backed AXI memory, or tightly coupled memory (TCM) integration. Primary system entry points are src/top/riscv_top.v (AXI/cache-oriented wrapper) and src/top/riscv_tcm_top.v (TCM-oriented wrapper).
Core composition
src/core/riscv_core.v composes the CPU datapath and exposes instruction/data memory-side interfaces. Shared architectural definitions and configurability live in src/core/biriscv_defs.v. The design is parameterized for dual issue, privilege/MMU, multiply/divide, bypass paths, decode depth, predictor resources, and cacheable address range.
Frontend, prediction, and fetch
src/core/biriscv_frontend.v manages PC-facing frontend behavior; src/core/biriscv_fetch.v performs 64-bit instruction fetch and instruction stream handling; src/core/biriscv_npc.v calculates next-PC behavior. This boundary consumes instruction memory responses and produces fetched instructions plus predicted control flow. Branch-target/history/return prediction is implemented within the frontend path and is configurable through core parameters.
Decode, dependency control, and issue
src/core/biriscv_decoder.v and src/core/biriscv_decode.v translate fetched RV32 instructions into execution controls and operand requirements. src/core/biriscv_issue.v selects up to two independent instructions per cycle for the in-order pipeline. src/core/biriscv_pipe_ctrl.v coordinates stalls, flushes, hazards, forwarding, and redirect recovery, forming the central control boundary between speculative frontend state and committed execution progress.
Execution and architectural state
src/core/biriscv_exec.v drives execution lanes, with arithmetic and branch operations in src/core/biriscv_alu.v; multiply and out-of-pipeline divide use src/core/biriscv_multiplier.v and src/core/biriscv_divider.v. Integer register state is held by src/core/biriscv_regfile.v (with FPGA-oriented alternative src/core/biriscv_xilinx_2r1w.v). CSR and privilege state are handled by src/core/biriscv_csr.v and src/core/biriscv_csr_regfile.v.
Load/store, translation, and memory boundary
src/core/biriscv_lsu.v serializes the single load/store execution resource and interfaces data accesses to the memory subsystem. src/core/biriscv_mmu.v provides the basic translation/privilege-aware memory path needed for Linux-capable configurations. The memory boundary distinguishes cacheable ranges from direct or tightly coupled accesses according to core/top-level parameters.
Cache and TCM subsystem options
The instruction cache is rooted at src/icache/icache.v, with separate tag/data RAM modules. The data-cache hierarchy begins at src/dcache/dcache.v; src/dcache/dcache_axi.v bridges cached data traffic toward AXI, while src/dcache/dcache_mux.v routes cache and non-cache paths. TCM deployments use src/tcm/tcm_mem.v and src/tcm/dport_axi.v, providing local memory and AXI-facing access routing.
Verification runtimes
A lightweight Icarus RTL bench enters through tb/tb_core_icarus/tb_top.v. Full-system wrapper simulations are supported by C++/SystemC-style harnesses around src/top/riscv_top.v and src/top/riscv_tcm_top.v, respectively under tb/tb_top/ and tb/tb_tcm/; these load ELF images and model AXI or memory behavior. The project also cites RISCV-DV random instruction generation and external ExactStep ISA-model cosimulation as verification infrastructure.
Main entry points: biriscv_exec.v Execution lanes · biriscv_frontend.v Frontend & prediction · riscv_core.v CPU datapath · riscv_top.v AXI/cache top
Components 22
CPU core
Dual-issue in-order RV32IMZicsr pipeline.
- Core definitions · Architecture features and memory-range configuration.
src/core/biriscv_defs.v - CPU datapath · Exposes instruction and data memory-side interfaces.
src/core/riscv_core.v - Frontend & prediction · PC control, prediction, and instruction-stream handling.
src/core/biriscv_frontend.v - Instruction fetch · Fetches and assembles 64-bit instruction data.
src/core/biriscv_fetch.v - Next-PC
src/core/biriscv_npc.v - Decode · Instruction decoding and operand requirements.
src/core/biriscv_decode.v - Dual issue · Selects up to two independent instructions per cycle.
src/core/biriscv_issue.v - Pipeline control · Stalls, flushes, forwarding, hazards, and redirects.
src/core/biriscv_pipe_ctrl.v - Execution lanes
src/core/biriscv_exec.v - ALU & branches
src/core/biriscv_alu.v - Multiply/divide · Multiply is pipelined; divide operates out of pipeline.
src/core/biriscv_multiplier.v - Integer registers
src/core/biriscv_regfile.v - CSR & privilege
src/core/biriscv_csr.v - Load/store unit · Serializes the single load/store resource.
src/core/biriscv_lsu.v - MMU · Privilege-aware translation for Linux-capable configurations.
src/core/biriscv_mmu.v
Memory integrations
Selectable cache/AXI or TCM memory systems.
- AXI/cache top
src/top/riscv_top.v - TCM top
src/top/riscv_tcm_top.v - Instruction cache
src/icache/icache.v - Data cache hierarchy · Caches data and routes cacheable versus direct traffic.
src/dcache/dcache.v - TCM memory · Local tightly coupled memory with AXI-facing routing.
src/tcm/tcm_mem.v
Verification
RTL and full-system simulation entry points.
- Icarus RTL bench
tb/tb_core_icarus/tb_top.v - Full-system harnesses · Loads ELF images and models AXI or memory behavior.
Connections 25
- AXI/cache top → CPU datapath: instantiates
- TCM top → CPU datapath: instantiates
- Core definitions → CPU datapath: configures
- CPU datapath → Frontend & prediction: instruction path
- Frontend & prediction → Instruction fetch: fetch control
- Frontend & prediction → Next-PC: next-PC prediction
- Instruction fetch → Decode: fetched instructions
- Decode → Dual issue: decoded operations
- Dual issue → Execution lanes: up to two issued ops
- Pipeline control → Frontend & prediction: flush and redirect
- Pipeline control → Dual issue: stall and hazard control
- Execution lanes → ALU & branches: arithmetic and branches
- Execution lanes → Multiply/divide: M-extension operations
- Execution lanes → Integer registers: reads and writes
- Execution lanes → CSR & privilege: CSR operations
- Execution lanes → Load/store unit: load/store operations
- Load/store unit → MMU: translated data accesses
- Frontend & prediction → Instruction cache: instruction memory requests
- MMU → Data cache hierarchy: cache/direct data path
- AXI/cache top → Instruction cache: cache integration
- AXI/cache top → Data cache hierarchy: AXI data integration
- TCM top → TCM memory: local memory integration
- Icarus RTL bench → CPU datapath: simulates
- Full-system harnesses → AXI/cache top: simulates
- Full-system harnesses → TCM top: simulates