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 Performs an atomic compare exchange operation on the 32-bit unsigned integer
2478 specified by Value. If Value is equal to CompareValue, then Value is set to
2479 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
2480 then Value is returned. The compare exchange operation must be performed using
2483 If Value is NULL, then ASSERT().
2485 @param Value A pointer to the 32-bit value for the compare exchange
2487 @param CompareValue 32-bit value used in compare operation.
2488 @param ExchangeValue 32-bit value used in exchange operation.
2490 @return The original *Value before exchange.
2495 InterlockedCompareExchange32 (
2496 IN OUT UINT32
*Value
,
2497 IN UINT32 CompareValue
,
2498 IN UINT32 ExchangeValue
2502 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
2504 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
2505 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
2506 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
2507 The compare exchange operation must be performed using MP safe mechanisms.
2509 If Value is NULL, then ASSERT().
2511 @param Value A pointer to the 64-bit value for the compare exchange
2513 @param CompareValue 64-bit value used in compare operation.
2514 @param ExchangeValue 64-bit value used in exchange operation.
2516 @return The original *Value before exchange.
2521 InterlockedCompareExchange64 (
2522 IN OUT UINT64
*Value
,
2523 IN UINT64 CompareValue
,
2524 IN UINT64 ExchangeValue
2528 Performs an atomic compare exchange operation on a pointer value.
2530 Performs an atomic compare exchange operation on the pointer value specified
2531 by Value. If Value is equal to CompareValue, then Value is set to
2532 ExchangeValue and CompareValue is returned. If Value is not equal to
2533 CompareValue, then Value is returned. The compare exchange operation must be
2534 performed using MP safe mechanisms.
2536 If Value is NULL, then ASSERT().
2538 @param Value A pointer to the pointer value for the compare exchange
2540 @param CompareValue Pointer value used in compare operation.
2541 @param ExchangeValue Pointer value used in exchange operation.
2546 InterlockedCompareExchangePointer (
2547 IN OUT VOID
**Value
,
2548 IN VOID
*CompareValue
,
2549 IN VOID
*ExchangeValue
2553 // Base Library CPU Functions
2557 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
2558 IN VOID
*Context1
, OPTIONAL
2559 IN VOID
*Context2 OPTIONAL
2563 Used to serialize load and store operations.
2565 All loads and stores that proceed calls to this function are guaranteed to be
2566 globally visible when this function returns.
2576 Saves the current CPU context that can be restored with a call to LongJump()
2579 Saves the current CPU context in the buffer specified by JumpBuffer and
2580 returns 0. The initial call to SetJump() must always return 0. Subsequent
2581 calls to LongJump() cause a non-zero value to be returned by SetJump().
2583 If JumpBuffer is NULL, then ASSERT().
2584 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2586 @param JumpBuffer A pointer to CPU context buffer.
2588 @retval 0 Indicates a return from SetJump().
2594 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
2598 Restores the CPU context that was saved with SetJump().
2600 Restores the CPU context from the buffer specified by JumpBuffer. This
2601 function never returns to the caller. Instead is resumes execution based on
2602 the state of JumpBuffer.
2604 If JumpBuffer is NULL, then ASSERT().
2605 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2606 If Value is 0, then ASSERT().
2608 @param JumpBuffer A pointer to CPU context buffer.
2609 @param Value The value to return when the SetJump() context is
2610 restored and must be non-zero.
2616 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
2621 Enables CPU interrupts.
2623 Enables CPU interrupts.
2633 Disables CPU interrupts.
2635 Disables CPU interrupts.
2645 Disables CPU interrupts and returns the interrupt state prior to the disable
2648 Disables CPU interrupts and returns the interrupt state prior to the disable
2651 @retval TRUE CPU interrupts were enabled on entry to this call.
2652 @retval FALSE CPU interrupts were disabled on entry to this call.
2657 SaveAndDisableInterrupts (
2662 Enables CPU interrupts for the smallest window required to capture any
2665 Enables CPU interrupts for the smallest window required to capture any
2671 EnableDisableInterrupts (
2676 Retrieves the current CPU interrupt state.
2678 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
2679 currently enabled. Otherwise returns FALSE.
2681 @retval TRUE CPU interrupts are enabled.
2682 @retval FALSE CPU interrupts are disabled.
2692 Set the current CPU interrupt state.
2694 Sets the current CPU interrupt state to the state specified by
2695 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
2696 InterruptState is FALSE, then interrupts are disabled. InterruptState is
2699 @param InterruptState TRUE if interrupts should enabled. FALSE if
2700 interrupts should be disabled.
2702 @return InterruptState
2708 IN BOOLEAN InterruptState
2712 Places the CPU in a sleep state until an interrupt is received.
2714 Places the CPU in a sleep state until an interrupt is received. If interrupts
2715 are disabled prior to calling this function, then the CPU will be placed in a
2716 sleep state indefinitely.
2726 Requests CPU to pause for a short period of time.
2728 Requests CPU to pause for a short period of time. Typically used in MP
2729 systems to prevent memory starvation while waiting for a spin lock.
2739 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2741 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2751 Transfers control to a function starting with a new stack.
2753 Transfers control to the function specified by EntryPoint using the new stack
2754 specified by NewStack and passing in the parameters specified by Context1 and
2755 Context2. Context1 and Context2 are optional and may be NULL. The function
2756 EntryPoint must never return.
2758 If EntryPoint is NULL, then ASSERT().
2759 If NewStack is NULL, then ASSERT().
2761 @param EntryPoint A pointer to function to call with the new stack.
2762 @param Context1 A pointer to the context to pass into the EntryPoint
2764 @param Context2 A pointer to the context to pass into the EntryPoint
2766 @param NewStack A pointer to the new stack to use for the EntryPoint
2773 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
2774 IN VOID
*Context1
, OPTIONAL
2775 IN VOID
*Context2
, OPTIONAL
2780 Generates a breakpoint on the CPU.
2782 Generates a breakpoint on the CPU. The breakpoint must be implemented such
2783 that code can resume normal execution after the breakpoint.
2793 Executes an infinite loop.
2795 Forces the CPU to execute an infinite loop. A debugger may be used to skip
2796 past the loop and the code that follows the loop must execute properly. This
2797 implies that the infinite loop must not cause the code that follow it to be
2808 // IA32 and X64 Specific Functions
2811 // Byte packed structure for 16-bit Real Mode EFLAGS
2815 UINT32 CF
:1; // Carry Flag
2816 UINT32 Reserved_0
:1; // Reserved
2817 UINT32 PF
:1; // Parity Flag
2818 UINT32 Reserved_1
:1; // Reserved
2819 UINT32 AF
:1; // Auxiliary Carry Flag
2820 UINT32 Reserved_2
:1; // Reserved
2821 UINT32 ZF
:1; // Zero Flag
2822 UINT32 SF
:1; // Sign Flag
2823 UINT32 TF
:1; // Trap Flag
2824 UINT32 IF
:1; // Interrupt Enable Flag
2825 UINT32 DF
:1; // Direction Flag
2826 UINT32 OF
:1; // Overflow Flag
2827 UINT32 IOPL
:2; // I/O Privilege Level
2828 UINT32 NT
:1; // Nested Task
2829 UINT32 Reserved_3
:1; // Reserved
2835 // Byte packed structure for EFLAGS/RFLAGS
2837 // 64-bits on X64. The upper 32-bits on X64 are reserved
2841 UINT32 CF
:1; // Carry Flag
2842 UINT32 Reserved_0
:1; // Reserved
2843 UINT32 PF
:1; // Parity Flag
2844 UINT32 Reserved_1
:1; // Reserved
2845 UINT32 AF
:1; // Auxiliary Carry Flag
2846 UINT32 Reserved_2
:1; // Reserved
2847 UINT32 ZF
:1; // Zero Flag
2848 UINT32 SF
:1; // Sign Flag
2849 UINT32 TF
:1; // Trap Flag
2850 UINT32 IF
:1; // Interrupt Enable Flag
2851 UINT32 DF
:1; // Direction Flag
2852 UINT32 OF
:1; // Overflow Flag
2853 UINT32 IOPL
:2; // I/O Privilege Level
2854 UINT32 NT
:1; // Nested Task
2855 UINT32 Reserved_3
:1; // Reserved
2856 UINT32 RF
:1; // Resume Flag
2857 UINT32 VM
:1; // Virtual 8086 Mode
2858 UINT32 AC
:1; // Alignment Check
2859 UINT32 VIF
:1; // Virtual Interrupt Flag
2860 UINT32 VIP
:1; // Virtual Interrupt Pending
2861 UINT32 ID
:1; // ID Flag
2862 UINT32 Reserved_4
:10; // Reserved
2868 // Byte packed structure for Control Register 0 (CR0)
2870 // 64-bits on X64. The upper 32-bits on X64 are reserved
2874 UINT32 PE
:1; // Protection Enable
2875 UINT32 MP
:1; // Monitor Coprocessor
2876 UINT32 EM
:1; // Emulation
2877 UINT32 TS
:1; // Task Switched
2878 UINT32 ET
:1; // Extension Type
2879 UINT32 NE
:1; // Numeric Error
2880 UINT32 Reserved_0
:10; // Reserved
2881 UINT32 WP
:1; // Write Protect
2882 UINT32 Reserved_1
:1; // Reserved
2883 UINT32 AM
:1; // Alignment Mask
2884 UINT32 Reserved_2
:10; // Reserved
2885 UINT32 NW
:1; // Mot Write-through
2886 UINT32 CD
:1; // Cache Disable
2887 UINT32 PG
:1; // Paging
2893 // Byte packed structure for Control Register 4 (CR4)
2895 // 64-bits on X64. The upper 32-bits on X64 are reserved
2899 UINT32 VME
:1; // Virtual-8086 Mode Extensions
2900 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
2901 UINT32 TSD
:1; // Time Stamp Disable
2902 UINT32 DE
:1; // Debugging Extensions
2903 UINT32 PSE
:1; // Page Size Extensions
2904 UINT32 PAE
:1; // Physical Address Extension
2905 UINT32 MCE
:1; // Machine Check Enable
2906 UINT32 PGE
:1; // Page Global Enable
2907 UINT32 PCE
:1; // Performance Monitoring Counter
2909 UINT32 OSFXSR
:1; // Operating System Support for
2910 // FXSAVE and FXRSTOR instructions
2911 UINT32 OSXMMEXCPT
:1; // Operating System Support for
2912 // Unmasked SIMD Floating Point
2914 UINT32 Reserved_0
:2; // Reserved
2915 UINT32 VMXE
:1; // VMX Enable
2916 UINT32 Reserved_1
:18; // Reseved
2922 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
2923 /// @bug How to make this structure byte-packed in a compiler independent way?
2932 #define IA32_IDT_GATE_TYPE_TASK 0x85
2933 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
2934 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
2935 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
2936 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
2939 // Byte packed structure for an Interrupt Gate Descriptor
2943 UINT32 OffsetLow
:16; // Offset bits 15..0
2944 UINT32 Selector
:16; // Selector
2945 UINT32 Reserved_0
:8; // Reserved
2946 UINT32 GateType
:8; // Gate Type. See #defines above
2947 UINT32 OffsetHigh
:16; // Offset bits 31..16
2950 } IA32_IDT_GATE_DESCRIPTOR
;
2953 // Byte packed structure for an FP/SSE/SSE2 context
2960 // Structures for the 16-bit real mode thunks
3013 IA32_EFLAGS32 EFLAGS
;
3023 } IA32_REGISTER_SET
;
3026 // Byte packed structure for an 16-bit real mode thunks
3029 IA32_REGISTER_SET
*RealModeState
;
3030 VOID
*RealModeBuffer
;
3031 UINT32 RealModeBufferSize
;
3032 UINT32 ThunkAttributes
;
3035 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
3036 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
3037 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3040 Retrieves CPUID information.
3042 Executes the CPUID instruction with EAX set to the value specified by Index.
3043 This function always returns Index.
3044 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3045 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3046 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3047 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3048 This function is only available on IA-32 and X64.
3050 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3052 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3053 instruction. This is an optional parameter that may be NULL.
3054 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3055 instruction. This is an optional parameter that may be NULL.
3056 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3057 instruction. This is an optional parameter that may be NULL.
3058 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3059 instruction. This is an optional parameter that may be NULL.
3068 OUT UINT32
*Eax
, OPTIONAL
3069 OUT UINT32
*Ebx
, OPTIONAL
3070 OUT UINT32
*Ecx
, OPTIONAL
3071 OUT UINT32
*Edx OPTIONAL
3075 Retrieves CPUID information using an extended leaf identifier.
3077 Executes the CPUID instruction with EAX set to the value specified by Index
3078 and ECX set to the value specified by SubIndex. This function always returns
3079 Index. This function is only available on IA-32 and x64.
3081 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3082 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3083 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3084 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3086 @param Index The 32-bit value to load into EAX prior to invoking the
3088 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3090 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3091 instruction. This is an optional parameter that may be
3093 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3094 instruction. This is an optional parameter that may be
3096 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3097 instruction. This is an optional parameter that may be
3099 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3100 instruction. This is an optional parameter that may be
3111 OUT UINT32
*Eax
, OPTIONAL
3112 OUT UINT32
*Ebx
, OPTIONAL
3113 OUT UINT32
*Ecx
, OPTIONAL
3114 OUT UINT32
*Edx OPTIONAL
3118 Returns the lower 32-bits of a Machine Specific Register(MSR).
3120 Reads and returns the lower 32-bits of the MSR specified by Index.
3121 No parameter checking is performed on Index, and some Index values may cause
3122 CPU exceptions. The caller must either guarantee that Index is valid, or the
3123 caller must set up exception handlers to catch the exceptions. This function
3124 is only available on IA-32 and X64.
3126 @param Index The 32-bit MSR index to read.
3128 @return The lower 32 bits of the MSR identified by Index.
3138 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3140 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3141 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3142 the MSR is returned. No parameter checking is performed on Index or Value,
3143 and some of these may cause CPU exceptions. The caller must either guarantee
3144 that Index and Value are valid, or the caller must establish proper exception
3145 handlers. This function is only available on IA-32 and X64.
3147 @param Index The 32-bit MSR index to write.
3148 @param Value The 32-bit value to write to the MSR.
3161 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3162 writes the result back to the 64-bit MSR.
3164 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3165 between the lower 32-bits of the read result and the value specified by
3166 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3167 32-bits of the value written to the MSR is returned. No parameter checking is
3168 performed on Index or OrData, and some of these may cause CPU exceptions. The
3169 caller must either guarantee that Index and OrData are valid, or the caller
3170 must establish proper exception handlers. This function is only available on
3173 @param Index The 32-bit MSR index to write.
3174 @param OrData The value to OR with the read value from the MSR.
3176 @return The lower 32-bit value written to the MSR.
3187 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3188 the result back to the 64-bit MSR.
3190 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3191 lower 32-bits of the read result and the value specified by AndData, and
3192 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3193 the value written to the MSR is returned. No parameter checking is performed
3194 on Index or AndData, and some of these may cause CPU exceptions. The caller
3195 must either guarantee that Index and AndData are valid, or the caller must
3196 establish proper exception handlers. This function is only available on IA-32
3199 @param Index The 32-bit MSR index to write.
3200 @param AndData The value to AND with the read value from the MSR.
3202 @return The lower 32-bit value written to the MSR.
3213 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3214 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3216 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3217 lower 32-bits of the read result and the value specified by AndData
3218 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3219 result of the AND operation and the value specified by OrData, and writes the
3220 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3221 written to the MSR is returned. No parameter checking is performed on Index,
3222 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3223 must either guarantee that Index, AndData, and OrData are valid, or the
3224 caller must establish proper exception handlers. This function is only
3225 available on IA-32 and X64.
3227 @param Index The 32-bit MSR index to write.
3228 @param AndData The value to AND with the read value from the MSR.
3229 @param OrData The value to OR with the result of the AND operation.
3231 @return The lower 32-bit value written to the MSR.
3243 Reads a bit field of an MSR.
3245 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3246 specified by the StartBit and the EndBit. The value of the bit field is
3247 returned. The caller must either guarantee that Index is valid, or the caller
3248 must set up exception handlers to catch the exceptions. This function is only
3249 available on IA-32 and X64.
3251 If StartBit is greater than 31, then ASSERT().
3252 If EndBit is greater than 31, then ASSERT().
3253 If EndBit is less than StartBit, then ASSERT().
3255 @param Index The 32-bit MSR index to read.
3256 @param StartBit The ordinal of the least significant bit in the bit field.
3258 @param EndBit The ordinal of the most significant bit in the bit field.
3261 @return The bit field read from the MSR.
3266 AsmMsrBitFieldRead32 (
3273 Writes a bit field to an MSR.
3275 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3276 field is specified by the StartBit and the EndBit. All other bits in the
3277 destination MSR are preserved. The lower 32-bits of the MSR written is
3278 returned. Extra left bits in Value are stripped. The caller must either
3279 guarantee that Index and the data written is valid, or the caller must set up
3280 exception handlers to catch the exceptions. This function is only available
3283 If StartBit is greater than 31, then ASSERT().
3284 If EndBit is greater than 31, then ASSERT().
3285 If EndBit is less than StartBit, then ASSERT().
3287 @param Index The 32-bit MSR index to write.
3288 @param StartBit The ordinal of the least significant bit in the bit field.
3290 @param EndBit The ordinal of the most significant bit in the bit field.
3292 @param Value New value of the bit field.
3294 @return The lower 32-bit of the value written to the MSR.
3299 AsmMsrBitFieldWrite32 (
3307 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3308 result back to the bit field in the 64-bit MSR.
3310 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3311 between the read result and the value specified by OrData, and writes the
3312 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3313 written to the MSR are returned. Extra left bits in OrData are stripped. The
3314 caller must either guarantee that Index and the data written is valid, or
3315 the caller must set up exception handlers to catch the exceptions. This
3316 function is only available on IA-32 and X64.
3318 If StartBit is greater than 31, then ASSERT().
3319 If EndBit is greater than 31, then ASSERT().
3320 If EndBit is less than StartBit, then ASSERT().
3322 @param Index The 32-bit MSR index to write.
3323 @param StartBit The ordinal of the least significant bit in the bit field.
3325 @param EndBit The ordinal of the most significant bit in the bit field.
3327 @param OrData The value to OR with the read value from the MSR.
3329 @return The lower 32-bit of the value written to the MSR.
3334 AsmMsrBitFieldOr32 (
3342 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3343 result back to the bit field in the 64-bit MSR.
3345 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3346 read result and the value specified by AndData, and writes the result to the
3347 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3348 MSR are returned. Extra left bits in AndData are stripped. The caller must
3349 either guarantee that Index and the data written is valid, or the caller must
3350 set up exception handlers to catch the exceptions. This function is only
3351 available on IA-32 and X64.
3353 If StartBit is greater than 31, then ASSERT().
3354 If EndBit is greater than 31, then ASSERT().
3355 If EndBit is less than StartBit, then ASSERT().
3357 @param Index The 32-bit MSR index to write.
3358 @param StartBit The ordinal of the least significant bit in the bit field.
3360 @param EndBit The ordinal of the most significant bit in the bit field.
3362 @param AndData The value to AND with the read value from the MSR.
3364 @return The lower 32-bit of the value written to the MSR.
3369 AsmMsrBitFieldAnd32 (
3377 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3378 bitwise inclusive OR, and writes the result back to the bit field in the
3381 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3382 bitwise inclusive OR between the read result and the value specified by
3383 AndData, and writes the result to the 64-bit MSR specified by Index. The
3384 lower 32-bits of the value written to the MSR are returned. Extra left bits
3385 in both AndData and OrData are stripped. The caller must either guarantee
3386 that Index and the data written is valid, or the caller must set up exception
3387 handlers to catch the exceptions. This function is only available on IA-32
3390 If StartBit is greater than 31, then ASSERT().
3391 If EndBit is greater than 31, then ASSERT().
3392 If EndBit is less than StartBit, then ASSERT().
3394 @param Index The 32-bit MSR index to write.
3395 @param StartBit The ordinal of the least significant bit in the bit field.
3397 @param EndBit The ordinal of the most significant bit in the bit field.
3399 @param AndData The value to AND with the read value from the MSR.
3400 @param OrData The value to OR with the result of the AND operation.
3402 @return The lower 32-bit of the value written to the MSR.
3407 AsmMsrBitFieldAndThenOr32 (
3416 Returns a 64-bit Machine Specific Register(MSR).
3418 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3419 performed on Index, and some Index values may cause CPU exceptions. The
3420 caller must either guarantee that Index is valid, or the caller must set up
3421 exception handlers to catch the exceptions. This function is only available
3424 @param Index The 32-bit MSR index to read.
3426 @return The value of the MSR identified by Index.
3436 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3439 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3440 64-bit value written to the MSR is returned. No parameter checking is
3441 performed on Index or Value, and some of these may cause CPU exceptions. The
3442 caller must either guarantee that Index and Value are valid, or the caller
3443 must establish proper exception handlers. This function is only available on
3446 @param Index The 32-bit MSR index to write.
3447 @param Value The 64-bit value to write to the MSR.
3460 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3461 back to the 64-bit MSR.
3463 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3464 between the read result and the value specified by OrData, and writes the
3465 result to the 64-bit MSR specified by Index. The value written to the MSR is
3466 returned. No parameter checking is performed on Index or OrData, and some of
3467 these may cause CPU exceptions. The caller must either guarantee that Index
3468 and OrData are valid, or the caller must establish proper exception handlers.
3469 This function is only available on IA-32 and X64.
3471 @param Index The 32-bit MSR index to write.
3472 @param OrData The value to OR with the read value from the MSR.
3474 @return The value written back to the MSR.
3485 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3488 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3489 read result and the value specified by OrData, and writes the result to the
3490 64-bit MSR specified by Index. The value written to the MSR is returned. No
3491 parameter checking is performed on Index or OrData, and some of these may
3492 cause CPU exceptions. The caller must either guarantee that Index and OrData
3493 are valid, or the caller must establish proper exception handlers. This
3494 function is only available on IA-32 and X64.
3496 @param Index The 32-bit MSR index to write.
3497 @param AndData The value to AND with the read value from the MSR.
3499 @return The value written back to the MSR.
3510 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3511 OR, and writes the result back to the 64-bit MSR.
3513 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3514 result and the value specified by AndData, performs a bitwise inclusive OR
3515 between the result of the AND operation and the value specified by OrData,
3516 and writes the result to the 64-bit MSR specified by Index. The value written
3517 to the MSR is returned. No parameter checking is performed on Index, AndData,
3518 or OrData, and some of these may cause CPU exceptions. The caller must either
3519 guarantee that Index, AndData, and OrData are valid, or the caller must
3520 establish proper exception handlers. This function is only available on IA-32
3523 @param Index The 32-bit MSR index to write.
3524 @param AndData The value to AND with the read value from the MSR.
3525 @param OrData The value to OR with the result of the AND operation.
3527 @return The value written back to the MSR.
3539 Reads a bit field of an MSR.
3541 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3542 StartBit and the EndBit. The value of the bit field is returned. The caller
3543 must either guarantee that Index is valid, or the caller must set up
3544 exception handlers to catch the exceptions. This function is only available
3547 If StartBit is greater than 63, then ASSERT().
3548 If EndBit is greater than 63, then ASSERT().
3549 If EndBit is less than StartBit, then ASSERT().
3551 @param Index The 32-bit MSR index to read.
3552 @param StartBit The ordinal of the least significant bit in the bit field.
3554 @param EndBit The ordinal of the most significant bit in the bit field.
3557 @return The value read from the MSR.
3562 AsmMsrBitFieldRead64 (
3569 Writes a bit field to an MSR.
3571 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3572 the StartBit and the EndBit. All other bits in the destination MSR are
3573 preserved. The MSR written is returned. Extra left bits in Value are
3574 stripped. The caller must either guarantee that Index and the data written is
3575 valid, or the caller must set up exception handlers to catch the exceptions.
3576 This function is only available on IA-32 and X64.
3578 If StartBit is greater than 63, then ASSERT().
3579 If EndBit is greater than 63, then ASSERT().
3580 If EndBit is less than StartBit, then ASSERT().
3582 @param Index The 32-bit MSR index to write.
3583 @param StartBit The ordinal of the least significant bit in the bit field.
3585 @param EndBit The ordinal of the most significant bit in the bit field.
3587 @param Value New value of the bit field.
3589 @return The value written back to the MSR.
3594 AsmMsrBitFieldWrite64 (
3602 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3603 writes the result back to the bit field in the 64-bit MSR.
3605 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3606 between the read result and the value specified by OrData, and writes the
3607 result to the 64-bit MSR specified by Index. The value written to the MSR is
3608 returned. Extra left bits in OrData are stripped. The caller must either
3609 guarantee that Index and the data written is valid, or the caller must set up
3610 exception handlers to catch the exceptions. This function is only available
3613 If StartBit is greater than 63, then ASSERT().
3614 If EndBit is greater than 63, then ASSERT().
3615 If EndBit is less than StartBit, then ASSERT().
3617 @param Index The 32-bit MSR index to write.
3618 @param StartBit The ordinal of the least significant bit in the bit field.
3620 @param EndBit The ordinal of the most significant bit in the bit field.
3622 @param OrData The value to OR with the read value from the bit field.
3624 @return The value written back to the MSR.
3629 AsmMsrBitFieldOr64 (
3637 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3638 result back to the bit field in the 64-bit MSR.
3640 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3641 read result and the value specified by AndData, and writes the result to the
3642 64-bit MSR specified by Index. The value written to the MSR is returned.
3643 Extra left bits in AndData are stripped. The caller must either guarantee
3644 that Index and the data written is valid, or the caller must set up exception
3645 handlers to catch the exceptions. This function is only available on IA-32
3648 If StartBit is greater than 63, then ASSERT().
3649 If EndBit is greater than 63, then ASSERT().
3650 If EndBit is less than StartBit, then ASSERT().
3652 @param Index The 32-bit MSR index to write.
3653 @param StartBit The ordinal of the least significant bit in the bit field.
3655 @param EndBit The ordinal of the most significant bit in the bit field.
3657 @param AndData The value to AND with the read value from the bit field.
3659 @return The value written back to the MSR.
3664 AsmMsrBitFieldAnd64 (
3672 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3673 bitwise inclusive OR, and writes the result back to the bit field in the
3676 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3677 a bitwise inclusive OR between the read result and the value specified by
3678 AndData, and writes the result to the 64-bit MSR specified by Index. The
3679 value written to the MSR is returned. Extra left bits in both AndData and
3680 OrData are stripped. The caller must either guarantee that Index and the data
3681 written is valid, or the caller must set up exception handlers to catch the
3682 exceptions. This function is only available on IA-32 and X64.
3684 If StartBit is greater than 63, then ASSERT().
3685 If EndBit is greater than 63, then ASSERT().
3686 If EndBit is less than StartBit, then ASSERT().
3688 @param Index The 32-bit MSR index to write.
3689 @param StartBit The ordinal of the least significant bit in the bit field.
3691 @param EndBit The ordinal of the most significant bit in the bit field.
3693 @param AndData The value to AND with the read value from the bit field.
3694 @param OrData The value to OR with the result of the AND operation.
3696 @return The value written back to the MSR.
3701 AsmMsrBitFieldAndThenOr64 (
3710 Reads the current value of the EFLAGS register.
3712 Reads and returns the current value of the EFLAGS register. This function is
3713 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3714 64-bit value on X64.
3716 @return EFLAGS on IA-32 or RFLAGS on X64.
3726 Reads the current value of the Control Register 0 (CR0).
3728 Reads and returns the current value of CR0. This function is only available
3729 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3732 @return The value of the Control Register 0 (CR0).
3742 Reads the current value of the Control Register 2 (CR2).
3744 Reads and returns the current value of CR2. This function is only available
3745 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3748 @return The value of the Control Register 2 (CR2).
3758 Reads the current value of the Control Register 3 (CR3).
3760 Reads and returns the current value of CR3. This function is only available
3761 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3764 @return The value of the Control Register 3 (CR3).
3774 Reads the current value of the Control Register 4 (CR4).
3776 Reads and returns the current value of CR4. This function is only available
3777 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3780 @return The value of the Control Register 4 (CR4).
3790 Writes a value to Control Register 0 (CR0).
3792 Writes and returns a new value to CR0. This function is only available on
3793 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3795 @param Cr0 The value to write to CR0.
3797 @return The value written to CR0.
3807 Writes a value to Control Register 2 (CR2).
3809 Writes and returns a new value to CR2. This function is only available on
3810 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3812 @param Cr2 The value to write to CR2.
3814 @return The value written to CR2.
3824 Writes a value to Control Register 3 (CR3).
3826 Writes and returns a new value to CR3. This function is only available on
3827 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3829 @param Cr3 The value to write to CR3.
3831 @return The value written to CR3.
3841 Writes a value to Control Register 4 (CR4).
3843 Writes and returns a new value to CR4. This function is only available on
3844 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3846 @param Cr4 The value to write to CR4.
3848 @return The value written to CR4.
3858 Reads the current value of Debug Register 0 (DR0).
3860 Reads and returns the current value of DR0. This function is only available
3861 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3864 @return The value of Debug Register 0 (DR0).
3874 Reads the current value of Debug Register 1 (DR1).
3876 Reads and returns the current value of DR1. This function is only available
3877 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3880 @return The value of Debug Register 1 (DR1).
3890 Reads the current value of Debug Register 2 (DR2).
3892 Reads and returns the current value of DR2. This function is only available
3893 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3896 @return The value of Debug Register 2 (DR2).
3906 Reads the current value of Debug Register 3 (DR3).
3908 Reads and returns the current value of DR3. This function is only available
3909 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3912 @return The value of Debug Register 3 (DR3).
3922 Reads the current value of Debug Register 4 (DR4).
3924 Reads and returns the current value of DR4. This function is only available
3925 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3928 @return The value of Debug Register 4 (DR4).
3938 Reads the current value of Debug Register 5 (DR5).
3940 Reads and returns the current value of DR5. This function is only available
3941 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3944 @return The value of Debug Register 5 (DR5).
3954 Reads the current value of Debug Register 6 (DR6).
3956 Reads and returns the current value of DR6. This function is only available
3957 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3960 @return The value of Debug Register 6 (DR6).
3970 Reads the current value of Debug Register 7 (DR7).
3972 Reads and returns the current value of DR7. This function is only available
3973 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3976 @return The value of Debug Register 7 (DR7).
3986 Writes a value to Debug Register 0 (DR0).
3988 Writes and returns a new value to DR0. This function is only available on
3989 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3991 @param Dr0 The value to write to Dr0.
3993 @return The value written to Debug Register 0 (DR0).
4003 Writes a value to Debug Register 1 (DR1).
4005 Writes and returns a new value to DR1. This function is only available on
4006 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4008 @param Dr1 The value to write to Dr1.
4010 @return The value written to Debug Register 1 (DR1).
4020 Writes a value to Debug Register 2 (DR2).
4022 Writes and returns a new value to DR2. This function is only available on
4023 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4025 @param Dr2 The value to write to Dr2.
4027 @return The value written to Debug Register 2 (DR2).
4037 Writes a value to Debug Register 3 (DR3).
4039 Writes and returns a new value to DR3. This function is only available on
4040 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4042 @param Dr3 The value to write to Dr3.
4044 @return The value written to Debug Register 3 (DR3).
4054 Writes a value to Debug Register 4 (DR4).
4056 Writes and returns a new value to DR4. This function is only available on
4057 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4059 @param Dr4 The value to write to Dr4.
4061 @return The value written to Debug Register 4 (DR4).
4071 Writes a value to Debug Register 5 (DR5).
4073 Writes and returns a new value to DR5. This function is only available on
4074 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4076 @param Dr5 The value to write to Dr5.
4078 @return The value written to Debug Register 5 (DR5).
4088 Writes a value to Debug Register 6 (DR6).
4090 Writes and returns a new value to DR6. This function is only available on
4091 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4093 @param Dr6 The value to write to Dr6.
4095 @return The value written to Debug Register 6 (DR6).
4105 Writes a value to Debug Register 7 (DR7).
4107 Writes and returns a new value to DR7. This function is only available on
4108 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4110 @param Dr7 The value to write to Dr7.
4112 @return The value written to Debug Register 7 (DR7).
4122 Reads the current value of Code Segment Register (CS).
4124 Reads and returns the current value of CS. This function is only available on
4127 @return The current value of CS.
4137 Reads the current value of Data Segment Register (DS).
4139 Reads and returns the current value of DS. This function is only available on
4142 @return The current value of DS.
4152 Reads the current value of Extra Segment Register (ES).
4154 Reads and returns the current value of ES. This function is only available on
4157 @return The current value of ES.
4167 Reads the current value of FS Data Segment Register (FS).
4169 Reads and returns the current value of FS. This function is only available on
4172 @return The current value of FS.
4182 Reads the current value of GS Data Segment Register (GS).
4184 Reads and returns the current value of GS. This function is only available on
4187 @return The current value of GS.
4197 Reads the current value of Stack Segment Register (SS).
4199 Reads and returns the current value of SS. This function is only available on
4202 @return The current value of SS.
4212 Reads the current value of Task Register (TR).
4214 Reads and returns the current value of TR. This function is only available on
4217 @return The current value of TR.
4227 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4229 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4230 function is only available on IA-32 and X64.
4232 If Gdtr is NULL, then ASSERT().
4234 @param Gdtr Pointer to a GDTR descriptor.
4240 OUT IA32_DESCRIPTOR
*Gdtr
4244 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4246 Writes and the current GDTR descriptor specified by Gdtr. This function is
4247 only available on IA-32 and X64.
4249 If Gdtr is NULL, then ASSERT().
4251 @param Gdtr Pointer to a GDTR descriptor.
4257 IN CONST IA32_DESCRIPTOR
*Gdtr
4261 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4263 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4264 function is only available on IA-32 and X64.
4266 If Idtr is NULL, then ASSERT().
4268 @param Idtr Pointer to a IDTR descriptor.
4274 OUT IA32_DESCRIPTOR
*Idtr
4278 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4280 Writes the current IDTR descriptor and returns it in Idtr. This function is
4281 only available on IA-32 and X64.
4283 If Idtr is NULL, then ASSERT().
4285 @param Idtr Pointer to a IDTR descriptor.
4291 IN CONST IA32_DESCRIPTOR
*Idtr
4295 Reads the current Local Descriptor Table Register(LDTR) selector.
4297 Reads and returns the current 16-bit LDTR descriptor value. This function is
4298 only available on IA-32 and X64.
4300 @return The current selector of LDT.
4310 Writes the current Local Descriptor Table Register (GDTR) selector.
4312 Writes and the current LDTR descriptor specified by Ldtr. This function is
4313 only available on IA-32 and X64.
4315 @param Ldtr 16-bit LDTR selector value.
4325 Save the current floating point/SSE/SSE2 context to a buffer.
4327 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4328 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4329 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().
4334 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4340 OUT IA32_FX_BUFFER
*Buffer
4344 Restores the current floating point/SSE/SSE2 context from a buffer.
4346 Restores the current floating point/SSE/SSE2 state from the buffer specified
4347 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4348 only available on IA-32 and X64.
4350 If Buffer is NULL, then ASSERT().
4351 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4352 If Buffer was not saved with AsmFxSave(), then ASSERT().
4354 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4360 IN CONST IA32_FX_BUFFER
*Buffer
4364 Reads the current value of 64-bit MMX Register #0 (MM0).
4366 Reads and returns the current value of MM0. This function is only available
4369 @return The current value of MM0.
4379 Reads the current value of 64-bit MMX Register #1 (MM1).
4381 Reads and returns the current value of MM1. This function is only available
4384 @return The current value of MM1.
4394 Reads the current value of 64-bit MMX Register #2 (MM2).
4396 Reads and returns the current value of MM2. This function is only available
4399 @return The current value of MM2.
4409 Reads the current value of 64-bit MMX Register #3 (MM3).
4411 Reads and returns the current value of MM3. This function is only available
4414 @return The current value of MM3.
4424 Reads the current value of 64-bit MMX Register #4 (MM4).
4426 Reads and returns the current value of MM4. This function is only available
4429 @return The current value of MM4.
4439 Reads the current value of 64-bit MMX Register #5 (MM5).
4441 Reads and returns the current value of MM5. This function is only available
4444 @return The current value of MM5.
4454 Reads the current value of 64-bit MMX Register #6 (MM6).
4456 Reads and returns the current value of MM6. This function is only available
4459 @return The current value of MM6.
4469 Reads the current value of 64-bit MMX Register #7 (MM7).
4471 Reads and returns the current value of MM7. This function is only available
4474 @return The current value of MM7.
4484 Writes the current value of 64-bit MMX Register #0 (MM0).
4486 Writes the current value of MM0. This function is only available on IA32 and
4489 @param Value The 64-bit value to write to MM0.
4499 Writes the current value of 64-bit MMX Register #1 (MM1).
4501 Writes the current value of MM1. This function is only available on IA32 and
4504 @param Value The 64-bit value to write to MM1.
4514 Writes the current value of 64-bit MMX Register #2 (MM2).
4516 Writes the current value of MM2. This function is only available on IA32 and
4519 @param Value The 64-bit value to write to MM2.
4529 Writes the current value of 64-bit MMX Register #3 (MM3).
4531 Writes the current value of MM3. This function is only available on IA32 and
4534 @param Value The 64-bit value to write to MM3.
4544 Writes the current value of 64-bit MMX Register #4 (MM4).
4546 Writes the current value of MM4. This function is only available on IA32 and
4549 @param Value The 64-bit value to write to MM4.
4559 Writes the current value of 64-bit MMX Register #5 (MM5).
4561 Writes the current value of MM5. This function is only available on IA32 and
4564 @param Value The 64-bit value to write to MM5.
4574 Writes the current value of 64-bit MMX Register #6 (MM6).
4576 Writes the current value of MM6. This function is only available on IA32 and
4579 @param Value The 64-bit value to write to MM6.
4589 Writes the current value of 64-bit MMX Register #7 (MM7).
4591 Writes the current value of MM7. This function is only available on IA32 and
4594 @param Value The 64-bit value to write to MM7.
4604 Reads the current value of Time Stamp Counter (TSC).
4606 Reads and returns the current value of TSC. This function is only available
4609 @return The current value of TSC
4619 Reads the current value of a Performance Counter (PMC).
4621 Reads and returns the current value of performance counter specified by
4622 Index. This function is only available on IA-32 and X64.
4624 @param Index The 32-bit Performance Counter index to read.
4626 @return The value of the PMC specified by Index.
4636 Sets up a monitor buffer that is used by AsmMwait().
4638 Executes a MONITOR instruction with the register state specified by Eax, Ecx
4639 and Edx. Returns Eax. This function is only available on IA-32 and X64.
4641 @param Eax The value to load into EAX or RAX before executing the MONITOR
4643 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4645 @param Edx The value to load into EDX or RDX before executing the MONITOR
4660 Executes an MWAIT instruction.
4662 Executes an MWAIT instruction with the register state specified by Eax and
4663 Ecx. Returns Eax. This function is only available on IA-32 and X64.
4665 @param Eax The value to load into EAX or RAX before executing the MONITOR
4667 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4681 Executes a WBINVD instruction.
4683 Executes a WBINVD instruction. This function is only available on IA-32 and
4694 Executes a INVD instruction.
4696 Executes a INVD instruction. This function is only available on IA-32 and
4707 Flushes a cache line from all the instruction and data caches within the
4708 coherency domain of the CPU.
4710 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
4711 This function is only available on IA-32 and X64.
4713 @param LinearAddress The address of the cache line to flush. If the CPU is
4714 in a physical addressing mode, then LinearAddress is a
4715 physical address. If the CPU is in a virtual
4716 addressing mode, then LinearAddress is a virtual
4719 @return LinearAddress
4724 IN VOID
*LinearAddress
4728 Enables the 32-bit paging mode on the CPU.
4730 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4731 must be properly initialized prior to calling this service. This function
4732 assumes the current execution mode is 32-bit protected mode. This function is
4733 only available on IA-32. After the 32-bit paging mode is enabled, control is
4734 transferred to the function specified by EntryPoint using the new stack
4735 specified by NewStack and passing in the parameters specified by Context1 and
4736 Context2. Context1 and Context2 are optional and may be NULL. The function
4737 EntryPoint must never return.
4739 If the current execution mode is not 32-bit protected mode, then ASSERT().
4740 If EntryPoint is NULL, then ASSERT().
4741 If NewStack is NULL, then ASSERT().
4743 There are a number of constraints that must be followed before calling this
4745 1) Interrupts must be disabled.
4746 2) The caller must be in 32-bit protected mode with flat descriptors. This
4747 means all descriptors must have a base of 0 and a limit of 4GB.
4748 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
4750 4) CR3 must point to valid page tables that will be used once the transition
4751 is complete, and those page tables must guarantee that the pages for this
4752 function and the stack are identity mapped.
4754 @param EntryPoint A pointer to function to call with the new stack after
4756 @param Context1 A pointer to the context to pass into the EntryPoint
4757 function as the first parameter after paging is enabled.
4758 @param Context2 A pointer to the context to pass into the EntryPoint
4759 function as the second parameter after paging is enabled.
4760 @param NewStack A pointer to the new stack to use for the EntryPoint
4761 function after paging is enabled.
4767 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4768 IN VOID
*Context1
, OPTIONAL
4769 IN VOID
*Context2
, OPTIONAL
4774 Disables the 32-bit paging mode on the CPU.
4776 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
4777 mode. This function assumes the current execution mode is 32-paged protected
4778 mode. This function is only available on IA-32. After the 32-bit paging mode
4779 is disabled, control is transferred to the function specified by EntryPoint
4780 using the new stack specified by NewStack and passing in the parameters
4781 specified by Context1 and Context2. Context1 and Context2 are optional and
4782 may be NULL. The function EntryPoint must never return.
4784 If the current execution mode is not 32-bit paged mode, then ASSERT().
4785 If EntryPoint is NULL, then ASSERT().
4786 If NewStack is NULL, then ASSERT().
4788 There are a number of constraints that must be followed before calling this
4790 1) Interrupts must be disabled.
4791 2) The caller must be in 32-bit paged mode.
4792 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
4793 4) CR3 must point to valid page tables that guarantee that the pages for
4794 this function and the stack are identity mapped.
4796 @param EntryPoint A pointer to function to call with the new stack after
4798 @param Context1 A pointer to the context to pass into the EntryPoint
4799 function as the first parameter after paging is disabled.
4800 @param Context2 A pointer to the context to pass into the EntryPoint
4801 function as the second parameter after paging is
4803 @param NewStack A pointer to the new stack to use for the EntryPoint
4804 function after paging is disabled.
4809 AsmDisablePaging32 (
4810 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4811 IN VOID
*Context1
, OPTIONAL
4812 IN VOID
*Context2
, OPTIONAL
4817 Enables the 64-bit paging mode on the CPU.
4819 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4820 must be properly initialized prior to calling this service. This function
4821 assumes the current execution mode is 32-bit protected mode with flat
4822 descriptors. This function is only available on IA-32. After the 64-bit
4823 paging mode is enabled, control is transferred to the function specified by
4824 EntryPoint using the new stack specified by NewStack and passing in the
4825 parameters specified by Context1 and Context2. Context1 and Context2 are
4826 optional and may be 0. The function EntryPoint must never return.
4828 If the current execution mode is not 32-bit protected mode with flat
4829 descriptors, then ASSERT().
4830 If EntryPoint is 0, then ASSERT().
4831 If NewStack is 0, then ASSERT().
4833 @param Cs The 16-bit selector to load in the CS before EntryPoint
4834 is called. The descriptor in the GDT that this selector
4835 references must be setup for long mode.
4836 @param EntryPoint The 64-bit virtual address of the function to call with
4837 the new stack after paging is enabled.
4838 @param Context1 The 64-bit virtual address of the context to pass into
4839 the EntryPoint function as the first parameter after
4841 @param Context2 The 64-bit virtual address of the context to pass into
4842 the EntryPoint function as the second parameter after
4844 @param NewStack The 64-bit virtual address of the new stack to use for
4845 the EntryPoint function after paging is enabled.
4851 IN UINT16 CodeSelector
,
4852 IN UINT64 EntryPoint
,
4853 IN UINT64 Context1
, OPTIONAL
4854 IN UINT64 Context2
, OPTIONAL
4859 Disables the 64-bit paging mode on the CPU.
4861 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
4862 mode. This function assumes the current execution mode is 64-paging mode.
4863 This function is only available on X64. After the 64-bit paging mode is
4864 disabled, control is transferred to the function specified by EntryPoint
4865 using the new stack specified by NewStack and passing in the parameters
4866 specified by Context1 and Context2. Context1 and Context2 are optional and
4867 may be 0. The function EntryPoint must never return.
4869 If the current execution mode is not 64-bit paged mode, then ASSERT().
4870 If EntryPoint is 0, then ASSERT().
4871 If NewStack is 0, then ASSERT().
4873 @param Cs The 16-bit selector to load in the CS before EntryPoint
4874 is called. The descriptor in the GDT that this selector
4875 references must be setup for 32-bit protected mode.
4876 @param EntryPoint The 64-bit virtual address of the function to call with
4877 the new stack after paging is disabled.
4878 @param Context1 The 64-bit virtual address of the context to pass into
4879 the EntryPoint function as the first parameter after
4881 @param Context2 The 64-bit virtual address of the context to pass into
4882 the EntryPoint function as the second parameter after
4884 @param NewStack The 64-bit virtual address of the new stack to use for
4885 the EntryPoint function after paging is disabled.
4890 AsmDisablePaging64 (
4891 IN UINT16 CodeSelector
,
4892 IN UINT32 EntryPoint
,
4893 IN UINT32 Context1
, OPTIONAL
4894 IN UINT32 Context2
, OPTIONAL
4899 // 16-bit thunking services
4903 Retrieves the properties for 16-bit thunk functions.
4905 Computes the size of the buffer and stack below 1MB required to use the
4906 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
4907 buffer size is returned in RealModeBufferSize, and the stack size is returned
4908 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
4909 then the actual minimum stack size is ExtraStackSize plus the maximum number
4910 of bytes that need to be passed to the 16-bit real mode code.
4912 If RealModeBufferSize is NULL, then ASSERT().
4913 If ExtraStackSize is NULL, then ASSERT().
4915 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
4916 required to use the 16-bit thunk functions.
4917 @param ExtraStackSize A pointer to the extra size of stack below 1MB
4918 that the 16-bit thunk functions require for
4919 temporary storage in the transition to and from
4925 AsmGetThunk16Properties (
4926 OUT UINT32
*RealModeBufferSize
,
4927 OUT UINT32
*ExtraStackSize
4931 Prepares all structures a code required to use AsmThunk16().
4933 Prepares all structures and code required to use AsmThunk16().
4935 If ThunkContext is NULL, then ASSERT().
4937 @param ThunkContext A pointer to the context structure that describes the
4938 16-bit real mode code to call.
4944 OUT THUNK_CONTEXT
*ThunkContext
4948 Transfers control to a 16-bit real mode entry point and returns the results.
4950 Transfers control to a 16-bit real mode entry point and returns the results.
4951 AsmPrepareThunk16() must be called with ThunkContext before this function is
4954 If ThunkContext is NULL, then ASSERT().
4955 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
4957 @param ThunkContext A pointer to the context structure that describes the
4958 16-bit real mode code to call.
4964 IN OUT THUNK_CONTEXT
*ThunkContext
4968 Prepares all structures and code for a 16-bit real mode thunk, transfers
4969 control to a 16-bit real mode entry point, and returns the results.
4971 Prepares all structures and code for a 16-bit real mode thunk, transfers
4972 control to a 16-bit real mode entry point, and returns the results. If the
4973 caller only need to perform a single 16-bit real mode thunk, then this
4974 service should be used. If the caller intends to make more than one 16-bit
4975 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
4976 once and AsmThunk16() can be called for each 16-bit real mode thunk.
4978 If ThunkContext is NULL, then ASSERT().
4980 @param ThunkContext A pointer to the context structure that describes the
4981 16-bit real mode code to call.
4986 AsmPrepareAndThunk16 (
4987 IN OUT THUNK_CONTEXT
*ThunkContext
4991 Transfers control to a function starting with a new stack.
4993 Transfers control to the function specified by EntryPoint using the new stack
4994 specified by NewStack and passing in the parameters specified by Context1 and
4995 Context2. Context1 and Context2 are optional and may be NULL. The function
4996 EntryPoint must never return.
4998 If EntryPoint is NULL, then ASSERT().
4999 If NewStack is NULL, then ASSERT().
5001 @param EntryPoint A pointer to function to call with the new stack.
5002 @param Context1 A pointer to the context to pass into the EntryPoint
5004 @param Context2 A pointer to the context to pass into the EntryPoint
5006 @param NewStack A pointer to the new stack to use for the EntryPoint
5008 @param NewBsp A pointer to the new memory location for RSE backing
5014 AsmSwitchStackAndBackingStore (
5015 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
5016 IN VOID
*Context1
, OPTIONAL
5017 IN VOID
*Context2
, OPTIONAL