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