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 #elif defined (MDE_CPU_IPF)
45 // IPF context buffer used by SetJump() and LongJump()
80 UINT64 AfterSpillUNAT
;
86 } BASE_LIBRARY_JUMP_BUFFER
;
88 #elif defined (MDE_CPU_X64)
90 // X64 context buffer used by SetJump() and LongJump()
103 } BASE_LIBRARY_JUMP_BUFFER
;
105 #elif defined (MDE_CPU_EBC)
107 // EBC context buffer used by SetJump() and LongJump()
115 } BASE_LIBRARY_JUMP_BUFFER
;
118 #error Unknown Processor Type
126 Copies one Null-terminated Unicode string to another Null-terminated Unicode
127 string and returns the new Unicode string.
129 This function copies the contents of the Unicode string Source to the Unicode
130 string Destination, and returns Destination. If Source and Destination
131 overlap, then the results are undefined.
133 If Destination is NULL, then ASSERT().
134 If Source is NULL, then ASSERT().
135 If Source and Destination overlap, then ASSERT().
136 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
137 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
139 @param Destination Pointer to a Null-terminated Unicode string.
140 @param Source Pointer to a Null-terminated Unicode string.
148 OUT CHAR16
*Destination
,
149 IN CONST CHAR16
*Source
153 Copies one Null-terminated Unicode string with a maximum length to another
154 Null-terminated Unicode string with a maximum length and returns the new
157 This function copies the contents of the Unicode string Source to the Unicode
158 string Destination, and returns Destination. At most, Length Unicode
159 characters are copied from Source to Destination. If Length is 0, then
160 Destination is returned unmodified. If Length is greater that the number of
161 Unicode characters in Source, then Destination is padded with Null Unicode
162 characters. If Source and Destination overlap, then the results are
165 If Destination is NULL, then ASSERT().
166 If Source is NULL, then ASSERT().
167 If Source and Destination overlap, then ASSERT().
168 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
169 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
171 @param Destination Pointer to a Null-terminated Unicode string.
172 @param Source Pointer to a Null-terminated Unicode string.
173 @param Length Maximum number of Unicode characters to copy.
181 OUT CHAR16
*Destination
,
182 IN CONST CHAR16
*Source
,
187 Returns the length of a Null-terminated Unicode string.
189 This function returns the number of Unicode characters in the Null-terminated
190 Unicode string specified by String.
192 If String is NULL, then ASSERT().
193 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
194 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
196 @param String Pointer to a Null-terminated Unicode string.
198 @return The length of String.
204 IN CONST CHAR16
*String
208 Returns the size of a Null-terminated Unicode string in bytes, including the
211 This function returns the size, in bytes, of the Null-terminated Unicode
212 string specified by String.
214 If String is NULL, then ASSERT().
215 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
216 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
218 @param String Pointer to a Null-terminated Unicode string.
220 @return The size of String.
226 IN CONST CHAR16
*String
230 Compares two Null-terminated Unicode strings, and returns the difference
231 between the first mismatched Unicode characters.
233 This function compares the Null-terminated Unicode string FirstString to the
234 Null-terminated Unicode string SecondString. If FirstString is identical to
235 SecondString, then 0 is returned. Otherwise, the value returned is the first
236 mismatched Unicode character in SecondString subtracted from the first
237 mismatched Unicode character in FirstString.
239 If FirstString is NULL, then ASSERT().
240 If SecondString is NULL, then ASSERT().
241 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
242 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
243 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
244 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
246 @param FirstString Pointer to a Null-terminated Unicode string.
247 @param SecondString Pointer to a Null-terminated Unicode string.
249 @retval 0 FirstString is identical to SecondString.
250 @retval !=0 FirstString is not identical to SecondString.
256 IN CONST CHAR16
*FirstString
,
257 IN CONST CHAR16
*SecondString
261 Compares two Null-terminated Unicode strings with maximum lengths, and
262 returns the difference between the first mismatched Unicode characters.
264 This function compares the Null-terminated Unicode string FirstString to the
265 Null-terminated Unicode string SecondString. At most, Length Unicode
266 characters will be compared. If Length is 0, then 0 is returned. If
267 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
268 value returned is the first mismatched Unicode character in SecondString
269 subtracted from the first mismatched Unicode character in FirstString.
271 If FirstString is NULL, then ASSERT().
272 If SecondString is NULL, then ASSERT().
273 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
274 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
275 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
276 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
278 @param FirstString Pointer to a Null-terminated Unicode string.
279 @param SecondString Pointer to a Null-terminated Unicode string.
280 @param Length Maximum number of Unicode characters to compare.
282 @retval 0 FirstString is identical to SecondString.
283 @retval !=0 FirstString is not identical to SecondString.
289 IN CONST CHAR16
*FirstString
,
290 IN CONST CHAR16
*SecondString
,
295 Concatenates one Null-terminated Unicode string to another Null-terminated
296 Unicode string, and returns the concatenated Unicode string.
298 This function concatenates two Null-terminated Unicode strings. The contents
299 of Null-terminated Unicode string Source are concatenated to the end of
300 Null-terminated Unicode string Destination. The Null-terminated concatenated
301 Unicode String is returned. If Source and Destination overlap, then the
302 results are undefined.
304 If Destination is NULL, then ASSERT().
305 If Source is NULL, then ASSERT().
306 If Source and Destination overlap, then ASSERT().
307 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
308 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
309 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
310 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
311 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
312 and Source results in a Unicode string with more than
313 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
315 @param Destination Pointer to a Null-terminated Unicode string.
316 @param Source Pointer to a Null-terminated Unicode string.
324 IN OUT CHAR16
*Destination
,
325 IN CONST CHAR16
*Source
329 Concatenates one Null-terminated Unicode string with a maximum length to the
330 end of another Null-terminated Unicode string, and returns the concatenated
333 This function concatenates two Null-terminated Unicode strings. The contents
334 of Null-terminated Unicode string Source are concatenated to the end of
335 Null-terminated Unicode string Destination, and Destination is returned. At
336 most, Length Unicode characters are concatenated from Source to the end of
337 Destination, and Destination is always Null-terminated. If Length is 0, then
338 Destination is returned unmodified. If Source and Destination overlap, then
339 the results are undefined.
341 If Destination is NULL, then ASSERT().
342 If Source is NULL, then ASSERT().
343 If Source and Destination overlap, then ASSERT().
344 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
345 than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
346 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
347 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
348 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
349 and Source results in a Unicode string with more than
350 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().
352 @param Destination Pointer to a Null-terminated Unicode string.
353 @param Source Pointer to a Null-terminated Unicode string.
354 @param Length Maximum number of Unicode characters to concatenate from
363 IN OUT CHAR16
*Destination
,
364 IN CONST CHAR16
*Source
,
369 Copies one Null-terminated ASCII string to another Null-terminated ASCII
370 string and returns the new ASCII string.
372 This function copies the contents of the ASCII string Source to the ASCII
373 string Destination, and returns Destination. If Source and Destination
374 overlap, then the results are undefined.
376 If Destination is NULL, then ASSERT().
377 If Source is NULL, then ASSERT().
378 If Source and Destination overlap, then ASSERT().
379 If PcdMaximumAsciiStringLength is not zero and Source contains more than
380 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
382 @param Destination Pointer to a Null-terminated ASCII string.
383 @param Source Pointer to a Null-terminated ASCII string.
391 OUT CHAR8
*Destination
,
392 IN CONST CHAR8
*Source
396 Copies one Null-terminated ASCII string with a maximum length to another
397 Null-terminated ASCII string with a maximum length and returns the new ASCII
400 This function copies the contents of the ASCII string Source to the ASCII
401 string Destination, and returns Destination. At most, Length ASCII characters
402 are copied from Source to Destination. If Length is 0, then Destination is
403 returned unmodified. If Length is greater that the number of ASCII characters
404 in Source, then Destination is padded with Null ASCII characters. If Source
405 and Destination overlap, then the results are undefined.
407 If Destination is NULL, then ASSERT().
408 If Source is NULL, then ASSERT().
409 If Source and Destination overlap, then ASSERT().
410 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
411 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
413 @param Destination Pointer to a Null-terminated ASCII string.
414 @param Source Pointer to a Null-terminated ASCII string.
415 @param Length Maximum number of ASCII characters to copy.
423 OUT CHAR8
*Destination
,
424 IN CONST CHAR8
*Source
,
429 Returns the length of a Null-terminated ASCII string.
431 This function returns the number of ASCII characters in the Null-terminated
432 ASCII string specified by String.
434 If String is NULL, then ASSERT().
435 If PcdMaximumAsciiStringLength is not zero and String contains more than
436 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
438 @param String Pointer to a Null-terminated ASCII string.
440 @return The length of String.
446 IN CONST CHAR8
*String
450 Returns the size of a Null-terminated ASCII string in bytes, including the
453 This function returns the size, in bytes, of the Null-terminated ASCII string
456 If String is NULL, then ASSERT().
457 If PcdMaximumAsciiStringLength is not zero and String contains more than
458 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
460 @param String Pointer to a Null-terminated ASCII string.
462 @return The size of String.
468 IN CONST CHAR8
*String
472 Compares two Null-terminated ASCII strings, and returns the difference
473 between the first mismatched ASCII characters.
475 This function compares the Null-terminated ASCII string FirstString to the
476 Null-terminated ASCII string SecondString. If FirstString is identical to
477 SecondString, then 0 is returned. Otherwise, the value returned is the first
478 mismatched ASCII character in SecondString subtracted from the first
479 mismatched ASCII character in FirstString.
481 If FirstString is NULL, then ASSERT().
482 If SecondString is NULL, then ASSERT().
483 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
484 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
485 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
486 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
488 @param FirstString Pointer to a Null-terminated ASCII string.
489 @param SecondString Pointer to a Null-terminated ASCII string.
491 @retval 0 FirstString is identical to SecondString.
492 @retval !=0 FirstString is not identical to SecondString.
498 IN CONST CHAR8
*FirstString
,
499 IN CONST CHAR8
*SecondString
503 Performs a case insensitive comparison of two Null-terminated ASCII strings,
504 and returns the difference between the first mismatched ASCII characters.
506 This function performs a case insensitive comparison of the Null-terminated
507 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
508 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
509 value returned is the first mismatched lower case ASCII character in
510 SecondString subtracted from the first mismatched lower case ASCII character
513 If FirstString is NULL, then ASSERT().
514 If SecondString is NULL, then ASSERT().
515 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
516 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
517 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
518 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
520 @param FirstString Pointer to a Null-terminated ASCII string.
521 @param SecondString Pointer to a Null-terminated ASCII string.
523 @retval 0 FirstString is identical to SecondString using case insensitive
525 @retval !=0 FirstString is not identical to SecondString using case
526 insensitive comparisons.
532 IN CONST CHAR8
*FirstString
,
533 IN CONST CHAR8
*SecondString
537 Compares two Null-terminated ASCII strings with maximum lengths, and returns
538 the difference between the first mismatched ASCII characters.
540 This function compares the Null-terminated ASCII string FirstString to the
541 Null-terminated ASCII string SecondString. At most, Length ASCII characters
542 will be compared. If Length is 0, then 0 is returned. If FirstString is
543 identical to SecondString, then 0 is returned. Otherwise, the value returned
544 is the first mismatched ASCII character in SecondString subtracted from the
545 first mismatched ASCII character in FirstString.
547 If FirstString is NULL, then ASSERT().
548 If SecondString is NULL, then ASSERT().
549 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
550 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
551 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
552 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
554 @param FirstString Pointer to a Null-terminated ASCII string.
555 @param SecondString Pointer to a Null-terminated ASCII string.
557 @retval 0 FirstString is identical to SecondString.
558 @retval !=0 FirstString is not identical to SecondString.
564 IN CONST CHAR8
*FirstString
,
565 IN CONST CHAR8
*SecondString
,
570 Concatenates one Null-terminated ASCII string to another Null-terminated
571 ASCII string, and returns the concatenated ASCII string.
573 This function concatenates two Null-terminated ASCII strings. The contents of
574 Null-terminated ASCII string Source are concatenated to the end of Null-
575 terminated ASCII string Destination. The Null-terminated concatenated ASCII
578 If Destination is NULL, then ASSERT().
579 If Source is NULL, then ASSERT().
580 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
581 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
582 If PcdMaximumAsciiStringLength is not zero and Source contains more than
583 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
584 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
585 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
586 ASCII characters, then ASSERT().
588 @param Destination Pointer to a Null-terminated ASCII string.
589 @param Source Pointer to a Null-terminated ASCII string.
597 IN OUT CHAR8
*Destination
,
598 IN CONST CHAR8
*Source
602 Concatenates one Null-terminated ASCII string with a maximum length to the
603 end of another Null-terminated ASCII string, and returns the concatenated
606 This function concatenates two Null-terminated ASCII strings. The contents
607 of Null-terminated ASCII string Source are concatenated to the end of Null-
608 terminated ASCII string Destination, and Destination is returned. At most,
609 Length ASCII characters are concatenated from Source to the end of
610 Destination, and Destination is always Null-terminated. If Length is 0, then
611 Destination is returned unmodified. If Source and Destination overlap, then
612 the results are undefined.
614 If Destination is NULL, then ASSERT().
615 If Source is NULL, then ASSERT().
616 If Source and Destination overlap, then ASSERT().
617 If PcdMaximumAsciiStringLength is not zero, and Destination contains more
618 than PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
619 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
620 PcdMaximumAsciiStringLength ASCII characters, then ASSERT().
621 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
622 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
623 ASCII characters, then ASSERT().
625 @param Destination Pointer to a Null-terminated ASCII string.
626 @param Source Pointer to a Null-terminated ASCII string.
627 @param Length Maximum number of ASCII characters to concatenate from
636 IN OUT CHAR8
*Destination
,
637 IN CONST CHAR8
*Source
,
642 // LIST_ENTRY definition
644 typedef struct _LIST_ENTRY LIST_ENTRY
;
647 LIST_ENTRY
*ForwardLink
;
648 LIST_ENTRY
*BackLink
;
652 // Linked List Functions and Macros
656 Initializes the head node of a doubly linked list that is declared as a
657 global variable in a module.
659 Initializes the forward and backward links of a new linked list. After
660 initializing a linked list with this macro, the other linked list functions
661 may be used to add and remove nodes from the linked list. This macro results
662 in smaller executables by initializing the linked list in the data section,
663 instead if calling the InitializeListHead() function to perform the
664 equivalent operation.
666 @param ListHead The head note of a list to initiailize.
669 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
672 Initializes the head node of a doubly linked list, and returns the pointer to
673 the head node of the doubly linked list.
675 Initializes the forward and backward links of a new linked list. After
676 initializing a linked list with this function, the other linked list
677 functions may be used to add and remove nodes from the linked list. It is up
678 to the caller of this function to allocate the memory for ListHead.
680 If ListHead is NULL, then ASSERT().
682 @param ListHead A pointer to the head node of a new doubly linked list.
690 IN LIST_ENTRY
*ListHead
694 Adds a node to the beginning of a doubly linked list, and returns the pointer
695 to the head node of the doubly linked list.
697 Adds the node Entry at the beginning of the doubly linked list denoted by
698 ListHead, and returns ListHead.
700 If ListHead is NULL, then ASSERT().
701 If Entry is NULL, then ASSERT().
702 If ListHead was not initialized with InitializeListHead(), then ASSERT().
703 If PcdMaximumLinkedListLenth is not zero, and ListHead contains more than
704 PcdMaximumLinkedListLenth nodes, then ASSERT().
706 @param ListHead A pointer to the head node of a doubly linked list.
707 @param Entry A pointer to a node that is to be inserted at the beginning
708 of a doubly linked list.
716 IN LIST_ENTRY
*ListHead
,
721 Adds a node to the end of a doubly linked list, and returns the pointer to
722 the head node of the doubly linked list.
724 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
725 and returns ListHead.
727 If ListHead is NULL, then ASSERT().
728 If Entry is NULL, then ASSERT().
729 If ListHead was not initialized with InitializeListHead(), then ASSERT().
730 If PcdMaximumLinkedListLenth is not zero, and ListHead contains more than
731 PcdMaximumLinkedListLenth nodes, then ASSERT().
733 @param ListHead A pointer to the head node of a doubly linked list.
734 @param Entry A pointer to a node that is to be added at the end of the
743 IN LIST_ENTRY
*ListHead
,
748 Retrieves the first node of a doubly linked list.
750 Returns the first node of a doubly linked list. List must have been
751 initialized with InitializeListHead(). If List is empty, then NULL is
754 If List is NULL, then ASSERT().
755 If List was not initialized with InitializeListHead(), then ASSERT().
756 If PcdMaximumLinkedListLenth is not zero, and List contains more than
757 PcdMaximumLinkedListLenth nodes, then ASSERT().
759 @param List A pointer to the head node of a doubly linked list.
761 @return The first node of a doubly linked list.
762 @retval NULL The list is empty.
768 IN CONST LIST_ENTRY
*List
772 Retrieves the next node of a doubly linked list.
774 Returns the node of a doubly linked list that follows Node. List must have
775 been initialized with InitializeListHead(). If List is empty, then List is
778 If List is NULL, then ASSERT().
779 If Node is NULL, then ASSERT().
780 If List was not initialized with InitializeListHead(), then ASSERT().
781 If PcdMaximumLinkedListLenth is not zero, and List contains more than
782 PcdMaximumLinkedListLenth nodes, then ASSERT().
783 If Node is not a node in List, then ASSERT().
785 @param List A pointer to the head node of a doubly linked list.
786 @param Node A pointer to a node in the doubly linked list.
788 @return Pointer to the next node if one exists. Otherwise a null value which
789 is actually List is returned.
795 IN CONST LIST_ENTRY
*List
,
796 IN CONST LIST_ENTRY
*Node
800 Checks to see if a doubly linked list is empty or not.
802 Checks to see if the doubly linked list is empty. If the linked list contains
803 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
805 If ListHead is NULL, then ASSERT().
806 If ListHead was not initialized with InitializeListHead(), then ASSERT().
807 If PcdMaximumLinkedListLenth is not zero, and List contains more than
808 PcdMaximumLinkedListLenth nodes, then ASSERT().
810 @param ListHead A pointer to the head node of a doubly linked list.
812 @retval TRUE The linked list is empty.
813 @retval FALSE The linked list is not empty.
819 IN CONST LIST_ENTRY
*ListHead
823 Determines if a node in a doubly linked list is null.
825 Returns FALSE if Node is one of the nodes in the doubly linked list specified
826 by List. Otherwise, TRUE is returned. List must have been initialized with
827 InitializeListHead().
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 and Node is not equal to 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 @retval TRUE Node is one of the nodes in the doubly linked list.
840 @retval FALSE Node is not one of the nodes in the doubly linked list.
846 IN CONST LIST_ENTRY
*List
,
847 IN CONST LIST_ENTRY
*Node
851 Determines if a node the last node in a doubly linked list.
853 Returns TRUE if Node is the last node in the doubly linked list specified by
854 List. Otherwise, FALSE is returned. List must have been initialized with
855 InitializeListHead().
857 If List is NULL, then ASSERT().
858 If Node is NULL, then ASSERT().
859 If List was not initialized with InitializeListHead(), then ASSERT().
860 If PcdMaximumLinkedListLenth is not zero, and List contains more than
861 PcdMaximumLinkedListLenth nodes, then ASSERT().
862 If Node is not a node in List, then ASSERT().
864 @param List A pointer to the head node of a doubly linked list.
865 @param Node A pointer to a node in the doubly linked list.
867 @retval TRUE Node is the last node in the linked list.
868 @retval FALSE Node is not the last node in the linked list.
874 IN CONST LIST_ENTRY
*List
,
875 IN CONST LIST_ENTRY
*Node
879 Swaps the location of two nodes in a doubly linked list, and returns the
880 first node after the swap.
882 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
883 Otherwise, the location of the FirstEntry node is swapped with the location
884 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
885 same double linked list as FirstEntry and that double linked list must have
886 been initialized with InitializeListHead(). SecondEntry is returned after the
889 If FirstEntry is NULL, then ASSERT().
890 If SecondEntry is NULL, then ASSERT().
891 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
892 If PcdMaximumLinkedListLenth is not zero, and the linked list containing
893 FirstEntry and SecondEntry contains more than PcdMaximumLinkedListLenth
894 nodes, then ASSERT().
896 @param FirstEntry A pointer to a node in a linked list.
897 @param SecondEntry A pointer to another node in the same linked list.
903 IN LIST_ENTRY
*FirstEntry
,
904 IN LIST_ENTRY
*SecondEntry
908 Removes a node from a doubly linked list, and returns the node that follows
911 Removes the node Entry from a doubly linked list. It is up to the caller of
912 this function to release the memory used by this node if that is required. On
913 exit, the node following Entry in the doubly linked list is returned. If
914 Entry is the only node in the linked list, then the head node of the linked
917 If Entry is NULL, then ASSERT().
918 If Entry is the head node of an empty list, then ASSERT().
919 If PcdMaximumLinkedListLenth is not zero, and the linked list containing
920 Entry contains more than PcdMaximumLinkedListLenth nodes, then ASSERT().
922 @param Entry A pointer to a node in a linked list
930 IN CONST LIST_ENTRY
*Entry
938 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
939 with zeros. The shifted value is returned.
941 This function shifts the 64-bit value Operand to the left by Count bits. The
942 low Count bits are set to zero. The shifted value is returned.
944 If Count is greater than 63, then ASSERT().
946 @param Operand The 64-bit operand to shift left.
947 @param Count The number of bits to shift left.
949 @return Operand << Count
960 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
961 filled with zeros. The shifted value is returned.
963 This function shifts the 64-bit value Operand to the right by Count bits. The
964 high Count bits are set to zero. The shifted value is returned.
966 If Count is greater than 63, then ASSERT().
968 @param Operand The 64-bit operand to shift right.
969 @param Count The number of bits to shift right.
971 @return Operand >> Count
982 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
983 with original integer's bit 63. The shifted value is returned.
985 This function shifts the 64-bit value Operand to the right by Count bits. The
986 high Count bits are set to bit 63 of Operand. The shifted value is returned.
988 If Count is greater than 63, then ASSERT().
990 @param Operand The 64-bit operand to shift right.
991 @param Count The number of bits to shift right.
993 @return Operand >> Count
1004 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1005 with the high bits that were rotated.
1007 This function rotates the 32-bit value Operand to the left by Count bits. The
1008 low Count bits are fill with the high Count bits of Operand. The rotated
1011 If Count is greater than 31, then ASSERT().
1013 @param Operand The 32-bit operand to rotate left.
1014 @param Count The number of bits to rotate left.
1016 @return Operand <<< Count
1027 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1028 with the low bits that were rotated.
1030 This function rotates the 32-bit value Operand to the right by Count bits.
1031 The high Count bits are fill with the low Count bits of Operand. The rotated
1034 If Count is greater than 31, then ASSERT().
1036 @param Operand The 32-bit operand to rotate right.
1037 @param Count The number of bits to rotate right.
1039 @return Operand >>> Count
1050 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1051 with the high bits that were rotated.
1053 This function rotates the 64-bit value Operand to the left by Count bits. The
1054 low Count bits are fill with the high Count bits of Operand. The rotated
1057 If Count is greater than 63, then ASSERT().
1059 @param Operand The 64-bit operand to rotate left.
1060 @param Count The number of bits to rotate left.
1062 @return Operand <<< Count
1073 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1074 with the high low bits that were rotated.
1076 This function rotates the 64-bit value Operand to the right by Count bits.
1077 The high Count bits are fill with the low Count bits of Operand. The rotated
1080 If Count is greater than 63, then ASSERT().
1082 @param Operand The 64-bit operand to rotate right.
1083 @param Count The number of bits to rotate right.
1085 @return Operand >>> Count
1096 Returns the bit position of the lowest bit set in a 32-bit value.
1098 This function computes the bit position of the lowest bit set in the 32-bit
1099 value specified by Operand. If Operand is zero, then -1 is returned.
1100 Otherwise, a value between 0 and 31 is returned.
1102 @param Operand The 32-bit operand to evaluate.
1104 @return Position of the lowest bit set in Operand if found.
1105 @retval -1 Operand is zero.
1115 Returns the bit position of the lowest bit set in a 64-bit value.
1117 This function computes the bit position of the lowest bit set in the 64-bit
1118 value specified by Operand. If Operand is zero, then -1 is returned.
1119 Otherwise, a value between 0 and 63 is returned.
1121 @param Operand The 64-bit operand to evaluate.
1123 @return Position of the lowest bit set in Operand if found.
1124 @retval -1 Operand is zero.
1134 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1137 This function computes the bit position of the highest bit set in the 32-bit
1138 value specified by Operand. If Operand is zero, then -1 is returned.
1139 Otherwise, a value between 0 and 31 is returned.
1141 @param Operand The 32-bit operand to evaluate.
1143 @return Position of the highest bit set in Operand if found.
1144 @retval -1 Operand is zero.
1154 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1157 This function computes the bit position of the highest bit set in the 64-bit
1158 value specified by Operand. If Operand is zero, then -1 is returned.
1159 Otherwise, a value between 0 and 63 is returned.
1161 @param Operand The 64-bit operand to evaluate.
1163 @return Position of the highest bit set in Operand if found.
1164 @retval -1 Operand is zero.
1174 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1175 1 << HighBitSet32(x).
1177 This function computes the value of the highest bit set in the 32-bit value
1178 specified by Operand. If Operand is zero, then zero is returned.
1180 @param Operand The 32-bit operand to evaluate.
1182 @return 1 << HighBitSet32(Operand)
1183 @retval 0 Operand is zero.
1193 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1194 1 << HighBitSet64(x).
1196 This function computes the value of the highest bit set in the 64-bit value
1197 specified by Operand. If Operand is zero, then zero is returned.
1199 @param Operand The 64-bit operand to evaluate.
1201 @return 1 << HighBitSet64(Operand)
1202 @retval 0 Operand is zero.
1212 Switches the endianess of a 16-bit integer.
1214 This function swaps the bytes in a 16-bit unsigned value to switch the value
1215 from little endian to big endian or vice versa. The byte swapped value is
1218 @param Operand A 16-bit unsigned value.
1220 @return The byte swaped Operand.
1230 Switches the endianess of a 32-bit integer.
1232 This function swaps the bytes in a 32-bit unsigned value to switch the value
1233 from little endian to big endian or vice versa. The byte swapped value is
1236 @param Operand A 32-bit unsigned value.
1238 @return The byte swaped Operand.
1248 Switches the endianess of a 64-bit integer.
1250 This function swaps the bytes in a 64-bit unsigned value to switch the value
1251 from little endian to big endian or vice versa. The byte swapped value is
1254 @param Operand A 64-bit unsigned value.
1256 @return The byte swaped Operand.
1266 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1267 generates a 64-bit unsigned result.
1269 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1270 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1271 bit unsigned result is returned.
1273 If the result overflows, then ASSERT().
1275 @param Multiplicand A 64-bit unsigned value.
1276 @param Multiplier A 32-bit unsigned value.
1278 @return Multiplicand * Multiplier
1284 IN UINT64 Multiplicand
,
1285 IN UINT32 Multiplier
1289 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1290 generates a 64-bit unsigned result.
1292 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1293 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1294 bit unsigned result is returned.
1296 If the result overflows, then ASSERT().
1298 @param Multiplicand A 64-bit unsigned value.
1299 @param Multiplier A 64-bit unsigned value.
1301 @return Multiplicand * Multiplier
1307 IN UINT64 Multiplicand
,
1308 IN UINT64 Multiplier
1312 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1313 64-bit signed result.
1315 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1316 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1317 signed result is returned.
1319 If the result overflows, then ASSERT().
1321 @param Multiplicand A 64-bit signed value.
1322 @param Multiplier A 64-bit signed value.
1324 @return Multiplicand * Multiplier
1330 IN INT64 Multiplicand
,
1335 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1336 a 64-bit unsigned result.
1338 This function divides the 64-bit unsigned value Dividend by the 32-bit
1339 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1340 function returns the 64-bit unsigned quotient.
1342 If Divisor is 0, then ASSERT().
1344 @param Dividend A 64-bit unsigned value.
1345 @param Divisor A 32-bit unsigned value.
1347 @return Dividend / Divisor
1358 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1359 a 32-bit unsigned remainder.
1361 This function divides the 64-bit unsigned value Dividend by the 32-bit
1362 unsigned value Divisor and generates a 32-bit remainder. This function
1363 returns the 32-bit unsigned remainder.
1365 If Divisor is 0, then ASSERT().
1367 @param Dividend A 64-bit unsigned value.
1368 @param Divisor A 32-bit unsigned value.
1370 @return Dividend % Divisor
1381 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1382 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1384 This function divides the 64-bit unsigned value Dividend by the 32-bit
1385 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1386 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1387 This function returns the 64-bit unsigned quotient.
1389 If Divisor is 0, then ASSERT().
1391 @param Dividend A 64-bit unsigned value.
1392 @param Divisor A 32-bit unsigned value.
1393 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1394 optional and may be NULL.
1396 @return Dividend / Divisor
1401 DivU64x32Remainder (
1404 OUT UINT32
*Remainder OPTIONAL
1408 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
1409 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
1411 This function divides the 64-bit unsigned value Dividend by the 64-bit
1412 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1413 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
1414 This function returns the 64-bit unsigned quotient.
1416 If Divisor is 0, then ASSERT().
1418 @param Dividend A 64-bit unsigned value.
1419 @param Divisor A 64-bit unsigned value.
1420 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
1421 optional and may be NULL.
1423 @return Dividend / Divisor
1428 DivU64x64Remainder (
1431 OUT UINT64
*Remainder OPTIONAL
1435 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
1436 64-bit signed result and a optional 64-bit signed remainder.
1438 This function divides the 64-bit signed value Dividend by the 64-bit signed
1439 value Divisor and generates a 64-bit signed quotient. If Remainder is not
1440 NULL, then the 64-bit signed remainder is returned in Remainder. This
1441 function returns the 64-bit signed quotient.
1443 If Divisor is 0, then ASSERT().
1445 @param Dividend A 64-bit signed value.
1446 @param Divisor A 64-bit signed value.
1447 @param Remainder A pointer to a 64-bit signed value. This parameter is
1448 optional and may be NULL.
1450 @return Dividend / Divisor
1455 DivS64x64Remainder (
1458 OUT INT64
*Remainder OPTIONAL
1462 Reads a 16-bit value from memory that may be unaligned.
1464 This function returns the 16-bit value pointed to by Buffer. The function
1465 guarantees that the read operation does not produce an alignment fault.
1467 If the Buffer is NULL, then ASSERT().
1469 @param Buffer Pointer to a 16-bit value that may be unaligned.
1477 IN CONST UINT16
*Uint16
1481 Writes a 16-bit value to memory that may be unaligned.
1483 This function writes the 16-bit value specified by Value to Buffer. Value is
1484 returned. The function guarantees that the write operation does not produce
1487 If the Buffer is NULL, then ASSERT().
1489 @param Buffer Pointer to a 16-bit value that may be unaligned.
1490 @param Value 16-bit value to write to Buffer.
1503 Reads a 24-bit value from memory that may be unaligned.
1505 This function returns the 24-bit value pointed to by Buffer. The function
1506 guarantees that the read operation does not produce an alignment fault.
1508 If the Buffer is NULL, then ASSERT().
1510 @param Buffer Pointer to a 24-bit value that may be unaligned.
1512 @return The value read.
1518 IN CONST UINT32
*Buffer
1522 Writes a 24-bit value to memory that may be unaligned.
1524 This function writes the 24-bit value specified by Value to Buffer. Value is
1525 returned. The function guarantees that the write operation does not produce
1528 If the Buffer is NULL, then ASSERT().
1530 @param Buffer Pointer to a 24-bit value that may be unaligned.
1531 @param Value 24-bit value to write to Buffer.
1533 @return The value written.
1544 Reads a 32-bit value from memory that may be unaligned.
1546 This function returns the 32-bit value pointed to by Buffer. The function
1547 guarantees that the read operation does not produce an alignment fault.
1549 If the Buffer is NULL, then ASSERT().
1551 @param Buffer Pointer to a 32-bit value that may be unaligned.
1559 IN CONST UINT32
*Uint32
1563 Writes a 32-bit value to memory that may be unaligned.
1565 This function writes the 32-bit value specified by Value to Buffer. Value is
1566 returned. The function guarantees that the write operation does not produce
1569 If the Buffer is NULL, then ASSERT().
1571 @param Buffer Pointer to a 32-bit value that may be unaligned.
1572 @param Value 32-bit value to write to Buffer.
1585 Reads a 64-bit value from memory that may be unaligned.
1587 This function returns the 64-bit value pointed to by Buffer. The function
1588 guarantees that the read operation does not produce an alignment fault.
1590 If the Buffer is NULL, then ASSERT().
1592 @param Buffer Pointer to a 64-bit value that may be unaligned.
1600 IN CONST UINT64
*Uint64
1604 Writes a 64-bit value to memory that may be unaligned.
1606 This function writes the 64-bit value specified by Value to Buffer. Value is
1607 returned. The function guarantees that the write operation does not produce
1610 If the Buffer is NULL, then ASSERT().
1612 @param Buffer Pointer to a 64-bit value that may be unaligned.
1613 @param Value 64-bit value to write to Buffer.
1626 // Bit Field Functions
1630 Returns a bit field from an 8-bit value.
1632 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1634 If 8-bit operations are not supported, then ASSERT().
1635 If StartBit is greater than 7, then ASSERT().
1636 If EndBit is greater than 7, then ASSERT().
1637 If EndBit is less than or equal to StartBit, then ASSERT().
1639 @param Operand Operand on which to perform the bitfield operation.
1640 @param StartBit The ordinal of the least significant bit in the bit field.
1642 @param EndBit The ordinal of the most significant bit in the bit field.
1645 @return The bit field read.
1657 Writes a bit field to an 8-bit value, and returns the result.
1659 Writes Value to the bit field specified by the StartBit and the EndBit in
1660 Operand. All other bits in Operand are preserved. The new 8-bit value is
1663 If 8-bit operations are not supported, then ASSERT().
1664 If StartBit is greater than 7, then ASSERT().
1665 If EndBit is greater than 7, then ASSERT().
1666 If EndBit is less than or equal to StartBit, then ASSERT().
1668 @param Operand Operand on which to perform the bitfield operation.
1669 @param StartBit The ordinal of the least significant bit in the bit field.
1671 @param EndBit The ordinal of the most significant bit in the bit field.
1673 @param Value New value of the bit field.
1675 @return The new 8-bit value.
1688 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
1691 Performs a bitwise inclusive OR between the bit field specified by StartBit
1692 and EndBit in Operand and the value specified by OrData. All other bits in
1693 Operand are preserved. The new 8-bit value is returned.
1695 If 8-bit operations are not supported, then ASSERT().
1696 If StartBit is greater than 7, then ASSERT().
1697 If EndBit is greater than 7, then ASSERT().
1698 If EndBit is less than or equal to StartBit, then ASSERT().
1700 @param Operand Operand on which to perform the bitfield operation.
1701 @param StartBit The ordinal of the least significant bit in the bit field.
1703 @param EndBit The ordinal of the most significant bit in the bit field.
1705 @param OrData The value to OR with the read value from the value
1707 @return The new 8-bit value.
1720 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
1723 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1724 in Operand and the value specified by AndData. All other bits in Operand are
1725 preserved. The new 8-bit value is returned.
1727 If 8-bit operations are not supported, then ASSERT().
1728 If StartBit is greater than 7, then ASSERT().
1729 If EndBit is greater than 7, then ASSERT().
1730 If EndBit is less than or equal to StartBit, then ASSERT().
1732 @param Operand Operand on which to perform the bitfield operation.
1733 @param StartBit The ordinal of the least significant bit in the bit field.
1735 @param EndBit The ordinal of the most significant bit in the bit field.
1737 @param AndData The value to AND with the read value from the value.
1739 @return The new 8-bit value.
1752 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
1753 bitwise OR, and returns the result.
1755 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1756 in Operand and the value specified by AndData, followed by a bitwise
1757 inclusive OR with value specified by OrData. All other bits in Operand are
1758 preserved. The new 8-bit value is returned.
1760 If 8-bit operations are not supported, then ASSERT().
1761 If StartBit is greater than 7, then ASSERT().
1762 If EndBit is greater than 7, then ASSERT().
1763 If EndBit is less than or equal to StartBit, then ASSERT().
1765 @param Operand Operand on which to perform the bitfield operation.
1766 @param StartBit The ordinal of the least significant bit in the bit field.
1768 @param EndBit The ordinal of the most significant bit in the bit field.
1770 @param AndData The value to AND with the read value from the value.
1771 @param OrData The value to OR with the result of the AND operation.
1773 @return The new 8-bit value.
1778 BitFieldAndThenOr8 (
1787 Returns a bit field from a 16-bit value.
1789 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1791 If 16-bit operations are not supported, then ASSERT().
1792 If StartBit is greater than 15, then ASSERT().
1793 If EndBit is greater than 15, then ASSERT().
1794 If EndBit is less than or equal to StartBit, then ASSERT().
1796 @param Operand Operand on which to perform the bitfield operation.
1797 @param StartBit The ordinal of the least significant bit in the bit field.
1799 @param EndBit The ordinal of the most significant bit in the bit field.
1802 @return The bit field read.
1814 Writes a bit field to a 16-bit value, and returns the result.
1816 Writes Value to the bit field specified by the StartBit and the EndBit in
1817 Operand. All other bits in Operand are preserved. The new 16-bit value is
1820 If 16-bit operations are not supported, then ASSERT().
1821 If StartBit is greater than 15, then ASSERT().
1822 If EndBit is greater than 15, then ASSERT().
1823 If EndBit is less than or equal to StartBit, then ASSERT().
1825 @param Operand Operand on which to perform the bitfield operation.
1826 @param StartBit The ordinal of the least significant bit in the bit field.
1828 @param EndBit The ordinal of the most significant bit in the bit field.
1830 @param Value New value of the bit field.
1832 @return The new 16-bit value.
1845 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
1848 Performs a bitwise inclusive OR between the bit field specified by StartBit
1849 and EndBit in Operand and the value specified by OrData. All other bits in
1850 Operand are preserved. The new 16-bit value is returned.
1852 If 16-bit operations are not supported, then ASSERT().
1853 If StartBit is greater than 15, then ASSERT().
1854 If EndBit is greater than 15, then ASSERT().
1855 If EndBit is less than or equal to StartBit, then ASSERT().
1857 @param Operand Operand on which to perform the bitfield operation.
1858 @param StartBit The ordinal of the least significant bit in the bit field.
1860 @param EndBit The ordinal of the most significant bit in the bit field.
1862 @param OrData The value to OR with the read value from the value
1864 @return The new 16-bit value.
1877 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
1880 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1881 in Operand and the value specified by AndData. All other bits in Operand are
1882 preserved. The new 16-bit value is returned.
1884 If 16-bit operations are not supported, then ASSERT().
1885 If StartBit is greater than 15, then ASSERT().
1886 If EndBit is greater than 15, then ASSERT().
1887 If EndBit is less than or equal to StartBit, then ASSERT().
1889 @param Operand Operand on which to perform the bitfield operation.
1890 @param StartBit The ordinal of the least significant bit in the bit field.
1892 @param EndBit The ordinal of the most significant bit in the bit field.
1894 @param AndData The value to AND with the read value from the value
1896 @return The new 16-bit value.
1909 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
1910 bitwise OR, and returns the result.
1912 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1913 in Operand and the value specified by AndData, followed by a bitwise
1914 inclusive OR with value specified by OrData. All other bits in Operand are
1915 preserved. The new 16-bit value is returned.
1917 If 16-bit operations are not supported, then ASSERT().
1918 If StartBit is greater than 15, then ASSERT().
1919 If EndBit is greater than 15, then ASSERT().
1920 If EndBit is less than or equal to StartBit, then ASSERT().
1922 @param Operand Operand on which to perform the bitfield operation.
1923 @param StartBit The ordinal of the least significant bit in the bit field.
1925 @param EndBit The ordinal of the most significant bit in the bit field.
1927 @param AndData The value to AND with the read value from the value.
1928 @param OrData The value to OR with the result of the AND operation.
1930 @return The new 16-bit value.
1935 BitFieldAndThenOr16 (
1944 Returns a bit field from a 32-bit value.
1946 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1948 If 32-bit operations are not supported, then ASSERT().
1949 If StartBit is greater than 31, then ASSERT().
1950 If EndBit is greater than 31, then ASSERT().
1951 If EndBit is less than or equal to StartBit, then ASSERT().
1953 @param Operand Operand on which to perform the bitfield operation.
1954 @param StartBit The ordinal of the least significant bit in the bit field.
1956 @param EndBit The ordinal of the most significant bit in the bit field.
1959 @return The bit field read.
1971 Writes a bit field to a 32-bit value, and returns the result.
1973 Writes Value to the bit field specified by the StartBit and the EndBit in
1974 Operand. All other bits in Operand are preserved. The new 32-bit value is
1977 If 32-bit operations are not supported, then ASSERT().
1978 If StartBit is greater than 31, then ASSERT().
1979 If EndBit is greater than 31, then ASSERT().
1980 If EndBit is less than or equal to StartBit, then ASSERT().
1982 @param Operand Operand on which to perform the bitfield operation.
1983 @param StartBit The ordinal of the least significant bit in the bit field.
1985 @param EndBit The ordinal of the most significant bit in the bit field.
1987 @param Value New value of the bit field.
1989 @return The new 32-bit value.
2002 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2005 Performs a bitwise inclusive OR between the bit field specified by StartBit
2006 and EndBit in Operand and the value specified by OrData. All other bits in
2007 Operand are preserved. The new 32-bit value is returned.
2009 If 32-bit operations are not supported, then ASSERT().
2010 If StartBit is greater than 31, then ASSERT().
2011 If EndBit is greater than 31, then ASSERT().
2012 If EndBit is less than or equal to StartBit, then ASSERT().
2014 @param Operand Operand on which to perform the bitfield operation.
2015 @param StartBit The ordinal of the least significant bit in the bit field.
2017 @param EndBit The ordinal of the most significant bit in the bit field.
2019 @param OrData The value to OR with the read value from the value
2021 @return The new 32-bit value.
2034 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2037 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2038 in Operand and the value specified by AndData. All other bits in Operand are
2039 preserved. The new 32-bit value is returned.
2041 If 32-bit operations are not supported, then ASSERT().
2042 If StartBit is greater than 31, then ASSERT().
2043 If EndBit is greater than 31, then ASSERT().
2044 If EndBit is less than or equal to StartBit, then ASSERT().
2046 @param Operand Operand on which to perform the bitfield operation.
2047 @param StartBit The ordinal of the least significant bit in the bit field.
2049 @param EndBit The ordinal of the most significant bit in the bit field.
2051 @param AndData The value to AND with the read value from the value
2053 @return The new 32-bit value.
2066 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2067 bitwise OR, and returns the result.
2069 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2070 in Operand and the value specified by AndData, followed by a bitwise
2071 inclusive OR with value specified by OrData. All other bits in Operand are
2072 preserved. The new 32-bit value is returned.
2074 If 32-bit operations are not supported, then ASSERT().
2075 If StartBit is greater than 31, then ASSERT().
2076 If EndBit is greater than 31, then ASSERT().
2077 If EndBit is less than or equal to StartBit, then ASSERT().
2079 @param Operand Operand on which to perform the bitfield operation.
2080 @param StartBit The ordinal of the least significant bit in the bit field.
2082 @param EndBit The ordinal of the most significant bit in the bit field.
2084 @param AndData The value to AND with the read value from the value.
2085 @param OrData The value to OR with the result of the AND operation.
2087 @return The new 32-bit value.
2092 BitFieldAndThenOr32 (
2101 Returns a bit field from a 64-bit value.
2103 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2105 If 64-bit operations are not supported, then ASSERT().
2106 If StartBit is greater than 63, then ASSERT().
2107 If EndBit is greater than 63, then ASSERT().
2108 If EndBit is less than or equal to StartBit, then ASSERT().
2110 @param Operand Operand on which to perform the bitfield operation.
2111 @param StartBit The ordinal of the least significant bit in the bit field.
2113 @param EndBit The ordinal of the most significant bit in the bit field.
2116 @return The bit field read.
2128 Writes a bit field to a 64-bit value, and returns the result.
2130 Writes Value to the bit field specified by the StartBit and the EndBit in
2131 Operand. All other bits in Operand are preserved. The new 64-bit value is
2134 If 64-bit operations are not supported, then ASSERT().
2135 If StartBit is greater than 63, then ASSERT().
2136 If EndBit is greater than 63, then ASSERT().
2137 If EndBit is less than or equal to StartBit, then ASSERT().
2139 @param Operand Operand on which to perform the bitfield operation.
2140 @param StartBit The ordinal of the least significant bit in the bit field.
2142 @param EndBit The ordinal of the most significant bit in the bit field.
2144 @param Value New value of the bit field.
2146 @return The new 64-bit value.
2159 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2162 Performs a bitwise inclusive OR between the bit field specified by StartBit
2163 and EndBit in Operand and the value specified by OrData. All other bits in
2164 Operand are preserved. The new 64-bit value is returned.
2166 If 64-bit operations are not supported, then ASSERT().
2167 If StartBit is greater than 63, then ASSERT().
2168 If EndBit is greater than 63, then ASSERT().
2169 If EndBit is less than or equal to StartBit, then ASSERT().
2171 @param Operand Operand on which to perform the bitfield operation.
2172 @param StartBit The ordinal of the least significant bit in the bit field.
2174 @param EndBit The ordinal of the most significant bit in the bit field.
2176 @param OrData The value to OR with the read value from the value
2178 @return The new 64-bit value.
2191 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2194 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2195 in Operand and the value specified by AndData. All other bits in Operand are
2196 preserved. The new 64-bit value is returned.
2198 If 64-bit operations are not supported, then ASSERT().
2199 If StartBit is greater than 63, then ASSERT().
2200 If EndBit is greater than 63, then ASSERT().
2201 If EndBit is less than or equal to StartBit, then ASSERT().
2203 @param Operand Operand on which to perform the bitfield operation.
2204 @param StartBit The ordinal of the least significant bit in the bit field.
2206 @param EndBit The ordinal of the most significant bit in the bit field.
2208 @param AndData The value to AND with the read value from the value
2210 @return The new 64-bit value.
2223 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2224 bitwise OR, and returns the result.
2226 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2227 in Operand and the value specified by AndData, followed by a bitwise
2228 inclusive OR with value specified by OrData. All other bits in Operand are
2229 preserved. The new 64-bit value is returned.
2231 If 64-bit operations are not supported, then ASSERT().
2232 If StartBit is greater than 63, then ASSERT().
2233 If EndBit is greater than 63, then ASSERT().
2234 If EndBit is less than or equal to StartBit, then ASSERT().
2236 @param Operand Operand on which to perform the bitfield operation.
2237 @param StartBit The ordinal of the least significant bit in the bit field.
2239 @param EndBit The ordinal of the most significant bit in the bit field.
2241 @param AndData The value to AND with the read value from the value.
2242 @param OrData The value to OR with the result of the AND operation.
2244 @return The new 64-bit value.
2249 BitFieldAndThenOr64 (
2258 // Base Library Synchronization Functions
2262 Retrieves the architecture specific spin lock alignment requirements for
2263 optimal spin lock performance.
2265 This function retrieves the spin lock alignment requirements for optimal
2266 performance on a given CPU architecture. The spin lock alignment must be a
2267 power of two and is returned by this function. If there are no alignment
2268 requirements, then 1 must be returned. The spin lock synchronization
2269 functions must function correctly if the spin lock size and alignment values
2270 returned by this function are not used at all. These values are hints to the
2271 consumers of the spin lock synchronization functions to obtain optimal spin
2274 @return The architecture specific spin lock alignment.
2279 GetSpinLockProperties (
2284 Initializes a spin lock to the released state and returns the spin lock.
2286 This function initializes the spin lock specified by SpinLock to the released
2287 state, and returns SpinLock. Optimal performance can be achieved by calling
2288 GetSpinLockProperties() to determine the size and alignment requirements for
2291 If SpinLock is NULL, then ASSERT().
2293 @param SpinLock A pointer to the spin lock to initialize to the released
2301 InitializeSpinLock (
2302 IN SPIN_LOCK
*SpinLock
2306 Waits until a spin lock can be placed in the acquired state.
2308 This function checks the state of the spin lock specified by SpinLock. If
2309 SpinLock is in the released state, then this function places SpinLock in the
2310 acquired state and returns SpinLock. Otherwise, this function waits
2311 indefinitely for the spin lock to be released, and then places it in the
2312 acquired state and returns SpinLock. All state transitions of SpinLock must
2313 be performed using MP safe mechanisms.
2315 If SpinLock is NULL, then ASSERT().
2316 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2317 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2318 PcdSpinLockTimeout microseconds, then ASSERT().
2320 @param SpinLock A pointer to the spin lock to place in the acquired state.
2328 IN SPIN_LOCK
*SpinLock
2332 Attempts to place a spin lock in the acquired state.
2334 This function checks the state of the spin lock specified by SpinLock. If
2335 SpinLock is in the released state, then this function places SpinLock in the
2336 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2337 transitions of SpinLock must be performed using MP safe mechanisms.
2339 If SpinLock is NULL, then ASSERT().
2340 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2342 @param SpinLock A pointer to the spin lock to place in the acquired state.
2344 @retval TRUE SpinLock was placed in the acquired state.
2345 @retval FALSE SpinLock could not be acquired.
2350 AcquireSpinLockOrFail (
2351 IN SPIN_LOCK
*SpinLock
2355 Releases a spin lock.
2357 This function places the spin lock specified by SpinLock in the release state
2358 and returns SpinLock.
2360 If SpinLock is NULL, then ASSERT().
2361 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2363 @param SpinLock A pointer to the spin lock to release.
2371 IN SPIN_LOCK
*SpinLock
2375 Performs an atomic increment of an 32-bit unsigned integer.
2377 Performs an atomic increment of the 32-bit unsigned integer specified by
2378 Value and returns the incremented value. The increment operation must be
2379 performed using MP safe mechanisms. The state of the return value is not
2380 guaranteed to be MP safe.
2382 If Value is NULL, then ASSERT().
2384 @param Value A pointer to the 32-bit value to increment.
2386 @return The incremented value.
2391 InterlockedIncrement (
2396 Performs an atomic decrement of an 32-bit unsigned integer.
2398 Performs an atomic decrement of the 32-bit unsigned integer specified by
2399 Value and returns the decremented value. The decrement operation must be
2400 performed using MP safe mechanisms. The state of the return value is not
2401 guaranteed to be MP safe.
2403 If Value is NULL, then ASSERT().
2405 @param Value A pointer to the 32-bit value to decrement.
2407 @return The decremented value.
2412 InterlockedDecrement (
2417 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
2419 @param Value A pointer to the 32-bit value for the compare exchange
2421 @param CompareValue 32-bit value used in compare operation.
2422 @param ExchangeValue 32-bit value used in exchange operation.
2424 @return The original *Value before exchange.
2429 InterlockedCompareExchange32 (
2431 IN UINT32 CompareValue
,
2432 IN UINT32 ExchangeValue
2436 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
2438 @param Value A pointer to the 64-bit value for the compare exchange
2440 @param CompareValue 64-bit value used in compare operation.
2441 @param ExchangeValue 64-bit value used in exchange operation.
2443 @return The original *Value before exchange.
2448 InterlockedCompareExchange64 (
2450 IN UINT64 CompareValue
,
2451 IN UINT64 ExchangeValue
2455 Performs an atomic compare exchange operation on a pointer value.
2457 Performs an atomic compare exchange operation on the pointer value specified
2458 by Value. If Value is equal to CompareValue, then Value is set to
2459 ExchangeValue and CompareValue is returned. If Value is not equal to
2460 CompareValue, then Value is returned. The compare exchange operation must be
2461 performed using MP safe mechanisms.
2463 If Value is NULL, then ASSERT().
2465 @param Value A pointer to the pointer value for the compare exchange
2467 @param CompareValue Pointer value used in compare operation.
2468 @param ExchangeValue Pointer value used in exchange operation.
2473 InterlockedCompareExchangePointer (
2475 IN VOID
*CompareValue
,
2476 IN VOID
*ExchangeValue
2480 // Base Library CPU Functions
2484 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
2485 IN VOID
*Context1
, OPTIONAL
2486 IN VOID
*Context2 OPTIONAL
2490 Used to serialize load and store operations.
2492 All loads and stores that proceed calls to this function are guaranteed to be
2493 globally visible when this function returns.
2503 Saves the current CPU context that can be restored with a call to LongJump()
2506 Saves the current CPU context in the buffer specified by JumpBuffer and
2507 returns 0. The initial call to SetJump() must always return 0. Subsequent
2508 calls to LongJump() cause a non-zero value to be returned by SetJump().
2510 If JumpBuffer is NULL, then ASSERT().
2512 @param JumpBuffer A pointer to CPU context buffer.
2514 @retval 0 Indicates a return from SetJump().
2520 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
2524 Restores the CPU context that was saved with SetJump().
2526 Restores the CPU context from the buffer specified by JumpBuffer. This
2527 function never returns to the caller. Instead is resumes execution based on
2528 the state of JumpBuffer.
2530 If JumpBuffer is NULL, then ASSERT().
2531 If Value is 0, then ASSERT().
2533 @param JumpBuffer A pointer to CPU context buffer.
2534 @param Value The value to return when the SetJump() context is
2535 restored and must be non-zero.
2541 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
2546 Enables CPU interrupts.
2548 Enables CPU interrupts.
2558 Disables CPU interrupts.
2560 Disables CPU interrupts.
2570 Disables CPU interrupts and returns the interrupt state prior to the disable
2573 Disables CPU interrupts and returns the interrupt state prior to the disable
2576 @retval TRUE CPU interrupts were enabled on entry to this call.
2577 @retval FALSE CPU interrupts were disabled on entry to this call.
2582 SaveAndDisableInterrupts (
2587 Enables CPU interrupts for the smallest window required to capture any
2590 Enables CPU interrupts for the smallest window required to capture any
2596 EnableDisableInterrupts (
2601 Retrieves the current CPU interrupt state.
2603 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
2604 currently enabled. Otherwise returns FALSE.
2606 @retval TRUE CPU interrupts are enabled.
2607 @retval FALSE CPU interrupts are disabled.
2617 Set the current CPU interrupt state.
2619 Sets the current CPU interrupt state to the state specified by
2620 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
2621 InterruptState is FALSE, then interrupts are disabled. InterruptState is
2624 @param InterruptState TRUE if interrupts should enabled. FALSE if
2625 interrupts should be disabled.
2627 @return InterruptState
2633 IN BOOLEAN InterruptState
2637 Places the CPU in a sleep state until an interrupt is received.
2639 Places the CPU in a sleep state until an interrupt is received. If interrupts
2640 are disabled prior to calling this function, then the CPU will be placed in a
2641 sleep state indefinitely.
2651 Requests CPU to pause for a short period of time.
2653 Requests CPU to pause for a short period of time. Typically used in MP
2654 systems to prevent memory starvation while waiting for a spin lock.
2664 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2666 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2676 Transfers control to a function starting with a new stack.
2678 Transfers control to the function specified by EntryPoint using the new stack
2679 specified by NewStack and passing in the parameters specified by Context1 and
2680 Context2. Context1 and Context2 are optional and may be NULL. The function
2681 EntryPoint must never return.
2683 If EntryPoint is NULL, then ASSERT().
2684 If NewStack is NULL, then ASSERT().
2686 @param EntryPoint A pointer to function to call with the new stack.
2687 @param Context1 A pointer to the context to pass into the EntryPoint
2689 @param Context2 A pointer to the context to pass into the EntryPoint
2691 @param NewStack A pointer to the new stack to use for the EntryPoint
2698 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
2699 IN VOID
*Context1
, OPTIONAL
2700 IN VOID
*Context2
, OPTIONAL
2705 Generates a breakpoint on the CPU.
2707 Generates a breakpoint on the CPU. The breakpoint must be implemented such
2708 that code can resume normal execution after the breakpoint.
2718 Executes an infinite loop.
2720 Forces the CPU to execute an infinite loop. A debugger may be used to skip
2721 past the loop and the code that follows the loop must execute properly. This
2722 implies that the infinite loop must not cause the code that follow it to be
2733 // IA32 and X64 Specific Functions
2736 // Byte packed structure for 16-bit Real Mode EFLAGS
2740 UINT32 CF
:1; // Carry Flag
2741 UINT32 Reserved_0
:1; // Reserved
2742 UINT32 PF
:1; // Parity Flag
2743 UINT32 Reserved_1
:1; // Reserved
2744 UINT32 AF
:1; // Auxiliary Carry Flag
2745 UINT32 Reserved_2
:1; // Reserved
2746 UINT32 ZF
:1; // Zero Flag
2747 UINT32 SF
:1; // Sign Flag
2748 UINT32 TF
:1; // Trap Flag
2749 UINT32 IF
:1; // Interrupt Enable Flag
2750 UINT32 DF
:1; // Direction Flag
2751 UINT32 OF
:1; // Overflow Flag
2752 UINT32 IOPL
:2; // I/O Privilege Level
2753 UINT32 NT
:1; // Nested Task
2754 UINT32 Reserved_3
:1; // Reserved
2760 // Byte packed structure for EFLAGS/RFLAGS
2762 // 64-bits on X64. The upper 32-bits on X64 are reserved
2766 UINT32 CF
:1; // Carry Flag
2767 UINT32 Reserved_0
:1; // Reserved
2768 UINT32 PF
:1; // Parity Flag
2769 UINT32 Reserved_1
:1; // Reserved
2770 UINT32 AF
:1; // Auxiliary Carry Flag
2771 UINT32 Reserved_2
:1; // Reserved
2772 UINT32 ZF
:1; // Zero Flag
2773 UINT32 SF
:1; // Sign Flag
2774 UINT32 TF
:1; // Trap Flag
2775 UINT32 IF
:1; // Interrupt Enable Flag
2776 UINT32 DF
:1; // Direction Flag
2777 UINT32 OF
:1; // Overflow Flag
2778 UINT32 IOPL
:2; // I/O Privilege Level
2779 UINT32 NT
:1; // Nested Task
2780 UINT32 Reserved_3
:1; // Reserved
2781 UINT32 RF
:1; // Resume Flag
2782 UINT32 VM
:1; // Virtual 8086 Mode
2783 UINT32 AC
:1; // Alignment Check
2784 UINT32 VIF
:1; // Virtual Interrupt Flag
2785 UINT32 VIP
:1; // Virtual Interrupt Pending
2786 UINT32 ID
:1; // ID Flag
2787 UINT32 Reserved_4
:10; // Reserved
2793 // Byte packed structure for Control Register 0 (CR0)
2795 // 64-bits on X64. The upper 32-bits on X64 are reserved
2799 UINT32 PE
:1; // Protection Enable
2800 UINT32 MP
:1; // Monitor Coprocessor
2801 UINT32 EM
:1; // Emulation
2802 UINT32 TS
:1; // Task Switched
2803 UINT32 ET
:1; // Extension Type
2804 UINT32 NE
:1; // Numeric Error
2805 UINT32 Reserved_0
:10; // Reserved
2806 UINT32 WP
:1; // Write Protect
2807 UINT32 Reserved_1
:1; // Reserved
2808 UINT32 AM
:1; // Alignment Mask
2809 UINT32 Reserved_2
:10; // Reserved
2810 UINT32 NW
:1; // Mot Write-through
2811 UINT32 CD
:1; // Cache Disable
2812 UINT32 PG
:1; // Paging
2818 // Byte packed structure for Control Register 4 (CR4)
2820 // 64-bits on X64. The upper 32-bits on X64 are reserved
2824 UINT32 VME
:1; // Virtual-8086 Mode Extensions
2825 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
2826 UINT32 TSD
:1; // Time Stamp Disable
2827 UINT32 DE
:1; // Debugging Extensions
2828 UINT32 PSE
:1; // Page Size Extensions
2829 UINT32 PAE
:1; // Physical Address Extension
2830 UINT32 MCE
:1; // Machine Check Enable
2831 UINT32 PGE
:1; // Page Global Enable
2832 UINT32 PCE
:1; // Performance Monitoring Counter
2834 UINT32 OSFXSR
:1; // Operating System Support for
2835 // FXSAVE and FXRSTOR instructions
2836 UINT32 OSXMMEXCPT
:1; // Operating System Support for
2837 // Unmasked SIMD Floating Point
2839 UINT32 Reserved_0
:2; // Reserved
2840 UINT32 VMXE
:1; // VMX Enable
2841 UINT32 Reserved_1
:18; // Reseved
2847 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
2848 /// @bug How to make this structure byte-packed in a compiler independent way?
2855 #define IA32_IDT_GATE_TYPE_TASK 0x85
2856 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
2857 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
2858 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
2859 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
2862 // Byte packed structure for an Interrupt Gate Descriptor
2866 UINT32 OffsetLow
:16; // Offset bits 15..0
2867 UINT32 Selector
:16; // Selector
2868 UINT32 Reserved_0
:8; // Reserved
2869 UINT32 GateType
:8; // Gate Type. See #defines above
2870 UINT32 OffsetHigh
:16; // Offset bits 31..16
2873 } IA32_IDT_GATE_DESCRIPTOR
;
2876 // Byte packed structure for an FP/SSE/SSE2 context
2883 // Structures for the 16-bit real mode thunks
2936 IA32_EFLAGS32 EFLAGS
;
2946 } IA32_REGISTER_SET
;
2949 // Byte packed structure for an 16-bit real mode thunks
2952 IA32_REGISTER_SET
*RealModeState
;
2953 VOID
*RealModeBuffer
;
2954 UINT32 RealModeBufferSize
;
2955 UINT32 ThunkAttributes
;
2958 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
2959 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
2960 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
2963 Retrieves CPUID information.
2965 Executes the CPUID instruction with EAX set to the value specified by Index.
2966 This function always returns Index.
2967 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
2968 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
2969 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
2970 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
2971 This function is only available on IA-32 and X64.
2973 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
2975 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
2976 instruction. This is an optional parameter that may be NULL.
2977 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
2978 instruction. This is an optional parameter that may be NULL.
2979 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
2980 instruction. This is an optional parameter that may be NULL.
2981 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
2982 instruction. This is an optional parameter that may be NULL.
2991 OUT UINT32
*Eax
, OPTIONAL
2992 OUT UINT32
*Ebx
, OPTIONAL
2993 OUT UINT32
*Ecx
, OPTIONAL
2994 OUT UINT32
*Edx OPTIONAL
2998 Returns the lower 32-bits of a Machine Specific Register(MSR).
3000 Reads and returns the lower 32-bits of the MSR specified by Index.
3001 No parameter checking is performed on Index, and some Index values may cause
3002 CPU exceptions. The caller must either guarantee that Index is valid, or the
3003 caller must set up exception handlers to catch the exceptions. This function
3004 is only available on IA-32 and X64.
3006 @param Index The 32-bit MSR index to read.
3008 @return The lower 32 bits of the MSR identified by Index.
3018 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3020 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3021 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3022 the MSR is returned. No parameter checking is performed on Index or Value,
3023 and some of these may cause CPU exceptions. The caller must either guarantee
3024 that Index and Value are valid, or the caller must establish proper exception
3025 handlers. This function is only available on IA-32 and X64.
3027 @param Index The 32-bit MSR index to write.
3028 @param Value The 32-bit value to write to the MSR.
3041 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3042 writes the result back to the 64-bit MSR.
3044 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3045 between the lower 32-bits of the read result and the value specified by
3046 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3047 32-bits of the value written to the MSR is returned. No parameter checking is
3048 performed on Index or OrData, and some of these may cause CPU exceptions. The
3049 caller must either guarantee that Index and OrData are valid, or the caller
3050 must establish proper exception handlers. This function is only available on
3053 @param Index The 32-bit MSR index to write.
3054 @param OrData The value to OR with the read value from the MSR.
3056 @return The lower 32-bit value written to the MSR.
3067 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3068 the result back to the 64-bit MSR.
3070 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3071 lower 32-bits of the read result and the value specified by AndData, and
3072 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3073 the value written to the MSR is returned. No parameter checking is performed
3074 on Index or AndData, and some of these may cause CPU exceptions. The caller
3075 must either guarantee that Index and AndData are valid, or the caller must
3076 establish proper exception handlers. This function is only available on IA-32
3079 @param Index The 32-bit MSR index to write.
3080 @param AndData The value to AND with the read value from the MSR.
3082 @return The lower 32-bit value written to the MSR.
3093 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3094 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3096 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3097 lower 32-bits of the read result and the value specified by AndData
3098 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3099 result of the AND operation and the value specified by OrData, and writes the
3100 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3101 written to the MSR is returned. No parameter checking is performed on Index,
3102 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3103 must either guarantee that Index, AndData, and OrData are valid, or the
3104 caller must establish proper exception handlers. This function is only
3105 available on IA-32 and X64.
3107 @param Index The 32-bit MSR index to write.
3108 @param AndData The value to AND with the read value from the MSR.
3109 @param OrData The value to OR with the result of the AND operation.
3111 @return The lower 32-bit value written to the MSR.
3123 Reads a bit field of an MSR.
3125 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3126 specified by the StartBit and the EndBit. The value of the bit field is
3127 returned. The caller must either guarantee that Index is valid, or the caller
3128 must set up exception handlers to catch the exceptions. This function is only
3129 available on IA-32 and X64.
3131 If StartBit is greater than 31, then ASSERT().
3132 If EndBit is greater than 31, then ASSERT().
3133 If EndBit is less than or equal to StartBit, then ASSERT().
3135 @param Index The 32-bit MSR index to read.
3136 @param StartBit The ordinal of the least significant bit in the bit field.
3138 @param EndBit The ordinal of the most significant bit in the bit field.
3141 @return The bit field read from the MSR.
3146 AsmMsrBitFieldRead32 (
3153 Writes a bit field to an MSR.
3155 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3156 field is specified by the StartBit and the EndBit. All other bits in the
3157 destination MSR are preserved. The lower 32-bits of the MSR written is
3158 returned. Extra left bits in Value are stripped. The caller must either
3159 guarantee that Index and the data written is valid, or the caller must set up
3160 exception handlers to catch the exceptions. This function is only available
3163 If StartBit is greater than 31, then ASSERT().
3164 If EndBit is greater than 31, then ASSERT().
3165 If EndBit is less than or equal to StartBit, then ASSERT().
3167 @param Index The 32-bit MSR index to write.
3168 @param StartBit The ordinal of the least significant bit in the bit field.
3170 @param EndBit The ordinal of the most significant bit in the bit field.
3172 @param Value New value of the bit field.
3174 @return The lower 32-bit of the value written to the MSR.
3179 AsmMsrBitFieldWrite32 (
3187 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3188 result back to the bit field in the 64-bit MSR.
3190 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3191 between the read result and the value specified by OrData, and writes the
3192 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3193 written to the MSR are returned. Extra left bits in OrData are stripped. The
3194 caller must either guarantee that Index and the data written is valid, or
3195 the caller must set up exception handlers to catch the exceptions. This
3196 function is only available on IA-32 and X64.
3198 If StartBit is greater than 31, then ASSERT().
3199 If EndBit is greater than 31, then ASSERT().
3200 If EndBit is less than or equal to StartBit, then ASSERT().
3202 @param Index The 32-bit MSR index to write.
3203 @param StartBit The ordinal of the least significant bit in the bit field.
3205 @param EndBit The ordinal of the most significant bit in the bit field.
3207 @param OrData The value to OR with the read value from the MSR.
3209 @return The lower 32-bit of the value written to the MSR.
3214 AsmMsrBitFieldOr32 (
3222 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3223 result back to the bit field in the 64-bit MSR.
3225 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3226 read result and the value specified by AndData, and writes the result to the
3227 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3228 MSR are returned. Extra left bits in AndData are stripped. The caller must
3229 either guarantee that Index and the data written is valid, or the caller must
3230 set up exception handlers to catch the exceptions. This function is only
3231 available on IA-32 and X64.
3233 If StartBit is greater than 31, then ASSERT().
3234 If EndBit is greater than 31, then ASSERT().
3235 If EndBit is less than or equal to StartBit, then ASSERT().
3237 @param Index The 32-bit MSR index to write.
3238 @param StartBit The ordinal of the least significant bit in the bit field.
3240 @param EndBit The ordinal of the most significant bit in the bit field.
3242 @param AndData The value to AND with the read value from the MSR.
3244 @return The lower 32-bit of the value written to the MSR.
3249 AsmMsrBitFieldAnd32 (
3257 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3258 bitwise inclusive OR, and writes the result back to the bit field in the
3261 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3262 bitwise inclusive OR between the read result and the value specified by
3263 AndData, and writes the result to the 64-bit MSR specified by Index. The
3264 lower 32-bits of the value written to the MSR are returned. Extra left bits
3265 in both AndData and OrData are stripped. The caller must either guarantee
3266 that Index and the data written is valid, or the caller must set up exception
3267 handlers to catch the exceptions. This function is only available on IA-32
3270 If StartBit is greater than 31, then ASSERT().
3271 If EndBit is greater than 31, then ASSERT().
3272 If EndBit is less than or equal to StartBit, then ASSERT().
3274 @param Index The 32-bit MSR index to write.
3275 @param StartBit The ordinal of the least significant bit in the bit field.
3277 @param EndBit The ordinal of the most significant bit in the bit field.
3279 @param AndData The value to AND with the read value from the MSR.
3280 @param OrData The value to OR with the result of the AND operation.
3282 @return The lower 32-bit of the value written to the MSR.
3287 AsmMsrBitFieldAndThenOr32 (
3296 Returns a 64-bit Machine Specific Register(MSR).
3298 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3299 performed on Index, and some Index values may cause CPU exceptions. The
3300 caller must either guarantee that Index is valid, or the caller must set up
3301 exception handlers to catch the exceptions. This function is only available
3304 @param Index The 32-bit MSR index to read.
3306 @return The value of the MSR identified by Index.
3316 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3319 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3320 64-bit value written to the MSR is returned. No parameter checking is
3321 performed on Index or Value, and some of these may cause CPU exceptions. The
3322 caller must either guarantee that Index and Value are valid, or the caller
3323 must establish proper exception handlers. This function is only available on
3326 @param Index The 32-bit MSR index to write.
3327 @param Value The 64-bit value to write to the MSR.
3340 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3341 back to the 64-bit MSR.
3343 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3344 between the read result and the value specified by OrData, and writes the
3345 result to the 64-bit MSR specified by Index. The value written to the MSR is
3346 returned. No parameter checking is performed on Index or OrData, and some of
3347 these may cause CPU exceptions. The caller must either guarantee that Index
3348 and OrData are valid, or the caller must establish proper exception handlers.
3349 This function is only available on IA-32 and X64.
3351 @param Index The 32-bit MSR index to write.
3352 @param OrData The value to OR with the read value from the MSR.
3354 @return The value written back to the MSR.
3365 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3368 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3369 read result and the value specified by OrData, and writes the result to the
3370 64-bit MSR specified by Index. The value written to the MSR is returned. No
3371 parameter checking is performed on Index or OrData, and some of these may
3372 cause CPU exceptions. The caller must either guarantee that Index and OrData
3373 are valid, or the caller must establish proper exception handlers. This
3374 function is only available on IA-32 and X64.
3376 @param Index The 32-bit MSR index to write.
3377 @param AndData The value to AND with the read value from the MSR.
3379 @return The value written back to the MSR.
3390 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3391 OR, and writes the result back to the 64-bit MSR.
3393 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3394 result and the value specified by AndData, performs a bitwise inclusive OR
3395 between the result of the AND operation and the value specified by OrData,
3396 and writes the result to the 64-bit MSR specified by Index. The value written
3397 to the MSR is returned. No parameter checking is performed on Index, AndData,
3398 or OrData, and some of these may cause CPU exceptions. The caller must either
3399 guarantee that Index, AndData, and OrData are valid, or the caller must
3400 establish proper exception handlers. This function is only available on IA-32
3403 @param Index The 32-bit MSR index to write.
3404 @param AndData The value to AND with the read value from the MSR.
3405 @param OrData The value to OR with the result of the AND operation.
3407 @return The value written back to the MSR.
3419 Reads a bit field of an MSR.
3421 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3422 StartBit and the EndBit. The value of the bit field is returned. The caller
3423 must either guarantee that Index is valid, or the caller must set up
3424 exception handlers to catch the exceptions. This function is only available
3427 If StartBit is greater than 63, then ASSERT().
3428 If EndBit is greater than 63, then ASSERT().
3429 If EndBit is less than or equal to StartBit, then ASSERT().
3431 @param Index The 32-bit MSR index to read.
3432 @param StartBit The ordinal of the least significant bit in the bit field.
3434 @param EndBit The ordinal of the most significant bit in the bit field.
3437 @return The value read from the MSR.
3442 AsmMsrBitFieldRead64 (
3449 Writes a bit field to an MSR.
3451 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3452 the StartBit and the EndBit. All other bits in the destination MSR are
3453 preserved. The MSR written is returned. Extra left bits in Value are
3454 stripped. The caller must either guarantee that Index and the data written is
3455 valid, or the caller must set up exception handlers to catch the exceptions.
3456 This function is only available on IA-32 and X64.
3458 If StartBit is greater than 63, then ASSERT().
3459 If EndBit is greater than 63, then ASSERT().
3460 If EndBit is less than or equal to StartBit, then ASSERT().
3462 @param Index The 32-bit MSR index to write.
3463 @param StartBit The ordinal of the least significant bit in the bit field.
3465 @param EndBit The ordinal of the most significant bit in the bit field.
3467 @param Value New value of the bit field.
3469 @return The value written back to the MSR.
3474 AsmMsrBitFieldWrite64 (
3482 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3483 writes the result back to the bit field in the 64-bit MSR.
3485 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3486 between the read result and the value specified by OrData, and writes the
3487 result to the 64-bit MSR specified by Index. The value written to the MSR is
3488 returned. Extra left bits in OrData are stripped. The caller must either
3489 guarantee that Index and the data written is valid, or the caller must set up
3490 exception handlers to catch the exceptions. This function is only available
3493 If StartBit is greater than 63, then ASSERT().
3494 If EndBit is greater than 63, then ASSERT().
3495 If EndBit is less than or equal to StartBit, then ASSERT().
3497 @param Index The 32-bit MSR index to write.
3498 @param StartBit The ordinal of the least significant bit in the bit field.
3500 @param EndBit The ordinal of the most significant bit in the bit field.
3502 @param OrData The value to OR with the read value from the bit field.
3504 @return The value written back to the MSR.
3509 AsmMsrBitFieldOr64 (
3517 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3518 result back to the bit field in the 64-bit MSR.
3520 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3521 read result and the value specified by AndData, and writes the result to the
3522 64-bit MSR specified by Index. The value written to the MSR is returned.
3523 Extra left bits in AndData are stripped. The caller must either guarantee
3524 that Index and the data written is valid, or the caller must set up exception
3525 handlers to catch the exceptions. This function is only available on IA-32
3528 If StartBit is greater than 63, then ASSERT().
3529 If EndBit is greater than 63, then ASSERT().
3530 If EndBit is less than or equal to StartBit, then ASSERT().
3532 @param Index The 32-bit MSR index to write.
3533 @param StartBit The ordinal of the least significant bit in the bit field.
3535 @param EndBit The ordinal of the most significant bit in the bit field.
3537 @param AndData The value to AND with the read value from the bit field.
3539 @return The value written back to the MSR.
3544 AsmMsrBitFieldAnd64 (
3552 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3553 bitwise inclusive OR, and writes the result back to the bit field in the
3556 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3557 a bitwise inclusive OR between the read result and the value specified by
3558 AndData, and writes the result to the 64-bit MSR specified by Index. The
3559 value written to the MSR is returned. Extra left bits in both AndData and
3560 OrData are stripped. The caller must either guarantee that Index and the data
3561 written is valid, or the caller must set up exception handlers to catch the
3562 exceptions. This function is only available on IA-32 and X64.
3564 If StartBit is greater than 63, then ASSERT().
3565 If EndBit is greater than 63, then ASSERT().
3566 If EndBit is less than or equal to StartBit, then ASSERT().
3568 @param Index The 32-bit MSR index to write.
3569 @param StartBit The ordinal of the least significant bit in the bit field.
3571 @param EndBit The ordinal of the most significant bit in the bit field.
3573 @param AndData The value to AND with the read value from the bit field.
3574 @param OrData The value to OR with the result of the AND operation.
3576 @return The value written back to the MSR.
3581 AsmMsrBitFieldAndThenOr64 (
3590 Reads the current value of the EFLAGS register.
3592 Reads and returns the current value of the EFLAGS register. This function is
3593 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3594 64-bit value on X64.
3596 @return EFLAGS on IA-32 or RFLAGS on X64.
3606 Reads the current value of the Control Register 0 (CR0).
3608 Reads and returns the current value of CR0. This function is only available
3609 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3612 @return The value of the Control Register 0 (CR0).
3622 Reads the current value of the Control Register 2 (CR2).
3624 Reads and returns the current value of CR2. This function is only available
3625 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3628 @return The value of the Control Register 2 (CR2).
3638 Reads the current value of the Control Register 3 (CR3).
3640 Reads and returns the current value of CR3. This function is only available
3641 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3644 @return The value of the Control Register 3 (CR3).
3654 Reads the current value of the Control Register 4 (CR4).
3656 Reads and returns the current value of CR4. This function is only available
3657 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3660 @return The value of the Control Register 4 (CR4).
3670 Writes a value to Control Register 0 (CR0).
3672 Writes and returns a new value to CR0. This function is only available on
3673 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3675 @param Cr0 The value to write to CR0.
3677 @return The value written to CR0.
3687 Writes a value to Control Register 2 (CR2).
3689 Writes and returns a new value to CR2. This function is only available on
3690 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3692 @param Cr2 The value to write to CR2.
3694 @return The value written to CR2.
3704 Writes a value to Control Register 3 (CR3).
3706 Writes and returns a new value to CR3. This function is only available on
3707 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3709 @param Cr3 The value to write to CR3.
3711 @return The value written to CR3.
3721 Writes a value to Control Register 4 (CR4).
3723 Writes and returns a new value to CR4. This function is only available on
3724 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3726 @param Cr4 The value to write to CR4.
3728 @return The value written to CR4.
3738 Reads the current value of Debug Register 0 (DR0).
3740 Reads and returns the current value of DR0. This function is only available
3741 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3744 @return The value of Debug Register 0 (DR0).
3754 Reads the current value of Debug Register 1 (DR1).
3756 Reads and returns the current value of DR1. This function is only available
3757 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3760 @return The value of Debug Register 1 (DR1).
3770 Reads the current value of Debug Register 2 (DR2).
3772 Reads and returns the current value of DR2. This function is only available
3773 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3776 @return The value of Debug Register 2 (DR2).
3786 Reads the current value of Debug Register 3 (DR3).
3788 Reads and returns the current value of DR3. This function is only available
3789 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3792 @return The value of Debug Register 3 (DR3).
3802 Reads the current value of Debug Register 4 (DR4).
3804 Reads and returns the current value of DR4. This function is only available
3805 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3808 @return The value of Debug Register 4 (DR4).
3818 Reads the current value of Debug Register 5 (DR5).
3820 Reads and returns the current value of DR5. This function is only available
3821 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3824 @return The value of Debug Register 5 (DR5).
3834 Reads the current value of Debug Register 6 (DR6).
3836 Reads and returns the current value of DR6. This function is only available
3837 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3840 @return The value of Debug Register 6 (DR6).
3850 Reads the current value of Debug Register 7 (DR7).
3852 Reads and returns the current value of DR7. This function is only available
3853 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3856 @return The value of Debug Register 7 (DR7).
3866 Writes a value to Debug Register 0 (DR0).
3868 Writes and returns a new value to DR0. This function is only available on
3869 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3871 @param Dr0 The value to write to Dr0.
3873 @return The value written to Debug Register 0 (DR0).
3883 Writes a value to Debug Register 1 (DR1).
3885 Writes and returns a new value to DR1. This function is only available on
3886 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3888 @param Dr1 The value to write to Dr1.
3890 @return The value written to Debug Register 1 (DR1).
3900 Writes a value to Debug Register 2 (DR2).
3902 Writes and returns a new value to DR2. This function is only available on
3903 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3905 @param Dr2 The value to write to Dr2.
3907 @return The value written to Debug Register 2 (DR2).
3917 Writes a value to Debug Register 3 (DR3).
3919 Writes and returns a new value to DR3. This function is only available on
3920 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3922 @param Dr3 The value to write to Dr3.
3924 @return The value written to Debug Register 3 (DR3).
3934 Writes a value to Debug Register 4 (DR4).
3936 Writes and returns a new value to DR4. This function is only available on
3937 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3939 @param Dr4 The value to write to Dr4.
3941 @return The value written to Debug Register 4 (DR4).
3951 Writes a value to Debug Register 5 (DR5).
3953 Writes and returns a new value to DR5. This function is only available on
3954 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3956 @param Dr5 The value to write to Dr5.
3958 @return The value written to Debug Register 5 (DR5).
3968 Writes a value to Debug Register 6 (DR6).
3970 Writes and returns a new value to DR6. This function is only available on
3971 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3973 @param Dr6 The value to write to Dr6.
3975 @return The value written to Debug Register 6 (DR6).
3985 Writes a value to Debug Register 7 (DR7).
3987 Writes and returns a new value to DR7. This function is only available on
3988 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3990 @param Dr7 The value to write to Dr7.
3992 @return The value written to Debug Register 7 (DR7).
4002 Reads the current value of Code Segment Register (CS).
4004 Reads and returns the current value of CS. This function is only available on
4007 @return The current value of CS.
4017 Reads the current value of Data Segment Register (DS).
4019 Reads and returns the current value of DS. This function is only available on
4022 @return The current value of DS.
4032 Reads the current value of Extra Segment Register (ES).
4034 Reads and returns the current value of ES. This function is only available on
4037 @return The current value of ES.
4047 Reads the current value of FS Data Segment Register (FS).
4049 Reads and returns the current value of FS. This function is only available on
4052 @return The current value of FS.
4062 Reads the current value of GS Data Segment Register (GS).
4064 Reads and returns the current value of GS. This function is only available on
4067 @return The current value of GS.
4077 Reads the current value of Stack Segment Register (SS).
4079 Reads and returns the current value of SS. This function is only available on
4082 @return The current value of SS.
4092 Reads the current value of Task Register (TR).
4094 Reads and returns the current value of TR. This function is only available on
4097 @return The current value of TR.
4107 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4109 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4110 function is only available on IA-32 and X64.
4112 If Gdtr is NULL, then ASSERT().
4114 @param Gdtr Pointer to a GDTR descriptor.
4120 OUT IA32_DESCRIPTOR
*Gdtr
4124 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4126 Writes and the current GDTR descriptor specified by Gdtr. This function is
4127 only available on IA-32 and X64.
4129 If Gdtr is NULL, then ASSERT().
4131 @param Gdtr Pointer to a GDTR descriptor.
4137 IN CONST IA32_DESCRIPTOR
*Gdtr
4141 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4143 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4144 function is only available on IA-32 and X64.
4146 If Idtr is NULL, then ASSERT().
4148 @param Idtr Pointer to a IDTR descriptor.
4154 OUT IA32_DESCRIPTOR
*Idtr
4158 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4160 Writes the current IDTR descriptor and returns it in Idtr. This function is
4161 only available on IA-32 and X64.
4163 If Idtr is NULL, then ASSERT().
4165 @param Idtr Pointer to a IDTR descriptor.
4171 IN CONST IA32_DESCRIPTOR
*Idtr
4175 Reads the current Local Descriptor Table Register(LDTR) selector.
4177 Reads and returns the current 16-bit LDTR descriptor value. This function is
4178 only available on IA-32 and X64.
4180 @return The current selector of LDT.
4190 Writes the current Local Descriptor Table Register (GDTR) selector.
4192 Writes and the current LDTR descriptor specified by Ldtr. This function is
4193 only available on IA-32 and X64.
4195 @param Ldtr 16-bit LDTR selector value.
4205 Save the current floating point/SSE/SSE2 context to a buffer.
4207 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4208 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4209 available on IA-32 and X64.
4211 If Buffer is NULL, then ASSERT().
4212 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4214 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4220 OUT IA32_FX_BUFFER
*Buffer
4224 Restores the current floating point/SSE/SSE2 context from a buffer.
4226 Restores the current floating point/SSE/SSE2 state from the buffer specified
4227 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4228 only available on IA-32 and X64.
4230 If Buffer is NULL, then ASSERT().
4231 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4232 If Buffer was not saved with AsmFxSave(), then ASSERT().
4234 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4240 IN CONST IA32_FX_BUFFER
*Buffer
4244 Reads the current value of 64-bit MMX Register #0 (MM0).
4246 Reads and returns the current value of MM0. This function is only available
4249 @return The current value of MM0.
4259 Reads the current value of 64-bit MMX Register #1 (MM1).
4261 Reads and returns the current value of MM1. This function is only available
4264 @return The current value of MM1.
4274 Reads the current value of 64-bit MMX Register #2 (MM2).
4276 Reads and returns the current value of MM2. This function is only available
4279 @return The current value of MM2.
4289 Reads the current value of 64-bit MMX Register #3 (MM3).
4291 Reads and returns the current value of MM3. This function is only available
4294 @return The current value of MM3.
4304 Reads the current value of 64-bit MMX Register #4 (MM4).
4306 Reads and returns the current value of MM4. This function is only available
4309 @return The current value of MM4.
4319 Reads the current value of 64-bit MMX Register #5 (MM5).
4321 Reads and returns the current value of MM5. This function is only available
4324 @return The current value of MM5.
4334 Reads the current value of 64-bit MMX Register #6 (MM6).
4336 Reads and returns the current value of MM6. This function is only available
4339 @return The current value of MM6.
4349 Reads the current value of 64-bit MMX Register #7 (MM7).
4351 Reads and returns the current value of MM7. This function is only available
4354 @return The current value of MM7.
4364 Writes the current value of 64-bit MMX Register #0 (MM0).
4366 Writes the current value of MM0. This function is only available on IA32 and
4369 @param Value The 64-bit value to write to MM0.
4379 Writes the current value of 64-bit MMX Register #1 (MM1).
4381 Writes the current value of MM1. This function is only available on IA32 and
4384 @param Value The 64-bit value to write to MM1.
4394 Writes the current value of 64-bit MMX Register #2 (MM2).
4396 Writes the current value of MM2. This function is only available on IA32 and
4399 @param Value The 64-bit value to write to MM2.
4409 Writes the current value of 64-bit MMX Register #3 (MM3).
4411 Writes the current value of MM3. This function is only available on IA32 and
4414 @param Value The 64-bit value to write to MM3.
4424 Writes the current value of 64-bit MMX Register #4 (MM4).
4426 Writes the current value of MM4. This function is only available on IA32 and
4429 @param Value The 64-bit value to write to MM4.
4439 Writes the current value of 64-bit MMX Register #5 (MM5).
4441 Writes the current value of MM5. This function is only available on IA32 and
4444 @param Value The 64-bit value to write to MM5.
4454 Writes the current value of 64-bit MMX Register #6 (MM6).
4456 Writes the current value of MM6. This function is only available on IA32 and
4459 @param Value The 64-bit value to write to MM6.
4469 Writes the current value of 64-bit MMX Register #7 (MM7).
4471 Writes the current value of MM7. This function is only available on IA32 and
4474 @param Value The 64-bit value to write to MM7.
4484 Reads the current value of Time Stamp Counter (TSC).
4486 Reads and returns the current value of TSC. This function is only available
4489 @return The current value of TSC
4499 Reads the current value of a Performance Counter (PMC).
4501 Reads and returns the current value of performance counter specified by
4502 Index. This function is only available on IA-32 and X64.
4504 @param Index The 32-bit Performance Counter index to read.
4506 @return The value of the PMC specified by Index.
4516 Sets up a monitor buffer that is used by AsmMwait().
4518 Executes a MONITOR instruction with the register state specified by Eax, Ecx
4519 and Edx. Returns Eax. This function is only available on IA-32 and X64.
4521 @param Eax The value to load into EAX or RAX before executing the MONITOR
4523 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4525 @param Edx The value to load into EDX or RDX before executing the MONITOR
4540 Executes an MWAIT instruction.
4542 Executes an MWAIT instruction with the register state specified by Eax and
4543 Ecx. Returns Eax. This function is only available on IA-32 and X64.
4545 @param Eax The value to load into EAX or RAX before executing the MONITOR
4547 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4561 Executes a WBINVD instruction.
4563 Executes a WBINVD instruction. This function is only available on IA-32 and
4574 Executes a INVD instruction.
4576 Executes a INVD instruction. This function is only available on IA-32 and
4587 Flushes a cache line from all the instruction and data caches within the
4588 coherency domain of the CPU.
4590 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
4591 This function is only available on IA-32 and X64.
4593 @param LinearAddress The address of the cache line to flush. If the CPU is
4594 in a physical addressing mode, then LinearAddress is a
4595 physical address. If the CPU is in a virtual
4596 addressing mode, then LinearAddress is a virtual
4599 @return LinearAddress
4604 IN VOID
*LinearAddress
4608 Enables the 32-bit paging mode on the CPU.
4610 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4611 must be properly initialized prior to calling this service. This function
4612 assumes the current execution mode is 32-bit protected mode. This function is
4613 only available on IA-32. After the 32-bit paging mode is enabled, control is
4614 transferred to the function specified by EntryPoint using the new stack
4615 specified by NewStack and passing in the parameters specified by Context1 and
4616 Context2. Context1 and Context2 are optional and may be NULL. The function
4617 EntryPoint must never return.
4619 If the current execution mode is not 32-bit protected mode, then ASSERT().
4620 If EntryPoint is NULL, then ASSERT().
4621 If NewStack is NULL, then ASSERT().
4623 There are a number of constraints that must be followed before calling this
4625 1) Interrupts must be disabled.
4626 2) The caller must be in 32-bit protected mode with flat descriptors. This
4627 means all descriptors must have a base of 0 and a limit of 4GB.
4628 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
4630 4) CR3 must point to valid page tables that will be used once the transition
4631 is complete, and those page tables must guarantee that the pages for this
4632 function and the stack are identity mapped.
4634 @param EntryPoint A pointer to function to call with the new stack after
4636 @param Context1 A pointer to the context to pass into the EntryPoint
4637 function as the first parameter after paging is enabled.
4638 @param Context2 A pointer to the context to pass into the EntryPoint
4639 function as the second parameter after paging is enabled.
4640 @param NewStack A pointer to the new stack to use for the EntryPoint
4641 function after paging is enabled.
4647 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4648 IN VOID
*Context1
, OPTIONAL
4649 IN VOID
*Context2
, OPTIONAL
4654 Disables the 32-bit paging mode on the CPU.
4656 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
4657 mode. This function assumes the current execution mode is 32-paged protected
4658 mode. This function is only available on IA-32. After the 32-bit paging mode
4659 is disabled, control is transferred to the function specified by EntryPoint
4660 using the new stack specified by NewStack and passing in the parameters
4661 specified by Context1 and Context2. Context1 and Context2 are optional and
4662 may be NULL. The function EntryPoint must never return.
4664 If the current execution mode is not 32-bit paged mode, then ASSERT().
4665 If EntryPoint is NULL, then ASSERT().
4666 If NewStack is NULL, then ASSERT().
4668 There are a number of constraints that must be followed before calling this
4670 1) Interrupts must be disabled.
4671 2) The caller must be in 32-bit paged mode.
4672 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
4673 4) CR3 must point to valid page tables that guarantee that the pages for
4674 this function and the stack are identity mapped.
4676 @param EntryPoint A pointer to function to call with the new stack after
4678 @param Context1 A pointer to the context to pass into the EntryPoint
4679 function as the first parameter after paging is disabled.
4680 @param Context2 A pointer to the context to pass into the EntryPoint
4681 function as the second parameter after paging is
4683 @param NewStack A pointer to the new stack to use for the EntryPoint
4684 function after paging is disabled.
4689 AsmDisablePaging32 (
4690 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4691 IN VOID
*Context1
, OPTIONAL
4692 IN VOID
*Context2
, OPTIONAL
4697 Enables the 64-bit paging mode on the CPU.
4699 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4700 must be properly initialized prior to calling this service. This function
4701 assumes the current execution mode is 32-bit protected mode with flat
4702 descriptors. This function is only available on IA-32. After the 64-bit
4703 paging mode is enabled, control is transferred to the function specified by
4704 EntryPoint using the new stack specified by NewStack and passing in the
4705 parameters specified by Context1 and Context2. Context1 and Context2 are
4706 optional and may be 0. The function EntryPoint must never return.
4708 If the current execution mode is not 32-bit protected mode with flat
4709 descriptors, then ASSERT().
4710 If EntryPoint is 0, then ASSERT().
4711 If NewStack is 0, then ASSERT().
4713 @param Cs The 16-bit selector to load in the CS before EntryPoint
4714 is called. The descriptor in the GDT that this selector
4715 references must be setup for long mode.
4716 @param EntryPoint The 64-bit virtual address of the function to call with
4717 the new stack after paging is enabled.
4718 @param Context1 The 64-bit virtual address of the context to pass into
4719 the EntryPoint function as the first parameter after
4721 @param Context2 The 64-bit virtual address of the context to pass into
4722 the EntryPoint function as the second parameter after
4724 @param NewStack The 64-bit virtual address of the new stack to use for
4725 the EntryPoint function after paging is enabled.
4731 IN UINT16 CodeSelector
,
4732 IN UINT64 EntryPoint
,
4733 IN UINT64 Context1
, OPTIONAL
4734 IN UINT64 Context2
, OPTIONAL
4739 Disables the 64-bit paging mode on the CPU.
4741 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
4742 mode. This function assumes the current execution mode is 64-paging mode.
4743 This function is only available on X64. After the 64-bit paging mode is
4744 disabled, control is transferred to the function specified by EntryPoint
4745 using the new stack specified by NewStack and passing in the parameters
4746 specified by Context1 and Context2. Context1 and Context2 are optional and
4747 may be 0. The function EntryPoint must never return.
4749 If the current execution mode is not 64-bit paged mode, then ASSERT().
4750 If EntryPoint is 0, then ASSERT().
4751 If NewStack is 0, then ASSERT().
4753 @param Cs The 16-bit selector to load in the CS before EntryPoint
4754 is called. The descriptor in the GDT that this selector
4755 references must be setup for 32-bit protected mode.
4756 @param EntryPoint The 64-bit virtual address of the function to call with
4757 the new stack after paging is disabled.
4758 @param Context1 The 64-bit virtual address of the context to pass into
4759 the EntryPoint function as the first parameter after
4761 @param Context2 The 64-bit virtual address of the context to pass into
4762 the EntryPoint function as the second parameter after
4764 @param NewStack The 64-bit virtual address of the new stack to use for
4765 the EntryPoint function after paging is disabled.
4770 AsmDisablePaging64 (
4771 IN UINT16 CodeSelector
,
4772 IN UINT32 EntryPoint
,
4773 IN UINT32 Context1
, OPTIONAL
4774 IN UINT32 Context2
, OPTIONAL
4779 // 16-bit thunking services
4783 Retrieves the properties for 16-bit thunk functions.
4785 Computes the size of the buffer and stack below 1MB required to use the
4786 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
4787 buffer size is returned in RealModeBufferSize, and the stack size is returned
4788 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
4789 then the actual minimum stack size is ExtraStackSize plus the maximum number
4790 of bytes that need to be passed to the 16-bit real mode code.
4792 If RealModeBufferSize is NULL, then ASSERT().
4793 If ExtraStackSize is NULL, then ASSERT().
4795 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
4796 required to use the 16-bit thunk functions.
4797 @param ExtraStackSize A pointer to the extra size of stack below 1MB
4798 that the 16-bit thunk functions require for
4799 temporary storage in the transition to and from
4805 AsmGetThunk16Properties (
4806 OUT UINT32
*RealModeBufferSize
,
4807 OUT UINT32
*ExtraStackSize
4811 Prepares all structures a code required to use AsmThunk16().
4813 Prepares all structures and code required to use AsmThunk16().
4815 If ThunkContext is NULL, then ASSERT().
4817 @param ThunkContext A pointer to the context structure that describes the
4818 16-bit real mode code to call.
4824 OUT THUNK_CONTEXT
*ThunkContext
4828 Transfers control to a 16-bit real mode entry point and returns the results.
4830 Transfers control to a 16-bit real mode entry point and returns the results.
4831 AsmPrepareThunk16() must be called with ThunkContext before this function is
4834 If ThunkContext is NULL, then ASSERT().
4835 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
4837 @param ThunkContext A pointer to the context structure that describes the
4838 16-bit real mode code to call.
4844 IN OUT THUNK_CONTEXT
*ThunkContext
4848 Prepares all structures and code for a 16-bit real mode thunk, transfers
4849 control to a 16-bit real mode entry point, and returns the results.
4851 Prepares all structures and code for a 16-bit real mode thunk, transfers
4852 control to a 16-bit real mode entry point, and returns the results. If the
4853 caller only need to perform a single 16-bit real mode thunk, then this
4854 service should be used. If the caller intends to make more than one 16-bit
4855 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
4856 once and AsmThunk16() can be called for each 16-bit real mode thunk.
4858 If ThunkContext is NULL, then ASSERT().
4860 @param ThunkContext A pointer to the context structure that describes the
4861 16-bit real mode code to call.
4866 AsmPrepareAndThunk16 (
4867 IN OUT THUNK_CONTEXT
*ThunkContext