DigitalLogic ComputerOrganization L25 IO Handout
DigitalLogic ComputerOrganization L25 IO Handout
COMPUTER ORGANIZATION
Lecture 25: Exceptions
Input/Output
ELEC3010
ACKNOWLEGEMENT
2
COVERED IN THIS COURSE
❑ Binary numbers and logic gates
❑ Boolean algebra and combinational logic
❑ Sequential logic and state machines
❑ Binary arithmetic
Digital logic
❑ Memories
❑Useful methods for signaling the CPU that some event has
occurred that requires action
▪ In response, the CPU may suspend the running program in order to
handle the exception/interrupt
❑Exceptions are used to handle conditions that arise when
executing instructions on the processor
▪ Detected by the processor itself
❑Interrupts are used to handle (asynchronous) events
external to the processor
▪ I/O device request, external error or malfunction
4
WHY ARE EXCEPTIONS USEFUL?
5
HANDLING A PAGE FAULT
6
COMPUTER WITH INPUT/OUTPUT
7
I/O CONTROLLERS + BRIDGE
I/O connected with I/O Controllers
• high-performance interconnect: processor, memory, display
• lower-performance interconnect: disk, keyboard, network
8
BUS TYPES
Processor – Memory (“Front Side Bus”)
▪ Short, fast, & wide
▪ Mostly fixed topology, designed as a “chipset”
• CPU + Caches + Interconnect + Memory Controller
I/O and Peripheral busses (PCIe, PCI, SCSI, USB…)
▪ Longer, slower, & narrower
▪ Flexible topology, multiple/varied connections
▪ Interoperability standards for devices
▪ Connect to processor-memory bus through a bridge
9
FOR EXAMPLE…
source
10
FOR EXAMPLE…
11
I/O DEVICE API
Typical I/O Device API
▪ a set of read-only or read/write registers
Command registers
▪ writing causes device to do something
Status registers
▪ reading indicates what device is doing, error codes, …
Data registers
▪ Write: transfer data to a device
▪ Read: transfer data from a device
13
MEMORY-MAPPED I/O
14
DEVICE DRIVERS
Memory Mapped I/O
struct kbd {
Programmed I/O char status;
char read_kbd() char data;
{ };
kbd *k = mmap(...);
do {
sleep(); char read_kbd()
status = inb(0x64); {
} while(!(status & 1)); do {
sleep();
status = k->status;
return inb(0x60); } while(!(status & 1));
} return k->data;
}
15
PROGRAMMED I/O VS MEMORY MAPPED I/O
Programmed I/O
▪ Requires special instructions
▪ Can require dedicated hardware interface to devices
Memory-Mapped I/O
▪ Re-uses standard load/store instructions
▪ Re-uses standard memory hardware interface
16
POLLING VS. INTERRUPTS
How does program learn device is ready/done?
1. Polling: Periodically check I/O status register
• Common in small, cheap, or real-time embedded systems
+Predictable timing, inexpensive
– Wastes CPU cycles
2. Interrupts: Device sends interrupt to CPU
• Cause register identifies the interrupting device
• Interrupt handler examines device, decides what to do
+Only interrupt when device ready/done
– Forced to save CPU context (PC, SP, registers, etc.)
– Unpredictable, event arrival depends on other devices’ activity
17
DIRECT MEMORY ACCESS (DMA)
How to talk to device?
• Programmed I/O or Memory-Mapped I/O
18
DIRECT MEMORY ACCESS (DMA)
1. Programmed: Device → CPU → RAM Transfer
for (i = 1 .. n)
CPU RAM
▪ CPU issues read request
▪ Device puts data on bus
& CPU reads into registers
▪ CPU writes data to memory DISK
19
BUILDING A COMPLETE COMPUTER
20
BEFORE NEXT CLASS
• Next time:
Revision
21