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