VexRiscv-Debug

MkDocs icon
SWD Debug support in VexRiscv

RISC-V ISA

RISC-V is an open standard instruction set architecture based on established RISC (Reduced Instruction Set Computer) principles.

Comparing to ARM and x86, a RISC-V CPU has the following advantages:

RISC-V Minimal Viable Debugger

To create a minimum viable debugger on a RISC-V Processor, you need the following capabilities:

Here’s a simplified diagram representing these core components:

     +---------------------+      +-----------------------+
     |    Debugger Host    |      |    Target Device      |
     +---------------------+      +-----------------------+
             |                           |
             |      (Debug Interface)    |
             v                           v
    +-----------------------+      +-----------------------+
    |   Memory Access      |----->| Memory                |
    |  (Read/Write)        |      |                       |
    +-----------------------+      +-----------------------+
             |                           |
             |                           |
    +-----------------------+      +-----------------------+
    | CPU Register Access  |----->| CPU Registers         |
    |  (Read/Write)        |      |                       |
    +-----------------------+      +-----------------------+
             |                           |
             |                           |
    +-----------------------+      +-----------------------+
    |   CPU Control         |----->| CPU (Halt, Step, etc.)|
    | (Halt, Step, Reset)   |      |                       |
    +-----------------------+      +-----------------------+

Vexriscv Processor

VexRiscv is an FPGA-friendly CPU core that implements the RISC-V instruction set architecture (ISA). Designed with flexibility and scalability in mind, it caters to a wide range of applications, from compact microcontroller-based systems to more complex multi-core configurations. The project is open-source under the MIT license, promoting community collaboration and adaptation.

VexRiscv is developed using SpinalHDL, a high-level hardware description language that enhances design modularity and reusability. This approach allows for a plugin-based architecture, enabling users to customize and extend the CPU’s capabilities to meet specific project requirements.

VexRiscv Current Debugging Status

The VexRiscv soft core supports minimal custom debugging by utilizing a debug plugin, which has two registers that allow for complete control of the CPU.

With these two registers, the core has all the necessary functions for a complete debugger, thus meeting the minimum requirements of a viable debugger.

JTAG support in Vexriscv

JTAG stands for Joint Test Action Group. JTAG support in VexRiscv is implemented through a combination of hardware and software components that adhere to the JTAG standard (IEEE 1149.1).

The diagram below describe how a host computer (with GDB) uses a JTAG interface to debug a VexRiscv CPU.

                                  +-----------------+
                                  |    GDB (Host PC)|
                                  +-------+---------+
                                          | (GDB remote target protocol)
                                          v
                                  +---------------+
                                  |   OpenOCD     |
                                  | (VexRiscv     |
                                  |   Driver)     |
                                  +-------+-------+
                                          | (JTAG transactions)
                                          v
    +----------+       +-----------------+    +-------------------+
    |  JTAG    | <---> |  JTAG Bridge    |--->|  VexRiscv Debug   |   
    |  Dongle  |       |(TAP, IR, DR,    |    |     Plugin        |
    |(TCK, TMS,|       |State Machine)   |    |(SystemDebugBus)   |
    |TDI, TDO) |       +-----------------+    +--------+----------+
    +----------+                                | (CPU Control, Registers)
                                                |
                                                v
                                   +--------------------------+
                                   |      VexRiscv CPU        |
                                   +--------------------------+

Debugging VexRiscv using JTAG involves connecting a JTAG dongle to the FPGA, and then using OpenOCD with a VexRiscv specific driver, to communicate with the JTAG bridge, which accesses the CPU debug module, all while GDB executes on the host machine. A custom version of OpenOCD acts as the glue between GDB and the VexRiscv debug logic, handling the low-level JTAG communication.


Benefits of standardized Debugging

The VexRiscv CPU has its own specific debugging implementation that is not compatible with the standard RISC-V Debug Specification. Current deviation from the ratified RISC-V debug specification is listed below :

Ratified Debug Spec Feature VexRiscv Support Status
Halt/Resume/Singlestep ✅ Supported
Register (GPR/CSR) Read/Write ✅ Via instruction injection
Memory Access via Abstract Commands ❌ Not standard; done via instruction injection
Hardware Breakpoints / Triggers ⚠️ Supports PC and load/store triggers, other modes not supported
Program Buffer ✅ Supported
Multi-hart / Multi-DM support ⚠️ Unable to halt/resume multiple harts with a single command
Alternate Transport Modules (non-JTAG) ❌ Not implemented
DM/DTM layer per spec ❌ Partial; custom version used, need to extend to supprt SWD

Other than above features , below feature needs to be implemented :

SWD support in Vexriscv

SWD stands for Serial Wire Debug. The key differences between JTAG and SWD are :

To add support for the RISC-V debug standard over SWD in VexRiscv below steps need to be followed:

1. Debug Module (DM) Implementation:

2. Debug Transport Module (DTM) Implementation:

3. Mapping the Debug Module Interface (DMI) Implementation:

Memory Access Methods

To be compliant, the implementation must have at least one of the memory access mechanisms: Program Buffer, Abstract Access Memory or System Bus Access (SBA).

Register Access
Control Register

4. SWD Implementation:

5. Software Support:

The following conceptual diagram explains the general components and data flow involved in debugging via SWD:

MkDocs icon

In the diagram:

Breakdown of Tasks

Below is the structured breakdown of tasks with estimated effort .

1. Refactor/Extend DebugPlugin

Goal: Align VexRiscv CPU-side debug logic to the RISC-V Debug Spec.

Tasks:

Effort: 30 person-days


2. Implement/Refine DTM + JTAG TAP

Goal: Make the transport layer spec-compliant.

Tasks:

Effort: 30 person-days


3. SWD Debug Transport Implementation

Goal: Add Serial Wire Debug support alongside JTAG.

Tasks:

Effort: 30 person-days

4. System Integration into SoC

Goal: Integrate the new debug architecture into the top-level FPGA/System design.

Tasks:

Effort: 15 person-days


5. Toolchain Integration (OpenOCD / GDB)

Goal: Fully debug the system using OpenOCD + GDB.

Tasks:

Effort: 15 person-days


6. Verification & Test Infrastructure

Goal: Ensure the entire debug pipeline behaves predictably.

Tasks:

Effort: 15 person-days


7. Documentation & Developer Interface

Goal: Make integration/usage clear for future development.

Tasks:

Effort: 15 person-days


8. Multi-Hart & Advanced Features

Goal: Add support for multiple cores and advanced triggers.

Tasks:

Effort: 30 person-days


** Total Estimated Effort**

Equivalent to 180 person-days .