An interrupt chain is two or more interrupt handlers that process the same interrupt. Programs create interrupt chains either to extend the capabilities of existing interrupt handlers or to permit replacement handlers to take advantage of features in existing handlers. For example, some programs intercept Interrupt 21h to detect when certain MS-DOS system functions have been called. Such programs do not then carry out the system functions themselves; instead, they pass control to the original Interrupt 21h handler.
A program creates an interrupt chain by installing an interrupt handler and saving the address of the original handler. When the new handler processes the interrupt, it can either call or jump to the original handler if it needs help processing the interrupt. A new handler calls the original handler if it needs to carry out additional processing after the original handler completes its work. Otherwise, it jumps to the original handler.
When a new handler calls an original handler, it can modify the registers and stack before passing control to the original handler, but it must push the flags onto the stack (by using the pushf instruction) before making the call. In all cases, a handler should use the iret instruction to return from the interrupt.
A handler should assume nothing about the state of the system and should do the following:
Disable interrupts if it needs them disabled, and explicitly enable them otherwise. Previous handlers in the interrupt chain may or may not have enabled them.
Set the direction flag before executing string instructions.
Call the next handler in the chain immediately if the interrupt is a time-critical interrupt (for example, a timer interrupt). This ensures that handlers expecting control immediately after the interrupt get it as soon as possible.