What is the main difference between SRET and MRET?
On the V=0 base path, SRET uses sepc and SPP/SPIE while MRET uses mepc and MPP/MPIE. Virtualized SRET additionally follows the dedicated hstatus/vsstatus/vsepc rules.
Supervisor trap return: without H, restore PC, mode and SIE from sepc and SPP/SPIE, clear SPP and set SPIE; TSR restricts S-mode execution.
Extension condition: Requires S-mode; executable in S-mode or M-mode. H adds separate VS/VU return and VTSR rules.
SRET has no explicit operands and is encoded as 0x10200073. Without H, sstatus.SPP selects U (0) or S (1); SIE←SPIE, SPIE←1, SPP←0, PC←sepc, and mstatus.MPRV is cleared. sepc[0] is always zero; on implementations with switchable IALIGN, the implicit read masks bit 1 at IALIGN=32. S-mode execution with TSR=1 raises an illegal-instruction exception. M-mode is not constrained by that TSR check; execution below S is illegal. With H, V=0 selects the return mode from hstatus.SPV/SPP and clears SPV; V=1 uses vsstatus/vsepc. VTSR and extension-conditioned state rules still apply.
Starts from the fixed SYSTEM encoding and shows the V=0 base SRET permission check, sepc-to-PC restoration, and SPP/SPIE state updates.
This SRET animation assumes U/S/M and models only V=0 without H. Input is the stored XLEN-bit sepc with bit 0 zero; the implicit read masks bit 1 at IALIGN=32. A successful return clears MPRV. It does not model hstatus.SPV, VS-mode vsstatus/vsepc, VTSR, or extension-conditioned SDT/ELP state, and must not be used as a virtualized-return model.
Supervisor trap return: without H, restore PC, mode and SIE from sepc and SPP/SPIE, clear SPP and set SPIE; TSR restricts S-mode execution.
Assume no H, U/S/M implemented, switchable IALIGN, execution in S with TSR=0, sepc=0x4042, IALIGN=32, SPP=U and SPIE=1: sret sets PC=0x4040, mode U, SIE=1, SPIE=1, SPP=0 and MPRV=0. Extension state such as SDT/ELP is omitted.
On the V=0 base path, SRET uses sepc and SPP/SPIE while MRET uses mepc and MPP/MPIE. Virtualized SRET additionally follows the dedicated hstatus/vsstatus/vsepc rules.
When mstatus.TSR=1 and SRET is executed in S-mode, the specification requires an illegal-instruction exception instead of completing the return.