CSC 325 Operating Systems with an Emphasis on UNIX

Chapter 2 Computer System Structures


Computer-System Operation

The modern computer system consists of the CPU and a number of device controllers are connected through a common bus that provides access to shared memory.


Interrupts

Turning the power switch on initiates an operating system boot program. Then the modern computer sits idle till some event takes place, since the typical modern operating system is interrupt driven, meaning that the operating system keeps waiting until an event sends what is called an interrupt. The interrupt could be a software interrupt such as a system call or a hardware interrupt sent through the system bus.

What happens when interrupt occurs?

The interrupt causes the transfer of control to the appropriate interrupt service routine program. The address of the interrupted instruction must then be saved. While an interrupt is serviced, typically other interrupts are disabled. Events are signaled to the operating system by interrupts or traps. A trap or exception is a software generated interrupt, that is caused by an error or a user request such as writing some value in some memory location.

How are interrupts handled?

When an interrupt occurs the hardware transfers the control to operating system. The operating system preserves the state of the CPU by storing the registers which are special data storage and manpulation areas on the microprocessor. This includes the Program Counter (PC) register, which keeps track of the address of the next instruction to be loaded into the instruction register (IR). Then the operating system determines what type of interrupt has occurred, either by polling - i.e. querying each I/O device or by a vectored interrupt system. The corresponding code in operating system is executed depending upon the interrupt.

Types of Interrupts

  1. Hardware - Asynchronous
    Device informs CPU that something has happened e.g. a key has been pressed on the keyboard.
  2. Hardware - Synchronous
    CPU has tried to do something that has caused the interrupt. e.g. tried to read from an invalid memory location. (This is not always a problem, it may just mean that the needed data is on disk and needs to be fetched).
  3. Software
    CPU asked for the interrupt to happen. e.g. to perform an operating system.

Hardware Interrupts

Interrupt Handling


Input and Output (I/O)

Each I/O device controller has a local buffer and set of special registers. The device controller is responsible for movement of data between the device and its local buffer. The operating system keeps a device-status table that consists of information on each device: type, address, and state. e.g. disk unit 1; busy; address xxx.

To start an I/O operation, CPU loads the appropriate registers within the device controller. Looking at the contents, the device controller determines what action to be taken. (e.g. if read, then device controller copies the data to the buffer). Once the device driver finishes its work, it sends an interrupt to the CPU.

Synchronous or Blocking I/O

Asynchronous or Non-Blocking I/O

Direct Memory Access (DMA) Structure

DMA is used for high speed I/O devices that are able to transmit information at close to memory speeds. The key difference with other I/O transfers is that the CPU is not interrupted for each word to be transferred, but only at the beginning and the end of an entire block transfer.


Storage Structure


Storage Hierarchy

Storage of data can occur in a number of locations
-registers - cache - main memory - electronic disk - magnetic disk - optical disk - magnetic tapes.

Hardware Protection


Dual-Mode Operation

Two modes are provided by the hardware - the user mode and the monitor (also called kernel mode or supervisor mode or system mode) mode. A mode bit is typically added to computer hardware to indicate the current mode. When the system boots, the hardware starts in monitor mode. The operating system is loaded and then a user process is started in user mode. When an interrupt occurs, the hardware switches to monitor mode. When the operating system gains control, it is always the monitor mode and before passing control to user program, it switches the hardware to user mode. Some Examples:

I/O Protection

Memory Protection

CPU Protection - how the operating system stays in control.

We must prevent the user program from gaining control and not relinquishing it such as getting stuck in an infinite loop, and then never returning control to operating system. Thus, we use a timer. Before giving control to a user, the operating system loads up the timer to interrupt after a given time slice. Once the timer interrupt occurs, the control is turned back to the operating system. At this point the operating system may send out a fatal error message or may increase the user's timer limit.

General-System Architecture

Given that I/O instructions are privileged, how does the user program perform I/O? Through the system call which is the method used by a process to request action by the operating system.