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