Chapter3-Io Organization
Chapter3-Io Organization
Operations
I/O
The data on which the instructions operate are not
necessarily already stored in memory.
Data need to be transferred between processor and
outside world (disk, keyboard, etc.)
I/O operations are essential, the way they are
performed can have a significant effect on the
performance of the computer.
Accessing I/O devices
•Multiple I/O devices may be connected to the processor and the memory via a bus.
•Bus consists of three sets of lines to carry address, data and control signals.
•Each I/O device is assigned an unique address.
•To access an I/O device, the processor places the address on the address lines.
•The device recognizes the address, and responds to the control signals.
Accessing I/O devices (contd..)
I/O devices and the memory may share the same address
space:
Memory-mapped I/O.
Any machine instruction that can access memory can be used to transfer data to
or from an I/O device.
Load R2, DATAIN ; DATAIN is the address of an i/p device register
Store R2, DATAOUT ; DATAOUT is the address of an o/p device register
Simpler software.
5
Accessing I/O devices (contd..)
Address lines
Bus Data lines
Control lines
Input device
•I/O device is connected to the bus using an I/O interface circuit which has:
- Address decoder, control circuit, and data and status registers.
•Address decoder decodes the address placed on the address lines thus enabling the
device to recognize its address.
•Data register holds the data being transferred to or from the processor.
•Status register holds information necessary for the operation of the I/O device.
•Data and status registers are connected to the data lines, and have unique addresses.
•I/O interface circuit coordinates I/O transfers.
Accessing I/O devices (contd..)
Recall that the rate of transfer to and from I/O devices
is slower than the speed of the processor. This creates
the need for mechanisms to synchronize data transfers
between them.
Program-controlled I/O:
Processor repeatedly monitors a status flag to achieve the necessary
synchronization.
Processor polls the I/O device.
- Registers
- Flags
- Device interface
Program-Controlled I/O Example
Memory-Mapped I/O – some memory address values are used to refer
to peripheral device buffer registers. No special instructions are needed.
Also use device status registers.
Program-Controlled I/O Example
1
2
Interrupt
occurs i
here
i +1
•Consider the task that requires continuous extensive computations to be performed and
the results to be displayed on display device.
•Processor is executing the instruction located at address i when an interrupt occurs.
•Routine executed in response to an interrupt request is called the interrupt-service
routine.
•When an interrupt occurs, control must be transferred to the interrupt service routine.
•But before transferring control, the current contents of the PC (i+1), must be saved in a
known
location.
•This will enable the return-from-interrupt instruction to resume execution at i+1.
•Return address, or the contents of the PC are usually stored on the processor stack.
Interrupts (contd..)
Treatment of an interrupt-service routine is very similar to
that of a subroutine.
However there are significant differences:
A subroutine performs a task that is required by the calling
program.
Interrupt-service routine may not have anything in common
with the program it interrupts.
Interrupt-service routine and the program that it interrupts
may belong to different users.
As a result, before branching to the interrupt-service routine,
not only the PC, but other information such as condition code
flags, and processor registers used by both the interrupted
program and the interrupt service routine must be stored.
This will enable the interrupted program to resume execution
upon return from interrupt service routine.
Interrupts (contd..)
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 (contd..)
Some computers provide two types of interrupts. One saves
all register contents, and the other does not.
A particular I/O device may use either type, depending upon
its response time requirements.
Another interesting approach is to provide duplicate sets of
processor registers.
In this case, a different set of registers can be used by the
interrupt-service routine, thus eliminating the need to save
and restore registers. The duplicate registers are sometimes
called the shadow registers.
• Interrupt concept is used in used in operating systems and in
many control applications where processing of certain
routines must be accurately timed relative to external events
(Real-time processing).
Interrupts (contd..)
When a processor receives an interrupt-request, it
must branch to the interrupt service routine.
It must also inform the device that it has recognized
the interrupt request.
This can be accomplished in two ways:
Some processors have an explicit interrupt-acknowledge
control signal for this purpose.
In other cases, the data transfer that takes place between
the device and the processor can be used to inform the
device.
Interrupts (contd..)
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. It should be available at the Device end also.
The processor has a status register (PS), which contains information
about its current state of operation. One bit, IE, of this register be
assigned for enabling/disabling interrupts.
To avoid interruption by the same device during the execution of an
interrupt service routine:
First instruction of an interrupt service routine can be Interrupt-
disable.
Last instruction of an interrupt service routine can be Interrupt-
enable.
Interrupts (contd..)
The interface of an I/O device includes a control
register that contains the information that
governs the mode of operation of the device.
One bit in this register may be dedicated to
interrupt control.
The I/O device is allowed to raise interrupt
requests only when this bit is set to 1.
Interrupts (contd..)
To summarize the sequence of events involved in
handling an interrupt request from a single device.
The device raises an interrupt request.
The processor interrupts the program currently being
executed and saves the contents of the PC and PS registers.
Interrupts are disabled by clearing the IE bit in the PS to 0.
The action requested by the interrupt is performed by the
interrupt-service routine, during which time the device is
informed that its request has been recognized, and in
response, it deactivates the interrupt-request signal.
Upon completion of the interrupt-service routine, the
saved contents of the PC and PS registers are restored
(enabling interrupts by setting the IE bit to 1), and
execution of the interrupted program is resumed.
Interrupts (contd..)
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?
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 (contd..)
Consider a simple arrangement where all devices send their
interrupt-requests over a single control line in the bus.
When the processor receives an interrupt request over this
control line, how does it know which device is requesting
an interrupt?
This information is available in the status register of the
device requesting an interrupt:
The status register of each device has an IRQ bit which it sets to 1 when it
requests an interrupt.
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.
Interrupts (contd..)
Vectored Interrupts: 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.
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.
Interrupts (contd..)
Previously, before the processor started executing the
interrupt service routine for a device, it disabled the
interrupts from the device.
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. Eg: a computer that keeps track of time of
day using real-time clock
It may be necessary to accept an interrupt nesting from some devices
(clock) during the execution of ISR.
Which devices can be allowed to interrupt a processor when it is executing
an interrupt service routine of another device?
Interrupts (contd..)
I/O devices are organized in a priority structure:
An interrupt request from a high-priority device is accepted
while the processor is executing the interrupt service routine
of a low priority device.
A priority level is assigned to a processor that can be
changed under program control.
Priority level of a processor is the priority of the program that
is currently being executed.
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.
Interrupts (contd..)
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.
Privileged instructions cannot be executed in the user mode.
Prevents a user program from accidentally or intentionally
changing the priority of the processor.
If there is an attempt to execute a privileged
instruction in the user mode, it causes a special type of
interrupt called as privilege exception.
Interrupts (contd..)
Simultaneous Interrupts:
When simultaneous interrupt requests arrive
processor must have some means of deciding which
request to service first.
Polling the status registers of the I/O devices is the
simplest such mechanism. In this case, priority is
determined by the order in which the devices are
polled.
In Vectored interrupts arbitration aitration circuit
selects only one device to send its interrupt vector
code.
Interrupts (contd..)
Controlling I/O device behavior:
To ensure that interrupt requests are generated only by those I/O
devices that the processor is currently willing to recognize, a
mechanism is needed in the interface circuits of individual devices
to control whether a device is allowed to interrupt the processor.
KIE=1, KB can raise interrupt request
KIRQ=1 if KB has raised the interrupt but not serviced by processor
yet.
Interrupts (contd..)
Processor control registers:
Figure 3.7 depicts one possibility, where there are four
processor control registers.
Interrupts (contd..)
Processor control registers:
The status register, PS, includes the interrupt-enable bit, IE, in
addition to other status information.
The IPS register is used to automatically save the contents of
PS when an interrupt request is received and accepted.
The IENABLE register allows the processor to selectively
respond to individual I/O devices. When a bit is set to 1, the
processor will accept interrupt requests from the
corresponding device.
The IPENDING register indicates the active interrupt
requests. This is convenient when multiple devices may raise
requests at the same time. Then, a program can decide which
interrupt should be serviced first.
Special instructions are provided to access these registers.
MoveControl R2, PS ; R2 <-- [PS]
MoveControl IENABLE, R3 ; IENABLE <-- [R3]
Interrupts (contd..)
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,
If the interrupt-enable bit in the device interface (device control register) is
set to 1, then the device is allowed to generate an interrupt-request.
By setting the corresponding bit in IENABLE control register in processor,
the processor selectively respond to individual I/O devices.
Interrupt-enable bit in the device’s interface circuit (control
register)determines whether the device is allowed to generate
an interrupt request.
Interrupt-enable bit in the processor status register (PS) or
the priority structure of the interrupts determines whether a
given interrupt will be accepted.
Interrupts (contd..)
A RISC-style program that reads a line of characters
using interrupts, and displays the line using polling.
Exceptions
Interrupts caused by interrupt-requests sent by I/O
devices.
Interrupts could be used in many other situations where
the execution of one program needs to be suspended and
execution of another program needs to be started.
In general, the term exception is used to refer to any event
that causes an interruption.
Interrupt-requests from I/O devices is one type of an exception.
Trace mode:
Exception occurs after the execution of every instruction.
Debugging program is used as the exception-service routine.
Breakpoints:
Exception occurs only at specific points selected by the user.
Debugging program is used as the exception-service routine.
Exceptions (contd..)
Certain instructions can be executed only when the
processor is in the supervisor mode. These are called
privileged instructions.
If an attempt is made to execute a privileged
instruction in the user mode, a privilege exception
occurs.
Privilege exception causes:
Processor to switch to the supervisor mode,
Execution of an appropriate exception-servicing routine.
Bus Structure
• Only one source/destination pair of units can use this bus to transfer
data at any one time.
• The bus consists of three sets of lines used to carry address, data, and
control signals.
Buses
Processor, main memory, and I/O devices are
interconnected by means of a bus.
Bus provides a communication path for the transfer of
data.
Bus also includes lines to support interrupts and arbitration.
Bus clock
Bus cycle
Synchronous bus (contd..) Time
Bus clock
Address and
command
Data
t0 t1 t2
Bus cycle
Master places the
device address and Addressed slave places
command on the bus, data on the data lines Master “strobes” the data
and indicates that on the data lines into its
it is a Read operation. input buffer, for a Read
operation.
•In case of a Write operation, the master places the data on the bus along with the
address and commands at time t0.
•The slave strobes the data into its input buffer at time t2.
Synchronous bus (contd..)
Once the master places the device address and
command on the bus, it takes time for this information
to propagate to the devices:
This time depends on the physical and electrical characteristics of the bus.
Data
Address & t DM
command reach Master strobes data
the slave-propagation Seen by slave into i/p buffer.
tAS
delay
Address and Data appears
command on the bus.
Data
tDS
Slave decodes address
t0 t1 t
2
• Signals do not appear on the bus as soon as they are placed on the bus, due to the
propagation delay in the interface circuits.
• Signals reach the devices after a propagation delay which depends on the
characteristics of the bus.
• t2 - t0 -> set time for the master’s i/p buffer
• Data must remain on the bus for some time after t2 equal to the hold time of the
buffer.
Synchronous bus (contd..)
Data transfer has to be completed within one clock
cycle.
Clock period t2 - t0 must be such that the longest propagation delay
on the bus and the slowest device interface must be accommodated.
Forces all the devices to operate at the speed of the slowest device.
Address
Command
Master strobes data
into the input buffer.
Data
Slave-ready
Slave places the data on the bus, Clock changes are seen by all the devices
and asserts Slave-ready signal. at the same time.
Asynchronous bus
Data transfers on the bus is controlled by a handshake
between the master and the slave.
Common clock in the synchronous bus case is replaced by
two timing control lines:
Master-ready,
Slave-ready.
and command
Master-ready
Slave-ready
Data