<<<    Index    >>>
3-609
INSTRUCTION SET REFERENCE
RET—Return from Procedure (Continued)
The mechanics of an inter-privilege-level far return are similar to an intersegment return, except
that the processor examines the privilege levels and access rights of the code and stack segments
being returned to determine if the control transfer is allowed to be made. The DS, ES, FS, and
GS segment registers are cleared by the RET instruction during an inter-privilege-level return if
they refer to segments that are not allowed to be accessed at the new privilege level. Since a
stack switch also occurs on an inter-privilege level return, the ESP and SS registers are loaded
from the stack. 
If parameters are passed to the called procedure during an inter-privilege level call, the optional
source operand must be used with the RET instruction to release the parameters on the return.
Here, the parameters are released both from the called procedure’s stack and the calling proce-
dure’s stack (that is, the stack being returned to).
Operation
(* Near return *)
IF instruction = near return 
THEN;
IF OperandSize = 32
THEN
IF top 12 bytes of stack not within stack limits THEN #SS(0); FI;
EIP 
<
 Pop();
ELSE (* OperandSize = 16 *)
IF top 6 bytes of stack not within stack limits
THEN #SS(0)
FI;
tempEIP 
<
 Pop();
tempEIP 
<
 tempEIP AND 0000FFFFH;
IF tempEIP not within code segment limits THEN #GP(0); FI;
EIP 
<
 tempEIP;
FI;
IF instruction has immediate operand 
THEN IF StackAddressSize=32
THEN 
ESP 
<
 ESP + SRC; (* release parameters from stack *)
ELSE (* StackAddressSize=16 *)
SP 
<
 SP + SRC; (* release parameters from stack *)
FI;
FI;
(* Real-address mode or virtual-8086 mode *)
IF ((PE = 0) OR (PE = 1 AND VM = 1)) AND instruction = far return
THEN;
<<<    Index    >>>