]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Include/StuffRsbNasm.inc
276baea9064fbb2f0b0a3fbaa98895a143891c59
[mirror_edk2.git] / UefiCpuPkg / Include / StuffRsbNasm.inc
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2018, 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 ; Abstract:
13 ;
14 ; This file provides macro definitions for stuffing the Return Stack Buffer (RSB)
15 ; for NASM files.
16 ;
17 ;------------------------------------------------------------------------------
18
19 %define RSB_STUFF_ENTRIES 0x20
20
21 ;
22 ; parameters:
23 ; @param 1: register to use as counter (e.g. IA32:eax, X64:rax)
24 ; @param 2: stack pointer to restore (IA32:esp, X64:rsp)
25 ; @param 3: the size of a stack frame (IA32:4, X64:8)
26 ;
27 %macro StuffRsb 3
28 mov %1, RSB_STUFF_ENTRIES / 2
29 %%Unroll1:
30 call %%Unroll2
31 %%SpecTrap1:
32 pause
33 lfence
34 jmp %%SpecTrap1
35 %%Unroll2:
36 call %%StuffLoop
37 %%SpecTrap2:
38 pause
39 lfence
40 jmp %%SpecTrap2
41 %%StuffLoop:
42 dec %1
43 jnz %%Unroll1
44 add %2, RSB_STUFF_ENTRIES * %3 ; Restore the stack pointer
45 %endmacro
46
47 ;
48 ; RSB stuffing macros for IA32 and X64
49 ;
50 %macro StuffRsb32 0
51 StuffRsb eax, esp, 4
52 %endmacro
53
54 %macro StuffRsb64 0
55 StuffRsb rax, rsp, 8
56 %endmacro