Lecture 4
Lecture 4
COB 2225
I/O ORGANIZATION
I/0 ORGANIZATION
• In general, the rate of transfer from any input device to the processor, or from the
processor to any output device is likely to the slower than the speed of a processor.
– The difference in speed makes it necessary to create mechanisms to synchronize
the data transfer between them.
– Two mechanisms for synchronizing data transfers between the processor and
memory are the following:
Interrupts.
Direct Memory Access.
INTERRUPTS
• In program-controlled I/O, when the processor continuously monitors the status of the
device, it does not perform any useful tasks.
• An alternate approach would be for the I/O device to alert the processor when it
becomes ready.
– Do so by sending a hardware signal called an interrupt to the processor.
– At least one of the bus control lines, called an interrupt-request line is dedicated
for this purpose.
• Processor can perform other useful tasks while it is waiting for the device to be ready.
INTERRUPTS
Cont..
Interrupt
occurs i
here
i +1
M
INTERRUPTS
• Saving and restoring information can be done automatically by the processor or explicitly by program
instructions.
• Saving and restoring registers involves memory transfers:
– Increases the total execution time.
– Increases the delay between the time an interrupt request is received, and the start of execution of the
interrupt-service routine. This delay is called interrupt latency.
• In order to reduce the interrupt latency, most processors save only the minimal amount of information:
– This minimal amount of information includes Program Counter and processor status registers.
• Any additional information that must be saved, must be saved explicitly by the program instructions at the
beginning of the interrupt service routine.
INTERRUPTS
• Interrupt-requests interrupt the execution of a program, and may alter the intended
sequence of events:
– Sometimes such alterations may be undesirable, and must not be allowed.
– For example, the processor may not want to be interrupted by the same device while
executing its interrupt-service routine.
• Processors generally provide the ability to enable and disable such interruptions as desired.
• One simple way is to provide machine instructions such as Interrupt-enable and Interrupt-
disable for this purpose.
INTERRUPTS
• How does the processor know which device has generated an interrupt?
• How does the processor know which interrupt service routine needs to be
executed?
• When the processor is executing an interrupt service routine for one device, can
other device interrupt the processor?
• If two interrupt-requests are received simultaneously, then how to break the
tie?
INTERRUPTS
• Interrupt service routine can poll the I/O devices connected to the bus. The first device
with IRQ equal to 1 is the one that is serviced.
• Polling mechanism is easy, but time consuming to query the status bits of all the I/O
devices connected to the bus.
• The device requesting an interrupt may identify itself directly to the processor.
– Device can do so by sending a special code (4 to 8 bits) the processor over the bus.
– Code supplied by the device may represent a part of the starting address of the
interrupt-service routine.
INTERRUPTS
– The remainder of the starting address is obtained by the processor based on other
information such as the range of memory addresses where interrupt service routines
are located.
• Usually the location pointed to by the interrupting device is used to store the starting
address of the interrupt-service routine.
• Multiple I/O devices may be connected to the processor and the memory via a bus. Some
or all of these devices may be capable of generating interrupt requests.
– Each device operates independently, and hence no definite order can be imposed on
how the devices generate interrupt requests?
INTERRUPTS
• How does the processor know which device has generated an interrupt?
• How does the processor know which interrupt service routine needs to be
executed?
• When the processor is executing an interrupt service routine for one device, can
other device interrupt the processor?
• If two interrupt-requests are received simultaneously, then how to break the
tie?
INTERRUPTS
• Interrupt service routine can poll the I/O devices connected to the bus. The first device
with IRQ equal to 1 is the one that is serviced.
• Polling mechanism is easy, but time consuming to query the status bits of all the I/O
devices connected to the bus.
• The device requesting an interrupt may identify itself directly to the processor.
– Device can do so by sending a special code (4 to 8 bits) the processor over the bus.
– Code supplied by the device may represent a part of the starting address of the
interrupt-service routine.
INTERRUPTS
• In general, same arrangement is used when multiple devices can send interrupt requests to
the processor.
– During the execution of an interrupt service routine of device, the processor does not
accept interrupt requests from any other device.
– Since the interrupt service routines are usually short, the delay that this causes is
generally acceptable.
• However, for certain devices this delay may not be acceptable.
– Which devices can be allowed to interrupt a processor when it is executing an interrupt
service routine of another device?
INTERRUPTS
– When the processor starts executing the interrupt service routine of a device, its
priority is raised to that of the device.
– If the device sending an interrupt request has a higher priority than the processor, the
processor accepts the interrupt request.
• Processor’s priority is encoded in a few bits of the processor status register.
– Priority can be changed by instructions that write into the processor status register.
– Usually, these are privileged instructions, or instructions that can be executed only in
the supervisor mode.
INTERRUPTS
INTR 1 I NTR p
Processor
Device 1 Device 2 Device p
INTA1 INTA p
• Which interrupt request does the processor accept if it receives interrupt requests from two or
more devices simultaneously?.
• If the I/O devices are organized in a priority structure, the processor accepts the interrupt
request from a device with higher priority.
– Each device has its own interrupt request and interrupt acknowledge line.
– A different priority level is assigned to the interrupt request line of each device.
• However, if the devices share an interrupt request line, then how does the processor decide
which interrupt request to accept?
INTERRUPTS
Polling scheme:
• The processor uses a polling mechanism to poll the status registers of I/O
devices to determine which device is requesting an interrupt.
• In this case the priority is determined by the order in which the devices are
polled.
• The first device with status bit set to 1 is the device whose interrupt request is
accepted.
INTERRUPTS
Device Device
INTA1
Processor
INTR p
Device Device
INTAp
Priority arbitration
circuit
• Only those devices that are being used in a program should be allowed to generate interrupt
requests.
• To control which devices are allowed to generate interrupt requests, the interface circuit of each I/O
device has an interrupt-enable bit.
– If the interrupt-enable bit in the device interface is set to 1, then the device is allowed to generate
an interrupt-request.
• Interrupt-enable bit in the device’s interface circuit determines whether the device is allowed to
generate an interrupt request.
• Interrupt-enable bit in the processor status register or the priority structure of the interrupts
determines whether a given interrupt will be accepted.
EXCEPTIONS