Interrupt Handlers

When the CPU gets an interrupt, it must execute a program to handle the interrupt. (For example, when the user presses a key on the keyboard, the CPU must execute a special program that copies the keystroke value into memory, and displays the value on the monitor). These special programs are called interrupt handlers, and may original from several different sources:

  • BIOS Programs
When the PC is turned on, or "booted", the programs in the BIOS ROM chip are copied into upper memory (called shadowing).  These programs are relatively small (between 1 - 8 MB), since they are meant for only a small number of standard devices, such as the keyboard, monitor and storage devices.
 
  • BIOS Extensions
Many devices, such as sound cards and network cards have so many variations in their configurations that it would be impossible for any BIOS to include all of the programs needed to handle them.  As a result, the programs for these devices are often found in a separate BIOS chip on the expansion card itself.  These "external" programs are sometimes called BIOS extensions.  Like the standard BIOS programs, they are copied into upper memory when the computer is booted.

The small programs found in the BIOS and BIOS Extensions are sometimes known as firmware, which refers to the fact that they have a closer relationship to the PC's hardware than normal software programs.
 

  • Device Drivers
Device Drivers are low-level programs that are similar to the firmware programs found in the BIOS and BIOS extensions.  Like firmware programs, they are needed to make a hardware device work, improve the performance of a hardware device, or add functionality to a hardware device.  However, unlike firmware programs, device drivers are packaged (usually in CD-ROM format) and distributed with the particular device.  After the device is physically installed, an installation program is used to copy the device drivers to a permanent location on the hard disk.  When the computer is booted, the device drivers are then loaded into memory along with the firmware programs found in the standard BIOS and the BIOS extensions.

Typically, device drivers are used to enhance or improve the BIOS extensions on the adapter card for that device, or they are use for devices that do not require an expansion card (such as a printer).
 

 

Interrupt Vectors

Since firmware programs and device drivers are loaded into memory when the PC is booted, they may not always be in the same memory location. How does the CPU know where to find the correct program when a particular interrupt occurs?

The memory location of each program is then stored in an interrupt vector table in lower memory. When a hardware or software interrupt occurs, the CPU responds by searching the interrupt vector table to find the location of the interrupt handler, then locates and executes it.

Each time the PC is booted, a special table is created in memory that stores the starting location of each interrupt handler program, along with the IRQ that it is associated with. This table is called an interrupt vector table. When an interrupt occurs, the CPU looks in the table to find the address of the interrupt handler that it needs. Then it goes to that address, and executes the interrupt handler.

The figure on the right shows the relationship between interrupt vectors and interrupt handlers:

When the user the presses a key on the keyboard, the following sequence occurs:

  • An interrupt signal travels from the keyboard, along IRQ1 to the CPU.
  • The CPU copies all of its registers to a special area called the “stack”.
  • The CPU knows that the signal came from IRQ1, so it looks in the Interrupt Vector Table for the IRQ1 record.
  • The IRQ1 record says that the required interrupt handler program is found in memory at address C.
  • The CPU goes to address C and executes the interrupt handler program. The program is very simple - it simply retrieves the keystroke value from the keyboard buffer, copies it into a corresponding I/O address in memory, and (depending on the application) displays the character on the screen (which may actually involve another interrupt).
  • The program has now successfully handled the keystroke. The CPU retrieves its previous contents from the stack, and continues where it left off.
Interrupt Vectors