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