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