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