| This document is a specification snapshot built from github.com/riscv/riscv-cheri/commit/ce97d508c546047176b7e81a37de8839f21247cd and is not a versioned release. The latest versioned PDF release can be downloaded from github.com/riscv/riscv-cheri/releases. |
|
This document is in the Stable state
Assume anything could still change, but limited change should be expected. |
1. Integrating RVY with Debug
1.1. Integrating RVY with Sdtrig
The Sdtrig extension is orthogonal to RVY. However, the priority of synchronous exceptions and where triggers fit is adjusted as shown in Table 1.
Debug triggers are higher priority than CHERI exceptions to allow debug.
| Priority | Exception Code | Description | Trigger |
|---|---|---|---|
Highest |
3 |
etrigger |
|
3 |
Instruction address breakpoint |
mcontrol/mcontrol6 execute address before |
|
32 |
Prior to instruction address translation: |
||
12, 20, 1 |
During instruction address translation: First encountered page fault, guest-page fault, or access fault |
||
1 |
With physical address for instruction: Instruction access fault |
||
3 |
mcontrol/mcontrol6 execute data before |
||
2 |
Illegal instruction |
mcontrol/mcontrol6 load/store address before, store data before |
|
33,34 |
Prior to address translation for an explicit memory access: |
||
4,6 |
Load/store/AMO capability address misaligned |
||
4, 6 |
Optionally: Load/Store/AMO address misaligned |
||
36, 13, 15, 21, 23, 5, 7 |
During address translation for an explicit memory access: First encountered CHERI Store/AMO Page Fault, page fault, guest-page fault, or access fault |
||
5, 7 |
With physical address for an explicit memory access: Load/store/AMO access fault |
||
4, 6 |
If not higher priority: Load/store/AMO address misaligned |
||
35 |
CHERI Load Capability Fault |
||
Lowest |
3 |
mcontrol/mcontrol6 load data before |
1.2. Integrating RVY with Sdext
RVY harts must provide a means for accessing capabilities in registers and in memory via the external debugger.
This is achieved by supporting at least one of:
-
Implementing a program buffer configured as specified below.
-
Supporting full capability access for both Access Register and Access Memory abstract commands (
aarsize=7andaamsize=7).
1.2.1. Program Buffer
If a Program Buffer is implemented, this section shows how it can be configured and used to access capabilities.
-
hartinfomust be implemented. -
hartinfo.nscratchis at least 1 and the dscratch0 (RVY) register is implemented. -
hartinfo.datasizeis at least 1 andhartinfo.dataaccessis 0. -
abstractcs.progbufsizeis at least 4 ifdmstatus.impebreakis 1, or at least 5 ifdmstatus.impebreakis 0.
|
These requirements allow a debugger to read and write capabilities in integer registers without disturbing other registers. These requirements may be relaxed if abstract commands support full capability access. The sequences below demonstrate how a debugger can read and write a capability in
The low The above instruction sequences utilize these guarantees provided by the RISC-V Debug Specification:
|
1.2.2. Abstract Commands
Abstract commands are optionally extended to access full capabilities.
aarsize/aamsize=7 represent full capability access.
When a capability is written via an abstract command it must be derivable from the set of root capabilities available in drootc. If not then the destination capability tag is set to zero.
The data<n> register mapping for full capability accesses is as shown in Table 2.
| ISA | arg0/return value | arg11 | arg22 | capability tag |
|---|---|---|---|---|
RV32Y |
data0,data1 |
data2 |
data3,data4 |
data5 |
RV64Y |
data0-data3 |
data4,data5 |
data6-data9 |
data10 |
1 arg1 represents an address so never needs to exceed DXLEN.
Each data<n> register is 32-bit so a maximum of 2 are required.
2 arg2 is not used for abstract commands, and is included for consistency with the equivalent table in the RISC-V Debug Specification
Bit 0 of data5 or data10 contain the capability tag which is either written to, or read from, the target register.
All other bits in that data register are UNSPECIFIED.
1.2.3. Access Register Command
When a YLEN-wide register is accessible via an Access Register abstract command, then:
-
Reads of YLEN bits or any smaller amounts of bits must be supported.
-
Writes of YLEN bits must be supported.
-
Writes of smaller amounts of bits than YLEN may optionally be supported but it is UNSPECIFIED what happens to the higher bits.
| The debugger can change the low XLEN bits of a YLEN wide register by performing a read-modify-write sequence. |
The requirement to support YLEN-wide access mandates that enough data<n> registers are implemented to cover the entire YLEN bit-width (at least 2 for RV32Y or at least 4 for RV64Y).
Implementations can choose to also support accessing capability tags as part of the access register command by supporting aarsize=7.
| If there is only a single root capability, then the derivable check is a capability subset of the written capability against the capability in drootc. If there are multiple root capabilities then checks against multiple root capabilities may be required, as defined by the capability encoding format. |
If aarsize≠7 then capability tags are always read and written as zero.
For the capability subset: cap2 is the capability being written and cap1 is the value of drootc.
|
| It is valid for root capabilities not to cover the entire possible address space. In this case the debugger cannot claim access to more memory than is permitted by the current value of drootc. |
1.2.4. Access Memory Command
Implementations can choose to support accessing full capabilities, including the capability tags, via the Access Memory abstract command. Full capability access is denoted by aamsize=7 and uses the data<n> register assignments specified in Table 2.
If aamsize≠7 then capability tags are always read and written as zero.
1.2.5. Core Debug Registers
RVY widens debug CSRs that are designated to hold addresses so that they can hold capabilities.
1.2.5.1. Debug Program Counter Capability (dpc)
The dpc register is widened to a capability.
The reset value of the capability tag of this CSR is zero, the reset values of the metadata and address fields are UNSPECIFIED.
When the hart is in debug mode, the RISC-V Debug Specification does not specify
how the pc is updated, and says that PC-relative instructions may be illegal. This concept
is extended to include any instruction which reads or updates PC, which refers to
all jumps, conditional branches and AUIPC. The exceptions are YMODESWY and YMODESWI,
which are supported if Zyhybrid is implemented, see drootc
for details.
As a result, the value of the pc is UNSPECIFIED in debug mode according
to this specification. The pc metadata has no architectural effect in debug
mode. Therefore, ASR-permission is implicitly granted for access to all CSRs for
instruction execution.
On debug mode entry, dpc (RVY) is updated with the
capability in the pc, whose address field equals to the address of the next
instruction to be executed upon debug mode exit as described in the RISC-V Debug Specification.
When leaving debug mode, the value in dpc (RVY) is unsealed if it is a Sealed entry point capability and is written to PC.
A debugger may write dpc (RVY) to change where the hart resumes and its mode, permissions, sealing or bounds.
The value saved from the pc on debug mode entry cannot be sealed.
|
The legalization of dpc (RVY) follows the same rules described for mepc.
One possible implementation choice for debug mode exit is DRET.
1.2.5.2. Debug Scratch Register 0 (dscratch0)
The dscratch0 register is widened to a capability.
The reset value of the capability tag of this CSR is zero, the reset values of the metadata and address fields are UNSPECIFIED.
1.2.5.3. Debug Scratch Register 1 (dscratch1)
The dscratch1 register is widened to a capability.
The reset value of the capability tag of this CSR is zero, the reset values of the metadata and address fields are UNSPECIFIED.
1.2.5.4. Debug Root Capability Selector (drootcsel)
drootcsel is a DXLEN-bit debug mode accessible integer CSR. The address and access details are shown in Table 5.
It selects which Root capability is exposed through drootc.
The reset value is 0, which must cause drootc to expose a
Root Executable capability.
Other capability values may be defined for exposure through drootc by the capability encoding, and may be selected by having the debugger write to this register. Writes are WARL, so the debugger may confirm that its selection has been applied.
1.2.5.5. Debug Root Capability Register (drootc)
drootc is a debug mode accessible capability CSR. The address and access details are shown in Table 5. It exposes the capability selected by drootcsel.
drootc is DRW; writes are ignored (WARL with no writable fields).
If Zyhybrid is implemented,
the Root Executable exposed when drootcsel is 0 is further specified as follows:
-
The
P-bitis reset to Integral Pointer Mode (1). -
The debugger can set the
P-bitto Capability Pointer Mode (0) by executingYMODESWYfrom the program buffer.-
Executing
YMODESWYcauses execution of subsequent instructions from the program buffer, starting from the next instruction, to be executed in Capability Pointer Mode. It also sets the CHERI Pointer Mode to Capability Pointer Mode on future entry into debug mode. -
Therefore, to enable use of a CHERI debugger, only a single
YMODESWYneeds to be executed once from the program buffer after resetting the core. -
The debugger can also execute
YMODESWIto change the CHERI Pointer Mode back to Integral Pointer Mode. This affects the execution of the next instruction in the program buffer, updates theP-bitof drootc, and thereby controls which CHERI Pointer Mode to use on the next entry into debug mode.
-
The P-bit of this capability is only updated by executing YMODESWY or YMODESWI from the program buffer.
1.2.5.6. DRET (RVY)
- Synopsis
-
Debug Return (DRET)
- Mnemonic
-
dret - Encoding
The DRET instruction is a documented method of exiting debug mode.
However, it is a pseudoinstruction to return that technically does not execute
from the program buffer or memory. It does not require the pc to
grant ASR-permission so it never raises an exception.
|
The definition of DRET is not part of Sdext, and is suggested as an implementation choice in the RISC-V Debug Specification.
This specification assumes the recommended specification including the recommended encoding.
|
- Prerequisites
-
RVY
- Operation
SAIL TO BE UPDATED
1.3. Integrating Zyhybrid with Sdext
A new debug default data capability (dddc) CSR is added.
Zyhybrid allows YMODESWY and YMODESWI to execute in debug mode.
When entering debug mode, whether the core enters Integral Pointer Mode or
Capability Pointer Mode is controlled by the P-bit in the drootc capability selected by drootcsel value 0.
The following sequence executed from the program buffer will write 0 for Capability Pointer Mode and 1 for Integral Pointer Mode to x1:
csrr x1, drootc
ymoder x1, x1
| There is no CHERI enable/disable bit for debug mode, so CHERI register and instruction access is always permitted. |
1.3.1. Debug Default Data Capability CSR (dddc)
dddc is a debug mode accessible capability CSR.
The reset value of the capability tag of this CSR is zero, the reset values of the metadata and address fields are UNSPECIFIED.
This CSR is only implemented if Zyhybrid is implemented.
Upon entry to debug mode, ddc is saved in dddc. ddc is set to a
Root Data capability with an unchanged address.
If the Root Data capability does not cover all of memory then ddc must be updated using the semantics of YADDRW.
|
When debug mode is exited by executing DRET (RVY), the hart’s ddc is updated to the capability stored in dddc.
When debug mode is exited the hart’s ddc is updated to the capability stored in dddc, which may have been updated by the debugger.
A debugger may write dddc to change the hart’s context.
1.4. Debug Mode YLEN CSR Summary
The tables below show all debug mode CSRs added or modified by RVY.
| RVY CSR | Extension | Width | Action on XLEN write | Action on YLEN write |
|---|---|---|---|---|
Sdext |
YLEN |
Apply invalid address conversion.
Always update the CSR with |
Apply invalid address conversion and update the CSR with the result if the address changed, direct write if address didn’t change |
|
Sdext |
YLEN |
Update the CSR using |
Direct write |
|
Sdext |
YLEN |
Update the CSR using |
Direct write |
|
Sdext, Zyhybrid |
YLEN |
Apply invalid address conversion.
Always update the CSR with |
Apply invalid address conversion and update the CSR with the result if the address changed, direct write if address didn’t change |
|
Sdext |
YLEN |
Ignore |
Ignore |
Code pointers and data pointers in Table 4 are WARL CSRs that do not need to store full 64-bit addresses on RV64, and so may be subject to invalid address conversion on writing.
| RVY CSR | Extension | Code Pointer | Data Pointer | Unseal On Execution |
|---|---|---|---|---|
Sdext |
✔ |
✔ |
||
Sdext, Zyhybrid |
✔ |
Table 5 shows all debug-mode CSRs added or modified by RVY.
| RVY CSR | Extension | Width | Address | Permissions | Reset Value | Description |
|---|---|---|---|---|---|---|
Sdext |
YLEN |
0x7b1 |
DRW |
tag=0, otherwise specified by the platform |
Debug Program Counter Capability |
|
Sdext |
YLEN |
0x7b2 |
DRW |
tag=0, otherwise specified by the platform |
Debug Scratch Capability 0 |
|
Sdext |
YLEN |
0x7b3 |
DRW |
tag=0, otherwise specified by the platform |
Debug Scratch Capability 1 |
|
Sdext, Zyhybrid |
YLEN |
0x7bc |
DRW |
tag=0, otherwise specified by the platform |
Debug Default Data Capability (saved/restored on debug mode entry/exit) |
|
Sdext |
DXLEN |
0x7ba |
DRW |
0 |
Multiplexing selector for drootc |
|
Sdext |
YLEN |
0x7bd |
DRW |
nominally Root Executable |
Source of authority in debug mode, writes are ignored |
| Where reset values are specified as a Root Executable or Root Data Capability they are the maximum possible value. The platform may reset those CSRs to a smaller memory range, or to have fewer permissions. |