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