]>
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 - 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.
67 __asm__
__volatile__ (
77 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
80 Writes the 64-bit value specified by Value to the MSR specified by Index. The
81 64-bit value written to the MSR is returned. No parameter checking is
82 performed on Index or Value, and some of these may cause CPU exceptions. The
83 caller must either guarantee that Index and Value are valid, or the caller
84 must establish proper exception handlers. This function is only available on
87 @param Index The 32-bit MSR index to write.
88 @param Value The 64-bit value to write to the MSR.
100 __asm__
__volatile__ (
111 Reads the current value of the Control Register 0 (CR0).
113 Reads and returns the current value of CR0. This function is only available
114 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
117 @return The value of the Control Register 0 (CR0).
128 __asm__
__volatile__ (
138 Reads the current value of the Control Register 2 (CR2).
140 Reads and returns the current value of CR2. This function is only available
141 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
144 @return The value of the Control Register 2 (CR2).
155 __asm__
__volatile__ (
164 Reads the current value of the Control Register 3 (CR3).
166 Reads and returns the current value of CR3. This function is only available
167 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
170 @return The value of the Control Register 3 (CR3).
181 __asm__
__volatile__ (
191 Reads the current value of the Control Register 4 (CR4).
193 Reads and returns the current value of CR4. This function is only available
194 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
197 @return The value of the Control Register 4 (CR4).
208 __asm__
__volatile__ (
218 Writes a value to Control Register 0 (CR0).
220 Writes and returns a new value to CR0. This function is only available on
221 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
223 @param Cr0 The value to write to CR0.
225 @return The value written to CR0.
234 __asm__
__volatile__ (
244 Writes a value to Control Register 2 (CR2).
246 Writes and returns a new value to CR2. This function is only available on
247 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
249 @param Cr2 The value to write to CR2.
251 @return The value written to CR2.
260 __asm__
__volatile__ (
270 Writes a value to Control Register 3 (CR3).
272 Writes and returns a new value to CR3. This function is only available on
273 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
275 @param Cr3 The value to write to CR3.
277 @return The value written to CR3.
286 __asm__
__volatile__ (
296 Writes a value to Control Register 4 (CR4).
298 Writes and returns a new value to CR4. This function is only available on
299 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
301 @param Cr4 The value to write to CR4.
303 @return The value written to CR4.
312 __asm__
__volatile__ (
322 Reads the current value of Debug Register 0 (DR0).
324 Reads and returns the current value of DR0. This function is only available
325 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
328 @return The value of Debug Register 0 (DR0).
339 __asm__
__volatile__ (
349 Reads the current value of Debug Register 1 (DR1).
351 Reads and returns the current value of DR1. This function is only available
352 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
355 @return The value of Debug Register 1 (DR1).
366 __asm__
__volatile__ (
376 Reads the current value of Debug Register 2 (DR2).
378 Reads and returns the current value of DR2. This function is only available
379 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
382 @return The value of Debug Register 2 (DR2).
393 __asm__
__volatile__ (
403 Reads the current value of Debug Register 3 (DR3).
405 Reads and returns the current value of DR3. This function is only available
406 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
409 @return The value of Debug Register 3 (DR3).
420 __asm__
__volatile__ (
430 Reads the current value of Debug Register 4 (DR4).
432 Reads and returns the current value of DR4. This function is only available
433 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
436 @return The value of Debug Register 4 (DR4).
447 __asm__
__volatile__ (
457 Reads the current value of Debug Register 5 (DR5).
459 Reads and returns the current value of DR5. This function is only available
460 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
463 @return The value of Debug Register 5 (DR5).
474 __asm__
__volatile__ (
484 Reads the current value of Debug Register 6 (DR6).
486 Reads and returns the current value of DR6. This function is only available
487 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
490 @return The value of Debug Register 6 (DR6).
501 __asm__
__volatile__ (
511 Reads the current value of Debug Register 7 (DR7).
513 Reads and returns the current value of DR7. This function is only available
514 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
517 @return The value of Debug Register 7 (DR7).
528 __asm__
__volatile__ (
538 Writes a value to Debug Register 0 (DR0).
540 Writes and returns a new value to DR0. This function is only available on
541 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
543 @param Dr0 The value to write to Dr0.
545 @return The value written to Debug Register 0 (DR0).
554 __asm__
__volatile__ (
564 Writes a value to Debug Register 1 (DR1).
566 Writes and returns a new value to DR1. This function is only available on
567 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
569 @param Dr1 The value to write to Dr1.
571 @return The value written to Debug Register 1 (DR1).
580 __asm__
__volatile__ (
590 Writes a value to Debug Register 2 (DR2).
592 Writes and returns a new value to DR2. This function is only available on
593 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
595 @param Dr2 The value to write to Dr2.
597 @return The value written to Debug Register 2 (DR2).
606 __asm__
__volatile__ (
616 Writes a value to Debug Register 3 (DR3).
618 Writes and returns a new value to DR3. This function is only available on
619 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
621 @param Dr3 The value to write to Dr3.
623 @return The value written to Debug Register 3 (DR3).
632 __asm__
__volatile__ (
642 Writes a value to Debug Register 4 (DR4).
644 Writes and returns a new value to DR4. This function is only available on
645 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
647 @param Dr4 The value to write to Dr4.
649 @return The value written to Debug Register 4 (DR4).
658 __asm__
__volatile__ (
668 Writes a value to Debug Register 5 (DR5).
670 Writes and returns a new value to DR5. This function is only available on
671 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
673 @param Dr5 The value to write to Dr5.
675 @return The value written to Debug Register 5 (DR5).
684 __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__ (
720 Writes a value to Debug Register 7 (DR7).
722 Writes and returns a new value to DR7. This function is only available on
723 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
725 @param Dr7 The value to write to Dr7.
727 @return The value written to Debug Register 7 (DR7).
736 __asm__
__volatile__ (
746 Reads the current value of Code Segment Register (CS).
748 Reads and returns the current value of CS. This function is only available on
751 @return The current value of CS.
762 __asm__
__volatile__ (
772 Reads the current value of Data Segment Register (DS).
774 Reads and returns the current value of DS. This function is only available on
777 @return The current value of DS.
788 __asm__
__volatile__ (
798 Reads the current value of Extra Segment Register (ES).
800 Reads and returns the current value of ES. This function is only available on
803 @return The current value of ES.
814 __asm__
__volatile__ (
824 Reads the current value of FS Data Segment Register (FS).
826 Reads and returns the current value of FS. This function is only available on
829 @return The current value of FS.
840 __asm__
__volatile__ (
850 Reads the current value of GS Data Segment Register (GS).
852 Reads and returns the current value of GS. This function is only available on
855 @return The current value of GS.
866 __asm__
__volatile__ (
876 Reads the current value of Stack Segment Register (SS).
878 Reads and returns the current value of SS. This function is only available on
881 @return The current value of SS.
892 __asm__
__volatile__ (
902 Reads the current value of Task Register (TR).
904 Reads and returns the current value of TR. This function is only available on
907 @return The current value of TR.
918 __asm__
__volatile__ (
928 Reads the current Global Descriptor Table Register(GDTR) descriptor.
930 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
931 function is only available on IA-32 and X64.
933 @param Gdtr The pointer to a GDTR descriptor.
938 InternalX86ReadGdtr (
939 OUT IA32_DESCRIPTOR
*Gdtr
942 __asm__
__volatile__ (
950 Writes the current Global Descriptor Table Register (GDTR) descriptor.
952 Writes and the current GDTR descriptor specified by Gdtr. This function is
953 only available on IA-32 and X64.
955 @param Gdtr The pointer to a GDTR descriptor.
960 InternalX86WriteGdtr (
961 IN CONST IA32_DESCRIPTOR
*Gdtr
964 __asm__
__volatile__ (
974 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
976 Reads and returns the current IDTR descriptor and returns it in Idtr. This
977 function is only available on IA-32 and X64.
979 @param Idtr The pointer to a IDTR descriptor.
984 InternalX86ReadIdtr (
985 OUT IA32_DESCRIPTOR
*Idtr
988 __asm__
__volatile__ (
996 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
998 Writes the current IDTR descriptor and returns it in Idtr. This function is
999 only available on IA-32 and X64.
1001 @param Idtr The pointer to a IDTR descriptor.
1006 InternalX86WriteIdtr (
1007 IN CONST IA32_DESCRIPTOR
*Idtr
1010 __asm__
__volatile__ (
1019 Reads the current Local Descriptor Table Register(LDTR) selector.
1021 Reads and returns the current 16-bit LDTR descriptor value. This function is
1022 only available on IA-32 and X64.
1024 @return The current selector of LDT.
1035 __asm__
__volatile__ (
1045 Writes the current Local Descriptor Table Register (GDTR) selector.
1047 Writes and the current LDTR descriptor specified by Ldtr. This function is
1048 only available on IA-32 and X64.
1050 @param Ldtr 16-bit LDTR selector value.
1059 __asm__
__volatile__ (
1067 Reads the current value of a Performance Counter (PMC).
1069 Reads and returns the current value of performance counter specified by
1070 Index. This function is only available on IA-32 and X64.
1072 @param Index The 32-bit Performance Counter index to read.
1074 @return The value of the PMC specified by Index.
1085 __asm__
__volatile__ (
1095 Executes a WBINVD instruction.
1097 Executes a WBINVD instruction. This function is only available on IA-32 and
1107 __asm__
__volatile__ ("wbinvd":::"memory");
1111 Executes a INVD instruction.
1113 Executes a INVD instruction. This function is only available on IA-32 and
1123 __asm__
__volatile__ ("invd":::"memory");
1129 Flushes a cache line from all the instruction and data caches within the
1130 coherency domain of the CPU.
1132 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1133 This function is only available on IA-32 and X64.
1135 @param LinearAddress The address of the cache line to flush. If the CPU is
1136 in a physical addressing mode, then LinearAddress is a
1137 physical address. If the CPU is in a virtual
1138 addressing mode, then LinearAddress is a virtual
1141 @return LinearAddress
1146 IN VOID
*LinearAddress
1152 // If the CPU does not support CLFLUSH instruction,
1153 // then promote flush range to flush entire cache.
1155 AsmCpuid (0x01, NULL
, NULL
, NULL
, &RegEdx
);
1156 if ((RegEdx
& BIT19
) == 0) {
1157 __asm__
__volatile__ ("wbinvd":::"memory");
1158 return LinearAddress
;
1162 __asm__
__volatile__ (
1164 : "+a" (LinearAddress
)
1169 return LinearAddress
;