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