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