2 Memory-only library functions with no library constructor/destructor
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
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.
13 Module Name: BaseLib.h
21 // Definitions for architecture specific types
22 // These include SPIN_LOCK and BASE_LIBRARY_JUMP_BUFFER
28 typedef UINTN SPIN_LOCK
;
30 #if defined (MDE_CPU_IA32)
32 // IA32 context buffer used by SetJump() and LongJump()
41 } BASE_LIBRARY_JUMP_BUFFER
;
43 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
45 #elif defined (MDE_CPU_IPF)
47 // IPF context buffer used by SetJump() and LongJump()
82 UINT64 AfterSpillUNAT
;
88 } BASE_LIBRARY_JUMP_BUFFER
;
90 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10
92 #elif defined (MDE_CPU_X64)
94 // X64 context buffer used by SetJump() and LongJump()
107 } BASE_LIBRARY_JUMP_BUFFER
;
109 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
111 #elif defined (MDE_CPU_EBC)
113 // EBC context buffer used by SetJump() and LongJump()
121 } BASE_LIBRARY_JUMP_BUFFER
;
123 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
126 #error Unknown Processor Type
134 Copies one Null-terminated Unicode string to another Null-terminated Unicode
135 string and returns the new Unicode string.
137 This function copies the contents of the Unicode string Source to the Unicode
138 string Destination, and returns Destination. If Source and Destination
139 overlap, then the results are undefined.
141 If Destination is NULL, then ASSERT().
142 If Source is NULL, then ASSERT().
143 If Source and Destination overlap, then ASSERT().
144 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
145 PcdMaximumUnicodeStringLength Unicode characters not including the
146 Null-terminator, then ASSERT().
148 @param Destination Pointer to a Null-terminated Unicode string.
149 @param Source Pointer to a Null-terminated Unicode string.
157 OUT CHAR16
*Destination
,
158 IN CONST CHAR16
*Source
161 Copies one Null-terminated Unicode string with a maximum length to another
162 Null-terminated Unicode string with a maximum length and returns the new
165 This function copies the contents of the Unicode string Source to the Unicode
166 string Destination, and returns Destination. At most, Length Unicode
167 characters are copied from Source to Destination. If Length is 0, then
168 Destination is returned unmodified. If Length is greater that the number of
169 Unicode characters in Source, then Destination is padded with Null Unicode
170 characters. If Source and Destination overlap, then the results are
173 If Destination is NULL, then ASSERT().
174 If Source is NULL, then ASSERT().
175 If Source and Destination overlap, then ASSERT().
176 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
177 PcdMaximumUnicodeStringLength Unicode characters not including the
178 Null-terminator, then ASSERT().
180 @param Destination Pointer to a Null-terminated Unicode string.
181 @param Source Pointer to a Null-terminated Unicode string.
182 @param Length Maximum number of Unicode characters to copy.
190 OUT CHAR16
*Destination
,
191 IN CONST CHAR16
*Source
,
195 Returns the length of a Null-terminated Unicode string.
197 This function returns the number of Unicode characters in the Null-terminated
198 Unicode string specified by String.
200 If String is NULL, then ASSERT().
201 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
202 PcdMaximumUnicodeStringLength Unicode characters not including the
203 Null-terminator, then ASSERT().
205 @param String Pointer to a Null-terminated Unicode string.
207 @return The length of String.
213 IN CONST CHAR16
*String
216 Returns the size of a Null-terminated Unicode string in bytes, including the
219 This function returns the size, in bytes, of the Null-terminated Unicode
220 string specified by String.
222 If String is NULL, then ASSERT().
223 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
224 PcdMaximumUnicodeStringLength Unicode characters not including the
225 Null-terminator, then ASSERT().
227 @param String Pointer to a Null-terminated Unicode string.
229 @return The size of String.
235 IN CONST CHAR16
*String
238 Compares two Null-terminated Unicode strings, and returns the difference
239 between the first mismatched Unicode characters.
241 This function compares the Null-terminated Unicode string FirstString to the
242 Null-terminated Unicode string SecondString. If FirstString is identical to
243 SecondString, then 0 is returned. Otherwise, the value returned is the first
244 mismatched Unicode character in SecondString subtracted from the first
245 mismatched Unicode character in FirstString.
247 If FirstString is NULL, then ASSERT().
248 If SecondString is NULL, then ASSERT().
249 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
250 than PcdMaximumUnicodeStringLength Unicode characters not including the
251 Null-terminator, then ASSERT().
252 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
253 than PcdMaximumUnicodeStringLength Unicode characters not including the
254 Null-terminator, then ASSERT().
256 @param FirstString Pointer to a Null-terminated Unicode string.
257 @param SecondString Pointer to a Null-terminated Unicode string.
259 @retval 0 FirstString is identical to SecondString.
260 @retval !=0 FirstString is not identical to SecondString.
266 IN CONST CHAR16
*FirstString
,
267 IN CONST CHAR16
*SecondString
270 Compares two Null-terminated Unicode strings with maximum lengths, and
271 returns the difference between the first mismatched Unicode characters.
273 This function compares the Null-terminated Unicode string FirstString to the
274 Null-terminated Unicode string SecondString. At most, Length Unicode
275 characters will be compared. If Length is 0, then 0 is returned. If
276 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
277 value returned is the first mismatched Unicode character in SecondString
278 subtracted from the first mismatched Unicode character in FirstString.
280 If FirstString is NULL, then ASSERT().
281 If SecondString is NULL, then ASSERT().
282 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
283 than PcdMaximumUnicodeStringLength Unicode characters not including the
284 Null-terminator, then ASSERT().
285 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
286 than PcdMaximumUnicodeStringLength Unicode characters not including the
287 Null-terminator, then ASSERT().
289 @param FirstString Pointer to a Null-terminated Unicode string.
290 @param SecondString Pointer to a Null-terminated Unicode string.
291 @param Length Maximum number of Unicode characters to compare.
293 @retval 0 FirstString is identical to SecondString.
294 @retval !=0 FirstString is not identical to SecondString.
300 IN CONST CHAR16
*FirstString
,
301 IN CONST CHAR16
*SecondString
,
305 Concatenates one Null-terminated Unicode string to another Null-terminated
306 Unicode string, and returns the concatenated Unicode string.
308 This function concatenates two Null-terminated Unicode strings. The contents
309 of Null-terminated Unicode string Source are concatenated to the end of
310 Null-terminated Unicode string Destination. The Null-terminated concatenated
311 Unicode String is returned. If Source and Destination overlap, then the
312 results are undefined.
314 If Destination is NULL, then ASSERT().
315 If Source is NULL, then ASSERT().
316 If Source and Destination overlap, then ASSERT().
317 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
318 than PcdMaximumUnicodeStringLength Unicode characters not including the
319 Null-terminator, then ASSERT().
320 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
321 PcdMaximumUnicodeStringLength Unicode characters not including the
322 Null-terminator, then ASSERT().
323 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
324 and Source results in a Unicode string with more than
325 PcdMaximumUnicodeStringLength Unicode characters not including the
326 Null-terminator, then ASSERT().
328 @param Destination Pointer to a Null-terminated Unicode string.
329 @param Source Pointer to a Null-terminated Unicode string.
337 IN OUT CHAR16
*Destination
,
338 IN CONST CHAR16
*Source
341 Concatenates one Null-terminated Unicode string with a maximum length to the
342 end of another Null-terminated Unicode string, and returns the concatenated
345 This function concatenates two Null-terminated Unicode strings. The contents
346 of Null-terminated Unicode string Source are concatenated to the end of
347 Null-terminated Unicode string Destination, and Destination is returned. At
348 most, Length Unicode characters are concatenated from Source to the end of
349 Destination, and Destination is always Null-terminated. If Length is 0, then
350 Destination is returned unmodified. If Source and Destination overlap, then
351 the results are undefined.
353 If Destination is NULL, then ASSERT().
354 If Source is NULL, then ASSERT().
355 If Source and Destination overlap, then ASSERT().
356 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
357 than PcdMaximumUnicodeStringLength Unicode characters not including the
358 Null-terminator, then ASSERT().
359 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
360 PcdMaximumUnicodeStringLength Unicode characters not including the
361 Null-terminator, then ASSERT().
362 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
363 and Source results in a Unicode string with more than
364 PcdMaximumUnicodeStringLength Unicode characters not including the
365 Null-terminator, then ASSERT().
367 @param Destination Pointer to a Null-terminated Unicode string.
368 @param Source Pointer to a Null-terminated Unicode string.
369 @param Length Maximum number of Unicode characters to concatenate from
378 IN OUT CHAR16
*Destination
,
379 IN CONST CHAR16
*Source
,
383 Copies one Null-terminated ASCII string to another Null-terminated ASCII
384 string and returns the new ASCII string.
386 This function copies the contents of the ASCII string Source to the ASCII
387 string Destination, and returns Destination. If Source and Destination
388 overlap, then the results are undefined.
390 If Destination is NULL, then ASSERT().
391 If Source is NULL, then ASSERT().
392 If Source and Destination overlap, then ASSERT().
393 If PcdMaximumAsciiStringLength is not zero and Source contains more than
394 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
397 @param Destination Pointer to a Null-terminated ASCII string.
398 @param Source Pointer to a Null-terminated ASCII string.
406 OUT CHAR8
*Destination
,
407 IN CONST CHAR8
*Source
410 Copies one Null-terminated ASCII string with a maximum length to another
411 Null-terminated ASCII string with a maximum length and returns the new ASCII
414 This function copies the contents of the ASCII string Source to the ASCII
415 string Destination, and returns Destination. At most, Length ASCII characters
416 are copied from Source to Destination. If Length is 0, then Destination is
417 returned unmodified. If Length is greater that the number of ASCII characters
418 in Source, then Destination is padded with Null ASCII characters. If Source
419 and Destination overlap, then the results are undefined.
421 If Destination is NULL, then ASSERT().
422 If Source is NULL, then ASSERT().
423 If Source and Destination overlap, then ASSERT().
424 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
425 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
428 @param Destination Pointer to a Null-terminated ASCII string.
429 @param Source Pointer to a Null-terminated ASCII string.
430 @param Length Maximum number of ASCII characters to copy.
438 OUT CHAR8
*Destination
,
439 IN CONST CHAR8
*Source
,
443 Returns the length of a Null-terminated ASCII string.
445 This function returns the number of ASCII characters in the Null-terminated
446 ASCII string specified by String.
448 If String is NULL, then ASSERT().
449 If PcdMaximumAsciiStringLength is not zero and String contains more than
450 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
453 @param String Pointer to a Null-terminated ASCII string.
455 @return The length of String.
461 IN CONST CHAR8
*String
464 Returns the size of a Null-terminated ASCII string in bytes, including the
467 This function returns the size, in bytes, of the Null-terminated ASCII string
470 If String is NULL, then ASSERT().
471 If PcdMaximumAsciiStringLength is not zero and String contains more than
472 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
475 @param String Pointer to a Null-terminated ASCII string.
477 @return The size of String.
483 IN CONST CHAR8
*String
486 Compares two Null-terminated ASCII strings, and returns the difference
487 between the first mismatched ASCII characters.
489 This function compares the Null-terminated ASCII string FirstString to the
490 Null-terminated ASCII string SecondString. If FirstString is identical to
491 SecondString, then 0 is returned. Otherwise, the value returned is the first
492 mismatched ASCII character in SecondString subtracted from the first
493 mismatched ASCII character in FirstString.
495 If FirstString is NULL, then ASSERT().
496 If SecondString is NULL, then ASSERT().
497 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
498 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
500 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
501 than PcdMaximumAsciiStringLength ASCII characters not including the
502 Null-terminator, then ASSERT().
504 @param FirstString Pointer to a Null-terminated ASCII string.
505 @param SecondString Pointer to a Null-terminated ASCII string.
507 @retval 0 FirstString is identical to SecondString.
508 @retval !=0 FirstString is not identical to SecondString.
514 IN CONST CHAR8
*FirstString
,
515 IN CONST CHAR8
*SecondString
518 Performs a case insensitive comparison of two Null-terminated ASCII strings,
519 and returns the difference between the first mismatched ASCII characters.
521 This function performs a case insensitive comparison of the Null-terminated
522 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
523 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
524 value returned is the first mismatched lower case ASCII character in
525 SecondString subtracted from the first mismatched lower case ASCII character
528 If FirstString is NULL, then ASSERT().
529 If SecondString is NULL, then ASSERT().
530 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
531 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
533 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
534 than PcdMaximumAsciiStringLength ASCII characters not including the
535 Null-terminator, then ASSERT().
537 @param FirstString Pointer to a Null-terminated ASCII string.
538 @param SecondString Pointer to a Null-terminated ASCII string.
540 @retval 0 FirstString is identical to SecondString using case insensitive
542 @retval !=0 FirstString is not identical to SecondString using case
543 insensitive comparisons.
549 IN CONST CHAR8
*FirstString
,
550 IN CONST CHAR8
*SecondString
553 Compares two Null-terminated ASCII strings with maximum lengths, and returns
554 the difference between the first mismatched ASCII characters.
556 This function compares the Null-terminated ASCII string FirstString to the
557 Null-terminated ASCII string SecondString. At most, Length ASCII characters
558 will be compared. If Length is 0, then 0 is returned. If FirstString is
559 identical to SecondString, then 0 is returned. Otherwise, the value returned
560 is the first mismatched ASCII character in SecondString subtracted from the
561 first mismatched ASCII character in FirstString.
563 If FirstString is NULL, then ASSERT().
564 If SecondString is NULL, then ASSERT().
565 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
566 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
568 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than
569 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
572 @param FirstString Pointer to a Null-terminated ASCII string.
573 @param SecondString Pointer to a Null-terminated ASCII string.
575 @retval 0 FirstString is identical to SecondString.
576 @retval !=0 FirstString is not identical to SecondString.
582 IN CONST CHAR8
*FirstString
,
583 IN CONST CHAR8
*SecondString
,
587 Concatenates one Null-terminated ASCII string to another Null-terminated
588 ASCII string, and returns the concatenated ASCII string.
590 This function concatenates two Null-terminated ASCII strings. The contents of
591 Null-terminated ASCII string Source are concatenated to the end of Null-
592 terminated ASCII string Destination. The Null-terminated concatenated ASCII
595 If Destination is NULL, then ASSERT().
596 If Source is NULL, then ASSERT().
597 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
598 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
600 If PcdMaximumAsciiStringLength is not zero and Source contains more than
601 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
603 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
604 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
605 ASCII characters, then ASSERT().
607 @param Destination Pointer to a Null-terminated ASCII string.
608 @param Source Pointer to a Null-terminated ASCII string.
616 IN OUT CHAR8
*Destination
,
617 IN CONST CHAR8
*Source
620 Concatenates one Null-terminated ASCII string with a maximum length to the
621 end of another Null-terminated ASCII string, and returns the concatenated
624 This function concatenates two Null-terminated ASCII strings. The contents
625 of Null-terminated ASCII string Source are concatenated to the end of Null-
626 terminated ASCII string Destination, and Destination is returned. At most,
627 Length ASCII characters are concatenated from Source to the end of
628 Destination, and Destination is always Null-terminated. If Length is 0, then
629 Destination is returned unmodified. If Source and Destination overlap, then
630 the results are undefined.
632 If Destination is NULL, then ASSERT().
633 If Source is NULL, then ASSERT().
634 If Source and Destination overlap, then ASSERT().
635 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
636 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
638 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
639 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
641 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
642 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
643 ASCII characters not including the Null-terminator, then ASSERT().
645 @param Destination Pointer to a Null-terminated ASCII string.
646 @param Source Pointer to a Null-terminated ASCII string.
647 @param Length Maximum number of ASCII characters to concatenate from
656 IN OUT CHAR8
*Destination
,
657 IN CONST CHAR8
*Source
,
661 Converts an 8-bit value to an 8-bit BCD value.
663 Converts the 8-bit value specified by Value to BCD. The BCD value is
666 If Value >= 100, then ASSERT().
668 @param Value The 8-bit value to convert to BCD. Range 0..99.
670 @return The BCD value
680 Converts an 8-bit BCD value to an 8-bit value.
682 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
685 If Value >= 0xA0, then ASSERT().
686 If (Value & 0x0F) >= 0x0A, then ASSERT().
688 @param Value The 8-bit BCD value to convert to an 8-bit value.
690 @return The 8-bit value is returned.
700 // LIST_ENTRY definition
702 typedef struct _LIST_ENTRY LIST_ENTRY
;
705 LIST_ENTRY
*ForwardLink
;
706 LIST_ENTRY
*BackLink
;
710 // Linked List Functions and Macros
714 Initializes the head node of a doubly linked list that is declared as a
715 global variable in a module.
717 Initializes the forward and backward links of a new linked list. After
718 initializing a linked list with this macro, the other linked list functions
719 may be used to add and remove nodes from the linked list. This macro results
720 in smaller executables by initializing the linked list in the data section,
721 instead if calling the InitializeListHead() function to perform the
722 equivalent operation.
724 @param ListHead The head note of a list to initiailize.
727 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
730 Initializes the head node of a doubly linked list, and returns the pointer to
731 the head node of the doubly linked list.
733 Initializes the forward and backward links of a new linked list. After
734 initializing a linked list with this function, the other linked list
735 functions may be used to add and remove nodes from the linked list. It is up
736 to the caller of this function to allocate the memory for ListHead.
738 If ListHead is NULL, then ASSERT().
740 @param ListHead A pointer to the head node of a new doubly linked list.
748 IN LIST_ENTRY
*ListHead
752 Adds a node to the beginning of a doubly linked list, and returns the pointer
753 to the head node of the doubly linked list.
755 Adds the node Entry at the beginning of the doubly linked list denoted by
756 ListHead, and returns ListHead.
758 If ListHead is NULL, then ASSERT().
759 If Entry is NULL, then ASSERT().
760 If ListHead was not initialized with InitializeListHead(), then ASSERT().
761 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
762 of nodes in ListHead, including the ListHead node, is greater than or
763 equal to PcdMaximumLinkedListLength, then ASSERT().
765 @param ListHead A pointer to the head node of a doubly linked list.
766 @param Entry A pointer to a node that is to be inserted at the beginning
767 of a doubly linked list.
775 IN LIST_ENTRY
*ListHead
,
780 Adds a node to the end of a doubly linked list, and returns the pointer to
781 the head node of the doubly linked list.
783 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
784 and returns ListHead.
786 If ListHead is NULL, then ASSERT().
787 If Entry is NULL, then ASSERT().
788 If ListHead was not initialized with InitializeListHead(), then ASSERT().
789 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
790 of nodes in ListHead, including the ListHead node, is greater than or
791 equal to PcdMaximumLinkedListLength, then ASSERT().
793 @param ListHead A pointer to the head node of a doubly linked list.
794 @param Entry A pointer to a node that is to be added at the end of the
803 IN LIST_ENTRY
*ListHead
,
808 Retrieves the first node of a doubly linked list.
810 Returns the first node of a doubly linked list. List must have been
811 initialized with InitializeListHead(). If List is empty, then NULL is
814 If List is NULL, then ASSERT().
815 If List was not initialized with InitializeListHead(), then ASSERT().
816 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
817 in List, including the List node, is greater than or equal to
818 PcdMaximumLinkedListLength, then ASSERT().
820 @param List A pointer to the head node of a doubly linked list.
822 @return The first node of a doubly linked list.
823 @retval NULL The list is empty.
829 IN CONST LIST_ENTRY
*List
833 Retrieves the next node of a doubly linked list.
835 Returns the node of a doubly linked list that follows Node. List must have
836 been initialized with InitializeListHead(). If List is empty, then List is
839 If List is NULL, then ASSERT().
840 If Node is NULL, then ASSERT().
841 If List was not initialized with InitializeListHead(), then ASSERT().
842 If PcdMaximumLinkedListLenth is not zero, and List contains more than
843 PcdMaximumLinkedListLenth nodes, then ASSERT().
844 If Node is not a node in List, then ASSERT().
846 @param List A pointer to the head node of a doubly linked list.
847 @param Node A pointer to a node in the doubly linked list.
849 @return Pointer to the next node if one exists. Otherwise a null value which
850 is actually List is returned.
856 IN CONST LIST_ENTRY
*List
,
857 IN CONST LIST_ENTRY
*Node
861 Checks to see if a doubly linked list is empty or not.
863 Checks to see if the doubly linked list is empty. If the linked list contains
864 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
866 If ListHead is NULL, then ASSERT().
867 If ListHead was not initialized with InitializeListHead(), then ASSERT().
868 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
869 in List, including the List node, is greater than or equal to
870 PcdMaximumLinkedListLength, then ASSERT().
872 @param ListHead A pointer to the head node of a doubly linked list.
874 @retval TRUE The linked list is empty.
875 @retval FALSE The linked list is not empty.
881 IN CONST LIST_ENTRY
*ListHead
885 Determines if a node in a doubly linked list is null.
887 Returns FALSE if Node is one of the nodes in the doubly linked list specified
888 by List. Otherwise, TRUE is returned. List must have been initialized with
889 InitializeListHead().
891 If List is NULL, then ASSERT().
892 If Node is NULL, then ASSERT().
893 If List was not initialized with InitializeListHead(), then ASSERT().
894 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
895 in List, including the List node, is greater than or equal to
896 PcdMaximumLinkedListLength, then ASSERT().
897 If Node is not a node in List and Node is not equal to List, then ASSERT().
899 @param List A pointer to the head node of a doubly linked list.
900 @param Node A pointer to a node in the doubly linked list.
902 @retval TRUE Node is one of the nodes in the doubly linked list.
903 @retval FALSE Node is not one of the nodes in the doubly linked list.
909 IN CONST LIST_ENTRY
*List
,
910 IN CONST LIST_ENTRY
*Node
914 Determines if a node the last node in a doubly linked list.
916 Returns TRUE if Node is the last node in the doubly linked list specified by
917 List. Otherwise, FALSE is returned. List must have been initialized with
918 InitializeListHead().
920 If List is NULL, then ASSERT().
921 If Node is NULL, then ASSERT().
922 If List was not initialized with InitializeListHead(), then ASSERT().
923 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
924 in List, including the List node, is greater than or equal to
925 PcdMaximumLinkedListLength, then ASSERT().
926 If Node is not a node in List, then ASSERT().
928 @param List A pointer to the head node of a doubly linked list.
929 @param Node A pointer to a node in the doubly linked list.
931 @retval TRUE Node is the last node in the linked list.
932 @retval FALSE Node is not the last node in the linked list.
938 IN CONST LIST_ENTRY
*List
,
939 IN CONST LIST_ENTRY
*Node
943 Swaps the location of two nodes in a doubly linked list, and returns the
944 first node after the swap.
946 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
947 Otherwise, the location of the FirstEntry node is swapped with the location
948 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
949 same double linked list as FirstEntry and that double linked list must have
950 been initialized with InitializeListHead(). SecondEntry is returned after the
953 If FirstEntry is NULL, then ASSERT().
954 If SecondEntry is NULL, then ASSERT().
955 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
956 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
957 linked list containing the FirstEntry and SecondEntry nodes, including
958 the FirstEntry and SecondEntry nodes, is greater than or equal to
959 PcdMaximumLinkedListLength, then ASSERT().
961 @param FirstEntry A pointer to a node in a linked list.
962 @param SecondEntry A pointer to another node in the same linked list.
968 IN LIST_ENTRY
*FirstEntry
,
969 IN LIST_ENTRY
*SecondEntry
973 Removes a node from a doubly linked list, and returns the node that follows
976 Removes the node Entry from a doubly linked list. It is up to the caller of
977 this function to release the memory used by this node if that is required. On
978 exit, the node following Entry in the doubly linked list is returned. If
979 Entry is the only node in the linked list, then the head node of the linked
982 If Entry is NULL, then ASSERT().
983 If Entry is the head node of an empty list, then ASSERT().
984 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
985 linked list containing Entry, including the Entry node, is greater than
986 or equal to PcdMaximumLinkedListLength, then ASSERT().
988 @param Entry A pointer to a node in a linked list
996 IN CONST LIST_ENTRY
*Entry
1004 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
1005 with zeros. The shifted value is returned.
1007 This function shifts the 64-bit value Operand to the left by Count bits. The
1008 low Count bits are set to zero. The shifted value is returned.
1010 If Count is greater than 63, then ASSERT().
1012 @param Operand The 64-bit operand to shift left.
1013 @param Count The number of bits to shift left.
1015 @return Operand << Count
1026 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1027 filled with zeros. The shifted value is returned.
1029 This function shifts the 64-bit value Operand to the right by Count bits. The
1030 high Count bits are set to zero. The shifted value is returned.
1032 If Count is greater than 63, then ASSERT().
1034 @param Operand The 64-bit operand to shift right.
1035 @param Count The number of bits to shift right.
1037 @return Operand >> Count
1048 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1049 with original integer's bit 63. The shifted value is returned.
1051 This function shifts the 64-bit value Operand to the right by Count bits. The
1052 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1054 If Count is greater than 63, then ASSERT().
1056 @param Operand The 64-bit operand to shift right.
1057 @param Count The number of bits to shift right.
1059 @return Operand >> Count
1070 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1071 with the high bits that were rotated.
1073 This function rotates the 32-bit value Operand to the left by Count bits. The
1074 low Count bits are fill with the high Count bits of Operand. The rotated
1077 If Count is greater than 31, then ASSERT().
1079 @param Operand The 32-bit operand to rotate left.
1080 @param Count The number of bits to rotate left.
1082 @return Operand <<< Count
1093 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1094 with the low bits that were rotated.
1096 This function rotates the 32-bit value Operand to the right by Count bits.
1097 The high Count bits are fill with the low Count bits of Operand. The rotated
1100 If Count is greater than 31, then ASSERT().
1102 @param Operand The 32-bit operand to rotate right.
1103 @param Count The number of bits to rotate right.
1105 @return Operand >>> Count
1116 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1117 with the high bits that were rotated.
1119 This function rotates the 64-bit value Operand to the left by Count bits. The
1120 low Count bits are fill with the high Count bits of Operand. The rotated
1123 If Count is greater than 63, then ASSERT().
1125 @param Operand The 64-bit operand to rotate left.
1126 @param Count The number of bits to rotate left.
1128 @return Operand <<< Count
1139 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1140 with the high low bits that were rotated.
1142 This function rotates the 64-bit value Operand to the right by Count bits.
1143 The high Count bits are fill with the low Count bits of Operand. The rotated
1146 If Count is greater than 63, then ASSERT().
1148 @param Operand The 64-bit operand to rotate right.
1149 @param Count The number of bits to rotate right.
1151 @return Operand >>> Count
1162 Returns the bit position of the lowest bit set in a 32-bit value.
1164 This function computes the bit position of the lowest bit set in the 32-bit
1165 value specified by Operand. If Operand is zero, then -1 is returned.
1166 Otherwise, a value between 0 and 31 is returned.
1168 @param Operand The 32-bit operand to evaluate.
1170 @return Position of the lowest bit set in Operand if found.
1171 @retval -1 Operand is zero.
1181 Returns the bit position of the lowest bit set in a 64-bit value.
1183 This function computes the bit position of the lowest bit set in the 64-bit
1184 value specified by Operand. If Operand is zero, then -1 is returned.
1185 Otherwise, a value between 0 and 63 is returned.
1187 @param Operand The 64-bit operand to evaluate.
1189 @return Position of the lowest bit set in Operand if found.
1190 @retval -1 Operand is zero.
1200 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1203 This function computes the bit position of the highest bit set in the 32-bit
1204 value specified by Operand. If Operand is zero, then -1 is returned.
1205 Otherwise, a value between 0 and 31 is returned.
1207 @param Operand The 32-bit operand to evaluate.
1209 @return Position of the highest bit set in Operand if found.
1210 @retval -1 Operand is zero.
1220 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1223 This function computes the bit position of the highest bit set in the 64-bit
1224 value specified by Operand. If Operand is zero, then -1 is returned.
1225 Otherwise, a value between 0 and 63 is returned.
1227 @param Operand The 64-bit operand to evaluate.
1229 @return Position of the highest bit set in Operand if found.
1230 @retval -1 Operand is zero.
1240 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1241 1 << HighBitSet32(x).
1243 This function computes the value of the highest bit set in the 32-bit value
1244 specified by Operand. If Operand is zero, then zero is returned.
1246 @param Operand The 32-bit operand to evaluate.
1248 @return 1 << HighBitSet32(Operand)
1249 @retval 0 Operand is zero.
1259 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1260 1 << HighBitSet64(x).
1262 This function computes the value of the highest bit set in the 64-bit value
1263 specified by Operand. If Operand is zero, then zero is returned.
1265 @param Operand The 64-bit operand to evaluate.
1267 @return 1 << HighBitSet64(Operand)
1268 @retval 0 Operand is zero.
1278 Switches the endianess of a 16-bit integer.
1280 This function swaps the bytes in a 16-bit unsigned value to switch the value
1281 from little endian to big endian or vice versa. The byte swapped value is
1284 @param Operand A 16-bit unsigned value.
1286 @return The byte swaped Operand.
1296 Switches the endianess of a 32-bit integer.
1298 This function swaps the bytes in a 32-bit unsigned value to switch the value
1299 from little endian to big endian or vice versa. The byte swapped value is
1302 @param Operand A 32-bit unsigned value.
1304 @return The byte swaped Operand.
1314 Switches the endianess of a 64-bit integer.
1316 This function swaps the bytes in a 64-bit unsigned value to switch the value
1317 from little endian to big endian or vice versa. The byte swapped value is
1320 @param Operand A 64-bit unsigned value.
1322 @return The byte swaped Operand.
1332 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1333 generates a 64-bit unsigned result.
1335 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1336 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1337 bit unsigned result is returned.
1339 If the result overflows, then ASSERT().
1341 @param Multiplicand A 64-bit unsigned value.
1342 @param Multiplier A 32-bit unsigned value.
1344 @return Multiplicand * Multiplier
1350 IN UINT64 Multiplicand
,
1351 IN UINT32 Multiplier
1355 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1356 generates a 64-bit unsigned result.
1358 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1359 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1360 bit unsigned result is returned.
1362 If the result overflows, then ASSERT().
1364 @param Multiplicand A 64-bit unsigned value.
1365 @param Multiplier A 64-bit unsigned value.
1367 @return Multiplicand * Multiplier
1373 IN UINT64 Multiplicand
,
1374 IN UINT64 Multiplier
1378 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1379 64-bit signed result.
1381 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1382 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1383 signed result is returned.
1385 If the result overflows, then ASSERT().
1387 @param Multiplicand A 64-bit signed value.
1388 @param Multiplier A 64-bit signed value.
1390 @return Multiplicand * Multiplier
1396 IN INT64 Multiplicand
,
1401 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1402 a 64-bit unsigned result.
1404 This function divides the 64-bit unsigned value Dividend by the 32-bit
1405 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1406 function returns the 64-bit unsigned quotient.
1408 If Divisor is 0, then ASSERT().
1410 @param Dividend A 64-bit unsigned value.
1411 @param Divisor A 32-bit unsigned value.
1413 @return Dividend / Divisor
1424 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1425 a 32-bit unsigned remainder.
1427 This function divides the 64-bit unsigned value Dividend by the 32-bit
1428 unsigned value Divisor and generates a 32-bit remainder. This function
1429 returns the 32-bit unsigned remainder.
1431 If Divisor is 0, then ASSERT().
1433 @param Dividend A 64-bit unsigned value.
1434 @param Divisor A 32-bit unsigned value.
1436 @return Dividend % Divisor
1447 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1448 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1450 This function divides the 64-bit unsigned value Dividend by the 32-bit
1451 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1452 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1453 This function returns the 64-bit unsigned quotient.
1455 If Divisor is 0, then ASSERT().
1457 @param Dividend A 64-bit unsigned value.
1458 @param Divisor A 32-bit unsigned value.
1459 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1460 optional and may be NULL.
1462 @return Dividend / Divisor
1467 DivU64x32Remainder (
1470 OUT UINT32
*Remainder OPTIONAL
1474 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
1475 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
1477 This function divides the 64-bit unsigned value Dividend by the 64-bit
1478 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1479 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
1480 This function returns the 64-bit unsigned quotient.
1482 If Divisor is 0, then ASSERT().
1484 @param Dividend A 64-bit unsigned value.
1485 @param Divisor A 64-bit unsigned value.
1486 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
1487 optional and may be NULL.
1489 @return Dividend / Divisor
1494 DivU64x64Remainder (
1497 OUT UINT64
*Remainder OPTIONAL
1501 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
1502 64-bit signed result and a optional 64-bit signed remainder.
1504 This function divides the 64-bit signed value Dividend by the 64-bit signed
1505 value Divisor and generates a 64-bit signed quotient. If Remainder is not
1506 NULL, then the 64-bit signed remainder is returned in Remainder. This
1507 function returns the 64-bit signed quotient.
1509 If Divisor is 0, then ASSERT().
1511 @param Dividend A 64-bit signed value.
1512 @param Divisor A 64-bit signed value.
1513 @param Remainder A pointer to a 64-bit signed value. This parameter is
1514 optional and may be NULL.
1516 @return Dividend / Divisor
1521 DivS64x64Remainder (
1524 OUT INT64
*Remainder OPTIONAL
1528 Reads a 16-bit value from memory that may be unaligned.
1530 This function returns the 16-bit value pointed to by Buffer. The function
1531 guarantees that the read operation does not produce an alignment fault.
1533 If the Buffer is NULL, then ASSERT().
1535 @param Buffer Pointer to a 16-bit value that may be unaligned.
1543 IN CONST UINT16
*Uint16
1547 Writes a 16-bit value to memory that may be unaligned.
1549 This function writes the 16-bit value specified by Value to Buffer. Value is
1550 returned. The function guarantees that the write operation does not produce
1553 If the Buffer is NULL, then ASSERT().
1555 @param Buffer Pointer to a 16-bit value that may be unaligned.
1556 @param Value 16-bit value to write to Buffer.
1569 Reads a 24-bit value from memory that may be unaligned.
1571 This function returns the 24-bit value pointed to by Buffer. The function
1572 guarantees that the read operation does not produce an alignment fault.
1574 If the Buffer is NULL, then ASSERT().
1576 @param Buffer Pointer to a 24-bit value that may be unaligned.
1578 @return The value read.
1584 IN CONST UINT32
*Buffer
1588 Writes a 24-bit value to memory that may be unaligned.
1590 This function writes the 24-bit value specified by Value to Buffer. Value is
1591 returned. The function guarantees that the write operation does not produce
1594 If the Buffer is NULL, then ASSERT().
1596 @param Buffer Pointer to a 24-bit value that may be unaligned.
1597 @param Value 24-bit value to write to Buffer.
1599 @return The value written.
1610 Reads a 32-bit value from memory that may be unaligned.
1612 This function returns the 32-bit value pointed to by Buffer. The function
1613 guarantees that the read operation does not produce an alignment fault.
1615 If the Buffer is NULL, then ASSERT().
1617 @param Buffer Pointer to a 32-bit value that may be unaligned.
1625 IN CONST UINT32
*Uint32
1629 Writes a 32-bit value to memory that may be unaligned.
1631 This function writes the 32-bit value specified by Value to Buffer. Value is
1632 returned. The function guarantees that the write operation does not produce
1635 If the Buffer is NULL, then ASSERT().
1637 @param Buffer Pointer to a 32-bit value that may be unaligned.
1638 @param Value 32-bit value to write to Buffer.
1651 Reads a 64-bit value from memory that may be unaligned.
1653 This function returns the 64-bit value pointed to by Buffer. The function
1654 guarantees that the read operation does not produce an alignment fault.
1656 If the Buffer is NULL, then ASSERT().
1658 @param Buffer Pointer to a 64-bit value that may be unaligned.
1666 IN CONST UINT64
*Uint64
1670 Writes a 64-bit value to memory that may be unaligned.
1672 This function writes the 64-bit value specified by Value to Buffer. Value is
1673 returned. The function guarantees that the write operation does not produce
1676 If the Buffer is NULL, then ASSERT().
1678 @param Buffer Pointer to a 64-bit value that may be unaligned.
1679 @param Value 64-bit value to write to Buffer.
1692 // Bit Field Functions
1696 Returns a bit field from an 8-bit value.
1698 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1700 If 8-bit operations are not supported, then ASSERT().
1701 If StartBit is greater than 7, then ASSERT().
1702 If EndBit is greater than 7, then ASSERT().
1703 If EndBit is less than StartBit, then ASSERT().
1705 @param Operand Operand on which to perform the bitfield operation.
1706 @param StartBit The ordinal of the least significant bit in the bit field.
1708 @param EndBit The ordinal of the most significant bit in the bit field.
1711 @return The bit field read.
1723 Writes a bit field to an 8-bit value, and returns the result.
1725 Writes Value to the bit field specified by the StartBit and the EndBit in
1726 Operand. All other bits in Operand are preserved. The new 8-bit value is
1729 If 8-bit operations are not supported, then ASSERT().
1730 If StartBit is greater than 7, then ASSERT().
1731 If EndBit is greater than 7, then ASSERT().
1732 If EndBit is less than StartBit, then ASSERT().
1734 @param Operand Operand on which to perform the bitfield operation.
1735 @param StartBit The ordinal of the least significant bit in the bit field.
1737 @param EndBit The ordinal of the most significant bit in the bit field.
1739 @param Value New value of the bit field.
1741 @return The new 8-bit value.
1754 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
1757 Performs a bitwise inclusive OR between the bit field specified by StartBit
1758 and EndBit in Operand and the value specified by OrData. All other bits in
1759 Operand are preserved. The new 8-bit value is returned.
1761 If 8-bit operations are not supported, then ASSERT().
1762 If StartBit is greater than 7, then ASSERT().
1763 If EndBit is greater than 7, then ASSERT().
1764 If EndBit is less than StartBit, then ASSERT().
1766 @param Operand Operand on which to perform the bitfield operation.
1767 @param StartBit The ordinal of the least significant bit in the bit field.
1769 @param EndBit The ordinal of the most significant bit in the bit field.
1771 @param OrData The value to OR with the read value from the value
1773 @return The new 8-bit value.
1786 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
1789 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1790 in Operand and the value specified by AndData. All other bits in Operand are
1791 preserved. The new 8-bit value is returned.
1793 If 8-bit operations are not supported, then ASSERT().
1794 If StartBit is greater than 7, then ASSERT().
1795 If EndBit is greater than 7, then ASSERT().
1796 If EndBit is less than StartBit, then ASSERT().
1798 @param Operand Operand on which to perform the bitfield operation.
1799 @param StartBit The ordinal of the least significant bit in the bit field.
1801 @param EndBit The ordinal of the most significant bit in the bit field.
1803 @param AndData The value to AND with the read value from the value.
1805 @return The new 8-bit value.
1818 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
1819 bitwise OR, and returns the result.
1821 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1822 in Operand and the value specified by AndData, followed by a bitwise
1823 inclusive OR with value specified by OrData. All other bits in Operand are
1824 preserved. The new 8-bit value is returned.
1826 If 8-bit operations are not supported, then ASSERT().
1827 If StartBit is greater than 7, then ASSERT().
1828 If EndBit is greater than 7, then ASSERT().
1829 If EndBit is less than StartBit, then ASSERT().
1831 @param Operand Operand on which to perform the bitfield operation.
1832 @param StartBit The ordinal of the least significant bit in the bit field.
1834 @param EndBit The ordinal of the most significant bit in the bit field.
1836 @param AndData The value to AND with the read value from the value.
1837 @param OrData The value to OR with the result of the AND operation.
1839 @return The new 8-bit value.
1844 BitFieldAndThenOr8 (
1853 Returns a bit field from a 16-bit value.
1855 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1857 If 16-bit operations are not supported, then ASSERT().
1858 If StartBit is greater than 15, then ASSERT().
1859 If EndBit is greater than 15, then ASSERT().
1860 If EndBit is less than StartBit, then ASSERT().
1862 @param Operand Operand on which to perform the bitfield operation.
1863 @param StartBit The ordinal of the least significant bit in the bit field.
1865 @param EndBit The ordinal of the most significant bit in the bit field.
1868 @return The bit field read.
1880 Writes a bit field to a 16-bit value, and returns the result.
1882 Writes Value to the bit field specified by the StartBit and the EndBit in
1883 Operand. All other bits in Operand are preserved. The new 16-bit value is
1886 If 16-bit operations are not supported, then ASSERT().
1887 If StartBit is greater than 15, then ASSERT().
1888 If EndBit is greater than 15, then ASSERT().
1889 If EndBit is less than StartBit, then ASSERT().
1891 @param Operand Operand on which to perform the bitfield operation.
1892 @param StartBit The ordinal of the least significant bit in the bit field.
1894 @param EndBit The ordinal of the most significant bit in the bit field.
1896 @param Value New value of the bit field.
1898 @return The new 16-bit value.
1911 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
1914 Performs a bitwise inclusive OR between the bit field specified by StartBit
1915 and EndBit in Operand and the value specified by OrData. All other bits in
1916 Operand are preserved. The new 16-bit value is returned.
1918 If 16-bit operations are not supported, then ASSERT().
1919 If StartBit is greater than 15, then ASSERT().
1920 If EndBit is greater than 15, then ASSERT().
1921 If EndBit is less than StartBit, then ASSERT().
1923 @param Operand Operand on which to perform the bitfield operation.
1924 @param StartBit The ordinal of the least significant bit in the bit field.
1926 @param EndBit The ordinal of the most significant bit in the bit field.
1928 @param OrData The value to OR with the read value from the value
1930 @return The new 16-bit value.
1943 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
1946 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1947 in Operand and the value specified by AndData. All other bits in Operand are
1948 preserved. The new 16-bit value is returned.
1950 If 16-bit operations are not supported, then ASSERT().
1951 If StartBit is greater than 15, then ASSERT().
1952 If EndBit is greater than 15, then ASSERT().
1953 If EndBit is less than StartBit, then ASSERT().
1955 @param Operand Operand on which to perform the bitfield operation.
1956 @param StartBit The ordinal of the least significant bit in the bit field.
1958 @param EndBit The ordinal of the most significant bit in the bit field.
1960 @param AndData The value to AND with the read value from the value
1962 @return The new 16-bit value.
1975 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
1976 bitwise OR, and returns the result.
1978 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1979 in Operand and the value specified by AndData, followed by a bitwise
1980 inclusive OR with value specified by OrData. All other bits in Operand are
1981 preserved. The new 16-bit value is returned.
1983 If 16-bit operations are not supported, then ASSERT().
1984 If StartBit is greater than 15, then ASSERT().
1985 If EndBit is greater than 15, then ASSERT().
1986 If EndBit is less than StartBit, then ASSERT().
1988 @param Operand Operand on which to perform the bitfield operation.
1989 @param StartBit The ordinal of the least significant bit in the bit field.
1991 @param EndBit The ordinal of the most significant bit in the bit field.
1993 @param AndData The value to AND with the read value from the value.
1994 @param OrData The value to OR with the result of the AND operation.
1996 @return The new 16-bit value.
2001 BitFieldAndThenOr16 (
2010 Returns a bit field from a 32-bit value.
2012 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2014 If 32-bit operations are not supported, then ASSERT().
2015 If StartBit is greater than 31, then ASSERT().
2016 If EndBit is greater than 31, then ASSERT().
2017 If EndBit is less than StartBit, then ASSERT().
2019 @param Operand Operand on which to perform the bitfield operation.
2020 @param StartBit The ordinal of the least significant bit in the bit field.
2022 @param EndBit The ordinal of the most significant bit in the bit field.
2025 @return The bit field read.
2037 Writes a bit field to a 32-bit value, and returns the result.
2039 Writes Value to the bit field specified by the StartBit and the EndBit in
2040 Operand. All other bits in Operand are preserved. The new 32-bit value is
2043 If 32-bit operations are not supported, then ASSERT().
2044 If StartBit is greater than 31, then ASSERT().
2045 If EndBit is greater than 31, then ASSERT().
2046 If EndBit is less than StartBit, then ASSERT().
2048 @param Operand Operand on which to perform the bitfield operation.
2049 @param StartBit The ordinal of the least significant bit in the bit field.
2051 @param EndBit The ordinal of the most significant bit in the bit field.
2053 @param Value New value of the bit field.
2055 @return The new 32-bit value.
2068 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2071 Performs a bitwise inclusive OR between the bit field specified by StartBit
2072 and EndBit in Operand and the value specified by OrData. All other bits in
2073 Operand are preserved. The new 32-bit value is returned.
2075 If 32-bit operations are not supported, then ASSERT().
2076 If StartBit is greater than 31, then ASSERT().
2077 If EndBit is greater than 31, then ASSERT().
2078 If EndBit is less than StartBit, then ASSERT().
2080 @param Operand Operand on which to perform the bitfield operation.
2081 @param StartBit The ordinal of the least significant bit in the bit field.
2083 @param EndBit The ordinal of the most significant bit in the bit field.
2085 @param OrData The value to OR with the read value from the value
2087 @return The new 32-bit value.
2100 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2103 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2104 in Operand and the value specified by AndData. All other bits in Operand are
2105 preserved. The new 32-bit value is returned.
2107 If 32-bit operations are not supported, then ASSERT().
2108 If StartBit is greater than 31, then ASSERT().
2109 If EndBit is greater than 31, then ASSERT().
2110 If EndBit is less than StartBit, then ASSERT().
2112 @param Operand Operand on which to perform the bitfield operation.
2113 @param StartBit The ordinal of the least significant bit in the bit field.
2115 @param EndBit The ordinal of the most significant bit in the bit field.
2117 @param AndData The value to AND with the read value from the value
2119 @return The new 32-bit value.
2132 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2133 bitwise OR, and returns the result.
2135 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2136 in Operand and the value specified by AndData, followed by a bitwise
2137 inclusive OR with value specified by OrData. All other bits in Operand are
2138 preserved. The new 32-bit value is returned.
2140 If 32-bit operations are not supported, then ASSERT().
2141 If StartBit is greater than 31, then ASSERT().
2142 If EndBit is greater than 31, then ASSERT().
2143 If EndBit is less than StartBit, then ASSERT().
2145 @param Operand Operand on which to perform the bitfield operation.
2146 @param StartBit The ordinal of the least significant bit in the bit field.
2148 @param EndBit The ordinal of the most significant bit in the bit field.
2150 @param AndData The value to AND with the read value from the value.
2151 @param OrData The value to OR with the result of the AND operation.
2153 @return The new 32-bit value.
2158 BitFieldAndThenOr32 (
2167 Returns a bit field from a 64-bit value.
2169 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2171 If 64-bit operations are not supported, then ASSERT().
2172 If StartBit is greater than 63, then ASSERT().
2173 If EndBit is greater than 63, then ASSERT().
2174 If EndBit is less than StartBit, then ASSERT().
2176 @param Operand Operand on which to perform the bitfield operation.
2177 @param StartBit The ordinal of the least significant bit in the bit field.
2179 @param EndBit The ordinal of the most significant bit in the bit field.
2182 @return The bit field read.
2194 Writes a bit field to a 64-bit value, and returns the result.
2196 Writes Value to the bit field specified by the StartBit and the EndBit in
2197 Operand. All other bits in Operand are preserved. The new 64-bit value is
2200 If 64-bit operations are not supported, then ASSERT().
2201 If StartBit is greater than 63, then ASSERT().
2202 If EndBit is greater than 63, then ASSERT().
2203 If EndBit is less than StartBit, then ASSERT().
2205 @param Operand Operand on which to perform the bitfield operation.
2206 @param StartBit The ordinal of the least significant bit in the bit field.
2208 @param EndBit The ordinal of the most significant bit in the bit field.
2210 @param Value New value of the bit field.
2212 @return The new 64-bit value.
2225 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2228 Performs a bitwise inclusive OR between the bit field specified by StartBit
2229 and EndBit in Operand and the value specified by OrData. All other bits in
2230 Operand are preserved. The new 64-bit value is returned.
2232 If 64-bit operations are not supported, then ASSERT().
2233 If StartBit is greater than 63, then ASSERT().
2234 If EndBit is greater than 63, then ASSERT().
2235 If EndBit is less than StartBit, then ASSERT().
2237 @param Operand Operand on which to perform the bitfield operation.
2238 @param StartBit The ordinal of the least significant bit in the bit field.
2240 @param EndBit The ordinal of the most significant bit in the bit field.
2242 @param OrData The value to OR with the read value from the value
2244 @return The new 64-bit value.
2257 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2260 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2261 in Operand and the value specified by AndData. All other bits in Operand are
2262 preserved. The new 64-bit value is returned.
2264 If 64-bit operations are not supported, then ASSERT().
2265 If StartBit is greater than 63, then ASSERT().
2266 If EndBit is greater than 63, then ASSERT().
2267 If EndBit is less than StartBit, then ASSERT().
2269 @param Operand Operand on which to perform the bitfield operation.
2270 @param StartBit The ordinal of the least significant bit in the bit field.
2272 @param EndBit The ordinal of the most significant bit in the bit field.
2274 @param AndData The value to AND with the read value from the value
2276 @return The new 64-bit value.
2289 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2290 bitwise OR, and returns the result.
2292 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2293 in Operand and the value specified by AndData, followed by a bitwise
2294 inclusive OR with value specified by OrData. All other bits in Operand are
2295 preserved. The new 64-bit value is returned.
2297 If 64-bit operations are not supported, then ASSERT().
2298 If StartBit is greater than 63, then ASSERT().
2299 If EndBit is greater than 63, then ASSERT().
2300 If EndBit is less than StartBit, then ASSERT().
2302 @param Operand Operand on which to perform the bitfield operation.
2303 @param StartBit The ordinal of the least significant bit in the bit field.
2305 @param EndBit The ordinal of the most significant bit in the bit field.
2307 @param AndData The value to AND with the read value from the value.
2308 @param OrData The value to OR with the result of the AND operation.
2310 @return The new 64-bit value.
2315 BitFieldAndThenOr64 (
2324 // Base Library Synchronization Functions
2328 Retrieves the architecture specific spin lock alignment requirements for
2329 optimal spin lock performance.
2331 This function retrieves the spin lock alignment requirements for optimal
2332 performance on a given CPU architecture. The spin lock alignment must be a
2333 power of two and is returned by this function. If there are no alignment
2334 requirements, then 1 must be returned. The spin lock synchronization
2335 functions must function correctly if the spin lock size and alignment values
2336 returned by this function are not used at all. These values are hints to the
2337 consumers of the spin lock synchronization functions to obtain optimal spin
2340 @return The architecture specific spin lock alignment.
2345 GetSpinLockProperties (
2350 Initializes a spin lock to the released state and returns the spin lock.
2352 This function initializes the spin lock specified by SpinLock to the released
2353 state, and returns SpinLock. Optimal performance can be achieved by calling
2354 GetSpinLockProperties() to determine the size and alignment requirements for
2357 If SpinLock is NULL, then ASSERT().
2359 @param SpinLock A pointer to the spin lock to initialize to the released
2367 InitializeSpinLock (
2368 IN SPIN_LOCK
*SpinLock
2372 Waits until a spin lock can be placed in the acquired state.
2374 This function checks the state of the spin lock specified by SpinLock. If
2375 SpinLock is in the released state, then this function places SpinLock in the
2376 acquired state and returns SpinLock. Otherwise, this function waits
2377 indefinitely for the spin lock to be released, and then places it in the
2378 acquired state and returns SpinLock. All state transitions of SpinLock must
2379 be performed using MP safe mechanisms.
2381 If SpinLock is NULL, then ASSERT().
2382 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2383 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2384 PcdSpinLockTimeout microseconds, then ASSERT().
2386 @param SpinLock A pointer to the spin lock to place in the acquired state.
2394 IN SPIN_LOCK
*SpinLock
2398 Attempts to place a spin lock in the acquired state.
2400 This function checks the state of the spin lock specified by SpinLock. If
2401 SpinLock is in the released state, then this function places SpinLock in the
2402 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2403 transitions of SpinLock must be performed using MP safe mechanisms.
2405 If SpinLock is NULL, then ASSERT().
2406 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2408 @param SpinLock A pointer to the spin lock to place in the acquired state.
2410 @retval TRUE SpinLock was placed in the acquired state.
2411 @retval FALSE SpinLock could not be acquired.
2416 AcquireSpinLockOrFail (
2417 IN SPIN_LOCK
*SpinLock
2421 Releases a spin lock.
2423 This function places the spin lock specified by SpinLock in the release state
2424 and returns SpinLock.
2426 If SpinLock is NULL, then ASSERT().
2427 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2429 @param SpinLock A pointer to the spin lock to release.
2437 IN SPIN_LOCK
*SpinLock
2441 Performs an atomic increment of an 32-bit unsigned integer.
2443 Performs an atomic increment of the 32-bit unsigned integer specified by
2444 Value and returns the incremented value. The increment operation must be
2445 performed using MP safe mechanisms. The state of the return value is not
2446 guaranteed to be MP safe.
2448 If Value is NULL, then ASSERT().
2450 @param Value A pointer to the 32-bit value to increment.
2452 @return The incremented value.
2457 InterlockedIncrement (
2462 Performs an atomic decrement of an 32-bit unsigned integer.
2464 Performs an atomic decrement of the 32-bit unsigned integer specified by
2465 Value and returns the decremented value. The decrement operation must be
2466 performed using MP safe mechanisms. The state of the return value is not
2467 guaranteed to be MP safe.
2469 If Value is NULL, then ASSERT().
2471 @param Value A pointer to the 32-bit value to decrement.
2473 @return The decremented value.
2478 InterlockedDecrement (
2483 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
2485 Performs an atomic compare exchange operation on the 32-bit unsigned integer
2486 specified by Value. If Value is equal to CompareValue, then Value is set to
2487 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
2488 then Value is returned. The compare exchange operation must be performed using
2491 If Value is NULL, then ASSERT().
2493 @param Value A pointer to the 32-bit value for the compare exchange
2495 @param CompareValue 32-bit value used in compare operation.
2496 @param ExchangeValue 32-bit value used in exchange operation.
2498 @return The original *Value before exchange.
2503 InterlockedCompareExchange32 (
2504 IN OUT UINT32
*Value
,
2505 IN UINT32 CompareValue
,
2506 IN UINT32 ExchangeValue
2510 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
2512 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
2513 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
2514 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
2515 The compare exchange operation must be performed using MP safe mechanisms.
2517 If Value is NULL, then ASSERT().
2519 @param Value A pointer to the 64-bit value for the compare exchange
2521 @param CompareValue 64-bit value used in compare operation.
2522 @param ExchangeValue 64-bit value used in exchange operation.
2524 @return The original *Value before exchange.
2529 InterlockedCompareExchange64 (
2530 IN OUT UINT64
*Value
,
2531 IN UINT64 CompareValue
,
2532 IN UINT64 ExchangeValue
2536 Performs an atomic compare exchange operation on a pointer value.
2538 Performs an atomic compare exchange operation on the pointer value specified
2539 by Value. If Value is equal to CompareValue, then Value is set to
2540 ExchangeValue and CompareValue is returned. If Value is not equal to
2541 CompareValue, then Value is returned. The compare exchange operation must be
2542 performed using MP safe mechanisms.
2544 If Value is NULL, then ASSERT().
2546 @param Value A pointer to the pointer value for the compare exchange
2548 @param CompareValue Pointer value used in compare operation.
2549 @param ExchangeValue Pointer value used in exchange operation.
2554 InterlockedCompareExchangePointer (
2555 IN OUT VOID
**Value
,
2556 IN VOID
*CompareValue
,
2557 IN VOID
*ExchangeValue
2561 // Base Library CPU Functions
2565 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
2566 IN VOID
*Context1
, OPTIONAL
2567 IN VOID
*Context2 OPTIONAL
2571 Used to serialize load and store operations.
2573 All loads and stores that proceed calls to this function are guaranteed to be
2574 globally visible when this function returns.
2584 Saves the current CPU context that can be restored with a call to LongJump()
2587 Saves the current CPU context in the buffer specified by JumpBuffer and
2588 returns 0. The initial call to SetJump() must always return 0. Subsequent
2589 calls to LongJump() cause a non-zero value to be returned by SetJump().
2591 If JumpBuffer is NULL, then ASSERT().
2592 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2594 @param JumpBuffer A pointer to CPU context buffer.
2596 @retval 0 Indicates a return from SetJump().
2602 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
2606 Restores the CPU context that was saved with SetJump().
2608 Restores the CPU context from the buffer specified by JumpBuffer. This
2609 function never returns to the caller. Instead is resumes execution based on
2610 the state of JumpBuffer.
2612 If JumpBuffer is NULL, then ASSERT().
2613 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2614 If Value is 0, then ASSERT().
2616 @param JumpBuffer A pointer to CPU context buffer.
2617 @param Value The value to return when the SetJump() context is
2618 restored and must be non-zero.
2624 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
2629 Enables CPU interrupts.
2631 Enables CPU interrupts.
2641 Disables CPU interrupts.
2643 Disables CPU interrupts.
2653 Disables CPU interrupts and returns the interrupt state prior to the disable
2656 Disables CPU interrupts and returns the interrupt state prior to the disable
2659 @retval TRUE CPU interrupts were enabled on entry to this call.
2660 @retval FALSE CPU interrupts were disabled on entry to this call.
2665 SaveAndDisableInterrupts (
2670 Enables CPU interrupts for the smallest window required to capture any
2673 Enables CPU interrupts for the smallest window required to capture any
2679 EnableDisableInterrupts (
2684 Retrieves the current CPU interrupt state.
2686 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
2687 currently enabled. Otherwise returns FALSE.
2689 @retval TRUE CPU interrupts are enabled.
2690 @retval FALSE CPU interrupts are disabled.
2700 Set the current CPU interrupt state.
2702 Sets the current CPU interrupt state to the state specified by
2703 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
2704 InterruptState is FALSE, then interrupts are disabled. InterruptState is
2707 @param InterruptState TRUE if interrupts should enabled. FALSE if
2708 interrupts should be disabled.
2710 @return InterruptState
2716 IN BOOLEAN InterruptState
2720 Places the CPU in a sleep state until an interrupt is received.
2722 Places the CPU in a sleep state until an interrupt is received. If interrupts
2723 are disabled prior to calling this function, then the CPU will be placed in a
2724 sleep state indefinitely.
2734 Requests CPU to pause for a short period of time.
2736 Requests CPU to pause for a short period of time. Typically used in MP
2737 systems to prevent memory starvation while waiting for a spin lock.
2747 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2749 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2759 Transfers control to a function starting with a new stack.
2761 Transfers control to the function specified by EntryPoint using the new stack
2762 specified by NewStack and passing in the parameters specified by Context1 and
2763 Context2. Context1 and Context2 are optional and may be NULL. The function
2764 EntryPoint must never return.
2766 If EntryPoint is NULL, then ASSERT().
2767 If NewStack is NULL, then ASSERT().
2769 @param EntryPoint A pointer to function to call with the new stack.
2770 @param Context1 A pointer to the context to pass into the EntryPoint
2772 @param Context2 A pointer to the context to pass into the EntryPoint
2774 @param NewStack A pointer to the new stack to use for the EntryPoint
2781 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
2782 IN VOID
*Context1
, OPTIONAL
2783 IN VOID
*Context2
, OPTIONAL
2788 Generates a breakpoint on the CPU.
2790 Generates a breakpoint on the CPU. The breakpoint must be implemented such
2791 that code can resume normal execution after the breakpoint.
2801 Executes an infinite loop.
2803 Forces the CPU to execute an infinite loop. A debugger may be used to skip
2804 past the loop and the code that follows the loop must execute properly. This
2805 implies that the infinite loop must not cause the code that follow it to be
2816 // IA32 and X64 Specific Functions
2819 // Byte packed structure for 16-bit Real Mode EFLAGS
2823 UINT32 CF
:1; // Carry Flag
2824 UINT32 Reserved_0
:1; // Reserved
2825 UINT32 PF
:1; // Parity Flag
2826 UINT32 Reserved_1
:1; // Reserved
2827 UINT32 AF
:1; // Auxiliary Carry Flag
2828 UINT32 Reserved_2
:1; // Reserved
2829 UINT32 ZF
:1; // Zero Flag
2830 UINT32 SF
:1; // Sign Flag
2831 UINT32 TF
:1; // Trap Flag
2832 UINT32 IF
:1; // Interrupt Enable Flag
2833 UINT32 DF
:1; // Direction Flag
2834 UINT32 OF
:1; // Overflow Flag
2835 UINT32 IOPL
:2; // I/O Privilege Level
2836 UINT32 NT
:1; // Nested Task
2837 UINT32 Reserved_3
:1; // Reserved
2843 // Byte packed structure for EFLAGS/RFLAGS
2845 // 64-bits on X64. The upper 32-bits on X64 are reserved
2849 UINT32 CF
:1; // Carry Flag
2850 UINT32 Reserved_0
:1; // Reserved
2851 UINT32 PF
:1; // Parity Flag
2852 UINT32 Reserved_1
:1; // Reserved
2853 UINT32 AF
:1; // Auxiliary Carry Flag
2854 UINT32 Reserved_2
:1; // Reserved
2855 UINT32 ZF
:1; // Zero Flag
2856 UINT32 SF
:1; // Sign Flag
2857 UINT32 TF
:1; // Trap Flag
2858 UINT32 IF
:1; // Interrupt Enable Flag
2859 UINT32 DF
:1; // Direction Flag
2860 UINT32 OF
:1; // Overflow Flag
2861 UINT32 IOPL
:2; // I/O Privilege Level
2862 UINT32 NT
:1; // Nested Task
2863 UINT32 Reserved_3
:1; // Reserved
2864 UINT32 RF
:1; // Resume Flag
2865 UINT32 VM
:1; // Virtual 8086 Mode
2866 UINT32 AC
:1; // Alignment Check
2867 UINT32 VIF
:1; // Virtual Interrupt Flag
2868 UINT32 VIP
:1; // Virtual Interrupt Pending
2869 UINT32 ID
:1; // ID Flag
2870 UINT32 Reserved_4
:10; // Reserved
2876 // Byte packed structure for Control Register 0 (CR0)
2878 // 64-bits on X64. The upper 32-bits on X64 are reserved
2882 UINT32 PE
:1; // Protection Enable
2883 UINT32 MP
:1; // Monitor Coprocessor
2884 UINT32 EM
:1; // Emulation
2885 UINT32 TS
:1; // Task Switched
2886 UINT32 ET
:1; // Extension Type
2887 UINT32 NE
:1; // Numeric Error
2888 UINT32 Reserved_0
:10; // Reserved
2889 UINT32 WP
:1; // Write Protect
2890 UINT32 Reserved_1
:1; // Reserved
2891 UINT32 AM
:1; // Alignment Mask
2892 UINT32 Reserved_2
:10; // Reserved
2893 UINT32 NW
:1; // Mot Write-through
2894 UINT32 CD
:1; // Cache Disable
2895 UINT32 PG
:1; // Paging
2901 // Byte packed structure for Control Register 4 (CR4)
2903 // 64-bits on X64. The upper 32-bits on X64 are reserved
2907 UINT32 VME
:1; // Virtual-8086 Mode Extensions
2908 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
2909 UINT32 TSD
:1; // Time Stamp Disable
2910 UINT32 DE
:1; // Debugging Extensions
2911 UINT32 PSE
:1; // Page Size Extensions
2912 UINT32 PAE
:1; // Physical Address Extension
2913 UINT32 MCE
:1; // Machine Check Enable
2914 UINT32 PGE
:1; // Page Global Enable
2915 UINT32 PCE
:1; // Performance Monitoring Counter
2917 UINT32 OSFXSR
:1; // Operating System Support for
2918 // FXSAVE and FXRSTOR instructions
2919 UINT32 OSXMMEXCPT
:1; // Operating System Support for
2920 // Unmasked SIMD Floating Point
2922 UINT32 Reserved_0
:2; // Reserved
2923 UINT32 VMXE
:1; // VMX Enable
2924 UINT32 Reserved_1
:18; // Reseved
2930 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
2931 /// @bug How to make this structure byte-packed in a compiler independent way?
2940 #define IA32_IDT_GATE_TYPE_TASK 0x85
2941 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
2942 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
2943 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
2944 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
2947 // Byte packed structure for an Interrupt Gate Descriptor
2951 UINT32 OffsetLow
:16; // Offset bits 15..0
2952 UINT32 Selector
:16; // Selector
2953 UINT32 Reserved_0
:8; // Reserved
2954 UINT32 GateType
:8; // Gate Type. See #defines above
2955 UINT32 OffsetHigh
:16; // Offset bits 31..16
2958 } IA32_IDT_GATE_DESCRIPTOR
;
2961 // Byte packed structure for an FP/SSE/SSE2 context
2968 // Structures for the 16-bit real mode thunks
3021 IA32_EFLAGS32 EFLAGS
;
3031 } IA32_REGISTER_SET
;
3034 // Byte packed structure for an 16-bit real mode thunks
3037 IA32_REGISTER_SET
*RealModeState
;
3038 VOID
*RealModeBuffer
;
3039 UINT32 RealModeBufferSize
;
3040 UINT32 ThunkAttributes
;
3043 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
3044 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
3045 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3048 Retrieves CPUID information.
3050 Executes the CPUID instruction with EAX set to the value specified by Index.
3051 This function always returns Index.
3052 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3053 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3054 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3055 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3056 This function is only available on IA-32 and X64.
3058 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3060 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3061 instruction. This is an optional parameter that may be NULL.
3062 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3063 instruction. This is an optional parameter that may be NULL.
3064 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3065 instruction. This is an optional parameter that may be NULL.
3066 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3067 instruction. This is an optional parameter that may be NULL.
3076 OUT UINT32
*Eax
, OPTIONAL
3077 OUT UINT32
*Ebx
, OPTIONAL
3078 OUT UINT32
*Ecx
, OPTIONAL
3079 OUT UINT32
*Edx OPTIONAL
3083 Retrieves CPUID information using an extended leaf identifier.
3085 Executes the CPUID instruction with EAX set to the value specified by Index
3086 and ECX set to the value specified by SubIndex. This function always returns
3087 Index. This function is only available on IA-32 and x64.
3089 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3090 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3091 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3092 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3094 @param Index The 32-bit value to load into EAX prior to invoking the
3096 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3098 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3099 instruction. This is an optional parameter that may be
3101 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3102 instruction. This is an optional parameter that may be
3104 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3105 instruction. This is an optional parameter that may be
3107 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3108 instruction. This is an optional parameter that may be
3119 OUT UINT32
*Eax
, OPTIONAL
3120 OUT UINT32
*Ebx
, OPTIONAL
3121 OUT UINT32
*Ecx
, OPTIONAL
3122 OUT UINT32
*Edx OPTIONAL
3126 Returns the lower 32-bits of a Machine Specific Register(MSR).
3128 Reads and returns the lower 32-bits of the MSR specified by Index.
3129 No parameter checking is performed on Index, and some Index values may cause
3130 CPU exceptions. The caller must either guarantee that Index is valid, or the
3131 caller must set up exception handlers to catch the exceptions. This function
3132 is only available on IA-32 and X64.
3134 @param Index The 32-bit MSR index to read.
3136 @return The lower 32 bits of the MSR identified by Index.
3146 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3148 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3149 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3150 the MSR is returned. No parameter checking is performed on Index or Value,
3151 and some of these may cause CPU exceptions. The caller must either guarantee
3152 that Index and Value are valid, or the caller must establish proper exception
3153 handlers. This function is only available on IA-32 and X64.
3155 @param Index The 32-bit MSR index to write.
3156 @param Value The 32-bit value to write to the MSR.
3169 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3170 writes the result back to the 64-bit MSR.
3172 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3173 between the lower 32-bits of the read result and the value specified by
3174 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3175 32-bits of the value written to the MSR is returned. No parameter checking is
3176 performed on Index or OrData, and some of these may cause CPU exceptions. The
3177 caller must either guarantee that Index and OrData are valid, or the caller
3178 must establish proper exception handlers. This function is only available on
3181 @param Index The 32-bit MSR index to write.
3182 @param OrData The value to OR with the read value from the MSR.
3184 @return The lower 32-bit value written to the MSR.
3195 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3196 the result back to the 64-bit MSR.
3198 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3199 lower 32-bits of the read result and the value specified by AndData, and
3200 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3201 the value written to the MSR is returned. No parameter checking is performed
3202 on Index or AndData, and some of these may cause CPU exceptions. The caller
3203 must either guarantee that Index and AndData are valid, or the caller must
3204 establish proper exception handlers. This function is only available on IA-32
3207 @param Index The 32-bit MSR index to write.
3208 @param AndData The value to AND with the read value from the MSR.
3210 @return The lower 32-bit value written to the MSR.
3221 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3222 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3224 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3225 lower 32-bits of the read result and the value specified by AndData
3226 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3227 result of the AND operation and the value specified by OrData, and writes the
3228 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3229 written to the MSR is returned. No parameter checking is performed on Index,
3230 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3231 must either guarantee that Index, AndData, and OrData are valid, or the
3232 caller must establish proper exception handlers. This function is only
3233 available on IA-32 and X64.
3235 @param Index The 32-bit MSR index to write.
3236 @param AndData The value to AND with the read value from the MSR.
3237 @param OrData The value to OR with the result of the AND operation.
3239 @return The lower 32-bit value written to the MSR.
3251 Reads a bit field of an MSR.
3253 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3254 specified by the StartBit and the EndBit. The value of the bit field is
3255 returned. The caller must either guarantee that Index is valid, or the caller
3256 must set up exception handlers to catch the exceptions. This function is only
3257 available on IA-32 and X64.
3259 If StartBit is greater than 31, then ASSERT().
3260 If EndBit is greater than 31, then ASSERT().
3261 If EndBit is less than StartBit, then ASSERT().
3263 @param Index The 32-bit MSR index to read.
3264 @param StartBit The ordinal of the least significant bit in the bit field.
3266 @param EndBit The ordinal of the most significant bit in the bit field.
3269 @return The bit field read from the MSR.
3274 AsmMsrBitFieldRead32 (
3281 Writes a bit field to an MSR.
3283 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3284 field is specified by the StartBit and the EndBit. All other bits in the
3285 destination MSR are preserved. The lower 32-bits of the MSR written is
3286 returned. Extra left bits in Value are stripped. The caller must either
3287 guarantee that Index and the data written is valid, or the caller must set up
3288 exception handlers to catch the exceptions. This function is only available
3291 If StartBit is greater than 31, then ASSERT().
3292 If EndBit is greater than 31, then ASSERT().
3293 If EndBit is less than StartBit, then ASSERT().
3295 @param Index The 32-bit MSR index to write.
3296 @param StartBit The ordinal of the least significant bit in the bit field.
3298 @param EndBit The ordinal of the most significant bit in the bit field.
3300 @param Value New value of the bit field.
3302 @return The lower 32-bit of the value written to the MSR.
3307 AsmMsrBitFieldWrite32 (
3315 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3316 result back to the bit field in the 64-bit MSR.
3318 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3319 between the read result and the value specified by OrData, and writes the
3320 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3321 written to the MSR are returned. Extra left bits in OrData are stripped. The
3322 caller must either guarantee that Index and the data written is valid, or
3323 the caller must set up exception handlers to catch the exceptions. This
3324 function is only available on IA-32 and X64.
3326 If StartBit is greater than 31, then ASSERT().
3327 If EndBit is greater than 31, then ASSERT().
3328 If EndBit is less than StartBit, then ASSERT().
3330 @param Index The 32-bit MSR index to write.
3331 @param StartBit The ordinal of the least significant bit in the bit field.
3333 @param EndBit The ordinal of the most significant bit in the bit field.
3335 @param OrData The value to OR with the read value from the MSR.
3337 @return The lower 32-bit of the value written to the MSR.
3342 AsmMsrBitFieldOr32 (
3350 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3351 result back to the bit field in the 64-bit MSR.
3353 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3354 read result and the value specified by AndData, and writes the result to the
3355 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3356 MSR are returned. Extra left bits in AndData are stripped. The caller must
3357 either guarantee that Index and the data written is valid, or the caller must
3358 set up exception handlers to catch the exceptions. This function is only
3359 available on IA-32 and X64.
3361 If StartBit is greater than 31, then ASSERT().
3362 If EndBit is greater than 31, then ASSERT().
3363 If EndBit is less than StartBit, then ASSERT().
3365 @param Index The 32-bit MSR index to write.
3366 @param StartBit The ordinal of the least significant bit in the bit field.
3368 @param EndBit The ordinal of the most significant bit in the bit field.
3370 @param AndData The value to AND with the read value from the MSR.
3372 @return The lower 32-bit of the value written to the MSR.
3377 AsmMsrBitFieldAnd32 (
3385 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3386 bitwise inclusive OR, and writes the result back to the bit field in the
3389 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3390 bitwise inclusive OR between the read result and the value specified by
3391 AndData, and writes the result to the 64-bit MSR specified by Index. The
3392 lower 32-bits of the value written to the MSR are returned. Extra left bits
3393 in both AndData and OrData are stripped. The caller must either guarantee
3394 that Index and the data written is valid, or the caller must set up exception
3395 handlers to catch the exceptions. This function is only available on IA-32
3398 If StartBit is greater than 31, then ASSERT().
3399 If EndBit is greater than 31, then ASSERT().
3400 If EndBit is less than StartBit, then ASSERT().
3402 @param Index The 32-bit MSR index to write.
3403 @param StartBit The ordinal of the least significant bit in the bit field.
3405 @param EndBit The ordinal of the most significant bit in the bit field.
3407 @param AndData The value to AND with the read value from the MSR.
3408 @param OrData The value to OR with the result of the AND operation.
3410 @return The lower 32-bit of the value written to the MSR.
3415 AsmMsrBitFieldAndThenOr32 (
3424 Returns a 64-bit Machine Specific Register(MSR).
3426 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3427 performed on Index, and some Index values may cause CPU exceptions. The
3428 caller must either guarantee that Index is valid, or the caller must set up
3429 exception handlers to catch the exceptions. This function is only available
3432 @param Index The 32-bit MSR index to read.
3434 @return The value of the MSR identified by Index.
3444 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3447 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3448 64-bit value written to the MSR is returned. No parameter checking is
3449 performed on Index or Value, and some of these may cause CPU exceptions. The
3450 caller must either guarantee that Index and Value are valid, or the caller
3451 must establish proper exception handlers. This function is only available on
3454 @param Index The 32-bit MSR index to write.
3455 @param Value The 64-bit value to write to the MSR.
3468 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3469 back to the 64-bit MSR.
3471 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3472 between the read result and the value specified by OrData, and writes the
3473 result to the 64-bit MSR specified by Index. The value written to the MSR is
3474 returned. No parameter checking is performed on Index or OrData, and some of
3475 these may cause CPU exceptions. The caller must either guarantee that Index
3476 and OrData are valid, or the caller must establish proper exception handlers.
3477 This function is only available on IA-32 and X64.
3479 @param Index The 32-bit MSR index to write.
3480 @param OrData The value to OR with the read value from the MSR.
3482 @return The value written back to the MSR.
3493 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3496 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3497 read result and the value specified by OrData, and writes the result to the
3498 64-bit MSR specified by Index. The value written to the MSR is returned. No
3499 parameter checking is performed on Index or OrData, and some of these may
3500 cause CPU exceptions. The caller must either guarantee that Index and OrData
3501 are valid, or the caller must establish proper exception handlers. This
3502 function is only available on IA-32 and X64.
3504 @param Index The 32-bit MSR index to write.
3505 @param AndData The value to AND with the read value from the MSR.
3507 @return The value written back to the MSR.
3518 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3519 OR, and writes the result back to the 64-bit MSR.
3521 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3522 result and the value specified by AndData, performs a bitwise inclusive OR
3523 between the result of the AND operation and the value specified by OrData,
3524 and writes the result to the 64-bit MSR specified by Index. The value written
3525 to the MSR is returned. No parameter checking is performed on Index, AndData,
3526 or OrData, and some of these may cause CPU exceptions. The caller must either
3527 guarantee that Index, AndData, and OrData are valid, or the caller must
3528 establish proper exception handlers. This function is only available on IA-32
3531 @param Index The 32-bit MSR index to write.
3532 @param AndData The value to AND with the read value from the MSR.
3533 @param OrData The value to OR with the result of the AND operation.
3535 @return The value written back to the MSR.
3547 Reads a bit field of an MSR.
3549 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3550 StartBit and the EndBit. The value of the bit field is returned. The caller
3551 must either guarantee that Index is valid, or the caller must set up
3552 exception handlers to catch the exceptions. This function is only available
3555 If StartBit is greater than 63, then ASSERT().
3556 If EndBit is greater than 63, then ASSERT().
3557 If EndBit is less than StartBit, then ASSERT().
3559 @param Index The 32-bit MSR index to read.
3560 @param StartBit The ordinal of the least significant bit in the bit field.
3562 @param EndBit The ordinal of the most significant bit in the bit field.
3565 @return The value read from the MSR.
3570 AsmMsrBitFieldRead64 (
3577 Writes a bit field to an MSR.
3579 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3580 the StartBit and the EndBit. All other bits in the destination MSR are
3581 preserved. The MSR written is returned. Extra left bits in Value are
3582 stripped. The caller must either guarantee that Index and the data written is
3583 valid, or the caller must set up exception handlers to catch the exceptions.
3584 This function is only available on IA-32 and X64.
3586 If StartBit is greater than 63, then ASSERT().
3587 If EndBit is greater than 63, then ASSERT().
3588 If EndBit is less than StartBit, then ASSERT().
3590 @param Index The 32-bit MSR index to write.
3591 @param StartBit The ordinal of the least significant bit in the bit field.
3593 @param EndBit The ordinal of the most significant bit in the bit field.
3595 @param Value New value of the bit field.
3597 @return The value written back to the MSR.
3602 AsmMsrBitFieldWrite64 (
3610 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3611 writes the result back to the bit field in the 64-bit MSR.
3613 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3614 between the read result and the value specified by OrData, and writes the
3615 result to the 64-bit MSR specified by Index. The value written to the MSR is
3616 returned. Extra left bits in OrData are stripped. The caller must either
3617 guarantee that Index and the data written is valid, or the caller must set up
3618 exception handlers to catch the exceptions. This function is only available
3621 If StartBit is greater than 63, then ASSERT().
3622 If EndBit is greater than 63, then ASSERT().
3623 If EndBit is less than StartBit, then ASSERT().
3625 @param Index The 32-bit MSR index to write.
3626 @param StartBit The ordinal of the least significant bit in the bit field.
3628 @param EndBit The ordinal of the most significant bit in the bit field.
3630 @param OrData The value to OR with the read value from the bit field.
3632 @return The value written back to the MSR.
3637 AsmMsrBitFieldOr64 (
3645 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3646 result back to the bit field in the 64-bit MSR.
3648 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3649 read result and the value specified by AndData, and writes the result to the
3650 64-bit MSR specified by Index. The value written to the MSR is returned.
3651 Extra left bits in AndData are stripped. The caller must either guarantee
3652 that Index and the data written is valid, or the caller must set up exception
3653 handlers to catch the exceptions. This function is only available on IA-32
3656 If StartBit is greater than 63, then ASSERT().
3657 If EndBit is greater than 63, then ASSERT().
3658 If EndBit is less than StartBit, then ASSERT().
3660 @param Index The 32-bit MSR index to write.
3661 @param StartBit The ordinal of the least significant bit in the bit field.
3663 @param EndBit The ordinal of the most significant bit in the bit field.
3665 @param AndData The value to AND with the read value from the bit field.
3667 @return The value written back to the MSR.
3672 AsmMsrBitFieldAnd64 (
3680 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3681 bitwise inclusive OR, and writes the result back to the bit field in the
3684 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3685 a bitwise inclusive OR between the read result and the value specified by
3686 AndData, and writes the result to the 64-bit MSR specified by Index. The
3687 value written to the MSR is returned. Extra left bits in both AndData and
3688 OrData are stripped. The caller must either guarantee that Index and the data
3689 written is valid, or the caller must set up exception handlers to catch the
3690 exceptions. This function is only available on IA-32 and X64.
3692 If StartBit is greater than 63, then ASSERT().
3693 If EndBit is greater than 63, then ASSERT().
3694 If EndBit is less than StartBit, then ASSERT().
3696 @param Index The 32-bit MSR index to write.
3697 @param StartBit The ordinal of the least significant bit in the bit field.
3699 @param EndBit The ordinal of the most significant bit in the bit field.
3701 @param AndData The value to AND with the read value from the bit field.
3702 @param OrData The value to OR with the result of the AND operation.
3704 @return The value written back to the MSR.
3709 AsmMsrBitFieldAndThenOr64 (
3718 Reads the current value of the EFLAGS register.
3720 Reads and returns the current value of the EFLAGS register. This function is
3721 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3722 64-bit value on X64.
3724 @return EFLAGS on IA-32 or RFLAGS on X64.
3734 Reads the current value of the Control Register 0 (CR0).
3736 Reads and returns the current value of CR0. This function is only available
3737 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3740 @return The value of the Control Register 0 (CR0).
3750 Reads the current value of the Control Register 2 (CR2).
3752 Reads and returns the current value of CR2. This function is only available
3753 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3756 @return The value of the Control Register 2 (CR2).
3766 Reads the current value of the Control Register 3 (CR3).
3768 Reads and returns the current value of CR3. This function is only available
3769 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3772 @return The value of the Control Register 3 (CR3).
3782 Reads the current value of the Control Register 4 (CR4).
3784 Reads and returns the current value of CR4. This function is only available
3785 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3788 @return The value of the Control Register 4 (CR4).
3798 Writes a value to Control Register 0 (CR0).
3800 Writes and returns a new value to CR0. This function is only available on
3801 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3803 @param Cr0 The value to write to CR0.
3805 @return The value written to CR0.
3815 Writes a value to Control Register 2 (CR2).
3817 Writes and returns a new value to CR2. This function is only available on
3818 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3820 @param Cr2 The value to write to CR2.
3822 @return The value written to CR2.
3832 Writes a value to Control Register 3 (CR3).
3834 Writes and returns a new value to CR3. This function is only available on
3835 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3837 @param Cr3 The value to write to CR3.
3839 @return The value written to CR3.
3849 Writes a value to Control Register 4 (CR4).
3851 Writes and returns a new value to CR4. This function is only available on
3852 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3854 @param Cr4 The value to write to CR4.
3856 @return The value written to CR4.
3866 Reads the current value of Debug Register 0 (DR0).
3868 Reads and returns the current value of DR0. This function is only available
3869 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3872 @return The value of Debug Register 0 (DR0).
3882 Reads the current value of Debug Register 1 (DR1).
3884 Reads and returns the current value of DR1. This function is only available
3885 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3888 @return The value of Debug Register 1 (DR1).
3898 Reads the current value of Debug Register 2 (DR2).
3900 Reads and returns the current value of DR2. This function is only available
3901 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3904 @return The value of Debug Register 2 (DR2).
3914 Reads the current value of Debug Register 3 (DR3).
3916 Reads and returns the current value of DR3. This function is only available
3917 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3920 @return The value of Debug Register 3 (DR3).
3930 Reads the current value of Debug Register 4 (DR4).
3932 Reads and returns the current value of DR4. This function is only available
3933 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3936 @return The value of Debug Register 4 (DR4).
3946 Reads the current value of Debug Register 5 (DR5).
3948 Reads and returns the current value of DR5. This function is only available
3949 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3952 @return The value of Debug Register 5 (DR5).
3962 Reads the current value of Debug Register 6 (DR6).
3964 Reads and returns the current value of DR6. This function is only available
3965 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3968 @return The value of Debug Register 6 (DR6).
3978 Reads the current value of Debug Register 7 (DR7).
3980 Reads and returns the current value of DR7. This function is only available
3981 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3984 @return The value of Debug Register 7 (DR7).
3994 Writes a value to Debug Register 0 (DR0).
3996 Writes and returns a new value to DR0. This function is only available on
3997 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3999 @param Dr0 The value to write to Dr0.
4001 @return The value written to Debug Register 0 (DR0).
4011 Writes a value to Debug Register 1 (DR1).
4013 Writes and returns a new value to DR1. This function is only available on
4014 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4016 @param Dr1 The value to write to Dr1.
4018 @return The value written to Debug Register 1 (DR1).
4028 Writes a value to Debug Register 2 (DR2).
4030 Writes and returns a new value to DR2. This function is only available on
4031 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4033 @param Dr2 The value to write to Dr2.
4035 @return The value written to Debug Register 2 (DR2).
4045 Writes a value to Debug Register 3 (DR3).
4047 Writes and returns a new value to DR3. This function is only available on
4048 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4050 @param Dr3 The value to write to Dr3.
4052 @return The value written to Debug Register 3 (DR3).
4062 Writes a value to Debug Register 4 (DR4).
4064 Writes and returns a new value to DR4. This function is only available on
4065 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4067 @param Dr4 The value to write to Dr4.
4069 @return The value written to Debug Register 4 (DR4).
4079 Writes a value to Debug Register 5 (DR5).
4081 Writes and returns a new value to DR5. This function is only available on
4082 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4084 @param Dr5 The value to write to Dr5.
4086 @return The value written to Debug Register 5 (DR5).
4096 Writes a value to Debug Register 6 (DR6).
4098 Writes and returns a new value to DR6. This function is only available on
4099 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4101 @param Dr6 The value to write to Dr6.
4103 @return The value written to Debug Register 6 (DR6).
4113 Writes a value to Debug Register 7 (DR7).
4115 Writes and returns a new value to DR7. This function is only available on
4116 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4118 @param Dr7 The value to write to Dr7.
4120 @return The value written to Debug Register 7 (DR7).
4130 Reads the current value of Code Segment Register (CS).
4132 Reads and returns the current value of CS. This function is only available on
4135 @return The current value of CS.
4145 Reads the current value of Data Segment Register (DS).
4147 Reads and returns the current value of DS. This function is only available on
4150 @return The current value of DS.
4160 Reads the current value of Extra Segment Register (ES).
4162 Reads and returns the current value of ES. This function is only available on
4165 @return The current value of ES.
4175 Reads the current value of FS Data Segment Register (FS).
4177 Reads and returns the current value of FS. This function is only available on
4180 @return The current value of FS.
4190 Reads the current value of GS Data Segment Register (GS).
4192 Reads and returns the current value of GS. This function is only available on
4195 @return The current value of GS.
4205 Reads the current value of Stack Segment Register (SS).
4207 Reads and returns the current value of SS. This function is only available on
4210 @return The current value of SS.
4220 Reads the current value of Task Register (TR).
4222 Reads and returns the current value of TR. This function is only available on
4225 @return The current value of TR.
4235 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4237 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4238 function is only available on IA-32 and X64.
4240 If Gdtr is NULL, then ASSERT().
4242 @param Gdtr Pointer to a GDTR descriptor.
4248 OUT IA32_DESCRIPTOR
*Gdtr
4252 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4254 Writes and the current GDTR descriptor specified by Gdtr. This function is
4255 only available on IA-32 and X64.
4257 If Gdtr is NULL, then ASSERT().
4259 @param Gdtr Pointer to a GDTR descriptor.
4265 IN CONST IA32_DESCRIPTOR
*Gdtr
4269 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4271 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4272 function is only available on IA-32 and X64.
4274 If Idtr is NULL, then ASSERT().
4276 @param Idtr Pointer to a IDTR descriptor.
4282 OUT IA32_DESCRIPTOR
*Idtr
4286 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4288 Writes the current IDTR descriptor and returns it in Idtr. This function is
4289 only available on IA-32 and X64.
4291 If Idtr is NULL, then ASSERT().
4293 @param Idtr Pointer to a IDTR descriptor.
4299 IN CONST IA32_DESCRIPTOR
*Idtr
4303 Reads the current Local Descriptor Table Register(LDTR) selector.
4305 Reads and returns the current 16-bit LDTR descriptor value. This function is
4306 only available on IA-32 and X64.
4308 @return The current selector of LDT.
4318 Writes the current Local Descriptor Table Register (GDTR) selector.
4320 Writes and the current LDTR descriptor specified by Ldtr. This function is
4321 only available on IA-32 and X64.
4323 @param Ldtr 16-bit LDTR selector value.
4333 Save the current floating point/SSE/SSE2 context to a buffer.
4335 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4336 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4337 available on IA-32 and X64.
4339 If Buffer is NULL, then ASSERT().
4340 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4342 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4348 OUT IA32_FX_BUFFER
*Buffer
4352 Restores the current floating point/SSE/SSE2 context from a buffer.
4354 Restores the current floating point/SSE/SSE2 state from the buffer specified
4355 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4356 only available on IA-32 and X64.
4358 If Buffer is NULL, then ASSERT().
4359 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4360 If Buffer was not saved with AsmFxSave(), then ASSERT().
4362 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4368 IN CONST IA32_FX_BUFFER
*Buffer
4372 Reads the current value of 64-bit MMX Register #0 (MM0).
4374 Reads and returns the current value of MM0. This function is only available
4377 @return The current value of MM0.
4387 Reads the current value of 64-bit MMX Register #1 (MM1).
4389 Reads and returns the current value of MM1. This function is only available
4392 @return The current value of MM1.
4402 Reads the current value of 64-bit MMX Register #2 (MM2).
4404 Reads and returns the current value of MM2. This function is only available
4407 @return The current value of MM2.
4417 Reads the current value of 64-bit MMX Register #3 (MM3).
4419 Reads and returns the current value of MM3. This function is only available
4422 @return The current value of MM3.
4432 Reads the current value of 64-bit MMX Register #4 (MM4).
4434 Reads and returns the current value of MM4. This function is only available
4437 @return The current value of MM4.
4447 Reads the current value of 64-bit MMX Register #5 (MM5).
4449 Reads and returns the current value of MM5. This function is only available
4452 @return The current value of MM5.
4462 Reads the current value of 64-bit MMX Register #6 (MM6).
4464 Reads and returns the current value of MM6. This function is only available
4467 @return The current value of MM6.
4477 Reads the current value of 64-bit MMX Register #7 (MM7).
4479 Reads and returns the current value of MM7. This function is only available
4482 @return The current value of MM7.
4492 Writes the current value of 64-bit MMX Register #0 (MM0).
4494 Writes the current value of MM0. This function is only available on IA32 and
4497 @param Value The 64-bit value to write to MM0.
4507 Writes the current value of 64-bit MMX Register #1 (MM1).
4509 Writes the current value of MM1. This function is only available on IA32 and
4512 @param Value The 64-bit value to write to MM1.
4522 Writes the current value of 64-bit MMX Register #2 (MM2).
4524 Writes the current value of MM2. This function is only available on IA32 and
4527 @param Value The 64-bit value to write to MM2.
4537 Writes the current value of 64-bit MMX Register #3 (MM3).
4539 Writes the current value of MM3. This function is only available on IA32 and
4542 @param Value The 64-bit value to write to MM3.
4552 Writes the current value of 64-bit MMX Register #4 (MM4).
4554 Writes the current value of MM4. This function is only available on IA32 and
4557 @param Value The 64-bit value to write to MM4.
4567 Writes the current value of 64-bit MMX Register #5 (MM5).
4569 Writes the current value of MM5. This function is only available on IA32 and
4572 @param Value The 64-bit value to write to MM5.
4582 Writes the current value of 64-bit MMX Register #6 (MM6).
4584 Writes the current value of MM6. This function is only available on IA32 and
4587 @param Value The 64-bit value to write to MM6.
4597 Writes the current value of 64-bit MMX Register #7 (MM7).
4599 Writes the current value of MM7. This function is only available on IA32 and
4602 @param Value The 64-bit value to write to MM7.
4612 Reads the current value of Time Stamp Counter (TSC).
4614 Reads and returns the current value of TSC. This function is only available
4617 @return The current value of TSC
4627 Reads the current value of a Performance Counter (PMC).
4629 Reads and returns the current value of performance counter specified by
4630 Index. This function is only available on IA-32 and X64.
4632 @param Index The 32-bit Performance Counter index to read.
4634 @return The value of the PMC specified by Index.
4644 Sets up a monitor buffer that is used by AsmMwait().
4646 Executes a MONITOR instruction with the register state specified by Eax, Ecx
4647 and Edx. Returns Eax. This function is only available on IA-32 and X64.
4649 @param Eax The value to load into EAX or RAX before executing the MONITOR
4651 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4653 @param Edx The value to load into EDX or RDX before executing the MONITOR
4668 Executes an MWAIT instruction.
4670 Executes an MWAIT instruction with the register state specified by Eax and
4671 Ecx. Returns Eax. This function is only available on IA-32 and X64.
4673 @param Eax The value to load into EAX or RAX before executing the MONITOR
4675 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4689 Executes a WBINVD instruction.
4691 Executes a WBINVD instruction. This function is only available on IA-32 and
4702 Executes a INVD instruction.
4704 Executes a INVD instruction. This function is only available on IA-32 and
4715 Flushes a cache line from all the instruction and data caches within the
4716 coherency domain of the CPU.
4718 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
4719 This function is only available on IA-32 and X64.
4721 @param LinearAddress The address of the cache line to flush. If the CPU is
4722 in a physical addressing mode, then LinearAddress is a
4723 physical address. If the CPU is in a virtual
4724 addressing mode, then LinearAddress is a virtual
4727 @return LinearAddress
4732 IN VOID
*LinearAddress
4736 Enables the 32-bit paging mode on the CPU.
4738 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4739 must be properly initialized prior to calling this service. This function
4740 assumes the current execution mode is 32-bit protected mode. This function is
4741 only available on IA-32. After the 32-bit paging mode is enabled, control is
4742 transferred to the function specified by EntryPoint using the new stack
4743 specified by NewStack and passing in the parameters specified by Context1 and
4744 Context2. Context1 and Context2 are optional and may be NULL. The function
4745 EntryPoint must never return.
4747 If the current execution mode is not 32-bit protected mode, then ASSERT().
4748 If EntryPoint is NULL, then ASSERT().
4749 If NewStack is NULL, then ASSERT().
4751 There are a number of constraints that must be followed before calling this
4753 1) Interrupts must be disabled.
4754 2) The caller must be in 32-bit protected mode with flat descriptors. This
4755 means all descriptors must have a base of 0 and a limit of 4GB.
4756 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
4758 4) CR3 must point to valid page tables that will be used once the transition
4759 is complete, and those page tables must guarantee that the pages for this
4760 function and the stack are identity mapped.
4762 @param EntryPoint A pointer to function to call with the new stack after
4764 @param Context1 A pointer to the context to pass into the EntryPoint
4765 function as the first parameter after paging is enabled.
4766 @param Context2 A pointer to the context to pass into the EntryPoint
4767 function as the second parameter after paging is enabled.
4768 @param NewStack A pointer to the new stack to use for the EntryPoint
4769 function after paging is enabled.
4775 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4776 IN VOID
*Context1
, OPTIONAL
4777 IN VOID
*Context2
, OPTIONAL
4782 Disables the 32-bit paging mode on the CPU.
4784 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
4785 mode. This function assumes the current execution mode is 32-paged protected
4786 mode. This function is only available on IA-32. After the 32-bit paging mode
4787 is disabled, control is transferred to the function specified by EntryPoint
4788 using the new stack specified by NewStack and passing in the parameters
4789 specified by Context1 and Context2. Context1 and Context2 are optional and
4790 may be NULL. The function EntryPoint must never return.
4792 If the current execution mode is not 32-bit paged mode, then ASSERT().
4793 If EntryPoint is NULL, then ASSERT().
4794 If NewStack is NULL, then ASSERT().
4796 There are a number of constraints that must be followed before calling this
4798 1) Interrupts must be disabled.
4799 2) The caller must be in 32-bit paged mode.
4800 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
4801 4) CR3 must point to valid page tables that guarantee that the pages for
4802 this function and the stack are identity mapped.
4804 @param EntryPoint A pointer to function to call with the new stack after
4806 @param Context1 A pointer to the context to pass into the EntryPoint
4807 function as the first parameter after paging is disabled.
4808 @param Context2 A pointer to the context to pass into the EntryPoint
4809 function as the second parameter after paging is
4811 @param NewStack A pointer to the new stack to use for the EntryPoint
4812 function after paging is disabled.
4817 AsmDisablePaging32 (
4818 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4819 IN VOID
*Context1
, OPTIONAL
4820 IN VOID
*Context2
, OPTIONAL
4825 Enables the 64-bit paging mode on the CPU.
4827 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4828 must be properly initialized prior to calling this service. This function
4829 assumes the current execution mode is 32-bit protected mode with flat
4830 descriptors. This function is only available on IA-32. After the 64-bit
4831 paging mode is enabled, control is transferred to the function specified by
4832 EntryPoint using the new stack specified by NewStack and passing in the
4833 parameters specified by Context1 and Context2. Context1 and Context2 are
4834 optional and may be 0. The function EntryPoint must never return.
4836 If the current execution mode is not 32-bit protected mode with flat
4837 descriptors, then ASSERT().
4838 If EntryPoint is 0, then ASSERT().
4839 If NewStack is 0, then ASSERT().
4841 @param Cs The 16-bit selector to load in the CS before EntryPoint
4842 is called. The descriptor in the GDT that this selector
4843 references must be setup for long mode.
4844 @param EntryPoint The 64-bit virtual address of the function to call with
4845 the new stack after paging is enabled.
4846 @param Context1 The 64-bit virtual address of the context to pass into
4847 the EntryPoint function as the first parameter after
4849 @param Context2 The 64-bit virtual address of the context to pass into
4850 the EntryPoint function as the second parameter after
4852 @param NewStack The 64-bit virtual address of the new stack to use for
4853 the EntryPoint function after paging is enabled.
4859 IN UINT16 CodeSelector
,
4860 IN UINT64 EntryPoint
,
4861 IN UINT64 Context1
, OPTIONAL
4862 IN UINT64 Context2
, OPTIONAL
4867 Disables the 64-bit paging mode on the CPU.
4869 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
4870 mode. This function assumes the current execution mode is 64-paging mode.
4871 This function is only available on X64. After the 64-bit paging mode is
4872 disabled, control is transferred to the function specified by EntryPoint
4873 using the new stack specified by NewStack and passing in the parameters
4874 specified by Context1 and Context2. Context1 and Context2 are optional and
4875 may be 0. The function EntryPoint must never return.
4877 If the current execution mode is not 64-bit paged mode, then ASSERT().
4878 If EntryPoint is 0, then ASSERT().
4879 If NewStack is 0, then ASSERT().
4881 @param Cs The 16-bit selector to load in the CS before EntryPoint
4882 is called. The descriptor in the GDT that this selector
4883 references must be setup for 32-bit protected mode.
4884 @param EntryPoint The 64-bit virtual address of the function to call with
4885 the new stack after paging is disabled.
4886 @param Context1 The 64-bit virtual address of the context to pass into
4887 the EntryPoint function as the first parameter after
4889 @param Context2 The 64-bit virtual address of the context to pass into
4890 the EntryPoint function as the second parameter after
4892 @param NewStack The 64-bit virtual address of the new stack to use for
4893 the EntryPoint function after paging is disabled.
4898 AsmDisablePaging64 (
4899 IN UINT16 CodeSelector
,
4900 IN UINT32 EntryPoint
,
4901 IN UINT32 Context1
, OPTIONAL
4902 IN UINT32 Context2
, OPTIONAL
4907 // 16-bit thunking services
4911 Retrieves the properties for 16-bit thunk functions.
4913 Computes the size of the buffer and stack below 1MB required to use the
4914 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
4915 buffer size is returned in RealModeBufferSize, and the stack size is returned
4916 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
4917 then the actual minimum stack size is ExtraStackSize plus the maximum number
4918 of bytes that need to be passed to the 16-bit real mode code.
4920 If RealModeBufferSize is NULL, then ASSERT().
4921 If ExtraStackSize is NULL, then ASSERT().
4923 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
4924 required to use the 16-bit thunk functions.
4925 @param ExtraStackSize A pointer to the extra size of stack below 1MB
4926 that the 16-bit thunk functions require for
4927 temporary storage in the transition to and from
4933 AsmGetThunk16Properties (
4934 OUT UINT32
*RealModeBufferSize
,
4935 OUT UINT32
*ExtraStackSize
4939 Prepares all structures a code required to use AsmThunk16().
4941 Prepares all structures and code required to use AsmThunk16().
4943 If ThunkContext is NULL, then ASSERT().
4945 @param ThunkContext A pointer to the context structure that describes the
4946 16-bit real mode code to call.
4952 OUT THUNK_CONTEXT
*ThunkContext
4956 Transfers control to a 16-bit real mode entry point and returns the results.
4958 Transfers control to a 16-bit real mode entry point and returns the results.
4959 AsmPrepareThunk16() must be called with ThunkContext before this function is
4962 If ThunkContext is NULL, then ASSERT().
4963 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
4965 @param ThunkContext A pointer to the context structure that describes the
4966 16-bit real mode code to call.
4972 IN OUT THUNK_CONTEXT
*ThunkContext
4976 Prepares all structures and code for a 16-bit real mode thunk, transfers
4977 control to a 16-bit real mode entry point, and returns the results.
4979 Prepares all structures and code for a 16-bit real mode thunk, transfers
4980 control to a 16-bit real mode entry point, and returns the results. If the
4981 caller only need to perform a single 16-bit real mode thunk, then this
4982 service should be used. If the caller intends to make more than one 16-bit
4983 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
4984 once and AsmThunk16() can be called for each 16-bit real mode thunk.
4986 If ThunkContext is NULL, then ASSERT().
4988 @param ThunkContext A pointer to the context structure that describes the
4989 16-bit real mode code to call.
4994 AsmPrepareAndThunk16 (
4995 IN OUT THUNK_CONTEXT
*ThunkContext
4999 Transfers control to a function starting with a new stack.
5001 Transfers control to the function specified by EntryPoint using the new stack
5002 specified by NewStack and passing in the parameters specified by Context1 and
5003 Context2. Context1 and Context2 are optional and may be NULL. The function
5004 EntryPoint must never return.
5006 If EntryPoint is NULL, then ASSERT().
5007 If NewStack is NULL, then ASSERT().
5009 @param EntryPoint A pointer to function to call with the new stack.
5010 @param Context1 A pointer to the context to pass into the EntryPoint
5012 @param Context2 A pointer to the context to pass into the EntryPoint
5014 @param NewStack A pointer to the new stack to use for the EntryPoint
5016 @param NewBsp A pointer to the new memory location for RSE backing
5022 AsmSwitchStackAndBackingStore (
5023 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
5024 IN VOID
*Context1
, OPTIONAL
5025 IN VOID
*Context2
, OPTIONAL
5038 // IPF Specific functions
5043 Performs a PAL call using static calling convention.
5045 An internal function to perform a PAL call using static calling convention.
5047 @param PalEntryPoint The entry point address of PAL. The address in ar.kr5
5048 would be used if this parameter were NULL on input.
5049 @param Arg1 The first argument of a PAL call.
5050 @param Arg1 The second argument of a PAL call.
5051 @param Arg1 The third argument of a PAL call.
5052 @param Arg1 The fourth argument of a PAL call.
5054 @return The values returned in r8, r9, r10 and r11.
5059 IN CONST VOID
*PalEntryPoint
,
5068 Returns the current value of ar.itc.
5070 An internal function to return the current value of ar.itc, which is the
5073 @return The currect value of ar.itc
5083 Flush a range of cache lines in the cache coherency domain of the calling
5086 Invalidates the cache lines specified by Address and Length. If Address is
5087 not aligned on a cache line boundary, then entire cache line containing
5088 Address is invalidated. If Address + Length is not aligned on a cache line
5089 boundary, then the entire instruction cache line containing Address + Length
5090 -1 is invalidated. This function may choose to invalidate the entire
5091 instruction cache if that is more efficient than invalidating the specified
5092 range. If Length is 0, the no instruction cache lines are invalidated.
5093 Address is returned.
5095 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
5097 @param Address The base address of the instruction lines to invalidate. If
5098 the CPU is in a physical addressing mode, then Address is a
5099 physical address. If the CPU is in a virtual addressing mode,
5100 then Address is a virtual address.
5102 @param Length The number of bytes to invalidate from the instruction cache.
5109 IpfFlushCacheRange (