]>
git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Library/UnixBaseLib/X64/GccInline.c
2 GCC inline implementation of BaseLib processor specific functions.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "BaseLibInternals.h"
23 Used to serialize load and store operations.
25 All loads and stores that proceed calls to this function are guaranteed to be
26 globally visible when this function returns.
35 // This is a little bit of overkill and it is more about the compiler that it is
36 // actually processor synchronization. This is like the _ReadWriteBarrier
37 // Microsoft specific intrinsic
38 __asm__
__volatile__ ("":::"memory");
43 Enables CPU interrupts.
45 Enables CPU interrupts.
54 __asm__
__volatile__ ("sti"::: "memory");
59 Disables CPU interrupts.
61 Disables CPU interrupts.
70 __asm__
__volatile__ ("cli"::: "memory");
77 Requests CPU to pause for a short period of time.
79 Requests CPU to pause for a short period of time. Typically used in MP
80 systems to prevent memory starvation while waiting for a spin lock.
89 __asm__
__volatile__ ("pause");
94 Generates a breakpoint on the CPU.
96 Generates a breakpoint on the CPU. The breakpoint must be implemented such
97 that code can resume normal execution after the breakpoint.
106 __asm__
__volatile__ ("int $3");
112 Returns a 64-bit Machine Specific Register(MSR).
114 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
115 performed on Index, and some Index values may cause CPU exceptions. The
116 caller must either guarantee that Index is valid, or the caller must set up
117 exception handlers to catch the exceptions. This function is only available
120 @param Index The 32-bit MSR index to read.
122 @return The value of the MSR identified by Index.
134 __asm__
__volatile__ (
136 : "=a" (LowData
), // %0
137 "=d" (HighData
) // %1
141 return (((UINT64
)HighData
) << 32) | LowData
;
145 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
148 Writes the 64-bit value specified by Value to the MSR specified by Index. The
149 64-bit value written to the MSR is returned. No parameter checking is
150 performed on Index or Value, and some of these may cause CPU exceptions. The
151 caller must either guarantee that Index and Value are valid, or the caller
152 must establish proper exception handlers. This function is only available on
155 @param Index The 32-bit MSR index to write.
156 @param Value The 64-bit value to write to the MSR.
171 LowData
= (UINT32
)(Value
);
172 HighData
= (UINT32
)(Value
>> 32);
174 __asm__
__volatile__ (
188 Reads the current value of the EFLAGS register.
190 Reads and returns the current value of the EFLAGS register. This function is
191 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
194 @return EFLAGS on IA-32 or RFLAGS on X64.
205 __asm__
__volatile__ (
208 : "=r" (Eflags
) // %0
217 Reads the current value of the Control Register 0 (CR0).
219 Reads and returns the current value of CR0. This function is only available
220 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
223 @return The value of the Control Register 0 (CR0).
234 __asm__
__volatile__ (
244 Reads the current value of the Control Register 2 (CR2).
246 Reads and returns the current value of CR2. This function is only available
247 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
250 @return The value of the Control Register 2 (CR2).
261 __asm__
__volatile__ (
270 Reads the current value of the Control Register 3 (CR3).
272 Reads and returns the current value of CR3. This function is only available
273 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
276 @return The value of the Control Register 3 (CR3).
287 __asm__
__volatile__ (
297 Reads the current value of the Control Register 4 (CR4).
299 Reads and returns the current value of CR4. This function is only available
300 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
303 @return The value of the Control Register 4 (CR4).
314 __asm__
__volatile__ (
324 Writes a value to Control Register 0 (CR0).
326 Writes and returns a new value to CR0. This function is only available on
327 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
329 @param Cr0 The value to write to CR0.
331 @return The value written to CR0.
340 __asm__
__volatile__ (
350 Writes a value to Control Register 2 (CR2).
352 Writes and returns a new value to CR2. This function is only available on
353 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
355 @param Cr2 The value to write to CR2.
357 @return The value written to CR2.
366 __asm__
__volatile__ (
376 Writes a value to Control Register 3 (CR3).
378 Writes and returns a new value to CR3. This function is only available on
379 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
381 @param Cr3 The value to write to CR3.
383 @return The value written to CR3.
397 Writes a value to Control Register 4 (CR4).
399 Writes and returns a new value to CR4. This function is only available on
400 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
402 @param Cr4 The value to write to CR4.
404 @return The value written to CR4.
413 __asm__
__volatile__ (
423 Reads the current value of Debug Register 0 (DR0).
425 Reads and returns the current value of DR0. This function is only available
426 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
429 @return The value of Debug Register 0 (DR0).
440 __asm__
__volatile__ (
450 Reads the current value of Debug Register 1 (DR1).
452 Reads and returns the current value of DR1. This function is only available
453 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
456 @return The value of Debug Register 1 (DR1).
467 __asm__
__volatile__ (
477 Reads the current value of Debug Register 2 (DR2).
479 Reads and returns the current value of DR2. This function is only available
480 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
483 @return The value of Debug Register 2 (DR2).
494 __asm__
__volatile__ (
504 Reads the current value of Debug Register 3 (DR3).
506 Reads and returns the current value of DR3. This function is only available
507 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
510 @return The value of Debug Register 3 (DR3).
521 __asm__
__volatile__ (
531 Reads the current value of Debug Register 4 (DR4).
533 Reads and returns the current value of DR4. This function is only available
534 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
537 @return The value of Debug Register 4 (DR4).
548 __asm__
__volatile__ (
558 Reads the current value of Debug Register 5 (DR5).
560 Reads and returns the current value of DR5. This function is only available
561 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
564 @return The value of Debug Register 5 (DR5).
575 __asm__
__volatile__ (
585 Reads the current value of Debug Register 6 (DR6).
587 Reads and returns the current value of DR6. This function is only available
588 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
591 @return The value of Debug Register 6 (DR6).
602 __asm__
__volatile__ (
612 Reads the current value of Debug Register 7 (DR7).
614 Reads and returns the current value of DR7. This function is only available
615 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
618 @return The value of Debug Register 7 (DR7).
629 __asm__
__volatile__ (
639 Writes a value to Debug Register 0 (DR0).
641 Writes and returns a new value to DR0. This function is only available on
642 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
644 @param Dr0 The value to write to Dr0.
646 @return The value written to Debug Register 0 (DR0).
655 __asm__
__volatile__ (
665 Writes a value to Debug Register 1 (DR1).
667 Writes and returns a new value to DR1. This function is only available on
668 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
670 @param Dr1 The value to write to Dr1.
672 @return The value written to Debug Register 1 (DR1).
681 __asm__
__volatile__ (
691 Writes a value to Debug Register 2 (DR2).
693 Writes and returns a new value to DR2. This function is only available on
694 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
696 @param Dr2 The value to write to Dr2.
698 @return The value written to Debug Register 2 (DR2).
707 __asm__
__volatile__ (
717 Writes a value to Debug Register 3 (DR3).
719 Writes and returns a new value to DR3. This function is only available on
720 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
722 @param Dr3 The value to write to Dr3.
724 @return The value written to Debug Register 3 (DR3).
733 __asm__
__volatile__ (
743 Writes a value to Debug Register 4 (DR4).
745 Writes and returns a new value to DR4. This function is only available on
746 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
748 @param Dr4 The value to write to Dr4.
750 @return The value written to Debug Register 4 (DR4).
759 __asm__
__volatile__ (
769 Writes a value to Debug Register 5 (DR5).
771 Writes and returns a new value to DR5. This function is only available on
772 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
774 @param Dr5 The value to write to Dr5.
776 @return The value written to Debug Register 5 (DR5).
785 __asm__
__volatile__ (
795 Writes a value to Debug Register 6 (DR6).
797 Writes and returns a new value to DR6. This function is only available on
798 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
800 @param Dr6 The value to write to Dr6.
802 @return The value written to Debug Register 6 (DR6).
811 __asm__
__volatile__ (
821 Writes a value to Debug Register 7 (DR7).
823 Writes and returns a new value to DR7. This function is only available on
824 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
826 @param Dr7 The value to write to Dr7.
828 @return The value written to Debug Register 7 (DR7).
837 __asm__
__volatile__ (
847 Reads the current value of Code Segment Register (CS).
849 Reads and returns the current value of CS. This function is only available on
852 @return The current value of CS.
863 __asm__
__volatile__ (
873 Reads the current value of Data Segment Register (DS).
875 Reads and returns the current value of DS. This function is only available on
878 @return The current value of DS.
889 __asm__
__volatile__ (
899 Reads the current value of Extra Segment Register (ES).
901 Reads and returns the current value of ES. This function is only available on
904 @return The current value of ES.
915 __asm__
__volatile__ (
925 Reads the current value of FS Data Segment Register (FS).
927 Reads and returns the current value of FS. This function is only available on
930 @return The current value of FS.
941 __asm__
__volatile__ (
951 Reads the current value of GS Data Segment Register (GS).
953 Reads and returns the current value of GS. This function is only available on
956 @return The current value of GS.
967 __asm__
__volatile__ (
977 Reads the current value of Stack Segment Register (SS).
979 Reads and returns the current value of SS. This function is only available on
982 @return The current value of SS.
993 __asm__
__volatile__ (
1003 Reads the current value of Task Register (TR).
1005 Reads and returns the current value of TR. This function is only available on
1008 @return The current value of TR.
1019 __asm__
__volatile__ (
1029 Reads the current Global Descriptor Table Register(GDTR) descriptor.
1031 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
1032 function is only available on IA-32 and X64.
1034 @param Gdtr The pointer to a GDTR descriptor.
1039 InternalX86ReadGdtr (
1040 OUT IA32_DESCRIPTOR
*Gdtr
1043 __asm__
__volatile__ (
1051 Writes the current Global Descriptor Table Register (GDTR) descriptor.
1053 Writes and the current GDTR descriptor specified by Gdtr. This function is
1054 only available on IA-32 and X64.
1056 @param Gdtr The pointer to a GDTR descriptor.
1061 InternalX86WriteGdtr (
1062 IN CONST IA32_DESCRIPTOR
*Gdtr
1065 __asm__
__volatile__ (
1075 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
1077 Reads and returns the current IDTR descriptor and returns it in Idtr. This
1078 function is only available on IA-32 and X64.
1080 @param Idtr The pointer to a IDTR descriptor.
1085 InternalX86ReadIdtr (
1086 OUT IA32_DESCRIPTOR
*Idtr
1089 __asm__
__volatile__ (
1097 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
1099 Writes the current IDTR descriptor and returns it in Idtr. This function is
1100 only available on IA-32 and X64.
1102 @param Idtr The pointer to a IDTR descriptor.
1107 InternalX86WriteIdtr (
1108 IN CONST IA32_DESCRIPTOR
*Idtr
1111 __asm__
__volatile__ (
1120 Reads the current Local Descriptor Table Register(LDTR) selector.
1122 Reads and returns the current 16-bit LDTR descriptor value. This function is
1123 only available on IA-32 and X64.
1125 @return The current selector of LDT.
1136 __asm__
__volatile__ (
1146 Writes the current Local Descriptor Table Register (GDTR) selector.
1148 Writes and the current LDTR descriptor specified by Ldtr. This function is
1149 only available on IA-32 and X64.
1151 @param Ldtr 16-bit LDTR selector value.
1160 __asm__
__volatile__ (
1169 Save the current floating point/SSE/SSE2 context to a buffer.
1171 Saves the current floating point/SSE/SSE2 state to the buffer specified by
1172 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
1173 available on IA-32 and X64.
1175 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
1181 OUT IA32_FX_BUFFER
*Buffer
1184 __asm__
__volatile__ (
1187 : "m" (*Buffer
) // %0
1193 Restores the current floating point/SSE/SSE2 context from a buffer.
1195 Restores the current floating point/SSE/SSE2 state from the buffer specified
1196 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
1197 only available on IA-32 and X64.
1199 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
1204 InternalX86FxRestore (
1205 IN CONST IA32_FX_BUFFER
*Buffer
1208 __asm__
__volatile__ (
1211 : "m" (*Buffer
) // %0
1217 Reads the current value of 64-bit MMX Register #0 (MM0).
1219 Reads and returns the current value of MM0. This function is only available
1222 @return The current value of MM0.
1233 __asm__
__volatile__ (
1234 "movd %%mm0, %0 \n\t"
1243 Reads the current value of 64-bit MMX Register #1 (MM1).
1245 Reads and returns the current value of MM1. This function is only available
1248 @return The current value of MM1.
1259 __asm__
__volatile__ (
1260 "movd %%mm1, %0 \n\t"
1269 Reads the current value of 64-bit MMX Register #2 (MM2).
1271 Reads and returns the current value of MM2. This function is only available
1274 @return The current value of MM2.
1285 __asm__
__volatile__ (
1286 "movd %%mm2, %0 \n\t"
1295 Reads the current value of 64-bit MMX Register #3 (MM3).
1297 Reads and returns the current value of MM3. This function is only available
1300 @return The current value of MM3.
1311 __asm__
__volatile__ (
1312 "movd %%mm3, %0 \n\t"
1321 Reads the current value of 64-bit MMX Register #4 (MM4).
1323 Reads and returns the current value of MM4. This function is only available
1326 @return The current value of MM4.
1337 __asm__
__volatile__ (
1338 "movd %%mm4, %0 \n\t"
1347 Reads the current value of 64-bit MMX Register #5 (MM5).
1349 Reads and returns the current value of MM5. This function is only available
1352 @return The current value of MM5.
1363 __asm__
__volatile__ (
1364 "movd %%mm5, %0 \n\t"
1373 Reads the current value of 64-bit MMX Register #6 (MM6).
1375 Reads and returns the current value of MM6. This function is only available
1378 @return The current value of MM6.
1389 __asm__
__volatile__ (
1390 "movd %%mm6, %0 \n\t"
1399 Reads the current value of 64-bit MMX Register #7 (MM7).
1401 Reads and returns the current value of MM7. This function is only available
1404 @return The current value of MM7.
1415 __asm__
__volatile__ (
1416 "movd %%mm7, %0 \n\t"
1425 Writes the current value of 64-bit MMX Register #0 (MM0).
1427 Writes the current value of MM0. This function is only available on IA32 and
1430 @param Value The 64-bit value to write to MM0.
1439 __asm__
__volatile__ (
1440 "movd %0, %%mm0" // %0
1448 Writes the current value of 64-bit MMX Register #1 (MM1).
1450 Writes the current value of MM1. This function is only available on IA32 and
1453 @param Value The 64-bit value to write to MM1.
1462 __asm__
__volatile__ (
1463 "movd %0, %%mm1" // %0
1471 Writes the current value of 64-bit MMX Register #2 (MM2).
1473 Writes the current value of MM2. This function is only available on IA32 and
1476 @param Value The 64-bit value to write to MM2.
1485 __asm__
__volatile__ (
1486 "movd %0, %%mm2" // %0
1494 Writes the current value of 64-bit MMX Register #3 (MM3).
1496 Writes the current value of MM3. This function is only available on IA32 and
1499 @param Value The 64-bit value to write to MM3.
1508 __asm__
__volatile__ (
1509 "movd %0, %%mm3" // %0
1517 Writes the current value of 64-bit MMX Register #4 (MM4).
1519 Writes the current value of MM4. This function is only available on IA32 and
1522 @param Value The 64-bit value to write to MM4.
1531 __asm__
__volatile__ (
1532 "movd %0, %%mm4" // %0
1540 Writes the current value of 64-bit MMX Register #5 (MM5).
1542 Writes the current value of MM5. This function is only available on IA32 and
1545 @param Value The 64-bit value to write to MM5.
1554 __asm__
__volatile__ (
1555 "movd %0, %%mm5" // %0
1563 Writes the current value of 64-bit MMX Register #6 (MM6).
1565 Writes the current value of MM6. This function is only available on IA32 and
1568 @param Value The 64-bit value to write to MM6.
1577 __asm__
__volatile__ (
1578 "movd %0, %%mm6" // %0
1586 Writes the current value of 64-bit MMX Register #7 (MM7).
1588 Writes the current value of MM7. This function is only available on IA32 and
1591 @param Value The 64-bit value to write to MM7.
1600 __asm__
__volatile__ (
1601 "movd %0, %%mm7" // %0
1609 Reads the current value of Time Stamp Counter (TSC).
1611 Reads and returns the current value of TSC. This function is only available
1614 @return The current value of TSC
1626 __asm__
__volatile__ (
1632 return (((UINT64
)HiData
) << 32) | LowData
;
1637 Reads the current value of a Performance Counter (PMC).
1639 Reads and returns the current value of performance counter specified by
1640 Index. This function is only available on IA-32 and X64.
1642 @param Index The 32-bit Performance Counter index to read.
1644 @return The value of the PMC specified by Index.
1656 __asm__
__volatile__ (
1663 return (((UINT64
)HiData
) << 32) | LowData
;
1668 Sets up a monitor buffer that is used by AsmMwait().
1670 Executes a MONITOR instruction with the register state specified by Eax, Ecx
1671 and Edx. Returns Eax. This function is only available on IA-32 and X64.
1673 @param Eax The value to load into EAX or RAX before executing the MONITOR
1675 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1677 @param Edx The value to load into EDX or RDX before executing the MONITOR
1691 __asm__
__volatile__ (
1704 Executes an MWAIT instruction.
1706 Executes an MWAIT instruction with the register state specified by Eax and
1707 Ecx. Returns Eax. This function is only available on IA-32 and X64.
1709 @param Eax The value to load into EAX or RAX before executing the MONITOR
1711 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1724 __asm__
__volatile__ (
1736 Executes a WBINVD instruction.
1738 Executes a WBINVD instruction. This function is only available on IA-32 and
1748 __asm__
__volatile__ ("wbinvd":::"memory");
1753 Executes a INVD instruction.
1755 Executes a INVD instruction. This function is only available on IA-32 and
1765 __asm__
__volatile__ ("invd":::"memory");
1771 Flushes a cache line from all the instruction and data caches within the
1772 coherency domain of the CPU.
1774 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1775 This function is only available on IA-32 and X64.
1777 @param LinearAddress The address of the cache line to flush. If the CPU is
1778 in a physical addressing mode, then LinearAddress is a
1779 physical address. If the CPU is in a virtual
1780 addressing mode, then LinearAddress is a virtual
1783 @return LinearAddress
1788 IN VOID
*LinearAddress
1791 __asm__
__volatile__ (
1794 : "r" (LinearAddress
)
1798 return LinearAddress
;