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