]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Ia32/LongJump.nasm
MdePkg: Replace Opcode with the corresponding instructions.
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / LongJump.nasm
index 7ef03462eed35401a5341e93b34678db4b59528c..6c13dfe307d7d6e36ef8aca7b5c673f44c0ad34b 100644 (file)
@@ -1,13 +1,7 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
-; This program and the accompanying materials\r
-; are licensed and made available under the terms and conditions of the BSD License\r
-; which accompanies this distribution.  The full text of the license may be found at\r
-; http://opensource.org/licenses/bsd-license.php.\r
-;\r
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+; Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
 ;\r
 ; Module Name:\r
 ;\r
 ;\r
 ;------------------------------------------------------------------------------\r
 \r
+%include "Nasm.inc"\r
+\r
     SECTION .text\r
 \r
+extern ASM_PFX(PcdGet32 (PcdControlFlowEnforcementPropertyMask))\r
+\r
 ;------------------------------------------------------------------------------\r
 ; VOID\r
 ; EFIAPI\r
 ;------------------------------------------------------------------------------\r
 global ASM_PFX(InternalLongJump)\r
 ASM_PFX(InternalLongJump):\r
+\r
+    mov     eax, [ASM_PFX(PcdGet32 (PcdControlFlowEnforcementPropertyMask))]\r
+    test    eax, eax\r
+    jz      CetDone\r
+    mov     eax, cr4\r
+    bt      eax, 23                ; check if CET is enabled\r
+    jnc     CetDone\r
+\r
+    mov     edx, [esp + 4]         ; edx = JumpBuffer\r
+    mov     edx, [edx + 24]        ; edx = target SSP\r
+    rdsspd  eax\r
+    sub     edx, eax               ; edx = delta\r
+    mov     eax, edx               ; eax = delta\r
+\r
+    shr     eax, 2                 ; eax = delta/sizeof(UINT32)\r
+    incsspd eax\r
+\r
+CetDone:\r
+\r
     pop     eax                         ; skip return address\r
     pop     edx                         ; edx <- JumpBuffer\r
     pop     eax                         ; eax <- Value\r