]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Library/CpuIA32Lib/X64/Cpu.asm
ArmPkg/CompilerIntrinsicsLib: Add uread, uwrite GCC assembly sources
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / CpuIA32Lib / X64 / Cpu.asm
CommitLineData
3cbfba02
DW
1\r
2TITLE Cpu.asm: Assembly code for the x64 resources\r
3\r
4;\r
5; This file contains an 'Intel Sample Driver' and is\r
6; licensed for Intel CPUs and chipsets under the terms of your\r
7; license agreement with Intel or your vendor. This file may\r
8; be modified by the user, subject to additional terms of the\r
9; license agreement\r
10;\r
11;\r
12; Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved\r
13; \r\r
9dc8036d
MK
14; SPDX-License-Identifier: BSD-2-Clause-Patent\r
15\r
3cbfba02
DW
16; \r\r
17;\r
18;\r
19;\r
20;\r
21;* Module Name:\r
22;*\r
23;* Cpu.asm\r
24;*\r
25;* Abstract:\r
26;*\r
27;------------------------------------------------------------------------------\r
28\r
29text SEGMENT\r
30\r
31\r
32;------------------------------------------------------------------------------\r
33; VOID\r
34; EfiHalt (\r
35; VOID\r
36; )\r
37;------------------------------------------------------------------------------\r
38EfiHalt PROC PUBLIC\r
39 hlt\r
40 ret\r
41EfiHalt ENDP\r
42\r
43\r
44;------------------------------------------------------------------------------\r
45; VOID\r
46; EfiWbinvd (\r
47; VOID\r
48; )\r
49;------------------------------------------------------------------------------\r
50EfiWbinvd PROC PUBLIC\r
51 wbinvd\r
52 ret\r
53EfiWbinvd ENDP\r
54\r
55\r
56;------------------------------------------------------------------------------\r
57; VOID\r
58; EfiInvd (\r
59; VOID\r
60; )\r
61;------------------------------------------------------------------------------\r
62EfiInvd PROC PUBLIC\r
63 invd\r
64 ret\r
65EfiInvd ENDP\r
66\r
67;------------------------------------------------------------------------------\r
68; VOID\r
69; EfiCpuid (\r
70; IN UINT32 RegisterInEax, // rcx\r
71; OUT EFI_CPUID_REGISTER *Reg OPTIONAL // rdx\r
72; )\r
73;------------------------------------------------------------------------------\r
74EfiCpuid PROC PUBLIC\r
75 push rbx\r
76\r
77 mov r8, rdx ; r8 = *Reg\r
78 mov rax, rcx ; RegisterInEax\r
79 cpuid\r
80 cmp r8, 0\r
81 je _Exit\r
82 mov [r8 + 0], eax ; Reg->RegEax\r
83 mov [r8 + 4], ebx ; Reg->RegEbx\r
84 mov [r8 + 8], ecx ; Reg->RegEcx\r
85 mov [r8 + 12], edx ; Reg->RegEdx\r
86\r
87_Exit:\r
88 pop rbx\r
89 ret\r
90EfiCpuid ENDP\r
91\r
92;------------------------------------------------------------------------------\r
93; UINT64\r
94; EfiReadMsr (\r
95; IN UINT32 Index, // rcx\r
96; )\r
97;------------------------------------------------------------------------------\r
98EfiReadMsr PROC PUBLIC\r
99 rdmsr\r
100 sal rdx, 32 ; edx:eax -> rax\r
101 or rax, rdx ; rax = edx:eax\r
102 ret\r
103EfiReadMsr ENDP\r
104\r
105;------------------------------------------------------------------------------\r
106; VOID\r
107; EfiWriteMsr (\r
108; IN UINT32 Index, // rcx\r
109; IN UINT64 Value // rdx\r
110; )\r
111;------------------------------------------------------------------------------\r
112EfiWriteMsr PROC PUBLIC\r
113 mov rax, rdx ; rdx = Value\r
114 sar rdx, 32 ; convert rdx to edx upper 32-bits\r
115 wrmsr ; wrmsr[ecx] result = edx:eax\r
116 ret\r
117EfiWriteMsr ENDP\r
118\r
119\r
120;------------------------------------------------------------------------------\r
121; UINT64\r
122; EfiReadTsc (\r
123; VOID\r
124; );\r
125;------------------------------------------------------------------------------\r
126EfiReadTsc PROC PUBLIC\r
127 rdtsc\r
128 shl rax, 32\r
129 shrd rax, rdx, 32\r
130 ret\r
131EfiReadTsc ENDP\r
132\r
133;------------------------------------------------------------------------------\r
134; VOID\r
135; EfiDisableCache (\r
136; VOID\r
137; );\r
138;------------------------------------------------------------------------------\r
139EfiDisableCache PROC PUBLIC\r
140; added a check to see if cache is already disabled. If it is, then skip.\r
141 mov rax, cr0\r
142 and rax, 060000000h\r
143 cmp rax, 0\r
144 jne @f\r
145 mov rax, cr0\r
146 or rax, 060000000h\r
147 mov cr0, rax\r
148 wbinvd\r
149@@:\r
150 ret\r
151EfiDisableCache ENDP\r
152\r
153;------------------------------------------------------------------------------\r
154; VOID\r
155; EfiEnableCache (\r
156; VOID\r
157; );\r
158;------------------------------------------------------------------------------\r
159EfiEnableCache PROC PUBLIC\r
160 wbinvd\r
161 mov rax, cr0\r
162 and rax, 09fffffffh\r
163 mov cr0, rax\r
164 ret\r
165EfiEnableCache ENDP\r
166\r
167;------------------------------------------------------------------------------\r
168; UINTN\r
169; EfiGetEflags (\r
170; VOID\r
171; );\r
172;------------------------------------------------------------------------------\r
173EfiGetEflags PROC PUBLIC\r
174 pushfq\r
175 pop rax\r
176 ret\r
177EfiGetEflags ENDP\r
178\r
179;------------------------------------------------------------------------------\r
180; VOID\r
181; EfiDisableInterrupts (\r
182; VOID\r
183; );\r
184;------------------------------------------------------------------------------\r
185EfiDisableInterrupts PROC PUBLIC\r
186 cli\r
187 ret\r
188EfiDisableInterrupts ENDP\r
189\r
190;------------------------------------------------------------------------------\r
191; VOID\r
192; EfiEnableInterrupts (\r
193; VOID\r
194; );\r
195;------------------------------------------------------------------------------\r
196EfiEnableInterrupts PROC PUBLIC\r
197 sti\r
198 ret\r
199EfiEnableInterrupts ENDP\r
200;------------------------------------------------------------------------------\r
201; VOID\r
202; EfiCpuidExt (\r
203; IN UINT32 RegisterInEax,\r
204; IN UINT32 CacheLevel,\r
205; OUT EFI_CPUID_REGISTER *Regs\r
206; )\r
207;------------------------------------------------------------------------------\r
208EfiCpuidExt PROC PUBLIC\r
209 push rbx\r
210 mov rax, rcx ; rax = RegisterInEax\r
211 mov rcx, rdx ; rcx = CacheLevel\r
212\r
213 cpuid\r
214 mov [r8 + 0 ], eax ; Reg->RegEax\r
215 mov [r8 + 4 ], ebx ; Reg->RegEbx\r
216 mov [r8 + 8 ], ecx ; Reg->RegEcx\r
217 mov [r8 + 12], edx ; Reg->RegEdx\r
218\r
219 pop rbx\r
220 ret\r
221EfiCpuidExt ENDP\r
222END\r