### Call Gates
If you are trying to access code from a higher privilege level (i.e. the OS) you can come to the OS from a special entry point called a call gate. The call gate will specify the code you want to access as well as the privilege level that you can come from (given as the call gate DPL).
In the case that the code segment is conforming we can continue running at the same privilege level we came from and no stack switch occurs. If it is nonconforming we have to switch the stack.
![[attachments/Screenshot 2023-05-26 at 3.45.00 PM.png]]
### SYSENTER and SYSEXIT (SYSCALL & SYSRET)
There are now instructions for system calls, SYSENTER for transferring from level 3 to level 0, and SYSEXIT for transferring from level 0 to level 3.
Registers that are used to create the necessary execution context (Intel Manual):
For SYSENTER, target fields are generated using the following sources:
- **Target code segment:** Reads this from IA32_SYSENTER_CS
- **Target instruction:** Reads this from IA32_SYSENTER_EIP
- **Stack segment:** Computed by adding 8 to the value in IA32_SYSENTER_CS
- **Stack pointer:** Reads this from the IA32_SYSENTER_ESP
For SYSEXIT, target fields are generated using the following sources:
- **Target code segment:** Computed by adding 16 to the value in the TA32_SYSENTER_CS
- **Target instruction:** Reads this from EDX
- **Stack segment:** Computed by adding 24 to the value in IA32_SYSENTER_CS
- **Stack pointer:** Reads this from ECX