]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/BaseLib.h
MdePkg: Remove code wrapped by DISABLE_NEW_DEPRECATED_INTERFACES
[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 - 2019, 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 /**
2861 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
2862 with zeros. The shifted value is returned.
2863
2864 This function shifts the 64-bit value Operand to the left by Count bits. The
2865 low Count bits are set to zero. The shifted value is returned.
2866
2867 If Count is greater than 63, then ASSERT().
2868
2869 @param Operand The 64-bit operand to shift left.
2870 @param Count The number of bits to shift left.
2871
2872 @return Operand << Count.
2873
2874 **/
2875 UINT64
2876 EFIAPI
2877 LShiftU64 (
2878 IN UINT64 Operand,
2879 IN UINTN Count
2880 );
2881
2882
2883 /**
2884 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
2885 filled with zeros. The shifted value is returned.
2886
2887 This function shifts the 64-bit value Operand to the right by Count bits. The
2888 high Count bits are set to zero. The shifted value is returned.
2889
2890 If Count is greater than 63, then ASSERT().
2891
2892 @param Operand The 64-bit operand to shift right.
2893 @param Count The number of bits to shift right.
2894
2895 @return Operand >> Count
2896
2897 **/
2898 UINT64
2899 EFIAPI
2900 RShiftU64 (
2901 IN UINT64 Operand,
2902 IN UINTN Count
2903 );
2904
2905
2906 /**
2907 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
2908 with original integer's bit 63. The shifted value is returned.
2909
2910 This function shifts the 64-bit value Operand to the right by Count bits. The
2911 high Count bits are set to bit 63 of Operand. The shifted value is returned.
2912
2913 If Count is greater than 63, then ASSERT().
2914
2915 @param Operand The 64-bit operand to shift right.
2916 @param Count The number of bits to shift right.
2917
2918 @return Operand >> Count
2919
2920 **/
2921 UINT64
2922 EFIAPI
2923 ARShiftU64 (
2924 IN UINT64 Operand,
2925 IN UINTN Count
2926 );
2927
2928
2929 /**
2930 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
2931 with the high bits that were rotated.
2932
2933 This function rotates the 32-bit value Operand to the left by Count bits. The
2934 low Count bits are fill with the high Count bits of Operand. The rotated
2935 value is returned.
2936
2937 If Count is greater than 31, then ASSERT().
2938
2939 @param Operand The 32-bit operand to rotate left.
2940 @param Count The number of bits to rotate left.
2941
2942 @return Operand << Count
2943
2944 **/
2945 UINT32
2946 EFIAPI
2947 LRotU32 (
2948 IN UINT32 Operand,
2949 IN UINTN Count
2950 );
2951
2952
2953 /**
2954 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
2955 with the low bits that were rotated.
2956
2957 This function rotates the 32-bit value Operand to the right by Count bits.
2958 The high Count bits are fill with the low Count bits of Operand. The rotated
2959 value is returned.
2960
2961 If Count is greater than 31, then ASSERT().
2962
2963 @param Operand The 32-bit operand to rotate right.
2964 @param Count The number of bits to rotate right.
2965
2966 @return Operand >> Count
2967
2968 **/
2969 UINT32
2970 EFIAPI
2971 RRotU32 (
2972 IN UINT32 Operand,
2973 IN UINTN Count
2974 );
2975
2976
2977 /**
2978 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
2979 with the high bits that were rotated.
2980
2981 This function rotates the 64-bit value Operand to the left by Count bits. The
2982 low Count bits are fill with the high Count bits of Operand. The rotated
2983 value is returned.
2984
2985 If Count is greater than 63, then ASSERT().
2986
2987 @param Operand The 64-bit operand to rotate left.
2988 @param Count The number of bits to rotate left.
2989
2990 @return Operand << Count
2991
2992 **/
2993 UINT64
2994 EFIAPI
2995 LRotU64 (
2996 IN UINT64 Operand,
2997 IN UINTN Count
2998 );
2999
3000
3001 /**
3002 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
3003 with the high low bits that were rotated.
3004
3005 This function rotates the 64-bit value Operand to the right by Count bits.
3006 The high Count bits are fill with the low Count bits of Operand. The rotated
3007 value is returned.
3008
3009 If Count is greater than 63, then ASSERT().
3010
3011 @param Operand The 64-bit operand to rotate right.
3012 @param Count The number of bits to rotate right.
3013
3014 @return Operand >> Count
3015
3016 **/
3017 UINT64
3018 EFIAPI
3019 RRotU64 (
3020 IN UINT64 Operand,
3021 IN UINTN Count
3022 );
3023
3024
3025 /**
3026 Returns the bit position of the lowest bit set in a 32-bit value.
3027
3028 This function computes the bit position of the lowest bit set in the 32-bit
3029 value specified by Operand. If Operand is zero, then -1 is returned.
3030 Otherwise, a value between 0 and 31 is returned.
3031
3032 @param Operand The 32-bit operand to evaluate.
3033
3034 @retval 0..31 The lowest bit set in Operand was found.
3035 @retval -1 Operand is zero.
3036
3037 **/
3038 INTN
3039 EFIAPI
3040 LowBitSet32 (
3041 IN UINT32 Operand
3042 );
3043
3044
3045 /**
3046 Returns the bit position of the lowest bit set in a 64-bit value.
3047
3048 This function computes the bit position of the lowest bit set in the 64-bit
3049 value specified by Operand. If Operand is zero, then -1 is returned.
3050 Otherwise, a value between 0 and 63 is returned.
3051
3052 @param Operand The 64-bit operand to evaluate.
3053
3054 @retval 0..63 The lowest bit set in Operand was found.
3055 @retval -1 Operand is zero.
3056
3057
3058 **/
3059 INTN
3060 EFIAPI
3061 LowBitSet64 (
3062 IN UINT64 Operand
3063 );
3064
3065
3066 /**
3067 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
3068 to log2(x).
3069
3070 This function computes the bit position of the highest bit set in the 32-bit
3071 value specified by Operand. If Operand is zero, then -1 is returned.
3072 Otherwise, a value between 0 and 31 is returned.
3073
3074 @param Operand The 32-bit operand to evaluate.
3075
3076 @retval 0..31 Position of the highest bit set in Operand if found.
3077 @retval -1 Operand is zero.
3078
3079 **/
3080 INTN
3081 EFIAPI
3082 HighBitSet32 (
3083 IN UINT32 Operand
3084 );
3085
3086
3087 /**
3088 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
3089 to log2(x).
3090
3091 This function computes the bit position of the highest bit set in the 64-bit
3092 value specified by Operand. If Operand is zero, then -1 is returned.
3093 Otherwise, a value between 0 and 63 is returned.
3094
3095 @param Operand The 64-bit operand to evaluate.
3096
3097 @retval 0..63 Position of the highest bit set in Operand if found.
3098 @retval -1 Operand is zero.
3099
3100 **/
3101 INTN
3102 EFIAPI
3103 HighBitSet64 (
3104 IN UINT64 Operand
3105 );
3106
3107
3108 /**
3109 Returns the value of the highest bit set in a 32-bit value. Equivalent to
3110 1 << log2(x).
3111
3112 This function computes the value of the highest bit set in the 32-bit value
3113 specified by Operand. If Operand is zero, then zero is returned.
3114
3115 @param Operand The 32-bit operand to evaluate.
3116
3117 @return 1 << HighBitSet32(Operand)
3118 @retval 0 Operand is zero.
3119
3120 **/
3121 UINT32
3122 EFIAPI
3123 GetPowerOfTwo32 (
3124 IN UINT32 Operand
3125 );
3126
3127
3128 /**
3129 Returns the value of the highest bit set in a 64-bit value. Equivalent to
3130 1 << log2(x).
3131
3132 This function computes the value of the highest bit set in the 64-bit value
3133 specified by Operand. If Operand is zero, then zero is returned.
3134
3135 @param Operand The 64-bit operand to evaluate.
3136
3137 @return 1 << HighBitSet64(Operand)
3138 @retval 0 Operand is zero.
3139
3140 **/
3141 UINT64
3142 EFIAPI
3143 GetPowerOfTwo64 (
3144 IN UINT64 Operand
3145 );
3146
3147
3148 /**
3149 Switches the endianness of a 16-bit integer.
3150
3151 This function swaps the bytes in a 16-bit unsigned value to switch the value
3152 from little endian to big endian or vice versa. The byte swapped value is
3153 returned.
3154
3155 @param Value A 16-bit unsigned value.
3156
3157 @return The byte swapped Value.
3158
3159 **/
3160 UINT16
3161 EFIAPI
3162 SwapBytes16 (
3163 IN UINT16 Value
3164 );
3165
3166
3167 /**
3168 Switches the endianness of a 32-bit integer.
3169
3170 This function swaps the bytes in a 32-bit unsigned value to switch the value
3171 from little endian to big endian or vice versa. The byte swapped value is
3172 returned.
3173
3174 @param Value A 32-bit unsigned value.
3175
3176 @return The byte swapped Value.
3177
3178 **/
3179 UINT32
3180 EFIAPI
3181 SwapBytes32 (
3182 IN UINT32 Value
3183 );
3184
3185
3186 /**
3187 Switches the endianness of a 64-bit integer.
3188
3189 This function swaps the bytes in a 64-bit unsigned value to switch the value
3190 from little endian to big endian or vice versa. The byte swapped value is
3191 returned.
3192
3193 @param Value A 64-bit unsigned value.
3194
3195 @return The byte swapped Value.
3196
3197 **/
3198 UINT64
3199 EFIAPI
3200 SwapBytes64 (
3201 IN UINT64 Value
3202 );
3203
3204
3205 /**
3206 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
3207 generates a 64-bit unsigned result.
3208
3209 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
3210 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
3211 bit unsigned result is returned.
3212
3213 @param Multiplicand A 64-bit unsigned value.
3214 @param Multiplier A 32-bit unsigned value.
3215
3216 @return Multiplicand * Multiplier
3217
3218 **/
3219 UINT64
3220 EFIAPI
3221 MultU64x32 (
3222 IN UINT64 Multiplicand,
3223 IN UINT32 Multiplier
3224 );
3225
3226
3227 /**
3228 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
3229 generates a 64-bit unsigned result.
3230
3231 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
3232 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
3233 bit unsigned result is returned.
3234
3235 @param Multiplicand A 64-bit unsigned value.
3236 @param Multiplier A 64-bit unsigned value.
3237
3238 @return Multiplicand * Multiplier.
3239
3240 **/
3241 UINT64
3242 EFIAPI
3243 MultU64x64 (
3244 IN UINT64 Multiplicand,
3245 IN UINT64 Multiplier
3246 );
3247
3248
3249 /**
3250 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
3251 64-bit signed result.
3252
3253 This function multiples the 64-bit signed value Multiplicand by the 64-bit
3254 signed value Multiplier and generates a 64-bit signed result. This 64-bit
3255 signed result is returned.
3256
3257 @param Multiplicand A 64-bit signed value.
3258 @param Multiplier A 64-bit signed value.
3259
3260 @return Multiplicand * Multiplier
3261
3262 **/
3263 INT64
3264 EFIAPI
3265 MultS64x64 (
3266 IN INT64 Multiplicand,
3267 IN INT64 Multiplier
3268 );
3269
3270
3271 /**
3272 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
3273 a 64-bit unsigned result.
3274
3275 This function divides the 64-bit unsigned value Dividend by the 32-bit
3276 unsigned value Divisor and generates a 64-bit unsigned quotient. This
3277 function returns the 64-bit unsigned quotient.
3278
3279 If Divisor is 0, then ASSERT().
3280
3281 @param Dividend A 64-bit unsigned value.
3282 @param Divisor A 32-bit unsigned value.
3283
3284 @return Dividend / Divisor.
3285
3286 **/
3287 UINT64
3288 EFIAPI
3289 DivU64x32 (
3290 IN UINT64 Dividend,
3291 IN UINT32 Divisor
3292 );
3293
3294
3295 /**
3296 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
3297 a 32-bit unsigned remainder.
3298
3299 This function divides the 64-bit unsigned value Dividend by the 32-bit
3300 unsigned value Divisor and generates a 32-bit remainder. This function
3301 returns the 32-bit unsigned remainder.
3302
3303 If Divisor is 0, then ASSERT().
3304
3305 @param Dividend A 64-bit unsigned value.
3306 @param Divisor A 32-bit unsigned value.
3307
3308 @return Dividend % Divisor.
3309
3310 **/
3311 UINT32
3312 EFIAPI
3313 ModU64x32 (
3314 IN UINT64 Dividend,
3315 IN UINT32 Divisor
3316 );
3317
3318
3319 /**
3320 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
3321 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
3322
3323 This function divides the 64-bit unsigned value Dividend by the 32-bit
3324 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
3325 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
3326 This 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 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
3333 optional and may be NULL.
3334
3335 @return Dividend / Divisor.
3336
3337 **/
3338 UINT64
3339 EFIAPI
3340 DivU64x32Remainder (
3341 IN UINT64 Dividend,
3342 IN UINT32 Divisor,
3343 OUT UINT32 *Remainder OPTIONAL
3344 );
3345
3346
3347 /**
3348 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
3349 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
3350
3351 This function divides the 64-bit unsigned value Dividend by the 64-bit
3352 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
3353 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
3354 This function returns the 64-bit unsigned quotient.
3355
3356 If Divisor is 0, then ASSERT().
3357
3358 @param Dividend A 64-bit unsigned value.
3359 @param Divisor A 64-bit unsigned value.
3360 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
3361 optional and may be NULL.
3362
3363 @return Dividend / Divisor.
3364
3365 **/
3366 UINT64
3367 EFIAPI
3368 DivU64x64Remainder (
3369 IN UINT64 Dividend,
3370 IN UINT64 Divisor,
3371 OUT UINT64 *Remainder OPTIONAL
3372 );
3373
3374
3375 /**
3376 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
3377 64-bit signed result and a optional 64-bit signed remainder.
3378
3379 This function divides the 64-bit signed value Dividend by the 64-bit signed
3380 value Divisor and generates a 64-bit signed quotient. If Remainder is not
3381 NULL, then the 64-bit signed remainder is returned in Remainder. This
3382 function returns the 64-bit signed quotient.
3383
3384 It is the caller's responsibility to not call this function with a Divisor of 0.
3385 If Divisor is 0, then the quotient and remainder should be assumed to be
3386 the largest negative integer.
3387
3388 If Divisor is 0, then ASSERT().
3389
3390 @param Dividend A 64-bit signed value.
3391 @param Divisor A 64-bit signed value.
3392 @param Remainder A pointer to a 64-bit signed value. This parameter is
3393 optional and may be NULL.
3394
3395 @return Dividend / Divisor.
3396
3397 **/
3398 INT64
3399 EFIAPI
3400 DivS64x64Remainder (
3401 IN INT64 Dividend,
3402 IN INT64 Divisor,
3403 OUT INT64 *Remainder OPTIONAL
3404 );
3405
3406
3407 /**
3408 Reads a 16-bit value from memory that may be unaligned.
3409
3410 This function returns the 16-bit value pointed to by Buffer. The function
3411 guarantees that the read operation does not produce an alignment fault.
3412
3413 If the Buffer is NULL, then ASSERT().
3414
3415 @param Buffer The pointer to a 16-bit value that may be unaligned.
3416
3417 @return The 16-bit value read from Buffer.
3418
3419 **/
3420 UINT16
3421 EFIAPI
3422 ReadUnaligned16 (
3423 IN CONST UINT16 *Buffer
3424 );
3425
3426
3427 /**
3428 Writes a 16-bit value to memory that may be unaligned.
3429
3430 This function writes the 16-bit value specified by Value to Buffer. Value is
3431 returned. The function guarantees that the write operation does not produce
3432 an alignment fault.
3433
3434 If the Buffer is NULL, then ASSERT().
3435
3436 @param Buffer The pointer to a 16-bit value that may be unaligned.
3437 @param Value 16-bit value to write to Buffer.
3438
3439 @return The 16-bit value to write to Buffer.
3440
3441 **/
3442 UINT16
3443 EFIAPI
3444 WriteUnaligned16 (
3445 OUT UINT16 *Buffer,
3446 IN UINT16 Value
3447 );
3448
3449
3450 /**
3451 Reads a 24-bit value from memory that may be unaligned.
3452
3453 This function returns the 24-bit value pointed to by Buffer. The function
3454 guarantees that the read operation does not produce an alignment fault.
3455
3456 If the Buffer is NULL, then ASSERT().
3457
3458 @param Buffer The pointer to a 24-bit value that may be unaligned.
3459
3460 @return The 24-bit value read from Buffer.
3461
3462 **/
3463 UINT32
3464 EFIAPI
3465 ReadUnaligned24 (
3466 IN CONST UINT32 *Buffer
3467 );
3468
3469
3470 /**
3471 Writes a 24-bit value to memory that may be unaligned.
3472
3473 This function writes the 24-bit value specified by Value to Buffer. Value is
3474 returned. The function guarantees that the write operation does not produce
3475 an alignment fault.
3476
3477 If the Buffer is NULL, then ASSERT().
3478
3479 @param Buffer The pointer to a 24-bit value that may be unaligned.
3480 @param Value 24-bit value to write to Buffer.
3481
3482 @return The 24-bit value to write to Buffer.
3483
3484 **/
3485 UINT32
3486 EFIAPI
3487 WriteUnaligned24 (
3488 OUT UINT32 *Buffer,
3489 IN UINT32 Value
3490 );
3491
3492
3493 /**
3494 Reads a 32-bit value from memory that may be unaligned.
3495
3496 This function returns the 32-bit value pointed to by Buffer. The function
3497 guarantees that the read operation does not produce an alignment fault.
3498
3499 If the Buffer is NULL, then ASSERT().
3500
3501 @param Buffer The pointer to a 32-bit value that may be unaligned.
3502
3503 @return The 32-bit value read from Buffer.
3504
3505 **/
3506 UINT32
3507 EFIAPI
3508 ReadUnaligned32 (
3509 IN CONST UINT32 *Buffer
3510 );
3511
3512
3513 /**
3514 Writes a 32-bit value to memory that may be unaligned.
3515
3516 This function writes the 32-bit value specified by Value to Buffer. Value is
3517 returned. The function guarantees that the write operation does not produce
3518 an alignment fault.
3519
3520 If the Buffer is NULL, then ASSERT().
3521
3522 @param Buffer The pointer to a 32-bit value that may be unaligned.
3523 @param Value 32-bit value to write to Buffer.
3524
3525 @return The 32-bit value to write to Buffer.
3526
3527 **/
3528 UINT32
3529 EFIAPI
3530 WriteUnaligned32 (
3531 OUT UINT32 *Buffer,
3532 IN UINT32 Value
3533 );
3534
3535
3536 /**
3537 Reads a 64-bit value from memory that may be unaligned.
3538
3539 This function returns the 64-bit value pointed to by Buffer. The function
3540 guarantees that the read operation does not produce an alignment fault.
3541
3542 If the Buffer is NULL, then ASSERT().
3543
3544 @param Buffer The pointer to a 64-bit value that may be unaligned.
3545
3546 @return The 64-bit value read from Buffer.
3547
3548 **/
3549 UINT64
3550 EFIAPI
3551 ReadUnaligned64 (
3552 IN CONST UINT64 *Buffer
3553 );
3554
3555
3556 /**
3557 Writes a 64-bit value to memory that may be unaligned.
3558
3559 This function writes the 64-bit value specified by Value to Buffer. Value is
3560 returned. The function guarantees that the write operation does not produce
3561 an alignment fault.
3562
3563 If the Buffer is NULL, then ASSERT().
3564
3565 @param Buffer The pointer to a 64-bit value that may be unaligned.
3566 @param Value 64-bit value to write to Buffer.
3567
3568 @return The 64-bit value to write to Buffer.
3569
3570 **/
3571 UINT64
3572 EFIAPI
3573 WriteUnaligned64 (
3574 OUT UINT64 *Buffer,
3575 IN UINT64 Value
3576 );
3577
3578
3579 //
3580 // Bit Field Functions
3581 //
3582
3583 /**
3584 Returns a bit field from an 8-bit value.
3585
3586 Returns the bitfield specified by the StartBit and the EndBit from Operand.
3587
3588 If 8-bit operations are not supported, then ASSERT().
3589 If StartBit is greater than 7, then ASSERT().
3590 If EndBit is greater than 7, then ASSERT().
3591 If EndBit is less than StartBit, then ASSERT().
3592
3593 @param Operand Operand on which to perform the bitfield operation.
3594 @param StartBit The ordinal of the least significant bit in the bit field.
3595 Range 0..7.
3596 @param EndBit The ordinal of the most significant bit in the bit field.
3597 Range 0..7.
3598
3599 @return The bit field read.
3600
3601 **/
3602 UINT8
3603 EFIAPI
3604 BitFieldRead8 (
3605 IN UINT8 Operand,
3606 IN UINTN StartBit,
3607 IN UINTN EndBit
3608 );
3609
3610
3611 /**
3612 Writes a bit field to an 8-bit value, and returns the result.
3613
3614 Writes Value to the bit field specified by the StartBit and the EndBit in
3615 Operand. All other bits in Operand are preserved. The new 8-bit value is
3616 returned.
3617
3618 If 8-bit operations are not supported, then ASSERT().
3619 If StartBit is greater than 7, then ASSERT().
3620 If EndBit is greater than 7, then ASSERT().
3621 If EndBit is less than StartBit, then ASSERT().
3622 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3623
3624 @param Operand Operand on which to perform the bitfield operation.
3625 @param StartBit The ordinal of the least significant bit in the bit field.
3626 Range 0..7.
3627 @param EndBit The ordinal of the most significant bit in the bit field.
3628 Range 0..7.
3629 @param Value New value of the bit field.
3630
3631 @return The new 8-bit value.
3632
3633 **/
3634 UINT8
3635 EFIAPI
3636 BitFieldWrite8 (
3637 IN UINT8 Operand,
3638 IN UINTN StartBit,
3639 IN UINTN EndBit,
3640 IN UINT8 Value
3641 );
3642
3643
3644 /**
3645 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
3646 result.
3647
3648 Performs a bitwise OR between the bit field specified by StartBit
3649 and EndBit in Operand and the value specified by OrData. All other bits in
3650 Operand are preserved. The new 8-bit value is returned.
3651
3652 If 8-bit operations are not supported, then ASSERT().
3653 If StartBit is greater than 7, then ASSERT().
3654 If EndBit is greater than 7, then ASSERT().
3655 If EndBit is less than StartBit, then ASSERT().
3656 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3657
3658 @param Operand Operand on which to perform the bitfield operation.
3659 @param StartBit The ordinal of the least significant bit in the bit field.
3660 Range 0..7.
3661 @param EndBit The ordinal of the most significant bit in the bit field.
3662 Range 0..7.
3663 @param OrData The value to OR with the read value from the value
3664
3665 @return The new 8-bit value.
3666
3667 **/
3668 UINT8
3669 EFIAPI
3670 BitFieldOr8 (
3671 IN UINT8 Operand,
3672 IN UINTN StartBit,
3673 IN UINTN EndBit,
3674 IN UINT8 OrData
3675 );
3676
3677
3678 /**
3679 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
3680 the result.
3681
3682 Performs a bitwise AND between the bit field specified by StartBit and EndBit
3683 in Operand and the value specified by AndData. All other bits in Operand are
3684 preserved. The new 8-bit value is returned.
3685
3686 If 8-bit operations are not supported, then ASSERT().
3687 If StartBit is greater than 7, then ASSERT().
3688 If EndBit is greater than 7, then ASSERT().
3689 If EndBit is less than StartBit, then ASSERT().
3690 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3691
3692 @param Operand Operand on which to perform the bitfield operation.
3693 @param StartBit The ordinal of the least significant bit in the bit field.
3694 Range 0..7.
3695 @param EndBit The ordinal of the most significant bit in the bit field.
3696 Range 0..7.
3697 @param AndData The value to AND with the read value from the value.
3698
3699 @return The new 8-bit value.
3700
3701 **/
3702 UINT8
3703 EFIAPI
3704 BitFieldAnd8 (
3705 IN UINT8 Operand,
3706 IN UINTN StartBit,
3707 IN UINTN EndBit,
3708 IN UINT8 AndData
3709 );
3710
3711
3712 /**
3713 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
3714 bitwise OR, and returns the result.
3715
3716 Performs a bitwise AND between the bit field specified by StartBit and EndBit
3717 in Operand and the value specified by AndData, followed by a bitwise
3718 OR with value specified by OrData. All other bits in Operand are
3719 preserved. The new 8-bit value is returned.
3720
3721 If 8-bit operations are not supported, then ASSERT().
3722 If StartBit is greater than 7, then ASSERT().
3723 If EndBit is greater than 7, then ASSERT().
3724 If EndBit is less than StartBit, then ASSERT().
3725 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3726 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3727
3728 @param Operand Operand on which to perform the bitfield operation.
3729 @param StartBit The ordinal of the least significant bit in the bit field.
3730 Range 0..7.
3731 @param EndBit The ordinal of the most significant bit in the bit field.
3732 Range 0..7.
3733 @param AndData The value to AND with the read value from the value.
3734 @param OrData The value to OR with the result of the AND operation.
3735
3736 @return The new 8-bit value.
3737
3738 **/
3739 UINT8
3740 EFIAPI
3741 BitFieldAndThenOr8 (
3742 IN UINT8 Operand,
3743 IN UINTN StartBit,
3744 IN UINTN EndBit,
3745 IN UINT8 AndData,
3746 IN UINT8 OrData
3747 );
3748
3749
3750 /**
3751 Returns a bit field from a 16-bit value.
3752
3753 Returns the bitfield specified by the StartBit and the EndBit from Operand.
3754
3755 If 16-bit operations are not supported, then ASSERT().
3756 If StartBit is greater than 15, then ASSERT().
3757 If EndBit is greater than 15, then ASSERT().
3758 If EndBit is less than StartBit, then ASSERT().
3759
3760 @param Operand Operand on which to perform the bitfield operation.
3761 @param StartBit The ordinal of the least significant bit in the bit field.
3762 Range 0..15.
3763 @param EndBit The ordinal of the most significant bit in the bit field.
3764 Range 0..15.
3765
3766 @return The bit field read.
3767
3768 **/
3769 UINT16
3770 EFIAPI
3771 BitFieldRead16 (
3772 IN UINT16 Operand,
3773 IN UINTN StartBit,
3774 IN UINTN EndBit
3775 );
3776
3777
3778 /**
3779 Writes a bit field to a 16-bit value, and returns the result.
3780
3781 Writes Value to the bit field specified by the StartBit and the EndBit in
3782 Operand. All other bits in Operand are preserved. The new 16-bit value is
3783 returned.
3784
3785 If 16-bit operations are not supported, then ASSERT().
3786 If StartBit is greater than 15, then ASSERT().
3787 If EndBit is greater than 15, then ASSERT().
3788 If EndBit is less than StartBit, then ASSERT().
3789 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3790
3791 @param Operand Operand on which to perform the bitfield operation.
3792 @param StartBit The ordinal of the least significant bit in the bit field.
3793 Range 0..15.
3794 @param EndBit The ordinal of the most significant bit in the bit field.
3795 Range 0..15.
3796 @param Value New value of the bit field.
3797
3798 @return The new 16-bit value.
3799
3800 **/
3801 UINT16
3802 EFIAPI
3803 BitFieldWrite16 (
3804 IN UINT16 Operand,
3805 IN UINTN StartBit,
3806 IN UINTN EndBit,
3807 IN UINT16 Value
3808 );
3809
3810
3811 /**
3812 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
3813 result.
3814
3815 Performs a bitwise OR between the bit field specified by StartBit
3816 and EndBit in Operand and the value specified by OrData. All other bits in
3817 Operand are preserved. The new 16-bit value is returned.
3818
3819 If 16-bit operations are not supported, then ASSERT().
3820 If StartBit is greater than 15, then ASSERT().
3821 If EndBit is greater than 15, then ASSERT().
3822 If EndBit is less than StartBit, then ASSERT().
3823 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3824
3825 @param Operand Operand on which to perform the bitfield operation.
3826 @param StartBit The ordinal of the least significant bit in the bit field.
3827 Range 0..15.
3828 @param EndBit The ordinal of the most significant bit in the bit field.
3829 Range 0..15.
3830 @param OrData The value to OR with the read value from the value
3831
3832 @return The new 16-bit value.
3833
3834 **/
3835 UINT16
3836 EFIAPI
3837 BitFieldOr16 (
3838 IN UINT16 Operand,
3839 IN UINTN StartBit,
3840 IN UINTN EndBit,
3841 IN UINT16 OrData
3842 );
3843
3844
3845 /**
3846 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
3847 the result.
3848
3849 Performs a bitwise AND between the bit field specified by StartBit and EndBit
3850 in Operand and the value specified by AndData. All other bits in Operand are
3851 preserved. The new 16-bit value is returned.
3852
3853 If 16-bit operations are not supported, then ASSERT().
3854 If StartBit is greater than 15, then ASSERT().
3855 If EndBit is greater than 15, then ASSERT().
3856 If EndBit is less than StartBit, then ASSERT().
3857 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3858
3859 @param Operand Operand on which to perform the bitfield operation.
3860 @param StartBit The ordinal of the least significant bit in the bit field.
3861 Range 0..15.
3862 @param EndBit The ordinal of the most significant bit in the bit field.
3863 Range 0..15.
3864 @param AndData The value to AND with the read value from the value
3865
3866 @return The new 16-bit value.
3867
3868 **/
3869 UINT16
3870 EFIAPI
3871 BitFieldAnd16 (
3872 IN UINT16 Operand,
3873 IN UINTN StartBit,
3874 IN UINTN EndBit,
3875 IN UINT16 AndData
3876 );
3877
3878
3879 /**
3880 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
3881 bitwise OR, and returns the result.
3882
3883 Performs a bitwise AND between the bit field specified by StartBit and EndBit
3884 in Operand and the value specified by AndData, followed by a bitwise
3885 OR with value specified by OrData. All other bits in Operand are
3886 preserved. The new 16-bit value is returned.
3887
3888 If 16-bit operations are not supported, then ASSERT().
3889 If StartBit is greater than 15, then ASSERT().
3890 If EndBit is greater than 15, then ASSERT().
3891 If EndBit is less than StartBit, then ASSERT().
3892 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3893 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3894
3895 @param Operand Operand on which to perform the bitfield operation.
3896 @param StartBit The ordinal of the least significant bit in the bit field.
3897 Range 0..15.
3898 @param EndBit The ordinal of the most significant bit in the bit field.
3899 Range 0..15.
3900 @param AndData The value to AND with the read value from the value.
3901 @param OrData The value to OR with the result of the AND operation.
3902
3903 @return The new 16-bit value.
3904
3905 **/
3906 UINT16
3907 EFIAPI
3908 BitFieldAndThenOr16 (
3909 IN UINT16 Operand,
3910 IN UINTN StartBit,
3911 IN UINTN EndBit,
3912 IN UINT16 AndData,
3913 IN UINT16 OrData
3914 );
3915
3916
3917 /**
3918 Returns a bit field from a 32-bit value.
3919
3920 Returns the bitfield specified by the StartBit and the EndBit from Operand.
3921
3922 If 32-bit operations are not supported, then ASSERT().
3923 If StartBit is greater than 31, then ASSERT().
3924 If EndBit is greater than 31, then ASSERT().
3925 If EndBit is less than StartBit, then ASSERT().
3926
3927 @param Operand Operand on which to perform the bitfield operation.
3928 @param StartBit The ordinal of the least significant bit in the bit field.
3929 Range 0..31.
3930 @param EndBit The ordinal of the most significant bit in the bit field.
3931 Range 0..31.
3932
3933 @return The bit field read.
3934
3935 **/
3936 UINT32
3937 EFIAPI
3938 BitFieldRead32 (
3939 IN UINT32 Operand,
3940 IN UINTN StartBit,
3941 IN UINTN EndBit
3942 );
3943
3944
3945 /**
3946 Writes a bit field to a 32-bit value, and returns the result.
3947
3948 Writes Value to the bit field specified by the StartBit and the EndBit in
3949 Operand. All other bits in Operand are preserved. The new 32-bit value is
3950 returned.
3951
3952 If 32-bit operations are not supported, then ASSERT().
3953 If StartBit is greater than 31, then ASSERT().
3954 If EndBit is greater than 31, then ASSERT().
3955 If EndBit is less than StartBit, then ASSERT().
3956 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3957
3958 @param Operand Operand on which to perform the bitfield operation.
3959 @param StartBit The ordinal of the least significant bit in the bit field.
3960 Range 0..31.
3961 @param EndBit The ordinal of the most significant bit in the bit field.
3962 Range 0..31.
3963 @param Value New value of the bit field.
3964
3965 @return The new 32-bit value.
3966
3967 **/
3968 UINT32
3969 EFIAPI
3970 BitFieldWrite32 (
3971 IN UINT32 Operand,
3972 IN UINTN StartBit,
3973 IN UINTN EndBit,
3974 IN UINT32 Value
3975 );
3976
3977
3978 /**
3979 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
3980 result.
3981
3982 Performs a bitwise OR between the bit field specified by StartBit
3983 and EndBit in Operand and the value specified by OrData. All other bits in
3984 Operand are preserved. The new 32-bit value is returned.
3985
3986 If 32-bit operations are not supported, then ASSERT().
3987 If StartBit is greater than 31, then ASSERT().
3988 If EndBit is greater than 31, then ASSERT().
3989 If EndBit is less than StartBit, then ASSERT().
3990 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
3991
3992 @param Operand Operand on which to perform the bitfield operation.
3993 @param StartBit The ordinal of the least significant bit in the bit field.
3994 Range 0..31.
3995 @param EndBit The ordinal of the most significant bit in the bit field.
3996 Range 0..31.
3997 @param OrData The value to OR with the read value from the value.
3998
3999 @return The new 32-bit value.
4000
4001 **/
4002 UINT32
4003 EFIAPI
4004 BitFieldOr32 (
4005 IN UINT32 Operand,
4006 IN UINTN StartBit,
4007 IN UINTN EndBit,
4008 IN UINT32 OrData
4009 );
4010
4011
4012 /**
4013 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
4014 the result.
4015
4016 Performs a bitwise AND between the bit field specified by StartBit and EndBit
4017 in Operand and the value specified by AndData. All other bits in Operand are
4018 preserved. The new 32-bit value is returned.
4019
4020 If 32-bit operations are not supported, then ASSERT().
4021 If StartBit is greater than 31, then ASSERT().
4022 If EndBit is greater than 31, then ASSERT().
4023 If EndBit is less than StartBit, then ASSERT().
4024 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4025
4026 @param Operand Operand on which to perform the bitfield operation.
4027 @param StartBit The ordinal of the least significant bit in the bit field.
4028 Range 0..31.
4029 @param EndBit The ordinal of the most significant bit in the bit field.
4030 Range 0..31.
4031 @param AndData The value to AND with the read value from the value
4032
4033 @return The new 32-bit value.
4034
4035 **/
4036 UINT32
4037 EFIAPI
4038 BitFieldAnd32 (
4039 IN UINT32 Operand,
4040 IN UINTN StartBit,
4041 IN UINTN EndBit,
4042 IN UINT32 AndData
4043 );
4044
4045
4046 /**
4047 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
4048 bitwise OR, and returns the result.
4049
4050 Performs a bitwise AND between the bit field specified by StartBit and EndBit
4051 in Operand and the value specified by AndData, followed by a bitwise
4052 OR with value specified by OrData. All other bits in Operand are
4053 preserved. The new 32-bit value is returned.
4054
4055 If 32-bit operations are not supported, then ASSERT().
4056 If StartBit is greater than 31, then ASSERT().
4057 If EndBit is greater than 31, then ASSERT().
4058 If EndBit is less than StartBit, then ASSERT().
4059 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4060 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4061
4062 @param Operand Operand on which to perform the bitfield operation.
4063 @param StartBit The ordinal of the least significant bit in the bit field.
4064 Range 0..31.
4065 @param EndBit The ordinal of the most significant bit in the bit field.
4066 Range 0..31.
4067 @param AndData The value to AND with the read value from the value.
4068 @param OrData The value to OR with the result of the AND operation.
4069
4070 @return The new 32-bit value.
4071
4072 **/
4073 UINT32
4074 EFIAPI
4075 BitFieldAndThenOr32 (
4076 IN UINT32 Operand,
4077 IN UINTN StartBit,
4078 IN UINTN EndBit,
4079 IN UINT32 AndData,
4080 IN UINT32 OrData
4081 );
4082
4083
4084 /**
4085 Returns a bit field from a 64-bit value.
4086
4087 Returns the bitfield specified by the StartBit and the EndBit from Operand.
4088
4089 If 64-bit operations are not supported, then ASSERT().
4090 If StartBit is greater than 63, then ASSERT().
4091 If EndBit is greater than 63, then ASSERT().
4092 If EndBit is less than StartBit, then ASSERT().
4093
4094 @param Operand Operand on which to perform the bitfield operation.
4095 @param StartBit The ordinal of the least significant bit in the bit field.
4096 Range 0..63.
4097 @param EndBit The ordinal of the most significant bit in the bit field.
4098 Range 0..63.
4099
4100 @return The bit field read.
4101
4102 **/
4103 UINT64
4104 EFIAPI
4105 BitFieldRead64 (
4106 IN UINT64 Operand,
4107 IN UINTN StartBit,
4108 IN UINTN EndBit
4109 );
4110
4111
4112 /**
4113 Writes a bit field to a 64-bit value, and returns the result.
4114
4115 Writes Value to the bit field specified by the StartBit and the EndBit in
4116 Operand. All other bits in Operand are preserved. The new 64-bit value is
4117 returned.
4118
4119 If 64-bit operations are not supported, then ASSERT().
4120 If StartBit is greater than 63, then ASSERT().
4121 If EndBit is greater than 63, then ASSERT().
4122 If EndBit is less than StartBit, then ASSERT().
4123 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4124
4125 @param Operand Operand on which to perform the bitfield operation.
4126 @param StartBit The ordinal of the least significant bit in the bit field.
4127 Range 0..63.
4128 @param EndBit The ordinal of the most significant bit in the bit field.
4129 Range 0..63.
4130 @param Value New value of the bit field.
4131
4132 @return The new 64-bit value.
4133
4134 **/
4135 UINT64
4136 EFIAPI
4137 BitFieldWrite64 (
4138 IN UINT64 Operand,
4139 IN UINTN StartBit,
4140 IN UINTN EndBit,
4141 IN UINT64 Value
4142 );
4143
4144
4145 /**
4146 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
4147 result.
4148
4149 Performs a bitwise OR between the bit field specified by StartBit
4150 and EndBit in Operand and the value specified by OrData. All other bits in
4151 Operand are preserved. The new 64-bit value is returned.
4152
4153 If 64-bit operations are not supported, then ASSERT().
4154 If StartBit is greater than 63, then ASSERT().
4155 If EndBit is greater than 63, then ASSERT().
4156 If EndBit is less than StartBit, then ASSERT().
4157 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4158
4159 @param Operand Operand on which to perform the bitfield operation.
4160 @param StartBit The ordinal of the least significant bit in the bit field.
4161 Range 0..63.
4162 @param EndBit The ordinal of the most significant bit in the bit field.
4163 Range 0..63.
4164 @param OrData The value to OR with the read value from the value
4165
4166 @return The new 64-bit value.
4167
4168 **/
4169 UINT64
4170 EFIAPI
4171 BitFieldOr64 (
4172 IN UINT64 Operand,
4173 IN UINTN StartBit,
4174 IN UINTN EndBit,
4175 IN UINT64 OrData
4176 );
4177
4178
4179 /**
4180 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
4181 the result.
4182
4183 Performs a bitwise AND between the bit field specified by StartBit and EndBit
4184 in Operand and the value specified by AndData. All other bits in Operand are
4185 preserved. The new 64-bit value is returned.
4186
4187 If 64-bit operations are not supported, then ASSERT().
4188 If StartBit is greater than 63, then ASSERT().
4189 If EndBit is greater than 63, then ASSERT().
4190 If EndBit is less than StartBit, then ASSERT().
4191 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4192
4193 @param Operand Operand on which to perform the bitfield operation.
4194 @param StartBit The ordinal of the least significant bit in the bit field.
4195 Range 0..63.
4196 @param EndBit The ordinal of the most significant bit in the bit field.
4197 Range 0..63.
4198 @param AndData The value to AND with the read value from the value
4199
4200 @return The new 64-bit value.
4201
4202 **/
4203 UINT64
4204 EFIAPI
4205 BitFieldAnd64 (
4206 IN UINT64 Operand,
4207 IN UINTN StartBit,
4208 IN UINTN EndBit,
4209 IN UINT64 AndData
4210 );
4211
4212
4213 /**
4214 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
4215 bitwise OR, and returns the result.
4216
4217 Performs a bitwise AND between the bit field specified by StartBit and EndBit
4218 in Operand and the value specified by AndData, followed by a bitwise
4219 OR with value specified by OrData. All other bits in Operand are
4220 preserved. The new 64-bit value is returned.
4221
4222 If 64-bit operations are not supported, then ASSERT().
4223 If StartBit is greater than 63, then ASSERT().
4224 If EndBit is greater than 63, then ASSERT().
4225 If EndBit is less than StartBit, then ASSERT().
4226 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4227 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
4228
4229 @param Operand Operand on which to perform the bitfield operation.
4230 @param StartBit The ordinal of the least significant bit in the bit field.
4231 Range 0..63.
4232 @param EndBit The ordinal of the most significant bit in the bit field.
4233 Range 0..63.
4234 @param AndData The value to AND with the read value from the value.
4235 @param OrData The value to OR with the result of the AND operation.
4236
4237 @return The new 64-bit value.
4238
4239 **/
4240 UINT64
4241 EFIAPI
4242 BitFieldAndThenOr64 (
4243 IN UINT64 Operand,
4244 IN UINTN StartBit,
4245 IN UINTN EndBit,
4246 IN UINT64 AndData,
4247 IN UINT64 OrData
4248 );
4249
4250 /**
4251 Reads a bit field from a 32-bit value, counts and returns
4252 the number of set bits.
4253
4254 Counts the number of set bits in the bit field specified by
4255 StartBit and EndBit in Operand. The count is returned.
4256
4257 If StartBit is greater than 31, then ASSERT().
4258 If EndBit is greater than 31, then ASSERT().
4259 If EndBit is less than StartBit, then ASSERT().
4260
4261 @param Operand Operand on which to perform the bitfield operation.
4262 @param StartBit The ordinal of the least significant bit in the bit field.
4263 Range 0..31.
4264 @param EndBit The ordinal of the most significant bit in the bit field.
4265 Range 0..31.
4266
4267 @return The number of bits set between StartBit and EndBit.
4268
4269 **/
4270 UINT8
4271 EFIAPI
4272 BitFieldCountOnes32 (
4273 IN UINT32 Operand,
4274 IN UINTN StartBit,
4275 IN UINTN EndBit
4276 );
4277
4278 /**
4279 Reads a bit field from a 64-bit value, counts and returns
4280 the number of set bits.
4281
4282 Counts the number of set bits in the bit field specified by
4283 StartBit and EndBit in Operand. The count is returned.
4284
4285 If StartBit is greater than 63, then ASSERT().
4286 If EndBit is greater than 63, then ASSERT().
4287 If EndBit is less than StartBit, then ASSERT().
4288
4289 @param Operand Operand on which to perform the bitfield operation.
4290 @param StartBit The ordinal of the least significant bit in the bit field.
4291 Range 0..63.
4292 @param EndBit The ordinal of the most significant bit in the bit field.
4293 Range 0..63.
4294
4295 @return The number of bits set between StartBit and EndBit.
4296
4297 **/
4298 UINT8
4299 EFIAPI
4300 BitFieldCountOnes64 (
4301 IN UINT64 Operand,
4302 IN UINTN StartBit,
4303 IN UINTN EndBit
4304 );
4305
4306 //
4307 // Base Library Checksum Functions
4308 //
4309
4310 /**
4311 Returns the sum of all elements in a buffer in unit of UINT8.
4312 During calculation, the carry bits are dropped.
4313
4314 This function calculates the sum of all elements in a buffer
4315 in unit of UINT8. The carry bits in result of addition are dropped.
4316 The result is returned as UINT8. If Length is Zero, then Zero is
4317 returned.
4318
4319 If Buffer is NULL, then ASSERT().
4320 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4321
4322 @param Buffer The pointer to the buffer to carry out the sum operation.
4323 @param Length The size, in bytes, of Buffer.
4324
4325 @return Sum The sum of Buffer with carry bits dropped during additions.
4326
4327 **/
4328 UINT8
4329 EFIAPI
4330 CalculateSum8 (
4331 IN CONST UINT8 *Buffer,
4332 IN UINTN Length
4333 );
4334
4335
4336 /**
4337 Returns the two's complement checksum of all elements in a buffer
4338 of 8-bit values.
4339
4340 This function first calculates the sum of the 8-bit values in the
4341 buffer specified by Buffer and Length. The carry bits in the result
4342 of addition are dropped. Then, the two's complement of the sum is
4343 returned. If Length is 0, then 0 is returned.
4344
4345 If Buffer is NULL, then ASSERT().
4346 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4347
4348 @param Buffer The pointer to the buffer to carry out the checksum operation.
4349 @param Length The size, in bytes, of Buffer.
4350
4351 @return Checksum The two's complement checksum of Buffer.
4352
4353 **/
4354 UINT8
4355 EFIAPI
4356 CalculateCheckSum8 (
4357 IN CONST UINT8 *Buffer,
4358 IN UINTN Length
4359 );
4360
4361
4362 /**
4363 Returns the sum of all elements in a buffer of 16-bit values. During
4364 calculation, the carry bits are dropped.
4365
4366 This function calculates the sum of the 16-bit values in the buffer
4367 specified by Buffer and Length. The carry bits in result of addition are dropped.
4368 The 16-bit result is returned. If Length is 0, then 0 is returned.
4369
4370 If Buffer is NULL, then ASSERT().
4371 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
4372 If Length is not aligned on a 16-bit boundary, then ASSERT().
4373 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4374
4375 @param Buffer The pointer to the buffer to carry out the sum operation.
4376 @param Length The size, in bytes, of Buffer.
4377
4378 @return Sum The sum of Buffer with carry bits dropped during additions.
4379
4380 **/
4381 UINT16
4382 EFIAPI
4383 CalculateSum16 (
4384 IN CONST UINT16 *Buffer,
4385 IN UINTN Length
4386 );
4387
4388
4389 /**
4390 Returns the two's complement checksum of all elements in a buffer of
4391 16-bit values.
4392
4393 This function first calculates the sum of the 16-bit values in the buffer
4394 specified by Buffer and Length. The carry bits in the result of addition
4395 are dropped. Then, the two's complement of the sum is returned. If Length
4396 is 0, then 0 is returned.
4397
4398 If Buffer is NULL, then ASSERT().
4399 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
4400 If Length is not aligned on a 16-bit boundary, then ASSERT().
4401 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4402
4403 @param Buffer The pointer to the buffer to carry out the checksum operation.
4404 @param Length The size, in bytes, of Buffer.
4405
4406 @return Checksum The two's complement checksum of Buffer.
4407
4408 **/
4409 UINT16
4410 EFIAPI
4411 CalculateCheckSum16 (
4412 IN CONST UINT16 *Buffer,
4413 IN UINTN Length
4414 );
4415
4416
4417 /**
4418 Returns the sum of all elements in a buffer of 32-bit values. During
4419 calculation, the carry bits are dropped.
4420
4421 This function calculates the sum of the 32-bit values in the buffer
4422 specified by Buffer and Length. The carry bits in result of addition are dropped.
4423 The 32-bit result is returned. If Length is 0, then 0 is returned.
4424
4425 If Buffer is NULL, then ASSERT().
4426 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
4427 If Length is not aligned on a 32-bit boundary, then ASSERT().
4428 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4429
4430 @param Buffer The pointer to the buffer to carry out the sum operation.
4431 @param Length The size, in bytes, of Buffer.
4432
4433 @return Sum The sum of Buffer with carry bits dropped during additions.
4434
4435 **/
4436 UINT32
4437 EFIAPI
4438 CalculateSum32 (
4439 IN CONST UINT32 *Buffer,
4440 IN UINTN Length
4441 );
4442
4443
4444 /**
4445 Returns the two's complement checksum of all elements in a buffer of
4446 32-bit values.
4447
4448 This function first calculates the sum of the 32-bit values in the buffer
4449 specified by Buffer and Length. The carry bits in the result of addition
4450 are dropped. Then, the two's complement of the sum is returned. If Length
4451 is 0, then 0 is returned.
4452
4453 If Buffer is NULL, then ASSERT().
4454 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
4455 If Length is not aligned on a 32-bit boundary, then ASSERT().
4456 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4457
4458 @param Buffer The pointer to the buffer to carry out the checksum operation.
4459 @param Length The size, in bytes, of Buffer.
4460
4461 @return Checksum The two's complement checksum of Buffer.
4462
4463 **/
4464 UINT32
4465 EFIAPI
4466 CalculateCheckSum32 (
4467 IN CONST UINT32 *Buffer,
4468 IN UINTN Length
4469 );
4470
4471
4472 /**
4473 Returns the sum of all elements in a buffer of 64-bit values. During
4474 calculation, the carry bits are dropped.
4475
4476 This function calculates the sum of the 64-bit values in the buffer
4477 specified by Buffer and Length. The carry bits in result of addition are dropped.
4478 The 64-bit result is returned. If Length is 0, then 0 is returned.
4479
4480 If Buffer is NULL, then ASSERT().
4481 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
4482 If Length is not aligned on a 64-bit boundary, then ASSERT().
4483 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4484
4485 @param Buffer The pointer to the buffer to carry out the sum operation.
4486 @param Length The size, in bytes, of Buffer.
4487
4488 @return Sum The sum of Buffer with carry bits dropped during additions.
4489
4490 **/
4491 UINT64
4492 EFIAPI
4493 CalculateSum64 (
4494 IN CONST UINT64 *Buffer,
4495 IN UINTN Length
4496 );
4497
4498
4499 /**
4500 Returns the two's complement checksum of all elements in a buffer of
4501 64-bit values.
4502
4503 This function first calculates the sum of the 64-bit values in the buffer
4504 specified by Buffer and Length. The carry bits in the result of addition
4505 are dropped. Then, the two's complement of the sum is returned. If Length
4506 is 0, then 0 is returned.
4507
4508 If Buffer is NULL, then ASSERT().
4509 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
4510 If Length is not aligned on a 64-bit boundary, then ASSERT().
4511 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4512
4513 @param Buffer The pointer to the buffer to carry out the checksum operation.
4514 @param Length The size, in bytes, of Buffer.
4515
4516 @return Checksum The two's complement checksum of Buffer.
4517
4518 **/
4519 UINT64
4520 EFIAPI
4521 CalculateCheckSum64 (
4522 IN CONST UINT64 *Buffer,
4523 IN UINTN Length
4524 );
4525
4526 /**
4527 Computes and returns a 32-bit CRC for a data buffer.
4528 CRC32 value bases on ITU-T V.42.
4529
4530 If Buffer is NULL, then ASSERT().
4531 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
4532
4533 @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed.
4534 @param[in] Length The number of bytes in the buffer Data.
4535
4536 @retval Crc32 The 32-bit CRC was computed for the data buffer.
4537
4538 **/
4539 UINT32
4540 EFIAPI
4541 CalculateCrc32(
4542 IN VOID *Buffer,
4543 IN UINTN Length
4544 );
4545
4546 //
4547 // Base Library CPU Functions
4548 //
4549
4550 /**
4551 Function entry point used when a stack switch is requested with SwitchStack()
4552
4553 @param Context1 Context1 parameter passed into SwitchStack().
4554 @param Context2 Context2 parameter passed into SwitchStack().
4555
4556 **/
4557 typedef
4558 VOID
4559 (EFIAPI *SWITCH_STACK_ENTRY_POINT)(
4560 IN VOID *Context1, OPTIONAL
4561 IN VOID *Context2 OPTIONAL
4562 );
4563
4564
4565 /**
4566 Used to serialize load and store operations.
4567
4568 All loads and stores that proceed calls to this function are guaranteed to be
4569 globally visible when this function returns.
4570
4571 **/
4572 VOID
4573 EFIAPI
4574 MemoryFence (
4575 VOID
4576 );
4577
4578
4579 /**
4580 Saves the current CPU context that can be restored with a call to LongJump()
4581 and returns 0.
4582
4583 Saves the current CPU context in the buffer specified by JumpBuffer and
4584 returns 0. The initial call to SetJump() must always return 0. Subsequent
4585 calls to LongJump() cause a non-zero value to be returned by SetJump().
4586
4587 If JumpBuffer is NULL, then ASSERT().
4588 For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
4589
4590 NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.
4591 The same structure must never be used for more than one CPU architecture context.
4592 For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module.
4593 SetJump()/LongJump() is not currently supported for the EBC processor type.
4594
4595 @param JumpBuffer A pointer to CPU context buffer.
4596
4597 @retval 0 Indicates a return from SetJump().
4598
4599 **/
4600 RETURNS_TWICE
4601 UINTN
4602 EFIAPI
4603 SetJump (
4604 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
4605 );
4606
4607
4608 /**
4609 Restores the CPU context that was saved with SetJump().
4610
4611 Restores the CPU context from the buffer specified by JumpBuffer. This
4612 function never returns to the caller. Instead is resumes execution based on
4613 the state of JumpBuffer.
4614
4615 If JumpBuffer is NULL, then ASSERT().
4616 For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
4617 If Value is 0, then ASSERT().
4618
4619 @param JumpBuffer A pointer to CPU context buffer.
4620 @param Value The value to return when the SetJump() context is
4621 restored and must be non-zero.
4622
4623 **/
4624 VOID
4625 EFIAPI
4626 LongJump (
4627 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
4628 IN UINTN Value
4629 );
4630
4631
4632 /**
4633 Enables CPU interrupts.
4634
4635 **/
4636 VOID
4637 EFIAPI
4638 EnableInterrupts (
4639 VOID
4640 );
4641
4642
4643 /**
4644 Disables CPU interrupts.
4645
4646 **/
4647 VOID
4648 EFIAPI
4649 DisableInterrupts (
4650 VOID
4651 );
4652
4653
4654 /**
4655 Disables CPU interrupts and returns the interrupt state prior to the disable
4656 operation.
4657
4658 @retval TRUE CPU interrupts were enabled on entry to this call.
4659 @retval FALSE CPU interrupts were disabled on entry to this call.
4660
4661 **/
4662 BOOLEAN
4663 EFIAPI
4664 SaveAndDisableInterrupts (
4665 VOID
4666 );
4667
4668
4669 /**
4670 Enables CPU interrupts for the smallest window required to capture any
4671 pending interrupts.
4672
4673 **/
4674 VOID
4675 EFIAPI
4676 EnableDisableInterrupts (
4677 VOID
4678 );
4679
4680
4681 /**
4682 Retrieves the current CPU interrupt state.
4683
4684 Returns TRUE if interrupts are currently enabled. Otherwise
4685 returns FALSE.
4686
4687 @retval TRUE CPU interrupts are enabled.
4688 @retval FALSE CPU interrupts are disabled.
4689
4690 **/
4691 BOOLEAN
4692 EFIAPI
4693 GetInterruptState (
4694 VOID
4695 );
4696
4697
4698 /**
4699 Set the current CPU interrupt state.
4700
4701 Sets the current CPU interrupt state to the state specified by
4702 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
4703 InterruptState is FALSE, then interrupts are disabled. InterruptState is
4704 returned.
4705
4706 @param InterruptState TRUE if interrupts should enabled. FALSE if
4707 interrupts should be disabled.
4708
4709 @return InterruptState
4710
4711 **/
4712 BOOLEAN
4713 EFIAPI
4714 SetInterruptState (
4715 IN BOOLEAN InterruptState
4716 );
4717
4718
4719 /**
4720 Requests CPU to pause for a short period of time.
4721
4722 Requests CPU to pause for a short period of time. Typically used in MP
4723 systems to prevent memory starvation while waiting for a spin lock.
4724
4725 **/
4726 VOID
4727 EFIAPI
4728 CpuPause (
4729 VOID
4730 );
4731
4732
4733 /**
4734 Transfers control to a function starting with a new stack.
4735
4736 Transfers control to the function specified by EntryPoint using the
4737 new stack specified by NewStack and passing in the parameters specified
4738 by Context1 and Context2. Context1 and Context2 are optional and may
4739 be NULL. The function EntryPoint must never return. This function
4740 supports a variable number of arguments following the NewStack parameter.
4741 These additional arguments are ignored on IA-32, x64, and EBC architectures.
4742 Itanium processors expect one additional parameter of type VOID * that specifies
4743 the new backing store pointer.
4744
4745 If EntryPoint is NULL, then ASSERT().
4746 If NewStack is NULL, then ASSERT().
4747
4748 @param EntryPoint A pointer to function to call with the new stack.
4749 @param Context1 A pointer to the context to pass into the EntryPoint
4750 function.
4751 @param Context2 A pointer to the context to pass into the EntryPoint
4752 function.
4753 @param NewStack A pointer to the new stack to use for the EntryPoint
4754 function.
4755 @param ... This variable argument list is ignored for IA-32, x64, and
4756 EBC architectures. For Itanium processors, this variable
4757 argument list is expected to contain a single parameter of
4758 type VOID * that specifies the new backing store pointer.
4759
4760
4761 **/
4762 VOID
4763 EFIAPI
4764 SwitchStack (
4765 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
4766 IN VOID *Context1, OPTIONAL
4767 IN VOID *Context2, OPTIONAL
4768 IN VOID *NewStack,
4769 ...
4770 );
4771
4772
4773 /**
4774 Generates a breakpoint on the CPU.
4775
4776 Generates a breakpoint on the CPU. The breakpoint must be implemented such
4777 that code can resume normal execution after the breakpoint.
4778
4779 **/
4780 VOID
4781 EFIAPI
4782 CpuBreakpoint (
4783 VOID
4784 );
4785
4786
4787 /**
4788 Executes an infinite loop.
4789
4790 Forces the CPU to execute an infinite loop. A debugger may be used to skip
4791 past the loop and the code that follows the loop must execute properly. This
4792 implies that the infinite loop must not cause the code that follow it to be
4793 optimized away.
4794
4795 **/
4796 VOID
4797 EFIAPI
4798 CpuDeadLoop (
4799 VOID
4800 );
4801
4802
4803 /**
4804 Uses as a barrier to stop speculative execution.
4805
4806 Ensures that no later instruction will execute speculatively, until all prior
4807 instructions have completed.
4808
4809 **/
4810 VOID
4811 EFIAPI
4812 SpeculationBarrier (
4813 VOID
4814 );
4815
4816
4817 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
4818 ///
4819 /// IA32 and x64 Specific Functions.
4820 /// Byte packed structure for 16-bit Real Mode EFLAGS.
4821 ///
4822 typedef union {
4823 struct {
4824 UINT32 CF:1; ///< Carry Flag.
4825 UINT32 Reserved_0:1; ///< Reserved.
4826 UINT32 PF:1; ///< Parity Flag.
4827 UINT32 Reserved_1:1; ///< Reserved.
4828 UINT32 AF:1; ///< Auxiliary Carry Flag.
4829 UINT32 Reserved_2:1; ///< Reserved.
4830 UINT32 ZF:1; ///< Zero Flag.
4831 UINT32 SF:1; ///< Sign Flag.
4832 UINT32 TF:1; ///< Trap Flag.
4833 UINT32 IF:1; ///< Interrupt Enable Flag.
4834 UINT32 DF:1; ///< Direction Flag.
4835 UINT32 OF:1; ///< Overflow Flag.
4836 UINT32 IOPL:2; ///< I/O Privilege Level.
4837 UINT32 NT:1; ///< Nested Task.
4838 UINT32 Reserved_3:1; ///< Reserved.
4839 } Bits;
4840 UINT16 Uint16;
4841 } IA32_FLAGS16;
4842
4843 ///
4844 /// Byte packed structure for EFLAGS/RFLAGS.
4845 /// 32-bits on IA-32.
4846 /// 64-bits on x64. The upper 32-bits on x64 are reserved.
4847 ///
4848 typedef union {
4849 struct {
4850 UINT32 CF:1; ///< Carry Flag.
4851 UINT32 Reserved_0:1; ///< Reserved.
4852 UINT32 PF:1; ///< Parity Flag.
4853 UINT32 Reserved_1:1; ///< Reserved.
4854 UINT32 AF:1; ///< Auxiliary Carry Flag.
4855 UINT32 Reserved_2:1; ///< Reserved.
4856 UINT32 ZF:1; ///< Zero Flag.
4857 UINT32 SF:1; ///< Sign Flag.
4858 UINT32 TF:1; ///< Trap Flag.
4859 UINT32 IF:1; ///< Interrupt Enable Flag.
4860 UINT32 DF:1; ///< Direction Flag.
4861 UINT32 OF:1; ///< Overflow Flag.
4862 UINT32 IOPL:2; ///< I/O Privilege Level.
4863 UINT32 NT:1; ///< Nested Task.
4864 UINT32 Reserved_3:1; ///< Reserved.
4865 UINT32 RF:1; ///< Resume Flag.
4866 UINT32 VM:1; ///< Virtual 8086 Mode.
4867 UINT32 AC:1; ///< Alignment Check.
4868 UINT32 VIF:1; ///< Virtual Interrupt Flag.
4869 UINT32 VIP:1; ///< Virtual Interrupt Pending.
4870 UINT32 ID:1; ///< ID Flag.
4871 UINT32 Reserved_4:10; ///< Reserved.
4872 } Bits;
4873 UINTN UintN;
4874 } IA32_EFLAGS32;
4875
4876 ///
4877 /// Byte packed structure for Control Register 0 (CR0).
4878 /// 32-bits on IA-32.
4879 /// 64-bits on x64. The upper 32-bits on x64 are reserved.
4880 ///
4881 typedef union {
4882 struct {
4883 UINT32 PE:1; ///< Protection Enable.
4884 UINT32 MP:1; ///< Monitor Coprocessor.
4885 UINT32 EM:1; ///< Emulation.
4886 UINT32 TS:1; ///< Task Switched.
4887 UINT32 ET:1; ///< Extension Type.
4888 UINT32 NE:1; ///< Numeric Error.
4889 UINT32 Reserved_0:10; ///< Reserved.
4890 UINT32 WP:1; ///< Write Protect.
4891 UINT32 Reserved_1:1; ///< Reserved.
4892 UINT32 AM:1; ///< Alignment Mask.
4893 UINT32 Reserved_2:10; ///< Reserved.
4894 UINT32 NW:1; ///< Mot Write-through.
4895 UINT32 CD:1; ///< Cache Disable.
4896 UINT32 PG:1; ///< Paging.
4897 } Bits;
4898 UINTN UintN;
4899 } IA32_CR0;
4900
4901 ///
4902 /// Byte packed structure for Control Register 4 (CR4).
4903 /// 32-bits on IA-32.
4904 /// 64-bits on x64. The upper 32-bits on x64 are reserved.
4905 ///
4906 typedef union {
4907 struct {
4908 UINT32 VME:1; ///< Virtual-8086 Mode Extensions.
4909 UINT32 PVI:1; ///< Protected-Mode Virtual Interrupts.
4910 UINT32 TSD:1; ///< Time Stamp Disable.
4911 UINT32 DE:1; ///< Debugging Extensions.
4912 UINT32 PSE:1; ///< Page Size Extensions.
4913 UINT32 PAE:1; ///< Physical Address Extension.
4914 UINT32 MCE:1; ///< Machine Check Enable.
4915 UINT32 PGE:1; ///< Page Global Enable.
4916 UINT32 PCE:1; ///< Performance Monitoring Counter
4917 ///< Enable.
4918 UINT32 OSFXSR:1; ///< Operating System Support for
4919 ///< FXSAVE and FXRSTOR instructions
4920 UINT32 OSXMMEXCPT:1; ///< Operating System Support for
4921 ///< Unmasked SIMD Floating Point
4922 ///< Exceptions.
4923 UINT32 UMIP:1; ///< User-Mode Instruction Prevention.
4924 UINT32 LA57:1; ///< Linear Address 57bit.
4925 UINT32 VMXE:1; ///< VMX Enable.
4926 UINT32 SMXE:1; ///< SMX Enable.
4927 UINT32 Reserved_3:1; ///< Reserved.
4928 UINT32 FSGSBASE:1; ///< FSGSBASE Enable.
4929 UINT32 PCIDE:1; ///< PCID Enable.
4930 UINT32 OSXSAVE:1; ///< XSAVE and Processor Extended States Enable.
4931 UINT32 Reserved_4:1; ///< Reserved.
4932 UINT32 SMEP:1; ///< SMEP Enable.
4933 UINT32 SMAP:1; ///< SMAP Enable.
4934 UINT32 PKE:1; ///< Protection-Key Enable.
4935 UINT32 Reserved_5:9; ///< Reserved.
4936 } Bits;
4937 UINTN UintN;
4938 } IA32_CR4;
4939
4940 ///
4941 /// Byte packed structure for a segment descriptor in a GDT/LDT.
4942 ///
4943 typedef union {
4944 struct {
4945 UINT32 LimitLow:16;
4946 UINT32 BaseLow:16;
4947 UINT32 BaseMid:8;
4948 UINT32 Type:4;
4949 UINT32 S:1;
4950 UINT32 DPL:2;
4951 UINT32 P:1;
4952 UINT32 LimitHigh:4;
4953 UINT32 AVL:1;
4954 UINT32 L:1;
4955 UINT32 DB:1;
4956 UINT32 G:1;
4957 UINT32 BaseHigh:8;
4958 } Bits;
4959 UINT64 Uint64;
4960 } IA32_SEGMENT_DESCRIPTOR;
4961
4962 ///
4963 /// Byte packed structure for an IDTR, GDTR, LDTR descriptor.
4964 ///
4965 #pragma pack (1)
4966 typedef struct {
4967 UINT16 Limit;
4968 UINTN Base;
4969 } IA32_DESCRIPTOR;
4970 #pragma pack ()
4971
4972 #define IA32_IDT_GATE_TYPE_TASK 0x85
4973 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
4974 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
4975 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
4976 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
4977
4978 #define IA32_GDT_TYPE_TSS 0x9
4979 #define IA32_GDT_ALIGNMENT 8
4980
4981 #if defined (MDE_CPU_IA32)
4982 ///
4983 /// Byte packed structure for an IA-32 Interrupt Gate Descriptor.
4984 ///
4985 typedef union {
4986 struct {
4987 UINT32 OffsetLow:16; ///< Offset bits 15..0.
4988 UINT32 Selector:16; ///< Selector.
4989 UINT32 Reserved_0:8; ///< Reserved.
4990 UINT32 GateType:8; ///< Gate Type. See #defines above.
4991 UINT32 OffsetHigh:16; ///< Offset bits 31..16.
4992 } Bits;
4993 UINT64 Uint64;
4994 } IA32_IDT_GATE_DESCRIPTOR;
4995
4996 #pragma pack (1)
4997 //
4998 // IA32 Task-State Segment Definition
4999 //
5000 typedef struct {
5001 UINT16 PreviousTaskLink;
5002 UINT16 Reserved_2;
5003 UINT32 ESP0;
5004 UINT16 SS0;
5005 UINT16 Reserved_10;
5006 UINT32 ESP1;
5007 UINT16 SS1;
5008 UINT16 Reserved_18;
5009 UINT32 ESP2;
5010 UINT16 SS2;
5011 UINT16 Reserved_26;
5012 UINT32 CR3;
5013 UINT32 EIP;
5014 UINT32 EFLAGS;
5015 UINT32 EAX;
5016 UINT32 ECX;
5017 UINT32 EDX;
5018 UINT32 EBX;
5019 UINT32 ESP;
5020 UINT32 EBP;
5021 UINT32 ESI;
5022 UINT32 EDI;
5023 UINT16 ES;
5024 UINT16 Reserved_74;
5025 UINT16 CS;
5026 UINT16 Reserved_78;
5027 UINT16 SS;
5028 UINT16 Reserved_82;
5029 UINT16 DS;
5030 UINT16 Reserved_86;
5031 UINT16 FS;
5032 UINT16 Reserved_90;
5033 UINT16 GS;
5034 UINT16 Reserved_94;
5035 UINT16 LDTSegmentSelector;
5036 UINT16 Reserved_98;
5037 UINT16 T;
5038 UINT16 IOMapBaseAddress;
5039 } IA32_TASK_STATE_SEGMENT;
5040
5041 typedef union {
5042 struct {
5043 UINT32 LimitLow:16; ///< Segment Limit 15..00
5044 UINT32 BaseLow:16; ///< Base Address 15..00
5045 UINT32 BaseMid:8; ///< Base Address 23..16
5046 UINT32 Type:4; ///< Type (1 0 B 1)
5047 UINT32 Reserved_43:1; ///< 0
5048 UINT32 DPL:2; ///< Descriptor Privilege Level
5049 UINT32 P:1; ///< Segment Present
5050 UINT32 LimitHigh:4; ///< Segment Limit 19..16
5051 UINT32 AVL:1; ///< Available for use by system software
5052 UINT32 Reserved_52:2; ///< 0 0
5053 UINT32 G:1; ///< Granularity
5054 UINT32 BaseHigh:8; ///< Base Address 31..24
5055 } Bits;
5056 UINT64 Uint64;
5057 } IA32_TSS_DESCRIPTOR;
5058 #pragma pack ()
5059
5060 #endif // defined (MDE_CPU_IA32)
5061
5062 #if defined (MDE_CPU_X64)
5063 ///
5064 /// Byte packed structure for an x64 Interrupt Gate Descriptor.
5065 ///
5066 typedef union {
5067 struct {
5068 UINT32 OffsetLow:16; ///< Offset bits 15..0.
5069 UINT32 Selector:16; ///< Selector.
5070 UINT32 Reserved_0:8; ///< Reserved.
5071 UINT32 GateType:8; ///< Gate Type. See #defines above.
5072 UINT32 OffsetHigh:16; ///< Offset bits 31..16.
5073 UINT32 OffsetUpper:32; ///< Offset bits 63..32.
5074 UINT32 Reserved_1:32; ///< Reserved.
5075 } Bits;
5076 struct {
5077 UINT64 Uint64;
5078 UINT64 Uint64_1;
5079 } Uint128;
5080 } IA32_IDT_GATE_DESCRIPTOR;
5081
5082 #pragma pack (1)
5083 //
5084 // IA32 Task-State Segment Definition
5085 //
5086 typedef struct {
5087 UINT32 Reserved_0;
5088 UINT64 RSP0;
5089 UINT64 RSP1;
5090 UINT64 RSP2;
5091 UINT64 Reserved_28;
5092 UINT64 IST[7];
5093 UINT64 Reserved_92;
5094 UINT16 Reserved_100;
5095 UINT16 IOMapBaseAddress;
5096 } IA32_TASK_STATE_SEGMENT;
5097
5098 typedef union {
5099 struct {
5100 UINT32 LimitLow:16; ///< Segment Limit 15..00
5101 UINT32 BaseLow:16; ///< Base Address 15..00
5102 UINT32 BaseMidl:8; ///< Base Address 23..16
5103 UINT32 Type:4; ///< Type (1 0 B 1)
5104 UINT32 Reserved_43:1; ///< 0
5105 UINT32 DPL:2; ///< Descriptor Privilege Level
5106 UINT32 P:1; ///< Segment Present
5107 UINT32 LimitHigh:4; ///< Segment Limit 19..16
5108 UINT32 AVL:1; ///< Available for use by system software
5109 UINT32 Reserved_52:2; ///< 0 0
5110 UINT32 G:1; ///< Granularity
5111 UINT32 BaseMidh:8; ///< Base Address 31..24
5112 UINT32 BaseHigh:32; ///< Base Address 63..32
5113 UINT32 Reserved_96:32; ///< Reserved
5114 } Bits;
5115 struct {
5116 UINT64 Uint64;
5117 UINT64 Uint64_1;
5118 } Uint128;
5119 } IA32_TSS_DESCRIPTOR;
5120 #pragma pack ()
5121
5122 #endif // defined (MDE_CPU_X64)
5123
5124 ///
5125 /// Byte packed structure for an FP/SSE/SSE2 context.
5126 ///
5127 typedef struct {
5128 UINT8 Buffer[512];
5129 } IA32_FX_BUFFER;
5130
5131 ///
5132 /// Structures for the 16-bit real mode thunks.
5133 ///
5134 typedef struct {
5135 UINT32 Reserved1;
5136 UINT32 Reserved2;
5137 UINT32 Reserved3;
5138 UINT32 Reserved4;
5139 UINT8 BL;
5140 UINT8 BH;
5141 UINT16 Reserved5;
5142 UINT8 DL;
5143 UINT8 DH;
5144 UINT16 Reserved6;
5145 UINT8 CL;
5146 UINT8 CH;
5147 UINT16 Reserved7;
5148 UINT8 AL;
5149 UINT8 AH;
5150 UINT16 Reserved8;
5151 } IA32_BYTE_REGS;
5152
5153 typedef struct {
5154 UINT16 DI;
5155 UINT16 Reserved1;
5156 UINT16 SI;
5157 UINT16 Reserved2;
5158 UINT16 BP;
5159 UINT16 Reserved3;
5160 UINT16 SP;
5161 UINT16 Reserved4;
5162 UINT16 BX;
5163 UINT16 Reserved5;
5164 UINT16 DX;
5165 UINT16 Reserved6;
5166 UINT16 CX;
5167 UINT16 Reserved7;
5168 UINT16 AX;
5169 UINT16 Reserved8;
5170 } IA32_WORD_REGS;
5171
5172 typedef struct {
5173 UINT32 EDI;
5174 UINT32 ESI;
5175 UINT32 EBP;
5176 UINT32 ESP;
5177 UINT32 EBX;
5178 UINT32 EDX;
5179 UINT32 ECX;
5180 UINT32 EAX;
5181 UINT16 DS;
5182 UINT16 ES;
5183 UINT16 FS;
5184 UINT16 GS;
5185 IA32_EFLAGS32 EFLAGS;
5186 UINT32 Eip;
5187 UINT16 CS;
5188 UINT16 SS;
5189 } IA32_DWORD_REGS;
5190
5191 typedef union {
5192 IA32_DWORD_REGS E;
5193 IA32_WORD_REGS X;
5194 IA32_BYTE_REGS H;
5195 } IA32_REGISTER_SET;
5196
5197 ///
5198 /// Byte packed structure for an 16-bit real mode thunks.
5199 ///
5200 typedef struct {
5201 IA32_REGISTER_SET *RealModeState;
5202 VOID *RealModeBuffer;
5203 UINT32 RealModeBufferSize;
5204 UINT32 ThunkAttributes;
5205 } THUNK_CONTEXT;
5206
5207 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
5208 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
5209 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
5210
5211 ///
5212 /// Type definition for representing labels in NASM source code that allow for
5213 /// the patching of immediate operands of IA32 and X64 instructions.
5214 ///
5215 /// While the type is technically defined as a function type (note: not a
5216 /// pointer-to-function type), such labels in NASM source code never stand for
5217 /// actual functions, and identifiers declared with this function type should
5218 /// never be called. This is also why the EFIAPI calling convention specifier
5219 /// is missing from the typedef, and why the typedef does not follow the usual
5220 /// edk2 coding style for function (or pointer-to-function) typedefs. The VOID
5221 /// return type and the VOID argument list are merely artifacts.
5222 ///
5223 typedef VOID (X86_ASSEMBLY_PATCH_LABEL) (VOID);
5224
5225 /**
5226 Retrieves CPUID information.
5227
5228 Executes the CPUID instruction with EAX set to the value specified by Index.
5229 This function always returns Index.
5230 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5231 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5232 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5233 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5234 This function is only available on IA-32 and x64.
5235
5236 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
5237 instruction.
5238 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
5239 instruction. This is an optional parameter that may be NULL.
5240 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
5241 instruction. This is an optional parameter that may be NULL.
5242 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
5243 instruction. This is an optional parameter that may be NULL.
5244 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
5245 instruction. This is an optional parameter that may be NULL.
5246
5247 @return Index.
5248
5249 **/
5250 UINT32
5251 EFIAPI
5252 AsmCpuid (
5253 IN UINT32 Index,
5254 OUT UINT32 *Eax, OPTIONAL
5255 OUT UINT32 *Ebx, OPTIONAL
5256 OUT UINT32 *Ecx, OPTIONAL
5257 OUT UINT32 *Edx OPTIONAL
5258 );
5259
5260
5261 /**
5262 Retrieves CPUID information using an extended leaf identifier.
5263
5264 Executes the CPUID instruction with EAX set to the value specified by Index
5265 and ECX set to the value specified by SubIndex. This function always returns
5266 Index. This function is only available on IA-32 and x64.
5267
5268 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
5269 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
5270 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
5271 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
5272
5273 @param Index The 32-bit value to load into EAX prior to invoking the
5274 CPUID instruction.
5275 @param SubIndex The 32-bit value to load into ECX prior to invoking the
5276 CPUID instruction.
5277 @param Eax The pointer to the 32-bit EAX value returned by the CPUID
5278 instruction. This is an optional parameter that may be
5279 NULL.
5280 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID
5281 instruction. This is an optional parameter that may be
5282 NULL.
5283 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID
5284 instruction. This is an optional parameter that may be
5285 NULL.
5286 @param Edx The pointer to the 32-bit EDX value returned by the CPUID
5287 instruction. This is an optional parameter that may be
5288 NULL.
5289
5290 @return Index.
5291
5292 **/
5293 UINT32
5294 EFIAPI
5295 AsmCpuidEx (
5296 IN UINT32 Index,
5297 IN UINT32 SubIndex,
5298 OUT UINT32 *Eax, OPTIONAL
5299 OUT UINT32 *Ebx, OPTIONAL
5300 OUT UINT32 *Ecx, OPTIONAL
5301 OUT UINT32 *Edx OPTIONAL
5302 );
5303
5304
5305 /**
5306 Set CD bit and clear NW bit of CR0 followed by a WBINVD.
5307
5308 Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,
5309 and executing a WBINVD instruction. This function is only available on IA-32 and x64.
5310
5311 **/
5312 VOID
5313 EFIAPI
5314 AsmDisableCache (
5315 VOID
5316 );
5317
5318
5319 /**
5320 Perform a WBINVD and clear both the CD and NW bits of CR0.
5321
5322 Enables the caches by executing a WBINVD instruction and then clear both the CD and NW
5323 bits of CR0 to 0. This function is only available on IA-32 and x64.
5324
5325 **/
5326 VOID
5327 EFIAPI
5328 AsmEnableCache (
5329 VOID
5330 );
5331
5332
5333 /**
5334 Returns the lower 32-bits of a Machine Specific Register(MSR).
5335
5336 Reads and returns the lower 32-bits of the MSR specified by Index.
5337 No parameter checking is performed on Index, and some Index values may cause
5338 CPU exceptions. The caller must either guarantee that Index is valid, or the
5339 caller must set up exception handlers to catch the exceptions. This function
5340 is only available on IA-32 and x64.
5341
5342 @param Index The 32-bit MSR index to read.
5343
5344 @return The lower 32 bits of the MSR identified by Index.
5345
5346 **/
5347 UINT32
5348 EFIAPI
5349 AsmReadMsr32 (
5350 IN UINT32 Index
5351 );
5352
5353
5354 /**
5355 Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.
5356 The upper 32-bits of the MSR are set to zero.
5357
5358 Writes the 32-bit value specified by Value to the MSR specified by Index. The
5359 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
5360 the MSR is returned. No parameter checking is performed on Index or Value,
5361 and some of these may cause CPU exceptions. The caller must either guarantee
5362 that Index and Value are valid, or the caller must establish proper exception
5363 handlers. This function is only available on IA-32 and x64.
5364
5365 @param Index The 32-bit MSR index to write.
5366 @param Value The 32-bit value to write to the MSR.
5367
5368 @return Value
5369
5370 **/
5371 UINT32
5372 EFIAPI
5373 AsmWriteMsr32 (
5374 IN UINT32 Index,
5375 IN UINT32 Value
5376 );
5377
5378
5379 /**
5380 Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and
5381 writes the result back to the 64-bit MSR.
5382
5383 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5384 between the lower 32-bits of the read result and the value specified by
5385 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
5386 32-bits of the value written to the MSR is returned. No parameter checking is
5387 performed on Index or OrData, and some of these may cause CPU exceptions. The
5388 caller must either guarantee that Index and OrData are valid, or the caller
5389 must establish proper exception handlers. This function is only available on
5390 IA-32 and x64.
5391
5392 @param Index The 32-bit MSR index to write.
5393 @param OrData The value to OR with the read value from the MSR.
5394
5395 @return The lower 32-bit value written to the MSR.
5396
5397 **/
5398 UINT32
5399 EFIAPI
5400 AsmMsrOr32 (
5401 IN UINT32 Index,
5402 IN UINT32 OrData
5403 );
5404
5405
5406 /**
5407 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
5408 the result back to the 64-bit MSR.
5409
5410 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5411 lower 32-bits of the read result and the value specified by AndData, and
5412 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
5413 the value written to the MSR is returned. No parameter checking is performed
5414 on Index or AndData, and some of these may cause CPU exceptions. The caller
5415 must either guarantee that Index and AndData are valid, or the caller must
5416 establish proper exception handlers. This function is only available on IA-32
5417 and x64.
5418
5419 @param Index The 32-bit MSR index to write.
5420 @param AndData The value to AND with the read value from the MSR.
5421
5422 @return The lower 32-bit value written to the MSR.
5423
5424 **/
5425 UINT32
5426 EFIAPI
5427 AsmMsrAnd32 (
5428 IN UINT32 Index,
5429 IN UINT32 AndData
5430 );
5431
5432
5433 /**
5434 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR
5435 on the lower 32-bits, and writes the result back to the 64-bit MSR.
5436
5437 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5438 lower 32-bits of the read result and the value specified by AndData
5439 preserving the upper 32-bits, performs a bitwise OR between the
5440 result of the AND operation and the value specified by OrData, and writes the
5441 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
5442 written to the MSR is returned. No parameter checking is performed on Index,
5443 AndData, or OrData, and some of these may cause CPU exceptions. The caller
5444 must either guarantee that Index, AndData, and OrData are valid, or the
5445 caller must establish proper exception handlers. This function is only
5446 available on IA-32 and x64.
5447
5448 @param Index The 32-bit MSR index to write.
5449 @param AndData The value to AND with the read value from the MSR.
5450 @param OrData The value to OR with the result of the AND operation.
5451
5452 @return The lower 32-bit value written to the MSR.
5453
5454 **/
5455 UINT32
5456 EFIAPI
5457 AsmMsrAndThenOr32 (
5458 IN UINT32 Index,
5459 IN UINT32 AndData,
5460 IN UINT32 OrData
5461 );
5462
5463
5464 /**
5465 Reads a bit field of an MSR.
5466
5467 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
5468 specified by the StartBit and the EndBit. The value of the bit field is
5469 returned. The caller must either guarantee that Index is valid, or the caller
5470 must set up exception handlers to catch the exceptions. This function is only
5471 available on IA-32 and x64.
5472
5473 If StartBit is greater than 31, then ASSERT().
5474 If EndBit is greater than 31, then ASSERT().
5475 If EndBit is less than StartBit, then ASSERT().
5476
5477 @param Index The 32-bit MSR index to read.
5478 @param StartBit The ordinal of the least significant bit in the bit field.
5479 Range 0..31.
5480 @param EndBit The ordinal of the most significant bit in the bit field.
5481 Range 0..31.
5482
5483 @return The bit field read from the MSR.
5484
5485 **/
5486 UINT32
5487 EFIAPI
5488 AsmMsrBitFieldRead32 (
5489 IN UINT32 Index,
5490 IN UINTN StartBit,
5491 IN UINTN EndBit
5492 );
5493
5494
5495 /**
5496 Writes a bit field to an MSR.
5497
5498 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
5499 field is specified by the StartBit and the EndBit. All other bits in the
5500 destination MSR are preserved. The lower 32-bits of the MSR written is
5501 returned. The caller must either guarantee that Index and the data written
5502 is valid, or the caller must set up exception handlers to catch the exceptions.
5503 This function is only available on IA-32 and x64.
5504
5505 If StartBit is greater than 31, then ASSERT().
5506 If EndBit is greater than 31, then ASSERT().
5507 If EndBit is less than StartBit, then ASSERT().
5508 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5509
5510 @param Index The 32-bit MSR index to write.
5511 @param StartBit The ordinal of the least significant bit in the bit field.
5512 Range 0..31.
5513 @param EndBit The ordinal of the most significant bit in the bit field.
5514 Range 0..31.
5515 @param Value New value of the bit field.
5516
5517 @return The lower 32-bit of the value written to the MSR.
5518
5519 **/
5520 UINT32
5521 EFIAPI
5522 AsmMsrBitFieldWrite32 (
5523 IN UINT32 Index,
5524 IN UINTN StartBit,
5525 IN UINTN EndBit,
5526 IN UINT32 Value
5527 );
5528
5529
5530 /**
5531 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
5532 result back to the bit field in the 64-bit MSR.
5533
5534 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5535 between the read result and the value specified by OrData, and writes the
5536 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
5537 written to the MSR are returned. Extra left bits in OrData are stripped. The
5538 caller must either guarantee that Index and the data written is valid, or
5539 the caller must set up exception handlers to catch the exceptions. This
5540 function is only available on IA-32 and x64.
5541
5542 If StartBit is greater than 31, then ASSERT().
5543 If EndBit is greater than 31, then ASSERT().
5544 If EndBit is less than StartBit, then ASSERT().
5545 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5546
5547 @param Index The 32-bit MSR index to write.
5548 @param StartBit The ordinal of the least significant bit in the bit field.
5549 Range 0..31.
5550 @param EndBit The ordinal of the most significant bit in the bit field.
5551 Range 0..31.
5552 @param OrData The value to OR with the read value from the MSR.
5553
5554 @return The lower 32-bit of the value written to the MSR.
5555
5556 **/
5557 UINT32
5558 EFIAPI
5559 AsmMsrBitFieldOr32 (
5560 IN UINT32 Index,
5561 IN UINTN StartBit,
5562 IN UINTN EndBit,
5563 IN UINT32 OrData
5564 );
5565
5566
5567 /**
5568 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5569 result back to the bit field in the 64-bit MSR.
5570
5571 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5572 read result and the value specified by AndData, and writes the result to the
5573 64-bit MSR specified by Index. The lower 32-bits of the value written to the
5574 MSR are returned. Extra left bits in AndData are stripped. The caller must
5575 either guarantee that Index and the data written is valid, or the caller must
5576 set up exception handlers to catch the exceptions. This function is only
5577 available on IA-32 and x64.
5578
5579 If StartBit is greater than 31, then ASSERT().
5580 If EndBit is greater than 31, then ASSERT().
5581 If EndBit is less than StartBit, then ASSERT().
5582 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5583
5584 @param Index The 32-bit MSR index to write.
5585 @param StartBit The ordinal of the least significant bit in the bit field.
5586 Range 0..31.
5587 @param EndBit The ordinal of the most significant bit in the bit field.
5588 Range 0..31.
5589 @param AndData The value to AND with the read value from the MSR.
5590
5591 @return The lower 32-bit of the value written to the MSR.
5592
5593 **/
5594 UINT32
5595 EFIAPI
5596 AsmMsrBitFieldAnd32 (
5597 IN UINT32 Index,
5598 IN UINTN StartBit,
5599 IN UINTN EndBit,
5600 IN UINT32 AndData
5601 );
5602
5603
5604 /**
5605 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5606 bitwise OR, and writes the result back to the bit field in the
5607 64-bit MSR.
5608
5609 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
5610 bitwise OR between the read result and the value specified by
5611 AndData, and writes the result to the 64-bit MSR specified by Index. The
5612 lower 32-bits of the value written to the MSR are returned. Extra left bits
5613 in both AndData and OrData are stripped. The caller must either guarantee
5614 that Index and the data written is valid, or the caller must set up exception
5615 handlers to catch the exceptions. This function is only available on IA-32
5616 and x64.
5617
5618 If StartBit is greater than 31, then ASSERT().
5619 If EndBit is greater than 31, then ASSERT().
5620 If EndBit is less than StartBit, then ASSERT().
5621 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5622 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5623
5624 @param Index The 32-bit MSR index to write.
5625 @param StartBit The ordinal of the least significant bit in the bit field.
5626 Range 0..31.
5627 @param EndBit The ordinal of the most significant bit in the bit field.
5628 Range 0..31.
5629 @param AndData The value to AND with the read value from the MSR.
5630 @param OrData The value to OR with the result of the AND operation.
5631
5632 @return The lower 32-bit of the value written to the MSR.
5633
5634 **/
5635 UINT32
5636 EFIAPI
5637 AsmMsrBitFieldAndThenOr32 (
5638 IN UINT32 Index,
5639 IN UINTN StartBit,
5640 IN UINTN EndBit,
5641 IN UINT32 AndData,
5642 IN UINT32 OrData
5643 );
5644
5645
5646 /**
5647 Returns a 64-bit Machine Specific Register(MSR).
5648
5649 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
5650 performed on Index, and some Index values may cause CPU exceptions. The
5651 caller must either guarantee that Index is valid, or the caller must set up
5652 exception handlers to catch the exceptions. This function is only available
5653 on IA-32 and x64.
5654
5655 @param Index The 32-bit MSR index to read.
5656
5657 @return The value of the MSR identified by Index.
5658
5659 **/
5660 UINT64
5661 EFIAPI
5662 AsmReadMsr64 (
5663 IN UINT32 Index
5664 );
5665
5666
5667 /**
5668 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
5669 value.
5670
5671 Writes the 64-bit value specified by Value to the MSR specified by Index. The
5672 64-bit value written to the MSR is returned. No parameter checking is
5673 performed on Index or Value, and some of these may cause CPU exceptions. The
5674 caller must either guarantee that Index and Value are valid, or the caller
5675 must establish proper exception handlers. This function is only available on
5676 IA-32 and x64.
5677
5678 @param Index The 32-bit MSR index to write.
5679 @param Value The 64-bit value to write to the MSR.
5680
5681 @return Value
5682
5683 **/
5684 UINT64
5685 EFIAPI
5686 AsmWriteMsr64 (
5687 IN UINT32 Index,
5688 IN UINT64 Value
5689 );
5690
5691
5692 /**
5693 Reads a 64-bit MSR, performs a bitwise OR, and writes the result
5694 back to the 64-bit MSR.
5695
5696 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5697 between the read result and the value specified by OrData, and writes the
5698 result to the 64-bit MSR specified by Index. The value written to the MSR is
5699 returned. No parameter checking is performed on Index or OrData, and some of
5700 these may cause CPU exceptions. The caller must either guarantee that Index
5701 and OrData are valid, or the caller must establish proper exception handlers.
5702 This function is only available on IA-32 and x64.
5703
5704 @param Index The 32-bit MSR index to write.
5705 @param OrData The value to OR with the read value from the MSR.
5706
5707 @return The value written back to the MSR.
5708
5709 **/
5710 UINT64
5711 EFIAPI
5712 AsmMsrOr64 (
5713 IN UINT32 Index,
5714 IN UINT64 OrData
5715 );
5716
5717
5718 /**
5719 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
5720 64-bit MSR.
5721
5722 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5723 read result and the value specified by OrData, and writes the result to the
5724 64-bit MSR specified by Index. The value written to the MSR is returned. No
5725 parameter checking is performed on Index or OrData, and some of these may
5726 cause CPU exceptions. The caller must either guarantee that Index and OrData
5727 are valid, or the caller must establish proper exception handlers. This
5728 function is only available on IA-32 and x64.
5729
5730 @param Index The 32-bit MSR index to write.
5731 @param AndData The value to AND with the read value from the MSR.
5732
5733 @return The value written back to the MSR.
5734
5735 **/
5736 UINT64
5737 EFIAPI
5738 AsmMsrAnd64 (
5739 IN UINT32 Index,
5740 IN UINT64 AndData
5741 );
5742
5743
5744 /**
5745 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise
5746 OR, and writes the result back to the 64-bit MSR.
5747
5748 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
5749 result and the value specified by AndData, performs a bitwise OR
5750 between the result of the AND operation and the value specified by OrData,
5751 and writes the result to the 64-bit MSR specified by Index. The value written
5752 to the MSR is returned. No parameter checking is performed on Index, AndData,
5753 or OrData, and some of these may cause CPU exceptions. The caller must either
5754 guarantee that Index, AndData, and OrData are valid, or the caller must
5755 establish proper exception handlers. This function is only available on IA-32
5756 and x64.
5757
5758 @param Index The 32-bit MSR index to write.
5759 @param AndData The value to AND with the read value from the MSR.
5760 @param OrData The value to OR with the result of the AND operation.
5761
5762 @return The value written back to the MSR.
5763
5764 **/
5765 UINT64
5766 EFIAPI
5767 AsmMsrAndThenOr64 (
5768 IN UINT32 Index,
5769 IN UINT64 AndData,
5770 IN UINT64 OrData
5771 );
5772
5773
5774 /**
5775 Reads a bit field of an MSR.
5776
5777 Reads the bit field in the 64-bit MSR. The bit field is specified by the
5778 StartBit and the EndBit. The value of the bit field is returned. The caller
5779 must either guarantee that Index is valid, or the caller must set up
5780 exception handlers to catch the exceptions. This function is only available
5781 on IA-32 and x64.
5782
5783 If StartBit is greater than 63, then ASSERT().
5784 If EndBit is greater than 63, then ASSERT().
5785 If EndBit is less than StartBit, then ASSERT().
5786
5787 @param Index The 32-bit MSR index to read.
5788 @param StartBit The ordinal of the least significant bit in the bit field.
5789 Range 0..63.
5790 @param EndBit The ordinal of the most significant bit in the bit field.
5791 Range 0..63.
5792
5793 @return The value read from the MSR.
5794
5795 **/
5796 UINT64
5797 EFIAPI
5798 AsmMsrBitFieldRead64 (
5799 IN UINT32 Index,
5800 IN UINTN StartBit,
5801 IN UINTN EndBit
5802 );
5803
5804
5805 /**
5806 Writes a bit field to an MSR.
5807
5808 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
5809 the StartBit and the EndBit. All other bits in the destination MSR are
5810 preserved. The MSR written is returned. The caller must either guarantee
5811 that Index and the data written is valid, or the caller must set up exception
5812 handlers to catch the exceptions. This function is only available on IA-32 and x64.
5813
5814 If StartBit is greater than 63, then ASSERT().
5815 If EndBit is greater than 63, then ASSERT().
5816 If EndBit is less than StartBit, then ASSERT().
5817 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5818
5819 @param Index The 32-bit MSR index to write.
5820 @param StartBit The ordinal of the least significant bit in the bit field.
5821 Range 0..63.
5822 @param EndBit The ordinal of the most significant bit in the bit field.
5823 Range 0..63.
5824 @param Value New value of the bit field.
5825
5826 @return The value written back to the MSR.
5827
5828 **/
5829 UINT64
5830 EFIAPI
5831 AsmMsrBitFieldWrite64 (
5832 IN UINT32 Index,
5833 IN UINTN StartBit,
5834 IN UINTN EndBit,
5835 IN UINT64 Value
5836 );
5837
5838
5839 /**
5840 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and
5841 writes the result back to the bit field in the 64-bit MSR.
5842
5843 Reads the 64-bit MSR specified by Index, performs a bitwise OR
5844 between the read result and the value specified by OrData, and writes the
5845 result to the 64-bit MSR specified by Index. The value written to the MSR is
5846 returned. Extra left bits in OrData are stripped. The caller must either
5847 guarantee that Index and the data written is valid, or the caller must set up
5848 exception handlers to catch the exceptions. This function is only available
5849 on IA-32 and x64.
5850
5851 If StartBit is greater than 63, then ASSERT().
5852 If EndBit is greater than 63, then ASSERT().
5853 If EndBit is less than StartBit, then ASSERT().
5854 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5855
5856 @param Index The 32-bit MSR index to write.
5857 @param StartBit The ordinal of the least significant bit in the bit field.
5858 Range 0..63.
5859 @param EndBit The ordinal of the most significant bit in the bit field.
5860 Range 0..63.
5861 @param OrData The value to OR with the read value from the bit field.
5862
5863 @return The value written back to the MSR.
5864
5865 **/
5866 UINT64
5867 EFIAPI
5868 AsmMsrBitFieldOr64 (
5869 IN UINT32 Index,
5870 IN UINTN StartBit,
5871 IN UINTN EndBit,
5872 IN UINT64 OrData
5873 );
5874
5875
5876 /**
5877 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
5878 result back to the bit field in the 64-bit MSR.
5879
5880 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
5881 read result and the value specified by AndData, and writes the result to the
5882 64-bit MSR specified by Index. The value written to the MSR is returned.
5883 Extra left bits in AndData are stripped. The caller must either guarantee
5884 that Index and the data written is valid, or the caller must set up exception
5885 handlers to catch the exceptions. This function is only available on IA-32
5886 and x64.
5887
5888 If StartBit is greater than 63, then ASSERT().
5889 If EndBit is greater than 63, then ASSERT().
5890 If EndBit is less than StartBit, then ASSERT().
5891 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5892
5893 @param Index The 32-bit MSR index to write.
5894 @param StartBit The ordinal of the least significant bit in the bit field.
5895 Range 0..63.
5896 @param EndBit The ordinal of the most significant bit in the bit field.
5897 Range 0..63.
5898 @param AndData The value to AND with the read value from the bit field.
5899
5900 @return The value written back to the MSR.
5901
5902 **/
5903 UINT64
5904 EFIAPI
5905 AsmMsrBitFieldAnd64 (
5906 IN UINT32 Index,
5907 IN UINTN StartBit,
5908 IN UINTN EndBit,
5909 IN UINT64 AndData
5910 );
5911
5912
5913 /**
5914 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
5915 bitwise OR, and writes the result back to the bit field in the
5916 64-bit MSR.
5917
5918 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
5919 a bitwise OR between the read result and the value specified by
5920 AndData, and writes the result to the 64-bit MSR specified by Index. The
5921 value written to the MSR is returned. Extra left bits in both AndData and
5922 OrData are stripped. The caller must either guarantee that Index and the data
5923 written is valid, or the caller must set up exception handlers to catch the
5924 exceptions. This function is only available on IA-32 and x64.
5925
5926 If StartBit is greater than 63, then ASSERT().
5927 If EndBit is greater than 63, then ASSERT().
5928 If EndBit is less than StartBit, then ASSERT().
5929 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5930 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
5931
5932 @param Index The 32-bit MSR index to write.
5933 @param StartBit The ordinal of the least significant bit in the bit field.
5934 Range 0..63.
5935 @param EndBit The ordinal of the most significant bit in the bit field.
5936 Range 0..63.
5937 @param AndData The value to AND with the read value from the bit field.
5938 @param OrData The value to OR with the result of the AND operation.
5939
5940 @return The value written back to the MSR.
5941
5942 **/
5943 UINT64
5944 EFIAPI
5945 AsmMsrBitFieldAndThenOr64 (
5946 IN UINT32 Index,
5947 IN UINTN StartBit,
5948 IN UINTN EndBit,
5949 IN UINT64 AndData,
5950 IN UINT64 OrData
5951 );
5952
5953
5954 /**
5955 Reads the current value of the EFLAGS register.
5956
5957 Reads and returns the current value of the EFLAGS register. This function is
5958 only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a
5959 64-bit value on x64.
5960
5961 @return EFLAGS on IA-32 or RFLAGS on x64.
5962
5963 **/
5964 UINTN
5965 EFIAPI
5966 AsmReadEflags (
5967 VOID
5968 );
5969
5970
5971 /**
5972 Reads the current value of the Control Register 0 (CR0).
5973
5974 Reads and returns the current value of CR0. This function is only available
5975 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
5976 x64.
5977
5978 @return The value of the Control Register 0 (CR0).
5979
5980 **/
5981 UINTN
5982 EFIAPI
5983 AsmReadCr0 (
5984 VOID
5985 );
5986
5987
5988 /**
5989 Reads the current value of the Control Register 2 (CR2).
5990
5991 Reads and returns the current value of CR2. This function is only available
5992 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
5993 x64.
5994
5995 @return The value of the Control Register 2 (CR2).
5996
5997 **/
5998 UINTN
5999 EFIAPI
6000 AsmReadCr2 (
6001 VOID
6002 );
6003
6004
6005 /**
6006 Reads the current value of the Control Register 3 (CR3).
6007
6008 Reads and returns the current value of CR3. This function is only available
6009 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6010 x64.
6011
6012 @return The value of the Control Register 3 (CR3).
6013
6014 **/
6015 UINTN
6016 EFIAPI
6017 AsmReadCr3 (
6018 VOID
6019 );
6020
6021
6022 /**
6023 Reads the current value of the Control Register 4 (CR4).
6024
6025 Reads and returns the current value of CR4. This function is only available
6026 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6027 x64.
6028
6029 @return The value of the Control Register 4 (CR4).
6030
6031 **/
6032 UINTN
6033 EFIAPI
6034 AsmReadCr4 (
6035 VOID
6036 );
6037
6038
6039 /**
6040 Writes a value to Control Register 0 (CR0).
6041
6042 Writes and returns a new value to CR0. This function is only available on
6043 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6044
6045 @param Cr0 The value to write to CR0.
6046
6047 @return The value written to CR0.
6048
6049 **/
6050 UINTN
6051 EFIAPI
6052 AsmWriteCr0 (
6053 UINTN Cr0
6054 );
6055
6056
6057 /**
6058 Writes a value to Control Register 2 (CR2).
6059
6060 Writes and returns a new value to CR2. This function is only available on
6061 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6062
6063 @param Cr2 The value to write to CR2.
6064
6065 @return The value written to CR2.
6066
6067 **/
6068 UINTN
6069 EFIAPI
6070 AsmWriteCr2 (
6071 UINTN Cr2
6072 );
6073
6074
6075 /**
6076 Writes a value to Control Register 3 (CR3).
6077
6078 Writes and returns a new value to CR3. This function is only available on
6079 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6080
6081 @param Cr3 The value to write to CR3.
6082
6083 @return The value written to CR3.
6084
6085 **/
6086 UINTN
6087 EFIAPI
6088 AsmWriteCr3 (
6089 UINTN Cr3
6090 );
6091
6092
6093 /**
6094 Writes a value to Control Register 4 (CR4).
6095
6096 Writes and returns a new value to CR4. This function is only available on
6097 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6098
6099 @param Cr4 The value to write to CR4.
6100
6101 @return The value written to CR4.
6102
6103 **/
6104 UINTN
6105 EFIAPI
6106 AsmWriteCr4 (
6107 UINTN Cr4
6108 );
6109
6110
6111 /**
6112 Reads the current value of Debug Register 0 (DR0).
6113
6114 Reads and returns the current value of DR0. This function is only available
6115 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6116 x64.
6117
6118 @return The value of Debug Register 0 (DR0).
6119
6120 **/
6121 UINTN
6122 EFIAPI
6123 AsmReadDr0 (
6124 VOID
6125 );
6126
6127
6128 /**
6129 Reads the current value of Debug Register 1 (DR1).
6130
6131 Reads and returns the current value of DR1. This function is only available
6132 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6133 x64.
6134
6135 @return The value of Debug Register 1 (DR1).
6136
6137 **/
6138 UINTN
6139 EFIAPI
6140 AsmReadDr1 (
6141 VOID
6142 );
6143
6144
6145 /**
6146 Reads the current value of Debug Register 2 (DR2).
6147
6148 Reads and returns the current value of DR2. This function is only available
6149 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6150 x64.
6151
6152 @return The value of Debug Register 2 (DR2).
6153
6154 **/
6155 UINTN
6156 EFIAPI
6157 AsmReadDr2 (
6158 VOID
6159 );
6160
6161
6162 /**
6163 Reads the current value of Debug Register 3 (DR3).
6164
6165 Reads and returns the current value of DR3. This function is only available
6166 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6167 x64.
6168
6169 @return The value of Debug Register 3 (DR3).
6170
6171 **/
6172 UINTN
6173 EFIAPI
6174 AsmReadDr3 (
6175 VOID
6176 );
6177
6178
6179 /**
6180 Reads the current value of Debug Register 4 (DR4).
6181
6182 Reads and returns the current value of DR4. This function is only available
6183 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6184 x64.
6185
6186 @return The value of Debug Register 4 (DR4).
6187
6188 **/
6189 UINTN
6190 EFIAPI
6191 AsmReadDr4 (
6192 VOID
6193 );
6194
6195
6196 /**
6197 Reads the current value of Debug Register 5 (DR5).
6198
6199 Reads and returns the current value of DR5. This function is only available
6200 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6201 x64.
6202
6203 @return The value of Debug Register 5 (DR5).
6204
6205 **/
6206 UINTN
6207 EFIAPI
6208 AsmReadDr5 (
6209 VOID
6210 );
6211
6212
6213 /**
6214 Reads the current value of Debug Register 6 (DR6).
6215
6216 Reads and returns the current value of DR6. This function is only available
6217 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6218 x64.
6219
6220 @return The value of Debug Register 6 (DR6).
6221
6222 **/
6223 UINTN
6224 EFIAPI
6225 AsmReadDr6 (
6226 VOID
6227 );
6228
6229
6230 /**
6231 Reads the current value of Debug Register 7 (DR7).
6232
6233 Reads and returns the current value of DR7. This function is only available
6234 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on
6235 x64.
6236
6237 @return The value of Debug Register 7 (DR7).
6238
6239 **/
6240 UINTN
6241 EFIAPI
6242 AsmReadDr7 (
6243 VOID
6244 );
6245
6246
6247 /**
6248 Writes a value to Debug Register 0 (DR0).
6249
6250 Writes and returns a new value to DR0. This function is only available on
6251 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6252
6253 @param Dr0 The value to write to Dr0.
6254
6255 @return The value written to Debug Register 0 (DR0).
6256
6257 **/
6258 UINTN
6259 EFIAPI
6260 AsmWriteDr0 (
6261 UINTN Dr0
6262 );
6263
6264
6265 /**
6266 Writes a value to Debug Register 1 (DR1).
6267
6268 Writes and returns a new value to DR1. This function is only available on
6269 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6270
6271 @param Dr1 The value to write to Dr1.
6272
6273 @return The value written to Debug Register 1 (DR1).
6274
6275 **/
6276 UINTN
6277 EFIAPI
6278 AsmWriteDr1 (
6279 UINTN Dr1
6280 );
6281
6282
6283 /**
6284 Writes a value to Debug Register 2 (DR2).
6285
6286 Writes and returns a new value to DR2. This function is only available on
6287 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6288
6289 @param Dr2 The value to write to Dr2.
6290
6291 @return The value written to Debug Register 2 (DR2).
6292
6293 **/
6294 UINTN
6295 EFIAPI
6296 AsmWriteDr2 (
6297 UINTN Dr2
6298 );
6299
6300
6301 /**
6302 Writes a value to Debug Register 3 (DR3).
6303
6304 Writes and returns a new value to DR3. This function is only available on
6305 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6306
6307 @param Dr3 The value to write to Dr3.
6308
6309 @return The value written to Debug Register 3 (DR3).
6310
6311 **/
6312 UINTN
6313 EFIAPI
6314 AsmWriteDr3 (
6315 UINTN Dr3
6316 );
6317
6318
6319 /**
6320 Writes a value to Debug Register 4 (DR4).
6321
6322 Writes and returns a new value to DR4. This function is only available on
6323 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6324
6325 @param Dr4 The value to write to Dr4.
6326
6327 @return The value written to Debug Register 4 (DR4).
6328
6329 **/
6330 UINTN
6331 EFIAPI
6332 AsmWriteDr4 (
6333 UINTN Dr4
6334 );
6335
6336
6337 /**
6338 Writes a value to Debug Register 5 (DR5).
6339
6340 Writes and returns a new value to DR5. This function is only available on
6341 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6342
6343 @param Dr5 The value to write to Dr5.
6344
6345 @return The value written to Debug Register 5 (DR5).
6346
6347 **/
6348 UINTN
6349 EFIAPI
6350 AsmWriteDr5 (
6351 UINTN Dr5
6352 );
6353
6354
6355 /**
6356 Writes a value to Debug Register 6 (DR6).
6357
6358 Writes and returns a new value to DR6. This function is only available on
6359 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6360
6361 @param Dr6 The value to write to Dr6.
6362
6363 @return The value written to Debug Register 6 (DR6).
6364
6365 **/
6366 UINTN
6367 EFIAPI
6368 AsmWriteDr6 (
6369 UINTN Dr6
6370 );
6371
6372
6373 /**
6374 Writes a value to Debug Register 7 (DR7).
6375
6376 Writes and returns a new value to DR7. This function is only available on
6377 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.
6378
6379 @param Dr7 The value to write to Dr7.
6380
6381 @return The value written to Debug Register 7 (DR7).
6382
6383 **/
6384 UINTN
6385 EFIAPI
6386 AsmWriteDr7 (
6387 UINTN Dr7
6388 );
6389
6390
6391 /**
6392 Reads the current value of Code Segment Register (CS).
6393
6394 Reads and returns the current value of CS. This function is only available on
6395 IA-32 and x64.
6396
6397 @return The current value of CS.
6398
6399 **/
6400 UINT16
6401 EFIAPI
6402 AsmReadCs (
6403 VOID
6404 );
6405
6406
6407 /**
6408 Reads the current value of Data Segment Register (DS).
6409
6410 Reads and returns the current value of DS. This function is only available on
6411 IA-32 and x64.
6412
6413 @return The current value of DS.
6414
6415 **/
6416 UINT16
6417 EFIAPI
6418 AsmReadDs (
6419 VOID
6420 );
6421
6422
6423 /**
6424 Reads the current value of Extra Segment Register (ES).
6425
6426 Reads and returns the current value of ES. This function is only available on
6427 IA-32 and x64.
6428
6429 @return The current value of ES.
6430
6431 **/
6432 UINT16
6433 EFIAPI
6434 AsmReadEs (
6435 VOID
6436 );
6437
6438
6439 /**
6440 Reads the current value of FS Data Segment Register (FS).
6441
6442 Reads and returns the current value of FS. This function is only available on
6443 IA-32 and x64.
6444
6445 @return The current value of FS.
6446
6447 **/
6448 UINT16
6449 EFIAPI
6450 AsmReadFs (
6451 VOID
6452 );
6453
6454
6455 /**
6456 Reads the current value of GS Data Segment Register (GS).
6457
6458 Reads and returns the current value of GS. This function is only available on
6459 IA-32 and x64.
6460
6461 @return The current value of GS.
6462
6463 **/
6464 UINT16
6465 EFIAPI
6466 AsmReadGs (
6467 VOID
6468 );
6469
6470
6471 /**
6472 Reads the current value of Stack Segment Register (SS).
6473
6474 Reads and returns the current value of SS. This function is only available on
6475 IA-32 and x64.
6476
6477 @return The current value of SS.
6478
6479 **/
6480 UINT16
6481 EFIAPI
6482 AsmReadSs (
6483 VOID
6484 );
6485
6486
6487 /**
6488 Reads the current value of Task Register (TR).
6489
6490 Reads and returns the current value of TR. This function is only available on
6491 IA-32 and x64.
6492
6493 @return The current value of TR.
6494
6495 **/
6496 UINT16
6497 EFIAPI
6498 AsmReadTr (
6499 VOID
6500 );
6501
6502
6503 /**
6504 Reads the current Global Descriptor Table Register(GDTR) descriptor.
6505
6506 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
6507 function is only available on IA-32 and x64.
6508
6509 If Gdtr is NULL, then ASSERT().
6510
6511 @param Gdtr The pointer to a GDTR descriptor.
6512
6513 **/
6514 VOID
6515 EFIAPI
6516 AsmReadGdtr (
6517 OUT IA32_DESCRIPTOR *Gdtr
6518 );
6519
6520
6521 /**
6522 Writes the current Global Descriptor Table Register (GDTR) descriptor.
6523
6524 Writes and the current GDTR descriptor specified by Gdtr. This function is
6525 only available on IA-32 and x64.
6526
6527 If Gdtr is NULL, then ASSERT().
6528
6529 @param Gdtr The pointer to a GDTR descriptor.
6530
6531 **/
6532 VOID
6533 EFIAPI
6534 AsmWriteGdtr (
6535 IN CONST IA32_DESCRIPTOR *Gdtr
6536 );
6537
6538
6539 /**
6540 Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.
6541
6542 Reads and returns the current IDTR descriptor and returns it in Idtr. This
6543 function is only available on IA-32 and x64.
6544
6545 If Idtr is NULL, then ASSERT().
6546
6547 @param Idtr The pointer to a IDTR descriptor.
6548
6549 **/
6550 VOID
6551 EFIAPI
6552 AsmReadIdtr (
6553 OUT IA32_DESCRIPTOR *Idtr
6554 );
6555
6556
6557 /**
6558 Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.
6559
6560 Writes the current IDTR descriptor and returns it in Idtr. This function is
6561 only available on IA-32 and x64.
6562
6563 If Idtr is NULL, then ASSERT().
6564
6565 @param Idtr The pointer to a IDTR descriptor.
6566
6567 **/
6568 VOID
6569 EFIAPI
6570 AsmWriteIdtr (
6571 IN CONST IA32_DESCRIPTOR *Idtr
6572 );
6573
6574
6575 /**
6576 Reads the current Local Descriptor Table Register(LDTR) selector.
6577
6578 Reads and returns the current 16-bit LDTR descriptor value. This function is
6579 only available on IA-32 and x64.
6580
6581 @return The current selector of LDT.
6582
6583 **/
6584 UINT16
6585 EFIAPI
6586 AsmReadLdtr (
6587 VOID
6588 );
6589
6590
6591 /**
6592 Writes the current Local Descriptor Table Register (LDTR) selector.
6593
6594 Writes and the current LDTR descriptor specified by Ldtr. This function is
6595 only available on IA-32 and x64.
6596
6597 @param Ldtr 16-bit LDTR selector value.
6598
6599 **/
6600 VOID
6601 EFIAPI
6602 AsmWriteLdtr (
6603 IN UINT16 Ldtr
6604 );
6605
6606
6607 /**
6608 Save the current floating point/SSE/SSE2 context to a buffer.
6609
6610 Saves the current floating point/SSE/SSE2 state to the buffer specified by
6611 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
6612 available on IA-32 and x64.
6613
6614 If Buffer is NULL, then ASSERT().
6615 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6616
6617 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
6618
6619 **/
6620 VOID
6621 EFIAPI
6622 AsmFxSave (
6623 OUT IA32_FX_BUFFER *Buffer
6624 );
6625
6626
6627 /**
6628 Restores the current floating point/SSE/SSE2 context from a buffer.
6629
6630 Restores the current floating point/SSE/SSE2 state from the buffer specified
6631 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
6632 only available on IA-32 and x64.
6633
6634 If Buffer is NULL, then ASSERT().
6635 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
6636 If Buffer was not saved with AsmFxSave(), then ASSERT().
6637
6638 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
6639
6640 **/
6641 VOID
6642 EFIAPI
6643 AsmFxRestore (
6644 IN CONST IA32_FX_BUFFER *Buffer
6645 );
6646
6647
6648 /**
6649 Reads the current value of 64-bit MMX Register #0 (MM0).
6650
6651 Reads and returns the current value of MM0. This function is only available
6652 on IA-32 and x64.
6653
6654 @return The current value of MM0.
6655
6656 **/
6657 UINT64
6658 EFIAPI
6659 AsmReadMm0 (
6660 VOID
6661 );
6662
6663
6664 /**
6665 Reads the current value of 64-bit MMX Register #1 (MM1).
6666
6667 Reads and returns the current value of MM1. This function is only available
6668 on IA-32 and x64.
6669
6670 @return The current value of MM1.
6671
6672 **/
6673 UINT64
6674 EFIAPI
6675 AsmReadMm1 (
6676 VOID
6677 );
6678
6679
6680 /**
6681 Reads the current value of 64-bit MMX Register #2 (MM2).
6682
6683 Reads and returns the current value of MM2. This function is only available
6684 on IA-32 and x64.
6685
6686 @return The current value of MM2.
6687
6688 **/
6689 UINT64
6690 EFIAPI
6691 AsmReadMm2 (
6692 VOID
6693 );
6694
6695
6696 /**
6697 Reads the current value of 64-bit MMX Register #3 (MM3).
6698
6699 Reads and returns the current value of MM3. This function is only available
6700 on IA-32 and x64.
6701
6702 @return The current value of MM3.
6703
6704 **/
6705 UINT64
6706 EFIAPI
6707 AsmReadMm3 (
6708 VOID
6709 );
6710
6711
6712 /**
6713 Reads the current value of 64-bit MMX Register #4 (MM4).
6714
6715 Reads and returns the current value of MM4. This function is only available
6716 on IA-32 and x64.
6717
6718 @return The current value of MM4.
6719
6720 **/
6721 UINT64
6722 EFIAPI
6723 AsmReadMm4 (
6724 VOID
6725 );
6726
6727
6728 /**
6729 Reads the current value of 64-bit MMX Register #5 (MM5).
6730
6731 Reads and returns the current value of MM5. This function is only available
6732 on IA-32 and x64.
6733
6734 @return The current value of MM5.
6735
6736 **/
6737 UINT64
6738 EFIAPI
6739 AsmReadMm5 (
6740 VOID
6741 );
6742
6743
6744 /**
6745 Reads the current value of 64-bit MMX Register #6 (MM6).
6746
6747 Reads and returns the current value of MM6. This function is only available
6748 on IA-32 and x64.
6749
6750 @return The current value of MM6.
6751
6752 **/
6753 UINT64
6754 EFIAPI
6755 AsmReadMm6 (
6756 VOID
6757 );
6758
6759
6760 /**
6761 Reads the current value of 64-bit MMX Register #7 (MM7).
6762
6763 Reads and returns the current value of MM7. This function is only available
6764 on IA-32 and x64.
6765
6766 @return The current value of MM7.
6767
6768 **/
6769 UINT64
6770 EFIAPI
6771 AsmReadMm7 (
6772 VOID
6773 );
6774
6775
6776 /**
6777 Writes the current value of 64-bit MMX Register #0 (MM0).
6778
6779 Writes the current value of MM0. This function is only available on IA32 and
6780 x64.
6781
6782 @param Value The 64-bit value to write to MM0.
6783
6784 **/
6785 VOID
6786 EFIAPI
6787 AsmWriteMm0 (
6788 IN UINT64 Value
6789 );
6790
6791
6792 /**
6793 Writes the current value of 64-bit MMX Register #1 (MM1).
6794
6795 Writes the current value of MM1. This function is only available on IA32 and
6796 x64.
6797
6798 @param Value The 64-bit value to write to MM1.
6799
6800 **/
6801 VOID
6802 EFIAPI
6803 AsmWriteMm1 (
6804 IN UINT64 Value
6805 );
6806
6807
6808 /**
6809 Writes the current value of 64-bit MMX Register #2 (MM2).
6810
6811 Writes the current value of MM2. This function is only available on IA32 and
6812 x64.
6813
6814 @param Value The 64-bit value to write to MM2.
6815
6816 **/
6817 VOID
6818 EFIAPI
6819 AsmWriteMm2 (
6820 IN UINT64 Value
6821 );
6822
6823
6824 /**
6825 Writes the current value of 64-bit MMX Register #3 (MM3).
6826
6827 Writes the current value of MM3. This function is only available on IA32 and
6828 x64.
6829
6830 @param Value The 64-bit value to write to MM3.
6831
6832 **/
6833 VOID
6834 EFIAPI
6835 AsmWriteMm3 (
6836 IN UINT64 Value
6837 );
6838
6839
6840 /**
6841 Writes the current value of 64-bit MMX Register #4 (MM4).
6842
6843 Writes the current value of MM4. This function is only available on IA32 and
6844 x64.
6845
6846 @param Value The 64-bit value to write to MM4.
6847
6848 **/
6849 VOID
6850 EFIAPI
6851 AsmWriteMm4 (
6852 IN UINT64 Value
6853 );
6854
6855
6856 /**
6857 Writes the current value of 64-bit MMX Register #5 (MM5).
6858
6859 Writes the current value of MM5. This function is only available on IA32 and
6860 x64.
6861
6862 @param Value The 64-bit value to write to MM5.
6863
6864 **/
6865 VOID
6866 EFIAPI
6867 AsmWriteMm5 (
6868 IN UINT64 Value
6869 );
6870
6871
6872 /**
6873 Writes the current value of 64-bit MMX Register #6 (MM6).
6874
6875 Writes the current value of MM6. This function is only available on IA32 and
6876 x64.
6877
6878 @param Value The 64-bit value to write to MM6.
6879
6880 **/
6881 VOID
6882 EFIAPI
6883 AsmWriteMm6 (
6884 IN UINT64 Value
6885 );
6886
6887
6888 /**
6889 Writes the current value of 64-bit MMX Register #7 (MM7).
6890
6891 Writes the current value of MM7. This function is only available on IA32 and
6892 x64.
6893
6894 @param Value The 64-bit value to write to MM7.
6895
6896 **/
6897 VOID
6898 EFIAPI
6899 AsmWriteMm7 (
6900 IN UINT64 Value
6901 );
6902
6903
6904 /**
6905 Reads the current value of Time Stamp Counter (TSC).
6906
6907 Reads and returns the current value of TSC. This function is only available
6908 on IA-32 and x64.
6909
6910 @return The current value of TSC
6911
6912 **/
6913 UINT64
6914 EFIAPI
6915 AsmReadTsc (
6916 VOID
6917 );
6918
6919
6920 /**
6921 Reads the current value of a Performance Counter (PMC).
6922
6923 Reads and returns the current value of performance counter specified by
6924 Index. This function is only available on IA-32 and x64.
6925
6926 @param Index The 32-bit Performance Counter index to read.
6927
6928 @return The value of the PMC specified by Index.
6929
6930 **/
6931 UINT64
6932 EFIAPI
6933 AsmReadPmc (
6934 IN UINT32 Index
6935 );
6936
6937
6938 /**
6939 Sets up a monitor buffer that is used by AsmMwait().
6940
6941 Executes a MONITOR instruction with the register state specified by Eax, Ecx
6942 and Edx. Returns Eax. This function is only available on IA-32 and x64.
6943
6944 @param Eax The value to load into EAX or RAX before executing the MONITOR
6945 instruction.
6946 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6947 instruction.
6948 @param Edx The value to load into EDX or RDX before executing the MONITOR
6949 instruction.
6950
6951 @return Eax
6952
6953 **/
6954 UINTN
6955 EFIAPI
6956 AsmMonitor (
6957 IN UINTN Eax,
6958 IN UINTN Ecx,
6959 IN UINTN Edx
6960 );
6961
6962
6963 /**
6964 Executes an MWAIT instruction.
6965
6966 Executes an MWAIT instruction with the register state specified by Eax and
6967 Ecx. Returns Eax. This function is only available on IA-32 and x64.
6968
6969 @param Eax The value to load into EAX or RAX before executing the MONITOR
6970 instruction.
6971 @param Ecx The value to load into ECX or RCX before executing the MONITOR
6972 instruction.
6973
6974 @return Eax
6975
6976 **/
6977 UINTN
6978 EFIAPI
6979 AsmMwait (
6980 IN UINTN Eax,
6981 IN UINTN Ecx
6982 );
6983
6984
6985 /**
6986 Executes a WBINVD instruction.
6987
6988 Executes a WBINVD instruction. This function is only available on IA-32 and
6989 x64.
6990
6991 **/
6992 VOID
6993 EFIAPI
6994 AsmWbinvd (
6995 VOID
6996 );
6997
6998
6999 /**
7000 Executes a INVD instruction.
7001
7002 Executes a INVD instruction. This function is only available on IA-32 and
7003 x64.
7004
7005 **/
7006 VOID
7007 EFIAPI
7008 AsmInvd (
7009 VOID
7010 );
7011
7012
7013 /**
7014 Flushes a cache line from all the instruction and data caches within the
7015 coherency domain of the CPU.
7016
7017 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
7018 This function is only available on IA-32 and x64.
7019
7020 @param LinearAddress The address of the cache line to flush. If the CPU is
7021 in a physical addressing mode, then LinearAddress is a
7022 physical address. If the CPU is in a virtual
7023 addressing mode, then LinearAddress is a virtual
7024 address.
7025
7026 @return LinearAddress.
7027 **/
7028 VOID *
7029 EFIAPI
7030 AsmFlushCacheLine (
7031 IN VOID *LinearAddress
7032 );
7033
7034
7035 /**
7036 Enables the 32-bit paging mode on the CPU.
7037
7038 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7039 must be properly initialized prior to calling this service. This function
7040 assumes the current execution mode is 32-bit protected mode. This function is
7041 only available on IA-32. After the 32-bit paging mode is enabled, control is
7042 transferred to the function specified by EntryPoint using the new stack
7043 specified by NewStack and passing in the parameters specified by Context1 and
7044 Context2. Context1 and Context2 are optional and may be NULL. The function
7045 EntryPoint must never return.
7046
7047 If the current execution mode is not 32-bit protected mode, then ASSERT().
7048 If EntryPoint is NULL, then ASSERT().
7049 If NewStack is NULL, then ASSERT().
7050
7051 There are a number of constraints that must be followed before calling this
7052 function:
7053 1) Interrupts must be disabled.
7054 2) The caller must be in 32-bit protected mode with flat descriptors. This
7055 means all descriptors must have a base of 0 and a limit of 4GB.
7056 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
7057 descriptors.
7058 4) CR3 must point to valid page tables that will be used once the transition
7059 is complete, and those page tables must guarantee that the pages for this
7060 function and the stack are identity mapped.
7061
7062 @param EntryPoint A pointer to function to call with the new stack after
7063 paging is enabled.
7064 @param Context1 A pointer to the context to pass into the EntryPoint
7065 function as the first parameter after paging is enabled.
7066 @param Context2 A pointer to the context to pass into the EntryPoint
7067 function as the second parameter after paging is enabled.
7068 @param NewStack A pointer to the new stack to use for the EntryPoint
7069 function after paging is enabled.
7070
7071 **/
7072 VOID
7073 EFIAPI
7074 AsmEnablePaging32 (
7075 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
7076 IN VOID *Context1, OPTIONAL
7077 IN VOID *Context2, OPTIONAL
7078 IN VOID *NewStack
7079 );
7080
7081
7082 /**
7083 Disables the 32-bit paging mode on the CPU.
7084
7085 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
7086 mode. This function assumes the current execution mode is 32-paged protected
7087 mode. This function is only available on IA-32. After the 32-bit paging mode
7088 is disabled, control is transferred to the function specified by EntryPoint
7089 using the new stack specified by NewStack and passing in the parameters
7090 specified by Context1 and Context2. Context1 and Context2 are optional and
7091 may be NULL. The function EntryPoint must never return.
7092
7093 If the current execution mode is not 32-bit paged mode, then ASSERT().
7094 If EntryPoint is NULL, then ASSERT().
7095 If NewStack is NULL, then ASSERT().
7096
7097 There are a number of constraints that must be followed before calling this
7098 function:
7099 1) Interrupts must be disabled.
7100 2) The caller must be in 32-bit paged mode.
7101 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
7102 4) CR3 must point to valid page tables that guarantee that the pages for
7103 this function and the stack are identity mapped.
7104
7105 @param EntryPoint A pointer to function to call with the new stack after
7106 paging is disabled.
7107 @param Context1 A pointer to the context to pass into the EntryPoint
7108 function as the first parameter after paging is disabled.
7109 @param Context2 A pointer to the context to pass into the EntryPoint
7110 function as the second parameter after paging is
7111 disabled.
7112 @param NewStack A pointer to the new stack to use for the EntryPoint
7113 function after paging is disabled.
7114
7115 **/
7116 VOID
7117 EFIAPI
7118 AsmDisablePaging32 (
7119 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
7120 IN VOID *Context1, OPTIONAL
7121 IN VOID *Context2, OPTIONAL
7122 IN VOID *NewStack
7123 );
7124
7125
7126 /**
7127 Enables the 64-bit paging mode on the CPU.
7128
7129 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
7130 must be properly initialized prior to calling this service. This function
7131 assumes the current execution mode is 32-bit protected mode with flat
7132 descriptors. This function is only available on IA-32. After the 64-bit
7133 paging mode is enabled, control is transferred to the function specified by
7134 EntryPoint using the new stack specified by NewStack and passing in the
7135 parameters specified by Context1 and Context2. Context1 and Context2 are
7136 optional and may be 0. The function EntryPoint must never return.
7137
7138 If the current execution mode is not 32-bit protected mode with flat
7139 descriptors, then ASSERT().
7140 If EntryPoint is 0, then ASSERT().
7141 If NewStack is 0, then ASSERT().
7142
7143 @param Cs The 16-bit selector to load in the CS before EntryPoint
7144 is called. The descriptor in the GDT that this selector
7145 references must be setup for long mode.
7146 @param EntryPoint The 64-bit virtual address of the function to call with
7147 the new stack after paging is enabled.
7148 @param Context1 The 64-bit virtual address of the context to pass into
7149 the EntryPoint function as the first parameter after
7150 paging is enabled.
7151 @param Context2 The 64-bit virtual address of the context to pass into
7152 the EntryPoint function as the second parameter after
7153 paging is enabled.
7154 @param NewStack The 64-bit virtual address of the new stack to use for
7155 the EntryPoint function after paging is enabled.
7156
7157 **/
7158 VOID
7159 EFIAPI
7160 AsmEnablePaging64 (
7161 IN UINT16 Cs,
7162 IN UINT64 EntryPoint,
7163 IN UINT64 Context1, OPTIONAL
7164 IN UINT64 Context2, OPTIONAL
7165 IN UINT64 NewStack
7166 );
7167
7168
7169 /**
7170 Disables the 64-bit paging mode on the CPU.
7171
7172 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
7173 mode. This function assumes the current execution mode is 64-paging mode.
7174 This function is only available on x64. After the 64-bit paging mode is
7175 disabled, control is transferred to the function specified by EntryPoint
7176 using the new stack specified by NewStack and passing in the parameters
7177 specified by Context1 and Context2. Context1 and Context2 are optional and
7178 may be 0. The function EntryPoint must never return.
7179
7180 If the current execution mode is not 64-bit paged mode, then ASSERT().
7181 If EntryPoint is 0, then ASSERT().
7182 If NewStack is 0, then ASSERT().
7183
7184 @param Cs The 16-bit selector to load in the CS before EntryPoint
7185 is called. The descriptor in the GDT that this selector
7186 references must be setup for 32-bit protected mode.
7187 @param EntryPoint The 64-bit virtual address of the function to call with
7188 the new stack after paging is disabled.
7189 @param Context1 The 64-bit virtual address of the context to pass into
7190 the EntryPoint function as the first parameter after
7191 paging is disabled.
7192 @param Context2 The 64-bit virtual address of the context to pass into
7193 the EntryPoint function as the second parameter after
7194 paging is disabled.
7195 @param NewStack The 64-bit virtual address of the new stack to use for
7196 the EntryPoint function after paging is disabled.
7197
7198 **/
7199 VOID
7200 EFIAPI
7201 AsmDisablePaging64 (
7202 IN UINT16 Cs,
7203 IN UINT32 EntryPoint,
7204 IN UINT32 Context1, OPTIONAL
7205 IN UINT32 Context2, OPTIONAL
7206 IN UINT32 NewStack
7207 );
7208
7209
7210 //
7211 // 16-bit thunking services
7212 //
7213
7214 /**
7215 Retrieves the properties for 16-bit thunk functions.
7216
7217 Computes the size of the buffer and stack below 1MB required to use the
7218 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
7219 buffer size is returned in RealModeBufferSize, and the stack size is returned
7220 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
7221 then the actual minimum stack size is ExtraStackSize plus the maximum number
7222 of bytes that need to be passed to the 16-bit real mode code.
7223
7224 If RealModeBufferSize is NULL, then ASSERT().
7225 If ExtraStackSize is NULL, then ASSERT().
7226
7227 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
7228 required to use the 16-bit thunk functions.
7229 @param ExtraStackSize A pointer to the extra size of stack below 1MB
7230 that the 16-bit thunk functions require for
7231 temporary storage in the transition to and from
7232 16-bit real mode.
7233
7234 **/
7235 VOID
7236 EFIAPI
7237 AsmGetThunk16Properties (
7238 OUT UINT32 *RealModeBufferSize,
7239 OUT UINT32 *ExtraStackSize
7240 );
7241
7242
7243 /**
7244 Prepares all structures a code required to use AsmThunk16().
7245
7246 Prepares all structures and code required to use AsmThunk16().
7247
7248 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
7249 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
7250
7251 If ThunkContext is NULL, then ASSERT().
7252
7253 @param ThunkContext A pointer to the context structure that describes the
7254 16-bit real mode code to call.
7255
7256 **/
7257 VOID
7258 EFIAPI
7259 AsmPrepareThunk16 (
7260 IN OUT THUNK_CONTEXT *ThunkContext
7261 );
7262
7263
7264 /**
7265 Transfers control to a 16-bit real mode entry point and returns the results.
7266
7267 Transfers control to a 16-bit real mode entry point and returns the results.
7268 AsmPrepareThunk16() must be called with ThunkContext before this function is used.
7269 This function must be called with interrupts disabled.
7270
7271 The register state from the RealModeState field of ThunkContext is restored just prior
7272 to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,
7273 which is used to set the interrupt state when a 16-bit real mode entry point is called.
7274 Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.
7275 The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to
7276 the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.
7277 The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,
7278 so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment
7279 and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry
7280 point must exit with a RETF instruction. The register state is captured into RealModeState immediately
7281 after the RETF instruction is executed.
7282
7283 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
7284 or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure
7285 the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.
7286
7287 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,
7288 then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.
7289 This includes the base vectors, the interrupt masks, and the edge/level trigger mode.
7290
7291 If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code
7292 is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.
7293
7294 If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
7295 ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to
7296 disable the A20 mask.
7297
7298 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in
7299 ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,
7300 then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
7301
7302 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in
7303 ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.
7304
7305 If ThunkContext is NULL, then ASSERT().
7306 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
7307 If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in
7308 ThunkAttributes, then ASSERT().
7309
7310 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
7311 virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.
7312
7313 @param ThunkContext A pointer to the context structure that describes the
7314 16-bit real mode code to call.
7315
7316 **/
7317 VOID
7318 EFIAPI
7319 AsmThunk16 (
7320 IN OUT THUNK_CONTEXT *ThunkContext
7321 );
7322
7323
7324 /**
7325 Prepares all structures and code for a 16-bit real mode thunk, transfers
7326 control to a 16-bit real mode entry point, and returns the results.
7327
7328 Prepares all structures and code for a 16-bit real mode thunk, transfers
7329 control to a 16-bit real mode entry point, and returns the results. If the
7330 caller only need to perform a single 16-bit real mode thunk, then this
7331 service should be used. If the caller intends to make more than one 16-bit
7332 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
7333 once and AsmThunk16() can be called for each 16-bit real mode thunk.
7334
7335 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the
7336 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.
7337
7338 See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.
7339
7340 @param ThunkContext A pointer to the context structure that describes the
7341 16-bit real mode code to call.
7342
7343 **/
7344 VOID
7345 EFIAPI
7346 AsmPrepareAndThunk16 (
7347 IN OUT THUNK_CONTEXT *ThunkContext
7348 );
7349
7350 /**
7351 Generates a 16-bit random number through RDRAND instruction.
7352
7353 if Rand is NULL, then ASSERT().
7354
7355 @param[out] Rand Buffer pointer to store the random result.
7356
7357 @retval TRUE RDRAND call was successful.
7358 @retval FALSE Failed attempts to call RDRAND.
7359
7360 **/
7361 BOOLEAN
7362 EFIAPI
7363 AsmRdRand16 (
7364 OUT UINT16 *Rand
7365 );
7366
7367 /**
7368 Generates a 32-bit random number through RDRAND instruction.
7369
7370 if Rand is NULL, then ASSERT().
7371
7372 @param[out] Rand Buffer pointer to store the random result.
7373
7374 @retval TRUE RDRAND call was successful.
7375 @retval FALSE Failed attempts to call RDRAND.
7376
7377 **/
7378 BOOLEAN
7379 EFIAPI
7380 AsmRdRand32 (
7381 OUT UINT32 *Rand
7382 );
7383
7384 /**
7385 Generates a 64-bit random number through RDRAND instruction.
7386
7387 if Rand is NULL, then ASSERT().
7388
7389 @param[out] Rand Buffer pointer to store the random result.
7390
7391 @retval TRUE RDRAND call was successful.
7392 @retval FALSE Failed attempts to call RDRAND.
7393
7394 **/
7395 BOOLEAN
7396 EFIAPI
7397 AsmRdRand64 (
7398 OUT UINT64 *Rand
7399 );
7400
7401 /**
7402 Load given selector into TR register.
7403
7404 @param[in] Selector Task segment selector
7405 **/
7406 VOID
7407 EFIAPI
7408 AsmWriteTr (
7409 IN UINT16 Selector
7410 );
7411
7412 /**
7413 Performs a serializing operation on all load-from-memory instructions that
7414 were issued prior the AsmLfence function.
7415
7416 Executes a LFENCE instruction. This function is only available on IA-32 and x64.
7417
7418 **/
7419 VOID
7420 EFIAPI
7421 AsmLfence (
7422 VOID
7423 );
7424
7425 /**
7426 Executes a XGETBV instruction
7427
7428 Executes a XGETBV instruction. This function is only available on IA-32 and
7429 x64.
7430
7431 @param[in] Index Extended control register index
7432
7433 @return The current value of the extended control register
7434 **/
7435 UINT64
7436 EFIAPI
7437 AsmXGetBv (
7438 IN UINT32 Index
7439 );
7440
7441
7442 /**
7443 Executes a VMGEXIT instruction (VMMCALL with a REP prefix)
7444
7445 Executes a VMGEXIT instruction. This function is only available on IA-32 and
7446 x64.
7447
7448 **/
7449 VOID
7450 EFIAPI
7451 AsmVmgExit (
7452 VOID
7453 );
7454
7455
7456 /**
7457 Patch the immediate operand of an IA32 or X64 instruction such that the byte,
7458 word, dword or qword operand is encoded at the end of the instruction's
7459 binary representation.
7460
7461 This function should be used to update object code that was compiled with
7462 NASM from assembly source code. Example:
7463
7464 NASM source code:
7465
7466 mov eax, strict dword 0 ; the imm32 zero operand will be patched
7467 ASM_PFX(gPatchCr3):
7468 mov cr3, eax
7469
7470 C source code:
7471
7472 X86_ASSEMBLY_PATCH_LABEL gPatchCr3;
7473 PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);
7474
7475 @param[out] InstructionEnd Pointer right past the instruction to patch. The
7476 immediate operand to patch is expected to
7477 comprise the trailing bytes of the instruction.
7478 If InstructionEnd is closer to address 0 than
7479 ValueSize permits, then ASSERT().
7480
7481 @param[in] PatchValue The constant to write to the immediate operand.
7482 The caller is responsible for ensuring that
7483 PatchValue can be represented in the byte, word,
7484 dword or qword operand (as indicated through
7485 ValueSize); otherwise ASSERT().
7486
7487 @param[in] ValueSize The size of the operand in bytes; must be 1, 2,
7488 4, or 8. ASSERT() otherwise.
7489 **/
7490 VOID
7491 EFIAPI
7492 PatchInstructionX86 (
7493 OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,
7494 IN UINT64 PatchValue,
7495 IN UINTN ValueSize
7496 );
7497
7498 #endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
7499 #endif // !defined (__BASE_LIB__)