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 not including the
138 Null-terminator, then ASSERT().
140 @param Destination Pointer to a Null-terminated Unicode string.
141 @param Source Pointer to a Null-terminated Unicode string.
149 OUT CHAR16
*Destination
,
150 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 not including the
170 Null-terminator, then ASSERT().
172 @param Destination Pointer to a Null-terminated Unicode string.
173 @param Source Pointer to a Null-terminated Unicode string.
174 @param Length Maximum number of Unicode characters to copy.
182 OUT CHAR16
*Destination
,
183 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 not including the
195 Null-terminator, then ASSERT().
197 @param String Pointer to a Null-terminated Unicode string.
199 @return The length of String.
205 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 not including the
217 Null-terminator, then ASSERT().
219 @param String Pointer to a Null-terminated Unicode string.
221 @return The size of String.
227 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 not including the
243 Null-terminator, then ASSERT().
244 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
245 than PcdMaximumUnicodeStringLength Unicode characters not including the
246 Null-terminator, then ASSERT().
248 @param FirstString Pointer to a Null-terminated Unicode string.
249 @param SecondString Pointer to a Null-terminated Unicode string.
251 @retval 0 FirstString is identical to SecondString.
252 @retval !=0 FirstString is not identical to SecondString.
258 IN CONST CHAR16
*FirstString
,
259 IN CONST CHAR16
*SecondString
262 Compares two Null-terminated Unicode strings with maximum lengths, and
263 returns the difference between the first mismatched Unicode characters.
265 This function compares the Null-terminated Unicode string FirstString to the
266 Null-terminated Unicode string SecondString. At most, Length Unicode
267 characters will be compared. If Length is 0, then 0 is returned. If
268 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
269 value returned is the first mismatched Unicode character in SecondString
270 subtracted from the first mismatched Unicode character in FirstString.
272 If FirstString is NULL, then ASSERT().
273 If SecondString is NULL, then ASSERT().
274 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
275 than PcdMaximumUnicodeStringLength Unicode characters not including the
276 Null-terminator, then ASSERT().
277 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
278 than PcdMaximumUnicodeStringLength Unicode characters not including the
279 Null-terminator, then ASSERT().
281 @param FirstString Pointer to a Null-terminated Unicode string.
282 @param SecondString Pointer to a Null-terminated Unicode string.
283 @param Length Maximum number of Unicode characters to compare.
285 @retval 0 FirstString is identical to SecondString.
286 @retval !=0 FirstString is not identical to SecondString.
292 IN CONST CHAR16
*FirstString
,
293 IN CONST CHAR16
*SecondString
,
297 Concatenates one Null-terminated Unicode string to another Null-terminated
298 Unicode string, and returns the concatenated Unicode string.
300 This function concatenates two Null-terminated Unicode strings. The contents
301 of Null-terminated Unicode string Source are concatenated to the end of
302 Null-terminated Unicode string Destination. The Null-terminated concatenated
303 Unicode String is returned. If Source and Destination overlap, then the
304 results are undefined.
306 If Destination is NULL, then ASSERT().
307 If Source is NULL, then ASSERT().
308 If Source and Destination overlap, then ASSERT().
309 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
310 than PcdMaximumUnicodeStringLength Unicode characters not including the
311 Null-terminator, then ASSERT().
312 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
313 PcdMaximumUnicodeStringLength Unicode characters not including the
314 Null-terminator, then ASSERT().
315 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
316 and Source results in a Unicode string with more than
317 PcdMaximumUnicodeStringLength Unicode characters not including the
318 Null-terminator, then ASSERT().
320 @param Destination Pointer to a Null-terminated Unicode string.
321 @param Source Pointer to a Null-terminated Unicode string.
329 IN OUT CHAR16
*Destination
,
330 IN CONST CHAR16
*Source
333 Concatenates one Null-terminated Unicode string with a maximum length to the
334 end of another Null-terminated Unicode string, and returns the concatenated
337 This function concatenates two Null-terminated Unicode strings. The contents
338 of Null-terminated Unicode string Source are concatenated to the end of
339 Null-terminated Unicode string Destination, and Destination is returned. At
340 most, Length Unicode characters are concatenated from Source to the end of
341 Destination, and Destination is always Null-terminated. If Length is 0, then
342 Destination is returned unmodified. If Source and Destination overlap, then
343 the results are undefined.
345 If Destination is NULL, then ASSERT().
346 If Source is NULL, then ASSERT().
347 If Source and Destination overlap, then ASSERT().
348 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
349 than PcdMaximumUnicodeStringLength Unicode characters not including the
350 Null-terminator, then ASSERT().
351 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
352 PcdMaximumUnicodeStringLength Unicode characters not including the
353 Null-terminator, then ASSERT().
354 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
355 and Source results in a Unicode string with more than
356 PcdMaximumUnicodeStringLength Unicode characters not including the
357 Null-terminator, then ASSERT().
359 @param Destination Pointer to a Null-terminated Unicode string.
360 @param Source Pointer to a Null-terminated Unicode string.
361 @param Length Maximum number of Unicode characters to concatenate from
370 IN OUT CHAR16
*Destination
,
371 IN CONST CHAR16
*Source
,
375 Copies one Null-terminated ASCII string to another Null-terminated ASCII
376 string and returns the new ASCII string.
378 This function copies the contents of the ASCII string Source to the ASCII
379 string Destination, and returns Destination. If Source and Destination
380 overlap, then the results are undefined.
382 If Destination is NULL, then ASSERT().
383 If Source is NULL, then ASSERT().
384 If Source and Destination overlap, then ASSERT().
385 If PcdMaximumAsciiStringLength is not zero and Source contains more than
386 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
389 @param Destination Pointer to a Null-terminated ASCII string.
390 @param Source Pointer to a Null-terminated ASCII string.
398 OUT CHAR8
*Destination
,
399 IN CONST CHAR8
*Source
402 Copies one Null-terminated ASCII string with a maximum length to another
403 Null-terminated ASCII string with a maximum length and returns the new ASCII
406 This function copies the contents of the ASCII string Source to the ASCII
407 string Destination, and returns Destination. At most, Length ASCII characters
408 are copied from Source to Destination. If Length is 0, then Destination is
409 returned unmodified. If Length is greater that the number of ASCII characters
410 in Source, then Destination is padded with Null ASCII characters. If Source
411 and Destination overlap, then the results are undefined.
413 If Destination is NULL, then ASSERT().
414 If Source is NULL, then ASSERT().
415 If Source and Destination overlap, then ASSERT().
416 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
417 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
420 @param Destination Pointer to a Null-terminated ASCII string.
421 @param Source Pointer to a Null-terminated ASCII string.
422 @param Length Maximum number of ASCII characters to copy.
430 OUT CHAR8
*Destination
,
431 IN CONST CHAR8
*Source
,
435 Returns the length of a Null-terminated ASCII string.
437 This function returns the number of ASCII characters in the Null-terminated
438 ASCII string specified by String.
440 If String is NULL, then ASSERT().
441 If PcdMaximumAsciiStringLength is not zero and String contains more than
442 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
445 @param String Pointer to a Null-terminated ASCII string.
447 @return The length of String.
453 IN CONST CHAR8
*String
456 Returns the size of a Null-terminated ASCII string in bytes, including the
459 This function returns the size, in bytes, of the Null-terminated ASCII string
462 If String is NULL, then ASSERT().
463 If PcdMaximumAsciiStringLength is not zero and String contains more than
464 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
467 @param String Pointer to a Null-terminated ASCII string.
469 @return The size of String.
475 IN CONST CHAR8
*String
478 Compares two Null-terminated ASCII strings, and returns the difference
479 between the first mismatched ASCII characters.
481 This function compares the Null-terminated ASCII string FirstString to the
482 Null-terminated ASCII string SecondString. If FirstString is identical to
483 SecondString, then 0 is returned. Otherwise, the value returned is the first
484 mismatched ASCII character in SecondString subtracted from the first
485 mismatched ASCII character in FirstString.
487 If FirstString is NULL, then ASSERT().
488 If SecondString is NULL, then ASSERT().
489 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
490 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
492 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
493 than PcdMaximumAsciiStringLength ASCII characters not including the
494 Null-terminator, then ASSERT().
496 @param FirstString Pointer to a Null-terminated ASCII string.
497 @param SecondString Pointer to a Null-terminated ASCII string.
499 @retval 0 FirstString is identical to SecondString.
500 @retval !=0 FirstString is not identical to SecondString.
506 IN CONST CHAR8
*FirstString
,
507 IN CONST CHAR8
*SecondString
510 Performs a case insensitive comparison of two Null-terminated ASCII strings,
511 and returns the difference between the first mismatched ASCII characters.
513 This function performs a case insensitive comparison of the Null-terminated
514 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
515 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
516 value returned is the first mismatched lower case ASCII character in
517 SecondString subtracted from the first mismatched lower case ASCII character
520 If FirstString is NULL, then ASSERT().
521 If SecondString is NULL, then ASSERT().
522 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
523 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
525 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
526 than PcdMaximumAsciiStringLength ASCII characters not including the
527 Null-terminator, then ASSERT().
529 @param FirstString Pointer to a Null-terminated ASCII string.
530 @param SecondString Pointer to a Null-terminated ASCII string.
532 @retval 0 FirstString is identical to SecondString using case insensitive
534 @retval !=0 FirstString is not identical to SecondString using case
535 insensitive comparisons.
541 IN CONST CHAR8
*FirstString
,
542 IN CONST CHAR8
*SecondString
545 Compares two Null-terminated ASCII strings with maximum lengths, and returns
546 the difference between the first mismatched ASCII characters.
548 This function compares the Null-terminated ASCII string FirstString to the
549 Null-terminated ASCII string SecondString. At most, Length ASCII characters
550 will be compared. If Length is 0, then 0 is returned. If FirstString is
551 identical to SecondString, then 0 is returned. Otherwise, the value returned
552 is the first mismatched ASCII character in SecondString subtracted from the
553 first mismatched ASCII character in FirstString.
555 If FirstString is NULL, then ASSERT().
556 If SecondString is NULL, then ASSERT().
557 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
558 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
560 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than
561 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
564 @param FirstString Pointer to a Null-terminated ASCII string.
565 @param SecondString Pointer to a Null-terminated ASCII string.
567 @retval 0 FirstString is identical to SecondString.
568 @retval !=0 FirstString is not identical to SecondString.
574 IN CONST CHAR8
*FirstString
,
575 IN CONST CHAR8
*SecondString
,
579 Concatenates one Null-terminated ASCII string to another Null-terminated
580 ASCII string, and returns the concatenated ASCII string.
582 This function concatenates two Null-terminated ASCII strings. The contents of
583 Null-terminated ASCII string Source are concatenated to the end of Null-
584 terminated ASCII string Destination. The Null-terminated concatenated ASCII
587 If Destination is NULL, then ASSERT().
588 If Source is NULL, then ASSERT().
589 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
590 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
592 If PcdMaximumAsciiStringLength is not zero and Source contains more than
593 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
595 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
596 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
597 ASCII characters, then ASSERT().
599 @param Destination Pointer to a Null-terminated ASCII string.
600 @param Source Pointer to a Null-terminated ASCII string.
608 IN OUT CHAR8
*Destination
,
609 IN CONST CHAR8
*Source
612 Concatenates one Null-terminated ASCII string with a maximum length to the
613 end of another Null-terminated ASCII string, and returns the concatenated
616 This function concatenates two Null-terminated ASCII strings. The contents
617 of Null-terminated ASCII string Source are concatenated to the end of Null-
618 terminated ASCII string Destination, and Destination is returned. At most,
619 Length ASCII characters are concatenated from Source to the end of
620 Destination, and Destination is always Null-terminated. If Length is 0, then
621 Destination is returned unmodified. If Source and Destination overlap, then
622 the results are undefined.
624 If Destination is NULL, then ASSERT().
625 If Source is NULL, then ASSERT().
626 If Source and Destination overlap, then ASSERT().
627 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
628 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
630 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
631 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
633 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
634 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
635 ASCII characters not including the Null-terminator, then ASSERT().
637 @param Destination Pointer to a Null-terminated ASCII string.
638 @param Source Pointer to a Null-terminated ASCII string.
639 @param Length Maximum number of ASCII characters to concatenate from
648 IN OUT CHAR8
*Destination
,
649 IN CONST CHAR8
*Source
,
653 Converts an 8-bit value to an 8-bit BCD value.
655 Converts the 8-bit value specified by Value to BCD. The BCD value is
658 If Value >= 100, then ASSERT().
660 @param Value The 8-bit value to convert to BCD. Range 0..99.
662 @return The BCD value
672 Converts an 8-bit BCD value to an 8-bit value.
674 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
677 If Value >= 0xA0, then ASSERT().
678 If (Value & 0x0F) >= 0x0A, then ASSERT().
680 @param Value The 8-bit BCD value to convert to an 8-bit value.
682 @return The 8-bit value is returned.
692 // LIST_ENTRY definition
694 typedef struct _LIST_ENTRY LIST_ENTRY
;
697 LIST_ENTRY
*ForwardLink
;
698 LIST_ENTRY
*BackLink
;
702 // Linked List Functions and Macros
706 Initializes the head node of a doubly linked list that is declared as a
707 global variable in a module.
709 Initializes the forward and backward links of a new linked list. After
710 initializing a linked list with this macro, the other linked list functions
711 may be used to add and remove nodes from the linked list. This macro results
712 in smaller executables by initializing the linked list in the data section,
713 instead if calling the InitializeListHead() function to perform the
714 equivalent operation.
716 @param ListHead The head note of a list to initiailize.
719 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
722 Initializes the head node of a doubly linked list, and returns the pointer to
723 the head node of the doubly linked list.
725 Initializes the forward and backward links of a new linked list. After
726 initializing a linked list with this function, the other linked list
727 functions may be used to add and remove nodes from the linked list. It is up
728 to the caller of this function to allocate the memory for ListHead.
730 If ListHead is NULL, then ASSERT().
732 @param ListHead A pointer to the head node of a new doubly linked list.
740 IN LIST_ENTRY
*ListHead
744 Adds a node to the beginning of a doubly linked list, and returns the pointer
745 to the head node of the doubly linked list.
747 Adds the node Entry at the beginning of the doubly linked list denoted by
748 ListHead, and returns ListHead.
750 If ListHead is NULL, then ASSERT().
751 If Entry is NULL, then ASSERT().
752 If ListHead was not initialized with InitializeListHead(), then ASSERT().
753 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
754 of nodes in ListHead, including the ListHead node, is greater than or
755 equal to PcdMaximumLinkedListLength, then ASSERT().
757 @param ListHead A pointer to the head node of a doubly linked list.
758 @param Entry A pointer to a node that is to be inserted at the beginning
759 of a doubly linked list.
767 IN LIST_ENTRY
*ListHead
,
772 Adds a node to the end of a doubly linked list, and returns the pointer to
773 the head node of the doubly linked list.
775 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
776 and returns ListHead.
778 If ListHead is NULL, then ASSERT().
779 If Entry is NULL, then ASSERT().
780 If ListHead was not initialized with InitializeListHead(), then ASSERT().
781 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
782 of nodes in ListHead, including the ListHead node, is greater than or
783 equal to PcdMaximumLinkedListLength, then ASSERT().
785 @param ListHead A pointer to the head node of a doubly linked list.
786 @param Entry A pointer to a node that is to be added at the end of the
795 IN LIST_ENTRY
*ListHead
,
800 Retrieves the first node of a doubly linked list.
802 Returns the first node of a doubly linked list. List must have been
803 initialized with InitializeListHead(). If List is empty, then NULL is
806 If List is NULL, then ASSERT().
807 If List was not initialized with InitializeListHead(), then ASSERT().
808 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
809 in List, including the List node, is greater than or equal to
810 PcdMaximumLinkedListLength, then ASSERT().
812 @param List A pointer to the head node of a doubly linked list.
814 @return The first node of a doubly linked list.
815 @retval NULL The list is empty.
821 IN CONST LIST_ENTRY
*List
825 Retrieves the next node of a doubly linked list.
827 Returns the node of a doubly linked list that follows Node. List must have
828 been initialized with InitializeListHead(). If List is empty, then List is
831 If List is NULL, then ASSERT().
832 If Node is NULL, then ASSERT().
833 If List was not initialized with InitializeListHead(), then ASSERT().
834 If PcdMaximumLinkedListLenth is not zero, and List contains more than
835 PcdMaximumLinkedListLenth nodes, then ASSERT().
836 If Node is not a node in List, then ASSERT().
838 @param List A pointer to the head node of a doubly linked list.
839 @param Node A pointer to a node in the doubly linked list.
841 @return Pointer to the next node if one exists. Otherwise a null value which
842 is actually List is returned.
848 IN CONST LIST_ENTRY
*List
,
849 IN CONST LIST_ENTRY
*Node
853 Checks to see if a doubly linked list is empty or not.
855 Checks to see if the doubly linked list is empty. If the linked list contains
856 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
858 If ListHead is NULL, then ASSERT().
859 If ListHead was not initialized with InitializeListHead(), then ASSERT().
860 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
861 in List, including the List node, is greater than or equal to
862 PcdMaximumLinkedListLength, then ASSERT().
864 @param ListHead A pointer to the head node of a doubly linked list.
866 @retval TRUE The linked list is empty.
867 @retval FALSE The linked list is not empty.
873 IN CONST LIST_ENTRY
*ListHead
877 Determines if a node in a doubly linked list is null.
879 Returns FALSE if Node is one of the nodes in the doubly linked list specified
880 by List. Otherwise, TRUE is returned. List must have been initialized with
881 InitializeListHead().
883 If List is NULL, then ASSERT().
884 If Node is NULL, then ASSERT().
885 If List was not initialized with InitializeListHead(), then ASSERT().
886 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
887 in List, including the List node, is greater than or equal to
888 PcdMaximumLinkedListLength, then ASSERT().
889 If Node is not a node in List and Node is not equal to List, then ASSERT().
891 @param List A pointer to the head node of a doubly linked list.
892 @param Node A pointer to a node in the doubly linked list.
894 @retval TRUE Node is one of the nodes in the doubly linked list.
895 @retval FALSE Node is not one of the nodes in the doubly linked list.
901 IN CONST LIST_ENTRY
*List
,
902 IN CONST LIST_ENTRY
*Node
906 Determines if a node the last node in a doubly linked list.
908 Returns TRUE if Node is the last node in the doubly linked list specified by
909 List. Otherwise, FALSE is returned. List must have been initialized with
910 InitializeListHead().
912 If List is NULL, then ASSERT().
913 If Node is NULL, then ASSERT().
914 If List was not initialized with InitializeListHead(), then ASSERT().
915 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
916 in List, including the List node, is greater than or equal to
917 PcdMaximumLinkedListLength, then ASSERT().
918 If Node is not a node in List, then ASSERT().
920 @param List A pointer to the head node of a doubly linked list.
921 @param Node A pointer to a node in the doubly linked list.
923 @retval TRUE Node is the last node in the linked list.
924 @retval FALSE Node is not the last node in the linked list.
930 IN CONST LIST_ENTRY
*List
,
931 IN CONST LIST_ENTRY
*Node
935 Swaps the location of two nodes in a doubly linked list, and returns the
936 first node after the swap.
938 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
939 Otherwise, the location of the FirstEntry node is swapped with the location
940 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
941 same double linked list as FirstEntry and that double linked list must have
942 been initialized with InitializeListHead(). SecondEntry is returned after the
945 If FirstEntry is NULL, then ASSERT().
946 If SecondEntry is NULL, then ASSERT().
947 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
948 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
949 linked list containing the FirstEntry and SecondEntry nodes, including
950 the FirstEntry and SecondEntry nodes, is greater than or equal to
951 PcdMaximumLinkedListLength, then ASSERT().
953 @param FirstEntry A pointer to a node in a linked list.
954 @param SecondEntry A pointer to another node in the same linked list.
960 IN LIST_ENTRY
*FirstEntry
,
961 IN LIST_ENTRY
*SecondEntry
965 Removes a node from a doubly linked list, and returns the node that follows
968 Removes the node Entry from a doubly linked list. It is up to the caller of
969 this function to release the memory used by this node if that is required. On
970 exit, the node following Entry in the doubly linked list is returned. If
971 Entry is the only node in the linked list, then the head node of the linked
974 If Entry is NULL, then ASSERT().
975 If Entry is the head node of an empty list, then ASSERT().
976 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
977 linked list containing Entry, including the Entry node, is greater than
978 or equal to PcdMaximumLinkedListLength, then ASSERT().
980 @param Entry A pointer to a node in a linked list
988 IN CONST LIST_ENTRY
*Entry
996 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
997 with zeros. The shifted value is returned.
999 This function shifts the 64-bit value Operand to the left by Count bits. The
1000 low Count bits are set to zero. The shifted value is returned.
1002 If Count is greater than 63, then ASSERT().
1004 @param Operand The 64-bit operand to shift left.
1005 @param Count The number of bits to shift left.
1007 @return Operand << Count
1018 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1019 filled with zeros. The shifted value is returned.
1021 This function shifts the 64-bit value Operand to the right by Count bits. The
1022 high Count bits are set to zero. The shifted value is returned.
1024 If Count is greater than 63, then ASSERT().
1026 @param Operand The 64-bit operand to shift right.
1027 @param Count The number of bits to shift right.
1029 @return Operand >> Count
1040 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1041 with original integer's bit 63. The shifted value is returned.
1043 This function shifts the 64-bit value Operand to the right by Count bits. The
1044 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1046 If Count is greater than 63, then ASSERT().
1048 @param Operand The 64-bit operand to shift right.
1049 @param Count The number of bits to shift right.
1051 @return Operand >> Count
1062 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1063 with the high bits that were rotated.
1065 This function rotates the 32-bit value Operand to the left by Count bits. The
1066 low Count bits are fill with the high Count bits of Operand. The rotated
1069 If Count is greater than 31, then ASSERT().
1071 @param Operand The 32-bit operand to rotate left.
1072 @param Count The number of bits to rotate left.
1074 @return Operand <<< Count
1085 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1086 with the low bits that were rotated.
1088 This function rotates the 32-bit value Operand to the right by Count bits.
1089 The high Count bits are fill with the low Count bits of Operand. The rotated
1092 If Count is greater than 31, then ASSERT().
1094 @param Operand The 32-bit operand to rotate right.
1095 @param Count The number of bits to rotate right.
1097 @return Operand >>> Count
1108 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1109 with the high bits that were rotated.
1111 This function rotates the 64-bit value Operand to the left by Count bits. The
1112 low Count bits are fill with the high Count bits of Operand. The rotated
1115 If Count is greater than 63, then ASSERT().
1117 @param Operand The 64-bit operand to rotate left.
1118 @param Count The number of bits to rotate left.
1120 @return Operand <<< Count
1131 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1132 with the high low bits that were rotated.
1134 This function rotates the 64-bit value Operand to the right by Count bits.
1135 The high Count bits are fill with the low Count bits of Operand. The rotated
1138 If Count is greater than 63, then ASSERT().
1140 @param Operand The 64-bit operand to rotate right.
1141 @param Count The number of bits to rotate right.
1143 @return Operand >>> Count
1154 Returns the bit position of the lowest bit set in a 32-bit value.
1156 This function computes the bit position of the lowest bit set in the 32-bit
1157 value specified by Operand. If Operand is zero, then -1 is returned.
1158 Otherwise, a value between 0 and 31 is returned.
1160 @param Operand The 32-bit operand to evaluate.
1162 @return Position of the lowest bit set in Operand if found.
1163 @retval -1 Operand is zero.
1173 Returns the bit position of the lowest bit set in a 64-bit value.
1175 This function computes the bit position of the lowest bit set in the 64-bit
1176 value specified by Operand. If Operand is zero, then -1 is returned.
1177 Otherwise, a value between 0 and 63 is returned.
1179 @param Operand The 64-bit operand to evaluate.
1181 @return Position of the lowest bit set in Operand if found.
1182 @retval -1 Operand is zero.
1192 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1195 This function computes the bit position of the highest bit set in the 32-bit
1196 value specified by Operand. If Operand is zero, then -1 is returned.
1197 Otherwise, a value between 0 and 31 is returned.
1199 @param Operand The 32-bit operand to evaluate.
1201 @return Position of the highest bit set in Operand if found.
1202 @retval -1 Operand is zero.
1212 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1215 This function computes the bit position of the highest bit set in the 64-bit
1216 value specified by Operand. If Operand is zero, then -1 is returned.
1217 Otherwise, a value between 0 and 63 is returned.
1219 @param Operand The 64-bit operand to evaluate.
1221 @return Position of the highest bit set in Operand if found.
1222 @retval -1 Operand is zero.
1232 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1233 1 << HighBitSet32(x).
1235 This function computes the value of the highest bit set in the 32-bit value
1236 specified by Operand. If Operand is zero, then zero is returned.
1238 @param Operand The 32-bit operand to evaluate.
1240 @return 1 << HighBitSet32(Operand)
1241 @retval 0 Operand is zero.
1251 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1252 1 << HighBitSet64(x).
1254 This function computes the value of the highest bit set in the 64-bit value
1255 specified by Operand. If Operand is zero, then zero is returned.
1257 @param Operand The 64-bit operand to evaluate.
1259 @return 1 << HighBitSet64(Operand)
1260 @retval 0 Operand is zero.
1270 Switches the endianess of a 16-bit integer.
1272 This function swaps the bytes in a 16-bit unsigned value to switch the value
1273 from little endian to big endian or vice versa. The byte swapped value is
1276 @param Operand A 16-bit unsigned value.
1278 @return The byte swaped Operand.
1288 Switches the endianess of a 32-bit integer.
1290 This function swaps the bytes in a 32-bit unsigned value to switch the value
1291 from little endian to big endian or vice versa. The byte swapped value is
1294 @param Operand A 32-bit unsigned value.
1296 @return The byte swaped Operand.
1306 Switches the endianess of a 64-bit integer.
1308 This function swaps the bytes in a 64-bit unsigned value to switch the value
1309 from little endian to big endian or vice versa. The byte swapped value is
1312 @param Operand A 64-bit unsigned value.
1314 @return The byte swaped Operand.
1324 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1325 generates a 64-bit unsigned result.
1327 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1328 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1329 bit unsigned result is returned.
1331 If the result overflows, then ASSERT().
1333 @param Multiplicand A 64-bit unsigned value.
1334 @param Multiplier A 32-bit unsigned value.
1336 @return Multiplicand * Multiplier
1342 IN UINT64 Multiplicand
,
1343 IN UINT32 Multiplier
1347 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1348 generates a 64-bit unsigned result.
1350 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1351 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1352 bit unsigned result is returned.
1354 If the result overflows, then ASSERT().
1356 @param Multiplicand A 64-bit unsigned value.
1357 @param Multiplier A 64-bit unsigned value.
1359 @return Multiplicand * Multiplier
1365 IN UINT64 Multiplicand
,
1366 IN UINT64 Multiplier
1370 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1371 64-bit signed result.
1373 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1374 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1375 signed result is returned.
1377 If the result overflows, then ASSERT().
1379 @param Multiplicand A 64-bit signed value.
1380 @param Multiplier A 64-bit signed value.
1382 @return Multiplicand * Multiplier
1388 IN INT64 Multiplicand
,
1393 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1394 a 64-bit unsigned result.
1396 This function divides the 64-bit unsigned value Dividend by the 32-bit
1397 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1398 function returns the 64-bit unsigned quotient.
1400 If Divisor is 0, then ASSERT().
1402 @param Dividend A 64-bit unsigned value.
1403 @param Divisor A 32-bit unsigned value.
1405 @return Dividend / Divisor
1416 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1417 a 32-bit unsigned remainder.
1419 This function divides the 64-bit unsigned value Dividend by the 32-bit
1420 unsigned value Divisor and generates a 32-bit remainder. This function
1421 returns the 32-bit unsigned remainder.
1423 If Divisor is 0, then ASSERT().
1425 @param Dividend A 64-bit unsigned value.
1426 @param Divisor A 32-bit unsigned value.
1428 @return Dividend % Divisor
1439 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1440 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1442 This function divides the 64-bit unsigned value Dividend by the 32-bit
1443 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1444 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1445 This function returns the 64-bit unsigned quotient.
1447 If Divisor is 0, then ASSERT().
1449 @param Dividend A 64-bit unsigned value.
1450 @param Divisor A 32-bit unsigned value.
1451 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1452 optional and may be NULL.
1454 @return Dividend / Divisor
1459 DivU64x32Remainder (
1462 OUT UINT32
*Remainder OPTIONAL
1466 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
1467 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
1469 This function divides the 64-bit unsigned value Dividend by the 64-bit
1470 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1471 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
1472 This function returns the 64-bit unsigned quotient.
1474 If Divisor is 0, then ASSERT().
1476 @param Dividend A 64-bit unsigned value.
1477 @param Divisor A 64-bit unsigned value.
1478 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
1479 optional and may be NULL.
1481 @return Dividend / Divisor
1486 DivU64x64Remainder (
1489 OUT UINT64
*Remainder OPTIONAL
1493 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
1494 64-bit signed result and a optional 64-bit signed remainder.
1496 This function divides the 64-bit signed value Dividend by the 64-bit signed
1497 value Divisor and generates a 64-bit signed quotient. If Remainder is not
1498 NULL, then the 64-bit signed remainder is returned in Remainder. This
1499 function returns the 64-bit signed quotient.
1501 If Divisor is 0, then ASSERT().
1503 @param Dividend A 64-bit signed value.
1504 @param Divisor A 64-bit signed value.
1505 @param Remainder A pointer to a 64-bit signed value. This parameter is
1506 optional and may be NULL.
1508 @return Dividend / Divisor
1513 DivS64x64Remainder (
1516 OUT INT64
*Remainder OPTIONAL
1520 Reads a 16-bit value from memory that may be unaligned.
1522 This function returns the 16-bit value pointed to by Buffer. The function
1523 guarantees that the read operation does not produce an alignment fault.
1525 If the Buffer is NULL, then ASSERT().
1527 @param Buffer Pointer to a 16-bit value that may be unaligned.
1535 IN CONST UINT16
*Uint16
1539 Writes a 16-bit value to memory that may be unaligned.
1541 This function writes the 16-bit value specified by Value to Buffer. Value is
1542 returned. The function guarantees that the write operation does not produce
1545 If the Buffer is NULL, then ASSERT().
1547 @param Buffer Pointer to a 16-bit value that may be unaligned.
1548 @param Value 16-bit value to write to Buffer.
1561 Reads a 24-bit value from memory that may be unaligned.
1563 This function returns the 24-bit value pointed to by Buffer. The function
1564 guarantees that the read operation does not produce an alignment fault.
1566 If the Buffer is NULL, then ASSERT().
1568 @param Buffer Pointer to a 24-bit value that may be unaligned.
1570 @return The value read.
1576 IN CONST UINT32
*Buffer
1580 Writes a 24-bit value to memory that may be unaligned.
1582 This function writes the 24-bit value specified by Value to Buffer. Value is
1583 returned. The function guarantees that the write operation does not produce
1586 If the Buffer is NULL, then ASSERT().
1588 @param Buffer Pointer to a 24-bit value that may be unaligned.
1589 @param Value 24-bit value to write to Buffer.
1591 @return The value written.
1602 Reads a 32-bit value from memory that may be unaligned.
1604 This function returns the 32-bit value pointed to by Buffer. The function
1605 guarantees that the read operation does not produce an alignment fault.
1607 If the Buffer is NULL, then ASSERT().
1609 @param Buffer Pointer to a 32-bit value that may be unaligned.
1617 IN CONST UINT32
*Uint32
1621 Writes a 32-bit value to memory that may be unaligned.
1623 This function writes the 32-bit value specified by Value to Buffer. Value is
1624 returned. The function guarantees that the write operation does not produce
1627 If the Buffer is NULL, then ASSERT().
1629 @param Buffer Pointer to a 32-bit value that may be unaligned.
1630 @param Value 32-bit value to write to Buffer.
1643 Reads a 64-bit value from memory that may be unaligned.
1645 This function returns the 64-bit value pointed to by Buffer. The function
1646 guarantees that the read operation does not produce an alignment fault.
1648 If the Buffer is NULL, then ASSERT().
1650 @param Buffer Pointer to a 64-bit value that may be unaligned.
1658 IN CONST UINT64
*Uint64
1662 Writes a 64-bit value to memory that may be unaligned.
1664 This function writes the 64-bit value specified by Value to Buffer. Value is
1665 returned. The function guarantees that the write operation does not produce
1668 If the Buffer is NULL, then ASSERT().
1670 @param Buffer Pointer to a 64-bit value that may be unaligned.
1671 @param Value 64-bit value to write to Buffer.
1684 // Bit Field Functions
1688 Returns a bit field from an 8-bit value.
1690 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1692 If 8-bit operations are not supported, then ASSERT().
1693 If StartBit is greater than 7, then ASSERT().
1694 If EndBit is greater than 7, then ASSERT().
1695 If EndBit is less than StartBit, then ASSERT().
1697 @param Operand Operand on which to perform the bitfield operation.
1698 @param StartBit The ordinal of the least significant bit in the bit field.
1700 @param EndBit The ordinal of the most significant bit in the bit field.
1703 @return The bit field read.
1715 Writes a bit field to an 8-bit value, and returns the result.
1717 Writes Value to the bit field specified by the StartBit and the EndBit in
1718 Operand. All other bits in Operand are preserved. The new 8-bit value is
1721 If 8-bit operations are not supported, then ASSERT().
1722 If StartBit is greater than 7, then ASSERT().
1723 If EndBit is greater than 7, then ASSERT().
1724 If EndBit is less than StartBit, then ASSERT().
1726 @param Operand Operand on which to perform the bitfield operation.
1727 @param StartBit The ordinal of the least significant bit in the bit field.
1729 @param EndBit The ordinal of the most significant bit in the bit field.
1731 @param Value New value of the bit field.
1733 @return The new 8-bit value.
1746 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
1749 Performs a bitwise inclusive OR between the bit field specified by StartBit
1750 and EndBit in Operand and the value specified by OrData. All other bits in
1751 Operand are preserved. The new 8-bit value is returned.
1753 If 8-bit operations are not supported, then ASSERT().
1754 If StartBit is greater than 7, then ASSERT().
1755 If EndBit is greater than 7, then ASSERT().
1756 If EndBit is less than StartBit, then ASSERT().
1758 @param Operand Operand on which to perform the bitfield operation.
1759 @param StartBit The ordinal of the least significant bit in the bit field.
1761 @param EndBit The ordinal of the most significant bit in the bit field.
1763 @param OrData The value to OR with the read value from the value
1765 @return The new 8-bit value.
1778 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
1781 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1782 in Operand and the value specified by AndData. All other bits in Operand are
1783 preserved. The new 8-bit value is returned.
1785 If 8-bit operations are not supported, then ASSERT().
1786 If StartBit is greater than 7, then ASSERT().
1787 If EndBit is greater than 7, then ASSERT().
1788 If EndBit is less than StartBit, then ASSERT().
1790 @param Operand Operand on which to perform the bitfield operation.
1791 @param StartBit The ordinal of the least significant bit in the bit field.
1793 @param EndBit The ordinal of the most significant bit in the bit field.
1795 @param AndData The value to AND with the read value from the value.
1797 @return The new 8-bit value.
1810 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
1811 bitwise OR, and returns the result.
1813 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1814 in Operand and the value specified by AndData, followed by a bitwise
1815 inclusive OR with value specified by OrData. All other bits in Operand are
1816 preserved. The new 8-bit value is returned.
1818 If 8-bit operations are not supported, then ASSERT().
1819 If StartBit is greater than 7, then ASSERT().
1820 If EndBit is greater than 7, then ASSERT().
1821 If EndBit is less than StartBit, then ASSERT().
1823 @param Operand Operand on which to perform the bitfield operation.
1824 @param StartBit The ordinal of the least significant bit in the bit field.
1826 @param EndBit The ordinal of the most significant bit in the bit field.
1828 @param AndData The value to AND with the read value from the value.
1829 @param OrData The value to OR with the result of the AND operation.
1831 @return The new 8-bit value.
1836 BitFieldAndThenOr8 (
1845 Returns a bit field from a 16-bit value.
1847 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1849 If 16-bit operations are not supported, then ASSERT().
1850 If StartBit is greater than 15, then ASSERT().
1851 If EndBit is greater than 15, then ASSERT().
1852 If EndBit is less than StartBit, then ASSERT().
1854 @param Operand Operand on which to perform the bitfield operation.
1855 @param StartBit The ordinal of the least significant bit in the bit field.
1857 @param EndBit The ordinal of the most significant bit in the bit field.
1860 @return The bit field read.
1872 Writes a bit field to a 16-bit value, and returns the result.
1874 Writes Value to the bit field specified by the StartBit and the EndBit in
1875 Operand. All other bits in Operand are preserved. The new 16-bit value is
1878 If 16-bit operations are not supported, then ASSERT().
1879 If StartBit is greater than 15, then ASSERT().
1880 If EndBit is greater than 15, then ASSERT().
1881 If EndBit is less than StartBit, then ASSERT().
1883 @param Operand Operand on which to perform the bitfield operation.
1884 @param StartBit The ordinal of the least significant bit in the bit field.
1886 @param EndBit The ordinal of the most significant bit in the bit field.
1888 @param Value New value of the bit field.
1890 @return The new 16-bit value.
1903 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
1906 Performs a bitwise inclusive OR between the bit field specified by StartBit
1907 and EndBit in Operand and the value specified by OrData. All other bits in
1908 Operand are preserved. The new 16-bit value is returned.
1910 If 16-bit operations are not supported, then ASSERT().
1911 If StartBit is greater than 15, then ASSERT().
1912 If EndBit is greater than 15, then ASSERT().
1913 If EndBit is less than StartBit, then ASSERT().
1915 @param Operand Operand on which to perform the bitfield operation.
1916 @param StartBit The ordinal of the least significant bit in the bit field.
1918 @param EndBit The ordinal of the most significant bit in the bit field.
1920 @param OrData The value to OR with the read value from the value
1922 @return The new 16-bit value.
1935 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
1938 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1939 in Operand and the value specified by AndData. All other bits in Operand are
1940 preserved. The new 16-bit value is returned.
1942 If 16-bit operations are not supported, then ASSERT().
1943 If StartBit is greater than 15, then ASSERT().
1944 If EndBit is greater than 15, then ASSERT().
1945 If EndBit is less than StartBit, then ASSERT().
1947 @param Operand Operand on which to perform the bitfield operation.
1948 @param StartBit The ordinal of the least significant bit in the bit field.
1950 @param EndBit The ordinal of the most significant bit in the bit field.
1952 @param AndData The value to AND with the read value from the value
1954 @return The new 16-bit value.
1967 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
1968 bitwise OR, and returns the result.
1970 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1971 in Operand and the value specified by AndData, followed by a bitwise
1972 inclusive OR with value specified by OrData. All other bits in Operand are
1973 preserved. The new 16-bit value is returned.
1975 If 16-bit operations are not supported, then ASSERT().
1976 If StartBit is greater than 15, then ASSERT().
1977 If EndBit is greater than 15, then ASSERT().
1978 If EndBit is less than StartBit, then ASSERT().
1980 @param Operand Operand on which to perform the bitfield operation.
1981 @param StartBit The ordinal of the least significant bit in the bit field.
1983 @param EndBit The ordinal of the most significant bit in the bit field.
1985 @param AndData The value to AND with the read value from the value.
1986 @param OrData The value to OR with the result of the AND operation.
1988 @return The new 16-bit value.
1993 BitFieldAndThenOr16 (
2002 Returns a bit field from a 32-bit value.
2004 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2006 If 32-bit operations are not supported, then ASSERT().
2007 If StartBit is greater than 31, then ASSERT().
2008 If EndBit is greater than 31, then ASSERT().
2009 If EndBit is less than StartBit, then ASSERT().
2011 @param Operand Operand on which to perform the bitfield operation.
2012 @param StartBit The ordinal of the least significant bit in the bit field.
2014 @param EndBit The ordinal of the most significant bit in the bit field.
2017 @return The bit field read.
2029 Writes a bit field to a 32-bit value, and returns the result.
2031 Writes Value to the bit field specified by the StartBit and the EndBit in
2032 Operand. All other bits in Operand are preserved. The new 32-bit value is
2035 If 32-bit operations are not supported, then ASSERT().
2036 If StartBit is greater than 31, then ASSERT().
2037 If EndBit is greater than 31, then ASSERT().
2038 If EndBit is less than StartBit, then ASSERT().
2040 @param Operand Operand on which to perform the bitfield operation.
2041 @param StartBit The ordinal of the least significant bit in the bit field.
2043 @param EndBit The ordinal of the most significant bit in the bit field.
2045 @param Value New value of the bit field.
2047 @return The new 32-bit value.
2060 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2063 Performs a bitwise inclusive OR between the bit field specified by StartBit
2064 and EndBit in Operand and the value specified by OrData. All other bits in
2065 Operand are preserved. The new 32-bit value is returned.
2067 If 32-bit operations are not supported, then ASSERT().
2068 If StartBit is greater than 31, then ASSERT().
2069 If EndBit is greater than 31, then ASSERT().
2070 If EndBit is less than StartBit, then ASSERT().
2072 @param Operand Operand on which to perform the bitfield operation.
2073 @param StartBit The ordinal of the least significant bit in the bit field.
2075 @param EndBit The ordinal of the most significant bit in the bit field.
2077 @param OrData The value to OR with the read value from the value
2079 @return The new 32-bit value.
2092 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2095 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2096 in Operand and the value specified by AndData. All other bits in Operand are
2097 preserved. The new 32-bit value is returned.
2099 If 32-bit operations are not supported, then ASSERT().
2100 If StartBit is greater than 31, then ASSERT().
2101 If EndBit is greater than 31, then ASSERT().
2102 If EndBit is less than StartBit, then ASSERT().
2104 @param Operand Operand on which to perform the bitfield operation.
2105 @param StartBit The ordinal of the least significant bit in the bit field.
2107 @param EndBit The ordinal of the most significant bit in the bit field.
2109 @param AndData The value to AND with the read value from the value
2111 @return The new 32-bit value.
2124 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2125 bitwise OR, and returns the result.
2127 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2128 in Operand and the value specified by AndData, followed by a bitwise
2129 inclusive OR with value specified by OrData. All other bits in Operand are
2130 preserved. The new 32-bit value is returned.
2132 If 32-bit operations are not supported, then ASSERT().
2133 If StartBit is greater than 31, then ASSERT().
2134 If EndBit is greater than 31, then ASSERT().
2135 If EndBit is less than StartBit, then ASSERT().
2137 @param Operand Operand on which to perform the bitfield operation.
2138 @param StartBit The ordinal of the least significant bit in the bit field.
2140 @param EndBit The ordinal of the most significant bit in the bit field.
2142 @param AndData The value to AND with the read value from the value.
2143 @param OrData The value to OR with the result of the AND operation.
2145 @return The new 32-bit value.
2150 BitFieldAndThenOr32 (
2159 Returns a bit field from a 64-bit value.
2161 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2163 If 64-bit operations are not supported, then ASSERT().
2164 If StartBit is greater than 63, then ASSERT().
2165 If EndBit is greater than 63, then ASSERT().
2166 If EndBit is less than StartBit, then ASSERT().
2168 @param Operand Operand on which to perform the bitfield operation.
2169 @param StartBit The ordinal of the least significant bit in the bit field.
2171 @param EndBit The ordinal of the most significant bit in the bit field.
2174 @return The bit field read.
2186 Writes a bit field to a 64-bit value, and returns the result.
2188 Writes Value to the bit field specified by the StartBit and the EndBit in
2189 Operand. All other bits in Operand are preserved. The new 64-bit value is
2192 If 64-bit operations are not supported, then ASSERT().
2193 If StartBit is greater than 63, then ASSERT().
2194 If EndBit is greater than 63, then ASSERT().
2195 If EndBit is less than StartBit, then ASSERT().
2197 @param Operand Operand on which to perform the bitfield operation.
2198 @param StartBit The ordinal of the least significant bit in the bit field.
2200 @param EndBit The ordinal of the most significant bit in the bit field.
2202 @param Value New value of the bit field.
2204 @return The new 64-bit value.
2217 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2220 Performs a bitwise inclusive OR between the bit field specified by StartBit
2221 and EndBit in Operand and the value specified by OrData. All other bits in
2222 Operand are preserved. The new 64-bit value is returned.
2224 If 64-bit operations are not supported, then ASSERT().
2225 If StartBit is greater than 63, then ASSERT().
2226 If EndBit is greater than 63, then ASSERT().
2227 If EndBit is less than StartBit, then ASSERT().
2229 @param Operand Operand on which to perform the bitfield operation.
2230 @param StartBit The ordinal of the least significant bit in the bit field.
2232 @param EndBit The ordinal of the most significant bit in the bit field.
2234 @param OrData The value to OR with the read value from the value
2236 @return The new 64-bit value.
2249 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2252 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2253 in Operand and the value specified by AndData. All other bits in Operand are
2254 preserved. The new 64-bit value is returned.
2256 If 64-bit operations are not supported, then ASSERT().
2257 If StartBit is greater than 63, then ASSERT().
2258 If EndBit is greater than 63, then ASSERT().
2259 If EndBit is less than StartBit, then ASSERT().
2261 @param Operand Operand on which to perform the bitfield operation.
2262 @param StartBit The ordinal of the least significant bit in the bit field.
2264 @param EndBit The ordinal of the most significant bit in the bit field.
2266 @param AndData The value to AND with the read value from the value
2268 @return The new 64-bit value.
2281 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2282 bitwise OR, and returns the result.
2284 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2285 in Operand and the value specified by AndData, followed by a bitwise
2286 inclusive OR with value specified by OrData. All other bits in Operand are
2287 preserved. The new 64-bit value is returned.
2289 If 64-bit operations are not supported, then ASSERT().
2290 If StartBit is greater than 63, then ASSERT().
2291 If EndBit is greater than 63, then ASSERT().
2292 If EndBit is less than StartBit, then ASSERT().
2294 @param Operand Operand on which to perform the bitfield operation.
2295 @param StartBit The ordinal of the least significant bit in the bit field.
2297 @param EndBit The ordinal of the most significant bit in the bit field.
2299 @param AndData The value to AND with the read value from the value.
2300 @param OrData The value to OR with the result of the AND operation.
2302 @return The new 64-bit value.
2307 BitFieldAndThenOr64 (
2316 // Base Library Synchronization Functions
2320 Retrieves the architecture specific spin lock alignment requirements for
2321 optimal spin lock performance.
2323 This function retrieves the spin lock alignment requirements for optimal
2324 performance on a given CPU architecture. The spin lock alignment must be a
2325 power of two and is returned by this function. If there are no alignment
2326 requirements, then 1 must be returned. The spin lock synchronization
2327 functions must function correctly if the spin lock size and alignment values
2328 returned by this function are not used at all. These values are hints to the
2329 consumers of the spin lock synchronization functions to obtain optimal spin
2332 @return The architecture specific spin lock alignment.
2337 GetSpinLockProperties (
2342 Initializes a spin lock to the released state and returns the spin lock.
2344 This function initializes the spin lock specified by SpinLock to the released
2345 state, and returns SpinLock. Optimal performance can be achieved by calling
2346 GetSpinLockProperties() to determine the size and alignment requirements for
2349 If SpinLock is NULL, then ASSERT().
2351 @param SpinLock A pointer to the spin lock to initialize to the released
2359 InitializeSpinLock (
2360 IN SPIN_LOCK
*SpinLock
2364 Waits until a spin lock can be placed in the acquired state.
2366 This function checks the state of the spin lock specified by SpinLock. If
2367 SpinLock is in the released state, then this function places SpinLock in the
2368 acquired state and returns SpinLock. Otherwise, this function waits
2369 indefinitely for the spin lock to be released, and then places it in the
2370 acquired state and returns SpinLock. All state transitions of SpinLock must
2371 be performed using MP safe mechanisms.
2373 If SpinLock is NULL, then ASSERT().
2374 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2375 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2376 PcdSpinLockTimeout microseconds, then ASSERT().
2378 @param SpinLock A pointer to the spin lock to place in the acquired state.
2386 IN SPIN_LOCK
*SpinLock
2390 Attempts to place a spin lock in the acquired state.
2392 This function checks the state of the spin lock specified by SpinLock. If
2393 SpinLock is in the released state, then this function places SpinLock in the
2394 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2395 transitions of SpinLock must be performed using MP safe mechanisms.
2397 If SpinLock is NULL, then ASSERT().
2398 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2400 @param SpinLock A pointer to the spin lock to place in the acquired state.
2402 @retval TRUE SpinLock was placed in the acquired state.
2403 @retval FALSE SpinLock could not be acquired.
2408 AcquireSpinLockOrFail (
2409 IN SPIN_LOCK
*SpinLock
2413 Releases a spin lock.
2415 This function places the spin lock specified by SpinLock in the release state
2416 and returns SpinLock.
2418 If SpinLock is NULL, then ASSERT().
2419 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2421 @param SpinLock A pointer to the spin lock to release.
2429 IN SPIN_LOCK
*SpinLock
2433 Performs an atomic increment of an 32-bit unsigned integer.
2435 Performs an atomic increment of the 32-bit unsigned integer specified by
2436 Value and returns the incremented value. The increment operation must be
2437 performed using MP safe mechanisms. The state of the return value is not
2438 guaranteed to be MP safe.
2440 If Value is NULL, then ASSERT().
2442 @param Value A pointer to the 32-bit value to increment.
2444 @return The incremented value.
2449 InterlockedIncrement (
2454 Performs an atomic decrement of an 32-bit unsigned integer.
2456 Performs an atomic decrement of the 32-bit unsigned integer specified by
2457 Value and returns the decremented value. The decrement operation must be
2458 performed using MP safe mechanisms. The state of the return value is not
2459 guaranteed to be MP safe.
2461 If Value is NULL, then ASSERT().
2463 @param Value A pointer to the 32-bit value to decrement.
2465 @return The decremented value.
2470 InterlockedDecrement (
2475 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
2477 @param Value A pointer to the 32-bit value for the compare exchange
2479 @param CompareValue 32-bit value used in compare operation.
2480 @param ExchangeValue 32-bit value used in exchange operation.
2482 @return The original *Value before exchange.
2487 InterlockedCompareExchange32 (
2488 IN OUT UINT32
*Value
,
2489 IN UINT32 CompareValue
,
2490 IN UINT32 ExchangeValue
2494 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
2496 @param Value A pointer to the 64-bit value for the compare exchange
2498 @param CompareValue 64-bit value used in compare operation.
2499 @param ExchangeValue 64-bit value used in exchange operation.
2501 @return The original *Value before exchange.
2506 InterlockedCompareExchange64 (
2507 IN OUT UINT64
*Value
,
2508 IN UINT64 CompareValue
,
2509 IN UINT64 ExchangeValue
2513 Performs an atomic compare exchange operation on a pointer value.
2515 Performs an atomic compare exchange operation on the pointer value specified
2516 by Value. If Value is equal to CompareValue, then Value is set to
2517 ExchangeValue and CompareValue is returned. If Value is not equal to
2518 CompareValue, then Value is returned. The compare exchange operation must be
2519 performed using MP safe mechanisms.
2521 If Value is NULL, then ASSERT().
2523 @param Value A pointer to the pointer value for the compare exchange
2525 @param CompareValue Pointer value used in compare operation.
2526 @param ExchangeValue Pointer value used in exchange operation.
2531 InterlockedCompareExchangePointer (
2532 IN OUT VOID
**Value
,
2533 IN VOID
*CompareValue
,
2534 IN VOID
*ExchangeValue
2538 // Base Library CPU Functions
2542 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
2543 IN VOID
*Context1
, OPTIONAL
2544 IN VOID
*Context2 OPTIONAL
2548 Used to serialize load and store operations.
2550 All loads and stores that proceed calls to this function are guaranteed to be
2551 globally visible when this function returns.
2561 Saves the current CPU context that can be restored with a call to LongJump()
2564 Saves the current CPU context in the buffer specified by JumpBuffer and
2565 returns 0. The initial call to SetJump() must always return 0. Subsequent
2566 calls to LongJump() cause a non-zero value to be returned by SetJump().
2568 If JumpBuffer is NULL, then ASSERT().
2570 @param JumpBuffer A pointer to CPU context buffer.
2572 @retval 0 Indicates a return from SetJump().
2578 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
2582 Restores the CPU context that was saved with SetJump().
2584 Restores the CPU context from the buffer specified by JumpBuffer. This
2585 function never returns to the caller. Instead is resumes execution based on
2586 the state of JumpBuffer.
2588 If JumpBuffer is NULL, then ASSERT().
2589 If Value is 0, then ASSERT().
2591 @param JumpBuffer A pointer to CPU context buffer.
2592 @param Value The value to return when the SetJump() context is
2593 restored and must be non-zero.
2599 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
2604 Enables CPU interrupts.
2606 Enables CPU interrupts.
2616 Disables CPU interrupts.
2618 Disables CPU interrupts.
2628 Disables CPU interrupts and returns the interrupt state prior to the disable
2631 Disables CPU interrupts and returns the interrupt state prior to the disable
2634 @retval TRUE CPU interrupts were enabled on entry to this call.
2635 @retval FALSE CPU interrupts were disabled on entry to this call.
2640 SaveAndDisableInterrupts (
2645 Enables CPU interrupts for the smallest window required to capture any
2648 Enables CPU interrupts for the smallest window required to capture any
2654 EnableDisableInterrupts (
2659 Retrieves the current CPU interrupt state.
2661 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
2662 currently enabled. Otherwise returns FALSE.
2664 @retval TRUE CPU interrupts are enabled.
2665 @retval FALSE CPU interrupts are disabled.
2675 Set the current CPU interrupt state.
2677 Sets the current CPU interrupt state to the state specified by
2678 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
2679 InterruptState is FALSE, then interrupts are disabled. InterruptState is
2682 @param InterruptState TRUE if interrupts should enabled. FALSE if
2683 interrupts should be disabled.
2685 @return InterruptState
2691 IN BOOLEAN InterruptState
2695 Places the CPU in a sleep state until an interrupt is received.
2697 Places the CPU in a sleep state until an interrupt is received. If interrupts
2698 are disabled prior to calling this function, then the CPU will be placed in a
2699 sleep state indefinitely.
2709 Requests CPU to pause for a short period of time.
2711 Requests CPU to pause for a short period of time. Typically used in MP
2712 systems to prevent memory starvation while waiting for a spin lock.
2722 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2724 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2734 Transfers control to a function starting with a new stack.
2736 Transfers control to the function specified by EntryPoint using the new stack
2737 specified by NewStack and passing in the parameters specified by Context1 and
2738 Context2. Context1 and Context2 are optional and may be NULL. The function
2739 EntryPoint must never return.
2741 If EntryPoint is NULL, then ASSERT().
2742 If NewStack is NULL, then ASSERT().
2744 @param EntryPoint A pointer to function to call with the new stack.
2745 @param Context1 A pointer to the context to pass into the EntryPoint
2747 @param Context2 A pointer to the context to pass into the EntryPoint
2749 @param NewStack A pointer to the new stack to use for the EntryPoint
2756 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
2757 IN VOID
*Context1
, OPTIONAL
2758 IN VOID
*Context2
, OPTIONAL
2763 Generates a breakpoint on the CPU.
2765 Generates a breakpoint on the CPU. The breakpoint must be implemented such
2766 that code can resume normal execution after the breakpoint.
2776 Executes an infinite loop.
2778 Forces the CPU to execute an infinite loop. A debugger may be used to skip
2779 past the loop and the code that follows the loop must execute properly. This
2780 implies that the infinite loop must not cause the code that follow it to be
2791 // IA32 and X64 Specific Functions
2794 // Byte packed structure for 16-bit Real Mode EFLAGS
2798 UINT32 CF
:1; // Carry Flag
2799 UINT32 Reserved_0
:1; // Reserved
2800 UINT32 PF
:1; // Parity Flag
2801 UINT32 Reserved_1
:1; // Reserved
2802 UINT32 AF
:1; // Auxiliary Carry Flag
2803 UINT32 Reserved_2
:1; // Reserved
2804 UINT32 ZF
:1; // Zero Flag
2805 UINT32 SF
:1; // Sign Flag
2806 UINT32 TF
:1; // Trap Flag
2807 UINT32 IF
:1; // Interrupt Enable Flag
2808 UINT32 DF
:1; // Direction Flag
2809 UINT32 OF
:1; // Overflow Flag
2810 UINT32 IOPL
:2; // I/O Privilege Level
2811 UINT32 NT
:1; // Nested Task
2812 UINT32 Reserved_3
:1; // Reserved
2818 // Byte packed structure for EFLAGS/RFLAGS
2820 // 64-bits on X64. The upper 32-bits on X64 are reserved
2824 UINT32 CF
:1; // Carry Flag
2825 UINT32 Reserved_0
:1; // Reserved
2826 UINT32 PF
:1; // Parity Flag
2827 UINT32 Reserved_1
:1; // Reserved
2828 UINT32 AF
:1; // Auxiliary Carry Flag
2829 UINT32 Reserved_2
:1; // Reserved
2830 UINT32 ZF
:1; // Zero Flag
2831 UINT32 SF
:1; // Sign Flag
2832 UINT32 TF
:1; // Trap Flag
2833 UINT32 IF
:1; // Interrupt Enable Flag
2834 UINT32 DF
:1; // Direction Flag
2835 UINT32 OF
:1; // Overflow Flag
2836 UINT32 IOPL
:2; // I/O Privilege Level
2837 UINT32 NT
:1; // Nested Task
2838 UINT32 Reserved_3
:1; // Reserved
2839 UINT32 RF
:1; // Resume Flag
2840 UINT32 VM
:1; // Virtual 8086 Mode
2841 UINT32 AC
:1; // Alignment Check
2842 UINT32 VIF
:1; // Virtual Interrupt Flag
2843 UINT32 VIP
:1; // Virtual Interrupt Pending
2844 UINT32 ID
:1; // ID Flag
2845 UINT32 Reserved_4
:10; // Reserved
2851 // Byte packed structure for Control Register 0 (CR0)
2853 // 64-bits on X64. The upper 32-bits on X64 are reserved
2857 UINT32 PE
:1; // Protection Enable
2858 UINT32 MP
:1; // Monitor Coprocessor
2859 UINT32 EM
:1; // Emulation
2860 UINT32 TS
:1; // Task Switched
2861 UINT32 ET
:1; // Extension Type
2862 UINT32 NE
:1; // Numeric Error
2863 UINT32 Reserved_0
:10; // Reserved
2864 UINT32 WP
:1; // Write Protect
2865 UINT32 Reserved_1
:1; // Reserved
2866 UINT32 AM
:1; // Alignment Mask
2867 UINT32 Reserved_2
:10; // Reserved
2868 UINT32 NW
:1; // Mot Write-through
2869 UINT32 CD
:1; // Cache Disable
2870 UINT32 PG
:1; // Paging
2876 // Byte packed structure for Control Register 4 (CR4)
2878 // 64-bits on X64. The upper 32-bits on X64 are reserved
2882 UINT32 VME
:1; // Virtual-8086 Mode Extensions
2883 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
2884 UINT32 TSD
:1; // Time Stamp Disable
2885 UINT32 DE
:1; // Debugging Extensions
2886 UINT32 PSE
:1; // Page Size Extensions
2887 UINT32 PAE
:1; // Physical Address Extension
2888 UINT32 MCE
:1; // Machine Check Enable
2889 UINT32 PGE
:1; // Page Global Enable
2890 UINT32 PCE
:1; // Performance Monitoring Counter
2892 UINT32 OSFXSR
:1; // Operating System Support for
2893 // FXSAVE and FXRSTOR instructions
2894 UINT32 OSXMMEXCPT
:1; // Operating System Support for
2895 // Unmasked SIMD Floating Point
2897 UINT32 Reserved_0
:2; // Reserved
2898 UINT32 VMXE
:1; // VMX Enable
2899 UINT32 Reserved_1
:18; // Reseved
2905 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
2906 /// @bug How to make this structure byte-packed in a compiler independent way?
2913 #define IA32_IDT_GATE_TYPE_TASK 0x85
2914 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
2915 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
2916 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
2917 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
2920 // Byte packed structure for an Interrupt Gate Descriptor
2924 UINT32 OffsetLow
:16; // Offset bits 15..0
2925 UINT32 Selector
:16; // Selector
2926 UINT32 Reserved_0
:8; // Reserved
2927 UINT32 GateType
:8; // Gate Type. See #defines above
2928 UINT32 OffsetHigh
:16; // Offset bits 31..16
2931 } IA32_IDT_GATE_DESCRIPTOR
;
2934 // Byte packed structure for an FP/SSE/SSE2 context
2941 // Structures for the 16-bit real mode thunks
2994 IA32_EFLAGS32 EFLAGS
;
3004 } IA32_REGISTER_SET
;
3007 // Byte packed structure for an 16-bit real mode thunks
3010 IA32_REGISTER_SET
*RealModeState
;
3011 VOID
*RealModeBuffer
;
3012 UINT32 RealModeBufferSize
;
3013 UINT32 ThunkAttributes
;
3016 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
3017 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
3018 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3021 Retrieves CPUID information.
3023 Executes the CPUID instruction with EAX set to the value specified by Index.
3024 This function always returns Index.
3025 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3026 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3027 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3028 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3029 This function is only available on IA-32 and X64.
3031 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3033 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3034 instruction. This is an optional parameter that may be NULL.
3035 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3036 instruction. This is an optional parameter that may be NULL.
3037 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3038 instruction. This is an optional parameter that may be NULL.
3039 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3040 instruction. This is an optional parameter that may be NULL.
3049 OUT UINT32
*Eax
, OPTIONAL
3050 OUT UINT32
*Ebx
, OPTIONAL
3051 OUT UINT32
*Ecx
, OPTIONAL
3052 OUT UINT32
*Edx OPTIONAL
3056 Retrieves CPUID information using an extended leaf identifier.
3058 Executes the CPUID instruction with EAX set to the value specified by Index
3059 and ECX set to the value specified by SubIndex. This function always returns
3060 Index. This function is only available on IA-32 and x64.
3062 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3063 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3064 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3065 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3067 @param Index The 32-bit value to load into EAX prior to invoking the
3069 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3071 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3072 instruction. This is an optional parameter that may be
3074 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3075 instruction. This is an optional parameter that may be
3077 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3078 instruction. This is an optional parameter that may be
3080 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3081 instruction. This is an optional parameter that may be
3092 OUT UINT32
*Eax
, OPTIONAL
3093 OUT UINT32
*Ebx
, OPTIONAL
3094 OUT UINT32
*Ecx
, OPTIONAL
3095 OUT UINT32
*Edx OPTIONAL
3099 Returns the lower 32-bits of a Machine Specific Register(MSR).
3101 Reads and returns the lower 32-bits of the MSR specified by Index.
3102 No parameter checking is performed on Index, and some Index values may cause
3103 CPU exceptions. The caller must either guarantee that Index is valid, or the
3104 caller must set up exception handlers to catch the exceptions. This function
3105 is only available on IA-32 and X64.
3107 @param Index The 32-bit MSR index to read.
3109 @return The lower 32 bits of the MSR identified by Index.
3119 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3121 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3122 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3123 the MSR is returned. No parameter checking is performed on Index or Value,
3124 and some of these may cause CPU exceptions. The caller must either guarantee
3125 that Index and Value are valid, or the caller must establish proper exception
3126 handlers. This function is only available on IA-32 and X64.
3128 @param Index The 32-bit MSR index to write.
3129 @param Value The 32-bit value to write to the MSR.
3142 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3143 writes the result back to the 64-bit MSR.
3145 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3146 between the lower 32-bits of the read result and the value specified by
3147 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3148 32-bits of the value written to the MSR is returned. No parameter checking is
3149 performed on Index or OrData, and some of these may cause CPU exceptions. The
3150 caller must either guarantee that Index and OrData are valid, or the caller
3151 must establish proper exception handlers. This function is only available on
3154 @param Index The 32-bit MSR index to write.
3155 @param OrData The value to OR with the read value from the MSR.
3157 @return The lower 32-bit value written to the MSR.
3168 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3169 the result back to the 64-bit MSR.
3171 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3172 lower 32-bits of the read result and the value specified by AndData, and
3173 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3174 the value written to the MSR is returned. No parameter checking is performed
3175 on Index or AndData, and some of these may cause CPU exceptions. The caller
3176 must either guarantee that Index and AndData are valid, or the caller must
3177 establish proper exception handlers. This function is only available on IA-32
3180 @param Index The 32-bit MSR index to write.
3181 @param AndData The value to AND with the read value from the MSR.
3183 @return The lower 32-bit value written to the MSR.
3194 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3195 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3197 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3198 lower 32-bits of the read result and the value specified by AndData
3199 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3200 result of the AND operation and the value specified by OrData, and writes the
3201 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3202 written to the MSR is returned. No parameter checking is performed on Index,
3203 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3204 must either guarantee that Index, AndData, and OrData are valid, or the
3205 caller must establish proper exception handlers. This function is only
3206 available on IA-32 and X64.
3208 @param Index The 32-bit MSR index to write.
3209 @param AndData The value to AND with the read value from the MSR.
3210 @param OrData The value to OR with the result of the AND operation.
3212 @return The lower 32-bit value written to the MSR.
3224 Reads a bit field of an MSR.
3226 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3227 specified by the StartBit and the EndBit. The value of the bit field is
3228 returned. The caller must either guarantee that Index is valid, or the caller
3229 must set up exception handlers to catch the exceptions. This function is only
3230 available on IA-32 and X64.
3232 If StartBit is greater than 31, then ASSERT().
3233 If EndBit is greater than 31, then ASSERT().
3234 If EndBit is less than StartBit, then ASSERT().
3236 @param Index The 32-bit MSR index to read.
3237 @param StartBit The ordinal of the least significant bit in the bit field.
3239 @param EndBit The ordinal of the most significant bit in the bit field.
3242 @return The bit field read from the MSR.
3247 AsmMsrBitFieldRead32 (
3254 Writes a bit field to an MSR.
3256 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3257 field is specified by the StartBit and the EndBit. All other bits in the
3258 destination MSR are preserved. The lower 32-bits of the MSR written is
3259 returned. Extra left bits in Value are stripped. The caller must either
3260 guarantee that Index and the data written is valid, or the caller must set up
3261 exception handlers to catch the exceptions. This function is only available
3264 If StartBit is greater than 31, then ASSERT().
3265 If EndBit is greater than 31, then ASSERT().
3266 If EndBit is less than StartBit, then ASSERT().
3268 @param Index The 32-bit MSR index to write.
3269 @param StartBit The ordinal of the least significant bit in the bit field.
3271 @param EndBit The ordinal of the most significant bit in the bit field.
3273 @param Value New value of the bit field.
3275 @return The lower 32-bit of the value written to the MSR.
3280 AsmMsrBitFieldWrite32 (
3288 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3289 result back to the bit field in the 64-bit MSR.
3291 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3292 between the read result and the value specified by OrData, and writes the
3293 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3294 written to the MSR are returned. Extra left bits in OrData are stripped. The
3295 caller must either guarantee that Index and the data written is valid, or
3296 the caller must set up exception handlers to catch the exceptions. This
3297 function is only available on IA-32 and X64.
3299 If StartBit is greater than 31, then ASSERT().
3300 If EndBit is greater than 31, then ASSERT().
3301 If EndBit is less than StartBit, then ASSERT().
3303 @param Index The 32-bit MSR index to write.
3304 @param StartBit The ordinal of the least significant bit in the bit field.
3306 @param EndBit The ordinal of the most significant bit in the bit field.
3308 @param OrData The value to OR with the read value from the MSR.
3310 @return The lower 32-bit of the value written to the MSR.
3315 AsmMsrBitFieldOr32 (
3323 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3324 result back to the bit field in the 64-bit MSR.
3326 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3327 read result and the value specified by AndData, and writes the result to the
3328 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3329 MSR are returned. Extra left bits in AndData are stripped. The caller must
3330 either guarantee that Index and the data written is valid, or the caller must
3331 set up exception handlers to catch the exceptions. This function is only
3332 available on IA-32 and X64.
3334 If StartBit is greater than 31, then ASSERT().
3335 If EndBit is greater than 31, then ASSERT().
3336 If EndBit is less than StartBit, then ASSERT().
3338 @param Index The 32-bit MSR index to write.
3339 @param StartBit The ordinal of the least significant bit in the bit field.
3341 @param EndBit The ordinal of the most significant bit in the bit field.
3343 @param AndData The value to AND with the read value from the MSR.
3345 @return The lower 32-bit of the value written to the MSR.
3350 AsmMsrBitFieldAnd32 (
3358 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3359 bitwise inclusive OR, and writes the result back to the bit field in the
3362 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3363 bitwise inclusive OR between the read result and the value specified by
3364 AndData, and writes the result to the 64-bit MSR specified by Index. The
3365 lower 32-bits of the value written to the MSR are returned. Extra left bits
3366 in both AndData and OrData are stripped. The caller must either guarantee
3367 that Index and the data written is valid, or the caller must set up exception
3368 handlers to catch the exceptions. This function is only available on IA-32
3371 If StartBit is greater than 31, then ASSERT().
3372 If EndBit is greater than 31, then ASSERT().
3373 If EndBit is less than StartBit, then ASSERT().
3375 @param Index The 32-bit MSR index to write.
3376 @param StartBit The ordinal of the least significant bit in the bit field.
3378 @param EndBit The ordinal of the most significant bit in the bit field.
3380 @param AndData The value to AND with the read value from the MSR.
3381 @param OrData The value to OR with the result of the AND operation.
3383 @return The lower 32-bit of the value written to the MSR.
3388 AsmMsrBitFieldAndThenOr32 (
3397 Returns a 64-bit Machine Specific Register(MSR).
3399 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3400 performed on Index, and some Index values may cause CPU exceptions. The
3401 caller must either guarantee that Index is valid, or the caller must set up
3402 exception handlers to catch the exceptions. This function is only available
3405 @param Index The 32-bit MSR index to read.
3407 @return The value of the MSR identified by Index.
3417 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3420 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3421 64-bit value written to the MSR is returned. No parameter checking is
3422 performed on Index or Value, and some of these may cause CPU exceptions. The
3423 caller must either guarantee that Index and Value are valid, or the caller
3424 must establish proper exception handlers. This function is only available on
3427 @param Index The 32-bit MSR index to write.
3428 @param Value The 64-bit value to write to the MSR.
3441 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3442 back to the 64-bit MSR.
3444 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3445 between the read result and the value specified by OrData, and writes the
3446 result to the 64-bit MSR specified by Index. The value written to the MSR is
3447 returned. No parameter checking is performed on Index or OrData, and some of
3448 these may cause CPU exceptions. The caller must either guarantee that Index
3449 and OrData are valid, or the caller must establish proper exception handlers.
3450 This function is only available on IA-32 and X64.
3452 @param Index The 32-bit MSR index to write.
3453 @param OrData The value to OR with the read value from the MSR.
3455 @return The value written back to the MSR.
3466 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3469 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3470 read result and the value specified by OrData, and writes the result to the
3471 64-bit MSR specified by Index. The value written to the MSR is returned. No
3472 parameter checking is performed on Index or OrData, and some of these may
3473 cause CPU exceptions. The caller must either guarantee that Index and OrData
3474 are valid, or the caller must establish proper exception handlers. This
3475 function is only available on IA-32 and X64.
3477 @param Index The 32-bit MSR index to write.
3478 @param AndData The value to AND with the read value from the MSR.
3480 @return The value written back to the MSR.
3491 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3492 OR, and writes the result back to the 64-bit MSR.
3494 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3495 result and the value specified by AndData, performs a bitwise inclusive OR
3496 between the result of the AND operation and the value specified by OrData,
3497 and writes the result to the 64-bit MSR specified by Index. The value written
3498 to the MSR is returned. No parameter checking is performed on Index, AndData,
3499 or OrData, and some of these may cause CPU exceptions. The caller must either
3500 guarantee that Index, AndData, and OrData are valid, or the caller must
3501 establish proper exception handlers. This function is only available on IA-32
3504 @param Index The 32-bit MSR index to write.
3505 @param AndData The value to AND with the read value from the MSR.
3506 @param OrData The value to OR with the result of the AND operation.
3508 @return The value written back to the MSR.
3520 Reads a bit field of an MSR.
3522 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3523 StartBit and the EndBit. The value of the bit field is returned. The caller
3524 must either guarantee that Index is valid, or the caller must set up
3525 exception handlers to catch the exceptions. This function is only available
3528 If StartBit is greater than 63, then ASSERT().
3529 If EndBit is greater than 63, then ASSERT().
3530 If EndBit is less than StartBit, then ASSERT().
3532 @param Index The 32-bit MSR index to read.
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.
3538 @return The value read from the MSR.
3543 AsmMsrBitFieldRead64 (
3550 Writes a bit field to an MSR.
3552 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3553 the StartBit and the EndBit. All other bits in the destination MSR are
3554 preserved. The MSR written is returned. Extra left bits in Value are
3555 stripped. The caller must either guarantee that Index and the data written is
3556 valid, or the caller must set up exception handlers to catch the exceptions.
3557 This function is only available on IA-32 and X64.
3559 If StartBit is greater than 63, then ASSERT().
3560 If EndBit is greater than 63, then ASSERT().
3561 If EndBit is less than StartBit, then ASSERT().
3563 @param Index The 32-bit MSR index to write.
3564 @param StartBit The ordinal of the least significant bit in the bit field.
3566 @param EndBit The ordinal of the most significant bit in the bit field.
3568 @param Value New value of the bit field.
3570 @return The value written back to the MSR.
3575 AsmMsrBitFieldWrite64 (
3583 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3584 writes the result back to the bit field in the 64-bit MSR.
3586 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3587 between the read result and the value specified by OrData, and writes the
3588 result to the 64-bit MSR specified by Index. The value written to the MSR is
3589 returned. Extra left bits in OrData are stripped. The caller must either
3590 guarantee that Index and the data written is valid, or the caller must set up
3591 exception handlers to catch the exceptions. This function is only available
3594 If StartBit is greater than 63, then ASSERT().
3595 If EndBit is greater than 63, then ASSERT().
3596 If EndBit is less than StartBit, then ASSERT().
3598 @param Index The 32-bit MSR index to write.
3599 @param StartBit The ordinal of the least significant bit in the bit field.
3601 @param EndBit The ordinal of the most significant bit in the bit field.
3603 @param OrData The value to OR with the read value from the bit field.
3605 @return The value written back to the MSR.
3610 AsmMsrBitFieldOr64 (
3618 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3619 result back to the bit field in the 64-bit MSR.
3621 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3622 read result and the value specified by AndData, and writes the result to the
3623 64-bit MSR specified by Index. The value written to the MSR is returned.
3624 Extra left bits in AndData are stripped. The caller must either guarantee
3625 that Index and the data written is valid, or the caller must set up exception
3626 handlers to catch the exceptions. This function is only available on IA-32
3629 If StartBit is greater than 63, then ASSERT().
3630 If EndBit is greater than 63, then ASSERT().
3631 If EndBit is less than StartBit, then ASSERT().
3633 @param Index The 32-bit MSR index to write.
3634 @param StartBit The ordinal of the least significant bit in the bit field.
3636 @param EndBit The ordinal of the most significant bit in the bit field.
3638 @param AndData The value to AND with the read value from the bit field.
3640 @return The value written back to the MSR.
3645 AsmMsrBitFieldAnd64 (
3653 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3654 bitwise inclusive OR, and writes the result back to the bit field in the
3657 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3658 a bitwise inclusive OR between the read result and the value specified by
3659 AndData, and writes the result to the 64-bit MSR specified by Index. The
3660 value written to the MSR is returned. Extra left bits in both AndData and
3661 OrData are stripped. The caller must either guarantee that Index and the data
3662 written is valid, or the caller must set up exception handlers to catch the
3663 exceptions. This function is only available on IA-32 and X64.
3665 If StartBit is greater than 63, then ASSERT().
3666 If EndBit is greater than 63, then ASSERT().
3667 If EndBit is less than StartBit, then ASSERT().
3669 @param Index The 32-bit MSR index to write.
3670 @param StartBit The ordinal of the least significant bit in the bit field.
3672 @param EndBit The ordinal of the most significant bit in the bit field.
3674 @param AndData The value to AND with the read value from the bit field.
3675 @param OrData The value to OR with the result of the AND operation.
3677 @return The value written back to the MSR.
3682 AsmMsrBitFieldAndThenOr64 (
3691 Reads the current value of the EFLAGS register.
3693 Reads and returns the current value of the EFLAGS register. This function is
3694 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3695 64-bit value on X64.
3697 @return EFLAGS on IA-32 or RFLAGS on X64.
3707 Reads the current value of the Control Register 0 (CR0).
3709 Reads and returns the current value of CR0. This function is only available
3710 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3713 @return The value of the Control Register 0 (CR0).
3723 Reads the current value of the Control Register 2 (CR2).
3725 Reads and returns the current value of CR2. This function is only available
3726 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3729 @return The value of the Control Register 2 (CR2).
3739 Reads the current value of the Control Register 3 (CR3).
3741 Reads and returns the current value of CR3. This function is only available
3742 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3745 @return The value of the Control Register 3 (CR3).
3755 Reads the current value of the Control Register 4 (CR4).
3757 Reads and returns the current value of CR4. This function is only available
3758 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3761 @return The value of the Control Register 4 (CR4).
3771 Writes a value to Control Register 0 (CR0).
3773 Writes and returns a new value to CR0. This function is only available on
3774 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3776 @param Cr0 The value to write to CR0.
3778 @return The value written to CR0.
3788 Writes a value to Control Register 2 (CR2).
3790 Writes and returns a new value to CR2. This function is only available on
3791 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3793 @param Cr2 The value to write to CR2.
3795 @return The value written to CR2.
3805 Writes a value to Control Register 3 (CR3).
3807 Writes and returns a new value to CR3. This function is only available on
3808 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3810 @param Cr3 The value to write to CR3.
3812 @return The value written to CR3.
3822 Writes a value to Control Register 4 (CR4).
3824 Writes and returns a new value to CR4. This function is only available on
3825 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3827 @param Cr4 The value to write to CR4.
3829 @return The value written to CR4.
3839 Reads the current value of Debug Register 0 (DR0).
3841 Reads and returns the current value of DR0. This function is only available
3842 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3845 @return The value of Debug Register 0 (DR0).
3855 Reads the current value of Debug Register 1 (DR1).
3857 Reads and returns the current value of DR1. This function is only available
3858 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3861 @return The value of Debug Register 1 (DR1).
3871 Reads the current value of Debug Register 2 (DR2).
3873 Reads and returns the current value of DR2. This function is only available
3874 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3877 @return The value of Debug Register 2 (DR2).
3887 Reads the current value of Debug Register 3 (DR3).
3889 Reads and returns the current value of DR3. This function is only available
3890 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3893 @return The value of Debug Register 3 (DR3).
3903 Reads the current value of Debug Register 4 (DR4).
3905 Reads and returns the current value of DR4. This function is only available
3906 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3909 @return The value of Debug Register 4 (DR4).
3919 Reads the current value of Debug Register 5 (DR5).
3921 Reads and returns the current value of DR5. This function is only available
3922 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3925 @return The value of Debug Register 5 (DR5).
3935 Reads the current value of Debug Register 6 (DR6).
3937 Reads and returns the current value of DR6. This function is only available
3938 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3941 @return The value of Debug Register 6 (DR6).
3951 Reads the current value of Debug Register 7 (DR7).
3953 Reads and returns the current value of DR7. This function is only available
3954 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3957 @return The value of Debug Register 7 (DR7).
3967 Writes a value to Debug Register 0 (DR0).
3969 Writes and returns a new value to DR0. This function is only available on
3970 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3972 @param Dr0 The value to write to Dr0.
3974 @return The value written to Debug Register 0 (DR0).
3984 Writes a value to Debug Register 1 (DR1).
3986 Writes and returns a new value to DR1. This function is only available on
3987 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3989 @param Dr1 The value to write to Dr1.
3991 @return The value written to Debug Register 1 (DR1).
4001 Writes a value to Debug Register 2 (DR2).
4003 Writes and returns a new value to DR2. This function is only available on
4004 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4006 @param Dr2 The value to write to Dr2.
4008 @return The value written to Debug Register 2 (DR2).
4018 Writes a value to Debug Register 3 (DR3).
4020 Writes and returns a new value to DR3. This function is only available on
4021 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4023 @param Dr3 The value to write to Dr3.
4025 @return The value written to Debug Register 3 (DR3).
4035 Writes a value to Debug Register 4 (DR4).
4037 Writes and returns a new value to DR4. This function is only available on
4038 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4040 @param Dr4 The value to write to Dr4.
4042 @return The value written to Debug Register 4 (DR4).
4052 Writes a value to Debug Register 5 (DR5).
4054 Writes and returns a new value to DR5. This function is only available on
4055 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4057 @param Dr5 The value to write to Dr5.
4059 @return The value written to Debug Register 5 (DR5).
4069 Writes a value to Debug Register 6 (DR6).
4071 Writes and returns a new value to DR6. This function is only available on
4072 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4074 @param Dr6 The value to write to Dr6.
4076 @return The value written to Debug Register 6 (DR6).
4086 Writes a value to Debug Register 7 (DR7).
4088 Writes and returns a new value to DR7. This function is only available on
4089 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4091 @param Dr7 The value to write to Dr7.
4093 @return The value written to Debug Register 7 (DR7).
4103 Reads the current value of Code Segment Register (CS).
4105 Reads and returns the current value of CS. This function is only available on
4108 @return The current value of CS.
4118 Reads the current value of Data Segment Register (DS).
4120 Reads and returns the current value of DS. This function is only available on
4123 @return The current value of DS.
4133 Reads the current value of Extra Segment Register (ES).
4135 Reads and returns the current value of ES. This function is only available on
4138 @return The current value of ES.
4148 Reads the current value of FS Data Segment Register (FS).
4150 Reads and returns the current value of FS. This function is only available on
4153 @return The current value of FS.
4163 Reads the current value of GS Data Segment Register (GS).
4165 Reads and returns the current value of GS. This function is only available on
4168 @return The current value of GS.
4178 Reads the current value of Stack Segment Register (SS).
4180 Reads and returns the current value of SS. This function is only available on
4183 @return The current value of SS.
4193 Reads the current value of Task Register (TR).
4195 Reads and returns the current value of TR. This function is only available on
4198 @return The current value of TR.
4208 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4210 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4211 function is only available on IA-32 and X64.
4213 If Gdtr is NULL, then ASSERT().
4215 @param Gdtr Pointer to a GDTR descriptor.
4221 OUT IA32_DESCRIPTOR
*Gdtr
4225 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4227 Writes and the current GDTR descriptor specified by Gdtr. This function is
4228 only available on IA-32 and X64.
4230 If Gdtr is NULL, then ASSERT().
4232 @param Gdtr Pointer to a GDTR descriptor.
4238 IN CONST IA32_DESCRIPTOR
*Gdtr
4242 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4244 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4245 function is only available on IA-32 and X64.
4247 If Idtr is NULL, then ASSERT().
4249 @param Idtr Pointer to a IDTR descriptor.
4255 OUT IA32_DESCRIPTOR
*Idtr
4259 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4261 Writes the current IDTR descriptor and returns it in Idtr. This function is
4262 only available on IA-32 and X64.
4264 If Idtr is NULL, then ASSERT().
4266 @param Idtr Pointer to a IDTR descriptor.
4272 IN CONST IA32_DESCRIPTOR
*Idtr
4276 Reads the current Local Descriptor Table Register(LDTR) selector.
4278 Reads and returns the current 16-bit LDTR descriptor value. This function is
4279 only available on IA-32 and X64.
4281 @return The current selector of LDT.
4291 Writes the current Local Descriptor Table Register (GDTR) selector.
4293 Writes and the current LDTR descriptor specified by Ldtr. This function is
4294 only available on IA-32 and X64.
4296 @param Ldtr 16-bit LDTR selector value.
4306 Save the current floating point/SSE/SSE2 context to a buffer.
4308 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4309 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4310 available on IA-32 and X64.
4312 If Buffer is NULL, then ASSERT().
4313 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4315 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4321 OUT IA32_FX_BUFFER
*Buffer
4325 Restores the current floating point/SSE/SSE2 context from a buffer.
4327 Restores the current floating point/SSE/SSE2 state from the buffer specified
4328 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4329 only available on IA-32 and X64.
4331 If Buffer is NULL, then ASSERT().
4332 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4333 If Buffer was not saved with AsmFxSave(), then ASSERT().
4335 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4341 IN CONST IA32_FX_BUFFER
*Buffer
4345 Reads the current value of 64-bit MMX Register #0 (MM0).
4347 Reads and returns the current value of MM0. This function is only available
4350 @return The current value of MM0.
4360 Reads the current value of 64-bit MMX Register #1 (MM1).
4362 Reads and returns the current value of MM1. This function is only available
4365 @return The current value of MM1.
4375 Reads the current value of 64-bit MMX Register #2 (MM2).
4377 Reads and returns the current value of MM2. This function is only available
4380 @return The current value of MM2.
4390 Reads the current value of 64-bit MMX Register #3 (MM3).
4392 Reads and returns the current value of MM3. This function is only available
4395 @return The current value of MM3.
4405 Reads the current value of 64-bit MMX Register #4 (MM4).
4407 Reads and returns the current value of MM4. This function is only available
4410 @return The current value of MM4.
4420 Reads the current value of 64-bit MMX Register #5 (MM5).
4422 Reads and returns the current value of MM5. This function is only available
4425 @return The current value of MM5.
4435 Reads the current value of 64-bit MMX Register #6 (MM6).
4437 Reads and returns the current value of MM6. This function is only available
4440 @return The current value of MM6.
4450 Reads the current value of 64-bit MMX Register #7 (MM7).
4452 Reads and returns the current value of MM7. This function is only available
4455 @return The current value of MM7.
4465 Writes the current value of 64-bit MMX Register #0 (MM0).
4467 Writes the current value of MM0. This function is only available on IA32 and
4470 @param Value The 64-bit value to write to MM0.
4480 Writes the current value of 64-bit MMX Register #1 (MM1).
4482 Writes the current value of MM1. This function is only available on IA32 and
4485 @param Value The 64-bit value to write to MM1.
4495 Writes the current value of 64-bit MMX Register #2 (MM2).
4497 Writes the current value of MM2. This function is only available on IA32 and
4500 @param Value The 64-bit value to write to MM2.
4510 Writes the current value of 64-bit MMX Register #3 (MM3).
4512 Writes the current value of MM3. This function is only available on IA32 and
4515 @param Value The 64-bit value to write to MM3.
4525 Writes the current value of 64-bit MMX Register #4 (MM4).
4527 Writes the current value of MM4. This function is only available on IA32 and
4530 @param Value The 64-bit value to write to MM4.
4540 Writes the current value of 64-bit MMX Register #5 (MM5).
4542 Writes the current value of MM5. This function is only available on IA32 and
4545 @param Value The 64-bit value to write to MM5.
4555 Writes the current value of 64-bit MMX Register #6 (MM6).
4557 Writes the current value of MM6. This function is only available on IA32 and
4560 @param Value The 64-bit value to write to MM6.
4570 Writes the current value of 64-bit MMX Register #7 (MM7).
4572 Writes the current value of MM7. This function is only available on IA32 and
4575 @param Value The 64-bit value to write to MM7.
4585 Reads the current value of Time Stamp Counter (TSC).
4587 Reads and returns the current value of TSC. This function is only available
4590 @return The current value of TSC
4600 Reads the current value of a Performance Counter (PMC).
4602 Reads and returns the current value of performance counter specified by
4603 Index. This function is only available on IA-32 and X64.
4605 @param Index The 32-bit Performance Counter index to read.
4607 @return The value of the PMC specified by Index.
4617 Sets up a monitor buffer that is used by AsmMwait().
4619 Executes a MONITOR instruction with the register state specified by Eax, Ecx
4620 and Edx. Returns Eax. This function is only available on IA-32 and X64.
4622 @param Eax The value to load into EAX or RAX before executing the MONITOR
4624 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4626 @param Edx The value to load into EDX or RDX before executing the MONITOR
4641 Executes an MWAIT instruction.
4643 Executes an MWAIT instruction with the register state specified by Eax and
4644 Ecx. Returns Eax. This function is only available on IA-32 and X64.
4646 @param Eax The value to load into EAX or RAX before executing the MONITOR
4648 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4662 Executes a WBINVD instruction.
4664 Executes a WBINVD instruction. This function is only available on IA-32 and
4675 Executes a INVD instruction.
4677 Executes a INVD instruction. This function is only available on IA-32 and
4688 Flushes a cache line from all the instruction and data caches within the
4689 coherency domain of the CPU.
4691 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
4692 This function is only available on IA-32 and X64.
4694 @param LinearAddress The address of the cache line to flush. If the CPU is
4695 in a physical addressing mode, then LinearAddress is a
4696 physical address. If the CPU is in a virtual
4697 addressing mode, then LinearAddress is a virtual
4700 @return LinearAddress
4705 IN VOID
*LinearAddress
4709 Enables the 32-bit paging mode on the CPU.
4711 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4712 must be properly initialized prior to calling this service. This function
4713 assumes the current execution mode is 32-bit protected mode. This function is
4714 only available on IA-32. After the 32-bit paging mode is enabled, control is
4715 transferred to the function specified by EntryPoint using the new stack
4716 specified by NewStack and passing in the parameters specified by Context1 and
4717 Context2. Context1 and Context2 are optional and may be NULL. The function
4718 EntryPoint must never return.
4720 If the current execution mode is not 32-bit protected mode, then ASSERT().
4721 If EntryPoint is NULL, then ASSERT().
4722 If NewStack is NULL, then ASSERT().
4724 There are a number of constraints that must be followed before calling this
4726 1) Interrupts must be disabled.
4727 2) The caller must be in 32-bit protected mode with flat descriptors. This
4728 means all descriptors must have a base of 0 and a limit of 4GB.
4729 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
4731 4) CR3 must point to valid page tables that will be used once the transition
4732 is complete, and those page tables must guarantee that the pages for this
4733 function and the stack are identity mapped.
4735 @param EntryPoint A pointer to function to call with the new stack after
4737 @param Context1 A pointer to the context to pass into the EntryPoint
4738 function as the first parameter after paging is enabled.
4739 @param Context2 A pointer to the context to pass into the EntryPoint
4740 function as the second parameter after paging is enabled.
4741 @param NewStack A pointer to the new stack to use for the EntryPoint
4742 function after paging is enabled.
4748 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4749 IN VOID
*Context1
, OPTIONAL
4750 IN VOID
*Context2
, OPTIONAL
4755 Disables the 32-bit paging mode on the CPU.
4757 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
4758 mode. This function assumes the current execution mode is 32-paged protected
4759 mode. This function is only available on IA-32. After the 32-bit paging mode
4760 is disabled, control is transferred to the function specified by EntryPoint
4761 using the new stack specified by NewStack and passing in the parameters
4762 specified by Context1 and Context2. Context1 and Context2 are optional and
4763 may be NULL. The function EntryPoint must never return.
4765 If the current execution mode is not 32-bit paged mode, then ASSERT().
4766 If EntryPoint is NULL, then ASSERT().
4767 If NewStack is NULL, then ASSERT().
4769 There are a number of constraints that must be followed before calling this
4771 1) Interrupts must be disabled.
4772 2) The caller must be in 32-bit paged mode.
4773 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
4774 4) CR3 must point to valid page tables that guarantee that the pages for
4775 this function and the stack are identity mapped.
4777 @param EntryPoint A pointer to function to call with the new stack after
4779 @param Context1 A pointer to the context to pass into the EntryPoint
4780 function as the first parameter after paging is disabled.
4781 @param Context2 A pointer to the context to pass into the EntryPoint
4782 function as the second parameter after paging is
4784 @param NewStack A pointer to the new stack to use for the EntryPoint
4785 function after paging is disabled.
4790 AsmDisablePaging32 (
4791 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4792 IN VOID
*Context1
, OPTIONAL
4793 IN VOID
*Context2
, OPTIONAL
4798 Enables the 64-bit paging mode on the CPU.
4800 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4801 must be properly initialized prior to calling this service. This function
4802 assumes the current execution mode is 32-bit protected mode with flat
4803 descriptors. This function is only available on IA-32. After the 64-bit
4804 paging mode is enabled, control is transferred to the function specified by
4805 EntryPoint using the new stack specified by NewStack and passing in the
4806 parameters specified by Context1 and Context2. Context1 and Context2 are
4807 optional and may be 0. The function EntryPoint must never return.
4809 If the current execution mode is not 32-bit protected mode with flat
4810 descriptors, then ASSERT().
4811 If EntryPoint is 0, then ASSERT().
4812 If NewStack is 0, then ASSERT().
4814 @param Cs The 16-bit selector to load in the CS before EntryPoint
4815 is called. The descriptor in the GDT that this selector
4816 references must be setup for long mode.
4817 @param EntryPoint The 64-bit virtual address of the function to call with
4818 the new stack after paging is enabled.
4819 @param Context1 The 64-bit virtual address of the context to pass into
4820 the EntryPoint function as the first parameter after
4822 @param Context2 The 64-bit virtual address of the context to pass into
4823 the EntryPoint function as the second parameter after
4825 @param NewStack The 64-bit virtual address of the new stack to use for
4826 the EntryPoint function after paging is enabled.
4832 IN UINT16 CodeSelector
,
4833 IN UINT64 EntryPoint
,
4834 IN UINT64 Context1
, OPTIONAL
4835 IN UINT64 Context2
, OPTIONAL
4840 Disables the 64-bit paging mode on the CPU.
4842 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
4843 mode. This function assumes the current execution mode is 64-paging mode.
4844 This function is only available on X64. After the 64-bit paging mode is
4845 disabled, control is transferred to the function specified by EntryPoint
4846 using the new stack specified by NewStack and passing in the parameters
4847 specified by Context1 and Context2. Context1 and Context2 are optional and
4848 may be 0. The function EntryPoint must never return.
4850 If the current execution mode is not 64-bit paged mode, then ASSERT().
4851 If EntryPoint is 0, then ASSERT().
4852 If NewStack is 0, then ASSERT().
4854 @param Cs The 16-bit selector to load in the CS before EntryPoint
4855 is called. The descriptor in the GDT that this selector
4856 references must be setup for 32-bit protected mode.
4857 @param EntryPoint The 64-bit virtual address of the function to call with
4858 the new stack after paging is disabled.
4859 @param Context1 The 64-bit virtual address of the context to pass into
4860 the EntryPoint function as the first parameter after
4862 @param Context2 The 64-bit virtual address of the context to pass into
4863 the EntryPoint function as the second parameter after
4865 @param NewStack The 64-bit virtual address of the new stack to use for
4866 the EntryPoint function after paging is disabled.
4871 AsmDisablePaging64 (
4872 IN UINT16 CodeSelector
,
4873 IN UINT32 EntryPoint
,
4874 IN UINT32 Context1
, OPTIONAL
4875 IN UINT32 Context2
, OPTIONAL
4880 // 16-bit thunking services
4884 Retrieves the properties for 16-bit thunk functions.
4886 Computes the size of the buffer and stack below 1MB required to use the
4887 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
4888 buffer size is returned in RealModeBufferSize, and the stack size is returned
4889 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
4890 then the actual minimum stack size is ExtraStackSize plus the maximum number
4891 of bytes that need to be passed to the 16-bit real mode code.
4893 If RealModeBufferSize is NULL, then ASSERT().
4894 If ExtraStackSize is NULL, then ASSERT().
4896 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
4897 required to use the 16-bit thunk functions.
4898 @param ExtraStackSize A pointer to the extra size of stack below 1MB
4899 that the 16-bit thunk functions require for
4900 temporary storage in the transition to and from
4906 AsmGetThunk16Properties (
4907 OUT UINT32
*RealModeBufferSize
,
4908 OUT UINT32
*ExtraStackSize
4912 Prepares all structures a code required to use AsmThunk16().
4914 Prepares all structures and code required to use AsmThunk16().
4916 If ThunkContext is NULL, then ASSERT().
4918 @param ThunkContext A pointer to the context structure that describes the
4919 16-bit real mode code to call.
4925 OUT THUNK_CONTEXT
*ThunkContext
4929 Transfers control to a 16-bit real mode entry point and returns the results.
4931 Transfers control to a 16-bit real mode entry point and returns the results.
4932 AsmPrepareThunk16() must be called with ThunkContext before this function is
4935 If ThunkContext is NULL, then ASSERT().
4936 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
4938 @param ThunkContext A pointer to the context structure that describes the
4939 16-bit real mode code to call.
4945 IN OUT THUNK_CONTEXT
*ThunkContext
4949 Prepares all structures and code for a 16-bit real mode thunk, transfers
4950 control to a 16-bit real mode entry point, and returns the results.
4952 Prepares all structures and code for a 16-bit real mode thunk, transfers
4953 control to a 16-bit real mode entry point, and returns the results. If the
4954 caller only need to perform a single 16-bit real mode thunk, then this
4955 service should be used. If the caller intends to make more than one 16-bit
4956 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
4957 once and AsmThunk16() can be called for each 16-bit real mode thunk.
4959 If ThunkContext is NULL, then ASSERT().
4961 @param ThunkContext A pointer to the context structure that describes the
4962 16-bit real mode code to call.
4967 AsmPrepareAndThunk16 (
4968 IN OUT THUNK_CONTEXT
*ThunkContext