2 Memory-only library functions with no library constructor/destructor
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // Definitions for architecture specific types
20 // These include SPIN_LOCK and BASE_LIBRARY_JUMP_BUFFER
26 typedef volatile UINTN SPIN_LOCK
;
28 #if defined (MDE_CPU_IA32)
30 // IA32 context buffer used by SetJump() and LongJump()
39 } BASE_LIBRARY_JUMP_BUFFER
;
41 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 4
43 #elif defined (MDE_CPU_IPF)
46 // IPF context buffer used by SetJump() and LongJump()
81 UINT64 AfterSpillUNAT
;
87 } BASE_LIBRARY_JUMP_BUFFER
;
89 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10
91 #elif defined (MDE_CPU_X64)
93 // X64 context buffer used by SetJump() and LongJump()
106 } BASE_LIBRARY_JUMP_BUFFER
;
108 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
110 #elif defined (MDE_CPU_EBC)
112 // EBC context buffer used by SetJump() and LongJump()
120 } BASE_LIBRARY_JUMP_BUFFER
;
122 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
125 #error Unknown Processor Type
133 Copies one Null-terminated Unicode string to another Null-terminated Unicode
134 string and returns the new Unicode string.
136 This function copies the contents of the Unicode string Source to the Unicode
137 string Destination, and returns Destination. If Source and Destination
138 overlap, then the results are undefined.
140 If Destination is NULL, then ASSERT().
141 If Destination is not aligned on a 16-bit boundary, then ASSERT().
142 If Source is NULL, then ASSERT().
143 If Source is not aligned on a 16-bit boundary, then ASSERT().
144 If Source and Destination overlap, then ASSERT().
145 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
146 PcdMaximumUnicodeStringLength Unicode characters not including the
147 Null-terminator, then ASSERT().
149 @param Destination Pointer to a Null-terminated Unicode string.
150 @param Source Pointer to a Null-terminated Unicode string.
158 OUT CHAR16
*Destination
,
159 IN CONST CHAR16
*Source
164 Copies one Null-terminated Unicode string with a maximum length to another
165 Null-terminated Unicode string with a maximum length and returns the new
168 This function copies the contents of the Unicode string Source to the Unicode
169 string Destination, and returns Destination. At most, Length Unicode
170 characters are copied from Source to Destination. If Length is 0, then
171 Destination is returned unmodified. If Length is greater that the number of
172 Unicode characters in Source, then Destination is padded with Null Unicode
173 characters. If Source and Destination overlap, then the results are
176 If Length > 0 and Destination is NULL, then ASSERT().
177 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
178 If Length > 0 and Source is NULL, then ASSERT().
179 If Length > 0 and Source is not aligned on a 16-bit bounadry, then ASSERT().
180 If Source and Destination overlap, then ASSERT().
181 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
182 PcdMaximumUnicodeStringLength Unicode characters not including the
183 Null-terminator, then ASSERT().
185 @param Destination Pointer to a Null-terminated Unicode string.
186 @param Source Pointer to a Null-terminated Unicode string.
187 @param Length Maximum number of Unicode characters to copy.
195 OUT CHAR16
*Destination
,
196 IN CONST CHAR16
*Source
,
202 Returns the length of a Null-terminated Unicode string.
204 This function returns the number of Unicode characters in the Null-terminated
205 Unicode string specified by String.
207 If String is NULL, then ASSERT().
208 If String is not aligned on a 16-bit boundary, then ASSERT().
209 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
210 PcdMaximumUnicodeStringLength Unicode characters not including the
211 Null-terminator, then ASSERT().
213 @param String Pointer to a Null-terminated Unicode string.
215 @return The length of String.
221 IN CONST CHAR16
*String
226 Returns the size of a Null-terminated Unicode string in bytes, including the
229 This function returns the size, in bytes, of the Null-terminated Unicode
230 string specified by String.
232 If String is NULL, then ASSERT().
233 If String is not aligned on a 16-bit boundary, then ASSERT().
234 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
235 PcdMaximumUnicodeStringLength Unicode characters not including the
236 Null-terminator, then ASSERT().
238 @param String Pointer to a Null-terminated Unicode string.
240 @return The size of String.
246 IN CONST CHAR16
*String
251 Compares two Null-terminated Unicode strings, and returns the difference
252 between the first mismatched Unicode characters.
254 This function compares the Null-terminated Unicode string FirstString to the
255 Null-terminated Unicode string SecondString. If FirstString is identical to
256 SecondString, then 0 is returned. Otherwise, the value returned is the first
257 mismatched Unicode character in SecondString subtracted from the first
258 mismatched Unicode character in FirstString.
260 If FirstString is NULL, then ASSERT().
261 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
262 If SecondString is NULL, then ASSERT().
263 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
264 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
265 than PcdMaximumUnicodeStringLength Unicode characters not including the
266 Null-terminator, then ASSERT().
267 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
268 than PcdMaximumUnicodeStringLength Unicode characters not including the
269 Null-terminator, then ASSERT().
271 @param FirstString Pointer to a Null-terminated Unicode string.
272 @param SecondString Pointer to a Null-terminated Unicode string.
274 @retval 0 FirstString is identical to SecondString.
275 @retval !=0 FirstString is not identical to SecondString.
281 IN CONST CHAR16
*FirstString
,
282 IN CONST CHAR16
*SecondString
287 Compares two Null-terminated Unicode strings with maximum lengths, and
288 returns the difference between the first mismatched Unicode characters.
290 This function compares the Null-terminated Unicode string FirstString to the
291 Null-terminated Unicode string SecondString. At most, Length Unicode
292 characters will be compared. If Length is 0, then 0 is returned. If
293 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
294 value returned is the first mismatched Unicode character in SecondString
295 subtracted from the first mismatched Unicode character in FirstString.
297 If Length > 0 and FirstString is NULL, then ASSERT().
298 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().
299 If Length > 0 and SecondString is NULL, then ASSERT().
300 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().
301 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
302 than PcdMaximumUnicodeStringLength Unicode characters not including the
303 Null-terminator, then ASSERT().
304 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
305 than PcdMaximumUnicodeStringLength Unicode characters not including the
306 Null-terminator, then ASSERT().
308 @param FirstString Pointer to a Null-terminated Unicode string.
309 @param SecondString Pointer to a Null-terminated Unicode string.
310 @param Length Maximum number of Unicode characters to compare.
312 @retval 0 FirstString is identical to SecondString.
313 @retval !=0 FirstString is not identical to SecondString.
319 IN CONST CHAR16
*FirstString
,
320 IN CONST CHAR16
*SecondString
,
326 Concatenates one Null-terminated Unicode string to another Null-terminated
327 Unicode string, and returns the concatenated Unicode string.
329 This function concatenates two Null-terminated Unicode strings. The contents
330 of Null-terminated Unicode string Source are concatenated to the end of
331 Null-terminated Unicode string Destination. The Null-terminated concatenated
332 Unicode String is returned. If Source and Destination overlap, then the
333 results are undefined.
335 If Destination is NULL, then ASSERT().
336 If Destination is not aligned on a 16-bit bounadary, then ASSERT().
337 If Source is NULL, then ASSERT().
338 If Source is not aligned on a 16-bit bounadary, then ASSERT().
339 If Source and Destination overlap, then ASSERT().
340 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
341 than PcdMaximumUnicodeStringLength Unicode characters not including the
342 Null-terminator, then ASSERT().
343 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
344 PcdMaximumUnicodeStringLength Unicode characters not including the
345 Null-terminator, then ASSERT().
346 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
347 and Source results in a Unicode string with more than
348 PcdMaximumUnicodeStringLength Unicode characters not including the
349 Null-terminator, then ASSERT().
351 @param Destination Pointer to a Null-terminated Unicode string.
352 @param Source Pointer to a Null-terminated Unicode string.
360 IN OUT CHAR16
*Destination
,
361 IN CONST CHAR16
*Source
366 Concatenates one Null-terminated Unicode string with a maximum length to the
367 end of another Null-terminated Unicode string, and returns the concatenated
370 This function concatenates two Null-terminated Unicode strings. The contents
371 of Null-terminated Unicode string Source are concatenated to the end of
372 Null-terminated Unicode string Destination, and Destination is returned. At
373 most, Length Unicode characters are concatenated from Source to the end of
374 Destination, and Destination is always Null-terminated. If Length is 0, then
375 Destination is returned unmodified. If Source and Destination overlap, then
376 the results are undefined.
378 If Destination is NULL, then ASSERT().
379 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
380 If Length > 0 and Source is NULL, then ASSERT().
381 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
382 If Source and Destination overlap, then ASSERT().
383 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
384 than PcdMaximumUnicodeStringLength Unicode characters not including the
385 Null-terminator, then ASSERT().
386 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
387 PcdMaximumUnicodeStringLength Unicode characters not including the
388 Null-terminator, then ASSERT().
389 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
390 and Source results in a Unicode string with more than
391 PcdMaximumUnicodeStringLength Unicode characters not including the
392 Null-terminator, then ASSERT().
394 @param Destination Pointer to a Null-terminated Unicode string.
395 @param Source Pointer to a Null-terminated Unicode string.
396 @param Length Maximum number of Unicode characters to concatenate from
405 IN OUT CHAR16
*Destination
,
406 IN CONST CHAR16
*Source
,
411 Returns the first occurance of a Null-terminated Unicode sub-string
412 in a Null-terminated Unicode string.
414 This function scans the contents of the Null-terminated Unicode string
415 specified by String and returns the first occurrence of SearchString.
416 If SearchString is not found in String, then NULL is returned. If
417 the length of SearchString is zero, then String is
420 If String is NULL, then ASSERT().
421 If String is not aligned on a 16-bit boundary, then ASSERT().
422 If SearchString is NULL, then ASSERT().
423 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
425 If PcdMaximumUnicodeStringLength is not zero, and SearchString
426 or String contains more than PcdMaximumUnicodeStringLength Unicode
427 characters not including the Null-terminator, then ASSERT().
429 @param String Pointer to a Null-terminated Unicode string.
430 @param SearchString Pointer to a Null-terminated Unicode string to search for.
432 @retval NULL If the SearchString does not appear in String.
433 @retval !NULL If there is a match.
439 IN CONST CHAR16
*String
,
440 IN CONST CHAR16
*SearchString
444 Convert a Null-terminated Unicode decimal string to a value of
447 This function returns a value of type UINTN by interpreting the contents
448 of the Unicode string specified by String as a decimal number. The format
449 of the input Unicode string String is:
451 [spaces] [decimal digits].
453 The valid decimal digit character is in the range [0-9]. The
454 function will ignore the pad space, which includes spaces or
455 tab characters, before [decimal digits]. The running zero in the
456 beginning of [decimal digits] will be ignored. Then, the function
457 stops at the first character that is a not a valid decimal character
458 or a Null-terminator, whichever one comes first.
460 If String is NULL, then ASSERT().
461 If String is not aligned in a 16-bit boundary, then ASSERT().
462 If String has only pad spaces, then 0 is returned.
463 If String has no pad spaces or valid decimal digits,
465 If the number represented by String overflows according
466 to the range defined by UINTN, then ASSERT().
468 If PcdMaximumUnicodeStringLength is not zero, and String contains
469 more than PcdMaximumUnicodeStringLength Unicode characters not including
470 the Null-terminator, then ASSERT().
472 @param String Pointer to a Null-terminated Unicode string.
480 IN CONST CHAR16
*String
484 Convert a Null-terminated Unicode decimal string to a value of
487 This function returns a value of type UINT64 by interpreting the contents
488 of the Unicode string specified by String as a decimal number. The format
489 of the input Unicode string String is:
491 [spaces] [decimal digits].
493 The valid decimal digit character is in the range [0-9]. The
494 function will ignore the pad space, which includes spaces or
495 tab characters, before [decimal digits]. The running zero in the
496 beginning of [decimal digits] will be ignored. Then, the function
497 stops at the first character that is a not a valid decimal character
498 or a Null-terminator, whichever one comes first.
500 If String is NULL, then ASSERT().
501 If String is not aligned in a 16-bit boundary, then ASSERT().
502 If String has only pad spaces, then 0 is returned.
503 If String has no pad spaces or valid decimal digits,
505 If the number represented by String overflows according
506 to the range defined by UINT64, then ASSERT().
508 If PcdMaximumUnicodeStringLength is not zero, and String contains
509 more than PcdMaximumUnicodeStringLength Unicode characters not including
510 the Null-terminator, then ASSERT().
512 @param String Pointer to a Null-terminated Unicode string.
520 IN CONST CHAR16
*String
525 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
527 This function returns a value of type UINTN by interpreting the contents
528 of the Unicode string specified by String as a hexadecimal number.
529 The format of the input Unicode string String is:
531 [spaces][zeros][x][hexadecimal digits].
533 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
534 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
535 If "x" appears in the input string, it must be prefixed with at least one 0.
536 The function will ignore the pad space, which includes spaces or tab characters,
537 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
538 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
539 first valid hexadecimal digit. Then, the function stops at the first character that is
540 a not a valid hexadecimal character or NULL, whichever one comes first.
542 If String is NULL, then ASSERT().
543 If String is not aligned in a 16-bit boundary, then ASSERT().
544 If String has only pad spaces, then zero is returned.
545 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
546 then zero is returned.
547 If the number represented by String overflows according to the range defined by
548 UINTN, then ASSERT().
550 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
551 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
554 @param String Pointer to a Null-terminated Unicode string.
562 IN CONST CHAR16
*String
567 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
569 This function returns a value of type UINT64 by interpreting the contents
570 of the Unicode string specified by String as a hexadecimal number.
571 The format of the input Unicode string String is
573 [spaces][zeros][x][hexadecimal digits].
575 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
576 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
577 If "x" appears in the input string, it must be prefixed with at least one 0.
578 The function will ignore the pad space, which includes spaces or tab characters,
579 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
580 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
581 first valid hexadecimal digit. Then, the function stops at the first character that is
582 a not a valid hexadecimal character or NULL, whichever one comes first.
584 If String is NULL, then ASSERT().
585 If String is not aligned in a 16-bit boundary, then ASSERT().
586 If String has only pad spaces, then zero is returned.
587 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
588 then zero is returned.
589 If the number represented by String overflows according to the range defined by
590 UINT64, then ASSERT().
592 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
593 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
596 @param String Pointer to a Null-terminated Unicode string.
604 IN CONST CHAR16
*String
608 Convert a nibble in the low 4 bits of a byte to a Unicode hexadecimal character.
610 This function converts a nibble in the low 4 bits of a byte to a Unicode hexadecimal
611 character For example, the nibble 0x01 and 0x0A will converted to L'1' and L'A'
614 The upper nibble in the input byte will be masked off.
616 @param Nibble The nibble which is in the low 4 bits of the input byte.
618 @retval CHAR16 The Unicode hexadecimal character.
629 Convert binary buffer to a Unicode String in a specified sequence.
631 This function converts bytes in the binary Buffer Buf to a Unicode String Str.
632 Each byte will be represented by two Unicode characters. For example, byte 0xA1 will
633 be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character
634 for the Most Significant Nibble will be put before the Unicode Character for the Least Significant
635 Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1".
636 For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the
637 the last character in the output string. The one next to first byte will be put into the
638 character before the last character. This rules applies to the rest of the bytes. The Unicode
639 character by the last byte will be put into the first character in the output string. For example,
640 the input buffer for a 64-bits unsigned integrer 0x12345678abcdef1234 will be converted to
641 a Unicode string equal to L"12345678abcdef1234".
643 @param String On input, String is pointed to the buffer allocated for the convertion.
644 @param StringLen The Length of String buffer to hold the output String. The length must include the tailing '\0' character.
645 The StringLen required to convert a N bytes Buffer will be a least equal to or greater
647 @param Buffer The pointer to a input buffer.
648 @param BufferSizeInBytes Lenth in bytes of the input buffer.
651 @retval EFI_SUCCESS The convertion is successfull. All bytes in Buffer has been convert to the corresponding
652 Unicode character and placed into the right place in String.
653 @retval EFI_BUFFER_TOO_SMALL StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to
654 complete the convertion.
659 IN OUT CHAR16
*String
,
660 IN OUT UINTN
*StringLen
,
661 IN CONST UINT8
*Buffer
,
662 IN UINTN BufferSizeInBytes
668 Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.
670 This function converts a Unicode string consisting of characters in the range of Hexadecimal
671 character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop
672 at the first non-hexadecimal character or the NULL character. The convertion process can be
673 simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be
674 converted into one byte. The first Unicode character represents the Most Significant Nibble and the
675 second Unicode character represents the Least Significant Nibble in the output byte.
676 The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode
677 characters represent the the byte preceding the last byte. This rule applies to the rest pairs of bytes.
678 The last pair represent the first byte in the output buffer.
680 For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes
681 (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".
683 If String has N valid hexadecimal characters for conversion, the caller must make sure Buffer is at least
684 N/2 (if N is even) or (N+1)/2 (if N if odd) bytes.
686 @param Buffer The output buffer allocated by the caller.
687 @param BufferSizeInBytes On input, the size in bytes of Buffer. On output, it is updated to
688 contain the size of the Buffer which is actually used for the converstion.
689 For Unicode string with 2*N hexadecimal characters (not including the
690 tailing NULL character), N bytes of Buffer will be used for the output.
691 @param String The input hexadecimal string.
692 @param ConvertedStrLen The number of hexadecimal characters used to produce content in output
695 @retval RETURN_BUFFER_TOO_SMALL The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes
696 will be updated to the size required for the converstion.
697 @retval RETURN_SUCCESS The convertion is successful or the first Unicode character from String
698 is hexadecimal. If ConvertedStrLen is not NULL, it is updated
699 to the number of hexadecimal character used for the converstion.
705 IN OUT UINTN
*BufferSizeInBytes
,
706 IN CONST CHAR16
*String
,
707 OUT UINTN
*ConvertedStrLen OPTIONAL
713 Test if a Unicode character is a hexadecimal digit. If true, the input
714 Unicode character is converted to a byte.
716 This function tests if a Unicode character is a hexadecimal digit. If true, the input
717 Unicode character is converted to a byte. For example, Unicode character
718 L'A' will be converted to 0x0A.
720 If Digit is NULL, then ASSERT.
722 @retval TRUE Char is in the range of Hexadecimal number. Digit is updated
723 to the byte value of the number.
724 @retval FALSE Char is not in the range of Hexadecimal number. Digit is keep
737 Convert one Null-terminated Unicode string to a Null-terminated
738 ASCII string and returns the ASCII string.
740 This function converts the content of the Unicode string Source
741 to the ASCII string Destination by copying the lower 8 bits of
742 each Unicode character. It returns Destination.
744 If any Unicode characters in Source contain non-zero value in
745 the upper 8 bits, then ASSERT().
747 If Destination is NULL, then ASSERT().
748 If Source is NULL, then ASSERT().
749 If Source is not aligned on a 16-bit boundary, then ASSERT().
750 If Source and Destination overlap, then ASSERT().
752 If PcdMaximumUnicodeStringLength is not zero, and Source contains
753 more than PcdMaximumUnicodeStringLength Unicode characters not including
754 the Null-terminator, then ASSERT().
756 If PcdMaximumAsciiStringLength is not zero, and Source contains more
757 than PcdMaximumAsciiStringLength Unicode characters not including the
758 Null-terminator, then ASSERT().
760 @param Source Pointer to a Null-terminated Unicode string.
761 @param Destination Pointer to a Null-terminated ASCII string.
768 UnicodeStrToAsciiStr (
769 IN CONST CHAR16
*Source
,
770 OUT CHAR8
*Destination
775 Copies one Null-terminated ASCII string to another Null-terminated ASCII
776 string and returns the new ASCII string.
778 This function copies the contents of the ASCII string Source to the ASCII
779 string Destination, and returns Destination. If Source and Destination
780 overlap, then the results are undefined.
782 If Destination is NULL, then ASSERT().
783 If Source is NULL, then ASSERT().
784 If Source and Destination overlap, then ASSERT().
785 If PcdMaximumAsciiStringLength is not zero and Source contains more than
786 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
789 @param Destination Pointer to a Null-terminated ASCII string.
790 @param Source Pointer to a Null-terminated ASCII string.
798 OUT CHAR8
*Destination
,
799 IN CONST CHAR8
*Source
804 Copies one Null-terminated ASCII string with a maximum length to another
805 Null-terminated ASCII string with a maximum length and returns the new ASCII
808 This function copies the contents of the ASCII string Source to the ASCII
809 string Destination, and returns Destination. At most, Length ASCII characters
810 are copied from Source to Destination. If Length is 0, then Destination is
811 returned unmodified. If Length is greater that the number of ASCII characters
812 in Source, then Destination is padded with Null ASCII characters. If Source
813 and Destination overlap, then the results are undefined.
815 If Destination is NULL, then ASSERT().
816 If Source is NULL, then ASSERT().
817 If Source and Destination overlap, then ASSERT().
818 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
819 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
822 @param Destination Pointer to a Null-terminated ASCII string.
823 @param Source Pointer to a Null-terminated ASCII string.
824 @param Length Maximum number of ASCII characters to copy.
832 OUT CHAR8
*Destination
,
833 IN CONST CHAR8
*Source
,
839 Returns the length of a Null-terminated ASCII string.
841 This function returns the number of ASCII characters in the Null-terminated
842 ASCII string specified by String.
844 If Length > 0 and Destination is NULL, then ASSERT().
845 If Length > 0 and Source is NULL, then ASSERT().
846 If PcdMaximumAsciiStringLength is not zero and String contains more than
847 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
850 @param String Pointer to a Null-terminated ASCII string.
852 @return The length of String.
858 IN CONST CHAR8
*String
863 Returns the size of a Null-terminated ASCII string in bytes, including the
866 This function returns the size, in bytes, of the Null-terminated ASCII string
869 If String is NULL, then ASSERT().
870 If PcdMaximumAsciiStringLength is not zero and String contains more than
871 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
874 @param String Pointer to a Null-terminated ASCII string.
876 @return The size of String.
882 IN CONST CHAR8
*String
887 Compares two Null-terminated ASCII strings, and returns the difference
888 between the first mismatched ASCII characters.
890 This function compares the Null-terminated ASCII string FirstString to the
891 Null-terminated ASCII string SecondString. If FirstString is identical to
892 SecondString, then 0 is returned. Otherwise, the value returned is the first
893 mismatched ASCII character in SecondString subtracted from the first
894 mismatched ASCII character in FirstString.
896 If FirstString is NULL, then ASSERT().
897 If SecondString is NULL, then ASSERT().
898 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
899 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
901 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
902 than PcdMaximumAsciiStringLength ASCII characters not including the
903 Null-terminator, then ASSERT().
905 @param FirstString Pointer to a Null-terminated ASCII string.
906 @param SecondString Pointer to a Null-terminated ASCII string.
908 @retval 0 FirstString is identical to SecondString.
909 @retval !=0 FirstString is not identical to SecondString.
915 IN CONST CHAR8
*FirstString
,
916 IN CONST CHAR8
*SecondString
921 Performs a case insensitive comparison of two Null-terminated ASCII strings,
922 and returns the difference between the first mismatched ASCII characters.
924 This function performs a case insensitive comparison of the Null-terminated
925 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
926 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
927 value returned is the first mismatched lower case ASCII character in
928 SecondString subtracted from the first mismatched lower case ASCII character
931 If FirstString is NULL, then ASSERT().
932 If SecondString is NULL, then ASSERT().
933 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
934 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
936 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
937 than PcdMaximumAsciiStringLength ASCII characters not including the
938 Null-terminator, then ASSERT().
940 @param FirstString Pointer to a Null-terminated ASCII string.
941 @param SecondString Pointer to a Null-terminated ASCII string.
943 @retval 0 FirstString is identical to SecondString using case insensitive
945 @retval !=0 FirstString is not identical to SecondString using case
946 insensitive comparisons.
952 IN CONST CHAR8
*FirstString
,
953 IN CONST CHAR8
*SecondString
958 Compares two Null-terminated ASCII strings with maximum lengths, and returns
959 the difference between the first mismatched ASCII characters.
961 This function compares the Null-terminated ASCII string FirstString to the
962 Null-terminated ASCII string SecondString. At most, Length ASCII characters
963 will be compared. If Length is 0, then 0 is returned. If FirstString is
964 identical to SecondString, then 0 is returned. Otherwise, the value returned
965 is the first mismatched ASCII character in SecondString subtracted from the
966 first mismatched ASCII character in FirstString.
968 If Length > 0 and FirstString is NULL, then ASSERT().
969 If Length > 0 and SecondString is NULL, then ASSERT().
970 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
971 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
973 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than
974 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
977 @param FirstString Pointer to a Null-terminated ASCII string.
978 @param SecondString Pointer to a Null-terminated ASCII string.
979 @param Length Maximum number of ASCII characters for compare.
981 @retval 0 FirstString is identical to SecondString.
982 @retval !=0 FirstString is not identical to SecondString.
988 IN CONST CHAR8
*FirstString
,
989 IN CONST CHAR8
*SecondString
,
995 Concatenates one Null-terminated ASCII string to another Null-terminated
996 ASCII string, and returns the concatenated ASCII string.
998 This function concatenates two Null-terminated ASCII strings. The contents of
999 Null-terminated ASCII string Source are concatenated to the end of Null-
1000 terminated ASCII string Destination. The Null-terminated concatenated ASCII
1003 If Destination is NULL, then ASSERT().
1004 If Source is NULL, then ASSERT().
1005 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
1006 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1008 If PcdMaximumAsciiStringLength is not zero and Source contains more than
1009 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1011 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
1012 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1013 ASCII characters, then ASSERT().
1015 @param Destination Pointer to a Null-terminated ASCII string.
1016 @param Source Pointer to a Null-terminated ASCII string.
1024 IN OUT CHAR8
*Destination
,
1025 IN CONST CHAR8
*Source
1030 Concatenates one Null-terminated ASCII string with a maximum length to the
1031 end of another Null-terminated ASCII string, and returns the concatenated
1034 This function concatenates two Null-terminated ASCII strings. The contents
1035 of Null-terminated ASCII string Source are concatenated to the end of Null-
1036 terminated ASCII string Destination, and Destination is returned. At most,
1037 Length ASCII characters are concatenated from Source to the end of
1038 Destination, and Destination is always Null-terminated. If Length is 0, then
1039 Destination is returned unmodified. If Source and Destination overlap, then
1040 the results are undefined.
1042 If Length > 0 and Destination is NULL, then ASSERT().
1043 If Length > 0 and Source is NULL, then ASSERT().
1044 If Source and Destination overlap, then ASSERT().
1045 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
1046 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1048 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1049 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1051 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
1052 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
1053 ASCII characters not including the Null-terminator, then ASSERT().
1055 @param Destination Pointer to a Null-terminated ASCII string.
1056 @param Source Pointer to a Null-terminated ASCII string.
1057 @param Length Maximum number of ASCII characters to concatenate from
1066 IN OUT CHAR8
*Destination
,
1067 IN CONST CHAR8
*Source
,
1073 Returns the first occurance of a Null-terminated ASCII sub-string
1074 in a Null-terminated ASCII string.
1076 This function scans the contents of the ASCII string specified by String
1077 and returns the first occurrence of SearchString. If SearchString is not
1078 found in String, then NULL is returned. If the length of SearchString is zero,
1079 then String is returned.
1081 If String is NULL, then ASSERT().
1082 If SearchString is NULL, then ASSERT().
1084 If PcdMaximumAsciiStringLength is not zero, and SearchString or
1085 String contains more than PcdMaximumAsciiStringLength Unicode characters
1086 not including the Null-terminator, then ASSERT().
1088 @param String Pointer to a Null-terminated ASCII string.
1089 @param SearchString Pointer to a Null-terminated ASCII string to search for.
1091 @retval NULL If the SearchString does not appear in String.
1092 @retval !NULL If there is a match.
1098 IN CONST CHAR8
*String
,
1099 IN CONST CHAR8
*SearchString
1104 Convert a Null-terminated ASCII decimal string to a value of type
1107 This function returns a value of type UINTN by interpreting the contents
1108 of the ASCII string String as a decimal number. The format of the input
1109 ASCII string String is:
1111 [spaces] [decimal digits].
1113 The valid decimal digit character is in the range [0-9]. The function will
1114 ignore the pad space, which includes spaces or tab characters, before the digits.
1115 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1116 function stops at the first character that is a not a valid decimal character or
1117 Null-terminator, whichever on comes first.
1119 If String has only pad spaces, then 0 is returned.
1120 If String has no pad spaces or valid decimal digits, then 0 is returned.
1121 If the number represented by String overflows according to the range defined by
1122 UINTN, then ASSERT().
1123 If String is NULL, then ASSERT().
1124 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1125 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1128 @param String Pointer to a Null-terminated ASCII string.
1135 AsciiStrDecimalToUintn (
1136 IN CONST CHAR8
*String
1141 Convert a Null-terminated ASCII decimal string to a value of type
1144 This function returns a value of type UINT64 by interpreting the contents
1145 of the ASCII string String as a decimal number. The format of the input
1146 ASCII string String is:
1148 [spaces] [decimal digits].
1150 The valid decimal digit character is in the range [0-9]. The function will
1151 ignore the pad space, which includes spaces or tab characters, before the digits.
1152 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1153 function stops at the first character that is a not a valid decimal character or
1154 Null-terminator, whichever on comes first.
1156 If String has only pad spaces, then 0 is returned.
1157 If String has no pad spaces or valid decimal digits, then 0 is returned.
1158 If the number represented by String overflows according to the range defined by
1159 UINT64, then ASSERT().
1160 If String is NULL, then ASSERT().
1161 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1162 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1165 @param String Pointer to a Null-terminated ASCII string.
1172 AsciiStrDecimalToUint64 (
1173 IN CONST CHAR8
*String
1178 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1180 This function returns a value of type UINTN by interpreting the contents of
1181 the ASCII string String as a hexadecimal number. The format of the input ASCII
1184 [spaces][zeros][x][hexadecimal digits].
1186 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1187 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1188 appears in the input string, it must be prefixed with at least one 0. The function
1189 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1190 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1191 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1192 digit. Then, the function stops at the first character that is a not a valid
1193 hexadecimal character or Null-terminator, whichever on comes first.
1195 If String has only pad spaces, then 0 is returned.
1196 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1199 If the number represented by String overflows according to the range defined by UINTN,
1201 If String is NULL, then ASSERT().
1202 If PcdMaximumAsciiStringLength is not zero,
1203 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1204 the Null-terminator, then ASSERT().
1206 @param String Pointer to a Null-terminated ASCII string.
1213 AsciiStrHexToUintn (
1214 IN CONST CHAR8
*String
1219 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1221 This function returns a value of type UINT64 by interpreting the contents of
1222 the ASCII string String as a hexadecimal number. The format of the input ASCII
1225 [spaces][zeros][x][hexadecimal digits].
1227 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1228 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1229 appears in the input string, it must be prefixed with at least one 0. The function
1230 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1231 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1232 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1233 digit. Then, the function stops at the first character that is a not a valid
1234 hexadecimal character or Null-terminator, whichever on comes first.
1236 If String has only pad spaces, then 0 is returned.
1237 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1240 If the number represented by String overflows according to the range defined by UINT64,
1242 If String is NULL, then ASSERT().
1243 If PcdMaximumAsciiStringLength is not zero,
1244 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1245 the Null-terminator, then ASSERT().
1247 @param String Pointer to a Null-terminated ASCII string.
1254 AsciiStrHexToUint64 (
1255 IN CONST CHAR8
*String
1260 Convert one Null-terminated ASCII string to a Null-terminated
1261 Unicode string and returns the Unicode string.
1263 This function converts the contents of the ASCII string Source to the Unicode
1264 string Destination, and returns Destination. The function terminates the
1265 Unicode string Destination by appending a Null-terminator character at the end.
1266 The caller is responsible to make sure Destination points to a buffer with size
1267 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1269 If Destination is NULL, then ASSERT().
1270 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1271 If Source is NULL, then ASSERT().
1272 If Source and Destination overlap, then ASSERT().
1273 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1274 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1276 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1277 PcdMaximumUnicodeStringLength ASCII characters not including the
1278 Null-terminator, then ASSERT().
1280 @param Source Pointer to a Null-terminated ASCII string.
1281 @param Destination Pointer to a Null-terminated Unicode string.
1288 AsciiStrToUnicodeStr (
1289 IN CONST CHAR8
*Source
,
1290 OUT CHAR16
*Destination
1295 Converts an 8-bit value to an 8-bit BCD value.
1297 Converts the 8-bit value specified by Value to BCD. The BCD value is
1300 If Value >= 100, then ASSERT().
1302 @param Value The 8-bit value to convert to BCD. Range 0..99.
1304 @return The BCD value
1315 Converts an 8-bit BCD value to an 8-bit value.
1317 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
1320 If Value >= 0xA0, then ASSERT().
1321 If (Value & 0x0F) >= 0x0A, then ASSERT().
1323 @param Value The 8-bit BCD value to convert to an 8-bit value.
1325 @return The 8-bit value is returned.
1336 // Linked List Functions and Macros
1340 Initializes the head node of a doubly linked list that is declared as a
1341 global variable in a module.
1343 Initializes the forward and backward links of a new linked list. After
1344 initializing a linked list with this macro, the other linked list functions
1345 may be used to add and remove nodes from the linked list. This macro results
1346 in smaller executables by initializing the linked list in the data section,
1347 instead if calling the InitializeListHead() function to perform the
1348 equivalent operation.
1350 @param ListHead The head note of a list to initiailize.
1353 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
1357 Initializes the head node of a doubly linked list, and returns the pointer to
1358 the head node of the doubly linked list.
1360 Initializes the forward and backward links of a new linked list. After
1361 initializing a linked list with this function, the other linked list
1362 functions may be used to add and remove nodes from the linked list. It is up
1363 to the caller of this function to allocate the memory for ListHead.
1365 If ListHead is NULL, then ASSERT().
1367 @param ListHead A pointer to the head node of a new doubly linked list.
1374 InitializeListHead (
1375 IN LIST_ENTRY
*ListHead
1380 Adds a node to the beginning of a doubly linked list, and returns the pointer
1381 to the head node of the doubly linked list.
1383 Adds the node Entry at the beginning of the doubly linked list denoted by
1384 ListHead, and returns ListHead.
1386 If ListHead is NULL, then ASSERT().
1387 If Entry is NULL, then ASSERT().
1388 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1389 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1390 of nodes in ListHead, including the ListHead node, is greater than or
1391 equal to PcdMaximumLinkedListLength, then ASSERT().
1393 @param ListHead A pointer to the head node of a doubly linked list.
1394 @param Entry A pointer to a node that is to be inserted at the beginning
1395 of a doubly linked list.
1403 IN LIST_ENTRY
*ListHead
,
1404 IN LIST_ENTRY
*Entry
1409 Adds a node to the end of a doubly linked list, and returns the pointer to
1410 the head node of the doubly linked list.
1412 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
1413 and returns ListHead.
1415 If ListHead is NULL, then ASSERT().
1416 If Entry is NULL, then ASSERT().
1417 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1418 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1419 of nodes in ListHead, including the ListHead node, is greater than or
1420 equal to PcdMaximumLinkedListLength, then ASSERT().
1422 @param ListHead A pointer to the head node of a doubly linked list.
1423 @param Entry A pointer to a node that is to be added at the end of the
1432 IN LIST_ENTRY
*ListHead
,
1433 IN LIST_ENTRY
*Entry
1438 Retrieves the first node of a doubly linked list.
1440 Returns the first node of a doubly linked list. List must have been
1441 initialized with InitializeListHead(). If List is empty, then NULL is
1444 If List is NULL, then ASSERT().
1445 If List was not initialized with InitializeListHead(), then ASSERT().
1446 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1447 in List, including the List node, is greater than or equal to
1448 PcdMaximumLinkedListLength, then ASSERT().
1450 @param List A pointer to the head node of a doubly linked list.
1452 @return The first node of a doubly linked list.
1453 @retval NULL The list is empty.
1459 IN CONST LIST_ENTRY
*List
1464 Retrieves the next node of a doubly linked list.
1466 Returns the node of a doubly linked list that follows Node. List must have
1467 been initialized with InitializeListHead(). If List is empty, then List is
1470 If List is NULL, then ASSERT().
1471 If Node is NULL, then ASSERT().
1472 If List was not initialized with InitializeListHead(), then ASSERT().
1473 If PcdMaximumLinkedListLenth is not zero, and List contains more than
1474 PcdMaximumLinkedListLenth nodes, then ASSERT().
1475 If Node is not a node in List, then ASSERT().
1477 @param List A pointer to the head node of a doubly linked list.
1478 @param Node A pointer to a node in the doubly linked list.
1480 @return Pointer to the next node if one exists. Otherwise a null value which
1481 is actually List is returned.
1487 IN CONST LIST_ENTRY
*List
,
1488 IN CONST LIST_ENTRY
*Node
1493 Checks to see if a doubly linked list is empty or not.
1495 Checks to see if the doubly linked list is empty. If the linked list contains
1496 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
1498 If ListHead is NULL, then ASSERT().
1499 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1500 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1501 in List, including the List node, is greater than or equal to
1502 PcdMaximumLinkedListLength, then ASSERT().
1504 @param ListHead A pointer to the head node of a doubly linked list.
1506 @retval TRUE The linked list is empty.
1507 @retval FALSE The linked list is not empty.
1513 IN CONST LIST_ENTRY
*ListHead
1518 Determines if a node in a doubly linked list is null.
1520 Returns FALSE if Node is one of the nodes in the doubly linked list specified
1521 by List. Otherwise, TRUE is returned. List must have been initialized with
1522 InitializeListHead().
1524 If List is NULL, then ASSERT().
1525 If Node is NULL, then ASSERT().
1526 If List was not initialized with InitializeListHead(), then ASSERT().
1527 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1528 in List, including the List node, is greater than or equal to
1529 PcdMaximumLinkedListLength, then ASSERT().
1530 If Node is not a node in List and Node is not equal to List, then ASSERT().
1532 @param List A pointer to the head node of a doubly linked list.
1533 @param Node A pointer to a node in the doubly linked list.
1535 @retval TRUE Node is one of the nodes in the doubly linked list.
1536 @retval FALSE Node is not one of the nodes in the doubly linked list.
1542 IN CONST LIST_ENTRY
*List
,
1543 IN CONST LIST_ENTRY
*Node
1548 Determines if a node the last node in a doubly linked list.
1550 Returns TRUE if Node is the last node in the doubly linked list specified by
1551 List. Otherwise, FALSE is returned. List must have been initialized with
1552 InitializeListHead().
1554 If List is NULL, then ASSERT().
1555 If Node is NULL, then ASSERT().
1556 If List was not initialized with InitializeListHead(), then ASSERT().
1557 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1558 in List, including the List node, is greater than or equal to
1559 PcdMaximumLinkedListLength, then ASSERT().
1560 If Node is not a node in List, then ASSERT().
1562 @param List A pointer to the head node of a doubly linked list.
1563 @param Node A pointer to a node in the doubly linked list.
1565 @retval TRUE Node is the last node in the linked list.
1566 @retval FALSE Node is not the last node in the linked list.
1572 IN CONST LIST_ENTRY
*List
,
1573 IN CONST LIST_ENTRY
*Node
1578 Swaps the location of two nodes in a doubly linked list, and returns the
1579 first node after the swap.
1581 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
1582 Otherwise, the location of the FirstEntry node is swapped with the location
1583 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
1584 same double linked list as FirstEntry and that double linked list must have
1585 been initialized with InitializeListHead(). SecondEntry is returned after the
1588 If FirstEntry is NULL, then ASSERT().
1589 If SecondEntry is NULL, then ASSERT().
1590 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
1591 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1592 linked list containing the FirstEntry and SecondEntry nodes, including
1593 the FirstEntry and SecondEntry nodes, is greater than or equal to
1594 PcdMaximumLinkedListLength, then ASSERT().
1596 @param FirstEntry A pointer to a node in a linked list.
1597 @param SecondEntry A pointer to another node in the same linked list.
1603 IN LIST_ENTRY
*FirstEntry
,
1604 IN LIST_ENTRY
*SecondEntry
1609 Removes a node from a doubly linked list, and returns the node that follows
1612 Removes the node Entry from a doubly linked list. It is up to the caller of
1613 this function to release the memory used by this node if that is required. On
1614 exit, the node following Entry in the doubly linked list is returned. If
1615 Entry is the only node in the linked list, then the head node of the linked
1618 If Entry is NULL, then ASSERT().
1619 If Entry is the head node of an empty list, then ASSERT().
1620 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1621 linked list containing Entry, including the Entry node, is greater than
1622 or equal to PcdMaximumLinkedListLength, then ASSERT().
1624 @param Entry A pointer to a node in a linked list
1632 IN CONST LIST_ENTRY
*Entry
1640 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
1641 with zeros. The shifted value is returned.
1643 This function shifts the 64-bit value Operand to the left by Count bits. The
1644 low Count bits are set to zero. The shifted value is returned.
1646 If Count is greater than 63, then ASSERT().
1648 @param Operand The 64-bit operand to shift left.
1649 @param Count The number of bits to shift left.
1651 @return Operand << Count
1663 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1664 filled with zeros. The shifted value is returned.
1666 This function shifts the 64-bit value Operand to the right by Count bits. The
1667 high Count bits are set to zero. The shifted value is returned.
1669 If Count is greater than 63, then ASSERT().
1671 @param Operand The 64-bit operand to shift right.
1672 @param Count The number of bits to shift right.
1674 @return Operand >> Count
1686 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1687 with original integer's bit 63. The shifted value is returned.
1689 This function shifts the 64-bit value Operand to the right by Count bits. The
1690 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1692 If Count is greater than 63, then ASSERT().
1694 @param Operand The 64-bit operand to shift right.
1695 @param Count The number of bits to shift right.
1697 @return Operand >> Count
1709 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1710 with the high bits that were rotated.
1712 This function rotates the 32-bit value Operand to the left by Count bits. The
1713 low Count bits are fill with the high Count bits of Operand. The rotated
1716 If Count is greater than 31, then ASSERT().
1718 @param Operand The 32-bit operand to rotate left.
1719 @param Count The number of bits to rotate left.
1721 @return Operand <<< Count
1733 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1734 with the low bits that were rotated.
1736 This function rotates the 32-bit value Operand to the right by Count bits.
1737 The high Count bits are fill with the low Count bits of Operand. The rotated
1740 If Count is greater than 31, then ASSERT().
1742 @param Operand The 32-bit operand to rotate right.
1743 @param Count The number of bits to rotate right.
1745 @return Operand >>> Count
1757 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1758 with the high bits that were rotated.
1760 This function rotates the 64-bit value Operand to the left by Count bits. The
1761 low Count bits are fill with the high Count bits of Operand. The rotated
1764 If Count is greater than 63, then ASSERT().
1766 @param Operand The 64-bit operand to rotate left.
1767 @param Count The number of bits to rotate left.
1769 @return Operand <<< Count
1781 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1782 with the high low bits that were rotated.
1784 This function rotates the 64-bit value Operand to the right by Count bits.
1785 The high Count bits are fill with the low Count bits of Operand. The rotated
1788 If Count is greater than 63, then ASSERT().
1790 @param Operand The 64-bit operand to rotate right.
1791 @param Count The number of bits to rotate right.
1793 @return Operand >>> Count
1805 Returns the bit position of the lowest bit set in a 32-bit value.
1807 This function computes the bit position of the lowest bit set in the 32-bit
1808 value specified by Operand. If Operand is zero, then -1 is returned.
1809 Otherwise, a value between 0 and 31 is returned.
1811 @param Operand The 32-bit operand to evaluate.
1813 @return Position of the lowest bit set in Operand if found.
1814 @retval -1 Operand is zero.
1825 Returns the bit position of the lowest bit set in a 64-bit value.
1827 This function computes the bit position of the lowest bit set in the 64-bit
1828 value specified by Operand. If Operand is zero, then -1 is returned.
1829 Otherwise, a value between 0 and 63 is returned.
1831 @param Operand The 64-bit operand to evaluate.
1833 @return Position of the lowest bit set in Operand if found.
1834 @retval -1 Operand is zero.
1845 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1848 This function computes the bit position of the highest bit set in the 32-bit
1849 value specified by Operand. If Operand is zero, then -1 is returned.
1850 Otherwise, a value between 0 and 31 is returned.
1852 @param Operand The 32-bit operand to evaluate.
1854 @return Position of the highest bit set in Operand if found.
1855 @retval -1 Operand is zero.
1866 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1869 This function computes the bit position of the highest bit set in the 64-bit
1870 value specified by Operand. If Operand is zero, then -1 is returned.
1871 Otherwise, a value between 0 and 63 is returned.
1873 @param Operand The 64-bit operand to evaluate.
1875 @return Position of the highest bit set in Operand if found.
1876 @retval -1 Operand is zero.
1887 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1888 1 << HighBitSet32(x).
1890 This function computes the value of the highest bit set in the 32-bit value
1891 specified by Operand. If Operand is zero, then zero is returned.
1893 @param Operand The 32-bit operand to evaluate.
1895 @return 1 << HighBitSet32(Operand)
1896 @retval 0 Operand is zero.
1907 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1908 1 << HighBitSet64(x).
1910 This function computes the value of the highest bit set in the 64-bit value
1911 specified by Operand. If Operand is zero, then zero is returned.
1913 @param Operand The 64-bit operand to evaluate.
1915 @return 1 << HighBitSet64(Operand)
1916 @retval 0 Operand is zero.
1927 Switches the endianess of a 16-bit integer.
1929 This function swaps the bytes in a 16-bit unsigned value to switch the value
1930 from little endian to big endian or vice versa. The byte swapped value is
1933 @param Value Operand A 16-bit unsigned value.
1935 @return The byte swaped Operand.
1946 Switches the endianess of a 32-bit integer.
1948 This function swaps the bytes in a 32-bit unsigned value to switch the value
1949 from little endian to big endian or vice versa. The byte swapped value is
1952 @param Value Operand A 32-bit unsigned value.
1954 @return The byte swaped Operand.
1965 Switches the endianess of a 64-bit integer.
1967 This function swaps the bytes in a 64-bit unsigned value to switch the value
1968 from little endian to big endian or vice versa. The byte swapped value is
1971 @param Value Operand A 64-bit unsigned value.
1973 @return The byte swaped Operand.
1984 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1985 generates a 64-bit unsigned result.
1987 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1988 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1989 bit unsigned result is returned.
1991 If the result overflows, then ASSERT().
1993 @param Multiplicand A 64-bit unsigned value.
1994 @param Multiplier A 32-bit unsigned value.
1996 @return Multiplicand * Multiplier
2002 IN UINT64 Multiplicand
,
2003 IN UINT32 Multiplier
2008 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
2009 generates a 64-bit unsigned result.
2011 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
2012 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
2013 bit unsigned result is returned.
2015 If the result overflows, then ASSERT().
2017 @param Multiplicand A 64-bit unsigned value.
2018 @param Multiplier A 64-bit unsigned value.
2020 @return Multiplicand * Multiplier
2026 IN UINT64 Multiplicand
,
2027 IN UINT64 Multiplier
2032 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
2033 64-bit signed result.
2035 This function multiples the 64-bit signed value Multiplicand by the 64-bit
2036 signed value Multiplier and generates a 64-bit signed result. This 64-bit
2037 signed result is returned.
2039 If the result overflows, then ASSERT().
2041 @param Multiplicand A 64-bit signed value.
2042 @param Multiplier A 64-bit signed value.
2044 @return Multiplicand * Multiplier
2050 IN INT64 Multiplicand
,
2056 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
2057 a 64-bit unsigned result.
2059 This function divides the 64-bit unsigned value Dividend by the 32-bit
2060 unsigned value Divisor and generates a 64-bit unsigned quotient. This
2061 function returns the 64-bit unsigned quotient.
2063 If Divisor is 0, then ASSERT().
2065 @param Dividend A 64-bit unsigned value.
2066 @param Divisor A 32-bit unsigned value.
2068 @return Dividend / Divisor
2080 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
2081 a 32-bit unsigned remainder.
2083 This function divides the 64-bit unsigned value Dividend by the 32-bit
2084 unsigned value Divisor and generates a 32-bit remainder. This function
2085 returns the 32-bit unsigned remainder.
2087 If Divisor is 0, then ASSERT().
2089 @param Dividend A 64-bit unsigned value.
2090 @param Divisor A 32-bit unsigned value.
2092 @return Dividend % Divisor
2104 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
2105 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
2107 This function divides the 64-bit unsigned value Dividend by the 32-bit
2108 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2109 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
2110 This function returns the 64-bit unsigned quotient.
2112 If Divisor is 0, then ASSERT().
2114 @param Dividend A 64-bit unsigned value.
2115 @param Divisor A 32-bit unsigned value.
2116 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
2117 optional and may be NULL.
2119 @return Dividend / Divisor
2124 DivU64x32Remainder (
2127 OUT UINT32
*Remainder OPTIONAL
2132 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
2133 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
2135 This function divides the 64-bit unsigned value Dividend by the 64-bit
2136 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
2137 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
2138 This function returns the 64-bit unsigned quotient.
2140 If Divisor is 0, then ASSERT().
2142 @param Dividend A 64-bit unsigned value.
2143 @param Divisor A 64-bit unsigned value.
2144 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
2145 optional and may be NULL.
2147 @return Dividend / Divisor
2152 DivU64x64Remainder (
2155 OUT UINT64
*Remainder OPTIONAL
2160 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
2161 64-bit signed result and a optional 64-bit signed remainder.
2163 This function divides the 64-bit signed value Dividend by the 64-bit signed
2164 value Divisor and generates a 64-bit signed quotient. If Remainder is not
2165 NULL, then the 64-bit signed remainder is returned in Remainder. This
2166 function returns the 64-bit signed quotient.
2168 If Divisor is 0, then ASSERT().
2170 @param Dividend A 64-bit signed value.
2171 @param Divisor A 64-bit signed value.
2172 @param Remainder A pointer to a 64-bit signed value. This parameter is
2173 optional and may be NULL.
2175 @return Dividend / Divisor
2180 DivS64x64Remainder (
2183 OUT INT64
*Remainder OPTIONAL
2188 Reads a 16-bit value from memory that may be unaligned.
2190 This function returns the 16-bit value pointed to by Buffer. The function
2191 guarantees that the read operation does not produce an alignment fault.
2193 If the Buffer is NULL, then ASSERT().
2195 @param Uint16 Pointer to a 16-bit value that may be unaligned.
2203 IN CONST UINT16
*Uint16
2208 Writes a 16-bit value to memory that may be unaligned.
2210 This function writes the 16-bit value specified by Value to Buffer. Value is
2211 returned. The function guarantees that the write operation does not produce
2214 If the Buffer is NULL, then ASSERT().
2216 @param Uint16 Pointer to a 16-bit value that may be unaligned.
2217 @param Value 16-bit value to write to Buffer.
2231 Reads a 24-bit value from memory that may be unaligned.
2233 This function returns the 24-bit value pointed to by Buffer. The function
2234 guarantees that the read operation does not produce an alignment fault.
2236 If the Buffer is NULL, then ASSERT().
2238 @param Buffer Pointer to a 24-bit value that may be unaligned.
2240 @return The value read.
2246 IN CONST UINT32
*Buffer
2251 Writes a 24-bit value to memory that may be unaligned.
2253 This function writes the 24-bit value specified by Value to Buffer. Value is
2254 returned. The function guarantees that the write operation does not produce
2257 If the Buffer is NULL, then ASSERT().
2259 @param Buffer Pointer to a 24-bit value that may be unaligned.
2260 @param Value 24-bit value to write to Buffer.
2262 @return The value written.
2274 Reads a 32-bit value from memory that may be unaligned.
2276 This function returns the 32-bit value pointed to by Buffer. The function
2277 guarantees that the read operation does not produce an alignment fault.
2279 If the Buffer is NULL, then ASSERT().
2281 @param Uint32 Pointer to a 32-bit value that may be unaligned.
2289 IN CONST UINT32
*Uint32
2294 Writes a 32-bit value to memory that may be unaligned.
2296 This function writes the 32-bit value specified by Value to Buffer. Value is
2297 returned. The function guarantees that the write operation does not produce
2300 If the Buffer is NULL, then ASSERT().
2302 @param Uint32 Pointer to a 32-bit value that may be unaligned.
2303 @param Value 32-bit value to write to Buffer.
2317 Reads a 64-bit value from memory that may be unaligned.
2319 This function returns the 64-bit value pointed to by Buffer. The function
2320 guarantees that the read operation does not produce an alignment fault.
2322 If the Buffer is NULL, then ASSERT().
2324 @param Uint64 Pointer to a 64-bit value that may be unaligned.
2332 IN CONST UINT64
*Uint64
2337 Writes a 64-bit value to memory that may be unaligned.
2339 This function writes the 64-bit value specified by Value to Buffer. Value is
2340 returned. The function guarantees that the write operation does not produce
2343 If the Buffer is NULL, then ASSERT().
2345 @param Uint64 Pointer to a 64-bit value that may be unaligned.
2346 @param Value 64-bit value to write to Buffer.
2360 // Bit Field Functions
2364 Returns a bit field from an 8-bit value.
2366 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2368 If 8-bit operations are not supported, then ASSERT().
2369 If StartBit is greater than 7, then ASSERT().
2370 If EndBit is greater than 7, then ASSERT().
2371 If EndBit is less than StartBit, then ASSERT().
2373 @param Operand Operand on which to perform the bitfield operation.
2374 @param StartBit The ordinal of the least significant bit in the bit field.
2376 @param EndBit The ordinal of the most significant bit in the bit field.
2379 @return The bit field read.
2392 Writes a bit field to an 8-bit value, and returns the result.
2394 Writes Value to the bit field specified by the StartBit and the EndBit in
2395 Operand. All other bits in Operand are preserved. The new 8-bit value is
2398 If 8-bit operations are not supported, then ASSERT().
2399 If StartBit is greater than 7, then ASSERT().
2400 If EndBit is greater than 7, then ASSERT().
2401 If EndBit is less than StartBit, then ASSERT().
2403 @param Operand Operand on which to perform the bitfield operation.
2404 @param StartBit The ordinal of the least significant bit in the bit field.
2406 @param EndBit The ordinal of the most significant bit in the bit field.
2408 @param Value New value of the bit field.
2410 @return The new 8-bit value.
2424 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
2427 Performs a bitwise inclusive OR between the bit field specified by StartBit
2428 and EndBit in Operand and the value specified by OrData. All other bits in
2429 Operand are preserved. The new 8-bit value is returned.
2431 If 8-bit operations are not supported, then ASSERT().
2432 If StartBit is greater than 7, then ASSERT().
2433 If EndBit is greater than 7, then ASSERT().
2434 If EndBit is less than StartBit, then ASSERT().
2436 @param Operand Operand on which to perform the bitfield operation.
2437 @param StartBit The ordinal of the least significant bit in the bit field.
2439 @param EndBit The ordinal of the most significant bit in the bit field.
2441 @param OrData The value to OR with the read value from the value
2443 @return The new 8-bit value.
2457 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
2460 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2461 in Operand and the value specified by AndData. All other bits in Operand are
2462 preserved. The new 8-bit value is returned.
2464 If 8-bit operations are not supported, then ASSERT().
2465 If StartBit is greater than 7, then ASSERT().
2466 If EndBit is greater than 7, then ASSERT().
2467 If EndBit is less than StartBit, then ASSERT().
2469 @param Operand Operand on which to perform the bitfield operation.
2470 @param StartBit The ordinal of the least significant bit in the bit field.
2472 @param EndBit The ordinal of the most significant bit in the bit field.
2474 @param AndData The value to AND with the read value from the value.
2476 @return The new 8-bit value.
2490 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
2491 bitwise OR, and returns the result.
2493 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2494 in Operand and the value specified by AndData, followed by a bitwise
2495 inclusive OR with value specified by OrData. All other bits in Operand are
2496 preserved. The new 8-bit value is returned.
2498 If 8-bit operations are not supported, then ASSERT().
2499 If StartBit is greater than 7, then ASSERT().
2500 If EndBit is greater than 7, then ASSERT().
2501 If EndBit is less than StartBit, then ASSERT().
2503 @param Operand Operand on which to perform the bitfield operation.
2504 @param StartBit The ordinal of the least significant bit in the bit field.
2506 @param EndBit The ordinal of the most significant bit in the bit field.
2508 @param AndData The value to AND with the read value from the value.
2509 @param OrData The value to OR with the result of the AND operation.
2511 @return The new 8-bit value.
2516 BitFieldAndThenOr8 (
2526 Returns a bit field from a 16-bit value.
2528 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2530 If 16-bit operations are not supported, then ASSERT().
2531 If StartBit is greater than 15, then ASSERT().
2532 If EndBit is greater than 15, then ASSERT().
2533 If EndBit is less than StartBit, then ASSERT().
2535 @param Operand Operand on which to perform the bitfield operation.
2536 @param StartBit The ordinal of the least significant bit in the bit field.
2538 @param EndBit The ordinal of the most significant bit in the bit field.
2541 @return The bit field read.
2554 Writes a bit field to a 16-bit value, and returns the result.
2556 Writes Value to the bit field specified by the StartBit and the EndBit in
2557 Operand. All other bits in Operand are preserved. The new 16-bit value is
2560 If 16-bit operations are not supported, then ASSERT().
2561 If StartBit is greater than 15, then ASSERT().
2562 If EndBit is greater than 15, then ASSERT().
2563 If EndBit is less than StartBit, then ASSERT().
2565 @param Operand Operand on which to perform the bitfield operation.
2566 @param StartBit The ordinal of the least significant bit in the bit field.
2568 @param EndBit The ordinal of the most significant bit in the bit field.
2570 @param Value New value of the bit field.
2572 @return The new 16-bit value.
2586 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
2589 Performs a bitwise inclusive OR between the bit field specified by StartBit
2590 and EndBit in Operand and the value specified by OrData. All other bits in
2591 Operand are preserved. The new 16-bit value is returned.
2593 If 16-bit operations are not supported, then ASSERT().
2594 If StartBit is greater than 15, then ASSERT().
2595 If EndBit is greater than 15, then ASSERT().
2596 If EndBit is less than StartBit, then ASSERT().
2598 @param Operand Operand on which to perform the bitfield operation.
2599 @param StartBit The ordinal of the least significant bit in the bit field.
2601 @param EndBit The ordinal of the most significant bit in the bit field.
2603 @param OrData The value to OR with the read value from the value
2605 @return The new 16-bit value.
2619 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
2622 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2623 in Operand and the value specified by AndData. All other bits in Operand are
2624 preserved. The new 16-bit value is returned.
2626 If 16-bit operations are not supported, then ASSERT().
2627 If StartBit is greater than 15, then ASSERT().
2628 If EndBit is greater than 15, then ASSERT().
2629 If EndBit is less than StartBit, then ASSERT().
2631 @param Operand Operand on which to perform the bitfield operation.
2632 @param StartBit The ordinal of the least significant bit in the bit field.
2634 @param EndBit The ordinal of the most significant bit in the bit field.
2636 @param AndData The value to AND with the read value from the value
2638 @return The new 16-bit value.
2652 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
2653 bitwise OR, and returns the result.
2655 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2656 in Operand and the value specified by AndData, followed by a bitwise
2657 inclusive OR with value specified by OrData. All other bits in Operand are
2658 preserved. The new 16-bit value is returned.
2660 If 16-bit operations are not supported, then ASSERT().
2661 If StartBit is greater than 15, then ASSERT().
2662 If EndBit is greater than 15, then ASSERT().
2663 If EndBit is less than StartBit, then ASSERT().
2665 @param Operand Operand on which to perform the bitfield operation.
2666 @param StartBit The ordinal of the least significant bit in the bit field.
2668 @param EndBit The ordinal of the most significant bit in the bit field.
2670 @param AndData The value to AND with the read value from the value.
2671 @param OrData The value to OR with the result of the AND operation.
2673 @return The new 16-bit value.
2678 BitFieldAndThenOr16 (
2688 Returns a bit field from a 32-bit value.
2690 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2692 If 32-bit operations are not supported, then ASSERT().
2693 If StartBit is greater than 31, then ASSERT().
2694 If EndBit is greater than 31, then ASSERT().
2695 If EndBit is less than StartBit, then ASSERT().
2697 @param Operand Operand on which to perform the bitfield operation.
2698 @param StartBit The ordinal of the least significant bit in the bit field.
2700 @param EndBit The ordinal of the most significant bit in the bit field.
2703 @return The bit field read.
2716 Writes a bit field to a 32-bit value, and returns the result.
2718 Writes Value to the bit field specified by the StartBit and the EndBit in
2719 Operand. All other bits in Operand are preserved. The new 32-bit value is
2722 If 32-bit operations are not supported, then ASSERT().
2723 If StartBit is greater than 31, then ASSERT().
2724 If EndBit is greater than 31, then ASSERT().
2725 If EndBit is less than StartBit, then ASSERT().
2727 @param Operand Operand on which to perform the bitfield operation.
2728 @param StartBit The ordinal of the least significant bit in the bit field.
2730 @param EndBit The ordinal of the most significant bit in the bit field.
2732 @param Value New value of the bit field.
2734 @return The new 32-bit value.
2748 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2751 Performs a bitwise inclusive OR between the bit field specified by StartBit
2752 and EndBit in Operand and the value specified by OrData. All other bits in
2753 Operand are preserved. The new 32-bit value is returned.
2755 If 32-bit operations are not supported, then ASSERT().
2756 If StartBit is greater than 31, then ASSERT().
2757 If EndBit is greater than 31, then ASSERT().
2758 If EndBit is less than StartBit, then ASSERT().
2760 @param Operand Operand on which to perform the bitfield operation.
2761 @param StartBit The ordinal of the least significant bit in the bit field.
2763 @param EndBit The ordinal of the most significant bit in the bit field.
2765 @param OrData The value to OR with the read value from the value
2767 @return The new 32-bit value.
2781 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2784 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2785 in Operand and the value specified by AndData. All other bits in Operand are
2786 preserved. The new 32-bit value is returned.
2788 If 32-bit operations are not supported, then ASSERT().
2789 If StartBit is greater than 31, then ASSERT().
2790 If EndBit is greater than 31, then ASSERT().
2791 If EndBit is less than StartBit, then ASSERT().
2793 @param Operand Operand on which to perform the bitfield operation.
2794 @param StartBit The ordinal of the least significant bit in the bit field.
2796 @param EndBit The ordinal of the most significant bit in the bit field.
2798 @param AndData The value to AND with the read value from the value
2800 @return The new 32-bit value.
2814 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2815 bitwise OR, and returns the result.
2817 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2818 in Operand and the value specified by AndData, followed by a bitwise
2819 inclusive OR with value specified by OrData. All other bits in Operand are
2820 preserved. The new 32-bit value is returned.
2822 If 32-bit operations are not supported, then ASSERT().
2823 If StartBit is greater than 31, then ASSERT().
2824 If EndBit is greater than 31, then ASSERT().
2825 If EndBit is less than StartBit, then ASSERT().
2827 @param Operand Operand on which to perform the bitfield operation.
2828 @param StartBit The ordinal of the least significant bit in the bit field.
2830 @param EndBit The ordinal of the most significant bit in the bit field.
2832 @param AndData The value to AND with the read value from the value.
2833 @param OrData The value to OR with the result of the AND operation.
2835 @return The new 32-bit value.
2840 BitFieldAndThenOr32 (
2850 Returns a bit field from a 64-bit value.
2852 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2854 If 64-bit operations are not supported, then ASSERT().
2855 If StartBit is greater than 63, then ASSERT().
2856 If EndBit is greater than 63, then ASSERT().
2857 If EndBit is less than StartBit, then ASSERT().
2859 @param Operand Operand on which to perform the bitfield operation.
2860 @param StartBit The ordinal of the least significant bit in the bit field.
2862 @param EndBit The ordinal of the most significant bit in the bit field.
2865 @return The bit field read.
2878 Writes a bit field to a 64-bit value, and returns the result.
2880 Writes Value to the bit field specified by the StartBit and the EndBit in
2881 Operand. All other bits in Operand are preserved. The new 64-bit value is
2884 If 64-bit operations are not supported, then ASSERT().
2885 If StartBit is greater than 63, then ASSERT().
2886 If EndBit is greater than 63, then ASSERT().
2887 If EndBit is less than StartBit, then ASSERT().
2889 @param Operand Operand on which to perform the bitfield operation.
2890 @param StartBit The ordinal of the least significant bit in the bit field.
2892 @param EndBit The ordinal of the most significant bit in the bit field.
2894 @param Value New value of the bit field.
2896 @return The new 64-bit value.
2910 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2913 Performs a bitwise inclusive OR between the bit field specified by StartBit
2914 and EndBit in Operand and the value specified by OrData. All other bits in
2915 Operand are preserved. The new 64-bit value is returned.
2917 If 64-bit operations are not supported, then ASSERT().
2918 If StartBit is greater than 63, then ASSERT().
2919 If EndBit is greater than 63, then ASSERT().
2920 If EndBit is less than StartBit, then ASSERT().
2922 @param Operand Operand on which to perform the bitfield operation.
2923 @param StartBit The ordinal of the least significant bit in the bit field.
2925 @param EndBit The ordinal of the most significant bit in the bit field.
2927 @param OrData The value to OR with the read value from the value
2929 @return The new 64-bit value.
2943 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2946 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2947 in Operand and the value specified by AndData. All other bits in Operand are
2948 preserved. The new 64-bit value is returned.
2950 If 64-bit operations are not supported, then ASSERT().
2951 If StartBit is greater than 63, then ASSERT().
2952 If EndBit is greater than 63, then ASSERT().
2953 If EndBit is less than StartBit, then ASSERT().
2955 @param Operand Operand on which to perform the bitfield operation.
2956 @param StartBit The ordinal of the least significant bit in the bit field.
2958 @param EndBit The ordinal of the most significant bit in the bit field.
2960 @param AndData The value to AND with the read value from the value
2962 @return The new 64-bit value.
2976 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2977 bitwise OR, and returns the result.
2979 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2980 in Operand and the value specified by AndData, followed by a bitwise
2981 inclusive OR with value specified by OrData. All other bits in Operand are
2982 preserved. The new 64-bit value is returned.
2984 If 64-bit operations are not supported, then ASSERT().
2985 If StartBit is greater than 63, then ASSERT().
2986 If EndBit is greater than 63, then ASSERT().
2987 If EndBit is less than StartBit, then ASSERT().
2989 @param Operand Operand on which to perform the bitfield operation.
2990 @param StartBit The ordinal of the least significant bit in the bit field.
2992 @param EndBit The ordinal of the most significant bit in the bit field.
2994 @param AndData The value to AND with the read value from the value.
2995 @param OrData The value to OR with the result of the AND operation.
2997 @return The new 64-bit value.
3002 BitFieldAndThenOr64 (
3012 // Base Library Synchronization Functions
3016 Retrieves the architecture specific spin lock alignment requirements for
3017 optimal spin lock performance.
3019 This function retrieves the spin lock alignment requirements for optimal
3020 performance on a given CPU architecture. The spin lock alignment must be a
3021 power of two and is returned by this function. If there are no alignment
3022 requirements, then 1 must be returned. The spin lock synchronization
3023 functions must function correctly if the spin lock size and alignment values
3024 returned by this function are not used at all. These values are hints to the
3025 consumers of the spin lock synchronization functions to obtain optimal spin
3028 @return The architecture specific spin lock alignment.
3033 GetSpinLockProperties (
3039 Initializes a spin lock to the released state and returns the spin lock.
3041 This function initializes the spin lock specified by SpinLock to the released
3042 state, and returns SpinLock. Optimal performance can be achieved by calling
3043 GetSpinLockProperties() to determine the size and alignment requirements for
3046 If SpinLock is NULL, then ASSERT().
3048 @param SpinLock A pointer to the spin lock to initialize to the released
3056 InitializeSpinLock (
3057 IN SPIN_LOCK
*SpinLock
3062 Waits until a spin lock can be placed in the acquired state.
3064 This function checks the state of the spin lock specified by SpinLock. If
3065 SpinLock is in the released state, then this function places SpinLock in the
3066 acquired state and returns SpinLock. Otherwise, this function waits
3067 indefinitely for the spin lock to be released, and then places it in the
3068 acquired state and returns SpinLock. All state transitions of SpinLock must
3069 be performed using MP safe mechanisms.
3071 If SpinLock is NULL, then ASSERT().
3072 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3073 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
3074 PcdSpinLockTimeout microseconds, then ASSERT().
3076 @param SpinLock A pointer to the spin lock to place in the acquired state.
3084 IN SPIN_LOCK
*SpinLock
3089 Attempts to place a spin lock in the acquired state.
3091 This function checks the state of the spin lock specified by SpinLock. If
3092 SpinLock is in the released state, then this function places SpinLock in the
3093 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
3094 transitions of SpinLock must be performed using MP safe mechanisms.
3096 If SpinLock is NULL, then ASSERT().
3097 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3099 @param SpinLock A pointer to the spin lock to place in the acquired state.
3101 @retval TRUE SpinLock was placed in the acquired state.
3102 @retval FALSE SpinLock could not be acquired.
3107 AcquireSpinLockOrFail (
3108 IN SPIN_LOCK
*SpinLock
3113 Releases a spin lock.
3115 This function places the spin lock specified by SpinLock in the release state
3116 and returns SpinLock.
3118 If SpinLock is NULL, then ASSERT().
3119 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
3121 @param SpinLock A pointer to the spin lock to release.
3129 IN SPIN_LOCK
*SpinLock
3134 Performs an atomic increment of an 32-bit unsigned integer.
3136 Performs an atomic increment of the 32-bit unsigned integer specified by
3137 Value and returns the incremented value. The increment operation must be
3138 performed using MP safe mechanisms. The state of the return value is not
3139 guaranteed to be MP safe.
3141 If Value is NULL, then ASSERT().
3143 @param Value A pointer to the 32-bit value to increment.
3145 @return The incremented value.
3150 InterlockedIncrement (
3156 Performs an atomic decrement of an 32-bit unsigned integer.
3158 Performs an atomic decrement of the 32-bit unsigned integer specified by
3159 Value and returns the decremented value. The decrement operation must be
3160 performed using MP safe mechanisms. The state of the return value is not
3161 guaranteed to be MP safe.
3163 If Value is NULL, then ASSERT().
3165 @param Value A pointer to the 32-bit value to decrement.
3167 @return The decremented value.
3172 InterlockedDecrement (
3178 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
3180 Performs an atomic compare exchange operation on the 32-bit unsigned integer
3181 specified by Value. If Value is equal to CompareValue, then Value is set to
3182 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
3183 then Value is returned. The compare exchange operation must be performed using
3186 If Value is NULL, then ASSERT().
3188 @param Value A pointer to the 32-bit value for the compare exchange
3190 @param CompareValue 32-bit value used in compare operation.
3191 @param ExchangeValue 32-bit value used in exchange operation.
3193 @return The original *Value before exchange.
3198 InterlockedCompareExchange32 (
3199 IN OUT UINT32
*Value
,
3200 IN UINT32 CompareValue
,
3201 IN UINT32 ExchangeValue
3206 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
3208 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
3209 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
3210 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
3211 The compare exchange operation must be performed using MP safe mechanisms.
3213 If Value is NULL, then ASSERT().
3215 @param Value A pointer to the 64-bit value for the compare exchange
3217 @param CompareValue 64-bit value used in compare operation.
3218 @param ExchangeValue 64-bit value used in exchange operation.
3220 @return The original *Value before exchange.
3225 InterlockedCompareExchange64 (
3226 IN OUT UINT64
*Value
,
3227 IN UINT64 CompareValue
,
3228 IN UINT64 ExchangeValue
3233 Performs an atomic compare exchange operation on a pointer value.
3235 Performs an atomic compare exchange operation on the pointer value specified
3236 by Value. If Value is equal to CompareValue, then Value is set to
3237 ExchangeValue and CompareValue is returned. If Value is not equal to
3238 CompareValue, then Value is returned. The compare exchange operation must be
3239 performed using MP safe mechanisms.
3241 If Value is NULL, then ASSERT().
3243 @param Value A pointer to the pointer value for the compare exchange
3245 @param CompareValue Pointer value used in compare operation.
3246 @param ExchangeValue Pointer value used in exchange operation.
3251 InterlockedCompareExchangePointer (
3252 IN OUT VOID
**Value
,
3253 IN VOID
*CompareValue
,
3254 IN VOID
*ExchangeValue
3259 // Base Library Checksum Functions
3263 Calculate the sum of all elements in a buffer in unit of UINT8.
3264 During calculation, the carry bits are dropped.
3266 This function calculates the sum of all elements in a buffer
3267 in unit of UINT8. The carry bits in result of addition are dropped.
3268 The result is returned as UINT8. If Length is Zero, then Zero is
3271 If Buffer is NULL, then ASSERT().
3272 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3274 @param Buffer Pointer to the buffer to carry out the sum operation.
3275 @param Length The size, in bytes, of Buffer .
3277 @return Sum The sum of Buffer with carry bits dropped during additions.
3283 IN CONST UINT8
*Buffer
,
3289 Returns the two's complement checksum of all elements in a buffer
3292 This function first calculates the sum of the 8-bit values in the
3293 buffer specified by Buffer and Length. The carry bits in the result
3294 of addition are dropped. Then, the two's complement of the sum is
3295 returned. If Length is 0, then 0 is returned.
3297 If Buffer is NULL, then ASSERT().
3298 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3301 @param Buffer Pointer to the buffer to carry out the checksum operation.
3302 @param Length The size, in bytes, of Buffer.
3304 @return Checksum The 2's complement checksum of Buffer.
3309 CalculateCheckSum8 (
3310 IN CONST UINT8
*Buffer
,
3316 Returns the sum of all elements in a buffer of 16-bit values. During
3317 calculation, the carry bits are dropped.
3319 This function calculates the sum of the 16-bit values in the buffer
3320 specified by Buffer and Length. The carry bits in result of addition are dropped.
3321 The 16-bit result is returned. If Length is 0, then 0 is returned.
3323 If Buffer is NULL, then ASSERT().
3324 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3325 If Length is not aligned on a 16-bit boundary, then ASSERT().
3326 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3328 @param Buffer Pointer to the buffer to carry out the sum operation.
3329 @param Length The size, in bytes, of Buffer.
3331 @return Sum The sum of Buffer with carry bits dropped during additions.
3337 IN CONST UINT16
*Buffer
,
3343 Returns the two's complement checksum of all elements in a buffer of
3346 This function first calculates the sum of the 16-bit values in the buffer
3347 specified by Buffer and Length. The carry bits in the result of addition
3348 are dropped. Then, the two's complement of the sum is returned. If Length
3349 is 0, then 0 is returned.
3351 If Buffer is NULL, then ASSERT().
3352 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3353 If Length is not aligned on a 16-bit boundary, then ASSERT().
3354 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3356 @param Buffer Pointer to the buffer to carry out the checksum operation.
3357 @param Length The size, in bytes, of Buffer.
3359 @return Checksum The 2's complement checksum of Buffer.
3364 CalculateCheckSum16 (
3365 IN CONST UINT16
*Buffer
,
3371 Returns the sum of all elements in a buffer of 32-bit values. During
3372 calculation, the carry bits are dropped.
3374 This function calculates the sum of the 32-bit values in the buffer
3375 specified by Buffer and Length. The carry bits in result of addition are dropped.
3376 The 32-bit result is returned. If Length is 0, then 0 is returned.
3378 If Buffer is NULL, then ASSERT().
3379 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3380 If Length is not aligned on a 32-bit boundary, then ASSERT().
3381 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3383 @param Buffer Pointer to the buffer to carry out the sum operation.
3384 @param Length The size, in bytes, of Buffer.
3386 @return Sum The sum of Buffer with carry bits dropped during additions.
3392 IN CONST UINT32
*Buffer
,
3398 Returns the two's complement checksum of all elements in a buffer of
3401 This function first calculates the sum of the 32-bit values in the buffer
3402 specified by Buffer and Length. The carry bits in the result of addition
3403 are dropped. Then, the two's complement of the sum is returned. If Length
3404 is 0, then 0 is returned.
3406 If Buffer is NULL, then ASSERT().
3407 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3408 If Length is not aligned on a 32-bit boundary, then ASSERT().
3409 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3411 @param Buffer Pointer to the buffer to carry out the checksum operation.
3412 @param Length The size, in bytes, of Buffer.
3414 @return Checksum The 2's complement checksum of Buffer.
3419 CalculateCheckSum32 (
3420 IN CONST UINT32
*Buffer
,
3426 Returns the sum of all elements in a buffer of 64-bit values. During
3427 calculation, the carry bits are dropped.
3429 This function calculates the sum of the 64-bit values in the buffer
3430 specified by Buffer and Length. The carry bits in result of addition are dropped.
3431 The 64-bit result is returned. If Length is 0, then 0 is returned.
3433 If Buffer is NULL, then ASSERT().
3434 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3435 If Length is not aligned on a 64-bit boundary, then ASSERT().
3436 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3438 @param Buffer Pointer to the buffer to carry out the sum operation.
3439 @param Length The size, in bytes, of Buffer.
3441 @return Sum The sum of Buffer with carry bits dropped during additions.
3447 IN CONST UINT64
*Buffer
,
3453 Returns the two's complement checksum of all elements in a buffer of
3456 This function first calculates the sum of the 64-bit values in the buffer
3457 specified by Buffer and Length. The carry bits in the result of addition
3458 are dropped. Then, the two's complement of the sum is returned. If Length
3459 is 0, then 0 is returned.
3461 If Buffer is NULL, then ASSERT().
3462 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3463 If Length is not aligned on a 64-bit boundary, then ASSERT().
3464 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3466 @param Buffer Pointer to the buffer to carry out the checksum operation.
3467 @param Length The size, in bytes, of Buffer.
3469 @return Checksum The 2's complement checksum of Buffer.
3474 CalculateCheckSum64 (
3475 IN CONST UINT64
*Buffer
,
3481 // Base Library CPU Functions
3485 (EFIAPI
*SWITCH_STACK_ENTRY_POINT
) (
3486 IN VOID
*Context1
, OPTIONAL
3487 IN VOID
*Context2 OPTIONAL
3492 Used to serialize load and store operations.
3494 All loads and stores that proceed calls to this function are guaranteed to be
3495 globally visible when this function returns.
3506 Saves the current CPU context that can be restored with a call to LongJump()
3509 Saves the current CPU context in the buffer specified by JumpBuffer and
3510 returns 0. The initial call to SetJump() must always return 0. Subsequent
3511 calls to LongJump() cause a non-zero value to be returned by SetJump().
3513 If JumpBuffer is NULL, then ASSERT().
3514 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3516 @param JumpBuffer A pointer to CPU context buffer.
3518 @retval 0 Indicates a return from SetJump().
3524 OUT BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
3529 Restores the CPU context that was saved with SetJump().
3531 Restores the CPU context from the buffer specified by JumpBuffer. This
3532 function never returns to the caller. Instead is resumes execution based on
3533 the state of JumpBuffer.
3535 If JumpBuffer is NULL, then ASSERT().
3536 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3537 If Value is 0, then ASSERT().
3539 @param JumpBuffer A pointer to CPU context buffer.
3540 @param Value The value to return when the SetJump() context is
3541 restored and must be non-zero.
3547 IN BASE_LIBRARY_JUMP_BUFFER
*JumpBuffer
,
3553 Enables CPU interrupts.
3555 Enables CPU interrupts.
3566 Disables CPU interrupts.
3568 Disables CPU interrupts.
3579 Disables CPU interrupts and returns the interrupt state prior to the disable
3582 Disables CPU interrupts and returns the interrupt state prior to the disable
3585 @retval TRUE CPU interrupts were enabled on entry to this call.
3586 @retval FALSE CPU interrupts were disabled on entry to this call.
3591 SaveAndDisableInterrupts (
3597 Enables CPU interrupts for the smallest window required to capture any
3600 Enables CPU interrupts for the smallest window required to capture any
3606 EnableDisableInterrupts (
3612 Retrieves the current CPU interrupt state.
3614 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
3615 currently enabled. Otherwise returns FALSE.
3617 @retval TRUE CPU interrupts are enabled.
3618 @retval FALSE CPU interrupts are disabled.
3629 Set the current CPU interrupt state.
3631 Sets the current CPU interrupt state to the state specified by
3632 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
3633 InterruptState is FALSE, then interrupts are disabled. InterruptState is
3636 @param InterruptState TRUE if interrupts should enabled. FALSE if
3637 interrupts should be disabled.
3639 @return InterruptState
3645 IN BOOLEAN InterruptState
3650 Requests CPU to pause for a short period of time.
3652 Requests CPU to pause for a short period of time. Typically used in MP
3653 systems to prevent memory starvation while waiting for a spin lock.
3664 Transfers control to a function starting with a new stack.
3666 Transfers control to the function specified by EntryPoint using the
3667 new stack specified by NewStack and passing in the parameters specified
3668 by Context1 and Context2. Context1 and Context2 are optional and may
3669 be NULL. The function EntryPoint must never return. This function
3670 supports a variable number of arguments following the NewStack parameter.
3671 These additional arguments are ignored on IA-32, x64, and EBC.
3672 IPF CPUs expect one additional parameter of type VOID * that specifies
3673 the new backing store pointer.
3675 If EntryPoint is NULL, then ASSERT().
3676 If NewStack is NULL, then ASSERT().
3678 @param EntryPoint A pointer to function to call with the new stack.
3679 @param Context1 A pointer to the context to pass into the EntryPoint
3681 @param Context2 A pointer to the context to pass into the EntryPoint
3683 @param NewStack A pointer to the new stack to use for the EntryPoint
3690 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
3691 IN VOID
*Context1
, OPTIONAL
3692 IN VOID
*Context2
, OPTIONAL
3699 Generates a breakpoint on the CPU.
3701 Generates a breakpoint on the CPU. The breakpoint must be implemented such
3702 that code can resume normal execution after the breakpoint.
3713 Executes an infinite loop.
3715 Forces the CPU to execute an infinite loop. A debugger may be used to skip
3716 past the loop and the code that follows the loop must execute properly. This
3717 implies that the infinite loop must not cause the code that follow it to be
3728 #if defined (MDE_CPU_IPF)
3731 Flush a range of cache lines in the cache coherency domain of the calling
3734 Invalidates the cache lines specified by Address and Length. If Address is
3735 not aligned on a cache line boundary, then entire cache line containing
3736 Address is invalidated. If Address + Length is not aligned on a cache line
3737 boundary, then the entire instruction cache line containing Address + Length
3738 -1 is invalidated. This function may choose to invalidate the entire
3739 instruction cache if that is more efficient than invalidating the specified
3740 range. If Length is 0, the no instruction cache lines are invalidated.
3741 Address is returned.
3743 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
3745 @param Address The base address of the instruction lines to invalidate. If
3746 the CPU is in a physical addressing mode, then Address is a
3747 physical address. If the CPU is in a virtual addressing mode,
3748 then Address is a virtual address.
3750 @param Length The number of bytes to invalidate from the instruction cache.
3757 IpfFlushCacheRange (
3764 Executes a FC instruction
3765 Executes a FC instruction on the cache line specified by Address.
3766 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3767 An implementation may flush a larger region. This function is only available on IPF.
3769 @param Address The Address of cache line to be flushed.
3771 @return The address of FC instruction executed.
3782 Executes a FC.I instruction.
3783 Executes a FC.I instruction on the cache line specified by Address.
3784 The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
3785 An implementation may flush a larger region. This function is only available on IPF.
3787 @param Address The Address of cache line to be flushed.
3789 @return The address of FC.I instruction executed.
3800 Reads the current value of a Processor Identifier Register (CPUID).
3801 The Index of largest implemented CPUID (One less than the number of implemented CPUID
3802 registers) is determined by CPUID [3] bits {7:0}.
3803 No parameter checking is performed on Index. If the Index value is beyond the
3804 implemented CPUID register range, a Reserved Register/Field fault may occur. The caller
3805 must either guarantee that Index is valid, or the caller must set up fault handlers to
3806 catch the faults. This function is only available on IPF.
3808 @param Index The 8-bit Processor Identifier Register index to read.
3810 @return The current value of Processor Identifier Register specified by Index.
3821 Reads the current value of 64-bit Processor Status Register (PSR).
3822 This function is only available on IPF.
3824 @return The current value of PSR.
3835 Writes the current value of 64-bit Processor Status Register (PSR).
3836 No parameter checking is performed on Value. All bits of Value corresponding to
3837 reserved fields of PSR must be 0 or a Reserved Register/Field fault may occur. The caller must either guarantee that Value is valid, or the caller must set up fault handlers to catch the faults.
3838 This function is only available on IPF.
3840 @param Value The 64-bit value to write to PSR.
3842 @return The 64-bit value written to the PSR.
3853 Reads the current value of 64-bit Kernel Register #0 (KR0).
3854 This function is only available on IPF.
3856 @return The current value of KR0.
3867 Reads the current value of 64-bit Kernel Register #1 (KR1).
3868 This function is only available on IPF.
3870 @return The current value of KR1.
3881 Reads the current value of 64-bit Kernel Register #2 (KR2).
3882 This function is only available on IPF.
3884 @return The current value of KR2.
3895 Reads the current value of 64-bit Kernel Register #3 (KR3).
3896 This function is only available on IPF.
3898 @return The current value of KR3.
3909 Reads the current value of 64-bit Kernel Register #4 (KR4).
3910 This function is only available on IPF.
3912 @return The current value of KR4.
3923 Reads the current value of 64-bit Kernel Register #5 (KR5).
3924 This function is only available on IPF.
3926 @return The current value of KR5.
3937 Reads the current value of 64-bit Kernel Register #6 (KR6).
3938 This function is only available on IPF.
3940 @return The current value of KR6.
3951 Reads the current value of 64-bit Kernel Register #7 (KR7).
3952 This function is only available on IPF.
3954 @return The current value of KR7.
3965 Write the current value of 64-bit Kernel Register #0 (KR0).
3966 This function is only available on IPF.
3968 @param Value The 64-bit value to write to KR0.
3970 @return The 64-bit value written to the KR0.
3981 Write the current value of 64-bit Kernel Register #1 (KR1).
3982 This function is only available on IPF.
3984 @param Value The 64-bit value to write to KR1.
3986 @return The 64-bit value written to the KR1.
3997 Write the current value of 64-bit Kernel Register #2 (KR2).
3998 This function is only available on IPF.
4000 @param Value The 64-bit value to write to KR2.
4002 @return The 64-bit value written to the KR2.
4013 Write the current value of 64-bit Kernel Register #3 (KR3).
4014 This function is only available on IPF.
4016 @param Value The 64-bit value to write to KR3.
4018 @return The 64-bit value written to the KR3.
4029 Write the current value of 64-bit Kernel Register #4 (KR4).
4030 This function is only available on IPF.
4032 @param Value The 64-bit value to write to KR4.
4034 @return The 64-bit value written to the KR4.
4045 Write the current value of 64-bit Kernel Register #5 (KR5).
4046 This function is only available on IPF.
4048 @param Value The 64-bit value to write to KR5.
4050 @return The 64-bit value written to the KR5.
4061 Write the current value of 64-bit Kernel Register #6 (KR6).
4062 This function is only available on IPF.
4064 @param Value The 64-bit value to write to KR6.
4066 @return The 64-bit value written to the KR6.
4077 Write the current value of 64-bit Kernel Register #7 (KR7).
4078 This function is only available on IPF.
4080 @param Value The 64-bit value to write to KR7.
4082 @return The 64-bit value written to the KR7.
4093 Reads the current value of Interval Timer Counter Register (ITC).
4094 This function is only available on IPF.
4096 @return The current value of ITC.
4107 Reads the current value of Interval Timer Vector Register (ITV).
4108 This function is only available on IPF.
4110 @return The current value of ITV.
4121 Reads the current value of Interval Timer Match Register (ITM).
4122 This function is only available on IPF.
4124 @return The current value of ITM.
4134 Writes the current value of 64-bit Interval Timer Counter Register (ITC).
4135 This function is only available on IPF.
4137 @param Value The 64-bit value to write to ITC.
4139 @return The 64-bit value written to the ITC.
4150 Writes the current value of 64-bit Interval Timer Match Register (ITM).
4151 This function is only available on IPF.
4153 @param Value The 64-bit value to write to ITM.
4155 @return The 64-bit value written to the ITM.
4166 Writes the current value of 64-bit Interval Timer Vector Register (ITV).
4167 No parameter checking is performed on Value. All bits of Value corresponding to
4168 reserved fields of ITV must be 0 or a Reserved Register/Field fault may occur.
4169 The caller must either guarantee that Value is valid, or the caller must set up
4170 fault handlers to catch the faults.
4171 This function is only available on IPF.
4173 @param Value The 64-bit value to write to ITV.
4175 @return The 64-bit value written to the ITV.
4186 Reads the current value of Default Control Register (DCR).
4187 This function is only available on IPF.
4189 @return The current value of DCR.
4200 Reads the current value of Interruption Vector Address Register (IVA).
4201 This function is only available on IPF.
4203 @return The current value of IVA.
4213 Reads the current value of Page Table Address Register (PTA).
4214 This function is only available on IPF.
4216 @return The current value of PTA.
4227 Writes the current value of 64-bit Default Control Register (DCR).
4228 No parameter checking is performed on Value. All bits of Value corresponding to
4229 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4230 The caller must either guarantee that Value is valid, or the caller must set up
4231 fault handlers to catch the faults.
4232 This function is only available on IPF.
4234 @param Value The 64-bit value to write to DCR.
4236 @return The 64-bit value written to the DCR.
4247 Writes the current value of 64-bit Interruption Vector Address Register (IVA).
4248 The size of vector table is 32 K bytes and is 32 K bytes aligned
4249 the low 15 bits of Value is ignored when written.
4250 This function is only available on IPF.
4252 @param Value The 64-bit value to write to IVA.
4254 @return The 64-bit value written to the IVA.
4265 Writes the current value of 64-bit Page Table Address Register (PTA).
4266 No parameter checking is performed on Value. All bits of Value corresponding to
4267 reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
4268 The caller must either guarantee that Value is valid, or the caller must set up
4269 fault handlers to catch the faults.
4270 This function is only available on IPF.
4272 @param Value The 64-bit value to write to PTA.
4274 @return The 64-bit value written to the PTA.
4284 Reads the current value of Local Interrupt ID Register (LID).
4285 This function is only available on IPF.
4287 @return The current value of LID.
4298 Reads the current value of External Interrupt Vector Register (IVR).
4299 This function is only available on IPF.
4301 @return The current value of IVR.
4312 Reads the current value of Task Priority Register (TPR).
4313 This function is only available on IPF.
4315 @return The current value of TPR.
4326 Reads the current value of External Interrupt Request Register #0 (IRR0).
4327 This function is only available on IPF.
4329 @return The current value of IRR0.
4340 Reads the current value of External Interrupt Request Register #1 (IRR1).
4341 This function is only available on IPF.
4343 @return The current value of IRR1.
4354 Reads the current value of External Interrupt Request Register #2 (IRR2).
4355 This function is only available on IPF.
4357 @return The current value of IRR2.
4368 Reads the current value of External Interrupt Request Register #3 (IRR3).
4369 This function is only available on IPF.
4371 @return The current value of IRR3.
4382 Reads the current value of Performance Monitor Vector Register (PMV).
4383 This function is only available on IPF.
4385 @return The current value of PMV.
4396 Reads the current value of Corrected Machine Check Vector Register (CMCV).
4397 This function is only available on IPF.
4399 @return The current value of CMCV.
4410 Reads the current value of Local Redirection Register #0 (LRR0).
4411 This function is only available on IPF.
4413 @return The current value of LRR0.
4424 Reads the current value of Local Redirection Register #1 (LRR1).
4425 This function is only available on IPF.
4427 @return The current value of LRR1.
4438 Writes the current value of 64-bit Page Local Interrupt ID Register (LID).
4439 No parameter checking is performed on Value. All bits of Value corresponding to
4440 reserved fields of LID must be 0 or a Reserved Register/Field fault may occur.
4441 The caller must either guarantee that Value is valid, or the caller must set up
4442 fault handlers to catch the faults.
4443 This function is only available on IPF.
4445 @param Value The 64-bit value to write to LID.
4447 @return The 64-bit value written to the LID.
4458 Writes the current value of 64-bit Task Priority Register (TPR).
4459 No parameter checking is performed on Value. All bits of Value corresponding to
4460 reserved fields of TPR must be 0 or a Reserved Register/Field fault may occur.
4461 The caller must either guarantee that Value is valid, or the caller must set up
4462 fault handlers to catch the faults.
4463 This function is only available on IPF.
4465 @param Value The 64-bit value to write to TPR.
4467 @return The 64-bit value written to the TPR.
4478 Performs a write operation on End OF External Interrupt Register (EOI).
4479 Writes a value of 0 to the EOI Register. This function is only available on IPF.
4490 Writes the current value of 64-bit Performance Monitor Vector Register (PMV).
4491 No parameter checking is performed on Value. All bits of Value corresponding
4492 to reserved fields of PMV must be 0 or a Reserved Register/Field fault may occur.
4493 The caller must either guarantee that Value is valid, or the caller must set up
4494 fault handlers to catch the faults.
4495 This function is only available on IPF.
4497 @param Value The 64-bit value to write to PMV.
4499 @return The 64-bit value written to the PMV.
4510 Writes the current value of 64-bit Corrected Machine Check Vector Register (CMCV).
4511 No parameter checking is performed on Value. All bits of Value corresponding
4512 to reserved fields of CMCV must be 0 or a Reserved Register/Field fault may occur.
4513 The caller must either guarantee that Value is valid, or the caller must set up
4514 fault handlers to catch the faults.
4515 This function is only available on IPF.
4517 @param Value The 64-bit value to write to CMCV.
4519 @return The 64-bit value written to the CMCV.
4530 Writes the current value of 64-bit Local Redirection Register #0 (LRR0).
4531 No parameter checking is performed on Value. All bits of Value corresponding
4532 to reserved fields of LRR0 must be 0 or a Reserved Register/Field fault may occur.
4533 The caller must either guarantee that Value is valid, or the caller must set up
4534 fault handlers to catch the faults.
4535 This function is only available on IPF.
4537 @param Value The 64-bit value to write to LRR0.
4539 @return The 64-bit value written to the LRR0.
4550 Writes the current value of 64-bit Local Redirection Register #1 (LRR1).
4551 No parameter checking is performed on Value. All bits of Value corresponding
4552 to reserved fields of LRR1 must be 0 or a Reserved Register/Field fault may occur.
4553 The caller must either guarantee that Value is valid, or the caller must
4554 set up fault handlers to catch the faults.
4555 This function is only available on IPF.
4557 @param Value The 64-bit value to write to LRR1.
4559 @return The 64-bit value written to the LRR1.
4570 Reads the current value of Instruction Breakpoint Register (IBR).
4572 The Instruction Breakpoint Registers are used in pairs. The even numbered
4573 registers contain breakpoint addresses, and the odd numbered registers contain
4574 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4575 on all processor models. Implemented registers are contiguous starting with
4576 register 0. No parameter checking is performed on Index, and if the Index value
4577 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4578 occur. The caller must either guarantee that Index is valid, or the caller must
4579 set up fault handlers to catch the faults.
4580 This function is only available on IPF.
4582 @param Index The 8-bit Instruction Breakpoint Register index to read.
4584 @return The current value of Instruction Breakpoint Register specified by Index.
4595 Reads the current value of Data Breakpoint Register (DBR).
4597 The Data Breakpoint Registers are used in pairs. The even numbered registers
4598 contain breakpoint addresses, and odd numbered registers contain breakpoint
4599 mask conditions. At least 4 data registers pairs are implemented on all processor
4600 models. Implemented registers are contiguous starting with register 0.
4601 No parameter checking is performed on Index. If the Index value is beyond
4602 the implemented DBR register range, a Reserved Register/Field fault may occur.
4603 The caller must either guarantee that Index is valid, or the caller must set up
4604 fault handlers to catch the faults.
4605 This function is only available on IPF.
4607 @param Index The 8-bit Data Breakpoint Register index to read.
4609 @return The current value of Data Breakpoint Register specified by Index.
4620 Reads the current value of Performance Monitor Configuration Register (PMC).
4622 All processor implementations provide at least 4 performance counters
4623 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4624 status registers (PMC [0]¡ PMC [3]). Processor implementations may provide
4625 additional implementation-dependent PMC and PMD to increase the number of
4626 ¡®generic¡¯ performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4627 register set is implementation dependent. No parameter checking is performed
4628 on Index. If the Index value is beyond the implemented PMC register range,
4629 zero value will be returned.
4630 This function is only available on IPF.
4632 @param Index The 8-bit Performance Monitor Configuration Register index to read.
4634 @return The current value of Performance Monitor Configuration Register
4646 Reads the current value of Performance Monitor Data Register (PMD).
4648 All processor implementations provide at least 4 performance counters
4649 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter
4650 overflow status registers (PMC [0]¡ PMC [3]). Processor implementations may
4651 provide additional implementation-dependent PMC and PMD to increase the number
4652 of ¡®generic¡¯ performance counters (PMC/PMD pairs). The remainder of PMC and PMD
4653 register set is implementation dependent. No parameter checking is performed
4654 on Index. If the Index value is beyond the implemented PMD register range,
4655 zero value will be returned.
4656 This function is only available on IPF.
4658 @param Index The 8-bit Performance Monitor Data Register index to read.
4660 @return The current value of Performance Monitor Data Register specified by Index.
4671 Writes the current value of 64-bit Instruction Breakpoint Register (IBR).
4673 Writes current value of Instruction Breakpoint Register specified by Index.
4674 The Instruction Breakpoint Registers are used in pairs. The even numbered
4675 registers contain breakpoint addresses, and odd numbered registers contain
4676 breakpoint mask conditions. At least 4 instruction registers pairs are implemented
4677 on all processor models. Implemented registers are contiguous starting with
4678 register 0. No parameter checking is performed on Index. If the Index value
4679 is beyond the implemented IBR register range, a Reserved Register/Field fault may
4680 occur. The caller must either guarantee that Index is valid, or the caller must
4681 set up fault handlers to catch the faults.
4682 This function is only available on IPF.
4684 @param Index The 8-bit Instruction Breakpoint Register index to write.
4685 @param Value The 64-bit value to write to IBR.
4687 @return The 64-bit value written to the IBR.
4699 Writes the current value of 64-bit Data Breakpoint Register (DBR).
4701 Writes current value of Data Breakpoint Register specified by Index.
4702 The Data Breakpoint Registers are used in pairs. The even numbered registers
4703 contain breakpoint addresses, and odd numbered registers contain breakpoint
4704 mask conditions. At least 4 data registers pairs are implemented on all processor
4705 models. Implemented registers are contiguous starting with register 0. No parameter
4706 checking is performed on Index. If the Index value is beyond the implemented
4707 DBR register range, a Reserved Register/Field fault may occur. The caller must
4708 either guarantee that Index is valid, or the caller must set up fault handlers to
4710 This function is only available on IPF.
4712 @param Index The 8-bit Data Breakpoint Register index to write.
4713 @param Value The 64-bit value to write to DBR.
4715 @return The 64-bit value written to the DBR.
4727 Writes the current value of 64-bit Performance Monitor Configuration Register (PMC).
4729 Writes current value of Performance Monitor Configuration Register specified by Index.
4730 All processor implementations provide at least 4 performance counters
4731 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow status
4732 registers (PMC [0]¡ PMC [3]). Processor implementations may provide additional
4733 implementation-dependent PMC and PMD to increase the number of ¡®generic¡¯ performance
4734 counters (PMC/PMD pairs). The remainder of PMC and PMD register set is implementation
4735 dependent. No parameter checking is performed on Index. If the Index value is
4736 beyond the implemented PMC register range, the write is ignored.
4737 This function is only available on IPF.
4739 @param Index The 8-bit Performance Monitor Configuration Register index to write.
4740 @param Value The 64-bit value to write to PMC.
4742 @return The 64-bit value written to the PMC.
4754 Writes the current value of 64-bit Performance Monitor Data Register (PMD).
4756 Writes current value of Performance Monitor Data Register specified by Index.
4757 All processor implementations provide at least 4 performance counters
4758 (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter overflow
4759 status registers (PMC [0]¡ PMC [3]). Processor implementations may provide
4760 additional implementation-dependent PMC and PMD to increase the number of ¡®generic¡¯
4761 performance counters (PMC/PMD pairs). The remainder of PMC and PMD register set
4762 is implementation dependent. No parameter checking is performed on Index. If the
4763 Index value is beyond the implemented PMD register range, the write is ignored.
4764 This function is only available on IPF.
4766 @param Index The 8-bit Performance Monitor Data Register index to write.
4767 @param Value The 64-bit value to write to PMD.
4769 @return The 64-bit value written to the PMD.
4781 Reads the current value of 64-bit Global Pointer (GP).
4783 Reads and returns the current value of GP.
4784 This function is only available on IPF.
4786 @return The current value of GP.
4797 Write the current value of 64-bit Global Pointer (GP).
4799 Writes the current value of GP. The 64-bit value written to the GP is returned.
4800 No parameter checking is performed on Value.
4801 This function is only available on IPF.
4803 @param Value The 64-bit value to write to GP.
4805 @return The 64-bit value written to the GP.
4816 Reads the current value of 64-bit Stack Pointer (SP).
4818 Reads and returns the current value of SP.
4819 This function is only available on IPF.
4821 @return The current value of SP.
4832 Determines if the CPU is currently executing in virtual, physical, or mixed mode.
4834 Determines the current execution mode of the CPU.
4835 If the CPU is in virtual mode(PSR.RT=1, PSR.DT=1, PSR.IT=1), then 1 is returned.
4836 If the CPU is in physical mode(PSR.RT=0, PSR.DT=0, PSR.IT=0), then 0 is returned.
4837 If the CPU is not in physical mode or virtual mode, then it is in mixed mode,
4839 This function is only available on IPF.
4841 @return 1 The CPU is in virtual mode.
4842 @return 0 The CPU is in physical mode.
4843 @return -1 The CPU is in mixed mode.
4854 Makes a PAL procedure call.
4856 This is a wrapper function to make a PAL procedure call. Based on the Index
4857 value this API will make static or stacked PAL call. The following table
4858 describes the usage of PAL Procedure Index Assignment. Architected procedures
4859 may be designated as required or optional. If a PAL procedure is specified
4860 as optional, a unique return code of 0xFFFFFFFFFFFFFFFF is returned in the
4861 Status field of the PAL_CALL_RETURN structure.
4862 This indicates that the procedure is not present in this PAL implementation.
4863 It is the caller¡¯s responsibility to check for this return code after calling
4864 any optional PAL procedure.
4865 No parameter checking is performed on the 5 input parameters, but there are
4866 some common rules that the caller should follow when making a PAL call. Any
4867 address passed to PAL as buffers for return parameters must be 8-byte aligned.
4868 Unaligned addresses may cause undefined results. For those parameters defined
4869 as reserved or some fields defined as reserved must be zero filled or the invalid
4870 argument return value may be returned or undefined result may occur during the
4871 execution of the procedure. If the PalEntryPoint does not point to a valid
4872 PAL entry point then the system behavior is undefined. This function is only
4875 @param PalEntryPoint The PAL procedure calls entry point.
4876 @param Index The PAL procedure Index number.
4877 @param Arg2 The 2nd parameter for PAL procedure calls.
4878 @param Arg3 The 3rd parameter for PAL procedure calls.
4879 @param Arg4 The 4th parameter for PAL procedure calls.
4881 @return structure returned from the PAL Call procedure, including the status and return value.
4887 IN UINT64 PalEntryPoint
,
4896 Transfers control to a function starting with a new stack.
4898 Transfers control to the function specified by EntryPoint using the new stack
4899 specified by NewStack and passing in the parameters specified by Context1 and
4900 Context2. Context1 and Context2 are optional and may be NULL. The function
4901 EntryPoint must never return.
4903 If EntryPoint is NULL, then ASSERT().
4904 If NewStack is NULL, then ASSERT().
4906 @param EntryPoint A pointer to function to call with the new stack.
4907 @param Context1 A pointer to the context to pass into the EntryPoint
4909 @param Context2 A pointer to the context to pass into the EntryPoint
4911 @param NewStack A pointer to the new stack to use for the EntryPoint
4913 @param NewBsp A pointer to the new memory location for RSE backing
4919 AsmSwitchStackAndBackingStore (
4920 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
4921 IN VOID
*Context1
, OPTIONAL
4922 IN VOID
*Context2
, OPTIONAL
4929 // Bugbug: This call should be removed after
4930 // the PalCall Instance issue has been fixed.
4933 Performs a PAL call using static calling convention.
4935 An internal function to perform a PAL call using static calling convention.
4937 @param PalEntryPoint The entry point address of PAL. The address in ar.kr5
4938 would be used if this parameter were NULL on input.
4939 @param Arg1 The first argument of a PAL call.
4940 @param Arg1 The second argument of a PAL call.
4941 @param Arg1 The third argument of a PAL call.
4942 @param Arg1 The fourth argument of a PAL call.
4944 @return The values returned in r8, r9, r10 and r11.
4949 IN CONST VOID
*PalEntryPoint
,
4957 #elif defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
4959 // IA32 and X64 Specific Functions
4962 // Byte packed structure for 16-bit Real Mode EFLAGS
4966 UINT32 CF
:1; // Carry Flag
4967 UINT32 Reserved_0
:1; // Reserved
4968 UINT32 PF
:1; // Parity Flag
4969 UINT32 Reserved_1
:1; // Reserved
4970 UINT32 AF
:1; // Auxiliary Carry Flag
4971 UINT32 Reserved_2
:1; // Reserved
4972 UINT32 ZF
:1; // Zero Flag
4973 UINT32 SF
:1; // Sign Flag
4974 UINT32 TF
:1; // Trap Flag
4975 UINT32 IF
:1; // Interrupt Enable Flag
4976 UINT32 DF
:1; // Direction Flag
4977 UINT32 OF
:1; // Overflow Flag
4978 UINT32 IOPL
:2; // I/O Privilege Level
4979 UINT32 NT
:1; // Nested Task
4980 UINT32 Reserved_3
:1; // Reserved
4986 // Byte packed structure for EFLAGS/RFLAGS
4988 // 64-bits on X64. The upper 32-bits on X64 are reserved
4992 UINT32 CF
:1; // Carry Flag
4993 UINT32 Reserved_0
:1; // Reserved
4994 UINT32 PF
:1; // Parity Flag
4995 UINT32 Reserved_1
:1; // Reserved
4996 UINT32 AF
:1; // Auxiliary Carry Flag
4997 UINT32 Reserved_2
:1; // Reserved
4998 UINT32 ZF
:1; // Zero Flag
4999 UINT32 SF
:1; // Sign Flag
5000 UINT32 TF
:1; // Trap Flag
5001 UINT32 IF
:1; // Interrupt Enable Flag
5002 UINT32 DF
:1; // Direction Flag
5003 UINT32 OF
:1; // Overflow Flag
5004 UINT32 IOPL
:2; // I/O Privilege Level
5005 UINT32 NT
:1; // Nested Task
5006 UINT32 Reserved_3
:1; // Reserved
5007 UINT32 RF
:1; // Resume Flag
5008 UINT32 VM
:1; // Virtual 8086 Mode
5009 UINT32 AC
:1; // Alignment Check
5010 UINT32 VIF
:1; // Virtual Interrupt Flag
5011 UINT32 VIP
:1; // Virtual Interrupt Pending
5012 UINT32 ID
:1; // ID Flag
5013 UINT32 Reserved_4
:10; // Reserved
5019 // Byte packed structure for Control Register 0 (CR0)
5021 // 64-bits on X64. The upper 32-bits on X64 are reserved
5025 UINT32 PE
:1; // Protection Enable
5026 UINT32 MP
:1; // Monitor Coprocessor
5027 UINT32 EM
:1; // Emulation
5028 UINT32 TS
:1; // Task Switched
5029 UINT32 ET
:1; // Extension Type
5030 UINT32 NE
:1; // Numeric Error
5031 UINT32 Reserved_0
:10; // Reserved
5032 UINT32 WP
:1; // Write Protect
5033 UINT32 Reserved_1
:1; // Reserved
5034 UINT32 AM
:1; // Alignment Mask
5035 UINT32 Reserved_2
:10; // Reserved
5036 UINT32 NW
:1; // Mot Write-through
5037 UINT32 CD
:1; // Cache Disable
5038 UINT32 PG
:1; // Paging
5044 // Byte packed structure for Control Register 4 (CR4)
5046 // 64-bits on X64. The upper 32-bits on X64 are reserved
5050 UINT32 VME
:1; // Virtual-8086 Mode Extensions
5051 UINT32 PVI
:1; // Protected-Mode Virtual Interrupts
5052 UINT32 TSD
:1; // Time Stamp Disable
5053 UINT32 DE
:1; // Debugging Extensions
5054 UINT32 PSE
:1; // Page Size Extensions
5055 UINT32 PAE
:1; // Physical Address Extension
5056 UINT32 MCE
:1; // Machine Check Enable
5057 UINT32 PGE
:1; // Page Global Enable
5058 UINT32 PCE
:1; // Performance Monitoring Counter
5060 UINT32 OSFXSR
:1; // Operating System Support for
5061 // FXSAVE and FXRSTOR instructions
5062 UINT32 OSXMMEXCPT
:1; // Operating System Support for
5063 // Unmasked SIMD Floating Point
5065 UINT32 Reserved_0
:2; // Reserved
5066 UINT32 VMXE
:1; // VMX Enable
5067 UINT32 Reserved_1
:18; // Reseved
5073 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
5074 /// @bug How to make this structure byte-packed in a compiler independent way?
5083 #define IA32_IDT_GATE_TYPE_TASK 0x85
5084 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
5085 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
5086 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
5087 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
5090 // Byte packed structure for an Interrupt Gate Descriptor
5094 UINT32 OffsetLow
:16; // Offset bits 15..0
5095 UINT32 Selector
:16; // Selector
5096 UINT32 Reserved_0
:8; // Reserved
5097 UINT32 GateType
:8; // Gate Type. See #defines above
5098 UINT32 OffsetHigh
:16; // Offset bits 31..16
5101 } IA32_IDT_GATE_DESCRIPTOR
;
5104 // Byte packed structure for an FP/SSE/SSE2 context
5111 // Structures for the 16-bit real mode thunks
5164 IA32_EFLAGS32 EFLAGS
;
5174 } IA32_REGISTER_SET
;
5177 // Byte packed structure for an 16-bit real mode thunks
5180 IA32_REGISTER_SET
*RealModeState
;
5181 VOID
*RealModeBuffer
;
5182 UINT32 RealModeBufferSize
;
5183 UINT32 ThunkAttributes
;
5186 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
5187 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
5188 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
5191 Retrieves CPUID information.
5193 Executes the CPUID instruction with EAX set to the value specified by Index.
5194 This function always returns Index.
5195 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5196 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5197 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5198 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5199 This function is only available on IA-32 and X64.
5201 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
5203 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5204 instruction. This is an optional parameter that may be NULL.
5205 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5206 instruction. This is an optional parameter that may be NULL.
5207 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5208 instruction. This is an optional parameter that may be NULL.
5209 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5210 instruction. This is an optional parameter that may be NULL.
5219 OUT UINT32
*Eax
, OPTIONAL
5220 OUT UINT32
*Ebx
, OPTIONAL
5221 OUT UINT32
*Ecx
, OPTIONAL
5222 OUT UINT32
*Edx OPTIONAL
5227 Retrieves CPUID information using an extended leaf identifier.
5229 Executes the CPUID instruction with EAX set to the value specified by Index
5230 and ECX set to the value specified by SubIndex. This function always returns
5231 Index. This function is only available on IA-32 and x64.
5233 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5234 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5235 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5236 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5238 @param Index The 32-bit value to load into EAX prior to invoking the
5240 @param SubIndex The 32-bit value to load into ECX prior to invoking the
5242 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
5243 instruction. This is an optional parameter that may be
5245 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
5246 instruction. This is an optional parameter that may be
5248 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
5249 instruction. This is an optional parameter that may be
5251 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
5252 instruction. This is an optional parameter that may be
5263 OUT UINT32
*Eax
, OPTIONAL
5264 OUT UINT32
*Ebx
, OPTIONAL
5265 OUT UINT32
*Ecx
, OPTIONAL
5266 OUT UINT32
*Edx OPTIONAL
5271 Returns the lower 32-bits of a Machine Specific Register(MSR).
5273 Reads and returns the lower 32-bits of the MSR specified by Index.
5274 No parameter checking is performed on Index, and some Index values may cause
5275 CPU exceptions. The caller must either guarantee that Index is valid, or the
5276 caller must set up exception handlers to catch the exceptions. This function
5277 is only available on IA-32 and X64.
5279 @param Index The 32-bit MSR index to read.
5281 @return The lower 32 bits of the MSR identified by Index.
5292 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
5294 Writes the 32-bit value specified by Value to the MSR specified by Index. The
5295 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
5296 the MSR is returned. No parameter checking is performed on Index or Value,
5297 and some of these may cause CPU exceptions. The caller must either guarantee
5298 that Index and Value are valid, or the caller must establish proper exception
5299 handlers. This function is only available on IA-32 and X64.
5301 @param Index The 32-bit MSR index to write.
5302 @param Value The 32-bit value to write to the MSR.
5316 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
5317 writes the result back to the 64-bit MSR.
5319 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5320 between the lower 32-bits of the read result and the value specified by
5321 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
5322 32-bits of the value written to the MSR is returned. No parameter checking is
5323 performed on Index or OrData, and some of these may cause CPU exceptions. The
5324 caller must either guarantee that Index and OrData are valid, or the caller
5325 must establish proper exception handlers. This function is only available on
5328 @param Index The 32-bit MSR index to write.
5329 @param OrData The value to OR with the read value from the MSR.
5331 @return The lower 32-bit value written to the MSR.
5343 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
5344 the result back to the 64-bit MSR.
5346 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5347 lower 32-bits of the read result and the value specified by AndData, and
5348 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
5349 the value written to the MSR is returned. No parameter checking is performed
5350 on Index or AndData, and some of these may cause CPU exceptions. The caller
5351 must either guarantee that Index and AndData are valid, or the caller must
5352 establish proper exception handlers. This function is only available on IA-32
5355 @param Index The 32-bit MSR index to write.
5356 @param AndData The value to AND with the read value from the MSR.
5358 @return The lower 32-bit value written to the MSR.
5370 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
5371 on the lower 32-bits, and writes the result back to the 64-bit MSR.
5373 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5374 lower 32-bits of the read result and the value specified by AndData
5375 preserving the upper 32-bits, performs a bitwise inclusive OR between the
5376 result of the AND operation and the value specified by OrData, and writes the
5377 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
5378 written to the MSR is returned. No parameter checking is performed on Index,
5379 AndData, or OrData, and some of these may cause CPU exceptions. The caller
5380 must either guarantee that Index, AndData, and OrData are valid, or the
5381 caller must establish proper exception handlers. This function is only
5382 available on IA-32 and X64.
5384 @param Index The 32-bit MSR index to write.
5385 @param AndData The value to AND with the read value from the MSR.
5386 @param OrData The value to OR with the result of the AND operation.
5388 @return The lower 32-bit value written to the MSR.
5401 Reads a bit field of an MSR.
5403 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
5404 specified by the StartBit and the EndBit. The value of the bit field is
5405 returned. The caller must either guarantee that Index is valid, or the caller
5406 must set up exception handlers to catch the exceptions. This function is only
5407 available on IA-32 and X64.
5409 If StartBit is greater than 31, then ASSERT().
5410 If EndBit is greater than 31, then ASSERT().
5411 If EndBit is less than StartBit, then ASSERT().
5413 @param Index The 32-bit MSR index to read.
5414 @param StartBit The ordinal of the least significant bit in the bit field.
5416 @param EndBit The ordinal of the most significant bit in the bit field.
5419 @return The bit field read from the MSR.
5424 AsmMsrBitFieldRead32 (
5432 Writes a bit field to an MSR.
5434 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
5435 field is specified by the StartBit and the EndBit. All other bits in the
5436 destination MSR are preserved. The lower 32-bits of the MSR written is
5437 returned. Extra left bits in Value are stripped. The caller must either
5438 guarantee that Index and the data written is valid, or the caller must set up
5439 exception handlers to catch the exceptions. This function is only available
5442 If StartBit is greater than 31, then ASSERT().
5443 If EndBit is greater than 31, then ASSERT().
5444 If EndBit is less than StartBit, then ASSERT().
5446 @param Index The 32-bit MSR index to write.
5447 @param StartBit The ordinal of the least significant bit in the bit field.
5449 @param EndBit The ordinal of the most significant bit in the bit field.
5451 @param Value New value of the bit field.
5453 @return The lower 32-bit of the value written to the MSR.
5458 AsmMsrBitFieldWrite32 (
5467 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
5468 result back to the bit field in the 64-bit MSR.
5470 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5471 between the read result and the value specified by OrData, and writes the
5472 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
5473 written to the MSR are returned. Extra left bits in OrData are stripped. The
5474 caller must either guarantee that Index and the data written is valid, or
5475 the caller must set up exception handlers to catch the exceptions. This
5476 function is only available on IA-32 and X64.
5478 If StartBit is greater than 31, then ASSERT().
5479 If EndBit is greater than 31, then ASSERT().
5480 If EndBit is less than StartBit, then ASSERT().
5482 @param Index The 32-bit MSR index to write.
5483 @param StartBit The ordinal of the least significant bit in the bit field.
5485 @param EndBit The ordinal of the most significant bit in the bit field.
5487 @param OrData The value to OR with the read value from the MSR.
5489 @return The lower 32-bit of the value written to the MSR.
5494 AsmMsrBitFieldOr32 (
5503 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5504 result back to the bit field in the 64-bit MSR.
5506 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5507 read result and the value specified by AndData, and writes the result to the
5508 64-bit MSR specified by Index. The lower 32-bits of the value written to the
5509 MSR are returned. Extra left bits in AndData are stripped. The caller must
5510 either guarantee that Index and the data written is valid, or the caller must
5511 set up exception handlers to catch the exceptions. This function is only
5512 available on IA-32 and X64.
5514 If StartBit is greater than 31, then ASSERT().
5515 If EndBit is greater than 31, then ASSERT().
5516 If EndBit is less than StartBit, then ASSERT().
5518 @param Index The 32-bit MSR index to write.
5519 @param StartBit The ordinal of the least significant bit in the bit field.
5521 @param EndBit The ordinal of the most significant bit in the bit field.
5523 @param AndData The value to AND with the read value from the MSR.
5525 @return The lower 32-bit of the value written to the MSR.
5530 AsmMsrBitFieldAnd32 (
5539 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5540 bitwise inclusive OR, and writes the result back to the bit field in the
5543 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
5544 bitwise inclusive OR between the read result and the value specified by
5545 AndData, and writes the result to the 64-bit MSR specified by Index. The
5546 lower 32-bits of the value written to the MSR are returned. Extra left bits
5547 in both AndData and OrData are stripped. The caller must either guarantee
5548 that Index and the data written is valid, or the caller must set up exception
5549 handlers to catch the exceptions. This function is only available on IA-32
5552 If StartBit is greater than 31, then ASSERT().
5553 If EndBit is greater than 31, then ASSERT().
5554 If EndBit is less than StartBit, then ASSERT().
5556 @param Index The 32-bit MSR index to write.
5557 @param StartBit The ordinal of the least significant bit in the bit field.
5559 @param EndBit The ordinal of the most significant bit in the bit field.
5561 @param AndData The value to AND with the read value from the MSR.
5562 @param OrData The value to OR with the result of the AND operation.
5564 @return The lower 32-bit of the value written to the MSR.
5569 AsmMsrBitFieldAndThenOr32 (
5579 Returns a 64-bit Machine Specific Register(MSR).
5581 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
5582 performed on Index, and some Index values may cause CPU exceptions. The
5583 caller must either guarantee that Index is valid, or the caller must set up
5584 exception handlers to catch the exceptions. This function is only available
5587 @param Index The 32-bit MSR index to read.
5589 @return The value of the MSR identified by Index.
5600 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
5603 Writes the 64-bit value specified by Value to the MSR specified by Index. The
5604 64-bit value written to the MSR is returned. No parameter checking is
5605 performed on Index or Value, and some of these may cause CPU exceptions. The
5606 caller must either guarantee that Index and Value are valid, or the caller
5607 must establish proper exception handlers. This function is only available on
5610 @param Index The 32-bit MSR index to write.
5611 @param Value The 64-bit value to write to the MSR.
5625 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
5626 back to the 64-bit MSR.
5628 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5629 between the read result and the value specified by OrData, and writes the
5630 result to the 64-bit MSR specified by Index. The value written to the MSR is
5631 returned. No parameter checking is performed on Index or OrData, and some of
5632 these may cause CPU exceptions. The caller must either guarantee that Index
5633 and OrData are valid, or the caller must establish proper exception handlers.
5634 This function is only available on IA-32 and X64.
5636 @param Index The 32-bit MSR index to write.
5637 @param OrData The value to OR with the read value from the MSR.
5639 @return The value written back to the MSR.
5651 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
5654 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5655 read result and the value specified by OrData, and writes the result to the
5656 64-bit MSR specified by Index. The value written to the MSR is returned. No
5657 parameter checking is performed on Index or OrData, and some of these may
5658 cause CPU exceptions. The caller must either guarantee that Index and OrData
5659 are valid, or the caller must establish proper exception handlers. This
5660 function is only available on IA-32 and X64.
5662 @param Index The 32-bit MSR index to write.
5663 @param AndData The value to AND with the read value from the MSR.
5665 @return The value written back to the MSR.
5677 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
5678 OR, and writes the result back to the 64-bit MSR.
5680 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
5681 result and the value specified by AndData, performs a bitwise inclusive OR
5682 between the result of the AND operation and the value specified by OrData,
5683 and writes the result to the 64-bit MSR specified by Index. The value written
5684 to the MSR is returned. No parameter checking is performed on Index, AndData,
5685 or OrData, and some of these may cause CPU exceptions. The caller must either
5686 guarantee that Index, AndData, and OrData are valid, or the caller must
5687 establish proper exception handlers. This function is only available on IA-32
5690 @param Index The 32-bit MSR index to write.
5691 @param AndData The value to AND with the read value from the MSR.
5692 @param OrData The value to OR with the result of the AND operation.
5694 @return The value written back to the MSR.
5707 Reads a bit field of an MSR.
5709 Reads the bit field in the 64-bit MSR. The bit field is specified by the
5710 StartBit and the EndBit. The value of the bit field is returned. The caller
5711 must either guarantee that Index is valid, or the caller must set up
5712 exception handlers to catch the exceptions. This function is only available
5715 If StartBit is greater than 63, then ASSERT().
5716 If EndBit is greater than 63, then ASSERT().
5717 If EndBit is less than StartBit, then ASSERT().
5719 @param Index The 32-bit MSR index to read.
5720 @param StartBit The ordinal of the least significant bit in the bit field.
5722 @param EndBit The ordinal of the most significant bit in the bit field.
5725 @return The value read from the MSR.
5730 AsmMsrBitFieldRead64 (
5738 Writes a bit field to an MSR.
5740 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
5741 the StartBit and the EndBit. All other bits in the destination MSR are
5742 preserved. The MSR written is returned. Extra left bits in Value are
5743 stripped. The caller must either guarantee that Index and the data written is
5744 valid, or the caller must set up exception handlers to catch the exceptions.
5745 This function is only available on IA-32 and X64.
5747 If StartBit is greater than 63, then ASSERT().
5748 If EndBit is greater than 63, then ASSERT().
5749 If EndBit is less than StartBit, then ASSERT().
5751 @param Index The 32-bit MSR index to write.
5752 @param StartBit The ordinal of the least significant bit in the bit field.
5754 @param EndBit The ordinal of the most significant bit in the bit field.
5756 @param Value New value of the bit field.
5758 @return The value written back to the MSR.
5763 AsmMsrBitFieldWrite64 (
5772 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
5773 writes the result back to the bit field in the 64-bit MSR.
5775 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
5776 between the read result and the value specified by OrData, and writes the
5777 result to the 64-bit MSR specified by Index. The value written to the MSR is
5778 returned. Extra left bits in OrData are stripped. The caller must either
5779 guarantee that Index and the data written is valid, or the caller must set up
5780 exception handlers to catch the exceptions. This function is only available
5783 If StartBit is greater than 63, then ASSERT().
5784 If EndBit is greater than 63, then ASSERT().
5785 If EndBit is less than StartBit, then ASSERT().
5787 @param Index The 32-bit MSR index to write.
5788 @param StartBit The ordinal of the least significant bit in the bit field.
5790 @param EndBit The ordinal of the most significant bit in the bit field.
5792 @param OrData The value to OR with the read value from the bit field.
5794 @return The value written back to the MSR.
5799 AsmMsrBitFieldOr64 (
5808 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5809 result back to the bit field in the 64-bit MSR.
5811 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5812 read result and the value specified by AndData, and writes the result to the
5813 64-bit MSR specified by Index. The value written to the MSR is returned.
5814 Extra left bits in AndData are stripped. The caller must either guarantee
5815 that Index and the data written is valid, or the caller must set up exception
5816 handlers to catch the exceptions. This function is only available on IA-32
5819 If StartBit is greater than 63, then ASSERT().
5820 If EndBit is greater than 63, then ASSERT().
5821 If EndBit is less than StartBit, then ASSERT().
5823 @param Index The 32-bit MSR index to write.
5824 @param StartBit The ordinal of the least significant bit in the bit field.
5826 @param EndBit The ordinal of the most significant bit in the bit field.
5828 @param AndData The value to AND with the read value from the bit field.
5830 @return The value written back to the MSR.
5835 AsmMsrBitFieldAnd64 (
5844 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5845 bitwise inclusive OR, and writes the result back to the bit field in the
5848 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
5849 a bitwise inclusive OR between the read result and the value specified by
5850 AndData, and writes the result to the 64-bit MSR specified by Index. The
5851 value written to the MSR is returned. Extra left bits in both AndData and
5852 OrData are stripped. The caller must either guarantee that Index and the data
5853 written is valid, or the caller must set up exception handlers to catch the
5854 exceptions. This function is only available on IA-32 and X64.
5856 If StartBit is greater than 63, then ASSERT().
5857 If EndBit is greater than 63, then ASSERT().
5858 If EndBit is less than StartBit, then ASSERT().
5860 @param Index The 32-bit MSR index to write.
5861 @param StartBit The ordinal of the least significant bit in the bit field.
5863 @param EndBit The ordinal of the most significant bit in the bit field.
5865 @param AndData The value to AND with the read value from the bit field.
5866 @param OrData The value to OR with the result of the AND operation.
5868 @return The value written back to the MSR.
5873 AsmMsrBitFieldAndThenOr64 (
5883 Reads the current value of the EFLAGS register.
5885 Reads and returns the current value of the EFLAGS register. This function is
5886 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
5887 64-bit value on X64.
5889 @return EFLAGS on IA-32 or RFLAGS on X64.
5900 Reads the current value of the Control Register 0 (CR0).
5902 Reads and returns the current value of CR0. This function is only available
5903 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5906 @return The value of the Control Register 0 (CR0).
5917 Reads the current value of the Control Register 2 (CR2).
5919 Reads and returns the current value of CR2. This function is only available
5920 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5923 @return The value of the Control Register 2 (CR2).
5934 Reads the current value of the Control Register 3 (CR3).
5936 Reads and returns the current value of CR3. This function is only available
5937 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5940 @return The value of the Control Register 3 (CR3).
5951 Reads the current value of the Control Register 4 (CR4).
5953 Reads and returns the current value of CR4. This function is only available
5954 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
5957 @return The value of the Control Register 4 (CR4).
5968 Writes a value to Control Register 0 (CR0).
5970 Writes and returns a new value to CR0. This function is only available on
5971 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5973 @param Cr0 The value to write to CR0.
5975 @return The value written to CR0.
5986 Writes a value to Control Register 2 (CR2).
5988 Writes and returns a new value to CR2. This function is only available on
5989 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
5991 @param Cr2 The value to write to CR2.
5993 @return The value written to CR2.
6004 Writes a value to Control Register 3 (CR3).
6006 Writes and returns a new value to CR3. This function is only available on
6007 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6009 @param Cr3 The value to write to CR3.
6011 @return The value written to CR3.
6022 Writes a value to Control Register 4 (CR4).
6024 Writes and returns a new value to CR4. This function is only available on
6025 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6027 @param Cr4 The value to write to CR4.
6029 @return The value written to CR4.
6040 Reads the current value of Debug Register 0 (DR0).
6042 Reads and returns the current value of DR0. This function is only available
6043 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6046 @return The value of Debug Register 0 (DR0).
6057 Reads the current value of Debug Register 1 (DR1).
6059 Reads and returns the current value of DR1. This function is only available
6060 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6063 @return The value of Debug Register 1 (DR1).
6074 Reads the current value of Debug Register 2 (DR2).
6076 Reads and returns the current value of DR2. This function is only available
6077 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6080 @return The value of Debug Register 2 (DR2).
6091 Reads the current value of Debug Register 3 (DR3).
6093 Reads and returns the current value of DR3. This function is only available
6094 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6097 @return The value of Debug Register 3 (DR3).
6108 Reads the current value of Debug Register 4 (DR4).
6110 Reads and returns the current value of DR4. This function is only available
6111 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6114 @return The value of Debug Register 4 (DR4).
6125 Reads the current value of Debug Register 5 (DR5).
6127 Reads and returns the current value of DR5. This function is only available
6128 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6131 @return The value of Debug Register 5 (DR5).
6142 Reads the current value of Debug Register 6 (DR6).
6144 Reads and returns the current value of DR6. This function is only available
6145 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6148 @return The value of Debug Register 6 (DR6).
6159 Reads the current value of Debug Register 7 (DR7).
6161 Reads and returns the current value of DR7. This function is only available
6162 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
6165 @return The value of Debug Register 7 (DR7).
6176 Writes a value to Debug Register 0 (DR0).
6178 Writes and returns a new value to DR0. This function is only available on
6179 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6181 @param Dr0 The value to write to Dr0.
6183 @return The value written to Debug Register 0 (DR0).
6194 Writes a value to Debug Register 1 (DR1).
6196 Writes and returns a new value to DR1. This function is only available on
6197 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6199 @param Dr1 The value to write to Dr1.
6201 @return The value written to Debug Register 1 (DR1).
6212 Writes a value to Debug Register 2 (DR2).
6214 Writes and returns a new value to DR2. This function is only available on
6215 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6217 @param Dr2 The value to write to Dr2.
6219 @return The value written to Debug Register 2 (DR2).
6230 Writes a value to Debug Register 3 (DR3).
6232 Writes and returns a new value to DR3. This function is only available on
6233 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6235 @param Dr3 The value to write to Dr3.
6237 @return The value written to Debug Register 3 (DR3).
6248 Writes a value to Debug Register 4 (DR4).
6250 Writes and returns a new value to DR4. This function is only available on
6251 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6253 @param Dr4 The value to write to Dr4.
6255 @return The value written to Debug Register 4 (DR4).
6266 Writes a value to Debug Register 5 (DR5).
6268 Writes and returns a new value to DR5. This function is only available on
6269 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6271 @param Dr5 The value to write to Dr5.
6273 @return The value written to Debug Register 5 (DR5).
6284 Writes a value to Debug Register 6 (DR6).
6286 Writes and returns a new value to DR6. This function is only available on
6287 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6289 @param Dr6 The value to write to Dr6.
6291 @return The value written to Debug Register 6 (DR6).
6302 Writes a value to Debug Register 7 (DR7).
6304 Writes and returns a new value to DR7. This function is only available on
6305 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
6307 @param Dr7 The value to write to Dr7.
6309 @return The value written to Debug Register 7 (DR7).
6320 Reads the current value of Code Segment Register (CS).
6322 Reads and returns the current value of CS. This function is only available on
6325 @return The current value of CS.
6336 Reads the current value of Data Segment Register (DS).
6338 Reads and returns the current value of DS. This function is only available on
6341 @return The current value of DS.
6352 Reads the current value of Extra Segment Register (ES).
6354 Reads and returns the current value of ES. This function is only available on
6357 @return The current value of ES.
6368 Reads the current value of FS Data Segment Register (FS).
6370 Reads and returns the current value of FS. This function is only available on
6373 @return The current value of FS.
6384 Reads the current value of GS Data Segment Register (GS).
6386 Reads and returns the current value of GS. This function is only available on
6389 @return The current value of GS.
6400 Reads the current value of Stack Segment Register (SS).
6402 Reads and returns the current value of SS. This function is only available on
6405 @return The current value of SS.
6416 Reads the current value of Task Register (TR).
6418 Reads and returns the current value of TR. This function is only available on
6421 @return The current value of TR.
6432 Reads the current Global Descriptor Table Register(GDTR) descriptor.
6434 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
6435 function is only available on IA-32 and X64.
6437 If Gdtr is NULL, then ASSERT().
6439 @param Gdtr Pointer to a GDTR descriptor.
6445 OUT IA32_DESCRIPTOR
*Gdtr
6450 Writes the current Global Descriptor Table Register (GDTR) descriptor.
6452 Writes and the current GDTR descriptor specified by Gdtr. This function is
6453 only available on IA-32 and X64.
6455 If Gdtr is NULL, then ASSERT().
6457 @param Gdtr Pointer to a GDTR descriptor.
6463 IN CONST IA32_DESCRIPTOR
*Gdtr
6468 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
6470 Reads and returns the current IDTR descriptor and returns it in Idtr. This
6471 function is only available on IA-32 and X64.
6473 If Idtr is NULL, then ASSERT().
6475 @param Idtr Pointer to a IDTR descriptor.
6481 OUT IA32_DESCRIPTOR
*Idtr
6486 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
6488 Writes the current IDTR descriptor and returns it in Idtr. This function is
6489 only available on IA-32 and X64.
6491 If Idtr is NULL, then ASSERT().
6493 @param Idtr Pointer to a IDTR descriptor.
6499 IN CONST IA32_DESCRIPTOR
*Idtr
6504 Reads the current Local Descriptor Table Register(LDTR) selector.
6506 Reads and returns the current 16-bit LDTR descriptor value. This function is
6507 only available on IA-32 and X64.
6509 @return The current selector of LDT.
6520 Writes the current Local Descriptor Table Register (GDTR) selector.
6522 Writes and the current LDTR descriptor specified by Ldtr. This function is
6523 only available on IA-32 and X64.
6525 @param Ldtr 16-bit LDTR selector value.
6536 Save the current floating point/SSE/SSE2 context to a buffer.
6538 Saves the current floating point/SSE/SSE2 state to the buffer specified by
6539 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
6540 available on IA-32 and X64.
6542 If Buffer is NULL, then ASSERT().
6543 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6545 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6551 OUT IA32_FX_BUFFER
*Buffer
6556 Restores the current floating point/SSE/SSE2 context from a buffer.
6558 Restores the current floating point/SSE/SSE2 state from the buffer specified
6559 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
6560 only available on IA-32 and X64.
6562 If Buffer is NULL, then ASSERT().
6563 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6564 If Buffer was not saved with AsmFxSave(), then ASSERT().
6566 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
6572 IN CONST IA32_FX_BUFFER
*Buffer
6577 Reads the current value of 64-bit MMX Register #0 (MM0).
6579 Reads and returns the current value of MM0. This function is only available
6582 @return The current value of MM0.
6593 Reads the current value of 64-bit MMX Register #1 (MM1).
6595 Reads and returns the current value of MM1. This function is only available
6598 @return The current value of MM1.
6609 Reads the current value of 64-bit MMX Register #2 (MM2).
6611 Reads and returns the current value of MM2. This function is only available
6614 @return The current value of MM2.
6625 Reads the current value of 64-bit MMX Register #3 (MM3).
6627 Reads and returns the current value of MM3. This function is only available
6630 @return The current value of MM3.
6641 Reads the current value of 64-bit MMX Register #4 (MM4).
6643 Reads and returns the current value of MM4. This function is only available
6646 @return The current value of MM4.
6657 Reads the current value of 64-bit MMX Register #5 (MM5).
6659 Reads and returns the current value of MM5. This function is only available
6662 @return The current value of MM5.
6673 Reads the current value of 64-bit MMX Register #6 (MM6).
6675 Reads and returns the current value of MM6. This function is only available
6678 @return The current value of MM6.
6689 Reads the current value of 64-bit MMX Register #7 (MM7).
6691 Reads and returns the current value of MM7. This function is only available
6694 @return The current value of MM7.
6705 Writes the current value of 64-bit MMX Register #0 (MM0).
6707 Writes the current value of MM0. This function is only available on IA32 and
6710 @param Value The 64-bit value to write to MM0.
6721 Writes the current value of 64-bit MMX Register #1 (MM1).
6723 Writes the current value of MM1. This function is only available on IA32 and
6726 @param Value The 64-bit value to write to MM1.
6737 Writes the current value of 64-bit MMX Register #2 (MM2).
6739 Writes the current value of MM2. This function is only available on IA32 and
6742 @param Value The 64-bit value to write to MM2.
6753 Writes the current value of 64-bit MMX Register #3 (MM3).
6755 Writes the current value of MM3. This function is only available on IA32 and
6758 @param Value The 64-bit value to write to MM3.
6769 Writes the current value of 64-bit MMX Register #4 (MM4).
6771 Writes the current value of MM4. This function is only available on IA32 and
6774 @param Value The 64-bit value to write to MM4.
6785 Writes the current value of 64-bit MMX Register #5 (MM5).
6787 Writes the current value of MM5. This function is only available on IA32 and
6790 @param Value The 64-bit value to write to MM5.
6801 Writes the current value of 64-bit MMX Register #6 (MM6).
6803 Writes the current value of MM6. This function is only available on IA32 and
6806 @param Value The 64-bit value to write to MM6.
6817 Writes the current value of 64-bit MMX Register #7 (MM7).
6819 Writes the current value of MM7. This function is only available on IA32 and
6822 @param Value The 64-bit value to write to MM7.
6833 Reads the current value of Time Stamp Counter (TSC).
6835 Reads and returns the current value of TSC. This function is only available
6838 @return The current value of TSC
6849 Reads the current value of a Performance Counter (PMC).
6851 Reads and returns the current value of performance counter specified by
6852 Index. This function is only available on IA-32 and X64.
6854 @param Index The 32-bit Performance Counter index to read.
6856 @return The value of the PMC specified by Index.
6867 Sets up a monitor buffer that is used by AsmMwait().
6869 Executes a MONITOR instruction with the register state specified by Eax, Ecx
6870 and Edx. Returns Eax. This function is only available on IA-32 and X64.
6872 @param Eax The value to load into EAX or RAX before executing the MONITOR
6874 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6876 @param Edx The value to load into EDX or RDX before executing the MONITOR
6892 Executes an MWAIT instruction.
6894 Executes an MWAIT instruction with the register state specified by Eax and
6895 Ecx. Returns Eax. This function is only available on IA-32 and X64.
6897 @param Eax The value to load into EAX or RAX before executing the MONITOR
6899 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6914 Executes a WBINVD instruction.
6916 Executes a WBINVD instruction. This function is only available on IA-32 and
6928 Executes a INVD instruction.
6930 Executes a INVD instruction. This function is only available on IA-32 and
6942 Flushes a cache line from all the instruction and data caches within the
6943 coherency domain of the CPU.
6945 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
6946 This function is only available on IA-32 and X64.
6948 @param LinearAddress The address of the cache line to flush. If the CPU is
6949 in a physical addressing mode, then LinearAddress is a
6950 physical address. If the CPU is in a virtual
6951 addressing mode, then LinearAddress is a virtual
6954 @return LinearAddress
6959 IN VOID
*LinearAddress
6964 Enables the 32-bit paging mode on the CPU.
6966 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
6967 must be properly initialized prior to calling this service. This function
6968 assumes the current execution mode is 32-bit protected mode. This function is
6969 only available on IA-32. After the 32-bit paging mode is enabled, control is
6970 transferred to the function specified by EntryPoint using the new stack
6971 specified by NewStack and passing in the parameters specified by Context1 and
6972 Context2. Context1 and Context2 are optional and may be NULL. The function
6973 EntryPoint must never return.
6975 If the current execution mode is not 32-bit protected mode, then ASSERT().
6976 If EntryPoint is NULL, then ASSERT().
6977 If NewStack is NULL, then ASSERT().
6979 There are a number of constraints that must be followed before calling this
6981 1) Interrupts must be disabled.
6982 2) The caller must be in 32-bit protected mode with flat descriptors. This
6983 means all descriptors must have a base of 0 and a limit of 4GB.
6984 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
6986 4) CR3 must point to valid page tables that will be used once the transition
6987 is complete, and those page tables must guarantee that the pages for this
6988 function and the stack are identity mapped.
6990 @param EntryPoint A pointer to function to call with the new stack after
6992 @param Context1 A pointer to the context to pass into the EntryPoint
6993 function as the first parameter after paging is enabled.
6994 @param Context2 A pointer to the context to pass into the EntryPoint
6995 function as the second parameter after paging is enabled.
6996 @param NewStack A pointer to the new stack to use for the EntryPoint
6997 function after paging is enabled.
7003 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
7004 IN VOID
*Context1
, OPTIONAL
7005 IN VOID
*Context2
, OPTIONAL
7011 Disables the 32-bit paging mode on the CPU.
7013 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
7014 mode. This function assumes the current execution mode is 32-paged protected
7015 mode. This function is only available on IA-32. After the 32-bit paging mode
7016 is disabled, control is transferred to the function specified by EntryPoint
7017 using the new stack specified by NewStack and passing in the parameters
7018 specified by Context1 and Context2. Context1 and Context2 are optional and
7019 may be NULL. The function EntryPoint must never return.
7021 If the current execution mode is not 32-bit paged mode, then ASSERT().
7022 If EntryPoint is NULL, then ASSERT().
7023 If NewStack is NULL, then ASSERT().
7025 There are a number of constraints that must be followed before calling this
7027 1) Interrupts must be disabled.
7028 2) The caller must be in 32-bit paged mode.
7029 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
7030 4) CR3 must point to valid page tables that guarantee that the pages for
7031 this function and the stack are identity mapped.
7033 @param EntryPoint A pointer to function to call with the new stack after
7035 @param Context1 A pointer to the context to pass into the EntryPoint
7036 function as the first parameter after paging is disabled.
7037 @param Context2 A pointer to the context to pass into the EntryPoint
7038 function as the second parameter after paging is
7040 @param NewStack A pointer to the new stack to use for the EntryPoint
7041 function after paging is disabled.
7046 AsmDisablePaging32 (
7047 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
7048 IN VOID
*Context1
, OPTIONAL
7049 IN VOID
*Context2
, OPTIONAL
7055 Enables the 64-bit paging mode on the CPU.
7057 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7058 must be properly initialized prior to calling this service. This function
7059 assumes the current execution mode is 32-bit protected mode with flat
7060 descriptors. This function is only available on IA-32. After the 64-bit
7061 paging mode is enabled, control is transferred to the function specified by
7062 EntryPoint using the new stack specified by NewStack and passing in the
7063 parameters specified by Context1 and Context2. Context1 and Context2 are
7064 optional and may be 0. The function EntryPoint must never return.
7066 If the current execution mode is not 32-bit protected mode with flat
7067 descriptors, then ASSERT().
7068 If EntryPoint is 0, then ASSERT().
7069 If NewStack is 0, then ASSERT().
7071 @param Cs The 16-bit selector to load in the CS before EntryPoint
7072 is called. The descriptor in the GDT that this selector
7073 references must be setup for long mode.
7074 @param EntryPoint The 64-bit virtual address of the function to call with
7075 the new stack after paging is enabled.
7076 @param Context1 The 64-bit virtual address of the context to pass into
7077 the EntryPoint function as the first parameter after
7079 @param Context2 The 64-bit virtual address of the context to pass into
7080 the EntryPoint function as the second parameter after
7082 @param NewStack The 64-bit virtual address of the new stack to use for
7083 the EntryPoint function after paging is enabled.
7089 IN UINT16 CodeSelector
,
7090 IN UINT64 EntryPoint
,
7091 IN UINT64 Context1
, OPTIONAL
7092 IN UINT64 Context2
, OPTIONAL
7098 Disables the 64-bit paging mode on the CPU.
7100 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
7101 mode. This function assumes the current execution mode is 64-paging mode.
7102 This function is only available on X64. After the 64-bit paging mode is
7103 disabled, control is transferred to the function specified by EntryPoint
7104 using the new stack specified by NewStack and passing in the parameters
7105 specified by Context1 and Context2. Context1 and Context2 are optional and
7106 may be 0. The function EntryPoint must never return.
7108 If the current execution mode is not 64-bit paged mode, then ASSERT().
7109 If EntryPoint is 0, then ASSERT().
7110 If NewStack is 0, then ASSERT().
7112 @param Cs The 16-bit selector to load in the CS before EntryPoint
7113 is called. The descriptor in the GDT that this selector
7114 references must be setup for 32-bit protected mode.
7115 @param EntryPoint The 64-bit virtual address of the function to call with
7116 the new stack after paging is disabled.
7117 @param Context1 The 64-bit virtual address of the context to pass into
7118 the EntryPoint function as the first parameter after
7120 @param Context2 The 64-bit virtual address of the context to pass into
7121 the EntryPoint function as the second parameter after
7123 @param NewStack The 64-bit virtual address of the new stack to use for
7124 the EntryPoint function after paging is disabled.
7129 AsmDisablePaging64 (
7130 IN UINT16 CodeSelector
,
7131 IN UINT32 EntryPoint
,
7132 IN UINT32 Context1
, OPTIONAL
7133 IN UINT32 Context2
, OPTIONAL
7139 // 16-bit thunking services
7143 Retrieves the properties for 16-bit thunk functions.
7145 Computes the size of the buffer and stack below 1MB required to use the
7146 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
7147 buffer size is returned in RealModeBufferSize, and the stack size is returned
7148 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
7149 then the actual minimum stack size is ExtraStackSize plus the maximum number
7150 of bytes that need to be passed to the 16-bit real mode code.
7152 If RealModeBufferSize is NULL, then ASSERT().
7153 If ExtraStackSize is NULL, then ASSERT().
7155 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
7156 required to use the 16-bit thunk functions.
7157 @param ExtraStackSize A pointer to the extra size of stack below 1MB
7158 that the 16-bit thunk functions require for
7159 temporary storage in the transition to and from
7165 AsmGetThunk16Properties (
7166 OUT UINT32
*RealModeBufferSize
,
7167 OUT UINT32
*ExtraStackSize
7172 Prepares all structures a code required to use AsmThunk16().
7174 Prepares all structures and code required to use AsmThunk16().
7176 If ThunkContext is NULL, then ASSERT().
7178 @param ThunkContext A pointer to the context structure that describes the
7179 16-bit real mode code to call.
7185 OUT THUNK_CONTEXT
*ThunkContext
7190 Transfers control to a 16-bit real mode entry point and returns the results.
7192 Transfers control to a 16-bit real mode entry point and returns the results.
7193 AsmPrepareThunk16() must be called with ThunkContext before this function is
7196 If ThunkContext is NULL, then ASSERT().
7197 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
7199 @param ThunkContext A pointer to the context structure that describes the
7200 16-bit real mode code to call.
7206 IN OUT THUNK_CONTEXT
*ThunkContext
7211 Prepares all structures and code for a 16-bit real mode thunk, transfers
7212 control to a 16-bit real mode entry point, and returns the results.
7214 Prepares all structures and code for a 16-bit real mode thunk, transfers
7215 control to a 16-bit real mode entry point, and returns the results. If the
7216 caller only need to perform a single 16-bit real mode thunk, then this
7217 service should be used. If the caller intends to make more than one 16-bit
7218 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
7219 once and AsmThunk16() can be called for each 16-bit real mode thunk.
7221 If ThunkContext is NULL, then ASSERT().
7223 @param ThunkContext A pointer to the context structure that describes the
7224 16-bit real mode code to call.
7229 AsmPrepareAndThunk16 (
7230 IN OUT THUNK_CONTEXT
*ThunkContext