]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/BaseLib.h
NetworkPkg: Remove some clarification from UefiPxeBcDxe.inf
[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
9095d37b 5Copyright (c) 2006 - 2018, 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
ac644614 2723/**\r
2724 Converts an 8-bit value to an 8-bit BCD value.\r
2725\r
2726 Converts the 8-bit value specified by Value to BCD. The BCD value is\r
2727 returned.\r
2728\r
2729 If Value >= 100, then ASSERT().\r
2730\r
2731 @param Value The 8-bit value to convert to BCD. Range 0..99.\r
2732\r
9aa049d9 2733 @return The BCD value.\r
ac644614 2734\r
2735**/\r
2736UINT8\r
2737EFIAPI\r
2738DecimalToBcd8 (\r
2739 IN UINT8 Value\r
2740 );\r
2741\r
2742\r
2743/**\r
2744 Converts an 8-bit BCD value to an 8-bit value.\r
2745\r
2746 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit\r
2747 value is returned.\r
2748\r
2749 If Value >= 0xA0, then ASSERT().\r
2750 If (Value & 0x0F) >= 0x0A, then ASSERT().\r
2751\r
2752 @param Value The 8-bit BCD value to convert to an 8-bit value.\r
2753\r
2754 @return The 8-bit value is returned.\r
2755\r
2756**/\r
2757UINT8\r
2758EFIAPI\r
2759BcdToDecimal8 (\r
2760 IN UINT8 Value\r
2761 );\r
2762\r
ae591c14
DM
2763//\r
2764// File Path Manipulation Functions\r
2765//\r
2766\r
2767/**\r
6a623094 2768 Removes the last directory or file entry in a path.\r
ae591c14
DM
2769\r
2770 @param[in, out] Path The pointer to the path to modify.\r
2771\r
2772 @retval FALSE Nothing was found to remove.\r
2773 @retval TRUE A directory or file was removed.\r
2774**/\r
2775BOOLEAN\r
2776EFIAPI\r
2777PathRemoveLastItem(\r
2778 IN OUT CHAR16 *Path\r
2779 );\r
2780\r
2781/**\r
2782 Function to clean up paths.\r
2783 - Single periods in the path are removed.\r
2784 - Double periods in the path are removed along with a single parent directory.\r
2785 - Forward slashes L'/' are converted to backward slashes L'\'.\r
2786\r
2787 This will be done inline and the existing buffer may be larger than required\r
2788 upon completion.\r
2789\r
2790 @param[in] Path The pointer to the string containing the path.\r
2791\r
00b7cc0f 2792 @return Returns Path, otherwise returns NULL to indicate that an error has occurred.\r
ae591c14
DM
2793**/\r
2794CHAR16*\r
2795EFIAPI\r
2796PathCleanUpDirectories(\r
2797 IN CHAR16 *Path\r
909ac47b 2798 );\r
ac644614 2799\r
2800//\r
2801// Linked List Functions and Macros\r
2802//\r
2803\r
2804/**\r
2805 Initializes the head node of a doubly linked list that is declared as a\r
2806 global variable in a module.\r
2807\r
2808 Initializes the forward and backward links of a new linked list. After\r
2809 initializing a linked list with this macro, the other linked list functions\r
2810 may be used to add and remove nodes from the linked list. This macro results\r
2811 in smaller executables by initializing the linked list in the data section,\r
2812 instead if calling the InitializeListHead() function to perform the\r
2813 equivalent operation.\r
2814\r
77f863ee 2815 @param ListHead The head note of a list to initialize.\r
ac644614 2816\r
2817**/\r
17f695ed 2818#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&(ListHead), &(ListHead)}\r
ac644614 2819\r
2820\r
d0aef615
MH
2821/**\r
2822 Checks whether FirstEntry and SecondEntry are part of the same doubly-linked\r
2823 list.\r
2824\r
2825 If FirstEntry is NULL, then ASSERT().\r
2826 If FirstEntry->ForwardLink is NULL, then ASSERT().\r
2827 If FirstEntry->BackLink is NULL, then ASSERT().\r
2828 If SecondEntry is NULL, then ASSERT();\r
2829 If PcdMaximumLinkedListLength is not zero, and List contains more than\r
2830 PcdMaximumLinkedListLength nodes, then ASSERT().\r
2831\r
2832 @param FirstEntry A pointer to a node in a linked list.\r
2833 @param SecondEntry A pointer to the node to locate.\r
2834\r
2835 @retval TRUE SecondEntry is in the same doubly-linked list as FirstEntry.\r
2836 @retval FALSE SecondEntry isn't in the same doubly-linked list as FirstEntry,\r
2837 or FirstEntry is invalid.\r
2838\r
2839**/\r
2840BOOLEAN\r
2841EFIAPI\r
2842IsNodeInList (\r
2843 IN CONST LIST_ENTRY *FirstEntry,\r
2844 IN CONST LIST_ENTRY *SecondEntry\r
2845 );\r
2846\r
2847\r
ac644614 2848/**\r
2849 Initializes the head node of a doubly linked list, and returns the pointer to\r
2850 the head node of the doubly linked list.\r
2851\r
2852 Initializes the forward and backward links of a new linked list. After\r
2853 initializing a linked list with this function, the other linked list\r
2854 functions may be used to add and remove nodes from the linked list. It is up\r
2855 to the caller of this function to allocate the memory for ListHead.\r
2856\r
2857 If ListHead is NULL, then ASSERT().\r
2858\r
2859 @param ListHead A pointer to the head node of a new doubly linked list.\r
2860\r
2861 @return ListHead\r
2862\r
2863**/\r
2864LIST_ENTRY *\r
2865EFIAPI\r
2866InitializeListHead (\r
aa0583c7 2867 IN OUT LIST_ENTRY *ListHead\r
ac644614 2868 );\r
2869\r
2870\r
2871/**\r
2872 Adds a node to the beginning of a doubly linked list, and returns the pointer\r
2873 to the head node of the doubly linked list.\r
2874\r
2875 Adds the node Entry at the beginning of the doubly linked list denoted by\r
2876 ListHead, and returns ListHead.\r
2877\r
2878 If ListHead is NULL, then ASSERT().\r
2879 If Entry is NULL, then ASSERT().\r
17f695ed 2880 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
2881 InitializeListHead(), then ASSERT().\r
a71865b1 2882 If PcdMaximumLinkedListLength is not zero, and prior to insertion the number\r
ac644614 2883 of nodes in ListHead, including the ListHead node, is greater than or\r
2884 equal to PcdMaximumLinkedListLength, then ASSERT().\r
2885\r
2886 @param ListHead A pointer to the head node of a doubly linked list.\r
2887 @param Entry A pointer to a node that is to be inserted at the beginning\r
2888 of a doubly linked list.\r
2889\r
2890 @return ListHead\r
2891\r
2892**/\r
2893LIST_ENTRY *\r
2894EFIAPI\r
2895InsertHeadList (\r
aa0583c7 2896 IN OUT LIST_ENTRY *ListHead,\r
2897 IN OUT LIST_ENTRY *Entry\r
ac644614 2898 );\r
2899\r
2900\r
2901/**\r
2902 Adds a node to the end of a doubly linked list, and returns the pointer to\r
2903 the head node of the doubly linked list.\r
2904\r
2905 Adds the node Entry to the end of the doubly linked list denoted by ListHead,\r
2906 and returns ListHead.\r
2907\r
2908 If ListHead is NULL, then ASSERT().\r
2909 If Entry is NULL, then ASSERT().\r
9095d37b 2910 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
17f695ed 2911 InitializeListHead(), then ASSERT().\r
a71865b1 2912 If PcdMaximumLinkedListLength is not zero, and prior to insertion the number\r
ac644614 2913 of nodes in ListHead, including the ListHead node, is greater than or\r
2914 equal to PcdMaximumLinkedListLength, then ASSERT().\r
2915\r
2916 @param ListHead A pointer to the head node of a doubly linked list.\r
2917 @param Entry A pointer to a node that is to be added at the end of the\r
2918 doubly linked list.\r
2919\r
2920 @return ListHead\r
2921\r
2922**/\r
2923LIST_ENTRY *\r
2924EFIAPI\r
2925InsertTailList (\r
aa0583c7 2926 IN OUT LIST_ENTRY *ListHead,\r
2927 IN OUT LIST_ENTRY *Entry\r
ac644614 2928 );\r
2929\r
2930\r
2931/**\r
2932 Retrieves the first node of a doubly linked list.\r
2933\r
9095d37b 2934 Returns the first node of a doubly linked list. List must have been\r
17f695ed 2935 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
2936 If List is empty, then List is returned.\r
ac644614 2937\r
2938 If List is NULL, then ASSERT().\r
9095d37b 2939 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
17f695ed 2940 InitializeListHead(), then ASSERT().\r
a71865b1 2941 If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
ac644614 2942 in List, including the List node, is greater than or equal to\r
2943 PcdMaximumLinkedListLength, then ASSERT().\r
2944\r
2945 @param List A pointer to the head node of a doubly linked list.\r
2946\r
2947 @return The first node of a doubly linked list.\r
e01a125f 2948 @retval List The list is empty.\r
ac644614 2949\r
2950**/\r
2951LIST_ENTRY *\r
2952EFIAPI\r
2953GetFirstNode (\r
2954 IN CONST LIST_ENTRY *List\r
2955 );\r
2956\r
2957\r
2958/**\r
2959 Retrieves the next node of a doubly linked list.\r
2960\r
9095d37b 2961 Returns the node of a doubly linked list that follows Node.\r
17f695ed 2962 List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()\r
2963 or InitializeListHead(). If List is empty, then List is returned.\r
ac644614 2964\r
2965 If List is NULL, then ASSERT().\r
2966 If Node is NULL, then ASSERT().\r
9095d37b 2967 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
17f695ed 2968 InitializeListHead(), then ASSERT().\r
a71865b1
LG
2969 If PcdMaximumLinkedListLength is not zero, and List contains more than\r
2970 PcdMaximumLinkedListLength nodes, then ASSERT().\r
1081f624 2971 If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
ac644614 2972\r
2973 @param List A pointer to the head node of a doubly linked list.\r
2974 @param Node A pointer to a node in the doubly linked list.\r
2975\r
af2dc6a7 2976 @return The pointer to the next node if one exists. Otherwise List is returned.\r
ac644614 2977\r
2978**/\r
2979LIST_ENTRY *\r
2980EFIAPI\r
2981GetNextNode (\r
2982 IN CONST LIST_ENTRY *List,\r
2983 IN CONST LIST_ENTRY *Node\r
2984 );\r
2985\r
9095d37b 2986\r
cbca8de5 2987/**\r
2988 Retrieves the previous node of a doubly linked list.\r
9095d37b
LG
2989\r
2990 Returns the node of a doubly linked list that precedes Node.\r
cbca8de5 2991 List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()\r
2992 or InitializeListHead(). If List is empty, then List is returned.\r
9095d37b 2993\r
cbca8de5 2994 If List is NULL, then ASSERT().\r
2995 If Node is NULL, then ASSERT().\r
9095d37b 2996 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
cbca8de5 2997 InitializeListHead(), then ASSERT().\r
a71865b1
LG
2998 If PcdMaximumLinkedListLength is not zero, and List contains more than\r
2999 PcdMaximumLinkedListLength nodes, then ASSERT().\r
cbca8de5 3000 If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
9095d37b 3001\r
cbca8de5 3002 @param List A pointer to the head node of a doubly linked list.\r
3003 @param Node A pointer to a node in the doubly linked list.\r
9095d37b 3004\r
af2dc6a7 3005 @return The pointer to the previous node if one exists. Otherwise List is returned.\r
9095d37b 3006\r
cbca8de5 3007**/\r
3008LIST_ENTRY *\r
3009EFIAPI\r
3010GetPreviousNode (\r
3011 IN CONST LIST_ENTRY *List,\r
3012 IN CONST LIST_ENTRY *Node\r
3013 );\r
ac644614 3014\r
9095d37b 3015\r
ac644614 3016/**\r
3017 Checks to see if a doubly linked list is empty or not.\r
3018\r
3019 Checks to see if the doubly linked list is empty. If the linked list contains\r
3020 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.\r
3021\r
3022 If ListHead is NULL, then ASSERT().\r
9095d37b 3023 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
17f695ed 3024 InitializeListHead(), then ASSERT().\r
a71865b1 3025 If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
ac644614 3026 in List, including the List node, is greater than or equal to\r
3027 PcdMaximumLinkedListLength, then ASSERT().\r
3028\r
3029 @param ListHead A pointer to the head node of a doubly linked list.\r
3030\r
3031 @retval TRUE The linked list is empty.\r
3032 @retval FALSE The linked list is not empty.\r
3033\r
3034**/\r
3035BOOLEAN\r
3036EFIAPI\r
3037IsListEmpty (\r
3038 IN CONST LIST_ENTRY *ListHead\r
3039 );\r
3040\r
3041\r
3042/**\r
aa0583c7 3043 Determines if a node in a doubly linked list is the head node of a the same\r
3044 doubly linked list. This function is typically used to terminate a loop that\r
3045 traverses all the nodes in a doubly linked list starting with the head node.\r
ac644614 3046\r
aa0583c7 3047 Returns TRUE if Node is equal to List. Returns FALSE if Node is one of the\r
3048 nodes in the doubly linked list specified by List. List must have been\r
17f695ed 3049 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
ac644614 3050\r
3051 If List is NULL, then ASSERT().\r
3052 If Node is NULL, then ASSERT().\r
9095d37b 3053 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(),\r
17f695ed 3054 then ASSERT().\r
a71865b1 3055 If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
ac644614 3056 in List, including the List node, is greater than or equal to\r
3057 PcdMaximumLinkedListLength, then ASSERT().\r
9095d37b 3058 If PcdVerifyNodeInList is TRUE and Node is not a node in List the and Node is not equal\r
1081f624 3059 to List, then ASSERT().\r
ac644614 3060\r
3061 @param List A pointer to the head node of a doubly linked list.\r
3062 @param Node A pointer to a node in the doubly linked list.\r
3063\r
1955808d
LG
3064 @retval TRUE Node is the head of the doubly-linked list pointed by List.\r
3065 @retval FALSE Node is not the head of the doubly-linked list pointed by List.\r
ac644614 3066\r
3067**/\r
3068BOOLEAN\r
3069EFIAPI\r
3070IsNull (\r
3071 IN CONST LIST_ENTRY *List,\r
3072 IN CONST LIST_ENTRY *Node\r
3073 );\r
3074\r
3075\r
3076/**\r
3077 Determines if a node the last node in a doubly linked list.\r
3078\r
3079 Returns TRUE if Node is the last node in the doubly linked list specified by\r
3080 List. Otherwise, FALSE is returned. List must have been initialized with\r
17f695ed 3081 INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
ac644614 3082\r
3083 If List is NULL, then ASSERT().\r
3084 If Node is NULL, then ASSERT().\r
17f695ed 3085 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
3086 InitializeListHead(), then ASSERT().\r
a71865b1 3087 If PcdMaximumLinkedListLength is not zero, and the number of nodes\r
ac644614 3088 in List, including the List node, is greater than or equal to\r
3089 PcdMaximumLinkedListLength, then ASSERT().\r
1081f624 3090 If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
ac644614 3091\r
3092 @param List A pointer to the head node of a doubly linked list.\r
3093 @param Node A pointer to a node in the doubly linked list.\r
3094\r
3095 @retval TRUE Node is the last node in the linked list.\r
3096 @retval FALSE Node is not the last node in the linked list.\r
3097\r
3098**/\r
3099BOOLEAN\r
3100EFIAPI\r
3101IsNodeAtEnd (\r
3102 IN CONST LIST_ENTRY *List,\r
3103 IN CONST LIST_ENTRY *Node\r
3104 );\r
3105\r
3106\r
3107/**\r
3108 Swaps the location of two nodes in a doubly linked list, and returns the\r
3109 first node after the swap.\r
3110\r
3111 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.\r
3112 Otherwise, the location of the FirstEntry node is swapped with the location\r
3113 of the SecondEntry node in a doubly linked list. SecondEntry must be in the\r
3114 same double linked list as FirstEntry and that double linked list must have\r
9095d37b 3115 been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
17f695ed 3116 SecondEntry is returned after the nodes are swapped.\r
ac644614 3117\r
3118 If FirstEntry is NULL, then ASSERT().\r
3119 If SecondEntry is NULL, then ASSERT().\r
9095d37b 3120 If PcdVerifyNodeInList is TRUE and SecondEntry and FirstEntry are not in the\r
1081f624 3121 same linked list, then ASSERT().\r
ac644614 3122 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r
3123 linked list containing the FirstEntry and SecondEntry nodes, including\r
3124 the FirstEntry and SecondEntry nodes, is greater than or equal to\r
3125 PcdMaximumLinkedListLength, then ASSERT().\r
3126\r
3127 @param FirstEntry A pointer to a node in a linked list.\r
3128 @param SecondEntry A pointer to another node in the same linked list.\r
9095d37b 3129\r
9aa049d9 3130 @return SecondEntry.\r
ac644614 3131\r
3132**/\r
3133LIST_ENTRY *\r
3134EFIAPI\r
3135SwapListEntries (\r
aa0583c7 3136 IN OUT LIST_ENTRY *FirstEntry,\r
3137 IN OUT LIST_ENTRY *SecondEntry\r
ac644614 3138 );\r
3139\r
3140\r
3141/**\r
3142 Removes a node from a doubly linked list, and returns the node that follows\r
3143 the removed node.\r
3144\r
3145 Removes the node Entry from a doubly linked list. It is up to the caller of\r
3146 this function to release the memory used by this node if that is required. On\r
3147 exit, the node following Entry in the doubly linked list is returned. If\r
3148 Entry is the only node in the linked list, then the head node of the linked\r
3149 list is returned.\r
3150\r
3151 If Entry is NULL, then ASSERT().\r
3152 If Entry is the head node of an empty list, then ASSERT().\r
3153 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r
3154 linked list containing Entry, including the Entry node, is greater than\r
3155 or equal to PcdMaximumLinkedListLength, then ASSERT().\r
3156\r
9aa049d9 3157 @param Entry A pointer to a node in a linked list.\r
ac644614 3158\r
9aa049d9 3159 @return Entry.\r
ac644614 3160\r
3161**/\r
3162LIST_ENTRY *\r
3163EFIAPI\r
3164RemoveEntryList (\r
3165 IN CONST LIST_ENTRY *Entry\r
3166 );\r
3167\r
3168//\r
3169// Math Services\r
3170//\r
3171\r
3172/**\r
3173 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled\r
3174 with zeros. The shifted value is returned.\r
3175\r
3176 This function shifts the 64-bit value Operand to the left by Count bits. The\r
3177 low Count bits are set to zero. The shifted value is returned.\r
3178\r
3179 If Count is greater than 63, then ASSERT().\r
3180\r
3181 @param Operand The 64-bit operand to shift left.\r
3182 @param Count The number of bits to shift left.\r
3183\r
9aa049d9 3184 @return Operand << Count.\r
ac644614 3185\r
3186**/\r
3187UINT64\r
3188EFIAPI\r
3189LShiftU64 (\r
3190 IN UINT64 Operand,\r
3191 IN UINTN Count\r
3192 );\r
3193\r
3194\r
3195/**\r
3196 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are\r
3197 filled with zeros. The shifted value is returned.\r
3198\r
3199 This function shifts the 64-bit value Operand to the right by Count bits. The\r
3200 high Count bits are set to zero. The shifted value is returned.\r
3201\r
3202 If Count is greater than 63, then ASSERT().\r
3203\r
3204 @param Operand The 64-bit operand to shift right.\r
3205 @param Count The number of bits to shift right.\r
3206\r
3207 @return Operand >> Count\r
3208\r
3209**/\r
3210UINT64\r
3211EFIAPI\r
3212RShiftU64 (\r
3213 IN UINT64 Operand,\r
3214 IN UINTN Count\r
3215 );\r
3216\r
3217\r
3218/**\r
3219 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled\r
3220 with original integer's bit 63. The shifted value is returned.\r
3221\r
3222 This function shifts the 64-bit value Operand to the right by Count bits. The\r
3223 high Count bits are set to bit 63 of Operand. The shifted value is returned.\r
3224\r
3225 If Count is greater than 63, then ASSERT().\r
3226\r
3227 @param Operand The 64-bit operand to shift right.\r
3228 @param Count The number of bits to shift right.\r
3229\r
3230 @return Operand >> Count\r
3231\r
3232**/\r
3233UINT64\r
3234EFIAPI\r
3235ARShiftU64 (\r
3236 IN UINT64 Operand,\r
3237 IN UINTN Count\r
3238 );\r
3239\r
3240\r
3241/**\r
3242 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits\r
3243 with the high bits that were rotated.\r
3244\r
3245 This function rotates the 32-bit value Operand to the left by Count bits. The\r
3246 low Count bits are fill with the high Count bits of Operand. The rotated\r
3247 value is returned.\r
3248\r
3249 If Count is greater than 31, then ASSERT().\r
3250\r
3251 @param Operand The 32-bit operand to rotate left.\r
3252 @param Count The number of bits to rotate left.\r
3253\r
17f695ed 3254 @return Operand << Count\r
ac644614 3255\r
3256**/\r
3257UINT32\r
3258EFIAPI\r
3259LRotU32 (\r
3260 IN UINT32 Operand,\r
3261 IN UINTN Count\r
3262 );\r
3263\r
3264\r
3265/**\r
3266 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits\r
3267 with the low bits that were rotated.\r
3268\r
3269 This function rotates the 32-bit value Operand to the right by Count bits.\r
3270 The high Count bits are fill with the low Count bits of Operand. The rotated\r
3271 value is returned.\r
3272\r
3273 If Count is greater than 31, then ASSERT().\r
3274\r
3275 @param Operand The 32-bit operand to rotate right.\r
3276 @param Count The number of bits to rotate right.\r
3277\r
2fe241a2 3278 @return Operand >> Count\r
ac644614 3279\r
3280**/\r
3281UINT32\r
3282EFIAPI\r
3283RRotU32 (\r
3284 IN UINT32 Operand,\r
3285 IN UINTN Count\r
3286 );\r
3287\r
3288\r
3289/**\r
3290 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits\r
3291 with the high bits that were rotated.\r
3292\r
3293 This function rotates the 64-bit value Operand to the left by Count bits. The\r
3294 low Count bits are fill with the high Count bits of Operand. The rotated\r
3295 value is returned.\r
3296\r
3297 If Count is greater than 63, then ASSERT().\r
3298\r
3299 @param Operand The 64-bit operand to rotate left.\r
3300 @param Count The number of bits to rotate left.\r
3301\r
17f695ed 3302 @return Operand << Count\r
ac644614 3303\r
3304**/\r
3305UINT64\r
3306EFIAPI\r
3307LRotU64 (\r
3308 IN UINT64 Operand,\r
3309 IN UINTN Count\r
3310 );\r
3311\r
3312\r
3313/**\r
3314 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits\r
3315 with the high low bits that were rotated.\r
3316\r
3317 This function rotates the 64-bit value Operand to the right by Count bits.\r
3318 The high Count bits are fill with the low Count bits of Operand. The rotated\r
3319 value is returned.\r
3320\r
3321 If Count is greater than 63, then ASSERT().\r
3322\r
3323 @param Operand The 64-bit operand to rotate right.\r
3324 @param Count The number of bits to rotate right.\r
3325\r
17f695ed 3326 @return Operand >> Count\r
ac644614 3327\r
3328**/\r
3329UINT64\r
3330EFIAPI\r
3331RRotU64 (\r
3332 IN UINT64 Operand,\r
3333 IN UINTN Count\r
3334 );\r
3335\r
3336\r
3337/**\r
3338 Returns the bit position of the lowest bit set in a 32-bit value.\r
3339\r
3340 This function computes the bit position of the lowest bit set in the 32-bit\r
3341 value specified by Operand. If Operand is zero, then -1 is returned.\r
3342 Otherwise, a value between 0 and 31 is returned.\r
3343\r
3344 @param Operand The 32-bit operand to evaluate.\r
3345\r
9aa049d9 3346 @retval 0..31 The lowest bit set in Operand was found.\r
17f695ed 3347 @retval -1 Operand is zero.\r
ac644614 3348\r
3349**/\r
3350INTN\r
3351EFIAPI\r
3352LowBitSet32 (\r
3353 IN UINT32 Operand\r
3354 );\r
3355\r
3356\r
3357/**\r
3358 Returns the bit position of the lowest bit set in a 64-bit value.\r
3359\r
3360 This function computes the bit position of the lowest bit set in the 64-bit\r
3361 value specified by Operand. If Operand is zero, then -1 is returned.\r
3362 Otherwise, a value between 0 and 63 is returned.\r
3363\r
3364 @param Operand The 64-bit operand to evaluate.\r
3365\r
9aa049d9 3366 @retval 0..63 The lowest bit set in Operand was found.\r
17f695ed 3367 @retval -1 Operand is zero.\r
3368\r
ac644614 3369\r
3370**/\r
3371INTN\r
3372EFIAPI\r
3373LowBitSet64 (\r
3374 IN UINT64 Operand\r
3375 );\r
3376\r
3377\r
3378/**\r
3379 Returns the bit position of the highest bit set in a 32-bit value. Equivalent\r
3380 to log2(x).\r
3381\r
3382 This function computes the bit position of the highest bit set in the 32-bit\r
3383 value specified by Operand. If Operand is zero, then -1 is returned.\r
3384 Otherwise, a value between 0 and 31 is returned.\r
3385\r
3386 @param Operand The 32-bit operand to evaluate.\r
3387\r
9aa049d9 3388 @retval 0..31 Position of the highest bit set in Operand if found.\r
17f695ed 3389 @retval -1 Operand is zero.\r
ac644614 3390\r
3391**/\r
3392INTN\r
3393EFIAPI\r
3394HighBitSet32 (\r
3395 IN UINT32 Operand\r
3396 );\r
3397\r
3398\r
3399/**\r
3400 Returns the bit position of the highest bit set in a 64-bit value. Equivalent\r
3401 to log2(x).\r
3402\r
3403 This function computes the bit position of the highest bit set in the 64-bit\r
3404 value specified by Operand. If Operand is zero, then -1 is returned.\r
3405 Otherwise, a value between 0 and 63 is returned.\r
3406\r
3407 @param Operand The 64-bit operand to evaluate.\r
3408\r
9aa049d9 3409 @retval 0..63 Position of the highest bit set in Operand if found.\r
17f695ed 3410 @retval -1 Operand is zero.\r
ac644614 3411\r
3412**/\r
3413INTN\r
3414EFIAPI\r
3415HighBitSet64 (\r
3416 IN UINT64 Operand\r
3417 );\r
3418\r
3419\r
3420/**\r
3421 Returns the value of the highest bit set in a 32-bit value. Equivalent to\r
17f695ed 3422 1 << log2(x).\r
ac644614 3423\r
3424 This function computes the value of the highest bit set in the 32-bit value\r
3425 specified by Operand. If Operand is zero, then zero is returned.\r
3426\r
3427 @param Operand The 32-bit operand to evaluate.\r
3428\r
3429 @return 1 << HighBitSet32(Operand)\r
3430 @retval 0 Operand is zero.\r
3431\r
3432**/\r
3433UINT32\r
3434EFIAPI\r
3435GetPowerOfTwo32 (\r
3436 IN UINT32 Operand\r
3437 );\r
3438\r
3439\r
3440/**\r
3441 Returns the value of the highest bit set in a 64-bit value. Equivalent to\r
17f695ed 3442 1 << log2(x).\r
ac644614 3443\r
3444 This function computes the value of the highest bit set in the 64-bit value\r
3445 specified by Operand. If Operand is zero, then zero is returned.\r
3446\r
3447 @param Operand The 64-bit operand to evaluate.\r
3448\r
3449 @return 1 << HighBitSet64(Operand)\r
3450 @retval 0 Operand is zero.\r
3451\r
3452**/\r
3453UINT64\r
3454EFIAPI\r
3455GetPowerOfTwo64 (\r
3456 IN UINT64 Operand\r
3457 );\r
3458\r
3459\r
3460/**\r
af2dc6a7 3461 Switches the endianness of a 16-bit integer.\r
ac644614 3462\r
3463 This function swaps the bytes in a 16-bit unsigned value to switch the value\r
3464 from little endian to big endian or vice versa. The byte swapped value is\r
3465 returned.\r
3466\r
2a53dabf 3467 @param Value A 16-bit unsigned value.\r
ac644614 3468\r
efb23117 3469 @return The byte swapped Value.\r
ac644614 3470\r
3471**/\r
3472UINT16\r
3473EFIAPI\r
3474SwapBytes16 (\r
3475 IN UINT16 Value\r
3476 );\r
3477\r
3478\r
3479/**\r
af2dc6a7 3480 Switches the endianness of a 32-bit integer.\r
ac644614 3481\r
3482 This function swaps the bytes in a 32-bit unsigned value to switch the value\r
3483 from little endian to big endian or vice versa. The byte swapped value is\r
3484 returned.\r
3485\r
2a53dabf 3486 @param Value A 32-bit unsigned value.\r
ac644614 3487\r
efb23117 3488 @return The byte swapped Value.\r
ac644614 3489\r
3490**/\r
3491UINT32\r
3492EFIAPI\r
3493SwapBytes32 (\r
3494 IN UINT32 Value\r
3495 );\r
3496\r
3497\r
3498/**\r
af2dc6a7 3499 Switches the endianness of a 64-bit integer.\r
ac644614 3500\r
3501 This function swaps the bytes in a 64-bit unsigned value to switch the value\r
3502 from little endian to big endian or vice versa. The byte swapped value is\r
3503 returned.\r
3504\r
2a53dabf 3505 @param Value A 64-bit unsigned value.\r
ac644614 3506\r
efb23117 3507 @return The byte swapped Value.\r
ac644614 3508\r
3509**/\r
3510UINT64\r
3511EFIAPI\r
3512SwapBytes64 (\r
3513 IN UINT64 Value\r
3514 );\r
3515\r
3516\r
3517/**\r
3518 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and\r
3519 generates a 64-bit unsigned result.\r
3520\r
3521 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit\r
3522 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
3523 bit unsigned result is returned.\r
3524\r
ac644614 3525 @param Multiplicand A 64-bit unsigned value.\r
3526 @param Multiplier A 32-bit unsigned value.\r
3527\r
3528 @return Multiplicand * Multiplier\r
3529\r
3530**/\r
3531UINT64\r
3532EFIAPI\r
3533MultU64x32 (\r
3534 IN UINT64 Multiplicand,\r
3535 IN UINT32 Multiplier\r
3536 );\r
3537\r
3538\r
3539/**\r
3540 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and\r
3541 generates a 64-bit unsigned result.\r
3542\r
3543 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit\r
3544 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
3545 bit unsigned result is returned.\r
3546\r
ac644614 3547 @param Multiplicand A 64-bit unsigned value.\r
3548 @param Multiplier A 64-bit unsigned value.\r
3549\r
af2dc6a7 3550 @return Multiplicand * Multiplier.\r
ac644614 3551\r
3552**/\r
3553UINT64\r
3554EFIAPI\r
3555MultU64x64 (\r
3556 IN UINT64 Multiplicand,\r
3557 IN UINT64 Multiplier\r
3558 );\r
3559\r
3560\r
3561/**\r
3562 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a\r
3563 64-bit signed result.\r
3564\r
3565 This function multiples the 64-bit signed value Multiplicand by the 64-bit\r
3566 signed value Multiplier and generates a 64-bit signed result. This 64-bit\r
3567 signed result is returned.\r
3568\r
ac644614 3569 @param Multiplicand A 64-bit signed value.\r
3570 @param Multiplier A 64-bit signed value.\r
3571\r
3572 @return Multiplicand * Multiplier\r
3573\r
3574**/\r
3575INT64\r
3576EFIAPI\r
3577MultS64x64 (\r
3578 IN INT64 Multiplicand,\r
3579 IN INT64 Multiplier\r
3580 );\r
3581\r
3582\r
3583/**\r
3584 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
3585 a 64-bit unsigned result.\r
3586\r
3587 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
3588 unsigned value Divisor and generates a 64-bit unsigned quotient. This\r
3589 function returns the 64-bit unsigned quotient.\r
3590\r
3591 If Divisor is 0, then ASSERT().\r
3592\r
3593 @param Dividend A 64-bit unsigned value.\r
3594 @param Divisor A 32-bit unsigned value.\r
3595\r
af2dc6a7 3596 @return Dividend / Divisor.\r
ac644614 3597\r
3598**/\r
3599UINT64\r
3600EFIAPI\r
3601DivU64x32 (\r
3602 IN UINT64 Dividend,\r
3603 IN UINT32 Divisor\r
3604 );\r
3605\r
3606\r
3607/**\r
3608 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
3609 a 32-bit unsigned remainder.\r
3610\r
3611 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
3612 unsigned value Divisor and generates a 32-bit remainder. This function\r
3613 returns the 32-bit unsigned remainder.\r
3614\r
3615 If Divisor is 0, then ASSERT().\r
3616\r
3617 @param Dividend A 64-bit unsigned value.\r
3618 @param Divisor A 32-bit unsigned value.\r
3619\r
af2dc6a7 3620 @return Dividend % Divisor.\r
ac644614 3621\r
3622**/\r
3623UINT32\r
3624EFIAPI\r
3625ModU64x32 (\r
3626 IN UINT64 Dividend,\r
3627 IN UINT32 Divisor\r
3628 );\r
3629\r
3630\r
3631/**\r
3632 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
3633 a 64-bit unsigned result and an optional 32-bit unsigned remainder.\r
3634\r
3635 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
3636 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r
3637 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.\r
3638 This function returns the 64-bit unsigned quotient.\r
3639\r
3640 If Divisor is 0, then ASSERT().\r
3641\r
3642 @param Dividend A 64-bit unsigned value.\r
3643 @param Divisor A 32-bit unsigned value.\r
3644 @param Remainder A pointer to a 32-bit unsigned value. This parameter is\r
3645 optional and may be NULL.\r
3646\r
af2dc6a7 3647 @return Dividend / Divisor.\r
ac644614 3648\r
3649**/\r
3650UINT64\r
3651EFIAPI\r
3652DivU64x32Remainder (\r
3653 IN UINT64 Dividend,\r
3654 IN UINT32 Divisor,\r
3655 OUT UINT32 *Remainder OPTIONAL\r
3656 );\r
3657\r
3658\r
3659/**\r
3660 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates\r
3661 a 64-bit unsigned result and an optional 64-bit unsigned remainder.\r
3662\r
3663 This function divides the 64-bit unsigned value Dividend by the 64-bit\r
3664 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r
3665 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.\r
3666 This function returns the 64-bit unsigned quotient.\r
3667\r
3668 If Divisor is 0, then ASSERT().\r
3669\r
3670 @param Dividend A 64-bit unsigned value.\r
3671 @param Divisor A 64-bit unsigned value.\r
3672 @param Remainder A pointer to a 64-bit unsigned value. This parameter is\r
3673 optional and may be NULL.\r
3674\r
af2dc6a7 3675 @return Dividend / Divisor.\r
ac644614 3676\r
3677**/\r
3678UINT64\r
3679EFIAPI\r
3680DivU64x64Remainder (\r
3681 IN UINT64 Dividend,\r
3682 IN UINT64 Divisor,\r
3683 OUT UINT64 *Remainder OPTIONAL\r
3684 );\r
3685\r
3686\r
3687/**\r
3688 Divides a 64-bit signed integer by a 64-bit signed integer and generates a\r
3689 64-bit signed result and a optional 64-bit signed remainder.\r
3690\r
3691 This function divides the 64-bit signed value Dividend by the 64-bit signed\r
3692 value Divisor and generates a 64-bit signed quotient. If Remainder is not\r
3693 NULL, then the 64-bit signed remainder is returned in Remainder. This\r
3694 function returns the 64-bit signed quotient.\r
3695\r
9aa049d9 3696 It is the caller's responsibility to not call this function with a Divisor of 0.\r
9095d37b 3697 If Divisor is 0, then the quotient and remainder should be assumed to be\r
17f695ed 3698 the largest negative integer.\r
3699\r
ac644614 3700 If Divisor is 0, then ASSERT().\r
3701\r
3702 @param Dividend A 64-bit signed value.\r
3703 @param Divisor A 64-bit signed value.\r
3704 @param Remainder A pointer to a 64-bit signed value. This parameter is\r
3705 optional and may be NULL.\r
3706\r
af2dc6a7 3707 @return Dividend / Divisor.\r
ac644614 3708\r
3709**/\r
3710INT64\r
3711EFIAPI\r
3712DivS64x64Remainder (\r
3713 IN INT64 Dividend,\r
3714 IN INT64 Divisor,\r
3715 OUT INT64 *Remainder OPTIONAL\r
3716 );\r
3717\r
3718\r
3719/**\r
3720 Reads a 16-bit value from memory that may be unaligned.\r
3721\r
3722 This function returns the 16-bit value pointed to by Buffer. The function\r
3723 guarantees that the read operation does not produce an alignment fault.\r
3724\r
3725 If the Buffer is NULL, then ASSERT().\r
3726\r
af2dc6a7 3727 @param Buffer The pointer to a 16-bit value that may be unaligned.\r
ac644614 3728\r
5385a579 3729 @return The 16-bit value read from Buffer.\r
ac644614 3730\r
3731**/\r
3732UINT16\r
3733EFIAPI\r
3734ReadUnaligned16 (\r
5385a579 3735 IN CONST UINT16 *Buffer\r
ac644614 3736 );\r
3737\r
3738\r
3739/**\r
3740 Writes a 16-bit value to memory that may be unaligned.\r
3741\r
3742 This function writes the 16-bit value specified by Value to Buffer. Value is\r
3743 returned. The function guarantees that the write operation does not produce\r
3744 an alignment fault.\r
3745\r
3746 If the Buffer is NULL, then ASSERT().\r
3747\r
af2dc6a7 3748 @param Buffer The pointer to a 16-bit value that may be unaligned.\r
ac644614 3749 @param Value 16-bit value to write to Buffer.\r
3750\r
5385a579 3751 @return The 16-bit value to write to Buffer.\r
ac644614 3752\r
3753**/\r
3754UINT16\r
3755EFIAPI\r
3756WriteUnaligned16 (\r
5385a579 3757 OUT UINT16 *Buffer,\r
3758 IN UINT16 Value\r
ac644614 3759 );\r
3760\r
3761\r
3762/**\r
3763 Reads a 24-bit value from memory that may be unaligned.\r
3764\r
3765 This function returns the 24-bit value pointed to by Buffer. The function\r
3766 guarantees that the read operation does not produce an alignment fault.\r
3767\r
3768 If the Buffer is NULL, then ASSERT().\r
3769\r
af2dc6a7 3770 @param Buffer The pointer to a 24-bit value that may be unaligned.\r
ac644614 3771\r
5385a579 3772 @return The 24-bit value read from Buffer.\r
ac644614 3773\r
3774**/\r
3775UINT32\r
3776EFIAPI\r
3777ReadUnaligned24 (\r
5385a579 3778 IN CONST UINT32 *Buffer\r
ac644614 3779 );\r
3780\r
3781\r
3782/**\r
3783 Writes a 24-bit value to memory that may be unaligned.\r
3784\r
3785 This function writes the 24-bit value specified by Value to Buffer. Value is\r
3786 returned. The function guarantees that the write operation does not produce\r
3787 an alignment fault.\r
3788\r
3789 If the Buffer is NULL, then ASSERT().\r
3790\r
af2dc6a7 3791 @param Buffer The pointer to a 24-bit value that may be unaligned.\r
ac644614 3792 @param Value 24-bit value to write to Buffer.\r
3793\r
5385a579 3794 @return The 24-bit value to write to Buffer.\r
ac644614 3795\r
3796**/\r
3797UINT32\r
3798EFIAPI\r
3799WriteUnaligned24 (\r
5385a579 3800 OUT UINT32 *Buffer,\r
3801 IN UINT32 Value\r
ac644614 3802 );\r
3803\r
3804\r
3805/**\r
3806 Reads a 32-bit value from memory that may be unaligned.\r
3807\r
3808 This function returns the 32-bit value pointed to by Buffer. The function\r
3809 guarantees that the read operation does not produce an alignment fault.\r
3810\r
3811 If the Buffer is NULL, then ASSERT().\r
3812\r
af2dc6a7 3813 @param Buffer The pointer to a 32-bit value that may be unaligned.\r
ac644614 3814\r
5385a579 3815 @return The 32-bit value read from Buffer.\r
ac644614 3816\r
3817**/\r
3818UINT32\r
3819EFIAPI\r
3820ReadUnaligned32 (\r
5385a579 3821 IN CONST UINT32 *Buffer\r
ac644614 3822 );\r
3823\r
3824\r
3825/**\r
3826 Writes a 32-bit value to memory that may be unaligned.\r
3827\r
3828 This function writes the 32-bit value specified by Value to Buffer. Value is\r
3829 returned. The function guarantees that the write operation does not produce\r
3830 an alignment fault.\r
3831\r
3832 If the Buffer is NULL, then ASSERT().\r
3833\r
af2dc6a7 3834 @param Buffer The pointer to a 32-bit value that may be unaligned.\r
ac644614 3835 @param Value 32-bit value to write to Buffer.\r
3836\r
5385a579 3837 @return The 32-bit value to write to Buffer.\r
ac644614 3838\r
3839**/\r
3840UINT32\r
3841EFIAPI\r
3842WriteUnaligned32 (\r
5385a579 3843 OUT UINT32 *Buffer,\r
3844 IN UINT32 Value\r
ac644614 3845 );\r
3846\r
3847\r
3848/**\r
3849 Reads a 64-bit value from memory that may be unaligned.\r
3850\r
3851 This function returns the 64-bit value pointed to by Buffer. The function\r
3852 guarantees that the read operation does not produce an alignment fault.\r
3853\r
3854 If the Buffer is NULL, then ASSERT().\r
3855\r
af2dc6a7 3856 @param Buffer The pointer to a 64-bit value that may be unaligned.\r
ac644614 3857\r
5385a579 3858 @return The 64-bit value read from Buffer.\r
ac644614 3859\r
3860**/\r
3861UINT64\r
3862EFIAPI\r
3863ReadUnaligned64 (\r
5385a579 3864 IN CONST UINT64 *Buffer\r
ac644614 3865 );\r
3866\r
3867\r
3868/**\r
3869 Writes a 64-bit value to memory that may be unaligned.\r
3870\r
3871 This function writes the 64-bit value specified by Value to Buffer. Value is\r
3872 returned. The function guarantees that the write operation does not produce\r
3873 an alignment fault.\r
3874\r
3875 If the Buffer is NULL, then ASSERT().\r
3876\r
af2dc6a7 3877 @param Buffer The pointer to a 64-bit value that may be unaligned.\r
ac644614 3878 @param Value 64-bit value to write to Buffer.\r
3879\r
5385a579 3880 @return The 64-bit value to write to Buffer.\r
ac644614 3881\r
3882**/\r
3883UINT64\r
3884EFIAPI\r
3885WriteUnaligned64 (\r
5385a579 3886 OUT UINT64 *Buffer,\r
3887 IN UINT64 Value\r
ac644614 3888 );\r
3889\r
3890\r
3891//\r
3892// Bit Field Functions\r
3893//\r
3894\r
3895/**\r
3896 Returns a bit field from an 8-bit value.\r
3897\r
3898 Returns the bitfield specified by the StartBit and the EndBit from Operand.\r
3899\r
3900 If 8-bit operations are not supported, then ASSERT().\r
3901 If StartBit is greater than 7, then ASSERT().\r
3902 If EndBit is greater than 7, then ASSERT().\r
3903 If EndBit is less than StartBit, then ASSERT().\r
3904\r
3905 @param Operand Operand on which to perform the bitfield operation.\r
3906 @param StartBit The ordinal of the least significant bit in the bit field.\r
3907 Range 0..7.\r
3908 @param EndBit The ordinal of the most significant bit in the bit field.\r
3909 Range 0..7.\r
3910\r
3911 @return The bit field read.\r
3912\r
3913**/\r
3914UINT8\r
3915EFIAPI\r
3916BitFieldRead8 (\r
3917 IN UINT8 Operand,\r
3918 IN UINTN StartBit,\r
3919 IN UINTN EndBit\r
3920 );\r
3921\r
3922\r
3923/**\r
3924 Writes a bit field to an 8-bit value, and returns the result.\r
3925\r
3926 Writes Value to the bit field specified by the StartBit and the EndBit in\r
3927 Operand. All other bits in Operand are preserved. The new 8-bit value is\r
3928 returned.\r
3929\r
3930 If 8-bit operations are not supported, then ASSERT().\r
3931 If StartBit is greater than 7, then ASSERT().\r
3932 If EndBit is greater than 7, then ASSERT().\r
3933 If EndBit is less than StartBit, then ASSERT().\r
94952554 3934 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 3935\r
3936 @param Operand Operand on which to perform the bitfield operation.\r
3937 @param StartBit The ordinal of the least significant bit in the bit field.\r
3938 Range 0..7.\r
3939 @param EndBit The ordinal of the most significant bit in the bit field.\r
3940 Range 0..7.\r
3941 @param Value New value of the bit field.\r
3942\r
3943 @return The new 8-bit value.\r
3944\r
3945**/\r
3946UINT8\r
3947EFIAPI\r
3948BitFieldWrite8 (\r
3949 IN UINT8 Operand,\r
3950 IN UINTN StartBit,\r
3951 IN UINTN EndBit,\r
3952 IN UINT8 Value\r
3953 );\r
3954\r
3955\r
3956/**\r
3957 Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the\r
3958 result.\r
3959\r
62991af2 3960 Performs a bitwise OR between the bit field specified by StartBit\r
ac644614 3961 and EndBit in Operand and the value specified by OrData. All other bits in\r
3962 Operand are preserved. The new 8-bit value is returned.\r
3963\r
3964 If 8-bit operations are not supported, then ASSERT().\r
3965 If StartBit is greater than 7, then ASSERT().\r
3966 If EndBit is greater than 7, then ASSERT().\r
3967 If EndBit is less than StartBit, then ASSERT().\r
94952554 3968 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 3969\r
3970 @param Operand Operand on which to perform the bitfield operation.\r
3971 @param StartBit The ordinal of the least significant bit in the bit field.\r
3972 Range 0..7.\r
3973 @param EndBit The ordinal of the most significant bit in the bit field.\r
3974 Range 0..7.\r
3975 @param OrData The value to OR with the read value from the value\r
3976\r
3977 @return The new 8-bit value.\r
3978\r
3979**/\r
3980UINT8\r
3981EFIAPI\r
3982BitFieldOr8 (\r
3983 IN UINT8 Operand,\r
3984 IN UINTN StartBit,\r
3985 IN UINTN EndBit,\r
3986 IN UINT8 OrData\r
3987 );\r
3988\r
3989\r
3990/**\r
3991 Reads a bit field from an 8-bit value, performs a bitwise AND, and returns\r
3992 the result.\r
3993\r
3994 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
3995 in Operand and the value specified by AndData. All other bits in Operand are\r
3996 preserved. The new 8-bit value is returned.\r
3997\r
3998 If 8-bit operations are not supported, then ASSERT().\r
3999 If StartBit is greater than 7, then ASSERT().\r
4000 If EndBit is greater than 7, then ASSERT().\r
4001 If EndBit is less than StartBit, then ASSERT().\r
94952554 4002 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4003\r
4004 @param Operand Operand on which to perform the bitfield operation.\r
4005 @param StartBit The ordinal of the least significant bit in the bit field.\r
4006 Range 0..7.\r
4007 @param EndBit The ordinal of the most significant bit in the bit field.\r
4008 Range 0..7.\r
4009 @param AndData The value to AND with the read value from the value.\r
4010\r
4011 @return The new 8-bit value.\r
4012\r
4013**/\r
4014UINT8\r
4015EFIAPI\r
4016BitFieldAnd8 (\r
4017 IN UINT8 Operand,\r
4018 IN UINTN StartBit,\r
4019 IN UINTN EndBit,\r
4020 IN UINT8 AndData\r
4021 );\r
4022\r
4023\r
4024/**\r
4025 Reads a bit field from an 8-bit value, performs a bitwise AND followed by a\r
4026 bitwise OR, and returns the result.\r
4027\r
4028 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
9095d37b 4029 in Operand and the value specified by AndData, followed by a bitwise\r
62991af2 4030 OR with value specified by OrData. All other bits in Operand are\r
ac644614 4031 preserved. The new 8-bit value is returned.\r
4032\r
4033 If 8-bit operations are not supported, then ASSERT().\r
4034 If StartBit is greater than 7, then ASSERT().\r
4035 If EndBit is greater than 7, then ASSERT().\r
4036 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
4037 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
4038 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4039\r
4040 @param Operand Operand on which to perform the bitfield operation.\r
4041 @param StartBit The ordinal of the least significant bit in the bit field.\r
4042 Range 0..7.\r
4043 @param EndBit The ordinal of the most significant bit in the bit field.\r
4044 Range 0..7.\r
4045 @param AndData The value to AND with the read value from the value.\r
4046 @param OrData The value to OR with the result of the AND operation.\r
4047\r
4048 @return The new 8-bit value.\r
4049\r
4050**/\r
4051UINT8\r
4052EFIAPI\r
4053BitFieldAndThenOr8 (\r
4054 IN UINT8 Operand,\r
4055 IN UINTN StartBit,\r
4056 IN UINTN EndBit,\r
4057 IN UINT8 AndData,\r
4058 IN UINT8 OrData\r
4059 );\r
4060\r
4061\r
4062/**\r
4063 Returns a bit field from a 16-bit value.\r
4064\r
4065 Returns the bitfield specified by the StartBit and the EndBit from Operand.\r
4066\r
4067 If 16-bit operations are not supported, then ASSERT().\r
4068 If StartBit is greater than 15, then ASSERT().\r
4069 If EndBit is greater than 15, then ASSERT().\r
4070 If EndBit is less than StartBit, then ASSERT().\r
4071\r
4072 @param Operand Operand on which to perform the bitfield operation.\r
4073 @param StartBit The ordinal of the least significant bit in the bit field.\r
4074 Range 0..15.\r
4075 @param EndBit The ordinal of the most significant bit in the bit field.\r
4076 Range 0..15.\r
4077\r
4078 @return The bit field read.\r
4079\r
4080**/\r
4081UINT16\r
4082EFIAPI\r
4083BitFieldRead16 (\r
4084 IN UINT16 Operand,\r
4085 IN UINTN StartBit,\r
4086 IN UINTN EndBit\r
4087 );\r
4088\r
4089\r
4090/**\r
4091 Writes a bit field to a 16-bit value, and returns the result.\r
4092\r
4093 Writes Value to the bit field specified by the StartBit and the EndBit in\r
4094 Operand. All other bits in Operand are preserved. The new 16-bit value is\r
4095 returned.\r
4096\r
4097 If 16-bit operations are not supported, then ASSERT().\r
4098 If StartBit is greater than 15, then ASSERT().\r
4099 If EndBit is greater than 15, then ASSERT().\r
4100 If EndBit is less than StartBit, then ASSERT().\r
94952554 4101 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4102\r
4103 @param Operand Operand on which to perform the bitfield operation.\r
4104 @param StartBit The ordinal of the least significant bit in the bit field.\r
4105 Range 0..15.\r
4106 @param EndBit The ordinal of the most significant bit in the bit field.\r
4107 Range 0..15.\r
4108 @param Value New value of the bit field.\r
4109\r
4110 @return The new 16-bit value.\r
4111\r
4112**/\r
4113UINT16\r
4114EFIAPI\r
4115BitFieldWrite16 (\r
4116 IN UINT16 Operand,\r
4117 IN UINTN StartBit,\r
4118 IN UINTN EndBit,\r
4119 IN UINT16 Value\r
4120 );\r
4121\r
4122\r
4123/**\r
4124 Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the\r
4125 result.\r
4126\r
62991af2 4127 Performs a bitwise OR between the bit field specified by StartBit\r
ac644614 4128 and EndBit in Operand and the value specified by OrData. All other bits in\r
4129 Operand are preserved. The new 16-bit value is returned.\r
4130\r
4131 If 16-bit operations are not supported, then ASSERT().\r
4132 If StartBit is greater than 15, then ASSERT().\r
4133 If EndBit is greater than 15, then ASSERT().\r
4134 If EndBit is less than StartBit, then ASSERT().\r
94952554 4135 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4136\r
4137 @param Operand Operand on which to perform the bitfield operation.\r
4138 @param StartBit The ordinal of the least significant bit in the bit field.\r
4139 Range 0..15.\r
4140 @param EndBit The ordinal of the most significant bit in the bit field.\r
4141 Range 0..15.\r
4142 @param OrData The value to OR with the read value from the value\r
4143\r
4144 @return The new 16-bit value.\r
4145\r
4146**/\r
4147UINT16\r
4148EFIAPI\r
4149BitFieldOr16 (\r
4150 IN UINT16 Operand,\r
4151 IN UINTN StartBit,\r
4152 IN UINTN EndBit,\r
4153 IN UINT16 OrData\r
4154 );\r
4155\r
4156\r
4157/**\r
4158 Reads a bit field from a 16-bit value, performs a bitwise AND, and returns\r
4159 the result.\r
4160\r
4161 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
4162 in Operand and the value specified by AndData. All other bits in Operand are\r
4163 preserved. The new 16-bit value is returned.\r
4164\r
4165 If 16-bit operations are not supported, then ASSERT().\r
4166 If StartBit is greater than 15, then ASSERT().\r
4167 If EndBit is greater than 15, then ASSERT().\r
4168 If EndBit is less than StartBit, then ASSERT().\r
94952554 4169 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4170\r
4171 @param Operand Operand on which to perform the bitfield operation.\r
4172 @param StartBit The ordinal of the least significant bit in the bit field.\r
4173 Range 0..15.\r
4174 @param EndBit The ordinal of the most significant bit in the bit field.\r
4175 Range 0..15.\r
4176 @param AndData The value to AND with the read value from the value\r
4177\r
4178 @return The new 16-bit value.\r
4179\r
4180**/\r
4181UINT16\r
4182EFIAPI\r
4183BitFieldAnd16 (\r
4184 IN UINT16 Operand,\r
4185 IN UINTN StartBit,\r
4186 IN UINTN EndBit,\r
4187 IN UINT16 AndData\r
4188 );\r
4189\r
4190\r
4191/**\r
4192 Reads a bit field from a 16-bit value, performs a bitwise AND followed by a\r
4193 bitwise OR, and returns the result.\r
4194\r
4195 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
9095d37b 4196 in Operand and the value specified by AndData, followed by a bitwise\r
62991af2 4197 OR with value specified by OrData. All other bits in Operand are\r
ac644614 4198 preserved. The new 16-bit value is returned.\r
4199\r
4200 If 16-bit operations are not supported, then ASSERT().\r
4201 If StartBit is greater than 15, then ASSERT().\r
4202 If EndBit is greater than 15, then ASSERT().\r
4203 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
4204 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
4205 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4206\r
4207 @param Operand Operand on which to perform the bitfield operation.\r
4208 @param StartBit The ordinal of the least significant bit in the bit field.\r
4209 Range 0..15.\r
4210 @param EndBit The ordinal of the most significant bit in the bit field.\r
4211 Range 0..15.\r
4212 @param AndData The value to AND with the read value from the value.\r
4213 @param OrData The value to OR with the result of the AND operation.\r
4214\r
4215 @return The new 16-bit value.\r
4216\r
4217**/\r
4218UINT16\r
4219EFIAPI\r
4220BitFieldAndThenOr16 (\r
4221 IN UINT16 Operand,\r
4222 IN UINTN StartBit,\r
4223 IN UINTN EndBit,\r
4224 IN UINT16 AndData,\r
4225 IN UINT16 OrData\r
4226 );\r
4227\r
4228\r
4229/**\r
4230 Returns a bit field from a 32-bit value.\r
4231\r
4232 Returns the bitfield specified by the StartBit and the EndBit from Operand.\r
4233\r
4234 If 32-bit operations are not supported, then ASSERT().\r
4235 If StartBit is greater than 31, then ASSERT().\r
4236 If EndBit is greater than 31, then ASSERT().\r
4237 If EndBit is less than StartBit, then ASSERT().\r
4238\r
4239 @param Operand Operand on which to perform the bitfield operation.\r
4240 @param StartBit The ordinal of the least significant bit in the bit field.\r
4241 Range 0..31.\r
4242 @param EndBit The ordinal of the most significant bit in the bit field.\r
4243 Range 0..31.\r
4244\r
4245 @return The bit field read.\r
4246\r
4247**/\r
4248UINT32\r
4249EFIAPI\r
4250BitFieldRead32 (\r
4251 IN UINT32 Operand,\r
4252 IN UINTN StartBit,\r
4253 IN UINTN EndBit\r
4254 );\r
4255\r
4256\r
4257/**\r
4258 Writes a bit field to a 32-bit value, and returns the result.\r
4259\r
4260 Writes Value to the bit field specified by the StartBit and the EndBit in\r
4261 Operand. All other bits in Operand are preserved. The new 32-bit value is\r
4262 returned.\r
4263\r
4264 If 32-bit operations are not supported, then ASSERT().\r
4265 If StartBit is greater than 31, then ASSERT().\r
4266 If EndBit is greater than 31, then ASSERT().\r
4267 If EndBit is less than StartBit, then ASSERT().\r
94952554 4268 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4269\r
4270 @param Operand Operand on which to perform the bitfield operation.\r
4271 @param StartBit The ordinal of the least significant bit in the bit field.\r
4272 Range 0..31.\r
4273 @param EndBit The ordinal of the most significant bit in the bit field.\r
4274 Range 0..31.\r
4275 @param Value New value of the bit field.\r
4276\r
4277 @return The new 32-bit value.\r
4278\r
4279**/\r
4280UINT32\r
4281EFIAPI\r
4282BitFieldWrite32 (\r
4283 IN UINT32 Operand,\r
4284 IN UINTN StartBit,\r
4285 IN UINTN EndBit,\r
4286 IN UINT32 Value\r
4287 );\r
4288\r
4289\r
4290/**\r
4291 Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the\r
4292 result.\r
4293\r
62991af2 4294 Performs a bitwise OR between the bit field specified by StartBit\r
ac644614 4295 and EndBit in Operand and the value specified by OrData. All other bits in\r
4296 Operand are preserved. The new 32-bit value is returned.\r
4297\r
4298 If 32-bit operations are not supported, then ASSERT().\r
4299 If StartBit is greater than 31, then ASSERT().\r
4300 If EndBit is greater than 31, then ASSERT().\r
4301 If EndBit is less than StartBit, then ASSERT().\r
94952554 4302 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4303\r
4304 @param Operand Operand on which to perform the bitfield operation.\r
4305 @param StartBit The ordinal of the least significant bit in the bit field.\r
4306 Range 0..31.\r
4307 @param EndBit The ordinal of the most significant bit in the bit field.\r
4308 Range 0..31.\r
af2dc6a7 4309 @param OrData The value to OR with the read value from the value.\r
ac644614 4310\r
4311 @return The new 32-bit value.\r
4312\r
4313**/\r
4314UINT32\r
4315EFIAPI\r
4316BitFieldOr32 (\r
4317 IN UINT32 Operand,\r
4318 IN UINTN StartBit,\r
4319 IN UINTN EndBit,\r
4320 IN UINT32 OrData\r
4321 );\r
4322\r
4323\r
4324/**\r
4325 Reads a bit field from a 32-bit value, performs a bitwise AND, and returns\r
4326 the result.\r
4327\r
4328 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
4329 in Operand and the value specified by AndData. All other bits in Operand are\r
4330 preserved. The new 32-bit value is returned.\r
4331\r
4332 If 32-bit operations are not supported, then ASSERT().\r
4333 If StartBit is greater than 31, then ASSERT().\r
4334 If EndBit is greater than 31, then ASSERT().\r
4335 If EndBit is less than StartBit, then ASSERT().\r
94952554 4336 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4337\r
4338 @param Operand Operand on which to perform the bitfield operation.\r
4339 @param StartBit The ordinal of the least significant bit in the bit field.\r
4340 Range 0..31.\r
4341 @param EndBit The ordinal of the most significant bit in the bit field.\r
4342 Range 0..31.\r
4343 @param AndData The value to AND with the read value from the value\r
4344\r
4345 @return The new 32-bit value.\r
4346\r
4347**/\r
4348UINT32\r
4349EFIAPI\r
4350BitFieldAnd32 (\r
4351 IN UINT32 Operand,\r
4352 IN UINTN StartBit,\r
4353 IN UINTN EndBit,\r
4354 IN UINT32 AndData\r
4355 );\r
4356\r
4357\r
4358/**\r
4359 Reads a bit field from a 32-bit value, performs a bitwise AND followed by a\r
4360 bitwise OR, and returns the result.\r
4361\r
4362 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
9095d37b 4363 in Operand and the value specified by AndData, followed by a bitwise\r
62991af2 4364 OR with value specified by OrData. All other bits in Operand are\r
ac644614 4365 preserved. The new 32-bit value is returned.\r
4366\r
4367 If 32-bit operations are not supported, then ASSERT().\r
4368 If StartBit is greater than 31, then ASSERT().\r
4369 If EndBit is greater than 31, then ASSERT().\r
4370 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
4371 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
4372 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4373\r
4374 @param Operand Operand on which to perform the bitfield operation.\r
4375 @param StartBit The ordinal of the least significant bit in the bit field.\r
4376 Range 0..31.\r
4377 @param EndBit The ordinal of the most significant bit in the bit field.\r
4378 Range 0..31.\r
4379 @param AndData The value to AND with the read value from the value.\r
4380 @param OrData The value to OR with the result of the AND operation.\r
4381\r
4382 @return The new 32-bit value.\r
4383\r
4384**/\r
4385UINT32\r
4386EFIAPI\r
4387BitFieldAndThenOr32 (\r
4388 IN UINT32 Operand,\r
4389 IN UINTN StartBit,\r
4390 IN UINTN EndBit,\r
4391 IN UINT32 AndData,\r
4392 IN UINT32 OrData\r
4393 );\r
4394\r
4395\r
4396/**\r
4397 Returns a bit field from a 64-bit value.\r
4398\r
4399 Returns the bitfield specified by the StartBit and the EndBit from Operand.\r
4400\r
4401 If 64-bit operations are not supported, then ASSERT().\r
4402 If StartBit is greater than 63, then ASSERT().\r
4403 If EndBit is greater than 63, then ASSERT().\r
4404 If EndBit is less than StartBit, then ASSERT().\r
4405\r
4406 @param Operand Operand on which to perform the bitfield operation.\r
4407 @param StartBit The ordinal of the least significant bit in the bit field.\r
4408 Range 0..63.\r
4409 @param EndBit The ordinal of the most significant bit in the bit field.\r
4410 Range 0..63.\r
4411\r
4412 @return The bit field read.\r
4413\r
4414**/\r
4415UINT64\r
4416EFIAPI\r
4417BitFieldRead64 (\r
4418 IN UINT64 Operand,\r
4419 IN UINTN StartBit,\r
4420 IN UINTN EndBit\r
4421 );\r
4422\r
4423\r
4424/**\r
4425 Writes a bit field to a 64-bit value, and returns the result.\r
4426\r
4427 Writes Value to the bit field specified by the StartBit and the EndBit in\r
4428 Operand. All other bits in Operand are preserved. The new 64-bit value is\r
4429 returned.\r
4430\r
4431 If 64-bit operations are not supported, then ASSERT().\r
4432 If StartBit is greater than 63, then ASSERT().\r
4433 If EndBit is greater than 63, then ASSERT().\r
4434 If EndBit is less than StartBit, then ASSERT().\r
94952554 4435 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4436\r
4437 @param Operand Operand on which to perform the bitfield operation.\r
4438 @param StartBit The ordinal of the least significant bit in the bit field.\r
4439 Range 0..63.\r
4440 @param EndBit The ordinal of the most significant bit in the bit field.\r
4441 Range 0..63.\r
4442 @param Value New value of the bit field.\r
4443\r
4444 @return The new 64-bit value.\r
4445\r
4446**/\r
4447UINT64\r
4448EFIAPI\r
4449BitFieldWrite64 (\r
4450 IN UINT64 Operand,\r
4451 IN UINTN StartBit,\r
4452 IN UINTN EndBit,\r
4453 IN UINT64 Value\r
4454 );\r
4455\r
4456\r
4457/**\r
4458 Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the\r
4459 result.\r
4460\r
62991af2 4461 Performs a bitwise OR between the bit field specified by StartBit\r
ac644614 4462 and EndBit in Operand and the value specified by OrData. All other bits in\r
4463 Operand are preserved. The new 64-bit value is returned.\r
4464\r
4465 If 64-bit operations are not supported, then ASSERT().\r
4466 If StartBit is greater than 63, then ASSERT().\r
4467 If EndBit is greater than 63, then ASSERT().\r
4468 If EndBit is less than StartBit, then ASSERT().\r
94952554 4469 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4470\r
4471 @param Operand Operand on which to perform the bitfield operation.\r
4472 @param StartBit The ordinal of the least significant bit in the bit field.\r
4473 Range 0..63.\r
4474 @param EndBit The ordinal of the most significant bit in the bit field.\r
4475 Range 0..63.\r
4476 @param OrData The value to OR with the read value from the value\r
4477\r
4478 @return The new 64-bit value.\r
4479\r
4480**/\r
4481UINT64\r
4482EFIAPI\r
4483BitFieldOr64 (\r
4484 IN UINT64 Operand,\r
4485 IN UINTN StartBit,\r
4486 IN UINTN EndBit,\r
4487 IN UINT64 OrData\r
4488 );\r
4489\r
4490\r
4491/**\r
4492 Reads a bit field from a 64-bit value, performs a bitwise AND, and returns\r
4493 the result.\r
4494\r
4495 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
4496 in Operand and the value specified by AndData. All other bits in Operand are\r
4497 preserved. The new 64-bit value is returned.\r
4498\r
4499 If 64-bit operations are not supported, then ASSERT().\r
4500 If StartBit is greater than 63, then ASSERT().\r
4501 If EndBit is greater than 63, then ASSERT().\r
4502 If EndBit is less than StartBit, then ASSERT().\r
94952554 4503 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4504\r
4505 @param Operand Operand on which to perform the bitfield operation.\r
4506 @param StartBit The ordinal of the least significant bit in the bit field.\r
4507 Range 0..63.\r
4508 @param EndBit The ordinal of the most significant bit in the bit field.\r
4509 Range 0..63.\r
4510 @param AndData The value to AND with the read value from the value\r
4511\r
4512 @return The new 64-bit value.\r
4513\r
4514**/\r
4515UINT64\r
4516EFIAPI\r
4517BitFieldAnd64 (\r
4518 IN UINT64 Operand,\r
4519 IN UINTN StartBit,\r
4520 IN UINTN EndBit,\r
4521 IN UINT64 AndData\r
4522 );\r
4523\r
4524\r
4525/**\r
4526 Reads a bit field from a 64-bit value, performs a bitwise AND followed by a\r
4527 bitwise OR, and returns the result.\r
4528\r
4529 Performs a bitwise AND between the bit field specified by StartBit and EndBit\r
9095d37b 4530 in Operand and the value specified by AndData, followed by a bitwise\r
62991af2 4531 OR with value specified by OrData. All other bits in Operand are\r
ac644614 4532 preserved. The new 64-bit value is returned.\r
4533\r
4534 If 64-bit operations are not supported, then ASSERT().\r
4535 If StartBit is greater than 63, then ASSERT().\r
4536 If EndBit is greater than 63, then ASSERT().\r
4537 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
4538 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
4539 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 4540\r
4541 @param Operand Operand on which to perform the bitfield operation.\r
4542 @param StartBit The ordinal of the least significant bit in the bit field.\r
4543 Range 0..63.\r
4544 @param EndBit The ordinal of the most significant bit in the bit field.\r
4545 Range 0..63.\r
4546 @param AndData The value to AND with the read value from the value.\r
4547 @param OrData The value to OR with the result of the AND operation.\r
4548\r
4549 @return The new 64-bit value.\r
4550\r
4551**/\r
4552UINT64\r
4553EFIAPI\r
4554BitFieldAndThenOr64 (\r
4555 IN UINT64 Operand,\r
4556 IN UINTN StartBit,\r
4557 IN UINTN EndBit,\r
4558 IN UINT64 AndData,\r
4559 IN UINT64 OrData\r
4560 );\r
4561\r
d7634dc0
TP
4562/**\r
4563 Reads a bit field from a 32-bit value, counts and returns\r
4564 the number of set bits.\r
4565\r
4566 Counts the number of set bits in the bit field specified by\r
4567 StartBit and EndBit in Operand. The count is returned.\r
4568\r
4569 If StartBit is greater than 31, then ASSERT().\r
4570 If EndBit is greater than 31, then ASSERT().\r
4571 If EndBit is less than StartBit, then ASSERT().\r
4572\r
4573 @param Operand Operand on which to perform the bitfield operation.\r
4574 @param StartBit The ordinal of the least significant bit in the bit field.\r
4575 Range 0..31.\r
4576 @param EndBit The ordinal of the most significant bit in the bit field.\r
4577 Range 0..31.\r
4578\r
4579 @return The number of bits set between StartBit and EndBit.\r
4580\r
4581**/\r
4582UINT8\r
4583EFIAPI\r
4584BitFieldCountOnes32 (\r
4585 IN UINT32 Operand,\r
4586 IN UINTN StartBit,\r
4587 IN UINTN EndBit\r
4588 );\r
4589\r
4590/**\r
4591 Reads a bit field from a 64-bit value, counts and returns\r
4592 the number of set bits.\r
4593\r
4594 Counts the number of set bits in the bit field specified by\r
4595 StartBit and EndBit in Operand. The count is returned.\r
4596\r
4597 If StartBit is greater than 63, then ASSERT().\r
4598 If EndBit is greater than 63, then ASSERT().\r
4599 If EndBit is less than StartBit, then ASSERT().\r
4600\r
4601 @param Operand Operand on which to perform the bitfield operation.\r
4602 @param StartBit The ordinal of the least significant bit in the bit field.\r
4603 Range 0..63.\r
4604 @param EndBit The ordinal of the most significant bit in the bit field.\r
4605 Range 0..63.\r
4606\r
4607 @return The number of bits set between StartBit and EndBit.\r
4608\r
4609**/\r
4610UINT8\r
4611EFIAPI\r
4612BitFieldCountOnes64 (\r
4613 IN UINT64 Operand,\r
4614 IN UINTN StartBit,\r
4615 IN UINTN EndBit\r
4616 );\r
4617\r
ac644614 4618//\r
4619// Base Library Checksum Functions\r
4620//\r
4621\r
4622/**\r
17f695ed 4623 Returns the sum of all elements in a buffer in unit of UINT8.\r
ac644614 4624 During calculation, the carry bits are dropped.\r
4625\r
4626 This function calculates the sum of all elements in a buffer\r
4627 in unit of UINT8. The carry bits in result of addition are dropped.\r
4628 The result is returned as UINT8. If Length is Zero, then Zero is\r
4629 returned.\r
4630\r
4631 If Buffer is NULL, then ASSERT().\r
4632 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4633\r
af2dc6a7 4634 @param Buffer The pointer to the buffer to carry out the sum operation.\r
17f695ed 4635 @param Length The size, in bytes, of Buffer.\r
ac644614 4636\r
4637 @return Sum The sum of Buffer with carry bits dropped during additions.\r
4638\r
4639**/\r
4640UINT8\r
4641EFIAPI\r
4642CalculateSum8 (\r
ee6c452c 4643 IN CONST UINT8 *Buffer,\r
4644 IN UINTN Length\r
ac644614 4645 );\r
4646\r
4647\r
4648/**\r
4649 Returns the two's complement checksum of all elements in a buffer\r
4650 of 8-bit values.\r
4651\r
4652 This function first calculates the sum of the 8-bit values in the\r
4653 buffer specified by Buffer and Length. The carry bits in the result\r
4654 of addition are dropped. Then, the two's complement of the sum is\r
4655 returned. If Length is 0, then 0 is returned.\r
4656\r
4657 If Buffer is NULL, then ASSERT().\r
4658 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4659\r
af2dc6a7 4660 @param Buffer The pointer to the buffer to carry out the checksum operation.\r
1106ffe1 4661 @param Length The size, in bytes, of Buffer.\r
ac644614 4662\r
af2dc6a7 4663 @return Checksum The two's complement checksum of Buffer.\r
ac644614 4664\r
4665**/\r
4666UINT8\r
4667EFIAPI\r
4668CalculateCheckSum8 (\r
ee6c452c 4669 IN CONST UINT8 *Buffer,\r
4670 IN UINTN Length\r
ac644614 4671 );\r
4672\r
4673\r
4674/**\r
4675 Returns the sum of all elements in a buffer of 16-bit values. During\r
4676 calculation, the carry bits are dropped.\r
4677\r
4678 This function calculates the sum of the 16-bit values in the buffer\r
4679 specified by Buffer and Length. The carry bits in result of addition are dropped.\r
4680 The 16-bit result is returned. If Length is 0, then 0 is returned.\r
4681\r
4682 If Buffer is NULL, then ASSERT().\r
4683 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
4684 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
4685 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4686\r
af2dc6a7 4687 @param Buffer The pointer to the buffer to carry out the sum operation.\r
1106ffe1 4688 @param Length The size, in bytes, of Buffer.\r
ac644614 4689\r
4690 @return Sum The sum of Buffer with carry bits dropped during additions.\r
4691\r
4692**/\r
4693UINT16\r
4694EFIAPI\r
4695CalculateSum16 (\r
ee6c452c 4696 IN CONST UINT16 *Buffer,\r
4697 IN UINTN Length\r
ac644614 4698 );\r
4699\r
4700\r
4701/**\r
4702 Returns the two's complement checksum of all elements in a buffer of\r
4703 16-bit values.\r
4704\r
4705 This function first calculates the sum of the 16-bit values in the buffer\r
4706 specified by Buffer and Length. The carry bits in the result of addition\r
4707 are dropped. Then, the two's complement of the sum is returned. If Length\r
4708 is 0, then 0 is returned.\r
4709\r
4710 If Buffer is NULL, then ASSERT().\r
4711 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
4712 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
4713 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4714\r
af2dc6a7 4715 @param Buffer The pointer to the buffer to carry out the checksum operation.\r
1106ffe1 4716 @param Length The size, in bytes, of Buffer.\r
ac644614 4717\r
af2dc6a7 4718 @return Checksum The two's complement checksum of Buffer.\r
ac644614 4719\r
4720**/\r
4721UINT16\r
4722EFIAPI\r
4723CalculateCheckSum16 (\r
ee6c452c 4724 IN CONST UINT16 *Buffer,\r
4725 IN UINTN Length\r
ac644614 4726 );\r
4727\r
4728\r
4729/**\r
17f695ed 4730 Returns the sum of all elements in a buffer of 32-bit values. During\r
ac644614 4731 calculation, the carry bits are dropped.\r
4732\r
4733 This function calculates the sum of the 32-bit values in the buffer\r
4734 specified by Buffer and Length. The carry bits in result of addition are dropped.\r
17f695ed 4735 The 32-bit result is returned. If Length is 0, then 0 is returned.\r
ac644614 4736\r
4737 If Buffer is NULL, then ASSERT().\r
4738 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
4739 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
4740 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4741\r
af2dc6a7 4742 @param Buffer The pointer to the buffer to carry out the sum operation.\r
1106ffe1 4743 @param Length The size, in bytes, of Buffer.\r
ac644614 4744\r
4745 @return Sum The sum of Buffer with carry bits dropped during additions.\r
4746\r
4747**/\r
4748UINT32\r
4749EFIAPI\r
4750CalculateSum32 (\r
ee6c452c 4751 IN CONST UINT32 *Buffer,\r
4752 IN UINTN Length\r
ac644614 4753 );\r
4754\r
4755\r
4756/**\r
4757 Returns the two's complement checksum of all elements in a buffer of\r
4758 32-bit values.\r
4759\r
4760 This function first calculates the sum of the 32-bit values in the buffer\r
4761 specified by Buffer and Length. The carry bits in the result of addition\r
4762 are dropped. Then, the two's complement of the sum is returned. If Length\r
4763 is 0, then 0 is returned.\r
4764\r
4765 If Buffer is NULL, then ASSERT().\r
4766 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
4767 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
4768 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4769\r
af2dc6a7 4770 @param Buffer The pointer to the buffer to carry out the checksum operation.\r
1106ffe1 4771 @param Length The size, in bytes, of Buffer.\r
ac644614 4772\r
af2dc6a7 4773 @return Checksum The two's complement checksum of Buffer.\r
ac644614 4774\r
4775**/\r
4776UINT32\r
4777EFIAPI\r
4778CalculateCheckSum32 (\r
ee6c452c 4779 IN CONST UINT32 *Buffer,\r
4780 IN UINTN Length\r
ac644614 4781 );\r
4782\r
4783\r
4784/**\r
4785 Returns the sum of all elements in a buffer of 64-bit values. During\r
4786 calculation, the carry bits are dropped.\r
4787\r
4788 This function calculates the sum of the 64-bit values in the buffer\r
4789 specified by Buffer and Length. The carry bits in result of addition are dropped.\r
4790 The 64-bit result is returned. If Length is 0, then 0 is returned.\r
4791\r
4792 If Buffer is NULL, then ASSERT().\r
4793 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
4794 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
4795 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4796\r
af2dc6a7 4797 @param Buffer The pointer to the buffer to carry out the sum operation.\r
1106ffe1 4798 @param Length The size, in bytes, of Buffer.\r
ac644614 4799\r
4800 @return Sum The sum of Buffer with carry bits dropped during additions.\r
4801\r
4802**/\r
4803UINT64\r
4804EFIAPI\r
4805CalculateSum64 (\r
ee6c452c 4806 IN CONST UINT64 *Buffer,\r
4807 IN UINTN Length\r
ac644614 4808 );\r
4809\r
4810\r
4811/**\r
4812 Returns the two's complement checksum of all elements in a buffer of\r
4813 64-bit values.\r
4814\r
4815 This function first calculates the sum of the 64-bit values in the buffer\r
4816 specified by Buffer and Length. The carry bits in the result of addition\r
4817 are dropped. Then, the two's complement of the sum is returned. If Length\r
4818 is 0, then 0 is returned.\r
4819\r
4820 If Buffer is NULL, then ASSERT().\r
4821 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
4822 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
4823 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4824\r
af2dc6a7 4825 @param Buffer The pointer to the buffer to carry out the checksum operation.\r
1106ffe1 4826 @param Length The size, in bytes, of Buffer.\r
ac644614 4827\r
af2dc6a7 4828 @return Checksum The two's complement checksum of Buffer.\r
ac644614 4829\r
4830**/\r
4831UINT64\r
4832EFIAPI\r
4833CalculateCheckSum64 (\r
ee6c452c 4834 IN CONST UINT64 *Buffer,\r
4835 IN UINTN Length\r
ac644614 4836 );\r
4837\r
0a8e6f79
LG
4838/**\r
4839 Computes and returns a 32-bit CRC for a data buffer.\r
4840 CRC32 value bases on ITU-T V.42.\r
4841\r
4842 If Buffer is NULL, then ASSERT().\r
4843 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
4844\r
4845 @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed.\r
4846 @param[in] Length The number of bytes in the buffer Data.\r
4847\r
4848 @retval Crc32 The 32-bit CRC was computed for the data buffer.\r
4849\r
4850**/\r
4851UINT32\r
4852EFIAPI\r
4853CalculateCrc32(\r
4854 IN VOID *Buffer,\r
4855 IN UINTN Length\r
4856 );\r
ac644614 4857\r
d75f9fc2 4858//\r
4859// Base Library CPU Functions\r
4860//\r
4861\r
4862/**\r
4863 Function entry point used when a stack switch is requested with SwitchStack()\r
4864\r
4865 @param Context1 Context1 parameter passed into SwitchStack().\r
4866 @param Context2 Context2 parameter passed into SwitchStack().\r
4867\r
4868**/\r
ac644614 4869typedef\r
4870VOID\r
9810cdd8 4871(EFIAPI *SWITCH_STACK_ENTRY_POINT)(\r
ac644614 4872 IN VOID *Context1, OPTIONAL\r
4873 IN VOID *Context2 OPTIONAL\r
4874 );\r
4875\r
4876\r
4877/**\r
4878 Used to serialize load and store operations.\r
4879\r
4880 All loads and stores that proceed calls to this function are guaranteed to be\r
4881 globally visible when this function returns.\r
4882\r
4883**/\r
4884VOID\r
4885EFIAPI\r
4886MemoryFence (\r
4887 VOID\r
4888 );\r
4889\r
4890\r
4891/**\r
4892 Saves the current CPU context that can be restored with a call to LongJump()\r
4893 and returns 0.\r
4894\r
4895 Saves the current CPU context in the buffer specified by JumpBuffer and\r
4896 returns 0. The initial call to SetJump() must always return 0. Subsequent\r
4897 calls to LongJump() cause a non-zero value to be returned by SetJump().\r
4898\r
4899 If JumpBuffer is NULL, then ASSERT().\r
1a2f870c 4900 For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r
9095d37b 4901\r
17f695ed 4902 NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.\r
4903 The same structure must never be used for more than one CPU architecture context.\r
9095d37b
LG
4904 For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module.\r
4905 SetJump()/LongJump() is not currently supported for the EBC processor type.\r
ac644614 4906\r
4907 @param JumpBuffer A pointer to CPU context buffer.\r
4908\r
4909 @retval 0 Indicates a return from SetJump().\r
4910\r
4911**/\r
2117989c 4912RETURNS_TWICE\r
ac644614 4913UINTN\r
4914EFIAPI\r
4915SetJump (\r
4916 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r
4917 );\r
4918\r
4919\r
4920/**\r
4921 Restores the CPU context that was saved with SetJump().\r
4922\r
4923 Restores the CPU context from the buffer specified by JumpBuffer. This\r
4924 function never returns to the caller. Instead is resumes execution based on\r
4925 the state of JumpBuffer.\r
4926\r
4927 If JumpBuffer is NULL, then ASSERT().\r
1a2f870c 4928 For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r
ac644614 4929 If Value is 0, then ASSERT().\r
4930\r
4931 @param JumpBuffer A pointer to CPU context buffer.\r
4932 @param Value The value to return when the SetJump() context is\r
4933 restored and must be non-zero.\r
4934\r
4935**/\r
4936VOID\r
4937EFIAPI\r
4938LongJump (\r
4939 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,\r
4940 IN UINTN Value\r
4941 );\r
4942\r
4943\r
4944/**\r
4945 Enables CPU interrupts.\r
4946\r
ac644614 4947**/\r
4948VOID\r
4949EFIAPI\r
4950EnableInterrupts (\r
4951 VOID\r
4952 );\r
4953\r
4954\r
4955/**\r
4956 Disables CPU interrupts.\r
4957\r
ac644614 4958**/\r
4959VOID\r
4960EFIAPI\r
4961DisableInterrupts (\r
4962 VOID\r
4963 );\r
4964\r
4965\r
4966/**\r
4967 Disables CPU interrupts and returns the interrupt state prior to the disable\r
4968 operation.\r
4969\r
ac644614 4970 @retval TRUE CPU interrupts were enabled on entry to this call.\r
4971 @retval FALSE CPU interrupts were disabled on entry to this call.\r
4972\r
4973**/\r
4974BOOLEAN\r
4975EFIAPI\r
4976SaveAndDisableInterrupts (\r
4977 VOID\r
4978 );\r
4979\r
4980\r
4981/**\r
4982 Enables CPU interrupts for the smallest window required to capture any\r
4983 pending interrupts.\r
4984\r
ac644614 4985**/\r
4986VOID\r
4987EFIAPI\r
4988EnableDisableInterrupts (\r
4989 VOID\r
4990 );\r
4991\r
4992\r
4993/**\r
4994 Retrieves the current CPU interrupt state.\r
4995\r
af2dc6a7 4996 Returns TRUE if interrupts are currently enabled. Otherwise\r
38bbd3d9 4997 returns FALSE.\r
ac644614 4998\r
4999 @retval TRUE CPU interrupts are enabled.\r
5000 @retval FALSE CPU interrupts are disabled.\r
5001\r
5002**/\r
5003BOOLEAN\r
5004EFIAPI\r
5005GetInterruptState (\r
5006 VOID\r
5007 );\r
5008\r
5009\r
5010/**\r
5011 Set the current CPU interrupt state.\r
5012\r
5013 Sets the current CPU interrupt state to the state specified by\r
5014 InterruptState. If InterruptState is TRUE, then interrupts are enabled. If\r
5015 InterruptState is FALSE, then interrupts are disabled. InterruptState is\r
5016 returned.\r
5017\r
5018 @param InterruptState TRUE if interrupts should enabled. FALSE if\r
5019 interrupts should be disabled.\r
5020\r
5021 @return InterruptState\r
5022\r
5023**/\r
5024BOOLEAN\r
5025EFIAPI\r
5026SetInterruptState (\r
5027 IN BOOLEAN InterruptState\r
5028 );\r
5029\r
5030\r
5031/**\r
5032 Requests CPU to pause for a short period of time.\r
5033\r
5034 Requests CPU to pause for a short period of time. Typically used in MP\r
5035 systems to prevent memory starvation while waiting for a spin lock.\r
5036\r
5037**/\r
5038VOID\r
5039EFIAPI\r
5040CpuPause (\r
5041 VOID\r
5042 );\r
5043\r
5044\r
5045/**\r
5046 Transfers control to a function starting with a new stack.\r
5047\r
5048 Transfers control to the function specified by EntryPoint using the\r
5049 new stack specified by NewStack and passing in the parameters specified\r
5050 by Context1 and Context2. Context1 and Context2 are optional and may\r
5051 be NULL. The function EntryPoint must never return. This function\r
5052 supports a variable number of arguments following the NewStack parameter.\r
1a2f870c 5053 These additional arguments are ignored on IA-32, x64, and EBC architectures.\r
5054 Itanium processors expect one additional parameter of type VOID * that specifies\r
ac644614 5055 the new backing store pointer.\r
5056\r
5057 If EntryPoint is NULL, then ASSERT().\r
5058 If NewStack is NULL, then ASSERT().\r
5059\r
5060 @param EntryPoint A pointer to function to call with the new stack.\r
5061 @param Context1 A pointer to the context to pass into the EntryPoint\r
5062 function.\r
5063 @param Context2 A pointer to the context to pass into the EntryPoint\r
5064 function.\r
5065 @param NewStack A pointer to the new stack to use for the EntryPoint\r
5066 function.\r
9095d37b
LG
5067 @param ... This variable argument list is ignored for IA-32, x64, and\r
5068 EBC architectures. For Itanium processors, this variable\r
5069 argument list is expected to contain a single parameter of\r
af2dc6a7 5070 type VOID * that specifies the new backing store pointer.\r
42eedea9 5071\r
ac644614 5072\r
5073**/\r
5074VOID\r
5075EFIAPI\r
5076SwitchStack (\r
5077 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
5078 IN VOID *Context1, OPTIONAL\r
5079 IN VOID *Context2, OPTIONAL\r
5080 IN VOID *NewStack,\r
5081 ...\r
5082 );\r
5083\r
5084\r
5085/**\r
5086 Generates a breakpoint on the CPU.\r
5087\r
5088 Generates a breakpoint on the CPU. The breakpoint must be implemented such\r
5089 that code can resume normal execution after the breakpoint.\r
5090\r
5091**/\r
5092VOID\r
5093EFIAPI\r
5094CpuBreakpoint (\r
5095 VOID\r
5096 );\r
5097\r
5098\r
5099/**\r
5100 Executes an infinite loop.\r
5101\r
5102 Forces the CPU to execute an infinite loop. A debugger may be used to skip\r
5103 past the loop and the code that follows the loop must execute properly. This\r
5104 implies that the infinite loop must not cause the code that follow it to be\r
5105 optimized away.\r
5106\r
5107**/\r
5108VOID\r
5109EFIAPI\r
5110CpuDeadLoop (\r
5111 VOID\r
5112 );\r
9095d37b 5113\r
fd163050 5114#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
1106ffe1 5115///\r
af2dc6a7 5116/// IA32 and x64 Specific Functions.\r
5117/// Byte packed structure for 16-bit Real Mode EFLAGS.\r
1106ffe1 5118///\r
ac644614 5119typedef union {\r
5120 struct {\r
af2dc6a7 5121 UINT32 CF:1; ///< Carry Flag.\r
5122 UINT32 Reserved_0:1; ///< Reserved.\r
5123 UINT32 PF:1; ///< Parity Flag.\r
5124 UINT32 Reserved_1:1; ///< Reserved.\r
5125 UINT32 AF:1; ///< Auxiliary Carry Flag.\r
5126 UINT32 Reserved_2:1; ///< Reserved.\r
5127 UINT32 ZF:1; ///< Zero Flag.\r
5128 UINT32 SF:1; ///< Sign Flag.\r
5129 UINT32 TF:1; ///< Trap Flag.\r
5130 UINT32 IF:1; ///< Interrupt Enable Flag.\r
5131 UINT32 DF:1; ///< Direction Flag.\r
5132 UINT32 OF:1; ///< Overflow Flag.\r
5133 UINT32 IOPL:2; ///< I/O Privilege Level.\r
5134 UINT32 NT:1; ///< Nested Task.\r
5135 UINT32 Reserved_3:1; ///< Reserved.\r
ac644614 5136 } Bits;\r
5137 UINT16 Uint16;\r
5138} IA32_FLAGS16;\r
5139\r
1106ffe1 5140///\r
af2dc6a7 5141/// Byte packed structure for EFLAGS/RFLAGS.\r
5142/// 32-bits on IA-32.\r
5143/// 64-bits on x64. The upper 32-bits on x64 are reserved.\r
1106ffe1 5144///\r
ac644614 5145typedef union {\r
5146 struct {\r
af2dc6a7 5147 UINT32 CF:1; ///< Carry Flag.\r
5148 UINT32 Reserved_0:1; ///< Reserved.\r
5149 UINT32 PF:1; ///< Parity Flag.\r
5150 UINT32 Reserved_1:1; ///< Reserved.\r
5151 UINT32 AF:1; ///< Auxiliary Carry Flag.\r
5152 UINT32 Reserved_2:1; ///< Reserved.\r
5153 UINT32 ZF:1; ///< Zero Flag.\r
5154 UINT32 SF:1; ///< Sign Flag.\r
5155 UINT32 TF:1; ///< Trap Flag.\r
5156 UINT32 IF:1; ///< Interrupt Enable Flag.\r
5157 UINT32 DF:1; ///< Direction Flag.\r
5158 UINT32 OF:1; ///< Overflow Flag.\r
5159 UINT32 IOPL:2; ///< I/O Privilege Level.\r
5160 UINT32 NT:1; ///< Nested Task.\r
5161 UINT32 Reserved_3:1; ///< Reserved.\r
5162 UINT32 RF:1; ///< Resume Flag.\r
5163 UINT32 VM:1; ///< Virtual 8086 Mode.\r
5164 UINT32 AC:1; ///< Alignment Check.\r
5165 UINT32 VIF:1; ///< Virtual Interrupt Flag.\r
5166 UINT32 VIP:1; ///< Virtual Interrupt Pending.\r
5167 UINT32 ID:1; ///< ID Flag.\r
5168 UINT32 Reserved_4:10; ///< Reserved.\r
ac644614 5169 } Bits;\r
5170 UINTN UintN;\r
5171} IA32_EFLAGS32;\r
5172\r
1106ffe1 5173///\r
af2dc6a7 5174/// Byte packed structure for Control Register 0 (CR0).\r
5175/// 32-bits on IA-32.\r
5176/// 64-bits on x64. The upper 32-bits on x64 are reserved.\r
1106ffe1 5177///\r
ac644614 5178typedef union {\r
5179 struct {\r
af2dc6a7 5180 UINT32 PE:1; ///< Protection Enable.\r
5181 UINT32 MP:1; ///< Monitor Coprocessor.\r
5182 UINT32 EM:1; ///< Emulation.\r
5183 UINT32 TS:1; ///< Task Switched.\r
5184 UINT32 ET:1; ///< Extension Type.\r
5185 UINT32 NE:1; ///< Numeric Error.\r
5186 UINT32 Reserved_0:10; ///< Reserved.\r
5187 UINT32 WP:1; ///< Write Protect.\r
5188 UINT32 Reserved_1:1; ///< Reserved.\r
5189 UINT32 AM:1; ///< Alignment Mask.\r
5190 UINT32 Reserved_2:10; ///< Reserved.\r
5191 UINT32 NW:1; ///< Mot Write-through.\r
5192 UINT32 CD:1; ///< Cache Disable.\r
5193 UINT32 PG:1; ///< Paging.\r
ac644614 5194 } Bits;\r
5195 UINTN UintN;\r
5196} IA32_CR0;\r
5197\r
1106ffe1 5198///\r
af2dc6a7 5199/// Byte packed structure for Control Register 4 (CR4).\r
5200/// 32-bits on IA-32.\r
5201/// 64-bits on x64. The upper 32-bits on x64 are reserved.\r
1106ffe1 5202///\r
ac644614 5203typedef union {\r
5204 struct {\r
af2dc6a7 5205 UINT32 VME:1; ///< Virtual-8086 Mode Extensions.\r
5206 UINT32 PVI:1; ///< Protected-Mode Virtual Interrupts.\r
5207 UINT32 TSD:1; ///< Time Stamp Disable.\r
5208 UINT32 DE:1; ///< Debugging Extensions.\r
5209 UINT32 PSE:1; ///< Page Size Extensions.\r
5210 UINT32 PAE:1; ///< Physical Address Extension.\r
5211 UINT32 MCE:1; ///< Machine Check Enable.\r
5212 UINT32 PGE:1; ///< Page Global Enable.\r
2a53dabf 5213 UINT32 PCE:1; ///< Performance Monitoring Counter\r
af2dc6a7 5214 ///< Enable.\r
2a53dabf
LG
5215 UINT32 OSFXSR:1; ///< Operating System Support for\r
5216 ///< FXSAVE and FXRSTOR instructions\r
5217 UINT32 OSXMMEXCPT:1; ///< Operating System Support for\r
5218 ///< Unmasked SIMD Floating Point\r
af2dc6a7 5219 ///< Exceptions.\r
5220 UINT32 Reserved_0:2; ///< Reserved.\r
2a53dabf 5221 UINT32 VMXE:1; ///< VMX Enable\r
af2dc6a7 5222 UINT32 Reserved_1:18; ///< Reserved.\r
ac644614 5223 } Bits;\r
5224 UINTN UintN;\r
5225} IA32_CR4;\r
5226\r
6088db38 5227///\r
5228/// Byte packed structure for a segment descriptor in a GDT/LDT.\r
5229///\r
5230typedef union {\r
5231 struct {\r
5232 UINT32 LimitLow:16;\r
5233 UINT32 BaseLow:16;\r
5234 UINT32 BaseMid:8;\r
5235 UINT32 Type:4;\r
5236 UINT32 S:1;\r
5237 UINT32 DPL:2;\r
5238 UINT32 P:1;\r
5239 UINT32 LimitHigh:4;\r
5240 UINT32 AVL:1;\r
5241 UINT32 L:1;\r
5242 UINT32 DB:1;\r
5243 UINT32 G:1;\r
5244 UINT32 BaseHigh:8;\r
5245 } Bits;\r
5246 UINT64 Uint64;\r
5247} IA32_SEGMENT_DESCRIPTOR;\r
5248\r
1106ffe1 5249///\r
af2dc6a7 5250/// Byte packed structure for an IDTR, GDTR, LDTR descriptor.\r
1106ffe1 5251///\r
ac644614 5252#pragma pack (1)\r
5253typedef struct {\r
5254 UINT16 Limit;\r
5255 UINTN Base;\r
5256} IA32_DESCRIPTOR;\r
5257#pragma pack ()\r
5258\r
5259#define IA32_IDT_GATE_TYPE_TASK 0x85\r
5260#define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86\r
5261#define IA32_IDT_GATE_TYPE_TRAP_16 0x87\r
5262#define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E\r
5263#define IA32_IDT_GATE_TYPE_TRAP_32 0x8F\r
5264\r
364a5474
JW
5265#define IA32_GDT_TYPE_TSS 0x9\r
5266#define IA32_GDT_ALIGNMENT 8\r
6f4aad3b 5267\r
5268#if defined (MDE_CPU_IA32)\r
1106ffe1 5269///\r
af2dc6a7 5270/// Byte packed structure for an IA-32 Interrupt Gate Descriptor.\r
1106ffe1 5271///\r
dc317713 5272typedef union {\r
5273 struct {\r
af2dc6a7 5274 UINT32 OffsetLow:16; ///< Offset bits 15..0.\r
5275 UINT32 Selector:16; ///< Selector.\r
5276 UINT32 Reserved_0:8; ///< Reserved.\r
5277 UINT32 GateType:8; ///< Gate Type. See #defines above.\r
5278 UINT32 OffsetHigh:16; ///< Offset bits 31..16.\r
dc317713 5279 } Bits;\r
5280 UINT64 Uint64;\r
5281} IA32_IDT_GATE_DESCRIPTOR;\r
5282\r
364a5474
JW
5283#pragma pack (1)\r
5284//\r
5285// IA32 Task-State Segment Definition\r
5286//\r
5287typedef struct {\r
5288 UINT16 PreviousTaskLink;\r
5289 UINT16 Reserved_2;\r
3ab032fc
JW
5290 UINT32 ESP0;\r
5291 UINT16 SS0;\r
364a5474 5292 UINT16 Reserved_10;\r
3ab032fc
JW
5293 UINT32 ESP1;\r
5294 UINT16 SS1;\r
364a5474 5295 UINT16 Reserved_18;\r
3ab032fc
JW
5296 UINT32 ESP2;\r
5297 UINT16 SS2;\r
364a5474 5298 UINT16 Reserved_26;\r
3ab032fc
JW
5299 UINT32 CR3;\r
5300 UINT32 EIP;\r
5301 UINT32 EFLAGS;\r
5302 UINT32 EAX;\r
5303 UINT32 ECX;\r
5304 UINT32 EDX;\r
5305 UINT32 EBX;\r
5306 UINT32 ESP;\r
5307 UINT32 EBP;\r
5308 UINT32 ESI;\r
5309 UINT32 EDI;\r
5310 UINT16 ES;\r
364a5474 5311 UINT16 Reserved_74;\r
3ab032fc 5312 UINT16 CS;\r
364a5474 5313 UINT16 Reserved_78;\r
3ab032fc 5314 UINT16 SS;\r
364a5474 5315 UINT16 Reserved_82;\r
3ab032fc 5316 UINT16 DS;\r
364a5474 5317 UINT16 Reserved_86;\r
3ab032fc 5318 UINT16 FS;\r
364a5474 5319 UINT16 Reserved_90;\r
3ab032fc 5320 UINT16 GS;\r
364a5474
JW
5321 UINT16 Reserved_94;\r
5322 UINT16 LDTSegmentSelector;\r
5323 UINT16 Reserved_98;\r
3ab032fc 5324 UINT16 T;\r
364a5474
JW
5325 UINT16 IOMapBaseAddress;\r
5326} IA32_TASK_STATE_SEGMENT;\r
5327\r
5328typedef union {\r
5329 struct {\r
5330 UINT32 LimitLow:16; ///< Segment Limit 15..00\r
5331 UINT32 BaseLow:16; ///< Base Address 15..00\r
5332 UINT32 BaseMid:8; ///< Base Address 23..16\r
5333 UINT32 Type:4; ///< Type (1 0 B 1)\r
5334 UINT32 Reserved_43:1; ///< 0\r
3ab032fc
JW
5335 UINT32 DPL:2; ///< Descriptor Privilege Level\r
5336 UINT32 P:1; ///< Segment Present\r
364a5474 5337 UINT32 LimitHigh:4; ///< Segment Limit 19..16\r
3ab032fc 5338 UINT32 AVL:1; ///< Available for use by system software\r
364a5474 5339 UINT32 Reserved_52:2; ///< 0 0\r
3ab032fc 5340 UINT32 G:1; ///< Granularity\r
364a5474
JW
5341 UINT32 BaseHigh:8; ///< Base Address 31..24\r
5342 } Bits;\r
5343 UINT64 Uint64;\r
5344} IA32_TSS_DESCRIPTOR;\r
5345#pragma pack ()\r
5346\r
de4f7f52 5347#endif // defined (MDE_CPU_IA32)\r
dc317713 5348\r
5349#if defined (MDE_CPU_X64)\r
6f4aad3b 5350///\r
af2dc6a7 5351/// Byte packed structure for an x64 Interrupt Gate Descriptor.\r
6f4aad3b 5352///\r
ac644614 5353typedef union {\r
5354 struct {\r
af2dc6a7 5355 UINT32 OffsetLow:16; ///< Offset bits 15..0.\r
5356 UINT32 Selector:16; ///< Selector.\r
5357 UINT32 Reserved_0:8; ///< Reserved.\r
5358 UINT32 GateType:8; ///< Gate Type. See #defines above.\r
5359 UINT32 OffsetHigh:16; ///< Offset bits 31..16.\r
5360 UINT32 OffsetUpper:32; ///< Offset bits 63..32.\r
5361 UINT32 Reserved_1:32; ///< Reserved.\r
ac644614 5362 } Bits;\r
6f4aad3b 5363 struct {\r
5364 UINT64 Uint64;\r
5365 UINT64 Uint64_1;\r
9095d37b 5366 } Uint128;\r
ac644614 5367} IA32_IDT_GATE_DESCRIPTOR;\r
5368\r
364a5474
JW
5369#pragma pack (1)\r
5370//\r
5371// IA32 Task-State Segment Definition\r
5372//\r
5373typedef struct {\r
5374 UINT32 Reserved_0;\r
3ab032fc
JW
5375 UINT64 RSP0;\r
5376 UINT64 RSP1;\r
5377 UINT64 RSP2;\r
364a5474 5378 UINT64 Reserved_28;\r
3ab032fc 5379 UINT64 IST[7];\r
364a5474
JW
5380 UINT64 Reserved_92;\r
5381 UINT16 Reserved_100;\r
5382 UINT16 IOMapBaseAddress;\r
5383} IA32_TASK_STATE_SEGMENT;\r
5384\r
5385typedef union {\r
5386 struct {\r
5387 UINT32 LimitLow:16; ///< Segment Limit 15..00\r
5388 UINT32 BaseLow:16; ///< Base Address 15..00\r
5389 UINT32 BaseMidl:8; ///< Base Address 23..16\r
5390 UINT32 Type:4; ///< Type (1 0 B 1)\r
5391 UINT32 Reserved_43:1; ///< 0\r
3ab032fc
JW
5392 UINT32 DPL:2; ///< Descriptor Privilege Level\r
5393 UINT32 P:1; ///< Segment Present\r
364a5474 5394 UINT32 LimitHigh:4; ///< Segment Limit 19..16\r
3ab032fc 5395 UINT32 AVL:1; ///< Available for use by system software\r
364a5474 5396 UINT32 Reserved_52:2; ///< 0 0\r
3ab032fc 5397 UINT32 G:1; ///< Granularity\r
364a5474
JW
5398 UINT32 BaseMidh:8; ///< Base Address 31..24\r
5399 UINT32 BaseHigh:32; ///< Base Address 63..32\r
5400 UINT32 Reserved_96:32; ///< Reserved\r
5401 } Bits;\r
5402 struct {\r
5403 UINT64 Uint64;\r
5404 UINT64 Uint64_1;\r
5405 } Uint128;\r
5406} IA32_TSS_DESCRIPTOR;\r
5407#pragma pack ()\r
5408\r
de4f7f52 5409#endif // defined (MDE_CPU_X64)\r
dc317713 5410\r
1106ffe1 5411///\r
af2dc6a7 5412/// Byte packed structure for an FP/SSE/SSE2 context.\r
1106ffe1 5413///\r
ac644614 5414typedef struct {\r
5415 UINT8 Buffer[512];\r
5416} IA32_FX_BUFFER;\r
5417\r
1106ffe1 5418///\r
af2dc6a7 5419/// Structures for the 16-bit real mode thunks.\r
1106ffe1 5420///\r
ac644614 5421typedef struct {\r
5422 UINT32 Reserved1;\r
5423 UINT32 Reserved2;\r
5424 UINT32 Reserved3;\r
5425 UINT32 Reserved4;\r
5426 UINT8 BL;\r
5427 UINT8 BH;\r
5428 UINT16 Reserved5;\r
5429 UINT8 DL;\r
5430 UINT8 DH;\r
5431 UINT16 Reserved6;\r
5432 UINT8 CL;\r
5433 UINT8 CH;\r
5434 UINT16 Reserved7;\r
5435 UINT8 AL;\r
5436 UINT8 AH;\r
5437 UINT16 Reserved8;\r
5438} IA32_BYTE_REGS;\r
5439\r
5440typedef struct {\r
5441 UINT16 DI;\r
5442 UINT16 Reserved1;\r
5443 UINT16 SI;\r
5444 UINT16 Reserved2;\r
5445 UINT16 BP;\r
5446 UINT16 Reserved3;\r
5447 UINT16 SP;\r
5448 UINT16 Reserved4;\r
5449 UINT16 BX;\r
5450 UINT16 Reserved5;\r
5451 UINT16 DX;\r
5452 UINT16 Reserved6;\r
5453 UINT16 CX;\r
5454 UINT16 Reserved7;\r
5455 UINT16 AX;\r
5456 UINT16 Reserved8;\r
5457} IA32_WORD_REGS;\r
5458\r
5459typedef struct {\r
5460 UINT32 EDI;\r
5461 UINT32 ESI;\r
5462 UINT32 EBP;\r
5463 UINT32 ESP;\r
5464 UINT32 EBX;\r
5465 UINT32 EDX;\r
5466 UINT32 ECX;\r
5467 UINT32 EAX;\r
5468 UINT16 DS;\r
5469 UINT16 ES;\r
5470 UINT16 FS;\r
5471 UINT16 GS;\r
5472 IA32_EFLAGS32 EFLAGS;\r
5473 UINT32 Eip;\r
5474 UINT16 CS;\r
5475 UINT16 SS;\r
5476} IA32_DWORD_REGS;\r
5477\r
5478typedef union {\r
5479 IA32_DWORD_REGS E;\r
5480 IA32_WORD_REGS X;\r
5481 IA32_BYTE_REGS H;\r
5482} IA32_REGISTER_SET;\r
5483\r
1106ffe1 5484///\r
af2dc6a7 5485/// Byte packed structure for an 16-bit real mode thunks.\r
1106ffe1 5486///\r
ac644614 5487typedef struct {\r
5488 IA32_REGISTER_SET *RealModeState;\r
5489 VOID *RealModeBuffer;\r
5490 UINT32 RealModeBufferSize;\r
5491 UINT32 ThunkAttributes;\r
5492} THUNK_CONTEXT;\r
5493\r
5494#define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001\r
5495#define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002\r
5496#define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004\r
5497\r
8596c140
LE
5498///\r
5499/// Type definition for representing labels in NASM source code that allow for\r
5500/// the patching of immediate operands of IA32 and X64 instructions.\r
5501///\r
5502/// While the type is technically defined as a function type (note: not a\r
5503/// pointer-to-function type), such labels in NASM source code never stand for\r
5504/// actual functions, and identifiers declared with this function type should\r
5505/// never be called. This is also why the EFIAPI calling convention specifier\r
5506/// is missing from the typedef, and why the typedef does not follow the usual\r
5507/// edk2 coding style for function (or pointer-to-function) typedefs. The VOID\r
5508/// return type and the VOID argument list are merely artifacts.\r
5509///\r
5510typedef VOID (X86_ASSEMBLY_PATCH_LABEL) (VOID);\r
5511\r
ac644614 5512/**\r
5513 Retrieves CPUID information.\r
5514\r
5515 Executes the CPUID instruction with EAX set to the value specified by Index.\r
5516 This function always returns Index.\r
5517 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.\r
5518 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.\r
5519 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.\r
5520 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.\r
030cd1a2 5521 This function is only available on IA-32 and x64.\r
ac644614 5522\r
5523 @param Index The 32-bit value to load into EAX prior to invoking the CPUID\r
5524 instruction.\r
af2dc6a7 5525 @param Eax The pointer to the 32-bit EAX value returned by the CPUID\r
ac644614 5526 instruction. This is an optional parameter that may be NULL.\r
af2dc6a7 5527 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID\r
ac644614 5528 instruction. This is an optional parameter that may be NULL.\r
af2dc6a7 5529 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID\r
ac644614 5530 instruction. This is an optional parameter that may be NULL.\r
af2dc6a7 5531 @param Edx The pointer to the 32-bit EDX value returned by the CPUID\r
ac644614 5532 instruction. This is an optional parameter that may be NULL.\r
5533\r
2fe241a2 5534 @return Index.\r
ac644614 5535\r
5536**/\r
5537UINT32\r
5538EFIAPI\r
5539AsmCpuid (\r
5540 IN UINT32 Index,\r
5541 OUT UINT32 *Eax, OPTIONAL\r
5542 OUT UINT32 *Ebx, OPTIONAL\r
5543 OUT UINT32 *Ecx, OPTIONAL\r
5544 OUT UINT32 *Edx OPTIONAL\r
5545 );\r
5546\r
5547\r
5548/**\r
5549 Retrieves CPUID information using an extended leaf identifier.\r
5550\r
5551 Executes the CPUID instruction with EAX set to the value specified by Index\r
5552 and ECX set to the value specified by SubIndex. This function always returns\r
5553 Index. This function is only available on IA-32 and x64.\r
5554\r
5555 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.\r
5556 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.\r
5557 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.\r
5558 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.\r
5559\r
5560 @param Index The 32-bit value to load into EAX prior to invoking the\r
5561 CPUID instruction.\r
5562 @param SubIndex The 32-bit value to load into ECX prior to invoking the\r
5563 CPUID instruction.\r
af2dc6a7 5564 @param Eax The pointer to the 32-bit EAX value returned by the CPUID\r
ac644614 5565 instruction. This is an optional parameter that may be\r
5566 NULL.\r
af2dc6a7 5567 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID\r
ac644614 5568 instruction. This is an optional parameter that may be\r
5569 NULL.\r
af2dc6a7 5570 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID\r
ac644614 5571 instruction. This is an optional parameter that may be\r
5572 NULL.\r
af2dc6a7 5573 @param Edx The pointer to the 32-bit EDX value returned by the CPUID\r
ac644614 5574 instruction. This is an optional parameter that may be\r
5575 NULL.\r
5576\r
2fe241a2 5577 @return Index.\r
ac644614 5578\r
5579**/\r
5580UINT32\r
5581EFIAPI\r
5582AsmCpuidEx (\r
5583 IN UINT32 Index,\r
5584 IN UINT32 SubIndex,\r
5585 OUT UINT32 *Eax, OPTIONAL\r
5586 OUT UINT32 *Ebx, OPTIONAL\r
5587 OUT UINT32 *Ecx, OPTIONAL\r
5588 OUT UINT32 *Edx OPTIONAL\r
5589 );\r
5590\r
5591\r
be5f1614 5592/**\r
5593 Set CD bit and clear NW bit of CR0 followed by a WBINVD.\r
5594\r
5595 Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,\r
5596 and executing a WBINVD instruction. This function is only available on IA-32 and x64.\r
5597\r
5598**/\r
5599VOID\r
5600EFIAPI\r
5601AsmDisableCache (\r
5602 VOID\r
5603 );\r
5604\r
5605\r
5606/**\r
5607 Perform a WBINVD and clear both the CD and NW bits of CR0.\r
5608\r
5609 Enables the caches by executing a WBINVD instruction and then clear both the CD and NW\r
5610 bits of CR0 to 0. This function is only available on IA-32 and x64.\r
5611\r
5612**/\r
5613VOID\r
5614EFIAPI\r
5615AsmEnableCache (\r
5616 VOID\r
5617 );\r
5618\r
5619\r
ac644614 5620/**\r
5621 Returns the lower 32-bits of a Machine Specific Register(MSR).\r
5622\r
5623 Reads and returns the lower 32-bits of the MSR specified by Index.\r
5624 No parameter checking is performed on Index, and some Index values may cause\r
5625 CPU exceptions. The caller must either guarantee that Index is valid, or the\r
5626 caller must set up exception handlers to catch the exceptions. This function\r
030cd1a2 5627 is only available on IA-32 and x64.\r
ac644614 5628\r
5629 @param Index The 32-bit MSR index to read.\r
5630\r
5631 @return The lower 32 bits of the MSR identified by Index.\r
5632\r
5633**/\r
5634UINT32\r
5635EFIAPI\r
5636AsmReadMsr32 (\r
5637 IN UINT32 Index\r
5638 );\r
5639\r
5640\r
5641/**\r
17f695ed 5642 Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.\r
5643 The upper 32-bits of the MSR are set to zero.\r
ac644614 5644\r
5645 Writes the 32-bit value specified by Value to the MSR specified by Index. The\r
5646 upper 32-bits of the MSR write are set to zero. The 32-bit value written to\r
5647 the MSR is returned. No parameter checking is performed on Index or Value,\r
5648 and some of these may cause CPU exceptions. The caller must either guarantee\r
5649 that Index and Value are valid, or the caller must establish proper exception\r
030cd1a2 5650 handlers. This function is only available on IA-32 and x64.\r
ac644614 5651\r
5652 @param Index The 32-bit MSR index to write.\r
5653 @param Value The 32-bit value to write to the MSR.\r
5654\r
5655 @return Value\r
5656\r
5657**/\r
5658UINT32\r
5659EFIAPI\r
5660AsmWriteMsr32 (\r
5661 IN UINT32 Index,\r
5662 IN UINT32 Value\r
5663 );\r
5664\r
5665\r
5666/**\r
62991af2 5667 Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and\r
ac644614 5668 writes the result back to the 64-bit MSR.\r
5669\r
62991af2 5670 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 5671 between the lower 32-bits of the read result and the value specified by\r
5672 OrData, and writes the result to the 64-bit MSR specified by Index. The lower\r
5673 32-bits of the value written to the MSR is returned. No parameter checking is\r
5674 performed on Index or OrData, and some of these may cause CPU exceptions. The\r
5675 caller must either guarantee that Index and OrData are valid, or the caller\r
5676 must establish proper exception handlers. This function is only available on\r
030cd1a2 5677 IA-32 and x64.\r
ac644614 5678\r
5679 @param Index The 32-bit MSR index to write.\r
5680 @param OrData The value to OR with the read value from the MSR.\r
5681\r
5682 @return The lower 32-bit value written to the MSR.\r
5683\r
5684**/\r
5685UINT32\r
5686EFIAPI\r
5687AsmMsrOr32 (\r
5688 IN UINT32 Index,\r
5689 IN UINT32 OrData\r
5690 );\r
5691\r
5692\r
5693/**\r
5694 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes\r
5695 the result back to the 64-bit MSR.\r
5696\r
5697 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
5698 lower 32-bits of the read result and the value specified by AndData, and\r
5699 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of\r
5700 the value written to the MSR is returned. No parameter checking is performed\r
5701 on Index or AndData, and some of these may cause CPU exceptions. The caller\r
5702 must either guarantee that Index and AndData are valid, or the caller must\r
5703 establish proper exception handlers. This function is only available on IA-32\r
030cd1a2 5704 and x64.\r
ac644614 5705\r
5706 @param Index The 32-bit MSR index to write.\r
5707 @param AndData The value to AND with the read value from the MSR.\r
5708\r
5709 @return The lower 32-bit value written to the MSR.\r
5710\r
5711**/\r
5712UINT32\r
5713EFIAPI\r
5714AsmMsrAnd32 (\r
5715 IN UINT32 Index,\r
5716 IN UINT32 AndData\r
5717 );\r
5718\r
5719\r
5720/**\r
62991af2 5721 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR\r
ac644614 5722 on the lower 32-bits, and writes the result back to the 64-bit MSR.\r
5723\r
5724 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
5725 lower 32-bits of the read result and the value specified by AndData\r
62991af2 5726 preserving the upper 32-bits, performs a bitwise OR between the\r
ac644614 5727 result of the AND operation and the value specified by OrData, and writes the\r
5728 result to the 64-bit MSR specified by Address. The lower 32-bits of the value\r
5729 written to the MSR is returned. No parameter checking is performed on Index,\r
5730 AndData, or OrData, and some of these may cause CPU exceptions. The caller\r
5731 must either guarantee that Index, AndData, and OrData are valid, or the\r
5732 caller must establish proper exception handlers. This function is only\r
030cd1a2 5733 available on IA-32 and x64.\r
ac644614 5734\r
5735 @param Index The 32-bit MSR index to write.\r
5736 @param AndData The value to AND with the read value from the MSR.\r
5737 @param OrData The value to OR with the result of the AND operation.\r
5738\r
5739 @return The lower 32-bit value written to the MSR.\r
5740\r
5741**/\r
5742UINT32\r
5743EFIAPI\r
5744AsmMsrAndThenOr32 (\r
5745 IN UINT32 Index,\r
5746 IN UINT32 AndData,\r
5747 IN UINT32 OrData\r
5748 );\r
5749\r
5750\r
5751/**\r
5752 Reads a bit field of an MSR.\r
5753\r
5754 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is\r
5755 specified by the StartBit and the EndBit. The value of the bit field is\r
5756 returned. The caller must either guarantee that Index is valid, or the caller\r
5757 must set up exception handlers to catch the exceptions. This function is only\r
030cd1a2 5758 available on IA-32 and x64.\r
ac644614 5759\r
5760 If StartBit is greater than 31, then ASSERT().\r
5761 If EndBit is greater than 31, then ASSERT().\r
5762 If EndBit is less than StartBit, then ASSERT().\r
5763\r
5764 @param Index The 32-bit MSR index to read.\r
5765 @param StartBit The ordinal of the least significant bit in the bit field.\r
5766 Range 0..31.\r
5767 @param EndBit The ordinal of the most significant bit in the bit field.\r
5768 Range 0..31.\r
5769\r
5770 @return The bit field read from the MSR.\r
5771\r
5772**/\r
5773UINT32\r
5774EFIAPI\r
5775AsmMsrBitFieldRead32 (\r
5776 IN UINT32 Index,\r
5777 IN UINTN StartBit,\r
5778 IN UINTN EndBit\r
5779 );\r
5780\r
5781\r
5782/**\r
5783 Writes a bit field to an MSR.\r
5784\r
2fe241a2 5785 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit\r
ac644614 5786 field is specified by the StartBit and the EndBit. All other bits in the\r
5787 destination MSR are preserved. The lower 32-bits of the MSR written is\r
9095d37b
LG
5788 returned. The caller must either guarantee that Index and the data written\r
5789 is valid, or the caller must set up exception handlers to catch the exceptions.\r
62991af2 5790 This function is only available on IA-32 and x64.\r
ac644614 5791\r
5792 If StartBit is greater than 31, then ASSERT().\r
5793 If EndBit is greater than 31, then ASSERT().\r
5794 If EndBit is less than StartBit, then ASSERT().\r
94952554 5795 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5796\r
5797 @param Index The 32-bit MSR index to write.\r
5798 @param StartBit The ordinal of the least significant bit in the bit field.\r
5799 Range 0..31.\r
5800 @param EndBit The ordinal of the most significant bit in the bit field.\r
5801 Range 0..31.\r
5802 @param Value New value of the bit field.\r
5803\r
5804 @return The lower 32-bit of the value written to the MSR.\r
5805\r
5806**/\r
5807UINT32\r
5808EFIAPI\r
5809AsmMsrBitFieldWrite32 (\r
5810 IN UINT32 Index,\r
5811 IN UINTN StartBit,\r
5812 IN UINTN EndBit,\r
5813 IN UINT32 Value\r
5814 );\r
5815\r
5816\r
5817/**\r
5818 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the\r
5819 result back to the bit field in the 64-bit MSR.\r
5820\r
62991af2 5821 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 5822 between the read result and the value specified by OrData, and writes the\r
5823 result to the 64-bit MSR specified by Index. The lower 32-bits of the value\r
5824 written to the MSR are returned. Extra left bits in OrData are stripped. The\r
5825 caller must either guarantee that Index and the data written is valid, or\r
5826 the caller must set up exception handlers to catch the exceptions. This\r
030cd1a2 5827 function is only available on IA-32 and x64.\r
ac644614 5828\r
5829 If StartBit is greater than 31, then ASSERT().\r
5830 If EndBit is greater than 31, then ASSERT().\r
5831 If EndBit is less than StartBit, then ASSERT().\r
94952554 5832 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5833\r
5834 @param Index The 32-bit MSR index to write.\r
5835 @param StartBit The ordinal of the least significant bit in the bit field.\r
5836 Range 0..31.\r
5837 @param EndBit The ordinal of the most significant bit in the bit field.\r
5838 Range 0..31.\r
5839 @param OrData The value to OR with the read value from the MSR.\r
5840\r
5841 @return The lower 32-bit of the value written to the MSR.\r
5842\r
5843**/\r
5844UINT32\r
5845EFIAPI\r
5846AsmMsrBitFieldOr32 (\r
5847 IN UINT32 Index,\r
5848 IN UINTN StartBit,\r
5849 IN UINTN EndBit,\r
5850 IN UINT32 OrData\r
5851 );\r
5852\r
5853\r
5854/**\r
5855 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
5856 result back to the bit field in the 64-bit MSR.\r
5857\r
5858 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
5859 read result and the value specified by AndData, and writes the result to the\r
5860 64-bit MSR specified by Index. The lower 32-bits of the value written to the\r
5861 MSR are returned. Extra left bits in AndData are stripped. The caller must\r
5862 either guarantee that Index and the data written is valid, or the caller must\r
5863 set up exception handlers to catch the exceptions. This function is only\r
030cd1a2 5864 available on IA-32 and x64.\r
ac644614 5865\r
5866 If StartBit is greater than 31, then ASSERT().\r
5867 If EndBit is greater than 31, then ASSERT().\r
5868 If EndBit is less than StartBit, then ASSERT().\r
94952554 5869 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5870\r
5871 @param Index The 32-bit MSR index to write.\r
5872 @param StartBit The ordinal of the least significant bit in the bit field.\r
5873 Range 0..31.\r
5874 @param EndBit The ordinal of the most significant bit in the bit field.\r
5875 Range 0..31.\r
5876 @param AndData The value to AND with the read value from the MSR.\r
5877\r
5878 @return The lower 32-bit of the value written to the MSR.\r
5879\r
5880**/\r
5881UINT32\r
5882EFIAPI\r
5883AsmMsrBitFieldAnd32 (\r
5884 IN UINT32 Index,\r
5885 IN UINTN StartBit,\r
5886 IN UINTN EndBit,\r
5887 IN UINT32 AndData\r
5888 );\r
5889\r
5890\r
5891/**\r
5892 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
62991af2 5893 bitwise OR, and writes the result back to the bit field in the\r
ac644614 5894 64-bit MSR.\r
5895\r
5896 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a\r
62991af2 5897 bitwise OR between the read result and the value specified by\r
ac644614 5898 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
5899 lower 32-bits of the value written to the MSR are returned. Extra left bits\r
5900 in both AndData and OrData are stripped. The caller must either guarantee\r
5901 that Index and the data written is valid, or the caller must set up exception\r
5902 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 5903 and x64.\r
ac644614 5904\r
5905 If StartBit is greater than 31, then ASSERT().\r
5906 If EndBit is greater than 31, then ASSERT().\r
5907 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
5908 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
5909 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5910\r
5911 @param Index The 32-bit MSR index to write.\r
5912 @param StartBit The ordinal of the least significant bit in the bit field.\r
5913 Range 0..31.\r
5914 @param EndBit The ordinal of the most significant bit in the bit field.\r
5915 Range 0..31.\r
5916 @param AndData The value to AND with the read value from the MSR.\r
5917 @param OrData The value to OR with the result of the AND operation.\r
5918\r
5919 @return The lower 32-bit of the value written to the MSR.\r
5920\r
5921**/\r
5922UINT32\r
5923EFIAPI\r
5924AsmMsrBitFieldAndThenOr32 (\r
5925 IN UINT32 Index,\r
5926 IN UINTN StartBit,\r
5927 IN UINTN EndBit,\r
5928 IN UINT32 AndData,\r
5929 IN UINT32 OrData\r
5930 );\r
5931\r
5932\r
5933/**\r
5934 Returns a 64-bit Machine Specific Register(MSR).\r
5935\r
5936 Reads and returns the 64-bit MSR specified by Index. No parameter checking is\r
5937 performed on Index, and some Index values may cause CPU exceptions. The\r
5938 caller must either guarantee that Index is valid, or the caller must set up\r
5939 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 5940 on IA-32 and x64.\r
ac644614 5941\r
5942 @param Index The 32-bit MSR index to read.\r
5943\r
5944 @return The value of the MSR identified by Index.\r
5945\r
5946**/\r
5947UINT64\r
5948EFIAPI\r
5949AsmReadMsr64 (\r
5950 IN UINT32 Index\r
5951 );\r
5952\r
5953\r
5954/**\r
5955 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the\r
5956 value.\r
5957\r
5958 Writes the 64-bit value specified by Value to the MSR specified by Index. The\r
5959 64-bit value written to the MSR is returned. No parameter checking is\r
5960 performed on Index or Value, and some of these may cause CPU exceptions. The\r
5961 caller must either guarantee that Index and Value are valid, or the caller\r
5962 must establish proper exception handlers. This function is only available on\r
030cd1a2 5963 IA-32 and x64.\r
ac644614 5964\r
5965 @param Index The 32-bit MSR index to write.\r
5966 @param Value The 64-bit value to write to the MSR.\r
5967\r
5968 @return Value\r
5969\r
5970**/\r
5971UINT64\r
5972EFIAPI\r
5973AsmWriteMsr64 (\r
5974 IN UINT32 Index,\r
5975 IN UINT64 Value\r
5976 );\r
5977\r
5978\r
5979/**\r
62991af2 5980 Reads a 64-bit MSR, performs a bitwise OR, and writes the result\r
ac644614 5981 back to the 64-bit MSR.\r
5982\r
62991af2 5983 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 5984 between the read result and the value specified by OrData, and writes the\r
5985 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
5986 returned. No parameter checking is performed on Index or OrData, and some of\r
5987 these may cause CPU exceptions. The caller must either guarantee that Index\r
5988 and OrData are valid, or the caller must establish proper exception handlers.\r
030cd1a2 5989 This function is only available on IA-32 and x64.\r
ac644614 5990\r
5991 @param Index The 32-bit MSR index to write.\r
5992 @param OrData The value to OR with the read value from the MSR.\r
5993\r
5994 @return The value written back to the MSR.\r
5995\r
5996**/\r
5997UINT64\r
5998EFIAPI\r
5999AsmMsrOr64 (\r
6000 IN UINT32 Index,\r
6001 IN UINT64 OrData\r
6002 );\r
6003\r
6004\r
6005/**\r
6006 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the\r
6007 64-bit MSR.\r
6008\r
6009 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
6010 read result and the value specified by OrData, and writes the result to the\r
6011 64-bit MSR specified by Index. The value written to the MSR is returned. No\r
6012 parameter checking is performed on Index or OrData, and some of these may\r
6013 cause CPU exceptions. The caller must either guarantee that Index and OrData\r
6014 are valid, or the caller must establish proper exception handlers. This\r
030cd1a2 6015 function is only available on IA-32 and x64.\r
ac644614 6016\r
6017 @param Index The 32-bit MSR index to write.\r
6018 @param AndData The value to AND with the read value from the MSR.\r
6019\r
6020 @return The value written back to the MSR.\r
6021\r
6022**/\r
6023UINT64\r
6024EFIAPI\r
6025AsmMsrAnd64 (\r
6026 IN UINT32 Index,\r
6027 IN UINT64 AndData\r
6028 );\r
6029\r
6030\r
6031/**\r
9095d37b 6032 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise\r
ac644614 6033 OR, and writes the result back to the 64-bit MSR.\r
6034\r
6035 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read\r
62991af2 6036 result and the value specified by AndData, performs a bitwise OR\r
ac644614 6037 between the result of the AND operation and the value specified by OrData,\r
6038 and writes the result to the 64-bit MSR specified by Index. The value written\r
6039 to the MSR is returned. No parameter checking is performed on Index, AndData,\r
6040 or OrData, and some of these may cause CPU exceptions. The caller must either\r
6041 guarantee that Index, AndData, and OrData are valid, or the caller must\r
6042 establish proper exception handlers. This function is only available on IA-32\r
030cd1a2 6043 and x64.\r
ac644614 6044\r
6045 @param Index The 32-bit MSR index to write.\r
6046 @param AndData The value to AND with the read value from the MSR.\r
6047 @param OrData The value to OR with the result of the AND operation.\r
6048\r
6049 @return The value written back to the MSR.\r
6050\r
6051**/\r
6052UINT64\r
6053EFIAPI\r
6054AsmMsrAndThenOr64 (\r
6055 IN UINT32 Index,\r
6056 IN UINT64 AndData,\r
6057 IN UINT64 OrData\r
6058 );\r
6059\r
6060\r
6061/**\r
6062 Reads a bit field of an MSR.\r
6063\r
6064 Reads the bit field in the 64-bit MSR. The bit field is specified by the\r
6065 StartBit and the EndBit. The value of the bit field is returned. The caller\r
6066 must either guarantee that Index is valid, or the caller must set up\r
6067 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 6068 on IA-32 and x64.\r
ac644614 6069\r
6070 If StartBit is greater than 63, then ASSERT().\r
6071 If EndBit is greater than 63, then ASSERT().\r
6072 If EndBit is less than StartBit, then ASSERT().\r
6073\r
6074 @param Index The 32-bit MSR index to read.\r
6075 @param StartBit The ordinal of the least significant bit in the bit field.\r
6076 Range 0..63.\r
6077 @param EndBit The ordinal of the most significant bit in the bit field.\r
6078 Range 0..63.\r
6079\r
6080 @return The value read from the MSR.\r
6081\r
6082**/\r
6083UINT64\r
6084EFIAPI\r
6085AsmMsrBitFieldRead64 (\r
6086 IN UINT32 Index,\r
6087 IN UINTN StartBit,\r
6088 IN UINTN EndBit\r
6089 );\r
6090\r
6091\r
6092/**\r
6093 Writes a bit field to an MSR.\r
6094\r
6095 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by\r
6096 the StartBit and the EndBit. All other bits in the destination MSR are\r
9095d37b
LG
6097 preserved. The MSR written is returned. The caller must either guarantee\r
6098 that Index and the data written is valid, or the caller must set up exception\r
62991af2 6099 handlers to catch the exceptions. This function is only available on IA-32 and x64.\r
ac644614 6100\r
6101 If StartBit is greater than 63, then ASSERT().\r
6102 If EndBit is greater than 63, then ASSERT().\r
6103 If EndBit is less than StartBit, then ASSERT().\r
94952554 6104 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6105\r
6106 @param Index The 32-bit MSR index to write.\r
6107 @param StartBit The ordinal of the least significant bit in the bit field.\r
6108 Range 0..63.\r
6109 @param EndBit The ordinal of the most significant bit in the bit field.\r
6110 Range 0..63.\r
6111 @param Value New value of the bit field.\r
6112\r
6113 @return The value written back to the MSR.\r
6114\r
6115**/\r
6116UINT64\r
6117EFIAPI\r
6118AsmMsrBitFieldWrite64 (\r
6119 IN UINT32 Index,\r
6120 IN UINTN StartBit,\r
6121 IN UINTN EndBit,\r
6122 IN UINT64 Value\r
6123 );\r
6124\r
6125\r
6126/**\r
62991af2 6127 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and\r
ac644614 6128 writes the result back to the bit field in the 64-bit MSR.\r
6129\r
62991af2 6130 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 6131 between the read result and the value specified by OrData, and writes the\r
6132 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
6133 returned. Extra left bits in OrData are stripped. The caller must either\r
6134 guarantee that Index and the data written is valid, or the caller must set up\r
6135 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 6136 on IA-32 and x64.\r
ac644614 6137\r
6138 If StartBit is greater than 63, then ASSERT().\r
6139 If EndBit is greater than 63, then ASSERT().\r
6140 If EndBit is less than StartBit, then ASSERT().\r
94952554 6141 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6142\r
6143 @param Index The 32-bit MSR index to write.\r
6144 @param StartBit The ordinal of the least significant bit in the bit field.\r
6145 Range 0..63.\r
6146 @param EndBit The ordinal of the most significant bit in the bit field.\r
6147 Range 0..63.\r
6148 @param OrData The value to OR with the read value from the bit field.\r
6149\r
6150 @return The value written back to the MSR.\r
6151\r
6152**/\r
6153UINT64\r
6154EFIAPI\r
6155AsmMsrBitFieldOr64 (\r
6156 IN UINT32 Index,\r
6157 IN UINTN StartBit,\r
6158 IN UINTN EndBit,\r
6159 IN UINT64 OrData\r
6160 );\r
6161\r
6162\r
6163/**\r
6164 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
6165 result back to the bit field in the 64-bit MSR.\r
6166\r
6167 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
6168 read result and the value specified by AndData, and writes the result to the\r
6169 64-bit MSR specified by Index. The value written to the MSR is returned.\r
6170 Extra left bits in AndData are stripped. The caller must either guarantee\r
6171 that Index and the data written is valid, or the caller must set up exception\r
6172 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 6173 and x64.\r
ac644614 6174\r
6175 If StartBit is greater than 63, then ASSERT().\r
6176 If EndBit is greater than 63, then ASSERT().\r
6177 If EndBit is less than StartBit, then ASSERT().\r
94952554 6178 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6179\r
6180 @param Index The 32-bit MSR index to write.\r
6181 @param StartBit The ordinal of the least significant bit in the bit field.\r
6182 Range 0..63.\r
6183 @param EndBit The ordinal of the most significant bit in the bit field.\r
6184 Range 0..63.\r
6185 @param AndData The value to AND with the read value from the bit field.\r
6186\r
6187 @return The value written back to the MSR.\r
6188\r
6189**/\r
6190UINT64\r
6191EFIAPI\r
6192AsmMsrBitFieldAnd64 (\r
6193 IN UINT32 Index,\r
6194 IN UINTN StartBit,\r
6195 IN UINTN EndBit,\r
6196 IN UINT64 AndData\r
6197 );\r
6198\r
6199\r
6200/**\r
6201 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
62991af2 6202 bitwise OR, and writes the result back to the bit field in the\r
ac644614 6203 64-bit MSR.\r
6204\r
6205 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by\r
62991af2 6206 a bitwise OR between the read result and the value specified by\r
ac644614 6207 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
6208 value written to the MSR is returned. Extra left bits in both AndData and\r
6209 OrData are stripped. The caller must either guarantee that Index and the data\r
6210 written is valid, or the caller must set up exception handlers to catch the\r
030cd1a2 6211 exceptions. This function is only available on IA-32 and x64.\r
ac644614 6212\r
6213 If StartBit is greater than 63, then ASSERT().\r
6214 If EndBit is greater than 63, then ASSERT().\r
6215 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
6216 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
6217 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6218\r
6219 @param Index The 32-bit MSR index to write.\r
6220 @param StartBit The ordinal of the least significant bit in the bit field.\r
6221 Range 0..63.\r
6222 @param EndBit The ordinal of the most significant bit in the bit field.\r
6223 Range 0..63.\r
6224 @param AndData The value to AND with the read value from the bit field.\r
6225 @param OrData The value to OR with the result of the AND operation.\r
6226\r
6227 @return The value written back to the MSR.\r
6228\r
6229**/\r
6230UINT64\r
6231EFIAPI\r
6232AsmMsrBitFieldAndThenOr64 (\r
6233 IN UINT32 Index,\r
6234 IN UINTN StartBit,\r
6235 IN UINTN EndBit,\r
6236 IN UINT64 AndData,\r
6237 IN UINT64 OrData\r
6238 );\r
6239\r
6240\r
6241/**\r
6242 Reads the current value of the EFLAGS register.\r
6243\r
6244 Reads and returns the current value of the EFLAGS register. This function is\r
030cd1a2 6245 only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a\r
6246 64-bit value on x64.\r
ac644614 6247\r
030cd1a2 6248 @return EFLAGS on IA-32 or RFLAGS on x64.\r
ac644614 6249\r
6250**/\r
6251UINTN\r
6252EFIAPI\r
6253AsmReadEflags (\r
6254 VOID\r
6255 );\r
6256\r
6257\r
6258/**\r
6259 Reads the current value of the Control Register 0 (CR0).\r
6260\r
6261 Reads and returns the current value of CR0. This function is only available\r
030cd1a2 6262 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6263 x64.\r
ac644614 6264\r
6265 @return The value of the Control Register 0 (CR0).\r
6266\r
6267**/\r
6268UINTN\r
6269EFIAPI\r
6270AsmReadCr0 (\r
6271 VOID\r
6272 );\r
6273\r
6274\r
6275/**\r
6276 Reads the current value of the Control Register 2 (CR2).\r
6277\r
6278 Reads and returns the current value of CR2. This function is only available\r
030cd1a2 6279 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6280 x64.\r
ac644614 6281\r
6282 @return The value of the Control Register 2 (CR2).\r
6283\r
6284**/\r
6285UINTN\r
6286EFIAPI\r
6287AsmReadCr2 (\r
6288 VOID\r
6289 );\r
6290\r
6291\r
6292/**\r
6293 Reads the current value of the Control Register 3 (CR3).\r
6294\r
6295 Reads and returns the current value of CR3. This function is only available\r
030cd1a2 6296 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6297 x64.\r
ac644614 6298\r
6299 @return The value of the Control Register 3 (CR3).\r
6300\r
6301**/\r
6302UINTN\r
6303EFIAPI\r
6304AsmReadCr3 (\r
6305 VOID\r
6306 );\r
6307\r
6308\r
6309/**\r
6310 Reads the current value of the Control Register 4 (CR4).\r
6311\r
6312 Reads and returns the current value of CR4. This function is only available\r
030cd1a2 6313 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6314 x64.\r
ac644614 6315\r
6316 @return The value of the Control Register 4 (CR4).\r
6317\r
6318**/\r
6319UINTN\r
6320EFIAPI\r
6321AsmReadCr4 (\r
6322 VOID\r
6323 );\r
6324\r
6325\r
6326/**\r
6327 Writes a value to Control Register 0 (CR0).\r
6328\r
6329 Writes and returns a new value to CR0. This function is only available on\r
030cd1a2 6330 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6331\r
6332 @param Cr0 The value to write to CR0.\r
6333\r
6334 @return The value written to CR0.\r
6335\r
6336**/\r
6337UINTN\r
6338EFIAPI\r
6339AsmWriteCr0 (\r
6340 UINTN Cr0\r
6341 );\r
6342\r
6343\r
6344/**\r
6345 Writes a value to Control Register 2 (CR2).\r
6346\r
6347 Writes and returns a new value to CR2. This function is only available on\r
030cd1a2 6348 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6349\r
6350 @param Cr2 The value to write to CR2.\r
6351\r
6352 @return The value written to CR2.\r
6353\r
6354**/\r
6355UINTN\r
6356EFIAPI\r
6357AsmWriteCr2 (\r
6358 UINTN Cr2\r
6359 );\r
6360\r
6361\r
6362/**\r
6363 Writes a value to Control Register 3 (CR3).\r
6364\r
6365 Writes and returns a new value to CR3. This function is only available on\r
030cd1a2 6366 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6367\r
6368 @param Cr3 The value to write to CR3.\r
6369\r
6370 @return The value written to CR3.\r
6371\r
6372**/\r
6373UINTN\r
6374EFIAPI\r
6375AsmWriteCr3 (\r
6376 UINTN Cr3\r
6377 );\r
6378\r
6379\r
6380/**\r
6381 Writes a value to Control Register 4 (CR4).\r
6382\r
6383 Writes and returns a new value to CR4. This function is only available on\r
030cd1a2 6384 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6385\r
6386 @param Cr4 The value to write to CR4.\r
6387\r
6388 @return The value written to CR4.\r
6389\r
6390**/\r
6391UINTN\r
6392EFIAPI\r
6393AsmWriteCr4 (\r
6394 UINTN Cr4\r
6395 );\r
6396\r
6397\r
6398/**\r
6399 Reads the current value of Debug Register 0 (DR0).\r
6400\r
6401 Reads and returns the current value of DR0. This function is only available\r
030cd1a2 6402 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6403 x64.\r
ac644614 6404\r
6405 @return The value of Debug Register 0 (DR0).\r
6406\r
6407**/\r
6408UINTN\r
6409EFIAPI\r
6410AsmReadDr0 (\r
6411 VOID\r
6412 );\r
6413\r
6414\r
6415/**\r
6416 Reads the current value of Debug Register 1 (DR1).\r
6417\r
6418 Reads and returns the current value of DR1. This function is only available\r
030cd1a2 6419 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6420 x64.\r
ac644614 6421\r
6422 @return The value of Debug Register 1 (DR1).\r
6423\r
6424**/\r
6425UINTN\r
6426EFIAPI\r
6427AsmReadDr1 (\r
6428 VOID\r
6429 );\r
6430\r
6431\r
6432/**\r
6433 Reads the current value of Debug Register 2 (DR2).\r
6434\r
6435 Reads and returns the current value of DR2. This function is only available\r
030cd1a2 6436 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6437 x64.\r
ac644614 6438\r
6439 @return The value of Debug Register 2 (DR2).\r
6440\r
6441**/\r
6442UINTN\r
6443EFIAPI\r
6444AsmReadDr2 (\r
6445 VOID\r
6446 );\r
6447\r
6448\r
6449/**\r
6450 Reads the current value of Debug Register 3 (DR3).\r
6451\r
6452 Reads and returns the current value of DR3. This function is only available\r
030cd1a2 6453 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6454 x64.\r
ac644614 6455\r
6456 @return The value of Debug Register 3 (DR3).\r
6457\r
6458**/\r
6459UINTN\r
6460EFIAPI\r
6461AsmReadDr3 (\r
6462 VOID\r
6463 );\r
6464\r
6465\r
6466/**\r
6467 Reads the current value of Debug Register 4 (DR4).\r
6468\r
6469 Reads and returns the current value of DR4. This function is only available\r
030cd1a2 6470 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6471 x64.\r
ac644614 6472\r
6473 @return The value of Debug Register 4 (DR4).\r
6474\r
6475**/\r
6476UINTN\r
6477EFIAPI\r
6478AsmReadDr4 (\r
6479 VOID\r
6480 );\r
6481\r
6482\r
6483/**\r
6484 Reads the current value of Debug Register 5 (DR5).\r
6485\r
6486 Reads and returns the current value of DR5. This function is only available\r
030cd1a2 6487 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6488 x64.\r
ac644614 6489\r
6490 @return The value of Debug Register 5 (DR5).\r
6491\r
6492**/\r
6493UINTN\r
6494EFIAPI\r
6495AsmReadDr5 (\r
6496 VOID\r
6497 );\r
6498\r
6499\r
6500/**\r
6501 Reads the current value of Debug Register 6 (DR6).\r
6502\r
6503 Reads and returns the current value of DR6. This function is only available\r
030cd1a2 6504 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6505 x64.\r
ac644614 6506\r
6507 @return The value of Debug Register 6 (DR6).\r
6508\r
6509**/\r
6510UINTN\r
6511EFIAPI\r
6512AsmReadDr6 (\r
6513 VOID\r
6514 );\r
6515\r
6516\r
6517/**\r
6518 Reads the current value of Debug Register 7 (DR7).\r
6519\r
6520 Reads and returns the current value of DR7. This function is only available\r
030cd1a2 6521 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6522 x64.\r
ac644614 6523\r
6524 @return The value of Debug Register 7 (DR7).\r
6525\r
6526**/\r
6527UINTN\r
6528EFIAPI\r
6529AsmReadDr7 (\r
6530 VOID\r
6531 );\r
6532\r
6533\r
6534/**\r
6535 Writes a value to Debug Register 0 (DR0).\r
6536\r
6537 Writes and returns a new value to DR0. This function is only available on\r
030cd1a2 6538 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6539\r
6540 @param Dr0 The value to write to Dr0.\r
6541\r
6542 @return The value written to Debug Register 0 (DR0).\r
6543\r
6544**/\r
6545UINTN\r
6546EFIAPI\r
6547AsmWriteDr0 (\r
6548 UINTN Dr0\r
6549 );\r
6550\r
6551\r
6552/**\r
6553 Writes a value to Debug Register 1 (DR1).\r
6554\r
6555 Writes and returns a new value to DR1. This function is only available on\r
030cd1a2 6556 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6557\r
6558 @param Dr1 The value to write to Dr1.\r
6559\r
6560 @return The value written to Debug Register 1 (DR1).\r
6561\r
6562**/\r
6563UINTN\r
6564EFIAPI\r
6565AsmWriteDr1 (\r
6566 UINTN Dr1\r
6567 );\r
6568\r
6569\r
6570/**\r
6571 Writes a value to Debug Register 2 (DR2).\r
6572\r
6573 Writes and returns a new value to DR2. This function is only available on\r
030cd1a2 6574 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6575\r
6576 @param Dr2 The value to write to Dr2.\r
6577\r
6578 @return The value written to Debug Register 2 (DR2).\r
6579\r
6580**/\r
6581UINTN\r
6582EFIAPI\r
6583AsmWriteDr2 (\r
6584 UINTN Dr2\r
6585 );\r
6586\r
6587\r
6588/**\r
6589 Writes a value to Debug Register 3 (DR3).\r
6590\r
6591 Writes and returns a new value to DR3. This function is only available on\r
030cd1a2 6592 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6593\r
6594 @param Dr3 The value to write to Dr3.\r
6595\r
6596 @return The value written to Debug Register 3 (DR3).\r
6597\r
6598**/\r
6599UINTN\r
6600EFIAPI\r
6601AsmWriteDr3 (\r
6602 UINTN Dr3\r
6603 );\r
6604\r
6605\r
6606/**\r
6607 Writes a value to Debug Register 4 (DR4).\r
6608\r
6609 Writes and returns a new value to DR4. This function is only available on\r
030cd1a2 6610 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6611\r
6612 @param Dr4 The value to write to Dr4.\r
6613\r
6614 @return The value written to Debug Register 4 (DR4).\r
6615\r
6616**/\r
6617UINTN\r
6618EFIAPI\r
6619AsmWriteDr4 (\r
6620 UINTN Dr4\r
6621 );\r
6622\r
6623\r
6624/**\r
6625 Writes a value to Debug Register 5 (DR5).\r
6626\r
6627 Writes and returns a new value to DR5. This function is only available on\r
030cd1a2 6628 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6629\r
6630 @param Dr5 The value to write to Dr5.\r
6631\r
6632 @return The value written to Debug Register 5 (DR5).\r
6633\r
6634**/\r
6635UINTN\r
6636EFIAPI\r
6637AsmWriteDr5 (\r
6638 UINTN Dr5\r
6639 );\r
6640\r
6641\r
6642/**\r
6643 Writes a value to Debug Register 6 (DR6).\r
6644\r
6645 Writes and returns a new value to DR6. This function is only available on\r
030cd1a2 6646 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6647\r
6648 @param Dr6 The value to write to Dr6.\r
6649\r
6650 @return The value written to Debug Register 6 (DR6).\r
6651\r
6652**/\r
6653UINTN\r
6654EFIAPI\r
6655AsmWriteDr6 (\r
6656 UINTN Dr6\r
6657 );\r
6658\r
6659\r
6660/**\r
6661 Writes a value to Debug Register 7 (DR7).\r
6662\r
6663 Writes and returns a new value to DR7. This function is only available on\r
030cd1a2 6664 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6665\r
6666 @param Dr7 The value to write to Dr7.\r
6667\r
6668 @return The value written to Debug Register 7 (DR7).\r
6669\r
6670**/\r
6671UINTN\r
6672EFIAPI\r
6673AsmWriteDr7 (\r
6674 UINTN Dr7\r
6675 );\r
6676\r
6677\r
6678/**\r
6679 Reads the current value of Code Segment Register (CS).\r
6680\r
6681 Reads and returns the current value of CS. This function is only available on\r
030cd1a2 6682 IA-32 and x64.\r
ac644614 6683\r
6684 @return The current value of CS.\r
6685\r
6686**/\r
6687UINT16\r
6688EFIAPI\r
6689AsmReadCs (\r
6690 VOID\r
6691 );\r
6692\r
6693\r
6694/**\r
6695 Reads the current value of Data Segment Register (DS).\r
6696\r
6697 Reads and returns the current value of DS. This function is only available on\r
030cd1a2 6698 IA-32 and x64.\r
ac644614 6699\r
6700 @return The current value of DS.\r
6701\r
6702**/\r
6703UINT16\r
6704EFIAPI\r
6705AsmReadDs (\r
6706 VOID\r
6707 );\r
6708\r
6709\r
6710/**\r
6711 Reads the current value of Extra Segment Register (ES).\r
6712\r
6713 Reads and returns the current value of ES. This function is only available on\r
030cd1a2 6714 IA-32 and x64.\r
ac644614 6715\r
6716 @return The current value of ES.\r
6717\r
6718**/\r
6719UINT16\r
6720EFIAPI\r
6721AsmReadEs (\r
6722 VOID\r
6723 );\r
6724\r
6725\r
6726/**\r
6727 Reads the current value of FS Data Segment Register (FS).\r
6728\r
6729 Reads and returns the current value of FS. This function is only available on\r
030cd1a2 6730 IA-32 and x64.\r
ac644614 6731\r
6732 @return The current value of FS.\r
6733\r
6734**/\r
6735UINT16\r
6736EFIAPI\r
6737AsmReadFs (\r
6738 VOID\r
6739 );\r
6740\r
6741\r
6742/**\r
6743 Reads the current value of GS Data Segment Register (GS).\r
6744\r
6745 Reads and returns the current value of GS. This function is only available on\r
030cd1a2 6746 IA-32 and x64.\r
ac644614 6747\r
6748 @return The current value of GS.\r
6749\r
6750**/\r
6751UINT16\r
6752EFIAPI\r
6753AsmReadGs (\r
6754 VOID\r
6755 );\r
6756\r
6757\r
6758/**\r
6759 Reads the current value of Stack Segment Register (SS).\r
6760\r
6761 Reads and returns the current value of SS. This function is only available on\r
030cd1a2 6762 IA-32 and x64.\r
ac644614 6763\r
6764 @return The current value of SS.\r
6765\r
6766**/\r
6767UINT16\r
6768EFIAPI\r
6769AsmReadSs (\r
6770 VOID\r
6771 );\r
6772\r
6773\r
6774/**\r
6775 Reads the current value of Task Register (TR).\r
6776\r
6777 Reads and returns the current value of TR. This function is only available on\r
030cd1a2 6778 IA-32 and x64.\r
ac644614 6779\r
6780 @return The current value of TR.\r
6781\r
6782**/\r
6783UINT16\r
6784EFIAPI\r
6785AsmReadTr (\r
6786 VOID\r
6787 );\r
6788\r
6789\r
6790/**\r
6791 Reads the current Global Descriptor Table Register(GDTR) descriptor.\r
6792\r
6793 Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r
030cd1a2 6794 function is only available on IA-32 and x64.\r
ac644614 6795\r
6796 If Gdtr is NULL, then ASSERT().\r
6797\r
af2dc6a7 6798 @param Gdtr The pointer to a GDTR descriptor.\r
ac644614 6799\r
6800**/\r
6801VOID\r
6802EFIAPI\r
6803AsmReadGdtr (\r
6804 OUT IA32_DESCRIPTOR *Gdtr\r
6805 );\r
6806\r
6807\r
6808/**\r
6809 Writes the current Global Descriptor Table Register (GDTR) descriptor.\r
6810\r
6811 Writes and the current GDTR descriptor specified by Gdtr. This function is\r
030cd1a2 6812 only available on IA-32 and x64.\r
ac644614 6813\r
6814 If Gdtr is NULL, then ASSERT().\r
6815\r
af2dc6a7 6816 @param Gdtr The pointer to a GDTR descriptor.\r
ac644614 6817\r
6818**/\r
6819VOID\r
6820EFIAPI\r
6821AsmWriteGdtr (\r
6822 IN CONST IA32_DESCRIPTOR *Gdtr\r
6823 );\r
6824\r
6825\r
6826/**\r
17f695ed 6827 Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.\r
ac644614 6828\r
6829 Reads and returns the current IDTR descriptor and returns it in Idtr. This\r
030cd1a2 6830 function is only available on IA-32 and x64.\r
ac644614 6831\r
6832 If Idtr is NULL, then ASSERT().\r
6833\r
af2dc6a7 6834 @param Idtr The pointer to a IDTR descriptor.\r
ac644614 6835\r
6836**/\r
6837VOID\r
6838EFIAPI\r
6839AsmReadIdtr (\r
6840 OUT IA32_DESCRIPTOR *Idtr\r
6841 );\r
6842\r
6843\r
6844/**\r
17f695ed 6845 Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.\r
ac644614 6846\r
6847 Writes the current IDTR descriptor and returns it in Idtr. This function is\r
030cd1a2 6848 only available on IA-32 and x64.\r
ac644614 6849\r
6850 If Idtr is NULL, then ASSERT().\r
6851\r
af2dc6a7 6852 @param Idtr The pointer to a IDTR descriptor.\r
ac644614 6853\r
6854**/\r
6855VOID\r
6856EFIAPI\r
6857AsmWriteIdtr (\r
6858 IN CONST IA32_DESCRIPTOR *Idtr\r
6859 );\r
6860\r
6861\r
6862/**\r
6863 Reads the current Local Descriptor Table Register(LDTR) selector.\r
6864\r
6865 Reads and returns the current 16-bit LDTR descriptor value. This function is\r
030cd1a2 6866 only available on IA-32 and x64.\r
ac644614 6867\r
6868 @return The current selector of LDT.\r
6869\r
6870**/\r
6871UINT16\r
6872EFIAPI\r
6873AsmReadLdtr (\r
6874 VOID\r
6875 );\r
6876\r
6877\r
6878/**\r
17f695ed 6879 Writes the current Local Descriptor Table Register (LDTR) selector.\r
ac644614 6880\r
6881 Writes and the current LDTR descriptor specified by Ldtr. This function is\r
030cd1a2 6882 only available on IA-32 and x64.\r
ac644614 6883\r
6884 @param Ldtr 16-bit LDTR selector value.\r
6885\r
6886**/\r
6887VOID\r
6888EFIAPI\r
6889AsmWriteLdtr (\r
6890 IN UINT16 Ldtr\r
6891 );\r
6892\r
6893\r
6894/**\r
6895 Save the current floating point/SSE/SSE2 context to a buffer.\r
6896\r
6897 Saves the current floating point/SSE/SSE2 state to the buffer specified by\r
6898 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r
030cd1a2 6899 available on IA-32 and x64.\r
ac644614 6900\r
6901 If Buffer is NULL, then ASSERT().\r
6902 If Buffer is not aligned on a 16-byte boundary, then ASSERT().\r
6903\r
af2dc6a7 6904 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
ac644614 6905\r
6906**/\r
6907VOID\r
6908EFIAPI\r
6909AsmFxSave (\r
6910 OUT IA32_FX_BUFFER *Buffer\r
6911 );\r
6912\r
6913\r
6914/**\r
6915 Restores the current floating point/SSE/SSE2 context from a buffer.\r
6916\r
6917 Restores the current floating point/SSE/SSE2 state from the buffer specified\r
6918 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r
030cd1a2 6919 only available on IA-32 and x64.\r
ac644614 6920\r
6921 If Buffer is NULL, then ASSERT().\r
6922 If Buffer is not aligned on a 16-byte boundary, then ASSERT().\r
6923 If Buffer was not saved with AsmFxSave(), then ASSERT().\r
6924\r
af2dc6a7 6925 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
ac644614 6926\r
6927**/\r
6928VOID\r
6929EFIAPI\r
6930AsmFxRestore (\r
6931 IN CONST IA32_FX_BUFFER *Buffer\r
6932 );\r
6933\r
6934\r
6935/**\r
6936 Reads the current value of 64-bit MMX Register #0 (MM0).\r
6937\r
6938 Reads and returns the current value of MM0. This function is only available\r
030cd1a2 6939 on IA-32 and x64.\r
ac644614 6940\r
6941 @return The current value of MM0.\r
6942\r
6943**/\r
6944UINT64\r
6945EFIAPI\r
6946AsmReadMm0 (\r
6947 VOID\r
6948 );\r
6949\r
6950\r
6951/**\r
6952 Reads the current value of 64-bit MMX Register #1 (MM1).\r
6953\r
6954 Reads and returns the current value of MM1. This function is only available\r
030cd1a2 6955 on IA-32 and x64.\r
ac644614 6956\r
6957 @return The current value of MM1.\r
6958\r
6959**/\r
6960UINT64\r
6961EFIAPI\r
6962AsmReadMm1 (\r
6963 VOID\r
6964 );\r
6965\r
6966\r
6967/**\r
6968 Reads the current value of 64-bit MMX Register #2 (MM2).\r
6969\r
6970 Reads and returns the current value of MM2. This function is only available\r
030cd1a2 6971 on IA-32 and x64.\r
ac644614 6972\r
6973 @return The current value of MM2.\r
6974\r
6975**/\r
6976UINT64\r
6977EFIAPI\r
6978AsmReadMm2 (\r
6979 VOID\r
6980 );\r
6981\r
6982\r
6983/**\r
6984 Reads the current value of 64-bit MMX Register #3 (MM3).\r
6985\r
6986 Reads and returns the current value of MM3. This function is only available\r
030cd1a2 6987 on IA-32 and x64.\r
ac644614 6988\r
6989 @return The current value of MM3.\r
6990\r
6991**/\r
6992UINT64\r
6993EFIAPI\r
6994AsmReadMm3 (\r
6995 VOID\r
6996 );\r
6997\r
6998\r
6999/**\r
7000 Reads the current value of 64-bit MMX Register #4 (MM4).\r
7001\r
7002 Reads and returns the current value of MM4. This function is only available\r
030cd1a2 7003 on IA-32 and x64.\r
ac644614 7004\r
7005 @return The current value of MM4.\r
7006\r
7007**/\r
7008UINT64\r
7009EFIAPI\r
7010AsmReadMm4 (\r
7011 VOID\r
7012 );\r
7013\r
7014\r
7015/**\r
7016 Reads the current value of 64-bit MMX Register #5 (MM5).\r
7017\r
7018 Reads and returns the current value of MM5. This function is only available\r
030cd1a2 7019 on IA-32 and x64.\r
ac644614 7020\r
7021 @return The current value of MM5.\r
7022\r
7023**/\r
7024UINT64\r
7025EFIAPI\r
7026AsmReadMm5 (\r
7027 VOID\r
7028 );\r
7029\r
7030\r
7031/**\r
7032 Reads the current value of 64-bit MMX Register #6 (MM6).\r
7033\r
7034 Reads and returns the current value of MM6. This function is only available\r
030cd1a2 7035 on IA-32 and x64.\r
ac644614 7036\r
7037 @return The current value of MM6.\r
7038\r
7039**/\r
7040UINT64\r
7041EFIAPI\r
7042AsmReadMm6 (\r
7043 VOID\r
7044 );\r
7045\r
7046\r
7047/**\r
7048 Reads the current value of 64-bit MMX Register #7 (MM7).\r
7049\r
7050 Reads and returns the current value of MM7. This function is only available\r
030cd1a2 7051 on IA-32 and x64.\r
ac644614 7052\r
7053 @return The current value of MM7.\r
7054\r
7055**/\r
7056UINT64\r
7057EFIAPI\r
7058AsmReadMm7 (\r
7059 VOID\r
7060 );\r
7061\r
7062\r
7063/**\r
7064 Writes the current value of 64-bit MMX Register #0 (MM0).\r
7065\r
7066 Writes the current value of MM0. This function is only available on IA32 and\r
030cd1a2 7067 x64.\r
ac644614 7068\r
7069 @param Value The 64-bit value to write to MM0.\r
7070\r
7071**/\r
7072VOID\r
7073EFIAPI\r
7074AsmWriteMm0 (\r
7075 IN UINT64 Value\r
7076 );\r
7077\r
7078\r
7079/**\r
7080 Writes the current value of 64-bit MMX Register #1 (MM1).\r
7081\r
7082 Writes the current value of MM1. This function is only available on IA32 and\r
030cd1a2 7083 x64.\r
ac644614 7084\r
7085 @param Value The 64-bit value to write to MM1.\r
7086\r
7087**/\r
7088VOID\r
7089EFIAPI\r
7090AsmWriteMm1 (\r
7091 IN UINT64 Value\r
7092 );\r
7093\r
7094\r
7095/**\r
7096 Writes the current value of 64-bit MMX Register #2 (MM2).\r
7097\r
7098 Writes the current value of MM2. This function is only available on IA32 and\r
030cd1a2 7099 x64.\r
ac644614 7100\r
7101 @param Value The 64-bit value to write to MM2.\r
7102\r
7103**/\r
7104VOID\r
7105EFIAPI\r
7106AsmWriteMm2 (\r
7107 IN UINT64 Value\r
7108 );\r
7109\r
7110\r
7111/**\r
7112 Writes the current value of 64-bit MMX Register #3 (MM3).\r
7113\r
7114 Writes the current value of MM3. This function is only available on IA32 and\r
030cd1a2 7115 x64.\r
ac644614 7116\r
7117 @param Value The 64-bit value to write to MM3.\r
7118\r
7119**/\r
7120VOID\r
7121EFIAPI\r
7122AsmWriteMm3 (\r
7123 IN UINT64 Value\r
7124 );\r
7125\r
7126\r
7127/**\r
7128 Writes the current value of 64-bit MMX Register #4 (MM4).\r
7129\r
7130 Writes the current value of MM4. This function is only available on IA32 and\r
030cd1a2 7131 x64.\r
ac644614 7132\r
7133 @param Value The 64-bit value to write to MM4.\r
7134\r
7135**/\r
7136VOID\r
7137EFIAPI\r
7138AsmWriteMm4 (\r
7139 IN UINT64 Value\r
7140 );\r
7141\r
7142\r
7143/**\r
7144 Writes the current value of 64-bit MMX Register #5 (MM5).\r
7145\r
7146 Writes the current value of MM5. This function is only available on IA32 and\r
030cd1a2 7147 x64.\r
ac644614 7148\r
7149 @param Value The 64-bit value to write to MM5.\r
7150\r
7151**/\r
7152VOID\r
7153EFIAPI\r
7154AsmWriteMm5 (\r
7155 IN UINT64 Value\r
7156 );\r
7157\r
7158\r
7159/**\r
7160 Writes the current value of 64-bit MMX Register #6 (MM6).\r
7161\r
7162 Writes the current value of MM6. This function is only available on IA32 and\r
030cd1a2 7163 x64.\r
ac644614 7164\r
7165 @param Value The 64-bit value to write to MM6.\r
7166\r
7167**/\r
7168VOID\r
7169EFIAPI\r
7170AsmWriteMm6 (\r
7171 IN UINT64 Value\r
7172 );\r
7173\r
7174\r
7175/**\r
7176 Writes the current value of 64-bit MMX Register #7 (MM7).\r
7177\r
7178 Writes the current value of MM7. This function is only available on IA32 and\r
030cd1a2 7179 x64.\r
ac644614 7180\r
7181 @param Value The 64-bit value to write to MM7.\r
7182\r
7183**/\r
7184VOID\r
7185EFIAPI\r
7186AsmWriteMm7 (\r
7187 IN UINT64 Value\r
7188 );\r
7189\r
7190\r
7191/**\r
7192 Reads the current value of Time Stamp Counter (TSC).\r
7193\r
7194 Reads and returns the current value of TSC. This function is only available\r
030cd1a2 7195 on IA-32 and x64.\r
ac644614 7196\r
7197 @return The current value of TSC\r
7198\r
7199**/\r
7200UINT64\r
7201EFIAPI\r
7202AsmReadTsc (\r
7203 VOID\r
7204 );\r
7205\r
7206\r
7207/**\r
7208 Reads the current value of a Performance Counter (PMC).\r
7209\r
7210 Reads and returns the current value of performance counter specified by\r
030cd1a2 7211 Index. This function is only available on IA-32 and x64.\r
ac644614 7212\r
7213 @param Index The 32-bit Performance Counter index to read.\r
7214\r
7215 @return The value of the PMC specified by Index.\r
7216\r
7217**/\r
7218UINT64\r
7219EFIAPI\r
7220AsmReadPmc (\r
7221 IN UINT32 Index\r
7222 );\r
7223\r
7224\r
7225/**\r
7226 Sets up a monitor buffer that is used by AsmMwait().\r
7227\r
7228 Executes a MONITOR instruction with the register state specified by Eax, Ecx\r
030cd1a2 7229 and Edx. Returns Eax. This function is only available on IA-32 and x64.\r
ac644614 7230\r
7231 @param Eax The value to load into EAX or RAX before executing the MONITOR\r
7232 instruction.\r
7233 @param Ecx The value to load into ECX or RCX before executing the MONITOR\r
7234 instruction.\r
7235 @param Edx The value to load into EDX or RDX before executing the MONITOR\r
7236 instruction.\r
7237\r
7238 @return Eax\r
7239\r
7240**/\r
7241UINTN\r
7242EFIAPI\r
7243AsmMonitor (\r
7244 IN UINTN Eax,\r
7245 IN UINTN Ecx,\r
7246 IN UINTN Edx\r
7247 );\r
7248\r
7249\r
7250/**\r
7251 Executes an MWAIT instruction.\r
7252\r
7253 Executes an MWAIT instruction with the register state specified by Eax and\r
030cd1a2 7254 Ecx. Returns Eax. This function is only available on IA-32 and x64.\r
ac644614 7255\r
7256 @param Eax The value to load into EAX or RAX before executing the MONITOR\r
7257 instruction.\r
7258 @param Ecx The value to load into ECX or RCX before executing the MONITOR\r
7259 instruction.\r
7260\r
7261 @return Eax\r
7262\r
7263**/\r
7264UINTN\r
7265EFIAPI\r
7266AsmMwait (\r
7267 IN UINTN Eax,\r
7268 IN UINTN Ecx\r
7269 );\r
7270\r
7271\r
7272/**\r
7273 Executes a WBINVD instruction.\r
7274\r
7275 Executes a WBINVD instruction. This function is only available on IA-32 and\r
030cd1a2 7276 x64.\r
ac644614 7277\r
7278**/\r
7279VOID\r
7280EFIAPI\r
7281AsmWbinvd (\r
7282 VOID\r
7283 );\r
7284\r
7285\r
7286/**\r
7287 Executes a INVD instruction.\r
7288\r
7289 Executes a INVD instruction. This function is only available on IA-32 and\r
030cd1a2 7290 x64.\r
ac644614 7291\r
7292**/\r
7293VOID\r
7294EFIAPI\r
7295AsmInvd (\r
7296 VOID\r
7297 );\r
7298\r
7299\r
7300/**\r
7301 Flushes a cache line from all the instruction and data caches within the\r
7302 coherency domain of the CPU.\r
7303\r
7304 Flushed the cache line specified by LinearAddress, and returns LinearAddress.\r
030cd1a2 7305 This function is only available on IA-32 and x64.\r
ac644614 7306\r
7307 @param LinearAddress The address of the cache line to flush. If the CPU is\r
7308 in a physical addressing mode, then LinearAddress is a\r
7309 physical address. If the CPU is in a virtual\r
7310 addressing mode, then LinearAddress is a virtual\r
7311 address.\r
7312\r
af2dc6a7 7313 @return LinearAddress.\r
ac644614 7314**/\r
7315VOID *\r
7316EFIAPI\r
7317AsmFlushCacheLine (\r
7318 IN VOID *LinearAddress\r
7319 );\r
7320\r
7321\r
7322/**\r
7323 Enables the 32-bit paging mode on the CPU.\r
7324\r
7325 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r
7326 must be properly initialized prior to calling this service. This function\r
7327 assumes the current execution mode is 32-bit protected mode. This function is\r
7328 only available on IA-32. After the 32-bit paging mode is enabled, control is\r
7329 transferred to the function specified by EntryPoint using the new stack\r
7330 specified by NewStack and passing in the parameters specified by Context1 and\r
7331 Context2. Context1 and Context2 are optional and may be NULL. The function\r
7332 EntryPoint must never return.\r
7333\r
7334 If the current execution mode is not 32-bit protected mode, then ASSERT().\r
7335 If EntryPoint is NULL, then ASSERT().\r
7336 If NewStack is NULL, then ASSERT().\r
7337\r
7338 There are a number of constraints that must be followed before calling this\r
7339 function:\r
7340 1) Interrupts must be disabled.\r
7341 2) The caller must be in 32-bit protected mode with flat descriptors. This\r
7342 means all descriptors must have a base of 0 and a limit of 4GB.\r
7343 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat\r
7344 descriptors.\r
7345 4) CR3 must point to valid page tables that will be used once the transition\r
7346 is complete, and those page tables must guarantee that the pages for this\r
7347 function and the stack are identity mapped.\r
7348\r
7349 @param EntryPoint A pointer to function to call with the new stack after\r
7350 paging is enabled.\r
7351 @param Context1 A pointer to the context to pass into the EntryPoint\r
7352 function as the first parameter after paging is enabled.\r
7353 @param Context2 A pointer to the context to pass into the EntryPoint\r
7354 function as the second parameter after paging is enabled.\r
7355 @param NewStack A pointer to the new stack to use for the EntryPoint\r
7356 function after paging is enabled.\r
7357\r
7358**/\r
7359VOID\r
7360EFIAPI\r
7361AsmEnablePaging32 (\r
7362 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
7363 IN VOID *Context1, OPTIONAL\r
7364 IN VOID *Context2, OPTIONAL\r
7365 IN VOID *NewStack\r
7366 );\r
7367\r
7368\r
7369/**\r
7370 Disables the 32-bit paging mode on the CPU.\r
7371\r
7372 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected\r
7373 mode. This function assumes the current execution mode is 32-paged protected\r
7374 mode. This function is only available on IA-32. After the 32-bit paging mode\r
7375 is disabled, control is transferred to the function specified by EntryPoint\r
7376 using the new stack specified by NewStack and passing in the parameters\r
7377 specified by Context1 and Context2. Context1 and Context2 are optional and\r
7378 may be NULL. The function EntryPoint must never return.\r
7379\r
7380 If the current execution mode is not 32-bit paged mode, then ASSERT().\r
7381 If EntryPoint is NULL, then ASSERT().\r
7382 If NewStack is NULL, then ASSERT().\r
7383\r
7384 There are a number of constraints that must be followed before calling this\r
7385 function:\r
7386 1) Interrupts must be disabled.\r
7387 2) The caller must be in 32-bit paged mode.\r
7388 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.\r
7389 4) CR3 must point to valid page tables that guarantee that the pages for\r
7390 this function and the stack are identity mapped.\r
7391\r
7392 @param EntryPoint A pointer to function to call with the new stack after\r
7393 paging is disabled.\r
7394 @param Context1 A pointer to the context to pass into the EntryPoint\r
7395 function as the first parameter after paging is disabled.\r
7396 @param Context2 A pointer to the context to pass into the EntryPoint\r
7397 function as the second parameter after paging is\r
7398 disabled.\r
7399 @param NewStack A pointer to the new stack to use for the EntryPoint\r
7400 function after paging is disabled.\r
7401\r
7402**/\r
7403VOID\r
7404EFIAPI\r
7405AsmDisablePaging32 (\r
7406 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
7407 IN VOID *Context1, OPTIONAL\r
7408 IN VOID *Context2, OPTIONAL\r
7409 IN VOID *NewStack\r
7410 );\r
7411\r
7412\r
7413/**\r
7414 Enables the 64-bit paging mode on the CPU.\r
7415\r
7416 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r
7417 must be properly initialized prior to calling this service. This function\r
7418 assumes the current execution mode is 32-bit protected mode with flat\r
7419 descriptors. This function is only available on IA-32. After the 64-bit\r
7420 paging mode is enabled, control is transferred to the function specified by\r
7421 EntryPoint using the new stack specified by NewStack and passing in the\r
7422 parameters specified by Context1 and Context2. Context1 and Context2 are\r
7423 optional and may be 0. The function EntryPoint must never return.\r
7424\r
7425 If the current execution mode is not 32-bit protected mode with flat\r
7426 descriptors, then ASSERT().\r
7427 If EntryPoint is 0, then ASSERT().\r
7428 If NewStack is 0, then ASSERT().\r
7429\r
17f695ed 7430 @param Cs The 16-bit selector to load in the CS before EntryPoint\r
ac644614 7431 is called. The descriptor in the GDT that this selector\r
7432 references must be setup for long mode.\r
7433 @param EntryPoint The 64-bit virtual address of the function to call with\r
7434 the new stack after paging is enabled.\r
7435 @param Context1 The 64-bit virtual address of the context to pass into\r
7436 the EntryPoint function as the first parameter after\r
7437 paging is enabled.\r
7438 @param Context2 The 64-bit virtual address of the context to pass into\r
7439 the EntryPoint function as the second parameter after\r
7440 paging is enabled.\r
7441 @param NewStack The 64-bit virtual address of the new stack to use for\r
7442 the EntryPoint function after paging is enabled.\r
7443\r
7444**/\r
7445VOID\r
7446EFIAPI\r
7447AsmEnablePaging64 (\r
17f695ed 7448 IN UINT16 Cs,\r
ac644614 7449 IN UINT64 EntryPoint,\r
7450 IN UINT64 Context1, OPTIONAL\r
7451 IN UINT64 Context2, OPTIONAL\r
7452 IN UINT64 NewStack\r
7453 );\r
7454\r
7455\r
7456/**\r
7457 Disables the 64-bit paging mode on the CPU.\r
7458\r
7459 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected\r
7460 mode. This function assumes the current execution mode is 64-paging mode.\r
030cd1a2 7461 This function is only available on x64. After the 64-bit paging mode is\r
ac644614 7462 disabled, control is transferred to the function specified by EntryPoint\r
7463 using the new stack specified by NewStack and passing in the parameters\r
7464 specified by Context1 and Context2. Context1 and Context2 are optional and\r
7465 may be 0. The function EntryPoint must never return.\r
7466\r
7467 If the current execution mode is not 64-bit paged mode, then ASSERT().\r
7468 If EntryPoint is 0, then ASSERT().\r
7469 If NewStack is 0, then ASSERT().\r
7470\r
17f695ed 7471 @param Cs The 16-bit selector to load in the CS before EntryPoint\r
ac644614 7472 is called. The descriptor in the GDT that this selector\r
7473 references must be setup for 32-bit protected mode.\r
7474 @param EntryPoint The 64-bit virtual address of the function to call with\r
7475 the new stack after paging is disabled.\r
7476 @param Context1 The 64-bit virtual address of the context to pass into\r
7477 the EntryPoint function as the first parameter after\r
7478 paging is disabled.\r
7479 @param Context2 The 64-bit virtual address of the context to pass into\r
7480 the EntryPoint function as the second parameter after\r
7481 paging is disabled.\r
7482 @param NewStack The 64-bit virtual address of the new stack to use for\r
7483 the EntryPoint function after paging is disabled.\r
7484\r
7485**/\r
7486VOID\r
7487EFIAPI\r
7488AsmDisablePaging64 (\r
17f695ed 7489 IN UINT16 Cs,\r
ac644614 7490 IN UINT32 EntryPoint,\r
7491 IN UINT32 Context1, OPTIONAL\r
7492 IN UINT32 Context2, OPTIONAL\r
7493 IN UINT32 NewStack\r
7494 );\r
7495\r
7496\r
7497//\r
7498// 16-bit thunking services\r
7499//\r
7500\r
7501/**\r
7502 Retrieves the properties for 16-bit thunk functions.\r
7503\r
7504 Computes the size of the buffer and stack below 1MB required to use the\r
7505 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This\r
7506 buffer size is returned in RealModeBufferSize, and the stack size is returned\r
7507 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,\r
7508 then the actual minimum stack size is ExtraStackSize plus the maximum number\r
7509 of bytes that need to be passed to the 16-bit real mode code.\r
9095d37b 7510\r
ac644614 7511 If RealModeBufferSize is NULL, then ASSERT().\r
7512 If ExtraStackSize is NULL, then ASSERT().\r
7513\r
7514 @param RealModeBufferSize A pointer to the size of the buffer below 1MB\r
7515 required to use the 16-bit thunk functions.\r
7516 @param ExtraStackSize A pointer to the extra size of stack below 1MB\r
7517 that the 16-bit thunk functions require for\r
7518 temporary storage in the transition to and from\r
7519 16-bit real mode.\r
7520\r
7521**/\r
7522VOID\r
7523EFIAPI\r
7524AsmGetThunk16Properties (\r
7525 OUT UINT32 *RealModeBufferSize,\r
7526 OUT UINT32 *ExtraStackSize\r
7527 );\r
7528\r
7529\r
7530/**\r
7531 Prepares all structures a code required to use AsmThunk16().\r
7532\r
7533 Prepares all structures and code required to use AsmThunk16().\r
9095d37b 7534\r
8243b089 7535 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the\r
7536 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.\r
ac644614 7537\r
7538 If ThunkContext is NULL, then ASSERT().\r
7539\r
7540 @param ThunkContext A pointer to the context structure that describes the\r
7541 16-bit real mode code to call.\r
7542\r
7543**/\r
7544VOID\r
7545EFIAPI\r
7546AsmPrepareThunk16 (\r
1445300f 7547 IN OUT THUNK_CONTEXT *ThunkContext\r
ac644614 7548 );\r
7549\r
7550\r
7551/**\r
7552 Transfers control to a 16-bit real mode entry point and returns the results.\r
7553\r
7554 Transfers control to a 16-bit real mode entry point and returns the results.\r
17f695ed 7555 AsmPrepareThunk16() must be called with ThunkContext before this function is used.\r
7556 This function must be called with interrupts disabled.\r
7557\r
9095d37b
LG
7558 The register state from the RealModeState field of ThunkContext is restored just prior\r
7559 to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,\r
17f695ed 7560 which is used to set the interrupt state when a 16-bit real mode entry point is called.\r
7561 Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.\r
9095d37b
LG
7562 The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to\r
7563 the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.\r
17f695ed 7564 The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,\r
9095d37b
LG
7565 so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment\r
7566 and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry\r
7567 point must exit with a RETF instruction. The register state is captured into RealModeState immediately\r
17f695ed 7568 after the RETF instruction is executed.\r
9095d37b
LG
7569\r
7570 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,\r
7571 or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure\r
7572 the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.\r
7573\r
7574 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,\r
7575 then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.\r
17f695ed 7576 This includes the base vectors, the interrupt masks, and the edge/level trigger mode.\r
9095d37b
LG
7577\r
7578 If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code\r
17f695ed 7579 is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.\r
9095d37b
LG
7580\r
7581 If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in\r
7582 ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to\r
17f695ed 7583 disable the A20 mask.\r
9095d37b
LG
7584\r
7585 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in\r
7586 ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,\r
17f695ed 7587 then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.\r
9095d37b
LG
7588\r
7589 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in\r
17f695ed 7590 ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.\r
9095d37b 7591\r
ac644614 7592 If ThunkContext is NULL, then ASSERT().\r
7593 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().\r
9095d37b 7594 If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in\r
17f695ed 7595 ThunkAttributes, then ASSERT().\r
ac644614 7596\r
8243b089 7597 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the\r
af2dc6a7 7598 virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.\r
52fa075c 7599\r
ac644614 7600 @param ThunkContext A pointer to the context structure that describes the\r
7601 16-bit real mode code to call.\r
7602\r
7603**/\r
7604VOID\r
7605EFIAPI\r
7606AsmThunk16 (\r
7607 IN OUT THUNK_CONTEXT *ThunkContext\r
7608 );\r
7609\r
7610\r
7611/**\r
7612 Prepares all structures and code for a 16-bit real mode thunk, transfers\r
7613 control to a 16-bit real mode entry point, and returns the results.\r
7614\r
7615 Prepares all structures and code for a 16-bit real mode thunk, transfers\r
7616 control to a 16-bit real mode entry point, and returns the results. If the\r
7617 caller only need to perform a single 16-bit real mode thunk, then this\r
7618 service should be used. If the caller intends to make more than one 16-bit\r
7619 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called\r
7620 once and AsmThunk16() can be called for each 16-bit real mode thunk.\r
7621\r
8243b089 7622 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the\r
7623 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.\r
52fa075c 7624\r
17f695ed 7625 See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.\r
ac644614 7626\r
7627 @param ThunkContext A pointer to the context structure that describes the\r
7628 16-bit real mode code to call.\r
7629\r
7630**/\r
7631VOID\r
7632EFIAPI\r
7633AsmPrepareAndThunk16 (\r
7634 IN OUT THUNK_CONTEXT *ThunkContext\r
7635 );\r
7636\r
3cfc7813
QL
7637/**\r
7638 Generates a 16-bit random number through RDRAND instruction.\r
7639\r
7640 if Rand is NULL, then ASSERT().\r
7641\r
7642 @param[out] Rand Buffer pointer to store the random result.\r
7643\r
7644 @retval TRUE RDRAND call was successful.\r
7645 @retval FALSE Failed attempts to call RDRAND.\r
7646\r
7647 **/\r
7648BOOLEAN\r
7649EFIAPI\r
7650AsmRdRand16 (\r
7651 OUT UINT16 *Rand\r
7652 );\r
7653\r
7654/**\r
7655 Generates a 32-bit random number through RDRAND instruction.\r
7656\r
7657 if Rand is NULL, then ASSERT().\r
7658\r
7659 @param[out] Rand Buffer pointer to store the random result.\r
7660\r
7661 @retval TRUE RDRAND call was successful.\r
7662 @retval FALSE Failed attempts to call RDRAND.\r
7663\r
7664**/\r
7665BOOLEAN\r
7666EFIAPI\r
7667AsmRdRand32 (\r
7668 OUT UINT32 *Rand\r
7669 );\r
7670\r
7671/**\r
7672 Generates a 64-bit random number through RDRAND instruction.\r
7673\r
7674 if Rand is NULL, then ASSERT().\r
7675\r
7676 @param[out] Rand Buffer pointer to store the random result.\r
7677\r
7678 @retval TRUE RDRAND call was successful.\r
7679 @retval FALSE Failed attempts to call RDRAND.\r
7680\r
7681**/\r
7682BOOLEAN\r
7683EFIAPI\r
7684AsmRdRand64 (\r
7685 OUT UINT64 *Rand\r
7686 );\r
7687\r
364a5474 7688/**\r
47595ac0 7689 Load given selector into TR register.\r
364a5474
JW
7690\r
7691 @param[in] Selector Task segment selector\r
7692**/\r
7693VOID\r
7694EFIAPI\r
7695AsmWriteTr (\r
7696 IN UINT16 Selector\r
7697 );\r
7698\r
2ecd8299
HW
7699/**\r
7700 Performs a serializing operation on all load-from-memory instructions that\r
7701 were issued prior the AsmLfence function.\r
7702\r
7703 Executes a LFENCE instruction. This function is only available on IA-32 and x64.\r
7704\r
7705**/\r
7706VOID\r
7707EFIAPI\r
7708AsmLfence (\r
7709 VOID\r
7710 );\r
7711\r
8596c140
LE
7712/**\r
7713 Patch the immediate operand of an IA32 or X64 instruction such that the byte,\r
7714 word, dword or qword operand is encoded at the end of the instruction's\r
7715 binary representation.\r
7716\r
7717 This function should be used to update object code that was compiled with\r
7718 NASM from assembly source code. Example:\r
7719\r
7720 NASM source code:\r
7721\r
7722 mov eax, strict dword 0 ; the imm32 zero operand will be patched\r
7723 ASM_PFX(gPatchCr3):\r
7724 mov cr3, eax\r
7725\r
7726 C source code:\r
7727\r
7728 X86_ASSEMBLY_PATCH_LABEL gPatchCr3;\r
7729 PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);\r
7730\r
7731 @param[out] InstructionEnd Pointer right past the instruction to patch. The\r
7732 immediate operand to patch is expected to\r
7733 comprise the trailing bytes of the instruction.\r
7734 If InstructionEnd is closer to address 0 than\r
7735 ValueSize permits, then ASSERT().\r
7736\r
7737 @param[in] PatchValue The constant to write to the immediate operand.\r
7738 The caller is responsible for ensuring that\r
7739 PatchValue can be represented in the byte, word,\r
7740 dword or qword operand (as indicated through\r
7741 ValueSize); otherwise ASSERT().\r
7742\r
7743 @param[in] ValueSize The size of the operand in bytes; must be 1, 2,\r
7744 4, or 8. ASSERT() otherwise.\r
7745**/\r
7746VOID\r
7747EFIAPI\r
7748PatchInstructionX86 (\r
7749 OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,\r
7750 IN UINT64 PatchValue,\r
7751 IN UINTN ValueSize\r
7752 );\r
7753\r
de4f7f52
LE
7754#endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
7755#endif // !defined (__BASE_LIB__)\r