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