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