Abstract
3 Modes
Machine Mode
- Free to do anything on the computer
Kernel Mode
User Mode
- Only a subset of Instruction is allowed, I/O and Main Memory access are limited, and many CPU settings are locked
- Applications run in this mode
- If application trying to access resources they don’t have access to like Main Memory they don’t have access to, Segmentation Fault will occur
Example
x86-64
- The privilege level can be read by CPU from a Registers called
cs
RISCV
- The privilege level of the current execution mode is stored in the
mstatus
, a Control & Status Registers (CSRs)
- Specifically, the mstatus.MPP (Mode Privilege Priority) field holds the current privilege level
- The mstatus.MPP field is a 2-bit field that can have the following values:
00
: User mode (U-mode)
01
: Supervisor mode (S-mode)
10
: Machine mode (M-mode)