riscv / riscv-debug-spec

Working Draft of the RISC-V Debug Specification Standard
https://jira.riscv.org/browse/RVG-94
Other
454 stars 92 forks source link

is dmstatus.version readable when dmactive is 0? #395

Closed timsifive closed 5 years ago

timsifive commented 5 years ago

@gravikumar92 raised the following problem in https://github.com/riscv/riscv-openocd/issues/316:

While dmactive is 0, the spec says:

The module’s state, including authentication mechanism, takes its reset values (the dmactive bit is the only bit which can be written to something other than its reset value). and also: Implementations may pay attention to this bit to further aid debugging, for example by preventing the Debug Module from being power gated while debugging is active.

The former implies that dmstatus.version is readable, but the latter implies it might not be. Currently OpenOCD assumes the version is always available, and it uses this to automatically detect 0.11 vs. 0.13. Since 0.11 doesn't have a dmactive bit automatic detection gets trickier (but probably still doable) if we can't assume the version is always accessible.

timsifive commented 5 years ago

@gravikumar92, I assume you have an implementation that does something such that dmstatus.version is not accessible until dmactive is 1. How much more complicated does your design get if there is a requirement to always have dmstatus.version accessible? What other costs are there to that?

gravikumar92 commented 5 years ago

I have to check with the design team. As per our understanding, dmactive should be 1(init sequence) to read dmstatus register.

aswaterman commented 5 years ago

@gravikumar92 IMO the behavior of reading dmstatus should be unspecified when dmactive=0.

timsifive commented 5 years ago

@aswaterman Even the version field, which should be a constant and isn't dependent on any system state? Is this because it's expensive to implement a register returning a constant when dmactive=0, some philosophical issue, or something else?

timsifive commented 5 years ago

The dmactive bit in 0.13 holds the place of fullreset in 0.11. Always writing dmactive and then checking version would result in resetting 0.11 systems.

mwachs5 commented 5 years ago

I think that you shouldn’t necessarily be able to connect to a system that has already powered itself down or clock gated or whatever dmactive is going to prevent.

timsifive commented 5 years ago

"connect to a system" is not very specific. I think it would be nice to be able read the version field of dmstatus even when dmactive is 0. If the DM is completely powered down, this could be achieved by simply intercepting the read of dmstatus when dmactive is 0, and returning the constant with the correct version. That sounds pretty cheap.

timsifive commented 5 years ago

In the end the question is: do we want to require slightly more hardware in 0.13, in order to be backwards compatible with 0.11. 0.11 was not widely implemented, but the 0.13 hardware cost is also low.

mwachs5 commented 5 years ago

Ok, it seems like we would perhaps want an exception for reading DMSTATUS (or even only DMSTATUS.version?) even when dmactive=0? But that's not a strictly backwards compatible change for either SW or Hardware... if it was vague before, the clarification will both put more restrictions on HW and limit what SW can assume.

timsifive commented 5 years ago

I would like to require version to always be readable, but since that's a backwards-incompatible change I don't want to make it now. I'll make a PR to make this unambiguous, and to state that the behavior/position of the dmactive bit won't change in the future.