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