What are the dual modes? What is its advantage? Explain sensitive, privileged, and non-privileged instructions?
Dual Mode forms the basis for I/O protection, CPU protection, and memory protection. It specifies that the computer system work in two separate modes. In the Hardware level, instructions are executed in these modes. It allows the Operating System to protect itself and system files.
Types of Dual Mode Operations
These two modes are user given below:
- User Mode
- Kernel Mode
Purpose of Dual Mode
The Purpose of dual-mode is to ensure that an incorrect program cannot cause other programs to execute incorrectly. If not, an error in one program can affect other processes. It might change or modify data of another program or also can affect the operating system. We use Dual modes So that the processor switches between the two modes depending on what type of code is running on the processor. Modern OS is interrupt-driven. Windows and Linux are dual-mode Operating System. On the other hand, MS-DOS had no mode bit and so no dual mode.
If one process stuck in an infinite loop, then this infinite loop could affect the correct operation of other processes. So, to ensure the proper execution, we use dual-mode operations.
Advantage of Dual Mode
Following are some of the main advantages of dual-mode:
- Protection must be needed for shared resources. Dual-mode operation is used to provide protection & security to the user’s program.
- It protects CPU, Input/output, Memory, and operating system from errant users (misbehaving users).
- If you do not have Dual-mode, then you can wipe or write over the Operating System.
- The Operating System gains the main control of the computer in the kernel mode.
- Dual Mode provides more feature and greater security for the Operating Systems
- Multiple processes can write in the same system at the same time, with disastrous results.
Mode Switching and Mode Bit
Interchanging the Mode from user to kernel or kernel to the user is referred to as mode switching, I should not be confused with context switch (switching of CPU from one process to another). 0x80 software interrupt is used to switch from user mode to kernel mode.
1. Kernel Mode
When the system starts, it is in kernel mode. During the booting process, the Operating System is loaded in the kernel mode. It executes other application programs in user mode. It is reserved as the lowest level, and only trusted functions of the OS are executed in kernel mode. The entire system will halt if a crash occurs in kernel mode. Instructions have complete and unrestricted access to the hardware and resources. In kernel mode, the Mode bit is set to 0. Mode bit changes from 0 to 1 in order to switch kernel mode to user mode.
These are the instruction that executes only in kernel mode. They generate a trap (software interrupt) that forces a switch to the mode to the kernel mode.
Characteristics of Privileged Instructions:
- It is considered as an illegal instruction If we attempt to execute privileged instruction in user mode.
- It is the responsibility of the Operating System to make sure that the timer is set to the interrupt before transferring the control. OS again regain control after the timer interrupt
- Correct Operations are achieved from privilege instructions.
Examples of Privileged Instructions:
- Context Switching
- Clearing Memory or Removing process from Memory
- Modify entries in Device-status table
- I/O instructions and Halt instructions
- Turn off all Interrupts
- Setting Timer
2. User Mode
The System is said to be in user mode when the operating system is running a user application such as handling a text editor. The application programs have no ability to directly access hardware or reference memory. The System switches its mode from user mode to kernel mode when the application requests the help of an operating system or an interrupt or a system call occurs. In user mode, the Mode bit is set to the value of 1. The mode bit changes from 1 to 0 in order to switch user mode to kernel mode.
These are the Instruction that executes only in User mode.
Examples of Non-Privileged Instructions:
- Reading the status of Processor
- Reading the System Time
- Generate any Trap Instruction (software interrupt)
- Sending the final printout of Printer
Changing Mode from Privileged to Non-Privileged
Non-privileged Instruction that does not generate any interrupt is used to change the mode from Privileged to Non-Privileged.
Sensitive & Non- sensitive Instructions
In order to identify an architecture is suitable for a virtual machine, it is necessary to distinguish between two classes of machine instructions.
- Sensitive Instructions
- Non-sensitive Instructions
1. Sensitive Instructions
These instructions must be a subset of the privileged instructions. They affect system resources and behavior. All sensitive instructions pass through the hypervisor (VMM). The hypervisor or VMM (virtual machine monitor) is software, firmware, or hardware that creates and runs virtual machines. For Example, VMware, VirtualBox which prevents direct execution of sensitive instructions. They require special precautions at execution time. Examples of sensitive instructions in x86 architecture are PUSHF, POPF. Sensitive instructions can be:
- Control sensitive
- Mode sensitive
Control Sensitive Instructions
Instructions that try to alter the configuration of resources in the system are called the Control sensitive Instructions. Examples Control Sensitive Instructions in x86 are PUSHF, POPF, SGDT, etc.
Mode Sensitive Instructions
Instructions those result depend upon the configuration of resources are called Mode Sensitive Instructions. Examples of Mode Sensitive Instructions on x86 are POP, PUSH, CALL, etc.
2. Non-sensitive Instructions
They are harmless and Safe Instructions. They are the regular instruction that executes directly without translation in user mode.
Was this helpful?
1 / 0