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