Introduction

advertisement
Introduction
A digital computer system consists of hardware and software. The hardware consists of the physical
components of the system, whereas the software is the collection of programs that the computer can execute.
The structure of a computer system is provided in Figure 1-1 in page 2 of the book, and Figure I.1 below
shows a schematic representation of the four major (functional or microarchitecture) components of a
digital computer system hardware, and how they are interconnected to each other. These major components
are the Central Processing Unit (CPU), the Main (or Primary) Memory, the input system, and the output
system.
Figure I.1
General Structure of a Digital Computer System Hardware
CPU
Registers
CU
ALU
Controller
Controller
Main
Memory
Output Device
Input Device
Controller
Drive
Secondary
Storage
The arrows indicate the flow of data between the computer components.
1
1
2
2
3
The input system consists of the input devices with their controllers, whereas the output system
consists of the output devices with their controllers. Computer components other than the processor and the
main memory are referred to as the system peripherals.
Figure 1-6 in page 20 in the book also shows the components of a simple personal computer.
1.1 Central Processing Unit (CPU)
The central processing unit (CPU) or processor is sometimes referred to as the brain of the computer
system, because it is the center of activities in a computer system. Some computer systems have two or more
processors, and are referred to as multiprocessing systems. A processor consists of the control unit (CU),
the arithmetic and logic unit (ALU) and the registers.
The Control Unit (CU) controls the operations of the different components of a computer system
hardware, supervises the transfer of data between the components of the system, and fetches the instructions
of a program from the main memory. After an instruction has been fetched, it interprets (decodes) it, and
then sends control signals to the ALU to perform the operation specified by the instruction.
The Arithmetic and Logic Unit (ALU) performs the arithmetic, relational, and logical operations on
data. The arithmetic operations are the addition, subtraction, multiplication and division of signed and
unsigned integers. It is also possible to instruct the CPU to perform arithmetic operations on decimal
integers.
Registers are special high-speed memory locations within the CPU that are directly accessed by both the
control unit and the arithmetic and logic unit. There are two classes of registers: those that are used by the
CPU to control its internal operations, and those that can be accessed by a user (user visible registers). In
general, computers have a small number of registers, and a register can only store a fixed size of data: The
number and size of registers on most computers are as follows: fourteen 16-bit registers, thirty two 32-bit
registers, or sixty four 64-bit registers. The following user visible registers are found in most processors:
1.
General registers are used by programmers, or the CPU to hold certain data on which an operation is
being performed, or the result of certain operations. General registers of an Intel 8086 processor are
registers AX, BX, CX, and DX.
2.
The program counter holds the memory address of the next instruction to be executed. The
program counter is called register IP on Intel 8086 processor.
3.
The stack pointer holds the memory address of the top of the stack which contains the parameters
and the local variables of a procedure (or function) that is called. The stack pointer is called register SP
on Intel 8086 processor.
4.
The Program Status Word (PSW) contains the collection of code bits which are set by comparison
instructions, the CPU priority and mode (user or kernel), and other control bits. The PSW is called flags
register on Intel 8086 processor.
Instructions that use registers to store their data execute much faster than those using the main memory
because registers are accessed much faster than the main memory. However, the number and the size of
registers in any computer system are limited because of the high cost of making registers.
4
Mode of Operations
Each processor has a specific set of instructions (called instruction set) that it can execute, and most
processors support at least two modes of execution: the user mode and the kernel or supervisory or system or
control mode.
In kernel mode, the processor can execute every instruction in the instruction set, whereas in user mode,
it can only execute non-privilege instructions. Instructions that the processor can execute only when it is in
kernel mode include instructions to read or alter a control or a status register, primitive I/O instructions (that
have access to the physical devices) and instructions that relate to memory management. In addition, certain
regions of the main memory can be accessed only if the CPU is in kernel mode.
Instruction Execution Cycle
The CPU executes a machine language instruction in three stages: It performs the fetch operation in the first
stage, the decode operation in the second stage, and the execute operation in the third stage. These
operations are usually referred to as the fetch, decode, and execute cycle, as they are continuously repeated
for each instruction. They are described as follows:
! Fetch Operation: the CU fetches (copies) the instruction at the memory address specified by the
program counter.
! Decode Operation: the control unit increments the program counter by the size of the instruction just
fetched, and then decodes the instruction by interpreting its opcode. If other operands are specified by
the instruction, the control unit decodes their addresses and fetches the operands. It then passes the
instruction and its operands (if any) to the arithmetic and logic unit for execution.
! Execute Operation: the arithmetic and logic unit executes the instruction and passes the result to the
control unit. The control unit then returns the result to the register(s) or the main memory.
To improve performance, many modern processors have facilities for executing more than one
instruction at the same time: in a pipeline design, there is a separate fetch, decode, and execute units so that
while instruction n is being executed, it could also be decoding instruction n+1, and fetching instruction n+2
(refer to Figure 1.7 (a) in page 22 in the book). A superscalar CPU uses multiples execution units (for
example, one for integer arithmetic, one for floating-point arithmetic, and one for boolean operations), and
two or more instructions are fetched at once, decoded, and dumped into a buffer until they can be executed
(refer to Figure 1.7 (b) in the book).
5
1.2 Main Memory
The Main Memory (also known as primary or core memory) is a collection of two-state devices that are
used to represent the binary digits, 0 and 1: when the device is in one state it is said to represent bit 1, and
when it is in the other state, it is said to represent bit 0.
Consecutive bits in the main memory are grouped into units of 8 called bytes. Each byte is identified by
its relative position in the main memory, referred to as its physical address or absolute address.
The main memory of most computers consists of the RAM (Random Access Memory), the ROM (Read
Only Memory), and the CMOS.
The RAM is used to temporarily hold programs to be executed on the computer and their data.
Information can be stored, and also retrieved from the RAM. However, the RAM is volatile: its contents are
lost when the power to the computer is turned off.
The ROM is a non-volatile memory. Unlike the RAM, information can only be retrieved from it: its
contents cannot be changed by the programmer. It is used by computer manufacturers to store programs to
handle low-level device control, such as programs to read the keyboard, write to the screen, and do disk I/O.
On some computers, it also holds the bootstrap loader that is used to start the computer (by controlling the
operations of the CPU).
The CMOS memory is used to hold the current time and data. It is volatile, but it is powered with the
clock that increments its time by a small battery: the time is therefore correctly updated even when the power
to the computer is turned off. The CMOS memory can also hold the configuration parameters, such as the
disk to boot from.
1.3 Input and Output Systems
The Input system consists of the input devices and their controllers. An input device transmits information
from the outside world to the computer. Examples of input devices are keyboards, mice, joysticks, scanners,
terminals, microphones . . . etc.
The output system consists of the output devices and their controllers. An output device transmits
information from the computer to the outside world. Examples of output devices are printers, monitors,
plotters, speakers, terminals, . . ., etc.
Controllers are located between the CPU and the input/output devices and are used to physically control
the devices. There is in general, a controller for each device. For an output device, a controller accepts data
from the computer that it converts into signals used by that device. For an input device, it accepts signals
from the device that it converts into sequences of bits to be used inside the computer.
6
On IBM PC and compatible computers, controllers often take the form of a printed circuit boards that can
be inserted into the motherboard or an expansion slot. There are also controllers than can handle two, four,
or even more identical devices.
Each controller has special registers (usually a byte or a word) for communication with the CPU. A
typical controller may have three or more registers associated with it as follows:
!
A control register
is used to set control information such as the send or the receive information.
!
A data register
is used to hold the data to be transmitted or the data received.
!
A status register
is used to record information about the status of the controller or the device.
Each controller has at least a data register, but the functions of the status and the control registers may be
combined into one register for a simple controller. Sophisticated controllers may however have several
control and status registers.
In some computers such as those based on Motorola 680x0 processors, controllers registers are part of
the memory address space: they are given addresses in the same range of addresses as the one given to bytes
in the main memory. Reading or writing these registers is performed in the same way that bytes or words in
the main memory are read or written. This approach is usually referred to as memory-mapped
input/output.
In other computers such as those based on Intel processors, these registers are referred to as ports, and
the port (or I/O) address space is separate from the memory address space: a port address is a three-digit
hexadecimal value.
Figure I.2 Some 8086 I/O Controllers and their I/O Addresses and Interrupts
I/O Controller
I/O Address
Interrupt
040 - 043
8
Keyboard
060 - 063
9
Hard Disk
1F0 - 1F7
11
Serial Port Controller COM1
3F8 - 3FF
12
Serial Port Controller COM2
2F8 - 2FF
11
Printer (LPT1)
378 - 37F
15
Floppy Disk
3F0 - 3F7
14
Parallel Port Controller LPT2
3BC - 3BF
13
VGA/EGA
3C0 - 3CF
16
7
The port addresses available for the Intel 8086 processor based computers are 000h - 3FFh. Each controller
is allocated a certain range of it (to identify its ports) as shown in Figure I.2. While the actual port numbers
and port settings may differ from machine to machine, the techniques involved are the same. With port
addressing, special instructions are used by the processor to read and write controllers’ registers. Controllers
use interrupts (discussed later in this chapter) to communicate with the CPU.
1.4 Secondary Storage
Since the RAM is volatile, data and programs (in the RAM) that are needed for future use in the computer
must be permanently saved in a different type of memory before the computer is turned off. This type of
memory is referred to as secondary storage (or memory). Examples of secondary storage are floppy disks,
hard disks, tapes and CD ROMs.
In order to use a particular secondary storage on a computer, that computer must be equipped with a
hardware device called drive to read and/or write on that secondary memory. For example, in order to use a
floppy disk on an IBM PC, that computer must be equipped with a floppy disk drive. As for I/O devices, a
controller is also needed for communication between the CPU and each drive. Figure I.1 shows how drives
and their controllers are connected to the rest of the computer system, and Figure I.2 provides the I/O address
and the interrupt information for the floppy disk drive and the hard disk drive controllers of a computer
system based on the Intel 8086 processor.
1.5 System Interconnection
The transfer of data from one component of the computer system to another, and the sending of control
codes and other signals by the CPU to the controllers or the memory control unit are accomplished by using a
set of parallel wires referred to as the system bus. It consists of the data bus, the address bus, and the
control bus as illustrated in Figure I.3.
The data bus is used for the flow of data between the different components of the system, whereas the
address bus is used by the CPU to specify the address of the memory location or the controller’s register
being accessed. The control bus (or control lines) is used by the CPU to send control signals to controllers
or the memory control unit.
Some computers have a single-bus architecture as illustrated in Figure 5.3 (a) in page 343 of the book.
However, the trend in newer computers is to have a dual-bus architecture as illustrated in Figure 5.3 (b) of
the same page. The structure of a large x86 system is provided in Figure 1.12 in page 32.
Figure I.3
Address Bus
Data Bus
Bus System of Intel X86 Processors Based Computer Systems
8
Control Bus
Processor
Memory
Control Unit
Memo
ry
Controller
I/O
Device
Controller
Drive
1.6
Interrupts
An interrupt is a signal to the CPU that an event that needs immediate attention has occurred. The CPU
responds to an interrupt by suspending the program being executed, and then transferring control to a special
program in the memory called interrupt handler (Figure 1-11, Page 31) and depending on the cause of the
interrupt, the control of the CPU may or may not be returned to the suspended program at the end of the
interrupt handler.
There are two types of interrupts: hardware/external interrupts and software/internal interrupts.
An external interrupt is initiated outside of the CPU by hardware devices such as the clock and
controllers. For example, an input device controller may generate an interrupt to alert the CPU that the
transfer of data requested by the CPU is completed. Some events such as power failure or operator-initiated
system shutdown also generate external interrupts.
An internal interrupt is generated within the CPU by errors detected during the execution of an
instruction or by some instructions that are specifically designed to initiate interrupts. Some error-initiated
interrupts are caused by overflow conditions, attempt to divide by 0, invalid operation code (opcode) or data,
or an attempt to access memory locations outside of the region allocated to a program in a multiprogramming
system.
9
Interrupt Vector
In general, interrupts of a computer are numbered, such that an interrupt number is the index of the address
of the corresponding interrupt handler into the array in the main memory of interrupt handlers addresses
called interrupt vector.
1.7 DMA Controller
A DMA (Direct Memory Access) controller is a special controller that is used by the CPU for the transfer
of data between the main memory and some I/O controllers. It has access to the “system bus” (to be
discussed later) independently of the CPU, and contains several registers that can be written and read by the
CPU (refer to Figure 5.4, page 345 in the book): there is a memory address register, a byte count register,
and one or more control registers.
The memory address register specifies the beginning memory address of the transfer; the byte count
register specifies the number of bytes to be transferred; and control registers specify the I/O port to use, the
direction of the transfer (reading from the device, or writing to it), the transfer unit (byte at a time or word at
a time), and the number of byte to transfer in one burst.
The CPU programs the DMA controller to perform an I/O transfer by setting its registers. The DMA
controller then does the following:
1. Write on the address bus the memory address for the transfer, and
2. Issue a read/write request to the controller over the bus.
3. After the transfer is complete, the controller sends an acknowledgment signal to the DMA controller.
4. The DMA controller then increments the memory address to use, and decrements the byte count.
5. If the byte count is still greater than 0, steps 1 to 4 are repeated;
6. Otherwise, the DMA controller sends an interrupt to the CPU to let it know that the transfer is
complete.
1.8 Clock
The clock is a device within the computer that generates periodic signals that are used to pace the operations
of the CPU. The most basic unit of time for the CPU is the clock cycle: The among of time that is needed by
the CPU to execute an instruction is expressed in terms of clock cycles, and the speed of the CPU is
determined by the system clock rate (number of cycles per second), the word size, and the bus width. The
system clock rate is measured in megahertz (MHz) which corresponds to one million of cycles per second.
Intel 8086 processors had clock rates in the range of 5 MHz to 8 MHz. But today’s newer Intel Pentium
processors have clock rates over 1.6 Ghz (gigahertz), with one gigahertz equals one billion of cycles per
second.
10
1.9 Sending and Receiving Data to the Main Memory
To write a word of data to a memory location, the processor loads the address of that memory location into
the address bus, and the data to be sent into the data bus; it then loads the command to write to memory into
the control bus. The memory control unit then decodes the command and the address, retrieves the data
from the data bus, and stores it into the corresponding memory location.
To read from a memory location, the processor loads the address of that memory location into the
address bus, and the command to read from memory into the control bus. The memory control unit is
responsible for decoding the address, retrieving the data from the appropriate memory location, and loading
it into the data bus for retrieval by the CPU.
1.10 Input and Output
I/O operations are usually done in one of the following three ways:
1. Programmed I/O or I/O with busy waiting.
2. Interrupt-driven I/O.
3. Direct Memory Access (DMA) I/O.
Programmed I/O and Interrupt-Driven I/O
To output data to a controller’s data register, the CPU loads the address of that register into the address
bus, and the data to be sent into the data bus; it then loads the command to output data into the control bus.
The controller being addressed is responsible for recognizing the output command and the register address,
and for retrieving the data from the data bus.
To input data from a controller’s data register, the CPU loads the address of that register into the address
bus, and the command to input data into the control bus. The controller being addressed recognizes the input
data command and then decodes the register address as the address of one of its data registers. It then
retrieves the data from the register and places it onto the data bus where it is retrieved by the CPU.
With Programmed I/O, after the I/O operation has been initiated, the CPU continuously polls the
controller to see if the operation is complete (page 342).
With Interrupt-driven I/O, after the I/O operation has been initiated, the CPU may continue to execute
other instructions or programs; and when the controller detects the end of the transfer, it generates an
interrupt to signal the completion (Figure 5-5, Page 347).
DMA I/O (refer to Figure 5.4, page 345 in the book)
With DMA I/O, the CPU issues a command to the DMA controller by sending the following information:
11

read/write request

the address of the I/O controller/device involved

the starting address in memory to read from, or to write to

the number of bytes to transfer
It can then continue to execute other instructions or programs while the DMA controller is controlling the
flow of data between the main memory and the controller. When the DMA controller detects the end of the
transfer, it generates an interrupt to signal the completion.
1.11 Memory Hierarchy
The three major characteristics of a memory are cost, capacity, and access time.

The cost per bit of the memory must be reasonable in relationship to the other components.

Capacity: how much memory is needed for a computer system?

The access time of a memory is the speed at which data and instructions are transferred to and from
that memory.
According to the technologies used to implement memories, the following relationship holds:

smaller access time
- greater cost per bit

greater capacity
- smaller cost per bit

greater capacity
- greater access time.
A trade-off among the above characteristics is necessary in the design of a computer system memory,
because smaller access time implies greater cost per bit. The approach used is a memory hierarchy. Figure
1.9, page 25.
As one goes down the hierarchy, the following conditions hold:
1. Decreasing cost per bit
2. Decreasing frequency of the memory access by the processor
3. Increasing capacity
4. Increasing access time.
The data/instructions are organized in a memory hierarchy in such a way that the processor accesses data
more often in faster memory than in slower ones. The basis for the validity of this condition is the principle
of locality of reference: during the execution of a program, memory references by the processor for both
instructions and data tend to cluster. That means involve only a small range of addresses.
Increase:
Decrease:
capacity
access time
cost per bit
Access frequency
Registers
------------------Cache
--------------------------Main Memory
-------- ---------------------------
12
Magnetic disk
--------------------------------------------Magnetic tape
Cache Memory
The cache memory is a high speed memory that is used to improve performance, by staging the movement
of data between the main memory and the processor registers. It is mostly controlled by the hardware, and is
subdivided into fixed size blocks, typically 64 bytes. The main memory is also subdivided into blocks with
the same size as the cache memory blocks, called cache lines.
The cache memory contains copies of certain cache lines in its blocks, and when the processor makes an
attempt to read a word from the main memory, a check is made to determine if that word is in the cache
memory:

If it is (we have a cache hit), it is delivered to the processor.

Otherwise, (we have cache miss), the cache line that contains that word is read from the main memory
into a cache memory block, and the word is delivered to the processor.
The same principle is used for writing a word.
Cache design issues: cache size - block size - mapping function - cache line replacement algorithms - write
policy.
Other Forms of Memory in the Hierarchy
The following are other forms of memory that may be included in the hierarchy:

Secondary storage:

Disk cache:

Expanded storage:
form of internal memory slower than the main memory used on large IBM
mainframes.

Magnetic disks
are also used to provide an extension of the main memory known as virtual
memory.
magnetic disks, optical disks, magnetic tapes.
is a portion of the main memory that is used as cache memory between the magnetic disk
and the main memory and/or registers.
13
Exercises
Part I
Fill in the blanks with the most appropriate answers.
1.
A digital computer system consists of ____________________________ and ______________________________________.
2.
The ________________________________________________________ consists of the physical components of the system.
3.
The ________________________________________________ is the collection of programs that the computer can execute.
4.
The four major components of a digital computer system hardware are: __________________________________________
____________________________________________________________________________________________________.
5.
The central processing unit (CPU) or processor consists of the _____________________________, the
__________________________________, and the ___________________________________________________________.
6.
A _____________________________ is a special high-speed memory location within the CPU that are directly accessed by
both the control unit and the arithmetic and logic unit.
7.
The Input system consists of the ________________________________ and ______________________________________.
8.
An _______________________________________________ transmits information from the outside world to the computer.
9.
The output system consists of the ________________________________ and _____________________________________.
10. An _______________________________________________ transmits information from the computer to the outside world.
11. The __________________________________ is a device within the computer that generates periodic signals that are used to
pace the operations of the CPU.
12. The most basic unit of time for the CPU is the ______________________________________________________________.
13. The among of time that is needed by the CPU to execute an instruction is expressed in terms of ________________________.
14. The speed of the CPU is determined by the following :_________________________________________________________
15. An ________________________________ is a signal to the CPU that an event that needs immediate attention has occurred.
16. The CPU processes an interrupt by passing control to a procedure (function) called __________________________________.
17. The _________________________________________ is a special controller that is used by the CPU for the transfer of data
between the main memory and some I/O controllers, independently of the CPU.
18. The _________________________________ is a high-speed memory that is used to improve performance, by staging the
movement of data between the main memory and the processor registers.
Part II
4.
What are the four major components of a digital computer system hardware?
5.
What are the two mode of operation of most CPU? What is the difference between these two modes of operation?
6.
What are the four major functions of the Control Unit?
7.
What is the major function of the Arithmetic and Logic Unit?
8.
What are the four different types of visible registers found in most CPU? Also provide their functions.
The CPU executes an instruction in three different stages.
14
15
9.
a)
What is the operation performed in each of these stages?
b) Give a description of each of the above operations.
10. To improve performance, many modern processors have facilities for executing more than one instruction at the same time.
a)
What are the two mostly used designs?
b) Also provide a description of each of the above designs
11. What are the three types of memory used in the main memory of most computers today? What is each of the above types of
memory used for?
12. What are the three major functions of an input controller?
13. What are the three major functions of an output controller?
14. What are the four major functions of a hard disk controller?
15. What are the three different types of register in a controller? What is each type of register used for?
16. What are the two different ways to give addresses to the registers of a controller?
17. How do controllers request the attention of the CPU?
18. What is the difference between an internal interrupt and an external interrupt?
19. What are the three different types of bus available in a computer system? What is each type of bus used for?
20. What are the two different bus architectures used in most computer systems? Provide a schematic representation of each of
these architectures.
21. What are the three different ways in which I/O is usually done?
22. Give a description of the programmed I/O.
23. Give a description of interrupt-driven I/O.
24. What are the four pieces of information that the CPU sends to a DMA controller in a DMA I/O?
25. What is the sequence of activities performed by a DMA controller in an I/O transfer?
26. What are the three major characteristics of the memory?
27. What is the memory hierarchy used on most computer systems? As one goes down the hierarchy, what are the four conditions
that hold?
28.What is the principle of locality reference?
29. Describe the process of reading a word from the main memory in a computer system with a cache memory.
30. What are the other forms of memory that may be included in a memory hierarchy?
31. What are the different types of register in a DMA controller? What is each type of register used for?
32. What is the sequence of activities performed by a DMA controller in an I/O transfer?
33. What is the sequence of activities performed by the CPU in the process of reading data from the main memory?
34. What is the sequence of activities performed by the CPU in the process of writing data to the main memory?
35. What is the sequence of activities performed by the memory management unit in the process of reading data from the main
memory?
36. What is the sequence of activities performed by the memory management unit in the process of writing data to the main
memory?
16
1.12 Computer Software
The two major classes of software are system programs and application programs. System programs are
used for the operations of the computer, whereas an application program is used to perform a specific task
or to solve a particular problem for its user.
Application programs are also classified according to the type of task that they perform. For example, a
wordprocessor lets its users create documents with formatting features. It also inserts hidden codes in a
document in order to obtain certain features such as boldfacing, underlining, italic, . . . etc. A data base
management system is a program that makes it possible for its users to create tables of information, and also
provides for easy access and update of information in those tables. A spreadsheet program lets its users
create electronic spreadsheets. Examples of commercial programs running on IBM PC and compatible
computers are WordPerfect and MS Word for wordprocessing, MS Access for data base management, and
MS Excel for electronic spreadsheets. Note that a vast majority of application programs do not fall in any of
the above classes.
Examples of system programs are editors, compilers, assemblers, linkers, loaders, debuggers, and
operating systems.
S An editor reads characters from the keyboard and places them into a file.
S A compiler translates a high-level language program source module into machine language and creates
an object file (module) that contains the machine language code translation of the program.
17
S An assembler translates an assembly language program source module into machine language and
creates an object file (module) that contains the machine language code translation of the program.
S A linker editor or linker combines separately translated object modules and the library functions called
in a program into a single load (or executable) module. It also adjusts the displacements in modules
other that the first, that are to be relative to the start of the final load module, and resolves external
references by providing the pointers needed for the external references in each object module.
S A loader determines how much memory is needed and the starting address for a program, and copies the
load module into memory. It also adjusts relative references to memory locations (that depend on the
starting address of the program) by adding a constant to them, initializes the registers that are necessary
for the execution of the program, and transfers the control of the CPU to the program for execution.
Operating Systems
An operating system is the most fundamental of all system programs. It manages the system resources
(main memory, disks, printers, CPU, . . etc), and also provides an interface to the hardware that is easy to
understand and use in other programs (user programs). It executes when the CPU is in kernel mode whereas
all other programs (user programs) execute when the CPU is in user mode.
It manages the system resources by doing one or more of the following:
S transforming a physical resource
S multiplexing (sharing) a single physical resource
S scheduling a resource.
It transforms a physical resource such as printer or disk drive into a virtual resource that provides the
same functionality but is easier to use (has a simpler interface) in other programs. For example, in a UNIX
environment, an I/O device is transformed into a file.
It multiplexes (shares) a single physical resource by dividing that resource based on time (time-division
multiplexing) or space (space-division multiplexing).
In a time-division multiplexing a resource (such as a processor) is used by different applications at
different times. Time sharing is a version of time-division multiplexing that involves switching a resource
(such as the CPU) between different applications.
In a space-division multiplexing, a resource (such as the main memory or a secondary storage) is
divided into smaller versions of itself and each application is given a part of that resource.
Multiprogramming (or multitasking) is the ability of an operating system to multiplex its resources
among multiple processes (programs in execution) in various stages of execution.
It schedules a resource by deciding which programs should get a resource and when they should get it.
18
Operating systems use system services to provide an interface to the hardware that is easy to use and
understand in user programs.
System services and System Calls
System services, also called kernel services are routines (or functions) within the operating system that may
be invoked by user programs to access the system resources such as the I/O devices, certain memory
locations, and files. Each kernel service is identified by an integer value code that is used as an index into
the service vector table in order to locate the instruction codes that correspond to that service in the kernel.
System services are invoked by user programs by using system calls (in UNIX), or Win32 API
(Application Program Interface) (in Windows). The mechanics of issuing a system call is highly machine
dependent and is often expressed in assembly language. On most computers, it is performed in the following
three steps:
1. Loads the arguments of the system service into specific register(s) or on the stack
2. Load the code of the system service into a specific register
3. Execute a trap (interrupt) instruction to switch the CPU to kernel mode and then invoke the
service.
At the end of the execution of these instruction codes, a special “return” instruction is executed in order to
flip the CPU back into the user mode and returns to the user process.
In a UNIX environment, there is a library function that corresponds to each system call. This library
function is in the standard C language library and is used to invoke the corresponding system call, regardless
of the actual implementation technique used to invoke a system call on any given system. A user program
calls this function using the standard C language calling sequence, and this function then invoke the
corresponding system call by using whatever technique is required on that system. System calls are
documented in section 2 of the UNIX programmer’s manual
According to their functions, system calls fall into the following three major groups:
S
File and I/O
S
process management
S
interprocess communication.
However, a typical operating system will have many more system calls; but most of them will be used in
specific situations to satisfy certain requirements.
Library functions
In a UNIX environment, previously defined functions in languages such as C and FORTRAN that have the
same functionality (e.g. math, string, or graphics routines) are stored in object code format (machine
language) in library (archive) files.
These functions are called library functions or runtime library routines, and may be called in a user
program. By convention, the three-letter prefix of a UNIX library file is lib and the filename extension is .a.
For examples libc.a (standard library); libm.a (math library).
19
The standard location for library files in most UNIX systems is the directory /usr/lib. Ancillary library
files may also be found in the directory /usr/local/lib. The system calls, the C library functions, and the
standard I/O functions form the standard C library . The object codes of these functions are found in the
archive /usr/lib/libc.a. The library functions are documented in section 3 of the UNIX programmer’s
manual.
Note that in a C/C++ program, a function is called in a source module only if it has been previously
defined or declared in that source module. Header files that contain the declarations of library functions are
also provided in a UNIX system, and you must include the header file that contains the declaration of a
function in any source module in which that function is called.
Kernel of the operating system
The kernel of an operating system is the program that is loaded from disk into the main memory when the
computer is first turned on. It always stays in the main memory, and runs until the system is turned off or
crashes. The UNIX kernel contains code for the following:
S
sharing the processor(s) and the main memory between competing processes
S
processing all system calls
S
handling peripherals.
It also contains several data structures that are essential to the functioning of the system. Examples of these
data structures are:
S
the process table, which contains one entry for every process in the system
S
the open-file table, which contains at least one entry for every open file in the system.
These data structures reside in the kernel’s memory space and can be accessed only when the processor is in
control (kernel) mode. The UNIX kernel may also be divided into the following subsystems:
S
memory management
S
process management
S
interprocess communication
S
input/output
S
file management
Virtual memory
Most operating systems also implement and manage a virtual memory. With virtual memory, programs are
allowed to address a memory space that may be larger than the actual main memory. For example, the size
of the virtual memory may be 1 MB, whereas that of the main memory is only 360 KB.
The virtual memory is stored on disk, and is subdivided into blocks. The main memory is also
subdivided into blocks, and a block of the virtual memory is read into the main memory only if it is needed
for computation. The memory management unit of the operating system is responsible for knowing which
blocks of the virtual memory are located in the physical memory versus disk.
20
Device drivers
A device driver is a software interface between an operating system and a peripheral device. It consists of
functions or procedures (in a peripheral-specific code) that the CPU executes in order to communicate (read
or write its registers) with a controller. For example, a keyboard device driver contains a procedure that is
executed to get a character when a key from the keyboard is depressed, and a tape drive device driver
contains a procedure that is executed for rewinding and re-tensioning the tape.
In general, each controller manufacturer has to supply a device driver for each operating system that it
supports. The device driver is then incorporated into the operating system so that it can be executed in
kernel mode. It may be incorporated into an operating system in three different ways:
1. Link the new device driver with the Kernel (main program) of the operating system and reboot the
system. Method used in most UNIX systems.
2. Make an entry in the operating system file, telling that it needs the device driver, and then reboot the
system. At boot time, the operating system finds the device drivers that it needs and loads them. Method
used by Windows
3. The operating system accepts new device drivers while running and installs them without rebooting.
Method used for USB and IEEE 1394 devices.
The interface provided by a device driver can be of two kinds:
S block oriented: physical I/O is performed on a block-by-block (sector) basis, and I/O is buffered by
the kernel. Disk drives and tapes drives have a block-oriented interface.
S character oriented: physical I/O is performed character-by character, and I/O is unbuffered. This kind
of interface is also called raw interface and all peripheral devices including tape drives and disk drives
have this interface.
However, some device drivers contains both kinds of interfaces, and the kind of interface that you choose
depends on how you want to access the device.
All UNIX device drivers must also follow a predefined format which includes a set of standard entry
points for functions that (physically) open, close, and access the peripheral. Block-oriented device drivers
also contain an entry point called strategy that is used by the kernel for performing block-oriented I/O to the
physical device.
All peripheral devices of the same type may be controlled by a single device driver.
21
History of Operating Systems
Operating systems have been evolving through the years, and are closely tied to the architecture of the
computers on which they run. The history of O.S is then presented by looking at successive generations of
computers to see what their O.S were like.
First Generation (1945 - 1955) Vacuum Tubes and Plugboards
 Computers are made of vacuum tubes.
 A single group of people designed, built, programmed, operated, and maintain each machine.
 All programming was done in absolute machine language by wiring up plugboards to control the
machine’s basic functions.
 By the early 1950s, with the introduction of punched cards, programs were punched on cards and read
into the computer, instead of using plugboards.
 There was no O.S.
Second Generation (1955 - 1965) Transistors and Batch Systems
 Computers are made of transistors (introduced in the mid-1950s), and became more reliable.
 There was a clear separation between designers, builders, operators, programmers, and maintenance
personnel.
 Computers are called mainframes and locked in special air conditioned rooms.
 Computers are run by professional operators.
 To run a job (a program or a collection of programs), the following things are done:
1.
A programmer writes the program on paper (in FORTRAN or assembly language)
2. Punches the program on cards
3. Brings the deck of cards to the input room and hand it to an operator
4. When the computer becomes available, an operator reads the deck of cards into the computer for
execution. He also read into the computer whatever software (such as a FORTRAN compiler) is
needed to run the program.
5. When the computer finishes the execution of a job, an operator tears off its output from the printer,
and carry it to the output room where it is collected by the programmer.
Note: the time between the end of the execution of a job and the beginning of the execution of the next job
is called tear-down time. This time is wasted because the CPU is idle. The batch system is
introduced in order to reduce the tear-down time.
22
23
Batch System
 Jobs are collected from the input room and read onto magnetic tapes using a small inexpensive computer
(for example the IBM 1401) good at reading cards, copying tapes, and printing output.
 An operator takes the tape with the batch of jobs to the tape drive of a more expensive computer (such as
the IBM 7094) for execution.
 The operator then loads a special program (the ancestor of today’s O.S) into the computer.
 This special program reads a job from the tape and executes it.
 The output of a program is written onto another tape.
 After a job is finished, the next job is automatically read from the tape and executed by the O.S.
 after all the jobs in the batch are executed, the operator removes the input and the output tapes, replaces
the input tape with the next batch, and takes the output tape to an inexpensive computer for printing off
line.
S Typical O.S were the FMS (Fortran Monitor System) and IBSYS, the IMB’s O.S for the 7094 system.
S Second generation computers are mostly used for scientific and engineering calculations such as solving
partial differential equations.
Third Generation (1965 - 1980) ICs and Multiprogramming
S Integrated circuits (IC) are used to build computers (starting with the IBM System/360).
S The functions of a word-oriented, large-scale scientific computer and character-oriented, commercial
computers are combined into one computer (starting with the IBM System/360).
S The 360 computers are also a series of software-compatible machines (with machines differing only in
price and performance (maximum memory, processor speed, number of I/O devices permitted, . . ., etc).
S One O.S, the OS/360 is used on all those IBM 360 computers. One consequence of this is that the
OS/360 was enormous and very complex.
S Key techniques introduced in O.S are batch multiprogramming, and spooling (Simultaneous
peripheral operation on line).
S Batch multiprogramming is introduced in order to improve CPU utilization and throughput (number of
jobs completed per unit of time)
S With third generation systems, the time between submitting a job and getting back the output is in
general very long. Timesharing is introduced in order to improve programmers response time (the time
between the execution of a command, and the response from the computer)
S Development of the MULTICS (MULTiplexed Information and Computing Service)
S phenomenal growth of minicomputers (PDP- 1 in 1961 to PDP- 11)
S development of the UNIX operating system (by Ken Thompson at Bell Labs)
24
25
Multiprogramming
In a multiprogramming batch system,
S
The memory is partitioned into several pieces, with the O.S in one partition, and a different job in each
partition.
S While the job using the CPU is waiting for I/O operations to complete, the CPU is switched by the O.S to
another job in memory.
S When a job in memory terminates, the O.S selects another job on disk to replace it.
Input Spooling
S jobs are read from cards to disks as soon as they brought to the computer room
S
Whenever a running job terminates, the O.S loads a new job from disk into the new empty partition.
Output spooling The output of a job is sent to disk and then printed later when a printer is available.
Time sharing
S Is a variant of multiprogramming in which each user interfaces directly with the computer through an online terminal.
S In a timesharing system, the CPU is allocated in turn to the jobs that are ready.
S Timesharing systems operate in an interactive or conversational mode with users: the user types a
command (request) to the computer, and the computer processes the request as soon as it can (often
within seconds) and a response (if any) is typed on the user’s terminal.
The first timesharing system was CTSS (Compatible Time Sharing System) developed at MIT.
Fourth Generation (1980 - Present): Personal Computers
 Large Scale Integrated circuits (LSI) are used to build chips used to build personal computers.
 in 1974, a controller for an 8-inch floppy disk is built to be used on the first Intel 8080 personal
computer, making it the first personal computer with disk.
 the first disk-based O.S called CP/M (Control Program for Microcomputers) is later written for the
Intel 8080 personal computer by Digital Research.
 in 1977, Digital Research write CP/M for other processor-based personal computers such as Zilog Z80.
 Many application programs were written to run on CP/M, allowing it to dominate the world of
microcomputers for about 5 years.
 In 1980, IBM introduced the IBM PC using the Intel 8088 processor, running the DOS/BASIC software
package offered by Bill Gates.
 By 1983, MS-DOS (Microsoft Disk Operating System) became the most dominant O.S on the personal
computer market.
 Apple Macintosh was the first personal computer to incorporate the GUI (Graphical User Interface)
 later versions of Microsoft O.S also incorporate the GUI: Windows 95, Windows 98, Windows NT,
Windows 2000, Windows Me (Millennium Edition), Windows XP.
26
 Other major O.S are UNIX, mostly running on workstations and network servers (using RISC
architecture). Linux (a version of UNIX) is becoming popular on Pentium-based computers.
 The fourth generation is also characterized by a growth of networks of personal computers running
network operating systems, and distributed operating systems that started in the mid-1980.
A network O.S is not fundamentally different from a single user O.S. With a network O.S, each
machine runs its own local O.S and has its own local users. But there is a need for a network interface
controller and some low-level software to drive it. Users are aware of the existence of other computers, and
can use programs to achieve remote login and remote file access. But the addition of these programs does
not change the essential structure of the O.S.
A distributed O.S appears to its user as a traditional uniprocessor system: a user should not be aware of
where his program is run, or where his files are located. It should be handled automatically by the O.S. A
distributed O.S. may also allow applications to run in parallel on several processors at the same time. A
distributed O.S. may also be designed with the expectation that it will continue to run even if part of the
hardware fails (Fault-tolerance property).
Fifth Generation (1990 - Present): Mobile Computers
 The first smartphone appeared in the mid-1990s with the release of the Nokia N9000 which combined a
phone and a PDA (Personal Digital Assistant).
 Now that we have a proliferation of smart phones, the competition between various operating systems is
fierce: At the moment, Google’s Android (a Linux-based OS) is the dominant operating system and is
followed by Apple iOS. Other OS for smartphones are Symbian OS, Blackberry’s RIM OS, and
Windows.
Different Types of Operating Systems
S Mainframe Operating Systems
S Server Operating Systems
S Multiprocessor Operating Systems
S personal Computer Operating Systems
S Real Time Operating Systems
S Embedded Operating Systems
S Smart Card Operating Systems
Operating System Structure
S Monolithic Systems
S Layered Systems
S Virtual machines
S Exokernels
S Client-Server Model
27
Exercises
Part I
Fill in the blanks with the most appropriate answers.
19.
A _______________________________________ is a program that is used for the operation of the computer
20.
An _____________________________________ is a program that is used to perform a task or to solve a problem for its
user.
21.
A ____________________ combines separately translated object modules and the library functions called in a program
into a single load (or executable) module.
22.
A ____________________ adjusts the displacements in object modules other that the first, that are to be relative to the
start of the final load module, and resolves external references by providing the pointers needed for the external
references in each object module.
23.
A ________________ determines how much memory is needed and the starting address for a program, and copies the
load module into memory.
24.
A _________________ adjusts relative references to memory locations (that depend on the starting address of the
program) by adding a constant to them, initializes the registers that are necessary for the execution of the program, and
transfers the control of the CPU to the program for execution.
25.
An _________________________________________ manages the system resources and also provides an interface to the
hardware that is easy to understand and use in other programs.
26.
An _________________________________________ is the only program that execute when the CPU is in kernel mode.
27.
In a _____________________________ system, a resource (such as a processor) is used by different applications at
different times.
28.
______________________ is a version of time-division multiplexing system that involves switching a resource (such as
the CPU) between different applications.
29.
In a ___________________________________ system, a resource (such as the main memory or a secondary storage) is
divided into smaller versions of itself and each application is given a part of that resource.
30.
______________________________________ is the ability of an operating system to multiplex its resources among
multiple processes (programs in execution) in various stages of execution.
31.
In a ___________________________________________ system, the CPU is allocated in turn to the jobs that are ready.
32.
____________________________________________ are routines (or functions) within the operating system that may be
invoked by user programs to access the system resources such as I/O devices, files, and certain memory locations.
33.
_________________________________________ are used by user programs to invoke an operating system services.
34.
The ____________________________ of an operating system is a program that is loaded from disk into the main
memory when the computer is first turned on. It always stays in the main memory, and runs until the system is turned off
or crashes.
35.
With _______________________________, programs are allowed to address a memory space that may be larger than the
actual main memory.
36.
A _________________________ is a software interface between an operating system and a peripheral device.
37.
A ___________________________ consists of functions or procedures (in a peripheral-specific code) that the CPU
executes in order to communicate (read or write its registers) with a controller.
28
Part II
1.
What are the two major classes of software?
2.
Name four types of application programs.
3.
Name four system programs.
4.
What does a linker do?
5.
What does a loader do?
6.
What are the two major functions of a modern operating system?
7.
What are the different operations that an operating systems performs in order to manage system resources? Give a description
of each of these operations.
8.
How does an operating system provide an interface to the hardware to other programs?
9.
How does a user program invoke a system service?
10. Why are system calls not provided in high-level languages?
11. Describe the three steps used in the execution of a system call.
12. How do you determine that a filename is the name of a library file in a UNIX system?
13. What are the two major tables contained in a UNIX kernel?
14. What are the subsystems of most UNIX kernel?
15. Describe the three different ways in which a device driver is incorporated into an operating system.
16. What are the two different types of interface provided by device drivers? Give a description of each of these types of
interface.
17. What are the primary reason(s) for the introduction of each of the following operating system techniques:
i)
Mono-programming batch system.
ii) Multiprogramming batch system.
iii) Timesharing.
18. Provide a brief description of each of the following:
a)
Mono-programming batch system.
c)
Input spooling.
b) Multiprogramming batch system.
d) Output spooling.
19. Describe each of the following operating systems:
a)
Mainframe operating system
c)
Real-time operating system
b) server operating system
20 what are the different types of operating systems?
21 describe the different ways in which processors cooperate in a multiprocessing system.
22. What is the major difference between a network system and a distributed system.
23. Name three operating system structures.
24. Describe each of the following operating system structures:
a) Monolithic systems
b) virtual machine
c) client-server model.
Download