An Interrupt is just a signal sent to a processor, through an Interrupt Controller circuit. That signal triggers a sequence of events that require a concerted hardware and software action. The Interrupt handling in operation systems is intimately connected with the architecture of the CPU and of the computer itself. Some examples: • Unexpected user command from the keyboard • Abnormal situation, such as power failure • Attempt to execute an illegal instruction • The completion of an I/O task Classes of Interrupts • Program - Generated by some condition that occurs as a result of an instruction execution, such as arithmetic overflow, division by zero, attempt to execute and illegal machine instruction, and reference outside a user's allowed memory space • Timer - Generated by a timer within the processor. This allows the processor to perform certain functions on a regular basis • I/O - Generated by an I/O controller, to signal normal completion of an operation or to signal a variety of error conditions • Hardware failure - Generated by a failure, such as power failure or memory parity error Servicing Interrupts: ISR = Interrupt Service Routine Some PC-compatible interrupt vectors in Pentium systems: • 08h - System Timer • 09h - Keyboard • 0bh - Serial port two • 0ch - Serial port one • 0dh - Parallel port two • 0eh - Floppy disk • 0fh - Parallel port one • 70h - Real Time Clock Alarm • 72h - Available for third party hardware usage • 73h - Available for third party hardware usage In some operating systems, Interrupt Service Routines are strongly limited as to what OS services they can use. ISR's run in kernel mode, and typically at an interrupt level that is higher - or much higher - than that of the routine that has just been interrupted. This means that the ISR must save every hardware entity it uses, including general purpose registers, segment registers, floating point registers, and others. ISR's are also supposed to be fast, because even when nesting of interrupts is allowed, a fast, high performance peripheral will hurt performance or reliability of slower devices if its interrupt service routine is too slow. Standard Interrupt Service Routine (ISR): • Save the system context, normally by pushing the desired elements into the stack or saving them into variables. • Block any interrupts that might cause interference if they are allowed to occur during this ISR execution. • Determine the cause of the interrupt. • Take the appropriate action for the interrupt. • Restore the system context, usually by popping the elements from the stack or by reading the variables. • Re-enable all interrupts blocked. • Resume execution of the interrupted process. Types of Interrupts: • Software interrupts Software interrupts are initiated with a "trap" instruction and, as the name implies, are triggered via software. For example, the instruction trap 33h issues the interrupt with the hex number 33h. Each trap instruction acts as an interrupt giving the vector specified as the interrupt. • Hardware interrupts NMI - non maskable Interrupts. This is quite easy to understand since it normally indicates a serious failure and a computer with incorrectly functioning hardware must be prevented from destroying data. IRQ - Interrupt requests. This can be masked/unmasked with special instructions that ignores/re-activates all interrupt requests. • exceptions Three main classes: • Fault - A fault issues an exception prior to completing the instruction. The saved values of the program counter then points to the same instruction that created the exception. Thus, it is possible to reload the program counter, and the processor will be able to re-execute the instruction, hopefully without another exception. • Trap - A trap issues an exception after completing the instruction execution. The saved content of the program counter points to the instruction immediately following the one that gave rise to the exception. The instruction is therefore not re-executed again. Traps are useful when, despite the fact the instruction was processed without errors, program execution should be stopped as with the case of debugger breakpoints. • Abort - Aborts usually translate very serious failures, such as hardware failures of invalid system tables. Sometimes the error address cannot be found. Therefore, recovering program execution after an abort is not always possible. Interrupt Prioritisation: Highest • 0 - Power fail • 1 - Real-time clock • 2 - Disk interface • 3 - Terminal I/O • 4 - Illegal instruction • 5 - Divide by 0 Lowest