Course: Computer Architectures
Lecture: Lecture 06 - Exceptions and Interrupts
Definition and intuition
An exceptional event redirects normal execution to a handler. In the lecture’s narrow terminology, an exception originates inside the CPU while an interrupt normally comes from an external device. The lecture also uses “exception” as an umbrella term.
A page fault belongs to an instruction attempting an access. A device interrupt requests attention independently of that instruction’s computation. In both cases, the processor must preserve enough state to resume or terminate correctly.
Several instructions are active in a pipeline, so “stop execution” requires deciding which instructions may finish and which effects must be discarded. See Precise Exceptions.
Classification
These are independent dimensions, not a single list of event types (slides 5-10).
| Dimension | Meaning | Example or qualification |
|---|---|---|
| Synchronous / asynchronous | Tied to execution of an instruction / arrives independently | Page fault / device request |
| User requested / coerced | Deliberately invoked / forced by circumstances | System call or breakpoint / protection fault |
| User maskable / nonmaskable | Can be suppressed by permitted masking / cannot be suppressed that way | Ordinary device interrupt / nonmaskable interrupt |
| Within / between instructions | Originates during the instruction / recognized at a boundary | Faulting load / interrupt taken between completed instructions |
| Resume / terminate | Execution can continue after handling / the program ends | Resolved page fault / unrecoverable violation |
Clarification: A synchronous event is tied to the instruction, not guaranteed to occur on every execution regardless of inputs or memory state. Masking permissions depend on processor privilege and event type; the slide’s “user maskable” wording does not mean every application can disable all interrupts. Whether a program resumes also depends on the cause and handler policy.
Sources by pipeline stage
Slide 20 presents the following five-stage teaching model. Detection stages depend on implementation.
| Stage | Slide examples |
|---|---|
| IF | Instruction-fetch page fault, misaligned access, protection violation |
| ID | Undefined or illegal opcode |
| EX | Arithmetic exception in the generic model |
| MEM | Data-access page fault, misaligned access, protection violation |
| WB | No new exception source in this model |
The absence of a WB source does not prevent a fault detected earlier from being handled at an ordered final stage.
RISC-V clarification
The generic EX row must not be interpreted as a promise that arithmetic anomalies trap in standard RISC-V. The standard F extension sets accrued FP exception flags in fflags; setting them does not itself generate a trap. Integer division by zero and signed division overflow also produce defined results rather than arithmetic traps.
Official references: RISC-V F extension, RISC-V M extension.
Handling and restarting
The lecture’s mechanism (slides 11-13) is:
- Detect the exceptional event and redirect control by inserting a trap into the next IF stage.
- Disable writes by the faulting instruction and all younger instructions until the trap is taken.
- Preserve the faulting instruction’s PC when the handler receives control.
- Handle the cause, preserve/restore the necessary context, and use a special return instruction to restart.
Older instructions must be allowed to finish for a precise restart. Registers, memory effects, and status must describe the correct instruction boundary; saving a PC alone is insufficient.
Which PC is restored?
For a retryable fault, such as a load whose page becomes available, retry the faulting instruction. For a completed system call, execution commonly continues after the call. For an interrupt, resume at the interrupted execution boundary. These are explanations of different cases; the exact saved PC and return behavior are defined by the ISA.
Architecture examples
Legacy 80x86 protocol (slide 14)
The device requests an interrupt; the CPU detects it and reads type N from the bus. It saves PSW and the return CS/IP on the stack, changes interrupt/trap flags, uses N to index the interrupt vector table, and transfers control to the ISR. This preserves the lecture’s legacy example, not a description of every modern x86 interrupt-delivery mode.
ARM example (slide 15)
The slide describes hardware stacking of eight registers, including PC and processor status, before transfer to the handler.
Scope clarification: Cortex-M provides this kind of basic stack frame: R0-R3, R12, LR, PC, and xPSR. Additional state may be saved depending on the processor and context. Treat the slide as an ARM-family example rather than a rule for all ARM cores.
Official reference: Arm Cortex-M7 exception entry and return.
Common mistakes
- Treating every exceptional arithmetic result as a control-flow trap.
- Assuming “maskable” means an unprivileged program can always disable it.
- Always restoring the faulting PC even when the event requires continuation after an instruction.
- Assuming the earliest detected fault must be the first handled fault.
- Saving the PC while allowing younger stores to alter memory.
Related and source
Precise Exceptions, Pipelining, Multicycle Operations, Stack, Function Calls.
E. Sanchez, Exceptions and interrupts in pipelined processors, ASE 2026/27, slides 2-15 and 20. Source PDF: Exceptions and interrupts in pipelined processors.pdf. Architecture qualifications above are study clarifications, supported by the separately linked official documentation.