VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdePkg/Include/Library/BaseLib.h@ 105668

Last change on this file since 105668 was 101291, checked in by vboxsync, 16 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette