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