Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VERILATOR ?= verilator
BUILD_DIR ?= build

CPU_RTL = hw/rtl/cpu/alu.sv hw/rtl/cpu/regfile.sv hw/rtl/cpu/rvc_decompress.sv hw/rtl/cpu/cpu_core.sv
BUS_RTL = hw/rtl/bus/wb_error_slave.sv hw/rtl/bus/wb_address_decoder.sv hw/rtl/bus/wb_arbiter.sv hw/rtl/bus/wb_interconnect.sv hw/rtl/bus/wb_cpu_adapter.sv
PERIPHERAL_RTL = hw/rtl/peripherals/wb_uart.sv hw/rtl/peripherals/wb_gpio.sv hw/rtl/peripherals/wb_spi.sv hw/rtl/peripherals/wb_i2c.sv hw/rtl/peripherals/wb_timer.sv hw/rtl/peripherals/wb_watchdog.sv hw/rtl/peripherals/interrupt_controller.sv hw/rtl/peripherals/wb_debug_perf.sv hw/rtl/peripherals/wb_power_ctrl.sv hw/rtl/peripherals/peripheral_subsystem.sv

.PHONY: all sim lint synth test-cocotb clean

Expand All @@ -20,10 +22,24 @@ sim: | $(BUILD_DIR)
$(VVP) $(BUILD_DIR)/cpu_tb
$(IVERILOG) -g2012 -Wall -s cpu_tb -o $(BUILD_DIR)/cpu_hex_tb $(CPU_RTL) hw/tb/cpu_tb.sv
$(VVP) $(BUILD_DIR)/cpu_hex_tb
$(IVERILOG) -g2012 -Wall -s wb_interconnect_tb -o $(BUILD_DIR)/wb_interconnect_tb $(BUS_RTL) hw/tb/wb_interconnect_tb.sv
$(VVP) $(BUILD_DIR)/wb_interconnect_tb
$(IVERILOG) -g2012 -Wall -s wb_cpu_adapter_tb -o $(BUILD_DIR)/wb_cpu_adapter_tb $(BUS_RTL) hw/tb/wb_cpu_adapter_tb.sv
$(VVP) $(BUILD_DIR)/wb_cpu_adapter_tb
$(IVERILOG) -g2012 -Wall -s memory_subsystem_tb -o $(BUILD_DIR)/memory_subsystem_tb $(CPU_RTL) hw/rtl/bus/wb_cpu_adapter.sv hw/rtl/memory/wb_sram.sv hw/rtl/memory/boot_rom.sv hw/rtl/memory/memory_subsystem.sv hw/tb/memory_subsystem_tb.sv
$(VVP) $(BUILD_DIR)/memory_subsystem_tb
$(IVERILOG) -g2012 -Wall -s peripheral_subsystem_tb -o $(BUILD_DIR)/peripheral_subsystem_tb $(PERIPHERAL_RTL) hw/tb/peripheral_subsystem_tb.sv
$(VVP) $(BUILD_DIR)/peripheral_subsystem_tb
$(IVERILOG) -g2012 -Wall -s peripheral_cpu_irq_tb -o $(BUILD_DIR)/peripheral_cpu_irq_tb $(CPU_RTL) hw/rtl/bus/wb_cpu_adapter.sv hw/rtl/memory/wb_sram.sv hw/rtl/memory/boot_rom.sv hw/rtl/memory/memory_subsystem.sv $(PERIPHERAL_RTL) hw/tb/peripheral_cpu_irq_tb.sv
$(VVP) $(BUILD_DIR)/peripheral_cpu_irq_tb

lint:
$(VERILATOR) --lint-only --Wall -Wno-fatal --top-module counter hw/rtl/counter.sv
$(VERILATOR) --lint-only --Wall -Wno-fatal --top-module cpu_core $(CPU_RTL)
$(VERILATOR) --lint-only --Wall -Wno-fatal --top-module wb_interconnect $(BUS_RTL)
$(VERILATOR) --lint-only --Wall -Wno-fatal --top-module wb_cpu_adapter $(BUS_RTL)
$(VERILATOR) --lint-only --Wall -Wno-fatal --top-module memory_subsystem hw/rtl/memory/wb_sram.sv hw/rtl/memory/boot_rom.sv hw/rtl/memory/memory_subsystem.sv
$(VERILATOR) --lint-only --Wall -Wno-fatal --top-module peripheral_subsystem $(PERIPHERAL_RTL)

synth: | $(BUILD_DIR)
$(YOSYS) -s scripts/synth.ys
Expand Down
6 changes: 3 additions & 3 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Status and design decisions

This document describes the target SoC architecture. The Phase 02 RV32I core and counter are implemented; the remaining diagram blocks are architectural targets and must not be inferred as implemented. Decisions marked **provisional** need review before their implementation phases.
This document describes the target SoC architecture. The CPU, counter, Wishbone fabric, Phase 05 behavioral memory, and initial Phase 06 UART/GPIO/SPI/I2C/timer/watchdog/interrupt/debug/performance/power-request collection are implemented. Other diagram blocks remain architectural targets and must not be inferred as implemented. Decisions marked **provisional** need review before their implementation phases.

## Block diagram

Expand All @@ -18,7 +18,7 @@ This document describes the target SoC architecture. The Phase 02 RV32I core and
debug, counters, power control
```

The diagram indicates intended connectivity only. The final master topology and whether DMA has two independent masters or one shared master are review decisions.
The diagram indicates intended connectivity except for implemented blocks documented in the corresponding subsystem specifications. The final master topology and whether DMA has two independent masters or one shared master are review decisions.

## CPU

Expand All @@ -31,7 +31,7 @@ The diagram indicates intended connectivity only. The final master topology and

**Provisional recommendation:** Wishbone B4 Classic, 32-bit address/data, byte selects, one outstanding transfer per granted master. A central decoder maps one selected target per transfer. CPU and DMA access are arbitrated; fairness and maximum wait are specified in the bus contract. The firewall checks DMA address, direction, and transfer size before target selection. PMP checks CPU accesses; bus firewall rules do not replace PMP.

Targets are boot ROM, SRAM, security control/crypto, AI accelerator, and peripheral register banks. ROM and SRAM may be integrated into a shared target or separate targets, but each must preserve the memory map and fault behavior.
Targets are boot ROM, SRAM, security control/crypto, AI accelerator, and peripheral register banks. The current [peripheral subsystem](PERIPHERAL_SUBSYSTEM.md) implements UART, GPIO, SPI/I2C masters, machine timer, interrupt controller, watchdog, performance observation counters, and software clock/power requests at their specified Wishbone pages. External debug halt/step, physical clock gating, and other peripheral targets remain future work. ROM and SRAM may be integrated into a shared target or separate targets, but each must preserve the memory map and fault behavior.

## Memory and protection

Expand Down
18 changes: 11 additions & 7 deletions docs/BUS_SPECIFICATION.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# Wishbone-B4 Bus Specification

This is the proposed SoC interface contract. No Wishbone interface exists in the current RTL.
This specification defines the implemented Phase 04 subsystem. The RTL implements the classic, single-outstanding subset described below. It does not implement pipelined B4 (`CTI`/`BTE`) or `RTY`.

## Selected profile

**Provisional:** Wishbone B4 Classic, synchronous, single 32-bit address and 32-bit data path, byte addressing, little-endian lane order, and at most one outstanding transfer per master. `CYC`, `STB`, `WE`, `ADR`, `DAT`, and `SEL` are used; `ACK`, `ERR`, and optionally `RTY` are slave responses. `CTI`/`BTE` and pipelined multiple outstanding transfers are not used in the initial profile. Whether retry is supported remains a decision; the recommended initial contract is no `RTY` and bounded `ACK` or `ERR`.
**Implemented:** Wishbone B4 Classic, synchronous, 32-bit byte address and data, little-endian lanes, one global outstanding transfer. Signals are `CYC`, `STB`, `WE`, `ADR`, `DAT_W`, and `SEL` from master; slave returns `DAT_R`, `ACK`, or `ERR`. `CTI`, `BTE`, and `RTY` are absent.

## Transfer rules

- A master presents stable address, direction, select, and write data while a request is active. `CYC` and `STB` remain asserted until termination.
- Exactly one of `ACK` or `ERR` terminates a transfer. They must never be asserted together. A slave must not produce a response without a selected request.
- `SEL[n]` selects byte lane `n`; `SEL=0000` is invalid and returns `ERR`. Byte lane 0 corresponds to the least-significant byte at the lowest address.
- On a successful write, only selected byte lanes change. A read returns the 32-bit aligned word; CPU load extraction/sign extension is performed by the CPU or its data path.
- A transfer may not be silently split by a slave. Any supported unaligned access policy must be handled above the slave and documented. The initial recommendation is to return an access error for unsupported unaligned word transfers.
- Address decode selects no more than one slave. Unmapped and prohibited transactions return `ERR` within a bounded number of clocks.
- All accesses are 32-bit words; `ADR[1:0]` are preserved for target decode but CPU adapter aligns data addresses to word boundaries. CPU byte lanes are carried in `SEL`; lane 0 is the least-significant byte. `SEL=0` returns `ERR`.
- The CPU adapter holds its request fields until termination, sends `SEL=1111` for reads, preserves write byte strobes, and maps Wishbone `ERR` to the CPU ready/error response.
- Address decode selects exactly one of ROM (`0x0000_0000`–`0x0000_0FFF`), SRAM (`0x1000_0000`–`0x1000_7FFF`) or peripheral window (`0x4000_0000`–`0x4000_FFFF`). Other addresses return `ERR`. The Phase 06 `peripheral_subsystem` refines its window to implemented UART, GPIO, timer, interrupt-controller, and watchdog pages; unimplemented pages return `ERR`.
- The arbiter is round-robin between CPU master 0 and DMA master 1. Only one master is forwarded at once. Grant persists until termination, master withdrawal, reset, or timeout. A response is delivered only to the owner. After completion, priority rotates to the other master.
- Default timeout is 16 clocks from grant. If no `ACK`/`ERR` arrives, the owner receives a one-cycle `ERR`; the target request is withdrawn. Reset asynchronously clears arbitration state and error response state, aborting the transaction without a late acknowledgement.
- The unmapped/invalid-select error target returns `ERR` on the cycle after request recognition. `ACK` and `ERR` are mutually exclusive. No response is valid without a request owned by the arbiter.
- Reset aborts in-flight requests and clears response outputs. Masters restart only after reset release. No stale `ACK` may terminate a post-reset request.

## Arbitration and protection

CPU and DMA requests are arbitrated. The proposed arbiter is round-robin with bounded service when all requests target responsive slaves. Locking/atomic bus cycles are out of scope while the A extension is excluded. CPU accesses are checked by PMP. DMA accesses are checked by a firewall using programmed allowed ranges and read/write permissions; default policy is deny until configured.
CPU and DMA requests are arbitrated round-robin. Locking/atomic bus cycles are out of scope while the A extension is excluded. PMP and the DMA firewall are not yet connected to this interconnect.

## CDC and timing

All initial bus participants share a synchronous clock. A future asynchronous peripheral domain must cross through a reviewed CDC bridge; direct unsynchronized Wishbone signals are prohibited. Response latency and timeout thresholds must be parameters with a documented default before integration.

## Verification requirements
## Verification and formal properties

Check stable request fields under stall, one-hot decode, no response without request, mutually exclusive termination, reset abort, byte select behavior, unmapped error, protection denial, and bounded completion. Add assertions for these protocol properties and randomized backpressure tests before bus integration is accepted.
The bus testbench checks single-master transfers, simultaneous requests, contention, delayed/backpressured targets, byte enables, decode boundaries, unmapped and empty-select errors, reset abort, ordering, and timeout. `FORMAL` assertions in arbiter/adapter/interconnect check owner routing, stable stalled fields, one-hot target selection, and termination exclusivity. These assertions have not yet been run in a formal engine. The current testbench uses independent target state machines and independent master drivers; additional randomized seeds and formal proof remain future verification work.
2 changes: 1 addition & 1 deletion docs/IMPLEMENTATION_ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Phases are gated in order. A specification entry is not an implementation claim.
| 03 — CPU verification closure | Reference-model and instruction-family verification, assertions and coverage | Required supported-profile tests pass; unsupported encodings trap; coverage gaps documented and accepted |
| 04 — Bus and memory | Wishbone fabric, arbitration, ROM, 32 KiB SRAM controller, timeout/error behavior | Protocol assertions, contention/backpressure, address boundary, ROM-write and unmapped-error tests pass |
| 05 — Protection and interrupts | PMP, DMA firewall, interrupt/timer controller, watchdog | Access-control properties and negative tests pass; reset/interrupt behavior reviewed |
| 06 — Peripherals and debug | UART, GPIO, SPI, I2C, debug/performance counters, clock/power control | Register-level tests, interrupt tests, lint/synthesis and clock/reset review pass |
| 06 — Peripherals and debug | UART, GPIO, SPI, I2C, debug/performance counters, clock/power control | Initial register blocks and CPU-level integration tests pass. Lint/synthesis and physical clock/reset review remain build-flow/integration gates; physical gating and halt/step transport are explicitly outside the initial register-block scope. |
| 07 — Security subsystem | AES-128, SHA-256, TRNG interface, key vault, secure boot policy | Known-answer and negative tests, lifecycle tests, threat review; no security claims beyond evidence |
| 08 — AI and DMA | INT8/INT4 accelerator and two DMA channels | Arithmetic corner cases, overflow/saturation, alignment, firewall and concurrency tests pass |
| 09 — SoC integration | Integrate verified modules, firmware, TinyML runtime, boot image | End-to-end simulation and software tests reproducible; all address/interrupt/reset contracts consistent |
Expand Down
30 changes: 15 additions & 15 deletions docs/MEMORY_MAP.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# SEAL-RV 2.0 Memory Map

All addresses are byte addresses. Windows below are proposed and reserved for the architecture; they are not implemented in the current repository. The interconnect must reject accesses outside a target's implemented registers and must not mirror addresses unless a later revision explicitly defines aliases.
All addresses are byte addresses. Boot ROM and main SRAM are implemented by Phase 05. UART, GPIO, SPI, I2C, machine timer, external interrupt controller, watchdog, debug/performance counters, and power/clock requests are implemented by the Phase 06 peripheral subsystem. Other peripheral windows remain reserved and return an error. The interconnect must reject accesses outside a target's implemented range and must not mirror addresses unless a later revision explicitly defines aliases.

| Region | Base | Limit (inclusive) | Size | Access and purpose |
|---|---:|---:|---:|---|
| Boot ROM | `0x0000_0000` | `0x0000_0FFF` | 4 KiB | Read-only instruction/data; reset entry |
| Main SRAM | `0x1000_0000` | `0x1000_7FFF` | 32 KiB | Read/write, SECDED-protected logical data |
| UART | `0x4000_0000` | `0x4000_0FFF` | 4 KiB window | Serial port registers |
| GPIO | `0x4000_1000` | `0x4000_1FFF` | 4 KiB window | GPIO control/data |
| SPI | `0x4000_2000` | `0x4000_2FFF` | 4 KiB window | SPI controller |
| I2C | `0x4000_3000` | `0x4000_3FFF` | 4 KiB window | I2C controller |
| Machine timer | `0x4000_4000` | `0x4000_4FFF` | 4 KiB window | `mtime`, `mtimecmp`, software interrupt |
| External interrupt controller | `0x4000_5000` | `0x4000_5FFF` | 4 KiB window | Pending, enable, priority, claim/complete |
| Boot ROM | `0x0000_0000` | `0x0000_0FFF` | 4 KiB | Read-only instruction/data; reset entry; one-cycle Wishbone read |
| Main SRAM | `0x1000_0000` | `0x1000_7FFF` | 32 KiB | Read/write behavioral SRAM; one-cycle Wishbone response; byte writes |
| UART | `0x4000_0000` | `0x4000_0FFF` | 4 KiB window | 8-N-1 serial; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| GPIO | `0x4000_1000` | `0x4000_1FFF` | 4 KiB window | Synchronized GPIO and IRQ; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| SPI | `0x4000_2000` | `0x4000_2FFF` | 4 KiB window | SPI master; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| I2C | `0x4000_3000` | `0x4000_3FFF` | 4 KiB window | Single-controller open-drain master; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| Machine timer | `0x4000_4000` | `0x4000_4FFF` | 4 KiB window | 64-bit `mtime`, `mtimecmp`, MTIP; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| External interrupt controller | `0x4000_5000` | `0x4000_5FFF` | 4 KiB window | UART/GPIO/watchdog pending, masks, priorities, claim/complete; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| DMA | `0x4000_6000` | `0x4000_6FFF` | 4 KiB window | Two channel control/status banks |
| AES/SHA engines | `0x4000_7000` | `0x4000_7FFF` | 4 KiB window | Crypto command/status/data |
| Key vault | `0x4000_8000` | `0x4000_8FFF` | 4 KiB window | Restricted key lifecycle/control |
| AI accelerator | `0x4000_9000` | `0x4000_9FFF` | 4 KiB window | INT8/INT4 command/status/data |
| Debug/performance | `0x4000_A000` | `0x4000_AFFF` | 4 KiB window | Debug and counters |
| Power management | `0x4000_B000` | `0x4000_BFFF` | 4 KiB window | Clock enables, sleep, wake status |
| Debug/performance | `0x4000_A000` | `0x4000_AFFF` | 4 KiB window | Cycle, retire, bus, IRQ counters and last PC; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| Power management | `0x4000_B000` | `0x4000_BFFF` | 4 KiB window | Clock requests, sleep/wake status, software reset; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| TRNG interface | `0x4000_C000` | `0x4000_CFFF` | 4 KiB window | Entropy data/status/health |
| Watchdog | `0x4000_D000` | `0x4000_DFFF` | 4 KiB window | Watchdog control/status |
| Watchdog | `0x4000_D000` | `0x4000_DFFF` | 4 KiB window | Programmable reset watchdog; see [peripheral register map](PERIPHERAL_SUBSYSTEM.md) |
| PMP/firewall control | `0x4000_E000` | `0x4000_EFFF` | 4 KiB window | Locked policy configuration/status |

## Access rules

- Register windows use aligned 32-bit registers at offsets documented by each peripheral specification. The initial bus supports byte enables; each register must define whether partial writes are accepted, merged, or rejected.
- Register windows use aligned 32-bit registers at offsets documented by each peripheral specification. The initial bus supports byte enables; partial-write behavior is defined in [PERIPHERAL_SUBSYSTEM.md](PERIPHERAL_SUBSYSTEM.md).
- Boot ROM writes return an error. SRAM accesses outside the 32 KiB range return an error. Unmapped addresses return an error and set an observable fault cause.
- Execute permission is denied for MMIO by default. ROM and SRAM execute permissions are governed by CPU privilege/PMP policy.
- DMA may access SRAM and explicitly permitted memory windows only. DMA access to ROM, key-vault state, debug controls, or protected peripheral registers is denied by default.
- The memory map is fixed for Phase 02 unless review approves a revision. Address decode must use the complete address so high-address aliases cannot reach a valid target.
- Address decode uses the complete address so high-address aliases cannot reach a valid target.

Per-register offsets, reset values, privilege, and side effects remain open until each peripheral is designed.
DMA, crypto, AI accelerator, TRNG, and PMP/firewall register behavior remains to be implemented. Physical clock gating, debug halt/step, and external debug transport are not part of the initial Phase 06 RTL.
Loading
Loading