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 // Linked List Functions and Macros
704 Initializes the head node of a doubly linked list that is declared as a
705 global variable in a module.
707 Initializes the forward and backward links of a new linked list. After
708 initializing a linked list with this macro, the other linked list functions
709 may be used to add and remove nodes from the linked list. This macro results
710 in smaller executables by initializing the linked list in the data section,
711 instead if calling the InitializeListHead() function to perform the
712 equivalent operation.
714 @param ListHead The head note of a list to initiailize.
717 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
720 Initializes the head node of a doubly linked list, and returns the pointer to
721 the head node of the doubly linked list.
723 Initializes the forward and backward links of a new linked list. After
724 initializing a linked list with this function, the other linked list
725 functions may be used to add and remove nodes from the linked list. It is up
726 to the caller of this function to allocate the memory for ListHead.
728 If ListHead is NULL, then ASSERT().
730 @param ListHead A pointer to the head node of a new doubly linked list.
738 IN LIST_ENTRY
*ListHead
742 Adds a node to the beginning of a doubly linked list, and returns the pointer
743 to the head node of the doubly linked list.
745 Adds the node Entry at the beginning of the doubly linked list denoted by
746 ListHead, and returns ListHead.
748 If ListHead is NULL, then ASSERT().
749 If Entry is NULL, then ASSERT().
750 If ListHead was not initialized with InitializeListHead(), then ASSERT().
751 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
752 of nodes in ListHead, including the ListHead node, is greater than or
753 equal to PcdMaximumLinkedListLength, then ASSERT().
755 @param ListHead A pointer to the head node of a doubly linked list.
756 @param Entry A pointer to a node that is to be inserted at the beginning
757 of a doubly linked list.
765 IN LIST_ENTRY
*ListHead
,
770 Adds a node to the end of a doubly linked list, and returns the pointer to
771 the head node of the doubly linked list.
773 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
774 and returns ListHead.
776 If ListHead is NULL, then ASSERT().
777 If Entry is NULL, then ASSERT().
778 If ListHead was not initialized with InitializeListHead(), then ASSERT().
779 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
780 of nodes in ListHead, including the ListHead node, is greater than or
781 equal to PcdMaximumLinkedListLength, then ASSERT().
783 @param ListHead A pointer to the head node of a doubly linked list.
784 @param Entry A pointer to a node that is to be added at the end of the
793 IN LIST_ENTRY
*ListHead
,
798 Retrieves the first node of a doubly linked list.
800 Returns the first node of a doubly linked list. List must have been
801 initialized with InitializeListHead(). If List is empty, then NULL is
804 If List is NULL, then ASSERT().
805 If List was not initialized with InitializeListHead(), then ASSERT().
806 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
807 in List, including the List node, is greater than or equal to
808 PcdMaximumLinkedListLength, then ASSERT().
810 @param List A pointer to the head node of a doubly linked list.
812 @return The first node of a doubly linked list.
813 @retval NULL The list is empty.
819 IN CONST LIST_ENTRY
*List
823 Retrieves the next node of a doubly linked list.
825 Returns the node of a doubly linked list that follows Node. List must have
826 been initialized with InitializeListHead(). If List is empty, then List is
829 If List is NULL, then ASSERT().
830 If Node is NULL, then ASSERT().
831 If List was not initialized with InitializeListHead(), then ASSERT().
832 If PcdMaximumLinkedListLenth is not zero, and List contains more than
833 PcdMaximumLinkedListLenth nodes, then ASSERT().
834 If Node is not a node in List, then ASSERT().
836 @param List A pointer to the head node of a doubly linked list.
837 @param Node A pointer to a node in the doubly linked list.
839 @return Pointer to the next node if one exists. Otherwise a null value which
840 is actually List is returned.
846 IN CONST LIST_ENTRY
*List
,
847 IN CONST LIST_ENTRY
*Node
851 Checks to see if a doubly linked list is empty or not.
853 Checks to see if the doubly linked list is empty. If the linked list contains
854 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
856 If ListHead is NULL, then ASSERT().
857 If ListHead was not initialized with InitializeListHead(), then ASSERT().
858 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
859 in List, including the List node, is greater than or equal to
860 PcdMaximumLinkedListLength, then ASSERT().
862 @param ListHead A pointer to the head node of a doubly linked list.
864 @retval TRUE The linked list is empty.
865 @retval FALSE The linked list is not empty.
871 IN CONST LIST_ENTRY
*ListHead
875 Determines if a node in a doubly linked list is null.
877 Returns FALSE if Node is one of the nodes in the doubly linked list specified
878 by List. Otherwise, TRUE is returned. List must have been initialized with
879 InitializeListHead().
881 If List is NULL, then ASSERT().
882 If Node is NULL, then ASSERT().
883 If List was not initialized with InitializeListHead(), then ASSERT().
884 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
885 in List, including the List node, is greater than or equal to
886 PcdMaximumLinkedListLength, then ASSERT().
887 If Node is not a node in List and Node is not equal to List, then ASSERT().
889 @param List A pointer to the head node of a doubly linked list.
890 @param Node A pointer to a node in the doubly linked list.
892 @retval TRUE Node is one of the nodes in the doubly linked list.
893 @retval FALSE Node is not one of the nodes in the doubly linked list.
899 IN CONST LIST_ENTRY
*List
,
900 IN CONST LIST_ENTRY
*Node
904 Determines if a node the last node in a doubly linked list.
906 Returns TRUE if Node is the last node in the doubly linked list specified by
907 List. Otherwise, FALSE is returned. List must have been initialized with
908 InitializeListHead().
910 If List is NULL, then ASSERT().
911 If Node is NULL, then ASSERT().
912 If List was not initialized with InitializeListHead(), then ASSERT().
913 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
914 in List, including the List node, is greater than or equal to
915 PcdMaximumLinkedListLength, then ASSERT().
916 If Node is not a node in List, then ASSERT().
918 @param List A pointer to the head node of a doubly linked list.
919 @param Node A pointer to a node in the doubly linked list.
921 @retval TRUE Node is the last node in the linked list.
922 @retval FALSE Node is not the last node in the linked list.
928 IN CONST LIST_ENTRY
*List
,
929 IN CONST LIST_ENTRY
*Node
933 Swaps the location of two nodes in a doubly linked list, and returns the
934 first node after the swap.
936 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
937 Otherwise, the location of the FirstEntry node is swapped with the location
938 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
939 same double linked list as FirstEntry and that double linked list must have
940 been initialized with InitializeListHead(). SecondEntry is returned after the
943 If FirstEntry is NULL, then ASSERT().
944 If SecondEntry is NULL, then ASSERT().
945 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
946 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
947 linked list containing the FirstEntry and SecondEntry nodes, including
948 the FirstEntry and SecondEntry nodes, is greater than or equal to
949 PcdMaximumLinkedListLength, then ASSERT().
951 @param FirstEntry A pointer to a node in a linked list.
952 @param SecondEntry A pointer to another node in the same linked list.
958 IN LIST_ENTRY
*FirstEntry
,
959 IN LIST_ENTRY
*SecondEntry
963 Removes a node from a doubly linked list, and returns the node that follows
966 Removes the node Entry from a doubly linked list. It is up to the caller of
967 this function to release the memory used by this node if that is required. On
968 exit, the node following Entry in the doubly linked list is returned. If
969 Entry is the only node in the linked list, then the head node of the linked
972 If Entry is NULL, then ASSERT().
973 If Entry is the head node of an empty list, then ASSERT().
974 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
975 linked list containing Entry, including the Entry node, is greater than
976 or equal to PcdMaximumLinkedListLength, then ASSERT().
978 @param Entry A pointer to a node in a linked list
986 IN CONST LIST_ENTRY
*Entry
994 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
995 with zeros. The shifted value is returned.
997 This function shifts the 64-bit value Operand to the left by Count bits. The
998 low Count bits are set to zero. The shifted value is returned.
1000 If Count is greater than 63, then ASSERT().
1002 @param Operand The 64-bit operand to shift left.
1003 @param Count The number of bits to shift left.
1005 @return Operand << Count
1016 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1017 filled with zeros. The shifted value is returned.
1019 This function shifts the 64-bit value Operand to the right by Count bits. The
1020 high Count bits are set to zero. The shifted value is returned.
1022 If Count is greater than 63, then ASSERT().
1024 @param Operand The 64-bit operand to shift right.
1025 @param Count The number of bits to shift right.
1027 @return Operand >> Count
1038 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1039 with original integer's bit 63. The shifted value is returned.
1041 This function shifts the 64-bit value Operand to the right by Count bits. The
1042 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1044 If Count is greater than 63, then ASSERT().
1046 @param Operand The 64-bit operand to shift right.
1047 @param Count The number of bits to shift right.
1049 @return Operand >> Count
1060 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1061 with the high bits that were rotated.
1063 This function rotates the 32-bit value Operand to the left by Count bits. The
1064 low Count bits are fill with the high Count bits of Operand. The rotated
1067 If Count is greater than 31, then ASSERT().
1069 @param Operand The 32-bit operand to rotate left.
1070 @param Count The number of bits to rotate left.
1072 @return Operand <<< Count
1083 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1084 with the low bits that were rotated.
1086 This function rotates the 32-bit value Operand to the right by Count bits.
1087 The high Count bits are fill with the low Count bits of Operand. The rotated
1090 If Count is greater than 31, then ASSERT().
1092 @param Operand The 32-bit operand to rotate right.
1093 @param Count The number of bits to rotate right.
1095 @return Operand >>> Count
1106 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1107 with the high bits that were rotated.
1109 This function rotates the 64-bit value Operand to the left by Count bits. The
1110 low Count bits are fill with the high Count bits of Operand. The rotated
1113 If Count is greater than 63, then ASSERT().
1115 @param Operand The 64-bit operand to rotate left.
1116 @param Count The number of bits to rotate left.
1118 @return Operand <<< Count
1129 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1130 with the high low bits that were rotated.
1132 This function rotates the 64-bit value Operand to the right by Count bits.
1133 The high Count bits are fill with the low Count bits of Operand. The rotated
1136 If Count is greater than 63, then ASSERT().
1138 @param Operand The 64-bit operand to rotate right.
1139 @param Count The number of bits to rotate right.
1141 @return Operand >>> Count
1152 Returns the bit position of the lowest bit set in a 32-bit value.
1154 This function computes the bit position of the lowest bit set in the 32-bit
1155 value specified by Operand. If Operand is zero, then -1 is returned.
1156 Otherwise, a value between 0 and 31 is returned.
1158 @param Operand The 32-bit operand to evaluate.
1160 @return Position of the lowest bit set in Operand if found.
1161 @retval -1 Operand is zero.
1171 Returns the bit position of the lowest bit set in a 64-bit value.
1173 This function computes the bit position of the lowest bit set in the 64-bit
1174 value specified by Operand. If Operand is zero, then -1 is returned.
1175 Otherwise, a value between 0 and 63 is returned.
1177 @param Operand The 64-bit operand to evaluate.
1179 @return Position of the lowest bit set in Operand if found.
1180 @retval -1 Operand is zero.
1190 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1193 This function computes the bit position of the highest bit set in the 32-bit
1194 value specified by Operand. If Operand is zero, then -1 is returned.
1195 Otherwise, a value between 0 and 31 is returned.
1197 @param Operand The 32-bit operand to evaluate.
1199 @return Position of the highest bit set in Operand if found.
1200 @retval -1 Operand is zero.
1210 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1213 This function computes the bit position of the highest bit set in the 64-bit
1214 value specified by Operand. If Operand is zero, then -1 is returned.
1215 Otherwise, a value between 0 and 63 is returned.
1217 @param Operand The 64-bit operand to evaluate.
1219 @return Position of the highest bit set in Operand if found.
1220 @retval -1 Operand is zero.
1230 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1231 1 << HighBitSet32(x).
1233 This function computes the value of the highest bit set in the 32-bit value
1234 specified by Operand. If Operand is zero, then zero is returned.
1236 @param Operand The 32-bit operand to evaluate.
1238 @return 1 << HighBitSet32(Operand)
1239 @retval 0 Operand is zero.
1249 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1250 1 << HighBitSet64(x).
1252 This function computes the value of the highest bit set in the 64-bit value
1253 specified by Operand. If Operand is zero, then zero is returned.
1255 @param Operand The 64-bit operand to evaluate.
1257 @return 1 << HighBitSet64(Operand)
1258 @retval 0 Operand is zero.
1268 Switches the endianess of a 16-bit integer.
1270 This function swaps the bytes in a 16-bit unsigned value to switch the value
1271 from little endian to big endian or vice versa. The byte swapped value is
1274 @param Operand A 16-bit unsigned value.
1276 @return The byte swaped Operand.
1286 Switches the endianess of a 32-bit integer.
1288 This function swaps the bytes in a 32-bit unsigned value to switch the value
1289 from little endian to big endian or vice versa. The byte swapped value is
1292 @param Operand A 32-bit unsigned value.
1294 @return The byte swaped Operand.
1304 Switches the endianess of a 64-bit integer.
1306 This function swaps the bytes in a 64-bit unsigned value to switch the value
1307 from little endian to big endian or vice versa. The byte swapped value is
1310 @param Operand A 64-bit unsigned value.
1312 @return The byte swaped Operand.
1322 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1323 generates a 64-bit unsigned result.
1325 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1326 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1327 bit unsigned result is returned.
1329 If the result overflows, then ASSERT().
1331 @param Multiplicand A 64-bit unsigned value.
1332 @param Multiplier A 32-bit unsigned value.
1334 @return Multiplicand * Multiplier
1340 IN UINT64 Multiplicand
,
1341 IN UINT32 Multiplier
1345 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1346 generates a 64-bit unsigned result.
1348 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1349 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1350 bit unsigned result is returned.
1352 If the result overflows, then ASSERT().
1354 @param Multiplicand A 64-bit unsigned value.
1355 @param Multiplier A 64-bit unsigned value.
1357 @return Multiplicand * Multiplier
1363 IN UINT64 Multiplicand
,
1364 IN UINT64 Multiplier
1368 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1369 64-bit signed result.
1371 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1372 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1373 signed result is returned.
1375 If the result overflows, then ASSERT().
1377 @param Multiplicand A 64-bit signed value.
1378 @param Multiplier A 64-bit signed value.
1380 @return Multiplicand * Multiplier
1386 IN INT64 Multiplicand
,
1391 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1392 a 64-bit unsigned result.
1394 This function divides the 64-bit unsigned value Dividend by the 32-bit
1395 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1396 function returns the 64-bit unsigned quotient.
1398 If Divisor is 0, then ASSERT().
1400 @param Dividend A 64-bit unsigned value.
1401 @param Divisor A 32-bit unsigned value.
1403 @return Dividend / Divisor
1414 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1415 a 32-bit unsigned remainder.
1417 This function divides the 64-bit unsigned value Dividend by the 32-bit
1418 unsigned value Divisor and generates a 32-bit remainder. This function
1419 returns the 32-bit unsigned remainder.
1421 If Divisor is 0, then ASSERT().
1423 @param Dividend A 64-bit unsigned value.
1424 @param Divisor A 32-bit unsigned value.
1426 @return Dividend % Divisor
1437 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1438 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1440 This function divides the 64-bit unsigned value Dividend by the 32-bit
1441 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1442 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1443 This function returns the 64-bit unsigned quotient.
1445 If Divisor is 0, then ASSERT().
1447 @param Dividend A 64-bit unsigned value.
1448 @param Divisor A 32-bit unsigned value.
1449 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1450 optional and may be NULL.
1452 @return Dividend / Divisor
1457 DivU64x32Remainder (
1460 OUT UINT32
*Remainder OPTIONAL
1464 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
1465 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
1467 This function divides the 64-bit unsigned value Dividend by the 64-bit
1468 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1469 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
1470 This function returns the 64-bit unsigned quotient.
1472 If Divisor is 0, then ASSERT().
1474 @param Dividend A 64-bit unsigned value.
1475 @param Divisor A 64-bit unsigned value.
1476 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
1477 optional and may be NULL.
1479 @return Dividend / Divisor
1484 DivU64x64Remainder (
1487 OUT UINT64
*Remainder OPTIONAL
1491 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
1492 64-bit signed result and a optional 64-bit signed remainder.
1494 This function divides the 64-bit signed value Dividend by the 64-bit signed
1495 value Divisor and generates a 64-bit signed quotient. If Remainder is not
1496 NULL, then the 64-bit signed remainder is returned in Remainder. This
1497 function returns the 64-bit signed quotient.
1499 If Divisor is 0, then ASSERT().
1501 @param Dividend A 64-bit signed value.
1502 @param Divisor A 64-bit signed value.
1503 @param Remainder A pointer to a 64-bit signed value. This parameter is
1504 optional and may be NULL.
1506 @return Dividend / Divisor
1511 DivS64x64Remainder (
1514 OUT INT64
*Remainder OPTIONAL
1518 Reads a 16-bit value from memory that may be unaligned.
1520 This function returns the 16-bit value pointed to by Buffer. The function
1521 guarantees that the read operation does not produce an alignment fault.
1523 If the Buffer is NULL, then ASSERT().
1525 @param Buffer Pointer to a 16-bit value that may be unaligned.
1533 IN CONST UINT16
*Uint16
1537 Writes a 16-bit value to memory that may be unaligned.
1539 This function writes the 16-bit value specified by Value to Buffer. Value is
1540 returned. The function guarantees that the write operation does not produce
1543 If the Buffer is NULL, then ASSERT().
1545 @param Buffer Pointer to a 16-bit value that may be unaligned.
1546 @param Value 16-bit value to write to Buffer.
1559 Reads a 24-bit value from memory that may be unaligned.
1561 This function returns the 24-bit value pointed to by Buffer. The function
1562 guarantees that the read operation does not produce an alignment fault.
1564 If the Buffer is NULL, then ASSERT().
1566 @param Buffer Pointer to a 24-bit value that may be unaligned.
1568 @return The value read.
1574 IN CONST UINT32
*Buffer
1578 Writes a 24-bit value to memory that may be unaligned.
1580 This function writes the 24-bit value specified by Value to Buffer. Value is
1581 returned. The function guarantees that the write operation does not produce
1584 If the Buffer is NULL, then ASSERT().
1586 @param Buffer Pointer to a 24-bit value that may be unaligned.
1587 @param Value 24-bit value to write to Buffer.
1589 @return The value written.
1600 Reads a 32-bit value from memory that may be unaligned.
1602 This function returns the 32-bit value pointed to by Buffer. The function
1603 guarantees that the read operation does not produce an alignment fault.
1605 If the Buffer is NULL, then ASSERT().
1607 @param Buffer Pointer to a 32-bit value that may be unaligned.
1615 IN CONST UINT32
*Uint32
1619 Writes a 32-bit value to memory that may be unaligned.
1621 This function writes the 32-bit value specified by Value to Buffer. Value is
1622 returned. The function guarantees that the write operation does not produce
1625 If the Buffer is NULL, then ASSERT().
1627 @param Buffer Pointer to a 32-bit value that may be unaligned.
1628 @param Value 32-bit value to write to Buffer.
1641 Reads a 64-bit value from memory that may be unaligned.
1643 This function returns the 64-bit value pointed to by Buffer. The function
1644 guarantees that the read operation does not produce an alignment fault.
1646 If the Buffer is NULL, then ASSERT().
1648 @param Buffer Pointer to a 64-bit value that may be unaligned.
1656 IN CONST UINT64
*Uint64
1660 Writes a 64-bit value to memory that may be unaligned.
1662 This function writes the 64-bit value specified by Value to Buffer. Value is
1663 returned. The function guarantees that the write operation does not produce
1666 If the Buffer is NULL, then ASSERT().
1668 @param Buffer Pointer to a 64-bit value that may be unaligned.
1669 @param Value 64-bit value to write to Buffer.
1682 // Bit Field Functions
1686 Returns a bit field from an 8-bit value.
1688 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1690 If 8-bit operations are not supported, then ASSERT().
1691 If StartBit is greater than 7, then ASSERT().
1692 If EndBit is greater than 7, then ASSERT().
1693 If EndBit is less than StartBit, then ASSERT().
1695 @param Operand Operand on which to perform the bitfield operation.
1696 @param StartBit The ordinal of the least significant bit in the bit field.
1698 @param EndBit The ordinal of the most significant bit in the bit field.
1701 @return The bit field read.
1713 Writes a bit field to an 8-bit value, and returns the result.
1715 Writes Value to the bit field specified by the StartBit and the EndBit in
1716 Operand. All other bits in Operand are preserved. The new 8-bit value is
1719 If 8-bit operations are not supported, then ASSERT().
1720 If StartBit is greater than 7, then ASSERT().
1721 If EndBit is greater than 7, then ASSERT().
1722 If EndBit is less than StartBit, then ASSERT().
1724 @param Operand Operand on which to perform the bitfield operation.
1725 @param StartBit The ordinal of the least significant bit in the bit field.
1727 @param EndBit The ordinal of the most significant bit in the bit field.
1729 @param Value New value of the bit field.
1731 @return The new 8-bit value.
1744 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
1747 Performs a bitwise inclusive OR between the bit field specified by StartBit
1748 and EndBit in Operand and the value specified by OrData. All other bits in
1749 Operand are preserved. The new 8-bit value is returned.
1751 If 8-bit operations are not supported, then ASSERT().
1752 If StartBit is greater than 7, then ASSERT().
1753 If EndBit is greater than 7, then ASSERT().
1754 If EndBit is less than StartBit, then ASSERT().
1756 @param Operand Operand on which to perform the bitfield operation.
1757 @param StartBit The ordinal of the least significant bit in the bit field.
1759 @param EndBit The ordinal of the most significant bit in the bit field.
1761 @param OrData The value to OR with the read value from the value
1763 @return The new 8-bit value.
1776 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
1779 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1780 in Operand and the value specified by AndData. All other bits in Operand are
1781 preserved. The new 8-bit value is returned.
1783 If 8-bit operations are not supported, then ASSERT().
1784 If StartBit is greater than 7, then ASSERT().
1785 If EndBit is greater than 7, then ASSERT().
1786 If EndBit is less than StartBit, then ASSERT().
1788 @param Operand Operand on which to perform the bitfield operation.
1789 @param StartBit The ordinal of the least significant bit in the bit field.
1791 @param EndBit The ordinal of the most significant bit in the bit field.
1793 @param AndData The value to AND with the read value from the value.
1795 @return The new 8-bit value.
1808 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
1809 bitwise OR, and returns the result.
1811 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1812 in Operand and the value specified by AndData, followed by a bitwise
1813 inclusive OR with value specified by OrData. All other bits in Operand are
1814 preserved. The new 8-bit value is returned.
1816 If 8-bit operations are not supported, then ASSERT().
1817 If StartBit is greater than 7, then ASSERT().
1818 If EndBit is greater than 7, then ASSERT().
1819 If EndBit is less than StartBit, then ASSERT().
1821 @param Operand Operand on which to perform the bitfield operation.
1822 @param StartBit The ordinal of the least significant bit in the bit field.
1824 @param EndBit The ordinal of the most significant bit in the bit field.
1826 @param AndData The value to AND with the read value from the value.
1827 @param OrData The value to OR with the result of the AND operation.
1829 @return The new 8-bit value.
1834 BitFieldAndThenOr8 (
1843 Returns a bit field from a 16-bit value.
1845 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1847 If 16-bit operations are not supported, then ASSERT().
1848 If StartBit is greater than 15, then ASSERT().
1849 If EndBit is greater than 15, then ASSERT().
1850 If EndBit is less than StartBit, then ASSERT().
1852 @param Operand Operand on which to perform the bitfield operation.
1853 @param StartBit The ordinal of the least significant bit in the bit field.
1855 @param EndBit The ordinal of the most significant bit in the bit field.
1858 @return The bit field read.
1870 Writes a bit field to a 16-bit value, and returns the result.
1872 Writes Value to the bit field specified by the StartBit and the EndBit in
1873 Operand. All other bits in Operand are preserved. The new 16-bit value is
1876 If 16-bit operations are not supported, then ASSERT().
1877 If StartBit is greater than 15, then ASSERT().
1878 If EndBit is greater than 15, then ASSERT().
1879 If EndBit is less than StartBit, then ASSERT().
1881 @param Operand Operand on which to perform the bitfield operation.
1882 @param StartBit The ordinal of the least significant bit in the bit field.
1884 @param EndBit The ordinal of the most significant bit in the bit field.
1886 @param Value New value of the bit field.
1888 @return The new 16-bit value.
1901 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
1904 Performs a bitwise inclusive OR between the bit field specified by StartBit
1905 and EndBit in Operand and the value specified by OrData. All other bits in
1906 Operand are preserved. The new 16-bit value is returned.
1908 If 16-bit operations are not supported, then ASSERT().
1909 If StartBit is greater than 15, then ASSERT().
1910 If EndBit is greater than 15, then ASSERT().
1911 If EndBit is less than StartBit, then ASSERT().
1913 @param Operand Operand on which to perform the bitfield operation.
1914 @param StartBit The ordinal of the least significant bit in the bit field.
1916 @param EndBit The ordinal of the most significant bit in the bit field.
1918 @param OrData The value to OR with the read value from the value
1920 @return The new 16-bit value.
1933 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
1936 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1937 in Operand and the value specified by AndData. All other bits in Operand are
1938 preserved. The new 16-bit value is returned.
1940 If 16-bit operations are not supported, then ASSERT().
1941 If StartBit is greater than 15, then ASSERT().
1942 If EndBit is greater than 15, then ASSERT().
1943 If EndBit is less than StartBit, then ASSERT().
1945 @param Operand Operand on which to perform the bitfield operation.
1946 @param StartBit The ordinal of the least significant bit in the bit field.
1948 @param EndBit The ordinal of the most significant bit in the bit field.
1950 @param AndData The value to AND with the read value from the value
1952 @return The new 16-bit value.
1965 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
1966 bitwise OR, and returns the result.
1968 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1969 in Operand and the value specified by AndData, followed by a bitwise
1970 inclusive OR with value specified by OrData. All other bits in Operand are
1971 preserved. The new 16-bit value is returned.
1973 If 16-bit operations are not supported, then ASSERT().
1974 If StartBit is greater than 15, then ASSERT().
1975 If EndBit is greater than 15, then ASSERT().
1976 If EndBit is less than StartBit, then ASSERT().
1978 @param Operand Operand on which to perform the bitfield operation.
1979 @param StartBit The ordinal of the least significant bit in the bit field.
1981 @param EndBit The ordinal of the most significant bit in the bit field.
1983 @param AndData The value to AND with the read value from the value.
1984 @param OrData The value to OR with the result of the AND operation.
1986 @return The new 16-bit value.
1991 BitFieldAndThenOr16 (
2000 Returns a bit field from a 32-bit value.
2002 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2004 If 32-bit operations are not supported, then ASSERT().
2005 If StartBit is greater than 31, then ASSERT().
2006 If EndBit is greater than 31, then ASSERT().
2007 If EndBit is less than StartBit, then ASSERT().
2009 @param Operand Operand on which to perform the bitfield operation.
2010 @param StartBit The ordinal of the least significant bit in the bit field.
2012 @param EndBit The ordinal of the most significant bit in the bit field.
2015 @return The bit field read.
2027 Writes a bit field to a 32-bit value, and returns the result.
2029 Writes Value to the bit field specified by the StartBit and the EndBit in
2030 Operand. All other bits in Operand are preserved. The new 32-bit value is
2033 If 32-bit operations are not supported, then ASSERT().
2034 If StartBit is greater than 31, then ASSERT().
2035 If EndBit is greater than 31, then ASSERT().
2036 If EndBit is less than StartBit, then ASSERT().
2038 @param Operand Operand on which to perform the bitfield operation.
2039 @param StartBit The ordinal of the least significant bit in the bit field.
2041 @param EndBit The ordinal of the most significant bit in the bit field.
2043 @param Value New value of the bit field.
2045 @return The new 32-bit value.
2058 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2061 Performs a bitwise inclusive OR between the bit field specified by StartBit
2062 and EndBit in Operand and the value specified by OrData. All other bits in
2063 Operand are preserved. The new 32-bit value is returned.
2065 If 32-bit operations are not supported, then ASSERT().
2066 If StartBit is greater than 31, then ASSERT().
2067 If EndBit is greater than 31, then ASSERT().
2068 If EndBit is less than StartBit, then ASSERT().
2070 @param Operand Operand on which to perform the bitfield operation.
2071 @param StartBit The ordinal of the least significant bit in the bit field.
2073 @param EndBit The ordinal of the most significant bit in the bit field.
2075 @param OrData The value to OR with the read value from the value
2077 @return The new 32-bit value.
2090 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2093 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2094 in Operand and the value specified by AndData. All other bits in Operand are
2095 preserved. The new 32-bit value is returned.
2097 If 32-bit operations are not supported, then ASSERT().
2098 If StartBit is greater than 31, then ASSERT().
2099 If EndBit is greater than 31, then ASSERT().
2100 If EndBit is less than StartBit, then ASSERT().
2102 @param Operand Operand on which to perform the bitfield operation.
2103 @param StartBit The ordinal of the least significant bit in the bit field.
2105 @param EndBit The ordinal of the most significant bit in the bit field.
2107 @param AndData The value to AND with the read value from the value
2109 @return The new 32-bit value.
2122 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2123 bitwise OR, and returns the result.
2125 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2126 in Operand and the value specified by AndData, followed by a bitwise
2127 inclusive OR with value specified by OrData. All other bits in Operand are
2128 preserved. The new 32-bit value is returned.
2130 If 32-bit operations are not supported, then ASSERT().
2131 If StartBit is greater than 31, then ASSERT().
2132 If EndBit is greater than 31, then ASSERT().
2133 If EndBit is less than StartBit, then ASSERT().
2135 @param Operand Operand on which to perform the bitfield operation.
2136 @param StartBit The ordinal of the least significant bit in the bit field.
2138 @param EndBit The ordinal of the most significant bit in the bit field.
2140 @param AndData The value to AND with the read value from the value.
2141 @param OrData The value to OR with the result of the AND operation.
2143 @return The new 32-bit value.
2148 BitFieldAndThenOr32 (
2157 Returns a bit field from a 64-bit value.
2159 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2161 If 64-bit operations are not supported, then ASSERT().
2162 If StartBit is greater than 63, then ASSERT().
2163 If EndBit is greater than 63, then ASSERT().
2164 If EndBit is less than StartBit, then ASSERT().
2166 @param Operand Operand on which to perform the bitfield operation.
2167 @param StartBit The ordinal of the least significant bit in the bit field.
2169 @param EndBit The ordinal of the most significant bit in the bit field.
2172 @return The bit field read.
2184 Writes a bit field to a 64-bit value, and returns the result.
2186 Writes Value to the bit field specified by the StartBit and the EndBit in
2187 Operand. All other bits in Operand are preserved. The new 64-bit value is
2190 If 64-bit operations are not supported, then ASSERT().
2191 If StartBit is greater than 63, then ASSERT().
2192 If EndBit is greater than 63, then ASSERT().
2193 If EndBit is less than StartBit, then ASSERT().
2195 @param Operand Operand on which to perform the bitfield operation.
2196 @param StartBit The ordinal of the least significant bit in the bit field.
2198 @param EndBit The ordinal of the most significant bit in the bit field.
2200 @param Value New value of the bit field.
2202 @return The new 64-bit value.
2215 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2218 Performs a bitwise inclusive OR between the bit field specified by StartBit
2219 and EndBit in Operand and the value specified by OrData. All other bits in
2220 Operand are preserved. The new 64-bit value is returned.
2222 If 64-bit operations are not supported, then ASSERT().
2223 If StartBit is greater than 63, then ASSERT().
2224 If EndBit is greater than 63, then ASSERT().
2225 If EndBit is less than StartBit, then ASSERT().
2227 @param Operand Operand on which to perform the bitfield operation.
2228 @param StartBit The ordinal of the least significant bit in the bit field.
2230 @param EndBit The ordinal of the most significant bit in the bit field.
2232 @param OrData The value to OR with the read value from the value
2234 @return The new 64-bit value.
2247 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2250 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2251 in Operand and the value specified by AndData. All other bits in Operand are
2252 preserved. The new 64-bit value is returned.
2254 If 64-bit operations are not supported, then ASSERT().
2255 If StartBit is greater than 63, then ASSERT().
2256 If EndBit is greater than 63, then ASSERT().
2257 If EndBit is less than StartBit, then ASSERT().
2259 @param Operand Operand on which to perform the bitfield operation.
2260 @param StartBit The ordinal of the least significant bit in the bit field.
2262 @param EndBit The ordinal of the most significant bit in the bit field.
2264 @param AndData The value to AND with the read value from the value
2266 @return The new 64-bit value.
2279 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2280 bitwise OR, and returns the result.
2282 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2283 in Operand and the value specified by AndData, followed by a bitwise
2284 inclusive OR with value specified by OrData. All other bits in Operand are
2285 preserved. The new 64-bit value is returned.
2287 If 64-bit operations are not supported, then ASSERT().
2288 If StartBit is greater than 63, then ASSERT().
2289 If EndBit is greater than 63, then ASSERT().
2290 If EndBit is less than StartBit, then ASSERT().
2292 @param Operand Operand on which to perform the bitfield operation.
2293 @param StartBit The ordinal of the least significant bit in the bit field.
2295 @param EndBit The ordinal of the most significant bit in the bit field.
2297 @param AndData The value to AND with the read value from the value.
2298 @param OrData The value to OR with the result of the AND operation.
2300 @return The new 64-bit value.
2305 BitFieldAndThenOr64 (
2314 // Base Library Synchronization Functions
2318 Retrieves the architecture specific spin lock alignment requirements for
2319 optimal spin lock performance.
2321 This function retrieves the spin lock alignment requirements for optimal
2322 performance on a given CPU architecture. The spin lock alignment must be a
2323 power of two and is returned by this function. If there are no alignment
2324 requirements, then 1 must be returned. The spin lock synchronization
2325 functions must function correctly if the spin lock size and alignment values
2326 returned by this function are not used at all. These values are hints to the
2327 consumers of the spin lock synchronization functions to obtain optimal spin
2330 @return The architecture specific spin lock alignment.
2335 GetSpinLockProperties (
2340 Initializes a spin lock to the released state and returns the spin lock.
2342 This function initializes the spin lock specified by SpinLock to the released
2343 state, and returns SpinLock. Optimal performance can be achieved by calling
2344 GetSpinLockProperties() to determine the size and alignment requirements for
2347 If SpinLock is NULL, then ASSERT().
2349 @param SpinLock A pointer to the spin lock to initialize to the released
2357 InitializeSpinLock (
2358 IN SPIN_LOCK
*SpinLock
2362 Waits until a spin lock can be placed in the acquired state.
2364 This function checks the state of the spin lock specified by SpinLock. If
2365 SpinLock is in the released state, then this function places SpinLock in the
2366 acquired state and returns SpinLock. Otherwise, this function waits
2367 indefinitely for the spin lock to be released, and then places it in the
2368 acquired state and returns SpinLock. All state transitions of SpinLock must
2369 be performed using MP safe mechanisms.
2371 If SpinLock is NULL, then ASSERT().
2372 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2373 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2374 PcdSpinLockTimeout microseconds, then ASSERT().
2376 @param SpinLock A pointer to the spin lock to place in the acquired state.
2384 IN SPIN_LOCK
*SpinLock
2388 Attempts to place a spin lock in the acquired state.
2390 This function checks the state of the spin lock specified by SpinLock. If
2391 SpinLock is in the released state, then this function places SpinLock in the
2392 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2393 transitions of SpinLock must be performed using MP safe mechanisms.
2395 If SpinLock is NULL, then ASSERT().
2396 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2398 @param SpinLock A pointer to the spin lock to place in the acquired state.
2400 @retval TRUE SpinLock was placed in the acquired state.
2401 @retval FALSE SpinLock could not be acquired.
2406 AcquireSpinLockOrFail (
2407 IN SPIN_LOCK
*SpinLock
2411 Releases a spin lock.
2413 This function places the spin lock specified by SpinLock in the release state
2414 and returns SpinLock.
2416 If SpinLock is NULL, then ASSERT().
2417 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2419 @param SpinLock A pointer to the spin lock to release.
2427 IN SPIN_LOCK
*SpinLock
2431 Performs an atomic increment of an 32-bit unsigned integer.
2433 Performs an atomic increment of the 32-bit unsigned integer specified by
2434 Value and returns the incremented value. The increment operation must be
2435 performed using MP safe mechanisms. The state of the return value is not
2436 guaranteed to be MP safe.
2438 If Value is NULL, then ASSERT().
2440 @param Value A pointer to the 32-bit value to increment.
2442 @return The incremented value.
2447 InterlockedIncrement (
2452 Performs an atomic decrement of an 32-bit unsigned integer.
2454 Performs an atomic decrement of the 32-bit unsigned integer specified by
2455 Value and returns the decremented value. The decrement operation must be
2456 performed using MP safe mechanisms. The state of the return value is not
2457 guaranteed to be MP safe.
2459 If Value is NULL, then ASSERT().
2461 @param Value A pointer to the 32-bit value to decrement.
2463 @return The decremented value.
2468 InterlockedDecrement (
2473 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
2475 Performs an atomic compare exchange operation on the 32-bit unsigned integer
2476 specified by Value. If Value is equal to CompareValue, then Value is set to
2477 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
2478 then Value is returned. The compare exchange operation must be performed using
2481 If Value is NULL, then ASSERT().
2483 @param Value A pointer to the 32-bit value for the compare exchange
2485 @param CompareValue 32-bit value used in compare operation.
2486 @param ExchangeValue 32-bit value used in exchange operation.
2488 @return The original *Value before exchange.
2493 InterlockedCompareExchange32 (
2494 IN OUT UINT32
*Value
,
2495 IN UINT32 CompareValue
,
2496 IN UINT32 ExchangeValue
2500 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
2502 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
2503 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
2504 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
2505 The compare exchange operation must be performed using MP safe mechanisms.
2507 If Value is NULL, then ASSERT().
2509 @param Value A pointer to the 64-bit value for the compare exchange
2511 @param CompareValue 64-bit value used in compare operation.
2512 @param ExchangeValue 64-bit value used in exchange operation.
2514 @return The original *Value before exchange.
2519 InterlockedCompareExchange64 (
2520 IN OUT UINT64
*Value
,
2521 IN UINT64 CompareValue
,
2522 IN UINT64 ExchangeValue
2526 Performs an atomic compare exchange operation on a pointer value.
2528 Performs an atomic compare exchange operation on the pointer value specified
2529 by Value. If Value is equal to CompareValue, then Value is set to
2530 ExchangeValue and CompareValue is returned. If Value is not equal to
2531 CompareValue, then Value is returned. The compare exchange operation must be
2532 performed using MP safe mechanisms.
2534 If Value is NULL, then ASSERT().
2536 @param Value A pointer to the pointer value for the compare exchange
2538 @param CompareValue Pointer value used in compare operation.
2539 @param ExchangeValue Pointer value used in exchange operation.
2544 InterlockedCompareExchangePointer (
2545 IN OUT VOID
**Value
,
2546 IN VOID
*CompareValue
,
2547 IN VOID
*ExchangeValue
2551 // Base Library CPU Functions
2555 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
2556 IN VOID
*Context1
, OPTIONAL
2557 IN VOID
*Context2 OPTIONAL
2561 Used to serialize load and store operations.
2563 All loads and stores that proceed calls to this function are guaranteed to be
2564 globally visible when this function returns.
2574 Saves the current CPU context that can be restored with a call to LongJump()
2577 Saves the current CPU context in the buffer specified by JumpBuffer and
2578 returns 0. The initial call to SetJump() must always return 0. Subsequent
2579 calls to LongJump() cause a non-zero value to be returned by SetJump().
2581 If JumpBuffer is NULL, then ASSERT().
2582 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2584 @param JumpBuffer A pointer to CPU context buffer.
2586 @retval 0 Indicates a return from SetJump().
2592 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
2596 Restores the CPU context that was saved with SetJump().
2598 Restores the CPU context from the buffer specified by JumpBuffer. This
2599 function never returns to the caller. Instead is resumes execution based on
2600 the state of JumpBuffer.
2602 If JumpBuffer is NULL, then ASSERT().
2603 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2604 If Value is 0, then ASSERT().
2606 @param JumpBuffer A pointer to CPU context buffer.
2607 @param Value The value to return when the SetJump() context is
2608 restored and must be non-zero.
2614 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
2619 Enables CPU interrupts.
2621 Enables CPU interrupts.
2631 Disables CPU interrupts.
2633 Disables CPU interrupts.
2643 Disables CPU interrupts and returns the interrupt state prior to the disable
2646 Disables CPU interrupts and returns the interrupt state prior to the disable
2649 @retval TRUE CPU interrupts were enabled on entry to this call.
2650 @retval FALSE CPU interrupts were disabled on entry to this call.
2655 SaveAndDisableInterrupts (
2660 Enables CPU interrupts for the smallest window required to capture any
2663 Enables CPU interrupts for the smallest window required to capture any
2669 EnableDisableInterrupts (
2674 Retrieves the current CPU interrupt state.
2676 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
2677 currently enabled. Otherwise returns FALSE.
2679 @retval TRUE CPU interrupts are enabled.
2680 @retval FALSE CPU interrupts are disabled.
2690 Set the current CPU interrupt state.
2692 Sets the current CPU interrupt state to the state specified by
2693 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
2694 InterruptState is FALSE, then interrupts are disabled. InterruptState is
2697 @param InterruptState TRUE if interrupts should enabled. FALSE if
2698 interrupts should be disabled.
2700 @return InterruptState
2706 IN BOOLEAN InterruptState
2710 Places the CPU in a sleep state until an interrupt is received.
2712 Places the CPU in a sleep state until an interrupt is received. If interrupts
2713 are disabled prior to calling this function, then the CPU will be placed in a
2714 sleep state indefinitely.
2724 Requests CPU to pause for a short period of time.
2726 Requests CPU to pause for a short period of time. Typically used in MP
2727 systems to prevent memory starvation while waiting for a spin lock.
2737 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2739 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2749 Transfers control to a function starting with a new stack.
2751 Transfers control to the function specified by EntryPoint using the new stack
2752 specified by NewStack and passing in the parameters specified by Context1 and
2753 Context2. Context1 and Context2 are optional and may be NULL. The function
2754 EntryPoint must never return.
2756 If EntryPoint is NULL, then ASSERT().
2757 If NewStack is NULL, then ASSERT().
2759 @param EntryPoint A pointer to function to call with the new stack.
2760 @param Context1 A pointer to the context to pass into the EntryPoint
2762 @param Context2 A pointer to the context to pass into the EntryPoint
2764 @param NewStack A pointer to the new stack to use for the EntryPoint
2771 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
2772 IN VOID
*Context1
, OPTIONAL
2773 IN VOID
*Context2
, OPTIONAL
2778 Generates a breakpoint on the CPU.
2780 Generates a breakpoint on the CPU. The breakpoint must be implemented such
2781 that code can resume normal execution after the breakpoint.
2791 Executes an infinite loop.
2793 Forces the CPU to execute an infinite loop. A debugger may be used to skip
2794 past the loop and the code that follows the loop must execute properly. This
2795 implies that the infinite loop must not cause the code that follow it to be
2806 // IA32 and X64 Specific Functions
2809 // Byte packed structure for 16-bit Real Mode EFLAGS
2813 UINT32 CF
:1; // Carry Flag
2814 UINT32 Reserved_0
:1; // Reserved
2815 UINT32 PF
:1; // Parity Flag
2816 UINT32 Reserved_1
:1; // Reserved
2817 UINT32 AF
:1; // Auxiliary Carry Flag
2818 UINT32 Reserved_2
:1; // Reserved
2819 UINT32 ZF
:1; // Zero Flag
2820 UINT32 SF
:1; // Sign Flag
2821 UINT32 TF
:1; // Trap Flag
2822 UINT32 IF
:1; // Interrupt Enable Flag
2823 UINT32 DF
:1; // Direction Flag
2824 UINT32 OF
:1; // Overflow Flag
2825 UINT32 IOPL
:2; // I/O Privilege Level
2826 UINT32 NT
:1; // Nested Task
2827 UINT32 Reserved_3
:1; // Reserved
2833 // Byte packed structure for EFLAGS/RFLAGS
2835 // 64-bits on X64. The upper 32-bits on X64 are reserved
2839 UINT32 CF
:1; // Carry Flag
2840 UINT32 Reserved_0
:1; // Reserved
2841 UINT32 PF
:1; // Parity Flag
2842 UINT32 Reserved_1
:1; // Reserved
2843 UINT32 AF
:1; // Auxiliary Carry Flag
2844 UINT32 Reserved_2
:1; // Reserved
2845 UINT32 ZF
:1; // Zero Flag
2846 UINT32 SF
:1; // Sign Flag
2847 UINT32 TF
:1; // Trap Flag
2848 UINT32 IF
:1; // Interrupt Enable Flag
2849 UINT32 DF
:1; // Direction Flag
2850 UINT32 OF
:1; // Overflow Flag
2851 UINT32 IOPL
:2; // I/O Privilege Level
2852 UINT32 NT
:1; // Nested Task
2853 UINT32 Reserved_3
:1; // Reserved
2854 UINT32 RF
:1; // Resume Flag
2855 UINT32 VM
:1; // Virtual 8086 Mode
2856 UINT32 AC
:1; // Alignment Check
2857 UINT32 VIF
:1; // Virtual Interrupt Flag
2858 UINT32 VIP
:1; // Virtual Interrupt Pending
2859 UINT32 ID
:1; // ID Flag
2860 UINT32 Reserved_4
:10; // Reserved
2866 // Byte packed structure for Control Register 0 (CR0)
2868 // 64-bits on X64. The upper 32-bits on X64 are reserved
2872 UINT32 PE
:1; // Protection Enable
2873 UINT32 MP
:1; // Monitor Coprocessor
2874 UINT32 EM
:1; // Emulation
2875 UINT32 TS
:1; // Task Switched
2876 UINT32 ET
:1; // Extension Type
2877 UINT32 NE
:1; // Numeric Error
2878 UINT32 Reserved_0
:10; // Reserved
2879 UINT32 WP
:1; // Write Protect
2880 UINT32 Reserved_1
:1; // Reserved
2881 UINT32 AM
:1; // Alignment Mask
2882 UINT32 Reserved_2
:10; // Reserved
2883 UINT32 NW
:1; // Mot Write-through
2884 UINT32 CD
:1; // Cache Disable
2885 UINT32 PG
:1; // Paging
2891 // Byte packed structure for Control Register 4 (CR4)
2893 // 64-bits on X64. The upper 32-bits on X64 are reserved
2897 UINT32 VME
:1; // Virtual-8086 Mode Extensions
2898 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
2899 UINT32 TSD
:1; // Time Stamp Disable
2900 UINT32 DE
:1; // Debugging Extensions
2901 UINT32 PSE
:1; // Page Size Extensions
2902 UINT32 PAE
:1; // Physical Address Extension
2903 UINT32 MCE
:1; // Machine Check Enable
2904 UINT32 PGE
:1; // Page Global Enable
2905 UINT32 PCE
:1; // Performance Monitoring Counter
2907 UINT32 OSFXSR
:1; // Operating System Support for
2908 // FXSAVE and FXRSTOR instructions
2909 UINT32 OSXMMEXCPT
:1; // Operating System Support for
2910 // Unmasked SIMD Floating Point
2912 UINT32 Reserved_0
:2; // Reserved
2913 UINT32 VMXE
:1; // VMX Enable
2914 UINT32 Reserved_1
:18; // Reseved
2920 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
2921 /// @bug How to make this structure byte-packed in a compiler independent way?
2930 #define IA32_IDT_GATE_TYPE_TASK 0x85
2931 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
2932 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
2933 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
2934 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
2937 // Byte packed structure for an Interrupt Gate Descriptor
2941 UINT32 OffsetLow
:16; // Offset bits 15..0
2942 UINT32 Selector
:16; // Selector
2943 UINT32 Reserved_0
:8; // Reserved
2944 UINT32 GateType
:8; // Gate Type. See #defines above
2945 UINT32 OffsetHigh
:16; // Offset bits 31..16
2948 } IA32_IDT_GATE_DESCRIPTOR
;
2951 // Byte packed structure for an FP/SSE/SSE2 context
2958 // Structures for the 16-bit real mode thunks
3011 IA32_EFLAGS32 EFLAGS
;
3021 } IA32_REGISTER_SET
;
3024 // Byte packed structure for an 16-bit real mode thunks
3027 IA32_REGISTER_SET
*RealModeState
;
3028 VOID
*RealModeBuffer
;
3029 UINT32 RealModeBufferSize
;
3030 UINT32 ThunkAttributes
;
3033 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
3034 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
3035 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3038 Retrieves CPUID information.
3040 Executes the CPUID instruction with EAX set to the value specified by Index.
3041 This function always returns Index.
3042 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3043 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3044 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3045 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3046 This function is only available on IA-32 and X64.
3048 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3050 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3051 instruction. This is an optional parameter that may be NULL.
3052 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3053 instruction. This is an optional parameter that may be NULL.
3054 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3055 instruction. This is an optional parameter that may be NULL.
3056 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3057 instruction. This is an optional parameter that may be NULL.
3066 OUT UINT32
*Eax
, OPTIONAL
3067 OUT UINT32
*Ebx
, OPTIONAL
3068 OUT UINT32
*Ecx
, OPTIONAL
3069 OUT UINT32
*Edx OPTIONAL
3073 Retrieves CPUID information using an extended leaf identifier.
3075 Executes the CPUID instruction with EAX set to the value specified by Index
3076 and ECX set to the value specified by SubIndex. This function always returns
3077 Index. This function is only available on IA-32 and x64.
3079 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3080 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3081 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3082 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3084 @param Index The 32-bit value to load into EAX prior to invoking the
3086 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3088 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3089 instruction. This is an optional parameter that may be
3091 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3092 instruction. This is an optional parameter that may be
3094 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3095 instruction. This is an optional parameter that may be
3097 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3098 instruction. This is an optional parameter that may be
3109 OUT UINT32
*Eax
, OPTIONAL
3110 OUT UINT32
*Ebx
, OPTIONAL
3111 OUT UINT32
*Ecx
, OPTIONAL
3112 OUT UINT32
*Edx OPTIONAL
3116 Returns the lower 32-bits of a Machine Specific Register(MSR).
3118 Reads and returns the lower 32-bits of the MSR specified by Index.
3119 No parameter checking is performed on Index, and some Index values may cause
3120 CPU exceptions. The caller must either guarantee that Index is valid, or the
3121 caller must set up exception handlers to catch the exceptions. This function
3122 is only available on IA-32 and X64.
3124 @param Index The 32-bit MSR index to read.
3126 @return The lower 32 bits of the MSR identified by Index.
3136 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3138 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3139 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3140 the MSR is returned. No parameter checking is performed on Index or Value,
3141 and some of these may cause CPU exceptions. The caller must either guarantee
3142 that Index and Value are valid, or the caller must establish proper exception
3143 handlers. This function is only available on IA-32 and X64.
3145 @param Index The 32-bit MSR index to write.
3146 @param Value The 32-bit value to write to the MSR.
3159 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3160 writes the result back to the 64-bit MSR.
3162 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3163 between the lower 32-bits of the read result and the value specified by
3164 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3165 32-bits of the value written to the MSR is returned. No parameter checking is
3166 performed on Index or OrData, and some of these may cause CPU exceptions. The
3167 caller must either guarantee that Index and OrData are valid, or the caller
3168 must establish proper exception handlers. This function is only available on
3171 @param Index The 32-bit MSR index to write.
3172 @param OrData The value to OR with the read value from the MSR.
3174 @return The lower 32-bit value written to the MSR.
3185 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3186 the result back to the 64-bit MSR.
3188 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3189 lower 32-bits of the read result and the value specified by AndData, and
3190 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3191 the value written to the MSR is returned. No parameter checking is performed
3192 on Index or AndData, and some of these may cause CPU exceptions. The caller
3193 must either guarantee that Index and AndData are valid, or the caller must
3194 establish proper exception handlers. This function is only available on IA-32
3197 @param Index The 32-bit MSR index to write.
3198 @param AndData The value to AND with the read value from the MSR.
3200 @return The lower 32-bit value written to the MSR.
3211 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3212 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3214 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3215 lower 32-bits of the read result and the value specified by AndData
3216 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3217 result of the AND operation and the value specified by OrData, and writes the
3218 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3219 written to the MSR is returned. No parameter checking is performed on Index,
3220 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3221 must either guarantee that Index, AndData, and OrData are valid, or the
3222 caller must establish proper exception handlers. This function is only
3223 available on IA-32 and X64.
3225 @param Index The 32-bit MSR index to write.
3226 @param AndData The value to AND with the read value from the MSR.
3227 @param OrData The value to OR with the result of the AND operation.
3229 @return The lower 32-bit value written to the MSR.
3241 Reads a bit field of an MSR.
3243 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3244 specified by the StartBit and the EndBit. The value of the bit field is
3245 returned. The caller must either guarantee that Index is valid, or the caller
3246 must set up exception handlers to catch the exceptions. This function is only
3247 available on IA-32 and X64.
3249 If StartBit is greater than 31, then ASSERT().
3250 If EndBit is greater than 31, then ASSERT().
3251 If EndBit is less than StartBit, then ASSERT().
3253 @param Index The 32-bit MSR index to read.
3254 @param StartBit The ordinal of the least significant bit in the bit field.
3256 @param EndBit The ordinal of the most significant bit in the bit field.
3259 @return The bit field read from the MSR.
3264 AsmMsrBitFieldRead32 (
3271 Writes a bit field to an MSR.
3273 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3274 field is specified by the StartBit and the EndBit. All other bits in the
3275 destination MSR are preserved. The lower 32-bits of the MSR written is
3276 returned. Extra left bits in Value are stripped. The caller must either
3277 guarantee that Index and the data written is valid, or the caller must set up
3278 exception handlers to catch the exceptions. This function is only available
3281 If StartBit is greater than 31, then ASSERT().
3282 If EndBit is greater than 31, then ASSERT().
3283 If EndBit is less than StartBit, then ASSERT().
3285 @param Index The 32-bit MSR index to write.
3286 @param StartBit The ordinal of the least significant bit in the bit field.
3288 @param EndBit The ordinal of the most significant bit in the bit field.
3290 @param Value New value of the bit field.
3292 @return The lower 32-bit of the value written to the MSR.
3297 AsmMsrBitFieldWrite32 (
3305 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3306 result back to the bit field in the 64-bit MSR.
3308 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3309 between the read result and the value specified by OrData, and writes the
3310 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3311 written to the MSR are returned. Extra left bits in OrData are stripped. The
3312 caller must either guarantee that Index and the data written is valid, or
3313 the caller must set up exception handlers to catch the exceptions. This
3314 function is only available on IA-32 and X64.
3316 If StartBit is greater than 31, then ASSERT().
3317 If EndBit is greater than 31, then ASSERT().
3318 If EndBit is less than StartBit, then ASSERT().
3320 @param Index The 32-bit MSR index to write.
3321 @param StartBit The ordinal of the least significant bit in the bit field.
3323 @param EndBit The ordinal of the most significant bit in the bit field.
3325 @param OrData The value to OR with the read value from the MSR.
3327 @return The lower 32-bit of the value written to the MSR.
3332 AsmMsrBitFieldOr32 (
3340 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3341 result back to the bit field in the 64-bit MSR.
3343 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3344 read result and the value specified by AndData, and writes the result to the
3345 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3346 MSR are returned. Extra left bits in AndData are stripped. The caller must
3347 either guarantee that Index and the data written is valid, or the caller must
3348 set up exception handlers to catch the exceptions. This function is only
3349 available on IA-32 and X64.
3351 If StartBit is greater than 31, then ASSERT().
3352 If EndBit is greater than 31, then ASSERT().
3353 If EndBit is less than StartBit, then ASSERT().
3355 @param Index The 32-bit MSR index to write.
3356 @param StartBit The ordinal of the least significant bit in the bit field.
3358 @param EndBit The ordinal of the most significant bit in the bit field.
3360 @param AndData The value to AND with the read value from the MSR.
3362 @return The lower 32-bit of the value written to the MSR.
3367 AsmMsrBitFieldAnd32 (
3375 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3376 bitwise inclusive OR, and writes the result back to the bit field in the
3379 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3380 bitwise inclusive OR between the read result and the value specified by
3381 AndData, and writes the result to the 64-bit MSR specified by Index. The
3382 lower 32-bits of the value written to the MSR are returned. Extra left bits
3383 in both AndData and OrData are stripped. The caller must either guarantee
3384 that Index and the data written is valid, or the caller must set up exception
3385 handlers to catch the exceptions. This function is only available on IA-32
3388 If StartBit is greater than 31, then ASSERT().
3389 If EndBit is greater than 31, then ASSERT().
3390 If EndBit is less than StartBit, then ASSERT().
3392 @param Index The 32-bit MSR index to write.
3393 @param StartBit The ordinal of the least significant bit in the bit field.
3395 @param EndBit The ordinal of the most significant bit in the bit field.
3397 @param AndData The value to AND with the read value from the MSR.
3398 @param OrData The value to OR with the result of the AND operation.
3400 @return The lower 32-bit of the value written to the MSR.
3405 AsmMsrBitFieldAndThenOr32 (
3414 Returns a 64-bit Machine Specific Register(MSR).
3416 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3417 performed on Index, and some Index values may cause CPU exceptions. The
3418 caller must either guarantee that Index is valid, or the caller must set up
3419 exception handlers to catch the exceptions. This function is only available
3422 @param Index The 32-bit MSR index to read.
3424 @return The value of the MSR identified by Index.
3434 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3437 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3438 64-bit value written to the MSR is returned. No parameter checking is
3439 performed on Index or Value, and some of these may cause CPU exceptions. The
3440 caller must either guarantee that Index and Value are valid, or the caller
3441 must establish proper exception handlers. This function is only available on
3444 @param Index The 32-bit MSR index to write.
3445 @param Value The 64-bit value to write to the MSR.
3458 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3459 back to the 64-bit MSR.
3461 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3462 between the read result and the value specified by OrData, and writes the
3463 result to the 64-bit MSR specified by Index. The value written to the MSR is
3464 returned. No parameter checking is performed on Index or OrData, and some of
3465 these may cause CPU exceptions. The caller must either guarantee that Index
3466 and OrData are valid, or the caller must establish proper exception handlers.
3467 This function is only available on IA-32 and X64.
3469 @param Index The 32-bit MSR index to write.
3470 @param OrData The value to OR with the read value from the MSR.
3472 @return The value written back to the MSR.
3483 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3486 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3487 read result and the value specified by OrData, and writes the result to the
3488 64-bit MSR specified by Index. The value written to the MSR is returned. No
3489 parameter checking is performed on Index or OrData, and some of these may
3490 cause CPU exceptions. The caller must either guarantee that Index and OrData
3491 are valid, or the caller must establish proper exception handlers. This
3492 function is only available on IA-32 and X64.
3494 @param Index The 32-bit MSR index to write.
3495 @param AndData The value to AND with the read value from the MSR.
3497 @return The value written back to the MSR.
3508 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3509 OR, and writes the result back to the 64-bit MSR.
3511 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3512 result and the value specified by AndData, performs a bitwise inclusive OR
3513 between the result of the AND operation and the value specified by OrData,
3514 and writes the result to the 64-bit MSR specified by Index. The value written
3515 to the MSR is returned. No parameter checking is performed on Index, AndData,
3516 or OrData, and some of these may cause CPU exceptions. The caller must either
3517 guarantee that Index, AndData, and OrData are valid, or the caller must
3518 establish proper exception handlers. This function is only available on IA-32
3521 @param Index The 32-bit MSR index to write.
3522 @param AndData The value to AND with the read value from the MSR.
3523 @param OrData The value to OR with the result of the AND operation.
3525 @return The value written back to the MSR.
3537 Reads a bit field of an MSR.
3539 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3540 StartBit and the EndBit. The value of the bit field is returned. The caller
3541 must either guarantee that Index is valid, or the caller must set up
3542 exception handlers to catch the exceptions. This function is only available
3545 If StartBit is greater than 63, then ASSERT().
3546 If EndBit is greater than 63, then ASSERT().
3547 If EndBit is less than StartBit, then ASSERT().
3549 @param Index The 32-bit MSR index to read.
3550 @param StartBit The ordinal of the least significant bit in the bit field.
3552 @param EndBit The ordinal of the most significant bit in the bit field.
3555 @return The value read from the MSR.
3560 AsmMsrBitFieldRead64 (
3567 Writes a bit field to an MSR.
3569 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3570 the StartBit and the EndBit. All other bits in the destination MSR are
3571 preserved. The MSR written is returned. Extra left bits in Value are
3572 stripped. The caller must either guarantee that Index and the data written is
3573 valid, or the caller must set up exception handlers to catch the exceptions.
3574 This function is only available on IA-32 and X64.
3576 If StartBit is greater than 63, then ASSERT().
3577 If EndBit is greater than 63, then ASSERT().
3578 If EndBit is less than StartBit, then ASSERT().
3580 @param Index The 32-bit MSR index to write.
3581 @param StartBit The ordinal of the least significant bit in the bit field.
3583 @param EndBit The ordinal of the most significant bit in the bit field.
3585 @param Value New value of the bit field.
3587 @return The value written back to the MSR.
3592 AsmMsrBitFieldWrite64 (
3600 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3601 writes the result back to the bit field in the 64-bit MSR.
3603 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3604 between the read result and the value specified by OrData, and writes the
3605 result to the 64-bit MSR specified by Index. The value written to the MSR is
3606 returned. Extra left bits in OrData are stripped. The caller must either
3607 guarantee that Index and the data written is valid, or the caller must set up
3608 exception handlers to catch the exceptions. This function is only available
3611 If StartBit is greater than 63, then ASSERT().
3612 If EndBit is greater than 63, then ASSERT().
3613 If EndBit is less than StartBit, then ASSERT().
3615 @param Index The 32-bit MSR index to write.
3616 @param StartBit The ordinal of the least significant bit in the bit field.
3618 @param EndBit The ordinal of the most significant bit in the bit field.
3620 @param OrData The value to OR with the read value from the bit field.
3622 @return The value written back to the MSR.
3627 AsmMsrBitFieldOr64 (
3635 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3636 result back to the bit field in the 64-bit MSR.
3638 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3639 read result and the value specified by AndData, and writes the result to the
3640 64-bit MSR specified by Index. The value written to the MSR is returned.
3641 Extra left bits in AndData are stripped. The caller must either guarantee
3642 that Index and the data written is valid, or the caller must set up exception
3643 handlers to catch the exceptions. This function is only available on IA-32
3646 If StartBit is greater than 63, then ASSERT().
3647 If EndBit is greater than 63, then ASSERT().
3648 If EndBit is less than StartBit, then ASSERT().
3650 @param Index The 32-bit MSR index to write.
3651 @param StartBit The ordinal of the least significant bit in the bit field.
3653 @param EndBit The ordinal of the most significant bit in the bit field.
3655 @param AndData The value to AND with the read value from the bit field.
3657 @return The value written back to the MSR.
3662 AsmMsrBitFieldAnd64 (
3670 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3671 bitwise inclusive OR, and writes the result back to the bit field in the
3674 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3675 a bitwise inclusive OR between the read result and the value specified by
3676 AndData, and writes the result to the 64-bit MSR specified by Index. The
3677 value written to the MSR is returned. Extra left bits in both AndData and
3678 OrData are stripped. The caller must either guarantee that Index and the data
3679 written is valid, or the caller must set up exception handlers to catch the
3680 exceptions. This function is only available on IA-32 and X64.
3682 If StartBit is greater than 63, then ASSERT().
3683 If EndBit is greater than 63, then ASSERT().
3684 If EndBit is less than StartBit, then ASSERT().
3686 @param Index The 32-bit MSR index to write.
3687 @param StartBit The ordinal of the least significant bit in the bit field.
3689 @param EndBit The ordinal of the most significant bit in the bit field.
3691 @param AndData The value to AND with the read value from the bit field.
3692 @param OrData The value to OR with the result of the AND operation.
3694 @return The value written back to the MSR.
3699 AsmMsrBitFieldAndThenOr64 (
3708 Reads the current value of the EFLAGS register.
3710 Reads and returns the current value of the EFLAGS register. This function is
3711 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3712 64-bit value on X64.
3714 @return EFLAGS on IA-32 or RFLAGS on X64.
3724 Reads the current value of the Control Register 0 (CR0).
3726 Reads and returns the current value of CR0. This function is only available
3727 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3730 @return The value of the Control Register 0 (CR0).
3740 Reads the current value of the Control Register 2 (CR2).
3742 Reads and returns the current value of CR2. This function is only available
3743 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3746 @return The value of the Control Register 2 (CR2).
3756 Reads the current value of the Control Register 3 (CR3).
3758 Reads and returns the current value of CR3. This function is only available
3759 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3762 @return The value of the Control Register 3 (CR3).
3772 Reads the current value of the Control Register 4 (CR4).
3774 Reads and returns the current value of CR4. This function is only available
3775 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3778 @return The value of the Control Register 4 (CR4).
3788 Writes a value to Control Register 0 (CR0).
3790 Writes and returns a new value to CR0. This function is only available on
3791 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3793 @param Cr0 The value to write to CR0.
3795 @return The value written to CR0.
3805 Writes a value to Control Register 2 (CR2).
3807 Writes and returns a new value to CR2. This function is only available on
3808 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3810 @param Cr2 The value to write to CR2.
3812 @return The value written to CR2.
3822 Writes a value to Control Register 3 (CR3).
3824 Writes and returns a new value to CR3. This function is only available on
3825 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3827 @param Cr3 The value to write to CR3.
3829 @return The value written to CR3.
3839 Writes a value to Control Register 4 (CR4).
3841 Writes and returns a new value to CR4. This function is only available on
3842 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3844 @param Cr4 The value to write to CR4.
3846 @return The value written to CR4.
3856 Reads the current value of Debug Register 0 (DR0).
3858 Reads and returns the current value of DR0. This function is only available
3859 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3862 @return The value of Debug Register 0 (DR0).
3872 Reads the current value of Debug Register 1 (DR1).
3874 Reads and returns the current value of DR1. This function is only available
3875 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3878 @return The value of Debug Register 1 (DR1).
3888 Reads the current value of Debug Register 2 (DR2).
3890 Reads and returns the current value of DR2. This function is only available
3891 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3894 @return The value of Debug Register 2 (DR2).
3904 Reads the current value of Debug Register 3 (DR3).
3906 Reads and returns the current value of DR3. This function is only available
3907 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3910 @return The value of Debug Register 3 (DR3).
3920 Reads the current value of Debug Register 4 (DR4).
3922 Reads and returns the current value of DR4. This function is only available
3923 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3926 @return The value of Debug Register 4 (DR4).
3936 Reads the current value of Debug Register 5 (DR5).
3938 Reads and returns the current value of DR5. This function is only available
3939 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3942 @return The value of Debug Register 5 (DR5).
3952 Reads the current value of Debug Register 6 (DR6).
3954 Reads and returns the current value of DR6. This function is only available
3955 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3958 @return The value of Debug Register 6 (DR6).
3968 Reads the current value of Debug Register 7 (DR7).
3970 Reads and returns the current value of DR7. This function is only available
3971 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3974 @return The value of Debug Register 7 (DR7).
3984 Writes a value to Debug Register 0 (DR0).
3986 Writes and returns a new value to DR0. This function is only available on
3987 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3989 @param Dr0 The value to write to Dr0.
3991 @return The value written to Debug Register 0 (DR0).
4001 Writes a value to Debug Register 1 (DR1).
4003 Writes and returns a new value to DR1. This function is only available on
4004 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4006 @param Dr1 The value to write to Dr1.
4008 @return The value written to Debug Register 1 (DR1).
4018 Writes a value to Debug Register 2 (DR2).
4020 Writes and returns a new value to DR2. This function is only available on
4021 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4023 @param Dr2 The value to write to Dr2.
4025 @return The value written to Debug Register 2 (DR2).
4035 Writes a value to Debug Register 3 (DR3).
4037 Writes and returns a new value to DR3. This function is only available on
4038 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4040 @param Dr3 The value to write to Dr3.
4042 @return The value written to Debug Register 3 (DR3).
4052 Writes a value to Debug Register 4 (DR4).
4054 Writes and returns a new value to DR4. This function is only available on
4055 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4057 @param Dr4 The value to write to Dr4.
4059 @return The value written to Debug Register 4 (DR4).
4069 Writes a value to Debug Register 5 (DR5).
4071 Writes and returns a new value to DR5. This function is only available on
4072 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4074 @param Dr5 The value to write to Dr5.
4076 @return The value written to Debug Register 5 (DR5).
4086 Writes a value to Debug Register 6 (DR6).
4088 Writes and returns a new value to DR6. This function is only available on
4089 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4091 @param Dr6 The value to write to Dr6.
4093 @return The value written to Debug Register 6 (DR6).
4103 Writes a value to Debug Register 7 (DR7).
4105 Writes and returns a new value to DR7. This function is only available on
4106 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4108 @param Dr7 The value to write to Dr7.
4110 @return The value written to Debug Register 7 (DR7).
4120 Reads the current value of Code Segment Register (CS).
4122 Reads and returns the current value of CS. This function is only available on
4125 @return The current value of CS.
4135 Reads the current value of Data Segment Register (DS).
4137 Reads and returns the current value of DS. This function is only available on
4140 @return The current value of DS.
4150 Reads the current value of Extra Segment Register (ES).
4152 Reads and returns the current value of ES. This function is only available on
4155 @return The current value of ES.
4165 Reads the current value of FS Data Segment Register (FS).
4167 Reads and returns the current value of FS. This function is only available on
4170 @return The current value of FS.
4180 Reads the current value of GS Data Segment Register (GS).
4182 Reads and returns the current value of GS. This function is only available on
4185 @return The current value of GS.
4195 Reads the current value of Stack Segment Register (SS).
4197 Reads and returns the current value of SS. This function is only available on
4200 @return The current value of SS.
4210 Reads the current value of Task Register (TR).
4212 Reads and returns the current value of TR. This function is only available on
4215 @return The current value of TR.
4225 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4227 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4228 function is only available on IA-32 and X64.
4230 If Gdtr is NULL, then ASSERT().
4232 @param Gdtr Pointer to a GDTR descriptor.
4238 OUT IA32_DESCRIPTOR
*Gdtr
4242 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4244 Writes and the current GDTR descriptor specified by Gdtr. This function is
4245 only available on IA-32 and X64.
4247 If Gdtr is NULL, then ASSERT().
4249 @param Gdtr Pointer to a GDTR descriptor.
4255 IN CONST IA32_DESCRIPTOR
*Gdtr
4259 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4261 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4262 function is only available on IA-32 and X64.
4264 If Idtr is NULL, then ASSERT().
4266 @param Idtr Pointer to a IDTR descriptor.
4272 OUT IA32_DESCRIPTOR
*Idtr
4276 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4278 Writes the current IDTR descriptor and returns it in Idtr. This function is
4279 only available on IA-32 and X64.
4281 If Idtr is NULL, then ASSERT().
4283 @param Idtr Pointer to a IDTR descriptor.
4289 IN CONST IA32_DESCRIPTOR
*Idtr
4293 Reads the current Local Descriptor Table Register(LDTR) selector.
4295 Reads and returns the current 16-bit LDTR descriptor value. This function is
4296 only available on IA-32 and X64.
4298 @return The current selector of LDT.
4308 Writes the current Local Descriptor Table Register (GDTR) selector.
4310 Writes and the current LDTR descriptor specified by Ldtr. This function is
4311 only available on IA-32 and X64.
4313 @param Ldtr 16-bit LDTR selector value.
4323 Save the current floating point/SSE/SSE2 context to a buffer.
4325 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4326 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4327 available on IA-32 and X64.
4329 If Buffer is NULL, then ASSERT().
4330 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4332 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4338 OUT IA32_FX_BUFFER
*Buffer
4342 Restores the current floating point/SSE/SSE2 context from a buffer.
4344 Restores the current floating point/SSE/SSE2 state from the buffer specified
4345 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4346 only available on IA-32 and X64.
4348 If Buffer is NULL, then ASSERT().
4349 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4350 If Buffer was not saved with AsmFxSave(), then ASSERT().
4352 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4358 IN CONST IA32_FX_BUFFER
*Buffer
4362 Reads the current value of 64-bit MMX Register #0 (MM0).
4364 Reads and returns the current value of MM0. This function is only available
4367 @return The current value of MM0.
4377 Reads the current value of 64-bit MMX Register #1 (MM1).
4379 Reads and returns the current value of MM1. This function is only available
4382 @return The current value of MM1.
4392 Reads the current value of 64-bit MMX Register #2 (MM2).
4394 Reads and returns the current value of MM2. This function is only available
4397 @return The current value of MM2.
4407 Reads the current value of 64-bit MMX Register #3 (MM3).
4409 Reads and returns the current value of MM3. This function is only available
4412 @return The current value of MM3.
4422 Reads the current value of 64-bit MMX Register #4 (MM4).
4424 Reads and returns the current value of MM4. This function is only available
4427 @return The current value of MM4.
4437 Reads the current value of 64-bit MMX Register #5 (MM5).
4439 Reads and returns the current value of MM5. This function is only available
4442 @return The current value of MM5.
4452 Reads the current value of 64-bit MMX Register #6 (MM6).
4454 Reads and returns the current value of MM6. This function is only available
4457 @return The current value of MM6.
4467 Reads the current value of 64-bit MMX Register #7 (MM7).
4469 Reads and returns the current value of MM7. This function is only available
4472 @return The current value of MM7.
4482 Writes the current value of 64-bit MMX Register #0 (MM0).
4484 Writes the current value of MM0. This function is only available on IA32 and
4487 @param Value The 64-bit value to write to MM0.
4497 Writes the current value of 64-bit MMX Register #1 (MM1).
4499 Writes the current value of MM1. This function is only available on IA32 and
4502 @param Value The 64-bit value to write to MM1.
4512 Writes the current value of 64-bit MMX Register #2 (MM2).
4514 Writes the current value of MM2. This function is only available on IA32 and
4517 @param Value The 64-bit value to write to MM2.
4527 Writes the current value of 64-bit MMX Register #3 (MM3).
4529 Writes the current value of MM3. This function is only available on IA32 and
4532 @param Value The 64-bit value to write to MM3.
4542 Writes the current value of 64-bit MMX Register #4 (MM4).
4544 Writes the current value of MM4. This function is only available on IA32 and
4547 @param Value The 64-bit value to write to MM4.
4557 Writes the current value of 64-bit MMX Register #5 (MM5).
4559 Writes the current value of MM5. This function is only available on IA32 and
4562 @param Value The 64-bit value to write to MM5.
4572 Writes the current value of 64-bit MMX Register #6 (MM6).
4574 Writes the current value of MM6. This function is only available on IA32 and
4577 @param Value The 64-bit value to write to MM6.
4587 Writes the current value of 64-bit MMX Register #7 (MM7).
4589 Writes the current value of MM7. This function is only available on IA32 and
4592 @param Value The 64-bit value to write to MM7.
4602 Reads the current value of Time Stamp Counter (TSC).
4604 Reads and returns the current value of TSC. This function is only available
4607 @return The current value of TSC
4617 Reads the current value of a Performance Counter (PMC).
4619 Reads and returns the current value of performance counter specified by
4620 Index. This function is only available on IA-32 and X64.
4622 @param Index The 32-bit Performance Counter index to read.
4624 @return The value of the PMC specified by Index.
4634 Sets up a monitor buffer that is used by AsmMwait().
4636 Executes a MONITOR instruction with the register state specified by Eax, Ecx
4637 and Edx. Returns Eax. This function is only available on IA-32 and X64.
4639 @param Eax The value to load into EAX or RAX before executing the MONITOR
4641 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4643 @param Edx The value to load into EDX or RDX before executing the MONITOR
4658 Executes an MWAIT instruction.
4660 Executes an MWAIT instruction with the register state specified by Eax and
4661 Ecx. Returns Eax. This function is only available on IA-32 and X64.
4663 @param Eax The value to load into EAX or RAX before executing the MONITOR
4665 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4679 Executes a WBINVD instruction.
4681 Executes a WBINVD instruction. This function is only available on IA-32 and
4692 Executes a INVD instruction.
4694 Executes a INVD instruction. This function is only available on IA-32 and
4705 Flushes a cache line from all the instruction and data caches within the
4706 coherency domain of the CPU.
4708 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
4709 This function is only available on IA-32 and X64.
4711 @param LinearAddress The address of the cache line to flush. If the CPU is
4712 in a physical addressing mode, then LinearAddress is a
4713 physical address. If the CPU is in a virtual
4714 addressing mode, then LinearAddress is a virtual
4717 @return LinearAddress
4722 IN VOID
*LinearAddress
4726 Enables the 32-bit paging mode on the CPU.
4728 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4729 must be properly initialized prior to calling this service. This function
4730 assumes the current execution mode is 32-bit protected mode. This function is
4731 only available on IA-32. After the 32-bit paging mode is enabled, control is
4732 transferred to the function specified by EntryPoint using the new stack
4733 specified by NewStack and passing in the parameters specified by Context1 and
4734 Context2. Context1 and Context2 are optional and may be NULL. The function
4735 EntryPoint must never return.
4737 If the current execution mode is not 32-bit protected mode, then ASSERT().
4738 If EntryPoint is NULL, then ASSERT().
4739 If NewStack is NULL, then ASSERT().
4741 There are a number of constraints that must be followed before calling this
4743 1) Interrupts must be disabled.
4744 2) The caller must be in 32-bit protected mode with flat descriptors. This
4745 means all descriptors must have a base of 0 and a limit of 4GB.
4746 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
4748 4) CR3 must point to valid page tables that will be used once the transition
4749 is complete, and those page tables must guarantee that the pages for this
4750 function and the stack are identity mapped.
4752 @param EntryPoint A pointer to function to call with the new stack after
4754 @param Context1 A pointer to the context to pass into the EntryPoint
4755 function as the first parameter after paging is enabled.
4756 @param Context2 A pointer to the context to pass into the EntryPoint
4757 function as the second parameter after paging is enabled.
4758 @param NewStack A pointer to the new stack to use for the EntryPoint
4759 function after paging is enabled.
4765 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4766 IN VOID
*Context1
, OPTIONAL
4767 IN VOID
*Context2
, OPTIONAL
4772 Disables the 32-bit paging mode on the CPU.
4774 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
4775 mode. This function assumes the current execution mode is 32-paged protected
4776 mode. This function is only available on IA-32. After the 32-bit paging mode
4777 is disabled, control is transferred to the function specified by EntryPoint
4778 using the new stack specified by NewStack and passing in the parameters
4779 specified by Context1 and Context2. Context1 and Context2 are optional and
4780 may be NULL. The function EntryPoint must never return.
4782 If the current execution mode is not 32-bit paged mode, then ASSERT().
4783 If EntryPoint is NULL, then ASSERT().
4784 If NewStack is NULL, then ASSERT().
4786 There are a number of constraints that must be followed before calling this
4788 1) Interrupts must be disabled.
4789 2) The caller must be in 32-bit paged mode.
4790 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
4791 4) CR3 must point to valid page tables that guarantee that the pages for
4792 this function and the stack are identity mapped.
4794 @param EntryPoint A pointer to function to call with the new stack after
4796 @param Context1 A pointer to the context to pass into the EntryPoint
4797 function as the first parameter after paging is disabled.
4798 @param Context2 A pointer to the context to pass into the EntryPoint
4799 function as the second parameter after paging is
4801 @param NewStack A pointer to the new stack to use for the EntryPoint
4802 function after paging is disabled.
4807 AsmDisablePaging32 (
4808 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4809 IN VOID
*Context1
, OPTIONAL
4810 IN VOID
*Context2
, OPTIONAL
4815 Enables the 64-bit paging mode on the CPU.
4817 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4818 must be properly initialized prior to calling this service. This function
4819 assumes the current execution mode is 32-bit protected mode with flat
4820 descriptors. This function is only available on IA-32. After the 64-bit
4821 paging mode is enabled, control is transferred to the function specified by
4822 EntryPoint using the new stack specified by NewStack and passing in the
4823 parameters specified by Context1 and Context2. Context1 and Context2 are
4824 optional and may be 0. The function EntryPoint must never return.
4826 If the current execution mode is not 32-bit protected mode with flat
4827 descriptors, then ASSERT().
4828 If EntryPoint is 0, then ASSERT().
4829 If NewStack is 0, then ASSERT().
4831 @param Cs The 16-bit selector to load in the CS before EntryPoint
4832 is called. The descriptor in the GDT that this selector
4833 references must be setup for long mode.
4834 @param EntryPoint The 64-bit virtual address of the function to call with
4835 the new stack after paging is enabled.
4836 @param Context1 The 64-bit virtual address of the context to pass into
4837 the EntryPoint function as the first parameter after
4839 @param Context2 The 64-bit virtual address of the context to pass into
4840 the EntryPoint function as the second parameter after
4842 @param NewStack The 64-bit virtual address of the new stack to use for
4843 the EntryPoint function after paging is enabled.
4849 IN UINT16 CodeSelector
,
4850 IN UINT64 EntryPoint
,
4851 IN UINT64 Context1
, OPTIONAL
4852 IN UINT64 Context2
, OPTIONAL
4857 Disables the 64-bit paging mode on the CPU.
4859 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
4860 mode. This function assumes the current execution mode is 64-paging mode.
4861 This function is only available on X64. After the 64-bit paging mode is
4862 disabled, control is transferred to the function specified by EntryPoint
4863 using the new stack specified by NewStack and passing in the parameters
4864 specified by Context1 and Context2. Context1 and Context2 are optional and
4865 may be 0. The function EntryPoint must never return.
4867 If the current execution mode is not 64-bit paged mode, then ASSERT().
4868 If EntryPoint is 0, then ASSERT().
4869 If NewStack is 0, then ASSERT().
4871 @param Cs The 16-bit selector to load in the CS before EntryPoint
4872 is called. The descriptor in the GDT that this selector
4873 references must be setup for 32-bit protected mode.
4874 @param EntryPoint The 64-bit virtual address of the function to call with
4875 the new stack after paging is disabled.
4876 @param Context1 The 64-bit virtual address of the context to pass into
4877 the EntryPoint function as the first parameter after
4879 @param Context2 The 64-bit virtual address of the context to pass into
4880 the EntryPoint function as the second parameter after
4882 @param NewStack The 64-bit virtual address of the new stack to use for
4883 the EntryPoint function after paging is disabled.
4888 AsmDisablePaging64 (
4889 IN UINT16 CodeSelector
,
4890 IN UINT32 EntryPoint
,
4891 IN UINT32 Context1
, OPTIONAL
4892 IN UINT32 Context2
, OPTIONAL
4897 // 16-bit thunking services
4901 Retrieves the properties for 16-bit thunk functions.
4903 Computes the size of the buffer and stack below 1MB required to use the
4904 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
4905 buffer size is returned in RealModeBufferSize, and the stack size is returned
4906 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
4907 then the actual minimum stack size is ExtraStackSize plus the maximum number
4908 of bytes that need to be passed to the 16-bit real mode code.
4910 If RealModeBufferSize is NULL, then ASSERT().
4911 If ExtraStackSize is NULL, then ASSERT().
4913 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
4914 required to use the 16-bit thunk functions.
4915 @param ExtraStackSize A pointer to the extra size of stack below 1MB
4916 that the 16-bit thunk functions require for
4917 temporary storage in the transition to and from
4923 AsmGetThunk16Properties (
4924 OUT UINT32
*RealModeBufferSize
,
4925 OUT UINT32
*ExtraStackSize
4929 Prepares all structures a code required to use AsmThunk16().
4931 Prepares all structures and code required to use AsmThunk16().
4933 If ThunkContext is NULL, then ASSERT().
4935 @param ThunkContext A pointer to the context structure that describes the
4936 16-bit real mode code to call.
4942 OUT THUNK_CONTEXT
*ThunkContext
4946 Transfers control to a 16-bit real mode entry point and returns the results.
4948 Transfers control to a 16-bit real mode entry point and returns the results.
4949 AsmPrepareThunk16() must be called with ThunkContext before this function is
4952 If ThunkContext is NULL, then ASSERT().
4953 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
4955 @param ThunkContext A pointer to the context structure that describes the
4956 16-bit real mode code to call.
4962 IN OUT THUNK_CONTEXT
*ThunkContext
4966 Prepares all structures and code for a 16-bit real mode thunk, transfers
4967 control to a 16-bit real mode entry point, and returns the results.
4969 Prepares all structures and code for a 16-bit real mode thunk, transfers
4970 control to a 16-bit real mode entry point, and returns the results. If the
4971 caller only need to perform a single 16-bit real mode thunk, then this
4972 service should be used. If the caller intends to make more than one 16-bit
4973 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
4974 once and AsmThunk16() can be called for each 16-bit real mode thunk.
4976 If ThunkContext is NULL, then ASSERT().
4978 @param ThunkContext A pointer to the context structure that describes the
4979 16-bit real mode code to call.
4984 AsmPrepareAndThunk16 (
4985 IN OUT THUNK_CONTEXT
*ThunkContext
4989 Transfers control to a function starting with a new stack.
4991 Transfers control to the function specified by EntryPoint using the new stack
4992 specified by NewStack and passing in the parameters specified by Context1 and
4993 Context2. Context1 and Context2 are optional and may be NULL. The function
4994 EntryPoint must never return.
4996 If EntryPoint is NULL, then ASSERT().
4997 If NewStack is NULL, then ASSERT().
4999 @param EntryPoint A pointer to function to call with the new stack.
5000 @param Context1 A pointer to the context to pass into the EntryPoint
5002 @param Context2 A pointer to the context to pass into the EntryPoint
5004 @param NewStack A pointer to the new stack to use for the EntryPoint
5006 @param NewBsp A pointer to the new memory location for RSE backing
5012 AsmSwitchStackAndBackingStore (
5013 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
5014 IN VOID
*Context1
, OPTIONAL
5015 IN VOID
*Context2
, OPTIONAL
5028 // IPF Specific functions
5033 Performs a PAL call using static calling convention.
5035 An internal function to perform a PAL call using static calling convention.
5037 @param PalEntryPoint The entry point address of PAL. The address in ar.kr5
5038 would be used if this parameter were NULL on input.
5039 @param Arg1 The first argument of a PAL call.
5040 @param Arg1 The second argument of a PAL call.
5041 @param Arg1 The third argument of a PAL call.
5042 @param Arg1 The fourth argument of a PAL call.
5044 @return The values returned in r8, r9, r10 and r11.
5049 IN CONST VOID
*PalEntryPoint
,
5058 Returns the current value of ar.itc.
5060 An internal function to return the current value of ar.itc, which is the
5063 @return The currect value of ar.itc
5073 Flush a range of cache lines in the cache coherency domain of the calling
5076 Invalidates the cache lines specified by Address and Length. If Address is
5077 not aligned on a cache line boundary, then entire cache line containing
5078 Address is invalidated. If Address + Length is not aligned on a cache line
5079 boundary, then the entire instruction cache line containing Address + Length
5080 -1 is invalidated. This function may choose to invalidate the entire
5081 instruction cache if that is more efficient than invalidating the specified
5082 range. If Length is 0, the no instruction cache lines are invalidated.
5083 Address is returned.
5085 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
5087 @param Address The base address of the instruction lines to invalidate. If
5088 the CPU is in a physical addressing mode, then Address is a
5089 physical address. If the CPU is in a virtual addressing mode,
5090 then Address is a virtual address.
5092 @param Length The number of bytes to invalidate from the instruction cache.
5099 IpfFlushCacheRange (