TRANSLATION SERVICES
These services are provided so that protected mode programs
can call real mode software that DPMI does not support
directly. The protected mode program sets up a data
structure that contains the values for every register. The
data structure is defined as:
Offset Register
00h EDI
04h ESI
08h EBP
0Ch Reserved by system
10h EBX
14h EDX
18h ECX
1Ch EAX
20h Flags
22h ES
24h DS
26h FS
28h GS
2Ah IP
2Ch CS
2Eh SP
30h SS
You will notice that all of the fields are dwords so that 32
bit registers can be passed to real mode. Most real mode
software will ignore the high word of the extended
registers. However, you can write a real mode procedure
that uses 32-bit registers if you desire. Note that 16-bit
DPMI implementations may not pass the high word of 32-bit
registers or the FS and GS segment registers to real mode
even when running on an 80386 machine.
Any interrupt handler or procedure called must return with
the stack in the same state as when it was called. This
means that the real mode code may switch stacks while it is
running but it must return on the same stack that it was
called on and it must pop off the entire far return/iret
structure.
After the call or interrupt is complete, all real mode
registers and flags except SS, SP, CS, and IP will be copied
back to the real mode call structure so that the caller can
examine the real mode return values.
Remember that the values in the segment registers should be
real mode segments, not protected mode selectors.
The translation services will provide a real mode stack if
the SS:SP fields are zero. However, the stack provided is
relatively small. If the real mode procedure/interrupt
routine uses more than 30 words of stack space then you
should provide your own real mode stack.
It is possible to pass parameters to real mode software on
the stack. The following code will call a real mode
procedure with 3 word parameters:
Protected_Mode_Code:
push Param1
push Param2
push Param3
(Set ES:DI to point to call structure)
mov cx, 3 ; Copy 3 words
mov ax, 0301h ; Call real mode proc
int 31h ; Call the procedure
add sp, 6 ; Clean up stack
The real mode procedure would be called with the following
data on the real mode stack:
Param1
Param2
Param3
Return
CS
Return
IP
<-- Real mode SS:SP
If your program needs to perform a series of calls to a real
mode API it is sometimes more convenient to use the
translation services to call a real mode procedure in your
own program. That procedure can then issue the API calls in
real mode and then return to protected mode. This also
avoids the overhead of a mode switch for each API call.
There is also a mechanism for protected mode software to
gain control from real mode via a real mode call-back
address. Real mode call-backs can be used to hook real mode
interrupts or to be called in protected mode by a real mode
driver. For example, many mouse drivers will call a
specified address whenever the mouse is moved. This service
allows the call-back to be handled by software running in
protected mode.