# ultraembedded/core_uriscv architecture

> Architecture diagram of the GitHub repository ultraembedded/core_uriscv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ultraembedded/core_uriscv
- Repository: https://github.com/ultraembedded/core_uriscv

## Overview

##### Main Components
a. CPU Core:
- Main module (riscv_core.v) as the central processing element.
- Inside the core, indicate the presence of functional units such as:
– ALU (uriscv_alu.v): for arithmetic and logic operations.
– Branch Unit (uriscv_branch.v): for conditional control flow.
– Control & Status Register unit (uriscv_csr.v): for CSR, interruptions, traps, etc.
– Load/Store Unit (uriscv_lsu.v): managing memory accesses.
– Multiplication/Division unit (uriscv_muldiv.v): which handles multi-cycle operations like multiplication and division.
– Definitions and constants (uriscv_defs.v) which support parameterization.
b. Test Bench Environment:
- A separate block for the test bench (located in tb/tb_core_icarus). This includes:
– The top-level test bench module (tb_top.v) that instantiates the CPU and provides the simulation environment.
– Memory models (tcm_mem.v, tcm_mem_ram.v) representing beyond-the-core memory for instruction and data handling.
– The simulation test image (test.elf) used for verifying correct operation.
c. External Dependencies:
- While not an external service in a typical software stack, note that the design is “FPGA friendly” and synthesizable with Verilator, suggesting the intended usage with FPGA tools and simulation vendors.

##### Establish Relationships and Data Flows
– The main riscv_core should send instruction decoding signals to the ALU, branch logic, and other units.
– Data flows between the LSU and the core’s register file (not explicitly depicted but implied as part of the execution).
– The CSR unit interacts with control logic for handling exceptions, interrupts, and system status.
- Communication between the CPU core and external memory units (as modeled by tcm_mem and associated RAM modules in the test bench).
- Incorporate simulation inputs (clock, reset) that drive both the CPU core and the test bench environment.

##### Architectural and Design Principles
- That this is a multi-cycle design (most instructions take 2 cycles while load/stores and division take more cycles). Emphasize the sequential step-by-step control path.
- Configurable nature of features (multiplication, division, CSR, etc.) as described in the README configuration table.
- That the CPU implements a subset of the RISC-V ISA with support for privileged modes (machine mode only).

## Diagram (Mermaid)

```mermaid
graph TD
    %% CPU Core Subgraph
    subgraph "CPU Core"
        core["riscv_core (CPU Core)"]:::coreUnit
        alu["ALU (uriscv_alu)"]:::coreUnit
        branch["Branch Unit (uriscv_branch)"]:::coreUnit
        csr["CSR Unit (uriscv_csr)"]:::coreUnit
        lsu["LSU (uriscv_lsu)"]:::coreUnit
        muldiv["MulDiv Unit (uriscv_muldiv)"]:::coreUnit
        defs["Defs & Constants (uriscv_defs)"]:::supportUnit
    end

    %% Test Bench Environment Subgraph
    subgraph "Test Bench Environment"
        tb["Test Bench Top (tb_top)"]:::testEnv
        mem1["Memory Model (tcm_mem)"]:::memory
        mem2["Memory RAM (tcm_mem_ram)"]:::memory
        sim["Simulation Test Image (test.elf)"]:::simImage
    end

    %% Connections inside CPU Core
    core -->|"instruction_flow"| alu
    core -->|"branch_decisions"| branch
    core -->|"csr_control"| csr
    core -->|"memory_access_signals"| lsu
    core -->|"muldiv_ops"| muldiv
    core -->|"uses_defines"| defs

    %% Connections between Test Bench and CPU Core
    tb -->|"clock_reset"| core

    %% Connections for Memory interactions
    lsu -->|"memory_RW"| mem1
    lsu -->|"memory_RW"| mem2
    tb -->|"drives_memory"| mem1
    tb -->|"drives_memory"| mem2
    sim -->|"loaded_into"| mem1

    %% Click Events
    click core "https://github.com/ultraembedded/core_uriscv/blob/main/src_v/riscv_core.v"
    click alu "https://github.com/ultraembedded/core_uriscv/blob/main/src_v/uriscv_alu.v"
    click branch "https://github.com/ultraembedded/core_uriscv/blob/main/src_v/uriscv_branch.v"
    click csr "https://github.com/ultraembedded/core_uriscv/blob/main/src_v/uriscv_csr.v"
    click lsu "https://github.com/ultraembedded/core_uriscv/blob/main/src_v/uriscv_lsu.v"
    click muldiv "https://github.com/ultraembedded/core_uriscv/blob/main/src_v/uriscv_muldiv.v"
    click defs "https://github.com/ultraembedded/core_uriscv/blob/main/src_v/uriscv_defs.v"
    click tb "https://github.com/ultraembedded/core_uriscv/blob/main/tb/tb_core_icarus/tb_top.v"
    click mem1 "https://github.com/ultraembedded/core_uriscv/blob/main/tb/tb_core_icarus/tcm_mem.v"
    click mem2 "https://github.com/ultraembedded/core_uriscv/blob/main/tb/tb_core_icarus/tcm_mem_ram.v"
    click sim "https://github.com/ultraembedded/core_uriscv/blob/main/tb/tb_core_icarus/test.elf"

    %% Styles
    classDef coreUnit fill:#a8dadc,stroke:#457b9d,stroke-width:2px;
    classDef supportUnit fill:#f1faee,stroke:#e63946,stroke-width:2px;
    classDef testEnv fill:#e9c46a,stroke:#264653,stroke-width:2px;
    classDef memory fill:#ffb703,stroke:#d62828,stroke-width:2px;
    classDef simImage fill:#d8f3dc,stroke:#52b788,stroke-width:2px;
```
