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