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