7f494f71b5806d6cd5de0217d04cc8d639cc477c
[mirror_edk2.git] / MdePkg / Include / Library / BaseLib.h
1 /** @file
2 Memory-only library functions with no library constructor/destructor
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: BaseLib.h
14
15 **/
16
17 #ifndef __BASE_LIB__
18 #define __BASE_LIB__
19
20 //
21 // Definitions for architecture specific types
22 // These include SPIN_LOCK and BASE_LIBRARY_JUMP_BUFFER
23 //
24
25 //
26 // SPIN_LOCK
27 //
28 typedef UINTN SPIN_LOCK;
29
30 #if defined (MDE_CPU_IA32)
31 //
32 // IA32 context buffer used by SetJump() and LongJump()
33 //
34 typedef struct {
35 UINT32 Ebx;
36 UINT32 Esi;
37 UINT32 Edi;
38 UINT32 Ebp;
39 UINT32 Esp;
40 UINT32 Eip;
41 } BASE_LIBRARY_JUMP_BUFFER;
42
43 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
44
45 #elif defined (MDE_CPU_IPF)
46 //
47 // IPF context buffer used by SetJump() and LongJump()
48 //
49 typedef struct {
50 UINT64 F2[2];
51 UINT64 F3[2];
52 UINT64 F4[2];
53 UINT64 F5[2];
54 UINT64 F16[2];
55 UINT64 F17[2];
56 UINT64 F18[2];
57 UINT64 F19[2];
58 UINT64 F20[2];
59 UINT64 F21[2];
60 UINT64 F22[2];
61 UINT64 F23[2];
62 UINT64 F24[2];
63 UINT64 F25[2];
64 UINT64 F26[2];
65 UINT64 F27[2];
66 UINT64 F28[2];
67 UINT64 F29[2];
68 UINT64 F30[2];
69 UINT64 F31[2];
70 UINT64 R4;
71 UINT64 R5;
72 UINT64 R6;
73 UINT64 R7;
74 UINT64 SP;
75 UINT64 BR0;
76 UINT64 BR1;
77 UINT64 BR2;
78 UINT64 BR3;
79 UINT64 BR4;
80 UINT64 BR5;
81 UINT64 InitialUNAT;
82 UINT64 AfterSpillUNAT;
83 UINT64 PFS;
84 UINT64 BSP;
85 UINT64 Predicates;
86 UINT64 LoopCount;
87 UINT64 FPSR;
88 } BASE_LIBRARY_JUMP_BUFFER;
89
90 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10
91
92 #elif defined (MDE_CPU_X64)
93 //
94 // X64 context buffer used by SetJump() and LongJump()
95 //
96 typedef struct {
97 UINT64 Rbx;
98 UINT64 Rsp;
99 UINT64 Rbp;
100 UINT64 Rdi;
101 UINT64 Rsi;
102 UINT64 R12;
103 UINT64 R13;
104 UINT64 R14;
105 UINT64 R15;
106 UINT64 Rip;
107 } BASE_LIBRARY_JUMP_BUFFER;
108
109 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
110
111 #elif defined (MDE_CPU_EBC)
112 //
113 // EBC context buffer used by SetJump() and LongJump()
114 //
115 typedef struct {
116 UINT64 R0;
117 UINT64 R1;
118 UINT64 R2;
119 UINT64 R3;
120 UINT64 IP;
121 } BASE_LIBRARY_JUMP_BUFFER;
122
123 #define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8
124
125 #else
126 #error Unknown Processor Type
127 #endif
128
129 //
130 // String Services
131 //
132
133 /**
134 Copies one Null-terminated Unicode string to another Null-terminated Unicode
135 string and returns the new Unicode string.
136
137 This function copies the contents of the Unicode string Source to the Unicode
138 string Destination, and returns Destination. If Source and Destination
139 overlap, then the results are undefined.
140
141 If Destination is NULL, then ASSERT().
142 If Source is NULL, then ASSERT().
143 If Source and Destination overlap, then ASSERT().
144 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
145 PcdMaximumUnicodeStringLength Unicode characters not including the
146 Null-terminator, then ASSERT().
147
148 @param Destination Pointer to a Null-terminated Unicode string.
149 @param Source Pointer to a Null-terminated Unicode string.
150
151 @return Destiantion
152
153 **/
154 CHAR16 *
155 EFIAPI
156 StrCpy (
157 OUT CHAR16 *Destination,
158 IN CONST CHAR16 *Source
159 );
160 /**
161 Copies one Null-terminated Unicode string with a maximum length to another
162 Null-terminated Unicode string with a maximum length and returns the new
163 Unicode string.
164
165 This function copies the contents of the Unicode string Source to the Unicode
166 string Destination, and returns Destination. At most, Length Unicode
167 characters are copied from Source to Destination. If Length is 0, then
168 Destination is returned unmodified. If Length is greater that the number of
169 Unicode characters in Source, then Destination is padded with Null Unicode
170 characters. If Source and Destination overlap, then the results are
171 undefined.
172
173 If Destination is NULL, then ASSERT().
174 If Source is NULL, then ASSERT().
175 If Source and Destination overlap, then ASSERT().
176 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
177 PcdMaximumUnicodeStringLength Unicode characters not including the
178 Null-terminator, then ASSERT().
179
180 @param Destination Pointer to a Null-terminated Unicode string.
181 @param Source Pointer to a Null-terminated Unicode string.
182 @param Length Maximum number of Unicode characters to copy.
183
184 @return Destination
185
186 **/
187 CHAR16 *
188 EFIAPI
189 StrnCpy (
190 OUT CHAR16 *Destination,
191 IN CONST CHAR16 *Source,
192 IN UINTN Length
193 );
194 /**
195 Returns the length of a Null-terminated Unicode string.
196
197 This function returns the number of Unicode characters in the Null-terminated
198 Unicode string specified by String.
199
200 If String is NULL, then ASSERT().
201 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
202 PcdMaximumUnicodeStringLength Unicode characters not including the
203 Null-terminator, then ASSERT().
204
205 @param String Pointer to a Null-terminated Unicode string.
206
207 @return The length of String.
208
209 **/
210 UINTN
211 EFIAPI
212 StrLen (
213 IN CONST CHAR16 *String
214 );
215 /**
216 Returns the size of a Null-terminated Unicode string in bytes, including the
217 Null terminator.
218
219 This function returns the size, in bytes, of the Null-terminated Unicode
220 string specified by String.
221
222 If String is NULL, then ASSERT().
223 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
224 PcdMaximumUnicodeStringLength Unicode characters not including the
225 Null-terminator, then ASSERT().
226
227 @param String Pointer to a Null-terminated Unicode string.
228
229 @return The size of String.
230
231 **/
232 UINTN
233 EFIAPI
234 StrSize (
235 IN CONST CHAR16 *String
236 );
237 /**
238 Compares two Null-terminated Unicode strings, and returns the difference
239 between the first mismatched Unicode characters.
240
241 This function compares the Null-terminated Unicode string FirstString to the
242 Null-terminated Unicode string SecondString. If FirstString is identical to
243 SecondString, then 0 is returned. Otherwise, the value returned is the first
244 mismatched Unicode character in SecondString subtracted from the first
245 mismatched Unicode character in FirstString.
246
247 If FirstString is NULL, then ASSERT().
248 If SecondString is NULL, then ASSERT().
249 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
250 than PcdMaximumUnicodeStringLength Unicode characters not including the
251 Null-terminator, then ASSERT().
252 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
253 than PcdMaximumUnicodeStringLength Unicode characters not including the
254 Null-terminator, then ASSERT().
255
256 @param FirstString Pointer to a Null-terminated Unicode string.
257 @param SecondString Pointer to a Null-terminated Unicode string.
258
259 @retval 0 FirstString is identical to SecondString.
260 @retval !=0 FirstString is not identical to SecondString.
261
262 **/
263 INTN
264 EFIAPI
265 StrCmp (
266 IN CONST CHAR16 *FirstString,
267 IN CONST CHAR16 *SecondString
268 );
269 /**
270 Compares two Null-terminated Unicode strings with maximum lengths, and
271 returns the difference between the first mismatched Unicode characters.
272
273 This function compares the Null-terminated Unicode string FirstString to the
274 Null-terminated Unicode string SecondString. At most, Length Unicode
275 characters will be compared. If Length is 0, then 0 is returned. If
276 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
277 value returned is the first mismatched Unicode character in SecondString
278 subtracted from the first mismatched Unicode character in FirstString.
279
280 If FirstString is NULL, then ASSERT().
281 If SecondString is NULL, then ASSERT().
282 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
283 than PcdMaximumUnicodeStringLength Unicode characters not including the
284 Null-terminator, then ASSERT().
285 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
286 than PcdMaximumUnicodeStringLength Unicode characters not including the
287 Null-terminator, then ASSERT().
288
289 @param FirstString Pointer to a Null-terminated Unicode string.
290 @param SecondString Pointer to a Null-terminated Unicode string.
291 @param Length Maximum number of Unicode characters to compare.
292
293 @retval 0 FirstString is identical to SecondString.
294 @retval !=0 FirstString is not identical to SecondString.
295
296 **/
297 INTN
298 EFIAPI
299 StrnCmp (
300 IN CONST CHAR16 *FirstString,
301 IN CONST CHAR16 *SecondString,
302 IN UINTN Length
303 );
304 /**
305 Concatenates one Null-terminated Unicode string to another Null-terminated
306 Unicode string, and returns the concatenated Unicode string.
307
308 This function concatenates two Null-terminated Unicode strings. The contents
309 of Null-terminated Unicode string Source are concatenated to the end of
310 Null-terminated Unicode string Destination. The Null-terminated concatenated
311 Unicode String is returned. If Source and Destination overlap, then the
312 results are undefined.
313
314 If Destination is NULL, then ASSERT().
315 If Source is NULL, then ASSERT().
316 If Source and Destination overlap, then ASSERT().
317 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
318 than PcdMaximumUnicodeStringLength Unicode characters not including the
319 Null-terminator, then ASSERT().
320 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
321 PcdMaximumUnicodeStringLength Unicode characters not including the
322 Null-terminator, then ASSERT().
323 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
324 and Source results in a Unicode string with more than
325 PcdMaximumUnicodeStringLength Unicode characters not including the
326 Null-terminator, then ASSERT().
327
328 @param Destination Pointer to a Null-terminated Unicode string.
329 @param Source Pointer to a Null-terminated Unicode string.
330
331 @return Destination
332
333 **/
334 CHAR16 *
335 EFIAPI
336 StrCat (
337 IN OUT CHAR16 *Destination,
338 IN CONST CHAR16 *Source
339 );
340 /**
341 Concatenates one Null-terminated Unicode string with a maximum length to the
342 end of another Null-terminated Unicode string, and returns the concatenated
343 Unicode string.
344
345 This function concatenates two Null-terminated Unicode strings. The contents
346 of Null-terminated Unicode string Source are concatenated to the end of
347 Null-terminated Unicode string Destination, and Destination is returned. At
348 most, Length Unicode characters are concatenated from Source to the end of
349 Destination, and Destination is always Null-terminated. If Length is 0, then
350 Destination is returned unmodified. If Source and Destination overlap, then
351 the results are undefined.
352
353 If Destination is NULL, then ASSERT().
354 If Source is NULL, then ASSERT().
355 If Source and Destination overlap, then ASSERT().
356 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
357 than PcdMaximumUnicodeStringLength Unicode characters not including the
358 Null-terminator, then ASSERT().
359 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
360 PcdMaximumUnicodeStringLength Unicode characters not including the
361 Null-terminator, then ASSERT().
362 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
363 and Source results in a Unicode string with more than
364 PcdMaximumUnicodeStringLength Unicode characters not including the
365 Null-terminator, then ASSERT().
366
367 @param Destination Pointer to a Null-terminated Unicode string.
368 @param Source Pointer to a Null-terminated Unicode string.
369 @param Length Maximum number of Unicode characters to concatenate from
370 Source.
371
372 @return Destination
373
374 **/
375 CHAR16 *
376 EFIAPI
377 StrnCat (
378 IN OUT CHAR16 *Destination,
379 IN CONST CHAR16 *Source,
380 IN UINTN Length
381 );
382 /**
383 Copies one Null-terminated ASCII string to another Null-terminated ASCII
384 string and returns the new ASCII string.
385
386 This function copies the contents of the ASCII string Source to the ASCII
387 string Destination, and returns Destination. If Source and Destination
388 overlap, then the results are undefined.
389
390 If Destination is NULL, then ASSERT().
391 If Source is NULL, then ASSERT().
392 If Source and Destination overlap, then ASSERT().
393 If PcdMaximumAsciiStringLength is not zero and Source contains more than
394 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
395 then ASSERT().
396
397 @param Destination Pointer to a Null-terminated ASCII string.
398 @param Source Pointer to a Null-terminated ASCII string.
399
400 @return Destination
401
402 **/
403 CHAR8 *
404 EFIAPI
405 AsciiStrCpy (
406 OUT CHAR8 *Destination,
407 IN CONST CHAR8 *Source
408 );
409 /**
410 Copies one Null-terminated ASCII string with a maximum length to another
411 Null-terminated ASCII string with a maximum length and returns the new ASCII
412 string.
413
414 This function copies the contents of the ASCII string Source to the ASCII
415 string Destination, and returns Destination. At most, Length ASCII characters
416 are copied from Source to Destination. If Length is 0, then Destination is
417 returned unmodified. If Length is greater that the number of ASCII characters
418 in Source, then Destination is padded with Null ASCII characters. If Source
419 and Destination overlap, then the results are undefined.
420
421 If Destination is NULL, then ASSERT().
422 If Source is NULL, then ASSERT().
423 If Source and Destination overlap, then ASSERT().
424 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
425 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
426 then ASSERT().
427
428 @param Destination Pointer to a Null-terminated ASCII string.
429 @param Source Pointer to a Null-terminated ASCII string.
430 @param Length Maximum number of ASCII characters to copy.
431
432 @return Destination
433
434 **/
435 CHAR8 *
436 EFIAPI
437 AsciiStrnCpy (
438 OUT CHAR8 *Destination,
439 IN CONST CHAR8 *Source,
440 IN UINTN Length
441 );
442 /**
443 Returns the length of a Null-terminated ASCII string.
444
445 This function returns the number of ASCII characters in the Null-terminated
446 ASCII string specified by String.
447
448 If String is NULL, then ASSERT().
449 If PcdMaximumAsciiStringLength is not zero and String contains more than
450 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
451 then ASSERT().
452
453 @param String Pointer to a Null-terminated ASCII string.
454
455 @return The length of String.
456
457 **/
458 UINTN
459 EFIAPI
460 AsciiStrLen (
461 IN CONST CHAR8 *String
462 );
463 /**
464 Returns the size of a Null-terminated ASCII string in bytes, including the
465 Null terminator.
466
467 This function returns the size, in bytes, of the Null-terminated ASCII string
468 specified by String.
469
470 If String is NULL, then ASSERT().
471 If PcdMaximumAsciiStringLength is not zero and String contains more than
472 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
473 then ASSERT().
474
475 @param String Pointer to a Null-terminated ASCII string.
476
477 @return The size of String.
478
479 **/
480 UINTN
481 EFIAPI
482 AsciiStrSize (
483 IN CONST CHAR8 *String
484 );
485 /**
486 Compares two Null-terminated ASCII strings, and returns the difference
487 between the first mismatched ASCII characters.
488
489 This function compares the Null-terminated ASCII string FirstString to the
490 Null-terminated ASCII string SecondString. If FirstString is identical to
491 SecondString, then 0 is returned. Otherwise, the value returned is the first
492 mismatched ASCII character in SecondString subtracted from the first
493 mismatched ASCII character in FirstString.
494
495 If FirstString is NULL, then ASSERT().
496 If SecondString is NULL, then ASSERT().
497 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
498 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
499 then ASSERT().
500 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
501 than PcdMaximumAsciiStringLength ASCII characters not including the
502 Null-terminator, then ASSERT().
503
504 @param FirstString Pointer to a Null-terminated ASCII string.
505 @param SecondString Pointer to a Null-terminated ASCII string.
506
507 @retval 0 FirstString is identical to SecondString.
508 @retval !=0 FirstString is not identical to SecondString.
509
510 **/
511 INTN
512 EFIAPI
513 AsciiStrCmp (
514 IN CONST CHAR8 *FirstString,
515 IN CONST CHAR8 *SecondString
516 );
517 /**
518 Performs a case insensitive comparison of two Null-terminated ASCII strings,
519 and returns the difference between the first mismatched ASCII characters.
520
521 This function performs a case insensitive comparison of the Null-terminated
522 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
523 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
524 value returned is the first mismatched lower case ASCII character in
525 SecondString subtracted from the first mismatched lower case ASCII character
526 in FirstString.
527
528 If FirstString is NULL, then ASSERT().
529 If SecondString is NULL, then ASSERT().
530 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
531 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
532 then ASSERT().
533 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
534 than PcdMaximumAsciiStringLength ASCII characters not including the
535 Null-terminator, then ASSERT().
536
537 @param FirstString Pointer to a Null-terminated ASCII string.
538 @param SecondString Pointer to a Null-terminated ASCII string.
539
540 @retval 0 FirstString is identical to SecondString using case insensitive
541 comparisons.
542 @retval !=0 FirstString is not identical to SecondString using case
543 insensitive comparisons.
544
545 **/
546 INTN
547 EFIAPI
548 AsciiStriCmp (
549 IN CONST CHAR8 *FirstString,
550 IN CONST CHAR8 *SecondString
551 );
552 /**
553 Compares two Null-terminated ASCII strings with maximum lengths, and returns
554 the difference between the first mismatched ASCII characters.
555
556 This function compares the Null-terminated ASCII string FirstString to the
557 Null-terminated ASCII string SecondString. At most, Length ASCII characters
558 will be compared. If Length is 0, then 0 is returned. If FirstString is
559 identical to SecondString, then 0 is returned. Otherwise, the value returned
560 is the first mismatched ASCII character in SecondString subtracted from the
561 first mismatched ASCII character in FirstString.
562
563 If FirstString is NULL, then ASSERT().
564 If SecondString is NULL, then ASSERT().
565 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
566 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
567 then ASSERT().
568 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than
569 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
570 then ASSERT().
571
572 @param FirstString Pointer to a Null-terminated ASCII string.
573 @param SecondString Pointer to a Null-terminated ASCII string.
574
575 @retval 0 FirstString is identical to SecondString.
576 @retval !=0 FirstString is not identical to SecondString.
577
578 **/
579 INTN
580 EFIAPI
581 AsciiStrnCmp (
582 IN CONST CHAR8 *FirstString,
583 IN CONST CHAR8 *SecondString,
584 IN UINTN Length
585 );
586 /**
587 Concatenates one Null-terminated ASCII string to another Null-terminated
588 ASCII string, and returns the concatenated ASCII string.
589
590 This function concatenates two Null-terminated ASCII strings. The contents of
591 Null-terminated ASCII string Source are concatenated to the end of Null-
592 terminated ASCII string Destination. The Null-terminated concatenated ASCII
593 String is returned.
594
595 If Destination is NULL, then ASSERT().
596 If Source is NULL, then ASSERT().
597 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
598 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
599 then ASSERT().
600 If PcdMaximumAsciiStringLength is not zero and Source contains more than
601 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
602 then ASSERT().
603 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
604 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
605 ASCII characters, then ASSERT().
606
607 @param Destination Pointer to a Null-terminated ASCII string.
608 @param Source Pointer to a Null-terminated ASCII string.
609
610 @return Destination
611
612 **/
613 CHAR8 *
614 EFIAPI
615 AsciiStrCat (
616 IN OUT CHAR8 *Destination,
617 IN CONST CHAR8 *Source
618 );
619 /**
620 Concatenates one Null-terminated ASCII string with a maximum length to the
621 end of another Null-terminated ASCII string, and returns the concatenated
622 ASCII string.
623
624 This function concatenates two Null-terminated ASCII strings. The contents
625 of Null-terminated ASCII string Source are concatenated to the end of Null-
626 terminated ASCII string Destination, and Destination is returned. At most,
627 Length ASCII characters are concatenated from Source to the end of
628 Destination, and Destination is always Null-terminated. If Length is 0, then
629 Destination is returned unmodified. If Source and Destination overlap, then
630 the results are undefined.
631
632 If Destination is NULL, then ASSERT().
633 If Source is NULL, then ASSERT().
634 If Source and Destination overlap, then ASSERT().
635 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
636 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
637 then ASSERT().
638 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
639 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
640 then ASSERT().
641 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
642 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
643 ASCII characters not including the Null-terminator, then ASSERT().
644
645 @param Destination Pointer to a Null-terminated ASCII string.
646 @param Source Pointer to a Null-terminated ASCII string.
647 @param Length Maximum number of ASCII characters to concatenate from
648 Source.
649
650 @return Destination
651
652 **/
653 CHAR8 *
654 EFIAPI
655 AsciiStrnCat (
656 IN OUT CHAR8 *Destination,
657 IN CONST CHAR8 *Source,
658 IN UINTN Length
659 );
660 /**
661 Converts an 8-bit value to an 8-bit BCD value.
662
663 Converts the 8-bit value specified by Value to BCD. The BCD value is
664 returned.
665
666 If Value >= 100, then ASSERT().
667
668 @param Value The 8-bit value to convert to BCD. Range 0..99.
669
670 @return The BCD value
671
672 **/
673 UINT8
674 EFIAPI
675 DecimalToBcd8 (
676 IN UINT8 Value
677 );
678
679 /**
680 Converts an 8-bit BCD value to an 8-bit value.
681
682 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
683 value is returned.
684
685 If Value >= 0xA0, then ASSERT().
686 If (Value & 0x0F) >= 0x0A, then ASSERT().
687
688 @param Value The 8-bit BCD value to convert to an 8-bit value.
689
690 @return The 8-bit value is returned.
691
692 **/
693 UINT8
694 EFIAPI
695 BcdToDecimal8 (
696 IN UINT8 Value
697 );
698
699 //
700 // Linked List Functions and Macros
701 //
702
703 /**
704 Initializes the head node of a doubly linked list that is declared as a
705 global variable in a module.
706
707 Initializes the forward and backward links of a new linked list. After
708 initializing a linked list with this macro, the other linked list functions
709 may be used to add and remove nodes from the linked list. This macro results
710 in smaller executables by initializing the linked list in the data section,
711 instead if calling the InitializeListHead() function to perform the
712 equivalent operation.
713
714 @param ListHead The head note of a list to initiailize.
715
716 **/
717 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
718
719 /**
720 Initializes the head node of a doubly linked list, and returns the pointer to
721 the head node of the doubly linked list.
722
723 Initializes the forward and backward links of a new linked list. After
724 initializing a linked list with this function, the other linked list
725 functions may be used to add and remove nodes from the linked list. It is up
726 to the caller of this function to allocate the memory for ListHead.
727
728 If ListHead is NULL, then ASSERT().
729
730 @param ListHead A pointer to the head node of a new doubly linked list.
731
732 @return ListHead
733
734 **/
735 LIST_ENTRY *
736 EFIAPI
737 InitializeListHead (
738 IN LIST_ENTRY *ListHead
739 );
740
741 /**
742 Adds a node to the beginning of a doubly linked list, and returns the pointer
743 to the head node of the doubly linked list.
744
745 Adds the node Entry at the beginning of the doubly linked list denoted by
746 ListHead, and returns ListHead.
747
748 If ListHead is NULL, then ASSERT().
749 If Entry is NULL, then ASSERT().
750 If ListHead was not initialized with InitializeListHead(), then ASSERT().
751 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
752 of nodes in ListHead, including the ListHead node, is greater than or
753 equal to PcdMaximumLinkedListLength, then ASSERT().
754
755 @param ListHead A pointer to the head node of a doubly linked list.
756 @param Entry A pointer to a node that is to be inserted at the beginning
757 of a doubly linked list.
758
759 @return ListHead
760
761 **/
762 LIST_ENTRY *
763 EFIAPI
764 InsertHeadList (
765 IN LIST_ENTRY *ListHead,
766 IN LIST_ENTRY *Entry
767 );
768
769 /**
770 Adds a node to the end of a doubly linked list, and returns the pointer to
771 the head node of the doubly linked list.
772
773 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
774 and returns ListHead.
775
776 If ListHead is NULL, then ASSERT().
777 If Entry is NULL, then ASSERT().
778 If ListHead was not initialized with InitializeListHead(), then ASSERT().
779 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
780 of nodes in ListHead, including the ListHead node, is greater than or
781 equal to PcdMaximumLinkedListLength, then ASSERT().
782
783 @param ListHead A pointer to the head node of a doubly linked list.
784 @param Entry A pointer to a node that is to be added at the end of the
785 doubly linked list.
786
787 @return ListHead
788
789 **/
790 LIST_ENTRY *
791 EFIAPI
792 InsertTailList (
793 IN LIST_ENTRY *ListHead,
794 IN LIST_ENTRY *Entry
795 );
796
797 /**
798 Retrieves the first node of a doubly linked list.
799
800 Returns the first node of a doubly linked list. List must have been
801 initialized with InitializeListHead(). If List is empty, then NULL is
802 returned.
803
804 If List is NULL, then ASSERT().
805 If List was not initialized with InitializeListHead(), then ASSERT().
806 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
807 in List, including the List node, is greater than or equal to
808 PcdMaximumLinkedListLength, then ASSERT().
809
810 @param List A pointer to the head node of a doubly linked list.
811
812 @return The first node of a doubly linked list.
813 @retval NULL The list is empty.
814
815 **/
816 LIST_ENTRY *
817 EFIAPI
818 GetFirstNode (
819 IN CONST LIST_ENTRY *List
820 );
821
822 /**
823 Retrieves the next node of a doubly linked list.
824
825 Returns the node of a doubly linked list that follows Node. List must have
826 been initialized with InitializeListHead(). If List is empty, then List is
827 returned.
828
829 If List is NULL, then ASSERT().
830 If Node is NULL, then ASSERT().
831 If List was not initialized with InitializeListHead(), then ASSERT().
832 If PcdMaximumLinkedListLenth is not zero, and List contains more than
833 PcdMaximumLinkedListLenth nodes, then ASSERT().
834 If Node is not a node in List, then ASSERT().
835
836 @param List A pointer to the head node of a doubly linked list.
837 @param Node A pointer to a node in the doubly linked list.
838
839 @return Pointer to the next node if one exists. Otherwise a null value which
840 is actually List is returned.
841
842 **/
843 LIST_ENTRY *
844 EFIAPI
845 GetNextNode (
846 IN CONST LIST_ENTRY *List,
847 IN CONST LIST_ENTRY *Node
848 );
849
850 /**
851 Checks to see if a doubly linked list is empty or not.
852
853 Checks to see if the doubly linked list is empty. If the linked list contains
854 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
855
856 If ListHead is NULL, then ASSERT().
857 If ListHead was not initialized with InitializeListHead(), then ASSERT().
858 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
859 in List, including the List node, is greater than or equal to
860 PcdMaximumLinkedListLength, then ASSERT().
861
862 @param ListHead A pointer to the head node of a doubly linked list.
863
864 @retval TRUE The linked list is empty.
865 @retval FALSE The linked list is not empty.
866
867 **/
868 BOOLEAN
869 EFIAPI
870 IsListEmpty (
871 IN CONST LIST_ENTRY *ListHead
872 );
873
874 /**
875 Determines if a node in a doubly linked list is null.
876
877 Returns FALSE if Node is one of the nodes in the doubly linked list specified
878 by List. Otherwise, TRUE is returned. List must have been initialized with
879 InitializeListHead().
880
881 If List is NULL, then ASSERT().
882 If Node is NULL, then ASSERT().
883 If List was not initialized with InitializeListHead(), then ASSERT().
884 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
885 in List, including the List node, is greater than or equal to
886 PcdMaximumLinkedListLength, then ASSERT().
887 If Node is not a node in List and Node is not equal to List, then ASSERT().
888
889 @param List A pointer to the head node of a doubly linked list.
890 @param Node A pointer to a node in the doubly linked list.
891
892 @retval TRUE Node is one of the nodes in the doubly linked list.
893 @retval FALSE Node is not one of the nodes in the doubly linked list.
894
895 **/
896 BOOLEAN
897 EFIAPI
898 IsNull (
899 IN CONST LIST_ENTRY *List,
900 IN CONST LIST_ENTRY *Node
901 );
902
903 /**
904 Determines if a node the last node in a doubly linked list.
905
906 Returns TRUE if Node is the last node in the doubly linked list specified by
907 List. Otherwise, FALSE is returned. List must have been initialized with
908 InitializeListHead().
909
910 If List is NULL, then ASSERT().
911 If Node is NULL, then ASSERT().
912 If List was not initialized with InitializeListHead(), then ASSERT().
913 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
914 in List, including the List node, is greater than or equal to
915 PcdMaximumLinkedListLength, then ASSERT().
916 If Node is not a node in List, then ASSERT().
917
918 @param List A pointer to the head node of a doubly linked list.
919 @param Node A pointer to a node in the doubly linked list.
920
921 @retval TRUE Node is the last node in the linked list.
922 @retval FALSE Node is not the last node in the linked list.
923
924 **/
925 BOOLEAN
926 EFIAPI
927 IsNodeAtEnd (
928 IN CONST LIST_ENTRY *List,
929 IN CONST LIST_ENTRY *Node
930 );
931
932 /**
933 Swaps the location of two nodes in a doubly linked list, and returns the
934 first node after the swap.
935
936 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
937 Otherwise, the location of the FirstEntry node is swapped with the location
938 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
939 same double linked list as FirstEntry and that double linked list must have
940 been initialized with InitializeListHead(). SecondEntry is returned after the
941 nodes are swapped.
942
943 If FirstEntry is NULL, then ASSERT().
944 If SecondEntry is NULL, then ASSERT().
945 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
946 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
947 linked list containing the FirstEntry and SecondEntry nodes, including
948 the FirstEntry and SecondEntry nodes, is greater than or equal to
949 PcdMaximumLinkedListLength, then ASSERT().
950
951 @param FirstEntry A pointer to a node in a linked list.
952 @param SecondEntry A pointer to another node in the same linked list.
953
954 **/
955 LIST_ENTRY *
956 EFIAPI
957 SwapListEntries (
958 IN LIST_ENTRY *FirstEntry,
959 IN LIST_ENTRY *SecondEntry
960 );
961
962 /**
963 Removes a node from a doubly linked list, and returns the node that follows
964 the removed node.
965
966 Removes the node Entry from a doubly linked list. It is up to the caller of
967 this function to release the memory used by this node if that is required. On
968 exit, the node following Entry in the doubly linked list is returned. If
969 Entry is the only node in the linked list, then the head node of the linked
970 list is returned.
971
972 If Entry is NULL, then ASSERT().
973 If Entry is the head node of an empty list, then ASSERT().
974 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
975 linked list containing Entry, including the Entry node, is greater than
976 or equal to PcdMaximumLinkedListLength, then ASSERT().
977
978 @param Entry A pointer to a node in a linked list
979
980 @return Entry
981
982 **/
983 LIST_ENTRY *
984 EFIAPI
985 RemoveEntryList (
986 IN CONST LIST_ENTRY *Entry
987 );
988
989 //
990 // Math Services
991 //
992
993 /**
994 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
995 with zeros. The shifted value is returned.
996
997 This function shifts the 64-bit value Operand to the left by Count bits. The
998 low Count bits are set to zero. The shifted value is returned.
999
1000 If Count is greater than 63, then ASSERT().
1001
1002 @param Operand The 64-bit operand to shift left.
1003 @param Count The number of bits to shift left.
1004
1005 @return Operand << Count
1006
1007 **/
1008 UINT64
1009 EFIAPI
1010 LShiftU64 (
1011 IN UINT64 Operand,
1012 IN UINTN Count
1013 );
1014
1015 /**
1016 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1017 filled with zeros. The shifted value is returned.
1018
1019 This function shifts the 64-bit value Operand to the right by Count bits. The
1020 high Count bits are set to zero. The shifted value is returned.
1021
1022 If Count is greater than 63, then ASSERT().
1023
1024 @param Operand The 64-bit operand to shift right.
1025 @param Count The number of bits to shift right.
1026
1027 @return Operand >> Count
1028
1029 **/
1030 UINT64
1031 EFIAPI
1032 RShiftU64 (
1033 IN UINT64 Operand,
1034 IN UINTN Count
1035 );
1036
1037 /**
1038 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1039 with original integer's bit 63. The shifted value is returned.
1040
1041 This function shifts the 64-bit value Operand to the right by Count bits. The
1042 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1043
1044 If Count is greater than 63, then ASSERT().
1045
1046 @param Operand The 64-bit operand to shift right.
1047 @param Count The number of bits to shift right.
1048
1049 @return Operand >> Count
1050
1051 **/
1052 UINT64
1053 EFIAPI
1054 ARShiftU64 (
1055 IN UINT64 Operand,
1056 IN UINTN Count
1057 );
1058
1059 /**
1060 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1061 with the high bits that were rotated.
1062
1063 This function rotates the 32-bit value Operand to the left by Count bits. The
1064 low Count bits are fill with the high Count bits of Operand. The rotated
1065 value is returned.
1066
1067 If Count is greater than 31, then ASSERT().
1068
1069 @param Operand The 32-bit operand to rotate left.
1070 @param Count The number of bits to rotate left.
1071
1072 @return Operand <<< Count
1073
1074 **/
1075 UINT32
1076 EFIAPI
1077 LRotU32 (
1078 IN UINT32 Operand,
1079 IN UINTN Count
1080 );
1081
1082 /**
1083 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1084 with the low bits that were rotated.
1085
1086 This function rotates the 32-bit value Operand to the right by Count bits.
1087 The high Count bits are fill with the low Count bits of Operand. The rotated
1088 value is returned.
1089
1090 If Count is greater than 31, then ASSERT().
1091
1092 @param Operand The 32-bit operand to rotate right.
1093 @param Count The number of bits to rotate right.
1094
1095 @return Operand >>> Count
1096
1097 **/
1098 UINT32
1099 EFIAPI
1100 RRotU32 (
1101 IN UINT32 Operand,
1102 IN UINTN Count
1103 );
1104
1105 /**
1106 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1107 with the high bits that were rotated.
1108
1109 This function rotates the 64-bit value Operand to the left by Count bits. The
1110 low Count bits are fill with the high Count bits of Operand. The rotated
1111 value is returned.
1112
1113 If Count is greater than 63, then ASSERT().
1114
1115 @param Operand The 64-bit operand to rotate left.
1116 @param Count The number of bits to rotate left.
1117
1118 @return Operand <<< Count
1119
1120 **/
1121 UINT64
1122 EFIAPI
1123 LRotU64 (
1124 IN UINT64 Operand,
1125 IN UINTN Count
1126 );
1127
1128 /**
1129 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1130 with the high low bits that were rotated.
1131
1132 This function rotates the 64-bit value Operand to the right by Count bits.
1133 The high Count bits are fill with the low Count bits of Operand. The rotated
1134 value is returned.
1135
1136 If Count is greater than 63, then ASSERT().
1137
1138 @param Operand The 64-bit operand to rotate right.
1139 @param Count The number of bits to rotate right.
1140
1141 @return Operand >>> Count
1142
1143 **/
1144 UINT64
1145 EFIAPI
1146 RRotU64 (
1147 IN UINT64 Operand,
1148 IN UINTN Count
1149 );
1150
1151 /**
1152 Returns the bit position of the lowest bit set in a 32-bit value.
1153
1154 This function computes the bit position of the lowest bit set in the 32-bit
1155 value specified by Operand. If Operand is zero, then -1 is returned.
1156 Otherwise, a value between 0 and 31 is returned.
1157
1158 @param Operand The 32-bit operand to evaluate.
1159
1160 @return Position of the lowest bit set in Operand if found.
1161 @retval -1 Operand is zero.
1162
1163 **/
1164 INTN
1165 EFIAPI
1166 LowBitSet32 (
1167 IN UINT32 Operand
1168 );
1169
1170 /**
1171 Returns the bit position of the lowest bit set in a 64-bit value.
1172
1173 This function computes the bit position of the lowest bit set in the 64-bit
1174 value specified by Operand. If Operand is zero, then -1 is returned.
1175 Otherwise, a value between 0 and 63 is returned.
1176
1177 @param Operand The 64-bit operand to evaluate.
1178
1179 @return Position of the lowest bit set in Operand if found.
1180 @retval -1 Operand is zero.
1181
1182 **/
1183 INTN
1184 EFIAPI
1185 LowBitSet64 (
1186 IN UINT64 Operand
1187 );
1188
1189 /**
1190 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1191 to log2(x).
1192
1193 This function computes the bit position of the highest bit set in the 32-bit
1194 value specified by Operand. If Operand is zero, then -1 is returned.
1195 Otherwise, a value between 0 and 31 is returned.
1196
1197 @param Operand The 32-bit operand to evaluate.
1198
1199 @return Position of the highest bit set in Operand if found.
1200 @retval -1 Operand is zero.
1201
1202 **/
1203 INTN
1204 EFIAPI
1205 HighBitSet32 (
1206 IN UINT32 Operand
1207 );
1208
1209 /**
1210 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1211 to log2(x).
1212
1213 This function computes the bit position of the highest bit set in the 64-bit
1214 value specified by Operand. If Operand is zero, then -1 is returned.
1215 Otherwise, a value between 0 and 63 is returned.
1216
1217 @param Operand The 64-bit operand to evaluate.
1218
1219 @return Position of the highest bit set in Operand if found.
1220 @retval -1 Operand is zero.
1221
1222 **/
1223 INTN
1224 EFIAPI
1225 HighBitSet64 (
1226 IN UINT64 Operand
1227 );
1228
1229 /**
1230 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1231 1 << HighBitSet32(x).
1232
1233 This function computes the value of the highest bit set in the 32-bit value
1234 specified by Operand. If Operand is zero, then zero is returned.
1235
1236 @param Operand The 32-bit operand to evaluate.
1237
1238 @return 1 << HighBitSet32(Operand)
1239 @retval 0 Operand is zero.
1240
1241 **/
1242 UINT32
1243 EFIAPI
1244 GetPowerOfTwo32 (
1245 IN UINT32 Operand
1246 );
1247
1248 /**
1249 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1250 1 << HighBitSet64(x).
1251
1252 This function computes the value of the highest bit set in the 64-bit value
1253 specified by Operand. If Operand is zero, then zero is returned.
1254
1255 @param Operand The 64-bit operand to evaluate.
1256
1257 @return 1 << HighBitSet64(Operand)
1258 @retval 0 Operand is zero.
1259
1260 **/
1261 UINT64
1262 EFIAPI
1263 GetPowerOfTwo64 (
1264 IN UINT64 Operand
1265 );
1266
1267 /**
1268 Switches the endianess of a 16-bit integer.
1269
1270 This function swaps the bytes in a 16-bit unsigned value to switch the value
1271 from little endian to big endian or vice versa. The byte swapped value is
1272 returned.
1273
1274 @param Operand A 16-bit unsigned value.
1275
1276 @return The byte swaped Operand.
1277
1278 **/
1279 UINT16
1280 EFIAPI
1281 SwapBytes16 (
1282 IN UINT16 Value
1283 );
1284
1285 /**
1286 Switches the endianess of a 32-bit integer.
1287
1288 This function swaps the bytes in a 32-bit unsigned value to switch the value
1289 from little endian to big endian or vice versa. The byte swapped value is
1290 returned.
1291
1292 @param Operand A 32-bit unsigned value.
1293
1294 @return The byte swaped Operand.
1295
1296 **/
1297 UINT32
1298 EFIAPI
1299 SwapBytes32 (
1300 IN UINT32 Value
1301 );
1302
1303 /**
1304 Switches the endianess of a 64-bit integer.
1305
1306 This function swaps the bytes in a 64-bit unsigned value to switch the value
1307 from little endian to big endian or vice versa. The byte swapped value is
1308 returned.
1309
1310 @param Operand A 64-bit unsigned value.
1311
1312 @return The byte swaped Operand.
1313
1314 **/
1315 UINT64
1316 EFIAPI
1317 SwapBytes64 (
1318 IN UINT64 Value
1319 );
1320
1321 /**
1322 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1323 generates a 64-bit unsigned result.
1324
1325 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1326 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1327 bit unsigned result is returned.
1328
1329 If the result overflows, then ASSERT().
1330
1331 @param Multiplicand A 64-bit unsigned value.
1332 @param Multiplier A 32-bit unsigned value.
1333
1334 @return Multiplicand * Multiplier
1335
1336 **/
1337 UINT64
1338 EFIAPI
1339 MultU64x32 (
1340 IN UINT64 Multiplicand,
1341 IN UINT32 Multiplier
1342 );
1343
1344 /**
1345 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1346 generates a 64-bit unsigned result.
1347
1348 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1349 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1350 bit unsigned result is returned.
1351
1352 If the result overflows, then ASSERT().
1353
1354 @param Multiplicand A 64-bit unsigned value.
1355 @param Multiplier A 64-bit unsigned value.
1356
1357 @return Multiplicand * Multiplier
1358
1359 **/
1360 UINT64
1361 EFIAPI
1362 MultU64x64 (
1363 IN UINT64 Multiplicand,
1364 IN UINT64 Multiplier
1365 );
1366
1367 /**
1368 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1369 64-bit signed result.
1370
1371 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1372 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1373 signed result is returned.
1374
1375 If the result overflows, then ASSERT().
1376
1377 @param Multiplicand A 64-bit signed value.
1378 @param Multiplier A 64-bit signed value.
1379
1380 @return Multiplicand * Multiplier
1381
1382 **/
1383 INT64
1384 EFIAPI
1385 MultS64x64 (
1386 IN INT64 Multiplicand,
1387 IN INT64 Multiplier
1388 );
1389
1390 /**
1391 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1392 a 64-bit unsigned result.
1393
1394 This function divides the 64-bit unsigned value Dividend by the 32-bit
1395 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1396 function returns the 64-bit unsigned quotient.
1397
1398 If Divisor is 0, then ASSERT().
1399
1400 @param Dividend A 64-bit unsigned value.
1401 @param Divisor A 32-bit unsigned value.
1402
1403 @return Dividend / Divisor
1404
1405 **/
1406 UINT64
1407 EFIAPI
1408 DivU64x32 (
1409 IN UINT64 Dividend,
1410 IN UINT32 Divisor
1411 );
1412
1413 /**
1414 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1415 a 32-bit unsigned remainder.
1416
1417 This function divides the 64-bit unsigned value Dividend by the 32-bit
1418 unsigned value Divisor and generates a 32-bit remainder. This function
1419 returns the 32-bit unsigned remainder.
1420
1421 If Divisor is 0, then ASSERT().
1422
1423 @param Dividend A 64-bit unsigned value.
1424 @param Divisor A 32-bit unsigned value.
1425
1426 @return Dividend % Divisor
1427
1428 **/
1429 UINT32
1430 EFIAPI
1431 ModU64x32 (
1432 IN UINT64 Dividend,
1433 IN UINT32 Divisor
1434 );
1435
1436 /**
1437 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1438 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1439
1440 This function divides the 64-bit unsigned value Dividend by the 32-bit
1441 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1442 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1443 This function returns the 64-bit unsigned quotient.
1444
1445 If Divisor is 0, then ASSERT().
1446
1447 @param Dividend A 64-bit unsigned value.
1448 @param Divisor A 32-bit unsigned value.
1449 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1450 optional and may be NULL.
1451
1452 @return Dividend / Divisor
1453
1454 **/
1455 UINT64
1456 EFIAPI
1457 DivU64x32Remainder (
1458 IN UINT64 Dividend,
1459 IN UINT32 Divisor,
1460 OUT UINT32 *Remainder OPTIONAL
1461 );
1462
1463 /**
1464 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
1465 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
1466
1467 This function divides the 64-bit unsigned value Dividend by the 64-bit
1468 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1469 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
1470 This function returns the 64-bit unsigned quotient.
1471
1472 If Divisor is 0, then ASSERT().
1473
1474 @param Dividend A 64-bit unsigned value.
1475 @param Divisor A 64-bit unsigned value.
1476 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
1477 optional and may be NULL.
1478
1479 @return Dividend / Divisor
1480
1481 **/
1482 UINT64
1483 EFIAPI
1484 DivU64x64Remainder (
1485 IN UINT64 Dividend,
1486 IN UINT64 Divisor,
1487 OUT UINT64 *Remainder OPTIONAL
1488 );
1489
1490 /**
1491 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
1492 64-bit signed result and a optional 64-bit signed remainder.
1493
1494 This function divides the 64-bit signed value Dividend by the 64-bit signed
1495 value Divisor and generates a 64-bit signed quotient. If Remainder is not
1496 NULL, then the 64-bit signed remainder is returned in Remainder. This
1497 function returns the 64-bit signed quotient.
1498
1499 If Divisor is 0, then ASSERT().
1500
1501 @param Dividend A 64-bit signed value.
1502 @param Divisor A 64-bit signed value.
1503 @param Remainder A pointer to a 64-bit signed value. This parameter is
1504 optional and may be NULL.
1505
1506 @return Dividend / Divisor
1507
1508 **/
1509 INT64
1510 EFIAPI
1511 DivS64x64Remainder (
1512 IN INT64 Dividend,
1513 IN INT64 Divisor,
1514 OUT INT64 *Remainder OPTIONAL
1515 );
1516
1517 /**
1518 Reads a 16-bit value from memory that may be unaligned.
1519
1520 This function returns the 16-bit value pointed to by Buffer. The function
1521 guarantees that the read operation does not produce an alignment fault.
1522
1523 If the Buffer is NULL, then ASSERT().
1524
1525 @param Buffer Pointer to a 16-bit value that may be unaligned.
1526
1527 @return *Uint16
1528
1529 **/
1530 UINT16
1531 EFIAPI
1532 ReadUnaligned16 (
1533 IN CONST UINT16 *Uint16
1534 );
1535
1536 /**
1537 Writes a 16-bit value to memory that may be unaligned.
1538
1539 This function writes the 16-bit value specified by Value to Buffer. Value is
1540 returned. The function guarantees that the write operation does not produce
1541 an alignment fault.
1542
1543 If the Buffer is NULL, then ASSERT().
1544
1545 @param Buffer Pointer to a 16-bit value that may be unaligned.
1546 @param Value 16-bit value to write to Buffer.
1547
1548 @return Value
1549
1550 **/
1551 UINT16
1552 EFIAPI
1553 WriteUnaligned16 (
1554 OUT UINT16 *Uint16,
1555 IN UINT16 Value
1556 );
1557
1558 /**
1559 Reads a 24-bit value from memory that may be unaligned.
1560
1561 This function returns the 24-bit value pointed to by Buffer. The function
1562 guarantees that the read operation does not produce an alignment fault.
1563
1564 If the Buffer is NULL, then ASSERT().
1565
1566 @param Buffer Pointer to a 24-bit value that may be unaligned.
1567
1568 @return The value read.
1569
1570 **/
1571 UINT32
1572 EFIAPI
1573 ReadUnaligned24 (
1574 IN CONST UINT32 *Buffer
1575 );
1576
1577 /**
1578 Writes a 24-bit value to memory that may be unaligned.
1579
1580 This function writes the 24-bit value specified by Value to Buffer. Value is
1581 returned. The function guarantees that the write operation does not produce
1582 an alignment fault.
1583
1584 If the Buffer is NULL, then ASSERT().
1585
1586 @param Buffer Pointer to a 24-bit value that may be unaligned.
1587 @param Value 24-bit value to write to Buffer.
1588
1589 @return The value written.
1590
1591 **/
1592 UINT32
1593 EFIAPI
1594 WriteUnaligned24 (
1595 OUT UINT32 *Buffer,
1596 IN UINT32 Value
1597 );
1598
1599 /**
1600 Reads a 32-bit value from memory that may be unaligned.
1601
1602 This function returns the 32-bit value pointed to by Buffer. The function
1603 guarantees that the read operation does not produce an alignment fault.
1604
1605 If the Buffer is NULL, then ASSERT().
1606
1607 @param Buffer Pointer to a 32-bit value that may be unaligned.
1608
1609 @return *Uint32
1610
1611 **/
1612 UINT32
1613 EFIAPI
1614 ReadUnaligned32 (
1615 IN CONST UINT32 *Uint32
1616 );
1617
1618 /**
1619 Writes a 32-bit value to memory that may be unaligned.
1620
1621 This function writes the 32-bit value specified by Value to Buffer. Value is
1622 returned. The function guarantees that the write operation does not produce
1623 an alignment fault.
1624
1625 If the Buffer is NULL, then ASSERT().
1626
1627 @param Buffer Pointer to a 32-bit value that may be unaligned.
1628 @param Value 32-bit value to write to Buffer.
1629
1630 @return Value
1631
1632 **/
1633 UINT32
1634 EFIAPI
1635 WriteUnaligned32 (
1636 OUT UINT32 *Uint32,
1637 IN UINT32 Value
1638 );
1639
1640 /**
1641 Reads a 64-bit value from memory that may be unaligned.
1642
1643 This function returns the 64-bit value pointed to by Buffer. The function
1644 guarantees that the read operation does not produce an alignment fault.
1645
1646 If the Buffer is NULL, then ASSERT().
1647
1648 @param Buffer Pointer to a 64-bit value that may be unaligned.
1649
1650 @return *Uint64
1651
1652 **/
1653 UINT64
1654 EFIAPI
1655 ReadUnaligned64 (
1656 IN CONST UINT64 *Uint64
1657 );
1658
1659 /**
1660 Writes a 64-bit value to memory that may be unaligned.
1661
1662 This function writes the 64-bit value specified by Value to Buffer. Value is
1663 returned. The function guarantees that the write operation does not produce
1664 an alignment fault.
1665
1666 If the Buffer is NULL, then ASSERT().
1667
1668 @param Buffer Pointer to a 64-bit value that may be unaligned.
1669 @param Value 64-bit value to write to Buffer.
1670
1671 @return Value
1672
1673 **/
1674 UINT64
1675 EFIAPI
1676 WriteUnaligned64 (
1677 OUT UINT64 *Uint64,
1678 IN UINT64 Value
1679 );
1680
1681 //
1682 // Bit Field Functions
1683 //
1684
1685 /**
1686 Returns a bit field from an 8-bit value.
1687
1688 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1689
1690 If 8-bit operations are not supported, then ASSERT().
1691 If StartBit is greater than 7, then ASSERT().
1692 If EndBit is greater than 7, then ASSERT().
1693 If EndBit is less than StartBit, then ASSERT().
1694
1695 @param Operand Operand on which to perform the bitfield operation.
1696 @param StartBit The ordinal of the least significant bit in the bit field.
1697 Range 0..7.
1698 @param EndBit The ordinal of the most significant bit in the bit field.
1699 Range 0..7.
1700
1701 @return The bit field read.
1702
1703 **/
1704 UINT8
1705 EFIAPI
1706 BitFieldRead8 (
1707 IN UINT8 Operand,
1708 IN UINTN StartBit,
1709 IN UINTN EndBit
1710 );
1711
1712 /**
1713 Writes a bit field to an 8-bit value, and returns the result.
1714
1715 Writes Value to the bit field specified by the StartBit and the EndBit in
1716 Operand. All other bits in Operand are preserved. The new 8-bit value is
1717 returned.
1718
1719 If 8-bit operations are not supported, then ASSERT().
1720 If StartBit is greater than 7, then ASSERT().
1721 If EndBit is greater than 7, then ASSERT().
1722 If EndBit is less than StartBit, then ASSERT().
1723
1724 @param Operand Operand on which to perform the bitfield operation.
1725 @param StartBit The ordinal of the least significant bit in the bit field.
1726 Range 0..7.
1727 @param EndBit The ordinal of the most significant bit in the bit field.
1728 Range 0..7.
1729 @param Value New value of the bit field.
1730
1731 @return The new 8-bit value.
1732
1733 **/
1734 UINT8
1735 EFIAPI
1736 BitFieldWrite8 (
1737 IN UINT8 Operand,
1738 IN UINTN StartBit,
1739 IN UINTN EndBit,
1740 IN UINT8 Value
1741 );
1742
1743 /**
1744 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
1745 result.
1746
1747 Performs a bitwise inclusive OR between the bit field specified by StartBit
1748 and EndBit in Operand and the value specified by OrData. All other bits in
1749 Operand are preserved. The new 8-bit value is returned.
1750
1751 If 8-bit operations are not supported, then ASSERT().
1752 If StartBit is greater than 7, then ASSERT().
1753 If EndBit is greater than 7, then ASSERT().
1754 If EndBit is less than StartBit, then ASSERT().
1755
1756 @param Operand Operand on which to perform the bitfield operation.
1757 @param StartBit The ordinal of the least significant bit in the bit field.
1758 Range 0..7.
1759 @param EndBit The ordinal of the most significant bit in the bit field.
1760 Range 0..7.
1761 @param OrData The value to OR with the read value from the value
1762
1763 @return The new 8-bit value.
1764
1765 **/
1766 UINT8
1767 EFIAPI
1768 BitFieldOr8 (
1769 IN UINT8 Operand,
1770 IN UINTN StartBit,
1771 IN UINTN EndBit,
1772 IN UINT8 OrData
1773 );
1774
1775 /**
1776 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
1777 the result.
1778
1779 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1780 in Operand and the value specified by AndData. All other bits in Operand are
1781 preserved. The new 8-bit value is returned.
1782
1783 If 8-bit operations are not supported, then ASSERT().
1784 If StartBit is greater than 7, then ASSERT().
1785 If EndBit is greater than 7, then ASSERT().
1786 If EndBit is less than StartBit, then ASSERT().
1787
1788 @param Operand Operand on which to perform the bitfield operation.
1789 @param StartBit The ordinal of the least significant bit in the bit field.
1790 Range 0..7.
1791 @param EndBit The ordinal of the most significant bit in the bit field.
1792 Range 0..7.
1793 @param AndData The value to AND with the read value from the value.
1794
1795 @return The new 8-bit value.
1796
1797 **/
1798 UINT8
1799 EFIAPI
1800 BitFieldAnd8 (
1801 IN UINT8 Operand,
1802 IN UINTN StartBit,
1803 IN UINTN EndBit,
1804 IN UINT8 AndData
1805 );
1806
1807 /**
1808 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
1809 bitwise OR, and returns the result.
1810
1811 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1812 in Operand and the value specified by AndData, followed by a bitwise
1813 inclusive OR with value specified by OrData. All other bits in Operand are
1814 preserved. The new 8-bit value is returned.
1815
1816 If 8-bit operations are not supported, then ASSERT().
1817 If StartBit is greater than 7, then ASSERT().
1818 If EndBit is greater than 7, then ASSERT().
1819 If EndBit is less than StartBit, then ASSERT().
1820
1821 @param Operand Operand on which to perform the bitfield operation.
1822 @param StartBit The ordinal of the least significant bit in the bit field.
1823 Range 0..7.
1824 @param EndBit The ordinal of the most significant bit in the bit field.
1825 Range 0..7.
1826 @param AndData The value to AND with the read value from the value.
1827 @param OrData The value to OR with the result of the AND operation.
1828
1829 @return The new 8-bit value.
1830
1831 **/
1832 UINT8
1833 EFIAPI
1834 BitFieldAndThenOr8 (
1835 IN UINT8 Operand,
1836 IN UINTN StartBit,
1837 IN UINTN EndBit,
1838 IN UINT8 AndData,
1839 IN UINT8 OrData
1840 );
1841
1842 /**
1843 Returns a bit field from a 16-bit value.
1844
1845 Returns the bitfield specified by the StartBit and the EndBit from Operand.
1846
1847 If 16-bit operations are not supported, then ASSERT().
1848 If StartBit is greater than 15, then ASSERT().
1849 If EndBit is greater than 15, then ASSERT().
1850 If EndBit is less than StartBit, then ASSERT().
1851
1852 @param Operand Operand on which to perform the bitfield operation.
1853 @param StartBit The ordinal of the least significant bit in the bit field.
1854 Range 0..15.
1855 @param EndBit The ordinal of the most significant bit in the bit field.
1856 Range 0..15.
1857
1858 @return The bit field read.
1859
1860 **/
1861 UINT16
1862 EFIAPI
1863 BitFieldRead16 (
1864 IN UINT16 Operand,
1865 IN UINTN StartBit,
1866 IN UINTN EndBit
1867 );
1868
1869 /**
1870 Writes a bit field to a 16-bit value, and returns the result.
1871
1872 Writes Value to the bit field specified by the StartBit and the EndBit in
1873 Operand. All other bits in Operand are preserved. The new 16-bit value is
1874 returned.
1875
1876 If 16-bit operations are not supported, then ASSERT().
1877 If StartBit is greater than 15, then ASSERT().
1878 If EndBit is greater than 15, then ASSERT().
1879 If EndBit is less than StartBit, then ASSERT().
1880
1881 @param Operand Operand on which to perform the bitfield operation.
1882 @param StartBit The ordinal of the least significant bit in the bit field.
1883 Range 0..15.
1884 @param EndBit The ordinal of the most significant bit in the bit field.
1885 Range 0..15.
1886 @param Value New value of the bit field.
1887
1888 @return The new 16-bit value.
1889
1890 **/
1891 UINT16
1892 EFIAPI
1893 BitFieldWrite16 (
1894 IN UINT16 Operand,
1895 IN UINTN StartBit,
1896 IN UINTN EndBit,
1897 IN UINT16 Value
1898 );
1899
1900 /**
1901 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
1902 result.
1903
1904 Performs a bitwise inclusive OR between the bit field specified by StartBit
1905 and EndBit in Operand and the value specified by OrData. All other bits in
1906 Operand are preserved. The new 16-bit value is returned.
1907
1908 If 16-bit operations are not supported, then ASSERT().
1909 If StartBit is greater than 15, then ASSERT().
1910 If EndBit is greater than 15, then ASSERT().
1911 If EndBit is less than StartBit, then ASSERT().
1912
1913 @param Operand Operand on which to perform the bitfield operation.
1914 @param StartBit The ordinal of the least significant bit in the bit field.
1915 Range 0..15.
1916 @param EndBit The ordinal of the most significant bit in the bit field.
1917 Range 0..15.
1918 @param OrData The value to OR with the read value from the value
1919
1920 @return The new 16-bit value.
1921
1922 **/
1923 UINT16
1924 EFIAPI
1925 BitFieldOr16 (
1926 IN UINT16 Operand,
1927 IN UINTN StartBit,
1928 IN UINTN EndBit,
1929 IN UINT16 OrData
1930 );
1931
1932 /**
1933 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
1934 the result.
1935
1936 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1937 in Operand and the value specified by AndData. All other bits in Operand are
1938 preserved. The new 16-bit value is returned.
1939
1940 If 16-bit operations are not supported, then ASSERT().
1941 If StartBit is greater than 15, then ASSERT().
1942 If EndBit is greater than 15, then ASSERT().
1943 If EndBit is less than StartBit, then ASSERT().
1944
1945 @param Operand Operand on which to perform the bitfield operation.
1946 @param StartBit The ordinal of the least significant bit in the bit field.
1947 Range 0..15.
1948 @param EndBit The ordinal of the most significant bit in the bit field.
1949 Range 0..15.
1950 @param AndData The value to AND with the read value from the value
1951
1952 @return The new 16-bit value.
1953
1954 **/
1955 UINT16
1956 EFIAPI
1957 BitFieldAnd16 (
1958 IN UINT16 Operand,
1959 IN UINTN StartBit,
1960 IN UINTN EndBit,
1961 IN UINT16 AndData
1962 );
1963
1964 /**
1965 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
1966 bitwise OR, and returns the result.
1967
1968 Performs a bitwise AND between the bit field specified by StartBit and EndBit
1969 in Operand and the value specified by AndData, followed by a bitwise
1970 inclusive OR with value specified by OrData. All other bits in Operand are
1971 preserved. The new 16-bit value is returned.
1972
1973 If 16-bit operations are not supported, then ASSERT().
1974 If StartBit is greater than 15, then ASSERT().
1975 If EndBit is greater than 15, then ASSERT().
1976 If EndBit is less than StartBit, then ASSERT().
1977
1978 @param Operand Operand on which to perform the bitfield operation.
1979 @param StartBit The ordinal of the least significant bit in the bit field.
1980 Range 0..15.
1981 @param EndBit The ordinal of the most significant bit in the bit field.
1982 Range 0..15.
1983 @param AndData The value to AND with the read value from the value.
1984 @param OrData The value to OR with the result of the AND operation.
1985
1986 @return The new 16-bit value.
1987
1988 **/
1989 UINT16
1990 EFIAPI
1991 BitFieldAndThenOr16 (
1992 IN UINT16 Operand,
1993 IN UINTN StartBit,
1994 IN UINTN EndBit,
1995 IN UINT16 AndData,
1996 IN UINT16 OrData
1997 );
1998
1999 /**
2000 Returns a bit field from a 32-bit value.
2001
2002 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2003
2004 If 32-bit operations are not supported, then ASSERT().
2005 If StartBit is greater than 31, then ASSERT().
2006 If EndBit is greater than 31, then ASSERT().
2007 If EndBit is less than StartBit, then ASSERT().
2008
2009 @param Operand Operand on which to perform the bitfield operation.
2010 @param StartBit The ordinal of the least significant bit in the bit field.
2011 Range 0..31.
2012 @param EndBit The ordinal of the most significant bit in the bit field.
2013 Range 0..31.
2014
2015 @return The bit field read.
2016
2017 **/
2018 UINT32
2019 EFIAPI
2020 BitFieldRead32 (
2021 IN UINT32 Operand,
2022 IN UINTN StartBit,
2023 IN UINTN EndBit
2024 );
2025
2026 /**
2027 Writes a bit field to a 32-bit value, and returns the result.
2028
2029 Writes Value to the bit field specified by the StartBit and the EndBit in
2030 Operand. All other bits in Operand are preserved. The new 32-bit value is
2031 returned.
2032
2033 If 32-bit operations are not supported, then ASSERT().
2034 If StartBit is greater than 31, then ASSERT().
2035 If EndBit is greater than 31, then ASSERT().
2036 If EndBit is less than StartBit, then ASSERT().
2037
2038 @param Operand Operand on which to perform the bitfield operation.
2039 @param StartBit The ordinal of the least significant bit in the bit field.
2040 Range 0..31.
2041 @param EndBit The ordinal of the most significant bit in the bit field.
2042 Range 0..31.
2043 @param Value New value of the bit field.
2044
2045 @return The new 32-bit value.
2046
2047 **/
2048 UINT32
2049 EFIAPI
2050 BitFieldWrite32 (
2051 IN UINT32 Operand,
2052 IN UINTN StartBit,
2053 IN UINTN EndBit,
2054 IN UINT32 Value
2055 );
2056
2057 /**
2058 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2059 result.
2060
2061 Performs a bitwise inclusive OR between the bit field specified by StartBit
2062 and EndBit in Operand and the value specified by OrData. All other bits in
2063 Operand are preserved. The new 32-bit value is returned.
2064
2065 If 32-bit operations are not supported, then ASSERT().
2066 If StartBit is greater than 31, then ASSERT().
2067 If EndBit is greater than 31, then ASSERT().
2068 If EndBit is less than StartBit, then ASSERT().
2069
2070 @param Operand Operand on which to perform the bitfield operation.
2071 @param StartBit The ordinal of the least significant bit in the bit field.
2072 Range 0..31.
2073 @param EndBit The ordinal of the most significant bit in the bit field.
2074 Range 0..31.
2075 @param OrData The value to OR with the read value from the value
2076
2077 @return The new 32-bit value.
2078
2079 **/
2080 UINT32
2081 EFIAPI
2082 BitFieldOr32 (
2083 IN UINT32 Operand,
2084 IN UINTN StartBit,
2085 IN UINTN EndBit,
2086 IN UINT32 OrData
2087 );
2088
2089 /**
2090 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2091 the result.
2092
2093 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2094 in Operand and the value specified by AndData. All other bits in Operand are
2095 preserved. The new 32-bit value is returned.
2096
2097 If 32-bit operations are not supported, then ASSERT().
2098 If StartBit is greater than 31, then ASSERT().
2099 If EndBit is greater than 31, then ASSERT().
2100 If EndBit is less than StartBit, then ASSERT().
2101
2102 @param Operand Operand on which to perform the bitfield operation.
2103 @param StartBit The ordinal of the least significant bit in the bit field.
2104 Range 0..31.
2105 @param EndBit The ordinal of the most significant bit in the bit field.
2106 Range 0..31.
2107 @param AndData The value to AND with the read value from the value
2108
2109 @return The new 32-bit value.
2110
2111 **/
2112 UINT32
2113 EFIAPI
2114 BitFieldAnd32 (
2115 IN UINT32 Operand,
2116 IN UINTN StartBit,
2117 IN UINTN EndBit,
2118 IN UINT32 AndData
2119 );
2120
2121 /**
2122 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2123 bitwise OR, and returns the result.
2124
2125 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2126 in Operand and the value specified by AndData, followed by a bitwise
2127 inclusive OR with value specified by OrData. All other bits in Operand are
2128 preserved. The new 32-bit value is returned.
2129
2130 If 32-bit operations are not supported, then ASSERT().
2131 If StartBit is greater than 31, then ASSERT().
2132 If EndBit is greater than 31, then ASSERT().
2133 If EndBit is less than StartBit, then ASSERT().
2134
2135 @param Operand Operand on which to perform the bitfield operation.
2136 @param StartBit The ordinal of the least significant bit in the bit field.
2137 Range 0..31.
2138 @param EndBit The ordinal of the most significant bit in the bit field.
2139 Range 0..31.
2140 @param AndData The value to AND with the read value from the value.
2141 @param OrData The value to OR with the result of the AND operation.
2142
2143 @return The new 32-bit value.
2144
2145 **/
2146 UINT32
2147 EFIAPI
2148 BitFieldAndThenOr32 (
2149 IN UINT32 Operand,
2150 IN UINTN StartBit,
2151 IN UINTN EndBit,
2152 IN UINT32 AndData,
2153 IN UINT32 OrData
2154 );
2155
2156 /**
2157 Returns a bit field from a 64-bit value.
2158
2159 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2160
2161 If 64-bit operations are not supported, then ASSERT().
2162 If StartBit is greater than 63, then ASSERT().
2163 If EndBit is greater than 63, then ASSERT().
2164 If EndBit is less than StartBit, then ASSERT().
2165
2166 @param Operand Operand on which to perform the bitfield operation.
2167 @param StartBit The ordinal of the least significant bit in the bit field.
2168 Range 0..63.
2169 @param EndBit The ordinal of the most significant bit in the bit field.
2170 Range 0..63.
2171
2172 @return The bit field read.
2173
2174 **/
2175 UINT64
2176 EFIAPI
2177 BitFieldRead64 (
2178 IN UINT64 Operand,
2179 IN UINTN StartBit,
2180 IN UINTN EndBit
2181 );
2182
2183 /**
2184 Writes a bit field to a 64-bit value, and returns the result.
2185
2186 Writes Value to the bit field specified by the StartBit and the EndBit in
2187 Operand. All other bits in Operand are preserved. The new 64-bit value is
2188 returned.
2189
2190 If 64-bit operations are not supported, then ASSERT().
2191 If StartBit is greater than 63, then ASSERT().
2192 If EndBit is greater than 63, then ASSERT().
2193 If EndBit is less than StartBit, then ASSERT().
2194
2195 @param Operand Operand on which to perform the bitfield operation.
2196 @param StartBit The ordinal of the least significant bit in the bit field.
2197 Range 0..63.
2198 @param EndBit The ordinal of the most significant bit in the bit field.
2199 Range 0..63.
2200 @param Value New value of the bit field.
2201
2202 @return The new 64-bit value.
2203
2204 **/
2205 UINT64
2206 EFIAPI
2207 BitFieldWrite64 (
2208 IN UINT64 Operand,
2209 IN UINTN StartBit,
2210 IN UINTN EndBit,
2211 IN UINT64 Value
2212 );
2213
2214 /**
2215 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2216 result.
2217
2218 Performs a bitwise inclusive OR between the bit field specified by StartBit
2219 and EndBit in Operand and the value specified by OrData. All other bits in
2220 Operand are preserved. The new 64-bit value is returned.
2221
2222 If 64-bit operations are not supported, then ASSERT().
2223 If StartBit is greater than 63, then ASSERT().
2224 If EndBit is greater than 63, then ASSERT().
2225 If EndBit is less than StartBit, then ASSERT().
2226
2227 @param Operand Operand on which to perform the bitfield operation.
2228 @param StartBit The ordinal of the least significant bit in the bit field.
2229 Range 0..63.
2230 @param EndBit The ordinal of the most significant bit in the bit field.
2231 Range 0..63.
2232 @param OrData The value to OR with the read value from the value
2233
2234 @return The new 64-bit value.
2235
2236 **/
2237 UINT64
2238 EFIAPI
2239 BitFieldOr64 (
2240 IN UINT64 Operand,
2241 IN UINTN StartBit,
2242 IN UINTN EndBit,
2243 IN UINT64 OrData
2244 );
2245
2246 /**
2247 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2248 the result.
2249
2250 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2251 in Operand and the value specified by AndData. All other bits in Operand are
2252 preserved. The new 64-bit value is returned.
2253
2254 If 64-bit operations are not supported, then ASSERT().
2255 If StartBit is greater than 63, then ASSERT().
2256 If EndBit is greater than 63, then ASSERT().
2257 If EndBit is less than StartBit, then ASSERT().
2258
2259 @param Operand Operand on which to perform the bitfield operation.
2260 @param StartBit The ordinal of the least significant bit in the bit field.
2261 Range 0..63.
2262 @param EndBit The ordinal of the most significant bit in the bit field.
2263 Range 0..63.
2264 @param AndData The value to AND with the read value from the value
2265
2266 @return The new 64-bit value.
2267
2268 **/
2269 UINT64
2270 EFIAPI
2271 BitFieldAnd64 (
2272 IN UINT64 Operand,
2273 IN UINTN StartBit,
2274 IN UINTN EndBit,
2275 IN UINT64 AndData
2276 );
2277
2278 /**
2279 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2280 bitwise OR, and returns the result.
2281
2282 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2283 in Operand and the value specified by AndData, followed by a bitwise
2284 inclusive OR with value specified by OrData. All other bits in Operand are
2285 preserved. The new 64-bit value is returned.
2286
2287 If 64-bit operations are not supported, then ASSERT().
2288 If StartBit is greater than 63, then ASSERT().
2289 If EndBit is greater than 63, then ASSERT().
2290 If EndBit is less than StartBit, then ASSERT().
2291
2292 @param Operand Operand on which to perform the bitfield operation.
2293 @param StartBit The ordinal of the least significant bit in the bit field.
2294 Range 0..63.
2295 @param EndBit The ordinal of the most significant bit in the bit field.
2296 Range 0..63.
2297 @param AndData The value to AND with the read value from the value.
2298 @param OrData The value to OR with the result of the AND operation.
2299
2300 @return The new 64-bit value.
2301
2302 **/
2303 UINT64
2304 EFIAPI
2305 BitFieldAndThenOr64 (
2306 IN UINT64 Operand,
2307 IN UINTN StartBit,
2308 IN UINTN EndBit,
2309 IN UINT64 AndData,
2310 IN UINT64 OrData
2311 );
2312
2313 //
2314 // Base Library Synchronization Functions
2315 //
2316
2317 /**
2318 Retrieves the architecture specific spin lock alignment requirements for
2319 optimal spin lock performance.
2320
2321 This function retrieves the spin lock alignment requirements for optimal
2322 performance on a given CPU architecture. The spin lock alignment must be a
2323 power of two and is returned by this function. If there are no alignment
2324 requirements, then 1 must be returned. The spin lock synchronization
2325 functions must function correctly if the spin lock size and alignment values
2326 returned by this function are not used at all. These values are hints to the
2327 consumers of the spin lock synchronization functions to obtain optimal spin
2328 lock performance.
2329
2330 @return The architecture specific spin lock alignment.
2331
2332 **/
2333 UINTN
2334 EFIAPI
2335 GetSpinLockProperties (
2336 VOID
2337 );
2338
2339 /**
2340 Initializes a spin lock to the released state and returns the spin lock.
2341
2342 This function initializes the spin lock specified by SpinLock to the released
2343 state, and returns SpinLock. Optimal performance can be achieved by calling
2344 GetSpinLockProperties() to determine the size and alignment requirements for
2345 SpinLock.
2346
2347 If SpinLock is NULL, then ASSERT().
2348
2349 @param SpinLock A pointer to the spin lock to initialize to the released
2350 state.
2351
2352 @return SpinLock
2353
2354 **/
2355 SPIN_LOCK *
2356 EFIAPI
2357 InitializeSpinLock (
2358 IN SPIN_LOCK *SpinLock
2359 );
2360
2361 /**
2362 Waits until a spin lock can be placed in the acquired state.
2363
2364 This function checks the state of the spin lock specified by SpinLock. If
2365 SpinLock is in the released state, then this function places SpinLock in the
2366 acquired state and returns SpinLock. Otherwise, this function waits
2367 indefinitely for the spin lock to be released, and then places it in the
2368 acquired state and returns SpinLock. All state transitions of SpinLock must
2369 be performed using MP safe mechanisms.
2370
2371 If SpinLock is NULL, then ASSERT().
2372 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2373 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2374 PcdSpinLockTimeout microseconds, then ASSERT().
2375
2376 @param SpinLock A pointer to the spin lock to place in the acquired state.
2377
2378 @return SpinLock
2379
2380 **/
2381 SPIN_LOCK *
2382 EFIAPI
2383 AcquireSpinLock (
2384 IN SPIN_LOCK *SpinLock
2385 );
2386
2387 /**
2388 Attempts to place a spin lock in the acquired state.
2389
2390 This function checks the state of the spin lock specified by SpinLock. If
2391 SpinLock is in the released state, then this function places SpinLock in the
2392 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2393 transitions of SpinLock must be performed using MP safe mechanisms.
2394
2395 If SpinLock is NULL, then ASSERT().
2396 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2397
2398 @param SpinLock A pointer to the spin lock to place in the acquired state.
2399
2400 @retval TRUE SpinLock was placed in the acquired state.
2401 @retval FALSE SpinLock could not be acquired.
2402
2403 **/
2404 BOOLEAN
2405 EFIAPI
2406 AcquireSpinLockOrFail (
2407 IN SPIN_LOCK *SpinLock
2408 );
2409
2410 /**
2411 Releases a spin lock.
2412
2413 This function places the spin lock specified by SpinLock in the release state
2414 and returns SpinLock.
2415
2416 If SpinLock is NULL, then ASSERT().
2417 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2418
2419 @param SpinLock A pointer to the spin lock to release.
2420
2421 @return SpinLock
2422
2423 **/
2424 SPIN_LOCK *
2425 EFIAPI
2426 ReleaseSpinLock (
2427 IN SPIN_LOCK *SpinLock
2428 );
2429
2430 /**
2431 Performs an atomic increment of an 32-bit unsigned integer.
2432
2433 Performs an atomic increment of the 32-bit unsigned integer specified by
2434 Value and returns the incremented value. The increment operation must be
2435 performed using MP safe mechanisms. The state of the return value is not
2436 guaranteed to be MP safe.
2437
2438 If Value is NULL, then ASSERT().
2439
2440 @param Value A pointer to the 32-bit value to increment.
2441
2442 @return The incremented value.
2443
2444 **/
2445 UINT32
2446 EFIAPI
2447 InterlockedIncrement (
2448 IN UINT32 *Value
2449 );
2450
2451 /**
2452 Performs an atomic decrement of an 32-bit unsigned integer.
2453
2454 Performs an atomic decrement of the 32-bit unsigned integer specified by
2455 Value and returns the decremented value. The decrement operation must be
2456 performed using MP safe mechanisms. The state of the return value is not
2457 guaranteed to be MP safe.
2458
2459 If Value is NULL, then ASSERT().
2460
2461 @param Value A pointer to the 32-bit value to decrement.
2462
2463 @return The decremented value.
2464
2465 **/
2466 UINT32
2467 EFIAPI
2468 InterlockedDecrement (
2469 IN UINT32 *Value
2470 );
2471
2472 /**
2473 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
2474
2475 Performs an atomic compare exchange operation on the 32-bit unsigned integer
2476 specified by Value. If Value is equal to CompareValue, then Value is set to
2477 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
2478 then Value is returned. The compare exchange operation must be performed using
2479 MP safe mechanisms.
2480
2481 If Value is NULL, then ASSERT().
2482
2483 @param Value A pointer to the 32-bit value for the compare exchange
2484 operation.
2485 @param CompareValue 32-bit value used in compare operation.
2486 @param ExchangeValue 32-bit value used in exchange operation.
2487
2488 @return The original *Value before exchange.
2489
2490 **/
2491 UINT32
2492 EFIAPI
2493 InterlockedCompareExchange32 (
2494 IN OUT UINT32 *Value,
2495 IN UINT32 CompareValue,
2496 IN UINT32 ExchangeValue
2497 );
2498
2499 /**
2500 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
2501
2502 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
2503 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
2504 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
2505 The compare exchange operation must be performed using MP safe mechanisms.
2506
2507 If Value is NULL, then ASSERT().
2508
2509 @param Value A pointer to the 64-bit value for the compare exchange
2510 operation.
2511 @param CompareValue 64-bit value used in compare operation.
2512 @param ExchangeValue 64-bit value used in exchange operation.
2513
2514 @return The original *Value before exchange.
2515
2516 **/
2517 UINT64
2518 EFIAPI
2519 InterlockedCompareExchange64 (
2520 IN OUT UINT64 *Value,
2521 IN UINT64 CompareValue,
2522 IN UINT64 ExchangeValue
2523 );
2524
2525 /**
2526 Performs an atomic compare exchange operation on a pointer value.
2527
2528 Performs an atomic compare exchange operation on the pointer value specified
2529 by Value. If Value is equal to CompareValue, then Value is set to
2530 ExchangeValue and CompareValue is returned. If Value is not equal to
2531 CompareValue, then Value is returned. The compare exchange operation must be
2532 performed using MP safe mechanisms.
2533
2534 If Value is NULL, then ASSERT().
2535
2536 @param Value A pointer to the pointer value for the compare exchange
2537 operation.
2538 @param CompareValue Pointer value used in compare operation.
2539 @param ExchangeValue Pointer value used in exchange operation.
2540
2541 **/
2542 VOID *
2543 EFIAPI
2544 InterlockedCompareExchangePointer (
2545 IN OUT VOID **Value,
2546 IN VOID *CompareValue,
2547 IN VOID *ExchangeValue
2548 );
2549
2550 //
2551 // Base Library CPU Functions
2552 //
2553 typedef
2554 VOID
2555 (EFIAPI *SWITCH_STACK_ENTRY_POINT) (
2556 IN VOID *Context1, OPTIONAL
2557 IN VOID *Context2 OPTIONAL
2558 );
2559
2560 /**
2561 Used to serialize load and store operations.
2562
2563 All loads and stores that proceed calls to this function are guaranteed to be
2564 globally visible when this function returns.
2565
2566 **/
2567 VOID
2568 EFIAPI
2569 MemoryFence (
2570 VOID
2571 );
2572
2573 /**
2574 Saves the current CPU context that can be restored with a call to LongJump()
2575 and returns 0.
2576
2577 Saves the current CPU context in the buffer specified by JumpBuffer and
2578 returns 0. The initial call to SetJump() must always return 0. Subsequent
2579 calls to LongJump() cause a non-zero value to be returned by SetJump().
2580
2581 If JumpBuffer is NULL, then ASSERT().
2582 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2583
2584 @param JumpBuffer A pointer to CPU context buffer.
2585
2586 @retval 0 Indicates a return from SetJump().
2587
2588 **/
2589 UINTN
2590 EFIAPI
2591 SetJump (
2592 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
2593 );
2594
2595 /**
2596 Restores the CPU context that was saved with SetJump().
2597
2598 Restores the CPU context from the buffer specified by JumpBuffer. This
2599 function never returns to the caller. Instead is resumes execution based on
2600 the state of JumpBuffer.
2601
2602 If JumpBuffer is NULL, then ASSERT().
2603 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
2604 If Value is 0, then ASSERT().
2605
2606 @param JumpBuffer A pointer to CPU context buffer.
2607 @param Value The value to return when the SetJump() context is
2608 restored and must be non-zero.
2609
2610 **/
2611 VOID
2612 EFIAPI
2613 LongJump (
2614 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
2615 IN UINTN Value
2616 );
2617
2618 /**
2619 Enables CPU interrupts.
2620
2621 Enables CPU interrupts.
2622
2623 **/
2624 VOID
2625 EFIAPI
2626 EnableInterrupts (
2627 VOID
2628 );
2629
2630 /**
2631 Disables CPU interrupts.
2632
2633 Disables CPU interrupts.
2634
2635 **/
2636 VOID
2637 EFIAPI
2638 DisableInterrupts (
2639 VOID
2640 );
2641
2642 /**
2643 Disables CPU interrupts and returns the interrupt state prior to the disable
2644 operation.
2645
2646 Disables CPU interrupts and returns the interrupt state prior to the disable
2647 operation.
2648
2649 @retval TRUE CPU interrupts were enabled on entry to this call.
2650 @retval FALSE CPU interrupts were disabled on entry to this call.
2651
2652 **/
2653 BOOLEAN
2654 EFIAPI
2655 SaveAndDisableInterrupts (
2656 VOID
2657 );
2658
2659 /**
2660 Enables CPU interrupts for the smallest window required to capture any
2661 pending interrupts.
2662
2663 Enables CPU interrupts for the smallest window required to capture any
2664 pending interrupts.
2665
2666 **/
2667 VOID
2668 EFIAPI
2669 EnableDisableInterrupts (
2670 VOID
2671 );
2672
2673 /**
2674 Retrieves the current CPU interrupt state.
2675
2676 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
2677 currently enabled. Otherwise returns FALSE.
2678
2679 @retval TRUE CPU interrupts are enabled.
2680 @retval FALSE CPU interrupts are disabled.
2681
2682 **/
2683 BOOLEAN
2684 EFIAPI
2685 GetInterruptState (
2686 VOID
2687 );
2688
2689 /**
2690 Set the current CPU interrupt state.
2691
2692 Sets the current CPU interrupt state to the state specified by
2693 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
2694 InterruptState is FALSE, then interrupts are disabled. InterruptState is
2695 returned.
2696
2697 @param InterruptState TRUE if interrupts should enabled. FALSE if
2698 interrupts should be disabled.
2699
2700 @return InterruptState
2701
2702 **/
2703 BOOLEAN
2704 EFIAPI
2705 SetInterruptState (
2706 IN BOOLEAN InterruptState
2707 );
2708
2709 /**
2710 Places the CPU in a sleep state until an interrupt is received.
2711
2712 Places the CPU in a sleep state until an interrupt is received. If interrupts
2713 are disabled prior to calling this function, then the CPU will be placed in a
2714 sleep state indefinitely.
2715
2716 **/
2717 VOID
2718 EFIAPI
2719 CpuSleep (
2720 VOID
2721 );
2722
2723 /**
2724 Requests CPU to pause for a short period of time.
2725
2726 Requests CPU to pause for a short period of time. Typically used in MP
2727 systems to prevent memory starvation while waiting for a spin lock.
2728
2729 **/
2730 VOID
2731 EFIAPI
2732 CpuPause (
2733 VOID
2734 );
2735
2736 /**
2737 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2738
2739 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
2740
2741 **/
2742 VOID
2743 EFIAPI
2744 CpuFlushTlb (
2745 VOID
2746 );
2747
2748 /**
2749 Transfers control to a function starting with a new stack.
2750
2751 Transfers control to the function specified by EntryPoint using the new stack
2752 specified by NewStack and passing in the parameters specified by Context1 and
2753 Context2. Context1 and Context2 are optional and may be NULL. The function
2754 EntryPoint must never return.
2755
2756 If EntryPoint is NULL, then ASSERT().
2757 If NewStack is NULL, then ASSERT().
2758
2759 @param EntryPoint A pointer to function to call with the new stack.
2760 @param Context1 A pointer to the context to pass into the EntryPoint
2761 function.
2762 @param Context2 A pointer to the context to pass into the EntryPoint
2763 function.
2764 @param NewStack A pointer to the new stack to use for the EntryPoint
2765 function.
2766
2767 **/
2768 VOID
2769 EFIAPI
2770 SwitchStack (
2771 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
2772 IN VOID *Context1, OPTIONAL
2773 IN VOID *Context2, OPTIONAL
2774 IN VOID *NewStack
2775 );
2776
2777 /**
2778 Generates a breakpoint on the CPU.
2779
2780 Generates a breakpoint on the CPU. The breakpoint must be implemented such
2781 that code can resume normal execution after the breakpoint.
2782
2783 **/
2784 VOID
2785 EFIAPI
2786 CpuBreakpoint (
2787 VOID
2788 );
2789
2790 /**
2791 Executes an infinite loop.
2792
2793 Forces the CPU to execute an infinite loop. A debugger may be used to skip
2794 past the loop and the code that follows the loop must execute properly. This
2795 implies that the infinite loop must not cause the code that follow it to be
2796 optimized away.
2797
2798 **/
2799 VOID
2800 EFIAPI
2801 CpuDeadLoop (
2802 VOID
2803 );
2804
2805 //
2806 // IA32 and X64 Specific Functions
2807 //
2808 //
2809 // Byte packed structure for 16-bit Real Mode EFLAGS
2810 //
2811 typedef union {
2812 struct {
2813 UINT32 CF:1; // Carry Flag
2814 UINT32 Reserved_0:1; // Reserved
2815 UINT32 PF:1; // Parity Flag
2816 UINT32 Reserved_1:1; // Reserved
2817 UINT32 AF:1; // Auxiliary Carry Flag
2818 UINT32 Reserved_2:1; // Reserved
2819 UINT32 ZF:1; // Zero Flag
2820 UINT32 SF:1; // Sign Flag
2821 UINT32 TF:1; // Trap Flag
2822 UINT32 IF:1; // Interrupt Enable Flag
2823 UINT32 DF:1; // Direction Flag
2824 UINT32 OF:1; // Overflow Flag
2825 UINT32 IOPL:2; // I/O Privilege Level
2826 UINT32 NT:1; // Nested Task
2827 UINT32 Reserved_3:1; // Reserved
2828 } Bits;
2829 UINT16 Uint16;
2830 } IA32_FLAGS16;
2831
2832 //
2833 // Byte packed structure for EFLAGS/RFLAGS
2834 // 32-bits on IA-32
2835 // 64-bits on X64. The upper 32-bits on X64 are reserved
2836 //
2837 typedef union {
2838 struct {
2839 UINT32 CF:1; // Carry Flag
2840 UINT32 Reserved_0:1; // Reserved
2841 UINT32 PF:1; // Parity Flag
2842 UINT32 Reserved_1:1; // Reserved
2843 UINT32 AF:1; // Auxiliary Carry Flag
2844 UINT32 Reserved_2:1; // Reserved
2845 UINT32 ZF:1; // Zero Flag
2846 UINT32 SF:1; // Sign Flag
2847 UINT32 TF:1; // Trap Flag
2848 UINT32 IF:1; // Interrupt Enable Flag
2849 UINT32 DF:1; // Direction Flag
2850 UINT32 OF:1; // Overflow Flag
2851 UINT32 IOPL:2; // I/O Privilege Level
2852 UINT32 NT:1; // Nested Task
2853 UINT32 Reserved_3:1; // Reserved
2854 UINT32 RF:1; // Resume Flag
2855 UINT32 VM:1; // Virtual 8086 Mode
2856 UINT32 AC:1; // Alignment Check
2857 UINT32 VIF:1; // Virtual Interrupt Flag
2858 UINT32 VIP:1; // Virtual Interrupt Pending
2859 UINT32 ID:1; // ID Flag
2860 UINT32 Reserved_4:10; // Reserved
2861 } Bits;
2862 UINTN UintN;
2863 } IA32_EFLAGS32;
2864
2865 //
2866 // Byte packed structure for Control Register 0 (CR0)
2867 // 32-bits on IA-32
2868 // 64-bits on X64. The upper 32-bits on X64 are reserved
2869 //
2870 typedef union {
2871 struct {
2872 UINT32 PE:1; // Protection Enable
2873 UINT32 MP:1; // Monitor Coprocessor
2874 UINT32 EM:1; // Emulation
2875 UINT32 TS:1; // Task Switched
2876 UINT32 ET:1; // Extension Type
2877 UINT32 NE:1; // Numeric Error
2878 UINT32 Reserved_0:10; // Reserved
2879 UINT32 WP:1; // Write Protect
2880 UINT32 Reserved_1:1; // Reserved
2881 UINT32 AM:1; // Alignment Mask
2882 UINT32 Reserved_2:10; // Reserved
2883 UINT32 NW:1; // Mot Write-through
2884 UINT32 CD:1; // Cache Disable
2885 UINT32 PG:1; // Paging
2886 } Bits;
2887 UINTN UintN;
2888 } IA32_CR0;
2889
2890 //
2891 // Byte packed structure for Control Register 4 (CR4)
2892 // 32-bits on IA-32
2893 // 64-bits on X64. The upper 32-bits on X64 are reserved
2894 //
2895 typedef union {
2896 struct {
2897 UINT32 VME:1; // Virtual-8086 Mode Extensions
2898 UINT32 PVI:1; // Protected-Mode Virtual Interrupts
2899 UINT32 TSD:1; // Time Stamp Disable
2900 UINT32 DE:1; // Debugging Extensions
2901 UINT32 PSE:1; // Page Size Extensions
2902 UINT32 PAE:1; // Physical Address Extension
2903 UINT32 MCE:1; // Machine Check Enable
2904 UINT32 PGE:1; // Page Global Enable
2905 UINT32 PCE:1; // Performance Monitoring Counter
2906 // Enable
2907 UINT32 OSFXSR:1; // Operating System Support for
2908 // FXSAVE and FXRSTOR instructions
2909 UINT32 OSXMMEXCPT:1; // Operating System Support for
2910 // Unmasked SIMD Floating Point
2911 // Exceptions
2912 UINT32 Reserved_0:2; // Reserved
2913 UINT32 VMXE:1; // VMX Enable
2914 UINT32 Reserved_1:18; // Reseved
2915 } Bits;
2916 UINTN UintN;
2917 } IA32_CR4;
2918
2919 //
2920 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
2921 /// @bug How to make this structure byte-packed in a compiler independent way?
2922 //
2923 #pragma pack (1)
2924 typedef struct {
2925 UINT16 Limit;
2926 UINTN Base;
2927 } IA32_DESCRIPTOR;
2928 #pragma pack ()
2929
2930 #define IA32_IDT_GATE_TYPE_TASK 0x85
2931 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
2932 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
2933 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
2934 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
2935
2936 //
2937 // Byte packed structure for an Interrupt Gate Descriptor
2938 //
2939 typedef union {
2940 struct {
2941 UINT32 OffsetLow:16; // Offset bits 15..0
2942 UINT32 Selector:16; // Selector
2943 UINT32 Reserved_0:8; // Reserved
2944 UINT32 GateType:8; // Gate Type. See #defines above
2945 UINT32 OffsetHigh:16; // Offset bits 31..16
2946 } Bits;
2947 UINT64 Uint64;
2948 } IA32_IDT_GATE_DESCRIPTOR;
2949
2950 //
2951 // Byte packed structure for an FP/SSE/SSE2 context
2952 //
2953 typedef struct {
2954 UINT8 Buffer[512];
2955 } IA32_FX_BUFFER;
2956
2957 //
2958 // Structures for the 16-bit real mode thunks
2959 //
2960 typedef struct {
2961 UINT32 Reserved1;
2962 UINT32 Reserved2;
2963 UINT32 Reserved3;
2964 UINT32 Reserved4;
2965 UINT8 BL;
2966 UINT8 BH;
2967 UINT16 Reserved5;
2968 UINT8 DL;
2969 UINT8 DH;
2970 UINT16 Reserved6;
2971 UINT8 CL;
2972 UINT8 CH;
2973 UINT16 Reserved7;
2974 UINT8 AL;
2975 UINT8 AH;
2976 UINT16 Reserved8;
2977 } IA32_BYTE_REGS;
2978
2979 typedef struct {
2980 UINT16 DI;
2981 UINT16 Reserved1;
2982 UINT16 SI;
2983 UINT16 Reserved2;
2984 UINT16 BP;
2985 UINT16 Reserved3;
2986 UINT16 SP;
2987 UINT16 Reserved4;
2988 UINT16 BX;
2989 UINT16 Reserved5;
2990 UINT16 DX;
2991 UINT16 Reserved6;
2992 UINT16 CX;
2993 UINT16 Reserved7;
2994 UINT16 AX;
2995 UINT16 Reserved8;
2996 } IA32_WORD_REGS;
2997
2998 typedef struct {
2999 UINT32 EDI;
3000 UINT32 ESI;
3001 UINT32 EBP;
3002 UINT32 ESP;
3003 UINT32 EBX;
3004 UINT32 EDX;
3005 UINT32 ECX;
3006 UINT32 EAX;
3007 UINT16 DS;
3008 UINT16 ES;
3009 UINT16 FS;
3010 UINT16 GS;
3011 IA32_EFLAGS32 EFLAGS;
3012 UINT32 Eip;
3013 UINT16 CS;
3014 UINT16 SS;
3015 } IA32_DWORD_REGS;
3016
3017 typedef union {
3018 IA32_DWORD_REGS E;
3019 IA32_WORD_REGS X;
3020 IA32_BYTE_REGS H;
3021 } IA32_REGISTER_SET;
3022
3023 //
3024 // Byte packed structure for an 16-bit real mode thunks
3025 //
3026 typedef struct {
3027 IA32_REGISTER_SET *RealModeState;
3028 VOID *RealModeBuffer;
3029 UINT32 RealModeBufferSize;
3030 UINT32 ThunkAttributes;
3031 } THUNK_CONTEXT;
3032
3033 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
3034 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
3035 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3036
3037 /**
3038 Retrieves CPUID information.
3039
3040 Executes the CPUID instruction with EAX set to the value specified by Index.
3041 This function always returns Index.
3042 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3043 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3044 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3045 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3046 This function is only available on IA-32 and X64.
3047
3048 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3049 instruction.
3050 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3051 instruction. This is an optional parameter that may be NULL.
3052 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3053 instruction. This is an optional parameter that may be NULL.
3054 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3055 instruction. This is an optional parameter that may be NULL.
3056 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3057 instruction. This is an optional parameter that may be NULL.
3058
3059 @return Index
3060
3061 **/
3062 UINT32
3063 EFIAPI
3064 AsmCpuid (
3065 IN UINT32 Index,
3066 OUT UINT32 *Eax, OPTIONAL
3067 OUT UINT32 *Ebx, OPTIONAL
3068 OUT UINT32 *Ecx, OPTIONAL
3069 OUT UINT32 *Edx OPTIONAL
3070 );
3071
3072 /**
3073 Retrieves CPUID information using an extended leaf identifier.
3074
3075 Executes the CPUID instruction with EAX set to the value specified by Index
3076 and ECX set to the value specified by SubIndex. This function always returns
3077 Index. This function is only available on IA-32 and x64.
3078
3079 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3080 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3081 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3082 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3083
3084 @param Index The 32-bit value to load into EAX prior to invoking the
3085 CPUID instruction.
3086 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3087 CPUID instruction.
3088 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3089 instruction. This is an optional parameter that may be
3090 NULL.
3091 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3092 instruction. This is an optional parameter that may be
3093 NULL.
3094 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3095 instruction. This is an optional parameter that may be
3096 NULL.
3097 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3098 instruction. This is an optional parameter that may be
3099 NULL.
3100
3101 @return Index
3102
3103 **/
3104 UINT32
3105 EFIAPI
3106 AsmCpuidEx (
3107 IN UINT32 Index,
3108 IN UINT32 SubIndex,
3109 OUT UINT32 *Eax, OPTIONAL
3110 OUT UINT32 *Ebx, OPTIONAL
3111 OUT UINT32 *Ecx, OPTIONAL
3112 OUT UINT32 *Edx OPTIONAL
3113 );
3114
3115 /**
3116 Returns the lower 32-bits of a Machine Specific Register(MSR).
3117
3118 Reads and returns the lower 32-bits of the MSR specified by Index.
3119 No parameter checking is performed on Index, and some Index values may cause
3120 CPU exceptions. The caller must either guarantee that Index is valid, or the
3121 caller must set up exception handlers to catch the exceptions. This function
3122 is only available on IA-32 and X64.
3123
3124 @param Index The 32-bit MSR index to read.
3125
3126 @return The lower 32 bits of the MSR identified by Index.
3127
3128 **/
3129 UINT32
3130 EFIAPI
3131 AsmReadMsr32 (
3132 IN UINT32 Index
3133 );
3134
3135 /**
3136 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3137
3138 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3139 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3140 the MSR is returned. No parameter checking is performed on Index or Value,
3141 and some of these may cause CPU exceptions. The caller must either guarantee
3142 that Index and Value are valid, or the caller must establish proper exception
3143 handlers. This function is only available on IA-32 and X64.
3144
3145 @param Index The 32-bit MSR index to write.
3146 @param Value The 32-bit value to write to the MSR.
3147
3148 @return Value
3149
3150 **/
3151 UINT32
3152 EFIAPI
3153 AsmWriteMsr32 (
3154 IN UINT32 Index,
3155 IN UINT32 Value
3156 );
3157
3158 /**
3159 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3160 writes the result back to the 64-bit MSR.
3161
3162 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3163 between the lower 32-bits of the read result and the value specified by
3164 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3165 32-bits of the value written to the MSR is returned. No parameter checking is
3166 performed on Index or OrData, and some of these may cause CPU exceptions. The
3167 caller must either guarantee that Index and OrData are valid, or the caller
3168 must establish proper exception handlers. This function is only available on
3169 IA-32 and X64.
3170
3171 @param Index The 32-bit MSR index to write.
3172 @param OrData The value to OR with the read value from the MSR.
3173
3174 @return The lower 32-bit value written to the MSR.
3175
3176 **/
3177 UINT32
3178 EFIAPI
3179 AsmMsrOr32 (
3180 IN UINT32 Index,
3181 IN UINT32 OrData
3182 );
3183
3184 /**
3185 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3186 the result back to the 64-bit MSR.
3187
3188 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3189 lower 32-bits of the read result and the value specified by AndData, and
3190 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3191 the value written to the MSR is returned. No parameter checking is performed
3192 on Index or AndData, and some of these may cause CPU exceptions. The caller
3193 must either guarantee that Index and AndData are valid, or the caller must
3194 establish proper exception handlers. This function is only available on IA-32
3195 and X64.
3196
3197 @param Index The 32-bit MSR index to write.
3198 @param AndData The value to AND with the read value from the MSR.
3199
3200 @return The lower 32-bit value written to the MSR.
3201
3202 **/
3203 UINT32
3204 EFIAPI
3205 AsmMsrAnd32 (
3206 IN UINT32 Index,
3207 IN UINT32 AndData
3208 );
3209
3210 /**
3211 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3212 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3213
3214 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3215 lower 32-bits of the read result and the value specified by AndData
3216 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3217 result of the AND operation and the value specified by OrData, and writes the
3218 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3219 written to the MSR is returned. No parameter checking is performed on Index,
3220 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3221 must either guarantee that Index, AndData, and OrData are valid, or the
3222 caller must establish proper exception handlers. This function is only
3223 available on IA-32 and X64.
3224
3225 @param Index The 32-bit MSR index to write.
3226 @param AndData The value to AND with the read value from the MSR.
3227 @param OrData The value to OR with the result of the AND operation.
3228
3229 @return The lower 32-bit value written to the MSR.
3230
3231 **/
3232 UINT32
3233 EFIAPI
3234 AsmMsrAndThenOr32 (
3235 IN UINT32 Index,
3236 IN UINT32 AndData,
3237 IN UINT32 OrData
3238 );
3239
3240 /**
3241 Reads a bit field of an MSR.
3242
3243 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3244 specified by the StartBit and the EndBit. The value of the bit field is
3245 returned. The caller must either guarantee that Index is valid, or the caller
3246 must set up exception handlers to catch the exceptions. This function is only
3247 available on IA-32 and X64.
3248
3249 If StartBit is greater than 31, then ASSERT().
3250 If EndBit is greater than 31, then ASSERT().
3251 If EndBit is less than StartBit, then ASSERT().
3252
3253 @param Index The 32-bit MSR index to read.
3254 @param StartBit The ordinal of the least significant bit in the bit field.
3255 Range 0..31.
3256 @param EndBit The ordinal of the most significant bit in the bit field.
3257 Range 0..31.
3258
3259 @return The bit field read from the MSR.
3260
3261 **/
3262 UINT32
3263 EFIAPI
3264 AsmMsrBitFieldRead32 (
3265 IN UINT32 Index,
3266 IN UINTN StartBit,
3267 IN UINTN EndBit
3268 );
3269
3270 /**
3271 Writes a bit field to an MSR.
3272
3273 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3274 field is specified by the StartBit and the EndBit. All other bits in the
3275 destination MSR are preserved. The lower 32-bits of the MSR written is
3276 returned. Extra left bits in Value are stripped. The caller must either
3277 guarantee that Index and the data written is valid, or the caller must set up
3278 exception handlers to catch the exceptions. This function is only available
3279 on IA-32 and X64.
3280
3281 If StartBit is greater than 31, then ASSERT().
3282 If EndBit is greater than 31, then ASSERT().
3283 If EndBit is less than StartBit, then ASSERT().
3284
3285 @param Index The 32-bit MSR index to write.
3286 @param StartBit The ordinal of the least significant bit in the bit field.
3287 Range 0..31.
3288 @param EndBit The ordinal of the most significant bit in the bit field.
3289 Range 0..31.
3290 @param Value New value of the bit field.
3291
3292 @return The lower 32-bit of the value written to the MSR.
3293
3294 **/
3295 UINT32
3296 EFIAPI
3297 AsmMsrBitFieldWrite32 (
3298 IN UINT32 Index,
3299 IN UINTN StartBit,
3300 IN UINTN EndBit,
3301 IN UINT32 Value
3302 );
3303
3304 /**
3305 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3306 result back to the bit field in the 64-bit MSR.
3307
3308 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3309 between the read result and the value specified by OrData, and writes the
3310 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3311 written to the MSR are returned. Extra left bits in OrData are stripped. The
3312 caller must either guarantee that Index and the data written is valid, or
3313 the caller must set up exception handlers to catch the exceptions. This
3314 function is only available on IA-32 and X64.
3315
3316 If StartBit is greater than 31, then ASSERT().
3317 If EndBit is greater than 31, then ASSERT().
3318 If EndBit is less than StartBit, then ASSERT().
3319
3320 @param Index The 32-bit MSR index to write.
3321 @param StartBit The ordinal of the least significant bit in the bit field.
3322 Range 0..31.
3323 @param EndBit The ordinal of the most significant bit in the bit field.
3324 Range 0..31.
3325 @param OrData The value to OR with the read value from the MSR.
3326
3327 @return The lower 32-bit of the value written to the MSR.
3328
3329 **/
3330 UINT32
3331 EFIAPI
3332 AsmMsrBitFieldOr32 (
3333 IN UINT32 Index,
3334 IN UINTN StartBit,
3335 IN UINTN EndBit,
3336 IN UINT32 OrData
3337 );
3338
3339 /**
3340 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3341 result back to the bit field in the 64-bit MSR.
3342
3343 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3344 read result and the value specified by AndData, and writes the result to the
3345 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3346 MSR are returned. Extra left bits in AndData are stripped. The caller must
3347 either guarantee that Index and the data written is valid, or the caller must
3348 set up exception handlers to catch the exceptions. This function is only
3349 available on IA-32 and X64.
3350
3351 If StartBit is greater than 31, then ASSERT().
3352 If EndBit is greater than 31, then ASSERT().
3353 If EndBit is less than StartBit, then ASSERT().
3354
3355 @param Index The 32-bit MSR index to write.
3356 @param StartBit The ordinal of the least significant bit in the bit field.
3357 Range 0..31.
3358 @param EndBit The ordinal of the most significant bit in the bit field.
3359 Range 0..31.
3360 @param AndData The value to AND with the read value from the MSR.
3361
3362 @return The lower 32-bit of the value written to the MSR.
3363
3364 **/
3365 UINT32
3366 EFIAPI
3367 AsmMsrBitFieldAnd32 (
3368 IN UINT32 Index,
3369 IN UINTN StartBit,
3370 IN UINTN EndBit,
3371 IN UINT32 AndData
3372 );
3373
3374 /**
3375 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3376 bitwise inclusive OR, and writes the result back to the bit field in the
3377 64-bit MSR.
3378
3379 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3380 bitwise inclusive OR between the read result and the value specified by
3381 AndData, and writes the result to the 64-bit MSR specified by Index. The
3382 lower 32-bits of the value written to the MSR are returned. Extra left bits
3383 in both AndData and OrData are stripped. The caller must either guarantee
3384 that Index and the data written is valid, or the caller must set up exception
3385 handlers to catch the exceptions. This function is only available on IA-32
3386 and X64.
3387
3388 If StartBit is greater than 31, then ASSERT().
3389 If EndBit is greater than 31, then ASSERT().
3390 If EndBit is less than StartBit, then ASSERT().
3391
3392 @param Index The 32-bit MSR index to write.
3393 @param StartBit The ordinal of the least significant bit in the bit field.
3394 Range 0..31.
3395 @param EndBit The ordinal of the most significant bit in the bit field.
3396 Range 0..31.
3397 @param AndData The value to AND with the read value from the MSR.
3398 @param OrData The value to OR with the result of the AND operation.
3399
3400 @return The lower 32-bit of the value written to the MSR.
3401
3402 **/
3403 UINT32
3404 EFIAPI
3405 AsmMsrBitFieldAndThenOr32 (
3406 IN UINT32 Index,
3407 IN UINTN StartBit,
3408 IN UINTN EndBit,
3409 IN UINT32 AndData,
3410 IN UINT32 OrData
3411 );
3412
3413 /**
3414 Returns a 64-bit Machine Specific Register(MSR).
3415
3416 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3417 performed on Index, and some Index values may cause CPU exceptions. The
3418 caller must either guarantee that Index is valid, or the caller must set up
3419 exception handlers to catch the exceptions. This function is only available
3420 on IA-32 and X64.
3421
3422 @param Index The 32-bit MSR index to read.
3423
3424 @return The value of the MSR identified by Index.
3425
3426 **/
3427 UINT64
3428 EFIAPI
3429 AsmReadMsr64 (
3430 IN UINT32 Index
3431 );
3432
3433 /**
3434 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3435 value.
3436
3437 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3438 64-bit value written to the MSR is returned. No parameter checking is
3439 performed on Index or Value, and some of these may cause CPU exceptions. The
3440 caller must either guarantee that Index and Value are valid, or the caller
3441 must establish proper exception handlers. This function is only available on
3442 IA-32 and X64.
3443
3444 @param Index The 32-bit MSR index to write.
3445 @param Value The 64-bit value to write to the MSR.
3446
3447 @return Value
3448
3449 **/
3450 UINT64
3451 EFIAPI
3452 AsmWriteMsr64 (
3453 IN UINT32 Index,
3454 IN UINT64 Value
3455 );
3456
3457 /**
3458 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3459 back to the 64-bit MSR.
3460
3461 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3462 between the read result and the value specified by OrData, and writes the
3463 result to the 64-bit MSR specified by Index. The value written to the MSR is
3464 returned. No parameter checking is performed on Index or OrData, and some of
3465 these may cause CPU exceptions. The caller must either guarantee that Index
3466 and OrData are valid, or the caller must establish proper exception handlers.
3467 This function is only available on IA-32 and X64.
3468
3469 @param Index The 32-bit MSR index to write.
3470 @param OrData The value to OR with the read value from the MSR.
3471
3472 @return The value written back to the MSR.
3473
3474 **/
3475 UINT64
3476 EFIAPI
3477 AsmMsrOr64 (
3478 IN UINT32 Index,
3479 IN UINT64 OrData
3480 );
3481
3482 /**
3483 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3484 64-bit MSR.
3485
3486 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3487 read result and the value specified by OrData, and writes the result to the
3488 64-bit MSR specified by Index. The value written to the MSR is returned. No
3489 parameter checking is performed on Index or OrData, and some of these may
3490 cause CPU exceptions. The caller must either guarantee that Index and OrData
3491 are valid, or the caller must establish proper exception handlers. This
3492 function is only available on IA-32 and X64.
3493
3494 @param Index The 32-bit MSR index to write.
3495 @param AndData The value to AND with the read value from the MSR.
3496
3497 @return The value written back to the MSR.
3498
3499 **/
3500 UINT64
3501 EFIAPI
3502 AsmMsrAnd64 (
3503 IN UINT32 Index,
3504 IN UINT64 AndData
3505 );
3506
3507 /**
3508 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3509 OR, and writes the result back to the 64-bit MSR.
3510
3511 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3512 result and the value specified by AndData, performs a bitwise inclusive OR
3513 between the result of the AND operation and the value specified by OrData,
3514 and writes the result to the 64-bit MSR specified by Index. The value written
3515 to the MSR is returned. No parameter checking is performed on Index, AndData,
3516 or OrData, and some of these may cause CPU exceptions. The caller must either
3517 guarantee that Index, AndData, and OrData are valid, or the caller must
3518 establish proper exception handlers. This function is only available on IA-32
3519 and X64.
3520
3521 @param Index The 32-bit MSR index to write.
3522 @param AndData The value to AND with the read value from the MSR.
3523 @param OrData The value to OR with the result of the AND operation.
3524
3525 @return The value written back to the MSR.
3526
3527 **/
3528 UINT64
3529 EFIAPI
3530 AsmMsrAndThenOr64 (
3531 IN UINT32 Index,
3532 IN UINT64 AndData,
3533 IN UINT64 OrData
3534 );
3535
3536 /**
3537 Reads a bit field of an MSR.
3538
3539 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3540 StartBit and the EndBit. The value of the bit field is returned. The caller
3541 must either guarantee that Index is valid, or the caller must set up
3542 exception handlers to catch the exceptions. This function is only available
3543 on IA-32 and X64.
3544
3545 If StartBit is greater than 63, then ASSERT().
3546 If EndBit is greater than 63, then ASSERT().
3547 If EndBit is less than StartBit, then ASSERT().
3548
3549 @param Index The 32-bit MSR index to read.
3550 @param StartBit The ordinal of the least significant bit in the bit field.
3551 Range 0..63.
3552 @param EndBit The ordinal of the most significant bit in the bit field.
3553 Range 0..63.
3554
3555 @return The value read from the MSR.
3556
3557 **/
3558 UINT64
3559 EFIAPI
3560 AsmMsrBitFieldRead64 (
3561 IN UINT32 Index,
3562 IN UINTN StartBit,
3563 IN UINTN EndBit
3564 );
3565
3566 /**
3567 Writes a bit field to an MSR.
3568
3569 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3570 the StartBit and the EndBit. All other bits in the destination MSR are
3571 preserved. The MSR written is returned. Extra left bits in Value are
3572 stripped. The caller must either guarantee that Index and the data written is
3573 valid, or the caller must set up exception handlers to catch the exceptions.
3574 This function is only available on IA-32 and X64.
3575
3576 If StartBit is greater than 63, then ASSERT().
3577 If EndBit is greater than 63, then ASSERT().
3578 If EndBit is less than StartBit, then ASSERT().
3579
3580 @param Index The 32-bit MSR index to write.
3581 @param StartBit The ordinal of the least significant bit in the bit field.
3582 Range 0..63.
3583 @param EndBit The ordinal of the most significant bit in the bit field.
3584 Range 0..63.
3585 @param Value New value of the bit field.
3586
3587 @return The value written back to the MSR.
3588
3589 **/
3590 UINT64
3591 EFIAPI
3592 AsmMsrBitFieldWrite64 (
3593 IN UINT32 Index,
3594 IN UINTN StartBit,
3595 IN UINTN EndBit,
3596 IN UINT64 Value
3597 );
3598
3599 /**
3600 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3601 writes the result back to the bit field in the 64-bit MSR.
3602
3603 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3604 between the read result and the value specified by OrData, and writes the
3605 result to the 64-bit MSR specified by Index. The value written to the MSR is
3606 returned. Extra left bits in OrData are stripped. The caller must either
3607 guarantee that Index and the data written is valid, or the caller must set up
3608 exception handlers to catch the exceptions. This function is only available
3609 on IA-32 and X64.
3610
3611 If StartBit is greater than 63, then ASSERT().
3612 If EndBit is greater than 63, then ASSERT().
3613 If EndBit is less than StartBit, then ASSERT().
3614
3615 @param Index The 32-bit MSR index to write.
3616 @param StartBit The ordinal of the least significant bit in the bit field.
3617 Range 0..63.
3618 @param EndBit The ordinal of the most significant bit in the bit field.
3619 Range 0..63.
3620 @param OrData The value to OR with the read value from the bit field.
3621
3622 @return The value written back to the MSR.
3623
3624 **/
3625 UINT64
3626 EFIAPI
3627 AsmMsrBitFieldOr64 (
3628 IN UINT32 Index,
3629 IN UINTN StartBit,
3630 IN UINTN EndBit,
3631 IN UINT64 OrData
3632 );
3633
3634 /**
3635 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3636 result back to the bit field in the 64-bit MSR.
3637
3638 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3639 read result and the value specified by AndData, and writes the result to the
3640 64-bit MSR specified by Index. The value written to the MSR is returned.
3641 Extra left bits in AndData are stripped. The caller must either guarantee
3642 that Index and the data written is valid, or the caller must set up exception
3643 handlers to catch the exceptions. This function is only available on IA-32
3644 and X64.
3645
3646 If StartBit is greater than 63, then ASSERT().
3647 If EndBit is greater than 63, then ASSERT().
3648 If EndBit is less than StartBit, then ASSERT().
3649
3650 @param Index The 32-bit MSR index to write.
3651 @param StartBit The ordinal of the least significant bit in the bit field.
3652 Range 0..63.
3653 @param EndBit The ordinal of the most significant bit in the bit field.
3654 Range 0..63.
3655 @param AndData The value to AND with the read value from the bit field.
3656
3657 @return The value written back to the MSR.
3658
3659 **/
3660 UINT64
3661 EFIAPI
3662 AsmMsrBitFieldAnd64 (
3663 IN UINT32 Index,
3664 IN UINTN StartBit,
3665 IN UINTN EndBit,
3666 IN UINT64 AndData
3667 );
3668
3669 /**
3670 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3671 bitwise inclusive OR, and writes the result back to the bit field in the
3672 64-bit MSR.
3673
3674 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3675 a bitwise inclusive OR between the read result and the value specified by
3676 AndData, and writes the result to the 64-bit MSR specified by Index. The
3677 value written to the MSR is returned. Extra left bits in both AndData and
3678 OrData are stripped. The caller must either guarantee that Index and the data
3679 written is valid, or the caller must set up exception handlers to catch the
3680 exceptions. This function is only available on IA-32 and X64.
3681
3682 If StartBit is greater than 63, then ASSERT().
3683 If EndBit is greater than 63, then ASSERT().
3684 If EndBit is less than StartBit, then ASSERT().
3685
3686 @param Index The 32-bit MSR index to write.
3687 @param StartBit The ordinal of the least significant bit in the bit field.
3688 Range 0..63.
3689 @param EndBit The ordinal of the most significant bit in the bit field.
3690 Range 0..63.
3691 @param AndData The value to AND with the read value from the bit field.
3692 @param OrData The value to OR with the result of the AND operation.
3693
3694 @return The value written back to the MSR.
3695
3696 **/
3697 UINT64
3698 EFIAPI
3699 AsmMsrBitFieldAndThenOr64 (
3700 IN UINT32 Index,
3701 IN UINTN StartBit,
3702 IN UINTN EndBit,
3703 IN UINT64 AndData,
3704 IN UINT64 OrData
3705 );
3706
3707 /**
3708 Reads the current value of the EFLAGS register.
3709
3710 Reads and returns the current value of the EFLAGS register. This function is
3711 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3712 64-bit value on X64.
3713
3714 @return EFLAGS on IA-32 or RFLAGS on X64.
3715
3716 **/
3717 UINTN
3718 EFIAPI
3719 AsmReadEflags (
3720 VOID
3721 );
3722
3723 /**
3724 Reads the current value of the Control Register 0 (CR0).
3725
3726 Reads and returns the current value of CR0. This function is only available
3727 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3728 X64.
3729
3730 @return The value of the Control Register 0 (CR0).
3731
3732 **/
3733 UINTN
3734 EFIAPI
3735 AsmReadCr0 (
3736 VOID
3737 );
3738
3739 /**
3740 Reads the current value of the Control Register 2 (CR2).
3741
3742 Reads and returns the current value of CR2. This function is only available
3743 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3744 X64.
3745
3746 @return The value of the Control Register 2 (CR2).
3747
3748 **/
3749 UINTN
3750 EFIAPI
3751 AsmReadCr2 (
3752 VOID
3753 );
3754
3755 /**
3756 Reads the current value of the Control Register 3 (CR3).
3757
3758 Reads and returns the current value of CR3. This function is only available
3759 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3760 X64.
3761
3762 @return The value of the Control Register 3 (CR3).
3763
3764 **/
3765 UINTN
3766 EFIAPI
3767 AsmReadCr3 (
3768 VOID
3769 );
3770
3771 /**
3772 Reads the current value of the Control Register 4 (CR4).
3773
3774 Reads and returns the current value of CR4. This function is only available
3775 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3776 X64.
3777
3778 @return The value of the Control Register 4 (CR4).
3779
3780 **/
3781 UINTN
3782 EFIAPI
3783 AsmReadCr4 (
3784 VOID
3785 );
3786
3787 /**
3788 Writes a value to Control Register 0 (CR0).
3789
3790 Writes and returns a new value to CR0. This function is only available on
3791 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3792
3793 @param Cr0 The value to write to CR0.
3794
3795 @return The value written to CR0.
3796
3797 **/
3798 UINTN
3799 EFIAPI
3800 AsmWriteCr0 (
3801 UINTN Cr0
3802 );
3803
3804 /**
3805 Writes a value to Control Register 2 (CR2).
3806
3807 Writes and returns a new value to CR2. This function is only available on
3808 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3809
3810 @param Cr2 The value to write to CR2.
3811
3812 @return The value written to CR2.
3813
3814 **/
3815 UINTN
3816 EFIAPI
3817 AsmWriteCr2 (
3818 UINTN Cr2
3819 );
3820
3821 /**
3822 Writes a value to Control Register 3 (CR3).
3823
3824 Writes and returns a new value to CR3. This function is only available on
3825 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3826
3827 @param Cr3 The value to write to CR3.
3828
3829 @return The value written to CR3.
3830
3831 **/
3832 UINTN
3833 EFIAPI
3834 AsmWriteCr3 (
3835 UINTN Cr3
3836 );
3837
3838 /**
3839 Writes a value to Control Register 4 (CR4).
3840
3841 Writes and returns a new value to CR4. This function is only available on
3842 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3843
3844 @param Cr4 The value to write to CR4.
3845
3846 @return The value written to CR4.
3847
3848 **/
3849 UINTN
3850 EFIAPI
3851 AsmWriteCr4 (
3852 UINTN Cr4
3853 );
3854
3855 /**
3856 Reads the current value of Debug Register 0 (DR0).
3857
3858 Reads and returns the current value of DR0. This function is only available
3859 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3860 X64.
3861
3862 @return The value of Debug Register 0 (DR0).
3863
3864 **/
3865 UINTN
3866 EFIAPI
3867 AsmReadDr0 (
3868 VOID
3869 );
3870
3871 /**
3872 Reads the current value of Debug Register 1 (DR1).
3873
3874 Reads and returns the current value of DR1. This function is only available
3875 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3876 X64.
3877
3878 @return The value of Debug Register 1 (DR1).
3879
3880 **/
3881 UINTN
3882 EFIAPI
3883 AsmReadDr1 (
3884 VOID
3885 );
3886
3887 /**
3888 Reads the current value of Debug Register 2 (DR2).
3889
3890 Reads and returns the current value of DR2. This function is only available
3891 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3892 X64.
3893
3894 @return The value of Debug Register 2 (DR2).
3895
3896 **/
3897 UINTN
3898 EFIAPI
3899 AsmReadDr2 (
3900 VOID
3901 );
3902
3903 /**
3904 Reads the current value of Debug Register 3 (DR3).
3905
3906 Reads and returns the current value of DR3. This function is only available
3907 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3908 X64.
3909
3910 @return The value of Debug Register 3 (DR3).
3911
3912 **/
3913 UINTN
3914 EFIAPI
3915 AsmReadDr3 (
3916 VOID
3917 );
3918
3919 /**
3920 Reads the current value of Debug Register 4 (DR4).
3921
3922 Reads and returns the current value of DR4. This function is only available
3923 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3924 X64.
3925
3926 @return The value of Debug Register 4 (DR4).
3927
3928 **/
3929 UINTN
3930 EFIAPI
3931 AsmReadDr4 (
3932 VOID
3933 );
3934
3935 /**
3936 Reads the current value of Debug Register 5 (DR5).
3937
3938 Reads and returns the current value of DR5. This function is only available
3939 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3940 X64.
3941
3942 @return The value of Debug Register 5 (DR5).
3943
3944 **/
3945 UINTN
3946 EFIAPI
3947 AsmReadDr5 (
3948 VOID
3949 );
3950
3951 /**
3952 Reads the current value of Debug Register 6 (DR6).
3953
3954 Reads and returns the current value of DR6. This function is only available
3955 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3956 X64.
3957
3958 @return The value of Debug Register 6 (DR6).
3959
3960 **/
3961 UINTN
3962 EFIAPI
3963 AsmReadDr6 (
3964 VOID
3965 );
3966
3967 /**
3968 Reads the current value of Debug Register 7 (DR7).
3969
3970 Reads and returns the current value of DR7. This function is only available
3971 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3972 X64.
3973
3974 @return The value of Debug Register 7 (DR7).
3975
3976 **/
3977 UINTN
3978 EFIAPI
3979 AsmReadDr7 (
3980 VOID
3981 );
3982
3983 /**
3984 Writes a value to Debug Register 0 (DR0).
3985
3986 Writes and returns a new value to DR0. This function is only available on
3987 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3988
3989 @param Dr0 The value to write to Dr0.
3990
3991 @return The value written to Debug Register 0 (DR0).
3992
3993 **/
3994 UINTN
3995 EFIAPI
3996 AsmWriteDr0 (
3997 UINTN Dr0
3998 );
3999
4000 /**
4001 Writes a value to Debug Register 1 (DR1).
4002
4003 Writes and returns a new value to DR1. This function is only available on
4004 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4005
4006 @param Dr1 The value to write to Dr1.
4007
4008 @return The value written to Debug Register 1 (DR1).
4009
4010 **/
4011 UINTN
4012 EFIAPI
4013 AsmWriteDr1 (
4014 UINTN Dr1
4015 );
4016
4017 /**
4018 Writes a value to Debug Register 2 (DR2).
4019
4020 Writes and returns a new value to DR2. This function is only available on
4021 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4022
4023 @param Dr2 The value to write to Dr2.
4024
4025 @return The value written to Debug Register 2 (DR2).
4026
4027 **/
4028 UINTN
4029 EFIAPI
4030 AsmWriteDr2 (
4031 UINTN Dr2
4032 );
4033
4034 /**
4035 Writes a value to Debug Register 3 (DR3).
4036
4037 Writes and returns a new value to DR3. This function is only available on
4038 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4039
4040 @param Dr3 The value to write to Dr3.
4041
4042 @return The value written to Debug Register 3 (DR3).
4043
4044 **/
4045 UINTN
4046 EFIAPI
4047 AsmWriteDr3 (
4048 UINTN Dr3
4049 );
4050
4051 /**
4052 Writes a value to Debug Register 4 (DR4).
4053
4054 Writes and returns a new value to DR4. This function is only available on
4055 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4056
4057 @param Dr4 The value to write to Dr4.
4058
4059 @return The value written to Debug Register 4 (DR4).
4060
4061 **/
4062 UINTN
4063 EFIAPI
4064 AsmWriteDr4 (
4065 UINTN Dr4
4066 );
4067
4068 /**
4069 Writes a value to Debug Register 5 (DR5).
4070
4071 Writes and returns a new value to DR5. This function is only available on
4072 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4073
4074 @param Dr5 The value to write to Dr5.
4075
4076 @return The value written to Debug Register 5 (DR5).
4077
4078 **/
4079 UINTN
4080 EFIAPI
4081 AsmWriteDr5 (
4082 UINTN Dr5
4083 );
4084
4085 /**
4086 Writes a value to Debug Register 6 (DR6).
4087
4088 Writes and returns a new value to DR6. This function is only available on
4089 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4090
4091 @param Dr6 The value to write to Dr6.
4092
4093 @return The value written to Debug Register 6 (DR6).
4094
4095 **/
4096 UINTN
4097 EFIAPI
4098 AsmWriteDr6 (
4099 UINTN Dr6
4100 );
4101
4102 /**
4103 Writes a value to Debug Register 7 (DR7).
4104
4105 Writes and returns a new value to DR7. This function is only available on
4106 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4107
4108 @param Dr7 The value to write to Dr7.
4109
4110 @return The value written to Debug Register 7 (DR7).
4111
4112 **/
4113 UINTN
4114 EFIAPI
4115 AsmWriteDr7 (
4116 UINTN Dr7
4117 );
4118
4119 /**
4120 Reads the current value of Code Segment Register (CS).
4121
4122 Reads and returns the current value of CS. This function is only available on
4123 IA-32 and X64.
4124
4125 @return The current value of CS.
4126
4127 **/
4128 UINT16
4129 EFIAPI
4130 AsmReadCs (
4131 VOID
4132 );
4133
4134 /**
4135 Reads the current value of Data Segment Register (DS).
4136
4137 Reads and returns the current value of DS. This function is only available on
4138 IA-32 and X64.
4139
4140 @return The current value of DS.
4141
4142 **/
4143 UINT16
4144 EFIAPI
4145 AsmReadDs (
4146 VOID
4147 );
4148
4149 /**
4150 Reads the current value of Extra Segment Register (ES).
4151
4152 Reads and returns the current value of ES. This function is only available on
4153 IA-32 and X64.
4154
4155 @return The current value of ES.
4156
4157 **/
4158 UINT16
4159 EFIAPI
4160 AsmReadEs (
4161 VOID
4162 );
4163
4164 /**
4165 Reads the current value of FS Data Segment Register (FS).
4166
4167 Reads and returns the current value of FS. This function is only available on
4168 IA-32 and X64.
4169
4170 @return The current value of FS.
4171
4172 **/
4173 UINT16
4174 EFIAPI
4175 AsmReadFs (
4176 VOID
4177 );
4178
4179 /**
4180 Reads the current value of GS Data Segment Register (GS).
4181
4182 Reads and returns the current value of GS. This function is only available on
4183 IA-32 and X64.
4184
4185 @return The current value of GS.
4186
4187 **/
4188 UINT16
4189 EFIAPI
4190 AsmReadGs (
4191 VOID
4192 );
4193
4194 /**
4195 Reads the current value of Stack Segment Register (SS).
4196
4197 Reads and returns the current value of SS. This function is only available on
4198 IA-32 and X64.
4199
4200 @return The current value of SS.
4201
4202 **/
4203 UINT16
4204 EFIAPI
4205 AsmReadSs (
4206 VOID
4207 );
4208
4209 /**
4210 Reads the current value of Task Register (TR).
4211
4212 Reads and returns the current value of TR. This function is only available on
4213 IA-32 and X64.
4214
4215 @return The current value of TR.
4216
4217 **/
4218 UINT16
4219 EFIAPI
4220 AsmReadTr (
4221 VOID
4222 );
4223
4224 /**
4225 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4226
4227 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4228 function is only available on IA-32 and X64.
4229
4230 If Gdtr is NULL, then ASSERT().
4231
4232 @param Gdtr Pointer to a GDTR descriptor.
4233
4234 **/
4235 VOID
4236 EFIAPI
4237 AsmReadGdtr (
4238 OUT IA32_DESCRIPTOR *Gdtr
4239 );
4240
4241 /**
4242 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4243
4244 Writes and the current GDTR descriptor specified by Gdtr. This function is
4245 only available on IA-32 and X64.
4246
4247 If Gdtr is NULL, then ASSERT().
4248
4249 @param Gdtr Pointer to a GDTR descriptor.
4250
4251 **/
4252 VOID
4253 EFIAPI
4254 AsmWriteGdtr (
4255 IN CONST IA32_DESCRIPTOR *Gdtr
4256 );
4257
4258 /**
4259 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4260
4261 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4262 function is only available on IA-32 and X64.
4263
4264 If Idtr is NULL, then ASSERT().
4265
4266 @param Idtr Pointer to a IDTR descriptor.
4267
4268 **/
4269 VOID
4270 EFIAPI
4271 AsmReadIdtr (
4272 OUT IA32_DESCRIPTOR *Idtr
4273 );
4274
4275 /**
4276 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4277
4278 Writes the current IDTR descriptor and returns it in Idtr. This function is
4279 only available on IA-32 and X64.
4280
4281 If Idtr is NULL, then ASSERT().
4282
4283 @param Idtr Pointer to a IDTR descriptor.
4284
4285 **/
4286 VOID
4287 EFIAPI
4288 AsmWriteIdtr (
4289 IN CONST IA32_DESCRIPTOR *Idtr
4290 );
4291
4292 /**
4293 Reads the current Local Descriptor Table Register(LDTR) selector.
4294
4295 Reads and returns the current 16-bit LDTR descriptor value. This function is
4296 only available on IA-32 and X64.
4297
4298 @return The current selector of LDT.
4299
4300 **/
4301 UINT16
4302 EFIAPI
4303 AsmReadLdtr (
4304 VOID
4305 );
4306
4307 /**
4308 Writes the current Local Descriptor Table Register (GDTR) selector.
4309
4310 Writes and the current LDTR descriptor specified by Ldtr. This function is
4311 only available on IA-32 and X64.
4312
4313 @param Ldtr 16-bit LDTR selector value.
4314
4315 **/
4316 VOID
4317 EFIAPI
4318 AsmWriteLdtr (
4319 IN UINT16 Ldtr
4320 );
4321
4322 /**
4323 Save the current floating point/SSE/SSE2 context to a buffer.
4324
4325 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4326 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4327 available on IA-32 and X64.
4328
4329 If Buffer is NULL, then ASSERT().
4330 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4331
4332 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4333
4334 **/
4335 VOID
4336 EFIAPI
4337 AsmFxSave (
4338 OUT IA32_FX_BUFFER *Buffer
4339 );
4340
4341 /**
4342 Restores the current floating point/SSE/SSE2 context from a buffer.
4343
4344 Restores the current floating point/SSE/SSE2 state from the buffer specified
4345 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4346 only available on IA-32 and X64.
4347
4348 If Buffer is NULL, then ASSERT().
4349 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4350 If Buffer was not saved with AsmFxSave(), then ASSERT().
4351
4352 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4353
4354 **/
4355 VOID
4356 EFIAPI
4357 AsmFxRestore (
4358 IN CONST IA32_FX_BUFFER *Buffer
4359 );
4360
4361 /**
4362 Reads the current value of 64-bit MMX Register #0 (MM0).
4363
4364 Reads and returns the current value of MM0. This function is only available
4365 on IA-32 and X64.
4366
4367 @return The current value of MM0.
4368
4369 **/
4370 UINT64
4371 EFIAPI
4372 AsmReadMm0 (
4373 VOID
4374 );
4375
4376 /**
4377 Reads the current value of 64-bit MMX Register #1 (MM1).
4378
4379 Reads and returns the current value of MM1. This function is only available
4380 on IA-32 and X64.
4381
4382 @return The current value of MM1.
4383
4384 **/
4385 UINT64
4386 EFIAPI
4387 AsmReadMm1 (
4388 VOID
4389 );
4390
4391 /**
4392 Reads the current value of 64-bit MMX Register #2 (MM2).
4393
4394 Reads and returns the current value of MM2. This function is only available
4395 on IA-32 and X64.
4396
4397 @return The current value of MM2.
4398
4399 **/
4400 UINT64
4401 EFIAPI
4402 AsmReadMm2 (
4403 VOID
4404 );
4405
4406 /**
4407 Reads the current value of 64-bit MMX Register #3 (MM3).
4408
4409 Reads and returns the current value of MM3. This function is only available
4410