2 Provides string functions, linked list functions, math functions, synchronization
3 functions, and CPU architecture specific functions.
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 /// Definitions for SPIN_LOCK
22 typedef volatile UINTN SPIN_LOCK
;
25 // Definitions for architecture specific types
27 #if defined (MDE_CPU_IA32)
29 /// IA32 context buffer used by SetJump() and LongJump()
38 } BASE_LIBRARY_JUMP_BUFFER
;
40 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 4
42 #endif // defined (MDE_CPU_IA32)
44 #if defined (MDE_CPU_IPF)
47 /// IPF context buffer used by SetJump() and LongJump()
82 UINT64 AfterSpillUNAT
;
88 } BASE_LIBRARY_JUMP_BUFFER
;
90 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10
92 #endif // defined (MDE_CPU_IPF)
94 #if defined (MDE_CPU_X64)
96 /// x64 context buffer used by SetJump() and LongJump()
109 } BASE_LIBRARY_JUMP_BUFFER
;
111 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
113 #endif // defined (MDE_CPU_X64)
115 #if defined (MDE_CPU_EBC)
117 /// EBC context buffer used by SetJump() and LongJump()
125 } BASE_LIBRARY_JUMP_BUFFER
;
127 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
129 #endif // defined (MDE_CPU_EBC)
136 Copies one Null-terminated Unicode string to another Null-terminated Unicode
137 string and returns the new Unicode string.
139 This function copies the contents of the Unicode string Source to the Unicode
140 string Destination, and returns Destination. If Source and Destination
141 overlap, then the results are undefined.
143 If Destination is NULL, then ASSERT().
144 If Destination is not aligned on a 16-bit boundary, then ASSERT().
145 If Source is NULL, then ASSERT().
146 If Source is not aligned on a 16-bit boundary, then ASSERT().
147 If Source and Destination overlap, then ASSERT().
148 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
149 PcdMaximumUnicodeStringLength Unicode characters not including the
150 Null-terminator, then ASSERT().
152 @param Destination Pointer to a Null-terminated Unicode string.
153 @param Source Pointer to a Null-terminated Unicode string.
161 OUT CHAR16
*Destination
,
162 IN CONST CHAR16
*Source
167 Copies up to a specified length from one Null-terminated Unicode string to
168 another Null-terminated Unicode string and returns the new Unicode string.
170 This function copies the contents of the Unicode string Source to the Unicode
171 string Destination, and returns Destination. At most, Length Unicode
172 characters are copied from Source to Destination. If Length is 0, then
173 Destination is returned unmodified. If Length is greater that the number of
174 Unicode characters in Source, then Destination is padded with Null Unicode
175 characters. If Source and Destination overlap, then the results are
178 If Length > 0 and Destination is NULL, then ASSERT().
179 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
180 If Length > 0 and Source is NULL, then ASSERT().
181 If Length > 0 and Source is not aligned on a 16-bit bounadry, then ASSERT().
182 If Source and Destination overlap, then ASSERT().
183 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
184 PcdMaximumUnicodeStringLength Unicode characters not including the
185 Null-terminator, then ASSERT().
187 @param Destination Pointer to a Null-terminated Unicode string.
188 @param Source Pointer to a Null-terminated Unicode string.
189 @param Length Maximum number of Unicode characters to copy.
197 OUT CHAR16
*Destination
,
198 IN CONST CHAR16
*Source
,
204 Returns the length of a Null-terminated Unicode string.
206 This function returns the number of Unicode characters in the Null-terminated
207 Unicode string specified by String.
209 If String is NULL, then ASSERT().
210 If String is not aligned on a 16-bit boundary, then ASSERT().
211 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
212 PcdMaximumUnicodeStringLength Unicode characters not including the
213 Null-terminator, then ASSERT().
215 @param String Pointer to a Null-terminated Unicode string.
217 @return The length of String.
223 IN CONST CHAR16
*String
228 Returns the size of a Null-terminated Unicode string in bytes, including the
231 This function returns the size, in bytes, of the Null-terminated Unicode string
234 If String is NULL, then ASSERT().
235 If String is not aligned on a 16-bit boundary, then ASSERT().
236 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
237 PcdMaximumUnicodeStringLength Unicode characters not including the
238 Null-terminator, then ASSERT().
240 @param String Pointer to a Null-terminated Unicode string.
242 @return The size of String.
248 IN CONST CHAR16
*String
253 Compares two Null-terminated Unicode strings, and returns the difference
254 between the first mismatched Unicode characters.
256 This function compares the Null-terminated Unicode string FirstString to the
257 Null-terminated Unicode string SecondString. If FirstString is identical to
258 SecondString, then 0 is returned. Otherwise, the value returned is the first
259 mismatched Unicode character in SecondString subtracted from the first
260 mismatched Unicode character in FirstString.
262 If FirstString is NULL, then ASSERT().
263 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
264 If SecondString is NULL, then ASSERT().
265 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
266 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
267 than PcdMaximumUnicodeStringLength Unicode characters not including the
268 Null-terminator, then ASSERT().
269 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
270 than PcdMaximumUnicodeStringLength Unicode characters not including the
271 Null-terminator, then ASSERT().
273 @param FirstString Pointer to a Null-terminated Unicode string.
274 @param SecondString Pointer to a Null-terminated Unicode string.
276 @retval 0 FirstString is identical to SecondString.
277 @return others FirstString is not identical to SecondString.
283 IN CONST CHAR16
*FirstString
,
284 IN CONST CHAR16
*SecondString
289 Compares up to a specified length the contents of two Null-terminated Unicode strings,
290 and returns the difference between the first mismatched Unicode characters.
292 This function compares the Null-terminated Unicode string FirstString to the
293 Null-terminated Unicode string SecondString. At most, Length Unicode
294 characters will be compared. If Length is 0, then 0 is returned. If
295 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
296 value returned is the first mismatched Unicode character in SecondString
297 subtracted from the first mismatched Unicode character in FirstString.
299 If Length > 0 and FirstString is NULL, then ASSERT().
300 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().
301 If Length > 0 and SecondString is NULL, then ASSERT().
302 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().
303 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
304 than PcdMaximumUnicodeStringLength Unicode characters not including the
305 Null-terminator, then ASSERT().
306 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
307 than PcdMaximumUnicodeStringLength Unicode characters not including the
308 Null-terminator, then ASSERT().
310 @param FirstString Pointer to a Null-terminated Unicode string.
311 @param SecondString Pointer to a Null-terminated Unicode string.
312 @param Length Maximum number of Unicode characters to compare.
314 @retval 0 FirstString is identical to SecondString.
315 @return others FirstString is not identical to SecondString.
321 IN CONST CHAR16
*FirstString
,
322 IN CONST CHAR16
*SecondString
,
328 Concatenates one Null-terminated Unicode string to another Null-terminated
329 Unicode string, and returns the concatenated Unicode string.
331 This function concatenates two Null-terminated Unicode strings. The contents
332 of Null-terminated Unicode string Source are concatenated to the end of
333 Null-terminated Unicode string Destination. The Null-terminated concatenated
334 Unicode String is returned. If Source and Destination overlap, then the
335 results are undefined.
337 If Destination is NULL, then ASSERT().
338 If Destination is not aligned on a 16-bit bounadary, then ASSERT().
339 If Source is NULL, then ASSERT().
340 If Source is not aligned on a 16-bit bounadary, then ASSERT().
341 If Source and Destination overlap, then ASSERT().
342 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
343 than PcdMaximumUnicodeStringLength Unicode characters not including the
344 Null-terminator, then ASSERT().
345 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
346 PcdMaximumUnicodeStringLength Unicode characters not including the
347 Null-terminator, then ASSERT().
348 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
349 and Source results in a Unicode string with more than
350 PcdMaximumUnicodeStringLength Unicode characters not including the
351 Null-terminator, then ASSERT().
353 @param Destination Pointer to a Null-terminated Unicode string.
354 @param Source Pointer to a Null-terminated Unicode string.
362 IN OUT CHAR16
*Destination
,
363 IN CONST CHAR16
*Source
368 Concatenates up to a specified length one Null-terminated Unicode to the end
369 of another Null-terminated Unicode string, and returns the concatenated
372 This function concatenates two Null-terminated Unicode strings. The contents
373 of Null-terminated Unicode string Source are concatenated to the end of
374 Null-terminated Unicode string Destination, and Destination is returned. At
375 most, Length Unicode characters are concatenated from Source to the end of
376 Destination, and Destination is always Null-terminated. If Length is 0, then
377 Destination is returned unmodified. If Source and Destination overlap, then
378 the results are undefined.
380 If Destination is NULL, then ASSERT().
381 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
382 If Length > 0 and Source is NULL, then ASSERT().
383 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
384 If Source and Destination overlap, then ASSERT().
385 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
386 than PcdMaximumUnicodeStringLength Unicode characters not including the
387 Null-terminator, then ASSERT().
388 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
389 PcdMaximumUnicodeStringLength Unicode characters not including the
390 Null-terminator, then ASSERT().
391 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
392 and Source results in a Unicode string with more than
393 PcdMaximumUnicodeStringLength Unicode characters not including the
394 Null-terminator, then ASSERT().
396 @param Destination Pointer to a Null-terminated Unicode string.
397 @param Source Pointer to a Null-terminated Unicode string.
398 @param Length Maximum number of Unicode characters to concatenate from
407 IN OUT CHAR16
*Destination
,
408 IN CONST CHAR16
*Source
,
413 Returns the first occurrence of a Null-terminated Unicode sub-string
414 in a Null-terminated Unicode string.
416 This function scans the contents of the Null-terminated Unicode string
417 specified by String and returns the first occurrence of SearchString.
418 If SearchString is not found in String, then NULL is returned. If
419 the length of SearchString is zero, then String is
422 If String is NULL, then ASSERT().
423 If String is not aligned on a 16-bit boundary, then ASSERT().
424 If SearchString is NULL, then ASSERT().
425 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
427 If PcdMaximumUnicodeStringLength is not zero, and SearchString
428 or String contains more than PcdMaximumUnicodeStringLength Unicode
429 characters not including the Null-terminator, then ASSERT().
431 @param String Pointer to a Null-terminated Unicode string.
432 @param SearchString Pointer to a Null-terminated Unicode string to search for.
434 @retval NULL If the SearchString does not appear in String.
435 @return others If there is a match.
441 IN CONST CHAR16
*String
,
442 IN CONST CHAR16
*SearchString
446 Convert a Null-terminated Unicode decimal string to a value of
449 This function returns a value of type UINTN by interpreting the contents
450 of the Unicode string specified by String as a decimal number. The format
451 of the input Unicode string String is:
453 [spaces] [decimal digits].
455 The valid decimal digit character is in the range [0-9]. The
456 function will ignore the pad space, which includes spaces or
457 tab characters, before [decimal digits]. The running zero in the
458 beginning of [decimal digits] will be ignored. Then, the function
459 stops at the first character that is a not a valid decimal character
460 or a Null-terminator, whichever one comes first.
462 If String is NULL, then ASSERT().
463 If String is not aligned in a 16-bit boundary, then ASSERT().
464 If String has only pad spaces, then 0 is returned.
465 If String has no pad spaces or valid decimal digits,
467 If the number represented by String overflows according
468 to the range defined by UINTN, then ASSERT().
470 If PcdMaximumUnicodeStringLength is not zero, and String contains
471 more than PcdMaximumUnicodeStringLength Unicode characters not including
472 the Null-terminator, then ASSERT().
474 @param String Pointer to a Null-terminated Unicode string.
476 @retval Value translated from String.
482 IN CONST CHAR16
*String
486 Convert a Null-terminated Unicode decimal string to a value of
489 This function returns a value of type UINT64 by interpreting the contents
490 of the Unicode string specified by String as a decimal number. The format
491 of the input Unicode string String is:
493 [spaces] [decimal digits].
495 The valid decimal digit character is in the range [0-9]. The
496 function will ignore the pad space, which includes spaces or
497 tab characters, before [decimal digits]. The running zero in the
498 beginning of [decimal digits] will be ignored. Then, the function
499 stops at the first character that is a not a valid decimal character
500 or a Null-terminator, whichever one comes first.
502 If String is NULL, then ASSERT().
503 If String is not aligned in a 16-bit boundary, then ASSERT().
504 If String has only pad spaces, then 0 is returned.
505 If String has no pad spaces or valid decimal digits,
507 If the number represented by String overflows according
508 to the range defined by UINT64, then ASSERT().
510 If PcdMaximumUnicodeStringLength is not zero, and String contains
511 more than PcdMaximumUnicodeStringLength Unicode characters not including
512 the Null-terminator, then ASSERT().
514 @param String Pointer to a Null-terminated Unicode string.
516 @retval Value translated from String.
522 IN CONST CHAR16
*String
527 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
529 This function returns a value of type UINTN by interpreting the contents
530 of the Unicode string specified by String as a hexadecimal number.
531 The format of the input Unicode string String is:
533 [spaces][zeros][x][hexadecimal digits].
535 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
536 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
537 If "x" appears in the input string, it must be prefixed with at least one 0.
538 The function will ignore the pad space, which includes spaces or tab characters,
539 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
540 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
541 first valid hexadecimal digit. Then, the function stops at the first character that is
542 a not a valid hexadecimal character or NULL, whichever one comes first.
544 If String is NULL, then ASSERT().
545 If String is not aligned in a 16-bit boundary, then ASSERT().
546 If String has only pad spaces, then zero is returned.
547 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
548 then zero is returned.
549 If the number represented by String overflows according to the range defined by
550 UINTN, then ASSERT().
552 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
553 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
556 @param String Pointer to a Null-terminated Unicode string.
558 @retval Value translated from String.
564 IN CONST CHAR16
*String
569 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
571 This function returns a value of type UINT64 by interpreting the contents
572 of the Unicode string specified by String as a hexadecimal number.
573 The format of the input Unicode string String is
575 [spaces][zeros][x][hexadecimal digits].
577 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
578 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
579 If "x" appears in the input string, it must be prefixed with at least one 0.
580 The function will ignore the pad space, which includes spaces or tab characters,
581 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
582 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
583 first valid hexadecimal digit. Then, the function stops at the first character that is
584 a not a valid hexadecimal character or NULL, whichever one comes first.
586 If String is NULL, then ASSERT().
587 If String is not aligned in a 16-bit boundary, then ASSERT().
588 If String has only pad spaces, then zero is returned.
589 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
590 then zero is returned.
591 If the number represented by String overflows according to the range defined by
592 UINT64, then ASSERT().
594 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
595 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
598 @param String Pointer to a Null-terminated Unicode string.
600 @retval Value translated from String.
606 IN CONST CHAR16
*String
610 Convert a Null-terminated Unicode string to a Null-terminated
611 ASCII string and returns the ASCII string.
613 This function converts the content of the Unicode string Source
614 to the ASCII string Destination by copying the lower 8 bits of
615 each Unicode character. It returns Destination.
617 If any Unicode characters in Source contain non-zero value in
618 the upper 8 bits, then ASSERT().
620 If Destination is NULL, then ASSERT().
621 If Source is NULL, then ASSERT().
622 If Source is not aligned on a 16-bit boundary, then ASSERT().
623 If Source and Destination overlap, then ASSERT().
625 If PcdMaximumUnicodeStringLength is not zero, and Source contains
626 more than PcdMaximumUnicodeStringLength Unicode characters not including
627 the Null-terminator, then ASSERT().
629 If PcdMaximumAsciiStringLength is not zero, and Source contains more
630 than PcdMaximumAsciiStringLength Unicode characters not including the
631 Null-terminator, then ASSERT().
633 @param Source Pointer to a Null-terminated Unicode string.
634 @param Destination Pointer to a Null-terminated ASCII string.
641 UnicodeStrToAsciiStr (
642 IN CONST CHAR16
*Source
,
643 OUT CHAR8
*Destination
648 Copies one Null-terminated ASCII string to another Null-terminated ASCII
649 string and returns the new ASCII string.
651 This function copies the contents of the ASCII string Source to the ASCII
652 string Destination, and returns Destination. If Source and Destination
653 overlap, then the results are undefined.
655 If Destination is NULL, then ASSERT().
656 If Source is NULL, then ASSERT().
657 If Source and Destination overlap, then ASSERT().
658 If PcdMaximumAsciiStringLength is not zero and Source contains more than
659 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
662 @param Destination Pointer to a Null-terminated ASCII string.
663 @param Source Pointer to a Null-terminated ASCII string.
671 OUT CHAR8
*Destination
,
672 IN CONST CHAR8
*Source
677 Copies up to a specified length one Null-terminated ASCII string to another
678 Null-terminated ASCII string and returns the new ASCII string.
680 This function copies the contents of the ASCII string Source to the ASCII
681 string Destination, and returns Destination. At most, Length ASCII characters
682 are copied from Source to Destination. If Length is 0, then Destination is
683 returned unmodified. If Length is greater that the number of ASCII characters
684 in Source, then Destination is padded with Null ASCII characters. If Source
685 and Destination overlap, then the results are undefined.
687 If Destination is NULL, then ASSERT().
688 If Source is NULL, then ASSERT().
689 If Source and Destination overlap, then ASSERT().
690 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
691 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
694 @param Destination Pointer to a Null-terminated ASCII string.
695 @param Source Pointer to a Null-terminated ASCII string.
696 @param Length Maximum number of ASCII characters to copy.
704 OUT CHAR8
*Destination
,
705 IN CONST CHAR8
*Source
,
711 Returns the length of a Null-terminated ASCII string.
713 This function returns the number of ASCII characters in the Null-terminated
714 ASCII string specified by String.
716 If Length > 0 and Destination is NULL, then ASSERT().
717 If Length > 0 and Source is NULL, then ASSERT().
718 If PcdMaximumAsciiStringLength is not zero and String contains more than
719 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
722 @param String Pointer to a Null-terminated ASCII string.
724 @return The length of String.
730 IN CONST CHAR8
*String
735 Returns the size of a Null-terminated ASCII string in bytes, including the
738 This function returns the size, in bytes, of the Null-terminated ASCII string
741 If String is NULL, then ASSERT().
742 If PcdMaximumAsciiStringLength is not zero and String contains more than
743 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
746 @param String Pointer to a Null-terminated ASCII string.
748 @return The size of String.
754 IN CONST CHAR8
*String
759 Compares two Null-terminated ASCII strings, and returns the difference
760 between the first mismatched ASCII characters.
762 This function compares the Null-terminated ASCII string FirstString to the
763 Null-terminated ASCII string SecondString. If FirstString is identical to
764 SecondString, then 0 is returned. Otherwise, the value returned is the first
765 mismatched ASCII character in SecondString subtracted from the first
766 mismatched ASCII character in FirstString.
768 If FirstString is NULL, then ASSERT().
769 If SecondString is NULL, then ASSERT().
770 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
771 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
773 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
774 than PcdMaximumAsciiStringLength ASCII characters not including the
775 Null-terminator, then ASSERT().
777 @param FirstString Pointer to a Null-terminated ASCII string.
778 @param SecondString Pointer to a Null-terminated ASCII string.
780 @retval ==0 FirstString is identical to SecondString.
781 @retval !=0 FirstString is not identical to SecondString.
787 IN CONST CHAR8
*FirstString
,
788 IN CONST CHAR8
*SecondString
793 Performs a case insensitive comparison of two Null-terminated ASCII strings,
794 and returns the difference between the first mismatched ASCII characters.
796 This function performs a case insensitive comparison of the Null-terminated
797 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
798 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
799 value returned is the first mismatched lower case ASCII character in
800 SecondString subtracted from the first mismatched lower case ASCII character
803 If FirstString is NULL, then ASSERT().
804 If SecondString is NULL, then ASSERT().
805 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
806 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
808 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
809 than PcdMaximumAsciiStringLength ASCII characters not including the
810 Null-terminator, then ASSERT().
812 @param FirstString Pointer to a Null-terminated ASCII string.
813 @param SecondString Pointer to a Null-terminated ASCII string.
815 @retval ==0 FirstString is identical to SecondString using case insensitive
817 @retval !=0 FirstString is not identical to SecondString using case
818 insensitive comparisons.
824 IN CONST CHAR8
*FirstString
,
825 IN CONST CHAR8
*SecondString
830 Compares two Null-terminated ASCII strings with maximum lengths, and returns
831 the difference between the first mismatched ASCII characters.
833 This function compares the Null-terminated ASCII string FirstString to the
834 Null-terminated ASCII string SecondString. At most, Length ASCII characters
835 will be compared. If Length is 0, then 0 is returned. If FirstString is
836 identical to SecondString, then 0 is returned. Otherwise, the value returned
837 is the first mismatched ASCII character in SecondString subtracted from the
838 first mismatched ASCII character in FirstString.
840 If Length > 0 and FirstString is NULL, then ASSERT().
841 If Length > 0 and SecondString is NULL, then ASSERT().
842 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
843 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
845 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than
846 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
849 @param FirstString Pointer to a Null-terminated ASCII string.
850 @param SecondString Pointer to a Null-terminated ASCII string.
851 @param Length Maximum number of ASCII characters for compare.
853 @retval ==0 FirstString is identical to SecondString.
854 @retval !=0 FirstString is not identical to SecondString.
860 IN CONST CHAR8
*FirstString
,
861 IN CONST CHAR8
*SecondString
,
867 Concatenates one Null-terminated ASCII string to another Null-terminated
868 ASCII string, and returns the concatenated ASCII string.
870 This function concatenates two Null-terminated ASCII strings. The contents of
871 Null-terminated ASCII string Source are concatenated to the end of Null-
872 terminated ASCII string Destination. The Null-terminated concatenated ASCII
875 If Destination is NULL, then ASSERT().
876 If Source is NULL, then ASSERT().
877 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
878 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
880 If PcdMaximumAsciiStringLength is not zero and Source contains more than
881 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
883 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
884 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
885 ASCII characters, then ASSERT().
887 @param Destination Pointer to a Null-terminated ASCII string.
888 @param Source Pointer to a Null-terminated ASCII string.
896 IN OUT CHAR8
*Destination
,
897 IN CONST CHAR8
*Source
902 Concatenates up to a specified length one Null-terminated ASCII string to
903 the end of another Null-terminated ASCII string, and returns the
904 concatenated ASCII string.
906 This function concatenates two Null-terminated ASCII strings. The contents
907 of Null-terminated ASCII string Source are concatenated to the end of Null-
908 terminated ASCII string Destination, and Destination is returned. At most,
909 Length ASCII characters are concatenated from Source to the end of
910 Destination, and Destination is always Null-terminated. If Length is 0, then
911 Destination is returned unmodified. If Source and Destination overlap, then
912 the results are undefined.
914 If Length > 0 and Destination is NULL, then ASSERT().
915 If Length > 0 and Source is NULL, then ASSERT().
916 If Source and Destination overlap, then ASSERT().
917 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
918 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
920 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
921 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
923 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
924 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
925 ASCII characters not including the Null-terminator, then ASSERT().
927 @param Destination Pointer to a Null-terminated ASCII string.
928 @param Source Pointer to a Null-terminated ASCII string.
929 @param Length Maximum number of ASCII characters to concatenate from
938 IN OUT CHAR8
*Destination
,
939 IN CONST CHAR8
*Source
,
945 Returns the first occurrence of a Null-terminated ASCII sub-string
946 in a Null-terminated ASCII string.
948 This function scans the contents of the ASCII string specified by String
949 and returns the first occurrence of SearchString. If SearchString is not
950 found in String, then NULL is returned. If the length of SearchString is zero,
951 then String is returned.
953 If String is NULL, then ASSERT().
954 If SearchString is NULL, then ASSERT().
956 If PcdMaximumAsciiStringLength is not zero, and SearchString or
957 String contains more than PcdMaximumAsciiStringLength Unicode characters
958 not including the Null-terminator, then ASSERT().
960 @param String Pointer to a Null-terminated ASCII string.
961 @param SearchString Pointer to a Null-terminated ASCII string to search for.
963 @retval NULL If the SearchString does not appear in String.
964 @retval others If there is a match return the first occurrence of SearchingString.
965 If the length of SearchString is zero,return String.
971 IN CONST CHAR8
*String
,
972 IN CONST CHAR8
*SearchString
977 Convert a Null-terminated ASCII decimal string to a value of type
980 This function returns a value of type UINTN by interpreting the contents
981 of the ASCII string String as a decimal number. The format of the input
982 ASCII string String is:
984 [spaces] [decimal digits].
986 The valid decimal digit character is in the range [0-9]. The function will
987 ignore the pad space, which includes spaces or tab characters, before the digits.
988 The running zero in the beginning of [decimal digits] will be ignored. Then, the
989 function stops at the first character that is a not a valid decimal character or
990 Null-terminator, whichever on comes first.
992 If String has only pad spaces, then 0 is returned.
993 If String has no pad spaces or valid decimal digits, then 0 is returned.
994 If the number represented by String overflows according to the range defined by
995 UINTN, then ASSERT().
996 If String is NULL, then ASSERT().
997 If PcdMaximumAsciiStringLength is not zero, and String contains more than
998 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1001 @param String Pointer to a Null-terminated ASCII string.
1003 @retval Value translated from String.
1008 AsciiStrDecimalToUintn (
1009 IN CONST CHAR8
*String
1014 Convert a Null-terminated ASCII decimal string to a value of type
1017 This function returns a value of type UINT64 by interpreting the contents
1018 of the ASCII string String as a decimal number. The format of the input
1019 ASCII string String is:
1021 [spaces] [decimal digits].
1023 The valid decimal digit character is in the range [0-9]. The function will
1024 ignore the pad space, which includes spaces or tab characters, before the digits.
1025 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1026 function stops at the first character that is a not a valid decimal character or
1027 Null-terminator, whichever on comes first.
1029 If String has only pad spaces, then 0 is returned.
1030 If String has no pad spaces or valid decimal digits, then 0 is returned.
1031 If the number represented by String overflows according to the range defined by
1032 UINT64, then ASSERT().
1033 If String is NULL, then ASSERT().
1034 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1035 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1038 @param String Pointer to a Null-terminated ASCII string.
1040 @retval Value translated from String.
1045 AsciiStrDecimalToUint64 (
1046 IN CONST CHAR8
*String
1051 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1053 This function returns a value of type UINTN by interpreting the contents of
1054 the ASCII string String as a hexadecimal number. The format of the input ASCII
1057 [spaces][zeros][x][hexadecimal digits].
1059 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1060 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1061 appears in the input string, it must be prefixed with at least one 0. The function
1062 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1063 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1064 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1065 digit. Then, the function stops at the first character that is a not a valid
1066 hexadecimal character or Null-terminator, whichever on comes first.
1068 If String has only pad spaces, then 0 is returned.
1069 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1072 If the number represented by String overflows according to the range defined by UINTN,
1074 If String is NULL, then ASSERT().
1075 If PcdMaximumAsciiStringLength is not zero,
1076 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1077 the Null-terminator, then ASSERT().
1079 @param String Pointer to a Null-terminated ASCII string.
1081 @retval Value translated from String.
1086 AsciiStrHexToUintn (
1087 IN CONST CHAR8
*String
1092 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1094 This function returns a value of type UINT64 by interpreting the contents of
1095 the ASCII string String as a hexadecimal number. The format of the input ASCII
1098 [spaces][zeros][x][hexadecimal digits].
1100 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1101 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1102 appears in the input string, it must be prefixed with at least one 0. The function
1103 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1104 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1105 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1106 digit. Then, the function stops at the first character that is a not a valid
1107 hexadecimal character or Null-terminator, whichever on comes first.
1109 If String has only pad spaces, then 0 is returned.
1110 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1113 If the number represented by String overflows according to the range defined by UINT64,
1115 If String is NULL, then ASSERT().
1116 If PcdMaximumAsciiStringLength is not zero,
1117 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1118 the Null-terminator, then ASSERT().
1120 @param String Pointer to a Null-terminated ASCII string.
1122 @retval Value translated from String.
1127 AsciiStrHexToUint64 (
1128 IN CONST CHAR8
*String
1133 Convert one Null-terminated ASCII string to a Null-terminated
1134 Unicode string and returns the Unicode string.
1136 This function converts the contents of the ASCII string Source to the Unicode
1137 string Destination, and returns Destination. The function terminates the
1138 Unicode string Destination by appending a Null-terminator character at the end.
1139 The caller is responsible to make sure Destination points to a buffer with size
1140 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1142 If Destination is NULL, then ASSERT().
1143 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1144 If Source is NULL, then ASSERT().
1145 If Source and Destination overlap, then ASSERT().
1146 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1147 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1149 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1150 PcdMaximumUnicodeStringLength ASCII characters not including the
1151 Null-terminator, then ASSERT().
1153 @param Source Pointer to a Null-terminated ASCII string.
1154 @param Destination Pointer to a Null-terminated Unicode string.
1156 @return Destination.
1161 AsciiStrToUnicodeStr (
1162 IN CONST CHAR8
*Source
,
1163 OUT CHAR16
*Destination
1168 Converts an 8-bit value to an 8-bit BCD value.
1170 Converts the 8-bit value specified by Value to BCD. The BCD value is
1173 If Value >= 100, then ASSERT().
1175 @param Value The 8-bit value to convert to BCD. Range 0..99.
1177 @return The BCD value.
1188 Converts an 8-bit BCD value to an 8-bit value.
1190 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
1193 If Value >= 0xA0, then ASSERT().
1194 If (Value & 0x0F) >= 0x0A, then ASSERT().
1196 @param Value The 8-bit BCD value to convert to an 8-bit value.
1198 @return The 8-bit value is returned.
1209 // Linked List Functions and Macros
1213 Initializes the head node of a doubly linked list that is declared as a
1214 global variable in a module.
1216 Initializes the forward and backward links of a new linked list. After
1217 initializing a linked list with this macro, the other linked list functions
1218 may be used to add and remove nodes from the linked list. This macro results
1219 in smaller executables by initializing the linked list in the data section,
1220 instead if calling the InitializeListHead() function to perform the
1221 equivalent operation.
1223 @param ListHead The head note of a list to initiailize.
1226 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&(ListHead), &(ListHead)}
1230 Initializes the head node of a doubly linked list, and returns the pointer to
1231 the head node of the doubly linked list.
1233 Initializes the forward and backward links of a new linked list. After
1234 initializing a linked list with this function, the other linked list
1235 functions may be used to add and remove nodes from the linked list. It is up
1236 to the caller of this function to allocate the memory for ListHead.
1238 If ListHead is NULL, then ASSERT().
1240 @param ListHead A pointer to the head node of a new doubly linked list.
1247 InitializeListHead (
1248 IN OUT LIST_ENTRY
*ListHead
1253 Adds a node to the beginning of a doubly linked list, and returns the pointer
1254 to the head node of the doubly linked list.
1256 Adds the node Entry at the beginning of the doubly linked list denoted by
1257 ListHead, and returns ListHead.
1259 If ListHead is NULL, then ASSERT().
1260 If Entry is NULL, then ASSERT().
1261 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
1262 InitializeListHead(), then ASSERT().
1263 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1264 of nodes in ListHead, including the ListHead node, is greater than or
1265 equal to PcdMaximumLinkedListLength, then ASSERT().
1267 @param ListHead A pointer to the head node of a doubly linked list.
1268 @param Entry A pointer to a node that is to be inserted at the beginning
1269 of a doubly linked list.
1277 IN OUT LIST_ENTRY
*ListHead
,
1278 IN OUT LIST_ENTRY
*Entry
1283 Adds a node to the end of a doubly linked list, and returns the pointer to
1284 the head node of the doubly linked list.
1286 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
1287 and returns ListHead.
1289 If ListHead is NULL, then ASSERT().
1290 If Entry is NULL, then ASSERT().
1291 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
1292 InitializeListHead(), then ASSERT().
1293 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1294 of nodes in ListHead, including the ListHead node, is greater than or
1295 equal to PcdMaximumLinkedListLength, then ASSERT().
1297 @param ListHead A pointer to the head node of a doubly linked list.
1298 @param Entry A pointer to a node that is to be added at the end of the
1307 IN OUT LIST_ENTRY
*ListHead
,
1308 IN OUT LIST_ENTRY
*Entry
1313 Retrieves the first node of a doubly linked list.
1315 Returns the first node of a doubly linked list. List must have been
1316 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
1317 If List is empty, then List is returned.
1319 If List is NULL, then ASSERT().
1320 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
1321 InitializeListHead(), then ASSERT().
1322 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1323 in List, including the List node, is greater than or equal to
1324 PcdMaximumLinkedListLength, then ASSERT().
1326 @param List A pointer to the head node of a doubly linked list.
1328 @return The first node of a doubly linked list.
1329 @retval NULL The list is empty.
1335 IN CONST LIST_ENTRY
*List
1340 Retrieves the next node of a doubly linked list.
1342 Returns the node of a doubly linked list that follows Node.
1343 List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()
1344 or InitializeListHead(). If List is empty, then List is returned.
1346 If List is NULL, then ASSERT().
1347 If Node is NULL, then ASSERT().
1348 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
1349 InitializeListHead(), then ASSERT().
1350 If PcdMaximumLinkedListLenth is not zero, and List contains more than
1351 PcdMaximumLinkedListLenth nodes, then ASSERT().
1352 If Node is not a node in List, then ASSERT().
1354 @param List A pointer to the head node of a doubly linked list.
1355 @param Node A pointer to a node in the doubly linked list.
1357 @return Pointer to the next node if one exists. Otherwise a null value which
1358 is actually List is returned.
1364 IN CONST LIST_ENTRY
*List
,
1365 IN CONST LIST_ENTRY
*Node
1370 Checks to see if a doubly linked list is empty or not.
1372 Checks to see if the doubly linked list is empty. If the linked list contains
1373 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
1375 If ListHead is NULL, then ASSERT().
1376 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
1377 InitializeListHead(), then ASSERT().
1378 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1379 in List, including the List node, is greater than or equal to
1380 PcdMaximumLinkedListLength, then ASSERT().
1382 @param ListHead A pointer to the head node of a doubly linked list.
1384 @retval TRUE The linked list is empty.
1385 @retval FALSE The linked list is not empty.
1391 IN CONST LIST_ENTRY
*ListHead
1396 Determines if a node in a doubly linked list is the head node of a the same
1397 doubly linked list. This function is typically used to terminate a loop that
1398 traverses all the nodes in a doubly linked list starting with the head node.
1400 Returns TRUE if Node is equal to List. Returns FALSE if Node is one of the
1401 nodes in the doubly linked list specified by List. List must have been
1402 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
1404 If List is NULL, then ASSERT().
1405 If Node is NULL, then ASSERT().
1406 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(),
1408 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1409 in List, including the List node, is greater than or equal to
1410 PcdMaximumLinkedListLength, then ASSERT().
1411 If Node is not a node in List and Node is not equal to List, then ASSERT().
1413 @param List A pointer to the head node of a doubly linked list.
1414 @param Node A pointer to a node in the doubly linked list.
1416 @retval TRUE Node is one of the nodes in the doubly linked list.
1417 @retval FALSE Node is not one of the nodes in the doubly linked list.
1423 IN CONST LIST_ENTRY
*List
,
1424 IN CONST LIST_ENTRY
*Node
1429 Determines if a node the last node in a doubly linked list.
1431 Returns TRUE if Node is the last node in the doubly linked list specified by
1432 List. Otherwise, FALSE is returned. List must have been initialized with
1433 INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
1435 If List is NULL, then ASSERT().
1436 If Node is NULL, then ASSERT().
1437 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
1438 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().
1442 If Node is not a node in List, then ASSERT().
1444 @param List A pointer to the head node of a doubly linked list.
1445 @param Node A pointer to a node in the doubly linked list.
1447 @retval TRUE Node is the last node in the linked list.
1448 @retval FALSE Node is not the last node in the linked list.
1454 IN CONST LIST_ENTRY
*List
,
1455 IN CONST LIST_ENTRY
*Node
1460 Swaps the location of two nodes in a doubly linked list, and returns the
1461 first node after the swap.
1463 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
1464 Otherwise, the location of the FirstEntry node is swapped with the location
1465 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
1466 same double linked list as FirstEntry and that double linked list must have
1467 been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
1468 SecondEntry is returned after the nodes are swapped.
1470 If FirstEntry is NULL, then ASSERT().
1471 If SecondEntry is NULL, then ASSERT().
1472 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
1473 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1474 linked list containing the FirstEntry and SecondEntry nodes, including
1475 the FirstEntry and SecondEntry nodes, is greater than or equal to
1476 PcdMaximumLinkedListLength, then ASSERT().
1478 @param FirstEntry A pointer to a node in a linked list.
1479 @param SecondEntry A pointer to another node in the same linked list.
1481 @return SecondEntry.
1487 IN OUT LIST_ENTRY
*FirstEntry
,
1488 IN OUT LIST_ENTRY
*SecondEntry
1493 Removes a node from a doubly linked list, and returns the node that follows
1496 Removes the node Entry from a doubly linked list. It is up to the caller of
1497 this function to release the memory used by this node if that is required. On
1498 exit, the node following Entry in the doubly linked list is returned. If
1499 Entry is the only node in the linked list, then the head node of the linked
1502 If Entry is NULL, then ASSERT().
1503 If Entry is the head node of an empty list, then ASSERT().
1504 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1505 linked list containing Entry, including the Entry node, is greater than
1506 or equal to PcdMaximumLinkedListLength, then ASSERT().
1508 @param Entry A pointer to a node in a linked list.
1516 IN CONST LIST_ENTRY
*Entry
1524 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
1525 with zeros. The shifted value is returned.
1527 This function shifts the 64-bit value Operand to the left by Count bits. The
1528 low Count bits are set to zero. The shifted value is returned.
1530 If Count is greater than 63, then ASSERT().
1532 @param Operand The 64-bit operand to shift left.
1533 @param Count The number of bits to shift left.
1535 @return Operand << Count.
1547 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1548 filled with zeros. The shifted value is returned.
1550 This function shifts the 64-bit value Operand to the right by Count bits. The
1551 high Count bits are set to zero. The shifted value is returned.
1553 If Count is greater than 63, then ASSERT().
1555 @param Operand The 64-bit operand to shift right.
1556 @param Count The number of bits to shift right.
1558 @return Operand >> Count
1570 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1571 with original integer's bit 63. The shifted value is returned.
1573 This function shifts the 64-bit value Operand to the right by Count bits. The
1574 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1576 If Count is greater than 63, then ASSERT().
1578 @param Operand The 64-bit operand to shift right.
1579 @param Count The number of bits to shift right.
1581 @return Operand >> Count
1593 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1594 with the high bits that were rotated.
1596 This function rotates the 32-bit value Operand to the left by Count bits. The
1597 low Count bits are fill with the high Count bits of Operand. The rotated
1600 If Count is greater than 31, then ASSERT().
1602 @param Operand The 32-bit operand to rotate left.
1603 @param Count The number of bits to rotate left.
1605 @return Operand << Count
1617 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1618 with the low bits that were rotated.
1620 This function rotates the 32-bit value Operand to the right by Count bits.
1621 The high Count bits are fill with the low Count bits of Operand. The rotated
1624 If Count is greater than 31, then ASSERT().
1626 @param Operand The 32-bit operand to rotate right.
1627 @param Count The number of bits to rotate right.
1629 @return Operand >>> Count
1641 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1642 with the high bits that were rotated.
1644 This function rotates the 64-bit value Operand to the left by Count bits. The
1645 low Count bits are fill with the high Count bits of Operand. The rotated
1648 If Count is greater than 63, then ASSERT().
1650 @param Operand The 64-bit operand to rotate left.
1651 @param Count The number of bits to rotate left.
1653 @return Operand << Count
1665 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1666 with the high low bits that were rotated.
1668 This function rotates the 64-bit value Operand to the right by Count bits.
1669 The high Count bits are fill with the low Count bits of Operand. The rotated
1672 If Count is greater than 63, then ASSERT().
1674 @param Operand The 64-bit operand to rotate right.
1675 @param Count The number of bits to rotate right.
1677 @return Operand >> Count
1689 Returns the bit position of the lowest bit set in a 32-bit value.
1691 This function computes the bit position of the lowest bit set in the 32-bit
1692 value specified by Operand. If Operand is zero, then -1 is returned.
1693 Otherwise, a value between 0 and 31 is returned.
1695 @param Operand The 32-bit operand to evaluate.
1697 @retval 0..31 The lowest bit set in Operand was found.
1698 @retval -1 Operand is zero.
1709 Returns the bit position of the lowest bit set in a 64-bit value.
1711 This function computes the bit position of the lowest bit set in the 64-bit
1712 value specified by Operand. If Operand is zero, then -1 is returned.
1713 Otherwise, a value between 0 and 63 is returned.
1715 @param Operand The 64-bit operand to evaluate.
1717 @retval 0..63 The lowest bit set in Operand was found.
1718 @retval -1 Operand is zero.
1730 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1733 This function computes the bit position of the highest bit set in the 32-bit
1734 value specified by Operand. If Operand is zero, then -1 is returned.
1735 Otherwise, a value between 0 and 31 is returned.
1737 @param Operand The 32-bit operand to evaluate.
1739 @retval 0..31 Position of the highest bit set in Operand if found.
1740 @retval -1 Operand is zero.
1751 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1754 This function computes the bit position of the highest bit set in the 64-bit
1755 value specified by Operand. If Operand is zero, then -1 is returned.
1756 Otherwise, a value between 0 and 63 is returned.
1758 @param Operand The 64-bit operand to evaluate.
1760 @retval 0..63 Position of the highest bit set in Operand if found.
1761 @retval -1 Operand is zero.
1772 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1775 This function computes the value of the highest bit set in the 32-bit value
1776 specified by Operand. If Operand is zero, then zero is returned.
1778 @param Operand The 32-bit operand to evaluate.
1780 @return 1 << HighBitSet32(Operand)
1781 @retval 0 Operand is zero.
1792 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1795 This function computes the value of the highest bit set in the 64-bit value
1796 specified by Operand. If Operand is zero, then zero is returned.
1798 @param Operand The 64-bit operand to evaluate.
1800 @return 1 << HighBitSet64(Operand)
1801 @retval 0 Operand is zero.
1812 Switches the endianess of a 16-bit integer.
1814 This function swaps the bytes in a 16-bit unsigned value to switch the value
1815 from little endian to big endian or vice versa. The byte swapped value is
1818 @param Value Operand A 16-bit unsigned value.
1820 @return The byte swapped Operand.
1831 Switches the endianess of a 32-bit integer.
1833 This function swaps the bytes in a 32-bit unsigned value to switch the value
1834 from little endian to big endian or vice versa. The byte swapped value is
1837 @param Value Operand A 32-bit unsigned value.
1839 @return The byte swapped Operand.
1850 Switches the endianess of a 64-bit integer.
1852 This function swaps the bytes in a 64-bit unsigned value to switch the value
1853 from little endian to big endian or vice versa. The byte swapped value is
1856 @param Value Operand A 64-bit unsigned value.
1858 @return The byte swapped Operand.
1869 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1870 generates a 64-bit unsigned result.
1872 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1873 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1874 bit unsigned result is returned.
1876 @param Multiplicand A 64-bit unsigned value.
1877 @param Multiplier A 32-bit unsigned value.
1879 @return Multiplicand * Multiplier
1885 IN UINT64 Multiplicand
,
1886 IN UINT32 Multiplier
1891 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1892 generates a 64-bit unsigned result.
1894 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1895 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1896 bit unsigned result is returned.
1898 If the result overflows, then ASSERT().
1900 @param Multiplicand A 64-bit unsigned value.
1901 @param Multiplier A 64-bit unsigned value.
1903 @return Multiplicand * Multiplier
1909 IN UINT64 Multiplicand
,
1910 IN UINT64 Multiplier
1915 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1916 64-bit signed result.
1918 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1919 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1920 signed result is returned.
1922 @param Multiplicand A 64-bit signed value.
1923 @param Multiplier A 64-bit signed value.
1925 @return Multiplicand * Multiplier
1931 IN INT64 Multiplicand
,
1937 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1938 a 64-bit unsigned result.
1940 This function divides the 64-bit unsigned value Dividend by the 32-bit
1941 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1942 function returns the 64-bit unsigned quotient.
1944 If Divisor is 0, then ASSERT().
1946 @param Dividend A 64-bit unsigned value.
1947 @param Divisor A 32-bit unsigned value.
1949 @return Dividend / Divisor
1961 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1962 a 32-bit unsigned remainder.
1964 This function divides the 64-bit unsigned value Dividend by the 32-bit
1965 unsigned value Divisor and generates a 32-bit remainder. This function
1966 returns the 32-bit unsigned remainder.
1968 If Divisor is 0, then ASSERT().
1970 @param Dividend A 64-bit unsigned value.
1971 @param Divisor A 32-bit unsigned value.
1973 @return Dividend % Divisor
1985 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1986 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1988 This function divides the 64-bit unsigned value Dividend by the 32-bit
1989 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1990 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1991 This function returns the 64-bit unsigned quotient.
1993 If Divisor is 0, then ASSERT().
1995 @param Dividend A 64-bit unsigned value.
1996 @param Divisor A 32-bit unsigned value.
1997 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1998 optional and may be NULL.
2000 @return Dividend / Divisor
2005 DivU64x32Remainder (
2008 OUT UINT32
*Remainder OPTIONAL
2013 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
2014 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
2016 This function divides the 64-bit unsigned value Dividend by the 64-bit
2017 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2018 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
2019 This function returns the 64-bit unsigned quotient.
2021 If Divisor is 0, then ASSERT().
2023 @param Dividend A 64-bit unsigned value.
2024 @param Divisor A 64-bit unsigned value.
2025 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
2026 optional and may be NULL.
2028 @return Dividend / Divisor
2033 DivU64x64Remainder (
2036 OUT UINT64
*Remainder OPTIONAL
2041 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
2042 64-bit signed result and a optional 64-bit signed remainder.
2044 This function divides the 64-bit signed value Dividend by the 64-bit signed
2045 value Divisor and generates a 64-bit signed quotient. If Remainder is not
2046 NULL, then the 64-bit signed remainder is returned in Remainder. This
2047 function returns the 64-bit signed quotient.
2049 It is the caller's responsibility to not call this function with a Divisor of 0.
2050 If Divisor is 0, then the quotient and remainder should be assumed to be
2051 the largest negative integer.
2053 If Divisor is 0, then ASSERT().
2055 @param Dividend A 64-bit signed value.
2056 @param Divisor A 64-bit signed value.
2057 @param Remainder A pointer to a 64-bit signed value. This parameter is
2058 optional and may be NULL.
2060 @return Dividend / Divisor
2065 DivS64x64Remainder (
2068 OUT INT64
*Remainder OPTIONAL
2073 Reads a 16-bit value from memory that may be unaligned.
2075 This function returns the 16-bit value pointed to by Buffer. The function
2076 guarantees that the read operation does not produce an alignment fault.
2078 If the Buffer is NULL, then ASSERT().
2080 @param Buffer Pointer to a 16-bit value that may be unaligned.
2082 @return The 16-bit value read from Buffer.
2088 IN CONST UINT16
*Buffer
2093 Writes a 16-bit value to memory that may be unaligned.
2095 This function writes the 16-bit value specified by Value to Buffer. Value is
2096 returned. The function guarantees that the write operation does not produce
2099 If the Buffer is NULL, then ASSERT().
2101 @param Buffer Pointer to a 16-bit value that may be unaligned.
2102 @param Value 16-bit value to write to Buffer.
2104 @return The 16-bit value to write to Buffer.
2116 Reads a 24-bit value from memory that may be unaligned.
2118 This function returns the 24-bit value pointed to by Buffer. The function
2119 guarantees that the read operation does not produce an alignment fault.
2121 If the Buffer is NULL, then ASSERT().
2123 @param Buffer Pointer to a 24-bit value that may be unaligned.
2125 @return The 24-bit value read from Buffer.
2131 IN CONST UINT32
*Buffer
2136 Writes a 24-bit value to memory that may be unaligned.
2138 This function writes the 24-bit value specified by Value to Buffer. Value is
2139 returned. The function guarantees that the write operation does not produce
2142 If the Buffer is NULL, then ASSERT().
2144 @param Buffer Pointer to a 24-bit value that may be unaligned.
2145 @param Value 24-bit value to write to Buffer.
2147 @return The 24-bit value to write to Buffer.
2159 Reads a 32-bit value from memory that may be unaligned.
2161 This function returns the 32-bit value pointed to by Buffer. The function
2162 guarantees that the read operation does not produce an alignment fault.
2164 If the Buffer is NULL, then ASSERT().
2166 @param Buffer Pointer to a 32-bit value that may be unaligned.
2168 @return The 32-bit value read from Buffer.
2174 IN CONST UINT32
*Buffer
2179 Writes a 32-bit value to memory that may be unaligned.
2181 This function writes the 32-bit value specified by Value to Buffer. Value is
2182 returned. The function guarantees that the write operation does not produce
2185 If the Buffer is NULL, then ASSERT().
2187 @param Buffer Pointer to a 32-bit value that may be unaligned.
2188 @param Value 32-bit value to write to Buffer.
2190 @return The 32-bit value to write to Buffer.
2202 Reads a 64-bit value from memory that may be unaligned.
2204 This function returns the 64-bit value pointed to by Buffer. The function
2205 guarantees that the read operation does not produce an alignment fault.
2207 If the Buffer is NULL, then ASSERT().
2209 @param Buffer Pointer to a 64-bit value that may be unaligned.
2211 @return The 64-bit value read from Buffer.
2217 IN CONST UINT64
*Buffer
2222 Writes a 64-bit value to memory that may be unaligned.
2224 This function writes the 64-bit value specified by Value to Buffer. Value is
2225 returned. The function guarantees that the write operation does not produce
2228 If the Buffer is NULL, then ASSERT().
2230 @param Buffer Pointer to a 64-bit value that may be unaligned.
2231 @param Value 64-bit value to write to Buffer.
2233 @return The 64-bit value to write to Buffer.
2245 // Bit Field Functions
2249 Returns a bit field from an 8-bit value.
2251 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2253 If 8-bit operations are not supported, then ASSERT().
2254 If StartBit is greater than 7, then ASSERT().
2255 If EndBit is greater than 7, then ASSERT().
2256 If EndBit is less than StartBit, then ASSERT().
2258 @param Operand Operand on which to perform the bitfield operation.
2259 @param StartBit The ordinal of the least significant bit in the bit field.
2261 @param EndBit The ordinal of the most significant bit in the bit field.
2264 @return The bit field read.
2277 Writes a bit field to an 8-bit value, and returns the result.
2279 Writes Value to the bit field specified by the StartBit and the EndBit in
2280 Operand. All other bits in Operand are preserved. The new 8-bit value is
2283 If 8-bit operations are not supported, then ASSERT().
2284 If StartBit is greater than 7, then ASSERT().
2285 If EndBit is greater than 7, then ASSERT().
2286 If EndBit is less than StartBit, then ASSERT().
2288 @param Operand Operand on which to perform the bitfield operation.
2289 @param StartBit The ordinal of the least significant bit in the bit field.
2291 @param EndBit The ordinal of the most significant bit in the bit field.
2293 @param Value New value of the bit field.
2295 @return The new 8-bit value.
2309 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
2312 Performs a bitwise OR between the bit field specified by StartBit
2313 and EndBit in Operand and the value specified by OrData. All other bits in
2314 Operand are preserved. The new 8-bit value is returned.
2316 If 8-bit operations are not supported, then ASSERT().
2317 If StartBit is greater than 7, then ASSERT().
2318 If EndBit is greater than 7, then ASSERT().
2319 If EndBit is less than StartBit, then ASSERT().
2321 @param Operand Operand on which to perform the bitfield operation.
2322 @param StartBit The ordinal of the least significant bit in the bit field.
2324 @param EndBit The ordinal of the most significant bit in the bit field.
2326 @param OrData The value to OR with the read value from the value
2328 @return The new 8-bit value.
2342 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
2345 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2346 in Operand and the value specified by AndData. All other bits in Operand are
2347 preserved. The new 8-bit value is returned.
2349 If 8-bit operations are not supported, then ASSERT().
2350 If StartBit is greater than 7, then ASSERT().
2351 If EndBit is greater than 7, then ASSERT().
2352 If EndBit is less than StartBit, then ASSERT().
2354 @param Operand Operand on which to perform the bitfield operation.
2355 @param StartBit The ordinal of the least significant bit in the bit field.
2357 @param EndBit The ordinal of the most significant bit in the bit field.
2359 @param AndData The value to AND with the read value from the value.
2361 @return The new 8-bit value.
2375 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
2376 bitwise OR, and returns the result.
2378 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2379 in Operand and the value specified by AndData, followed by a bitwise
2380 OR with value specified by OrData. All other bits in Operand are
2381 preserved. The new 8-bit value is returned.
2383 If 8-bit operations are not supported, then ASSERT().
2384 If StartBit is greater than 7, then ASSERT().
2385 If EndBit is greater than 7, then ASSERT().
2386 If EndBit is less than StartBit, then ASSERT().
2388 @param Operand Operand on which to perform the bitfield operation.
2389 @param StartBit The ordinal of the least significant bit in the bit field.
2391 @param EndBit The ordinal of the most significant bit in the bit field.
2393 @param AndData The value to AND with the read value from the value.
2394 @param OrData The value to OR with the result of the AND operation.
2396 @return The new 8-bit value.
2401 BitFieldAndThenOr8 (
2411 Returns a bit field from a 16-bit value.
2413 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2415 If 16-bit operations are not supported, then ASSERT().
2416 If StartBit is greater than 15, then ASSERT().
2417 If EndBit is greater than 15, then ASSERT().
2418 If EndBit is less than StartBit, then ASSERT().
2420 @param Operand Operand on which to perform the bitfield operation.
2421 @param StartBit The ordinal of the least significant bit in the bit field.
2423 @param EndBit The ordinal of the most significant bit in the bit field.
2426 @return The bit field read.
2439 Writes a bit field to a 16-bit value, and returns the result.
2441 Writes Value to the bit field specified by the StartBit and the EndBit in
2442 Operand. All other bits in Operand are preserved. The new 16-bit value is
2445 If 16-bit operations are not supported, then ASSERT().
2446 If StartBit is greater than 15, then ASSERT().
2447 If EndBit is greater than 15, then ASSERT().
2448 If EndBit is less than StartBit, then ASSERT().
2450 @param Operand Operand on which to perform the bitfield operation.
2451 @param StartBit The ordinal of the least significant bit in the bit field.
2453 @param EndBit The ordinal of the most significant bit in the bit field.
2455 @param Value New value of the bit field.
2457 @return The new 16-bit value.
2471 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
2474 Performs a bitwise OR between the bit field specified by StartBit
2475 and EndBit in Operand and the value specified by OrData. All other bits in
2476 Operand are preserved. The new 16-bit value is returned.
2478 If 16-bit operations are not supported, then ASSERT().
2479 If StartBit is greater than 15, then ASSERT().
2480 If EndBit is greater than 15, then ASSERT().
2481 If EndBit is less than StartBit, then ASSERT().
2483 @param Operand Operand on which to perform the bitfield operation.
2484 @param StartBit The ordinal of the least significant bit in the bit field.
2486 @param EndBit The ordinal of the most significant bit in the bit field.
2488 @param OrData The value to OR with the read value from the value
2490 @return The new 16-bit value.
2504 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
2507 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2508 in Operand and the value specified by AndData. All other bits in Operand are
2509 preserved. The new 16-bit value is returned.
2511 If 16-bit operations are not supported, then ASSERT().
2512 If StartBit is greater than 15, then ASSERT().
2513 If EndBit is greater than 15, then ASSERT().
2514 If EndBit is less than StartBit, then ASSERT().
2516 @param Operand Operand on which to perform the bitfield operation.
2517 @param StartBit The ordinal of the least significant bit in the bit field.
2519 @param EndBit The ordinal of the most significant bit in the bit field.
2521 @param AndData The value to AND with the read value from the value
2523 @return The new 16-bit value.
2537 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
2538 bitwise OR, and returns the result.
2540 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2541 in Operand and the value specified by AndData, followed by a bitwise
2542 OR with value specified by OrData. All other bits in Operand are
2543 preserved. The new 16-bit value is returned.
2545 If 16-bit operations are not supported, then ASSERT().
2546 If StartBit is greater than 15, then ASSERT().
2547 If EndBit is greater than 15, then ASSERT().
2548 If EndBit is less than StartBit, then ASSERT().
2550 @param Operand Operand on which to perform the bitfield operation.
2551 @param StartBit The ordinal of the least significant bit in the bit field.
2553 @param EndBit The ordinal of the most significant bit in the bit field.
2555 @param AndData The value to AND with the read value from the value.
2556 @param OrData The value to OR with the result of the AND operation.
2558 @return The new 16-bit value.
2563 BitFieldAndThenOr16 (
2573 Returns a bit field from a 32-bit value.
2575 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2577 If 32-bit operations are not supported, then ASSERT().
2578 If StartBit is greater than 31, then ASSERT().
2579 If EndBit is greater than 31, then ASSERT().
2580 If EndBit is less than StartBit, then ASSERT().
2582 @param Operand Operand on which to perform the bitfield operation.
2583 @param StartBit The ordinal of the least significant bit in the bit field.
2585 @param EndBit The ordinal of the most significant bit in the bit field.
2588 @return The bit field read.
2601 Writes a bit field to a 32-bit value, and returns the result.
2603 Writes Value to the bit field specified by the StartBit and the EndBit in
2604 Operand. All other bits in Operand are preserved. The new 32-bit value is
2607 If 32-bit operations are not supported, then ASSERT().
2608 If StartBit is greater than 31, then ASSERT().
2609 If EndBit is greater than 31, then ASSERT().
2610 If EndBit is less than StartBit, then ASSERT().
2612 @param Operand Operand on which to perform the bitfield operation.
2613 @param StartBit The ordinal of the least significant bit in the bit field.
2615 @param EndBit The ordinal of the most significant bit in the bit field.
2617 @param Value New value of the bit field.
2619 @return The new 32-bit value.
2633 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2636 Performs a bitwise OR between the bit field specified by StartBit
2637 and EndBit in Operand and the value specified by OrData. All other bits in
2638 Operand are preserved. The new 32-bit value is returned.
2640 If 32-bit operations are not supported, then ASSERT().
2641 If StartBit is greater than 31, then ASSERT().
2642 If EndBit is greater than 31, then ASSERT().
2643 If EndBit is less than StartBit, then ASSERT().
2645 @param Operand Operand on which to perform the bitfield operation.
2646 @param StartBit The ordinal of the least significant bit in the bit field.
2648 @param EndBit The ordinal of the most significant bit in the bit field.
2650 @param OrData The value to OR with the read value from the value
2652 @return The new 32-bit value.
2666 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2669 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2670 in Operand and the value specified by AndData. All other bits in Operand are
2671 preserved. The new 32-bit value is returned.
2673 If 32-bit operations are not supported, then ASSERT().
2674 If StartBit is greater than 31, then ASSERT().
2675 If EndBit is greater than 31, then ASSERT().
2676 If EndBit is less than StartBit, then ASSERT().
2678 @param Operand Operand on which to perform the bitfield operation.
2679 @param StartBit The ordinal of the least significant bit in the bit field.
2681 @param EndBit The ordinal of the most significant bit in the bit field.
2683 @param AndData The value to AND with the read value from the value
2685 @return The new 32-bit value.
2699 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2700 bitwise OR, and returns the result.
2702 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2703 in Operand and the value specified by AndData, followed by a bitwise
2704 OR with value specified by OrData. All other bits in Operand are
2705 preserved. The new 32-bit value is returned.
2707 If 32-bit operations are not supported, then ASSERT().
2708 If StartBit is greater than 31, then ASSERT().
2709 If EndBit is greater than 31, then ASSERT().
2710 If EndBit is less than StartBit, then ASSERT().
2712 @param Operand Operand on which to perform the bitfield operation.
2713 @param StartBit The ordinal of the least significant bit in the bit field.
2715 @param EndBit The ordinal of the most significant bit in the bit field.
2717 @param AndData The value to AND with the read value from the value.
2718 @param OrData The value to OR with the result of the AND operation.
2720 @return The new 32-bit value.
2725 BitFieldAndThenOr32 (
2735 Returns a bit field from a 64-bit value.
2737 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2739 If 64-bit operations are not supported, then ASSERT().
2740 If StartBit is greater than 63, then ASSERT().
2741 If EndBit is greater than 63, then ASSERT().
2742 If EndBit is less than StartBit, then ASSERT().
2744 @param Operand Operand on which to perform the bitfield operation.
2745 @param StartBit The ordinal of the least significant bit in the bit field.
2747 @param EndBit The ordinal of the most significant bit in the bit field.
2750 @return The bit field read.
2763 Writes a bit field to a 64-bit value, and returns the result.
2765 Writes Value to the bit field specified by the StartBit and the EndBit in
2766 Operand. All other bits in Operand are preserved. The new 64-bit value is
2769 If 64-bit operations are not supported, then ASSERT().
2770 If StartBit is greater than 63, then ASSERT().
2771 If EndBit is greater than 63, then ASSERT().
2772 If EndBit is less than StartBit, then ASSERT().
2774 @param Operand Operand on which to perform the bitfield operation.
2775 @param StartBit The ordinal of the least significant bit in the bit field.
2777 @param EndBit The ordinal of the most significant bit in the bit field.
2779 @param Value New value of the bit field.
2781 @return The new 64-bit value.
2795 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2798 Performs a bitwise OR between the bit field specified by StartBit
2799 and EndBit in Operand and the value specified by OrData. All other bits in
2800 Operand are preserved. The new 64-bit value is returned.
2802 If 64-bit operations are not supported, then ASSERT().
2803 If StartBit is greater than 63, then ASSERT().
2804 If EndBit is greater than 63, then ASSERT().
2805 If EndBit is less than StartBit, then ASSERT().
2807 @param Operand Operand on which to perform the bitfield operation.
2808 @param StartBit The ordinal of the least significant bit in the bit field.
2810 @param EndBit The ordinal of the most significant bit in the bit field.
2812 @param OrData The value to OR with the read value from the value
2814 @return The new 64-bit value.
2828 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2831 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2832 in Operand and the value specified by AndData. All other bits in Operand are
2833 preserved. The new 64-bit value is returned.
2835 If 64-bit operations are not supported, then ASSERT().
2836 If StartBit is greater than 63, then ASSERT().
2837 If EndBit is greater than 63, then ASSERT().
2838 If EndBit is less than StartBit, then ASSERT().
2840 @param Operand Operand on which to perform the bitfield operation.
2841 @param StartBit The ordinal of the least significant bit in the bit field.
2843 @param EndBit The ordinal of the most significant bit in the bit field.
2845 @param AndData The value to AND with the read value from the value
2847 @return The new 64-bit value.
2861 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2862 bitwise OR, and returns the result.
2864 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2865 in Operand and the value specified by AndData, followed by a bitwise
2866 OR with value specified by OrData. All other bits in Operand are
2867 preserved. The new 64-bit value is returned.
2869 If 64-bit operations are not supported, then ASSERT().
2870 If StartBit is greater than 63, then ASSERT().
2871 If EndBit is greater than 63, then ASSERT().
2872 If EndBit is less than StartBit, then ASSERT().
2874 @param Operand Operand on which to perform the bitfield operation.
2875 @param StartBit The ordinal of the least significant bit in the bit field.
2877 @param EndBit The ordinal of the most significant bit in the bit field.
2879 @param AndData The value to AND with the read value from the value.
2880 @param OrData The value to OR with the result of the AND operation.
2882 @return The new 64-bit value.
2887 BitFieldAndThenOr64 (
2897 // Base Library Synchronization Functions
2901 Retrieves the architecture specific spin lock alignment requirements for
2902 optimal spin lock performance.
2904 This function retrieves the spin lock alignment requirements for optimal
2905 performance on a given CPU architecture. The spin lock alignment must be a
2906 power of two and is returned by this function. If there are no alignment
2907 requirements, then 1 must be returned. The spin lock synchronization
2908 functions must function correctly if the spin lock size and alignment values
2909 returned by this function are not used at all. These values are hints to the
2910 consumers of the spin lock synchronization functions to obtain optimal spin
2913 @return The architecture specific spin lock alignment.
2918 GetSpinLockProperties (
2924 Initializes a spin lock to the released state and returns the spin lock.
2926 This function initializes the spin lock specified by SpinLock to the released
2927 state, and returns SpinLock. Optimal performance can be achieved by calling
2928 GetSpinLockProperties() to determine the size and alignment requirements for
2931 If SpinLock is NULL, then ASSERT().
2933 @param SpinLock A pointer to the spin lock to initialize to the released
2936 @return SpinLock in release state.
2941 InitializeSpinLock (
2942 OUT SPIN_LOCK
*SpinLock
2947 Waits until a spin lock can be placed in the acquired state.
2949 This function checks the state of the spin lock specified by SpinLock. If
2950 SpinLock is in the released state, then this function places SpinLock in the
2951 acquired state and returns SpinLock. Otherwise, this function waits
2952 indefinitely for the spin lock to be released, and then places it in the
2953 acquired state and returns SpinLock. All state transitions of SpinLock must
2954 be performed using MP safe mechanisms.
2956 If SpinLock is NULL, then ASSERT().
2957 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2958 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2959 PcdSpinLockTimeout microseconds, then ASSERT().
2961 @param SpinLock A pointer to the spin lock to place in the acquired state.
2963 @return SpinLock acquired lock.
2969 IN OUT SPIN_LOCK
*SpinLock
2974 Attempts to place a spin lock in the acquired state.
2976 This function checks the state of the spin lock specified by SpinLock. If
2977 SpinLock is in the released state, then this function places SpinLock in the
2978 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2979 transitions of SpinLock must be performed using MP safe mechanisms.
2981 If SpinLock is NULL, then ASSERT().
2982 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2984 @param SpinLock A pointer to the spin lock to place in the acquired state.
2986 @retval TRUE SpinLock was placed in the acquired state.
2987 @retval FALSE SpinLock could not be acquired.
2992 AcquireSpinLockOrFail (
2993 IN OUT SPIN_LOCK
*SpinLock
2998 Releases a spin lock.
3000 This function places the spin lock specified by SpinLock in the release state
3001 and returns SpinLock.
3003 If SpinLock is NULL, then ASSERT().
3004 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3006 @param SpinLock A pointer to the spin lock to release.
3008 @return SpinLock released lock.
3014 IN OUT SPIN_LOCK
*SpinLock
3019 Performs an atomic increment of an 32-bit unsigned integer.
3021 Performs an atomic increment of the 32-bit unsigned integer specified by
3022 Value and returns the incremented value. The increment operation must be
3023 performed using MP safe mechanisms. The state of the return value is not
3024 guaranteed to be MP safe.
3026 If Value is NULL, then ASSERT().
3028 @param Value A pointer to the 32-bit value to increment.
3030 @return The incremented value.
3035 InterlockedIncrement (
3041 Performs an atomic decrement of an 32-bit unsigned integer.
3043 Performs an atomic decrement of the 32-bit unsigned integer specified by
3044 Value and returns the decremented value. The decrement operation must be
3045 performed using MP safe mechanisms. The state of the return value is not
3046 guaranteed to be MP safe.
3048 If Value is NULL, then ASSERT().
3050 @param Value A pointer to the 32-bit value to decrement.
3052 @return The decremented value.
3057 InterlockedDecrement (
3063 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
3065 Performs an atomic compare exchange operation on the 32-bit unsigned integer
3066 specified by Value. If Value is equal to CompareValue, then Value is set to
3067 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
3068 then Value is returned. The compare exchange operation must be performed using
3071 If Value is NULL, then ASSERT().
3073 @param Value A pointer to the 32-bit value for the compare exchange
3075 @param CompareValue 32-bit value used in compare operation.
3076 @param ExchangeValue 32-bit value used in exchange operation.
3078 @return The original *Value before exchange.
3083 InterlockedCompareExchange32 (
3084 IN OUT UINT32
*Value
,
3085 IN UINT32 CompareValue
,
3086 IN UINT32 ExchangeValue
3091 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
3093 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
3094 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
3095 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
3096 The compare exchange operation must be performed using MP safe mechanisms.
3098 If Value is NULL, then ASSERT().
3100 @param Value A pointer to the 64-bit value for the compare exchange
3102 @param CompareValue 64-bit value used in compare operation.
3103 @param ExchangeValue 64-bit value used in exchange operation.
3105 @return The original *Value before exchange.
3110 InterlockedCompareExchange64 (
3111 IN OUT UINT64
*Value
,
3112 IN UINT64 CompareValue
,
3113 IN UINT64 ExchangeValue
3118 Performs an atomic compare exchange operation on a pointer value.
3120 Performs an atomic compare exchange operation on the pointer value specified
3121 by Value. If Value is equal to CompareValue, then Value is set to
3122 ExchangeValue and CompareValue is returned. If Value is not equal to
3123 CompareValue, then Value is returned. The compare exchange operation must be
3124 performed using MP safe mechanisms.
3126 If Value is NULL, then ASSERT().
3128 @param Value A pointer to the pointer value for the compare exchange
3130 @param CompareValue Pointer value used in compare operation.
3131 @param ExchangeValue Pointer value used in exchange operation.
3133 @return The original *Value before exchange.
3137 InterlockedCompareExchangePointer (
3138 IN OUT VOID
**Value
,
3139 IN VOID
*CompareValue
,
3140 IN VOID
*ExchangeValue
3145 // Base Library Checksum Functions
3149 Returns the sum of all elements in a buffer in unit of UINT8.
3150 During calculation, the carry bits are dropped.
3152 This function calculates the sum of all elements in a buffer
3153 in unit of UINT8. The carry bits in result of addition are dropped.
3154 The result is returned as UINT8. If Length is Zero, then Zero is
3157 If Buffer is NULL, then ASSERT().
3158 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3160 @param Buffer Pointer to the buffer to carry out the sum operation.
3161 @param Length The size, in bytes, of Buffer.
3163 @return Sum The sum of Buffer with carry bits dropped during additions.
3169 IN CONST UINT8
*Buffer
,
3175 Returns the two's complement checksum of all elements in a buffer
3178 This function first calculates the sum of the 8-bit values in the
3179 buffer specified by Buffer and Length. The carry bits in the result
3180 of addition are dropped. Then, the two's complement of the sum is
3181 returned. If Length is 0, then 0 is returned.
3183 If Buffer is NULL, then ASSERT().
3184 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3186 @param Buffer Pointer to the buffer to carry out the checksum operation.
3187 @param Length The size, in bytes, of Buffer.
3189 @return Checksum The 2's complement checksum of Buffer.
3194 CalculateCheckSum8 (
3195 IN CONST UINT8
*Buffer
,
3201 Returns the sum of all elements in a buffer of 16-bit values. During
3202 calculation, the carry bits are dropped.
3204 This function calculates the sum of the 16-bit values in the buffer
3205 specified by Buffer and Length. The carry bits in result of addition are dropped.
3206 The 16-bit result is returned. If Length is 0, then 0 is returned.
3208 If Buffer is NULL, then ASSERT().
3209 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3210 If Length is not aligned on a 16-bit boundary, 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 UINT16
*Buffer
,
3228 Returns the two's complement checksum of all elements in a buffer of
3231 This function first calculates the sum of the 16-bit values in the buffer
3232 specified by Buffer and Length. The carry bits in the result of addition
3233 are dropped. Then, the two's complement of the sum is returned. If Length
3234 is 0, then 0 is returned.
3236 If Buffer is NULL, then ASSERT().
3237 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3238 If Length is not aligned on a 16-bit boundary, then ASSERT().
3239 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3241 @param Buffer Pointer to the buffer to carry out the checksum operation.
3242 @param Length The size, in bytes, of Buffer.
3244 @return Checksum The 2's complement checksum of Buffer.
3249 CalculateCheckSum16 (
3250 IN CONST UINT16
*Buffer
,
3256 Returns the sum of all elements in a buffer of 32-bit values. During
3257 calculation, the carry bits are dropped.
3259 This function calculates the sum of the 32-bit values in the buffer
3260 specified by Buffer and Length. The carry bits in result of addition are dropped.
3261 The 32-bit result is returned. If Length is 0, then 0 is returned.
3263 If Buffer is NULL, then ASSERT().
3264 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3265 If Length is not aligned on a 32-bit boundary, then ASSERT().
3266 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3268 @param Buffer Pointer to the buffer to carry out the sum operation.
3269 @param Length The size, in bytes, of Buffer.
3271 @return Sum The sum of Buffer with carry bits dropped during additions.
3277 IN CONST UINT32
*Buffer
,
3283 Returns the two's complement checksum of all elements in a buffer of
3286 This function first calculates the sum of the 32-bit values in the buffer
3287 specified by Buffer and Length. The carry bits in the result of addition
3288 are dropped. Then, the two's complement of the sum is returned. If Length
3289 is 0, then 0 is returned.
3291 If Buffer is NULL, then ASSERT().
3292 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3293 If Length is not aligned on a 32-bit boundary, then ASSERT().
3294 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3296 @param Buffer Pointer to the buffer to carry out the checksum operation.
3297 @param Length The size, in bytes, of Buffer.
3299 @return Checksum The 2's complement checksum of Buffer.
3304 CalculateCheckSum32 (
3305 IN CONST UINT32
*Buffer
,
3311 Returns the sum of all elements in a buffer of 64-bit values. During
3312 calculation, the carry bits are dropped.
3314 This function calculates the sum of the 64-bit values in the buffer
3315 specified by Buffer and Length. The carry bits in result of addition are dropped.
3316 The 64-bit result is returned. If Length is 0, then 0 is returned.
3318 If Buffer is NULL, then ASSERT().
3319 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3320 If Length is not aligned on a 64-bit boundary, then ASSERT().
3321 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3323 @param Buffer Pointer to the buffer to carry out the sum operation.
3324 @param Length The size, in bytes, of Buffer.
3326 @return Sum The sum of Buffer with carry bits dropped during additions.
3332 IN CONST UINT64
*Buffer
,
3338 Returns the two's complement checksum of all elements in a buffer of
3341 This function first calculates the sum of the 64-bit values in the buffer
3342 specified by Buffer and Length. The carry bits in the result of addition
3343 are dropped. Then, the two's complement of the sum is returned. If Length
3344 is 0, then 0 is returned.
3346 If Buffer is NULL, then ASSERT().
3347 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3348 If Length is not aligned on a 64-bit boundary, then ASSERT().
3349 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3351 @param Buffer Pointer to the buffer to carry out the checksum operation.
3352 @param Length The size, in bytes, of Buffer.
3354 @return Checksum The 2's complement checksum of Buffer.
3359 CalculateCheckSum64 (
3360 IN CONST UINT64
*Buffer
,
3366 // Base Library CPU Functions
3370 Function entry point used when a stack switch is requested with SwitchStack()
3372 @param Context1 Context1 parameter passed into SwitchStack().
3373 @param Context2 Context2 parameter passed into SwitchStack().
3378 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
)(
3379 IN VOID
*Context1
, OPTIONAL
3380 IN VOID
*Context2 OPTIONAL
3385 Used to serialize load and store operations.
3387 All loads and stores that proceed calls to this function are guaranteed to be
3388 globally visible when this function returns.
3399 Saves the current CPU context that can be restored with a call to LongJump()
3402 Saves the current CPU context in the buffer specified by JumpBuffer and
3403 returns 0. The initial call to SetJump() must always return 0. Subsequent
3404 calls to LongJump() cause a non-zero value to be returned by SetJump().
3406 If JumpBuffer is NULL, then ASSERT().
3407 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3409 NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.
3410 The same structure must never be used for more than one CPU architecture context.
3411 For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module.
3412 SetJump()/LongJump() is not currently supported for the EBC processor type.
3414 @param JumpBuffer A pointer to CPU context buffer.
3416 @retval 0 Indicates a return from SetJump().
3422 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
3427 Restores the CPU context that was saved with SetJump().
3429 Restores the CPU context from the buffer specified by JumpBuffer. This
3430 function never returns to the caller. Instead is resumes execution based on
3431 the state of JumpBuffer.
3433 If JumpBuffer is NULL, then ASSERT().
3434 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3435 If Value is 0, then ASSERT().
3437 @param JumpBuffer A pointer to CPU context buffer.
3438 @param Value The value to return when the SetJump() context is
3439 restored and must be non-zero.
3445 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
3451 Enables CPU interrupts.
3462 Disables CPU interrupts.
3473 Disables CPU interrupts and returns the interrupt state prior to the disable
3476 @retval TRUE CPU interrupts were enabled on entry to this call.
3477 @retval FALSE CPU interrupts were disabled on entry to this call.
3482 SaveAndDisableInterrupts (
3488 Enables CPU interrupts for the smallest window required to capture any
3494 EnableDisableInterrupts (
3500 Retrieves the current CPU interrupt state.
3502 Returns TRUE is interrupts are currently enabled. Otherwise
3505 @retval TRUE CPU interrupts are enabled.
3506 @retval FALSE CPU interrupts are disabled.
3517 Set the current CPU interrupt state.
3519 Sets the current CPU interrupt state to the state specified by
3520 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
3521 InterruptState is FALSE, then interrupts are disabled. InterruptState is
3524 @param InterruptState TRUE if interrupts should enabled. FALSE if
3525 interrupts should be disabled.
3527 @return InterruptState
3533 IN BOOLEAN InterruptState
3538 Requests CPU to pause for a short period of time.
3540 Requests CPU to pause for a short period of time. Typically used in MP
3541 systems to prevent memory starvation while waiting for a spin lock.
3552 Transfers control to a function starting with a new stack.
3554 Transfers control to the function specified by EntryPoint using the
3555 new stack specified by NewStack and passing in the parameters specified
3556 by Context1 and Context2. Context1 and Context2 are optional and may
3557 be NULL. The function EntryPoint must never return. This function
3558 supports a variable number of arguments following the NewStack parameter.
3559 These additional arguments are ignored on IA-32, x64, and EBC.
3560 IPF CPUs expect one additional parameter of type VOID * that specifies
3561 the new backing store pointer.
3563 If EntryPoint is NULL, then ASSERT().
3564 If NewStack is NULL, then ASSERT().
3566 @param EntryPoint A pointer to function to call with the new stack.
3567 @param Context1 A pointer to the context to pass into the EntryPoint
3569 @param Context2 A pointer to the context to pass into the EntryPoint
3571 @param NewStack A pointer to the new stack to use for the EntryPoint
3573 @param ... This variable argument list is ignored for IA32, x64, and EBC.
3574 For IPF, this variable argument list is expected to contain
3575 a single parameter of type VOID * that specifies the new backing
3583 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
3584 IN VOID
*Context1
, OPTIONAL
3585 IN VOID
*Context2
, OPTIONAL
3592 Generates a breakpoint on the CPU.
3594 Generates a breakpoint on the CPU. The breakpoint must be implemented such
3595 that code can resume normal execution after the breakpoint.
3606 Executes an infinite loop.
3608 Forces the CPU to execute an infinite loop. A debugger may be used to skip
3609 past the loop and the code that follows the loop must execute properly. This
3610 implies that the infinite loop must not cause the code that follow it to be
3619 #if defined (MDE_CPU_IPF)
3622 Flush a range of cache lines in the cache coherency domain of the calling
3625 Flushes the cache lines specified by Address and Length. If Address is not aligned
3626 on a cache line boundary, then entire cache line containing Address is flushed.
3627 If Address + Length is not aligned on a cache line boundary, then the entire cache
3628 line containing Address + Length - 1 is flushed. This function may choose to flush
3629 the entire cache if that is more efficient than flushing the specified range. If
3630 Length is 0, the no cache lines are flushed. Address is returned.
3631 This function is only available on IPF.
3633 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
3635 @param Address The base address of the instruction lines to invalidate. If
3636 the CPU is in a physical addressing mode, then Address is a
3637 physical address. If the CPU is in a virtual addressing mode,
3638 then Address is a virtual address.
3640 @param Length The number of bytes to invalidate from the instruction cache.
3647 AsmFlushCacheRange (
3654 Executes a FC instruction
3655 Executes a FC instruction on the cache line specified by Address.
3656 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3657 An implementation may flush a larger region. This function is only available on IPF.
3659 @param Address The Address of cache line to be flushed.
3661 @return The address of FC instruction executed.
3672 Executes a FC.I instruction.
3673 Executes a FC.I instruction on the cache line specified by Address.
3674 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3675 An implementation may flush a larger region. This function is only available on IPF.
3677 @param Address The Address of cache line to be flushed.
3679 @return The address of FC.I instruction executed.
3690 Reads the current value of a Processor Identifier Register (CPUID).
3692 Reads and returns the current value of Processor Identifier Register specified by Index.
3693 The Index of largest implemented CPUID (One less than the number of implemented CPUID
3694 registers) is determined by CPUID [3] bits {7:0}.
3695 No parameter checking is performed on Index. If the Index value is beyond the
3696 implemented CPUID register range, a Reserved Register/Field fault may occur. The caller
3697 must either guarantee that Index is valid, or the caller must set up fault handlers to
3698 catch the faults. This function is only available on IPF.
3700 @param Index The 8-bit Processor Identifier Register index to read.
3702 @return The current value of Processor Identifier Register specified by Index.
3713 Reads the current value of 64-bit Processor Status Register (PSR).
3714 This function is only available on IPF.
3716 @return The current value of PSR.
3727 Writes the current value of 64-bit Processor Status Register (PSR).
3729 No parameter checking is performed on Value. All bits of Value corresponding to
3730 reserved fields of PSR must be 0 or a Reserved Register/Field fault may occur.
3731 The caller must either guarantee that Value is valid, or the caller must set up
3732 fault handlers to catch the faults. This function is only available on IPF.
3734 @param Value The 64-bit value to write to PSR.
3736 @return The 64-bit value written to the PSR.
3747 Reads the current value of 64-bit Kernel Register #0 (KR0).
3748 This function is only available on IPF.
3750 @return The current value of KR0.
3761 Reads the current value of 64-bit Kernel Register #1 (KR1).
3762 This function is only available on IPF.
3764 @return The current value of KR1.
3775 Reads the current value of 64-bit Kernel Register #2 (KR2).
3776 This function is only available on IPF.
3778 @return The current value of KR2.
3789 Reads the current value of 64-bit Kernel Register #3 (KR3).
3790 This function is only available on IPF.
3792 @return The current value of KR3.
3803 Reads the current value of 64-bit Kernel Register #4 (KR4).
3804 This function is only available on IPF.
3806 @return The current value of KR4.
3817 Reads the current value of 64-bit Kernel Register #5 (KR5).
3818 This function is only available on IPF.
3820 @return The current value of KR5.
3831 Reads the current value of 64-bit Kernel Register #6 (KR6).
3832 This function is only available on IPF.
3834 @return The current value of KR6.
3845 Reads the current value of 64-bit Kernel Register #7 (KR7).
3846 This function is only available on IPF.
3848 @return The current value of KR7.
3859 Write the current value of 64-bit Kernel Register #0 (KR0).
3860 This function is only available on IPF.
3862 @param Value The 64-bit value to write to KR0.
3864 @return The 64-bit value written to the KR0.
3875 Write the current value of 64-bit Kernel Register #1 (KR1).
3876 This function is only available on IPF.
3878 @param Value The 64-bit value to write to KR1.
3880 @return The 64-bit value written to the KR1.
3891 Write the current value of 64-bit Kernel Register #2 (KR2).
3892 This function is only available on IPF.
3894 @param Value The 64-bit value to write to KR2.
3896 @return The 64-bit value written to the KR2.
3907 Write the current value of 64-bit Kernel Register #3 (KR3).
3908 This function is only available on IPF.
3910 @param Value The 64-bit value to write to KR3.
3912 @return The 64-bit value written to the KR3.
3923 Write the current value of 64-bit Kernel Register #4 (KR4).
3924 This function is only available on IPF.
3926 @param Value The 64-bit value to write to KR4.
3928 @return The 64-bit value written to the KR4.
3939 Write the current value of 64-bit Kernel Register #5 (KR5).
3940 This function is only available on IPF.
3942 @param Value The 64-bit value to write to KR5.
3944 @return The 64-bit value written to the KR5.
3955 Write the current value of 64-bit Kernel Register #6 (KR6).
3956 This function is only available on IPF.
3958 @param Value The 64-bit value to write to KR6.
3960 @return The 64-bit value written to the KR6.
3971 Write the current value of 64-bit Kernel Register #7 (KR7).
3972 This function is only available on IPF.
3974 @param Value The 64-bit value to write to KR7.
3976 @return The 64-bit value written to the KR7.
3987 Reads the current value of Interval Timer Counter Register (ITC).
3988 This function is only available on IPF.
3990 @return The current value of ITC.
4001 Reads the current value of Interval Timer Vector Register (ITV).
4002 This function is only available on IPF.
4004 @return The current value of ITV.
4015 Reads the current value of Interval Timer Match Register (ITM).
4016 This function is only available on IPF.
4018 @return The current value of ITM.
4028 Writes the current value of 64-bit Interval Timer Counter Register (ITC).
4029 This function is only available on IPF.
4031 @param Value The 64-bit value to write to ITC.
4033 @return The 64-bit value written to the ITC.
4044 Writes the current value of 64-bit Interval Timer Match Register (ITM).
4045 This function is only available on IPF.
4047 @param Value The 64-bit value to write to ITM.
4049 @return The 64-bit value written to the ITM.
4060 Writes the current value of 64-bit Interval Timer Vector Register (ITV).
4061 No parameter checking is performed on Value. All bits of Value corresponding to
4062 reserved fields of ITV must be 0 or a Reserved Register/Field fault may occur.
4063 The caller must either guarantee that Value is valid, or the caller must set up
4064 fault handlers to catch the faults.
4065 This function is only available on IPF.
4067 @param Value The 64-bit value to write to ITV.
4069 @return The 64-bit value written to the ITV.
4080 Reads the current value of Default Control Register (DCR).
4081 This function is only available on IPF.
4083 @return The current value of DCR.
4094 Reads the current value of Interruption Vector Address Register (IVA).
4095 This function is only available on IPF.
4097 @return The current value of IVA.
4107 Reads the current value of Page Table Address Register (PTA).
4108 This function is only available on IPF.
4110 @return The current value of PTA.
4121 Writes the current value of 64-bit Default Control Register (DCR).
4122 No parameter checking is performed on Value. All bits of Value corresponding to
4123 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4124 The caller must either guarantee that Value is valid, or the caller must set up
4125 fault handlers to catch the faults.
4126 This function is only available on IPF.
4128 @param Value The 64-bit value to write to DCR.
4130 @return The 64-bit value written to the DCR.
4141 Writes the current value of 64-bit Interruption Vector Address Register (IVA).
4142 The size of vector table is 32 K bytes and is 32 K bytes aligned
4143 the low 15 bits of Value is ignored when written.
4144 This function is only available on IPF.
4146 @param Value The 64-bit value to write to IVA.
4148 @return The 64-bit value written to the IVA.
4159 Writes the current value of 64-bit Page Table Address Register (PTA).
4160 No parameter checking is performed on Value. All bits of Value corresponding to
4161 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4162 The caller must either guarantee that Value is valid, or the caller must set up
4163 fault handlers to catch the faults.
4164 This function is only available on IPF.
4166 @param Value The 64-bit value to write to PTA.
4168 @return The 64-bit value written to the PTA.
4178 Reads the current value of Local Interrupt ID Register (LID).
4179 This function is only available on IPF.
4181 @return The current value of LID.
4192 Reads the current value of External Interrupt Vector Register (IVR).
4193 This function is only available on IPF.
4195 @return The current value of IVR.
4206 Reads the current value of Task Priority Register (TPR).
4207 This function is only available on IPF.
4209 @return The current value of TPR.
4220 Reads the current value of External Interrupt Request Register #0 (IRR0).
4221 This function is only available on IPF.
4223 @return The current value of IRR0.
4234 Reads the current value of External Interrupt Request Register #1 (IRR1).
4235 This function is only available on IPF.
4237 @return The current value of IRR1.
4248 Reads the current value of External Interrupt Request Register #2 (IRR2).
4249 This function is only available on IPF.
4251 @return The current value of IRR2.
4262 Reads the current value of External Interrupt Request Register #3 (IRR3).
4263 This function is only available on IPF.
4265 @return The current value of IRR3.
4276 Reads the current value of Performance Monitor Vector Register (PMV).
4277 This function is only available on IPF.
4279 @return The current value of PMV.
4290 Reads the current value of Corrected Machine Check Vector Register (CMCV).
4291 This function is only available on IPF.
4293 @return The current value of CMCV.
4304 Reads the current value of Local Redirection Register #0 (LRR0).
4305 This function is only available on IPF.
4307 @return The current value of LRR0.
4318 Reads the current value of Local Redirection Register #1 (LRR1).
4319 This function is only available on IPF.
4321 @return The current value of LRR1.
4332 Writes the current value of 64-bit Page Local Interrupt ID Register (LID).
4333 No parameter checking is performed on Value. All bits of Value corresponding to
4334 reserved fields of LID must be 0 or a Reserved Register/Field fault may occur.
4335 The caller must either guarantee that Value is valid, or the caller must set up
4336 fault handlers to catch the faults.
4337 This function is only available on IPF.
4339 @param Value The 64-bit value to write to LID.
4341 @return The 64-bit value written to the LID.
4352 Writes the current value of 64-bit Task Priority Register (TPR).
4353 No parameter checking is performed on Value. All bits of Value corresponding to
4354 reserved fields of TPR must be 0 or a Reserved Register/Field fault may occur.
4355 The caller must either guarantee that Value is valid, or the caller must set up
4356 fault handlers to catch the faults.
4357 This function is only available on IPF.
4359 @param Value The 64-bit value to write to TPR.
4361 @return The 64-bit value written to the TPR.
4372 Performs a write operation on End OF External Interrupt Register (EOI).
4373 Writes a value of 0 to the EOI Register. This function is only available on IPF.
4384 Writes the current value of 64-bit Performance Monitor Vector Register (PMV).
4385 No parameter checking is performed on Value. All bits of Value corresponding
4386 to reserved fields of PMV must be 0 or a Reserved Register/Field fault may occur.
4387 The caller must either guarantee that Value is valid, or the caller must set up
4388 fault handlers to catch the faults.
4389 This function is only available on IPF.
4391 @param Value The 64-bit value to write to PMV.
4393 @return The 64-bit value written to the PMV.
4404 Writes the current value of 64-bit Corrected Machine Check Vector Register (CMCV).
4405 No parameter checking is performed on Value. All bits of Value corresponding
4406 to reserved fields of CMCV must be 0 or a Reserved Register/Field fault may occur.
4407 The caller must either guarantee that Value is valid, or the caller must set up
4408 fault handlers to catch the faults.
4409 This function is only available on IPF.
4411 @param Value The 64-bit value to write to CMCV.
4413 @return The 64-bit value written to the CMCV.
4424 Writes the current value of 64-bit Local Redirection Register #0 (LRR0).
4425 No parameter checking is performed on Value. All bits of Value corresponding
4426 to reserved fields of LRR0 must be 0 or a Reserved Register/Field fault may occur.
4427 The caller must either guarantee that Value is valid, or the caller must set up
4428 fault handlers to catch the faults.
4429 This function is only available on IPF.
4431 @param Value The 64-bit value to write to LRR0.
4433 @return The 64-bit value written to the LRR0.
4444 Writes the current value of 64-bit Local Redirection Register #1 (LRR1).
4445 No parameter checking is performed on Value. All bits of Value corresponding
4446 to reserved fields of LRR1 must be 0 or a Reserved Register/Field fault may occur.
4447 The caller must either guarantee that Value is valid, or the caller must
4448 set up fault handlers to catch the faults.
4449 This function is only available on IPF.
4451 @param Value The 64-bit value to write to LRR1.
4453 @return The 64-bit value written to the LRR1.
4464 Reads the current value of Instruction Breakpoint Register (IBR).
4466 The Instruction Breakpoint Registers are used in pairs. The even numbered
4467 registers contain breakpoint addresses, and the odd numbered registers contain
4468 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4469 on all processor models. Implemented registers are contiguous starting with
4470 register 0. No parameter checking is performed on Index, and if the Index value
4471 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4472 occur. The caller must either guarantee that Index is valid, or the caller must
4473 set up fault handlers to catch the faults.
4474 This function is only available on IPF.
4476 @param Index The 8-bit Instruction Breakpoint Register index to read.
4478 @return The current value of Instruction Breakpoint Register specified by Index.
4489 Reads the current value of Data Breakpoint Register (DBR).
4491 The Data Breakpoint Registers are used in pairs. The even numbered registers
4492 contain breakpoint addresses, and odd numbered registers contain breakpoint
4493 mask conditions. At least 4 data registers pairs are implemented on all processor
4494 models. Implemented registers are contiguous starting with register 0.
4495 No parameter checking is performed on Index. If the Index value is beyond
4496 the implemented DBR register range, a Reserved Register/Field fault may occur.
4497 The caller must either guarantee that Index is valid, or the caller must set up
4498 fault handlers to catch the faults.
4499 This function is only available on IPF.
4501 @param Index The 8-bit Data Breakpoint Register index to read.
4503 @return The current value of Data Breakpoint Register specified by Index.
4514 Reads the current value of Performance Monitor Configuration Register (PMC).
4516 All processor implementations provide at least 4 performance counters
4517 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4518 status registers (PMC [0]... PMC [3]). Processor implementations may provide
4519 additional implementation-dependent PMC and PMD to increase the number of
4520 'generic' performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4521 register set is implementation dependent. No parameter checking is performed
4522 on Index. If the Index value is beyond the implemented PMC register range,
4523 zero value will be returned.
4524 This function is only available on IPF.
4526 @param Index The 8-bit Performance Monitor Configuration Register index to read.
4528 @return The current value of Performance Monitor Configuration Register
4540 Reads the current value of Performance Monitor Data Register (PMD).
4542 All processor implementations provide at least 4 performance counters
4543 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter
4544 overflow status registers (PMC [0]... PMC [3]). Processor implementations may
4545 provide additional implementation-dependent PMC and PMD to increase the number
4546 of 'generic' performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4547 register set is implementation dependent. No parameter checking is performed
4548 on Index. If the Index value is beyond the implemented PMD register range,
4549 zero value will be returned.
4550 This function is only available on IPF.
4552 @param Index The 8-bit Performance Monitor Data Register index to read.
4554 @return The current value of Performance Monitor Data Register specified by Index.
4565 Writes the current value of 64-bit Instruction Breakpoint Register (IBR).
4567 Writes current value of Instruction Breakpoint Register specified by Index.
4568 The Instruction Breakpoint Registers are used in pairs. The even numbered
4569 registers contain breakpoint addresses, and odd numbered registers contain
4570 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4571 on all processor models. Implemented registers are contiguous starting with
4572 register 0. No parameter checking is performed on Index. If the Index value
4573 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4574 occur. The caller must either guarantee that Index is valid, or the caller must
4575 set up fault handlers to catch the faults.
4576 This function is only available on IPF.
4578 @param Index The 8-bit Instruction Breakpoint Register index to write.
4579 @param Value The 64-bit value to write to IBR.
4581 @return The 64-bit value written to the IBR.
4593 Writes the current value of 64-bit Data Breakpoint Register (DBR).
4595 Writes current value of Data Breakpoint Register specified by Index.
4596 The Data Breakpoint Registers are used in pairs. The even numbered registers
4597 contain breakpoint addresses, and odd numbered registers contain breakpoint
4598 mask conditions. At least 4 data registers pairs are implemented on all processor
4599 models. Implemented registers are contiguous starting with register 0. No parameter
4600 checking is performed on Index. If the Index value is beyond the implemented
4601 DBR register range, a Reserved Register/Field fault may occur. The caller must
4602 either guarantee that Index is valid, or the caller must set up fault handlers to
4604 This function is only available on IPF.
4606 @param Index The 8-bit Data Breakpoint Register index to write.
4607 @param Value The 64-bit value to write to DBR.
4609 @return The 64-bit value written to the DBR.
4621 Writes the current value of 64-bit Performance Monitor Configuration Register (PMC).
4623 Writes current value of Performance Monitor Configuration Register specified by Index.
4624 All processor implementations provide at least 4 performance counters
4625 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow status
4626 registers (PMC [0]... PMC [3]). Processor implementations may provide additional
4627 implementation-dependent PMC and PMD to increase the number of 'generic' performance
4628 counters (PMC/PMD pairs). The remainder of PMC and PMD register set is implementation
4629 dependent. No parameter checking is performed on Index. If the Index value is
4630 beyond the implemented PMC register range, the write is ignored.
4631 This function is only available on IPF.
4633 @param Index The 8-bit Performance Monitor Configuration Register index to write.
4634 @param Value The 64-bit value to write to PMC.
4636 @return The 64-bit value written to the PMC.
4648 Writes the current value of 64-bit Performance Monitor Data Register (PMD).
4650 Writes current value of Performance Monitor Data Register specified by Index.
4651 All processor implementations provide at least 4 performance counters
4652 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4653 status registers (PMC [0]... PMC [3]). Processor implementations may provide
4654 additional implementation-dependent PMC and PMD to increase the number of 'generic'
4655 performance counters (PMC/PMD pairs). The remainder of PMC and PMD register set
4656 is implementation dependent. No parameter checking is performed on Index. If the
4657 Index value is beyond the implemented PMD register range, the write is ignored.
4658 This function is only available on IPF.
4660 @param Index The 8-bit Performance Monitor Data Register index to write.
4661 @param Value The 64-bit value to write to PMD.
4663 @return The 64-bit value written to the PMD.
4675 Reads the current value of 64-bit Global Pointer (GP).
4677 Reads and returns the current value of GP.
4678 This function is only available on IPF.
4680 @return The current value of GP.
4691 Write the current value of 64-bit Global Pointer (GP).
4693 Writes the current value of GP. The 64-bit value written to the GP is returned.
4694 No parameter checking is performed on Value.
4695 This function is only available on IPF.
4697 @param Value The 64-bit value to write to GP.
4699 @return The 64-bit value written to the GP.
4710 Reads the current value of 64-bit Stack Pointer (SP).
4712 Reads and returns the current value of SP.
4713 This function is only available on IPF.
4715 @return The current value of SP.
4726 /// Valid Index value for AsmReadControlRegister()
4728 #define IPF_CONTROL_REGISTER_DCR 0
4729 #define IPF_CONTROL_REGISTER_ITM 1
4730 #define IPF_CONTROL_REGISTER_IVA 2
4731 #define IPF_CONTROL_REGISTER_PTA 8
4732 #define IPF_CONTROL_REGISTER_IPSR 16
4733 #define IPF_CONTROL_REGISTER_ISR 17
4734 #define IPF_CONTROL_REGISTER_IIP 19
4735 #define IPF_CONTROL_REGISTER_IFA 20
4736 #define IPF_CONTROL_REGISTER_ITIR 21
4737 #define IPF_CONTROL_REGISTER_IIPA 22
4738 #define IPF_CONTROL_REGISTER_IFS 23
4739 #define IPF_CONTROL_REGISTER_IIM 24
4740 #define IPF_CONTROL_REGISTER_IHA 25
4741 #define IPF_CONTROL_REGISTER_LID 64
4742 #define IPF_CONTROL_REGISTER_IVR 65
4743 #define IPF_CONTROL_REGISTER_TPR 66
4744 #define IPF_CONTROL_REGISTER_EOI 67
4745 #define IPF_CONTROL_REGISTER_IRR0 68
4746 #define IPF_CONTROL_REGISTER_IRR1 69
4747 #define IPF_CONTROL_REGISTER_IRR2 70
4748 #define IPF_CONTROL_REGISTER_IRR3 71
4749 #define IPF_CONTROL_REGISTER_ITV 72
4750 #define IPF_CONTROL_REGISTER_PMV 73
4751 #define IPF_CONTROL_REGISTER_CMCV 74
4752 #define IPF_CONTROL_REGISTER_LRR0 80
4753 #define IPF_CONTROL_REGISTER_LRR1 81
4756 Reads a 64-bit control register.
4758 Reads and returns the control register specified by Index. The valid Index valued are defined
4759 above in "Related Definitions".
4760 If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned. This function is only available on IPF.
4762 @param Index The index of the control register to read.
4764 @return The control register specified by Index.
4769 AsmReadControlRegister (
4775 /// Valid Index value for AsmReadApplicationRegister()
4777 #define IPF_APPLICATION_REGISTER_K0 0
4778 #define IPF_APPLICATION_REGISTER_K1 1
4779 #define IPF_APPLICATION_REGISTER_K2 2
4780 #define IPF_APPLICATION_REGISTER_K3 3
4781 #define IPF_APPLICATION_REGISTER_K4 4
4782 #define IPF_APPLICATION_REGISTER_K5 5
4783 #define IPF_APPLICATION_REGISTER_K6 6
4784 #define IPF_APPLICATION_REGISTER_K7 7
4785 #define IPF_APPLICATION_REGISTER_RSC 16
4786 #define IPF_APPLICATION_REGISTER_BSP 17
4787 #define IPF_APPLICATION_REGISTER_BSPSTORE 18
4788 #define IPF_APPLICATION_REGISTER_RNAT 19
4789 #define IPF_APPLICATION_REGISTER_FCR 21
4790 #define IPF_APPLICATION_REGISTER_EFLAG 24
4791 #define IPF_APPLICATION_REGISTER_CSD 25
4792 #define IPF_APPLICATION_REGISTER_SSD 26
4793 #define IPF_APPLICATION_REGISTER_CFLG 27
4794 #define IPF_APPLICATION_REGISTER_FSR 28
4795 #define IPF_APPLICATION_REGISTER_FIR 29
4796 #define IPF_APPLICATION_REGISTER_FDR 30
4797 #define IPF_APPLICATION_REGISTER_CCV 32
4798 #define IPF_APPLICATION_REGISTER_UNAT 36
4799 #define IPF_APPLICATION_REGISTER_FPSR 40
4800 #define IPF_APPLICATION_REGISTER_ITC 44
4801 #define IPF_APPLICATION_REGISTER_PFS 64
4802 #define IPF_APPLICATION_REGISTER_LC 65
4803 #define IPF_APPLICATION_REGISTER_EC 66
4806 Reads a 64-bit application register.
4808 Reads and returns the application register specified by Index. The valid Index valued are defined
4809 above in "Related Definitions".
4810 If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned. This function is only available on IPF.
4812 @param Index The index of the application register to read.
4814 @return The application register specified by Index.
4819 AsmReadApplicationRegister (
4825 Determines if the CPU is currently executing in virtual, physical, or mixed mode.
4827 Determines the current execution mode of the CPU.
4828 If the CPU is in virtual mode(PSR.RT=1, PSR.DT=1, PSR.IT=1), then 1 is returned.
4829 If the CPU is in physical mode(PSR.RT=0, PSR.DT=0, PSR.IT=0), then 0 is returned.
4830 If the CPU is not in physical mode or virtual mode, then it is in mixed mode,
4832 This function is only available on IPF.
4834 @retval 1 The CPU is in virtual mode.
4835 @retval 0 The CPU is in physical mode.
4836 @retval -1 The CPU is in mixed mode.
4847 Makes a PAL procedure call.
4849 This is a wrapper function to make a PAL procedure call. Based on the Index
4850 value this API will make static or stacked PAL call. The following table
4851 describes the usage of PAL Procedure Index Assignment. Architected procedures
4852 may be designated as required or optional. If a PAL procedure is specified
4853 as optional, a unique return code of 0xFFFFFFFFFFFFFFFF is returned in the
4854 Status field of the PAL_CALL_RETURN structure.
4855 This indicates that the procedure is not present in this PAL implementation.
4856 It is the caller's responsibility to check for this return code after calling
4857 any optional PAL procedure.
4858 No parameter checking is performed on the 5 input parameters, but there are
4859 some common rules that the caller should follow when making a PAL call. Any
4860 address passed to PAL as buffers for return parameters must be 8-byte aligned.
4861 Unaligned addresses may cause undefined results. For those parameters defined
4862 as reserved or some fields defined as reserved must be zero filled or the invalid
4863 argument return value may be returned or undefined result may occur during the
4864 execution of the procedure. If the PalEntryPoint does not point to a valid
4865 PAL entry point then the system behavior is undefined. This function is only
4868 @param PalEntryPoint The PAL procedure calls entry point.
4869 @param Index The PAL procedure Index number.
4870 @param Arg2 The 2nd parameter for PAL procedure calls.
4871 @param Arg3 The 3rd parameter for PAL procedure calls.
4872 @param Arg4 The 4th parameter for PAL procedure calls.
4874 @return structure returned from the PAL Call procedure, including the status and return value.
4880 IN UINT64 PalEntryPoint
,
4888 #elif defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
4890 /// IA32 and x64 Specific Functions
4891 /// Byte packed structure for 16-bit Real Mode EFLAGS
4895 UINT32 CF
:1; /// Carry Flag
4896 UINT32 Reserved_0
:1; /// Reserved
4897 UINT32 PF
:1; /// Parity Flag
4898 UINT32 Reserved_1
:1; /// Reserved
4899 UINT32 AF
:1; /// Auxiliary Carry Flag
4900 UINT32 Reserved_2
:1; /// Reserved
4901 UINT32 ZF
:1; /// Zero Flag
4902 UINT32 SF
:1; /// Sign Flag
4903 UINT32 TF
:1; /// Trap Flag
4904 UINT32 IF
:1; /// Interrupt Enable Flag
4905 UINT32 DF
:1; /// Direction Flag
4906 UINT32 OF
:1; /// Overflow Flag
4907 UINT32 IOPL
:2; /// I/O Privilege Level
4908 UINT32 NT
:1; /// Nested Task
4909 UINT32 Reserved_3
:1; /// Reserved
4915 /// Byte packed structure for EFLAGS/RFLAGS
4916 /// 32-bits on IA-32
4917 /// 64-bits on x64. The upper 32-bits on x64 are reserved
4921 UINT32 CF
:1; /// Carry Flag
4922 UINT32 Reserved_0
:1; /// Reserved
4923 UINT32 PF
:1; /// Parity Flag
4924 UINT32 Reserved_1
:1; /// Reserved
4925 UINT32 AF
:1; /// Auxiliary Carry Flag
4926 UINT32 Reserved_2
:1; /// Reserved
4927 UINT32 ZF
:1; /// Zero Flag
4928 UINT32 SF
:1; /// Sign Flag
4929 UINT32 TF
:1; /// Trap Flag
4930 UINT32 IF
:1; /// Interrupt Enable Flag
4931 UINT32 DF
:1; /// Direction Flag
4932 UINT32 OF
:1; /// Overflow Flag
4933 UINT32 IOPL
:2; /// I/O Privilege Level
4934 UINT32 NT
:1; /// Nested Task
4935 UINT32 Reserved_3
:1; /// Reserved
4936 UINT32 RF
:1; /// Resume Flag
4937 UINT32 VM
:1; /// Virtual 8086 Mode
4938 UINT32 AC
:1; /// Alignment Check
4939 UINT32 VIF
:1; /// Virtual Interrupt Flag
4940 UINT32 VIP
:1; /// Virtual Interrupt Pending
4941 UINT32 ID
:1; /// ID Flag
4942 UINT32 Reserved_4
:10; /// Reserved
4948 /// Byte packed structure for Control Register 0 (CR0)
4949 /// 32-bits on IA-32
4950 /// 64-bits on x64. The upper 32-bits on x64 are reserved
4954 UINT32 PE
:1; /// Protection Enable
4955 UINT32 MP
:1; /// Monitor Coprocessor
4956 UINT32 EM
:1; /// Emulation
4957 UINT32 TS
:1; /// Task Switched
4958 UINT32 ET
:1; /// Extension Type
4959 UINT32 NE
:1; /// Numeric Error
4960 UINT32 Reserved_0
:10; /// Reserved
4961 UINT32 WP
:1; /// Write Protect
4962 UINT32 Reserved_1
:1; /// Reserved
4963 UINT32 AM
:1; /// Alignment Mask
4964 UINT32 Reserved_2
:10; /// Reserved
4965 UINT32 NW
:1; /// Mot Write-through
4966 UINT32 CD
:1; /// Cache Disable
4967 UINT32 PG
:1; /// Paging
4973 /// Byte packed structure for Control Register 4 (CR4)
4974 /// 32-bits on IA-32
4975 /// 64-bits on x64. The upper 32-bits on x64 are reserved
4979 UINT32 VME
:1; /// Virtual-8086 Mode Extensions
4980 UINT32 PVI
:1; /// Protected-Mode Virtual Interrupts
4981 UINT32 TSD
:1; /// Time Stamp Disable
4982 UINT32 DE
:1; /// Debugging Extensions
4983 UINT32 PSE
:1; /// Page Size Extensions
4984 UINT32 PAE
:1; /// Physical Address Extension
4985 UINT32 MCE
:1; /// Machine Check Enable
4986 UINT32 PGE
:1; /// Page Global Enable
4987 UINT32 PCE
:1; /// Performance Monitoring Counter
4989 UINT32 OSFXSR
:1; /// Operating System Support for
4990 /// FXSAVE and FXRSTOR instructions
4991 UINT32 OSXMMEXCPT
:1; /// Operating System Support for
4992 /// Unmasked SIMD Floating Point
4994 UINT32 Reserved_0
:2; /// Reserved
4995 UINT32 VMXE
:1; /// VMX Enable
4996 UINT32 Reserved_1
:18; /// Reseved
5002 /// Byte packed structure for an IDTR, GDTR, LDTR descriptor
5011 #define IA32_IDT_GATE_TYPE_TASK 0x85
5012 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
5013 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
5014 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
5015 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
5018 /// Byte packed structure for an Interrupt Gate Descriptor
5020 #if defined (MDE_CPU_IA32)
5024 UINT32 OffsetLow
:16; // Offset bits 15..0
5025 UINT32 Selector
:16; // Selector
5026 UINT32 Reserved_0
:8; // Reserved
5027 UINT32 GateType
:8; // Gate Type. See #defines above
5028 UINT32 OffsetHigh
:16; // Offset bits 31..16
5031 } IA32_IDT_GATE_DESCRIPTOR
;
5035 #if defined (MDE_CPU_X64)
5039 UINT32 OffsetLow
:16; // Offset bits 15..0
5040 UINT32 Selector
:16; // Selector
5041 UINT32 Reserved_0
:8; // Reserved
5042 UINT32 GateType
:8; // Gate Type. See #defines above
5043 UINT32 OffsetHigh
:16; // Offset bits 31..16
5044 UINT32 OffsetUpper
:32; // Offset bits 63..32
5045 UINT32 Reserved_1
:32; // Reserved
5049 } IA32_IDT_GATE_DESCRIPTOR
;
5054 /// Byte packed structure for an FP/SSE/SSE2 context
5061 /// Structures for the 16-bit real mode thunks
5114 IA32_EFLAGS32 EFLAGS
;
5124 } IA32_REGISTER_SET
;
5127 /// Byte packed structure for an 16-bit real mode thunks
5130 IA32_REGISTER_SET
*RealModeState
;
5131 VOID
*RealModeBuffer
;
5132 UINT32 RealModeBufferSize
;
5133 UINT32 ThunkAttributes
;
5136 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
5137 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
5138 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
5141 Retrieves CPUID information.
5143 Executes the CPUID instruction with EAX set to the value specified by Index.
5144 This function always returns Index.
5145 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5146 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5147 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5148 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5149 This function is only available on IA-32 and x64.
5151 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
5153 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5154 instruction. This is an optional parameter that may be NULL.
5155 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5156 instruction. This is an optional parameter that may be NULL.
5157 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5158 instruction. This is an optional parameter that may be NULL.
5159 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5160 instruction. This is an optional parameter that may be NULL.
5169 OUT UINT32
*Eax
, OPTIONAL
5170 OUT UINT32
*Ebx
, OPTIONAL
5171 OUT UINT32
*Ecx
, OPTIONAL
5172 OUT UINT32
*Edx OPTIONAL
5177 Retrieves CPUID information using an extended leaf identifier.
5179 Executes the CPUID instruction with EAX set to the value specified by Index
5180 and ECX set to the value specified by SubIndex. This function always returns
5181 Index. This function is only available on IA-32 and x64.
5183 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5184 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5185 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5186 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5188 @param Index The 32-bit value to load into EAX prior to invoking the
5190 @param SubIndex The 32-bit value to load into ECX prior to invoking the
5192 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5193 instruction. This is an optional parameter that may be
5195 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5196 instruction. This is an optional parameter that may be
5198 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5199 instruction. This is an optional parameter that may be
5201 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5202 instruction. This is an optional parameter that may be
5213 OUT UINT32
*Eax
, OPTIONAL
5214 OUT UINT32
*Ebx
, OPTIONAL
5215 OUT UINT32
*Ecx
, OPTIONAL
5216 OUT UINT32
*Edx OPTIONAL
5221 Set CD bit and clear NW bit of CR0 followed by a WBINVD.
5223 Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,
5224 and executing a WBINVD instruction. This function is only available on IA-32 and x64.
5235 Perform a WBINVD and clear both the CD and NW bits of CR0.
5237 Enables the caches by executing a WBINVD instruction and then clear both the CD and NW
5238 bits of CR0 to 0. This function is only available on IA-32 and x64.
5249 Returns the lower 32-bits of a Machine Specific Register(MSR).
5251 Reads and returns the lower 32-bits of the MSR specified by Index.
5252 No parameter checking is performed on Index, and some Index values may cause
5253 CPU exceptions. The caller must either guarantee that Index is valid, or the
5254 caller must set up exception handlers to catch the exceptions. This function
5255 is only available on IA-32 and x64.
5257 @param Index The 32-bit MSR index to read.
5259 @return The lower 32 bits of the MSR identified by Index.
5270 Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.
5271 The upper 32-bits of the MSR are set to zero.
5273 Writes the 32-bit value specified by Value to the MSR specified by Index. The
5274 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
5275 the MSR is returned. No parameter checking is performed on Index or Value,
5276 and some of these may cause CPU exceptions. The caller must either guarantee
5277 that Index and Value are valid, or the caller must establish proper exception
5278 handlers. This function is only available on IA-32 and x64.
5280 @param Index The 32-bit MSR index to write.
5281 @param Value The 32-bit value to write to the MSR.
5295 Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and
5296 writes the result back to the 64-bit MSR.
5298 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5299 between the lower 32-bits of the read result and the value specified by
5300 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
5301 32-bits of the value written to the MSR is returned. No parameter checking is
5302 performed on Index or OrData, and some of these may cause CPU exceptions. The
5303 caller must either guarantee that Index and OrData are valid, or the caller
5304 must establish proper exception handlers. This function is only available on
5307 @param Index The 32-bit MSR index to write.
5308 @param OrData The value to OR with the read value from the MSR.
5310 @return The lower 32-bit value written to the MSR.
5322 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
5323 the result back to the 64-bit MSR.
5325 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5326 lower 32-bits of the read result and the value specified by AndData, and
5327 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
5328 the value written to the MSR is returned. No parameter checking is performed
5329 on Index or AndData, and some of these may cause CPU exceptions. The caller
5330 must either guarantee that Index and AndData are valid, or the caller must
5331 establish proper exception handlers. This function is only available on IA-32
5334 @param Index The 32-bit MSR index to write.
5335 @param AndData The value to AND with the read value from the MSR.
5337 @return The lower 32-bit value written to the MSR.
5349 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR
5350 on the lower 32-bits, and writes the result back to the 64-bit MSR.
5352 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5353 lower 32-bits of the read result and the value specified by AndData
5354 preserving the upper 32-bits, performs a bitwise OR between the
5355 result of the AND operation and the value specified by OrData, and writes the
5356 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
5357 written to the MSR is returned. No parameter checking is performed on Index,
5358 AndData, or OrData, and some of these may cause CPU exceptions. The caller
5359 must either guarantee that Index, AndData, and OrData are valid, or the
5360 caller must establish proper exception handlers. This function is only
5361 available on IA-32 and x64.
5363 @param Index The 32-bit MSR index to write.
5364 @param AndData The value to AND with the read value from the MSR.
5365 @param OrData The value to OR with the result of the AND operation.
5367 @return The lower 32-bit value written to the MSR.
5380 Reads a bit field of an MSR.
5382 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
5383 specified by the StartBit and the EndBit. The value of the bit field is
5384 returned. The caller must either guarantee that Index is valid, or the caller
5385 must set up exception handlers to catch the exceptions. This function is only
5386 available on IA-32 and x64.
5388 If StartBit is greater than 31, then ASSERT().
5389 If EndBit is greater than 31, then ASSERT().
5390 If EndBit is less than StartBit, then ASSERT().
5392 @param Index The 32-bit MSR index to read.
5393 @param StartBit The ordinal of the least significant bit in the bit field.
5395 @param EndBit The ordinal of the most significant bit in the bit field.
5398 @return The bit field read from the MSR.
5403 AsmMsrBitFieldRead32 (
5411 Writes a bit field to an MSR.
5413 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
5414 field is specified by the StartBit and the EndBit. All other bits in the
5415 destination MSR are preserved. The lower 32-bits of the MSR written is
5416 returned. The caller must either guarantee that Index and the data written
5417 is valid, or the caller must set up exception handlers to catch the exceptions.
5418 This function is only available on IA-32 and x64.
5420 If StartBit is greater than 31, then ASSERT().
5421 If EndBit is greater than 31, then ASSERT().
5422 If EndBit is less than StartBit, then ASSERT().
5424 @param Index The 32-bit MSR index to write.
5425 @param StartBit The ordinal of the least significant bit in the bit field.
5427 @param EndBit The ordinal of the most significant bit in the bit field.
5429 @param Value New value of the bit field.
5431 @return The lower 32-bit of the value written to the MSR.
5436 AsmMsrBitFieldWrite32 (
5445 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
5446 result back to the bit field in the 64-bit MSR.
5448 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5449 between the read result and the value specified by OrData, and writes the
5450 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
5451 written to the MSR are returned. Extra left bits in OrData are stripped. The
5452 caller must either guarantee that Index and the data written is valid, or
5453 the caller must set up exception handlers to catch the exceptions. This
5454 function is only available on IA-32 and x64.
5456 If StartBit is greater than 31, then ASSERT().
5457 If EndBit is greater than 31, then ASSERT().
5458 If EndBit is less than StartBit, then ASSERT().
5460 @param Index The 32-bit MSR index to write.
5461 @param StartBit The ordinal of the least significant bit in the bit field.
5463 @param EndBit The ordinal of the most significant bit in the bit field.
5465 @param OrData The value to OR with the read value from the MSR.
5467 @return The lower 32-bit of the value written to the MSR.
5472 AsmMsrBitFieldOr32 (
5481 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5482 result back to the bit field in the 64-bit MSR.
5484 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5485 read result and the value specified by AndData, and writes the result to the
5486 64-bit MSR specified by Index. The lower 32-bits of the value written to the
5487 MSR are returned. Extra left bits in AndData are stripped. The caller must
5488 either guarantee that Index and the data written is valid, or the caller must
5489 set up exception handlers to catch the exceptions. This function is only
5490 available on IA-32 and x64.
5492 If StartBit is greater than 31, then ASSERT().
5493 If EndBit is greater than 31, then ASSERT().
5494 If EndBit is less than StartBit, then ASSERT().
5496 @param Index The 32-bit MSR index to write.
5497 @param StartBit The ordinal of the least significant bit in the bit field.
5499 @param EndBit The ordinal of the most significant bit in the bit field.
5501 @param AndData The value to AND with the read value from the MSR.
5503 @return The lower 32-bit of the value written to the MSR.
5508 AsmMsrBitFieldAnd32 (
5517 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5518 bitwise OR, and writes the result back to the bit field in the
5521 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
5522 bitwise OR between the read result and the value specified by
5523 AndData, and writes the result to the 64-bit MSR specified by Index. The
5524 lower 32-bits of the value written to the MSR are returned. Extra left bits
5525 in both AndData and OrData are stripped. The caller must either guarantee
5526 that Index and the data written is valid, or the caller must set up exception
5527 handlers to catch the exceptions. This function is only available on IA-32
5530 If StartBit is greater than 31, then ASSERT().
5531 If EndBit is greater than 31, then ASSERT().
5532 If EndBit is less than StartBit, then ASSERT().
5534 @param Index The 32-bit MSR index to write.
5535 @param StartBit The ordinal of the least significant bit in the bit field.
5537 @param EndBit The ordinal of the most significant bit in the bit field.
5539 @param AndData The value to AND with the read value from the MSR.
5540 @param OrData The value to OR with the result of the AND operation.
5542 @return The lower 32-bit of the value written to the MSR.
5547 AsmMsrBitFieldAndThenOr32 (
5557 Returns a 64-bit Machine Specific Register(MSR).
5559 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
5560 performed on Index, and some Index values may cause CPU exceptions. The
5561 caller must either guarantee that Index is valid, or the caller must set up
5562 exception handlers to catch the exceptions. This function is only available
5565 @param Index The 32-bit MSR index to read.
5567 @return The value of the MSR identified by Index.
5578 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
5581 Writes the 64-bit value specified by Value to the MSR specified by Index. The
5582 64-bit value written to the MSR is returned. No parameter checking is
5583 performed on Index or Value, and some of these may cause CPU exceptions. The
5584 caller must either guarantee that Index and Value are valid, or the caller
5585 must establish proper exception handlers. This function is only available on
5588 @param Index The 32-bit MSR index to write.
5589 @param Value The 64-bit value to write to the MSR.
5603 Reads a 64-bit MSR, performs a bitwise OR, and writes the result
5604 back to the 64-bit MSR.
5606 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5607 between the read result and the value specified by OrData, and writes the
5608 result to the 64-bit MSR specified by Index. The value written to the MSR is
5609 returned. No parameter checking is performed on Index or OrData, and some of
5610 these may cause CPU exceptions. The caller must either guarantee that Index
5611 and OrData are valid, or the caller must establish proper exception handlers.
5612 This function is only available on IA-32 and x64.
5614 @param Index The 32-bit MSR index to write.
5615 @param OrData The value to OR with the read value from the MSR.
5617 @return The value written back to the MSR.
5629 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
5632 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5633 read result and the value specified by OrData, and writes the result to the
5634 64-bit MSR specified by Index. The value written to the MSR is returned. No
5635 parameter checking is performed on Index or OrData, and some of these may
5636 cause CPU exceptions. The caller must either guarantee that Index and OrData
5637 are valid, or the caller must establish proper exception handlers. This
5638 function is only available on IA-32 and x64.
5640 @param Index The 32-bit MSR index to write.
5641 @param AndData The value to AND with the read value from the MSR.
5643 @return The value written back to the MSR.
5655 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise
5656 OR, and writes the result back to the 64-bit MSR.
5658 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
5659 result and the value specified by AndData, performs a bitwise OR
5660 between the result of the AND operation and the value specified by OrData,
5661 and writes the result to the 64-bit MSR specified by Index. The value written
5662 to the MSR is returned. No parameter checking is performed on Index, AndData,
5663 or OrData, and some of these may cause CPU exceptions. The caller must either
5664 guarantee that Index, AndData, and OrData are valid, or the caller must
5665 establish proper exception handlers. This function is only available on IA-32
5668 @param Index The 32-bit MSR index to write.
5669 @param AndData The value to AND with the read value from the MSR.
5670 @param OrData The value to OR with the result of the AND operation.
5672 @return The value written back to the MSR.
5685 Reads a bit field of an MSR.
5687 Reads the bit field in the 64-bit MSR. The bit field is specified by the
5688 StartBit and the EndBit. The value of the bit field is returned. The caller
5689 must either guarantee that Index is valid, or the caller must set up
5690 exception handlers to catch the exceptions. This function is only available
5693 If StartBit is greater than 63, then ASSERT().
5694 If EndBit is greater than 63, then ASSERT().
5695 If EndBit is less than StartBit, then ASSERT().
5697 @param Index The 32-bit MSR index to read.
5698 @param StartBit The ordinal of the least significant bit in the bit field.
5700 @param EndBit The ordinal of the most significant bit in the bit field.
5703 @return The value read from the MSR.
5708 AsmMsrBitFieldRead64 (
5716 Writes a bit field to an MSR.
5718 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
5719 the StartBit and the EndBit. All other bits in the destination MSR are
5720 preserved. The MSR written is returned. The caller must either guarantee
5721 that Index and the data written is valid, or the caller must set up exception
5722 handlers to catch the exceptions. This function is only available on IA-32 and x64.
5724 If StartBit is greater than 63, then ASSERT().
5725 If EndBit is greater than 63, then ASSERT().
5726 If EndBit is less than StartBit, then ASSERT().
5728 @param Index The 32-bit MSR index to write.
5729 @param StartBit The ordinal of the least significant bit in the bit field.
5731 @param EndBit The ordinal of the most significant bit in the bit field.
5733 @param Value New value of the bit field.
5735 @return The value written back to the MSR.
5740 AsmMsrBitFieldWrite64 (
5749 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and
5750 writes the result back to the bit field in the 64-bit MSR.
5752 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5753 between the read result and the value specified by OrData, and writes the
5754 result to the 64-bit MSR specified by Index. The value written to the MSR is
5755 returned. Extra left bits in OrData are stripped. The caller must either
5756 guarantee that Index and the data written is valid, or the caller must set up
5757 exception handlers to catch the exceptions. This function is only available
5760 If StartBit is greater than 63, then ASSERT().
5761 If EndBit is greater than 63, then ASSERT().
5762 If EndBit is less than StartBit, then ASSERT().
5764 @param Index The 32-bit MSR index to write.
5765 @param StartBit The ordinal of the least significant bit in the bit field.
5767 @param EndBit The ordinal of the most significant bit in the bit field.
5769 @param OrData The value to OR with the read value from the bit field.
5771 @return The value written back to the MSR.
5776 AsmMsrBitFieldOr64 (
5785 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5786 result back to the bit field in the 64-bit MSR.
5788 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5789 read result and the value specified by AndData, and writes the result to the
5790 64-bit MSR specified by Index. The value written to the MSR is returned.
5791 Extra left bits in AndData are stripped. The caller must either guarantee
5792 that Index and the data written is valid, or the caller must set up exception
5793 handlers to catch the exceptions. This function is only available on IA-32
5796 If StartBit is greater than 63, then ASSERT().
5797 If EndBit is greater than 63, then ASSERT().
5798 If EndBit is less than StartBit, then ASSERT().
5800 @param Index The 32-bit MSR index to write.
5801 @param StartBit The ordinal of the least significant bit in the bit field.
5803 @param EndBit The ordinal of the most significant bit in the bit field.
5805 @param AndData The value to AND with the read value from the bit field.
5807 @return The value written back to the MSR.
5812 AsmMsrBitFieldAnd64 (
5821 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5822 bitwise OR, and writes the result back to the bit field in the
5825 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
5826 a bitwise OR between the read result and the value specified by
5827 AndData, and writes the result to the 64-bit MSR specified by Index. The
5828 value written to the MSR is returned. Extra left bits in both AndData and
5829 OrData are stripped. The caller must either guarantee that Index and the data
5830 written is valid, or the caller must set up exception handlers to catch the
5831 exceptions. This function is only available on IA-32 and x64.
5833 If StartBit is greater than 63, then ASSERT().
5834 If EndBit is greater than 63, then ASSERT().
5835 If EndBit is less than StartBit, then ASSERT().
5837 @param Index The 32-bit MSR index to write.
5838 @param StartBit The ordinal of the least significant bit in the bit field.
5840 @param EndBit The ordinal of the most significant bit in the bit field.
5842 @param AndData The value to AND with the read value from the bit field.
5843 @param OrData The value to OR with the result of the AND operation.
5845 @return The value written back to the MSR.
5850 AsmMsrBitFieldAndThenOr64 (
5860 Reads the current value of the EFLAGS register.
5862 Reads and returns the current value of the EFLAGS register. This function is
5863 only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a
5864 64-bit value on x64.
5866 @return EFLAGS on IA-32 or RFLAGS on x64.
5877 Reads the current value of the Control Register 0 (CR0).
5879 Reads and returns the current value of CR0. This function is only available
5880 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
5883 @return The value of the Control Register 0 (CR0).
5894 Reads the current value of the Control Register 2 (CR2).
5896 Reads and returns the current value of CR2. This function is only available
5897 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
5900 @return The value of the Control Register 2 (CR2).
5911 Reads the current value of the Control Register 3 (CR3).
5913 Reads and returns the current value of CR3. This function is only available
5914 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
5917 @return The value of the Control Register 3 (CR3).
5928 Reads the current value of the Control Register 4 (CR4).
5930 Reads and returns the current value of CR4. This function is only available
5931 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
5934 @return The value of the Control Register 4 (CR4).
5945 Writes a value to Control Register 0 (CR0).
5947 Writes and returns a new value to CR0. This function is only available on
5948 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
5950 @param Cr0 The value to write to CR0.
5952 @return The value written to CR0.
5963 Writes a value to Control Register 2 (CR2).
5965 Writes and returns a new value to CR2. This function is only available on
5966 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
5968 @param Cr2 The value to write to CR2.
5970 @return The value written to CR2.
5981 Writes a value to Control Register 3 (CR3).
5983 Writes and returns a new value to CR3. This function is only available on
5984 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
5986 @param Cr3 The value to write to CR3.
5988 @return The value written to CR3.
5999 Writes a value to Control Register 4 (CR4).
6001 Writes and returns a new value to CR4. This function is only available on
6002 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6004 @param Cr4 The value to write to CR4.
6006 @return The value written to CR4.
6017 Reads the current value of Debug Register 0 (DR0).
6019 Reads and returns the current value of DR0. This function is only available
6020 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6023 @return The value of Debug Register 0 (DR0).
6034 Reads the current value of Debug Register 1 (DR1).
6036 Reads and returns the current value of DR1. This function is only available
6037 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6040 @return The value of Debug Register 1 (DR1).
6051 Reads the current value of Debug Register 2 (DR2).
6053 Reads and returns the current value of DR2. This function is only available
6054 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6057 @return The value of Debug Register 2 (DR2).
6068 Reads the current value of Debug Register 3 (DR3).
6070 Reads and returns the current value of DR3. This function is only available
6071 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6074 @return The value of Debug Register 3 (DR3).
6085 Reads the current value of Debug Register 4 (DR4).
6087 Reads and returns the current value of DR4. This function is only available
6088 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6091 @return The value of Debug Register 4 (DR4).
6102 Reads the current value of Debug Register 5 (DR5).
6104 Reads and returns the current value of DR5. This function is only available
6105 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6108 @return The value of Debug Register 5 (DR5).
6119 Reads the current value of Debug Register 6 (DR6).
6121 Reads and returns the current value of DR6. This function is only available
6122 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6125 @return The value of Debug Register 6 (DR6).
6136 Reads the current value of Debug Register 7 (DR7).
6138 Reads and returns the current value of DR7. This function is only available
6139 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6142 @return The value of Debug Register 7 (DR7).
6153 Writes a value to Debug Register 0 (DR0).
6155 Writes and returns a new value to DR0. This function is only available on
6156 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6158 @param Dr0 The value to write to Dr0.
6160 @return The value written to Debug Register 0 (DR0).
6171 Writes a value to Debug Register 1 (DR1).
6173 Writes and returns a new value to DR1. This function is only available on
6174 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6176 @param Dr1 The value to write to Dr1.
6178 @return The value written to Debug Register 1 (DR1).
6189 Writes a value to Debug Register 2 (DR2).
6191 Writes and returns a new value to DR2. This function is only available on
6192 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6194 @param Dr2 The value to write to Dr2.
6196 @return The value written to Debug Register 2 (DR2).
6207 Writes a value to Debug Register 3 (DR3).
6209 Writes and returns a new value to DR3. This function is only available on
6210 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6212 @param Dr3 The value to write to Dr3.
6214 @return The value written to Debug Register 3 (DR3).
6225 Writes a value to Debug Register 4 (DR4).
6227 Writes and returns a new value to DR4. This function is only available on
6228 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6230 @param Dr4 The value to write to Dr4.
6232 @return The value written to Debug Register 4 (DR4).
6243 Writes a value to Debug Register 5 (DR5).
6245 Writes and returns a new value to DR5. This function is only available on
6246 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6248 @param Dr5 The value to write to Dr5.
6250 @return The value written to Debug Register 5 (DR5).
6261 Writes a value to Debug Register 6 (DR6).
6263 Writes and returns a new value to DR6. This function is only available on
6264 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6266 @param Dr6 The value to write to Dr6.
6268 @return The value written to Debug Register 6 (DR6).
6279 Writes a value to Debug Register 7 (DR7).
6281 Writes and returns a new value to DR7. This function is only available on
6282 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6284 @param Dr7 The value to write to Dr7.
6286 @return The value written to Debug Register 7 (DR7).
6297 Reads the current value of Code Segment Register (CS).
6299 Reads and returns the current value of CS. This function is only available on
6302 @return The current value of CS.
6313 Reads the current value of Data Segment Register (DS).
6315 Reads and returns the current value of DS. This function is only available on
6318 @return The current value of DS.
6329 Reads the current value of Extra Segment Register (ES).
6331 Reads and returns the current value of ES. This function is only available on
6334 @return The current value of ES.
6345 Reads the current value of FS Data Segment Register (FS).
6347 Reads and returns the current value of FS. This function is only available on
6350 @return The current value of FS.
6361 Reads the current value of GS Data Segment Register (GS).
6363 Reads and returns the current value of GS. This function is only available on
6366 @return The current value of GS.
6377 Reads the current value of Stack Segment Register (SS).
6379 Reads and returns the current value of SS. This function is only available on
6382 @return The current value of SS.
6393 Reads the current value of Task Register (TR).
6395 Reads and returns the current value of TR. This function is only available on
6398 @return The current value of TR.
6409 Reads the current Global Descriptor Table Register(GDTR) descriptor.
6411 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
6412 function is only available on IA-32 and x64.
6414 If Gdtr is NULL, then ASSERT().
6416 @param Gdtr Pointer to a GDTR descriptor.
6422 OUT IA32_DESCRIPTOR
*Gdtr
6427 Writes the current Global Descriptor Table Register (GDTR) descriptor.
6429 Writes and the current GDTR descriptor specified by Gdtr. This function is
6430 only available on IA-32 and x64.
6432 If Gdtr is NULL, then ASSERT().
6434 @param Gdtr Pointer to a GDTR descriptor.
6440 IN CONST IA32_DESCRIPTOR
*Gdtr
6445 Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.
6447 Reads and returns the current IDTR descriptor and returns it in Idtr. This
6448 function is only available on IA-32 and x64.
6450 If Idtr is NULL, then ASSERT().
6452 @param Idtr Pointer to a IDTR descriptor.
6458 OUT IA32_DESCRIPTOR
*Idtr
6463 Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.
6465 Writes the current IDTR descriptor and returns it in Idtr. This function is
6466 only available on IA-32 and x64.
6468 If Idtr is NULL, then ASSERT().
6470 @param Idtr Pointer to a IDTR descriptor.
6476 IN CONST IA32_DESCRIPTOR
*Idtr
6481 Reads the current Local Descriptor Table Register(LDTR) selector.
6483 Reads and returns the current 16-bit LDTR descriptor value. This function is
6484 only available on IA-32 and x64.
6486 @return The current selector of LDT.
6497 Writes the current Local Descriptor Table Register (LDTR) selector.
6499 Writes and the current LDTR descriptor specified by Ldtr. This function is
6500 only available on IA-32 and x64.
6502 @param Ldtr 16-bit LDTR selector value.
6513 Save the current floating point/SSE/SSE2 context to a buffer.
6515 Saves the current floating point/SSE/SSE2 state to the buffer specified by
6516 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
6517 available on IA-32 and x64.
6519 If Buffer is NULL, then ASSERT().
6520 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6522 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6528 OUT IA32_FX_BUFFER
*Buffer
6533 Restores the current floating point/SSE/SSE2 context from a buffer.
6535 Restores the current floating point/SSE/SSE2 state from the buffer specified
6536 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
6537 only available on IA-32 and x64.
6539 If Buffer is NULL, then ASSERT().
6540 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6541 If Buffer was not saved with AsmFxSave(), then ASSERT().
6543 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6549 IN CONST IA32_FX_BUFFER
*Buffer
6554 Reads the current value of 64-bit MMX Register #0 (MM0).
6556 Reads and returns the current value of MM0. This function is only available
6559 @return The current value of MM0.
6570 Reads the current value of 64-bit MMX Register #1 (MM1).
6572 Reads and returns the current value of MM1. This function is only available
6575 @return The current value of MM1.
6586 Reads the current value of 64-bit MMX Register #2 (MM2).
6588 Reads and returns the current value of MM2. This function is only available
6591 @return The current value of MM2.
6602 Reads the current value of 64-bit MMX Register #3 (MM3).
6604 Reads and returns the current value of MM3. This function is only available
6607 @return The current value of MM3.
6618 Reads the current value of 64-bit MMX Register #4 (MM4).
6620 Reads and returns the current value of MM4. This function is only available
6623 @return The current value of MM4.
6634 Reads the current value of 64-bit MMX Register #5 (MM5).
6636 Reads and returns the current value of MM5. This function is only available
6639 @return The current value of MM5.
6650 Reads the current value of 64-bit MMX Register #6 (MM6).
6652 Reads and returns the current value of MM6. This function is only available
6655 @return The current value of MM6.
6666 Reads the current value of 64-bit MMX Register #7 (MM7).
6668 Reads and returns the current value of MM7. This function is only available
6671 @return The current value of MM7.
6682 Writes the current value of 64-bit MMX Register #0 (MM0).
6684 Writes the current value of MM0. This function is only available on IA32 and
6687 @param Value The 64-bit value to write to MM0.
6698 Writes the current value of 64-bit MMX Register #1 (MM1).
6700 Writes the current value of MM1. This function is only available on IA32 and
6703 @param Value The 64-bit value to write to MM1.
6714 Writes the current value of 64-bit MMX Register #2 (MM2).
6716 Writes the current value of MM2. This function is only available on IA32 and
6719 @param Value The 64-bit value to write to MM2.
6730 Writes the current value of 64-bit MMX Register #3 (MM3).
6732 Writes the current value of MM3. This function is only available on IA32 and
6735 @param Value The 64-bit value to write to MM3.
6746 Writes the current value of 64-bit MMX Register #4 (MM4).
6748 Writes the current value of MM4. This function is only available on IA32 and
6751 @param Value The 64-bit value to write to MM4.
6762 Writes the current value of 64-bit MMX Register #5 (MM5).
6764 Writes the current value of MM5. This function is only available on IA32 and
6767 @param Value The 64-bit value to write to MM5.
6778 Writes the current value of 64-bit MMX Register #6 (MM6).
6780 Writes the current value of MM6. This function is only available on IA32 and
6783 @param Value The 64-bit value to write to MM6.
6794 Writes the current value of 64-bit MMX Register #7 (MM7).
6796 Writes the current value of MM7. This function is only available on IA32 and
6799 @param Value The 64-bit value to write to MM7.
6810 Reads the current value of Time Stamp Counter (TSC).
6812 Reads and returns the current value of TSC. This function is only available
6815 @return The current value of TSC
6826 Reads the current value of a Performance Counter (PMC).
6828 Reads and returns the current value of performance counter specified by
6829 Index. This function is only available on IA-32 and x64.
6831 @param Index The 32-bit Performance Counter index to read.
6833 @return The value of the PMC specified by Index.
6844 Sets up a monitor buffer that is used by AsmMwait().
6846 Executes a MONITOR instruction with the register state specified by Eax, Ecx
6847 and Edx. Returns Eax. This function is only available on IA-32 and x64.
6849 @param Eax The value to load into EAX or RAX before executing the MONITOR
6851 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6853 @param Edx The value to load into EDX or RDX before executing the MONITOR
6869 Executes an MWAIT instruction.
6871 Executes an MWAIT instruction with the register state specified by Eax and
6872 Ecx. Returns Eax. This function is only available on IA-32 and x64.
6874 @param Eax The value to load into EAX or RAX before executing the MONITOR
6876 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6891 Executes a WBINVD instruction.
6893 Executes a WBINVD instruction. This function is only available on IA-32 and
6905 Executes a INVD instruction.
6907 Executes a INVD instruction. This function is only available on IA-32 and
6919 Flushes a cache line from all the instruction and data caches within the
6920 coherency domain of the CPU.
6922 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
6923 This function is only available on IA-32 and x64.
6925 @param LinearAddress The address of the cache line to flush. If the CPU is
6926 in a physical addressing mode, then LinearAddress is a
6927 physical address. If the CPU is in a virtual
6928 addressing mode, then LinearAddress is a virtual
6931 @return LinearAddress
6936 IN VOID
*LinearAddress
6941 Enables the 32-bit paging mode on the CPU.
6943 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
6944 must be properly initialized prior to calling this service. This function
6945 assumes the current execution mode is 32-bit protected mode. This function is
6946 only available on IA-32. After the 32-bit paging mode is enabled, control is
6947 transferred to the function specified by EntryPoint using the new stack
6948 specified by NewStack and passing in the parameters specified by Context1 and
6949 Context2. Context1 and Context2 are optional and may be NULL. The function
6950 EntryPoint must never return.
6952 If the current execution mode is not 32-bit protected mode, then ASSERT().
6953 If EntryPoint is NULL, then ASSERT().
6954 If NewStack is NULL, then ASSERT().
6956 There are a number of constraints that must be followed before calling this
6958 1) Interrupts must be disabled.
6959 2) The caller must be in 32-bit protected mode with flat descriptors. This
6960 means all descriptors must have a base of 0 and a limit of 4GB.
6961 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
6963 4) CR3 must point to valid page tables that will be used once the transition
6964 is complete, and those page tables must guarantee that the pages for this
6965 function and the stack are identity mapped.
6967 @param EntryPoint A pointer to function to call with the new stack after
6969 @param Context1 A pointer to the context to pass into the EntryPoint
6970 function as the first parameter after paging is enabled.
6971 @param Context2 A pointer to the context to pass into the EntryPoint
6972 function as the second parameter after paging is enabled.
6973 @param NewStack A pointer to the new stack to use for the EntryPoint
6974 function after paging is enabled.
6980 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
6981 IN VOID
*Context1
, OPTIONAL
6982 IN VOID
*Context2
, OPTIONAL
6988 Disables the 32-bit paging mode on the CPU.
6990 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
6991 mode. This function assumes the current execution mode is 32-paged protected
6992 mode. This function is only available on IA-32. After the 32-bit paging mode
6993 is disabled, control is transferred to the function specified by EntryPoint
6994 using the new stack specified by NewStack and passing in the parameters
6995 specified by Context1 and Context2. Context1 and Context2 are optional and
6996 may be NULL. The function EntryPoint must never return.
6998 If the current execution mode is not 32-bit paged mode, then ASSERT().
6999 If EntryPoint is NULL, then ASSERT().
7000 If NewStack is NULL, then ASSERT().
7002 There are a number of constraints that must be followed before calling this
7004 1) Interrupts must be disabled.
7005 2) The caller must be in 32-bit paged mode.
7006 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
7007 4) CR3 must point to valid page tables that guarantee that the pages for
7008 this function and the stack are identity mapped.
7010 @param EntryPoint A pointer to function to call with the new stack after
7012 @param Context1 A pointer to the context to pass into the EntryPoint
7013 function as the first parameter after paging is disabled.
7014 @param Context2 A pointer to the context to pass into the EntryPoint
7015 function as the second parameter after paging is
7017 @param NewStack A pointer to the new stack to use for the EntryPoint
7018 function after paging is disabled.
7023 AsmDisablePaging32 (
7024 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
7025 IN VOID
*Context1
, OPTIONAL
7026 IN VOID
*Context2
, OPTIONAL
7032 Enables the 64-bit paging mode on the CPU.
7034 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7035 must be properly initialized prior to calling this service. This function
7036 assumes the current execution mode is 32-bit protected mode with flat
7037 descriptors. This function is only available on IA-32. After the 64-bit
7038 paging mode is enabled, control is transferred to the function specified by
7039 EntryPoint using the new stack specified by NewStack and passing in the
7040 parameters specified by Context1 and Context2. Context1 and Context2 are
7041 optional and may be 0. The function EntryPoint must never return.
7043 If the current execution mode is not 32-bit protected mode with flat
7044 descriptors, then ASSERT().
7045 If EntryPoint is 0, then ASSERT().
7046 If NewStack is 0, then ASSERT().
7048 @param Cs The 16-bit selector to load in the CS before EntryPoint
7049 is called. The descriptor in the GDT that this selector
7050 references must be setup for long mode.
7051 @param EntryPoint The 64-bit virtual address of the function to call with
7052 the new stack after paging is enabled.
7053 @param Context1 The 64-bit virtual address of the context to pass into
7054 the EntryPoint function as the first parameter after
7056 @param Context2 The 64-bit virtual address of the context to pass into
7057 the EntryPoint function as the second parameter after
7059 @param NewStack The 64-bit virtual address of the new stack to use for
7060 the EntryPoint function after paging is enabled.
7067 IN UINT64 EntryPoint
,
7068 IN UINT64 Context1
, OPTIONAL
7069 IN UINT64 Context2
, OPTIONAL
7075 Disables the 64-bit paging mode on the CPU.
7077 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
7078 mode. This function assumes the current execution mode is 64-paging mode.
7079 This function is only available on x64. After the 64-bit paging mode is
7080 disabled, control is transferred to the function specified by EntryPoint
7081 using the new stack specified by NewStack and passing in the parameters
7082 specified by Context1 and Context2. Context1 and Context2 are optional and
7083 may be 0. The function EntryPoint must never return.
7085 If the current execution mode is not 64-bit paged mode, then ASSERT().
7086 If EntryPoint is 0, then ASSERT().
7087 If NewStack is 0, then ASSERT().
7089 @param Cs The 16-bit selector to load in the CS before EntryPoint
7090 is called. The descriptor in the GDT that this selector
7091 references must be setup for 32-bit protected mode.
7092 @param EntryPoint The 64-bit virtual address of the function to call with
7093 the new stack after paging is disabled.
7094 @param Context1 The 64-bit virtual address of the context to pass into
7095 the EntryPoint function as the first parameter after
7097 @param Context2 The 64-bit virtual address of the context to pass into
7098 the EntryPoint function as the second parameter after
7100 @param NewStack The 64-bit virtual address of the new stack to use for
7101 the EntryPoint function after paging is disabled.
7106 AsmDisablePaging64 (
7108 IN UINT32 EntryPoint
,
7109 IN UINT32 Context1
, OPTIONAL
7110 IN UINT32 Context2
, OPTIONAL
7116 // 16-bit thunking services
7120 Retrieves the properties for 16-bit thunk functions.
7122 Computes the size of the buffer and stack below 1MB required to use the
7123 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
7124 buffer size is returned in RealModeBufferSize, and the stack size is returned
7125 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
7126 then the actual minimum stack size is ExtraStackSize plus the maximum number
7127 of bytes that need to be passed to the 16-bit real mode code.
7129 If RealModeBufferSize is NULL, then ASSERT().
7130 If ExtraStackSize is NULL, then ASSERT().
7132 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
7133 required to use the 16-bit thunk functions.
7134 @param ExtraStackSize A pointer to the extra size of stack below 1MB
7135 that the 16-bit thunk functions require for
7136 temporary storage in the transition to and from
7142 AsmGetThunk16Properties (
7143 OUT UINT32
*RealModeBufferSize
,
7144 OUT UINT32
*ExtraStackSize
7149 Prepares all structures a code required to use AsmThunk16().
7151 Prepares all structures and code required to use AsmThunk16().
7153 If ThunkContext is NULL, then ASSERT().
7155 @param ThunkContext A pointer to the context structure that describes the
7156 16-bit real mode code to call.
7162 OUT THUNK_CONTEXT
*ThunkContext
7167 Transfers control to a 16-bit real mode entry point and returns the results.
7169 Transfers control to a 16-bit real mode entry point and returns the results.
7170 AsmPrepareThunk16() must be called with ThunkContext before this function is used.
7171 This function must be called with interrupts disabled.
7173 The register state from the RealModeState field of ThunkContext is restored just prior
7174 to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,
7175 which is used to set the interrupt state when a 16-bit real mode entry point is called.
7176 Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.
7177 The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to
7178 the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.
7179 The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,
7180 so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment
7181 and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry
7182 point must exit with a RETF instruction. The register state is captured into RealModeState immediately
7183 after the RETF instruction is executed.
7185 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
7186 or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure
7187 the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.
7189 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
7190 then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.
7191 This includes the base vectors, the interrupt masks, and the edge/level trigger mode.
7193 If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code
7194 is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.
7196 If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
7197 ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to
7198 disable the A20 mask.
7200 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in
7201 ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,
7202 then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
7204 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in
7205 ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
7207 If ThunkContext is NULL, then ASSERT().
7208 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
7209 If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
7210 ThunkAttributes, then ASSERT().
7212 @param ThunkContext A pointer to the context structure that describes the
7213 16-bit real mode code to call.
7219 IN OUT THUNK_CONTEXT
*ThunkContext
7224 Prepares all structures and code for a 16-bit real mode thunk, transfers
7225 control to a 16-bit real mode entry point, and returns the results.
7227 Prepares all structures and code for a 16-bit real mode thunk, transfers
7228 control to a 16-bit real mode entry point, and returns the results. If the
7229 caller only need to perform a single 16-bit real mode thunk, then this
7230 service should be used. If the caller intends to make more than one 16-bit
7231 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
7232 once and AsmThunk16() can be called for each 16-bit real mode thunk.
7234 See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.
7236 @param ThunkContext A pointer to the context structure that describes the
7237 16-bit real mode code to call.
7242 AsmPrepareAndThunk16 (
7243 IN OUT THUNK_CONTEXT
*ThunkContext