06-10-2016, 09:34 AM
1457957271-unit1.docx (Size: 1.24 MB / Downloads: 4)
1.1 Introduction:
Definition:
An operating systemacts as an intermediary between the user of acomputer and the computer hardware.
Goal:
The purpose of an operatingsystem is to provide an environment in which a user can executeprograms in a convenientand efficientmanner.
An operating system is software that manages the computer hardware.The hardware must provide appropriate mechanisms to ensure thecorrect operation of the computer system and to prevent user programsfrom interfering with the proper operation of the system.
1.2 Computer System Overview:
12.1 Basic Elements:
At a top level, a computer consists of processor, memory, and I/O components, withone or more modules of each type. These components are interconnected to achieve the main function of the computer, which is to execute programs.
There are four main structural elements:
• Processor: Controls the operation 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).
• Main memory: 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 memoryor primary memory.
• I/O modules: Move data between the computer and its external environment. The external environment consists of a variety of devices, including secondary memory devices (e.g., disks), communications equipment, and terminals.
• System bus: Provides for communication among processors, main memory, and I/O modules.
Figure 1 depicts these top-level components. One of the processor’s functionsis to exchange data with memory. For this purpose, it typically makes use oftwo internal (to the processor) registers:
• Memory addresses register (MAR), which specifies the address in memory for the next read or write.
• Memory buffer register (MBR), which contains the data to be written into memory or which receivesthe data read from 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.
A memory module consists of a set of locations, defined by sequentially numberedaddresses. Each location contains a bit pattern that can be interpreted aseither an instruction or data.
An I/O module transfers data from external devices toprocessor and memory, and vice versa. It contains internal buffers for temporarilyholding data until they can be sent on.
Instruction Execution:
A program to be executed by a processor consists of a set of instructions storedin memory. In its simplest form, instruction processing consists of two steps. The two steps are referred to as the fetch stage and the execute stage.:
• The processor reads ( fetches ) instructions from memory one at a time and executes each
instruction.
• 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. The processing required for a single instruction is called an instruction cycle.
• Program executionhalts only if the processor is turned off, some sort of unrecoverable error occurs,or a program instruction that halts the processor is encountered.
• At the beginning of each instruction cycle, the processor fetches an instructionfrom memory. Typically, the program counter (PC) holds the address of thenext instruction to be fetched. Unless instructed otherwise, the processor alwaysincrements the PC after each instruction fetch so that it will fetch the next instructionin sequence (i.e., the instruction located at the next higher memory address).
• Example:
Consider a simplified computer in which each instruction occupies one16-bit word of memory. Assume that the program counter is set to location 300.The processor will next fetch the instruction at location 300. On succeeding instructioncycles, it will fetch instructions from locations 301, 302, 303, and so on. Thissequence may be altered, as explained subsequently.
• The fetched instruction is loaded into the instruction register (IR). Theinstruction contains bits that specify the action the processor is to take. The processorinterprets the instruction and performs the required action. Theseactions fall into four categories:
1. Processor-memory: Data may be transferred from processor to memoryorfrom memory to processor.
2. Processor-I/O: Data may be transferred to or from a peripheral device bytransferring between the processor and an I/O module.
3. Data processing: The processor may perform some arithmetic or logic operationon 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 will 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.
The processor contains a single data register,called the accumulator (AC). Both instructions and data are 16 bits long,and memory is organized as a sequence of 16-bit words. The instruction formatprovides 4 bits for the opcode, allowing as many as 24= 16 different opcodes (representedby a single hexadecimal 1 digit). The opcode defines the operation theprocessor is to perform. With the remaining 12 bits of the instruction format, up to212= 4,096 (4K) words of memory (denoted by three hexadecimal digits) can bedirectly addressed.
Figure 4 illustrates a partial program execution, showing the relevantportions of memory and processor registers. The program fragment shown adds thecontents of the memory word at address 940 to the contents of the memory word ataddress 941 and stores the result in the latter location.
The I/O program consists of three sections:
• A sequence of instructions, labeled 4 in the figure 1.5, prepare for the actual I/O operation. This may include copying the data to be output into a special buffer and preparing the parameters for a device command.
• The actual I/O command. Without the use of interrupts, once this command is issued, the program must wait for the I/O device to perform the requested function (or periodically check the status, or poll, the I/O device). The program might wait by simply repeatedly performing a test operation to determine if the I/O operation is done.
• A sequence of instructions, labeled 5 in the figure 1.5, to complete the operation. This may include setting a flag indicating the success or failure of the operation.
The dashed line shows the sequence in which instructions are executed. Thus, afterthe first WRITE instruction is encountered, the user program is interrupted andexecution continues with the I/O program. After the I/O program execution is complete,execution resumes in the user program immediately following the WRITEinstruction.Because the I/O operation may take a relatively long time to complete, the I/Oprogram is hung up waiting for the operation to complete; hence, the user programis stopped at the point of the WRITE call for some considerable period of time.
Interrupts and the Instruction Cycle
With interrupts, the processor can be engaged in executing other instructions whilean I/O operation is in progress. Consider the flow of control in Figure 1.5b.
• The user program reaches a point at which it makes a system call in the form of a WRITE call. The I/O program that is invoked in this case consists only of the preparation code and the actual I/O command.
• After these few instructions have been executed, control returns to the user program.
• Meanwhile, the external device is busy accepting data from computer memory and printing it. This I/O operation is conducted concurrently with the execution of instructions in the user program.
• When the external device becomes ready to accept more data from the processor, the I/O module for that external device sends an interrupt requestsignal to the processor.
• The processor responds by suspending operation of the current program. It branches off to a routine to service that particular I/O device, known as an interrupt handler. It resumes the original execution after the device is serviced.