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