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