]>
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
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
);
83 return (((UINT64
)HighData
) << 32) | LowData
;
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 LowData
= (UINT32
)(Value
);
115 HighData
= (UINT32
)(Value
>> 32);
117 Flag
= FilterBeforeMsrWrite (Index
, &Value
);
119 __asm__
__volatile__ (
127 FilterAfterMsrWrite (Index
, &Value
);
133 Reads the current value of the Control Register 0 (CR0).
135 Reads and returns the current value of CR0. This function is only available
136 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
139 @return The value of the Control Register 0 (CR0).
150 __asm__
__volatile__ (
160 Reads the current value of the Control Register 2 (CR2).
162 Reads and returns the current value of CR2. This function is only available
163 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
166 @return The value of the Control Register 2 (CR2).
177 __asm__
__volatile__ (
186 Reads the current value of the Control Register 3 (CR3).
188 Reads and returns the current value of CR3. This function is only available
189 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
192 @return The value of the Control Register 3 (CR3).
203 __asm__
__volatile__ (
213 Reads the current value of the Control Register 4 (CR4).
215 Reads and returns the current value of CR4. This function is only available
216 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
219 @return The value of the Control Register 4 (CR4).
230 __asm__
__volatile__ (
240 Writes a value to Control Register 0 (CR0).
242 Writes and returns a new value to CR0. This function is only available on
243 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
245 @param Cr0 The value to write to CR0.
247 @return The value written to CR0.
256 __asm__
__volatile__ (
266 Writes a value to Control Register 2 (CR2).
268 Writes and returns a new value to CR2. This function is only available on
269 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
271 @param Cr2 The value to write to CR2.
273 @return The value written to CR2.
282 __asm__
__volatile__ (
292 Writes a value to Control Register 3 (CR3).
294 Writes and returns a new value to CR3. This function is only available on
295 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
297 @param Cr3 The value to write to CR3.
299 @return The value written to CR3.
308 __asm__
__volatile__ (
318 Writes a value to Control Register 4 (CR4).
320 Writes and returns a new value to CR4. This function is only available on
321 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
323 @param Cr4 The value to write to CR4.
325 @return The value written to CR4.
334 __asm__
__volatile__ (
344 Reads the current value of Debug Register 0 (DR0).
346 Reads and returns the current value of DR0. This function is only available
347 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
350 @return The value of Debug Register 0 (DR0).
361 __asm__
__volatile__ (
371 Reads the current value of Debug Register 1 (DR1).
373 Reads and returns the current value of DR1. This function is only available
374 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
377 @return The value of Debug Register 1 (DR1).
388 __asm__
__volatile__ (
398 Reads the current value of Debug Register 2 (DR2).
400 Reads and returns the current value of DR2. This function is only available
401 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
404 @return The value of Debug Register 2 (DR2).
415 __asm__
__volatile__ (
425 Reads the current value of Debug Register 3 (DR3).
427 Reads and returns the current value of DR3. This function is only available
428 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
431 @return The value of Debug Register 3 (DR3).
442 __asm__
__volatile__ (
452 Reads the current value of Debug Register 4 (DR4).
454 Reads and returns the current value of DR4. This function is only available
455 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
458 @return The value of Debug Register 4 (DR4).
469 __asm__
__volatile__ (
479 Reads the current value of Debug Register 5 (DR5).
481 Reads and returns the current value of DR5. This function is only available
482 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
485 @return The value of Debug Register 5 (DR5).
496 __asm__
__volatile__ (
506 Reads the current value of Debug Register 6 (DR6).
508 Reads and returns the current value of DR6. This function is only available
509 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
512 @return The value of Debug Register 6 (DR6).
523 __asm__
__volatile__ (
533 Reads the current value of Debug Register 7 (DR7).
535 Reads and returns the current value of DR7. This function is only available
536 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
539 @return The value of Debug Register 7 (DR7).
550 __asm__
__volatile__ (
560 Writes a value to Debug Register 0 (DR0).
562 Writes and returns a new value to DR0. This function is only available on
563 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
565 @param Dr0 The value to write to Dr0.
567 @return The value written to Debug Register 0 (DR0).
576 __asm__
__volatile__ (
586 Writes a value to Debug Register 1 (DR1).
588 Writes and returns a new value to DR1. This function is only available on
589 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
591 @param Dr1 The value to write to Dr1.
593 @return The value written to Debug Register 1 (DR1).
602 __asm__
__volatile__ (
612 Writes a value to Debug Register 2 (DR2).
614 Writes and returns a new value to DR2. This function is only available on
615 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
617 @param Dr2 The value to write to Dr2.
619 @return The value written to Debug Register 2 (DR2).
628 __asm__
__volatile__ (
638 Writes a value to Debug Register 3 (DR3).
640 Writes and returns a new value to DR3. This function is only available on
641 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
643 @param Dr3 The value to write to Dr3.
645 @return The value written to Debug Register 3 (DR3).
654 __asm__
__volatile__ (
664 Writes a value to Debug Register 4 (DR4).
666 Writes and returns a new value to DR4. This function is only available on
667 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
669 @param Dr4 The value to write to Dr4.
671 @return The value written to Debug Register 4 (DR4).
680 __asm__
__volatile__ (
690 Writes a value to Debug Register 5 (DR5).
692 Writes and returns a new value to DR5. This function is only available on
693 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
695 @param Dr5 The value to write to Dr5.
697 @return The value written to Debug Register 5 (DR5).
706 __asm__
__volatile__ (
716 Writes a value to Debug Register 6 (DR6).
718 Writes and returns a new value to DR6. This function is only available on
719 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
721 @param Dr6 The value to write to Dr6.
723 @return The value written to Debug Register 6 (DR6).
732 __asm__
__volatile__ (
742 Writes a value to Debug Register 7 (DR7).
744 Writes and returns a new value to DR7. This function is only available on
745 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
747 @param Dr7 The value to write to Dr7.
749 @return The value written to Debug Register 7 (DR7).
758 __asm__
__volatile__ (
768 Reads the current value of Code Segment Register (CS).
770 Reads and returns the current value of CS. This function is only available on
773 @return The current value of CS.
784 __asm__
__volatile__ (
794 Reads the current value of Data Segment Register (DS).
796 Reads and returns the current value of DS. This function is only available on
799 @return The current value of DS.
810 __asm__
__volatile__ (
820 Reads the current value of Extra Segment Register (ES).
822 Reads and returns the current value of ES. This function is only available on
825 @return The current value of ES.
836 __asm__
__volatile__ (
846 Reads the current value of FS Data Segment Register (FS).
848 Reads and returns the current value of FS. This function is only available on
851 @return The current value of FS.
862 __asm__
__volatile__ (
872 Reads the current value of GS Data Segment Register (GS).
874 Reads and returns the current value of GS. This function is only available on
877 @return The current value of GS.
888 __asm__
__volatile__ (
898 Reads the current value of Stack Segment Register (SS).
900 Reads and returns the current value of SS. This function is only available on
903 @return The current value of SS.
914 __asm__
__volatile__ (
924 Reads the current value of Task Register (TR).
926 Reads and returns the current value of TR. This function is only available on
929 @return The current value of TR.
940 __asm__
__volatile__ (
950 Reads the current Global Descriptor Table Register(GDTR) descriptor.
952 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
953 function is only available on IA-32 and X64.
955 @param Gdtr The pointer to a GDTR descriptor.
960 InternalX86ReadGdtr (
961 OUT IA32_DESCRIPTOR
*Gdtr
964 __asm__
__volatile__ (
972 Writes the current Global Descriptor Table Register (GDTR) descriptor.
974 Writes and the current GDTR descriptor specified by Gdtr. This function is
975 only available on IA-32 and X64.
977 @param Gdtr The pointer to a GDTR descriptor.
982 InternalX86WriteGdtr (
983 IN CONST IA32_DESCRIPTOR
*Gdtr
986 __asm__
__volatile__ (
996 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
998 Reads and returns the current IDTR descriptor and returns it in Idtr. This
999 function is only available on IA-32 and X64.
1001 @param Idtr The pointer to a IDTR descriptor.
1006 InternalX86ReadIdtr (
1007 OUT IA32_DESCRIPTOR
*Idtr
1010 __asm__
__volatile__ (
1018 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
1020 Writes the current IDTR descriptor and returns it in Idtr. This function is
1021 only available on IA-32 and X64.
1023 @param Idtr The pointer to a IDTR descriptor.
1028 InternalX86WriteIdtr (
1029 IN CONST IA32_DESCRIPTOR
*Idtr
1032 __asm__
__volatile__ (
1041 Reads the current Local Descriptor Table Register(LDTR) selector.
1043 Reads and returns the current 16-bit LDTR descriptor value. This function is
1044 only available on IA-32 and X64.
1046 @return The current selector of LDT.
1057 __asm__
__volatile__ (
1067 Writes the current Local Descriptor Table Register (GDTR) selector.
1069 Writes and the current LDTR descriptor specified by Ldtr. This function is
1070 only available on IA-32 and X64.
1072 @param Ldtr 16-bit LDTR selector value.
1081 __asm__
__volatile__ (
1089 Reads the current value of a Performance Counter (PMC).
1091 Reads and returns the current value of performance counter specified by
1092 Index. This function is only available on IA-32 and X64.
1094 @param Index The 32-bit Performance Counter index to read.
1096 @return The value of the PMC specified by Index.
1108 __asm__
__volatile__ (
1115 return (((UINT64
)HiData
) << 32) | LowData
;
1119 Sets up a monitor buffer that is used by AsmMwait().
1121 Executes a MONITOR instruction with the register state specified by Eax, Ecx
1122 and Edx. Returns Eax. This function is only available on IA-32 and X64.
1124 @param Eax The value to load into EAX or RAX before executing the MONITOR
1126 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1128 @param Edx The value to load into EDX or RDX before executing the MONITOR
1142 __asm__
__volatile__ (
1154 Executes an MWAIT instruction.
1156 Executes an MWAIT instruction with the register state specified by Eax and
1157 Ecx. Returns Eax. This function is only available on IA-32 and X64.
1159 @param Eax The value to load into EAX or RAX before executing the MONITOR
1161 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1174 __asm__
__volatile__ (
1185 Executes a WBINVD instruction.
1187 Executes a WBINVD instruction. This function is only available on IA-32 and
1197 __asm__
__volatile__ ("wbinvd":::"memory");
1201 Executes a INVD instruction.
1203 Executes a INVD instruction. This function is only available on IA-32 and
1213 __asm__
__volatile__ ("invd":::"memory");
1219 Flushes a cache line from all the instruction and data caches within the
1220 coherency domain of the CPU.
1222 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1223 This function is only available on IA-32 and X64.
1225 @param LinearAddress The address of the cache line to flush. If the CPU is
1226 in a physical addressing mode, then LinearAddress is a
1227 physical address. If the CPU is in a virtual
1228 addressing mode, then LinearAddress is a virtual
1231 @return LinearAddress
1236 IN VOID
*LinearAddress
1239 __asm__
__volatile__ (
1242 : "r" (LinearAddress
)
1246 return LinearAddress
;