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