HARDWARE PROTECTION
Many programming errors can be detected by the hardware.
These errors are normally handled by the OS.
OS provides the hardware protection.
1. Dual-Mode Operation
To ensure proper operation, we must protect the OS and all other programs and their
data from any malfunctioning program.
Protection is nedded for any shared resource.
The approach taken by many OS provides hardware support that allows us to
differentiate a many various modes of execution.
We need two seperate modes of operation : user mode and monitor mode (also called
supervisor mode, system mode or privileged mode)
A bit, called the mode bit is added to the hardware of the computer to indicate the
current mode : monitor (0) or user (1).
At system boot time, the hardware starts in monitor mode. The OS is then loaded and
starts user processors in user mode .
Whatever a trap or interrupt occurs, the hardware switches from user mode to monitor
mode.
2. I/O Protection
A user program may disrupt the normal operation of the system by issuing illegal I/O
instructions.
We can use various mechanishms to ensure that such disruptions cannot take place in
the system.
To prevent users from performing illegal I/O, we define all I/O instructions to be
privileged instructions.
Thus, user cannot issue I/O instructions directly : they must do it through the OS.
For I/O protection to be complete, we must be sure that a user program can never gain
control of the computer in monitor mode.
3. Memory Protection
To ensure correct operation, we must protect the interrupt vector from modification by
a user program.
In addition, we must also protect the interrupt-service routines in the OS from
modification.
We see that we must provide memory protection at least for the interrupt vector and
the interrupt service routines of the OS.
In general, we want to protect the OS from access by users and, in addition, to protect
user programs from one another.
This protection must be provided by the hardware.
To seperate each program’s memory space, we need the ability to determine the range
of legal addresses that the program may access and to protect the memory outside that
space.
We can provide this protection by using two registers, usually a base and a limit.
The base register holds the smallest legal physical memory address; the limit register
contains the size of the range.
For example if the base register holds 3000040 and limit register is 120900 then the
program can legally access all address from 300040 through 420940 inclusive.
This protection is accomplished by the CPU hardware comparing every address
generated in user mode with the registers.
4. CPU Protection
In addition to protection I/O and memory, we must ensure that the OS maintains
control.
We must prevent a user program from getting stuck in an infinite loop or not calling
system service and never returning control to the OS.
To accomplish this goal, we can use a timer.
A timer can be set to interrupt the computer after a specified period.
The period may be fixed or variable.
A variable timer is generally implemented by a fixed-rate clock and a counter.
The OS sets the counter.
Every time the clock ticks, the counter is decremented.
When the counter reaches 0, an interrupt occurs.