Exceptions Handling

Interrupts

Interrupts are signals that alter the normal control flow of a program at runtime. An interrupt must be handled by a dedicated interrupt handler, and the architecture should be able to resume the normal execution of the program. Causes:

  • Asynchronous external events:
    • I/O device reply
    • timer expiration
    • HW failure
  • Synchronous internal event:
    • opcode error
    • arithmetic overflow
    • bad memory access
    • traps: traps are a mechanism used by computers to transfer control to the OS or to kernel routines in response to various events like system calls.

Interrupts can be characterized in various ways:

  • Async interrupts are caused by external sources and can be handled at the end of the execution of the current instruction, making them easier to manage than sync ones.
  • User request interrupts are predictable: they are treated as exceptions because they use the same mechanism. Coerced interrupts (forced) are caused by some HW event not under control of the program.
  • User maskable vs user nonmaskable
  • Within instructions interrupts are usually synchronous since the instruction triggers the exception. The instruction must be stopped and restarted.
  • Resume vs terminate interrupts

Super exception table

Exception typeSynchronous vs. asynchronousUser request vs. coercedOser maskable vs. nonmaskableWithin vs. between instructionsResume vs. terminate
I/O device requestAsynchronousCoercedNonmaskableBetweenResume
Invoke operating system Tracing instruction executionSynchronousUser requestNonmaskableBetweenResume
Breakpoint Integer arithmetic overflowSynchronousUser requestUser maskableBetweenResume
Floating-point arithmetic overflow or underflowSynchronousCoercedUser maskableWithinResume
Page faultSynchronousCoercedNonmaskableWithinResume
Mischaligned memory accessesSynchronousCoercedUser maskableWithinResume
Memory protection violationsSynchronousCoercedNonmaskableWithinResume
Using undefined instructionsSynchronousCoercedNonmaskableWithinTerminate
Hardware malfunctionsAsynchronousCoercedNonmaskableWithinTerminate
Power failureAsynchronousCoercedNonmaskableWithinTerminate