3 Copyright (c) 2004 - 2009, 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 Length is greater than
230 PcdMaximumUnicodeStringLength, then ASSERT().
231 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
232 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
235 @param Destination Pointer to a Null-terminated Unicode string.
236 @param Source Pointer to a Null-terminated Unicode string.
237 @param Length Maximum number of Unicode characters to copy.
245 OUT CHAR16
*Destination
,
246 IN CONST CHAR16
*Source
,
252 Returns the length of a Null-terminated Unicode string.
254 This function returns the number of Unicode characters in the Null-terminated
255 Unicode string specified by String.
257 If String is NULL, then ASSERT().
258 If String is not aligned on a 16-bit boundary, then ASSERT().
259 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
260 PcdMaximumUnicodeStringLength Unicode characters not including the
261 Null-terminator, then ASSERT().
263 @param String Pointer to a Null-terminated Unicode string.
265 @return The length of String.
271 IN CONST CHAR16
*String
276 Returns the size of a Null-terminated Unicode string in bytes, including the
279 This function returns the size, in bytes, of the Null-terminated Unicode
280 string specified by String.
282 If String is NULL, then ASSERT().
283 If String is not aligned on a 16-bit boundary, then ASSERT().
284 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
285 PcdMaximumUnicodeStringLength Unicode characters not including the
286 Null-terminator, then ASSERT().
288 @param String Pointer to a Null-terminated Unicode string.
290 @return The size of String.
296 IN CONST CHAR16
*String
301 Compares two Null-terminated Unicode strings, and returns the difference
302 between the first mismatched Unicode characters.
304 This function compares the Null-terminated Unicode string FirstString to the
305 Null-terminated Unicode string SecondString. If FirstString is identical to
306 SecondString, then 0 is returned. Otherwise, the value returned is the first
307 mismatched Unicode character in SecondString subtracted from the first
308 mismatched Unicode character in FirstString.
310 If FirstString is NULL, then ASSERT().
311 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
312 If SecondString is NULL, then ASSERT().
313 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
314 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
315 than PcdMaximumUnicodeStringLength Unicode characters not including the
316 Null-terminator, then ASSERT().
317 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
318 than PcdMaximumUnicodeStringLength Unicode characters not including the
319 Null-terminator, then ASSERT().
321 @param FirstString Pointer to a Null-terminated Unicode string.
322 @param SecondString Pointer to a Null-terminated Unicode string.
324 @retval 0 FirstString is identical to SecondString.
325 @retval !=0 FirstString is not identical to SecondString.
331 IN CONST CHAR16
*FirstString
,
332 IN CONST CHAR16
*SecondString
337 Compares two Null-terminated Unicode strings with maximum lengths, and
338 returns the difference between the first mismatched Unicode characters.
340 This function compares the Null-terminated Unicode string FirstString to the
341 Null-terminated Unicode string SecondString. At most, Length Unicode
342 characters will be compared. If Length is 0, then 0 is returned. If
343 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
344 value returned is the first mismatched Unicode character in SecondString
345 subtracted from the first mismatched Unicode character in FirstString.
347 If Length > 0 and FirstString is NULL, then ASSERT().
348 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().
349 If Length > 0 and SecondString is NULL, then ASSERT().
350 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().
351 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
352 PcdMaximumUnicodeStringLength, then ASSERT().
353 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than
354 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
356 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than
357 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
360 @param FirstString Pointer to a Null-terminated Unicode string.
361 @param SecondString Pointer to a Null-terminated Unicode string.
362 @param Length Maximum number of Unicode characters to compare.
364 @retval 0 FirstString is identical to SecondString.
365 @retval !=0 FirstString is not identical to SecondString.
371 IN CONST CHAR16
*FirstString
,
372 IN CONST CHAR16
*SecondString
,
378 Concatenates one Null-terminated Unicode string to another Null-terminated
379 Unicode string, and returns the concatenated Unicode string.
381 This function concatenates two Null-terminated Unicode strings. The contents
382 of Null-terminated Unicode string Source are concatenated to the end of
383 Null-terminated Unicode string Destination. The Null-terminated concatenated
384 Unicode String is returned. If Source and Destination overlap, then the
385 results are undefined.
387 If Destination is NULL, then ASSERT().
388 If Destination is not aligned on a 16-bit bounadary, then ASSERT().
389 If Source is NULL, then ASSERT().
390 If Source is not aligned on a 16-bit bounadary, then ASSERT().
391 If Source and Destination overlap, then ASSERT().
392 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
393 than PcdMaximumUnicodeStringLength Unicode characters not including the
394 Null-terminator, then ASSERT().
395 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
396 PcdMaximumUnicodeStringLength Unicode characters not including the
397 Null-terminator, then ASSERT().
398 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
399 and Source results in a Unicode string with more than
400 PcdMaximumUnicodeStringLength Unicode characters not including the
401 Null-terminator, then ASSERT().
403 @param Destination Pointer to a Null-terminated Unicode string.
404 @param Source Pointer to a Null-terminated Unicode string.
412 IN OUT CHAR16
*Destination
,
413 IN CONST CHAR16
*Source
418 Concatenates one Null-terminated Unicode string with a maximum length to the
419 end of another Null-terminated Unicode string, and returns the concatenated
422 This function concatenates two Null-terminated Unicode strings. The contents
423 of Null-terminated Unicode string Source are concatenated to the end of
424 Null-terminated Unicode string Destination, and Destination is returned. At
425 most, Length Unicode characters are concatenated from Source to the end of
426 Destination, and Destination is always Null-terminated. If Length is 0, then
427 Destination is returned unmodified. If Source and Destination overlap, then
428 the results are undefined.
430 If Destination is NULL, then ASSERT().
431 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
432 If Length > 0 and Source is NULL, then ASSERT().
433 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
434 If Source and Destination overlap, then ASSERT().
435 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
436 PcdMaximumUnicodeStringLength, then ASSERT().
437 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
438 than PcdMaximumUnicodeStringLength Unicode characters, not including the
439 Null-terminator, then ASSERT().
440 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
441 PcdMaximumUnicodeStringLength Unicode characters, not including the
442 Null-terminator, then ASSERT().
443 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
444 and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength
445 Unicode characters, not including the Null-terminator, then ASSERT().
447 @param Destination Pointer to a Null-terminated Unicode string.
448 @param Source Pointer to a Null-terminated Unicode string.
449 @param Length Maximum number of Unicode characters to concatenate from
458 IN OUT CHAR16
*Destination
,
459 IN CONST CHAR16
*Source
,
464 Returns the first occurance of a Null-terminated Unicode sub-string
465 in a Null-terminated Unicode string.
467 This function scans the contents of the Null-terminated Unicode string
468 specified by String and returns the first occurrence of SearchString.
469 If SearchString is not found in String, then NULL is returned. If
470 the length of SearchString is zero, then String is
473 If String is NULL, then ASSERT().
474 If String is not aligned on a 16-bit boundary, then ASSERT().
475 If SearchString is NULL, then ASSERT().
476 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
478 If PcdMaximumUnicodeStringLength is not zero, and SearchString
479 or String contains more than PcdMaximumUnicodeStringLength Unicode
480 characters not including the Null-terminator, then ASSERT().
482 @param String Pointer to a Null-terminated Unicode string.
483 @param SearchString Pointer to a Null-terminated Unicode string to search for.
485 @retval NULL If the SearchString does not appear in String.
486 @retval !NULL If there is a match.
492 IN CONST CHAR16
*String
,
493 IN CONST CHAR16
*SearchString
497 Convert a Null-terminated Unicode decimal string to a value of
500 This function returns a value of type UINTN by interpreting the contents
501 of the Unicode string specified by String as a decimal number. The format
502 of the input Unicode string String is:
504 [spaces] [decimal digits].
506 The valid decimal digit character is in the range [0-9]. The
507 function will ignore the pad space, which includes spaces or
508 tab characters, before [decimal digits]. The running zero in the
509 beginning of [decimal digits] will be ignored. Then, the function
510 stops at the first character that is a not a valid decimal character
511 or a Null-terminator, whichever one comes first.
513 If String is NULL, then ASSERT().
514 If String is not aligned in a 16-bit boundary, then ASSERT().
515 If String has only pad spaces, then 0 is returned.
516 If String has no pad spaces or valid decimal digits,
518 If the number represented by String overflows according
519 to the range defined by UINTN, then ASSERT().
521 If PcdMaximumUnicodeStringLength is not zero, and String contains
522 more than PcdMaximumUnicodeStringLength Unicode characters not including
523 the Null-terminator, then ASSERT().
525 @param String Pointer to a Null-terminated Unicode string.
533 IN CONST CHAR16
*String
537 Convert a Null-terminated Unicode decimal string to a value of
540 This function returns a value of type UINT64 by interpreting the contents
541 of the Unicode string specified by String as a decimal number. The format
542 of the input Unicode string String is:
544 [spaces] [decimal digits].
546 The valid decimal digit character is in the range [0-9]. The
547 function will ignore the pad space, which includes spaces or
548 tab characters, before [decimal digits]. The running zero in the
549 beginning of [decimal digits] will be ignored. Then, the function
550 stops at the first character that is a not a valid decimal character
551 or a Null-terminator, whichever one comes first.
553 If String is NULL, then ASSERT().
554 If String is not aligned in a 16-bit boundary, then ASSERT().
555 If String has only pad spaces, then 0 is returned.
556 If String has no pad spaces or valid decimal digits,
558 If the number represented by String overflows according
559 to the range defined by UINT64, then ASSERT().
561 If PcdMaximumUnicodeStringLength is not zero, and String contains
562 more than PcdMaximumUnicodeStringLength Unicode characters not including
563 the Null-terminator, then ASSERT().
565 @param String Pointer to a Null-terminated Unicode string.
573 IN CONST CHAR16
*String
578 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
580 This function returns a value of type UINTN by interpreting the contents
581 of the Unicode string specified by String as a hexadecimal number.
582 The format of the input Unicode string String is:
584 [spaces][zeros][x][hexadecimal digits].
586 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
587 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
588 If "x" appears in the input string, it must be prefixed with at least one 0.
589 The function will ignore the pad space, which includes spaces or tab characters,
590 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
591 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
592 first valid hexadecimal digit. Then, the function stops at the first character that is
593 a not a valid hexadecimal character or NULL, whichever one comes first.
595 If String is NULL, then ASSERT().
596 If String is not aligned in a 16-bit boundary, then ASSERT().
597 If String has only pad spaces, then zero is returned.
598 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
599 then zero is returned.
600 If the number represented by String overflows according to the range defined by
601 UINTN, then ASSERT().
603 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
604 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
607 @param String Pointer to a Null-terminated Unicode string.
615 IN CONST CHAR16
*String
620 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
622 This function returns a value of type UINT64 by interpreting the contents
623 of the Unicode string specified by String as a hexadecimal number.
624 The format of the input Unicode string String is
626 [spaces][zeros][x][hexadecimal digits].
628 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
629 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
630 If "x" appears in the input string, it must be prefixed with at least one 0.
631 The function will ignore the pad space, which includes spaces or tab characters,
632 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
633 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
634 first valid hexadecimal digit. Then, the function stops at the first character that is
635 a not a valid hexadecimal character or NULL, whichever one comes first.
637 If String is NULL, then ASSERT().
638 If String is not aligned in a 16-bit boundary, then ASSERT().
639 If String has only pad spaces, then zero is returned.
640 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
641 then zero is returned.
642 If the number represented by String overflows according to the range defined by
643 UINT64, then ASSERT().
645 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
646 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
649 @param String Pointer to a Null-terminated Unicode string.
657 IN CONST CHAR16
*String
662 Convert one Null-terminated Unicode string to a Null-terminated
663 ASCII string and returns the ASCII string.
665 This function converts the content of the Unicode string Source
666 to the ASCII string Destination by copying the lower 8 bits of
667 each Unicode character. It returns Destination.
669 If any Unicode characters in Source contain non-zero value in
670 the upper 8 bits, then ASSERT().
672 If Destination is NULL, then ASSERT().
673 If Source is NULL, then ASSERT().
674 If Source is not aligned on a 16-bit boundary, then ASSERT().
675 If Source and Destination overlap, then ASSERT().
677 If PcdMaximumUnicodeStringLength is not zero, and Source contains
678 more than PcdMaximumUnicodeStringLength Unicode characters not including
679 the Null-terminator, then ASSERT().
681 If PcdMaximumAsciiStringLength is not zero, and Source contains more
682 than PcdMaximumAsciiStringLength Unicode characters not including the
683 Null-terminator, then ASSERT().
685 @param Source Pointer to a Null-terminated Unicode string.
686 @param Destination Pointer to a Null-terminated ASCII string.
693 UnicodeStrToAsciiStr (
694 IN CONST CHAR16
*Source
,
695 OUT CHAR8
*Destination
700 Copies one Null-terminated ASCII string to another Null-terminated ASCII
701 string and returns the new ASCII string.
703 This function copies the contents of the ASCII string Source to the ASCII
704 string Destination, and returns Destination. If Source and Destination
705 overlap, then the results are undefined.
707 If Destination is NULL, then ASSERT().
708 If Source is NULL, then ASSERT().
709 If Source and Destination overlap, then ASSERT().
710 If PcdMaximumAsciiStringLength is not zero and Source contains more than
711 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
714 @param Destination Pointer to a Null-terminated ASCII string.
715 @param Source Pointer to a Null-terminated ASCII string.
723 OUT CHAR8
*Destination
,
724 IN CONST CHAR8
*Source
729 Copies one Null-terminated ASCII string with a maximum length to another
730 Null-terminated ASCII string with a maximum length and returns the new ASCII
733 This function copies the contents of the ASCII string Source to the ASCII
734 string Destination, and returns Destination. At most, Length ASCII characters
735 are copied from Source to Destination. If Length is 0, then Destination is
736 returned unmodified. If Length is greater that the number of ASCII characters
737 in Source, then Destination is padded with Null ASCII characters. If Source
738 and Destination overlap, then the results are undefined.
740 If Destination is NULL, then ASSERT().
741 If Source is NULL, then ASSERT().
742 If Source and Destination overlap, then ASSERT().
743 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
744 PcdMaximumAsciiStringLength, then ASSERT().
745 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
746 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
749 @param Destination Pointer to a Null-terminated ASCII string.
750 @param Source Pointer to a Null-terminated ASCII string.
751 @param Length Maximum number of ASCII characters to copy.
759 OUT CHAR8
*Destination
,
760 IN CONST CHAR8
*Source
,
766 Returns the length of a Null-terminated ASCII string.
768 This function returns the number of ASCII characters in the Null-terminated
769 ASCII string specified by String.
771 If Length > 0 and Destination is NULL, then ASSERT().
772 If Length > 0 and Source is NULL, then ASSERT().
773 If PcdMaximumAsciiStringLength is not zero and String contains more than
774 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
777 @param String Pointer to a Null-terminated ASCII string.
779 @return The length of String.
785 IN CONST CHAR8
*String
790 Returns the size of a Null-terminated ASCII string in bytes, including the
793 This function returns the size, in bytes, of the Null-terminated ASCII string
796 If String is NULL, then ASSERT().
797 If PcdMaximumAsciiStringLength is not zero and String contains more than
798 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
801 @param String Pointer to a Null-terminated ASCII string.
803 @return The size of String.
809 IN CONST CHAR8
*String
814 Compares two Null-terminated ASCII strings, and returns the difference
815 between the first mismatched ASCII characters.
817 This function compares the Null-terminated ASCII string FirstString to the
818 Null-terminated ASCII string SecondString. If FirstString is identical to
819 SecondString, then 0 is returned. Otherwise, the value returned is the first
820 mismatched ASCII character in SecondString subtracted from the first
821 mismatched ASCII character in FirstString.
823 If FirstString is NULL, then ASSERT().
824 If SecondString is NULL, then ASSERT().
825 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
826 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
828 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
829 than PcdMaximumAsciiStringLength ASCII characters not including the
830 Null-terminator, then ASSERT().
832 @param FirstString Pointer to a Null-terminated ASCII string.
833 @param SecondString Pointer to a Null-terminated ASCII string.
835 @retval 0 FirstString is identical to SecondString.
836 @retval !=0 FirstString is not identical to SecondString.
842 IN CONST CHAR8
*FirstString
,
843 IN CONST CHAR8
*SecondString
848 Performs a case insensitive comparison of two Null-terminated ASCII strings,
849 and returns the difference between the first mismatched ASCII characters.
851 This function performs a case insensitive comparison of the Null-terminated
852 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
853 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
854 value returned is the first mismatched lower case ASCII character in
855 SecondString subtracted from the first mismatched lower case ASCII character
858 If FirstString is NULL, then ASSERT().
859 If SecondString is NULL, then ASSERT().
860 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
861 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
863 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
864 than PcdMaximumAsciiStringLength ASCII characters not including the
865 Null-terminator, then ASSERT().
867 @param FirstString Pointer to a Null-terminated ASCII string.
868 @param SecondString Pointer to a Null-terminated ASCII string.
870 @retval 0 FirstString is identical to SecondString using case insensitive
872 @retval !=0 FirstString is not identical to SecondString using case
873 insensitive comparisons.
879 IN CONST CHAR8
*FirstString
,
880 IN CONST CHAR8
*SecondString
885 Compares two Null-terminated ASCII strings with maximum lengths, and returns
886 the difference between the first mismatched ASCII characters.
888 This function compares the Null-terminated ASCII string FirstString to the
889 Null-terminated ASCII string SecondString. At most, Length ASCII characters
890 will be compared. If Length is 0, then 0 is returned. If FirstString is
891 identical to SecondString, then 0 is returned. Otherwise, the value returned
892 is the first mismatched ASCII character in SecondString subtracted from the
893 first mismatched ASCII character in FirstString.
895 If Length > 0 and FirstString is NULL, then ASSERT().
896 If Length > 0 and SecondString is NULL, then ASSERT().
897 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
898 PcdMaximumAsciiStringLength, then ASSERT().
899 If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than
900 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
902 If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than
903 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
906 @param FirstString Pointer to a Null-terminated ASCII string.
907 @param SecondString Pointer to a Null-terminated ASCII string.
909 @retval 0 FirstString is identical to SecondString.
910 @retval !=0 FirstString is not identical to SecondString.
916 IN CONST CHAR8
*FirstString
,
917 IN CONST CHAR8
*SecondString
,
923 Concatenates one Null-terminated ASCII string to another Null-terminated
924 ASCII string, and returns the concatenated ASCII string.
926 This function concatenates two Null-terminated ASCII strings. The contents of
927 Null-terminated ASCII string Source are concatenated to the end of Null-
928 terminated ASCII string Destination. The Null-terminated concatenated ASCII
931 If Destination is NULL, then ASSERT().
932 If Source is NULL, then ASSERT().
933 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
934 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
936 If PcdMaximumAsciiStringLength is not zero and Source contains more than
937 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
939 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
940 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
941 ASCII characters, then ASSERT().
943 @param Destination Pointer to a Null-terminated ASCII string.
944 @param Source Pointer to a Null-terminated ASCII string.
952 IN OUT CHAR8
*Destination
,
953 IN CONST CHAR8
*Source
958 Concatenates one Null-terminated ASCII string with a maximum length to the
959 end of another Null-terminated ASCII string, and returns the concatenated
962 This function concatenates two Null-terminated ASCII strings. The contents
963 of Null-terminated ASCII string Source are concatenated to the end of Null-
964 terminated ASCII string Destination, and Destination is returned. At most,
965 Length ASCII characters are concatenated from Source to the end of
966 Destination, and Destination is always Null-terminated. If Length is 0, then
967 Destination is returned unmodified. If Source and Destination overlap, then
968 the results are undefined.
970 If Length > 0 and Destination is NULL, then ASSERT().
971 If Length > 0 and Source is NULL, then ASSERT().
972 If Source and Destination overlap, then ASSERT().
973 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
974 PcdMaximumAsciiStringLength, then ASSERT().
975 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
976 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
978 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
979 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
981 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
982 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
983 ASCII characters, not including the Null-terminator, then ASSERT().
985 @param Destination Pointer to a Null-terminated ASCII string.
986 @param Source Pointer to a Null-terminated ASCII string.
987 @param Length Maximum number of ASCII characters to concatenate from
996 IN OUT CHAR8
*Destination
,
997 IN CONST CHAR8
*Source
,
1003 Returns the first occurance of a Null-terminated ASCII sub-string
1004 in a Null-terminated ASCII string.
1006 This function scans the contents of the ASCII string specified by String
1007 and returns the first occurrence of SearchString. If SearchString is not
1008 found in String, then NULL is returned. If the length of SearchString is zero,
1009 then String is returned.
1011 If String is NULL, then ASSERT().
1012 If SearchString is NULL, then ASSERT().
1014 If PcdMaximumAsciiStringLength is not zero, and SearchString or
1015 String contains more than PcdMaximumAsciiStringLength Unicode characters
1016 not including the Null-terminator, then ASSERT().
1018 @param String Pointer to a Null-terminated ASCII string.
1019 @param SearchString Pointer to a Null-terminated ASCII string to search for.
1021 @retval NULL If the SearchString does not appear in String.
1022 @retval !NULL If there is a match.
1028 IN CONST CHAR8
*String
,
1029 IN CONST CHAR8
*SearchString
1034 Convert a Null-terminated ASCII decimal string to a value of type
1037 This function returns a value of type UINTN by interpreting the contents
1038 of the ASCII string String as a decimal number. The format of the input
1039 ASCII string String is:
1041 [spaces] [decimal digits].
1043 The valid decimal digit character is in the range [0-9]. The function will
1044 ignore the pad space, which includes spaces or tab characters, before the digits.
1045 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1046 function stops at the first character that is a not a valid decimal character or
1047 Null-terminator, whichever on comes first.
1049 If String has only pad spaces, then 0 is returned.
1050 If String has no pad spaces or valid decimal digits, then 0 is returned.
1051 If the number represented by String overflows according to the range defined by
1052 UINTN, then ASSERT().
1053 If String is NULL, then ASSERT().
1054 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1055 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1058 @param String Pointer to a Null-terminated ASCII string.
1065 AsciiStrDecimalToUintn (
1066 IN CONST CHAR8
*String
1071 Convert a Null-terminated ASCII decimal string to a value of type
1074 This function returns a value of type UINT64 by interpreting the contents
1075 of the ASCII string String as a decimal number. The format of the input
1076 ASCII string String is:
1078 [spaces] [decimal digits].
1080 The valid decimal digit character is in the range [0-9]. The function will
1081 ignore the pad space, which includes spaces or tab characters, before the digits.
1082 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1083 function stops at the first character that is a not a valid decimal character or
1084 Null-terminator, whichever on comes first.
1086 If String has only pad spaces, then 0 is returned.
1087 If String has no pad spaces or valid decimal digits, then 0 is returned.
1088 If the number represented by String overflows according to the range defined by
1089 UINT64, then ASSERT().
1090 If String is NULL, then ASSERT().
1091 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1092 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1095 @param String Pointer to a Null-terminated ASCII string.
1102 AsciiStrDecimalToUint64 (
1103 IN CONST CHAR8
*String
1108 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1110 This function returns a value of type UINTN by interpreting the contents of
1111 the ASCII string String as a hexadecimal number. The format of the input ASCII
1114 [spaces][zeros][x][hexadecimal digits].
1116 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1117 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1118 appears in the input string, it must be prefixed with at least one 0. The function
1119 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1120 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1121 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1122 digit. Then, the function stops at the first character that is a not a valid
1123 hexadecimal character or Null-terminator, whichever on comes first.
1125 If String has only pad spaces, then 0 is returned.
1126 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1129 If the number represented by String overflows according to the range defined by UINTN,
1131 If String is NULL, then ASSERT().
1132 If PcdMaximumAsciiStringLength is not zero,
1133 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1134 the Null-terminator, then ASSERT().
1136 @param String Pointer to a Null-terminated ASCII string.
1143 AsciiStrHexToUintn (
1144 IN CONST CHAR8
*String
1149 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1151 This function returns a value of type UINT64 by interpreting the contents of
1152 the ASCII string String as a hexadecimal number. The format of the input ASCII
1155 [spaces][zeros][x][hexadecimal digits].
1157 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1158 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1159 appears in the input string, it must be prefixed with at least one 0. The function
1160 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1161 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1162 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1163 digit. Then, the function stops at the first character that is a not a valid
1164 hexadecimal character or Null-terminator, whichever on comes first.
1166 If String has only pad spaces, then 0 is returned.
1167 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1170 If the number represented by String overflows according to the range defined by UINT64,
1172 If String is NULL, then ASSERT().
1173 If PcdMaximumAsciiStringLength is not zero,
1174 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1175 the Null-terminator, then ASSERT().
1177 @param String Pointer to a Null-terminated ASCII string.
1184 AsciiStrHexToUint64 (
1185 IN CONST CHAR8
*String
1190 Convert one Null-terminated ASCII string to a Null-terminated
1191 Unicode string and returns the Unicode string.
1193 This function converts the contents of the ASCII string Source to the Unicode
1194 string Destination, and returns Destination. The function terminates the
1195 Unicode string Destination by appending a Null-terminator character at the end.
1196 The caller is responsible to make sure Destination points to a buffer with size
1197 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1199 If Destination is NULL, then ASSERT().
1200 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1201 If Source is NULL, then ASSERT().
1202 If Source and Destination overlap, then ASSERT().
1203 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1204 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1206 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1207 PcdMaximumUnicodeStringLength ASCII characters not including the
1208 Null-terminator, then ASSERT().
1210 @param Source Pointer to a Null-terminated ASCII string.
1211 @param Destination Pointer to a Null-terminated Unicode string.
1218 AsciiStrToUnicodeStr (
1219 IN CONST CHAR8
*Source
,
1220 OUT CHAR16
*Destination
1225 Converts an 8-bit value to an 8-bit BCD value.
1227 Converts the 8-bit value specified by Value to BCD. The BCD value is
1230 If Value >= 100, then ASSERT().
1232 @param Value The 8-bit value to convert to BCD. Range 0..99.
1234 @return The BCD value
1245 Converts an 8-bit BCD value to an 8-bit value.
1247 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
1250 If Value >= 0xA0, then ASSERT().
1251 If (Value & 0x0F) >= 0x0A, then ASSERT().
1253 @param Value The 8-bit BCD value to convert to an 8-bit value.
1255 @return The 8-bit value is returned.
1265 // LIST_ENTRY definition
1267 typedef struct _LIST_ENTRY LIST_ENTRY
;
1269 struct _LIST_ENTRY
{
1270 LIST_ENTRY
*ForwardLink
;
1271 LIST_ENTRY
*BackLink
;
1275 // Linked List Functions and Macros
1279 Initializes the head node of a doubly linked list that is declared as a
1280 global variable in a module.
1282 Initializes the forward and backward links of a new linked list. After
1283 initializing a linked list with this macro, the other linked list functions
1284 may be used to add and remove nodes from the linked list. This macro results
1285 in smaller executables by initializing the linked list in the data section,
1286 instead if calling the InitializeListHead() function to perform the
1287 equivalent operation.
1289 @param ListHead The head note of a list to initiailize.
1292 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
1296 Initializes the head node of a doubly linked list, and returns the pointer to
1297 the head node of the doubly linked list.
1299 Initializes the forward and backward links of a new linked list. After
1300 initializing a linked list with this function, the other linked list
1301 functions may be used to add and remove nodes from the linked list. It is up
1302 to the caller of this function to allocate the memory for ListHead.
1304 If ListHead is NULL, then ASSERT().
1306 @param ListHead A pointer to the head node of a new doubly linked list.
1313 GlueInitializeListHead (
1314 IN LIST_ENTRY
*ListHead
1319 Adds a node to the beginning of a doubly linked list, and returns the pointer
1320 to the head node of the doubly linked list.
1322 Adds the node Entry at the beginning of the doubly linked list denoted by
1323 ListHead, and returns ListHead.
1325 If ListHead is NULL, then ASSERT().
1326 If Entry is NULL, then ASSERT().
1327 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1328 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1329 of nodes in ListHead, including the ListHead node, is greater than or
1330 equal to PcdMaximumLinkedListLength, then ASSERT().
1332 @param ListHead A pointer to the head node of a doubly linked list.
1333 @param Entry A pointer to a node that is to be inserted at the beginning
1334 of a doubly linked list.
1341 GlueInsertHeadList (
1342 IN LIST_ENTRY
*ListHead
,
1343 IN LIST_ENTRY
*Entry
1348 Adds a node to the end of a doubly linked list, and returns the pointer to
1349 the head node of the doubly linked list.
1351 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
1352 and returns ListHead.
1354 If ListHead is NULL, then ASSERT().
1355 If Entry is NULL, then ASSERT().
1356 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1357 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1358 of nodes in ListHead, including the ListHead node, is greater than or
1359 equal to PcdMaximumLinkedListLength, then ASSERT().
1361 @param ListHead A pointer to the head node of a doubly linked list.
1362 @param Entry A pointer to a node that is to be added at the end of the
1370 GlueInsertTailList (
1371 IN LIST_ENTRY
*ListHead
,
1372 IN LIST_ENTRY
*Entry
1377 Retrieves the first node of a doubly linked list.
1379 Returns the first node of a doubly linked list. List must have been
1380 initialized with InitializeListHead(). If List is empty, then NULL is
1383 If List is NULL, then ASSERT().
1384 If List was not initialized with InitializeListHead(), then ASSERT().
1385 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1386 in List, including the List node, is greater than or equal to
1387 PcdMaximumLinkedListLength, then ASSERT().
1389 @param List A pointer to the head node of a doubly linked list.
1391 @return The first node of a doubly linked list.
1392 @retval NULL The list is empty.
1398 IN CONST LIST_ENTRY
*List
1403 Retrieves the next node of a doubly linked list.
1405 Returns the node of a doubly linked list that follows Node. List must have
1406 been initialized with InitializeListHead(). If List is empty, then List is
1409 If List is NULL, then ASSERT().
1410 If Node is NULL, then ASSERT().
1411 If List was not initialized with InitializeListHead(), then ASSERT().
1412 If PcdMaximumLinkedListLenth is not zero, and List contains more than
1413 PcdMaximumLinkedListLenth nodes, then ASSERT().
1414 If Node is not a node in List, then ASSERT().
1416 @param List A pointer to the head node of a doubly linked list.
1417 @param Node A pointer to a node in the doubly linked list.
1419 @return Pointer to the next node if one exists. Otherwise a null value which
1420 is actually List is returned.
1426 IN CONST LIST_ENTRY
*List
,
1427 IN CONST LIST_ENTRY
*Node
1432 Checks to see if a doubly linked list is empty or not.
1434 Checks to see if the doubly linked list is empty. If the linked list contains
1435 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
1437 If ListHead is NULL, then ASSERT().
1438 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1439 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1440 in List, including the List node, is greater than or equal to
1441 PcdMaximumLinkedListLength, then ASSERT().
1443 @param ListHead A pointer to the head node of a doubly linked list.
1445 @retval TRUE The linked list is empty.
1446 @retval FALSE The linked list is not empty.
1452 IN CONST LIST_ENTRY
*ListHead
1457 Determines if a node in a doubly linked list is null.
1459 Returns FALSE if Node is one of the nodes in the doubly linked list specified
1460 by List. Otherwise, TRUE is returned. List must have been initialized with
1461 InitializeListHead().
1463 If List is NULL, then ASSERT().
1464 If Node is NULL, then ASSERT().
1465 If List was not initialized with InitializeListHead(), then ASSERT().
1466 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1467 in List, including the List node, is greater than or equal to
1468 PcdMaximumLinkedListLength, then ASSERT().
1469 If Node is not a node in List and Node is not equal to List, then ASSERT().
1471 @param List A pointer to the head node of a doubly linked list.
1472 @param Node A pointer to a node in the doubly linked list.
1474 @retval TRUE Node is one of the nodes in the doubly linked list.
1475 @retval FALSE Node is not one of the nodes in the doubly linked list.
1481 IN CONST LIST_ENTRY
*List
,
1482 IN CONST LIST_ENTRY
*Node
1487 Determines if a node the last node in a doubly linked list.
1489 Returns TRUE if Node is the last node in the doubly linked list specified by
1490 List. Otherwise, FALSE is returned. List must have been initialized with
1491 InitializeListHead().
1493 If List is NULL, then ASSERT().
1494 If Node is NULL, then ASSERT().
1495 If List was not initialized with InitializeListHead(), then ASSERT().
1496 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1497 in List, including the List node, is greater than or equal to
1498 PcdMaximumLinkedListLength, then ASSERT().
1499 If Node is not a node in List, then ASSERT().
1501 @param List A pointer to the head node of a doubly linked list.
1502 @param Node A pointer to a node in the doubly linked list.
1504 @retval TRUE Node is the last node in the linked list.
1505 @retval FALSE Node is not the last node in the linked list.
1511 IN CONST LIST_ENTRY
*List
,
1512 IN CONST LIST_ENTRY
*Node
1517 Swaps the location of two nodes in a doubly linked list, and returns the
1518 first node after the swap.
1520 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
1521 Otherwise, the location of the FirstEntry node is swapped with the location
1522 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
1523 same double linked list as FirstEntry and that double linked list must have
1524 been initialized with InitializeListHead(). SecondEntry is returned after the
1527 If FirstEntry is NULL, then ASSERT().
1528 If SecondEntry is NULL, then ASSERT().
1529 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
1530 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1531 linked list containing the FirstEntry and SecondEntry nodes, including
1532 the FirstEntry and SecondEntry nodes, is greater than or equal to
1533 PcdMaximumLinkedListLength, then ASSERT().
1535 @param FirstEntry A pointer to a node in a linked list.
1536 @param SecondEntry A pointer to another node in the same linked list.
1541 GlueSwapListEntries (
1542 IN LIST_ENTRY
*FirstEntry
,
1543 IN LIST_ENTRY
*SecondEntry
1548 Removes a node from a doubly linked list, and returns the node that follows
1551 Removes the node Entry from a doubly linked list. It is up to the caller of
1552 this function to release the memory used by this node if that is required. On
1553 exit, the node following Entry in the doubly linked list is returned. If
1554 Entry is the only node in the linked list, then the head node of the linked
1557 If Entry is NULL, then ASSERT().
1558 If Entry is the head node of an empty list, then ASSERT().
1559 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1560 linked list containing Entry, including the Entry node, is greater than
1561 or equal to PcdMaximumLinkedListLength, then ASSERT().
1563 @param Entry A pointer to a node in a linked list
1570 GlueRemoveEntryList (
1571 IN CONST LIST_ENTRY
*Entry
1579 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
1580 with zeros. The shifted value is returned.
1582 This function shifts the 64-bit value Operand to the left by Count bits. The
1583 low Count bits are set to zero. The shifted value is returned.
1585 If Count is greater than 63, then ASSERT().
1587 @param Operand The 64-bit operand to shift left.
1588 @param Count The number of bits to shift left.
1590 @return Operand << Count
1602 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1603 filled with zeros. The shifted value is returned.
1605 This function shifts the 64-bit value Operand to the right by Count bits. The
1606 high Count bits are set to zero. The shifted value is returned.
1608 If Count is greater than 63, then ASSERT().
1610 @param Operand The 64-bit operand to shift right.
1611 @param Count The number of bits to shift right.
1613 @return Operand >> Count
1625 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1626 with original integer's bit 63. The shifted value is returned.
1628 This function shifts the 64-bit value Operand to the right by Count bits. The
1629 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1631 If Count is greater than 63, then ASSERT().
1633 @param Operand The 64-bit operand to shift right.
1634 @param Count The number of bits to shift right.
1636 @return Operand >> Count
1648 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1649 with the high bits that were rotated.
1651 This function rotates the 32-bit value Operand to the left by Count bits. The
1652 low Count bits are fill with the high Count bits of Operand. The rotated
1655 If Count is greater than 31, then ASSERT().
1657 @param Operand The 32-bit operand to rotate left.
1658 @param Count The number of bits to rotate left.
1660 @return Operand <<< Count
1672 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1673 with the low bits that were rotated.
1675 This function rotates the 32-bit value Operand to the right by Count bits.
1676 The high Count bits are fill with the low Count bits of Operand. The rotated
1679 If Count is greater than 31, then ASSERT().
1681 @param Operand The 32-bit operand to rotate right.
1682 @param Count The number of bits to rotate right.
1684 @return Operand >>> Count
1696 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1697 with the high bits that were rotated.
1699 This function rotates the 64-bit value Operand to the left by Count bits. The
1700 low Count bits are fill with the high Count bits of Operand. The rotated
1703 If Count is greater than 63, then ASSERT().
1705 @param Operand The 64-bit operand to rotate left.
1706 @param Count The number of bits to rotate left.
1708 @return Operand <<< Count
1720 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1721 with the high low bits that were rotated.
1723 This function rotates the 64-bit value Operand to the right by Count bits.
1724 The high Count bits are fill with the low Count bits of Operand. The rotated
1727 If Count is greater than 63, then ASSERT().
1729 @param Operand The 64-bit operand to rotate right.
1730 @param Count The number of bits to rotate right.
1732 @return Operand >>> Count
1744 Returns the bit position of the lowest bit set in a 32-bit value.
1746 This function computes the bit position of the lowest bit set in the 32-bit
1747 value specified by Operand. If Operand is zero, then -1 is returned.
1748 Otherwise, a value between 0 and 31 is returned.
1750 @param Operand The 32-bit operand to evaluate.
1752 @return Position of the lowest bit set in Operand if found.
1753 @retval -1 Operand is zero.
1764 Returns the bit position of the lowest bit set in a 64-bit value.
1766 This function computes the bit position of the lowest bit set in the 64-bit
1767 value specified by Operand. If Operand is zero, then -1 is returned.
1768 Otherwise, a value between 0 and 63 is returned.
1770 @param Operand The 64-bit operand to evaluate.
1772 @return Position of the lowest bit set in Operand if found.
1773 @retval -1 Operand is zero.
1784 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1787 This function computes the bit position of the highest bit set in the 32-bit
1788 value specified by Operand. If Operand is zero, then -1 is returned.
1789 Otherwise, a value between 0 and 31 is returned.
1791 @param Operand The 32-bit operand to evaluate.
1793 @return Position of the highest bit set in Operand if found.
1794 @retval -1 Operand is zero.
1805 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1808 This function computes the bit position of the highest bit set in the 64-bit
1809 value specified by Operand. If Operand is zero, then -1 is returned.
1810 Otherwise, a value between 0 and 63 is returned.
1812 @param Operand The 64-bit operand to evaluate.
1814 @return Position of the highest bit set in Operand if found.
1815 @retval -1 Operand is zero.
1826 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1827 1 << HighBitSet32(x).
1829 This function computes the value of the highest bit set in the 32-bit value
1830 specified by Operand. If Operand is zero, then zero is returned.
1832 @param Operand The 32-bit operand to evaluate.
1834 @return 1 << HighBitSet32(Operand)
1835 @retval 0 Operand is zero.
1846 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1847 1 << HighBitSet64(x).
1849 This function computes the value of the highest bit set in the 64-bit value
1850 specified by Operand. If Operand is zero, then zero is returned.
1852 @param Operand The 64-bit operand to evaluate.
1854 @return 1 << HighBitSet64(Operand)
1855 @retval 0 Operand is zero.
1866 Switches the endianess of a 16-bit integer.
1868 This function swaps the bytes in a 16-bit unsigned value to switch the value
1869 from little endian to big endian or vice versa. The byte swapped value is
1872 @param Operand A 16-bit unsigned value.
1874 @return The byte swaped Operand.
1885 Switches the endianess of a 32-bit integer.
1887 This function swaps the bytes in a 32-bit unsigned value to switch the value
1888 from little endian to big endian or vice versa. The byte swapped value is
1891 @param Operand A 32-bit unsigned value.
1893 @return The byte swaped Operand.
1904 Switches the endianess of a 64-bit integer.
1906 This function swaps the bytes in a 64-bit unsigned value to switch the value
1907 from little endian to big endian or vice versa. The byte swapped value is
1910 @param Operand A 64-bit unsigned value.
1912 @return The byte swaped Operand.
1923 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1924 generates a 64-bit unsigned result.
1926 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1927 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1928 bit unsigned result is returned.
1930 If the result overflows, then ASSERT().
1932 @param Multiplicand A 64-bit unsigned value.
1933 @param Multiplier A 32-bit unsigned value.
1935 @return Multiplicand * Multiplier
1941 IN UINT64 Multiplicand
,
1942 IN UINT32 Multiplier
1947 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1948 generates a 64-bit unsigned result.
1950 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1951 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1952 bit unsigned result is returned.
1954 If the result overflows, then ASSERT().
1956 @param Multiplicand A 64-bit unsigned value.
1957 @param Multiplier A 64-bit unsigned value.
1959 @return Multiplicand * Multiplier
1965 IN UINT64 Multiplicand
,
1966 IN UINT64 Multiplier
1971 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1972 64-bit signed result.
1974 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1975 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1976 signed result is returned.
1978 If the result overflows, then ASSERT().
1980 @param Multiplicand A 64-bit signed value.
1981 @param Multiplier A 64-bit signed value.
1983 @return Multiplicand * Multiplier
1989 IN INT64 Multiplicand
,
1995 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1996 a 64-bit unsigned result.
1998 This function divides the 64-bit unsigned value Dividend by the 32-bit
1999 unsigned value Divisor and generates a 64-bit unsigned quotient. This
2000 function returns the 64-bit unsigned quotient.
2002 If Divisor is 0, then ASSERT().
2004 @param Dividend A 64-bit unsigned value.
2005 @param Divisor A 32-bit unsigned value.
2007 @return Dividend / Divisor
2019 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
2020 a 32-bit unsigned remainder.
2022 This function divides the 64-bit unsigned value Dividend by the 32-bit
2023 unsigned value Divisor and generates a 32-bit remainder. This function
2024 returns the 32-bit unsigned remainder.
2026 If Divisor is 0, then ASSERT().
2028 @param Dividend A 64-bit unsigned value.
2029 @param Divisor A 32-bit unsigned value.
2031 @return Dividend % Divisor
2043 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
2044 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
2046 This function divides the 64-bit unsigned value Dividend by the 32-bit
2047 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2048 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
2049 This function returns the 64-bit unsigned quotient.
2051 If Divisor is 0, then ASSERT().
2053 @param Dividend A 64-bit unsigned value.
2054 @param Divisor A 32-bit unsigned value.
2055 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
2056 optional and may be NULL.
2058 @return Dividend / Divisor
2063 DivU64x32Remainder (
2066 OUT UINT32
*Remainder OPTIONAL
2071 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
2072 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
2074 This function divides the 64-bit unsigned value Dividend by the 64-bit
2075 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2076 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
2077 This function returns the 64-bit unsigned quotient.
2079 If Divisor is 0, then ASSERT().
2081 @param Dividend A 64-bit unsigned value.
2082 @param Divisor A 64-bit unsigned value.
2083 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
2084 optional and may be NULL.
2086 @return Dividend / Divisor
2091 DivU64x64Remainder (
2094 OUT UINT64
*Remainder OPTIONAL
2099 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
2100 64-bit signed result and a optional 64-bit signed remainder.
2102 This function divides the 64-bit signed value Dividend by the 64-bit signed
2103 value Divisor and generates a 64-bit signed quotient. If Remainder is not
2104 NULL, then the 64-bit signed remainder is returned in Remainder. This
2105 function returns the 64-bit signed quotient.
2107 If Divisor is 0, then ASSERT().
2109 @param Dividend A 64-bit signed value.
2110 @param Divisor A 64-bit signed value.
2111 @param Remainder A pointer to a 64-bit signed value. This parameter is
2112 optional and may be NULL.
2114 @return Dividend / Divisor
2119 DivS64x64Remainder (
2122 OUT INT64
*Remainder OPTIONAL
2127 Reads a 16-bit value from memory that may be unaligned.
2129 This function returns the 16-bit value pointed to by Buffer. The function
2130 guarantees that the read operation does not produce an alignment fault.
2132 If the Buffer is NULL, then ASSERT().
2134 @param Buffer Pointer to a 16-bit value that may be unaligned.
2142 IN CONST UINT16
*Uint16
2147 Writes a 16-bit value to memory that may be unaligned.
2149 This function writes the 16-bit value specified by Value to Buffer. Value is
2150 returned. The function guarantees that the write operation does not produce
2153 If the Buffer is NULL, then ASSERT().
2155 @param Buffer Pointer to a 16-bit value that may be unaligned.
2156 @param Value 16-bit value to write to Buffer.
2170 Reads a 24-bit value from memory that may be unaligned.
2172 This function returns the 24-bit value pointed to by Buffer. The function
2173 guarantees that the read operation does not produce an alignment fault.
2175 If the Buffer is NULL, then ASSERT().
2177 @param Buffer Pointer to a 24-bit value that may be unaligned.
2179 @return The value read.
2185 IN CONST UINT32
*Buffer
2190 Writes a 24-bit value to memory that may be unaligned.
2192 This function writes the 24-bit value specified by Value to Buffer. Value is
2193 returned. The function guarantees that the write operation does not produce
2196 If the Buffer is NULL, then ASSERT().
2198 @param Buffer Pointer to a 24-bit value that may be unaligned.
2199 @param Value 24-bit value to write to Buffer.
2201 @return The value written.
2213 Reads a 32-bit value from memory that may be unaligned.
2215 This function returns the 32-bit value pointed to by Buffer. The function
2216 guarantees that the read operation does not produce an alignment fault.
2218 If the Buffer is NULL, then ASSERT().
2220 @param Buffer Pointer to a 32-bit value that may be unaligned.
2228 IN CONST UINT32
*Uint32
2233 Writes a 32-bit value to memory that may be unaligned.
2235 This function writes the 32-bit value specified by Value to Buffer. Value is
2236 returned. The function guarantees that the write operation does not produce
2239 If the Buffer is NULL, then ASSERT().
2241 @param Buffer Pointer to a 32-bit value that may be unaligned.
2242 @param Value 32-bit value to write to Buffer.
2256 Reads a 64-bit value from memory that may be unaligned.
2258 This function returns the 64-bit value pointed to by Buffer. The function
2259 guarantees that the read operation does not produce an alignment fault.
2261 If the Buffer is NULL, then ASSERT().
2263 @param Buffer Pointer to a 64-bit value that may be unaligned.
2271 IN CONST UINT64
*Uint64
2276 Writes a 64-bit value to memory that may be unaligned.
2278 This function writes the 64-bit value specified by Value to Buffer. Value is
2279 returned. The function guarantees that the write operation does not produce
2282 If the Buffer is NULL, then ASSERT().
2284 @param Buffer Pointer to a 64-bit value that may be unaligned.
2285 @param Value 64-bit value to write to Buffer.
2299 // Bit Field Functions
2303 Returns a bit field from an 8-bit value.
2305 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2307 If 8-bit operations are not supported, then ASSERT().
2308 If StartBit is greater than 7, then ASSERT().
2309 If EndBit is greater than 7, then ASSERT().
2310 If EndBit is less than StartBit, then ASSERT().
2312 @param Operand Operand on which to perform the bitfield operation.
2313 @param StartBit The ordinal of the least significant bit in the bit field.
2315 @param EndBit The ordinal of the most significant bit in the bit field.
2318 @return The bit field read.
2331 Writes a bit field to an 8-bit value, and returns the result.
2333 Writes Value to the bit field specified by the StartBit and the EndBit in
2334 Operand. All other bits in Operand are preserved. The new 8-bit value is
2337 If 8-bit operations are not supported, then ASSERT().
2338 If StartBit is greater than 7, then ASSERT().
2339 If EndBit is greater than 7, then ASSERT().
2340 If EndBit is less than StartBit, then ASSERT().
2342 @param Operand Operand on which to perform the bitfield operation.
2343 @param StartBit The ordinal of the least significant bit in the bit field.
2345 @param EndBit The ordinal of the most significant bit in the bit field.
2347 @param Value New value of the bit field.
2349 @return The new 8-bit value.
2363 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
2366 Performs a bitwise inclusive OR between the bit field specified by StartBit
2367 and EndBit in Operand and the value specified by OrData. All other bits in
2368 Operand are preserved. The new 8-bit value is returned.
2370 If 8-bit operations are not supported, then ASSERT().
2371 If StartBit is greater than 7, then ASSERT().
2372 If EndBit is greater than 7, then ASSERT().
2373 If EndBit is less than StartBit, then ASSERT().
2375 @param Operand Operand on which to perform the bitfield operation.
2376 @param StartBit The ordinal of the least significant bit in the bit field.
2378 @param EndBit The ordinal of the most significant bit in the bit field.
2380 @param OrData The value to OR with the read value from the value
2382 @return The new 8-bit value.
2396 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
2399 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2400 in Operand and the value specified by AndData. All other bits in Operand are
2401 preserved. The new 8-bit value is returned.
2403 If 8-bit operations are not supported, then ASSERT().
2404 If StartBit is greater than 7, then ASSERT().
2405 If EndBit is greater than 7, then ASSERT().
2406 If EndBit is less than StartBit, then ASSERT().
2408 @param Operand Operand on which to perform the bitfield operation.
2409 @param StartBit The ordinal of the least significant bit in the bit field.
2411 @param EndBit The ordinal of the most significant bit in the bit field.
2413 @param AndData The value to AND with the read value from the value.
2415 @return The new 8-bit value.
2429 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
2430 bitwise OR, and returns the result.
2432 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2433 in Operand and the value specified by AndData, followed by a bitwise
2434 inclusive OR with value specified by OrData. All other bits in Operand are
2435 preserved. The new 8-bit value is returned.
2437 If 8-bit operations are not supported, then ASSERT().
2438 If StartBit is greater than 7, then ASSERT().
2439 If EndBit is greater than 7, then ASSERT().
2440 If EndBit is less than StartBit, then ASSERT().
2442 @param Operand Operand on which to perform the bitfield operation.
2443 @param StartBit The ordinal of the least significant bit in the bit field.
2445 @param EndBit The ordinal of the most significant bit in the bit field.
2447 @param AndData The value to AND with the read value from the value.
2448 @param OrData The value to OR with the result of the AND operation.
2450 @return The new 8-bit value.
2455 BitFieldAndThenOr8 (
2465 Returns a bit field from a 16-bit value.
2467 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2469 If 16-bit operations are not supported, then ASSERT().
2470 If StartBit is greater than 15, then ASSERT().
2471 If EndBit is greater than 15, then ASSERT().
2472 If EndBit is less than StartBit, then ASSERT().
2474 @param Operand Operand on which to perform the bitfield operation.
2475 @param StartBit The ordinal of the least significant bit in the bit field.
2477 @param EndBit The ordinal of the most significant bit in the bit field.
2480 @return The bit field read.
2493 Writes a bit field to a 16-bit value, and returns the result.
2495 Writes Value to the bit field specified by the StartBit and the EndBit in
2496 Operand. All other bits in Operand are preserved. The new 16-bit value is
2499 If 16-bit operations are not supported, then ASSERT().
2500 If StartBit is greater than 15, then ASSERT().
2501 If EndBit is greater than 15, then ASSERT().
2502 If EndBit is less than StartBit, then ASSERT().
2504 @param Operand Operand on which to perform the bitfield operation.
2505 @param StartBit The ordinal of the least significant bit in the bit field.
2507 @param EndBit The ordinal of the most significant bit in the bit field.
2509 @param Value New value of the bit field.
2511 @return The new 16-bit value.
2525 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
2528 Performs a bitwise inclusive OR between the bit field specified by StartBit
2529 and EndBit in Operand and the value specified by OrData. All other bits in
2530 Operand are preserved. The new 16-bit value is returned.
2532 If 16-bit operations are not supported, then ASSERT().
2533 If StartBit is greater than 15, then ASSERT().
2534 If EndBit is greater than 15, then ASSERT().
2535 If EndBit is less than StartBit, then ASSERT().
2537 @param Operand Operand on which to perform the bitfield operation.
2538 @param StartBit The ordinal of the least significant bit in the bit field.
2540 @param EndBit The ordinal of the most significant bit in the bit field.
2542 @param OrData The value to OR with the read value from the value
2544 @return The new 16-bit value.
2558 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
2561 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2562 in Operand and the value specified by AndData. All other bits in Operand are
2563 preserved. The new 16-bit value is returned.
2565 If 16-bit operations are not supported, then ASSERT().
2566 If StartBit is greater than 15, then ASSERT().
2567 If EndBit is greater than 15, then ASSERT().
2568 If EndBit is less than StartBit, then ASSERT().
2570 @param Operand Operand on which to perform the bitfield operation.
2571 @param StartBit The ordinal of the least significant bit in the bit field.
2573 @param EndBit The ordinal of the most significant bit in the bit field.
2575 @param AndData The value to AND with the read value from the value
2577 @return The new 16-bit value.
2591 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
2592 bitwise OR, and returns the result.
2594 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2595 in Operand and the value specified by AndData, followed by a bitwise
2596 inclusive OR with value specified by OrData. All other bits in Operand are
2597 preserved. The new 16-bit value is returned.
2599 If 16-bit operations are not supported, then ASSERT().
2600 If StartBit is greater than 15, then ASSERT().
2601 If EndBit is greater than 15, then ASSERT().
2602 If EndBit is less than StartBit, then ASSERT().
2604 @param Operand Operand on which to perform the bitfield operation.
2605 @param StartBit The ordinal of the least significant bit in the bit field.
2607 @param EndBit The ordinal of the most significant bit in the bit field.
2609 @param AndData The value to AND with the read value from the value.
2610 @param OrData The value to OR with the result of the AND operation.
2612 @return The new 16-bit value.
2617 BitFieldAndThenOr16 (
2627 Returns a bit field from a 32-bit value.
2629 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2631 If 32-bit operations are not supported, then ASSERT().
2632 If StartBit is greater than 31, then ASSERT().
2633 If EndBit is greater than 31, then ASSERT().
2634 If EndBit is less than StartBit, then ASSERT().
2636 @param Operand Operand on which to perform the bitfield operation.
2637 @param StartBit The ordinal of the least significant bit in the bit field.
2639 @param EndBit The ordinal of the most significant bit in the bit field.
2642 @return The bit field read.
2655 Writes a bit field to a 32-bit value, and returns the result.
2657 Writes Value to the bit field specified by the StartBit and the EndBit in
2658 Operand. All other bits in Operand are preserved. The new 32-bit value is
2661 If 32-bit operations are not supported, then ASSERT().
2662 If StartBit is greater than 31, then ASSERT().
2663 If EndBit is greater than 31, then ASSERT().
2664 If EndBit is less than StartBit, then ASSERT().
2666 @param Operand Operand on which to perform the bitfield operation.
2667 @param StartBit The ordinal of the least significant bit in the bit field.
2669 @param EndBit The ordinal of the most significant bit in the bit field.
2671 @param Value New value of the bit field.
2673 @return The new 32-bit value.
2687 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2690 Performs a bitwise inclusive OR between the bit field specified by StartBit
2691 and EndBit in Operand and the value specified by OrData. All other bits in
2692 Operand are preserved. The new 32-bit value is returned.
2694 If 32-bit operations are not supported, then ASSERT().
2695 If StartBit is greater than 31, then ASSERT().
2696 If EndBit is greater than 31, then ASSERT().
2697 If EndBit is less than StartBit, then ASSERT().
2699 @param Operand Operand on which to perform the bitfield operation.
2700 @param StartBit The ordinal of the least significant bit in the bit field.
2702 @param EndBit The ordinal of the most significant bit in the bit field.
2704 @param OrData The value to OR with the read value from the value
2706 @return The new 32-bit value.
2720 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2723 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2724 in Operand and the value specified by AndData. All other bits in Operand are
2725 preserved. The new 32-bit value is returned.
2727 If 32-bit operations are not supported, then ASSERT().
2728 If StartBit is greater than 31, then ASSERT().
2729 If EndBit is greater than 31, then ASSERT().
2730 If EndBit is less than StartBit, then ASSERT().
2732 @param Operand Operand on which to perform the bitfield operation.
2733 @param StartBit The ordinal of the least significant bit in the bit field.
2735 @param EndBit The ordinal of the most significant bit in the bit field.
2737 @param AndData The value to AND with the read value from the value
2739 @return The new 32-bit value.
2753 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2754 bitwise OR, and returns the result.
2756 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2757 in Operand and the value specified by AndData, followed by a bitwise
2758 inclusive OR with value specified by OrData. All other bits in Operand are
2759 preserved. The new 32-bit value is returned.
2761 If 32-bit operations are not supported, then ASSERT().
2762 If StartBit is greater than 31, then ASSERT().
2763 If EndBit is greater than 31, then ASSERT().
2764 If EndBit is less than StartBit, then ASSERT().
2766 @param Operand Operand on which to perform the bitfield operation.
2767 @param StartBit The ordinal of the least significant bit in the bit field.
2769 @param EndBit The ordinal of the most significant bit in the bit field.
2771 @param AndData The value to AND with the read value from the value.
2772 @param OrData The value to OR with the result of the AND operation.
2774 @return The new 32-bit value.
2779 BitFieldAndThenOr32 (
2789 Returns a bit field from a 64-bit value.
2791 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2793 If 64-bit operations are not supported, then ASSERT().
2794 If StartBit is greater than 63, then ASSERT().
2795 If EndBit is greater than 63, then ASSERT().
2796 If EndBit is less than StartBit, then ASSERT().
2798 @param Operand Operand on which to perform the bitfield operation.
2799 @param StartBit The ordinal of the least significant bit in the bit field.
2801 @param EndBit The ordinal of the most significant bit in the bit field.
2804 @return The bit field read.
2817 Writes a bit field to a 64-bit value, and returns the result.
2819 Writes Value to the bit field specified by the StartBit and the EndBit in
2820 Operand. All other bits in Operand are preserved. The new 64-bit value is
2823 If 64-bit operations are not supported, then ASSERT().
2824 If StartBit is greater than 63, then ASSERT().
2825 If EndBit is greater than 63, then ASSERT().
2826 If EndBit is less than StartBit, then ASSERT().
2828 @param Operand Operand on which to perform the bitfield operation.
2829 @param StartBit The ordinal of the least significant bit in the bit field.
2831 @param EndBit The ordinal of the most significant bit in the bit field.
2833 @param Value New value of the bit field.
2835 @return The new 64-bit value.
2849 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2852 Performs a bitwise inclusive OR between the bit field specified by StartBit
2853 and EndBit in Operand and the value specified by OrData. All other bits in
2854 Operand are preserved. The new 64-bit value is returned.
2856 If 64-bit operations are not supported, then ASSERT().
2857 If StartBit is greater than 63, then ASSERT().
2858 If EndBit is greater than 63, then ASSERT().
2859 If EndBit is less than StartBit, then ASSERT().
2861 @param Operand Operand on which to perform the bitfield operation.
2862 @param StartBit The ordinal of the least significant bit in the bit field.
2864 @param EndBit The ordinal of the most significant bit in the bit field.
2866 @param OrData The value to OR with the read value from the value
2868 @return The new 64-bit value.
2882 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2885 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2886 in Operand and the value specified by AndData. All other bits in Operand are
2887 preserved. The new 64-bit value is returned.
2889 If 64-bit operations are not supported, then ASSERT().
2890 If StartBit is greater than 63, then ASSERT().
2891 If EndBit is greater than 63, then ASSERT().
2892 If EndBit is less than StartBit, then ASSERT().
2894 @param Operand Operand on which to perform the bitfield operation.
2895 @param StartBit The ordinal of the least significant bit in the bit field.
2897 @param EndBit The ordinal of the most significant bit in the bit field.
2899 @param AndData The value to AND with the read value from the value
2901 @return The new 64-bit value.
2915 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2916 bitwise OR, and returns the result.
2918 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2919 in Operand and the value specified by AndData, followed by a bitwise
2920 inclusive OR with value specified by OrData. All other bits in Operand are
2921 preserved. The new 64-bit value is returned.
2923 If 64-bit operations are not supported, then ASSERT().
2924 If StartBit is greater than 63, then ASSERT().
2925 If EndBit is greater than 63, then ASSERT().
2926 If EndBit is less than StartBit, then ASSERT().
2928 @param Operand Operand on which to perform the bitfield operation.
2929 @param StartBit The ordinal of the least significant bit in the bit field.
2931 @param EndBit The ordinal of the most significant bit in the bit field.
2933 @param AndData The value to AND with the read value from the value.
2934 @param OrData The value to OR with the result of the AND operation.
2936 @return The new 64-bit value.
2941 BitFieldAndThenOr64 (
2951 // Base Library Synchronization Functions
2955 Retrieves the architecture specific spin lock alignment requirements for
2956 optimal spin lock performance.
2958 This function retrieves the spin lock alignment requirements for optimal
2959 performance on a given CPU architecture. The spin lock alignment must be a
2960 power of two and is returned by this function. If there are no alignment
2961 requirements, then 1 must be returned. The spin lock synchronization
2962 functions must function correctly if the spin lock size and alignment values
2963 returned by this function are not used at all. These values are hints to the
2964 consumers of the spin lock synchronization functions to obtain optimal spin
2967 @return The architecture specific spin lock alignment.
2972 GetSpinLockProperties (
2978 Initializes a spin lock to the released state and returns the spin lock.
2980 This function initializes the spin lock specified by SpinLock to the released
2981 state, and returns SpinLock. Optimal performance can be achieved by calling
2982 GetSpinLockProperties() to determine the size and alignment requirements for
2985 If SpinLock is NULL, then ASSERT().
2987 @param SpinLock A pointer to the spin lock to initialize to the released
2995 InitializeSpinLock (
2996 IN SPIN_LOCK
*SpinLock
3001 Waits until a spin lock can be placed in the acquired state.
3003 This function checks the state of the spin lock specified by SpinLock. If
3004 SpinLock is in the released state, then this function places SpinLock in the
3005 acquired state and returns SpinLock. Otherwise, this function waits
3006 indefinitely for the spin lock to be released, and then places it in the
3007 acquired state and returns SpinLock. All state transitions of SpinLock must
3008 be performed using MP safe mechanisms.
3010 If SpinLock is NULL, then ASSERT().
3011 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3012 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
3013 PcdSpinLockTimeout microseconds, then ASSERT().
3015 @param SpinLock A pointer to the spin lock to place in the acquired state.
3023 IN SPIN_LOCK
*SpinLock
3028 Attempts to place a spin lock in the acquired state.
3030 This function checks the state of the spin lock specified by SpinLock. If
3031 SpinLock is in the released state, then this function places SpinLock in the
3032 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
3033 transitions of SpinLock must be performed using MP safe mechanisms.
3035 If SpinLock is NULL, then ASSERT().
3036 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3038 @param SpinLock A pointer to the spin lock to place in the acquired state.
3040 @retval TRUE SpinLock was placed in the acquired state.
3041 @retval FALSE SpinLock could not be acquired.
3046 AcquireSpinLockOrFail (
3047 IN SPIN_LOCK
*SpinLock
3052 Releases a spin lock.
3054 This function places the spin lock specified by SpinLock in the release state
3055 and returns SpinLock.
3057 If SpinLock is NULL, then ASSERT().
3058 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3060 @param SpinLock A pointer to the spin lock to release.
3068 IN SPIN_LOCK
*SpinLock
3073 Performs an atomic increment of an 32-bit unsigned integer.
3075 Performs an atomic increment of the 32-bit unsigned integer specified by
3076 Value and returns the incremented value. The increment operation must be
3077 performed using MP safe mechanisms. The state of the return value is not
3078 guaranteed to be MP safe.
3080 If Value is NULL, then ASSERT().
3082 @param Value A pointer to the 32-bit value to increment.
3084 @return The incremented value.
3089 InterlockedIncrement (
3095 Performs an atomic decrement of an 32-bit unsigned integer.
3097 Performs an atomic decrement of the 32-bit unsigned integer specified by
3098 Value and returns the decremented value. The decrement operation must be
3099 performed using MP safe mechanisms. The state of the return value is not
3100 guaranteed to be MP safe.
3102 If Value is NULL, then ASSERT().
3104 @param Value A pointer to the 32-bit value to decrement.
3106 @return The decremented value.
3111 InterlockedDecrement (
3117 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
3119 Performs an atomic compare exchange operation on the 32-bit unsigned integer
3120 specified by Value. If Value is equal to CompareValue, then Value is set to
3121 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
3122 then Value is returned. The compare exchange operation must be performed using
3125 If Value is NULL, then ASSERT().
3127 @param Value A pointer to the 32-bit value for the compare exchange
3129 @param CompareValue 32-bit value used in compare operation.
3130 @param ExchangeValue 32-bit value used in exchange operation.
3132 @return The original *Value before exchange.
3137 InterlockedCompareExchange32 (
3138 IN OUT UINT32
*Value
,
3139 IN UINT32 CompareValue
,
3140 IN UINT32 ExchangeValue
3145 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
3147 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
3148 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
3149 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
3150 The compare exchange operation must be performed using MP safe mechanisms.
3152 If Value is NULL, then ASSERT().
3154 @param Value A pointer to the 64-bit value for the compare exchange
3156 @param CompareValue 64-bit value used in compare operation.
3157 @param ExchangeValue 64-bit value used in exchange operation.
3159 @return The original *Value before exchange.
3164 InterlockedCompareExchange64 (
3165 IN OUT UINT64
*Value
,
3166 IN UINT64 CompareValue
,
3167 IN UINT64 ExchangeValue
3172 Performs an atomic compare exchange operation on a pointer value.
3174 Performs an atomic compare exchange operation on the pointer value specified
3175 by Value. If Value is equal to CompareValue, then Value is set to
3176 ExchangeValue and CompareValue is returned. If Value is not equal to
3177 CompareValue, then Value is returned. The compare exchange operation must be
3178 performed using MP safe mechanisms.
3180 If Value is NULL, then ASSERT().
3182 @param Value A pointer to the pointer value for the compare exchange
3184 @param CompareValue Pointer value used in compare operation.
3185 @param ExchangeValue Pointer value used in exchange operation.
3190 InterlockedCompareExchangePointer (
3191 IN OUT VOID
**Value
,
3192 IN VOID
*CompareValue
,
3193 IN VOID
*ExchangeValue
3198 // Base Library Checksum Functions
3202 Calculate the sum of all elements in a buffer in unit of UINT8.
3203 During calculation, the carry bits are dropped.
3205 This function calculates the sum of all elements in a buffer
3206 in unit of UINT8. The carry bits in result of addition are dropped.
3207 The result is returned as UINT8. If Length is Zero, then Zero is
3210 If Buffer is NULL, then ASSERT().
3211 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3213 @param Buffer Pointer to the buffer to carry out the sum operation.
3214 @param Length The size, in bytes, of Buffer .
3216 @return Sum The sum of Buffer with carry bits dropped during additions.
3222 IN CONST UINT8
*Buffer
,
3228 Returns the two's complement checksum of all elements in a buffer
3231 This function first calculates the sum of the 8-bit values in the
3232 buffer specified by Buffer and Length. The carry bits in the result
3233 of addition are dropped. Then, the two's complement of the sum is
3234 returned. If Length is 0, then 0 is returned.
3236 If Buffer is NULL, then ASSERT().
3237 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3240 @param Buffer Pointer to the buffer to carry out the checksum operation.
3241 @param Length The size, in bytes, of Buffer.
3243 @return Checksum The 2's complement checksum of Buffer.
3248 CalculateCheckSum8 (
3249 IN CONST UINT8
*Buffer
,
3255 Returns the sum of all elements in a buffer of 16-bit values. During
3256 calculation, the carry bits are dropped.
3258 This function calculates the sum of the 16-bit values in the buffer
3259 specified by Buffer and Length. The carry bits in result of addition are dropped.
3260 The 16-bit result is returned. If Length is 0, then 0 is returned.
3262 If Buffer is NULL, then ASSERT().
3263 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3264 If Length is not aligned on a 16-bit boundary, then ASSERT().
3265 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3267 @param Buffer Pointer to the buffer to carry out the sum operation.
3268 @param Length The size, in bytes, of Buffer.
3270 @return Sum The sum of Buffer with carry bits dropped during additions.
3276 IN CONST UINT16
*Buffer
,
3282 Returns the two's complement checksum of all elements in a buffer of
3285 This function first calculates the sum of the 16-bit values in the buffer
3286 specified by Buffer and Length. The carry bits in the result of addition
3287 are dropped. Then, the two's complement of the sum is returned. If Length
3288 is 0, then 0 is returned.
3290 If Buffer is NULL, then ASSERT().
3291 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3292 If Length is not aligned on a 16-bit boundary, then ASSERT().
3293 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3295 @param Buffer Pointer to the buffer to carry out the checksum operation.
3296 @param Length The size, in bytes, of Buffer.
3298 @return Checksum The 2's complement checksum of Buffer.
3303 CalculateCheckSum16 (
3304 IN CONST UINT16
*Buffer
,
3310 Returns the sum of all elements in a buffer of 32-bit values. During
3311 calculation, the carry bits are dropped.
3313 This function calculates the sum of the 32-bit values in the buffer
3314 specified by Buffer and Length. The carry bits in result of addition are dropped.
3315 The 32-bit result is returned. If Length is 0, then 0 is returned.
3317 If Buffer is NULL, then ASSERT().
3318 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3319 If Length is not aligned on a 32-bit boundary, then ASSERT().
3320 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3322 @param Buffer Pointer to the buffer to carry out the sum operation.
3323 @param Length The size, in bytes, of Buffer.
3325 @return Sum The sum of Buffer with carry bits dropped during additions.
3331 IN CONST UINT32
*Buffer
,
3337 Returns the two's complement checksum of all elements in a buffer of
3340 This function first calculates the sum of the 32-bit values in the buffer
3341 specified by Buffer and Length. The carry bits in the result of addition
3342 are dropped. Then, the two's complement of the sum is returned. If Length
3343 is 0, then 0 is returned.
3345 If Buffer is NULL, then ASSERT().
3346 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3347 If Length is not aligned on a 32-bit boundary, then ASSERT().
3348 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3350 @param Buffer Pointer to the buffer to carry out the checksum operation.
3351 @param Length The size, in bytes, of Buffer.
3353 @return Checksum The 2's complement checksum of Buffer.
3358 CalculateCheckSum32 (
3359 IN CONST UINT32
*Buffer
,
3365 Returns the sum of all elements in a buffer of 64-bit values. During
3366 calculation, the carry bits are dropped.
3368 This function calculates the sum of the 64-bit values in the buffer
3369 specified by Buffer and Length. The carry bits in result of addition are dropped.
3370 The 64-bit result is returned. If Length is 0, then 0 is returned.
3372 If Buffer is NULL, then ASSERT().
3373 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3374 If Length is not aligned on a 64-bit boundary, then ASSERT().
3375 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3377 @param Buffer Pointer to the buffer to carry out the sum operation.
3378 @param Length The size, in bytes, of Buffer.
3380 @return Sum The sum of Buffer with carry bits dropped during additions.
3386 IN CONST UINT64
*Buffer
,
3392 Returns the two's complement checksum of all elements in a buffer of
3395 This function first calculates the sum of the 64-bit values in the buffer
3396 specified by Buffer and Length. The carry bits in the result of addition
3397 are dropped. Then, the two's complement of the sum is returned. If Length
3398 is 0, then 0 is returned.
3400 If Buffer is NULL, then ASSERT().
3401 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3402 If Length is not aligned on a 64-bit boundary, then ASSERT().
3403 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3405 @param Buffer Pointer to the buffer to carry out the checksum operation.
3406 @param Length The size, in bytes, of Buffer.
3408 @return Checksum The 2's complement checksum of Buffer.
3413 CalculateCheckSum64 (
3414 IN CONST UINT64
*Buffer
,
3420 // Base Library CPU Functions
3424 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
3425 IN VOID
*Context1
, OPTIONAL
3426 IN VOID
*Context2 OPTIONAL
3431 Used to serialize load and store operations.
3433 All loads and stores that proceed calls to this function are guaranteed to be
3434 globally visible when this function returns.
3445 Saves the current CPU context that can be restored with a call to LongJump()
3448 Saves the current CPU context in the buffer specified by JumpBuffer and
3449 returns 0. The initial call to SetJump() must always return 0. Subsequent
3450 calls to LongJump() cause a non-zero value to be returned by SetJump().
3452 If JumpBuffer is NULL, then ASSERT().
3453 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3455 @param JumpBuffer A pointer to CPU context buffer.
3457 @retval 0 Indicates a return from SetJump().
3463 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
3468 Restores the CPU context that was saved with SetJump().
3470 Restores the CPU context from the buffer specified by JumpBuffer. This
3471 function never returns to the caller. Instead is resumes execution based on
3472 the state of JumpBuffer.
3474 If JumpBuffer is NULL, then ASSERT().
3475 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3476 If Value is 0, then ASSERT().
3478 @param JumpBuffer A pointer to CPU context buffer.
3479 @param Value The value to return when the SetJump() context is
3480 restored and must be non-zero.
3486 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
3492 Enables CPU interrupts.
3494 Enables CPU interrupts.
3505 Disables CPU interrupts.
3507 Disables CPU interrupts.
3518 Disables CPU interrupts and returns the interrupt state prior to the disable
3521 Disables CPU interrupts and returns the interrupt state prior to the disable
3524 @retval TRUE CPU interrupts were enabled on entry to this call.
3525 @retval FALSE CPU interrupts were disabled on entry to this call.
3530 SaveAndDisableInterrupts (
3536 Enables CPU interrupts for the smallest window required to capture any
3539 Enables CPU interrupts for the smallest window required to capture any
3545 EnableDisableInterrupts (
3551 Retrieves the current CPU interrupt state.
3553 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
3554 currently enabled. Otherwise returns FALSE.
3556 @retval TRUE CPU interrupts are enabled.
3557 @retval FALSE CPU interrupts are disabled.
3562 GlueGetInterruptState (
3568 Set the current CPU interrupt state.
3570 Sets the current CPU interrupt state to the state specified by
3571 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
3572 InterruptState is FALSE, then interrupts are disabled. InterruptState is
3575 @param InterruptState TRUE if interrupts should enabled. FALSE if
3576 interrupts should be disabled.
3578 @return InterruptState
3584 IN BOOLEAN InterruptState
3589 Places the CPU in a sleep state until an interrupt is received.
3591 Places the CPU in a sleep state until an interrupt is received. If interrupts
3592 are disabled prior to calling this function, then the CPU will be placed in a
3593 sleep state indefinitely.
3604 Requests CPU to pause for a short period of time.
3606 Requests CPU to pause for a short period of time. Typically used in MP
3607 systems to prevent memory starvation while waiting for a spin lock.
3618 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3620 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3631 Transfers control to a function starting with a new stack.
3633 Transfers control to the function specified by EntryPoint using the
3634 new stack specified by NewStack and passing in the parameters specified
3635 by Context1 and Context2. Context1 and Context2 are optional and may
3636 be NULL. The function EntryPoint must never return. This function
3637 supports a variable number of arguments following the NewStack parameter.
3638 These additional arguments are ignored on IA-32, x64, and EBC.
3639 IPF CPUs expect one additional parameter of type VOID * that specifies
3640 the new backing store pointer.
3642 If EntryPoint is NULL, then ASSERT().
3643 If NewStack is NULL, then ASSERT().
3645 @param EntryPoint A pointer to function to call with the new stack.
3646 @param Context1 A pointer to the context to pass into the EntryPoint
3648 @param Context2 A pointer to the context to pass into the EntryPoint
3650 @param NewStack A pointer to the new stack to use for the EntryPoint
3657 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
3658 IN VOID
*Context1
, OPTIONAL
3659 IN VOID
*Context2
, OPTIONAL
3666 Generates a breakpoint on the CPU.
3668 Generates a breakpoint on the CPU. The breakpoint must be implemented such
3669 that code can resume normal execution after the breakpoint.
3680 Executes an infinite loop.
3682 Forces the CPU to execute an infinite loop. A debugger may be used to skip
3683 past the loop and the code that follows the loop must execute properly. This
3684 implies that the infinite loop must not cause the code that follow it to be
3695 #if defined (MDE_CPU_IPF)
3698 Flush a range of cache lines in the cache coherency domain of the calling
3701 Invalidates the cache lines specified by Address and Length. If Address is
3702 not aligned on a cache line boundary, then entire cache line containing
3703 Address is invalidated. If Address + Length is not aligned on a cache line
3704 boundary, then the entire instruction cache line containing Address + Length
3705 -1 is invalidated. This function may choose to invalidate the entire
3706 instruction cache if that is more efficient than invalidating the specified
3707 range. If Length is 0, the no instruction cache lines are invalidated.
3708 Address is returned. This function is only available on IPF.
3710 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
3712 @param Address The base address of the instruction lines to invalidate. If
3713 the CPU is in a physical addressing mode, then Address is a
3714 physical address. If the CPU is in a virtual addressing mode,
3715 then Address is a virtual address.
3717 @param Length The number of bytes to invalidate from the instruction cache.
3724 AsmFlushCacheRange (
3731 Executes a FC instruction
3732 Executes a FC instruction on the cache line specified by Address.
3733 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3734 An implementation may flush a larger region. This function is only available on IPF.
3736 @param Address The Address of cache line to be flushed.
3738 @return The address of FC instruction executed.
3749 Executes a FC.I instruction.
3750 Executes a FC.I instruction on the cache line specified by Address.
3751 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3752 An implementation may flush a larger region. This function is only available on IPF.
3754 @param Address The Address of cache line to be flushed.
3756 @return The address of FC.I instruction executed.
3767 Reads the current value of a Processor Identifier Register (CPUID).
3768 The Index of largest implemented CPUID (One less than the number of implemented CPUID
3769 registers) is determined by CPUID [3] bits {7:0}.
3770 No parameter checking is performed on Index. If the Index value is beyond the
3771 implemented CPUID register range, a Reserved Register/Field fault may occur. The caller
3772 must either guarantee that Index is valid, or the caller must set up fault handlers to
3773 catch the faults. This function is only available on IPF.
3775 @param Index The 8-bit Processor Identifier Register index to read.
3777 @return The current value of Processor Identifier Register specified by Index.
3788 Reads the current value of 64-bit Processor Status Register (PSR).
3789 This function is only available on IPF.
3791 @return The current value of PSR.
3802 Writes the current value of 64-bit Processor Status Register (PSR).
3803 No parameter checking is performed on Value. All bits of Value corresponding to
3804 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.
3805 This function is only available on IPF.
3807 @param Value The 64-bit value to write to PSR.
3809 @return The 64-bit value written to the PSR.
3820 Reads the current value of 64-bit Kernel Register #0 (KR0).
3821 This function is only available on IPF.
3823 @return The current value of KR0.
3834 Reads the current value of 64-bit Kernel Register #1 (KR1).
3835 This function is only available on IPF.
3837 @return The current value of KR1.
3848 Reads the current value of 64-bit Kernel Register #2 (KR2).
3849 This function is only available on IPF.
3851 @return The current value of KR2.
3862 Reads the current value of 64-bit Kernel Register #3 (KR3).
3863 This function is only available on IPF.
3865 @return The current value of KR3.
3876 Reads the current value of 64-bit Kernel Register #4 (KR4).
3877 This function is only available on IPF.
3879 @return The current value of KR4.
3890 Reads the current value of 64-bit Kernel Register #5 (KR5).
3891 This function is only available on IPF.
3893 @return The current value of KR5.
3904 Reads the current value of 64-bit Kernel Register #6 (KR6).
3905 This function is only available on IPF.
3907 @return The current value of KR6.
3918 Reads the current value of 64-bit Kernel Register #7 (KR7).
3919 This function is only available on IPF.
3921 @return The current value of KR7.
3932 Write the current value of 64-bit Kernel Register #0 (KR0).
3933 This function is only available on IPF.
3935 @param Value The 64-bit value to write to KR0.
3937 @return The 64-bit value written to the KR0.
3948 Write the current value of 64-bit Kernel Register #1 (KR1).
3949 This function is only available on IPF.
3951 @param Value The 64-bit value to write to KR1.
3953 @return The 64-bit value written to the KR1.
3964 Write the current value of 64-bit Kernel Register #2 (KR2).
3965 This function is only available on IPF.
3967 @param Value The 64-bit value to write to KR2.
3969 @return The 64-bit value written to the KR2.
3980 Write the current value of 64-bit Kernel Register #3 (KR3).
3981 This function is only available on IPF.
3983 @param Value The 64-bit value to write to KR3.
3985 @return The 64-bit value written to the KR3.
3996 Write the current value of 64-bit Kernel Register #4 (KR4).
3997 This function is only available on IPF.
3999 @param Value The 64-bit value to write to KR4.
4001 @return The 64-bit value written to the KR4.
4012 Write the current value of 64-bit Kernel Register #5 (KR5).
4013 This function is only available on IPF.
4015 @param Value The 64-bit value to write to KR5.
4017 @return The 64-bit value written to the KR5.
4028 Write the current value of 64-bit Kernel Register #6 (KR6).
4029 This function is only available on IPF.
4031 @param Value The 64-bit value to write to KR6.
4033 @return The 64-bit value written to the KR6.
4044 Write the current value of 64-bit Kernel Register #7 (KR7).
4045 This function is only available on IPF.
4047 @param Value The 64-bit value to write to KR7.
4049 @return The 64-bit value written to the KR7.
4060 Reads the current value of Interval Timer Counter Register (ITC).
4061 This function is only available on IPF.
4063 @return The current value of ITC.
4074 Reads the current value of Interval Timer Vector Register (ITV).
4075 This function is only available on IPF.
4077 @return The current value of ITV.
4088 Reads the current value of Interval Timer Match Register (ITM).
4089 This function is only available on IPF.
4091 @return The current value of ITM.
4101 Writes the current value of 64-bit Interval Timer Counter Register (ITC).
4102 This function is only available on IPF.
4104 @param Value The 64-bit value to write to ITC.
4106 @return The 64-bit value written to the ITC.
4117 Writes the current value of 64-bit Interval Timer Match Register (ITM).
4118 This function is only available on IPF.
4120 @param Value The 64-bit value to write to ITM.
4122 @return The 64-bit value written to the ITM.
4133 Writes the current value of 64-bit Interval Timer Vector Register (ITV).
4134 No parameter checking is performed on Value. All bits of Value corresponding to
4135 reserved fields of ITV must be 0 or a Reserved Register/Field fault may occur.
4136 The caller must either guarantee that Value is valid, or the caller must set up
4137 fault handlers to catch the faults.
4138 This function is only available on IPF.
4140 @param Value The 64-bit value to write to ITV.
4142 @return The 64-bit value written to the ITV.
4153 Reads the current value of Default Control Register (DCR).
4154 This function is only available on IPF.
4156 @return The current value of DCR.
4167 Reads the current value of Interruption Vector Address Register (IVA).
4168 This function is only available on IPF.
4170 @return The current value of IVA.
4180 Reads the current value of Page Table Address Register (PTA).
4181 This function is only available on IPF.
4183 @return The current value of PTA.
4194 Writes the current value of 64-bit Default Control Register (DCR).
4195 No parameter checking is performed on Value. All bits of Value corresponding to
4196 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4197 The caller must either guarantee that Value is valid, or the caller must set up
4198 fault handlers to catch the faults.
4199 This function is only available on IPF.
4201 @param Value The 64-bit value to write to DCR.
4203 @return The 64-bit value written to the DCR.
4214 Writes the current value of 64-bit Interruption Vector Address Register (IVA).
4215 The size of vector table is 32 K bytes and is 32 K bytes aligned
4216 the low 15 bits of Value is ignored when written.
4217 This function is only available on IPF.
4219 @param Value The 64-bit value to write to IVA.
4221 @return The 64-bit value written to the IVA.
4232 Writes the current value of 64-bit Page Table Address Register (PTA).
4233 No parameter checking is performed on Value. All bits of Value corresponding to
4234 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4235 The caller must either guarantee that Value is valid, or the caller must set up
4236 fault handlers to catch the faults.
4237 This function is only available on IPF.
4239 @param Value The 64-bit value to write to PTA.
4241 @return The 64-bit value written to the PTA.
4251 Reads the current value of Local Interrupt ID Register (LID).
4252 This function is only available on IPF.
4254 @return The current value of LID.
4265 Reads the current value of External Interrupt Vector Register (IVR).
4266 This function is only available on IPF.
4268 @return The current value of IVR.
4279 Reads the current value of Task Priority Register (TPR).
4280 This function is only available on IPF.
4282 @return The current value of TPR.
4293 Reads the current value of External Interrupt Request Register #0 (IRR0).
4294 This function is only available on IPF.
4296 @return The current value of IRR0.
4307 Reads the current value of External Interrupt Request Register #1 (IRR1).
4308 This function is only available on IPF.
4310 @return The current value of IRR1.
4321 Reads the current value of External Interrupt Request Register #2 (IRR2).
4322 This function is only available on IPF.
4324 @return The current value of IRR2.
4335 Reads the current value of External Interrupt Request Register #3 (IRR3).
4336 This function is only available on IPF.
4338 @return The current value of IRR3.
4349 Reads the current value of Performance Monitor Vector Register (PMV).
4350 This function is only available on IPF.
4352 @return The current value of PMV.
4363 Reads the current value of Corrected Machine Check Vector Register (CMCV).
4364 This function is only available on IPF.
4366 @return The current value of CMCV.
4377 Reads the current value of Local Redirection Register #0 (LRR0).
4378 This function is only available on IPF.
4380 @return The current value of LRR0.
4391 Reads the current value of Local Redirection Register #1 (LRR1).
4392 This function is only available on IPF.
4394 @return The current value of LRR1.
4405 Writes the current value of 64-bit Page Local Interrupt ID Register (LID).
4406 No parameter checking is performed on Value. All bits of Value corresponding to
4407 reserved fields of LID must be 0 or a Reserved Register/Field fault may occur.
4408 The caller must either guarantee that Value is valid, or the caller must set up
4409 fault handlers to catch the faults.
4410 This function is only available on IPF.
4412 @param Value The 64-bit value to write to LID.
4414 @return The 64-bit value written to the LID.
4425 Writes the current value of 64-bit Task Priority Register (TPR).
4426 No parameter checking is performed on Value. All bits of Value corresponding to
4427 reserved fields of TPR must be 0 or a Reserved Register/Field fault may occur.
4428 The caller must either guarantee that Value is valid, or the caller must set up
4429 fault handlers to catch the faults.
4430 This function is only available on IPF.
4432 @param Value The 64-bit value to write to TPR.
4434 @return The 64-bit value written to the TPR.
4445 Performs a write operation on End OF External Interrupt Register (EOI).
4446 Writes a value of 0 to the EOI Register. This function is only available on IPF.
4457 Writes the current value of 64-bit Performance Monitor Vector Register (PMV).
4458 No parameter checking is performed on Value. All bits of Value corresponding
4459 to reserved fields of PMV must be 0 or a Reserved Register/Field fault may occur.
4460 The caller must either guarantee that Value is valid, or the caller must set up
4461 fault handlers to catch the faults.
4462 This function is only available on IPF.
4464 @param Value The 64-bit value to write to PMV.
4466 @return The 64-bit value written to the PMV.
4477 Writes the current value of 64-bit Corrected Machine Check Vector Register (CMCV).
4478 No parameter checking is performed on Value. All bits of Value corresponding
4479 to reserved fields of CMCV must be 0 or a Reserved Register/Field fault may occur.
4480 The caller must either guarantee that Value is valid, or the caller must set up
4481 fault handlers to catch the faults.
4482 This function is only available on IPF.
4484 @param Value The 64-bit value to write to CMCV.
4486 @return The 64-bit value written to the CMCV.
4497 Writes the current value of 64-bit Local Redirection Register #0 (LRR0).
4498 No parameter checking is performed on Value. All bits of Value corresponding
4499 to reserved fields of LRR0 must be 0 or a Reserved Register/Field fault may occur.
4500 The caller must either guarantee that Value is valid, or the caller must set up
4501 fault handlers to catch the faults.
4502 This function is only available on IPF.
4504 @param Value The 64-bit value to write to LRR0.
4506 @return The 64-bit value written to the LRR0.
4517 Writes the current value of 64-bit Local Redirection Register #1 (LRR1).
4518 No parameter checking is performed on Value. All bits of Value corresponding
4519 to reserved fields of LRR1 must be 0 or a Reserved Register/Field fault may occur.
4520 The caller must either guarantee that Value is valid, or the caller must
4521 set up fault handlers to catch the faults.
4522 This function is only available on IPF.
4524 @param Value The 64-bit value to write to LRR1.
4526 @return The 64-bit value written to the LRR1.
4537 Reads the current value of Instruction Breakpoint Register (IBR).
4539 The Instruction Breakpoint Registers are used in pairs. The even numbered
4540 registers contain breakpoint addresses, and the odd numbered registers contain
4541 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4542 on all processor models. Implemented registers are contiguous starting with
4543 register 0. No parameter checking is performed on Index, and if the Index value
4544 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4545 occur. The caller must either guarantee that Index is valid, or the caller must
4546 set up fault handlers to catch the faults.
4547 This function is only available on IPF.
4549 @param Index The 8-bit Instruction Breakpoint Register index to read.
4551 @return The current value of Instruction Breakpoint Register specified by Index.
4562 Reads the current value of Data Breakpoint Register (DBR).
4564 The Data Breakpoint Registers are used in pairs. The even numbered registers
4565 contain breakpoint addresses, and odd numbered registers contain breakpoint
4566 mask conditions. At least 4 data registers pairs are implemented on all processor
4567 models. Implemented registers are contiguous starting with register 0.
4568 No parameter checking is performed on Index. If the Index value is beyond
4569 the implemented DBR register range, a Reserved Register/Field fault may occur.
4570 The caller must either guarantee that Index is valid, or the caller must set up
4571 fault handlers to catch the faults.
4572 This function is only available on IPF.
4574 @param Index The 8-bit Data Breakpoint Register index to read.
4576 @return The current value of Data Breakpoint Register specified by Index.
4587 Reads the current value of Performance Monitor Configuration Register (PMC).
4589 All processor implementations provide at least 4 performance counters
4590 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4591 status registers (PMC [0]... PMC [3]). Processor implementations may provide
4592 additional implementation-dependent PMC and PMD to increase the number of
4593 'generic' performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4594 register set is implementation dependent. No parameter checking is performed
4595 on Index. If the Index value is beyond the implemented PMC register range,
4596 zero value will be returned.
4597 This function is only available on IPF.
4599 @param Index The 8-bit Performance Monitor Configuration Register index to read.
4601 @return The current value of Performance Monitor Configuration Register
4613 Reads the current value of Performance Monitor Data Register (PMD).
4615 All processor implementations provide at least 4 performance counters
4616 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter
4617 overflow status registers (PMC [0]... PMC [3]). Processor implementations may
4618 provide additional implementation-dependent PMC and PMD to increase the number
4619 of 'generic' performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4620 register set is implementation dependent. No parameter checking is performed
4621 on Index. If the Index value is beyond the implemented PMD register range,
4622 zero value will be returned.
4623 This function is only available on IPF.
4625 @param Index The 8-bit Performance Monitor Data Register index to read.
4627 @return The current value of Performance Monitor Data Register specified by Index.
4638 Writes the current value of 64-bit Instruction Breakpoint Register (IBR).
4640 Writes current value of Instruction Breakpoint Register specified by Index.
4641 The Instruction Breakpoint Registers are used in pairs. The even numbered
4642 registers contain breakpoint addresses, and odd numbered registers contain
4643 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4644 on all processor models. Implemented registers are contiguous starting with
4645 register 0. No parameter checking is performed on Index. If the Index value
4646 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4647 occur. The caller must either guarantee that Index is valid, or the caller must
4648 set up fault handlers to catch the faults.
4649 This function is only available on IPF.
4651 @param Index The 8-bit Instruction Breakpoint Register index to write.
4652 @param Value The 64-bit value to write to IBR.
4654 @return The 64-bit value written to the IBR.
4666 Writes the current value of 64-bit Data Breakpoint Register (DBR).
4668 Writes current value of Data Breakpoint Register specified by Index.
4669 The Data Breakpoint Registers are used in pairs. The even numbered registers
4670 contain breakpoint addresses, and odd numbered registers contain breakpoint
4671 mask conditions. At least 4 data registers pairs are implemented on all processor
4672 models. Implemented registers are contiguous starting with register 0. No parameter
4673 checking is performed on Index. If the Index value is beyond the implemented
4674 DBR register range, a Reserved Register/Field fault may occur. The caller must
4675 either guarantee that Index is valid, or the caller must set up fault handlers to
4677 This function is only available on IPF.
4679 @param Index The 8-bit Data Breakpoint Register index to write.
4680 @param Value The 64-bit value to write to DBR.
4682 @return The 64-bit value written to the DBR.
4694 Writes the current value of 64-bit Performance Monitor Configuration Register (PMC).
4696 Writes current value of Performance Monitor Configuration Register specified by Index.
4697 All processor implementations provide at least 4 performance counters
4698 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow status
4699 registers (PMC [0]... PMC [3]). Processor implementations may provide additional
4700 implementation-dependent PMC and PMD to increase the number of 'generic' performance
4701 counters (PMC/PMD pairs). The remainder of PMC and PMD register set is implementation
4702 dependent. No parameter checking is performed on Index. If the Index value is
4703 beyond the implemented PMC register range, the write is ignored.
4704 This function is only available on IPF.
4706 @param Index The 8-bit Performance Monitor Configuration Register index to write.
4707 @param Value The 64-bit value to write to PMC.
4709 @return The 64-bit value written to the PMC.
4721 Writes the current value of 64-bit Performance Monitor Data Register (PMD).
4723 Writes current value of Performance Monitor Data Register specified by Index.
4724 All processor implementations provide at least 4 performance counters
4725 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4726 status registers (PMC [0]... PMC [3]). Processor implementations may provide
4727 additional implementation-dependent PMC and PMD to increase the number of 'generic'
4728 performance counters (PMC/PMD pairs). The remainder of PMC and PMD register set
4729 is implementation dependent. No parameter checking is performed on Index. If the
4730 Index value is beyond the implemented PMD register range, the write is ignored.
4731 This function is only available on IPF.
4733 @param Index The 8-bit Performance Monitor Data Register index to write.
4734 @param Value The 64-bit value to write to PMD.
4736 @return The 64-bit value written to the PMD.
4748 Reads the current value of 64-bit Global Pointer (GP).
4750 Reads and returns the current value of GP.
4751 This function is only available on IPF.
4753 @return The current value of GP.
4764 Write the current value of 64-bit Global Pointer (GP).
4766 Writes the current value of GP. The 64-bit value written to the GP is returned.
4767 No parameter checking is performed on Value.
4768 This function is only available on IPF.
4770 @param Value The 64-bit value to write to GP.
4772 @return The 64-bit value written to the GP.
4783 Reads the current value of 64-bit Stack Pointer (SP).
4785 Reads and returns the current value of SP.
4786 This function is only available on IPF.
4788 @return The current value of SP.
4799 Determines if the CPU is currently executing in virtual, physical, or mixed mode.
4801 Determines the current execution mode of the CPU.
4802 If the CPU is in virtual mode(PSR.RT=1, PSR.DT=1, PSR.IT=1), then 1 is returned.
4803 If the CPU is in physical mode(PSR.RT=0, PSR.DT=0, PSR.IT=0), then 0 is returned.
4804 If the CPU is not in physical mode or virtual mode, then it is in mixed mode,
4806 This function is only available on IPF.
4808 @return 1 The CPU is in virtual mode.
4809 @return 0 The CPU is in physical mode.
4810 @return -1 The CPU is in mixed mode.
4821 Makes a PAL procedure call.
4823 This is a wrapper function to make a PAL procedure call. Based on the Index
4824 value this API will make static or stacked PAL call. The following table
4825 describes the usage of PAL Procedure Index Assignment. Architected procedures
4826 may be designated as required or optional. If a PAL procedure is specified
4827 as optional, a unique return code of 0xFFFFFFFFFFFFFFFF is returned in the
4828 Status field of the PAL_CALL_RETURN structure.
4829 This indicates that the procedure is not present in this PAL implementation.
4830 It is the caller's responsibility to check for this return code after calling
4831 any optional PAL procedure.
4832 No parameter checking is performed on the 5 input parameters, but there are
4833 some common rules that the caller should follow when making a PAL call. Any
4834 address passed to PAL as buffers for return parameters must be 8-byte aligned.
4835 Unaligned addresses may cause undefined results. For those parameters defined
4836 as reserved or some fields defined as reserved must be zero filled or the invalid
4837 argument return value may be returned or undefined result may occur during the
4838 execution of the procedure. If the PalEntryPoint does not point to a valid
4839 PAL entry point then the system behavior is undefined. This function is only
4842 @param PalEntryPoint The PAL procedure calls entry point.
4843 @param Index The PAL procedure Index number.
4844 @param Arg2 The 2nd parameter for PAL procedure calls.
4845 @param Arg3 The 3rd parameter for PAL procedure calls.
4846 @param Arg4 The 4th parameter for PAL procedure calls.
4848 @return structure returned from the PAL Call procedure, including the status and return value.
4854 IN UINT64 PalEntryPoint
,
4863 Transfers control to a function starting with a new stack.
4865 Transfers control to the function specified by EntryPoint using the new stack
4866 specified by NewStack and passing in the parameters specified by Context1 and
4867 Context2. Context1 and Context2 are optional and may be NULL. The function
4868 EntryPoint must never return.
4870 If EntryPoint is NULL, then ASSERT().
4871 If NewStack is NULL, then ASSERT().
4873 @param EntryPoint A pointer to function to call with the new stack.
4874 @param Context1 A pointer to the context to pass into the EntryPoint
4876 @param Context2 A pointer to the context to pass into the EntryPoint
4878 @param NewStack A pointer to the new stack to use for the EntryPoint
4880 @param NewBsp A pointer to the new memory location for RSE backing
4886 AsmSwitchStackAndBackingStore (
4887 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4888 IN VOID
*Context1
, OPTIONAL
4889 IN VOID
*Context2
, OPTIONAL
4896 // Bugbug: This call should be removed after
4897 // the PalCall Instance issue has been fixed.
4900 Performs a PAL call using static calling convention.
4902 An internal function to perform a PAL call using static calling convention.
4904 @param PalEntryPoint The entry point address of PAL. The address in ar.kr5
4905 would be used if this parameter were NULL on input.
4906 @param Arg1 The first argument of a PAL call.
4907 @param Arg1 The second argument of a PAL call.
4908 @param Arg1 The third argument of a PAL call.
4909 @param Arg1 The fourth argument of a PAL call.
4911 @return The values returned in r8, r9, r10 and r11.
4916 IN CONST VOID
*PalEntryPoint
,
4924 #elif defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
4926 // IA32 and X64 Specific Functions
4929 // Byte packed structure for 16-bit Real Mode EFLAGS
4933 UINT32 CF
:1; // Carry Flag
4934 UINT32 Reserved_0
:1; // Reserved
4935 UINT32 PF
:1; // Parity Flag
4936 UINT32 Reserved_1
:1; // Reserved
4937 UINT32 AF
:1; // Auxiliary Carry Flag
4938 UINT32 Reserved_2
:1; // Reserved
4939 UINT32 ZF
:1; // Zero Flag
4940 UINT32 SF
:1; // Sign Flag
4941 UINT32 TF
:1; // Trap Flag
4942 UINT32 IF
:1; // Interrupt Enable Flag
4943 UINT32 DF
:1; // Direction Flag
4944 UINT32 OF
:1; // Overflow Flag
4945 UINT32 IOPL
:2; // I/O Privilege Level
4946 UINT32 NT
:1; // Nested Task
4947 UINT32 Reserved_3
:1; // Reserved
4953 // Byte packed structure for EFLAGS/RFLAGS
4955 // 64-bits on X64. The upper 32-bits on X64 are reserved
4959 UINT32 CF
:1; // Carry Flag
4960 UINT32 Reserved_0
:1; // Reserved
4961 UINT32 PF
:1; // Parity Flag
4962 UINT32 Reserved_1
:1; // Reserved
4963 UINT32 AF
:1; // Auxiliary Carry Flag
4964 UINT32 Reserved_2
:1; // Reserved
4965 UINT32 ZF
:1; // Zero Flag
4966 UINT32 SF
:1; // Sign Flag
4967 UINT32 TF
:1; // Trap Flag
4968 UINT32 IF
:1; // Interrupt Enable Flag
4969 UINT32 DF
:1; // Direction Flag
4970 UINT32 OF
:1; // Overflow Flag
4971 UINT32 IOPL
:2; // I/O Privilege Level
4972 UINT32 NT
:1; // Nested Task
4973 UINT32 Reserved_3
:1; // Reserved
4974 UINT32 RF
:1; // Resume Flag
4975 UINT32 VM
:1; // Virtual 8086 Mode
4976 UINT32 AC
:1; // Alignment Check
4977 UINT32 VIF
:1; // Virtual Interrupt Flag
4978 UINT32 VIP
:1; // Virtual Interrupt Pending
4979 UINT32 ID
:1; // ID Flag
4980 UINT32 Reserved_4
:10; // Reserved
4986 // Byte packed structure for Control Register 0 (CR0)
4988 // 64-bits on X64. The upper 32-bits on X64 are reserved
4992 UINT32 PE
:1; // Protection Enable
4993 UINT32 MP
:1; // Monitor Coprocessor
4994 UINT32 EM
:1; // Emulation
4995 UINT32 TS
:1; // Task Switched
4996 UINT32 ET
:1; // Extension Type
4997 UINT32 NE
:1; // Numeric Error
4998 UINT32 Reserved_0
:10; // Reserved
4999 UINT32 WP
:1; // Write Protect
5000 UINT32 Reserved_1
:1; // Reserved
5001 UINT32 AM
:1; // Alignment Mask
5002 UINT32 Reserved_2
:10; // Reserved
5003 UINT32 NW
:1; // Mot Write-through
5004 UINT32 CD
:1; // Cache Disable
5005 UINT32 PG
:1; // Paging
5011 // Byte packed structure for Control Register 4 (CR4)
5013 // 64-bits on X64. The upper 32-bits on X64 are reserved
5017 UINT32 VME
:1; // Virtual-8086 Mode Extensions
5018 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
5019 UINT32 TSD
:1; // Time Stamp Disable
5020 UINT32 DE
:1; // Debugging Extensions
5021 UINT32 PSE
:1; // Page Size Extensions
5022 UINT32 PAE
:1; // Physical Address Extension
5023 UINT32 MCE
:1; // Machine Check Enable
5024 UINT32 PGE
:1; // Page Global Enable
5025 UINT32 PCE
:1; // Performance Monitoring Counter
5027 UINT32 OSFXSR
:1; // Operating System Support for
5028 // FXSAVE and FXRSTOR instructions
5029 UINT32 OSXMMEXCPT
:1; // Operating System Support for
5030 // Unmasked SIMD Floating Point
5032 UINT32 Reserved_0
:2; // Reserved
5033 UINT32 VMXE
:1; // VMX Enable
5034 UINT32 Reserved_1
:18; // Reseved
5040 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
5041 /// @bug How to make this structure byte-packed in a compiler independent way?
5050 #define IA32_IDT_GATE_TYPE_TASK 0x85
5051 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
5052 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
5053 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
5054 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
5057 // Byte packed structure for an Interrupt Gate Descriptor
5061 UINT32 OffsetLow
:16; // Offset bits 15..0
5062 UINT32 Selector
:16; // Selector
5063 UINT32 Reserved_0
:8; // Reserved
5064 UINT32 GateType
:8; // Gate Type. See #defines above
5065 UINT32 OffsetHigh
:16; // Offset bits 31..16
5068 } IA32_IDT_GATE_DESCRIPTOR
;
5071 // Byte packed structure for an FP/SSE/SSE2 context
5078 // Structures for the 16-bit real mode thunks
5131 IA32_EFLAGS32 EFLAGS
;
5141 } IA32_REGISTER_SET
;
5144 // Byte packed structure for an 16-bit real mode thunks
5147 IA32_REGISTER_SET
*RealModeState
;
5148 VOID
*RealModeBuffer
;
5149 UINT32 RealModeBufferSize
;
5150 UINT32 ThunkAttributes
;
5153 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
5154 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
5155 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
5158 Retrieves CPUID information.
5160 Executes the CPUID instruction with EAX set to the value specified by Index.
5161 This function always returns Index.
5162 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5163 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5164 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5165 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5166 This function is only available on IA-32 and X64.
5168 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
5170 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5171 instruction. This is an optional parameter that may be NULL.
5172 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5173 instruction. This is an optional parameter that may be NULL.
5174 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5175 instruction. This is an optional parameter that may be NULL.
5176 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5177 instruction. This is an optional parameter that may be NULL.
5186 OUT UINT32
*Eax
, OPTIONAL
5187 OUT UINT32
*Ebx
, OPTIONAL
5188 OUT UINT32
*Ecx
, OPTIONAL
5189 OUT UINT32
*Edx OPTIONAL
5194 Retrieves CPUID information using an extended leaf identifier.
5196 Executes the CPUID instruction with EAX set to the value specified by Index
5197 and ECX set to the value specified by SubIndex. This function always returns
5198 Index. This function is only available on IA-32 and x64.
5200 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5201 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5202 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5203 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5205 @param Index The 32-bit value to load into EAX prior to invoking the
5207 @param SubIndex The 32-bit value to load into ECX prior to invoking the
5209 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5210 instruction. This is an optional parameter that may be
5212 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5213 instruction. This is an optional parameter that may be
5215 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5216 instruction. This is an optional parameter that may be
5218 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5219 instruction. This is an optional parameter that may be
5230 OUT UINT32
*Eax
, OPTIONAL
5231 OUT UINT32
*Ebx
, OPTIONAL
5232 OUT UINT32
*Ecx
, OPTIONAL
5233 OUT UINT32
*Edx OPTIONAL
5238 Returns the lower 32-bits of a Machine Specific Register(MSR).
5240 Reads and returns the lower 32-bits of the MSR specified by Index.
5241 No parameter checking is performed on Index, and some Index values may cause
5242 CPU exceptions. The caller must either guarantee that Index is valid, or the
5243 caller must set up exception handlers to catch the exceptions. This function
5244 is only available on IA-32 and X64.
5246 @param Index The 32-bit MSR index to read.
5248 @return The lower 32 bits of the MSR identified by Index.
5259 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
5261 Writes the 32-bit value specified by Value to the MSR specified by Index. The
5262 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
5263 the MSR is returned. No parameter checking is performed on Index or Value,
5264 and some of these may cause CPU exceptions. The caller must either guarantee
5265 that Index and Value are valid, or the caller must establish proper exception
5266 handlers. This function is only available on IA-32 and X64.
5268 @param Index The 32-bit MSR index to write.
5269 @param Value The 32-bit value to write to the MSR.
5283 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
5284 writes the result back to the 64-bit MSR.
5286 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5287 between the lower 32-bits of the read result and the value specified by
5288 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
5289 32-bits of the value written to the MSR is returned. No parameter checking is
5290 performed on Index or OrData, and some of these may cause CPU exceptions. The
5291 caller must either guarantee that Index and OrData are valid, or the caller
5292 must establish proper exception handlers. This function is only available on
5295 @param Index The 32-bit MSR index to write.
5296 @param OrData The value to OR with the read value from the MSR.
5298 @return The lower 32-bit value written to the MSR.
5310 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
5311 the result back to the 64-bit MSR.
5313 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5314 lower 32-bits of the read result and the value specified by AndData, and
5315 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
5316 the value written to the MSR is returned. No parameter checking is performed
5317 on Index or AndData, and some of these may cause CPU exceptions. The caller
5318 must either guarantee that Index and AndData are valid, or the caller must
5319 establish proper exception handlers. This function is only available on IA-32
5322 @param Index The 32-bit MSR index to write.
5323 @param AndData The value to AND with the read value from the MSR.
5325 @return The lower 32-bit value written to the MSR.
5337 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
5338 on the lower 32-bits, and writes the result back to the 64-bit MSR.
5340 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5341 lower 32-bits of the read result and the value specified by AndData
5342 preserving the upper 32-bits, performs a bitwise inclusive OR between the
5343 result of the AND operation and the value specified by OrData, and writes the
5344 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
5345 written to the MSR is returned. No parameter checking is performed on Index,
5346 AndData, or OrData, and some of these may cause CPU exceptions. The caller
5347 must either guarantee that Index, AndData, and OrData are valid, or the
5348 caller must establish proper exception handlers. This function is only
5349 available on IA-32 and X64.
5351 @param Index The 32-bit MSR index to write.
5352 @param AndData The value to AND with the read value from the MSR.
5353 @param OrData The value to OR with the result of the AND operation.
5355 @return The lower 32-bit value written to the MSR.
5368 Reads a bit field of an MSR.
5370 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
5371 specified by the StartBit and the EndBit. The value of the bit field is
5372 returned. The caller must either guarantee that Index is valid, or the caller
5373 must set up exception handlers to catch the exceptions. This function is only
5374 available on IA-32 and X64.
5376 If StartBit is greater than 31, then ASSERT().
5377 If EndBit is greater than 31, then ASSERT().
5378 If EndBit is less than StartBit, then ASSERT().
5380 @param Index The 32-bit MSR index to read.
5381 @param StartBit The ordinal of the least significant bit in the bit field.
5383 @param EndBit The ordinal of the most significant bit in the bit field.
5386 @return The bit field read from the MSR.
5391 AsmMsrBitFieldRead32 (
5399 Writes a bit field to an MSR.
5401 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
5402 field is specified by the StartBit and the EndBit. All other bits in the
5403 destination MSR are preserved. The lower 32-bits of the MSR written is
5404 returned. Extra left bits in Value are stripped. The caller must either
5405 guarantee that Index and the data written is valid, or the caller must set up
5406 exception handlers to catch the exceptions. This function is only available
5409 If StartBit is greater than 31, then ASSERT().
5410 If EndBit is greater than 31, then ASSERT().
5411 If EndBit is less than StartBit, then ASSERT().
5413 @param Index The 32-bit MSR index to write.
5414 @param StartBit The ordinal of the least significant bit in the bit field.
5416 @param EndBit The ordinal of the most significant bit in the bit field.
5418 @param Value New value of the bit field.
5420 @return The lower 32-bit of the value written to the MSR.
5425 AsmMsrBitFieldWrite32 (
5434 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
5435 result back to the bit field in the 64-bit MSR.
5437 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5438 between the read result and the value specified by OrData, and writes the
5439 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
5440 written to the MSR are returned. Extra left bits in OrData are stripped. The
5441 caller must either guarantee that Index and the data written is valid, or
5442 the caller must set up exception handlers to catch the exceptions. This
5443 function is only available on IA-32 and X64.
5445 If StartBit is greater than 31, then ASSERT().
5446 If EndBit is greater than 31, then ASSERT().
5447 If EndBit is less than StartBit, then ASSERT().
5449 @param Index The 32-bit MSR index to write.
5450 @param StartBit The ordinal of the least significant bit in the bit field.
5452 @param EndBit The ordinal of the most significant bit in the bit field.
5454 @param OrData The value to OR with the read value from the MSR.
5456 @return The lower 32-bit of the value written to the MSR.
5461 AsmMsrBitFieldOr32 (
5470 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5471 result back to the bit field in the 64-bit MSR.
5473 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5474 read result and the value specified by AndData, and writes the result to the
5475 64-bit MSR specified by Index. The lower 32-bits of the value written to the
5476 MSR are returned. Extra left bits in AndData are stripped. The caller must
5477 either guarantee that Index and the data written is valid, or the caller must
5478 set up exception handlers to catch the exceptions. This function is only
5479 available on IA-32 and X64.
5481 If StartBit is greater than 31, then ASSERT().
5482 If EndBit is greater than 31, then ASSERT().
5483 If EndBit is less than StartBit, then ASSERT().
5485 @param Index The 32-bit MSR index to write.
5486 @param StartBit The ordinal of the least significant bit in the bit field.
5488 @param EndBit The ordinal of the most significant bit in the bit field.
5490 @param AndData The value to AND with the read value from the MSR.
5492 @return The lower 32-bit of the value written to the MSR.
5497 AsmMsrBitFieldAnd32 (
5506 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5507 bitwise inclusive OR, and writes the result back to the bit field in the
5510 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
5511 bitwise inclusive OR between the read result and the value specified by
5512 AndData, and writes the result to the 64-bit MSR specified by Index. The
5513 lower 32-bits of the value written to the MSR are returned. Extra left bits
5514 in both AndData and OrData are stripped. The caller must either guarantee
5515 that Index and the data written is valid, or the caller must set up exception
5516 handlers to catch the exceptions. This function is only available on IA-32
5519 If StartBit is greater than 31, then ASSERT().
5520 If EndBit is greater than 31, then ASSERT().
5521 If EndBit is less than StartBit, then ASSERT().
5523 @param Index The 32-bit MSR index to write.
5524 @param StartBit The ordinal of the least significant bit in the bit field.
5526 @param EndBit The ordinal of the most significant bit in the bit field.
5528 @param AndData The value to AND with the read value from the MSR.
5529 @param OrData The value to OR with the result of the AND operation.
5531 @return The lower 32-bit of the value written to the MSR.
5536 AsmMsrBitFieldAndThenOr32 (
5546 Returns a 64-bit Machine Specific Register(MSR).
5548 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
5549 performed on Index, and some Index values may cause CPU exceptions. The
5550 caller must either guarantee that Index is valid, or the caller must set up
5551 exception handlers to catch the exceptions. This function is only available
5554 @param Index The 32-bit MSR index to read.
5556 @return The value of the MSR identified by Index.
5567 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
5570 Writes the 64-bit value specified by Value to the MSR specified by Index. The
5571 64-bit value written to the MSR is returned. No parameter checking is
5572 performed on Index or Value, and some of these may cause CPU exceptions. The
5573 caller must either guarantee that Index and Value are valid, or the caller
5574 must establish proper exception handlers. This function is only available on
5577 @param Index The 32-bit MSR index to write.
5578 @param Value The 64-bit value to write to the MSR.
5592 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
5593 back to the 64-bit MSR.
5595 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5596 between the read result and the value specified by OrData, and writes the
5597 result to the 64-bit MSR specified by Index. The value written to the MSR is
5598 returned. No parameter checking is performed on Index or OrData, and some of
5599 these may cause CPU exceptions. The caller must either guarantee that Index
5600 and OrData are valid, or the caller must establish proper exception handlers.
5601 This function is only available on IA-32 and X64.
5603 @param Index The 32-bit MSR index to write.
5604 @param OrData The value to OR with the read value from the MSR.
5606 @return The value written back to the MSR.
5618 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
5621 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5622 read result and the value specified by OrData, and writes the result to the
5623 64-bit MSR specified by Index. The value written to the MSR is returned. No
5624 parameter checking is performed on Index or OrData, and some of these may
5625 cause CPU exceptions. The caller must either guarantee that Index and OrData
5626 are valid, or the caller must establish proper exception handlers. This
5627 function is only available on IA-32 and X64.
5629 @param Index The 32-bit MSR index to write.
5630 @param AndData The value to AND with the read value from the MSR.
5632 @return The value written back to the MSR.
5644 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
5645 OR, and writes the result back to the 64-bit MSR.
5647 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
5648 result and the value specified by AndData, performs a bitwise inclusive OR
5649 between the result of the AND operation and the value specified by OrData,
5650 and writes the result to the 64-bit MSR specified by Index. The value written
5651 to the MSR is returned. No parameter checking is performed on Index, AndData,
5652 or OrData, and some of these may cause CPU exceptions. The caller must either
5653 guarantee that Index, AndData, and OrData are valid, or the caller must
5654 establish proper exception handlers. This function is only available on IA-32
5657 @param Index The 32-bit MSR index to write.
5658 @param AndData The value to AND with the read value from the MSR.
5659 @param OrData The value to OR with the result of the AND operation.
5661 @return The value written back to the MSR.
5674 Reads a bit field of an MSR.
5676 Reads the bit field in the 64-bit MSR. The bit field is specified by the
5677 StartBit and the EndBit. The value of the bit field is returned. The caller
5678 must either guarantee that Index is valid, or the caller must set up
5679 exception handlers to catch the exceptions. This function is only available
5682 If StartBit is greater than 63, then ASSERT().
5683 If EndBit is greater than 63, then ASSERT().
5684 If EndBit is less than StartBit, then ASSERT().
5686 @param Index The 32-bit MSR index to read.
5687 @param StartBit The ordinal of the least significant bit in the bit field.
5689 @param EndBit The ordinal of the most significant bit in the bit field.
5692 @return The value read from the MSR.
5697 AsmMsrBitFieldRead64 (
5705 Writes a bit field to an MSR.
5707 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
5708 the StartBit and the EndBit. All other bits in the destination MSR are
5709 preserved. The MSR written is returned. Extra left bits in Value are
5710 stripped. The caller must either guarantee that Index and the data written is
5711 valid, or the caller must set up exception handlers to catch the exceptions.
5712 This function is only available on IA-32 and X64.
5714 If StartBit is greater than 63, then ASSERT().
5715 If EndBit is greater than 63, then ASSERT().
5716 If EndBit is less than StartBit, then ASSERT().
5718 @param Index The 32-bit MSR index to write.
5719 @param StartBit The ordinal of the least significant bit in the bit field.
5721 @param EndBit The ordinal of the most significant bit in the bit field.
5723 @param Value New value of the bit field.
5725 @return The value written back to the MSR.
5730 AsmMsrBitFieldWrite64 (
5739 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
5740 writes the result back to the bit field in the 64-bit MSR.
5742 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5743 between the read result and the value specified by OrData, and writes the
5744 result to the 64-bit MSR specified by Index. The value written to the MSR is
5745 returned. Extra left bits in OrData are stripped. The caller must either
5746 guarantee that Index and the data written is valid, or the caller must set up
5747 exception handlers to catch the exceptions. This function is only available
5750 If StartBit is greater than 63, then ASSERT().
5751 If EndBit is greater than 63, then ASSERT().
5752 If EndBit is less than StartBit, then ASSERT().
5754 @param Index The 32-bit MSR index to write.
5755 @param StartBit The ordinal of the least significant bit in the bit field.
5757 @param EndBit The ordinal of the most significant bit in the bit field.
5759 @param OrData The value to OR with the read value from the bit field.
5761 @return The value written back to the MSR.
5766 AsmMsrBitFieldOr64 (
5775 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5776 result back to the bit field in the 64-bit MSR.
5778 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5779 read result and the value specified by AndData, and writes the result to the
5780 64-bit MSR specified by Index. The value written to the MSR is returned.
5781 Extra left bits in AndData are stripped. The caller must either guarantee
5782 that Index and the data written is valid, or the caller must set up exception
5783 handlers to catch the exceptions. This function is only available on IA-32
5786 If StartBit is greater than 63, then ASSERT().
5787 If EndBit is greater than 63, then ASSERT().
5788 If EndBit is less than StartBit, then ASSERT().
5790 @param Index The 32-bit MSR index to write.
5791 @param StartBit The ordinal of the least significant bit in the bit field.
5793 @param EndBit The ordinal of the most significant bit in the bit field.
5795 @param AndData The value to AND with the read value from the bit field.
5797 @return The value written back to the MSR.
5802 AsmMsrBitFieldAnd64 (
5811 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5812 bitwise inclusive OR, and writes the result back to the bit field in the
5815 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
5816 a bitwise inclusive OR between the read result and the value specified by
5817 AndData, and writes the result to the 64-bit MSR specified by Index. The
5818 value written to the MSR is returned. Extra left bits in both AndData and
5819 OrData are stripped. The caller must either guarantee that Index and the data
5820 written is valid, or the caller must set up exception handlers to catch the
5821 exceptions. This function is only available on IA-32 and X64.
5823 If StartBit is greater than 63, then ASSERT().
5824 If EndBit is greater than 63, then ASSERT().
5825 If EndBit is less than StartBit, then ASSERT().
5827 @param Index The 32-bit MSR index to write.
5828 @param StartBit The ordinal of the least significant bit in the bit field.
5830 @param EndBit The ordinal of the most significant bit in the bit field.
5832 @param AndData The value to AND with the read value from the bit field.
5833 @param OrData The value to OR with the result of the AND operation.
5835 @return The value written back to the MSR.
5840 AsmMsrBitFieldAndThenOr64 (
5850 Reads the current value of the EFLAGS register.
5852 Reads and returns the current value of the EFLAGS register. This function is
5853 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
5854 64-bit value on X64.
5856 @return EFLAGS on IA-32 or RFLAGS on X64.
5867 Reads the current value of the Control Register 0 (CR0).
5869 Reads and returns the current value of CR0. This function is only available
5870 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5873 @return The value of the Control Register 0 (CR0).
5884 Reads the current value of the Control Register 2 (CR2).
5886 Reads and returns the current value of CR2. This function is only available
5887 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5890 @return The value of the Control Register 2 (CR2).
5901 Reads the current value of the Control Register 3 (CR3).
5903 Reads and returns the current value of CR3. This function is only available
5904 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5907 @return The value of the Control Register 3 (CR3).
5918 Reads the current value of the Control Register 4 (CR4).
5920 Reads and returns the current value of CR4. This function is only available
5921 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5924 @return The value of the Control Register 4 (CR4).
5935 Writes a value to Control Register 0 (CR0).
5937 Writes and returns a new value to CR0. This function is only available on
5938 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5940 @param Cr0 The value to write to CR0.
5942 @return The value written to CR0.
5953 Writes a value to Control Register 2 (CR2).
5955 Writes and returns a new value to CR2. This function is only available on
5956 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5958 @param Cr2 The value to write to CR2.
5960 @return The value written to CR2.
5971 Writes a value to Control Register 3 (CR3).
5973 Writes and returns a new value to CR3. This function is only available on
5974 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5976 @param Cr3 The value to write to CR3.
5978 @return The value written to CR3.
5989 Writes a value to Control Register 4 (CR4).
5991 Writes and returns a new value to CR4. This function is only available on
5992 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5994 @param Cr4 The value to write to CR4.
5996 @return The value written to CR4.
6007 Reads the current value of Debug Register 0 (DR0).
6009 Reads and returns the current value of DR0. This function is only available
6010 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6013 @return The value of Debug Register 0 (DR0).
6024 Reads the current value of Debug Register 1 (DR1).
6026 Reads and returns the current value of DR1. This function is only available
6027 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6030 @return The value of Debug Register 1 (DR1).
6041 Reads the current value of Debug Register 2 (DR2).
6043 Reads and returns the current value of DR2. This function is only available
6044 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6047 @return The value of Debug Register 2 (DR2).
6058 Reads the current value of Debug Register 3 (DR3).
6060 Reads and returns the current value of DR3. This function is only available
6061 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6064 @return The value of Debug Register 3 (DR3).
6075 Reads the current value of Debug Register 4 (DR4).
6077 Reads and returns the current value of DR4. This function is only available
6078 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6081 @return The value of Debug Register 4 (DR4).
6092 Reads the current value of Debug Register 5 (DR5).
6094 Reads and returns the current value of DR5. This function is only available
6095 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6098 @return The value of Debug Register 5 (DR5).
6109 Reads the current value of Debug Register 6 (DR6).
6111 Reads and returns the current value of DR6. This function is only available
6112 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6115 @return The value of Debug Register 6 (DR6).
6126 Reads the current value of Debug Register 7 (DR7).
6128 Reads and returns the current value of DR7. This function is only available
6129 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6132 @return The value of Debug Register 7 (DR7).
6143 Writes a value to Debug Register 0 (DR0).
6145 Writes and returns a new value to DR0. This function is only available on
6146 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6148 @param Dr0 The value to write to Dr0.
6150 @return The value written to Debug Register 0 (DR0).
6161 Writes a value to Debug Register 1 (DR1).
6163 Writes and returns a new value to DR1. This function is only available on
6164 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6166 @param Dr1 The value to write to Dr1.
6168 @return The value written to Debug Register 1 (DR1).
6179 Writes a value to Debug Register 2 (DR2).
6181 Writes and returns a new value to DR2. This function is only available on
6182 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6184 @param Dr2 The value to write to Dr2.
6186 @return The value written to Debug Register 2 (DR2).
6197 Writes a value to Debug Register 3 (DR3).
6199 Writes and returns a new value to DR3. This function is only available on
6200 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6202 @param Dr3 The value to write to Dr3.
6204 @return The value written to Debug Register 3 (DR3).
6215 Writes a value to Debug Register 4 (DR4).
6217 Writes and returns a new value to DR4. This function is only available on
6218 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6220 @param Dr4 The value to write to Dr4.
6222 @return The value written to Debug Register 4 (DR4).
6233 Writes a value to Debug Register 5 (DR5).
6235 Writes and returns a new value to DR5. This function is only available on
6236 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6238 @param Dr5 The value to write to Dr5.
6240 @return The value written to Debug Register 5 (DR5).
6251 Writes a value to Debug Register 6 (DR6).
6253 Writes and returns a new value to DR6. This function is only available on
6254 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6256 @param Dr6 The value to write to Dr6.
6258 @return The value written to Debug Register 6 (DR6).
6269 Writes a value to Debug Register 7 (DR7).
6271 Writes and returns a new value to DR7. This function is only available on
6272 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6274 @param Dr7 The value to write to Dr7.
6276 @return The value written to Debug Register 7 (DR7).
6287 Reads the current value of Code Segment Register (CS).
6289 Reads and returns the current value of CS. This function is only available on
6292 @return The current value of CS.
6303 Reads the current value of Data Segment Register (DS).
6305 Reads and returns the current value of DS. This function is only available on
6308 @return The current value of DS.
6319 Reads the current value of Extra Segment Register (ES).
6321 Reads and returns the current value of ES. This function is only available on
6324 @return The current value of ES.
6335 Reads the current value of FS Data Segment Register (FS).
6337 Reads and returns the current value of FS. This function is only available on
6340 @return The current value of FS.
6351 Reads the current value of GS Data Segment Register (GS).
6353 Reads and returns the current value of GS. This function is only available on
6356 @return The current value of GS.
6367 Reads the current value of Stack Segment Register (SS).
6369 Reads and returns the current value of SS. This function is only available on
6372 @return The current value of SS.
6383 Reads the current value of Task Register (TR).
6385 Reads and returns the current value of TR. This function is only available on
6388 @return The current value of TR.
6399 Reads the current Global Descriptor Table Register(GDTR) descriptor.
6401 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
6402 function is only available on IA-32 and X64.
6404 If Gdtr is NULL, then ASSERT().
6406 @param Gdtr Pointer to a GDTR descriptor.
6412 OUT IA32_DESCRIPTOR
*Gdtr
6417 Writes the current Global Descriptor Table Register (GDTR) descriptor.
6419 Writes and the current GDTR descriptor specified by Gdtr. This function is
6420 only available on IA-32 and X64.
6422 If Gdtr is NULL, then ASSERT().
6424 @param Gdtr Pointer to a GDTR descriptor.
6430 IN CONST IA32_DESCRIPTOR
*Gdtr
6435 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
6437 Reads and returns the current IDTR descriptor and returns it in Idtr. This
6438 function is only available on IA-32 and X64.
6440 If Idtr is NULL, then ASSERT().
6442 @param Idtr Pointer to a IDTR descriptor.
6448 OUT IA32_DESCRIPTOR
*Idtr
6453 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
6455 Writes the current IDTR descriptor and returns it in Idtr. This function is
6456 only available on IA-32 and X64.
6458 If Idtr is NULL, then ASSERT().
6460 @param Idtr Pointer to a IDTR descriptor.
6466 IN CONST IA32_DESCRIPTOR
*Idtr
6471 Reads the current Local Descriptor Table Register(LDTR) selector.
6473 Reads and returns the current 16-bit LDTR descriptor value. This function is
6474 only available on IA-32 and X64.
6476 @return The current selector of LDT.
6487 Writes the current Local Descriptor Table Register (GDTR) selector.
6489 Writes and the current LDTR descriptor specified by Ldtr. This function is
6490 only available on IA-32 and X64.
6492 @param Ldtr 16-bit LDTR selector value.
6503 Save the current floating point/SSE/SSE2 context to a buffer.
6505 Saves the current floating point/SSE/SSE2 state to the buffer specified by
6506 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
6507 available on IA-32 and X64.
6509 If Buffer is NULL, then ASSERT().
6510 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6512 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6518 OUT IA32_FX_BUFFER
*Buffer
6523 Restores the current floating point/SSE/SSE2 context from a buffer.
6525 Restores the current floating point/SSE/SSE2 state from the buffer specified
6526 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
6527 only available on IA-32 and X64.
6529 If Buffer is NULL, then ASSERT().
6530 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6531 If Buffer was not saved with AsmFxSave(), then ASSERT().
6533 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6539 IN CONST IA32_FX_BUFFER
*Buffer
6544 Reads the current value of 64-bit MMX Register #0 (MM0).
6546 Reads and returns the current value of MM0. This function is only available
6549 @return The current value of MM0.
6560 Reads the current value of 64-bit MMX Register #1 (MM1).
6562 Reads and returns the current value of MM1. This function is only available
6565 @return The current value of MM1.
6576 Reads the current value of 64-bit MMX Register #2 (MM2).
6578 Reads and returns the current value of MM2. This function is only available
6581 @return The current value of MM2.
6592 Reads the current value of 64-bit MMX Register #3 (MM3).
6594 Reads and returns the current value of MM3. This function is only available
6597 @return The current value of MM3.
6608 Reads the current value of 64-bit MMX Register #4 (MM4).
6610 Reads and returns the current value of MM4. This function is only available
6613 @return The current value of MM4.
6624 Reads the current value of 64-bit MMX Register #5 (MM5).
6626 Reads and returns the current value of MM5. This function is only available
6629 @return The current value of MM5.
6640 Reads the current value of 64-bit MMX Register #6 (MM6).
6642 Reads and returns the current value of MM6. This function is only available
6645 @return The current value of MM6.
6656 Reads the current value of 64-bit MMX Register #7 (MM7).
6658 Reads and returns the current value of MM7. This function is only available
6661 @return The current value of MM7.
6672 Writes the current value of 64-bit MMX Register #0 (MM0).
6674 Writes the current value of MM0. This function is only available on IA32 and
6677 @param Value The 64-bit value to write to MM0.
6688 Writes the current value of 64-bit MMX Register #1 (MM1).
6690 Writes the current value of MM1. This function is only available on IA32 and
6693 @param Value The 64-bit value to write to MM1.
6704 Writes the current value of 64-bit MMX Register #2 (MM2).
6706 Writes the current value of MM2. This function is only available on IA32 and
6709 @param Value The 64-bit value to write to MM2.
6720 Writes the current value of 64-bit MMX Register #3 (MM3).
6722 Writes the current value of MM3. This function is only available on IA32 and
6725 @param Value The 64-bit value to write to MM3.
6736 Writes the current value of 64-bit MMX Register #4 (MM4).
6738 Writes the current value of MM4. This function is only available on IA32 and
6741 @param Value The 64-bit value to write to MM4.
6752 Writes the current value of 64-bit MMX Register #5 (MM5).
6754 Writes the current value of MM5. This function is only available on IA32 and
6757 @param Value The 64-bit value to write to MM5.
6768 Writes the current value of 64-bit MMX Register #6 (MM6).
6770 Writes the current value of MM6. This function is only available on IA32 and
6773 @param Value The 64-bit value to write to MM6.
6784 Writes the current value of 64-bit MMX Register #7 (MM7).
6786 Writes the current value of MM7. This function is only available on IA32 and
6789 @param Value The 64-bit value to write to MM7.
6800 Reads the current value of Time Stamp Counter (TSC).
6802 Reads and returns the current value of TSC. This function is only available
6805 @return The current value of TSC
6816 Reads the current value of a Performance Counter (PMC).
6818 Reads and returns the current value of performance counter specified by
6819 Index. This function is only available on IA-32 and X64.
6821 @param Index The 32-bit Performance Counter index to read.
6823 @return The value of the PMC specified by Index.
6834 Sets up a monitor buffer that is used by AsmMwait().
6836 Executes a MONITOR instruction with the register state specified by Eax, Ecx
6837 and Edx. Returns Eax. This function is only available on IA-32 and X64.
6839 @param Eax The value to load into EAX or RAX before executing the MONITOR
6841 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6843 @param Edx The value to load into EDX or RDX before executing the MONITOR
6859 Executes an MWAIT instruction.
6861 Executes an MWAIT instruction with the register state specified by Eax and
6862 Ecx. Returns Eax. This function is only available on IA-32 and X64.
6864 @param Eax The value to load into EAX or RAX before executing the MONITOR
6866 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6881 Executes a WBINVD instruction.
6883 Executes a WBINVD instruction. This function is only available on IA-32 and
6895 Executes a INVD instruction.
6897 Executes a INVD instruction. This function is only available on IA-32 and
6909 Flushes a cache line from all the instruction and data caches within the
6910 coherency domain of the CPU.
6912 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
6913 This function is only available on IA-32 and X64.
6915 @param LinearAddress The address of the cache line to flush. If the CPU is
6916 in a physical addressing mode, then LinearAddress is a
6917 physical address. If the CPU is in a virtual
6918 addressing mode, then LinearAddress is a virtual
6921 @return LinearAddress
6926 IN VOID
*LinearAddress
6931 Enables the 32-bit paging mode on the CPU.
6933 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
6934 must be properly initialized prior to calling this service. This function
6935 assumes the current execution mode is 32-bit protected mode. This function is
6936 only available on IA-32. After the 32-bit paging mode is enabled, control is
6937 transferred to the function specified by EntryPoint using the new stack
6938 specified by NewStack and passing in the parameters specified by Context1 and
6939 Context2. Context1 and Context2 are optional and may be NULL. The function
6940 EntryPoint must never return.
6942 If the current execution mode is not 32-bit protected mode, then ASSERT().
6943 If EntryPoint is NULL, then ASSERT().
6944 If NewStack is NULL, then ASSERT().
6946 There are a number of constraints that must be followed before calling this
6948 1) Interrupts must be disabled.
6949 2) The caller must be in 32-bit protected mode with flat descriptors. This
6950 means all descriptors must have a base of 0 and a limit of 4GB.
6951 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
6953 4) CR3 must point to valid page tables that will be used once the transition
6954 is complete, and those page tables must guarantee that the pages for this
6955 function and the stack are identity mapped.
6957 @param EntryPoint A pointer to function to call with the new stack after
6959 @param Context1 A pointer to the context to pass into the EntryPoint
6960 function as the first parameter after paging is enabled.
6961 @param Context2 A pointer to the context to pass into the EntryPoint
6962 function as the second parameter after paging is enabled.
6963 @param NewStack A pointer to the new stack to use for the EntryPoint
6964 function after paging is enabled.
6970 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
6971 IN VOID
*Context1
, OPTIONAL
6972 IN VOID
*Context2
, OPTIONAL
6978 Disables the 32-bit paging mode on the CPU.
6980 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
6981 mode. This function assumes the current execution mode is 32-paged protected
6982 mode. This function is only available on IA-32. After the 32-bit paging mode
6983 is disabled, control is transferred to the function specified by EntryPoint
6984 using the new stack specified by NewStack and passing in the parameters
6985 specified by Context1 and Context2. Context1 and Context2 are optional and
6986 may be NULL. The function EntryPoint must never return.
6988 If the current execution mode is not 32-bit paged mode, then ASSERT().
6989 If EntryPoint is NULL, then ASSERT().
6990 If NewStack is NULL, then ASSERT().
6992 There are a number of constraints that must be followed before calling this
6994 1) Interrupts must be disabled.
6995 2) The caller must be in 32-bit paged mode.
6996 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
6997 4) CR3 must point to valid page tables that guarantee that the pages for
6998 this function and the stack are identity mapped.
7000 @param EntryPoint A pointer to function to call with the new stack after
7002 @param Context1 A pointer to the context to pass into the EntryPoint
7003 function as the first parameter after paging is disabled.
7004 @param Context2 A pointer to the context to pass into the EntryPoint
7005 function as the second parameter after paging is
7007 @param NewStack A pointer to the new stack to use for the EntryPoint
7008 function after paging is disabled.
7013 AsmDisablePaging32 (
7014 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
7015 IN VOID
*Context1
, OPTIONAL
7016 IN VOID
*Context2
, OPTIONAL
7022 Enables the 64-bit paging mode on the CPU.
7024 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7025 must be properly initialized prior to calling this service. This function
7026 assumes the current execution mode is 32-bit protected mode with flat
7027 descriptors. This function is only available on IA-32. After the 64-bit
7028 paging mode is enabled, control is transferred to the function specified by
7029 EntryPoint using the new stack specified by NewStack and passing in the
7030 parameters specified by Context1 and Context2. Context1 and Context2 are
7031 optional and may be 0. The function EntryPoint must never return.
7033 If the current execution mode is not 32-bit protected mode with flat
7034 descriptors, then ASSERT().
7035 If EntryPoint is 0, then ASSERT().
7036 If NewStack is 0, then ASSERT().
7038 @param Cs The 16-bit selector to load in the CS before EntryPoint
7039 is called. The descriptor in the GDT that this selector
7040 references must be setup for long mode.
7041 @param EntryPoint The 64-bit virtual address of the function to call with
7042 the new stack after paging is enabled.
7043 @param Context1 The 64-bit virtual address of the context to pass into
7044 the EntryPoint function as the first parameter after
7046 @param Context2 The 64-bit virtual address of the context to pass into
7047 the EntryPoint function as the second parameter after
7049 @param NewStack The 64-bit virtual address of the new stack to use for
7050 the EntryPoint function after paging is enabled.
7056 IN UINT16 CodeSelector
,
7057 IN UINT64 EntryPoint
,
7058 IN UINT64 Context1
, OPTIONAL
7059 IN UINT64 Context2
, OPTIONAL
7065 Disables the 64-bit paging mode on the CPU.
7067 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
7068 mode. This function assumes the current execution mode is 64-paging mode.
7069 This function is only available on X64. After the 64-bit paging mode is
7070 disabled, control is transferred to the function specified by EntryPoint
7071 using the new stack specified by NewStack and passing in the parameters
7072 specified by Context1 and Context2. Context1 and Context2 are optional and
7073 may be 0. The function EntryPoint must never return.
7075 If the current execution mode is not 64-bit paged mode, then ASSERT().
7076 If EntryPoint is 0, then ASSERT().
7077 If NewStack is 0, then ASSERT().
7079 @param Cs The 16-bit selector to load in the CS before EntryPoint
7080 is called. The descriptor in the GDT that this selector
7081 references must be setup for 32-bit protected mode.
7082 @param EntryPoint The 64-bit virtual address of the function to call with
7083 the new stack after paging is disabled.
7084 @param Context1 The 64-bit virtual address of the context to pass into
7085 the EntryPoint function as the first parameter after
7087 @param Context2 The 64-bit virtual address of the context to pass into
7088 the EntryPoint function as the second parameter after
7090 @param NewStack The 64-bit virtual address of the new stack to use for
7091 the EntryPoint function after paging is disabled.
7096 AsmDisablePaging64 (
7097 IN UINT16 CodeSelector
,
7098 IN UINT32 EntryPoint
,
7099 IN UINT32 Context1
, OPTIONAL
7100 IN UINT32 Context2
, OPTIONAL
7106 // 16-bit thunking services
7110 Retrieves the properties for 16-bit thunk functions.
7112 Computes the size of the buffer and stack below 1MB required to use the
7113 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
7114 buffer size is returned in RealModeBufferSize, and the stack size is returned
7115 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
7116 then the actual minimum stack size is ExtraStackSize plus the maximum number
7117 of bytes that need to be passed to the 16-bit real mode code.
7119 If RealModeBufferSize is NULL, then ASSERT().
7120 If ExtraStackSize is NULL, then ASSERT().
7122 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
7123 required to use the 16-bit thunk functions.
7124 @param ExtraStackSize A pointer to the extra size of stack below 1MB
7125 that the 16-bit thunk functions require for
7126 temporary storage in the transition to and from
7132 AsmGetThunk16Properties (
7133 OUT UINT32
*RealModeBufferSize
,
7134 OUT UINT32
*ExtraStackSize
7139 Prepares all structures a code required to use AsmThunk16().
7141 Prepares all structures and code required to use AsmThunk16().
7143 If ThunkContext is NULL, then ASSERT().
7145 @param ThunkContext A pointer to the context structure that describes the
7146 16-bit real mode code to call.
7152 OUT THUNK_CONTEXT
*ThunkContext
7157 Transfers control to a 16-bit real mode entry point and returns the results.
7159 Transfers control to a 16-bit real mode entry point and returns the results.
7160 AsmPrepareThunk16() must be called with ThunkContext before this function is
7163 If ThunkContext is NULL, then ASSERT().
7164 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
7166 @param ThunkContext A pointer to the context structure that describes the
7167 16-bit real mode code to call.
7173 IN OUT THUNK_CONTEXT
*ThunkContext
7178 Prepares all structures and code for a 16-bit real mode thunk, transfers
7179 control to a 16-bit real mode entry point, and returns the results.
7181 Prepares all structures and code for a 16-bit real mode thunk, transfers
7182 control to a 16-bit real mode entry point, and returns the results. If the
7183 caller only need to perform a single 16-bit real mode thunk, then this
7184 service should be used. If the caller intends to make more than one 16-bit
7185 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
7186 once and AsmThunk16() can be called for each 16-bit real mode thunk.
7188 If ThunkContext is NULL, then ASSERT().
7190 @param ThunkContext A pointer to the context structure that describes the
7191 16-bit real mode code to call.
7196 AsmPrepareAndThunk16 (
7197 IN OUT THUNK_CONTEXT
*ThunkContext