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