]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/BaseLib.h
add function header
[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 UINT32 RealModeBufferSize;
2975 UINT32 ThunkAttributes;
2976 } THUNK_CONTEXT;
2977
2978 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
2979 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
2980 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
2981
2982 /**
2983 Retrieves CPUID information.
2984
2985 Executes the CPUID instruction with EAX set to the value specified by Index.
2986 This function always returns Index.
2987 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
2988 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
2989 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
2990 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
2991 This function is only available on IA-32 and X64.
2992
2993 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
2994 instruction.
2995 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
2996 instruction. This is an optional parameter that may be NULL.
2997 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
2998 instruction. This is an optional parameter that may be NULL.
2999 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3000 instruction. This is an optional parameter that may be NULL.
3001 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3002 instruction. This is an optional parameter that may be NULL.
3003
3004 @return Index
3005
3006 **/
3007 UINT32
3008 EFIAPI
3009 AsmCpuid (
3010 IN UINT32 Index,
3011 OUT UINT32 *Eax, OPTIONAL
3012 OUT UINT32 *Ebx, OPTIONAL
3013 OUT UINT32 *Ecx, OPTIONAL
3014 OUT UINT32 *Edx OPTIONAL
3015 );
3016
3017 /**
3018 Returns the lower 32-bits of a Machine Specific Register(MSR).
3019
3020 Reads and returns the lower 32-bits of the MSR specified by Index.
3021 No parameter checking is performed on Index, and some Index values may cause
3022 CPU exceptions. The caller must either guarantee that Index is valid, or the
3023 caller must set up exception handlers to catch the exceptions. This function
3024 is only available on IA-32 and X64.
3025
3026 @param Index The 32-bit MSR index to read.
3027
3028 @return The lower 32 bits of the MSR identified by Index.
3029
3030 **/
3031 UINT32
3032 EFIAPI
3033 AsmReadMsr32 (
3034 IN UINT32 Index
3035 );
3036
3037 /**
3038 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3039
3040 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3041 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3042 the MSR is returned. No parameter checking is performed on Index or Value,
3043 and some of these may cause CPU exceptions. The caller must either guarantee
3044 that Index and Value are valid, or the caller must establish proper exception
3045 handlers. This function is only available on IA-32 and X64.
3046
3047 @param Index The 32-bit MSR index to write.
3048 @param Value The 32-bit value to write to the MSR.
3049
3050 @return Value
3051
3052 **/
3053 UINT32
3054 EFIAPI
3055 AsmWriteMsr32 (
3056 IN UINT32 Index,
3057 IN UINT32 Value
3058 );
3059
3060 /**
3061 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3062 writes the result back to the 64-bit MSR.
3063
3064 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3065 between the lower 32-bits of the read result and the value specified by
3066 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3067 32-bits of the value written to the MSR is returned. No parameter checking is
3068 performed on Index or OrData, and some of these may cause CPU exceptions. The
3069 caller must either guarantee that Index and OrData are valid, or the caller
3070 must establish proper exception handlers. This function is only available on
3071 IA-32 and X64.
3072
3073 @param Index The 32-bit MSR index to write.
3074 @param OrData The value to OR with the read value from the MSR.
3075
3076 @return The lower 32-bit value written to the MSR.
3077
3078 **/
3079 UINT32
3080 EFIAPI
3081 AsmMsrOr32 (
3082 IN UINT32 Index,
3083 IN UINT32 OrData
3084 );
3085
3086 /**
3087 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3088 the result back to the 64-bit MSR.
3089
3090 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3091 lower 32-bits of the read result and the value specified by AndData, and
3092 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3093 the value written to the MSR is returned. No parameter checking is performed
3094 on Index or AndData, and some of these may cause CPU exceptions. The caller
3095 must either guarantee that Index and AndData are valid, or the caller must
3096 establish proper exception handlers. This function is only available on IA-32
3097 and X64.
3098
3099 @param Index The 32-bit MSR index to write.
3100 @param AndData The value to AND with the read value from the MSR.
3101
3102 @return The lower 32-bit value written to the MSR.
3103
3104 **/
3105 UINT32
3106 EFIAPI
3107 AsmMsrAnd32 (
3108 IN UINT32 Index,
3109 IN UINT32 AndData
3110 );
3111
3112 /**
3113 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3114 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3115
3116 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3117 lower 32-bits of the read result and the value specified by AndData
3118 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3119 result of the AND operation and the value specified by OrData, and writes the
3120 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3121 written to the MSR is returned. No parameter checking is performed on Index,
3122 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3123 must either guarantee that Index, AndData, and OrData are valid, or the
3124 caller must establish proper exception handlers. This function is only
3125 available on IA-32 and X64.
3126
3127 @param Index The 32-bit MSR index to write.
3128 @param AndData The value to AND with the read value from the MSR.
3129 @param OrData The value to OR with the result of the AND operation.
3130
3131 @return The lower 32-bit value written to the MSR.
3132
3133 **/
3134 UINT32
3135 EFIAPI
3136 AsmMsrAndThenOr32 (
3137 IN UINT32 Index,
3138 IN UINT32 AndData,
3139 IN UINT32 OrData
3140 );
3141
3142 /**
3143 Reads a bit field of an MSR.
3144
3145 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3146 specified by the StartBit and the EndBit. The value of the bit field is
3147 returned. The caller must either guarantee that Index is valid, or the caller
3148 must set up exception handlers to catch the exceptions. This function is only
3149 available on IA-32 and X64.
3150
3151 If StartBit is greater than 31, then ASSERT().
3152 If EndBit is greater than 31, then ASSERT().
3153 If EndBit is less than or equal to StartBit, then ASSERT().
3154
3155 @param Index The 32-bit MSR index to read.
3156 @param StartBit The ordinal of the least significant bit in the bit field.
3157 Range 0..31.
3158 @param EndBit The ordinal of the most significant bit in the bit field.
3159 Range 0..31.
3160
3161 @return The bit field read from the MSR.
3162
3163 **/
3164 UINT32
3165 EFIAPI
3166 AsmMsrBitFieldRead32 (
3167 IN UINT32 Index,
3168 IN UINTN StartBit,
3169 IN UINTN EndBit
3170 );
3171
3172 /**
3173 Writes a bit field to an MSR.
3174
3175 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
3176 field is specified by the StartBit and the EndBit. All other bits in the
3177 destination MSR are preserved. The lower 32-bits of the MSR written is
3178 returned. Extra left bits in Value are stripped. The caller must either
3179 guarantee that Index and the data written is valid, or the caller must set up
3180 exception handlers to catch the exceptions. This function is only available
3181 on IA-32 and X64.
3182
3183 If StartBit is greater than 31, then ASSERT().
3184 If EndBit is greater than 31, then ASSERT().
3185 If EndBit is less than or equal to StartBit, then ASSERT().
3186
3187 @param Index The 32-bit MSR index to write.
3188 @param StartBit The ordinal of the least significant bit in the bit field.
3189 Range 0..31.
3190 @param EndBit The ordinal of the most significant bit in the bit field.
3191 Range 0..31.
3192 @param Value New value of the bit field.
3193
3194 @return The lower 32-bit of the value written to the MSR.
3195
3196 **/
3197 UINT32
3198 EFIAPI
3199 AsmMsrBitFieldWrite32 (
3200 IN UINT32 Index,
3201 IN UINTN StartBit,
3202 IN UINTN EndBit,
3203 IN UINT32 Value
3204 );
3205
3206 /**
3207 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
3208 result back to the bit field in the 64-bit MSR.
3209
3210 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3211 between the read result and the value specified by OrData, and writes the
3212 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
3213 written to the MSR are returned. Extra left bits in OrData are stripped. The
3214 caller must either guarantee that Index and the data written is valid, or
3215 the caller must set up exception handlers to catch the exceptions. This
3216 function is only available on IA-32 and X64.
3217
3218 If StartBit is greater than 31, then ASSERT().
3219 If EndBit is greater than 31, then ASSERT().
3220 If EndBit is less than or equal to StartBit, then ASSERT().
3221
3222 @param Index The 32-bit MSR index to write.
3223 @param StartBit The ordinal of the least significant bit in the bit field.
3224 Range 0..31.
3225 @param EndBit The ordinal of the most significant bit in the bit field.
3226 Range 0..31.
3227 @param OrData The value to OR with the read value from the MSR.
3228
3229 @return The lower 32-bit of the value written to the MSR.
3230
3231 **/
3232 UINT32
3233 EFIAPI
3234 AsmMsrBitFieldOr32 (
3235 IN UINT32 Index,
3236 IN UINTN StartBit,
3237 IN UINTN EndBit,
3238 IN UINT32 OrData
3239 );
3240
3241 /**
3242 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3243 result back to the bit field in the 64-bit MSR.
3244
3245 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3246 read result and the value specified by AndData, and writes the result to the
3247 64-bit MSR specified by Index. The lower 32-bits of the value written to the
3248 MSR are returned. Extra left bits in AndData are stripped. The caller must
3249 either guarantee that Index and the data written is valid, or the caller must
3250 set up exception handlers to catch the exceptions. This function is only
3251 available on IA-32 and X64.
3252
3253 If StartBit is greater than 31, then ASSERT().
3254 If EndBit is greater than 31, then ASSERT().
3255 If EndBit is less than or equal to StartBit, then ASSERT().
3256
3257 @param Index The 32-bit MSR index to write.
3258 @param StartBit The ordinal of the least significant bit in the bit field.
3259 Range 0..31.
3260 @param EndBit The ordinal of the most significant bit in the bit field.
3261 Range 0..31.
3262 @param AndData The value to AND with the read value from the MSR.
3263
3264 @return The lower 32-bit of the value written to the MSR.
3265
3266 **/
3267 UINT32
3268 EFIAPI
3269 AsmMsrBitFieldAnd32 (
3270 IN UINT32 Index,
3271 IN UINTN StartBit,
3272 IN UINTN EndBit,
3273 IN UINT32 AndData
3274 );
3275
3276 /**
3277 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3278 bitwise inclusive OR, and writes the result back to the bit field in the
3279 64-bit MSR.
3280
3281 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
3282 bitwise inclusive OR between the read result and the value specified by
3283 AndData, and writes the result to the 64-bit MSR specified by Index. The
3284 lower 32-bits of the value written to the MSR are returned. Extra left bits
3285 in both AndData and OrData are stripped. The caller must either guarantee
3286 that Index and the data written is valid, or the caller must set up exception
3287 handlers to catch the exceptions. This function is only available on IA-32
3288 and X64.
3289
3290 If StartBit is greater than 31, then ASSERT().
3291 If EndBit is greater than 31, then ASSERT().
3292 If EndBit is less than or equal to StartBit, then ASSERT().
3293
3294 @param Index The 32-bit MSR index to write.
3295 @param StartBit The ordinal of the least significant bit in the bit field.
3296 Range 0..31.
3297 @param EndBit The ordinal of the most significant bit in the bit field.
3298 Range 0..31.
3299 @param AndData The value to AND with the read value from the MSR.
3300 @param OrData The value to OR with the result of the AND operation.
3301
3302 @return The lower 32-bit of the value written to the MSR.
3303
3304 **/
3305 UINT32
3306 EFIAPI
3307 AsmMsrBitFieldAndThenOr32 (
3308 IN UINT32 Index,
3309 IN UINTN StartBit,
3310 IN UINTN EndBit,
3311 IN UINT32 AndData,
3312 IN UINT32 OrData
3313 );
3314
3315 /**
3316 Returns a 64-bit Machine Specific Register(MSR).
3317
3318 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
3319 performed on Index, and some Index values may cause CPU exceptions. The
3320 caller must either guarantee that Index is valid, or the caller must set up
3321 exception handlers to catch the exceptions. This function is only available
3322 on IA-32 and X64.
3323
3324 @param Index The 32-bit MSR index to read.
3325
3326 @return The value of the MSR identified by Index.
3327
3328 **/
3329 UINT64
3330 EFIAPI
3331 AsmReadMsr64 (
3332 IN UINT32 Index
3333 );
3334
3335 /**
3336 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
3337 value.
3338
3339 Writes the 64-bit value specified by Value to the MSR specified by Index. The
3340 64-bit value written to the MSR is returned. No parameter checking is
3341 performed on Index or Value, and some of these may cause CPU exceptions. The
3342 caller must either guarantee that Index and Value are valid, or the caller
3343 must establish proper exception handlers. This function is only available on
3344 IA-32 and X64.
3345
3346 @param Index The 32-bit MSR index to write.
3347 @param Value The 64-bit value to write to the MSR.
3348
3349 @return Value
3350
3351 **/
3352 UINT64
3353 EFIAPI
3354 AsmWriteMsr64 (
3355 IN UINT32 Index,
3356 IN UINT64 Value
3357 );
3358
3359 /**
3360 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
3361 back to the 64-bit MSR.
3362
3363 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3364 between the read result and the value specified by OrData, and writes the
3365 result to the 64-bit MSR specified by Index. The value written to the MSR is
3366 returned. No parameter checking is performed on Index or OrData, and some of
3367 these may cause CPU exceptions. The caller must either guarantee that Index
3368 and OrData are valid, or the caller must establish proper exception handlers.
3369 This function is only available on IA-32 and X64.
3370
3371 @param Index The 32-bit MSR index to write.
3372 @param OrData The value to OR with the read value from the MSR.
3373
3374 @return The value written back to the MSR.
3375
3376 **/
3377 UINT64
3378 EFIAPI
3379 AsmMsrOr64 (
3380 IN UINT32 Index,
3381 IN UINT64 OrData
3382 );
3383
3384 /**
3385 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
3386 64-bit MSR.
3387
3388 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3389 read result and the value specified by OrData, and writes the result to the
3390 64-bit MSR specified by Index. The value written to the MSR is returned. No
3391 parameter checking is performed on Index or OrData, and some of these may
3392 cause CPU exceptions. The caller must either guarantee that Index and OrData
3393 are valid, or the caller must establish proper exception handlers. This
3394 function is only available on IA-32 and X64.
3395
3396 @param Index The 32-bit MSR index to write.
3397 @param AndData The value to AND with the read value from the MSR.
3398
3399 @return The value written back to the MSR.
3400
3401 **/
3402 UINT64
3403 EFIAPI
3404 AsmMsrAnd64 (
3405 IN UINT32 Index,
3406 IN UINT64 AndData
3407 );
3408
3409 /**
3410 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
3411 OR, and writes the result back to the 64-bit MSR.
3412
3413 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
3414 result and the value specified by AndData, performs a bitwise inclusive OR
3415 between the result of the AND operation and the value specified by OrData,
3416 and writes the result to the 64-bit MSR specified by Index. The value written
3417 to the MSR is returned. No parameter checking is performed on Index, AndData,
3418 or OrData, and some of these may cause CPU exceptions. The caller must either
3419 guarantee that Index, AndData, and OrData are valid, or the caller must
3420 establish proper exception handlers. This function is only available on IA-32
3421 and X64.
3422
3423 @param Index The 32-bit MSR index to write.
3424 @param AndData The value to AND with the read value from the MSR.
3425 @param OrData The value to OR with the result of the AND operation.
3426
3427 @return The value written back to the MSR.
3428
3429 **/
3430 UINT64
3431 EFIAPI
3432 AsmMsrAndThenOr64 (
3433 IN UINT32 Index,
3434 IN UINT64 AndData,
3435 IN UINT64 OrData
3436 );
3437
3438 /**
3439 Reads a bit field of an MSR.
3440
3441 Reads the bit field in the 64-bit MSR. The bit field is specified by the
3442 StartBit and the EndBit. The value of the bit field is returned. The caller
3443 must either guarantee that Index is valid, or the caller must set up
3444 exception handlers to catch the exceptions. This function is only available
3445 on IA-32 and X64.
3446
3447 If StartBit is greater than 63, then ASSERT().
3448 If EndBit is greater than 63, then ASSERT().
3449 If EndBit is less than or equal to StartBit, then ASSERT().
3450
3451 @param Index The 32-bit MSR index to read.
3452 @param StartBit The ordinal of the least significant bit in the bit field.
3453 Range 0..63.
3454 @param EndBit The ordinal of the most significant bit in the bit field.
3455 Range 0..63.
3456
3457 @return The value read from the MSR.
3458
3459 **/
3460 UINT64
3461 EFIAPI
3462 AsmMsrBitFieldRead64 (
3463 IN UINT32 Index,
3464 IN UINTN StartBit,
3465 IN UINTN EndBit
3466 );
3467
3468 /**
3469 Writes a bit field to an MSR.
3470
3471 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
3472 the StartBit and the EndBit. All other bits in the destination MSR are
3473 preserved. The MSR written is returned. Extra left bits in Value are
3474 stripped. The caller must either guarantee that Index and the data written is
3475 valid, or the caller must set up exception handlers to catch the exceptions.
3476 This function is only available on IA-32 and X64.
3477
3478 If StartBit is greater than 63, then ASSERT().
3479 If EndBit is greater than 63, then ASSERT().
3480 If EndBit is less than or equal to StartBit, then ASSERT().
3481
3482 @param Index The 32-bit MSR index to write.
3483 @param StartBit The ordinal of the least significant bit in the bit field.
3484 Range 0..63.
3485 @param EndBit The ordinal of the most significant bit in the bit field.
3486 Range 0..63.
3487 @param Value New value of the bit field.
3488
3489 @return The value written back to the MSR.
3490
3491 **/
3492 UINT64
3493 EFIAPI
3494 AsmMsrBitFieldWrite64 (
3495 IN UINT32 Index,
3496 IN UINTN StartBit,
3497 IN UINTN EndBit,
3498 IN UINT64 Value
3499 );
3500
3501 /**
3502 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
3503 writes the result back to the bit field in the 64-bit MSR.
3504
3505 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3506 between the read result and the value specified by OrData, and writes the
3507 result to the 64-bit MSR specified by Index. The value written to the MSR is
3508 returned. Extra left bits in OrData are stripped. The caller must either
3509 guarantee that Index and the data written is valid, or the caller must set up
3510 exception handlers to catch the exceptions. This function is only available
3511 on IA-32 and X64.
3512
3513 If StartBit is greater than 63, then ASSERT().
3514 If EndBit is greater than 63, then ASSERT().
3515 If EndBit is less than or equal to StartBit, then ASSERT().
3516
3517 @param Index The 32-bit MSR index to write.
3518 @param StartBit The ordinal of the least significant bit in the bit field.
3519 Range 0..63.
3520 @param EndBit The ordinal of the most significant bit in the bit field.
3521 Range 0..63.
3522 @param OrData The value to OR with the read value from the bit field.
3523
3524 @return The value written back to the MSR.
3525
3526 **/
3527 UINT64
3528 EFIAPI
3529 AsmMsrBitFieldOr64 (
3530 IN UINT32 Index,
3531 IN UINTN StartBit,
3532 IN UINTN EndBit,
3533 IN UINT64 OrData
3534 );
3535
3536 /**
3537 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
3538 result back to the bit field in the 64-bit MSR.
3539
3540 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3541 read result and the value specified by AndData, and writes the result to the
3542 64-bit MSR specified by Index. The value written to the MSR is returned.
3543 Extra left bits in AndData are stripped. The caller must either guarantee
3544 that Index and the data written is valid, or the caller must set up exception
3545 handlers to catch the exceptions. This function is only available on IA-32
3546 and X64.
3547
3548 If StartBit is greater than 63, then ASSERT().
3549 If EndBit is greater than 63, then ASSERT().
3550 If EndBit is less than or equal to StartBit, then ASSERT().
3551
3552 @param Index The 32-bit MSR index to write.
3553 @param StartBit The ordinal of the least significant bit in the bit field.
3554 Range 0..63.
3555 @param EndBit The ordinal of the most significant bit in the bit field.
3556 Range 0..63.
3557 @param AndData The value to AND with the read value from the bit field.
3558
3559 @return The value written back to the MSR.
3560
3561 **/
3562 UINT64
3563 EFIAPI
3564 AsmMsrBitFieldAnd64 (
3565 IN UINT32 Index,
3566 IN UINTN StartBit,
3567 IN UINTN EndBit,
3568 IN UINT64 AndData
3569 );
3570
3571 /**
3572 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
3573 bitwise inclusive OR, and writes the result back to the bit field in the
3574 64-bit MSR.
3575
3576 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
3577 a bitwise inclusive OR between the read result and the value specified by
3578 AndData, and writes the result to the 64-bit MSR specified by Index. The
3579 value written to the MSR is returned. Extra left bits in both AndData and
3580 OrData are stripped. The caller must either guarantee that Index and the data
3581 written is valid, or the caller must set up exception handlers to catch the
3582 exceptions. This function is only available on IA-32 and X64.
3583
3584 If StartBit is greater than 63, then ASSERT().
3585 If EndBit is greater than 63, then ASSERT().
3586 If EndBit is less than or equal to StartBit, then ASSERT().
3587
3588 @param Index The 32-bit MSR index to write.
3589 @param StartBit The ordinal of the least significant bit in the bit field.
3590 Range 0..63.
3591 @param EndBit The ordinal of the most significant bit in the bit field.
3592 Range 0..63.
3593 @param AndData The value to AND with the read value from the bit field.
3594 @param OrData The value to OR with the result of the AND operation.
3595
3596 @return The value written back to the MSR.
3597
3598 **/
3599 UINT64
3600 EFIAPI
3601 AsmMsrBitFieldAndThenOr64 (
3602 IN UINT32 Index,
3603 IN UINTN StartBit,
3604 IN UINTN EndBit,
3605 IN UINT64 AndData,
3606 IN UINT64 OrData
3607 );
3608
3609 /**
3610 Reads the current value of the EFLAGS register.
3611
3612 Reads and returns the current value of the EFLAGS register. This function is
3613 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
3614 64-bit value on X64.
3615
3616 @return EFLAGS on IA-32 or RFLAGS on X64.
3617
3618 **/
3619 UINTN
3620 EFIAPI
3621 AsmReadEflags (
3622 VOID
3623 );
3624
3625 /**
3626 Reads the current value of the Control Register 0 (CR0).
3627
3628 Reads and returns the current value of CR0. This function is only available
3629 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3630 X64.
3631
3632 @return The value of the Control Register 0 (CR0).
3633
3634 **/
3635 UINTN
3636 EFIAPI
3637 AsmReadCr0 (
3638 VOID
3639 );
3640
3641 /**
3642 Reads the current value of the Control Register 2 (CR2).
3643
3644 Reads and returns the current value of CR2. This function is only available
3645 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3646 X64.
3647
3648 @return The value of the Control Register 2 (CR2).
3649
3650 **/
3651 UINTN
3652 EFIAPI
3653 AsmReadCr2 (
3654 VOID
3655 );
3656
3657 /**
3658 Reads the current value of the Control Register 3 (CR3).
3659
3660 Reads and returns the current value of CR3. This function is only available
3661 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3662 X64.
3663
3664 @return The value of the Control Register 3 (CR3).
3665
3666 **/
3667 UINTN
3668 EFIAPI
3669 AsmReadCr3 (
3670 VOID
3671 );
3672
3673 /**
3674 Reads the current value of the Control Register 4 (CR4).
3675
3676 Reads and returns the current value of CR4. This function is only available
3677 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3678 X64.
3679
3680 @return The value of the Control Register 4 (CR4).
3681
3682 **/
3683 UINTN
3684 EFIAPI
3685 AsmReadCr4 (
3686 VOID
3687 );
3688
3689 /**
3690 Writes a value to Control Register 0 (CR0).
3691
3692 Writes and returns a new value to CR0. This function is only available on
3693 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3694
3695 @param Cr0 The value to write to CR0.
3696
3697 @return The value written to CR0.
3698
3699 **/
3700 UINTN
3701 EFIAPI
3702 AsmWriteCr0 (
3703 UINTN Cr0
3704 );
3705
3706 /**
3707 Writes a value to Control Register 2 (CR2).
3708
3709 Writes and returns a new value to CR2. This function is only available on
3710 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3711
3712 @param Cr2 The value to write to CR2.
3713
3714 @return The value written to CR2.
3715
3716 **/
3717 UINTN
3718 EFIAPI
3719 AsmWriteCr2 (
3720 UINTN Cr2
3721 );
3722
3723 /**
3724 Writes a value to Control Register 3 (CR3).
3725
3726 Writes and returns a new value to CR3. This function is only available on
3727 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3728
3729 @param Cr3 The value to write to CR3.
3730
3731 @return The value written to CR3.
3732
3733 **/
3734 UINTN
3735 EFIAPI
3736 AsmWriteCr3 (
3737 UINTN Cr3
3738 );
3739
3740 /**
3741 Writes a value to Control Register 4 (CR4).
3742
3743 Writes and returns a new value to CR4. This function is only available on
3744 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3745
3746 @param Cr4 The value to write to CR4.
3747
3748 @return The value written to CR4.
3749
3750 **/
3751 UINTN
3752 EFIAPI
3753 AsmWriteCr4 (
3754 UINTN Cr4
3755 );
3756
3757 /**
3758 Reads the current value of Debug Register 0 (DR0).
3759
3760 Reads and returns the current value of DR0. This function is only available
3761 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3762 X64.
3763
3764 @return The value of Debug Register 0 (DR0).
3765
3766 **/
3767 UINTN
3768 EFIAPI
3769 AsmReadDr0 (
3770 VOID
3771 );
3772
3773 /**
3774 Reads the current value of Debug Register 1 (DR1).
3775
3776 Reads and returns the current value of DR1. This function is only available
3777 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3778 X64.
3779
3780 @return The value of Debug Register 1 (DR1).
3781
3782 **/
3783 UINTN
3784 EFIAPI
3785 AsmReadDr1 (
3786 VOID
3787 );
3788
3789 /**
3790 Reads the current value of Debug Register 2 (DR2).
3791
3792 Reads and returns the current value of DR2. This function is only available
3793 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3794 X64.
3795
3796 @return The value of Debug Register 2 (DR2).
3797
3798 **/
3799 UINTN
3800 EFIAPI
3801 AsmReadDr2 (
3802 VOID
3803 );
3804
3805 /**
3806 Reads the current value of Debug Register 3 (DR3).
3807
3808 Reads and returns the current value of DR3. This function is only available
3809 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3810 X64.
3811
3812 @return The value of Debug Register 3 (DR3).
3813
3814 **/
3815 UINTN
3816 EFIAPI
3817 AsmReadDr3 (
3818 VOID
3819 );
3820
3821 /**
3822 Reads the current value of Debug Register 4 (DR4).
3823
3824 Reads and returns the current value of DR4. This function is only available
3825 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3826 X64.
3827
3828 @return The value of Debug Register 4 (DR4).
3829
3830 **/
3831 UINTN
3832 EFIAPI
3833 AsmReadDr4 (
3834 VOID
3835 );
3836
3837 /**
3838 Reads the current value of Debug Register 5 (DR5).
3839
3840 Reads and returns the current value of DR5. This function is only available
3841 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3842 X64.
3843
3844 @return The value of Debug Register 5 (DR5).
3845
3846 **/
3847 UINTN
3848 EFIAPI
3849 AsmReadDr5 (
3850 VOID
3851 );
3852
3853 /**
3854 Reads the current value of Debug Register 6 (DR6).
3855
3856 Reads and returns the current value of DR6. This function is only available
3857 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3858 X64.
3859
3860 @return The value of Debug Register 6 (DR6).
3861
3862 **/
3863 UINTN
3864 EFIAPI
3865 AsmReadDr6 (
3866 VOID
3867 );
3868
3869 /**
3870 Reads the current value of Debug Register 7 (DR7).
3871
3872 Reads and returns the current value of DR7. This function is only available
3873 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
3874 X64.
3875
3876 @return The value of Debug Register 7 (DR7).
3877
3878 **/
3879 UINTN
3880 EFIAPI
3881 AsmReadDr7 (
3882 VOID
3883 );
3884
3885 /**
3886 Writes a value to Debug Register 0 (DR0).
3887
3888 Writes and returns a new value to DR0. This function is only available on
3889 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3890
3891 @param Dr0 The value to write to Dr0.
3892
3893 @return The value written to Debug Register 0 (DR0).
3894
3895 **/
3896 UINTN
3897 EFIAPI
3898 AsmWriteDr0 (
3899 UINTN Dr0
3900 );
3901
3902 /**
3903 Writes a value to Debug Register 1 (DR1).
3904
3905 Writes and returns a new value to DR1. This function is only available on
3906 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3907
3908 @param Dr1 The value to write to Dr1.
3909
3910 @return The value written to Debug Register 1 (DR1).
3911
3912 **/
3913 UINTN
3914 EFIAPI
3915 AsmWriteDr1 (
3916 UINTN Dr1
3917 );
3918
3919 /**
3920 Writes a value to Debug Register 2 (DR2).
3921
3922 Writes and returns a new value to DR2. This function is only available on
3923 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3924
3925 @param Dr2 The value to write to Dr2.
3926
3927 @return The value written to Debug Register 2 (DR2).
3928
3929 **/
3930 UINTN
3931 EFIAPI
3932 AsmWriteDr2 (
3933 UINTN Dr2
3934 );
3935
3936 /**
3937 Writes a value to Debug Register 3 (DR3).
3938
3939 Writes and returns a new value to DR3. This function is only available on
3940 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3941
3942 @param Dr3 The value to write to Dr3.
3943
3944 @return The value written to Debug Register 3 (DR3).
3945
3946 **/
3947 UINTN
3948 EFIAPI
3949 AsmWriteDr3 (
3950 UINTN Dr3
3951 );
3952
3953 /**
3954 Writes a value to Debug Register 4 (DR4).
3955
3956 Writes and returns a new value to DR4. This function is only available on
3957 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3958
3959 @param Dr4 The value to write to Dr4.
3960
3961 @return The value written to Debug Register 4 (DR4).
3962
3963 **/
3964 UINTN
3965 EFIAPI
3966 AsmWriteDr4 (
3967 UINTN Dr4
3968 );
3969
3970 /**
3971 Writes a value to Debug Register 5 (DR5).
3972
3973 Writes and returns a new value to DR5. This function is only available on
3974 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3975
3976 @param Dr5 The value to write to Dr5.
3977
3978 @return The value written to Debug Register 5 (DR5).
3979
3980 **/
3981 UINTN
3982 EFIAPI
3983 AsmWriteDr5 (
3984 UINTN Dr5
3985 );
3986
3987 /**
3988 Writes a value to Debug Register 6 (DR6).
3989
3990 Writes and returns a new value to DR6. This function is only available on
3991 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
3992
3993 @param Dr6 The value to write to Dr6.
3994
3995 @return The value written to Debug Register 6 (DR6).
3996
3997 **/
3998 UINTN
3999 EFIAPI
4000 AsmWriteDr6 (
4001 UINTN Dr6
4002 );
4003
4004 /**
4005 Writes a value to Debug Register 7 (DR7).
4006
4007 Writes and returns a new value to DR7. This function is only available on
4008 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4009
4010 @param Dr7 The value to write to Dr7.
4011
4012 @return The value written to Debug Register 7 (DR7).
4013
4014 **/
4015 UINTN
4016 EFIAPI
4017 AsmWriteDr7 (
4018 UINTN Dr7
4019 );
4020
4021 /**
4022 Reads the current value of Code Segment Register (CS).
4023
4024 Reads and returns the current value of CS. This function is only available on
4025 IA-32 and X64.
4026
4027 @return The current value of CS.
4028
4029 **/
4030 UINT16
4031 EFIAPI
4032 AsmReadCs (
4033 VOID
4034 );
4035
4036 /**
4037 Reads the current value of Data Segment Register (DS).
4038
4039 Reads and returns the current value of DS. This function is only available on
4040 IA-32 and X64.
4041
4042 @return The current value of DS.
4043
4044 **/
4045 UINT16
4046 EFIAPI
4047 AsmReadDs (
4048 VOID
4049 );
4050
4051 /**
4052 Reads the current value of Extra Segment Register (ES).
4053
4054 Reads and returns the current value of ES. This function is only available on
4055 IA-32 and X64.
4056
4057 @return The current value of ES.
4058
4059 **/
4060 UINT16
4061 EFIAPI
4062 AsmReadEs (
4063 VOID
4064 );
4065
4066 /**
4067 Reads the current value of FS Data Segment Register (FS).
4068
4069 Reads and returns the current value of FS. This function is only available on
4070 IA-32 and X64.
4071
4072 @return The current value of FS.
4073
4074 **/
4075 UINT16
4076 EFIAPI
4077 AsmReadFs (
4078 VOID
4079 );
4080
4081 /**
4082 Reads the current value of GS Data Segment Register (GS).
4083
4084 Reads and returns the current value of GS. This function is only available on
4085 IA-32 and X64.
4086
4087 @return The current value of GS.
4088
4089 **/
4090 UINT16
4091 EFIAPI
4092 AsmReadGs (
4093 VOID
4094 );
4095
4096 /**
4097 Reads the current value of Stack Segment Register (SS).
4098
4099 Reads and returns the current value of SS. This function is only available on
4100 IA-32 and X64.
4101
4102 @return The current value of SS.
4103
4104 **/
4105 UINT16
4106 EFIAPI
4107 AsmReadSs (
4108 VOID
4109 );
4110
4111 /**
4112 Reads the current value of Task Register (TR).
4113
4114 Reads and returns the current value of TR. This function is only available on
4115 IA-32 and X64.
4116
4117 @return The current value of TR.
4118
4119 **/
4120 UINT16
4121 EFIAPI
4122 AsmReadTr (
4123 VOID
4124 );
4125
4126 /**
4127 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4128
4129 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4130 function is only available on IA-32 and X64.
4131
4132 If Gdtr is NULL, then ASSERT().
4133
4134 @param Gdtr Pointer to a GDTR descriptor.
4135
4136 **/
4137 VOID
4138 EFIAPI
4139 AsmReadGdtr (
4140 OUT IA32_DESCRIPTOR *Gdtr
4141 );
4142
4143 /**
4144 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4145
4146 Writes and the current GDTR descriptor specified by Gdtr. This function is
4147 only available on IA-32 and X64.
4148
4149 If Gdtr is NULL, then ASSERT().
4150
4151 @param Gdtr Pointer to a GDTR descriptor.
4152
4153 **/
4154 VOID
4155 EFIAPI
4156 AsmWriteGdtr (
4157 IN CONST IA32_DESCRIPTOR *Gdtr
4158 );
4159
4160 /**
4161 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4162
4163 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4164 function is only available on IA-32 and X64.
4165
4166 If Idtr is NULL, then ASSERT().
4167
4168 @param Idtr Pointer to a IDTR descriptor.
4169
4170 **/
4171 VOID
4172 EFIAPI
4173 AsmReadIdtr (
4174 OUT IA32_DESCRIPTOR *Idtr
4175 );
4176
4177 /**
4178 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
4179
4180 Writes the current IDTR descriptor and returns it in Idtr. This function is
4181 only available on IA-32 and X64.
4182
4183 If Idtr is NULL, then ASSERT().
4184
4185 @param Idtr Pointer to a IDTR descriptor.
4186
4187 **/
4188 VOID
4189 EFIAPI
4190 AsmWriteIdtr (
4191 IN CONST IA32_DESCRIPTOR *Idtr
4192 );
4193
4194 /**
4195 Reads the current Local Descriptor Table Register(LDTR) selector.
4196
4197 Reads and returns the current 16-bit LDTR descriptor value. This function is
4198 only available on IA-32 and X64.
4199
4200 @return The current selector of LDT.
4201
4202 **/
4203 UINT16
4204 EFIAPI
4205 AsmReadLdtr (
4206 VOID
4207 );
4208
4209 /**
4210 Writes the current Local Descriptor Table Register (GDTR) selector.
4211
4212 Writes and the current LDTR descriptor specified by Ldtr. This function is
4213 only available on IA-32 and X64.
4214
4215 @param Ldtr 16-bit LDTR selector value.
4216
4217 **/
4218 VOID
4219 EFIAPI
4220 AsmWriteLdtr (
4221 IN UINT16 Ldtr
4222 );
4223
4224 /**
4225 Save the current floating point/SSE/SSE2 context to a buffer.
4226
4227 Saves the current floating point/SSE/SSE2 state to the buffer specified by
4228 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
4229 available on IA-32 and X64.
4230
4231 If Buffer is NULL, then ASSERT().
4232 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4233
4234 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4235
4236 **/
4237 VOID
4238 EFIAPI
4239 AsmFxSave (
4240 OUT IA32_FX_BUFFER *Buffer
4241 );
4242
4243 /**
4244 Restores the current floating point/SSE/SSE2 context from a buffer.
4245
4246 Restores the current floating point/SSE/SSE2 state from the buffer specified
4247 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
4248 only available on IA-32 and X64.
4249
4250 If Buffer is NULL, then ASSERT().
4251 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
4252 If Buffer was not saved with AsmFxSave(), then ASSERT().
4253
4254 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
4255
4256 **/
4257 VOID
4258 EFIAPI
4259 AsmFxRestore (
4260 IN CONST IA32_FX_BUFFER *Buffer
4261 );
4262
4263 /**
4264 Reads the current value of 64-bit MMX Register #0 (MM0).
4265
4266 Reads and returns the current value of MM0. This function is only available
4267 on IA-32 and X64.
4268
4269 @return The current value of MM0.
4270
4271 **/
4272 UINT64
4273 EFIAPI
4274 AsmReadMm0 (
4275 VOID
4276 );
4277
4278 /**
4279 Reads the current value of 64-bit MMX Register #1 (MM1).
4280
4281 Reads and returns the current value of MM1. This function is only available
4282 on IA-32 and X64.
4283
4284 @return The current value of MM1.
4285
4286 **/
4287 UINT64
4288 EFIAPI
4289 AsmReadMm1 (
4290 VOID
4291 );
4292
4293 /**
4294 Reads the current value of 64-bit MMX Register #2 (MM2).
4295
4296 Reads and returns the current value of MM2. This function is only available
4297 on IA-32 and X64.
4298
4299 @return The current value of MM2.
4300
4301 **/
4302 UINT64
4303 EFIAPI
4304 AsmReadMm2 (
4305 VOID
4306 );
4307
4308 /**
4309 Reads the current value of 64-bit MMX Register #3 (MM3).
4310
4311 Reads and returns the current value of MM3. This function is only available
4312 on IA-32 and X64.
4313
4314 @return The current value of MM3.
4315
4316 **/
4317 UINT64
4318 EFIAPI
4319 AsmReadMm3 (
4320 VOID
4321 );
4322
4323 /**
4324 Reads the current value of 64-bit MMX Register #4 (MM4).
4325
4326 Reads and returns the current value of MM4. This function is only available
4327 on IA-32 and X64.
4328
4329 @return The current value of MM4.
4330
4331 **/
4332 UINT64
4333 EFIAPI
4334 AsmReadMm4 (
4335 VOID
4336 );
4337
4338 /**
4339 Reads the current value of 64-bit MMX Register #5 (MM5).
4340
4341 Reads and returns the current value of MM5. This function is only available
4342 on IA-32 and X64.
4343
4344 @return The current value of MM5.
4345
4346 **/
4347 UINT64
4348 EFIAPI
4349 AsmReadMm5 (
4350 VOID
4351 );
4352
4353 /**
4354 Reads the current value of 64-bit MMX Register #6 (MM6).
4355
4356 Reads and returns the current value of MM6. This function is only available
4357 on IA-32 and X64.
4358
4359 @return The current value of MM6.
4360
4361 **/
4362 UINT64
4363 EFIAPI
4364 AsmReadMm6 (
4365 VOID
4366 );
4367
4368 /**
4369 Reads the current value of 64-bit MMX Register #7 (MM7).
4370
4371 Reads and returns the current value of MM7. This function is only available
4372 on IA-32 and X64.
4373
4374 @return The current value of MM7.
4375
4376 **/
4377 UINT64
4378 EFIAPI
4379 AsmReadMm7 (
4380 VOID
4381 );
4382
4383 /**
4384 Writes the current value of 64-bit MMX Register #0 (MM0).
4385
4386 Writes the current value of MM0. This function is only available on IA32 and
4387 X64.
4388
4389 @param Value The 64-bit value to write to MM0.
4390
4391 **/
4392 VOID
4393 EFIAPI
4394 AsmWriteMm0 (
4395 IN UINT64 Value
4396 );
4397
4398 /**
4399 Writes the current value of 64-bit MMX Register #1 (MM1).
4400
4401 Writes the current value of MM1. This function is only available on IA32 and
4402 X64.
4403
4404 @param Value The 64-bit value to write to MM1.
4405
4406 **/
4407 VOID
4408 EFIAPI
4409 AsmWriteMm1 (
4410 IN UINT64 Value
4411 );
4412
4413 /**
4414 Writes the current value of 64-bit MMX Register #2 (MM2).
4415
4416 Writes the current value of MM2. This function is only available on IA32 and
4417 X64.
4418
4419 @param Value The 64-bit value to write to MM2.
4420
4421 **/
4422 VOID
4423 EFIAPI
4424 AsmWriteMm2 (
4425 IN UINT64 Value
4426 );
4427
4428 /**
4429 Writes the current value of 64-bit MMX Register #3 (MM3).
4430
4431 Writes the current value of MM3. This function is only available on IA32 and
4432 X64.
4433
4434 @param Value The 64-bit value to write to MM3.
4435
4436 **/
4437 VOID
4438 EFIAPI
4439 AsmWriteMm3 (
4440 IN UINT64 Value
4441 );
4442
4443 /**
4444 Writes the current value of 64-bit MMX Register #4 (MM4).
4445
4446 Writes the current value of MM4. This function is only available on IA32 and
4447 X64.
4448
4449 @param Value The 64-bit value to write to MM4.
4450
4451 **/
4452 VOID
4453 EFIAPI
4454 AsmWriteMm4 (
4455 IN UINT64 Value
4456 );
4457
4458 /**
4459 Writes the current value of 64-bit MMX Register #5 (MM5).
4460
4461 Writes the current value of MM5. This function is only available on IA32 and
4462 X64.
4463
4464 @param Value The 64-bit value to write to MM5.
4465
4466 **/
4467 VOID
4468 EFIAPI
4469 AsmWriteMm5 (
4470 IN UINT64 Value
4471 );
4472
4473 /**
4474 Writes the current value of 64-bit MMX Register #6 (MM6).
4475
4476 Writes the current value of MM6. This function is only available on IA32 and
4477 X64.
4478
4479 @param Value The 64-bit value to write to MM6.
4480
4481 **/
4482 VOID
4483 EFIAPI
4484 AsmWriteMm6 (
4485 IN UINT64 Value
4486 );
4487
4488 /**
4489 Writes the current value of 64-bit MMX Register #7 (MM7).
4490
4491 Writes the current value of MM7. This function is only available on IA32 and
4492 X64.
4493
4494 @param Value The 64-bit value to write to MM7.
4495
4496 **/
4497 VOID
4498 EFIAPI
4499 AsmWriteMm7 (
4500 IN UINT64 Value
4501 );
4502
4503 /**
4504 Reads the current value of Time Stamp Counter (TSC).
4505
4506 Reads and returns the current value of TSC. This function is only available
4507 on IA-32 and X64.
4508
4509 @return The current value of TSC
4510
4511 **/
4512 UINT64
4513 EFIAPI
4514 AsmReadTsc (
4515 VOID
4516 );
4517
4518 /**
4519 Reads the current value of a Performance Counter (PMC).
4520
4521 Reads and returns the current value of performance counter specified by
4522 Index. This function is only available on IA-32 and X64.
4523
4524 @param Index The 32-bit Performance Counter index to read.
4525
4526 @return The value of the PMC specified by Index.
4527
4528 **/
4529 UINT64
4530 EFIAPI
4531 AsmReadPmc (
4532 IN UINT32 Index
4533 );
4534
4535 /**
4536 Sets up a monitor buffer that is used by AsmMwait().
4537
4538 Executes a MONITOR instruction with the register state specified by Eax, Ecx
4539 and Edx. Returns Eax. This function is only available on IA-32 and X64.
4540
4541 @param Eax The value to load into EAX or RAX before executing the MONITOR
4542 instruction.
4543 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4544 instruction.
4545 @param Edx The value to load into EDX or RDX before executing the MONITOR
4546 instruction.
4547
4548 @return Eax
4549
4550 **/
4551 UINTN
4552 EFIAPI
4553 AsmMonitor (
4554 IN UINTN Eax,
4555 IN UINTN Ecx,
4556 IN UINTN Edx
4557 );
4558
4559 /**
4560 Executes an MWAIT instruction.
4561
4562 Executes an MWAIT instruction with the register state specified by Eax and
4563 Ecx. Returns Eax. This function is only available on IA-32 and X64.
4564
4565 @param Eax The value to load into EAX or RAX before executing the MONITOR
4566 instruction.
4567 @param Ecx The value to load into ECX or RCX before executing the MONITOR
4568 instruction.
4569
4570 @return Eax
4571
4572 **/
4573 UINTN
4574 EFIAPI
4575 AsmMwait (
4576 IN UINTN Eax,
4577 IN UINTN Ecx
4578 );
4579
4580 /**
4581 Executes a WBINVD instruction.
4582
4583 Executes a WBINVD instruction. This function is only available on IA-32 and
4584 X64.
4585
4586 **/
4587 VOID
4588 EFIAPI
4589 AsmWbinvd (
4590 VOID
4591 );
4592
4593 /**
4594 Executes a INVD instruction.
4595
4596 Executes a INVD instruction. This function is only available on IA-32 and
4597 X64.
4598
4599 **/
4600 VOID
4601 EFIAPI
4602 AsmInvd (
4603 VOID
4604 );
4605
4606 /**
4607 Flushes a cache line from all the instruction and data caches within the
4608 coherency domain of the CPU.
4609
4610 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
4611 This function is only available on IA-32 and X64.
4612
4613 @param LinearAddress The address of the cache line to flush. If the CPU is
4614 in a physical addressing mode, then LinearAddress is a
4615 physical address. If the CPU is in a virtual
4616 addressing mode, then LinearAddress is a virtual
4617 address.
4618
4619 @return LinearAddress
4620 **/
4621 VOID *
4622 EFIAPI
4623 AsmFlushCacheLine (
4624 IN VOID *LinearAddress
4625 );
4626
4627 /**
4628 Enables the 32-bit paging mode on the CPU.
4629
4630 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4631 must be properly initialized prior to calling this service. This function
4632 assumes the current execution mode is 32-bit protected mode. This function is
4633 only available on IA-32. After the 32-bit paging mode is enabled, control is
4634 transferred to the function specified by EntryPoint using the new stack
4635 specified by NewStack and passing in the parameters specified by Context1 and
4636 Context2. Context1 and Context2 are optional and may be NULL. The function
4637 EntryPoint must never return.
4638
4639 If the current execution mode is not 32-bit protected mode, then ASSERT().
4640 If EntryPoint is NULL, then ASSERT().
4641 If NewStack is NULL, then ASSERT().
4642
4643 There are a number of constraints that must be followed before calling this
4644 function:
4645 1) Interrupts must be disabled.
4646 2) The caller must be in 32-bit protected mode with flat descriptors. This
4647 means all descriptors must have a base of 0 and a limit of 4GB.
4648 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
4649 descriptors.
4650 4) CR3 must point to valid page tables that will be used once the transition
4651 is complete, and those page tables must guarantee that the pages for this
4652 function and the stack are identity mapped.
4653
4654 @param EntryPoint A pointer to function to call with the new stack after
4655 paging is enabled.
4656 @param Context1 A pointer to the context to pass into the EntryPoint
4657 function as the first parameter after paging is enabled.
4658 @param Context2 A pointer to the context to pass into the EntryPoint
4659 function as the second parameter after paging is enabled.
4660 @param NewStack A pointer to the new stack to use for the EntryPoint
4661 function after paging is enabled.
4662
4663 **/
4664 VOID
4665 EFIAPI
4666 AsmEnablePaging32 (
4667 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
4668 IN VOID *Context1, OPTIONAL
4669 IN VOID *Context2, OPTIONAL
4670 IN VOID *NewStack
4671 );
4672
4673 /**
4674 Disables the 32-bit paging mode on the CPU.
4675
4676 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
4677 mode. This function assumes the current execution mode is 32-paged protected
4678 mode. This function is only available on IA-32. After the 32-bit paging mode
4679 is disabled, control is transferred to the function specified by EntryPoint
4680 using the new stack specified by NewStack and passing in the parameters
4681 specified by Context1 and Context2. Context1 and Context2 are optional and
4682 may be NULL. The function EntryPoint must never return.
4683
4684 If the current execution mode is not 32-bit paged mode, then ASSERT().
4685 If EntryPoint is NULL, then ASSERT().
4686 If NewStack is NULL, then ASSERT().
4687
4688 There are a number of constraints that must be followed before calling this
4689 function:
4690 1) Interrupts must be disabled.
4691 2) The caller must be in 32-bit paged mode.
4692 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
4693 4) CR3 must point to valid page tables that guarantee that the pages for
4694 this function and the stack are identity mapped.
4695
4696 @param EntryPoint A pointer to function to call with the new stack after
4697 paging is disabled.
4698 @param Context1 A pointer to the context to pass into the EntryPoint
4699 function as the first parameter after paging is disabled.
4700 @param Context2 A pointer to the context to pass into the EntryPoint
4701 function as the second parameter after paging is
4702 disabled.
4703 @param NewStack A pointer to the new stack to use for the EntryPoint
4704 function after paging is disabled.
4705
4706 **/
4707 VOID
4708 EFIAPI
4709 AsmDisablePaging32 (
4710 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
4711 IN VOID *Context1, OPTIONAL
4712 IN VOID *Context2, OPTIONAL
4713 IN VOID *NewStack
4714 );
4715
4716 /**
4717 Enables the 64-bit paging mode on the CPU.
4718
4719 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
4720 must be properly initialized prior to calling this service. This function
4721 assumes the current execution mode is 32-bit protected mode with flat
4722 descriptors. This function is only available on IA-32. After the 64-bit
4723 paging mode is enabled, control is transferred to the function specified by
4724 EntryPoint using the new stack specified by NewStack and passing in the
4725 parameters specified by Context1 and Context2. Context1 and Context2 are
4726 optional and may be 0. The function EntryPoint must never return.
4727
4728 If the current execution mode is not 32-bit protected mode with flat
4729 descriptors, then ASSERT().
4730 If EntryPoint is 0, then ASSERT().
4731 If NewStack is 0, then ASSERT().
4732
4733 @param Cs The 16-bit selector to load in the CS before EntryPoint
4734 is called. The descriptor in the GDT that this selector
4735 references must be setup for long mode.
4736 @param EntryPoint The 64-bit virtual address of the function to call with
4737 the new stack after paging is enabled.
4738 @param Context1 The 64-bit virtual address of the context to pass into
4739 the EntryPoint function as the first parameter after
4740 paging is enabled.
4741 @param Context2 The 64-bit virtual address of the context to pass into
4742 the EntryPoint function as the second parameter after
4743 paging is enabled.
4744 @param NewStack The 64-bit virtual address of the new stack to use for
4745 the EntryPoint function after paging is enabled.
4746
4747 **/
4748 VOID
4749 EFIAPI
4750 AsmEnablePaging64 (
4751 IN UINT16 CodeSelector,
4752 IN UINT64 EntryPoint,
4753 IN UINT64 Context1, OPTIONAL
4754 IN UINT64 Context2, OPTIONAL
4755 IN UINT64 NewStack
4756 );
4757
4758 /**
4759 Disables the 64-bit paging mode on the CPU.
4760
4761 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
4762 mode. This function assumes the current execution mode is 64-paging mode.
4763 This function is only available on X64. After the 64-bit paging mode is
4764 disabled, control is transferred to the function specified by EntryPoint
4765 using the new stack specified by NewStack and passing in the parameters
4766 specified by Context1 and Context2. Context1 and Context2 are optional and
4767 may be 0. The function EntryPoint must never return.
4768
4769 If the current execution mode is not 64-bit paged mode, then ASSERT().
4770 If EntryPoint is 0, then ASSERT().
4771 If NewStack is 0, then ASSERT().
4772
4773 @param Cs The 16-bit selector to load in the CS before EntryPoint
4774 is called. The descriptor in the GDT that this selector
4775 references must be setup for 32-bit protected mode.
4776 @param EntryPoint The 64-bit virtual address of the function to call with
4777 the new stack after paging is disabled.
4778 @param Context1 The 64-bit virtual address of the context to pass into
4779 the EntryPoint function as the first parameter after
4780 paging is disabled.
4781 @param Context2 The 64-bit virtual address of the context to pass into
4782 the EntryPoint function as the second parameter after
4783 paging is disabled.
4784 @param NewStack The 64-bit virtual address of the new stack to use for
4785 the EntryPoint function after paging is disabled.
4786
4787 **/
4788 VOID
4789 EFIAPI
4790 AsmDisablePaging64 (
4791 IN UINT16 CodeSelector,
4792 IN UINT32 EntryPoint,
4793 IN UINT32 Context1, OPTIONAL
4794 IN UINT32 Context2, OPTIONAL
4795 IN UINT32 NewStack
4796 );
4797
4798 //
4799 // 16-bit thunking services
4800 //
4801
4802 /**
4803 Retrieves the properties for 16-bit thunk functions.
4804
4805 Computes the size of the buffer and stack below 1MB required to use the
4806 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
4807 buffer size is returned in RealModeBufferSize, and the stack size is returned
4808 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
4809 then the actual minimum stack size is ExtraStackSize plus the maximum number
4810 of bytes that need to be passed to the 16-bit real mode code.
4811
4812 If RealModeBufferSize is NULL, then ASSERT().
4813 If ExtraStackSize is NULL, then ASSERT().
4814
4815 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
4816 required to use the 16-bit thunk functions.
4817 @param ExtraStackSize A pointer to the extra size of stack below 1MB
4818 that the 16-bit thunk functions require for
4819 temporary storage in the transition to and from
4820 16-bit real mode.
4821
4822 **/
4823 VOID
4824 EFIAPI
4825 AsmGetThunk16Properties (
4826 OUT UINT32 *RealModeBufferSize,
4827 OUT UINT32 *ExtraStackSize
4828 );
4829
4830 /**
4831 Prepares all structures a code required to use AsmThunk16().
4832
4833 Prepares all structures and code required to use AsmThunk16().
4834
4835 If ThunkContext is NULL, then ASSERT().
4836
4837 @param ThunkContext A pointer to the context structure that describes the
4838 16-bit real mode code to call.
4839
4840 **/
4841 VOID
4842 EFIAPI
4843 AsmPrepareThunk16 (
4844 OUT THUNK_CONTEXT *ThunkContext
4845 );
4846
4847 /**
4848 Transfers control to a 16-bit real mode entry point and returns the results.
4849
4850 Transfers control to a 16-bit real mode entry point and returns the results.
4851 AsmPrepareThunk16() must be called with ThunkContext before this function is
4852 used.
4853
4854 If ThunkContext is NULL, then ASSERT().
4855 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
4856
4857 @param ThunkContext A pointer to the context structure that describes the
4858 16-bit real mode code to call.
4859
4860 **/
4861 VOID
4862 EFIAPI
4863 AsmThunk16 (
4864 IN OUT THUNK_CONTEXT *ThunkContext
4865 );
4866
4867 /**
4868 Prepares all structures and code for a 16-bit real mode thunk, transfers
4869 control to a 16-bit real mode entry point, and returns the results.
4870
4871 Prepares all structures and code for a 16-bit real mode thunk, transfers
4872 control to a 16-bit real mode entry point, and returns the results. If the
4873 caller only need to perform a single 16-bit real mode thunk, then this
4874 service should be used. If the caller intends to make more than one 16-bit
4875 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
4876 once and AsmThunk16() can be called for each 16-bit real mode thunk.
4877
4878 If ThunkContext is NULL, then ASSERT().
4879
4880 @param ThunkContext A pointer to the context structure that describes the
4881 16-bit real mode code to call.
4882
4883 **/
4884 VOID
4885 EFIAPI
4886 AsmPrepareAndThunk16 (
4887 IN OUT THUNK_CONTEXT *ThunkContext
4888 );
4889
4890 #endif