]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/BaseLib.h
9d58a7c4ad13e5a9eb240639370e3f964156e9c6
[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 // Base Library CPU Functions
4508 //
4509
4510 /**
4511 Function entry point used when a stack switch is requested with SwitchStack()
4512
4513 @param Context1 Context1 parameter passed into SwitchStack().
4514 @param Context2 Context2 parameter passed into SwitchStack().
4515
4516 **/
4517 typedef
4518 VOID
4519 (EFIAPI *SWITCH_STACK_ENTRY_POINT)(
4520 IN VOID *Context1 OPTIONAL,
4521 IN VOID *Context2 OPTIONAL
4522 );
4523
4524 /**
4525 Used to serialize load and store operations.
4526
4527 All loads and stores that proceed calls to this function are guaranteed to be
4528 globally visible when this function returns.
4529
4530 **/
4531 VOID
4532 EFIAPI
4533 MemoryFence (
4534 VOID
4535 );
4536
4537 /**
4538 Saves the current CPU context that can be restored with a call to LongJump()
4539 and returns 0.
4540
4541 Saves the current CPU context in the buffer specified by JumpBuffer and
4542 returns 0. The initial call to SetJump() must always return 0. Subsequent
4543 calls to LongJump() cause a non-zero value to be returned by SetJump().
4544
4545 If JumpBuffer is NULL, then ASSERT().
4546 For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
4547
4548 NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.
4549 The same structure must never be used for more than one CPU architecture context.
4550 For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module.
4551 SetJump()/LongJump() is not currently supported for the EBC processor type.
4552
4553 @param JumpBuffer A pointer to CPU context buffer.
4554
4555 @retval 0 Indicates a return from SetJump().
4556
4557 **/
4558 RETURNS_TWICE
4559 UINTN
4560 EFIAPI
4561 SetJump (
4562 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
4563 );
4564
4565 /**
4566 Restores the CPU context that was saved with SetJump().
4567
4568 Restores the CPU context from the buffer specified by JumpBuffer. This
4569 function never returns to the caller. Instead is resumes execution based on
4570 the state of JumpBuffer.
4571
4572 If JumpBuffer is NULL, then ASSERT().
4573 For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
4574 If Value is 0, then ASSERT().
4575
4576 @param JumpBuffer A pointer to CPU context buffer.
4577 @param Value The value to return when the SetJump() context is
4578 restored and must be non-zero.
4579
4580 **/
4581 VOID
4582 EFIAPI
4583 LongJump (
4584 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
4585 IN UINTN Value
4586 );
4587
4588 /**
4589 Enables CPU interrupts.
4590
4591 **/
4592 VOID
4593 EFIAPI
4594 EnableInterrupts (
4595 VOID
4596 );
4597
4598 /**
4599 Disables CPU interrupts.
4600
4601 **/
4602 VOID
4603 EFIAPI
4604 DisableInterrupts (
4605 VOID
4606 );
4607
4608 /**
4609 Disables CPU interrupts and returns the interrupt state prior to the disable
4610 operation.
4611
4612 @retval TRUE CPU interrupts were enabled on entry to this call.
4613 @retval FALSE CPU interrupts were disabled on entry to this call.
4614
4615 **/
4616 BOOLEAN
4617 EFIAPI
4618 SaveAndDisableInterrupts (
4619 VOID
4620 );
4621
4622 /**
4623 Enables CPU interrupts for the smallest window required to capture any
4624 pending interrupts.
4625
4626 **/
4627 VOID
4628 EFIAPI
4629 EnableDisableInterrupts (
4630 VOID
4631 );
4632
4633 /**
4634 Retrieves the current CPU interrupt state.
4635
4636 Returns TRUE if interrupts are currently enabled. Otherwise
4637 returns FALSE.
4638
4639 @retval TRUE CPU interrupts are enabled.
4640 @retval FALSE CPU interrupts are disabled.
4641
4642 **/
4643 BOOLEAN
4644 EFIAPI
4645 GetInterruptState (
4646 VOID
4647 );
4648
4649 /**
4650 Set the current CPU interrupt state.
4651
4652 Sets the current CPU interrupt state to the state specified by
4653 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
4654 InterruptState is FALSE, then interrupts are disabled. InterruptState is
4655 returned.
4656
4657 @param InterruptState TRUE if interrupts should enabled. FALSE if
4658 interrupts should be disabled.
4659
4660 @return InterruptState
4661
4662 **/
4663 BOOLEAN
4664 EFIAPI
4665 SetInterruptState (
4666 IN BOOLEAN InterruptState
4667 );
4668
4669 /**
4670 Requests CPU to pause for a short period of time.
4671
4672 Requests CPU to pause for a short period of time. Typically used in MP
4673 systems to prevent memory starvation while waiting for a spin lock.
4674
4675 **/
4676 VOID
4677 EFIAPI
4678 CpuPause (
4679 VOID
4680 );
4681
4682 /**
4683 Transfers control to a function starting with a new stack.
4684
4685 Transfers control to the function specified by EntryPoint using the
4686 new stack specified by NewStack and passing in the parameters specified
4687 by Context1 and Context2. Context1 and Context2 are optional and may
4688 be NULL. The function EntryPoint must never return. This function
4689 supports a variable number of arguments following the NewStack parameter.
4690 These additional arguments are ignored on IA-32, x64, and EBC architectures.
4691 Itanium processors expect one additional parameter of type VOID * that specifies
4692 the new backing store pointer.
4693
4694 If EntryPoint is NULL, then ASSERT().
4695 If NewStack is NULL, then ASSERT().
4696
4697 @param EntryPoint A pointer to function to call with the new stack.
4698 @param Context1 A pointer to the context to pass into the EntryPoint
4699 function.
4700 @param Context2 A pointer to the context to pass into the EntryPoint
4701 function.
4702 @param NewStack A pointer to the new stack to use for the EntryPoint
4703 function.
4704 @param ... This variable argument list is ignored for IA-32, x64, and
4705 EBC architectures. For Itanium processors, this variable
4706 argument list is expected to contain a single parameter of
4707 type VOID * that specifies the new backing store pointer.
4708
4709
4710 **/
4711 VOID
4712 EFIAPI
4713 SwitchStack (
4714 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
4715 IN VOID *Context1 OPTIONAL,
4716 IN VOID *Context2 OPTIONAL,
4717 IN VOID *NewStack,
4718 ...
4719 );
4720
4721 /**
4722 Generates a breakpoint on the CPU.
4723
4724 Generates a breakpoint on the CPU. The breakpoint must be implemented such
4725 that code can resume normal execution after the breakpoint.
4726
4727 **/
4728 VOID
4729 EFIAPI
4730 CpuBreakpoint (
4731 VOID
4732 );
4733
4734 /**
4735 Executes an infinite loop.
4736
4737 Forces the CPU to execute an infinite loop. A debugger may be used to skip
4738 past the loop and the code that follows the loop must execute properly. This
4739 implies that the infinite loop must not cause the code that follow it to be
4740 optimized away.
4741
4742 **/
4743 VOID
4744 EFIAPI
4745 CpuDeadLoop (
4746 VOID
4747 );
4748
4749 /**
4750 Uses as a barrier to stop speculative execution.
4751
4752 Ensures that no later instruction will execute speculatively, until all prior
4753 instructions have completed.
4754
4755 **/
4756 VOID
4757 EFIAPI
4758 SpeculationBarrier (
4759 VOID
4760 );
4761
4762 #if defined (MDE_CPU_X64) || defined (MDE_CPU_IA32)
4763
4764 /**
4765 The TDCALL instruction causes a VM exit to the Intel TDX module. It is
4766 used to call guest-side Intel TDX functions, either local or a TD exit
4767 to the host VMM, as selected by Leaf.
4768
4769 @param[in] Leaf Leaf number of TDCALL instruction
4770 @param[in] Arg1 Arg1
4771 @param[in] Arg2 Arg2
4772 @param[in] Arg3 Arg3
4773 @param[in,out] Results Returned result of the Leaf function
4774
4775 @return 0 A successful call
4776 @return Other See individual leaf functions
4777 **/
4778 UINTN
4779 EFIAPI
4780 TdCall (
4781 IN UINT64 Leaf,
4782 IN UINT64 Arg1,
4783 IN UINT64 Arg2,
4784 IN UINT64 Arg3,
4785 IN OUT VOID *Results
4786 );
4787
4788 /**
4789 TDVMALL is a leaf function 0 for TDCALL. It helps invoke services from the
4790 host VMM to pass/receive information.
4791
4792 @param[in] Leaf Number of sub-functions
4793 @param[in] Arg1 Arg1
4794 @param[in] Arg2 Arg2
4795 @param[in] Arg3 Arg3
4796 @param[in] Arg4 Arg4
4797 @param[in,out] Results Returned result of the sub-function
4798
4799 @return 0 A successful call
4800 @return Other See individual sub-functions
4801
4802 **/
4803 UINTN
4804 EFIAPI
4805 TdVmCall (
4806 IN UINT64 Leaf,
4807 IN UINT64 Arg1,
4808 IN UINT64 Arg2,
4809 IN UINT64 Arg3,
4810 IN UINT64 Arg4,
4811 IN OUT VOID *Results
4812 );
4813
4814 /**
4815 Probe if TD is enabled.
4816
4817 @return TRUE TD is enabled.
4818 @return FALSE TD is not enabled.
4819 **/
4820 BOOLEAN
4821 EFIAPI
4822 TdIsEnabled (
4823 VOID
4824 );
4825
4826 #endif
4827
4828 #if defined (MDE_CPU_X64)
4829 //
4830 // The page size for the PVALIDATE instruction
4831 //
4832 typedef enum {
4833 PvalidatePageSize4K = 0,
4834 PvalidatePageSize2MB,
4835 } PVALIDATE_PAGE_SIZE;
4836
4837 //
4838 // PVALIDATE Return Code.
4839 //
4840 #define PVALIDATE_RET_SUCCESS 0
4841 #define PVALIDATE_RET_FAIL_INPUT 1
4842 #define PVALIDATE_RET_SIZE_MISMATCH 6
4843
4844 //
4845 // The PVALIDATE instruction did not make any changes to the RMP entry.
4846 //
4847 #define PVALIDATE_RET_NO_RMPUPDATE 255
4848
4849 /**
4850 Execute a PVALIDATE instruction to validate or to rescinds validation of a guest
4851 page's RMP entry.
4852
4853 The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=1.
4854
4855 The function is available on X64.
4856
4857 @param[in] PageSize The page size to use.
4858 @param[in] Validate If TRUE, validate the guest virtual address
4859 otherwise invalidate the guest virtual address.
4860 @param[in] Address The guest virtual address.
4861
4862 @retval PVALIDATE_RET_SUCCESS The PVALIDATE instruction succeeded, and
4863 updated the RMP entry.
4864 @retval PVALIDATE_RET_NO_RMPUPDATE The PVALIDATE instruction succeeded, but
4865 did not update the RMP entry.
4866 @return Failure code from the PVALIDATE
4867 instruction.
4868 **/
4869 UINT32
4870 EFIAPI
4871 AsmPvalidate (
4872 IN PVALIDATE_PAGE_SIZE PageSize,
4873 IN BOOLEAN Validate,
4874 IN PHYSICAL_ADDRESS Address
4875 );
4876
4877 //
4878 // RDX settings for RMPADJUST
4879 //
4880 #define RMPADJUST_VMPL_MAX 3
4881 #define RMPADJUST_VMPL_MASK 0xFF
4882 #define RMPADJUST_VMPL_SHIFT 0
4883 #define RMPADJUST_PERMISSION_MASK_MASK 0xFF
4884 #define RMPADJUST_PERMISSION_MASK_SHIFT 8
4885 #define RMPADJUST_VMSA_PAGE_BIT BIT16
4886
4887 /**
4888 Adjusts the permissions of an SEV-SNP guest page.
4889
4890 Executes a RMPADJUST instruction with the register state specified by Rax,
4891 Rcx, and Rdx. Returns Eax. This function is only available on X64.
4892
4893 The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=1.
4894
4895 @param[in] Rax The value to load into RAX before executing the RMPADJUST
4896 instruction.
4897 @param[in] Rcx The value to load into RCX before executing the RMPADJUST
4898 instruction.
4899 @param[in] Rdx The value to load into RDX before executing the RMPADJUST
4900 instruction.
4901
4902 @return Eax
4903 **/
4904 UINT32
4905 EFIAPI
4906 AsmRmpAdjust (
4907 IN UINT64 Rax,
4908 IN UINT64 Rcx,
4909 IN UINT64 Rdx
4910 );
4911
4912 #endif
4913
4914 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
4915 ///
4916 /// IA32 and x64 Specific Functions.
4917 /// Byte packed structure for 16-bit Real Mode EFLAGS.
4918 ///
4919 typedef union {
4920 struct {
4921 UINT32 CF : 1; ///< Carry Flag.
4922 UINT32 Reserved_0 : 1; ///< Reserved.
4923 UINT32 PF : 1; ///< Parity Flag.
4924 UINT32 Reserved_1 : 1; ///< Reserved.
4925 UINT32 AF : 1; ///< Auxiliary Carry Flag.
4926 UINT32 Reserved_2 : 1; ///< Reserved.
4927 UINT32 ZF : 1; ///< Zero Flag.
4928 UINT32 SF : 1; ///< Sign Flag.
4929 UINT32 TF : 1; ///< Trap Flag.
4930 UINT32 IF : 1; ///< Interrupt Enable Flag.
4931 UINT32 DF : 1; ///< Direction Flag.
4932 UINT32 OF : 1; ///< Overflow Flag.
4933 UINT32 IOPL : 2; ///< I/O Privilege Level.
4934 UINT32 NT : 1; ///< Nested Task.
4935 UINT32 Reserved_3 : 1; ///< Reserved.
4936 } Bits;
4937 UINT16 Uint16;
4938 } IA32_FLAGS16;
4939
4940 ///
4941 /// Byte packed structure for EFLAGS/RFLAGS.
4942 /// 32-bits on IA-32.
4943 /// 64-bits on x64. The upper 32-bits on x64 are reserved.
4944 ///
4945 typedef union {
4946 struct {
4947 UINT32 CF : 1; ///< Carry Flag.
4948 UINT32 Reserved_0 : 1; ///< Reserved.
4949 UINT32 PF : 1; ///< Parity Flag.
4950 UINT32 Reserved_1 : 1; ///< Reserved.
4951 UINT32 AF : 1; ///< Auxiliary Carry Flag.
4952 UINT32 Reserved_2 : 1; ///< Reserved.
4953 UINT32 ZF : 1; ///< Zero Flag.
4954 UINT32 SF : 1; ///< Sign Flag.
4955 UINT32 TF : 1; ///< Trap Flag.
4956 UINT32 IF : 1; ///< Interrupt Enable Flag.
4957 UINT32 DF : 1; ///< Direction Flag.
4958 UINT32 OF : 1; ///< Overflow Flag.
4959 UINT32 IOPL : 2; ///< I/O Privilege Level.
4960 UINT32 NT : 1; ///< Nested Task.
4961 UINT32 Reserved_3 : 1; ///< Reserved.
4962 UINT32 RF : 1; ///< Resume Flag.
4963 UINT32 VM : 1; ///< Virtual 8086 Mode.
4964 UINT32 AC : 1; ///< Alignment Check.
4965 UINT32 VIF : 1; ///< Virtual Interrupt Flag.
4966 UINT32 VIP : 1; ///< Virtual Interrupt Pending.
4967 UINT32 ID : 1; ///< ID Flag.
4968 UINT32 Reserved_4 : 10; ///< Reserved.
4969 } Bits;
4970 UINTN UintN;
4971 } IA32_EFLAGS32;
4972
4973 ///
4974 /// Byte packed structure for Control Register 0 (CR0).
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 PE : 1; ///< Protection Enable.
4981 UINT32 MP : 1; ///< Monitor Coprocessor.
4982 UINT32 EM : 1; ///< Emulation.
4983 UINT32 TS : 1; ///< Task Switched.
4984 UINT32 ET : 1; ///< Extension Type.
4985 UINT32 NE : 1; ///< Numeric Error.
4986 UINT32 Reserved_0 : 10; ///< Reserved.
4987 UINT32 WP : 1; ///< Write Protect.
4988 UINT32 Reserved_1 : 1; ///< Reserved.
4989 UINT32 AM : 1; ///< Alignment Mask.
4990 UINT32 Reserved_2 : 10; ///< Reserved.
4991 UINT32 NW : 1; ///< Mot Write-through.
4992 UINT32 CD : 1; ///< Cache Disable.
4993 UINT32 PG : 1; ///< Paging.
4994 } Bits;
4995 UINTN UintN;
4996 } IA32_CR0;
4997
4998 ///
4999 /// Byte packed structure for Control Register 4 (CR4).
5000 /// 32-bits on IA-32.
5001 /// 64-bits on x64. The upper 32-bits on x64 are reserved.
5002 ///
5003 typedef union {
5004 struct {
5005 UINT32 VME : 1; ///< Virtual-8086 Mode Extensions.
5006 UINT32 PVI : 1; ///< Protected-Mode Virtual Interrupts.
5007 UINT32 TSD : 1; ///< Time Stamp Disable.
5008 UINT32 DE : 1; ///< Debugging Extensions.
5009 UINT32 PSE : 1; ///< Page Size Extensions.
5010 UINT32 PAE : 1; ///< Physical Address Extension.
5011 UINT32 MCE : 1; ///< Machine Check Enable.
5012 UINT32 PGE : 1; ///< Page Global Enable.
5013 UINT32 PCE : 1; ///< Performance Monitoring Counter
5014 ///< Enable.
5015 UINT32 OSFXSR : 1; ///< Operating System Support for
5016 ///< FXSAVE and FXRSTOR instructions
5017 UINT32 OSXMMEXCPT : 1; ///< Operating System Support for
5018 ///< Unmasked SIMD Floating Point
5019 ///< Exceptions.
5020 UINT32 UMIP : 1; ///< User-Mode Instruction Prevention.
5021 UINT32 LA57 : 1; ///< Linear Address 57bit.
5022 UINT32 VMXE : 1; ///< VMX Enable.
5023 UINT32 SMXE : 1; ///< SMX Enable.
5024 UINT32 Reserved_3 : 1; ///< Reserved.
5025 UINT32 FSGSBASE : 1; ///< FSGSBASE Enable.
5026 UINT32 PCIDE : 1; ///< PCID Enable.
5027 UINT32 OSXSAVE : 1; ///< XSAVE and Processor Extended States Enable.
5028 UINT32 Reserved_4 : 1; ///< Reserved.
5029 UINT32 SMEP : 1; ///< SMEP Enable.
5030 UINT32 SMAP : 1; ///< SMAP Enable.
5031 UINT32 PKE : 1; ///< Protection-Key Enable.
5032 UINT32 Reserved_5 : 9; ///< Reserved.
5033 } Bits;
5034 UINTN UintN;
5035 } IA32_CR4;
5036
5037 ///
5038 /// Byte packed structure for a segment descriptor in a GDT/LDT.
5039 ///
5040 typedef union {
5041 struct {
5042 UINT32 LimitLow : 16;
5043 UINT32 BaseLow : 16;
5044 UINT32 BaseMid : 8;
5045 UINT32 Type : 4;
5046 UINT32 S : 1;
5047 UINT32 DPL : 2;
5048 UINT32 P : 1;
5049 UINT32 LimitHigh : 4;
5050 UINT32 AVL : 1;
5051 UINT32 L : 1;
5052 UINT32 DB : 1;
5053 UINT32 G : 1;
5054 UINT32 BaseHigh : 8;
5055 } Bits;
5056 UINT64 Uint64;
5057 } IA32_SEGMENT_DESCRIPTOR;
5058
5059 ///
5060 /// Byte packed structure for an IDTR, GDTR, LDTR descriptor.
5061 ///
5062 #pragma pack (1)
5063 typedef struct {
5064 UINT16 Limit;
5065 UINTN Base;
5066 } IA32_DESCRIPTOR;
5067 #pragma pack ()
5068
5069 #define IA32_IDT_GATE_TYPE_TASK 0x85
5070 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
5071 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
5072 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
5073 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
5074
5075 #define IA32_GDT_TYPE_TSS 0x9
5076 #define IA32_GDT_ALIGNMENT 8
5077
5078 #if defined (MDE_CPU_IA32)
5079 ///
5080 /// Byte packed structure for an IA-32 Interrupt Gate Descriptor.
5081 ///
5082 typedef union {
5083 struct {
5084 UINT32 OffsetLow : 16; ///< Offset bits 15..0.
5085 UINT32 Selector : 16; ///< Selector.
5086 UINT32 Reserved_0 : 8; ///< Reserved.
5087 UINT32 GateType : 8; ///< Gate Type. See #defines above.
5088 UINT32 OffsetHigh : 16; ///< Offset bits 31..16.
5089 } Bits;
5090 UINT64 Uint64;
5091 } IA32_IDT_GATE_DESCRIPTOR;
5092
5093 #pragma pack (1)
5094 //
5095 // IA32 Task-State Segment Definition
5096 //
5097 typedef struct {
5098 UINT16 PreviousTaskLink;
5099 UINT16 Reserved_2;
5100 UINT32 ESP0;
5101 UINT16 SS0;
5102 UINT16 Reserved_10;
5103 UINT32 ESP1;
5104 UINT16 SS1;
5105 UINT16 Reserved_18;
5106 UINT32 ESP2;
5107 UINT16 SS2;
5108 UINT16 Reserved_26;
5109 UINT32 CR3;
5110 UINT32 EIP;
5111 UINT32 EFLAGS;
5112 UINT32 EAX;
5113 UINT32 ECX;
5114 UINT32 EDX;
5115 UINT32 EBX;
5116 UINT32 ESP;
5117 UINT32 EBP;
5118 UINT32 ESI;
5119 UINT32 EDI;
5120 UINT16 ES;
5121 UINT16 Reserved_74;
5122 UINT16 CS;
5123 UINT16 Reserved_78;
5124 UINT16 SS;
5125 UINT16 Reserved_82;
5126 UINT16 DS;
5127 UINT16 Reserved_86;
5128 UINT16 FS;
5129 UINT16 Reserved_90;
5130 UINT16 GS;
5131 UINT16 Reserved_94;
5132 UINT16 LDTSegmentSelector;
5133 UINT16 Reserved_98;
5134 UINT16 T;
5135 UINT16 IOMapBaseAddress;
5136 } IA32_TASK_STATE_SEGMENT;
5137
5138 typedef union {
5139 struct {
5140 UINT32 LimitLow : 16; ///< Segment Limit 15..00
5141 UINT32 BaseLow : 16; ///< Base Address 15..00
5142 UINT32 BaseMid : 8; ///< Base Address 23..16
5143 UINT32 Type : 4; ///< Type (1 0 B 1)
5144 UINT32 Reserved_43 : 1; ///< 0
5145 UINT32 DPL : 2; ///< Descriptor Privilege Level
5146 UINT32 P : 1; ///< Segment Present
5147 UINT32 LimitHigh : 4; ///< Segment Limit 19..16
5148 UINT32 AVL : 1; ///< Available for use by system software
5149 UINT32 Reserved_52 : 2; ///< 0 0
5150 UINT32 G : 1; ///< Granularity
5151 UINT32 BaseHigh : 8; ///< Base Address 31..24
5152 } Bits;
5153 UINT64 Uint64;
5154 } IA32_TSS_DESCRIPTOR;
5155 #pragma pack ()
5156
5157 #endif // defined (MDE_CPU_IA32)
5158
5159 #if defined (MDE_CPU_X64)
5160 ///
5161 /// Byte packed structure for an x64 Interrupt Gate Descriptor.
5162 ///
5163 typedef union {
5164 struct {
5165 UINT32 OffsetLow : 16; ///< Offset bits 15..0.
5166 UINT32 Selector : 16; ///< Selector.
5167 UINT32 Reserved_0 : 8; ///< Reserved.
5168 UINT32 GateType : 8; ///< Gate Type. See #defines above.
5169 UINT32 OffsetHigh : 16; ///< Offset bits 31..16.
5170 UINT32 OffsetUpper : 32; ///< Offset bits 63..32.
5171 UINT32 Reserved_1 : 32; ///< Reserved.
5172 } Bits;
5173 struct {
5174 UINT64 Uint64;
5175 UINT64 Uint64_1;
5176 } Uint128;
5177 } IA32_IDT_GATE_DESCRIPTOR;
5178
5179 #pragma pack (1)
5180 //
5181 // IA32 Task-State Segment Definition
5182 //
5183 typedef struct {
5184 UINT32 Reserved_0;
5185 UINT64 RSP0;
5186 UINT64 RSP1;
5187 UINT64 RSP2;
5188 UINT64 Reserved_28;
5189 UINT64 IST[7];
5190 UINT64 Reserved_92;
5191 UINT16 Reserved_100;
5192 UINT16 IOMapBaseAddress;
5193 } IA32_TASK_STATE_SEGMENT;
5194
5195 typedef union {
5196 struct {
5197 UINT32 LimitLow : 16; ///< Segment Limit 15..00
5198 UINT32 BaseLow : 16; ///< Base Address 15..00
5199 UINT32 BaseMidl : 8; ///< Base Address 23..16
5200 UINT32 Type : 4; ///< Type (1 0 B 1)
5201 UINT32 Reserved_43 : 1; ///< 0
5202 UINT32 DPL : 2; ///< Descriptor Privilege Level
5203 UINT32 P : 1; ///< Segment Present
5204 UINT32 LimitHigh : 4; ///< Segment Limit 19..16
5205 UINT32 AVL : 1; ///< Available for use by system software
5206 UINT32 Reserved_52 : 2; ///< 0 0
5207 UINT32 G : 1; ///< Granularity
5208 UINT32 BaseMidh : 8; ///< Base Address 31..24
5209 UINT32 BaseHigh : 32; ///< Base Address 63..32
5210 UINT32 Reserved_96 : 32; ///< Reserved
5211 } Bits;
5212 struct {
5213 UINT64 Uint64;
5214 UINT64 Uint64_1;
5215 } Uint128;
5216 } IA32_TSS_DESCRIPTOR;
5217 #pragma pack ()
5218
5219 #endif // defined (MDE_CPU_X64)
5220
5221 ///
5222 /// Byte packed structure for an FP/SSE/SSE2 context.
5223 ///
5224 typedef struct {
5225 UINT8 Buffer[512];
5226 } IA32_FX_BUFFER;
5227
5228 ///
5229 /// Structures for the 16-bit real mode thunks.
5230 ///
5231 typedef struct {
5232 UINT32 Reserved1;
5233 UINT32 Reserved2;
5234 UINT32 Reserved3;
5235 UINT32 Reserved4;
5236 UINT8 BL;
5237 UINT8 BH;
5238 UINT16 Reserved5;
5239 UINT8 DL;
5240 UINT8 DH;
5241 UINT16 Reserved6;
5242 UINT8 CL;
5243 UINT8 CH;
5244 UINT16 Reserved7;
5245 UINT8 AL;
5246 UINT8 AH;
5247 UINT16 Reserved8;
5248 } IA32_BYTE_REGS;
5249
5250 typedef struct {
5251 UINT16 DI;
5252 UINT16 Reserved1;
5253 UINT16 SI;
5254 UINT16 Reserved2;
5255 UINT16 BP;
5256 UINT16 Reserved3;
5257 UINT16 SP;
5258 UINT16 Reserved4;
5259 UINT16 BX;
5260 UINT16 Reserved5;
5261 UINT16 DX;
5262 UINT16 Reserved6;
5263 UINT16 CX;
5264 UINT16 Reserved7;
5265 UINT16 AX;
5266 UINT16 Reserved8;
5267 } IA32_WORD_REGS;
5268
5269 typedef struct {
5270 UINT32 EDI;
5271 UINT32 ESI;
5272 UINT32 EBP;
5273 UINT32 ESP;
5274 UINT32 EBX;
5275 UINT32 EDX;
5276 UINT32 ECX;
5277 UINT32 EAX;
5278 UINT16 DS;
5279 UINT16 ES;
5280 UINT16 FS;
5281 UINT16 GS;
5282 IA32_EFLAGS32 EFLAGS;
5283 UINT32 Eip;
5284 UINT16 CS;
5285 UINT16 SS;
5286 } IA32_DWORD_REGS;
5287
5288 typedef union {
5289 IA32_DWORD_REGS E;
5290 IA32_WORD_REGS X;
5291 IA32_BYTE_REGS H;
5292 } IA32_REGISTER_SET;
5293
5294 ///
5295 /// Byte packed structure for an 16-bit real mode thunks.
5296 ///
5297 typedef struct {
5298 IA32_REGISTER_SET *RealModeState;
5299 VOID *RealModeBuffer;
5300 UINT32 RealModeBufferSize;
5301 UINT32 ThunkAttributes;
5302 } THUNK_CONTEXT;
5303
5304 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
5305 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
5306 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
5307
5308 ///
5309 /// Type definition for representing labels in NASM source code that allow for
5310 /// the patching of immediate operands of IA32 and X64 instructions.
5311 ///
5312 /// While the type is technically defined as a function type (note: not a
5313 /// pointer-to-function type), such labels in NASM source code never stand for
5314 /// actual functions, and identifiers declared with this function type should
5315 /// never be called. This is also why the EFIAPI calling convention specifier
5316 /// is missing from the typedef, and why the typedef does not follow the usual
5317 /// edk2 coding style for function (or pointer-to-function) typedefs. The VOID
5318 /// return type and the VOID argument list are merely artifacts.
5319 ///
5320 typedef VOID (X86_ASSEMBLY_PATCH_LABEL) (
5321 VOID
5322 );
5323
5324 /**
5325 Retrieves CPUID information.
5326
5327 Executes the CPUID instruction with EAX set to the value specified by Index.
5328 This function always returns Index.
5329 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5330 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5331 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5332 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5333 This function is only available on IA-32 and x64.
5334
5335 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
5336 instruction.
5337 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
5338 instruction. This is an optional parameter that may be NULL.
5339 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
5340 instruction. This is an optional parameter that may be NULL.
5341 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
5342 instruction. This is an optional parameter that may be NULL.
5343 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
5344 instruction. This is an optional parameter that may be NULL.
5345
5346 @return Index.
5347
5348 **/
5349 UINT32
5350 EFIAPI
5351 AsmCpuid (
5352 IN UINT32 Index,
5353 OUT UINT32 *Eax OPTIONAL,
5354 OUT UINT32 *Ebx OPTIONAL,
5355 OUT UINT32 *Ecx OPTIONAL,
5356 OUT UINT32 *Edx OPTIONAL
5357 );
5358
5359 /**
5360 Retrieves CPUID information using an extended leaf identifier.
5361
5362 Executes the CPUID instruction with EAX set to the value specified by Index
5363 and ECX set to the value specified by SubIndex. This function always returns
5364 Index. This function is only available on IA-32 and x64.
5365
5366 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5367 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5368 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5369 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5370
5371 @param Index The 32-bit value to load into EAX prior to invoking the
5372 CPUID instruction.
5373 @param SubIndex The 32-bit value to load into ECX prior to invoking the
5374 CPUID instruction.
5375 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
5376 instruction. This is an optional parameter that may be
5377 NULL.
5378 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
5379 instruction. This is an optional parameter that may be
5380 NULL.
5381 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
5382 instruction. This is an optional parameter that may be
5383 NULL.
5384 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
5385 instruction. This is an optional parameter that may be
5386 NULL.
5387
5388 @return Index.
5389
5390 **/
5391 UINT32
5392 EFIAPI
5393 AsmCpuidEx (
5394 IN UINT32 Index,
5395 IN UINT32 SubIndex,
5396 OUT UINT32 *Eax OPTIONAL,
5397 OUT UINT32 *Ebx OPTIONAL,
5398 OUT UINT32 *Ecx OPTIONAL,
5399 OUT UINT32 *Edx OPTIONAL
5400 );
5401
5402 /**
5403 Set CD bit and clear NW bit of CR0 followed by a WBINVD.
5404
5405 Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,
5406 and executing a WBINVD instruction. This function is only available on IA-32 and x64.
5407
5408 **/
5409 VOID
5410 EFIAPI
5411 AsmDisableCache (
5412 VOID
5413 );
5414
5415 /**
5416 Perform a WBINVD and clear both the CD and NW bits of CR0.
5417
5418 Enables the caches by executing a WBINVD instruction and then clear both the CD and NW
5419 bits of CR0 to 0. This function is only available on IA-32 and x64.
5420
5421 **/
5422 VOID
5423 EFIAPI
5424 AsmEnableCache (
5425 VOID
5426 );
5427
5428 /**
5429 Returns the lower 32-bits of a Machine Specific Register(MSR).
5430
5431 Reads and returns the lower 32-bits of the MSR specified by Index.
5432 No parameter checking is performed on Index, and some Index values may cause
5433 CPU exceptions. The caller must either guarantee that Index is valid, or the
5434 caller must set up exception handlers to catch the exceptions. This function
5435 is only available on IA-32 and x64.
5436
5437 @param Index The 32-bit MSR index to read.
5438
5439 @return The lower 32 bits of the MSR identified by Index.
5440
5441 **/
5442 UINT32
5443 EFIAPI
5444 AsmReadMsr32 (
5445 IN UINT32 Index
5446 );
5447
5448 /**
5449 Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.
5450 The upper 32-bits of the MSR are set to zero.
5451
5452 Writes the 32-bit value specified by Value to the MSR specified by Index. The
5453 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
5454 the MSR is returned. No parameter checking is performed on Index or Value,
5455 and some of these may cause CPU exceptions. The caller must either guarantee
5456 that Index and Value are valid, or the caller must establish proper exception
5457 handlers. This function is only available on IA-32 and x64.
5458
5459 @param Index The 32-bit MSR index to write.
5460 @param Value The 32-bit value to write to the MSR.
5461
5462 @return Value
5463
5464 **/
5465 UINT32
5466 EFIAPI
5467 AsmWriteMsr32 (
5468 IN UINT32 Index,
5469 IN UINT32 Value
5470 );
5471
5472 /**
5473 Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and
5474 writes the result back to the 64-bit MSR.
5475
5476 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5477 between the lower 32-bits of the read result and the value specified by
5478 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
5479 32-bits of the value written to the MSR is returned. No parameter checking is
5480 performed on Index or OrData, and some of these may cause CPU exceptions. The
5481 caller must either guarantee that Index and OrData are valid, or the caller
5482 must establish proper exception handlers. This function is only available on
5483 IA-32 and x64.
5484
5485 @param Index The 32-bit MSR index to write.
5486 @param OrData The value to OR with the read value from the MSR.
5487
5488 @return The lower 32-bit value written to the MSR.
5489
5490 **/
5491 UINT32
5492 EFIAPI
5493 AsmMsrOr32 (
5494 IN UINT32 Index,
5495 IN UINT32 OrData
5496 );
5497
5498 /**
5499 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
5500 the result back to the 64-bit MSR.
5501
5502 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5503 lower 32-bits of the read result and the value specified by AndData, and
5504 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
5505 the value written to the MSR is returned. No parameter checking is performed
5506 on Index or AndData, and some of these may cause CPU exceptions. The caller
5507 must either guarantee that Index and AndData are valid, or the caller must
5508 establish proper exception handlers. This function is only available on IA-32
5509 and x64.
5510
5511 @param Index The 32-bit MSR index to write.
5512 @param AndData The value to AND with the read value from the MSR.
5513
5514 @return The lower 32-bit value written to the MSR.
5515
5516 **/
5517 UINT32
5518 EFIAPI
5519 AsmMsrAnd32 (
5520 IN UINT32 Index,
5521 IN UINT32 AndData
5522 );
5523
5524 /**
5525 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR
5526 on the lower 32-bits, and writes the result back to the 64-bit MSR.
5527
5528 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5529 lower 32-bits of the read result and the value specified by AndData
5530 preserving the upper 32-bits, performs a bitwise OR between the
5531 result of the AND operation and the value specified by OrData, and writes the
5532 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
5533 written to the MSR is returned. No parameter checking is performed on Index,
5534 AndData, or OrData, and some of these may cause CPU exceptions. The caller
5535 must either guarantee that Index, AndData, and OrData are valid, or the
5536 caller must establish proper exception handlers. This function is only
5537 available on IA-32 and x64.
5538
5539 @param Index The 32-bit MSR index to write.
5540 @param AndData The value to AND with the read value from the MSR.
5541 @param OrData The value to OR with the result of the AND operation.
5542
5543 @return The lower 32-bit value written to the MSR.
5544
5545 **/
5546 UINT32
5547 EFIAPI
5548 AsmMsrAndThenOr32 (
5549 IN UINT32 Index,
5550 IN UINT32 AndData,
5551 IN UINT32 OrData
5552 );
5553
5554 /**
5555 Reads a bit field of an MSR.
5556
5557 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
5558 specified by the StartBit and the EndBit. The value of the bit field is
5559 returned. The caller must either guarantee that Index is valid, or the caller
5560 must set up exception handlers to catch the exceptions. This function is only
5561 available on IA-32 and x64.
5562
5563 If StartBit is greater than 31, then ASSERT().
5564 If EndBit is greater than 31, then ASSERT().
5565 If EndBit is less than StartBit, then ASSERT().
5566
5567 @param Index The 32-bit MSR index to read.
5568 @param StartBit The ordinal of the least significant bit in the bit field.
5569 Range 0..31.
5570 @param EndBit The ordinal of the most significant bit in the bit field.
5571 Range 0..31.
5572
5573 @return The bit field read from the MSR.
5574
5575 **/
5576 UINT32
5577 EFIAPI
5578 AsmMsrBitFieldRead32 (
5579 IN UINT32 Index,
5580 IN UINTN StartBit,
5581 IN UINTN EndBit
5582 );
5583
5584 /**
5585 Writes a bit field to an MSR.
5586
5587 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
5588 field is specified by the StartBit and the EndBit. All other bits in the
5589 destination MSR are preserved. The lower 32-bits of the MSR written is
5590 returned. The caller must either guarantee that Index and the data written
5591 is valid, or the caller must set up exception handlers to catch the exceptions.
5592 This function is only available on IA-32 and x64.
5593
5594 If StartBit is greater than 31, then ASSERT().
5595 If EndBit is greater than 31, then ASSERT().
5596 If EndBit is less than StartBit, then ASSERT().
5597 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5598
5599 @param Index The 32-bit MSR index to write.
5600 @param StartBit The ordinal of the least significant bit in the bit field.
5601 Range 0..31.
5602 @param EndBit The ordinal of the most significant bit in the bit field.
5603 Range 0..31.
5604 @param Value New value of the bit field.
5605
5606 @return The lower 32-bit of the value written to the MSR.
5607
5608 **/
5609 UINT32
5610 EFIAPI
5611 AsmMsrBitFieldWrite32 (
5612 IN UINT32 Index,
5613 IN UINTN StartBit,
5614 IN UINTN EndBit,
5615 IN UINT32 Value
5616 );
5617
5618 /**
5619 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
5620 result back to the bit field in the 64-bit MSR.
5621
5622 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5623 between the read result and the value specified by OrData, and writes the
5624 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
5625 written to the MSR are returned. Extra left bits in OrData are stripped. The
5626 caller must either guarantee that Index and the data written is valid, or
5627 the caller must set up exception handlers to catch the exceptions. This
5628 function is only available on IA-32 and x64.
5629
5630 If StartBit is greater than 31, then ASSERT().
5631 If EndBit is greater than 31, then ASSERT().
5632 If EndBit is less than StartBit, then ASSERT().
5633 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5634
5635 @param Index The 32-bit MSR index to write.
5636 @param StartBit The ordinal of the least significant bit in the bit field.
5637 Range 0..31.
5638 @param EndBit The ordinal of the most significant bit in the bit field.
5639 Range 0..31.
5640 @param OrData The value to OR with the read value from the MSR.
5641
5642 @return The lower 32-bit of the value written to the MSR.
5643
5644 **/
5645 UINT32
5646 EFIAPI
5647 AsmMsrBitFieldOr32 (
5648 IN UINT32 Index,
5649 IN UINTN StartBit,
5650 IN UINTN EndBit,
5651 IN UINT32 OrData
5652 );
5653
5654 /**
5655 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5656 result back to the bit field in the 64-bit MSR.
5657
5658 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5659 read result and the value specified by AndData, and writes the result to the
5660 64-bit MSR specified by Index. The lower 32-bits of the value written to the
5661 MSR are returned. Extra left bits in AndData are stripped. The caller must
5662 either guarantee that Index and the data written is valid, or the caller must
5663 set up exception handlers to catch the exceptions. This function is only
5664 available on IA-32 and x64.
5665
5666 If StartBit is greater than 31, then ASSERT().
5667 If EndBit is greater than 31, then ASSERT().
5668 If EndBit is less than StartBit, then ASSERT().
5669 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5670
5671 @param Index The 32-bit MSR index to write.
5672 @param StartBit The ordinal of the least significant bit in the bit field.
5673 Range 0..31.
5674 @param EndBit The ordinal of the most significant bit in the bit field.
5675 Range 0..31.
5676 @param AndData The value to AND with the read value from the MSR.
5677
5678 @return The lower 32-bit of the value written to the MSR.
5679
5680 **/
5681 UINT32
5682 EFIAPI
5683 AsmMsrBitFieldAnd32 (
5684 IN UINT32 Index,
5685 IN UINTN StartBit,
5686 IN UINTN EndBit,
5687 IN UINT32 AndData
5688 );
5689
5690 /**
5691 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5692 bitwise OR, and writes the result back to the bit field in the
5693 64-bit MSR.
5694
5695 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
5696 bitwise OR between the read result and the value specified by
5697 AndData, and writes the result to the 64-bit MSR specified by Index. The
5698 lower 32-bits of the value written to the MSR are returned. Extra left bits
5699 in both AndData and OrData are stripped. The caller must either guarantee
5700 that Index and the data written is valid, or the caller must set up exception
5701 handlers to catch the exceptions. This function is only available on IA-32
5702 and x64.
5703
5704 If StartBit is greater than 31, then ASSERT().
5705 If EndBit is greater than 31, then ASSERT().
5706 If EndBit is less than StartBit, then ASSERT().
5707 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5708 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5709
5710 @param Index The 32-bit MSR index to write.
5711 @param StartBit The ordinal of the least significant bit in the bit field.
5712 Range 0..31.
5713 @param EndBit The ordinal of the most significant bit in the bit field.
5714 Range 0..31.
5715 @param AndData The value to AND with the read value from the MSR.
5716 @param OrData The value to OR with the result of the AND operation.
5717
5718 @return The lower 32-bit of the value written to the MSR.
5719
5720 **/
5721 UINT32
5722 EFIAPI
5723 AsmMsrBitFieldAndThenOr32 (
5724 IN UINT32 Index,
5725 IN UINTN StartBit,
5726 IN UINTN EndBit,
5727 IN UINT32 AndData,
5728 IN UINT32 OrData
5729 );
5730
5731 /**
5732 Returns a 64-bit Machine Specific Register(MSR).
5733
5734 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
5735 performed on Index, and some Index values may cause CPU exceptions. The
5736 caller must either guarantee that Index is valid, or the caller must set up
5737 exception handlers to catch the exceptions. This function is only available
5738 on IA-32 and x64.
5739
5740 @param Index The 32-bit MSR index to read.
5741
5742 @return The value of the MSR identified by Index.
5743
5744 **/
5745 UINT64
5746 EFIAPI
5747 AsmReadMsr64 (
5748 IN UINT32 Index
5749 );
5750
5751 /**
5752 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
5753 value.
5754
5755 Writes the 64-bit value specified by Value to the MSR specified by Index. The
5756 64-bit value written to the MSR is returned. No parameter checking is
5757 performed on Index or Value, and some of these may cause CPU exceptions. The
5758 caller must either guarantee that Index and Value are valid, or the caller
5759 must establish proper exception handlers. This function is only available on
5760 IA-32 and x64.
5761
5762 @param Index The 32-bit MSR index to write.
5763 @param Value The 64-bit value to write to the MSR.
5764
5765 @return Value
5766
5767 **/
5768 UINT64
5769 EFIAPI
5770 AsmWriteMsr64 (
5771 IN UINT32 Index,
5772 IN UINT64 Value
5773 );
5774
5775 /**
5776 Reads a 64-bit MSR, performs a bitwise OR, and writes the result
5777 back to the 64-bit MSR.
5778
5779 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5780 between the read result and the value specified by OrData, and writes the
5781 result to the 64-bit MSR specified by Index. The value written to the MSR is
5782 returned. No parameter checking is performed on Index or OrData, and some of
5783 these may cause CPU exceptions. The caller must either guarantee that Index
5784 and OrData are valid, or the caller must establish proper exception handlers.
5785 This function is only available on IA-32 and x64.
5786
5787 @param Index The 32-bit MSR index to write.
5788 @param OrData The value to OR with the read value from the MSR.
5789
5790 @return The value written back to the MSR.
5791
5792 **/
5793 UINT64
5794 EFIAPI
5795 AsmMsrOr64 (
5796 IN UINT32 Index,
5797 IN UINT64 OrData
5798 );
5799
5800 /**
5801 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
5802 64-bit MSR.
5803
5804 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5805 read result and the value specified by OrData, and writes the result to the
5806 64-bit MSR specified by Index. The value written to the MSR is returned. No
5807 parameter checking is performed on Index or OrData, and some of these may
5808 cause CPU exceptions. The caller must either guarantee that Index and OrData
5809 are valid, or the caller must establish proper exception handlers. This
5810 function is only available on IA-32 and x64.
5811
5812 @param Index The 32-bit MSR index to write.
5813 @param AndData The value to AND with the read value from the MSR.
5814
5815 @return The value written back to the MSR.
5816
5817 **/
5818 UINT64
5819 EFIAPI
5820 AsmMsrAnd64 (
5821 IN UINT32 Index,
5822 IN UINT64 AndData
5823 );
5824
5825 /**
5826 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise
5827 OR, and writes the result back to the 64-bit MSR.
5828
5829 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
5830 result and the value specified by AndData, performs a bitwise OR
5831 between the result of the AND operation and the value specified by OrData,
5832 and writes the result to the 64-bit MSR specified by Index. The value written
5833 to the MSR is returned. No parameter checking is performed on Index, AndData,
5834 or OrData, and some of these may cause CPU exceptions. The caller must either
5835 guarantee that Index, AndData, and OrData are valid, or the caller must
5836 establish proper exception handlers. This function is only available on IA-32
5837 and x64.
5838
5839 @param Index The 32-bit MSR index to write.
5840 @param AndData The value to AND with the read value from the MSR.
5841 @param OrData The value to OR with the result of the AND operation.
5842
5843 @return The value written back to the MSR.
5844
5845 **/
5846 UINT64
5847 EFIAPI
5848 AsmMsrAndThenOr64 (
5849 IN UINT32 Index,
5850 IN UINT64 AndData,
5851 IN UINT64 OrData
5852 );
5853
5854 /**
5855 Reads a bit field of an MSR.
5856
5857 Reads the bit field in the 64-bit MSR. The bit field is specified by the
5858 StartBit and the EndBit. The value of the bit field is returned. The caller
5859 must either guarantee that Index is valid, or the caller must set up
5860 exception handlers to catch the exceptions. This function is only available
5861 on IA-32 and x64.
5862
5863 If StartBit is greater than 63, then ASSERT().
5864 If EndBit is greater than 63, then ASSERT().
5865 If EndBit is less than StartBit, then ASSERT().
5866
5867 @param Index The 32-bit MSR index to read.
5868 @param StartBit The ordinal of the least significant bit in the bit field.
5869 Range 0..63.
5870 @param EndBit The ordinal of the most significant bit in the bit field.
5871 Range 0..63.
5872
5873 @return The value read from the MSR.
5874
5875 **/
5876 UINT64
5877 EFIAPI
5878 AsmMsrBitFieldRead64 (
5879 IN UINT32 Index,
5880 IN UINTN StartBit,
5881 IN UINTN EndBit
5882 );
5883
5884 /**
5885 Writes a bit field to an MSR.
5886
5887 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
5888 the StartBit and the EndBit. All other bits in the destination MSR are
5889 preserved. The MSR written is returned. The caller must either guarantee
5890 that Index and the data written is valid, or the caller must set up exception
5891 handlers to catch the exceptions. This function is only available on IA-32 and x64.
5892
5893 If StartBit is greater than 63, then ASSERT().
5894 If EndBit is greater than 63, then ASSERT().
5895 If EndBit is less than StartBit, then ASSERT().
5896 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5897
5898 @param Index The 32-bit MSR index to write.
5899 @param StartBit The ordinal of the least significant bit in the bit field.
5900 Range 0..63.
5901 @param EndBit The ordinal of the most significant bit in the bit field.
5902 Range 0..63.
5903 @param Value New value of the bit field.
5904
5905 @return The value written back to the MSR.
5906
5907 **/
5908 UINT64
5909 EFIAPI
5910 AsmMsrBitFieldWrite64 (
5911 IN UINT32 Index,
5912 IN UINTN StartBit,
5913 IN UINTN EndBit,
5914 IN UINT64 Value
5915 );
5916
5917 /**
5918 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and
5919 writes the result back to the bit field in the 64-bit MSR.
5920
5921 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5922 between the read result and the value specified by OrData, and writes the
5923 result to the 64-bit MSR specified by Index. The value written to the MSR is
5924 returned. Extra left bits in OrData are stripped. The caller must either
5925 guarantee that Index and the data written is valid, or the caller must set up
5926 exception handlers to catch the exceptions. This function is only available
5927 on IA-32 and x64.
5928
5929 If StartBit is greater than 63, then ASSERT().
5930 If EndBit is greater than 63, then ASSERT().
5931 If EndBit is less than StartBit, then ASSERT().
5932 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5933
5934 @param Index The 32-bit MSR index to write.
5935 @param StartBit The ordinal of the least significant bit in the bit field.
5936 Range 0..63.
5937 @param EndBit The ordinal of the most significant bit in the bit field.
5938 Range 0..63.
5939 @param OrData The value to OR with the read value from the bit field.
5940
5941 @return The value written back to the MSR.
5942
5943 **/
5944 UINT64
5945 EFIAPI
5946 AsmMsrBitFieldOr64 (
5947 IN UINT32 Index,
5948 IN UINTN StartBit,
5949 IN UINTN EndBit,
5950 IN UINT64 OrData
5951 );
5952
5953 /**
5954 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5955 result back to the bit field in the 64-bit MSR.
5956
5957 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5958 read result and the value specified by AndData, and writes the result to the
5959 64-bit MSR specified by Index. The value written to the MSR is returned.
5960 Extra left bits in AndData are stripped. The caller must either guarantee
5961 that Index and the data written is valid, or the caller must set up exception
5962 handlers to catch the exceptions. This function is only available on IA-32
5963 and x64.
5964
5965 If StartBit is greater than 63, then ASSERT().
5966 If EndBit is greater than 63, then ASSERT().
5967 If EndBit is less than StartBit, then ASSERT().
5968 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5969
5970 @param Index The 32-bit MSR index to write.
5971 @param StartBit The ordinal of the least significant bit in the bit field.
5972 Range 0..63.
5973 @param EndBit The ordinal of the most significant bit in the bit field.
5974 Range 0..63.
5975 @param AndData The value to AND with the read value from the bit field.
5976
5977 @return The value written back to the MSR.
5978
5979 **/
5980 UINT64
5981 EFIAPI
5982 AsmMsrBitFieldAnd64 (
5983 IN UINT32 Index,
5984 IN UINTN StartBit,
5985 IN UINTN EndBit,
5986 IN UINT64 AndData
5987 );
5988
5989 /**
5990 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5991 bitwise OR, and writes the result back to the bit field in the
5992 64-bit MSR.
5993
5994 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
5995 a bitwise OR between the read result and the value specified by
5996 AndData, and writes the result to the 64-bit MSR specified by Index. The
5997 value written to the MSR is returned. Extra left bits in both AndData and
5998 OrData are stripped. The caller must either guarantee that Index and the data
5999 written is valid, or the caller must set up exception handlers to catch the
6000 exceptions. This function is only available on IA-32 and x64.
6001
6002 If StartBit is greater than 63, then ASSERT().
6003 If EndBit is greater than 63, then ASSERT().
6004 If EndBit is less than StartBit, then ASSERT().
6005 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
6006 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
6007
6008 @param Index The 32-bit MSR index to write.
6009 @param StartBit The ordinal of the least significant bit in the bit field.
6010 Range 0..63.
6011 @param EndBit The ordinal of the most significant bit in the bit field.
6012 Range 0..63.
6013 @param AndData The value to AND with the read value from the bit field.
6014 @param OrData The value to OR with the result of the AND operation.
6015
6016 @return The value written back to the MSR.
6017
6018 **/
6019 UINT64
6020 EFIAPI
6021 AsmMsrBitFieldAndThenOr64 (
6022 IN UINT32 Index,
6023 IN UINTN StartBit,
6024 IN UINTN EndBit,
6025 IN UINT64 AndData,
6026 IN UINT64 OrData
6027 );
6028
6029 /**
6030 Reads the current value of the EFLAGS register.
6031
6032 Reads and returns the current value of the EFLAGS register. This function is
6033 only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a
6034 64-bit value on x64.
6035
6036 @return EFLAGS on IA-32 or RFLAGS on x64.
6037
6038 **/
6039 UINTN
6040 EFIAPI
6041 AsmReadEflags (
6042 VOID
6043 );
6044
6045 /**
6046 Reads the current value of the Control Register 0 (CR0).
6047
6048 Reads and returns the current value of CR0. This function is only available
6049 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6050 x64.
6051
6052 @return The value of the Control Register 0 (CR0).
6053
6054 **/
6055 UINTN
6056 EFIAPI
6057 AsmReadCr0 (
6058 VOID
6059 );
6060
6061 /**
6062 Reads the current value of the Control Register 2 (CR2).
6063
6064 Reads and returns the current value of CR2. This function is only available
6065 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6066 x64.
6067
6068 @return The value of the Control Register 2 (CR2).
6069
6070 **/
6071 UINTN
6072 EFIAPI
6073 AsmReadCr2 (
6074 VOID
6075 );
6076
6077 /**
6078 Reads the current value of the Control Register 3 (CR3).
6079
6080 Reads and returns the current value of CR3. This function is only available
6081 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6082 x64.
6083
6084 @return The value of the Control Register 3 (CR3).
6085
6086 **/
6087 UINTN
6088 EFIAPI
6089 AsmReadCr3 (
6090 VOID
6091 );
6092
6093 /**
6094 Reads the current value of the Control Register 4 (CR4).
6095
6096 Reads and returns the current value of CR4. This function is only available
6097 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6098 x64.
6099
6100 @return The value of the Control Register 4 (CR4).
6101
6102 **/
6103 UINTN
6104 EFIAPI
6105 AsmReadCr4 (
6106 VOID
6107 );
6108
6109 /**
6110 Writes a value to Control Register 0 (CR0).
6111
6112 Writes and returns a new value to CR0. This function is only available on
6113 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6114
6115 @param Cr0 The value to write to CR0.
6116
6117 @return The value written to CR0.
6118
6119 **/
6120 UINTN
6121 EFIAPI
6122 AsmWriteCr0 (
6123 UINTN Cr0
6124 );
6125
6126 /**
6127 Writes a value to Control Register 2 (CR2).
6128
6129 Writes and returns a new value to CR2. This function is only available on
6130 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6131
6132 @param Cr2 The value to write to CR2.
6133
6134 @return The value written to CR2.
6135
6136 **/
6137 UINTN
6138 EFIAPI
6139 AsmWriteCr2 (
6140 UINTN Cr2
6141 );
6142
6143 /**
6144 Writes a value to Control Register 3 (CR3).
6145
6146 Writes and returns a new value to CR3. This function is only available on
6147 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6148
6149 @param Cr3 The value to write to CR3.
6150
6151 @return The value written to CR3.
6152
6153 **/
6154 UINTN
6155 EFIAPI
6156 AsmWriteCr3 (
6157 UINTN Cr3
6158 );
6159
6160 /**
6161 Writes a value to Control Register 4 (CR4).
6162
6163 Writes and returns a new value to CR4. This function is only available on
6164 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6165
6166 @param Cr4 The value to write to CR4.
6167
6168 @return The value written to CR4.
6169
6170 **/
6171 UINTN
6172 EFIAPI
6173 AsmWriteCr4 (
6174 UINTN Cr4
6175 );
6176
6177 /**
6178 Reads the current value of Debug Register 0 (DR0).
6179
6180 Reads and returns the current value of DR0. This function is only available
6181 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6182 x64.
6183
6184 @return The value of Debug Register 0 (DR0).
6185
6186 **/
6187 UINTN
6188 EFIAPI
6189 AsmReadDr0 (
6190 VOID
6191 );
6192
6193 /**
6194 Reads the current value of Debug Register 1 (DR1).
6195
6196 Reads and returns the current value of DR1. This function is only available
6197 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6198 x64.
6199
6200 @return The value of Debug Register 1 (DR1).
6201
6202 **/
6203 UINTN
6204 EFIAPI
6205 AsmReadDr1 (
6206 VOID
6207 );
6208
6209 /**
6210 Reads the current value of Debug Register 2 (DR2).
6211
6212 Reads and returns the current value of DR2. This function is only available
6213 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6214 x64.
6215
6216 @return The value of Debug Register 2 (DR2).
6217
6218 **/
6219 UINTN
6220 EFIAPI
6221 AsmReadDr2 (
6222 VOID
6223 );
6224
6225 /**
6226 Reads the current value of Debug Register 3 (DR3).
6227
6228 Reads and returns the current value of DR3. This function is only available
6229 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6230 x64.
6231
6232 @return The value of Debug Register 3 (DR3).
6233
6234 **/
6235 UINTN
6236 EFIAPI
6237 AsmReadDr3 (
6238 VOID
6239 );
6240
6241 /**
6242 Reads the current value of Debug Register 4 (DR4).
6243
6244 Reads and returns the current value of DR4. This function is only available
6245 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6246 x64.
6247
6248 @return The value of Debug Register 4 (DR4).
6249
6250 **/
6251 UINTN
6252 EFIAPI
6253 AsmReadDr4 (
6254 VOID
6255 );
6256
6257 /**
6258 Reads the current value of Debug Register 5 (DR5).
6259
6260 Reads and returns the current value of DR5. This function is only available
6261 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6262 x64.
6263
6264 @return The value of Debug Register 5 (DR5).
6265
6266 **/
6267 UINTN
6268 EFIAPI
6269 AsmReadDr5 (
6270 VOID
6271 );
6272
6273 /**
6274 Reads the current value of Debug Register 6 (DR6).
6275
6276 Reads and returns the current value of DR6. This function is only available
6277 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6278 x64.
6279
6280 @return The value of Debug Register 6 (DR6).
6281
6282 **/
6283 UINTN
6284 EFIAPI
6285 AsmReadDr6 (
6286 VOID
6287 );
6288
6289 /**
6290 Reads the current value of Debug Register 7 (DR7).
6291
6292 Reads and returns the current value of DR7. This function is only available
6293 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6294 x64.
6295
6296 @return The value of Debug Register 7 (DR7).
6297
6298 **/
6299 UINTN
6300 EFIAPI
6301 AsmReadDr7 (
6302 VOID
6303 );
6304
6305 /**
6306 Writes a value to Debug Register 0 (DR0).
6307
6308 Writes and returns a new value to DR0. This function is only available on
6309 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6310
6311 @param Dr0 The value to write to Dr0.
6312
6313 @return The value written to Debug Register 0 (DR0).
6314
6315 **/
6316 UINTN
6317 EFIAPI
6318 AsmWriteDr0 (
6319 UINTN Dr0
6320 );
6321
6322 /**
6323 Writes a value to Debug Register 1 (DR1).
6324
6325 Writes and returns a new value to DR1. This function is only available on
6326 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6327
6328 @param Dr1 The value to write to Dr1.
6329
6330 @return The value written to Debug Register 1 (DR1).
6331
6332 **/
6333 UINTN
6334 EFIAPI
6335 AsmWriteDr1 (
6336 UINTN Dr1
6337 );
6338
6339 /**
6340 Writes a value to Debug Register 2 (DR2).
6341
6342 Writes and returns a new value to DR2. This function is only available on
6343 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6344
6345 @param Dr2 The value to write to Dr2.
6346
6347 @return The value written to Debug Register 2 (DR2).
6348
6349 **/
6350 UINTN
6351 EFIAPI
6352 AsmWriteDr2 (
6353 UINTN Dr2
6354 );
6355
6356 /**
6357 Writes a value to Debug Register 3 (DR3).
6358
6359 Writes and returns a new value to DR3. This function is only available on
6360 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6361
6362 @param Dr3 The value to write to Dr3.
6363
6364 @return The value written to Debug Register 3 (DR3).
6365
6366 **/
6367 UINTN
6368 EFIAPI
6369 AsmWriteDr3 (
6370 UINTN Dr3
6371 );
6372
6373 /**
6374 Writes a value to Debug Register 4 (DR4).
6375
6376 Writes and returns a new value to DR4. This function is only available on
6377 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6378
6379 @param Dr4 The value to write to Dr4.
6380
6381 @return The value written to Debug Register 4 (DR4).
6382
6383 **/
6384 UINTN
6385 EFIAPI
6386 AsmWriteDr4 (
6387 UINTN Dr4
6388 );
6389
6390 /**
6391 Writes a value to Debug Register 5 (DR5).
6392
6393 Writes and returns a new value to DR5. This function is only available on
6394 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6395
6396 @param Dr5 The value to write to Dr5.
6397
6398 @return The value written to Debug Register 5 (DR5).
6399
6400 **/
6401 UINTN
6402 EFIAPI
6403 AsmWriteDr5 (
6404 UINTN Dr5
6405 );
6406
6407 /**
6408 Writes a value to Debug Register 6 (DR6).
6409
6410 Writes and returns a new value to DR6. This function is only available on
6411 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6412
6413 @param Dr6 The value to write to Dr6.
6414
6415 @return The value written to Debug Register 6 (DR6).
6416
6417 **/
6418 UINTN
6419 EFIAPI
6420 AsmWriteDr6 (
6421 UINTN Dr6
6422 );
6423
6424 /**
6425 Writes a value to Debug Register 7 (DR7).
6426
6427 Writes and returns a new value to DR7. This function is only available on
6428 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6429
6430 @param Dr7 The value to write to Dr7.
6431
6432 @return The value written to Debug Register 7 (DR7).
6433
6434 **/
6435 UINTN
6436 EFIAPI
6437 AsmWriteDr7 (
6438 UINTN Dr7
6439 );
6440
6441 /**
6442 Reads the current value of Code Segment Register (CS).
6443
6444 Reads and returns the current value of CS. This function is only available on
6445 IA-32 and x64.
6446
6447 @return The current value of CS.
6448
6449 **/
6450 UINT16
6451 EFIAPI
6452 AsmReadCs (
6453 VOID
6454 );
6455
6456 /**
6457 Reads the current value of Data Segment Register (DS).
6458
6459 Reads and returns the current value of DS. This function is only available on
6460 IA-32 and x64.
6461
6462 @return The current value of DS.
6463
6464 **/
6465 UINT16
6466 EFIAPI
6467 AsmReadDs (
6468 VOID
6469 );
6470
6471 /**
6472 Reads the current value of Extra Segment Register (ES).
6473
6474 Reads and returns the current value of ES. This function is only available on
6475 IA-32 and x64.
6476
6477 @return The current value of ES.
6478
6479 **/
6480 UINT16
6481 EFIAPI
6482 AsmReadEs (
6483 VOID
6484 );
6485
6486 /**
6487 Reads the current value of FS Data Segment Register (FS).
6488
6489 Reads and returns the current value of FS. This function is only available on
6490 IA-32 and x64.
6491
6492 @return The current value of FS.
6493
6494 **/
6495 UINT16
6496 EFIAPI
6497 AsmReadFs (
6498 VOID
6499 );
6500
6501 /**
6502 Reads the current value of GS Data Segment Register (GS).
6503
6504 Reads and returns the current value of GS. This function is only available on
6505 IA-32 and x64.
6506
6507 @return The current value of GS.
6508
6509 **/
6510 UINT16
6511 EFIAPI
6512 AsmReadGs (
6513 VOID
6514 );
6515
6516 /**
6517 Reads the current value of Stack Segment Register (SS).
6518
6519 Reads and returns the current value of SS. This function is only available on
6520 IA-32 and x64.
6521
6522 @return The current value of SS.
6523
6524 **/
6525 UINT16
6526 EFIAPI
6527 AsmReadSs (
6528 VOID
6529 );
6530
6531 /**
6532 Reads the current value of Task Register (TR).
6533
6534 Reads and returns the current value of TR. This function is only available on
6535 IA-32 and x64.
6536
6537 @return The current value of TR.
6538
6539 **/
6540 UINT16
6541 EFIAPI
6542 AsmReadTr (
6543 VOID
6544 );
6545
6546 /**
6547 Reads the current Global Descriptor Table Register(GDTR) descriptor.
6548
6549 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
6550 function is only available on IA-32 and x64.
6551
6552 If Gdtr is NULL, then ASSERT().
6553
6554 @param Gdtr The pointer to a GDTR descriptor.
6555
6556 **/
6557 VOID
6558 EFIAPI
6559 AsmReadGdtr (
6560 OUT IA32_DESCRIPTOR *Gdtr
6561 );
6562
6563 /**
6564 Writes the current Global Descriptor Table Register (GDTR) descriptor.
6565
6566 Writes and the current GDTR descriptor specified by Gdtr. This function is
6567 only available on IA-32 and x64.
6568
6569 If Gdtr is NULL, then ASSERT().
6570
6571 @param Gdtr The pointer to a GDTR descriptor.
6572
6573 **/
6574 VOID
6575 EFIAPI
6576 AsmWriteGdtr (
6577 IN CONST IA32_DESCRIPTOR *Gdtr
6578 );
6579
6580 /**
6581 Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.
6582
6583 Reads and returns the current IDTR descriptor and returns it in Idtr. This
6584 function is only available on IA-32 and x64.
6585
6586 If Idtr is NULL, then ASSERT().
6587
6588 @param Idtr The pointer to a IDTR descriptor.
6589
6590 **/
6591 VOID
6592 EFIAPI
6593 AsmReadIdtr (
6594 OUT IA32_DESCRIPTOR *Idtr
6595 );
6596
6597 /**
6598 Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.
6599
6600 Writes the current IDTR descriptor and returns it in Idtr. This function is
6601 only available on IA-32 and x64.
6602
6603 If Idtr is NULL, then ASSERT().
6604
6605 @param Idtr The pointer to a IDTR descriptor.
6606
6607 **/
6608 VOID
6609 EFIAPI
6610 AsmWriteIdtr (
6611 IN CONST IA32_DESCRIPTOR *Idtr
6612 );
6613
6614 /**
6615 Reads the current Local Descriptor Table Register(LDTR) selector.
6616
6617 Reads and returns the current 16-bit LDTR descriptor value. This function is
6618 only available on IA-32 and x64.
6619
6620 @return The current selector of LDT.
6621
6622 **/
6623 UINT16
6624 EFIAPI
6625 AsmReadLdtr (
6626 VOID
6627 );
6628
6629 /**
6630 Writes the current Local Descriptor Table Register (LDTR) selector.
6631
6632 Writes and the current LDTR descriptor specified by Ldtr. This function is
6633 only available on IA-32 and x64.
6634
6635 @param Ldtr 16-bit LDTR selector value.
6636
6637 **/
6638 VOID
6639 EFIAPI
6640 AsmWriteLdtr (
6641 IN UINT16 Ldtr
6642 );
6643
6644 /**
6645 Save the current floating point/SSE/SSE2 context to a buffer.
6646
6647 Saves the current floating point/SSE/SSE2 state to the buffer specified by
6648 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
6649 available on IA-32 and x64.
6650
6651 If Buffer is NULL, then ASSERT().
6652 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6653
6654 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
6655
6656 **/
6657 VOID
6658 EFIAPI
6659 AsmFxSave (
6660 OUT IA32_FX_BUFFER *Buffer
6661 );
6662
6663 /**
6664 Restores the current floating point/SSE/SSE2 context from a buffer.
6665
6666 Restores the current floating point/SSE/SSE2 state from the buffer specified
6667 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
6668 only available on IA-32 and x64.
6669
6670 If Buffer is NULL, then ASSERT().
6671 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6672 If Buffer was not saved with AsmFxSave(), then ASSERT().
6673
6674 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
6675
6676 **/
6677 VOID
6678 EFIAPI
6679 AsmFxRestore (
6680 IN CONST IA32_FX_BUFFER *Buffer
6681 );
6682
6683 /**
6684 Reads the current value of 64-bit MMX Register #0 (MM0).
6685
6686 Reads and returns the current value of MM0. This function is only available
6687 on IA-32 and x64.
6688
6689 @return The current value of MM0.
6690
6691 **/
6692 UINT64
6693 EFIAPI
6694 AsmReadMm0 (
6695 VOID
6696 );
6697
6698 /**
6699 Reads the current value of 64-bit MMX Register #1 (MM1).
6700
6701 Reads and returns the current value of MM1. This function is only available
6702 on IA-32 and x64.
6703
6704 @return The current value of MM1.
6705
6706 **/
6707 UINT64
6708 EFIAPI
6709 AsmReadMm1 (
6710 VOID
6711 );
6712
6713 /**
6714 Reads the current value of 64-bit MMX Register #2 (MM2).
6715
6716 Reads and returns the current value of MM2. This function is only available
6717 on IA-32 and x64.
6718
6719 @return The current value of MM2.
6720
6721 **/
6722 UINT64
6723 EFIAPI
6724 AsmReadMm2 (
6725 VOID
6726 );
6727
6728 /**
6729 Reads the current value of 64-bit MMX Register #3 (MM3).
6730
6731 Reads and returns the current value of MM3. This function is only available
6732 on IA-32 and x64.
6733
6734 @return The current value of MM3.
6735
6736 **/
6737 UINT64
6738 EFIAPI
6739 AsmReadMm3 (
6740 VOID
6741 );
6742
6743 /**
6744 Reads the current value of 64-bit MMX Register #4 (MM4).
6745
6746 Reads and returns the current value of MM4. This function is only available
6747 on IA-32 and x64.
6748
6749 @return The current value of MM4.
6750
6751 **/
6752 UINT64
6753 EFIAPI
6754 AsmReadMm4 (
6755 VOID
6756 );
6757
6758 /**
6759 Reads the current value of 64-bit MMX Register #5 (MM5).
6760
6761 Reads and returns the current value of MM5. This function is only available
6762 on IA-32 and x64.
6763
6764 @return The current value of MM5.
6765
6766 **/
6767 UINT64
6768 EFIAPI
6769 AsmReadMm5 (
6770 VOID
6771 );
6772
6773 /**
6774 Reads the current value of 64-bit MMX Register #6 (MM6).
6775
6776 Reads and returns the current value of MM6. This function is only available
6777 on IA-32 and x64.
6778
6779 @return The current value of MM6.
6780
6781 **/
6782 UINT64
6783 EFIAPI
6784 AsmReadMm6 (
6785 VOID
6786 );
6787
6788 /**
6789 Reads the current value of 64-bit MMX Register #7 (MM7).
6790
6791 Reads and returns the current value of MM7. This function is only available
6792 on IA-32 and x64.
6793
6794 @return The current value of MM7.
6795
6796 **/
6797 UINT64
6798 EFIAPI
6799 AsmReadMm7 (
6800 VOID
6801 );
6802
6803 /**
6804 Writes the current value of 64-bit MMX Register #0 (MM0).
6805
6806 Writes the current value of MM0. This function is only available on IA32 and
6807 x64.
6808
6809 @param Value The 64-bit value to write to MM0.
6810
6811 **/
6812 VOID
6813 EFIAPI
6814 AsmWriteMm0 (
6815 IN UINT64 Value
6816 );
6817
6818 /**
6819 Writes the current value of 64-bit MMX Register #1 (MM1).
6820
6821 Writes the current value of MM1. This function is only available on IA32 and
6822 x64.
6823
6824 @param Value The 64-bit value to write to MM1.
6825
6826 **/
6827 VOID
6828 EFIAPI
6829 AsmWriteMm1 (
6830 IN UINT64 Value
6831 );
6832
6833 /**
6834 Writes the current value of 64-bit MMX Register #2 (MM2).
6835
6836 Writes the current value of MM2. This function is only available on IA32 and
6837 x64.
6838
6839 @param Value The 64-bit value to write to MM2.
6840
6841 **/
6842 VOID
6843 EFIAPI
6844 AsmWriteMm2 (
6845 IN UINT64 Value
6846 );
6847
6848 /**
6849 Writes the current value of 64-bit MMX Register #3 (MM3).
6850
6851 Writes the current value of MM3. This function is only available on IA32 and
6852 x64.
6853
6854 @param Value The 64-bit value to write to MM3.
6855
6856 **/
6857 VOID
6858 EFIAPI
6859 AsmWriteMm3 (
6860 IN UINT64 Value
6861 );
6862
6863 /**
6864 Writes the current value of 64-bit MMX Register #4 (MM4).
6865
6866 Writes the current value of MM4. This function is only available on IA32 and
6867 x64.
6868
6869 @param Value The 64-bit value to write to MM4.
6870
6871 **/
6872 VOID
6873 EFIAPI
6874 AsmWriteMm4 (
6875 IN UINT64 Value
6876 );
6877
6878 /**
6879 Writes the current value of 64-bit MMX Register #5 (MM5).
6880
6881 Writes the current value of MM5. This function is only available on IA32 and
6882 x64.
6883
6884 @param Value The 64-bit value to write to MM5.
6885
6886 **/
6887 VOID
6888 EFIAPI
6889 AsmWriteMm5 (
6890 IN UINT64 Value
6891 );
6892
6893 /**
6894 Writes the current value of 64-bit MMX Register #6 (MM6).
6895
6896 Writes the current value of MM6. This function is only available on IA32 and
6897 x64.
6898
6899 @param Value The 64-bit value to write to MM6.
6900
6901 **/
6902 VOID
6903 EFIAPI
6904 AsmWriteMm6 (
6905 IN UINT64 Value
6906 );
6907
6908 /**
6909 Writes the current value of 64-bit MMX Register #7 (MM7).
6910
6911 Writes the current value of MM7. This function is only available on IA32 and
6912 x64.
6913
6914 @param Value The 64-bit value to write to MM7.
6915
6916 **/
6917 VOID
6918 EFIAPI
6919 AsmWriteMm7 (
6920 IN UINT64 Value
6921 );
6922
6923 /**
6924 Reads the current value of Time Stamp Counter (TSC).
6925
6926 Reads and returns the current value of TSC. This function is only available
6927 on IA-32 and x64.
6928
6929 @return The current value of TSC
6930
6931 **/
6932 UINT64
6933 EFIAPI
6934 AsmReadTsc (
6935 VOID
6936 );
6937
6938 /**
6939 Reads the current value of a Performance Counter (PMC).
6940
6941 Reads and returns the current value of performance counter specified by
6942 Index. This function is only available on IA-32 and x64.
6943
6944 @param Index The 32-bit Performance Counter index to read.
6945
6946 @return The value of the PMC specified by Index.
6947
6948 **/
6949 UINT64
6950 EFIAPI
6951 AsmReadPmc (
6952 IN UINT32 Index
6953 );
6954
6955 /**
6956 Sets up a monitor buffer that is used by AsmMwait().
6957
6958 Executes a MONITOR instruction with the register state specified by Eax, Ecx
6959 and Edx. Returns Eax. This function is only available on IA-32 and x64.
6960
6961 @param Eax The value to load into EAX or RAX before executing the MONITOR
6962 instruction.
6963 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6964 instruction.
6965 @param Edx The value to load into EDX or RDX before executing the MONITOR
6966 instruction.
6967
6968 @return Eax
6969
6970 **/
6971 UINTN
6972 EFIAPI
6973 AsmMonitor (
6974 IN UINTN Eax,
6975 IN UINTN Ecx,
6976 IN UINTN Edx
6977 );
6978
6979 /**
6980 Executes an MWAIT instruction.
6981
6982 Executes an MWAIT instruction with the register state specified by Eax and
6983 Ecx. Returns Eax. This function is only available on IA-32 and x64.
6984
6985 @param Eax The value to load into EAX or RAX before executing the MONITOR
6986 instruction.
6987 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6988 instruction.
6989
6990 @return Eax
6991
6992 **/
6993 UINTN
6994 EFIAPI
6995 AsmMwait (
6996 IN UINTN Eax,
6997 IN UINTN Ecx
6998 );
6999
7000 /**
7001 Executes a WBINVD instruction.
7002
7003 Executes a WBINVD instruction. This function is only available on IA-32 and
7004 x64.
7005
7006 **/
7007 VOID
7008 EFIAPI
7009 AsmWbinvd (
7010 VOID
7011 );
7012
7013 /**
7014 Executes a INVD instruction.
7015
7016 Executes a INVD instruction. This function is only available on IA-32 and
7017 x64.
7018
7019 **/
7020 VOID
7021 EFIAPI
7022 AsmInvd (
7023 VOID
7024 );
7025
7026 /**
7027 Flushes a cache line from all the instruction and data caches within the
7028 coherency domain of the CPU.
7029
7030 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
7031 This function is only available on IA-32 and x64.
7032
7033 @param LinearAddress The address of the cache line to flush. If the CPU is
7034 in a physical addressing mode, then LinearAddress is a
7035 physical address. If the CPU is in a virtual
7036 addressing mode, then LinearAddress is a virtual
7037 address.
7038
7039 @return LinearAddress.
7040 **/
7041 VOID *
7042 EFIAPI
7043 AsmFlushCacheLine (
7044 IN VOID *LinearAddress
7045 );
7046
7047 /**
7048 Enables the 32-bit paging mode on the CPU.
7049
7050 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7051 must be properly initialized prior to calling this service. This function
7052 assumes the current execution mode is 32-bit protected mode. This function is
7053 only available on IA-32. After the 32-bit paging mode is enabled, control is
7054 transferred to the function specified by EntryPoint using the new stack
7055 specified by NewStack and passing in the parameters specified by Context1 and
7056 Context2. Context1 and Context2 are optional and may be NULL. The function
7057 EntryPoint must never return.
7058
7059 If the current execution mode is not 32-bit protected mode, then ASSERT().
7060 If EntryPoint is NULL, then ASSERT().
7061 If NewStack is NULL, then ASSERT().
7062
7063 There are a number of constraints that must be followed before calling this
7064 function:
7065 1) Interrupts must be disabled.
7066 2) The caller must be in 32-bit protected mode with flat descriptors. This
7067 means all descriptors must have a base of 0 and a limit of 4GB.
7068 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
7069 descriptors.
7070 4) CR3 must point to valid page tables that will be used once the transition
7071 is complete, and those page tables must guarantee that the pages for this
7072 function and the stack are identity mapped.
7073
7074 @param EntryPoint A pointer to function to call with the new stack after
7075 paging is enabled.
7076 @param Context1 A pointer to the context to pass into the EntryPoint
7077 function as the first parameter after paging is enabled.
7078 @param Context2 A pointer to the context to pass into the EntryPoint
7079 function as the second parameter after paging is enabled.
7080 @param NewStack A pointer to the new stack to use for the EntryPoint
7081 function after paging is enabled.
7082
7083 **/
7084 VOID
7085 EFIAPI
7086 AsmEnablePaging32 (
7087 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
7088 IN VOID *Context1 OPTIONAL,
7089 IN VOID *Context2 OPTIONAL,
7090 IN VOID *NewStack
7091 );
7092
7093 /**
7094 Disables the 32-bit paging mode on the CPU.
7095
7096 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
7097 mode. This function assumes the current execution mode is 32-paged protected
7098 mode. This function is only available on IA-32. After the 32-bit paging mode
7099 is disabled, control is transferred to the function specified by EntryPoint
7100 using the new stack specified by NewStack and passing in the parameters
7101 specified by Context1 and Context2. Context1 and Context2 are optional and
7102 may be NULL. The function EntryPoint must never return.
7103
7104 If the current execution mode is not 32-bit paged mode, then ASSERT().
7105 If EntryPoint is NULL, then ASSERT().
7106 If NewStack is NULL, then ASSERT().
7107
7108 There are a number of constraints that must be followed before calling this
7109 function:
7110 1) Interrupts must be disabled.
7111 2) The caller must be in 32-bit paged mode.
7112 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
7113 4) CR3 must point to valid page tables that guarantee that the pages for
7114 this function and the stack are identity mapped.
7115
7116 @param EntryPoint A pointer to function to call with the new stack after
7117 paging is disabled.
7118 @param Context1 A pointer to the context to pass into the EntryPoint
7119 function as the first parameter after paging is disabled.
7120 @param Context2 A pointer to the context to pass into the EntryPoint
7121 function as the second parameter after paging is
7122 disabled.
7123 @param NewStack A pointer to the new stack to use for the EntryPoint
7124 function after paging is disabled.
7125
7126 **/
7127 VOID
7128 EFIAPI
7129 AsmDisablePaging32 (
7130 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
7131 IN VOID *Context1 OPTIONAL,
7132 IN VOID *Context2 OPTIONAL,
7133 IN VOID *NewStack
7134 );
7135
7136 /**
7137 Enables the 64-bit paging mode on the CPU.
7138
7139 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7140 must be properly initialized prior to calling this service. This function
7141 assumes the current execution mode is 32-bit protected mode with flat
7142 descriptors. This function is only available on IA-32. After the 64-bit
7143 paging mode is enabled, control is transferred to the function specified by
7144 EntryPoint using the new stack specified by NewStack and passing in the
7145 parameters specified by Context1 and Context2. Context1 and Context2 are
7146 optional and may be 0. The function EntryPoint must never return.
7147
7148 If the current execution mode is not 32-bit protected mode with flat
7149 descriptors, then ASSERT().
7150 If EntryPoint is 0, then ASSERT().
7151 If NewStack is 0, then ASSERT().
7152
7153 @param Cs The 16-bit selector to load in the CS before EntryPoint
7154 is called. The descriptor in the GDT that this selector
7155 references must be setup for long mode.
7156 @param EntryPoint The 64-bit virtual address of the function to call with
7157 the new stack after paging is enabled.
7158 @param Context1 The 64-bit virtual address of the context to pass into
7159 the EntryPoint function as the first parameter after
7160 paging is enabled.
7161 @param Context2 The 64-bit virtual address of the context to pass into
7162 the EntryPoint function as the second parameter after
7163 paging is enabled.
7164 @param NewStack The 64-bit virtual address of the new stack to use for
7165 the EntryPoint function after paging is enabled.
7166
7167 **/
7168 VOID
7169 EFIAPI
7170 AsmEnablePaging64 (
7171 IN UINT16 Cs,
7172 IN UINT64 EntryPoint,
7173 IN UINT64 Context1 OPTIONAL,
7174 IN UINT64 Context2 OPTIONAL,
7175 IN UINT64 NewStack
7176 );
7177
7178 /**
7179 Disables the 64-bit paging mode on the CPU.
7180
7181 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
7182 mode. This function assumes the current execution mode is 64-paging mode.
7183 This function is only available on x64. After the 64-bit paging mode is
7184 disabled, control is transferred to the function specified by EntryPoint
7185 using the new stack specified by NewStack and passing in the parameters
7186 specified by Context1 and Context2. Context1 and Context2 are optional and
7187 may be 0. The function EntryPoint must never return.
7188
7189 If the current execution mode is not 64-bit paged mode, then ASSERT().
7190 If EntryPoint is 0, then ASSERT().
7191 If NewStack is 0, then ASSERT().
7192
7193 @param Cs The 16-bit selector to load in the CS before EntryPoint
7194 is called. The descriptor in the GDT that this selector
7195 references must be setup for 32-bit protected mode.
7196 @param EntryPoint The 64-bit virtual address of the function to call with
7197 the new stack after paging is disabled.
7198 @param Context1 The 64-bit virtual address of the context to pass into
7199 the EntryPoint function as the first parameter after
7200 paging is disabled.
7201 @param Context2 The 64-bit virtual address of the context to pass into
7202 the EntryPoint function as the second parameter after
7203 paging is disabled.
7204 @param NewStack The 64-bit virtual address of the new stack to use for
7205 the EntryPoint function after paging is disabled.
7206
7207 **/
7208 VOID
7209 EFIAPI
7210 AsmDisablePaging64 (
7211 IN UINT16 Cs,
7212 IN UINT32 EntryPoint,
7213 IN UINT32 Context1 OPTIONAL,
7214 IN UINT32 Context2 OPTIONAL,
7215 IN UINT32 NewStack
7216 );
7217
7218 //
7219 // 16-bit thunking services
7220 //
7221
7222 /**
7223 Retrieves the properties for 16-bit thunk functions.
7224
7225 Computes the size of the buffer and stack below 1MB required to use the
7226 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
7227 buffer size is returned in RealModeBufferSize, and the stack size is returned
7228 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
7229 then the actual minimum stack size is ExtraStackSize plus the maximum number
7230 of bytes that need to be passed to the 16-bit real mode code.
7231
7232 If RealModeBufferSize is NULL, then ASSERT().
7233 If ExtraStackSize is NULL, then ASSERT().
7234
7235 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
7236 required to use the 16-bit thunk functions.
7237 @param ExtraStackSize A pointer to the extra size of stack below 1MB
7238 that the 16-bit thunk functions require for
7239 temporary storage in the transition to and from
7240 16-bit real mode.
7241
7242 **/
7243 VOID
7244 EFIAPI
7245 AsmGetThunk16Properties (
7246 OUT UINT32 *RealModeBufferSize,
7247 OUT UINT32 *ExtraStackSize
7248 );
7249
7250 /**
7251 Prepares all structures a code required to use AsmThunk16().
7252
7253 Prepares all structures and code required to use AsmThunk16().
7254
7255 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
7256 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
7257
7258 If ThunkContext is NULL, then ASSERT().
7259
7260 @param ThunkContext A pointer to the context structure that describes the
7261 16-bit real mode code to call.
7262
7263 **/
7264 VOID
7265 EFIAPI
7266 AsmPrepareThunk16 (
7267 IN OUT THUNK_CONTEXT *ThunkContext
7268 );
7269
7270 /**
7271 Transfers control to a 16-bit real mode entry point and returns the results.
7272
7273 Transfers control to a 16-bit real mode entry point and returns the results.
7274 AsmPrepareThunk16() must be called with ThunkContext before this function is used.
7275 This function must be called with interrupts disabled.
7276
7277 The register state from the RealModeState field of ThunkContext is restored just prior
7278 to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,
7279 which is used to set the interrupt state when a 16-bit real mode entry point is called.
7280 Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.
7281 The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to
7282 the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.
7283 The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,
7284 so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment
7285 and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry
7286 point must exit with a RETF instruction. The register state is captured into RealModeState immediately
7287 after the RETF instruction is executed.
7288
7289 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
7290 or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure
7291 the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.
7292
7293 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
7294 then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.
7295 This includes the base vectors, the interrupt masks, and the edge/level trigger mode.
7296
7297 If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code
7298 is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.
7299
7300 If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
7301 ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to
7302 disable the A20 mask.
7303
7304 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in
7305 ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,
7306 then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
7307
7308 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in
7309 ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
7310
7311 If ThunkContext is NULL, then ASSERT().
7312 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
7313 If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
7314 ThunkAttributes, then ASSERT().
7315
7316 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
7317 virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.
7318
7319 @param ThunkContext A pointer to the context structure that describes the
7320 16-bit real mode code to call.
7321
7322 **/
7323 VOID
7324 EFIAPI
7325 AsmThunk16 (
7326 IN OUT THUNK_CONTEXT *ThunkContext
7327 );
7328
7329 /**
7330 Prepares all structures and code for a 16-bit real mode thunk, transfers
7331 control to a 16-bit real mode entry point, and returns the results.
7332
7333 Prepares all structures and code for a 16-bit real mode thunk, transfers
7334 control to a 16-bit real mode entry point, and returns the results. If the
7335 caller only need to perform a single 16-bit real mode thunk, then this
7336 service should be used. If the caller intends to make more than one 16-bit
7337 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
7338 once and AsmThunk16() can be called for each 16-bit real mode thunk.
7339
7340 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
7341 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
7342
7343 See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.
7344
7345 @param ThunkContext A pointer to the context structure that describes the
7346 16-bit real mode code to call.
7347
7348 **/
7349 VOID
7350 EFIAPI
7351 AsmPrepareAndThunk16 (
7352 IN OUT THUNK_CONTEXT *ThunkContext
7353 );
7354
7355 /**
7356 Generates a 16-bit random number through RDRAND instruction.
7357
7358 if Rand is NULL, then ASSERT().
7359
7360 @param[out] Rand Buffer pointer to store the random result.
7361
7362 @retval TRUE RDRAND call was successful.
7363 @retval FALSE Failed attempts to call RDRAND.
7364
7365 **/
7366 BOOLEAN
7367 EFIAPI
7368 AsmRdRand16 (
7369 OUT UINT16 *Rand
7370 );
7371
7372 /**
7373 Generates a 32-bit random number through RDRAND instruction.
7374
7375 if Rand is NULL, then ASSERT().
7376
7377 @param[out] Rand Buffer pointer to store the random result.
7378
7379 @retval TRUE RDRAND call was successful.
7380 @retval FALSE Failed attempts to call RDRAND.
7381
7382 **/
7383 BOOLEAN
7384 EFIAPI
7385 AsmRdRand32 (
7386 OUT UINT32 *Rand
7387 );
7388
7389 /**
7390 Generates a 64-bit random number through RDRAND instruction.
7391
7392 if Rand is NULL, then ASSERT().
7393
7394 @param[out] Rand Buffer pointer to store the random result.
7395
7396 @retval TRUE RDRAND call was successful.
7397 @retval FALSE Failed attempts to call RDRAND.
7398
7399 **/
7400 BOOLEAN
7401 EFIAPI
7402 AsmRdRand64 (
7403 OUT UINT64 *Rand
7404 );
7405
7406 /**
7407 Load given selector into TR register.
7408
7409 @param[in] Selector Task segment selector
7410 **/
7411 VOID
7412 EFIAPI
7413 AsmWriteTr (
7414 IN UINT16 Selector
7415 );
7416
7417 /**
7418 Performs a serializing operation on all load-from-memory instructions that
7419 were issued prior the AsmLfence function.
7420
7421 Executes a LFENCE instruction. This function is only available on IA-32 and x64.
7422
7423 **/
7424 VOID
7425 EFIAPI
7426 AsmLfence (
7427 VOID
7428 );
7429
7430 /**
7431 Executes a XGETBV instruction
7432
7433 Executes a XGETBV instruction. This function is only available on IA-32 and
7434 x64.
7435
7436 @param[in] Index Extended control register index
7437
7438 @return The current value of the extended control register
7439 **/
7440 UINT64
7441 EFIAPI
7442 AsmXGetBv (
7443 IN UINT32 Index
7444 );
7445
7446 /**
7447 Executes a XSETBV instruction to write a 64-bit value to a Extended Control
7448 Register(XCR), and returns the value.
7449
7450 Writes the 64-bit value specified by Value to the XCR specified by Index. The
7451 64-bit value written to the XCR is returned. No parameter checking is
7452 performed on Index or Value, and some of these may cause CPU exceptions. The
7453 caller must either guarantee that Index and Value are valid, or the caller
7454 must establish proper exception handlers. This function is only available on
7455 IA-32 and x64.
7456
7457 @param Index The 32-bit XCR index to write.
7458 @param Value The 64-bit value to write to the XCR.
7459
7460 @return Value
7461
7462 **/
7463 UINT64
7464 EFIAPI
7465 AsmXSetBv (
7466 IN UINT32 Index,
7467 IN UINT64 Value
7468 );
7469
7470 /**
7471 Executes a VMGEXIT instruction (VMMCALL with a REP prefix)
7472
7473 Executes a VMGEXIT instruction. This function is only available on IA-32 and
7474 x64.
7475
7476 **/
7477 VOID
7478 EFIAPI
7479 AsmVmgExit (
7480 VOID
7481 );
7482
7483 /**
7484 Patch the immediate operand of an IA32 or X64 instruction such that the byte,
7485 word, dword or qword operand is encoded at the end of the instruction's
7486 binary representation.
7487
7488 This function should be used to update object code that was compiled with
7489 NASM from assembly source code. Example:
7490
7491 NASM source code:
7492
7493 mov eax, strict dword 0 ; the imm32 zero operand will be patched
7494 ASM_PFX(gPatchCr3):
7495 mov cr3, eax
7496
7497 C source code:
7498
7499 X86_ASSEMBLY_PATCH_LABEL gPatchCr3;
7500 PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);
7501
7502 @param[out] InstructionEnd Pointer right past the instruction to patch. The
7503 immediate operand to patch is expected to
7504 comprise the trailing bytes of the instruction.
7505 If InstructionEnd is closer to address 0 than
7506 ValueSize permits, then ASSERT().
7507
7508 @param[in] PatchValue The constant to write to the immediate operand.
7509 The caller is responsible for ensuring that
7510 PatchValue can be represented in the byte, word,
7511 dword or qword operand (as indicated through
7512 ValueSize); otherwise ASSERT().
7513
7514 @param[in] ValueSize The size of the operand in bytes; must be 1, 2,
7515 4, or 8. ASSERT() otherwise.
7516 **/
7517 VOID
7518 EFIAPI
7519 PatchInstructionX86 (
7520 OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,
7521 IN UINT64 PatchValue,
7522 IN UINTN ValueSize
7523 );
7524
7525 #endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
7526 #endif // !defined (__BASE_LIB__)