Stacks and Stack Switching


Every DPMI task runs on four different stacks: An
application ring protected mode stack, a locked protected
mode stack, a real mode stack, and a DPMI host ring 0 stack.

The protected mode stack is the one the DPMI client was
running on when it switched into protected mode by calling
the protected mode entry point (although the client can
switch to another protected mode stack if desired). The
locked protected mode stack is provided by the DPMI server
and is used for simulating hardware interrupts and
processing real mode call-backs. The DPMI host provides the
real mode stack, which is usually located in the data area
provided by the client. The ring 0 stack is only accessible
by the DPMI host. However, this stack may contain state
information about the currently running program.


Protected Mode Stack

This is the stack that the client uses for normal execution
in protected mode. The protected mode stack of a DPMI
client can be unlocked if desired. Software interrupts
executed in protected mode will be reflected on this stack.

Locked Protected Mode Stack

During hardware interrupts, Int 1Ch, Int 23h, Int 24h,
exceptions, and real mode call-back handling in protected
mode, the DPMI will host automatically switch to a locked
protected mode stack. When the interrupt or call returns,
the host will return to the original protected mode stack.
Note that there is only one, 4K, locked stack provided by
the host. The stack will be switched onto the first time an
interrupt or call is reflected to protected mode, and will
be switched away from when the client returns. Subsequent
nested interrupts or calls will not cause a stack switch.
Software interrupts do not automatically switch stacks.

Real Mode Stack

The DPMI host will provide the client with a real mode stack
that is at least 200h bytes in size and will always be
locked. Interrupts that are reflected into real mode, as
well as calls made using the translation services, will be
reflected on this stack. DPMI hosts will not automatically
switch stacks for hardware interrupt processing in real mode
since DOS performs this function automatically.

DPMI Host Ring 0 Stack

DPMI hosts will normally have a stack associated with each
DPMI task. The DPMI client will not be able to access this
stack in any way -- it is used by the host for execution at
ring 0 to handle interrupts and exceptions. This stack will
sometimes be used to store state information while switching
modes. For example, the original SS:ESP of the protected
mode program could be saved on the ring 0 stack while the
DPMI host switches onto the locked protected mode stack.