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