Information Technology Reference
In-Depth Information
Processor
Register
Interrupt
Vector
handleTimerInterrupt() {
...
}
handleDivideByZero() {
...
...
}
handleTrap() {
...
...
}
Figure2.7: An interrupt vector identifies the code in the kernel to handle
various hardware interrupts, traps, and exceptions.
Interrupt vector
When an interrupt, exception or system call trap occurs, the operating system
must take different actions depending on whether the event is a divide by zero
exception, a file read system call, or a timer interrupt. How does the processor
know what code to run?
To identify the code to run on a context switch, the processor will include
a special register that points to an area of kernel memory called the interrupt
vector. The interrupt vector is an array of pointers, with each entry pointing to
the first instruction of a different handler procedure in the kernel. As Figure 2.7
illustrates, some entries might point to various interrupt handlers such as for the
timer interrupt or keyboard interrupt. Another might point to the trap handler
for handling process-initiated system calls. Still other entries might point to
various exception handlers like the handler for a divide-by-zero exception.
When an interrupt, trap, or exception occurs, the hardware determines which
hardware device caused the interrupt, whether the trap instruction was exe-
cuted, or what exception condition occurred. Thus, the hardware can select the
right entry from the interrupt vector and invoke the appropriate handler.
The format of the interrupt vector is processor-specific. On the x86, for
example, the interrupt vector entries 0 - 31 are for different types of hardware
exceptions, entries 32 - 255 are for different types of interrupts, and by conven-
tion, entry 64 points to the system call trap handler.
Of course, the interrupt vector must be stored in protected kernel memory;
otherwise a process could, for example, hijack the network by directing all net-
work interrupts to its own code. Similarly, the hardware register that points to
Search WWH ::




Custom Search