]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X64/GccInlinePriv.c
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
11 #include "BaseLibInternals.h"
12 #include <Library/RegisterFilterLib.h>
15 Enables CPU interrupts.
17 Enables CPU interrupts.
26 __asm__
__volatile__ ("sti"::: "memory");
30 Disables CPU interrupts.
32 Disables CPU interrupts.
41 __asm__
__volatile__ ("cli"::: "memory");
45 Returns a 64-bit Machine Specific Register(MSR).
47 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
48 performed on Index, and some Index values may cause CPU exceptions. The
49 caller must either guarantee that Index is valid, or the caller must set up
50 exception handlers to catch the exceptions. This function is only available
53 @param Index The 32-bit MSR index to read.
55 @return The value of the MSR identified by Index.
69 Flag
= FilterBeforeMsrRead (Index
, &Value
);
71 __asm__
__volatile__ (
73 : "=a" (LowData
), // %0
77 Value
= (((UINT64
)HighData
) << 32) | LowData
;
80 FilterAfterMsrRead (Index
, &Value
);
86 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
89 Writes the 64-bit value specified by Value to the MSR specified by Index. The
90 64-bit value written to the MSR is returned. No parameter checking is
91 performed on Index or Value, and some of these may cause CPU exceptions. The
92 caller must either guarantee that Index and Value are valid, or the caller
93 must establish proper exception handlers. This function is only available on
96 @param Index The 32-bit MSR index to write.
97 @param Value The 64-bit value to write to the MSR.
113 Flag
= FilterBeforeMsrWrite (Index
, &Value
);
115 LowData
= (UINT32
)(Value
);
116 HighData
= (UINT32
)(Value
>> 32);
117 __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__ (
158 Reads the current value of the Control Register 2 (CR2).
160 Reads and returns the current value of CR2. This function is only available
161 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
164 @return The value of the Control Register 2 (CR2).
175 __asm__
__volatile__ (
184 Reads the current value of the Control Register 3 (CR3).
186 Reads and returns the current value of CR3. This function is only available
187 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
190 @return The value of the Control Register 3 (CR3).
201 __asm__
__volatile__ (
210 Reads the current value of the Control Register 4 (CR4).
212 Reads and returns the current value of CR4. This function is only available
213 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
216 @return The value of the Control Register 4 (CR4).
227 __asm__
__volatile__ (
236 Writes a value to Control Register 0 (CR0).
238 Writes and returns a new value to CR0. This function is only available on
239 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
241 @param Cr0 The value to write to CR0.
243 @return The value written to CR0.
252 __asm__
__volatile__ (
261 Writes a value to Control Register 2 (CR2).
263 Writes and returns a new value to CR2. This function is only available on
264 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
266 @param Cr2 The value to write to CR2.
268 @return The value written to CR2.
277 __asm__
__volatile__ (
286 Writes a value to Control Register 3 (CR3).
288 Writes and returns a new value to CR3. This function is only available on
289 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
291 @param Cr3 The value to write to CR3.
293 @return The value written to CR3.
302 __asm__
__volatile__ (
311 Writes a value to Control Register 4 (CR4).
313 Writes and returns a new value to CR4. This function is only available on
314 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
316 @param Cr4 The value to write to CR4.
318 @return The value written to CR4.
327 __asm__
__volatile__ (
336 Reads the current value of Debug Register 0 (DR0).
338 Reads and returns the current value of DR0. This function is only available
339 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
342 @return The value of Debug Register 0 (DR0).
353 __asm__
__volatile__ (
362 Reads the current value of Debug Register 1 (DR1).
364 Reads and returns the current value of DR1. This function is only available
365 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
368 @return The value of Debug Register 1 (DR1).
379 __asm__
__volatile__ (
388 Reads the current value of Debug Register 2 (DR2).
390 Reads and returns the current value of DR2. This function is only available
391 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
394 @return The value of Debug Register 2 (DR2).
405 __asm__
__volatile__ (
414 Reads the current value of Debug Register 3 (DR3).
416 Reads and returns the current value of DR3. This function is only available
417 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
420 @return The value of Debug Register 3 (DR3).
431 __asm__
__volatile__ (
440 Reads the current value of Debug Register 4 (DR4).
442 Reads and returns the current value of DR4. This function is only available
443 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
446 @return The value of Debug Register 4 (DR4).
457 __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__ (
492 Reads the current value of Debug Register 6 (DR6).
494 Reads and returns the current value of DR6. This function is only available
495 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
498 @return The value of Debug Register 6 (DR6).
509 __asm__
__volatile__ (
518 Reads the current value of Debug Register 7 (DR7).
520 Reads and returns the current value of DR7. This function is only available
521 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
524 @return The value of Debug Register 7 (DR7).
535 __asm__
__volatile__ (
544 Writes a value to Debug Register 0 (DR0).
546 Writes and returns a new value to DR0. This function is only available on
547 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
549 @param Dr0 The value to write to Dr0.
551 @return The value written to Debug Register 0 (DR0).
560 __asm__
__volatile__ (
569 Writes a value to Debug Register 1 (DR1).
571 Writes and returns a new value to DR1. This function is only available on
572 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
574 @param Dr1 The value to write to Dr1.
576 @return The value written to Debug Register 1 (DR1).
585 __asm__
__volatile__ (
594 Writes a value to Debug Register 2 (DR2).
596 Writes and returns a new value to DR2. This function is only available on
597 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
599 @param Dr2 The value to write to Dr2.
601 @return The value written to Debug Register 2 (DR2).
610 __asm__
__volatile__ (
619 Writes a value to Debug Register 3 (DR3).
621 Writes and returns a new value to DR3. This function is only available on
622 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
624 @param Dr3 The value to write to Dr3.
626 @return The value written to Debug Register 3 (DR3).
635 __asm__
__volatile__ (
644 Writes a value to Debug Register 4 (DR4).
646 Writes and returns a new value to DR4. This function is only available on
647 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
649 @param Dr4 The value to write to Dr4.
651 @return The value written to Debug Register 4 (DR4).
660 __asm__
__volatile__ (
669 Writes a value to Debug Register 5 (DR5).
671 Writes and returns a new value to DR5. This function is only available on
672 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
674 @param Dr5 The value to write to Dr5.
676 @return The value written to Debug Register 5 (DR5).
685 __asm__
__volatile__ (
694 Writes a value to Debug Register 6 (DR6).
696 Writes and returns a new value to DR6. This function is only available on
697 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
699 @param Dr6 The value to write to Dr6.
701 @return The value written to Debug Register 6 (DR6).
710 __asm__
__volatile__ (
719 Writes a value to Debug Register 7 (DR7).
721 Writes and returns a new value to DR7. This function is only available on
722 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
724 @param Dr7 The value to write to Dr7.
726 @return The value written to Debug Register 7 (DR7).
735 __asm__
__volatile__ (
744 Reads the current value of Code Segment Register (CS).
746 Reads and returns the current value of CS. This function is only available on
749 @return The current value of CS.
760 __asm__
__volatile__ (
769 Reads the current value of Data Segment Register (DS).
771 Reads and returns the current value of DS. This function is only available on
774 @return The current value of DS.
785 __asm__
__volatile__ (
794 Reads the current value of Extra Segment Register (ES).
796 Reads and returns the current value of ES. This function is only available on
799 @return The current value of ES.
810 __asm__
__volatile__ (
819 Reads the current value of FS Data Segment Register (FS).
821 Reads and returns the current value of FS. This function is only available on
824 @return The current value of FS.
835 __asm__
__volatile__ (
844 Reads the current value of GS Data Segment Register (GS).
846 Reads and returns the current value of GS. This function is only available on
849 @return The current value of GS.
860 __asm__
__volatile__ (
869 Reads the current value of Stack Segment Register (SS).
871 Reads and returns the current value of SS. This function is only available on
874 @return The current value of SS.
885 __asm__
__volatile__ (
894 Reads the current value of Task Register (TR).
896 Reads and returns the current value of TR. This function is only available on
899 @return The current value of TR.
910 __asm__
__volatile__ (
919 Reads the current Global Descriptor Table Register(GDTR) descriptor.
921 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
922 function is only available on IA-32 and X64.
924 @param Gdtr The pointer to a GDTR descriptor.
929 InternalX86ReadGdtr (
930 OUT IA32_DESCRIPTOR
*Gdtr
933 __asm__
__volatile__ (
940 Writes the current Global Descriptor Table Register (GDTR) descriptor.
942 Writes and the current GDTR descriptor specified by Gdtr. This function is
943 only available on IA-32 and X64.
945 @param Gdtr The pointer to a GDTR descriptor.
950 InternalX86WriteGdtr (
951 IN CONST IA32_DESCRIPTOR
*Gdtr
954 __asm__
__volatile__ (
962 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
964 Reads and returns the current IDTR descriptor and returns it in Idtr. This
965 function is only available on IA-32 and X64.
967 @param Idtr The pointer to a IDTR descriptor.
972 InternalX86ReadIdtr (
973 OUT IA32_DESCRIPTOR
*Idtr
976 __asm__
__volatile__ (
983 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
985 Writes the current IDTR descriptor and returns it in Idtr. This function is
986 only available on IA-32 and X64.
988 @param Idtr The pointer to a IDTR descriptor.
993 InternalX86WriteIdtr (
994 IN CONST IA32_DESCRIPTOR
*Idtr
997 __asm__
__volatile__ (
1005 Reads the current Local Descriptor Table Register(LDTR) selector.
1007 Reads and returns the current 16-bit LDTR descriptor value. This function is
1008 only available on IA-32 and X64.
1010 @return The current selector of LDT.
1021 __asm__
__volatile__ (
1030 Writes the current Local Descriptor Table Register (GDTR) selector.
1032 Writes and the current LDTR descriptor specified by Ldtr. This function is
1033 only available on IA-32 and X64.
1035 @param Ldtr 16-bit LDTR selector value.
1044 __asm__
__volatile__ (
1052 Reads the current value of a Performance Counter (PMC).
1054 Reads and returns the current value of performance counter specified by
1055 Index. This function is only available on IA-32 and X64.
1057 @param Index The 32-bit Performance Counter index to read.
1059 @return The value of the PMC specified by Index.
1071 __asm__
__volatile__ (
1078 return (((UINT64
)HiData
) << 32) | LowData
;
1082 Sets up a monitor buffer that is used by AsmMwait().
1084 Executes a MONITOR instruction with the register state specified by Eax, Ecx
1085 and Edx. Returns Eax. This function is only available on IA-32 and X64.
1087 @param Eax The value to load into EAX or RAX before executing the MONITOR
1089 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1091 @param Edx The value to load into EDX or RDX before executing the MONITOR
1105 __asm__
__volatile__ (
1117 Executes an MWAIT instruction.
1119 Executes an MWAIT instruction with the register state specified by Eax and
1120 Ecx. Returns Eax. This function is only available on IA-32 and X64.
1122 @param Eax The value to load into EAX or RAX before executing the MONITOR
1124 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1137 __asm__
__volatile__ (
1148 Executes a WBINVD instruction.
1150 Executes a WBINVD instruction. This function is only available on IA-32 and
1160 __asm__
__volatile__ ("wbinvd":::"memory");
1164 Executes a INVD instruction.
1166 Executes a INVD instruction. This function is only available on IA-32 and
1176 __asm__
__volatile__ ("invd":::"memory");
1180 Flushes a cache line from all the instruction and data caches within the
1181 coherency domain of the CPU.
1183 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1184 This function is only available on IA-32 and X64.
1186 @param LinearAddress The address of the cache line to flush. If the CPU is
1187 in a physical addressing mode, then LinearAddress is a
1188 physical address. If the CPU is in a virtual
1189 addressing mode, then LinearAddress is a virtual
1192 @return LinearAddress
1197 IN VOID
*LinearAddress
1200 __asm__
__volatile__ (
1203 : "r" (LinearAddress
)
1207 return LinearAddress
;