Input / Output System

Introduction
Input/Output, or I/O, refers to the communication between an information processing system (such as a computer), and the outside world possibly a human, or another information processing system as applied in computing. Inputs are signals or data received by the system from an input device, and outputs are the signals or data sent from the computer via an output device.

The term can also be used as part of an action; to "perform I/O" is to perform an input or output operation. I/O devices are used by a person (or other system) to communicate with a computer.

Input devices include a keyboard or a mouse among others, while monitor sand printers are considered output devices for a computer. Devices for communication between computers, such as modems and network cards, typically serve for both input and output.



Goals of Input and Output
• The OS, without the intervention of the user program, should handle recoverable errors. • Users should access all devices in a uniform manner. • Devices should be named in a uniform manner. • The OS must maintain security of the devices. • The OS should optimize the performance of the I/O system.

In computer architecture, any transfer of information from or to the CPU and main memory, for example to or from a disk drive, is considered I/O. The CPU and its supporting circuitry provide memory-mapped I/O that is used in low-level computer programming in the implementation of device drivers. An I/O algorithm is one designed to exploit locality and perform efficiently when data reside on secondary storage, such as a disk drive. Port-mapped I/O usually requires the use of instructions which are specifically designed to perform I/O operations.

BIOS
Basic Input/Output System (BIOS), also known as the system BIOS or ROM BIOS, is a de facto standard defining a firmware interface. The name originated from the Basic Input Output System used in the CP/M operating system. The BIOS software is built into the PC, and is the first software run by a PC when powered on. The fundamental purposes of the BIOS are to initialize and test the system hardware components, and to load an operating system or other programs from a mass memory device. The BIOS provides a consistent way for application programs and operating systems to interact with the keyboard, display, and other input/output devices. Variations in the system hardware are hidden by the BIOS from programs that use BIOS services instead of directly accessing the hardware.

The BIOS of the original IBM PC/XT had no interactive user interface. Error messages were displayed on the screen, or coded series of sounds were generated to signal errors. Options on the PC and XT were set by switches and jumpers on the main board and on peripheral cards. Modern Wintel-compatible computers provide a setup routine, accessed at system power-up by a particular key sequence. The user can configure hardware options using the keyboard and video display.

BIOS software is stored on a non-volatile ROM chip on the motherboard. It is specifically designed to work with each particular model of computer, interfacing with various devices that make up the complementary chipset of the system. In modern computer systems, the BIOS contents is stored on an EEPROM chip so that the contents can be rewritten without removing the chip from the motherboard. This allows BIOS software to be easily upgraded to add new features or fix bugs.

BIOS Boot Process
When the micro-processor (CPU or processor) is reset, it loads its program counter with a fixed address near the top of the 1 megabyte real-mode address space. The BIOS ROM chips are located in memory so that this starting address is within the BIOS. A jump instruction then directs the processor to start executing code in the BIOS. If the system has just been powered up ("cold boot"), the full power-on self-test (POST) is run. If the reset button was pressed ("warm boot"), a special flag value is detected in memory and the BIOS does not run the POST. This saves the time otherwise used to test all memory.

The power-on self-test tests, identifies, and initializes system devices such as the CPU, RAM, interrupt and DMA controllers and other parts of the chipset, video display card, keyboard, hard disk drive, optical disc drive and other basic hardware. The BIOS then locates boot loader software held on a storage device designated as a 'boot device', such as a hard disk, a floppy disk, or a CD/DVD, and loads and executes that software, giving it control of the PC.[7] This process is known as booting, or booting up, which is short for "bootstrapping".

Booting Devices
The BIOS selects candidate boot devices using information collected by POST and configuration information from EEPROM, CMOS RAM or, in the earliest PCs, DIP switches. Option ROMs may also influence or supplant the boot process defined by the motherboard BIOS ROM. The BIOS checks each device in order to see if it is bootable. For a disk drive or a device that logically emulates a disk drive, such as a USB Flash drive or perhaps a tape drive, to perform this check the BIOS attempts to load the first sector (boot sector) from the disk to address 7C00 hexadecimal, and checks for the boot sector signature 0x55 0xAA in the last two bytes of the sector. If the sector cannot be read (due to a missing or blank disk, or due to a hardware failure), or if the sector does not end with the boot signature, the BIOS considers the disk unbootable and proceeds to check the next device. Another device such as a network adapter attempts booting by a procedure that is defined by its option ROM (or the equivalent integrated into the motherboard BIOS ROM). The BIOS proceeds to test each device sequentially until a bootable device is found, at which time the BIOS transfers control to the loaded sector with a jump instruction to its first byte at address 7C00 hexadecimal (1 KiB below the 32 KiB mark). A computer that failed to boot from a disk would display "No ROM BASIC" and halt. Later computers would display a message like "No bootable disk found." Modern BIOSes may display nothing or may automatically enter the BIOS configuration utility when the boot process fails.

Historically, the BIOS would try to boot from a floppy drive first and a hard disk second. CD or DVD booting is an extension of this.

Boot Environment
The environment for the boot program is very simple: the CPU is in real mode and the general-purpose and segment registers are undefined. All BIOS services are available, and the memory below address 500 hex contains the interrupt vector table and the 256-byte BIOS data area, but the boot program must set up its own stack. All memory at and above address 500 hex can be used by the boot program; it may even overwrite itself. The BIOS initializes a reserved block of system RAM with various parameters initialized during the POST. The interrupt vectors corresponding to the BIOS interrupts have been set to point at the appropriate entry points in the BIOS.

Interaction b/w user and i/o


The output from the input devices is input for the computer. Similarly, printers and monitors take as input signals that a computer outputs. They then convert these signals into representations that human users can see or read. For a human user the process of reading or seeing these representations is receiving input. These interactions between computers and humans is studied in a field called human–computer interaction.

i/o procedure
A user process requesting I/O makes a call in the form:-DOIO(stream, mode, amount, destination, semaphores) Where DOIO is the name of the relevant I/O procedure

stream:- is the identification number of the stream on which I/O is to take place

mode:- is the operation required,- input, output, scan, etc,- may indicate character code too

amount: how much data to be transferred.destination (source): memory area where data is to be transferred to/from

semaphore: address of semaphore 'request serviced' to be signaled by the device handler when I/O operation is complete.

input output management in operating systems
Humans interact with machines by providing information through IO devices. Much of whatever a computer system provides as on-line services is essentially made available through specialized devices such as screen displays, printers, keyboards, mouse, etc. Clearly, management of all these devices can affect the throughput of a system. For this reason, input output management also becomes one of the primary responsibilities of an operating system.

Communication is required at thefollowing three levels:

�� The need for a human to input information and receive output from a computer.

�� The need for a device to input information and receive output from a computer.

�� The need for computers to communicate (receive/send information) over networks.

Internal Interrupt
The source of interrupt may be a memory resident process or a function from within the processor. We regard such an interrupt as an internal interrupt. A processor malfunction results in an internal interrupt. An attempt to divide by zero or execute an illegal or non-existent instruction code results in an internal interrupt as well. A malfunction arising from a division by zero is called a trap. Internal interrupt may be caused by a timer as well. This may be because either the allocated processor time slice to a process has elapsed or for some reason the process needs to be pre-empted.

Note that an RTOS may pre-empt a running process by using an interrupt to ensure that the stipulated response time required is met. This would also be a case of internal interrupt.

External Interrupt
If the source of interrupt in not internal, i.e. it is other than a process or processor related event then it is an external interrupt. This may be caused by a device which is seeking attention of a processor. As indicated earlier, a program may seek an IO and issue an IO command but proceed. After a while, the device from which IO was sought is ready to communicate. In that case the device may raise an interrupt. This would be a case of an external interrupt.

Software Interrupt
Most OSs offer two modes of operation, the user mode and the system mode. Whenever a user program makes a system call, be it for IO or a special service, the operation must have a transition from user mode to system mode. An interrupt is raised to effect this transition from user to system mode of operation. Such an interrupt is called a software interrupt. We shall next examine how an interrupt is serviced. Suppose we are executing an instruction at i in program P when interrupt signal has been raised. Let us also assume that we have an interrupt service routine which is to be initiated to service the interrupt. The following steps describe how a typical interrupt service may happen.

DMA (Direct memory access)Mode of Data Transfer
This is a mode of data transfer in which IO is performed in large data blocks. For instance, the disks communicate in data blocks of sizes like 512 bytes or 1024 bytes. The direct memory access, or DMA ensures access to main memory without processor intervention or support. Such independence from processor makes this mode of transfer extremely efficient. When a process initiates a direct memory access (DMA) transfer, its execution is briefly suspended (using an interrupt) to set up the DMA control. The DMA control requires the information on starting address in main memory and size of data for transfer. This information is stored in DMA controller. Following the DMA set up, the program resumes from the point of suspension. The device communicates with main memory stealing memory access cycles in competition with other devices and processor. of disk to main memory transfer in DMA mode. We first note that there is a disk controller to regulate communication from one or more disk drives. This controller essentially isolates individual devices from direct communication with the CPU or main memory. The communication is regulated to first happen between the device and the controller, and later between the controller and main memory or CPU if so needed. Note that these devices communicate in blocks of bits or bytes as a data stream. Clearly, an unbuffered communication is infeasible via the data bus. The bus has its own timing control protocol.

Once the controller buffer has the required data, then one can envisage to put the controller in contention with CPU and main memory or CPU to obtain an access to the bus. Thus if the controller can get the bus then by using the address and data bus it can directly communicate with main memory. This transfer shall be completely independent of program control from the processor memory.

IO management requires that a proper set-up is created by an application on computer system with an IO device. An IO operation is a combination of HW and SW instructions as shown below. Following the issuance of an IO command, OS kernel resolves it, and then communicates



Handling Interrupt Using Device Drivers
Let us assume we have a user process which seeks to communicate with an input device using a device driver process. Processes communicate by signaling. The steps describe the complete operational sequence (with corresponding numbers).

1. Register with listener chain of the driver: The user process P signals the device driver as process DD to register its IO request. Process DD maintains a list data structure, basically a listener chain, in which it registers requests received from processes which seek to communicate with the input device.

2. Enable the device: The process DD sends a device enable signal to the device.

Spooling
Suppose we have a printer connected to a machine. Many users may seek to use the printer. To avoid print clashes, it is important to be able to queue up all the print requests. This is achieved by spooling. The OS maintains all print requests and schedules each users' print requests. In other words, all output commands to print are intercepted by the OS kernel. An area is used to spool the output so that a users' job does not have to wait for the printer to be available. One can examine a print queue status by using lpq and lpstat commands in Unix.

Clocks
The CPU has a system clock. The OS uses this clock to provide a variety of system- and application-based services. For instance, the print-out should display the date and time of printing. Below we list some of the common clock-based services.

�� Maintaining time of day. (Look up date command under Unix.)

�� Scheduling a program run at a specified time during systems' operation. (Look up at and cron commands under Unix.)

�� Preventing overruns by processes in preemptive scheduling. Note that this is important for real-time systems. In RTOS one follows a scheduling policy like the earliest deadline first. This policy may necessitate preemption of a running process.

�� Keeping track of resource utilization or reserving resource use.

�� Performance related measurements (like timing IO, CPU activity).

Addressing a device
Most OSs reserve some addresses for use as exclusive addresses for devices. A system may have several DMA controllers, interrupt handling cards (for some process control), timers, serial ports (for terminals) or terminal concentrators, parallel ports (for printers), graphics controllers, or floppy and CD ROM drives, etc. A fixed range of addresses allocated to each of these devices. This ensures that the device drives communicate with the right ports for data.

Caching
A cache is an intermediate level fast storage. Often caches can be regarded as fast buffers. These buffers may be used for communication between disk and memory or memory and CPU. The CPU memory caches may used for instructions or data. In case cache is used for instructions, then a group of instructions may be pre-fetched and kept there. This helps in overcoming the latency experienced in instruction fetch. In the same manner, when it is used for data it helps to attain a higher locality of reference. As for the main memory to disk caches, one use is in disk rewrites. The technique is used almost always to collect all the write requests for a few seconds before actually a disk is written into. Caching is always used to enhance the performance of systems.

I/O channels
An IO channel is primarily a small computer to basically handle I/O from multiple sources. It ensures that I/O traffic is smoothed out.

OS and CDE
The common desk top environment (CDE) is the norm now days. An OS provides some terminal-oriented facilities for operations in a CDE. In particular the graphics user interface (GUI) within windows is now a standard facility. The kernel I/O system recognizes all cursor and mouse events within a window to allow a user to bring windows up, iconize, scroll, reverse video, or even change font and control display. The I/O kernel provides all the screen management functions within the framework of a CDE.

I/O Buffering
Instead of reading or writing data directly from the user’s memory, it is copied to or from an OS buffer Reasons for buffering:

– Processes must wait for I/O to complete before proceeding

– Certain pages must remain in main memory during I/O

Single Buffer
• Operating system assigns a buffer in main memory for an I/O request

• Block-oriented

– Input transfers made to buffer

– Block moved to user space when needed

– Another block is moved into the buffer

Double Buffer
• Use two system buffers instead of one

• A process can transfer data to or from one buffer while the operating system empties or fills the other buffer.

• More than two buffers can be used for circular buffering

Levels of I/O
• User program

• User level I/O functions

• Device-independent OS software

• Device drivers

• Interrupt handlers