3 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Memory-only library functions with no library constructor/destructor
23 #ifndef __EDKII_GLUE_BASE_LIB_H__
24 #define __EDKII_GLUE_BASE_LIB_H__
30 #define StrCpy(_Dest, _Source) GlueStrCpy(_Dest, _Source)
31 #define StrnCpy(_Dest, _Source, _Length) GlueStrnCpy(_Dest, _Source, _Length)
32 #define StrLen(_String) GlueStrLen(_String)
33 #define StrSize(_String) GlueStrSize(_String)
34 #define StrCmp(_FristString, _SecondString) GlueStrCmp(_FristString, _SecondString)
35 #define StrnCmp(_FirstString, _SecondString, _Length) GlueStrnCmp(_FirstString, _SecondString, _Length)
36 #define StrCat(_Dest, _Source) GlueStrCat(_Dest, _Source)
37 #define StrnCat(_Dest, _Source, _Length) GlueStrnCat(_Dest, _Source, _Length)
42 #define InitializeListHead(_ListHead) GlueInitializeListHead(_ListHead)
43 #define InsertHeadList(_ListHead, _Entry ) GlueInsertHeadList(_ListHead, _Entry)
44 #define InsertTailList(_ListHead, _Entry) GlueInsertTailList(_ListHead, _Entry)
45 #define GetFirstNode(_List) GlueGetFirstNode(_List)
46 #define GetNextNode(_List, _Node) GlueGetNextNode(_List, _Node)
47 #define IsListEmpty(_ListHead) GlueIsListEmpty(_ListHead)
48 #define IsNull(_List, _Node) GlueIsNull(_List, _Node)
49 #define IsNodeAtEnd(_List, _Node) GlueIsNodeAtEnd(_List, _Node)
50 #define SwapListEntries(_FirstEntry, _SecondEntry) GlueSwapListEntries(_FirstEntry, _SecondEntry)
51 #define RemoveEntryList(_Entry) GlueRemoveEntryList(_Entry)
56 #define LShiftU64(_Op, _Count) GlueLShiftU64(_Op, _Count)
57 #define RShiftU64(_Op, _Count) GlueRShiftU64(_Op, _Count)
58 #define MultU64x32(_Multiplicand, _Multiplier) GlueMultU64x32(_Multiplicand, _Multiplier)
59 #define DivU64x32(_Dividend, _Divisor) GlueDivU64x32(_Dividend, _Divisor)
64 #define GetInterruptState() GlueGetInterruptState()
68 // Definitions for architecture specific types
69 // These include SPIN_LOCK and BASE_LIBRARY_JUMP_BUFFER
75 typedef volatile UINTN SPIN_LOCK
;
77 #if defined (MDE_CPU_IA32)
79 // IA32 context buffer used by SetJump() and LongJump()
88 } BASE_LIBRARY_JUMP_BUFFER
;
90 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
92 #elif defined (MDE_CPU_X64)
94 // X64 context buffer used by SetJump() and LongJump()
108 UINT8 XmmBuffer
[160]; ///< XMM6-XMM15.
109 } BASE_LIBRARY_JUMP_BUFFER
;
111 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
113 #elif defined (MDE_CPU_EBC)
115 // EBC context buffer used by SetJump() and LongJump()
123 } BASE_LIBRARY_JUMP_BUFFER
;
125 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
128 #error Unknown Processor Type
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 one Null-terminated Unicode string with a maximum length to another
168 Null-terminated Unicode string with a maximum length and returns the new
171 This function copies the contents of the Unicode string Source to the Unicode
172 string Destination, and returns Destination. At most, Length Unicode
173 characters are copied from Source to Destination. If Length is 0, then
174 Destination is returned unmodified. If Length is greater that the number of
175 Unicode characters in Source, then Destination is padded with Null Unicode
176 characters. If Source and Destination overlap, then the results are
179 If Length > 0 and Destination is NULL, then ASSERT().
180 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
181 If Length > 0 and Source is NULL, then ASSERT().
182 If Length > 0 and Source is not aligned on a 16-bit bounadry, then ASSERT().
183 If Source and Destination overlap, then ASSERT().
184 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
185 PcdMaximumUnicodeStringLength, then ASSERT().
186 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
187 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
190 @param Destination Pointer to a Null-terminated Unicode string.
191 @param Source Pointer to a Null-terminated Unicode string.
192 @param Length Maximum number of Unicode characters to copy.
200 OUT CHAR16
*Destination
,
201 IN CONST CHAR16
*Source
,
207 Returns the length of a Null-terminated Unicode string.
209 This function returns the number of Unicode characters in the Null-terminated
210 Unicode string specified by String.
212 If String is NULL, then ASSERT().
213 If String is not aligned on a 16-bit boundary, then ASSERT().
214 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
215 PcdMaximumUnicodeStringLength Unicode characters not including the
216 Null-terminator, then ASSERT().
218 @param String Pointer to a Null-terminated Unicode string.
220 @return The length of String.
226 IN CONST CHAR16
*String
231 Returns the size of a Null-terminated Unicode string in bytes, including the
234 This function returns the size, in bytes, of the Null-terminated Unicode
235 string specified by String.
237 If String is NULL, then ASSERT().
238 If String is not aligned on a 16-bit boundary, then ASSERT().
239 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
240 PcdMaximumUnicodeStringLength Unicode characters not including the
241 Null-terminator, then ASSERT().
243 @param String Pointer to a Null-terminated Unicode string.
245 @return The size of String.
251 IN CONST CHAR16
*String
256 Compares two Null-terminated Unicode strings, and returns the difference
257 between the first mismatched Unicode characters.
259 This function compares the Null-terminated Unicode string FirstString to the
260 Null-terminated Unicode string SecondString. If FirstString is identical to
261 SecondString, then 0 is returned. Otherwise, the value returned is the first
262 mismatched Unicode character in SecondString subtracted from the first
263 mismatched Unicode character in FirstString.
265 If FirstString is NULL, then ASSERT().
266 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
267 If SecondString is NULL, then ASSERT().
268 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
269 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
270 than PcdMaximumUnicodeStringLength Unicode characters not including the
271 Null-terminator, then ASSERT().
272 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
273 than PcdMaximumUnicodeStringLength Unicode characters not including the
274 Null-terminator, then ASSERT().
276 @param FirstString Pointer to a Null-terminated Unicode string.
277 @param SecondString Pointer to a Null-terminated Unicode string.
279 @retval 0 FirstString is identical to SecondString.
280 @retval !=0 FirstString is not identical to SecondString.
286 IN CONST CHAR16
*FirstString
,
287 IN CONST CHAR16
*SecondString
292 Compares two Null-terminated Unicode strings with maximum lengths, and
293 returns the difference between the first mismatched Unicode characters.
295 This function compares the Null-terminated Unicode string FirstString to the
296 Null-terminated Unicode string SecondString. At most, Length Unicode
297 characters will be compared. If Length is 0, then 0 is returned. If
298 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
299 value returned is the first mismatched Unicode character in SecondString
300 subtracted from the first mismatched Unicode character in FirstString.
302 If Length > 0 and FirstString is NULL, then ASSERT().
303 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().
304 If Length > 0 and SecondString is NULL, then ASSERT().
305 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().
306 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
307 PcdMaximumUnicodeStringLength, then ASSERT().
308 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than
309 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
311 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than
312 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
315 @param FirstString Pointer to a Null-terminated Unicode string.
316 @param SecondString Pointer to a Null-terminated Unicode string.
317 @param Length Maximum number of Unicode characters to compare.
319 @retval 0 FirstString is identical to SecondString.
320 @retval !=0 FirstString is not identical to SecondString.
326 IN CONST CHAR16
*FirstString
,
327 IN CONST CHAR16
*SecondString
,
333 Concatenates one Null-terminated Unicode string to another Null-terminated
334 Unicode string, and returns the concatenated Unicode string.
336 This function concatenates two Null-terminated Unicode strings. The contents
337 of Null-terminated Unicode string Source are concatenated to the end of
338 Null-terminated Unicode string Destination. The Null-terminated concatenated
339 Unicode String is returned. If Source and Destination overlap, then the
340 results are undefined.
342 If Destination is NULL, then ASSERT().
343 If Destination is not aligned on a 16-bit bounadary, then ASSERT().
344 If Source is NULL, then ASSERT().
345 If Source is not aligned on a 16-bit bounadary, then ASSERT().
346 If Source and Destination overlap, then ASSERT().
347 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
348 than PcdMaximumUnicodeStringLength Unicode characters not including the
349 Null-terminator, then ASSERT().
350 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
351 PcdMaximumUnicodeStringLength Unicode characters not including the
352 Null-terminator, then ASSERT().
353 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
354 and Source results in a Unicode string with more than
355 PcdMaximumUnicodeStringLength Unicode characters not including the
356 Null-terminator, then ASSERT().
358 @param Destination Pointer to a Null-terminated Unicode string.
359 @param Source Pointer to a Null-terminated Unicode string.
367 IN OUT CHAR16
*Destination
,
368 IN CONST CHAR16
*Source
373 Concatenates one Null-terminated Unicode string with a maximum length to the
374 end of another Null-terminated Unicode string, and returns the concatenated
377 This function concatenates two Null-terminated Unicode strings. The contents
378 of Null-terminated Unicode string Source are concatenated to the end of
379 Null-terminated Unicode string Destination, and Destination is returned. At
380 most, Length Unicode characters are concatenated from Source to the end of
381 Destination, and Destination is always Null-terminated. If Length is 0, then
382 Destination is returned unmodified. If Source and Destination overlap, then
383 the results are undefined.
385 If Destination is NULL, then ASSERT().
386 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
387 If Length > 0 and Source is NULL, then ASSERT().
388 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
389 If Source and Destination overlap, then ASSERT().
390 If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
391 PcdMaximumUnicodeStringLength, then ASSERT().
392 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
393 than PcdMaximumUnicodeStringLength Unicode characters, not including the
394 Null-terminator, then ASSERT().
395 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
396 PcdMaximumUnicodeStringLength Unicode characters, not including the
397 Null-terminator, then ASSERT().
398 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
399 and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength
400 Unicode characters, not including the Null-terminator, then ASSERT().
402 @param Destination Pointer to a Null-terminated Unicode string.
403 @param Source Pointer to a Null-terminated Unicode string.
404 @param Length Maximum number of Unicode characters to concatenate from
413 IN OUT CHAR16
*Destination
,
414 IN CONST CHAR16
*Source
,
419 Returns the first occurance of a Null-terminated Unicode sub-string
420 in a Null-terminated Unicode string.
422 This function scans the contents of the Null-terminated Unicode string
423 specified by String and returns the first occurrence of SearchString.
424 If SearchString is not found in String, then NULL is returned. If
425 the length of SearchString is zero, then String is
428 If String is NULL, then ASSERT().
429 If String is not aligned on a 16-bit boundary, then ASSERT().
430 If SearchString is NULL, then ASSERT().
431 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
433 If PcdMaximumUnicodeStringLength is not zero, and SearchString
434 or String contains more than PcdMaximumUnicodeStringLength Unicode
435 characters not including the Null-terminator, then ASSERT().
437 @param String Pointer to a Null-terminated Unicode string.
438 @param SearchString Pointer to a Null-terminated Unicode string to search for.
440 @retval NULL If the SearchString does not appear in String.
441 @retval !NULL If there is a match.
447 IN CONST CHAR16
*String
,
448 IN CONST CHAR16
*SearchString
452 Convert a Null-terminated Unicode decimal string to a value of
455 This function returns a value of type UINTN by interpreting the contents
456 of the Unicode string specified by String as a decimal number. The format
457 of the input Unicode string String is:
459 [spaces] [decimal digits].
461 The valid decimal digit character is in the range [0-9]. The
462 function will ignore the pad space, which includes spaces or
463 tab characters, before [decimal digits]. The running zero in the
464 beginning of [decimal digits] will be ignored. Then, the function
465 stops at the first character that is a not a valid decimal character
466 or a Null-terminator, whichever one comes first.
468 If String is NULL, then ASSERT().
469 If String is not aligned in a 16-bit boundary, then ASSERT().
470 If String has only pad spaces, then 0 is returned.
471 If String has no pad spaces or valid decimal digits,
473 If the number represented by String overflows according
474 to the range defined by UINTN, then ASSERT().
476 If PcdMaximumUnicodeStringLength is not zero, and String contains
477 more than PcdMaximumUnicodeStringLength Unicode characters not including
478 the Null-terminator, then ASSERT().
480 @param String Pointer to a Null-terminated Unicode string.
488 IN CONST CHAR16
*String
492 Convert a Null-terminated Unicode decimal string to a value of
495 This function returns a value of type UINT64 by interpreting the contents
496 of the Unicode string specified by String as a decimal number. The format
497 of the input Unicode string String is:
499 [spaces] [decimal digits].
501 The valid decimal digit character is in the range [0-9]. The
502 function will ignore the pad space, which includes spaces or
503 tab characters, before [decimal digits]. The running zero in the
504 beginning of [decimal digits] will be ignored. Then, the function
505 stops at the first character that is a not a valid decimal character
506 or a Null-terminator, whichever one comes first.
508 If String is NULL, then ASSERT().
509 If String is not aligned in a 16-bit boundary, then ASSERT().
510 If String has only pad spaces, then 0 is returned.
511 If String has no pad spaces or valid decimal digits,
513 If the number represented by String overflows according
514 to the range defined by UINT64, then ASSERT().
516 If PcdMaximumUnicodeStringLength is not zero, and String contains
517 more than PcdMaximumUnicodeStringLength Unicode characters not including
518 the Null-terminator, then ASSERT().
520 @param String Pointer to a Null-terminated Unicode string.
528 IN CONST CHAR16
*String
533 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
535 This function returns a value of type UINTN by interpreting the contents
536 of the Unicode string specified by String as a hexadecimal number.
537 The format of the input Unicode string String is:
539 [spaces][zeros][x][hexadecimal digits].
541 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
542 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
543 If "x" appears in the input string, it must be prefixed with at least one 0.
544 The function will ignore the pad space, which includes spaces or tab characters,
545 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
546 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
547 first valid hexadecimal digit. Then, the function stops at the first character that is
548 a not a valid hexadecimal character or NULL, whichever one comes first.
550 If String is NULL, then ASSERT().
551 If String is not aligned in a 16-bit boundary, then ASSERT().
552 If String has only pad spaces, then zero is returned.
553 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
554 then zero is returned.
555 If the number represented by String overflows according to the range defined by
556 UINTN, then ASSERT().
558 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
559 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
562 @param String Pointer to a Null-terminated Unicode string.
570 IN CONST CHAR16
*String
575 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
577 This function returns a value of type UINT64 by interpreting the contents
578 of the Unicode string specified by String as a hexadecimal number.
579 The format of the input Unicode string String is
581 [spaces][zeros][x][hexadecimal digits].
583 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
584 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
585 If "x" appears in the input string, it must be prefixed with at least one 0.
586 The function will ignore the pad space, which includes spaces or tab characters,
587 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
588 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
589 first valid hexadecimal digit. Then, the function stops at the first character that is
590 a not a valid hexadecimal character or NULL, whichever one comes first.
592 If String is NULL, then ASSERT().
593 If String is not aligned in a 16-bit boundary, then ASSERT().
594 If String has only pad spaces, then zero is returned.
595 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
596 then zero is returned.
597 If the number represented by String overflows according to the range defined by
598 UINT64, then ASSERT().
600 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
601 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
604 @param String Pointer to a Null-terminated Unicode string.
612 IN CONST CHAR16
*String
617 Convert one Null-terminated Unicode string to a Null-terminated
618 ASCII string and returns the ASCII string.
620 This function converts the content of the Unicode string Source
621 to the ASCII string Destination by copying the lower 8 bits of
622 each Unicode character. It returns Destination.
624 If any Unicode characters in Source contain non-zero value in
625 the upper 8 bits, then ASSERT().
627 If Destination is NULL, then ASSERT().
628 If Source is NULL, then ASSERT().
629 If Source is not aligned on a 16-bit boundary, then ASSERT().
630 If Source and Destination overlap, then ASSERT().
632 If PcdMaximumUnicodeStringLength is not zero, and Source contains
633 more than PcdMaximumUnicodeStringLength Unicode characters not including
634 the Null-terminator, then ASSERT().
636 If PcdMaximumAsciiStringLength is not zero, and Source contains more
637 than PcdMaximumAsciiStringLength Unicode characters not including the
638 Null-terminator, then ASSERT().
640 @param Source Pointer to a Null-terminated Unicode string.
641 @param Destination Pointer to a Null-terminated ASCII string.
648 UnicodeStrToAsciiStr (
649 IN CONST CHAR16
*Source
,
650 OUT CHAR8
*Destination
655 Copies one Null-terminated ASCII string to another Null-terminated ASCII
656 string and returns the new ASCII string.
658 This function copies the contents of the ASCII string Source to the ASCII
659 string Destination, and returns Destination. If Source and Destination
660 overlap, then the results are undefined.
662 If Destination is NULL, then ASSERT().
663 If Source is NULL, then ASSERT().
664 If Source and Destination overlap, then ASSERT().
665 If PcdMaximumAsciiStringLength is not zero and Source contains more than
666 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
669 @param Destination Pointer to a Null-terminated ASCII string.
670 @param Source Pointer to a Null-terminated ASCII string.
678 OUT CHAR8
*Destination
,
679 IN CONST CHAR8
*Source
684 Copies one Null-terminated ASCII string with a maximum length to another
685 Null-terminated ASCII string with a maximum length and returns the new ASCII
688 This function copies the contents of the ASCII string Source to the ASCII
689 string Destination, and returns Destination. At most, Length ASCII characters
690 are copied from Source to Destination. If Length is 0, then Destination is
691 returned unmodified. If Length is greater that the number of ASCII characters
692 in Source, then Destination is padded with Null ASCII characters. If Source
693 and Destination overlap, then the results are undefined.
695 If Destination is NULL, then ASSERT().
696 If Source is NULL, then ASSERT().
697 If Source and Destination overlap, then ASSERT().
698 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
699 PcdMaximumAsciiStringLength, then ASSERT().
700 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
701 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
704 @param Destination Pointer to a Null-terminated ASCII string.
705 @param Source Pointer to a Null-terminated ASCII string.
706 @param Length Maximum number of ASCII characters to copy.
714 OUT CHAR8
*Destination
,
715 IN CONST CHAR8
*Source
,
721 Returns the length of a Null-terminated ASCII string.
723 This function returns the number of ASCII characters in the Null-terminated
724 ASCII string specified by String.
726 If Length > 0 and Destination is NULL, then ASSERT().
727 If Length > 0 and Source is NULL, then ASSERT().
728 If PcdMaximumAsciiStringLength is not zero and String contains more than
729 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
732 @param String Pointer to a Null-terminated ASCII string.
734 @return The length of String.
740 IN CONST CHAR8
*String
745 Returns the size of a Null-terminated ASCII string in bytes, including the
748 This function returns the size, in bytes, of the Null-terminated ASCII string
751 If String is NULL, then ASSERT().
752 If PcdMaximumAsciiStringLength is not zero and String contains more than
753 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
756 @param String Pointer to a Null-terminated ASCII string.
758 @return The size of String.
764 IN CONST CHAR8
*String
769 Compares two Null-terminated ASCII strings, and returns the difference
770 between the first mismatched ASCII characters.
772 This function compares the Null-terminated ASCII string FirstString to the
773 Null-terminated ASCII string SecondString. If FirstString is identical to
774 SecondString, then 0 is returned. Otherwise, the value returned is the first
775 mismatched ASCII character in SecondString subtracted from the first
776 mismatched ASCII character in FirstString.
778 If FirstString is NULL, then ASSERT().
779 If SecondString is NULL, then ASSERT().
780 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
781 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
783 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
784 than PcdMaximumAsciiStringLength ASCII characters not including the
785 Null-terminator, then ASSERT().
787 @param FirstString Pointer to a Null-terminated ASCII string.
788 @param SecondString Pointer to a Null-terminated ASCII string.
790 @retval 0 FirstString is identical to SecondString.
791 @retval !=0 FirstString is not identical to SecondString.
797 IN CONST CHAR8
*FirstString
,
798 IN CONST CHAR8
*SecondString
803 Performs a case insensitive comparison of two Null-terminated ASCII strings,
804 and returns the difference between the first mismatched ASCII characters.
806 This function performs a case insensitive comparison of the Null-terminated
807 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
808 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
809 value returned is the first mismatched lower case ASCII character in
810 SecondString subtracted from the first mismatched lower case ASCII character
813 If FirstString is NULL, then ASSERT().
814 If SecondString is NULL, then ASSERT().
815 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
816 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
818 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
819 than PcdMaximumAsciiStringLength ASCII characters not including the
820 Null-terminator, then ASSERT().
822 @param FirstString Pointer to a Null-terminated ASCII string.
823 @param SecondString Pointer to a Null-terminated ASCII string.
825 @retval 0 FirstString is identical to SecondString using case insensitive
827 @retval !=0 FirstString is not identical to SecondString using case
828 insensitive comparisons.
834 IN CONST CHAR8
*FirstString
,
835 IN CONST CHAR8
*SecondString
840 Compares two Null-terminated ASCII strings with maximum lengths, and returns
841 the difference between the first mismatched ASCII characters.
843 This function compares the Null-terminated ASCII string FirstString to the
844 Null-terminated ASCII string SecondString. At most, Length ASCII characters
845 will be compared. If Length is 0, then 0 is returned. If FirstString is
846 identical to SecondString, then 0 is returned. Otherwise, the value returned
847 is the first mismatched ASCII character in SecondString subtracted from the
848 first mismatched ASCII character in FirstString.
850 If Length > 0 and FirstString is NULL, then ASSERT().
851 If Length > 0 and SecondString is NULL, then ASSERT().
852 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
853 PcdMaximumAsciiStringLength, then ASSERT().
854 If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than
855 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
857 If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than
858 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
861 @param FirstString Pointer to a Null-terminated ASCII string.
862 @param SecondString Pointer to a Null-terminated ASCII string.
864 @retval 0 FirstString is identical to SecondString.
865 @retval !=0 FirstString is not identical to SecondString.
871 IN CONST CHAR8
*FirstString
,
872 IN CONST CHAR8
*SecondString
,
878 Concatenates one Null-terminated ASCII string to another Null-terminated
879 ASCII string, and returns the concatenated ASCII string.
881 This function concatenates two Null-terminated ASCII strings. The contents of
882 Null-terminated ASCII string Source are concatenated to the end of Null-
883 terminated ASCII string Destination. The Null-terminated concatenated ASCII
886 If Destination is NULL, then ASSERT().
887 If Source is NULL, then ASSERT().
888 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
889 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
891 If PcdMaximumAsciiStringLength is not zero and Source contains more than
892 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
894 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
895 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
896 ASCII characters, then ASSERT().
898 @param Destination Pointer to a Null-terminated ASCII string.
899 @param Source Pointer to a Null-terminated ASCII string.
907 IN OUT CHAR8
*Destination
,
908 IN CONST CHAR8
*Source
913 Concatenates one Null-terminated ASCII string with a maximum length to the
914 end of another Null-terminated ASCII string, and returns the concatenated
917 This function concatenates two Null-terminated ASCII strings. The contents
918 of Null-terminated ASCII string Source are concatenated to the end of Null-
919 terminated ASCII string Destination, and Destination is returned. At most,
920 Length ASCII characters are concatenated from Source to the end of
921 Destination, and Destination is always Null-terminated. If Length is 0, then
922 Destination is returned unmodified. If Source and Destination overlap, then
923 the results are undefined.
925 If Length > 0 and Destination is NULL, then ASSERT().
926 If Length > 0 and Source is NULL, then ASSERT().
927 If Source and Destination overlap, then ASSERT().
928 If PcdMaximumAsciiStringLength is not zero, and Length is greater than
929 PcdMaximumAsciiStringLength, then ASSERT().
930 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
931 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
933 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
934 PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
936 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
937 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
938 ASCII characters, not including the Null-terminator, then ASSERT().
940 @param Destination Pointer to a Null-terminated ASCII string.
941 @param Source Pointer to a Null-terminated ASCII string.
942 @param Length Maximum number of ASCII characters to concatenate from
951 IN OUT CHAR8
*Destination
,
952 IN CONST CHAR8
*Source
,
958 Returns the first occurance of a Null-terminated ASCII sub-string
959 in a Null-terminated ASCII string.
961 This function scans the contents of the ASCII string specified by String
962 and returns the first occurrence of SearchString. If SearchString is not
963 found in String, then NULL is returned. If the length of SearchString is zero,
964 then String is returned.
966 If String is NULL, then ASSERT().
967 If SearchString is NULL, then ASSERT().
969 If PcdMaximumAsciiStringLength is not zero, and SearchString or
970 String contains more than PcdMaximumAsciiStringLength Unicode characters
971 not including the Null-terminator, then ASSERT().
973 @param String Pointer to a Null-terminated ASCII string.
974 @param SearchString Pointer to a Null-terminated ASCII string to search for.
976 @retval NULL If the SearchString does not appear in String.
977 @retval !NULL If there is a match.
983 IN CONST CHAR8
*String
,
984 IN CONST CHAR8
*SearchString
989 Convert a Null-terminated ASCII decimal string to a value of type
992 This function returns a value of type UINTN by interpreting the contents
993 of the ASCII string String as a decimal number. The format of the input
994 ASCII string String is:
996 [spaces] [decimal digits].
998 The valid decimal digit character is in the range [0-9]. The function will
999 ignore the pad space, which includes spaces or tab characters, before the digits.
1000 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1001 function stops at the first character that is a not a valid decimal character or
1002 Null-terminator, whichever on comes first.
1004 If String has only pad spaces, then 0 is returned.
1005 If String has no pad spaces or valid decimal digits, then 0 is returned.
1006 If the number represented by String overflows according to the range defined by
1007 UINTN, then ASSERT().
1008 If String is NULL, then ASSERT().
1009 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1010 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1013 @param String Pointer to a Null-terminated ASCII string.
1020 AsciiStrDecimalToUintn (
1021 IN CONST CHAR8
*String
1026 Convert a Null-terminated ASCII decimal string to a value of type
1029 This function returns a value of type UINT64 by interpreting the contents
1030 of the ASCII string String as a decimal number. The format of the input
1031 ASCII string String is:
1033 [spaces] [decimal digits].
1035 The valid decimal digit character is in the range [0-9]. The function will
1036 ignore the pad space, which includes spaces or tab characters, before the digits.
1037 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1038 function stops at the first character that is a not a valid decimal character or
1039 Null-terminator, whichever on comes first.
1041 If String has only pad spaces, then 0 is returned.
1042 If String has no pad spaces or valid decimal digits, then 0 is returned.
1043 If the number represented by String overflows according to the range defined by
1044 UINT64, then ASSERT().
1045 If String is NULL, then ASSERT().
1046 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1047 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1050 @param String Pointer to a Null-terminated ASCII string.
1057 AsciiStrDecimalToUint64 (
1058 IN CONST CHAR8
*String
1063 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1065 This function returns a value of type UINTN by interpreting the contents of
1066 the ASCII string String as a hexadecimal number. The format of the input ASCII
1069 [spaces][zeros][x][hexadecimal digits].
1071 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1072 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1073 appears in the input string, it must be prefixed with at least one 0. The function
1074 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1075 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1076 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1077 digit. Then, the function stops at the first character that is a not a valid
1078 hexadecimal character or Null-terminator, whichever on comes first.
1080 If String has only pad spaces, then 0 is returned.
1081 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1084 If the number represented by String overflows according to the range defined by UINTN,
1086 If String is NULL, then ASSERT().
1087 If PcdMaximumAsciiStringLength is not zero,
1088 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1089 the Null-terminator, then ASSERT().
1091 @param String Pointer to a Null-terminated ASCII string.
1098 AsciiStrHexToUintn (
1099 IN CONST CHAR8
*String
1104 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1106 This function returns a value of type UINT64 by interpreting the contents of
1107 the ASCII string String as a hexadecimal number. The format of the input ASCII
1110 [spaces][zeros][x][hexadecimal digits].
1112 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1113 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1114 appears in the input string, it must be prefixed with at least one 0. The function
1115 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1116 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1117 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1118 digit. Then, the function stops at the first character that is a not a valid
1119 hexadecimal character or Null-terminator, whichever on comes first.
1121 If String has only pad spaces, then 0 is returned.
1122 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1125 If the number represented by String overflows according to the range defined by UINT64,
1127 If String is NULL, then ASSERT().
1128 If PcdMaximumAsciiStringLength is not zero,
1129 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1130 the Null-terminator, then ASSERT().
1132 @param String Pointer to a Null-terminated ASCII string.
1139 AsciiStrHexToUint64 (
1140 IN CONST CHAR8
*String
1145 Convert one Null-terminated ASCII string to a Null-terminated
1146 Unicode string and returns the Unicode string.
1148 This function converts the contents of the ASCII string Source to the Unicode
1149 string Destination, and returns Destination. The function terminates the
1150 Unicode string Destination by appending a Null-terminator character at the end.
1151 The caller is responsible to make sure Destination points to a buffer with size
1152 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1154 If Destination is NULL, then ASSERT().
1155 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1156 If Source is NULL, then ASSERT().
1157 If Source and Destination overlap, then ASSERT().
1158 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1159 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1161 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1162 PcdMaximumUnicodeStringLength ASCII characters not including the
1163 Null-terminator, then ASSERT().
1165 @param Source Pointer to a Null-terminated ASCII string.
1166 @param Destination Pointer to a Null-terminated Unicode string.
1173 AsciiStrToUnicodeStr (
1174 IN CONST CHAR8
*Source
,
1175 OUT CHAR16
*Destination
1180 Converts an 8-bit value to an 8-bit BCD value.
1182 Converts the 8-bit value specified by Value to BCD. The BCD value is
1185 If Value >= 100, then ASSERT().
1187 @param Value The 8-bit value to convert to BCD. Range 0..99.
1189 @return The BCD value
1200 Converts an 8-bit BCD value to an 8-bit value.
1202 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
1205 If Value >= 0xA0, then ASSERT().
1206 If (Value & 0x0F) >= 0x0A, then ASSERT().
1208 @param Value The 8-bit BCD value to convert to an 8-bit value.
1210 @return The 8-bit value is returned.
1220 // LIST_ENTRY definition
1222 typedef struct _LIST_ENTRY LIST_ENTRY
;
1224 struct _LIST_ENTRY
{
1225 LIST_ENTRY
*ForwardLink
;
1226 LIST_ENTRY
*BackLink
;
1230 // Linked List Functions and Macros
1234 Initializes the head node of a doubly linked list that is declared as a
1235 global variable in a module.
1237 Initializes the forward and backward links of a new linked list. After
1238 initializing a linked list with this macro, the other linked list functions
1239 may be used to add and remove nodes from the linked list. This macro results
1240 in smaller executables by initializing the linked list in the data section,
1241 instead if calling the InitializeListHead() function to perform the
1242 equivalent operation.
1244 @param ListHead The head note of a list to initiailize.
1247 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
1251 Initializes the head node of a doubly linked list, and returns the pointer to
1252 the head node of the doubly linked list.
1254 Initializes the forward and backward links of a new linked list. After
1255 initializing a linked list with this function, the other linked list
1256 functions may be used to add and remove nodes from the linked list. It is up
1257 to the caller of this function to allocate the memory for ListHead.
1259 If ListHead is NULL, then ASSERT().
1261 @param ListHead A pointer to the head node of a new doubly linked list.
1268 GlueInitializeListHead (
1269 IN LIST_ENTRY
*ListHead
1274 Adds a node to the beginning of a doubly linked list, and returns the pointer
1275 to the head node of the doubly linked list.
1277 Adds the node Entry at the beginning of the doubly linked list denoted by
1278 ListHead, and returns ListHead.
1280 If ListHead is NULL, then ASSERT().
1281 If Entry is NULL, then ASSERT().
1282 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1283 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1284 of nodes in ListHead, including the ListHead node, is greater than or
1285 equal to PcdMaximumLinkedListLength, then ASSERT().
1287 @param ListHead A pointer to the head node of a doubly linked list.
1288 @param Entry A pointer to a node that is to be inserted at the beginning
1289 of a doubly linked list.
1296 GlueInsertHeadList (
1297 IN LIST_ENTRY
*ListHead
,
1298 IN LIST_ENTRY
*Entry
1303 Adds a node to the end of a doubly linked list, and returns the pointer to
1304 the head node of the doubly linked list.
1306 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
1307 and returns ListHead.
1309 If ListHead is NULL, then ASSERT().
1310 If Entry is NULL, then ASSERT().
1311 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1312 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1313 of nodes in ListHead, including the ListHead node, is greater than or
1314 equal to PcdMaximumLinkedListLength, then ASSERT().
1316 @param ListHead A pointer to the head node of a doubly linked list.
1317 @param Entry A pointer to a node that is to be added at the end of the
1325 GlueInsertTailList (
1326 IN LIST_ENTRY
*ListHead
,
1327 IN LIST_ENTRY
*Entry
1332 Retrieves the first node of a doubly linked list.
1334 Returns the first node of a doubly linked list. List must have been
1335 initialized with InitializeListHead(). If List is empty, then NULL is
1338 If List is NULL, then ASSERT().
1339 If List was not initialized with InitializeListHead(), then ASSERT().
1340 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1341 in List, including the List node, is greater than or equal to
1342 PcdMaximumLinkedListLength, then ASSERT().
1344 @param List A pointer to the head node of a doubly linked list.
1346 @return The first node of a doubly linked list.
1347 @retval NULL The list is empty.
1353 IN CONST LIST_ENTRY
*List
1358 Retrieves the next node of a doubly linked list.
1360 Returns the node of a doubly linked list that follows Node. List must have
1361 been initialized with InitializeListHead(). If List is empty, then List is
1364 If List is NULL, then ASSERT().
1365 If Node is NULL, then ASSERT().
1366 If List was not initialized with InitializeListHead(), then ASSERT().
1367 If PcdMaximumLinkedListLenth is not zero, and List contains more than
1368 PcdMaximumLinkedListLenth nodes, then ASSERT().
1369 If Node is not a node in List, then ASSERT().
1371 @param List A pointer to the head node of a doubly linked list.
1372 @param Node A pointer to a node in the doubly linked list.
1374 @return Pointer to the next node if one exists. Otherwise a null value which
1375 is actually List is returned.
1381 IN CONST LIST_ENTRY
*List
,
1382 IN CONST LIST_ENTRY
*Node
1387 Checks to see if a doubly linked list is empty or not.
1389 Checks to see if the doubly linked list is empty. If the linked list contains
1390 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
1392 If ListHead is NULL, then ASSERT().
1393 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1394 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1395 in List, including the List node, is greater than or equal to
1396 PcdMaximumLinkedListLength, then ASSERT().
1398 @param ListHead A pointer to the head node of a doubly linked list.
1400 @retval TRUE The linked list is empty.
1401 @retval FALSE The linked list is not empty.
1407 IN CONST LIST_ENTRY
*ListHead
1412 Determines if a node in a doubly linked list is null.
1414 Returns FALSE if Node is one of the nodes in the doubly linked list specified
1415 by List. Otherwise, TRUE is returned. List must have been initialized with
1416 InitializeListHead().
1418 If List is NULL, then ASSERT().
1419 If Node is NULL, then ASSERT().
1420 If List was not initialized with InitializeListHead(), then ASSERT().
1421 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1422 in List, including the List node, is greater than or equal to
1423 PcdMaximumLinkedListLength, then ASSERT().
1424 If Node is not a node in List and Node is not equal to List, then ASSERT().
1426 @param List A pointer to the head node of a doubly linked list.
1427 @param Node A pointer to a node in the doubly linked list.
1429 @retval TRUE Node is one of the nodes in the doubly linked list.
1430 @retval FALSE Node is not one of the nodes in the doubly linked list.
1436 IN CONST LIST_ENTRY
*List
,
1437 IN CONST LIST_ENTRY
*Node
1442 Determines if a node the last node in a doubly linked list.
1444 Returns TRUE if Node is the last node in the doubly linked list specified by
1445 List. Otherwise, FALSE is returned. List must have been initialized with
1446 InitializeListHead().
1448 If List is NULL, then ASSERT().
1449 If Node is NULL, then ASSERT().
1450 If List was not initialized with InitializeListHead(), then ASSERT().
1451 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1452 in List, including the List node, is greater than or equal to
1453 PcdMaximumLinkedListLength, then ASSERT().
1454 If Node is not a node in List, then ASSERT().
1456 @param List A pointer to the head node of a doubly linked list.
1457 @param Node A pointer to a node in the doubly linked list.
1459 @retval TRUE Node is the last node in the linked list.
1460 @retval FALSE Node is not the last node in the linked list.
1466 IN CONST LIST_ENTRY
*List
,
1467 IN CONST LIST_ENTRY
*Node
1472 Swaps the location of two nodes in a doubly linked list, and returns the
1473 first node after the swap.
1475 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
1476 Otherwise, the location of the FirstEntry node is swapped with the location
1477 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
1478 same double linked list as FirstEntry and that double linked list must have
1479 been initialized with InitializeListHead(). SecondEntry is returned after the
1482 If FirstEntry is NULL, then ASSERT().
1483 If SecondEntry is NULL, then ASSERT().
1484 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
1485 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1486 linked list containing the FirstEntry and SecondEntry nodes, including
1487 the FirstEntry and SecondEntry nodes, is greater than or equal to
1488 PcdMaximumLinkedListLength, then ASSERT().
1490 @param FirstEntry A pointer to a node in a linked list.
1491 @param SecondEntry A pointer to another node in the same linked list.
1496 GlueSwapListEntries (
1497 IN LIST_ENTRY
*FirstEntry
,
1498 IN LIST_ENTRY
*SecondEntry
1503 Removes a node from a doubly linked list, and returns the node that follows
1506 Removes the node Entry from a doubly linked list. It is up to the caller of
1507 this function to release the memory used by this node if that is required. On
1508 exit, the node following Entry in the doubly linked list is returned. If
1509 Entry is the only node in the linked list, then the head node of the linked
1512 If Entry is NULL, then ASSERT().
1513 If Entry is the head node of an empty list, then ASSERT().
1514 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1515 linked list containing Entry, including the Entry node, is greater than
1516 or equal to PcdMaximumLinkedListLength, then ASSERT().
1518 @param Entry A pointer to a node in a linked list
1525 GlueRemoveEntryList (
1526 IN CONST LIST_ENTRY
*Entry
1534 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
1535 with zeros. The shifted value is returned.
1537 This function shifts the 64-bit value Operand to the left by Count bits. The
1538 low Count bits are set to zero. The shifted value is returned.
1540 If Count is greater than 63, then ASSERT().
1542 @param Operand The 64-bit operand to shift left.
1543 @param Count The number of bits to shift left.
1545 @return Operand << Count
1557 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1558 filled with zeros. The shifted value is returned.
1560 This function shifts the 64-bit value Operand to the right by Count bits. The
1561 high Count bits are set to zero. The shifted value is returned.
1563 If Count is greater than 63, then ASSERT().
1565 @param Operand The 64-bit operand to shift right.
1566 @param Count The number of bits to shift right.
1568 @return Operand >> Count
1580 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1581 with original integer's bit 63. The shifted value is returned.
1583 This function shifts the 64-bit value Operand to the right by Count bits. The
1584 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1586 If Count is greater than 63, then ASSERT().
1588 @param Operand The 64-bit operand to shift right.
1589 @param Count The number of bits to shift right.
1591 @return Operand >> Count
1603 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1604 with the high bits that were rotated.
1606 This function rotates the 32-bit value Operand to the left by Count bits. The
1607 low Count bits are fill with the high Count bits of Operand. The rotated
1610 If Count is greater than 31, then ASSERT().
1612 @param Operand The 32-bit operand to rotate left.
1613 @param Count The number of bits to rotate left.
1615 @return Operand <<< Count
1627 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1628 with the low bits that were rotated.
1630 This function rotates the 32-bit value Operand to the right by Count bits.
1631 The high Count bits are fill with the low Count bits of Operand. The rotated
1634 If Count is greater than 31, then ASSERT().
1636 @param Operand The 32-bit operand to rotate right.
1637 @param Count The number of bits to rotate right.
1639 @return Operand >>> Count
1651 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1652 with the high bits that were rotated.
1654 This function rotates the 64-bit value Operand to the left by Count bits. The
1655 low Count bits are fill with the high Count bits of Operand. The rotated
1658 If Count is greater than 63, then ASSERT().
1660 @param Operand The 64-bit operand to rotate left.
1661 @param Count The number of bits to rotate left.
1663 @return Operand <<< Count
1675 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1676 with the high low bits that were rotated.
1678 This function rotates the 64-bit value Operand to the right by Count bits.
1679 The high Count bits are fill with the low Count bits of Operand. The rotated
1682 If Count is greater than 63, then ASSERT().
1684 @param Operand The 64-bit operand to rotate right.
1685 @param Count The number of bits to rotate right.
1687 @return Operand >>> Count
1699 Returns the bit position of the lowest bit set in a 32-bit value.
1701 This function computes the bit position of the lowest bit set in the 32-bit
1702 value specified by Operand. If Operand is zero, then -1 is returned.
1703 Otherwise, a value between 0 and 31 is returned.
1705 @param Operand The 32-bit operand to evaluate.
1707 @return Position of the lowest bit set in Operand if found.
1708 @retval -1 Operand is zero.
1719 Returns the bit position of the lowest bit set in a 64-bit value.
1721 This function computes the bit position of the lowest bit set in the 64-bit
1722 value specified by Operand. If Operand is zero, then -1 is returned.
1723 Otherwise, a value between 0 and 63 is returned.
1725 @param Operand The 64-bit operand to evaluate.
1727 @return Position of the lowest bit set in Operand if found.
1728 @retval -1 Operand is zero.
1739 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1742 This function computes the bit position of the highest bit set in the 32-bit
1743 value specified by Operand. If Operand is zero, then -1 is returned.
1744 Otherwise, a value between 0 and 31 is returned.
1746 @param Operand The 32-bit operand to evaluate.
1748 @return Position of the highest bit set in Operand if found.
1749 @retval -1 Operand is zero.
1760 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1763 This function computes the bit position of the highest bit set in the 64-bit
1764 value specified by Operand. If Operand is zero, then -1 is returned.
1765 Otherwise, a value between 0 and 63 is returned.
1767 @param Operand The 64-bit operand to evaluate.
1769 @return Position of the highest bit set in Operand if found.
1770 @retval -1 Operand is zero.
1781 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1782 1 << HighBitSet32(x).
1784 This function computes the value of the highest bit set in the 32-bit value
1785 specified by Operand. If Operand is zero, then zero is returned.
1787 @param Operand The 32-bit operand to evaluate.
1789 @return 1 << HighBitSet32(Operand)
1790 @retval 0 Operand is zero.
1801 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1802 1 << HighBitSet64(x).
1804 This function computes the value of the highest bit set in the 64-bit value
1805 specified by Operand. If Operand is zero, then zero is returned.
1807 @param Operand The 64-bit operand to evaluate.
1809 @return 1 << HighBitSet64(Operand)
1810 @retval 0 Operand is zero.
1821 Switches the endianess of a 16-bit integer.
1823 This function swaps the bytes in a 16-bit unsigned value to switch the value
1824 from little endian to big endian or vice versa. The byte swapped value is
1827 @param Operand A 16-bit unsigned value.
1829 @return The byte swaped Operand.
1840 Switches the endianess of a 32-bit integer.
1842 This function swaps the bytes in a 32-bit unsigned value to switch the value
1843 from little endian to big endian or vice versa. The byte swapped value is
1846 @param Operand A 32-bit unsigned value.
1848 @return The byte swaped Operand.
1859 Switches the endianess of a 64-bit integer.
1861 This function swaps the bytes in a 64-bit unsigned value to switch the value
1862 from little endian to big endian or vice versa. The byte swapped value is
1865 @param Operand A 64-bit unsigned value.
1867 @return The byte swaped Operand.
1878 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1879 generates a 64-bit unsigned result.
1881 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1882 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1883 bit unsigned result is returned.
1885 If the result overflows, then ASSERT().
1887 @param Multiplicand A 64-bit unsigned value.
1888 @param Multiplier A 32-bit unsigned value.
1890 @return Multiplicand * Multiplier
1896 IN UINT64 Multiplicand
,
1897 IN UINT32 Multiplier
1902 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1903 generates a 64-bit unsigned result.
1905 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1906 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1907 bit unsigned result is returned.
1909 If the result overflows, then ASSERT().
1911 @param Multiplicand A 64-bit unsigned value.
1912 @param Multiplier A 64-bit unsigned value.
1914 @return Multiplicand * Multiplier
1920 IN UINT64 Multiplicand
,
1921 IN UINT64 Multiplier
1926 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1927 64-bit signed result.
1929 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1930 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1931 signed result is returned.
1933 If the result overflows, then ASSERT().
1935 @param Multiplicand A 64-bit signed value.
1936 @param Multiplier A 64-bit signed value.
1938 @return Multiplicand * Multiplier
1944 IN INT64 Multiplicand
,
1950 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1951 a 64-bit unsigned result.
1953 This function divides the 64-bit unsigned value Dividend by the 32-bit
1954 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1955 function returns the 64-bit unsigned quotient.
1957 If Divisor is 0, then ASSERT().
1959 @param Dividend A 64-bit unsigned value.
1960 @param Divisor A 32-bit unsigned value.
1962 @return Dividend / Divisor
1974 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1975 a 32-bit unsigned remainder.
1977 This function divides the 64-bit unsigned value Dividend by the 32-bit
1978 unsigned value Divisor and generates a 32-bit remainder. This function
1979 returns the 32-bit unsigned remainder.
1981 If Divisor is 0, then ASSERT().
1983 @param Dividend A 64-bit unsigned value.
1984 @param Divisor A 32-bit unsigned value.
1986 @return Dividend % Divisor
1998 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1999 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
2001 This function divides the 64-bit unsigned value Dividend by the 32-bit
2002 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2003 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
2004 This function returns the 64-bit unsigned quotient.
2006 If Divisor is 0, then ASSERT().
2008 @param Dividend A 64-bit unsigned value.
2009 @param Divisor A 32-bit unsigned value.
2010 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
2011 optional and may be NULL.
2013 @return Dividend / Divisor
2018 DivU64x32Remainder (
2021 OUT UINT32
*Remainder OPTIONAL
2026 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
2027 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
2029 This function divides the 64-bit unsigned value Dividend by the 64-bit
2030 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2031 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
2032 This function returns the 64-bit unsigned quotient.
2034 If Divisor is 0, then ASSERT().
2036 @param Dividend A 64-bit unsigned value.
2037 @param Divisor A 64-bit unsigned value.
2038 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
2039 optional and may be NULL.
2041 @return Dividend / Divisor
2046 DivU64x64Remainder (
2049 OUT UINT64
*Remainder OPTIONAL
2054 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
2055 64-bit signed result and a optional 64-bit signed remainder.
2057 This function divides the 64-bit signed value Dividend by the 64-bit signed
2058 value Divisor and generates a 64-bit signed quotient. If Remainder is not
2059 NULL, then the 64-bit signed remainder is returned in Remainder. This
2060 function returns the 64-bit signed quotient.
2062 If Divisor is 0, then ASSERT().
2064 @param Dividend A 64-bit signed value.
2065 @param Divisor A 64-bit signed value.
2066 @param Remainder A pointer to a 64-bit signed value. This parameter is
2067 optional and may be NULL.
2069 @return Dividend / Divisor
2074 DivS64x64Remainder (
2077 OUT INT64
*Remainder OPTIONAL
2082 Reads a 16-bit value from memory that may be unaligned.
2084 This function returns the 16-bit value pointed to by Buffer. The function
2085 guarantees that the read operation does not produce an alignment fault.
2087 If the Buffer is NULL, then ASSERT().
2089 @param Buffer Pointer to a 16-bit value that may be unaligned.
2097 IN CONST UINT16
*Uint16
2102 Writes a 16-bit value to memory that may be unaligned.
2104 This function writes the 16-bit value specified by Value to Buffer. Value is
2105 returned. The function guarantees that the write operation does not produce
2108 If the Buffer is NULL, then ASSERT().
2110 @param Buffer Pointer to a 16-bit value that may be unaligned.
2111 @param Value 16-bit value to write to Buffer.
2125 Reads a 24-bit value from memory that may be unaligned.
2127 This function returns the 24-bit value pointed to by Buffer. The function
2128 guarantees that the read operation does not produce an alignment fault.
2130 If the Buffer is NULL, then ASSERT().
2132 @param Buffer Pointer to a 24-bit value that may be unaligned.
2134 @return The value read.
2140 IN CONST UINT32
*Buffer
2145 Writes a 24-bit value to memory that may be unaligned.
2147 This function writes the 24-bit value specified by Value to Buffer. Value is
2148 returned. The function guarantees that the write operation does not produce
2151 If the Buffer is NULL, then ASSERT().
2153 @param Buffer Pointer to a 24-bit value that may be unaligned.
2154 @param Value 24-bit value to write to Buffer.
2156 @return The value written.
2168 Reads a 32-bit value from memory that may be unaligned.
2170 This function returns the 32-bit value pointed to by Buffer. The function
2171 guarantees that the read operation does not produce an alignment fault.
2173 If the Buffer is NULL, then ASSERT().
2175 @param Buffer Pointer to a 32-bit value that may be unaligned.
2183 IN CONST UINT32
*Uint32
2188 Writes a 32-bit value to memory that may be unaligned.
2190 This function writes the 32-bit value specified by Value to Buffer. Value is
2191 returned. The function guarantees that the write operation does not produce
2194 If the Buffer is NULL, then ASSERT().
2196 @param Buffer Pointer to a 32-bit value that may be unaligned.
2197 @param Value 32-bit value to write to Buffer.
2211 Reads a 64-bit value from memory that may be unaligned.
2213 This function returns the 64-bit value pointed to by Buffer. The function
2214 guarantees that the read operation does not produce an alignment fault.
2216 If the Buffer is NULL, then ASSERT().
2218 @param Buffer Pointer to a 64-bit value that may be unaligned.
2226 IN CONST UINT64
*Uint64
2231 Writes a 64-bit value to memory that may be unaligned.
2233 This function writes the 64-bit value specified by Value to Buffer. Value is
2234 returned. The function guarantees that the write operation does not produce
2237 If the Buffer is NULL, then ASSERT().
2239 @param Buffer Pointer to a 64-bit value that may be unaligned.
2240 @param Value 64-bit value to write to Buffer.
2254 // Bit Field Functions
2258 Returns a bit field from an 8-bit value.
2260 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2262 If 8-bit operations are not supported, then ASSERT().
2263 If StartBit is greater than 7, then ASSERT().
2264 If EndBit is greater than 7, then ASSERT().
2265 If EndBit is less than StartBit, then ASSERT().
2267 @param Operand Operand on which to perform the bitfield operation.
2268 @param StartBit The ordinal of the least significant bit in the bit field.
2270 @param EndBit The ordinal of the most significant bit in the bit field.
2273 @return The bit field read.
2286 Writes a bit field to an 8-bit value, and returns the result.
2288 Writes Value to the bit field specified by the StartBit and the EndBit in
2289 Operand. All other bits in Operand are preserved. The new 8-bit value is
2292 If 8-bit operations are not supported, then ASSERT().
2293 If StartBit is greater than 7, then ASSERT().
2294 If EndBit is greater than 7, then ASSERT().
2295 If EndBit is less than StartBit, then ASSERT().
2297 @param Operand Operand on which to perform the bitfield operation.
2298 @param StartBit The ordinal of the least significant bit in the bit field.
2300 @param EndBit The ordinal of the most significant bit in the bit field.
2302 @param Value New value of the bit field.
2304 @return The new 8-bit value.
2318 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
2321 Performs a bitwise inclusive OR between the bit field specified by StartBit
2322 and EndBit in Operand and the value specified by OrData. All other bits in
2323 Operand are preserved. The new 8-bit value is returned.
2325 If 8-bit operations are not supported, then ASSERT().
2326 If StartBit is greater than 7, then ASSERT().
2327 If EndBit is greater than 7, then ASSERT().
2328 If EndBit is less than StartBit, then ASSERT().
2330 @param Operand Operand on which to perform the bitfield operation.
2331 @param StartBit The ordinal of the least significant bit in the bit field.
2333 @param EndBit The ordinal of the most significant bit in the bit field.
2335 @param OrData The value to OR with the read value from the value
2337 @return The new 8-bit value.
2351 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
2354 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2355 in Operand and the value specified by AndData. All other bits in Operand are
2356 preserved. The new 8-bit value is returned.
2358 If 8-bit operations are not supported, then ASSERT().
2359 If StartBit is greater than 7, then ASSERT().
2360 If EndBit is greater than 7, then ASSERT().
2361 If EndBit is less than StartBit, then ASSERT().
2363 @param Operand Operand on which to perform the bitfield operation.
2364 @param StartBit The ordinal of the least significant bit in the bit field.
2366 @param EndBit The ordinal of the most significant bit in the bit field.
2368 @param AndData The value to AND with the read value from the value.
2370 @return The new 8-bit value.
2384 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
2385 bitwise OR, and returns the result.
2387 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2388 in Operand and the value specified by AndData, followed by a bitwise
2389 inclusive OR with value specified by OrData. All other bits in Operand are
2390 preserved. The new 8-bit value is returned.
2392 If 8-bit operations are not supported, then ASSERT().
2393 If StartBit is greater than 7, then ASSERT().
2394 If EndBit is greater than 7, then ASSERT().
2395 If EndBit is less than StartBit, then ASSERT().
2397 @param Operand Operand on which to perform the bitfield operation.
2398 @param StartBit The ordinal of the least significant bit in the bit field.
2400 @param EndBit The ordinal of the most significant bit in the bit field.
2402 @param AndData The value to AND with the read value from the value.
2403 @param OrData The value to OR with the result of the AND operation.
2405 @return The new 8-bit value.
2410 BitFieldAndThenOr8 (
2420 Returns a bit field from a 16-bit value.
2422 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2424 If 16-bit operations are not supported, then ASSERT().
2425 If StartBit is greater than 15, then ASSERT().
2426 If EndBit is greater than 15, then ASSERT().
2427 If EndBit is less than StartBit, then ASSERT().
2429 @param Operand Operand on which to perform the bitfield operation.
2430 @param StartBit The ordinal of the least significant bit in the bit field.
2432 @param EndBit The ordinal of the most significant bit in the bit field.
2435 @return The bit field read.
2448 Writes a bit field to a 16-bit value, and returns the result.
2450 Writes Value to the bit field specified by the StartBit and the EndBit in
2451 Operand. All other bits in Operand are preserved. The new 16-bit value is
2454 If 16-bit operations are not supported, then ASSERT().
2455 If StartBit is greater than 15, then ASSERT().
2456 If EndBit is greater than 15, then ASSERT().
2457 If EndBit is less than StartBit, then ASSERT().
2459 @param Operand Operand on which to perform the bitfield operation.
2460 @param StartBit The ordinal of the least significant bit in the bit field.
2462 @param EndBit The ordinal of the most significant bit in the bit field.
2464 @param Value New value of the bit field.
2466 @return The new 16-bit value.
2480 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
2483 Performs a bitwise inclusive OR between the bit field specified by StartBit
2484 and EndBit in Operand and the value specified by OrData. All other bits in
2485 Operand are preserved. The new 16-bit value is returned.
2487 If 16-bit operations are not supported, then ASSERT().
2488 If StartBit is greater than 15, then ASSERT().
2489 If EndBit is greater than 15, then ASSERT().
2490 If EndBit is less than StartBit, then ASSERT().
2492 @param Operand Operand on which to perform the bitfield operation.
2493 @param StartBit The ordinal of the least significant bit in the bit field.
2495 @param EndBit The ordinal of the most significant bit in the bit field.
2497 @param OrData The value to OR with the read value from the value
2499 @return The new 16-bit value.
2513 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
2516 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2517 in Operand and the value specified by AndData. All other bits in Operand are
2518 preserved. The new 16-bit value is returned.
2520 If 16-bit operations are not supported, then ASSERT().
2521 If StartBit is greater than 15, then ASSERT().
2522 If EndBit is greater than 15, then ASSERT().
2523 If EndBit is less than StartBit, then ASSERT().
2525 @param Operand Operand on which to perform the bitfield operation.
2526 @param StartBit The ordinal of the least significant bit in the bit field.
2528 @param EndBit The ordinal of the most significant bit in the bit field.
2530 @param AndData The value to AND with the read value from the value
2532 @return The new 16-bit value.
2546 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
2547 bitwise OR, and returns the result.
2549 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2550 in Operand and the value specified by AndData, followed by a bitwise
2551 inclusive OR with value specified by OrData. All other bits in Operand are
2552 preserved. The new 16-bit value is returned.
2554 If 16-bit operations are not supported, then ASSERT().
2555 If StartBit is greater than 15, then ASSERT().
2556 If EndBit is greater than 15, then ASSERT().
2557 If EndBit is less than StartBit, then ASSERT().
2559 @param Operand Operand on which to perform the bitfield operation.
2560 @param StartBit The ordinal of the least significant bit in the bit field.
2562 @param EndBit The ordinal of the most significant bit in the bit field.
2564 @param AndData The value to AND with the read value from the value.
2565 @param OrData The value to OR with the result of the AND operation.
2567 @return The new 16-bit value.
2572 BitFieldAndThenOr16 (
2582 Returns a bit field from a 32-bit value.
2584 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2586 If 32-bit operations are not supported, then ASSERT().
2587 If StartBit is greater than 31, then ASSERT().
2588 If EndBit is greater than 31, then ASSERT().
2589 If EndBit is less than StartBit, then ASSERT().
2591 @param Operand Operand on which to perform the bitfield operation.
2592 @param StartBit The ordinal of the least significant bit in the bit field.
2594 @param EndBit The ordinal of the most significant bit in the bit field.
2597 @return The bit field read.
2610 Writes a bit field to a 32-bit value, and returns the result.
2612 Writes Value to the bit field specified by the StartBit and the EndBit in
2613 Operand. All other bits in Operand are preserved. The new 32-bit value is
2616 If 32-bit operations are not supported, then ASSERT().
2617 If StartBit is greater than 31, then ASSERT().
2618 If EndBit is greater than 31, then ASSERT().
2619 If EndBit is less than StartBit, then ASSERT().
2621 @param Operand Operand on which to perform the bitfield operation.
2622 @param StartBit The ordinal of the least significant bit in the bit field.
2624 @param EndBit The ordinal of the most significant bit in the bit field.
2626 @param Value New value of the bit field.
2628 @return The new 32-bit value.
2642 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2645 Performs a bitwise inclusive OR between the bit field specified by StartBit
2646 and EndBit in Operand and the value specified by OrData. All other bits in
2647 Operand are preserved. The new 32-bit value is returned.
2649 If 32-bit operations are not supported, then ASSERT().
2650 If StartBit is greater than 31, then ASSERT().
2651 If EndBit is greater than 31, then ASSERT().
2652 If EndBit is less than StartBit, then ASSERT().
2654 @param Operand Operand on which to perform the bitfield operation.
2655 @param StartBit The ordinal of the least significant bit in the bit field.
2657 @param EndBit The ordinal of the most significant bit in the bit field.
2659 @param OrData The value to OR with the read value from the value
2661 @return The new 32-bit value.
2675 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2678 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2679 in Operand and the value specified by AndData. All other bits in Operand are
2680 preserved. The new 32-bit value is returned.
2682 If 32-bit operations are not supported, then ASSERT().
2683 If StartBit is greater than 31, then ASSERT().
2684 If EndBit is greater than 31, then ASSERT().
2685 If EndBit is less than StartBit, then ASSERT().
2687 @param Operand Operand on which to perform the bitfield operation.
2688 @param StartBit The ordinal of the least significant bit in the bit field.
2690 @param EndBit The ordinal of the most significant bit in the bit field.
2692 @param AndData The value to AND with the read value from the value
2694 @return The new 32-bit value.
2708 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2709 bitwise OR, and returns the result.
2711 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2712 in Operand and the value specified by AndData, followed by a bitwise
2713 inclusive OR with value specified by OrData. All other bits in Operand are
2714 preserved. The new 32-bit value is returned.
2716 If 32-bit operations are not supported, then ASSERT().
2717 If StartBit is greater than 31, then ASSERT().
2718 If EndBit is greater than 31, then ASSERT().
2719 If EndBit is less than StartBit, then ASSERT().
2721 @param Operand Operand on which to perform the bitfield operation.
2722 @param StartBit The ordinal of the least significant bit in the bit field.
2724 @param EndBit The ordinal of the most significant bit in the bit field.
2726 @param AndData The value to AND with the read value from the value.
2727 @param OrData The value to OR with the result of the AND operation.
2729 @return The new 32-bit value.
2734 BitFieldAndThenOr32 (
2744 Returns a bit field from a 64-bit value.
2746 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2748 If 64-bit operations are not supported, then ASSERT().
2749 If StartBit is greater than 63, then ASSERT().
2750 If EndBit is greater than 63, then ASSERT().
2751 If EndBit is less than StartBit, then ASSERT().
2753 @param Operand Operand on which to perform the bitfield operation.
2754 @param StartBit The ordinal of the least significant bit in the bit field.
2756 @param EndBit The ordinal of the most significant bit in the bit field.
2759 @return The bit field read.
2772 Writes a bit field to a 64-bit value, and returns the result.
2774 Writes Value to the bit field specified by the StartBit and the EndBit in
2775 Operand. All other bits in Operand are preserved. The new 64-bit value is
2778 If 64-bit operations are not supported, then ASSERT().
2779 If StartBit is greater than 63, then ASSERT().
2780 If EndBit is greater than 63, then ASSERT().
2781 If EndBit is less than StartBit, then ASSERT().
2783 @param Operand Operand on which to perform the bitfield operation.
2784 @param StartBit The ordinal of the least significant bit in the bit field.
2786 @param EndBit The ordinal of the most significant bit in the bit field.
2788 @param Value New value of the bit field.
2790 @return The new 64-bit value.
2804 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2807 Performs a bitwise inclusive OR between the bit field specified by StartBit
2808 and EndBit in Operand and the value specified by OrData. All other bits in
2809 Operand are preserved. The new 64-bit value is returned.
2811 If 64-bit operations are not supported, then ASSERT().
2812 If StartBit is greater than 63, then ASSERT().
2813 If EndBit is greater than 63, then ASSERT().
2814 If EndBit is less than StartBit, then ASSERT().
2816 @param Operand Operand on which to perform the bitfield operation.
2817 @param StartBit The ordinal of the least significant bit in the bit field.
2819 @param EndBit The ordinal of the most significant bit in the bit field.
2821 @param OrData The value to OR with the read value from the value
2823 @return The new 64-bit value.
2837 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2840 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2841 in Operand and the value specified by AndData. All other bits in Operand are
2842 preserved. The new 64-bit value is returned.
2844 If 64-bit operations are not supported, then ASSERT().
2845 If StartBit is greater than 63, then ASSERT().
2846 If EndBit is greater than 63, then ASSERT().
2847 If EndBit is less than StartBit, then ASSERT().
2849 @param Operand Operand on which to perform the bitfield operation.
2850 @param StartBit The ordinal of the least significant bit in the bit field.
2852 @param EndBit The ordinal of the most significant bit in the bit field.
2854 @param AndData The value to AND with the read value from the value
2856 @return The new 64-bit value.
2870 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2871 bitwise OR, and returns the result.
2873 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2874 in Operand and the value specified by AndData, followed by a bitwise
2875 inclusive OR with value specified by OrData. All other bits in Operand are
2876 preserved. The new 64-bit value is returned.
2878 If 64-bit operations are not supported, then ASSERT().
2879 If StartBit is greater than 63, then ASSERT().
2880 If EndBit is greater than 63, then ASSERT().
2881 If EndBit is less than StartBit, then ASSERT().
2883 @param Operand Operand on which to perform the bitfield operation.
2884 @param StartBit The ordinal of the least significant bit in the bit field.
2886 @param EndBit The ordinal of the most significant bit in the bit field.
2888 @param AndData The value to AND with the read value from the value.
2889 @param OrData The value to OR with the result of the AND operation.
2891 @return The new 64-bit value.
2896 BitFieldAndThenOr64 (
2906 // Base Library Synchronization Functions
2910 Retrieves the architecture specific spin lock alignment requirements for
2911 optimal spin lock performance.
2913 This function retrieves the spin lock alignment requirements for optimal
2914 performance on a given CPU architecture. The spin lock alignment must be a
2915 power of two and is returned by this function. If there are no alignment
2916 requirements, then 1 must be returned. The spin lock synchronization
2917 functions must function correctly if the spin lock size and alignment values
2918 returned by this function are not used at all. These values are hints to the
2919 consumers of the spin lock synchronization functions to obtain optimal spin
2922 @return The architecture specific spin lock alignment.
2927 GetSpinLockProperties (
2933 Initializes a spin lock to the released state and returns the spin lock.
2935 This function initializes the spin lock specified by SpinLock to the released
2936 state, and returns SpinLock. Optimal performance can be achieved by calling
2937 GetSpinLockProperties() to determine the size and alignment requirements for
2940 If SpinLock is NULL, then ASSERT().
2942 @param SpinLock A pointer to the spin lock to initialize to the released
2950 InitializeSpinLock (
2951 IN SPIN_LOCK
*SpinLock
2956 Waits until a spin lock can be placed in the acquired state.
2958 This function checks the state of the spin lock specified by SpinLock. If
2959 SpinLock is in the released state, then this function places SpinLock in the
2960 acquired state and returns SpinLock. Otherwise, this function waits
2961 indefinitely for the spin lock to be released, and then places it in the
2962 acquired state and returns SpinLock. All state transitions of SpinLock must
2963 be performed using MP safe mechanisms.
2965 If SpinLock is NULL, then ASSERT().
2966 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2967 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2968 PcdSpinLockTimeout microseconds, then ASSERT().
2970 @param SpinLock A pointer to the spin lock to place in the acquired state.
2978 IN SPIN_LOCK
*SpinLock
2983 Attempts to place a spin lock in the acquired state.
2985 This function checks the state of the spin lock specified by SpinLock. If
2986 SpinLock is in the released state, then this function places SpinLock in the
2987 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2988 transitions of SpinLock must be performed using MP safe mechanisms.
2990 If SpinLock is NULL, then ASSERT().
2991 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2993 @param SpinLock A pointer to the spin lock to place in the acquired state.
2995 @retval TRUE SpinLock was placed in the acquired state.
2996 @retval FALSE SpinLock could not be acquired.
3001 AcquireSpinLockOrFail (
3002 IN SPIN_LOCK
*SpinLock
3007 Releases a spin lock.
3009 This function places the spin lock specified by SpinLock in the release state
3010 and returns SpinLock.
3012 If SpinLock is NULL, then ASSERT().
3013 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3015 @param SpinLock A pointer to the spin lock to release.
3023 IN SPIN_LOCK
*SpinLock
3028 Performs an atomic increment of an 32-bit unsigned integer.
3030 Performs an atomic increment of the 32-bit unsigned integer specified by
3031 Value and returns the incremented value. The increment operation must be
3032 performed using MP safe mechanisms. The state of the return value is not
3033 guaranteed to be MP safe.
3035 If Value is NULL, then ASSERT().
3037 @param Value A pointer to the 32-bit value to increment.
3039 @return The incremented value.
3044 InterlockedIncrement (
3050 Performs an atomic decrement of an 32-bit unsigned integer.
3052 Performs an atomic decrement of the 32-bit unsigned integer specified by
3053 Value and returns the decremented value. The decrement operation must be
3054 performed using MP safe mechanisms. The state of the return value is not
3055 guaranteed to be MP safe.
3057 If Value is NULL, then ASSERT().
3059 @param Value A pointer to the 32-bit value to decrement.
3061 @return The decremented value.
3066 InterlockedDecrement (
3072 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
3074 Performs an atomic compare exchange operation on the 32-bit unsigned integer
3075 specified by Value. If Value is equal to CompareValue, then Value is set to
3076 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
3077 then Value is returned. The compare exchange operation must be performed using
3080 If Value is NULL, then ASSERT().
3082 @param Value A pointer to the 32-bit value for the compare exchange
3084 @param CompareValue 32-bit value used in compare operation.
3085 @param ExchangeValue 32-bit value used in exchange operation.
3087 @return The original *Value before exchange.
3092 InterlockedCompareExchange32 (
3093 IN OUT UINT32
*Value
,
3094 IN UINT32 CompareValue
,
3095 IN UINT32 ExchangeValue
3100 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
3102 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
3103 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
3104 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
3105 The compare exchange operation must be performed using MP safe mechanisms.
3107 If Value is NULL, then ASSERT().
3109 @param Value A pointer to the 64-bit value for the compare exchange
3111 @param CompareValue 64-bit value used in compare operation.
3112 @param ExchangeValue 64-bit value used in exchange operation.
3114 @return The original *Value before exchange.
3119 InterlockedCompareExchange64 (
3120 IN OUT UINT64
*Value
,
3121 IN UINT64 CompareValue
,
3122 IN UINT64 ExchangeValue
3127 Performs an atomic compare exchange operation on a pointer value.
3129 Performs an atomic compare exchange operation on the pointer value specified
3130 by Value. If Value is equal to CompareValue, then Value is set to
3131 ExchangeValue and CompareValue is returned. If Value is not equal to
3132 CompareValue, then Value is returned. The compare exchange operation must be
3133 performed using MP safe mechanisms.
3135 If Value is NULL, then ASSERT().
3137 @param Value A pointer to the pointer value for the compare exchange
3139 @param CompareValue Pointer value used in compare operation.
3140 @param ExchangeValue Pointer value used in exchange operation.
3145 InterlockedCompareExchangePointer (
3146 IN OUT VOID
**Value
,
3147 IN VOID
*CompareValue
,
3148 IN VOID
*ExchangeValue
3153 // Base Library Checksum Functions
3157 Calculate the sum of all elements in a buffer in unit of UINT8.
3158 During calculation, the carry bits are dropped.
3160 This function calculates the sum of all elements in a buffer
3161 in unit of UINT8. The carry bits in result of addition are dropped.
3162 The result is returned as UINT8. If Length is Zero, then Zero is
3165 If Buffer is NULL, then ASSERT().
3166 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3168 @param Buffer Pointer to the buffer to carry out the sum operation.
3169 @param Length The size, in bytes, of Buffer .
3171 @return Sum The sum of Buffer with carry bits dropped during additions.
3177 IN CONST UINT8
*Buffer
,
3183 Returns the two's complement checksum of all elements in a buffer
3186 This function first calculates the sum of the 8-bit values in the
3187 buffer specified by Buffer and Length. The carry bits in the result
3188 of addition are dropped. Then, the two's complement of the sum is
3189 returned. If Length is 0, then 0 is returned.
3191 If Buffer is NULL, then ASSERT().
3192 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3195 @param Buffer Pointer to the buffer to carry out the checksum operation.
3196 @param Length The size, in bytes, of Buffer.
3198 @return Checksum The 2's complement checksum of Buffer.
3203 CalculateCheckSum8 (
3204 IN CONST UINT8
*Buffer
,
3210 Returns the sum of all elements in a buffer of 16-bit values. During
3211 calculation, the carry bits are dropped.
3213 This function calculates the sum of the 16-bit values in the buffer
3214 specified by Buffer and Length. The carry bits in result of addition are dropped.
3215 The 16-bit result is returned. If Length is 0, then 0 is returned.
3217 If Buffer is NULL, then ASSERT().
3218 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3219 If Length is not aligned on a 16-bit boundary, then ASSERT().
3220 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3222 @param Buffer Pointer to the buffer to carry out the sum operation.
3223 @param Length The size, in bytes, of Buffer.
3225 @return Sum The sum of Buffer with carry bits dropped during additions.
3231 IN CONST UINT16
*Buffer
,
3237 Returns the two's complement checksum of all elements in a buffer of
3240 This function first calculates the sum of the 16-bit values in the buffer
3241 specified by Buffer and Length. The carry bits in the result of addition
3242 are dropped. Then, the two's complement of the sum is returned. If Length
3243 is 0, then 0 is returned.
3245 If Buffer is NULL, then ASSERT().
3246 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3247 If Length is not aligned on a 16-bit boundary, then ASSERT().
3248 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3250 @param Buffer Pointer to the buffer to carry out the checksum operation.
3251 @param Length The size, in bytes, of Buffer.
3253 @return Checksum The 2's complement checksum of Buffer.
3258 CalculateCheckSum16 (
3259 IN CONST UINT16
*Buffer
,
3265 Returns the sum of all elements in a buffer of 32-bit values. During
3266 calculation, the carry bits are dropped.
3268 This function calculates the sum of the 32-bit values in the buffer
3269 specified by Buffer and Length. The carry bits in result of addition are dropped.
3270 The 32-bit result is returned. If Length is 0, then 0 is returned.
3272 If Buffer is NULL, then ASSERT().
3273 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3274 If Length is not aligned on a 32-bit boundary, then ASSERT().
3275 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3277 @param Buffer Pointer to the buffer to carry out the sum operation.
3278 @param Length The size, in bytes, of Buffer.
3280 @return Sum The sum of Buffer with carry bits dropped during additions.
3286 IN CONST UINT32
*Buffer
,
3292 Returns the two's complement checksum of all elements in a buffer of
3295 This function first calculates the sum of the 32-bit values in the buffer
3296 specified by Buffer and Length. The carry bits in the result of addition
3297 are dropped. Then, the two's complement of the sum is returned. If Length
3298 is 0, then 0 is returned.
3300 If Buffer is NULL, then ASSERT().
3301 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3302 If Length is not aligned on a 32-bit boundary, then ASSERT().
3303 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3305 @param Buffer Pointer to the buffer to carry out the checksum operation.
3306 @param Length The size, in bytes, of Buffer.
3308 @return Checksum The 2's complement checksum of Buffer.
3313 CalculateCheckSum32 (
3314 IN CONST UINT32
*Buffer
,
3320 Returns the sum of all elements in a buffer of 64-bit values. During
3321 calculation, the carry bits are dropped.
3323 This function calculates the sum of the 64-bit values in the buffer
3324 specified by Buffer and Length. The carry bits in result of addition are dropped.
3325 The 64-bit result is returned. If Length is 0, then 0 is returned.
3327 If Buffer is NULL, then ASSERT().
3328 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3329 If Length is not aligned on a 64-bit boundary, then ASSERT().
3330 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3332 @param Buffer Pointer to the buffer to carry out the sum operation.
3333 @param Length The size, in bytes, of Buffer.
3335 @return Sum The sum of Buffer with carry bits dropped during additions.
3341 IN CONST UINT64
*Buffer
,
3347 Returns the two's complement checksum of all elements in a buffer of
3350 This function first calculates the sum of the 64-bit values in the buffer
3351 specified by Buffer and Length. The carry bits in the result of addition
3352 are dropped. Then, the two's complement of the sum is returned. If Length
3353 is 0, then 0 is returned.
3355 If Buffer is NULL, then ASSERT().
3356 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3357 If Length is not aligned on a 64-bit boundary, then ASSERT().
3358 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3360 @param Buffer Pointer to the buffer to carry out the checksum operation.
3361 @param Length The size, in bytes, of Buffer.
3363 @return Checksum The 2's complement checksum of Buffer.
3368 CalculateCheckSum64 (
3369 IN CONST UINT64
*Buffer
,
3375 // Base Library CPU Functions
3379 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
3380 IN VOID
*Context1
, OPTIONAL
3381 IN VOID
*Context2 OPTIONAL
3386 Used to serialize load and store operations.
3388 All loads and stores that proceed calls to this function are guaranteed to be
3389 globally visible when this function returns.
3400 Saves the current CPU context that can be restored with a call to LongJump()
3403 Saves the current CPU context in the buffer specified by JumpBuffer and
3404 returns 0. The initial call to SetJump() must always return 0. Subsequent
3405 calls to LongJump() cause a non-zero value to be returned by SetJump().
3407 If JumpBuffer is NULL, then ASSERT().
3408 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3410 @param JumpBuffer A pointer to CPU context buffer.
3412 @retval 0 Indicates a return from SetJump().
3418 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
3423 Restores the CPU context that was saved with SetJump().
3425 Restores the CPU context from the buffer specified by JumpBuffer. This
3426 function never returns to the caller. Instead is resumes execution based on
3427 the state of JumpBuffer.
3429 If JumpBuffer is NULL, then ASSERT().
3430 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3431 If Value is 0, then ASSERT().
3433 @param JumpBuffer A pointer to CPU context buffer.
3434 @param Value The value to return when the SetJump() context is
3435 restored and must be non-zero.
3441 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
3447 Enables CPU interrupts.
3449 Enables CPU interrupts.
3460 Disables CPU interrupts.
3462 Disables CPU interrupts.
3473 Disables CPU interrupts and returns the interrupt state prior to the disable
3476 Disables CPU interrupts and returns the interrupt state prior to the disable
3479 @retval TRUE CPU interrupts were enabled on entry to this call.
3480 @retval FALSE CPU interrupts were disabled on entry to this call.
3485 SaveAndDisableInterrupts (
3491 Enables CPU interrupts for the smallest window required to capture any
3494 Enables CPU interrupts for the smallest window required to capture any
3500 EnableDisableInterrupts (
3506 Retrieves the current CPU interrupt state.
3508 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
3509 currently enabled. Otherwise returns FALSE.
3511 @retval TRUE CPU interrupts are enabled.
3512 @retval FALSE CPU interrupts are disabled.
3517 GlueGetInterruptState (
3523 Set the current CPU interrupt state.
3525 Sets the current CPU interrupt state to the state specified by
3526 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
3527 InterruptState is FALSE, then interrupts are disabled. InterruptState is
3530 @param InterruptState TRUE if interrupts should enabled. FALSE if
3531 interrupts should be disabled.
3533 @return InterruptState
3539 IN BOOLEAN InterruptState
3544 Places the CPU in a sleep state until an interrupt is received.
3546 Places the CPU in a sleep state until an interrupt is received. If interrupts
3547 are disabled prior to calling this function, then the CPU will be placed in a
3548 sleep state indefinitely.
3559 Requests CPU to pause for a short period of time.
3561 Requests CPU to pause for a short period of time. Typically used in MP
3562 systems to prevent memory starvation while waiting for a spin lock.
3573 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3575 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3586 Transfers control to a function starting with a new stack.
3588 Transfers control to the function specified by EntryPoint using the
3589 new stack specified by NewStack and passing in the parameters specified
3590 by Context1 and Context2. Context1 and Context2 are optional and may
3591 be NULL. The function EntryPoint must never return. This function
3592 supports a variable number of arguments following the NewStack parameter.
3593 These additional arguments are ignored on IA-32, x64, and EBC.
3594 IPF CPUs expect one additional parameter of type VOID * that specifies
3595 the new backing store pointer.
3597 If EntryPoint is NULL, then ASSERT().
3598 If NewStack is NULL, then ASSERT().
3600 @param EntryPoint A pointer to function to call with the new stack.
3601 @param Context1 A pointer to the context to pass into the EntryPoint
3603 @param Context2 A pointer to the context to pass into the EntryPoint
3605 @param NewStack A pointer to the new stack to use for the EntryPoint
3612 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
3613 IN VOID
*Context1
, OPTIONAL
3614 IN VOID
*Context2
, OPTIONAL
3621 Generates a breakpoint on the CPU.
3623 Generates a breakpoint on the CPU. The breakpoint must be implemented such
3624 that code can resume normal execution after the breakpoint.
3635 Executes an infinite loop.
3637 Forces the CPU to execute an infinite loop. A debugger may be used to skip
3638 past the loop and the code that follows the loop must execute properly. This
3639 implies that the infinite loop must not cause the code that follow it to be
3649 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
3651 // IA32 and X64 Specific Functions
3654 // Byte packed structure for 16-bit Real Mode EFLAGS
3658 UINT32 CF
:1; // Carry Flag
3659 UINT32 Reserved_0
:1; // Reserved
3660 UINT32 PF
:1; // Parity Flag
3661 UINT32 Reserved_1
:1; // Reserved
3662 UINT32 AF
:1; // Auxiliary Carry Flag
3663 UINT32 Reserved_2
:1; // Reserved
3664 UINT32 ZF
:1; // Zero Flag
3665 UINT32 SF
:1; // Sign Flag
3666 UINT32 TF
:1; // Trap Flag
3667 UINT32 IF
:1; // Interrupt Enable Flag
3668 UINT32 DF
:1; // Direction Flag
3669 UINT32 OF
:1; // Overflow Flag
3670 UINT32 IOPL
:2; // I/O Privilege Level
3671 UINT32 NT
:1; // Nested Task
3672 UINT32 Reserved_3
:1; // Reserved
3678 // Byte packed structure for EFLAGS/RFLAGS
3680 // 64-bits on X64. The upper 32-bits on X64 are reserved
3684 UINT32 CF
:1; // Carry Flag
3685 UINT32 Reserved_0
:1; // Reserved
3686 UINT32 PF
:1; // Parity Flag
3687 UINT32 Reserved_1
:1; // Reserved
3688 UINT32 AF
:1; // Auxiliary Carry Flag
3689 UINT32 Reserved_2
:1; // Reserved
3690 UINT32 ZF
:1; // Zero Flag
3691 UINT32 SF
:1; // Sign Flag
3692 UINT32 TF
:1; // Trap Flag
3693 UINT32 IF
:1; // Interrupt Enable Flag
3694 UINT32 DF
:1; // Direction Flag
3695 UINT32 OF
:1; // Overflow Flag
3696 UINT32 IOPL
:2; // I/O Privilege Level
3697 UINT32 NT
:1; // Nested Task
3698 UINT32 Reserved_3
:1; // Reserved
3699 UINT32 RF
:1; // Resume Flag
3700 UINT32 VM
:1; // Virtual 8086 Mode
3701 UINT32 AC
:1; // Alignment Check
3702 UINT32 VIF
:1; // Virtual Interrupt Flag
3703 UINT32 VIP
:1; // Virtual Interrupt Pending
3704 UINT32 ID
:1; // ID Flag
3705 UINT32 Reserved_4
:10; // Reserved
3711 // Byte packed structure for Control Register 0 (CR0)
3713 // 64-bits on X64. The upper 32-bits on X64 are reserved
3717 UINT32 PE
:1; // Protection Enable
3718 UINT32 MP
:1; // Monitor Coprocessor
3719 UINT32 EM
:1; // Emulation
3720 UINT32 TS
:1; // Task Switched
3721 UINT32 ET
:1; // Extension Type
3722 UINT32 NE
:1; // Numeric Error
3723 UINT32 Reserved_0
:10; // Reserved
3724 UINT32 WP
:1; // Write Protect
3725 UINT32 Reserved_1
:1; // Reserved
3726 UINT32 AM
:1; // Alignment Mask
3727 UINT32 Reserved_2
:10; // Reserved
3728 UINT32 NW
:1; // Mot Write-through
3729 UINT32 CD
:1; // Cache Disable
3730 UINT32 PG
:1; // Paging
3736 // Byte packed structure for Control Register 4 (CR4)
3738 // 64-bits on X64. The upper 32-bits on X64 are reserved
3742 UINT32 VME
:1; // Virtual-8086 Mode Extensions
3743 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
3744 UINT32 TSD
:1; // Time Stamp Disable
3745 UINT32 DE
:1; // Debugging Extensions
3746 UINT32 PSE
:1; // Page Size Extensions
3747 UINT32 PAE
:1; // Physical Address Extension
3748 UINT32 MCE
:1; // Machine Check Enable
3749 UINT32 PGE
:1; // Page Global Enable
3750 UINT32 PCE
:1; // Performance Monitoring Counter
3752 UINT32 OSFXSR
:1; // Operating System Support for
3753 // FXSAVE and FXRSTOR instructions
3754 UINT32 OSXMMEXCPT
:1; // Operating System Support for
3755 // Unmasked SIMD Floating Point
3757 UINT32 Reserved_0
:2; // Reserved
3758 UINT32 VMXE
:1; // VMX Enable
3759 UINT32 Reserved_1
:18; // Reseved
3765 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
3766 /// @bug How to make this structure byte-packed in a compiler independent way?
3775 #define IA32_IDT_GATE_TYPE_TASK 0x85
3776 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
3777 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
3778 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
3779 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
3782 // Byte packed structure for an Interrupt Gate Descriptor
3786 UINT32 OffsetLow
:16; // Offset bits 15..0
3787 UINT32 Selector
:16; // Selector
3788 UINT32 Reserved_0
:8; // Reserved
3789 UINT32 GateType
:8; // Gate Type. See #defines above
3790 UINT32 OffsetHigh
:16; // Offset bits 31..16
3793 } IA32_IDT_GATE_DESCRIPTOR
;
3796 // Byte packed structure for an FP/SSE/SSE2 context
3803 // Structures for the 16-bit real mode thunks
3856 IA32_EFLAGS32 EFLAGS
;
3866 } IA32_REGISTER_SET
;
3869 // Byte packed structure for an 16-bit real mode thunks
3872 IA32_REGISTER_SET
*RealModeState
;
3873 VOID
*RealModeBuffer
;
3874 UINT32 RealModeBufferSize
;
3875 UINT32 ThunkAttributes
;
3878 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
3879 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
3880 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3883 Retrieves CPUID information.
3885 Executes the CPUID instruction with EAX set to the value specified by Index.
3886 This function always returns Index.
3887 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3888 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3889 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3890 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3891 This function is only available on IA-32 and X64.
3893 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3895 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3896 instruction. This is an optional parameter that may be NULL.
3897 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3898 instruction. This is an optional parameter that may be NULL.
3899 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3900 instruction. This is an optional parameter that may be NULL.
3901 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3902 instruction. This is an optional parameter that may be NULL.
3911 OUT UINT32
*Eax
, OPTIONAL
3912 OUT UINT32
*Ebx
, OPTIONAL
3913 OUT UINT32
*Ecx
, OPTIONAL
3914 OUT UINT32
*Edx OPTIONAL
3919 Retrieves CPUID information using an extended leaf identifier.
3921 Executes the CPUID instruction with EAX set to the value specified by Index
3922 and ECX set to the value specified by SubIndex. This function always returns
3923 Index. This function is only available on IA-32 and x64.
3925 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3926 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3927 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3928 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3930 @param Index The 32-bit value to load into EAX prior to invoking the
3932 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3934 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3935 instruction. This is an optional parameter that may be
3937 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3938 instruction. This is an optional parameter that may be
3940 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3941 instruction. This is an optional parameter that may be
3943 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3944 instruction. This is an optional parameter that may be
3955 OUT UINT32
*Eax
, OPTIONAL
3956 OUT UINT32
*Ebx
, OPTIONAL
3957 OUT UINT32
*Ecx
, OPTIONAL
3958 OUT UINT32
*Edx OPTIONAL
3963 Returns the lower 32-bits of a Machine Specific Register(MSR).
3965 Reads and returns the lower 32-bits of the MSR specified by Index.
3966 No parameter checking is performed on Index, and some Index values may cause
3967 CPU exceptions. The caller must either guarantee that Index is valid, or the
3968 caller must set up exception handlers to catch the exceptions. This function
3969 is only available on IA-32 and X64.
3971 @param Index The 32-bit MSR index to read.
3973 @return The lower 32 bits of the MSR identified by Index.
3984 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3986 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3987 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3988 the MSR is returned. No parameter checking is performed on Index or Value,
3989 and some of these may cause CPU exceptions. The caller must either guarantee
3990 that Index and Value are valid, or the caller must establish proper exception
3991 handlers. This function is only available on IA-32 and X64.
3993 @param Index The 32-bit MSR index to write.
3994 @param Value The 32-bit value to write to the MSR.
4008 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
4009 writes the result back to the 64-bit MSR.
4011 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
4012 between the lower 32-bits of the read result and the value specified by
4013 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
4014 32-bits of the value written to the MSR is returned. No parameter checking is
4015 performed on Index or OrData, and some of these may cause CPU exceptions. The
4016 caller must either guarantee that Index and OrData are valid, or the caller
4017 must establish proper exception handlers. This function is only available on
4020 @param Index The 32-bit MSR index to write.
4021 @param OrData The value to OR with the read value from the MSR.
4023 @return The lower 32-bit value written to the MSR.
4035 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
4036 the result back to the 64-bit MSR.
4038 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4039 lower 32-bits of the read result and the value specified by AndData, and
4040 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
4041 the value written to the MSR is returned. No parameter checking is performed
4042 on Index or AndData, and some of these may cause CPU exceptions. The caller
4043 must either guarantee that Index and AndData are valid, or the caller must
4044 establish proper exception handlers. This function is only available on IA-32
4047 @param Index The 32-bit MSR index to write.
4048 @param AndData The value to AND with the read value from the MSR.
4050 @return The lower 32-bit value written to the MSR.
4062 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
4063 on the lower 32-bits, and writes the result back to the 64-bit MSR.
4065 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4066 lower 32-bits of the read result and the value specified by AndData
4067 preserving the upper 32-bits, performs a bitwise inclusive OR between the
4068 result of the AND operation and the value specified by OrData, and writes the
4069 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
4070 written to the MSR is returned. No parameter checking is performed on Index,
4071 AndData, or OrData, and some of these may cause CPU exceptions. The caller
4072 must either guarantee that Index, AndData, and OrData are valid, or the
4073 caller must establish proper exception handlers. This function is only
4074 available on IA-32 and X64.
4076 @param Index The 32-bit MSR index to write.
4077 @param AndData The value to AND with the read value from the MSR.
4078 @param OrData The value to OR with the result of the AND operation.
4080 @return The lower 32-bit value written to the MSR.
4093 Reads a bit field of an MSR.
4095 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
4096 specified by the StartBit and the EndBit. The value of the bit field is
4097 returned. The caller must either guarantee that Index is valid, or the caller
4098 must set up exception handlers to catch the exceptions. This function is only
4099 available on IA-32 and X64.
4101 If StartBit is greater than 31, then ASSERT().
4102 If EndBit is greater than 31, then ASSERT().
4103 If EndBit is less than StartBit, then ASSERT().
4105 @param Index The 32-bit MSR index to read.
4106 @param StartBit The ordinal of the least significant bit in the bit field.
4108 @param EndBit The ordinal of the most significant bit in the bit field.
4111 @return The bit field read from the MSR.
4116 AsmMsrBitFieldRead32 (
4124 Writes a bit field to an MSR.
4126 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
4127 field is specified by the StartBit and the EndBit. All other bits in the
4128 destination MSR are preserved. The lower 32-bits of the MSR written is
4129 returned. Extra left bits in Value are stripped. The caller must either
4130 guarantee that Index and the data written is valid, or the caller must set up
4131 exception handlers to catch the exceptions. This function is only available
4134 If StartBit is greater than 31, then ASSERT().
4135 If EndBit is greater than 31, then ASSERT().
4136 If EndBit is less than StartBit, then ASSERT().
4138 @param Index The 32-bit MSR index to write.
4139 @param StartBit The ordinal of the least significant bit in the bit field.
4141 @param EndBit The ordinal of the most significant bit in the bit field.
4143 @param Value New value of the bit field.
4145 @return The lower 32-bit of the value written to the MSR.
4150 AsmMsrBitFieldWrite32 (
4159 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
4160 result back to the bit field in the 64-bit MSR.
4162 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
4163 between the read result and the value specified by OrData, and writes the
4164 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
4165 written to the MSR are returned. Extra left bits in OrData are stripped. The
4166 caller must either guarantee that Index and the data written is valid, or
4167 the caller must set up exception handlers to catch the exceptions. This
4168 function is only available on IA-32 and X64.
4170 If StartBit is greater than 31, then ASSERT().
4171 If EndBit is greater than 31, then ASSERT().
4172 If EndBit is less than StartBit, then ASSERT().
4174 @param Index The 32-bit MSR index to write.
4175 @param StartBit The ordinal of the least significant bit in the bit field.
4177 @param EndBit The ordinal of the most significant bit in the bit field.
4179 @param OrData The value to OR with the read value from the MSR.
4181 @return The lower 32-bit of the value written to the MSR.
4186 AsmMsrBitFieldOr32 (
4195 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
4196 result back to the bit field in the 64-bit MSR.
4198 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4199 read result and the value specified by AndData, and writes the result to the
4200 64-bit MSR specified by Index. The lower 32-bits of the value written to the
4201 MSR are returned. Extra left bits in AndData are stripped. The caller must
4202 either guarantee that Index and the data written is valid, or the caller must
4203 set up exception handlers to catch the exceptions. This function is only
4204 available on IA-32 and X64.
4206 If StartBit is greater than 31, then ASSERT().
4207 If EndBit is greater than 31, then ASSERT().
4208 If EndBit is less than StartBit, then ASSERT().
4210 @param Index The 32-bit MSR index to write.
4211 @param StartBit The ordinal of the least significant bit in the bit field.
4213 @param EndBit The ordinal of the most significant bit in the bit field.
4215 @param AndData The value to AND with the read value from the MSR.
4217 @return The lower 32-bit of the value written to the MSR.
4222 AsmMsrBitFieldAnd32 (
4231 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
4232 bitwise inclusive OR, and writes the result back to the bit field in the
4235 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
4236 bitwise inclusive OR between the read result and the value specified by
4237 AndData, and writes the result to the 64-bit MSR specified by Index. The
4238 lower 32-bits of the value written to the MSR are returned. Extra left bits
4239 in both AndData and OrData are stripped. The caller must either guarantee
4240 that Index and the data written is valid, or the caller must set up exception
4241 handlers to catch the exceptions. This function is only available on IA-32
4244 If StartBit is greater than 31, then ASSERT().
4245 If EndBit is greater than 31, then ASSERT().
4246 If EndBit is less than StartBit, then ASSERT().
4248 @param Index The 32-bit MSR index to write.
4249 @param StartBit The ordinal of the least significant bit in the bit field.
4251 @param EndBit The ordinal of the most significant bit in the bit field.
4253 @param AndData The value to AND with the read value from the MSR.
4254 @param OrData The value to OR with the result of the AND operation.
4256 @return The lower 32-bit of the value written to the MSR.
4261 AsmMsrBitFieldAndThenOr32 (
4271 Returns a 64-bit Machine Specific Register(MSR).
4273 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
4274 performed on Index, and some Index values may cause CPU exceptions. The
4275 caller must either guarantee that Index is valid, or the caller must set up
4276 exception handlers to catch the exceptions. This function is only available
4279 @param Index The 32-bit MSR index to read.
4281 @return The value of the MSR identified by Index.
4292 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
4295 Writes the 64-bit value specified by Value to the MSR specified by Index. The
4296 64-bit value written to the MSR is returned. No parameter checking is
4297 performed on Index or Value, and some of these may cause CPU exceptions. The
4298 caller must either guarantee that Index and Value are valid, or the caller
4299 must establish proper exception handlers. This function is only available on
4302 @param Index The 32-bit MSR index to write.
4303 @param Value The 64-bit value to write to the MSR.
4317 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
4318 back to the 64-bit MSR.
4320 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
4321 between the read result and the value specified by OrData, and writes the
4322 result to the 64-bit MSR specified by Index. The value written to the MSR is
4323 returned. No parameter checking is performed on Index or OrData, and some of
4324 these may cause CPU exceptions. The caller must either guarantee that Index
4325 and OrData are valid, or the caller must establish proper exception handlers.
4326 This function is only available on IA-32 and X64.
4328 @param Index The 32-bit MSR index to write.
4329 @param OrData The value to OR with the read value from the MSR.
4331 @return The value written back to the MSR.
4343 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
4346 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4347 read result and the value specified by OrData, and writes the result to the
4348 64-bit MSR specified by Index. The value written to the MSR is returned. No
4349 parameter checking is performed on Index or OrData, and some of these may
4350 cause CPU exceptions. The caller must either guarantee that Index and OrData
4351 are valid, or the caller must establish proper exception handlers. This
4352 function is only available on IA-32 and X64.
4354 @param Index The 32-bit MSR index to write.
4355 @param AndData The value to AND with the read value from the MSR.
4357 @return The value written back to the MSR.
4369 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
4370 OR, and writes the result back to the 64-bit MSR.
4372 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
4373 result and the value specified by AndData, performs a bitwise inclusive OR
4374 between the result of the AND operation and the value specified by OrData,
4375 and writes the result to the 64-bit MSR specified by Index. The value written
4376 to the MSR is returned. No parameter checking is performed on Index, AndData,
4377 or OrData, and some of these may cause CPU exceptions. The caller must either
4378 guarantee that Index, AndData, and OrData are valid, or the caller must
4379 establish proper exception handlers. This function is only available on IA-32
4382 @param Index The 32-bit MSR index to write.
4383 @param AndData The value to AND with the read value from the MSR.
4384 @param OrData The value to OR with the result of the AND operation.
4386 @return The value written back to the MSR.
4399 Reads a bit field of an MSR.
4401 Reads the bit field in the 64-bit MSR. The bit field is specified by the
4402 StartBit and the EndBit. The value of the bit field is returned. The caller
4403 must either guarantee that Index is valid, or the caller must set up
4404 exception handlers to catch the exceptions. This function is only available
4407 If StartBit is greater than 63, then ASSERT().
4408 If EndBit is greater than 63, then ASSERT().
4409 If EndBit is less than StartBit, then ASSERT().
4411 @param Index The 32-bit MSR index to read.
4412 @param StartBit The ordinal of the least significant bit in the bit field.
4414 @param EndBit The ordinal of the most significant bit in the bit field.
4417 @return The value read from the MSR.
4422 AsmMsrBitFieldRead64 (
4430 Writes a bit field to an MSR.
4432 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
4433 the StartBit and the EndBit. All other bits in the destination MSR are
4434 preserved. The MSR written is returned. Extra left bits in Value are
4435 stripped. The caller must either guarantee that Index and the data written is
4436 valid, or the caller must set up exception handlers to catch the exceptions.
4437 This function is only available on IA-32 and X64.
4439 If StartBit is greater than 63, then ASSERT().
4440 If EndBit is greater than 63, then ASSERT().
4441 If EndBit is less than StartBit, then ASSERT().
4443 @param Index The 32-bit MSR index to write.
4444 @param StartBit The ordinal of the least significant bit in the bit field.
4446 @param EndBit The ordinal of the most significant bit in the bit field.
4448 @param Value New value of the bit field.
4450 @return The value written back to the MSR.
4455 AsmMsrBitFieldWrite64 (
4464 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
4465 writes the result back to the bit field in the 64-bit MSR.
4467 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
4468 between the read result and the value specified by OrData, and writes the
4469 result to the 64-bit MSR specified by Index. The value written to the MSR is
4470 returned. Extra left bits in OrData are stripped. The caller must either
4471 guarantee that Index and the data written is valid, or the caller must set up
4472 exception handlers to catch the exceptions. This function is only available
4475 If StartBit is greater than 63, then ASSERT().
4476 If EndBit is greater than 63, then ASSERT().
4477 If EndBit is less than StartBit, then ASSERT().
4479 @param Index The 32-bit MSR index to write.
4480 @param StartBit The ordinal of the least significant bit in the bit field.
4482 @param EndBit The ordinal of the most significant bit in the bit field.
4484 @param OrData The value to OR with the read value from the bit field.
4486 @return The value written back to the MSR.
4491 AsmMsrBitFieldOr64 (
4500 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
4501 result back to the bit field in the 64-bit MSR.
4503 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4504 read result and the value specified by AndData, and writes the result to the
4505 64-bit MSR specified by Index. The value written to the MSR is returned.
4506 Extra left bits in AndData are stripped. The caller must either guarantee
4507 that Index and the data written is valid, or the caller must set up exception
4508 handlers to catch the exceptions. This function is only available on IA-32
4511 If StartBit is greater than 63, then ASSERT().
4512 If EndBit is greater than 63, then ASSERT().
4513 If EndBit is less than StartBit, then ASSERT().
4515 @param Index The 32-bit MSR index to write.
4516 @param StartBit The ordinal of the least significant bit in the bit field.
4518 @param EndBit The ordinal of the most significant bit in the bit field.
4520 @param AndData The value to AND with the read value from the bit field.
4522 @return The value written back to the MSR.
4527 AsmMsrBitFieldAnd64 (
4536 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
4537 bitwise inclusive OR, and writes the result back to the bit field in the
4540 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
4541 a bitwise inclusive OR between the read result and the value specified by
4542 AndData, and writes the result to the 64-bit MSR specified by Index. The
4543 value written to the MSR is returned. Extra left bits in both AndData and
4544 OrData are stripped. The caller must either guarantee that Index and the data
4545 written is valid, or the caller must set up exception handlers to catch the
4546 exceptions. This function is only available on IA-32 and X64.
4548 If StartBit is greater than 63, then ASSERT().
4549 If EndBit is greater than 63, then ASSERT().
4550 If EndBit is less than StartBit, then ASSERT().
4552 @param Index The 32-bit MSR index to write.
4553 @param StartBit The ordinal of the least significant bit in the bit field.
4555 @param EndBit The ordinal of the most significant bit in the bit field.
4557 @param AndData The value to AND with the read value from the bit field.
4558 @param OrData The value to OR with the result of the AND operation.
4560 @return The value written back to the MSR.
4565 AsmMsrBitFieldAndThenOr64 (
4575 Reads the current value of the EFLAGS register.
4577 Reads and returns the current value of the EFLAGS register. This function is
4578 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
4579 64-bit value on X64.
4581 @return EFLAGS on IA-32 or RFLAGS on X64.
4592 Reads the current value of the Control Register 0 (CR0).
4594 Reads and returns the current value of CR0. This function is only available
4595 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4598 @return The value of the Control Register 0 (CR0).
4609 Reads the current value of the Control Register 2 (CR2).
4611 Reads and returns the current value of CR2. This function is only available
4612 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4615 @return The value of the Control Register 2 (CR2).
4626 Reads the current value of the Control Register 3 (CR3).
4628 Reads and returns the current value of CR3. This function is only available
4629 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4632 @return The value of the Control Register 3 (CR3).
4643 Reads the current value of the Control Register 4 (CR4).
4645 Reads and returns the current value of CR4. This function is only available
4646 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4649 @return The value of the Control Register 4 (CR4).
4660 Writes a value to Control Register 0 (CR0).
4662 Writes and returns a new value to CR0. This function is only available on
4663 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4665 @param Cr0 The value to write to CR0.
4667 @return The value written to CR0.
4678 Writes a value to Control Register 2 (CR2).
4680 Writes and returns a new value to CR2. This function is only available on
4681 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4683 @param Cr2 The value to write to CR2.
4685 @return The value written to CR2.
4696 Writes a value to Control Register 3 (CR3).
4698 Writes and returns a new value to CR3. This function is only available on
4699 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4701 @param Cr3 The value to write to CR3.
4703 @return The value written to CR3.
4714 Writes a value to Control Register 4 (CR4).
4716 Writes and returns a new value to CR4. This function is only available on
4717 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4719 @param Cr4 The value to write to CR4.
4721 @return The value written to CR4.
4732 Reads the current value of Debug Register 0 (DR0).
4734 Reads and returns the current value of DR0. This function is only available
4735 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4738 @return The value of Debug Register 0 (DR0).
4749 Reads the current value of Debug Register 1 (DR1).
4751 Reads and returns the current value of DR1. This function is only available
4752 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4755 @return The value of Debug Register 1 (DR1).
4766 Reads the current value of Debug Register 2 (DR2).
4768 Reads and returns the current value of DR2. This function is only available
4769 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4772 @return The value of Debug Register 2 (DR2).
4783 Reads the current value of Debug Register 3 (DR3).
4785 Reads and returns the current value of DR3. This function is only available
4786 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4789 @return The value of Debug Register 3 (DR3).
4800 Reads the current value of Debug Register 4 (DR4).
4802 Reads and returns the current value of DR4. This function is only available
4803 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4806 @return The value of Debug Register 4 (DR4).
4817 Reads the current value of Debug Register 5 (DR5).
4819 Reads and returns the current value of DR5. This function is only available
4820 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4823 @return The value of Debug Register 5 (DR5).
4834 Reads the current value of Debug Register 6 (DR6).
4836 Reads and returns the current value of DR6. This function is only available
4837 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4840 @return The value of Debug Register 6 (DR6).
4851 Reads the current value of Debug Register 7 (DR7).
4853 Reads and returns the current value of DR7. This function is only available
4854 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4857 @return The value of Debug Register 7 (DR7).
4868 Writes a value to Debug Register 0 (DR0).
4870 Writes and returns a new value to DR0. This function is only available on
4871 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4873 @param Dr0 The value to write to Dr0.
4875 @return The value written to Debug Register 0 (DR0).
4886 Writes a value to Debug Register 1 (DR1).
4888 Writes and returns a new value to DR1. This function is only available on
4889 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4891 @param Dr1 The value to write to Dr1.
4893 @return The value written to Debug Register 1 (DR1).
4904 Writes a value to Debug Register 2 (DR2).
4906 Writes and returns a new value to DR2. This function is only available on
4907 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4909 @param Dr2 The value to write to Dr2.
4911 @return The value written to Debug Register 2 (DR2).
4922 Writes a value to Debug Register 3 (DR3).
4924 Writes and returns a new value to DR3. This function is only available on
4925 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4927 @param Dr3 The value to write to Dr3.
4929 @return The value written to Debug Register 3 (DR3).
4940 Writes a value to Debug Register 4 (DR4).
4942 Writes and returns a new value to DR4. This function is only available on
4943 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4945 @param Dr4 The value to write to Dr4.
4947 @return The value written to Debug Register 4 (DR4).
4958 Writes a value to Debug Register 5 (DR5).
4960 Writes and returns a new value to DR5. This function is only available on
4961 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4963 @param Dr5 The value to write to Dr5.
4965 @return The value written to Debug Register 5 (DR5).
4976 Writes a value to Debug Register 6 (DR6).
4978 Writes and returns a new value to DR6. This function is only available on
4979 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4981 @param Dr6 The value to write to Dr6.
4983 @return The value written to Debug Register 6 (DR6).
4994 Writes a value to Debug Register 7 (DR7).
4996 Writes and returns a new value to DR7. This function is only available on
4997 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4999 @param Dr7 The value to write to Dr7.
5001 @return The value written to Debug Register 7 (DR7).
5012 Reads the current value of Code Segment Register (CS).
5014 Reads and returns the current value of CS. This function is only available on
5017 @return The current value of CS.
5028 Reads the current value of Data Segment Register (DS).
5030 Reads and returns the current value of DS. This function is only available on
5033 @return The current value of DS.
5044 Reads the current value of Extra Segment Register (ES).
5046 Reads and returns the current value of ES. This function is only available on
5049 @return The current value of ES.
5060 Reads the current value of FS Data Segment Register (FS).
5062 Reads and returns the current value of FS. This function is only available on
5065 @return The current value of FS.
5076 Reads the current value of GS Data Segment Register (GS).
5078 Reads and returns the current value of GS. This function is only available on
5081 @return The current value of GS.
5092 Reads the current value of Stack Segment Register (SS).
5094 Reads and returns the current value of SS. This function is only available on
5097 @return The current value of SS.
5108 Reads the current value of Task Register (TR).
5110 Reads and returns the current value of TR. This function is only available on
5113 @return The current value of TR.
5124 Reads the current Global Descriptor Table Register(GDTR) descriptor.
5126 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
5127 function is only available on IA-32 and X64.
5129 If Gdtr is NULL, then ASSERT().
5131 @param Gdtr Pointer to a GDTR descriptor.
5137 OUT IA32_DESCRIPTOR
*Gdtr
5142 Writes the current Global Descriptor Table Register (GDTR) descriptor.
5144 Writes and the current GDTR descriptor specified by Gdtr. This function is
5145 only available on IA-32 and X64.
5147 If Gdtr is NULL, then ASSERT().
5149 @param Gdtr Pointer to a GDTR descriptor.
5155 IN CONST IA32_DESCRIPTOR
*Gdtr
5160 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
5162 Reads and returns the current IDTR descriptor and returns it in Idtr. This
5163 function is only available on IA-32 and X64.
5165 If Idtr is NULL, then ASSERT().
5167 @param Idtr Pointer to a IDTR descriptor.
5173 OUT IA32_DESCRIPTOR
*Idtr
5178 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
5180 Writes the current IDTR descriptor and returns it in Idtr. This function is
5181 only available on IA-32 and X64.
5183 If Idtr is NULL, then ASSERT().
5185 @param Idtr Pointer to a IDTR descriptor.
5191 IN CONST IA32_DESCRIPTOR
*Idtr
5196 Reads the current Local Descriptor Table Register(LDTR) selector.
5198 Reads and returns the current 16-bit LDTR descriptor value. This function is
5199 only available on IA-32 and X64.
5201 @return The current selector of LDT.
5212 Writes the current Local Descriptor Table Register (GDTR) selector.
5214 Writes and the current LDTR descriptor specified by Ldtr. This function is
5215 only available on IA-32 and X64.
5217 @param Ldtr 16-bit LDTR selector value.
5228 Save the current floating point/SSE/SSE2 context to a buffer.
5230 Saves the current floating point/SSE/SSE2 state to the buffer specified by
5231 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
5232 available on IA-32 and X64.
5234 If Buffer is NULL, then ASSERT().
5235 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
5237 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
5243 OUT IA32_FX_BUFFER
*Buffer
5248 Restores the current floating point/SSE/SSE2 context from a buffer.
5250 Restores the current floating point/SSE/SSE2 state from the buffer specified
5251 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
5252 only available on IA-32 and X64.
5254 If Buffer is NULL, then ASSERT().
5255 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
5256 If Buffer was not saved with AsmFxSave(), then ASSERT().
5258 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
5264 IN CONST IA32_FX_BUFFER
*Buffer
5269 Reads the current value of 64-bit MMX Register #0 (MM0).
5271 Reads and returns the current value of MM0. This function is only available
5274 @return The current value of MM0.
5285 Reads the current value of 64-bit MMX Register #1 (MM1).
5287 Reads and returns the current value of MM1. This function is only available
5290 @return The current value of MM1.
5301 Reads the current value of 64-bit MMX Register #2 (MM2).
5303 Reads and returns the current value of MM2. This function is only available
5306 @return The current value of MM2.
5317 Reads the current value of 64-bit MMX Register #3 (MM3).
5319 Reads and returns the current value of MM3. This function is only available
5322 @return The current value of MM3.
5333 Reads the current value of 64-bit MMX Register #4 (MM4).
5335 Reads and returns the current value of MM4. This function is only available
5338 @return The current value of MM4.
5349 Reads the current value of 64-bit MMX Register #5 (MM5).
5351 Reads and returns the current value of MM5. This function is only available
5354 @return The current value of MM5.
5365 Reads the current value of 64-bit MMX Register #6 (MM6).
5367 Reads and returns the current value of MM6. This function is only available
5370 @return The current value of MM6.
5381 Reads the current value of 64-bit MMX Register #7 (MM7).
5383 Reads and returns the current value of MM7. This function is only available
5386 @return The current value of MM7.
5397 Writes the current value of 64-bit MMX Register #0 (MM0).
5399 Writes the current value of MM0. This function is only available on IA32 and
5402 @param Value The 64-bit value to write to MM0.
5413 Writes the current value of 64-bit MMX Register #1 (MM1).
5415 Writes the current value of MM1. This function is only available on IA32 and
5418 @param Value The 64-bit value to write to MM1.
5429 Writes the current value of 64-bit MMX Register #2 (MM2).
5431 Writes the current value of MM2. This function is only available on IA32 and
5434 @param Value The 64-bit value to write to MM2.
5445 Writes the current value of 64-bit MMX Register #3 (MM3).
5447 Writes the current value of MM3. This function is only available on IA32 and
5450 @param Value The 64-bit value to write to MM3.
5461 Writes the current value of 64-bit MMX Register #4 (MM4).
5463 Writes the current value of MM4. This function is only available on IA32 and
5466 @param Value The 64-bit value to write to MM4.
5477 Writes the current value of 64-bit MMX Register #5 (MM5).
5479 Writes the current value of MM5. This function is only available on IA32 and
5482 @param Value The 64-bit value to write to MM5.
5493 Writes the current value of 64-bit MMX Register #6 (MM6).
5495 Writes the current value of MM6. This function is only available on IA32 and
5498 @param Value The 64-bit value to write to MM6.
5509 Writes the current value of 64-bit MMX Register #7 (MM7).
5511 Writes the current value of MM7. This function is only available on IA32 and
5514 @param Value The 64-bit value to write to MM7.
5525 Reads the current value of Time Stamp Counter (TSC).
5527 Reads and returns the current value of TSC. This function is only available
5530 @return The current value of TSC
5541 Reads the current value of a Performance Counter (PMC).
5543 Reads and returns the current value of performance counter specified by
5544 Index. This function is only available on IA-32 and X64.
5546 @param Index The 32-bit Performance Counter index to read.
5548 @return The value of the PMC specified by Index.
5559 Sets up a monitor buffer that is used by AsmMwait().
5561 Executes a MONITOR instruction with the register state specified by Eax, Ecx
5562 and Edx. Returns Eax. This function is only available on IA-32 and X64.
5564 @param Eax The value to load into EAX or RAX before executing the MONITOR
5566 @param Ecx The value to load into ECX or RCX before executing the MONITOR
5568 @param Edx The value to load into EDX or RDX before executing the MONITOR
5584 Executes an MWAIT instruction.
5586 Executes an MWAIT instruction with the register state specified by Eax and
5587 Ecx. Returns Eax. This function is only available on IA-32 and X64.
5589 @param Eax The value to load into EAX or RAX before executing the MONITOR
5591 @param Ecx The value to load into ECX or RCX before executing the MONITOR
5606 Executes a WBINVD instruction.
5608 Executes a WBINVD instruction. This function is only available on IA-32 and
5620 Executes a INVD instruction.
5622 Executes a INVD instruction. This function is only available on IA-32 and
5634 Flushes a cache line from all the instruction and data caches within the
5635 coherency domain of the CPU.
5637 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
5638 This function is only available on IA-32 and X64.
5640 @param LinearAddress The address of the cache line to flush. If the CPU is
5641 in a physical addressing mode, then LinearAddress is a
5642 physical address. If the CPU is in a virtual
5643 addressing mode, then LinearAddress is a virtual
5646 @return LinearAddress
5651 IN VOID
*LinearAddress
5656 Enables the 32-bit paging mode on the CPU.
5658 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
5659 must be properly initialized prior to calling this service. This function
5660 assumes the current execution mode is 32-bit protected mode. This function is
5661 only available on IA-32. After the 32-bit paging mode is enabled, control is
5662 transferred to the function specified by EntryPoint using the new stack
5663 specified by NewStack and passing in the parameters specified by Context1 and
5664 Context2. Context1 and Context2 are optional and may be NULL. The function
5665 EntryPoint must never return.
5667 If the current execution mode is not 32-bit protected mode, then ASSERT().
5668 If EntryPoint is NULL, then ASSERT().
5669 If NewStack is NULL, then ASSERT().
5671 There are a number of constraints that must be followed before calling this
5673 1) Interrupts must be disabled.
5674 2) The caller must be in 32-bit protected mode with flat descriptors. This
5675 means all descriptors must have a base of 0 and a limit of 4GB.
5676 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
5678 4) CR3 must point to valid page tables that will be used once the transition
5679 is complete, and those page tables must guarantee that the pages for this
5680 function and the stack are identity mapped.
5682 @param EntryPoint A pointer to function to call with the new stack after
5684 @param Context1 A pointer to the context to pass into the EntryPoint
5685 function as the first parameter after paging is enabled.
5686 @param Context2 A pointer to the context to pass into the EntryPoint
5687 function as the second parameter after paging is enabled.
5688 @param NewStack A pointer to the new stack to use for the EntryPoint
5689 function after paging is enabled.
5695 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
5696 IN VOID
*Context1
, OPTIONAL
5697 IN VOID
*Context2
, OPTIONAL
5703 Disables the 32-bit paging mode on the CPU.
5705 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
5706 mode. This function assumes the current execution mode is 32-paged protected
5707 mode. This function is only available on IA-32. After the 32-bit paging mode
5708 is disabled, control is transferred to the function specified by EntryPoint
5709 using the new stack specified by NewStack and passing in the parameters
5710 specified by Context1 and Context2. Context1 and Context2 are optional and
5711 may be NULL. The function EntryPoint must never return.
5713 If the current execution mode is not 32-bit paged mode, then ASSERT().
5714 If EntryPoint is NULL, then ASSERT().
5715 If NewStack is NULL, then ASSERT().
5717 There are a number of constraints that must be followed before calling this
5719 1) Interrupts must be disabled.
5720 2) The caller must be in 32-bit paged mode.
5721 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
5722 4) CR3 must point to valid page tables that guarantee that the pages for
5723 this function and the stack are identity mapped.
5725 @param EntryPoint A pointer to function to call with the new stack after
5727 @param Context1 A pointer to the context to pass into the EntryPoint
5728 function as the first parameter after paging is disabled.
5729 @param Context2 A pointer to the context to pass into the EntryPoint
5730 function as the second parameter after paging is
5732 @param NewStack A pointer to the new stack to use for the EntryPoint
5733 function after paging is disabled.
5738 AsmDisablePaging32 (
5739 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
5740 IN VOID
*Context1
, OPTIONAL
5741 IN VOID
*Context2
, OPTIONAL
5747 Enables the 64-bit paging mode on the CPU.
5749 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
5750 must be properly initialized prior to calling this service. This function
5751 assumes the current execution mode is 32-bit protected mode with flat
5752 descriptors. This function is only available on IA-32. After the 64-bit
5753 paging mode is enabled, control is transferred to the function specified by
5754 EntryPoint using the new stack specified by NewStack and passing in the
5755 parameters specified by Context1 and Context2. Context1 and Context2 are
5756 optional and may be 0. The function EntryPoint must never return.
5758 If the current execution mode is not 32-bit protected mode with flat
5759 descriptors, then ASSERT().
5760 If EntryPoint is 0, then ASSERT().
5761 If NewStack is 0, then ASSERT().
5763 @param Cs The 16-bit selector to load in the CS before EntryPoint
5764 is called. The descriptor in the GDT that this selector
5765 references must be setup for long mode.
5766 @param EntryPoint The 64-bit virtual address of the function to call with
5767 the new stack after paging is enabled.
5768 @param Context1 The 64-bit virtual address of the context to pass into
5769 the EntryPoint function as the first parameter after
5771 @param Context2 The 64-bit virtual address of the context to pass into
5772 the EntryPoint function as the second parameter after
5774 @param NewStack The 64-bit virtual address of the new stack to use for
5775 the EntryPoint function after paging is enabled.
5781 IN UINT16 CodeSelector
,
5782 IN UINT64 EntryPoint
,
5783 IN UINT64 Context1
, OPTIONAL
5784 IN UINT64 Context2
, OPTIONAL
5790 Disables the 64-bit paging mode on the CPU.
5792 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
5793 mode. This function assumes the current execution mode is 64-paging mode.
5794 This function is only available on X64. After the 64-bit paging mode is
5795 disabled, control is transferred to the function specified by EntryPoint
5796 using the new stack specified by NewStack and passing in the parameters
5797 specified by Context1 and Context2. Context1 and Context2 are optional and
5798 may be 0. The function EntryPoint must never return.
5800 If the current execution mode is not 64-bit paged mode, then ASSERT().
5801 If EntryPoint is 0, then ASSERT().
5802 If NewStack is 0, then ASSERT().
5804 @param Cs The 16-bit selector to load in the CS before EntryPoint
5805 is called. The descriptor in the GDT that this selector
5806 references must be setup for 32-bit protected mode.
5807 @param EntryPoint The 64-bit virtual address of the function to call with
5808 the new stack after paging is disabled.
5809 @param Context1 The 64-bit virtual address of the context to pass into
5810 the EntryPoint function as the first parameter after
5812 @param Context2 The 64-bit virtual address of the context to pass into
5813 the EntryPoint function as the second parameter after
5815 @param NewStack The 64-bit virtual address of the new stack to use for
5816 the EntryPoint function after paging is disabled.
5821 AsmDisablePaging64 (
5822 IN UINT16 CodeSelector
,
5823 IN UINT32 EntryPoint
,
5824 IN UINT32 Context1
, OPTIONAL
5825 IN UINT32 Context2
, OPTIONAL
5831 // 16-bit thunking services
5835 Retrieves the properties for 16-bit thunk functions.
5837 Computes the size of the buffer and stack below 1MB required to use the
5838 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
5839 buffer size is returned in RealModeBufferSize, and the stack size is returned
5840 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
5841 then the actual minimum stack size is ExtraStackSize plus the maximum number
5842 of bytes that need to be passed to the 16-bit real mode code.
5844 If RealModeBufferSize is NULL, then ASSERT().
5845 If ExtraStackSize is NULL, then ASSERT().
5847 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
5848 required to use the 16-bit thunk functions.
5849 @param ExtraStackSize A pointer to the extra size of stack below 1MB
5850 that the 16-bit thunk functions require for
5851 temporary storage in the transition to and from
5857 AsmGetThunk16Properties (
5858 OUT UINT32
*RealModeBufferSize
,
5859 OUT UINT32
*ExtraStackSize
5864 Prepares all structures a code required to use AsmThunk16().
5866 Prepares all structures and code required to use AsmThunk16().
5868 If ThunkContext is NULL, then ASSERT().
5870 @param ThunkContext A pointer to the context structure that describes the
5871 16-bit real mode code to call.
5877 OUT THUNK_CONTEXT
*ThunkContext
5882 Transfers control to a 16-bit real mode entry point and returns the results.
5884 Transfers control to a 16-bit real mode entry point and returns the results.
5885 AsmPrepareThunk16() must be called with ThunkContext before this function is
5888 If ThunkContext is NULL, then ASSERT().
5889 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
5891 @param ThunkContext A pointer to the context structure that describes the
5892 16-bit real mode code to call.
5898 IN OUT THUNK_CONTEXT
*ThunkContext
5903 Prepares all structures and code for a 16-bit real mode thunk, transfers
5904 control to a 16-bit real mode entry point, and returns the results.
5906 Prepares all structures and code for a 16-bit real mode thunk, transfers
5907 control to a 16-bit real mode entry point, and returns the results. If the
5908 caller only need to perform a single 16-bit real mode thunk, then this
5909 service should be used. If the caller intends to make more than one 16-bit
5910 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
5911 once and AsmThunk16() can be called for each 16-bit real mode thunk.
5913 If ThunkContext is NULL, then ASSERT().
5915 @param ThunkContext A pointer to the context structure that describes the
5916 16-bit real mode code to call.
5921 AsmPrepareAndThunk16 (
5922 IN OUT THUNK_CONTEXT
*ThunkContext