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