Javatpoint Logo
Javatpoint Logo

Privileged and Non-Privileged Instructions in Operating System

In this tutorial, we are going to learn about Privileged and Non-Privileged Instructions in Operating System. Before learning about those instructions let us know a bit about the Operating System.

Operating System

An Operating System is a program which is used to act as an intermediary or a gateway between the computer and the computer hardware. An operating system (OS) is the software that handles all other application program on a computer after or before being installed on the computer first by a boot program.

The installation of boot program is done by a specified application program interface, the application programs seek services from the operating system (API). Additionally, users can communicate directly with the operating system by using a user interface, such as a graphical user interface (UI) or a command-line interface (CLI) or an (GUI)

Dual Mode Operation

The Computer works well only when an operating system runs well. So, we must ensure that the operating system is having or working under a proper execution.

In order to ensure the proper execution of the operating, we must ensure the proper execution of the operating system, we must be able to distinguish between the execution of operating-system code and userdefined code. This approach is followed by all the computers. This is used because the Operating System provides support to the hardware and it helps us and allows us to see the variation between various modes of execution.

We also need various modes of operations because an error in the program can cause or give many problems to the existing and executing processes.

For example if the program running is stuck in an infinite loop. Then, all the remaining processes have to wait for the completion of existing processes. Practically, the program is never going to stop execution until all the resources are exhausted. So, to prevent from all this problems occurring this dual mode operations are used.

The two operations used in Dual Mode Operations are:

  • User Mode
  • Kernel Mode

User Mode

User mode is used when the computer system is executing the processes given to the Operating System when user applications like creating a document in notepad or using any in built programs , then in these situations the Operating System uses User Mode.

There will be a switch from user to kernel mode to handle requests made by the user program for an operating system service, an interrupt, or a system call.

Kernel Mode

Kernel mode is used when the computer system is executing the processes given to the Operating System when the operating system is started and in loaded state then the system installs boot program and the hardware is started in kernel. This mode is used to start the user application in User Mode.

For protection purpose in Kernel Mode the Operating System only uses privileged instructions which can only be executed in Kernel Mode only. If the user attempts to run privileged instruction in user mode then the Operating System will treat the specified instruction as illegal and traps to Operating System.

The Kernel Mode is also called as Supervisor Mode , System Mode , Privileged Mode , etc.

Relation between User and Kernel Mode

The user and Kernel Mode are differentiated with the help of a bit. This bit is also called as a mode bit. This mode bit is added to the computer hardware. This addition is done to know the current mode of the computer.

If the bit or the mode bit is zero ( 0 ) then, the Mode in which the execution is going is Kernel Mode.

If the bit or the mode bit is one ( 1 ) then, the Mode in which the execution is going is User Mode.

This helps in separating the tasks between User and Kernel Mode. When the computer system is executing on behalf of a user application, the system is in user mode. However, when a user application requests a service from the operating system (via a . . system call), it must transition from user to kernel mode to fulfill the request. At system boot time, the hardware starts in kernel mode. The operating system is then loaded and starts user applications in user mode.

Instruction

An instruction is a job or command or order given to the Computer by an App or an Application. These instructions are brought into execution by the Operating System used in the Computer. There are two types of instructions in the Operating Systems. They are

  1. Privileged Instructions
  2. Non-Privileged Instructions

Before learning about them let us know about the life cycle of an instruction in an Operating System

Life Cycle of an Instruction

The Evolution of an Instruction starts with initial execution of the instructions takes place in kernel mode, with the operating system in control. An application's control is immediately shifted to user mode when it is launched by a user.

The instruction's working is sent abruptly to the kernel mode whenever the instruction is called by the system or there is a system interrupt or there is a system trap. When the system call is executed, the control is transferred back to the instruction that came before it. All instructions are carried out in this manner.

Now let us discuss about the privileged instructions and Non-Privileged instructions.

Privileged Instructions

The instructions which are executed and can be made to run only in kernel mode. Then, these types of instructions are known as Privileged Instructions.

We know that a Privileged Instruction can only be executed in Kernel Mode. But, the Privileged Instruction tries to be executed or runned in user mode. As the instruction cannot be executed inside the user mode, then that instruction will be thrown away and will be seen as an illegal instruction. The instruction would be stopped in the Operating System by the hardware.

The operating system has the responsibility to see that the stopped instructions are executed or not. The operating system has also the responsibility to set the timer for any System interrupt before giving access or control to any user or system application.

The operating system can hold the access the control of the timer if there occurs an System Interrupt.

The Operating System duty is to ensure proper operation of Privileged Instruction.

Examples of Privileged Instructions

  1. Clear Memory
  2. Input and Output Instructions
  3. Halt Instructions
  4. Context Instructions
  5. Remove a process from the Memory
  6. Set the Timer
  7. Turn of all Interrupts
  8. Modify Entries in the Device Status Table
  9. Flush Data Cache
  10. Reset a Processor
  11. Load and Read System Registers
  12. Change processor modes from kernel to user
  13. Change the voltage and frequency of processor
  14. Invalidate Data Cache
  15. Invalidate TLB Entries

The Privileged Instructions are very dangerous. So, we must be very careful. We should use them very intelligently. They can cause problems to our computer in future.

Non-Privileged Instructions

The instructions which are executed and can be made to run only in User mode. Then, these types of instructions are known as Non-Privileged Instructions.

Examples of Non-Privileged Instructions

  1. Performing Arithmetic Operations
  2. Reading System Time
  3. Sending the final output for printout in printer
  4. Reading the status of processor
  5. Generate a trap instruction

The mechanism that switch modes follows are

  1. User - - - - > kernel ( built into hardware )
  2. Kernel - - - - > user ( privileged instructions )

We all know that computer has two different parts. They are

  1. Hardware
  2. Software

The software part works by communicating with the hardware part using the instructions prescribed above.

The Non-Privileged Instructions are Safe Instructions. They do not cause any problems in computer in future.

The Software Part can be divided into different categories based on the Instructions. They are

  1. Kernel
  2. Application

Kernel can only execute Privileged Instructions only.

Whereas,

The Application has the capability to execute both Privileged Instructions and Non-Privileged Instructions.

Difference between Privileged and Non-Privileged Instructions in Operating System

Serial Number Privileged Instructions Non-Privileged Instructions
1. ) The instructions which are executed and can be made to run only in kernel mode. Then, these types of instructions are known as Privileged Instructions. The instructions which are executed and can be made to run only in User mode. Then, these types of instructions are known as Non-Privileged Instructions.
2.) These instructions are often used for delicate procedures and are only permitted to be carried out under certain conditions. Due to the fact that they do not share any resources, these instructions are carried out without interfering with other operations.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA