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