How do I programmatically exit back to the debugger?

I’m trying to execute small pieces of assembler code that, when finished, exit back to the debugger. I’m using SiFive’s openocd in the usual way. (Except that I’m not using GDB - more on this later. :wink:

After reading thru both debug specs (0.11 and 0.13) and eyeballing and grepping the code in openocd/src/target/riscv/ I’m coming to the conclusion that I can simply use an EBREAK instruction to exit back to the debugger. Is this right? It seems like openocd is setting all the EBREAK{M,H,S,U} bits in the DCSR register before re-starting the target, and this suggests that EBREAK will halt the core and return the debugger. I just wanted to ping folks here to see if my thinking (and understanding) is correct.

Thanks!

Right, both v11 and v13 of the Debug Spec state that if your core executes an EBREAK with the relevant bits of DCSR set, you’ll drop into “debug mode”. Exactly what that means differs between the two specs, but in both cases the core informs the debugger that it’s halted in Debug Mode, and waits for further instructions from the debugger.

Let us know if you have more questions about the debug interface. Note that v13 of OpenOCD is very much a work in progress.

Sweet!

Thanks for your quick answer.

I’ll be posting more here soon about what it is, exactly, that I’m up to… :wink: