Process Control
The less-privileged mode is often referred to as the user mode, because user programs typically would execute in this mode. The more-privileged mode is referred to as the system mode, control mode or kernel mode.
Modes of Execution Most processors support at least two modes of execution. Certain instructions can only be executed in the more privileged mode. These include reading or altering a control register, such as the program status word; primitive I/O instructions; and instructions that related to memory management. And certain regions of memory can only be accessed in more privileged mode.
User mode: less privileged mode, because user programs typically would execute in this mode.
Kernel mode: more privileged mode (system mode, control mode orKernel mode).
Reason for two modes
The reason for using two modes should be clear. It is necessary to protect the OS and key operating system tables, such as process control blocks, from interfer- ence by user programs. In the kernel mode, the software has complete control of the processor and all its instructions, registers, and memory. This level of control is not necessary and for safety is not desirable for user programs.
How does the processor know in which mode it is to be executing and how is the mode changed?
There is typically a bit in the program status word (PSW) that indicates the mode of execution. This bit is changed in response to certain events. When a user makes a call to an OS service or when an interrupt triggers execution of an OS routine, the mode is set to user mode. Most operating systems, such as Linux, use level 0 for the kernel and one other level for user mode. When an interrupt occurs, the processor clears most of the bits in the psr, including the cpl field. This automatically sets the cpl to level 0. At the end of the interrupt-handling routine, the final instruction that is executed is irt (interrupt return). This instruction causes the processor to restore the psr of the interrupted program, which restores the privilege level of that program.