Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [rtl] on-chip debugger: add RISC-V trigger module for hardware breakpoints #274

Merged
merged 11 commits into from
Feb 10, 2022

Conversation

stnolting
Copy link
Owner

@stnolting stnolting commented Feb 10, 2022

This PR adds a simple implementation of the RISC-V trigger module to the CPU core. It complies to the RISC-V debug spec. v0.13.2. A copy of this spec. can be found in docs/references.

💡 The NEORV32 trigger module is part of the on-chip debugger and implements a single instruction address match trigger that can be used to add "hardware-assisted breakpoints" when debugging code that is executed from ROM.
The idea to add this was triggered by @emb4fun.

Hardware Breakpoints vs. Software Breakpoints

The "normal" software breakpoints using gdb's b/break command temporarily replace the instruction word, where the debugger shall halt, by a BREAK instruction (ebreak or c.ebreak). After the CPU has halted and entered debug mode, the debugger will restore the original instruction word to maintain correct operation. Obviously, this concept is only possible when the program being executed resides in RAM.

Example: Adding a software breakpoint at address 0xffff0000 in gdb:

b *0xffff0000

When debugging code, which is executed from ROM, one needs to use hardware-assisted breakpoints using gdb's hb/hbreak commands. A hardware breakpoint uses the CPU's trigger module to store the address of the instruction that shall trigger a breakpoint. Whenever execution reaches this specific address the CPU is halted and enters debug mode.

Example: Adding a hardware-assisted breakpoint at address 0xffff0000 in gdb:

hb *0xffff0000

🐛 This PR also fixes a minor bug in ebreak instruction's dcsr.cause value (was 0b010 but has to be 0b001).

@stnolting stnolting added risc-v compliance Modification to comply with official RISC-V specs. HW hardware-related labels Feb 10, 2022
@stnolting stnolting self-assigned this Feb 10, 2022
reworked whole section "on-chip debugger"
add RISC-V trigger module to CPU / debugger
@stnolting stnolting added the enhancement New feature or request label Feb 10, 2022
@stnolting stnolting marked this pull request as ready for review February 10, 2022 07:17
@stnolting stnolting merged commit 7488e3f into main Feb 10, 2022
@stnolting stnolting deleted the add_hw_trigger_module branch February 10, 2022 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request HW hardware-related risc-v compliance Modification to comply with official RISC-V specs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant