Webcentive RISC-V Reference

mnret

Machine mode resume from the RNMI or Double Trap handler

Extension
Smrnmi
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
mnret
Length
32-bit

Encoding

3120191514121176210
01110000001000000000000001110011

Match 0x70200073, mask 0xffffffff. Source: mnret 11..7=0 19..15=0 31..20=0x702 14..12=0 6..2=0x1C 1..0=3 in riscv-opcodes/extensions/rv_smrnmi.

Description

MNRET is an M-mode-only instruction that uses the values in mnepc and mnstatus to return to the program counter, privilege mode, and virtualization mode of the interrupted context. This instruction also sets mnstatus.NMIE. If MNRET changes the privilege mode to a mode less privileged than M, it also sets mstatus.MPRV to 0. If the Zicfilp extension is implemented, then if the new privileged mode is y, MNRET sets ELP to the logical AND of yLPE (see Section 22.1.1) and mnstatus.MNPELP.

Description from riscv-unified-db, reformatted.

Operation

if (CSR[mnstatus].MNPP != 2'b11) {
  if (implemented?(ExtensionName::U)) {
    CSR[mstatus].MPRV = 0;
  }
  if (implemented?(ExtensionName::Smdbltrp)) {
    if (xlen() == 64) {
      CSR[mstatus].MDT = 1'b0;
    } else {
      CSR[mstatush].MDT = 1'b0;
    }
  }
}
CSR[mnstatus].NMIE = 1'b1;
if (CSR[mnstatus].MNPP == 2'b00) {
  set_mode(PrivilegeMode::U);
} else if (CSR[mnstatus].MNPP == 2'b01) {
  set_mode(PrivilegeMode::S);
} else if (CSR[mnstatus].MNPP == 2'b11) {
  set_mode(PrivilegeMode::M);
}
CSR[mnstatus].MNPP = implemented?(ExtensionName::U) ? 2'b00 : 2'b11;
$pc = CSR[mnepc].sw_read();

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages