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