SYSENTER executes a fast call to a level 0 system procedure or
routine. Before using this instruction, various MSRs need to be set
up:
-
SYSENTER_CS_MSRcontains the 32-bit segment selector for the privilege level 0 code segment. (This value is also used to compute the segment selector of the privilege level 0 stack segment.) -
SYSENTER_EIP_MSRcontains the 32-bit offset into the privilege level 0 code segment to the first instruction of the selected operating procedure or routine. -
SYSENTER_ESP_MSRcontains the 32-bit stack pointer for the privilege level 0 stack.
SYSENTER performs the following sequence of operations:
-
Loads the segment selector from the
SYSENTER_CS_MSRinto theCSregister. -
Loads the instruction pointer from the
SYSENTER_EIP_MSRinto theEIPregister. -
Adds 8 to the value in
SYSENTER_CS_MSRand loads it into theSSregister. -
Loads the stack pointer from the
SYSENTER_ESP_MSRinto theESPregister. -
Switches to privilege level 0.
-
Clears the
VMflag in theEFLAGSregister, if the flag is set. -
Begins executing the selected system procedure.
In particular, note that this instruction des not save the values of
CS or (E)IP. If you need to return to the calling code, you
need to write your code to cater for this.
For more information, see the Intel Architecture Software Developer's Manual, Volume 2.