Input/Output Organization: Bus Structure
Input/Output Organization: Bus Structure
Input/Output
Organization
Bus Structure
Processor Memory
Bus
• Multiple
I/O devices may be connected to the processor and the
memory via a bus.
• Busconsists of three sets of lines to carry address, data and control
signals.
1
21-02-2019
2
21-02-2019
Address lines
The I/O interface circuit has: Bus Data lines
• Address decoder Control lines
• Control circuit
• Data and Status
registers. Address Control Data and I/O
decoder circuits status registers interface
3
21-02-2019
4
21-02-2019
Master/Slave
Synchronous Bus
• On a synchronous bus, all devices derive timing
information from a control line called the bus
clock.
• The signal on this line has two phases:
•a high level followed by a low level.
• The two phases constitute a clock cycle.
• The first half of the cycle between the low-to-high
and high-to-low transitions is often referred to as
a clock pulse.
5
21-02-2019
Synchronous bus
All devices derive timing information from a
common clock line.
The clock line has equally spaced pulses which
define equal time intervals.
In a simple synchronous bus, each of these
pulses constitutes a bus cycle.
One data transfer can take place during one
bus cycle.
Bus clock
Bus cycle
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.
6
21-02-2019
7
21-02-2019
T ime
Data
Address & tDM
command reach
Seen by slave
the slave. tAS
Address and Data appears
command on the bus.
Data
tDS
t0 t1 t
2
8
21-02-2019
9
21-02-2019
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.
Sequence of events
Clock cycle 1 – master sends address and command information
(Read) on the bus.
Slave receives information and decodes it.
Clock cycle 2 – Slave makes a decision to respond and begins to
access the requested data.
Clock cycle 3 – Data is ready and slave places the data on the bus.
Generates a control signal Slave Ready.
End of clock cycle 3 – on receiving Slave Ready the master strobes
the data into the input buffer.
Clock cycle 4 – bus transfer operation is complete. Master can send
a new address.
Slave Ready – used to synchronize slave and master. If the
addressed slave does not respond master waits for a predefined
amount of time and aborts the operation.
10
21-02-2019
Asynchronous bus
Data transfers on a bus is based on the use of a handshake protocol
between the master and the slave. A handshake is an exchange of
command and response signals between the master and the slave
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.
Master-ready signal is asserted by the master to indicate to the slave
that it is ready to participate in a data transfer.
Slave-ready signal is asserted by the slave in response to the master-
ready from the master, and it indicates to the master that the slave is
ready to participate in a data transfer.
11
21-02-2019
T ime
Address
and command
Master-ready
Slave-ready
Data
t0 t1 t2 t3 t4 t5
Bus cycle
• t0
- Master places the address and command information on the
bus. All devices begin to decode this information.
• t1
- Master asserts the Master-ready signal to inform devices
that address and command information is ready. Master-ready
signal is asserted at t1 instead of t0
• t1-t0
– delay to care of skew (two signals transmitted from
one source simultaneously arrive at destination at
different times. Caused by propagation delays). This delay
should be larger than the maximum possible skew.
Decoding of address also takes place during this time.
• t2
- Addressed slave places the data on the bus and asserts the
Slave-ready signal.
12
21-02-2019
• t2
– t1 – this period depends on the distance between
master and slave and delays in the slave’s circuit.
• t3
- Slave-ready signal arrives at the master, indicating that
input data is available on the bus. After a delay equivalent to
the maximum bus skew and minimum set up time, the
master strobes the data into its input buffer. Now it drops
Master – ready signal to indicate it has received the data.
• t4
- Master removes the address and command information.
The delay between t3 and t4 allows bus skew.
• t5
- Slave receives the transition of the Master-ready signal
from 1 to 0. It removes the data and the Slave-ready signal
from the bus.
• This completes the input transfer.
13
21-02-2019
14
21-02-2019
Electrical Considerations
• A bus is an interconnection medium to which several devices may be
connected.
• Only one device can place data on the bus at any given time.
• A logic gate that places data on the bus is called a bus driver.
• All devices connected to the bus, except the one that is currently
sending data, must have their bus drivers turned off.
• A tri-state gate, is used for this purpose.
It has a control input that is used to turn the gate on or off.
When turned on, or enabled, it drives the bus with 1 or 0,
corresponding to the value of its input signal.
When turned off, or disabled, it is effectively disconnected from the
bus (its output goes into a high-impedance state that does not affect
the signal on the bus).
Arbitration
15
21-02-2019
Arbitration
• Twoor more entities may contend for the use of a single
resource.
• Forexample, two devices may need to access a given slave
at the same time. It is necessary to decide which device will
access the slave first.
• The decision is made in an arbitration process performed by
an arbiter circuit.
The arbitration process starts by each device sending a
request to use the shared resource.
The arbiter associates priorities with individual requests.
If it receives two requests at the same time, it grants the
use of the slave to the device having the higher priority
first.
Arbitration
• Consider the case where a single bus is the shared resource.
• Thedevice that initiates data transfer requests for the bus
and becomes the bus master.
• Usually the processor is the bus master.
• Itis possible that several devices in a computer system need
to be bus masters to transfer data.
• Forexample, an I/O device needs to be a bus master to
transfer data directly to or from the computer’s memory.
• Sincethe bus is a single shared facility, it is essential to
provide orderly access to it by the bus masters.
16
21-02-2019
Arbitration
• A device that wishes to use the bus sends a request to the arbiter.
• When multiple requests arrive at the same time, the arbiter selects
one request and grants the bus to the corresponding device.
• For some devices, a delay in gaining access to the bus may lead to an
error. Such devices must be given high priority.
• If there is no particular urgency among requests, the arbiter may
grant the bus using a simple round-robin scheme.
17
21-02-2019
• Assume that master 1 has the highest priority, followed by the others
in increasing numerical order.
• Master 2 sends a request to use the bus first. Since there are no other
requests, the arbiter grants the bus to this master by asserting BG2.
• When master 2 completes its data transfer operation, it releases the
bus by deactivating BR2.
• By that time, both masters 1 and 3 have activated their request lines.
• Since device 1 has a higher priority, the arbiter activates BG1 after it
deactivates BG2, thus granting the bus to master 1.
• Later, when master 1 releases the bus by deactivating BR1, the
arbiter deactivates BG1 and activates BG3 to grant the bus to master
3.
• Note that the bus is granted to master 1 before master 3 even though
master 3 activated its request line before master 1.
18
21-02-2019
Accessing I/O
Devices
19
21-02-2019
20
21-02-2019
Program-Controlled I/O
• Eg: Human-computer interaction—keyboard and display
• The task is to read characters typed on a keyboard, stores these
data in the memory, and displays the same characters on a display
screen.
• A simple way of implementing this task is to write a program that
performs all these functions.
• This method is known as program-controlled I/O.
• It is necessary to ensure that these happen at the right time.
• An input character must be read in response to a key being pressed.
For output, a character must be sent to the display only when the
display device is able to accept it.
21
21-02-2019
Program-Controlled I/O
• The rate of data transfer from the keyboard to a computer is limited
by the typing speed of the user, which is unlikely to exceed a few
characters per second.
• The rate at which characters can be transmitted to and displayed on
the display device, typically several thousand characters per second.
• This is much slower than the speed of a processor that can execute
billions of instructions per second.
• The difference in speed between the processor and I/O devices creates
the need for mechanisms to synchronize the transfer of data between
them.
Signaling Protocol
Output
• Processor sends the first character
• Waits for a signal from the display that the next character can
be sent.
• It then sends the second character, and so on.
Input
• The processor waits for a signal indicating that a key has been
pressed and its corresponding that a binary code is available in
an I/O register associated with the keyboard.
• Then the processor proceeds to read that code.
22
21-02-2019
Display interface
23
21-02-2019
24
21-02-2019
• The And instruction is used to test the KIN flag, which is bit b1 of
the status information in R4.
• As long as b1 = 0, the result of the AND operation leaves the value
in R4 equal to zero, and the READWAIT loop continues to be
executed.
25
21-02-2019
Interrupts
26
21-02-2019
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.
Example
• Consider a task that requires continuous extensive computations to
be performed and the results to be displayed on a display device.
• The displayed results must be updated every ten seconds.
• The ten-second intervals can be determined by a simple timer
circuit, which generates an appropriate signal.
• The processor treats the timer circuit as an input device that
produces a signal that can be interrogated.
• If this is done by means of polling, the processor will waste
considerable time checking the state of the signal.
• A better solution is to have the timer circuit raise an interrupt
request once every ten seconds.
• In response, the processor displays the latest results.
27
21-02-2019
Interrupt
occurs i
here
i + 1
28
21-02-2019
29
21-02-2019
30
21-02-2019
31
21-02-2019
Design Variations
• 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 called the shadow registers.
32
21-02-2019
33
21-02-2019
34
21-02-2019
Disabling Interrupts at
Processor End
• Processor automatically disable interrupts before starting the
execution of the interrupt-service routine.
• The processor saves the contents of the program counter and the
processor status register.
• After saving the contents of the PS register, with the IE bit equal to
1, the processor clears the IE bit in the PS register, thus disabling
further interrupts.
• Then, it begins execution of the interrupt-service routine.
• When a Return-from-interrupt instruction is executed, the saved
contents of the PS register are restored, setting the IE bit back to 1.
Hence, interrupts are again enabled.
35
21-02-2019
Sequence of events
1. The device raises an interrupt request.
2. The processor interrupts the program currently being executed
and saves the contents of the PC and PS registers.
3. Interrupts are disabled by clearing the IE bit in the PS to 0.
4. 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.
5. 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.
36
21-02-2019
37
21-02-2019
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 is used to find the
starting address of the interrupt-service routine.
• A commonly used scheme is to allocate permanently an
area in the memory to hold the starting addresses of
interrupt-service routines.
• These addresses are usually referred to as interrupt
vectors and they are said to constitute the interrupt-
vector table.
38
21-02-2019
39
21-02-2019
Interrupt Nesting
• Previously,
before the processor started executing
the interrupt service routine for a device, it disabled
the interrupts from the device.
• Ingeneral, 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 as it may
lead to erroneous operation.
Which devices can be allowed to interrupt a processor when it is
executing an interrupt service routine of another device?
• A computer that keeps track of the time of day using a real-time clock.
• This is a device that sends interrupt requests to the processor at regular
intervals.
• For each of these requests, the processor executes a short interrupt-
service routine to increment a set of counters in the memory that keep
track of time.
• Proper operation requires that the delay in responding to an interrupt
request from the real-time clock be small in comparison with the
interval between two successive requests.
• To ensure that this requirement is satisfied, it is necessary to accept an
interrupt request from the clock during the execution of an interrupt-
service routine for another device, i.e., to nest interrupts.
40
21-02-2019
41
21-02-2019
Interrupt Nesting
• If nested interrupts are allowed, then each interrupt
service routine must save on the stack the saved
contents of the program counter and the status
register.
• This has to be done before the interrupt-service
routine enables nesting by setting the IE bit in the
status register to 1.
Simultaneous Requests
• When interrupt requests from two or more devices arrive
Simultaneously, the processor must decide which request
to service first.
Polling the status registers of the I/O
Priority is determined by the order in which the
devices are polled.
Vectored interrupts
Ensure that only one device is selected to send its
interrupt vector code. This is done by using
arbitration circuits
42
21-02-2019
43
21-02-2019
• Only one or two bits in these registers are needed in handling the I/O
transfers.
• The remaining bits can be used to specify other aspects of the operation of the
device, or ignored if they are not needed.
• The keyboard status register includes bits KIN and KIRQ.
• The KIRQ bit is set to 1 if an interrupt request has been raised, but not yet
serviced.
• The keyboard may raise interrupt requests only when the interrupt-enable bit,
KIE, in its control register is set to 1.
• When both KIE and KIN bits are equal to 1, an interrupt request is raised and
the KIRQ bit is set to 1.
• The DIRQ bit in the status register of the display interface indicates whether
an interrupt request has been raised.
• Bit DIE in the control register of this interface is used to enable interrupts.
44
21-02-2019
45
21-02-2019
46
21-02-2019
47
21-02-2019
48
21-02-2019
• The last three instructions in the Main program are used to set to 1
the interrupt-enable bit in PS.
• Only MoveControl instructions can access the contents of a
control register.
• The contents of PS are loaded into a general-purpose register, R2,
modified and then written back into PS.
• Using the Or instruction to modify the contents affects only the IE
bit and leaves the rest of the bits in PS unchanged.
• When multiple I/O devices raise interrupt requests, it is necessary
to determine which device has requested an interrupt.
• This can be done in software by checking the information in the
IPENDING control register and choosing the interrupt-service
routine that should be executed.
49
21-02-2019
Example 2
• Suppose a program needs to display a page of
text stored in the memory.
• Thiscan be done by having the processor send a
character whenever the display interface is
ready, which may be indicated by an interrupt
request.
• Assume that both the display and the keyboard
are used by this program, and that both are
enabled to raise interrupt requests.
50
21-02-2019
51
21-02-2019
Main Program
• Initialize
any variables needed by the interrupt-
service routines, such as the memory buffer pointers.
• Enables interrupts in both the keyboard and display
interfaces.
• Enables
interrupts in the processor control register
IENABLE.
• Enable the processor to respond to interrupts by
setting the IE bit in the processor status register, PS
to 1.
• Note that the immediate value 6, which is loaded
into this register, sets bits KBD and DISP to 1.
52
21-02-2019
• The program parts that handle interrupt requests and provide the
corresponding service to the requesting devices are often referred
to as the interrupt handler.
• The interrupt handler starts at the fixed address ILOC
• The individual ISRs are just subroutines that can be placed
anywhere in the memory.
• In processors that use vectored interrupts, the circuit that detects
interrupt requests automatically loads a different address into the
program counter for each interrupt that is assigned a specific
location in the interrupt-vector table.
• A separate interrupt-service routine is executed to completion for
each pending request, even if multiple interrupt requests are
raised at the same time.
53
21-02-2019
Exceptions
• Interrupts caused by interrupt-requests sent by I/O devices.
• Interruptscould 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.
• Other types of exceptions are:
Recovery from errors
Debugging
Privilege exception
54
21-02-2019
Debugging
• Debugger uses exceptions to provide important features:
Trace,
Breakpoints.
• Tracemode:
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.
TRAP instruction is used for this purpose.
Debugging program is used as the exception-service routine.
55
21-02-2019
Privilege exception
• 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.
56