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