Exceptions

Overview

An exception is an abrupt change in the control flow in response to some change in the processor's state. The change in state is known as an event.

When an event occurs, the processor makes an indirect procedure call (the exception), though a jump table (the exception table), to an operating system subroutine (the exception hander) specifically designed to process this kind of event.

Afterward, one of the following occurs:

  1. The handler returns control to the current instruction.
  2. The handler returns control to the instruction that would have executed had the exception not occurred.
  3. The handler aborts the interrupted program.

Exception Table

Every exception is given a unique nonnegative integer called its exception number. This is used as an index into the exception table in which entry k contains the address of the handler for exception k.

The starting address of the exception table is contained in a special CPU register called the exception table base register (ETBR).

exception-table.png

Exception Classes

There exist four classes of exceptions with the following characteristics:

Name Cause Async/Sync Return Behavior
Interrupt Signal from I/O device Async Returns to next instruction
Trap Intentional exception Sync Returns to next instruction
Fault Potentially recoverable error Sync Might return to current instruction
Abort Nonrecoverable error Sync Never Returns

Interrupts

An interrupt is an asynchronous exception, signaled from an I/O device.

interrupt-diagram-text.png

Traps

A trap is an intentional exception that occurs as a result of executing an instruction. The most important use of traps is to provide system calls.

trap-diagram-text.png

Faults

A fault is an exception that occurs from error conditions that a handler might be able to correct.

fault-diagram-text.png

Aborts

An abort is an exception that occurs from unrecoverable fatal errors. Control is never returned to the user program.

abort-diagram-text.png

Powered by Forestry.md