Interrupts
# Interrupts
An interrupt is a request for the processor to interrupt currently executing code so that the event can be processed in a timely manner. It usually refers to hardware interrupts triggered by, for example, USB controllers, which generate them on the basis of some event. Interrupts can also include Exceptions, which are triggered by the CPU itself.
# Interrupt Controller
Connecting all hardware devices directly to the CPU is not possible. Instead, a separate interrupt controller aggregates the interrupts from all devices and then notifies the CPU:
|
|
# 8259 Programmable Interrupt Controller (PIC)
The 8259 has eight interrupt lines and several lines for communicating with the CPU. The typical systems back then were equipped with two instances of the 8259 PIC, one primary and one secondary PIC, connected to one of the interrupt lines of the primary:
|
|
This graphic shows the typical assignment of interrupt lines. We see that most of the 15 lines have a fixed mapping, e.g., line 4 of the secondary PIC is assigned to the mouse.
# Interrupt Service Routine
# Interrupt Handling
- Context Switch
- Determines the type of interrupt that has occurred using the segments of code
- Executes the appropriate ISR based on the interrupt vector table The ISR is a very short routine so as to not suspend the main program for too long. This usually means no usage of loops.
- Allows for efficient use of CPU as it does not need to monitor I/O device status
- More hardware is required between I/O and processor to interface with each other
# Interrupt Stack Table (IST) and Task State Segment (TSS)
The 64-bit TSS has the following format:
Field | Type |
---|---|
(reserved) | u32 |
Privilege Stack Table | [u64; 3] |
(reserved) | u64 |
Interrupt Stack Table | [u64; 7] |
(reserved) | u64 |
(reserved) | u16 |
I/O Map Base Address | u16 |
The Privilege Stack Table is used by the CPU when the privilege level changes. For example, if an exception occurs while the CPU is in user mode (privilege level 3), the CPU normally switch to kernel mode (privilege level 0) before invoking the exception handler.