Vol. 3 5-19
PROTECTION

5.8.3 Call Gates

Call gates facilitate controlled transfers of program control between different privi-
lege levels. They are typically used only in operating systems or executives that use
the privilege-level protection mechanism. Call gates are also useful for transferring
program control between 16-bit and 32-bit code segments, as described in Section
18.4, “Transferring Control Among Mixed-Size Code Segments.”
Figure 5-8 shows the format of a call-gate descriptor. A call-gate descriptor may
reside in the GDT or in an LDT, but n ot in the interrupt descriptor table (IDT). It
performs six functions:
It specifies the code segment to be accessed.
It defines an entry point for a procedure in the specified code segment.
It specifies the privilege level required for a caller trying to access the procedure.
If a stack switch occurs, it specifies the number of optional parameters to be
copied between stacks.
It defines the size of values to be pushed onto the target stack: 16-bit gates force
16-bit pushes and 32-bit gates force 32-bit pushes.
It specifies whether the call-gate descriptor is valid.
The segment selector field in a call gate specifies the code segment to be accessed.
The offset field specifies the entry point in the code segment. This entry point is
generally to the first instruction of a specific procedure. The DPL field indicates the
privilege level of the call gate, which in turn is the privilege level required to access
the selected procedure through the gate. The P flag indicates whether the call-gate
descriptor is valid. (The presence of the code segment to which the gate points is
indicated by the P flag in the code segment’s descriptor.) The parameter count field
indicates the number of parameters to copy from the calling procedures stack to the
new stack if a stack switch occurs (see Section 5.8.5, “Stack Switching”). The param-
eter count specifies the number of words for 16-bit call gates and doublewords for
32-bit call gates.

Figure 5-8. Call-Gate Descriptor

31 1615 13
14 12 11 87 0
P
Offset in Segment 31:16 D
P
L
Type
04
31 1615 0
Segment Selector Offset in Segment 15:00 0
Param.
0011
P
DPL Gate Valid
Descriptor Privilege Level
Count
456
0 0 0