Operating System Modes - What, Differences, Necessity, Switch

Every Operating system supports two modes of operation for it to work properly.

  • User Mode
  • Kernel Mode
X86 Hardware provide four protection rings for these modes. Ring 0 is used for Kernel mode, Ring 3 is used for User mode

Differences




Kernel Mode
User Mode
Can Access any memory location, hardware resources
No direct access to memory and hardware resources
Crash will halt the system
Crash will stop the program that has bug, system will continue
Reserved for lowest-level functions such as memory allocation, file system handling, process handling etc
Most programs such as text editor, media player, browser etc
Necessity of two modes:
  • User program can wipe out the OS by overwriting with user data
  • If something crashes will halts the whole computer
How do we change from one Mode to other

User Mode to Kernel Mode

Using system call such as open, fopen etc, which will raise an software interrupt. On software interrupt, the control code will jump to Interrupt Vector Table of the OS which will handle switching to kernel mode and execute kernel instructions
Kernel Mode to User Mode

Code to switch from kernel mode to user mode is simply an assembly instruction : RTI (Return from Interrupt)

Comments

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto