- The mode (sometimes called privilege level or ring) a processor is in controls what it’s allowed to do
- Modern architectures have at least two options:
- kernel/ supervisor mode
- user mode
Kernel mode
In kernel mode, anything goes
The kernel has near-full access to your computer’s memory, peripherals, and other resources, and is in charge of running software installed on your computer (known as userland programs).
User mode
In user mode, only a subset of instructions is allowed, I/O and memory access is limited, and many CPU settings are locked
Btw modes
- Generally, the kernel and drivers run in kernel mode while applications run in user mode
- Processors start in kernel mode. Before executing a program, the kernel initiates the switch to user mode
Modes from a hardware PoV
- On x86-64, the current privilege level (CPL) can be read from a register called
cs
(code segment). Specifically, the CPL is contained in the two least significant bits of thecs
register- Those two bits can store x86-64’s four possible rings: ring 0 is kernel mode and ring 3 is user mode. Rings 1 and 2 are designed for running drivers but are only used by a handful of older niche operating systems
- If the CPL bits are
11
, for example, the CPU is running in ring 3: user mode