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