Interrupts
Interrupts are a way for hardware or software (Process running in user space) to get the CPU's "attention".
Interrupts forcibly change the control flow of the CPU. A typical scenario that happens when an interrupt occurs is as such:
- Hardware saves some contents on the stack
- Kernel jumps to the interrupt table
- Kernel executes the interrupt handler
- Once the interrupt handler has finished running, it calls
iret
Some types of interrupts are:
- Asynchronous
- Interrupt comes from an external source like an I/O device
- Synchronous
- Processor-detected Exceptions
- Faults
- Traps
- Aborts
- Software triggered
- System Calls (To read more on system calls, click here)
- Processor-detected Exceptions
Faults
Faults occur when an instruction would be illegal to execute.
Some examples of illegal instructions are:
- Writing to a memory that is marked
read-only
- Reading from an unavailable memory
- Insufficient privileges to execute a command
Faults are detected before the instruction pointer is incremented. The return address for the fault handler points to the faulting instruction, rather than to the instruction following the faulting instruction.
Most faults can be remedied, and the CPU can continue processing after displaying the fault.
Trap
Traps are an exception that is reported immediately following the execution of the trapping instruction.
An example would be a debugger attached to the program.
The return address for the trap handler points to the instruction to be executed after the trapping instruction.
Aborts
An abort does not always report the precise location of the instruction causing the exception and does not allow a restart of the program or task that caused the exception.
Aborts are used to report severe errors, such as hardware errors and inconsistent or illegal values in system tables.
Summary
In short, Faults do not increment the IP. Traps increment the IP. Aborts crashes the system.