MNRET

RISC-V MNRET Instruction Details

Instruction ManualI-type

Return from an Smrnmi RNMI handler: restore pc from mnepc and privilege/virtualization state from mnstatus.

Instruction Syntax

mnret
Operand Breakdown
MNRET has no explicit assembly operands; it uses a fixed SYSTEM I-type encoding.
imm[11:0] is fixed to 011100000010, with rs1=x0, funct3=000, rd=x0, and opcode=1110011.
mnepc, mnstatus, and mstatus are implicit architectural state, not assembly register or immediate operands.
PrivilegedSmrnmiSystem & Privilege

Instruction Behavior

MNRET is the M-mode-only return instruction added by Smrnmi. It uses mnepc and mnstatus to return to the interrupted program counter, privilege mode, and virtualization mode, sets mnstatus.NMIE, and clears mstatus.MPRV if returning below M-mode.

MNRET Decode And Return Animation

Shows only Smrnmi-defined mnepc, MNPP/MNPV, NMIE, and conditional MPRV state.

mnret
31..20
19..15
14..12
11..7
6..0
011100000010
funct12
00000
rs1=x0
000
funct3
00000
rd=x0
1110011
SYSTEM
instruction
0x70200073
permission
M-mode -> execute
mnepc
0x0000000000008042 -> 0x0000000000008040 (bit 1 masked)
mnstatus
MNPP=S, MNPV=0 -> S
architectural state
pc=0x0000000000008040; mode=S; NMIE=1; MPRV=0

Quick Understanding & Search Notes

MNRET is a system-level instruction defined by the privileged architecture. This page covers architectural semantics only, not platform firmware policy.

MNRET is M-mode only and requires Smrnmi.
It restores PC from mnepc, restores MNPV/MNPP from mnstatus, and sets NMIE to 1.
When MNPP is less privileged than M, MNRET clears mstatus.MPRV.

Common Usage Scenarios

OS Interface

Understand this scenario with real code like «mnret # Return from NMI handler».

System & Privilege

Understand this scenario with real code like «mnret # Return from NMI handler».

Pre-Use Checklist

Syntax Check
  • Verify the immediate field is within the valid range.
  • Confirm source register rs1 points to the correct operand.
Semantic Check
  • Check if the immediate sign-extension matches expectations.
  • Ensure the result register rd has a clear purpose.

Pitfalls / Common Confusions

Requires Smrnmi and is M-mode only.
It is for resumable non-maskable interrupt handlers, not a general trap return.
MRET and SRET are unaffected by mnstatus.NMIE; use MNRET to resume from RNMI.

FAQ

Does MNRET change MRET or SRET?

No. MRET and SRET are unaffected by mnstatus.NMIE and do not change it; MNRET performs the RNMI return.

When does MNRET clear MPRV?

MNRET clears mstatus.MPRV when mnstatus.MNPP specifies a return privilege mode below M-mode.