Dual Mode Operations in Operating System

Operating Systems

Dual Mode Operations

The dual mode operations in operating system provide us protection of the operating system from errant users. We accomplish this defense by designating some of the system instructions as privileged instructions that can cause harm. The hardware only allows for the execution of privileged instructions in kernel mode. An example of a privileged instruction is the command to switch to user mode. Other examples include monitoring of I/O, controlling timers and handling interruptions. To ensure proper operating system execution we must be able to differentiate between machine code execution and user defined code. Most computer systems have embraced the approach of offering hardware support that helps us to distinguish between different execution modes. We need two different operating modes: user mode and kernel mode (also called supervisor mode, system mode or privileged mode). Mode bit is applied to the computer’s hardware to signify current mode as: kernel (0 bit) or user (1 bit). With the aid of mode bit we can differentiate between a function performed on behalf of the operating system and one performed on behalf of the user.

  • Hardware begins in kernel mode at system boot time.
  • The operating system is then loaded, and user programs are started in user mode.
  • If a trap or interrupt occurs, the hardware transitions from user mode to kernel mode (i.e. changes the mode bit status to zero).
  • So it is in kernel mode once the operating system takes control of the machine.
  • Always move the device to user mode (by setting the bit mode to 1) before transferring power to the user program.
  • The device is in User mode while the operating program is working on behalf of the user client.
  • However, when a user application demands a service from the operating system (through a system call), it must switch from user to kernel mode in order to complete the request. This architectural improvement is, as we can see, also useful for many other aspects of device operation.

The two modes of dual mode operations:

User Mode:

If user programs such as creating a text document or using some application software are running on the computer system, then the device is in user mode. If the user application requests a service from the operating system or an interrupt or a device call occurs then there will be a switch from user to kernel mode to satisfy the requests. In order to switch from kernel to user mode, then mode bit should be one.

Kernel Mode:

When the system boots, the hardware begins in kernel mode and it begins user program in user mode when the operating system is loaded. We have privileged instructions which execute only in kernel mode to protect the hardware. If user tries to run privileged instructions in user mode then the instructions will be viewed as illegal and the OS will be stuck.


Dual Mode Operations


Safe mode Switch:

Either the transition from user to kernel mode, or in the opposite direction, care must be taken to ensure that the kernel is not infected by a faulty or malicious user program. The context switch code needs to be carefully designed, and some amount of hardware support is required. To prevent ambiguity and minimize the risk of error, most operating systems have a standard sequence of kernel entry instructions whether due to interruptions, anomalies or system calls and a standard sequence of user-level return instructions, again regardless of the cause.

This specific sequence must at least provide for:

Atomic changes to processor state:

The transformation between the two must be performed atomically, so that at the same time the mode, program counter, stack, and memory security are all modified. The system counter and stack point to memory locations in the user process in user mode; memory security prevents user process access to any memory outside its area. In kernel mode, the program counter and stack point to the kernel’s memory locations; memory security is modified so that the kernel can access both its own data and that of the user process.

Limited entry:

The hardware must ensure that the entry point into the kernel is one set by the kernel to pass power to the operating system kernel. For example, the kernel code used to handle a system call for reading a file must first test whether the user program has permission to do so, and if not, the kernel will return an error. Without restricted entry points into the kernel, a malicious program might simply leap to perform the test right after the code, allowing any user to access any file in the file system.

Transparent restartable execution:

The processor saves its current state to memory on an interrupt, momentarily defers additional events, and sets the processor to run in kernel mode before switching to the interrupt or exception handler. The steps are reversed when the handler completes the processor state is restored from its saved position, with the program interrupted none the wiser.


More Information can be found on this topic here.


Visit this link for studying more about Operating Systems.

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *