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