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