Skip to content

Commit fa8173e

Browse files
DRET clarification (#1045)
replacement for #1044 which got messed up on a rebase @JanMatCodasip can you review this one please instead? let's work from here. fix #1043 --------- Signed-off-by: Tariq Kurd <tariq.kurd@codasip.com> Co-authored-by: Jan Matyas <50193733+JanMatCodasip@users.noreply.github.com>
1 parent f97f22a commit fa8173e

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

src/cheri/debug-integration.adoc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ The <<dpc>> register is extended to hold a capability.
138138
include::img/dpccreg.edn[]
139139

140140
Upon entry to debug mode, the _RISC-V Debug Specification_, does not specify how to
141-
update the PC, and says PC-relative instructions may be illegal. This concept
141+
When the hart is in debug mode, the _RISC-V Debug Specification_ does not specify
142+
how the PC is updated, and says that PC-relative instructions may be illegal. This concept
142143
is extended to include any instruction which reads or updates <<pcc>>, which refers to
143144
all jumps, conditional branches and <<AUIPC_CHERI>>. The exceptions are <<MODESW_CAP>> and <<MODESW_INT>>,
144145
which _are_ supported if {cheri_default_ext_name} is implemented, see <<drootc>>
@@ -151,13 +152,21 @@ instruction execution.
151152

152153
On debug mode entry, <<dpc_y>> is updated with the
153154
capability in <<pcc>> whose address field is set to the address of the next
155+
On debug mode entry, <<dpc_y>> is updated with the
156+
capability in <<pcc>>, whose address field equals to the address of the next
154157
instruction to be executed upon debug mode exit as described in the _RISC-V Debug Specification_.
155158

156-
When leaving debug mode, an unsealed capability value is copied from the value in <<dpc_y>> and written into <<pcc>>.
157-
A debugger may write <<dpc_y>> to change where the hart resumes and its mode, permissions, sealing or bounds.
159+
When leaving debug mode, the value in <<dpc_y>> is unsealed if it is a <<sentry_cap>> and is written to <<pcc>>.
160+
161+
NOTE: A debugger may write <<dpc_y>> to change where the hart resumes and its mode, permissions, sealing or bounds.
162+
The value saved from the <<pcc>> on debug mode entry cannot be sealed.
158163

159164
The legalization of <<dpc_y>> follows the same rules described for <<mepc_y>>.
160165

166+
One possible implementation choice for debug mode exit is DRET.
167+
168+
include::insns/dret.adoc[leveloffset=+1]
169+
161170
[#dscratch0_y,reftext="dscratch0 ({cheri_base_ext_name})"]
162171
==== Debug Scratch Register 0 (dscratch0)
163172

@@ -219,11 +228,6 @@ The <<p_bit>> of this capability is _only_ updated by executing <<MODESW_CAP>> o
219228
.Debug root capability register
220229
include::img/drootcreg.edn[]
221230

222-
==== Modified Trap-Return Instruction Behavior
223-
The <<DRET_CHERI>> instruction reads the full YLEN bits of the <<mepc_y>>/<<sepc_y>> register and unseals it prior to exception return if it is a <<sentry_cap>>.
224-
225-
include::insns/dret.adoc[leveloffset=+1]
226-
227231
[#section_hybrid_debug_integration]
228232
=== Integrating {cheri_default_ext_name} with Sdext
229233

src/cheri/insns/dret.adoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ Encoding::
1313
include::wavedrom/dret.adoc[]
1414

1515
Description::
16-
<<DRET_CHERI>> returns from debug mode. It unseals <<dpc_y>> and writes the result into
17-
<<pcc>>.
16+
<<DRET_CHERI>> returns from debug mode.
17+
It unseals <<dpc_y>> if it is sealed as a <<sentry_cap>> and writes the result into <<pcc>>.
18+
It also restores <<ddc>> from <<dddc>>.
1819

1920
NOTE: The <<DRET_CHERI>> instruction is a documented method of exiting debug mode.
2021
However, it is a pseudoinstruction to return that technically does not execute
21-
from the program buffer or memory. It currently does not require the <<pcc>> to
22+
from the program buffer or memory. It does not require the <<pcc>> to
2223
grant <<asr_perm>> so it never raises an exception.
2324

2425
NOTE: The definition of `DRET` is not part of Sdext, and is a suggested as an implementation choice in the _RISC-V Debug Specification_.

0 commit comments

Comments
 (0)