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).

DimensionMeaningExample or qualification
Synchronous / asynchronousTied to execution of an instruction / arrives independentlyPage fault / device request
User requested / coercedDeliberately invoked / forced by circumstancesSystem call or breakpoint / protection fault
User maskable / nonmaskableCan be suppressed by permitted masking / cannot be suppressed that wayOrdinary device interrupt / nonmaskable interrupt
Within / between instructionsOriginates during the instruction / recognized at a boundaryFaulting load / interrupt taken between completed instructions
Resume / terminateExecution can continue after handling / the program endsResolved 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.

StageSlide examples
IFInstruction-fetch page fault, misaligned access, protection violation
IDUndefined or illegal opcode
EXArithmetic exception in the generic model
MEMData-access page fault, misaligned access, protection violation
WBNo 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:

  1. Detect the exceptional event and redirect control by inserting a trap into the next IF stage.
  2. Disable writes by the faulting instruction and all younger instructions until the trap is taken.
  3. Preserve the faulting instruction’s PC when the handler receives control.
  4. 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.

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.