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