Timer in CPU Protection
In multiple process system, we want to make sure the multiple processes can be run so the CPU is switched between different running processes. For example, if multiple processes are run then CPU is given first to process1 for a specific time period then 2 similarly to all the other processes.The technique of given CPU to the multiple processes is called CPU scheduling. As multiple processes are using CPU so we don’t want a process used CPU for an infinite time period so we need a timer which is loaded with a predetermined time and fix interval clock which periodically interrupt the CPU and when this clock interrupt, timer value is decremented by 1 and when timer value is 0 a special type of interrupt is generated which is called timer interrupt and Interrupt service routine (ISR) is executed which take the CPU from the previous process and give it to the next process.
Dual Mode Operation in Hardware Protection
There are two CPU modes by which CPU can execute instructions. One is privileged or restricted mode also called kernel mode and the other is non-privileged or unrestricted mode also called user mode. When the CPU is in kernel mode, it has complete control on everything such as access of memory addresses, reading from a file, etc so if any user program which is in the user mode wants to execute a system call i.e new process creation, I/O operations then it is done through system call in privileged mode. A system call is a request by the user program to the operating system’s kernel
For example at system boot time, the hardware starts in monitor mode. The operating system is then loaded and starts user processes in user mode. Whenever a trap or interrupt occurs, the hardware switches from user mode to monitor mode. Thus, whenever the operating system gains control of the computer, it is in monitor mode. The system always switches to user mode (by setting the mode bit to 1) before passing control to a user program.
The dual-mode of operation provides us with the means for protecting the operating system from users who can harm each other or can disturb the working of privileged mode. We accomplish this protection by designating some of the machine instructions that may cause harm as privileged instructions. The hardware allows privileged instructions to be executed only in monitor mode. If an attempt is made to execute a privileged instruction in user mode, the hardware does not execute the instruction, but rather treats the instruction as illegal and traps it to the operating system.
0 Comments