a3d5c47ffaf28cae64150696f9f787574351254f
[mirror_edk2.git] / IntelFspPkg / FspSecCore / Ia32 / SaveRestoreSse.inc
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2014, 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 ; Provide macro for register save/restore using SSE registers
15 ;
16 ;------------------------------------------------------------------------------
17
18 ;
19 ; Define SSE instruction set
20 ;
21 IFDEF USE_SSE41_FLAG
22 ;
23 ; Define SSE macros using SSE 4.1 instructions
24 ;
25 SXMMN MACRO XMM, IDX, REG
26 pinsrd XMM, REG, (IDX AND 3)
27 ENDM
28
29 LXMMN MACRO XMM, REG, IDX
30 pextrd REG, XMM, (IDX AND 3)
31 ENDM
32 ELSE
33 ;
34 ; Define SSE macros using SSE 2 instructions
35 ;
36 SXMMN MACRO XMM, IDX, REG
37 pinsrw XMM, REG, (IDX AND 3) * 2
38 ror REG, 16
39 pinsrw XMM, REG, (IDX AND 3) * 2 + 1
40 rol REG, 16
41 ENDM
42
43 LXMMN MACRO XMM, REG, IDX
44 pshufd XMM, XMM, (0E4E4E4h SHR (IDX * 2)) AND 0FFh
45 movd REG, XMM
46 pshufd XMM, XMM, (0E4E4E4h SHR (IDX * 2 + (IDX AND 1) * 4)) AND 0FFh
47 ENDM
48 ENDIF
49
50
51 SAVE_REGS MACRO
52 SXMMN xmm7, 0, ebp
53 SXMMN xmm7, 1, ebx
54 SXMMN xmm7, 2, esi
55 SXMMN xmm7, 3, edi
56 SAVE_ESP
57 ENDM
58
59 LOAD_REGS MACRO
60 LXMMN xmm7, ebp, 0
61 LXMMN xmm7, ebx, 1
62 LXMMN xmm7, esi, 2
63 LXMMN xmm7, edi, 3
64 LOAD_ESP
65 ENDM
66
67 LOAD_EAX MACRO
68 LXMMN xmm6, eax, 1
69 ENDM
70
71 SAVE_EAX MACRO
72 SXMMN xmm6, 1, eax
73 ENDM
74
75 LOAD_EDX MACRO
76 LXMMN xmm6, edx, 2
77 ENDM
78
79 SAVE_EDX MACRO
80 SXMMN xmm6, 2, edx
81 ENDM
82
83 SAVE_ECX MACRO
84 SXMMN xmm6, 3, ecx
85 ENDM
86
87 LOAD_ECX MACRO
88 LXMMN xmm6, ecx, 3
89 ENDM
90
91 SAVE_ESP MACRO
92 SXMMN xmm6, 0, esp
93 ENDM
94
95 LOAD_ESP MACRO
96 movd esp, xmm6
97 ENDM
98
99 ENABLE_SSE MACRO
100 mov eax, cr4
101 or eax, 00000600h
102 mov cr4, eax
103 ENDM