]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Library/CpuIA32Lib/IA32/CpuIA32.c
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / CpuIA32Lib / IA32 / CpuIA32.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
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 Module Name:
15
16
17 CpuIA32.c
18
19 Abstract:
20
21 --*/
22
23 #include <Library/CpuIA32.h>
24
25 VOID
26 EfiHalt (VOID)
27 {
28 __asm {
29 hlt
30 }
31 }
32
33 VOID
34 EfiWbinvd (VOID)
35 {
36 __asm {
37 wbinvd
38 }
39 }
40
41 VOID
42 EfiInvd (VOID)
43 {
44 __asm {
45 invd
46 }
47 }
48
49 VOID
50 EfiCpuid (IN UINT32 RegisterInEax,
51 OUT EFI_CPUID_REGISTER *Reg OPTIONAL)
52 {
53 __asm {
54 pushad
55
56 mov eax, RegisterInEax
57 cpuid
58 cmp Reg, 0
59 je _Exit
60 mov edi, DWORD PTR Reg
61
62 mov DWORD PTR [edi].RegEax, eax ; Reg->RegEax
63 mov DWORD PTR [edi].RegEbx, ebx ; Reg->RegEbx
64 mov DWORD PTR [edi].RegEcx, ecx ; Reg->RegEcx
65 mov DWORD PTR [edi].RegEdx, edx ; Reg->RegEdx
66
67 _Exit:
68 popad
69 }
70 }
71
72 UINT64
73 EfiReadMsr (IN UINT32 Index)
74 {
75 __asm {
76 mov ecx, Index
77 rdmsr
78 }
79 }
80
81 VOID
82 EfiWriteMsr (
83 IN UINT32 Index,
84 IN UINT64 Value
85 )
86 {
87 __asm {
88 mov ecx, Index
89 mov eax, DWORD PTR Value[0]
90 mov edx, DWORD PTR Value[4]
91 wrmsr
92 }
93 }
94
95 UINT64
96 EfiReadTsc (VOID)
97 {
98 __asm {
99 rdtsc
100 }
101 }
102
103 VOID
104 EfiDisableCache (VOID)
105 {
106 __asm {
107 mov eax, cr0
108 bswap eax
109 and al, 60h
110 cmp al, 60h
111 je Exit
112 mov eax, cr0
113 or eax, 060000000h
114 mov cr0, eax
115 wbinvd
116 Exit:
117 }
118 }
119
120 VOID
121 EfiEnableCache (VOID)
122 {
123 __asm {
124 wbinvd
125 mov eax, cr0
126 and eax, 09fffffffh
127 mov cr0, eax
128 }
129 }
130
131 UINT32
132 EfiGetEflags (
133 VOID
134 )
135 {
136 __asm {
137 pushfd
138 pop eax
139 }
140 }
141
142 VOID
143 EfiDisableInterrupts (VOID)
144 {
145 __asm {
146 cli
147 }
148 }
149
150 VOID
151 EfiEnableInterrupts (
152 VOID
153 )
154 {
155 __asm {
156 sti
157 }
158 }
159
160 VOID
161 EfiCpuidExt (
162 IN UINT32 RegisterInEax,
163 IN UINT32 CacheLevel,
164 OUT EFI_CPUID_REGISTER *Regs
165 )
166 {
167 __asm {
168 pushad
169
170 mov eax, RegisterInEax
171 mov ecx, CacheLevel
172 cpuid
173 mov edi, DWORD PTR Regs
174
175 mov DWORD PTR [edi].RegEax, eax ; Reg->RegEax
176 mov DWORD PTR [edi].RegEbx, ebx ; Reg->RegEbx
177 mov DWORD PTR [edi].RegEcx, ecx ; Reg->RegEcx
178 mov DWORD PTR [edi].RegEdx, edx ; Reg->RegEdx
179
180 popad
181 }
182 }