TianoCore EDK2 master
Loading...
Searching...
No Matches
GccInlinePriv.c
Go to the documentation of this file.
1
11#include "BaseLibInternals.h"
13
20VOID
21EFIAPI
23 VOID
24 )
25{
26 __asm__ __volatile__ ("sti"::: "memory");
27}
28
35VOID
36EFIAPI
38 VOID
39 )
40{
41 __asm__ __volatile__ ("cli"::: "memory");
42}
43
58UINT64
59EFIAPI
61 IN UINT32 Index
62 )
63{
64 UINT32 LowData;
65 UINT32 HighData;
66 UINT64 Value;
67 BOOLEAN Flag;
68
69 Flag = FilterBeforeMsrRead (Index, &Value);
70 if (Flag) {
71 __asm__ __volatile__ (
72 "rdmsr"
73 : "=a" (LowData), // %0
74 "=d" (HighData) // %1
75 : "c" (Index) // %2
76 );
77 Value = (((UINT64)HighData) << 32) | LowData;
78 }
79
80 FilterAfterMsrRead (Index, &Value);
81
82 return Value;
83}
84
102UINT64
103EFIAPI
105 IN UINT32 Index,
106 IN UINT64 Value
107 )
108{
109 UINT32 LowData;
110 UINT32 HighData;
111 BOOLEAN Flag;
112
113 Flag = FilterBeforeMsrWrite (Index, &Value);
114 if (Flag) {
115 LowData = (UINT32)(Value);
116 HighData = (UINT32)(Value >> 32);
117 __asm__ __volatile__ (
118 "wrmsr"
119 :
120 : "c" (Index),
121 "a" (LowData),
122 "d" (HighData)
123 );
124 }
125
126 FilterAfterMsrWrite (Index, &Value);
127
128 return Value;
129}
130
141UINTN
142EFIAPI
144 VOID
145 )
146{
147 UINTN Data;
148
149 __asm__ __volatile__ (
150 "mov %%cr0,%0"
151 : "=r" (Data) // %0
152 );
153
154 return Data;
155}
156
167UINTN
168EFIAPI
170 VOID
171 )
172{
173 UINTN Data;
174
175 __asm__ __volatile__ (
176 "mov %%cr2, %0"
177 : "=r" (Data) // %0
178 );
179
180 return Data;
181}
182
193UINTN
194EFIAPI
196 VOID
197 )
198{
199 UINTN Data;
200
201 __asm__ __volatile__ (
202 "mov %%cr3, %0"
203 : "=r" (Data) // %0
204 );
205
206 return Data;
207}
208
219UINTN
220EFIAPI
222 VOID
223 )
224{
225 UINTN Data;
226
227 __asm__ __volatile__ (
228 "mov %%cr4, %0"
229 : "=r" (Data) // %0
230 );
231
232 return Data;
233}
234
246UINTN
247EFIAPI
249 UINTN Cr0
250 )
251{
252 __asm__ __volatile__ (
253 "mov %0, %%cr0"
254 :
255 : "r" (Cr0)
256 );
257 return Cr0;
258}
259
271UINTN
272EFIAPI
274 UINTN Cr2
275 )
276{
277 __asm__ __volatile__ (
278 "mov %0, %%cr2"
279 :
280 : "r" (Cr2)
281 );
282 return Cr2;
283}
284
296UINTN
297EFIAPI
299 UINTN Cr3
300 )
301{
302 __asm__ __volatile__ (
303 "mov %0, %%cr3"
304 :
305 : "r" (Cr3)
306 );
307 return Cr3;
308}
309
321UINTN
322EFIAPI
324 UINTN Cr4
325 )
326{
327 __asm__ __volatile__ (
328 "mov %0, %%cr4"
329 :
330 : "r" (Cr4)
331 );
332 return Cr4;
333}
334
345UINTN
346EFIAPI
348 VOID
349 )
350{
351 UINTN Data;
352
353 __asm__ __volatile__ (
354 "mov %%dr0, %0"
355 : "=r" (Data)
356 );
357
358 return Data;
359}
360
371UINTN
372EFIAPI
374 VOID
375 )
376{
377 UINTN Data;
378
379 __asm__ __volatile__ (
380 "mov %%dr1, %0"
381 : "=r" (Data)
382 );
383
384 return Data;
385}
386
397UINTN
398EFIAPI
400 VOID
401 )
402{
403 UINTN Data;
404
405 __asm__ __volatile__ (
406 "mov %%dr2, %0"
407 : "=r" (Data)
408 );
409
410 return Data;
411}
412
423UINTN
424EFIAPI
426 VOID
427 )
428{
429 UINTN Data;
430
431 __asm__ __volatile__ (
432 "mov %%dr3, %0"
433 : "=r" (Data)
434 );
435
436 return Data;
437}
438
449UINTN
450EFIAPI
452 VOID
453 )
454{
455 UINTN Data;
456
457 __asm__ __volatile__ (
458 "mov %%dr4, %0"
459 : "=r" (Data)
460 );
461
462 return Data;
463}
464
475UINTN
476EFIAPI
478 VOID
479 )
480{
481 UINTN Data;
482
483 __asm__ __volatile__ (
484 "mov %%dr5, %0"
485 : "=r" (Data)
486 );
487
488 return Data;
489}
490
501UINTN
502EFIAPI
504 VOID
505 )
506{
507 UINTN Data;
508
509 __asm__ __volatile__ (
510 "mov %%dr6, %0"
511 : "=r" (Data)
512 );
513
514 return Data;
515}
516
527UINTN
528EFIAPI
530 VOID
531 )
532{
533 UINTN Data;
534
535 __asm__ __volatile__ (
536 "mov %%dr7, %0"
537 : "=r" (Data)
538 );
539
540 return Data;
541}
542
554UINTN
555EFIAPI
557 UINTN Dr0
558 )
559{
560 __asm__ __volatile__ (
561 "mov %0, %%dr0"
562 :
563 : "r" (Dr0)
564 );
565 return Dr0;
566}
567
579UINTN
580EFIAPI
582 UINTN Dr1
583 )
584{
585 __asm__ __volatile__ (
586 "mov %0, %%dr1"
587 :
588 : "r" (Dr1)
589 );
590 return Dr1;
591}
592
604UINTN
605EFIAPI
607 UINTN Dr2
608 )
609{
610 __asm__ __volatile__ (
611 "mov %0, %%dr2"
612 :
613 : "r" (Dr2)
614 );
615 return Dr2;
616}
617
629UINTN
630EFIAPI
632 UINTN Dr3
633 )
634{
635 __asm__ __volatile__ (
636 "mov %0, %%dr3"
637 :
638 : "r" (Dr3)
639 );
640 return Dr3;
641}
642
654UINTN
655EFIAPI
657 UINTN Dr4
658 )
659{
660 __asm__ __volatile__ (
661 "mov %0, %%dr4"
662 :
663 : "r" (Dr4)
664 );
665 return Dr4;
666}
667
679UINTN
680EFIAPI
682 UINTN Dr5
683 )
684{
685 __asm__ __volatile__ (
686 "mov %0, %%dr5"
687 :
688 : "r" (Dr5)
689 );
690 return Dr5;
691}
692
704UINTN
705EFIAPI
707 UINTN Dr6
708 )
709{
710 __asm__ __volatile__ (
711 "mov %0, %%dr6"
712 :
713 : "r" (Dr6)
714 );
715 return Dr6;
716}
717
729UINTN
730EFIAPI
732 UINTN Dr7
733 )
734{
735 __asm__ __volatile__ (
736 "mov %0, %%dr7"
737 :
738 : "r" (Dr7)
739 );
740 return Dr7;
741}
742
752UINT16
753EFIAPI
755 VOID
756 )
757{
758 UINT16 Data;
759
760 __asm__ __volatile__ (
761 "mov %%cs, %0"
762 :"=a" (Data)
763 );
764
765 return Data;
766}
767
777UINT16
778EFIAPI
780 VOID
781 )
782{
783 UINT16 Data;
784
785 __asm__ __volatile__ (
786 "mov %%ds, %0"
787 :"=a" (Data)
788 );
789
790 return Data;
791}
792
802UINT16
803EFIAPI
805 VOID
806 )
807{
808 UINT16 Data;
809
810 __asm__ __volatile__ (
811 "mov %%es, %0"
812 :"=a" (Data)
813 );
814
815 return Data;
816}
817
827UINT16
828EFIAPI
830 VOID
831 )
832{
833 UINT16 Data;
834
835 __asm__ __volatile__ (
836 "mov %%fs, %0"
837 :"=a" (Data)
838 );
839
840 return Data;
841}
842
852UINT16
853EFIAPI
855 VOID
856 )
857{
858 UINT16 Data;
859
860 __asm__ __volatile__ (
861 "mov %%gs, %0"
862 :"=a" (Data)
863 );
864
865 return Data;
866}
867
877UINT16
878EFIAPI
880 VOID
881 )
882{
883 UINT16 Data;
884
885 __asm__ __volatile__ (
886 "mov %%ss, %0"
887 :"=a" (Data)
888 );
889
890 return Data;
891}
892
902UINT16
903EFIAPI
905 VOID
906 )
907{
908 UINT16 Data;
909
910 __asm__ __volatile__ (
911 "str %0"
912 : "=r" (Data)
913 );
914
915 return Data;
916}
917
927VOID
928EFIAPI
930 OUT IA32_DESCRIPTOR *Gdtr
931 )
932{
933 __asm__ __volatile__ (
934 "sgdt %0"
935 : "=m" (*Gdtr)
936 );
937}
938
948VOID
949EFIAPI
951 IN CONST IA32_DESCRIPTOR *Gdtr
952 )
953{
954 __asm__ __volatile__ (
955 "lgdt %0"
956 :
957 : "m" (*Gdtr)
958 );
959}
960
970VOID
971EFIAPI
973 OUT IA32_DESCRIPTOR *Idtr
974 )
975{
976 __asm__ __volatile__ (
977 "sidt %0"
978 : "=m" (*Idtr)
979 );
980}
981
991VOID
992EFIAPI
994 IN CONST IA32_DESCRIPTOR *Idtr
995 )
996{
997 __asm__ __volatile__ (
998 "lidt %0"
999 :
1000 : "m" (*Idtr)
1001 );
1002}
1003
1013UINT16
1014EFIAPI
1016 VOID
1017 )
1018{
1019 UINT16 Data;
1020
1021 __asm__ __volatile__ (
1022 "sldt %0"
1023 : "=g" (Data) // %0
1024 );
1025
1026 return Data;
1027}
1028
1038VOID
1039EFIAPI
1041 IN UINT16 Ldtr
1042 )
1043{
1044 __asm__ __volatile__ (
1045 "lldtw %0"
1046 :
1047 : "g" (Ldtr) // %0
1048 );
1049}
1050
1062UINT64
1063EFIAPI
1065 IN UINT32 Index
1066 )
1067{
1068 UINT32 LowData;
1069 UINT32 HiData;
1070
1071 __asm__ __volatile__ (
1072 "rdpmc"
1073 : "=a" (LowData),
1074 "=d" (HiData)
1075 : "c" (Index)
1076 );
1077
1078 return (((UINT64)HiData) << 32) | LowData;
1079}
1080
1097UINTN
1098EFIAPI
1100 IN UINTN Eax,
1101 IN UINTN Ecx,
1102 IN UINTN Edx
1103 )
1104{
1105 __asm__ __volatile__ (
1106 "monitor"
1107 :
1108 : "a" (Eax),
1109 "c" (Ecx),
1110 "d" (Edx)
1111 );
1112
1113 return Eax;
1114}
1115
1130UINTN
1131EFIAPI
1133 IN UINTN Eax,
1134 IN UINTN Ecx
1135 )
1136{
1137 __asm__ __volatile__ (
1138 "mwait"
1139 :
1140 : "a" (Eax),
1141 "c" (Ecx)
1142 );
1143
1144 return Eax;
1145}
1146
1154VOID
1155EFIAPI
1157 VOID
1158 )
1159{
1160 __asm__ __volatile__ ("wbinvd":::"memory");
1161}
1162
1170VOID
1171EFIAPI
1173 VOID
1174 )
1175{
1176 __asm__ __volatile__ ("invd":::"memory");
1177}
1178
1194VOID *
1195EFIAPI
1197 IN VOID *LinearAddress
1198 )
1199{
1200 __asm__ __volatile__ (
1201 "clflush (%0)"
1202 :
1203 : "r" (LinearAddress)
1204 : "memory"
1205 );
1206
1207 return LinearAddress;
1208}
UINT64 UINTN
UINTN EFIAPI AsmWriteDr1(UINTN Dr1)
UINT16 EFIAPI AsmReadTr(VOID)
UINT16 EFIAPI AsmReadLdtr(VOID)
UINTN EFIAPI AsmWriteDr4(UINTN Dr4)
UINTN EFIAPI AsmReadDr1(VOID)
VOID EFIAPI AsmInvd(VOID)
UINTN EFIAPI AsmReadDr0(VOID)
UINT16 EFIAPI AsmReadFs(VOID)
UINTN EFIAPI AsmWriteDr7(UINTN Dr7)
VOID EFIAPI InternalX86ReadGdtr(OUT IA32_DESCRIPTOR *Gdtr)
UINTN EFIAPI AsmWriteDr3(UINTN Dr3)
UINT16 EFIAPI AsmReadEs(VOID)
UINTN EFIAPI AsmReadCr3(VOID)
VOID EFIAPI InternalX86ReadIdtr(OUT IA32_DESCRIPTOR *Idtr)
UINTN EFIAPI AsmReadDr2(VOID)
UINTN EFIAPI AsmWriteCr2(UINTN Cr2)
VOID EFIAPI EnableInterrupts(VOID)
Definition: GccInlinePriv.c:22
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
Definition: GccInlinePriv.c:60
VOID EFIAPI DisableInterrupts(VOID)
Definition: GccInlinePriv.c:37
UINTN EFIAPI AsmWriteCr3(UINTN Cr3)
VOID EFIAPI InternalX86WriteIdtr(IN CONST IA32_DESCRIPTOR *Idtr)
UINTN EFIAPI AsmWriteCr4(UINTN Cr4)
VOID EFIAPI AsmWbinvd(VOID)
UINTN EFIAPI AsmReadCr0(VOID)
UINTN EFIAPI AsmWriteDr2(UINTN Dr2)
UINTN EFIAPI AsmWriteDr0(UINTN Dr0)
UINT16 EFIAPI AsmReadGs(VOID)
UINTN EFIAPI AsmWriteCr0(UINTN Cr0)
VOID *EFIAPI AsmFlushCacheLine(IN VOID *LinearAddress)
UINTN EFIAPI AsmWriteDr5(UINTN Dr5)
UINTN EFIAPI AsmReadCr2(VOID)
UINT16 EFIAPI AsmReadSs(VOID)
UINT16 EFIAPI AsmReadCs(VOID)
UINT64 EFIAPI AsmWriteMsr64(IN UINT32 Index, IN UINT64 Value)
UINTN EFIAPI AsmReadDr3(VOID)
VOID EFIAPI AsmWriteLdtr(IN UINT16 Ldtr)
UINTN EFIAPI AsmReadCr4(VOID)
VOID EFIAPI InternalX86WriteGdtr(IN CONST IA32_DESCRIPTOR *Gdtr)
UINTN EFIAPI AsmReadDr6(VOID)
UINTN EFIAPI AsmWriteDr6(UINTN Dr6)
UINT64 EFIAPI AsmReadPmc(IN UINT32 Index)
UINT16 EFIAPI AsmReadDs(VOID)
UINTN EFIAPI AsmReadDr4(VOID)
UINTN EFIAPI AsmReadDr7(VOID)
UINTN EFIAPI AsmReadDr5(VOID)
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID EFIAPI FilterAfterMsrWrite(IN UINT32 Index, IN UINT64 *Value)
BOOLEAN EFIAPI FilterBeforeMsrRead(IN UINT32 Index, IN OUT UINT64 *Value)
VOID EFIAPI FilterAfterMsrRead(IN UINT32 Index, IN UINT64 *Value)
BOOLEAN EFIAPI FilterBeforeMsrWrite(IN UINT32 Index, IN UINT64 *Value)
UINTN EFIAPI AsmMonitor(IN UINTN Eax, IN UINTN Ecx, IN UINTN Edx)
UINTN EFIAPI AsmMwait(IN UINTN Eax, IN UINTN Ecx)