]>
Commit | Line | Data |
---|---|---|
9a1ed798 | 1 | #------------------------------------------------------------------------------ |
2 | #* | |
3 | #* Copyright (c) 2008, Intel Corporation | |
4 | #* All rights reserved. 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 | #* Module Name: | |
13 | #* | |
14 | #* Cpu.asm | |
15 | #* | |
16 | #* Abstract: | |
17 | #* | |
18 | #------------------------------------------------------------------------------ | |
19 | #include <EfiBind.h> | |
20 | ||
21 | .globl ASM_PFX(EfiHalt) | |
22 | .globl ASM_PFX(EfiWbinvd) | |
23 | .globl ASM_PFX(EfiInvd) | |
24 | .globl ASM_PFX(EfiCpuid) | |
25 | .globl ASM_PFX(EfiReadTsc) | |
26 | .globl ASM_PFX(EfiDisableCache) | |
27 | .globl ASM_PFX(EfiEnableCache) | |
28 | .globl ASM_PFX(EfiReadMsr) | |
29 | .globl ASM_PFX(EfiGetEflags) | |
30 | .globl ASM_PFX(EfiDisableInterrupts) | |
31 | .globl ASM_PFX(EfiEnableInterrupts) | |
32 | .globl ASM_PFX(EfiCpuidExt) | |
33 | ||
34 | .text | |
35 | ||
36 | ||
37 | #------------------------------------------------------------------------------ | |
38 | # VOID | |
39 | # EfiHalt ( | |
40 | # VOID | |
41 | # ) | |
42 | #------------------------------------------------------------------------------ | |
43 | ASM_PFX(EfiHalt): | |
44 | hlt | |
45 | retq | |
46 | ||
47 | ||
48 | #------------------------------------------------------------------------------ | |
49 | # VOID | |
50 | # EfiWbinvd ( | |
51 | # VOID | |
52 | # ) | |
53 | #------------------------------------------------------------------------------ | |
54 | ASM_PFX(EfiWbinvd): | |
55 | wbinvd | |
56 | retq | |
57 | ||
58 | ||
59 | #------------------------------------------------------------------------------ | |
60 | # VOID | |
61 | # EfiInvd ( | |
62 | # VOID | |
63 | # ) | |
64 | #------------------------------------------------------------------------------ | |
65 | ASM_PFX(EfiInvd): | |
66 | invd | |
67 | retq | |
68 | ||
69 | #------------------------------------------------------------------------------ | |
70 | # VOID | |
71 | # EfiCpuid ( | |
72 | # IN UINT32 RegisterInEax, // rcx | |
73 | # OUT EFI_CPUID_REGISTER *Reg OPTIONAL // rdx | |
74 | # ) | |
75 | #------------------------------------------------------------------------------ | |
76 | ASM_PFX(EfiCpuid): | |
77 | push %rbx\r | |
78 | mov %rdx,%r8\r | |
79 | mov %rcx,%rax\r | |
80 | cpuid \r | |
81 | cmp $0x0,%r8\r | |
82 | je _Exit\r | |
83 | mov %eax,(%r8)\r | |
84 | mov %ebx,0x4(%r8)\r | |
85 | mov %ecx,0x8(%r8)\r | |
86 | mov %edx,0xc(%r8) | |
87 | _Exit: | |
88 | pop %rbx | |
89 | retq | |
90 | ||
91 | #------------------------------------------------------------------------------ | |
92 | # UINT64 | |
93 | # EfiReadMsr ( | |
94 | # IN UINT32 Index, // rcx | |
95 | # ) | |
96 | #------------------------------------------------------------------------------ | |
97 | ASM_PFX(EfiReadMsr): | |
98 | rdmsr \r | |
99 | shl $0x20,%rdx\r | |
100 | or %rdx,%rax\r | |
101 | retq \r | |
102 | ||
103 | #------------------------------------------------------------------------------ | |
104 | # VOID | |
105 | # EfiWriteMsr ( | |
106 | # IN UINT32 Index, // rcx | |
107 | # IN UINT64 Value // rdx | |
108 | # ) | |
109 | #------------------------------------------------------------------------------ | |
110 | ASM_PFX(EfiWriteMsr): | |
111 | mov %rdx,%rax\r | |
112 | sar $0x20,%rdx\r | |
113 | wrmsr \r | |
114 | retq | |
115 | ||
116 | #------------------------------------------------------------------------------ | |
117 | # UINT64 | |
118 | # EfiReadTsc ( | |
119 | # VOID | |
120 | # ); | |
121 | #------------------------------------------------------------------------------ | |
122 | ASM_PFX(EfiReadTsc): | |
123 | rdtsc \r | |
124 | shl $0x20,%rax\r | |
125 | shrd $0x20,%rdx,%rax\r | |
126 | retq \r | |
127 | ||
128 | #------------------------------------------------------------------------------ | |
129 | # VOID | |
130 | # EfiDisableCache ( | |
131 | # VOID | |
132 | # ); | |
133 | #------------------------------------------------------------------------------ | |
134 | ASM_PFX(EfiDisableCache): | |
135 | # added a check to see if cache is already disabled. If it is, then skip. | |
136 | mov %cr0,%rax\r | |
137 | and $0x60000000,%rax\r | |
138 | cmp $0x0,%rax\r | |
139 | jne 1f\r | |
140 | mov %cr0,%rax\r | |
141 | or $0x60000000,%rax\r | |
142 | mov %rax,%cr0\r | |
143 | wbinvd \r | |
144 | 1: | |
145 | retq \r | |
146 | ||
147 | #------------------------------------------------------------------------------ | |
148 | # VOID | |
149 | # EfiEnableCache ( | |
150 | # VOID | |
151 | # ); | |
152 | #------------------------------------------------------------------------------ | |
153 | ASM_PFX(EfiEnableCache): | |
154 | invd \r | |
155 | mov %cr0,%rax\r | |
156 | and $0xffffffff9fffffff,%rax\r | |
157 | mov %rax,%cr0\r | |
158 | retq \r | |
159 | ||
160 | #------------------------------------------------------------------------------ | |
161 | # UINTN | |
162 | # EfiGetEflags ( | |
163 | # VOID | |
164 | # ); | |
165 | #------------------------------------------------------------------------------ | |
166 | ASM_PFX(EfiGetEflags): | |
167 | pushfq \r | |
168 | pop %rax\r | |
169 | retq \r | |
170 | ||
171 | #------------------------------------------------------------------------------ | |
172 | # VOID | |
173 | # EfiDisableInterrupts ( | |
174 | # VOID | |
175 | # ); | |
176 | #------------------------------------------------------------------------------ | |
177 | ASM_PFX(EfiDisableInterrupts): | |
178 | cli | |
179 | ret | |
180 | ||
181 | #------------------------------------------------------------------------------ | |
182 | # VOID | |
183 | # EfiEnableInterrupts ( | |
184 | # VOID | |
185 | # ); | |
186 | #------------------------------------------------------------------------------ | |
187 | ASM_PFX(EfiEnableInterrupts): | |
188 | sti | |
189 | ret | |
190 | #------------------------------------------------------------------------------ | |
191 | # VOID | |
192 | # EfiCpuidExt ( | |
193 | # IN UINT32 RegisterInEax, | |
194 | # IN UINT32 CacheLevel, | |
195 | # OUT EFI_CPUID_REGISTER *Regs | |
196 | # ) | |
197 | #------------------------------------------------------------------------------ | |
198 | ASM_PFX(EfiCpuidExt): | |
199 | push %rbx\r | |
200 | mov %rcx,%rax\r | |
201 | mov %rdx,%rcx\r | |
202 | cpuid \r | |
203 | mov %eax,(%r8)\r | |
204 | mov %ebx,0x4(%r8)\r | |
205 | mov %ecx,0x8(%r8)\r | |
206 | mov %edx,0xc(%r8)\r | |
207 | pop %rbx\r | |
208 | retq \r |