Intel 64 and IA-32 Architectures Software Developers Manual Volume 3A, System Programming Guide, Part 1
Vol. 3A 15-23
8086 EMULATION
program. But actually the IF flag, managed by the operating system, always controls
whether maskable hardware interrupts are enabled. Also, if under these circum-
stances an 8086 program tries to read or change the IF flag using the PUSHF or POPF
instructions, the processor will change the VIF flag instead, leaving IF unchanged.
The VIP flag provides software a means of recording the existence of a deferred (or
pending) maskable hardware interrupt. This flag is read by the processor but never
explicitly written by the processor; it can only be written by software.
If the IF flag is set and the VIF and VIP flags are enabled, and the processor receives
a maskable hardware interrupt (interrupt vector 0 through 255), the processor
performs and the interrupt handler software should perform the following opera-
tions:
1. The processor invokes the protected-mode interrupt handler for the interrupt
received, as described in the following steps. These steps are almost identical to
those described for method 1 interrupt and exception handling in Section
15.3.1.1, “Handling an Interrupt or Exception Through a Protected-Mode Trap or
Interrupt Gate”:
a. Switches to 32-bit protected mode and privilege level 0.
b. Saves the state of the processor on the privilege-level 0 stack. The states of
the EIP, CS, EFLAGS, ESP, SS, ES, DS, FS, and GS registers are saved (see
Figure 15-4).
c. Clears the segment registers.
d. Clears the VM flag in the EFLAGS register.
e. Begins executing the selected protected-mode interrupt handler.
2. The recommended action of the protected-mode interrupt handler is to read the
VM flag from the EFLAGS image on the stack. If this flag is set, the handler makes
a call to the virtual-8086 monitor.
3. The virtual-8086 monitor should read the VIF flag in the EFLAGS register.
— If the VIF flag is clear, the virtual-8086 monitor sets the VIP flag in the
EFLAGS image on the stack to indicate that there is a deferred interrupt
pending and returns to the protected-mode handler.
— If the VIF flag is set, the virtual-8086 monitor can handle the interrupt if it
“belongs” to the 8086 program running in the interrupted virtual-8086 task;
otherwise, it can call the protected-mode interrupt handler to handle the
interrupt.
4. The protected-mode handler executes a return to the program executing in
virtual-8086 mode.
5. Upon returning to virtual-8086 mode, the processor continues execution of the
8086 program.
When the 8086 program is ready to receive maskable hardware interrupts, it
executes the STI instruction to set the VIF flag (enabling maskable hardware inter-