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