computer-organization-notes
computer-organization-notes
The address decoder decodes the address sent by the CPU and enables the device to
recognize its address. The data register holds the data being transferred to or from the
processor.
The status register contains information relevant to the operation of the I/O device. Both
status and data are connected to the data bus and assigned unique address.
The address decoder, the data and status register and control circuitry required to
coordinate I/O transfer constitute device interface circuit.
The speed of operation of the I/O device varies from that of the processor. An instruction
that reads a character from the keyboard should be executed only when a character is
available in the I/p buffer of keyboard interface. Also, it has to be made sure that a
character is read only once.
For an input device such as keyboard, a status flag is included in the interface circuit as a
part of status register. This flag is set to 1 when a character is entered at the keyboard and
cleared to 0 once the character is read by the processor.
Hence by checking the SIN flag, software can ensure that CPU is reading valid data. This
is done in a program loop that repeatedly reads the ststus register and checks the status of
SIN. When SIN becomes equal to 1, the program reads the input data register. The
register that are used for i/o operations are shown below
The status register consists of 2 flags SIN and SOUT that are used to check the status of
keyboard and display respectively. The flags KIRQ and DIRQ are used to control the devices.
The data from the keyboard are made available in the DATAIN register and the data sent to the
display are stored n DATAOUT register.
For example consider COMPUTE and PRINT routines. The routine is executed in response to
an interrupt request is called interrupt service routine. Transfer of control through the use of
interrupt happens.
The method has the drawback that, the processor wastes its time in checking the status of the
device before the actual data transfer takes places. A program that reads, one lines form the
keyboard stores it in a memory buffer, and echoes it back to the display.
The following are the techniques that can be used to solve the problem
Technique-I
The processor hardware ignores the interrupt request line until the execution of the first
instruction of ISR has been completed. The 1 st Instruction in ISR would be interrupt disable
instruction. These instructions interrupts will be disabled until the execution of interrupt enable
instruction.
The last instruction in the ISR would be interrupt enable instruction i.e., before return from
interrupt instruction. The CPU must guarantee that execution of return from interrupt instruction
is completed before further interruption can occur.
Technique –II
One bit in the Process status (PS) is called interrupt enable, indicates whether interrupts are
disabled or not. An interrupt is arrived while this bit is equal to 1 will be accepted. To disable
interrupts, the CPU does the following
Save the contents of PS on stack
Disable the Interrupt Enable bit in PS disabling further interrupts
When a return from interrupt instruction is executed. The contents of PS are restored
from the stack, setting IE bit back to 1.
Technique-III
The processor has a special interrupt request line for which the interrupt handling circuit
responds only to the leading edge of the signal. Such a line is said to be edge triggered. In this
case the processor will receive only one request regardless of how long the line is activated.
Summarizing sequence of events involved in handling interrupts
i. The device raises an interrupt request
ii. The processor interrupts the program currently being executed
iii. Interrupts are disabled by changing the control bits in the PS {expect in the case of
edge triggered}
iv. The device is informed that its request has been recognized by ISR.
v. Interrupts are enabled and execution of the interrupted program is resumed.
Whenever a device request an interrupt, its information available in the status register with its
one of the bit set to 1, which we call it has IRQ bit. If multiple device request the interrupt
request in case of request from keyboard and display with bits known as KIRQ and DIRQ,
respectively.
The simplest way to identify the interrupting device is to have the interrupt- service routine
pool the entire I/O device connected to bus.
The first device encountered with its IRQ bit set is the device that should be serviced. An
appropriate subroutine is called to provide the requested service. The polling scheme is easy to
implement. Its main disadvantage is the time spent in interrogating the IRQ bits of the entire
device that may not be requesting any service.
INTR 1 I NTR p
P rocessor
INTA1 INTA p
Priority arbitration
circuit
The action disables interrupts from device at the same level of priority or lower. Interrupt
request from higher priority devices will be continue to be accepted. The processor priority is
usually encoded in a few bits of the processor status word (ps). It can be changed by program
instruction that write into the PS.
These are privileged instructions, which can be executed only when the processor is running in
the SUPERVISOR mode. The CPU is in supervisor mode only when it is executing OS routines.
It switches to user mode before beginning to execute application program. A user program
cannot accidently change priority of CPU. An attempt to execute a privileged instruction in user
mode raises a PRIVELEGED exception.
I NTR
I NTR 1
P ro c e sso r
Device Device
INTA1
INTR p
Device Device
INTA p
Priority arbitration
circuit
Therefore in daisy chain, the device that is electrically closest to processor has the highest
priority. Using this technique devices are organized into groups, and each group is connected at a
different priority level.
To perform the operation of interrupt, we need to initialize the interrupt process. This may be
accomplished as follows
i. Load the starting address of the interrupt service routine in location INTVEC
ii. Load the address LINE in a memory location PNTR. The ISR will use this location as a
pointer to store the input characters in the memory.
iii. Enable keyboard interrupts by setting bit 2 in register CONTROL to 1.
iv. Enable interrupts in the processor by setting to 1 the IE bit in the processor status register,
PS.
Once the initialization is completed, typing a character on the keyboard will cause an interrupt
request to be generated by the keyboard interface. The program being executed at that time will
be interrupted and the ISR will be executed. This routine has to perform the following tasks.
i. Read the input character from the keyboard input data register. This will cause the
interface circuit to remove its interrupt request.
ii. Store the character in the memory location pointed to by PNTR, and increment PNTR.
iii. When the end of the line is reached, disable keyboard interrupts and inform program
main.
iv. Return form interrupt.
2.5 Exceptions
An interrupt is an event that causes the execution of one program to be suspended and execution
of another program to begin. So, for we have dealt only with interrupts caused by requests
received during I/O data transfer.
The term exception is often used to refer to any event that causes an interruption. Hence,
I/O interrupts are one example of an exception. There are few other kinds of exceptions are
i. Recovery from errors
ii. Debugging
iii. Privilege Exception
ii. Debugging:
System software usually includes a program called a debugger, which helps programmer to
find errors in a program. The debugger uses exceptions to provide 2 important facilities called
trace and breakpoints.
When the processor is operating in the trace mode, an exception occurs after execution of
every instruction, using the debugging program as the exception service routine. It examines the
contents of register, memory locations and so on. On return, the next instruction in the program
is activated again; the trace exception is disabled during the execution of the debugging program.
Breakpoints provide a similar facility, except that the program being debugged is interrupted
only at specific points selected by the user. An instruction called trap or software interrupt is
usually provided for this purpose. When the program is executed and reaches that point, it is
interrupted and the debugging routine is activated. This gives the user a chance to examine
memory and register contents.
Two registers are used for storing the starting address and the word count. Third register
continue status and control flags. The R/W bit determines the direction of the transfer. When this
bit is set to 1 by a program instruction, the controller performs a read operation i.e., it transfer
data from the memory to the I/O device. Otherwise it performs the write operation.
When the controller has completed transferring a block of data and is ready to receive
anther commend, it sets the DONE flag to1. Bit-30 is the interrupt enable flag, IE.
Disk/DMA
Controller
Bus Arbitration
The device that is allowed to initiate data transfers on the bus at any given time is called the
bus master. Bus arbitration is the process by which the next device to become the bus master is
selected and bus mastership is transferred to it.
There are 2 approaches to bus arbitration: Centralized and Distributed
In centralized arbitration, a single bus arbiter performs the required arbitration.
In distributed arbitration, all devices participate in the selection of the next bus master.
i. Centralized Arbitration
The bus arbiter may be the processor or a separate unit connected to the bus. Figure shows the
basic arrangement in which the processor contains the bus arbitration circuitry. In this case, the
processor is normally the bus master unless it grants bus mastership to one of the DMA
controller.
BBSY
BR
Processor
DMA DMA
controller controller
BG1 1 BG2 2
Figure: A simple arrangement for bus arbitration using a daisy chain
DMA controller 2 requests and acquires bus mastership and later releases the bus. During its
tenure as the bus master, it may perform one or more data transfer operations, depending on
whether it is operating in the cycle stealing or block mode. After it releases the bus, the processor
resumes bus mastership.
The timing diagram in figure 2 shows the sequence of events for the device in the figure.
DMA controller 2
Time
BR
asserts the BR signal. Processor asserts
BG1
the BG1 signal
BG1 signal propagates
BG2 to DMA#2.
BBSY
Bus
master Processor DMA controller 2 Processor
The signal on the Bus-Request line is the logical OR of the bus requests from all the devices
connected to it. When Bus-Request is activated, the processor activates, the Bus-Request signal,
BGI, indicating to the DMA controller that they may use the bus when it becomes free.
2.7 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.
A bus protocol is the set of rules that govern the behavior of various devices connected to
the bus, as to when to place information on the bus, when to assert control signals, etc.
Bus lines may be grouped into three types:
Data
Address
Control
Control signals specify: Whether it is a read or a write operation. Required size of the data, when
several operand sizes (byte, word, long word) are possible. Timing information to indicate when
the processor and I/O devices may place data or receive data from the bus. Schemes for timing of
data transfers over a bus can be classified into:
i. Synchronous,
ii. Asynchronous.
i. Synchronous Bus
• 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.
• 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.
T ime
Data
Address DATAIN Data
Encoder
R/W SIN and Keyboard
Processor debouncing switches
Master
-ready circuit
Input Valid
Slave-ready interface
Figure: Keyboard to processor connection
• Output lines of DATAIN are connected to the data lines of the bus by means of 3 state
drivers
• Drivers are turned on when the processor issues a read signal and the address selects this
register.
• SIN signal is generated using a status flag circuit.
• It is connected to line D0 of the processor bus using a three-state driver.
• Address decoder selects the input interface based on bits A1 through A31.
• Bit A0 determines whether the status or data register is to be read, when Master-ready is
active.
• In response, the processor activates the Slave-ready signal, when either the Read-status or
Read-data is equal to 1, which depends on line A0.
Data
Address DATAOUT Data
Processor
CPU R/W SOUT Valid Printer
Master-ready
Output Idle
Slave-ready interface
Figure: Printer to processor connection
• Data lines of the processor bus are connected to the DATAOUT register of the interface.
• The status flag SOUT is connected to the data line D1 using a three-state driver.
• The three-state driver is turned on, when the control Read-status line is 1.
• Address decoder selects the output interface using address lines A1 through A31.
• Address line A0 determines whether the data is to be loaded into the DATAOUT register
or status flag is to be read.
Bus
D7 PA7
DATAIN
D1
D0 PA0
SIN
Input CA
status
PB7
DATAOUT
PB0
SOUT
Handshake CB1
control CB2
Slave- 1
Ready
Master-
Ready
R/ W
A31
Address My-address
decoder
A2
RS1
A1
RS0
A0
• Combined I/O interface circuit. Address bits A2 through A31 that is 30 bits are used to
select the overall interface.
• Address bits A1 through A0, that is, 2 bits select one of the three registers, namely,
DATAIN, DATAOUT, and the status register.
• Status register contains the flags SIN and SOUT in bits 0 and 1.
• Data lines PA0 through PA7 connect the input device to the DATAIN register.
• DATAOUT register connects the data lines on the processor bus to lines PB0 through
PB7 which connect to the output device.
• Separate input and output data lines for connection to an I/O device.
Serial port
• Input shift register accepts input one bit at a time from the I/O device.
• Once all the 8 bits are received, the contents of the input shift register are loaded in
parallel into DATAIN register.
• Output data in the DATAOUT register are loaded into the output shift register.
Bits are shifted out of the o/p shift register and sent out to the I/O device one bit at a time.
Interface
Figure: An example computer system using different interface standards
2.9.1 Peripheral Component Interconnect (PCI) Bus
The PCI (Peripheral Component Interconnect) bus was developed as a low-cost, processor-
independent bus. It is housed on the motherboard of a computer and used to connect I/O
interfaces for a wide variety of devices. A device connected to the PCI bus appears to the
processor as if it is connected directly to the processor bus. Its interface registers are assigned
addresses in the address space of the processor. We will start by describing how the PCI bus
operates, then discuss some of its features.
Bus Structure
The use of the PCI bus in a computer system is illustrated in figure. The PCI bus is connected to
the processor bus via a controller called a bridge. The bridge has a special port for connecting the
computer’s main memory. It may also have another special high speed port for connecting
graphics devices. The bridge translates and relays commands and responses from one bus to the
other and transfers data between them.
We will examine a typical bus transaction. The bus master, which is the device that initiates
data transfers by issuing Read and Write commands, is called the initiator in PCI terminology.
The addressed device that responds to these commands is called a target. The main bus signals
used for transferring data are listed in Table.
There are 32 or 64 lines that carry address and data using a synchronous signaling scheme.
The target-ready, TRDY#, signal is equivalent to the Slave-ready signal. In addition, PCI uses an
initiator-ready signal, IRDY#, to support burst transfers. A complete transfer operation on the
PCI bus, involving an address and a burst of data, is called a transaction. Individual word
transfers within a transaction are called phases.
• Because of these various options, SCSI connector may have 50, 68 or 80 pins. The data transfer
rate ranges from 5MB/s to 160MB/s 320Mb/s, 640MB/s. The transfer rate depends on,
Length of the cable
Number of devices connected.
• To achieve high transfer rate, the bus length should be 1.6m for SE signaling and 12m for LVD
signaling.
• The SCSI bus us connected to the processor-bus through the SCSI controller. The data are
stored on a disk in blocks called sectors. Each sector contains several hundreds of bytes. These
data will not be stored in contiguous memory-location.
• SCSI protocol is designed to retrieve the data in the first sector or any other selected sectors. •
Using SCSI protocol, the burst of data are transferred at high speed.
• The controller connected to SCSI bus is of 2 types. They are Initiator &Target
1) Initiator: It has the ability to select a particular target & to send commands specifying the
operation to be performed. They are the controllers on the processor side.
2) Target : The disk controller operates as a target. It carries out the commands it receive from
the initiator. The initiator establishes a logical connection with the intended target.
Steps for Read-operation
i. The SCSI controller contends for control of the bus (initiator).
ii. When the initiator wins the arbitration-process, the initiator
→ selects the target controller and hands over control of the bus to it.
iii. The target starts an output operation. The initiator sends a command specifying the
required read- operation.
iv. The target ends a message to initiator indicating that it will temporarily suspend
connection b/w them and then releases the bus.
v. The target controller sends a command to the disk drive to move the read head to the first
sector involved in the requested read-operation.
vi. The target → transfers the contents of the data buffer to the initiator and → then
suspends the connection again.
vii. The target controller sends a command to the disk drive to perform another seek
operation.
Targets examine ID
DB2
DB5
DB6
BSY
SEL
2) Information Transfer
The information transferred between two controllerss may consists of
• Commands from the initiator to the target
• Status responses from the target to the initiator or
• Data transferred to/from the I/O device.
Handshake signalling is used to control information transfers, with the target controller taking
the role of the bus-master.
The USB has been designed to meet the key objectives. They are
1) Provide a simple, low-cost and easy to use interconnection system.
This overcomes difficulties due to the limited number of I/O ports available on a computer.
2) Accommodate a wide range of data transfer characteristics for I/O devices.
For e.g. telephone and Internet connections
3) Enhance user convenience through a “plug-and-play” mode of operation.
• Advantage: USB helps to add many devices to a computer system at any time without opening
the computer-box.
Port Limitation
Normally, the system has a few limited ports.
To add new ports, the user must open the computer-box to gain access to the internal
expansion bus & install a new interface card.
The user may also need to know to configure the device & the s/w.
Plug & Play
The main objective: USB provides a plug & play capability.
The plug & play feature enhances the connection of new device at any time, while the system is
operation. The system should
→ Detect the existence of the new device automatically.
→ Identify the appropriate device driver s/w.
→ Establish the appropriate addresses.
→ Establish the logical connection for communication.
USB Architecture
• To accommodate a large number of devices that can be added or removed at any time, the USB
has the tree structure as shown in the figure 7.17.
• Each node of the tree has a device called a Hub.
• A hub acts as an intermediate control point between the host and the I/O devices.
• At the root of the tree, a Root Hub connects the entire tree to the host computer.
• The leaves of the tree are the I/O devices being served (for example, keyboard or speaker).
• A hub copies a message that it receives from its upstream connection to all its downstream
ports.
• As a result, a message sent by the host computer is broadcast to all I/O devices, but only the
addressed-device will respond to that message.
uter
Host comp
Rhouobt
Hub
Hub
dIev/O
ice
dIev/O
ice
dIev/O
ice
dIev/O
ice
Hub
dIev/O
ice
dIev/O
ice
USB ADDRESSING
• Each device may be a hub or an I/O device.
• Each device on the USB is assigned a 7‐bit address.
• This address → is local to the USB tree and
→ is not related in any way to the addresses used on the processor-bus.
• A hub may have any number of devices or other hubs connected to it, and addresses are
assigned arbitrarily.
• When a device is first connected to a hub, or when it is powered-on, it has the address 0.
• The hardware of the hub detects the device that has been connected, and it records this fact as
part of its own status information.
• Periodically, the host polls each hub to collect status information and learn about new devices
that may have been added or disconnected.
• When the host is informed that a new device has been connected, it uses sequence of
commands to
Send a reset signal on the corresponding hub port.
Read information from the device about its capabilities.
Send configuration information to the device, and
Assign the device a unique USB address.
• Once this sequence is completed, the device
→ begins normal operation and
→ responds only to the new address.
USB PROTOCOLS
• All information transferred over the USB is organized in packets.
• A packet consists of one or more bytes of information.
• There are many types of packets that perform a variety of control functions.
• The information transferred on USB is divided into 2 broad categories: 1) Control and 2) Data.
Control packets used for controlling data transfer operations are called token
packets.
Figure : USB Packet format
• Control packets perform tasks such as
→ addressing a device to initiate data transfer.
→ acknowledging that data have been received correctly or
→ indicating an error.
• Data-packets carry information that is delivered to a device.
• A packet consists of one or more fields containing different kinds of information.
• The first field of any packet is called the Packet Identifier (PID) which identifies type of that
packet.
• They are transmitted twice.
1) The first time they are sent with their true values and
2) The second time with each bit complemented.
• The four PID bits identify one of 16 different packet types.
• Some control packets, such as ACK (Acknowledge), consist only of the PID byte.
• Control packets used for controlling data transfer operations are called Token Packets.