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