47 lines
2.0 KiB
HTML
47 lines
2.0 KiB
HTML
|
|
|
|
Under many DPMI hosts, interrupts will always remain enabled in
|
|
protected mode (i.e. the interrupt flag will be set at all times) to
|
|
allow preemptive multitasking. Such hosts will maintain a virtual
|
|
interrupt state for each virtual machine, trapping the execution of
|
|
instructions that ordinarily affect the hardware interrupt flag and
|
|
adjusting the client's virtual interrupt flag accordingly. When the
|
|
virtual interrupt flag is cleared by the client's execution of
|
|
<tt>CLI</tt> or call to <a href="api/310900.html">DPMI function Int
|
|
31H 0900H</a>, the program will not receive any hardware interrupts
|
|
until it sets the flag again with <tt>STI</tt> or calls <a
|
|
href="api/310901.html">Function 0901H</a>. DPMI clients should not
|
|
use the <tt>PUSHF</tt> instruction to examine their interrupt status.
|
|
This is because <tt>PUSHF</tt> pushes the real processor flags onto
|
|
the stack, which do not reflect the state of the client's virtual
|
|
interrupt flag. Similarly, clients cannot use <tt>IRET(D)</tt> or
|
|
<tt>POPF</tt> to alter the interrupt flag, because these instructions
|
|
access the physical interrupt flag and are ignored by the CPU due to
|
|
the client's privilege level. <p>
|
|
|
|
<b>Example:</b> The following source code demonstrates how a client
|
|
would disable virtual interrupts prior to entry to an
|
|
interrupt-critical section of code, then restore the virtual interrupt
|
|
flag to its previous state at the end of the critical section:
|
|
|
|
<pre>
|
|
|
|
mov ax,0900h ; get previous virtual interrupt
|
|
<a href="api/310900.html">int 31h</a> ; flag and disable interrupts
|
|
push ax ; save value 0900H or 0901H
|
|
.
|
|
. ; interrupt-critical code goes here
|
|
.
|
|
pop ax
|
|
<a href="api/310900.html">int 31h</a> ; restore previous interrupt flag
|
|
</pre>
|
|
|
|
If the client already knows (or does not care about) the previous
|
|
state of the virtual interrupt flag, it can use <tt>CLI</tt> and
|
|
<tt>STI</tt> instead of <a href="api/310900.html">DPMI functions
|
|
0900H</a> and <a href="api/310901.html">0901H</a>. The programmer
|
|
should assume that the execution of either of these instructions will
|
|
be slow. <p>
|
|
|
|
|