Return from Debug Mode
Resumes execution after Debug Mode. `dret` is only legal in Debug Mode; executing it in any other mode raises an Illegal Instruction exception.
When executed in Debug Mode, `dret`:
. Sets the PC to the value in `dpc`. . Changes the privilege and virtualization mode to those held in `dcsr.PRV` and `dcsr.V`. . If the new privilege mode is less privileged than M-mode, clears `mstatus.MPRV`. . If Smdbltrp is implemented and the new privilege mode is less privileged than M-mode, clears `mstatus.MDT`. . If Ssdbltrp is implemented and the new privilege mode is U, VS, or VU, clears `sstatus.SDT`; if the new mode is VU, also clears `vsstatus.SDT`. . If Zicfilp is implemented, sets `ELP` to `dcsr.PELP` if Zicfilp is enabled (`xLPE`=1) in the new privilege mode, otherwise to `NO_LP_EXPECTED`, and then clears `dcsr.PELP`. . Leaves Debug Mode.
dret
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1111 | 0 | 11 | 00 | 1 | 00000000000000 | 111 | 00 | 11 | ||||||||||||||||||||||
# UDB does not yet model Debug Mode state, so the hart can never be in Debug
# Mode and dret is always illegal, regardless of privilege mode.
# TODO: once Debug Mode is modeled, raise this only when the hart is not in
# Debug Mode.
raise (ExceptionCode::IllegalInstruction, mode(), $encoding);
# determine the resume mode from dcsr.PRV/dcsr.V
PrivilegeMode new_mode = PrivilegeMode::M;
if (CSR[dcsr].PRV == 2'b11) {
new_mode = PrivilegeMode::M;
} else if (CSR[dcsr].PRV == 2'b01) {
new_mode = PrivilegeMode::S;
if (implemented?(ExtensionName::H)) {
if (CSR[dcsr].V == 1'b1) {
new_mode = PrivilegeMode::VS;
}
}
} else if (CSR[dcsr].PRV == 2'b00) {
new_mode = PrivilegeMode::U;
if (implemented?(ExtensionName::H)) {
if (CSR[dcsr].V == 1'b1) {
new_mode = PrivilegeMode::VU;
}
}
} else {
unpredictable("dcsr.PRV holds a reserved encoding; the hart may resume in any supported privilege mode");
}
if (new_mode != PrivilegeMode::M) {
if (implemented?(ExtensionName::U)) {
CSR[mstatus].MPRV = 0;
}
if (implemented?(ExtensionName::Smdbltrp)) {
CSR[mstatus].MDT = 1'b0;
}
}
# TODO: Ssdbltrp: if new_mode is U, VS, or VU, clear sstatus.SDT; if new_mode
# is VU, also clear vsstatus.SDT. UDB does not yet define the SDT fields.
if (implemented?(ExtensionName::Zicfilp)) {
# TODO: set ELP to dcsr.PELP if xLPE is enabled for new_mode, otherwise to
# NO_LP_EXPECTED. UDB does not yet model the ELP state, so this restore
# must happen before dcsr.PELP is cleared below once it is added.
CSR[dcsr].PELP = 1'b0;
}
set_mode(new_mode);
$pc = $bits(CSR[dpc]);
Sdext
| S | U | VS | VU |
|---|---|---|---|
| Never | Never | Never | Never |
Version af3eaf9+cheriot.f635218
Data from the RISC-V Unified Database, copyright RISC-V International and contributors.
CHERIoT extensions from the CHERIoT specification and Sail model, copyright Microsoft and the CHERIoT Platform contributors.
This site is provided as a community resource and is NOT affiliated with nor endorsed by RISC-V International.