Interrupt signals may be issued in response to
hardware or
software events. These are classified as
hardware interrupts or
software interrupts, respectively. For any particular processor, the number of interrupt types is limited by the architecture.
Hardware interrupts A hardware interrupt is a condition related to the state of the hardware that may be signaled by an external hardware device, e.g., an
interrupt request (IRQ) line on a PC, or detected by devices embedded in processor logic (e.g., the CPU timer in IBM System/370), to communicate that the device needs attention from the
operating system (OS) or, if there is no OS, from the
bare metal program running on the CPU. Such external devices may be part of the computer (e.g.,
disk controller) or they may be external
peripherals. For example, pressing a
keyboard key or moving a
mouse plugged into a
PS/2 port triggers hardware interrupts that cause the processor to read the keystroke or mouse position. Hardware interrupts can arrive
asynchronously with respect to the processor clock, and at any time during instruction execution. Consequently, all incoming hardware interrupt signals are conditioned by synchronizing them to the processor clock, and acted upon only at instruction execution boundaries. In many systems, each device is associated with a particular IRQ signal. This makes it possible to quickly determine which hardware device is requesting service, and to expedite servicing of that device. On some older systems, such as the 1964
CDC 3600, all interrupts went to the same location, and the OS used a specialized instruction to determine the highest-priority outstanding unmasked interrupt. On contemporary systems, there is generally a distinct interrupt routine for each type of interrupt (or for each interrupt source), often implemented as one or more
interrupt vector tables.
Masking To
mask an interrupt is to disable it, so it is deferred or ignored by the processor, while to
unmask an interrupt is to enable it. Processors typically have an internal
interrupt mask register, which allows selective enabling
Missing interrupts One failure mode is when the hardware does not generate the expected interrupt for a change in state, causing the operating system to wait indefinitely. Depending on the details, the failure might affect only a single process or might have global impact. Some operating systems have code specifically to deal with this. As an example, IBM
Operating System/360 (OS/360) relies on a not-ready to ready device-end interrupt when a tape has been mounted on a tape drive, and will not read the tape label until that interrupt occurs or is simulated. IBM added code in OS/360 so that the VARY ONLINE command will simulate a device end interrupt on the target device.
Spurious interrupts A
spurious interrupt is a hardware interrupt for which no source can be found. The term "phantom interrupt" or "ghost interrupt" may also be used to describe this phenomenon. Spurious interrupts tend to be a problem with a
wired-OR interrupt circuit attached to a level-sensitive processor input. Such interrupts may be difficult to identify when a system misbehaves. In a wired-OR circuit,
parasitic capacitance charging/discharging through the interrupt line's bias resistor will cause a small delay before the processor recognizes that the interrupt source has been cleared. If the interrupting device is cleared too late in the interrupt service routine (ISR), there will not be enough time for the interrupt circuit to return to the quiescent state before the current instance of the ISR terminates. The result is the processor will think another interrupt is pending, since the voltage at its interrupt request input will be not high or low enough to establish an unambiguous internal logic 1 or logic 0. The apparent interrupt will have no identifiable source, hence the "spurious" moniker. A spurious interrupt may also be the result of electrical
anomalies due to faulty circuit design, high
noise levels,
crosstalk, timing issues, or more rarely,
device errata. A spurious interrupt may result in system deadlock or other undefined operation if the ISR does not account for the possibility of such an interrupt occurring. As spurious interrupts are mostly a problem with wired-OR interrupt circuits, good programming practice in such systems is for the ISR to check all interrupt sources for activity and take no action (other than possibly logging the event) if none of the sources is interrupting.
Software interrupts A software interrupt is requested by the processor itself upon executing particular instructions or when certain conditions are met. Every software interrupt signal is associated with a particular interrupt handler. A software interrupt may be intentionally caused by executing a special
instruction which, by design, invokes an interrupt when executed. Such instructions function similarly to
subroutine calls and are used for a variety of purposes, such as requesting operating system services and interacting with
device drivers (e.g., to read or write storage media). Software interrupts may also be triggered by program execution errors or by the
virtual memory system. Typically, the operating system
kernel will catch and handle software interrupts. Some interrupts are handled transparently to the program - for example, the normal resolution of a
page fault is to make the required page accessible in physical memory. But in other cases such as a
segmentation fault the operating system executes a process callback. On
Unix-like operating systems this involves sending a
signal such as
SIGSEGV,
SIGBUS,
SIGILL or
SIGFPE, which may either call a signal handler or execute a default action (terminating the program). On Windows the callback is made using
Structured Exception Handling with an exception code such as STATUS_ACCESS_VIOLATION or STATUS_INTEGER_DIVIDE_BY_ZERO. Intentional software interrupts for
system calls result in calls to routines in the kernel to perform the function requested by the system call. In a kernel
process, it is often the case that some types of software interrupts are not supposed to happen. If they occur nonetheless, an
operating system crash may result.
Terminology The terms
interrupt,
trap,
exception,
fault, and
abort are used to distinguish types of interrupts, although "there is no clear consensus as to the exact meaning of these terms". The term
trap may refer to any interrupt, to any software interrupt, to any synchronous software interrupt, or only to interrupts caused by instructions with
trap in their names. In some usages, the term
trap refers specifically to a
breakpoint intended to initiate a
context switch to a
monitor program or
debugger. (Hardware) interrupts are interrupts triggered asynchronously by an I/O device, and allow the program to be restarted with no loss of continuity. A fault is restartable as well but is tied to the synchronous execution of an instruction - the return address points to the faulting instruction. A trap is similar to a fault except that the return address points to the instruction to be executed after the trapping instruction;
ARM uses the term
exception to refer to all types of interrupts, and divides exceptions into (hardware)
interrupts,
aborts,
reset, and exception-generating instructions. Aborts correspond to x86 exceptions and may be prefetch aborts (failed instruction fetches) or data aborts (failed data accesses), and may be synchronous or asynchronous. Asynchronous aborts may be precise or imprecise. MMU aborts (page faults) are synchronous.
RISC-V uses interrupt as the overall term as well as for the external subset; internal interrupts are called exceptions. ==Triggering methods==