1 /** @file
2 
3   Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
4 
5 
6   This program and the accompanying materials are licensed and made available under
7 
8   the terms and conditions of the BSD License that accompanies this distribution.
9 
10   The full text of the license may be found at
11 
12   http://opensource.org/licenses/bsd-license.php.
13 
14 
15 
16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 
21 
22 
23 Module Name:
24 
25 
EfiHalt(VOID)26   CpuIA32.c
27 
28 Abstract:
29 
30 --*/
31 
32 #include <Library/CpuIA32.h>
33 
34 VOID
35 EfiHalt (VOID)
36 {
37   __asm {
38     hlt
39   }
40 }
41 
EfiInvd(VOID)42 VOID
43 EfiWbinvd (VOID)
44 {
45   __asm {
46     wbinvd
47   }
48 }
49 
EfiCpuid(IN UINT32 RegisterInEax,OUT EFI_CPUID_REGISTER * Reg OPTIONAL)50 VOID
51 EfiInvd (VOID)
52 {
53   __asm {
54     invd
55   }
56 }
57 
58 VOID
59 EfiCpuid (IN UINT32 RegisterInEax,
60           OUT EFI_CPUID_REGISTER *Reg OPTIONAL)
61 {
62   __asm {
63     pushad
64 
65     mov    eax, RegisterInEax
66     cpuid
67     cmp    Reg, 0
68     je     _Exit
69     mov    edi, DWORD PTR Reg
70 
71     mov    DWORD PTR [edi].RegEax, eax   ; Reg->RegEax
72     mov    DWORD PTR [edi].RegEbx, ebx   ; Reg->RegEbx
EfiReadMsr(IN UINT32 Index)73     mov    DWORD PTR [edi].RegEcx, ecx   ; Reg->RegEcx
74     mov    DWORD PTR [edi].RegEdx, edx   ; Reg->RegEdx
75 
76 _Exit:
77      popad
78   }
79 }
80 
81 UINT64
EfiWriteMsr(IN UINT32 Index,IN UINT64 Value)82 EfiReadMsr (IN UINT32 Index)
83 {
84   __asm {
85     mov    ecx, Index
86     rdmsr
87   }
88 }
89 
90 VOID
91 EfiWriteMsr (
92   IN   UINT32  Index,
93   IN   UINT64  Value
94   )
95 {
EfiReadTsc(VOID)96   __asm {
97     mov    ecx, Index
98     mov    eax, DWORD PTR Value[0]
99     mov    edx, DWORD PTR Value[4]
100     wrmsr
101   }
102 }
103 
EfiDisableCache(VOID)104 UINT64
105 EfiReadTsc (VOID)
106 {
107   __asm {
108     rdtsc
109   }
110 }
111 
112 VOID
113 EfiDisableCache (VOID)
114 {
115   __asm {
116     mov   eax, cr0
117     bswap eax
118     and   al, 60h
119     cmp   al, 60h
120     je    Exit
EfiEnableCache(VOID)121     mov   eax, cr0
122     or    eax, 060000000h
123     mov   cr0, eax
124     wbinvd
125 Exit:
126   }
127 }
128 
129 VOID
130 EfiEnableCache (VOID)
131 {
132   __asm {
133     wbinvd
134     mov   eax, cr0
135     and   eax, 09fffffffh
136     mov   cr0, eax
137   }
138 }
139 
140 UINT32
141 EfiGetEflags (
142   VOID
EfiDisableInterrupts(VOID)143   )
144 {
145   __asm {
146     pushfd
147     pop  eax
148   }
149 }
150 
EfiEnableInterrupts(VOID)151 VOID
152 EfiDisableInterrupts (VOID)
153 {
154   __asm {
155     cli
156   }
157 }
158 
159 VOID
160 EfiEnableInterrupts (
EfiCpuidExt(IN UINT32 RegisterInEax,IN UINT32 CacheLevel,OUT EFI_CPUID_REGISTER * Regs)161   VOID
162   )
163 {
164   __asm {
165     sti
166   }
167 }
168 
169 VOID
170 EfiCpuidExt (
171   IN   UINT32              RegisterInEax,
172   IN   UINT32              CacheLevel,
173   OUT  EFI_CPUID_REGISTER  *Regs
174   )
175 {
176   __asm {
177     pushad
178 
179     mov    eax, RegisterInEax
180     mov    ecx, CacheLevel
181     cpuid
182     mov    edi, DWORD PTR Regs
183 
184     mov    DWORD PTR [edi].RegEax, eax   ; Reg->RegEax
185     mov    DWORD PTR [edi].RegEbx, ebx   ; Reg->RegEbx
186     mov    DWORD PTR [edi].RegEcx, ecx   ; Reg->RegEcx
187     mov    DWORD PTR [edi].RegEdx, edx   ; Reg->RegEdx
188 
189     popad
190   }
191 }
192