-End-of-Interrupt (EOI) Command
After an interrupt service routine is complete, the 8259 Interrupt Controller must be
acknowledged by writing the value 20h to port 20h.
-What exactly happens when an interrupt occurs?
Understanding the sequence of events when an interrupt is triggered is necessary to
correctly write interrupt handlers. When an interrupt request line is driven high by a peripheral
device (such as the DM5854), the interrupt controller checks to see if interrupts are enabled for
that IRQ, and then checks to see if other interrupts are active or requested and determines which
interrupt has priority. The interrupt controller then interrupts the processor. The current code
segment (CS), instruction pointer (IP), and flags are pushed onto the system stack, and a new
set if CS and IP are loaded from the lowest 1024 bytes of memory.
This table is referred to as the interrupt vector table and each entry to this table is called an
interrupt vector. Once the new CS and IP are loaded from the interrupt vector table , the
processor starts to execute code from the new Code Segment (CS) and from the new Instruction
Pointer (IP). When the interrupt routine is completed the old CS and IP are popped from the
system stack and the program execution continues from the point it was interrupted.
-Using Interrupt in your Program
Adding interrupt support to your program is not as difficult as it may seem especially
when programming under DOS. The following discussion will cover programming under DOS.
Note, that even the smallest mistake in your interrupt program may cause the computer to hang
up and will only restart after a reboot. This can be frustrating and time-consuming.
-Writing an Interrupt Service Routine (ISR)
The first step in adding interrupts to your software is to write an interrupt service routine
(ISR). This is the routine that will be executed automatically each time an interrupt request
occurs for the specified IRQ. An ISR is different from other subroutines or procedures. First,
on entrance the processor registers must be pushed onto the stack before anything else! Second,
just before exiting the routine , you must clear the interrupt on the DM6854HR by writing to
address BA+0, and write the EOI command to the interrupt controller. Finally, when exiting the
interrupt routine the processor registers must be popped from the system stack and you must
execute the IRET assembly instruction. This instruction pops the CS, IP and processor flags from
the system stack. These were pushed onto the stack when entering the ISR.
Most compilers allow you to identify a function as an interrupt type and will automatically
add these instructions to your ISR with one exception: most compilers do not automatically add
the EOI command to the function, you must do it yourself. Other than this and a few exceptions
discussed below, you can write your ISR as any code routine. It can call other functions and
DM5854HR/DM6854HR Page 37 (c) RTD Finland Oy 1996-2001