Você está na página 1de 8

Chapter 1

Computer System

1.1 Introduction

An operating system OS is a layer of software that acts as an interface between a


computer user and the computer hardware. It manages the computer resources
like the memory, the input/output devices and files. It can thus be said to that it
exploits the hardware resources of one or more processors to provide a set of
services to the system users. The OS also manages secondary memory and I/O
(input/output) devices on behalf of its users. Its functions can be summarized below
as:

1. User interface: It allows the user to interact with the operating system in
order to access the hardware resources.
2. Memory management: The OS manages memory by allocating memory to
the currently running programs
3. Process management: OS schedules the processing power of the processor,
the memory and the hardware to programs it is running.
4. Device management: OS initiates the hardware devices and controls the
sending or receiving of data
5. File management: OS also controls the opening, closing and access
permissions to a file.

OS classification is either based on based on the number of users using the system
simultaneously or on the number of tasks being performed by the computer
simultaneously.

According to the number of simultaneous users we have

1. Single user OS: it is an OS where only one user can access the resources of
the computer at one time.
2. Multi-user OS: it is an OS where more than one user can access the computer
resources simultanoeusly.

According to the number of tasks being performed at the same time, we have

1. Single tasking: It is an OS which allows a user to perform only a single task at


a time
2. Multi-tasking: it is an OS that permits a user to execute multiple programs
simultaneously

Before continuing our discussion on OS it is important to get a good background on


the underlying computer system hardware. At a top level, a computer consists of a
processor, a memory, and Input/Output (I/O) components. Each of this could have
one or more modules. These components are interconnected in some fashion to
achieve the main function of the computer, which is to execute programs. Thus,
there are four main structural elements:

1
1. The Processor: This controls the operations of the computer and performs
its data processing functions. When there is only one processor, it is often
referred to as the central processing unit (CPU).

2. Main memory: It stores data and programs. This memory is typically


volatile, that is, when the computer is shut down, the contents of the memory
are lost. In contrast, the contents of disk memory are retained even when the
computer system is shut down. Main memory is also referred to as real
memory or primary memory.

3. I/O modules: This moves data between the computer and its external
environment. The external environment may consist of a variety of devices,
including secondary memory devices, communications equipment, and
terminals.

4. System bus: This provides for communication among the processors, the
main memory, and the I/O modules.

The figure below depicts these top-level components. One of the processor’s
functions is the exchange of data with the memory. For this purpose, among other
registers that it might contain, it typically makes use of two internal (to the
processor) registers. The memory address register (MAR), which specifies the
address in the memory for the next read or write operation, and the memory
buffer register (MBR),which contains the data to be written into the memory or
which receives the data read from the memory. Similarly, an I/O address register
(I/OAR) specifies a particular I/O device. An I/O buffer register (I/OBR) is used for the
exchange of data between an I/O module and the processor.

The memory module consists of a set of locations, defined by sequentially


numbered addresses. Each location contains a bit pattern that can be interpreted as
either an instruction or data. An I/O module transfers data from external devices to
processor and memory, and vice versa. It contains internal buffers for temporarily
holding data until they can be sent on.

1.1.1 Processor Registers


PROCESSOR REGISTERS
The processor contains a set of registers that constitute a memory that is faster and
smaller than the main memory. These registers are divided into two according to
their functions:

User-visible registers: These registers are accessible to programmers. These


enable the machine or assembly language programmer to minimize main memory
references by optimizing register use. For high level languages, an optimizing
compiler will attempt to make intelligent choices of which variables to assign to
registers and which to main memory locations. Some high-level languages, such as
C, allow the programmer to suggest to the compiler which variables should be held
in registers.

2
Control and status registers: These are used by the processor to control the
operations of the processor and by privileged OS routines to control the execution
of programs. They are not accessible to programmers.

1.1.1.1 User-Visible Registers

A user-visible register may be referenced by means of the machine language


program that the processor executes and is generally available to all programs,
including application programs as well as system programs. Types of registers that
are typically available are data, address, and condition code registers.

Data registers can be assigned to a variety of functions by the programmer. In


some cases, they are general purpose in nature and can be used with any machine
instruction that performs operations on data. Often, however, there are restrictions.
For example, there may be dedicated registers for floating-point operations and
others for integer operations.

Address registers contain main memory addresses of data and instructions, or


they contain a portion of the address that is used in the calculation of the complete
or effective address. These registers may themselves be general purpose, or may
be devoted to a particular way, or mode, of addressing memory.
3
Examples of address registers include the following:

Index register: Keeps only an index to add to a base value to get the effective
address.
Segment pointer: Memory is divided into segments. Reference is made to a
particular segment only to get location. This mode of addressing is important in
memory management.
Stack pointer: If there is user-visible stack addressing, then there is a dedicated
register that points to the top of the stack. This allows the use of instructions like as
push and pop.

1.1.1.2 Control and Status Registers

A variety of processor registers are employed to control the operations of the


processor. On most processors, most of these are not visible to the user. Some of
them may be accessible by machine instructions executed in what is referred to as
a control or kernel mode.

Different processors may have different register organizations and use different
terminologies. An almost complete list of these types of registers is given here in
addition to the MAR, MBR, I/OAR, and I/OBR registers mentioned earlier. These are:

Program counter (PC): It contains the address of the next instruction to be


fetched
Instruction register (IR): It contains the instruction most recently fetched
Program status word (PSW): All processor have a register or set of registers,
that contains status information. Status information include flags, interrupt
enable/disable bit, and a kernel/user mode bit.
Flags or Condition codes: These are bits typically set by the processor hardware
as the result of operations.
Interrupt registers: In processors with multiple types of interrupts, a set of
interrupt registers may be provided with one pointer to each interrupt-handling
routine.

One key issue to processor design is OS support. Certain types of control


information are of specific utility to the OS. If the processor designer has a
functional understanding of the OS to be used, then the register organization can be
designed to provide hardware support for particular features such as memory
protection and switching between user programs.

1.2 Instruction Execution

A program to be executed by a processor consists of a set of instructions stored in


memory. In its simplest form, instruction processing consists of two steps. The
processor first reads (fetches) an instruction from the memory and then executes it
before reading another. Program execution consists of repeating the process of
instruction fetch and instruction execution. Instruction execution may involve
several operations and depends on the nature of the instruction.

4
The processing required for a single instruction is called an instruction cycle. Using
a simplified two-step description, the instruction cycle is depicted in the Figure
below.

The two steps are referred to as the fetch stage and the execute stage. Program
execution halts only if either the processor is turned off, some sort of unrecoverable
error occurs, or a program instruction is encountered that halts the processor.

Instruction Fetch and Execute

At the beginning of each instruction cycle, the processor fetches an instruction from
memory. Typically, the program counter (PC) holds the address of the next
instruction to be fetched. Unless instructed otherwise, the processor always
increments the PC after each instruction fetch so that it will fetch the next
instruction in sequence. Assume that the program counter is set to location
300.The processor will fetch the next instruction at location 300. On succeeding
instruction cycles, it will fetch instructions from locations 301, 302, 303, and so on.
This sequence may be altered, whenever the need arises.

The fetched instruction is loaded into the instruction register (IR). The instruction
contains bits that specify the action the processor is to take. The processor
interprets the instruction and performs the required action. In general, these actions
fall into four categories:

1. Processor-memory: Data may be transferred from processor to memory or


from memory to processor.
2. Processor-I/O: Data may be transferred to or from peripheral devices.
3. Data processing: The processor may perform some arithmetic or logic
operation on data.
4. Control: An instruction may specify that the sequence of execution be
altered. For example, the processor may fetch an instruction from location
149, which specifies that the next instruction be from location 182.The
processor sets the program counter to 182. Thus, on the next fetch stage, the
instruction will be fetched from location 182 rather than 150.

5
An instruction’s execution may involve a combination of these actions

The Figure below illustrates a partial program execution, showing the relevant
portions of memory and processor registers. The program fragment shown adds the
contents of the memory word at address 940 to the contents of the memory word at
address 941 and stores the result in the latter location.

Three instructions, which can be described as three fetch and three execute stages,
are required:

1. The PC contains 300, the address of the first instruction. This instruction (the
value 1940 in hexadecimal) is loaded into the IR and the PC is incremented.
2. The first 4 bits (first hexadecimal digit) in the IR indicate that the AC is to be
loaded from memory. The remaining 12 bits (three hexadecimal digits)
specify the address, which is 940.
3. The next instruction (5941) is fetched from location 301 and the PC is
incremented.
4. The old contents of the AC and the contents of location 941 are added and
the result is stored in the AC.
5. The next instruction (2941) is fetched from location 302 and the PC is
incremented.
6. The contents of the AC are stored in location 941.

In this example, three instruction cycles, each consisting of a fetch stage and an
execute stage, are needed to add the contents of location 940 to the contents of
941. With a more complex set of instructions, fewer instruction cycles would be
needed.

Most modern processors include instructions that contain more than one address.
Thus the execution stage for a particular instruction may involve more than one
reference to memory. Also, instead of memory references, an instruction may
specify an I/O operation.

6
I/O Function

Data can be exchanged directly between an I/O module (e. g., a disk controller) and
the processor. Just as the processor can initiate a read or write with memory,
specifying the address of a memory location, the processor can also read data from
or write data to an I/O module. In this latter case, the processor identifies a specific
device that is controlled by a particular I/O module. Thus, an instruction sequence
similar in form to the one seen above could occur, with I/O instructions rather than
memory-referencing instructions.

In some cases, it is desirable to allow I/O exchanges to occur directly with main
memory to relieve the processor of the I/O task. In such a case, the processor
grants to an I/O module the authority to read from or write to memory, so that the
I/O memory transfer can occur without tying up the processor. During such a
transfer, the I/O module issues read or write commands to memory, relieving the
processor of the responsibility for the exchange. This operation is known as direct
memory access (DMA).

1.3 Interrupts

Virtually all computers provide a mechanism by which other modules (I/O, memory)
may interrupt the normal sequencing of the processor. Table 1.1 lists the most
7
common classes of interrupts. Interrupts are provided primarily as a way to improve
processor utilization. For example, most I/O devices are much slower than the
processor. Suppose that the processor is transferring data to a printer using an
instruction cycle scheme. After each write operation, the processor must pause and
remain idle until the printer catches up. The length of this pause may be on the
order of many thousands or even millions of instruction cycles. Clearly, this is a very
wasteful use of the processor.

To give a specific example, consider a PC that operates at 1 GHz, which would allow
roughly 109 instructions per second. A typical hard disk has a rotational speed of
7200 revolutions per minute for a half-track rotation time of 4 ms, which is 4 million
times slower than the processor.

Você também pode gostar