]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X64/SetJump.nasm
MdePkg/BaseLib: Add Shadow Stack Support for X86.
[mirror_edk2.git] / MdePkg / Library / BaseLib / X64 / SetJump.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 ; SetJump.Asm
15 ;
16 ; Abstract:
17 ;
18 ; Implementation of SetJump() on x64.
19 ;
20 ;------------------------------------------------------------------------------
21
22 %include "Nasm.inc"
23
24 DEFAULT REL
25 SECTION .text
26
27 extern ASM_PFX(InternalAssertJumpBuffer)
28 extern ASM_PFX(PcdGet32 (PcdControlFlowEnforcementPropertyMask))
29
30 ;------------------------------------------------------------------------------
31 ; UINTN
32 ; EFIAPI
33 ; SetJump (
34 ; OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
35 ; );
36 ;------------------------------------------------------------------------------
37 global ASM_PFX(SetJump)
38 ASM_PFX(SetJump):
39 push rcx
40 add rsp, -0x20
41 call ASM_PFX(InternalAssertJumpBuffer)
42 add rsp, 0x20
43 pop rcx
44 pop rdx
45
46 xor rax, rax
47 mov [rcx + 0xF8], rax ; save 0 to SSP
48
49 mov eax, [ASM_PFX(PcdGet32 (PcdControlFlowEnforcementPropertyMask))]
50 test eax, eax
51 jz CetDone
52 mov rax, cr4
53 bt eax, 23 ; check if CET is enabled
54 jnc CetDone
55
56 mov rax, 1
57 INCSSP_RAX ; to read original SSP
58 READSSP_RAX
59 mov [rcx + 0xF8], rax ; save SSP
60
61 CetDone:
62
63 mov [rcx], rbx
64 mov [rcx + 8], rsp
65 mov [rcx + 0x10], rbp
66 mov [rcx + 0x18], rdi
67 mov [rcx + 0x20], rsi
68 mov [rcx + 0x28], r12
69 mov [rcx + 0x30], r13
70 mov [rcx + 0x38], r14
71 mov [rcx + 0x40], r15
72 mov [rcx + 0x48], rdx
73 ; save non-volatile fp registers
74 stmxcsr [rcx + 0x50]
75 movdqu [rcx + 0x58], xmm6
76 movdqu [rcx + 0x68], xmm7
77 movdqu [rcx + 0x78], xmm8
78 movdqu [rcx + 0x88], xmm9
79 movdqu [rcx + 0x98], xmm10
80 movdqu [rcx + 0xA8], xmm11
81 movdqu [rcx + 0xB8], xmm12
82 movdqu [rcx + 0xC8], xmm13
83 movdqu [rcx + 0xD8], xmm14
84 movdqu [rcx + 0xE8], xmm15
85 xor rax, rax
86 jmp rdx
87