FOR FREE CONTENT

Dual mode of operation:

 

In the hardware level, the instructions are executed by using dual-mode operation.

 

(i) User mode (Non privileged mode) (ii) Kernel Mode (Privileged mode)

 

The dual-mode operation is used to provide protection and security to the user program and also to the operating system. Actually, the operating system decides the instruction has to be executed in which particular mode. 

 

  • Mode bit is required to identify in which particular mode the current instruction is executing.
  •  
  • If mode bit is 1, it operates user mode. On the other hand, it operates in kernel mode when the mode bit is 0.
  •  
  • At the booting time of the system, it always starts with the kernel mode.

 

Important point:

 

  • The mode switching takes very less time compared to the process switching require because mode switching does not require saving a lot of attributes, unlike process switching.

 

Kernel Mode (Privileged Mode): 

The lowest level of the system is Kernel mode where processes are granted privileged access to the unrestricted hardware, processor, and most trusted functions of the operating system. Therefore, all machine instructions are allowed and system memory is accessible. The privileged processor mode is called kernel mode and the non-privileged processor mode is called user mode. Usually, operating systems execute in kernel mode only and application programs execute in user mode only, except when they call operating system services.

 

Privileged Instructions:

Examples: I/O operations, Context Switching, Disabling/Enabling interrupt, Interrupt service routine, clearing the memory, set the time of the clock, changing memory map.

 

User mode (Non Privileged Mode):

When the operating system is running a user application (except any request for OS services), the system is in user mode. But in user mode processes are not granted privileged access to the processor, memory, and other devices. Code running in user mode must envoy to system APIs to access hardware or memory. Therefore, certain instructions are not allowed and system memory isn’t accessible.

 

Non privileged Instructions:

Example:  Generate Trap, User to Kernel mode switch, Reading the states of the CPU, Reading the time of the clock, etc.

 

Difference Between User mode and Kernel Mode

The difference between kernel mode and user mode provides an elementary form of protection in the following manner. Certain instructions could be executed only when the CPU is in kernel mode. 

 

Similarly, hardware devices could be accessed only when the program is executing in kernel mode. Control over when interrupts could be abled or disabled is also possible only when the CPU is in kernel mode. 

 

Consequently, the CPU has very limited capability when executing in user mode, thereby enforcing the protection of critical resources. The processor switches (by Dispatcher) between the two modes depending on what type of code is running on the processor. Applications run in user mode, and core operating system components run in kernel mode. 

 

Fig 5: Kernel mode and User mode