]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/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.
69 Flag
= FilterBeforeMsrRead (Index
, &Data
);
71 __asm__
__volatile__ (
77 FilterAfterMsrRead (Index
, &Data
);
83 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
86 Writes the 64-bit value specified by Value to the MSR specified by Index. The
87 64-bit value written to the MSR is returned. No parameter checking is
88 performed on Index or Value, and some of these may cause CPU exceptions. The
89 caller must either guarantee that Index and Value are valid, or the caller
90 must establish proper exception handlers. This function is only available on
93 @param Index The 32-bit MSR index to write.
94 @param Value The 64-bit value to write to the MSR.
108 Flag
= FilterBeforeMsrWrite (Index
, &Value
);
110 __asm__
__volatile__ (
117 FilterAfterMsrWrite (Index
, &Value
);
123 Reads the current value of the Control Register 0 (CR0).
125 Reads and returns the current value of CR0. This function is only available
126 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
129 @return The value of the Control Register 0 (CR0).
140 __asm__
__volatile__ (
150 Reads the current value of the Control Register 2 (CR2).
152 Reads and returns the current value of CR2. This function is only available
153 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
156 @return The value of the Control Register 2 (CR2).
167 __asm__
__volatile__ (
176 Reads the current value of the Control Register 3 (CR3).
178 Reads and returns the current value of CR3. This function is only available
179 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
182 @return The value of the Control Register 3 (CR3).
193 __asm__
__volatile__ (
203 Reads the current value of the Control Register 4 (CR4).
205 Reads and returns the current value of CR4. This function is only available
206 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
209 @return The value of the Control Register 4 (CR4).
220 __asm__
__volatile__ (
230 Writes a value to Control Register 0 (CR0).
232 Writes and returns a new value to CR0. This function is only available on
233 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
235 @param Cr0 The value to write to CR0.
237 @return The value written to CR0.
246 __asm__
__volatile__ (
256 Writes a value to Control Register 2 (CR2).
258 Writes and returns a new value to CR2. This function is only available on
259 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
261 @param Cr2 The value to write to CR2.
263 @return The value written to CR2.
272 __asm__
__volatile__ (
282 Writes a value to Control Register 3 (CR3).
284 Writes and returns a new value to CR3. This function is only available on
285 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
287 @param Cr3 The value to write to CR3.
289 @return The value written to CR3.
298 __asm__
__volatile__ (
308 Writes a value to Control Register 4 (CR4).
310 Writes and returns a new value to CR4. This function is only available on
311 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
313 @param Cr4 The value to write to CR4.
315 @return The value written to CR4.
324 __asm__
__volatile__ (
334 Reads the current value of Debug Register 0 (DR0).
336 Reads and returns the current value of DR0. This function is only available
337 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
340 @return The value of Debug Register 0 (DR0).
351 __asm__
__volatile__ (
361 Reads the current value of Debug Register 1 (DR1).
363 Reads and returns the current value of DR1. This function is only available
364 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
367 @return The value of Debug Register 1 (DR1).
378 __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__ (
415 Reads the current value of Debug Register 3 (DR3).
417 Reads and returns the current value of DR3. This function is only available
418 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
421 @return The value of Debug Register 3 (DR3).
432 __asm__
__volatile__ (
442 Reads the current value of Debug Register 4 (DR4).
444 Reads and returns the current value of DR4. This function is only available
445 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
448 @return The value of Debug Register 4 (DR4).
459 __asm__
__volatile__ (
469 Reads the current value of Debug Register 5 (DR5).
471 Reads and returns the current value of DR5. This function is only available
472 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
475 @return The value of Debug Register 5 (DR5).
486 __asm__
__volatile__ (
496 Reads the current value of Debug Register 6 (DR6).
498 Reads and returns the current value of DR6. This function is only available
499 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
502 @return The value of Debug Register 6 (DR6).
513 __asm__
__volatile__ (
523 Reads the current value of Debug Register 7 (DR7).
525 Reads and returns the current value of DR7. This function is only available
526 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
529 @return The value of Debug Register 7 (DR7).
540 __asm__
__volatile__ (
550 Writes a value to Debug Register 0 (DR0).
552 Writes and returns a new value to DR0. This function is only available on
553 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
555 @param Dr0 The value to write to Dr0.
557 @return The value written to Debug Register 0 (DR0).
566 __asm__
__volatile__ (
576 Writes a value to Debug Register 1 (DR1).
578 Writes and returns a new value to DR1. This function is only available on
579 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
581 @param Dr1 The value to write to Dr1.
583 @return The value written to Debug Register 1 (DR1).
592 __asm__
__volatile__ (
602 Writes a value to Debug Register 2 (DR2).
604 Writes and returns a new value to DR2. This function is only available on
605 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
607 @param Dr2 The value to write to Dr2.
609 @return The value written to Debug Register 2 (DR2).
618 __asm__
__volatile__ (
628 Writes a value to Debug Register 3 (DR3).
630 Writes and returns a new value to DR3. This function is only available on
631 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
633 @param Dr3 The value to write to Dr3.
635 @return The value written to Debug Register 3 (DR3).
644 __asm__
__volatile__ (
654 Writes a value to Debug Register 4 (DR4).
656 Writes and returns a new value to DR4. This function is only available on
657 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
659 @param Dr4 The value to write to Dr4.
661 @return The value written to Debug Register 4 (DR4).
670 __asm__
__volatile__ (
680 Writes a value to Debug Register 5 (DR5).
682 Writes and returns a new value to DR5. This function is only available on
683 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
685 @param Dr5 The value to write to Dr5.
687 @return The value written to Debug Register 5 (DR5).
696 __asm__
__volatile__ (
706 Writes a value to Debug Register 6 (DR6).
708 Writes and returns a new value to DR6. This function is only available on
709 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
711 @param Dr6 The value to write to Dr6.
713 @return The value written to Debug Register 6 (DR6).
722 __asm__
__volatile__ (
732 Writes a value to Debug Register 7 (DR7).
734 Writes and returns a new value to DR7. This function is only available on
735 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
737 @param Dr7 The value to write to Dr7.
739 @return The value written to Debug Register 7 (DR7).
748 __asm__
__volatile__ (
758 Reads the current value of Code Segment Register (CS).
760 Reads and returns the current value of CS. This function is only available on
763 @return The current value of CS.
774 __asm__
__volatile__ (
784 Reads the current value of Data Segment Register (DS).
786 Reads and returns the current value of DS. This function is only available on
789 @return The current value of DS.
800 __asm__
__volatile__ (
810 Reads the current value of Extra Segment Register (ES).
812 Reads and returns the current value of ES. This function is only available on
815 @return The current value of ES.
826 __asm__
__volatile__ (
836 Reads the current value of FS Data Segment Register (FS).
838 Reads and returns the current value of FS. This function is only available on
841 @return The current value of FS.
852 __asm__
__volatile__ (
862 Reads the current value of GS Data Segment Register (GS).
864 Reads and returns the current value of GS. This function is only available on
867 @return The current value of GS.
878 __asm__
__volatile__ (
888 Reads the current value of Stack Segment Register (SS).
890 Reads and returns the current value of SS. This function is only available on
893 @return The current value of SS.
904 __asm__
__volatile__ (
914 Reads the current value of Task Register (TR).
916 Reads and returns the current value of TR. This function is only available on
919 @return The current value of TR.
930 __asm__
__volatile__ (
940 Reads the current Global Descriptor Table Register(GDTR) descriptor.
942 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
943 function is only available on IA-32 and X64.
945 @param Gdtr The pointer to a GDTR descriptor.
950 InternalX86ReadGdtr (
951 OUT IA32_DESCRIPTOR
*Gdtr
954 __asm__
__volatile__ (
962 Writes the current Global Descriptor Table Register (GDTR) descriptor.
964 Writes and the current GDTR descriptor specified by Gdtr. This function is
965 only available on IA-32 and X64.
967 @param Gdtr The pointer to a GDTR descriptor.
972 InternalX86WriteGdtr (
973 IN CONST IA32_DESCRIPTOR
*Gdtr
976 __asm__
__volatile__ (
986 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
988 Reads and returns the current IDTR descriptor and returns it in Idtr. This
989 function is only available on IA-32 and X64.
991 @param Idtr The pointer to a IDTR descriptor.
996 InternalX86ReadIdtr (
997 OUT IA32_DESCRIPTOR
*Idtr
1000 __asm__
__volatile__ (
1008 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
1010 Writes the current IDTR descriptor and returns it in Idtr. This function is
1011 only available on IA-32 and X64.
1013 @param Idtr The pointer to a IDTR descriptor.
1018 InternalX86WriteIdtr (
1019 IN CONST IA32_DESCRIPTOR
*Idtr
1022 __asm__
__volatile__ (
1031 Reads the current Local Descriptor Table Register(LDTR) selector.
1033 Reads and returns the current 16-bit LDTR descriptor value. This function is
1034 only available on IA-32 and X64.
1036 @return The current selector of LDT.
1047 __asm__
__volatile__ (
1057 Writes the current Local Descriptor Table Register (GDTR) selector.
1059 Writes and the current LDTR descriptor specified by Ldtr. This function is
1060 only available on IA-32 and X64.
1062 @param Ldtr 16-bit LDTR selector value.
1071 __asm__
__volatile__ (
1079 Reads the current value of a Performance Counter (PMC).
1081 Reads and returns the current value of performance counter specified by
1082 Index. This function is only available on IA-32 and X64.
1084 @param Index The 32-bit Performance Counter index to read.
1086 @return The value of the PMC specified by Index.
1097 __asm__
__volatile__ (
1107 Executes a WBINVD instruction.
1109 Executes a WBINVD instruction. This function is only available on IA-32 and
1119 __asm__
__volatile__ ("wbinvd":::"memory");
1123 Executes a INVD instruction.
1125 Executes a INVD instruction. This function is only available on IA-32 and
1135 __asm__
__volatile__ ("invd":::"memory");
1141 Flushes a cache line from all the instruction and data caches within the
1142 coherency domain of the CPU.
1144 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1145 This function is only available on IA-32 and X64.
1147 @param LinearAddress The address of the cache line to flush. If the CPU is
1148 in a physical addressing mode, then LinearAddress is a
1149 physical address. If the CPU is in a virtual
1150 addressing mode, then LinearAddress is a virtual
1153 @return LinearAddress
1158 IN VOID
*LinearAddress
1164 // If the CPU does not support CLFLUSH instruction,
1165 // then promote flush range to flush entire cache.
1167 AsmCpuid (0x01, NULL
, NULL
, NULL
, &RegEdx
);
1168 if ((RegEdx
& BIT19
) == 0) {
1169 __asm__
__volatile__ ("wbinvd":::"memory");
1170 return LinearAddress
;
1174 __asm__
__volatile__ (
1176 : "+a" (LinearAddress
)
1181 return LinearAddress
;