]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/BaseLib.h
MdePkg/BaseLib: Introduce new SpeculationBarrier API
[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
d9f1cac5
HW
5114\r
5115/**\r
5116 Uses as a barrier to stop speculative execution.\r
5117\r
5118 Ensures that no later instruction will execute speculatively, until all prior\r
5119 instructions have completed.\r
5120\r
5121**/\r
5122VOID\r
5123EFIAPI\r
5124SpeculationBarrier (\r
5125 VOID\r
5126 );\r
5127\r
5128\r
fd163050 5129#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
1106ffe1 5130///\r
af2dc6a7 5131/// IA32 and x64 Specific Functions.\r
5132/// Byte packed structure for 16-bit Real Mode EFLAGS.\r
1106ffe1 5133///\r
ac644614 5134typedef union {\r
5135 struct {\r
af2dc6a7 5136 UINT32 CF:1; ///< Carry Flag.\r
5137 UINT32 Reserved_0:1; ///< Reserved.\r
5138 UINT32 PF:1; ///< Parity Flag.\r
5139 UINT32 Reserved_1:1; ///< Reserved.\r
5140 UINT32 AF:1; ///< Auxiliary Carry Flag.\r
5141 UINT32 Reserved_2:1; ///< Reserved.\r
5142 UINT32 ZF:1; ///< Zero Flag.\r
5143 UINT32 SF:1; ///< Sign Flag.\r
5144 UINT32 TF:1; ///< Trap Flag.\r
5145 UINT32 IF:1; ///< Interrupt Enable Flag.\r
5146 UINT32 DF:1; ///< Direction Flag.\r
5147 UINT32 OF:1; ///< Overflow Flag.\r
5148 UINT32 IOPL:2; ///< I/O Privilege Level.\r
5149 UINT32 NT:1; ///< Nested Task.\r
5150 UINT32 Reserved_3:1; ///< Reserved.\r
ac644614 5151 } Bits;\r
5152 UINT16 Uint16;\r
5153} IA32_FLAGS16;\r
5154\r
1106ffe1 5155///\r
af2dc6a7 5156/// Byte packed structure for EFLAGS/RFLAGS.\r
5157/// 32-bits on IA-32.\r
5158/// 64-bits on x64. The upper 32-bits on x64 are reserved.\r
1106ffe1 5159///\r
ac644614 5160typedef union {\r
5161 struct {\r
af2dc6a7 5162 UINT32 CF:1; ///< Carry Flag.\r
5163 UINT32 Reserved_0:1; ///< Reserved.\r
5164 UINT32 PF:1; ///< Parity Flag.\r
5165 UINT32 Reserved_1:1; ///< Reserved.\r
5166 UINT32 AF:1; ///< Auxiliary Carry Flag.\r
5167 UINT32 Reserved_2:1; ///< Reserved.\r
5168 UINT32 ZF:1; ///< Zero Flag.\r
5169 UINT32 SF:1; ///< Sign Flag.\r
5170 UINT32 TF:1; ///< Trap Flag.\r
5171 UINT32 IF:1; ///< Interrupt Enable Flag.\r
5172 UINT32 DF:1; ///< Direction Flag.\r
5173 UINT32 OF:1; ///< Overflow Flag.\r
5174 UINT32 IOPL:2; ///< I/O Privilege Level.\r
5175 UINT32 NT:1; ///< Nested Task.\r
5176 UINT32 Reserved_3:1; ///< Reserved.\r
5177 UINT32 RF:1; ///< Resume Flag.\r
5178 UINT32 VM:1; ///< Virtual 8086 Mode.\r
5179 UINT32 AC:1; ///< Alignment Check.\r
5180 UINT32 VIF:1; ///< Virtual Interrupt Flag.\r
5181 UINT32 VIP:1; ///< Virtual Interrupt Pending.\r
5182 UINT32 ID:1; ///< ID Flag.\r
5183 UINT32 Reserved_4:10; ///< Reserved.\r
ac644614 5184 } Bits;\r
5185 UINTN UintN;\r
5186} IA32_EFLAGS32;\r
5187\r
1106ffe1 5188///\r
af2dc6a7 5189/// Byte packed structure for Control Register 0 (CR0).\r
5190/// 32-bits on IA-32.\r
5191/// 64-bits on x64. The upper 32-bits on x64 are reserved.\r
1106ffe1 5192///\r
ac644614 5193typedef union {\r
5194 struct {\r
af2dc6a7 5195 UINT32 PE:1; ///< Protection Enable.\r
5196 UINT32 MP:1; ///< Monitor Coprocessor.\r
5197 UINT32 EM:1; ///< Emulation.\r
5198 UINT32 TS:1; ///< Task Switched.\r
5199 UINT32 ET:1; ///< Extension Type.\r
5200 UINT32 NE:1; ///< Numeric Error.\r
5201 UINT32 Reserved_0:10; ///< Reserved.\r
5202 UINT32 WP:1; ///< Write Protect.\r
5203 UINT32 Reserved_1:1; ///< Reserved.\r
5204 UINT32 AM:1; ///< Alignment Mask.\r
5205 UINT32 Reserved_2:10; ///< Reserved.\r
5206 UINT32 NW:1; ///< Mot Write-through.\r
5207 UINT32 CD:1; ///< Cache Disable.\r
5208 UINT32 PG:1; ///< Paging.\r
ac644614 5209 } Bits;\r
5210 UINTN UintN;\r
5211} IA32_CR0;\r
5212\r
1106ffe1 5213///\r
af2dc6a7 5214/// Byte packed structure for Control Register 4 (CR4).\r
5215/// 32-bits on IA-32.\r
5216/// 64-bits on x64. The upper 32-bits on x64 are reserved.\r
1106ffe1 5217///\r
ac644614 5218typedef union {\r
5219 struct {\r
af2dc6a7 5220 UINT32 VME:1; ///< Virtual-8086 Mode Extensions.\r
5221 UINT32 PVI:1; ///< Protected-Mode Virtual Interrupts.\r
5222 UINT32 TSD:1; ///< Time Stamp Disable.\r
5223 UINT32 DE:1; ///< Debugging Extensions.\r
5224 UINT32 PSE:1; ///< Page Size Extensions.\r
5225 UINT32 PAE:1; ///< Physical Address Extension.\r
5226 UINT32 MCE:1; ///< Machine Check Enable.\r
5227 UINT32 PGE:1; ///< Page Global Enable.\r
2a53dabf 5228 UINT32 PCE:1; ///< Performance Monitoring Counter\r
af2dc6a7 5229 ///< Enable.\r
2a53dabf
LG
5230 UINT32 OSFXSR:1; ///< Operating System Support for\r
5231 ///< FXSAVE and FXRSTOR instructions\r
5232 UINT32 OSXMMEXCPT:1; ///< Operating System Support for\r
5233 ///< Unmasked SIMD Floating Point\r
af2dc6a7 5234 ///< Exceptions.\r
5235 UINT32 Reserved_0:2; ///< Reserved.\r
2a53dabf 5236 UINT32 VMXE:1; ///< VMX Enable\r
af2dc6a7 5237 UINT32 Reserved_1:18; ///< Reserved.\r
ac644614 5238 } Bits;\r
5239 UINTN UintN;\r
5240} IA32_CR4;\r
5241\r
6088db38 5242///\r
5243/// Byte packed structure for a segment descriptor in a GDT/LDT.\r
5244///\r
5245typedef union {\r
5246 struct {\r
5247 UINT32 LimitLow:16;\r
5248 UINT32 BaseLow:16;\r
5249 UINT32 BaseMid:8;\r
5250 UINT32 Type:4;\r
5251 UINT32 S:1;\r
5252 UINT32 DPL:2;\r
5253 UINT32 P:1;\r
5254 UINT32 LimitHigh:4;\r
5255 UINT32 AVL:1;\r
5256 UINT32 L:1;\r
5257 UINT32 DB:1;\r
5258 UINT32 G:1;\r
5259 UINT32 BaseHigh:8;\r
5260 } Bits;\r
5261 UINT64 Uint64;\r
5262} IA32_SEGMENT_DESCRIPTOR;\r
5263\r
1106ffe1 5264///\r
af2dc6a7 5265/// Byte packed structure for an IDTR, GDTR, LDTR descriptor.\r
1106ffe1 5266///\r
ac644614 5267#pragma pack (1)\r
5268typedef struct {\r
5269 UINT16 Limit;\r
5270 UINTN Base;\r
5271} IA32_DESCRIPTOR;\r
5272#pragma pack ()\r
5273\r
5274#define IA32_IDT_GATE_TYPE_TASK 0x85\r
5275#define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x86\r
5276#define IA32_IDT_GATE_TYPE_TRAP_16 0x87\r
5277#define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E\r
5278#define IA32_IDT_GATE_TYPE_TRAP_32 0x8F\r
5279\r
364a5474
JW
5280#define IA32_GDT_TYPE_TSS 0x9\r
5281#define IA32_GDT_ALIGNMENT 8\r
6f4aad3b 5282\r
5283#if defined (MDE_CPU_IA32)\r
1106ffe1 5284///\r
af2dc6a7 5285/// Byte packed structure for an IA-32 Interrupt Gate Descriptor.\r
1106ffe1 5286///\r
dc317713 5287typedef union {\r
5288 struct {\r
af2dc6a7 5289 UINT32 OffsetLow:16; ///< Offset bits 15..0.\r
5290 UINT32 Selector:16; ///< Selector.\r
5291 UINT32 Reserved_0:8; ///< Reserved.\r
5292 UINT32 GateType:8; ///< Gate Type. See #defines above.\r
5293 UINT32 OffsetHigh:16; ///< Offset bits 31..16.\r
dc317713 5294 } Bits;\r
5295 UINT64 Uint64;\r
5296} IA32_IDT_GATE_DESCRIPTOR;\r
5297\r
364a5474
JW
5298#pragma pack (1)\r
5299//\r
5300// IA32 Task-State Segment Definition\r
5301//\r
5302typedef struct {\r
5303 UINT16 PreviousTaskLink;\r
5304 UINT16 Reserved_2;\r
3ab032fc
JW
5305 UINT32 ESP0;\r
5306 UINT16 SS0;\r
364a5474 5307 UINT16 Reserved_10;\r
3ab032fc
JW
5308 UINT32 ESP1;\r
5309 UINT16 SS1;\r
364a5474 5310 UINT16 Reserved_18;\r
3ab032fc
JW
5311 UINT32 ESP2;\r
5312 UINT16 SS2;\r
364a5474 5313 UINT16 Reserved_26;\r
3ab032fc
JW
5314 UINT32 CR3;\r
5315 UINT32 EIP;\r
5316 UINT32 EFLAGS;\r
5317 UINT32 EAX;\r
5318 UINT32 ECX;\r
5319 UINT32 EDX;\r
5320 UINT32 EBX;\r
5321 UINT32 ESP;\r
5322 UINT32 EBP;\r
5323 UINT32 ESI;\r
5324 UINT32 EDI;\r
5325 UINT16 ES;\r
364a5474 5326 UINT16 Reserved_74;\r
3ab032fc 5327 UINT16 CS;\r
364a5474 5328 UINT16 Reserved_78;\r
3ab032fc 5329 UINT16 SS;\r
364a5474 5330 UINT16 Reserved_82;\r
3ab032fc 5331 UINT16 DS;\r
364a5474 5332 UINT16 Reserved_86;\r
3ab032fc 5333 UINT16 FS;\r
364a5474 5334 UINT16 Reserved_90;\r
3ab032fc 5335 UINT16 GS;\r
364a5474
JW
5336 UINT16 Reserved_94;\r
5337 UINT16 LDTSegmentSelector;\r
5338 UINT16 Reserved_98;\r
3ab032fc 5339 UINT16 T;\r
364a5474
JW
5340 UINT16 IOMapBaseAddress;\r
5341} IA32_TASK_STATE_SEGMENT;\r
5342\r
5343typedef union {\r
5344 struct {\r
5345 UINT32 LimitLow:16; ///< Segment Limit 15..00\r
5346 UINT32 BaseLow:16; ///< Base Address 15..00\r
5347 UINT32 BaseMid:8; ///< Base Address 23..16\r
5348 UINT32 Type:4; ///< Type (1 0 B 1)\r
5349 UINT32 Reserved_43:1; ///< 0\r
3ab032fc
JW
5350 UINT32 DPL:2; ///< Descriptor Privilege Level\r
5351 UINT32 P:1; ///< Segment Present\r
364a5474 5352 UINT32 LimitHigh:4; ///< Segment Limit 19..16\r
3ab032fc 5353 UINT32 AVL:1; ///< Available for use by system software\r
364a5474 5354 UINT32 Reserved_52:2; ///< 0 0\r
3ab032fc 5355 UINT32 G:1; ///< Granularity\r
364a5474
JW
5356 UINT32 BaseHigh:8; ///< Base Address 31..24\r
5357 } Bits;\r
5358 UINT64 Uint64;\r
5359} IA32_TSS_DESCRIPTOR;\r
5360#pragma pack ()\r
5361\r
de4f7f52 5362#endif // defined (MDE_CPU_IA32)\r
dc317713 5363\r
5364#if defined (MDE_CPU_X64)\r
6f4aad3b 5365///\r
af2dc6a7 5366/// Byte packed structure for an x64 Interrupt Gate Descriptor.\r
6f4aad3b 5367///\r
ac644614 5368typedef union {\r
5369 struct {\r
af2dc6a7 5370 UINT32 OffsetLow:16; ///< Offset bits 15..0.\r
5371 UINT32 Selector:16; ///< Selector.\r
5372 UINT32 Reserved_0:8; ///< Reserved.\r
5373 UINT32 GateType:8; ///< Gate Type. See #defines above.\r
5374 UINT32 OffsetHigh:16; ///< Offset bits 31..16.\r
5375 UINT32 OffsetUpper:32; ///< Offset bits 63..32.\r
5376 UINT32 Reserved_1:32; ///< Reserved.\r
ac644614 5377 } Bits;\r
6f4aad3b 5378 struct {\r
5379 UINT64 Uint64;\r
5380 UINT64 Uint64_1;\r
9095d37b 5381 } Uint128;\r
ac644614 5382} IA32_IDT_GATE_DESCRIPTOR;\r
5383\r
364a5474
JW
5384#pragma pack (1)\r
5385//\r
5386// IA32 Task-State Segment Definition\r
5387//\r
5388typedef struct {\r
5389 UINT32 Reserved_0;\r
3ab032fc
JW
5390 UINT64 RSP0;\r
5391 UINT64 RSP1;\r
5392 UINT64 RSP2;\r
364a5474 5393 UINT64 Reserved_28;\r
3ab032fc 5394 UINT64 IST[7];\r
364a5474
JW
5395 UINT64 Reserved_92;\r
5396 UINT16 Reserved_100;\r
5397 UINT16 IOMapBaseAddress;\r
5398} IA32_TASK_STATE_SEGMENT;\r
5399\r
5400typedef union {\r
5401 struct {\r
5402 UINT32 LimitLow:16; ///< Segment Limit 15..00\r
5403 UINT32 BaseLow:16; ///< Base Address 15..00\r
5404 UINT32 BaseMidl:8; ///< Base Address 23..16\r
5405 UINT32 Type:4; ///< Type (1 0 B 1)\r
5406 UINT32 Reserved_43:1; ///< 0\r
3ab032fc
JW
5407 UINT32 DPL:2; ///< Descriptor Privilege Level\r
5408 UINT32 P:1; ///< Segment Present\r
364a5474 5409 UINT32 LimitHigh:4; ///< Segment Limit 19..16\r
3ab032fc 5410 UINT32 AVL:1; ///< Available for use by system software\r
364a5474 5411 UINT32 Reserved_52:2; ///< 0 0\r
3ab032fc 5412 UINT32 G:1; ///< Granularity\r
364a5474
JW
5413 UINT32 BaseMidh:8; ///< Base Address 31..24\r
5414 UINT32 BaseHigh:32; ///< Base Address 63..32\r
5415 UINT32 Reserved_96:32; ///< Reserved\r
5416 } Bits;\r
5417 struct {\r
5418 UINT64 Uint64;\r
5419 UINT64 Uint64_1;\r
5420 } Uint128;\r
5421} IA32_TSS_DESCRIPTOR;\r
5422#pragma pack ()\r
5423\r
de4f7f52 5424#endif // defined (MDE_CPU_X64)\r
dc317713 5425\r
1106ffe1 5426///\r
af2dc6a7 5427/// Byte packed structure for an FP/SSE/SSE2 context.\r
1106ffe1 5428///\r
ac644614 5429typedef struct {\r
5430 UINT8 Buffer[512];\r
5431} IA32_FX_BUFFER;\r
5432\r
1106ffe1 5433///\r
af2dc6a7 5434/// Structures for the 16-bit real mode thunks.\r
1106ffe1 5435///\r
ac644614 5436typedef struct {\r
5437 UINT32 Reserved1;\r
5438 UINT32 Reserved2;\r
5439 UINT32 Reserved3;\r
5440 UINT32 Reserved4;\r
5441 UINT8 BL;\r
5442 UINT8 BH;\r
5443 UINT16 Reserved5;\r
5444 UINT8 DL;\r
5445 UINT8 DH;\r
5446 UINT16 Reserved6;\r
5447 UINT8 CL;\r
5448 UINT8 CH;\r
5449 UINT16 Reserved7;\r
5450 UINT8 AL;\r
5451 UINT8 AH;\r
5452 UINT16 Reserved8;\r
5453} IA32_BYTE_REGS;\r
5454\r
5455typedef struct {\r
5456 UINT16 DI;\r
5457 UINT16 Reserved1;\r
5458 UINT16 SI;\r
5459 UINT16 Reserved2;\r
5460 UINT16 BP;\r
5461 UINT16 Reserved3;\r
5462 UINT16 SP;\r
5463 UINT16 Reserved4;\r
5464 UINT16 BX;\r
5465 UINT16 Reserved5;\r
5466 UINT16 DX;\r
5467 UINT16 Reserved6;\r
5468 UINT16 CX;\r
5469 UINT16 Reserved7;\r
5470 UINT16 AX;\r
5471 UINT16 Reserved8;\r
5472} IA32_WORD_REGS;\r
5473\r
5474typedef struct {\r
5475 UINT32 EDI;\r
5476 UINT32 ESI;\r
5477 UINT32 EBP;\r
5478 UINT32 ESP;\r
5479 UINT32 EBX;\r
5480 UINT32 EDX;\r
5481 UINT32 ECX;\r
5482 UINT32 EAX;\r
5483 UINT16 DS;\r
5484 UINT16 ES;\r
5485 UINT16 FS;\r
5486 UINT16 GS;\r
5487 IA32_EFLAGS32 EFLAGS;\r
5488 UINT32 Eip;\r
5489 UINT16 CS;\r
5490 UINT16 SS;\r
5491} IA32_DWORD_REGS;\r
5492\r
5493typedef union {\r
5494 IA32_DWORD_REGS E;\r
5495 IA32_WORD_REGS X;\r
5496 IA32_BYTE_REGS H;\r
5497} IA32_REGISTER_SET;\r
5498\r
1106ffe1 5499///\r
af2dc6a7 5500/// Byte packed structure for an 16-bit real mode thunks.\r
1106ffe1 5501///\r
ac644614 5502typedef struct {\r
5503 IA32_REGISTER_SET *RealModeState;\r
5504 VOID *RealModeBuffer;\r
5505 UINT32 RealModeBufferSize;\r
5506 UINT32 ThunkAttributes;\r
5507} THUNK_CONTEXT;\r
5508\r
5509#define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x00000001\r
5510#define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002\r
5511#define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004\r
5512\r
8596c140
LE
5513///\r
5514/// Type definition for representing labels in NASM source code that allow for\r
5515/// the patching of immediate operands of IA32 and X64 instructions.\r
5516///\r
5517/// While the type is technically defined as a function type (note: not a\r
5518/// pointer-to-function type), such labels in NASM source code never stand for\r
5519/// actual functions, and identifiers declared with this function type should\r
5520/// never be called. This is also why the EFIAPI calling convention specifier\r
5521/// is missing from the typedef, and why the typedef does not follow the usual\r
5522/// edk2 coding style for function (or pointer-to-function) typedefs. The VOID\r
5523/// return type and the VOID argument list are merely artifacts.\r
5524///\r
5525typedef VOID (X86_ASSEMBLY_PATCH_LABEL) (VOID);\r
5526\r
ac644614 5527/**\r
5528 Retrieves CPUID information.\r
5529\r
5530 Executes the CPUID instruction with EAX set to the value specified by Index.\r
5531 This function always returns Index.\r
5532 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.\r
5533 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.\r
5534 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.\r
5535 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.\r
030cd1a2 5536 This function is only available on IA-32 and x64.\r
ac644614 5537\r
5538 @param Index The 32-bit value to load into EAX prior to invoking the CPUID\r
5539 instruction.\r
af2dc6a7 5540 @param Eax The pointer to the 32-bit EAX value returned by the CPUID\r
ac644614 5541 instruction. This is an optional parameter that may be NULL.\r
af2dc6a7 5542 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID\r
ac644614 5543 instruction. This is an optional parameter that may be NULL.\r
af2dc6a7 5544 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID\r
ac644614 5545 instruction. This is an optional parameter that may be NULL.\r
af2dc6a7 5546 @param Edx The pointer to the 32-bit EDX value returned by the CPUID\r
ac644614 5547 instruction. This is an optional parameter that may be NULL.\r
5548\r
2fe241a2 5549 @return Index.\r
ac644614 5550\r
5551**/\r
5552UINT32\r
5553EFIAPI\r
5554AsmCpuid (\r
5555 IN UINT32 Index,\r
5556 OUT UINT32 *Eax, OPTIONAL\r
5557 OUT UINT32 *Ebx, OPTIONAL\r
5558 OUT UINT32 *Ecx, OPTIONAL\r
5559 OUT UINT32 *Edx OPTIONAL\r
5560 );\r
5561\r
5562\r
5563/**\r
5564 Retrieves CPUID information using an extended leaf identifier.\r
5565\r
5566 Executes the CPUID instruction with EAX set to the value specified by Index\r
5567 and ECX set to the value specified by SubIndex. This function always returns\r
5568 Index. This function is only available on IA-32 and x64.\r
5569\r
5570 If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.\r
5571 If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.\r
5572 If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.\r
5573 If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.\r
5574\r
5575 @param Index The 32-bit value to load into EAX prior to invoking the\r
5576 CPUID instruction.\r
5577 @param SubIndex The 32-bit value to load into ECX prior to invoking the\r
5578 CPUID instruction.\r
af2dc6a7 5579 @param Eax The pointer to the 32-bit EAX value returned by the CPUID\r
ac644614 5580 instruction. This is an optional parameter that may be\r
5581 NULL.\r
af2dc6a7 5582 @param Ebx The pointer to the 32-bit EBX value returned by the CPUID\r
ac644614 5583 instruction. This is an optional parameter that may be\r
5584 NULL.\r
af2dc6a7 5585 @param Ecx The pointer to the 32-bit ECX value returned by the CPUID\r
ac644614 5586 instruction. This is an optional parameter that may be\r
5587 NULL.\r
af2dc6a7 5588 @param Edx The pointer to the 32-bit EDX value returned by the CPUID\r
ac644614 5589 instruction. This is an optional parameter that may be\r
5590 NULL.\r
5591\r
2fe241a2 5592 @return Index.\r
ac644614 5593\r
5594**/\r
5595UINT32\r
5596EFIAPI\r
5597AsmCpuidEx (\r
5598 IN UINT32 Index,\r
5599 IN UINT32 SubIndex,\r
5600 OUT UINT32 *Eax, OPTIONAL\r
5601 OUT UINT32 *Ebx, OPTIONAL\r
5602 OUT UINT32 *Ecx, OPTIONAL\r
5603 OUT UINT32 *Edx OPTIONAL\r
5604 );\r
5605\r
5606\r
be5f1614 5607/**\r
5608 Set CD bit and clear NW bit of CR0 followed by a WBINVD.\r
5609\r
5610 Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,\r
5611 and executing a WBINVD instruction. This function is only available on IA-32 and x64.\r
5612\r
5613**/\r
5614VOID\r
5615EFIAPI\r
5616AsmDisableCache (\r
5617 VOID\r
5618 );\r
5619\r
5620\r
5621/**\r
5622 Perform a WBINVD and clear both the CD and NW bits of CR0.\r
5623\r
5624 Enables the caches by executing a WBINVD instruction and then clear both the CD and NW\r
5625 bits of CR0 to 0. This function is only available on IA-32 and x64.\r
5626\r
5627**/\r
5628VOID\r
5629EFIAPI\r
5630AsmEnableCache (\r
5631 VOID\r
5632 );\r
5633\r
5634\r
ac644614 5635/**\r
5636 Returns the lower 32-bits of a Machine Specific Register(MSR).\r
5637\r
5638 Reads and returns the lower 32-bits of the MSR specified by Index.\r
5639 No parameter checking is performed on Index, and some Index values may cause\r
5640 CPU exceptions. The caller must either guarantee that Index is valid, or the\r
5641 caller must set up exception handlers to catch the exceptions. This function\r
030cd1a2 5642 is only available on IA-32 and x64.\r
ac644614 5643\r
5644 @param Index The 32-bit MSR index to read.\r
5645\r
5646 @return The lower 32 bits of the MSR identified by Index.\r
5647\r
5648**/\r
5649UINT32\r
5650EFIAPI\r
5651AsmReadMsr32 (\r
5652 IN UINT32 Index\r
5653 );\r
5654\r
5655\r
5656/**\r
17f695ed 5657 Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.\r
5658 The upper 32-bits of the MSR are set to zero.\r
ac644614 5659\r
5660 Writes the 32-bit value specified by Value to the MSR specified by Index. The\r
5661 upper 32-bits of the MSR write are set to zero. The 32-bit value written to\r
5662 the MSR is returned. No parameter checking is performed on Index or Value,\r
5663 and some of these may cause CPU exceptions. The caller must either guarantee\r
5664 that Index and Value are valid, or the caller must establish proper exception\r
030cd1a2 5665 handlers. This function is only available on IA-32 and x64.\r
ac644614 5666\r
5667 @param Index The 32-bit MSR index to write.\r
5668 @param Value The 32-bit value to write to the MSR.\r
5669\r
5670 @return Value\r
5671\r
5672**/\r
5673UINT32\r
5674EFIAPI\r
5675AsmWriteMsr32 (\r
5676 IN UINT32 Index,\r
5677 IN UINT32 Value\r
5678 );\r
5679\r
5680\r
5681/**\r
62991af2 5682 Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and\r
ac644614 5683 writes the result back to the 64-bit MSR.\r
5684\r
62991af2 5685 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 5686 between the lower 32-bits of the read result and the value specified by\r
5687 OrData, and writes the result to the 64-bit MSR specified by Index. The lower\r
5688 32-bits of the value written to the MSR is returned. No parameter checking is\r
5689 performed on Index or OrData, and some of these may cause CPU exceptions. The\r
5690 caller must either guarantee that Index and OrData are valid, or the caller\r
5691 must establish proper exception handlers. This function is only available on\r
030cd1a2 5692 IA-32 and x64.\r
ac644614 5693\r
5694 @param Index The 32-bit MSR index to write.\r
5695 @param OrData The value to OR with the read value from the MSR.\r
5696\r
5697 @return The lower 32-bit value written to the MSR.\r
5698\r
5699**/\r
5700UINT32\r
5701EFIAPI\r
5702AsmMsrOr32 (\r
5703 IN UINT32 Index,\r
5704 IN UINT32 OrData\r
5705 );\r
5706\r
5707\r
5708/**\r
5709 Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes\r
5710 the result back to the 64-bit MSR.\r
5711\r
5712 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
5713 lower 32-bits of the read result and the value specified by AndData, and\r
5714 writes the result to the 64-bit MSR specified by Index. The lower 32-bits of\r
5715 the value written to the MSR is returned. No parameter checking is performed\r
5716 on Index or AndData, and some of these may cause CPU exceptions. The caller\r
5717 must either guarantee that Index and AndData are valid, or the caller must\r
5718 establish proper exception handlers. This function is only available on IA-32\r
030cd1a2 5719 and x64.\r
ac644614 5720\r
5721 @param Index The 32-bit MSR index to write.\r
5722 @param AndData The value to AND with the read value from the MSR.\r
5723\r
5724 @return The lower 32-bit value written to the MSR.\r
5725\r
5726**/\r
5727UINT32\r
5728EFIAPI\r
5729AsmMsrAnd32 (\r
5730 IN UINT32 Index,\r
5731 IN UINT32 AndData\r
5732 );\r
5733\r
5734\r
5735/**\r
62991af2 5736 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR\r
ac644614 5737 on the lower 32-bits, and writes the result back to the 64-bit MSR.\r
5738\r
5739 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
5740 lower 32-bits of the read result and the value specified by AndData\r
62991af2 5741 preserving the upper 32-bits, performs a bitwise OR between the\r
ac644614 5742 result of the AND operation and the value specified by OrData, and writes the\r
5743 result to the 64-bit MSR specified by Address. The lower 32-bits of the value\r
5744 written to the MSR is returned. No parameter checking is performed on Index,\r
5745 AndData, or OrData, and some of these may cause CPU exceptions. The caller\r
5746 must either guarantee that Index, AndData, and OrData are valid, or the\r
5747 caller must establish proper exception handlers. This function is only\r
030cd1a2 5748 available on IA-32 and x64.\r
ac644614 5749\r
5750 @param Index The 32-bit MSR index to write.\r
5751 @param AndData The value to AND with the read value from the MSR.\r
5752 @param OrData The value to OR with the result of the AND operation.\r
5753\r
5754 @return The lower 32-bit value written to the MSR.\r
5755\r
5756**/\r
5757UINT32\r
5758EFIAPI\r
5759AsmMsrAndThenOr32 (\r
5760 IN UINT32 Index,\r
5761 IN UINT32 AndData,\r
5762 IN UINT32 OrData\r
5763 );\r
5764\r
5765\r
5766/**\r
5767 Reads a bit field of an MSR.\r
5768\r
5769 Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is\r
5770 specified by the StartBit and the EndBit. The value of the bit field is\r
5771 returned. The caller must either guarantee that Index is valid, or the caller\r
5772 must set up exception handlers to catch the exceptions. This function is only\r
030cd1a2 5773 available on IA-32 and x64.\r
ac644614 5774\r
5775 If StartBit is greater than 31, then ASSERT().\r
5776 If EndBit is greater than 31, then ASSERT().\r
5777 If EndBit is less than StartBit, then ASSERT().\r
5778\r
5779 @param Index The 32-bit MSR index to read.\r
5780 @param StartBit The ordinal of the least significant bit in the bit field.\r
5781 Range 0..31.\r
5782 @param EndBit The ordinal of the most significant bit in the bit field.\r
5783 Range 0..31.\r
5784\r
5785 @return The bit field read from the MSR.\r
5786\r
5787**/\r
5788UINT32\r
5789EFIAPI\r
5790AsmMsrBitFieldRead32 (\r
5791 IN UINT32 Index,\r
5792 IN UINTN StartBit,\r
5793 IN UINTN EndBit\r
5794 );\r
5795\r
5796\r
5797/**\r
5798 Writes a bit field to an MSR.\r
5799\r
2fe241a2 5800 Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit\r
ac644614 5801 field is specified by the StartBit and the EndBit. All other bits in the\r
5802 destination MSR are preserved. The lower 32-bits of the MSR written is\r
9095d37b
LG
5803 returned. The caller must either guarantee that Index and the data written\r
5804 is valid, or the caller must set up exception handlers to catch the exceptions.\r
62991af2 5805 This function is only available on IA-32 and x64.\r
ac644614 5806\r
5807 If StartBit is greater than 31, then ASSERT().\r
5808 If EndBit is greater than 31, then ASSERT().\r
5809 If EndBit is less than StartBit, then ASSERT().\r
94952554 5810 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5811\r
5812 @param Index The 32-bit MSR index to write.\r
5813 @param StartBit The ordinal of the least significant bit in the bit field.\r
5814 Range 0..31.\r
5815 @param EndBit The ordinal of the most significant bit in the bit field.\r
5816 Range 0..31.\r
5817 @param Value New value of the bit field.\r
5818\r
5819 @return The lower 32-bit of the value written to the MSR.\r
5820\r
5821**/\r
5822UINT32\r
5823EFIAPI\r
5824AsmMsrBitFieldWrite32 (\r
5825 IN UINT32 Index,\r
5826 IN UINTN StartBit,\r
5827 IN UINTN EndBit,\r
5828 IN UINT32 Value\r
5829 );\r
5830\r
5831\r
5832/**\r
5833 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the\r
5834 result back to the bit field in the 64-bit MSR.\r
5835\r
62991af2 5836 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 5837 between the read result and the value specified by OrData, and writes the\r
5838 result to the 64-bit MSR specified by Index. The lower 32-bits of the value\r
5839 written to the MSR are returned. Extra left bits in OrData are stripped. The\r
5840 caller must either guarantee that Index and the data written is valid, or\r
5841 the caller must set up exception handlers to catch the exceptions. This\r
030cd1a2 5842 function is only available on IA-32 and x64.\r
ac644614 5843\r
5844 If StartBit is greater than 31, then ASSERT().\r
5845 If EndBit is greater than 31, then ASSERT().\r
5846 If EndBit is less than StartBit, then ASSERT().\r
94952554 5847 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5848\r
5849 @param Index The 32-bit MSR index to write.\r
5850 @param StartBit The ordinal of the least significant bit in the bit field.\r
5851 Range 0..31.\r
5852 @param EndBit The ordinal of the most significant bit in the bit field.\r
5853 Range 0..31.\r
5854 @param OrData The value to OR with the read value from the MSR.\r
5855\r
5856 @return The lower 32-bit of the value written to the MSR.\r
5857\r
5858**/\r
5859UINT32\r
5860EFIAPI\r
5861AsmMsrBitFieldOr32 (\r
5862 IN UINT32 Index,\r
5863 IN UINTN StartBit,\r
5864 IN UINTN EndBit,\r
5865 IN UINT32 OrData\r
5866 );\r
5867\r
5868\r
5869/**\r
5870 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
5871 result back to the bit field in the 64-bit MSR.\r
5872\r
5873 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
5874 read result and the value specified by AndData, and writes the result to the\r
5875 64-bit MSR specified by Index. The lower 32-bits of the value written to the\r
5876 MSR are returned. Extra left bits in AndData are stripped. The caller must\r
5877 either guarantee that Index and the data written is valid, or the caller must\r
5878 set up exception handlers to catch the exceptions. This function is only\r
030cd1a2 5879 available on IA-32 and x64.\r
ac644614 5880\r
5881 If StartBit is greater than 31, then ASSERT().\r
5882 If EndBit is greater than 31, then ASSERT().\r
5883 If EndBit is less than StartBit, then ASSERT().\r
94952554 5884 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5885\r
5886 @param Index The 32-bit MSR index to write.\r
5887 @param StartBit The ordinal of the least significant bit in the bit field.\r
5888 Range 0..31.\r
5889 @param EndBit The ordinal of the most significant bit in the bit field.\r
5890 Range 0..31.\r
5891 @param AndData The value to AND with the read value from the MSR.\r
5892\r
5893 @return The lower 32-bit of the value written to the MSR.\r
5894\r
5895**/\r
5896UINT32\r
5897EFIAPI\r
5898AsmMsrBitFieldAnd32 (\r
5899 IN UINT32 Index,\r
5900 IN UINTN StartBit,\r
5901 IN UINTN EndBit,\r
5902 IN UINT32 AndData\r
5903 );\r
5904\r
5905\r
5906/**\r
5907 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
62991af2 5908 bitwise OR, and writes the result back to the bit field in the\r
ac644614 5909 64-bit MSR.\r
5910\r
5911 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a\r
62991af2 5912 bitwise OR between the read result and the value specified by\r
ac644614 5913 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
5914 lower 32-bits of the value written to the MSR are returned. Extra left bits\r
5915 in both AndData and OrData are stripped. The caller must either guarantee\r
5916 that Index and the data written is valid, or the caller must set up exception\r
5917 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 5918 and x64.\r
ac644614 5919\r
5920 If StartBit is greater than 31, then ASSERT().\r
5921 If EndBit is greater than 31, then ASSERT().\r
5922 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
5923 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
5924 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 5925\r
5926 @param Index The 32-bit MSR index to write.\r
5927 @param StartBit The ordinal of the least significant bit in the bit field.\r
5928 Range 0..31.\r
5929 @param EndBit The ordinal of the most significant bit in the bit field.\r
5930 Range 0..31.\r
5931 @param AndData The value to AND with the read value from the MSR.\r
5932 @param OrData The value to OR with the result of the AND operation.\r
5933\r
5934 @return The lower 32-bit of the value written to the MSR.\r
5935\r
5936**/\r
5937UINT32\r
5938EFIAPI\r
5939AsmMsrBitFieldAndThenOr32 (\r
5940 IN UINT32 Index,\r
5941 IN UINTN StartBit,\r
5942 IN UINTN EndBit,\r
5943 IN UINT32 AndData,\r
5944 IN UINT32 OrData\r
5945 );\r
5946\r
5947\r
5948/**\r
5949 Returns a 64-bit Machine Specific Register(MSR).\r
5950\r
5951 Reads and returns the 64-bit MSR specified by Index. No parameter checking is\r
5952 performed on Index, and some Index values may cause CPU exceptions. The\r
5953 caller must either guarantee that Index is valid, or the caller must set up\r
5954 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 5955 on IA-32 and x64.\r
ac644614 5956\r
5957 @param Index The 32-bit MSR index to read.\r
5958\r
5959 @return The value of the MSR identified by Index.\r
5960\r
5961**/\r
5962UINT64\r
5963EFIAPI\r
5964AsmReadMsr64 (\r
5965 IN UINT32 Index\r
5966 );\r
5967\r
5968\r
5969/**\r
5970 Writes a 64-bit value to a Machine Specific Register(MSR), and returns the\r
5971 value.\r
5972\r
5973 Writes the 64-bit value specified by Value to the MSR specified by Index. The\r
5974 64-bit value written to the MSR is returned. No parameter checking is\r
5975 performed on Index or Value, and some of these may cause CPU exceptions. The\r
5976 caller must either guarantee that Index and Value are valid, or the caller\r
5977 must establish proper exception handlers. This function is only available on\r
030cd1a2 5978 IA-32 and x64.\r
ac644614 5979\r
5980 @param Index The 32-bit MSR index to write.\r
5981 @param Value The 64-bit value to write to the MSR.\r
5982\r
5983 @return Value\r
5984\r
5985**/\r
5986UINT64\r
5987EFIAPI\r
5988AsmWriteMsr64 (\r
5989 IN UINT32 Index,\r
5990 IN UINT64 Value\r
5991 );\r
5992\r
5993\r
5994/**\r
62991af2 5995 Reads a 64-bit MSR, performs a bitwise OR, and writes the result\r
ac644614 5996 back to the 64-bit MSR.\r
5997\r
62991af2 5998 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 5999 between the read result and the value specified by OrData, and writes the\r
6000 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
6001 returned. No parameter checking is performed on Index or OrData, and some of\r
6002 these may cause CPU exceptions. The caller must either guarantee that Index\r
6003 and OrData are valid, or the caller must establish proper exception handlers.\r
030cd1a2 6004 This function is only available on IA-32 and x64.\r
ac644614 6005\r
6006 @param Index The 32-bit MSR index to write.\r
6007 @param OrData The value to OR with the read value from the MSR.\r
6008\r
6009 @return The value written back to the MSR.\r
6010\r
6011**/\r
6012UINT64\r
6013EFIAPI\r
6014AsmMsrOr64 (\r
6015 IN UINT32 Index,\r
6016 IN UINT64 OrData\r
6017 );\r
6018\r
6019\r
6020/**\r
6021 Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the\r
6022 64-bit MSR.\r
6023\r
6024 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
6025 read result and the value specified by OrData, and writes the result to the\r
6026 64-bit MSR specified by Index. The value written to the MSR is returned. No\r
6027 parameter checking is performed on Index or OrData, and some of these may\r
6028 cause CPU exceptions. The caller must either guarantee that Index and OrData\r
6029 are valid, or the caller must establish proper exception handlers. This\r
030cd1a2 6030 function is only available on IA-32 and x64.\r
ac644614 6031\r
6032 @param Index The 32-bit MSR index to write.\r
6033 @param AndData The value to AND with the read value from the MSR.\r
6034\r
6035 @return The value written back to the MSR.\r
6036\r
6037**/\r
6038UINT64\r
6039EFIAPI\r
6040AsmMsrAnd64 (\r
6041 IN UINT32 Index,\r
6042 IN UINT64 AndData\r
6043 );\r
6044\r
6045\r
6046/**\r
9095d37b 6047 Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise\r
ac644614 6048 OR, and writes the result back to the 64-bit MSR.\r
6049\r
6050 Reads the 64-bit MSR specified by Index, performs a bitwise AND between read\r
62991af2 6051 result and the value specified by AndData, performs a bitwise OR\r
ac644614 6052 between the result of the AND operation and the value specified by OrData,\r
6053 and writes the result to the 64-bit MSR specified by Index. The value written\r
6054 to the MSR is returned. No parameter checking is performed on Index, AndData,\r
6055 or OrData, and some of these may cause CPU exceptions. The caller must either\r
6056 guarantee that Index, AndData, and OrData are valid, or the caller must\r
6057 establish proper exception handlers. This function is only available on IA-32\r
030cd1a2 6058 and x64.\r
ac644614 6059\r
6060 @param Index The 32-bit MSR index to write.\r
6061 @param AndData The value to AND with the read value from the MSR.\r
6062 @param OrData The value to OR with the result of the AND operation.\r
6063\r
6064 @return The value written back to the MSR.\r
6065\r
6066**/\r
6067UINT64\r
6068EFIAPI\r
6069AsmMsrAndThenOr64 (\r
6070 IN UINT32 Index,\r
6071 IN UINT64 AndData,\r
6072 IN UINT64 OrData\r
6073 );\r
6074\r
6075\r
6076/**\r
6077 Reads a bit field of an MSR.\r
6078\r
6079 Reads the bit field in the 64-bit MSR. The bit field is specified by the\r
6080 StartBit and the EndBit. The value of the bit field is returned. The caller\r
6081 must either guarantee that Index is valid, or the caller must set up\r
6082 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 6083 on IA-32 and x64.\r
ac644614 6084\r
6085 If StartBit is greater than 63, then ASSERT().\r
6086 If EndBit is greater than 63, then ASSERT().\r
6087 If EndBit is less than StartBit, then ASSERT().\r
6088\r
6089 @param Index The 32-bit MSR index to read.\r
6090 @param StartBit The ordinal of the least significant bit in the bit field.\r
6091 Range 0..63.\r
6092 @param EndBit The ordinal of the most significant bit in the bit field.\r
6093 Range 0..63.\r
6094\r
6095 @return The value read from the MSR.\r
6096\r
6097**/\r
6098UINT64\r
6099EFIAPI\r
6100AsmMsrBitFieldRead64 (\r
6101 IN UINT32 Index,\r
6102 IN UINTN StartBit,\r
6103 IN UINTN EndBit\r
6104 );\r
6105\r
6106\r
6107/**\r
6108 Writes a bit field to an MSR.\r
6109\r
6110 Writes Value to a bit field in a 64-bit MSR. The bit field is specified by\r
6111 the StartBit and the EndBit. All other bits in the destination MSR are\r
9095d37b
LG
6112 preserved. The MSR written is returned. The caller must either guarantee\r
6113 that Index and the data written is valid, or the caller must set up exception\r
62991af2 6114 handlers to catch the exceptions. This function is only available on IA-32 and x64.\r
ac644614 6115\r
6116 If StartBit is greater than 63, then ASSERT().\r
6117 If EndBit is greater than 63, then ASSERT().\r
6118 If EndBit is less than StartBit, then ASSERT().\r
94952554 6119 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6120\r
6121 @param Index The 32-bit MSR index to write.\r
6122 @param StartBit The ordinal of the least significant bit in the bit field.\r
6123 Range 0..63.\r
6124 @param EndBit The ordinal of the most significant bit in the bit field.\r
6125 Range 0..63.\r
6126 @param Value New value of the bit field.\r
6127\r
6128 @return The value written back to the MSR.\r
6129\r
6130**/\r
6131UINT64\r
6132EFIAPI\r
6133AsmMsrBitFieldWrite64 (\r
6134 IN UINT32 Index,\r
6135 IN UINTN StartBit,\r
6136 IN UINTN EndBit,\r
6137 IN UINT64 Value\r
6138 );\r
6139\r
6140\r
6141/**\r
62991af2 6142 Reads a bit field in a 64-bit MSR, performs a bitwise OR, and\r
ac644614 6143 writes the result back to the bit field in the 64-bit MSR.\r
6144\r
62991af2 6145 Reads the 64-bit MSR specified by Index, performs a bitwise OR\r
ac644614 6146 between the read result and the value specified by OrData, and writes the\r
6147 result to the 64-bit MSR specified by Index. The value written to the MSR is\r
6148 returned. Extra left bits in OrData are stripped. The caller must either\r
6149 guarantee that Index and the data written is valid, or the caller must set up\r
6150 exception handlers to catch the exceptions. This function is only available\r
030cd1a2 6151 on IA-32 and x64.\r
ac644614 6152\r
6153 If StartBit is greater than 63, then ASSERT().\r
6154 If EndBit is greater than 63, then ASSERT().\r
6155 If EndBit is less than StartBit, then ASSERT().\r
94952554 6156 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6157\r
6158 @param Index The 32-bit MSR index to write.\r
6159 @param StartBit The ordinal of the least significant bit in the bit field.\r
6160 Range 0..63.\r
6161 @param EndBit The ordinal of the most significant bit in the bit field.\r
6162 Range 0..63.\r
6163 @param OrData The value to OR with the read value from the bit field.\r
6164\r
6165 @return The value written back to the MSR.\r
6166\r
6167**/\r
6168UINT64\r
6169EFIAPI\r
6170AsmMsrBitFieldOr64 (\r
6171 IN UINT32 Index,\r
6172 IN UINTN StartBit,\r
6173 IN UINTN EndBit,\r
6174 IN UINT64 OrData\r
6175 );\r
6176\r
6177\r
6178/**\r
6179 Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the\r
6180 result back to the bit field in the 64-bit MSR.\r
6181\r
6182 Reads the 64-bit MSR specified by Index, performs a bitwise AND between the\r
6183 read result and the value specified by AndData, and writes the result to the\r
6184 64-bit MSR specified by Index. The value written to the MSR is returned.\r
6185 Extra left bits in AndData are stripped. The caller must either guarantee\r
6186 that Index and the data written is valid, or the caller must set up exception\r
6187 handlers to catch the exceptions. This function is only available on IA-32\r
030cd1a2 6188 and x64.\r
ac644614 6189\r
6190 If StartBit is greater than 63, then ASSERT().\r
6191 If EndBit is greater than 63, then ASSERT().\r
6192 If EndBit is less than StartBit, then ASSERT().\r
94952554 6193 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6194\r
6195 @param Index The 32-bit MSR index to write.\r
6196 @param StartBit The ordinal of the least significant bit in the bit field.\r
6197 Range 0..63.\r
6198 @param EndBit The ordinal of the most significant bit in the bit field.\r
6199 Range 0..63.\r
6200 @param AndData The value to AND with the read value from the bit field.\r
6201\r
6202 @return The value written back to the MSR.\r
6203\r
6204**/\r
6205UINT64\r
6206EFIAPI\r
6207AsmMsrBitFieldAnd64 (\r
6208 IN UINT32 Index,\r
6209 IN UINTN StartBit,\r
6210 IN UINTN EndBit,\r
6211 IN UINT64 AndData\r
6212 );\r
6213\r
6214\r
6215/**\r
6216 Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a\r
62991af2 6217 bitwise OR, and writes the result back to the bit field in the\r
ac644614 6218 64-bit MSR.\r
6219\r
6220 Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by\r
62991af2 6221 a bitwise OR between the read result and the value specified by\r
ac644614 6222 AndData, and writes the result to the 64-bit MSR specified by Index. The\r
6223 value written to the MSR is returned. Extra left bits in both AndData and\r
6224 OrData are stripped. The caller must either guarantee that Index and the data\r
6225 written is valid, or the caller must set up exception handlers to catch the\r
030cd1a2 6226 exceptions. This function is only available on IA-32 and x64.\r
ac644614 6227\r
6228 If StartBit is greater than 63, then ASSERT().\r
6229 If EndBit is greater than 63, then ASSERT().\r
6230 If EndBit is less than StartBit, then ASSERT().\r
94952554
LG
6231 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
6232 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
ac644614 6233\r
6234 @param Index The 32-bit MSR index to write.\r
6235 @param StartBit The ordinal of the least significant bit in the bit field.\r
6236 Range 0..63.\r
6237 @param EndBit The ordinal of the most significant bit in the bit field.\r
6238 Range 0..63.\r
6239 @param AndData The value to AND with the read value from the bit field.\r
6240 @param OrData The value to OR with the result of the AND operation.\r
6241\r
6242 @return The value written back to the MSR.\r
6243\r
6244**/\r
6245UINT64\r
6246EFIAPI\r
6247AsmMsrBitFieldAndThenOr64 (\r
6248 IN UINT32 Index,\r
6249 IN UINTN StartBit,\r
6250 IN UINTN EndBit,\r
6251 IN UINT64 AndData,\r
6252 IN UINT64 OrData\r
6253 );\r
6254\r
6255\r
6256/**\r
6257 Reads the current value of the EFLAGS register.\r
6258\r
6259 Reads and returns the current value of the EFLAGS register. This function is\r
030cd1a2 6260 only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a\r
6261 64-bit value on x64.\r
ac644614 6262\r
030cd1a2 6263 @return EFLAGS on IA-32 or RFLAGS on x64.\r
ac644614 6264\r
6265**/\r
6266UINTN\r
6267EFIAPI\r
6268AsmReadEflags (\r
6269 VOID\r
6270 );\r
6271\r
6272\r
6273/**\r
6274 Reads the current value of the Control Register 0 (CR0).\r
6275\r
6276 Reads and returns the current value of CR0. This function is only available\r
030cd1a2 6277 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6278 x64.\r
ac644614 6279\r
6280 @return The value of the Control Register 0 (CR0).\r
6281\r
6282**/\r
6283UINTN\r
6284EFIAPI\r
6285AsmReadCr0 (\r
6286 VOID\r
6287 );\r
6288\r
6289\r
6290/**\r
6291 Reads the current value of the Control Register 2 (CR2).\r
6292\r
6293 Reads and returns the current value of CR2. This function is only available\r
030cd1a2 6294 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6295 x64.\r
ac644614 6296\r
6297 @return The value of the Control Register 2 (CR2).\r
6298\r
6299**/\r
6300UINTN\r
6301EFIAPI\r
6302AsmReadCr2 (\r
6303 VOID\r
6304 );\r
6305\r
6306\r
6307/**\r
6308 Reads the current value of the Control Register 3 (CR3).\r
6309\r
6310 Reads and returns the current value of CR3. This function is only available\r
030cd1a2 6311 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6312 x64.\r
ac644614 6313\r
6314 @return The value of the Control Register 3 (CR3).\r
6315\r
6316**/\r
6317UINTN\r
6318EFIAPI\r
6319AsmReadCr3 (\r
6320 VOID\r
6321 );\r
6322\r
6323\r
6324/**\r
6325 Reads the current value of the Control Register 4 (CR4).\r
6326\r
6327 Reads and returns the current value of CR4. This function is only available\r
030cd1a2 6328 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6329 x64.\r
ac644614 6330\r
6331 @return The value of the Control Register 4 (CR4).\r
6332\r
6333**/\r
6334UINTN\r
6335EFIAPI\r
6336AsmReadCr4 (\r
6337 VOID\r
6338 );\r
6339\r
6340\r
6341/**\r
6342 Writes a value to Control Register 0 (CR0).\r
6343\r
6344 Writes and returns a new value to CR0. This function is only available on\r
030cd1a2 6345 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6346\r
6347 @param Cr0 The value to write to CR0.\r
6348\r
6349 @return The value written to CR0.\r
6350\r
6351**/\r
6352UINTN\r
6353EFIAPI\r
6354AsmWriteCr0 (\r
6355 UINTN Cr0\r
6356 );\r
6357\r
6358\r
6359/**\r
6360 Writes a value to Control Register 2 (CR2).\r
6361\r
6362 Writes and returns a new value to CR2. This function is only available on\r
030cd1a2 6363 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6364\r
6365 @param Cr2 The value to write to CR2.\r
6366\r
6367 @return The value written to CR2.\r
6368\r
6369**/\r
6370UINTN\r
6371EFIAPI\r
6372AsmWriteCr2 (\r
6373 UINTN Cr2\r
6374 );\r
6375\r
6376\r
6377/**\r
6378 Writes a value to Control Register 3 (CR3).\r
6379\r
6380 Writes and returns a new value to CR3. This function is only available on\r
030cd1a2 6381 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6382\r
6383 @param Cr3 The value to write to CR3.\r
6384\r
6385 @return The value written to CR3.\r
6386\r
6387**/\r
6388UINTN\r
6389EFIAPI\r
6390AsmWriteCr3 (\r
6391 UINTN Cr3\r
6392 );\r
6393\r
6394\r
6395/**\r
6396 Writes a value to Control Register 4 (CR4).\r
6397\r
6398 Writes and returns a new value to CR4. This function is only available on\r
030cd1a2 6399 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6400\r
6401 @param Cr4 The value to write to CR4.\r
6402\r
6403 @return The value written to CR4.\r
6404\r
6405**/\r
6406UINTN\r
6407EFIAPI\r
6408AsmWriteCr4 (\r
6409 UINTN Cr4\r
6410 );\r
6411\r
6412\r
6413/**\r
6414 Reads the current value of Debug Register 0 (DR0).\r
6415\r
6416 Reads and returns the current value of DR0. This function is only available\r
030cd1a2 6417 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6418 x64.\r
ac644614 6419\r
6420 @return The value of Debug Register 0 (DR0).\r
6421\r
6422**/\r
6423UINTN\r
6424EFIAPI\r
6425AsmReadDr0 (\r
6426 VOID\r
6427 );\r
6428\r
6429\r
6430/**\r
6431 Reads the current value of Debug Register 1 (DR1).\r
6432\r
6433 Reads and returns the current value of DR1. This function is only available\r
030cd1a2 6434 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6435 x64.\r
ac644614 6436\r
6437 @return The value of Debug Register 1 (DR1).\r
6438\r
6439**/\r
6440UINTN\r
6441EFIAPI\r
6442AsmReadDr1 (\r
6443 VOID\r
6444 );\r
6445\r
6446\r
6447/**\r
6448 Reads the current value of Debug Register 2 (DR2).\r
6449\r
6450 Reads and returns the current value of DR2. This function is only available\r
030cd1a2 6451 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6452 x64.\r
ac644614 6453\r
6454 @return The value of Debug Register 2 (DR2).\r
6455\r
6456**/\r
6457UINTN\r
6458EFIAPI\r
6459AsmReadDr2 (\r
6460 VOID\r
6461 );\r
6462\r
6463\r
6464/**\r
6465 Reads the current value of Debug Register 3 (DR3).\r
6466\r
6467 Reads and returns the current value of DR3. This function is only available\r
030cd1a2 6468 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6469 x64.\r
ac644614 6470\r
6471 @return The value of Debug Register 3 (DR3).\r
6472\r
6473**/\r
6474UINTN\r
6475EFIAPI\r
6476AsmReadDr3 (\r
6477 VOID\r
6478 );\r
6479\r
6480\r
6481/**\r
6482 Reads the current value of Debug Register 4 (DR4).\r
6483\r
6484 Reads and returns the current value of DR4. This function is only available\r
030cd1a2 6485 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6486 x64.\r
ac644614 6487\r
6488 @return The value of Debug Register 4 (DR4).\r
6489\r
6490**/\r
6491UINTN\r
6492EFIAPI\r
6493AsmReadDr4 (\r
6494 VOID\r
6495 );\r
6496\r
6497\r
6498/**\r
6499 Reads the current value of Debug Register 5 (DR5).\r
6500\r
6501 Reads and returns the current value of DR5. This function is only available\r
030cd1a2 6502 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6503 x64.\r
ac644614 6504\r
6505 @return The value of Debug Register 5 (DR5).\r
6506\r
6507**/\r
6508UINTN\r
6509EFIAPI\r
6510AsmReadDr5 (\r
6511 VOID\r
6512 );\r
6513\r
6514\r
6515/**\r
6516 Reads the current value of Debug Register 6 (DR6).\r
6517\r
6518 Reads and returns the current value of DR6. This function is only available\r
030cd1a2 6519 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6520 x64.\r
ac644614 6521\r
6522 @return The value of Debug Register 6 (DR6).\r
6523\r
6524**/\r
6525UINTN\r
6526EFIAPI\r
6527AsmReadDr6 (\r
6528 VOID\r
6529 );\r
6530\r
6531\r
6532/**\r
6533 Reads the current value of Debug Register 7 (DR7).\r
6534\r
6535 Reads and returns the current value of DR7. This function is only available\r
030cd1a2 6536 on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on\r
6537 x64.\r
ac644614 6538\r
6539 @return The value of Debug Register 7 (DR7).\r
6540\r
6541**/\r
6542UINTN\r
6543EFIAPI\r
6544AsmReadDr7 (\r
6545 VOID\r
6546 );\r
6547\r
6548\r
6549/**\r
6550 Writes a value to Debug Register 0 (DR0).\r
6551\r
6552 Writes and returns a new value to DR0. This function is only available on\r
030cd1a2 6553 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6554\r
6555 @param Dr0 The value to write to Dr0.\r
6556\r
6557 @return The value written to Debug Register 0 (DR0).\r
6558\r
6559**/\r
6560UINTN\r
6561EFIAPI\r
6562AsmWriteDr0 (\r
6563 UINTN Dr0\r
6564 );\r
6565\r
6566\r
6567/**\r
6568 Writes a value to Debug Register 1 (DR1).\r
6569\r
6570 Writes and returns a new value to DR1. This function is only available on\r
030cd1a2 6571 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6572\r
6573 @param Dr1 The value to write to Dr1.\r
6574\r
6575 @return The value written to Debug Register 1 (DR1).\r
6576\r
6577**/\r
6578UINTN\r
6579EFIAPI\r
6580AsmWriteDr1 (\r
6581 UINTN Dr1\r
6582 );\r
6583\r
6584\r
6585/**\r
6586 Writes a value to Debug Register 2 (DR2).\r
6587\r
6588 Writes and returns a new value to DR2. This function is only available on\r
030cd1a2 6589 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6590\r
6591 @param Dr2 The value to write to Dr2.\r
6592\r
6593 @return The value written to Debug Register 2 (DR2).\r
6594\r
6595**/\r
6596UINTN\r
6597EFIAPI\r
6598AsmWriteDr2 (\r
6599 UINTN Dr2\r
6600 );\r
6601\r
6602\r
6603/**\r
6604 Writes a value to Debug Register 3 (DR3).\r
6605\r
6606 Writes and returns a new value to DR3. This function is only available on\r
030cd1a2 6607 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6608\r
6609 @param Dr3 The value to write to Dr3.\r
6610\r
6611 @return The value written to Debug Register 3 (DR3).\r
6612\r
6613**/\r
6614UINTN\r
6615EFIAPI\r
6616AsmWriteDr3 (\r
6617 UINTN Dr3\r
6618 );\r
6619\r
6620\r
6621/**\r
6622 Writes a value to Debug Register 4 (DR4).\r
6623\r
6624 Writes and returns a new value to DR4. This function is only available on\r
030cd1a2 6625 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6626\r
6627 @param Dr4 The value to write to Dr4.\r
6628\r
6629 @return The value written to Debug Register 4 (DR4).\r
6630\r
6631**/\r
6632UINTN\r
6633EFIAPI\r
6634AsmWriteDr4 (\r
6635 UINTN Dr4\r
6636 );\r
6637\r
6638\r
6639/**\r
6640 Writes a value to Debug Register 5 (DR5).\r
6641\r
6642 Writes and returns a new value to DR5. This function is only available on\r
030cd1a2 6643 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6644\r
6645 @param Dr5 The value to write to Dr5.\r
6646\r
6647 @return The value written to Debug Register 5 (DR5).\r
6648\r
6649**/\r
6650UINTN\r
6651EFIAPI\r
6652AsmWriteDr5 (\r
6653 UINTN Dr5\r
6654 );\r
6655\r
6656\r
6657/**\r
6658 Writes a value to Debug Register 6 (DR6).\r
6659\r
6660 Writes and returns a new value to DR6. This function is only available on\r
030cd1a2 6661 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6662\r
6663 @param Dr6 The value to write to Dr6.\r
6664\r
6665 @return The value written to Debug Register 6 (DR6).\r
6666\r
6667**/\r
6668UINTN\r
6669EFIAPI\r
6670AsmWriteDr6 (\r
6671 UINTN Dr6\r
6672 );\r
6673\r
6674\r
6675/**\r
6676 Writes a value to Debug Register 7 (DR7).\r
6677\r
6678 Writes and returns a new value to DR7. This function is only available on\r
030cd1a2 6679 IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.\r
ac644614 6680\r
6681 @param Dr7 The value to write to Dr7.\r
6682\r
6683 @return The value written to Debug Register 7 (DR7).\r
6684\r
6685**/\r
6686UINTN\r
6687EFIAPI\r
6688AsmWriteDr7 (\r
6689 UINTN Dr7\r
6690 );\r
6691\r
6692\r
6693/**\r
6694 Reads the current value of Code Segment Register (CS).\r
6695\r
6696 Reads and returns the current value of CS. This function is only available on\r
030cd1a2 6697 IA-32 and x64.\r
ac644614 6698\r
6699 @return The current value of CS.\r
6700\r
6701**/\r
6702UINT16\r
6703EFIAPI\r
6704AsmReadCs (\r
6705 VOID\r
6706 );\r
6707\r
6708\r
6709/**\r
6710 Reads the current value of Data Segment Register (DS).\r
6711\r
6712 Reads and returns the current value of DS. This function is only available on\r
030cd1a2 6713 IA-32 and x64.\r
ac644614 6714\r
6715 @return The current value of DS.\r
6716\r
6717**/\r
6718UINT16\r
6719EFIAPI\r
6720AsmReadDs (\r
6721 VOID\r
6722 );\r
6723\r
6724\r
6725/**\r
6726 Reads the current value of Extra Segment Register (ES).\r
6727\r
6728 Reads and returns the current value of ES. This function is only available on\r
030cd1a2 6729 IA-32 and x64.\r
ac644614 6730\r
6731 @return The current value of ES.\r
6732\r
6733**/\r
6734UINT16\r
6735EFIAPI\r
6736AsmReadEs (\r
6737 VOID\r
6738 );\r
6739\r
6740\r
6741/**\r
6742 Reads the current value of FS Data Segment Register (FS).\r
6743\r
6744 Reads and returns the current value of FS. This function is only available on\r
030cd1a2 6745 IA-32 and x64.\r
ac644614 6746\r
6747 @return The current value of FS.\r
6748\r
6749**/\r
6750UINT16\r
6751EFIAPI\r
6752AsmReadFs (\r
6753 VOID\r
6754 );\r
6755\r
6756\r
6757/**\r
6758 Reads the current value of GS Data Segment Register (GS).\r
6759\r
6760 Reads and returns the current value of GS. This function is only available on\r
030cd1a2 6761 IA-32 and x64.\r
ac644614 6762\r
6763 @return The current value of GS.\r
6764\r
6765**/\r
6766UINT16\r
6767EFIAPI\r
6768AsmReadGs (\r
6769 VOID\r
6770 );\r
6771\r
6772\r
6773/**\r
6774 Reads the current value of Stack Segment Register (SS).\r
6775\r
6776 Reads and returns the current value of SS. This function is only available on\r
030cd1a2 6777 IA-32 and x64.\r
ac644614 6778\r
6779 @return The current value of SS.\r
6780\r
6781**/\r
6782UINT16\r
6783EFIAPI\r
6784AsmReadSs (\r
6785 VOID\r
6786 );\r
6787\r
6788\r
6789/**\r
6790 Reads the current value of Task Register (TR).\r
6791\r
6792 Reads and returns the current value of TR. This function is only available on\r
030cd1a2 6793 IA-32 and x64.\r
ac644614 6794\r
6795 @return The current value of TR.\r
6796\r
6797**/\r
6798UINT16\r
6799EFIAPI\r
6800AsmReadTr (\r
6801 VOID\r
6802 );\r
6803\r
6804\r
6805/**\r
6806 Reads the current Global Descriptor Table Register(GDTR) descriptor.\r
6807\r
6808 Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r
030cd1a2 6809 function is only available on IA-32 and x64.\r
ac644614 6810\r
6811 If Gdtr is NULL, then ASSERT().\r
6812\r
af2dc6a7 6813 @param Gdtr The pointer to a GDTR descriptor.\r
ac644614 6814\r
6815**/\r
6816VOID\r
6817EFIAPI\r
6818AsmReadGdtr (\r
6819 OUT IA32_DESCRIPTOR *Gdtr\r
6820 );\r
6821\r
6822\r
6823/**\r
6824 Writes the current Global Descriptor Table Register (GDTR) descriptor.\r
6825\r
6826 Writes and the current GDTR descriptor specified by Gdtr. This function is\r
030cd1a2 6827 only available on IA-32 and x64.\r
ac644614 6828\r
6829 If Gdtr is NULL, then ASSERT().\r
6830\r
af2dc6a7 6831 @param Gdtr The pointer to a GDTR descriptor.\r
ac644614 6832\r
6833**/\r
6834VOID\r
6835EFIAPI\r
6836AsmWriteGdtr (\r
6837 IN CONST IA32_DESCRIPTOR *Gdtr\r
6838 );\r
6839\r
6840\r
6841/**\r
17f695ed 6842 Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.\r
ac644614 6843\r
6844 Reads and returns the current IDTR descriptor and returns it in Idtr. This\r
030cd1a2 6845 function is only available on IA-32 and x64.\r
ac644614 6846\r
6847 If Idtr is NULL, then ASSERT().\r
6848\r
af2dc6a7 6849 @param Idtr The pointer to a IDTR descriptor.\r
ac644614 6850\r
6851**/\r
6852VOID\r
6853EFIAPI\r
6854AsmReadIdtr (\r
6855 OUT IA32_DESCRIPTOR *Idtr\r
6856 );\r
6857\r
6858\r
6859/**\r
17f695ed 6860 Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.\r
ac644614 6861\r
6862 Writes the current IDTR descriptor and returns it in Idtr. This function is\r
030cd1a2 6863 only available on IA-32 and x64.\r
ac644614 6864\r
6865 If Idtr is NULL, then ASSERT().\r
6866\r
af2dc6a7 6867 @param Idtr The pointer to a IDTR descriptor.\r
ac644614 6868\r
6869**/\r
6870VOID\r
6871EFIAPI\r
6872AsmWriteIdtr (\r
6873 IN CONST IA32_DESCRIPTOR *Idtr\r
6874 );\r
6875\r
6876\r
6877/**\r
6878 Reads the current Local Descriptor Table Register(LDTR) selector.\r
6879\r
6880 Reads and returns the current 16-bit LDTR descriptor value. This function is\r
030cd1a2 6881 only available on IA-32 and x64.\r
ac644614 6882\r
6883 @return The current selector of LDT.\r
6884\r
6885**/\r
6886UINT16\r
6887EFIAPI\r
6888AsmReadLdtr (\r
6889 VOID\r
6890 );\r
6891\r
6892\r
6893/**\r
17f695ed 6894 Writes the current Local Descriptor Table Register (LDTR) selector.\r
ac644614 6895\r
6896 Writes and the current LDTR descriptor specified by Ldtr. This function is\r
030cd1a2 6897 only available on IA-32 and x64.\r
ac644614 6898\r
6899 @param Ldtr 16-bit LDTR selector value.\r
6900\r
6901**/\r
6902VOID\r
6903EFIAPI\r
6904AsmWriteLdtr (\r
6905 IN UINT16 Ldtr\r
6906 );\r
6907\r
6908\r
6909/**\r
6910 Save the current floating point/SSE/SSE2 context to a buffer.\r
6911\r
6912 Saves the current floating point/SSE/SSE2 state to the buffer specified by\r
6913 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r
030cd1a2 6914 available on IA-32 and x64.\r
ac644614 6915\r
6916 If Buffer is NULL, then ASSERT().\r
6917 If Buffer is not aligned on a 16-byte boundary, then ASSERT().\r
6918\r
af2dc6a7 6919 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
ac644614 6920\r
6921**/\r
6922VOID\r
6923EFIAPI\r
6924AsmFxSave (\r
6925 OUT IA32_FX_BUFFER *Buffer\r
6926 );\r
6927\r
6928\r
6929/**\r
6930 Restores the current floating point/SSE/SSE2 context from a buffer.\r
6931\r
6932 Restores the current floating point/SSE/SSE2 state from the buffer specified\r
6933 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r
030cd1a2 6934 only available on IA-32 and x64.\r
ac644614 6935\r
6936 If Buffer is NULL, then ASSERT().\r
6937 If Buffer is not aligned on a 16-byte boundary, then ASSERT().\r
6938 If Buffer was not saved with AsmFxSave(), then ASSERT().\r
6939\r
af2dc6a7 6940 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.\r
ac644614 6941\r
6942**/\r
6943VOID\r
6944EFIAPI\r
6945AsmFxRestore (\r
6946 IN CONST IA32_FX_BUFFER *Buffer\r
6947 );\r
6948\r
6949\r
6950/**\r
6951 Reads the current value of 64-bit MMX Register #0 (MM0).\r
6952\r
6953 Reads and returns the current value of MM0. This function is only available\r
030cd1a2 6954 on IA-32 and x64.\r
ac644614 6955\r
6956 @return The current value of MM0.\r
6957\r
6958**/\r
6959UINT64\r
6960EFIAPI\r
6961AsmReadMm0 (\r
6962 VOID\r
6963 );\r
6964\r
6965\r
6966/**\r
6967 Reads the current value of 64-bit MMX Register #1 (MM1).\r
6968\r
6969 Reads and returns the current value of MM1. This function is only available\r
030cd1a2 6970 on IA-32 and x64.\r
ac644614 6971\r
6972 @return The current value of MM1.\r
6973\r
6974**/\r
6975UINT64\r
6976EFIAPI\r
6977AsmReadMm1 (\r
6978 VOID\r
6979 );\r
6980\r
6981\r
6982/**\r
6983 Reads the current value of 64-bit MMX Register #2 (MM2).\r
6984\r
6985 Reads and returns the current value of MM2. This function is only available\r
030cd1a2 6986 on IA-32 and x64.\r
ac644614 6987\r
6988 @return The current value of MM2.\r
6989\r
6990**/\r
6991UINT64\r
6992EFIAPI\r
6993AsmReadMm2 (\r
6994 VOID\r
6995 );\r
6996\r
6997\r
6998/**\r
6999 Reads the current value of 64-bit MMX Register #3 (MM3).\r
7000\r
7001 Reads and returns the current value of MM3. This function is only available\r
030cd1a2 7002 on IA-32 and x64.\r
ac644614 7003\r
7004 @return The current value of MM3.\r
7005\r
7006**/\r
7007UINT64\r
7008EFIAPI\r
7009AsmReadMm3 (\r
7010 VOID\r
7011 );\r
7012\r
7013\r
7014/**\r
7015 Reads the current value of 64-bit MMX Register #4 (MM4).\r
7016\r
7017 Reads and returns the current value of MM4. This function is only available\r
030cd1a2 7018 on IA-32 and x64.\r
ac644614 7019\r
7020 @return The current value of MM4.\r
7021\r
7022**/\r
7023UINT64\r
7024EFIAPI\r
7025AsmReadMm4 (\r
7026 VOID\r
7027 );\r
7028\r
7029\r
7030/**\r
7031 Reads the current value of 64-bit MMX Register #5 (MM5).\r
7032\r
7033 Reads and returns the current value of MM5. This function is only available\r
030cd1a2 7034 on IA-32 and x64.\r
ac644614 7035\r
7036 @return The current value of MM5.\r
7037\r
7038**/\r
7039UINT64\r
7040EFIAPI\r
7041AsmReadMm5 (\r
7042 VOID\r
7043 );\r
7044\r
7045\r
7046/**\r
7047 Reads the current value of 64-bit MMX Register #6 (MM6).\r
7048\r
7049 Reads and returns the current value of MM6. This function is only available\r
030cd1a2 7050 on IA-32 and x64.\r
ac644614 7051\r
7052 @return The current value of MM6.\r
7053\r
7054**/\r
7055UINT64\r
7056EFIAPI\r
7057AsmReadMm6 (\r
7058 VOID\r
7059 );\r
7060\r
7061\r
7062/**\r
7063 Reads the current value of 64-bit MMX Register #7 (MM7).\r
7064\r
7065 Reads and returns the current value of MM7. This function is only available\r
030cd1a2 7066 on IA-32 and x64.\r
ac644614 7067\r
7068 @return The current value of MM7.\r
7069\r
7070**/\r
7071UINT64\r
7072EFIAPI\r
7073AsmReadMm7 (\r
7074 VOID\r
7075 );\r
7076\r
7077\r
7078/**\r
7079 Writes the current value of 64-bit MMX Register #0 (MM0).\r
7080\r
7081 Writes the current value of MM0. This function is only available on IA32 and\r
030cd1a2 7082 x64.\r
ac644614 7083\r
7084 @param Value The 64-bit value to write to MM0.\r
7085\r
7086**/\r
7087VOID\r
7088EFIAPI\r
7089AsmWriteMm0 (\r
7090 IN UINT64 Value\r
7091 );\r
7092\r
7093\r
7094/**\r
7095 Writes the current value of 64-bit MMX Register #1 (MM1).\r
7096\r
7097 Writes the current value of MM1. This function is only available on IA32 and\r
030cd1a2 7098 x64.\r
ac644614 7099\r
7100 @param Value The 64-bit value to write to MM1.\r
7101\r
7102**/\r
7103VOID\r
7104EFIAPI\r
7105AsmWriteMm1 (\r
7106 IN UINT64 Value\r
7107 );\r
7108\r
7109\r
7110/**\r
7111 Writes the current value of 64-bit MMX Register #2 (MM2).\r
7112\r
7113 Writes the current value of MM2. This function is only available on IA32 and\r
030cd1a2 7114 x64.\r
ac644614 7115\r
7116 @param Value The 64-bit value to write to MM2.\r
7117\r
7118**/\r
7119VOID\r
7120EFIAPI\r
7121AsmWriteMm2 (\r
7122 IN UINT64 Value\r
7123 );\r
7124\r
7125\r
7126/**\r
7127 Writes the current value of 64-bit MMX Register #3 (MM3).\r
7128\r
7129 Writes the current value of MM3. This function is only available on IA32 and\r
030cd1a2 7130 x64.\r
ac644614 7131\r
7132 @param Value The 64-bit value to write to MM3.\r
7133\r
7134**/\r
7135VOID\r
7136EFIAPI\r
7137AsmWriteMm3 (\r
7138 IN UINT64 Value\r
7139 );\r
7140\r
7141\r
7142/**\r
7143 Writes the current value of 64-bit MMX Register #4 (MM4).\r
7144\r
7145 Writes the current value of MM4. This function is only available on IA32 and\r
030cd1a2 7146 x64.\r
ac644614 7147\r
7148 @param Value The 64-bit value to write to MM4.\r
7149\r
7150**/\r
7151VOID\r
7152EFIAPI\r
7153AsmWriteMm4 (\r
7154 IN UINT64 Value\r
7155 );\r
7156\r
7157\r
7158/**\r
7159 Writes the current value of 64-bit MMX Register #5 (MM5).\r
7160\r
7161 Writes the current value of MM5. This function is only available on IA32 and\r
030cd1a2 7162 x64.\r
ac644614 7163\r
7164 @param Value The 64-bit value to write to MM5.\r
7165\r
7166**/\r
7167VOID\r
7168EFIAPI\r
7169AsmWriteMm5 (\r
7170 IN UINT64 Value\r
7171 );\r
7172\r
7173\r
7174/**\r
7175 Writes the current value of 64-bit MMX Register #6 (MM6).\r
7176\r
7177 Writes the current value of MM6. This function is only available on IA32 and\r
030cd1a2 7178 x64.\r
ac644614 7179\r
7180 @param Value The 64-bit value to write to MM6.\r
7181\r
7182**/\r
7183VOID\r
7184EFIAPI\r
7185AsmWriteMm6 (\r
7186 IN UINT64 Value\r
7187 );\r
7188\r
7189\r
7190/**\r
7191 Writes the current value of 64-bit MMX Register #7 (MM7).\r
7192\r
7193 Writes the current value of MM7. This function is only available on IA32 and\r
030cd1a2 7194 x64.\r
ac644614 7195\r
7196 @param Value The 64-bit value to write to MM7.\r
7197\r
7198**/\r
7199VOID\r
7200EFIAPI\r
7201AsmWriteMm7 (\r
7202 IN UINT64 Value\r
7203 );\r
7204\r
7205\r
7206/**\r
7207 Reads the current value of Time Stamp Counter (TSC).\r
7208\r
7209 Reads and returns the current value of TSC. This function is only available\r
030cd1a2 7210 on IA-32 and x64.\r
ac644614 7211\r
7212 @return The current value of TSC\r
7213\r
7214**/\r
7215UINT64\r
7216EFIAPI\r
7217AsmReadTsc (\r
7218 VOID\r
7219 );\r
7220\r
7221\r
7222/**\r
7223 Reads the current value of a Performance Counter (PMC).\r
7224\r
7225 Reads and returns the current value of performance counter specified by\r
030cd1a2 7226 Index. This function is only available on IA-32 and x64.\r
ac644614 7227\r
7228 @param Index The 32-bit Performance Counter index to read.\r
7229\r
7230 @return The value of the PMC specified by Index.\r
7231\r
7232**/\r
7233UINT64\r
7234EFIAPI\r
7235AsmReadPmc (\r
7236 IN UINT32 Index\r
7237 );\r
7238\r
7239\r
7240/**\r
7241 Sets up a monitor buffer that is used by AsmMwait().\r
7242\r
7243 Executes a MONITOR instruction with the register state specified by Eax, Ecx\r
030cd1a2 7244 and Edx. Returns Eax. This function is only available on IA-32 and x64.\r
ac644614 7245\r
7246 @param Eax The value to load into EAX or RAX before executing the MONITOR\r
7247 instruction.\r
7248 @param Ecx The value to load into ECX or RCX before executing the MONITOR\r
7249 instruction.\r
7250 @param Edx The value to load into EDX or RDX before executing the MONITOR\r
7251 instruction.\r
7252\r
7253 @return Eax\r
7254\r
7255**/\r
7256UINTN\r
7257EFIAPI\r
7258AsmMonitor (\r
7259 IN UINTN Eax,\r
7260 IN UINTN Ecx,\r
7261 IN UINTN Edx\r
7262 );\r
7263\r
7264\r
7265/**\r
7266 Executes an MWAIT instruction.\r
7267\r
7268 Executes an MWAIT instruction with the register state specified by Eax and\r
030cd1a2 7269 Ecx. Returns Eax. This function is only available on IA-32 and x64.\r
ac644614 7270\r
7271 @param Eax The value to load into EAX or RAX before executing the MONITOR\r
7272 instruction.\r
7273 @param Ecx The value to load into ECX or RCX before executing the MONITOR\r
7274 instruction.\r
7275\r
7276 @return Eax\r
7277\r
7278**/\r
7279UINTN\r
7280EFIAPI\r
7281AsmMwait (\r
7282 IN UINTN Eax,\r
7283 IN UINTN Ecx\r
7284 );\r
7285\r
7286\r
7287/**\r
7288 Executes a WBINVD instruction.\r
7289\r
7290 Executes a WBINVD instruction. This function is only available on IA-32 and\r
030cd1a2 7291 x64.\r
ac644614 7292\r
7293**/\r
7294VOID\r
7295EFIAPI\r
7296AsmWbinvd (\r
7297 VOID\r
7298 );\r
7299\r
7300\r
7301/**\r
7302 Executes a INVD instruction.\r
7303\r
7304 Executes a INVD instruction. This function is only available on IA-32 and\r
030cd1a2 7305 x64.\r
ac644614 7306\r
7307**/\r
7308VOID\r
7309EFIAPI\r
7310AsmInvd (\r
7311 VOID\r
7312 );\r
7313\r
7314\r
7315/**\r
7316 Flushes a cache line from all the instruction and data caches within the\r
7317 coherency domain of the CPU.\r
7318\r
7319 Flushed the cache line specified by LinearAddress, and returns LinearAddress.\r
030cd1a2 7320 This function is only available on IA-32 and x64.\r
ac644614 7321\r
7322 @param LinearAddress The address of the cache line to flush. If the CPU is\r
7323 in a physical addressing mode, then LinearAddress is a\r
7324 physical address. If the CPU is in a virtual\r
7325 addressing mode, then LinearAddress is a virtual\r
7326 address.\r
7327\r
af2dc6a7 7328 @return LinearAddress.\r
ac644614 7329**/\r
7330VOID *\r
7331EFIAPI\r
7332AsmFlushCacheLine (\r
7333 IN VOID *LinearAddress\r
7334 );\r
7335\r
7336\r
7337/**\r
7338 Enables the 32-bit paging mode on the CPU.\r
7339\r
7340 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r
7341 must be properly initialized prior to calling this service. This function\r
7342 assumes the current execution mode is 32-bit protected mode. This function is\r
7343 only available on IA-32. After the 32-bit paging mode is enabled, control is\r
7344 transferred to the function specified by EntryPoint using the new stack\r
7345 specified by NewStack and passing in the parameters specified by Context1 and\r
7346 Context2. Context1 and Context2 are optional and may be NULL. The function\r
7347 EntryPoint must never return.\r
7348\r
7349 If the current execution mode is not 32-bit protected mode, then ASSERT().\r
7350 If EntryPoint is NULL, then ASSERT().\r
7351 If NewStack is NULL, then ASSERT().\r
7352\r
7353 There are a number of constraints that must be followed before calling this\r
7354 function:\r
7355 1) Interrupts must be disabled.\r
7356 2) The caller must be in 32-bit protected mode with flat descriptors. This\r
7357 means all descriptors must have a base of 0 and a limit of 4GB.\r
7358 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat\r
7359 descriptors.\r
7360 4) CR3 must point to valid page tables that will be used once the transition\r
7361 is complete, and those page tables must guarantee that the pages for this\r
7362 function and the stack are identity mapped.\r
7363\r
7364 @param EntryPoint A pointer to function to call with the new stack after\r
7365 paging is enabled.\r
7366 @param Context1 A pointer to the context to pass into the EntryPoint\r
7367 function as the first parameter after paging is enabled.\r
7368 @param Context2 A pointer to the context to pass into the EntryPoint\r
7369 function as the second parameter after paging is enabled.\r
7370 @param NewStack A pointer to the new stack to use for the EntryPoint\r
7371 function after paging is enabled.\r
7372\r
7373**/\r
7374VOID\r
7375EFIAPI\r
7376AsmEnablePaging32 (\r
7377 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
7378 IN VOID *Context1, OPTIONAL\r
7379 IN VOID *Context2, OPTIONAL\r
7380 IN VOID *NewStack\r
7381 );\r
7382\r
7383\r
7384/**\r
7385 Disables the 32-bit paging mode on the CPU.\r
7386\r
7387 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected\r
7388 mode. This function assumes the current execution mode is 32-paged protected\r
7389 mode. This function is only available on IA-32. After the 32-bit paging mode\r
7390 is disabled, control is transferred to the function specified by EntryPoint\r
7391 using the new stack specified by NewStack and passing in the parameters\r
7392 specified by Context1 and Context2. Context1 and Context2 are optional and\r
7393 may be NULL. The function EntryPoint must never return.\r
7394\r
7395 If the current execution mode is not 32-bit paged mode, then ASSERT().\r
7396 If EntryPoint is NULL, then ASSERT().\r
7397 If NewStack is NULL, then ASSERT().\r
7398\r
7399 There are a number of constraints that must be followed before calling this\r
7400 function:\r
7401 1) Interrupts must be disabled.\r
7402 2) The caller must be in 32-bit paged mode.\r
7403 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.\r
7404 4) CR3 must point to valid page tables that guarantee that the pages for\r
7405 this function and the stack are identity mapped.\r
7406\r
7407 @param EntryPoint A pointer to function to call with the new stack after\r
7408 paging is disabled.\r
7409 @param Context1 A pointer to the context to pass into the EntryPoint\r
7410 function as the first parameter after paging is disabled.\r
7411 @param Context2 A pointer to the context to pass into the EntryPoint\r
7412 function as the second parameter after paging is\r
7413 disabled.\r
7414 @param NewStack A pointer to the new stack to use for the EntryPoint\r
7415 function after paging is disabled.\r
7416\r
7417**/\r
7418VOID\r
7419EFIAPI\r
7420AsmDisablePaging32 (\r
7421 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
7422 IN VOID *Context1, OPTIONAL\r
7423 IN VOID *Context2, OPTIONAL\r
7424 IN VOID *NewStack\r
7425 );\r
7426\r
7427\r
7428/**\r
7429 Enables the 64-bit paging mode on the CPU.\r
7430\r
7431 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r
7432 must be properly initialized prior to calling this service. This function\r
7433 assumes the current execution mode is 32-bit protected mode with flat\r
7434 descriptors. This function is only available on IA-32. After the 64-bit\r
7435 paging mode is enabled, control is transferred to the function specified by\r
7436 EntryPoint using the new stack specified by NewStack and passing in the\r
7437 parameters specified by Context1 and Context2. Context1 and Context2 are\r
7438 optional and may be 0. The function EntryPoint must never return.\r
7439\r
7440 If the current execution mode is not 32-bit protected mode with flat\r
7441 descriptors, then ASSERT().\r
7442 If EntryPoint is 0, then ASSERT().\r
7443 If NewStack is 0, then ASSERT().\r
7444\r
17f695ed 7445 @param Cs The 16-bit selector to load in the CS before EntryPoint\r
ac644614 7446 is called. The descriptor in the GDT that this selector\r
7447 references must be setup for long mode.\r
7448 @param EntryPoint The 64-bit virtual address of the function to call with\r
7449 the new stack after paging is enabled.\r
7450 @param Context1 The 64-bit virtual address of the context to pass into\r
7451 the EntryPoint function as the first parameter after\r
7452 paging is enabled.\r
7453 @param Context2 The 64-bit virtual address of the context to pass into\r
7454 the EntryPoint function as the second parameter after\r
7455 paging is enabled.\r
7456 @param NewStack The 64-bit virtual address of the new stack to use for\r
7457 the EntryPoint function after paging is enabled.\r
7458\r
7459**/\r
7460VOID\r
7461EFIAPI\r
7462AsmEnablePaging64 (\r
17f695ed 7463 IN UINT16 Cs,\r
ac644614 7464 IN UINT64 EntryPoint,\r
7465 IN UINT64 Context1, OPTIONAL\r
7466 IN UINT64 Context2, OPTIONAL\r
7467 IN UINT64 NewStack\r
7468 );\r
7469\r
7470\r
7471/**\r
7472 Disables the 64-bit paging mode on the CPU.\r
7473\r
7474 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected\r
7475 mode. This function assumes the current execution mode is 64-paging mode.\r
030cd1a2 7476 This function is only available on x64. After the 64-bit paging mode is\r
ac644614 7477 disabled, control is transferred to the function specified by EntryPoint\r
7478 using the new stack specified by NewStack and passing in the parameters\r
7479 specified by Context1 and Context2. Context1 and Context2 are optional and\r
7480 may be 0. The function EntryPoint must never return.\r
7481\r
7482 If the current execution mode is not 64-bit paged mode, then ASSERT().\r
7483 If EntryPoint is 0, then ASSERT().\r
7484 If NewStack is 0, then ASSERT().\r
7485\r
17f695ed 7486 @param Cs The 16-bit selector to load in the CS before EntryPoint\r
ac644614 7487 is called. The descriptor in the GDT that this selector\r
7488 references must be setup for 32-bit protected mode.\r
7489 @param EntryPoint The 64-bit virtual address of the function to call with\r
7490 the new stack after paging is disabled.\r
7491 @param Context1 The 64-bit virtual address of the context to pass into\r
7492 the EntryPoint function as the first parameter after\r
7493 paging is disabled.\r
7494 @param Context2 The 64-bit virtual address of the context to pass into\r
7495 the EntryPoint function as the second parameter after\r
7496 paging is disabled.\r
7497 @param NewStack The 64-bit virtual address of the new stack to use for\r
7498 the EntryPoint function after paging is disabled.\r
7499\r
7500**/\r
7501VOID\r
7502EFIAPI\r
7503AsmDisablePaging64 (\r
17f695ed 7504 IN UINT16 Cs,\r
ac644614 7505 IN UINT32 EntryPoint,\r
7506 IN UINT32 Context1, OPTIONAL\r
7507 IN UINT32 Context2, OPTIONAL\r
7508 IN UINT32 NewStack\r
7509 );\r
7510\r
7511\r
7512//\r
7513// 16-bit thunking services\r
7514//\r
7515\r
7516/**\r
7517 Retrieves the properties for 16-bit thunk functions.\r
7518\r
7519 Computes the size of the buffer and stack below 1MB required to use the\r
7520 AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This\r
7521 buffer size is returned in RealModeBufferSize, and the stack size is returned\r
7522 in ExtraStackSize. If parameters are passed to the 16-bit real mode code,\r
7523 then the actual minimum stack size is ExtraStackSize plus the maximum number\r
7524 of bytes that need to be passed to the 16-bit real mode code.\r
9095d37b 7525\r
ac644614 7526 If RealModeBufferSize is NULL, then ASSERT().\r
7527 If ExtraStackSize is NULL, then ASSERT().\r
7528\r
7529 @param RealModeBufferSize A pointer to the size of the buffer below 1MB\r
7530 required to use the 16-bit thunk functions.\r
7531 @param ExtraStackSize A pointer to the extra size of stack below 1MB\r
7532 that the 16-bit thunk functions require for\r
7533 temporary storage in the transition to and from\r
7534 16-bit real mode.\r
7535\r
7536**/\r
7537VOID\r
7538EFIAPI\r
7539AsmGetThunk16Properties (\r
7540 OUT UINT32 *RealModeBufferSize,\r
7541 OUT UINT32 *ExtraStackSize\r
7542 );\r
7543\r
7544\r
7545/**\r
7546 Prepares all structures a code required to use AsmThunk16().\r
7547\r
7548 Prepares all structures and code required to use AsmThunk16().\r
9095d37b 7549\r
8243b089 7550 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the\r
7551 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.\r
ac644614 7552\r
7553 If ThunkContext is NULL, then ASSERT().\r
7554\r
7555 @param ThunkContext A pointer to the context structure that describes the\r
7556 16-bit real mode code to call.\r
7557\r
7558**/\r
7559VOID\r
7560EFIAPI\r
7561AsmPrepareThunk16 (\r
1445300f 7562 IN OUT THUNK_CONTEXT *ThunkContext\r
ac644614 7563 );\r
7564\r
7565\r
7566/**\r
7567 Transfers control to a 16-bit real mode entry point and returns the results.\r
7568\r
7569 Transfers control to a 16-bit real mode entry point and returns the results.\r
17f695ed 7570 AsmPrepareThunk16() must be called with ThunkContext before this function is used.\r
7571 This function must be called with interrupts disabled.\r
7572\r
9095d37b
LG
7573 The register state from the RealModeState field of ThunkContext is restored just prior\r
7574 to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,\r
17f695ed 7575 which is used to set the interrupt state when a 16-bit real mode entry point is called.\r
7576 Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.\r
9095d37b
LG
7577 The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to\r
7578 the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.\r
17f695ed 7579 The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,\r
9095d37b
LG
7580 so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment\r
7581 and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry\r
7582 point must exit with a RETF instruction. The register state is captured into RealModeState immediately\r
17f695ed 7583 after the RETF instruction is executed.\r
9095d37b
LG
7584\r
7585 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,\r
7586 or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure\r
7587 the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.\r
7588\r
7589 If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,\r
7590 then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.\r
17f695ed 7591 This includes the base vectors, the interrupt masks, and the edge/level trigger mode.\r
9095d37b
LG
7592\r
7593 If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code\r
17f695ed 7594 is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.\r
9095d37b
LG
7595\r
7596 If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in\r
7597 ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to\r
17f695ed 7598 disable the A20 mask.\r
9095d37b
LG
7599\r
7600 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in\r
7601 ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,\r
17f695ed 7602 then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.\r
9095d37b
LG
7603\r
7604 If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in\r
17f695ed 7605 ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.\r
9095d37b 7606\r
ac644614 7607 If ThunkContext is NULL, then ASSERT().\r
7608 If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().\r
9095d37b 7609 If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in\r
17f695ed 7610 ThunkAttributes, then ASSERT().\r
ac644614 7611\r
8243b089 7612 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the\r
af2dc6a7 7613 virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.\r
52fa075c 7614\r
ac644614 7615 @param ThunkContext A pointer to the context structure that describes the\r
7616 16-bit real mode code to call.\r
7617\r
7618**/\r
7619VOID\r
7620EFIAPI\r
7621AsmThunk16 (\r
7622 IN OUT THUNK_CONTEXT *ThunkContext\r
7623 );\r
7624\r
7625\r
7626/**\r
7627 Prepares all structures and code for a 16-bit real mode thunk, transfers\r
7628 control to a 16-bit real mode entry point, and returns the results.\r
7629\r
7630 Prepares all structures and code for a 16-bit real mode thunk, transfers\r
7631 control to a 16-bit real mode entry point, and returns the results. If the\r
7632 caller only need to perform a single 16-bit real mode thunk, then this\r
7633 service should be used. If the caller intends to make more than one 16-bit\r
7634 real mode thunk, then it is more efficient if AsmPrepareThunk16() is called\r
7635 once and AsmThunk16() can be called for each 16-bit real mode thunk.\r
7636\r
8243b089 7637 This interface is limited to be used in either physical mode or virtual modes with paging enabled where the\r
7638 virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.\r
52fa075c 7639\r
17f695ed 7640 See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.\r
ac644614 7641\r
7642 @param ThunkContext A pointer to the context structure that describes the\r
7643 16-bit real mode code to call.\r
7644\r
7645**/\r
7646VOID\r
7647EFIAPI\r
7648AsmPrepareAndThunk16 (\r
7649 IN OUT THUNK_CONTEXT *ThunkContext\r
7650 );\r
7651\r
3cfc7813
QL
7652/**\r
7653 Generates a 16-bit random number through RDRAND instruction.\r
7654\r
7655 if Rand is NULL, then ASSERT().\r
7656\r
7657 @param[out] Rand Buffer pointer to store the random result.\r
7658\r
7659 @retval TRUE RDRAND call was successful.\r
7660 @retval FALSE Failed attempts to call RDRAND.\r
7661\r
7662 **/\r
7663BOOLEAN\r
7664EFIAPI\r
7665AsmRdRand16 (\r
7666 OUT UINT16 *Rand\r
7667 );\r
7668\r
7669/**\r
7670 Generates a 32-bit random number through RDRAND instruction.\r
7671\r
7672 if Rand is NULL, then ASSERT().\r
7673\r
7674 @param[out] Rand Buffer pointer to store the random result.\r
7675\r
7676 @retval TRUE RDRAND call was successful.\r
7677 @retval FALSE Failed attempts to call RDRAND.\r
7678\r
7679**/\r
7680BOOLEAN\r
7681EFIAPI\r
7682AsmRdRand32 (\r
7683 OUT UINT32 *Rand\r
7684 );\r
7685\r
7686/**\r
7687 Generates a 64-bit random number through RDRAND instruction.\r
7688\r
7689 if Rand is NULL, then ASSERT().\r
7690\r
7691 @param[out] Rand Buffer pointer to store the random result.\r
7692\r
7693 @retval TRUE RDRAND call was successful.\r
7694 @retval FALSE Failed attempts to call RDRAND.\r
7695\r
7696**/\r
7697BOOLEAN\r
7698EFIAPI\r
7699AsmRdRand64 (\r
7700 OUT UINT64 *Rand\r
7701 );\r
7702\r
364a5474 7703/**\r
47595ac0 7704 Load given selector into TR register.\r
364a5474
JW
7705\r
7706 @param[in] Selector Task segment selector\r
7707**/\r
7708VOID\r
7709EFIAPI\r
7710AsmWriteTr (\r
7711 IN UINT16 Selector\r
7712 );\r
7713\r
2ecd8299
HW
7714/**\r
7715 Performs a serializing operation on all load-from-memory instructions that\r
7716 were issued prior the AsmLfence function.\r
7717\r
7718 Executes a LFENCE instruction. This function is only available on IA-32 and x64.\r
7719\r
7720**/\r
7721VOID\r
7722EFIAPI\r
7723AsmLfence (\r
7724 VOID\r
7725 );\r
7726\r
8596c140
LE
7727/**\r
7728 Patch the immediate operand of an IA32 or X64 instruction such that the byte,\r
7729 word, dword or qword operand is encoded at the end of the instruction's\r
7730 binary representation.\r
7731\r
7732 This function should be used to update object code that was compiled with\r
7733 NASM from assembly source code. Example:\r
7734\r
7735 NASM source code:\r
7736\r
7737 mov eax, strict dword 0 ; the imm32 zero operand will be patched\r
7738 ASM_PFX(gPatchCr3):\r
7739 mov cr3, eax\r
7740\r
7741 C source code:\r
7742\r
7743 X86_ASSEMBLY_PATCH_LABEL gPatchCr3;\r
7744 PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);\r
7745\r
7746 @param[out] InstructionEnd Pointer right past the instruction to patch. The\r
7747 immediate operand to patch is expected to\r
7748 comprise the trailing bytes of the instruction.\r
7749 If InstructionEnd is closer to address 0 than\r
7750 ValueSize permits, then ASSERT().\r
7751\r
7752 @param[in] PatchValue The constant to write to the immediate operand.\r
7753 The caller is responsible for ensuring that\r
7754 PatchValue can be represented in the byte, word,\r
7755 dword or qword operand (as indicated through\r
7756 ValueSize); otherwise ASSERT().\r
7757\r
7758 @param[in] ValueSize The size of the operand in bytes; must be 1, 2,\r
7759 4, or 8. ASSERT() otherwise.\r
7760**/\r
7761VOID\r
7762EFIAPI\r
7763PatchInstructionX86 (\r
7764 OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,\r
7765 IN UINT64 PatchValue,\r
7766 IN UINTN ValueSize\r
7767 );\r
7768\r
de4f7f52
LE
7769#endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
7770#endif // !defined (__BASE_LIB__)\r