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