OpenOCD fails to connect in Verilator
Reproduction steps:
- Build and run Verilator model
- Run OpenOCD with Verilator configuration
$ /tools/openocd/bin/openocd -s util/openocd \ -f board/lowrisc-earlgrey-verilator.cfg
Observed results in OpenOCD stderr:
Warn : Adapter driver 'remote_bitbang' did not declare which transports it allows; assuming legacy JTAG-only
Info : only one transport option; autoselect 'jtag'
Info : Initializing remote_bitbang driver
Info : Connecting to localhost:44853
Info : remote_bitbang driver initialized
Info : This adapter doesn't support configurable speed
Info : JTAG tap: riscv.tap tap/device found: 0x00000001 (mfg: 0x000 (<invalid>), part: 0x0000, ver: 0x0)
Info : datacount=2 progbufsize=8
Error: Abstract command ended in error 'exception' (abstractcs=0x8001302)
Error: Timed out after 120s waiting for busy to go low (abstractcs=0x8001302). Increase the timeout with riscv set_command_timeout_sec.
Observed output in Verilator:
Simulation running, end by pressing CTRL-c.
TOP.top_earlgrey_verilator.top_earlgrey.core.ibex_tracer_i: Writing execution trace to trace_core_00000000.log
jtag0: Accepted client connection
1160795: Illegal instruction (hart 0) at PC 0x1a110360: 0x00010413
The illegal instruction is seed right after connecting to jtag0 via OpenOCD.
I haven't tested this on the FPGA yet.
Illegal instructions are expected when connecting through OpenOCD; they just need to be handled properly by the core and the debug system. I don't have time to look into that today, but hopefully tomorrow or on Monday latest.
This may be the same issue as discussed later on here: https://github.com/lowRISC/ibex/issues/365 (OpenOCD or GDB inserting an FENCE.I causing an illegal instruction exception)
hi all, i took a look today. In my environment at least, there might be an issue with ebreak instructions not being honored.
It basically boils down to the qualified ebreak_insn being qualified with instr_valid_i. The latter disappears when we flush, so the DBG_TAKEN_ID state never sees it. I accidentally closed my gtkwave so I don't have the waveforms anymore. Udi reproduced this on verdi, and will add it here soon.
Hi all,
Below are the waves of this issue:
The ebreak instruction at 0x80010a2a inside the debug rom is qualified during the controller DECODE and FLUSH states, but instr_valid_i drops after the transition into DBG_TAKEN_ID since instr_valid_clear_o is high at the same time. As a result, the core doesn't jump back to to the entry point of the debug rom, which in this example is at 0x800108a0, but keeps fetching and executing normally.
I'll take a look at the ebreak issue, sounds like I broke it in the first place (I added the instr_valid_i qualifiers) plus it's a good excuse to get familiar with the debug infrastructure
ebreak is indeed broken (in debug mode). The issue is the ID stage get flushed before the ebreak is dealt with properly. I have a fix for this but I think I may have broken single stepping at the same time so want to give it more thought on Monday before creating a PR for it. However I have got as far as OpenOCD connecting and then listening for a GDB connection (which I haven't yet tried).
Issue in ibex repo to track this problem https://github.com/lowRISC/ibex/issues/393
Oh and thanks to @tjaychen @udinator for the initial diagnosis which was spot on, I've just spent today learning about how the debug infrastructure works so I'm now far better placed to fix it!
thanks for the quick turnaround Greg!
On Fri, Oct 11, 2019 at 9:11 AM Greg Chadwick [email protected] wrote:
Oh and thanks to @tjaychen https://github.com/tjaychen @udinator https://github.com/udinator for the initial diagnosis which was spot on, I've just spent today learning about how the debug infrastructure works so I'm now far better placed to fix it!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/413?email_source=notifications&email_token=AAH2RSWVNMQ4VCVW6DNRAK3QOCQUFA5CNFSM4I7NQ7J2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBAPFMQ#issuecomment-541127346, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSXKROF3DYQDNRAG3FTQOCQUFANCNFSM4I7NQ7JQ .
Adding @mcy since i believe he's looking at the pytest framework + openocd compliance test.
With this PR https://github.com/lowRISC/ibex/pull/398 applied I can connect OpenOCD to earlgrey verilator. The OpenOCD compliance test suite passes. GDB connects and basic single stepping, variable and register examining works. However breakpoints don't work as we're executing out of emulated flash which doesn't allow writes.
However we're getting plenty of 'Ignoring packet error, continuing...' messages out of GDB and illegal instruction warnings out of Ibex.
It's also surprisingly slow, whilst you'll never expect it to be that snappy it takes several seconds for a single-step I'd hope you could make that quicker. Printing the value of a register or variable is far quicker. Potentially something to do with the packet errors? (it sends a command, gets dodgy response and waits for a timeout before trying something else).
thanks @GregAC ! illegal instructions out of ibex still doesn't sound right... it still feels like maybe ibex is going off into the weeks somehow.
Regarding breakpoint, is there no PC comparison hardware inside ibex, and it relies on inserting breakpoints directly in instruction memory? Just trying to see if that's what you meant by breakpoints not working.
Yup, there's no hardware breakpoint support currently so GDB wants to overwrite instructions which then fails. We already have an issue to track this in Ibex https://github.com/lowRISC/ibex/issues/382. Looks like we should implement that soon to allow debugging programs in flash.
sounds good! Do you think we should pursue the other illegal ibex instructions more? It doesn't sound like that should be happening. I must admit I'm not at all an expert on how openocd and gdb play together.
I think it's worth looking into. I'll do a bit more investigation tomorrow.
Thanks Greg! If you guys are comfortable doing another vendor drop with this fix, we can help look at it too (or I can try to just cherry-pick that PR)
On Tue, Oct 15, 2019, 09:11 Greg Chadwick [email protected] wrote:
I think it's worth looking into. I'll do a bit more investigation tomorrow.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/413?email_source=notifications&email_token=AAH2RSXXPKSR3BMQMM4UXN3QOXTRPA5CNFSM4I7NQ7J2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBJLA7Y#issuecomment-542290047, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSQJ7PLPRMVQAUM6YJDQOXTRPANCNFSM4I7NQ7JQ .
I believe this is now fixed.
@udinator can you confirm? I know you are the most recent one to try this. I'm going to close this issue first, feel free to re-open.
@tjaychen - Confirming that I'm able to connect OpenOCD successfully to verilator. Just as @GregAC said previously, I'm also seeing a lot of warnings about dropped packets and packet errors. I also see illegal instruction messages from the Ibex core, but these all appear to be due to fence.i instructions being inserted, which Ibex doesn't support right now. Single stepping with GDB has a tendency to hang indefinitely, but this may be a topic for another issue.
I am looking at making GDB/OpenOCD work better with earlgrey verilator, supporting FENCE.I and hardware breakpoints should be straight-forward and will help. There's also a debug test suite that uses GDB and OpenOCD in the riscv/riscv-tests repository that I have been meaning to try out. I'll create a new issue for this just so people are aware I'm looking into it.