Intel 80386 DJ Equipment User Manual


 
80386
Table 4-3. Descriptor Types Used for Control Transfer
Control Transfer Types
Intersegment within the same privilege level
Intersegment to the same or higher privilege level
Interrupt within task may change CPL
Intersegment to a lower privilege level
(changes task
CPL)
Task Switch
'NT
(Nested Task bit
of
flag register)
~
0
"NT
(Nested Task bit of flag register)
~
1
or a jump to another routine. There are five types of
control transfers which are summarized
in
Table 4-3.
Many of these transfers result
in
a privilege level
transfer. Changing privilege levels
is
done only via
control transfers,
by
using gates, task switches, and
interrupt or trap gates.
Control transfers can only occur if the operation
which loaded the selector references the correct
de-
scriptor type. Any violation of these descriptor usage
rules will cause
an
exception
13
(e.g. JMP through a
call gate, or
IRET from a normal subroutine call).
In
order to provide further system security, all control
transfers are also subject to the privilege rules.
The privilege rules require that:
- Privilege level transitions can only occur via
gates.
-
JMPs can
be
made
to
a non-conforming code
segment with the same privilege or to a
conform-
ing code segment with greater or equal privilege.
- CALLs can be made to a non-conforming code
segment with the same privilege or via a gate to a
more privileged level.
-
Interrupts handled within the task obey the same
privilege rules as CALLs.
- Conforming Code segments are accessible by
privilege levels which are the same or less
privi-
leged than the conforming-code segment's
OPL.
- Both the requested privilege level
(RPL)
in
the
selector
pOinting
to the gate and the task's
CPL
Operation Types
Descriptor Descriptor
Referenced Table
JMP, CALL,
RET,
IRET',
Code Segment
GOT/LOT
CALL Call Gate
GOT/LOT
Interrupt Instruction,
Trap or lOT
Exception, External
Interrupt
Interrupt
Gate
RET,IRET' Code Segment
GOT/LOT
CALL,
JMP
Task State
GOT
Segment
CALL, JMP Task Gate GOT/LOT
IRET" Task Gate lOT
Interrupt Instruction,
Exception, External
Interrupt
47
must be of equal or greater privilege than the
gate's
OPL.
- The code segment selected
in
the gate must
be
the same or more privileged than the task's
CPL.
- Return instructions that do not switch tasks can
only return control to a code segment with same
or less privilege.
- Task switches can
be
performed
by
a CALL,
JMP,
or INT which references either a task gate
or task state segment who's
OPL
is
less privi-
leged or the same privilege
as
the old task's
CPL.
Any control transfer that changes
CPL
within a task
causes a change of stacks as a result of the
privi-
lege level change. The initial values of SS:ESP for
privilege levels
0,
1,
and 2 are retained
in
the task
state segment (see section 4.4.6
Task Switching).
During a JMP or CALL control transfer, the new
stack pointer is loaded into the
SS
and
ESP
regis-
ters and the previous stack pointer
is
pushed onto
the new stack.
When RETurning to the original privilege level, use
of the lower-privileged stack
is
restored as part of
the
RET
or IRET instruction operation. For subrou-
tine calls that pass parameters
on
the stack and
cross privilege levels, a fixed number of words (as
specified
in
the gate's word count field) are copied
from the previous stack to the current stack. The
inter-segment RET instruction with a stack
adjust-
ment value will correctly restore the previous stack
pointer upon return.