Volume 2A Instruction Set Reference A-M (794101), страница 34
Текст из файла (страница 34)
However, using this mechanismrequires that the target code segment descriptor have the L bit set.When executing an inter-privilege-level far call, the code segment for the procedurebeing called must be accessed through a 64-bit call gate. The segment selector specified by the target operand identifies the call gate.
The target operand can onlyspecify the call gate segment selector indirectly with a memory location (m16:16,m16:32 or m16:64). The processor obtains the segment selector for the new codesegment and the new instruction pointer (offset) from the 16-byte call gatedescriptor. (The offset from the target operand is ignored when a call gate is used.)On inter-privilege-level calls, the processor switches to the stack for the privilegelevel of the called procedure.
The segment selector for the new stack segment is setto NULL. The new stack pointer is specified in the TSS for the currently running task.The branch to the new code segment occurs after the stack switch.Note that when using a call gate to perform a far call to a segment at the same privilege level, an implicit stack switch occurs as a result of entering 64-bit mode. The SSselector is unchanged, but stack segment accesses use a segment base of 0x0, thelimit is ignored, and the default stack size is 64-bits. (The full value of RSP is used forthe offset.) On the new stack, the processor pushes the segment selector and stackpointer for the calling procedure’s stack and the segment selector and instructionpointer for the calling procedure’s code segment.
(Parameter copy is not supported inIA-32e mode.) Finally, the processor branches to the address of the procedure beingcalled within the new code segment.OperationIF near callTHEN IF near relative callTHENIF OperandSize = 64THENtempDEST ← SignExtend(DEST); (* DEST is rel32 *)tempRIP ← RIP + tempDEST;IF stack not large enough for a 8-byte return addressTHEN #SS(0); FI;Push(RIP);RIP ← tempRIP;FI;IF OperandSize = 323-126 Vol. 2ACALL—Call ProcedureINSTRUCTION SET REFERENCE, A-MTHENtempEIP ← EIP + DEST; (* DEST is rel32 *)IF tempEIP is not within code segment limit THEN #GP(0); FI;IF stack not large enough for a 4-byte return addressTHEN #SS(0); FI;Push(EIP);EIP ← tempEIP;FI;IF OperandSize = 16THENtempEIP ← (EIP + DEST) AND 0000FFFFH; (* DEST is rel16 *)IF tempEIP is not within code segment limit THEN #GP(0); FI;IF stack not large enough for a 2-byte return addressTHEN #SS(0); FI;Push(IP);EIP ← tempEIP;FI;ELSE (* Near absolute call *)IF OperandSize = 64THENtempRIP ← DEST; (* DEST is r/m64 *)IF stack not large enough for a 8-byte return addressTHEN #SS(0); FI;Push(RIP);RIP ← tempRIP;FI;IF OperandSize = 32THENtempEIP ← DEST; (* DEST is r/m32 *)IF tempEIP is not within code segment limit THEN #GP(0); FI;IF stack not large enough for a 4-byte return addressTHEN #SS(0); FI;Push(EIP);EIP ← tempEIP;FI;IF OperandSize = 16THENtempEIP ← DEST AND 0000FFFFH; (* DEST is r/m16 *)IF tempEIP is not within code segment limit THEN #GP(0); FI;IF stack not large enough for a 2-byte return addressTHEN #SS(0); FI;Push(IP);EIP ← tempEIP;CALL—Call ProcedureVol.
2A 3-127INSTRUCTION SET REFERENCE, A-MFI;FI;rel/absFI; nearIF far call and (PE = 0 or (PE = 1 and VM = 1)) (* Real-address or virtual-8086 mode *)THENIF OperandSize = 32THENIF stack not large enough for a 6-byte return addressTHEN #SS(0); FI;IF DEST[31:16] is not zero THEN #GP(0); FI;Push(CS); (* Padded with 16 high-order bits *)Push(EIP);CS ← DEST[47:32]; (* DEST is ptr16:32 or [m16:32] *)EIP ← DEST[31:0]; (* DEST is ptr16:32 or [m16:32] *)ELSE (* OperandSize = 16 *)IF stack not large enough for a 4-byte return addressTHEN #SS(0); FI;Push(CS);Push(IP);CS ← DEST[31:16]; (* DEST is ptr16:16 or [m16:16] *)EIP ← DEST[15:0]; (* DEST is ptr16:16 or [m16:16]; clear upper 16 bits *)FI;FI;IF far call and (PE = 1 and VM = 0) (* Protected mode or IA-32e Mode, not virtual-8086 mode*)THENIF segment selector in target operand NULLTHEN #GP(0); FI;IF segment selector index not within descriptor table limitsTHEN #GP(new code segment selector); FI;Read type and access rights of selected segment descriptor;IF IA32_EFER.LMA = 0THENIF segment type is not a conforming or nonconforming code segment, callgate, task gate, or TSSTHEN #GP(segment selector); FI;ELSEIF segment type is not a conforming or nonconforming code segment or64-bit call gate,THEN #GP(segment selector); FI;FI;Depending on type and access rights:3-128 Vol.
2ACALL—Call ProcedureINSTRUCTION SET REFERENCE, A-MGO TO CONFORMING-CODE-SEGMENT;GO TO NONCONFORMING-CODE-SEGMENT;GO TO CALL-GATE;GO TO TASK-GATE;GO TO TASK-STATE-SEGMENT;FI;CONFORMING-CODE-SEGMENT:IF L-Bit = 1 and D-BIT = 1 and IA32_EFER.LMA = 1THEN GP(new code segment selector); FI;IF DPL > CPLTHEN #GP(new code segment selector); FI;IF segment not presentTHEN #NP(new code segment selector); FI;IF stack not large enough for return addressTHEN #SS(0); FI;tempEIP ← DEST(Offset);IF OperandSize = 16THENtempEIP ← tempEIP AND 0000FFFFH; FI; (* Clear upper 16 bits *)IF (EFER.LMA = 0 or target mode = Compatibility mode) and (tempEIP outside new codesegment limit)THEN #GP(0); FI;IF tempEIP is non-canonicalTHEN #GP(0); FI;IF OperandSize = 32THENPush(CS); (* Padded with 16 high-order bits *)Push(EIP);CS ← DEST(CodeSegmentSelector);(* Segment descriptor information also loaded *)CS(RPL) ← CPL;EIP ← tempEIP;ELSEIF OperandSize = 16THENPush(CS);Push(IP);CS ← DEST(CodeSegmentSelector);(* Segment descriptor information also loaded *)CS(RPL) ← CPL;EIP ← tempEIP;ELSE (* OperandSize = 64 *)CALL—Call ProcedureVol.
2A 3-129INSTRUCTION SET REFERENCE, A-MPush(CS); (* Padded with 48 high-order bits *)Push(RIP);CS ← DEST(CodeSegmentSelector);(* Segment descriptor information also loaded *)CS(RPL) ← CPL;RIP ← tempEIP;FI;FI;END;NONCONFORMING-CODE-SEGMENT:IF L-Bit = 1 and D-BIT = 1 and IA32_EFER.LMA = 1THEN GP(new code segment selector); FI;IF (RPL > CPL) or (DPL ≠ CPL)THEN #GP(new code segment selector); FI;IF segment not presentTHEN #NP(new code segment selector); FI;IF stack not large enough for return addressTHEN #SS(0); FI;tempEIP ← DEST(Offset);IF OperandSize = 16THEN tempEIP ← tempEIP AND 0000FFFFH; FI; (* Clear upper 16 bits *)IF (EFER.LMA = 0 or target mode = Compatibility mode) and (tempEIP outside new codesegment limit)THEN #GP(0); FI;IF tempEIP is non-canonicalTHEN #GP(0); FI;IF OperandSize = 32THENPush(CS); (* Padded with 16 high-order bits *)Push(EIP);CS ← DEST(CodeSegmentSelector);(* Segment descriptor information also loaded *)CS(RPL) ← CPL;EIP ← tempEIP;ELSEIF OperandSize = 16THENPush(CS);Push(IP);CS ← DEST(CodeSegmentSelector);(* Segment descriptor information also loaded *)CS(RPL) ← CPL;EIP ← tempEIP;3-130 Vol.
2ACALL—Call ProcedureINSTRUCTION SET REFERENCE, A-MELSE (* OperandSize = 64 *)Push(CS); (* Padded with 48 high-order bits *)Push(RIP);CS ← DEST(CodeSegmentSelector);(* Segment descriptor information also loaded *)CS(RPL) ← CPL;RIP ← tempEIP;FI;FI;END;CALL-GATE:IF call gate (DPL < CPL) or (RPL > DPL)THEN #GP(call gate selector); FI;IF call gate not presentTHEN #NP(call gate selector); FI;IF call gate code-segment selector is NULLTHEN #GP(0); FI;IF call gate code-segment selector index is outside descriptor table limitsTHEN #GP(code segment selector); FI;Read code segment descriptor;IF code-segment segment descriptor does not indicate a code segmentor code-segment segment descriptor DPL > CPLTHEN #GP(code segment selector); FI;IF IA32_EFER.LMA = 1 AND (code-segment segment descriptor isnot a 64-bit code segment or code-segment descriptor has both L-Bit and D-bit set)THEN #GP(code segment selector); FI;IF code segment not presentTHEN #NP(new code segment selector); FI;IF code segment is non-conforming and DPL < CPLTHEN go to MORE-PRIVILEGE;ELSE go to SAME-PRIVILEGE;FI;END;MORE-PRIVILEGE:IF current TSS is 32-bit TSSTHENTSSstackAddress ← new code segment (DPL ∗ 8) + 4;IF (TSSstackAddress + 7) > TSS limitTHEN #TS(current TSS selector); FI;newSS ← TSSstackAddress + 4;newESP ← stack address;ELSECALL—Call ProcedureVol.
2A 3-131INSTRUCTION SET REFERENCE, A-MIF current TSS is 16-bit TSSTHENTSSstackAddress ← new code segment (DPL ∗ 4) + 2;IF (TSSstackAddress + 4) > TSS limitTHEN #TS(current TSS selector); FI;newESP ← TSSstackAddress;newSS ← TSSstackAddress + 2;ELSE (* TSS is 64-bit *)TSSstackAddress ← new code segment (DPL ∗ 8) + 4;IF (TSSstackAddress + 8) > TSS limitTHEN #TS(current TSS selector); FI;newESP ← TSSstackAddress;newSS ← CodeSegment (DPL);(* null selector with RPL = new CPL *)FI;FI;IF IA32_EFER.LMA = 0 and stack segment selector = NULLTHEN #TS(stack segment selector); FI;Read code segment descriptor;IF IA32_EFER.LMA = 0 and (stack segment selector's RPL ≠ DPL of code segmentor stack segment DPL ≠ DPL of code segment or stack segment is not awritable data segment)THEN #TS(SS selector); FIIF IA32_EFER.LMA = 0 and stack segment not presentTHEN #SS(SS selector); FI;IF CallGateSize = 32THENIF stack does not have room for parameters plus 16 bytesTHEN #SS(SS selector); FI;IF CallGate(InstructionPointer) not within code segment limitTHEN #GP(0); FI;SS ← newSS;(* Segment descriptor information also loaded *)ESP ← newESP;CS:EIP ← CallGate(CS:InstructionPointer);(* Segment descriptor information also loaded *)Push(oldSS:oldESP); (* From calling procedure *)temp ← parameter count from call gate, masked to 5 bits;Push(parameters from calling procedure’s stack, temp)Push(oldCS:oldEIP); (* Return address to calling procedure *)ELSEIF CallGateSize = 16THENIF stack does not have room for parameters plus 8 bytes3-132 Vol.