Interrupts
The interrupt mechanism is implemented as follows:
- A device controller, which is a piece of hardware in the device whose purpose is to control the device's I/O signals, sends a signal to the CPU via a wire called an interrupt-request line.
- In-between the execution of some program's instructions, the CPU notices that the controller issued a signal, and reads the interrupt number (which indicates what the interrupt type is.)
- The CPU uses this number as an index into the interrupt vector to call the appropriate interrupt handler.
- The handler first saves the current execution state (so that the CPU could return executing code after the interrupt is handled,) finds the reason for the interrupt, performs all the actions needed to resolve the interrupt, restores the saved execution state, and returns.
- The CPU now continues to execute the instructions of the program that was running before the interrupt occurred.