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