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