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