-/** @file\r
- Implementation of SetJump() on IA-32.\r
-\r
- Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
- SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-\r
-\r
-#include "BaseLibInternals.h"\r
-\r
-/**\r
- Worker function that checks ASSERT condition for JumpBuffer\r
-\r
- Checks ASSERT condition for JumpBuffer.\r
-\r
- If JumpBuffer is NULL, then ASSERT().\r
- For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r
-\r
- @param JumpBuffer A pointer to CPU context buffer.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-InternalAssertJumpBuffer (\r
- IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r
- );\r
-\r
-/**\r
- Saves the current CPU context that can be restored with a call to LongJump()\r
- and returns 0.\r
-\r
- Saves the current CPU context in the buffer specified by JumpBuffer and\r
- returns 0. The initial call to SetJump() must always return 0. Subsequent\r
- calls to LongJump() cause a non-zero value to be returned by SetJump().\r
-\r
- If JumpBuffer is NULL, then ASSERT().\r
- For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r
-\r
- @param JumpBuffer A pointer to CPU context buffer.\r
-\r
- @retval 0 Indicates a return from SetJump().\r
-\r
-**/\r
-_declspec (naked)\r
-RETURNS_TWICE\r
-UINTN\r
-EFIAPI\r
-SetJump (\r
- OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r
- )\r
-{\r
- _asm {\r
- push [esp + 4]\r
- call InternalAssertJumpBuffer\r
- pop ecx\r
- pop ecx\r
- mov edx, [esp]\r
-\r
- xor eax, eax\r
- mov [edx + 24], eax ; save 0 to SSP\r
-\r
- mov eax, [PcdGet32 (PcdControlFlowEnforcementPropertyMask)]\r
- test eax, eax\r
- jz CetDone\r
- _emit 0x0F\r
- _emit 0x20\r
- _emit 0xE0 ; mov eax, cr4\r
- bt eax, 23 ; check if CET is enabled\r
- jnc CetDone\r
-\r
- mov eax, 1\r
- _emit 0xF3\r
- _emit 0x0F\r
- _emit 0xAE\r
- _emit 0xE8 ; INCSSP EAX to read original SSP\r
- _emit 0xF3\r
- _emit 0x0F\r
- _emit 0x1E\r
- _emit 0xC8 ; READSSP EAX\r
- mov [edx + 0x24], eax ; save SSP\r
-\r
-CetDone:\r
-\r
- mov [edx], ebx\r
- mov [edx + 4], esi\r
- mov [edx + 8], edi\r
- mov [edx + 12], ebp\r
- mov [edx + 16], esp\r
- mov [edx + 20], ecx\r
- xor eax, eax\r
- jmp ecx\r
- }\r
-}\r
-\r