dret
Return from Debug Mode
This instruction is defined by:
Synopsis
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.PRVanddcsr.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; if the new mode is VU, also clears vsstatus.
-
If Zicfilp is implemented, sets
ELPtodcsr.PELPif Zicfilp is enabled (xLPE=1) in the new privilege mode, otherwise toNO_LP_EXPECTED, and then clearsdcsr.PELP. -
Leaves Debug Mode.
Execution
-
Pruned, XLEN == 64
-
Original
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
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;
}
}
if (implemented?(ExtensionName::Zicfilp)) {
CSR[dcsr].PELP = 1'b0;
}
set_mode(new_mode);
$pc = $bits(CSR[CSR[dpc]]);