CSC 325 Operating Systems with an Emphasis on UNIX
Chapter 2 Computer System Structures
- Computer-System Operation
- I/O Structure
- Storage Structure
- Storage Hierarchy
- Hardware Protection
- General System Architecture
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.

- Devices include such thinks as a printer, a disk, a tape drive, etc.
- Each device controller is in charge of a particular device type.
- Each device controller has a local buffer, a temporary data storage holding place.
- The CPU moves data from/to main memory to/from the local buffers along the system bus, which is just a set of wire connections along which data can be sent.
- I/O is from the device to local buffer of controller.
- Device controller informs CPU that it has finished its operation by causing a what is called an interrupt.
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
- Hardware - Asynchronous
Device informs CPU that something has happened e.g. a key has been pressed on the
keyboard.
- 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).
- Software
CPU asked for the interrupt to happen. e.g. to perform an operating system.
Hardware Interrupts
- I/O devices use Asynchronous Hardware Interrupts (i.e. caused by outside world and may
happen at any time).
- Transfers control to the interrupt service routine, through the interrupt vector, which
contains the addresses of all the service routines.
Interrupt Handling
- Interrupt handling is a very important part of the operating system.
- Before turning control over to an interrupt handler, the operating system must preserve the state of the CPU by storing all registers.
- Determine which type of interrupt has occurred:
- by polling - ask each device if it caused the interrupt or
- by vectored interrupt system - device identifies itself when it causes the interrupt
- Determine which I/O device caused the interrupt, then index into
the device table for that device, and modify the table entry to reflect the occurrence of the interrupt.
- Separate segments of code determine what action should be taken for each type of interrupt.
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
- Once synchronous I/O started, then control returns to user program only upon I/O completion.
- The CPU sits idle or waiting for an interrupt, and only one interrupt can take place, i.e. after the I/O.
completion.
Asynchronous or Non-Blocking I/O
- After I/O starts, control returns to user program without waiting for I/O completion.
- One key thing is that asynchronous I/O is more efficient, since the CPU can do other work while I/O is taking
place.
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.
- Used for high-speed I/O devices able to transmit information at close to memory speeds.
- Device controller transfers blocks of data from buffer storage directly to main memory
without CPU intervention.
- Only one interrupt is generated at the beginning and end of each block, rather than at the beginning and end of each word.
Storage Structure
- Main memory is the only large storage media that the CPU can access directly. This is done through the instruction cycle:
- Fetch: Get an instruction from memory, store it in instruction register (IR), and increment the Program Counter (PC).
- Execute: Decode and execute instruction, possibly fetching the operands and storing in internal registers, and/or storing the result in memory addresses.
- Main memory is small and typically volatile, so there is
Secondary Memory. Secondary storage is an extension of main memory that provides large non-volatile storage capacity. One good example is the magnetic disk.
- Magnetic disks
- Disk surface is logically divided into tracks, which are subdivided into sectors.
- The disk controller determines the logical interaction between the device and the
computer.
Storage Hierarchy
Storage of data can occur in a number of locations
-registers - cache - main memory - electronic disk - magnetic disk
- optical disk - magnetic tapes.
- Storage systems can be organized in a hierarchy according to:
- Most programs make accesses to memory which are localized
- in time
i.e. the program spends a lot of time executing short sections of code.
- in space
i.e. the program reads and writes to certain memory locations a lot; these locations tend
to be close together.
- Caching - copying information into faster storage system; main memory can be viewed as a
fast cache for secondary memory.
Hardware Protection
- Dual-Mode Operation
- I/O Protection
- Memory Protection
- CPU 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.
- User mode - execution done on behalf of a user.
- Kernel mode - execution done on behalf of operating system.
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.
- Sharing system resources requires the operating system to ensure that an incorrect program
cannot cause other programs to execute incorrectly.
- Preferable to have hardware support to differentiate between at least two modes of operations.
Some Examples:
- Intel 8088 had no mode bit - so there was no dual mode in
MSDOS
- Intel 80486 has a mode bit so Windows NT and IBM operating system/2 uses this
feature.
- Mode bit added to computer hardware (in CPU flags) to indicate the current mode: monitor
(0) or user (1).
- When an interrupt or fault occurs hardware switches to monitor mode

- Certain privileged instructions can be issued only in monitor mode.
- Some CPUs have more complex protection mechanisms with many levels of protection
(sometimes called rings).
I/O Protection
- All I/O instructions are privileged instructions.
- Must ensure that a user program could never gain control of the computer in monitor mode.
Memory Protection
- The operating system has unrestricted access to any memory address, but the user does not.
- Must provide memory protection at least for the interrupt vector and the interrupt
service routines.
- In order to have memory protection, add two registers that determine the range of legal
addresses a program may access:
- base register - holds the smallest legal physical memory address.
- limit register - contains the size of the range.
- Memory outside the defined range is protected.


- When executing in monitor mode, the operating system has unrestricted access to both
monitor and users' memory.
- The load instructions for the base and limit registers are privileged instructions.
- In practice, memory protection is much more complicated than this. A device called a
Memory Management Unit (MMU) controls access to memory.
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.
- Timer - interrupts computer after specified period to ensure operating system maintains
control.
- Timer is decremented every clock tick.
- When timer reaches the value 0, an interrupt occurs.
- Timer used to implement multiprogramming and time-sharing.
- Timer also used to compute the current time.
- Load-timer is a privileged instruction.
- User programs can not disable interrupts.
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.
- Usually takes the form of a trap (software interrupt).
- Control passes through an interrupt vector to a service routine in the operating system, and the mode
bit is automatically set to monitor mode.
- The operating system verifies that the parameters are correct and legal, executes the request, and
returns control to the instruction following the system call.