]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X64/GccInlinePriv.c
98be19b3c7b7962fb93f7662f5097a1de3ae9db8
2 GCC inline implementation of BaseLib processor specific functions that use
3 privlidged instructions.
5 Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
6 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include "BaseLibInternals.h"
15 Enables CPU interrupts.
17 Enables CPU interrupts.
26 __asm__
__volatile__ ("sti"::: "memory");
31 Disables CPU interrupts.
33 Disables CPU interrupts.
42 __asm__
__volatile__ ("cli"::: "memory");
46 Returns a 64-bit Machine Specific Register(MSR).
48 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
49 performed on Index, and some Index values may cause CPU exceptions. The
50 caller must either guarantee that Index is valid, or the caller must set up
51 exception handlers to catch the exceptions. This function is only available
54 @param Index The 32-bit MSR index to read.
56 @return The value of the MSR identified by Index.
68 __asm__
__volatile__ (
70 : "=a" (LowData
), // %0
75 return (((UINT64
)HighData
) << 32) | LowData
;
79 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
82 Writes the 64-bit value specified by Value to the MSR specified by Index. The
83 64-bit value written to the MSR is returned. No parameter checking is
84 performed on Index or Value, and some of these may cause CPU exceptions. The
85 caller must either guarantee that Index and Value are valid, or the caller
86 must establish proper exception handlers. This function is only available on
89 @param Index The 32-bit MSR index to write.
90 @param Value The 64-bit value to write to the MSR.
105 LowData
= (UINT32
)(Value
);
106 HighData
= (UINT32
)(Value
>> 32);
108 __asm__
__volatile__ (
120 Reads the current value of the Control Register 0 (CR0).
122 Reads and returns the current value of CR0. This function is only available
123 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
126 @return The value of the Control Register 0 (CR0).
137 __asm__
__volatile__ (
147 Reads the current value of the Control Register 2 (CR2).
149 Reads and returns the current value of CR2. This function is only available
150 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
153 @return The value of the Control Register 2 (CR2).
164 __asm__
__volatile__ (
173 Reads the current value of the Control Register 3 (CR3).
175 Reads and returns the current value of CR3. This function is only available
176 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
179 @return The value of the Control Register 3 (CR3).
190 __asm__
__volatile__ (
200 Reads the current value of the Control Register 4 (CR4).
202 Reads and returns the current value of CR4. This function is only available
203 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
206 @return The value of the Control Register 4 (CR4).
217 __asm__
__volatile__ (
227 Writes a value to Control Register 0 (CR0).
229 Writes and returns a new value to CR0. This function is only available on
230 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
232 @param Cr0 The value to write to CR0.
234 @return The value written to CR0.
243 __asm__
__volatile__ (
253 Writes a value to Control Register 2 (CR2).
255 Writes and returns a new value to CR2. This function is only available on
256 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
258 @param Cr2 The value to write to CR2.
260 @return The value written to CR2.
269 __asm__
__volatile__ (
279 Writes a value to Control Register 3 (CR3).
281 Writes and returns a new value to CR3. This function is only available on
282 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
284 @param Cr3 The value to write to CR3.
286 @return The value written to CR3.
295 __asm__
__volatile__ (
305 Writes a value to Control Register 4 (CR4).
307 Writes and returns a new value to CR4. This function is only available on
308 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
310 @param Cr4 The value to write to CR4.
312 @return The value written to CR4.
321 __asm__
__volatile__ (
331 Reads the current value of Debug Register 0 (DR0).
333 Reads and returns the current value of DR0. This function is only available
334 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
337 @return The value of Debug Register 0 (DR0).
348 __asm__
__volatile__ (
358 Reads the current value of Debug Register 1 (DR1).
360 Reads and returns the current value of DR1. This function is only available
361 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
364 @return The value of Debug Register 1 (DR1).
375 __asm__
__volatile__ (
385 Reads the current value of Debug Register 2 (DR2).
387 Reads and returns the current value of DR2. This function is only available
388 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
391 @return The value of Debug Register 2 (DR2).
402 __asm__
__volatile__ (
412 Reads the current value of Debug Register 3 (DR3).
414 Reads and returns the current value of DR3. This function is only available
415 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
418 @return The value of Debug Register 3 (DR3).
429 __asm__
__volatile__ (
439 Reads the current value of Debug Register 4 (DR4).
441 Reads and returns the current value of DR4. This function is only available
442 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
445 @return The value of Debug Register 4 (DR4).
456 __asm__
__volatile__ (
466 Reads the current value of Debug Register 5 (DR5).
468 Reads and returns the current value of DR5. This function is only available
469 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
472 @return The value of Debug Register 5 (DR5).
483 __asm__
__volatile__ (
493 Reads the current value of Debug Register 6 (DR6).
495 Reads and returns the current value of DR6. This function is only available
496 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
499 @return The value of Debug Register 6 (DR6).
510 __asm__
__volatile__ (
520 Reads the current value of Debug Register 7 (DR7).
522 Reads and returns the current value of DR7. This function is only available
523 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
526 @return The value of Debug Register 7 (DR7).
537 __asm__
__volatile__ (
547 Writes a value to Debug Register 0 (DR0).
549 Writes and returns a new value to DR0. This function is only available on
550 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
552 @param Dr0 The value to write to Dr0.
554 @return The value written to Debug Register 0 (DR0).
563 __asm__
__volatile__ (
573 Writes a value to Debug Register 1 (DR1).
575 Writes and returns a new value to DR1. This function is only available on
576 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
578 @param Dr1 The value to write to Dr1.
580 @return The value written to Debug Register 1 (DR1).
589 __asm__
__volatile__ (
599 Writes a value to Debug Register 2 (DR2).
601 Writes and returns a new value to DR2. This function is only available on
602 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
604 @param Dr2 The value to write to Dr2.
606 @return The value written to Debug Register 2 (DR2).
615 __asm__
__volatile__ (
625 Writes a value to Debug Register 3 (DR3).
627 Writes and returns a new value to DR3. This function is only available on
628 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
630 @param Dr3 The value to write to Dr3.
632 @return The value written to Debug Register 3 (DR3).
641 __asm__
__volatile__ (
651 Writes a value to Debug Register 4 (DR4).
653 Writes and returns a new value to DR4. This function is only available on
654 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
656 @param Dr4 The value to write to Dr4.
658 @return The value written to Debug Register 4 (DR4).
667 __asm__
__volatile__ (
677 Writes a value to Debug Register 5 (DR5).
679 Writes and returns a new value to DR5. This function is only available on
680 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
682 @param Dr5 The value to write to Dr5.
684 @return The value written to Debug Register 5 (DR5).
693 __asm__
__volatile__ (
703 Writes a value to Debug Register 6 (DR6).
705 Writes and returns a new value to DR6. This function is only available on
706 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
708 @param Dr6 The value to write to Dr6.
710 @return The value written to Debug Register 6 (DR6).
719 __asm__
__volatile__ (
729 Writes a value to Debug Register 7 (DR7).
731 Writes and returns a new value to DR7. This function is only available on
732 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
734 @param Dr7 The value to write to Dr7.
736 @return The value written to Debug Register 7 (DR7).
745 __asm__
__volatile__ (
755 Reads the current value of Code Segment Register (CS).
757 Reads and returns the current value of CS. This function is only available on
760 @return The current value of CS.
771 __asm__
__volatile__ (
781 Reads the current value of Data Segment Register (DS).
783 Reads and returns the current value of DS. This function is only available on
786 @return The current value of DS.
797 __asm__
__volatile__ (
807 Reads the current value of Extra Segment Register (ES).
809 Reads and returns the current value of ES. This function is only available on
812 @return The current value of ES.
823 __asm__
__volatile__ (
833 Reads the current value of FS Data Segment Register (FS).
835 Reads and returns the current value of FS. This function is only available on
838 @return The current value of FS.
849 __asm__
__volatile__ (
859 Reads the current value of GS Data Segment Register (GS).
861 Reads and returns the current value of GS. This function is only available on
864 @return The current value of GS.
875 __asm__
__volatile__ (
885 Reads the current value of Stack Segment Register (SS).
887 Reads and returns the current value of SS. This function is only available on
890 @return The current value of SS.
901 __asm__
__volatile__ (
911 Reads the current value of Task Register (TR).
913 Reads and returns the current value of TR. This function is only available on
916 @return The current value of TR.
927 __asm__
__volatile__ (
937 Reads the current Global Descriptor Table Register(GDTR) descriptor.
939 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
940 function is only available on IA-32 and X64.
942 @param Gdtr The pointer to a GDTR descriptor.
947 InternalX86ReadGdtr (
948 OUT IA32_DESCRIPTOR
*Gdtr
951 __asm__
__volatile__ (
959 Writes the current Global Descriptor Table Register (GDTR) descriptor.
961 Writes and the current GDTR descriptor specified by Gdtr. This function is
962 only available on IA-32 and X64.
964 @param Gdtr The pointer to a GDTR descriptor.
969 InternalX86WriteGdtr (
970 IN CONST IA32_DESCRIPTOR
*Gdtr
973 __asm__
__volatile__ (
983 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
985 Reads and returns the current IDTR descriptor and returns it in Idtr. This
986 function is only available on IA-32 and X64.
988 @param Idtr The pointer to a IDTR descriptor.
993 InternalX86ReadIdtr (
994 OUT IA32_DESCRIPTOR
*Idtr
997 __asm__
__volatile__ (
1005 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
1007 Writes the current IDTR descriptor and returns it in Idtr. This function is
1008 only available on IA-32 and X64.
1010 @param Idtr The pointer to a IDTR descriptor.
1015 InternalX86WriteIdtr (
1016 IN CONST IA32_DESCRIPTOR
*Idtr
1019 __asm__
__volatile__ (
1028 Reads the current Local Descriptor Table Register(LDTR) selector.
1030 Reads and returns the current 16-bit LDTR descriptor value. This function is
1031 only available on IA-32 and X64.
1033 @return The current selector of LDT.
1044 __asm__
__volatile__ (
1054 Writes the current Local Descriptor Table Register (GDTR) selector.
1056 Writes and the current LDTR descriptor specified by Ldtr. This function is
1057 only available on IA-32 and X64.
1059 @param Ldtr 16-bit LDTR selector value.
1068 __asm__
__volatile__ (
1076 Reads the current value of a Performance Counter (PMC).
1078 Reads and returns the current value of performance counter specified by
1079 Index. This function is only available on IA-32 and X64.
1081 @param Index The 32-bit Performance Counter index to read.
1083 @return The value of the PMC specified by Index.
1095 __asm__
__volatile__ (
1102 return (((UINT64
)HiData
) << 32) | LowData
;
1106 Sets up a monitor buffer that is used by AsmMwait().
1108 Executes a MONITOR instruction with the register state specified by Eax, Ecx
1109 and Edx. Returns Eax. This function is only available on IA-32 and X64.
1111 @param Eax The value to load into EAX or RAX before executing the MONITOR
1113 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1115 @param Edx The value to load into EDX or RDX before executing the MONITOR
1129 __asm__
__volatile__ (
1141 Executes an MWAIT instruction.
1143 Executes an MWAIT instruction with the register state specified by Eax and
1144 Ecx. Returns Eax. This function is only available on IA-32 and X64.
1146 @param Eax The value to load into EAX or RAX before executing the MONITOR
1148 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1161 __asm__
__volatile__ (
1172 Executes a WBINVD instruction.
1174 Executes a WBINVD instruction. This function is only available on IA-32 and
1184 __asm__
__volatile__ ("wbinvd":::"memory");
1188 Executes a INVD instruction.
1190 Executes a INVD instruction. This function is only available on IA-32 and
1200 __asm__
__volatile__ ("invd":::"memory");
1206 Flushes a cache line from all the instruction and data caches within the
1207 coherency domain of the CPU.
1209 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1210 This function is only available on IA-32 and X64.
1212 @param LinearAddress The address of the cache line to flush. If the CPU is
1213 in a physical addressing mode, then LinearAddress is a
1214 physical address. If the CPU is in a virtual
1215 addressing mode, then LinearAddress is a virtual
1218 @return LinearAddress
1223 IN VOID
*LinearAddress
1226 __asm__
__volatile__ (
1229 : "r" (LinearAddress
)
1233 return LinearAddress
;