3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Memory-only library functions with no library constructor/destructor
23 #ifndef __EDKII_GLUE_BASE_LIB_H__
24 #define __EDKII_GLUE_BASE_LIB_H__
30 #define StrCpy(_Dest, _Source) GlueStrCpy(_Dest, _Source)
31 #define StrnCpy(_Dest, _Source, _Length) GlueStrnCpy(_Dest, _Source, _Length)
32 #define StrLen(_String) GlueStrLen(_String)
33 #define StrSize(_String) GlueStrSize(_String)
34 #define StrCmp(_FristString, _SecondString) GlueStrCmp(_FristString, _SecondString)
35 #define StrnCmp(_FirstString, _SecondString, _Length) GlueStrnCmp(_FirstString, _SecondString, _Length)
36 #define StrCat(_Dest, _Source) GlueStrCat(_Dest, _Source)
37 #define StrnCat(_Dest, _Source, _Length) GlueStrnCat(_Dest, _Source, _Length)
42 #define InitializeListHead(_ListHead) GlueInitializeListHead(_ListHead)
43 #define InsertHeadList(_ListHead, _Entry ) GlueInsertHeadList(_ListHead, _Entry)
44 #define InsertTailList(_ListHead, _Entry) GlueInsertTailList(_ListHead, _Entry)
45 #define GetFirstNode(_List) GlueGetFirstNode(_List)
46 #define GetNextNode(_List, _Node) GlueGetNextNode(_List, _Node)
47 #define IsListEmpty(_ListHead) GlueIsListEmpty(_ListHead)
48 #define IsNull(_List, _Node) GlueIsNull(_List, _Node)
49 #define IsNodeAtEnd(_List, _Node) GlueIsNodeAtEnd(_List, _Node)
50 #define SwapListEntries(_FirstEntry, _SecondEntry) GlueSwapListEntries(_FirstEntry, _SecondEntry)
51 #define RemoveEntryList(_Entry) GlueRemoveEntryList(_Entry)
56 #define LShiftU64(_Op, _Count) GlueLShiftU64(_Op, _Count)
57 #define RShiftU64(_Op, _Count) GlueRShiftU64(_Op, _Count)
58 #define MultU64x32(_Multiplicand, _Multiplier) GlueMultU64x32(_Multiplicand, _Multiplier)
59 #define DivU64x32(_Dividend, _Divisor) GlueDivU64x32(_Dividend, _Divisor)
64 #define GetInterruptState() GlueGetInterruptState()
68 // Definitions for architecture specific types
69 // These include SPIN_LOCK and BASE_LIBRARY_JUMP_BUFFER
75 typedef volatile UINTN SPIN_LOCK
;
77 #if defined (MDE_CPU_IA32)
79 // IA32 context buffer used by SetJump() and LongJump()
88 } BASE_LIBRARY_JUMP_BUFFER
;
90 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
92 #elif defined (MDE_CPU_IPF)
94 // IPF context buffer used by SetJump() and LongJump()
129 UINT64 AfterSpillUNAT
;
135 } BASE_LIBRARY_JUMP_BUFFER
;
137 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10
139 #elif defined (MDE_CPU_X64)
141 // X64 context buffer used by SetJump() and LongJump()
154 } BASE_LIBRARY_JUMP_BUFFER
;
156 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
158 #elif defined (MDE_CPU_EBC)
160 // EBC context buffer used by SetJump() and LongJump()
168 } BASE_LIBRARY_JUMP_BUFFER
;
170 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
173 #error Unknown Processor Type
181 Copies one Null-terminated Unicode string to another Null-terminated Unicode
182 string and returns the new Unicode string.
184 This function copies the contents of the Unicode string Source to the Unicode
185 string Destination, and returns Destination. If Source and Destination
186 overlap, then the results are undefined.
188 If Destination is NULL, then ASSERT().
189 If Destination is not aligned on a 16-bit boundary, then ASSERT().
190 If Source is NULL, then ASSERT().
191 If Source is not aligned on a 16-bit boundary, then ASSERT().
192 If Source and Destination overlap, then ASSERT().
193 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
194 PcdMaximumUnicodeStringLength Unicode characters not including the
195 Null-terminator, then ASSERT().
197 @param Destination Pointer to a Null-terminated Unicode string.
198 @param Source Pointer to a Null-terminated Unicode string.
206 OUT CHAR16
*Destination
,
207 IN CONST CHAR16
*Source
212 Copies one Null-terminated Unicode string with a maximum length to another
213 Null-terminated Unicode string with a maximum length and returns the new
216 This function copies the contents of the Unicode string Source to the Unicode
217 string Destination, and returns Destination. At most, Length Unicode
218 characters are copied from Source to Destination. If Length is 0, then
219 Destination is returned unmodified. If Length is greater that the number of
220 Unicode characters in Source, then Destination is padded with Null Unicode
221 characters. If Source and Destination overlap, then the results are
224 If Length > 0 and Destination is NULL, then ASSERT().
225 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
226 If Length > 0 and Source is NULL, then ASSERT().
227 If Length > 0 and Source is not aligned on a 16-bit bounadry, then ASSERT().
228 If Source and Destination overlap, then ASSERT().
229 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
230 PcdMaximumUnicodeStringLength Unicode characters not including the
231 Null-terminator, then ASSERT().
233 @param Destination Pointer to a Null-terminated Unicode string.
234 @param Source Pointer to a Null-terminated Unicode string.
235 @param Length Maximum number of Unicode characters to copy.
243 OUT CHAR16
*Destination
,
244 IN CONST CHAR16
*Source
,
250 Returns the length of a Null-terminated Unicode string.
252 This function returns the number of Unicode characters in the Null-terminated
253 Unicode string specified by String.
255 If String is NULL, then ASSERT().
256 If String is not aligned on a 16-bit boundary, then ASSERT().
257 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
258 PcdMaximumUnicodeStringLength Unicode characters not including the
259 Null-terminator, then ASSERT().
261 @param String Pointer to a Null-terminated Unicode string.
263 @return The length of String.
269 IN CONST CHAR16
*String
274 Returns the size of a Null-terminated Unicode string in bytes, including the
277 This function returns the size, in bytes, of the Null-terminated Unicode
278 string specified by String.
280 If String is NULL, then ASSERT().
281 If String is not aligned on a 16-bit boundary, then ASSERT().
282 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
283 PcdMaximumUnicodeStringLength Unicode characters not including the
284 Null-terminator, then ASSERT().
286 @param String Pointer to a Null-terminated Unicode string.
288 @return The size of String.
294 IN CONST CHAR16
*String
299 Compares two Null-terminated Unicode strings, and returns the difference
300 between the first mismatched Unicode characters.
302 This function compares the Null-terminated Unicode string FirstString to the
303 Null-terminated Unicode string SecondString. If FirstString is identical to
304 SecondString, then 0 is returned. Otherwise, the value returned is the first
305 mismatched Unicode character in SecondString subtracted from the first
306 mismatched Unicode character in FirstString.
308 If FirstString is NULL, then ASSERT().
309 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
310 If SecondString is NULL, then ASSERT().
311 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
312 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
313 than PcdMaximumUnicodeStringLength Unicode characters not including the
314 Null-terminator, then ASSERT().
315 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
316 than PcdMaximumUnicodeStringLength Unicode characters not including the
317 Null-terminator, then ASSERT().
319 @param FirstString Pointer to a Null-terminated Unicode string.
320 @param SecondString Pointer to a Null-terminated Unicode string.
322 @retval 0 FirstString is identical to SecondString.
323 @retval !=0 FirstString is not identical to SecondString.
329 IN CONST CHAR16
*FirstString
,
330 IN CONST CHAR16
*SecondString
335 Compares two Null-terminated Unicode strings with maximum lengths, and
336 returns the difference between the first mismatched Unicode characters.
338 This function compares the Null-terminated Unicode string FirstString to the
339 Null-terminated Unicode string SecondString. At most, Length Unicode
340 characters will be compared. If Length is 0, then 0 is returned. If
341 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
342 value returned is the first mismatched Unicode character in SecondString
343 subtracted from the first mismatched Unicode character in FirstString.
345 If Length > 0 and FirstString is NULL, then ASSERT().
346 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().
347 If Length > 0 and SecondString is NULL, then ASSERT().
348 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().
349 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
350 than PcdMaximumUnicodeStringLength Unicode characters not including the
351 Null-terminator, then ASSERT().
352 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
353 than PcdMaximumUnicodeStringLength Unicode characters not including the
354 Null-terminator, then ASSERT().
356 @param FirstString Pointer to a Null-terminated Unicode string.
357 @param SecondString Pointer to a Null-terminated Unicode string.
358 @param Length Maximum number of Unicode characters to compare.
360 @retval 0 FirstString is identical to SecondString.
361 @retval !=0 FirstString is not identical to SecondString.
367 IN CONST CHAR16
*FirstString
,
368 IN CONST CHAR16
*SecondString
,
374 Concatenates one Null-terminated Unicode string to another Null-terminated
375 Unicode string, and returns the concatenated Unicode string.
377 This function concatenates two Null-terminated Unicode strings. The contents
378 of Null-terminated Unicode string Source are concatenated to the end of
379 Null-terminated Unicode string Destination. The Null-terminated concatenated
380 Unicode String is returned. If Source and Destination overlap, then the
381 results are undefined.
383 If Destination is NULL, then ASSERT().
384 If Destination is not aligned on a 16-bit bounadary, then ASSERT().
385 If Source is NULL, then ASSERT().
386 If Source is not aligned on a 16-bit bounadary, then ASSERT().
387 If Source and Destination overlap, then ASSERT().
388 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
389 than PcdMaximumUnicodeStringLength Unicode characters not including the
390 Null-terminator, then ASSERT().
391 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
392 PcdMaximumUnicodeStringLength Unicode characters not including the
393 Null-terminator, then ASSERT().
394 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
395 and Source results in a Unicode string with more than
396 PcdMaximumUnicodeStringLength Unicode characters not including the
397 Null-terminator, then ASSERT().
399 @param Destination Pointer to a Null-terminated Unicode string.
400 @param Source Pointer to a Null-terminated Unicode string.
408 IN OUT CHAR16
*Destination
,
409 IN CONST CHAR16
*Source
414 Concatenates one Null-terminated Unicode string with a maximum length to the
415 end of another Null-terminated Unicode string, and returns the concatenated
418 This function concatenates two Null-terminated Unicode strings. The contents
419 of Null-terminated Unicode string Source are concatenated to the end of
420 Null-terminated Unicode string Destination, and Destination is returned. At
421 most, Length Unicode characters are concatenated from Source to the end of
422 Destination, and Destination is always Null-terminated. If Length is 0, then
423 Destination is returned unmodified. If Source and Destination overlap, then
424 the results are undefined.
426 If Destination is NULL, then ASSERT().
427 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
428 If Length > 0 and Source is NULL, then ASSERT().
429 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
430 If Source and Destination overlap, then ASSERT().
431 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
432 than PcdMaximumUnicodeStringLength Unicode characters not including the
433 Null-terminator, then ASSERT().
434 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
435 PcdMaximumUnicodeStringLength Unicode characters not including the
436 Null-terminator, then ASSERT().
437 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
438 and Source results in a Unicode string with more than
439 PcdMaximumUnicodeStringLength Unicode characters not including the
440 Null-terminator, then ASSERT().
442 @param Destination Pointer to a Null-terminated Unicode string.
443 @param Source Pointer to a Null-terminated Unicode string.
444 @param Length Maximum number of Unicode characters to concatenate from
453 IN OUT CHAR16
*Destination
,
454 IN CONST CHAR16
*Source
,
459 Returns the first occurance of a Null-terminated Unicode sub-string
460 in a Null-terminated Unicode string.
462 This function scans the contents of the Null-terminated Unicode string
463 specified by String and returns the first occurrence of SearchString.
464 If SearchString is not found in String, then NULL is returned. If
465 the length of SearchString is zero, then String is
468 If String is NULL, then ASSERT().
469 If String is not aligned on a 16-bit boundary, then ASSERT().
470 If SearchString is NULL, then ASSERT().
471 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
473 If PcdMaximumUnicodeStringLength is not zero, and SearchString
474 or String contains more than PcdMaximumUnicodeStringLength Unicode
475 characters not including the Null-terminator, then ASSERT().
477 @param String Pointer to a Null-terminated Unicode string.
478 @param SearchString Pointer to a Null-terminated Unicode string to search for.
480 @retval NULL If the SearchString does not appear in String.
481 @retval !NULL If there is a match.
487 IN CONST CHAR16
*String
,
488 IN CONST CHAR16
*SearchString
492 Convert a Null-terminated Unicode decimal string to a value of
495 This function returns a value of type UINTN by interpreting the contents
496 of the Unicode string specified by String as a decimal number. The format
497 of the input Unicode string String is:
499 [spaces] [decimal digits].
501 The valid decimal digit character is in the range [0-9]. The
502 function will ignore the pad space, which includes spaces or
503 tab characters, before [decimal digits]. The running zero in the
504 beginning of [decimal digits] will be ignored. Then, the function
505 stops at the first character that is a not a valid decimal character
506 or a Null-terminator, whichever one comes first.
508 If String is NULL, then ASSERT().
509 If String is not aligned in a 16-bit boundary, then ASSERT().
510 If String has only pad spaces, then 0 is returned.
511 If String has no pad spaces or valid decimal digits,
513 If the number represented by String overflows according
514 to the range defined by UINTN, then ASSERT().
516 If PcdMaximumUnicodeStringLength is not zero, and String contains
517 more than PcdMaximumUnicodeStringLength Unicode characters not including
518 the Null-terminator, then ASSERT().
520 @param String Pointer to a Null-terminated Unicode string.
528 IN CONST CHAR16
*String
532 Convert a Null-terminated Unicode decimal string to a value of
535 This function returns a value of type UINT64 by interpreting the contents
536 of the Unicode string specified by String as a decimal number. The format
537 of the input Unicode string String is:
539 [spaces] [decimal digits].
541 The valid decimal digit character is in the range [0-9]. The
542 function will ignore the pad space, which includes spaces or
543 tab characters, before [decimal digits]. The running zero in the
544 beginning of [decimal digits] will be ignored. Then, the function
545 stops at the first character that is a not a valid decimal character
546 or a Null-terminator, whichever one comes first.
548 If String is NULL, then ASSERT().
549 If String is not aligned in a 16-bit boundary, then ASSERT().
550 If String has only pad spaces, then 0 is returned.
551 If String has no pad spaces or valid decimal digits,
553 If the number represented by String overflows according
554 to the range defined by UINT64, then ASSERT().
556 If PcdMaximumUnicodeStringLength is not zero, and String contains
557 more than PcdMaximumUnicodeStringLength Unicode characters not including
558 the Null-terminator, then ASSERT().
560 @param String Pointer to a Null-terminated Unicode string.
568 IN CONST CHAR16
*String
573 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
575 This function returns a value of type UINTN by interpreting the contents
576 of the Unicode string specified by String as a hexadecimal number.
577 The format of the input Unicode string String is:
579 [spaces][zeros][x][hexadecimal digits].
581 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
582 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
583 If "x" appears in the input string, it must be prefixed with at least one 0.
584 The function will ignore the pad space, which includes spaces or tab characters,
585 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
586 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
587 first valid hexadecimal digit. Then, the function stops at the first character that is
588 a not a valid hexadecimal character or NULL, whichever one comes first.
590 If String is NULL, then ASSERT().
591 If String is not aligned in a 16-bit boundary, then ASSERT().
592 If String has only pad spaces, then zero is returned.
593 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
594 then zero is returned.
595 If the number represented by String overflows according to the range defined by
596 UINTN, then ASSERT().
598 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
599 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
602 @param String Pointer to a Null-terminated Unicode string.
610 IN CONST CHAR16
*String
615 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
617 This function returns a value of type UINT64 by interpreting the contents
618 of the Unicode string specified by String as a hexadecimal number.
619 The format of the input Unicode string String is
621 [spaces][zeros][x][hexadecimal digits].
623 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
624 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
625 If "x" appears in the input string, it must be prefixed with at least one 0.
626 The function will ignore the pad space, which includes spaces or tab characters,
627 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
628 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
629 first valid hexadecimal digit. Then, the function stops at the first character that is
630 a not a valid hexadecimal character or NULL, whichever one comes first.
632 If String is NULL, then ASSERT().
633 If String is not aligned in a 16-bit boundary, then ASSERT().
634 If String has only pad spaces, then zero is returned.
635 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
636 then zero is returned.
637 If the number represented by String overflows according to the range defined by
638 UINT64, then ASSERT().
640 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
641 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
644 @param String Pointer to a Null-terminated Unicode string.
652 IN CONST CHAR16
*String
657 Convert one Null-terminated Unicode string to a Null-terminated
658 ASCII string and returns the ASCII string.
660 This function converts the content of the Unicode string Source
661 to the ASCII string Destination by copying the lower 8 bits of
662 each Unicode character. It returns Destination.
664 If any Unicode characters in Source contain non-zero value in
665 the upper 8 bits, then ASSERT().
667 If Destination is NULL, then ASSERT().
668 If Source is NULL, then ASSERT().
669 If Source is not aligned on a 16-bit boundary, then ASSERT().
670 If Source and Destination overlap, then ASSERT().
672 If PcdMaximumUnicodeStringLength is not zero, and Source contains
673 more than PcdMaximumUnicodeStringLength Unicode characters not including
674 the Null-terminator, then ASSERT().
676 If PcdMaximumAsciiStringLength is not zero, and Source contains more
677 than PcdMaximumAsciiStringLength Unicode characters not including the
678 Null-terminator, then ASSERT().
680 @param Source Pointer to a Null-terminated Unicode string.
681 @param Destination Pointer to a Null-terminated ASCII string.
688 UnicodeStrToAsciiStr (
689 IN CONST CHAR16
*Source
,
690 OUT CHAR8
*Destination
695 Copies one Null-terminated ASCII string to another Null-terminated ASCII
696 string and returns the new ASCII string.
698 This function copies the contents of the ASCII string Source to the ASCII
699 string Destination, and returns Destination. If Source and Destination
700 overlap, then the results are undefined.
702 If Destination is NULL, then ASSERT().
703 If Source is NULL, then ASSERT().
704 If Source and Destination overlap, then ASSERT().
705 If PcdMaximumAsciiStringLength is not zero and Source contains more than
706 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
709 @param Destination Pointer to a Null-terminated ASCII string.
710 @param Source Pointer to a Null-terminated ASCII string.
718 OUT CHAR8
*Destination
,
719 IN CONST CHAR8
*Source
724 Copies one Null-terminated ASCII string with a maximum length to another
725 Null-terminated ASCII string with a maximum length and returns the new ASCII
728 This function copies the contents of the ASCII string Source to the ASCII
729 string Destination, and returns Destination. At most, Length ASCII characters
730 are copied from Source to Destination. If Length is 0, then Destination is
731 returned unmodified. If Length is greater that the number of ASCII characters
732 in Source, then Destination is padded with Null ASCII characters. If Source
733 and Destination overlap, then the results are undefined.
735 If Destination is NULL, then ASSERT().
736 If Source is NULL, then ASSERT().
737 If Source and Destination overlap, then ASSERT().
738 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
739 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
742 @param Destination Pointer to a Null-terminated ASCII string.
743 @param Source Pointer to a Null-terminated ASCII string.
744 @param Length Maximum number of ASCII characters to copy.
752 OUT CHAR8
*Destination
,
753 IN CONST CHAR8
*Source
,
759 Returns the length of a Null-terminated ASCII string.
761 This function returns the number of ASCII characters in the Null-terminated
762 ASCII string specified by String.
764 If Length > 0 and Destination is NULL, then ASSERT().
765 If Length > 0 and Source is NULL, then ASSERT().
766 If PcdMaximumAsciiStringLength is not zero and String contains more than
767 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
770 @param String Pointer to a Null-terminated ASCII string.
772 @return The length of String.
778 IN CONST CHAR8
*String
783 Returns the size of a Null-terminated ASCII string in bytes, including the
786 This function returns the size, in bytes, of the Null-terminated ASCII string
789 If String is NULL, then ASSERT().
790 If PcdMaximumAsciiStringLength is not zero and String contains more than
791 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
794 @param String Pointer to a Null-terminated ASCII string.
796 @return The size of String.
802 IN CONST CHAR8
*String
807 Compares two Null-terminated ASCII strings, and returns the difference
808 between the first mismatched ASCII characters.
810 This function compares the Null-terminated ASCII string FirstString to the
811 Null-terminated ASCII string SecondString. If FirstString is identical to
812 SecondString, then 0 is returned. Otherwise, the value returned is the first
813 mismatched ASCII character in SecondString subtracted from the first
814 mismatched ASCII character in FirstString.
816 If FirstString is NULL, then ASSERT().
817 If SecondString is NULL, then ASSERT().
818 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
819 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
821 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
822 than PcdMaximumAsciiStringLength ASCII characters not including the
823 Null-terminator, then ASSERT().
825 @param FirstString Pointer to a Null-terminated ASCII string.
826 @param SecondString Pointer to a Null-terminated ASCII string.
828 @retval 0 FirstString is identical to SecondString.
829 @retval !=0 FirstString is not identical to SecondString.
835 IN CONST CHAR8
*FirstString
,
836 IN CONST CHAR8
*SecondString
841 Performs a case insensitive comparison of two Null-terminated ASCII strings,
842 and returns the difference between the first mismatched ASCII characters.
844 This function performs a case insensitive comparison of the Null-terminated
845 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
846 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
847 value returned is the first mismatched lower case ASCII character in
848 SecondString subtracted from the first mismatched lower case ASCII character
851 If FirstString is NULL, then ASSERT().
852 If SecondString is NULL, then ASSERT().
853 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
854 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
856 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
857 than PcdMaximumAsciiStringLength ASCII characters not including the
858 Null-terminator, then ASSERT().
860 @param FirstString Pointer to a Null-terminated ASCII string.
861 @param SecondString Pointer to a Null-terminated ASCII string.
863 @retval 0 FirstString is identical to SecondString using case insensitive
865 @retval !=0 FirstString is not identical to SecondString using case
866 insensitive comparisons.
872 IN CONST CHAR8
*FirstString
,
873 IN CONST CHAR8
*SecondString
878 Compares two Null-terminated ASCII strings with maximum lengths, and returns
879 the difference between the first mismatched ASCII characters.
881 This function compares the Null-terminated ASCII string FirstString to the
882 Null-terminated ASCII string SecondString. At most, Length ASCII characters
883 will be compared. If Length is 0, then 0 is returned. If FirstString is
884 identical to SecondString, then 0 is returned. Otherwise, the value returned
885 is the first mismatched ASCII character in SecondString subtracted from the
886 first mismatched ASCII character in FirstString.
888 If Length > 0 and FirstString is NULL, then ASSERT().
889 If Length > 0 and SecondString is NULL, then ASSERT().
890 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
891 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
893 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than
894 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
897 @param FirstString Pointer to a Null-terminated ASCII string.
898 @param SecondString Pointer to a Null-terminated ASCII string.
900 @retval 0 FirstString is identical to SecondString.
901 @retval !=0 FirstString is not identical to SecondString.
907 IN CONST CHAR8
*FirstString
,
908 IN CONST CHAR8
*SecondString
,
914 Concatenates one Null-terminated ASCII string to another Null-terminated
915 ASCII string, and returns the concatenated ASCII string.
917 This function concatenates two Null-terminated ASCII strings. The contents of
918 Null-terminated ASCII string Source are concatenated to the end of Null-
919 terminated ASCII string Destination. The Null-terminated concatenated ASCII
922 If Destination is NULL, then ASSERT().
923 If Source is NULL, then ASSERT().
924 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
925 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
927 If PcdMaximumAsciiStringLength is not zero and Source contains more than
928 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
930 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
931 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
932 ASCII characters, then ASSERT().
934 @param Destination Pointer to a Null-terminated ASCII string.
935 @param Source Pointer to a Null-terminated ASCII string.
943 IN OUT CHAR8
*Destination
,
944 IN CONST CHAR8
*Source
949 Concatenates one Null-terminated ASCII string with a maximum length to the
950 end of another Null-terminated ASCII string, and returns the concatenated
953 This function concatenates two Null-terminated ASCII strings. The contents
954 of Null-terminated ASCII string Source are concatenated to the end of Null-
955 terminated ASCII string Destination, and Destination is returned. At most,
956 Length ASCII characters are concatenated from Source to the end of
957 Destination, and Destination is always Null-terminated. If Length is 0, then
958 Destination is returned unmodified. If Source and Destination overlap, then
959 the results are undefined.
961 If Length > 0 and Destination is NULL, then ASSERT().
962 If Length > 0 and Source is NULL, then ASSERT().
963 If Source and Destination overlap, then ASSERT().
964 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
965 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
967 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
968 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
970 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
971 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
972 ASCII characters not including the Null-terminator, then ASSERT().
974 @param Destination Pointer to a Null-terminated ASCII string.
975 @param Source Pointer to a Null-terminated ASCII string.
976 @param Length Maximum number of ASCII characters to concatenate from
985 IN OUT CHAR8
*Destination
,
986 IN CONST CHAR8
*Source
,
992 Returns the first occurance of a Null-terminated ASCII sub-string
993 in a Null-terminated ASCII string.
995 This function scans the contents of the ASCII string specified by String
996 and returns the first occurrence of SearchString. If SearchString is not
997 found in String, then NULL is returned. If the length of SearchString is zero,
998 then String is returned.
1000 If String is NULL, then ASSERT().
1001 If SearchString is NULL, then ASSERT().
1003 If PcdMaximumAsciiStringLength is not zero, and SearchString or
1004 String contains more than PcdMaximumAsciiStringLength Unicode characters
1005 not including the Null-terminator, then ASSERT().
1007 @param String Pointer to a Null-terminated ASCII string.
1008 @param SearchString Pointer to a Null-terminated ASCII string to search for.
1010 @retval NULL If the SearchString does not appear in String.
1011 @retval !NULL If there is a match.
1017 IN CONST CHAR8
*String
,
1018 IN CONST CHAR8
*SearchString
1023 Convert a Null-terminated ASCII decimal string to a value of type
1026 This function returns a value of type UINTN by interpreting the contents
1027 of the ASCII string String as a decimal number. The format of the input
1028 ASCII string String is:
1030 [spaces] [decimal digits].
1032 The valid decimal digit character is in the range [0-9]. The function will
1033 ignore the pad space, which includes spaces or tab characters, before the digits.
1034 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1035 function stops at the first character that is a not a valid decimal character or
1036 Null-terminator, whichever on comes first.
1038 If String has only pad spaces, then 0 is returned.
1039 If String has no pad spaces or valid decimal digits, then 0 is returned.
1040 If the number represented by String overflows according to the range defined by
1041 UINTN, then ASSERT().
1042 If String is NULL, then ASSERT().
1043 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1044 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1047 @param String Pointer to a Null-terminated ASCII string.
1054 AsciiStrDecimalToUintn (
1055 IN CONST CHAR8
*String
1060 Convert a Null-terminated ASCII decimal string to a value of type
1063 This function returns a value of type UINT64 by interpreting the contents
1064 of the ASCII string String as a decimal number. The format of the input
1065 ASCII string String is:
1067 [spaces] [decimal digits].
1069 The valid decimal digit character is in the range [0-9]. The function will
1070 ignore the pad space, which includes spaces or tab characters, before the digits.
1071 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1072 function stops at the first character that is a not a valid decimal character or
1073 Null-terminator, whichever on comes first.
1075 If String has only pad spaces, then 0 is returned.
1076 If String has no pad spaces or valid decimal digits, then 0 is returned.
1077 If the number represented by String overflows according to the range defined by
1078 UINT64, then ASSERT().
1079 If String is NULL, then ASSERT().
1080 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1081 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1084 @param String Pointer to a Null-terminated ASCII string.
1091 AsciiStrDecimalToUint64 (
1092 IN CONST CHAR8
*String
1097 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1099 This function returns a value of type UINTN by interpreting the contents of
1100 the ASCII string String as a hexadecimal number. The format of the input ASCII
1103 [spaces][zeros][x][hexadecimal digits].
1105 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1106 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1107 appears in the input string, it must be prefixed with at least one 0. The function
1108 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1109 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1110 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1111 digit. Then, the function stops at the first character that is a not a valid
1112 hexadecimal character or Null-terminator, whichever on comes first.
1114 If String has only pad spaces, then 0 is returned.
1115 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1118 If the number represented by String overflows according to the range defined by UINTN,
1120 If String is NULL, then ASSERT().
1121 If PcdMaximumAsciiStringLength is not zero,
1122 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1123 the Null-terminator, then ASSERT().
1125 @param String Pointer to a Null-terminated ASCII string.
1132 AsciiStrHexToUintn (
1133 IN CONST CHAR8
*String
1138 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1140 This function returns a value of type UINT64 by interpreting the contents of
1141 the ASCII string String as a hexadecimal number. The format of the input ASCII
1144 [spaces][zeros][x][hexadecimal digits].
1146 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1147 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1148 appears in the input string, it must be prefixed with at least one 0. The function
1149 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1150 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1151 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1152 digit. Then, the function stops at the first character that is a not a valid
1153 hexadecimal character or Null-terminator, whichever on comes first.
1155 If String has only pad spaces, then 0 is returned.
1156 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1159 If the number represented by String overflows according to the range defined by UINT64,
1161 If String is NULL, then ASSERT().
1162 If PcdMaximumAsciiStringLength is not zero,
1163 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1164 the Null-terminator, then ASSERT().
1166 @param String Pointer to a Null-terminated ASCII string.
1173 AsciiStrHexToUint64 (
1174 IN CONST CHAR8
*String
1179 Convert one Null-terminated ASCII string to a Null-terminated
1180 Unicode string and returns the Unicode string.
1182 This function converts the contents of the ASCII string Source to the Unicode
1183 string Destination, and returns Destination. The function terminates the
1184 Unicode string Destination by appending a Null-terminator character at the end.
1185 The caller is responsible to make sure Destination points to a buffer with size
1186 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1188 If Destination is NULL, then ASSERT().
1189 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1190 If Source is NULL, then ASSERT().
1191 If Source and Destination overlap, then ASSERT().
1192 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1193 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1195 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1196 PcdMaximumUnicodeStringLength ASCII characters not including the
1197 Null-terminator, then ASSERT().
1199 @param Source Pointer to a Null-terminated ASCII string.
1200 @param Destination Pointer to a Null-terminated Unicode string.
1207 AsciiStrToUnicodeStr (
1208 IN CONST CHAR8
*Source
,
1209 OUT CHAR16
*Destination
1214 Converts an 8-bit value to an 8-bit BCD value.
1216 Converts the 8-bit value specified by Value to BCD. The BCD value is
1219 If Value >= 100, then ASSERT().
1221 @param Value The 8-bit value to convert to BCD. Range 0..99.
1223 @return The BCD value
1234 Converts an 8-bit BCD value to an 8-bit value.
1236 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
1239 If Value >= 0xA0, then ASSERT().
1240 If (Value & 0x0F) >= 0x0A, then ASSERT().
1242 @param Value The 8-bit BCD value to convert to an 8-bit value.
1244 @return The 8-bit value is returned.
1254 // LIST_ENTRY definition
1256 typedef struct _LIST_ENTRY LIST_ENTRY
;
1258 struct _LIST_ENTRY
{
1259 LIST_ENTRY
*ForwardLink
;
1260 LIST_ENTRY
*BackLink
;
1264 // Linked List Functions and Macros
1268 Initializes the head node of a doubly linked list that is declared as a
1269 global variable in a module.
1271 Initializes the forward and backward links of a new linked list. After
1272 initializing a linked list with this macro, the other linked list functions
1273 may be used to add and remove nodes from the linked list. This macro results
1274 in smaller executables by initializing the linked list in the data section,
1275 instead if calling the InitializeListHead() function to perform the
1276 equivalent operation.
1278 @param ListHead The head note of a list to initiailize.
1281 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
1285 Initializes the head node of a doubly linked list, and returns the pointer to
1286 the head node of the doubly linked list.
1288 Initializes the forward and backward links of a new linked list. After
1289 initializing a linked list with this function, the other linked list
1290 functions may be used to add and remove nodes from the linked list. It is up
1291 to the caller of this function to allocate the memory for ListHead.
1293 If ListHead is NULL, then ASSERT().
1295 @param ListHead A pointer to the head node of a new doubly linked list.
1302 GlueInitializeListHead (
1303 IN LIST_ENTRY
*ListHead
1308 Adds a node to the beginning of a doubly linked list, and returns the pointer
1309 to the head node of the doubly linked list.
1311 Adds the node Entry at the beginning of the doubly linked list denoted by
1312 ListHead, and returns ListHead.
1314 If ListHead is NULL, then ASSERT().
1315 If Entry is NULL, then ASSERT().
1316 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1317 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1318 of nodes in ListHead, including the ListHead node, is greater than or
1319 equal to PcdMaximumLinkedListLength, then ASSERT().
1321 @param ListHead A pointer to the head node of a doubly linked list.
1322 @param Entry A pointer to a node that is to be inserted at the beginning
1323 of a doubly linked list.
1330 GlueInsertHeadList (
1331 IN LIST_ENTRY
*ListHead
,
1332 IN LIST_ENTRY
*Entry
1337 Adds a node to the end of a doubly linked list, and returns the pointer to
1338 the head node of the doubly linked list.
1340 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
1341 and returns ListHead.
1343 If ListHead is NULL, then ASSERT().
1344 If Entry is NULL, then ASSERT().
1345 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1346 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1347 of nodes in ListHead, including the ListHead node, is greater than or
1348 equal to PcdMaximumLinkedListLength, then ASSERT().
1350 @param ListHead A pointer to the head node of a doubly linked list.
1351 @param Entry A pointer to a node that is to be added at the end of the
1359 GlueInsertTailList (
1360 IN LIST_ENTRY
*ListHead
,
1361 IN LIST_ENTRY
*Entry
1366 Retrieves the first node of a doubly linked list.
1368 Returns the first node of a doubly linked list. List must have been
1369 initialized with InitializeListHead(). If List is empty, then NULL is
1372 If List is NULL, then ASSERT().
1373 If List was not initialized with InitializeListHead(), then ASSERT().
1374 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1375 in List, including the List node, is greater than or equal to
1376 PcdMaximumLinkedListLength, then ASSERT().
1378 @param List A pointer to the head node of a doubly linked list.
1380 @return The first node of a doubly linked list.
1381 @retval NULL The list is empty.
1387 IN CONST LIST_ENTRY
*List
1392 Retrieves the next node of a doubly linked list.
1394 Returns the node of a doubly linked list that follows Node. List must have
1395 been initialized with InitializeListHead(). If List is empty, then List is
1398 If List is NULL, then ASSERT().
1399 If Node is NULL, then ASSERT().
1400 If List was not initialized with InitializeListHead(), then ASSERT().
1401 If PcdMaximumLinkedListLenth is not zero, and List contains more than
1402 PcdMaximumLinkedListLenth nodes, then ASSERT().
1403 If Node is not a node in List, then ASSERT().
1405 @param List A pointer to the head node of a doubly linked list.
1406 @param Node A pointer to a node in the doubly linked list.
1408 @return Pointer to the next node if one exists. Otherwise a null value which
1409 is actually List is returned.
1415 IN CONST LIST_ENTRY
*List
,
1416 IN CONST LIST_ENTRY
*Node
1421 Checks to see if a doubly linked list is empty or not.
1423 Checks to see if the doubly linked list is empty. If the linked list contains
1424 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
1426 If ListHead is NULL, then ASSERT().
1427 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1428 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1429 in List, including the List node, is greater than or equal to
1430 PcdMaximumLinkedListLength, then ASSERT().
1432 @param ListHead A pointer to the head node of a doubly linked list.
1434 @retval TRUE The linked list is empty.
1435 @retval FALSE The linked list is not empty.
1441 IN CONST LIST_ENTRY
*ListHead
1446 Determines if a node in a doubly linked list is null.
1448 Returns FALSE if Node is one of the nodes in the doubly linked list specified
1449 by List. Otherwise, TRUE is returned. List must have been initialized with
1450 InitializeListHead().
1452 If List is NULL, then ASSERT().
1453 If Node is NULL, then ASSERT().
1454 If List was not initialized with InitializeListHead(), then ASSERT().
1455 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1456 in List, including the List node, is greater than or equal to
1457 PcdMaximumLinkedListLength, then ASSERT().
1458 If Node is not a node in List and Node is not equal to List, then ASSERT().
1460 @param List A pointer to the head node of a doubly linked list.
1461 @param Node A pointer to a node in the doubly linked list.
1463 @retval TRUE Node is one of the nodes in the doubly linked list.
1464 @retval FALSE Node is not one of the nodes in the doubly linked list.
1470 IN CONST LIST_ENTRY
*List
,
1471 IN CONST LIST_ENTRY
*Node
1476 Determines if a node the last node in a doubly linked list.
1478 Returns TRUE if Node is the last node in the doubly linked list specified by
1479 List. Otherwise, FALSE is returned. List must have been initialized with
1480 InitializeListHead().
1482 If List is NULL, then ASSERT().
1483 If Node is NULL, then ASSERT().
1484 If List was not initialized with InitializeListHead(), then ASSERT().
1485 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1486 in List, including the List node, is greater than or equal to
1487 PcdMaximumLinkedListLength, then ASSERT().
1488 If Node is not a node in List, then ASSERT().
1490 @param List A pointer to the head node of a doubly linked list.
1491 @param Node A pointer to a node in the doubly linked list.
1493 @retval TRUE Node is the last node in the linked list.
1494 @retval FALSE Node is not the last node in the linked list.
1500 IN CONST LIST_ENTRY
*List
,
1501 IN CONST LIST_ENTRY
*Node
1506 Swaps the location of two nodes in a doubly linked list, and returns the
1507 first node after the swap.
1509 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
1510 Otherwise, the location of the FirstEntry node is swapped with the location
1511 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
1512 same double linked list as FirstEntry and that double linked list must have
1513 been initialized with InitializeListHead(). SecondEntry is returned after the
1516 If FirstEntry is NULL, then ASSERT().
1517 If SecondEntry is NULL, then ASSERT().
1518 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
1519 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1520 linked list containing the FirstEntry and SecondEntry nodes, including
1521 the FirstEntry and SecondEntry nodes, is greater than or equal to
1522 PcdMaximumLinkedListLength, then ASSERT().
1524 @param FirstEntry A pointer to a node in a linked list.
1525 @param SecondEntry A pointer to another node in the same linked list.
1530 GlueSwapListEntries (
1531 IN LIST_ENTRY
*FirstEntry
,
1532 IN LIST_ENTRY
*SecondEntry
1537 Removes a node from a doubly linked list, and returns the node that follows
1540 Removes the node Entry from a doubly linked list. It is up to the caller of
1541 this function to release the memory used by this node if that is required. On
1542 exit, the node following Entry in the doubly linked list is returned. If
1543 Entry is the only node in the linked list, then the head node of the linked
1546 If Entry is NULL, then ASSERT().
1547 If Entry is the head node of an empty list, then ASSERT().
1548 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1549 linked list containing Entry, including the Entry node, is greater than
1550 or equal to PcdMaximumLinkedListLength, then ASSERT().
1552 @param Entry A pointer to a node in a linked list
1559 GlueRemoveEntryList (
1560 IN CONST LIST_ENTRY
*Entry
1568 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
1569 with zeros. The shifted value is returned.
1571 This function shifts the 64-bit value Operand to the left by Count bits. The
1572 low Count bits are set to zero. The shifted value is returned.
1574 If Count is greater than 63, then ASSERT().
1576 @param Operand The 64-bit operand to shift left.
1577 @param Count The number of bits to shift left.
1579 @return Operand << Count
1591 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1592 filled with zeros. The shifted value is returned.
1594 This function shifts the 64-bit value Operand to the right by Count bits. The
1595 high Count bits are set to zero. The shifted value is returned.
1597 If Count is greater than 63, then ASSERT().
1599 @param Operand The 64-bit operand to shift right.
1600 @param Count The number of bits to shift right.
1602 @return Operand >> Count
1614 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1615 with original integer's bit 63. The shifted value is returned.
1617 This function shifts the 64-bit value Operand to the right by Count bits. The
1618 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1620 If Count is greater than 63, then ASSERT().
1622 @param Operand The 64-bit operand to shift right.
1623 @param Count The number of bits to shift right.
1625 @return Operand >> Count
1637 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1638 with the high bits that were rotated.
1640 This function rotates the 32-bit value Operand to the left by Count bits. The
1641 low Count bits are fill with the high Count bits of Operand. The rotated
1644 If Count is greater than 31, then ASSERT().
1646 @param Operand The 32-bit operand to rotate left.
1647 @param Count The number of bits to rotate left.
1649 @return Operand <<< Count
1661 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1662 with the low bits that were rotated.
1664 This function rotates the 32-bit value Operand to the right by Count bits.
1665 The high Count bits are fill with the low Count bits of Operand. The rotated
1668 If Count is greater than 31, then ASSERT().
1670 @param Operand The 32-bit operand to rotate right.
1671 @param Count The number of bits to rotate right.
1673 @return Operand >>> Count
1685 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1686 with the high bits that were rotated.
1688 This function rotates the 64-bit value Operand to the left by Count bits. The
1689 low Count bits are fill with the high Count bits of Operand. The rotated
1692 If Count is greater than 63, then ASSERT().
1694 @param Operand The 64-bit operand to rotate left.
1695 @param Count The number of bits to rotate left.
1697 @return Operand <<< Count
1709 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1710 with the high low bits that were rotated.
1712 This function rotates the 64-bit value Operand to the right by Count bits.
1713 The high Count bits are fill with the low Count bits of Operand. The rotated
1716 If Count is greater than 63, then ASSERT().
1718 @param Operand The 64-bit operand to rotate right.
1719 @param Count The number of bits to rotate right.
1721 @return Operand >>> Count
1733 Returns the bit position of the lowest bit set in a 32-bit value.
1735 This function computes the bit position of the lowest bit set in the 32-bit
1736 value specified by Operand. If Operand is zero, then -1 is returned.
1737 Otherwise, a value between 0 and 31 is returned.
1739 @param Operand The 32-bit operand to evaluate.
1741 @return Position of the lowest bit set in Operand if found.
1742 @retval -1 Operand is zero.
1753 Returns the bit position of the lowest bit set in a 64-bit value.
1755 This function computes the bit position of the lowest bit set in the 64-bit
1756 value specified by Operand. If Operand is zero, then -1 is returned.
1757 Otherwise, a value between 0 and 63 is returned.
1759 @param Operand The 64-bit operand to evaluate.
1761 @return Position of the lowest bit set in Operand if found.
1762 @retval -1 Operand is zero.
1773 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1776 This function computes the bit position of the highest bit set in the 32-bit
1777 value specified by Operand. If Operand is zero, then -1 is returned.
1778 Otherwise, a value between 0 and 31 is returned.
1780 @param Operand The 32-bit operand to evaluate.
1782 @return Position of the highest bit set in Operand if found.
1783 @retval -1 Operand is zero.
1794 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1797 This function computes the bit position of the highest bit set in the 64-bit
1798 value specified by Operand. If Operand is zero, then -1 is returned.
1799 Otherwise, a value between 0 and 63 is returned.
1801 @param Operand The 64-bit operand to evaluate.
1803 @return Position of the highest bit set in Operand if found.
1804 @retval -1 Operand is zero.
1815 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1816 1 << HighBitSet32(x).
1818 This function computes the value of the highest bit set in the 32-bit value
1819 specified by Operand. If Operand is zero, then zero is returned.
1821 @param Operand The 32-bit operand to evaluate.
1823 @return 1 << HighBitSet32(Operand)
1824 @retval 0 Operand is zero.
1835 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1836 1 << HighBitSet64(x).
1838 This function computes the value of the highest bit set in the 64-bit value
1839 specified by Operand. If Operand is zero, then zero is returned.
1841 @param Operand The 64-bit operand to evaluate.
1843 @return 1 << HighBitSet64(Operand)
1844 @retval 0 Operand is zero.
1855 Switches the endianess of a 16-bit integer.
1857 This function swaps the bytes in a 16-bit unsigned value to switch the value
1858 from little endian to big endian or vice versa. The byte swapped value is
1861 @param Operand A 16-bit unsigned value.
1863 @return The byte swaped Operand.
1874 Switches the endianess of a 32-bit integer.
1876 This function swaps the bytes in a 32-bit unsigned value to switch the value
1877 from little endian to big endian or vice versa. The byte swapped value is
1880 @param Operand A 32-bit unsigned value.
1882 @return The byte swaped Operand.
1893 Switches the endianess of a 64-bit integer.
1895 This function swaps the bytes in a 64-bit unsigned value to switch the value
1896 from little endian to big endian or vice versa. The byte swapped value is
1899 @param Operand A 64-bit unsigned value.
1901 @return The byte swaped Operand.
1912 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1913 generates a 64-bit unsigned result.
1915 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1916 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1917 bit unsigned result is returned.
1919 If the result overflows, then ASSERT().
1921 @param Multiplicand A 64-bit unsigned value.
1922 @param Multiplier A 32-bit unsigned value.
1924 @return Multiplicand * Multiplier
1930 IN UINT64 Multiplicand
,
1931 IN UINT32 Multiplier
1936 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1937 generates a 64-bit unsigned result.
1939 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1940 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1941 bit unsigned result is returned.
1943 If the result overflows, then ASSERT().
1945 @param Multiplicand A 64-bit unsigned value.
1946 @param Multiplier A 64-bit unsigned value.
1948 @return Multiplicand * Multiplier
1954 IN UINT64 Multiplicand
,
1955 IN UINT64 Multiplier
1960 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1961 64-bit signed result.
1963 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1964 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1965 signed result is returned.
1967 If the result overflows, then ASSERT().
1969 @param Multiplicand A 64-bit signed value.
1970 @param Multiplier A 64-bit signed value.
1972 @return Multiplicand * Multiplier
1978 IN INT64 Multiplicand
,
1984 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1985 a 64-bit unsigned result.
1987 This function divides the 64-bit unsigned value Dividend by the 32-bit
1988 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1989 function returns the 64-bit unsigned quotient.
1991 If Divisor is 0, then ASSERT().
1993 @param Dividend A 64-bit unsigned value.
1994 @param Divisor A 32-bit unsigned value.
1996 @return Dividend / Divisor
2008 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
2009 a 32-bit unsigned remainder.
2011 This function divides the 64-bit unsigned value Dividend by the 32-bit
2012 unsigned value Divisor and generates a 32-bit remainder. This function
2013 returns the 32-bit unsigned remainder.
2015 If Divisor is 0, then ASSERT().
2017 @param Dividend A 64-bit unsigned value.
2018 @param Divisor A 32-bit unsigned value.
2020 @return Dividend % Divisor
2032 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
2033 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
2035 This function divides the 64-bit unsigned value Dividend by the 32-bit
2036 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2037 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
2038 This function returns the 64-bit unsigned quotient.
2040 If Divisor is 0, then ASSERT().
2042 @param Dividend A 64-bit unsigned value.
2043 @param Divisor A 32-bit unsigned value.
2044 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
2045 optional and may be NULL.
2047 @return Dividend / Divisor
2052 DivU64x32Remainder (
2055 OUT UINT32
*Remainder OPTIONAL
2060 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
2061 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
2063 This function divides the 64-bit unsigned value Dividend by the 64-bit
2064 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2065 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
2066 This function returns the 64-bit unsigned quotient.
2068 If Divisor is 0, then ASSERT().
2070 @param Dividend A 64-bit unsigned value.
2071 @param Divisor A 64-bit unsigned value.
2072 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
2073 optional and may be NULL.
2075 @return Dividend / Divisor
2080 DivU64x64Remainder (
2083 OUT UINT64
*Remainder OPTIONAL
2088 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
2089 64-bit signed result and a optional 64-bit signed remainder.
2091 This function divides the 64-bit signed value Dividend by the 64-bit signed
2092 value Divisor and generates a 64-bit signed quotient. If Remainder is not
2093 NULL, then the 64-bit signed remainder is returned in Remainder. This
2094 function returns the 64-bit signed quotient.
2096 If Divisor is 0, then ASSERT().
2098 @param Dividend A 64-bit signed value.
2099 @param Divisor A 64-bit signed value.
2100 @param Remainder A pointer to a 64-bit signed value. This parameter is
2101 optional and may be NULL.
2103 @return Dividend / Divisor
2108 DivS64x64Remainder (
2111 OUT INT64
*Remainder OPTIONAL
2116 Reads a 16-bit value from memory that may be unaligned.
2118 This function returns the 16-bit value pointed to by Buffer. The function
2119 guarantees that the read operation does not produce an alignment fault.
2121 If the Buffer is NULL, then ASSERT().
2123 @param Buffer Pointer to a 16-bit value that may be unaligned.
2131 IN CONST UINT16
*Uint16
2136 Writes a 16-bit value to memory that may be unaligned.
2138 This function writes the 16-bit value specified by Value to Buffer. Value is
2139 returned. The function guarantees that the write operation does not produce
2142 If the Buffer is NULL, then ASSERT().
2144 @param Buffer Pointer to a 16-bit value that may be unaligned.
2145 @param Value 16-bit value to write to Buffer.
2159 Reads a 24-bit value from memory that may be unaligned.
2161 This function returns the 24-bit value pointed to by Buffer. The function
2162 guarantees that the read operation does not produce an alignment fault.
2164 If the Buffer is NULL, then ASSERT().
2166 @param Buffer Pointer to a 24-bit value that may be unaligned.
2168 @return The value read.
2174 IN CONST UINT32
*Buffer
2179 Writes a 24-bit value to memory that may be unaligned.
2181 This function writes the 24-bit value specified by Value to Buffer. Value is
2182 returned. The function guarantees that the write operation does not produce
2185 If the Buffer is NULL, then ASSERT().
2187 @param Buffer Pointer to a 24-bit value that may be unaligned.
2188 @param Value 24-bit value to write to Buffer.
2190 @return The value written.
2202 Reads a 32-bit value from memory that may be unaligned.
2204 This function returns the 32-bit value pointed to by Buffer. The function
2205 guarantees that the read operation does not produce an alignment fault.
2207 If the Buffer is NULL, then ASSERT().
2209 @param Buffer Pointer to a 32-bit value that may be unaligned.
2217 IN CONST UINT32
*Uint32
2222 Writes a 32-bit value to memory that may be unaligned.
2224 This function writes the 32-bit value specified by Value to Buffer. Value is
2225 returned. The function guarantees that the write operation does not produce
2228 If the Buffer is NULL, then ASSERT().
2230 @param Buffer Pointer to a 32-bit value that may be unaligned.
2231 @param Value 32-bit value to write to Buffer.
2245 Reads a 64-bit value from memory that may be unaligned.
2247 This function returns the 64-bit value pointed to by Buffer. The function
2248 guarantees that the read operation does not produce an alignment fault.
2250 If the Buffer is NULL, then ASSERT().
2252 @param Buffer Pointer to a 64-bit value that may be unaligned.
2260 IN CONST UINT64
*Uint64
2265 Writes a 64-bit value to memory that may be unaligned.
2267 This function writes the 64-bit value specified by Value to Buffer. Value is
2268 returned. The function guarantees that the write operation does not produce
2271 If the Buffer is NULL, then ASSERT().
2273 @param Buffer Pointer to a 64-bit value that may be unaligned.
2274 @param Value 64-bit value to write to Buffer.
2288 // Bit Field Functions
2292 Returns a bit field from an 8-bit value.
2294 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2296 If 8-bit operations are not supported, then ASSERT().
2297 If StartBit is greater than 7, then ASSERT().
2298 If EndBit is greater than 7, then ASSERT().
2299 If EndBit is less than StartBit, then ASSERT().
2301 @param Operand Operand on which to perform the bitfield operation.
2302 @param StartBit The ordinal of the least significant bit in the bit field.
2304 @param EndBit The ordinal of the most significant bit in the bit field.
2307 @return The bit field read.
2320 Writes a bit field to an 8-bit value, and returns the result.
2322 Writes Value to the bit field specified by the StartBit and the EndBit in
2323 Operand. All other bits in Operand are preserved. The new 8-bit value is
2326 If 8-bit operations are not supported, then ASSERT().
2327 If StartBit is greater than 7, then ASSERT().
2328 If EndBit is greater than 7, then ASSERT().
2329 If EndBit is less than StartBit, then ASSERT().
2331 @param Operand Operand on which to perform the bitfield operation.
2332 @param StartBit The ordinal of the least significant bit in the bit field.
2334 @param EndBit The ordinal of the most significant bit in the bit field.
2336 @param Value New value of the bit field.
2338 @return The new 8-bit value.
2352 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
2355 Performs a bitwise inclusive OR between the bit field specified by StartBit
2356 and EndBit in Operand and the value specified by OrData. All other bits in
2357 Operand are preserved. The new 8-bit value is returned.
2359 If 8-bit operations are not supported, then ASSERT().
2360 If StartBit is greater than 7, then ASSERT().
2361 If EndBit is greater than 7, then ASSERT().
2362 If EndBit is less than StartBit, then ASSERT().
2364 @param Operand Operand on which to perform the bitfield operation.
2365 @param StartBit The ordinal of the least significant bit in the bit field.
2367 @param EndBit The ordinal of the most significant bit in the bit field.
2369 @param OrData The value to OR with the read value from the value
2371 @return The new 8-bit value.
2385 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
2388 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2389 in Operand and the value specified by AndData. All other bits in Operand are
2390 preserved. The new 8-bit value is returned.
2392 If 8-bit operations are not supported, then ASSERT().
2393 If StartBit is greater than 7, then ASSERT().
2394 If EndBit is greater than 7, then ASSERT().
2395 If EndBit is less than StartBit, then ASSERT().
2397 @param Operand Operand on which to perform the bitfield operation.
2398 @param StartBit The ordinal of the least significant bit in the bit field.
2400 @param EndBit The ordinal of the most significant bit in the bit field.
2402 @param AndData The value to AND with the read value from the value.
2404 @return The new 8-bit value.
2418 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
2419 bitwise OR, and returns the result.
2421 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2422 in Operand and the value specified by AndData, followed by a bitwise
2423 inclusive OR with value specified by OrData. All other bits in Operand are
2424 preserved. The new 8-bit value is returned.
2426 If 8-bit operations are not supported, then ASSERT().
2427 If StartBit is greater than 7, then ASSERT().
2428 If EndBit is greater than 7, then ASSERT().
2429 If EndBit is less than StartBit, then ASSERT().
2431 @param Operand Operand on which to perform the bitfield operation.
2432 @param StartBit The ordinal of the least significant bit in the bit field.
2434 @param EndBit The ordinal of the most significant bit in the bit field.
2436 @param AndData The value to AND with the read value from the value.
2437 @param OrData The value to OR with the result of the AND operation.
2439 @return The new 8-bit value.
2444 BitFieldAndThenOr8 (
2454 Returns a bit field from a 16-bit value.
2456 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2458 If 16-bit operations are not supported, then ASSERT().
2459 If StartBit is greater than 15, then ASSERT().
2460 If EndBit is greater than 15, then ASSERT().
2461 If EndBit is less than StartBit, then ASSERT().
2463 @param Operand Operand on which to perform the bitfield operation.
2464 @param StartBit The ordinal of the least significant bit in the bit field.
2466 @param EndBit The ordinal of the most significant bit in the bit field.
2469 @return The bit field read.
2482 Writes a bit field to a 16-bit value, and returns the result.
2484 Writes Value to the bit field specified by the StartBit and the EndBit in
2485 Operand. All other bits in Operand are preserved. The new 16-bit value is
2488 If 16-bit operations are not supported, then ASSERT().
2489 If StartBit is greater than 15, then ASSERT().
2490 If EndBit is greater than 15, then ASSERT().
2491 If EndBit is less than StartBit, then ASSERT().
2493 @param Operand Operand on which to perform the bitfield operation.
2494 @param StartBit The ordinal of the least significant bit in the bit field.
2496 @param EndBit The ordinal of the most significant bit in the bit field.
2498 @param Value New value of the bit field.
2500 @return The new 16-bit value.
2514 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
2517 Performs a bitwise inclusive OR between the bit field specified by StartBit
2518 and EndBit in Operand and the value specified by OrData. All other bits in
2519 Operand are preserved. The new 16-bit value is returned.
2521 If 16-bit operations are not supported, then ASSERT().
2522 If StartBit is greater than 15, then ASSERT().
2523 If EndBit is greater than 15, then ASSERT().
2524 If EndBit is less than StartBit, then ASSERT().
2526 @param Operand Operand on which to perform the bitfield operation.
2527 @param StartBit The ordinal of the least significant bit in the bit field.
2529 @param EndBit The ordinal of the most significant bit in the bit field.
2531 @param OrData The value to OR with the read value from the value
2533 @return The new 16-bit value.
2547 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
2550 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2551 in Operand and the value specified by AndData. All other bits in Operand are
2552 preserved. The new 16-bit value is returned.
2554 If 16-bit operations are not supported, then ASSERT().
2555 If StartBit is greater than 15, then ASSERT().
2556 If EndBit is greater than 15, then ASSERT().
2557 If EndBit is less than StartBit, then ASSERT().
2559 @param Operand Operand on which to perform the bitfield operation.
2560 @param StartBit The ordinal of the least significant bit in the bit field.
2562 @param EndBit The ordinal of the most significant bit in the bit field.
2564 @param AndData The value to AND with the read value from the value
2566 @return The new 16-bit value.
2580 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
2581 bitwise OR, and returns the result.
2583 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2584 in Operand and the value specified by AndData, followed by a bitwise
2585 inclusive OR with value specified by OrData. All other bits in Operand are
2586 preserved. The new 16-bit value is returned.
2588 If 16-bit operations are not supported, then ASSERT().
2589 If StartBit is greater than 15, then ASSERT().
2590 If EndBit is greater than 15, then ASSERT().
2591 If EndBit is less than StartBit, then ASSERT().
2593 @param Operand Operand on which to perform the bitfield operation.
2594 @param StartBit The ordinal of the least significant bit in the bit field.
2596 @param EndBit The ordinal of the most significant bit in the bit field.
2598 @param AndData The value to AND with the read value from the value.
2599 @param OrData The value to OR with the result of the AND operation.
2601 @return The new 16-bit value.
2606 BitFieldAndThenOr16 (
2616 Returns a bit field from a 32-bit value.
2618 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2620 If 32-bit operations are not supported, then ASSERT().
2621 If StartBit is greater than 31, then ASSERT().
2622 If EndBit is greater than 31, then ASSERT().
2623 If EndBit is less than StartBit, then ASSERT().
2625 @param Operand Operand on which to perform the bitfield operation.
2626 @param StartBit The ordinal of the least significant bit in the bit field.
2628 @param EndBit The ordinal of the most significant bit in the bit field.
2631 @return The bit field read.
2644 Writes a bit field to a 32-bit value, and returns the result.
2646 Writes Value to the bit field specified by the StartBit and the EndBit in
2647 Operand. All other bits in Operand are preserved. The new 32-bit value is
2650 If 32-bit operations are not supported, then ASSERT().
2651 If StartBit is greater than 31, then ASSERT().
2652 If EndBit is greater than 31, then ASSERT().
2653 If EndBit is less than StartBit, then ASSERT().
2655 @param Operand Operand on which to perform the bitfield operation.
2656 @param StartBit The ordinal of the least significant bit in the bit field.
2658 @param EndBit The ordinal of the most significant bit in the bit field.
2660 @param Value New value of the bit field.
2662 @return The new 32-bit value.
2676 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2679 Performs a bitwise inclusive OR between the bit field specified by StartBit
2680 and EndBit in Operand and the value specified by OrData. All other bits in
2681 Operand are preserved. The new 32-bit value is returned.
2683 If 32-bit operations are not supported, then ASSERT().
2684 If StartBit is greater than 31, then ASSERT().
2685 If EndBit is greater than 31, then ASSERT().
2686 If EndBit is less than StartBit, then ASSERT().
2688 @param Operand Operand on which to perform the bitfield operation.
2689 @param StartBit The ordinal of the least significant bit in the bit field.
2691 @param EndBit The ordinal of the most significant bit in the bit field.
2693 @param OrData The value to OR with the read value from the value
2695 @return The new 32-bit value.
2709 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2712 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2713 in Operand and the value specified by AndData. All other bits in Operand are
2714 preserved. The new 32-bit value is returned.
2716 If 32-bit operations are not supported, then ASSERT().
2717 If StartBit is greater than 31, then ASSERT().
2718 If EndBit is greater than 31, then ASSERT().
2719 If EndBit is less than StartBit, then ASSERT().
2721 @param Operand Operand on which to perform the bitfield operation.
2722 @param StartBit The ordinal of the least significant bit in the bit field.
2724 @param EndBit The ordinal of the most significant bit in the bit field.
2726 @param AndData The value to AND with the read value from the value
2728 @return The new 32-bit value.
2742 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2743 bitwise OR, and returns the result.
2745 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2746 in Operand and the value specified by AndData, followed by a bitwise
2747 inclusive OR with value specified by OrData. All other bits in Operand are
2748 preserved. The new 32-bit value is returned.
2750 If 32-bit operations are not supported, then ASSERT().
2751 If StartBit is greater than 31, then ASSERT().
2752 If EndBit is greater than 31, then ASSERT().
2753 If EndBit is less than StartBit, then ASSERT().
2755 @param Operand Operand on which to perform the bitfield operation.
2756 @param StartBit The ordinal of the least significant bit in the bit field.
2758 @param EndBit The ordinal of the most significant bit in the bit field.
2760 @param AndData The value to AND with the read value from the value.
2761 @param OrData The value to OR with the result of the AND operation.
2763 @return The new 32-bit value.
2768 BitFieldAndThenOr32 (
2778 Returns a bit field from a 64-bit value.
2780 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2782 If 64-bit operations are not supported, then ASSERT().
2783 If StartBit is greater than 63, then ASSERT().
2784 If EndBit is greater than 63, then ASSERT().
2785 If EndBit is less than StartBit, then ASSERT().
2787 @param Operand Operand on which to perform the bitfield operation.
2788 @param StartBit The ordinal of the least significant bit in the bit field.
2790 @param EndBit The ordinal of the most significant bit in the bit field.
2793 @return The bit field read.
2806 Writes a bit field to a 64-bit value, and returns the result.
2808 Writes Value to the bit field specified by the StartBit and the EndBit in
2809 Operand. All other bits in Operand are preserved. The new 64-bit value is
2812 If 64-bit operations are not supported, then ASSERT().
2813 If StartBit is greater than 63, then ASSERT().
2814 If EndBit is greater than 63, then ASSERT().
2815 If EndBit is less than StartBit, then ASSERT().
2817 @param Operand Operand on which to perform the bitfield operation.
2818 @param StartBit The ordinal of the least significant bit in the bit field.
2820 @param EndBit The ordinal of the most significant bit in the bit field.
2822 @param Value New value of the bit field.
2824 @return The new 64-bit value.
2838 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2841 Performs a bitwise inclusive OR between the bit field specified by StartBit
2842 and EndBit in Operand and the value specified by OrData. All other bits in
2843 Operand are preserved. The new 64-bit value is returned.
2845 If 64-bit operations are not supported, then ASSERT().
2846 If StartBit is greater than 63, then ASSERT().
2847 If EndBit is greater than 63, then ASSERT().
2848 If EndBit is less than StartBit, then ASSERT().
2850 @param Operand Operand on which to perform the bitfield operation.
2851 @param StartBit The ordinal of the least significant bit in the bit field.
2853 @param EndBit The ordinal of the most significant bit in the bit field.
2855 @param OrData The value to OR with the read value from the value
2857 @return The new 64-bit value.
2871 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2874 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2875 in Operand and the value specified by AndData. All other bits in Operand are
2876 preserved. The new 64-bit value is returned.
2878 If 64-bit operations are not supported, then ASSERT().
2879 If StartBit is greater than 63, then ASSERT().
2880 If EndBit is greater than 63, then ASSERT().
2881 If EndBit is less than StartBit, then ASSERT().
2883 @param Operand Operand on which to perform the bitfield operation.
2884 @param StartBit The ordinal of the least significant bit in the bit field.
2886 @param EndBit The ordinal of the most significant bit in the bit field.
2888 @param AndData The value to AND with the read value from the value
2890 @return The new 64-bit value.
2904 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2905 bitwise OR, and returns the result.
2907 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2908 in Operand and the value specified by AndData, followed by a bitwise
2909 inclusive OR with value specified by OrData. All other bits in Operand are
2910 preserved. The new 64-bit value is returned.
2912 If 64-bit operations are not supported, then ASSERT().
2913 If StartBit is greater than 63, then ASSERT().
2914 If EndBit is greater than 63, then ASSERT().
2915 If EndBit is less than StartBit, then ASSERT().
2917 @param Operand Operand on which to perform the bitfield operation.
2918 @param StartBit The ordinal of the least significant bit in the bit field.
2920 @param EndBit The ordinal of the most significant bit in the bit field.
2922 @param AndData The value to AND with the read value from the value.
2923 @param OrData The value to OR with the result of the AND operation.
2925 @return The new 64-bit value.
2930 BitFieldAndThenOr64 (
2940 // Base Library Synchronization Functions
2944 Retrieves the architecture specific spin lock alignment requirements for
2945 optimal spin lock performance.
2947 This function retrieves the spin lock alignment requirements for optimal
2948 performance on a given CPU architecture. The spin lock alignment must be a
2949 power of two and is returned by this function. If there are no alignment
2950 requirements, then 1 must be returned. The spin lock synchronization
2951 functions must function correctly if the spin lock size and alignment values
2952 returned by this function are not used at all. These values are hints to the
2953 consumers of the spin lock synchronization functions to obtain optimal spin
2956 @return The architecture specific spin lock alignment.
2961 GetSpinLockProperties (
2967 Initializes a spin lock to the released state and returns the spin lock.
2969 This function initializes the spin lock specified by SpinLock to the released
2970 state, and returns SpinLock. Optimal performance can be achieved by calling
2971 GetSpinLockProperties() to determine the size and alignment requirements for
2974 If SpinLock is NULL, then ASSERT().
2976 @param SpinLock A pointer to the spin lock to initialize to the released
2984 InitializeSpinLock (
2985 IN SPIN_LOCK
*SpinLock
2990 Waits until a spin lock can be placed in the acquired state.
2992 This function checks the state of the spin lock specified by SpinLock. If
2993 SpinLock is in the released state, then this function places SpinLock in the
2994 acquired state and returns SpinLock. Otherwise, this function waits
2995 indefinitely for the spin lock to be released, and then places it in the
2996 acquired state and returns SpinLock. All state transitions of SpinLock must
2997 be performed using MP safe mechanisms.
2999 If SpinLock is NULL, then ASSERT().
3000 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3001 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
3002 PcdSpinLockTimeout microseconds, then ASSERT().
3004 @param SpinLock A pointer to the spin lock to place in the acquired state.
3012 IN SPIN_LOCK
*SpinLock
3017 Attempts to place a spin lock in the acquired state.
3019 This function checks the state of the spin lock specified by SpinLock. If
3020 SpinLock is in the released state, then this function places SpinLock in the
3021 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
3022 transitions of SpinLock must be performed using MP safe mechanisms.
3024 If SpinLock is NULL, then ASSERT().
3025 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3027 @param SpinLock A pointer to the spin lock to place in the acquired state.
3029 @retval TRUE SpinLock was placed in the acquired state.
3030 @retval FALSE SpinLock could not be acquired.
3035 AcquireSpinLockOrFail (
3036 IN SPIN_LOCK
*SpinLock
3041 Releases a spin lock.
3043 This function places the spin lock specified by SpinLock in the release state
3044 and returns SpinLock.
3046 If SpinLock is NULL, then ASSERT().
3047 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3049 @param SpinLock A pointer to the spin lock to release.
3057 IN SPIN_LOCK
*SpinLock
3062 Performs an atomic increment of an 32-bit unsigned integer.
3064 Performs an atomic increment of the 32-bit unsigned integer specified by
3065 Value and returns the incremented value. The increment operation must be
3066 performed using MP safe mechanisms. The state of the return value is not
3067 guaranteed to be MP safe.
3069 If Value is NULL, then ASSERT().
3071 @param Value A pointer to the 32-bit value to increment.
3073 @return The incremented value.
3078 InterlockedIncrement (
3084 Performs an atomic decrement of an 32-bit unsigned integer.
3086 Performs an atomic decrement of the 32-bit unsigned integer specified by
3087 Value and returns the decremented value. The decrement operation must be
3088 performed using MP safe mechanisms. The state of the return value is not
3089 guaranteed to be MP safe.
3091 If Value is NULL, then ASSERT().
3093 @param Value A pointer to the 32-bit value to decrement.
3095 @return The decremented value.
3100 InterlockedDecrement (
3106 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
3108 Performs an atomic compare exchange operation on the 32-bit unsigned integer
3109 specified by Value. If Value is equal to CompareValue, then Value is set to
3110 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
3111 then Value is returned. The compare exchange operation must be performed using
3114 If Value is NULL, then ASSERT().
3116 @param Value A pointer to the 32-bit value for the compare exchange
3118 @param CompareValue 32-bit value used in compare operation.
3119 @param ExchangeValue 32-bit value used in exchange operation.
3121 @return The original *Value before exchange.
3126 InterlockedCompareExchange32 (
3127 IN OUT UINT32
*Value
,
3128 IN UINT32 CompareValue
,
3129 IN UINT32 ExchangeValue
3134 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
3136 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
3137 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
3138 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
3139 The compare exchange operation must be performed using MP safe mechanisms.
3141 If Value is NULL, then ASSERT().
3143 @param Value A pointer to the 64-bit value for the compare exchange
3145 @param CompareValue 64-bit value used in compare operation.
3146 @param ExchangeValue 64-bit value used in exchange operation.
3148 @return The original *Value before exchange.
3153 InterlockedCompareExchange64 (
3154 IN OUT UINT64
*Value
,
3155 IN UINT64 CompareValue
,
3156 IN UINT64 ExchangeValue
3161 Performs an atomic compare exchange operation on a pointer value.
3163 Performs an atomic compare exchange operation on the pointer value specified
3164 by Value. If Value is equal to CompareValue, then Value is set to
3165 ExchangeValue and CompareValue is returned. If Value is not equal to
3166 CompareValue, then Value is returned. The compare exchange operation must be
3167 performed using MP safe mechanisms.
3169 If Value is NULL, then ASSERT().
3171 @param Value A pointer to the pointer value for the compare exchange
3173 @param CompareValue Pointer value used in compare operation.
3174 @param ExchangeValue Pointer value used in exchange operation.
3179 InterlockedCompareExchangePointer (
3180 IN OUT VOID
**Value
,
3181 IN VOID
*CompareValue
,
3182 IN VOID
*ExchangeValue
3187 // Base Library Checksum Functions
3191 Calculate the sum of all elements in a buffer in unit of UINT8.
3192 During calculation, the carry bits are dropped.
3194 This function calculates the sum of all elements in a buffer
3195 in unit of UINT8. The carry bits in result of addition are dropped.
3196 The result is returned as UINT8. If Length is Zero, then Zero is
3199 If Buffer is NULL, then ASSERT().
3200 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3202 @param Buffer Pointer to the buffer to carry out the sum operation.
3203 @param Length The size, in bytes, of Buffer .
3205 @return Sum The sum of Buffer with carry bits dropped during additions.
3211 IN CONST UINT8
*Buffer
,
3217 Returns the two's complement checksum of all elements in a buffer
3220 This function first calculates the sum of the 8-bit values in the
3221 buffer specified by Buffer and Length. The carry bits in the result
3222 of addition are dropped. Then, the two's complement of the sum is
3223 returned. If Length is 0, then 0 is returned.
3225 If Buffer is NULL, then ASSERT().
3226 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3229 @param Buffer Pointer to the buffer to carry out the checksum operation.
3230 @param Length The size, in bytes, of Buffer.
3232 @return Checksum The 2's complement checksum of Buffer.
3237 CalculateCheckSum8 (
3238 IN CONST UINT8
*Buffer
,
3244 Returns the sum of all elements in a buffer of 16-bit values. During
3245 calculation, the carry bits are dropped.
3247 This function calculates the sum of the 16-bit values in the buffer
3248 specified by Buffer and Length. The carry bits in result of addition are dropped.
3249 The 16-bit result is returned. If Length is 0, then 0 is returned.
3251 If Buffer is NULL, then ASSERT().
3252 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3253 If Length is not aligned on a 16-bit boundary, then ASSERT().
3254 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3256 @param Buffer Pointer to the buffer to carry out the sum operation.
3257 @param Length The size, in bytes, of Buffer.
3259 @return Sum The sum of Buffer with carry bits dropped during additions.
3265 IN CONST UINT16
*Buffer
,
3271 Returns the two's complement checksum of all elements in a buffer of
3274 This function first calculates the sum of the 16-bit values in the buffer
3275 specified by Buffer and Length. The carry bits in the result of addition
3276 are dropped. Then, the two's complement of the sum is returned. If Length
3277 is 0, then 0 is returned.
3279 If Buffer is NULL, then ASSERT().
3280 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3281 If Length is not aligned on a 16-bit boundary, then ASSERT().
3282 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3284 @param Buffer Pointer to the buffer to carry out the checksum operation.
3285 @param Length The size, in bytes, of Buffer.
3287 @return Checksum The 2's complement checksum of Buffer.
3292 CalculateCheckSum16 (
3293 IN CONST UINT16
*Buffer
,
3299 Returns the sum of all elements in a buffer of 32-bit values. During
3300 calculation, the carry bits are dropped.
3302 This function calculates the sum of the 32-bit values in the buffer
3303 specified by Buffer and Length. The carry bits in result of addition are dropped.
3304 The 32-bit result is returned. If Length is 0, then 0 is returned.
3306 If Buffer is NULL, then ASSERT().
3307 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3308 If Length is not aligned on a 32-bit boundary, then ASSERT().
3309 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3311 @param Buffer Pointer to the buffer to carry out the sum operation.
3312 @param Length The size, in bytes, of Buffer.
3314 @return Sum The sum of Buffer with carry bits dropped during additions.
3320 IN CONST UINT32
*Buffer
,
3326 Returns the two's complement checksum of all elements in a buffer of
3329 This function first calculates the sum of the 32-bit values in the buffer
3330 specified by Buffer and Length. The carry bits in the result of addition
3331 are dropped. Then, the two's complement of the sum is returned. If Length
3332 is 0, then 0 is returned.
3334 If Buffer is NULL, then ASSERT().
3335 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3336 If Length is not aligned on a 32-bit boundary, then ASSERT().
3337 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3339 @param Buffer Pointer to the buffer to carry out the checksum operation.
3340 @param Length The size, in bytes, of Buffer.
3342 @return Checksum The 2's complement checksum of Buffer.
3347 CalculateCheckSum32 (
3348 IN CONST UINT32
*Buffer
,
3354 Returns the sum of all elements in a buffer of 64-bit values. During
3355 calculation, the carry bits are dropped.
3357 This function calculates the sum of the 64-bit values in the buffer
3358 specified by Buffer and Length. The carry bits in result of addition are dropped.
3359 The 64-bit result is returned. If Length is 0, then 0 is returned.
3361 If Buffer is NULL, then ASSERT().
3362 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3363 If Length is not aligned on a 64-bit boundary, then ASSERT().
3364 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3366 @param Buffer Pointer to the buffer to carry out the sum operation.
3367 @param Length The size, in bytes, of Buffer.
3369 @return Sum The sum of Buffer with carry bits dropped during additions.
3375 IN CONST UINT64
*Buffer
,
3381 Returns the two's complement checksum of all elements in a buffer of
3384 This function first calculates the sum of the 64-bit values in the buffer
3385 specified by Buffer and Length. The carry bits in the result of addition
3386 are dropped. Then, the two's complement of the sum is returned. If Length
3387 is 0, then 0 is returned.
3389 If Buffer is NULL, then ASSERT().
3390 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3391 If Length is not aligned on a 64-bit boundary, then ASSERT().
3392 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3394 @param Buffer Pointer to the buffer to carry out the checksum operation.
3395 @param Length The size, in bytes, of Buffer.
3397 @return Checksum The 2's complement checksum of Buffer.
3402 CalculateCheckSum64 (
3403 IN CONST UINT64
*Buffer
,
3409 // Base Library CPU Functions
3413 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
3414 IN VOID
*Context1
, OPTIONAL
3415 IN VOID
*Context2 OPTIONAL
3420 Used to serialize load and store operations.
3422 All loads and stores that proceed calls to this function are guaranteed to be
3423 globally visible when this function returns.
3434 Saves the current CPU context that can be restored with a call to LongJump()
3437 Saves the current CPU context in the buffer specified by JumpBuffer and
3438 returns 0. The initial call to SetJump() must always return 0. Subsequent
3439 calls to LongJump() cause a non-zero value to be returned by SetJump().
3441 If JumpBuffer is NULL, then ASSERT().
3442 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3444 @param JumpBuffer A pointer to CPU context buffer.
3446 @retval 0 Indicates a return from SetJump().
3452 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
3457 Restores the CPU context that was saved with SetJump().
3459 Restores the CPU context from the buffer specified by JumpBuffer. This
3460 function never returns to the caller. Instead is resumes execution based on
3461 the state of JumpBuffer.
3463 If JumpBuffer is NULL, then ASSERT().
3464 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3465 If Value is 0, then ASSERT().
3467 @param JumpBuffer A pointer to CPU context buffer.
3468 @param Value The value to return when the SetJump() context is
3469 restored and must be non-zero.
3475 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
3481 Enables CPU interrupts.
3483 Enables CPU interrupts.
3494 Disables CPU interrupts.
3496 Disables CPU interrupts.
3507 Disables CPU interrupts and returns the interrupt state prior to the disable
3510 Disables CPU interrupts and returns the interrupt state prior to the disable
3513 @retval TRUE CPU interrupts were enabled on entry to this call.
3514 @retval FALSE CPU interrupts were disabled on entry to this call.
3519 SaveAndDisableInterrupts (
3525 Enables CPU interrupts for the smallest window required to capture any
3528 Enables CPU interrupts for the smallest window required to capture any
3534 EnableDisableInterrupts (
3540 Retrieves the current CPU interrupt state.
3542 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
3543 currently enabled. Otherwise returns FALSE.
3545 @retval TRUE CPU interrupts are enabled.
3546 @retval FALSE CPU interrupts are disabled.
3551 GlueGetInterruptState (
3557 Set the current CPU interrupt state.
3559 Sets the current CPU interrupt state to the state specified by
3560 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
3561 InterruptState is FALSE, then interrupts are disabled. InterruptState is
3564 @param InterruptState TRUE if interrupts should enabled. FALSE if
3565 interrupts should be disabled.
3567 @return InterruptState
3573 IN BOOLEAN InterruptState
3578 Places the CPU in a sleep state until an interrupt is received.
3580 Places the CPU in a sleep state until an interrupt is received. If interrupts
3581 are disabled prior to calling this function, then the CPU will be placed in a
3582 sleep state indefinitely.
3593 Requests CPU to pause for a short period of time.
3595 Requests CPU to pause for a short period of time. Typically used in MP
3596 systems to prevent memory starvation while waiting for a spin lock.
3607 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3609 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3620 Transfers control to a function starting with a new stack.
3622 Transfers control to the function specified by EntryPoint using the
3623 new stack specified by NewStack and passing in the parameters specified
3624 by Context1 and Context2. Context1 and Context2 are optional and may
3625 be NULL. The function EntryPoint must never return. This function
3626 supports a variable number of arguments following the NewStack parameter.
3627 These additional arguments are ignored on IA-32, x64, and EBC.
3628 IPF CPUs expect one additional parameter of type VOID * that specifies
3629 the new backing store pointer.
3631 If EntryPoint is NULL, then ASSERT().
3632 If NewStack is NULL, then ASSERT().
3634 @param EntryPoint A pointer to function to call with the new stack.
3635 @param Context1 A pointer to the context to pass into the EntryPoint
3637 @param Context2 A pointer to the context to pass into the EntryPoint
3639 @param NewStack A pointer to the new stack to use for the EntryPoint
3646 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
3647 IN VOID
*Context1
, OPTIONAL
3648 IN VOID
*Context2
, OPTIONAL
3655 Generates a breakpoint on the CPU.
3657 Generates a breakpoint on the CPU. The breakpoint must be implemented such
3658 that code can resume normal execution after the breakpoint.
3669 Executes an infinite loop.
3671 Forces the CPU to execute an infinite loop. A debugger may be used to skip
3672 past the loop and the code that follows the loop must execute properly. This
3673 implies that the infinite loop must not cause the code that follow it to be
3684 #if defined (MDE_CPU_IPF)
3687 Flush a range of cache lines in the cache coherency domain of the calling
3690 Invalidates the cache lines specified by Address and Length. If Address is
3691 not aligned on a cache line boundary, then entire cache line containing
3692 Address is invalidated. If Address + Length is not aligned on a cache line
3693 boundary, then the entire instruction cache line containing Address + Length
3694 -1 is invalidated. This function may choose to invalidate the entire
3695 instruction cache if that is more efficient than invalidating the specified
3696 range. If Length is 0, the no instruction cache lines are invalidated.
3697 Address is returned.
3699 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
3701 @param Address The base address of the instruction lines to invalidate. If
3702 the CPU is in a physical addressing mode, then Address is a
3703 physical address. If the CPU is in a virtual addressing mode,
3704 then Address is a virtual address.
3706 @param Length The number of bytes to invalidate from the instruction cache.
3713 IpfFlushCacheRange (
3720 Executes a FC instruction
3721 Executes a FC instruction on the cache line specified by Address.
3722 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3723 An implementation may flush a larger region. This function is only available on IPF.
3725 @param Address The Address of cache line to be flushed.
3727 @return The address of FC instruction executed.
3738 Executes a FC.I instruction.
3739 Executes a FC.I instruction on the cache line specified by Address.
3740 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3741 An implementation may flush a larger region. This function is only available on IPF.
3743 @param Address The Address of cache line to be flushed.
3745 @return The address of FC.I instruction executed.
3756 Reads the current value of a Processor Identifier Register (CPUID).
3757 The Index of largest implemented CPUID (One less than the number of implemented CPUID
3758 registers) is determined by CPUID [3] bits {7:0}.
3759 No parameter checking is performed on Index. If the Index value is beyond the
3760 implemented CPUID register range, a Reserved Register/Field fault may occur. The caller
3761 must either guarantee that Index is valid, or the caller must set up fault handlers to
3762 catch the faults. This function is only available on IPF.
3764 @param Index The 8-bit Processor Identifier Register index to read.
3766 @return The current value of Processor Identifier Register specified by Index.
3777 Reads the current value of 64-bit Processor Status Register (PSR).
3778 This function is only available on IPF.
3780 @return The current value of PSR.
3791 Writes the current value of 64-bit Processor Status Register (PSR).
3792 No parameter checking is performed on Value. All bits of Value corresponding to
3793 reserved fields of PSR must be 0 or a Reserved Register/Field fault may occur. The caller must either guarantee that Value is valid, or the caller must set up fault handlers to catch the faults.
3794 This function is only available on IPF.
3796 @param Value The 64-bit value to write to PSR.
3798 @return The 64-bit value written to the PSR.
3809 Reads the current value of 64-bit Kernel Register #0 (KR0).
3810 This function is only available on IPF.
3812 @return The current value of KR0.
3823 Reads the current value of 64-bit Kernel Register #1 (KR1).
3824 This function is only available on IPF.
3826 @return The current value of KR1.
3837 Reads the current value of 64-bit Kernel Register #2 (KR2).
3838 This function is only available on IPF.
3840 @return The current value of KR2.
3851 Reads the current value of 64-bit Kernel Register #3 (KR3).
3852 This function is only available on IPF.
3854 @return The current value of KR3.
3865 Reads the current value of 64-bit Kernel Register #4 (KR4).
3866 This function is only available on IPF.
3868 @return The current value of KR4.
3879 Reads the current value of 64-bit Kernel Register #5 (KR5).
3880 This function is only available on IPF.
3882 @return The current value of KR5.
3893 Reads the current value of 64-bit Kernel Register #6 (KR6).
3894 This function is only available on IPF.
3896 @return The current value of KR6.
3907 Reads the current value of 64-bit Kernel Register #7 (KR7).
3908 This function is only available on IPF.
3910 @return The current value of KR7.
3921 Write the current value of 64-bit Kernel Register #0 (KR0).
3922 This function is only available on IPF.
3924 @param Value The 64-bit value to write to KR0.
3926 @return The 64-bit value written to the KR0.
3937 Write the current value of 64-bit Kernel Register #1 (KR1).
3938 This function is only available on IPF.
3940 @param Value The 64-bit value to write to KR1.
3942 @return The 64-bit value written to the KR1.
3953 Write the current value of 64-bit Kernel Register #2 (KR2).
3954 This function is only available on IPF.
3956 @param Value The 64-bit value to write to KR2.
3958 @return The 64-bit value written to the KR2.
3969 Write the current value of 64-bit Kernel Register #3 (KR3).
3970 This function is only available on IPF.
3972 @param Value The 64-bit value to write to KR3.
3974 @return The 64-bit value written to the KR3.
3985 Write the current value of 64-bit Kernel Register #4 (KR4).
3986 This function is only available on IPF.
3988 @param Value The 64-bit value to write to KR4.
3990 @return The 64-bit value written to the KR4.
4001 Write the current value of 64-bit Kernel Register #5 (KR5).
4002 This function is only available on IPF.
4004 @param Value The 64-bit value to write to KR5.
4006 @return The 64-bit value written to the KR5.
4017 Write the current value of 64-bit Kernel Register #6 (KR6).
4018 This function is only available on IPF.
4020 @param Value The 64-bit value to write to KR6.
4022 @return The 64-bit value written to the KR6.
4033 Write the current value of 64-bit Kernel Register #7 (KR7).
4034 This function is only available on IPF.
4036 @param Value The 64-bit value to write to KR7.
4038 @return The 64-bit value written to the KR7.
4049 Reads the current value of Interval Timer Counter Register (ITC).
4050 This function is only available on IPF.
4052 @return The current value of ITC.
4063 Reads the current value of Interval Timer Vector Register (ITV).
4064 This function is only available on IPF.
4066 @return The current value of ITV.
4077 Reads the current value of Interval Timer Match Register (ITM).
4078 This function is only available on IPF.
4080 @return The current value of ITM.
4090 Writes the current value of 64-bit Interval Timer Counter Register (ITC).
4091 This function is only available on IPF.
4093 @param Value The 64-bit value to write to ITC.
4095 @return The 64-bit value written to the ITC.
4106 Writes the current value of 64-bit Interval Timer Match Register (ITM).
4107 This function is only available on IPF.
4109 @param Value The 64-bit value to write to ITM.
4111 @return The 64-bit value written to the ITM.
4122 Writes the current value of 64-bit Interval Timer Vector Register (ITV).
4123 No parameter checking is performed on Value. All bits of Value corresponding to
4124 reserved fields of ITV must be 0 or a Reserved Register/Field fault may occur.
4125 The caller must either guarantee that Value is valid, or the caller must set up
4126 fault handlers to catch the faults.
4127 This function is only available on IPF.
4129 @param Value The 64-bit value to write to ITV.
4131 @return The 64-bit value written to the ITV.
4142 Reads the current value of Default Control Register (DCR).
4143 This function is only available on IPF.
4145 @return The current value of DCR.
4156 Reads the current value of Interruption Vector Address Register (IVA).
4157 This function is only available on IPF.
4159 @return The current value of IVA.
4169 Reads the current value of Page Table Address Register (PTA).
4170 This function is only available on IPF.
4172 @return The current value of PTA.
4183 Writes the current value of 64-bit Default Control Register (DCR).
4184 No parameter checking is performed on Value. All bits of Value corresponding to
4185 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4186 The caller must either guarantee that Value is valid, or the caller must set up
4187 fault handlers to catch the faults.
4188 This function is only available on IPF.
4190 @param Value The 64-bit value to write to DCR.
4192 @return The 64-bit value written to the DCR.
4203 Writes the current value of 64-bit Interruption Vector Address Register (IVA).
4204 The size of vector table is 32 K bytes and is 32 K bytes aligned
4205 the low 15 bits of Value is ignored when written.
4206 This function is only available on IPF.
4208 @param Value The 64-bit value to write to IVA.
4210 @return The 64-bit value written to the IVA.
4221 Writes the current value of 64-bit Page Table Address Register (PTA).
4222 No parameter checking is performed on Value. All bits of Value corresponding to
4223 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4224 The caller must either guarantee that Value is valid, or the caller must set up
4225 fault handlers to catch the faults.
4226 This function is only available on IPF.
4228 @param Value The 64-bit value to write to PTA.
4230 @return The 64-bit value written to the PTA.
4240 Reads the current value of Local Interrupt ID Register (LID).
4241 This function is only available on IPF.
4243 @return The current value of LID.
4254 Reads the current value of External Interrupt Vector Register (IVR).
4255 This function is only available on IPF.
4257 @return The current value of IVR.
4268 Reads the current value of Task Priority Register (TPR).
4269 This function is only available on IPF.
4271 @return The current value of TPR.
4282 Reads the current value of External Interrupt Request Register #0 (IRR0).
4283 This function is only available on IPF.
4285 @return The current value of IRR0.
4296 Reads the current value of External Interrupt Request Register #1 (IRR1).
4297 This function is only available on IPF.
4299 @return The current value of IRR1.
4310 Reads the current value of External Interrupt Request Register #2 (IRR2).
4311 This function is only available on IPF.
4313 @return The current value of IRR2.
4324 Reads the current value of External Interrupt Request Register #3 (IRR3).
4325 This function is only available on IPF.
4327 @return The current value of IRR3.
4338 Reads the current value of Performance Monitor Vector Register (PMV).
4339 This function is only available on IPF.
4341 @return The current value of PMV.
4352 Reads the current value of Corrected Machine Check Vector Register (CMCV).
4353 This function is only available on IPF.
4355 @return The current value of CMCV.
4366 Reads the current value of Local Redirection Register #0 (LRR0).
4367 This function is only available on IPF.
4369 @return The current value of LRR0.
4380 Reads the current value of Local Redirection Register #1 (LRR1).
4381 This function is only available on IPF.
4383 @return The current value of LRR1.
4394 Writes the current value of 64-bit Page Local Interrupt ID Register (LID).
4395 No parameter checking is performed on Value. All bits of Value corresponding to
4396 reserved fields of LID must be 0 or a Reserved Register/Field fault may occur.
4397 The caller must either guarantee that Value is valid, or the caller must set up
4398 fault handlers to catch the faults.
4399 This function is only available on IPF.
4401 @param Value The 64-bit value to write to LID.
4403 @return The 64-bit value written to the LID.
4414 Writes the current value of 64-bit Task Priority Register (TPR).
4415 No parameter checking is performed on Value. All bits of Value corresponding to
4416 reserved fields of TPR must be 0 or a Reserved Register/Field fault may occur.
4417 The caller must either guarantee that Value is valid, or the caller must set up
4418 fault handlers to catch the faults.
4419 This function is only available on IPF.
4421 @param Value The 64-bit value to write to TPR.
4423 @return The 64-bit value written to the TPR.
4434 Performs a write operation on End OF External Interrupt Register (EOI).
4435 Writes a value of 0 to the EOI Register. This function is only available on IPF.
4446 Writes the current value of 64-bit Performance Monitor Vector Register (PMV).
4447 No parameter checking is performed on Value. All bits of Value corresponding
4448 to reserved fields of PMV must be 0 or a Reserved Register/Field fault may occur.
4449 The caller must either guarantee that Value is valid, or the caller must set up
4450 fault handlers to catch the faults.
4451 This function is only available on IPF.
4453 @param Value The 64-bit value to write to PMV.
4455 @return The 64-bit value written to the PMV.
4466 Writes the current value of 64-bit Corrected Machine Check Vector Register (CMCV).
4467 No parameter checking is performed on Value. All bits of Value corresponding
4468 to reserved fields of CMCV must be 0 or a Reserved Register/Field fault may occur.
4469 The caller must either guarantee that Value is valid, or the caller must set up
4470 fault handlers to catch the faults.
4471 This function is only available on IPF.
4473 @param Value The 64-bit value to write to CMCV.
4475 @return The 64-bit value written to the CMCV.
4486 Writes the current value of 64-bit Local Redirection Register #0 (LRR0).
4487 No parameter checking is performed on Value. All bits of Value corresponding
4488 to reserved fields of LRR0 must be 0 or a Reserved Register/Field fault may occur.
4489 The caller must either guarantee that Value is valid, or the caller must set up
4490 fault handlers to catch the faults.
4491 This function is only available on IPF.
4493 @param Value The 64-bit value to write to LRR0.
4495 @return The 64-bit value written to the LRR0.
4506 Writes the current value of 64-bit Local Redirection Register #1 (LRR1).
4507 No parameter checking is performed on Value. All bits of Value corresponding
4508 to reserved fields of LRR1 must be 0 or a Reserved Register/Field fault may occur.
4509 The caller must either guarantee that Value is valid, or the caller must
4510 set up fault handlers to catch the faults.
4511 This function is only available on IPF.
4513 @param Value The 64-bit value to write to LRR1.
4515 @return The 64-bit value written to the LRR1.
4526 Reads the current value of Instruction Breakpoint Register (IBR).
4528 The Instruction Breakpoint Registers are used in pairs. The even numbered
4529 registers contain breakpoint addresses, and the odd numbered registers contain
4530 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4531 on all processor models. Implemented registers are contiguous starting with
4532 register 0. No parameter checking is performed on Index, and if the Index value
4533 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4534 occur. The caller must either guarantee that Index is valid, or the caller must
4535 set up fault handlers to catch the faults.
4536 This function is only available on IPF.
4538 @param Index The 8-bit Instruction Breakpoint Register index to read.
4540 @return The current value of Instruction Breakpoint Register specified by Index.
4551 Reads the current value of Data Breakpoint Register (DBR).
4553 The Data Breakpoint Registers are used in pairs. The even numbered registers
4554 contain breakpoint addresses, and odd numbered registers contain breakpoint
4555 mask conditions. At least 4 data registers pairs are implemented on all processor
4556 models. Implemented registers are contiguous starting with register 0.
4557 No parameter checking is performed on Index. If the Index value is beyond
4558 the implemented DBR register range, a Reserved Register/Field fault may occur.
4559 The caller must either guarantee that Index is valid, or the caller must set up
4560 fault handlers to catch the faults.
4561 This function is only available on IPF.
4563 @param Index The 8-bit Data Breakpoint Register index to read.
4565 @return The current value of Data Breakpoint Register specified by Index.
4576 Reads the current value of Performance Monitor Configuration Register (PMC).
4578 All processor implementations provide at least 4 performance counters
4579 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4580 status registers (PMC [0]¡ PMC [3]). Processor implementations may provide
4581 additional implementation-dependent PMC and PMD to increase the number of
4582 ¡®generic¡¯ performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4583 register set is implementation dependent. No parameter checking is performed
4584 on Index. If the Index value is beyond the implemented PMC register range,
4585 zero value will be returned.
4586 This function is only available on IPF.
4588 @param Index The 8-bit Performance Monitor Configuration Register index to read.
4590 @return The current value of Performance Monitor Configuration Register
4602 Reads the current value of Performance Monitor Data Register (PMD).
4604 All processor implementations provide at least 4 performance counters
4605 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter
4606 overflow status registers (PMC [0]¡ PMC [3]). Processor implementations may
4607 provide additional implementation-dependent PMC and PMD to increase the number
4608 of ¡®generic¡¯ performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4609 register set is implementation dependent. No parameter checking is performed
4610 on Index. If the Index value is beyond the implemented PMD register range,
4611 zero value will be returned.
4612 This function is only available on IPF.
4614 @param Index The 8-bit Performance Monitor Data Register index to read.
4616 @return The current value of Performance Monitor Data Register specified by Index.
4627 Writes the current value of 64-bit Instruction Breakpoint Register (IBR).
4629 Writes current value of Instruction Breakpoint Register specified by Index.
4630 The Instruction Breakpoint Registers are used in pairs. The even numbered
4631 registers contain breakpoint addresses, and odd numbered registers contain
4632 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4633 on all processor models. Implemented registers are contiguous starting with
4634 register 0. No parameter checking is performed on Index. If the Index value
4635 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4636 occur. The caller must either guarantee that Index is valid, or the caller must
4637 set up fault handlers to catch the faults.
4638 This function is only available on IPF.
4640 @param Index The 8-bit Instruction Breakpoint Register index to write.
4641 @param Value The 64-bit value to write to IBR.
4643 @return The 64-bit value written to the IBR.
4655 Writes the current value of 64-bit Data Breakpoint Register (DBR).
4657 Writes current value of Data Breakpoint Register specified by Index.
4658 The Data Breakpoint Registers are used in pairs. The even numbered registers
4659 contain breakpoint addresses, and odd numbered registers contain breakpoint
4660 mask conditions. At least 4 data registers pairs are implemented on all processor
4661 models. Implemented registers are contiguous starting with register 0. No parameter
4662 checking is performed on Index. If the Index value is beyond the implemented
4663 DBR register range, a Reserved Register/Field fault may occur. The caller must
4664 either guarantee that Index is valid, or the caller must set up fault handlers to
4666 This function is only available on IPF.
4668 @param Index The 8-bit Data Breakpoint Register index to write.
4669 @param Value The 64-bit value to write to DBR.
4671 @return The 64-bit value written to the DBR.
4683 Writes the current value of 64-bit Performance Monitor Configuration Register (PMC).
4685 Writes current value of Performance Monitor Configuration Register specified by Index.
4686 All processor implementations provide at least 4 performance counters
4687 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow status
4688 registers (PMC [0]¡ PMC [3]). Processor implementations may provide additional
4689 implementation-dependent PMC and PMD to increase the number of ¡®generic¡¯ performance
4690 counters (PMC/PMD pairs). The remainder of PMC and PMD register set is implementation
4691 dependent. No parameter checking is performed on Index. If the Index value is
4692 beyond the implemented PMC register range, the write is ignored.
4693 This function is only available on IPF.
4695 @param Index The 8-bit Performance Monitor Configuration Register index to write.
4696 @param Value The 64-bit value to write to PMC.
4698 @return The 64-bit value written to the PMC.
4710 Writes the current value of 64-bit Performance Monitor Data Register (PMD).
4712 Writes current value of Performance Monitor Data Register specified by Index.
4713 All processor implementations provide at least 4 performance counters
4714 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4715 status registers (PMC [0]¡ PMC [3]). Processor implementations may provide
4716 additional implementation-dependent PMC and PMD to increase the number of ¡®generic¡¯
4717 performance counters (PMC/PMD pairs). The remainder of PMC and PMD register set
4718 is implementation dependent. No parameter checking is performed on Index. If the
4719 Index value is beyond the implemented PMD register range, the write is ignored.
4720 This function is only available on IPF.
4722 @param Index The 8-bit Performance Monitor Data Register index to write.
4723 @param Value The 64-bit value to write to PMD.
4725 @return The 64-bit value written to the PMD.
4737 Reads the current value of 64-bit Global Pointer (GP).
4739 Reads and returns the current value of GP.
4740 This function is only available on IPF.
4742 @return The current value of GP.
4753 Write the current value of 64-bit Global Pointer (GP).
4755 Writes the current value of GP. The 64-bit value written to the GP is returned.
4756 No parameter checking is performed on Value.
4757 This function is only available on IPF.
4759 @param Value The 64-bit value to write to GP.
4761 @return The 64-bit value written to the GP.
4772 Reads the current value of 64-bit Stack Pointer (SP).
4774 Reads and returns the current value of SP.
4775 This function is only available on IPF.
4777 @return The current value of SP.
4788 Determines if the CPU is currently executing in virtual, physical, or mixed mode.
4790 Determines the current execution mode of the CPU.
4791 If the CPU is in virtual mode(PSR.RT=1, PSR.DT=1, PSR.IT=1), then 1 is returned.
4792 If the CPU is in physical mode(PSR.RT=0, PSR.DT=0, PSR.IT=0), then 0 is returned.
4793 If the CPU is not in physical mode or virtual mode, then it is in mixed mode,
4795 This function is only available on IPF.
4797 @return 1 The CPU is in virtual mode.
4798 @return 0 The CPU is in physical mode.
4799 @return -1 The CPU is in mixed mode.
4810 Makes a PAL procedure call.
4812 This is a wrapper function to make a PAL procedure call. Based on the Index
4813 value this API will make static or stacked PAL call. The following table
4814 describes the usage of PAL Procedure Index Assignment. Architected procedures
4815 may be designated as required or optional. If a PAL procedure is specified
4816 as optional, a unique return code of 0xFFFFFFFFFFFFFFFF is returned in the
4817 Status field of the PAL_CALL_RETURN structure.
4818 This indicates that the procedure is not present in this PAL implementation.
4819 It is the caller¡¯s responsibility to check for this return code after calling
4820 any optional PAL procedure.
4821 No parameter checking is performed on the 5 input parameters, but there are
4822 some common rules that the caller should follow when making a PAL call. Any
4823 address passed to PAL as buffers for return parameters must be 8-byte aligned.
4824 Unaligned addresses may cause undefined results. For those parameters defined
4825 as reserved or some fields defined as reserved must be zero filled or the invalid
4826 argument return value may be returned or undefined result may occur during the
4827 execution of the procedure. If the PalEntryPoint does not point to a valid
4828 PAL entry point then the system behavior is undefined. This function is only
4831 @param PalEntryPoint The PAL procedure calls entry point.
4832 @param Index The PAL procedure Index number.
4833 @param Arg2 The 2nd parameter for PAL procedure calls.
4834 @param Arg3 The 3rd parameter for PAL procedure calls.
4835 @param Arg4 The 4th parameter for PAL procedure calls.
4837 @return structure returned from the PAL Call procedure, including the status and return value.
4843 IN UINT64 PalEntryPoint
,
4852 Transfers control to a function starting with a new stack.
4854 Transfers control to the function specified by EntryPoint using the new stack
4855 specified by NewStack and passing in the parameters specified by Context1 and
4856 Context2. Context1 and Context2 are optional and may be NULL. The function
4857 EntryPoint must never return.
4859 If EntryPoint is NULL, then ASSERT().
4860 If NewStack is NULL, then ASSERT().
4862 @param EntryPoint A pointer to function to call with the new stack.
4863 @param Context1 A pointer to the context to pass into the EntryPoint
4865 @param Context2 A pointer to the context to pass into the EntryPoint
4867 @param NewStack A pointer to the new stack to use for the EntryPoint
4869 @param NewBsp A pointer to the new memory location for RSE backing
4875 AsmSwitchStackAndBackingStore (
4876 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4877 IN VOID
*Context1
, OPTIONAL
4878 IN VOID
*Context2
, OPTIONAL
4885 // Bugbug: This call should be removed after
4886 // the PalCall Instance issue has been fixed.
4889 Performs a PAL call using static calling convention.
4891 An internal function to perform a PAL call using static calling convention.
4893 @param PalEntryPoint The entry point address of PAL. The address in ar.kr5
4894 would be used if this parameter were NULL on input.
4895 @param Arg1 The first argument of a PAL call.
4896 @param Arg1 The second argument of a PAL call.
4897 @param Arg1 The third argument of a PAL call.
4898 @param Arg1 The fourth argument of a PAL call.
4900 @return The values returned in r8, r9, r10 and r11.
4905 IN CONST VOID
*PalEntryPoint
,
4913 #elif defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
4915 // IA32 and X64 Specific Functions
4918 // Byte packed structure for 16-bit Real Mode EFLAGS
4922 UINT32 CF
:1; // Carry Flag
4923 UINT32 Reserved_0
:1; // Reserved
4924 UINT32 PF
:1; // Parity Flag
4925 UINT32 Reserved_1
:1; // Reserved
4926 UINT32 AF
:1; // Auxiliary Carry Flag
4927 UINT32 Reserved_2
:1; // Reserved
4928 UINT32 ZF
:1; // Zero Flag
4929 UINT32 SF
:1; // Sign Flag
4930 UINT32 TF
:1; // Trap Flag
4931 UINT32 IF
:1; // Interrupt Enable Flag
4932 UINT32 DF
:1; // Direction Flag
4933 UINT32 OF
:1; // Overflow Flag
4934 UINT32 IOPL
:2; // I/O Privilege Level
4935 UINT32 NT
:1; // Nested Task
4936 UINT32 Reserved_3
:1; // Reserved
4942 // Byte packed structure for EFLAGS/RFLAGS
4944 // 64-bits on X64. The upper 32-bits on X64 are reserved
4948 UINT32 CF
:1; // Carry Flag
4949 UINT32 Reserved_0
:1; // Reserved
4950 UINT32 PF
:1; // Parity Flag
4951 UINT32 Reserved_1
:1; // Reserved
4952 UINT32 AF
:1; // Auxiliary Carry Flag
4953 UINT32 Reserved_2
:1; // Reserved
4954 UINT32 ZF
:1; // Zero Flag
4955 UINT32 SF
:1; // Sign Flag
4956 UINT32 TF
:1; // Trap Flag
4957 UINT32 IF
:1; // Interrupt Enable Flag
4958 UINT32 DF
:1; // Direction Flag
4959 UINT32 OF
:1; // Overflow Flag
4960 UINT32 IOPL
:2; // I/O Privilege Level
4961 UINT32 NT
:1; // Nested Task
4962 UINT32 Reserved_3
:1; // Reserved
4963 UINT32 RF
:1; // Resume Flag
4964 UINT32 VM
:1; // Virtual 8086 Mode
4965 UINT32 AC
:1; // Alignment Check
4966 UINT32 VIF
:1; // Virtual Interrupt Flag
4967 UINT32 VIP
:1; // Virtual Interrupt Pending
4968 UINT32 ID
:1; // ID Flag
4969 UINT32 Reserved_4
:10; // Reserved
4975 // Byte packed structure for Control Register 0 (CR0)
4977 // 64-bits on X64. The upper 32-bits on X64 are reserved
4981 UINT32 PE
:1; // Protection Enable
4982 UINT32 MP
:1; // Monitor Coprocessor
4983 UINT32 EM
:1; // Emulation
4984 UINT32 TS
:1; // Task Switched
4985 UINT32 ET
:1; // Extension Type
4986 UINT32 NE
:1; // Numeric Error
4987 UINT32 Reserved_0
:10; // Reserved
4988 UINT32 WP
:1; // Write Protect
4989 UINT32 Reserved_1
:1; // Reserved
4990 UINT32 AM
:1; // Alignment Mask
4991 UINT32 Reserved_2
:10; // Reserved
4992 UINT32 NW
:1; // Mot Write-through
4993 UINT32 CD
:1; // Cache Disable
4994 UINT32 PG
:1; // Paging
5000 // Byte packed structure for Control Register 4 (CR4)
5002 // 64-bits on X64. The upper 32-bits on X64 are reserved
5006 UINT32 VME
:1; // Virtual-8086 Mode Extensions
5007 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
5008 UINT32 TSD
:1; // Time Stamp Disable
5009 UINT32 DE
:1; // Debugging Extensions
5010 UINT32 PSE
:1; // Page Size Extensions
5011 UINT32 PAE
:1; // Physical Address Extension
5012 UINT32 MCE
:1; // Machine Check Enable
5013 UINT32 PGE
:1; // Page Global Enable
5014 UINT32 PCE
:1; // Performance Monitoring Counter
5016 UINT32 OSFXSR
:1; // Operating System Support for
5017 // FXSAVE and FXRSTOR instructions
5018 UINT32 OSXMMEXCPT
:1; // Operating System Support for
5019 // Unmasked SIMD Floating Point
5021 UINT32 Reserved_0
:2; // Reserved
5022 UINT32 VMXE
:1; // VMX Enable
5023 UINT32 Reserved_1
:18; // Reseved
5029 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
5030 /// @bug How to make this structure byte-packed in a compiler independent way?
5039 #define IA32_IDT_GATE_TYPE_TASK 0x85
5040 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
5041 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
5042 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
5043 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
5046 // Byte packed structure for an Interrupt Gate Descriptor
5050 UINT32 OffsetLow
:16; // Offset bits 15..0
5051 UINT32 Selector
:16; // Selector
5052 UINT32 Reserved_0
:8; // Reserved
5053 UINT32 GateType
:8; // Gate Type. See #defines above
5054 UINT32 OffsetHigh
:16; // Offset bits 31..16
5057 } IA32_IDT_GATE_DESCRIPTOR
;
5060 // Byte packed structure for an FP/SSE/SSE2 context
5067 // Structures for the 16-bit real mode thunks
5120 IA32_EFLAGS32 EFLAGS
;
5130 } IA32_REGISTER_SET
;
5133 // Byte packed structure for an 16-bit real mode thunks
5136 IA32_REGISTER_SET
*RealModeState
;
5137 VOID
*RealModeBuffer
;
5138 UINT32 RealModeBufferSize
;
5139 UINT32 ThunkAttributes
;
5142 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
5143 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
5144 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
5147 Retrieves CPUID information.
5149 Executes the CPUID instruction with EAX set to the value specified by Index.
5150 This function always returns Index.
5151 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5152 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5153 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5154 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5155 This function is only available on IA-32 and X64.
5157 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
5159 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5160 instruction. This is an optional parameter that may be NULL.
5161 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5162 instruction. This is an optional parameter that may be NULL.
5163 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5164 instruction. This is an optional parameter that may be NULL.
5165 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5166 instruction. This is an optional parameter that may be NULL.
5175 OUT UINT32
*Eax
, OPTIONAL
5176 OUT UINT32
*Ebx
, OPTIONAL
5177 OUT UINT32
*Ecx
, OPTIONAL
5178 OUT UINT32
*Edx OPTIONAL
5183 Retrieves CPUID information using an extended leaf identifier.
5185 Executes the CPUID instruction with EAX set to the value specified by Index
5186 and ECX set to the value specified by SubIndex. This function always returns
5187 Index. This function is only available on IA-32 and x64.
5189 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5190 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5191 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5192 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5194 @param Index The 32-bit value to load into EAX prior to invoking the
5196 @param SubIndex The 32-bit value to load into ECX prior to invoking the
5198 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5199 instruction. This is an optional parameter that may be
5201 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5202 instruction. This is an optional parameter that may be
5204 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5205 instruction. This is an optional parameter that may be
5207 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5208 instruction. This is an optional parameter that may be
5219 OUT UINT32
*Eax
, OPTIONAL
5220 OUT UINT32
*Ebx
, OPTIONAL
5221 OUT UINT32
*Ecx
, OPTIONAL
5222 OUT UINT32
*Edx OPTIONAL
5227 Returns the lower 32-bits of a Machine Specific Register(MSR).
5229 Reads and returns the lower 32-bits of the MSR specified by Index.
5230 No parameter checking is performed on Index, and some Index values may cause
5231 CPU exceptions. The caller must either guarantee that Index is valid, or the
5232 caller must set up exception handlers to catch the exceptions. This function
5233 is only available on IA-32 and X64.
5235 @param Index The 32-bit MSR index to read.
5237 @return The lower 32 bits of the MSR identified by Index.
5248 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
5250 Writes the 32-bit value specified by Value to the MSR specified by Index. The
5251 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
5252 the MSR is returned. No parameter checking is performed on Index or Value,
5253 and some of these may cause CPU exceptions. The caller must either guarantee
5254 that Index and Value are valid, or the caller must establish proper exception
5255 handlers. This function is only available on IA-32 and X64.
5257 @param Index The 32-bit MSR index to write.
5258 @param Value The 32-bit value to write to the MSR.
5272 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
5273 writes the result back to the 64-bit MSR.
5275 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5276 between the lower 32-bits of the read result and the value specified by
5277 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
5278 32-bits of the value written to the MSR is returned. No parameter checking is
5279 performed on Index or OrData, and some of these may cause CPU exceptions. The
5280 caller must either guarantee that Index and OrData are valid, or the caller
5281 must establish proper exception handlers. This function is only available on
5284 @param Index The 32-bit MSR index to write.
5285 @param OrData The value to OR with the read value from the MSR.
5287 @return The lower 32-bit value written to the MSR.
5299 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
5300 the result back to the 64-bit MSR.
5302 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5303 lower 32-bits of the read result and the value specified by AndData, and
5304 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
5305 the value written to the MSR is returned. No parameter checking is performed
5306 on Index or AndData, and some of these may cause CPU exceptions. The caller
5307 must either guarantee that Index and AndData are valid, or the caller must
5308 establish proper exception handlers. This function is only available on IA-32
5311 @param Index The 32-bit MSR index to write.
5312 @param AndData The value to AND with the read value from the MSR.
5314 @return The lower 32-bit value written to the MSR.
5326 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
5327 on the lower 32-bits, and writes the result back to the 64-bit MSR.
5329 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5330 lower 32-bits of the read result and the value specified by AndData
5331 preserving the upper 32-bits, performs a bitwise inclusive OR between the
5332 result of the AND operation and the value specified by OrData, and writes the
5333 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
5334 written to the MSR is returned. No parameter checking is performed on Index,
5335 AndData, or OrData, and some of these may cause CPU exceptions. The caller
5336 must either guarantee that Index, AndData, and OrData are valid, or the
5337 caller must establish proper exception handlers. This function is only
5338 available on IA-32 and X64.
5340 @param Index The 32-bit MSR index to write.
5341 @param AndData The value to AND with the read value from the MSR.
5342 @param OrData The value to OR with the result of the AND operation.
5344 @return The lower 32-bit value written to the MSR.
5357 Reads a bit field of an MSR.
5359 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
5360 specified by the StartBit and the EndBit. The value of the bit field is
5361 returned. The caller must either guarantee that Index is valid, or the caller
5362 must set up exception handlers to catch the exceptions. This function is only
5363 available on IA-32 and X64.
5365 If StartBit is greater than 31, then ASSERT().
5366 If EndBit is greater than 31, then ASSERT().
5367 If EndBit is less than StartBit, then ASSERT().
5369 @param Index The 32-bit MSR index to read.
5370 @param StartBit The ordinal of the least significant bit in the bit field.
5372 @param EndBit The ordinal of the most significant bit in the bit field.
5375 @return The bit field read from the MSR.
5380 AsmMsrBitFieldRead32 (
5388 Writes a bit field to an MSR.
5390 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
5391 field is specified by the StartBit and the EndBit. All other bits in the
5392 destination MSR are preserved. The lower 32-bits of the MSR written is
5393 returned. Extra left bits in Value are stripped. The caller must either
5394 guarantee that Index and the data written is valid, or the caller must set up
5395 exception handlers to catch the exceptions. This function is only available
5398 If StartBit is greater than 31, then ASSERT().
5399 If EndBit is greater than 31, then ASSERT().
5400 If EndBit is less than StartBit, then ASSERT().
5402 @param Index The 32-bit MSR index to write.
5403 @param StartBit The ordinal of the least significant bit in the bit field.
5405 @param EndBit The ordinal of the most significant bit in the bit field.
5407 @param Value New value of the bit field.
5409 @return The lower 32-bit of the value written to the MSR.
5414 AsmMsrBitFieldWrite32 (
5423 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
5424 result back to the bit field in the 64-bit MSR.
5426 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5427 between the read result and the value specified by OrData, and writes the
5428 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
5429 written to the MSR are returned. Extra left bits in OrData are stripped. The
5430 caller must either guarantee that Index and the data written is valid, or
5431 the caller must set up exception handlers to catch the exceptions. This
5432 function is only available on IA-32 and X64.
5434 If StartBit is greater than 31, then ASSERT().
5435 If EndBit is greater than 31, then ASSERT().
5436 If EndBit is less than StartBit, then ASSERT().
5438 @param Index The 32-bit MSR index to write.
5439 @param StartBit The ordinal of the least significant bit in the bit field.
5441 @param EndBit The ordinal of the most significant bit in the bit field.
5443 @param OrData The value to OR with the read value from the MSR.
5445 @return The lower 32-bit of the value written to the MSR.
5450 AsmMsrBitFieldOr32 (
5459 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5460 result back to the bit field in the 64-bit MSR.
5462 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5463 read result and the value specified by AndData, and writes the result to the
5464 64-bit MSR specified by Index. The lower 32-bits of the value written to the
5465 MSR are returned. Extra left bits in AndData are stripped. The caller must
5466 either guarantee that Index and the data written is valid, or the caller must
5467 set up exception handlers to catch the exceptions. This function is only
5468 available on IA-32 and X64.
5470 If StartBit is greater than 31, then ASSERT().
5471 If EndBit is greater than 31, then ASSERT().
5472 If EndBit is less than StartBit, then ASSERT().
5474 @param Index The 32-bit MSR index to write.
5475 @param StartBit The ordinal of the least significant bit in the bit field.
5477 @param EndBit The ordinal of the most significant bit in the bit field.
5479 @param AndData The value to AND with the read value from the MSR.
5481 @return The lower 32-bit of the value written to the MSR.
5486 AsmMsrBitFieldAnd32 (
5495 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5496 bitwise inclusive OR, and writes the result back to the bit field in the
5499 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
5500 bitwise inclusive OR between the read result and the value specified by
5501 AndData, and writes the result to the 64-bit MSR specified by Index. The
5502 lower 32-bits of the value written to the MSR are returned. Extra left bits
5503 in both AndData and OrData are stripped. The caller must either guarantee
5504 that Index and the data written is valid, or the caller must set up exception
5505 handlers to catch the exceptions. This function is only available on IA-32
5508 If StartBit is greater than 31, then ASSERT().
5509 If EndBit is greater than 31, then ASSERT().
5510 If EndBit is less than StartBit, then ASSERT().
5512 @param Index The 32-bit MSR index to write.
5513 @param StartBit The ordinal of the least significant bit in the bit field.
5515 @param EndBit The ordinal of the most significant bit in the bit field.
5517 @param AndData The value to AND with the read value from the MSR.
5518 @param OrData The value to OR with the result of the AND operation.
5520 @return The lower 32-bit of the value written to the MSR.
5525 AsmMsrBitFieldAndThenOr32 (
5535 Returns a 64-bit Machine Specific Register(MSR).
5537 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
5538 performed on Index, and some Index values may cause CPU exceptions. The
5539 caller must either guarantee that Index is valid, or the caller must set up
5540 exception handlers to catch the exceptions. This function is only available
5543 @param Index The 32-bit MSR index to read.
5545 @return The value of the MSR identified by Index.
5556 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
5559 Writes the 64-bit value specified by Value to the MSR specified by Index. The
5560 64-bit value written to the MSR is returned. No parameter checking is
5561 performed on Index or Value, and some of these may cause CPU exceptions. The
5562 caller must either guarantee that Index and Value are valid, or the caller
5563 must establish proper exception handlers. This function is only available on
5566 @param Index The 32-bit MSR index to write.
5567 @param Value The 64-bit value to write to the MSR.
5581 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
5582 back to the 64-bit MSR.
5584 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5585 between the read result and the value specified by OrData, and writes the
5586 result to the 64-bit MSR specified by Index. The value written to the MSR is
5587 returned. No parameter checking is performed on Index or OrData, and some of
5588 these may cause CPU exceptions. The caller must either guarantee that Index
5589 and OrData are valid, or the caller must establish proper exception handlers.
5590 This function is only available on IA-32 and X64.
5592 @param Index The 32-bit MSR index to write.
5593 @param OrData The value to OR with the read value from the MSR.
5595 @return The value written back to the MSR.
5607 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
5610 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5611 read result and the value specified by OrData, and writes the result to the
5612 64-bit MSR specified by Index. The value written to the MSR is returned. No
5613 parameter checking is performed on Index or OrData, and some of these may
5614 cause CPU exceptions. The caller must either guarantee that Index and OrData
5615 are valid, or the caller must establish proper exception handlers. This
5616 function is only available on IA-32 and X64.
5618 @param Index The 32-bit MSR index to write.
5619 @param AndData The value to AND with the read value from the MSR.
5621 @return The value written back to the MSR.
5633 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
5634 OR, and writes the result back to the 64-bit MSR.
5636 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
5637 result and the value specified by AndData, performs a bitwise inclusive OR
5638 between the result of the AND operation and the value specified by OrData,
5639 and writes the result to the 64-bit MSR specified by Index. The value written
5640 to the MSR is returned. No parameter checking is performed on Index, AndData,
5641 or OrData, and some of these may cause CPU exceptions. The caller must either
5642 guarantee that Index, AndData, and OrData are valid, or the caller must
5643 establish proper exception handlers. This function is only available on IA-32
5646 @param Index The 32-bit MSR index to write.
5647 @param AndData The value to AND with the read value from the MSR.
5648 @param OrData The value to OR with the result of the AND operation.
5650 @return The value written back to the MSR.
5663 Reads a bit field of an MSR.
5665 Reads the bit field in the 64-bit MSR. The bit field is specified by the
5666 StartBit and the EndBit. The value of the bit field is returned. The caller
5667 must either guarantee that Index is valid, or the caller must set up
5668 exception handlers to catch the exceptions. This function is only available
5671 If StartBit is greater than 63, then ASSERT().
5672 If EndBit is greater than 63, then ASSERT().
5673 If EndBit is less than StartBit, then ASSERT().
5675 @param Index The 32-bit MSR index to read.
5676 @param StartBit The ordinal of the least significant bit in the bit field.
5678 @param EndBit The ordinal of the most significant bit in the bit field.
5681 @return The value read from the MSR.
5686 AsmMsrBitFieldRead64 (
5694 Writes a bit field to an MSR.
5696 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
5697 the StartBit and the EndBit. All other bits in the destination MSR are
5698 preserved. The MSR written is returned. Extra left bits in Value are
5699 stripped. The caller must either guarantee that Index and the data written is
5700 valid, or the caller must set up exception handlers to catch the exceptions.
5701 This function is only available on IA-32 and X64.
5703 If StartBit is greater than 63, then ASSERT().
5704 If EndBit is greater than 63, then ASSERT().
5705 If EndBit is less than StartBit, then ASSERT().
5707 @param Index The 32-bit MSR index to write.
5708 @param StartBit The ordinal of the least significant bit in the bit field.
5710 @param EndBit The ordinal of the most significant bit in the bit field.
5712 @param Value New value of the bit field.
5714 @return The value written back to the MSR.
5719 AsmMsrBitFieldWrite64 (
5728 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
5729 writes the result back to the bit field in the 64-bit MSR.
5731 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5732 between the read result and the value specified by OrData, and writes the
5733 result to the 64-bit MSR specified by Index. The value written to the MSR is
5734 returned. Extra left bits in OrData are stripped. The caller must either
5735 guarantee that Index and the data written is valid, or the caller must set up
5736 exception handlers to catch the exceptions. This function is only available
5739 If StartBit is greater than 63, then ASSERT().
5740 If EndBit is greater than 63, then ASSERT().
5741 If EndBit is less than StartBit, then ASSERT().
5743 @param Index The 32-bit MSR index to write.
5744 @param StartBit The ordinal of the least significant bit in the bit field.
5746 @param EndBit The ordinal of the most significant bit in the bit field.
5748 @param OrData The value to OR with the read value from the bit field.
5750 @return The value written back to the MSR.
5755 AsmMsrBitFieldOr64 (
5764 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5765 result back to the bit field in the 64-bit MSR.
5767 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5768 read result and the value specified by AndData, and writes the result to the
5769 64-bit MSR specified by Index. The value written to the MSR is returned.
5770 Extra left bits in AndData are stripped. The caller must either guarantee
5771 that Index and the data written is valid, or the caller must set up exception
5772 handlers to catch the exceptions. This function is only available on IA-32
5775 If StartBit is greater than 63, then ASSERT().
5776 If EndBit is greater than 63, then ASSERT().
5777 If EndBit is less than StartBit, then ASSERT().
5779 @param Index The 32-bit MSR index to write.
5780 @param StartBit The ordinal of the least significant bit in the bit field.
5782 @param EndBit The ordinal of the most significant bit in the bit field.
5784 @param AndData The value to AND with the read value from the bit field.
5786 @return The value written back to the MSR.
5791 AsmMsrBitFieldAnd64 (
5800 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5801 bitwise inclusive OR, and writes the result back to the bit field in the
5804 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
5805 a bitwise inclusive OR between the read result and the value specified by
5806 AndData, and writes the result to the 64-bit MSR specified by Index. The
5807 value written to the MSR is returned. Extra left bits in both AndData and
5808 OrData are stripped. The caller must either guarantee that Index and the data
5809 written is valid, or the caller must set up exception handlers to catch the
5810 exceptions. This function is only available on IA-32 and X64.
5812 If StartBit is greater than 63, then ASSERT().
5813 If EndBit is greater than 63, then ASSERT().
5814 If EndBit is less than StartBit, then ASSERT().
5816 @param Index The 32-bit MSR index to write.
5817 @param StartBit The ordinal of the least significant bit in the bit field.
5819 @param EndBit The ordinal of the most significant bit in the bit field.
5821 @param AndData The value to AND with the read value from the bit field.
5822 @param OrData The value to OR with the result of the AND operation.
5824 @return The value written back to the MSR.
5829 AsmMsrBitFieldAndThenOr64 (
5839 Reads the current value of the EFLAGS register.
5841 Reads and returns the current value of the EFLAGS register. This function is
5842 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
5843 64-bit value on X64.
5845 @return EFLAGS on IA-32 or RFLAGS on X64.
5856 Reads the current value of the Control Register 0 (CR0).
5858 Reads and returns the current value of CR0. This function is only available
5859 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5862 @return The value of the Control Register 0 (CR0).
5873 Reads the current value of the Control Register 2 (CR2).
5875 Reads and returns the current value of CR2. This function is only available
5876 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5879 @return The value of the Control Register 2 (CR2).
5890 Reads the current value of the Control Register 3 (CR3).
5892 Reads and returns the current value of CR3. This function is only available
5893 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5896 @return The value of the Control Register 3 (CR3).
5907 Reads the current value of the Control Register 4 (CR4).
5909 Reads and returns the current value of CR4. This function is only available
5910 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5913 @return The value of the Control Register 4 (CR4).
5924 Writes a value to Control Register 0 (CR0).
5926 Writes and returns a new value to CR0. This function is only available on
5927 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5929 @param Cr0 The value to write to CR0.
5931 @return The value written to CR0.
5942 Writes a value to Control Register 2 (CR2).
5944 Writes and returns a new value to CR2. This function is only available on
5945 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5947 @param Cr2 The value to write to CR2.
5949 @return The value written to CR2.
5960 Writes a value to Control Register 3 (CR3).
5962 Writes and returns a new value to CR3. This function is only available on
5963 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5965 @param Cr3 The value to write to CR3.
5967 @return The value written to CR3.
5978 Writes a value to Control Register 4 (CR4).
5980 Writes and returns a new value to CR4. This function is only available on
5981 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5983 @param Cr4 The value to write to CR4.
5985 @return The value written to CR4.
5996 Reads the current value of Debug Register 0 (DR0).
5998 Reads and returns the current value of DR0. This function is only available
5999 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6002 @return The value of Debug Register 0 (DR0).
6013 Reads the current value of Debug Register 1 (DR1).
6015 Reads and returns the current value of DR1. This function is only available
6016 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6019 @return The value of Debug Register 1 (DR1).
6030 Reads the current value of Debug Register 2 (DR2).
6032 Reads and returns the current value of DR2. This function is only available
6033 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6036 @return The value of Debug Register 2 (DR2).
6047 Reads the current value of Debug Register 3 (DR3).
6049 Reads and returns the current value of DR3. This function is only available
6050 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6053 @return The value of Debug Register 3 (DR3).
6064 Reads the current value of Debug Register 4 (DR4).
6066 Reads and returns the current value of DR4. This function is only available
6067 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6070 @return The value of Debug Register 4 (DR4).
6081 Reads the current value of Debug Register 5 (DR5).
6083 Reads and returns the current value of DR5. This function is only available
6084 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6087 @return The value of Debug Register 5 (DR5).
6098 Reads the current value of Debug Register 6 (DR6).
6100 Reads and returns the current value of DR6. This function is only available
6101 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6104 @return The value of Debug Register 6 (DR6).
6115 Reads the current value of Debug Register 7 (DR7).
6117 Reads and returns the current value of DR7. This function is only available
6118 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6121 @return The value of Debug Register 7 (DR7).
6132 Writes a value to Debug Register 0 (DR0).
6134 Writes and returns a new value to DR0. This function is only available on
6135 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6137 @param Dr0 The value to write to Dr0.
6139 @return The value written to Debug Register 0 (DR0).
6150 Writes a value to Debug Register 1 (DR1).
6152 Writes and returns a new value to DR1. This function is only available on
6153 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6155 @param Dr1 The value to write to Dr1.
6157 @return The value written to Debug Register 1 (DR1).
6168 Writes a value to Debug Register 2 (DR2).
6170 Writes and returns a new value to DR2. This function is only available on
6171 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6173 @param Dr2 The value to write to Dr2.
6175 @return The value written to Debug Register 2 (DR2).
6186 Writes a value to Debug Register 3 (DR3).
6188 Writes and returns a new value to DR3. This function is only available on
6189 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6191 @param Dr3 The value to write to Dr3.
6193 @return The value written to Debug Register 3 (DR3).
6204 Writes a value to Debug Register 4 (DR4).
6206 Writes and returns a new value to DR4. This function is only available on
6207 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6209 @param Dr4 The value to write to Dr4.
6211 @return The value written to Debug Register 4 (DR4).
6222 Writes a value to Debug Register 5 (DR5).
6224 Writes and returns a new value to DR5. This function is only available on
6225 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6227 @param Dr5 The value to write to Dr5.
6229 @return The value written to Debug Register 5 (DR5).
6240 Writes a value to Debug Register 6 (DR6).
6242 Writes and returns a new value to DR6. This function is only available on
6243 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6245 @param Dr6 The value to write to Dr6.
6247 @return The value written to Debug Register 6 (DR6).
6258 Writes a value to Debug Register 7 (DR7).
6260 Writes and returns a new value to DR7. This function is only available on
6261 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6263 @param Dr7 The value to write to Dr7.
6265 @return The value written to Debug Register 7 (DR7).
6276 Reads the current value of Code Segment Register (CS).
6278 Reads and returns the current value of CS. This function is only available on
6281 @return The current value of CS.
6292 Reads the current value of Data Segment Register (DS).
6294 Reads and returns the current value of DS. This function is only available on
6297 @return The current value of DS.
6308 Reads the current value of Extra Segment Register (ES).
6310 Reads and returns the current value of ES. This function is only available on
6313 @return The current value of ES.
6324 Reads the current value of FS Data Segment Register (FS).
6326 Reads and returns the current value of FS. This function is only available on
6329 @return The current value of FS.
6340 Reads the current value of GS Data Segment Register (GS).
6342 Reads and returns the current value of GS. This function is only available on
6345 @return The current value of GS.
6356 Reads the current value of Stack Segment Register (SS).
6358 Reads and returns the current value of SS. This function is only available on
6361 @return The current value of SS.
6372 Reads the current value of Task Register (TR).
6374 Reads and returns the current value of TR. This function is only available on
6377 @return The current value of TR.
6388 Reads the current Global Descriptor Table Register(GDTR) descriptor.
6390 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
6391 function is only available on IA-32 and X64.
6393 If Gdtr is NULL, then ASSERT().
6395 @param Gdtr Pointer to a GDTR descriptor.
6401 OUT IA32_DESCRIPTOR
*Gdtr
6406 Writes the current Global Descriptor Table Register (GDTR) descriptor.
6408 Writes and the current GDTR descriptor specified by Gdtr. This function is
6409 only available on IA-32 and X64.
6411 If Gdtr is NULL, then ASSERT().
6413 @param Gdtr Pointer to a GDTR descriptor.
6419 IN CONST IA32_DESCRIPTOR
*Gdtr
6424 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
6426 Reads and returns the current IDTR descriptor and returns it in Idtr. This
6427 function is only available on IA-32 and X64.
6429 If Idtr is NULL, then ASSERT().
6431 @param Idtr Pointer to a IDTR descriptor.
6437 OUT IA32_DESCRIPTOR
*Idtr
6442 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
6444 Writes the current IDTR descriptor and returns it in Idtr. This function is
6445 only available on IA-32 and X64.
6447 If Idtr is NULL, then ASSERT().
6449 @param Idtr Pointer to a IDTR descriptor.
6455 IN CONST IA32_DESCRIPTOR
*Idtr
6460 Reads the current Local Descriptor Table Register(LDTR) selector.
6462 Reads and returns the current 16-bit LDTR descriptor value. This function is
6463 only available on IA-32 and X64.
6465 @return The current selector of LDT.
6476 Writes the current Local Descriptor Table Register (GDTR) selector.
6478 Writes and the current LDTR descriptor specified by Ldtr. This function is
6479 only available on IA-32 and X64.
6481 @param Ldtr 16-bit LDTR selector value.
6492 Save the current floating point/SSE/SSE2 context to a buffer.
6494 Saves the current floating point/SSE/SSE2 state to the buffer specified by
6495 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
6496 available on IA-32 and X64.
6498 If Buffer is NULL, then ASSERT().
6499 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6501 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6507 OUT IA32_FX_BUFFER
*Buffer
6512 Restores the current floating point/SSE/SSE2 context from a buffer.
6514 Restores the current floating point/SSE/SSE2 state from the buffer specified
6515 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
6516 only available on IA-32 and X64.
6518 If Buffer is NULL, then ASSERT().
6519 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6520 If Buffer was not saved with AsmFxSave(), then ASSERT().
6522 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6528 IN CONST IA32_FX_BUFFER
*Buffer
6533 Reads the current value of 64-bit MMX Register #0 (MM0).
6535 Reads and returns the current value of MM0. This function is only available
6538 @return The current value of MM0.
6549 Reads the current value of 64-bit MMX Register #1 (MM1).
6551 Reads and returns the current value of MM1. This function is only available
6554 @return The current value of MM1.
6565 Reads the current value of 64-bit MMX Register #2 (MM2).
6567 Reads and returns the current value of MM2. This function is only available
6570 @return The current value of MM2.
6581 Reads the current value of 64-bit MMX Register #3 (MM3).
6583 Reads and returns the current value of MM3. This function is only available
6586 @return The current value of MM3.
6597 Reads the current value of 64-bit MMX Register #4 (MM4).
6599 Reads and returns the current value of MM4. This function is only available
6602 @return The current value of MM4.
6613 Reads the current value of 64-bit MMX Register #5 (MM5).
6615 Reads and returns the current value of MM5. This function is only available
6618 @return The current value of MM5.
6629 Reads the current value of 64-bit MMX Register #6 (MM6).
6631 Reads and returns the current value of MM6. This function is only available
6634 @return The current value of MM6.
6645 Reads the current value of 64-bit MMX Register #7 (MM7).
6647 Reads and returns the current value of MM7. This function is only available
6650 @return The current value of MM7.
6661 Writes the current value of 64-bit MMX Register #0 (MM0).
6663 Writes the current value of MM0. This function is only available on IA32 and
6666 @param Value The 64-bit value to write to MM0.
6677 Writes the current value of 64-bit MMX Register #1 (MM1).
6679 Writes the current value of MM1. This function is only available on IA32 and
6682 @param Value The 64-bit value to write to MM1.
6693 Writes the current value of 64-bit MMX Register #2 (MM2).
6695 Writes the current value of MM2. This function is only available on IA32 and
6698 @param Value The 64-bit value to write to MM2.
6709 Writes the current value of 64-bit MMX Register #3 (MM3).
6711 Writes the current value of MM3. This function is only available on IA32 and
6714 @param Value The 64-bit value to write to MM3.
6725 Writes the current value of 64-bit MMX Register #4 (MM4).
6727 Writes the current value of MM4. This function is only available on IA32 and
6730 @param Value The 64-bit value to write to MM4.
6741 Writes the current value of 64-bit MMX Register #5 (MM5).
6743 Writes the current value of MM5. This function is only available on IA32 and
6746 @param Value The 64-bit value to write to MM5.
6757 Writes the current value of 64-bit MMX Register #6 (MM6).
6759 Writes the current value of MM6. This function is only available on IA32 and
6762 @param Value The 64-bit value to write to MM6.
6773 Writes the current value of 64-bit MMX Register #7 (MM7).
6775 Writes the current value of MM7. This function is only available on IA32 and
6778 @param Value The 64-bit value to write to MM7.
6789 Reads the current value of Time Stamp Counter (TSC).
6791 Reads and returns the current value of TSC. This function is only available
6794 @return The current value of TSC
6805 Reads the current value of a Performance Counter (PMC).
6807 Reads and returns the current value of performance counter specified by
6808 Index. This function is only available on IA-32 and X64.
6810 @param Index The 32-bit Performance Counter index to read.
6812 @return The value of the PMC specified by Index.
6823 Sets up a monitor buffer that is used by AsmMwait().
6825 Executes a MONITOR instruction with the register state specified by Eax, Ecx
6826 and Edx. Returns Eax. This function is only available on IA-32 and X64.
6828 @param Eax The value to load into EAX or RAX before executing the MONITOR
6830 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6832 @param Edx The value to load into EDX or RDX before executing the MONITOR
6848 Executes an MWAIT instruction.
6850 Executes an MWAIT instruction with the register state specified by Eax and
6851 Ecx. Returns Eax. This function is only available on IA-32 and X64.
6853 @param Eax The value to load into EAX or RAX before executing the MONITOR
6855 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6870 Executes a WBINVD instruction.
6872 Executes a WBINVD instruction. This function is only available on IA-32 and
6884 Executes a INVD instruction.
6886 Executes a INVD instruction. This function is only available on IA-32 and
6898 Flushes a cache line from all the instruction and data caches within the
6899 coherency domain of the CPU.
6901 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
6902 This function is only available on IA-32 and X64.
6904 @param LinearAddress The address of the cache line to flush. If the CPU is
6905 in a physical addressing mode, then LinearAddress is a
6906 physical address. If the CPU is in a virtual
6907 addressing mode, then LinearAddress is a virtual
6910 @return LinearAddress
6915 IN VOID
*LinearAddress
6920 Enables the 32-bit paging mode on the CPU.
6922 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
6923 must be properly initialized prior to calling this service. This function
6924 assumes the current execution mode is 32-bit protected mode. This function is
6925 only available on IA-32. After the 32-bit paging mode is enabled, control is
6926 transferred to the function specified by EntryPoint using the new stack
6927 specified by NewStack and passing in the parameters specified by Context1 and
6928 Context2. Context1 and Context2 are optional and may be NULL. The function
6929 EntryPoint must never return.
6931 If the current execution mode is not 32-bit protected mode, then ASSERT().
6932 If EntryPoint is NULL, then ASSERT().
6933 If NewStack is NULL, then ASSERT().
6935 There are a number of constraints that must be followed before calling this
6937 1) Interrupts must be disabled.
6938 2) The caller must be in 32-bit protected mode with flat descriptors. This
6939 means all descriptors must have a base of 0 and a limit of 4GB.
6940 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
6942 4) CR3 must point to valid page tables that will be used once the transition
6943 is complete, and those page tables must guarantee that the pages for this
6944 function and the stack are identity mapped.
6946 @param EntryPoint A pointer to function to call with the new stack after
6948 @param Context1 A pointer to the context to pass into the EntryPoint
6949 function as the first parameter after paging is enabled.
6950 @param Context2 A pointer to the context to pass into the EntryPoint
6951 function as the second parameter after paging is enabled.
6952 @param NewStack A pointer to the new stack to use for the EntryPoint
6953 function after paging is enabled.
6959 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
6960 IN VOID
*Context1
, OPTIONAL
6961 IN VOID
*Context2
, OPTIONAL
6967 Disables the 32-bit paging mode on the CPU.
6969 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
6970 mode. This function assumes the current execution mode is 32-paged protected
6971 mode. This function is only available on IA-32. After the 32-bit paging mode
6972 is disabled, control is transferred to the function specified by EntryPoint
6973 using the new stack specified by NewStack and passing in the parameters
6974 specified by Context1 and Context2. Context1 and Context2 are optional and
6975 may be NULL. The function EntryPoint must never return.
6977 If the current execution mode is not 32-bit paged mode, then ASSERT().
6978 If EntryPoint is NULL, then ASSERT().
6979 If NewStack is NULL, then ASSERT().
6981 There are a number of constraints that must be followed before calling this
6983 1) Interrupts must be disabled.
6984 2) The caller must be in 32-bit paged mode.
6985 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
6986 4) CR3 must point to valid page tables that guarantee that the pages for
6987 this function and the stack are identity mapped.
6989 @param EntryPoint A pointer to function to call with the new stack after
6991 @param Context1 A pointer to the context to pass into the EntryPoint
6992 function as the first parameter after paging is disabled.
6993 @param Context2 A pointer to the context to pass into the EntryPoint
6994 function as the second parameter after paging is
6996 @param NewStack A pointer to the new stack to use for the EntryPoint
6997 function after paging is disabled.
7002 AsmDisablePaging32 (
7003 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
7004 IN VOID
*Context1
, OPTIONAL
7005 IN VOID
*Context2
, OPTIONAL
7011 Enables the 64-bit paging mode on the CPU.
7013 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7014 must be properly initialized prior to calling this service. This function
7015 assumes the current execution mode is 32-bit protected mode with flat
7016 descriptors. This function is only available on IA-32. After the 64-bit
7017 paging mode is enabled, control is transferred to the function specified by
7018 EntryPoint using the new stack specified by NewStack and passing in the
7019 parameters specified by Context1 and Context2. Context1 and Context2 are
7020 optional and may be 0. The function EntryPoint must never return.
7022 If the current execution mode is not 32-bit protected mode with flat
7023 descriptors, then ASSERT().
7024 If EntryPoint is 0, then ASSERT().
7025 If NewStack is 0, then ASSERT().
7027 @param Cs The 16-bit selector to load in the CS before EntryPoint
7028 is called. The descriptor in the GDT that this selector
7029 references must be setup for long mode.
7030 @param EntryPoint The 64-bit virtual address of the function to call with
7031 the new stack after paging is enabled.
7032 @param Context1 The 64-bit virtual address of the context to pass into
7033 the EntryPoint function as the first parameter after
7035 @param Context2 The 64-bit virtual address of the context to pass into
7036 the EntryPoint function as the second parameter after
7038 @param NewStack The 64-bit virtual address of the new stack to use for
7039 the EntryPoint function after paging is enabled.
7045 IN UINT16 CodeSelector
,
7046 IN UINT64 EntryPoint
,
7047 IN UINT64 Context1
, OPTIONAL
7048 IN UINT64 Context2
, OPTIONAL
7054 Disables the 64-bit paging mode on the CPU.
7056 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
7057 mode. This function assumes the current execution mode is 64-paging mode.
7058 This function is only available on X64. After the 64-bit paging mode is
7059 disabled, control is transferred to the function specified by EntryPoint
7060 using the new stack specified by NewStack and passing in the parameters
7061 specified by Context1 and Context2. Context1 and Context2 are optional and
7062 may be 0. The function EntryPoint must never return.
7064 If the current execution mode is not 64-bit paged mode, then ASSERT().
7065 If EntryPoint is 0, then ASSERT().
7066 If NewStack is 0, then ASSERT().
7068 @param Cs The 16-bit selector to load in the CS before EntryPoint
7069 is called. The descriptor in the GDT that this selector
7070 references must be setup for 32-bit protected mode.
7071 @param EntryPoint The 64-bit virtual address of the function to call with
7072 the new stack after paging is disabled.
7073 @param Context1 The 64-bit virtual address of the context to pass into
7074 the EntryPoint function as the first parameter after
7076 @param Context2 The 64-bit virtual address of the context to pass into
7077 the EntryPoint function as the second parameter after
7079 @param NewStack The 64-bit virtual address of the new stack to use for
7080 the EntryPoint function after paging is disabled.
7085 AsmDisablePaging64 (
7086 IN UINT16 CodeSelector
,
7087 IN UINT32 EntryPoint
,
7088 IN UINT32 Context1
, OPTIONAL
7089 IN UINT32 Context2
, OPTIONAL
7095 // 16-bit thunking services
7099 Retrieves the properties for 16-bit thunk functions.
7101 Computes the size of the buffer and stack below 1MB required to use the
7102 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
7103 buffer size is returned in RealModeBufferSize, and the stack size is returned
7104 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
7105 then the actual minimum stack size is ExtraStackSize plus the maximum number
7106 of bytes that need to be passed to the 16-bit real mode code.
7108 If RealModeBufferSize is NULL, then ASSERT().
7109 If ExtraStackSize is NULL, then ASSERT().
7111 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
7112 required to use the 16-bit thunk functions.
7113 @param ExtraStackSize A pointer to the extra size of stack below 1MB
7114 that the 16-bit thunk functions require for
7115 temporary storage in the transition to and from
7121 AsmGetThunk16Properties (
7122 OUT UINT32
*RealModeBufferSize
,
7123 OUT UINT32
*ExtraStackSize
7128 Prepares all structures a code required to use AsmThunk16().
7130 Prepares all structures and code required to use AsmThunk16().
7132 If ThunkContext is NULL, then ASSERT().
7134 @param ThunkContext A pointer to the context structure that describes the
7135 16-bit real mode code to call.
7141 OUT THUNK_CONTEXT
*ThunkContext
7146 Transfers control to a 16-bit real mode entry point and returns the results.
7148 Transfers control to a 16-bit real mode entry point and returns the results.
7149 AsmPrepareThunk16() must be called with ThunkContext before this function is
7152 If ThunkContext is NULL, then ASSERT().
7153 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
7155 @param ThunkContext A pointer to the context structure that describes the
7156 16-bit real mode code to call.
7162 IN OUT THUNK_CONTEXT
*ThunkContext
7167 Prepares all structures and code for a 16-bit real mode thunk, transfers
7168 control to a 16-bit real mode entry point, and returns the results.
7170 Prepares all structures and code for a 16-bit real mode thunk, transfers
7171 control to a 16-bit real mode entry point, and returns the results. If the
7172 caller only need to perform a single 16-bit real mode thunk, then this
7173 service should be used. If the caller intends to make more than one 16-bit
7174 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
7175 once and AsmThunk16() can be called for each 16-bit real mode thunk.
7177 If ThunkContext is NULL, then ASSERT().
7179 @param ThunkContext A pointer to the context structure that describes the
7180 16-bit real mode code to call.
7185 AsmPrepareAndThunk16 (
7186 IN OUT THUNK_CONTEXT
*ThunkContext