Current running mode
First identify whether the hart is executing in U, S, or M privilege mode. Delegation eligibility, the CSR bank written, and the return mode all depend on this context.
Ordinary programs cannot directly manage every hardware resource. The RISC-V privileged architecture uses privilege modes to separate software layers, and traps hand exceptions, interrupts, and environment calls to a handler determined by the privileged architecture, current privilege mode, and delegation configuration.
The animation only teaches general trap behavior confirmed by the RISC-V Privileged Architecture Manual; timer, interrupt-controller, SBI, and Linux paths are only marked as simplified boundaries in related demos.
To learn RISC-V privilege architecture, start with two ideas: statically, software runs in different privilege modes; dynamically, exceptions, interrupts, and environment calls use traps to hand control to a handler selected by the current privilege mode and delegation configuration, then MRET or SRET returns.
This is the common U/S/M learning view; U-mode and S-mode presence depends on the implementation and extensions, and virtualization-related layers are not expanded here.
All demo animations share this backbone: identify the current privilege mode, recognize the trap cause, choose the target layer by delegation and privilege rules, record architectural state, enter the handler, and return.
First identify whether the hart is executing in U, S, or M privilege mode. Delegation eligibility, the CSR bank written, and the return mode all depend on this context.
A synchronous exception comes from the current instruction, such as ECALL, an illegal instruction, or a page fault; an asynchronous interrupt is taken when enable and priority conditions allow it. Both use the trap mechanism.
Delegable traps occurring below M-mode can be routed to S-mode by medeleg/mideleg; non-delegated, non-delegable, or M-mode traps enter M-mode.
Hardware writes the target level's xepc and xcause, and xtval when applicable; it also updates xstatus fields for the previous privilege mode and interrupt enable used by xRET.
The PC jumps to the Direct or Vectored entry from mtvec/stvec. After the handler runs, MRET/SRET resumes execution according to the current xepc and xstatus return state, which software may have adjusted.
The RISC-V privileged architecture defines trap entry, architectural state recording, and xRET return; syscall ABI, handler code, and scheduling policy belong to the OS, firmware, or execution environment.
Hardware records only the trap state specified by the architecture. Full register context and thread-state save/restore are usually software work.
medeleg/mideleg can route eligible traps that occur below M-mode to S-mode. They do not change the trap's cause code or turn OS policy into hardware behavior.