Volume 2B Instruction Set Reference N-Z (794102), страница 37
Текст из файла (страница 37)
Here, the parameters are released both from the calledprocedure’s stack and the calling procedure’s stack (that is, the stack being returnedto).In 64-bit mode, the default operation size of this instruction is the stack size, i.e. 64bits.Operation(* Near return *)IF instruction = Near returnTHEN;IF OperandSize = 32THENIF top 4 bytes of stack not within stack limitsTHEN #SS(0); FI;EIP ← Pop();ELSEIF OperandSize = 64THENIF top 8 bytes of stack not within stack limitsTHEN #SS(0); FI;RIP ← Pop();ELSE (* OperandSize = 16 *)IF top 2 bytes of stack not within stack limitsTHEN #SS(0); FI;tempEIP ← Pop();tempEIP ← tempEIP AND 0000FFFFH;IF tempEIP not within code segment limitsTHEN #GP(0); FI;EIP ← tempEIP;FI;FI;RET—Return from ProcedureVol. 2B 4-259INSTRUCTION SET REFERENCE, N-ZIF instruction has immediate operandTHEN IF StackAddressSize = 32THENESP ← ESP + SRC; (* Release parameters from stack *)ELSEIF StackAddressSize = 64THENRSP ← RSP + SRC; (* Release parameters from stack *)ELSE (* StackAddressSize = 16 *)SP ← SP + SRC; (* Release parameters from stack *)FI;FI;FI;FI;(* Real-address mode or virtual-8086 mode *)IF ((PE = 0) or (PE = 1 AND VM = 1)) and instruction = far returnTHENIF OperandSize = 32THENIF top 12 bytes of stack not within stack limitsTHEN #SS(0); FI;EIP ← Pop();CS ← Pop(); (* 32-bit pop, high-order 16 bits discarded *)ELSE (* OperandSize = 16 *)IF top 6 bytes of stack not within stack limitsTHEN #SS(0); FI;tempEIP ← Pop();tempEIP ← tempEIP AND 0000FFFFH;IF tempEIP not within code segment limitsTHEN #GP(0); FI;EIP ← tempEIP;CS ← Pop(); (* 16-bit pop *)FI;IF instruction has immediate operandTHENSP ← SP + (SRC AND FFFFH); (* Release parameters from stack *)FI;FI;(* Protected mode, not virtual-8086 mode *)IF (PE = 1 and VM = 0 and IA32_EFER.LMA = 0) and instruction = far RETTHEN4-260 Vol.
2BRET—Return from ProcedureINSTRUCTION SET REFERENCE, N-ZIF OperandSize = 32THENIF second doubleword on stack is not within stack limitsTHEN #SS(0); FI;ELSE (* OperandSize = 16 *)IF second word on stack is not within stack limitsTHEN #SS(0); FI;FI;IF return code segment selector is NULLTHEN #GP(0); FI;IF return code segment selector addresses descriptor beyond descriptor table limitTHEN #GP(selector); FI;Obtain descriptor to which return code segment selector points from descriptor table;IF return code segment descriptor is not a code segmentTHEN #GP(selector); FI;IF return code segment selector RPL < CPLTHEN #GP(selector); FI;IF return code segment descriptor is conformingand return code segment DPL > return code segment selector RPLTHEN #GP(selector); FI;IF return code segment descriptor is non-conforming and return codesegment DPL ≠ return code segment selector RPLTHEN #GP(selector); FI;IF return code segment descriptor is not presentTHEN #NP(selector); FI:IF return code segment selector RPL > CPLTHEN GOTO RETURN-OUTER-PRIVILEGE-LEVEL;ELSE GOTO RETURN-TO-SAME-PRIVILEGE-LEVEL;FI;FI;RETURN-SAME-PRIVILEGE-LEVEL:IF the return instruction pointer is not within ther return code segment limitTHEN #GP(0); FI;IF OperandSize = 32THENEIP ← Pop();CS ← Pop(); (* 32-bit pop, high-order 16 bits discarded *)ESP ← ESP + SRC; (* Release parameters from stack *)ELSE (* OperandSize = 16 *)EIP ← Pop();EIP ← EIP AND 0000FFFFH;CS ← Pop(); (* 16-bit pop *)ESP ← ESP + SRC; (* Release parameters from stack *)RET—Return from ProcedureVol.
2B 4-261INSTRUCTION SET REFERENCE, N-ZFI;RETURN-OUTER-PRIVILEGE-LEVEL:IF top (16 + SRC) bytes of stack are not within stack limits (OperandSize = 32)or top (8 + SRC) bytes of stack are not within stack limits (OperandSize = 16)THEN #SS(0); FI;Read return segment selector;IF stack segment selector is NULLTHEN #GP(0); FI;IF return stack segment selector index is not within its descriptor table limitsTHEN #GP(selector); FI;Read segment descriptor pointed to by return segment selector;IF stack segment selector RPL ≠ RPL of the return code segment selectoror stack segment is not a writable data segmentor stack segment descriptor DPL ≠ RPL of the return code segment selectorTHEN #GP(selector); FI;IF stack segment not presentTHEN #SS(StackSegmentSelector); FI;IF the return instruction pointer is not within the return code segment limitTHEN #GP(0); FI;CPL ← ReturnCodeSegmentSelector(RPL);IF OperandSize = 32THENEIP ← Pop();CS ← Pop(); (* 32-bit pop, high-order 16 bits discarded; segment descriptorinformation also loaded *)CS(RPL) ← CPL;ESP ← ESP + SRC; (* Release parameters from called procedure’s stack *)tempESP ← Pop();tempSS ← Pop(); (* 32-bit pop, high-order 16 bits discarded; segmentdescriptor information also loaded *)ESP ← tempESP;SS ← tempSS;ELSE (* OperandSize = 16 *)EIP ← Pop();EIP ← EIP AND 0000FFFFH;CS ← Pop(); (* 16-bit pop; segment descriptor information also loaded *)CS(RPL) ← CPL;ESP ← ESP + SRC; (* Release parameters from called procedure’s stack *)tempESP ← Pop();tempSS ← Pop(); (* 16-bit pop; segment descriptor information also loaded *)ESP ← tempESP;SS ← tempSS;4-262 Vol.
2BRET—Return from ProcedureINSTRUCTION SET REFERENCE, N-ZFI;FOR each of segment register (ES, FS, GS, and DS)DOIF segment register points to data or non-conforming code segmentand CPL > segment descriptor DPL (* DPL in hidden part of segment register *)THEN SegmentSelector ← 0; (* Segment selector invalid *)FI;OD;For each of ES, FS, GS, and DSDOIF segment selector index is not within descriptor table limitsor segment descriptor indicates the segment is not a data orreadable code segmentor if the segment is a data or non-conforming code segmentand the segment descriptor’s DPL < CPL or RPL of code segment’ssegment selectorTHEN SegmentSelector ← 0; (* Segment selector invalid *)OD;ESP ← ESP + SRC; (* Release parameters from calling procedure’s stack *)(* IA-32e Mode *)IF (PE = 1 and VM = 0 and IA32_EFER.LMA = 1) and instruction = far RETTHENIF OperandSize = 32THENIF second doubleword on stack is not within stack limitsTHEN #SS(0); FI;IF first or second doubleword on stack is not in canonical spaceTHEN #SS(0); FI;ELSEIF OperandSize = 16THENIF second word on stack is not within stack limitsTHEN #SS(0); FI;IF first or second word on stack is not in canonical spaceTHEN #SS(0); FI;ELSE (* OperandSize = 64 *)IF first or second quadword on stack is not in canonical spaceTHEN #SS(0); FI;FIFI;IF return code segment selector is NULLRET—Return from ProcedureVol.
2B 4-263INSTRUCTION SET REFERENCE, N-ZTHEN GP(0); FI;IF return code segment selector addresses descriptor beyond descriptor table limitTHEN GP(selector); FI;IF return code segment selector addresses descriptor in non-canonical spaceTHEN GP(selector); FI;Obtain descriptor to which return code segment selector points from descriptor table;IF return code segment descriptor is not a code segmentTHEN #GP(selector); FI;IF return code segment descriptor has L-bit = 1 and D-bit = 1THEN #GP(selector); FI;IF return code segment selector RPL < CPLTHEN #GP(selector); FI;IF return code segment descriptor is conformingand return code segment DPL > return code segment selector RPLTHEN #GP(selector); FI;IF return code segment descriptor is non-conformingand return code segment DPL ≠ return code segment selector RPLTHEN #GP(selector); FI;IF return code segment descriptor is not presentTHEN #NP(selector); FI:IF return code segment selector RPL > CPLTHEN GOTO IA-32E-MODE-RETURN-OUTER-PRIVILEGE-LEVEL;ELSE GOTO IA-32E-MODE-RETURN-SAME-PRIVILEGE-LEVEL;FI;FI;IA-32E-MODE-RETURN-SAME-PRIVILEGE-LEVEL:IF the return instruction pointer is not within the return code segment limitTHEN #GP(0); FI;IF the return instruction pointer is not within canonical address spaceTHEN #GP(0); FI;IF OperandSize = 32THENEIP ← Pop();CS ← Pop(); (* 32-bit pop, high-order 16 bits discarded *)ESP ← ESP + SRC; (* Release parameters from stack *)ELSEIF OperandSize = 16THENEIP ← Pop();EIP ← EIP AND 0000FFFFH;CS ← Pop(); (* 16-bit pop *)ESP ← ESP + SRC; (* Release parameters from stack *)4-264 Vol.
2BRET—Return from ProcedureINSTRUCTION SET REFERENCE, N-ZELSE (* OperandSize = 64 *)RIP ← Pop();CS ← Pop(); (* 64-bit pop, high-order 48 bits discarded *)ESP ← ESP + SRC; (* Release parameters from stack *)FI;FI;IA-32E-MODE-RETURN-OUTER-PRIVILEGE-LEVEL:IF top (16 + SRC) bytes of stack are not within stack limits (OperandSize = 32)or top (8 + SRC) bytes of stack are not within stack limits (OperandSize = 16)THEN #SS(0); FI;IF top (16 + SRC) bytes of stack are not in canonical address space (OperandSize = 32)or top (8 + SRC) bytes of stack are not in canonical address space (OperandSize = 16)or top (32 + SRC) bytes of stack are not in canonical address space (OperandSize = 64)THEN #SS(0); FI;Read return stack segment selector;IF stack segment selector is NULLTHENIF new CS descriptor L-bit = 0THEN #GP(selector);IF stack segment selector RPL = 3THEN #GP(selector);FI;IF return stack segment descriptor is not within descriptor table limitsTHEN #GP(selector); FI;IF return stack segment descriptor is in non-canonical address spaceTHEN #GP(selector); FI;Read segment descriptor pointed to by return segment selector;IF stack segment selector RPL ≠ RPL of the return code segment selectoror stack segment is not a writable data segmentor stack segment descriptor DPL ≠ RPL of the return code segment selectorTHEN #GP(selector); FI;IF stack segment not presentTHEN #SS(StackSegmentSelector); FI;IF the return instruction pointer is not within the return code segment limitTHEN #GP(0); FI:IF the return instruction pointer is not within canonical address spaceTHEN #GP(0); FI;CPL ← ReturnCodeSegmentSelector(RPL);IF OperandSize = 32THENEIP ← Pop();CS ← Pop(); (* 32-bit pop, high-order 16 bits discarded, segment descriptorRET—Return from ProcedureVol.