Generalities about Interrupts
An interrupt causes the computer to stop doing what it is doing, save the current state of the interrupted program and transfers control to an interrupt handler, which is in another program or the operating system. When it saves the state information, it must save all the of necessary information so that the interrupted program can resume without any indication of being interrupted. An interrupt is said to be transparent to the interrupted program. There are hardware and software interrupts. In general, interrupts can be viewed as a good thing, when the interrupts handlers are properly written and interrupts don't happen too often. Examples of when interrupts are used are:- Completion of I/O, such as key presses and releases. This allows the computer to computations in what would be the wasted time between keystokes and greatly increasing the computers productivity [throughput].
- Computers have a real-time clock that will cause a set number of interrupts per second. This keeps the the time-of-day clock up to date and to give each user a time-slice so that the computer can be a time-shared system or multiprocessing system. There are also interval timers which allow the system to be interrupted at the request of the applications programmer.
- Error interrupts such as divide by zero, illegal opcode, illegal memory address [does not exist or is allocated to another program] and hardware error conditions [out of paper on the printer, floppy disk door open, etc].
- Exection of a group of instructions such as INT 21 to do the input and output we saw in earlier chapters.
Interrupts can be enabled or disabled. There are some operations that can only take place reliably when interrupts are disabled, however disabling interrupts is not something that we want to happen indiscrimanately! Additionally, there are some interrupts that can not be disabled, such as caused by power failure or machine errors. We can disable some by changing a bit in a mask, and they are called maskable interrupts and the others are called non-maskable interrupts.
More than one interrupt can occur during the execution of an instruction. When this happens, at the end of the instruction, the CPU picks one interrupt to be serviced. The others are held until the end of another instruction, when another one will be serviced.
There are many ways to classify interrupts:
- hardware vs software generated interrupts.
- internal [within the CPU] vs external interrupts.
- asynchronous or synchronous interrupts.
- error condition or normal condition interrupts.
Interrupt Processing on the 80X86
There are 256 interrupts possible on the X86 computers. An interrupt can be either hardware or software. The hardware interrupts come from devices within the computer system. Software interrupts are caused to executing the instruction: While in the user mode in Linux, we can only use INT 80h because this is a constraint imposed by the operating system so that we can have multiprocessing. Windows and DOS allow the applications access to all interrupts. In order to have more power, the DOS interrupt systems allowed sub-functions within a specific interrupt.Interrupts can be enables or disable with the instructions:
sti | ;set I flag to 1, enable | |
cli | ;set I flag to 0, disable |
The interruption mechanism is:
- When an device wishes to cause an interrupt, it makes an interrupt request that includes the number of the interrupt. When arriving in the CPU it is held until the completion of the current instruction.
- At the end of each instruction, before the next instruction is fetched, the CPU checks to see if there are any interrupts waiting. If there is, one is selected for interrupt service and the others are held.
- The CPU does the following items:
- Push the flag register onto the stack
- Disable interrupts.
- Push the CS and IP registers.
- Load the address of the handler.
iret | ;return from interrupt. |
The interrupt vector table is setup by the boot-up procedure in the BIOS when the computer starts up, setting addresses puter starts up, setting addresses of interrupt handlers for interrupts that the BIOS handles, and initializing the rest to a handler that consists of nothing but the iret instruction. This makes it easy to upgrade the handlers in future releases of the operating system or even to have a different operating system altogether. When the operating system loads, it puts in the address of its handlers where necessary. Additionally, the user can piggy-back on an interrupt, as we shall see.
WARNING: Since interrupts occur at any time, they wipe out anything that had been put onto the stack previously. Never assume that something you popped is still on the stack waiting for you!
A Short History of Interrupts
Early computers were purely uniprocessing. The CPU executed until I/O was required, and then cam a grinding halt until the I/O was complete. CPS's were very fast and expensive, operating at electronic speed while I/O devices were extremely slow and inexpensive, operating at mechanical speed. It became obvious that the I/O needed to be decoupled from computation.With the introduction of the interrupt, I/O programming became much more complicated and the batch processing became popular. More and more demands were put on the system to increase productivity!
Certain operations became designated privileged. There were two states that the computer could operate in:
- user state -- for ordinary user programs
- supervisor or kernel state -- for the OS
Previous | Next