Interrupts
Protected mode programs can hook both hardware and software
interrupts using the DPMI get and set protected mode
interrupt vector functions. All interrupts
from hardware devices such as the timer or keyboard
controller will always be reflected to the protected mode
interrupt handler first. If the protected mode handler
jumps to or calls the previous interrupt handler then the
interrupt will be reflected to real mode.
As in real mode, interrupt procedures can either service the
interrupt and iret or they can chain to the next handler in
the interrupt chain by executing pushf/call or by jumping to
the next handler. The final handler for all protected mode
interrupts will reflect the interrupt to real mode.
When an interrupt is reflected to real mode, the EAX, EBX,
ECX, EDX, ESI, EDI, EBP registers, and flags will all be
passed from protected to real mode unaltered. The segment
registers will contain undefined values unless an API
translator (such as a DOS or BIOS translator) explicitly
sets a real mode segment register. DPMI will automatically
provide a real mode stack for interrupts that are reflected
to real mode.
Hardware Interrupts
The interrupt controllers are mapped to the system's default
interrupts. On an IBM AT-compatible system, for example,
the master interrupt controller is programmed with a base
interrupt of 8 and the slave controller has a base of 70h.
The virtualized interrupt controllers can be reprogrammed;
the base setting may be examined in protected mode with Int
31h function 0400h.
Hardware interrupt procedures and all of their data must
reside in locked memory. All memory that is touched by
hardware interrupt hooks must be locked. The handler will
always be called on a locked stack.
As in real mode, hardware interrupt handlers are called with
interrupts disabled. Since iret will not restore the
interrupt flag, hardware interrupt hooks must execute an sti
before executing iret or else interrupts will remain
disabled.
Protected mode hardware interrupt handlers will always be
called even for interrupts that occur in real mode. The
last hook on the protected mode interrupt chain will reflect
the interrupt to real mode.
Protected mode hardware interrupt handlers that need to call
software running in real mode must either be sure that the
real mode software that they are calling will not modify
segment registers or they must use the state save service
to save and restore the real mode segment
registers. However, any interrupt handler that executes
completely in protected mode, or uses translation services
0300h, 0301h, or 0302h does not need to save the real mode
register state. Therefore, this is not an issue for most
interrupt handlers.
For compatibility with older systems, computers with two
interrupt controllers have the BIOS redirect one of the
interrupts from the slave controller into the range of the
master controller. For example, devices jumpered for IRQ 2
on IBM AT-compatible computers actually interrupt on IRQ 9
(interrupt 71h). In real mode, the BIOS on these systems
will convert interrupt 71h to Int 0Ah and EOI the slave
controller. A protected mode program that needs access to
the redirected interrupt may use variations on either of
these techniques:
1. Hook the target interrupt in real mode. This
takes advantage of the built in redirection. This
is robust on systems where other software has
reprogrammed the interrupt controllers, or where
the slave interrupt controller may be absent.
2. Hook the actual interrupt in both real and
protected mode. In this case, the program must
EOI both the slave and master interrupt
controllers since the BIOS will not get control.
This is more efficient in that there will not be
any unnecessary switches to real mode.
Software Interrupts
Most software interrupts executed in real mode will not be
reflected to the protected mode interrupt hooks. However,
some software interrupts are also reflected to protected
mode programs when they are called in real mode. These are:
INT DESCRIPTION
1Ch BIOS timer tick interrupt
23h DOS Ctrl+C interrupt
24h DOS critical error interrupt
Programs should not terminate during interrupts that were
reflected from real mode. Terminating the program at this
point may prevent the DPMI host from cleaning up properly.
Of all software interrupts, only Ints 00h-07h will be called
with virtual interrupts disabled. For these interrupts, the
handler should return with interrupts enabled. All other
interrupts will not modify the interrupt flag state.
Since most software interrupts that are executed in real
mode are not reflected to protected mode interrupt hooks,
programs would be required to install a real mode interrupt
hook to monitor these interrupts.