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