What is the main difference between SRET and MRET?
SRET restores supervisor trap-return state using sepc and SPP/SPIE; MRET restores machine trap-return state using mepc and MPP/MPIE.
Supervisor trap return: pc<-sepc, privilege<-sstatus.SPP, SIE<-SPIE; in S-mode, TSR=1 makes SRET raise an illegal-instruction exception.
SRET is the privileged return instruction used by a supervisor trap handler. It sets pc to sepc, restores the current privilege mode from sstatus.SPP, restores SIE from SPIE, sets SPIE to 1, and clears SPP. SRET may execute in S-mode or a higher privilege mode; if mstatus.TSR=1, S-mode execution raises an illegal-instruction exception, and U-mode execution also raises an illegal-instruction exception.
Starts from the fixed SYSTEM encoding, then shows xRET permission checks, EPC-to-PC restoration, and previous interrupt-enable / previous privilege field updates.
This animation shows only privileged-architecture ISA-visible return state; it does not simulate OS scheduling, handler body, pipeline behavior, latency, or platform policy.
SRET restores the return context saved for a supervisor trap handler: 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.
Understand this scenario with real code like «sret # Return from S-mode trap».
SRET restores supervisor trap-return state using sepc and SPP/SPIE; MRET restores machine trap-return state using mepc and MPP/MPIE.
When mstatus.TSR=1 and SRET is executed in S-mode, the specification requires an illegal-instruction exception instead of completing the return.