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