]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Library/CpuIA32Lib/X64/Cpu.S
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / CpuIA32Lib / X64 / Cpu.S
1 #
2 #
3 # Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
4 #
5 # This program and the accompanying materials are licensed and made available under
6 # the terms and conditions of the BSD License that accompanies this distribution.
7 # The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php.
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13 #
14 #
15 #* Module Name:
16 #*
17 #* Cpu.asm
18 #*
19 #* Abstract:
20 #*
21 #------------------------------------------------------------------------------
22 ##include <EfiBind.h>
23
24 .globl ASM_PFX(EfiHalt)
25 .globl ASM_PFX(EfiWbinvd)
26 .globl ASM_PFX(EfiInvd)
27 .globl ASM_PFX(EfiCpuid)
28 .globl ASM_PFX(EfiReadTsc)
29 .globl ASM_PFX(EfiDisableCache)
30 .globl ASM_PFX(EfiEnableCache)
31 .globl ASM_PFX(EfiReadMsr)
32 .globl ASM_PFX(EfiWriteMsr)
33 .globl ASM_PFX(EfiGetEflags)
34 .globl ASM_PFX(EfiDisableInterrupts)
35 .globl ASM_PFX(EfiEnableInterrupts)
36 .globl ASM_PFX(EfiCpuidExt)
37
38 .text
39
40
41 #------------------------------------------------------------------------------
42 # VOID
43 # EfiHalt (
44 # VOID
45 # )
46 #------------------------------------------------------------------------------
47 ASM_PFX(EfiHalt):
48 hlt
49 retq
50
51
52 #------------------------------------------------------------------------------
53 # VOID
54 # EfiWbinvd (
55 # VOID
56 # )
57 #------------------------------------------------------------------------------
58 ASM_PFX(EfiWbinvd):
59 wbinvd
60 retq
61
62
63 #------------------------------------------------------------------------------
64 # VOID
65 # EfiInvd (
66 # VOID
67 # )
68 #------------------------------------------------------------------------------
69 ASM_PFX(EfiInvd):
70 invd
71 retq
72
73 #------------------------------------------------------------------------------
74 # VOID
75 # EfiCpuid (
76 # IN UINT32 RegisterInEax, // rcx
77 # OUT EFI_CPUID_REGISTER *Reg OPTIONAL // rdx
78 # )
79 #------------------------------------------------------------------------------
80 ASM_PFX(EfiCpuid):
81 push %rbx
82 mov %rdx,%r8
83 mov %rcx,%rax
84 cpuid
85 cmp $0x0,%r8
86 je _Exit
87 mov %eax,(%r8)
88 mov %ebx,0x4(%r8)
89 mov %ecx,0x8(%r8)
90 mov %edx,0xc(%r8)
91 _Exit:
92 pop %rbx
93 retq
94
95 #------------------------------------------------------------------------------
96 # UINT64
97 # EfiReadMsr (
98 # IN UINT32 Index, // rcx
99 # )
100 #------------------------------------------------------------------------------
101 ASM_PFX(EfiReadMsr):
102 rdmsr
103 shl $0x20,%rdx
104 or %rdx,%rax
105 retq
106
107 #------------------------------------------------------------------------------
108 # VOID
109 # EfiWriteMsr (
110 # IN UINT32 Index, // rcx
111 # IN UINT64 Value // rdx
112 # )
113 #------------------------------------------------------------------------------
114 ASM_PFX(EfiWriteMsr):
115 mov %rdx,%rax
116 sar $0x20,%rdx
117 wrmsr
118 retq
119
120 #------------------------------------------------------------------------------
121 # UINT64
122 # EfiReadTsc (
123 # VOID
124 # );
125 #------------------------------------------------------------------------------
126 ASM_PFX(EfiReadTsc):
127 rdtsc
128 shl $0x20,%rax
129 shrd $0x20,%rdx,%rax
130 retq
131
132 #------------------------------------------------------------------------------
133 # VOID
134 # EfiDisableCache (
135 # VOID
136 # );
137 #------------------------------------------------------------------------------
138 ASM_PFX(EfiDisableCache):
139 # added a check to see if cache is already disabled. If it is, then skip.
140 mov %cr0,%rax
141 and $0x60000000,%rax
142 cmp $0x0,%rax
143 jne 1f
144 mov %cr0,%rax
145 or $0x60000000,%rax
146 mov %rax,%cr0
147 wbinvd
148 1:
149 retq
150
151 #------------------------------------------------------------------------------
152 # VOID
153 # EfiEnableCache (
154 # VOID
155 # );
156 #------------------------------------------------------------------------------
157 ASM_PFX(EfiEnableCache):
158 wbinvd
159 mov %cr0,%rax
160 and $0xffffffff9fffffff,%rax
161 mov %rax,%cr0
162 retq
163
164 #------------------------------------------------------------------------------
165 # UINTN
166 # EfiGetEflags (
167 # VOID
168 # );
169 #------------------------------------------------------------------------------
170 ASM_PFX(EfiGetEflags):
171 pushfq
172 pop %rax
173 retq
174
175 #------------------------------------------------------------------------------
176 # VOID
177 # EfiDisableInterrupts (
178 # VOID
179 # );
180 #------------------------------------------------------------------------------
181 ASM_PFX(EfiDisableInterrupts):
182 cli
183 ret
184
185 #------------------------------------------------------------------------------
186 # VOID
187 # EfiEnableInterrupts (
188 # VOID
189 # );
190 #------------------------------------------------------------------------------
191 ASM_PFX(EfiEnableInterrupts):
192 sti
193 ret
194 #------------------------------------------------------------------------------
195 # VOID
196 # EfiCpuidExt (
197 # IN UINT32 RegisterInEax,
198 # IN UINT32 CacheLevel,
199 # OUT EFI_CPUID_REGISTER *Regs
200 # )
201 #------------------------------------------------------------------------------
202 ASM_PFX(EfiCpuidExt):
203 push %rbx
204 mov %rcx,%rax
205 mov %rdx,%rcx
206 cpuid
207 mov %eax,(%r8)
208 mov %ebx,0x4(%r8)
209 mov %ecx,0x8(%r8)
210 mov %edx,0xc(%r8)
211 pop %rbx
212 retq