In: Computer Science
Modern CPU architectures allow for two modes of operation. Explain what the goal of having these two modes is/are, and explain how two-mode operation is used to achieve this goal(s).
There are two
modes of Operation:
1) Kernel Mode
2) User Mode
First, Let us understand what are these modes and what do they
do.
Kernel
Mode
Kernel is a bridge between Applications and Hardware.
When the system is switched on, It boots first in the Kernel Mode
and then shifts to User Mode.
Mode bit for Kernel Mode is 0 and Mode bit for User Mode is 1. So,
when changing the operating modes, actually Mode bit changed from 0
to 1 or from 1 to 0.
There are certain privileged operations which can only be performed
in the kernel mode. Like Interrupts, I/O calls.
In Kernel mode, executing code can have completely unrestricted
access to all the memory addresses and Hardware.
Kernel Mode is almost always kept and used for trusted
functions.
Because, there is so much control and power given kernel mode, and
kind of crash and damage and impact the system to the roots and can
be disastrous.
User
Mode
The Operating System starts in the user mode. It frequently need
help of the Kernel Mode to perform various operations.
In User mode, executing code has no direct access to Memory
addresses and Hardware.
It must take help of the kernel mode with system APIs to have the
access to address and hardware.
Because, User mode does not have so much control and power, crashes
in this mode are mostly recoverable.
Goals
Having these two modes is important because this isolation protects
the system from severe damage.
If we do not have two modes, then giving all the
access in any 1 mode can be fatal to the system. Entire
Operating System can be wiped out.
Multiple processes may write at the same time in the same system,
with catastrophic results.
--------------------------------------
Now, Let's see how the system protects itself when privileged
access is wanted in user mode.
Here, we can see that a user process executes in user mode until a
system call comes.
When that happens, A TRAP is generated and mode bit changed from 1
to 0.
That system call is executed in Kernel Mode and when that
completes,
A return is generated and mode bit is changed from 0 to 1.
and the execution resumes in user mode.
This way, it is made sure that privileged instruction are always
performed in kernel mode and not in user mode.
Please comment for any further assistance.