]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Include/Library/EdkIIGlueBaseLib.h
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Include / Library / EdkIIGlueBaseLib.h
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. 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 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 Copies one Null-terminated Unicode string with a maximum length to another
211 Null-terminated Unicode string with a maximum length and returns the new
212 Unicode string.
213
214 This function copies the contents of the Unicode string Source to the Unicode
215 string Destination, and returns Destination. At most, Length Unicode
216 characters are copied from Source to Destination. If Length is 0, then
217 Destination is returned unmodified. If Length is greater that the number of
218 Unicode characters in Source, then Destination is padded with Null Unicode
219 characters. If Source and Destination overlap, then the results are
220 undefined.
221
222 If Length > 0 and Destination is NULL, then ASSERT().
223 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
224 If Length > 0 and Source is NULL, then ASSERT().
225 If Length > 0 and Source is not aligned on a 16-bit bounadry, then ASSERT().
226 If Source and Destination overlap, then ASSERT().
227 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
228 PcdMaximumUnicodeStringLength Unicode characters not including the
229 Null-terminator, then ASSERT().
230
231 @param Destination Pointer to a Null-terminated Unicode string.
232 @param Source Pointer to a Null-terminated Unicode string.
233 @param Length Maximum number of Unicode characters to copy.
234
235 @return Destination
236
237 **/
238 CHAR16 *
239 EFIAPI
240 GlueStrnCpy (
241 OUT CHAR16 *Destination,
242 IN CONST CHAR16 *Source,
243 IN UINTN Length
244 );
245 /**
246 Returns the length of a Null-terminated Unicode string.
247
248 This function returns the number of Unicode characters in the Null-terminated
249 Unicode string specified by String.
250
251 If String is NULL, then ASSERT().
252 If String is not aligned on a 16-bit boundary, then ASSERT().
253 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
254 PcdMaximumUnicodeStringLength Unicode characters not including the
255 Null-terminator, then ASSERT().
256
257 @param String Pointer to a Null-terminated Unicode string.
258
259 @return The length of String.
260
261 **/
262 UINTN
263 EFIAPI
264 GlueStrLen (
265 IN CONST CHAR16 *String
266 );
267 /**
268 Returns the size of a Null-terminated Unicode string in bytes, including the
269 Null terminator.
270
271 This function returns the size, in bytes, of the Null-terminated Unicode
272 string specified by String.
273
274 If String is NULL, then ASSERT().
275 If String is not aligned on a 16-bit boundary, then ASSERT().
276 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
277 PcdMaximumUnicodeStringLength Unicode characters not including the
278 Null-terminator, then ASSERT().
279
280 @param String Pointer to a Null-terminated Unicode string.
281
282 @return The size of String.
283
284 **/
285 UINTN
286 EFIAPI
287 GlueStrSize (
288 IN CONST CHAR16 *String
289 );
290 /**
291 Compares two Null-terminated Unicode strings, and returns the difference
292 between the first mismatched Unicode characters.
293
294 This function compares the Null-terminated Unicode string FirstString to the
295 Null-terminated Unicode string SecondString. If FirstString is identical to
296 SecondString, then 0 is returned. Otherwise, the value returned is the first
297 mismatched Unicode character in SecondString subtracted from the first
298 mismatched Unicode character in FirstString.
299
300 If FirstString is NULL, then ASSERT().
301 If FirstString is not aligned on a 16-bit boundary, then ASSERT().
302 If SecondString is NULL, then ASSERT().
303 If SecondString is not aligned on a 16-bit boundary, then ASSERT().
304 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
305 than PcdMaximumUnicodeStringLength Unicode characters not including the
306 Null-terminator, then ASSERT().
307 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
308 than PcdMaximumUnicodeStringLength Unicode characters not including the
309 Null-terminator, then ASSERT().
310
311 @param FirstString Pointer to a Null-terminated Unicode string.
312 @param SecondString Pointer to a Null-terminated Unicode string.
313
314 @retval 0 FirstString is identical to SecondString.
315 @retval !=0 FirstString is not identical to SecondString.
316
317 **/
318 INTN
319 EFIAPI
320 GlueStrCmp (
321 IN CONST CHAR16 *FirstString,
322 IN CONST CHAR16 *SecondString
323 );
324 /**
325 Compares two Null-terminated Unicode strings with maximum lengths, and
326 returns the difference between the first mismatched Unicode characters.
327
328 This function compares the Null-terminated Unicode string FirstString to the
329 Null-terminated Unicode string SecondString. At most, Length Unicode
330 characters will be compared. If Length is 0, then 0 is returned. If
331 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
332 value returned is the first mismatched Unicode character in SecondString
333 subtracted from the first mismatched Unicode character in FirstString.
334
335 If Length > 0 and FirstString is NULL, then ASSERT().
336 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().
337 If Length > 0 and SecondString is NULL, then ASSERT().
338 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().
339 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more
340 than PcdMaximumUnicodeStringLength Unicode characters not including the
341 Null-terminator, then ASSERT().
342 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more
343 than PcdMaximumUnicodeStringLength Unicode characters not including the
344 Null-terminator, then ASSERT().
345
346 @param FirstString Pointer to a Null-terminated Unicode string.
347 @param SecondString Pointer to a Null-terminated Unicode string.
348 @param Length Maximum number of Unicode characters to compare.
349
350 @retval 0 FirstString is identical to SecondString.
351 @retval !=0 FirstString is not identical to SecondString.
352
353 **/
354 INTN
355 EFIAPI
356 GlueStrnCmp (
357 IN CONST CHAR16 *FirstString,
358 IN CONST CHAR16 *SecondString,
359 IN UINTN Length
360 );
361 /**
362 Concatenates one Null-terminated Unicode string to another Null-terminated
363 Unicode string, and returns the concatenated Unicode string.
364
365 This function concatenates two Null-terminated Unicode strings. The contents
366 of Null-terminated Unicode string Source are concatenated to the end of
367 Null-terminated Unicode string Destination. The Null-terminated concatenated
368 Unicode String is returned. If Source and Destination overlap, then the
369 results are undefined.
370
371 If Destination is NULL, then ASSERT().
372 If Destination is not aligned on a 16-bit bounadary, then ASSERT().
373 If Source is NULL, then ASSERT().
374 If Source is not aligned on a 16-bit bounadary, then ASSERT().
375 If Source and Destination overlap, then ASSERT().
376 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
377 than PcdMaximumUnicodeStringLength Unicode characters not including the
378 Null-terminator, then ASSERT().
379 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
380 PcdMaximumUnicodeStringLength Unicode characters not including the
381 Null-terminator, then ASSERT().
382 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
383 and Source results in a Unicode string with more than
384 PcdMaximumUnicodeStringLength Unicode characters not including the
385 Null-terminator, then ASSERT().
386
387 @param Destination Pointer to a Null-terminated Unicode string.
388 @param Source Pointer to a Null-terminated Unicode string.
389
390 @return Destination
391
392 **/
393 CHAR16 *
394 EFIAPI
395 GlueStrCat (
396 IN OUT CHAR16 *Destination,
397 IN CONST CHAR16 *Source
398 );
399 /**
400 Concatenates one Null-terminated Unicode string with a maximum length to the
401 end of another Null-terminated Unicode string, and returns the concatenated
402 Unicode string.
403
404 This function concatenates two Null-terminated Unicode strings. The contents
405 of Null-terminated Unicode string Source are concatenated to the end of
406 Null-terminated Unicode string Destination, and Destination is returned. At
407 most, Length Unicode characters are concatenated from Source to the end of
408 Destination, and Destination is always Null-terminated. If Length is 0, then
409 Destination is returned unmodified. If Source and Destination overlap, then
410 the results are undefined.
411
412 If Destination is NULL, then ASSERT().
413 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().
414 If Length > 0 and Source is NULL, then ASSERT().
415 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().
416 If Source and Destination overlap, then ASSERT().
417 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more
418 than PcdMaximumUnicodeStringLength Unicode characters not including the
419 Null-terminator, then ASSERT().
420 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
421 PcdMaximumUnicodeStringLength Unicode characters not including the
422 Null-terminator, then ASSERT().
423 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination
424 and Source results in a Unicode string with more than
425 PcdMaximumUnicodeStringLength Unicode characters not including the
426 Null-terminator, then ASSERT().
427
428 @param Destination Pointer to a Null-terminated Unicode string.
429 @param Source Pointer to a Null-terminated Unicode string.
430 @param Length Maximum number of Unicode characters to concatenate from
431 Source.
432
433 @return Destination
434
435 **/
436 CHAR16 *
437 EFIAPI
438 GlueStrnCat (
439 IN OUT CHAR16 *Destination,
440 IN CONST CHAR16 *Source,
441 IN UINTN Length
442 );
443
444 /**
445 Returns the first occurance of a Null-terminated Unicode sub-string
446 in a Null-terminated Unicode string.
447
448 This function scans the contents of the Null-terminated Unicode string
449 specified by String and returns the first occurrence of SearchString.
450 If SearchString is not found in String, then NULL is returned. If
451 the length of SearchString is zero, then String is
452 returned.
453
454 If String is NULL, then ASSERT().
455 If String is not aligned on a 16-bit boundary, then ASSERT().
456 If SearchString is NULL, then ASSERT().
457 If SearchString is not aligned on a 16-bit boundary, then ASSERT().
458
459 If PcdMaximumUnicodeStringLength is not zero, and SearchString
460 or String contains more than PcdMaximumUnicodeStringLength Unicode
461 characters not including the Null-terminator, then ASSERT().
462
463 @param String Pointer to a Null-terminated Unicode string.
464 @param SearchString Pointer to a Null-terminated Unicode string to search for.
465
466 @retval NULL If the SearchString does not appear in String.
467 @retval !NULL If there is a match.
468
469 **/
470 CHAR16 *
471 EFIAPI
472 StrStr (
473 IN CONST CHAR16 *String,
474 IN CONST CHAR16 *SearchString
475 );
476
477 /**
478 Convert a Null-terminated Unicode decimal string to a value of
479 type UINTN.
480
481 This function returns a value of type UINTN by interpreting the contents
482 of the Unicode string specified by String as a decimal number. The format
483 of the input Unicode string String is:
484
485 [spaces] [decimal digits].
486
487 The valid decimal digit character is in the range [0-9]. The
488 function will ignore the pad space, which includes spaces or
489 tab characters, before [decimal digits]. The running zero in the
490 beginning of [decimal digits] will be ignored. Then, the function
491 stops at the first character that is a not a valid decimal character
492 or a Null-terminator, whichever one comes first.
493
494 If String is NULL, then ASSERT().
495 If String is not aligned in a 16-bit boundary, then ASSERT().
496 If String has only pad spaces, then 0 is returned.
497 If String has no pad spaces or valid decimal digits,
498 then 0 is returned.
499 If the number represented by String overflows according
500 to the range defined by UINTN, then ASSERT().
501
502 If PcdMaximumUnicodeStringLength is not zero, and String contains
503 more than PcdMaximumUnicodeStringLength Unicode characters not including
504 the Null-terminator, then ASSERT().
505
506 @param String Pointer to a Null-terminated Unicode string.
507
508 @retval UINTN
509
510 **/
511 UINTN
512 EFIAPI
513 StrDecimalToUintn (
514 IN CONST CHAR16 *String
515 );
516
517 /**
518 Convert a Null-terminated Unicode decimal string to a value of
519 type UINT64.
520
521 This function returns a value of type UINT64 by interpreting the contents
522 of the Unicode string specified by String as a decimal number. The format
523 of the input Unicode string String is:
524
525 [spaces] [decimal digits].
526
527 The valid decimal digit character is in the range [0-9]. The
528 function will ignore the pad space, which includes spaces or
529 tab characters, before [decimal digits]. The running zero in the
530 beginning of [decimal digits] will be ignored. Then, the function
531 stops at the first character that is a not a valid decimal character
532 or a Null-terminator, whichever one comes first.
533
534 If String is NULL, then ASSERT().
535 If String is not aligned in a 16-bit boundary, then ASSERT().
536 If String has only pad spaces, then 0 is returned.
537 If String has no pad spaces or valid decimal digits,
538 then 0 is returned.
539 If the number represented by String overflows according
540 to the range defined by UINT64, then ASSERT().
541
542 If PcdMaximumUnicodeStringLength is not zero, and String contains
543 more than PcdMaximumUnicodeStringLength Unicode characters not including
544 the Null-terminator, then ASSERT().
545
546 @param String Pointer to a Null-terminated Unicode string.
547
548 @retval UINT64
549
550 **/
551 UINT64
552 EFIAPI
553 StrDecimalToUint64 (
554 IN CONST CHAR16 *String
555 );
556
557 /**
558 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.
559
560 This function returns a value of type UINTN by interpreting the contents
561 of the Unicode string specified by String as a hexadecimal number.
562 The format of the input Unicode string String is:
563
564 [spaces][zeros][x][hexadecimal digits].
565
566 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
567 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
568 If "x" appears in the input string, it must be prefixed with at least one 0.
569 The function will ignore the pad space, which includes spaces or tab characters,
570 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
571 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
572 first valid hexadecimal digit. Then, the function stops at the first character that is
573 a not a valid hexadecimal character or NULL, whichever one comes first.
574
575 If String is NULL, then ASSERT().
576 If String is not aligned in a 16-bit boundary, then ASSERT().
577 If String has only pad spaces, then zero is returned.
578 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
579 then zero is returned.
580 If the number represented by String overflows according to the range defined by
581 UINTN, then ASSERT().
582
583 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
584 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
585 then ASSERT().
586
587 @param String Pointer to a Null-terminated Unicode string.
588
589 @retval UINTN
590
591 **/
592 UINTN
593 EFIAPI
594 StrHexToUintn (
595 IN CONST CHAR16 *String
596 );
597
598 /**
599 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
600
601 This function returns a value of type UINT64 by interpreting the contents
602 of the Unicode string specified by String as a hexadecimal number.
603 The format of the input Unicode string String is
604
605 [spaces][zeros][x][hexadecimal digits].
606
607 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
608 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
609 If "x" appears in the input string, it must be prefixed with at least one 0.
610 The function will ignore the pad space, which includes spaces or tab characters,
611 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
612 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
613 first valid hexadecimal digit. Then, the function stops at the first character that is
614 a not a valid hexadecimal character or NULL, whichever one comes first.
615
616 If String is NULL, then ASSERT().
617 If String is not aligned in a 16-bit boundary, then ASSERT().
618 If String has only pad spaces, then zero is returned.
619 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
620 then zero is returned.
621 If the number represented by String overflows according to the range defined by
622 UINT64, then ASSERT().
623
624 If PcdMaximumUnicodeStringLength is not zero, and String contains more than
625 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,
626 then ASSERT().
627
628 @param String Pointer to a Null-terminated Unicode string.
629
630 @retval UINT64
631
632 **/
633 UINT64
634 EFIAPI
635 StrHexToUint64 (
636 IN CONST CHAR16 *String
637 );
638
639 /**
640 Convert one Null-terminated Unicode string to a Null-terminated
641 ASCII string and returns the ASCII string.
642
643 This function converts the content of the Unicode string Source
644 to the ASCII string Destination by copying the lower 8 bits of
645 each Unicode character. It returns Destination.
646
647 If any Unicode characters in Source contain non-zero value in
648 the upper 8 bits, then ASSERT().
649
650 If Destination is NULL, then ASSERT().
651 If Source is NULL, then ASSERT().
652 If Source is not aligned on a 16-bit boundary, then ASSERT().
653 If Source and Destination overlap, then ASSERT().
654
655 If PcdMaximumUnicodeStringLength is not zero, and Source contains
656 more than PcdMaximumUnicodeStringLength Unicode characters not including
657 the Null-terminator, then ASSERT().
658
659 If PcdMaximumAsciiStringLength is not zero, and Source contains more
660 than PcdMaximumAsciiStringLength Unicode characters not including the
661 Null-terminator, then ASSERT().
662
663 @param Source Pointer to a Null-terminated Unicode string.
664 @param Destination Pointer to a Null-terminated ASCII string.
665
666 @reture Destination
667
668 **/
669 CHAR8 *
670 EFIAPI
671 UnicodeStrToAsciiStr (
672 IN CONST CHAR16 *Source,
673 OUT CHAR8 *Destination
674 );
675
676 /**
677 Copies one Null-terminated ASCII string to another Null-terminated ASCII
678 string and returns the new ASCII string.
679
680 This function copies the contents of the ASCII string Source to the ASCII
681 string Destination, and returns Destination. If Source and Destination
682 overlap, then the results are undefined.
683
684 If Destination is NULL, then ASSERT().
685 If Source is NULL, then ASSERT().
686 If Source and Destination overlap, then ASSERT().
687 If PcdMaximumAsciiStringLength is not zero and Source contains more than
688 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
689 then ASSERT().
690
691 @param Destination Pointer to a Null-terminated ASCII string.
692 @param Source Pointer to a Null-terminated ASCII string.
693
694 @return Destination
695
696 **/
697 CHAR8 *
698 EFIAPI
699 AsciiStrCpy (
700 OUT CHAR8 *Destination,
701 IN CONST CHAR8 *Source
702 );
703 /**
704 Copies one Null-terminated ASCII string with a maximum length to another
705 Null-terminated ASCII string with a maximum length and returns the new ASCII
706 string.
707
708 This function copies the contents of the ASCII string Source to the ASCII
709 string Destination, and returns Destination. At most, Length ASCII characters
710 are copied from Source to Destination. If Length is 0, then Destination is
711 returned unmodified. If Length is greater that the number of ASCII characters
712 in Source, then Destination is padded with Null ASCII characters. If Source
713 and Destination overlap, then the results are undefined.
714
715 If Destination is NULL, then ASSERT().
716 If Source is NULL, then ASSERT().
717 If Source and Destination overlap, then ASSERT().
718 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
719 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
720 then ASSERT().
721
722 @param Destination Pointer to a Null-terminated ASCII string.
723 @param Source Pointer to a Null-terminated ASCII string.
724 @param Length Maximum number of ASCII characters to copy.
725
726 @return Destination
727
728 **/
729 CHAR8 *
730 EFIAPI
731 AsciiStrnCpy (
732 OUT CHAR8 *Destination,
733 IN CONST CHAR8 *Source,
734 IN UINTN Length
735 );
736 /**
737 Returns the length of a Null-terminated ASCII string.
738
739 This function returns the number of ASCII characters in the Null-terminated
740 ASCII string specified by String.
741
742 If Length > 0 and Destination is NULL, then ASSERT().
743 If Length > 0 and Source is NULL, then ASSERT().
744 If PcdMaximumAsciiStringLength is not zero and String contains more than
745 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
746 then ASSERT().
747
748 @param String Pointer to a Null-terminated ASCII string.
749
750 @return The length of String.
751
752 **/
753 UINTN
754 EFIAPI
755 AsciiStrLen (
756 IN CONST CHAR8 *String
757 );
758 /**
759 Returns the size of a Null-terminated ASCII string in bytes, including the
760 Null terminator.
761
762 This function returns the size, in bytes, of the Null-terminated ASCII string
763 specified by String.
764
765 If String is NULL, then ASSERT().
766 If PcdMaximumAsciiStringLength is not zero and String contains more than
767 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
768 then ASSERT().
769
770 @param String Pointer to a Null-terminated ASCII string.
771
772 @return The size of String.
773
774 **/
775 UINTN
776 EFIAPI
777 AsciiStrSize (
778 IN CONST CHAR8 *String
779 );
780 /**
781 Compares two Null-terminated ASCII strings, and returns the difference
782 between the first mismatched ASCII characters.
783
784 This function compares the Null-terminated ASCII string FirstString to the
785 Null-terminated ASCII string SecondString. If FirstString is identical to
786 SecondString, then 0 is returned. Otherwise, the value returned is the first
787 mismatched ASCII character in SecondString subtracted from the first
788 mismatched ASCII character in FirstString.
789
790 If FirstString is NULL, then ASSERT().
791 If SecondString is NULL, then ASSERT().
792 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than
793 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
794 then ASSERT().
795 If PcdMaximumAsciiStringLength is not zero and SecondString contains more
796 than PcdMaximumAsciiStringLength ASCII characters not including the
797 Null-terminator, then ASSERT().
798
799 @param FirstString Pointer to a Null-terminated ASCII string.
800 @param SecondString Pointer to a Null-terminated ASCII string.
801
802 @retval 0 FirstString is identical to SecondString.
803 @retval !=0 FirstString is not identical to SecondString.
804
805 **/
806 INTN
807 EFIAPI
808 AsciiStrCmp (
809 IN CONST CHAR8 *FirstString,
810 IN CONST CHAR8 *SecondString
811 );
812 /**
813 Performs a case insensitive comparison of two Null-terminated ASCII strings,
814 and returns the difference between the first mismatched ASCII characters.
815
816 This function performs a case insensitive comparison of the Null-terminated
817 ASCII string FirstString to the Null-terminated ASCII string SecondString. If
818 FirstString is identical to SecondString, then 0 is returned. Otherwise, the
819 value returned is the first mismatched lower case ASCII character in
820 SecondString subtracted from the first mismatched lower case ASCII character
821 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 using case insensitive
836 comparisons.
837 @retval !=0 FirstString is not identical to SecondString using case
838 insensitive comparisons.
839
840 **/
841 INTN
842 EFIAPI
843 AsciiStriCmp (
844 IN CONST CHAR8 *FirstString,
845 IN CONST CHAR8 *SecondString
846 );
847 /**
848 Compares two Null-terminated ASCII strings with maximum lengths, and returns
849 the difference between the first mismatched ASCII characters.
850
851 This function compares the Null-terminated ASCII string FirstString to the
852 Null-terminated ASCII string SecondString. At most, Length ASCII characters
853 will be compared. If Length is 0, then 0 is returned. If FirstString is
854 identical to SecondString, then 0 is returned. Otherwise, the value returned
855 is the first mismatched ASCII character in SecondString subtracted from the
856 first mismatched ASCII character in FirstString.
857
858 If Length > 0 and FirstString is NULL, then ASSERT().
859 If Length > 0 and 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 than
864 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
865 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.
871 @retval !=0 FirstString is not identical to SecondString.
872
873 **/
874 INTN
875 EFIAPI
876 AsciiStrnCmp (
877 IN CONST CHAR8 *FirstString,
878 IN CONST CHAR8 *SecondString,
879 IN UINTN Length
880 );
881 /**
882 Concatenates one Null-terminated ASCII string to another Null-terminated
883 ASCII string, and returns the concatenated ASCII string.
884
885 This function concatenates two Null-terminated ASCII strings. The contents of
886 Null-terminated ASCII string Source are concatenated to the end of Null-
887 terminated ASCII string Destination. The Null-terminated concatenated ASCII
888 String is returned.
889
890 If Destination is NULL, then ASSERT().
891 If Source is NULL, then ASSERT().
892 If PcdMaximumAsciiStringLength is not zero and Destination contains more than
893 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
894 then ASSERT().
895 If PcdMaximumAsciiStringLength is not zero and Source contains more than
896 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
897 then ASSERT().
898 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and
899 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
900 ASCII characters, then ASSERT().
901
902 @param Destination Pointer to a Null-terminated ASCII string.
903 @param Source Pointer to a Null-terminated ASCII string.
904
905 @return Destination
906
907 **/
908 CHAR8 *
909 EFIAPI
910 AsciiStrCat (
911 IN OUT CHAR8 *Destination,
912 IN CONST CHAR8 *Source
913 );
914 /**
915 Concatenates one Null-terminated ASCII string with a maximum length to the
916 end of another Null-terminated ASCII string, and returns the concatenated
917 ASCII string.
918
919 This function concatenates two Null-terminated ASCII strings. The contents
920 of Null-terminated ASCII string Source are concatenated to the end of Null-
921 terminated ASCII string Destination, and Destination is returned. At most,
922 Length ASCII characters are concatenated from Source to the end of
923 Destination, and Destination is always Null-terminated. If Length is 0, then
924 Destination is returned unmodified. If Source and Destination overlap, then
925 the results are undefined.
926
927 If Length > 0 and Destination is NULL, then ASSERT().
928 If Length > 0 and Source is NULL, then ASSERT().
929 If Source and Destination overlap, then ASSERT().
930 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than
931 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
932 then ASSERT().
933 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
934 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
935 then ASSERT().
936 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and
937 Source results in a ASCII string with more than PcdMaximumAsciiStringLength
938 ASCII characters not including the Null-terminator, then ASSERT().
939
940 @param Destination Pointer to a Null-terminated ASCII string.
941 @param Source Pointer to a Null-terminated ASCII string.
942 @param Length Maximum number of ASCII characters to concatenate from
943 Source.
944
945 @return Destination
946
947 **/
948 CHAR8 *
949 EFIAPI
950 AsciiStrnCat (
951 IN OUT CHAR8 *Destination,
952 IN CONST CHAR8 *Source,
953 IN UINTN Length
954 );
955
956 /**
957 Returns the first occurance of a Null-terminated ASCII sub-string
958 in a Null-terminated ASCII string.
959
960 This function scans the contents of the ASCII string specified by String
961 and returns the first occurrence of SearchString. If SearchString is not
962 found in String, then NULL is returned. If the length of SearchString is zero,
963 then String is returned.
964
965 If String is NULL, then ASSERT().
966 If SearchString is NULL, then ASSERT().
967
968 If PcdMaximumAsciiStringLength is not zero, and SearchString or
969 String contains more than PcdMaximumAsciiStringLength Unicode characters
970 not including the Null-terminator, then ASSERT().
971
972 @param String Pointer to a Null-terminated ASCII string.
973 @param SearchString Pointer to a Null-terminated ASCII string to search for.
974
975 @retval NULL If the SearchString does not appear in String.
976 @retval !NULL If there is a match.
977
978 **/
979 CHAR8 *
980 EFIAPI
981 AsciiStrStr (
982 IN CONST CHAR8 *String,
983 IN CONST CHAR8 *SearchString
984 );
985
986 /**
987 Convert a Null-terminated ASCII decimal string to a value of type
988 UINTN.
989
990 This function returns a value of type UINTN by interpreting the contents
991 of the ASCII string String as a decimal number. The format of the input
992 ASCII string String is:
993
994 [spaces] [decimal digits].
995
996 The valid decimal digit character is in the range [0-9]. The function will
997 ignore the pad space, which includes spaces or tab characters, before the digits.
998 The running zero in the beginning of [decimal digits] will be ignored. Then, the
999 function stops at the first character that is a not a valid decimal character or
1000 Null-terminator, whichever on comes first.
1001
1002 If String has only pad spaces, then 0 is returned.
1003 If String has no pad spaces or valid decimal digits, then 0 is returned.
1004 If the number represented by String overflows according to the range defined by
1005 UINTN, then ASSERT().
1006 If String is NULL, then ASSERT().
1007 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1008 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1009 then ASSERT().
1010
1011 @param String Pointer to a Null-terminated ASCII string.
1012
1013 @retval UINTN
1014
1015 **/
1016 UINTN
1017 EFIAPI
1018 AsciiStrDecimalToUintn (
1019 IN CONST CHAR8 *String
1020 );
1021
1022 /**
1023 Convert a Null-terminated ASCII decimal string to a value of type
1024 UINT64.
1025
1026 This function returns a value of type UINT64 by interpreting the contents
1027 of the ASCII string String as a decimal number. The format of the input
1028 ASCII string String is:
1029
1030 [spaces] [decimal digits].
1031
1032 The valid decimal digit character is in the range [0-9]. The function will
1033 ignore the pad space, which includes spaces or tab characters, before the digits.
1034 The running zero in the beginning of [decimal digits] will be ignored. Then, the
1035 function stops at the first character that is a not a valid decimal character or
1036 Null-terminator, whichever on comes first.
1037
1038 If String has only pad spaces, then 0 is returned.
1039 If String has no pad spaces or valid decimal digits, then 0 is returned.
1040 If the number represented by String overflows according to the range defined by
1041 UINT64, then ASSERT().
1042 If String is NULL, then ASSERT().
1043 If PcdMaximumAsciiStringLength is not zero, and String contains more than
1044 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1045 then ASSERT().
1046
1047 @param String Pointer to a Null-terminated ASCII string.
1048
1049 @retval UINT64
1050
1051 **/
1052 UINT64
1053 EFIAPI
1054 AsciiStrDecimalToUint64 (
1055 IN CONST CHAR8 *String
1056 );
1057
1058 /**
1059 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.
1060
1061 This function returns a value of type UINTN by interpreting the contents of
1062 the ASCII string String as a hexadecimal number. The format of the input ASCII
1063 string String is:
1064
1065 [spaces][zeros][x][hexadecimal digits].
1066
1067 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1068 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1069 appears in the input string, it must be prefixed with at least one 0. The function
1070 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1071 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1072 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1073 digit. Then, the function stops at the first character that is a not a valid
1074 hexadecimal character or Null-terminator, whichever on comes first.
1075
1076 If String has only pad spaces, then 0 is returned.
1077 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1078 0 is returned.
1079
1080 If the number represented by String overflows according to the range defined by UINTN,
1081 then ASSERT().
1082 If String is NULL, then ASSERT().
1083 If PcdMaximumAsciiStringLength is not zero,
1084 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1085 the Null-terminator, then ASSERT().
1086
1087 @param String Pointer to a Null-terminated ASCII string.
1088
1089 @retval UINTN
1090
1091 **/
1092 UINTN
1093 EFIAPI
1094 AsciiStrHexToUintn (
1095 IN CONST CHAR8 *String
1096 );
1097
1098 /**
1099 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.
1100
1101 This function returns a value of type UINT64 by interpreting the contents of
1102 the ASCII string String as a hexadecimal number. The format of the input ASCII
1103 string String is:
1104
1105 [spaces][zeros][x][hexadecimal digits].
1106
1107 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
1108 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"
1109 appears in the input string, it must be prefixed with at least one 0. The function
1110 will ignore the pad space, which includes spaces or tab characters, before [zeros],
1111 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]
1112 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal
1113 digit. Then, the function stops at the first character that is a not a valid
1114 hexadecimal character or Null-terminator, whichever on comes first.
1115
1116 If String has only pad spaces, then 0 is returned.
1117 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then
1118 0 is returned.
1119
1120 If the number represented by String overflows according to the range defined by UINT64,
1121 then ASSERT().
1122 If String is NULL, then ASSERT().
1123 If PcdMaximumAsciiStringLength is not zero,
1124 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including
1125 the Null-terminator, then ASSERT().
1126
1127 @param String Pointer to a Null-terminated ASCII string.
1128
1129 @retval UINT64
1130
1131 **/
1132 UINT64
1133 EFIAPI
1134 AsciiStrHexToUint64 (
1135 IN CONST CHAR8 *String
1136 );
1137
1138 /**
1139 Convert one Null-terminated ASCII string to a Null-terminated
1140 Unicode string and returns the Unicode string.
1141
1142 This function converts the contents of the ASCII string Source to the Unicode
1143 string Destination, and returns Destination. The function terminates the
1144 Unicode string Destination by appending a Null-terminator character at the end.
1145 The caller is responsible to make sure Destination points to a buffer with size
1146 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.
1147
1148 If Destination is NULL, then ASSERT().
1149 If Destination is not aligned on a 16-bit boundary, then ASSERT().
1150 If Source is NULL, then ASSERT().
1151 If Source and Destination overlap, then ASSERT().
1152 If PcdMaximumAsciiStringLength is not zero, and Source contains more than
1153 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,
1154 then ASSERT().
1155 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than
1156 PcdMaximumUnicodeStringLength ASCII characters not including the
1157 Null-terminator, then ASSERT().
1158
1159 @param Source Pointer to a Null-terminated ASCII string.
1160 @param Destination Pointer to a Null-terminated Unicode string.
1161
1162 @reture Destination
1163
1164 **/
1165 CHAR16 *
1166 EFIAPI
1167 AsciiStrToUnicodeStr (
1168 IN CONST CHAR8 *Source,
1169 OUT CHAR16 *Destination
1170 );
1171
1172 /**
1173 Converts an 8-bit value to an 8-bit BCD value.
1174
1175 Converts the 8-bit value specified by Value to BCD. The BCD value is
1176 returned.
1177
1178 If Value >= 100, then ASSERT().
1179
1180 @param Value The 8-bit value to convert to BCD. Range 0..99.
1181
1182 @return The BCD value
1183
1184 **/
1185 UINT8
1186 EFIAPI
1187 DecimalToBcd8 (
1188 IN UINT8 Value
1189 );
1190
1191 /**
1192 Converts an 8-bit BCD value to an 8-bit value.
1193
1194 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit
1195 value is returned.
1196
1197 If Value >= 0xA0, then ASSERT().
1198 If (Value & 0x0F) >= 0x0A, then ASSERT().
1199
1200 @param Value The 8-bit BCD value to convert to an 8-bit value.
1201
1202 @return The 8-bit value is returned.
1203
1204 **/
1205 UINT8
1206 EFIAPI
1207 BcdToDecimal8 (
1208 IN UINT8 Value
1209 );
1210
1211 //
1212 // LIST_ENTRY definition
1213 //
1214 typedef struct _LIST_ENTRY LIST_ENTRY;
1215
1216 struct _LIST_ENTRY {
1217 LIST_ENTRY *ForwardLink;
1218 LIST_ENTRY *BackLink;
1219 };
1220
1221 //
1222 // Linked List Functions and Macros
1223 //
1224
1225 /**
1226 Initializes the head node of a doubly linked list that is declared as a
1227 global variable in a module.
1228
1229 Initializes the forward and backward links of a new linked list. After
1230 initializing a linked list with this macro, the other linked list functions
1231 may be used to add and remove nodes from the linked list. This macro results
1232 in smaller executables by initializing the linked list in the data section,
1233 instead if calling the InitializeListHead() function to perform the
1234 equivalent operation.
1235
1236 @param ListHead The head note of a list to initiailize.
1237
1238 **/
1239 #define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&ListHead, &ListHead}
1240
1241 /**
1242 Initializes the head node of a doubly linked list, and returns the pointer to
1243 the head node of the doubly linked list.
1244
1245 Initializes the forward and backward links of a new linked list. After
1246 initializing a linked list with this function, the other linked list
1247 functions may be used to add and remove nodes from the linked list. It is up
1248 to the caller of this function to allocate the memory for ListHead.
1249
1250 If ListHead is NULL, then ASSERT().
1251
1252 @param ListHead A pointer to the head node of a new doubly linked list.
1253
1254 @return ListHead
1255
1256 **/
1257 LIST_ENTRY *
1258 EFIAPI
1259 GlueInitializeListHead (
1260 IN LIST_ENTRY *ListHead
1261 );
1262
1263 /**
1264 Adds a node to the beginning of a doubly linked list, and returns the pointer
1265 to the head node of the doubly linked list.
1266
1267 Adds the node Entry at the beginning of the doubly linked list denoted by
1268 ListHead, and returns ListHead.
1269
1270 If ListHead is NULL, then ASSERT().
1271 If Entry is NULL, then ASSERT().
1272 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1273 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1274 of nodes in ListHead, including the ListHead node, is greater than or
1275 equal to PcdMaximumLinkedListLength, then ASSERT().
1276
1277 @param ListHead A pointer to the head node of a doubly linked list.
1278 @param Entry A pointer to a node that is to be inserted at the beginning
1279 of a doubly linked list.
1280
1281 @return ListHead
1282
1283 **/
1284 LIST_ENTRY *
1285 EFIAPI
1286 GlueInsertHeadList (
1287 IN LIST_ENTRY *ListHead,
1288 IN LIST_ENTRY *Entry
1289 );
1290
1291 /**
1292 Adds a node to the end of a doubly linked list, and returns the pointer to
1293 the head node of the doubly linked list.
1294
1295 Adds the node Entry to the end of the doubly linked list denoted by ListHead,
1296 and returns ListHead.
1297
1298 If ListHead is NULL, then ASSERT().
1299 If Entry is NULL, then ASSERT().
1300 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1301 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number
1302 of nodes in ListHead, including the ListHead node, is greater than or
1303 equal to PcdMaximumLinkedListLength, then ASSERT().
1304
1305 @param ListHead A pointer to the head node of a doubly linked list.
1306 @param Entry A pointer to a node that is to be added at the end of the
1307 doubly linked list.
1308
1309 @return ListHead
1310
1311 **/
1312 LIST_ENTRY *
1313 EFIAPI
1314 GlueInsertTailList (
1315 IN LIST_ENTRY *ListHead,
1316 IN LIST_ENTRY *Entry
1317 );
1318
1319 /**
1320 Retrieves the first node of a doubly linked list.
1321
1322 Returns the first node of a doubly linked list. List must have been
1323 initialized with InitializeListHead(). If List is empty, then NULL is
1324 returned.
1325
1326 If List is NULL, then ASSERT().
1327 If List was not initialized with InitializeListHead(), then ASSERT().
1328 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1329 in List, including the List node, is greater than or equal to
1330 PcdMaximumLinkedListLength, then ASSERT().
1331
1332 @param List A pointer to the head node of a doubly linked list.
1333
1334 @return The first node of a doubly linked list.
1335 @retval NULL The list is empty.
1336
1337 **/
1338 LIST_ENTRY *
1339 EFIAPI
1340 GlueGetFirstNode (
1341 IN CONST LIST_ENTRY *List
1342 );
1343
1344 /**
1345 Retrieves the next node of a doubly linked list.
1346
1347 Returns the node of a doubly linked list that follows Node. List must have
1348 been initialized with InitializeListHead(). If List is empty, then List is
1349 returned.
1350
1351 If List is NULL, then ASSERT().
1352 If Node is NULL, then ASSERT().
1353 If List was not initialized with InitializeListHead(), then ASSERT().
1354 If PcdMaximumLinkedListLenth is not zero, and List contains more than
1355 PcdMaximumLinkedListLenth nodes, then ASSERT().
1356 If Node is not a node in List, then ASSERT().
1357
1358 @param List A pointer to the head node of a doubly linked list.
1359 @param Node A pointer to a node in the doubly linked list.
1360
1361 @return Pointer to the next node if one exists. Otherwise a null value which
1362 is actually List is returned.
1363
1364 **/
1365 LIST_ENTRY *
1366 EFIAPI
1367 GlueGetNextNode (
1368 IN CONST LIST_ENTRY *List,
1369 IN CONST LIST_ENTRY *Node
1370 );
1371
1372 /**
1373 Checks to see if a doubly linked list is empty or not.
1374
1375 Checks to see if the doubly linked list is empty. If the linked list contains
1376 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.
1377
1378 If ListHead is NULL, then ASSERT().
1379 If ListHead was not initialized with InitializeListHead(), then ASSERT().
1380 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1381 in List, including the List node, is greater than or equal to
1382 PcdMaximumLinkedListLength, then ASSERT().
1383
1384 @param ListHead A pointer to the head node of a doubly linked list.
1385
1386 @retval TRUE The linked list is empty.
1387 @retval FALSE The linked list is not empty.
1388
1389 **/
1390 BOOLEAN
1391 EFIAPI
1392 GlueIsListEmpty (
1393 IN CONST LIST_ENTRY *ListHead
1394 );
1395
1396 /**
1397 Determines if a node in a doubly linked list is null.
1398
1399 Returns FALSE if Node is one of the nodes in the doubly linked list specified
1400 by List. Otherwise, TRUE is returned. List must have been initialized with
1401 InitializeListHead().
1402
1403 If List is NULL, then ASSERT().
1404 If Node is NULL, then ASSERT().
1405 If List was not initialized with InitializeListHead(), then ASSERT().
1406 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1407 in List, including the List node, is greater than or equal to
1408 PcdMaximumLinkedListLength, then ASSERT().
1409 If Node is not a node in List and Node is not equal to List, then ASSERT().
1410
1411 @param List A pointer to the head node of a doubly linked list.
1412 @param Node A pointer to a node in the doubly linked list.
1413
1414 @retval TRUE Node is one of the nodes in the doubly linked list.
1415 @retval FALSE Node is not one of the nodes in the doubly linked list.
1416
1417 **/
1418 BOOLEAN
1419 EFIAPI
1420 GlueIsNull (
1421 IN CONST LIST_ENTRY *List,
1422 IN CONST LIST_ENTRY *Node
1423 );
1424
1425 /**
1426 Determines if a node the last node in a doubly linked list.
1427
1428 Returns TRUE if Node is the last node in the doubly linked list specified by
1429 List. Otherwise, FALSE is returned. List must have been initialized with
1430 InitializeListHead().
1431
1432 If List is NULL, then ASSERT().
1433 If Node is NULL, then ASSERT().
1434 If List was not initialized with InitializeListHead(), then ASSERT().
1435 If PcdMaximumLinkedListLenth is not zero, and the number of nodes
1436 in List, including the List node, is greater than or equal to
1437 PcdMaximumLinkedListLength, then ASSERT().
1438 If Node is not a node in List, then ASSERT().
1439
1440 @param List A pointer to the head node of a doubly linked list.
1441 @param Node A pointer to a node in the doubly linked list.
1442
1443 @retval TRUE Node is the last node in the linked list.
1444 @retval FALSE Node is not the last node in the linked list.
1445
1446 **/
1447 BOOLEAN
1448 EFIAPI
1449 GlueIsNodeAtEnd (
1450 IN CONST LIST_ENTRY *List,
1451 IN CONST LIST_ENTRY *Node
1452 );
1453
1454 /**
1455 Swaps the location of two nodes in a doubly linked list, and returns the
1456 first node after the swap.
1457
1458 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.
1459 Otherwise, the location of the FirstEntry node is swapped with the location
1460 of the SecondEntry node in a doubly linked list. SecondEntry must be in the
1461 same double linked list as FirstEntry and that double linked list must have
1462 been initialized with InitializeListHead(). SecondEntry is returned after the
1463 nodes are swapped.
1464
1465 If FirstEntry is NULL, then ASSERT().
1466 If SecondEntry is NULL, then ASSERT().
1467 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().
1468 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1469 linked list containing the FirstEntry and SecondEntry nodes, including
1470 the FirstEntry and SecondEntry nodes, is greater than or equal to
1471 PcdMaximumLinkedListLength, then ASSERT().
1472
1473 @param FirstEntry A pointer to a node in a linked list.
1474 @param SecondEntry A pointer to another node in the same linked list.
1475
1476 **/
1477 LIST_ENTRY *
1478 EFIAPI
1479 GlueSwapListEntries (
1480 IN LIST_ENTRY *FirstEntry,
1481 IN LIST_ENTRY *SecondEntry
1482 );
1483
1484 /**
1485 Removes a node from a doubly linked list, and returns the node that follows
1486 the removed node.
1487
1488 Removes the node Entry from a doubly linked list. It is up to the caller of
1489 this function to release the memory used by this node if that is required. On
1490 exit, the node following Entry in the doubly linked list is returned. If
1491 Entry is the only node in the linked list, then the head node of the linked
1492 list is returned.
1493
1494 If Entry is NULL, then ASSERT().
1495 If Entry is the head node of an empty list, then ASSERT().
1496 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the
1497 linked list containing Entry, including the Entry node, is greater than
1498 or equal to PcdMaximumLinkedListLength, then ASSERT().
1499
1500 @param Entry A pointer to a node in a linked list
1501
1502 @return Entry
1503
1504 **/
1505 LIST_ENTRY *
1506 EFIAPI
1507 GlueRemoveEntryList (
1508 IN CONST LIST_ENTRY *Entry
1509 );
1510
1511 //
1512 // Math Services
1513 //
1514
1515 /**
1516 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled
1517 with zeros. The shifted value is returned.
1518
1519 This function shifts the 64-bit value Operand to the left by Count bits. The
1520 low Count bits are set to zero. The shifted value is returned.
1521
1522 If Count is greater than 63, then ASSERT().
1523
1524 @param Operand The 64-bit operand to shift left.
1525 @param Count The number of bits to shift left.
1526
1527 @return Operand << Count
1528
1529 **/
1530 UINT64
1531 EFIAPI
1532 GlueLShiftU64 (
1533 IN UINT64 Operand,
1534 IN UINTN Count
1535 );
1536
1537 /**
1538 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are
1539 filled with zeros. The shifted value is returned.
1540
1541 This function shifts the 64-bit value Operand to the right by Count bits. The
1542 high Count bits are set to zero. The shifted value is returned.
1543
1544 If Count is greater than 63, then ASSERT().
1545
1546 @param Operand The 64-bit operand to shift right.
1547 @param Count The number of bits to shift right.
1548
1549 @return Operand >> Count
1550
1551 **/
1552 UINT64
1553 EFIAPI
1554 GlueRShiftU64 (
1555 IN UINT64 Operand,
1556 IN UINTN Count
1557 );
1558
1559 /**
1560 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled
1561 with original integer's bit 63. The shifted value is returned.
1562
1563 This function shifts the 64-bit value Operand to the right by Count bits. The
1564 high Count bits are set to bit 63 of Operand. The shifted value is returned.
1565
1566 If Count is greater than 63, then ASSERT().
1567
1568 @param Operand The 64-bit operand to shift right.
1569 @param Count The number of bits to shift right.
1570
1571 @return Operand >> Count
1572
1573 **/
1574 UINT64
1575 EFIAPI
1576 ARShiftU64 (
1577 IN UINT64 Operand,
1578 IN UINTN Count
1579 );
1580
1581 /**
1582 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits
1583 with the high bits that were rotated.
1584
1585 This function rotates the 32-bit value Operand to the left by Count bits. The
1586 low Count bits are fill with the high Count bits of Operand. The rotated
1587 value is returned.
1588
1589 If Count is greater than 31, then ASSERT().
1590
1591 @param Operand The 32-bit operand to rotate left.
1592 @param Count The number of bits to rotate left.
1593
1594 @return Operand <<< Count
1595
1596 **/
1597 UINT32
1598 EFIAPI
1599 LRotU32 (
1600 IN UINT32 Operand,
1601 IN UINTN Count
1602 );
1603
1604 /**
1605 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits
1606 with the low bits that were rotated.
1607
1608 This function rotates the 32-bit value Operand to the right by Count bits.
1609 The high Count bits are fill with the low Count bits of Operand. The rotated
1610 value is returned.
1611
1612 If Count is greater than 31, then ASSERT().
1613
1614 @param Operand The 32-bit operand to rotate right.
1615 @param Count The number of bits to rotate right.
1616
1617 @return Operand >>> Count
1618
1619 **/
1620 UINT32
1621 EFIAPI
1622 RRotU32 (
1623 IN UINT32 Operand,
1624 IN UINTN Count
1625 );
1626
1627 /**
1628 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits
1629 with the high bits that were rotated.
1630
1631 This function rotates the 64-bit value Operand to the left by Count bits. The
1632 low Count bits are fill with the high Count bits of Operand. The rotated
1633 value is returned.
1634
1635 If Count is greater than 63, then ASSERT().
1636
1637 @param Operand The 64-bit operand to rotate left.
1638 @param Count The number of bits to rotate left.
1639
1640 @return Operand <<< Count
1641
1642 **/
1643 UINT64
1644 EFIAPI
1645 LRotU64 (
1646 IN UINT64 Operand,
1647 IN UINTN Count
1648 );
1649
1650 /**
1651 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits
1652 with the high low bits that were rotated.
1653
1654 This function rotates the 64-bit value Operand to the right by Count bits.
1655 The high Count bits are fill with the low Count bits of Operand. The rotated
1656 value is returned.
1657
1658 If Count is greater than 63, then ASSERT().
1659
1660 @param Operand The 64-bit operand to rotate right.
1661 @param Count The number of bits to rotate right.
1662
1663 @return Operand >>> Count
1664
1665 **/
1666 UINT64
1667 EFIAPI
1668 RRotU64 (
1669 IN UINT64 Operand,
1670 IN UINTN Count
1671 );
1672
1673 /**
1674 Returns the bit position of the lowest bit set in a 32-bit value.
1675
1676 This function computes the bit position of the lowest bit set in the 32-bit
1677 value specified by Operand. If Operand is zero, then -1 is returned.
1678 Otherwise, a value between 0 and 31 is returned.
1679
1680 @param Operand The 32-bit operand to evaluate.
1681
1682 @return Position of the lowest bit set in Operand if found.
1683 @retval -1 Operand is zero.
1684
1685 **/
1686 INTN
1687 EFIAPI
1688 LowBitSet32 (
1689 IN UINT32 Operand
1690 );
1691
1692 /**
1693 Returns the bit position of the lowest bit set in a 64-bit value.
1694
1695 This function computes the bit position of the lowest bit set in the 64-bit
1696 value specified by Operand. If Operand is zero, then -1 is returned.
1697 Otherwise, a value between 0 and 63 is returned.
1698
1699 @param Operand The 64-bit operand to evaluate.
1700
1701 @return Position of the lowest bit set in Operand if found.
1702 @retval -1 Operand is zero.
1703
1704 **/
1705 INTN
1706 EFIAPI
1707 LowBitSet64 (
1708 IN UINT64 Operand
1709 );
1710
1711 /**
1712 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
1713 to log2(x).
1714
1715 This function computes the bit position of the highest bit set in the 32-bit
1716 value specified by Operand. If Operand is zero, then -1 is returned.
1717 Otherwise, a value between 0 and 31 is returned.
1718
1719 @param Operand The 32-bit operand to evaluate.
1720
1721 @return Position of the highest bit set in Operand if found.
1722 @retval -1 Operand is zero.
1723
1724 **/
1725 INTN
1726 EFIAPI
1727 HighBitSet32 (
1728 IN UINT32 Operand
1729 );
1730
1731 /**
1732 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
1733 to log2(x).
1734
1735 This function computes the bit position of the highest bit set in the 64-bit
1736 value specified by Operand. If Operand is zero, then -1 is returned.
1737 Otherwise, a value between 0 and 63 is returned.
1738
1739 @param Operand The 64-bit operand to evaluate.
1740
1741 @return Position of the highest bit set in Operand if found.
1742 @retval -1 Operand is zero.
1743
1744 **/
1745 INTN
1746 EFIAPI
1747 HighBitSet64 (
1748 IN UINT64 Operand
1749 );
1750
1751 /**
1752 Returns the value of the highest bit set in a 32-bit value. Equivalent to
1753 1 << HighBitSet32(x).
1754
1755 This function computes the value of the highest bit set in the 32-bit value
1756 specified by Operand. If Operand is zero, then zero is returned.
1757
1758 @param Operand The 32-bit operand to evaluate.
1759
1760 @return 1 << HighBitSet32(Operand)
1761 @retval 0 Operand is zero.
1762
1763 **/
1764 UINT32
1765 EFIAPI
1766 GetPowerOfTwo32 (
1767 IN UINT32 Operand
1768 );
1769
1770 /**
1771 Returns the value of the highest bit set in a 64-bit value. Equivalent to
1772 1 << HighBitSet64(x).
1773
1774 This function computes the value of the highest bit set in the 64-bit value
1775 specified by Operand. If Operand is zero, then zero is returned.
1776
1777 @param Operand The 64-bit operand to evaluate.
1778
1779 @return 1 << HighBitSet64(Operand)
1780 @retval 0 Operand is zero.
1781
1782 **/
1783 UINT64
1784 EFIAPI
1785 GetPowerOfTwo64 (
1786 IN UINT64 Operand
1787 );
1788
1789 /**
1790 Switches the endianess of a 16-bit integer.
1791
1792 This function swaps the bytes in a 16-bit unsigned value to switch the value
1793 from little endian to big endian or vice versa. The byte swapped value is
1794 returned.
1795
1796 @param Operand A 16-bit unsigned value.
1797
1798 @return The byte swaped Operand.
1799
1800 **/
1801 UINT16
1802 EFIAPI
1803 SwapBytes16 (
1804 IN UINT16 Value
1805 );
1806
1807 /**
1808 Switches the endianess of a 32-bit integer.
1809
1810 This function swaps the bytes in a 32-bit unsigned value to switch the value
1811 from little endian to big endian or vice versa. The byte swapped value is
1812 returned.
1813
1814 @param Operand A 32-bit unsigned value.
1815
1816 @return The byte swaped Operand.
1817
1818 **/
1819 UINT32
1820 EFIAPI
1821 SwapBytes32 (
1822 IN UINT32 Value
1823 );
1824
1825 /**
1826 Switches the endianess of a 64-bit integer.
1827
1828 This function swaps the bytes in a 64-bit unsigned value to switch the value
1829 from little endian to big endian or vice versa. The byte swapped value is
1830 returned.
1831
1832 @param Operand A 64-bit unsigned value.
1833
1834 @return The byte swaped Operand.
1835
1836 **/
1837 UINT64
1838 EFIAPI
1839 SwapBytes64 (
1840 IN UINT64 Value
1841 );
1842
1843 /**
1844 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and
1845 generates a 64-bit unsigned result.
1846
1847 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit
1848 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1849 bit unsigned result is returned.
1850
1851 If the result overflows, then ASSERT().
1852
1853 @param Multiplicand A 64-bit unsigned value.
1854 @param Multiplier A 32-bit unsigned value.
1855
1856 @return Multiplicand * Multiplier
1857
1858 **/
1859 UINT64
1860 EFIAPI
1861 GlueMultU64x32 (
1862 IN UINT64 Multiplicand,
1863 IN UINT32 Multiplier
1864 );
1865
1866 /**
1867 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and
1868 generates a 64-bit unsigned result.
1869
1870 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
1871 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
1872 bit unsigned result is returned.
1873
1874 If the result overflows, then ASSERT().
1875
1876 @param Multiplicand A 64-bit unsigned value.
1877 @param Multiplier A 64-bit unsigned value.
1878
1879 @return Multiplicand * Multiplier
1880
1881 **/
1882 UINT64
1883 EFIAPI
1884 MultU64x64 (
1885 IN UINT64 Multiplicand,
1886 IN UINT64 Multiplier
1887 );
1888
1889 /**
1890 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a
1891 64-bit signed result.
1892
1893 This function multiples the 64-bit signed value Multiplicand by the 64-bit
1894 signed value Multiplier and generates a 64-bit signed result. This 64-bit
1895 signed result is returned.
1896
1897 If the result overflows, then ASSERT().
1898
1899 @param Multiplicand A 64-bit signed value.
1900 @param Multiplier A 64-bit signed value.
1901
1902 @return Multiplicand * Multiplier
1903
1904 **/
1905 INT64
1906 EFIAPI
1907 MultS64x64 (
1908 IN INT64 Multiplicand,
1909 IN INT64 Multiplier
1910 );
1911
1912 /**
1913 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1914 a 64-bit unsigned result.
1915
1916 This function divides the 64-bit unsigned value Dividend by the 32-bit
1917 unsigned value Divisor and generates a 64-bit unsigned quotient. This
1918 function returns the 64-bit unsigned quotient.
1919
1920 If Divisor is 0, then ASSERT().
1921
1922 @param Dividend A 64-bit unsigned value.
1923 @param Divisor A 32-bit unsigned value.
1924
1925 @return Dividend / Divisor
1926
1927 **/
1928 UINT64
1929 EFIAPI
1930 GlueDivU64x32 (
1931 IN UINT64 Dividend,
1932 IN UINT32 Divisor
1933 );
1934
1935 /**
1936 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1937 a 32-bit unsigned remainder.
1938
1939 This function divides the 64-bit unsigned value Dividend by the 32-bit
1940 unsigned value Divisor and generates a 32-bit remainder. This function
1941 returns the 32-bit unsigned remainder.
1942
1943 If Divisor is 0, then ASSERT().
1944
1945 @param Dividend A 64-bit unsigned value.
1946 @param Divisor A 32-bit unsigned value.
1947
1948 @return Dividend % Divisor
1949
1950 **/
1951 UINT32
1952 EFIAPI
1953 ModU64x32 (
1954 IN UINT64 Dividend,
1955 IN UINT32 Divisor
1956 );
1957
1958 /**
1959 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates
1960 a 64-bit unsigned result and an optional 32-bit unsigned remainder.
1961
1962 This function divides the 64-bit unsigned value Dividend by the 32-bit
1963 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1964 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
1965 This function returns the 64-bit unsigned quotient.
1966
1967 If Divisor is 0, then ASSERT().
1968
1969 @param Dividend A 64-bit unsigned value.
1970 @param Divisor A 32-bit unsigned value.
1971 @param Remainder A pointer to a 32-bit unsigned value. This parameter is
1972 optional and may be NULL.
1973
1974 @return Dividend / Divisor
1975
1976 **/
1977 UINT64
1978 EFIAPI
1979 DivU64x32Remainder (
1980 IN UINT64 Dividend,
1981 IN UINT32 Divisor,
1982 OUT UINT32 *Remainder OPTIONAL
1983 );
1984
1985 /**
1986 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates
1987 a 64-bit unsigned result and an optional 64-bit unsigned remainder.
1988
1989 This function divides the 64-bit unsigned value Dividend by the 64-bit
1990 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
1991 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
1992 This function returns the 64-bit unsigned quotient.
1993
1994 If Divisor is 0, then ASSERT().
1995
1996 @param Dividend A 64-bit unsigned value.
1997 @param Divisor A 64-bit unsigned value.
1998 @param Remainder A pointer to a 64-bit unsigned value. This parameter is
1999 optional and may be NULL.
2000
2001 @return Dividend / Divisor
2002
2003 **/
2004 UINT64
2005 EFIAPI
2006 DivU64x64Remainder (
2007 IN UINT64 Dividend,
2008 IN UINT64 Divisor,
2009 OUT UINT64 *Remainder OPTIONAL
2010 );
2011
2012 /**
2013 Divides a 64-bit signed integer by a 64-bit signed integer and generates a
2014 64-bit signed result and a optional 64-bit signed remainder.
2015
2016 This function divides the 64-bit signed value Dividend by the 64-bit signed
2017 value Divisor and generates a 64-bit signed quotient. If Remainder is not
2018 NULL, then the 64-bit signed remainder is returned in Remainder. This
2019 function returns the 64-bit signed quotient.
2020
2021 If Divisor is 0, then ASSERT().
2022
2023 @param Dividend A 64-bit signed value.
2024 @param Divisor A 64-bit signed value.
2025 @param Remainder A pointer to a 64-bit signed value. This parameter is
2026 optional and may be NULL.
2027
2028 @return Dividend / Divisor
2029
2030 **/
2031 INT64
2032 EFIAPI
2033 DivS64x64Remainder (
2034 IN INT64 Dividend,
2035 IN INT64 Divisor,
2036 OUT INT64 *Remainder OPTIONAL
2037 );
2038
2039 /**
2040 Reads a 16-bit value from memory that may be unaligned.
2041
2042 This function returns the 16-bit value pointed to by Buffer. The function
2043 guarantees that the read operation does not produce an alignment fault.
2044
2045 If the Buffer is NULL, then ASSERT().
2046
2047 @param Buffer Pointer to a 16-bit value that may be unaligned.
2048
2049 @return *Uint16
2050
2051 **/
2052 UINT16
2053 EFIAPI
2054 ReadUnaligned16 (
2055 IN CONST UINT16 *Uint16
2056 );
2057
2058 /**
2059 Writes a 16-bit value to memory that may be unaligned.
2060
2061 This function writes the 16-bit value specified by Value to Buffer. Value is
2062 returned. The function guarantees that the write operation does not produce
2063 an alignment fault.
2064
2065 If the Buffer is NULL, then ASSERT().
2066
2067 @param Buffer Pointer to a 16-bit value that may be unaligned.
2068 @param Value 16-bit value to write to Buffer.
2069
2070 @return Value
2071
2072 **/
2073 UINT16
2074 EFIAPI
2075 WriteUnaligned16 (
2076 OUT UINT16 *Uint16,
2077 IN UINT16 Value
2078 );
2079
2080 /**
2081 Reads a 24-bit value from memory that may be unaligned.
2082
2083 This function returns the 24-bit value pointed to by Buffer. The function
2084 guarantees that the read operation does not produce an alignment fault.
2085
2086 If the Buffer is NULL, then ASSERT().
2087
2088 @param Buffer Pointer to a 24-bit value that may be unaligned.
2089
2090 @return The value read.
2091
2092 **/
2093 UINT32
2094 EFIAPI
2095 ReadUnaligned24 (
2096 IN CONST UINT32 *Buffer
2097 );
2098
2099 /**
2100 Writes a 24-bit value to memory that may be unaligned.
2101
2102 This function writes the 24-bit value specified by Value to Buffer. Value is
2103 returned. The function guarantees that the write operation does not produce
2104 an alignment fault.
2105
2106 If the Buffer is NULL, then ASSERT().
2107
2108 @param Buffer Pointer to a 24-bit value that may be unaligned.
2109 @param Value 24-bit value to write to Buffer.
2110
2111 @return The value written.
2112
2113 **/
2114 UINT32
2115 EFIAPI
2116 WriteUnaligned24 (
2117 OUT UINT32 *Buffer,
2118 IN UINT32 Value
2119 );
2120
2121 /**
2122 Reads a 32-bit value from memory that may be unaligned.
2123
2124 This function returns the 32-bit value pointed to by Buffer. The function
2125 guarantees that the read operation does not produce an alignment fault.
2126
2127 If the Buffer is NULL, then ASSERT().
2128
2129 @param Buffer Pointer to a 32-bit value that may be unaligned.
2130
2131 @return *Uint32
2132
2133 **/
2134 UINT32
2135 EFIAPI
2136 ReadUnaligned32 (
2137 IN CONST UINT32 *Uint32
2138 );
2139
2140 /**
2141 Writes a 32-bit value to memory that may be unaligned.
2142
2143 This function writes the 32-bit value specified by Value to Buffer. Value is
2144 returned. The function guarantees that the write operation does not produce
2145 an alignment fault.
2146
2147 If the Buffer is NULL, then ASSERT().
2148
2149 @param Buffer Pointer to a 32-bit value that may be unaligned.
2150 @param Value 32-bit value to write to Buffer.
2151
2152 @return Value
2153
2154 **/
2155 UINT32
2156 EFIAPI
2157 WriteUnaligned32 (
2158 OUT UINT32 *Uint32,
2159 IN UINT32 Value
2160 );
2161
2162 /**
2163 Reads a 64-bit value from memory that may be unaligned.
2164
2165 This function returns the 64-bit value pointed to by Buffer. The function
2166 guarantees that the read operation does not produce an alignment fault.
2167
2168 If the Buffer is NULL, then ASSERT().
2169
2170 @param Buffer Pointer to a 64-bit value that may be unaligned.
2171
2172 @return *Uint64
2173
2174 **/
2175 UINT64
2176 EFIAPI
2177 ReadUnaligned64 (
2178 IN CONST UINT64 *Uint64
2179 );
2180
2181 /**
2182 Writes a 64-bit value to memory that may be unaligned.
2183
2184 This function writes the 64-bit value specified by Value to Buffer. Value is
2185 returned. The function guarantees that the write operation does not produce
2186 an alignment fault.
2187
2188 If the Buffer is NULL, then ASSERT().
2189
2190 @param Buffer Pointer to a 64-bit value that may be unaligned.
2191 @param Value 64-bit value to write to Buffer.
2192
2193 @return Value
2194
2195 **/
2196 UINT64
2197 EFIAPI
2198 WriteUnaligned64 (
2199 OUT UINT64 *Uint64,
2200 IN UINT64 Value
2201 );
2202
2203 //
2204 // Bit Field Functions
2205 //
2206
2207 /**
2208 Returns a bit field from an 8-bit value.
2209
2210 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2211
2212 If 8-bit operations are not supported, then ASSERT().
2213 If StartBit is greater than 7, then ASSERT().
2214 If EndBit is greater than 7, then ASSERT().
2215 If EndBit is less than StartBit, then ASSERT().
2216
2217 @param Operand Operand on which to perform the bitfield operation.
2218 @param StartBit The ordinal of the least significant bit in the bit field.
2219 Range 0..7.
2220 @param EndBit The ordinal of the most significant bit in the bit field.
2221 Range 0..7.
2222
2223 @return The bit field read.
2224
2225 **/
2226 UINT8
2227 EFIAPI
2228 BitFieldRead8 (
2229 IN UINT8 Operand,
2230 IN UINTN StartBit,
2231 IN UINTN EndBit
2232 );
2233
2234 /**
2235 Writes a bit field to an 8-bit value, and returns the result.
2236
2237 Writes Value to the bit field specified by the StartBit and the EndBit in
2238 Operand. All other bits in Operand are preserved. The new 8-bit value is
2239 returned.
2240
2241 If 8-bit operations are not supported, then ASSERT().
2242 If StartBit is greater than 7, then ASSERT().
2243 If EndBit is greater than 7, then ASSERT().
2244 If EndBit is less than StartBit, then ASSERT().
2245
2246 @param Operand Operand on which to perform the bitfield operation.
2247 @param StartBit The ordinal of the least significant bit in the bit field.
2248 Range 0..7.
2249 @param EndBit The ordinal of the most significant bit in the bit field.
2250 Range 0..7.
2251 @param Value New value of the bit field.
2252
2253 @return The new 8-bit value.
2254
2255 **/
2256 UINT8
2257 EFIAPI
2258 BitFieldWrite8 (
2259 IN UINT8 Operand,
2260 IN UINTN StartBit,
2261 IN UINTN EndBit,
2262 IN UINT8 Value
2263 );
2264
2265 /**
2266 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the
2267 result.
2268
2269 Performs a bitwise inclusive OR between the bit field specified by StartBit
2270 and EndBit in Operand and the value specified by OrData. All other bits in
2271 Operand are preserved. The new 8-bit value is returned.
2272
2273 If 8-bit operations are not supported, then ASSERT().
2274 If StartBit is greater than 7, then ASSERT().
2275 If EndBit is greater than 7, then ASSERT().
2276 If EndBit is less than StartBit, then ASSERT().
2277
2278 @param Operand Operand on which to perform the bitfield operation.
2279 @param StartBit The ordinal of the least significant bit in the bit field.
2280 Range 0..7.
2281 @param EndBit The ordinal of the most significant bit in the bit field.
2282 Range 0..7.
2283 @param OrData The value to OR with the read value from the value
2284
2285 @return The new 8-bit value.
2286
2287 **/
2288 UINT8
2289 EFIAPI
2290 BitFieldOr8 (
2291 IN UINT8 Operand,
2292 IN UINTN StartBit,
2293 IN UINTN EndBit,
2294 IN UINT8 OrData
2295 );
2296
2297 /**
2298 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns
2299 the result.
2300
2301 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2302 in Operand and the value specified by AndData. All other bits in Operand are
2303 preserved. The new 8-bit value is returned.
2304
2305 If 8-bit operations are not supported, then ASSERT().
2306 If StartBit is greater than 7, then ASSERT().
2307 If EndBit is greater than 7, then ASSERT().
2308 If EndBit is less than StartBit, then ASSERT().
2309
2310 @param Operand Operand on which to perform the bitfield operation.
2311 @param StartBit The ordinal of the least significant bit in the bit field.
2312 Range 0..7.
2313 @param EndBit The ordinal of the most significant bit in the bit field.
2314 Range 0..7.
2315 @param AndData The value to AND with the read value from the value.
2316
2317 @return The new 8-bit value.
2318
2319 **/
2320 UINT8
2321 EFIAPI
2322 BitFieldAnd8 (
2323 IN UINT8 Operand,
2324 IN UINTN StartBit,
2325 IN UINTN EndBit,
2326 IN UINT8 AndData
2327 );
2328
2329 /**
2330 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a
2331 bitwise OR, and returns the result.
2332
2333 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2334 in Operand and the value specified by AndData, followed by a bitwise
2335 inclusive OR with value specified by OrData. All other bits in Operand are
2336 preserved. The new 8-bit value is returned.
2337
2338 If 8-bit operations are not supported, then ASSERT().
2339 If StartBit is greater than 7, then ASSERT().
2340 If EndBit is greater than 7, then ASSERT().
2341 If EndBit is less than StartBit, then ASSERT().
2342
2343 @param Operand Operand on which to perform the bitfield operation.
2344 @param StartBit The ordinal of the least significant bit in the bit field.
2345 Range 0..7.
2346 @param EndBit The ordinal of the most significant bit in the bit field.
2347 Range 0..7.
2348 @param AndData The value to AND with the read value from the value.
2349 @param OrData The value to OR with the result of the AND operation.
2350
2351 @return The new 8-bit value.
2352
2353 **/
2354 UINT8
2355 EFIAPI
2356 BitFieldAndThenOr8 (
2357 IN UINT8 Operand,
2358 IN UINTN StartBit,
2359 IN UINTN EndBit,
2360 IN UINT8 AndData,
2361 IN UINT8 OrData
2362 );
2363
2364 /**
2365 Returns a bit field from a 16-bit value.
2366
2367 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2368
2369 If 16-bit operations are not supported, then ASSERT().
2370 If StartBit is greater than 15, then ASSERT().
2371 If EndBit is greater than 15, then ASSERT().
2372 If EndBit is less than StartBit, then ASSERT().
2373
2374 @param Operand Operand on which to perform the bitfield operation.
2375 @param StartBit The ordinal of the least significant bit in the bit field.
2376 Range 0..15.
2377 @param EndBit The ordinal of the most significant bit in the bit field.
2378 Range 0..15.
2379
2380 @return The bit field read.
2381
2382 **/
2383 UINT16
2384 EFIAPI
2385 BitFieldRead16 (
2386 IN UINT16 Operand,
2387 IN UINTN StartBit,
2388 IN UINTN EndBit
2389 );
2390
2391 /**
2392 Writes a bit field to a 16-bit value, and returns the result.
2393
2394 Writes Value to the bit field specified by the StartBit and the EndBit in
2395 Operand. All other bits in Operand are preserved. The new 16-bit value is
2396 returned.
2397
2398 If 16-bit operations are not supported, then ASSERT().
2399 If StartBit is greater than 15, then ASSERT().
2400 If EndBit is greater than 15, then ASSERT().
2401 If EndBit is less than StartBit, then ASSERT().
2402
2403 @param Operand Operand on which to perform the bitfield operation.
2404 @param StartBit The ordinal of the least significant bit in the bit field.
2405 Range 0..15.
2406 @param EndBit The ordinal of the most significant bit in the bit field.
2407 Range 0..15.
2408 @param Value New value of the bit field.
2409
2410 @return The new 16-bit value.
2411
2412 **/
2413 UINT16
2414 EFIAPI
2415 BitFieldWrite16 (
2416 IN UINT16 Operand,
2417 IN UINTN StartBit,
2418 IN UINTN EndBit,
2419 IN UINT16 Value
2420 );
2421
2422 /**
2423 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the
2424 result.
2425
2426 Performs a bitwise inclusive OR between the bit field specified by StartBit
2427 and EndBit in Operand and the value specified by OrData. All other bits in
2428 Operand are preserved. The new 16-bit value is returned.
2429
2430 If 16-bit operations are not supported, then ASSERT().
2431 If StartBit is greater than 15, then ASSERT().
2432 If EndBit is greater than 15, then ASSERT().
2433 If EndBit is less than StartBit, then ASSERT().
2434
2435 @param Operand Operand on which to perform the bitfield operation.
2436 @param StartBit The ordinal of the least significant bit in the bit field.
2437 Range 0..15.
2438 @param EndBit The ordinal of the most significant bit in the bit field.
2439 Range 0..15.
2440 @param OrData The value to OR with the read value from the value
2441
2442 @return The new 16-bit value.
2443
2444 **/
2445 UINT16
2446 EFIAPI
2447 BitFieldOr16 (
2448 IN UINT16 Operand,
2449 IN UINTN StartBit,
2450 IN UINTN EndBit,
2451 IN UINT16 OrData
2452 );
2453
2454 /**
2455 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns
2456 the result.
2457
2458 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2459 in Operand and the value specified by AndData. All other bits in Operand are
2460 preserved. The new 16-bit value is returned.
2461
2462 If 16-bit operations are not supported, then ASSERT().
2463 If StartBit is greater than 15, then ASSERT().
2464 If EndBit is greater than 15, then ASSERT().
2465 If EndBit is less than StartBit, then ASSERT().
2466
2467 @param Operand Operand on which to perform the bitfield operation.
2468 @param StartBit The ordinal of the least significant bit in the bit field.
2469 Range 0..15.
2470 @param EndBit The ordinal of the most significant bit in the bit field.
2471 Range 0..15.
2472 @param AndData The value to AND with the read value from the value
2473
2474 @return The new 16-bit value.
2475
2476 **/
2477 UINT16
2478 EFIAPI
2479 BitFieldAnd16 (
2480 IN UINT16 Operand,
2481 IN UINTN StartBit,
2482 IN UINTN EndBit,
2483 IN UINT16 AndData
2484 );
2485
2486 /**
2487 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a
2488 bitwise OR, and returns the result.
2489
2490 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2491 in Operand and the value specified by AndData, followed by a bitwise
2492 inclusive OR with value specified by OrData. All other bits in Operand are
2493 preserved. The new 16-bit value is returned.
2494
2495 If 16-bit operations are not supported, then ASSERT().
2496 If StartBit is greater than 15, then ASSERT().
2497 If EndBit is greater than 15, then ASSERT().
2498 If EndBit is less than StartBit, then ASSERT().
2499
2500 @param Operand Operand on which to perform the bitfield operation.
2501 @param StartBit The ordinal of the least significant bit in the bit field.
2502 Range 0..15.
2503 @param EndBit The ordinal of the most significant bit in the bit field.
2504 Range 0..15.
2505 @param AndData The value to AND with the read value from the value.
2506 @param OrData The value to OR with the result of the AND operation.
2507
2508 @return The new 16-bit value.
2509
2510 **/
2511 UINT16
2512 EFIAPI
2513 BitFieldAndThenOr16 (
2514 IN UINT16 Operand,
2515 IN UINTN StartBit,
2516 IN UINTN EndBit,
2517 IN UINT16 AndData,
2518 IN UINT16 OrData
2519 );
2520
2521 /**
2522 Returns a bit field from a 32-bit value.
2523
2524 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2525
2526 If 32-bit operations are not supported, then ASSERT().
2527 If StartBit is greater than 31, then ASSERT().
2528 If EndBit is greater than 31, then ASSERT().
2529 If EndBit is less than StartBit, then ASSERT().
2530
2531 @param Operand Operand on which to perform the bitfield operation.
2532 @param StartBit The ordinal of the least significant bit in the bit field.
2533 Range 0..31.
2534 @param EndBit The ordinal of the most significant bit in the bit field.
2535 Range 0..31.
2536
2537 @return The bit field read.
2538
2539 **/
2540 UINT32
2541 EFIAPI
2542 BitFieldRead32 (
2543 IN UINT32 Operand,
2544 IN UINTN StartBit,
2545 IN UINTN EndBit
2546 );
2547
2548 /**
2549 Writes a bit field to a 32-bit value, and returns the result.
2550
2551 Writes Value to the bit field specified by the StartBit and the EndBit in
2552 Operand. All other bits in Operand are preserved. The new 32-bit value is
2553 returned.
2554
2555 If 32-bit operations are not supported, then ASSERT().
2556 If StartBit is greater than 31, then ASSERT().
2557 If EndBit is greater than 31, then ASSERT().
2558 If EndBit is less than StartBit, then ASSERT().
2559
2560 @param Operand Operand on which to perform the bitfield operation.
2561 @param StartBit The ordinal of the least significant bit in the bit field.
2562 Range 0..31.
2563 @param EndBit The ordinal of the most significant bit in the bit field.
2564 Range 0..31.
2565 @param Value New value of the bit field.
2566
2567 @return The new 32-bit value.
2568
2569 **/
2570 UINT32
2571 EFIAPI
2572 BitFieldWrite32 (
2573 IN UINT32 Operand,
2574 IN UINTN StartBit,
2575 IN UINTN EndBit,
2576 IN UINT32 Value
2577 );
2578
2579 /**
2580 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the
2581 result.
2582
2583 Performs a bitwise inclusive OR between the bit field specified by StartBit
2584 and EndBit in Operand and the value specified by OrData. All other bits in
2585 Operand are preserved. The new 32-bit value is returned.
2586
2587 If 32-bit operations are not supported, then ASSERT().
2588 If StartBit is greater than 31, then ASSERT().
2589 If EndBit is greater than 31, then ASSERT().
2590 If EndBit is less than StartBit, then ASSERT().
2591
2592 @param Operand Operand on which to perform the bitfield operation.
2593 @param StartBit The ordinal of the least significant bit in the bit field.
2594 Range 0..31.
2595 @param EndBit The ordinal of the most significant bit in the bit field.
2596 Range 0..31.
2597 @param OrData The value to OR with the read value from the value
2598
2599 @return The new 32-bit value.
2600
2601 **/
2602 UINT32
2603 EFIAPI
2604 BitFieldOr32 (
2605 IN UINT32 Operand,
2606 IN UINTN StartBit,
2607 IN UINTN EndBit,
2608 IN UINT32 OrData
2609 );
2610
2611 /**
2612 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns
2613 the result.
2614
2615 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2616 in Operand and the value specified by AndData. All other bits in Operand are
2617 preserved. The new 32-bit value is returned.
2618
2619 If 32-bit operations are not supported, then ASSERT().
2620 If StartBit is greater than 31, then ASSERT().
2621 If EndBit is greater than 31, then ASSERT().
2622 If EndBit is less than StartBit, then ASSERT().
2623
2624 @param Operand Operand on which to perform the bitfield operation.
2625 @param StartBit The ordinal of the least significant bit in the bit field.
2626 Range 0..31.
2627 @param EndBit The ordinal of the most significant bit in the bit field.
2628 Range 0..31.
2629 @param AndData The value to AND with the read value from the value
2630
2631 @return The new 32-bit value.
2632
2633 **/
2634 UINT32
2635 EFIAPI
2636 BitFieldAnd32 (
2637 IN UINT32 Operand,
2638 IN UINTN StartBit,
2639 IN UINTN EndBit,
2640 IN UINT32 AndData
2641 );
2642
2643 /**
2644 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a
2645 bitwise OR, and returns the result.
2646
2647 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2648 in Operand and the value specified by AndData, followed by a bitwise
2649 inclusive OR with value specified by OrData. All other bits in Operand are
2650 preserved. The new 32-bit value is returned.
2651
2652 If 32-bit operations are not supported, then ASSERT().
2653 If StartBit is greater than 31, then ASSERT().
2654 If EndBit is greater than 31, then ASSERT().
2655 If EndBit is less than StartBit, then ASSERT().
2656
2657 @param Operand Operand on which to perform the bitfield operation.
2658 @param StartBit The ordinal of the least significant bit in the bit field.
2659 Range 0..31.
2660 @param EndBit The ordinal of the most significant bit in the bit field.
2661 Range 0..31.
2662 @param AndData The value to AND with the read value from the value.
2663 @param OrData The value to OR with the result of the AND operation.
2664
2665 @return The new 32-bit value.
2666
2667 **/
2668 UINT32
2669 EFIAPI
2670 BitFieldAndThenOr32 (
2671 IN UINT32 Operand,
2672 IN UINTN StartBit,
2673 IN UINTN EndBit,
2674 IN UINT32 AndData,
2675 IN UINT32 OrData
2676 );
2677
2678 /**
2679 Returns a bit field from a 64-bit value.
2680
2681 Returns the bitfield specified by the StartBit and the EndBit from Operand.
2682
2683 If 64-bit operations are not supported, then ASSERT().
2684 If StartBit is greater than 63, then ASSERT().
2685 If EndBit is greater than 63, then ASSERT().
2686 If EndBit is less than StartBit, then ASSERT().
2687
2688 @param Operand Operand on which to perform the bitfield operation.
2689 @param StartBit The ordinal of the least significant bit in the bit field.
2690 Range 0..63.
2691 @param EndBit The ordinal of the most significant bit in the bit field.
2692 Range 0..63.
2693
2694 @return The bit field read.
2695
2696 **/
2697 UINT64
2698 EFIAPI
2699 BitFieldRead64 (
2700 IN UINT64 Operand,
2701 IN UINTN StartBit,
2702 IN UINTN EndBit
2703 );
2704
2705 /**
2706 Writes a bit field to a 64-bit value, and returns the result.
2707
2708 Writes Value to the bit field specified by the StartBit and the EndBit in
2709 Operand. All other bits in Operand are preserved. The new 64-bit value is
2710 returned.
2711
2712 If 64-bit operations are not supported, then ASSERT().
2713 If StartBit is greater than 63, then ASSERT().
2714 If EndBit is greater than 63, then ASSERT().
2715 If EndBit is less than StartBit, then ASSERT().
2716
2717 @param Operand Operand on which to perform the bitfield operation.
2718 @param StartBit The ordinal of the least significant bit in the bit field.
2719 Range 0..63.
2720 @param EndBit The ordinal of the most significant bit in the bit field.
2721 Range 0..63.
2722 @param Value New value of the bit field.
2723
2724 @return The new 64-bit value.
2725
2726 **/
2727 UINT64
2728 EFIAPI
2729 BitFieldWrite64 (
2730 IN UINT64 Operand,
2731 IN UINTN StartBit,
2732 IN UINTN EndBit,
2733 IN UINT64 Value
2734 );
2735
2736 /**
2737 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the
2738 result.
2739
2740 Performs a bitwise inclusive OR between the bit field specified by StartBit
2741 and EndBit in Operand and the value specified by OrData. All other bits in
2742 Operand are preserved. The new 64-bit value is returned.
2743
2744 If 64-bit operations are not supported, then ASSERT().
2745 If StartBit is greater than 63, then ASSERT().
2746 If EndBit is greater than 63, then ASSERT().
2747 If EndBit is less than StartBit, then ASSERT().
2748
2749 @param Operand Operand on which to perform the bitfield operation.
2750 @param StartBit The ordinal of the least significant bit in the bit field.
2751 Range 0..63.
2752 @param EndBit The ordinal of the most significant bit in the bit field.
2753 Range 0..63.
2754 @param OrData The value to OR with the read value from the value
2755
2756 @return The new 64-bit value.
2757
2758 **/
2759 UINT64
2760 EFIAPI
2761 BitFieldOr64 (
2762 IN UINT64 Operand,
2763 IN UINTN StartBit,
2764 IN UINTN EndBit,
2765 IN UINT64 OrData
2766 );
2767
2768 /**
2769 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns
2770 the result.
2771
2772 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2773 in Operand and the value specified by AndData. All other bits in Operand are
2774 preserved. The new 64-bit value is returned.
2775
2776 If 64-bit operations are not supported, then ASSERT().
2777 If StartBit is greater than 63, then ASSERT().
2778 If EndBit is greater than 63, then ASSERT().
2779 If EndBit is less than StartBit, then ASSERT().
2780
2781 @param Operand Operand on which to perform the bitfield operation.
2782 @param StartBit The ordinal of the least significant bit in the bit field.
2783 Range 0..63.
2784 @param EndBit The ordinal of the most significant bit in the bit field.
2785 Range 0..63.
2786 @param AndData The value to AND with the read value from the value
2787
2788 @return The new 64-bit value.
2789
2790 **/
2791 UINT64
2792 EFIAPI
2793 BitFieldAnd64 (
2794 IN UINT64 Operand,
2795 IN UINTN StartBit,
2796 IN UINTN EndBit,
2797 IN UINT64 AndData
2798 );
2799
2800 /**
2801 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a
2802 bitwise OR, and returns the result.
2803
2804 Performs a bitwise AND between the bit field specified by StartBit and EndBit
2805 in Operand and the value specified by AndData, followed by a bitwise
2806 inclusive OR with value specified by OrData. All other bits in Operand are
2807 preserved. The new 64-bit value is returned.
2808
2809 If 64-bit operations are not supported, then ASSERT().
2810 If StartBit is greater than 63, then ASSERT().
2811 If EndBit is greater than 63, then ASSERT().
2812 If EndBit is less than StartBit, then ASSERT().
2813
2814 @param Operand Operand on which to perform the bitfield operation.
2815 @param StartBit The ordinal of the least significant bit in the bit field.
2816 Range 0..63.
2817 @param EndBit The ordinal of the most significant bit in the bit field.
2818 Range 0..63.
2819 @param AndData The value to AND with the read value from the value.
2820 @param OrData The value to OR with the result of the AND operation.
2821
2822 @return The new 64-bit value.
2823
2824 **/
2825 UINT64
2826 EFIAPI
2827 BitFieldAndThenOr64 (
2828 IN UINT64 Operand,
2829 IN UINTN StartBit,
2830 IN UINTN EndBit,
2831 IN UINT64 AndData,
2832 IN UINT64 OrData
2833 );
2834
2835 //
2836 // Base Library Synchronization Functions
2837 //
2838
2839 /**
2840 Retrieves the architecture specific spin lock alignment requirements for
2841 optimal spin lock performance.
2842
2843 This function retrieves the spin lock alignment requirements for optimal
2844 performance on a given CPU architecture. The spin lock alignment must be a
2845 power of two and is returned by this function. If there are no alignment
2846 requirements, then 1 must be returned. The spin lock synchronization
2847 functions must function correctly if the spin lock size and alignment values
2848 returned by this function are not used at all. These values are hints to the
2849 consumers of the spin lock synchronization functions to obtain optimal spin
2850 lock performance.
2851
2852 @return The architecture specific spin lock alignment.
2853
2854 **/
2855 UINTN
2856 EFIAPI
2857 GetSpinLockProperties (
2858 VOID
2859 );
2860
2861 /**
2862 Initializes a spin lock to the released state and returns the spin lock.
2863
2864 This function initializes the spin lock specified by SpinLock to the released
2865 state, and returns SpinLock. Optimal performance can be achieved by calling
2866 GetSpinLockProperties() to determine the size and alignment requirements for
2867 SpinLock.
2868
2869 If SpinLock is NULL, then ASSERT().
2870
2871 @param SpinLock A pointer to the spin lock to initialize to the released
2872 state.
2873
2874 @return SpinLock
2875
2876 **/
2877 SPIN_LOCK *
2878 EFIAPI
2879 InitializeSpinLock (
2880 IN SPIN_LOCK *SpinLock
2881 );
2882
2883 /**
2884 Waits until a spin lock can be placed in the acquired state.
2885
2886 This function checks the state of the spin lock specified by SpinLock. If
2887 SpinLock is in the released state, then this function places SpinLock in the
2888 acquired state and returns SpinLock. Otherwise, this function waits
2889 indefinitely for the spin lock to be released, and then places it in the
2890 acquired state and returns SpinLock. All state transitions of SpinLock must
2891 be performed using MP safe mechanisms.
2892
2893 If SpinLock is NULL, then ASSERT().
2894 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2895 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
2896 PcdSpinLockTimeout microseconds, then ASSERT().
2897
2898 @param SpinLock A pointer to the spin lock to place in the acquired state.
2899
2900 @return SpinLock
2901
2902 **/
2903 SPIN_LOCK *
2904 EFIAPI
2905 AcquireSpinLock (
2906 IN SPIN_LOCK *SpinLock
2907 );
2908
2909 /**
2910 Attempts to place a spin lock in the acquired state.
2911
2912 This function checks the state of the spin lock specified by SpinLock. If
2913 SpinLock is in the released state, then this function places SpinLock in the
2914 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
2915 transitions of SpinLock must be performed using MP safe mechanisms.
2916
2917 If SpinLock is NULL, then ASSERT().
2918 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2919
2920 @param SpinLock A pointer to the spin lock to place in the acquired state.
2921
2922 @retval TRUE SpinLock was placed in the acquired state.
2923 @retval FALSE SpinLock could not be acquired.
2924
2925 **/
2926 BOOLEAN
2927 EFIAPI
2928 AcquireSpinLockOrFail (
2929 IN SPIN_LOCK *SpinLock
2930 );
2931
2932 /**
2933 Releases a spin lock.
2934
2935 This function places the spin lock specified by SpinLock in the release state
2936 and returns SpinLock.
2937
2938 If SpinLock is NULL, then ASSERT().
2939 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
2940
2941 @param SpinLock A pointer to the spin lock to release.
2942
2943 @return SpinLock
2944
2945 **/
2946 SPIN_LOCK *
2947 EFIAPI
2948 ReleaseSpinLock (
2949 IN SPIN_LOCK *SpinLock
2950 );
2951
2952 /**
2953 Performs an atomic increment of an 32-bit unsigned integer.
2954
2955 Performs an atomic increment of the 32-bit unsigned integer specified by
2956 Value and returns the incremented value. The increment operation must be
2957 performed using MP safe mechanisms. The state of the return value is not
2958 guaranteed to be MP safe.
2959
2960 If Value is NULL, then ASSERT().
2961
2962 @param Value A pointer to the 32-bit value to increment.
2963
2964 @return The incremented value.
2965
2966 **/
2967 UINT32
2968 EFIAPI
2969 InterlockedIncrement (
2970 IN UINT32 *Value
2971 );
2972
2973 /**
2974 Performs an atomic decrement of an 32-bit unsigned integer.
2975
2976 Performs an atomic decrement of the 32-bit unsigned integer specified by
2977 Value and returns the decremented value. The decrement operation must be
2978 performed using MP safe mechanisms. The state of the return value is not
2979 guaranteed to be MP safe.
2980
2981 If Value is NULL, then ASSERT().
2982
2983 @param Value A pointer to the 32-bit value to decrement.
2984
2985 @return The decremented value.
2986
2987 **/
2988 UINT32
2989 EFIAPI
2990 InterlockedDecrement (
2991 IN UINT32 *Value
2992 );
2993
2994 /**
2995 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
2996
2997 Performs an atomic compare exchange operation on the 32-bit unsigned integer
2998 specified by Value. If Value is equal to CompareValue, then Value is set to
2999 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
3000 then Value is returned. The compare exchange operation must be performed using
3001 MP safe mechanisms.
3002
3003 If Value is NULL, then ASSERT().
3004
3005 @param Value A pointer to the 32-bit value for the compare exchange
3006 operation.
3007 @param CompareValue 32-bit value used in compare operation.
3008 @param ExchangeValue 32-bit value used in exchange operation.
3009
3010 @return The original *Value before exchange.
3011
3012 **/
3013 UINT32
3014 EFIAPI
3015 InterlockedCompareExchange32 (
3016 IN OUT UINT32 *Value,
3017 IN UINT32 CompareValue,
3018 IN UINT32 ExchangeValue
3019 );
3020
3021 /**
3022 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
3023
3024 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
3025 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
3026 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
3027 The compare exchange operation must be performed using MP safe mechanisms.
3028
3029 If Value is NULL, then ASSERT().
3030
3031 @param Value A pointer to the 64-bit value for the compare exchange
3032 operation.
3033 @param CompareValue 64-bit value used in compare operation.
3034 @param ExchangeValue 64-bit value used in exchange operation.
3035
3036 @return The original *Value before exchange.
3037
3038 **/
3039 UINT64
3040 EFIAPI
3041 InterlockedCompareExchange64 (
3042 IN OUT UINT64 *Value,
3043 IN UINT64 CompareValue,
3044 IN UINT64 ExchangeValue
3045 );
3046
3047 /**
3048 Performs an atomic compare exchange operation on a pointer value.
3049
3050 Performs an atomic compare exchange operation on the pointer value specified
3051 by Value. If Value is equal to CompareValue, then Value is set to
3052 ExchangeValue and CompareValue is returned. If Value is not equal to
3053 CompareValue, then Value is returned. The compare exchange operation must be
3054 performed using MP safe mechanisms.
3055
3056 If Value is NULL, then ASSERT().
3057
3058 @param Value A pointer to the pointer value for the compare exchange
3059 operation.
3060 @param CompareValue Pointer value used in compare operation.
3061 @param ExchangeValue Pointer value used in exchange operation.
3062
3063 **/
3064 VOID *
3065 EFIAPI
3066 InterlockedCompareExchangePointer (
3067 IN OUT VOID **Value,
3068 IN VOID *CompareValue,
3069 IN VOID *ExchangeValue
3070 );
3071
3072 //
3073 // Base Library Checksum Functions
3074 //
3075
3076 /**
3077 Calculate the sum of all elements in a buffer in unit of UINT8.
3078 During calculation, the carry bits are dropped.
3079
3080 This function calculates the sum of all elements in a buffer
3081 in unit of UINT8. The carry bits in result of addition are dropped.
3082 The result is returned as UINT8. If Length is Zero, then Zero is
3083 returned.
3084
3085 If Buffer is NULL, then ASSERT().
3086 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3087
3088 @param Buffer Pointer to the buffer to carry out the sum operation.
3089 @param Length The size, in bytes, of Buffer .
3090
3091 @return Sum The sum of Buffer with carry bits dropped during additions.
3092
3093 **/
3094 UINT8
3095 EFIAPI
3096 CalculateSum8 (
3097 IN CONST UINT8 *Buffer,
3098 IN UINTN Length
3099 );
3100
3101
3102 /**
3103 Returns the two's complement checksum of all elements in a buffer
3104 of 8-bit values.
3105
3106 This function first calculates the sum of the 8-bit values in the
3107 buffer specified by Buffer and Length. The carry bits in the result
3108 of addition are dropped. Then, the two's complement of the sum is
3109 returned. If Length is 0, then 0 is returned.
3110
3111 If Buffer is NULL, then ASSERT().
3112 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3113
3114
3115 @param Buffer Pointer to the buffer to carry out the checksum operation.
3116 @param Length The size, in bytes, of Buffer.
3117
3118 @return Checksum The 2's complement checksum of Buffer.
3119
3120 **/
3121 UINT8
3122 EFIAPI
3123 CalculateCheckSum8 (
3124 IN CONST UINT8 *Buffer,
3125 IN UINTN Length
3126 );
3127
3128 /**
3129 Returns the sum of all elements in a buffer of 16-bit values. During
3130 calculation, the carry bits are dropped.
3131
3132 This function calculates the sum of the 16-bit values in the buffer
3133 specified by Buffer and Length. The carry bits in result of addition are dropped.
3134 The 16-bit result is returned. If Length is 0, then 0 is returned.
3135
3136 If Buffer is NULL, then ASSERT().
3137 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3138 If Length is not aligned on a 16-bit boundary, then ASSERT().
3139 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3140
3141 @param Buffer Pointer to the buffer to carry out the sum operation.
3142 @param Length The size, in bytes, of Buffer.
3143
3144 @return Sum The sum of Buffer with carry bits dropped during additions.
3145
3146 **/
3147 UINT16
3148 EFIAPI
3149 CalculateSum16 (
3150 IN CONST UINT16 *Buffer,
3151 IN UINTN Length
3152 );
3153
3154 /**
3155 Returns the two's complement checksum of all elements in a buffer of
3156 16-bit values.
3157
3158 This function first calculates the sum of the 16-bit values in the buffer
3159 specified by Buffer and Length. The carry bits in the result of addition
3160 are dropped. Then, the two's complement of the sum is returned. If Length
3161 is 0, then 0 is returned.
3162
3163 If Buffer is NULL, then ASSERT().
3164 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
3165 If Length is not aligned on a 16-bit boundary, then ASSERT().
3166 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3167
3168 @param Buffer Pointer to the buffer to carry out the checksum operation.
3169 @param Length The size, in bytes, of Buffer.
3170
3171 @return Checksum The 2's complement checksum of Buffer.
3172
3173 **/
3174 UINT16
3175 EFIAPI
3176 CalculateCheckSum16 (
3177 IN CONST UINT16 *Buffer,
3178 IN UINTN Length
3179 );
3180
3181 /**
3182 Returns the sum of all elements in a buffer of 32-bit values. During
3183 calculation, the carry bits are dropped.
3184
3185 This function calculates the sum of the 32-bit values in the buffer
3186 specified by Buffer and Length. The carry bits in result of addition are dropped.
3187 The 32-bit result is returned. If Length is 0, then 0 is returned.
3188
3189 If Buffer is NULL, then ASSERT().
3190 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3191 If Length is not aligned on a 32-bit boundary, then ASSERT().
3192 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3193
3194 @param Buffer Pointer to the buffer to carry out the sum operation.
3195 @param Length The size, in bytes, of Buffer.
3196
3197 @return Sum The sum of Buffer with carry bits dropped during additions.
3198
3199 **/
3200 UINT32
3201 EFIAPI
3202 CalculateSum32 (
3203 IN CONST UINT32 *Buffer,
3204 IN UINTN Length
3205 );
3206
3207 /**
3208 Returns the two's complement checksum of all elements in a buffer of
3209 32-bit values.
3210
3211 This function first calculates the sum of the 32-bit values in the buffer
3212 specified by Buffer and Length. The carry bits in the result of addition
3213 are dropped. Then, the two's complement of the sum is returned. If Length
3214 is 0, then 0 is returned.
3215
3216 If Buffer is NULL, then ASSERT().
3217 If Buffer is not aligned on a 32-bit boundary, then ASSERT().
3218 If Length is not aligned on a 32-bit boundary, then ASSERT().
3219 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3220
3221 @param Buffer Pointer to the buffer to carry out the checksum operation.
3222 @param Length The size, in bytes, of Buffer.
3223
3224 @return Checksum The 2's complement checksum of Buffer.
3225
3226 **/
3227 UINT32
3228 EFIAPI
3229 CalculateCheckSum32 (
3230 IN CONST UINT32 *Buffer,
3231 IN UINTN Length
3232 );
3233
3234 /**
3235 Returns the sum of all elements in a buffer of 64-bit values. During
3236 calculation, the carry bits are dropped.
3237
3238 This function calculates the sum of the 64-bit values in the buffer
3239 specified by Buffer and Length. The carry bits in result of addition are dropped.
3240 The 64-bit result is returned. If Length is 0, then 0 is returned.
3241
3242 If Buffer is NULL, then ASSERT().
3243 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3244 If Length is not aligned on a 64-bit boundary, then ASSERT().
3245 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3246
3247 @param Buffer Pointer to the buffer to carry out the sum operation.
3248 @param Length The size, in bytes, of Buffer.
3249
3250 @return Sum The sum of Buffer with carry bits dropped during additions.
3251
3252 **/
3253 UINT64
3254 EFIAPI
3255 CalculateSum64 (
3256 IN CONST UINT64 *Buffer,
3257 IN UINTN Length
3258 );
3259
3260 /**
3261 Returns the two's complement checksum of all elements in a buffer of
3262 64-bit values.
3263
3264 This function first calculates the sum of the 64-bit values in the buffer
3265 specified by Buffer and Length. The carry bits in the result of addition
3266 are dropped. Then, the two's complement of the sum is returned. If Length
3267 is 0, then 0 is returned.
3268
3269 If Buffer is NULL, then ASSERT().
3270 If Buffer is not aligned on a 64-bit boundary, then ASSERT().
3271 If Length is not aligned on a 64-bit boundary, then ASSERT().
3272 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
3273
3274 @param Buffer Pointer to the buffer to carry out the checksum operation.
3275 @param Length The size, in bytes, of Buffer.
3276
3277 @return Checksum The 2's complement checksum of Buffer.
3278
3279 **/
3280 UINT64
3281 EFIAPI
3282 CalculateCheckSum64 (
3283 IN CONST UINT64 *Buffer,
3284 IN UINTN Length
3285 );
3286
3287 //
3288 // Base Library CPU Functions
3289 //
3290 typedef
3291 VOID
3292 (EFIAPI *SWITCH_STACK_ENTRY_POINT) (
3293 IN VOID *Context1, OPTIONAL
3294 IN VOID *Context2 OPTIONAL
3295 );
3296
3297 /**
3298 Used to serialize load and store operations.
3299
3300 All loads and stores that proceed calls to this function are guaranteed to be
3301 globally visible when this function returns.
3302
3303 **/
3304 VOID
3305 EFIAPI
3306 MemoryFence (
3307 VOID
3308 );
3309
3310 /**
3311 Saves the current CPU context that can be restored with a call to LongJump()
3312 and returns 0.
3313
3314 Saves the current CPU context in the buffer specified by JumpBuffer and
3315 returns 0. The initial call to SetJump() must always return 0. Subsequent
3316 calls to LongJump() cause a non-zero value to be returned by SetJump().
3317
3318 If JumpBuffer is NULL, then ASSERT().
3319 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3320
3321 @param JumpBuffer A pointer to CPU context buffer.
3322
3323 @retval 0 Indicates a return from SetJump().
3324
3325 **/
3326 UINTN
3327 EFIAPI
3328 SetJump (
3329 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
3330 );
3331
3332 /**
3333 Restores the CPU context that was saved with SetJump().
3334
3335 Restores the CPU context from the buffer specified by JumpBuffer. This
3336 function never returns to the caller. Instead is resumes execution based on
3337 the state of JumpBuffer.
3338
3339 If JumpBuffer is NULL, then ASSERT().
3340 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
3341 If Value is 0, then ASSERT().
3342
3343 @param JumpBuffer A pointer to CPU context buffer.
3344 @param Value The value to return when the SetJump() context is
3345 restored and must be non-zero.
3346
3347 **/
3348 VOID
3349 EFIAPI
3350 LongJump (
3351 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
3352 IN UINTN Value
3353 );
3354
3355 /**
3356 Enables CPU interrupts.
3357
3358 Enables CPU interrupts.
3359
3360 **/
3361 VOID
3362 EFIAPI
3363 EnableInterrupts (
3364 VOID
3365 );
3366
3367 /**
3368 Disables CPU interrupts.
3369
3370 Disables CPU interrupts.
3371
3372 **/
3373 VOID
3374 EFIAPI
3375 DisableInterrupts (
3376 VOID
3377 );
3378
3379 /**
3380 Disables CPU interrupts and returns the interrupt state prior to the disable
3381 operation.
3382
3383 Disables CPU interrupts and returns the interrupt state prior to the disable
3384 operation.
3385
3386 @retval TRUE CPU interrupts were enabled on entry to this call.
3387 @retval FALSE CPU interrupts were disabled on entry to this call.
3388
3389 **/
3390 BOOLEAN
3391 EFIAPI
3392 SaveAndDisableInterrupts (
3393 VOID
3394 );
3395
3396 /**
3397 Enables CPU interrupts for the smallest window required to capture any
3398 pending interrupts.
3399
3400 Enables CPU interrupts for the smallest window required to capture any
3401 pending interrupts.
3402
3403 **/
3404 VOID
3405 EFIAPI
3406 EnableDisableInterrupts (
3407 VOID
3408 );
3409
3410 /**
3411 Retrieves the current CPU interrupt state.
3412
3413 Retrieves the current CPU interrupt state. Returns TRUE is interrupts are
3414 currently enabled. Otherwise returns FALSE.
3415
3416 @retval TRUE CPU interrupts are enabled.
3417 @retval FALSE CPU interrupts are disabled.
3418
3419 **/
3420 BOOLEAN
3421 EFIAPI
3422 GlueGetInterruptState (
3423 VOID
3424 );
3425
3426 /**
3427 Set the current CPU interrupt state.
3428
3429 Sets the current CPU interrupt state to the state specified by
3430 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If
3431 InterruptState is FALSE, then interrupts are disabled. InterruptState is
3432 returned.
3433
3434 @param InterruptState TRUE if interrupts should enabled. FALSE if
3435 interrupts should be disabled.
3436
3437 @return InterruptState
3438
3439 **/
3440 BOOLEAN
3441 EFIAPI
3442 SetInterruptState (
3443 IN BOOLEAN InterruptState
3444 );
3445
3446 /**
3447 Places the CPU in a sleep state until an interrupt is received.
3448
3449 Places the CPU in a sleep state until an interrupt is received. If interrupts
3450 are disabled prior to calling this function, then the CPU will be placed in a
3451 sleep state indefinitely.
3452
3453 **/
3454 VOID
3455 EFIAPI
3456 CpuSleep (
3457 VOID
3458 );
3459
3460 /**
3461 Requests CPU to pause for a short period of time.
3462
3463 Requests CPU to pause for a short period of time. Typically used in MP
3464 systems to prevent memory starvation while waiting for a spin lock.
3465
3466 **/
3467 VOID
3468 EFIAPI
3469 CpuPause (
3470 VOID
3471 );
3472
3473 /**
3474 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3475
3476 Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU.
3477
3478 **/
3479 VOID
3480 EFIAPI
3481 CpuFlushTlb (
3482 VOID
3483 );
3484
3485 /**
3486 Transfers control to a function starting with a new stack.
3487
3488 Transfers control to the function specified by EntryPoint using the new stack
3489 specified by NewStack and passing in the parameters specified by Context1 and
3490 Context2. Context1 and Context2 are optional and may be NULL. The function
3491 EntryPoint must never return.
3492
3493 If EntryPoint is NULL, then ASSERT().
3494 If NewStack is NULL, then ASSERT().
3495
3496 @param EntryPoint A pointer to function to call with the new stack.
3497 @param Context1 A pointer to the context to pass into the EntryPoint
3498 function.
3499 @param Context2 A pointer to the context to pass into the EntryPoint
3500 function.
3501 @param NewStack A pointer to the new stack to use for the EntryPoint
3502 function.
3503
3504 **/
3505 VOID
3506 EFIAPI
3507 SwitchStack (
3508 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
3509 IN VOID *Context1, OPTIONAL
3510 IN VOID *Context2, OPTIONAL
3511 IN VOID *NewStack
3512 );
3513
3514 /**
3515 Generates a breakpoint on the CPU.
3516
3517 Generates a breakpoint on the CPU. The breakpoint must be implemented such
3518 that code can resume normal execution after the breakpoint.
3519
3520 **/
3521 VOID
3522 EFIAPI
3523 CpuBreakpoint (
3524 VOID
3525 );
3526
3527 /**
3528 Executes an infinite loop.
3529
3530 Forces the CPU to execute an infinite loop. A debugger may be used to skip
3531 past the loop and the code that follows the loop must execute properly. This
3532 implies that the infinite loop must not cause the code that follow it to be
3533 optimized away.
3534
3535 **/
3536 VOID
3537 EFIAPI
3538 CpuDeadLoop (
3539 VOID
3540 );
3541
3542 //
3543 // IA32 and X64 Specific Functions
3544 //
3545 //
3546 // Byte packed structure for 16-bit Real Mode EFLAGS
3547 //
3548 typedef union {
3549 struct {
3550 UINT32 CF:1; // Carry Flag
3551 UINT32 Reserved_0:1; // Reserved
3552 UINT32 PF:1; // Parity Flag
3553 UINT32 Reserved_1:1; // Reserved
3554 UINT32 AF:1; // Auxiliary Carry Flag
3555 UINT32 Reserved_2:1; // Reserved
3556 UINT32 ZF:1; // Zero Flag
3557 UINT32 SF:1; // Sign Flag
3558 UINT32 TF:1; // Trap Flag
3559 UINT32 IF:1; // Interrupt Enable Flag
3560 UINT32 DF:1; // Direction Flag
3561 UINT32 OF:1; // Overflow Flag
3562 UINT32 IOPL:2; // I/O Privilege Level
3563 UINT32 NT:1; // Nested Task
3564 UINT32 Reserved_3:1; // Reserved
3565 } Bits;
3566 UINT16 Uint16;
3567 } IA32_FLAGS16;
3568
3569 //
3570 // Byte packed structure for EFLAGS/RFLAGS
3571 // 32-bits on IA-32
3572 // 64-bits on X64. The upper 32-bits on X64 are reserved
3573 //
3574 typedef union {
3575 struct {
3576 UINT32 CF:1; // Carry Flag
3577 UINT32 Reserved_0:1; // Reserved
3578 UINT32 PF:1; // Parity Flag
3579 UINT32 Reserved_1:1; // Reserved
3580 UINT32 AF:1; // Auxiliary Carry Flag
3581 UINT32 Reserved_2:1; // Reserved
3582 UINT32 ZF:1; // Zero Flag
3583 UINT32 SF:1; // Sign Flag
3584 UINT32 TF:1; // Trap Flag
3585 UINT32 IF:1; // Interrupt Enable Flag
3586 UINT32 DF:1; // Direction Flag
3587 UINT32 OF:1; // Overflow Flag
3588 UINT32 IOPL:2; // I/O Privilege Level
3589 UINT32 NT:1; // Nested Task
3590 UINT32 Reserved_3:1; // Reserved
3591 UINT32 RF:1; // Resume Flag
3592 UINT32 VM:1; // Virtual 8086 Mode
3593 UINT32 AC:1; // Alignment Check
3594 UINT32 VIF:1; // Virtual Interrupt Flag
3595 UINT32 VIP:1; // Virtual Interrupt Pending
3596 UINT32 ID:1; // ID Flag
3597 UINT32 Reserved_4:10; // Reserved
3598 } Bits;
3599 UINTN UintN;
3600 } IA32_EFLAGS32;
3601
3602 //
3603 // Byte packed structure for Control Register 0 (CR0)
3604 // 32-bits on IA-32
3605 // 64-bits on X64. The upper 32-bits on X64 are reserved
3606 //
3607 typedef union {
3608 struct {
3609 UINT32 PE:1; // Protection Enable
3610 UINT32 MP:1; // Monitor Coprocessor
3611 UINT32 EM:1; // Emulation
3612 UINT32 TS:1; // Task Switched
3613 UINT32 ET:1; // Extension Type
3614 UINT32 NE:1; // Numeric Error
3615 UINT32 Reserved_0:10; // Reserved
3616 UINT32 WP:1; // Write Protect
3617 UINT32 Reserved_1:1; // Reserved
3618 UINT32 AM:1; // Alignment Mask
3619 UINT32 Reserved_2:10; // Reserved
3620 UINT32 NW:1; // Mot Write-through
3621 UINT32 CD:1; // Cache Disable
3622 UINT32 PG:1; // Paging
3623 } Bits;
3624 UINTN UintN;
3625 } IA32_CR0;
3626
3627 //
3628 // Byte packed structure for Control Register 4 (CR4)
3629 // 32-bits on IA-32
3630 // 64-bits on X64. The upper 32-bits on X64 are reserved
3631 //
3632 typedef union {
3633 struct {
3634 UINT32 VME:1; // Virtual-8086 Mode Extensions
3635 UINT32 PVI:1; // Protected-Mode Virtual Interrupts
3636 UINT32 TSD:1; // Time Stamp Disable
3637 UINT32 DE:1; // Debugging Extensions
3638 UINT32 PSE:1; // Page Size Extensions
3639 UINT32 PAE:1; // Physical Address Extension
3640 UINT32 MCE:1; // Machine Check Enable
3641 UINT32 PGE:1; // Page Global Enable
3642 UINT32 PCE:1; // Performance Monitoring Counter
3643 // Enable
3644 UINT32 OSFXSR:1; // Operating System Support for
3645 // FXSAVE and FXRSTOR instructions
3646 UINT32 OSXMMEXCPT:1; // Operating System Support for
3647 // Unmasked SIMD Floating Point
3648 // Exceptions
3649 UINT32 Reserved_0:2; // Reserved
3650 UINT32 VMXE:1; // VMX Enable
3651 UINT32 Reserved_1:18; // Reseved
3652 } Bits;
3653 UINTN UintN;
3654 } IA32_CR4;
3655
3656 //
3657 // Byte packed structure for an IDTR, GDTR, LDTR descriptor
3658 /// @bug How to make this structure byte-packed in a compiler independent way?
3659 //
3660 #pragma pack (1)
3661 typedef struct {
3662 UINT16 Limit;
3663 UINTN Base;
3664 } IA32_DESCRIPTOR;
3665 #pragma pack ()
3666
3667 #define IA32_IDT_GATE_TYPE_TASK 0x85
3668 #define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86
3669 #define IA32_IDT_GATE_TYPE_TRAP_16 0x87
3670 #define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E
3671 #define IA32_IDT_GATE_TYPE_TRAP_32 0x8F
3672
3673 //
3674 // Byte packed structure for an Interrupt Gate Descriptor
3675 //
3676 typedef union {
3677 struct {
3678 UINT32 OffsetLow:16; // Offset bits 15..0
3679 UINT32 Selector:16; // Selector
3680 UINT32 Reserved_0:8; // Reserved
3681 UINT32 GateType:8; // Gate Type. See #defines above
3682 UINT32 OffsetHigh:16; // Offset bits 31..16
3683 } Bits;
3684 UINT64 Uint64;
3685 } IA32_IDT_GATE_DESCRIPTOR;
3686
3687 //
3688 // Byte packed structure for an FP/SSE/SSE2 context
3689 //
3690 typedef struct {
3691 UINT8 Buffer[512];
3692 } IA32_FX_BUFFER;
3693
3694 //
3695 // Structures for the 16-bit real mode thunks
3696 //
3697 typedef struct {
3698 UINT32 Reserved1;
3699 UINT32 Reserved2;
3700 UINT32 Reserved3;
3701 UINT32 Reserved4;
3702 UINT8 BL;
3703 UINT8 BH;
3704 UINT16 Reserved5;
3705 UINT8 DL;
3706 UINT8 DH;
3707 UINT16 Reserved6;
3708 UINT8 CL;
3709 UINT8 CH;
3710 UINT16 Reserved7;
3711 UINT8 AL;
3712 UINT8 AH;
3713 UINT16 Reserved8;
3714 } IA32_BYTE_REGS;
3715
3716 typedef struct {
3717 UINT16 DI;
3718 UINT16 Reserved1;
3719 UINT16 SI;
3720 UINT16 Reserved2;
3721 UINT16 BP;
3722 UINT16 Reserved3;
3723 UINT16 SP;
3724 UINT16 Reserved4;
3725 UINT16 BX;
3726 UINT16 Reserved5;
3727 UINT16 DX;
3728 UINT16 Reserved6;
3729 UINT16 CX;
3730 UINT16 Reserved7;
3731 UINT16 AX;
3732 UINT16 Reserved8;
3733 } IA32_WORD_REGS;
3734
3735 typedef struct {
3736 UINT32 EDI;
3737 UINT32 ESI;
3738 UINT32 EBP;
3739 UINT32 ESP;
3740 UINT32 EBX;
3741 UINT32 EDX;
3742 UINT32 ECX;
3743 UINT32 EAX;
3744 UINT16 DS;
3745 UINT16 ES;
3746 UINT16 FS;
3747 UINT16 GS;
3748 IA32_EFLAGS32 EFLAGS;
3749 UINT32 Eip;
3750 UINT16 CS;
3751 UINT16 SS;
3752 } IA32_DWORD_REGS;
3753
3754 typedef union {
3755 IA32_DWORD_REGS E;
3756 IA32_WORD_REGS X;
3757 IA32_BYTE_REGS H;
3758 } IA32_REGISTER_SET;
3759
3760 //
3761 // Byte packed structure for an 16-bit real mode thunks
3762 //
3763 typedef struct {
3764 IA32_REGISTER_SET *RealModeState;
3765 VOID *RealModeBuffer;
3766 UINT32 RealModeBufferSize;
3767 UINT32 ThunkAttributes;
3768 } THUNK_CONTEXT;
3769
3770 #define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001
3771 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002
3772 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004
3773
3774 /**
3775 Retrieves CPUID information.
3776
3777 Executes the CPUID instruction with EAX set to the value specified by Index.
3778 This function always returns Index.
3779 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3780 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3781 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3782 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3783 This function is only available on IA-32 and X64.
3784
3785 @param Index The 32-bit value to load into EAX prior to invoking the CPUID
3786 instruction.
3787 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3788 instruction. This is an optional parameter that may be NULL.
3789 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3790 instruction. This is an optional parameter that may be NULL.
3791 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3792 instruction. This is an optional parameter that may be NULL.
3793 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3794 instruction. This is an optional parameter that may be NULL.
3795
3796 @return Index
3797
3798 **/
3799 UINT32
3800 EFIAPI
3801 AsmCpuid (
3802 IN UINT32 Index,
3803 OUT UINT32 *Eax, OPTIONAL
3804 OUT UINT32 *Ebx, OPTIONAL
3805 OUT UINT32 *Ecx, OPTIONAL
3806 OUT UINT32 *Edx OPTIONAL
3807 );
3808
3809 /**
3810 Retrieves CPUID information using an extended leaf identifier.
3811
3812 Executes the CPUID instruction with EAX set to the value specified by Index
3813 and ECX set to the value specified by SubIndex. This function always returns
3814 Index. This function is only available on IA-32 and x64.
3815
3816 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.
3817 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.
3818 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.
3819 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.
3820
3821 @param Index The 32-bit value to load into EAX prior to invoking the
3822 CPUID instruction.
3823 @param SubIndex The 32-bit value to load into ECX prior to invoking the
3824 CPUID instruction.
3825 @param Eax Pointer to the 32-bit EAX value returned by the CPUID
3826 instruction. This is an optional parameter that may be
3827 NULL.
3828 @param Ebx Pointer to the 32-bit EBX value returned by the CPUID
3829 instruction. This is an optional parameter that may be
3830 NULL.
3831 @param Ecx Pointer to the 32-bit ECX value returned by the CPUID
3832 instruction. This is an optional parameter that may be
3833 NULL.
3834 @param Edx Pointer to the 32-bit EDX value returned by the CPUID
3835 instruction. This is an optional parameter that may be
3836 NULL.
3837
3838 @return Index
3839
3840 **/
3841 UINT32
3842 EFIAPI
3843 AsmCpuidEx (
3844 IN UINT32 Index,
3845 IN UINT32 SubIndex,
3846 OUT UINT32 *Eax, OPTIONAL
3847 OUT UINT32 *Ebx, OPTIONAL
3848 OUT UINT32 *Ecx, OPTIONAL
3849 OUT UINT32 *Edx OPTIONAL
3850 );
3851
3852 /**
3853 Returns the lower 32-bits of a Machine Specific Register(MSR).
3854
3855 Reads and returns the lower 32-bits of the MSR specified by Index.
3856 No parameter checking is performed on Index, and some Index values may cause
3857 CPU exceptions. The caller must either guarantee that Index is valid, or the
3858 caller must set up exception handlers to catch the exceptions. This function
3859 is only available on IA-32 and X64.
3860
3861 @param Index The 32-bit MSR index to read.
3862
3863 @return The lower 32 bits of the MSR identified by Index.
3864
3865 **/
3866 UINT32
3867 EFIAPI
3868 AsmReadMsr32 (
3869 IN UINT32 Index
3870 );
3871
3872 /**
3873 Zero-extend a 32-bit value and writes it to a Machine Specific Register(MSR).
3874
3875 Writes the 32-bit value specified by Value to the MSR specified by Index. The
3876 upper 32-bits of the MSR write are set to zero. The 32-bit value written to
3877 the MSR is returned. No parameter checking is performed on Index or Value,
3878 and some of these may cause CPU exceptions. The caller must either guarantee
3879 that Index and Value are valid, or the caller must establish proper exception
3880 handlers. This function is only available on IA-32 and X64.
3881
3882 @param Index The 32-bit MSR index to write.
3883 @param Value The 32-bit value to write to the MSR.
3884
3885 @return Value
3886
3887 **/
3888 UINT32
3889 EFIAPI
3890 AsmWriteMsr32 (
3891 IN UINT32 Index,
3892 IN UINT32 Value
3893 );
3894
3895 /**
3896 Reads a 64-bit MSR, performs a bitwise inclusive OR on the lower 32-bits, and
3897 writes the result back to the 64-bit MSR.
3898
3899 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
3900 between the lower 32-bits of the read result and the value specified by
3901 OrData, and writes the result to the 64-bit MSR specified by Index. The lower
3902 32-bits of the value written to the MSR is returned. No parameter checking is
3903 performed on Index or OrData, and some of these may cause CPU exceptions. The
3904 caller must either guarantee that Index and OrData are valid, or the caller
3905 must establish proper exception handlers. This function is only available on
3906 IA-32 and X64.
3907
3908 @param Index The 32-bit MSR index to write.
3909 @param OrData The value to OR with the read value from the MSR.
3910
3911 @return The lower 32-bit value written to the MSR.
3912
3913 **/
3914 UINT32
3915 EFIAPI
3916 AsmMsrOr32 (
3917 IN UINT32 Index,
3918 IN UINT32 OrData
3919 );
3920
3921 /**
3922 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes
3923 the result back to the 64-bit MSR.
3924
3925 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3926 lower 32-bits of the read result and the value specified by AndData, and
3927 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of
3928 the value written to the MSR is returned. No parameter checking is performed
3929 on Index or AndData, and some of these may cause CPU exceptions. The caller
3930 must either guarantee that Index and AndData are valid, or the caller must
3931 establish proper exception handlers. This function is only available on IA-32
3932 and X64.
3933
3934 @param Index The 32-bit MSR index to write.
3935 @param AndData The value to AND with the read value from the MSR.
3936
3937 @return The lower 32-bit value written to the MSR.
3938
3939 **/
3940 UINT32
3941 EFIAPI
3942 AsmMsrAnd32 (
3943 IN UINT32 Index,
3944 IN UINT32 AndData
3945 );
3946
3947 /**
3948 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive OR
3949 on the lower 32-bits, and writes the result back to the 64-bit MSR.
3950
3951 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
3952 lower 32-bits of the read result and the value specified by AndData
3953 preserving the upper 32-bits, performs a bitwise inclusive OR between the
3954 result of the AND operation and the value specified by OrData, and writes the
3955 result to the 64-bit MSR specified by Address. The lower 32-bits of the value
3956 written to the MSR is returned. No parameter checking is performed on Index,
3957 AndData, or OrData, and some of these may cause CPU exceptions. The caller
3958 must either guarantee that Index, AndData, and OrData are valid, or the
3959 caller must establish proper exception handlers. This function is only
3960 available on IA-32 and X64.
3961
3962 @param Index The 32-bit MSR index to write.
3963 @param AndData The value to AND with the read value from the MSR.
3964 @param OrData The value to OR with the result of the AND operation.
3965
3966 @return The lower 32-bit value written to the MSR.
3967
3968 **/
3969 UINT32
3970 EFIAPI
3971 AsmMsrAndThenOr32 (
3972 IN UINT32 Index,
3973 IN UINT32 AndData,
3974 IN UINT32 OrData
3975 );
3976
3977 /**
3978 Reads a bit field of an MSR.
3979
3980 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is
3981 specified by the StartBit and the EndBit. The value of the bit field is
3982 returned. The caller must either guarantee that Index is valid, or the caller
3983 must set up exception handlers to catch the exceptions. This function is only
3984 available on IA-32 and X64.
3985
3986 If StartBit is greater than 31, then ASSERT().
3987 If EndBit is greater than 31, then ASSERT().
3988 If EndBit is less than StartBit, then ASSERT().
3989
3990 @param Index The 32-bit MSR index to read.
3991 @param StartBit The ordinal of the least significant bit in the bit field.
3992 Range 0..31.
3993 @param EndBit The ordinal of the most significant bit in the bit field.
3994 Range 0..31.
3995
3996 @return The bit field read from the MSR.
3997
3998 **/
3999 UINT32
4000 EFIAPI
4001 AsmMsrBitFieldRead32 (
4002 IN UINT32 Index,
4003 IN UINTN StartBit,
4004 IN UINTN EndBit
4005 );
4006
4007 /**
4008 Writes a bit field to an MSR.
4009
4010 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit
4011 field is specified by the StartBit and the EndBit. All other bits in the
4012 destination MSR are preserved. The lower 32-bits of the MSR written is
4013 returned. Extra left bits in Value are stripped. The caller must either
4014 guarantee that Index and the data written is valid, or the caller must set up
4015 exception handlers to catch the exceptions. This function is only available
4016 on IA-32 and X64.
4017
4018 If StartBit is greater than 31, then ASSERT().
4019 If EndBit is greater than 31, then ASSERT().
4020 If EndBit is less than StartBit, then ASSERT().
4021
4022 @param Index The 32-bit MSR index to write.
4023 @param StartBit The ordinal of the least significant bit in the bit field.
4024 Range 0..31.
4025 @param EndBit The ordinal of the most significant bit in the bit field.
4026 Range 0..31.
4027 @param Value New value of the bit field.
4028
4029 @return The lower 32-bit of the value written to the MSR.
4030
4031 **/
4032 UINT32
4033 EFIAPI
4034 AsmMsrBitFieldWrite32 (
4035 IN UINT32 Index,
4036 IN UINTN StartBit,
4037 IN UINTN EndBit,
4038 IN UINT32 Value
4039 );
4040
4041 /**
4042 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the
4043 result back to the bit field in the 64-bit MSR.
4044
4045 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
4046 between the read result and the value specified by OrData, and writes the
4047 result to the 64-bit MSR specified by Index. The lower 32-bits of the value
4048 written to the MSR are returned. Extra left bits in OrData are stripped. The
4049 caller must either guarantee that Index and the data written is valid, or
4050 the caller must set up exception handlers to catch the exceptions. This
4051 function is only available on IA-32 and X64.
4052
4053 If StartBit is greater than 31, then ASSERT().
4054 If EndBit is greater than 31, then ASSERT().
4055 If EndBit is less than StartBit, then ASSERT().
4056
4057 @param Index The 32-bit MSR index to write.
4058 @param StartBit The ordinal of the least significant bit in the bit field.
4059 Range 0..31.
4060 @param EndBit The ordinal of the most significant bit in the bit field.
4061 Range 0..31.
4062 @param OrData The value to OR with the read value from the MSR.
4063
4064 @return The lower 32-bit of the value written to the MSR.
4065
4066 **/
4067 UINT32
4068 EFIAPI
4069 AsmMsrBitFieldOr32 (
4070 IN UINT32 Index,
4071 IN UINTN StartBit,
4072 IN UINTN EndBit,
4073 IN UINT32 OrData
4074 );
4075
4076 /**
4077 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
4078 result back to the bit field in the 64-bit MSR.
4079
4080 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4081 read result and the value specified by AndData, and writes the result to the
4082 64-bit MSR specified by Index. The lower 32-bits of the value written to the
4083 MSR are returned. Extra left bits in AndData are stripped. The caller must
4084 either guarantee that Index and the data written is valid, or the caller must
4085 set up exception handlers to catch the exceptions. This function is only
4086 available on IA-32 and X64.
4087
4088 If StartBit is greater than 31, then ASSERT().
4089 If EndBit is greater than 31, then ASSERT().
4090 If EndBit is less than StartBit, then ASSERT().
4091
4092 @param Index The 32-bit MSR index to write.
4093 @param StartBit The ordinal of the least significant bit in the bit field.
4094 Range 0..31.
4095 @param EndBit The ordinal of the most significant bit in the bit field.
4096 Range 0..31.
4097 @param AndData The value to AND with the read value from the MSR.
4098
4099 @return The lower 32-bit of the value written to the MSR.
4100
4101 **/
4102 UINT32
4103 EFIAPI
4104 AsmMsrBitFieldAnd32 (
4105 IN UINT32 Index,
4106 IN UINTN StartBit,
4107 IN UINTN EndBit,
4108 IN UINT32 AndData
4109 );
4110
4111 /**
4112 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
4113 bitwise inclusive OR, and writes the result back to the bit field in the
4114 64-bit MSR.
4115
4116 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a
4117 bitwise inclusive OR between the read result and the value specified by
4118 AndData, and writes the result to the 64-bit MSR specified by Index. The
4119 lower 32-bits of the value written to the MSR are returned. Extra left bits
4120 in both AndData and OrData are stripped. The caller must either guarantee
4121 that Index and the data written is valid, or the caller must set up exception
4122 handlers to catch the exceptions. This function is only available on IA-32
4123 and X64.
4124
4125 If StartBit is greater than 31, then ASSERT().
4126 If EndBit is greater than 31, then ASSERT().
4127 If EndBit is less than StartBit, then ASSERT().
4128
4129 @param Index The 32-bit MSR index to write.
4130 @param StartBit The ordinal of the least significant bit in the bit field.
4131 Range 0..31.
4132 @param EndBit The ordinal of the most significant bit in the bit field.
4133 Range 0..31.
4134 @param AndData The value to AND with the read value from the MSR.
4135 @param OrData The value to OR with the result of the AND operation.
4136
4137 @return The lower 32-bit of the value written to the MSR.
4138
4139 **/
4140 UINT32
4141 EFIAPI
4142 AsmMsrBitFieldAndThenOr32 (
4143 IN UINT32 Index,
4144 IN UINTN StartBit,
4145 IN UINTN EndBit,
4146 IN UINT32 AndData,
4147 IN UINT32 OrData
4148 );
4149
4150 /**
4151 Returns a 64-bit Machine Specific Register(MSR).
4152
4153 Reads and returns the 64-bit MSR specified by Index. No parameter checking is
4154 performed on Index, and some Index values may cause CPU exceptions. The
4155 caller must either guarantee that Index is valid, or the caller must set up
4156 exception handlers to catch the exceptions. This function is only available
4157 on IA-32 and X64.
4158
4159 @param Index The 32-bit MSR index to read.
4160
4161 @return The value of the MSR identified by Index.
4162
4163 **/
4164 UINT64
4165 EFIAPI
4166 AsmReadMsr64 (
4167 IN UINT32 Index
4168 );
4169
4170 /**
4171 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the
4172 value.
4173
4174 Writes the 64-bit value specified by Value to the MSR specified by Index. The
4175 64-bit value written to the MSR is returned. No parameter checking is
4176 performed on Index or Value, and some of these may cause CPU exceptions. The
4177 caller must either guarantee that Index and Value are valid, or the caller
4178 must establish proper exception handlers. This function is only available on
4179 IA-32 and X64.
4180
4181 @param Index The 32-bit MSR index to write.
4182 @param Value The 64-bit value to write to the MSR.
4183
4184 @return Value
4185
4186 **/
4187 UINT64
4188 EFIAPI
4189 AsmWriteMsr64 (
4190 IN UINT32 Index,
4191 IN UINT64 Value
4192 );
4193
4194 /**
4195 Reads a 64-bit MSR, performs a bitwise inclusive OR, and writes the result
4196 back to the 64-bit MSR.
4197
4198 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
4199 between the read result and the value specified by OrData, and writes the
4200 result to the 64-bit MSR specified by Index. The value written to the MSR is
4201 returned. No parameter checking is performed on Index or OrData, and some of
4202 these may cause CPU exceptions. The caller must either guarantee that Index
4203 and OrData are valid, or the caller must establish proper exception handlers.
4204 This function is only available on IA-32 and X64.
4205
4206 @param Index The 32-bit MSR index to write.
4207 @param OrData The value to OR with the read value from the MSR.
4208
4209 @return The value written back to the MSR.
4210
4211 **/
4212 UINT64
4213 EFIAPI
4214 AsmMsrOr64 (
4215 IN UINT32 Index,
4216 IN UINT64 OrData
4217 );
4218
4219 /**
4220 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the
4221 64-bit MSR.
4222
4223 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4224 read result and the value specified by OrData, and writes the result to the
4225 64-bit MSR specified by Index. The value written to the MSR is returned. No
4226 parameter checking is performed on Index or OrData, and some of these may
4227 cause CPU exceptions. The caller must either guarantee that Index and OrData
4228 are valid, or the caller must establish proper exception handlers. This
4229 function is only available on IA-32 and X64.
4230
4231 @param Index The 32-bit MSR index to write.
4232 @param AndData The value to AND with the read value from the MSR.
4233
4234 @return The value written back to the MSR.
4235
4236 **/
4237 UINT64
4238 EFIAPI
4239 AsmMsrAnd64 (
4240 IN UINT32 Index,
4241 IN UINT64 AndData
4242 );
4243
4244 /**
4245 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise inclusive
4246 OR, and writes the result back to the 64-bit MSR.
4247
4248 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read
4249 result and the value specified by AndData, performs a bitwise inclusive OR
4250 between the result of the AND operation and the value specified by OrData,
4251 and writes the result to the 64-bit MSR specified by Index. The value written
4252 to the MSR is returned. No parameter checking is performed on Index, AndData,
4253 or OrData, and some of these may cause CPU exceptions. The caller must either
4254 guarantee that Index, AndData, and OrData are valid, or the caller must
4255 establish proper exception handlers. This function is only available on IA-32
4256 and X64.
4257
4258 @param Index The 32-bit MSR index to write.
4259 @param AndData The value to AND with the read value from the MSR.
4260 @param OrData The value to OR with the result of the AND operation.
4261
4262 @return The value written back to the MSR.
4263
4264 **/
4265 UINT64
4266 EFIAPI
4267 AsmMsrAndThenOr64 (
4268 IN UINT32 Index,
4269 IN UINT64 AndData,
4270 IN UINT64 OrData
4271 );
4272
4273 /**
4274 Reads a bit field of an MSR.
4275
4276 Reads the bit field in the 64-bit MSR. The bit field is specified by the
4277 StartBit and the EndBit. The value of the bit field is returned. The caller
4278 must either guarantee that Index is valid, or the caller must set up
4279 exception handlers to catch the exceptions. This function is only available
4280 on IA-32 and X64.
4281
4282 If StartBit is greater than 63, then ASSERT().
4283 If EndBit is greater than 63, then ASSERT().
4284 If EndBit is less than StartBit, then ASSERT().
4285
4286 @param Index The 32-bit MSR index to read.
4287 @param StartBit The ordinal of the least significant bit in the bit field.
4288 Range 0..63.
4289 @param EndBit The ordinal of the most significant bit in the bit field.
4290 Range 0..63.
4291
4292 @return The value read from the MSR.
4293
4294 **/
4295 UINT64
4296 EFIAPI
4297 AsmMsrBitFieldRead64 (
4298 IN UINT32 Index,
4299 IN UINTN StartBit,
4300 IN UINTN EndBit
4301 );
4302
4303 /**
4304 Writes a bit field to an MSR.
4305
4306 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by
4307 the StartBit and the EndBit. All other bits in the destination MSR are
4308 preserved. The MSR written is returned. Extra left bits in Value are
4309 stripped. The caller must either guarantee that Index and the data written is
4310 valid, or the caller must set up exception handlers to catch the exceptions.
4311 This function is only available on IA-32 and X64.
4312
4313 If StartBit is greater than 63, then ASSERT().
4314 If EndBit is greater than 63, then ASSERT().
4315 If EndBit is less than StartBit, then ASSERT().
4316
4317 @param Index The 32-bit MSR index to write.
4318 @param StartBit The ordinal of the least significant bit in the bit field.
4319 Range 0..63.
4320 @param EndBit The ordinal of the most significant bit in the bit field.
4321 Range 0..63.
4322 @param Value New value of the bit field.
4323
4324 @return The value written back to the MSR.
4325
4326 **/
4327 UINT64
4328 EFIAPI
4329 AsmMsrBitFieldWrite64 (
4330 IN UINT32 Index,
4331 IN UINTN StartBit,
4332 IN UINTN EndBit,
4333 IN UINT64 Value
4334 );
4335
4336 /**
4337 Reads a bit field in a 64-bit MSR, performs a bitwise inclusive OR, and
4338 writes the result back to the bit field in the 64-bit MSR.
4339
4340 Reads the 64-bit MSR specified by Index, performs a bitwise inclusive OR
4341 between the read result and the value specified by OrData, and writes the
4342 result to the 64-bit MSR specified by Index. The value written to the MSR is
4343 returned. Extra left bits in OrData are stripped. The caller must either
4344 guarantee that Index and the data written is valid, or the caller must set up
4345 exception handlers to catch the exceptions. This function is only available
4346 on IA-32 and X64.
4347
4348 If StartBit is greater than 63, then ASSERT().
4349 If EndBit is greater than 63, then ASSERT().
4350 If EndBit is less than StartBit, then ASSERT().
4351
4352 @param Index The 32-bit MSR index to write.
4353 @param StartBit The ordinal of the least significant bit in the bit field.
4354 Range 0..63.
4355 @param EndBit The ordinal of the most significant bit in the bit field.
4356 Range 0..63.
4357 @param OrData The value to OR with the read value from the bit field.
4358
4359 @return The value written back to the MSR.
4360
4361 **/
4362 UINT64
4363 EFIAPI
4364 AsmMsrBitFieldOr64 (
4365 IN UINT32 Index,
4366 IN UINTN StartBit,
4367 IN UINTN EndBit,
4368 IN UINT64 OrData
4369 );
4370
4371 /**
4372 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the
4373 result back to the bit field in the 64-bit MSR.
4374
4375 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the
4376 read result and the value specified by AndData, and writes the result to the
4377 64-bit MSR specified by Index. The value written to the MSR is returned.
4378 Extra left bits in AndData are stripped. The caller must either guarantee
4379 that Index and the data written is valid, or the caller must set up exception
4380 handlers to catch the exceptions. This function is only available on IA-32
4381 and X64.
4382
4383 If StartBit is greater than 63, then ASSERT().
4384 If EndBit is greater than 63, then ASSERT().
4385 If EndBit is less than StartBit, then ASSERT().
4386
4387 @param Index The 32-bit MSR index to write.
4388 @param StartBit The ordinal of the least significant bit in the bit field.
4389 Range 0..63.
4390 @param EndBit The ordinal of the most significant bit in the bit field.
4391 Range 0..63.
4392 @param AndData The value to AND with the read value from the bit field.
4393
4394 @return The value written back to the MSR.
4395
4396 **/
4397 UINT64
4398 EFIAPI
4399 AsmMsrBitFieldAnd64 (
4400 IN UINT32 Index,
4401 IN UINTN StartBit,
4402 IN UINTN EndBit,
4403 IN UINT64 AndData
4404 );
4405
4406 /**
4407 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a
4408 bitwise inclusive OR, and writes the result back to the bit field in the
4409 64-bit MSR.
4410
4411 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by
4412 a bitwise inclusive OR between the read result and the value specified by
4413 AndData, and writes the result to the 64-bit MSR specified by Index. The
4414 value written to the MSR is returned. Extra left bits in both AndData and
4415 OrData are stripped. The caller must either guarantee that Index and the data
4416 written is valid, or the caller must set up exception handlers to catch the
4417 exceptions. This function is only available on IA-32 and X64.
4418
4419 If StartBit is greater than 63, then ASSERT().
4420 If EndBit is greater than 63, then ASSERT().
4421 If EndBit is less than StartBit, then ASSERT().
4422
4423 @param Index The 32-bit MSR index to write.
4424 @param StartBit The ordinal of the least significant bit in the bit field.
4425 Range 0..63.
4426 @param EndBit The ordinal of the most significant bit in the bit field.
4427 Range 0..63.
4428 @param AndData The value to AND with the read value from the bit field.
4429 @param OrData The value to OR with the result of the AND operation.
4430
4431 @return The value written back to the MSR.
4432
4433 **/
4434 UINT64
4435 EFIAPI
4436 AsmMsrBitFieldAndThenOr64 (
4437 IN UINT32 Index,
4438 IN UINTN StartBit,
4439 IN UINTN EndBit,
4440 IN UINT64 AndData,
4441 IN UINT64 OrData
4442 );
4443
4444 /**
4445 Reads the current value of the EFLAGS register.
4446
4447 Reads and returns the current value of the EFLAGS register. This function is
4448 only available on IA-32 and X64. This returns a 32-bit value on IA-32 and a
4449 64-bit value on X64.
4450
4451 @return EFLAGS on IA-32 or RFLAGS on X64.
4452
4453 **/
4454 UINTN
4455 EFIAPI
4456 AsmReadEflags (
4457 VOID
4458 );
4459
4460 /**
4461 Reads the current value of the Control Register 0 (CR0).
4462
4463 Reads and returns the current value of CR0. This function is only available
4464 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4465 X64.
4466
4467 @return The value of the Control Register 0 (CR0).
4468
4469 **/
4470 UINTN
4471 EFIAPI
4472 AsmReadCr0 (
4473 VOID
4474 );
4475
4476 /**
4477 Reads the current value of the Control Register 2 (CR2).
4478
4479 Reads and returns the current value of CR2. This function is only available
4480 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4481 X64.
4482
4483 @return The value of the Control Register 2 (CR2).
4484
4485 **/
4486 UINTN
4487 EFIAPI
4488 AsmReadCr2 (
4489 VOID
4490 );
4491
4492 /**
4493 Reads the current value of the Control Register 3 (CR3).
4494
4495 Reads and returns the current value of CR3. This function is only available
4496 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4497 X64.
4498
4499 @return The value of the Control Register 3 (CR3).
4500
4501 **/
4502 UINTN
4503 EFIAPI
4504 AsmReadCr3 (
4505 VOID
4506 );
4507
4508 /**
4509 Reads the current value of the Control Register 4 (CR4).
4510
4511 Reads and returns the current value of CR4. This function is only available
4512 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4513 X64.
4514
4515 @return The value of the Control Register 4 (CR4).
4516
4517 **/
4518 UINTN
4519 EFIAPI
4520 AsmReadCr4 (
4521 VOID
4522 );
4523
4524 /**
4525 Writes a value to Control Register 0 (CR0).
4526
4527 Writes and returns a new value to CR0. This function is only available on
4528 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4529
4530 @param Cr0 The value to write to CR0.
4531
4532 @return The value written to CR0.
4533
4534 **/
4535 UINTN
4536 EFIAPI
4537 AsmWriteCr0 (
4538 UINTN Cr0
4539 );
4540
4541 /**
4542 Writes a value to Control Register 2 (CR2).
4543
4544 Writes and returns a new value to CR2. This function is only available on
4545 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4546
4547 @param Cr2 The value to write to CR2.
4548
4549 @return The value written to CR2.
4550
4551 **/
4552 UINTN
4553 EFIAPI
4554 AsmWriteCr2 (
4555 UINTN Cr2
4556 );
4557
4558 /**
4559 Writes a value to Control Register 3 (CR3).
4560
4561 Writes and returns a new value to CR3. This function is only available on
4562 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4563
4564 @param Cr3 The value to write to CR3.
4565
4566 @return The value written to CR3.
4567
4568 **/
4569 UINTN
4570 EFIAPI
4571 AsmWriteCr3 (
4572 UINTN Cr3
4573 );
4574
4575 /**
4576 Writes a value to Control Register 4 (CR4).
4577
4578 Writes and returns a new value to CR4. This function is only available on
4579 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4580
4581 @param Cr4 The value to write to CR4.
4582
4583 @return The value written to CR4.
4584
4585 **/
4586 UINTN
4587 EFIAPI
4588 AsmWriteCr4 (
4589 UINTN Cr4
4590 );
4591
4592 /**
4593 Reads the current value of Debug Register 0 (DR0).
4594
4595 Reads and returns the current value of DR0. This function is only available
4596 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4597 X64.
4598
4599 @return The value of Debug Register 0 (DR0).
4600
4601 **/
4602 UINTN
4603 EFIAPI
4604 AsmReadDr0 (
4605 VOID
4606 );
4607
4608 /**
4609 Reads the current value of Debug Register 1 (DR1).
4610
4611 Reads and returns the current value of DR1. This function is only available
4612 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4613 X64.
4614
4615 @return The value of Debug Register 1 (DR1).
4616
4617 **/
4618 UINTN
4619 EFIAPI
4620 AsmReadDr1 (
4621 VOID
4622 );
4623
4624 /**
4625 Reads the current value of Debug Register 2 (DR2).
4626
4627 Reads and returns the current value of DR2. This function is only available
4628 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4629 X64.
4630
4631 @return The value of Debug Register 2 (DR2).
4632
4633 **/
4634 UINTN
4635 EFIAPI
4636 AsmReadDr2 (
4637 VOID
4638 );
4639
4640 /**
4641 Reads the current value of Debug Register 3 (DR3).
4642
4643 Reads and returns the current value of DR3. This function is only available
4644 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4645 X64.
4646
4647 @return The value of Debug Register 3 (DR3).
4648
4649 **/
4650 UINTN
4651 EFIAPI
4652 AsmReadDr3 (
4653 VOID
4654 );
4655
4656 /**
4657 Reads the current value of Debug Register 4 (DR4).
4658
4659 Reads and returns the current value of DR4. This function is only available
4660 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4661 X64.
4662
4663 @return The value of Debug Register 4 (DR4).
4664
4665 **/
4666 UINTN
4667 EFIAPI
4668 AsmReadDr4 (
4669 VOID
4670 );
4671
4672 /**
4673 Reads the current value of Debug Register 5 (DR5).
4674
4675 Reads and returns the current value of DR5. This function is only available
4676 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4677 X64.
4678
4679 @return The value of Debug Register 5 (DR5).
4680
4681 **/
4682 UINTN
4683 EFIAPI
4684 AsmReadDr5 (
4685 VOID
4686 );
4687
4688 /**
4689 Reads the current value of Debug Register 6 (DR6).
4690
4691 Reads and returns the current value of DR6. This function is only available
4692 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4693 X64.
4694
4695 @return The value of Debug Register 6 (DR6).
4696
4697 **/
4698 UINTN
4699 EFIAPI
4700 AsmReadDr6 (
4701 VOID
4702 );
4703
4704 /**
4705 Reads the current value of Debug Register 7 (DR7).
4706
4707 Reads and returns the current value of DR7. This function is only available
4708 on IA-32 and X64. This returns a 32-bit value on IA-32 and a 64-bit value on
4709 X64.
4710
4711 @return The value of Debug Register 7 (DR7).
4712
4713 **/
4714 UINTN
4715 EFIAPI
4716 AsmReadDr7 (
4717 VOID
4718 );
4719
4720 /**
4721 Writes a value to Debug Register 0 (DR0).
4722
4723 Writes and returns a new value to DR0. This function is only available on
4724 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4725
4726 @param Dr0 The value to write to Dr0.
4727
4728 @return The value written to Debug Register 0 (DR0).
4729
4730 **/
4731 UINTN
4732 EFIAPI
4733 AsmWriteDr0 (
4734 UINTN Dr0
4735 );
4736
4737 /**
4738 Writes a value to Debug Register 1 (DR1).
4739
4740 Writes and returns a new value to DR1. This function is only available on
4741 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4742
4743 @param Dr1 The value to write to Dr1.
4744
4745 @return The value written to Debug Register 1 (DR1).
4746
4747 **/
4748 UINTN
4749 EFIAPI
4750 AsmWriteDr1 (
4751 UINTN Dr1
4752 );
4753
4754 /**
4755 Writes a value to Debug Register 2 (DR2).
4756
4757 Writes and returns a new value to DR2. This function is only available on
4758 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4759
4760 @param Dr2 The value to write to Dr2.
4761
4762 @return The value written to Debug Register 2 (DR2).
4763
4764 **/
4765 UINTN
4766 EFIAPI
4767 AsmWriteDr2 (
4768 UINTN Dr2
4769 );
4770
4771 /**
4772 Writes a value to Debug Register 3 (DR3).
4773
4774 Writes and returns a new value to DR3. This function is only available on
4775 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4776
4777 @param Dr3 The value to write to Dr3.
4778
4779 @return The value written to Debug Register 3 (DR3).
4780
4781 **/
4782 UINTN
4783 EFIAPI
4784 AsmWriteDr3 (
4785 UINTN Dr3
4786 );
4787
4788 /**
4789 Writes a value to Debug Register 4 (DR4).
4790
4791 Writes and returns a new value to DR4. This function is only available on
4792 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4793
4794 @param Dr4 The value to write to Dr4.
4795
4796 @return The value written to Debug Register 4 (DR4).
4797
4798 **/
4799 UINTN
4800 EFIAPI
4801 AsmWriteDr4 (
4802 UINTN Dr4
4803 );
4804
4805 /**
4806 Writes a value to Debug Register 5 (DR5).
4807
4808 Writes and returns a new value to DR5. This function is only available on
4809 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4810
4811 @param Dr5 The value to write to Dr5.
4812
4813 @return The value written to Debug Register 5 (DR5).
4814
4815 **/
4816 UINTN
4817 EFIAPI
4818 AsmWriteDr5 (
4819 UINTN Dr5
4820 );
4821
4822 /**
4823 Writes a value to Debug Register 6 (DR6).
4824
4825 Writes and returns a new value to DR6. This function is only available on
4826 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4827
4828 @param Dr6 The value to write to Dr6.
4829
4830 @return The value written to Debug Register 6 (DR6).
4831
4832 **/
4833 UINTN
4834 EFIAPI
4835 AsmWriteDr6 (
4836 UINTN Dr6
4837 );
4838
4839 /**
4840 Writes a value to Debug Register 7 (DR7).
4841
4842 Writes and returns a new value to DR7. This function is only available on
4843 IA-32 and X64. This writes a 32-bit value on IA-32 and a 64-bit value on X64.
4844
4845 @param Dr7 The value to write to Dr7.
4846
4847 @return The value written to Debug Register 7 (DR7).
4848
4849 **/
4850 UINTN
4851 EFIAPI
4852 AsmWriteDr7 (
4853 UINTN Dr7
4854 );
4855
4856 /**
4857 Reads the current value of Code Segment Register (CS).
4858
4859 Reads and returns the current value of CS. This function is only available on
4860 IA-32 and X64.
4861
4862 @return The current value of CS.
4863
4864 **/
4865 UINT16
4866 EFIAPI
4867 AsmReadCs (
4868 VOID
4869 );
4870
4871 /**
4872 Reads the current value of Data Segment Register (DS).
4873
4874 Reads and returns the current value of DS. This function is only available on
4875 IA-32 and X64.
4876
4877 @return The current value of DS.
4878
4879 **/
4880 UINT16
4881 EFIAPI
4882 AsmReadDs (
4883 VOID
4884 );
4885
4886 /**
4887 Reads the current value of Extra Segment Register (ES).
4888
4889 Reads and returns the current value of ES. This function is only available on
4890 IA-32 and X64.
4891
4892 @return The current value of ES.
4893
4894 **/
4895 UINT16
4896 EFIAPI
4897 AsmReadEs (
4898 VOID
4899 );
4900
4901 /**
4902 Reads the current value of FS Data Segment Register (FS).
4903
4904 Reads and returns the current value of FS. This function is only available on
4905 IA-32 and X64.
4906
4907 @return The current value of FS.
4908
4909 **/
4910 UINT16
4911 EFIAPI
4912 AsmReadFs (
4913 VOID
4914 );
4915
4916 /**
4917 Reads the current value of GS Data Segment Register (GS).
4918
4919 Reads and returns the current value of GS. This function is only available on
4920 IA-32 and X64.
4921
4922 @return The current value of GS.
4923
4924 **/
4925 UINT16
4926 EFIAPI
4927 AsmReadGs (
4928 VOID
4929 );
4930
4931 /**
4932 Reads the current value of Stack Segment Register (SS).
4933
4934 Reads and returns the current value of SS. This function is only available on
4935 IA-32 and X64.
4936
4937 @return The current value of SS.
4938
4939 **/
4940 UINT16
4941 EFIAPI
4942 AsmReadSs (
4943 VOID
4944 );
4945
4946 /**
4947 Reads the current value of Task Register (TR).
4948
4949 Reads and returns the current value of TR. This function is only available on
4950 IA-32 and X64.
4951
4952 @return The current value of TR.
4953
4954 **/
4955 UINT16
4956 EFIAPI
4957 AsmReadTr (
4958 VOID
4959 );
4960
4961 /**
4962 Reads the current Global Descriptor Table Register(GDTR) descriptor.
4963
4964 Reads and returns the current GDTR descriptor and returns it in Gdtr. This
4965 function is only available on IA-32 and X64.
4966
4967 If Gdtr is NULL, then ASSERT().
4968
4969 @param Gdtr Pointer to a GDTR descriptor.
4970
4971 **/
4972 VOID
4973 EFIAPI
4974 AsmReadGdtr (
4975 OUT IA32_DESCRIPTOR *Gdtr
4976 );
4977
4978 /**
4979 Writes the current Global Descriptor Table Register (GDTR) descriptor.
4980
4981 Writes and the current GDTR descriptor specified by Gdtr. This function is
4982 only available on IA-32 and X64.
4983
4984 If Gdtr is NULL, then ASSERT().
4985
4986 @param Gdtr Pointer to a GDTR descriptor.
4987
4988 **/
4989 VOID
4990 EFIAPI
4991 AsmWriteGdtr (
4992 IN CONST IA32_DESCRIPTOR *Gdtr
4993 );
4994
4995 /**
4996 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
4997
4998 Reads and returns the current IDTR descriptor and returns it in Idtr. This
4999 function is only available on IA-32 and X64.
5000
5001 If Idtr is NULL, then ASSERT().
5002
5003 @param Idtr Pointer to a IDTR descriptor.
5004
5005 **/
5006 VOID
5007 EFIAPI
5008 AsmReadIdtr (
5009 OUT IA32_DESCRIPTOR *Idtr
5010 );
5011
5012 /**
5013 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
5014
5015 Writes the current IDTR descriptor and returns it in Idtr. This function is
5016 only available on IA-32 and X64.
5017
5018 If Idtr is NULL, then ASSERT().
5019
5020 @param Idtr Pointer to a IDTR descriptor.
5021
5022 **/
5023 VOID
5024 EFIAPI
5025 AsmWriteIdtr (
5026 IN CONST IA32_DESCRIPTOR *Idtr
5027 );
5028
5029 /**
5030 Reads the current Local Descriptor Table Register(LDTR) selector.
5031
5032 Reads and returns the current 16-bit LDTR descriptor value. This function is
5033 only available on IA-32 and X64.
5034
5035 @return The current selector of LDT.
5036
5037 **/
5038 UINT16
5039 EFIAPI
5040 AsmReadLdtr (
5041 VOID
5042 );
5043
5044 /**
5045 Writes the current Local Descriptor Table Register (GDTR) selector.
5046
5047 Writes and the current LDTR descriptor specified by Ldtr. This function is
5048 only available on IA-32 and X64.
5049
5050 @param Ldtr 16-bit LDTR selector value.
5051
5052 **/
5053 VOID
5054 EFIAPI
5055 AsmWriteLdtr (
5056 IN UINT16 Ldtr
5057 );
5058
5059 /**
5060 Save the current floating point/SSE/SSE2 context to a buffer.
5061
5062 Saves the current floating point/SSE/SSE2 state to the buffer specified by
5063 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
5064 available on IA-32 and X64.
5065
5066 If Buffer is NULL, then ASSERT().
5067 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
5068
5069 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
5070
5071 **/
5072 VOID
5073 EFIAPI
5074 AsmFxSave (
5075 OUT IA32_FX_BUFFER *Buffer
5076 );
5077
5078 /**
5079 Restores the current floating point/SSE/SSE2 context from a buffer.
5080
5081 Restores the current floating point/SSE/SSE2 state from the buffer specified
5082 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
5083 only available on IA-32 and X64.
5084
5085 If Buffer is NULL, then ASSERT().
5086 If Buffer is not aligned on a 16-byte boundary, then ASSERT().
5087 If Buffer was not saved with AsmFxSave(), then ASSERT().
5088
5089 @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.
5090
5091 **/
5092 VOID
5093 EFIAPI
5094 AsmFxRestore (
5095 IN CONST IA32_FX_BUFFER *Buffer
5096 );
5097
5098 /**
5099 Reads the current value of 64-bit MMX Register #0 (MM0).
5100
5101 Reads and returns the current value of MM0. This function is only available
5102 on IA-32 and X64.
5103
5104 @return The current value of MM0.
5105
5106 **/
5107 UINT64
5108 EFIAPI
5109 AsmReadMm0 (
5110 VOID
5111 );
5112
5113 /**
5114 Reads the current value of 64-bit MMX Register #1 (MM1).
5115
5116 Reads and returns the current value of MM1. This function is only available
5117 on IA-32 and X64.
5118
5119 @return The current value of MM1.
5120
5121 **/
5122 UINT64
5123 EFIAPI
5124 AsmReadMm1 (
5125 VOID
5126 );
5127
5128 /**
5129 Reads the current value of 64-bit MMX Register #2 (MM2).
5130
5131 Reads and returns the current value of MM2. This function is only available
5132 on IA-32 and X64.
5133
5134 @return The current value of MM2.
5135
5136 **/
5137 UINT64
5138 EFIAPI
5139 AsmReadMm2 (
5140 VOID
5141 );
5142
5143 /**
5144 Reads the current value of 64-bit MMX Register #3 (MM3).
5145
5146 Reads and returns the current value of MM3. This function is only available
5147 on IA-32 and X64.
5148
5149 @return The current value of MM3.
5150
5151 **/
5152 UINT64
5153 EFIAPI
5154 AsmReadMm3 (
5155 VOID
5156 );
5157
5158 /**
5159 Reads the current value of 64-bit MMX Register #4 (MM4).
5160
5161 Reads and returns the current value of MM4. This function is only available
5162 on IA-32 and X64.
5163
5164 @return The current value of MM4.
5165
5166 **/
5167 UINT64
5168 EFIAPI
5169 AsmReadMm4 (
5170 VOID
5171 );
5172
5173 /**
5174 Reads the current value of 64-bit MMX Register #5 (MM5).
5175
5176 Reads and returns the current value of MM5. This function is only available
5177 on IA-32 and X64.
5178
5179 @return The current value of MM5.
5180
5181 **/
5182 UINT64
5183 EFIAPI
5184 AsmReadMm5 (
5185 VOID
5186 );
5187
5188 /**
5189 Reads the current value of 64-bit MMX Register #6 (MM6).
5190
5191 Reads and returns the current value of MM6. This function is only available
5192 on IA-32 and X64.
5193
5194 @return The current value of MM6.
5195
5196 **/
5197 UINT64
5198 EFIAPI
5199 AsmReadMm6 (
5200 VOID
5201 );
5202
5203 /**
5204 Reads the current value of 64-bit MMX Register #7 (MM7).
5205
5206 Reads and returns the current value of MM7. This function is only available
5207 on IA-32 and X64.
5208
5209 @return The current value of MM7.
5210
5211 **/
5212 UINT64
5213 EFIAPI
5214 AsmReadMm7 (
5215 VOID
5216 );
5217
5218 /**
5219 Writes the current value of 64-bit MMX Register #0 (MM0).
5220
5221 Writes the current value of MM0. This function is only available on IA32 and
5222 X64.
5223
5224 @param Value The 64-bit value to write to MM0.
5225
5226 **/
5227 VOID
5228 EFIAPI
5229 AsmWriteMm0 (
5230 IN UINT64 Value
5231 );
5232
5233 /**
5234 Writes the current value of 64-bit MMX Register #1 (MM1).
5235
5236 Writes the current value of MM1. This function is only available on IA32 and
5237 X64.
5238
5239 @param Value The 64-bit value to write to MM1.
5240
5241 **/
5242 VOID
5243 EFIAPI
5244 AsmWriteMm1 (
5245 IN UINT64 Value
5246 );
5247
5248 /**
5249 Writes the current value of 64-bit MMX Register #2 (MM2).
5250
5251 Writes the current value of MM2. This function is only available on IA32 and
5252 X64.
5253
5254 @param Value The 64-bit value to write to MM2.
5255
5256 **/
5257 VOID
5258 EFIAPI
5259 AsmWriteMm2 (
5260 IN UINT64 Value
5261 );
5262
5263 /**
5264 Writes the current value of 64-bit MMX Register #3 (MM3).
5265
5266 Writes the current value of MM3. This function is only available on IA32 and
5267 X64.
5268
5269 @param Value The 64-bit value to write to MM3.
5270
5271 **/
5272 VOID
5273 EFIAPI
5274 AsmWriteMm3 (
5275 IN UINT64 Value
5276 );
5277
5278 /**
5279 Writes the current value of 64-bit MMX Register #4 (MM4).
5280
5281 Writes the current value of MM4. This function is only available on IA32 and
5282 X64.
5283
5284 @param Value The 64-bit value to write to MM4.
5285
5286 **/
5287 VOID
5288 EFIAPI
5289 AsmWriteMm4 (
5290 IN UINT64 Value
5291 );
5292
5293 /**
5294 Writes the current value of 64-bit MMX Register #5 (MM5).
5295
5296 Writes the current value of MM5. This function is only available on IA32 and
5297 X64.
5298
5299 @param Value The 64-bit value to write to MM5.
5300
5301 **/
5302 VOID
5303 EFIAPI
5304 AsmWriteMm5 (
5305 IN UINT64 Value
5306 );
5307
5308 /**
5309 Writes the current value of 64-bit MMX Register #6 (MM6).
5310
5311 Writes the current value of MM6. This function is only available on IA32 and
5312 X64.
5313
5314 @param Value The 64-bit value to write to MM6.
5315
5316 **/
5317 VOID
5318 EFIAPI
5319 AsmWriteMm6 (
5320 IN UINT64 Value
5321 );
5322
5323 /**
5324 Writes the current value of 64-bit MMX Register #7 (MM7).
5325
5326 Writes the current value of MM7. This function is only available on IA32 and
5327 X64.
5328
5329 @param Value The 64-bit value to write to MM7.
5330
5331 **/
5332 VOID
5333 EFIAPI
5334 AsmWriteMm7 (
5335 IN UINT64 Value
5336 );
5337
5338 /**
5339 Reads the current value of Time Stamp Counter (TSC).
5340
5341 Reads and returns the current value of TSC. This function is only available
5342 on IA-32 and X64.
5343
5344 @return The current value of TSC
5345
5346 **/
5347 UINT64
5348 EFIAPI
5349 AsmReadTsc (
5350 VOID
5351 );
5352
5353 /**
5354 Reads the current value of a Performance Counter (PMC).
5355
5356 Reads and returns the current value of performance counter specified by
5357 Index. This function is only available on IA-32 and X64.
5358
5359 @param Index The 32-bit Performance Counter index to read.
5360
5361 @return The value of the PMC specified by Index.
5362
5363 **/
5364 UINT64
5365 EFIAPI
5366 AsmReadPmc (
5367 IN UINT32 Index
5368 );
5369
5370 /**
5371 Sets up a monitor buffer that is used by AsmMwait().
5372
5373 Executes a MONITOR instruction with the register state specified by Eax, Ecx
5374 and Edx. Returns Eax. This function is only available on IA-32 and X64.
5375
5376 @param Eax The value to load into EAX or RAX before executing the MONITOR
5377 instruction.
5378 @param Ecx The value to load into ECX or RCX before executing the MONITOR
5379 instruction.
5380 @param Edx The value to load into EDX or RDX before executing the MONITOR
5381 instruction.
5382
5383 @return Eax
5384
5385 **/
5386 UINTN
5387 EFIAPI
5388 AsmMonitor (
5389 IN UINTN Eax,
5390 IN UINTN Ecx,
5391 IN UINTN Edx
5392 );
5393
5394 /**
5395 Executes an MWAIT instruction.
5396
5397 Executes an MWAIT instruction with the register state specified by Eax and
5398 Ecx. Returns Eax. This function is only available on IA-32 and X64.
5399
5400 @param Eax The value to load into EAX or RAX before executing the MONITOR
5401 instruction.
5402 @param Ecx The value to load into ECX or RCX before executing the MONITOR
5403 instruction.
5404
5405 @return Eax
5406
5407 **/
5408 UINTN
5409 EFIAPI
5410 AsmMwait (
5411 IN UINTN Eax,
5412 IN UINTN Ecx
5413 );
5414
5415 /**
5416 Executes a WBINVD instruction.
5417
5418 Executes a WBINVD instruction. This function is only available on IA-32 and
5419 X64.
5420
5421 **/
5422 VOID
5423 EFIAPI
5424 AsmWbinvd (
5425 VOID
5426 );
5427
5428 /**
5429 Executes a INVD instruction.
5430
5431 Executes a INVD instruction. This function is only available on IA-32 and
5432 X64.
5433
5434 **/
5435 VOID
5436 EFIAPI
5437 AsmInvd (
5438 VOID
5439 );
5440
5441 /**
5442 Flushes a cache line from all the instruction and data caches within the
5443 coherency domain of the CPU.
5444
5445 Flushed the cache line specified by LinearAddress, and returns LinearAddress.
5446 This function is only available on IA-32 and X64.
5447
5448 @param LinearAddress The address of the cache line to flush. If the CPU is
5449 in a physical addressing mode, then LinearAddress is a
5450 physical address. If the CPU is in a virtual
5451 addressing mode, then LinearAddress is a virtual
5452 address.
5453
5454 @return LinearAddress
5455 **/
5456 VOID *
5457 EFIAPI
5458 AsmFlushCacheLine (
5459 IN VOID *LinearAddress
5460 );
5461
5462 /**
5463 Enables the 32-bit paging mode on the CPU.
5464
5465 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
5466 must be properly initialized prior to calling this service. This function
5467 assumes the current execution mode is 32-bit protected mode. This function is
5468 only available on IA-32. After the 32-bit paging mode is enabled, control is
5469 transferred to the function specified by EntryPoint using the new stack
5470 specified by NewStack and passing in the parameters specified by Context1 and
5471 Context2. Context1 and Context2 are optional and may be NULL. The function
5472 EntryPoint must never return.
5473
5474 If the current execution mode is not 32-bit protected mode, then ASSERT().
5475 If EntryPoint is NULL, then ASSERT().
5476 If NewStack is NULL, then ASSERT().
5477
5478 There are a number of constraints that must be followed before calling this
5479 function:
5480 1) Interrupts must be disabled.
5481 2) The caller must be in 32-bit protected mode with flat descriptors. This
5482 means all descriptors must have a base of 0 and a limit of 4GB.
5483 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
5484 descriptors.
5485 4) CR3 must point to valid page tables that will be used once the transition
5486 is complete, and those page tables must guarantee that the pages for this
5487 function and the stack are identity mapped.
5488
5489 @param EntryPoint A pointer to function to call with the new stack after
5490 paging is enabled.
5491 @param Context1 A pointer to the context to pass into the EntryPoint
5492 function as the first parameter after paging is enabled.
5493 @param Context2 A pointer to the context to pass into the EntryPoint
5494 function as the second parameter after paging is enabled.
5495 @param NewStack A pointer to the new stack to use for the EntryPoint
5496 function after paging is enabled.
5497
5498 **/
5499 VOID
5500 EFIAPI
5501 AsmEnablePaging32 (
5502 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
5503 IN VOID *Context1, OPTIONAL
5504 IN VOID *Context2, OPTIONAL
5505 IN VOID *NewStack
5506 );
5507
5508 /**
5509 Disables the 32-bit paging mode on the CPU.
5510
5511 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
5512 mode. This function assumes the current execution mode is 32-paged protected
5513 mode. This function is only available on IA-32. After the 32-bit paging mode
5514 is disabled, control is transferred to the function specified by EntryPoint
5515 using the new stack specified by NewStack and passing in the parameters
5516 specified by Context1 and Context2. Context1 and Context2 are optional and
5517 may be NULL. The function EntryPoint must never return.
5518
5519 If the current execution mode is not 32-bit paged mode, then ASSERT().
5520 If EntryPoint is NULL, then ASSERT().
5521 If NewStack is NULL, then ASSERT().
5522
5523 There are a number of constraints that must be followed before calling this
5524 function:
5525 1) Interrupts must be disabled.
5526 2) The caller must be in 32-bit paged mode.
5527 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
5528 4) CR3 must point to valid page tables that guarantee that the pages for
5529 this function and the stack are identity mapped.
5530
5531 @param EntryPoint A pointer to function to call with the new stack after
5532 paging is disabled.
5533 @param Context1 A pointer to the context to pass into the EntryPoint
5534 function as the first parameter after paging is disabled.
5535 @param Context2 A pointer to the context to pass into the EntryPoint
5536 function as the second parameter after paging is
5537 disabled.
5538 @param NewStack A pointer to the new stack to use for the EntryPoint
5539 function after paging is disabled.
5540
5541 **/
5542 VOID
5543 EFIAPI
5544 AsmDisablePaging32 (
5545 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
5546 IN VOID *Context1, OPTIONAL
5547 IN VOID *Context2, OPTIONAL
5548 IN VOID *NewStack
5549 );
5550
5551 /**
5552 Enables the 64-bit paging mode on the CPU.
5553
5554 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
5555 must be properly initialized prior to calling this service. This function
5556 assumes the current execution mode is 32-bit protected mode with flat
5557 descriptors. This function is only available on IA-32. After the 64-bit
5558 paging mode is enabled, control is transferred to the function specified by
5559 EntryPoint using the new stack specified by NewStack and passing in the
5560 parameters specified by Context1 and Context2. Context1 and Context2 are
5561 optional and may be 0. The function EntryPoint must never return.
5562
5563 If the current execution mode is not 32-bit protected mode with flat
5564 descriptors, then ASSERT().
5565 If EntryPoint is 0, then ASSERT().
5566 If NewStack is 0, then ASSERT().
5567
5568 @param Cs The 16-bit selector to load in the CS before EntryPoint
5569 is called. The descriptor in the GDT that this selector
5570 references must be setup for long mode.
5571 @param EntryPoint The 64-bit virtual address of the function to call with
5572 the new stack after paging is enabled.
5573 @param Context1 The 64-bit virtual address of the context to pass into
5574 the EntryPoint function as the first parameter after
5575 paging is enabled.
5576 @param Context2 The 64-bit virtual address of the context to pass into
5577 the EntryPoint function as the second parameter after
5578 paging is enabled.
5579 @param NewStack The 64-bit virtual address of the new stack to use for
5580 the EntryPoint function after paging is enabled.
5581
5582 **/
5583 VOID
5584 EFIAPI
5585 AsmEnablePaging64 (
5586 IN UINT16 CodeSelector,
5587 IN UINT64 EntryPoint,
5588 IN UINT64 Context1, OPTIONAL
5589 IN UINT64 Context2, OPTIONAL
5590 IN UINT64 NewStack
5591 );
5592
5593 /**
5594 Disables the 64-bit paging mode on the CPU.
5595
5596 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
5597 mode. This function assumes the current execution mode is 64-paging mode.
5598 This function is only available on X64. After the 64-bit paging mode is
5599 disabled, control is transferred to the function specified by EntryPoint
5600 using the new stack specified by NewStack and passing in the parameters
5601 specified by Context1 and Context2. Context1 and Context2 are optional and
5602 may be 0. The function EntryPoint must never return.
5603
5604 If the current execution mode is not 64-bit paged mode, then ASSERT().
5605 If EntryPoint is 0, then ASSERT().
5606 If NewStack is 0, then ASSERT().
5607
5608 @param Cs The 16-bit selector to load in the CS before EntryPoint
5609 is called. The descriptor in the GDT that this selector
5610 references must be setup for 32-bit protected mode.
5611 @param EntryPoint The 64-bit virtual address of the function to call with
5612 the new stack after paging is disabled.
5613 @param Context1 The 64-bit virtual address of the context to pass into
5614 the EntryPoint function as the first parameter after
5615 paging is disabled.
5616 @param Context2 The 64-bit virtual address of the context to pass into
5617 the EntryPoint function as the second parameter after
5618 paging is disabled.
5619 @param NewStack The 64-bit virtual address of the new stack to use for
5620 the EntryPoint function after paging is disabled.
5621
5622 **/
5623 VOID
5624 EFIAPI
5625 AsmDisablePaging64 (
5626 IN UINT16 CodeSelector,
5627 IN UINT32 EntryPoint,
5628 IN UINT32 Context1, OPTIONAL
5629 IN UINT32 Context2, OPTIONAL
5630 IN UINT32 NewStack
5631 );
5632
5633 //
5634 // 16-bit thunking services
5635 //
5636
5637 /**
5638 Retrieves the properties for 16-bit thunk functions.
5639
5640 Computes the size of the buffer and stack below 1MB required to use the
5641 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This
5642 buffer size is returned in RealModeBufferSize, and the stack size is returned
5643 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,
5644 then the actual minimum stack size is ExtraStackSize plus the maximum number
5645 of bytes that need to be passed to the 16-bit real mode code.
5646
5647 If RealModeBufferSize is NULL, then ASSERT().
5648 If ExtraStackSize is NULL, then ASSERT().
5649
5650 @param RealModeBufferSize A pointer to the size of the buffer below 1MB
5651 required to use the 16-bit thunk functions.
5652 @param ExtraStackSize A pointer to the extra size of stack below 1MB
5653 that the 16-bit thunk functions require for
5654 temporary storage in the transition to and from
5655 16-bit real mode.
5656
5657 **/
5658 VOID
5659 EFIAPI
5660 AsmGetThunk16Properties (
5661 OUT UINT32 *RealModeBufferSize,
5662 OUT UINT32 *ExtraStackSize
5663 );
5664
5665 /**
5666 Prepares all structures a code required to use AsmThunk16().
5667
5668 Prepares all structures and code required to use AsmThunk16().
5669
5670 If ThunkContext is NULL, then ASSERT().
5671
5672 @param ThunkContext A pointer to the context structure that describes the
5673 16-bit real mode code to call.
5674
5675 **/
5676 VOID
5677 EFIAPI
5678 AsmPrepareThunk16 (
5679 OUT THUNK_CONTEXT *ThunkContext
5680 );
5681
5682 /**
5683 Transfers control to a 16-bit real mode entry point and returns the results.
5684
5685 Transfers control to a 16-bit real mode entry point and returns the results.
5686 AsmPrepareThunk16() must be called with ThunkContext before this function is
5687 used.
5688
5689 If ThunkContext is NULL, then ASSERT().
5690 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().
5691
5692 @param ThunkContext A pointer to the context structure that describes the
5693 16-bit real mode code to call.
5694
5695 **/
5696 VOID
5697 EFIAPI
5698 AsmThunk16 (
5699 IN OUT THUNK_CONTEXT *ThunkContext
5700 );
5701
5702 /**
5703 Prepares all structures and code for a 16-bit real mode thunk, transfers
5704 control to a 16-bit real mode entry point, and returns the results.
5705
5706 Prepares all structures and code for a 16-bit real mode thunk, transfers
5707 control to a 16-bit real mode entry point, and returns the results. If the
5708 caller only need to perform a single 16-bit real mode thunk, then this
5709 service should be used. If the caller intends to make more than one 16-bit
5710 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called
5711 once and AsmThunk16() can be called for each 16-bit real mode thunk.
5712
5713 If ThunkContext is NULL, then ASSERT().
5714
5715 @param ThunkContext A pointer to the context structure that describes the
5716 16-bit real mode code to call.
5717
5718 **/
5719 VOID
5720 EFIAPI
5721 AsmPrepareAndThunk16 (
5722 IN OUT THUNK_CONTEXT *ThunkContext
5723 );
5724
5725 /**
5726 Transfers control to a function starting with a new stack.
5727
5728 Transfers control to the function specified by EntryPoint using the new stack
5729 specified by NewStack and passing in the parameters specified by Context1 and
5730 Context2. Context1 and Context2 are optional and may be NULL. The function
5731 EntryPoint must never return.
5732
5733 If EntryPoint is NULL, then ASSERT().
5734 If NewStack is NULL, then ASSERT().
5735
5736 @param EntryPoint A pointer to function to call with the new stack.
5737 @param Context1 A pointer to the context to pass into the EntryPoint
5738 function.
5739 @param Context2 A pointer to the context to pass into the EntryPoint
5740 function.
5741 @param NewStack A pointer to the new stack to use for the EntryPoint
5742 function.
5743 @param NewBsp A pointer to the new memory location for RSE backing
5744 store.
5745
5746 **/
5747 VOID
5748 EFIAPI
5749 AsmSwitchStackAndBackingStore (
5750 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
5751 IN VOID *Context1, OPTIONAL
5752 IN VOID *Context2, OPTIONAL
5753 IN VOID *NewStack,
5754 IN VOID *NewBsp
5755 );
5756
5757 typedef struct {
5758 UINT64 Status;
5759 UINT64 r9;
5760 UINT64 r10;
5761 UINT64 r11;
5762 } PAL_PROC_RETURN;
5763
5764 //
5765 // IPF Specific functions
5766 //
5767
5768
5769 /**
5770 Performs a PAL call using static calling convention.
5771
5772 An internal function to perform a PAL call using static calling convention.
5773
5774 @param PalEntryPoint The entry point address of PAL. The address in ar.kr5
5775 would be used if this parameter were NULL on input.
5776 @param Arg1 The first argument of a PAL call.
5777 @param Arg1 The second argument of a PAL call.
5778 @param Arg1 The third argument of a PAL call.
5779 @param Arg1 The fourth argument of a PAL call.
5780
5781 @return The values returned in r8, r9, r10 and r11.
5782
5783 **/
5784 PAL_PROC_RETURN
5785 PalCallStatic (
5786 IN CONST VOID *PalEntryPoint,
5787 IN UINT64 Arg1,
5788 IN UINT64 Arg2,
5789 IN UINT64 Arg3,
5790 IN UINT64 Arg4
5791 );
5792
5793
5794 /**
5795 Returns the current value of ar.itc.
5796
5797 An internal function to return the current value of ar.itc, which is the
5798 timer tick on IPF.
5799
5800 @return The currect value of ar.itc
5801
5802 **/
5803 INT64
5804 IpfReadItc (
5805 VOID
5806 );
5807
5808
5809 /**
5810 Flush a range of cache lines in the cache coherency domain of the calling
5811 CPU.
5812
5813 Invalidates the cache lines specified by Address and Length. If Address is
5814 not aligned on a cache line boundary, then entire cache line containing
5815 Address is invalidated. If Address + Length is not aligned on a cache line
5816 boundary, then the entire instruction cache line containing Address + Length
5817 -1 is invalidated. This function may choose to invalidate the entire
5818 instruction cache if that is more efficient than invalidating the specified
5819 range. If Length is 0, the no instruction cache lines are invalidated.
5820 Address is returned.
5821
5822 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
5823
5824 @param Address The base address of the instruction lines to invalidate. If
5825 the CPU is in a physical addressing mode, then Address is a
5826 physical address. If the CPU is in a virtual addressing mode,
5827 then Address is a virtual address.
5828
5829 @param Length The number of bytes to invalidate from the instruction cache.
5830
5831 @return Address
5832
5833 **/
5834 VOID *
5835 EFIAPI
5836 IpfFlushCacheRange (
5837 IN VOID *Address,
5838 IN UINTN Length
5839 );
5840
5841 #endif
5842