]>
Commit | Line | Data |
---|---|---|
cf683fed | 1 | /** @file\r |
2 | GCC inline implementation of BaseLib processor specific functions.\r | |
9095d37b LG |
3 | \r |
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
c9b34b8c | 5 | Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r |
9344f092 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
cf683fed | 7 | \r |
8 | **/\r | |
9 | \r | |
10 | \r | |
11 | #include "BaseLibInternals.h"\r | |
12 | \r | |
13 | \r | |
14 | \r | |
15 | /**\r | |
16 | Used to serialize load and store operations.\r | |
17 | \r | |
18 | All loads and stores that proceed calls to this function are guaranteed to be\r | |
19 | globally visible when this function returns.\r | |
20 | \r | |
21 | **/\r | |
22 | VOID\r | |
23 | EFIAPI\r | |
24 | MemoryFence (\r | |
25 | VOID\r | |
26 | )\r | |
27 | {\r | |
28 | // This is a little bit of overkill and it is more about the compiler that it is\r | |
9095d37b | 29 | // actually processor synchronization. This is like the _ReadWriteBarrier\r |
d01a90fb | 30 | // Microsoft specific intrinsic\r |
cf683fed | 31 | __asm__ __volatile__ ("":::"memory");\r |
32 | }\r | |
33 | \r | |
34 | \r | |
35 | /**\r | |
36 | Enables CPU interrupts.\r | |
37 | \r | |
38 | Enables CPU interrupts.\r | |
39 | \r | |
40 | **/\r | |
41 | VOID\r | |
42 | EFIAPI\r | |
43 | EnableInterrupts (\r | |
44 | VOID\r | |
45 | )\r | |
46 | {\r | |
47 | __asm__ __volatile__ ("sti"::: "memory");\r | |
48 | }\r | |
49 | \r | |
50 | \r | |
51 | /**\r | |
52 | Disables CPU interrupts.\r | |
53 | \r | |
54 | Disables CPU interrupts.\r | |
55 | \r | |
56 | **/\r | |
57 | VOID\r | |
58 | EFIAPI\r | |
59 | DisableInterrupts (\r | |
60 | VOID\r | |
61 | )\r | |
9095d37b | 62 | {\r |
cf683fed | 63 | __asm__ __volatile__ ("cli"::: "memory");\r |
64 | }\r | |
65 | \r | |
66 | \r | |
67 | \r | |
68 | \r | |
69 | /**\r | |
70 | Requests CPU to pause for a short period of time.\r | |
71 | \r | |
72 | Requests CPU to pause for a short period of time. Typically used in MP\r | |
73 | systems to prevent memory starvation while waiting for a spin lock.\r | |
74 | \r | |
75 | **/\r | |
76 | VOID\r | |
77 | EFIAPI\r | |
78 | CpuPause (\r | |
79 | VOID\r | |
80 | )\r | |
81 | {\r | |
82 | __asm__ __volatile__ ("pause");\r | |
83 | }\r | |
84 | \r | |
85 | \r | |
86 | /**\r | |
87 | Generates a breakpoint on the CPU.\r | |
88 | \r | |
89 | Generates a breakpoint on the CPU. The breakpoint must be implemented such\r | |
90 | that code can resume normal execution after the breakpoint.\r | |
91 | \r | |
92 | **/\r | |
93 | VOID\r | |
94 | EFIAPI\r | |
95 | CpuBreakpoint (\r | |
96 | VOID\r | |
97 | )\r | |
98 | {\r | |
99 | __asm__ __volatile__ ("int $3");\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
103 | \r | |
104 | /**\r | |
105 | Returns a 64-bit Machine Specific Register(MSR).\r | |
106 | \r | |
107 | Reads and returns the 64-bit MSR specified by Index. No parameter checking is\r | |
108 | performed on Index, and some Index values may cause CPU exceptions. The\r | |
109 | caller must either guarantee that Index is valid, or the caller must set up\r | |
110 | exception handlers to catch the exceptions. This function is only available\r | |
111 | on IA-32 and X64.\r | |
112 | \r | |
113 | @param Index The 32-bit MSR index to read.\r | |
114 | \r | |
115 | @return The value of the MSR identified by Index.\r | |
116 | \r | |
117 | **/\r | |
118 | UINT64\r | |
119 | EFIAPI\r | |
120 | AsmReadMsr64 (\r | |
121 | IN UINT32 Index\r | |
122 | )\r | |
123 | {\r | |
124 | UINT64 Data;\r | |
9095d37b | 125 | \r |
cf683fed | 126 | __asm__ __volatile__ (\r |
127 | "rdmsr"\r | |
128 | : "=A" (Data) // %0\r | |
129 | : "c" (Index) // %1\r | |
130 | );\r | |
9095d37b | 131 | \r |
cf683fed | 132 | return Data;\r |
133 | }\r | |
134 | \r | |
135 | /**\r | |
136 | Writes a 64-bit value to a Machine Specific Register(MSR), and returns the\r | |
137 | value.\r | |
138 | \r | |
139 | Writes the 64-bit value specified by Value to the MSR specified by Index. The\r | |
140 | 64-bit value written to the MSR is returned. No parameter checking is\r | |
141 | performed on Index or Value, and some of these may cause CPU exceptions. The\r | |
142 | caller must either guarantee that Index and Value are valid, or the caller\r | |
143 | must establish proper exception handlers. This function is only available on\r | |
144 | IA-32 and X64.\r | |
145 | \r | |
146 | @param Index The 32-bit MSR index to write.\r | |
147 | @param Value The 64-bit value to write to the MSR.\r | |
148 | \r | |
149 | @return Value\r | |
150 | \r | |
151 | **/\r | |
152 | UINT64\r | |
153 | EFIAPI\r | |
154 | AsmWriteMsr64 (\r | |
155 | IN UINT32 Index,\r | |
156 | IN UINT64 Value\r | |
157 | )\r | |
158 | {\r | |
159 | __asm__ __volatile__ (\r | |
160 | "wrmsr"\r | |
161 | :\r | |
162 | : "c" (Index),\r | |
163 | "A" (Value)\r | |
164 | );\r | |
9095d37b | 165 | \r |
cf683fed | 166 | return Value;\r |
167 | }\r | |
168 | \r | |
169 | \r | |
170 | \r | |
171 | /**\r | |
172 | Reads the current value of the EFLAGS register.\r | |
173 | \r | |
174 | Reads and returns the current value of the EFLAGS register. This function is\r | |
175 | only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a\r | |
176 | 64-bit value on X64.\r | |
177 | \r | |
178 | @return EFLAGS on IA-32 or RFLAGS on X64.\r | |
179 | \r | |
180 | **/\r | |
181 | UINTN\r | |
182 | EFIAPI\r | |
183 | AsmReadEflags (\r | |
184 | VOID\r | |
185 | )\r | |
186 | {\r | |
187 | UINTN Eflags;\r | |
9095d37b | 188 | \r |
cf683fed | 189 | __asm__ __volatile__ (\r |
190 | "pushfl \n\t"\r | |
191 | "popl %0 "\r | |
192 | : "=r" (Eflags)\r | |
193 | );\r | |
9095d37b | 194 | \r |
cf683fed | 195 | return Eflags;\r |
196 | }\r | |
197 | \r | |
198 | \r | |
199 | \r | |
200 | /**\r | |
201 | Reads the current value of the Control Register 0 (CR0).\r | |
202 | \r | |
203 | Reads and returns the current value of CR0. This function is only available\r | |
204 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
205 | X64.\r | |
206 | \r | |
207 | @return The value of the Control Register 0 (CR0).\r | |
208 | \r | |
209 | **/\r | |
210 | UINTN\r | |
211 | EFIAPI\r | |
212 | AsmReadCr0 (\r | |
213 | VOID\r | |
214 | )\r | |
215 | {\r | |
216 | UINTN Data;\r | |
9095d37b | 217 | \r |
cf683fed | 218 | __asm__ __volatile__ (\r |
9095d37b | 219 | "movl %%cr0,%0"\r |
cf683fed | 220 | : "=a" (Data)\r |
221 | );\r | |
9095d37b | 222 | \r |
cf683fed | 223 | return Data;\r |
224 | }\r | |
225 | \r | |
226 | \r | |
227 | /**\r | |
228 | Reads the current value of the Control Register 2 (CR2).\r | |
229 | \r | |
230 | Reads and returns the current value of CR2. This function is only available\r | |
231 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
232 | X64.\r | |
233 | \r | |
234 | @return The value of the Control Register 2 (CR2).\r | |
235 | \r | |
236 | **/\r | |
237 | UINTN\r | |
238 | EFIAPI\r | |
239 | AsmReadCr2 (\r | |
240 | VOID\r | |
241 | )\r | |
242 | {\r | |
243 | UINTN Data;\r | |
9095d37b | 244 | \r |
cf683fed | 245 | __asm__ __volatile__ (\r |
9095d37b | 246 | "movl %%cr2, %0"\r |
cf683fed | 247 | : "=r" (Data)\r |
248 | );\r | |
9095d37b | 249 | \r |
cf683fed | 250 | return Data;\r |
251 | }\r | |
252 | \r | |
253 | /**\r | |
254 | Reads the current value of the Control Register 3 (CR3).\r | |
255 | \r | |
256 | Reads and returns the current value of CR3. This function is only available\r | |
257 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
258 | X64.\r | |
259 | \r | |
260 | @return The value of the Control Register 3 (CR3).\r | |
261 | \r | |
262 | **/\r | |
263 | UINTN\r | |
264 | EFIAPI\r | |
265 | AsmReadCr3 (\r | |
266 | VOID\r | |
267 | )\r | |
268 | {\r | |
269 | UINTN Data;\r | |
9095d37b | 270 | \r |
cf683fed | 271 | __asm__ __volatile__ (\r |
272 | "movl %%cr3, %0"\r | |
273 | : "=r" (Data)\r | |
274 | );\r | |
9095d37b | 275 | \r |
cf683fed | 276 | return Data;\r |
277 | }\r | |
278 | \r | |
279 | \r | |
280 | /**\r | |
281 | Reads the current value of the Control Register 4 (CR4).\r | |
282 | \r | |
283 | Reads and returns the current value of CR4. This function is only available\r | |
284 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
285 | X64.\r | |
286 | \r | |
287 | @return The value of the Control Register 4 (CR4).\r | |
288 | \r | |
289 | **/\r | |
290 | UINTN\r | |
291 | EFIAPI\r | |
292 | AsmReadCr4 (\r | |
293 | VOID\r | |
294 | )\r | |
295 | {\r | |
296 | UINTN Data;\r | |
9095d37b | 297 | \r |
cf683fed | 298 | __asm__ __volatile__ (\r |
299 | "movl %%cr4, %0"\r | |
300 | : "=a" (Data)\r | |
301 | );\r | |
9095d37b | 302 | \r |
cf683fed | 303 | return Data;\r |
304 | }\r | |
305 | \r | |
306 | \r | |
307 | /**\r | |
308 | Writes a value to Control Register 0 (CR0).\r | |
309 | \r | |
310 | Writes and returns a new value to CR0. This function is only available on\r | |
311 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
312 | \r | |
313 | @param Cr0 The value to write to CR0.\r | |
314 | \r | |
315 | @return The value written to CR0.\r | |
316 | \r | |
317 | **/\r | |
318 | UINTN\r | |
319 | EFIAPI\r | |
320 | AsmWriteCr0 (\r | |
321 | UINTN Cr0\r | |
322 | )\r | |
323 | {\r | |
324 | __asm__ __volatile__ (\r | |
325 | "movl %0, %%cr0"\r | |
326 | :\r | |
327 | : "r" (Cr0)\r | |
328 | );\r | |
329 | return Cr0;\r | |
330 | }\r | |
331 | \r | |
332 | \r | |
333 | /**\r | |
334 | Writes a value to Control Register 2 (CR2).\r | |
335 | \r | |
336 | Writes and returns a new value to CR2. This function is only available on\r | |
337 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
338 | \r | |
339 | @param Cr2 The value to write to CR2.\r | |
340 | \r | |
341 | @return The value written to CR2.\r | |
342 | \r | |
343 | **/\r | |
344 | UINTN\r | |
345 | EFIAPI\r | |
346 | AsmWriteCr2 (\r | |
347 | UINTN Cr2\r | |
348 | )\r | |
349 | {\r | |
350 | __asm__ __volatile__ (\r | |
351 | "movl %0, %%cr2"\r | |
352 | :\r | |
353 | : "r" (Cr2)\r | |
354 | );\r | |
355 | return Cr2;\r | |
356 | }\r | |
357 | \r | |
358 | \r | |
359 | /**\r | |
360 | Writes a value to Control Register 3 (CR3).\r | |
361 | \r | |
362 | Writes and returns a new value to CR3. This function is only available on\r | |
363 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
364 | \r | |
365 | @param Cr3 The value to write to CR3.\r | |
366 | \r | |
367 | @return The value written to CR3.\r | |
368 | \r | |
369 | **/\r | |
370 | UINTN\r | |
371 | EFIAPI\r | |
372 | AsmWriteCr3 (\r | |
373 | UINTN Cr3\r | |
374 | )\r | |
375 | {\r | |
376 | __asm__ __volatile__ (\r | |
377 | "movl %0, %%cr3"\r | |
378 | :\r | |
379 | : "r" (Cr3)\r | |
380 | );\r | |
381 | return Cr3;\r | |
382 | }\r | |
383 | \r | |
384 | \r | |
385 | /**\r | |
386 | Writes a value to Control Register 4 (CR4).\r | |
387 | \r | |
388 | Writes and returns a new value to CR4. This function is only available on\r | |
389 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
390 | \r | |
391 | @param Cr4 The value to write to CR4.\r | |
392 | \r | |
393 | @return The value written to CR4.\r | |
394 | \r | |
395 | **/\r | |
396 | UINTN\r | |
397 | EFIAPI\r | |
398 | AsmWriteCr4 (\r | |
399 | UINTN Cr4\r | |
400 | )\r | |
401 | {\r | |
402 | __asm__ __volatile__ (\r | |
403 | "movl %0, %%cr4"\r | |
404 | :\r | |
405 | : "r" (Cr4)\r | |
406 | );\r | |
407 | return Cr4;\r | |
408 | }\r | |
409 | \r | |
410 | \r | |
411 | /**\r | |
412 | Reads the current value of Debug Register 0 (DR0).\r | |
413 | \r | |
414 | Reads and returns the current value of DR0. This function is only available\r | |
415 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
416 | X64.\r | |
417 | \r | |
418 | @return The value of Debug Register 0 (DR0).\r | |
419 | \r | |
420 | **/\r | |
421 | UINTN\r | |
422 | EFIAPI\r | |
423 | AsmReadDr0 (\r | |
424 | VOID\r | |
425 | )\r | |
426 | {\r | |
427 | UINTN Data;\r | |
9095d37b | 428 | \r |
cf683fed | 429 | __asm__ __volatile__ (\r |
430 | "movl %%dr0, %0"\r | |
431 | : "=r" (Data)\r | |
432 | );\r | |
9095d37b | 433 | \r |
cf683fed | 434 | return Data;\r |
435 | }\r | |
436 | \r | |
437 | \r | |
438 | /**\r | |
439 | Reads the current value of Debug Register 1 (DR1).\r | |
440 | \r | |
441 | Reads and returns the current value of DR1. This function is only available\r | |
442 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
443 | X64.\r | |
444 | \r | |
445 | @return The value of Debug Register 1 (DR1).\r | |
446 | \r | |
447 | **/\r | |
448 | UINTN\r | |
449 | EFIAPI\r | |
450 | AsmReadDr1 (\r | |
451 | VOID\r | |
452 | )\r | |
453 | {\r | |
454 | UINTN Data;\r | |
9095d37b | 455 | \r |
cf683fed | 456 | __asm__ __volatile__ (\r |
457 | "movl %%dr1, %0"\r | |
458 | : "=r" (Data)\r | |
459 | );\r | |
9095d37b | 460 | \r |
cf683fed | 461 | return Data;\r |
462 | }\r | |
463 | \r | |
464 | \r | |
465 | /**\r | |
466 | Reads the current value of Debug Register 2 (DR2).\r | |
467 | \r | |
468 | Reads and returns the current value of DR2. This function is only available\r | |
469 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
470 | X64.\r | |
471 | \r | |
472 | @return The value of Debug Register 2 (DR2).\r | |
473 | \r | |
474 | **/\r | |
475 | UINTN\r | |
476 | EFIAPI\r | |
477 | AsmReadDr2 (\r | |
478 | VOID\r | |
479 | )\r | |
480 | {\r | |
481 | UINTN Data;\r | |
9095d37b | 482 | \r |
cf683fed | 483 | __asm__ __volatile__ (\r |
484 | "movl %%dr2, %0"\r | |
485 | : "=r" (Data)\r | |
486 | );\r | |
9095d37b | 487 | \r |
cf683fed | 488 | return Data;\r |
489 | }\r | |
490 | \r | |
491 | \r | |
492 | /**\r | |
493 | Reads the current value of Debug Register 3 (DR3).\r | |
494 | \r | |
495 | Reads and returns the current value of DR3. This function is only available\r | |
496 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
497 | X64.\r | |
498 | \r | |
499 | @return The value of Debug Register 3 (DR3).\r | |
500 | \r | |
501 | **/\r | |
502 | UINTN\r | |
503 | EFIAPI\r | |
504 | AsmReadDr3 (\r | |
505 | VOID\r | |
506 | )\r | |
507 | {\r | |
508 | UINTN Data;\r | |
9095d37b | 509 | \r |
cf683fed | 510 | __asm__ __volatile__ (\r |
511 | "movl %%dr3, %0"\r | |
512 | : "=r" (Data)\r | |
513 | );\r | |
9095d37b | 514 | \r |
cf683fed | 515 | return Data;\r |
516 | }\r | |
517 | \r | |
518 | \r | |
519 | /**\r | |
520 | Reads the current value of Debug Register 4 (DR4).\r | |
521 | \r | |
522 | Reads and returns the current value of DR4. This function is only available\r | |
523 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
524 | X64.\r | |
525 | \r | |
526 | @return The value of Debug Register 4 (DR4).\r | |
527 | \r | |
528 | **/\r | |
529 | UINTN\r | |
530 | EFIAPI\r | |
531 | AsmReadDr4 (\r | |
532 | VOID\r | |
533 | )\r | |
534 | {\r | |
535 | UINTN Data;\r | |
9095d37b | 536 | \r |
cf683fed | 537 | __asm__ __volatile__ (\r |
538 | "movl %%dr4, %0"\r | |
539 | : "=r" (Data)\r | |
540 | );\r | |
9095d37b | 541 | \r |
cf683fed | 542 | return Data;\r |
543 | }\r | |
544 | \r | |
545 | \r | |
546 | /**\r | |
547 | Reads the current value of Debug Register 5 (DR5).\r | |
548 | \r | |
549 | Reads and returns the current value of DR5. This function is only available\r | |
550 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
551 | X64.\r | |
552 | \r | |
553 | @return The value of Debug Register 5 (DR5).\r | |
554 | \r | |
555 | **/\r | |
556 | UINTN\r | |
557 | EFIAPI\r | |
558 | AsmReadDr5 (\r | |
559 | VOID\r | |
560 | )\r | |
561 | {\r | |
562 | UINTN Data;\r | |
9095d37b | 563 | \r |
cf683fed | 564 | __asm__ __volatile__ (\r |
565 | "movl %%dr5, %0"\r | |
566 | : "=r" (Data)\r | |
567 | );\r | |
9095d37b | 568 | \r |
cf683fed | 569 | return Data;\r |
570 | }\r | |
571 | \r | |
572 | \r | |
573 | /**\r | |
574 | Reads the current value of Debug Register 6 (DR6).\r | |
575 | \r | |
576 | Reads and returns the current value of DR6. This function is only available\r | |
577 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
578 | X64.\r | |
579 | \r | |
580 | @return The value of Debug Register 6 (DR6).\r | |
581 | \r | |
582 | **/\r | |
583 | UINTN\r | |
584 | EFIAPI\r | |
585 | AsmReadDr6 (\r | |
586 | VOID\r | |
587 | )\r | |
588 | {\r | |
589 | UINTN Data;\r | |
9095d37b | 590 | \r |
cf683fed | 591 | __asm__ __volatile__ (\r |
592 | "movl %%dr6, %0"\r | |
593 | : "=r" (Data)\r | |
594 | );\r | |
9095d37b | 595 | \r |
cf683fed | 596 | return Data;\r |
597 | }\r | |
598 | \r | |
599 | \r | |
600 | /**\r | |
601 | Reads the current value of Debug Register 7 (DR7).\r | |
602 | \r | |
603 | Reads and returns the current value of DR7. This function is only available\r | |
604 | on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on\r | |
605 | X64.\r | |
606 | \r | |
607 | @return The value of Debug Register 7 (DR7).\r | |
608 | \r | |
609 | **/\r | |
610 | UINTN\r | |
611 | EFIAPI\r | |
612 | AsmReadDr7 (\r | |
613 | VOID\r | |
614 | )\r | |
615 | {\r | |
616 | UINTN Data;\r | |
9095d37b | 617 | \r |
cf683fed | 618 | __asm__ __volatile__ (\r |
619 | "movl %%dr7, %0"\r | |
620 | : "=r" (Data)\r | |
621 | );\r | |
9095d37b | 622 | \r |
cf683fed | 623 | return Data;\r |
624 | }\r | |
625 | \r | |
626 | \r | |
627 | /**\r | |
628 | Writes a value to Debug Register 0 (DR0).\r | |
629 | \r | |
630 | Writes and returns a new value to DR0. This function is only available on\r | |
631 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
632 | \r | |
633 | @param Dr0 The value to write to Dr0.\r | |
634 | \r | |
635 | @return The value written to Debug Register 0 (DR0).\r | |
636 | \r | |
637 | **/\r | |
638 | UINTN\r | |
639 | EFIAPI\r | |
640 | AsmWriteDr0 (\r | |
641 | UINTN Dr0\r | |
642 | )\r | |
643 | {\r | |
644 | __asm__ __volatile__ (\r | |
645 | "movl %0, %%dr0"\r | |
646 | :\r | |
647 | : "r" (Dr0)\r | |
648 | );\r | |
649 | return Dr0;\r | |
650 | }\r | |
651 | \r | |
652 | \r | |
653 | /**\r | |
654 | Writes a value to Debug Register 1 (DR1).\r | |
655 | \r | |
656 | Writes and returns a new value to DR1. This function is only available on\r | |
657 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
658 | \r | |
659 | @param Dr1 The value to write to Dr1.\r | |
660 | \r | |
661 | @return The value written to Debug Register 1 (DR1).\r | |
662 | \r | |
663 | **/\r | |
664 | UINTN\r | |
665 | EFIAPI\r | |
666 | AsmWriteDr1 (\r | |
667 | UINTN Dr1\r | |
668 | )\r | |
669 | {\r | |
670 | __asm__ __volatile__ (\r | |
671 | "movl %0, %%dr1"\r | |
672 | :\r | |
673 | : "r" (Dr1)\r | |
674 | );\r | |
675 | return Dr1;\r | |
676 | }\r | |
677 | \r | |
678 | \r | |
679 | /**\r | |
680 | Writes a value to Debug Register 2 (DR2).\r | |
681 | \r | |
682 | Writes and returns a new value to DR2. This function is only available on\r | |
683 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
684 | \r | |
685 | @param Dr2 The value to write to Dr2.\r | |
686 | \r | |
687 | @return The value written to Debug Register 2 (DR2).\r | |
688 | \r | |
689 | **/\r | |
690 | UINTN\r | |
691 | EFIAPI\r | |
692 | AsmWriteDr2 (\r | |
693 | UINTN Dr2\r | |
694 | )\r | |
695 | {\r | |
696 | __asm__ __volatile__ (\r | |
697 | "movl %0, %%dr2"\r | |
698 | :\r | |
699 | : "r" (Dr2)\r | |
700 | );\r | |
701 | return Dr2;\r | |
702 | }\r | |
703 | \r | |
704 | \r | |
705 | /**\r | |
706 | Writes a value to Debug Register 3 (DR3).\r | |
707 | \r | |
708 | Writes and returns a new value to DR3. This function is only available on\r | |
709 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
710 | \r | |
711 | @param Dr3 The value to write to Dr3.\r | |
712 | \r | |
713 | @return The value written to Debug Register 3 (DR3).\r | |
714 | \r | |
715 | **/\r | |
716 | UINTN\r | |
717 | EFIAPI\r | |
718 | AsmWriteDr3 (\r | |
719 | UINTN Dr3\r | |
720 | )\r | |
721 | {\r | |
722 | __asm__ __volatile__ (\r | |
723 | "movl %0, %%dr3"\r | |
724 | :\r | |
725 | : "r" (Dr3)\r | |
726 | );\r | |
727 | return Dr3;\r | |
728 | }\r | |
729 | \r | |
730 | \r | |
731 | /**\r | |
732 | Writes a value to Debug Register 4 (DR4).\r | |
733 | \r | |
734 | Writes and returns a new value to DR4. This function is only available on\r | |
735 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
736 | \r | |
737 | @param Dr4 The value to write to Dr4.\r | |
738 | \r | |
739 | @return The value written to Debug Register 4 (DR4).\r | |
740 | \r | |
741 | **/\r | |
742 | UINTN\r | |
743 | EFIAPI\r | |
744 | AsmWriteDr4 (\r | |
745 | UINTN Dr4\r | |
746 | )\r | |
747 | {\r | |
748 | __asm__ __volatile__ (\r | |
749 | "movl %0, %%dr4"\r | |
750 | :\r | |
751 | : "r" (Dr4)\r | |
752 | );\r | |
753 | return Dr4;\r | |
754 | }\r | |
755 | \r | |
756 | \r | |
757 | /**\r | |
758 | Writes a value to Debug Register 5 (DR5).\r | |
759 | \r | |
760 | Writes and returns a new value to DR5. This function is only available on\r | |
761 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
762 | \r | |
763 | @param Dr5 The value to write to Dr5.\r | |
764 | \r | |
765 | @return The value written to Debug Register 5 (DR5).\r | |
766 | \r | |
767 | **/\r | |
768 | UINTN\r | |
769 | EFIAPI\r | |
770 | AsmWriteDr5 (\r | |
771 | UINTN Dr5\r | |
772 | )\r | |
773 | {\r | |
774 | __asm__ __volatile__ (\r | |
775 | "movl %0, %%dr5"\r | |
776 | :\r | |
777 | : "r" (Dr5)\r | |
778 | );\r | |
779 | return Dr5;\r | |
780 | }\r | |
781 | \r | |
782 | \r | |
783 | /**\r | |
784 | Writes a value to Debug Register 6 (DR6).\r | |
785 | \r | |
786 | Writes and returns a new value to DR6. This function is only available on\r | |
787 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
788 | \r | |
789 | @param Dr6 The value to write to Dr6.\r | |
790 | \r | |
791 | @return The value written to Debug Register 6 (DR6).\r | |
792 | \r | |
793 | **/\r | |
794 | UINTN\r | |
795 | EFIAPI\r | |
796 | AsmWriteDr6 (\r | |
797 | UINTN Dr6\r | |
798 | )\r | |
799 | {\r | |
800 | __asm__ __volatile__ (\r | |
801 | "movl %0, %%dr6"\r | |
802 | :\r | |
803 | : "r" (Dr6)\r | |
804 | );\r | |
805 | return Dr6;\r | |
806 | }\r | |
807 | \r | |
808 | \r | |
809 | /**\r | |
810 | Writes a value to Debug Register 7 (DR7).\r | |
811 | \r | |
812 | Writes and returns a new value to DR7. This function is only available on\r | |
813 | IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.\r | |
814 | \r | |
815 | @param Dr7 The value to write to Dr7.\r | |
816 | \r | |
817 | @return The value written to Debug Register 7 (DR7).\r | |
818 | \r | |
819 | **/\r | |
820 | UINTN\r | |
821 | EFIAPI\r | |
822 | AsmWriteDr7 (\r | |
823 | UINTN Dr7\r | |
824 | )\r | |
825 | {\r | |
826 | __asm__ __volatile__ (\r | |
827 | "movl %0, %%dr7"\r | |
828 | :\r | |
829 | : "r" (Dr7)\r | |
830 | );\r | |
831 | return Dr7;\r | |
832 | }\r | |
833 | \r | |
834 | \r | |
835 | /**\r | |
836 | Reads the current value of Code Segment Register (CS).\r | |
837 | \r | |
838 | Reads and returns the current value of CS. This function is only available on\r | |
839 | IA-32 and X64.\r | |
840 | \r | |
841 | @return The current value of CS.\r | |
842 | \r | |
843 | **/\r | |
844 | UINT16\r | |
845 | EFIAPI\r | |
846 | AsmReadCs (\r | |
847 | VOID\r | |
848 | )\r | |
849 | {\r | |
850 | UINT16 Data;\r | |
9095d37b | 851 | \r |
cf683fed | 852 | __asm__ __volatile__ (\r |
853 | "mov %%cs, %0"\r | |
854 | :"=a" (Data)\r | |
855 | );\r | |
9095d37b | 856 | \r |
cf683fed | 857 | return Data;\r |
858 | }\r | |
859 | \r | |
860 | \r | |
861 | /**\r | |
862 | Reads the current value of Data Segment Register (DS).\r | |
863 | \r | |
864 | Reads and returns the current value of DS. This function is only available on\r | |
865 | IA-32 and X64.\r | |
866 | \r | |
867 | @return The current value of DS.\r | |
868 | \r | |
869 | **/\r | |
870 | UINT16\r | |
871 | EFIAPI\r | |
872 | AsmReadDs (\r | |
873 | VOID\r | |
874 | )\r | |
875 | {\r | |
876 | UINT16 Data;\r | |
9095d37b | 877 | \r |
cf683fed | 878 | __asm__ __volatile__ (\r |
879 | "mov %%ds, %0"\r | |
880 | :"=a" (Data)\r | |
881 | );\r | |
9095d37b | 882 | \r |
cf683fed | 883 | return Data;\r |
884 | }\r | |
885 | \r | |
886 | \r | |
887 | /**\r | |
888 | Reads the current value of Extra Segment Register (ES).\r | |
889 | \r | |
890 | Reads and returns the current value of ES. This function is only available on\r | |
891 | IA-32 and X64.\r | |
892 | \r | |
893 | @return The current value of ES.\r | |
894 | \r | |
895 | **/\r | |
896 | UINT16\r | |
897 | EFIAPI\r | |
898 | AsmReadEs (\r | |
899 | VOID\r | |
900 | )\r | |
901 | {\r | |
902 | UINT16 Data;\r | |
9095d37b | 903 | \r |
cf683fed | 904 | __asm__ __volatile__ (\r |
905 | "mov %%es, %0"\r | |
906 | :"=a" (Data)\r | |
907 | );\r | |
9095d37b | 908 | \r |
cf683fed | 909 | return Data;\r |
910 | }\r | |
911 | \r | |
912 | \r | |
913 | /**\r | |
914 | Reads the current value of FS Data Segment Register (FS).\r | |
915 | \r | |
916 | Reads and returns the current value of FS. This function is only available on\r | |
917 | IA-32 and X64.\r | |
918 | \r | |
919 | @return The current value of FS.\r | |
920 | \r | |
921 | **/\r | |
922 | UINT16\r | |
923 | EFIAPI\r | |
924 | AsmReadFs (\r | |
925 | VOID\r | |
926 | )\r | |
927 | {\r | |
928 | UINT16 Data;\r | |
9095d37b | 929 | \r |
cf683fed | 930 | __asm__ __volatile__ (\r |
931 | "mov %%fs, %0"\r | |
932 | :"=a" (Data)\r | |
933 | );\r | |
9095d37b | 934 | \r |
cf683fed | 935 | return Data;\r |
936 | }\r | |
937 | \r | |
938 | \r | |
939 | /**\r | |
940 | Reads the current value of GS Data Segment Register (GS).\r | |
941 | \r | |
942 | Reads and returns the current value of GS. This function is only available on\r | |
943 | IA-32 and X64.\r | |
944 | \r | |
945 | @return The current value of GS.\r | |
946 | \r | |
947 | **/\r | |
948 | UINT16\r | |
949 | EFIAPI\r | |
950 | AsmReadGs (\r | |
951 | VOID\r | |
952 | )\r | |
953 | {\r | |
954 | UINT16 Data;\r | |
9095d37b | 955 | \r |
cf683fed | 956 | __asm__ __volatile__ (\r |
957 | "mov %%gs, %0"\r | |
958 | :"=a" (Data)\r | |
959 | );\r | |
9095d37b | 960 | \r |
cf683fed | 961 | return Data;\r |
962 | }\r | |
963 | \r | |
964 | \r | |
965 | /**\r | |
966 | Reads the current value of Stack Segment Register (SS).\r | |
967 | \r | |
968 | Reads and returns the current value of SS. This function is only available on\r | |
969 | IA-32 and X64.\r | |
970 | \r | |
971 | @return The current value of SS.\r | |
972 | \r | |
973 | **/\r | |
974 | UINT16\r | |
975 | EFIAPI\r | |
976 | AsmReadSs (\r | |
977 | VOID\r | |
978 | )\r | |
979 | {\r | |
980 | UINT16 Data;\r | |
9095d37b | 981 | \r |
cf683fed | 982 | __asm__ __volatile__ (\r |
983 | "mov %%ds, %0"\r | |
984 | :"=a" (Data)\r | |
985 | );\r | |
9095d37b | 986 | \r |
cf683fed | 987 | return Data;\r |
988 | }\r | |
989 | \r | |
990 | \r | |
991 | /**\r | |
992 | Reads the current value of Task Register (TR).\r | |
993 | \r | |
994 | Reads and returns the current value of TR. This function is only available on\r | |
995 | IA-32 and X64.\r | |
996 | \r | |
997 | @return The current value of TR.\r | |
998 | \r | |
999 | **/\r | |
1000 | UINT16\r | |
1001 | EFIAPI\r | |
1002 | AsmReadTr (\r | |
1003 | VOID\r | |
1004 | )\r | |
1005 | {\r | |
1006 | UINT16 Data;\r | |
9095d37b | 1007 | \r |
cf683fed | 1008 | __asm__ __volatile__ (\r |
1009 | "str %0"\r | |
1010 | : "=a" (Data)\r | |
1011 | );\r | |
9095d37b | 1012 | \r |
cf683fed | 1013 | return Data;\r |
1014 | }\r | |
1015 | \r | |
1016 | \r | |
1017 | /**\r | |
1018 | Reads the current Global Descriptor Table Register(GDTR) descriptor.\r | |
1019 | \r | |
1020 | Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r | |
1021 | function is only available on IA-32 and X64.\r | |
1022 | \r | |
2fc59a00 | 1023 | @param Gdtr The pointer to a GDTR descriptor.\r |
cf683fed | 1024 | \r |
1025 | **/\r | |
1026 | VOID\r | |
1027 | EFIAPI\r | |
1028 | InternalX86ReadGdtr (\r | |
1029 | OUT IA32_DESCRIPTOR *Gdtr\r | |
1030 | )\r | |
1031 | {\r | |
1032 | __asm__ __volatile__ (\r | |
1033 | "sgdt %0"\r | |
1034 | : "=m" (*Gdtr)\r | |
1035 | );\r | |
1036 | }\r | |
1037 | \r | |
1038 | \r | |
1039 | /**\r | |
1040 | Writes the current Global Descriptor Table Register (GDTR) descriptor.\r | |
1041 | \r | |
1042 | Writes and the current GDTR descriptor specified by Gdtr. This function is\r | |
1043 | only available on IA-32 and X64.\r | |
1044 | \r | |
2fc59a00 | 1045 | @param Gdtr The pointer to a GDTR descriptor.\r |
cf683fed | 1046 | \r |
1047 | **/\r | |
1048 | VOID\r | |
1049 | EFIAPI\r | |
1050 | InternalX86WriteGdtr (\r | |
1051 | IN CONST IA32_DESCRIPTOR *Gdtr\r | |
1052 | )\r | |
1053 | {\r | |
1054 | __asm__ __volatile__ (\r | |
1055 | "lgdt %0"\r | |
1056 | :\r | |
1057 | : "m" (*Gdtr)\r | |
1058 | );\r | |
9095d37b | 1059 | \r |
cf683fed | 1060 | }\r |
1061 | \r | |
1062 | \r | |
1063 | /**\r | |
1064 | Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
1065 | \r | |
1066 | Reads and returns the current IDTR descriptor and returns it in Idtr. This\r | |
1067 | function is only available on IA-32 and X64.\r | |
1068 | \r | |
2fc59a00 | 1069 | @param Idtr The pointer to a IDTR descriptor.\r |
cf683fed | 1070 | \r |
1071 | **/\r | |
1072 | VOID\r | |
1073 | EFIAPI\r | |
1074 | InternalX86ReadIdtr (\r | |
1075 | OUT IA32_DESCRIPTOR *Idtr\r | |
1076 | )\r | |
1077 | {\r | |
1078 | __asm__ __volatile__ (\r | |
2bd78c92 | 1079 | "sidt %0"\r |
cf683fed | 1080 | : "=m" (*Idtr)\r |
1081 | );\r | |
1082 | }\r | |
1083 | \r | |
1084 | \r | |
1085 | /**\r | |
1086 | Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
1087 | \r | |
1088 | Writes the current IDTR descriptor and returns it in Idtr. This function is\r | |
1089 | only available on IA-32 and X64.\r | |
1090 | \r | |
2fc59a00 | 1091 | @param Idtr The pointer to a IDTR descriptor.\r |
cf683fed | 1092 | \r |
1093 | **/\r | |
1094 | VOID\r | |
1095 | EFIAPI\r | |
1096 | InternalX86WriteIdtr (\r | |
1097 | IN CONST IA32_DESCRIPTOR *Idtr\r | |
1098 | )\r | |
1099 | {\r | |
1100 | __asm__ __volatile__ (\r | |
1101 | "lidt %0"\r | |
1102 | :\r | |
1103 | : "m" (*Idtr)\r | |
1104 | );\r | |
1105 | }\r | |
1106 | \r | |
1107 | \r | |
1108 | /**\r | |
1109 | Reads the current Local Descriptor Table Register(LDTR) selector.\r | |
1110 | \r | |
1111 | Reads and returns the current 16-bit LDTR descriptor value. This function is\r | |
1112 | only available on IA-32 and X64.\r | |
1113 | \r | |
1114 | @return The current selector of LDT.\r | |
1115 | \r | |
1116 | **/\r | |
1117 | UINT16\r | |
1118 | EFIAPI\r | |
1119 | AsmReadLdtr (\r | |
1120 | VOID\r | |
1121 | )\r | |
1122 | {\r | |
1123 | UINT16 Data;\r | |
9095d37b | 1124 | \r |
cf683fed | 1125 | __asm__ __volatile__ (\r |
1126 | "sldt %0"\r | |
1127 | : "=g" (Data) // %0\r | |
1128 | );\r | |
9095d37b | 1129 | \r |
cf683fed | 1130 | return Data;\r |
1131 | }\r | |
1132 | \r | |
1133 | \r | |
1134 | /**\r | |
1135 | Writes the current Local Descriptor Table Register (GDTR) selector.\r | |
1136 | \r | |
1137 | Writes and the current LDTR descriptor specified by Ldtr. This function is\r | |
1138 | only available on IA-32 and X64.\r | |
1139 | \r | |
1140 | @param Ldtr 16-bit LDTR selector value.\r | |
1141 | \r | |
1142 | **/\r | |
1143 | VOID\r | |
1144 | EFIAPI\r | |
1145 | AsmWriteLdtr (\r | |
1146 | IN UINT16 Ldtr\r | |
1147 | )\r | |
1148 | {\r | |
1149 | __asm__ __volatile__ (\r | |
1150 | "lldtw %0"\r | |
1151 | :\r | |
1152 | : "g" (Ldtr) // %0\r | |
1153 | );\r | |
1154 | }\r | |
1155 | \r | |
1156 | \r | |
1157 | /**\r | |
1158 | Save the current floating point/SSE/SSE2 context to a buffer.\r | |
1159 | \r | |
1160 | Saves the current floating point/SSE/SSE2 state to the buffer specified by\r | |
1161 | Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r | |
1162 | available on IA-32 and X64.\r | |
1163 | \r | |
2fc59a00 | 1164 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
cf683fed | 1165 | \r |
1166 | **/\r | |
1167 | VOID\r | |
1168 | EFIAPI\r | |
1169 | InternalX86FxSave (\r | |
1170 | OUT IA32_FX_BUFFER *Buffer\r | |
1171 | )\r | |
1172 | {\r | |
1173 | __asm__ __volatile__ (\r | |
1174 | "fxsave %0"\r | |
1175 | :\r | |
1176 | : "m" (*Buffer) // %0\r | |
9095d37b | 1177 | );\r |
cf683fed | 1178 | }\r |
1179 | \r | |
1180 | \r | |
1181 | /**\r | |
1182 | Restores the current floating point/SSE/SSE2 context from a buffer.\r | |
1183 | \r | |
1184 | Restores the current floating point/SSE/SSE2 state from the buffer specified\r | |
1185 | by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r | |
1186 | only available on IA-32 and X64.\r | |
1187 | \r | |
2fc59a00 | 1188 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r |
cf683fed | 1189 | \r |
1190 | **/\r | |
1191 | VOID\r | |
1192 | EFIAPI\r | |
1193 | InternalX86FxRestore (\r | |
1194 | IN CONST IA32_FX_BUFFER *Buffer\r | |
1195 | )\r | |
1196 | {\r | |
1197 | __asm__ __volatile__ (\r | |
1198 | "fxrstor %0"\r | |
1199 | :\r | |
1200 | : "m" (*Buffer) // %0\r | |
1201 | );\r | |
1202 | }\r | |
1203 | \r | |
1204 | \r | |
1205 | /**\r | |
1206 | Reads the current value of 64-bit MMX Register #0 (MM0).\r | |
1207 | \r | |
1208 | Reads and returns the current value of MM0. This function is only available\r | |
1209 | on IA-32 and X64.\r | |
1210 | \r | |
1211 | @return The current value of MM0.\r | |
1212 | \r | |
1213 | **/\r | |
1214 | UINT64\r | |
1215 | EFIAPI\r | |
1216 | AsmReadMm0 (\r | |
1217 | VOID\r | |
1218 | )\r | |
1219 | {\r | |
1220 | UINT64 Data;\r | |
1221 | \r | |
1222 | __asm__ __volatile__ (\r | |
1223 | "push %%eax \n\t"\r | |
1224 | "push %%eax \n\t"\r | |
1225 | "movq %%mm0, (%%esp)\n\t"\r | |
1226 | "pop %%eax \n\t"\r | |
1227 | "pop %%edx \n\t"\r | |
1228 | : "=A" (Data) // %0\r | |
1229 | );\r | |
9095d37b | 1230 | \r |
cf683fed | 1231 | return Data;\r |
1232 | }\r | |
1233 | \r | |
1234 | \r | |
1235 | /**\r | |
1236 | Reads the current value of 64-bit MMX Register #1 (MM1).\r | |
1237 | \r | |
1238 | Reads and returns the current value of MM1. This function is only available\r | |
1239 | on IA-32 and X64.\r | |
1240 | \r | |
1241 | @return The current value of MM1.\r | |
1242 | \r | |
1243 | **/\r | |
1244 | UINT64\r | |
1245 | EFIAPI\r | |
1246 | AsmReadMm1 (\r | |
1247 | VOID\r | |
1248 | )\r | |
1249 | {\r | |
1250 | UINT64 Data;\r | |
1251 | \r | |
1252 | __asm__ __volatile__ (\r | |
1253 | "push %%eax \n\t"\r | |
1254 | "push %%eax \n\t"\r | |
1255 | "movq %%mm1, (%%esp)\n\t"\r | |
1256 | "pop %%eax \n\t"\r | |
1257 | "pop %%edx \n\t"\r | |
1258 | : "=A" (Data) // %0\r | |
1259 | );\r | |
9095d37b | 1260 | \r |
cf683fed | 1261 | return Data;\r |
1262 | }\r | |
1263 | \r | |
1264 | \r | |
1265 | /**\r | |
1266 | Reads the current value of 64-bit MMX Register #2 (MM2).\r | |
1267 | \r | |
1268 | Reads and returns the current value of MM2. This function is only available\r | |
1269 | on IA-32 and X64.\r | |
1270 | \r | |
1271 | @return The current value of MM2.\r | |
1272 | \r | |
1273 | **/\r | |
1274 | UINT64\r | |
1275 | EFIAPI\r | |
1276 | AsmReadMm2 (\r | |
1277 | VOID\r | |
1278 | )\r | |
1279 | {\r | |
1280 | UINT64 Data;\r | |
1281 | \r | |
1282 | __asm__ __volatile__ (\r | |
1283 | "push %%eax \n\t"\r | |
1284 | "push %%eax \n\t"\r | |
1285 | "movq %%mm2, (%%esp)\n\t"\r | |
1286 | "pop %%eax \n\t"\r | |
1287 | "pop %%edx \n\t"\r | |
1288 | : "=A" (Data) // %0\r | |
1289 | );\r | |
9095d37b | 1290 | \r |
cf683fed | 1291 | return Data;\r |
1292 | }\r | |
1293 | \r | |
1294 | \r | |
1295 | /**\r | |
1296 | Reads the current value of 64-bit MMX Register #3 (MM3).\r | |
1297 | \r | |
1298 | Reads and returns the current value of MM3. This function is only available\r | |
1299 | on IA-32 and X64.\r | |
1300 | \r | |
1301 | @return The current value of MM3.\r | |
1302 | \r | |
1303 | **/\r | |
1304 | UINT64\r | |
1305 | EFIAPI\r | |
1306 | AsmReadMm3 (\r | |
1307 | VOID\r | |
1308 | )\r | |
1309 | {\r | |
1310 | UINT64 Data;\r | |
1311 | \r | |
1312 | __asm__ __volatile__ (\r | |
1313 | "push %%eax \n\t"\r | |
1314 | "push %%eax \n\t"\r | |
1315 | "movq %%mm3, (%%esp)\n\t"\r | |
1316 | "pop %%eax \n\t"\r | |
1317 | "pop %%edx \n\t"\r | |
1318 | : "=A" (Data) // %0\r | |
1319 | );\r | |
9095d37b | 1320 | \r |
cf683fed | 1321 | return Data;\r |
1322 | }\r | |
1323 | \r | |
1324 | \r | |
1325 | /**\r | |
1326 | Reads the current value of 64-bit MMX Register #4 (MM4).\r | |
1327 | \r | |
1328 | Reads and returns the current value of MM4. This function is only available\r | |
1329 | on IA-32 and X64.\r | |
1330 | \r | |
1331 | @return The current value of MM4.\r | |
1332 | \r | |
1333 | **/\r | |
1334 | UINT64\r | |
1335 | EFIAPI\r | |
1336 | AsmReadMm4 (\r | |
1337 | VOID\r | |
1338 | )\r | |
1339 | {\r | |
1340 | UINT64 Data;\r | |
1341 | \r | |
1342 | __asm__ __volatile__ (\r | |
1343 | "push %%eax \n\t"\r | |
1344 | "push %%eax \n\t"\r | |
1345 | "movq %%mm4, (%%esp)\n\t"\r | |
1346 | "pop %%eax \n\t"\r | |
1347 | "pop %%edx \n\t"\r | |
1348 | : "=A" (Data) // %0\r | |
1349 | );\r | |
9095d37b | 1350 | \r |
cf683fed | 1351 | return Data;\r |
1352 | }\r | |
1353 | \r | |
1354 | \r | |
1355 | /**\r | |
1356 | Reads the current value of 64-bit MMX Register #5 (MM5).\r | |
1357 | \r | |
1358 | Reads and returns the current value of MM5. This function is only available\r | |
1359 | on IA-32 and X64.\r | |
1360 | \r | |
1361 | @return The current value of MM5.\r | |
1362 | \r | |
1363 | **/\r | |
1364 | UINT64\r | |
1365 | EFIAPI\r | |
1366 | AsmReadMm5 (\r | |
1367 | VOID\r | |
1368 | )\r | |
1369 | {\r | |
1370 | UINT64 Data;\r | |
1371 | \r | |
1372 | __asm__ __volatile__ (\r | |
1373 | "push %%eax \n\t"\r | |
1374 | "push %%eax \n\t"\r | |
1375 | "movq %%mm5, (%%esp)\n\t"\r | |
1376 | "pop %%eax \n\t"\r | |
1377 | "pop %%edx \n\t"\r | |
1378 | : "=A" (Data) // %0\r | |
1379 | );\r | |
9095d37b | 1380 | \r |
cf683fed | 1381 | return Data;\r |
1382 | }\r | |
1383 | \r | |
1384 | \r | |
1385 | /**\r | |
1386 | Reads the current value of 64-bit MMX Register #6 (MM6).\r | |
1387 | \r | |
1388 | Reads and returns the current value of MM6. This function is only available\r | |
1389 | on IA-32 and X64.\r | |
1390 | \r | |
1391 | @return The current value of MM6.\r | |
1392 | \r | |
1393 | **/\r | |
1394 | UINT64\r | |
1395 | EFIAPI\r | |
1396 | AsmReadMm6 (\r | |
1397 | VOID\r | |
1398 | )\r | |
1399 | {\r | |
1400 | UINT64 Data;\r | |
1401 | \r | |
1402 | __asm__ __volatile__ (\r | |
1403 | "push %%eax \n\t"\r | |
1404 | "push %%eax \n\t"\r | |
1405 | "movq %%mm6, (%%esp)\n\t"\r | |
1406 | "pop %%eax \n\t"\r | |
1407 | "pop %%edx \n\t"\r | |
1408 | : "=A" (Data) // %0\r | |
1409 | );\r | |
9095d37b | 1410 | \r |
cf683fed | 1411 | return Data;\r |
1412 | }\r | |
1413 | \r | |
1414 | \r | |
1415 | /**\r | |
1416 | Reads the current value of 64-bit MMX Register #7 (MM7).\r | |
1417 | \r | |
1418 | Reads and returns the current value of MM7. This function is only available\r | |
1419 | on IA-32 and X64.\r | |
1420 | \r | |
1421 | @return The current value of MM7.\r | |
1422 | \r | |
1423 | **/\r | |
1424 | UINT64\r | |
1425 | EFIAPI\r | |
1426 | AsmReadMm7 (\r | |
1427 | VOID\r | |
1428 | )\r | |
1429 | {\r | |
1430 | UINT64 Data;\r | |
1431 | \r | |
1432 | __asm__ __volatile__ (\r | |
1433 | "push %%eax \n\t"\r | |
1434 | "push %%eax \n\t"\r | |
1435 | "movq %%mm7, (%%esp)\n\t"\r | |
1436 | "pop %%eax \n\t"\r | |
1437 | "pop %%edx \n\t"\r | |
1438 | : "=A" (Data) // %0\r | |
1439 | );\r | |
9095d37b | 1440 | \r |
cf683fed | 1441 | return Data;\r |
1442 | }\r | |
1443 | \r | |
1444 | \r | |
1445 | /**\r | |
1446 | Writes the current value of 64-bit MMX Register #0 (MM0).\r | |
1447 | \r | |
1448 | Writes the current value of MM0. This function is only available on IA32 and\r | |
1449 | X64.\r | |
1450 | \r | |
1451 | @param Value The 64-bit value to write to MM0.\r | |
1452 | \r | |
1453 | **/\r | |
1454 | VOID\r | |
1455 | EFIAPI\r | |
1456 | AsmWriteMm0 (\r | |
1457 | IN UINT64 Value\r | |
1458 | )\r | |
1459 | {\r | |
1460 | __asm__ __volatile__ (\r | |
1461 | "movq %0, %%mm0" // %0\r | |
9095d37b | 1462 | :\r |
cf683fed | 1463 | : "m" (Value)\r |
1464 | );\r | |
1465 | }\r | |
1466 | \r | |
1467 | \r | |
1468 | /**\r | |
1469 | Writes the current value of 64-bit MMX Register #1 (MM1).\r | |
1470 | \r | |
1471 | Writes the current value of MM1. This function is only available on IA32 and\r | |
1472 | X64.\r | |
1473 | \r | |
1474 | @param Value The 64-bit value to write to MM1.\r | |
1475 | \r | |
1476 | **/\r | |
1477 | VOID\r | |
1478 | EFIAPI\r | |
1479 | AsmWriteMm1 (\r | |
1480 | IN UINT64 Value\r | |
1481 | )\r | |
1482 | {\r | |
1483 | __asm__ __volatile__ (\r | |
1484 | "movq %0, %%mm1" // %0\r | |
9095d37b | 1485 | :\r |
cf683fed | 1486 | : "m" (Value)\r |
1487 | );\r | |
1488 | }\r | |
1489 | \r | |
1490 | \r | |
1491 | /**\r | |
1492 | Writes the current value of 64-bit MMX Register #2 (MM2).\r | |
1493 | \r | |
1494 | Writes the current value of MM2. This function is only available on IA32 and\r | |
1495 | X64.\r | |
1496 | \r | |
1497 | @param Value The 64-bit value to write to MM2.\r | |
1498 | \r | |
1499 | **/\r | |
1500 | VOID\r | |
1501 | EFIAPI\r | |
1502 | AsmWriteMm2 (\r | |
1503 | IN UINT64 Value\r | |
1504 | )\r | |
1505 | {\r | |
1506 | __asm__ __volatile__ (\r | |
1507 | "movq %0, %%mm2" // %0\r | |
9095d37b | 1508 | :\r |
cf683fed | 1509 | : "m" (Value)\r |
1510 | );\r | |
1511 | }\r | |
1512 | \r | |
1513 | \r | |
1514 | /**\r | |
1515 | Writes the current value of 64-bit MMX Register #3 (MM3).\r | |
1516 | \r | |
1517 | Writes the current value of MM3. This function is only available on IA32 and\r | |
1518 | X64.\r | |
1519 | \r | |
1520 | @param Value The 64-bit value to write to MM3.\r | |
1521 | \r | |
1522 | **/\r | |
1523 | VOID\r | |
1524 | EFIAPI\r | |
1525 | AsmWriteMm3 (\r | |
1526 | IN UINT64 Value\r | |
1527 | )\r | |
1528 | {\r | |
1529 | __asm__ __volatile__ (\r | |
1530 | "movq %0, %%mm3" // %0\r | |
9095d37b | 1531 | :\r |
cf683fed | 1532 | : "m" (Value)\r |
1533 | );\r | |
1534 | }\r | |
1535 | \r | |
1536 | \r | |
1537 | /**\r | |
1538 | Writes the current value of 64-bit MMX Register #4 (MM4).\r | |
1539 | \r | |
1540 | Writes the current value of MM4. This function is only available on IA32 and\r | |
1541 | X64.\r | |
1542 | \r | |
1543 | @param Value The 64-bit value to write to MM4.\r | |
1544 | \r | |
1545 | **/\r | |
1546 | VOID\r | |
1547 | EFIAPI\r | |
1548 | AsmWriteMm4 (\r | |
1549 | IN UINT64 Value\r | |
1550 | )\r | |
1551 | {\r | |
1552 | __asm__ __volatile__ (\r | |
1553 | "movq %0, %%mm4" // %0\r | |
9095d37b | 1554 | :\r |
cf683fed | 1555 | : "m" (Value)\r |
1556 | );\r | |
1557 | }\r | |
1558 | \r | |
1559 | \r | |
1560 | /**\r | |
1561 | Writes the current value of 64-bit MMX Register #5 (MM5).\r | |
1562 | \r | |
1563 | Writes the current value of MM5. This function is only available on IA32 and\r | |
1564 | X64.\r | |
1565 | \r | |
1566 | @param Value The 64-bit value to write to MM5.\r | |
1567 | \r | |
1568 | **/\r | |
1569 | VOID\r | |
1570 | EFIAPI\r | |
1571 | AsmWriteMm5 (\r | |
1572 | IN UINT64 Value\r | |
1573 | )\r | |
1574 | {\r | |
1575 | __asm__ __volatile__ (\r | |
1576 | "movq %0, %%mm5" // %0\r | |
9095d37b | 1577 | :\r |
cf683fed | 1578 | : "m" (Value)\r |
1579 | );\r | |
1580 | }\r | |
1581 | \r | |
1582 | \r | |
1583 | /**\r | |
1584 | Writes the current value of 64-bit MMX Register #6 (MM6).\r | |
1585 | \r | |
1586 | Writes the current value of MM6. This function is only available on IA32 and\r | |
1587 | X64.\r | |
1588 | \r | |
1589 | @param Value The 64-bit value to write to MM6.\r | |
1590 | \r | |
1591 | **/\r | |
1592 | VOID\r | |
1593 | EFIAPI\r | |
1594 | AsmWriteMm6 (\r | |
1595 | IN UINT64 Value\r | |
1596 | )\r | |
1597 | {\r | |
1598 | __asm__ __volatile__ (\r | |
1599 | "movq %0, %%mm6" // %0\r | |
9095d37b | 1600 | :\r |
cf683fed | 1601 | : "m" (Value)\r |
1602 | );\r | |
1603 | }\r | |
1604 | \r | |
1605 | \r | |
1606 | /**\r | |
1607 | Writes the current value of 64-bit MMX Register #7 (MM7).\r | |
1608 | \r | |
1609 | Writes the current value of MM7. This function is only available on IA32 and\r | |
1610 | X64.\r | |
1611 | \r | |
1612 | @param Value The 64-bit value to write to MM7.\r | |
1613 | \r | |
1614 | **/\r | |
1615 | VOID\r | |
1616 | EFIAPI\r | |
1617 | AsmWriteMm7 (\r | |
1618 | IN UINT64 Value\r | |
1619 | )\r | |
1620 | {\r | |
1621 | __asm__ __volatile__ (\r | |
1622 | "movq %0, %%mm7" // %0\r | |
9095d37b | 1623 | :\r |
cf683fed | 1624 | : "m" (Value)\r |
1625 | );\r | |
1626 | }\r | |
1627 | \r | |
1628 | \r | |
1629 | /**\r | |
1630 | Reads the current value of Time Stamp Counter (TSC).\r | |
1631 | \r | |
1632 | Reads and returns the current value of TSC. This function is only available\r | |
1633 | on IA-32 and X64.\r | |
1634 | \r | |
1635 | @return The current value of TSC\r | |
1636 | \r | |
1637 | **/\r | |
1638 | UINT64\r | |
1639 | EFIAPI\r | |
1640 | AsmReadTsc (\r | |
1641 | VOID\r | |
1642 | )\r | |
1643 | {\r | |
1644 | UINT64 Data;\r | |
9095d37b | 1645 | \r |
cf683fed | 1646 | __asm__ __volatile__ (\r |
1647 | "rdtsc"\r | |
1648 | : "=A" (Data)\r | |
1649 | );\r | |
9095d37b LG |
1650 | \r |
1651 | return Data;\r | |
cf683fed | 1652 | }\r |
1653 | \r | |
1654 | \r | |
1655 | /**\r | |
1656 | Reads the current value of a Performance Counter (PMC).\r | |
1657 | \r | |
1658 | Reads and returns the current value of performance counter specified by\r | |
1659 | Index. This function is only available on IA-32 and X64.\r | |
1660 | \r | |
1661 | @param Index The 32-bit Performance Counter index to read.\r | |
1662 | \r | |
1663 | @return The value of the PMC specified by Index.\r | |
1664 | \r | |
1665 | **/\r | |
1666 | UINT64\r | |
1667 | EFIAPI\r | |
1668 | AsmReadPmc (\r | |
1669 | IN UINT32 Index\r | |
1670 | )\r | |
1671 | {\r | |
1672 | UINT64 Data;\r | |
9095d37b | 1673 | \r |
cf683fed | 1674 | __asm__ __volatile__ (\r |
1675 | "rdpmc"\r | |
1676 | : "=A" (Data)\r | |
1677 | : "c" (Index)\r | |
1678 | );\r | |
9095d37b LG |
1679 | \r |
1680 | return Data;\r | |
cf683fed | 1681 | }\r |
1682 | \r | |
1683 | \r | |
1684 | \r | |
1685 | \r | |
1686 | /**\r | |
1687 | Executes a WBINVD instruction.\r | |
1688 | \r | |
1689 | Executes a WBINVD instruction. This function is only available on IA-32 and\r | |
1690 | X64.\r | |
1691 | \r | |
1692 | **/\r | |
1693 | VOID\r | |
1694 | EFIAPI\r | |
1695 | AsmWbinvd (\r | |
1696 | VOID\r | |
1697 | )\r | |
1698 | {\r | |
1699 | __asm__ __volatile__ ("wbinvd":::"memory");\r | |
1700 | }\r | |
1701 | \r | |
1702 | \r | |
1703 | /**\r | |
1704 | Executes a INVD instruction.\r | |
1705 | \r | |
1706 | Executes a INVD instruction. This function is only available on IA-32 and\r | |
1707 | X64.\r | |
1708 | \r | |
1709 | **/\r | |
1710 | VOID\r | |
1711 | EFIAPI\r | |
1712 | AsmInvd (\r | |
1713 | VOID\r | |
1714 | )\r | |
1715 | {\r | |
1716 | __asm__ __volatile__ ("invd":::"memory");\r | |
9095d37b | 1717 | \r |
cf683fed | 1718 | }\r |
1719 | \r | |
1720 | \r | |
1721 | /**\r | |
1722 | Flushes a cache line from all the instruction and data caches within the\r | |
1723 | coherency domain of the CPU.\r | |
1724 | \r | |
1725 | Flushed the cache line specified by LinearAddress, and returns LinearAddress.\r | |
1726 | This function is only available on IA-32 and X64.\r | |
1727 | \r | |
1728 | @param LinearAddress The address of the cache line to flush. If the CPU is\r | |
1729 | in a physical addressing mode, then LinearAddress is a\r | |
1730 | physical address. If the CPU is in a virtual\r | |
1731 | addressing mode, then LinearAddress is a virtual\r | |
1732 | address.\r | |
1733 | \r | |
1734 | @return LinearAddress\r | |
1735 | **/\r | |
1736 | VOID *\r | |
1737 | EFIAPI\r | |
1738 | AsmFlushCacheLine (\r | |
1739 | IN VOID *LinearAddress\r | |
1740 | )\r | |
1741 | {\r | |
881813d7 MK |
1742 | UINT32 RegEdx;\r |
1743 | \r | |
1744 | //\r | |
9095d37b | 1745 | // If the CPU does not support CLFLUSH instruction,\r |
881813d7 MK |
1746 | // then promote flush range to flush entire cache.\r |
1747 | //\r | |
1748 | AsmCpuid (0x01, NULL, NULL, NULL, &RegEdx);\r | |
1749 | if ((RegEdx & BIT19) == 0) {\r | |
1750 | __asm__ __volatile__ ("wbinvd":::"memory");\r | |
1751 | return LinearAddress;\r | |
1752 | }\r | |
1753 | \r | |
1754 | \r | |
cf683fed | 1755 | __asm__ __volatile__ (\r |
1756 | "clflush (%0)"\r | |
9095d37b LG |
1757 | : "+a" (LinearAddress)\r |
1758 | :\r | |
cf683fed | 1759 | : "memory"\r |
1760 | );\r | |
9095d37b | 1761 | \r |
881813d7 | 1762 | return LinearAddress;\r |
cf683fed | 1763 | }\r |
1764 | \r | |
1765 | \r |