]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/LongJump.nasm
MdePkg/BaseLib: Add Shadow Stack Support for X86.
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / LongJump.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
4 ; This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php.
8 ;
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 ;
12 ; Module Name:
13 ;
14 ; LongJump.Asm
15 ;
16 ; Abstract:
17 ;
18 ; Implementation of _LongJump() on IA-32.
19 ;
20 ;------------------------------------------------------------------------------
21
22 %include "Nasm.inc"
23
24 SECTION .text
25
26 extern ASM_PFX(PcdGet32 (PcdControlFlowEnforcementPropertyMask))
27
28 ;------------------------------------------------------------------------------
29 ; VOID
30 ; EFIAPI
31 ; InternalLongJump (
32 ; IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
33 ; IN UINTN Value
34 ; );
35 ;------------------------------------------------------------------------------
36 global ASM_PFX(InternalLongJump)
37 ASM_PFX(InternalLongJump):
38
39 mov eax, [ASM_PFX(PcdGet32 (PcdControlFlowEnforcementPropertyMask))]
40 test eax, eax
41 jz CetDone
42 mov eax, cr4
43 bt eax, 23 ; check if CET is enabled
44 jnc CetDone
45
46 mov edx, [esp + 4] ; edx = JumpBuffer
47 mov edx, [edx + 24] ; edx = target SSP
48 READSSP_EAX
49 sub edx, eax ; edx = delta
50 mov eax, edx ; eax = delta
51
52 shr eax, 2 ; eax = delta/sizeof(UINT32)
53 INCSSP_EAX
54
55 CetDone:
56
57 pop eax ; skip return address
58 pop edx ; edx <- JumpBuffer
59 pop eax ; eax <- Value
60 mov ebx, [edx]
61 mov esi, [edx + 4]
62 mov edi, [edx + 8]
63 mov ebp, [edx + 12]
64 mov esp, [edx + 16]
65 jmp dword [edx + 20] ; restore "eip"
66