RISC-V VHDL: System-on-Chip  2.0
Debug Support Unit (DSU)

Overview

Debug Support Unit (DSU) was developed to interact with "RIVER" CPU via its debug port interace. This bus provides access to all internal CPU registers and states and may be additionally extended by request. Run control functionality like 'run', 'halt', 'step' or 'breakpoints' imlemented using proprietary algorithms and intend to simplify integration with debugger application.

Set of general registers and control registers (CSR) are described in RISC-V privileged ISA specification and also available for read and write access via debug port.

Note
Take into account that CPU can have any number of platform specific CSRs that usually not entirely documented.

DSU registers mapping

DSU acts like a slave AMBA AXI4 device that is directly mapped into physical memory. Default address location for our implementation is 0x80020000. DSU directly transforms device offset address into one of regions of the debug port:

  • 0x00000..0x08000 (Region 1): CSR registers.
  • 0x08000..0x10000 (Region 2): General set of registers.
  • 0x10000..0x18000 (Region 3): Run control and debug support registers.
  • 0x18000..0x20000 (Region 4): Local DSU region that doesn't access CPU debug port.
Example:
Bus transaction at address 0x80023C10 will be redirected to Debug port with CSR index 0x782.

CSR Region (32 KB)

User Exception Program Counter (0x00208). ISA offset 0x041.
BitsTypeReset Name Definition
64 RO 64h'0 uepc User mode exception program counter. Instruction URET is used to return from traps in User Mode into specified instruction pointer. URET is only provided if user-mode traps are supported.
Machine Status Register (0x01800). ISA offset 0x300.
BitsTypeReset Field NameBits Description
1 RW 1b'0 SD 63 Bit summarizes whether either the FS field or XS field signals the presence of some dirty state that will require saving extended user context to memory
22 RW 22h'0 WPRI 62:20 Reserved
5 RW 5h'0 VM (WARL)28:24 Virtual addressing enable
4 RW 4h'0 WPRI 23:20 Reserved
1 RW 1b'0 MXR 19 Make eXecutable Readable
1 RW 1b'0 PUM 18 Protect User Memory bit modifies the privilege with which loads access virtual memory
1 RW 1b'0 MPRV 17 Privilege level at which loads and stores execute
2 RW 2h'0 XS 16:15 Context switch reducing flags: 0=All Off; 1=None dirty or clean, some on; 2=None dirty, some clean; 3=Some dirty
2 RW 2h'0 FS 14:13 Context switch reducing flags: 0=Off; 1=Initial; 2=Clean; 3=Dirty
2 RW 2h'0 MPP 12:11 Priviledge mode on MRET
2 RW 2h'0 HPP 10:9 Priviledge mode on HRET
1 RW 1b'0 SPP 8 Priviledge mode on SRET
1 RW 1b'0 MPIE 7 MIE prior to the trap
1 RW 1b'0 HPIE 6 HIE prior to the trap
1 RW 1b'0 SPIE 5 SIE prior to the trap
1 RW 1b'0 UPIE 4 UIE prior to the trap
1 RW 1b'0 MIE 3 Machine interrupt enable bit
1 RW 1b'0 HIE 2 Hypervisor interrupt enable bit
1 RW 1b'0 SIE 1 Super-user interrupt enable bit
1 RW 1b'0 UIE 0 User interrupt enable bit
Machine Trap-Vector Base-Address Register (0x01828). ISA offset 0x305.
BitsTypeReset Field Name Definition
64 RW 64h'0 mtvec Trap-vector Base Address. The mtvec register is an XLEN-bit read/write register that holds the base address of the M-mode trap vector.
Machine Exception Program Counter (0x01A08). ISA offset 0x341.
BitsTypeReset Field Name Definition
64 RW 64h'0 mepc Machine mode exception program counter. Instruction MRET is used to return from traps in User Mode into specified instruction pointer. On implementations that do not support instruction-set extensions with 16-bit instruction alignment, the two low bits (mepc[1:0]) are always zero.
Machine Cause Register (0x01A10). ISA offset 0x342.
BitsTypeReset Field Name BitsDefinition
1 RW 1b'0 Interrupt 63 The Interrupt bit is set if the trap was caused by an interrupt.
63 RW 63h'0 Exception Code 62:0 Exception code. The Exception Code field contains a code identifying the last exception. Table 3.6 lists the possible machine-level exception codes.
Machine Cause Register (0x01A18). ISA offset 0x343.
BitsTypeReset Field Name BitsDefinition
64 RW 64h'0 mbadaddr 63:0 Exception address. When a hardware breakpoint is triggered, or an instruction-fetch, load, or store address-misaligned or access exception occurs, mbadaddr is written with the faulting address. mbadaddr is not modified for other exceptions.
Machine ISA Register (0x07880). ISA offset 0xf10.
BitsTypeReset Field NameBits Description
2 RO 2h'2 Base (WARL)63:62 Integer ISA width: 1=32 bits; 2=64 bits; 3=128 bits.
34 RO 64h'0 WIRI 61:28 Reserved.
28 RO 28h'141181 Extension (WARL) 27:0 Supported ISA extensions. See priviledge-isa datasheet.
Machine Vendor ID (0x07888). ISA offset 0xf11.
BitsTypeReset Field NameBits Description
64 RO 64h'0 Vendor 63:0 Vendor ID. read-only register encoding the manufacturer of the part. This register must be readable in any implementation, but a value of 0 can be returned to indicate the field is not implemented or that this is a non-commercial implementation.
Machine Architecture ID Register (0x07890). ISA offset 0xf12.
BitsTypeReset Field NameBits Description
64 RO 64h'0 marchid 63:0 Architecture ID. Read-only register encoding the base microarchitecture of the hart. This register must be readable in any implementation, but a value of 0 can be returned to indicate the field is not implemented. The combination of mvendorid and marchid should uniquely identify the type of hart microarchitecture that is implemented.
Machine implementation ID Register (0x07898). ISA offset 0xf13.
BitsTypeReset Field NameBits Description
64 RO 64h'0 mimplid 63:0 Implementation ID. CSR provides a unique encoding of the version of the processor implementation. This register must be readable in any implementation, but a value of 0 can be returned to indicate that the field is not implemented.
Hart ID Register (0x078A0). ISA offset 0xf14.
BitsTypeReset Field NameBits Description
64 RO 64h'0 mhartid 63:0 Integer ID of hardware thread. Hart IDs mightnot necessarily be numbered contiguously in a multiprocessor system, but at least one hart musthave a hart ID of zero.

General CPU Registers Region (32 KB)

CPU integer registers (0x08000).
Offset BitsTypeReset Name Definition
0x0800064 RW 64h'0 zero x0. CPU General Integer Register hardware connected to zero.
0x0800864 RW 64h'0 ra x1. Return address.
0x0801064 RW 64h'0 sp x2. Stack pointer.
0x0801864 RW 64h'0 gp x3. Global pointer.
0x0802064 RW 64h'0 tp x4. Thread pointer.
0x0802864 RW 64h'0 t0 x5. Temporaries 0.
0x0803064 RW 64h'0 t1 x6. Temporaries 1.
0x0803864 RW 64h'0 t2 x7. Temporaries 2.
0x0804064 RW 64h'0 s0/fpx8. CPU General Integer Register 'Saved register 0/ Frame pointer'.
0x0804864 RW 64h'0 s1 x9. Saved register 1.
0x0805064 RW 64h'0 a0 x10. Function argument 0. It is also used to save return value.
0x0805864 RW 64h'0 a1 x11. Function argument 1.
0x0806064 RW 64h'0 a2 x12. Function argument 2.
0x0806864 RW 64h'0 a3 x13. Function argument 3.
0x0807064 RW 64h'0 a4 x14. Function argument 4.
0x0807864 RW 64h'0 a5 x15. Function argument 5.
0x0808064 RW 64h'0 a6 x16. Function argument 6.
0x0808864 RW 64h'0 a7 x17. Function argument 7.
0x0809064 RW 64h'0 s2 x18. Saved register 2.
0x0809864 RW 64h'0 s3 x19. Saved register 3.
0x080a064 RW 64h'0 s4 x20. Saved register 4.
0x080a864 RW 64h'0 s5 x21. Saved register 5.
0x080b064 RW 64h'0 s6 x22. Saved register 6.
0x080b864 RW 64h'0 s7 x23. Saved register 7.
0x080c064 RW 64h'0 s8 x24. Saved register 8.
0x080c864 RW 64h'0 s9 x25. Saved register 9.
0x080d064 RW 64h'0 s10 x26. Saved register 10.
0x080d864 RW 64h'0 s11 x27. Saved register 11.
0x080e064 RW 64h'0 t3 x28. Temporaries 3.
0x080e864 RW 64h'0 t4 x29. Temporaries 4.
0x080f064 RW 64h'0 t5 x30. Temporaries 5.
0x080f864 RW 64h'0 t6 x31. Temporaries 6.
0x0810064 RO 64h'0 pc Instruction pointer. Cannot be modified because shows the latest executed instruction address
0x0810864 RW 64h'0 npc Next Instruction Pointer

Run Control and Debug support Region (32 KB)

Run control/status registers (0x10000).
BitsTypeReset Field Name Bits Description
44 RW 61h'0 Reserved 63:6 Reserved.
16 RO 16h'0 core_id 15:4 Core ID.
1 RW 1b'0 Reserved 3 Reserved.
1 RO 1b'0 breakpoint 2 Breakpoint. Status bit is set when CPU was halted due the EBREAK instruction.
1 WO 1b'0 stepping_mode 1 Stepping mode. This bit enables stepping mode if the Register 'steps' is non zero.
1 RW 1b'0 halt 0 Halt mode. When this bit is set CPU pipeline is in the halted state. CPU can be halted at any time without impact on processing data.
Stepping mode Steps registers (0x10008).
BitsTypeReset Field Name Bits Description
64 RW 64h'0 steps 63:0 Step counter. Total number of instructions that should execute CPU before halt. CPU is set into stepping using 'stepping mode' bit in Run Control register.
Clock counter registers (0x10010).
BitsTypeReset Field Name Bits Description
64 RW 64h'0 clock_cnt 63:0 Clock counter. Clock counter is used for hardware computation of CPI rate. Clock counter isn't incrementing in Halt state.
Step counter registers (0x10018).
BitsTypeReset Field Name Bits Description
64 RW 64h'0 executed_cnt 63:0 Step counter. Total number of executed instructions. Step counter is used for hardware computation of CPI rate.
Breakpoint Control registers (0x10020).
BitsTypeReset Field Name Bits Description
63 RW 63h'0 Reserved 63:1 Reserved
1 RW 1b'0 trap_on_break 0 Trap On Break. Generate exception 'Breakpoint' on EBRAK instruction if this bit is set or just Halt the pipeline otherwise.
Add hardware breakpoint registers (0x10028).
BitsTypeReset Field Name Bits Description
64 RW 64h'0 add_break 63:0 Add HW breakpoint address. Add specified address into Hardware breakpoint stack. In case of matching Instruction Pointer (pc) and any HW breakpoint there's injected EBREAK instruction on hardware level.
Remove hardware breakpoint registers (0x10030).
BitsTypeReset Field Name Bits Description
64 RW 64h'0 rem_break 63:0 Remove HW breakpoint address. Remove specified address from Hardware breakpoints stack.
Breakpoint Address Fetch registers (0x10038).
BitsTypeReset Field Name Bits Description
64 RW 64h'0 br_address_fetch 63:0 Breakpoint fetch address. Specify address that will be ignored by Fetch stage and used Breakpoint Fetch Instruction value instead. This logic is used to avoid re-writing EBREAK into memory.
Breakpoint Instruction Fetch registers (0x10040).
BitsTypeReset Field Name Bits Description
64 RW 64h'0 br_instr_fetch 63:0 Breakpoint fetch instruction. Specify instruction that should executed instead of fetched from memory in a case of matching Breapoint Address Fetch register and Instruction pointer (pc).

Local DSU Region (32 KB)

Soft Reset registers (0x18000).
BitsTypeReset Field Name Bits Description
63 RW 63h'0 Reserved 63:1 Reserved.
1 RW 1b'0 soft_reset 0 Soft Reset. Status bit is set when CPU was halted due the EBREAK instruction.
Miss Access counter registers (0x18008).
BitsTypeReset Field Name Bits Description
64 RO 64h'0 miss_access_cnt 63:0 Miss Access counter. This value as an additional debugging informantion provided by AXI Controller. It is possible to enable interrupt generation in Interrupt Controller on miss-access.
Miss Access Address registers (0x18010).
BitsTypeReset Field Name Bits Description
64 RO 64h'0 miss_access_addr 63:0 Miss Access address. Address of the latest miss-accessed transaction. This information comes from AXI Controller.
Bus Utilization registers (0x18040 + n*2*sizeof(uint64_t)).
Offset BitsTypeReset Name Definition
0x1804064 RO 64h'0 w_cnt Write transactions counter for master 0. Master 0 is the RIVER CPU by default.
0x1804864 RO 64h'0 r_cnt Read transactions counter for master 0.
0x1805064 RO 64h'0 w_cnt Write transactions counter for master 1. Master 1 is unused in a case of configuration with RIVER CPU.
0x1805864 RO 64h'0 r_cnt Read transactions counter for master 1.
0x1806064 RO 64h'0 w_cnt Write transactions counter for master 2. Master 2 is the GRETH by default (Ethernet Controller with master interface).
0x1806864 RO 64h'0 r_cnt Read transactions counter for master 2.