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