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