-
Notifications
You must be signed in to change notification settings - Fork 861
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
medeleg: the third bit(CAUSE_BREAKPOINT) of medeleg is unwritable when Sdtrig exist. #1742
base: master
Are you sure you want to change the base?
medeleg: the third bit(CAUSE_BREAKPOINT) of medeleg is unwritable when Sdtrig exist. #1742
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's entirely true. Making medeleg.breakpoint read-only zero is one implementation choice:
We should be doing the first one in Spike (right @YenHaoChen?) because supporting the delegation of breakpoint exceptions is the more common implementation choice.
We hope to use Spike as the golden reference, and our hardware implements the second choice. Can both choice be implemented in Spike? Additionally, add a switch to select which choice to use? You can set the first choice as the default. |
This statement comes from Debug spec Section 5.4, which states the bit is unwritable when implementing tcontrol.mte/mtep (the second choice). When reading the debug spec, I also needed clarification about what a general implementation should be. Based on my reading, the spec prefers to implement one of the solutions but not both. Additionally, the medeleg[3] is writable in Spike. Thus, I went for the first solution without implementing the optional tcontrol CSR of the second solution. However, people requested implementing the tcontrol CSR #1688. Currently, Spike implements both solutions with the medeleg[3] writable. @rtwfroody Is the behavior of the current Spike generally expected by the debugger? It is not clear to me whether the debug spec allows the behavior. (I have another question unrelated to this post. The tcontrol is an optional CSR. The default value of tcontrol prevents triggers from M-mode if the tcontrol exists. How does the debugger know whether to write the tcontrol or not? If the tcontrol does not exist, won't writing the tcontrol cause the debugger to fail?) |
External debuggers (e.g. OpenOCD) don't care about any of this. These features only exist to facilitate M-Mode debuggers running in spike, debugging M-Mode code.
The spec says to implement one of the two options. Option 1 is cheap to implement but keeps triggers disabled during interrupt handlers. Option 2 is more costly and gives better options for having triggers fire even during interrupt handlers. Implementing both at the same time doesn't really make sense. For using spike as a golden model, there should probably be a build or run-time option to select which of the two is active.
If you want triggers to cause a breakpoint while executing from M-Mode, you must have M-Mode privileges to make that happen. In that case you can set up a simple trap handler, write tcontrol, and see if your trap handler was hit or not. |
Both @NewPaulWalker and @rtwfroody have expressed interest in a build option that switches the writability of medeleg[3] and the existence of tcontrol. However, the current commit won’t compile because we don't have the Would anyone like to take on this task? Alternatively, I can provide a prototype for it. |
We are moving away from build-time options. (Even misaligned loads and stores are no longer a build-time option.) If we really need to support this, it needs to come in through an ISA string. Specifying that might be a matter for the debug TG; regardless, it seems out of scope for the Spike authors. |
According to the riscv instruction set manual, when the Sdtrig extension exists, the CAUSE_BREAKPOINT bit (the third bit) of the medeleg CSR is unwritable. Otherwise, this bit is writable.