]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X86UnitTestHost.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseLib / X86UnitTestHost.c
1 /** @file
2 IA32/X64 specific Unit Test Host functions.
3
4 Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "UnitTestHost.h"
10
11 ///
12 /// Defines for mUnitTestHostBaseLibSegment indexes
13 ///
14 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_CS 0
15 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_DS 1
16 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_ES 2
17 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_FS 3
18 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_GS 4
19 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_SS 5
20 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_TR 6
21 #define UNIT_TEST_HOST_BASE_LIB_SEGMENT_LDTR 7
22
23 ///
24 /// Module global variables for simple system emulation of MSRs, CRx, DRx,
25 /// GDTR, IDTR, and Segment Selectors.
26 ///
27 STATIC UINT64 mUnitTestHostBaseLibMsr[2][0x1000];
28 STATIC UINTN mUnitTestHostBaseLibCr[5];
29 STATIC UINTN mUnitTestHostBaseLibDr[8];
30 STATIC UINT16 mUnitTestHostBaseLibSegment[8];
31 STATIC IA32_DESCRIPTOR mUnitTestHostBaseLibGdtr;
32 STATIC IA32_DESCRIPTOR mUnitTestHostBaseLibIdtr;
33
34 /**
35 Retrieves CPUID information.
36
37 Executes the CPUID instruction with EAX set to the value specified by Index.
38 This function always returns Index.
39 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
40 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
41 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
42 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
43 This function is only available on IA-32 and x64.
44
45 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
46 instruction.
47 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
48 instruction. This is an optional parameter that may be NULL.
49 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
50 instruction. This is an optional parameter that may be NULL.
51 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
52 instruction. This is an optional parameter that may be NULL.
53 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
54 instruction. This is an optional parameter that may be NULL.
55
56 @return Index.
57
58 **/
59 UINT32
60 EFIAPI
61 UnitTestHostBaseLibAsmCpuid (
62 IN UINT32 Index,
63 OUT UINT32 *Eax OPTIONAL,
64 OUT UINT32 *Ebx OPTIONAL,
65 OUT UINT32 *Ecx OPTIONAL,
66 OUT UINT32 *Edx OPTIONAL
67 )
68 {
69 if (Eax != NULL) {
70 *Eax = 0;
71 }
72
73 if (Ebx != NULL) {
74 *Ebx = 0;
75 }
76
77 if (Ecx != NULL) {
78 *Ecx = 0;
79 }
80
81 if (Edx != NULL) {
82 *Edx = 0;
83 }
84
85 return Index;
86 }
87
88 /**
89 Retrieves CPUID information using an extended leaf identifier.
90
91 Executes the CPUID instruction with EAX set to the value specified by Index
92 and ECX set to the value specified by SubIndex. This function always returns
93 Index. This function is only available on IA-32 and x64.
94
95 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
96 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
97 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
98 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
99
100 @param Index The 32-bit value to load into EAX prior to invoking the
101 CPUID instruction.
102 @param SubIndex The 32-bit value to load into ECX prior to invoking the
103 CPUID instruction.
104 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
105 instruction. This is an optional parameter that may be
106 NULL.
107 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
108 instruction. This is an optional parameter that may be
109 NULL.
110 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
111 instruction. This is an optional parameter that may be
112 NULL.
113 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
114 instruction. This is an optional parameter that may be
115 NULL.
116
117 @return Index.
118
119 **/
120 UINT32
121 EFIAPI
122 UnitTestHostBaseLibAsmCpuidEx (
123 IN UINT32 Index,
124 IN UINT32 SubIndex,
125 OUT UINT32 *Eax OPTIONAL,
126 OUT UINT32 *Ebx OPTIONAL,
127 OUT UINT32 *Ecx OPTIONAL,
128 OUT UINT32 *Edx OPTIONAL
129 )
130 {
131 if (Eax != NULL) {
132 *Eax = 0;
133 }
134
135 if (Ebx != NULL) {
136 *Ebx = 0;
137 }
138
139 if (Ecx != NULL) {
140 *Ecx = 0;
141 }
142
143 if (Edx != NULL) {
144 *Edx = 0;
145 }
146
147 return Index;
148 }
149
150 /**
151 Set CD bit and clear NW bit of CR0 followed by a WBINVD.
152
153 Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,
154 and executing a WBINVD instruction. This function is only available on IA-32 and x64.
155
156 **/
157 VOID
158 EFIAPI
159 UnitTestHostBaseLibAsmDisableCache (
160 VOID
161 )
162 {
163 }
164
165 /**
166 Perform a WBINVD and clear both the CD and NW bits of CR0.
167
168 Enables the caches by executing a WBINVD instruction and then clear both the CD and NW
169 bits of CR0 to 0. This function is only available on IA-32 and x64.
170
171 **/
172 VOID
173 EFIAPI
174 UnitTestHostBaseLibAsmEnableCache (
175 VOID
176 )
177 {
178 }
179
180 /**
181 Returns a 64-bit Machine Specific Register(MSR).
182
183 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
184 performed on Index, and some Index values may cause CPU exceptions. The
185 caller must either guarantee that Index is valid, or the caller must set up
186 exception handlers to catch the exceptions. This function is only available
187 on IA-32 and x64.
188
189 @param Index The 32-bit MSR index to read.
190
191 @return The value of the MSR identified by Index.
192
193 **/
194 UINT64
195 EFIAPI
196 UnitTestHostBaseLibAsmReadMsr64 (
197 IN UINT32 Index
198 )
199 {
200 if (Index < 0x1000) {
201 return mUnitTestHostBaseLibMsr[0][Index];
202 }
203
204 if ((Index >= 0xC0000000) && (Index < 0xC0001000)) {
205 return mUnitTestHostBaseLibMsr[1][Index];
206 }
207
208 return 0;
209 }
210
211 /**
212 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
213 value.
214
215 Writes the 64-bit value specified by Value to the MSR specified by Index. The
216 64-bit value written to the MSR is returned. No parameter checking is
217 performed on Index or Value, and some of these may cause CPU exceptions. The
218 caller must either guarantee that Index and Value are valid, or the caller
219 must establish proper exception handlers. This function is only available on
220 IA-32 and x64.
221
222 @param Index The 32-bit MSR index to write.
223 @param Value The 64-bit value to write to the MSR.
224
225 @return Value
226
227 **/
228 UINT64
229 EFIAPI
230 UnitTestHostBaseLibAsmWriteMsr64 (
231 IN UINT32 Index,
232 IN UINT64 Value
233 )
234 {
235 if (Index < 0x1000) {
236 mUnitTestHostBaseLibMsr[0][Index] = Value;
237 }
238
239 if ((Index >= 0xC0000000) && (Index < 0xC0001000)) {
240 mUnitTestHostBaseLibMsr[1][Index - 0xC00000000] = Value;
241 }
242
243 return Value;
244 }
245
246 /**
247 Reads the current value of the Control Register 0 (CR0).
248
249 Reads and returns the current value of CR0. This function is only available
250 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
251 x64.
252
253 @return The value of the Control Register 0 (CR0).
254
255 **/
256 UINTN
257 EFIAPI
258 UnitTestHostBaseLibAsmReadCr0 (
259 VOID
260 )
261 {
262 return mUnitTestHostBaseLibCr[0];
263 }
264
265 /**
266 Reads the current value of the Control Register 2 (CR2).
267
268 Reads and returns the current value of CR2. This function is only available
269 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
270 x64.
271
272 @return The value of the Control Register 2 (CR2).
273
274 **/
275 UINTN
276 EFIAPI
277 UnitTestHostBaseLibAsmReadCr2 (
278 VOID
279 )
280 {
281 return mUnitTestHostBaseLibCr[2];
282 }
283
284 /**
285 Reads the current value of the Control Register 3 (CR3).
286
287 Reads and returns the current value of CR3. This function is only available
288 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
289 x64.
290
291 @return The value of the Control Register 3 (CR3).
292
293 **/
294 UINTN
295 EFIAPI
296 UnitTestHostBaseLibAsmReadCr3 (
297 VOID
298 )
299 {
300 return mUnitTestHostBaseLibCr[3];
301 }
302
303 /**
304 Reads the current value of the Control Register 4 (CR4).
305
306 Reads and returns the current value of CR4. This function is only available
307 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
308 x64.
309
310 @return The value of the Control Register 4 (CR4).
311
312 **/
313 UINTN
314 EFIAPI
315 UnitTestHostBaseLibAsmReadCr4 (
316 VOID
317 )
318 {
319 return mUnitTestHostBaseLibCr[4];
320 }
321
322 /**
323 Writes a value to Control Register 0 (CR0).
324
325 Writes and returns a new value to CR0. This function is only available on
326 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
327
328 @param Cr0 The value to write to CR0.
329
330 @return The value written to CR0.
331
332 **/
333 UINTN
334 EFIAPI
335 UnitTestHostBaseLibAsmWriteCr0 (
336 UINTN Cr0
337 )
338 {
339 mUnitTestHostBaseLibCr[0] = Cr0;
340 return Cr0;
341 }
342
343 /**
344 Writes a value to Control Register 2 (CR2).
345
346 Writes and returns a new value to CR2. This function is only available on
347 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
348
349 @param Cr2 The value to write to CR2.
350
351 @return The value written to CR2.
352
353 **/
354 UINTN
355 EFIAPI
356 UnitTestHostBaseLibAsmWriteCr2 (
357 UINTN Cr2
358 )
359 {
360 mUnitTestHostBaseLibCr[2] = Cr2;
361 return Cr2;
362 }
363
364 /**
365 Writes a value to Control Register 3 (CR3).
366
367 Writes and returns a new value to CR3. This function is only available on
368 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
369
370 @param Cr3 The value to write to CR3.
371
372 @return The value written to CR3.
373
374 **/
375 UINTN
376 EFIAPI
377 UnitTestHostBaseLibAsmWriteCr3 (
378 UINTN Cr3
379 )
380 {
381 mUnitTestHostBaseLibCr[3] = Cr3;
382 return Cr3;
383 }
384
385 /**
386 Writes a value to Control Register 4 (CR4).
387
388 Writes and returns a new value to CR4. This function is only available on
389 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
390
391 @param Cr4 The value to write to CR4.
392
393 @return The value written to CR4.
394
395 **/
396 UINTN
397 EFIAPI
398 UnitTestHostBaseLibAsmWriteCr4 (
399 UINTN Cr4
400 )
401 {
402 mUnitTestHostBaseLibCr[4] = Cr4;
403 return Cr4;
404 }
405
406 /**
407 Reads the current value of Debug Register 0 (DR0).
408
409 Reads and returns the current value of DR0. This function is only available
410 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
411 x64.
412
413 @return The value of Debug Register 0 (DR0).
414
415 **/
416 UINTN
417 EFIAPI
418 UnitTestHostBaseLibAsmReadDr0 (
419 VOID
420 )
421 {
422 return mUnitTestHostBaseLibDr[0];
423 }
424
425 /**
426 Reads the current value of Debug Register 1 (DR1).
427
428 Reads and returns the current value of DR1. This function is only available
429 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
430 x64.
431
432 @return The value of Debug Register 1 (DR1).
433
434 **/
435 UINTN
436 EFIAPI
437 UnitTestHostBaseLibAsmReadDr1 (
438 VOID
439 )
440 {
441 return mUnitTestHostBaseLibDr[1];
442 }
443
444 /**
445 Reads the current value of Debug Register 2 (DR2).
446
447 Reads and returns the current value of DR2. This function is only available
448 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
449 x64.
450
451 @return The value of Debug Register 2 (DR2).
452
453 **/
454 UINTN
455 EFIAPI
456 UnitTestHostBaseLibAsmReadDr2 (
457 VOID
458 )
459 {
460 return mUnitTestHostBaseLibDr[2];
461 }
462
463 /**
464 Reads the current value of Debug Register 3 (DR3).
465
466 Reads and returns the current value of DR3. This function is only available
467 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
468 x64.
469
470 @return The value of Debug Register 3 (DR3).
471
472 **/
473 UINTN
474 EFIAPI
475 UnitTestHostBaseLibAsmReadDr3 (
476 VOID
477 )
478 {
479 return mUnitTestHostBaseLibDr[3];
480 }
481
482 /**
483 Reads the current value of Debug Register 4 (DR4).
484
485 Reads and returns the current value of DR4. This function is only available
486 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
487 x64.
488
489 @return The value of Debug Register 4 (DR4).
490
491 **/
492 UINTN
493 EFIAPI
494 UnitTestHostBaseLibAsmReadDr4 (
495 VOID
496 )
497 {
498 return mUnitTestHostBaseLibDr[4];
499 }
500
501 /**
502 Reads the current value of Debug Register 5 (DR5).
503
504 Reads and returns the current value of DR5. This function is only available
505 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
506 x64.
507
508 @return The value of Debug Register 5 (DR5).
509
510 **/
511 UINTN
512 EFIAPI
513 UnitTestHostBaseLibAsmReadDr5 (
514 VOID
515 )
516 {
517 return mUnitTestHostBaseLibDr[5];
518 }
519
520 /**
521 Reads the current value of Debug Register 6 (DR6).
522
523 Reads and returns the current value of DR6. This function is only available
524 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
525 x64.
526
527 @return The value of Debug Register 6 (DR6).
528
529 **/
530 UINTN
531 EFIAPI
532 UnitTestHostBaseLibAsmReadDr6 (
533 VOID
534 )
535 {
536 return mUnitTestHostBaseLibDr[6];
537 }
538
539 /**
540 Reads the current value of Debug Register 7 (DR7).
541
542 Reads and returns the current value of DR7. This function is only available
543 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
544 x64.
545
546 @return The value of Debug Register 7 (DR7).
547
548 **/
549 UINTN
550 EFIAPI
551 UnitTestHostBaseLibAsmReadDr7 (
552 VOID
553 )
554 {
555 return mUnitTestHostBaseLibDr[7];
556 }
557
558 /**
559 Writes a value to Debug Register 0 (DR0).
560
561 Writes and returns a new value to DR0. This function is only available on
562 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
563
564 @param Dr0 The value to write to Dr0.
565
566 @return The value written to Debug Register 0 (DR0).
567
568 **/
569 UINTN
570 EFIAPI
571 UnitTestHostBaseLibAsmWriteDr0 (
572 UINTN Dr0
573 )
574 {
575 mUnitTestHostBaseLibDr[0] = Dr0;
576 return Dr0;
577 }
578
579 /**
580 Writes a value to Debug Register 1 (DR1).
581
582 Writes and returns a new value to DR1. This function is only available on
583 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
584
585 @param Dr1 The value to write to Dr1.
586
587 @return The value written to Debug Register 1 (DR1).
588
589 **/
590 UINTN
591 EFIAPI
592 UnitTestHostBaseLibAsmWriteDr1 (
593 UINTN Dr1
594 )
595 {
596 mUnitTestHostBaseLibDr[1] = Dr1;
597 return Dr1;
598 }
599
600 /**
601 Writes a value to Debug Register 2 (DR2).
602
603 Writes and returns a new value to DR2. This function is only available on
604 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
605
606 @param Dr2 The value to write to Dr2.
607
608 @return The value written to Debug Register 2 (DR2).
609
610 **/
611 UINTN
612 EFIAPI
613 UnitTestHostBaseLibAsmWriteDr2 (
614 UINTN Dr2
615 )
616 {
617 mUnitTestHostBaseLibDr[2] = Dr2;
618 return Dr2;
619 }
620
621 /**
622 Writes a value to Debug Register 3 (DR3).
623
624 Writes and returns a new value to DR3. This function is only available on
625 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
626
627 @param Dr3 The value to write to Dr3.
628
629 @return The value written to Debug Register 3 (DR3).
630
631 **/
632 UINTN
633 EFIAPI
634 UnitTestHostBaseLibAsmWriteDr3 (
635 UINTN Dr3
636 )
637 {
638 mUnitTestHostBaseLibDr[3] = Dr3;
639 return Dr3;
640 }
641
642 /**
643 Writes a value to Debug Register 4 (DR4).
644
645 Writes and returns a new value to DR4. This function is only available on
646 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
647
648 @param Dr4 The value to write to Dr4.
649
650 @return The value written to Debug Register 4 (DR4).
651
652 **/
653 UINTN
654 EFIAPI
655 UnitTestHostBaseLibAsmWriteDr4 (
656 UINTN Dr4
657 )
658 {
659 mUnitTestHostBaseLibDr[4] = Dr4;
660 return Dr4;
661 }
662
663 /**
664 Writes a value to Debug Register 5 (DR5).
665
666 Writes and returns a new value to DR5. 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.
668
669 @param Dr5 The value to write to Dr5.
670
671 @return The value written to Debug Register 5 (DR5).
672
673 **/
674 UINTN
675 EFIAPI
676 UnitTestHostBaseLibAsmWriteDr5 (
677 UINTN Dr5
678 )
679 {
680 mUnitTestHostBaseLibDr[5] = Dr5;
681 return Dr5;
682 }
683
684 /**
685 Writes a value to Debug Register 6 (DR6).
686
687 Writes and returns a new value to DR6. This function is only available on
688 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
689
690 @param Dr6 The value to write to Dr6.
691
692 @return The value written to Debug Register 6 (DR6).
693
694 **/
695 UINTN
696 EFIAPI
697 UnitTestHostBaseLibAsmWriteDr6 (
698 UINTN Dr6
699 )
700 {
701 mUnitTestHostBaseLibDr[6] = Dr6;
702 return Dr6;
703 }
704
705 /**
706 Writes a value to Debug Register 7 (DR7).
707
708 Writes and returns a new value to DR7. 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.
710
711 @param Dr7 The value to write to Dr7.
712
713 @return The value written to Debug Register 7 (DR7).
714
715 **/
716 UINTN
717 EFIAPI
718 UnitTestHostBaseLibAsmWriteDr7 (
719 UINTN Dr7
720 )
721 {
722 mUnitTestHostBaseLibDr[7] = Dr7;
723 return Dr7;
724 }
725
726 /**
727 Reads the current value of Code Segment Register (CS).
728
729 Reads and returns the current value of CS. This function is only available on
730 IA-32 and x64.
731
732 @return The current value of CS.
733
734 **/
735 UINT16
736 EFIAPI
737 UnitTestHostBaseLibAsmReadCs (
738 VOID
739 )
740 {
741 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_CS];
742 }
743
744 /**
745 Reads the current value of Data Segment Register (DS).
746
747 Reads and returns the current value of DS. This function is only available on
748 IA-32 and x64.
749
750 @return The current value of DS.
751
752 **/
753 UINT16
754 EFIAPI
755 UnitTestHostBaseLibAsmReadDs (
756 VOID
757 )
758 {
759 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_DS];
760 }
761
762 /**
763 Reads the current value of Extra Segment Register (ES).
764
765 Reads and returns the current value of ES. This function is only available on
766 IA-32 and x64.
767
768 @return The current value of ES.
769
770 **/
771 UINT16
772 EFIAPI
773 UnitTestHostBaseLibAsmReadEs (
774 VOID
775 )
776 {
777 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_ES];
778 }
779
780 /**
781 Reads the current value of FS Data Segment Register (FS).
782
783 Reads and returns the current value of FS. This function is only available on
784 IA-32 and x64.
785
786 @return The current value of FS.
787
788 **/
789 UINT16
790 EFIAPI
791 UnitTestHostBaseLibAsmReadFs (
792 VOID
793 )
794 {
795 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_FS];
796 }
797
798 /**
799 Reads the current value of GS Data Segment Register (GS).
800
801 Reads and returns the current value of GS. This function is only available on
802 IA-32 and x64.
803
804 @return The current value of GS.
805
806 **/
807 UINT16
808 EFIAPI
809 UnitTestHostBaseLibAsmReadGs (
810 VOID
811 )
812 {
813 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_GS];
814 }
815
816 /**
817 Reads the current value of Stack Segment Register (SS).
818
819 Reads and returns the current value of SS. This function is only available on
820 IA-32 and x64.
821
822 @return The current value of SS.
823
824 **/
825 UINT16
826 EFIAPI
827 UnitTestHostBaseLibAsmReadSs (
828 VOID
829 )
830 {
831 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_SS];
832 }
833
834 /**
835 Reads the current value of Task Register (TR).
836
837 Reads and returns the current value of TR. This function is only available on
838 IA-32 and x64.
839
840 @return The current value of TR.
841
842 **/
843 UINT16
844 EFIAPI
845 UnitTestHostBaseLibAsmReadTr (
846 VOID
847 )
848 {
849 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_TR];
850 }
851
852 /**
853 Reads the current Global Descriptor Table Register(GDTR) descriptor.
854
855 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
856 function is only available on IA-32 and x64.
857
858 If Gdtr is NULL, then ASSERT().
859
860 @param Gdtr The pointer to a GDTR descriptor.
861
862 **/
863 VOID
864 EFIAPI
865 UnitTestHostBaseLibAsmReadGdtr (
866 OUT IA32_DESCRIPTOR *Gdtr
867 )
868 {
869 Gdtr = &mUnitTestHostBaseLibGdtr;
870 }
871
872 /**
873 Writes the current Global Descriptor Table Register (GDTR) descriptor.
874
875 Writes and the current GDTR descriptor specified by Gdtr. This function is
876 only available on IA-32 and x64.
877
878 If Gdtr is NULL, then ASSERT().
879
880 @param Gdtr The pointer to a GDTR descriptor.
881
882 **/
883 VOID
884 EFIAPI
885 UnitTestHostBaseLibAsmWriteGdtr (
886 IN CONST IA32_DESCRIPTOR *Gdtr
887 )
888 {
889 CopyMem (&mUnitTestHostBaseLibGdtr, Gdtr, sizeof (IA32_DESCRIPTOR));
890 }
891
892 /**
893 Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.
894
895 Reads and returns the current IDTR descriptor and returns it in Idtr. This
896 function is only available on IA-32 and x64.
897
898 If Idtr is NULL, then ASSERT().
899
900 @param Idtr The pointer to a IDTR descriptor.
901
902 **/
903 VOID
904 EFIAPI
905 UnitTestHostBaseLibAsmReadIdtr (
906 OUT IA32_DESCRIPTOR *Idtr
907 )
908 {
909 Idtr = &mUnitTestHostBaseLibIdtr;
910 }
911
912 /**
913 Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.
914
915 Writes the current IDTR descriptor and returns it in Idtr. This function is
916 only available on IA-32 and x64.
917
918 If Idtr is NULL, then ASSERT().
919
920 @param Idtr The pointer to a IDTR descriptor.
921
922 **/
923 VOID
924 EFIAPI
925 UnitTestHostBaseLibAsmWriteIdtr (
926 IN CONST IA32_DESCRIPTOR *Idtr
927 )
928 {
929 CopyMem (&mUnitTestHostBaseLibIdtr, Idtr, sizeof (IA32_DESCRIPTOR));
930 }
931
932 /**
933 Reads the current Local Descriptor Table Register(LDTR) selector.
934
935 Reads and returns the current 16-bit LDTR descriptor value. This function is
936 only available on IA-32 and x64.
937
938 @return The current selector of LDT.
939
940 **/
941 UINT16
942 EFIAPI
943 UnitTestHostBaseLibAsmReadLdtr (
944 VOID
945 )
946 {
947 return mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_LDTR];
948 }
949
950 /**
951 Writes the current Local Descriptor Table Register (LDTR) selector.
952
953 Writes and the current LDTR descriptor specified by Ldtr. This function is
954 only available on IA-32 and x64.
955
956 @param Ldtr 16-bit LDTR selector value.
957
958 **/
959 VOID
960 EFIAPI
961 UnitTestHostBaseLibAsmWriteLdtr (
962 IN UINT16 Ldtr
963 )
964 {
965 mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_LDTR] = Ldtr;
966 }
967
968 /**
969 Reads the current value of a Performance Counter (PMC).
970
971 Reads and returns the current value of performance counter specified by
972 Index. This function is only available on IA-32 and x64.
973
974 @param Index The 32-bit Performance Counter index to read.
975
976 @return The value of the PMC specified by Index.
977
978 **/
979 UINT64
980 EFIAPI
981 UnitTestHostBaseLibAsmReadPmc (
982 IN UINT32 Index
983 )
984 {
985 return 0;
986 }
987
988 /**
989 Sets up a monitor buffer that is used by AsmMwait().
990
991 Executes a MONITOR instruction with the register state specified by Eax, Ecx
992 and Edx. Returns Eax. This function is only available on IA-32 and x64.
993
994 @param Eax The value to load into EAX or RAX before executing the MONITOR
995 instruction.
996 @param Ecx The value to load into ECX or RCX before executing the MONITOR
997 instruction.
998 @param Edx The value to load into EDX or RDX before executing the MONITOR
999 instruction.
1000
1001 @return Eax
1002
1003 **/
1004 UINTN
1005 EFIAPI
1006 UnitTestHostBaseLibAsmMonitor (
1007 IN UINTN Eax,
1008 IN UINTN Ecx,
1009 IN UINTN Edx
1010 )
1011 {
1012 return Eax;
1013 }
1014
1015 /**
1016 Executes an MWAIT instruction.
1017
1018 Executes an MWAIT instruction with the register state specified by Eax and
1019 Ecx. Returns Eax. This function is only available on IA-32 and x64.
1020
1021 @param Eax The value to load into EAX or RAX before executing the MONITOR
1022 instruction.
1023 @param Ecx The value to load into ECX or RCX before executing the MONITOR
1024 instruction.
1025
1026 @return Eax
1027
1028 **/
1029 UINTN
1030 EFIAPI
1031 UnitTestHostBaseLibAsmMwait (
1032 IN UINTN Eax,
1033 IN UINTN Ecx
1034 )
1035 {
1036 return Eax;
1037 }
1038
1039 /**
1040 Executes a WBINVD instruction.
1041
1042 Executes a WBINVD instruction. This function is only available on IA-32 and
1043 x64.
1044
1045 **/
1046 VOID
1047 EFIAPI
1048 UnitTestHostBaseLibAsmWbinvd (
1049 VOID
1050 )
1051 {
1052 }
1053
1054 /**
1055 Executes a INVD instruction.
1056
1057 Executes a INVD instruction. This function is only available on IA-32 and
1058 x64.
1059
1060 **/
1061 VOID
1062 EFIAPI
1063 UnitTestHostBaseLibAsmInvd (
1064 VOID
1065 )
1066 {
1067 }
1068
1069 /**
1070 Flushes a cache line from all the instruction and data caches within the
1071 coherency domain of the CPU.
1072
1073 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
1074 This function is only available on IA-32 and x64.
1075
1076 @param LinearAddress The address of the cache line to flush. If the CPU is
1077 in a physical addressing mode, then LinearAddress is a
1078 physical address. If the CPU is in a virtual
1079 addressing mode, then LinearAddress is a virtual
1080 address.
1081
1082 @return LinearAddress.
1083 **/
1084 VOID *
1085 EFIAPI
1086 UnitTestHostBaseLibAsmFlushCacheLine (
1087 IN VOID *LinearAddress
1088 )
1089 {
1090 return LinearAddress;
1091 }
1092
1093 /**
1094 Enables the 32-bit paging mode on the CPU.
1095
1096 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
1097 must be properly initialized prior to calling this service. This function
1098 assumes the current execution mode is 32-bit protected mode. This function is
1099 only available on IA-32. After the 32-bit paging mode is enabled, control is
1100 transferred to the function specified by EntryPoint using the new stack
1101 specified by NewStack and passing in the parameters specified by Context1 and
1102 Context2. Context1 and Context2 are optional and may be NULL. The function
1103 EntryPoint must never return.
1104
1105 If the current execution mode is not 32-bit protected mode, then ASSERT().
1106 If EntryPoint is NULL, then ASSERT().
1107 If NewStack is NULL, then ASSERT().
1108
1109 There are a number of constraints that must be followed before calling this
1110 function:
1111 1) Interrupts must be disabled.
1112 2) The caller must be in 32-bit protected mode with flat descriptors. This
1113 means all descriptors must have a base of 0 and a limit of 4GB.
1114 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
1115 descriptors.
1116 4) CR3 must point to valid page tables that will be used once the transition
1117 is complete, and those page tables must guarantee that the pages for this
1118 function and the stack are identity mapped.
1119
1120 @param EntryPoint A pointer to function to call with the new stack after
1121 paging is enabled.
1122 @param Context1 A pointer to the context to pass into the EntryPoint
1123 function as the first parameter after paging is enabled.
1124 @param Context2 A pointer to the context to pass into the EntryPoint
1125 function as the second parameter after paging is enabled.
1126 @param NewStack A pointer to the new stack to use for the EntryPoint
1127 function after paging is enabled.
1128
1129 **/
1130 VOID
1131 EFIAPI
1132 UnitTestHostBaseLibAsmEnablePaging32 (
1133 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
1134 IN VOID *Context1 OPTIONAL,
1135 IN VOID *Context2 OPTIONAL,
1136 IN VOID *NewStack
1137 )
1138 {
1139 EntryPoint (Context1, Context2);
1140 }
1141
1142 /**
1143 Disables the 32-bit paging mode on the CPU.
1144
1145 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
1146 mode. This function assumes the current execution mode is 32-paged protected
1147 mode. This function is only available on IA-32. After the 32-bit paging mode
1148 is disabled, control is transferred to the function specified by EntryPoint
1149 using the new stack specified by NewStack and passing in the parameters
1150 specified by Context1 and Context2. Context1 and Context2 are optional and
1151 may be NULL. The function EntryPoint must never return.
1152
1153 If the current execution mode is not 32-bit paged mode, then ASSERT().
1154 If EntryPoint is NULL, then ASSERT().
1155 If NewStack is NULL, then ASSERT().
1156
1157 There are a number of constraints that must be followed before calling this
1158 function:
1159 1) Interrupts must be disabled.
1160 2) The caller must be in 32-bit paged mode.
1161 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
1162 4) CR3 must point to valid page tables that guarantee that the pages for
1163 this function and the stack are identity mapped.
1164
1165 @param EntryPoint A pointer to function to call with the new stack after
1166 paging is disabled.
1167 @param Context1 A pointer to the context to pass into the EntryPoint
1168 function as the first parameter after paging is disabled.
1169 @param Context2 A pointer to the context to pass into the EntryPoint
1170 function as the second parameter after paging is
1171 disabled.
1172 @param NewStack A pointer to the new stack to use for the EntryPoint
1173 function after paging is disabled.
1174
1175 **/
1176 VOID
1177 EFIAPI
1178 UnitTestHostBaseLibAsmDisablePaging32 (
1179 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
1180 IN VOID *Context1 OPTIONAL,
1181 IN VOID *Context2 OPTIONAL,
1182 IN VOID *NewStack
1183 )
1184 {
1185 EntryPoint (Context1, Context2);
1186 }
1187
1188 /**
1189 Enables the 64-bit paging mode on the CPU.
1190
1191 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
1192 must be properly initialized prior to calling this service. This function
1193 assumes the current execution mode is 32-bit protected mode with flat
1194 descriptors. This function is only available on IA-32. After the 64-bit
1195 paging mode is enabled, control is transferred to the function specified by
1196 EntryPoint using the new stack specified by NewStack and passing in the
1197 parameters specified by Context1 and Context2. Context1 and Context2 are
1198 optional and may be 0. The function EntryPoint must never return.
1199
1200 If the current execution mode is not 32-bit protected mode with flat
1201 descriptors, then ASSERT().
1202 If EntryPoint is 0, then ASSERT().
1203 If NewStack is 0, then ASSERT().
1204
1205 @param Cs The 16-bit selector to load in the CS before EntryPoint
1206 is called. The descriptor in the GDT that this selector
1207 references must be setup for long mode.
1208 @param EntryPoint The 64-bit virtual address of the function to call with
1209 the new stack after paging is enabled.
1210 @param Context1 The 64-bit virtual address of the context to pass into
1211 the EntryPoint function as the first parameter after
1212 paging is enabled.
1213 @param Context2 The 64-bit virtual address of the context to pass into
1214 the EntryPoint function as the second parameter after
1215 paging is enabled.
1216 @param NewStack The 64-bit virtual address of the new stack to use for
1217 the EntryPoint function after paging is enabled.
1218
1219 **/
1220 VOID
1221 EFIAPI
1222 UnitTestHostBaseLibAsmEnablePaging64 (
1223 IN UINT16 Cs,
1224 IN UINT64 EntryPoint,
1225 IN UINT64 Context1 OPTIONAL,
1226 IN UINT64 Context2 OPTIONAL,
1227 IN UINT64 NewStack
1228 )
1229 {
1230 SWITCH_STACK_ENTRY_POINT NewEntryPoint;
1231
1232 NewEntryPoint = (SWITCH_STACK_ENTRY_POINT)(UINTN)(EntryPoint);
1233 NewEntryPoint ((VOID *)(UINTN)Context1, (VOID *)(UINTN)Context2);
1234 }
1235
1236 /**
1237 Disables the 64-bit paging mode on the CPU.
1238
1239 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
1240 mode. This function assumes the current execution mode is 64-paging mode.
1241 This function is only available on x64. After the 64-bit paging mode is
1242 disabled, control is transferred to the function specified by EntryPoint
1243 using the new stack specified by NewStack and passing in the parameters
1244 specified by Context1 and Context2. Context1 and Context2 are optional and
1245 may be 0. The function EntryPoint must never return.
1246
1247 If the current execution mode is not 64-bit paged mode, then ASSERT().
1248 If EntryPoint is 0, then ASSERT().
1249 If NewStack is 0, then ASSERT().
1250
1251 @param Cs The 16-bit selector to load in the CS before EntryPoint
1252 is called. The descriptor in the GDT that this selector
1253 references must be setup for 32-bit protected mode.
1254 @param EntryPoint The 64-bit virtual address of the function to call with
1255 the new stack after paging is disabled.
1256 @param Context1 The 64-bit virtual address of the context to pass into
1257 the EntryPoint function as the first parameter after
1258 paging is disabled.
1259 @param Context2 The 64-bit virtual address of the context to pass into
1260 the EntryPoint function as the second parameter after
1261 paging is disabled.
1262 @param NewStack The 64-bit virtual address of the new stack to use for
1263 the EntryPoint function after paging is disabled.
1264
1265 **/
1266 VOID
1267 EFIAPI
1268 UnitTestHostBaseLibAsmDisablePaging64 (
1269 IN UINT16 Cs,
1270 IN UINT32 EntryPoint,
1271 IN UINT32 Context1 OPTIONAL,
1272 IN UINT32 Context2 OPTIONAL,
1273 IN UINT32 NewStack
1274 )
1275 {
1276 SWITCH_STACK_ENTRY_POINT NewEntryPoint;
1277
1278 NewEntryPoint = (SWITCH_STACK_ENTRY_POINT)(UINTN)(EntryPoint);
1279 NewEntryPoint ((VOID *)(UINTN)Context1, (VOID *)(UINTN)Context2);
1280 }
1281
1282 /**
1283 Retrieves the properties for 16-bit thunk functions.
1284
1285 Computes the size of the buffer and stack below 1MB required to use the
1286 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
1287 buffer size is returned in RealModeBufferSize, and the stack size is returned
1288 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
1289 then the actual minimum stack size is ExtraStackSize plus the maximum number
1290 of bytes that need to be passed to the 16-bit real mode code.
1291
1292 If RealModeBufferSize is NULL, then ASSERT().
1293 If ExtraStackSize is NULL, then ASSERT().
1294
1295 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
1296 required to use the 16-bit thunk functions.
1297 @param ExtraStackSize A pointer to the extra size of stack below 1MB
1298 that the 16-bit thunk functions require for
1299 temporary storage in the transition to and from
1300 16-bit real mode.
1301
1302 **/
1303 VOID
1304 EFIAPI
1305 UnitTestHostBaseLibAsmGetThunk16Properties (
1306 OUT UINT32 *RealModeBufferSize,
1307 OUT UINT32 *ExtraStackSize
1308 )
1309 {
1310 *RealModeBufferSize = 0;
1311 *ExtraStackSize = 0;
1312 }
1313
1314 /**
1315 Prepares all structures a code required to use AsmThunk16().
1316
1317 Prepares all structures and code required to use AsmThunk16().
1318
1319 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
1320 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
1321
1322 If ThunkContext is NULL, then ASSERT().
1323
1324 @param ThunkContext A pointer to the context structure that describes the
1325 16-bit real mode code to call.
1326
1327 **/
1328 VOID
1329 EFIAPI
1330 UnitTestHostBaseLibAsmPrepareThunk16 (
1331 IN OUT THUNK_CONTEXT *ThunkContext
1332 )
1333 {
1334 }
1335
1336 /**
1337 Transfers control to a 16-bit real mode entry point and returns the results.
1338
1339 Transfers control to a 16-bit real mode entry point and returns the results.
1340 AsmPrepareThunk16() must be called with ThunkContext before this function is used.
1341 This function must be called with interrupts disabled.
1342
1343 The register state from the RealModeState field of ThunkContext is restored just prior
1344 to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,
1345 which is used to set the interrupt state when a 16-bit real mode entry point is called.
1346 Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.
1347 The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to
1348 the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.
1349 The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,
1350 so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment
1351 and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry
1352 point must exit with a RETF instruction. The register state is captured into RealModeState immediately
1353 after the RETF instruction is executed.
1354
1355 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
1356 or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure
1357 the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.
1358
1359 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
1360 then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.
1361 This includes the base vectors, the interrupt masks, and the edge/level trigger mode.
1362
1363 If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code
1364 is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.
1365
1366 If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
1367 ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to
1368 disable the A20 mask.
1369
1370 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in
1371 ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,
1372 then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
1373
1374 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in
1375 ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
1376
1377 If ThunkContext is NULL, then ASSERT().
1378 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
1379 If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
1380 ThunkAttributes, then ASSERT().
1381
1382 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
1383 virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.
1384
1385 @param ThunkContext A pointer to the context structure that describes the
1386 16-bit real mode code to call.
1387
1388 **/
1389 VOID
1390 EFIAPI
1391 UnitTestHostBaseLibAsmThunk16 (
1392 IN OUT THUNK_CONTEXT *ThunkContext
1393 )
1394 {
1395 }
1396
1397 /**
1398 Prepares all structures and code for a 16-bit real mode thunk, transfers
1399 control to a 16-bit real mode entry point, and returns the results.
1400
1401 Prepares all structures and code for a 16-bit real mode thunk, transfers
1402 control to a 16-bit real mode entry point, and returns the results. If the
1403 caller only need to perform a single 16-bit real mode thunk, then this
1404 service should be used. If the caller intends to make more than one 16-bit
1405 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
1406 once and AsmThunk16() can be called for each 16-bit real mode thunk.
1407
1408 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
1409 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
1410
1411 See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.
1412
1413 @param ThunkContext A pointer to the context structure that describes the
1414 16-bit real mode code to call.
1415
1416 **/
1417 VOID
1418 EFIAPI
1419 UnitTestHostBaseLibAsmPrepareAndThunk16 (
1420 IN OUT THUNK_CONTEXT *ThunkContext
1421 )
1422 {
1423 }
1424
1425 /**
1426 Load given selector into TR register.
1427
1428 @param[in] Selector Task segment selector
1429 **/
1430 VOID
1431 EFIAPI
1432 UnitTestHostBaseLibAsmWriteTr (
1433 IN UINT16 Selector
1434 )
1435 {
1436 mUnitTestHostBaseLibSegment[UNIT_TEST_HOST_BASE_LIB_SEGMENT_TR] = Selector;
1437 }
1438
1439 /**
1440 Performs a serializing operation on all load-from-memory instructions that
1441 were issued prior the AsmLfence function.
1442
1443 Executes a LFENCE instruction. This function is only available on IA-32 and x64.
1444
1445 **/
1446 VOID
1447 EFIAPI
1448 UnitTestHostBaseLibAsmLfence (
1449 VOID
1450 )
1451 {
1452 }
1453
1454 /**
1455 Patch the immediate operand of an IA32 or X64 instruction such that the byte,
1456 word, dword or qword operand is encoded at the end of the instruction's
1457 binary representation.
1458
1459 This function should be used to update object code that was compiled with
1460 NASM from assembly source code. Example:
1461
1462 NASM source code:
1463
1464 mov eax, strict dword 0 ; the imm32 zero operand will be patched
1465 ASM_PFX(gPatchCr3):
1466 mov cr3, eax
1467
1468 C source code:
1469
1470 X86_ASSEMBLY_PATCH_LABEL gPatchCr3;
1471 PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);
1472
1473 @param[out] InstructionEnd Pointer right past the instruction to patch. The
1474 immediate operand to patch is expected to
1475 comprise the trailing bytes of the instruction.
1476 If InstructionEnd is closer to address 0 than
1477 ValueSize permits, then ASSERT().
1478
1479 @param[in] PatchValue The constant to write to the immediate operand.
1480 The caller is responsible for ensuring that
1481 PatchValue can be represented in the byte, word,
1482 dword or qword operand (as indicated through
1483 ValueSize); otherwise ASSERT().
1484
1485 @param[in] ValueSize The size of the operand in bytes; must be 1, 2,
1486 4, or 8. ASSERT() otherwise.
1487 **/
1488 VOID
1489 EFIAPI
1490 UnitTestHostBaseLibPatchInstructionX86 (
1491 OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,
1492 IN UINT64 PatchValue,
1493 IN UINTN ValueSize
1494 )
1495 {
1496 }
1497
1498 /**
1499 Retrieves CPUID information.
1500
1501 Executes the CPUID instruction with EAX set to the value specified by Index.
1502 This function always returns Index.
1503 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
1504 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
1505 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
1506 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
1507 This function is only available on IA-32 and x64.
1508
1509 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
1510 instruction.
1511 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
1512 instruction. This is an optional parameter that may be NULL.
1513 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
1514 instruction. This is an optional parameter that may be NULL.
1515 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
1516 instruction. This is an optional parameter that may be NULL.
1517 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
1518 instruction. This is an optional parameter that may be NULL.
1519
1520 @return Index.
1521
1522 **/
1523 UINT32
1524 EFIAPI
1525 AsmCpuid (
1526 IN UINT32 Index,
1527 OUT UINT32 *Eax OPTIONAL,
1528 OUT UINT32 *Ebx OPTIONAL,
1529 OUT UINT32 *Ecx OPTIONAL,
1530 OUT UINT32 *Edx OPTIONAL
1531 )
1532 {
1533 return gUnitTestHostBaseLib.X86->AsmCpuid (Index, Eax, Ebx, Ecx, Edx);
1534 }
1535
1536 /**
1537 Retrieves CPUID information using an extended leaf identifier.
1538
1539 Executes the CPUID instruction with EAX set to the value specified by Index
1540 and ECX set to the value specified by SubIndex. This function always returns
1541 Index. This function is only available on IA-32 and x64.
1542
1543 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
1544 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
1545 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
1546 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
1547
1548 @param Index The 32-bit value to load into EAX prior to invoking the
1549 CPUID instruction.
1550 @param SubIndex The 32-bit value to load into ECX prior to invoking the
1551 CPUID instruction.
1552 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
1553 instruction. This is an optional parameter that may be
1554 NULL.
1555 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
1556 instruction. This is an optional parameter that may be
1557 NULL.
1558 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
1559 instruction. This is an optional parameter that may be
1560 NULL.
1561 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
1562 instruction. This is an optional parameter that may be
1563 NULL.
1564
1565 @return Index.
1566
1567 **/
1568 UINT32
1569 EFIAPI
1570 AsmCpuidEx (
1571 IN UINT32 Index,
1572 IN UINT32 SubIndex,
1573 OUT UINT32 *Eax OPTIONAL,
1574 OUT UINT32 *Ebx OPTIONAL,
1575 OUT UINT32 *Ecx OPTIONAL,
1576 OUT UINT32 *Edx OPTIONAL
1577 )
1578 {
1579 return gUnitTestHostBaseLib.X86->AsmCpuidEx (Index, SubIndex, Eax, Ebx, Ecx, Edx);
1580 }
1581
1582 /**
1583 Set CD bit and clear NW bit of CR0 followed by a WBINVD.
1584
1585 Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,
1586 and executing a WBINVD instruction. This function is only available on IA-32 and x64.
1587
1588 **/
1589 VOID
1590 EFIAPI
1591 AsmDisableCache (
1592 VOID
1593 )
1594 {
1595 gUnitTestHostBaseLib.X86->AsmDisableCache ();
1596 }
1597
1598 /**
1599 Perform a WBINVD and clear both the CD and NW bits of CR0.
1600
1601 Enables the caches by executing a WBINVD instruction and then clear both the CD and NW
1602 bits of CR0 to 0. This function is only available on IA-32 and x64.
1603
1604 **/
1605 VOID
1606 EFIAPI
1607 AsmEnableCache (
1608 VOID
1609 )
1610 {
1611 gUnitTestHostBaseLib.X86->AsmEnableCache ();
1612 }
1613
1614 /**
1615 Returns a 64-bit Machine Specific Register(MSR).
1616
1617 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
1618 performed on Index, and some Index values may cause CPU exceptions. The
1619 caller must either guarantee that Index is valid, or the caller must set up
1620 exception handlers to catch the exceptions. This function is only available
1621 on IA-32 and x64.
1622
1623 @param Index The 32-bit MSR index to read.
1624
1625 @return The value of the MSR identified by Index.
1626
1627 **/
1628 UINT64
1629 EFIAPI
1630 AsmReadMsr64 (
1631 IN UINT32 Index
1632 )
1633 {
1634 return gUnitTestHostBaseLib.X86->AsmReadMsr64 (Index);
1635 }
1636
1637 /**
1638 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
1639 value.
1640
1641 Writes the 64-bit value specified by Value to the MSR specified by Index. The
1642 64-bit value written to the MSR is returned. No parameter checking is
1643 performed on Index or Value, and some of these may cause CPU exceptions. The
1644 caller must either guarantee that Index and Value are valid, or the caller
1645 must establish proper exception handlers. This function is only available on
1646 IA-32 and x64.
1647
1648 @param Index The 32-bit MSR index to write.
1649 @param Value The 64-bit value to write to the MSR.
1650
1651 @return Value
1652
1653 **/
1654 UINT64
1655 EFIAPI
1656 AsmWriteMsr64 (
1657 IN UINT32 Index,
1658 IN UINT64 Value
1659 )
1660 {
1661 return gUnitTestHostBaseLib.X86->AsmWriteMsr64 (Index, Value);
1662 }
1663
1664 /**
1665 Reads the current value of the Control Register 0 (CR0).
1666
1667 Reads and returns the current value of CR0. This function is only available
1668 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1669 x64.
1670
1671 @return The value of the Control Register 0 (CR0).
1672
1673 **/
1674 UINTN
1675 EFIAPI
1676 AsmReadCr0 (
1677 VOID
1678 )
1679 {
1680 return gUnitTestHostBaseLib.X86->AsmReadCr0 ();
1681 }
1682
1683 /**
1684 Reads the current value of the Control Register 2 (CR2).
1685
1686 Reads and returns the current value of CR2. This function is only available
1687 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1688 x64.
1689
1690 @return The value of the Control Register 2 (CR2).
1691
1692 **/
1693 UINTN
1694 EFIAPI
1695 AsmReadCr2 (
1696 VOID
1697 )
1698 {
1699 return gUnitTestHostBaseLib.X86->AsmReadCr2 ();
1700 }
1701
1702 /**
1703 Reads the current value of the Control Register 3 (CR3).
1704
1705 Reads and returns the current value of CR3. This function is only available
1706 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1707 x64.
1708
1709 @return The value of the Control Register 3 (CR3).
1710
1711 **/
1712 UINTN
1713 EFIAPI
1714 AsmReadCr3 (
1715 VOID
1716 )
1717 {
1718 return gUnitTestHostBaseLib.X86->AsmReadCr3 ();
1719 }
1720
1721 /**
1722 Reads the current value of the Control Register 4 (CR4).
1723
1724 Reads and returns the current value of CR4. This function is only available
1725 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1726 x64.
1727
1728 @return The value of the Control Register 4 (CR4).
1729
1730 **/
1731 UINTN
1732 EFIAPI
1733 AsmReadCr4 (
1734 VOID
1735 )
1736 {
1737 return gUnitTestHostBaseLib.X86->AsmReadCr4 ();
1738 }
1739
1740 /**
1741 Writes a value to Control Register 0 (CR0).
1742
1743 Writes and returns a new value to CR0. This function is only available on
1744 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
1745
1746 @param Cr0 The value to write to CR0.
1747
1748 @return The value written to CR0.
1749
1750 **/
1751 UINTN
1752 EFIAPI
1753 AsmWriteCr0 (
1754 UINTN Cr0
1755 )
1756 {
1757 return gUnitTestHostBaseLib.X86->AsmWriteCr0 (Cr0);
1758 }
1759
1760 /**
1761 Writes a value to Control Register 2 (CR2).
1762
1763 Writes and returns a new value to CR2. This function is only available on
1764 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
1765
1766 @param Cr2 The value to write to CR2.
1767
1768 @return The value written to CR2.
1769
1770 **/
1771 UINTN
1772 EFIAPI
1773 AsmWriteCr2 (
1774 UINTN Cr2
1775 )
1776 {
1777 return gUnitTestHostBaseLib.X86->AsmWriteCr2 (Cr2);
1778 }
1779
1780 /**
1781 Writes a value to Control Register 3 (CR3).
1782
1783 Writes and returns a new value to CR3. This function is only available on
1784 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
1785
1786 @param Cr3 The value to write to CR3.
1787
1788 @return The value written to CR3.
1789
1790 **/
1791 UINTN
1792 EFIAPI
1793 AsmWriteCr3 (
1794 UINTN Cr3
1795 )
1796 {
1797 return gUnitTestHostBaseLib.X86->AsmWriteCr3 (Cr3);
1798 }
1799
1800 /**
1801 Writes a value to Control Register 4 (CR4).
1802
1803 Writes and returns a new value to CR4. This function is only available on
1804 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
1805
1806 @param Cr4 The value to write to CR4.
1807
1808 @return The value written to CR4.
1809
1810 **/
1811 UINTN
1812 EFIAPI
1813 AsmWriteCr4 (
1814 UINTN Cr4
1815 )
1816 {
1817 return gUnitTestHostBaseLib.X86->AsmWriteCr4 (Cr4);
1818 }
1819
1820 /**
1821 Reads the current value of Debug Register 0 (DR0).
1822
1823 Reads and returns the current value of DR0. This function is only available
1824 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1825 x64.
1826
1827 @return The value of Debug Register 0 (DR0).
1828
1829 **/
1830 UINTN
1831 EFIAPI
1832 AsmReadDr0 (
1833 VOID
1834 )
1835 {
1836 return gUnitTestHostBaseLib.X86->AsmReadDr0 ();
1837 }
1838
1839 /**
1840 Reads the current value of Debug Register 1 (DR1).
1841
1842 Reads and returns the current value of DR1. This function is only available
1843 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1844 x64.
1845
1846 @return The value of Debug Register 1 (DR1).
1847
1848 **/
1849 UINTN
1850 EFIAPI
1851 AsmReadDr1 (
1852 VOID
1853 )
1854 {
1855 return gUnitTestHostBaseLib.X86->AsmReadDr1 ();
1856 }
1857
1858 /**
1859 Reads the current value of Debug Register 2 (DR2).
1860
1861 Reads and returns the current value of DR2. This function is only available
1862 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1863 x64.
1864
1865 @return The value of Debug Register 2 (DR2).
1866
1867 **/
1868 UINTN
1869 EFIAPI
1870 AsmReadDr2 (
1871 VOID
1872 )
1873 {
1874 return gUnitTestHostBaseLib.X86->AsmReadDr2 ();
1875 }
1876
1877 /**
1878 Reads the current value of Debug Register 3 (DR3).
1879
1880 Reads and returns the current value of DR3. This function is only available
1881 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1882 x64.
1883
1884 @return The value of Debug Register 3 (DR3).
1885
1886 **/
1887 UINTN
1888 EFIAPI
1889 AsmReadDr3 (
1890 VOID
1891 )
1892 {
1893 return gUnitTestHostBaseLib.X86->AsmReadDr3 ();
1894 }
1895
1896 /**
1897 Reads the current value of Debug Register 4 (DR4).
1898
1899 Reads and returns the current value of DR4. This function is only available
1900 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1901 x64.
1902
1903 @return The value of Debug Register 4 (DR4).
1904
1905 **/
1906 UINTN
1907 EFIAPI
1908 AsmReadDr4 (
1909 VOID
1910 )
1911 {
1912 return gUnitTestHostBaseLib.X86->AsmReadDr4 ();
1913 }
1914
1915 /**
1916 Reads the current value of Debug Register 5 (DR5).
1917
1918 Reads and returns the current value of DR5. This function is only available
1919 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1920 x64.
1921
1922 @return The value of Debug Register 5 (DR5).
1923
1924 **/
1925 UINTN
1926 EFIAPI
1927 AsmReadDr5 (
1928 VOID
1929 )
1930 {
1931 return gUnitTestHostBaseLib.X86->AsmReadDr5 ();
1932 }
1933
1934 /**
1935 Reads the current value of Debug Register 6 (DR6).
1936
1937 Reads and returns the current value of DR6. This function is only available
1938 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1939 x64.
1940
1941 @return The value of Debug Register 6 (DR6).
1942
1943 **/
1944 UINTN
1945 EFIAPI
1946 AsmReadDr6 (
1947 VOID
1948 )
1949 {
1950 return gUnitTestHostBaseLib.X86->AsmReadDr6 ();
1951 }
1952
1953 /**
1954 Reads the current value of Debug Register 7 (DR7).
1955
1956 Reads and returns the current value of DR7. This function is only available
1957 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
1958 x64.
1959
1960 @return The value of Debug Register 7 (DR7).
1961
1962 **/
1963 UINTN
1964 EFIAPI
1965 AsmReadDr7 (
1966 VOID
1967 )
1968 {
1969 return gUnitTestHostBaseLib.X86->AsmReadDr7 ();
1970 }
1971
1972 /**
1973 Writes a value to Debug Register 0 (DR0).
1974
1975 Writes and returns a new value to DR0. This function is only available on
1976 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
1977
1978 @param Dr0 The value to write to Dr0.
1979
1980 @return The value written to Debug Register 0 (DR0).
1981
1982 **/
1983 UINTN
1984 EFIAPI
1985 AsmWriteDr0 (
1986 UINTN Dr0
1987 )
1988 {
1989 return gUnitTestHostBaseLib.X86->AsmWriteDr0 (Dr0);
1990 }
1991
1992 /**
1993 Writes a value to Debug Register 1 (DR1).
1994
1995 Writes and returns a new value to DR1. This function is only available on
1996 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
1997
1998 @param Dr1 The value to write to Dr1.
1999
2000 @return The value written to Debug Register 1 (DR1).
2001
2002 **/
2003 UINTN
2004 EFIAPI
2005 AsmWriteDr1 (
2006 UINTN Dr1
2007 )
2008 {
2009 return gUnitTestHostBaseLib.X86->AsmWriteDr1 (Dr1);
2010 }
2011
2012 /**
2013 Writes a value to Debug Register 2 (DR2).
2014
2015 Writes and returns a new value to DR2. This function is only available on
2016 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
2017
2018 @param Dr2 The value to write to Dr2.
2019
2020 @return The value written to Debug Register 2 (DR2).
2021
2022 **/
2023 UINTN
2024 EFIAPI
2025 AsmWriteDr2 (
2026 UINTN Dr2
2027 )
2028 {
2029 return gUnitTestHostBaseLib.X86->AsmWriteDr2 (Dr2);
2030 }
2031
2032 /**
2033 Writes a value to Debug Register 3 (DR3).
2034
2035 Writes and returns a new value to DR3. This function is only available on
2036 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
2037
2038 @param Dr3 The value to write to Dr3.
2039
2040 @return The value written to Debug Register 3 (DR3).
2041
2042 **/
2043 UINTN
2044 EFIAPI
2045 AsmWriteDr3 (
2046 UINTN Dr3
2047 )
2048 {
2049 return gUnitTestHostBaseLib.X86->AsmWriteDr3 (Dr3);
2050 }
2051
2052 /**
2053 Writes a value to Debug Register 4 (DR4).
2054
2055 Writes and returns a new value to DR4. This function is only available on
2056 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
2057
2058 @param Dr4 The value to write to Dr4.
2059
2060 @return The value written to Debug Register 4 (DR4).
2061
2062 **/
2063 UINTN
2064 EFIAPI
2065 AsmWriteDr4 (
2066 UINTN Dr4
2067 )
2068 {
2069 return gUnitTestHostBaseLib.X86->AsmWriteDr4 (Dr4);
2070 }
2071
2072 /**
2073 Writes a value to Debug Register 5 (DR5).
2074
2075 Writes and returns a new value to DR5. This function is only available on
2076 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
2077
2078 @param Dr5 The value to write to Dr5.
2079
2080 @return The value written to Debug Register 5 (DR5).
2081
2082 **/
2083 UINTN
2084 EFIAPI
2085 AsmWriteDr5 (
2086 UINTN Dr5
2087 )
2088 {
2089 return gUnitTestHostBaseLib.X86->AsmWriteDr5 (Dr5);
2090 }
2091
2092 /**
2093 Writes a value to Debug Register 6 (DR6).
2094
2095 Writes and returns a new value to DR6. This function is only available on
2096 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
2097
2098 @param Dr6 The value to write to Dr6.
2099
2100 @return The value written to Debug Register 6 (DR6).
2101
2102 **/
2103 UINTN
2104 EFIAPI
2105 AsmWriteDr6 (
2106 UINTN Dr6
2107 )
2108 {
2109 return gUnitTestHostBaseLib.X86->AsmWriteDr6 (Dr6);
2110 }
2111
2112 /**
2113 Writes a value to Debug Register 7 (DR7).
2114
2115 Writes and returns a new value to DR7. This function is only available on
2116 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
2117
2118 @param Dr7 The value to write to Dr7.
2119
2120 @return The value written to Debug Register 7 (DR7).
2121
2122 **/
2123 UINTN
2124 EFIAPI
2125 AsmWriteDr7 (
2126 UINTN Dr7
2127 )
2128 {
2129 return gUnitTestHostBaseLib.X86->AsmWriteDr7 (Dr7);
2130 }
2131
2132 /**
2133 Reads the current value of Code Segment Register (CS).
2134
2135 Reads and returns the current value of CS. This function is only available on
2136 IA-32 and x64.
2137
2138 @return The current value of CS.
2139
2140 **/
2141 UINT16
2142 EFIAPI
2143 AsmReadCs (
2144 VOID
2145 )
2146 {
2147 return gUnitTestHostBaseLib.X86->AsmReadCs ();
2148 }
2149
2150 /**
2151 Reads the current value of Data Segment Register (DS).
2152
2153 Reads and returns the current value of DS. This function is only available on
2154 IA-32 and x64.
2155
2156 @return The current value of DS.
2157
2158 **/
2159 UINT16
2160 EFIAPI
2161 AsmReadDs (
2162 VOID
2163 )
2164 {
2165 return gUnitTestHostBaseLib.X86->AsmReadDs ();
2166 }
2167
2168 /**
2169 Reads the current value of Extra Segment Register (ES).
2170
2171 Reads and returns the current value of ES. This function is only available on
2172 IA-32 and x64.
2173
2174 @return The current value of ES.
2175
2176 **/
2177 UINT16
2178 EFIAPI
2179 AsmReadEs (
2180 VOID
2181 )
2182 {
2183 return gUnitTestHostBaseLib.X86->AsmReadEs ();
2184 }
2185
2186 /**
2187 Reads the current value of FS Data Segment Register (FS).
2188
2189 Reads and returns the current value of FS. This function is only available on
2190 IA-32 and x64.
2191
2192 @return The current value of FS.
2193
2194 **/
2195 UINT16
2196 EFIAPI
2197 AsmReadFs (
2198 VOID
2199 )
2200 {
2201 return gUnitTestHostBaseLib.X86->AsmReadFs ();
2202 }
2203
2204 /**
2205 Reads the current value of GS Data Segment Register (GS).
2206
2207 Reads and returns the current value of GS. This function is only available on
2208 IA-32 and x64.
2209
2210 @return The current value of GS.
2211
2212 **/
2213 UINT16
2214 EFIAPI
2215 AsmReadGs (
2216 VOID
2217 )
2218 {
2219 return gUnitTestHostBaseLib.X86->AsmReadGs ();
2220 }
2221
2222 /**
2223 Reads the current value of Stack Segment Register (SS).
2224
2225 Reads and returns the current value of SS. This function is only available on
2226 IA-32 and x64.
2227
2228 @return The current value of SS.
2229
2230 **/
2231 UINT16
2232 EFIAPI
2233 AsmReadSs (
2234 VOID
2235 )
2236 {
2237 return gUnitTestHostBaseLib.X86->AsmReadSs ();
2238 }
2239
2240 /**
2241 Reads the current value of Task Register (TR).
2242
2243 Reads and returns the current value of TR. This function is only available on
2244 IA-32 and x64.
2245
2246 @return The current value of TR.
2247
2248 **/
2249 UINT16
2250 EFIAPI
2251 AsmReadTr (
2252 VOID
2253 )
2254 {
2255 return gUnitTestHostBaseLib.X86->AsmReadTr ();
2256 }
2257
2258 /**
2259 Reads the current Global Descriptor Table Register(GDTR) descriptor.
2260
2261 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
2262 function is only available on IA-32 and x64.
2263
2264 If Gdtr is NULL, then ASSERT().
2265
2266 @param Gdtr The pointer to a GDTR descriptor.
2267
2268 **/
2269 VOID
2270 EFIAPI
2271 AsmReadGdtr (
2272 OUT IA32_DESCRIPTOR *Gdtr
2273 )
2274 {
2275 gUnitTestHostBaseLib.X86->AsmReadGdtr (Gdtr);
2276 }
2277
2278 /**
2279 Writes the current Global Descriptor Table Register (GDTR) descriptor.
2280
2281 Writes and the current GDTR descriptor specified by Gdtr. This function is
2282 only available on IA-32 and x64.
2283
2284 If Gdtr is NULL, then ASSERT().
2285
2286 @param Gdtr The pointer to a GDTR descriptor.
2287
2288 **/
2289 VOID
2290 EFIAPI
2291 AsmWriteGdtr (
2292 IN CONST IA32_DESCRIPTOR *Gdtr
2293 )
2294 {
2295 gUnitTestHostBaseLib.X86->AsmWriteGdtr (Gdtr);
2296 }
2297
2298 /**
2299 Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.
2300
2301 Reads and returns the current IDTR descriptor and returns it in Idtr. This
2302 function is only available on IA-32 and x64.
2303
2304 If Idtr is NULL, then ASSERT().
2305
2306 @param Idtr The pointer to a IDTR descriptor.
2307
2308 **/
2309 VOID
2310 EFIAPI
2311 AsmReadIdtr (
2312 OUT IA32_DESCRIPTOR *Idtr
2313 )
2314 {
2315 gUnitTestHostBaseLib.X86->AsmReadIdtr (Idtr);
2316 }
2317
2318 /**
2319 Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.
2320
2321 Writes the current IDTR descriptor and returns it in Idtr. This function is
2322 only available on IA-32 and x64.
2323
2324 If Idtr is NULL, then ASSERT().
2325
2326 @param Idtr The pointer to a IDTR descriptor.
2327
2328 **/
2329 VOID
2330 EFIAPI
2331 AsmWriteIdtr (
2332 IN CONST IA32_DESCRIPTOR *Idtr
2333 )
2334 {
2335 gUnitTestHostBaseLib.X86->AsmWriteIdtr (Idtr);
2336 }
2337
2338 /**
2339 Reads the current Local Descriptor Table Register(LDTR) selector.
2340
2341 Reads and returns the current 16-bit LDTR descriptor value. This function is
2342 only available on IA-32 and x64.
2343
2344 @return The current selector of LDT.
2345
2346 **/
2347 UINT16
2348 EFIAPI
2349 AsmReadLdtr (
2350 VOID
2351 )
2352 {
2353 return gUnitTestHostBaseLib.X86->AsmReadLdtr ();
2354 }
2355
2356 /**
2357 Writes the current Local Descriptor Table Register (LDTR) selector.
2358
2359 Writes and the current LDTR descriptor specified by Ldtr. This function is
2360 only available on IA-32 and x64.
2361
2362 @param Ldtr 16-bit LDTR selector value.
2363
2364 **/
2365 VOID
2366 EFIAPI
2367 AsmWriteLdtr (
2368 IN UINT16 Ldtr
2369 )
2370 {
2371 gUnitTestHostBaseLib.X86->AsmWriteLdtr (Ldtr);
2372 }
2373
2374 /**
2375 Reads the current value of a Performance Counter (PMC).
2376
2377 Reads and returns the current value of performance counter specified by
2378 Index. This function is only available on IA-32 and x64.
2379
2380 @param Index The 32-bit Performance Counter index to read.
2381
2382 @return The value of the PMC specified by Index.
2383
2384 **/
2385 UINT64
2386 EFIAPI
2387 AsmReadPmc (
2388 IN UINT32 Index
2389 )
2390 {
2391 return gUnitTestHostBaseLib.X86->AsmReadPmc (Index);
2392 }
2393
2394 /**
2395 Sets up a monitor buffer that is used by AsmMwait().
2396
2397 Executes a MONITOR instruction with the register state specified by Eax, Ecx
2398 and Edx. Returns Eax. This function is only available on IA-32 and x64.
2399
2400 @param Eax The value to load into EAX or RAX before executing the MONITOR
2401 instruction.
2402 @param Ecx The value to load into ECX or RCX before executing the MONITOR
2403 instruction.
2404 @param Edx The value to load into EDX or RDX before executing the MONITOR
2405 instruction.
2406
2407 @return Eax
2408
2409 **/
2410 UINTN
2411 EFIAPI
2412 AsmMonitor (
2413 IN UINTN Eax,
2414 IN UINTN Ecx,
2415 IN UINTN Edx
2416 )
2417 {
2418 return gUnitTestHostBaseLib.X86->AsmMonitor (Eax, Ecx, Edx);
2419 }
2420
2421 /**
2422 Executes an MWAIT instruction.
2423
2424 Executes an MWAIT instruction with the register state specified by Eax and
2425 Ecx. Returns Eax. This function is only available on IA-32 and x64.
2426
2427 @param Eax The value to load into EAX or RAX before executing the MONITOR
2428 instruction.
2429 @param Ecx The value to load into ECX or RCX before executing the MONITOR
2430 instruction.
2431
2432 @return Eax
2433
2434 **/
2435 UINTN
2436 EFIAPI
2437 AsmMwait (
2438 IN UINTN Eax,
2439 IN UINTN Ecx
2440 )
2441 {
2442 return gUnitTestHostBaseLib.X86->AsmMwait (Eax, Ecx);
2443 }
2444
2445 /**
2446 Executes a WBINVD instruction.
2447
2448 Executes a WBINVD instruction. This function is only available on IA-32 and
2449 x64.
2450
2451 **/
2452 VOID
2453 EFIAPI
2454 AsmWbinvd (
2455 VOID
2456 )
2457 {
2458 gUnitTestHostBaseLib.X86->AsmWbinvd ();
2459 }
2460
2461 /**
2462 Executes a INVD instruction.
2463
2464 Executes a INVD instruction. This function is only available on IA-32 and
2465 x64.
2466
2467 **/
2468 VOID
2469 EFIAPI
2470 AsmInvd (
2471 VOID
2472 )
2473 {
2474 gUnitTestHostBaseLib.X86->AsmInvd ();
2475 }
2476
2477 /**
2478 Flushes a cache line from all the instruction and data caches within the
2479 coherency domain of the CPU.
2480
2481 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
2482 This function is only available on IA-32 and x64.
2483
2484 @param LinearAddress The address of the cache line to flush. If the CPU is
2485 in a physical addressing mode, then LinearAddress is a
2486 physical address. If the CPU is in a virtual
2487 addressing mode, then LinearAddress is a virtual
2488 address.
2489
2490 @return LinearAddress.
2491 **/
2492 VOID *
2493 EFIAPI
2494 AsmFlushCacheLine (
2495 IN VOID *LinearAddress
2496 )
2497 {
2498 return gUnitTestHostBaseLib.X86->AsmFlushCacheLine (LinearAddress);
2499 }
2500
2501 /**
2502 Enables the 32-bit paging mode on the CPU.
2503
2504 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
2505 must be properly initialized prior to calling this service. This function
2506 assumes the current execution mode is 32-bit protected mode. This function is
2507 only available on IA-32. After the 32-bit paging mode is enabled, control is
2508 transferred to the function specified by EntryPoint using the new stack
2509 specified by NewStack and passing in the parameters specified by Context1 and
2510 Context2. Context1 and Context2 are optional and may be NULL. The function
2511 EntryPoint must never return.
2512
2513 If the current execution mode is not 32-bit protected mode, then ASSERT().
2514 If EntryPoint is NULL, then ASSERT().
2515 If NewStack is NULL, then ASSERT().
2516
2517 There are a number of constraints that must be followed before calling this
2518 function:
2519 1) Interrupts must be disabled.
2520 2) The caller must be in 32-bit protected mode with flat descriptors. This
2521 means all descriptors must have a base of 0 and a limit of 4GB.
2522 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
2523 descriptors.
2524 4) CR3 must point to valid page tables that will be used once the transition
2525 is complete, and those page tables must guarantee that the pages for this
2526 function and the stack are identity mapped.
2527
2528 @param EntryPoint A pointer to function to call with the new stack after
2529 paging is enabled.
2530 @param Context1 A pointer to the context to pass into the EntryPoint
2531 function as the first parameter after paging is enabled.
2532 @param Context2 A pointer to the context to pass into the EntryPoint
2533 function as the second parameter after paging is enabled.
2534 @param NewStack A pointer to the new stack to use for the EntryPoint
2535 function after paging is enabled.
2536
2537 **/
2538 VOID
2539 EFIAPI
2540 AsmEnablePaging32 (
2541 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
2542 IN VOID *Context1 OPTIONAL,
2543 IN VOID *Context2 OPTIONAL,
2544 IN VOID *NewStack
2545 )
2546 {
2547 gUnitTestHostBaseLib.X86->AsmEnablePaging32 (EntryPoint, Context1, Context2, NewStack);
2548 }
2549
2550 /**
2551 Disables the 32-bit paging mode on the CPU.
2552
2553 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
2554 mode. This function assumes the current execution mode is 32-paged protected
2555 mode. This function is only available on IA-32. After the 32-bit paging mode
2556 is disabled, control is transferred to the function specified by EntryPoint
2557 using the new stack specified by NewStack and passing in the parameters
2558 specified by Context1 and Context2. Context1 and Context2 are optional and
2559 may be NULL. The function EntryPoint must never return.
2560
2561 If the current execution mode is not 32-bit paged mode, then ASSERT().
2562 If EntryPoint is NULL, then ASSERT().
2563 If NewStack is NULL, then ASSERT().
2564
2565 There are a number of constraints that must be followed before calling this
2566 function:
2567 1) Interrupts must be disabled.
2568 2) The caller must be in 32-bit paged mode.
2569 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
2570 4) CR3 must point to valid page tables that guarantee that the pages for
2571 this function and the stack are identity mapped.
2572
2573 @param EntryPoint A pointer to function to call with the new stack after
2574 paging is disabled.
2575 @param Context1 A pointer to the context to pass into the EntryPoint
2576 function as the first parameter after paging is disabled.
2577 @param Context2 A pointer to the context to pass into the EntryPoint
2578 function as the second parameter after paging is
2579 disabled.
2580 @param NewStack A pointer to the new stack to use for the EntryPoint
2581 function after paging is disabled.
2582
2583 **/
2584 VOID
2585 EFIAPI
2586 AsmDisablePaging32 (
2587 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
2588 IN VOID *Context1 OPTIONAL,
2589 IN VOID *Context2 OPTIONAL,
2590 IN VOID *NewStack
2591 )
2592 {
2593 gUnitTestHostBaseLib.X86->AsmDisablePaging32 (EntryPoint, Context1, Context2, NewStack);
2594 }
2595
2596 /**
2597 Enables the 64-bit paging mode on the CPU.
2598
2599 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
2600 must be properly initialized prior to calling this service. This function
2601 assumes the current execution mode is 32-bit protected mode with flat
2602 descriptors. This function is only available on IA-32. After the 64-bit
2603 paging mode is enabled, control is transferred to the function specified by
2604 EntryPoint using the new stack specified by NewStack and passing in the
2605 parameters specified by Context1 and Context2. Context1 and Context2 are
2606 optional and may be 0. The function EntryPoint must never return.
2607
2608 If the current execution mode is not 32-bit protected mode with flat
2609 descriptors, then ASSERT().
2610 If EntryPoint is 0, then ASSERT().
2611 If NewStack is 0, then ASSERT().
2612
2613 @param Cs The 16-bit selector to load in the CS before EntryPoint
2614 is called. The descriptor in the GDT that this selector
2615 references must be setup for long mode.
2616 @param EntryPoint The 64-bit virtual address of the function to call with
2617 the new stack after paging is enabled.
2618 @param Context1 The 64-bit virtual address of the context to pass into
2619 the EntryPoint function as the first parameter after
2620 paging is enabled.
2621 @param Context2 The 64-bit virtual address of the context to pass into
2622 the EntryPoint function as the second parameter after
2623 paging is enabled.
2624 @param NewStack The 64-bit virtual address of the new stack to use for
2625 the EntryPoint function after paging is enabled.
2626
2627 **/
2628 VOID
2629 EFIAPI
2630 AsmEnablePaging64 (
2631 IN UINT16 Cs,
2632 IN UINT64 EntryPoint,
2633 IN UINT64 Context1 OPTIONAL,
2634 IN UINT64 Context2 OPTIONAL,
2635 IN UINT64 NewStack
2636 )
2637 {
2638 gUnitTestHostBaseLib.X86->AsmEnablePaging64 (Cs, EntryPoint, Context1, Context2, NewStack);
2639 }
2640
2641 /**
2642 Disables the 64-bit paging mode on the CPU.
2643
2644 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
2645 mode. This function assumes the current execution mode is 64-paging mode.
2646 This function is only available on x64. After the 64-bit paging mode is
2647 disabled, control is transferred to the function specified by EntryPoint
2648 using the new stack specified by NewStack and passing in the parameters
2649 specified by Context1 and Context2. Context1 and Context2 are optional and
2650 may be 0. The function EntryPoint must never return.
2651
2652 If the current execution mode is not 64-bit paged mode, then ASSERT().
2653 If EntryPoint is 0, then ASSERT().
2654 If NewStack is 0, then ASSERT().
2655
2656 @param Cs The 16-bit selector to load in the CS before EntryPoint
2657 is called. The descriptor in the GDT that this selector
2658 references must be setup for 32-bit protected mode.
2659 @param EntryPoint The 64-bit virtual address of the function to call with
2660 the new stack after paging is disabled.
2661 @param Context1 The 64-bit virtual address of the context to pass into
2662 the EntryPoint function as the first parameter after
2663 paging is disabled.
2664 @param Context2 The 64-bit virtual address of the context to pass into
2665 the EntryPoint function as the second parameter after
2666 paging is disabled.
2667 @param NewStack The 64-bit virtual address of the new stack to use for
2668 the EntryPoint function after paging is disabled.
2669
2670 **/
2671 VOID
2672 EFIAPI
2673 AsmDisablePaging64 (
2674 IN UINT16 Cs,
2675 IN UINT32 EntryPoint,
2676 IN UINT32 Context1 OPTIONAL,
2677 IN UINT32 Context2 OPTIONAL,
2678 IN UINT32 NewStack
2679 )
2680 {
2681 gUnitTestHostBaseLib.X86->AsmDisablePaging64 (Cs, EntryPoint, Context1, Context2, NewStack);
2682 }
2683
2684 /**
2685 Retrieves the properties for 16-bit thunk functions.
2686
2687 Computes the size of the buffer and stack below 1MB required to use the
2688 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
2689 buffer size is returned in RealModeBufferSize, and the stack size is returned
2690 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
2691 then the actual minimum stack size is ExtraStackSize plus the maximum number
2692 of bytes that need to be passed to the 16-bit real mode code.
2693
2694 If RealModeBufferSize is NULL, then ASSERT().
2695 If ExtraStackSize is NULL, then ASSERT().
2696
2697 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
2698 required to use the 16-bit thunk functions.
2699 @param ExtraStackSize A pointer to the extra size of stack below 1MB
2700 that the 16-bit thunk functions require for
2701 temporary storage in the transition to and from
2702 16-bit real mode.
2703
2704 **/
2705 VOID
2706 EFIAPI
2707 AsmGetThunk16Properties (
2708 OUT UINT32 *RealModeBufferSize,
2709 OUT UINT32 *ExtraStackSize
2710 )
2711 {
2712 gUnitTestHostBaseLib.X86->AsmGetThunk16Properties (RealModeBufferSize, ExtraStackSize);
2713 }
2714
2715 /**
2716 Prepares all structures a code required to use AsmThunk16().
2717
2718 Prepares all structures and code required to use AsmThunk16().
2719
2720 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
2721 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
2722
2723 If ThunkContext is NULL, then ASSERT().
2724
2725 @param ThunkContext A pointer to the context structure that describes the
2726 16-bit real mode code to call.
2727
2728 **/
2729 VOID
2730 EFIAPI
2731 AsmPrepareThunk16 (
2732 IN OUT THUNK_CONTEXT *ThunkContext
2733 )
2734 {
2735 gUnitTestHostBaseLib.X86->AsmPrepareThunk16 (ThunkContext);
2736 }
2737
2738 /**
2739 Transfers control to a 16-bit real mode entry point and returns the results.
2740
2741 Transfers control to a 16-bit real mode entry point and returns the results.
2742 AsmPrepareThunk16() must be called with ThunkContext before this function is used.
2743 This function must be called with interrupts disabled.
2744
2745 The register state from the RealModeState field of ThunkContext is restored just prior
2746 to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,
2747 which is used to set the interrupt state when a 16-bit real mode entry point is called.
2748 Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.
2749 The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to
2750 the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.
2751 The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,
2752 so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment
2753 and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry
2754 point must exit with a RETF instruction. The register state is captured into RealModeState immediately
2755 after the RETF instruction is executed.
2756
2757 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
2758 or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure
2759 the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.
2760
2761 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
2762 then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.
2763 This includes the base vectors, the interrupt masks, and the edge/level trigger mode.
2764
2765 If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code
2766 is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.
2767
2768 If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
2769 ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to
2770 disable the A20 mask.
2771
2772 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in
2773 ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,
2774 then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
2775
2776 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in
2777 ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
2778
2779 If ThunkContext is NULL, then ASSERT().
2780 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
2781 If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
2782 ThunkAttributes, then ASSERT().
2783
2784 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
2785 virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.
2786
2787 @param ThunkContext A pointer to the context structure that describes the
2788 16-bit real mode code to call.
2789
2790 **/
2791 VOID
2792 EFIAPI
2793 AsmThunk16 (
2794 IN OUT THUNK_CONTEXT *ThunkContext
2795 )
2796 {
2797 gUnitTestHostBaseLib.X86->AsmThunk16 (ThunkContext);
2798 }
2799
2800 /**
2801 Prepares all structures and code for a 16-bit real mode thunk, transfers
2802 control to a 16-bit real mode entry point, and returns the results.
2803
2804 Prepares all structures and code for a 16-bit real mode thunk, transfers
2805 control to a 16-bit real mode entry point, and returns the results. If the
2806 caller only need to perform a single 16-bit real mode thunk, then this
2807 service should be used. If the caller intends to make more than one 16-bit
2808 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
2809 once and AsmThunk16() can be called for each 16-bit real mode thunk.
2810
2811 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
2812 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
2813
2814 See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.
2815
2816 @param ThunkContext A pointer to the context structure that describes the
2817 16-bit real mode code to call.
2818
2819 **/
2820 VOID
2821 EFIAPI
2822 AsmPrepareAndThunk16 (
2823 IN OUT THUNK_CONTEXT *ThunkContext
2824 )
2825 {
2826 gUnitTestHostBaseLib.X86->AsmPrepareAndThunk16 (ThunkContext);
2827 }
2828
2829 /**
2830 Load given selector into TR register.
2831
2832 @param[in] Selector Task segment selector
2833 **/
2834 VOID
2835 EFIAPI
2836 AsmWriteTr (
2837 IN UINT16 Selector
2838 )
2839 {
2840 gUnitTestHostBaseLib.X86->AsmWriteTr (Selector);
2841 }
2842
2843 /**
2844 Performs a serializing operation on all load-from-memory instructions that
2845 were issued prior the AsmLfence function.
2846
2847 Executes a LFENCE instruction. This function is only available on IA-32 and x64.
2848
2849 **/
2850 VOID
2851 EFIAPI
2852 AsmLfence (
2853 VOID
2854 )
2855 {
2856 gUnitTestHostBaseLib.X86->AsmLfence ();
2857 }
2858
2859 /**
2860 Patch the immediate operand of an IA32 or X64 instruction such that the byte,
2861 word, dword or qword operand is encoded at the end of the instruction's
2862 binary representation.
2863
2864 This function should be used to update object code that was compiled with
2865 NASM from assembly source code. Example:
2866
2867 NASM source code:
2868
2869 mov eax, strict dword 0 ; the imm32 zero operand will be patched
2870 ASM_PFX(gPatchCr3):
2871 mov cr3, eax
2872
2873 C source code:
2874
2875 X86_ASSEMBLY_PATCH_LABEL gPatchCr3;
2876 PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);
2877
2878 @param[out] InstructionEnd Pointer right past the instruction to patch. The
2879 immediate operand to patch is expected to
2880 comprise the trailing bytes of the instruction.
2881 If InstructionEnd is closer to address 0 than
2882 ValueSize permits, then ASSERT().
2883
2884 @param[in] PatchValue The constant to write to the immediate operand.
2885 The caller is responsible for ensuring that
2886 PatchValue can be represented in the byte, word,
2887 dword or qword operand (as indicated through
2888 ValueSize); otherwise ASSERT().
2889
2890 @param[in] ValueSize The size of the operand in bytes; must be 1, 2,
2891 4, or 8. ASSERT() otherwise.
2892 **/
2893 VOID
2894 EFIAPI
2895 PatchInstructionX86 (
2896 OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,
2897 IN UINT64 PatchValue,
2898 IN UINTN ValueSize
2899 )
2900 {
2901 gUnitTestHostBaseLib.X86->PatchInstructionX86 (InstructionEnd, PatchValue, ValueSize);
2902 }
2903
2904 ///
2905 /// Common services
2906 ///
2907 STATIC UNIT_TEST_HOST_BASE_LIB_COMMON mUnitTestHostBaseLibCommon = {
2908 UnitTestHostBaseLibEnableInterrupts,
2909 UnitTestHostBaseLibDisableInterrupts,
2910 UnitTestHostBaseLibEnableDisableInterrupts,
2911 UnitTestHostBaseLibGetInterruptState,
2912 };
2913
2914 ///
2915 /// IA32/X64 services
2916 ///
2917 STATIC UNIT_TEST_HOST_BASE_LIB_X86 mUnitTestHostBaseLibX86 = {
2918 UnitTestHostBaseLibAsmCpuid,
2919 UnitTestHostBaseLibAsmCpuidEx,
2920 UnitTestHostBaseLibAsmDisableCache,
2921 UnitTestHostBaseLibAsmEnableCache,
2922 UnitTestHostBaseLibAsmReadMsr64,
2923 UnitTestHostBaseLibAsmWriteMsr64,
2924 UnitTestHostBaseLibAsmReadCr0,
2925 UnitTestHostBaseLibAsmReadCr2,
2926 UnitTestHostBaseLibAsmReadCr3,
2927 UnitTestHostBaseLibAsmReadCr4,
2928 UnitTestHostBaseLibAsmWriteCr0,
2929 UnitTestHostBaseLibAsmWriteCr2,
2930 UnitTestHostBaseLibAsmWriteCr3,
2931 UnitTestHostBaseLibAsmWriteCr4,
2932 UnitTestHostBaseLibAsmReadDr0,
2933 UnitTestHostBaseLibAsmReadDr1,
2934 UnitTestHostBaseLibAsmReadDr2,
2935 UnitTestHostBaseLibAsmReadDr3,
2936 UnitTestHostBaseLibAsmReadDr4,
2937 UnitTestHostBaseLibAsmReadDr5,
2938 UnitTestHostBaseLibAsmReadDr6,
2939 UnitTestHostBaseLibAsmReadDr7,
2940 UnitTestHostBaseLibAsmWriteDr0,
2941 UnitTestHostBaseLibAsmWriteDr1,
2942 UnitTestHostBaseLibAsmWriteDr2,
2943 UnitTestHostBaseLibAsmWriteDr3,
2944 UnitTestHostBaseLibAsmWriteDr4,
2945 UnitTestHostBaseLibAsmWriteDr5,
2946 UnitTestHostBaseLibAsmWriteDr6,
2947 UnitTestHostBaseLibAsmWriteDr7,
2948 UnitTestHostBaseLibAsmReadCs,
2949 UnitTestHostBaseLibAsmReadDs,
2950 UnitTestHostBaseLibAsmReadEs,
2951 UnitTestHostBaseLibAsmReadFs,
2952 UnitTestHostBaseLibAsmReadGs,
2953 UnitTestHostBaseLibAsmReadSs,
2954 UnitTestHostBaseLibAsmReadTr,
2955 UnitTestHostBaseLibAsmReadGdtr,
2956 UnitTestHostBaseLibAsmWriteGdtr,
2957 UnitTestHostBaseLibAsmReadIdtr,
2958 UnitTestHostBaseLibAsmWriteIdtr,
2959 UnitTestHostBaseLibAsmReadLdtr,
2960 UnitTestHostBaseLibAsmWriteLdtr,
2961 UnitTestHostBaseLibAsmReadPmc,
2962 UnitTestHostBaseLibAsmMonitor,
2963 UnitTestHostBaseLibAsmMwait,
2964 UnitTestHostBaseLibAsmWbinvd,
2965 UnitTestHostBaseLibAsmInvd,
2966 UnitTestHostBaseLibAsmFlushCacheLine,
2967 UnitTestHostBaseLibAsmEnablePaging32,
2968 UnitTestHostBaseLibAsmDisablePaging32,
2969 UnitTestHostBaseLibAsmEnablePaging64,
2970 UnitTestHostBaseLibAsmDisablePaging64,
2971 UnitTestHostBaseLibAsmGetThunk16Properties,
2972 UnitTestHostBaseLibAsmPrepareThunk16,
2973 UnitTestHostBaseLibAsmThunk16,
2974 UnitTestHostBaseLibAsmPrepareAndThunk16,
2975 UnitTestHostBaseLibAsmWriteTr,
2976 UnitTestHostBaseLibAsmLfence,
2977 UnitTestHostBaseLibPatchInstructionX86
2978 };
2979
2980 ///
2981 /// Structure of hook functions for BaseLib functions that can not be used from
2982 /// a host application. A simple emulation of these function is provided by
2983 /// default. A specific unit test can provide its own implementation for any
2984 /// of these functions.
2985 ///
2986 UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib = {
2987 &mUnitTestHostBaseLibCommon,
2988 &mUnitTestHostBaseLibX86
2989 };