Protection is needed for any shared resources. There are two mode of operation to distinguish between the execution of operating-system code and user defined code:
(i) Kernel or supervisor or protected or privileged mode
(ii) User mode or non-privileged mode
Two modes are provided by the hardware - user and kernel mode. There is mode bit that indicate the current mode. Operating System runs in kernel mode and user programs run in user mode. The mode bit for user mode is 1 and for kernel mode is 0. When interrupt occurs, hardware switches to kernel mode.
When the process running in kernel mode, process has full access to machine instruction set and direct access to hardwares. Example : Set timer, clear memory, disable interrupts, access I/O devices. These process must run in kernel mode to ensure protection. Also, OS and device drivers must run in kernel mode.
Normal user defined processes run in user mode, but these process allow access to limited set of instructions, no direct access of hardware and hardware access is supported by Operating System. Example: Read clock, generate trap, user to kernel mode switch etc.