What are privileged instructions, and why can they only run in kernel mode?
Last updated
Privileged instructions are machine instructions that can affect the whole system (I/O, memory mapping, halting the CPU), so the hardware restricts them to kernel mode to prevent a user program from corrupting or hijacking the machine.
What they are: Instructions that manage hardware or global state: setting the interrupt vector, loading page-table registers, direct device I/O, masking interrupts, halting the CPU.
The dual-mode mechanism:
The CPU has a mode bit: kernel mode (0) and user mode (1). Privileged instructions are only allowed when the bit says kernel mode.
Attempting one in user mode raises a trap (exception), transferring control to the OS instead of executing it.
Why the restriction exists:
Protection: one buggy or malicious process must not disable interrupts, remap another process's memory, or crash the system.
Isolation and fairness: the OS stays in control of resources and can enforce scheduling and access rules.
How user code still uses them: Via a system call: a controlled trap that switches to kernel mode, runs the privileged operation on the program's behalf, then returns to user mode.
- https://dev.to/adityabhuyan/understanding-privileged-instructions-in-x86-architecture-5fmg
- https://testbook.com/question-answer/the-hardware-allows-privileged-instructions-to-be--5ef5d70bb5ca250d06520da3
- https://aditya-sunjava.medium.com/understanding-privileged-instructions-in-x86-architecture-6125d8db4185
- https://www.geeksforgeeks.org/operating-systems/privileged-and-non-privileged-instructions-in-operating-system/
- https://algomaster.io/learn/operating-systems/privilege-levels