]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X64/GccInlinePriv.c
244bd62ee67fbd79c0e393186593f514f76c7d17
2 GCC inline implementation of BaseLib processor specific functions that use
3 privlidged instructions.
5 Copyright (c) 2006 - 2021, 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"
13 #include <Library/RegisterFilterLib.h>
16 Enables CPU interrupts.
18 Enables CPU interrupts.
27 __asm__
__volatile__ ("sti"::: "memory");
32 Disables CPU interrupts.
34 Disables CPU interrupts.
43 __asm__
__volatile__ ("cli"::: "memory");
47 Returns a 64-bit Machine Specific Register(MSR).
49 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
50 performed on Index, and some Index values may cause CPU exceptions. The
51 caller must either guarantee that Index is valid, or the caller must set up
52 exception handlers to catch the exceptions. This function is only available
55 @param Index The 32-bit MSR index to read.
57 @return The value of the MSR identified by Index.
71 Flag
= FilterBeforeMsrRead (Index
, &Value
);
73 __asm__
__volatile__ (
75 : "=a" (LowData
), // %0
79 Value
= (((UINT64
)HighData
) << 32) | LowData
;
81 FilterAfterMsrRead (Index
, &Value
);
87 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
90 Writes the 64-bit value specified by Value to the MSR specified by Index. The
91 64-bit value written to the MSR is returned. No parameter checking is
92 performed on Index or Value, and some of these may cause CPU exceptions. The
93 caller must either guarantee that Index and Value are valid, or the caller
94 must establish proper exception handlers. This function is only available on
97 @param Index The 32-bit MSR index to write.
98 @param Value The 64-bit value to write to the MSR.
114 Flag
= FilterBeforeMsrWrite (Index
, &Value
);
116 LowData
= (UINT32
)(Value
);
117 HighData
= (UINT32
)(Value
>> 32);
118 __asm__
__volatile__ (
126 FilterAfterMsrWrite (Index
, &Value
);
132 Reads the current value of the Control Register 0 (CR0).
134 Reads and returns the current value of CR0. This function is only available
135 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
138 @return The value of the Control Register 0 (CR0).
149 __asm__
__volatile__ (
159 Reads the current value of the Control Register 2 (CR2).
161 Reads and returns the current value of CR2. This function is only available
162 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
165 @return The value of the Control Register 2 (CR2).
176 __asm__
__volatile__ (
185 Reads the current value of the Control Register 3 (CR3).
187 Reads and returns the current value of CR3. This function is only available
188 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
191 @return The value of the Control Register 3 (CR3).
202 __asm__
__volatile__ (
212 Reads the current value of the Control Register 4 (CR4).
214 Reads and returns the current value of CR4. This function is only available
215 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
218 @return The value of the Control Register 4 (CR4).
229 __asm__
__volatile__ (
239 Writes a value to Control Register 0 (CR0).
241 Writes and returns a new value to CR0. This function is only available on
242 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
244 @param Cr0 The value to write to CR0.
246 @return The value written to CR0.
255 __asm__
__volatile__ (
265 Writes a value to Control Register 2 (CR2).
267 Writes and returns a new value to CR2. This function is only available on
268 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
270 @param Cr2 The value to write to CR2.
272 @return The value written to CR2.
281 __asm__
__volatile__ (
291 Writes a value to Control Register 3 (CR3).
293 Writes and returns a new value to CR3. This function is only available on
294 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
296 @param Cr3 The value to write to CR3.
298 @return The value written to CR3.
307 __asm__
__volatile__ (
317 Writes a value to Control Register 4 (CR4).
319 Writes and returns a new value to CR4. This function is only available on
320 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
322 @param Cr4 The value to write to CR4.
324 @return The value written to CR4.
333 __asm__
__volatile__ (
343 Reads the current value of Debug Register 0 (DR0).
345 Reads and returns the current value of DR0. This function is only available
346 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
349 @return The value of Debug Register 0 (DR0).
360 __asm__
__volatile__ (
370 Reads the current value of Debug Register 1 (DR1).
372 Reads and returns the current value of DR1. This function is only available
373 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
376 @return The value of Debug Register 1 (DR1).
387 __asm__
__volatile__ (
397 Reads the current value of Debug Register 2 (DR2).
399 Reads and returns the current value of DR2. This function is only available
400 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
403 @return The value of Debug Register 2 (DR2).
414 __asm__
__volatile__ (
424 Reads the current value of Debug Register 3 (DR3).
426 Reads and returns the current value of DR3. This function is only available
427 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
430 @return The value of Debug Register 3 (DR3).
441 __asm__
__volatile__ (
451 Reads the current value of Debug Register 4 (DR4).
453 Reads and returns the current value of DR4. This function is only available
454 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
457 @return The value of Debug Register 4 (DR4).
468 __asm__
__volatile__ (
478 Reads the current value of Debug Register 5 (DR5).
480 Reads and returns the current value of DR5. This function is only available
481 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
484 @return The value of Debug Register 5 (DR5).
495 __asm__
__volatile__ (
505 Reads the current value of Debug Register 6 (DR6).
507 Reads and returns the current value of DR6. This function is only available
508 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
511 @return The value of Debug Register 6 (DR6).
522 __asm__
__volatile__ (
532 Reads the current value of Debug Register 7 (DR7).
534 Reads and returns the current value of DR7. This function is only available
535 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
538 @return The value of Debug Register 7 (DR7).
549 __asm__
__volatile__ (
559 Writes a value to Debug Register 0 (DR0).
561 Writes and returns a new value to DR0. This function is only available on
562 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
564 @param Dr0 The value to write to Dr0.
566 @return The value written to Debug Register 0 (DR0).
575 __asm__
__volatile__ (
585 Writes a value to Debug Register 1 (DR1).
587 Writes and returns a new value to DR1. This function is only available on
588 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
590 @param Dr1 The value to write to Dr1.
592 @return The value written to Debug Register 1 (DR1).
601 __asm__
__volatile__ (
611 Writes a value to Debug Register 2 (DR2).
613 Writes and returns a new value to DR2. This function is only available on
614 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
616 @param Dr2 The value to write to Dr2.
618 @return The value written to Debug Register 2 (DR2).
627 __asm__
__volatile__ (
637 Writes a value to Debug Register 3 (DR3).
639 Writes and returns a new value to DR3. This function is only available on
640 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
642 @param Dr3 The value to write to Dr3.
644 @return The value written to Debug Register 3 (DR3).
653 __asm__
__volatile__ (
663 Writes a value to Debug Register 4 (DR4).
665 Writes and returns a new value to DR4. This function is only available on
666 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
668 @param Dr4 The value to write to Dr4.
670 @return The value written to Debug Register 4 (DR4).
679 __asm__
__volatile__ (
689 Writes a value to Debug Register 5 (DR5).
691 Writes and returns a new value to DR5. This function is only available on
692 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
694 @param Dr5 The value to write to Dr5.
696 @return The value written to Debug Register 5 (DR5).
705 __asm__
__volatile__ (
715 Writes a value to Debug Register 6 (DR6).
717 Writes and returns a new value to DR6. This function is only available on
718 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
720 @param Dr6 The value to write to Dr6.
722 @return The value written to Debug Register 6 (DR6).
731 __asm__
__volatile__ (
741 Writes a value to Debug Register 7 (DR7).
743 Writes and returns a new value to DR7. This function is only available on
744 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
746 @param Dr7 The value to write to Dr7.
748 @return The value written to Debug Register 7 (DR7).
757 __asm__
__volatile__ (
767 Reads the current value of Code Segment Register (CS).
769 Reads and returns the current value of CS. This function is only available on
772 @return The current value of CS.
783 __asm__
__volatile__ (
793 Reads the current value of Data Segment Register (DS).
795 Reads and returns the current value of DS. This function is only available on
798 @return The current value of DS.
809 __asm__
__volatile__ (
819 Reads the current value of Extra Segment Register (ES).
821 Reads and returns the current value of ES. This function is only available on
824 @return The current value of ES.
835 __asm__
__volatile__ (
845 Reads the current value of FS Data Segment Register (FS).
847 Reads and returns the current value of FS. This function is only available on
850 @return The current value of FS.
861 __asm__
__volatile__ (
871 Reads the current value of GS Data Segment Register (GS).
873 Reads and returns the current value of GS. This function is only available on
876 @return The current value of GS.
887 __asm__
__volatile__ (
897 Reads the current value of Stack Segment Register (SS).
899 Reads and returns the current value of SS. This function is only available on
902 @return The current value of SS.
913 __asm__
__volatile__ (
923 Reads the current value of Task Register (TR).
925 Reads and returns the current value of TR. This function is only available on
928 @return The current value of TR.
939 __asm__
__volatile__ (
949 Reads the current Global Descriptor Table Register(GDTR) descriptor.
951 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
952 function is only available on IA-32 and X64.
954 @param Gdtr The pointer to a GDTR descriptor.
959 InternalX86ReadGdtr (
960 OUT IA32_DESCRIPTOR
*Gdtr
963 __asm__
__volatile__ (
971 Writes the current Global Descriptor Table Register (GDTR) descriptor.
973 Writes and the current GDTR descriptor specified by Gdtr. This function is
974 only available on IA-32 and X64.
976 @param Gdtr The pointer to a GDTR descriptor.
981 InternalX86WriteGdtr (
982 IN CONST IA32_DESCRIPTOR
*Gdtr
985 __asm__
__volatile__ (
995 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
997 Reads and returns the current IDTR descriptor and returns it in Idtr. This
998 function is only available on IA-32 and X64.
1000 @param Idtr The pointer to a IDTR descriptor.
1005 InternalX86ReadIdtr (
1006 OUT IA32_DESCRIPTOR
*Idtr
1009 __asm__
__volatile__ (
1017 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
1019 Writes the current IDTR descriptor and returns it in Idtr. This function is
1020 only available on IA-32 and X64.
1022 @param Idtr The pointer to a IDTR descriptor.
1027 InternalX86WriteIdtr (
1028 IN CONST IA32_DESCRIPTOR
*Idtr
1031 __asm__
__volatile__ (
1040 Reads the current Local Descriptor Table Register(LDTR) selector.
1042 Reads and returns the current 16-bit LDTR descriptor value. This function is
1043 only available on IA-32 and X64.
1045 @return The current selector of LDT.
1056 __asm__
__volatile__ (
1066 Writes the current Local Descriptor Table Register (GDTR) selector.
1068 Writes and the current LDTR descriptor specified by Ldtr. This function is
1069 only available on IA-32 and X64.
1071 @param Ldtr 16-bit LDTR selector value.
1080 __asm__
__volatile__ (
1088 Reads the current value of a Performance Counter (PMC).
1090 Reads and returns the current value of performance counter specified by
1091 Index. This function is only available on IA-32 and X64.
1093 @param Index The 32-bit Performance Counter index to read.
1095 @return The value of the PMC specified by Index.
1107 __asm__
__volatile__ (
1114 return (((UINT64
)HiData
) << 32) | LowData
;
1118 Sets up a monitor buffer that is used by AsmMwait().
1120 Executes a MONITOR instruction with the register state specified by Eax, Ecx
1121 and Edx. Returns Eax. This function is only available on IA-32 and X64.
1123 @param Eax The value to load into EAX or RAX before executing the MONITOR
1125 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1127 @param Edx The value to load into EDX or RDX before executing the MONITOR
1141 __asm__
__volatile__ (
1153 Executes an MWAIT instruction.
1155 Executes an MWAIT instruction with the register state specified by Eax and
1156 Ecx. Returns Eax. This function is only available on IA-32 and X64.
1158 @param Eax The value to load into EAX or RAX before executing the MONITOR
1160 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1173 __asm__
__volatile__ (
1184 Executes a WBINVD instruction.
1186 Executes a WBINVD instruction. This function is only available on IA-32 and
1196 __asm__
__volatile__ ("wbinvd":::"memory");
1200 Executes a INVD instruction.
1202 Executes a INVD instruction. This function is only available on IA-32 and
1212 __asm__
__volatile__ ("invd":::"memory");
1218 Flushes a cache line from all the instruction and data caches within the
1219 coherency domain of the CPU.
1221 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1222 This function is only available on IA-32 and X64.
1224 @param LinearAddress The address of the cache line to flush. If the CPU is
1225 in a physical addressing mode, then LinearAddress is a
1226 physical address. If the CPU is in a virtual
1227 addressing mode, then LinearAddress is a virtual
1230 @return LinearAddress
1235 IN VOID
*LinearAddress
1238 __asm__
__volatile__ (
1241 : "r" (LinearAddress
)
1245 return LinearAddress
;