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: on the V=0 base path pc<-sepc, privilege is restored from sstatus.SPP, and SIE<-SPIE; in S-mode, TSR=1 raises an illegal-instruction exception. Virtualized paths instead follow the hstatus/vsstatus/vsepc rules.
SRET is the supervisor trap-return instruction. On the non-virtualized V=0 path it first determines the return mode from hstatus.SPV and sstatus.SPP, then clears hstatus.SPV and SPP, sets SIE<-SPIE and SPIE<-1, and finally sets pc<-sepc; without H this reduces to the usual SPP/SPIE/sepc restore. The V=1 VS-mode path instead uses vsstatus.SPP/SPIE and vsepc. With mstatus.TSR=1, execution in S-mode raises an illegal-instruction exception; executing an xRET below its privilege mode also raises an illegal-instruction exception.
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 models only the V=0 base path without H virtualization. It does not model hstatus.SPV, VS-mode vsstatus/vsepc, VTSR, or Ssdbltrp state, and must not be used as a virtualized-return model.
On the V=0 path, SRET restores a trap handler's saved return context: PC comes from sepc, return privilege from SPP, and interrupt enable from SPIE. TSR can make SRET in S-mode trap as an illegal instruction; VS-mode uses its dedicated vsepc/vsstatus rules.
Understand this scenario with real code like «sret # Return from S-mode trap».
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.