Skip to content

SYSEXIT

Henk-Jan Lebbink edited this page Jun 5, 2018 · 14 revisions

SYSEXIT — Fast Return from Fast System Call

Opcode Instruction Op/ En 64-Bit Mode Compat/ Leg Mode Description
0F 35 SYSEXIT ZO Valid Valid Fast return to privilege level 3 user code.
REX.W + 0F 35 SYSEXIT ZO Valid Valid Fast return to 64-bit mode privilege level 3 user code.

Instruction Operand Encoding

Op/En Operand 1 Operand 2 Operand 3 Operand 4
ZO NA NA NA NA

Description

Executes a fast return to privilege level 3 user code. SYSEXIT is a companion instruction to the SYSENTER instruction . The instruction is optimized to provide the maximum performance for returns from system procedures executing at protections levels 0 to user procedures executing at protection level 3. It must be executed from code executing at privilege level 0.

With a 64-bit operand size, SYSEXIT remains in 64-bit mode; otherwise, it either enters compatibility mode (if the logical processor is in IA-32e mode) or remains in protected mode (if it is not).

Prior to executing SYSEXIT, software must specify the privilege level 3 code segment and code entry point, and the privilege level 3 stack segment and stack pointer by writing values into the following MSR and general-purpose registers:

  • IA32_SYSENTER_CS (MSR address 174H) — Contains a 32-bit value that is used to determine the segment selectors for the privilege level 3 code and stack segments (see the Operation section)

  • RDX — The canonical address in this register is loaded into RIP (thus, this value references the first instruction

to be executed in the user code). If the return is not to 64-bit mode, only bits 31:0 are loaded.

  • ECX — The canonical address in this register is loaded into RSP (thus, this value contains the stack pointer for

the privilege level 3 stack). If the return is not to 64-bit mode, only bits 31:0 are loaded.

The IA32_SYSENTER_CS MSR can be read from and written to using RDMSR and WRMSR.

While SYSEXIT loads the CS and SS selectors with values derived from the IA32_SYSENTER_CS MSR, the CS and SS descriptor caches are not loaded from the descriptors (in GDT or LDT) referenced by those selectors. Instead, the descriptor caches are loaded with fixed values. See the Operation section for details. It is the responsibility of OS software to ensure that the descriptors (in GDT or LDT) referenced by those selector values correspond to the fixed values loaded into the descriptor caches; the SYSEXIT instruction does not ensure this correspondence.

The SYSEXIT instruction can be invoked from all operating modes except real-address mode and virtual-8086 mode.

The SYSENTER and SYSEXIT instructions were introduced into the IA-32 architecture in the Pentium II processor. The availability of these instructions on a processor is indicated with the SYSENTER/SYSEXIT present (SEP) feature flag returned to the EDX register by the CPUID instruction. An operating system that qualifies the SEP flag must also qualify the processor family and model to ensure that the SYSENTER/SYSEXIT instructions are actually present. For example:

IF CPUID SEP bit is set THEN IF (Family = 6) and (Model < 3) and (Stepping < 3)

THEN SYSENTER/SYSEXIT_Not_Supported; FI; ELSE SYSENTER/SYSEXIT_Supported; FI; FI; When the CPUID instruction is executed on the Pentium Pro processor (model 1), the processor returns a the SEP flag as set, but does not support the SYSENTER/SYSEXIT instructions.

Operation

IF IA32_SYSENTER_CS[15:2] = 0 OR CR0.PE = 0 OR CPL0 THEN #GP(0); FI;
IF operand size is 64-bit
    THEN
            (* Return to 64-bit mode *)
        RSPRCX;
        RIPRDX;
    ELSE
            (* Return to protected mode or compatibility mode *)
        RSPECX;
        RIPEDX;
FI;
IF operand size is 64-bit
                            (* Operating system provides CS; RPL forced to 3 *)
    THEN CS.SelectorIA32_SYSENTER_CS[15:0] + 32;
    ELSE CS.SelectorIA32_SYSENTER_CS[15:0] + 16;
FI;
CS.SelectorCS.Selector OR 3;
                            (* RPL forced to 3 *)
(* Set rest of CS to a fixed value *)
CS.Base0;
                            (* Flat segment *)
CS.LimitFFFFFH;
                            (* With 4-KByte granularity, implies a 4-GByte limit *)
CS.Type11;
                            (* Execute/read code, accessed *)
CS.S1;
CS.DPL3;
CS.P1;
IF operand size is 64-bit
    THEN
            (* return to 64-bit mode *)
        CS.L1;
                            (* 64-bit code segment *)
        CS.D0;
                            (* Required if CS.L = 1 *)
    ELSE
            (* return to protected mode or compatibility mode *)
        CS.L0;
        CS.D1;
                            (* 32-bit code segment*)
FI;
CS.G1;
                            (* 4-KByte granularity *)
CPL3;
SS.SelectorCS.Selector + 8;
                            (* SS just above CS *)
(* Set rest of SS to a fixed value *)
SS.Base0;
                            (* Flat segment *)
SS.LimitFFFFFH;
                            (* With 4-KByte granularity, implies a 4-GByte limit *)
SS.Type3;
                            (* Read/write data, accessed *)
SS.S1;
SS.DPL3;
SS.P1;
SS.B1;
                            (* 32-bit stack segment*)
SS.G1;
                            (* 4-KByte granularity *)

Flags Affected

None.

Protected Mode Exceptions

#GP(0) If IA32_SYSENTER_CS[15:2] = 0. If CPL ≠ 0.

#UD If the LOCK prefix is used.

Real-Address Mode Exceptions

#GP The SYSEXIT instruction is not recognized in real-address mode.

#UD If the LOCK prefix is used.

Virtual-8086 Mode Exceptions

#GP(0) The SYSEXIT instruction is not recognized in virtual-8086 mode.

Compatibility Mode Exceptions

Same exceptions as in protected mode.

64-Bit Mode Exceptions

#GP(0) If IA32_SYSENTER_CS = 0. If CPL ≠ 0.

If RCX or RDX contains a non-canonical address.

#UD If the LOCK prefix is used.


Source: Intel® Architecture Software Developer's Manual (May 2018)
Generated: 5-6-2018

Clone this wiki locally