Sub topic 6
Interrupt Types, Masking, Vectoring and Daisy-Chain Priority
Assume that you know CPU registers, memory, buses, the instruction cycle, and stack-based subroutine calls and returns. This chapter focuses on how a processor decides which interrupt to accept and which service routine to execute.
Why interrupts need control
An interrupt is a signal that asks the CPU to pause its current program and handle an event. A device might raise an interrupt when it has received a byte, finished a transfer, or detected an error.
The CPU cannot safely accept every request immediately. Several devices may request service at the same time. Some events are more urgent than others. The CPU may also be executing a short sequence that must not be interrupted.
Interrupt control answers three questions:
- Can the CPU ignore this request temporarily?
- Which request has the highest priority?
- Where is the code that handles the request?
Maskable and non-maskable interrupts
A maskable interrupt can be disabled by a control bit in the CPU's status register. The operating system or interrupt service routine (ISR) can mask interrupts while protecting a critical section. A critical section is a sequence of instructions that must execute without interruption.
When the CPU clears the interrupt-enable bit, ordinary device requests remain pending or are ignored according to the processor design. The CPU can enable them again after the critical section.
A non-maskable interrupt (NMI) cannot be disabled by the normal interrupt-mask bit. It is reserved for events that require urgent attention, such as a serious hardware failure, power loss warning, or memory error.
| Type | Can software disable it? | Typical use |
|---|---|---|
| Maskable interrupt | Yes, using an interrupt-enable or mask bit | Normal device I/O |
| Non-maskable interrupt | No, not through the ordinary mask bit | Severe hardware fault |
Masking is not the same as removing an interrupt. A masked device may keep its request pending. When interrupts become enabled, the CPU may service that request.
Vectored and non-vectored interrupts
In a vectored interrupt, the interrupt source identifies the address of its ISR, either directly or through an interrupt vector. An interrupt vector is a table entry containing the starting address of a service routine. The CPU uses the vector to jump quickly to the correct handler.
For example, vector number 5 might identify the keyboard ISR, while vector number 9 identifies a timer ISR. The vector table may be stored at a fixed memory location.
In a non-vectored interrupt, the CPU enters a common address supplied by the processor. Software must determine which device requested service, often by examining device status registers. This adds decision time and usually requires polling the devices after the interrupt occurs.
A common mistake is to confuse the interrupt signal with the vector. The signal requests service. The vector identifies the service routine.
What the CPU does when it accepts an interrupt
The exact sequence depends on the architecture, but the general process is:
- The device raises an interrupt request.
- The CPU finishes the current instruction.
- The CPU checks whether interrupts are enabled and whether the request has sufficient priority.
- The CPU saves enough state to resume the interrupted program, such as the program counter and status register.
- The CPU obtains an interrupt vector, or branches to a common interrupt entry point.
- The ISR saves any additional registers that it will use.
- The ISR identifies the device, transfers or acknowledges the data, and clears the request.
- A return-from-interrupt instruction restores the saved state and resumes the interrupted program.
The CPU normally does not stop halfway through an instruction to service a maskable interrupt. This property makes interrupt timing easier to reason about.
Priority and masking
If multiple requests arrive together, the interrupt controller applies a priority scheme. A fixed priority assigns each source a permanent rank. A rotating priority changes the highest rank after each service, which can reduce starvation.
Starvation occurs when a low-priority device waits indefinitely because higher-priority requests keep arriving.
Mask bits can provide finer control. A CPU may globally disable interrupts, while an interrupt controller independently masks selected sources. Some systems allow a currently executing ISR to block only interrupts at the same or lower priority and allow higher-priority interrupts to preempt it.
Daisy-chain priority
A daisy-chain scheme connects interrupting devices in a sequence. The interrupt request lines may be combined, so the CPU knows that at least one device needs service. The CPU then sends an interrupt-acknowledge signal through the chain.
The first requesting device in the chain captures the acknowledge signal, places its vector on the bus, and prevents the signal from reaching devices farther down the chain. Therefore, physical position determines priority. The device nearest the CPU has the highest priority.
Daisy chaining is simple and uses few control wires. Its drawbacks are that a failed device can disrupt devices after it, and low-position devices can suffer starvation. Reordering the hardware changes the priority.
Common errors in exam problems
- A maskable interrupt is not necessarily low priority. Maskability and priority are separate properties.
- Vectored means the ISR address is selected through a vector. It does not mean the interrupt is non-maskable.
- In a daisy chain, the nearest device usually wins, even if another device requested service earlier.
- The CPU usually completes the current instruction before accepting a maskable interrupt.
- DMA completion interrupts still require CPU interrupt handling. DMA reduces data-movement work, but it does not eliminate all interrupts.
Exercise
Three devices are connected in a daisy chain in the order A, B, C, with A closest to the CPU. Devices B and C request interrupts at the same time. Which device is serviced first, and why?
Show answer
Device B is serviced first. The CPU's interrupt-acknowledge signal reaches B before C, so B captures the signal and supplies its vector. B has higher priority than C in this physical ordering.