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