I/O interfaces, interrupts and DMA
An I/O interface exposes data, status and control registers. Separate the mechanism that requests service from the mechanism that transfers data. The CPU, device and memory may have different speeds and must agree on each transfer.
7.1 Programmed and interrupt-driven I/O
Past papers · CS 2014–2026 (23 papers): 1 question, 1 mark
Programmed I/O executes instructions to test device status and transfer data. With polling, the processor repeatedly tests ready/busy; polling does not mean the device writes the CPU's registers automatically. Interrupt-driven I/O lets the CPU do other work until a device requests service, but a programmed handler still transfers data through CPU instructions unless DMA is also used.
| Interface choice | Addressing and synchronisation |
|---|---|
| Memory-mapped I/O | Device registers occupy memory addresses; ordinary addressing mechanisms access them, subject to device rules |
| Isolated I/O | Separate I/O address space and I/O instructions or bus control signals |
| Synchronous transfer | Timing follows a shared clock and specified cycles |
| Asynchronous handshake | Request/data-valid and acknowledge/ready coordinate a transfer |
In a handshake, the sender keeps data valid until the receiver's acceptance condition is met. A strobe alone assumes enough timing information to sample correctly. Memory-mapped device registers may have read/write side effects, so normal caching or speculative access cannot be assumed.
7.2 Interrupt recognition, priority and return
Past papers · CS 2014–2026 (23 papers): 4 questions, 4 marks
For a conventional precise interrupt accepted between instructions: finish the current instruction; preserve the return PC and required status; obtain/load the handler PC; execute the handler; restore state and return. Hardware may save only part of the context and software the rest. An exception caused by an instruction may save a different restart PC; use the ISA's rule.
| Mechanism | Source identification and priority |
|---|---|
| Vectored interrupt | Source supplies or identifies a vector used to find its handler |
| Non-vectored interrupt | Common entry or fixed handler; software may need to identify the source |
| Software polling | Handler checks devices in an explicit order |
| Daisy-chain priority | Acknowledge passes through devices; the nearest requesting device captures it |
| Parallel priority | Hardware encoder chooses among pending requests |
| Masking/nesting | A mask disables selected sources; higher-priority requests may pre-empt if enabled |
A vector can be an index into a table, not necessarily the entire handler address. Daisy chaining determines priority in hardware; it is not CPU polling of every device. A distant device can starve under persistent higher-priority requests. Handler return must restore enough status for the interrupted computation to continue correctly.
7.3 Direct memory access and bus ownership
Past papers · CS 2014–2026 (23 papers): 5 questions, 6 marks
The CPU programs DMA source/destination addresses, direction and transfer count. DMA requests the shared bus; after grant, it drives that bus and transfers data between device and memory. Only one master drives a single shared bus at a time. The CPU may still execute work that does not require that occupied bus; DMA does not universally halt every part of the CPU.
| Mode | Transfer schedule | Main trade-off |
|---|---|---|
| Burst | Retain bus for a block | High bulk throughput, longer CPU memory wait |
| Cycle stealing | Take an individual transfer opportunity, then release | Interleaves CPU and DMA accesses |
| Transparent/idle-cycle | Use bus only when CPU does not need it | Less CPU interference, lower guaranteed DMA rate |
A DMA read of memory must see recent CPU writes; dirty cache lines may need cleaning before the transfer. A DMA write can leave stale CPU cache copies; invalidate or use a coherent DMA mechanism according to the system contract. Write-through alone does not prevent stale cached data after an external write. Synchronisation and cache maintenance are distinct from granting the bus.
Last-minute recall
- Polling repeatedly reads status; interrupt-driven I/O requests attention when needed.
- A vectored source identifies a handler; daisy chaining establishes hardware priority.
- Save the return state before overwriting it with handler state.
- DMA transfers bulk data without a CPU copy instruction for each item.
- CPU and DMA cannot simultaneously drive one shared bus as masters.
- Count registers may encode count or count minus one; check the convention.
- Multiply DMA bytes/s by eight to obtain bits/s.
- DMA can require cache cleaning or invalidation even when transfer timing is correct.