Skip to content

Comments

CHERIoT debug module integrated#387

Merged
marnovandermaas merged 21 commits intolowRISC:mainfrom
marnovandermaas:cheriot-debug-module
Mar 26, 2025
Merged

CHERIoT debug module integrated#387
marnovandermaas merged 21 commits intolowRISC:mainfrom
marnovandermaas:cheriot-debug-module

Conversation

@marnovandermaas
Copy link
Contributor

This integrates the CHERIoT debug module into Sonata.

Memory inspection and register inspection work, as well as setting break points.

When trying the "run" command in GDB and asking it to start from the beginning, I get a remote failure reply 'E0E', but I'm hoping this will be solved when using a CHERI-aware LLDB.

Copy link
Contributor

@elliotb-lowrisc elliotb-lowrisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not managed to get to the point of testing this yet, but here are a couple of early comments.

@elliotb-lowrisc
Copy link
Contributor

elliotb-lowrisc commented Mar 19, 2025

I tried building LLDB using the CHERIoT LLVM toolchain, but I'm not sure it's CHERI-aware. It seemed less capable than the RISC-V GDB we have in the nix develop shell, unable to read CSRs and it getting the byte order wrong when reading system info registers. I also don't see much by way of changes in the lldb/ part of the toolchain source. EDIT: note, I am a novice when it comes to debuggers and may have missed something.

@marnovandermaas marnovandermaas marked this pull request as draft March 19, 2025 13:25
@marnovandermaas

This comment was marked as outdated.

@elliotb-lowrisc
Copy link
Contributor

When trying the "run" command in GDB and asking it to start from the beginning, I get a remote failure reply 'E0E'...

I think I've found the cause of this. I noticed the Verilator sim output an Illegal instruction (hart 0) at PC 0xb0000348: 0x39052023 error when run was issued in GDB. This decodes to a sw x16 0x380(x10) instruction. The key part is that rs2 is set to register 16, which does not exist for CHERIoT Ibex. The debugger doesn't know this, however, as misa is set for RV32I, not RV32E. The run command seemed to work when I tried hacking misa to show the reverse.

@marnovandermaas
Copy link
Contributor Author

marnovandermaas commented Mar 19, 2025

When trying the "run" command in GDB and asking it to start from the beginning, I get a remote failure reply 'E0E'...

I think I've found the cause of this. I noticed the Verilator sim output an Illegal instruction (hart 0) at PC 0xb0000348: 0x39052023 error when run was issued in GDB. This decodes to a sw x16 0x380(x10) instruction. The key part is that rs2 is set to register 16, which does not exist for CHERIoT Ibex. The debugger doesn't know this, however, as misa is set for RV32I, not RV32E. The run command seemed to work when I tried hacking misa to show the reverse.

Cool, that makes sense! It also means that using a CHERIoT-enabled debugger should help this issue.

This patch fixes the test logic inside the CHERIoT debug module TAP.
Initialize the vendor directory from the CHERIoT debug module upstream
at revision: 145bc9e2186368ec804aadfe61d21e7cbcbba33c
The upstream repository is located at
github.com/CHERIoT-Platform/cheriot-dbg-module
The debug module needs to be accessible on both the data and instruction
ports.
@marnovandermaas marnovandermaas marked this pull request as ready for review March 19, 2025 15:48
@elliotb-lowrisc
Copy link
Contributor

Ah ha! The instruction cache is the culprit. It's not respecting the mutable nature of instructions loaded from the AbstractCmd part of the debug module memory map. Register load Abstract Commands kept ending up returning the value of misa (and early CSR load) rather than the value of the intended register. Disabling the icache by changing sw/cheri/common/boot.S:62 seemed to finally make breakpoints work as they should (combined with hacked RV32E misa value).

@marnovandermaas
Copy link
Contributor Author

@elliotb-lowrisc here's a fix for the MISA issue: lowRISC/sunburst-chip#68

This commit:
- Regenerates both crossbars and connect up debug module.
- Removes the custom debug reset logic.
- Switches from RISC-V to CHERIoT debug module.
- Adjust Verilator lints.
marnovandermaas and others added 7 commits March 24, 2025 11:20
An example of how you would use this is:
$ util/mem_helper.sh load_program -e sw/cheri/build/checks/uart_check -t util/verilator-openocd-cfg.tcl
This also includes code to restart the core after reprogramming using
the memory helper script.
With the RTOS mainline gaining some support for code in HyperRAM, it
would be nice to be able to load such images in over OpenOCD without
needing to write code to do bounce buffering.

While here, also give the debug host access to the system_info
peripheral, to provide some more diagnostic information.
This connects the debug host up so that it can also inspect the HyperRAM
and the System information IP.
@marnovandermaas marnovandermaas force-pushed the cheriot-debug-module branch 2 times, most recently from 63841b5 to 347aa3d Compare March 24, 2025 13:57
marnovandermaas and others added 7 commits March 24, 2025 14:37
Also remove stale sw-debug.md
This renames the chip to riscv-cheriot and also adds some additional
configuration for GDB.
This means that you can load a new program into memory and not exit
OpenOCD immediately, for example:
util/mem_helper.sh load_program -e sw/cheri/build/checks/uart_check -x ""
Synthesis under Vivado 2021.1 is currently not passing timing because of
the debug module being added to the instruction fetch bus. Vivado 2024.1
does pass timing so use this instead.

Co-authored-by: Elliot Baptist <elliot.baptist@lowrisc.org>
Now that we have a properly functioning debug module, we must start the
core again after loading the image.
This commit pulls in the latest changes to the sonata-ibex branch, which
reports RV32E as enabled when running in CHERIoT mode and disables the
instruction cache when in debug mode.

Update code from upstream repository
https://github.com/lowrisc/cheriot-ibex.git to revision
158a03fd338f9a5aa977edbe7452bff67c499e93

Signed-off-by: Marno van der Maas <mvdmaas+git@lowrisc.org>
Copy link
Contributor

@elliotb-lowrisc elliotb-lowrisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me

@marnovandermaas marnovandermaas merged commit 558d8fd into lowRISC:main Mar 26, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants