]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/BaseLib.h
a63bc1bc3e893828505a1e841292dc413cbe0cde
[mirror_edk2.git] / MdePkg / Include / Library / BaseLib.h
1 /** @file
2 Memory-only library functions with no library constructor/destructor
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: BaseLib.h
14
15 **/
16
17 #ifndef __BASE_LIB__
18 #define __BASE_LIB__
19
20 //
21 // Definitions for architecture specific types
22 // These include SPIN_LOCK and BASE_LIBRARY_JUMP_BUFFER
23 //
24
25 //
26 // SPIN_LOCK
27 //
28 typedef UINTN SPIN_LOCK;
29
30 #if defined (MDE_CPU_IA32)
31 //
32 // IA32 context buffer used by SetJump() and LongJump()
33 //
34 typedef struct {
35 UINT32 Ebx;
36 UINT32 Esi;
37 UINT32 Edi;
38 UINT32 Ebp;
39 UINT32 Esp;
40 UINT32 Eip;
41 } BASE_LIBRARY_JUMP_BUFFER;
42
43 #elif defined (MDE_CPU_IPF)
44 //
45 // IPF context buffer used by SetJump() and LongJump()
46 //
47 typedef struct {
48 UINT64 F2[2];
49 UINT64 F3[2];
50 UINT64 F4[2];
51 UINT64 F5[2];
52 UINT64 F16[2];
53 UINT64 F17[2];
54 UINT64 F18[2];
55 UINT64 F19[2];
56 UINT64 F20[2];
57 UINT64 F21[2];
58 UINT64 F22[2];
59 UINT64 F23[2];
60 UINT64 F24[2];
61 UINT64 F25[2];
62 UINT64 F26[2];
63 UINT64 F27[2];
64 UINT64 F28[2];
65 UINT64 F29[2];
66 UINT64 F30[2];
67 UINT64 F31[2];
68 UINT64 R4;
69 UINT64 R5;
70 UINT64 R6;
71 UINT64 R7;
72 UINT64 SP;
73 UINT64 BR0;
74 UINT64 BR1;
75 UINT64 BR2;
76 UINT64 BR3;
77 UINT64 BR4;
78 UINT64 BR5;
79 UINT64 InitialUNAT;
80 UINT64 AfterSpillUNAT;
81 UINT64 PFS;
82 UINT64 BSP;
83 UINT64 Predicates;
84 UINT64 LoopCount;
85 UINT64 FPSR;
86 } BASE_LIBRARY_JUMP_BUFFER;
87
88 #elif defined (MDE_CPU_X64)
89 //
90 // X64 context buffer used by SetJump() and LongJump()
91 //
92 typedef struct {
93 UINT64 Rbx;
94 UINT64 Rsp;
95 UINT64 Rbp;
96 UINT64 Rdi;
97 UINT64 Rsi;
98 UINT64 R12;
99 UINT64 R13;
100 UINT64 R14;
101 UINT64 R15;
102 UINT64 Rip;
103 } BASE_LIBRARY_JUMP_BUFFER;
104
105 #elif defined (MDE_CPU_EBC)
106 //
107 // EBC context buffer used by SetJump() and LongJump()
108 //
109 typedef struct {
110 UINT64 R0;
111 UINT64 R1;
112 UINT64 R2;
113 UINT64 R3;
114 UINT64 IP;
115 } BASE_LIBRARY_JUMP_BUFFER;
116
117 #else
118 #error Unknown Processor Type
119 #endif
120
121 //
122 // String Services
123 //
124
125 /**
126 Copies one Null-terminated Unicode string to another Null-terminated Unicode
127 string and returns the new Unicode string.
128
129 This function copies the contents of the Unicode string Source to the Unicode
130 string Destination, and returns Destination. If Source and Destination
131 overlap, then the results are undefined.
132
133 If Destination is NULL, then ASSERT().
134 If Source is NULL, then ASSERT().
135 If Source and Destination overlap, then ASSERT().
136 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
137 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
138
139 @param Destination Pointer to a Null-terminated Unicode string.
140 @param Source Pointer to a Null-terminated Unicode string.
141
142 @return Destiantion
143
144 **/
145 CHAR16 *
146 EFIAPI
147 StrCpy (
148 OUT CHAR16 *Destination,
149 IN CONST CHAR16 *Source
150 );
151
152 /**
153 Copies one Null-terminated Unicode string with a maximum length to another
154 Null-terminated Unicode string with a maximum length and returns the new
155 Unicode string.
156
157 This function copies the contents of the Unicode string Source to the Unicode
158 string Destination, and returns Destination. At most, Length Unicode
159 characters are copied from Source to Destination. If Length is 0, then
160 Destination is returned unmodified. If Length is greater that the number of
161 Unicode characters in Source, then Destination is padded with Null Unicode
162 characters. If Source and Destination overlap, then the results are
163 undefined.
164
165 If Destination is NULL, then ASSERT().
166 If Source is NULL, then ASSERT().
167 If Source and Destination overlap, then ASSERT().
168 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
169 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
170
171 @param Destination Pointer to a Null-terminated Unicode string.
172 @param Source Pointer to a Null-terminated Unicode string.
173 @param Length Maximum number of Unicode characters to copy.
174
175 @return Destination
176
177 **/
178 CHAR16 *
179 EFIAPI
180 StrnCpy (
181 OUT CHAR16 *Destination,
182 IN CONST CHAR16 *Source,
183 IN UINTN Length
184 );
185
186 /**
187 Returns the length of a Null-terminated Unicode string.
188
189 This function returns the number of Unicode characters in the Null-terminated
190 Unicode string specified by String.
191
192 If String is NULL, then ASSERT().
193 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
194 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
195
196 @param String Pointer to a Null-terminated Unicode string.
197
198 @return The length of String.
199
200 **/
201 UINTN
202 EFIAPI
203 StrLen (
204 IN CONST CHAR16 *String
205 );
206
207 /**
208 Returns the size of a Null-terminated Unicode string in bytes, including the
209 Null terminator.
210
211 This function returns the size, in bytes, of the Null-terminated Unicode
212 string specified by String.
213
214 If String is NULL, then ASSERT().
215 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
216 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
217
218 @param String Pointer to a Null-terminated Unicode string.
219
220 @return The size of String.
221
222 **/
223 UINTN
224 EFIAPI
225 StrSize (
226 IN CONST CHAR16 *String
227 );
228
229 /**
230 Compares two Null-terminated Unicode strings, and returns the difference
231 between the first mismatched Unicode characters.
232
233 This function compares the Null-terminated Unicode string FirstString to the
234 Null-terminated Unicode string SecondString. If FirstString is identical to
235 SecondString, then 0 is returned. Otherwise, the value returned is the first
236 mismatched Unicode character in SecondString subtracted from the first
237 mismatched Unicode character in FirstString.
238
239 If FirstString is NULL, then ASSERT().
240 If SecondString is NULL, then ASSERT().
241 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
242 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
243 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
244 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
245
246 @param FirstString Pointer to a Null-terminated Unicode string.
247 @param SecondString Pointer to a Null-terminated Unicode string.
248
249 @retval 0 FirstString is identical to SecondString.
250 @retval !=0 FirstString is not identical to SecondString.
251
252 **/
253 INTN
254 EFIAPI
255 StrCmp (
256 IN CONST CHAR16 *FirstString,
257 IN CONST CHAR16 *SecondString
258 );
259
260 /**
261 Compares two Null-terminated Unicode strings with maximum lengths, and
262 returns the difference between the first mismatched Unicode characters.
263
264 This function compares the Null-terminated Unicode string FirstString to the
265 Null-terminated Unicode string SecondString. At most, Length Unicode
266 characters will be compared. If Length is 0, then 0 is returned. If
267 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
268 value returned is the first mismatched Unicode character in SecondString
269 subtracted from the first mismatched Unicode character in FirstString.
270
271 If FirstString is NULL, then ASSERT().
272 If SecondString is NULL, then ASSERT().
273 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
274 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
275 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
276 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
277
278 @param FirstString Pointer to a Null-terminated Unicode string.
279 @param SecondString Pointer to a Null-terminated Unicode string.
280 @param Length Maximum number of Unicode characters to compare.
281
282 @retval 0 FirstString is identical to SecondString.
283 @retval !=0 FirstString is not identical to SecondString.
284
285 **/
286 INTN
287 EFIAPI
288 StrnCmp (
289 IN CONST CHAR16 *FirstString,
290 IN CONST CHAR16 *SecondString,
291 IN UINTN Length
292 );
293
294 /**
295 Concatenates one Null-terminated Unicode string to another Null-terminated
296 Unicode string, and returns the concatenated Unicode string.
297
298 This function concatenates two Null-terminated Unicode strings. The contents
299 of Null-terminated Unicode string Source are concatenated to the end of
300 Null-terminated Unicode string Destination. The Null-terminated concatenated
301 Unicode String is returned. If Source and Destination overlap, then the
302 results are undefined.
303
304 If Destination is NULL, then ASSERT().
305 If Source is NULL, then ASSERT().
306 If Source and Destination overlap, then ASSERT().
307 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
308 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
309 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
310 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
311 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
312 and Source results in a Unicode string with more than
313 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
314
315 @param Destination Pointer to a Null-terminated Unicode string.
316 @param Source Pointer to a Null-terminated Unicode string.
317
318 @return Destination
319
320 **/
321 CHAR16 *
322 EFIAPI
323 StrCat (
324 IN OUT CHAR16 *Destination,
325 IN CONST CHAR16 *Source
326 );
327
328 /**
329 Concatenates one Null-terminated Unicode string with a maximum length to the
330 end of another Null-terminated Unicode string, and returns the concatenated
331 Unicode string.
332
333 This function concatenates two Null-terminated Unicode strings. The contents
334 of Null-terminated Unicode string Source are concatenated to the end of
335 Null-terminated Unicode string Destination, and Destination is returned. At
336 most, Length Unicode characters are concatenated from Source to the end of
337 Destination, and Destination is always Null-terminated. If Length is 0, then
338 Destination is returned unmodified. If Source and Destination overlap, then
339 the results are undefined.
340
341 If Destination is NULL, then ASSERT().
342 If Source is NULL, then ASSERT().
343 If Source and Destination overlap, then ASSERT().
344 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
345 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
346 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
347 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
348 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
349 and Source results in a Unicode string with more than
350 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
351
352 @param Destination Pointer to a Null-terminated Unicode string.
353 @param Source Pointer to a Null-terminated Unicode string.
354 @param Length Maximum number of Unicode characters to concatenate from
355 Source.
356
357 @return Destination
358
359 **/
360 CHAR16 *
361 EFIAPI
362 StrnCat (
363 IN OUT CHAR16 *Destination,
364 IN CONST CHAR16 *Source,
365 IN UINTN Length
366 );
367
368 /**
369 Copies one Null-terminated ASCII string to another Null-terminated ASCII
370 string and returns the new ASCII string.
371
372 This function copies the contents of the ASCII string Source to the ASCII
373 string Destination, and returns Destination. If Source and Destination
374 overlap, then the results are undefined.
375
376 If Destination is NULL, then ASSERT().
377 If Source is NULL, then ASSERT().
378 If Source and Destination overlap, then ASSERT().
379 If PcdMaximumAsciiStringLength is not zero and Source contains more than
380 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
381
382 @param Destination Pointer to a Null-terminated ASCII string.
383 @param Source Pointer to a Null-terminated ASCII string.
384
385 @return Destination
386
387 **/
388 CHAR8 *
389 EFIAPI
390 AsciiStrCpy (
391 OUT CHAR8 *Destination,
392 IN CONST CHAR8 *Source
393 );
394
395 /**
396 Copies one Null-terminated ASCII string with a maximum length to another
397 Null-terminated ASCII string with a maximum length and returns the new ASCII
398 string.
399
400 This function copies the contents of the ASCII string Source to the ASCII
401 string Destination, and returns Destination. At most, Length ASCII characters
402 are copied from Source to Destination. If Length is 0, then Destination is
403 returned unmodified. If Length is greater that the number of ASCII characters
404 in Source, then Destination is padded with Null ASCII characters. If Source
405 and Destination overlap, then the results are undefined.
406
407 If Destination is NULL, then ASSERT().
408 If Source is NULL, then ASSERT().
409 If Source and Destination overlap, then ASSERT().
410 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
411 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
412
413 @param Destination Pointer to a Null-terminated ASCII string.
414 @param Source Pointer to a Null-terminated ASCII string.
415 @param Length Maximum number of ASCII characters to copy.
416
417 @return Destination
418
419 **/
420 CHAR8 *
421 EFIAPI
422 AsciiStrnCpy (
423 OUT CHAR8 *Destination,
424 IN CONST CHAR8 *Source,
425 IN UINTN Length
426 );
427
428 /**
429 Returns the length of a Null-terminated ASCII string.
430
431 This function returns the number of ASCII characters in the Null-terminated
432 ASCII string specified by String.
433
434 If String is NULL, then ASSERT().
435 If PcdMaximumAsciiStringLength is not zero and String contains more than
436 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
437
438 @param String Pointer to a Null-terminated ASCII string.
439
440 @return The length of String.
441
442 **/
443 UINTN
444 EFIAPI
445 AsciiStrLen (
446 IN CONST CHAR8 *String
447 );
448
449 /**
450 Returns the size of a Null-terminated ASCII string in bytes, including the
451 Null terminator.
452
453 This function returns the size, in bytes, of the Null-terminated ASCII string
454 specified by String.
455
456 If String is NULL, then ASSERT().
457 If PcdMaximumAsciiStringLength is not zero and String contains more than
458 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
459
460 @param String Pointer to a Null-terminated ASCII string.
461
462 @return The size of String.
463
464 **/
465 UINTN
466 EFIAPI
467 AsciiStrSize (
468 IN CONST CHAR8 *String
469 );
470
471 /**
472 Compares two Null-terminated ASCII strings, and returns the difference
473 between the first mismatched ASCII characters.
474
475 This function compares the Null-terminated ASCII string FirstString to the
476 Null-terminated ASCII string SecondString. If FirstString is identical to
477 SecondString, then 0 is returned. Otherwise, the value returned is the first
478 mismatched ASCII character in SecondString subtracted from the first
479 mismatched ASCII character in FirstString.
480
481 If FirstString is NULL, then ASSERT().
482 If SecondString is NULL, then ASSERT().
483 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
484 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
485 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
486 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
487
488 @param FirstString Pointer to a Null-terminated ASCII string.
489 @param SecondString Pointer to a Null-terminated ASCII string.
490
491 @retval 0 FirstString is identical to SecondString.
492 @retval !=0 FirstString is not identical to SecondString.
493
494 **/
495 INTN
496 EFIAPI
497 AsciiStrCmp (
498 IN CONST CHAR8 *FirstString,
499 IN CONST CHAR8 *SecondString
500 );
501
502 /**
503 Performs a case insensitive comparison of two Null-terminated ASCII strings,
504 and returns the difference between the first mismatched ASCII characters.
505
506 This function performs a case insensitive comparison of the Null-terminated
507 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
508 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
509 value returned is the first mismatched lower case ASCII character in
510 SecondString subtracted from the first mismatched lower case ASCII character
511 in FirstString.
512
513 If FirstString is NULL, then ASSERT().
514 If SecondString is NULL, then ASSERT().
515 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
516 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
517 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
518 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
519
520 @param FirstString Pointer to a Null-terminated ASCII string.
521 @param SecondString Pointer to a Null-terminated ASCII string.
522
523 @retval 0 FirstString is identical to SecondString using case insensitive
524 comparisons.
525 @retval !=0 FirstString is not identical to SecondString using case
526 insensitive comparisons.
527
528 **/
529 INTN
530 EFIAPI
531 AsciiStriCmp (
532 IN CONST CHAR8 *FirstString,
533 IN CONST CHAR8 *SecondString
534 );
535
536 /**
537 Compares two Null-terminated ASCII strings with maximum lengths, and returns
538 the difference between the first mismatched ASCII characters.
539
540 This function compares the Null-terminated ASCII string FirstString to the
541 Null-terminated ASCII string SecondString. At most, Length ASCII characters
542 will be compared. If Length is 0, then 0 is returned. If FirstString is
543 identical to SecondString, then 0 is returned. Otherwise, the value returned
544 is the first mismatched ASCII character in SecondString subtracted from the
545 first mismatched ASCII character in FirstString.
546
547 If FirstString is NULL, then ASSERT().
548 If SecondString is NULL, then ASSERT().
549 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
550 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
551 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
552 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
553
554 @param FirstString Pointer to a Null-terminated ASCII string.
555 @param SecondString Pointer to a Null-terminated ASCII string.
556
557 @retval 0 FirstString is identical to SecondString.
558 @retval !=0 FirstString is not identical to SecondString.
559
560 **/
561 INTN
562 EFIAPI
563 AsciiStrnCmp (
564 IN CONST CHAR8 *FirstString,
565 IN CONST CHAR8 *SecondString,
566 IN UINTN Length
567 );
568
569 /**
570 Concatenates one Null-terminated ASCII string to another Null-terminated
571 ASCII string, and returns the concatenated ASCII string.
572
573 This function concatenates two Null-terminated ASCII strings. The contents of
574 Null-terminated ASCII string Source are concatenated to the end of Null-
575 terminated ASCII string Destination. The Null-terminated concatenated ASCII
576 String is returned.
577
578 If Destination is NULL, then ASSERT().
579 If Source is NULL, then ASSERT().
580 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
581 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
582 If PcdMaximumAsciiStringLength is not zero and Source contains more than
583 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
584 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
585 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
586 ASCII characters, then ASSERT().
587
588 @param Destination Pointer to a Null-terminated ASCII string.
589 @param Source Pointer to a Null-terminated ASCII string.
590
591 @return Destination
592
593 **/
594 CHAR8 *
595 EFIAPI
596 AsciiStrCat (
597 IN OUT CHAR8 *Destination,
598 IN CONST CHAR8 *Source
599 );
600
601 /**
602 Concatenates one Null-terminated ASCII string with a maximum length to the
603 end of another Null-terminated ASCII string, and returns the concatenated
604 ASCII string.
605
606 This function concatenates two Null-terminated ASCII strings. The contents
607 of Null-terminated ASCII string Source are concatenated to the end of Null-
608 terminated ASCII string Destination, and Destination is returned. At most,
609 Length ASCII characters are concatenated from Source to the end of
610 Destination, and Destination is always Null-terminated. If Length is 0, then
611 Destination is returned unmodified. If Source and Destination overlap, then
612 the results are undefined.
613
614 If Destination is NULL, then ASSERT().
615 If Source is NULL, then ASSERT().
616 If Source and Destination overlap, then ASSERT().
617 If PcdMaximumAsciiStringLength is not zero, and Destination contains more
618 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
619 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
620 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
621 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
622 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
623 ASCII characters, then ASSERT().
624
625 @param Destination Pointer to a Null-terminated ASCII string.
626 @param Source Pointer to a Null-terminated ASCII string.
627 @param Length Maximum number of ASCII characters to concatenate from
628 Source.
629
630 @return Destination
631
632 **/
633 CHAR8 *
634 EFIAPI
635 AsciiStrnCat (
636 IN OUT CHAR8 *Destination,
637 IN CONST CHAR8 *Source,
638 IN UINTN Length
639 );
640
641 /**
642 Converts an 8-bit value to an 8-bit BCD value.
643
644 Converts the 8-bit value specified by Value to BCD. The BCD value is
645 returned.
646
647 If Value >= 100, then ASSERT().
648
649 @param Value The 8-bit value to convert to BCD. Range 0..99.
650
651 @return The BCD value
652
653 **/
654 UINT8
655 EFIAPI
656 DecimalToBcd8 (
657 IN UINT8 Value
658 );
659
660 /**
661 Converts an 8-bit BCD value to an 8-bit value.
662
663 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
664 value is returned.
665
666 If Value >= 0xA0, then ASSERT().
667 If (Value & 0x0F) >= 0x0A, then ASSERT().
668
669 @param Value The 8-bit BCD value to convert to an 8-bit value.
670
671 @return The 8-bit value is returned.
672
673 **/
674 UINT8
675 EFIAPI
676 BcdToDecimal8 (
677 IN UINT8 Value
678 );
679
680 //
681 // LIST_ENTRY definition
682 //
683 typedef struct _LIST_ENTRY LIST_ENTRY;
684
685 struct _LIST_ENTRY {
686 LIST_ENTRY *ForwardLink;
687 LIST_ENTRY *BackLink;
688 };
689
690 //
691 // Linked List Functions and Macros
692 //
693
694 /**
695 Initializes the head node of a doubly linked list that is declared as a
696 global variable in a module.
697
698 Initializes the forward and backward links of a new linked list. After
699 initializing a linked list with this macro, the other linked list functions
700 may be used to add and remove nodes from the linked list. This macro results
701 in smaller executables by initializing the linked list in the data section,
702 instead if calling the InitializeListHead() function to perform the
703 equivalent operation.
704
705 @param ListHead The head note of a list to initiailize.
706
707 **/
708 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
709
710 /**
711 Initializes the head node of a doubly linked list, and returns the pointer to
712 the head node of the doubly linked list.
713
714 Initializes the forward and backward links of a new linked list. After
715 initializing a linked list with this function, the other linked list
716 functions may be used to add and remove nodes from the linked list. It is up
717 to the caller of this function to allocate the memory for ListHead.
718
719 If ListHead is NULL, then ASSERT().
720
721 @param ListHead A pointer to the head node of a new doubly linked list.
722
723 @return ListHead
724
725 **/
726 LIST_ENTRY *
727 EFIAPI
728 InitializeListHead (
729 IN LIST_ENTRY *ListHead
730 );
731
732 /**
733 Adds a node to the beginning of a doubly linked list, and returns the pointer
734 to the head node of the doubly linked list.
735
736 Adds the node Entry at the beginning of the doubly linked list denoted by
737 ListHead, and returns ListHead.
738
739 If ListHead is NULL, then ASSERT().
740 If Entry is NULL, then ASSERT().
741 If ListHead was not initialized with InitializeListHead(), then ASSERT().
742 If PcdMaximumLinkedListLenth is not zero, and ListHead contains more than
743 PcdMaximumLinkedListLenth nodes, then ASSERT().
744
745 @param ListHead A pointer to the head node of a doubly linked list.
746 @param Entry A pointer to a node that is to be inserted at the beginning
747 of a doubly linked list.
748
749 @return ListHead
750
751 **/
752 LIST_ENTRY *
753 EFIAPI
754 InsertHeadList (
755 IN LIST_ENTRY *ListHead,
756 IN LIST_ENTRY *Entry
757 );
758
759 /**
760 Adds a node to the end of a doubly linked list, and returns the pointer to
761 the head node of the doubly linked list.
762
763 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
764 and returns ListHead.
765
766 If ListHead is NULL, then ASSERT().
767 If Entry is NULL, then ASSERT().
768 If ListHead was not initialized with InitializeListHead(), then ASSERT().
769 If PcdMaximumLinkedListLenth is not zero, and ListHead contains more than
770 PcdMaximumLinkedListLenth nodes, then ASSERT().
771
772 @param ListHead A pointer to the head node of a doubly linked list.
773 @param Entry A pointer to a node that is to be added at the end of the
774 doubly linked list.
775
776 @return ListHead
777
778 **/
779 LIST_ENTRY *
780 EFIAPI
781 InsertTailList (
782 IN LIST_ENTRY *ListHead,
783 IN LIST_ENTRY *Entry
784 );
785
786 /**
787 Retrieves the first node of a doubly linked list.
788
789 Returns the first node of a doubly linked list. List must have been
790 initialized with InitializeListHead(). If List is empty, then NULL is
791 returned.
792
793 If List is NULL, then ASSERT().
794 If List was not initialized with InitializeListHead(), then ASSERT().
795 If PcdMaximumLinkedListLenth is not zero, and List contains more than
796 PcdMaximumLinkedListLenth nodes, then ASSERT().
797
798 @param List A pointer to the head node of a doubly linked list.
799
800 @return The first node of a doubly linked list.
801 @retval NULL The list is empty.
802
803 **/
804 LIST_ENTRY *
805 EFIAPI
806 GetFirstNode (
807 IN CONST LIST_ENTRY *List
808 );
809
810 /**
811 Retrieves the next node of a doubly linked list.
812
813 Returns the node of a doubly linked list that follows Node. List must have
814 been initialized with InitializeListHead(). If List is empty, then List is
815 returned.
816
817 If List is NULL, then ASSERT().
818 If Node is NULL, then ASSERT().
819 If List was not initialized with InitializeListHead(), then ASSERT().
820 If PcdMaximumLinkedListLenth is not zero, and List contains more than
821 PcdMaximumLinkedListLenth nodes, then ASSERT().
822 If Node is not a node in List, then ASSERT().
823
824 @param List A pointer to the head node of a doubly linked list.
825 @param Node A pointer to a node in the doubly linked list.
826
827 @return Pointer to the next node if one exists. Otherwise a null value which
828 is actually List is returned.
829
830 **/
831 LIST_ENTRY *
832 EFIAPI
833 GetNextNode (
834 IN CONST LIST_ENTRY *List,
835 IN CONST LIST_ENTRY *Node
836 );
837
838 /**
839 Checks to see if a doubly linked list is empty or not.
840
841 Checks to see if the doubly linked list is empty. If the linked list contains
842 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
843
844 If ListHead is NULL, then ASSERT().
845 If ListHead was not initialized with InitializeListHead(), then ASSERT().
846 If PcdMaximumLinkedListLenth is not zero, and List contains more than
847 PcdMaximumLinkedListLenth nodes, then ASSERT().
848
849 @param ListHead A pointer to the head node of a doubly linked list.
850
851 @retval TRUE The linked list is empty.
852 @retval FALSE The linked list is not empty.
853
854 **/
855 BOOLEAN
856 EFIAPI
857 IsListEmpty (
858 IN CONST LIST_ENTRY *ListHead
859 );
860
861 /**
862 Determines if a node in a doubly linked list is null.
863
864 Returns FALSE if Node is one of the nodes in the doubly linked list specified
865 by List. Otherwise, TRUE is returned. List must have been initialized with
866 InitializeListHead().
867
868 If List is NULL, then ASSERT().
869 If Node is NULL, then ASSERT().
870 If List was not initialized with InitializeListHead(), then ASSERT().
871 If PcdMaximumLinkedListLenth is not zero, and List contains more than
872 PcdMaximumLinkedListLenth nodes, then ASSERT().
873 If Node is not a node in List and Node is not equal to List, then ASSERT().
874
875 @param List A pointer to the head node of a doubly linked list.
876 @param Node A pointer to a node in the doubly linked list.
877
878 @retval TRUE Node is one of the nodes in the doubly linked list.
879 @retval FALSE Node is not one of the nodes in the doubly linked list.
880
881 **/
882 BOOLEAN
883 EFIAPI
884 IsNull (
885 IN CONST LIST_ENTRY *List,
886 IN CONST LIST_ENTRY *Node
887 );
888
889 /**
890 Determines if a node the last node in a doubly linked list.
891
892 Returns TRUE if Node is the last node in the doubly linked list specified by
893 List. Otherwise, FALSE is returned. List must have been initialized with
894 InitializeListHead().
895
896 If List is NULL, then ASSERT().
897 If Node is NULL, then ASSERT().
898 If List was not initialized with InitializeListHead(), then ASSERT().
899 If PcdMaximumLinkedListLenth is not zero, and List contains more than
900 PcdMaximumLinkedListLenth nodes, then ASSERT().
901 If Node is not a node in List, then ASSERT().
902
903 @param List A pointer to the head node of a doubly linked list.
904 @param Node A pointer to a node in the doubly linked list.
905
906 @retval TRUE Node is the last node in the linked list.
907 @retval FALSE Node is not the last node in the linked list.
908
909 **/
910 BOOLEAN
911 EFIAPI
912 IsNodeAtEnd (
913 IN CONST LIST_ENTRY *List,
914 IN CONST LIST_ENTRY *Node
915 );
916
917 /**
918 Swaps the location of two nodes in a doubly linked list, and returns the
919 first node after the swap.
920
921 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
922 Otherwise, the location of the FirstEntry node is swapped with the location
923 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
924 same double linked list as FirstEntry and that double linked list must have
925 been initialized with InitializeListHead(). SecondEntry is returned after the
926 nodes are swapped.
927
928 If FirstEntry is NULL, then ASSERT().
929 If SecondEntry is NULL, then ASSERT().
930 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
931 If PcdMaximumLinkedListLenth is not zero, and the linked list containing
932 FirstEntry and SecondEntry contains more than PcdMaximumLinkedListLenth
933 nodes, then ASSERT().
934
935 @param FirstEntry A pointer to a node in a linked list.
936 @param SecondEntry A pointer to another node in the same linked list.
937
938 **/
939 LIST_ENTRY *
940 EFIAPI
941 SwapListEntries (
942 IN LIST_ENTRY *FirstEntry,
943 IN LIST_ENTRY *SecondEntry
944 );
945
946 /**
947 Removes a node from a doubly linked list, and returns the node that follows
948 the removed node.
949
950 Removes the node Entry from a doubly linked list. It is up to the caller of
951 this function to release the memory used by this node if that is required. On
952 exit, the node following Entry in the doubly linked list is returned. If
953 Entry is the only node in the linked list, then the head node of the linked
954 list is returned.
955
956 If Entry is NULL, then ASSERT().
957 If Entry is the head node of an empty list, then ASSERT().
958 If PcdMaximumLinkedListLenth is not zero, and the linked list containing
959 Entry contains more than PcdMaximumLinkedListLenth nodes, then ASSERT().
960
961 @param Entry A pointer to a node in a linked list
962
963 @return Entry
964
965 **/
966 LIST_ENTRY *
967 EFIAPI
968 RemoveEntryList (
969 IN CONST LIST_ENTRY *Entry
970 );
971
972 //
973 // Math Services
974 //
975
976 /**
977 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
978 with zeros. The shifted value is returned.
979
980 This function shifts the 64-bit value Operand to the left by Count bits. The
981 low Count bits are set to zero. The shifted value is returned.
982
983 If Count is greater than 63, then ASSERT().
984
985 @param Operand The 64-bit operand to shift left.
986 @param Count The number of bits to shift left.
987
988 @return Operand << Count
989
990 **/
991 UINT64
992 EFIAPI
993 LShiftU64 (
994 IN UINT64 Operand,
995 IN UINTN Count
996 );
997
998 /**
999 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1000 filled with zeros. The shifted value is returned.
1001
1002 This function shifts the 64-bit value Operand to the right by Count bits. The
1003 high Count bits are set to zero. The shifted value is returned.
1004
1005 If Count is greater than 63, then ASSERT().
1006
1007 @param Operand The 64-bit operand to shift right.
1008 @param Count The number of bits to shift right.
1009
1010 @return Operand >> Count
1011
1012 **/
1013 UINT64
1014 EFIAPI
1015 RShiftU64 (
1016 IN UINT64 Operand,
1017 IN UINTN Count
1018 );
1019
1020 /**
1021 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1022 with original integer's bit 63. The shifted value is returned.
1023
1024 This function shifts the 64-bit value Operand to the right by Count bits. The
1025 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1026
1027 If Count is greater than 63, then ASSERT().
1028
1029 @param Operand The 64-bit operand to shift right.
1030 @param Count The number of bits to shift right.
1031
1032 @return Operand >> Count
1033
1034 **/
1035 UINT64
1036 EFIAPI
1037 ARShiftU64 (
1038 IN UINT64 Operand,
1039 IN UINTN Count
1040 );
1041
1042 /**
1043 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1044 with the high bits that were rotated.
1045
1046 This function rotates the 32-bit value Operand to the left by Count bits. The
1047 low Count bits are fill with the high Count bits of Operand. The rotated
1048 value is returned.
1049
1050 If Count is greater than 31, then ASSERT().
1051
1052 @param Operand The 32-bit operand to rotate left.
1053 @param Count The number of bits to rotate left.
1054
1055 @return Operand <<< Count
1056
1057 **/
1058 UINT32
1059 EFIAPI
1060 LRotU32 (
1061 IN UINT32 Operand,
1062 IN UINTN Count
1063 );
1064
1065 /**
1066 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1067 with the low bits that were rotated.
1068
1069 This function rotates the 32-bit value Operand to the right by Count bits.
1070 The high Count bits are fill with the low Count bits of Operand. The rotated
1071 value is returned.
1072
1073 If Count is greater than 31, then ASSERT().
1074
1075 @param Operand The 32-bit operand to rotate right.
1076 @param Count The number of bits to rotate right.
1077
1078 @return Operand >>> Count
1079
1080 **/
1081 UINT32
1082 EFIAPI
1083 RRotU32 (
1084 IN UINT32 Operand,
1085 IN UINTN Count
1086 );
1087
1088 /**
1089 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1090 with the high bits that were rotated.
1091
1092 This function rotates the 64-bit value Operand to the left by Count bits. The
1093 low Count bits are fill with the high Count bits of Operand. The rotated
1094 value is returned.
1095
1096 If Count is greater than 63, then ASSERT().
1097
1098 @param Operand The 64-bit operand to rotate left.
1099 @param Count The number of bits to rotate left.
1100
1101 @return Operand <<< Count
1102
1103 **/
1104 UINT64
1105 EFIAPI
1106 LRotU64 (
1107 IN UINT64 Operand,
1108 IN UINTN Count
1109 );
1110
1111 /**
1112 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1113 with the high low bits that were rotated.
1114
1115 This function rotates the 64-bit value Operand to the right by Count bits.
1116 The high Count bits are fill with the low Count bits of Operand. The rotated
1117 value is returned.
1118
1119 If Count is greater than 63, then ASSERT().
1120
1121 @param Operand The 64-bit operand to rotate right.
1122 @param Count The number of bits to rotate right.
1123
1124 @return Operand >>> Count
1125
1126 **/
1127 UINT64
1128 EFIAPI
1129 RRotU64 (
1130 IN UINT64 Operand,
1131 IN UINTN Count
1132 );
1133
1134 /**
1135 Returns the bit position of the lowest bit set in a 32-bit value.
1136
1137 This function computes the bit position of the lowest bit set in the 32-bit
1138 value specified by Operand. If Operand is zero, then -1 is returned.
1139 Otherwise, a value between 0 and 31 is returned.
1140
1141 @param Operand The 32-bit operand to evaluate.
1142
1143 @return Position of the lowest bit set in Operand if found.
1144 @retval -1 Operand is zero.
1145
1146 **/
1147 INTN
1148 EFIAPI
1149 LowBitSet32 (
1150 IN UINT32 Operand
1151 );
1152
1153 /**
1154 Returns the bit position of the lowest bit set in a 64-bit value.
1155
1156 This function computes the bit position of the lowest bit set in the 64-bit
1157 value specified by Operand. If Operand is zero, then -1 is returned.
1158 Otherwise, a value between 0 and 63 is returned.
1159
1160 @param Operand The 64-bit operand to evaluate.
1161
1162 @return Position of the lowest bit set in Operand if found.
1163 @retval -1 Operand is zero.
1164
1165 **/
1166 INTN
1167 EFIAPI
1168 LowBitSet64 (
1169 IN UINT64 Operand
1170 );
1171
1172 /**
1173 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1174 to log2(x).
1175
1176 This function computes the bit position of the highest bit set in the 32-bit
1177 value specified by Operand. If Operand is zero, then -1 is returned.
1178 Otherwise, a value between 0 and 31 is returned.
1179
1180 @param Operand The 32-bit operand to evaluate.
1181
1182 @return Position of the highest bit set in Operand if found.
1183 @retval -1 Operand is zero.
1184
1185 **/
1186 INTN
1187 EFIAPI
1188 HighBitSet32 (
1189 IN UINT32 Operand
1190 );
1191
1192 /**
1193 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1194 to log2(x).
1195
1196 This function computes the bit position of the highest bit set in the 64-bit
1197 value specified by Operand. If Operand is zero, then -1 is returned.
1198 Otherwise, a value between 0 and 63 is returned.
1199
1200 @param Operand The 64-bit operand to evaluate.
1201
1202 @return Position of the highest bit set in Operand if found.
1203 @retval -1 Operand is zero.
1204
1205 **/
1206 INTN
1207 EFIAPI
1208 HighBitSet64 (
1209 IN UINT64 Operand
1210 );
1211
1212 /**
1213 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1214 1 << HighBitSet32(x).
1215
1216 This function computes the value of the highest bit set in the 32-bit value
1217 specified by Operand. If Operand is zero, then zero is returned.
1218
1219 @param Operand The 32-bit operand to evaluate.
1220
1221 @return 1 << HighBitSet32(Operand)
1222 @retval 0 Operand is zero.
1223
1224 **/
1225 UINT32
1226 EFIAPI
1227 GetPowerOfTwo32 (
1228 IN UINT32 Operand
1229 );
1230
1231 /**
1232 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1233 1 << HighBitSet64(x).
1234
1235 This function computes the value of the highest bit set in the 64-bit value
1236 specified by Operand. If Operand is zero, then zero is returned.
1237
1238 @param Operand The 64-bit operand to evaluate.
1239
1240 @return 1 << HighBitSet64(Operand)
1241 @retval 0 Operand is zero.
1242
1243 **/
1244 UINT64
1245 EFIAPI
1246 GetPowerOfTwo64 (
1247 IN UINT64 Operand
1248 );
1249
1250 /**
1251 Switches the endianess of a 16-bit integer.
1252
1253 This function swaps the bytes in a 16-bit unsigned value to switch the value
1254 from little endian to big endian or vice versa. The byte swapped value is
1255 returned.
1256
1257 @param Operand A 16-bit unsigned value.
1258
1259 @return The byte swaped Operand.
1260
1261 **/
1262 UINT16
1263 EFIAPI
1264 SwapBytes16 (
1265 IN UINT16 Value
1266 );
1267
1268 /**
1269 Switches the endianess of a 32-bit integer.
1270
1271 This function swaps the bytes in a 32-bit unsigned value to switch the value
1272 from little endian to big endian or vice versa. The byte swapped value is
1273 returned.
1274
1275 @param Operand A 32-bit unsigned value.
1276
1277 @return The byte swaped Operand.
1278
1279 **/
1280 UINT32
1281 EFIAPI
1282 SwapBytes32 (
1283 IN UINT32 Value
1284 );
1285
1286 /**
1287 Switches the endianess of a 64-bit integer.
1288
1289 This function swaps the bytes in a 64-bit unsigned value to switch the value
1290 from little endian to big endian or vice versa. The byte swapped value is
1291 returned.
1292
1293 @param Operand A 64-bit unsigned value.
1294
1295 @return The byte swaped Operand.
1296
1297 **/
1298 UINT64
1299 EFIAPI
1300 SwapBytes64 (
1301 IN UINT64 Value
1302 );
1303
1304 /**
1305 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1306 generates a 64-bit unsigned result.
1307
1308 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1309 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1310 bit unsigned result is returned.
1311
1312 If the result overflows, then ASSERT().
1313
1314 @param Multiplicand A 64-bit unsigned value.
1315 @param Multiplier A 32-bit unsigned value.
1316
1317 @return Multiplicand * Multiplier
1318
1319 **/
1320 UINT64
1321 EFIAPI
1322 MultU64x32 (
1323 IN UINT64 Multiplicand,
1324 IN UINT32 Multiplier
1325 );
1326
1327 /**
1328 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1329 generates a 64-bit unsigned result.
1330
1331 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1332 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1333 bit unsigned result is returned.
1334
1335 If the result overflows, then ASSERT().
1336
1337 @param Multiplicand A 64-bit unsigned value.
1338 @param Multiplier A 64-bit unsigned value.
1339
1340 @return Multiplicand * Multiplier
1341
1342 **/
1343 UINT64
1344 EFIAPI
1345 MultU64x64 (
1346 IN UINT64 Multiplicand,
1347 IN UINT64 Multiplier
1348 );
1349
1350 /**
1351 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1352 64-bit signed result.
1353
1354 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1355 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1356 signed result is returned.
1357
1358 If the result overflows, then ASSERT().
1359
1360 @param Multiplicand A 64-bit signed value.
1361 @param Multiplier A 64-bit signed value.
1362
1363 @return Multiplicand * Multiplier
1364
1365 **/
1366 INT64
1367 EFIAPI
1368 MultS64x64 (
1369 IN INT64 Multiplicand,
1370 IN INT64 Multiplier
1371 );
1372
1373 /**
1374 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1375 a 64-bit unsigned result.
1376
1377 This function divides the 64-bit unsigned value Dividend by the 32-bit
1378 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1379 function returns the 64-bit unsigned quotient.
1380
1381 If Divisor is 0, then ASSERT().
1382
1383 @param Dividend A 64-bit unsigned value.
1384 @param Divisor A 32-bit unsigned value.
1385
1386 @return Dividend / Divisor
1387
1388 **/
1389 UINT64
1390 EFIAPI
1391 DivU64x32 (
1392 IN UINT64 Dividend,
1393 IN UINT32 Divisor
1394 );
1395
1396 /**
1397 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1398 a 32-bit unsigned remainder.
1399
1400 This function divides the 64-bit unsigned value Dividend by the 32-bit
1401 unsigned value Divisor and generates a 32-bit remainder. This function
1402 returns the 32-bit unsigned remainder.
1403
1404 If Divisor is 0, then ASSERT().
1405
1406 @param Dividend A 64-bit unsigned value.
1407 @param Divisor A 32-bit unsigned value.
1408
1409 @return Dividend % Divisor
1410
1411 **/
1412 UINT32
1413 EFIAPI
1414 ModU64x32 (
1415 IN UINT64 Dividend,
1416 IN UINT32 Divisor
1417 );
1418
1419 /**
1420 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1421 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1422
1423 This function divides the 64-bit unsigned value Dividend by the 32-bit
1424 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1425 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1426 This function returns the 64-bit unsigned quotient.
1427
1428 If Divisor is 0, then ASSERT().
1429
1430 @param Dividend A 64-bit unsigned value.
1431 @param Divisor A 32-bit unsigned value.
1432 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1433 optional and may be NULL.
1434
1435 @return Dividend / Divisor
1436
1437 **/
1438 UINT64
1439 EFIAPI
1440 DivU64x32Remainder (
1441 IN UINT64 Dividend,
1442 IN UINT32 Divisor,
1443 OUT UINT32 *Remainder OPTIONAL
1444 );
1445
1446 /**
1447 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
1448 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
1449
1450 This function divides the 64-bit unsigned value Dividend by the 64-bit
1451 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1452 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
1453 This function returns the 64-bit unsigned quotient.
1454
1455 If Divisor is 0, then ASSERT().
1456
1457 @param Dividend A 64-bit unsigned value.
1458 @param Divisor A 64-bit unsigned value.
1459 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
1460 optional and may be NULL.
1461
1462 @return Dividend / Divisor
1463
1464 **/
1465 UINT64
1466 EFIAPI
1467 DivU64x64Remainder (
1468 IN UINT64 Dividend,
1469 IN UINT64 Divisor,
1470 OUT UINT64 *Remainder OPTIONAL
1471 );
1472
1473 /**
1474 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
1475 64-bit signed result and a optional 64-bit signed remainder.
1476
1477 This function divides the 64-bit signed value Dividend by the 64-bit signed
1478 value Divisor and generates a 64-bit signed quotient. If Remainder is not
1479 NULL, then the 64-bit signed remainder is returned in Remainder. This
1480 function returns the 64-bit signed quotient.
1481
1482 If Divisor is 0, then ASSERT().
1483
1484 @param Dividend A 64-bit signed value.
1485 @param Divisor A 64-bit signed value.
1486 @param Remainder A pointer to a 64-bit signed value. This parameter is
1487 optional and may be NULL.
1488
1489 @return Dividend / Divisor
1490
1491 **/
1492 INT64
1493 EFIAPI
1494 DivS64x64Remainder (
1495 IN INT64 Dividend,
1496 IN INT64 Divisor,
1497 OUT INT64 *Remainder OPTIONAL
1498 );
1499
1500 /**
1501 Reads a 16-bit value from memory that may be unaligned.
1502
1503 This function returns the 16-bit value pointed to by Buffer. The function
1504 guarantees that the read operation does not produce an alignment fault.
1505
1506 If the Buffer is NULL, then ASSERT().
1507
1508 @param Buffer Pointer to a 16-bit value that may be unaligned.
1509
1510 @return *Uint16
1511
1512 **/
1513 UINT16
1514 EFIAPI
1515 ReadUnaligned16 (
1516 IN CONST UINT16 *Uint16
1517 );
1518
1519 /**
1520 Writes a 16-bit value to memory that may be unaligned.
1521
1522 This function writes the 16-bit value specified by Value to Buffer. Value is
1523 returned. The function guarantees that the write operation does not produce
1524 an alignment fault.
1525
1526 If the Buffer is NULL, then ASSERT().
1527
1528 @param Buffer Pointer to a 16-bit value that may be unaligned.
1529 @param Value 16-bit value to write to Buffer.
1530
1531 @return Value
1532
1533 **/
1534 UINT16
1535 EFIAPI
1536 WriteUnaligned16 (
1537 OUT UINT16 *Uint16,
1538 IN UINT16 Value
1539 );
1540
1541 /**
1542 Reads a 24-bit value from memory that may be unaligned.
1543
1544 This function returns the 24-bit value pointed to by Buffer. The function
1545 guarantees that the read operation does not produce an alignment fault.
1546
1547 If the Buffer is NULL, then ASSERT().
1548
1549 @param Buffer Pointer to a 24-bit value that may be unaligned.
1550
1551 @return The value read.
1552
1553 **/
1554 UINT32
1555 EFIAPI
1556 ReadUnaligned24 (
1557 IN CONST UINT32 *Buffer
1558 );
1559
1560 /**
1561 Writes a 24-bit value to memory that may be unaligned.
1562
1563 This function writes the 24-bit value specified by Value to Buffer. Value is
1564 returned. The function guarantees that the write operation does not produce
1565 an alignment fault.
1566
1567 If the Buffer is NULL, then ASSERT().
1568
1569 @param Buffer Pointer to a 24-bit value that may be unaligned.
1570 @param Value 24-bit value to write to Buffer.
1571
1572 @return The value written.
1573
1574 **/
1575 UINT32
1576 EFIAPI
1577 WriteUnaligned24 (
1578 OUT UINT32 *Buffer,
1579 IN UINT32 Value
1580 );
1581
1582 /**
1583 Reads a 32-bit value from memory that may be unaligned.
1584
1585 This function returns the 32-bit value pointed to by Buffer. The function
1586 guarantees that the read operation does not produce an alignment fault.
1587
1588 If the Buffer is NULL, then ASSERT().
1589
1590 @param Buffer Pointer to a 32-bit value that may be unaligned.
1591
1592 @return *Uint32
1593
1594 **/
1595 UINT32
1596 EFIAPI
1597 ReadUnaligned32 (
1598 IN CONST UINT32 *Uint32
1599 );
1600
1601 /**
1602 Writes a 32-bit value to memory that may be unaligned.
1603
1604 This function writes the 32-bit value specified by Value to Buffer. Value is
1605 returned. The function guarantees that the write operation does not produce
1606 an alignment fault.
1607
1608 If the Buffer is NULL, then ASSERT().
1609
1610 @param Buffer Pointer to a 32-bit value that may be unaligned.
1611 @param Value 32-bit value to write to Buffer.
1612
1613 @return Value
1614
1615 **/
1616 UINT32
1617 EFIAPI
1618 WriteUnaligned32 (
1619 OUT UINT32 *Uint32,
1620 IN UINT32 Value
1621 );
1622
1623 /**
1624 Reads a 64-bit value from memory that may be unaligned.
1625
1626 This function returns the 64-bit value pointed to by Buffer. The function
1627 guarantees that the read operation does not produce an alignment fault.
1628
1629 If the Buffer is NULL, then ASSERT().
1630
1631 @param Buffer Pointer to a 64-bit value that may be unaligned.
1632
1633 @return *Uint64
1634
1635 **/
1636 UINT64
1637 EFIAPI
1638 ReadUnaligned64 (
1639 IN CONST UINT64 *Uint64
1640 );
1641
1642 /**
1643 Writes a 64-bit value to memory that may be unaligned.
1644
1645 This function writes the 64-bit value specified by Value to Buffer. Value is
1646 returned. The function guarantees that the write operation does not produce
1647 an alignment fault.
1648
1649 If the Buffer is NULL, then ASSERT().
1650
1651 @param Buffer Pointer to a 64-bit value that may be unaligned.
1652 @param Value 64-bit value to write to Buffer.
1653
1654 @return Value
1655
1656 **/
1657 UINT64
1658 EFIAPI
1659 WriteUnaligned64 (
1660 OUT UINT64 *Uint64,
1661 IN UINT64 Value
1662 );
1663
1664 //
1665 // Bit Field Functions
1666 //
1667
1668 /**
1669 Returns a bit field from an 8-bit value.
1670
1671 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1672
1673 If 8-bit operations are not supported, then ASSERT().
1674 If StartBit is greater than 7, then ASSERT().
1675 If EndBit is greater than 7, then ASSERT().
1676 If EndBit is less than or equal to StartBit, then ASSERT().
1677
1678 @param Operand Operand on which to perform the bitfield operation.
1679 @param StartBit The ordinal of the least significant bit in the bit field.
1680 Range 0..7.
1681 @param EndBit The ordinal of the most significant bit in the bit field.
1682 Range 0..7.
1683
1684 @return The bit field read.
1685
1686 **/
1687 UINT8
1688 EFIAPI
1689 BitFieldRead8 (
1690 IN UINT8 Operand,
1691 IN UINTN StartBit,
1692 IN UINTN EndBit
1693 );
1694
1695 /**
1696 Writes a bit field to an 8-bit value, and returns the result.
1697
1698 Writes Value to the bit field specified by the StartBit and the EndBit in
1699 Operand. All other bits in Operand are preserved. The new 8-bit value is
1700 returned.
1701
1702 If 8-bit operations are not supported, then ASSERT().
1703 If StartBit is greater than 7, then ASSERT().
1704 If EndBit is greater than 7, then ASSERT().
1705 If EndBit is less than or equal to StartBit, then ASSERT().
1706
1707 @param Operand Operand on which to perform the bitfield operation.
1708 @param StartBit The ordinal of the least significant bit in the bit field.
1709 Range 0..7.
1710 @param EndBit The ordinal of the most significant bit in the bit field.
1711 Range 0..7.
1712 @param Value New value of the bit field.
1713
1714 @return The new 8-bit value.
1715
1716 **/
1717 UINT8
1718 EFIAPI
1719 BitFieldWrite8 (
1720 IN UINT8 Operand,
1721 IN UINTN StartBit,
1722 IN UINTN EndBit,
1723 IN UINT8 Value
1724 );
1725
1726 /**
1727 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
1728 result.
1729
1730 Performs a bitwise inclusive OR between the bit field specified by StartBit
1731 and EndBit in Operand and the value specified by OrData. All other bits in
1732 Operand are preserved. The new 8-bit value is returned.
1733
1734 If 8-bit operations are not supported, then ASSERT().
1735 If StartBit is greater than 7, then ASSERT().
1736 If EndBit is greater than 7, then ASSERT().
1737 If EndBit is less than or equal to StartBit, then ASSERT().
1738
1739 @param Operand Operand on which to perform the bitfield operation.
1740 @param StartBit The ordinal of the least significant bit in the bit field.
1741 Range 0..7.
1742 @param EndBit The ordinal of the most significant bit in the bit field.
1743 Range 0..7.
1744 @param OrData The value to OR with the read value from the value
1745
1746 @return The new 8-bit value.
1747
1748 **/
1749 UINT8
1750 EFIAPI
1751 BitFieldOr8 (
1752 IN UINT8 Operand,
1753 IN UINTN StartBit,
1754 IN UINTN EndBit,
1755 IN UINT8 OrData
1756 );
1757
1758 /**
1759 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
1760 the result.
1761
1762 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1763 in Operand and the value specified by AndData. All other bits in Operand are
1764 preserved. The new 8-bit value is returned.
1765
1766 If 8-bit operations are not supported, then ASSERT().
1767 If StartBit is greater than 7, then ASSERT().
1768 If EndBit is greater than 7, then ASSERT().
1769 If EndBit is less than or equal to StartBit, then ASSERT().
1770
1771 @param Operand Operand on which to perform the bitfield operation.
1772 @param StartBit The ordinal of the least significant bit in the bit field.
1773 Range 0..7.
1774 @param EndBit The ordinal of the most significant bit in the bit field.
1775 Range 0..7.
1776 @param AndData The value to AND with the read value from the value.
1777
1778 @return The new 8-bit value.
1779
1780 **/
1781 UINT8
1782 EFIAPI
1783 BitFieldAnd8 (
1784 IN UINT8 Operand,
1785 IN UINTN StartBit,
1786 IN UINTN EndBit,
1787 IN UINT8 AndData
1788 );
1789
1790 /**
1791 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
1792 bitwise OR, and returns the result.
1793
1794 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1795 in Operand and the value specified by AndData, followed by a bitwise
1796 inclusive OR with value specified by OrData. All other bits in Operand are
1797 preserved. The new 8-bit value is returned.
1798
1799 If 8-bit operations are not supported, then ASSERT().
1800 If StartBit is greater than 7, then ASSERT().
1801 If EndBit is greater than 7, then ASSERT().
1802 If EndBit is less than or equal to StartBit, then ASSERT().
1803
1804 @param Operand Operand on which to perform the bitfield operation.
1805 @param StartBit The ordinal of the least significant bit in the bit field.
1806 Range 0..7.
1807 @param EndBit The ordinal of the most significant bit in the bit field.
1808 Range 0..7.
1809 @param AndData The value to AND with the read value from the value.
1810 @param OrData The value to OR with the result of the AND operation.
1811
1812 @return The new 8-bit value.
1813
1814 **/
1815 UINT8
1816 EFIAPI
1817 BitFieldAndThenOr8 (
1818 IN UINT8 Operand,
1819 IN UINTN StartBit,
1820 IN UINTN EndBit,
1821 IN UINT8 AndData,
1822 IN UINT8 OrData
1823 );
1824
1825 /**
1826 Returns a bit field from a 16-bit value.
1827
1828 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1829
1830 If 16-bit operations are not supported, then ASSERT().
1831 If StartBit is greater than 15, then ASSERT().
1832 If EndBit is greater than 15, then ASSERT().
1833 If EndBit is less than or equal to StartBit, then ASSERT().
1834
1835 @param Operand Operand on which to perform the bitfield operation.
1836 @param StartBit The ordinal of the least significant bit in the bit field.
1837 Range 0..15.
1838 @param EndBit The ordinal of the most significant bit in the bit field.
1839 Range 0..15.
1840
1841 @return The bit field read.
1842
1843 **/
1844 UINT16
1845 EFIAPI
1846 BitFieldRead16 (
1847 IN UINT16 Operand,
1848 IN UINTN StartBit,
1849 IN UINTN EndBit
1850 );
1851
1852 /**
1853 Writes a bit field to a 16-bit value, and returns the result.
1854
1855 Writes Value to the bit field specified by the StartBit and the EndBit in
1856 Operand. All other bits in Operand are preserved. The new 16-bit value is
1857 returned.
1858
1859 If 16-bit operations are not supported, then ASSERT().
1860 If StartBit is greater than 15, then ASSERT().
1861 If EndBit is greater than 15, then ASSERT().
1862 If EndBit is less than or equal to StartBit, then ASSERT().
1863
1864 @param Operand Operand on which to perform the bitfield operation.
1865 @param StartBit The ordinal of the least significant bit in the bit field.
1866 Range 0..15.
1867 @param EndBit The ordinal of the most significant bit in the bit field.
1868 Range 0..15.
1869 @param Value New value of the bit field.
1870
1871 @return The new 16-bit value.
1872
1873 **/
1874 UINT16
1875 EFIAPI
1876 BitFieldWrite16 (
1877 IN UINT16 Operand,
1878 IN UINTN StartBit,
1879 IN UINTN EndBit,
1880 IN UINT16 Value
1881 );
1882
1883 /**
1884 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
1885 result.
1886
1887 Performs a bitwise inclusive OR between the bit field specified by StartBit
1888 and EndBit in Operand and the value specified by OrData. All other bits in
1889 Operand are preserved. The new 16-bit value is returned.
1890
1891 If 16-bit operations are not supported, then ASSERT().
1892 If StartBit is greater than 15, then ASSERT().
1893 If EndBit is greater than 15, then ASSERT().
1894 If EndBit is less than or equal to StartBit, then ASSERT().
1895
1896 @param Operand Operand on which to perform the bitfield operation.
1897 @param StartBit The ordinal of the least significant bit in the bit field.
1898 Range 0..15.
1899 @param EndBit The ordinal of the most significant bit in the bit field.
1900 Range 0..15.
1901 @param OrData The value to OR with the read value from the value
1902
1903 @return The new 16-bit value.
1904
1905 **/
1906 UINT16
1907 EFIAPI
1908 BitFieldOr16 (
1909 IN UINT16 Operand,
1910 IN UINTN StartBit,
1911 IN UINTN EndBit,
1912 IN UINT16 OrData
1913 );
1914
1915 /**
1916 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
1917 the result.
1918
1919 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1920 in Operand and the value specified by AndData. All other bits in Operand are
1921 preserved. The new 16-bit value is returned.
1922
1923 If 16-bit operations are not supported, then ASSERT().
1924 If StartBit is greater than 15, then ASSERT().
1925 If EndBit is greater than 15, then ASSERT().
1926 If EndBit is less than or equal to StartBit, then ASSERT().
1927
1928 @param Operand Operand on which to perform the bitfield operation.
1929 @param StartBit The ordinal of the least significant bit in the bit field.
1930 Range 0..15.
1931 @param EndBit The ordinal of the most significant bit in the bit field.
1932 Range 0..15.
1933 @param AndData The value to AND with the read value from the value
1934
1935 @return The new 16-bit value.
1936
1937 **/
1938 UINT16
1939 EFIAPI
1940 BitFieldAnd16 (
1941 IN UINT16 Operand,
1942 IN UINTN StartBit,
1943 IN UINTN EndBit,
1944 IN UINT16 AndData
1945 );
1946
1947 /**
1948 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
1949 bitwise OR, and returns the result.
1950
1951 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1952 in Operand and the value specified by AndData, followed by a bitwise
1953 inclusive OR with value specified by OrData. All other bits in Operand are
1954 preserved. The new 16-bit value is returned.
1955
1956 If 16-bit operations are not supported, then ASSERT().
1957 If StartBit is greater than 15, then ASSERT().
1958 If EndBit is greater than 15, then ASSERT().
1959 If EndBit is less than or equal to StartBit, then ASSERT().
1960
1961 @param Operand Operand on which to perform the bitfield operation.
1962 @param StartBit The ordinal of the least significant bit in the bit field.
1963 Range 0..15.
1964 @param EndBit The ordinal of the most significant bit in the bit field.
1965 Range 0..15.
1966 @param AndData The value to AND with the read value from the value.
1967 @param OrData The value to OR with the result of the AND operation.
1968
1969 @return The new 16-bit value.
1970
1971 **/
1972 UINT16
1973 EFIAPI
1974 BitFieldAndThenOr16 (
1975 IN UINT16 Operand,
1976 IN UINTN StartBit,
1977 IN UINTN EndBit,
1978 IN UINT16 AndData,
1979 IN UINT16 OrData
1980 );
1981
1982 /**
1983 Returns a bit field from a 32-bit value.
1984
1985 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1986
1987 If 32-bit operations are not supported, then ASSERT().
1988 If StartBit is greater than 31, then ASSERT().
1989 If EndBit is greater than 31, then ASSERT().
1990 If EndBit is less than or equal to StartBit, then ASSERT().
1991
1992 @param Operand Operand on which to perform the bitfield operation.
1993 @param StartBit The ordinal of the least significant bit in the bit field.
1994 Range 0..31.
1995 @param EndBit The ordinal of the most significant bit in the bit field.
1996 Range 0..31.
1997
1998 @return The bit field read.
1999
2000 **/
2001 UINT32
2002 EFIAPI
2003 BitFieldRead32 (
2004 IN UINT32 Operand,
2005 IN UINTN StartBit,
2006 IN UINTN EndBit
2007 );
2008
2009 /**
2010 Writes a bit field to a 32-bit value, and returns the result.
2011
2012 Writes Value to the bit field specified by the StartBit and the EndBit in
2013 Operand. All other bits in Operand are preserved. The new 32-bit value is
2014 returned.
2015
2016 If 32-bit operations are not supported, then ASSERT().
2017 If StartBit is greater than 31, then ASSERT().
2018 If EndBit is greater than 31, then ASSERT().
2019 If EndBit is less than or equal to StartBit, then ASSERT().
2020
2021 @param Operand Operand on which to perform the bitfield operation.
2022 @param StartBit The ordinal of the least significant bit in the bit field.
2023 Range 0..31.
2024 @param EndBit The ordinal of the most significant bit in the bit field.
2025 Range 0..31.
2026 @param Value New value of the bit field.
2027
2028 @return The new 32-bit value.
2029
2030 **/
2031 UINT32
2032 EFIAPI
2033 BitFieldWrite32 (
2034 IN UINT32 Operand,
2035 IN UINTN StartBit,
2036 IN UINTN EndBit,
2037 IN UINT32 Value
2038 );
2039
2040 /**
2041 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2042 result.
2043
2044 Performs a bitwise inclusive OR between the bit field specified by StartBit
2045 and EndBit in Operand and the value specified by OrData. All other bits in
2046 Operand are preserved. The new 32-bit value is returned.
2047
2048 If 32-bit operations are not supported, then ASSERT().
2049 If StartBit is greater than 31, then ASSERT().
2050 If EndBit is greater than 31, then ASSERT().
2051 If EndBit is less than or equal to StartBit, then ASSERT().
2052
2053 @param Operand Operand on which to perform the bitfield operation.
2054 @param StartBit The ordinal of the least significant bit in the bit field.
2055 Range 0..31.
2056 @param EndBit The ordinal of the most significant bit in the bit field.
2057 Range 0..31.
2058 @param OrData The value to OR with the read value from the value
2059
2060 @return The new 32-bit value.
2061
2062 **/
2063 UINT32
2064 EFIAPI
2065 BitFieldOr32 (
2066 IN UINT32 Operand,
2067 IN UINTN StartBit,
2068 IN UINTN EndBit,
2069 IN UINT32 OrData
2070 );
2071
2072 /**
2073 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2074 the result.
2075
2076 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2077 in Operand and the value specified by AndData. All other bits in Operand are
2078 preserved. The new 32-bit value is returned.
2079
2080 If 32-bit operations are not supported, then ASSERT().
2081 If StartBit is greater than 31, then ASSERT().
2082 If EndBit is greater than 31, then ASSERT().
2083 If EndBit is less than or equal to StartBit, then ASSERT().
2084
2085 @param Operand Operand on which to perform the bitfield operation.
2086 @param StartBit The ordinal of the least significant bit in the bit field.
2087 Range 0..31.
2088 @param EndBit The ordinal of the most significant bit in the bit field.
2089 Range 0..31.
2090 @param AndData The value to AND with the read value from the value
2091
2092 @return The new 32-bit value.
2093
2094 **/
2095 UINT32
2096 EFIAPI
2097 BitFieldAnd32 (
2098 IN UINT32 Operand,
2099 IN UINTN StartBit,
2100 IN UINTN EndBit,
2101 IN UINT32 AndData
2102 );
2103
2104 /**
2105 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2106 bitwise OR, and returns the result.
2107
2108 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2109 in Operand and the value specified by AndData, followed by a bitwise
2110 inclusive OR with value specified by OrData. All other bits in Operand are
2111 preserved. The new 32-bit value is returned.
2112
2113 If 32-bit operations are not supported, then ASSERT().
2114 If StartBit is greater than 31, then ASSERT().
2115 If EndBit is greater than 31, then ASSERT().
2116 If EndBit is less than or equal to StartBit, then ASSERT().
2117
2118 @param Operand Operand on which to perform the bitfield operation.
2119 @param StartBit The ordinal of the least significant bit in the bit field.
2120 Range 0..31.
2121 @param EndBit The ordinal of the most significant bit in the bit field.
2122 Range 0..31.
2123 @param AndData The value to AND with the read value from the value.
2124 @param OrData The value to OR with the result of the AND operation.
2125
2126 @return The new 32-bit value.
2127
2128 **/
2129 UINT32
2130 EFIAPI
2131 BitFieldAndThenOr32 (
2132 IN UINT32 Operand,
2133 IN UINTN StartBit,
2134 IN UINTN EndBit,
2135 IN UINT32 AndData,
2136 IN UINT32 OrData
2137 );
2138
2139 /**
2140 Returns a bit field from a 64-bit value.
2141
2142 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2143
2144 If 64-bit operations are not supported, then ASSERT().
2145 If StartBit is greater than 63, then ASSERT().
2146 If EndBit is greater than 63, then ASSERT().
2147 If EndBit is less than or equal to StartBit, then ASSERT().
2148
2149 @param Operand Operand on which to perform the bitfield operation.
2150 @param StartBit The ordinal of the least significant bit in the bit field.
2151 Range 0..63.
2152 @param EndBit The ordinal of the most significant bit in the bit field.
2153 Range 0..63.
2154
2155 @return The bit field read.
2156
2157 **/
2158 UINT64
2159 EFIAPI
2160 BitFieldRead64 (
2161 IN UINT64 Operand,
2162 IN UINTN StartBit,
2163 IN UINTN EndBit
2164 );
2165
2166 /**
2167 Writes a bit field to a 64-bit value, and returns the result.
2168
2169 Writes Value to the bit field specified by the StartBit and the EndBit in
2170 Operand. All other bits in Operand are preserved. The new 64-bit value is
2171 returned.
2172
2173 If 64-bit operations are not supported, then ASSERT().
2174 If StartBit is greater than 63, then ASSERT().
2175 If EndBit is greater than 63, then ASSERT().
2176 If EndBit is less than or equal to StartBit, then ASSERT().
2177
2178 @param Operand Operand on which to perform the bitfield operation.
2179 @param StartBit The ordinal of the least significant bit in the bit field.
2180 Range 0..63.
2181 @param EndBit The ordinal of the most significant bit in the bit field.
2182 Range 0..63.
2183 @param Value New value of the bit field.
2184
2185 @return The new 64-bit value.
2186
2187 **/
2188 UINT64
2189 EFIAPI
2190 BitFieldWrite64 (
2191 IN UINT64 Operand,
2192 IN UINTN StartBit,
2193 IN UINTN EndBit,
2194 IN UINT64 Value
2195 );
2196
2197 /**
2198 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2199 result.
2200
2201 Performs a bitwise inclusive OR between the bit field specified by StartBit
2202 and EndBit in Operand and the value specified by OrData. All other bits in
2203 Operand are preserved. The new 64-bit value is returned.
2204
2205 If 64-bit operations are not supported, then ASSERT().
2206 If StartBit is greater than 63, then ASSERT().
2207 If EndBit is greater than 63, then ASSERT().
2208 If EndBit is less than or equal to StartBit, then ASSERT().
2209
2210 @param Operand Operand on which to perform the bitfield operation.
2211 @param StartBit The ordinal of the least significant bit in the bit field.
2212 Range 0..63.
2213 @param EndBit The ordinal of the most significant bit in the bit field.
2214 Range 0..63.
2215 @param OrData The value to OR with the read value from the value
2216
2217 @return The new 64-bit value.
2218
2219 **/
2220 UINT64
2221 EFIAPI
2222 BitFieldOr64 (
2223 IN UINT64 Operand,
2224 IN UINTN StartBit,
2225 IN UINTN EndBit,
2226 IN UINT64 OrData
2227 );
2228
2229 /**
2230 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2231 the result.
2232
2233 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2234 in Operand and the value specified by AndData. All other bits in Operand are
2235 preserved. The new 64-bit value is returned.
2236
2237 If 64-bit operations are not supported, then ASSERT().
2238 If StartBit is greater than 63, then ASSERT().
2239 If EndBit is greater than 63, then ASSERT().
2240 If EndBit is less than or equal to StartBit, then ASSERT().
2241
2242 @param Operand Operand on which to perform the bitfield operation.
2243 @param StartBit The ordinal of the least significant bit in the bit field.
2244 Range 0..63.
2245 @param EndBit The ordinal of the most significant bit in the bit field.
2246 Range 0..63.
2247 @param AndData The value to AND with the read value from the value
2248
2249 @return The new 64-bit value.
2250
2251 **/
2252 UINT64
2253 EFIAPI
2254 BitFieldAnd64 (
2255 IN UINT64 Operand,
2256 IN UINTN StartBit,
2257 IN UINTN EndBit,
2258 IN UINT64 AndData
2259 );
2260
2261 /**
2262 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2263 bitwise OR, and returns the result.
2264
2265 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2266 in Operand and the value specified by AndData, followed by a bitwise
2267 inclusive OR with value specified by OrData. All other bits in Operand are
2268 preserved. The new 64-bit value is returned.
2269
2270 If 64-bit operations are not supported, then ASSERT().
2271 If StartBit is greater than 63, then ASSERT().
2272 If EndBit is greater than 63, then ASSERT().
2273 If EndBit is less than or equal to StartBit, then ASSERT().
2274
2275 @param Operand Operand on which to perform the bitfield operation.
2276 @param StartBit The ordinal of the least significant bit in the bit field.
2277 Range 0..63.
2278 @param EndBit The ordinal of the most significant bit in the bit field.
2279 Range 0..63.
2280 @param AndData The value to AND with the read value from the value.
2281 @param OrData The value to OR with the result of the AND operation.
2282
2283 @return The new 64-bit value.
2284
2285 **/
2286 UINT64
2287 EFIAPI
2288 BitFieldAndThenOr64 (
2289 IN UINT64 Operand,
2290 IN UINTN StartBit,
2291 IN UINTN EndBit,
2292 IN UINT64 AndData,
2293 IN UINT64 OrData
2294 );
2295
2296 //
2297 // Base Library Synchronization Functions
2298 //
2299
2300 /**
2301 Retrieves the architecture specific spin lock alignment requirements for
2302 optimal spin lock performance.
2303
2304 This function retrieves the spin lock alignment requirements for optimal
2305 performance on a given CPU architecture. The spin lock alignment must be a
2306 power of two and is returned by this function. If there are no alignment
2307 requirements, then 1 must be returned. The spin lock synchronization
2308 functions must function correctly if the spin lock size and alignment values
2309 returned by this function are not used at all. These values are hints to the
2310 consumers of the spin lock synchronization functions to obtain optimal spin
2311 lock performance.
2312
2313 @return The architecture specific spin lock alignment.
2314
2315 **/
2316 UINTN
2317 EFIAPI
2318 GetSpinLockProperties (
2319 VOID
2320 );
2321
2322 /**
2323 Initializes a spin lock to the released state and returns the spin lock.
2324
2325 This function initializes the spin lock specified by SpinLock to the released
2326 state, and returns SpinLock. Optimal performance can be achieved by calling
2327 GetSpinLockProperties() to determine the size and alignment requirements for
2328 SpinLock.
2329
2330 If SpinLock is NULL, then ASSERT().
2331
2332 @param SpinLock A pointer to the spin lock to initialize to the released
2333 state.
2334
2335 @return SpinLock
2336
2337 **/
2338 SPIN_LOCK *
2339 EFIAPI
2340 InitializeSpinLock (
2341 IN SPIN_LOCK *SpinLock
2342 );
2343
2344 /**
2345 Waits until a spin lock can be placed in the acquired state.
2346
2347 This function checks the state of the spin lock specified by SpinLock. If
2348 SpinLock is in the released state, then this function places SpinLock in the
2349 acquired state and returns SpinLock. Otherwise, this function waits
2350 indefinitely for the spin lock to be released, and then places it in the
2351 acquired state and returns SpinLock. All state transitions of SpinLock must
2352 be performed using MP safe mechanisms.
2353
2354 If SpinLock is NULL, then ASSERT().
2355 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2356 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2357 PcdSpinLockTimeout microseconds, then ASSERT().
2358
2359 @param SpinLock A pointer to the spin lock to place in the acquired state.
2360
2361 @return SpinLock
2362
2363 **/
2364 SPIN_LOCK *
2365 EFIAPI
2366 AcquireSpinLock (
2367 IN SPIN_LOCK *SpinLock
2368 );
2369
2370 /**
2371 Attempts to place a spin lock in the acquired state.
2372
2373 This function checks the state of the spin lock specified by SpinLock. If
2374 SpinLock is in the released state, then this function places SpinLock in the
2375 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2376 transitions of SpinLock must be performed using MP safe mechanisms.
2377
2378 If SpinLock is NULL, then ASSERT().
2379 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2380
2381 @param SpinLock A pointer to the spin lock to place in the acquired state.
2382
2383 @retval TRUE SpinLock was placed in the acquired state.
2384 @retval FALSE SpinLock could not be acquired.
2385
2386 **/
2387 BOOLEAN
2388 EFIAPI
2389 AcquireSpinLockOrFail (
2390 IN SPIN_LOCK *SpinLock
2391 );
2392
2393 /**
2394 Releases a spin lock.
2395
2396 This function places the spin lock specified by SpinLock in the release state
2397 and returns SpinLock.
2398
2399 If SpinLock is NULL, then ASSERT().
2400 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2401
2402 @param SpinLock A pointer to the spin lock to release.
2403
2404 @return SpinLock
2405
2406 **/
2407 SPIN_LOCK *
2408 EFIAPI
2409 ReleaseSpinLock (
2410 IN SPIN_LOCK *SpinLock
2411 );
2412
2413 /**
2414 Performs an atomic increment of an 32-bit unsigned integer.
2415
2416 Performs an atomic increment of the 32-bit unsigned integer specified by
2417 Value and returns the incremented value. The increment operation must be
2418 performed using MP safe mechanisms. The state of the return value is not
2419 guaranteed to be MP safe.
2420
2421 If Value is NULL, then ASSERT().
2422
2423 @param Value A pointer to the 32-bit value to increment.
2424
2425 @return The incremented value.
2426
2427 **/
2428 UINT32
2429 EFIAPI
2430 InterlockedIncrement (
2431 IN UINT32 *Value
2432 );
2433
2434 /**
2435 Performs an atomic decrement of an 32-bit unsigned integer.
2436
2437 Performs an atomic decrement of the 32-bit unsigned integer specified by
2438 Value and returns the decremented value. The decrement operation must be
2439 performed using MP safe mechanisms. The state of the return value is not
2440 guaranteed to be MP safe.
2441
2442 If Value is NULL, then ASSERT().
2443
2444 @param Value A pointer to the 32-bit value to decrement.
2445
2446 @return The decremented value.
2447
2448 **/
2449 UINT32
2450 EFIAPI
2451 InterlockedDecrement (
2452 IN UINT32 *Value
2453 );
2454
2455 /**
2456 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
2457
2458 @param Value A pointer to the 32-bit value for the compare exchange
2459 operation.
2460 @param CompareValue 32-bit value used in compare operation.
2461 @param ExchangeValue 32-bit value used in exchange operation.
2462
2463 @return The original *Value before exchange.
2464
2465 **/
2466 UINT32
2467 EFIAPI
2468 InterlockedCompareExchange32 (
2469 IN UINT32 *Value,
2470 IN UINT32 CompareValue,
2471 IN UINT32 ExchangeValue
2472 );
2473
2474 /**
2475 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
2476
2477 @param Value A pointer to the 64-bit value for the compare exchange
2478 operation.
2479 @param CompareValue 64-bit value used in compare operation.
2480 @param ExchangeValue 64-bit value used in exchange operation.
2481
2482 @return The original *Value before exchange.
2483
2484 **/
2485 UINT64
2486 EFIAPI
2487 InterlockedCompareExchange64 (
2488 IN UINT64 *Value,
2489 IN UINT64 CompareValue,
2490 IN UINT64 ExchangeValue
2491 );
2492
2493 /**
2494 Performs an atomic compare exchange operation on a pointer value.
2495
2496 Performs an atomic compare exchange operation on the pointer value specified
2497 by Value. If Value is equal to CompareValue, then Value is set to
2498 ExchangeValue and CompareValue is returned. If Value is not equal to
2499 CompareValue, then Value is returned. The compare exchange operation must be
2500 performed using MP safe mechanisms.
2501
2502 If Value is NULL, then ASSERT().
2503
2504 @param Value A pointer to the pointer value for the compare exchange
2505 operation.
2506 @param CompareValue Pointer value used in compare operation.
2507 @param ExchangeValue Pointer value used in exchange operation.
2508
2509 **/
2510 VOID *
2511 EFIAPI
2512 InterlockedCompareExchangePointer (
2513 IN VOID **Value,
2514 IN VOID *CompareValue,
2515 IN VOID *ExchangeValue
2516 );
2517
2518 //
2519 // Base Library CPU Functions
2520 //
2521 typedef
2522 VOID
2523 (EFIAPI *SWITCH_STACK_ENTRY_POINT) (
2524 IN VOID *Context1, OPTIONAL
2525 IN VOID *Context2 OPTIONAL
2526 );
2527
2528 /**
2529 Used to serialize load and store operations.
2530
2531 All loads and stores that proceed calls to this function are guaranteed to be
2532 globally visible when this function returns.
2533
2534 **/
2535 VOID
2536 EFIAPI
2537 MemoryFence (
2538 VOID
2539 );
2540
2541 /**
2542 Saves the current CPU context that can be restored with a call to LongJump()
2543 and returns 0.
2544
2545 Saves the current CPU context in the buffer specified by JumpBuffer and
2546 returns 0. The initial call to SetJump() must always return 0. Subsequent
2547 calls to LongJump() cause a non-zero value to be returned by SetJump().
2548
2549 If JumpBuffer is NULL, then ASSERT().
2550
2551 @param JumpBuffer A pointer to CPU context buffer.
2552
2553 @retval 0 Indicates a return from SetJump().
2554
2555 **/
2556 UINTN
2557 EFIAPI
2558 SetJump (
2559 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
2560 );
2561
2562 /**
2563 Restores the CPU context that was saved with SetJump().
2564
2565 Restores the CPU context from the buffer specified by JumpBuffer. This
2566 function never returns to the caller. Instead is resumes execution based on
2567 the state of JumpBuffer.
2568
2569 If JumpBuffer is NULL, then ASSERT().
2570 If Value is 0, then ASSERT().
2571
2572 @param JumpBuffer A pointer to CPU context buffer.
2573 @param Value The value to return when the SetJump() context is
2574 restored and must be non-zero.
2575
2576 **/
2577 VOID
2578 EFIAPI
2579 LongJump (
2580 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
2581 IN UINTN Value
2582 );
2583
2584 /**
2585 Enables CPU interrupts.
2586
2587 Enables CPU interrupts.
2588
2589 **/
2590 VOID
2591 EFIAPI
2592 EnableInterrupts (
2593 VOID
2594 );
2595
2596 /**
2597 Disables CPU interrupts.
2598
2599 Disables CPU interrupts.
2600
2601 **/
2602 VOID
2603 EFIAPI
2604 DisableInterrupts (
2605 VOID
2606 );
2607
2608 /**
2609 Disables CPU interrupts and returns the interrupt state prior to the disable
2610 operation.
2611
2612 Disables CPU interrupts and returns the interrupt state prior to the disable
2613 operation.
2614
2615 @retval TRUE CPU interrupts were enabled on entry to this call.
2616 @retval FALSE CPU interrupts were disabled on entry to this call.
2617
2618 **/
2619 BOOLEAN
2620 EFIAPI
2621 SaveAndDisableInterrupts (
2622 VOID
2623 );
2624
2625 /**
2626 Enables CPU interrupts for the smallest window required to capture any
2627 pending interrupts.
2628
2629 Enables CPU interrupts for the smallest window required to capture any
2630 pending interrupts.
2631
2632 **/
2633 VOID
2634 EFIAPI
2635 EnableDisableInterrupts (
2636 VOID
2637 );
2638
2639 /**
2640 Retrieves the current CPU interrupt state.
2641
2642 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
2643 currently enabled. Otherwise returns FALSE.
2644
2645 @retval TRUE CPU interrupts are enabled.
2646 @retval FALSE CPU interrupts are disabled.
2647
2648 **/
2649 BOOLEAN
2650 EFIAPI
2651 GetInterruptState (
2652 VOID
2653 );
2654
2655 /**
2656 Set the current CPU interrupt state.
2657
2658 Sets the current CPU interrupt state to the state specified by
2659 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
2660 InterruptState is FALSE, then interrupts are disabled. InterruptState is
2661 returned.
2662
2663 @param InterruptState TRUE if interrupts should enabled. FALSE if
2664 interrupts should be disabled.
2665
2666 @return InterruptState
2667
2668 **/
2669 BOOLEAN
2670 EFIAPI
2671 SetInterruptState (
2672 IN BOOLEAN InterruptState
2673 );
2674
2675 /**
2676 Places the CPU in a sleep state until an interrupt is received.
2677
2678 Places the CPU in a sleep state until an interrupt is received. If interrupts
2679 are disabled prior to calling this function, then the CPU will be placed in a
2680 sleep state indefinitely.
2681
2682 **/
2683 VOID
2684 EFIAPI
2685 CpuSleep (
2686 VOID
2687 );
2688
2689 /**
2690 Requests CPU to pause for a short period of time.
2691
2692 Requests CPU to pause for a short period of time. Typically used in MP
2693 systems to prevent memory starvation while waiting for a spin lock.
2694
2695 **/
2696 VOID
2697 EFIAPI
2698 CpuPause (
2699 VOID
2700 );
2701
2702 /**
2703 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2704
2705 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2706
2707 **/
2708 VOID
2709 EFIAPI
2710 CpuFlushTlb (
2711 VOID
2712 );
2713
2714 /**
2715 Transfers control to a function starting with a new stack.
2716
2717 Transfers control to the function specified by EntryPoint using the new stack
2718 specified by NewStack and passing in the parameters specified by Context1 and
2719 Context2. Context1 and Context2 are optional and may be NULL. The function
2720 EntryPoint must never return.
2721
2722 If EntryPoint is NULL, then ASSERT().
2723 If NewStack is NULL, then ASSERT().
2724
2725 @param EntryPoint A pointer to function to call with the new stack.
2726 @param Context1 A pointer to the context to pass into the EntryPoint
2727 function.
2728 @param Context2 A pointer to the context to pass into the EntryPoint
2729 function.
2730 @param NewStack A pointer to the new stack to use for the EntryPoint
2731 function.
2732
2733 **/
2734 VOID
2735 EFIAPI
2736 SwitchStack (
2737 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
2738 IN VOID *Context1, OPTIONAL
2739 IN VOID *Context2, OPTIONAL
2740 IN VOID *NewStack
2741 );
2742
2743 /**
2744 Generates a breakpoint on the CPU.
2745
2746 Generates a breakpoint on the CPU. The breakpoint must be implemented such
2747 that code can resume normal execution after the breakpoint.
2748
2749 **/
2750 VOID
2751 EFIAPI
2752 CpuBreakpoint (
2753 VOID
2754 );
2755
2756 /**
2757 Executes an infinite loop.
2758
2759 Forces the CPU to execute an infinite loop. A debugger may be used to skip
2760 past the loop and the code that follows the loop must execute properly. This
2761 implies that the infinite loop must not cause the code that follow it to be
2762 optimized away.
2763
2764 **/
2765 VOID
2766 EFIAPI
2767 CpuDeadLoop (
2768 VOID
2769 );
2770
2771 //
2772 // IA32 and X64 Specific Functions
2773 //
2774 //
2775 // Byte packed structure for 16-bit Real Mode EFLAGS
2776 //
2777 typedef union {
2778 struct {
2779 UINT32 CF:1; // Carry Flag
2780 UINT32 Reserved_0:1; // Reserved
2781 UINT32 PF:1; // Parity Flag
2782 UINT32 Reserved_1:1; // Reserved
2783 UINT32 AF:1; // Auxiliary Carry Flag
2784 UINT32 Reserved_2:1; // Reserved
2785 UINT32 ZF:1; // Zero Flag
2786 UINT32 SF:1; // Sign Flag
2787 UINT32 TF:1; // Trap Flag
2788 UINT32 IF:1; // Interrupt Enable Flag
2789 UINT32 DF:1; // Direction Flag
2790 UINT32 OF:1; // Overflow Flag
2791 UINT32 IOPL:2; // I/O Privilege Level
2792 UINT32 NT:1; // Nested Task
2793 UINT32 Reserved_3:1; // Reserved
2794 } Bits;
2795 UINT16 Uint16;
2796 } IA32_FLAGS16;
2797
2798 //
2799 // Byte packed structure for EFLAGS/RFLAGS
2800 // 32-bits on IA-32
2801 // 64-bits on X64. The upper 32-bits on X64 are reserved
2802 //
2803 typedef union {
2804 struct {
2805 UINT32 CF:1; // Carry Flag
2806 UINT32 Reserved_0:1; // Reserved
2807 UINT32 PF:1; // Parity Flag
2808 UINT32 Reserved_1:1; // Reserved
2809 UINT32 AF:1; // Auxiliary Carry Flag
2810 UINT32 Reserved_2:1; // Reserved
2811 UINT32 ZF:1; // Zero Flag
2812 UINT32 SF:1; // Sign Flag
2813 UINT32 TF:1; // Trap Flag
2814 UINT32 IF:1; // Interrupt Enable Flag
2815 UINT32 DF:1; // Direction Flag
2816 UINT32 OF:1; // Overflow Flag
2817 UINT32 IOPL:2; // I/O Privilege Level
2818 UINT32 NT:1; // Nested Task
2819 UINT32 Reserved_3:1; // Reserved
2820 UINT32 RF:1; // Resume Flag
2821 UINT32 VM:1; // Virtual 8086 Mode
2822 UINT32 AC:1; // Alignment Check
2823 UINT32 VIF:1; // Virtual Interrupt Flag
2824 UINT32 VIP:1; // Virtual Interrupt Pending
2825 UINT32 ID:1; // ID Flag
2826 UINT32 Reserved_4:10; // Reserved
2827 } Bits;
2828 UINTN UintN;
2829 } IA32_EFLAGS32;
2830
2831 //
2832 // Byte packed structure for Control Register 0 (CR0)
2833 // 32-bits on IA-32
2834 // 64-bits on X64. The upper 32-bits on X64 are reserved
2835 //
2836 typedef union {
2837 struct {
2838 UINT32 PE:1; // Protection Enable
2839 UINT32 MP:1; // Monitor Coprocessor
2840 UINT32 EM:1; // Emulation
2841 UINT32 TS:1; // Task Switched
2842 UINT32 ET:1; // Extension Type
2843 UINT32 NE:1; // Numeric Error
2844 UINT32 Reserved_0:10; // Reserved
2845 UINT32 WP:1; // Write Protect
2846 UINT32 Reserved_1:1; // Reserved
2847 UINT32 AM:1; // Alignment Mask
2848 UINT32 Reserved_2:10; // Reserved
2849 UINT32 NW:1; // Mot Write-through
2850 UINT32 CD:1; // Cache Disable
2851 UINT32 PG:1; // Paging
2852 } Bits;
2853 UINTN UintN;
2854 } IA32_CR0;
2855
2856 //
2857 // Byte packed structure for Control Register 4 (CR4)
2858 // 32-bits on IA-32
2859 // 64-bits on X64. The upper 32-bits on X64 are reserved
2860 //
2861 typedef union {
2862 struct {
2863 UINT32 VME:1; // Virtual-8086 Mode Extensions
2864 UINT32 PVI:1; // Protected-Mode Virtual Interrupts
2865 UINT32 TSD:1; // Time Stamp Disable
2866 UINT32 DE:1; // Debugging Extensions
2867 UINT32 PSE:1; // Page Size Extensions
2868 UINT32 PAE:1; // Physical Address Extension
2869 UINT32 MCE:1; // Machine Check Enable
2870 UINT32 PGE:1; // Page Global Enable
2871 UINT32 PCE:1; // Performance Monitoring Counter
2872 // Enable
2873 UINT32 OSFXSR:1; // Operating System Support for
2874 // FXSAVE and FXRSTOR instructions
2875 UINT32 OSXMMEXCPT:1; // Operating System Support for
2876 // Unmasked SIMD Floating Point
2877 // Exceptions
2878 UINT32 Reserved_0:2; // Reserved
2879 UINT32 VMXE:1; // VMX Enable
2880 UINT32 Reserved_1:18; // Reseved
2881 } Bits;
2882 UINTN UintN;
2883 } IA32_CR4;
2884
2885 //
2886 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
2887 /// @bug How to make this structure byte-packed in a compiler independent way?
2888 //
2889 typedef struct {
2890 UINT16 Limit;
2891 UINTN Base;
2892 } IA32_DESCRIPTOR;
2893
2894 #define IA32_IDT_GATE_TYPE_TASK 0x85
2895 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
2896 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
2897 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
2898 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
2899
2900 //
2901 // Byte packed structure for an Interrupt Gate Descriptor
2902 //
2903 typedef union {
2904 struct {
2905 UINT32 OffsetLow:16; // Offset bits 15..0
2906 UINT32 Selector:16; // Selector
2907 UINT32 Reserved_0:8; // Reserved
2908 UINT32 GateType:8; // Gate Type. See #defines above
2909 UINT32 OffsetHigh:16; // Offset bits 31..16
2910 } Bits;
2911 UINT64 Uint64;
2912 } IA32_IDT_GATE_DESCRIPTOR;
2913
2914 //
2915 // Byte packed structure for an FP/SSE/SSE2 context
2916 //
2917 typedef struct {
2918 UINT8 Buffer[512];
2919 } IA32_FX_BUFFER;
2920
2921 //
2922 // Structures for the 16-bit real mode thunks
2923 //
2924 typedef struct {
2925 UINT32 Reserved1;
2926 UINT32 Reserved2;
2927 UINT32 Reserved3;
2928 UINT32 Reserved4;
2929 UINT8 BL;
2930 UINT8 BH;
2931 UINT16 Reserved5;
2932 UINT8 DL;
2933 UINT8 DH;
2934 UINT16 Reserved6;
2935 UINT8 CL;
2936 UINT8 CH;
2937 UINT16 Reserved7;
2938 UINT8 AL;
2939 UINT8 AH;
2940 UINT16 Reserved8;
2941 } IA32_BYTE_REGS;
2942
2943 typedef struct {
2944 UINT16 DI;
2945 UINT16 Reserved1;
2946 UINT16 SI;
2947 UINT16 Reserved2;
2948 UINT16 BP;
2949 UINT16 Reserved3;
2950 UINT16 SP;
2951 UINT16 Reserved4;
2952 UINT16 BX;
2953 UINT16 Reserved5;
2954 UINT16 DX;
2955 UINT16 Reserved6;
2956 UINT16 CX;
2957 UINT16 Reserved7;
2958 UINT16 AX;
2959 UINT16 Reserved8;
2960 } IA32_WORD_REGS;
2961
2962 typedef struct {
2963 UINT32 EDI;
2964 UINT32 ESI;
2965 UINT32 EBP;
2966 UINT32 ESP;
2967 UINT32 EBX;
2968 UINT32 EDX;
2969 UINT32 ECX;
2970 UINT32 EAX;
2971 UINT16 DS;
2972 UINT16 ES;
2973 UINT16 FS;
2974 UINT16 GS;
2975 IA32_EFLAGS32 EFLAGS;
2976 UINT32 Eip;
2977 UINT16 CS;
2978 UINT16 SS;
2979 } IA32_DWORD_REGS;
2980
2981 typedef union {
2982 IA32_DWORD_REGS E;
2983 IA32_WORD_REGS X;
2984 IA32_BYTE_REGS H;
2985 } IA32_REGISTER_SET;
2986
2987 //
2988 // Byte packed structure for an 16-bit real mode thunks
2989 //
2990 typedef struct {
2991 IA32_REGISTER_SET *RealModeState;
2992 VOID *RealModeBuffer;
2993 UINT32 RealModeBufferSize;
2994 UINT32 ThunkAttributes;
2995 } THUNK_CONTEXT;
2996
2997 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
2998 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
2999 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3000
3001 /**
3002 Retrieves CPUID information.
3003
3004 Executes the CPUID instruction with EAX set to the value specified by Index.
3005 This function always returns Index.
3006 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3007 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3008 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3009 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3010 This function is only available on IA-32 and X64.
3011
3012 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3013 instruction.
3014 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3015 instruction. This is an optional parameter that may be NULL.
3016 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3017 instruction. This is an optional parameter that may be NULL.
3018 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3019 instruction. This is an optional parameter that may be NULL.
3020 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3021 instruction. This is an optional parameter that may be NULL.
3022
3023 @return Index
3024
3025 **/
3026 UINT32
3027 EFIAPI
3028 AsmCpuid (
3029 IN UINT32 Index,
3030 OUT UINT32 *Eax, OPTIONAL
3031 OUT UINT32 *Ebx, OPTIONAL
3032 OUT UINT32 *Ecx, OPTIONAL
3033 OUT UINT32 *Edx OPTIONAL
3034 );
3035
3036 /**
3037 Retrieves CPUID information using an extended leaf identifier.
3038
3039 Executes the CPUID instruction with EAX set to the value specified by Index
3040 and ECX set to the value specified by SubIndex. This function always returns
3041 Index. This function is only available on IA-32 and x64.
3042
3043 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3044 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3045 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3046 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3047
3048 @param Index The 32-bit value to load into EAX prior to invoking the
3049 CPUID instruction.
3050 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3051 CPUID instruction.
3052 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3053 instruction. This is an optional parameter that may be
3054 NULL.
3055 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3056 instruction. This is an optional parameter that may be
3057 NULL.
3058 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3059 instruction. This is an optional parameter that may be
3060 NULL.
3061 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3062 instruction. This is an optional parameter that may be
3063 NULL.
3064
3065 @return Index
3066
3067 **/
3068 UINT32
3069 EFIAPI
3070 AsmCpuidEx (
3071 IN UINT32 Index,
3072 IN UINT32 SubIndex,
3073 OUT UINT32 *Eax, OPTIONAL
3074 OUT UINT32 *Ebx, OPTIONAL
3075 OUT UINT32 *Ecx, OPTIONAL
3076 OUT UINT32 *Edx OPTIONAL
3077 );
3078
3079 /**
3080 Returns the lower 32-bits of a Machine Specific Register(MSR).
3081
3082 Reads and returns the lower 32-bits of the MSR specified by Index.
3083 No parameter checking is performed on Index, and some Index values may cause
3084 CPU exceptions. The caller must either guarantee that Index is valid, or the
3085 caller must set up exception handlers to catch the exceptions. This function
3086 is only available on IA-32 and X64.
3087
3088 @param Index The 32-bit MSR index to read.
3089
3090 @return The lower 32 bits of the MSR identified by Index.
3091
3092 **/
3093 UINT32
3094 EFIAPI
3095 AsmReadMsr32 (
3096 IN UINT32 Index
3097 );
3098
3099 /**
3100 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3101
3102 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3103 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3104 the MSR is returned. No parameter checking is performed on Index or Value,
3105 and some of these may cause CPU exceptions. The caller must either guarantee
3106 that Index and Value are valid, or the caller must establish proper exception
3107 handlers. This function is only available on IA-32 and X64.
3108
3109 @param Index The 32-bit MSR index to write.
3110 @param Value The 32-bit value to write to the MSR.
3111
3112 @return Value
3113
3114 **/
3115 UINT32
3116 EFIAPI
3117 AsmWriteMsr32 (
3118 IN UINT32 Index,
3119 IN UINT32 Value
3120 );
3121
3122 /**
3123 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3124 writes the result back to the 64-bit MSR.
3125
3126 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3127 between the lower 32-bits of the read result and the value specified by
3128 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3129 32-bits of the value written to the MSR is returned. No parameter checking is
3130 performed on Index or OrData, and some of these may cause CPU exceptions. The
3131 caller must either guarantee that Index and OrData are valid, or the caller
3132 must establish proper exception handlers. This function is only available on
3133 IA-32 and X64.
3134
3135 @param Index The 32-bit MSR index to write.
3136 @param OrData The value to OR with the read value from the MSR.
3137
3138 @return The lower 32-bit value written to the MSR.
3139
3140 **/
3141 UINT32
3142 EFIAPI
3143 AsmMsrOr32 (
3144 IN UINT32 Index,
3145 IN UINT32 OrData
3146 );
3147
3148 /**
3149 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3150 the result back to the 64-bit MSR.
3151
3152 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3153 lower 32-bits of the read result and the value specified by AndData, and
3154 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3155 the value written to the MSR is returned. No parameter checking is performed
3156 on Index or AndData, and some of these may cause CPU exceptions. The caller
3157 must either guarantee that Index and AndData are valid, or the caller must
3158 establish proper exception handlers. This function is only available on IA-32
3159 and X64.
3160
3161 @param Index The 32-bit MSR index to write.
3162 @param AndData The value to AND with the read value from the MSR.
3163
3164 @return The lower 32-bit value written to the MSR.
3165
3166 **/
3167 UINT32
3168 EFIAPI
3169 AsmMsrAnd32 (
3170 IN UINT32 Index,
3171 IN UINT32 AndData
3172 );
3173
3174 /**
3175 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3176 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3177
3178 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3179 lower 32-bits of the read result and the value specified by AndData
3180 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3181 result of the AND operation and the value specified by OrData, and writes the
3182 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3183 written to the MSR is returned. No parameter checking is performed on Index,
3184 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3185 must either guarantee that Index, AndData, and OrData are valid, or the
3186 caller must establish proper exception handlers. This function is only
3187 available on IA-32 and X64.
3188
3189 @param Index The 32-bit MSR index to write.
3190 @param AndData The value to AND with the read value from the MSR.
3191 @param OrData The value to OR with the result of the AND operation.
3192
3193 @return The lower 32-bit value written to the MSR.
3194
3195 **/
3196 UINT32
3197 EFIAPI
3198 AsmMsrAndThenOr32 (
3199 IN UINT32 Index,
3200 IN UINT32 AndData,
3201 IN UINT32 OrData
3202 );
3203
3204 /**
3205 Reads a bit field of an MSR.
3206
3207 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3208 specified by the StartBit and the EndBit. The value of the bit field is
3209 returned. The caller must either guarantee that Index is valid, or the caller
3210 must set up exception handlers to catch the exceptions. This function is only
3211 available on IA-32 and X64.
3212
3213 If StartBit is greater than 31, then ASSERT().
3214 If EndBit is greater than 31, then ASSERT().
3215 If EndBit is less than or equal to StartBit, then ASSERT().
3216
3217 @param Index The 32-bit MSR index to read.
3218 @param StartBit The ordinal of the least significant bit in the bit field.
3219 Range 0..31.
3220 @param EndBit The ordinal of the most significant bit in the bit field.
3221 Range 0..31.
3222
3223 @return The bit field read from the MSR.
3224
3225 **/
3226 UINT32
3227 EFIAPI
3228 AsmMsrBitFieldRead32 (
3229 IN UINT32 Index,
3230 IN UINTN StartBit,
3231 IN UINTN EndBit
3232 );
3233
3234 /**
3235 Writes a bit field to an MSR.
3236
3237 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3238 field is specified by the StartBit and the EndBit. All other bits in the
3239 destination MSR are preserved. The lower 32-bits of the MSR written is
3240 returned. Extra left bits in Value are stripped. The caller must either
3241 guarantee that Index and the data written is valid, or the caller must set up
3242 exception handlers to catch the exceptions. This function is only available
3243 on IA-32 and X64.
3244
3245 If StartBit is greater than 31, then ASSERT().
3246 If EndBit is greater than 31, then ASSERT().
3247 If EndBit is less than or equal to StartBit, then ASSERT().
3248
3249 @param Index The 32-bit MSR index to write.
3250 @param StartBit The ordinal of the least significant bit in the bit field.
3251 Range 0..31.
3252 @param EndBit The ordinal of the most significant bit in the bit field.
3253 Range 0..31.
3254 @param Value New value of the bit field.
3255
3256 @return The lower 32-bit of the value written to the MSR.
3257
3258 **/
3259 UINT32
3260 EFIAPI
3261 AsmMsrBitFieldWrite32 (
3262 IN UINT32 Index,
3263 IN UINTN StartBit,
3264 IN UINTN EndBit,
3265 IN UINT32 Value
3266 );
3267
3268 /**
3269 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3270 result back to the bit field in the 64-bit MSR.
3271
3272 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3273 between the read result and the value specified by OrData, and writes the
3274 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3275 written to the MSR are returned. Extra left bits in OrData are stripped. The
3276 caller must either guarantee that Index and the data written is valid, or
3277 the caller must set up exception handlers to catch the exceptions. This
3278 function is only available on IA-32 and X64.
3279
3280 If StartBit is greater than 31, then ASSERT().
3281 If EndBit is greater than 31, then ASSERT().
3282 If EndBit is less than or equal to StartBit, then ASSERT().
3283
3284 @param Index The 32-bit MSR index to write.
3285 @param StartBit The ordinal of the least significant bit in the bit field.
3286 Range 0..31.
3287 @param EndBit The ordinal of the most significant bit in the bit field.
3288 Range 0..31.
3289 @param OrData The value to OR with the read value from the MSR.
3290
3291 @return The lower 32-bit of the value written to the MSR.
3292
3293 **/
3294 UINT32
3295 EFIAPI
3296 AsmMsrBitFieldOr32 (
3297 IN UINT32 Index,
3298 IN UINTN StartBit,
3299 IN UINTN EndBit,
3300 IN UINT32 OrData
3301 );
3302
3303 /**
3304 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3305 result back to the bit field in the 64-bit MSR.
3306
3307 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3308 read result and the value specified by AndData, and writes the result to the
3309 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3310 MSR are returned. Extra left bits in AndData are stripped. The caller must
3311 either guarantee that Index and the data written is valid, or the caller must
3312 set up exception handlers to catch the exceptions. This function is only
3313 available on IA-32 and X64.
3314
3315 If StartBit is greater than 31, then ASSERT().
3316 If EndBit is greater than 31, then ASSERT().
3317 If EndBit is less than or equal to StartBit, then ASSERT().
3318
3319 @param Index The 32-bit MSR index to write.
3320 @param StartBit The ordinal of the least significant bit in the bit field.
3321 Range 0..31.
3322 @param EndBit The ordinal of the most significant bit in the bit field.
3323 Range 0..31.
3324 @param AndData The value to AND with the read value from the MSR.
3325
3326 @return The lower 32-bit of the value written to the MSR.
3327
3328 **/
3329 UINT32
3330 EFIAPI
3331 AsmMsrBitFieldAnd32 (
3332 IN UINT32 Index,
3333 IN UINTN StartBit,
3334 IN UINTN EndBit,
3335 IN UINT32 AndData
3336 );
3337
3338 /**
3339 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3340 bitwise inclusive OR, and writes the result back to the bit field in the
3341 64-bit MSR.
3342
3343 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3344 bitwise inclusive OR between the read result and the value specified by
3345 AndData, and writes the result to the 64-bit MSR specified by Index. The
3346 lower 32-bits of the value written to the MSR are returned. Extra left bits
3347 in both AndData and OrData are stripped. The caller must either guarantee
3348 that Index and the data written is valid, or the caller must set up exception
3349 handlers to catch the exceptions. This function is only available on IA-32
3350 and X64.
3351
3352 If StartBit is greater than 31, then ASSERT().
3353 If EndBit is greater than 31, then ASSERT().
3354 If EndBit is less than or equal to StartBit, then ASSERT().
3355
3356 @param Index The 32-bit MSR index to write.
3357 @param StartBit The ordinal of the least significant bit in the bit field.
3358 Range 0..31.
3359 @param EndBit The ordinal of the most significant bit in the bit field.
3360 Range 0..31.
3361 @param AndData The value to AND with the read value from the MSR.
3362 @param OrData The value to OR with the result of the AND operation.
3363
3364 @return The lower 32-bit of the value written to the MSR.
3365
3366 **/
3367 UINT32
3368 EFIAPI
3369 AsmMsrBitFieldAndThenOr32 (
3370 IN UINT32 Index,
3371 IN UINTN StartBit,
3372 IN UINTN EndBit,
3373 IN UINT32 AndData,
3374 IN UINT32 OrData
3375 );
3376
3377 /**
3378 Returns a 64-bit Machine Specific Register(MSR).
3379
3380 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3381 performed on Index, and some Index values may cause CPU exceptions. The
3382 caller must either guarantee that Index is valid, or the caller must set up
3383 exception handlers to catch the exceptions. This function is only available
3384 on IA-32 and X64.
3385
3386 @param Index The 32-bit MSR index to read.
3387
3388 @return The value of the MSR identified by Index.
3389
3390 **/
3391 UINT64
3392 EFIAPI
3393 AsmReadMsr64 (
3394 IN UINT32 Index
3395 );
3396
3397 /**
3398 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3399 value.
3400
3401 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3402 64-bit value written to the MSR is returned. No parameter checking is
3403 performed on Index or Value, and some of these may cause CPU exceptions. The
3404 caller must either guarantee that Index and Value are valid, or the caller
3405 must establish proper exception handlers. This function is only available on
3406 IA-32 and X64.
3407
3408 @param Index The 32-bit MSR index to write.
3409 @param Value The 64-bit value to write to the MSR.
3410
3411 @return Value
3412
3413 **/
3414 UINT64
3415 EFIAPI
3416 AsmWriteMsr64 (
3417 IN UINT32 Index,
3418 IN UINT64 Value
3419 );
3420
3421 /**
3422 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3423 back to the 64-bit MSR.
3424
3425 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3426 between the read result and the value specified by OrData, and writes the
3427 result to the 64-bit MSR specified by Index. The value written to the MSR is
3428 returned. No parameter checking is performed on Index or OrData, and some of
3429 these may cause CPU exceptions. The caller must either guarantee that Index
3430 and OrData are valid, or the caller must establish proper exception handlers.
3431 This function is only available on IA-32 and X64.
3432
3433 @param Index The 32-bit MSR index to write.
3434 @param OrData The value to OR with the read value from the MSR.
3435
3436 @return The value written back to the MSR.
3437
3438 **/
3439 UINT64
3440 EFIAPI
3441 AsmMsrOr64 (
3442 IN UINT32 Index,
3443 IN UINT64 OrData
3444 );
3445
3446 /**
3447 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3448 64-bit MSR.
3449
3450 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3451 read result and the value specified by OrData, and writes the result to the
3452 64-bit MSR specified by Index. The value written to the MSR is returned. No
3453 parameter checking is performed on Index or OrData, and some of these may
3454 cause CPU exceptions. The caller must either guarantee that Index and OrData
3455 are valid, or the caller must establish proper exception handlers. This
3456 function is only available on IA-32 and X64.
3457
3458 @param Index The 32-bit MSR index to write.
3459 @param AndData The value to AND with the read value from the MSR.
3460
3461 @return The value written back to the MSR.
3462
3463 **/
3464 UINT64
3465 EFIAPI
3466 AsmMsrAnd64 (
3467 IN UINT32 Index,
3468 IN UINT64 AndData
3469 );
3470
3471 /**
3472 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3473 OR, and writes the result back to the 64-bit MSR.
3474
3475 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3476 result and the value specified by AndData, performs a bitwise inclusive OR
3477 between the result of the AND operation and the value specified by OrData,
3478 and writes the result to the 64-bit MSR specified by Index. The value written
3479 to the MSR is returned. No parameter checking is performed on Index, AndData,
3480 or OrData, and some of these may cause CPU exceptions. The caller must either
3481 guarantee that Index, AndData, and OrData are valid, or the caller must
3482 establish proper exception handlers. This function is only available on IA-32
3483 and X64.
3484
3485 @param Index The 32-bit MSR index to write.
3486 @param AndData The value to AND with the read value from the MSR.
3487 @param OrData The value to OR with the result of the AND operation.
3488
3489 @return The value written back to the MSR.
3490
3491 **/
3492 UINT64
3493 EFIAPI
3494 AsmMsrAndThenOr64 (
3495 IN UINT32 Index,
3496 IN UINT64 AndData,
3497 IN UINT64 OrData
3498 );
3499
3500 /**
3501 Reads a bit field of an MSR.
3502
3503 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3504 StartBit and the EndBit. The value of the bit field is returned. The caller
3505 must either guarantee that Index is valid, or the caller must set up
3506 exception handlers to catch the exceptions. This function is only available
3507 on IA-32 and X64.
3508
3509 If StartBit is greater than 63, then ASSERT().
3510 If EndBit is greater than 63, then ASSERT().
3511 If EndBit is less than or equal to StartBit, then ASSERT().
3512
3513 @param Index The 32-bit MSR index to read.
3514 @param StartBit The ordinal of the least significant bit in the bit field.
3515 Range 0..63.
3516 @param EndBit The ordinal of the most significant bit in the bit field.
3517 Range 0..63.
3518
3519 @return The value read from the MSR.
3520
3521 **/
3522 UINT64
3523 EFIAPI
3524 AsmMsrBitFieldRead64 (
3525 IN UINT32 Index,
3526 IN UINTN StartBit,
3527 IN UINTN EndBit
3528 );
3529
3530 /**
3531 Writes a bit field to an MSR.
3532
3533 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3534 the StartBit and the EndBit. All other bits in the destination MSR are
3535 preserved. The MSR written is returned. Extra left bits in Value are
3536 stripped. The caller must either guarantee that Index and the data written is
3537 valid, or the caller must set up exception handlers to catch the exceptions.
3538 This function is only available on IA-32 and X64.
3539
3540 If StartBit is greater than 63, then ASSERT().
3541 If EndBit is greater than 63, then ASSERT().
3542 If EndBit is less than or equal to StartBit, then ASSERT().
3543
3544 @param Index The 32-bit MSR index to write.
3545 @param StartBit The ordinal of the least significant bit in the bit field.
3546 Range 0..63.
3547 @param EndBit The ordinal of the most significant bit in the bit field.
3548 Range 0..63.
3549 @param Value New value of the bit field.
3550
3551 @return The value written back to the MSR.
3552
3553 **/
3554 UINT64
3555 EFIAPI
3556 AsmMsrBitFieldWrite64 (
3557 IN UINT32 Index,
3558 IN UINTN StartBit,
3559 IN UINTN EndBit,
3560 IN UINT64 Value
3561 );
3562
3563 /**
3564 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3565 writes the result back to the bit field in the 64-bit MSR.
3566
3567 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3568 between the read result and the value specified by OrData, and writes the
3569 result to the 64-bit MSR specified by Index. The value written to the MSR is
3570 returned. Extra left bits in OrData are stripped. The caller must either
3571 guarantee that Index and the data written is valid, or the caller must set up
3572 exception handlers to catch the exceptions. This function is only available
3573 on IA-32 and X64.
3574
3575 If StartBit is greater than 63, then ASSERT().
3576 If EndBit is greater than 63, then ASSERT().
3577 If EndBit is less than or equal to StartBit, then ASSERT().
3578
3579 @param Index The 32-bit MSR index to write.
3580 @param StartBit The ordinal of the least significant bit in the bit field.
3581 Range 0..63.
3582 @param EndBit The ordinal of the most significant bit in the bit field.
3583 Range 0..63.
3584 @param OrData The value to OR with the read value from the bit field.
3585
3586 @return The value written back to the MSR.
3587
3588 **/
3589 UINT64
3590 EFIAPI
3591 AsmMsrBitFieldOr64 (
3592 IN UINT32 Index,
3593 IN UINTN StartBit,
3594 IN UINTN EndBit,
3595 IN UINT64 OrData
3596 );
3597
3598 /**
3599 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3600 result back to the bit field in the 64-bit MSR.
3601
3602 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3603 read result and the value specified by AndData, and writes the result to the
3604 64-bit MSR specified by Index. The value written to the MSR is returned.
3605 Extra left bits in AndData are stripped. The caller must either guarantee
3606 that Index and the data written is valid, or the caller must set up exception
3607 handlers to catch the exceptions. This function is only available on IA-32
3608 and X64.
3609
3610 If StartBit is greater than 63, then ASSERT().
3611 If EndBit is greater than 63, then ASSERT().
3612 If EndBit is less than or equal to StartBit, then ASSERT().
3613
3614 @param Index The 32-bit MSR index to write.
3615 @param StartBit The ordinal of the least significant bit in the bit field.
3616 Range 0..63.
3617 @param EndBit The ordinal of the most significant bit in the bit field.
3618 Range 0..63.
3619 @param AndData The value to AND with the read value from the bit field.
3620
3621 @return The value written back to the MSR.
3622
3623 **/
3624 UINT64
3625 EFIAPI
3626 AsmMsrBitFieldAnd64 (
3627 IN UINT32 Index,
3628 IN UINTN StartBit,
3629 IN UINTN EndBit,
3630 IN UINT64 AndData
3631 );
3632
3633 /**
3634 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3635 bitwise inclusive OR, and writes the result back to the bit field in the
3636 64-bit MSR.
3637
3638 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3639 a bitwise inclusive OR between the read result and the value specified by
3640 AndData, and writes the result to the 64-bit MSR specified by Index. The
3641 value written to the MSR is returned. Extra left bits in both AndData and
3642 OrData are stripped. The caller must either guarantee that Index and the data
3643 written is valid, or the caller must set up exception handlers to catch the
3644 exceptions. This function is only available on IA-32 and X64.
3645
3646 If StartBit is greater than 63, then ASSERT().
3647 If EndBit is greater than 63, then ASSERT().
3648 If EndBit is less than or equal to StartBit, then ASSERT().
3649
3650 @param Index The 32-bit MSR index to write.
3651 @param StartBit The ordinal of the least significant bit in the bit field.
3652 Range 0..63.
3653 @param EndBit The ordinal of the most significant bit in the bit field.
3654 Range 0..63.
3655 @param AndData The value to AND with the read value from the bit field.
3656 @param OrData The value to OR with the result of the AND operation.
3657
3658 @return The value written back to the MSR.
3659
3660 **/
3661 UINT64
3662 EFIAPI
3663 AsmMsrBitFieldAndThenOr64 (
3664 IN UINT32 Index,
3665 IN UINTN StartBit,
3666 IN UINTN EndBit,
3667 IN UINT64 AndData,
3668 IN UINT64 OrData
3669 );
3670
3671 /**
3672 Reads the current value of the EFLAGS register.
3673
3674 Reads and returns the current value of the EFLAGS register. This function is
3675 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3676 64-bit value on X64.
3677
3678 @return EFLAGS on IA-32 or RFLAGS on X64.
3679
3680 **/
3681 UINTN
3682 EFIAPI
3683 AsmReadEflags (
3684 VOID
3685 );
3686
3687 /**
3688 Reads the current value of the Control Register 0 (CR0).
3689
3690 Reads and returns the current value of CR0. This function is only available
3691 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3692 X64.
3693
3694 @return The value of the Control Register 0 (CR0).
3695
3696 **/
3697 UINTN
3698 EFIAPI
3699 AsmReadCr0 (
3700 VOID
3701 );
3702
3703 /**
3704 Reads the current value of the Control Register 2 (CR2).
3705
3706 Reads and returns the current value of CR2. This function is only available
3707 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3708 X64.
3709
3710 @return The value of the Control Register 2 (CR2).
3711
3712 **/
3713 UINTN
3714 EFIAPI
3715 AsmReadCr2 (
3716 VOID
3717 );
3718
3719 /**
3720 Reads the current value of the Control Register 3 (CR3).
3721
3722 Reads and returns the current value of CR3. This function is only available
3723 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3724 X64.
3725
3726 @return The value of the Control Register 3 (CR3).
3727
3728 **/
3729 UINTN
3730 EFIAPI
3731 AsmReadCr3 (
3732 VOID
3733 );
3734
3735 /**
3736 Reads the current value of the Control Register 4 (CR4).
3737
3738 Reads and returns the current value of CR4. This function is only available
3739 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3740 X64.
3741
3742 @return The value of the Control Register 4 (CR4).
3743
3744 **/
3745 UINTN
3746 EFIAPI
3747 AsmReadCr4 (
3748 VOID
3749 );
3750
3751 /**
3752 Writes a value to Control Register 0 (CR0).
3753
3754 Writes and returns a new value to CR0. This function is only available on
3755 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3756
3757 @param Cr0 The value to write to CR0.
3758
3759 @return The value written to CR0.
3760
3761 **/
3762 UINTN
3763 EFIAPI
3764 AsmWriteCr0 (
3765 UINTN Cr0
3766 );
3767
3768 /**
3769 Writes a value to Control Register 2 (CR2).
3770
3771 Writes and returns a new value to CR2. This function is only available on
3772 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3773
3774 @param Cr2 The value to write to CR2.
3775
3776 @return The value written to CR2.
3777
3778 **/
3779 UINTN
3780 EFIAPI
3781 AsmWriteCr2 (
3782 UINTN Cr2
3783 );
3784
3785 /**
3786 Writes a value to Control Register 3 (CR3).
3787
3788 Writes and returns a new value to CR3. This function is only available on
3789 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3790
3791 @param Cr3 The value to write to CR3.
3792
3793 @return The value written to CR3.
3794
3795 **/
3796 UINTN
3797 EFIAPI
3798 AsmWriteCr3 (
3799 UINTN Cr3
3800 );
3801
3802 /**
3803 Writes a value to Control Register 4 (CR4).
3804
3805 Writes and returns a new value to CR4. This function is only available on
3806 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3807
3808 @param Cr4 The value to write to CR4.
3809
3810 @return The value written to CR4.
3811
3812 **/
3813 UINTN
3814 EFIAPI
3815 AsmWriteCr4 (
3816 UINTN Cr4
3817 );
3818
3819 /**
3820 Reads the current value of Debug Register 0 (DR0).
3821
3822 Reads and returns the current value of DR0. This function is only available
3823 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3824 X64.
3825
3826 @return The value of Debug Register 0 (DR0).
3827
3828 **/
3829 UINTN
3830 EFIAPI
3831 AsmReadDr0 (
3832 VOID
3833 );
3834
3835 /**
3836 Reads the current value of Debug Register 1 (DR1).
3837
3838 Reads and returns the current value of DR1. This function is only available
3839 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3840 X64.
3841
3842 @return The value of Debug Register 1 (DR1).
3843
3844 **/
3845 UINTN
3846 EFIAPI
3847 AsmReadDr1 (
3848 VOID
3849 );
3850
3851 /**
3852 Reads the current value of Debug Register 2 (DR2).
3853
3854 Reads and returns the current value of DR2. This function is only available
3855 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3856 X64.
3857
3858 @return The value of Debug Register 2 (DR2).
3859
3860 **/
3861 UINTN
3862 EFIAPI
3863 AsmReadDr2 (
3864 VOID
3865 );
3866
3867 /**
3868 Reads the current value of Debug Register 3 (DR3).
3869
3870 Reads and returns the current value of DR3. This function is only available
3871 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3872 X64.
3873
3874 @return The value of Debug Register 3 (DR3).
3875
3876 **/
3877 UINTN
3878 EFIAPI
3879 AsmReadDr3 (
3880 VOID
3881 );
3882
3883 /**
3884 Reads the current value of Debug Register 4 (DR4).
3885
3886 Reads and returns the current value of DR4. This function is only available
3887 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3888 X64.
3889
3890 @return The value of Debug Register 4 (DR4).
3891
3892 **/
3893 UINTN
3894 EFIAPI
3895 AsmReadDr4 (
3896 VOID
3897 );
3898
3899 /**
3900 Reads the current value of Debug Register 5 (DR5).
3901
3902 Reads and returns the current value of DR5. This function is only available
3903 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3904 X64.
3905
3906 @return The value of Debug Register 5 (DR5).
3907
3908 **/
3909 UINTN
3910 EFIAPI
3911 AsmReadDr5 (
3912 VOID
3913 );
3914
3915 /**
3916 Reads the current value of Debug Register 6 (DR6).
3917
3918 Reads and returns the current value of DR6. This function is only available
3919 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3920 X64.
3921
3922 @return The value of Debug Register 6 (DR6).
3923
3924 **/
3925 UINTN
3926 EFIAPI
3927 AsmReadDr6 (
3928 VOID
3929 );
3930
3931 /**
3932 Reads the current value of Debug Register 7 (DR7).
3933
3934 Reads and returns the current value of DR7. This function is only available
3935 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3936 X64.
3937
3938 @return The value of Debug Register 7 (DR7).
3939
3940 **/
3941 UINTN
3942 EFIAPI
3943 AsmReadDr7 (
3944 VOID
3945 );
3946
3947 /**
3948 Writes a value to Debug Register 0 (DR0).
3949
3950 Writes and returns a new value to DR0. This function is only available on
3951 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3952
3953 @param Dr0 The value to write to Dr0.
3954
3955 @return The value written to Debug Register 0 (DR0).
3956
3957 **/
3958 UINTN
3959 EFIAPI
3960 AsmWriteDr0 (
3961 UINTN Dr0
3962 );
3963
3964 /**
3965 Writes a value to Debug Register 1 (DR1).
3966
3967 Writes and returns a new value to DR1. This function is only available on
3968 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3969
3970 @param Dr1 The value to write to Dr1.
3971
3972 @return The value written to Debug Register 1 (DR1).
3973
3974 **/
3975 UINTN
3976 EFIAPI
3977 AsmWriteDr1 (
3978 UINTN Dr1
3979 );
3980
3981 /**
3982 Writes a value to Debug Register 2 (DR2).
3983
3984 Writes and returns a new value to DR2. This function is only available on
3985 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3986
3987 @param Dr2 The value to write to Dr2.
3988
3989 @return The value written to Debug Register 2 (DR2).
3990
3991 **/
3992 UINTN
3993 EFIAPI
3994 AsmWriteDr2 (
3995 UINTN Dr2
3996 );
3997
3998 /**
3999 Writes a value to Debug Register 3 (DR3).
4000
4001 Writes and returns a new value to DR3. This function is only available on
4002 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4003
4004 @param Dr3 The value to write to Dr3.
4005
4006 @return The value written to Debug Register 3 (DR3).
4007
4008 **/
4009 UINTN
4010 EFIAPI
4011 AsmWriteDr3 (
4012 UINTN Dr3
4013 );
4014
4015 /**
4016 Writes a value to Debug Register 4 (DR4).
4017
4018 Writes and returns a new value to DR4. This function is only available on
4019 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4020
4021 @param Dr4 The value to write to Dr4.
4022
4023 @return The value written to Debug Register 4 (DR4).
4024
4025 **/
4026 UINTN
4027 EFIAPI
4028 AsmWriteDr4 (
4029 UINTN Dr4
4030 );
4031
4032 /**
4033 Writes a value to Debug Register 5 (DR5).
4034
4035 Writes and returns a new value to DR5. This function is only available on
4036 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4037
4038 @param Dr5 The value to write to Dr5.
4039
4040 @return The value written to Debug Register 5 (DR5).
4041
4042 **/
4043 UINTN
4044 EFIAPI
4045 AsmWriteDr5 (
4046 UINTN Dr5
4047 );
4048
4049 /**
4050 Writes a value to Debug Register 6 (DR6).
4051
4052 Writes and returns a new value to DR6. This function is only available on
4053 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4054
4055 @param Dr6 The value to write to Dr6.
4056
4057 @return The value written to Debug Register 6 (DR6).
4058
4059 **/
4060 UINTN
4061 EFIAPI
4062 AsmWriteDr6 (
4063 UINTN Dr6
4064 );
4065
4066 /**
4067 Writes a value to Debug Register 7 (DR7).
4068
4069 Writes and returns a new value to DR7. This function is only available on
4070 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4071
4072 @param Dr7 The value to write to Dr7.
4073
4074 @return The value written to Debug Register 7 (DR7).
4075
4076 **/
4077 UINTN
4078 EFIAPI
4079 AsmWriteDr7 (
4080 UINTN Dr7
4081 );
4082
4083 /**
4084 Reads the current value of Code Segment Register (CS).
4085
4086 Reads and returns the current value of CS. This function is only available on
4087 IA-32 and X64.
4088
4089 @return The current value of CS.
4090
4091 **/
4092 UINT16
4093 EFIAPI
4094 AsmReadCs (
4095 VOID
4096 );
4097
4098 /**
4099 Reads the current value of Data Segment Register (DS).
4100
4101 Reads and returns the current value of DS. This function is only available on
4102 IA-32 and X64.
4103
4104 @return The current value of DS.
4105
4106 **/
4107 UINT16
4108 EFIAPI
4109 AsmReadDs (
4110 VOID
4111 );
4112
4113 /**
4114 Reads the current value of Extra Segment Register (ES).
4115
4116 Reads and returns the current value of ES. This function is only available on
4117 IA-32 and X64.
4118
4119 @return The current value of ES.
4120
4121 **/
4122 UINT16
4123 EFIAPI
4124 AsmReadEs (
4125 VOID
4126 );
4127
4128 /**
4129 Reads the current value of FS Data Segment Register (FS).
4130
4131 Reads and returns the current value of FS. This function is only available on
4132 IA-32 and X64.
4133
4134 @return The current value of FS.
4135
4136 **/
4137 UINT16
4138 EFIAPI
4139 AsmReadFs (
4140 VOID
4141 );
4142
4143 /**
4144 Reads the current value of GS Data Segment Register (GS).
4145
4146 Reads and returns the current value of GS. This function is only available on
4147 IA-32 and X64.
4148
4149 @return The current value of GS.
4150
4151 **/
4152 UINT16
4153 EFIAPI
4154 AsmReadGs (
4155 VOID
4156 );
4157
4158 /**
4159 Reads the current value of Stack Segment Register (SS).
4160
4161 Reads and returns the current value of SS. This function is only available on
4162 IA-32 and X64.
4163
4164 @return The current value of SS.
4165
4166 **/
4167 UINT16
4168 EFIAPI
4169 AsmReadSs (
4170 VOID
4171 );
4172
4173 /**
4174 Reads the current value of Task Register (TR).
4175
4176 Reads and returns the current value of TR. This function is only available on
4177 IA-32 and X64.
4178
4179 @return The current value of TR.
4180
4181 **/
4182 UINT16
4183 EFIAPI
4184 AsmReadTr (
4185 VOID
4186 );
4187
4188 /**
4189 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4190
4191 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4192 function is only available on IA-32 and X64.
4193
4194 If Gdtr is NULL, then ASSERT().
4195
4196 @param Gdtr Pointer to a GDTR descriptor.
4197
4198 **/
4199 VOID
4200 EFIAPI
4201 AsmReadGdtr (
4202 OUT IA32_DESCRIPTOR *Gdtr
4203 );
4204
4205 /**
4206 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4207
4208 Writes and the current GDTR descriptor specified by Gdtr. This function is
4209 only available on IA-32 and X64.
4210
4211 If Gdtr is NULL, then ASSERT().
4212
4213 @param Gdtr Pointer to a GDTR descriptor.
4214
4215 **/
4216 VOID
4217 EFIAPI
4218 AsmWriteGdtr (
4219 IN CONST IA32_DESCRIPTOR *Gdtr
4220 );
4221
4222 /**
4223 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4224
4225 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4226 function is only available on IA-32 and X64.
4227
4228 If Idtr is NULL, then ASSERT().
4229
4230 @param Idtr Pointer to a IDTR descriptor.
4231
4232 **/
4233 VOID
4234 EFIAPI
4235 AsmReadIdtr (
4236 OUT IA32_DESCRIPTOR *Idtr
4237 );
4238
4239 /**
4240 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4241
4242 Writes the current IDTR descriptor and returns it in Idtr. This function is
4243 only available on IA-32 and X64.
4244
4245 If Idtr is NULL, then ASSERT().
4246
4247 @param Idtr Pointer to a IDTR descriptor.
4248
4249 **/
4250 VOID
4251 EFIAPI
4252 AsmWriteIdtr (
4253 IN CONST IA32_DESCRIPTOR *Idtr
4254 );
4255
4256 /**
4257 Reads the current Local Descriptor Table Register(LDTR) selector.
4258
4259 Reads and returns the current 16-bit LDTR descriptor value. This function is
4260 only available on IA-32 and X64.
4261
4262 @return The current selector of LDT.
4263
4264 **/
4265 UINT16
4266 EFIAPI
4267 AsmReadLdtr (
4268 VOID
4269 );
4270
4271 /**
4272 Writes the current Local Descriptor Table Register (GDTR) selector.
4273
4274 Writes and the current LDTR descriptor specified by Ldtr. This function is
4275 only available on IA-32 and X64.
4276
4277 @param Ldtr 16-bit LDTR selector value.
4278
4279 **/
4280 VOID
4281 EFIAPI
4282 AsmWriteLdtr (
4283 IN UINT16 Ldtr
4284 );
4285
4286 /**
4287 Save the current floating point/SSE/SSE2 context to a buffer.
4288
4289 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4290 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4291 available on IA-32 and X64.
4292
4293 If Buffer is NULL, then ASSERT().
4294 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4295
4296 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4297
4298 **/
4299 VOID
4300 EFIAPI
4301 AsmFxSave (
4302 OUT IA32_FX_BUFFER *Buffer
4303 );
4304
4305 /**
4306 Restores the current floating point/SSE/SSE2 context from a buffer.
4307
4308 Restores the current floating point/SSE/SSE2 state from the buffer specified
4309 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4310 only available on IA-32 and X64.
4311
4312 If Buffer is NULL, then ASSERT().
4313 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4314 If Buffer was not saved with AsmFxSave(), then ASSERT().
4315
4316 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4317
4318 **/
4319 VOID
4320 EFIAPI
4321 AsmFxRestore (
4322 IN CONST IA32_FX_BUFFER *Buffer
4323 );
4324
4325 /**
4326 Reads the current value of 64-bit MMX Register #0 (MM0).
4327
4328 Reads and returns the current value of MM0. This function is only available
4329 on IA-32 and X64.
4330
4331 @return The current value of MM0.
4332
4333 **/
4334 UINT64
4335 EFIAPI
4336 AsmReadMm0 (
4337 VOID
4338 );
4339
4340 /**
4341 Reads the current value of 64-bit MMX Register #1 (MM1).
4342
4343 Reads and returns the current value of MM1. This function is only available
4344 on IA-32 and X64.
4345
4346 @return The current value of MM1.
4347
4348 **/
4349 UINT64
4350 EFIAPI
4351 AsmReadMm1 (
4352 VOID
4353 );
4354
4355 /**
4356 Reads the current value of 64-bit MMX Register #2 (MM2).
4357
4358 Reads and returns the current value of MM2. This function is only available
4359 on IA-32 and X64.
4360
4361 @return The current value of MM2.
4362
4363 **/
4364 UINT64
4365 EFIAPI
4366 AsmReadMm2 (
4367 VOID
4368 );
4369
4370 /**
4371 Reads the current value of 64-bit MMX Register #3 (MM3).
4372
4373 Reads and returns the current value of MM3. This function is only available
4374 on IA-32 and X64.
4375
4376 @return The current value of MM3.
4377
4378 **/
4379 UINT64
4380 EFIAPI
4381 AsmReadMm3 (
4382 VOID
4383 );
4384
4385 /**
4386 Reads the current value of 64-bit MMX Register #4 (MM4).
4387
4388 Reads and returns the current value of MM4. This function is only available
4389 on IA-32 and X64.
4390
4391 @return The current value of MM4.
4392
4393 **/
4394 UINT64
4395 EFIAPI
4396 AsmReadMm4 (
4397 VOID
4398 );
4399
4400 /**
4401 Reads the current value of 64-bit MMX Register #5 (MM5).
4402
4403 Reads and returns the current value of MM5. This function is only available
4404 on IA-32 and X64.
4405
4406 @return The current value of MM5.
4407
4408 **/
4409 UINT64
4410 EFIAPI
4411 AsmReadMm5 (
4412 VOID
4413 );
4414
4415 /**
4416 Reads the current value of 64-bit MMX Register #6 (MM6).
4417
4418 Reads and returns the current value of MM6. This function is only available
4419 on IA-32 and X64.
4420
4421 @return The current value of MM6.
4422
4423 **/
4424 UINT64
4425 EFIAPI
4426 AsmReadMm6 (
4427 VOID
4428 );
4429
4430 /**
4431 Reads the current value of 64-bit MMX Register #7 (MM7).
4432
4433 Reads and returns the current value of MM7. This function is only available
4434 on IA-32 and X64.
4435
4436 @return The current value of MM7.
4437
4438 **/
4439 UINT64
4440 EFIAPI
4441 AsmReadMm7 (
4442 VOID
4443 );
4444
4445 /**
4446 Writes the current value of 64-bit MMX Register #0 (MM0).
4447
4448 Writes the current value of MM0. This function is only available on IA32 and
4449 X64.
4450
4451 @param Value The 64-bit value to write to MM0.
4452
4453 **/
4454 VOID
4455 EFIAPI
4456 AsmWriteMm0 (
4457 IN UINT64 Value
4458 );
4459
4460 /**
4461 Writes the current value of 64-bit MMX Register #1 (MM1).
4462
4463 Writes the current value of MM1. This function is only available on IA32 and
4464 X64.
4465
4466 @param Value The 64-bit value to write to MM1.
4467
4468 **/
4469 VOID
4470 EFIAPI
4471 AsmWriteMm1 (
4472 IN UINT64 Value
4473 );
4474
4475 /**
4476 Writes the current value of 64-bit MMX Register #2 (MM2).
4477
4478 Writes the current value of MM2. This function is only available on IA32 and
4479 X64.
4480
4481 @param Value The 64-bit value to write to MM2.
4482
4483 **/
4484 VOID
4485 EFIAPI
4486 AsmWriteMm2 (
4487 IN UINT64 Value
4488 );
4489
4490 /**
4491 Writes the current value of 64-bit MMX Register #3 (MM3).
4492
4493 Writes the current value of MM3. This function is only available on IA32 and
4494 X64.
4495
4496 @param Value The 64-bit value to write to MM3.
4497
4498 **/
4499 VOID
4500 EFIAPI
4501 AsmWriteMm3 (
4502 IN UINT64 Value
4503 );
4504
4505 /**
4506 Writes the current value of 64-bit MMX Register #4 (MM4).
4507
4508 Writes the current value of MM4. This function is only available on IA32 and
4509 X64.
4510
4511 @param Value The 64-bit value to write to MM4.
4512
4513 **/
4514 VOID
4515 EFIAPI
4516 AsmWriteMm4 (
4517 IN UINT64 Value
4518 );
4519
4520 /**
4521 Writes the current value of 64-bit MMX Register #5 (MM5).
4522
4523 Writes the current value of MM5. This function is only available on IA32 and
4524 X64.
4525
4526 @param Value The 64-bit value to write to MM5.
4527
4528 **/
4529 VOID
4530 EFIAPI
4531 AsmWriteMm5 (
4532 IN UINT64 Value
4533 );
4534
4535 /**
4536 Writes the current value of 64-bit MMX Register #6 (MM6).
4537
4538 Writes the current value of MM6. This function is only available on IA32 and
4539 X64.
4540
4541 @param Value The 64-bit value to write to MM6.
4542
4543 **/
4544 VOID
4545 EFIAPI
4546 AsmWriteMm6 (
4547 IN UINT64 Value
4548 );
4549
4550 /**
4551 Writes the current value of 64-bit MMX Register #7 (MM7).
4552
4553 Writes the current value of MM7. This function is only available on IA32 and
4554 X64.
4555
4556 @param Value The 64-bit value to write to MM7.
4557
4558 **/
4559 VOID
4560 EFIAPI
4561 AsmWriteMm7 (
4562 IN UINT64 Value
4563 );
4564
4565 /**
4566 Reads the current value of Time Stamp Counter (TSC).
4567
4568 Reads and returns the current value of TSC. This function is only available
4569 on IA-32 and X64.
4570
4571 @return The current value of TSC
4572
4573 **/
4574 UINT64
4575 EFIAPI
4576 AsmReadTsc (
4577 VOID
4578 );
4579
4580 /**
4581 Reads the current value of a Performance Counter (PMC).
4582
4583 Reads and returns the current value of performance counter specified by
4584 Index. This function is only available on IA-32 and X64.
4585
4586 @param Index The 32-bit Performance Counter index to read.
4587
4588 @return The value of the PMC specified by Index.
4589
4590 **/
4591 UINT64
4592 EFIAPI
4593 AsmReadPmc (
4594 IN UINT32 Index
4595 );
4596
4597 /**
4598 Sets up a monitor buffer that is used by AsmMwait().
4599
4600 Executes a MONITOR instruction with the register state specified by Eax, Ecx
4601 and Edx. Returns Eax. This function is only available on IA-32 and X64.
4602
4603 @param Eax The value to load into EAX or RAX before executing the MONITOR
4604 instruction.
4605 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4606 instruction.
4607 @param Edx The value to load into EDX or RDX before executing the MONITOR
4608 instruction.
4609
4610 @return Eax
4611
4612 **/
4613 UINTN
4614 EFIAPI
4615 AsmMonitor (
4616 IN UINTN Eax,
4617 IN UINTN Ecx,
4618 IN UINTN Edx
4619 );
4620
4621 /**
4622 Executes an MWAIT instruction.
4623
4624 Executes an MWAIT instruction with the register state specified by Eax and
4625 Ecx. Returns Eax. This function is only available on IA-32 and X64.
4626
4627 @param Eax The value to load into EAX or RAX before executing the MONITOR
4628 instruction.
4629 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4630 instruction.
4631
4632 @return Eax
4633
4634 **/
4635 UINTN
4636 EFIAPI
4637 AsmMwait (
4638 IN UINTN Eax,
4639 IN UINTN Ecx
4640 );
4641
4642 /**
4643 Executes a WBINVD instruction.
4644
4645 Executes a WBINVD instruction. This function is only available on IA-32 and
4646 X64.
4647
4648 **/
4649 VOID
4650 EFIAPI
4651 AsmWbinvd (
4652 VOID
4653 );
4654
4655 /**
4656 Executes a INVD instruction.
4657
4658 Executes a INVD instruction. This function is only available on IA-32 and
4659 X64.
4660
4661 **/
4662 VOID
4663 EFIAPI
4664 AsmInvd (
4665 VOID
4666 );
4667
4668 /**
4669 Flushes a cache line from all the instruction and data caches within the
4670 coherency domain of the CPU.
4671
4672 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
4673 This function is only available on IA-32 and X64.
4674
4675 @param LinearAddress The address of the cache line to flush. If the CPU is
4676 in a physical addressing mode, then LinearAddress is a
4677 physical address. If the CPU is in a virtual
4678 addressing mode, then LinearAddress is a virtual
4679 address.
4680
4681 @return LinearAddress
4682 **/
4683 VOID *
4684 EFIAPI
4685 AsmFlushCacheLine (
4686 IN VOID *LinearAddress
4687 );
4688
4689 /**
4690 Enables the 32-bit paging mode on the CPU.
4691
4692 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4693 must be properly initialized prior to calling this service. This function
4694 assumes the current execution mode is 32-bit protected mode. This function is
4695 only available on IA-32. After the 32-bit paging mode is enabled, control is
4696 transferred to the function specified by EntryPoint using the new stack
4697 specified by NewStack and passing in the parameters specified by Context1 and
4698 Context2. Context1 and Context2 are optional and may be NULL. The function
4699 EntryPoint must never return.
4700
4701 If the current execution mode is not 32-bit protected mode, then ASSERT().
4702 If EntryPoint is NULL, then ASSERT().
4703 If NewStack is NULL, then ASSERT().
4704
4705 There are a number of constraints that must be followed before calling this
4706 function:
4707 1) Interrupts must be disabled.
4708 2) The caller must be in 32-bit protected mode with flat descriptors. This
4709 means all descriptors must have a base of 0 and a limit of 4GB.
4710 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
4711 descriptors.
4712 4) CR3 must point to valid page tables that will be used once the transition
4713 is complete, and those page tables must guarantee that the pages for this
4714 function and the stack are identity mapped.
4715
4716 @param EntryPoint A pointer to function to call with the new stack after
4717 paging is enabled.
4718 @param Context1 A pointer to the context to pass into the EntryPoint
4719 function as the first parameter after paging is enabled.
4720 @param Context2 A pointer to the context to pass into the EntryPoint
4721 function as the second parameter after paging is enabled.
4722 @param NewStack A pointer to the new stack to use for the EntryPoint
4723 function after paging is enabled.
4724
4725 **/
4726 VOID
4727 EFIAPI
4728 AsmEnablePaging32 (
4729 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
4730 IN VOID *Context1, OPTIONAL
4731 IN VOID *Context2, OPTIONAL
4732 IN VOID *NewStack
4733 );
4734
4735 /**
4736 Disables the 32-bit paging mode on the CPU.
4737
4738 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
4739 mode. This function assumes the current execution mode is 32-paged protected
4740 mode. This function is only available on IA-32. After the 32-bit paging mode
4741 is disabled, control is transferred to the function specified by EntryPoint
4742 using the new stack specified by NewStack and passing in the parameters
4743 specified by Context1 and Context2. Context1 and Context2 are optional and
4744 may be NULL. The function EntryPoint must never return.
4745
4746 If the current execution mode is not 32-bit paged mode, then ASSERT().
4747 If EntryPoint is NULL, then ASSERT().
4748 If NewStack is NULL, then ASSERT().
4749
4750 There are a number of constraints that must be followed before calling this
4751 function:
4752 1) Interrupts must be disabled.
4753 2) The caller must be in 32-bit paged mode.
4754 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
4755 4) CR3 must point to valid page tables that guarantee that the pages for
4756 this function and the stack are identity mapped.
4757
4758 @param EntryPoint A pointer to function to call with the new stack after
4759 paging is disabled.
4760 @param Context1 A pointer to the context to pass into the EntryPoint
4761 function as the first parameter after paging is disabled.
4762 @param Context2 A pointer to the context to pass into the EntryPoint
4763 function as the second parameter after paging is
4764 disabled.
4765 @param NewStack A pointer to the new stack to use for the EntryPoint
4766 function after paging is disabled.
4767
4768 **/
4769 VOID
4770 EFIAPI
4771 AsmDisablePaging32 (
4772 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
4773 IN VOID *Context1, OPTIONAL
4774 IN VOID *Context2, OPTIONAL
4775 IN VOID *NewStack
4776 );
4777
4778 /**
4779 Enables the 64-bit paging mode on the CPU.
4780
4781 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4782 must be properly initialized prior to calling this service. This function
4783 assumes the current execution mode is 32-bit protected mode with flat
4784 descriptors. This function is only available on IA-32. After the 64-bit
4785 paging mode is enabled, control is transferred to the function specified by
4786 EntryPoint using the new stack specified by NewStack and passing in the
4787 parameters specified by Context1 and Context2. Context1 and Context2 are
4788 optional and may be 0. The function EntryPoint must never return.
4789
4790 If the current execution mode is not 32-bit protected mode with flat
4791 descriptors, then ASSERT().
4792 If EntryPoint is 0, then ASSERT().
4793 If NewStack is 0, then ASSERT().
4794
4795 @param Cs The 16-bit selector to load in the CS before EntryPoint
4796 is called. The descriptor in the GDT that this selector
4797 references must be setup for long mode.
4798 @param EntryPoint The 64-bit virtual address of the function to call with
4799 the new stack after paging is enabled.
4800 @param Context1 The 64-bit virtual address of the context to pass into
4801 the EntryPoint function as the first parameter after
4802 paging is enabled.
4803 @param Context2 The 64-bit virtual address of the context to pass into
4804 the EntryPoint function as the second parameter after
4805 paging is enabled.
4806 @param NewStack The 64-bit virtual address of the new stack to use for
4807 the EntryPoint function after paging is enabled.
4808
4809 **/
4810 VOID
4811 EFIAPI
4812 AsmEnablePaging64 (
4813 IN UINT16 CodeSelector,
4814 IN UINT64 EntryPoint,
4815 IN UINT64 Context1, OPTIONAL
4816 IN UINT64 Context2, OPTIONAL
4817 IN UINT64 NewStack
4818 );
4819
4820 /**
4821 Disables the 64-bit paging mode on the CPU.
4822
4823 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
4824 mode. This function assumes the current execution mode is 64-paging mode.
4825 This function is only available on X64. After the 64-bit paging mode is
4826 disabled, control is transferred to the function specified by EntryPoint
4827 using the new stack specified by NewStack and passing in the parameters
4828 specified by Context1 and Context2. Context1 and Context2 are optional and
4829 may be 0. The function EntryPoint must never return.
4830
4831 If the current execution mode is not 64-bit paged mode, then ASSERT().
4832 If EntryPoint is 0, then ASSERT().
4833 If NewStack is 0, then ASSERT().
4834
4835 @param Cs The 16-bit selector to load in the CS before EntryPoint
4836 is called. The descriptor in the GDT that this selector
4837 references must be setup for 32-bit protected mode.
4838 @param EntryPoint The 64-bit virtual address of the function to call with
4839 the new stack after paging is disabled.
4840 @param Context1 The 64-bit virtual address of the context to pass into
4841 the EntryPoint function as the first parameter after
4842 paging is disabled.
4843 @param Context2 The 64-bit virtual address of the context to pass into
4844 the EntryPoint function as the second parameter after
4845 paging is disabled.
4846 @param NewStack The 64-bit virtual address of the new stack to use for
4847 the EntryPoint function after paging is disabled.
4848
4849 **/
4850 VOID
4851 EFIAPI
4852 AsmDisablePaging64 (
4853 IN UINT16 CodeSelector,
4854 IN UINT32 EntryPoint,
4855 IN UINT32 Context1, OPTIONAL
4856 IN UINT32 Context2, OPTIONAL
4857 IN UINT32 NewStack
4858 );
4859
4860 //
4861 // 16-bit thunking services
4862 //
4863
4864 /**
4865 Retrieves the properties for 16-bit thunk functions.
4866
4867 Computes the size of the buffer and stack below 1MB required to use the
4868 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
4869 buffer size is returned in RealModeBufferSize, and the stack size is returned
4870 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
4871 then the actual minimum stack size is ExtraStackSize plus the maximum number
4872 of bytes that need to be passed to the 16-bit real mode code.
4873
4874 If RealModeBufferSize is NULL, then ASSERT().
4875 If ExtraStackSize is NULL, then ASSERT().
4876
4877 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
4878 required to use the 16-bit thunk functions.
4879 @param ExtraStackSize A pointer to the extra size of stack below 1MB
4880 that the 16-bit thunk functions require for
4881 temporary storage in the transition to and from
4882 16-bit real mode.
4883
4884 **/
4885 VOID
4886 EFIAPI
4887 AsmGetThunk16Properties (
4888 OUT UINT32 *RealModeBufferSize,
4889 OUT UINT32 *ExtraStackSize
4890 );
4891
4892 /**
4893 Prepares all structures a code required to use AsmThunk16().
4894
4895 Prepares all structures and code required to use AsmThunk16().
4896
4897 If ThunkContext is NULL, then ASSERT().
4898
4899 @param ThunkContext A pointer to the context structure that describes the
4900 16-bit real mode code to call.
4901
4902 **/
4903 VOID
4904 EFIAPI
4905 AsmPrepareThunk16 (
4906 OUT THUNK_CONTEXT *ThunkContext
4907 );
4908
4909 /**
4910 Transfers control to a 16-bit real mode entry point and returns the results.
4911
4912 Transfers control to a 16-bit real mode entry point and returns the results.
4913 AsmPrepareThunk16() must be called with ThunkContext before this function is
4914 used.
4915
4916 If ThunkContext is NULL, then ASSERT().
4917 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
4918
4919 @param ThunkContext A pointer to the context structure that describes the
4920 16-bit real mode code to call.
4921
4922 **/
4923 VOID
4924 EFIAPI
4925 AsmThunk16 (
4926 IN OUT THUNK_CONTEXT *ThunkContext
4927 );
4928
4929 /**
4930 Prepares all structures and code for a 16-bit real mode thunk, transfers
4931 control to a 16-bit real mode entry point, and returns the results.
4932
4933 Prepares all structures and code for a 16-bit real mode thunk, transfers
4934 control to a 16-bit real mode entry point, and returns the results. If the
4935 caller only need to perform a single 16-bit real mode thunk, then this
4936 service should be used. If the caller intends to make more than one 16-bit
4937 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
4938 once and AsmThunk16() can be called for each 16-bit real mode thunk.
4939
4940 If ThunkContext is NULL, then ASSERT().
4941
4942 @param ThunkContext A pointer to the context structure that describes the
4943 16-bit real mode code to call.
4944
4945 **/
4946 VOID
4947 EFIAPI
4948 AsmPrepareAndThunk16 (
4949 IN OUT THUNK_CONTEXT *ThunkContext
4950 );
4951
4952 #endif