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