Intel architecture ia-32 User Manual
16-8 Vol. 3A
MIXING 16-BIT AND 32-BIT CODE
16.4.3
Interrupt Control Transfers
A program-control transfer caused by an exception or interrupt is always carried out through an
interrupt or trap gate (located in the IDT). Here, the type of the gate (16-bit or 32-bit) determines
the operand-size attribute used in the implicit call to the exception or interrupt handler procedure
in another code segment.
interrupt or trap gate (located in the IDT). Here, the type of the gate (16-bit or 32-bit) determines
the operand-size attribute used in the implicit call to the exception or interrupt handler procedure
in another code segment.
A 32-bit interrupt or trap gate provides a safe interface to a 32-bit exception or interrupt handler
when the exception or interrupt occurs in either a 32-bit or a 16-bit code segment. It is sometimes
impractical, however, to place exception or interrupt handlers in 16-bit code segments, because
only 16-bit return addresses are saved on the stack. If an exception or interrupt occurs in a 32-bit
code segment when the EIP was greater than FFFFH, the 16-bit handler procedure cannot
provide the correct return address.
when the exception or interrupt occurs in either a 32-bit or a 16-bit code segment. It is sometimes
impractical, however, to place exception or interrupt handlers in 16-bit code segments, because
only 16-bit return addresses are saved on the stack. If an exception or interrupt occurs in a 32-bit
code segment when the EIP was greater than FFFFH, the 16-bit handler procedure cannot
provide the correct return address.
16.4.4
Parameter Translation
When segment offsets or pointers (which contain segment offsets) are passed as parameters
between 16-bit and 32-bit procedures, some translation is required. If a 32-bit procedure passes
a pointer to data located beyond 64 KBytes to a 16-bit procedure, the 16-bit procedure cannot
use it. Except for this limitation, interface code can perform any format conversion between
32-bit and 16-bit pointers that may be needed.
between 16-bit and 32-bit procedures, some translation is required. If a 32-bit procedure passes
a pointer to data located beyond 64 KBytes to a 16-bit procedure, the 16-bit procedure cannot
use it. Except for this limitation, interface code can perform any format conversion between
32-bit and 16-bit pointers that may be needed.
Parameters passed by value between 32-bit and 16-bit code also may require translation between
32-bit and 16-bit formats. The form of the translation is application-dependent.
32-bit and 16-bit formats. The form of the translation is application-dependent.
16.4.5
Writing Interface Procedures
Placing interface code between 32-bit and 16-bit procedures can be the solution to the following
interface problems:
interface problems:
•
Allowing procedures in 16-bit code segments to call procedures with offsets greater than
FFFFH in 32-bit code segments.
FFFFH in 32-bit code segments.
•
Matching operand-size attributes between companion CALL and RET instructions.
•
Translating parameters (data), including managing parameter strings with a variable count
or an odd number of 16-bit words.
or an odd number of 16-bit words.
•
The possible invalidation of the upper bits of the ESP register.
The interface procedure is simplified where these rules are followed.
1.
The interface procedure must reside in a 32-bit code segment (the D flag for the code-
segment descriptor is set).
segment descriptor is set).
2.
All procedures that may be called by 16-bit procedures must have offsets not greater than
FFFFH.
FFFFH.
3.
All return addresses saved by 16-bit procedures must have offsets not greater than FFFFH.