mret

Machine Exception Return

This instruction is defined by:

  • Sm, version >= Sm@1.11.0

This instruction is included in the following profiles:

  • RVA23M64 (Mandatory)

  • RVB23M64 (Mandatory)

Encoding

svg

Assembly format

`mret `

Synopsis

Returns from an exception in M-mode.

Access

M HS U VS VU

Always

Never

Never

Never

Never

Decode Variables

Execution

  • IDL

  • Sail

if (%%LINK%csr_field;mstatus.MPP;CSR[mstatus].MPP%% != 2'b11) {
  %%LINK%csr_field;mstatus.MPRV;CSR[mstatus].MPRV%% = 0;
}
if (%%LINK%func;implemented?;implemented?%%(ExtensionName::Smdbltrp)) {
  if (%%LINK%func;xlen;xlen%%() == 64) {
    %%LINK%csr_field;mstatus.MDT;CSR[mstatus].MDT%% = 1'b0;
  } else {
    %%LINK%csr_field;mstatush.MDT;CSR[mstatush].MDT%% = 1'b0;
  }
}
%%LINK%csr_field;mstatus.MIE;CSR[mstatus].MIE%% = %%LINK%csr_field;mstatus.MPIE;CSR[mstatus].MPIE%%;
%%LINK%csr_field;mstatus.MPIE;CSR[mstatus].MPIE%% = 1;
if (%%LINK%csr_field;mstatus.MPP;CSR[mstatus].MPP%% == 2'b00) {
  %%LINK%func;set_mode;set_mode%%(PrivilegeMode::U);
} else if (%%LINK%csr_field;mstatus.MPP;CSR[mstatus].MPP%% == 2'b01) {
  %%LINK%func;set_mode;set_mode%%(PrivilegeMode::S);
} else if (%%LINK%csr_field;mstatus.MPP;CSR[mstatus].MPP%% == 2'b11) {
  %%LINK%func;set_mode;set_mode%%(PrivilegeMode::M);
}
%%LINK%csr_field;mstatus.MPP;CSR[mstatus].MPP%% = %%LINK%func;implemented?;implemented?%%(ExtensionName::U) ? 2'b00 : 2'b11;
$pc = $bits(CSR[mepc]);
{
  if   cur_privilege != Machine
  then { handle_illegal(); RETIRE_FAIL }
  else if not(ext_check_xret_priv (Machine))
  then { ext_fail_xret_priv(); RETIRE_FAIL }
  else {
    set_next_pc(exception_handler(cur_privilege, CTL_MRET(), PC));
    RETIRE_SUCCESS
  }
}