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