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