xref: /freebsd/sys/contrib/edk2/Include/Library/BaseLib.h (revision 13ea0450a9c8742119d36f3bf8f47accdce46e54)
1 /** @file
2   Provides string functions, linked list functions, math functions, synchronization
3   functions, file path functions, and CPU architecture-specific functions.
4 
5 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
6 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 #ifndef __BASE_LIB__
18 #define __BASE_LIB__
19 
20 //
21 // Definitions for architecture-specific types
22 //
23 #if   defined (MDE_CPU_IA32)
24 ///
25 /// The IA-32 architecture context buffer used by SetJump() and LongJump().
26 ///
27 typedef struct {
28   UINT32                            Ebx;
29   UINT32                            Esi;
30   UINT32                            Edi;
31   UINT32                            Ebp;
32   UINT32                            Esp;
33   UINT32                            Eip;
34 } BASE_LIBRARY_JUMP_BUFFER;
35 
36 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 4
37 
38 #endif // defined (MDE_CPU_IA32)
39 
40 #if defined (MDE_CPU_IPF)
41 
42 ///
43 /// The Itanium architecture context buffer used by SetJump() and LongJump().
44 ///
45 typedef struct {
46   UINT64                            F2[2];
47   UINT64                            F3[2];
48   UINT64                            F4[2];
49   UINT64                            F5[2];
50   UINT64                            F16[2];
51   UINT64                            F17[2];
52   UINT64                            F18[2];
53   UINT64                            F19[2];
54   UINT64                            F20[2];
55   UINT64                            F21[2];
56   UINT64                            F22[2];
57   UINT64                            F23[2];
58   UINT64                            F24[2];
59   UINT64                            F25[2];
60   UINT64                            F26[2];
61   UINT64                            F27[2];
62   UINT64                            F28[2];
63   UINT64                            F29[2];
64   UINT64                            F30[2];
65   UINT64                            F31[2];
66   UINT64                            R4;
67   UINT64                            R5;
68   UINT64                            R6;
69   UINT64                            R7;
70   UINT64                            SP;
71   UINT64                            BR0;
72   UINT64                            BR1;
73   UINT64                            BR2;
74   UINT64                            BR3;
75   UINT64                            BR4;
76   UINT64                            BR5;
77   UINT64                            InitialUNAT;
78   UINT64                            AfterSpillUNAT;
79   UINT64                            PFS;
80   UINT64                            BSP;
81   UINT64                            Predicates;
82   UINT64                            LoopCount;
83   UINT64                            FPSR;
84 } BASE_LIBRARY_JUMP_BUFFER;
85 
86 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10
87 
88 #endif // defined (MDE_CPU_IPF)
89 
90 #if defined (MDE_CPU_X64)
91 ///
92 /// The x64 architecture context buffer used by SetJump() and LongJump().
93 ///
94 typedef struct {
95   UINT64                            Rbx;
96   UINT64                            Rsp;
97   UINT64                            Rbp;
98   UINT64                            Rdi;
99   UINT64                            Rsi;
100   UINT64                            R12;
101   UINT64                            R13;
102   UINT64                            R14;
103   UINT64                            R15;
104   UINT64                            Rip;
105   UINT64                            MxCsr;
106   UINT8                             XmmBuffer[160]; ///< XMM6-XMM15.
107 } BASE_LIBRARY_JUMP_BUFFER;
108 
109 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
110 
111 #endif // defined (MDE_CPU_X64)
112 
113 #if defined (MDE_CPU_EBC)
114 ///
115 /// The EBC context buffer used by SetJump() and LongJump().
116 ///
117 typedef struct {
118   UINT64                            R0;
119   UINT64                            R1;
120   UINT64                            R2;
121   UINT64                            R3;
122   UINT64                            IP;
123 } BASE_LIBRARY_JUMP_BUFFER;
124 
125 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
126 
127 #endif // defined (MDE_CPU_EBC)
128 
129 #if defined (MDE_CPU_ARM)
130 
131 typedef struct {
132   UINT32    R3;  ///< A copy of R13.
133   UINT32    R4;
134   UINT32    R5;
135   UINT32    R6;
136   UINT32    R7;
137   UINT32    R8;
138   UINT32    R9;
139   UINT32    R10;
140   UINT32    R11;
141   UINT32    R12;
142   UINT32    R14;
143 } BASE_LIBRARY_JUMP_BUFFER;
144 
145 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 4
146 
147 #endif  // defined (MDE_CPU_ARM)
148 
149 #if defined (MDE_CPU_AARCH64)
150 typedef struct {
151   // GP regs
152   UINT64    X19;
153   UINT64    X20;
154   UINT64    X21;
155   UINT64    X22;
156   UINT64    X23;
157   UINT64    X24;
158   UINT64    X25;
159   UINT64    X26;
160   UINT64    X27;
161   UINT64    X28;
162   UINT64    FP;
163   UINT64    LR;
164   UINT64    IP0;
165 
166   // FP regs
167   UINT64    D8;
168   UINT64    D9;
169   UINT64    D10;
170   UINT64    D11;
171   UINT64    D12;
172   UINT64    D13;
173   UINT64    D14;
174   UINT64    D15;
175 } BASE_LIBRARY_JUMP_BUFFER;
176 
177 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
178 
179 #endif  // defined (MDE_CPU_AARCH64)
180 
181 
182 //
183 // String Services
184 //
185 
186 
187 /**
188   Returns the length of a Null-terminated Unicode string.
189 
190   This function is similar as strlen_s defined in C11.
191 
192   If String is not aligned on a 16-bit boundary, then ASSERT().
193 
194   @param  String   A pointer to a Null-terminated Unicode string.
195   @param  MaxSize  The maximum number of Destination Unicode
196                    char, including terminating null char.
197 
198   @retval 0        If String is NULL.
199   @retval MaxSize  If there is no null character in the first MaxSize characters of String.
200   @return The number of characters that percede the terminating null character.
201 
202 **/
203 UINTN
204 EFIAPI
205 StrnLenS (
206   IN CONST CHAR16              *String,
207   IN UINTN                     MaxSize
208   );
209 
210 /**
211   Returns the size of a Null-terminated Unicode string in bytes, including the
212   Null terminator.
213 
214   This function returns the size of the Null-terminated Unicode string
215   specified by String in bytes, including the Null terminator.
216 
217   If String is not aligned on a 16-bit boundary, then ASSERT().
218 
219   @param  String   A pointer to a Null-terminated Unicode string.
220   @param  MaxSize  The maximum number of Destination Unicode
221                    char, including the Null terminator.
222 
223   @retval 0  If String is NULL.
224   @retval (sizeof (CHAR16) * (MaxSize + 1))
225              If there is no Null terminator in the first MaxSize characters of
226              String.
227   @return The size of the Null-terminated Unicode string in bytes, including
228           the Null terminator.
229 
230 **/
231 UINTN
232 EFIAPI
233 StrnSizeS (
234   IN CONST CHAR16              *String,
235   IN UINTN                     MaxSize
236   );
237 
238 /**
239   Copies the string pointed to by Source (including the terminating null char)
240   to the array pointed to by Destination.
241 
242   This function is similar as strcpy_s defined in C11.
243 
244   If Destination is not aligned on a 16-bit boundary, then ASSERT().
245   If Source is not aligned on a 16-bit boundary, then ASSERT().
246   If an error would be returned, then the function will also ASSERT().
247 
248   If an error is returned, then the Destination is unmodified.
249 
250   @param  Destination              A pointer to a Null-terminated Unicode string.
251   @param  DestMax                  The maximum number of Destination Unicode
252                                    char, including terminating null char.
253   @param  Source                   A pointer to a Null-terminated Unicode string.
254 
255   @retval RETURN_SUCCESS           String is copied.
256   @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).
257   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
258                                    If Source is NULL.
259                                    If PcdMaximumUnicodeStringLength is not zero,
260                                     and DestMax is greater than
261                                     PcdMaximumUnicodeStringLength.
262                                    If DestMax is 0.
263   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
264 **/
265 RETURN_STATUS
266 EFIAPI
267 StrCpyS (
268   OUT CHAR16       *Destination,
269   IN  UINTN        DestMax,
270   IN  CONST CHAR16 *Source
271   );
272 
273 /**
274   Copies not more than Length successive char from the string pointed to by
275   Source to the array pointed to by Destination. If no null char is copied from
276   Source, then Destination[Length] is always set to null.
277 
278   This function is similar as strncpy_s defined in C11.
279 
280   If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
281   If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
282   If an error would be returned, then the function will also ASSERT().
283 
284   If an error is returned, then the Destination is unmodified.
285 
286   @param  Destination              A pointer to a Null-terminated Unicode string.
287   @param  DestMax                  The maximum number of Destination Unicode
288                                    char, including terminating null char.
289   @param  Source                   A pointer to a Null-terminated Unicode string.
290   @param  Length                   The maximum number of Unicode characters to copy.
291 
292   @retval RETURN_SUCCESS           String is copied.
293   @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than
294                                    MIN(StrLen(Source), Length).
295   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
296                                    If Source is NULL.
297                                    If PcdMaximumUnicodeStringLength is not zero,
298                                     and DestMax is greater than
299                                     PcdMaximumUnicodeStringLength.
300                                    If DestMax is 0.
301   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
302 **/
303 RETURN_STATUS
304 EFIAPI
305 StrnCpyS (
306   OUT CHAR16       *Destination,
307   IN  UINTN        DestMax,
308   IN  CONST CHAR16 *Source,
309   IN  UINTN        Length
310   );
311 
312 /**
313   Appends a copy of the string pointed to by Source (including the terminating
314   null char) to the end of the string pointed to by Destination.
315 
316   This function is similar as strcat_s defined in C11.
317 
318   If Destination is not aligned on a 16-bit boundary, then ASSERT().
319   If Source is not aligned on a 16-bit boundary, then ASSERT().
320   If an error would be returned, then the function will also ASSERT().
321 
322   If an error is returned, then the Destination is unmodified.
323 
324   @param  Destination              A pointer to a Null-terminated Unicode string.
325   @param  DestMax                  The maximum number of Destination Unicode
326                                    char, including terminating null char.
327   @param  Source                   A pointer to a Null-terminated Unicode string.
328 
329   @retval RETURN_SUCCESS           String is appended.
330   @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than
331                                    StrLen(Destination).
332   @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT
333                                    greater than StrLen(Source).
334   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
335                                    If Source is NULL.
336                                    If PcdMaximumUnicodeStringLength is not zero,
337                                     and DestMax is greater than
338                                     PcdMaximumUnicodeStringLength.
339                                    If DestMax is 0.
340   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
341 **/
342 RETURN_STATUS
343 EFIAPI
344 StrCatS (
345   IN OUT CHAR16       *Destination,
346   IN     UINTN        DestMax,
347   IN     CONST CHAR16 *Source
348   );
349 
350 /**
351   Appends not more than Length successive char from the string pointed to by
352   Source to the end of the string pointed to by Destination. If no null char is
353   copied from Source, then Destination[StrLen(Destination) + Length] is always
354   set to null.
355 
356   This function is similar as strncat_s defined in C11.
357 
358   If Destination is not aligned on a 16-bit boundary, then ASSERT().
359   If Source is not aligned on a 16-bit boundary, then ASSERT().
360   If an error would be returned, then the function will also ASSERT().
361 
362   If an error is returned, then the Destination is unmodified.
363 
364   @param  Destination              A pointer to a Null-terminated Unicode string.
365   @param  DestMax                  The maximum number of Destination Unicode
366                                    char, including terminating null char.
367   @param  Source                   A pointer to a Null-terminated Unicode string.
368   @param  Length                   The maximum number of Unicode characters to copy.
369 
370   @retval RETURN_SUCCESS           String is appended.
371   @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than
372                                    StrLen(Destination).
373   @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT
374                                    greater than MIN(StrLen(Source), Length).
375   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
376                                    If Source is NULL.
377                                    If PcdMaximumUnicodeStringLength is not zero,
378                                     and DestMax is greater than
379                                     PcdMaximumUnicodeStringLength.
380                                    If DestMax is 0.
381   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
382 **/
383 RETURN_STATUS
384 EFIAPI
385 StrnCatS (
386   IN OUT CHAR16       *Destination,
387   IN     UINTN        DestMax,
388   IN     CONST CHAR16 *Source,
389   IN     UINTN        Length
390   );
391 
392 /**
393   Convert a Null-terminated Unicode decimal string to a value of type UINTN.
394 
395   This function outputs a value of type UINTN by interpreting the contents of
396   the Unicode string specified by String as a decimal number. The format of the
397   input Unicode string String is:
398 
399                   [spaces] [decimal digits].
400 
401   The valid decimal digit character is in the range [0-9]. The function will
402   ignore the pad space, which includes spaces or tab characters, before
403   [decimal digits]. The running zero in the beginning of [decimal digits] will
404   be ignored. Then, the function stops at the first character that is a not a
405   valid decimal character or a Null-terminator, whichever one comes first.
406 
407   If String is NULL, then ASSERT().
408   If Data is NULL, then ASSERT().
409   If String is not aligned in a 16-bit boundary, then ASSERT().
410   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
411   PcdMaximumUnicodeStringLength Unicode characters, not including the
412   Null-terminator, then ASSERT().
413 
414   If String has no valid decimal digits in the above format, then 0 is stored
415   at the location pointed to by Data.
416   If the number represented by String exceeds the range defined by UINTN, then
417   MAX_UINTN is stored at the location pointed to by Data.
418 
419   If EndPointer is not NULL, a pointer to the character that stopped the scan
420   is stored at the location pointed to by EndPointer. If String has no valid
421   decimal digits right after the optional pad spaces, the value of String is
422   stored at the location pointed to by EndPointer.
423 
424   @param  String                   Pointer to a Null-terminated Unicode string.
425   @param  EndPointer               Pointer to character that stops scan.
426   @param  Data                     Pointer to the converted value.
427 
428   @retval RETURN_SUCCESS           Value is translated from String.
429   @retval RETURN_INVALID_PARAMETER If String is NULL.
430                                    If Data is NULL.
431                                    If PcdMaximumUnicodeStringLength is not
432                                    zero, and String contains more than
433                                    PcdMaximumUnicodeStringLength Unicode
434                                    characters, not including the
435                                    Null-terminator.
436   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
437                                    the range defined by UINTN.
438 
439 **/
440 RETURN_STATUS
441 EFIAPI
442 StrDecimalToUintnS (
443   IN  CONST CHAR16             *String,
444   OUT       CHAR16             **EndPointer,  OPTIONAL
445   OUT       UINTN              *Data
446   );
447 
448 /**
449   Convert a Null-terminated Unicode decimal string to a value of type UINT64.
450 
451   This function outputs a value of type UINT64 by interpreting the contents of
452   the Unicode string specified by String as a decimal number. The format of the
453   input Unicode string String is:
454 
455                   [spaces] [decimal digits].
456 
457   The valid decimal digit character is in the range [0-9]. The function will
458   ignore the pad space, which includes spaces or tab characters, before
459   [decimal digits]. The running zero in the beginning of [decimal digits] will
460   be ignored. Then, the function stops at the first character that is a not a
461   valid decimal character or a Null-terminator, whichever one comes first.
462 
463   If String is NULL, then ASSERT().
464   If Data is NULL, then ASSERT().
465   If String is not aligned in a 16-bit boundary, then ASSERT().
466   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
467   PcdMaximumUnicodeStringLength Unicode characters, not including the
468   Null-terminator, then ASSERT().
469 
470   If String has no valid decimal digits in the above format, then 0 is stored
471   at the location pointed to by Data.
472   If the number represented by String exceeds the range defined by UINT64, then
473   MAX_UINT64 is stored at the location pointed to by Data.
474 
475   If EndPointer is not NULL, a pointer to the character that stopped the scan
476   is stored at the location pointed to by EndPointer. If String has no valid
477   decimal digits right after the optional pad spaces, the value of String is
478   stored at the location pointed to by EndPointer.
479 
480   @param  String                   Pointer to a Null-terminated Unicode string.
481   @param  EndPointer               Pointer to character that stops scan.
482   @param  Data                     Pointer to the converted value.
483 
484   @retval RETURN_SUCCESS           Value is translated from String.
485   @retval RETURN_INVALID_PARAMETER If String is NULL.
486                                    If Data is NULL.
487                                    If PcdMaximumUnicodeStringLength is not
488                                    zero, and String contains more than
489                                    PcdMaximumUnicodeStringLength Unicode
490                                    characters, not including the
491                                    Null-terminator.
492   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
493                                    the range defined by UINT64.
494 
495 **/
496 RETURN_STATUS
497 EFIAPI
498 StrDecimalToUint64S (
499   IN  CONST CHAR16             *String,
500   OUT       CHAR16             **EndPointer,  OPTIONAL
501   OUT       UINT64             *Data
502   );
503 
504 /**
505   Convert a Null-terminated Unicode hexadecimal string to a value of type
506   UINTN.
507 
508   This function outputs a value of type UINTN by interpreting the contents of
509   the Unicode string specified by String as a hexadecimal number. The format of
510   the input Unicode string String is:
511 
512                   [spaces][zeros][x][hexadecimal digits].
513 
514   The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
515   The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
516   If "x" appears in the input string, it must be prefixed with at least one 0.
517   The function will ignore the pad space, which includes spaces or tab
518   characters, before [zeros], [x] or [hexadecimal digit]. The running zero
519   before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts
520   after [x] or the first valid hexadecimal digit. Then, the function stops at
521   the first character that is a not a valid hexadecimal character or NULL,
522   whichever one comes first.
523 
524   If String is NULL, then ASSERT().
525   If Data is NULL, then ASSERT().
526   If String is not aligned in a 16-bit boundary, then ASSERT().
527   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
528   PcdMaximumUnicodeStringLength Unicode characters, not including the
529   Null-terminator, then ASSERT().
530 
531   If String has no valid hexadecimal digits in the above format, then 0 is
532   stored at the location pointed to by Data.
533   If the number represented by String exceeds the range defined by UINTN, then
534   MAX_UINTN is stored at the location pointed to by Data.
535 
536   If EndPointer is not NULL, a pointer to the character that stopped the scan
537   is stored at the location pointed to by EndPointer. If String has no valid
538   hexadecimal digits right after the optional pad spaces, the value of String
539   is stored at the location pointed to by EndPointer.
540 
541   @param  String                   Pointer to a Null-terminated Unicode string.
542   @param  EndPointer               Pointer to character that stops scan.
543   @param  Data                     Pointer to the converted value.
544 
545   @retval RETURN_SUCCESS           Value is translated from String.
546   @retval RETURN_INVALID_PARAMETER If String is NULL.
547                                    If Data is NULL.
548                                    If PcdMaximumUnicodeStringLength is not
549                                    zero, and String contains more than
550                                    PcdMaximumUnicodeStringLength Unicode
551                                    characters, not including the
552                                    Null-terminator.
553   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
554                                    the range defined by UINTN.
555 
556 **/
557 RETURN_STATUS
558 EFIAPI
559 StrHexToUintnS (
560   IN  CONST CHAR16             *String,
561   OUT       CHAR16             **EndPointer,  OPTIONAL
562   OUT       UINTN              *Data
563   );
564 
565 /**
566   Convert a Null-terminated Unicode hexadecimal string to a value of type
567   UINT64.
568 
569   This function outputs a value of type UINT64 by interpreting the contents of
570   the Unicode string specified by String as a hexadecimal number. The format of
571   the input Unicode string String is:
572 
573                   [spaces][zeros][x][hexadecimal digits].
574 
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
579   characters, before [zeros], [x] or [hexadecimal digit]. The running zero
580   before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts
581   after [x] or the first valid hexadecimal digit. Then, the function stops at
582   the first character that is a not a valid hexadecimal character or NULL,
583   whichever one comes first.
584 
585   If String is NULL, then ASSERT().
586   If Data is NULL, then ASSERT().
587   If String is not aligned in a 16-bit boundary, then ASSERT().
588   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
589   PcdMaximumUnicodeStringLength Unicode characters, not including the
590   Null-terminator, then ASSERT().
591 
592   If String has no valid hexadecimal digits in the above format, then 0 is
593   stored at the location pointed to by Data.
594   If the number represented by String exceeds the range defined by UINT64, then
595   MAX_UINT64 is stored at the location pointed to by Data.
596 
597   If EndPointer is not NULL, a pointer to the character that stopped the scan
598   is stored at the location pointed to by EndPointer. If String has no valid
599   hexadecimal digits right after the optional pad spaces, the value of String
600   is stored at the location pointed to by EndPointer.
601 
602   @param  String                   Pointer to a Null-terminated Unicode string.
603   @param  EndPointer               Pointer to character that stops scan.
604   @param  Data                     Pointer to the converted value.
605 
606   @retval RETURN_SUCCESS           Value is translated from String.
607   @retval RETURN_INVALID_PARAMETER If String is NULL.
608                                    If Data is NULL.
609                                    If PcdMaximumUnicodeStringLength is not
610                                    zero, and String contains more than
611                                    PcdMaximumUnicodeStringLength Unicode
612                                    characters, not including the
613                                    Null-terminator.
614   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
615                                    the range defined by UINT64.
616 
617 **/
618 RETURN_STATUS
619 EFIAPI
620 StrHexToUint64S (
621   IN  CONST CHAR16             *String,
622   OUT       CHAR16             **EndPointer,  OPTIONAL
623   OUT       UINT64             *Data
624   );
625 
626 /**
627   Returns the length of a Null-terminated Ascii string.
628 
629   This function is similar as strlen_s defined in C11.
630 
631   @param  String   A pointer to a Null-terminated Ascii string.
632   @param  MaxSize  The maximum number of Destination Ascii
633                    char, including terminating null char.
634 
635   @retval 0        If String is NULL.
636   @retval MaxSize  If there is no null character in the first MaxSize characters of String.
637   @return The number of characters that percede the terminating null character.
638 
639 **/
640 UINTN
641 EFIAPI
642 AsciiStrnLenS (
643   IN CONST CHAR8               *String,
644   IN UINTN                     MaxSize
645   );
646 
647 /**
648   Returns the size of a Null-terminated Ascii string in bytes, including the
649   Null terminator.
650 
651   This function returns the size of the Null-terminated Ascii string specified
652   by String in bytes, including the Null terminator.
653 
654   @param  String   A pointer to a Null-terminated Ascii string.
655   @param  MaxSize  The maximum number of Destination Ascii
656                    char, including the Null terminator.
657 
658   @retval 0  If String is NULL.
659   @retval (sizeof (CHAR8) * (MaxSize + 1))
660              If there is no Null terminator in the first MaxSize characters of
661              String.
662   @return The size of the Null-terminated Ascii string in bytes, including the
663           Null terminator.
664 
665 **/
666 UINTN
667 EFIAPI
668 AsciiStrnSizeS (
669   IN CONST CHAR8               *String,
670   IN UINTN                     MaxSize
671   );
672 
673 /**
674   Copies the string pointed to by Source (including the terminating null char)
675   to the array pointed to by Destination.
676 
677   This function is similar as strcpy_s defined in C11.
678 
679   If an error would be returned, then the function will also ASSERT().
680 
681   If an error is returned, then the Destination is unmodified.
682 
683   @param  Destination              A pointer to a Null-terminated Ascii string.
684   @param  DestMax                  The maximum number of Destination Ascii
685                                    char, including terminating null char.
686   @param  Source                   A pointer to a Null-terminated Ascii string.
687 
688   @retval RETURN_SUCCESS           String is copied.
689   @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).
690   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
691                                    If Source is NULL.
692                                    If PcdMaximumAsciiStringLength is not zero,
693                                     and DestMax is greater than
694                                     PcdMaximumAsciiStringLength.
695                                    If DestMax is 0.
696   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
697 **/
698 RETURN_STATUS
699 EFIAPI
700 AsciiStrCpyS (
701   OUT CHAR8        *Destination,
702   IN  UINTN        DestMax,
703   IN  CONST CHAR8  *Source
704   );
705 
706 /**
707   Copies not more than Length successive char from the string pointed to by
708   Source to the array pointed to by Destination. If no null char is copied from
709   Source, then Destination[Length] is always set to null.
710 
711   This function is similar as strncpy_s defined in C11.
712 
713   If an error would be returned, then the function will also ASSERT().
714 
715   If an error is returned, then the Destination is unmodified.
716 
717   @param  Destination              A pointer to a Null-terminated Ascii string.
718   @param  DestMax                  The maximum number of Destination Ascii
719                                    char, including terminating null char.
720   @param  Source                   A pointer to a Null-terminated Ascii string.
721   @param  Length                   The maximum number of Ascii characters to copy.
722 
723   @retval RETURN_SUCCESS           String is copied.
724   @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than
725                                    MIN(StrLen(Source), Length).
726   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
727                                    If Source is NULL.
728                                    If PcdMaximumAsciiStringLength is not zero,
729                                     and DestMax is greater than
730                                     PcdMaximumAsciiStringLength.
731                                    If DestMax is 0.
732   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
733 **/
734 RETURN_STATUS
735 EFIAPI
736 AsciiStrnCpyS (
737   OUT CHAR8        *Destination,
738   IN  UINTN        DestMax,
739   IN  CONST CHAR8  *Source,
740   IN  UINTN        Length
741   );
742 
743 /**
744   Appends a copy of the string pointed to by Source (including the terminating
745   null char) to the end of the string pointed to by Destination.
746 
747   This function is similar as strcat_s defined in C11.
748 
749   If an error would be returned, then the function will also ASSERT().
750 
751   If an error is returned, then the Destination is unmodified.
752 
753   @param  Destination              A pointer to a Null-terminated Ascii string.
754   @param  DestMax                  The maximum number of Destination Ascii
755                                    char, including terminating null char.
756   @param  Source                   A pointer to a Null-terminated Ascii string.
757 
758   @retval RETURN_SUCCESS           String is appended.
759   @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than
760                                    StrLen(Destination).
761   @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT
762                                    greater than StrLen(Source).
763   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
764                                    If Source is NULL.
765                                    If PcdMaximumAsciiStringLength is not zero,
766                                     and DestMax is greater than
767                                     PcdMaximumAsciiStringLength.
768                                    If DestMax is 0.
769   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
770 **/
771 RETURN_STATUS
772 EFIAPI
773 AsciiStrCatS (
774   IN OUT CHAR8        *Destination,
775   IN     UINTN        DestMax,
776   IN     CONST CHAR8  *Source
777   );
778 
779 /**
780   Appends not more than Length successive char from the string pointed to by
781   Source to the end of the string pointed to by Destination. If no null char is
782   copied from Source, then Destination[StrLen(Destination) + Length] is always
783   set to null.
784 
785   This function is similar as strncat_s defined in C11.
786 
787   If an error would be returned, then the function will also ASSERT().
788 
789   If an error is returned, then the Destination is unmodified.
790 
791   @param  Destination              A pointer to a Null-terminated Ascii string.
792   @param  DestMax                  The maximum number of Destination Ascii
793                                    char, including terminating null char.
794   @param  Source                   A pointer to a Null-terminated Ascii string.
795   @param  Length                   The maximum number of Ascii characters to copy.
796 
797   @retval RETURN_SUCCESS           String is appended.
798   @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than
799                                    StrLen(Destination).
800   @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT
801                                    greater than MIN(StrLen(Source), Length).
802   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
803                                    If Source is NULL.
804                                    If PcdMaximumAsciiStringLength is not zero,
805                                     and DestMax is greater than
806                                     PcdMaximumAsciiStringLength.
807                                    If DestMax is 0.
808   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
809 **/
810 RETURN_STATUS
811 EFIAPI
812 AsciiStrnCatS (
813   IN OUT CHAR8        *Destination,
814   IN     UINTN        DestMax,
815   IN     CONST CHAR8  *Source,
816   IN     UINTN        Length
817   );
818 
819 /**
820   Convert a Null-terminated Ascii decimal string to a value of type UINTN.
821 
822   This function outputs a value of type UINTN by interpreting the contents of
823   the Ascii string specified by String as a decimal number. The format of the
824   input Ascii string String is:
825 
826                   [spaces] [decimal digits].
827 
828   The valid decimal digit character is in the range [0-9]. The function will
829   ignore the pad space, which includes spaces or tab characters, before
830   [decimal digits]. The running zero in the beginning of [decimal digits] will
831   be ignored. Then, the function stops at the first character that is a not a
832   valid decimal character or a Null-terminator, whichever one comes first.
833 
834   If String is NULL, then ASSERT().
835   If Data is NULL, then ASSERT().
836   If PcdMaximumAsciiStringLength is not zero, and String contains more than
837   PcdMaximumAsciiStringLength Ascii characters, not including the
838   Null-terminator, then ASSERT().
839 
840   If String has no valid decimal digits in the above format, then 0 is stored
841   at the location pointed to by Data.
842   If the number represented by String exceeds the range defined by UINTN, then
843   MAX_UINTN is stored at the location pointed to by Data.
844 
845   If EndPointer is not NULL, a pointer to the character that stopped the scan
846   is stored at the location pointed to by EndPointer. If String has no valid
847   decimal digits right after the optional pad spaces, the value of String is
848   stored at the location pointed to by EndPointer.
849 
850   @param  String                   Pointer to a Null-terminated Ascii string.
851   @param  EndPointer               Pointer to character that stops scan.
852   @param  Data                     Pointer to the converted value.
853 
854   @retval RETURN_SUCCESS           Value is translated from String.
855   @retval RETURN_INVALID_PARAMETER If String is NULL.
856                                    If Data is NULL.
857                                    If PcdMaximumAsciiStringLength is not zero,
858                                    and String contains more than
859                                    PcdMaximumAsciiStringLength Ascii
860                                    characters, not including the
861                                    Null-terminator.
862   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
863                                    the range defined by UINTN.
864 
865 **/
866 RETURN_STATUS
867 EFIAPI
868 AsciiStrDecimalToUintnS (
869   IN  CONST CHAR8              *String,
870   OUT       CHAR8              **EndPointer,  OPTIONAL
871   OUT       UINTN              *Data
872   );
873 
874 /**
875   Convert a Null-terminated Ascii decimal string to a value of type UINT64.
876 
877   This function outputs a value of type UINT64 by interpreting the contents of
878   the Ascii string specified by String as a decimal number. The format of the
879   input Ascii string String is:
880 
881                   [spaces] [decimal digits].
882 
883   The valid decimal digit character is in the range [0-9]. The function will
884   ignore the pad space, which includes spaces or tab characters, before
885   [decimal digits]. The running zero in the beginning of [decimal digits] will
886   be ignored. Then, the function stops at the first character that is a not a
887   valid decimal character or a Null-terminator, whichever one comes first.
888 
889   If String is NULL, then ASSERT().
890   If Data is NULL, then ASSERT().
891   If PcdMaximumAsciiStringLength is not zero, and String contains more than
892   PcdMaximumAsciiStringLength Ascii characters, not including the
893   Null-terminator, then ASSERT().
894 
895   If String has no valid decimal digits in the above format, then 0 is stored
896   at the location pointed to by Data.
897   If the number represented by String exceeds the range defined by UINT64, then
898   MAX_UINT64 is stored at the location pointed to by Data.
899 
900   If EndPointer is not NULL, a pointer to the character that stopped the scan
901   is stored at the location pointed to by EndPointer. If String has no valid
902   decimal digits right after the optional pad spaces, the value of String is
903   stored at the location pointed to by EndPointer.
904 
905   @param  String                   Pointer to a Null-terminated Ascii string.
906   @param  EndPointer               Pointer to character that stops scan.
907   @param  Data                     Pointer to the converted value.
908 
909   @retval RETURN_SUCCESS           Value is translated from String.
910   @retval RETURN_INVALID_PARAMETER If String is NULL.
911                                    If Data is NULL.
912                                    If PcdMaximumAsciiStringLength is not zero,
913                                    and String contains more than
914                                    PcdMaximumAsciiStringLength Ascii
915                                    characters, not including the
916                                    Null-terminator.
917   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
918                                    the range defined by UINT64.
919 
920 **/
921 RETURN_STATUS
922 EFIAPI
923 AsciiStrDecimalToUint64S (
924   IN  CONST CHAR8              *String,
925   OUT       CHAR8              **EndPointer,  OPTIONAL
926   OUT       UINT64             *Data
927   );
928 
929 /**
930   Convert a Null-terminated Ascii hexadecimal string to a value of type UINTN.
931 
932   This function outputs a value of type UINTN by interpreting the contents of
933   the Ascii string specified by String as a hexadecimal number. The format of
934   the input Ascii string String is:
935 
936                   [spaces][zeros][x][hexadecimal digits].
937 
938   The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
939   The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If
940   "x" appears in the input string, it must be prefixed with at least one 0. The
941   function will ignore the pad space, which includes spaces or tab characters,
942   before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or
943   [hexadecimal digits] will be ignored. Then, the decoding starts after [x] or
944   the first valid hexadecimal digit. Then, the function stops at the first
945   character that is a not a valid hexadecimal character or Null-terminator,
946   whichever on comes first.
947 
948   If String is NULL, then ASSERT().
949   If Data is NULL, then ASSERT().
950   If PcdMaximumAsciiStringLength is not zero, and String contains more than
951   PcdMaximumAsciiStringLength Ascii characters, not including the
952   Null-terminator, then ASSERT().
953 
954   If String has no valid hexadecimal digits in the above format, then 0 is
955   stored at the location pointed to by Data.
956   If the number represented by String exceeds the range defined by UINTN, then
957   MAX_UINTN is stored at the location pointed to by Data.
958 
959   If EndPointer is not NULL, a pointer to the character that stopped the scan
960   is stored at the location pointed to by EndPointer. If String has no valid
961   hexadecimal digits right after the optional pad spaces, the value of String
962   is stored at the location pointed to by EndPointer.
963 
964   @param  String                   Pointer to a Null-terminated Ascii string.
965   @param  EndPointer               Pointer to character that stops scan.
966   @param  Data                     Pointer to the converted value.
967 
968   @retval RETURN_SUCCESS           Value is translated from String.
969   @retval RETURN_INVALID_PARAMETER If String is NULL.
970                                    If Data is NULL.
971                                    If PcdMaximumAsciiStringLength is not zero,
972                                    and String contains more than
973                                    PcdMaximumAsciiStringLength Ascii
974                                    characters, not including the
975                                    Null-terminator.
976   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
977                                    the range defined by UINTN.
978 
979 **/
980 RETURN_STATUS
981 EFIAPI
982 AsciiStrHexToUintnS (
983   IN  CONST CHAR8              *String,
984   OUT       CHAR8              **EndPointer,  OPTIONAL
985   OUT       UINTN              *Data
986   );
987 
988 /**
989   Convert a Null-terminated Ascii hexadecimal string to a value of type UINT64.
990 
991   This function outputs a value of type UINT64 by interpreting the contents of
992   the Ascii string specified by String as a hexadecimal number. The format of
993   the input Ascii string String is:
994 
995                   [spaces][zeros][x][hexadecimal digits].
996 
997   The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
998   The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If
999   "x" appears in the input string, it must be prefixed with at least one 0. The
1000   function will ignore the pad space, which includes spaces or tab characters,
1001   before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or
1002   [hexadecimal digits] will be ignored. Then, the decoding starts after [x] or
1003   the first valid hexadecimal digit. Then, the function stops at the first
1004   character that is a not a valid hexadecimal character or Null-terminator,
1005   whichever on comes first.
1006 
1007   If String is NULL, then ASSERT().
1008   If Data is NULL, then ASSERT().
1009   If PcdMaximumAsciiStringLength is not zero, and String contains more than
1010   PcdMaximumAsciiStringLength Ascii characters, not including the
1011   Null-terminator, then ASSERT().
1012 
1013   If String has no valid hexadecimal digits in the above format, then 0 is
1014   stored at the location pointed to by Data.
1015   If the number represented by String exceeds the range defined by UINT64, then
1016   MAX_UINT64 is stored at the location pointed to by Data.
1017 
1018   If EndPointer is not NULL, a pointer to the character that stopped the scan
1019   is stored at the location pointed to by EndPointer. If String has no valid
1020   hexadecimal digits right after the optional pad spaces, the value of String
1021   is stored at the location pointed to by EndPointer.
1022 
1023   @param  String                   Pointer to a Null-terminated Ascii string.
1024   @param  EndPointer               Pointer to character that stops scan.
1025   @param  Data                     Pointer to the converted value.
1026 
1027   @retval RETURN_SUCCESS           Value is translated from String.
1028   @retval RETURN_INVALID_PARAMETER If String is NULL.
1029                                    If Data is NULL.
1030                                    If PcdMaximumAsciiStringLength is not zero,
1031                                    and String contains more than
1032                                    PcdMaximumAsciiStringLength Ascii
1033                                    characters, not including the
1034                                    Null-terminator.
1035   @retval RETURN_UNSUPPORTED       If the number represented by String exceeds
1036                                    the range defined by UINT64.
1037 
1038 **/
1039 RETURN_STATUS
1040 EFIAPI
1041 AsciiStrHexToUint64S (
1042   IN  CONST CHAR8              *String,
1043   OUT       CHAR8              **EndPointer,  OPTIONAL
1044   OUT       UINT64             *Data
1045   );
1046 
1047 
1048 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1049 
1050 /**
1051   [ATTENTION] This function is deprecated for security reason.
1052 
1053   Copies one Null-terminated Unicode string to another Null-terminated Unicode
1054   string and returns the new Unicode string.
1055 
1056   This function copies the contents of the Unicode string Source to the Unicode
1057   string Destination, and returns Destination. If Source and Destination
1058   overlap, then the results are undefined.
1059 
1060   If Destination is NULL, then ASSERT().
1061   If Destination is not aligned on a 16-bit boundary, then ASSERT().
1062   If Source is NULL, then ASSERT().
1063   If Source is not aligned on a 16-bit boundary, then ASSERT().
1064   If Source and Destination overlap, then ASSERT().
1065   If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1066   PcdMaximumUnicodeStringLength Unicode characters not including the
1067   Null-terminator, then ASSERT().
1068 
1069   @param  Destination The pointer to a Null-terminated Unicode string.
1070   @param  Source      The pointer to a Null-terminated Unicode string.
1071 
1072   @return Destination.
1073 
1074 **/
1075 CHAR16 *
1076 EFIAPI
1077 StrCpy (
1078   OUT     CHAR16                    *Destination,
1079   IN      CONST CHAR16              *Source
1080   );
1081 
1082 
1083 /**
1084   [ATTENTION] This function is deprecated for security reason.
1085 
1086   Copies up to a specified length from one Null-terminated Unicode string to
1087   another Null-terminated Unicode string and returns the new Unicode string.
1088 
1089   This function copies the contents of the Unicode string Source to the Unicode
1090   string Destination, and returns Destination. At most, Length Unicode
1091   characters are copied from Source to Destination. If Length is 0, then
1092   Destination is returned unmodified. If Length is greater that the number of
1093   Unicode characters in Source, then Destination is padded with Null Unicode
1094   characters. If Source and Destination overlap, then the results are
1095   undefined.
1096 
1097   If Length > 0 and Destination is NULL, then ASSERT().
1098   If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
1099   If Length > 0 and Source is NULL, then ASSERT().
1100   If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
1101   If Source and Destination overlap, then ASSERT().
1102   If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
1103   PcdMaximumUnicodeStringLength, then ASSERT().
1104   If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1105   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
1106   then ASSERT().
1107 
1108   @param  Destination The pointer to a Null-terminated Unicode string.
1109   @param  Source      The pointer to a Null-terminated Unicode string.
1110   @param  Length      The maximum number of Unicode characters to copy.
1111 
1112   @return Destination.
1113 
1114 **/
1115 CHAR16 *
1116 EFIAPI
1117 StrnCpy (
1118   OUT     CHAR16                    *Destination,
1119   IN      CONST CHAR16              *Source,
1120   IN      UINTN                     Length
1121   );
1122 #endif
1123 
1124 /**
1125   Returns the length of a Null-terminated Unicode string.
1126 
1127   This function returns the number of Unicode characters in the Null-terminated
1128   Unicode string specified by String.
1129 
1130   If String is NULL, then ASSERT().
1131   If String is not aligned on a 16-bit boundary, then ASSERT().
1132   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
1133   PcdMaximumUnicodeStringLength Unicode characters not including the
1134   Null-terminator, then ASSERT().
1135 
1136   @param  String  Pointer to a Null-terminated Unicode string.
1137 
1138   @return The length of String.
1139 
1140 **/
1141 UINTN
1142 EFIAPI
1143 StrLen (
1144   IN      CONST CHAR16              *String
1145   );
1146 
1147 
1148 /**
1149   Returns the size of a Null-terminated Unicode string in bytes, including the
1150   Null terminator.
1151 
1152   This function returns the size, in bytes, of the Null-terminated Unicode string
1153   specified by String.
1154 
1155   If String is NULL, then ASSERT().
1156   If String is not aligned on a 16-bit boundary, then ASSERT().
1157   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
1158   PcdMaximumUnicodeStringLength Unicode characters not including the
1159   Null-terminator, then ASSERT().
1160 
1161   @param  String  The pointer to a Null-terminated Unicode string.
1162 
1163   @return The size of String.
1164 
1165 **/
1166 UINTN
1167 EFIAPI
1168 StrSize (
1169   IN      CONST CHAR16              *String
1170   );
1171 
1172 
1173 /**
1174   Compares two Null-terminated Unicode strings, and returns the difference
1175   between the first mismatched Unicode characters.
1176 
1177   This function compares the Null-terminated Unicode string FirstString to the
1178   Null-terminated Unicode string SecondString. If FirstString is identical to
1179   SecondString, then 0 is returned. Otherwise, the value returned is the first
1180   mismatched Unicode character in SecondString subtracted from the first
1181   mismatched Unicode character in FirstString.
1182 
1183   If FirstString is NULL, then ASSERT().
1184   If FirstString is not aligned on a 16-bit boundary, then ASSERT().
1185   If SecondString is NULL, then ASSERT().
1186   If SecondString is not aligned on a 16-bit boundary, then ASSERT().
1187   If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
1188   than PcdMaximumUnicodeStringLength Unicode characters not including the
1189   Null-terminator, then ASSERT().
1190   If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
1191   than PcdMaximumUnicodeStringLength Unicode characters, not including the
1192   Null-terminator, then ASSERT().
1193 
1194   @param  FirstString   The pointer to a Null-terminated Unicode string.
1195   @param  SecondString  The pointer to a Null-terminated Unicode string.
1196 
1197   @retval 0      FirstString is identical to SecondString.
1198   @return others FirstString is not identical to SecondString.
1199 
1200 **/
1201 INTN
1202 EFIAPI
1203 StrCmp (
1204   IN      CONST CHAR16              *FirstString,
1205   IN      CONST CHAR16              *SecondString
1206   );
1207 
1208 
1209 /**
1210   Compares up to a specified length the contents of two Null-terminated Unicode strings,
1211   and returns the difference between the first mismatched Unicode characters.
1212 
1213   This function compares the Null-terminated Unicode string FirstString to the
1214   Null-terminated Unicode string SecondString. At most, Length Unicode
1215   characters will be compared. If Length is 0, then 0 is returned. If
1216   FirstString is identical to SecondString, then 0 is returned. Otherwise, the
1217   value returned is the first mismatched Unicode character in SecondString
1218   subtracted from the first mismatched Unicode character in FirstString.
1219 
1220   If Length > 0 and FirstString is NULL, then ASSERT().
1221   If Length > 0 and FirstString is not aligned on a 16-bit boundary, then ASSERT().
1222   If Length > 0 and SecondString is NULL, then ASSERT().
1223   If Length > 0 and SecondString is not aligned on a 16-bit boundary, then ASSERT().
1224   If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
1225   PcdMaximumUnicodeStringLength, then ASSERT().
1226   If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than
1227   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
1228   then ASSERT().
1229   If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than
1230   PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,
1231   then ASSERT().
1232 
1233   @param  FirstString   The pointer to a Null-terminated Unicode string.
1234   @param  SecondString  The pointer to a Null-terminated Unicode string.
1235   @param  Length        The maximum number of Unicode characters to compare.
1236 
1237   @retval 0      FirstString is identical to SecondString.
1238   @return others FirstString is not identical to SecondString.
1239 
1240 **/
1241 INTN
1242 EFIAPI
1243 StrnCmp (
1244   IN      CONST CHAR16              *FirstString,
1245   IN      CONST CHAR16              *SecondString,
1246   IN      UINTN                     Length
1247   );
1248 
1249 
1250 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1251 
1252 /**
1253   [ATTENTION] This function is deprecated for security reason.
1254 
1255   Concatenates one Null-terminated Unicode string to another Null-terminated
1256   Unicode string, and returns the concatenated Unicode string.
1257 
1258   This function concatenates two Null-terminated Unicode strings. The contents
1259   of Null-terminated Unicode string Source are concatenated to the end of
1260   Null-terminated Unicode string Destination. The Null-terminated concatenated
1261   Unicode String is returned. If Source and Destination overlap, then the
1262   results are undefined.
1263 
1264   If Destination is NULL, then ASSERT().
1265   If Destination is not aligned on a 16-bit boundary, then ASSERT().
1266   If Source is NULL, then ASSERT().
1267   If Source is not aligned on a 16-bit boundary, then ASSERT().
1268   If Source and Destination overlap, then ASSERT().
1269   If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
1270   than PcdMaximumUnicodeStringLength Unicode characters, not including the
1271   Null-terminator, then ASSERT().
1272   If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1273   PcdMaximumUnicodeStringLength Unicode characters, not including the
1274   Null-terminator, then ASSERT().
1275   If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
1276   and Source results in a Unicode string with more than
1277   PcdMaximumUnicodeStringLength Unicode characters, not including the
1278   Null-terminator, then ASSERT().
1279 
1280   @param  Destination The pointer to a Null-terminated Unicode string.
1281   @param  Source      The pointer to a Null-terminated Unicode string.
1282 
1283   @return Destination.
1284 
1285 **/
1286 CHAR16 *
1287 EFIAPI
1288 StrCat (
1289   IN OUT  CHAR16                    *Destination,
1290   IN      CONST CHAR16              *Source
1291   );
1292 
1293 
1294 /**
1295   [ATTENTION] This function is deprecated for security reason.
1296 
1297   Concatenates up to a specified length one Null-terminated Unicode to the end
1298   of another Null-terminated Unicode string, and returns the concatenated
1299   Unicode string.
1300 
1301   This function concatenates two Null-terminated Unicode strings. The contents
1302   of Null-terminated Unicode string Source are concatenated to the end of
1303   Null-terminated Unicode string Destination, and Destination is returned. At
1304   most, Length Unicode characters are concatenated from Source to the end of
1305   Destination, and Destination is always Null-terminated. If Length is 0, then
1306   Destination is returned unmodified. If Source and Destination overlap, then
1307   the results are undefined.
1308 
1309   If Destination is NULL, then ASSERT().
1310   If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
1311   If Length > 0 and Source is NULL, then ASSERT().
1312   If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
1313   If Source and Destination overlap, then ASSERT().
1314   If PcdMaximumUnicodeStringLength is not zero, and Length is greater than
1315   PcdMaximumUnicodeStringLength, then ASSERT().
1316   If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
1317   than PcdMaximumUnicodeStringLength Unicode characters, not including the
1318   Null-terminator, then ASSERT().
1319   If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1320   PcdMaximumUnicodeStringLength Unicode characters, not including the
1321   Null-terminator, then ASSERT().
1322   If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
1323   and Source results in a Unicode string with more than PcdMaximumUnicodeStringLength
1324   Unicode characters, not including the Null-terminator, then ASSERT().
1325 
1326   @param  Destination The pointer to a Null-terminated Unicode string.
1327   @param  Source      The pointer to a Null-terminated Unicode string.
1328   @param  Length      The maximum number of Unicode characters to concatenate from
1329                       Source.
1330 
1331   @return Destination.
1332 
1333 **/
1334 CHAR16 *
1335 EFIAPI
1336 StrnCat (
1337   IN OUT  CHAR16                    *Destination,
1338   IN      CONST CHAR16              *Source,
1339   IN      UINTN                     Length
1340   );
1341 #endif
1342 
1343 /**
1344   Returns the first occurrence of a Null-terminated Unicode sub-string
1345   in a Null-terminated Unicode string.
1346 
1347   This function scans the contents of the Null-terminated Unicode string
1348   specified by String and returns the first occurrence of SearchString.
1349   If SearchString is not found in String, then NULL is returned.  If
1350   the length of SearchString is zero, then String is returned.
1351 
1352   If String is NULL, then ASSERT().
1353   If String is not aligned on a 16-bit boundary, then ASSERT().
1354   If SearchString is NULL, then ASSERT().
1355   If SearchString is not aligned on a 16-bit boundary, then ASSERT().
1356 
1357   If PcdMaximumUnicodeStringLength is not zero, and SearchString
1358   or String contains more than PcdMaximumUnicodeStringLength Unicode
1359   characters, not including the Null-terminator, then ASSERT().
1360 
1361   @param  String          The pointer to a Null-terminated Unicode string.
1362   @param  SearchString    The pointer to a Null-terminated Unicode string to search for.
1363 
1364   @retval NULL            If the SearchString does not appear in String.
1365   @return others          If there is a match.
1366 
1367 **/
1368 CHAR16 *
1369 EFIAPI
1370 StrStr (
1371   IN      CONST CHAR16              *String,
1372   IN      CONST CHAR16              *SearchString
1373   );
1374 
1375 /**
1376   Convert a Null-terminated Unicode decimal string to a value of
1377   type UINTN.
1378 
1379   This function returns a value of type UINTN by interpreting the contents
1380   of the Unicode string specified by String as a decimal number. The format
1381   of the input Unicode string String is:
1382 
1383                   [spaces] [decimal digits].
1384 
1385   The valid decimal digit character is in the range [0-9]. The
1386   function will ignore the pad space, which includes spaces or
1387   tab characters, before [decimal digits]. The running zero in the
1388   beginning of [decimal digits] will be ignored. Then, the function
1389   stops at the first character that is a not a valid decimal character
1390   or a Null-terminator, whichever one comes first.
1391 
1392   If String is NULL, then ASSERT().
1393   If String is not aligned in a 16-bit boundary, then ASSERT().
1394   If String has only pad spaces, then 0 is returned.
1395   If String has no pad spaces or valid decimal digits,
1396   then 0 is returned.
1397   If the number represented by String overflows according
1398   to the range defined by UINTN, then MAX_UINTN is returned.
1399 
1400   If PcdMaximumUnicodeStringLength is not zero, and String contains
1401   more than PcdMaximumUnicodeStringLength Unicode characters not including
1402   the Null-terminator, then ASSERT().
1403 
1404   @param  String      The pointer to a Null-terminated Unicode string.
1405 
1406   @retval Value translated from String.
1407 
1408 **/
1409 UINTN
1410 EFIAPI
1411 StrDecimalToUintn (
1412   IN      CONST CHAR16              *String
1413   );
1414 
1415 /**
1416   Convert a Null-terminated Unicode decimal string to a value of
1417   type UINT64.
1418 
1419   This function returns a value of type UINT64 by interpreting the contents
1420   of the Unicode string specified by String as a decimal number. The format
1421   of the input Unicode string String is:
1422 
1423                   [spaces] [decimal digits].
1424 
1425   The valid decimal digit character is in the range [0-9]. The
1426   function will ignore the pad space, which includes spaces or
1427   tab characters, before [decimal digits]. The running zero in the
1428   beginning of [decimal digits] will be ignored. Then, the function
1429   stops at the first character that is a not a valid decimal character
1430   or a Null-terminator, whichever one comes first.
1431 
1432   If String is NULL, then ASSERT().
1433   If String is not aligned in a 16-bit boundary, then ASSERT().
1434   If String has only pad spaces, then 0 is returned.
1435   If String has no pad spaces or valid decimal digits,
1436   then 0 is returned.
1437   If the number represented by String overflows according
1438   to the range defined by UINT64, then MAX_UINT64 is returned.
1439 
1440   If PcdMaximumUnicodeStringLength is not zero, and String contains
1441   more than PcdMaximumUnicodeStringLength Unicode characters not including
1442   the Null-terminator, then ASSERT().
1443 
1444   @param  String          The pointer to a Null-terminated Unicode string.
1445 
1446   @retval Value translated from String.
1447 
1448 **/
1449 UINT64
1450 EFIAPI
1451 StrDecimalToUint64 (
1452   IN      CONST CHAR16              *String
1453   );
1454 
1455 
1456 /**
1457   Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
1458 
1459   This function returns a value of type UINTN by interpreting the contents
1460   of the Unicode string specified by String as a hexadecimal number.
1461   The format of the input Unicode string String is:
1462 
1463                   [spaces][zeros][x][hexadecimal digits].
1464 
1465   The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1466   The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
1467   If "x" appears in the input string, it must be prefixed with at least one 0.
1468   The function will ignore the pad space, which includes spaces or tab characters,
1469   before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
1470   [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
1471   first valid hexadecimal digit. Then, the function stops at the first character
1472   that is a not a valid hexadecimal character or NULL, whichever one comes first.
1473 
1474   If String is NULL, then ASSERT().
1475   If String is not aligned in a 16-bit boundary, then ASSERT().
1476   If String has only pad spaces, then zero is returned.
1477   If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
1478   then zero is returned.
1479   If the number represented by String overflows according to the range defined by
1480   UINTN, then MAX_UINTN is returned.
1481 
1482   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
1483   PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
1484   then ASSERT().
1485 
1486   @param  String          The pointer to a Null-terminated Unicode string.
1487 
1488   @retval Value translated from String.
1489 
1490 **/
1491 UINTN
1492 EFIAPI
1493 StrHexToUintn (
1494   IN      CONST CHAR16              *String
1495   );
1496 
1497 
1498 /**
1499   Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
1500 
1501   This function returns a value of type UINT64 by interpreting the contents
1502   of the Unicode string specified by String as a hexadecimal number.
1503   The format of the input Unicode string String is
1504 
1505                   [spaces][zeros][x][hexadecimal digits].
1506 
1507   The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1508   The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
1509   If "x" appears in the input string, it must be prefixed with at least one 0.
1510   The function will ignore the pad space, which includes spaces or tab characters,
1511   before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
1512   [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
1513   first valid hexadecimal digit. Then, the function stops at the first character that is
1514   a not a valid hexadecimal character or NULL, whichever one comes first.
1515 
1516   If String is NULL, then ASSERT().
1517   If String is not aligned in a 16-bit boundary, then ASSERT().
1518   If String has only pad spaces, then zero is returned.
1519   If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
1520   then zero is returned.
1521   If the number represented by String overflows according to the range defined by
1522   UINT64, then MAX_UINT64 is returned.
1523 
1524   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
1525   PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
1526   then ASSERT().
1527 
1528   @param  String          The pointer to a Null-terminated Unicode string.
1529 
1530   @retval Value translated from String.
1531 
1532 **/
1533 UINT64
1534 EFIAPI
1535 StrHexToUint64 (
1536   IN      CONST CHAR16             *String
1537   );
1538 
1539 /**
1540   Convert a Null-terminated Unicode string to IPv6 address and prefix length.
1541 
1542   This function outputs a value of type IPv6_ADDRESS and may output a value
1543   of type UINT8 by interpreting the contents of the Unicode string specified
1544   by String. The format of the input Unicode string String is as follows:
1545 
1546                   X:X:X:X:X:X:X:X[/P]
1547 
1548   X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and
1549   [A-F]. X is converted to a value of type UINT16, whose low byte is stored in low
1550   memory address and high byte is stored in high memory address. P contains decimal
1551   digit characters in the range [0-9]. The running zero in the beginning of P will
1552   be ignored. /P is optional.
1553 
1554   When /P is not in the String, the function stops at the first character that is
1555   not a valid hexadecimal digit character after eight X's are converted.
1556 
1557   When /P is in the String, the function stops at the first character that is not
1558   a valid decimal digit character after P is converted.
1559 
1560   "::" can be used to compress one or more groups of X when X contains only 0.
1561   The "::" can only appear once in the String.
1562 
1563   If String is NULL, then ASSERT().
1564 
1565   If Address is NULL, then ASSERT().
1566 
1567   If String is not aligned in a 16-bit boundary, then ASSERT().
1568 
1569   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
1570   PcdMaximumUnicodeStringLength Unicode characters, not including the
1571   Null-terminator, then ASSERT().
1572 
1573   If EndPointer is not NULL and Address is translated from String, a pointer
1574   to the character that stopped the scan is stored at the location pointed to
1575   by EndPointer.
1576 
1577   @param  String                   Pointer to a Null-terminated Unicode string.
1578   @param  EndPointer               Pointer to character that stops scan.
1579   @param  Address                  Pointer to the converted IPv6 address.
1580   @param  PrefixLength             Pointer to the converted IPv6 address prefix
1581                                    length. MAX_UINT8 is returned when /P is
1582                                    not in the String.
1583 
1584   @retval RETURN_SUCCESS           Address is translated from String.
1585   @retval RETURN_INVALID_PARAMETER If String is NULL.
1586                                    If Data is NULL.
1587   @retval RETURN_UNSUPPORTED       If X contains more than four hexadecimal
1588                                     digit characters.
1589                                    If String contains "::" and number of X
1590                                     is not less than 8.
1591                                    If P starts with character that is not a
1592                                     valid decimal digit character.
1593                                    If the decimal number converted from P
1594                                     exceeds 128.
1595 
1596 **/
1597 RETURN_STATUS
1598 EFIAPI
1599 StrToIpv6Address (
1600   IN  CONST CHAR16       *String,
1601   OUT CHAR16             **EndPointer, OPTIONAL
1602   OUT IPv6_ADDRESS       *Address,
1603   OUT UINT8              *PrefixLength OPTIONAL
1604   );
1605 
1606 /**
1607   Convert a Null-terminated Unicode string to IPv4 address and prefix length.
1608 
1609   This function outputs a value of type IPv4_ADDRESS and may output a value
1610   of type UINT8 by interpreting the contents of the Unicode string specified
1611   by String. The format of the input Unicode string String is as follows:
1612 
1613                   D.D.D.D[/P]
1614 
1615   D and P are decimal digit characters in the range [0-9]. The running zero in
1616   the beginning of D and P will be ignored. /P is optional.
1617 
1618   When /P is not in the String, the function stops at the first character that is
1619   not a valid decimal digit character after four D's are converted.
1620 
1621   When /P is in the String, the function stops at the first character that is not
1622   a valid decimal digit character after P is converted.
1623 
1624   If String is NULL, then ASSERT().
1625 
1626   If Address is NULL, then ASSERT().
1627 
1628   If String is not aligned in a 16-bit boundary, then ASSERT().
1629 
1630   If PcdMaximumUnicodeStringLength is not zero, and String contains more than
1631   PcdMaximumUnicodeStringLength Unicode characters, not including the
1632   Null-terminator, then ASSERT().
1633 
1634   If EndPointer is not NULL and Address is translated from String, a pointer
1635   to the character that stopped the scan is stored at the location pointed to
1636   by EndPointer.
1637 
1638   @param  String                   Pointer to a Null-terminated Unicode string.
1639   @param  EndPointer               Pointer to character that stops scan.
1640   @param  Address                  Pointer to the converted IPv4 address.
1641   @param  PrefixLength             Pointer to the converted IPv4 address prefix
1642                                    length. MAX_UINT8 is returned when /P is
1643                                    not in the String.
1644 
1645   @retval RETURN_SUCCESS           Address is translated from String.
1646   @retval RETURN_INVALID_PARAMETER If String is NULL.
1647                                    If Data is NULL.
1648   @retval RETURN_UNSUPPORTED       If String is not in the correct format.
1649                                    If any decimal number converted from D
1650                                     exceeds 255.
1651                                    If the decimal number converted from P
1652                                     exceeds 32.
1653 
1654 **/
1655 RETURN_STATUS
1656 EFIAPI
1657 StrToIpv4Address (
1658   IN  CONST CHAR16       *String,
1659   OUT CHAR16             **EndPointer, OPTIONAL
1660   OUT IPv4_ADDRESS       *Address,
1661   OUT UINT8              *PrefixLength OPTIONAL
1662   );
1663 
1664 #define GUID_STRING_LENGTH  36
1665 
1666 /**
1667   Convert a Null-terminated Unicode GUID string to a value of type
1668   EFI_GUID.
1669 
1670   This function outputs a GUID value by interpreting the contents of
1671   the Unicode string specified by String. The format of the input
1672   Unicode string String consists of 36 characters, as follows:
1673 
1674                   aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
1675 
1676   The pairs aa - pp are two characters in the range [0-9], [a-f] and
1677   [A-F], with each pair representing a single byte hexadecimal value.
1678 
1679   The mapping between String and the EFI_GUID structure is as follows:
1680                   aa          Data1[24:31]
1681                   bb          Data1[16:23]
1682                   cc          Data1[8:15]
1683                   dd          Data1[0:7]
1684                   ee          Data2[8:15]
1685                   ff          Data2[0:7]
1686                   gg          Data3[8:15]
1687                   hh          Data3[0:7]
1688                   ii          Data4[0:7]
1689                   jj          Data4[8:15]
1690                   kk          Data4[16:23]
1691                   ll          Data4[24:31]
1692                   mm          Data4[32:39]
1693                   nn          Data4[40:47]
1694                   oo          Data4[48:55]
1695                   pp          Data4[56:63]
1696 
1697   If String is NULL, then ASSERT().
1698   If Guid is NULL, then ASSERT().
1699   If String is not aligned in a 16-bit boundary, then ASSERT().
1700 
1701   @param  String                   Pointer to a Null-terminated Unicode string.
1702   @param  Guid                     Pointer to the converted GUID.
1703 
1704   @retval RETURN_SUCCESS           Guid is translated from String.
1705   @retval RETURN_INVALID_PARAMETER If String is NULL.
1706                                    If Data is NULL.
1707   @retval RETURN_UNSUPPORTED       If String is not as the above format.
1708 
1709 **/
1710 RETURN_STATUS
1711 EFIAPI
1712 StrToGuid (
1713   IN  CONST CHAR16       *String,
1714   OUT GUID               *Guid
1715   );
1716 
1717 /**
1718   Convert a Null-terminated Unicode hexadecimal string to a byte array.
1719 
1720   This function outputs a byte array by interpreting the contents of
1721   the Unicode string specified by String in hexadecimal format. The format of
1722   the input Unicode string String is:
1723 
1724                   [XX]*
1725 
1726   X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].
1727   The function decodes every two hexadecimal digit characters as one byte. The
1728   decoding stops after Length of characters and outputs Buffer containing
1729   (Length / 2) bytes.
1730 
1731   If String is not aligned in a 16-bit boundary, then ASSERT().
1732 
1733   If String is NULL, then ASSERT().
1734 
1735   If Buffer is NULL, then ASSERT().
1736 
1737   If Length is not multiple of 2, then ASSERT().
1738 
1739   If PcdMaximumUnicodeStringLength is not zero and Length is greater than
1740   PcdMaximumUnicodeStringLength, then ASSERT().
1741 
1742   If MaxBufferSize is less than (Length / 2), then ASSERT().
1743 
1744   @param  String                   Pointer to a Null-terminated Unicode string.
1745   @param  Length                   The number of Unicode characters to decode.
1746   @param  Buffer                   Pointer to the converted bytes array.
1747   @param  MaxBufferSize            The maximum size of Buffer.
1748 
1749   @retval RETURN_SUCCESS           Buffer is translated from String.
1750   @retval RETURN_INVALID_PARAMETER If String is NULL.
1751                                    If Data is NULL.
1752                                    If Length is not multiple of 2.
1753                                    If PcdMaximumUnicodeStringLength is not zero,
1754                                     and Length is greater than
1755                                     PcdMaximumUnicodeStringLength.
1756   @retval RETURN_UNSUPPORTED       If Length of characters from String contain
1757                                     a character that is not valid hexadecimal
1758                                     digit characters, or a Null-terminator.
1759   @retval RETURN_BUFFER_TOO_SMALL  If MaxBufferSize is less than (Length / 2).
1760 **/
1761 RETURN_STATUS
1762 EFIAPI
1763 StrHexToBytes (
1764   IN  CONST CHAR16       *String,
1765   IN  UINTN              Length,
1766   OUT UINT8              *Buffer,
1767   IN  UINTN              MaxBufferSize
1768   );
1769 
1770 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1771 
1772 /**
1773   [ATTENTION] This function is deprecated for security reason.
1774 
1775   Convert a Null-terminated Unicode string to a Null-terminated
1776   ASCII string and returns the ASCII string.
1777 
1778   This function converts the content of the Unicode string Source
1779   to the ASCII string Destination by copying the lower 8 bits of
1780   each Unicode character. It returns Destination.
1781 
1782   The caller is responsible to make sure Destination points to a buffer with size
1783   equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.
1784 
1785   If any Unicode characters in Source contain non-zero value in
1786   the upper 8 bits, then ASSERT().
1787 
1788   If Destination is NULL, then ASSERT().
1789   If Source is NULL, then ASSERT().
1790   If Source is not aligned on a 16-bit boundary, then ASSERT().
1791   If Source and Destination overlap, then ASSERT().
1792 
1793   If PcdMaximumUnicodeStringLength is not zero, and Source contains
1794   more than PcdMaximumUnicodeStringLength Unicode characters not including
1795   the Null-terminator, then ASSERT().
1796 
1797   If PcdMaximumAsciiStringLength is not zero, and Source contains more
1798   than PcdMaximumAsciiStringLength Unicode characters not including the
1799   Null-terminator, then ASSERT().
1800 
1801   @param  Source        The pointer to a Null-terminated Unicode string.
1802   @param  Destination   The pointer to a Null-terminated ASCII string.
1803 
1804   @return Destination.
1805 
1806 **/
1807 CHAR8 *
1808 EFIAPI
1809 UnicodeStrToAsciiStr (
1810   IN      CONST CHAR16              *Source,
1811   OUT     CHAR8                     *Destination
1812   );
1813 
1814 #endif
1815 
1816 /**
1817   Convert a Null-terminated Unicode string to a Null-terminated
1818   ASCII string.
1819 
1820   This function is similar to AsciiStrCpyS.
1821 
1822   This function converts the content of the Unicode string Source
1823   to the ASCII string Destination by copying the lower 8 bits of
1824   each Unicode character. The function terminates the ASCII string
1825   Destination by appending a Null-terminator character at the end.
1826 
1827   The caller is responsible to make sure Destination points to a buffer with size
1828   equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.
1829 
1830   If any Unicode characters in Source contain non-zero value in
1831   the upper 8 bits, then ASSERT().
1832 
1833   If Source is not aligned on a 16-bit boundary, then ASSERT().
1834   If an error would be returned, then the function will also ASSERT().
1835 
1836   If an error is returned, then the Destination is unmodified.
1837 
1838   @param  Source        The pointer to a Null-terminated Unicode string.
1839   @param  Destination   The pointer to a Null-terminated ASCII string.
1840   @param  DestMax       The maximum number of Destination Ascii
1841                         char, including terminating null char.
1842 
1843   @retval RETURN_SUCCESS           String is converted.
1844   @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).
1845   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
1846                                    If Source is NULL.
1847                                    If PcdMaximumAsciiStringLength is not zero,
1848                                     and DestMax is greater than
1849                                     PcdMaximumAsciiStringLength.
1850                                    If PcdMaximumUnicodeStringLength is not zero,
1851                                     and DestMax is greater than
1852                                     PcdMaximumUnicodeStringLength.
1853                                    If DestMax is 0.
1854   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
1855 
1856 **/
1857 RETURN_STATUS
1858 EFIAPI
1859 UnicodeStrToAsciiStrS (
1860   IN      CONST CHAR16              *Source,
1861   OUT     CHAR8                     *Destination,
1862   IN      UINTN                     DestMax
1863   );
1864 
1865 /**
1866   Convert not more than Length successive characters from a Null-terminated
1867   Unicode string to a Null-terminated Ascii string. If no null char is copied
1868   from Source, then Destination[Length] is always set to null.
1869 
1870   This function converts not more than Length successive characters from the
1871   Unicode string Source to the Ascii string Destination by copying the lower 8
1872   bits of each Unicode character. The function terminates the Ascii string
1873   Destination by appending a Null-terminator character at the end.
1874 
1875   The caller is responsible to make sure Destination points to a buffer with size
1876   equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.
1877 
1878   If any Unicode characters in Source contain non-zero value in the upper 8
1879   bits, then ASSERT().
1880   If Source is not aligned on a 16-bit boundary, then ASSERT().
1881   If an error would be returned, then the function will also ASSERT().
1882 
1883   If an error is returned, then the Destination is unmodified.
1884 
1885   @param  Source             The pointer to a Null-terminated Unicode string.
1886   @param  Length             The maximum number of Unicode characters to
1887                              convert.
1888   @param  Destination        The pointer to a Null-terminated Ascii string.
1889   @param  DestMax            The maximum number of Destination Ascii
1890                              char, including terminating null char.
1891   @param  DestinationLength  The number of Unicode characters converted.
1892 
1893   @retval RETURN_SUCCESS            String is converted.
1894   @retval RETURN_INVALID_PARAMETER  If Destination is NULL.
1895                                     If Source is NULL.
1896                                     If DestinationLength is NULL.
1897                                     If PcdMaximumAsciiStringLength is not zero,
1898                                     and Length or DestMax is greater than
1899                                     PcdMaximumAsciiStringLength.
1900                                     If PcdMaximumUnicodeStringLength is not
1901                                     zero, and Length or DestMax is greater than
1902                                     PcdMaximumUnicodeStringLength.
1903                                     If DestMax is 0.
1904   @retval RETURN_BUFFER_TOO_SMALL   If DestMax is NOT greater than
1905                                     MIN(StrLen(Source), Length).
1906   @retval RETURN_ACCESS_DENIED      If Source and Destination overlap.
1907 
1908 **/
1909 RETURN_STATUS
1910 EFIAPI
1911 UnicodeStrnToAsciiStrS (
1912   IN      CONST CHAR16              *Source,
1913   IN      UINTN                     Length,
1914   OUT     CHAR8                     *Destination,
1915   IN      UINTN                     DestMax,
1916   OUT     UINTN                     *DestinationLength
1917   );
1918 
1919 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1920 
1921 /**
1922   [ATTENTION] This function is deprecated for security reason.
1923 
1924   Copies one Null-terminated ASCII string to another Null-terminated ASCII
1925   string and returns the new ASCII string.
1926 
1927   This function copies the contents of the ASCII string Source to the ASCII
1928   string Destination, and returns Destination. If Source and Destination
1929   overlap, then the results are undefined.
1930 
1931   If Destination is NULL, then ASSERT().
1932   If Source is NULL, then ASSERT().
1933   If Source and Destination overlap, then ASSERT().
1934   If PcdMaximumAsciiStringLength is not zero and Source contains more than
1935   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1936   then ASSERT().
1937 
1938   @param  Destination The pointer to a Null-terminated ASCII string.
1939   @param  Source      The pointer to a Null-terminated ASCII string.
1940 
1941   @return Destination
1942 
1943 **/
1944 CHAR8 *
1945 EFIAPI
1946 AsciiStrCpy (
1947   OUT     CHAR8                     *Destination,
1948   IN      CONST CHAR8               *Source
1949   );
1950 
1951 
1952 /**
1953   [ATTENTION] This function is deprecated for security reason.
1954 
1955   Copies up to a specified length one Null-terminated ASCII string to another
1956   Null-terminated ASCII string and returns the new ASCII string.
1957 
1958   This function copies the contents of the ASCII string Source to the ASCII
1959   string Destination, and returns Destination. At most, Length ASCII characters
1960   are copied from Source to Destination. If Length is 0, then Destination is
1961   returned unmodified. If Length is greater that the number of ASCII characters
1962   in Source, then Destination is padded with Null ASCII characters. If Source
1963   and Destination overlap, then the results are undefined.
1964 
1965   If Destination is NULL, then ASSERT().
1966   If Source is NULL, then ASSERT().
1967   If Source and Destination overlap, then ASSERT().
1968   If PcdMaximumAsciiStringLength is not zero, and Length is greater than
1969   PcdMaximumAsciiStringLength, then ASSERT().
1970   If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1971   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
1972   then ASSERT().
1973 
1974   @param  Destination The pointer to a Null-terminated ASCII string.
1975   @param  Source      The pointer to a Null-terminated ASCII string.
1976   @param  Length      The maximum number of ASCII characters to copy.
1977 
1978   @return Destination
1979 
1980 **/
1981 CHAR8 *
1982 EFIAPI
1983 AsciiStrnCpy (
1984   OUT     CHAR8                     *Destination,
1985   IN      CONST CHAR8               *Source,
1986   IN      UINTN                     Length
1987   );
1988 #endif
1989 
1990 /**
1991   Returns the length of a Null-terminated ASCII string.
1992 
1993   This function returns the number of ASCII characters in the Null-terminated
1994   ASCII string specified by String.
1995 
1996   If Length > 0 and Destination is NULL, then ASSERT().
1997   If Length > 0 and Source is NULL, then ASSERT().
1998   If PcdMaximumAsciiStringLength is not zero and String contains more than
1999   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2000   then ASSERT().
2001 
2002   @param  String  The pointer to a Null-terminated ASCII string.
2003 
2004   @return The length of String.
2005 
2006 **/
2007 UINTN
2008 EFIAPI
2009 AsciiStrLen (
2010   IN      CONST CHAR8               *String
2011   );
2012 
2013 
2014 /**
2015   Returns the size of a Null-terminated ASCII string in bytes, including the
2016   Null terminator.
2017 
2018   This function returns the size, in bytes, of the Null-terminated ASCII string
2019   specified by String.
2020 
2021   If String is NULL, then ASSERT().
2022   If PcdMaximumAsciiStringLength is not zero and String contains more than
2023   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2024   then ASSERT().
2025 
2026   @param  String  The pointer to a Null-terminated ASCII string.
2027 
2028   @return The size of String.
2029 
2030 **/
2031 UINTN
2032 EFIAPI
2033 AsciiStrSize (
2034   IN      CONST CHAR8               *String
2035   );
2036 
2037 
2038 /**
2039   Compares two Null-terminated ASCII strings, and returns the difference
2040   between the first mismatched ASCII characters.
2041 
2042   This function compares the Null-terminated ASCII string FirstString to the
2043   Null-terminated ASCII string SecondString. If FirstString is identical to
2044   SecondString, then 0 is returned. Otherwise, the value returned is the first
2045   mismatched ASCII character in SecondString subtracted from the first
2046   mismatched ASCII character in FirstString.
2047 
2048   If FirstString is NULL, then ASSERT().
2049   If SecondString is NULL, then ASSERT().
2050   If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
2051   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2052   then ASSERT().
2053   If PcdMaximumAsciiStringLength is not zero and SecondString contains more
2054   than PcdMaximumAsciiStringLength ASCII characters not including the
2055   Null-terminator, then ASSERT().
2056 
2057   @param  FirstString   The pointer to a Null-terminated ASCII string.
2058   @param  SecondString  The pointer to a Null-terminated ASCII string.
2059 
2060   @retval ==0      FirstString is identical to SecondString.
2061   @retval !=0      FirstString is not identical to SecondString.
2062 
2063 **/
2064 INTN
2065 EFIAPI
2066 AsciiStrCmp (
2067   IN      CONST CHAR8               *FirstString,
2068   IN      CONST CHAR8               *SecondString
2069   );
2070 
2071 
2072 /**
2073   Performs a case insensitive comparison of two Null-terminated ASCII strings,
2074   and returns the difference between the first mismatched ASCII characters.
2075 
2076   This function performs a case insensitive comparison of the Null-terminated
2077   ASCII string FirstString to the Null-terminated ASCII string SecondString. If
2078   FirstString is identical to SecondString, then 0 is returned. Otherwise, the
2079   value returned is the first mismatched lower case ASCII character in
2080   SecondString subtracted from the first mismatched lower case ASCII character
2081   in FirstString.
2082 
2083   If FirstString is NULL, then ASSERT().
2084   If SecondString is NULL, then ASSERT().
2085   If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
2086   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2087   then ASSERT().
2088   If PcdMaximumAsciiStringLength is not zero and SecondString contains more
2089   than PcdMaximumAsciiStringLength ASCII characters not including the
2090   Null-terminator, then ASSERT().
2091 
2092   @param  FirstString   The pointer to a Null-terminated ASCII string.
2093   @param  SecondString  The pointer to a Null-terminated ASCII string.
2094 
2095   @retval ==0    FirstString is identical to SecondString using case insensitive
2096                  comparisons.
2097   @retval !=0    FirstString is not identical to SecondString using case
2098                  insensitive comparisons.
2099 
2100 **/
2101 INTN
2102 EFIAPI
2103 AsciiStriCmp (
2104   IN      CONST CHAR8               *FirstString,
2105   IN      CONST CHAR8               *SecondString
2106   );
2107 
2108 
2109 /**
2110   Compares two Null-terminated ASCII strings with maximum lengths, and returns
2111   the difference between the first mismatched ASCII characters.
2112 
2113   This function compares the Null-terminated ASCII string FirstString to the
2114   Null-terminated ASCII  string SecondString. At most, Length ASCII characters
2115   will be compared. If Length is 0, then 0 is returned. If FirstString is
2116   identical to SecondString, then 0 is returned. Otherwise, the value returned
2117   is the first mismatched ASCII character in SecondString subtracted from the
2118   first mismatched ASCII character in FirstString.
2119 
2120   If Length > 0 and FirstString is NULL, then ASSERT().
2121   If Length > 0 and SecondString is NULL, then ASSERT().
2122   If PcdMaximumAsciiStringLength is not zero, and Length is greater than
2123   PcdMaximumAsciiStringLength, then ASSERT().
2124   If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than
2125   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
2126   then ASSERT().
2127   If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than
2128   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
2129   then ASSERT().
2130 
2131   @param  FirstString   The pointer to a Null-terminated ASCII string.
2132   @param  SecondString  The pointer to a Null-terminated ASCII string.
2133   @param  Length        The maximum number of ASCII characters for compare.
2134 
2135   @retval ==0       FirstString is identical to SecondString.
2136   @retval !=0       FirstString is not identical to SecondString.
2137 
2138 **/
2139 INTN
2140 EFIAPI
2141 AsciiStrnCmp (
2142   IN      CONST CHAR8               *FirstString,
2143   IN      CONST CHAR8               *SecondString,
2144   IN      UINTN                     Length
2145   );
2146 
2147 
2148 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
2149 
2150 /**
2151   [ATTENTION] This function is deprecated for security reason.
2152 
2153   Concatenates one Null-terminated ASCII string to another Null-terminated
2154   ASCII string, and returns the concatenated ASCII string.
2155 
2156   This function concatenates two Null-terminated ASCII strings. The contents of
2157   Null-terminated ASCII string Source are concatenated to the end of Null-
2158   terminated ASCII string Destination. The Null-terminated concatenated ASCII
2159   String is returned.
2160 
2161   If Destination is NULL, then ASSERT().
2162   If Source is NULL, then ASSERT().
2163   If PcdMaximumAsciiStringLength is not zero and Destination contains more than
2164   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2165   then ASSERT().
2166   If PcdMaximumAsciiStringLength is not zero and Source contains more than
2167   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2168   then ASSERT().
2169   If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
2170   Source results in a ASCII string with more than PcdMaximumAsciiStringLength
2171   ASCII characters, then ASSERT().
2172 
2173   @param  Destination The pointer to a Null-terminated ASCII string.
2174   @param  Source      The pointer to a Null-terminated ASCII string.
2175 
2176   @return Destination
2177 
2178 **/
2179 CHAR8 *
2180 EFIAPI
2181 AsciiStrCat (
2182   IN OUT CHAR8    *Destination,
2183   IN CONST CHAR8  *Source
2184   );
2185 
2186 
2187 /**
2188   [ATTENTION] This function is deprecated for security reason.
2189 
2190   Concatenates up to a specified length one Null-terminated ASCII string to
2191   the end of another Null-terminated ASCII string, and returns the
2192   concatenated ASCII string.
2193 
2194   This function concatenates two Null-terminated ASCII strings. The contents
2195   of Null-terminated ASCII string Source are concatenated to the end of Null-
2196   terminated ASCII string Destination, and Destination is returned. At most,
2197   Length ASCII characters are concatenated from Source to the end of
2198   Destination, and Destination is always Null-terminated. If Length is 0, then
2199   Destination is returned unmodified. If Source and Destination overlap, then
2200   the results are undefined.
2201 
2202   If Length > 0 and Destination is NULL, then ASSERT().
2203   If Length > 0 and Source is NULL, then ASSERT().
2204   If Source and Destination overlap, then ASSERT().
2205   If PcdMaximumAsciiStringLength is not zero, and Length is greater than
2206   PcdMaximumAsciiStringLength, then ASSERT().
2207   If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
2208   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
2209   then ASSERT().
2210   If PcdMaximumAsciiStringLength is not zero, and Source contains more than
2211   PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,
2212   then ASSERT().
2213   If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
2214   Source results in a ASCII string with more than PcdMaximumAsciiStringLength
2215   ASCII characters, not including the Null-terminator, then ASSERT().
2216 
2217   @param  Destination The pointer to a Null-terminated ASCII string.
2218   @param  Source      The pointer to a Null-terminated ASCII string.
2219   @param  Length      The maximum number of ASCII characters to concatenate from
2220                       Source.
2221 
2222   @return Destination
2223 
2224 **/
2225 CHAR8 *
2226 EFIAPI
2227 AsciiStrnCat (
2228   IN OUT  CHAR8                     *Destination,
2229   IN      CONST CHAR8               *Source,
2230   IN      UINTN                     Length
2231   );
2232 #endif
2233 
2234 /**
2235   Returns the first occurrence of a Null-terminated ASCII sub-string
2236   in a Null-terminated ASCII string.
2237 
2238   This function scans the contents of the ASCII string specified by String
2239   and returns the first occurrence of SearchString. If SearchString is not
2240   found in String, then NULL is returned. If the length of SearchString is zero,
2241   then String is returned.
2242 
2243   If String is NULL, then ASSERT().
2244   If SearchString is NULL, then ASSERT().
2245 
2246   If PcdMaximumAsciiStringLength is not zero, and SearchString or
2247   String contains more than PcdMaximumAsciiStringLength Unicode characters
2248   not including the Null-terminator, then ASSERT().
2249 
2250   @param  String          The pointer to a Null-terminated ASCII string.
2251   @param  SearchString    The pointer to a Null-terminated ASCII string to search for.
2252 
2253   @retval NULL            If the SearchString does not appear in String.
2254   @retval others          If there is a match return the first occurrence of SearchingString.
2255                           If the length of SearchString is zero,return String.
2256 
2257 **/
2258 CHAR8 *
2259 EFIAPI
2260 AsciiStrStr (
2261   IN      CONST CHAR8               *String,
2262   IN      CONST CHAR8               *SearchString
2263   );
2264 
2265 
2266 /**
2267   Convert a Null-terminated ASCII decimal string to a value of type
2268   UINTN.
2269 
2270   This function returns a value of type UINTN by interpreting the contents
2271   of the ASCII string String as a decimal number. The format of the input
2272   ASCII string String is:
2273 
2274                     [spaces] [decimal digits].
2275 
2276   The valid decimal digit character is in the range [0-9]. The function will
2277   ignore the pad space, which includes spaces or tab characters, before the digits.
2278   The running zero in the beginning of [decimal digits] will be ignored. Then, the
2279   function stops at the first character that is a not a valid decimal character or
2280   Null-terminator, whichever on comes first.
2281 
2282   If String has only pad spaces, then 0 is returned.
2283   If String has no pad spaces or valid decimal digits, then 0 is returned.
2284   If the number represented by String overflows according to the range defined by
2285   UINTN, then MAX_UINTN is returned.
2286   If String is NULL, then ASSERT().
2287   If PcdMaximumAsciiStringLength is not zero, and String contains more than
2288   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2289   then ASSERT().
2290 
2291   @param  String          The pointer to a Null-terminated ASCII string.
2292 
2293   @retval The value translated from String.
2294 
2295 **/
2296 UINTN
2297 EFIAPI
2298 AsciiStrDecimalToUintn (
2299   IN      CONST CHAR8               *String
2300   );
2301 
2302 
2303 /**
2304   Convert a Null-terminated ASCII decimal string to a value of type
2305   UINT64.
2306 
2307   This function returns a value of type UINT64 by interpreting the contents
2308   of the ASCII string String as a decimal number. The format of the input
2309   ASCII string String is:
2310 
2311                     [spaces] [decimal digits].
2312 
2313   The valid decimal digit character is in the range [0-9]. The function will
2314   ignore the pad space, which includes spaces or tab characters, before the digits.
2315   The running zero in the beginning of [decimal digits] will be ignored. Then, the
2316   function stops at the first character that is a not a valid decimal character or
2317   Null-terminator, whichever on comes first.
2318 
2319   If String has only pad spaces, then 0 is returned.
2320   If String has no pad spaces or valid decimal digits, then 0 is returned.
2321   If the number represented by String overflows according to the range defined by
2322   UINT64, then MAX_UINT64 is returned.
2323   If String is NULL, then ASSERT().
2324   If PcdMaximumAsciiStringLength is not zero, and String contains more than
2325   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2326   then ASSERT().
2327 
2328   @param  String          The pointer to a Null-terminated ASCII string.
2329 
2330   @retval Value translated from String.
2331 
2332 **/
2333 UINT64
2334 EFIAPI
2335 AsciiStrDecimalToUint64 (
2336   IN      CONST CHAR8               *String
2337   );
2338 
2339 
2340 /**
2341   Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
2342 
2343   This function returns a value of type UINTN by interpreting the contents of
2344   the ASCII string String as a hexadecimal number. The format of the input ASCII
2345   string String is:
2346 
2347                   [spaces][zeros][x][hexadecimal digits].
2348 
2349   The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
2350   The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
2351   appears in the input string, it must be prefixed with at least one 0. The function
2352   will ignore the pad space, which includes spaces or tab characters, before [zeros],
2353   [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
2354   will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
2355   digit. Then, the function stops at the first character that is a not a valid
2356   hexadecimal character or Null-terminator, whichever on comes first.
2357 
2358   If String has only pad spaces, then 0 is returned.
2359   If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
2360   0 is returned.
2361 
2362   If the number represented by String overflows according to the range defined by UINTN,
2363   then MAX_UINTN is returned.
2364   If String is NULL, then ASSERT().
2365   If PcdMaximumAsciiStringLength is not zero,
2366   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
2367   the Null-terminator, then ASSERT().
2368 
2369   @param  String          The pointer to a Null-terminated ASCII string.
2370 
2371   @retval Value translated from String.
2372 
2373 **/
2374 UINTN
2375 EFIAPI
2376 AsciiStrHexToUintn (
2377   IN      CONST CHAR8               *String
2378   );
2379 
2380 
2381 /**
2382   Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
2383 
2384   This function returns a value of type UINT64 by interpreting the contents of
2385   the ASCII string String as a hexadecimal number. The format of the input ASCII
2386   string String is:
2387 
2388                   [spaces][zeros][x][hexadecimal digits].
2389 
2390   The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
2391   The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
2392   appears in the input string, it must be prefixed with at least one 0. The function
2393   will ignore the pad space, which includes spaces or tab characters, before [zeros],
2394   [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
2395   will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
2396   digit. Then, the function stops at the first character that is a not a valid
2397   hexadecimal character or Null-terminator, whichever on comes first.
2398 
2399   If String has only pad spaces, then 0 is returned.
2400   If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
2401   0 is returned.
2402 
2403   If the number represented by String overflows according to the range defined by UINT64,
2404   then MAX_UINT64 is returned.
2405   If String is NULL, then ASSERT().
2406   If PcdMaximumAsciiStringLength is not zero,
2407   and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
2408   the Null-terminator, then ASSERT().
2409 
2410   @param  String          The pointer to a Null-terminated ASCII string.
2411 
2412   @retval Value translated from String.
2413 
2414 **/
2415 UINT64
2416 EFIAPI
2417 AsciiStrHexToUint64 (
2418   IN      CONST CHAR8                *String
2419   );
2420 
2421 /**
2422   Convert a Null-terminated ASCII string to IPv6 address and prefix length.
2423 
2424   This function outputs a value of type IPv6_ADDRESS and may output a value
2425   of type UINT8 by interpreting the contents of the ASCII string specified
2426   by String. The format of the input ASCII string String is as follows:
2427 
2428                   X:X:X:X:X:X:X:X[/P]
2429 
2430   X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and
2431   [A-F]. X is converted to a value of type UINT16, whose low byte is stored in low
2432   memory address and high byte is stored in high memory address. P contains decimal
2433   digit characters in the range [0-9]. The running zero in the beginning of P will
2434   be ignored. /P is optional.
2435 
2436   When /P is not in the String, the function stops at the first character that is
2437   not a valid hexadecimal digit character after eight X's are converted.
2438 
2439   When /P is in the String, the function stops at the first character that is not
2440   a valid decimal digit character after P is converted.
2441 
2442   "::" can be used to compress one or more groups of X when X contains only 0.
2443   The "::" can only appear once in the String.
2444 
2445   If String is NULL, then ASSERT().
2446 
2447   If Address is NULL, then ASSERT().
2448 
2449   If EndPointer is not NULL and Address is translated from String, a pointer
2450   to the character that stopped the scan is stored at the location pointed to
2451   by EndPointer.
2452 
2453   @param  String                   Pointer to a Null-terminated ASCII string.
2454   @param  EndPointer               Pointer to character that stops scan.
2455   @param  Address                  Pointer to the converted IPv6 address.
2456   @param  PrefixLength             Pointer to the converted IPv6 address prefix
2457                                    length. MAX_UINT8 is returned when /P is
2458                                    not in the String.
2459 
2460   @retval RETURN_SUCCESS           Address is translated from String.
2461   @retval RETURN_INVALID_PARAMETER If String is NULL.
2462                                    If Data is NULL.
2463   @retval RETURN_UNSUPPORTED       If X contains more than four hexadecimal
2464                                     digit characters.
2465                                    If String contains "::" and number of X
2466                                     is not less than 8.
2467                                    If P starts with character that is not a
2468                                     valid decimal digit character.
2469                                    If the decimal number converted from P
2470                                     exceeds 128.
2471 
2472 **/
2473 RETURN_STATUS
2474 EFIAPI
2475 AsciiStrToIpv6Address (
2476   IN  CONST CHAR8        *String,
2477   OUT CHAR8              **EndPointer, OPTIONAL
2478   OUT IPv6_ADDRESS       *Address,
2479   OUT UINT8              *PrefixLength OPTIONAL
2480   );
2481 
2482 /**
2483   Convert a Null-terminated ASCII string to IPv4 address and prefix length.
2484 
2485   This function outputs a value of type IPv4_ADDRESS and may output a value
2486   of type UINT8 by interpreting the contents of the ASCII string specified
2487   by String. The format of the input ASCII string String is as follows:
2488 
2489                   D.D.D.D[/P]
2490 
2491   D and P are decimal digit characters in the range [0-9]. The running zero in
2492   the beginning of D and P will be ignored. /P is optional.
2493 
2494   When /P is not in the String, the function stops at the first character that is
2495   not a valid decimal digit character after four D's are converted.
2496 
2497   When /P is in the String, the function stops at the first character that is not
2498   a valid decimal digit character after P is converted.
2499 
2500   If String is NULL, then ASSERT().
2501 
2502   If Address is NULL, then ASSERT().
2503 
2504   If EndPointer is not NULL and Address is translated from String, a pointer
2505   to the character that stopped the scan is stored at the location pointed to
2506   by EndPointer.
2507 
2508   @param  String                   Pointer to a Null-terminated ASCII string.
2509   @param  EndPointer               Pointer to character that stops scan.
2510   @param  Address                  Pointer to the converted IPv4 address.
2511   @param  PrefixLength             Pointer to the converted IPv4 address prefix
2512                                    length. MAX_UINT8 is returned when /P is
2513                                    not in the String.
2514 
2515   @retval RETURN_SUCCESS           Address is translated from String.
2516   @retval RETURN_INVALID_PARAMETER If String is NULL.
2517                                    If Data is NULL.
2518   @retval RETURN_UNSUPPORTED       If String is not in the correct format.
2519                                    If any decimal number converted from D
2520                                     exceeds 255.
2521                                    If the decimal number converted from P
2522                                     exceeds 32.
2523 
2524 **/
2525 RETURN_STATUS
2526 EFIAPI
2527 AsciiStrToIpv4Address (
2528   IN  CONST CHAR8        *String,
2529   OUT CHAR8              **EndPointer, OPTIONAL
2530   OUT IPv4_ADDRESS       *Address,
2531   OUT UINT8              *PrefixLength OPTIONAL
2532   );
2533 
2534 /**
2535   Convert a Null-terminated ASCII GUID string to a value of type
2536   EFI_GUID.
2537 
2538   This function outputs a GUID value by interpreting the contents of
2539   the ASCII string specified by String. The format of the input
2540   ASCII string String consists of 36 characters, as follows:
2541 
2542                   aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
2543 
2544   The pairs aa - pp are two characters in the range [0-9], [a-f] and
2545   [A-F], with each pair representing a single byte hexadecimal value.
2546 
2547   The mapping between String and the EFI_GUID structure is as follows:
2548                   aa          Data1[24:31]
2549                   bb          Data1[16:23]
2550                   cc          Data1[8:15]
2551                   dd          Data1[0:7]
2552                   ee          Data2[8:15]
2553                   ff          Data2[0:7]
2554                   gg          Data3[8:15]
2555                   hh          Data3[0:7]
2556                   ii          Data4[0:7]
2557                   jj          Data4[8:15]
2558                   kk          Data4[16:23]
2559                   ll          Data4[24:31]
2560                   mm          Data4[32:39]
2561                   nn          Data4[40:47]
2562                   oo          Data4[48:55]
2563                   pp          Data4[56:63]
2564 
2565   If String is NULL, then ASSERT().
2566   If Guid is NULL, then ASSERT().
2567 
2568   @param  String                   Pointer to a Null-terminated ASCII string.
2569   @param  Guid                     Pointer to the converted GUID.
2570 
2571   @retval RETURN_SUCCESS           Guid is translated from String.
2572   @retval RETURN_INVALID_PARAMETER If String is NULL.
2573                                    If Data is NULL.
2574   @retval RETURN_UNSUPPORTED       If String is not as the above format.
2575 
2576 **/
2577 RETURN_STATUS
2578 EFIAPI
2579 AsciiStrToGuid (
2580   IN  CONST CHAR8        *String,
2581   OUT GUID               *Guid
2582   );
2583 
2584 /**
2585   Convert a Null-terminated ASCII hexadecimal string to a byte array.
2586 
2587   This function outputs a byte array by interpreting the contents of
2588   the ASCII string specified by String in hexadecimal format. The format of
2589   the input ASCII string String is:
2590 
2591                   [XX]*
2592 
2593   X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].
2594   The function decodes every two hexadecimal digit characters as one byte. The
2595   decoding stops after Length of characters and outputs Buffer containing
2596   (Length / 2) bytes.
2597 
2598   If String is NULL, then ASSERT().
2599 
2600   If Buffer is NULL, then ASSERT().
2601 
2602   If Length is not multiple of 2, then ASSERT().
2603 
2604   If PcdMaximumAsciiStringLength is not zero and Length is greater than
2605   PcdMaximumAsciiStringLength, then ASSERT().
2606 
2607   If MaxBufferSize is less than (Length / 2), then ASSERT().
2608 
2609   @param  String                   Pointer to a Null-terminated ASCII string.
2610   @param  Length                   The number of ASCII characters to decode.
2611   @param  Buffer                   Pointer to the converted bytes array.
2612   @param  MaxBufferSize            The maximum size of Buffer.
2613 
2614   @retval RETURN_SUCCESS           Buffer is translated from String.
2615   @retval RETURN_INVALID_PARAMETER If String is NULL.
2616                                    If Data is NULL.
2617                                    If Length is not multiple of 2.
2618                                    If PcdMaximumAsciiStringLength is not zero,
2619                                     and Length is greater than
2620                                     PcdMaximumAsciiStringLength.
2621   @retval RETURN_UNSUPPORTED       If Length of characters from String contain
2622                                     a character that is not valid hexadecimal
2623                                     digit characters, or a Null-terminator.
2624   @retval RETURN_BUFFER_TOO_SMALL  If MaxBufferSize is less than (Length / 2).
2625 **/
2626 RETURN_STATUS
2627 EFIAPI
2628 AsciiStrHexToBytes (
2629   IN  CONST CHAR8        *String,
2630   IN  UINTN              Length,
2631   OUT UINT8              *Buffer,
2632   IN  UINTN              MaxBufferSize
2633   );
2634 
2635 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
2636 
2637 /**
2638   [ATTENTION] This function is deprecated for security reason.
2639 
2640   Convert one Null-terminated ASCII string to a Null-terminated
2641   Unicode string and returns the Unicode string.
2642 
2643   This function converts the contents of the ASCII string Source to the Unicode
2644   string Destination, and returns Destination.  The function terminates the
2645   Unicode string Destination by appending a Null-terminator character at the end.
2646   The caller is responsible to make sure Destination points to a buffer with size
2647   equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
2648 
2649   If Destination is NULL, then ASSERT().
2650   If Destination is not aligned on a 16-bit boundary, then ASSERT().
2651   If Source is NULL, then ASSERT().
2652   If Source and Destination overlap, then ASSERT().
2653   If PcdMaximumAsciiStringLength is not zero, and Source contains more than
2654   PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
2655   then ASSERT().
2656   If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
2657   PcdMaximumUnicodeStringLength ASCII characters not including the
2658   Null-terminator, then ASSERT().
2659 
2660   @param  Source        The pointer to a Null-terminated ASCII string.
2661   @param  Destination   The pointer to a Null-terminated Unicode string.
2662 
2663   @return Destination.
2664 
2665 **/
2666 CHAR16 *
2667 EFIAPI
2668 AsciiStrToUnicodeStr (
2669   IN      CONST CHAR8               *Source,
2670   OUT     CHAR16                    *Destination
2671   );
2672 
2673 #endif
2674 
2675 /**
2676   Convert one Null-terminated ASCII string to a Null-terminated
2677   Unicode string.
2678 
2679   This function is similar to StrCpyS.
2680 
2681   This function converts the contents of the ASCII string Source to the Unicode
2682   string Destination. The function terminates the Unicode string Destination by
2683   appending a Null-terminator character at the end.
2684 
2685   The caller is responsible to make sure Destination points to a buffer with size
2686   equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
2687 
2688   If Destination is not aligned on a 16-bit boundary, then ASSERT().
2689   If an error would be returned, then the function will also ASSERT().
2690 
2691   If an error is returned, then the Destination is unmodified.
2692 
2693   @param  Source        The pointer to a Null-terminated ASCII string.
2694   @param  Destination   The pointer to a Null-terminated Unicode string.
2695   @param  DestMax       The maximum number of Destination Unicode
2696                         char, including terminating null char.
2697 
2698   @retval RETURN_SUCCESS           String is converted.
2699   @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than StrLen(Source).
2700   @retval RETURN_INVALID_PARAMETER If Destination is NULL.
2701                                    If Source is NULL.
2702                                    If PcdMaximumUnicodeStringLength is not zero,
2703                                     and DestMax is greater than
2704                                     PcdMaximumUnicodeStringLength.
2705                                    If PcdMaximumAsciiStringLength is not zero,
2706                                     and DestMax is greater than
2707                                     PcdMaximumAsciiStringLength.
2708                                    If DestMax is 0.
2709   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.
2710 
2711 **/
2712 RETURN_STATUS
2713 EFIAPI
2714 AsciiStrToUnicodeStrS (
2715   IN      CONST CHAR8               *Source,
2716   OUT     CHAR16                    *Destination,
2717   IN      UINTN                     DestMax
2718   );
2719 
2720 /**
2721   Convert not more than Length successive characters from a Null-terminated
2722   Ascii string to a Null-terminated Unicode string. If no null char is copied
2723   from Source, then Destination[Length] is always set to null.
2724 
2725   This function converts not more than Length successive characters from the
2726   Ascii string Source to the Unicode string Destination. The function
2727   terminates the Unicode string Destination by appending a Null-terminator
2728   character at the end.
2729 
2730   The caller is responsible to make sure Destination points to a buffer with
2731   size not smaller than
2732   ((MIN(AsciiStrLen(Source), Length) + 1) * sizeof (CHAR8)) in bytes.
2733 
2734   If Destination is not aligned on a 16-bit boundary, then ASSERT().
2735   If an error would be returned, then the function will also ASSERT().
2736 
2737   If an error is returned, then Destination and DestinationLength are
2738   unmodified.
2739 
2740   @param  Source             The pointer to a Null-terminated Ascii string.
2741   @param  Length             The maximum number of Ascii characters to convert.
2742   @param  Destination        The pointer to a Null-terminated Unicode string.
2743   @param  DestMax            The maximum number of Destination Unicode char,
2744                              including terminating null char.
2745   @param  DestinationLength  The number of Ascii characters converted.
2746 
2747   @retval RETURN_SUCCESS            String is converted.
2748   @retval RETURN_INVALID_PARAMETER  If Destination is NULL.
2749                                     If Source is NULL.
2750                                     If DestinationLength is NULL.
2751                                     If PcdMaximumUnicodeStringLength is not
2752                                     zero, and Length or DestMax is greater than
2753                                     PcdMaximumUnicodeStringLength.
2754                                     If PcdMaximumAsciiStringLength is not zero,
2755                                     and Length or DestMax is greater than
2756                                     PcdMaximumAsciiStringLength.
2757                                     If DestMax is 0.
2758   @retval RETURN_BUFFER_TOO_SMALL   If DestMax is NOT greater than
2759                                     MIN(AsciiStrLen(Source), Length).
2760   @retval RETURN_ACCESS_DENIED      If Source and Destination overlap.
2761 
2762 **/
2763 RETURN_STATUS
2764 EFIAPI
2765 AsciiStrnToUnicodeStrS (
2766   IN      CONST CHAR8               *Source,
2767   IN      UINTN                     Length,
2768   OUT     CHAR16                    *Destination,
2769   IN      UINTN                     DestMax,
2770   OUT     UINTN                     *DestinationLength
2771   );
2772 
2773 /**
2774   Converts an 8-bit value to an 8-bit BCD value.
2775 
2776   Converts the 8-bit value specified by Value to BCD. The BCD value is
2777   returned.
2778 
2779   If Value >= 100, then ASSERT().
2780 
2781   @param  Value The 8-bit value to convert to BCD. Range 0..99.
2782 
2783   @return The BCD value.
2784 
2785 **/
2786 UINT8
2787 EFIAPI
2788 DecimalToBcd8 (
2789   IN      UINT8                     Value
2790   );
2791 
2792 
2793 /**
2794   Converts an 8-bit BCD value to an 8-bit value.
2795 
2796   Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
2797   value is returned.
2798 
2799   If Value >= 0xA0, then ASSERT().
2800   If (Value & 0x0F) >= 0x0A, then ASSERT().
2801 
2802   @param  Value The 8-bit BCD value to convert to an 8-bit value.
2803 
2804   @return The 8-bit value is returned.
2805 
2806 **/
2807 UINT8
2808 EFIAPI
2809 BcdToDecimal8 (
2810   IN      UINT8                     Value
2811   );
2812 
2813 //
2814 //  File Path Manipulation Functions
2815 //
2816 
2817 /**
2818   Removes the last directory or file entry in a path.
2819 
2820   @param[in, out] Path    The pointer to the path to modify.
2821 
2822   @retval FALSE     Nothing was found to remove.
2823   @retval TRUE      A directory or file was removed.
2824 **/
2825 BOOLEAN
2826 EFIAPI
2827 PathRemoveLastItem(
2828   IN OUT CHAR16 *Path
2829   );
2830 
2831 /**
2832   Function to clean up paths.
2833     - Single periods in the path are removed.
2834     - Double periods in the path are removed along with a single parent directory.
2835     - Forward slashes L'/' are converted to backward slashes L'\'.
2836 
2837   This will be done inline and the existing buffer may be larger than required
2838   upon completion.
2839 
2840   @param[in] Path       The pointer to the string containing the path.
2841 
2842   @return       Returns Path, otherwise returns NULL to indicate that an error has occurred.
2843 **/
2844 CHAR16*
2845 EFIAPI
2846 PathCleanUpDirectories(
2847   IN CHAR16 *Path
2848   );
2849 
2850 //
2851 // Linked List Functions and Macros
2852 //
2853 
2854 /**
2855   Initializes the head node of a doubly linked list that is declared as a
2856   global variable in a module.
2857 
2858   Initializes the forward and backward links of a new linked list. After
2859   initializing a linked list with this macro, the other linked list functions
2860   may be used to add and remove nodes from the linked list. This macro results
2861   in smaller executables by initializing the linked list in the data section,
2862   instead if calling the InitializeListHead() function to perform the
2863   equivalent operation.
2864 
2865   @param  ListHead  The head note of a list to initialize.
2866 
2867 **/
2868 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)  {&(ListHead), &(ListHead)}
2869 
2870 
2871 /**
2872   Initializes the head node of a doubly linked list, and returns the pointer to
2873   the head node of the doubly linked list.
2874 
2875   Initializes the forward and backward links of a new linked list. After
2876   initializing a linked list with this function, the other linked list
2877   functions may be used to add and remove nodes from the linked list. It is up
2878   to the caller of this function to allocate the memory for ListHead.
2879 
2880   If ListHead is NULL, then ASSERT().
2881 
2882   @param  ListHead  A pointer to the head node of a new doubly linked list.
2883 
2884   @return ListHead
2885 
2886 **/
2887 LIST_ENTRY *
2888 EFIAPI
2889 InitializeListHead (
2890   IN OUT  LIST_ENTRY                *ListHead
2891   );
2892 
2893 
2894 /**
2895   Adds a node to the beginning of a doubly linked list, and returns the pointer
2896   to the head node of the doubly linked list.
2897 
2898   Adds the node Entry at the beginning of the doubly linked list denoted by
2899   ListHead, and returns ListHead.
2900 
2901   If ListHead is NULL, then ASSERT().
2902   If Entry is NULL, then ASSERT().
2903   If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
2904   InitializeListHead(), then ASSERT().
2905   If PcdMaximumLinkedListLength is not zero, and prior to insertion the number
2906   of nodes in ListHead, including the ListHead node, is greater than or
2907   equal to PcdMaximumLinkedListLength, then ASSERT().
2908 
2909   @param  ListHead  A pointer to the head node of a doubly linked list.
2910   @param  Entry     A pointer to a node that is to be inserted at the beginning
2911                     of a doubly linked list.
2912 
2913   @return ListHead
2914 
2915 **/
2916 LIST_ENTRY *
2917 EFIAPI
2918 InsertHeadList (
2919   IN OUT  LIST_ENTRY                *ListHead,
2920   IN OUT  LIST_ENTRY                *Entry
2921   );
2922 
2923 
2924 /**
2925   Adds a node to the end of a doubly linked list, and returns the pointer to
2926   the head node of the doubly linked list.
2927 
2928   Adds the node Entry to the end of the doubly linked list denoted by ListHead,
2929   and returns ListHead.
2930 
2931   If ListHead is NULL, then ASSERT().
2932   If Entry is NULL, then ASSERT().
2933   If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
2934   InitializeListHead(), then ASSERT().
2935   If PcdMaximumLinkedListLength is not zero, and prior to insertion the number
2936   of nodes in ListHead, including the ListHead node, is greater than or
2937   equal to PcdMaximumLinkedListLength, then ASSERT().
2938 
2939   @param  ListHead  A pointer to the head node of a doubly linked list.
2940   @param  Entry     A pointer to a node that is to be added at the end of the
2941                     doubly linked list.
2942 
2943   @return ListHead
2944 
2945 **/
2946 LIST_ENTRY *
2947 EFIAPI
2948 InsertTailList (
2949   IN OUT  LIST_ENTRY                *ListHead,
2950   IN OUT  LIST_ENTRY                *Entry
2951   );
2952 
2953 
2954 /**
2955   Retrieves the first node of a doubly linked list.
2956 
2957   Returns the first node of a doubly linked list.  List must have been
2958   initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
2959   If List is empty, then List is returned.
2960 
2961   If List is NULL, then ASSERT().
2962   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
2963   InitializeListHead(), then ASSERT().
2964   If PcdMaximumLinkedListLength is not zero, and the number of nodes
2965   in List, including the List node, is greater than or equal to
2966   PcdMaximumLinkedListLength, then ASSERT().
2967 
2968   @param  List  A pointer to the head node of a doubly linked list.
2969 
2970   @return The first node of a doubly linked list.
2971   @retval List  The list is empty.
2972 
2973 **/
2974 LIST_ENTRY *
2975 EFIAPI
2976 GetFirstNode (
2977   IN      CONST LIST_ENTRY          *List
2978   );
2979 
2980 
2981 /**
2982   Retrieves the next node of a doubly linked list.
2983 
2984   Returns the node of a doubly linked list that follows Node.
2985   List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()
2986   or InitializeListHead().  If List is empty, then List is returned.
2987 
2988   If List is NULL, then ASSERT().
2989   If Node is NULL, then ASSERT().
2990   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
2991   InitializeListHead(), then ASSERT().
2992   If PcdMaximumLinkedListLength is not zero, and List contains more than
2993   PcdMaximumLinkedListLength nodes, then ASSERT().
2994   If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
2995 
2996   @param  List  A pointer to the head node of a doubly linked list.
2997   @param  Node  A pointer to a node in the doubly linked list.
2998 
2999   @return The pointer to the next node if one exists. Otherwise List is returned.
3000 
3001 **/
3002 LIST_ENTRY *
3003 EFIAPI
3004 GetNextNode (
3005   IN      CONST LIST_ENTRY          *List,
3006   IN      CONST LIST_ENTRY          *Node
3007   );
3008 
3009 
3010 /**
3011   Retrieves the previous node of a doubly linked list.
3012 
3013   Returns the node of a doubly linked list that precedes Node.
3014   List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()
3015   or InitializeListHead().  If List is empty, then List is returned.
3016 
3017   If List is NULL, then ASSERT().
3018   If Node is NULL, then ASSERT().
3019   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
3020   InitializeListHead(), then ASSERT().
3021   If PcdMaximumLinkedListLength is not zero, and List contains more than
3022   PcdMaximumLinkedListLength nodes, then ASSERT().
3023   If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
3024 
3025   @param  List  A pointer to the head node of a doubly linked list.
3026   @param  Node  A pointer to a node in the doubly linked list.
3027 
3028   @return The pointer to the previous node if one exists. Otherwise List is returned.
3029 
3030 **/
3031 LIST_ENTRY *
3032 EFIAPI
3033 GetPreviousNode (
3034   IN      CONST LIST_ENTRY          *List,
3035   IN      CONST LIST_ENTRY          *Node
3036   );
3037 
3038 
3039 /**
3040   Checks to see if a doubly linked list is empty or not.
3041 
3042   Checks to see if the doubly linked list is empty. If the linked list contains
3043   zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
3044 
3045   If ListHead is NULL, then ASSERT().
3046   If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
3047   InitializeListHead(), then ASSERT().
3048   If PcdMaximumLinkedListLength is not zero, and the number of nodes
3049   in List, including the List node, is greater than or equal to
3050   PcdMaximumLinkedListLength, then ASSERT().
3051 
3052   @param  ListHead  A pointer to the head node of a doubly linked list.
3053 
3054   @retval TRUE  The linked list is empty.
3055   @retval FALSE The linked list is not empty.
3056 
3057 **/
3058 BOOLEAN
3059 EFIAPI
3060 IsListEmpty (
3061   IN      CONST LIST_ENTRY          *ListHead
3062   );
3063 
3064 
3065 /**
3066   Determines if a node in a doubly linked list is the head node of a the same
3067   doubly linked list.  This function is typically used to terminate a loop that
3068   traverses all the nodes in a doubly linked list starting with the head node.
3069 
3070   Returns TRUE if Node is equal to List.  Returns FALSE if Node is one of the
3071   nodes in the doubly linked list specified by List.  List must have been
3072   initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
3073 
3074   If List is NULL, then ASSERT().
3075   If Node is NULL, then ASSERT().
3076   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(),
3077   then ASSERT().
3078   If PcdMaximumLinkedListLength is not zero, and the number of nodes
3079   in List, including the List node, is greater than or equal to
3080   PcdMaximumLinkedListLength, then ASSERT().
3081   If PcdVerifyNodeInList is TRUE and Node is not a node in List the and Node is not equal
3082   to List, then ASSERT().
3083 
3084   @param  List  A pointer to the head node of a doubly linked list.
3085   @param  Node  A pointer to a node in the doubly linked list.
3086 
3087   @retval TRUE  Node is the head of the doubly-linked list pointed by List.
3088   @retval FALSE Node is not the head of the doubly-linked list pointed by List.
3089 
3090 **/
3091 BOOLEAN
3092 EFIAPI
3093 IsNull (
3094   IN      CONST LIST_ENTRY          *List,
3095   IN      CONST LIST_ENTRY          *Node
3096   );
3097 
3098 
3099 /**
3100   Determines if a node the last node in a doubly linked list.
3101 
3102   Returns TRUE if Node is the last node in the doubly linked list specified by
3103   List. Otherwise, FALSE is returned. List must have been initialized with
3104   INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
3105 
3106   If List is NULL, then ASSERT().
3107   If Node is NULL, then ASSERT().
3108   If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or
3109   InitializeListHead(), then ASSERT().
3110   If PcdMaximumLinkedListLength is not zero, and the number of nodes
3111   in List, including the List node, is greater than or equal to
3112   PcdMaximumLinkedListLength, then ASSERT().
3113   If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().
3114 
3115   @param  List  A pointer to the head node of a doubly linked list.
3116   @param  Node  A pointer to a node in the doubly linked list.
3117 
3118   @retval TRUE  Node is the last node in the linked list.
3119   @retval FALSE Node is not the last node in the linked list.
3120 
3121 **/
3122 BOOLEAN
3123 EFIAPI
3124 IsNodeAtEnd (
3125   IN      CONST LIST_ENTRY          *List,
3126   IN      CONST LIST_ENTRY          *Node
3127   );
3128 
3129 
3130 /**
3131   Swaps the location of two nodes in a doubly linked list, and returns the
3132   first node after the swap.
3133 
3134   If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
3135   Otherwise, the location of the FirstEntry node is swapped with the location
3136   of the SecondEntry node in a doubly linked list. SecondEntry must be in the
3137   same double linked list as FirstEntry and that double linked list must have
3138   been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().
3139   SecondEntry is returned after the nodes are swapped.
3140 
3141   If FirstEntry is NULL, then ASSERT().
3142   If SecondEntry is NULL, then ASSERT().
3143   If PcdVerifyNodeInList is TRUE and SecondEntry and FirstEntry are not in the
3144   same linked list, then ASSERT().
3145   If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
3146   linked list containing the FirstEntry and SecondEntry nodes, including
3147   the FirstEntry and SecondEntry nodes, is greater than or equal to
3148   PcdMaximumLinkedListLength, then ASSERT().
3149 
3150   @param  FirstEntry  A pointer to a node in a linked list.
3151   @param  SecondEntry A pointer to another node in the same linked list.
3152 
3153   @return SecondEntry.
3154 
3155 **/
3156 LIST_ENTRY *
3157 EFIAPI
3158 SwapListEntries (
3159   IN OUT  LIST_ENTRY                *FirstEntry,
3160   IN OUT  LIST_ENTRY                *SecondEntry
3161   );
3162 
3163 
3164 /**
3165   Removes a node from a doubly linked list, and returns the node that follows
3166   the removed node.
3167 
3168   Removes the node Entry from a doubly linked list. It is up to the caller of
3169   this function to release the memory used by this node if that is required. On
3170   exit, the node following Entry in the doubly linked list is returned. If
3171   Entry is the only node in the linked list, then the head node of the linked
3172   list is returned.
3173 
3174   If Entry is NULL, then ASSERT().
3175   If Entry is the head node of an empty list, then ASSERT().
3176   If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
3177   linked list containing Entry, including the Entry node, is greater than
3178   or equal to PcdMaximumLinkedListLength, then ASSERT().
3179 
3180   @param  Entry A pointer to a node in a linked list.
3181 
3182   @return Entry.
3183 
3184 **/
3185 LIST_ENTRY *
3186 EFIAPI
3187 RemoveEntryList (
3188   IN      CONST LIST_ENTRY          *Entry
3189   );
3190 
3191 //
3192 // Math Services
3193 //
3194 
3195 /**
3196   Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
3197   with zeros. The shifted value is returned.
3198 
3199   This function shifts the 64-bit value Operand to the left by Count bits. The
3200   low Count bits are set to zero. The shifted value is returned.
3201 
3202   If Count is greater than 63, then ASSERT().
3203 
3204   @param  Operand The 64-bit operand to shift left.
3205   @param  Count   The number of bits to shift left.
3206 
3207   @return Operand << Count.
3208 
3209 **/
3210 UINT64
3211 EFIAPI
3212 LShiftU64 (
3213   IN      UINT64                    Operand,
3214   IN      UINTN                     Count
3215   );
3216 
3217 
3218 /**
3219   Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
3220   filled with zeros. The shifted value is returned.
3221 
3222   This function shifts the 64-bit value Operand to the right by Count bits. The
3223   high Count bits are set to zero. The shifted value is returned.
3224 
3225   If Count is greater than 63, then ASSERT().
3226 
3227   @param  Operand The 64-bit operand to shift right.
3228   @param  Count   The number of bits to shift right.
3229 
3230   @return Operand >> Count
3231 
3232 **/
3233 UINT64
3234 EFIAPI
3235 RShiftU64 (
3236   IN      UINT64                    Operand,
3237   IN      UINTN                     Count
3238   );
3239 
3240 
3241 /**
3242   Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
3243   with original integer's bit 63. The shifted value is returned.
3244 
3245   This function shifts the 64-bit value Operand to the right by Count bits. The
3246   high Count bits are set to bit 63 of Operand.  The shifted value is returned.
3247 
3248   If Count is greater than 63, then ASSERT().
3249 
3250   @param  Operand The 64-bit operand to shift right.
3251   @param  Count   The number of bits to shift right.
3252 
3253   @return Operand >> Count
3254 
3255 **/
3256 UINT64
3257 EFIAPI
3258 ARShiftU64 (
3259   IN      UINT64                    Operand,
3260   IN      UINTN                     Count
3261   );
3262 
3263 
3264 /**
3265   Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
3266   with the high bits that were rotated.
3267 
3268   This function rotates the 32-bit value Operand to the left by Count bits. The
3269   low Count bits are fill with the high Count bits of Operand. The rotated
3270   value is returned.
3271 
3272   If Count is greater than 31, then ASSERT().
3273 
3274   @param  Operand The 32-bit operand to rotate left.
3275   @param  Count   The number of bits to rotate left.
3276 
3277   @return Operand << Count
3278 
3279 **/
3280 UINT32
3281 EFIAPI
3282 LRotU32 (
3283   IN      UINT32                    Operand,
3284   IN      UINTN                     Count
3285   );
3286 
3287 
3288 /**
3289   Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
3290   with the low bits that were rotated.
3291 
3292   This function rotates the 32-bit value Operand to the right by Count bits.
3293   The high Count bits are fill with the low Count bits of Operand. The rotated
3294   value is returned.
3295 
3296   If Count is greater than 31, then ASSERT().
3297 
3298   @param  Operand The 32-bit operand to rotate right.
3299   @param  Count   The number of bits to rotate right.
3300 
3301   @return Operand >> Count
3302 
3303 **/
3304 UINT32
3305 EFIAPI
3306 RRotU32 (
3307   IN      UINT32                    Operand,
3308   IN      UINTN                     Count
3309   );
3310 
3311 
3312 /**
3313   Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
3314   with the high bits that were rotated.
3315 
3316   This function rotates the 64-bit value Operand to the left by Count bits. The
3317   low Count bits are fill with the high Count bits of Operand. The rotated
3318   value is returned.
3319 
3320   If Count is greater than 63, then ASSERT().
3321 
3322   @param  Operand The 64-bit operand to rotate left.
3323   @param  Count   The number of bits to rotate left.
3324 
3325   @return Operand << Count
3326 
3327 **/
3328 UINT64
3329 EFIAPI
3330 LRotU64 (
3331   IN      UINT64                    Operand,
3332   IN      UINTN                     Count
3333   );
3334 
3335 
3336 /**
3337   Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
3338   with the high low bits that were rotated.
3339 
3340   This function rotates the 64-bit value Operand to the right by Count bits.
3341   The high Count bits are fill with the low Count bits of Operand. The rotated
3342   value is returned.
3343 
3344   If Count is greater than 63, then ASSERT().
3345 
3346   @param  Operand The 64-bit operand to rotate right.
3347   @param  Count   The number of bits to rotate right.
3348 
3349   @return Operand >> Count
3350 
3351 **/
3352 UINT64
3353 EFIAPI
3354 RRotU64 (
3355   IN      UINT64                    Operand,
3356   IN      UINTN                     Count
3357   );
3358 
3359 
3360 /**
3361   Returns the bit position of the lowest bit set in a 32-bit value.
3362 
3363   This function computes the bit position of the lowest bit set in the 32-bit
3364   value specified by Operand. If Operand is zero, then -1 is returned.
3365   Otherwise, a value between 0 and 31 is returned.
3366 
3367   @param  Operand The 32-bit operand to evaluate.
3368 
3369   @retval 0..31  The lowest bit set in Operand was found.
3370   @retval -1    Operand is zero.
3371 
3372 **/
3373 INTN
3374 EFIAPI
3375 LowBitSet32 (
3376   IN      UINT32                    Operand
3377   );
3378 
3379 
3380 /**
3381   Returns the bit position of the lowest bit set in a 64-bit value.
3382 
3383   This function computes the bit position of the lowest bit set in the 64-bit
3384   value specified by Operand. If Operand is zero, then -1 is returned.
3385   Otherwise, a value between 0 and 63 is returned.
3386 
3387   @param  Operand The 64-bit operand to evaluate.
3388 
3389   @retval 0..63  The lowest bit set in Operand was found.
3390   @retval -1    Operand is zero.
3391 
3392 
3393 **/
3394 INTN
3395 EFIAPI
3396 LowBitSet64 (
3397   IN      UINT64                    Operand
3398   );
3399 
3400 
3401 /**
3402   Returns the bit position of the highest bit set in a 32-bit value. Equivalent
3403   to log2(x).
3404 
3405   This function computes the bit position of the highest bit set in the 32-bit
3406   value specified by Operand. If Operand is zero, then -1 is returned.
3407   Otherwise, a value between 0 and 31 is returned.
3408 
3409   @param  Operand The 32-bit operand to evaluate.
3410 
3411   @retval 0..31  Position of the highest bit set in Operand if found.
3412   @retval -1    Operand is zero.
3413 
3414 **/
3415 INTN
3416 EFIAPI
3417 HighBitSet32 (
3418   IN      UINT32                    Operand
3419   );
3420 
3421 
3422 /**
3423   Returns the bit position of the highest bit set in a 64-bit value. Equivalent
3424   to log2(x).
3425 
3426   This function computes the bit position of the highest bit set in the 64-bit
3427   value specified by Operand. If Operand is zero, then -1 is returned.
3428   Otherwise, a value between 0 and 63 is returned.
3429 
3430   @param  Operand The 64-bit operand to evaluate.
3431 
3432   @retval 0..63   Position of the highest bit set in Operand if found.
3433   @retval -1     Operand is zero.
3434 
3435 **/
3436 INTN
3437 EFIAPI
3438 HighBitSet64 (
3439   IN      UINT64                    Operand
3440   );
3441 
3442 
3443 /**
3444   Returns the value of the highest bit set in a 32-bit value. Equivalent to
3445   1 << log2(x).
3446 
3447   This function computes the value of the highest bit set in the 32-bit value
3448   specified by Operand. If Operand is zero, then zero is returned.
3449 
3450   @param  Operand The 32-bit operand to evaluate.
3451 
3452   @return 1 << HighBitSet32(Operand)
3453   @retval 0 Operand is zero.
3454 
3455 **/
3456 UINT32
3457 EFIAPI
3458 GetPowerOfTwo32 (
3459   IN      UINT32                    Operand
3460   );
3461 
3462 
3463 /**
3464   Returns the value of the highest bit set in a 64-bit value. Equivalent to
3465   1 << log2(x).
3466 
3467   This function computes the value of the highest bit set in the 64-bit value
3468   specified by Operand. If Operand is zero, then zero is returned.
3469 
3470   @param  Operand The 64-bit operand to evaluate.
3471 
3472   @return 1 << HighBitSet64(Operand)
3473   @retval 0 Operand is zero.
3474 
3475 **/
3476 UINT64
3477 EFIAPI
3478 GetPowerOfTwo64 (
3479   IN      UINT64                    Operand
3480   );
3481 
3482 
3483 /**
3484   Switches the endianness of a 16-bit integer.
3485 
3486   This function swaps the bytes in a 16-bit unsigned value to switch the value
3487   from little endian to big endian or vice versa. The byte swapped value is
3488   returned.
3489 
3490   @param  Value A 16-bit unsigned value.
3491 
3492   @return The byte swapped Value.
3493 
3494 **/
3495 UINT16
3496 EFIAPI
3497 SwapBytes16 (
3498   IN      UINT16                    Value
3499   );
3500 
3501 
3502 /**
3503   Switches the endianness of a 32-bit integer.
3504 
3505   This function swaps the bytes in a 32-bit unsigned value to switch the value
3506   from little endian to big endian or vice versa. The byte swapped value is
3507   returned.
3508 
3509   @param  Value A 32-bit unsigned value.
3510 
3511   @return The byte swapped Value.
3512 
3513 **/
3514 UINT32
3515 EFIAPI
3516 SwapBytes32 (
3517   IN      UINT32                    Value
3518   );
3519 
3520 
3521 /**
3522   Switches the endianness of a 64-bit integer.
3523 
3524   This function swaps the bytes in a 64-bit unsigned value to switch the value
3525   from little endian to big endian or vice versa. The byte swapped value is
3526   returned.
3527 
3528   @param  Value A 64-bit unsigned value.
3529 
3530   @return The byte swapped Value.
3531 
3532 **/
3533 UINT64
3534 EFIAPI
3535 SwapBytes64 (
3536   IN      UINT64                    Value
3537   );
3538 
3539 
3540 /**
3541   Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
3542   generates a 64-bit unsigned result.
3543 
3544   This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
3545   unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
3546   bit unsigned result is returned.
3547 
3548   @param  Multiplicand  A 64-bit unsigned value.
3549   @param  Multiplier    A 32-bit unsigned value.
3550 
3551   @return Multiplicand * Multiplier
3552 
3553 **/
3554 UINT64
3555 EFIAPI
3556 MultU64x32 (
3557   IN      UINT64                    Multiplicand,
3558   IN      UINT32                    Multiplier
3559   );
3560 
3561 
3562 /**
3563   Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
3564   generates a 64-bit unsigned result.
3565 
3566   This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
3567   unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
3568   bit unsigned result is returned.
3569 
3570   @param  Multiplicand  A 64-bit unsigned value.
3571   @param  Multiplier    A 64-bit unsigned value.
3572 
3573   @return Multiplicand * Multiplier.
3574 
3575 **/
3576 UINT64
3577 EFIAPI
3578 MultU64x64 (
3579   IN      UINT64                    Multiplicand,
3580   IN      UINT64                    Multiplier
3581   );
3582 
3583 
3584 /**
3585   Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
3586   64-bit signed result.
3587 
3588   This function multiples the 64-bit signed value Multiplicand by the 64-bit
3589   signed value Multiplier and generates a 64-bit signed result. This 64-bit
3590   signed result is returned.
3591 
3592   @param  Multiplicand  A 64-bit signed value.
3593   @param  Multiplier    A 64-bit signed value.
3594 
3595   @return Multiplicand * Multiplier
3596 
3597 **/
3598 INT64
3599 EFIAPI
3600 MultS64x64 (
3601   IN      INT64                     Multiplicand,
3602   IN      INT64                     Multiplier
3603   );
3604 
3605 
3606 /**
3607   Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
3608   a 64-bit unsigned result.
3609 
3610   This function divides the 64-bit unsigned value Dividend by the 32-bit
3611   unsigned value Divisor and generates a 64-bit unsigned quotient. This
3612   function returns the 64-bit unsigned quotient.
3613 
3614   If Divisor is 0, then ASSERT().
3615 
3616   @param  Dividend  A 64-bit unsigned value.
3617   @param  Divisor   A 32-bit unsigned value.
3618 
3619   @return Dividend / Divisor.
3620 
3621 **/
3622 UINT64
3623 EFIAPI
3624 DivU64x32 (
3625   IN      UINT64                    Dividend,
3626   IN      UINT32                    Divisor
3627   );
3628 
3629 
3630 /**
3631   Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
3632   a 32-bit unsigned remainder.
3633 
3634   This function divides the 64-bit unsigned value Dividend by the 32-bit
3635   unsigned value Divisor and generates a 32-bit remainder. This function
3636   returns the 32-bit unsigned remainder.
3637 
3638   If Divisor is 0, then ASSERT().
3639 
3640   @param  Dividend  A 64-bit unsigned value.
3641   @param  Divisor   A 32-bit unsigned value.
3642 
3643   @return Dividend % Divisor.
3644 
3645 **/
3646 UINT32
3647 EFIAPI
3648 ModU64x32 (
3649   IN      UINT64                    Dividend,
3650   IN      UINT32                    Divisor
3651   );
3652 
3653 
3654 /**
3655   Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
3656   a 64-bit unsigned result and an optional 32-bit unsigned remainder.
3657 
3658   This function divides the 64-bit unsigned value Dividend by the 32-bit
3659   unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
3660   is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
3661   This function returns the 64-bit unsigned quotient.
3662 
3663   If Divisor is 0, then ASSERT().
3664 
3665   @param  Dividend  A 64-bit unsigned value.
3666   @param  Divisor   A 32-bit unsigned value.
3667   @param  Remainder A pointer to a 32-bit unsigned value. This parameter is
3668                     optional and may be NULL.
3669 
3670   @return Dividend / Divisor.
3671 
3672 **/
3673 UINT64
3674 EFIAPI
3675 DivU64x32Remainder (
3676   IN      UINT64                    Dividend,
3677   IN      UINT32                    Divisor,
3678   OUT     UINT32                    *Remainder  OPTIONAL
3679   );
3680 
3681 
3682 /**
3683   Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
3684   a 64-bit unsigned result and an optional 64-bit unsigned remainder.
3685 
3686   This function divides the 64-bit unsigned value Dividend by the 64-bit
3687   unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
3688   is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
3689   This function returns the 64-bit unsigned quotient.
3690 
3691   If Divisor is 0, then ASSERT().
3692 
3693   @param  Dividend  A 64-bit unsigned value.
3694   @param  Divisor   A 64-bit unsigned value.
3695   @param  Remainder A pointer to a 64-bit unsigned value. This parameter is
3696                     optional and may be NULL.
3697 
3698   @return Dividend / Divisor.
3699 
3700 **/
3701 UINT64
3702 EFIAPI
3703 DivU64x64Remainder (
3704   IN      UINT64                    Dividend,
3705   IN      UINT64                    Divisor,
3706   OUT     UINT64                    *Remainder  OPTIONAL
3707   );
3708 
3709 
3710 /**
3711   Divides a 64-bit signed integer by a 64-bit signed integer and generates a
3712   64-bit signed result and a optional 64-bit signed remainder.
3713 
3714   This function divides the 64-bit signed value Dividend by the 64-bit signed
3715   value Divisor and generates a 64-bit signed quotient. If Remainder is not
3716   NULL, then the 64-bit signed remainder is returned in Remainder. This
3717   function returns the 64-bit signed quotient.
3718 
3719   It is the caller's responsibility to not call this function with a Divisor of 0.
3720   If Divisor is 0, then the quotient and remainder should be assumed to be
3721   the largest negative integer.
3722 
3723   If Divisor is 0, then ASSERT().
3724 
3725   @param  Dividend  A 64-bit signed value.
3726   @param  Divisor   A 64-bit signed value.
3727   @param  Remainder A pointer to a 64-bit signed value. This parameter is
3728                     optional and may be NULL.
3729 
3730   @return Dividend / Divisor.
3731 
3732 **/
3733 INT64
3734 EFIAPI
3735 DivS64x64Remainder (
3736   IN      INT64                     Dividend,
3737   IN      INT64                     Divisor,
3738   OUT     INT64                     *Remainder  OPTIONAL
3739   );
3740 
3741 
3742 /**
3743   Reads a 16-bit value from memory that may be unaligned.
3744 
3745   This function returns the 16-bit value pointed to by Buffer. The function
3746   guarantees that the read operation does not produce an alignment fault.
3747 
3748   If the Buffer is NULL, then ASSERT().
3749 
3750   @param  Buffer  The pointer to a 16-bit value that may be unaligned.
3751 
3752   @return The 16-bit value read from Buffer.
3753 
3754 **/
3755 UINT16
3756 EFIAPI
3757 ReadUnaligned16 (
3758   IN CONST UINT16              *Buffer
3759   );
3760 
3761 
3762 /**
3763   Writes a 16-bit value to memory that may be unaligned.
3764 
3765   This function writes the 16-bit value specified by Value to Buffer. Value is
3766   returned. The function guarantees that the write operation does not produce
3767   an alignment fault.
3768 
3769   If the Buffer is NULL, then ASSERT().
3770 
3771   @param  Buffer  The pointer to a 16-bit value that may be unaligned.
3772   @param  Value   16-bit value to write to Buffer.
3773 
3774   @return The 16-bit value to write to Buffer.
3775 
3776 **/
3777 UINT16
3778 EFIAPI
3779 WriteUnaligned16 (
3780   OUT UINT16                    *Buffer,
3781   IN  UINT16                    Value
3782   );
3783 
3784 
3785 /**
3786   Reads a 24-bit value from memory that may be unaligned.
3787 
3788   This function returns the 24-bit value pointed to by Buffer. The function
3789   guarantees that the read operation does not produce an alignment fault.
3790 
3791   If the Buffer is NULL, then ASSERT().
3792 
3793   @param  Buffer  The pointer to a 24-bit value that may be unaligned.
3794 
3795   @return The 24-bit value read from Buffer.
3796 
3797 **/
3798 UINT32
3799 EFIAPI
3800 ReadUnaligned24 (
3801   IN CONST UINT32              *Buffer
3802   );
3803 
3804 
3805 /**
3806   Writes a 24-bit value to memory that may be unaligned.
3807 
3808   This function writes the 24-bit value specified by Value to Buffer. Value is
3809   returned. The function guarantees that the write operation does not produce
3810   an alignment fault.
3811 
3812   If the Buffer is NULL, then ASSERT().
3813 
3814   @param  Buffer  The pointer to a 24-bit value that may be unaligned.
3815   @param  Value   24-bit value to write to Buffer.
3816 
3817   @return The 24-bit value to write to Buffer.
3818 
3819 **/
3820 UINT32
3821 EFIAPI
3822 WriteUnaligned24 (
3823   OUT UINT32                    *Buffer,
3824   IN  UINT32                    Value
3825   );
3826 
3827 
3828 /**
3829   Reads a 32-bit value from memory that may be unaligned.
3830 
3831   This function returns the 32-bit value pointed to by Buffer. The function
3832   guarantees that the read operation does not produce an alignment fault.
3833 
3834   If the Buffer is NULL, then ASSERT().
3835 
3836   @param  Buffer  The pointer to a 32-bit value that may be unaligned.
3837 
3838   @return The 32-bit value read from Buffer.
3839 
3840 **/
3841 UINT32
3842 EFIAPI
3843 ReadUnaligned32 (
3844   IN CONST UINT32              *Buffer
3845   );
3846 
3847 
3848 /**
3849   Writes a 32-bit value to memory that may be unaligned.
3850 
3851   This function writes the 32-bit value specified by Value to Buffer. Value is
3852   returned. The function guarantees that the write operation does not produce
3853   an alignment fault.
3854 
3855   If the Buffer is NULL, then ASSERT().
3856 
3857   @param  Buffer  The pointer to a 32-bit value that may be unaligned.
3858   @param  Value   32-bit value to write to Buffer.
3859 
3860   @return The 32-bit value to write to Buffer.
3861 
3862 **/
3863 UINT32
3864 EFIAPI
3865 WriteUnaligned32 (
3866   OUT UINT32                    *Buffer,
3867   IN  UINT32                    Value
3868   );
3869 
3870 
3871 /**
3872   Reads a 64-bit value from memory that may be unaligned.
3873 
3874   This function returns the 64-bit value pointed to by Buffer. The function
3875   guarantees that the read operation does not produce an alignment fault.
3876 
3877   If the Buffer is NULL, then ASSERT().
3878 
3879   @param  Buffer  The pointer to a 64-bit value that may be unaligned.
3880 
3881   @return The 64-bit value read from Buffer.
3882 
3883 **/
3884 UINT64
3885 EFIAPI
3886 ReadUnaligned64 (
3887   IN CONST UINT64              *Buffer
3888   );
3889 
3890 
3891 /**
3892   Writes a 64-bit value to memory that may be unaligned.
3893 
3894   This function writes the 64-bit value specified by Value to Buffer. Value is
3895   returned. The function guarantees that the write operation does not produce
3896   an alignment fault.
3897 
3898   If the Buffer is NULL, then ASSERT().
3899 
3900   @param  Buffer  The pointer to a 64-bit value that may be unaligned.
3901   @param  Value   64-bit value to write to Buffer.
3902 
3903   @return The 64-bit value to write to Buffer.
3904 
3905 **/
3906 UINT64
3907 EFIAPI
3908 WriteUnaligned64 (
3909   OUT UINT64                    *Buffer,
3910   IN  UINT64                    Value
3911   );
3912 
3913 
3914 //
3915 // Bit Field Functions
3916 //
3917 
3918 /**
3919   Returns a bit field from an 8-bit value.
3920 
3921   Returns the bitfield specified by the StartBit and the EndBit from Operand.
3922 
3923   If 8-bit operations are not supported, then ASSERT().
3924   If StartBit is greater than 7, then ASSERT().
3925   If EndBit is greater than 7, then ASSERT().
3926   If EndBit is less than StartBit, then ASSERT().
3927 
3928   @param  Operand   Operand on which to perform the bitfield operation.
3929   @param  StartBit  The ordinal of the least significant bit in the bit field.
3930                     Range 0..7.
3931   @param  EndBit    The ordinal of the most significant bit in the bit field.
3932                     Range 0..7.
3933 
3934   @return The bit field read.
3935 
3936 **/
3937 UINT8
3938 EFIAPI
3939 BitFieldRead8 (
3940   IN      UINT8                     Operand,
3941   IN      UINTN                     StartBit,
3942   IN      UINTN                     EndBit
3943   );
3944 
3945 
3946 /**
3947   Writes a bit field to an 8-bit value, and returns the result.
3948 
3949   Writes Value to the bit field specified by the StartBit and the EndBit in
3950   Operand. All other bits in Operand are preserved. The new 8-bit value is
3951   returned.
3952 
3953   If 8-bit operations are not supported, then ASSERT().
3954   If StartBit is greater than 7, then ASSERT().
3955   If EndBit is greater than 7, then ASSERT().
3956   If EndBit is less than StartBit, then ASSERT().
3957   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3958 
3959   @param  Operand   Operand on which to perform the bitfield operation.
3960   @param  StartBit  The ordinal of the least significant bit in the bit field.
3961                     Range 0..7.
3962   @param  EndBit    The ordinal of the most significant bit in the bit field.
3963                     Range 0..7.
3964   @param  Value     New value of the bit field.
3965 
3966   @return The new 8-bit value.
3967 
3968 **/
3969 UINT8
3970 EFIAPI
3971 BitFieldWrite8 (
3972   IN      UINT8                     Operand,
3973   IN      UINTN                     StartBit,
3974   IN      UINTN                     EndBit,
3975   IN      UINT8                     Value
3976   );
3977 
3978 
3979 /**
3980   Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
3981   result.
3982 
3983   Performs a bitwise OR between the bit field specified by StartBit
3984   and EndBit in Operand and the value specified by OrData. All other bits in
3985   Operand are preserved. The new 8-bit value is returned.
3986 
3987   If 8-bit operations are not supported, then ASSERT().
3988   If StartBit is greater than 7, then ASSERT().
3989   If EndBit is greater than 7, then ASSERT().
3990   If EndBit is less than StartBit, then ASSERT().
3991   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3992 
3993   @param  Operand   Operand on which to perform the bitfield operation.
3994   @param  StartBit  The ordinal of the least significant bit in the bit field.
3995                     Range 0..7.
3996   @param  EndBit    The ordinal of the most significant bit in the bit field.
3997                     Range 0..7.
3998   @param  OrData    The value to OR with the read value from the value
3999 
4000   @return The new 8-bit value.
4001 
4002 **/
4003 UINT8
4004 EFIAPI
4005 BitFieldOr8 (
4006   IN      UINT8                     Operand,
4007   IN      UINTN                     StartBit,
4008   IN      UINTN                     EndBit,
4009   IN      UINT8                     OrData
4010   );
4011 
4012 
4013 /**
4014   Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
4015   the result.
4016 
4017   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4018   in Operand and the value specified by AndData. All other bits in Operand are
4019   preserved. The new 8-bit value is returned.
4020 
4021   If 8-bit operations are not supported, then ASSERT().
4022   If StartBit is greater than 7, then ASSERT().
4023   If EndBit is greater than 7, then ASSERT().
4024   If EndBit is less than StartBit, then ASSERT().
4025   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4026 
4027   @param  Operand   Operand on which to perform the bitfield operation.
4028   @param  StartBit  The ordinal of the least significant bit in the bit field.
4029                     Range 0..7.
4030   @param  EndBit    The ordinal of the most significant bit in the bit field.
4031                     Range 0..7.
4032   @param  AndData   The value to AND with the read value from the value.
4033 
4034   @return The new 8-bit value.
4035 
4036 **/
4037 UINT8
4038 EFIAPI
4039 BitFieldAnd8 (
4040   IN      UINT8                     Operand,
4041   IN      UINTN                     StartBit,
4042   IN      UINTN                     EndBit,
4043   IN      UINT8                     AndData
4044   );
4045 
4046 
4047 /**
4048   Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
4049   bitwise OR, and returns the result.
4050 
4051   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4052   in Operand and the value specified by AndData, followed by a bitwise
4053   OR with value specified by OrData. All other bits in Operand are
4054   preserved. The new 8-bit value is returned.
4055 
4056   If 8-bit operations are not supported, then ASSERT().
4057   If StartBit is greater than 7, then ASSERT().
4058   If EndBit is greater than 7, then ASSERT().
4059   If EndBit is less than StartBit, then ASSERT().
4060   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4061   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4062 
4063   @param  Operand   Operand on which to perform the bitfield operation.
4064   @param  StartBit  The ordinal of the least significant bit in the bit field.
4065                     Range 0..7.
4066   @param  EndBit    The ordinal of the most significant bit in the bit field.
4067                     Range 0..7.
4068   @param  AndData   The value to AND with the read value from the value.
4069   @param  OrData    The value to OR with the result of the AND operation.
4070 
4071   @return The new 8-bit value.
4072 
4073 **/
4074 UINT8
4075 EFIAPI
4076 BitFieldAndThenOr8 (
4077   IN      UINT8                     Operand,
4078   IN      UINTN                     StartBit,
4079   IN      UINTN                     EndBit,
4080   IN      UINT8                     AndData,
4081   IN      UINT8                     OrData
4082   );
4083 
4084 
4085 /**
4086   Returns a bit field from a 16-bit value.
4087 
4088   Returns the bitfield specified by the StartBit and the EndBit from Operand.
4089 
4090   If 16-bit operations are not supported, then ASSERT().
4091   If StartBit is greater than 15, then ASSERT().
4092   If EndBit is greater than 15, then ASSERT().
4093   If EndBit is less than StartBit, then ASSERT().
4094 
4095   @param  Operand   Operand on which to perform the bitfield operation.
4096   @param  StartBit  The ordinal of the least significant bit in the bit field.
4097                     Range 0..15.
4098   @param  EndBit    The ordinal of the most significant bit in the bit field.
4099                     Range 0..15.
4100 
4101   @return The bit field read.
4102 
4103 **/
4104 UINT16
4105 EFIAPI
4106 BitFieldRead16 (
4107   IN      UINT16                    Operand,
4108   IN      UINTN                     StartBit,
4109   IN      UINTN                     EndBit
4110   );
4111 
4112 
4113 /**
4114   Writes a bit field to a 16-bit value, and returns the result.
4115 
4116   Writes Value to the bit field specified by the StartBit and the EndBit in
4117   Operand. All other bits in Operand are preserved. The new 16-bit value is
4118   returned.
4119 
4120   If 16-bit operations are not supported, then ASSERT().
4121   If StartBit is greater than 15, then ASSERT().
4122   If EndBit is greater than 15, then ASSERT().
4123   If EndBit is less than StartBit, then ASSERT().
4124   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4125 
4126   @param  Operand   Operand on which to perform the bitfield operation.
4127   @param  StartBit  The ordinal of the least significant bit in the bit field.
4128                     Range 0..15.
4129   @param  EndBit    The ordinal of the most significant bit in the bit field.
4130                     Range 0..15.
4131   @param  Value     New value of the bit field.
4132 
4133   @return The new 16-bit value.
4134 
4135 **/
4136 UINT16
4137 EFIAPI
4138 BitFieldWrite16 (
4139   IN      UINT16                    Operand,
4140   IN      UINTN                     StartBit,
4141   IN      UINTN                     EndBit,
4142   IN      UINT16                    Value
4143   );
4144 
4145 
4146 /**
4147   Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
4148   result.
4149 
4150   Performs a bitwise OR between the bit field specified by StartBit
4151   and EndBit in Operand and the value specified by OrData. All other bits in
4152   Operand are preserved. The new 16-bit value is returned.
4153 
4154   If 16-bit operations are not supported, then ASSERT().
4155   If StartBit is greater than 15, then ASSERT().
4156   If EndBit is greater than 15, then ASSERT().
4157   If EndBit is less than StartBit, then ASSERT().
4158   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4159 
4160   @param  Operand   Operand on which to perform the bitfield operation.
4161   @param  StartBit  The ordinal of the least significant bit in the bit field.
4162                     Range 0..15.
4163   @param  EndBit    The ordinal of the most significant bit in the bit field.
4164                     Range 0..15.
4165   @param  OrData    The value to OR with the read value from the value
4166 
4167   @return The new 16-bit value.
4168 
4169 **/
4170 UINT16
4171 EFIAPI
4172 BitFieldOr16 (
4173   IN      UINT16                    Operand,
4174   IN      UINTN                     StartBit,
4175   IN      UINTN                     EndBit,
4176   IN      UINT16                    OrData
4177   );
4178 
4179 
4180 /**
4181   Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
4182   the result.
4183 
4184   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4185   in Operand and the value specified by AndData. All other bits in Operand are
4186   preserved. The new 16-bit value is returned.
4187 
4188   If 16-bit operations are not supported, then ASSERT().
4189   If StartBit is greater than 15, then ASSERT().
4190   If EndBit is greater than 15, then ASSERT().
4191   If EndBit is less than StartBit, then ASSERT().
4192   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4193 
4194   @param  Operand   Operand on which to perform the bitfield operation.
4195   @param  StartBit  The ordinal of the least significant bit in the bit field.
4196                     Range 0..15.
4197   @param  EndBit    The ordinal of the most significant bit in the bit field.
4198                     Range 0..15.
4199   @param  AndData   The value to AND with the read value from the value
4200 
4201   @return The new 16-bit value.
4202 
4203 **/
4204 UINT16
4205 EFIAPI
4206 BitFieldAnd16 (
4207   IN      UINT16                    Operand,
4208   IN      UINTN                     StartBit,
4209   IN      UINTN                     EndBit,
4210   IN      UINT16                    AndData
4211   );
4212 
4213 
4214 /**
4215   Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
4216   bitwise OR, and returns the result.
4217 
4218   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4219   in Operand and the value specified by AndData, followed by a bitwise
4220   OR with value specified by OrData. All other bits in Operand are
4221   preserved. The new 16-bit value is returned.
4222 
4223   If 16-bit operations are not supported, then ASSERT().
4224   If StartBit is greater than 15, then ASSERT().
4225   If EndBit is greater than 15, then ASSERT().
4226   If EndBit is less than StartBit, then ASSERT().
4227   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4228   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4229 
4230   @param  Operand   Operand on which to perform the bitfield operation.
4231   @param  StartBit  The ordinal of the least significant bit in the bit field.
4232                     Range 0..15.
4233   @param  EndBit    The ordinal of the most significant bit in the bit field.
4234                     Range 0..15.
4235   @param  AndData   The value to AND with the read value from the value.
4236   @param  OrData    The value to OR with the result of the AND operation.
4237 
4238   @return The new 16-bit value.
4239 
4240 **/
4241 UINT16
4242 EFIAPI
4243 BitFieldAndThenOr16 (
4244   IN      UINT16                    Operand,
4245   IN      UINTN                     StartBit,
4246   IN      UINTN                     EndBit,
4247   IN      UINT16                    AndData,
4248   IN      UINT16                    OrData
4249   );
4250 
4251 
4252 /**
4253   Returns a bit field from a 32-bit value.
4254 
4255   Returns the bitfield specified by the StartBit and the EndBit from Operand.
4256 
4257   If 32-bit operations are not supported, then ASSERT().
4258   If StartBit is greater than 31, then ASSERT().
4259   If EndBit is greater than 31, then ASSERT().
4260   If EndBit is less than StartBit, then ASSERT().
4261 
4262   @param  Operand   Operand on which to perform the bitfield operation.
4263   @param  StartBit  The ordinal of the least significant bit in the bit field.
4264                     Range 0..31.
4265   @param  EndBit    The ordinal of the most significant bit in the bit field.
4266                     Range 0..31.
4267 
4268   @return The bit field read.
4269 
4270 **/
4271 UINT32
4272 EFIAPI
4273 BitFieldRead32 (
4274   IN      UINT32                    Operand,
4275   IN      UINTN                     StartBit,
4276   IN      UINTN                     EndBit
4277   );
4278 
4279 
4280 /**
4281   Writes a bit field to a 32-bit value, and returns the result.
4282 
4283   Writes Value to the bit field specified by the StartBit and the EndBit in
4284   Operand. All other bits in Operand are preserved. The new 32-bit value is
4285   returned.
4286 
4287   If 32-bit operations are not supported, then ASSERT().
4288   If StartBit is greater than 31, then ASSERT().
4289   If EndBit is greater than 31, then ASSERT().
4290   If EndBit is less than StartBit, then ASSERT().
4291   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4292 
4293   @param  Operand   Operand on which to perform the bitfield operation.
4294   @param  StartBit  The ordinal of the least significant bit in the bit field.
4295                     Range 0..31.
4296   @param  EndBit    The ordinal of the most significant bit in the bit field.
4297                     Range 0..31.
4298   @param  Value     New value of the bit field.
4299 
4300   @return The new 32-bit value.
4301 
4302 **/
4303 UINT32
4304 EFIAPI
4305 BitFieldWrite32 (
4306   IN      UINT32                    Operand,
4307   IN      UINTN                     StartBit,
4308   IN      UINTN                     EndBit,
4309   IN      UINT32                    Value
4310   );
4311 
4312 
4313 /**
4314   Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
4315   result.
4316 
4317   Performs a bitwise OR between the bit field specified by StartBit
4318   and EndBit in Operand and the value specified by OrData. All other bits in
4319   Operand are preserved. The new 32-bit value is returned.
4320 
4321   If 32-bit operations are not supported, then ASSERT().
4322   If StartBit is greater than 31, then ASSERT().
4323   If EndBit is greater than 31, then ASSERT().
4324   If EndBit is less than StartBit, then ASSERT().
4325   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4326 
4327   @param  Operand   Operand on which to perform the bitfield operation.
4328   @param  StartBit  The ordinal of the least significant bit in the bit field.
4329                     Range 0..31.
4330   @param  EndBit    The ordinal of the most significant bit in the bit field.
4331                     Range 0..31.
4332   @param  OrData    The value to OR with the read value from the value.
4333 
4334   @return The new 32-bit value.
4335 
4336 **/
4337 UINT32
4338 EFIAPI
4339 BitFieldOr32 (
4340   IN      UINT32                    Operand,
4341   IN      UINTN                     StartBit,
4342   IN      UINTN                     EndBit,
4343   IN      UINT32                    OrData
4344   );
4345 
4346 
4347 /**
4348   Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
4349   the result.
4350 
4351   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4352   in Operand and the value specified by AndData. All other bits in Operand are
4353   preserved. The new 32-bit value is returned.
4354 
4355   If 32-bit operations are not supported, then ASSERT().
4356   If StartBit is greater than 31, then ASSERT().
4357   If EndBit is greater than 31, then ASSERT().
4358   If EndBit is less than StartBit, then ASSERT().
4359   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4360 
4361   @param  Operand   Operand on which to perform the bitfield operation.
4362   @param  StartBit  The ordinal of the least significant bit in the bit field.
4363                     Range 0..31.
4364   @param  EndBit    The ordinal of the most significant bit in the bit field.
4365                     Range 0..31.
4366   @param  AndData   The value to AND with the read value from the value
4367 
4368   @return The new 32-bit value.
4369 
4370 **/
4371 UINT32
4372 EFIAPI
4373 BitFieldAnd32 (
4374   IN      UINT32                    Operand,
4375   IN      UINTN                     StartBit,
4376   IN      UINTN                     EndBit,
4377   IN      UINT32                    AndData
4378   );
4379 
4380 
4381 /**
4382   Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
4383   bitwise OR, and returns the result.
4384 
4385   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4386   in Operand and the value specified by AndData, followed by a bitwise
4387   OR with value specified by OrData. All other bits in Operand are
4388   preserved. The new 32-bit value is returned.
4389 
4390   If 32-bit operations are not supported, then ASSERT().
4391   If StartBit is greater than 31, then ASSERT().
4392   If EndBit is greater than 31, then ASSERT().
4393   If EndBit is less than StartBit, then ASSERT().
4394   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4395   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4396 
4397   @param  Operand   Operand on which to perform the bitfield operation.
4398   @param  StartBit  The ordinal of the least significant bit in the bit field.
4399                     Range 0..31.
4400   @param  EndBit    The ordinal of the most significant bit in the bit field.
4401                     Range 0..31.
4402   @param  AndData   The value to AND with the read value from the value.
4403   @param  OrData    The value to OR with the result of the AND operation.
4404 
4405   @return The new 32-bit value.
4406 
4407 **/
4408 UINT32
4409 EFIAPI
4410 BitFieldAndThenOr32 (
4411   IN      UINT32                    Operand,
4412   IN      UINTN                     StartBit,
4413   IN      UINTN                     EndBit,
4414   IN      UINT32                    AndData,
4415   IN      UINT32                    OrData
4416   );
4417 
4418 
4419 /**
4420   Returns a bit field from a 64-bit value.
4421 
4422   Returns the bitfield specified by the StartBit and the EndBit from Operand.
4423 
4424   If 64-bit operations are not supported, then ASSERT().
4425   If StartBit is greater than 63, then ASSERT().
4426   If EndBit is greater than 63, then ASSERT().
4427   If EndBit is less than StartBit, then ASSERT().
4428 
4429   @param  Operand   Operand on which to perform the bitfield operation.
4430   @param  StartBit  The ordinal of the least significant bit in the bit field.
4431                     Range 0..63.
4432   @param  EndBit    The ordinal of the most significant bit in the bit field.
4433                     Range 0..63.
4434 
4435   @return The bit field read.
4436 
4437 **/
4438 UINT64
4439 EFIAPI
4440 BitFieldRead64 (
4441   IN      UINT64                    Operand,
4442   IN      UINTN                     StartBit,
4443   IN      UINTN                     EndBit
4444   );
4445 
4446 
4447 /**
4448   Writes a bit field to a 64-bit value, and returns the result.
4449 
4450   Writes Value to the bit field specified by the StartBit and the EndBit in
4451   Operand. All other bits in Operand are preserved. The new 64-bit value is
4452   returned.
4453 
4454   If 64-bit operations are not supported, then ASSERT().
4455   If StartBit is greater than 63, then ASSERT().
4456   If EndBit is greater than 63, then ASSERT().
4457   If EndBit is less than StartBit, then ASSERT().
4458   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4459 
4460   @param  Operand   Operand on which to perform the bitfield operation.
4461   @param  StartBit  The ordinal of the least significant bit in the bit field.
4462                     Range 0..63.
4463   @param  EndBit    The ordinal of the most significant bit in the bit field.
4464                     Range 0..63.
4465   @param  Value     New value of the bit field.
4466 
4467   @return The new 64-bit value.
4468 
4469 **/
4470 UINT64
4471 EFIAPI
4472 BitFieldWrite64 (
4473   IN      UINT64                    Operand,
4474   IN      UINTN                     StartBit,
4475   IN      UINTN                     EndBit,
4476   IN      UINT64                    Value
4477   );
4478 
4479 
4480 /**
4481   Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
4482   result.
4483 
4484   Performs a bitwise OR between the bit field specified by StartBit
4485   and EndBit in Operand and the value specified by OrData. All other bits in
4486   Operand are preserved. The new 64-bit value is returned.
4487 
4488   If 64-bit operations are not supported, then ASSERT().
4489   If StartBit is greater than 63, then ASSERT().
4490   If EndBit is greater than 63, then ASSERT().
4491   If EndBit is less than StartBit, then ASSERT().
4492   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4493 
4494   @param  Operand   Operand on which to perform the bitfield operation.
4495   @param  StartBit  The ordinal of the least significant bit in the bit field.
4496                     Range 0..63.
4497   @param  EndBit    The ordinal of the most significant bit in the bit field.
4498                     Range 0..63.
4499   @param  OrData    The value to OR with the read value from the value
4500 
4501   @return The new 64-bit value.
4502 
4503 **/
4504 UINT64
4505 EFIAPI
4506 BitFieldOr64 (
4507   IN      UINT64                    Operand,
4508   IN      UINTN                     StartBit,
4509   IN      UINTN                     EndBit,
4510   IN      UINT64                    OrData
4511   );
4512 
4513 
4514 /**
4515   Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
4516   the result.
4517 
4518   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4519   in Operand and the value specified by AndData. All other bits in Operand are
4520   preserved. The new 64-bit value is returned.
4521 
4522   If 64-bit operations are not supported, then ASSERT().
4523   If StartBit is greater than 63, then ASSERT().
4524   If EndBit is greater than 63, then ASSERT().
4525   If EndBit is less than StartBit, then ASSERT().
4526   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4527 
4528   @param  Operand   Operand on which to perform the bitfield operation.
4529   @param  StartBit  The ordinal of the least significant bit in the bit field.
4530                     Range 0..63.
4531   @param  EndBit    The ordinal of the most significant bit in the bit field.
4532                     Range 0..63.
4533   @param  AndData   The value to AND with the read value from the value
4534 
4535   @return The new 64-bit value.
4536 
4537 **/
4538 UINT64
4539 EFIAPI
4540 BitFieldAnd64 (
4541   IN      UINT64                    Operand,
4542   IN      UINTN                     StartBit,
4543   IN      UINTN                     EndBit,
4544   IN      UINT64                    AndData
4545   );
4546 
4547 
4548 /**
4549   Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
4550   bitwise OR, and returns the result.
4551 
4552   Performs a bitwise AND between the bit field specified by StartBit and EndBit
4553   in Operand and the value specified by AndData, followed by a bitwise
4554   OR with value specified by OrData. All other bits in Operand are
4555   preserved. The new 64-bit value is returned.
4556 
4557   If 64-bit operations are not supported, then ASSERT().
4558   If StartBit is greater than 63, then ASSERT().
4559   If EndBit is greater than 63, then ASSERT().
4560   If EndBit is less than StartBit, then ASSERT().
4561   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4562   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4563 
4564   @param  Operand   Operand on which to perform the bitfield operation.
4565   @param  StartBit  The ordinal of the least significant bit in the bit field.
4566                     Range 0..63.
4567   @param  EndBit    The ordinal of the most significant bit in the bit field.
4568                     Range 0..63.
4569   @param  AndData   The value to AND with the read value from the value.
4570   @param  OrData    The value to OR with the result of the AND operation.
4571 
4572   @return The new 64-bit value.
4573 
4574 **/
4575 UINT64
4576 EFIAPI
4577 BitFieldAndThenOr64 (
4578   IN      UINT64                    Operand,
4579   IN      UINTN                     StartBit,
4580   IN      UINTN                     EndBit,
4581   IN      UINT64                    AndData,
4582   IN      UINT64                    OrData
4583   );
4584 
4585 //
4586 // Base Library Checksum Functions
4587 //
4588 
4589 /**
4590   Returns the sum of all elements in a buffer in unit of UINT8.
4591   During calculation, the carry bits are dropped.
4592 
4593   This function calculates the sum of all elements in a buffer
4594   in unit of UINT8. The carry bits in result of addition are dropped.
4595   The result is returned as UINT8. If Length is Zero, then Zero is
4596   returned.
4597 
4598   If Buffer is NULL, then ASSERT().
4599   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4600 
4601   @param  Buffer      The pointer to the buffer to carry out the sum operation.
4602   @param  Length      The size, in bytes, of Buffer.
4603 
4604   @return Sum         The sum of Buffer with carry bits dropped during additions.
4605 
4606 **/
4607 UINT8
4608 EFIAPI
4609 CalculateSum8 (
4610   IN      CONST UINT8              *Buffer,
4611   IN      UINTN                     Length
4612   );
4613 
4614 
4615 /**
4616   Returns the two's complement checksum of all elements in a buffer
4617   of 8-bit values.
4618 
4619   This function first calculates the sum of the 8-bit values in the
4620   buffer specified by Buffer and Length.  The carry bits in the result
4621   of addition are dropped. Then, the two's complement of the sum is
4622   returned.  If Length is 0, then 0 is returned.
4623 
4624   If Buffer is NULL, then ASSERT().
4625   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4626 
4627   @param  Buffer      The pointer to the buffer to carry out the checksum operation.
4628   @param  Length      The size, in bytes, of Buffer.
4629 
4630   @return Checksum    The two's complement checksum of Buffer.
4631 
4632 **/
4633 UINT8
4634 EFIAPI
4635 CalculateCheckSum8 (
4636   IN      CONST UINT8              *Buffer,
4637   IN      UINTN                     Length
4638   );
4639 
4640 
4641 /**
4642   Returns the sum of all elements in a buffer of 16-bit values.  During
4643   calculation, the carry bits are dropped.
4644 
4645   This function calculates the sum of the 16-bit values in the buffer
4646   specified by Buffer and Length. The carry bits in result of addition are dropped.
4647   The 16-bit result is returned.  If Length is 0, then 0 is returned.
4648 
4649   If Buffer is NULL, then ASSERT().
4650   If Buffer is not aligned on a 16-bit boundary, then ASSERT().
4651   If Length is not aligned on a 16-bit boundary, then ASSERT().
4652   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4653 
4654   @param  Buffer      The pointer to the buffer to carry out the sum operation.
4655   @param  Length      The size, in bytes, of Buffer.
4656 
4657   @return Sum         The sum of Buffer with carry bits dropped during additions.
4658 
4659 **/
4660 UINT16
4661 EFIAPI
4662 CalculateSum16 (
4663   IN      CONST UINT16             *Buffer,
4664   IN      UINTN                     Length
4665   );
4666 
4667 
4668 /**
4669   Returns the two's complement checksum of all elements in a buffer of
4670   16-bit values.
4671 
4672   This function first calculates the sum of the 16-bit values in the buffer
4673   specified by Buffer and Length.  The carry bits in the result of addition
4674   are dropped. Then, the two's complement of the sum is returned.  If Length
4675   is 0, then 0 is returned.
4676 
4677   If Buffer is NULL, then ASSERT().
4678   If Buffer is not aligned on a 16-bit boundary, then ASSERT().
4679   If Length is not aligned on a 16-bit boundary, then ASSERT().
4680   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4681 
4682   @param  Buffer      The pointer to the buffer to carry out the checksum operation.
4683   @param  Length      The size, in bytes, of Buffer.
4684 
4685   @return Checksum    The two's complement checksum of Buffer.
4686 
4687 **/
4688 UINT16
4689 EFIAPI
4690 CalculateCheckSum16 (
4691   IN      CONST UINT16             *Buffer,
4692   IN      UINTN                     Length
4693   );
4694 
4695 
4696 /**
4697   Returns the sum of all elements in a buffer of 32-bit values. During
4698   calculation, the carry bits are dropped.
4699 
4700   This function calculates the sum of the 32-bit values in the buffer
4701   specified by Buffer and Length. The carry bits in result of addition are dropped.
4702   The 32-bit result is returned. If Length is 0, then 0 is returned.
4703 
4704   If Buffer is NULL, then ASSERT().
4705   If Buffer is not aligned on a 32-bit boundary, then ASSERT().
4706   If Length is not aligned on a 32-bit boundary, then ASSERT().
4707   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4708 
4709   @param  Buffer      The pointer to the buffer to carry out the sum operation.
4710   @param  Length      The size, in bytes, of Buffer.
4711 
4712   @return Sum         The sum of Buffer with carry bits dropped during additions.
4713 
4714 **/
4715 UINT32
4716 EFIAPI
4717 CalculateSum32 (
4718   IN      CONST UINT32             *Buffer,
4719   IN      UINTN                     Length
4720   );
4721 
4722 
4723 /**
4724   Returns the two's complement checksum of all elements in a buffer of
4725   32-bit values.
4726 
4727   This function first calculates the sum of the 32-bit values in the buffer
4728   specified by Buffer and Length.  The carry bits in the result of addition
4729   are dropped. Then, the two's complement of the sum is returned.  If Length
4730   is 0, then 0 is returned.
4731 
4732   If Buffer is NULL, then ASSERT().
4733   If Buffer is not aligned on a 32-bit boundary, then ASSERT().
4734   If Length is not aligned on a 32-bit boundary, then ASSERT().
4735   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4736 
4737   @param  Buffer      The pointer to the buffer to carry out the checksum operation.
4738   @param  Length      The size, in bytes, of Buffer.
4739 
4740   @return Checksum    The two's complement checksum of Buffer.
4741 
4742 **/
4743 UINT32
4744 EFIAPI
4745 CalculateCheckSum32 (
4746   IN      CONST UINT32             *Buffer,
4747   IN      UINTN                     Length
4748   );
4749 
4750 
4751 /**
4752   Returns the sum of all elements in a buffer of 64-bit values.  During
4753   calculation, the carry bits are dropped.
4754 
4755   This function calculates the sum of the 64-bit values in the buffer
4756   specified by Buffer and Length. The carry bits in result of addition are dropped.
4757   The 64-bit result is returned.  If Length is 0, then 0 is returned.
4758 
4759   If Buffer is NULL, then ASSERT().
4760   If Buffer is not aligned on a 64-bit boundary, then ASSERT().
4761   If Length is not aligned on a 64-bit boundary, then ASSERT().
4762   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4763 
4764   @param  Buffer      The pointer to the buffer to carry out the sum operation.
4765   @param  Length      The size, in bytes, of Buffer.
4766 
4767   @return Sum         The sum of Buffer with carry bits dropped during additions.
4768 
4769 **/
4770 UINT64
4771 EFIAPI
4772 CalculateSum64 (
4773   IN      CONST UINT64             *Buffer,
4774   IN      UINTN                     Length
4775   );
4776 
4777 
4778 /**
4779   Returns the two's complement checksum of all elements in a buffer of
4780   64-bit values.
4781 
4782   This function first calculates the sum of the 64-bit values in the buffer
4783   specified by Buffer and Length.  The carry bits in the result of addition
4784   are dropped. Then, the two's complement of the sum is returned.  If Length
4785   is 0, then 0 is returned.
4786 
4787   If Buffer is NULL, then ASSERT().
4788   If Buffer is not aligned on a 64-bit boundary, then ASSERT().
4789   If Length is not aligned on a 64-bit boundary, then ASSERT().
4790   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4791 
4792   @param  Buffer      The pointer to the buffer to carry out the checksum operation.
4793   @param  Length      The size, in bytes, of Buffer.
4794 
4795   @return Checksum    The two's complement checksum of Buffer.
4796 
4797 **/
4798 UINT64
4799 EFIAPI
4800 CalculateCheckSum64 (
4801   IN      CONST UINT64             *Buffer,
4802   IN      UINTN                     Length
4803   );
4804 
4805 
4806 //
4807 // Base Library CPU Functions
4808 //
4809 
4810 /**
4811   Function entry point used when a stack switch is requested with SwitchStack()
4812 
4813   @param  Context1        Context1 parameter passed into SwitchStack().
4814   @param  Context2        Context2 parameter passed into SwitchStack().
4815 
4816 **/
4817 typedef
4818 VOID
4819 (EFIAPI *SWITCH_STACK_ENTRY_POINT)(
4820   IN      VOID                      *Context1,  OPTIONAL
4821   IN      VOID                      *Context2   OPTIONAL
4822   );
4823 
4824 
4825 /**
4826   Used to serialize load and store operations.
4827 
4828   All loads and stores that proceed calls to this function are guaranteed to be
4829   globally visible when this function returns.
4830 
4831 **/
4832 VOID
4833 EFIAPI
4834 MemoryFence (
4835   VOID
4836   );
4837 
4838 
4839 /**
4840   Saves the current CPU context that can be restored with a call to LongJump()
4841   and returns 0.
4842 
4843   Saves the current CPU context in the buffer specified by JumpBuffer and
4844   returns 0. The initial call to SetJump() must always return 0. Subsequent
4845   calls to LongJump() cause a non-zero value to be returned by SetJump().
4846 
4847   If JumpBuffer is NULL, then ASSERT().
4848   For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
4849 
4850   NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.
4851   The same structure must never be used for more than one CPU architecture context.
4852   For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module.
4853   SetJump()/LongJump() is not currently supported for the EBC processor type.
4854 
4855   @param  JumpBuffer  A pointer to CPU context buffer.
4856 
4857   @retval 0 Indicates a return from SetJump().
4858 
4859 **/
4860 UINTN
4861 EFIAPI
4862 SetJump (
4863   OUT     BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer
4864   );
4865 
4866 
4867 /**
4868   Restores the CPU context that was saved with SetJump().
4869 
4870   Restores the CPU context from the buffer specified by JumpBuffer. This
4871   function never returns to the caller. Instead is resumes execution based on
4872   the state of JumpBuffer.
4873 
4874   If JumpBuffer is NULL, then ASSERT().
4875   For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
4876   If Value is 0, then ASSERT().
4877 
4878   @param  JumpBuffer  A pointer to CPU context buffer.
4879   @param  Value       The value to return when the SetJump() context is
4880                       restored and must be non-zero.
4881 
4882 **/
4883 VOID
4884 EFIAPI
4885 LongJump (
4886   IN      BASE_LIBRARY_JUMP_BUFFER  *JumpBuffer,
4887   IN      UINTN                     Value
4888   );
4889 
4890 
4891 /**
4892   Enables CPU interrupts.
4893 
4894 **/
4895 VOID
4896 EFIAPI
4897 EnableInterrupts (
4898   VOID
4899   );
4900 
4901 
4902 /**
4903   Disables CPU interrupts.
4904 
4905 **/
4906 VOID
4907 EFIAPI
4908 DisableInterrupts (
4909   VOID
4910   );
4911 
4912 
4913 /**
4914   Disables CPU interrupts and returns the interrupt state prior to the disable
4915   operation.
4916 
4917   @retval TRUE  CPU interrupts were enabled on entry to this call.
4918   @retval FALSE CPU interrupts were disabled on entry to this call.
4919 
4920 **/
4921 BOOLEAN
4922 EFIAPI
4923 SaveAndDisableInterrupts (
4924   VOID
4925   );
4926 
4927 
4928 /**
4929   Enables CPU interrupts for the smallest window required to capture any
4930   pending interrupts.
4931 
4932 **/
4933 VOID
4934 EFIAPI
4935 EnableDisableInterrupts (
4936   VOID
4937   );
4938 
4939 
4940 /**
4941   Retrieves the current CPU interrupt state.
4942 
4943   Returns TRUE if interrupts are currently enabled. Otherwise
4944   returns FALSE.
4945 
4946   @retval TRUE  CPU interrupts are enabled.
4947   @retval FALSE CPU interrupts are disabled.
4948 
4949 **/
4950 BOOLEAN
4951 EFIAPI
4952 GetInterruptState (
4953   VOID
4954   );
4955 
4956 
4957 /**
4958   Set the current CPU interrupt state.
4959 
4960   Sets the current CPU interrupt state to the state specified by
4961   InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
4962   InterruptState is FALSE, then interrupts are disabled. InterruptState is
4963   returned.
4964 
4965   @param  InterruptState  TRUE if interrupts should enabled. FALSE if
4966                           interrupts should be disabled.
4967 
4968   @return InterruptState
4969 
4970 **/
4971 BOOLEAN
4972 EFIAPI
4973 SetInterruptState (
4974   IN      BOOLEAN                   InterruptState
4975   );
4976 
4977 
4978 /**
4979   Requests CPU to pause for a short period of time.
4980 
4981   Requests CPU to pause for a short period of time. Typically used in MP
4982   systems to prevent memory starvation while waiting for a spin lock.
4983 
4984 **/
4985 VOID
4986 EFIAPI
4987 CpuPause (
4988   VOID
4989   );
4990 
4991 
4992 /**
4993   Transfers control to a function starting with a new stack.
4994 
4995   Transfers control to the function specified by EntryPoint using the
4996   new stack specified by NewStack and passing in the parameters specified
4997   by Context1 and Context2.  Context1 and Context2 are optional and may
4998   be NULL.  The function EntryPoint must never return.  This function
4999   supports a variable number of arguments following the NewStack parameter.
5000   These additional arguments are ignored on IA-32, x64, and EBC architectures.
5001   Itanium processors expect one additional parameter of type VOID * that specifies
5002   the new backing store pointer.
5003 
5004   If EntryPoint is NULL, then ASSERT().
5005   If NewStack is NULL, then ASSERT().
5006 
5007   @param  EntryPoint  A pointer to function to call with the new stack.
5008   @param  Context1    A pointer to the context to pass into the EntryPoint
5009                       function.
5010   @param  Context2    A pointer to the context to pass into the EntryPoint
5011                       function.
5012   @param  NewStack    A pointer to the new stack to use for the EntryPoint
5013                       function.
5014   @param  ...         This variable argument list is ignored for IA-32, x64, and
5015                       EBC architectures.  For Itanium processors, this variable
5016                       argument list is expected to contain a single parameter of
5017                       type VOID * that specifies the new backing store pointer.
5018 
5019 
5020 **/
5021 VOID
5022 EFIAPI
5023 SwitchStack (
5024   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
5025   IN      VOID                      *Context1,  OPTIONAL
5026   IN      VOID                      *Context2,  OPTIONAL
5027   IN      VOID                      *NewStack,
5028   ...
5029   );
5030 
5031 
5032 /**
5033   Generates a breakpoint on the CPU.
5034 
5035   Generates a breakpoint on the CPU. The breakpoint must be implemented such
5036   that code can resume normal execution after the breakpoint.
5037 
5038 **/
5039 VOID
5040 EFIAPI
5041 CpuBreakpoint (
5042   VOID
5043   );
5044 
5045 
5046 /**
5047   Executes an infinite loop.
5048 
5049   Forces the CPU to execute an infinite loop. A debugger may be used to skip
5050   past the loop and the code that follows the loop must execute properly. This
5051   implies that the infinite loop must not cause the code that follow it to be
5052   optimized away.
5053 
5054 **/
5055 VOID
5056 EFIAPI
5057 CpuDeadLoop (
5058   VOID
5059   );
5060 
5061 #if defined (MDE_CPU_IPF)
5062 
5063 /**
5064   Flush a range of  cache lines in the cache coherency domain of the calling
5065   CPU.
5066 
5067   Flushes the cache lines specified by Address and Length.  If Address is not aligned
5068   on a cache line boundary, then entire cache line containing Address is flushed.
5069   If Address + Length is not aligned on a cache line boundary, then the entire cache
5070   line containing Address + Length - 1 is flushed.  This function may choose to flush
5071   the entire cache if that is more efficient than flushing the specified range.  If
5072   Length is 0, the no cache lines are flushed.  Address is returned.
5073   This function is only available on Itanium processors.
5074 
5075   If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
5076 
5077   @param  Address The base address of the instruction lines to invalidate. If
5078                   the CPU is in a physical addressing mode, then Address is a
5079                   physical address. If the CPU is in a virtual addressing mode,
5080                   then Address is a virtual address.
5081 
5082   @param  Length  The number of bytes to invalidate from the instruction cache.
5083 
5084   @return Address.
5085 
5086 **/
5087 VOID *
5088 EFIAPI
5089 AsmFlushCacheRange (
5090   IN      VOID                      *Address,
5091   IN      UINTN                     Length
5092   );
5093 
5094 
5095 /**
5096   Executes an FC instruction.
5097   Executes an FC instruction on the cache line specified by Address.
5098   The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
5099   An implementation may flush a larger region.  This function is only available on Itanium processors.
5100 
5101   @param Address    The Address of cache line to be flushed.
5102 
5103   @return The address of FC instruction executed.
5104 
5105 **/
5106 UINT64
5107 EFIAPI
5108 AsmFc (
5109   IN  UINT64  Address
5110   );
5111 
5112 
5113 /**
5114   Executes an FC.I instruction.
5115   Executes an FC.I instruction on the cache line specified by Address.
5116   The cache line size affected is at least 32-bytes (aligned on a 32-byte boundary).
5117   An implementation may flush a larger region.  This function is only available on Itanium processors.
5118 
5119   @param Address    The Address of cache line to be flushed.
5120 
5121   @return The address of the FC.I instruction executed.
5122 
5123 **/
5124 UINT64
5125 EFIAPI
5126 AsmFci (
5127   IN  UINT64  Address
5128   );
5129 
5130 
5131 /**
5132   Reads the current value of a Processor Identifier Register (CPUID).
5133 
5134   Reads and returns the current value of Processor Identifier Register specified by Index.
5135   The Index of largest implemented CPUID (One less than the number of implemented CPUID
5136   registers) is determined by CPUID [3] bits {7:0}.
5137   No parameter checking is performed on Index.  If the Index value is beyond the
5138   implemented CPUID register range, a Reserved Register/Field fault may occur.  The caller
5139   must either guarantee that Index is valid, or the caller must set up fault handlers to
5140   catch the faults.  This function is only available on Itanium processors.
5141 
5142   @param Index    The 8-bit Processor Identifier Register index to read.
5143 
5144   @return The current value of Processor Identifier Register specified by Index.
5145 
5146 **/
5147 UINT64
5148 EFIAPI
5149 AsmReadCpuid (
5150   IN  UINT8   Index
5151   );
5152 
5153 
5154 /**
5155   Reads the current value of 64-bit Processor Status Register (PSR).
5156   This function is only available on Itanium processors.
5157 
5158   @return The current value of PSR.
5159 
5160 **/
5161 UINT64
5162 EFIAPI
5163 AsmReadPsr (
5164   VOID
5165   );
5166 
5167 
5168 /**
5169   Writes the current value of 64-bit Processor Status Register (PSR).
5170 
5171   No parameter checking is performed on Value.  All bits of Value corresponding to
5172   reserved fields of PSR must be 0 or a Reserved Register/Field fault may occur.
5173   The caller must either guarantee that Value is valid, or the caller must set up
5174   fault handlers to catch the faults. This function is only available on Itanium processors.
5175 
5176   @param Value    The 64-bit value to write to PSR.
5177 
5178   @return The 64-bit value written to the PSR.
5179 
5180 **/
5181 UINT64
5182 EFIAPI
5183 AsmWritePsr (
5184   IN UINT64  Value
5185   );
5186 
5187 
5188 /**
5189   Reads the current value of 64-bit Kernel Register #0 (KR0).
5190 
5191   Reads and returns the current value of KR0.
5192   This function is only available on Itanium processors.
5193 
5194   @return The current value of KR0.
5195 
5196 **/
5197 UINT64
5198 EFIAPI
5199 AsmReadKr0 (
5200   VOID
5201   );
5202 
5203 
5204 /**
5205   Reads the current value of 64-bit Kernel Register #1 (KR1).
5206 
5207   Reads and returns the current value of KR1.
5208   This function is only available on Itanium processors.
5209 
5210   @return The current value of KR1.
5211 
5212 **/
5213 UINT64
5214 EFIAPI
5215 AsmReadKr1 (
5216   VOID
5217   );
5218 
5219 
5220 /**
5221   Reads the current value of 64-bit Kernel Register #2 (KR2).
5222 
5223   Reads and returns the current value of KR2.
5224   This function is only available on Itanium processors.
5225 
5226   @return The current value of KR2.
5227 
5228 **/
5229 UINT64
5230 EFIAPI
5231 AsmReadKr2 (
5232   VOID
5233   );
5234 
5235 
5236 /**
5237   Reads the current value of 64-bit Kernel Register #3 (KR3).
5238 
5239   Reads and returns the current value of KR3.
5240   This function is only available on Itanium processors.
5241 
5242   @return The current value of KR3.
5243 
5244 **/
5245 UINT64
5246 EFIAPI
5247 AsmReadKr3 (
5248   VOID
5249   );
5250 
5251 
5252 /**
5253   Reads the current value of 64-bit Kernel Register #4 (KR4).
5254 
5255   Reads and returns the current value of KR4.
5256   This function is only available on Itanium processors.
5257 
5258   @return The current value of KR4.
5259 
5260 **/
5261 UINT64
5262 EFIAPI
5263 AsmReadKr4 (
5264   VOID
5265   );
5266 
5267 
5268 /**
5269   Reads the current value of 64-bit Kernel Register #5 (KR5).
5270 
5271   Reads and returns the current value of KR5.
5272   This function is only available on Itanium processors.
5273 
5274   @return The current value of KR5.
5275 
5276 **/
5277 UINT64
5278 EFIAPI
5279 AsmReadKr5 (
5280   VOID
5281   );
5282 
5283 
5284 /**
5285   Reads the current value of 64-bit Kernel Register #6 (KR6).
5286 
5287   Reads and returns the current value of KR6.
5288   This function is only available on Itanium processors.
5289 
5290   @return The current value of KR6.
5291 
5292 **/
5293 UINT64
5294 EFIAPI
5295 AsmReadKr6 (
5296   VOID
5297   );
5298 
5299 
5300 /**
5301   Reads the current value of 64-bit Kernel Register #7 (KR7).
5302 
5303   Reads and returns the current value of KR7.
5304   This function is only available on Itanium processors.
5305 
5306   @return The current value of KR7.
5307 
5308 **/
5309 UINT64
5310 EFIAPI
5311 AsmReadKr7 (
5312   VOID
5313   );
5314 
5315 
5316 /**
5317   Write the current value of 64-bit Kernel Register #0 (KR0).
5318 
5319   Writes the current value of KR0.  The 64-bit value written to
5320   the KR0 is returned. This function is only available on Itanium processors.
5321 
5322   @param  Value   The 64-bit value to write to KR0.
5323 
5324   @return The 64-bit value written to the KR0.
5325 
5326 **/
5327 UINT64
5328 EFIAPI
5329 AsmWriteKr0 (
5330   IN UINT64  Value
5331   );
5332 
5333 
5334 /**
5335   Write the current value of 64-bit Kernel Register #1 (KR1).
5336 
5337   Writes the current value of KR1.  The 64-bit value written to
5338   the KR1 is returned. This function is only available on Itanium processors.
5339 
5340   @param  Value   The 64-bit value to write to KR1.
5341 
5342   @return The 64-bit value written to the KR1.
5343 
5344 **/
5345 UINT64
5346 EFIAPI
5347 AsmWriteKr1 (
5348   IN UINT64  Value
5349   );
5350 
5351 
5352 /**
5353   Write the current value of 64-bit Kernel Register #2 (KR2).
5354 
5355   Writes the current value of KR2.  The 64-bit value written to
5356   the KR2 is returned. This function is only available on Itanium processors.
5357 
5358   @param  Value   The 64-bit value to write to KR2.
5359 
5360   @return The 64-bit value written to the KR2.
5361 
5362 **/
5363 UINT64
5364 EFIAPI
5365 AsmWriteKr2 (
5366   IN UINT64  Value
5367   );
5368 
5369 
5370 /**
5371   Write the current value of 64-bit Kernel Register #3 (KR3).
5372 
5373   Writes the current value of KR3.  The 64-bit value written to
5374   the KR3 is returned. This function is only available on Itanium processors.
5375 
5376   @param  Value   The 64-bit value to write to KR3.
5377 
5378   @return The 64-bit value written to the KR3.
5379 
5380 **/
5381 UINT64
5382 EFIAPI
5383 AsmWriteKr3 (
5384   IN UINT64  Value
5385   );
5386 
5387 
5388 /**
5389   Write the current value of 64-bit Kernel Register #4 (KR4).
5390 
5391   Writes the current value of KR4.  The 64-bit value written to
5392   the KR4 is returned. This function is only available on Itanium processors.
5393 
5394   @param  Value   The 64-bit value to write to KR4.
5395 
5396   @return The 64-bit value written to the KR4.
5397 
5398 **/
5399 UINT64
5400 EFIAPI
5401 AsmWriteKr4 (
5402   IN UINT64  Value
5403   );
5404 
5405 
5406 /**
5407   Write the current value of 64-bit Kernel Register #5 (KR5).
5408 
5409   Writes the current value of KR5.  The 64-bit value written to
5410   the KR5 is returned. This function is only available on Itanium processors.
5411 
5412   @param  Value   The 64-bit value to write to KR5.
5413 
5414   @return The 64-bit value written to the KR5.
5415 
5416 **/
5417 UINT64
5418 EFIAPI
5419 AsmWriteKr5 (
5420   IN UINT64  Value
5421   );
5422 
5423 
5424 /**
5425   Write the current value of 64-bit Kernel Register #6 (KR6).
5426 
5427   Writes the current value of KR6.  The 64-bit value written to
5428   the KR6 is returned. This function is only available on Itanium processors.
5429 
5430   @param  Value   The 64-bit value to write to KR6.
5431 
5432   @return The 64-bit value written to the KR6.
5433 
5434 **/
5435 UINT64
5436 EFIAPI
5437 AsmWriteKr6 (
5438   IN UINT64  Value
5439   );
5440 
5441 
5442 /**
5443   Write the current value of 64-bit Kernel Register #7 (KR7).
5444 
5445   Writes the current value of KR7.  The 64-bit value written to
5446   the KR7 is returned. This function is only available on Itanium processors.
5447 
5448   @param  Value   The 64-bit value to write to KR7.
5449 
5450   @return The 64-bit value written to the KR7.
5451 
5452 **/
5453 UINT64
5454 EFIAPI
5455 AsmWriteKr7 (
5456   IN UINT64  Value
5457   );
5458 
5459 
5460 /**
5461   Reads the current value of Interval Timer Counter Register (ITC).
5462 
5463   Reads and returns the current value of ITC.
5464   This function is only available on Itanium processors.
5465 
5466   @return The current value of ITC.
5467 
5468 **/
5469 UINT64
5470 EFIAPI
5471 AsmReadItc (
5472   VOID
5473   );
5474 
5475 
5476 /**
5477   Reads the current value of Interval Timer Vector Register (ITV).
5478 
5479   Reads and returns the current value of ITV.
5480   This function is only available on Itanium processors.
5481 
5482   @return The current value of ITV.
5483 
5484 **/
5485 UINT64
5486 EFIAPI
5487 AsmReadItv (
5488   VOID
5489   );
5490 
5491 
5492 /**
5493   Reads the current value of Interval Timer Match Register (ITM).
5494 
5495   Reads and returns the current value of ITM.
5496   This function is only available on Itanium processors.
5497 
5498   @return The current value of ITM.
5499 **/
5500 UINT64
5501 EFIAPI
5502 AsmReadItm (
5503   VOID
5504   );
5505 
5506 
5507 /**
5508   Writes the current value of 64-bit Interval Timer Counter Register (ITC).
5509 
5510   Writes the current value of ITC.  The 64-bit value written to the ITC is returned.
5511   This function is only available on Itanium processors.
5512 
5513   @param Value    The 64-bit value to write to ITC.
5514 
5515   @return The 64-bit value written to the ITC.
5516 
5517 **/
5518 UINT64
5519 EFIAPI
5520 AsmWriteItc (
5521   IN UINT64  Value
5522   );
5523 
5524 
5525 /**
5526   Writes the current value of 64-bit Interval Timer Match Register (ITM).
5527 
5528   Writes the current value of ITM.  The 64-bit value written to the ITM is returned.
5529   This function is only available on Itanium processors.
5530 
5531   @param Value    The 64-bit value to write to ITM.
5532 
5533   @return The 64-bit value written to the ITM.
5534 
5535 **/
5536 UINT64
5537 EFIAPI
5538 AsmWriteItm (
5539   IN UINT64  Value
5540   );
5541 
5542 
5543 /**
5544   Writes the current value of 64-bit Interval Timer Vector Register (ITV).
5545 
5546   Writes the current value of ITV.  The 64-bit value written to the ITV is returned.
5547   No parameter checking is performed on Value.  All bits of Value corresponding to
5548   reserved fields of ITV must be 0 or a Reserved Register/Field fault may occur.
5549   The caller must either guarantee that Value is valid, or the caller must set up
5550   fault handlers to catch the faults.
5551   This function is only available on Itanium processors.
5552 
5553   @param Value    The 64-bit value to write to ITV.
5554 
5555   @return The 64-bit value written to the ITV.
5556 
5557 **/
5558 UINT64
5559 EFIAPI
5560 AsmWriteItv (
5561   IN UINT64  Value
5562   );
5563 
5564 
5565 /**
5566   Reads the current value of Default Control Register (DCR).
5567 
5568   Reads and returns the current value of DCR.  This function is only available on Itanium processors.
5569 
5570   @return The current value of DCR.
5571 
5572 **/
5573 UINT64
5574 EFIAPI
5575 AsmReadDcr (
5576   VOID
5577   );
5578 
5579 
5580 /**
5581   Reads the current value of Interruption Vector Address Register (IVA).
5582 
5583   Reads and returns the current value of IVA.  This function is only available on Itanium processors.
5584 
5585   @return The current value of IVA.
5586 **/
5587 UINT64
5588 EFIAPI
5589 AsmReadIva (
5590   VOID
5591   );
5592 
5593 
5594 /**
5595   Reads the current value of Page Table Address Register (PTA).
5596 
5597   Reads and returns the current value of PTA.  This function is only available on Itanium processors.
5598 
5599   @return The current value of PTA.
5600 
5601 **/
5602 UINT64
5603 EFIAPI
5604 AsmReadPta (
5605   VOID
5606   );
5607 
5608 
5609 /**
5610   Writes the current value of 64-bit Default Control Register (DCR).
5611 
5612   Writes the current value of DCR.  The 64-bit value written to the DCR is returned.
5613   No parameter checking is performed on Value.  All bits of Value corresponding to
5614   reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
5615   The caller must either guarantee that Value is valid, or the caller must set up
5616   fault handlers to catch the faults.
5617   This function is only available on Itanium processors.
5618 
5619   @param Value    The 64-bit value to write to DCR.
5620 
5621   @return The 64-bit value written to the DCR.
5622 
5623 **/
5624 UINT64
5625 EFIAPI
5626 AsmWriteDcr (
5627   IN UINT64  Value
5628   );
5629 
5630 
5631 /**
5632   Writes the current value of 64-bit Interruption Vector Address Register (IVA).
5633 
5634   Writes the current value of IVA.  The 64-bit value written to the IVA is returned.
5635   The size of vector table is 32 K bytes and is 32 K bytes aligned
5636   the low 15 bits of Value is ignored when written.
5637   This function is only available on Itanium processors.
5638 
5639   @param Value    The 64-bit value to write to IVA.
5640 
5641   @return The 64-bit value written to the IVA.
5642 
5643 **/
5644 UINT64
5645 EFIAPI
5646 AsmWriteIva (
5647   IN UINT64  Value
5648   );
5649 
5650 
5651 /**
5652   Writes the current value of 64-bit Page Table Address Register (PTA).
5653 
5654   Writes the current value of PTA.  The 64-bit value written to the PTA is returned.
5655   No parameter checking is performed on Value.  All bits of Value corresponding to
5656   reserved fields of DCR must be 0 or a Reserved Register/Field fault may occur.
5657   The caller must either guarantee that Value is valid, or the caller must set up
5658   fault handlers to catch the faults.
5659   This function is only available on Itanium processors.
5660 
5661   @param Value    The 64-bit value to write to PTA.
5662 
5663   @return The 64-bit value written to the PTA.
5664 **/
5665 UINT64
5666 EFIAPI
5667 AsmWritePta (
5668   IN UINT64  Value
5669   );
5670 
5671 
5672 /**
5673   Reads the current value of Local Interrupt ID Register (LID).
5674 
5675   Reads and returns the current value of LID.  This function is only available on Itanium processors.
5676 
5677   @return The current value of LID.
5678 
5679 **/
5680 UINT64
5681 EFIAPI
5682 AsmReadLid (
5683   VOID
5684   );
5685 
5686 
5687 /**
5688   Reads the current value of External Interrupt Vector Register (IVR).
5689 
5690   Reads and returns the current value of IVR.  This function is only available on Itanium processors.
5691 
5692   @return The current value of IVR.
5693 
5694 **/
5695 UINT64
5696 EFIAPI
5697 AsmReadIvr (
5698   VOID
5699   );
5700 
5701 
5702 /**
5703   Reads the current value of Task Priority Register (TPR).
5704 
5705   Reads and returns the current value of TPR.  This function is only available on Itanium processors.
5706 
5707   @return The current value of TPR.
5708 
5709 **/
5710 UINT64
5711 EFIAPI
5712 AsmReadTpr (
5713   VOID
5714   );
5715 
5716 
5717 /**
5718   Reads the current value of External Interrupt Request Register #0 (IRR0).
5719 
5720   Reads and returns the current value of IRR0.  This function is only available on Itanium processors.
5721 
5722   @return The current value of IRR0.
5723 
5724 **/
5725 UINT64
5726 EFIAPI
5727 AsmReadIrr0 (
5728   VOID
5729   );
5730 
5731 
5732 /**
5733   Reads the current value of External Interrupt Request Register #1 (IRR1).
5734 
5735   Reads and returns the current value of IRR1.  This function is only available on Itanium processors.
5736 
5737   @return The current value of IRR1.
5738 
5739 **/
5740 UINT64
5741 EFIAPI
5742 AsmReadIrr1 (
5743   VOID
5744   );
5745 
5746 
5747 /**
5748   Reads the current value of External Interrupt Request Register #2 (IRR2).
5749 
5750   Reads and returns the current value of IRR2.  This function is only available on Itanium processors.
5751 
5752   @return The current value of IRR2.
5753 
5754 **/
5755 UINT64
5756 EFIAPI
5757 AsmReadIrr2 (
5758   VOID
5759   );
5760 
5761 
5762 /**
5763   Reads the current value of External Interrupt Request Register #3 (IRR3).
5764 
5765   Reads and returns the current value of IRR3.  This function is only available on Itanium processors.
5766 
5767   @return The current value of IRR3.
5768 
5769 **/
5770 UINT64
5771 EFIAPI
5772 AsmReadIrr3 (
5773   VOID
5774   );
5775 
5776 
5777 /**
5778   Reads the current value of Performance Monitor Vector Register (PMV).
5779 
5780   Reads and returns the current value of PMV.  This function is only available on Itanium processors.
5781 
5782   @return The current value of PMV.
5783 
5784 **/
5785 UINT64
5786 EFIAPI
5787 AsmReadPmv (
5788   VOID
5789   );
5790 
5791 
5792 /**
5793   Reads the current value of Corrected Machine Check Vector Register (CMCV).
5794 
5795   Reads and returns the current value of CMCV.  This function is only available on Itanium processors.
5796 
5797   @return The current value of CMCV.
5798 
5799 **/
5800 UINT64
5801 EFIAPI
5802 AsmReadCmcv (
5803   VOID
5804   );
5805 
5806 
5807 /**
5808   Reads the current value of Local Redirection Register #0 (LRR0).
5809 
5810   Reads and returns the current value of LRR0.  This function is only available on Itanium processors.
5811 
5812   @return The current value of LRR0.
5813 
5814 **/
5815 UINT64
5816 EFIAPI
5817 AsmReadLrr0 (
5818   VOID
5819   );
5820 
5821 
5822 /**
5823   Reads the current value of Local Redirection Register #1 (LRR1).
5824 
5825   Reads and returns the current value of LRR1.  This function is only available on Itanium processors.
5826 
5827   @return The current value of LRR1.
5828 
5829 **/
5830 UINT64
5831 EFIAPI
5832 AsmReadLrr1 (
5833   VOID
5834   );
5835 
5836 
5837 /**
5838   Writes the current value of 64-bit Page Local Interrupt ID Register (LID).
5839 
5840   Writes the current value of LID.  The 64-bit value written to the LID is returned.
5841   No parameter checking is performed on Value.  All bits of Value corresponding to
5842   reserved fields of LID must be 0 or a Reserved Register/Field fault may occur.
5843   The caller must either guarantee that Value is valid, or the caller must set up
5844   fault handlers to catch the faults.
5845   This function is only available on Itanium processors.
5846 
5847   @param Value    The 64-bit value to write to LID.
5848 
5849   @return The 64-bit value written to the LID.
5850 
5851 **/
5852 UINT64
5853 EFIAPI
5854 AsmWriteLid (
5855   IN UINT64  Value
5856   );
5857 
5858 
5859 /**
5860   Writes the current value of 64-bit Task Priority Register (TPR).
5861 
5862   Writes the current value of TPR.  The 64-bit value written to the TPR is returned.
5863   No parameter checking is performed on Value.  All bits of Value corresponding to
5864   reserved fields of TPR must be 0 or a Reserved Register/Field fault may occur.
5865   The caller must either guarantee that Value is valid, or the caller must set up
5866   fault handlers to catch the faults.
5867   This function is only available on Itanium processors.
5868 
5869   @param Value    The 64-bit value to write to TPR.
5870 
5871   @return The 64-bit value written to the TPR.
5872 
5873 **/
5874 UINT64
5875 EFIAPI
5876 AsmWriteTpr (
5877   IN UINT64  Value
5878   );
5879 
5880 
5881 /**
5882   Performs a write operation on End OF External Interrupt Register (EOI).
5883 
5884   Writes a value of 0 to the EOI Register.  This function is only available on Itanium processors.
5885 
5886 **/
5887 VOID
5888 EFIAPI
5889 AsmWriteEoi (
5890   VOID
5891   );
5892 
5893 
5894 /**
5895   Writes the current value of 64-bit Performance Monitor Vector Register (PMV).
5896 
5897   Writes the current value of PMV.  The 64-bit value written to the PMV is returned.
5898   No parameter checking is performed on Value.  All bits of Value corresponding
5899   to reserved fields of PMV must be 0 or a Reserved Register/Field fault may occur.
5900   The caller must either guarantee that Value is valid, or the caller must set up
5901   fault handlers to catch the faults.
5902   This function is only available on Itanium processors.
5903 
5904   @param Value    The 64-bit value to write to PMV.
5905 
5906   @return The 64-bit value written to the PMV.
5907 
5908 **/
5909 UINT64
5910 EFIAPI
5911 AsmWritePmv (
5912   IN UINT64  Value
5913   );
5914 
5915 
5916 /**
5917   Writes the current value of 64-bit Corrected Machine Check Vector Register (CMCV).
5918 
5919   Writes the current value of CMCV.  The 64-bit value written to the CMCV is returned.
5920   No parameter checking is performed on Value.  All bits of Value corresponding
5921   to reserved fields of CMCV must be 0 or a Reserved Register/Field fault may occur.
5922   The caller must either guarantee that Value is valid, or the caller must set up
5923   fault handlers to catch the faults.
5924   This function is only available on Itanium processors.
5925 
5926   @param Value    The 64-bit value to write to CMCV.
5927 
5928   @return The 64-bit value written to the CMCV.
5929 
5930 **/
5931 UINT64
5932 EFIAPI
5933 AsmWriteCmcv (
5934   IN UINT64  Value
5935   );
5936 
5937 
5938 /**
5939   Writes the current value of 64-bit Local Redirection Register #0 (LRR0).
5940 
5941   Writes the current value of LRR0.  The 64-bit value written to the LRR0 is returned.
5942   No parameter checking is performed on Value.  All bits of Value corresponding
5943   to reserved fields of LRR0 must be 0 or a Reserved Register/Field fault may occur.
5944   The caller must either guarantee that Value is valid, or the caller must set up
5945   fault handlers to catch the faults.
5946   This function is only available on Itanium processors.
5947 
5948   @param Value    The 64-bit value to write to LRR0.
5949 
5950   @return The 64-bit value written to the LRR0.
5951 
5952 **/
5953 UINT64
5954 EFIAPI
5955 AsmWriteLrr0 (
5956   IN UINT64  Value
5957   );
5958 
5959 
5960 /**
5961   Writes the current value of 64-bit Local Redirection Register #1 (LRR1).
5962 
5963   Writes the current value of LRR1.  The 64-bit value written to the LRR1 is returned.
5964   No parameter checking is performed on Value.  All bits of Value corresponding
5965   to reserved fields of LRR1 must be 0 or a Reserved Register/Field fault may occur.
5966   The caller must either guarantee that Value is valid, or the caller must
5967   set up fault handlers to catch the faults.
5968   This function is only available on Itanium processors.
5969 
5970   @param Value    The 64-bit value to write to LRR1.
5971 
5972   @return The 64-bit value written to the LRR1.
5973 
5974 **/
5975 UINT64
5976 EFIAPI
5977 AsmWriteLrr1 (
5978   IN UINT64  Value
5979   );
5980 
5981 
5982 /**
5983   Reads the current value of Instruction Breakpoint Register (IBR).
5984 
5985   The Instruction Breakpoint Registers are used in pairs.  The even numbered
5986   registers contain breakpoint addresses, and the odd numbered registers contain
5987   breakpoint mask conditions.  At least four instruction registers pairs are implemented
5988   on all processor models.   Implemented registers are contiguous starting with
5989   register 0.  No parameter checking is performed on Index, and if the Index value
5990   is beyond the implemented IBR register range, a Reserved Register/Field fault may
5991   occur.  The caller must either guarantee that Index is valid, or the caller must
5992   set up fault handlers to catch the faults.
5993   This function is only available on Itanium processors.
5994 
5995   @param Index    The 8-bit Instruction Breakpoint Register index to read.
5996 
5997   @return The current value of Instruction Breakpoint Register specified by Index.
5998 
5999 **/
6000 UINT64
6001 EFIAPI
6002 AsmReadIbr (
6003   IN  UINT8   Index
6004   );
6005 
6006 
6007 /**
6008   Reads the current value of Data Breakpoint Register (DBR).
6009 
6010   The Data Breakpoint Registers are used in pairs.  The even numbered registers
6011   contain breakpoint addresses, and odd numbered registers contain breakpoint
6012   mask conditions.  At least four data registers pairs are implemented on all processor
6013   models.  Implemented registers are contiguous starting with register 0.
6014   No parameter checking is performed on Index.  If the Index value is beyond
6015   the implemented DBR register range, a Reserved Register/Field fault may occur.
6016   The caller must either guarantee that Index is valid, or the caller must set up
6017   fault handlers to catch the faults.
6018   This function is only available on Itanium processors.
6019 
6020   @param Index    The 8-bit Data Breakpoint Register index to read.
6021 
6022   @return The current value of Data Breakpoint Register specified by Index.
6023 
6024 **/
6025 UINT64
6026 EFIAPI
6027 AsmReadDbr (
6028   IN  UINT8   Index
6029   );
6030 
6031 
6032 /**
6033   Reads the current value of Performance Monitor Configuration Register (PMC).
6034 
6035   All processor implementations provide at least four performance counters
6036   (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow
6037   status registers (PMC [0]... PMC [3]).  Processor implementations may provide
6038   additional implementation-dependent PMC and PMD to increase the number of
6039   'generic' performance counters (PMC/PMD pairs).  The remainder of PMC and PMD
6040   register set is implementation dependent.  No parameter checking is performed
6041   on Index.  If the Index value is beyond the implemented PMC register range,
6042   zero value will be returned.
6043   This function is only available on Itanium processors.
6044 
6045   @param Index    The 8-bit Performance Monitor Configuration Register index to read.
6046 
6047   @return   The current value of Performance Monitor Configuration Register
6048             specified by Index.
6049 
6050 **/
6051 UINT64
6052 EFIAPI
6053 AsmReadPmc (
6054   IN  UINT8   Index
6055   );
6056 
6057 
6058 /**
6059   Reads the current value of Performance Monitor Data Register (PMD).
6060 
6061   All processor implementations provide at least 4 performance counters
6062   (PMC/PMD [4]...PMC/PMD [7] pairs), and 4 performance monitor counter
6063   overflow status registers (PMC [0]... PMC [3]).  Processor implementations may
6064   provide additional implementation-dependent PMC and PMD to increase the number
6065   of 'generic' performance counters (PMC/PMD pairs).  The remainder of PMC and PMD
6066   register set is implementation dependent.  No parameter checking is performed
6067   on Index.  If the Index value is beyond the implemented PMD register range,
6068   zero value will be returned.
6069   This function is only available on Itanium processors.
6070 
6071   @param Index    The 8-bit Performance Monitor Data Register index to read.
6072 
6073   @return The current value of Performance Monitor Data Register specified by Index.
6074 
6075 **/
6076 UINT64
6077 EFIAPI
6078 AsmReadPmd (
6079   IN  UINT8   Index
6080   );
6081 
6082 
6083 /**
6084   Writes the current value of 64-bit Instruction Breakpoint Register (IBR).
6085 
6086   Writes current value of Instruction Breakpoint Register specified by Index.
6087   The Instruction Breakpoint Registers are used in pairs.  The even numbered
6088   registers contain breakpoint addresses, and odd numbered registers contain
6089   breakpoint mask conditions.  At least four instruction registers pairs are implemented
6090   on all processor models.  Implemented registers are contiguous starting with
6091   register 0.  No parameter checking is performed on Index.  If the Index value
6092   is beyond the implemented IBR register range, a Reserved Register/Field fault may
6093   occur.  The caller must either guarantee that Index is valid, or the caller must
6094   set up fault handlers to catch the faults.
6095   This function is only available on Itanium processors.
6096 
6097   @param Index    The 8-bit Instruction Breakpoint Register index to write.
6098   @param Value    The 64-bit value to write to IBR.
6099 
6100   @return The 64-bit value written to the IBR.
6101 
6102 **/
6103 UINT64
6104 EFIAPI
6105 AsmWriteIbr (
6106   IN UINT8   Index,
6107   IN UINT64  Value
6108   );
6109 
6110 
6111 /**
6112   Writes the current value of 64-bit Data Breakpoint Register (DBR).
6113 
6114   Writes current value of Data Breakpoint Register specified by Index.
6115   The Data Breakpoint Registers are used in pairs.  The even numbered registers
6116   contain breakpoint addresses, and odd numbered registers contain breakpoint
6117   mask conditions.  At least four data registers pairs are implemented on all processor
6118   models.  Implemented registers are contiguous starting with register 0.  No parameter
6119   checking is performed on Index.  If the Index value is beyond the implemented
6120   DBR register range, a Reserved Register/Field fault may occur.  The caller must
6121   either guarantee that Index is valid, or the caller must set up fault handlers to
6122   catch the faults.
6123   This function is only available on Itanium processors.
6124 
6125   @param Index    The 8-bit Data Breakpoint Register index to write.
6126   @param Value    The 64-bit value to write to DBR.
6127 
6128   @return The 64-bit value written to the DBR.
6129 
6130 **/
6131 UINT64
6132 EFIAPI
6133 AsmWriteDbr (
6134   IN UINT8   Index,
6135   IN UINT64  Value
6136   );
6137 
6138 
6139 /**
6140   Writes the current value of 64-bit Performance Monitor Configuration Register (PMC).
6141 
6142   Writes current value of Performance Monitor Configuration Register specified by Index.
6143   All processor implementations provide at least four performance counters
6144   (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow status
6145   registers (PMC [0]... PMC [3]).  Processor implementations may provide additional
6146   implementation-dependent PMC and PMD to increase the number of 'generic' performance
6147   counters (PMC/PMD pairs).  The remainder of PMC and PMD register set is implementation
6148   dependent.  No parameter checking is performed on Index.  If the Index value is
6149   beyond the implemented PMC register range, the write is ignored.
6150   This function is only available on Itanium processors.
6151 
6152   @param Index    The 8-bit Performance Monitor Configuration Register index to write.
6153   @param Value    The 64-bit value to write to PMC.
6154 
6155   @return The 64-bit value written to the PMC.
6156 
6157 **/
6158 UINT64
6159 EFIAPI
6160 AsmWritePmc (
6161   IN UINT8   Index,
6162   IN UINT64  Value
6163   );
6164 
6165 
6166 /**
6167   Writes the current value of 64-bit Performance Monitor Data Register (PMD).
6168 
6169   Writes current value of Performance Monitor Data Register specified by Index.
6170   All processor implementations provide at least four performance counters
6171   (PMC/PMD [4]...PMC/PMD [7] pairs), and four performance monitor counter overflow
6172   status registers (PMC [0]... PMC [3]).  Processor implementations may provide
6173   additional implementation-dependent PMC and PMD to increase the number of 'generic'
6174   performance counters (PMC/PMD pairs).  The remainder of PMC and PMD register set
6175   is implementation dependent.  No parameter checking is performed on Index.  If the
6176   Index value is beyond the implemented PMD register range, the write is ignored.
6177   This function is only available on Itanium processors.
6178 
6179   @param Index    The 8-bit Performance Monitor Data Register index to write.
6180   @param Value    The 64-bit value to write to PMD.
6181 
6182   @return The 64-bit value written to the PMD.
6183 
6184 **/
6185 UINT64
6186 EFIAPI
6187 AsmWritePmd (
6188   IN UINT8   Index,
6189   IN UINT64  Value
6190   );
6191 
6192 
6193 /**
6194   Reads the current value of 64-bit Global Pointer (GP).
6195 
6196   Reads and returns the current value of GP.
6197   This function is only available on Itanium processors.
6198 
6199   @return The current value of GP.
6200 
6201 **/
6202 UINT64
6203 EFIAPI
6204 AsmReadGp (
6205   VOID
6206   );
6207 
6208 
6209 /**
6210   Write the current value of 64-bit Global Pointer (GP).
6211 
6212   Writes the current value of GP. The 64-bit value written to the GP is returned.
6213   No parameter checking is performed on Value.
6214   This function is only available on Itanium processors.
6215 
6216   @param Value  The 64-bit value to write to GP.
6217 
6218   @return The 64-bit value written to the GP.
6219 
6220 **/
6221 UINT64
6222 EFIAPI
6223 AsmWriteGp (
6224   IN UINT64  Value
6225   );
6226 
6227 
6228 /**
6229   Reads the current value of 64-bit Stack Pointer (SP).
6230 
6231   Reads and returns the current value of SP.
6232   This function is only available on Itanium processors.
6233 
6234   @return The current value of SP.
6235 
6236 **/
6237 UINT64
6238 EFIAPI
6239 AsmReadSp (
6240   VOID
6241   );
6242 
6243 
6244 ///
6245 /// Valid Index value for AsmReadControlRegister().
6246 ///
6247 #define IPF_CONTROL_REGISTER_DCR   0
6248 #define IPF_CONTROL_REGISTER_ITM   1
6249 #define IPF_CONTROL_REGISTER_IVA   2
6250 #define IPF_CONTROL_REGISTER_PTA   8
6251 #define IPF_CONTROL_REGISTER_IPSR  16
6252 #define IPF_CONTROL_REGISTER_ISR   17
6253 #define IPF_CONTROL_REGISTER_IIP   19
6254 #define IPF_CONTROL_REGISTER_IFA   20
6255 #define IPF_CONTROL_REGISTER_ITIR  21
6256 #define IPF_CONTROL_REGISTER_IIPA  22
6257 #define IPF_CONTROL_REGISTER_IFS   23
6258 #define IPF_CONTROL_REGISTER_IIM   24
6259 #define IPF_CONTROL_REGISTER_IHA   25
6260 #define IPF_CONTROL_REGISTER_LID   64
6261 #define IPF_CONTROL_REGISTER_IVR   65
6262 #define IPF_CONTROL_REGISTER_TPR   66
6263 #define IPF_CONTROL_REGISTER_EOI   67
6264 #define IPF_CONTROL_REGISTER_IRR0  68
6265 #define IPF_CONTROL_REGISTER_IRR1  69
6266 #define IPF_CONTROL_REGISTER_IRR2  70
6267 #define IPF_CONTROL_REGISTER_IRR3  71
6268 #define IPF_CONTROL_REGISTER_ITV   72
6269 #define IPF_CONTROL_REGISTER_PMV   73
6270 #define IPF_CONTROL_REGISTER_CMCV  74
6271 #define IPF_CONTROL_REGISTER_LRR0  80
6272 #define IPF_CONTROL_REGISTER_LRR1  81
6273 
6274 /**
6275   Reads a 64-bit control register.
6276 
6277   Reads and returns the control register specified by Index. The valid Index valued
6278   are defined above in "Related Definitions".
6279   If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned.  This function is only
6280   available on Itanium processors.
6281 
6282   @param  Index                     The index of the control register to read.
6283 
6284   @return The control register specified by Index.
6285 
6286 **/
6287 UINT64
6288 EFIAPI
6289 AsmReadControlRegister (
6290   IN UINT64  Index
6291   );
6292 
6293 
6294 ///
6295 /// Valid Index value for AsmReadApplicationRegister().
6296 ///
6297 #define IPF_APPLICATION_REGISTER_K0        0
6298 #define IPF_APPLICATION_REGISTER_K1        1
6299 #define IPF_APPLICATION_REGISTER_K2        2
6300 #define IPF_APPLICATION_REGISTER_K3        3
6301 #define IPF_APPLICATION_REGISTER_K4        4
6302 #define IPF_APPLICATION_REGISTER_K5        5
6303 #define IPF_APPLICATION_REGISTER_K6        6
6304 #define IPF_APPLICATION_REGISTER_K7        7
6305 #define IPF_APPLICATION_REGISTER_RSC       16
6306 #define IPF_APPLICATION_REGISTER_BSP       17
6307 #define IPF_APPLICATION_REGISTER_BSPSTORE  18
6308 #define IPF_APPLICATION_REGISTER_RNAT      19
6309 #define IPF_APPLICATION_REGISTER_FCR       21
6310 #define IPF_APPLICATION_REGISTER_EFLAG     24
6311 #define IPF_APPLICATION_REGISTER_CSD       25
6312 #define IPF_APPLICATION_REGISTER_SSD       26
6313 #define IPF_APPLICATION_REGISTER_CFLG      27
6314 #define IPF_APPLICATION_REGISTER_FSR       28
6315 #define IPF_APPLICATION_REGISTER_FIR       29
6316 #define IPF_APPLICATION_REGISTER_FDR       30
6317 #define IPF_APPLICATION_REGISTER_CCV       32
6318 #define IPF_APPLICATION_REGISTER_UNAT      36
6319 #define IPF_APPLICATION_REGISTER_FPSR      40
6320 #define IPF_APPLICATION_REGISTER_ITC       44
6321 #define IPF_APPLICATION_REGISTER_PFS       64
6322 #define IPF_APPLICATION_REGISTER_LC        65
6323 #define IPF_APPLICATION_REGISTER_EC        66
6324 
6325 /**
6326   Reads a 64-bit application register.
6327 
6328   Reads and returns the application register specified by Index. The valid Index
6329   valued are defined above in "Related Definitions".
6330   If Index is invalid then 0xFFFFFFFFFFFFFFFF is returned.  This function is only
6331   available on Itanium processors.
6332 
6333   @param  Index                     The index of the application register to read.
6334 
6335   @return The application register specified by Index.
6336 
6337 **/
6338 UINT64
6339 EFIAPI
6340 AsmReadApplicationRegister (
6341   IN UINT64  Index
6342   );
6343 
6344 
6345 /**
6346   Reads the current value of a Machine Specific Register (MSR).
6347 
6348   Reads and returns the current value of the Machine Specific Register specified by Index.  No
6349   parameter checking is performed on Index, and if the Index value is beyond the implemented MSR
6350   register range, a Reserved Register/Field fault may occur.  The caller must either guarantee that
6351   Index is valid, or the caller must set up fault handlers to catch the faults.  This function is
6352   only available on Itanium processors.
6353 
6354   @param  Index                     The 8-bit Machine Specific Register index to read.
6355 
6356   @return The current value of the Machine Specific Register specified by Index.
6357 
6358 **/
6359 UINT64
6360 EFIAPI
6361 AsmReadMsr (
6362   IN UINT8   Index
6363   );
6364 
6365 
6366 /**
6367   Writes the current value of a Machine Specific Register (MSR).
6368 
6369   Writes Value to the Machine Specific Register specified by Index.  Value is returned.  No
6370   parameter checking is performed on Index, and if the Index value is beyond the implemented MSR
6371   register range, a Reserved Register/Field fault may occur.  The caller must either guarantee that
6372   Index is valid, or the caller must set up fault handlers to catch the faults.  This function is
6373   only available on Itanium processors.
6374 
6375   @param  Index                     The 8-bit Machine Specific Register index to write.
6376   @param  Value                     The 64-bit value to write to the Machine Specific Register.
6377 
6378   @return The 64-bit value to write to the Machine Specific Register.
6379 
6380 **/
6381 UINT64
6382 EFIAPI
6383 AsmWriteMsr (
6384   IN UINT8   Index,
6385   IN UINT64  Value
6386   );
6387 
6388 
6389 /**
6390   Determines if the CPU is currently executing in virtual, physical, or mixed mode.
6391 
6392   Determines the current execution mode of the CPU.
6393   If the CPU is in virtual mode(PSR.RT=1, PSR.DT=1, PSR.IT=1), then 1 is returned.
6394   If the CPU is in physical mode(PSR.RT=0, PSR.DT=0, PSR.IT=0), then 0 is returned.
6395   If the CPU is not in physical mode or virtual mode, then it is in mixed mode,
6396   and -1 is returned.
6397   This function is only available on Itanium processors.
6398 
6399   @retval  1  The CPU is in virtual mode.
6400   @retval  0  The CPU is in physical mode.
6401   @retval -1  The CPU is in mixed mode.
6402 
6403 **/
6404 INT64
6405 EFIAPI
6406 AsmCpuVirtual (
6407   VOID
6408   );
6409 
6410 
6411 /**
6412   Makes a PAL procedure call.
6413 
6414   This is a wrapper function to make a PAL procedure call.  Based on the Index
6415   value this API will make static or stacked PAL call.  The following table
6416   describes the usage of PAL Procedure Index Assignment. Architected procedures
6417   may be designated as required or optional.  If a PAL procedure is specified
6418   as optional, a unique return code of 0xFFFFFFFFFFFFFFFF is returned in the
6419   Status field of the PAL_CALL_RETURN structure.
6420   This indicates that the procedure is not present in this PAL implementation.
6421   It is the caller's responsibility to check for this return code after calling
6422   any optional PAL procedure.
6423   No parameter checking is performed on the 5 input parameters, but there are
6424   some common rules that the caller should follow when making a PAL call.  Any
6425   address passed to PAL as buffers for return parameters must be 8-byte aligned.
6426   Unaligned addresses may cause undefined results.  For those parameters defined
6427   as reserved or some fields defined as reserved must be zero filled or the invalid
6428   argument return value may be returned or undefined result may occur during the
6429   execution of the procedure.  If the PalEntryPoint  does not point to a valid
6430   PAL entry point then the system behavior is undefined.  This function is only
6431   available on Itanium processors.
6432 
6433   @param PalEntryPoint  The PAL procedure calls entry point.
6434   @param Index          The PAL procedure Index number.
6435   @param Arg2           The 2nd parameter for PAL procedure calls.
6436   @param Arg3           The 3rd parameter for PAL procedure calls.
6437   @param Arg4           The 4th parameter for PAL procedure calls.
6438 
6439   @return structure returned from the PAL Call procedure, including the status and return value.
6440 
6441 **/
6442 PAL_CALL_RETURN
6443 EFIAPI
6444 AsmPalCall (
6445   IN UINT64  PalEntryPoint,
6446   IN UINT64  Index,
6447   IN UINT64  Arg2,
6448   IN UINT64  Arg3,
6449   IN UINT64  Arg4
6450   );
6451 #endif
6452 
6453 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
6454 ///
6455 /// IA32 and x64 Specific Functions.
6456 /// Byte packed structure for 16-bit Real Mode EFLAGS.
6457 ///
6458 typedef union {
6459   struct {
6460     UINT32  CF:1;           ///< Carry Flag.
6461     UINT32  Reserved_0:1;   ///< Reserved.
6462     UINT32  PF:1;           ///< Parity Flag.
6463     UINT32  Reserved_1:1;   ///< Reserved.
6464     UINT32  AF:1;           ///< Auxiliary Carry Flag.
6465     UINT32  Reserved_2:1;   ///< Reserved.
6466     UINT32  ZF:1;           ///< Zero Flag.
6467     UINT32  SF:1;           ///< Sign Flag.
6468     UINT32  TF:1;           ///< Trap Flag.
6469     UINT32  IF:1;           ///< Interrupt Enable Flag.
6470     UINT32  DF:1;           ///< Direction Flag.
6471     UINT32  OF:1;           ///< Overflow Flag.
6472     UINT32  IOPL:2;         ///< I/O Privilege Level.
6473     UINT32  NT:1;           ///< Nested Task.
6474     UINT32  Reserved_3:1;   ///< Reserved.
6475   } Bits;
6476   UINT16    Uint16;
6477 } IA32_FLAGS16;
6478 
6479 ///
6480 /// Byte packed structure for EFLAGS/RFLAGS.
6481 /// 32-bits on IA-32.
6482 /// 64-bits on x64.  The upper 32-bits on x64 are reserved.
6483 ///
6484 typedef union {
6485   struct {
6486     UINT32  CF:1;           ///< Carry Flag.
6487     UINT32  Reserved_0:1;   ///< Reserved.
6488     UINT32  PF:1;           ///< Parity Flag.
6489     UINT32  Reserved_1:1;   ///< Reserved.
6490     UINT32  AF:1;           ///< Auxiliary Carry Flag.
6491     UINT32  Reserved_2:1;   ///< Reserved.
6492     UINT32  ZF:1;           ///< Zero Flag.
6493     UINT32  SF:1;           ///< Sign Flag.
6494     UINT32  TF:1;           ///< Trap Flag.
6495     UINT32  IF:1;           ///< Interrupt Enable Flag.
6496     UINT32  DF:1;           ///< Direction Flag.
6497     UINT32  OF:1;           ///< Overflow Flag.
6498     UINT32  IOPL:2;         ///< I/O Privilege Level.
6499     UINT32  NT:1;           ///< Nested Task.
6500     UINT32  Reserved_3:1;   ///< Reserved.
6501     UINT32  RF:1;           ///< Resume Flag.
6502     UINT32  VM:1;           ///< Virtual 8086 Mode.
6503     UINT32  AC:1;           ///< Alignment Check.
6504     UINT32  VIF:1;          ///< Virtual Interrupt Flag.
6505     UINT32  VIP:1;          ///< Virtual Interrupt Pending.
6506     UINT32  ID:1;           ///< ID Flag.
6507     UINT32  Reserved_4:10;  ///< Reserved.
6508   } Bits;
6509   UINTN     UintN;
6510 } IA32_EFLAGS32;
6511 
6512 ///
6513 /// Byte packed structure for Control Register 0 (CR0).
6514 /// 32-bits on IA-32.
6515 /// 64-bits on x64.  The upper 32-bits on x64 are reserved.
6516 ///
6517 typedef union {
6518   struct {
6519     UINT32  PE:1;           ///< Protection Enable.
6520     UINT32  MP:1;           ///< Monitor Coprocessor.
6521     UINT32  EM:1;           ///< Emulation.
6522     UINT32  TS:1;           ///< Task Switched.
6523     UINT32  ET:1;           ///< Extension Type.
6524     UINT32  NE:1;           ///< Numeric Error.
6525     UINT32  Reserved_0:10;  ///< Reserved.
6526     UINT32  WP:1;           ///< Write Protect.
6527     UINT32  Reserved_1:1;   ///< Reserved.
6528     UINT32  AM:1;           ///< Alignment Mask.
6529     UINT32  Reserved_2:10;  ///< Reserved.
6530     UINT32  NW:1;           ///< Mot Write-through.
6531     UINT32  CD:1;           ///< Cache Disable.
6532     UINT32  PG:1;           ///< Paging.
6533   } Bits;
6534   UINTN     UintN;
6535 } IA32_CR0;
6536 
6537 ///
6538 /// Byte packed structure for Control Register 4 (CR4).
6539 /// 32-bits on IA-32.
6540 /// 64-bits on x64.  The upper 32-bits on x64 are reserved.
6541 ///
6542 typedef union {
6543   struct {
6544     UINT32  VME:1;          ///< Virtual-8086 Mode Extensions.
6545     UINT32  PVI:1;          ///< Protected-Mode Virtual Interrupts.
6546     UINT32  TSD:1;          ///< Time Stamp Disable.
6547     UINT32  DE:1;           ///< Debugging Extensions.
6548     UINT32  PSE:1;          ///< Page Size Extensions.
6549     UINT32  PAE:1;          ///< Physical Address Extension.
6550     UINT32  MCE:1;          ///< Machine Check Enable.
6551     UINT32  PGE:1;          ///< Page Global Enable.
6552     UINT32  PCE:1;          ///< Performance Monitoring Counter
6553                             ///< Enable.
6554     UINT32  OSFXSR:1;       ///< Operating System Support for
6555                             ///< FXSAVE and FXRSTOR instructions
6556     UINT32  OSXMMEXCPT:1;   ///< Operating System Support for
6557                             ///< Unmasked SIMD Floating Point
6558                             ///< Exceptions.
6559     UINT32  Reserved_0:2;   ///< Reserved.
6560     UINT32  VMXE:1;         ///< VMX Enable
6561     UINT32  Reserved_1:18;  ///< Reserved.
6562   } Bits;
6563   UINTN     UintN;
6564 } IA32_CR4;
6565 
6566 ///
6567 /// Byte packed structure for a segment descriptor in a GDT/LDT.
6568 ///
6569 typedef union {
6570   struct {
6571     UINT32  LimitLow:16;
6572     UINT32  BaseLow:16;
6573     UINT32  BaseMid:8;
6574     UINT32  Type:4;
6575     UINT32  S:1;
6576     UINT32  DPL:2;
6577     UINT32  P:1;
6578     UINT32  LimitHigh:4;
6579     UINT32  AVL:1;
6580     UINT32  L:1;
6581     UINT32  DB:1;
6582     UINT32  G:1;
6583     UINT32  BaseHigh:8;
6584   } Bits;
6585   UINT64  Uint64;
6586 } IA32_SEGMENT_DESCRIPTOR;
6587 
6588 ///
6589 /// Byte packed structure for an IDTR, GDTR, LDTR descriptor.
6590 ///
6591 #pragma pack (1)
6592 typedef struct {
6593   UINT16  Limit;
6594   UINTN   Base;
6595 } IA32_DESCRIPTOR;
6596 #pragma pack ()
6597 
6598 #define IA32_IDT_GATE_TYPE_TASK          0x85
6599 #define IA32_IDT_GATE_TYPE_INTERRUPT_16  0x86
6600 #define IA32_IDT_GATE_TYPE_TRAP_16       0x87
6601 #define IA32_IDT_GATE_TYPE_INTERRUPT_32  0x8E
6602 #define IA32_IDT_GATE_TYPE_TRAP_32       0x8F
6603 
6604 
6605 #if defined (MDE_CPU_IA32)
6606 ///
6607 /// Byte packed structure for an IA-32 Interrupt Gate Descriptor.
6608 ///
6609 typedef union {
6610   struct {
6611     UINT32  OffsetLow:16;   ///< Offset bits 15..0.
6612     UINT32  Selector:16;    ///< Selector.
6613     UINT32  Reserved_0:8;   ///< Reserved.
6614     UINT32  GateType:8;     ///< Gate Type.  See #defines above.
6615     UINT32  OffsetHigh:16;  ///< Offset bits 31..16.
6616   } Bits;
6617   UINT64  Uint64;
6618 } IA32_IDT_GATE_DESCRIPTOR;
6619 
6620 #endif
6621 
6622 #if defined (MDE_CPU_X64)
6623 ///
6624 /// Byte packed structure for an x64 Interrupt Gate Descriptor.
6625 ///
6626 typedef union {
6627   struct {
6628     UINT32  OffsetLow:16;   ///< Offset bits 15..0.
6629     UINT32  Selector:16;    ///< Selector.
6630     UINT32  Reserved_0:8;   ///< Reserved.
6631     UINT32  GateType:8;     ///< Gate Type.  See #defines above.
6632     UINT32  OffsetHigh:16;  ///< Offset bits 31..16.
6633     UINT32  OffsetUpper:32; ///< Offset bits 63..32.
6634     UINT32  Reserved_1:32;  ///< Reserved.
6635   } Bits;
6636   struct {
6637     UINT64  Uint64;
6638     UINT64  Uint64_1;
6639   } Uint128;
6640 } IA32_IDT_GATE_DESCRIPTOR;
6641 
6642 #endif
6643 
6644 ///
6645 /// Byte packed structure for an FP/SSE/SSE2 context.
6646 ///
6647 typedef struct {
6648   UINT8  Buffer[512];
6649 } IA32_FX_BUFFER;
6650 
6651 ///
6652 /// Structures for the 16-bit real mode thunks.
6653 ///
6654 typedef struct {
6655   UINT32                            Reserved1;
6656   UINT32                            Reserved2;
6657   UINT32                            Reserved3;
6658   UINT32                            Reserved4;
6659   UINT8                             BL;
6660   UINT8                             BH;
6661   UINT16                            Reserved5;
6662   UINT8                             DL;
6663   UINT8                             DH;
6664   UINT16                            Reserved6;
6665   UINT8                             CL;
6666   UINT8                             CH;
6667   UINT16                            Reserved7;
6668   UINT8                             AL;
6669   UINT8                             AH;
6670   UINT16                            Reserved8;
6671 } IA32_BYTE_REGS;
6672 
6673 typedef struct {
6674   UINT16                            DI;
6675   UINT16                            Reserved1;
6676   UINT16                            SI;
6677   UINT16                            Reserved2;
6678   UINT16                            BP;
6679   UINT16                            Reserved3;
6680   UINT16                            SP;
6681   UINT16                            Reserved4;
6682   UINT16                            BX;
6683   UINT16                            Reserved5;
6684   UINT16                            DX;
6685   UINT16                            Reserved6;
6686   UINT16                            CX;
6687   UINT16                            Reserved7;
6688   UINT16                            AX;
6689   UINT16                            Reserved8;
6690 } IA32_WORD_REGS;
6691 
6692 typedef struct {
6693   UINT32                            EDI;
6694   UINT32                            ESI;
6695   UINT32                            EBP;
6696   UINT32                            ESP;
6697   UINT32                            EBX;
6698   UINT32                            EDX;
6699   UINT32                            ECX;
6700   UINT32                            EAX;
6701   UINT16                            DS;
6702   UINT16                            ES;
6703   UINT16                            FS;
6704   UINT16                            GS;
6705   IA32_EFLAGS32                     EFLAGS;
6706   UINT32                            Eip;
6707   UINT16                            CS;
6708   UINT16                            SS;
6709 } IA32_DWORD_REGS;
6710 
6711 typedef union {
6712   IA32_DWORD_REGS                   E;
6713   IA32_WORD_REGS                    X;
6714   IA32_BYTE_REGS                    H;
6715 } IA32_REGISTER_SET;
6716 
6717 ///
6718 /// Byte packed structure for an 16-bit real mode thunks.
6719 ///
6720 typedef struct {
6721   IA32_REGISTER_SET                 *RealModeState;
6722   VOID                              *RealModeBuffer;
6723   UINT32                            RealModeBufferSize;
6724   UINT32                            ThunkAttributes;
6725 } THUNK_CONTEXT;
6726 
6727 #define THUNK_ATTRIBUTE_BIG_REAL_MODE             0x00000001
6728 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15   0x00000002
6729 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
6730 
6731 /**
6732   Retrieves CPUID information.
6733 
6734   Executes the CPUID instruction with EAX set to the value specified by Index.
6735   This function always returns Index.
6736   If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
6737   If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
6738   If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
6739   If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
6740   This function is only available on IA-32 and x64.
6741 
6742   @param  Index The 32-bit value to load into EAX prior to invoking the CPUID
6743                 instruction.
6744   @param  Eax   The pointer to the 32-bit EAX value returned by the CPUID
6745                 instruction. This is an optional parameter that may be NULL.
6746   @param  Ebx   The pointer to the 32-bit EBX value returned by the CPUID
6747                 instruction. This is an optional parameter that may be NULL.
6748   @param  Ecx   The pointer to the 32-bit ECX value returned by the CPUID
6749                 instruction. This is an optional parameter that may be NULL.
6750   @param  Edx   The pointer to the 32-bit EDX value returned by the CPUID
6751                 instruction. This is an optional parameter that may be NULL.
6752 
6753   @return Index.
6754 
6755 **/
6756 UINT32
6757 EFIAPI
6758 AsmCpuid (
6759   IN      UINT32                    Index,
6760   OUT     UINT32                    *Eax,  OPTIONAL
6761   OUT     UINT32                    *Ebx,  OPTIONAL
6762   OUT     UINT32                    *Ecx,  OPTIONAL
6763   OUT     UINT32                    *Edx   OPTIONAL
6764   );
6765 
6766 
6767 /**
6768   Retrieves CPUID information using an extended leaf identifier.
6769 
6770   Executes the CPUID instruction with EAX set to the value specified by Index
6771   and ECX set to the value specified by SubIndex. This function always returns
6772   Index. This function is only available on IA-32 and x64.
6773 
6774   If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
6775   If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
6776   If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
6777   If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
6778 
6779   @param  Index     The 32-bit value to load into EAX prior to invoking the
6780                     CPUID instruction.
6781   @param  SubIndex  The 32-bit value to load into ECX prior to invoking the
6782                     CPUID instruction.
6783   @param  Eax       The pointer to the 32-bit EAX value returned by the CPUID
6784                     instruction. This is an optional parameter that may be
6785                     NULL.
6786   @param  Ebx       The pointer to the 32-bit EBX value returned by the CPUID
6787                     instruction. This is an optional parameter that may be
6788                     NULL.
6789   @param  Ecx       The pointer to the 32-bit ECX value returned by the CPUID
6790                     instruction. This is an optional parameter that may be
6791                     NULL.
6792   @param  Edx       The pointer to the 32-bit EDX value returned by the CPUID
6793                     instruction. This is an optional parameter that may be
6794                     NULL.
6795 
6796   @return Index.
6797 
6798 **/
6799 UINT32
6800 EFIAPI
6801 AsmCpuidEx (
6802   IN      UINT32                    Index,
6803   IN      UINT32                    SubIndex,
6804   OUT     UINT32                    *Eax,  OPTIONAL
6805   OUT     UINT32                    *Ebx,  OPTIONAL
6806   OUT     UINT32                    *Ecx,  OPTIONAL
6807   OUT     UINT32                    *Edx   OPTIONAL
6808   );
6809 
6810 
6811 /**
6812   Set CD bit and clear NW bit of CR0 followed by a WBINVD.
6813 
6814   Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,
6815   and executing a WBINVD instruction.  This function is only available on IA-32 and x64.
6816 
6817 **/
6818 VOID
6819 EFIAPI
6820 AsmDisableCache (
6821   VOID
6822   );
6823 
6824 
6825 /**
6826   Perform a WBINVD and clear both the CD and NW bits of CR0.
6827 
6828   Enables the caches by executing a WBINVD instruction and then clear both the CD and NW
6829   bits of CR0 to 0.  This function is only available on IA-32 and x64.
6830 
6831 **/
6832 VOID
6833 EFIAPI
6834 AsmEnableCache (
6835   VOID
6836   );
6837 
6838 
6839 /**
6840   Returns the lower 32-bits of a Machine Specific Register(MSR).
6841 
6842   Reads and returns the lower 32-bits of the MSR specified by Index.
6843   No parameter checking is performed on Index, and some Index values may cause
6844   CPU exceptions. The caller must either guarantee that Index is valid, or the
6845   caller must set up exception handlers to catch the exceptions. This function
6846   is only available on IA-32 and x64.
6847 
6848   @param  Index The 32-bit MSR index to read.
6849 
6850   @return The lower 32 bits of the MSR identified by Index.
6851 
6852 **/
6853 UINT32
6854 EFIAPI
6855 AsmReadMsr32 (
6856   IN      UINT32                    Index
6857   );
6858 
6859 
6860 /**
6861   Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.
6862   The upper 32-bits of the MSR are set to zero.
6863 
6864   Writes the 32-bit value specified by Value to the MSR specified by Index. The
6865   upper 32-bits of the MSR write are set to zero. The 32-bit value written to
6866   the MSR is returned. No parameter checking is performed on Index or Value,
6867   and some of these may cause CPU exceptions. The caller must either guarantee
6868   that Index and Value are valid, or the caller must establish proper exception
6869   handlers. This function is only available on IA-32 and x64.
6870 
6871   @param  Index The 32-bit MSR index to write.
6872   @param  Value The 32-bit value to write to the MSR.
6873 
6874   @return Value
6875 
6876 **/
6877 UINT32
6878 EFIAPI
6879 AsmWriteMsr32 (
6880   IN      UINT32                    Index,
6881   IN      UINT32                    Value
6882   );
6883 
6884 
6885 /**
6886   Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and
6887   writes the result back to the 64-bit MSR.
6888 
6889   Reads the 64-bit MSR specified by Index, performs a bitwise OR
6890   between the lower 32-bits of the read result and the value specified by
6891   OrData, and writes the result to the 64-bit MSR specified by Index. The lower
6892   32-bits of the value written to the MSR is returned. No parameter checking is
6893   performed on Index or OrData, and some of these may cause CPU exceptions. The
6894   caller must either guarantee that Index and OrData are valid, or the caller
6895   must establish proper exception handlers. This function is only available on
6896   IA-32 and x64.
6897 
6898   @param  Index   The 32-bit MSR index to write.
6899   @param  OrData  The value to OR with the read value from the MSR.
6900 
6901   @return The lower 32-bit value written to the MSR.
6902 
6903 **/
6904 UINT32
6905 EFIAPI
6906 AsmMsrOr32 (
6907   IN      UINT32                    Index,
6908   IN      UINT32                    OrData
6909   );
6910 
6911 
6912 /**
6913   Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
6914   the result back to the 64-bit MSR.
6915 
6916   Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
6917   lower 32-bits of the read result and the value specified by AndData, and
6918   writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
6919   the value written to the MSR is returned. No parameter checking is performed
6920   on Index or AndData, and some of these may cause CPU exceptions. The caller
6921   must either guarantee that Index and AndData are valid, or the caller must
6922   establish proper exception handlers. This function is only available on IA-32
6923   and x64.
6924 
6925   @param  Index   The 32-bit MSR index to write.
6926   @param  AndData The value to AND with the read value from the MSR.
6927 
6928   @return The lower 32-bit value written to the MSR.
6929 
6930 **/
6931 UINT32
6932 EFIAPI
6933 AsmMsrAnd32 (
6934   IN      UINT32                    Index,
6935   IN      UINT32                    AndData
6936   );
6937 
6938 
6939 /**
6940   Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR
6941   on the lower 32-bits, and writes the result back to the 64-bit MSR.
6942 
6943   Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
6944   lower 32-bits of the read result and the value specified by AndData
6945   preserving the upper 32-bits, performs a bitwise OR between the
6946   result of the AND operation and the value specified by OrData, and writes the
6947   result to the 64-bit MSR specified by Address. The lower 32-bits of the value
6948   written to the MSR is returned. No parameter checking is performed on Index,
6949   AndData, or OrData, and some of these may cause CPU exceptions. The caller
6950   must either guarantee that Index, AndData, and OrData are valid, or the
6951   caller must establish proper exception handlers. This function is only
6952   available on IA-32 and x64.
6953 
6954   @param  Index   The 32-bit MSR index to write.
6955   @param  AndData The value to AND with the read value from the MSR.
6956   @param  OrData  The value to OR with the result of the AND operation.
6957 
6958   @return The lower 32-bit value written to the MSR.
6959 
6960 **/
6961 UINT32
6962 EFIAPI
6963 AsmMsrAndThenOr32 (
6964   IN      UINT32                    Index,
6965   IN      UINT32                    AndData,
6966   IN      UINT32                    OrData
6967   );
6968 
6969 
6970 /**
6971   Reads a bit field of an MSR.
6972 
6973   Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
6974   specified by the StartBit and the EndBit. The value of the bit field is
6975   returned. The caller must either guarantee that Index is valid, or the caller
6976   must set up exception handlers to catch the exceptions. This function is only
6977   available on IA-32 and x64.
6978 
6979   If StartBit is greater than 31, then ASSERT().
6980   If EndBit is greater than 31, then ASSERT().
6981   If EndBit is less than StartBit, then ASSERT().
6982 
6983   @param  Index     The 32-bit MSR index to read.
6984   @param  StartBit  The ordinal of the least significant bit in the bit field.
6985                     Range 0..31.
6986   @param  EndBit    The ordinal of the most significant bit in the bit field.
6987                     Range 0..31.
6988 
6989   @return The bit field read from the MSR.
6990 
6991 **/
6992 UINT32
6993 EFIAPI
6994 AsmMsrBitFieldRead32 (
6995   IN      UINT32                    Index,
6996   IN      UINTN                     StartBit,
6997   IN      UINTN                     EndBit
6998   );
6999 
7000 
7001 /**
7002   Writes a bit field to an MSR.
7003 
7004   Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
7005   field is specified by the StartBit and the EndBit. All other bits in the
7006   destination MSR are preserved. The lower 32-bits of the MSR written is
7007   returned. The caller must either guarantee that Index and the data written
7008   is valid, or the caller must set up exception handlers to catch the exceptions.
7009   This function is only available on IA-32 and x64.
7010 
7011   If StartBit is greater than 31, then ASSERT().
7012   If EndBit is greater than 31, then ASSERT().
7013   If EndBit is less than StartBit, then ASSERT().
7014   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7015 
7016   @param  Index     The 32-bit MSR index to write.
7017   @param  StartBit  The ordinal of the least significant bit in the bit field.
7018                     Range 0..31.
7019   @param  EndBit    The ordinal of the most significant bit in the bit field.
7020                     Range 0..31.
7021   @param  Value     New value of the bit field.
7022 
7023   @return The lower 32-bit of the value written to the MSR.
7024 
7025 **/
7026 UINT32
7027 EFIAPI
7028 AsmMsrBitFieldWrite32 (
7029   IN      UINT32                    Index,
7030   IN      UINTN                     StartBit,
7031   IN      UINTN                     EndBit,
7032   IN      UINT32                    Value
7033   );
7034 
7035 
7036 /**
7037   Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
7038   result back to the bit field in the 64-bit MSR.
7039 
7040   Reads the 64-bit MSR specified by Index, performs a bitwise OR
7041   between the read result and the value specified by OrData, and writes the
7042   result to the 64-bit MSR specified by Index. The lower 32-bits of the value
7043   written to the MSR are returned. Extra left bits in OrData are stripped. The
7044   caller must either guarantee that Index and the data written is valid, or
7045   the caller must set up exception handlers to catch the exceptions. This
7046   function is only available on IA-32 and x64.
7047 
7048   If StartBit is greater than 31, then ASSERT().
7049   If EndBit is greater than 31, then ASSERT().
7050   If EndBit is less than StartBit, then ASSERT().
7051   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7052 
7053   @param  Index     The 32-bit MSR index to write.
7054   @param  StartBit  The ordinal of the least significant bit in the bit field.
7055                     Range 0..31.
7056   @param  EndBit    The ordinal of the most significant bit in the bit field.
7057                     Range 0..31.
7058   @param  OrData    The value to OR with the read value from the MSR.
7059 
7060   @return The lower 32-bit of the value written to the MSR.
7061 
7062 **/
7063 UINT32
7064 EFIAPI
7065 AsmMsrBitFieldOr32 (
7066   IN      UINT32                    Index,
7067   IN      UINTN                     StartBit,
7068   IN      UINTN                     EndBit,
7069   IN      UINT32                    OrData
7070   );
7071 
7072 
7073 /**
7074   Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
7075   result back to the bit field in the 64-bit MSR.
7076 
7077   Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
7078   read result and the value specified by AndData, and writes the result to the
7079   64-bit MSR specified by Index. The lower 32-bits of the value written to the
7080   MSR are returned. Extra left bits in AndData are stripped. The caller must
7081   either guarantee that Index and the data written is valid, or the caller must
7082   set up exception handlers to catch the exceptions. This function is only
7083   available on IA-32 and x64.
7084 
7085   If StartBit is greater than 31, then ASSERT().
7086   If EndBit is greater than 31, then ASSERT().
7087   If EndBit is less than StartBit, then ASSERT().
7088   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7089 
7090   @param  Index     The 32-bit MSR index to write.
7091   @param  StartBit  The ordinal of the least significant bit in the bit field.
7092                     Range 0..31.
7093   @param  EndBit    The ordinal of the most significant bit in the bit field.
7094                     Range 0..31.
7095   @param  AndData   The value to AND with the read value from the MSR.
7096 
7097   @return The lower 32-bit of the value written to the MSR.
7098 
7099 **/
7100 UINT32
7101 EFIAPI
7102 AsmMsrBitFieldAnd32 (
7103   IN      UINT32                    Index,
7104   IN      UINTN                     StartBit,
7105   IN      UINTN                     EndBit,
7106   IN      UINT32                    AndData
7107   );
7108 
7109 
7110 /**
7111   Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
7112   bitwise OR, and writes the result back to the bit field in the
7113   64-bit MSR.
7114 
7115   Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
7116   bitwise OR between the read result and the value specified by
7117   AndData, and writes the result to the 64-bit MSR specified by Index. The
7118   lower 32-bits of the value written to the MSR are returned. Extra left bits
7119   in both AndData and OrData are stripped. The caller must either guarantee
7120   that Index and the data written is valid, or the caller must set up exception
7121   handlers to catch the exceptions. This function is only available on IA-32
7122   and x64.
7123 
7124   If StartBit is greater than 31, then ASSERT().
7125   If EndBit is greater than 31, then ASSERT().
7126   If EndBit is less than StartBit, then ASSERT().
7127   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7128   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7129 
7130   @param  Index     The 32-bit MSR index to write.
7131   @param  StartBit  The ordinal of the least significant bit in the bit field.
7132                     Range 0..31.
7133   @param  EndBit    The ordinal of the most significant bit in the bit field.
7134                     Range 0..31.
7135   @param  AndData   The value to AND with the read value from the MSR.
7136   @param  OrData    The value to OR with the result of the AND operation.
7137 
7138   @return The lower 32-bit of the value written to the MSR.
7139 
7140 **/
7141 UINT32
7142 EFIAPI
7143 AsmMsrBitFieldAndThenOr32 (
7144   IN      UINT32                    Index,
7145   IN      UINTN                     StartBit,
7146   IN      UINTN                     EndBit,
7147   IN      UINT32                    AndData,
7148   IN      UINT32                    OrData
7149   );
7150 
7151 
7152 /**
7153   Returns a 64-bit Machine Specific Register(MSR).
7154 
7155   Reads and returns the 64-bit MSR specified by Index. No parameter checking is
7156   performed on Index, and some Index values may cause CPU exceptions. The
7157   caller must either guarantee that Index is valid, or the caller must set up
7158   exception handlers to catch the exceptions. This function is only available
7159   on IA-32 and x64.
7160 
7161   @param  Index The 32-bit MSR index to read.
7162 
7163   @return The value of the MSR identified by Index.
7164 
7165 **/
7166 UINT64
7167 EFIAPI
7168 AsmReadMsr64 (
7169   IN      UINT32                    Index
7170   );
7171 
7172 
7173 /**
7174   Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
7175   value.
7176 
7177   Writes the 64-bit value specified by Value to the MSR specified by Index. The
7178   64-bit value written to the MSR is returned. No parameter checking is
7179   performed on Index or Value, and some of these may cause CPU exceptions. The
7180   caller must either guarantee that Index and Value are valid, or the caller
7181   must establish proper exception handlers. This function is only available on
7182   IA-32 and x64.
7183 
7184   @param  Index The 32-bit MSR index to write.
7185   @param  Value The 64-bit value to write to the MSR.
7186 
7187   @return Value
7188 
7189 **/
7190 UINT64
7191 EFIAPI
7192 AsmWriteMsr64 (
7193   IN      UINT32                    Index,
7194   IN      UINT64                    Value
7195   );
7196 
7197 
7198 /**
7199   Reads a 64-bit MSR, performs a bitwise OR, and writes the result
7200   back to the 64-bit MSR.
7201 
7202   Reads the 64-bit MSR specified by Index, performs a bitwise OR
7203   between the read result and the value specified by OrData, and writes the
7204   result to the 64-bit MSR specified by Index. The value written to the MSR is
7205   returned. No parameter checking is performed on Index or OrData, and some of
7206   these may cause CPU exceptions. The caller must either guarantee that Index
7207   and OrData are valid, or the caller must establish proper exception handlers.
7208   This function is only available on IA-32 and x64.
7209 
7210   @param  Index   The 32-bit MSR index to write.
7211   @param  OrData  The value to OR with the read value from the MSR.
7212 
7213   @return The value written back to the MSR.
7214 
7215 **/
7216 UINT64
7217 EFIAPI
7218 AsmMsrOr64 (
7219   IN      UINT32                    Index,
7220   IN      UINT64                    OrData
7221   );
7222 
7223 
7224 /**
7225   Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
7226   64-bit MSR.
7227 
7228   Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
7229   read result and the value specified by OrData, and writes the result to the
7230   64-bit MSR specified by Index. The value written to the MSR is returned. No
7231   parameter checking is performed on Index or OrData, and some of these may
7232   cause CPU exceptions. The caller must either guarantee that Index and OrData
7233   are valid, or the caller must establish proper exception handlers. This
7234   function is only available on IA-32 and x64.
7235 
7236   @param  Index   The 32-bit MSR index to write.
7237   @param  AndData The value to AND with the read value from the MSR.
7238 
7239   @return The value written back to the MSR.
7240 
7241 **/
7242 UINT64
7243 EFIAPI
7244 AsmMsrAnd64 (
7245   IN      UINT32                    Index,
7246   IN      UINT64                    AndData
7247   );
7248 
7249 
7250 /**
7251   Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise
7252   OR, and writes the result back to the 64-bit MSR.
7253 
7254   Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
7255   result and the value specified by AndData, performs a bitwise OR
7256   between the result of the AND operation and the value specified by OrData,
7257   and writes the result to the 64-bit MSR specified by Index. The value written
7258   to the MSR is returned. No parameter checking is performed on Index, AndData,
7259   or OrData, and some of these may cause CPU exceptions. The caller must either
7260   guarantee that Index, AndData, and OrData are valid, or the caller must
7261   establish proper exception handlers. This function is only available on IA-32
7262   and x64.
7263 
7264   @param  Index   The 32-bit MSR index to write.
7265   @param  AndData The value to AND with the read value from the MSR.
7266   @param  OrData  The value to OR with the result of the AND operation.
7267 
7268   @return The value written back to the MSR.
7269 
7270 **/
7271 UINT64
7272 EFIAPI
7273 AsmMsrAndThenOr64 (
7274   IN      UINT32                    Index,
7275   IN      UINT64                    AndData,
7276   IN      UINT64                    OrData
7277   );
7278 
7279 
7280 /**
7281   Reads a bit field of an MSR.
7282 
7283   Reads the bit field in the 64-bit MSR. The bit field is specified by the
7284   StartBit and the EndBit. The value of the bit field is returned. The caller
7285   must either guarantee that Index is valid, or the caller must set up
7286   exception handlers to catch the exceptions. This function is only available
7287   on IA-32 and x64.
7288 
7289   If StartBit is greater than 63, then ASSERT().
7290   If EndBit is greater than 63, then ASSERT().
7291   If EndBit is less than StartBit, then ASSERT().
7292 
7293   @param  Index     The 32-bit MSR index to read.
7294   @param  StartBit  The ordinal of the least significant bit in the bit field.
7295                     Range 0..63.
7296   @param  EndBit    The ordinal of the most significant bit in the bit field.
7297                     Range 0..63.
7298 
7299   @return The value read from the MSR.
7300 
7301 **/
7302 UINT64
7303 EFIAPI
7304 AsmMsrBitFieldRead64 (
7305   IN      UINT32                    Index,
7306   IN      UINTN                     StartBit,
7307   IN      UINTN                     EndBit
7308   );
7309 
7310 
7311 /**
7312   Writes a bit field to an MSR.
7313 
7314   Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
7315   the StartBit and the EndBit. All other bits in the destination MSR are
7316   preserved. The MSR written is returned. The caller must either guarantee
7317   that Index and the data written is valid, or the caller must set up exception
7318   handlers to catch the exceptions. This function is only available on IA-32 and x64.
7319 
7320   If StartBit is greater than 63, then ASSERT().
7321   If EndBit is greater than 63, then ASSERT().
7322   If EndBit is less than StartBit, then ASSERT().
7323   If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7324 
7325   @param  Index     The 32-bit MSR index to write.
7326   @param  StartBit  The ordinal of the least significant bit in the bit field.
7327                     Range 0..63.
7328   @param  EndBit    The ordinal of the most significant bit in the bit field.
7329                     Range 0..63.
7330   @param  Value     New value of the bit field.
7331 
7332   @return The value written back to the MSR.
7333 
7334 **/
7335 UINT64
7336 EFIAPI
7337 AsmMsrBitFieldWrite64 (
7338   IN      UINT32                    Index,
7339   IN      UINTN                     StartBit,
7340   IN      UINTN                     EndBit,
7341   IN      UINT64                    Value
7342   );
7343 
7344 
7345 /**
7346   Reads a bit field in a 64-bit MSR, performs a bitwise OR, and
7347   writes the result back to the bit field in the 64-bit MSR.
7348 
7349   Reads the 64-bit MSR specified by Index, performs a bitwise OR
7350   between the read result and the value specified by OrData, and writes the
7351   result to the 64-bit MSR specified by Index. The value written to the MSR is
7352   returned. Extra left bits in OrData are stripped. The caller must either
7353   guarantee that Index and the data written is valid, or the caller must set up
7354   exception handlers to catch the exceptions. This function is only available
7355   on IA-32 and x64.
7356 
7357   If StartBit is greater than 63, then ASSERT().
7358   If EndBit is greater than 63, then ASSERT().
7359   If EndBit is less than StartBit, then ASSERT().
7360   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7361 
7362   @param  Index     The 32-bit MSR index to write.
7363   @param  StartBit  The ordinal of the least significant bit in the bit field.
7364                     Range 0..63.
7365   @param  EndBit    The ordinal of the most significant bit in the bit field.
7366                     Range 0..63.
7367   @param  OrData    The value to OR with the read value from the bit field.
7368 
7369   @return The value written back to the MSR.
7370 
7371 **/
7372 UINT64
7373 EFIAPI
7374 AsmMsrBitFieldOr64 (
7375   IN      UINT32                    Index,
7376   IN      UINTN                     StartBit,
7377   IN      UINTN                     EndBit,
7378   IN      UINT64                    OrData
7379   );
7380 
7381 
7382 /**
7383   Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
7384   result back to the bit field in the 64-bit MSR.
7385 
7386   Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
7387   read result and the value specified by AndData, and writes the result to the
7388   64-bit MSR specified by Index. The value written to the MSR is returned.
7389   Extra left bits in AndData are stripped. The caller must either guarantee
7390   that Index and the data written is valid, or the caller must set up exception
7391   handlers to catch the exceptions. This function is only available on IA-32
7392   and x64.
7393 
7394   If StartBit is greater than 63, then ASSERT().
7395   If EndBit is greater than 63, then ASSERT().
7396   If EndBit is less than StartBit, then ASSERT().
7397   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7398 
7399   @param  Index     The 32-bit MSR index to write.
7400   @param  StartBit  The ordinal of the least significant bit in the bit field.
7401                     Range 0..63.
7402   @param  EndBit    The ordinal of the most significant bit in the bit field.
7403                     Range 0..63.
7404   @param  AndData   The value to AND with the read value from the bit field.
7405 
7406   @return The value written back to the MSR.
7407 
7408 **/
7409 UINT64
7410 EFIAPI
7411 AsmMsrBitFieldAnd64 (
7412   IN      UINT32                    Index,
7413   IN      UINTN                     StartBit,
7414   IN      UINTN                     EndBit,
7415   IN      UINT64                    AndData
7416   );
7417 
7418 
7419 /**
7420   Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
7421   bitwise OR, and writes the result back to the bit field in the
7422   64-bit MSR.
7423 
7424   Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
7425   a bitwise OR between the read result and the value specified by
7426   AndData, and writes the result to the 64-bit MSR specified by Index. The
7427   value written to the MSR is returned. Extra left bits in both AndData and
7428   OrData are stripped. The caller must either guarantee that Index and the data
7429   written is valid, or the caller must set up exception handlers to catch the
7430   exceptions. This function is only available on IA-32 and x64.
7431 
7432   If StartBit is greater than 63, then ASSERT().
7433   If EndBit is greater than 63, then ASSERT().
7434   If EndBit is less than StartBit, then ASSERT().
7435   If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7436   If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
7437 
7438   @param  Index     The 32-bit MSR index to write.
7439   @param  StartBit  The ordinal of the least significant bit in the bit field.
7440                     Range 0..63.
7441   @param  EndBit    The ordinal of the most significant bit in the bit field.
7442                     Range 0..63.
7443   @param  AndData   The value to AND with the read value from the bit field.
7444   @param  OrData    The value to OR with the result of the AND operation.
7445 
7446   @return The value written back to the MSR.
7447 
7448 **/
7449 UINT64
7450 EFIAPI
7451 AsmMsrBitFieldAndThenOr64 (
7452   IN      UINT32                    Index,
7453   IN      UINTN                     StartBit,
7454   IN      UINTN                     EndBit,
7455   IN      UINT64                    AndData,
7456   IN      UINT64                    OrData
7457   );
7458 
7459 
7460 /**
7461   Reads the current value of the EFLAGS register.
7462 
7463   Reads and returns the current value of the EFLAGS register. This function is
7464   only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a
7465   64-bit value on x64.
7466 
7467   @return EFLAGS on IA-32 or RFLAGS on x64.
7468 
7469 **/
7470 UINTN
7471 EFIAPI
7472 AsmReadEflags (
7473   VOID
7474   );
7475 
7476 
7477 /**
7478   Reads the current value of the Control Register 0 (CR0).
7479 
7480   Reads and returns the current value of CR0. This function is only available
7481   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7482   x64.
7483 
7484   @return The value of the Control Register 0 (CR0).
7485 
7486 **/
7487 UINTN
7488 EFIAPI
7489 AsmReadCr0 (
7490   VOID
7491   );
7492 
7493 
7494 /**
7495   Reads the current value of the Control Register 2 (CR2).
7496 
7497   Reads and returns the current value of CR2. This function is only available
7498   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7499   x64.
7500 
7501   @return The value of the Control Register 2 (CR2).
7502 
7503 **/
7504 UINTN
7505 EFIAPI
7506 AsmReadCr2 (
7507   VOID
7508   );
7509 
7510 
7511 /**
7512   Reads the current value of the Control Register 3 (CR3).
7513 
7514   Reads and returns the current value of CR3. This function is only available
7515   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7516   x64.
7517 
7518   @return The value of the Control Register 3 (CR3).
7519 
7520 **/
7521 UINTN
7522 EFIAPI
7523 AsmReadCr3 (
7524   VOID
7525   );
7526 
7527 
7528 /**
7529   Reads the current value of the Control Register 4 (CR4).
7530 
7531   Reads and returns the current value of CR4. This function is only available
7532   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7533   x64.
7534 
7535   @return The value of the Control Register 4 (CR4).
7536 
7537 **/
7538 UINTN
7539 EFIAPI
7540 AsmReadCr4 (
7541   VOID
7542   );
7543 
7544 
7545 /**
7546   Writes a value to Control Register 0 (CR0).
7547 
7548   Writes and returns a new value to CR0. This function is only available on
7549   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7550 
7551   @param  Cr0 The value to write to CR0.
7552 
7553   @return The value written to CR0.
7554 
7555 **/
7556 UINTN
7557 EFIAPI
7558 AsmWriteCr0 (
7559   UINTN  Cr0
7560   );
7561 
7562 
7563 /**
7564   Writes a value to Control Register 2 (CR2).
7565 
7566   Writes and returns a new value to CR2. This function is only available on
7567   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7568 
7569   @param  Cr2 The value to write to CR2.
7570 
7571   @return The value written to CR2.
7572 
7573 **/
7574 UINTN
7575 EFIAPI
7576 AsmWriteCr2 (
7577   UINTN  Cr2
7578   );
7579 
7580 
7581 /**
7582   Writes a value to Control Register 3 (CR3).
7583 
7584   Writes and returns a new value to CR3. This function is only available on
7585   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7586 
7587   @param  Cr3 The value to write to CR3.
7588 
7589   @return The value written to CR3.
7590 
7591 **/
7592 UINTN
7593 EFIAPI
7594 AsmWriteCr3 (
7595   UINTN  Cr3
7596   );
7597 
7598 
7599 /**
7600   Writes a value to Control Register 4 (CR4).
7601 
7602   Writes and returns a new value to CR4. This function is only available on
7603   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7604 
7605   @param  Cr4 The value to write to CR4.
7606 
7607   @return The value written to CR4.
7608 
7609 **/
7610 UINTN
7611 EFIAPI
7612 AsmWriteCr4 (
7613   UINTN  Cr4
7614   );
7615 
7616 
7617 /**
7618   Reads the current value of Debug Register 0 (DR0).
7619 
7620   Reads and returns the current value of DR0. This function is only available
7621   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7622   x64.
7623 
7624   @return The value of Debug Register 0 (DR0).
7625 
7626 **/
7627 UINTN
7628 EFIAPI
7629 AsmReadDr0 (
7630   VOID
7631   );
7632 
7633 
7634 /**
7635   Reads the current value of Debug Register 1 (DR1).
7636 
7637   Reads and returns the current value of DR1. This function is only available
7638   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7639   x64.
7640 
7641   @return The value of Debug Register 1 (DR1).
7642 
7643 **/
7644 UINTN
7645 EFIAPI
7646 AsmReadDr1 (
7647   VOID
7648   );
7649 
7650 
7651 /**
7652   Reads the current value of Debug Register 2 (DR2).
7653 
7654   Reads and returns the current value of DR2. This function is only available
7655   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7656   x64.
7657 
7658   @return The value of Debug Register 2 (DR2).
7659 
7660 **/
7661 UINTN
7662 EFIAPI
7663 AsmReadDr2 (
7664   VOID
7665   );
7666 
7667 
7668 /**
7669   Reads the current value of Debug Register 3 (DR3).
7670 
7671   Reads and returns the current value of DR3. This function is only available
7672   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7673   x64.
7674 
7675   @return The value of Debug Register 3 (DR3).
7676 
7677 **/
7678 UINTN
7679 EFIAPI
7680 AsmReadDr3 (
7681   VOID
7682   );
7683 
7684 
7685 /**
7686   Reads the current value of Debug Register 4 (DR4).
7687 
7688   Reads and returns the current value of DR4. This function is only available
7689   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7690   x64.
7691 
7692   @return The value of Debug Register 4 (DR4).
7693 
7694 **/
7695 UINTN
7696 EFIAPI
7697 AsmReadDr4 (
7698   VOID
7699   );
7700 
7701 
7702 /**
7703   Reads the current value of Debug Register 5 (DR5).
7704 
7705   Reads and returns the current value of DR5. This function is only available
7706   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7707   x64.
7708 
7709   @return The value of Debug Register 5 (DR5).
7710 
7711 **/
7712 UINTN
7713 EFIAPI
7714 AsmReadDr5 (
7715   VOID
7716   );
7717 
7718 
7719 /**
7720   Reads the current value of Debug Register 6 (DR6).
7721 
7722   Reads and returns the current value of DR6. This function is only available
7723   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7724   x64.
7725 
7726   @return The value of Debug Register 6 (DR6).
7727 
7728 **/
7729 UINTN
7730 EFIAPI
7731 AsmReadDr6 (
7732   VOID
7733   );
7734 
7735 
7736 /**
7737   Reads the current value of Debug Register 7 (DR7).
7738 
7739   Reads and returns the current value of DR7. This function is only available
7740   on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
7741   x64.
7742 
7743   @return The value of Debug Register 7 (DR7).
7744 
7745 **/
7746 UINTN
7747 EFIAPI
7748 AsmReadDr7 (
7749   VOID
7750   );
7751 
7752 
7753 /**
7754   Writes a value to Debug Register 0 (DR0).
7755 
7756   Writes and returns a new value to DR0. This function is only available on
7757   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7758 
7759   @param  Dr0 The value to write to Dr0.
7760 
7761   @return The value written to Debug Register 0 (DR0).
7762 
7763 **/
7764 UINTN
7765 EFIAPI
7766 AsmWriteDr0 (
7767   UINTN  Dr0
7768   );
7769 
7770 
7771 /**
7772   Writes a value to Debug Register 1 (DR1).
7773 
7774   Writes and returns a new value to DR1. This function is only available on
7775   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7776 
7777   @param  Dr1 The value to write to Dr1.
7778 
7779   @return The value written to Debug Register 1 (DR1).
7780 
7781 **/
7782 UINTN
7783 EFIAPI
7784 AsmWriteDr1 (
7785   UINTN  Dr1
7786   );
7787 
7788 
7789 /**
7790   Writes a value to Debug Register 2 (DR2).
7791 
7792   Writes and returns a new value to DR2. This function is only available on
7793   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7794 
7795   @param  Dr2 The value to write to Dr2.
7796 
7797   @return The value written to Debug Register 2 (DR2).
7798 
7799 **/
7800 UINTN
7801 EFIAPI
7802 AsmWriteDr2 (
7803   UINTN  Dr2
7804   );
7805 
7806 
7807 /**
7808   Writes a value to Debug Register 3 (DR3).
7809 
7810   Writes and returns a new value to DR3. This function is only available on
7811   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7812 
7813   @param  Dr3 The value to write to Dr3.
7814 
7815   @return The value written to Debug Register 3 (DR3).
7816 
7817 **/
7818 UINTN
7819 EFIAPI
7820 AsmWriteDr3 (
7821   UINTN  Dr3
7822   );
7823 
7824 
7825 /**
7826   Writes a value to Debug Register 4 (DR4).
7827 
7828   Writes and returns a new value to DR4. This function is only available on
7829   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7830 
7831   @param  Dr4 The value to write to Dr4.
7832 
7833   @return The value written to Debug Register 4 (DR4).
7834 
7835 **/
7836 UINTN
7837 EFIAPI
7838 AsmWriteDr4 (
7839   UINTN  Dr4
7840   );
7841 
7842 
7843 /**
7844   Writes a value to Debug Register 5 (DR5).
7845 
7846   Writes and returns a new value to DR5. This function is only available on
7847   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7848 
7849   @param  Dr5 The value to write to Dr5.
7850 
7851   @return The value written to Debug Register 5 (DR5).
7852 
7853 **/
7854 UINTN
7855 EFIAPI
7856 AsmWriteDr5 (
7857   UINTN  Dr5
7858   );
7859 
7860 
7861 /**
7862   Writes a value to Debug Register 6 (DR6).
7863 
7864   Writes and returns a new value to DR6. This function is only available on
7865   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7866 
7867   @param  Dr6 The value to write to Dr6.
7868 
7869   @return The value written to Debug Register 6 (DR6).
7870 
7871 **/
7872 UINTN
7873 EFIAPI
7874 AsmWriteDr6 (
7875   UINTN  Dr6
7876   );
7877 
7878 
7879 /**
7880   Writes a value to Debug Register 7 (DR7).
7881 
7882   Writes and returns a new value to DR7. This function is only available on
7883   IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
7884 
7885   @param  Dr7 The value to write to Dr7.
7886 
7887   @return The value written to Debug Register 7 (DR7).
7888 
7889 **/
7890 UINTN
7891 EFIAPI
7892 AsmWriteDr7 (
7893   UINTN  Dr7
7894   );
7895 
7896 
7897 /**
7898   Reads the current value of Code Segment Register (CS).
7899 
7900   Reads and returns the current value of CS. This function is only available on
7901   IA-32 and x64.
7902 
7903   @return The current value of CS.
7904 
7905 **/
7906 UINT16
7907 EFIAPI
7908 AsmReadCs (
7909   VOID
7910   );
7911 
7912 
7913 /**
7914   Reads the current value of Data Segment Register (DS).
7915 
7916   Reads and returns the current value of DS. This function is only available on
7917   IA-32 and x64.
7918 
7919   @return The current value of DS.
7920 
7921 **/
7922 UINT16
7923 EFIAPI
7924 AsmReadDs (
7925   VOID
7926   );
7927 
7928 
7929 /**
7930   Reads the current value of Extra Segment Register (ES).
7931 
7932   Reads and returns the current value of ES. This function is only available on
7933   IA-32 and x64.
7934 
7935   @return The current value of ES.
7936 
7937 **/
7938 UINT16
7939 EFIAPI
7940 AsmReadEs (
7941   VOID
7942   );
7943 
7944 
7945 /**
7946   Reads the current value of FS Data Segment Register (FS).
7947 
7948   Reads and returns the current value of FS. This function is only available on
7949   IA-32 and x64.
7950 
7951   @return The current value of FS.
7952 
7953 **/
7954 UINT16
7955 EFIAPI
7956 AsmReadFs (
7957   VOID
7958   );
7959 
7960 
7961 /**
7962   Reads the current value of GS Data Segment Register (GS).
7963 
7964   Reads and returns the current value of GS. This function is only available on
7965   IA-32 and x64.
7966 
7967   @return The current value of GS.
7968 
7969 **/
7970 UINT16
7971 EFIAPI
7972 AsmReadGs (
7973   VOID
7974   );
7975 
7976 
7977 /**
7978   Reads the current value of Stack Segment Register (SS).
7979 
7980   Reads and returns the current value of SS. This function is only available on
7981   IA-32 and x64.
7982 
7983   @return The current value of SS.
7984 
7985 **/
7986 UINT16
7987 EFIAPI
7988 AsmReadSs (
7989   VOID
7990   );
7991 
7992 
7993 /**
7994   Reads the current value of Task Register (TR).
7995 
7996   Reads and returns the current value of TR. This function is only available on
7997   IA-32 and x64.
7998 
7999   @return The current value of TR.
8000 
8001 **/
8002 UINT16
8003 EFIAPI
8004 AsmReadTr (
8005   VOID
8006   );
8007 
8008 
8009 /**
8010   Reads the current Global Descriptor Table Register(GDTR) descriptor.
8011 
8012   Reads and returns the current GDTR descriptor and returns it in Gdtr. This
8013   function is only available on IA-32 and x64.
8014 
8015   If Gdtr is NULL, then ASSERT().
8016 
8017   @param  Gdtr  The pointer to a GDTR descriptor.
8018 
8019 **/
8020 VOID
8021 EFIAPI
8022 AsmReadGdtr (
8023   OUT     IA32_DESCRIPTOR           *Gdtr
8024   );
8025 
8026 
8027 /**
8028   Writes the current Global Descriptor Table Register (GDTR) descriptor.
8029 
8030   Writes and the current GDTR descriptor specified by Gdtr. This function is
8031   only available on IA-32 and x64.
8032 
8033   If Gdtr is NULL, then ASSERT().
8034 
8035   @param  Gdtr  The pointer to a GDTR descriptor.
8036 
8037 **/
8038 VOID
8039 EFIAPI
8040 AsmWriteGdtr (
8041   IN      CONST IA32_DESCRIPTOR     *Gdtr
8042   );
8043 
8044 
8045 /**
8046   Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.
8047 
8048   Reads and returns the current IDTR descriptor and returns it in Idtr. This
8049   function is only available on IA-32 and x64.
8050 
8051   If Idtr is NULL, then ASSERT().
8052 
8053   @param  Idtr  The pointer to a IDTR descriptor.
8054 
8055 **/
8056 VOID
8057 EFIAPI
8058 AsmReadIdtr (
8059   OUT     IA32_DESCRIPTOR           *Idtr
8060   );
8061 
8062 
8063 /**
8064   Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.
8065 
8066   Writes the current IDTR descriptor and returns it in Idtr. This function is
8067   only available on IA-32 and x64.
8068 
8069   If Idtr is NULL, then ASSERT().
8070 
8071   @param  Idtr  The pointer to a IDTR descriptor.
8072 
8073 **/
8074 VOID
8075 EFIAPI
8076 AsmWriteIdtr (
8077   IN      CONST IA32_DESCRIPTOR     *Idtr
8078   );
8079 
8080 
8081 /**
8082   Reads the current Local Descriptor Table Register(LDTR) selector.
8083 
8084   Reads and returns the current 16-bit LDTR descriptor value. This function is
8085   only available on IA-32 and x64.
8086 
8087   @return The current selector of LDT.
8088 
8089 **/
8090 UINT16
8091 EFIAPI
8092 AsmReadLdtr (
8093   VOID
8094   );
8095 
8096 
8097 /**
8098   Writes the current Local Descriptor Table Register (LDTR) selector.
8099 
8100   Writes and the current LDTR descriptor specified by Ldtr. This function is
8101   only available on IA-32 and x64.
8102 
8103   @param  Ldtr  16-bit LDTR selector value.
8104 
8105 **/
8106 VOID
8107 EFIAPI
8108 AsmWriteLdtr (
8109   IN      UINT16                    Ldtr
8110   );
8111 
8112 
8113 /**
8114   Save the current floating point/SSE/SSE2 context to a buffer.
8115 
8116   Saves the current floating point/SSE/SSE2 state to the buffer specified by
8117   Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
8118   available on IA-32 and x64.
8119 
8120   If Buffer is NULL, then ASSERT().
8121   If Buffer is not aligned on a 16-byte boundary, then ASSERT().
8122 
8123   @param  Buffer  The pointer to a buffer to save the floating point/SSE/SSE2 context.
8124 
8125 **/
8126 VOID
8127 EFIAPI
8128 AsmFxSave (
8129   OUT     IA32_FX_BUFFER            *Buffer
8130   );
8131 
8132 
8133 /**
8134   Restores the current floating point/SSE/SSE2 context from a buffer.
8135 
8136   Restores the current floating point/SSE/SSE2 state from the buffer specified
8137   by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
8138   only available on IA-32 and x64.
8139 
8140   If Buffer is NULL, then ASSERT().
8141   If Buffer is not aligned on a 16-byte boundary, then ASSERT().
8142   If Buffer was not saved with AsmFxSave(), then ASSERT().
8143 
8144   @param  Buffer  The pointer to a buffer to save the floating point/SSE/SSE2 context.
8145 
8146 **/
8147 VOID
8148 EFIAPI
8149 AsmFxRestore (
8150   IN      CONST IA32_FX_BUFFER      *Buffer
8151   );
8152 
8153 
8154 /**
8155   Reads the current value of 64-bit MMX Register #0 (MM0).
8156 
8157   Reads and returns the current value of MM0. This function is only available
8158   on IA-32 and x64.
8159 
8160   @return The current value of MM0.
8161 
8162 **/
8163 UINT64
8164 EFIAPI
8165 AsmReadMm0 (
8166   VOID
8167   );
8168 
8169 
8170 /**
8171   Reads the current value of 64-bit MMX Register #1 (MM1).
8172 
8173   Reads and returns the current value of MM1. This function is only available
8174   on IA-32 and x64.
8175 
8176   @return The current value of MM1.
8177 
8178 **/
8179 UINT64
8180 EFIAPI
8181 AsmReadMm1 (
8182   VOID
8183   );
8184 
8185 
8186 /**
8187   Reads the current value of 64-bit MMX Register #2 (MM2).
8188 
8189   Reads and returns the current value of MM2. This function is only available
8190   on IA-32 and x64.
8191 
8192   @return The current value of MM2.
8193 
8194 **/
8195 UINT64
8196 EFIAPI
8197 AsmReadMm2 (
8198   VOID
8199   );
8200 
8201 
8202 /**
8203   Reads the current value of 64-bit MMX Register #3 (MM3).
8204 
8205   Reads and returns the current value of MM3. This function is only available
8206   on IA-32 and x64.
8207 
8208   @return The current value of MM3.
8209 
8210 **/
8211 UINT64
8212 EFIAPI
8213 AsmReadMm3 (
8214   VOID
8215   );
8216 
8217 
8218 /**
8219   Reads the current value of 64-bit MMX Register #4 (MM4).
8220 
8221   Reads and returns the current value of MM4. This function is only available
8222   on IA-32 and x64.
8223 
8224   @return The current value of MM4.
8225 
8226 **/
8227 UINT64
8228 EFIAPI
8229 AsmReadMm4 (
8230   VOID
8231   );
8232 
8233 
8234 /**
8235   Reads the current value of 64-bit MMX Register #5 (MM5).
8236 
8237   Reads and returns the current value of MM5. This function is only available
8238   on IA-32 and x64.
8239 
8240   @return The current value of MM5.
8241 
8242 **/
8243 UINT64
8244 EFIAPI
8245 AsmReadMm5 (
8246   VOID
8247   );
8248 
8249 
8250 /**
8251   Reads the current value of 64-bit MMX Register #6 (MM6).
8252 
8253   Reads and returns the current value of MM6. This function is only available
8254   on IA-32 and x64.
8255 
8256   @return The current value of MM6.
8257 
8258 **/
8259 UINT64
8260 EFIAPI
8261 AsmReadMm6 (
8262   VOID
8263   );
8264 
8265 
8266 /**
8267   Reads the current value of 64-bit MMX Register #7 (MM7).
8268 
8269   Reads and returns the current value of MM7. This function is only available
8270   on IA-32 and x64.
8271 
8272   @return The current value of MM7.
8273 
8274 **/
8275 UINT64
8276 EFIAPI
8277 AsmReadMm7 (
8278   VOID
8279   );
8280 
8281 
8282 /**
8283   Writes the current value of 64-bit MMX Register #0 (MM0).
8284 
8285   Writes the current value of MM0. This function is only available on IA32 and
8286   x64.
8287 
8288   @param  Value The 64-bit value to write to MM0.
8289 
8290 **/
8291 VOID
8292 EFIAPI
8293 AsmWriteMm0 (
8294   IN      UINT64                    Value
8295   );
8296 
8297 
8298 /**
8299   Writes the current value of 64-bit MMX Register #1 (MM1).
8300 
8301   Writes the current value of MM1. This function is only available on IA32 and
8302   x64.
8303 
8304   @param  Value The 64-bit value to write to MM1.
8305 
8306 **/
8307 VOID
8308 EFIAPI
8309 AsmWriteMm1 (
8310   IN      UINT64                    Value
8311   );
8312 
8313 
8314 /**
8315   Writes the current value of 64-bit MMX Register #2 (MM2).
8316 
8317   Writes the current value of MM2. This function is only available on IA32 and
8318   x64.
8319 
8320   @param  Value The 64-bit value to write to MM2.
8321 
8322 **/
8323 VOID
8324 EFIAPI
8325 AsmWriteMm2 (
8326   IN      UINT64                    Value
8327   );
8328 
8329 
8330 /**
8331   Writes the current value of 64-bit MMX Register #3 (MM3).
8332 
8333   Writes the current value of MM3. This function is only available on IA32 and
8334   x64.
8335 
8336   @param  Value The 64-bit value to write to MM3.
8337 
8338 **/
8339 VOID
8340 EFIAPI
8341 AsmWriteMm3 (
8342   IN      UINT64                    Value
8343   );
8344 
8345 
8346 /**
8347   Writes the current value of 64-bit MMX Register #4 (MM4).
8348 
8349   Writes the current value of MM4. This function is only available on IA32 and
8350   x64.
8351 
8352   @param  Value The 64-bit value to write to MM4.
8353 
8354 **/
8355 VOID
8356 EFIAPI
8357 AsmWriteMm4 (
8358   IN      UINT64                    Value
8359   );
8360 
8361 
8362 /**
8363   Writes the current value of 64-bit MMX Register #5 (MM5).
8364 
8365   Writes the current value of MM5. This function is only available on IA32 and
8366   x64.
8367 
8368   @param  Value The 64-bit value to write to MM5.
8369 
8370 **/
8371 VOID
8372 EFIAPI
8373 AsmWriteMm5 (
8374   IN      UINT64                    Value
8375   );
8376 
8377 
8378 /**
8379   Writes the current value of 64-bit MMX Register #6 (MM6).
8380 
8381   Writes the current value of MM6. This function is only available on IA32 and
8382   x64.
8383 
8384   @param  Value The 64-bit value to write to MM6.
8385 
8386 **/
8387 VOID
8388 EFIAPI
8389 AsmWriteMm6 (
8390   IN      UINT64                    Value
8391   );
8392 
8393 
8394 /**
8395   Writes the current value of 64-bit MMX Register #7 (MM7).
8396 
8397   Writes the current value of MM7. This function is only available on IA32 and
8398   x64.
8399 
8400   @param  Value The 64-bit value to write to MM7.
8401 
8402 **/
8403 VOID
8404 EFIAPI
8405 AsmWriteMm7 (
8406   IN      UINT64                    Value
8407   );
8408 
8409 
8410 /**
8411   Reads the current value of Time Stamp Counter (TSC).
8412 
8413   Reads and returns the current value of TSC. This function is only available
8414   on IA-32 and x64.
8415 
8416   @return The current value of TSC
8417 
8418 **/
8419 UINT64
8420 EFIAPI
8421 AsmReadTsc (
8422   VOID
8423   );
8424 
8425 
8426 /**
8427   Reads the current value of a Performance Counter (PMC).
8428 
8429   Reads and returns the current value of performance counter specified by
8430   Index. This function is only available on IA-32 and x64.
8431 
8432   @param  Index The 32-bit Performance Counter index to read.
8433 
8434   @return The value of the PMC specified by Index.
8435 
8436 **/
8437 UINT64
8438 EFIAPI
8439 AsmReadPmc (
8440   IN      UINT32                    Index
8441   );
8442 
8443 
8444 /**
8445   Sets up a monitor buffer that is used by AsmMwait().
8446 
8447   Executes a MONITOR instruction with the register state specified by Eax, Ecx
8448   and Edx. Returns Eax. This function is only available on IA-32 and x64.
8449 
8450   @param  Eax The value to load into EAX or RAX before executing the MONITOR
8451               instruction.
8452   @param  Ecx The value to load into ECX or RCX before executing the MONITOR
8453               instruction.
8454   @param  Edx The value to load into EDX or RDX before executing the MONITOR
8455               instruction.
8456 
8457   @return Eax
8458 
8459 **/
8460 UINTN
8461 EFIAPI
8462 AsmMonitor (
8463   IN      UINTN                     Eax,
8464   IN      UINTN                     Ecx,
8465   IN      UINTN                     Edx
8466   );
8467 
8468 
8469 /**
8470   Executes an MWAIT instruction.
8471 
8472   Executes an MWAIT instruction with the register state specified by Eax and
8473   Ecx. Returns Eax. This function is only available on IA-32 and x64.
8474 
8475   @param  Eax The value to load into EAX or RAX before executing the MONITOR
8476               instruction.
8477   @param  Ecx The value to load into ECX or RCX before executing the MONITOR
8478               instruction.
8479 
8480   @return Eax
8481 
8482 **/
8483 UINTN
8484 EFIAPI
8485 AsmMwait (
8486   IN      UINTN                     Eax,
8487   IN      UINTN                     Ecx
8488   );
8489 
8490 
8491 /**
8492   Executes a WBINVD instruction.
8493 
8494   Executes a WBINVD instruction. This function is only available on IA-32 and
8495   x64.
8496 
8497 **/
8498 VOID
8499 EFIAPI
8500 AsmWbinvd (
8501   VOID
8502   );
8503 
8504 
8505 /**
8506   Executes a INVD instruction.
8507 
8508   Executes a INVD instruction. This function is only available on IA-32 and
8509   x64.
8510 
8511 **/
8512 VOID
8513 EFIAPI
8514 AsmInvd (
8515   VOID
8516   );
8517 
8518 
8519 /**
8520   Flushes a cache line from all the instruction and data caches within the
8521   coherency domain of the CPU.
8522 
8523   Flushed the cache line specified by LinearAddress, and returns LinearAddress.
8524   This function is only available on IA-32 and x64.
8525 
8526   @param  LinearAddress The address of the cache line to flush. If the CPU is
8527                         in a physical addressing mode, then LinearAddress is a
8528                         physical address. If the CPU is in a virtual
8529                         addressing mode, then LinearAddress is a virtual
8530                         address.
8531 
8532   @return LinearAddress.
8533 **/
8534 VOID *
8535 EFIAPI
8536 AsmFlushCacheLine (
8537   IN      VOID                      *LinearAddress
8538   );
8539 
8540 
8541 /**
8542   Enables the 32-bit paging mode on the CPU.
8543 
8544   Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
8545   must be properly initialized prior to calling this service. This function
8546   assumes the current execution mode is 32-bit protected mode. This function is
8547   only available on IA-32. After the 32-bit paging mode is enabled, control is
8548   transferred to the function specified by EntryPoint using the new stack
8549   specified by NewStack and passing in the parameters specified by Context1 and
8550   Context2. Context1 and Context2 are optional and may be NULL. The function
8551   EntryPoint must never return.
8552 
8553   If the current execution mode is not 32-bit protected mode, then ASSERT().
8554   If EntryPoint is NULL, then ASSERT().
8555   If NewStack is NULL, then ASSERT().
8556 
8557   There are a number of constraints that must be followed before calling this
8558   function:
8559   1)  Interrupts must be disabled.
8560   2)  The caller must be in 32-bit protected mode with flat descriptors. This
8561       means all descriptors must have a base of 0 and a limit of 4GB.
8562   3)  CR0 and CR4 must be compatible with 32-bit protected mode with flat
8563       descriptors.
8564   4)  CR3 must point to valid page tables that will be used once the transition
8565       is complete, and those page tables must guarantee that the pages for this
8566       function and the stack are identity mapped.
8567 
8568   @param  EntryPoint  A pointer to function to call with the new stack after
8569                       paging is enabled.
8570   @param  Context1    A pointer to the context to pass into the EntryPoint
8571                       function as the first parameter after paging is enabled.
8572   @param  Context2    A pointer to the context to pass into the EntryPoint
8573                       function as the second parameter after paging is enabled.
8574   @param  NewStack    A pointer to the new stack to use for the EntryPoint
8575                       function after paging is enabled.
8576 
8577 **/
8578 VOID
8579 EFIAPI
8580 AsmEnablePaging32 (
8581   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
8582   IN      VOID                      *Context1,  OPTIONAL
8583   IN      VOID                      *Context2,  OPTIONAL
8584   IN      VOID                      *NewStack
8585   );
8586 
8587 
8588 /**
8589   Disables the 32-bit paging mode on the CPU.
8590 
8591   Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
8592   mode. This function assumes the current execution mode is 32-paged protected
8593   mode. This function is only available on IA-32. After the 32-bit paging mode
8594   is disabled, control is transferred to the function specified by EntryPoint
8595   using the new stack specified by NewStack and passing in the parameters
8596   specified by Context1 and Context2. Context1 and Context2 are optional and
8597   may be NULL. The function EntryPoint must never return.
8598 
8599   If the current execution mode is not 32-bit paged mode, then ASSERT().
8600   If EntryPoint is NULL, then ASSERT().
8601   If NewStack is NULL, then ASSERT().
8602 
8603   There are a number of constraints that must be followed before calling this
8604   function:
8605   1)  Interrupts must be disabled.
8606   2)  The caller must be in 32-bit paged mode.
8607   3)  CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
8608   4)  CR3 must point to valid page tables that guarantee that the pages for
8609       this function and the stack are identity mapped.
8610 
8611   @param  EntryPoint  A pointer to function to call with the new stack after
8612                       paging is disabled.
8613   @param  Context1    A pointer to the context to pass into the EntryPoint
8614                       function as the first parameter after paging is disabled.
8615   @param  Context2    A pointer to the context to pass into the EntryPoint
8616                       function as the second parameter after paging is
8617                       disabled.
8618   @param  NewStack    A pointer to the new stack to use for the EntryPoint
8619                       function after paging is disabled.
8620 
8621 **/
8622 VOID
8623 EFIAPI
8624 AsmDisablePaging32 (
8625   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
8626   IN      VOID                      *Context1,  OPTIONAL
8627   IN      VOID                      *Context2,  OPTIONAL
8628   IN      VOID                      *NewStack
8629   );
8630 
8631 
8632 /**
8633   Enables the 64-bit paging mode on the CPU.
8634 
8635   Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
8636   must be properly initialized prior to calling this service. This function
8637   assumes the current execution mode is 32-bit protected mode with flat
8638   descriptors. This function is only available on IA-32. After the 64-bit
8639   paging mode is enabled, control is transferred to the function specified by
8640   EntryPoint using the new stack specified by NewStack and passing in the
8641   parameters specified by Context1 and Context2. Context1 and Context2 are
8642   optional and may be 0. The function EntryPoint must never return.
8643 
8644   If the current execution mode is not 32-bit protected mode with flat
8645   descriptors, then ASSERT().
8646   If EntryPoint is 0, then ASSERT().
8647   If NewStack is 0, then ASSERT().
8648 
8649   @param  Cs          The 16-bit selector to load in the CS before EntryPoint
8650                       is called. The descriptor in the GDT that this selector
8651                       references must be setup for long mode.
8652   @param  EntryPoint  The 64-bit virtual address of the function to call with
8653                       the new stack after paging is enabled.
8654   @param  Context1    The 64-bit virtual address of the context to pass into
8655                       the EntryPoint function as the first parameter after
8656                       paging is enabled.
8657   @param  Context2    The 64-bit virtual address of the context to pass into
8658                       the EntryPoint function as the second parameter after
8659                       paging is enabled.
8660   @param  NewStack    The 64-bit virtual address of the new stack to use for
8661                       the EntryPoint function after paging is enabled.
8662 
8663 **/
8664 VOID
8665 EFIAPI
8666 AsmEnablePaging64 (
8667   IN      UINT16                    Cs,
8668   IN      UINT64                    EntryPoint,
8669   IN      UINT64                    Context1,  OPTIONAL
8670   IN      UINT64                    Context2,  OPTIONAL
8671   IN      UINT64                    NewStack
8672   );
8673 
8674 
8675 /**
8676   Disables the 64-bit paging mode on the CPU.
8677 
8678   Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
8679   mode. This function assumes the current execution mode is 64-paging mode.
8680   This function is only available on x64. After the 64-bit paging mode is
8681   disabled, control is transferred to the function specified by EntryPoint
8682   using the new stack specified by NewStack and passing in the parameters
8683   specified by Context1 and Context2. Context1 and Context2 are optional and
8684   may be 0. The function EntryPoint must never return.
8685 
8686   If the current execution mode is not 64-bit paged mode, then ASSERT().
8687   If EntryPoint is 0, then ASSERT().
8688   If NewStack is 0, then ASSERT().
8689 
8690   @param  Cs          The 16-bit selector to load in the CS before EntryPoint
8691                       is called. The descriptor in the GDT that this selector
8692                       references must be setup for 32-bit protected mode.
8693   @param  EntryPoint  The 64-bit virtual address of the function to call with
8694                       the new stack after paging is disabled.
8695   @param  Context1    The 64-bit virtual address of the context to pass into
8696                       the EntryPoint function as the first parameter after
8697                       paging is disabled.
8698   @param  Context2    The 64-bit virtual address of the context to pass into
8699                       the EntryPoint function as the second parameter after
8700                       paging is disabled.
8701   @param  NewStack    The 64-bit virtual address of the new stack to use for
8702                       the EntryPoint function after paging is disabled.
8703 
8704 **/
8705 VOID
8706 EFIAPI
8707 AsmDisablePaging64 (
8708   IN      UINT16                    Cs,
8709   IN      UINT32                    EntryPoint,
8710   IN      UINT32                    Context1,  OPTIONAL
8711   IN      UINT32                    Context2,  OPTIONAL
8712   IN      UINT32                    NewStack
8713   );
8714 
8715 
8716 //
8717 // 16-bit thunking services
8718 //
8719 
8720 /**
8721   Retrieves the properties for 16-bit thunk functions.
8722 
8723   Computes the size of the buffer and stack below 1MB required to use the
8724   AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
8725   buffer size is returned in RealModeBufferSize, and the stack size is returned
8726   in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
8727   then the actual minimum stack size is ExtraStackSize plus the maximum number
8728   of bytes that need to be passed to the 16-bit real mode code.
8729 
8730   If RealModeBufferSize is NULL, then ASSERT().
8731   If ExtraStackSize is NULL, then ASSERT().
8732 
8733   @param  RealModeBufferSize  A pointer to the size of the buffer below 1MB
8734                               required to use the 16-bit thunk functions.
8735   @param  ExtraStackSize      A pointer to the extra size of stack below 1MB
8736                               that the 16-bit thunk functions require for
8737                               temporary storage in the transition to and from
8738                               16-bit real mode.
8739 
8740 **/
8741 VOID
8742 EFIAPI
8743 AsmGetThunk16Properties (
8744   OUT     UINT32                    *RealModeBufferSize,
8745   OUT     UINT32                    *ExtraStackSize
8746   );
8747 
8748 
8749 /**
8750   Prepares all structures a code required to use AsmThunk16().
8751 
8752   Prepares all structures and code required to use AsmThunk16().
8753 
8754   This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
8755   virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
8756 
8757   If ThunkContext is NULL, then ASSERT().
8758 
8759   @param  ThunkContext  A pointer to the context structure that describes the
8760                         16-bit real mode code to call.
8761 
8762 **/
8763 VOID
8764 EFIAPI
8765 AsmPrepareThunk16 (
8766   IN OUT  THUNK_CONTEXT             *ThunkContext
8767   );
8768 
8769 
8770 /**
8771   Transfers control to a 16-bit real mode entry point and returns the results.
8772 
8773   Transfers control to a 16-bit real mode entry point and returns the results.
8774   AsmPrepareThunk16() must be called with ThunkContext before this function is used.
8775   This function must be called with interrupts disabled.
8776 
8777   The register state from the RealModeState field of ThunkContext is restored just prior
8778   to calling the 16-bit real mode entry point.  This includes the EFLAGS field of RealModeState,
8779   which is used to set the interrupt state when a 16-bit real mode entry point is called.
8780   Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.
8781   The stack is initialized to the SS and ESP fields of RealModeState.  Any parameters passed to
8782   the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.
8783   The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,
8784   so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment
8785   and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry
8786   point must exit with a RETF instruction. The register state is captured into RealModeState immediately
8787   after the RETF instruction is executed.
8788 
8789   If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
8790   or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure
8791   the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.
8792 
8793   If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
8794   then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.
8795   This includes the base vectors, the interrupt masks, and the edge/level trigger mode.
8796 
8797   If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code
8798   is invoked in big real mode.  Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.
8799 
8800   If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
8801   ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to
8802   disable the A20 mask.
8803 
8804   If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in
8805   ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask.  If this INT 15 call fails,
8806   then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
8807 
8808   If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in
8809   ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
8810 
8811   If ThunkContext is NULL, then ASSERT().
8812   If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
8813   If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
8814   ThunkAttributes, then ASSERT().
8815 
8816   This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
8817   virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.
8818 
8819   @param  ThunkContext  A pointer to the context structure that describes the
8820                         16-bit real mode code to call.
8821 
8822 **/
8823 VOID
8824 EFIAPI
8825 AsmThunk16 (
8826   IN OUT  THUNK_CONTEXT             *ThunkContext
8827   );
8828 
8829 
8830 /**
8831   Prepares all structures and code for a 16-bit real mode thunk, transfers
8832   control to a 16-bit real mode entry point, and returns the results.
8833 
8834   Prepares all structures and code for a 16-bit real mode thunk, transfers
8835   control to a 16-bit real mode entry point, and returns the results. If the
8836   caller only need to perform a single 16-bit real mode thunk, then this
8837   service should be used. If the caller intends to make more than one 16-bit
8838   real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
8839   once and AsmThunk16() can be called for each 16-bit real mode thunk.
8840 
8841   This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
8842   virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
8843 
8844   See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.
8845 
8846   @param  ThunkContext  A pointer to the context structure that describes the
8847                         16-bit real mode code to call.
8848 
8849 **/
8850 VOID
8851 EFIAPI
8852 AsmPrepareAndThunk16 (
8853   IN OUT  THUNK_CONTEXT             *ThunkContext
8854   );
8855 
8856 /**
8857   Generates a 16-bit random number through RDRAND instruction.
8858 
8859   if Rand is NULL, then ASSERT().
8860 
8861   @param[out]  Rand     Buffer pointer to store the random result.
8862 
8863   @retval TRUE          RDRAND call was successful.
8864   @retval FALSE         Failed attempts to call RDRAND.
8865 
8866  **/
8867 BOOLEAN
8868 EFIAPI
8869 AsmRdRand16 (
8870   OUT     UINT16                    *Rand
8871   );
8872 
8873 /**
8874   Generates a 32-bit random number through RDRAND instruction.
8875 
8876   if Rand is NULL, then ASSERT().
8877 
8878   @param[out]  Rand     Buffer pointer to store the random result.
8879 
8880   @retval TRUE          RDRAND call was successful.
8881   @retval FALSE         Failed attempts to call RDRAND.
8882 
8883 **/
8884 BOOLEAN
8885 EFIAPI
8886 AsmRdRand32 (
8887   OUT     UINT32                    *Rand
8888   );
8889 
8890 /**
8891   Generates a 64-bit random number through RDRAND instruction.
8892 
8893   if Rand is NULL, then ASSERT().
8894 
8895   @param[out]  Rand     Buffer pointer to store the random result.
8896 
8897   @retval TRUE          RDRAND call was successful.
8898   @retval FALSE         Failed attempts to call RDRAND.
8899 
8900 **/
8901 BOOLEAN
8902 EFIAPI
8903 AsmRdRand64  (
8904   OUT     UINT64                    *Rand
8905   );
8906 
8907 #endif
8908 #endif
8909 
8910 
8911