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

OpenOCD and ndmreset signal reset issue #65

Open
imi415 opened this issue Jun 13, 2020 · 3 comments
Open

OpenOCD and ndmreset signal reset issue #65

imi415 opened this issue Jun 13, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@imi415
Copy link

imi415 commented Jun 13, 2020

Hi, I'm trying to integrate Ibex with debug module, however I found that under current implementation of the debug module, both reset-to-halt and reset-to-run are not working correctly, which crashes the OpenOCD process.

Below are my attempts to locate the problem, However, I have little knowledge about the code or the specification, if there are anything I got wrong or missed, please point out. Any suggestions are appreciated. Thanks in advance.


OpenOCD sets NDMRESET field in dmcontrol during reset period, and expects to see ALLRUNNING field to be set in dmstatus indicating the end of reset operation. These behaviors are addressed below:
https://github.com/riscv/riscv-openocd/blob/4f9e2d7171f3cad8d1a99dff3eee5ec5e6d8ea2b/src/target/riscv/riscv-013.c#L2090

https://github.com/riscv/riscv-openocd/blob/4f9e2d7171f3cad8d1a99dff3eee5ec5e6d8ea2b/src/target/riscv/riscv-013.c#L2144

However, the debug module has its ALLRUNNING field wired to halted signal, which is set by a write operation to HALT address of the debug bus, and cleared by write to RESUME address of the debug bus.

riscv-dbg/src/dm_csrs.sv

Lines 249 to 250 in 3670267

dmstatus.allrunning = ~halted_aligned[selected_hart] & ~unavailable_aligned[selected_hart];
dmstatus.anyrunning = ~halted_aligned[selected_hart] & ~unavailable_aligned[selected_hart];

riscv-dbg/src/dm_mem.sv

Lines 242 to 255 in 3670267

unique case (addr_i[DbgAddressBits-1:0]) inside
HaltedAddr: begin
halted_aligned[wdata_hartsel] = 1'b1;
halted_d_aligned[wdata_hartsel] = 1'b1;
end
GoingAddr: begin
going = 1'b1;
end
ResumingAddr: begin
// clear the halted flag as the hart resumed execution
halted_d_aligned[wdata_hartsel] = 1'b0;
// set the resuming flag which needs to be cleared by the debugger
resuming_d_aligned[wdata_hartsel] = 1'b1;
end

When the core is already in parked-loop state and a reset-to-run command is issued by OpenOCD, the core may never has a chance to write to RESUME address, since it has been resetted by ndmreset signal. So the ALLRUNNING field will never be set and OpenOCD just get stucked in the loop until timeout reached.

This internal state (core is actually running while dmstatus has wrong value) also causes crash of OpenOCD, then a reset to dm will be needed for the dm to function properly.

@bluewww bluewww added the bug Something isn't working label Jun 13, 2020
@bluewww
Copy link
Collaborator

bluewww commented Jun 13, 2020

I guess they need to be put into the unavailable or running state after a ndmreset

@gxflying
Copy link

yeah, this is because when ndmreset is set, the current version DM doesn't clear the "halted flags".

and one more thing, the dmcontrol.dmactive may also not works well because it should do something with the registers in dm_mem.sv but it doesn't.
for example:
spec says dmactive can clear the abstractcs.busy status. but the current version does nothing with abstractcs.busy
image

@bluewww
Copy link
Collaborator

bluewww commented Jun 25, 2020

Can you open a separate issue for this, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants