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