]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/BaseLib.h
Detab
[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
3 functions, and CPU architecture specific functions.\r
ac644614 4\r
50a64e5b 5Copyright (c) 2006 - 2008, Intel Corporation\r
6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
ac644614 10\r
50a64e5b 11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
ac644614 13\r
14**/\r
15\r
16#ifndef __BASE_LIB__\r
17#define __BASE_LIB__\r
18\r
fc30687f 19///\r
1106ffe1 20/// Definitions for SPIN_LOCK\r
fc30687f 21///\r
ac644614 22typedef volatile UINTN SPIN_LOCK;\r
23\r
1106ffe1 24//\r
25// Definitions for architecture specific types\r
26//\r
ac644614 27#if defined (MDE_CPU_IA32)\r
fc30687f 28///\r
29/// IA32 context buffer used by SetJump() and LongJump()\r
30///\r
ac644614 31typedef struct {\r
32 UINT32 Ebx;\r
33 UINT32 Esi;\r
34 UINT32 Edi;\r
35 UINT32 Ebp;\r
36 UINT32 Esp;\r
37 UINT32 Eip;\r
38} BASE_LIBRARY_JUMP_BUFFER;\r
39\r
40#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 4\r
41\r
42#elif defined (MDE_CPU_IPF)\r
43\r
fc30687f 44///\r
45/// IPF context buffer used by SetJump() and LongJump()\r
46///\r
ac644614 47typedef struct {\r
48 UINT64 F2[2];\r
49 UINT64 F3[2];\r
50 UINT64 F4[2];\r
51 UINT64 F5[2];\r
52 UINT64 F16[2];\r
53 UINT64 F17[2];\r
54 UINT64 F18[2];\r
55 UINT64 F19[2];\r
56 UINT64 F20[2];\r
57 UINT64 F21[2];\r
58 UINT64 F22[2];\r
59 UINT64 F23[2];\r
60 UINT64 F24[2];\r
61 UINT64 F25[2];\r
62 UINT64 F26[2];\r
63 UINT64 F27[2];\r
64 UINT64 F28[2];\r
65 UINT64 F29[2];\r
66 UINT64 F30[2];\r
67 UINT64 F31[2];\r
68 UINT64 R4;\r
69 UINT64 R5;\r
70 UINT64 R6;\r
71 UINT64 R7;\r
72 UINT64 SP;\r
73 UINT64 BR0;\r
74 UINT64 BR1;\r
75 UINT64 BR2;\r
76 UINT64 BR3;\r
77 UINT64 BR4;\r
78 UINT64 BR5;\r
79 UINT64 InitialUNAT;\r
80 UINT64 AfterSpillUNAT;\r
81 UINT64 PFS;\r
82 UINT64 BSP;\r
83 UINT64 Predicates;\r
84 UINT64 LoopCount;\r
85 UINT64 FPSR;\r
86} BASE_LIBRARY_JUMP_BUFFER;\r
87\r
88#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 0x10\r
89\r
90#elif defined (MDE_CPU_X64)\r
fc30687f 91///\r
92/// X64 context buffer used by SetJump() and LongJump()\r
93///\r
ac644614 94typedef struct {\r
95 UINT64 Rbx;\r
96 UINT64 Rsp;\r
97 UINT64 Rbp;\r
98 UINT64 Rdi;\r
99 UINT64 Rsi;\r
100 UINT64 R12;\r
101 UINT64 R13;\r
102 UINT64 R14;\r
103 UINT64 R15;\r
104 UINT64 Rip;\r
105} BASE_LIBRARY_JUMP_BUFFER;\r
106\r
107#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8\r
108\r
109#elif defined (MDE_CPU_EBC)\r
fc30687f 110///\r
111/// EBC context buffer used by SetJump() and LongJump()\r
112///\r
ac644614 113typedef struct {\r
114 UINT64 R0;\r
115 UINT64 R1;\r
116 UINT64 R2;\r
117 UINT64 R3;\r
118 UINT64 IP;\r
119} BASE_LIBRARY_JUMP_BUFFER;\r
120\r
121#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8\r
122\r
123#else\r
124#error Unknown Processor Type\r
125#endif\r
126\r
127//\r
128// String Services\r
129//\r
130\r
131/**\r
132 Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
133 string and returns the new Unicode string.\r
134\r
135 This function copies the contents of the Unicode string Source to the Unicode\r
136 string Destination, and returns Destination. If Source and Destination\r
137 overlap, then the results are undefined.\r
138\r
139 If Destination is NULL, then ASSERT().\r
140 If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
141 If Source is NULL, then ASSERT().\r
142 If Source is not aligned on a 16-bit boundary, then ASSERT().\r
143 If Source and Destination overlap, then ASSERT().\r
144 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
145 PcdMaximumUnicodeStringLength Unicode characters not including the\r
146 Null-terminator, then ASSERT().\r
147\r
148 @param Destination Pointer to a Null-terminated Unicode string.\r
149 @param Source Pointer to a Null-terminated Unicode string.\r
150\r
151 @return Destiantion\r
152\r
153**/\r
154CHAR16 *\r
155EFIAPI\r
156StrCpy (\r
157 OUT CHAR16 *Destination,\r
158 IN CONST CHAR16 *Source\r
159 );\r
160\r
161\r
162/**\r
17f695ed 163 Copies up to a specified length from one Null-terminated Unicode string to \r
164 another Null-terminated Unicode string and returns the new Unicode string.\r
ac644614 165\r
166 This function copies the contents of the Unicode string Source to the Unicode\r
167 string Destination, and returns Destination. At most, Length Unicode\r
168 characters are copied from Source to Destination. If Length is 0, then\r
169 Destination is returned unmodified. If Length is greater that the number of\r
170 Unicode characters in Source, then Destination is padded with Null Unicode\r
171 characters. If Source and Destination overlap, then the results are\r
172 undefined.\r
173\r
174 If Length > 0 and Destination is NULL, then ASSERT().\r
175 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().\r
176 If Length > 0 and Source is NULL, then ASSERT().\r
177 If Length > 0 and Source is not aligned on a 16-bit bounadry, then ASSERT().\r
178 If Source and Destination overlap, then ASSERT().\r
179 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
180 PcdMaximumUnicodeStringLength Unicode characters not including the\r
181 Null-terminator, then ASSERT().\r
182\r
183 @param Destination Pointer to a Null-terminated Unicode string.\r
184 @param Source Pointer to a Null-terminated Unicode string.\r
185 @param Length Maximum number of Unicode characters to copy.\r
186\r
187 @return Destination\r
188\r
189**/\r
190CHAR16 *\r
191EFIAPI\r
192StrnCpy (\r
193 OUT CHAR16 *Destination,\r
194 IN CONST CHAR16 *Source,\r
195 IN UINTN Length\r
196 );\r
197\r
198\r
199/**\r
200 Returns the length of a Null-terminated Unicode string.\r
201\r
202 This function returns the number of Unicode characters in the Null-terminated\r
203 Unicode string specified by String.\r
204\r
205 If String is NULL, then ASSERT().\r
206 If String is not aligned on a 16-bit boundary, then ASSERT().\r
207 If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
208 PcdMaximumUnicodeStringLength Unicode characters not including the\r
209 Null-terminator, then ASSERT().\r
210\r
211 @param String Pointer to a Null-terminated Unicode string.\r
212\r
213 @return The length of String.\r
214\r
215**/\r
216UINTN\r
217EFIAPI\r
218StrLen (\r
219 IN CONST CHAR16 *String\r
220 );\r
221\r
222\r
223/**\r
224 Returns the size of a Null-terminated Unicode string in bytes, including the\r
225 Null terminator.\r
226\r
17f695ed 227 This function returns the size, in bytes, of the Null-terminated Unicode string \r
228 specified by String.\r
ac644614 229\r
230 If String is NULL, then ASSERT().\r
231 If String is not aligned on a 16-bit boundary, then ASSERT().\r
232 If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
233 PcdMaximumUnicodeStringLength Unicode characters not including the\r
234 Null-terminator, then ASSERT().\r
235\r
236 @param String Pointer to a Null-terminated Unicode string.\r
237\r
238 @return The size of String.\r
239\r
240**/\r
241UINTN\r
242EFIAPI\r
243StrSize (\r
244 IN CONST CHAR16 *String\r
245 );\r
246\r
247\r
248/**\r
249 Compares two Null-terminated Unicode strings, and returns the difference\r
250 between the first mismatched Unicode characters.\r
251\r
252 This function compares the Null-terminated Unicode string FirstString to the\r
253 Null-terminated Unicode string SecondString. If FirstString is identical to\r
254 SecondString, then 0 is returned. Otherwise, the value returned is the first\r
255 mismatched Unicode character in SecondString subtracted from the first\r
256 mismatched Unicode character in FirstString.\r
257\r
258 If FirstString is NULL, then ASSERT().\r
259 If FirstString is not aligned on a 16-bit boundary, then ASSERT().\r
260 If SecondString is NULL, then ASSERT().\r
261 If SecondString is not aligned on a 16-bit boundary, then ASSERT().\r
262 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more\r
263 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
264 Null-terminator, then ASSERT().\r
265 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more\r
266 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
267 Null-terminator, then ASSERT().\r
268\r
269 @param FirstString Pointer to a Null-terminated Unicode string.\r
270 @param SecondString Pointer to a Null-terminated Unicode string.\r
271\r
1106ffe1 272 @retval 0 FirstString is identical to SecondString.\r
273 @return others FirstString is not identical to SecondString.\r
ac644614 274\r
275**/\r
276INTN\r
277EFIAPI\r
278StrCmp (\r
279 IN CONST CHAR16 *FirstString,\r
280 IN CONST CHAR16 *SecondString\r
281 );\r
282\r
283\r
284/**\r
17f695ed 285 Compares up to a specified length the contents of two Null-terminated Unicode strings,\r
286 and returns the difference between the first mismatched Unicode characters.\r
287 \r
ac644614 288 This function compares the Null-terminated Unicode string FirstString to the\r
289 Null-terminated Unicode string SecondString. At most, Length Unicode\r
290 characters will be compared. If Length is 0, then 0 is returned. If\r
291 FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r
292 value returned is the first mismatched Unicode character in SecondString\r
293 subtracted from the first mismatched Unicode character in FirstString.\r
294\r
295 If Length > 0 and FirstString is NULL, then ASSERT().\r
296 If Length > 0 and FirstString is not aligned on a 16-bit bounadary, then ASSERT().\r
297 If Length > 0 and SecondString is NULL, then ASSERT().\r
298 If Length > 0 and SecondString is not aligned on a 16-bit bounadary, then ASSERT().\r
299 If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more\r
300 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
301 Null-terminator, then ASSERT().\r
302 If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more\r
303 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
304 Null-terminator, then ASSERT().\r
305\r
306 @param FirstString Pointer to a Null-terminated Unicode string.\r
307 @param SecondString Pointer to a Null-terminated Unicode string.\r
308 @param Length Maximum number of Unicode characters to compare.\r
309\r
1106ffe1 310 @retval 0 FirstString is identical to SecondString.\r
311 @return others FirstString is not identical to SecondString.\r
ac644614 312\r
313**/\r
314INTN\r
315EFIAPI\r
316StrnCmp (\r
317 IN CONST CHAR16 *FirstString,\r
318 IN CONST CHAR16 *SecondString,\r
319 IN UINTN Length\r
320 );\r
321\r
322\r
323/**\r
324 Concatenates one Null-terminated Unicode string to another Null-terminated\r
325 Unicode string, and returns the concatenated Unicode string.\r
326\r
327 This function concatenates two Null-terminated Unicode strings. The contents\r
328 of Null-terminated Unicode string Source are concatenated to the end of\r
329 Null-terminated Unicode string Destination. The Null-terminated concatenated\r
330 Unicode String is returned. If Source and Destination overlap, then the\r
331 results are undefined.\r
332\r
333 If Destination is NULL, then ASSERT().\r
334 If Destination is not aligned on a 16-bit bounadary, then ASSERT().\r
335 If Source is NULL, then ASSERT().\r
336 If Source is not aligned on a 16-bit bounadary, then ASSERT().\r
337 If Source and Destination overlap, then ASSERT().\r
338 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r
339 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
340 Null-terminator, then ASSERT().\r
341 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
342 PcdMaximumUnicodeStringLength Unicode characters not including the\r
343 Null-terminator, then ASSERT().\r
344 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r
345 and Source results in a Unicode string with more than\r
346 PcdMaximumUnicodeStringLength Unicode characters not including the\r
347 Null-terminator, then ASSERT().\r
348\r
349 @param Destination Pointer to a Null-terminated Unicode string.\r
350 @param Source Pointer to a Null-terminated Unicode string.\r
351\r
352 @return Destination\r
353\r
354**/\r
355CHAR16 *\r
356EFIAPI\r
357StrCat (\r
358 IN OUT CHAR16 *Destination,\r
359 IN CONST CHAR16 *Source\r
360 );\r
361\r
362\r
363/**\r
17f695ed 364 Concatenates up to a specified length one Null-terminated Unicode to the end \r
365 of another Null-terminated Unicode string, and returns the concatenated \r
ac644614 366 Unicode string.\r
367\r
368 This function concatenates two Null-terminated Unicode strings. The contents\r
369 of Null-terminated Unicode string Source are concatenated to the end of\r
370 Null-terminated Unicode string Destination, and Destination is returned. At\r
371 most, Length Unicode characters are concatenated from Source to the end of\r
372 Destination, and Destination is always Null-terminated. If Length is 0, then\r
373 Destination is returned unmodified. If Source and Destination overlap, then\r
374 the results are undefined.\r
375\r
376 If Destination is NULL, then ASSERT().\r
377 If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().\r
378 If Length > 0 and Source is NULL, then ASSERT().\r
379 If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().\r
380 If Source and Destination overlap, then ASSERT().\r
381 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r
382 than PcdMaximumUnicodeStringLength Unicode characters not including the\r
383 Null-terminator, then ASSERT().\r
384 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
385 PcdMaximumUnicodeStringLength Unicode characters not including the\r
386 Null-terminator, then ASSERT().\r
387 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r
388 and Source results in a Unicode string with more than\r
389 PcdMaximumUnicodeStringLength Unicode characters not including the\r
390 Null-terminator, then ASSERT().\r
391\r
392 @param Destination Pointer to a Null-terminated Unicode string.\r
393 @param Source Pointer to a Null-terminated Unicode string.\r
394 @param Length Maximum number of Unicode characters to concatenate from\r
395 Source.\r
396\r
397 @return Destination\r
398\r
399**/\r
400CHAR16 *\r
401EFIAPI\r
402StrnCat (\r
403 IN OUT CHAR16 *Destination,\r
404 IN CONST CHAR16 *Source,\r
405 IN UINTN Length\r
406 );\r
407\r
408/**\r
409 Returns the first occurance of a Null-terminated Unicode sub-string\r
410 in a Null-terminated Unicode string.\r
411\r
412 This function scans the contents of the Null-terminated Unicode string\r
413 specified by String and returns the first occurrence of SearchString.\r
414 If SearchString is not found in String, then NULL is returned. If\r
415 the length of SearchString is zero, then String is\r
416 returned.\r
417\r
418 If String is NULL, then ASSERT().\r
419 If String is not aligned on a 16-bit boundary, then ASSERT().\r
420 If SearchString is NULL, then ASSERT().\r
421 If SearchString is not aligned on a 16-bit boundary, then ASSERT().\r
422\r
423 If PcdMaximumUnicodeStringLength is not zero, and SearchString\r
424 or String contains more than PcdMaximumUnicodeStringLength Unicode\r
425 characters not including the Null-terminator, then ASSERT().\r
426\r
17f695ed 427 @param String Pointer to a Null-terminated Unicode string.\r
428 @param SearchString Pointer to a Null-terminated Unicode string to search for.\r
ac644614 429\r
430 @retval NULL If the SearchString does not appear in String.\r
1106ffe1 431 @return others If there is a match.\r
ac644614 432\r
433**/\r
434CHAR16 *\r
435EFIAPI\r
436StrStr (\r
17f695ed 437 IN CONST CHAR16 *String,\r
438 IN CONST CHAR16 *SearchString\r
ac644614 439 );\r
440\r
441/**\r
442 Convert a Null-terminated Unicode decimal string to a value of\r
443 type UINTN.\r
444\r
445 This function returns a value of type UINTN by interpreting the contents\r
446 of the Unicode string specified by String as a decimal number. The format\r
447 of the input Unicode string String is:\r
448\r
449 [spaces] [decimal digits].\r
450\r
451 The valid decimal digit character is in the range [0-9]. The\r
452 function will ignore the pad space, which includes spaces or\r
453 tab characters, before [decimal digits]. The running zero in the\r
454 beginning of [decimal digits] will be ignored. Then, the function\r
455 stops at the first character that is a not a valid decimal character\r
456 or a Null-terminator, whichever one comes first.\r
457\r
458 If String is NULL, then ASSERT().\r
459 If String is not aligned in a 16-bit boundary, then ASSERT().\r
460 If String has only pad spaces, then 0 is returned.\r
461 If String has no pad spaces or valid decimal digits,\r
462 then 0 is returned.\r
463 If the number represented by String overflows according\r
464 to the range defined by UINTN, then ASSERT().\r
465\r
466 If PcdMaximumUnicodeStringLength is not zero, and String contains\r
467 more than PcdMaximumUnicodeStringLength Unicode characters not including\r
468 the Null-terminator, then ASSERT().\r
469\r
17f695ed 470 @param String Pointer to a Null-terminated Unicode string.\r
ac644614 471\r
38bbd3d9 472 @retval Value translated from String.\r
ac644614 473\r
474**/\r
475UINTN\r
476EFIAPI\r
477StrDecimalToUintn (\r
17f695ed 478 IN CONST CHAR16 *String\r
ac644614 479 );\r
480\r
481/**\r
482 Convert a Null-terminated Unicode decimal string to a value of\r
483 type UINT64.\r
484\r
485 This function returns a value of type UINT64 by interpreting the contents\r
486 of the Unicode string specified by String as a decimal number. The format\r
487 of the input Unicode string String is:\r
488\r
489 [spaces] [decimal digits].\r
490\r
491 The valid decimal digit character is in the range [0-9]. The\r
492 function will ignore the pad space, which includes spaces or\r
493 tab characters, before [decimal digits]. The running zero in the\r
494 beginning of [decimal digits] will be ignored. Then, the function\r
495 stops at the first character that is a not a valid decimal character\r
496 or a Null-terminator, whichever one comes first.\r
497\r
498 If String is NULL, then ASSERT().\r
499 If String is not aligned in a 16-bit boundary, then ASSERT().\r
500 If String has only pad spaces, then 0 is returned.\r
501 If String has no pad spaces or valid decimal digits,\r
502 then 0 is returned.\r
503 If the number represented by String overflows according\r
504 to the range defined by UINT64, then ASSERT().\r
505\r
506 If PcdMaximumUnicodeStringLength is not zero, and String contains\r
507 more than PcdMaximumUnicodeStringLength Unicode characters not including\r
508 the Null-terminator, then ASSERT().\r
509\r
17f695ed 510 @param String Pointer to a Null-terminated Unicode string.\r
ac644614 511\r
38bbd3d9 512 @retval Value translated from String.\r
ac644614 513\r
514**/\r
515UINT64\r
516EFIAPI\r
517StrDecimalToUint64 (\r
17f695ed 518 IN CONST CHAR16 *String\r
ac644614 519 );\r
520 \r
521\r
522/**\r
523 Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.\r
524\r
525 This function returns a value of type UINTN by interpreting the contents\r
526 of the Unicode string specified by String as a hexadecimal number.\r
527 The format of the input Unicode string String is:\r
528\r
529 [spaces][zeros][x][hexadecimal digits].\r
530\r
531 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
532 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
533 If "x" appears in the input string, it must be prefixed with at least one 0.\r
534 The function will ignore the pad space, which includes spaces or tab characters,\r
535 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or\r
536 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the\r
537 first valid hexadecimal digit. Then, the function stops at the first character that is\r
538 a not a valid hexadecimal character or NULL, whichever one comes first.\r
539\r
540 If String is NULL, then ASSERT().\r
541 If String is not aligned in a 16-bit boundary, then ASSERT().\r
542 If String has only pad spaces, then zero is returned.\r
543 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r
544 then zero is returned.\r
545 If the number represented by String overflows according to the range defined by\r
546 UINTN, then ASSERT().\r
547\r
548 If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
549 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,\r
550 then ASSERT().\r
551\r
17f695ed 552 @param String Pointer to a Null-terminated Unicode string.\r
ac644614 553\r
38bbd3d9 554 @retval Value translated from String.\r
ac644614 555\r
556**/\r
557UINTN\r
558EFIAPI\r
559StrHexToUintn (\r
17f695ed 560 IN CONST CHAR16 *String\r
ac644614 561 );\r
562\r
563\r
564/**\r
565 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.\r
566\r
567 This function returns a value of type UINT64 by interpreting the contents\r
568 of the Unicode string specified by String as a hexadecimal number.\r
569 The format of the input Unicode string String is\r
570\r
571 [spaces][zeros][x][hexadecimal digits].\r
572\r
573 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
574 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
575 If "x" appears in the input string, it must be prefixed with at least one 0.\r
576 The function will ignore the pad space, which includes spaces or tab characters,\r
577 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or\r
578 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the\r
579 first valid hexadecimal digit. Then, the function stops at the first character that is\r
580 a not a valid hexadecimal character or NULL, whichever one comes first.\r
581\r
582 If String is NULL, then ASSERT().\r
583 If String is not aligned in a 16-bit boundary, then ASSERT().\r
584 If String has only pad spaces, then zero is returned.\r
585 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r
586 then zero is returned.\r
587 If the number represented by String overflows according to the range defined by\r
588 UINT64, then ASSERT().\r
589\r
590 If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
591 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,\r
592 then ASSERT().\r
593\r
17f695ed 594 @param String Pointer to a Null-terminated Unicode string.\r
ac644614 595\r
38bbd3d9 596 @retval Value translated from String.\r
ac644614 597\r
598**/\r
599UINT64\r
600EFIAPI\r
601StrHexToUint64 (\r
17f695ed 602 IN CONST CHAR16 *String\r
ac644614 603 );\r
604\r
605/**\r
606 Convert a nibble in the low 4 bits of a byte to a Unicode hexadecimal character.\r
607\r
608 This function converts a nibble in the low 4 bits of a byte to a Unicode hexadecimal \r
609 character For example, the nibble 0x01 and 0x0A will converted to L'1' and L'A' \r
610 respectively.\r
611\r
612 The upper nibble in the input byte will be masked off.\r
613\r
614 @param Nibble The nibble which is in the low 4 bits of the input byte.\r
615\r
616 @retval CHAR16 The Unicode hexadecimal character.\r
617 \r
618**/\r
619CHAR16\r
620EFIAPI\r
621NibbleToHexChar (\r
622 IN UINT8 Nibble\r
ed66e1bc 623 );\r
ac644614 624\r
625/** \r
626 Convert binary buffer to a Unicode String in a specified sequence. \r
627\r
1106ffe1 628 This function converts bytes in the memory block pointed by Buffer to a Unicode String Str. \r
ac644614 629 Each byte will be represented by two Unicode characters. For example, byte 0xA1 will \r
630 be converted into two Unicode character L'A' and L'1'. In the output String, the Unicode Character \r
631 for the Most Significant Nibble will be put before the Unicode Character for the Least Significant\r
632 Nibble. The output string for the buffer containing a single byte 0xA1 will be L"A1". \r
633 For a buffer with multiple bytes, the Unicode character produced by the first byte will be put into the \r
634 the last character in the output string. The one next to first byte will be put into the\r
635 character before the last character. This rules applies to the rest of the bytes. The Unicode\r
636 character by the last byte will be put into the first character in the output string. For example,\r
637 the input buffer for a 64-bits unsigned integrer 0x12345678abcdef1234 will be converted to\r
638 a Unicode string equal to L"12345678abcdef1234".\r
639\r
640 @param String On input, String is pointed to the buffer allocated for the convertion.\r
641 @param StringLen The Length of String buffer to hold the output String. The length must include the tailing '\0' character.\r
642 The StringLen required to convert a N bytes Buffer will be a least equal to or greater \r
643 than 2*N + 1.\r
644 @param Buffer The pointer to a input buffer.\r
645 @param BufferSizeInBytes Lenth in bytes of the input buffer.\r
646 \r
647\r
648 @retval EFI_SUCCESS The convertion is successfull. All bytes in Buffer has been convert to the corresponding\r
649 Unicode character and placed into the right place in String.\r
650 @retval EFI_BUFFER_TOO_SMALL StringSizeInBytes is smaller than 2 * N + 1the number of bytes required to\r
651 complete the convertion. \r
652**/\r
653RETURN_STATUS\r
654EFIAPI\r
655BufToHexString (\r
656 IN OUT CHAR16 *String,\r
657 IN OUT UINTN *StringLen,\r
658 IN CONST UINT8 *Buffer,\r
659 IN UINTN BufferSizeInBytes\r
ed66e1bc 660 );\r
ac644614 661\r
662\r
663/**\r
664 Convert a Unicode string consisting of hexadecimal characters to a output byte buffer.\r
665\r
666 This function converts a Unicode string consisting of characters in the range of Hexadecimal\r
667 character (L'0' to L'9', L'A' to L'F' and L'a' to L'f') to a output byte buffer. The function will stop\r
668 at the first non-hexadecimal character or the NULL character. The convertion process can be\r
669 simply viewed as the reverse operations defined by BufToHexString. Two Unicode characters will be \r
670 converted into one byte. The first Unicode character represents the Most Significant Nibble and the\r
671 second Unicode character represents the Least Significant Nibble in the output byte. \r
672 The first pair of Unicode characters represents the last byte in the output buffer. The second pair of Unicode \r
673 characters represent the the byte preceding the last byte. This rule applies to the rest pairs of bytes. \r
674 The last pair represent the first byte in the output buffer. \r
675\r
676 For example, a Unciode String L"12345678" will be converted into a buffer wil the following bytes \r
677 (first byte is the byte in the lowest memory address): "0x78, 0x56, 0x34, 0x12".\r
678\r
679 If String has N valid hexadecimal characters for conversion, the caller must make sure Buffer is at least \r
680 N/2 (if N is even) or (N+1)/2 (if N if odd) bytes. \r
681\r
682 @param Buffer The output buffer allocated by the caller.\r
683 @param BufferSizeInBytes On input, the size in bytes of Buffer. On output, it is updated to \r
684 contain the size of the Buffer which is actually used for the converstion.\r
685 For Unicode string with 2*N hexadecimal characters (not including the \r
686 tailing NULL character), N bytes of Buffer will be used for the output.\r
687 @param String The input hexadecimal string.\r
688 @param ConvertedStrLen The number of hexadecimal characters used to produce content in output\r
689 buffer Buffer.\r
690\r
691 @retval RETURN_BUFFER_TOO_SMALL The input BufferSizeInBytes is too small to hold the output. BufferSizeInBytes\r
692 will be updated to the size required for the converstion.\r
693 @retval RETURN_SUCCESS The convertion is successful or the first Unicode character from String\r
694 is hexadecimal. If ConvertedStrLen is not NULL, it is updated\r
695 to the number of hexadecimal character used for the converstion.\r
696**/\r
697RETURN_STATUS\r
698EFIAPI\r
699HexStringToBuf (\r
700 OUT UINT8 *Buffer, \r
701 IN OUT UINTN *BufferSizeInBytes,\r
702 IN CONST CHAR16 *String,\r
703 OUT UINTN *ConvertedStrLen OPTIONAL\r
ed66e1bc 704 );\r
ac644614 705\r
706\r
707/**\r
708 Test if a Unicode character is a hexadecimal digit. If true, the input\r
709 Unicode character is converted to a byte. \r
710\r
711 This function tests if a Unicode character is a hexadecimal digit. If true, the input\r
712 Unicode character is converted to a byte. For example, Unicode character\r
713 L'A' will be converted to 0x0A. \r
714\r
715 If Digit is NULL, then ASSERT.\r
716\r
1106ffe1 717 @param Digit The output hexadecimal digit.\r
718\r
719 @param Char The input Unicode character.\r
720\r
ac644614 721 @retval TRUE Char is in the range of Hexadecimal number. Digit is updated\r
722 to the byte value of the number.\r
723 @retval FALSE Char is not in the range of Hexadecimal number. Digit is keep\r
724 intact.\r
725 \r
726**/\r
727BOOLEAN\r
728EFIAPI\r
729IsHexDigit (\r
730 OUT UINT8 *Digit,\r
731 IN CHAR16 Char\r
ed66e1bc 732 );\r
ac644614 733\r
734/**\r
17f695ed 735 Convert a Null-terminated Unicode string to a Null-terminated\r
ac644614 736 ASCII string and returns the ASCII string.\r
737\r
738 This function converts the content of the Unicode string Source\r
739 to the ASCII string Destination by copying the lower 8 bits of\r
740 each Unicode character. It returns Destination.\r
741\r
742 If any Unicode characters in Source contain non-zero value in\r
743 the upper 8 bits, then ASSERT().\r
744\r
745 If Destination is NULL, then ASSERT().\r
746 If Source is NULL, then ASSERT().\r
747 If Source is not aligned on a 16-bit boundary, then ASSERT().\r
748 If Source and Destination overlap, then ASSERT().\r
749\r
750 If PcdMaximumUnicodeStringLength is not zero, and Source contains\r
751 more than PcdMaximumUnicodeStringLength Unicode characters not including\r
752 the Null-terminator, then ASSERT().\r
753\r
754 If PcdMaximumAsciiStringLength is not zero, and Source contains more\r
755 than PcdMaximumAsciiStringLength Unicode characters not including the\r
756 Null-terminator, then ASSERT().\r
757\r
758 @param Source Pointer to a Null-terminated Unicode string.\r
759 @param Destination Pointer to a Null-terminated ASCII string.\r
760\r
761 @return Destination\r
762\r
763**/\r
764CHAR8 *\r
765EFIAPI\r
766UnicodeStrToAsciiStr (\r
17f695ed 767 IN CONST CHAR16 *Source,\r
768 OUT CHAR8 *Destination\r
ac644614 769 );\r
770\r
771\r
772/**\r
773 Copies one Null-terminated ASCII string to another Null-terminated ASCII\r
774 string and returns the new ASCII string.\r
775\r
776 This function copies the contents of the ASCII string Source to the ASCII\r
777 string Destination, and returns Destination. If Source and Destination\r
778 overlap, then the results are undefined.\r
779\r
780 If Destination is NULL, then ASSERT().\r
781 If Source is NULL, then ASSERT().\r
782 If Source and Destination overlap, then ASSERT().\r
783 If PcdMaximumAsciiStringLength is not zero and Source contains more than\r
784 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
785 then ASSERT().\r
786\r
787 @param Destination Pointer to a Null-terminated ASCII string.\r
788 @param Source Pointer to a Null-terminated ASCII string.\r
789\r
790 @return Destination\r
791\r
792**/\r
793CHAR8 *\r
794EFIAPI\r
795AsciiStrCpy (\r
796 OUT CHAR8 *Destination,\r
797 IN CONST CHAR8 *Source\r
798 );\r
799\r
800\r
801/**\r
17f695ed 802 Copies up to a specified length one Null-terminated ASCII string to another \r
803 Null-terminated ASCII string and returns the new ASCII string.\r
ac644614 804\r
805 This function copies the contents of the ASCII string Source to the ASCII\r
806 string Destination, and returns Destination. At most, Length ASCII characters\r
807 are copied from Source to Destination. If Length is 0, then Destination is\r
808 returned unmodified. If Length is greater that the number of ASCII characters\r
809 in Source, then Destination is padded with Null ASCII characters. If Source\r
810 and Destination overlap, then the results are undefined.\r
811\r
812 If Destination is NULL, then ASSERT().\r
813 If Source is NULL, then ASSERT().\r
814 If Source and Destination overlap, then ASSERT().\r
815 If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r
816 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
817 then ASSERT().\r
818\r
819 @param Destination Pointer to a Null-terminated ASCII string.\r
820 @param Source Pointer to a Null-terminated ASCII string.\r
821 @param Length Maximum number of ASCII characters to copy.\r
822\r
823 @return Destination\r
824\r
825**/\r
826CHAR8 *\r
827EFIAPI\r
828AsciiStrnCpy (\r
829 OUT CHAR8 *Destination,\r
830 IN CONST CHAR8 *Source,\r
831 IN UINTN Length\r
832 );\r
833\r
834\r
835/**\r
836 Returns the length of a Null-terminated ASCII string.\r
837\r
838 This function returns the number of ASCII characters in the Null-terminated\r
839 ASCII string specified by String.\r
840\r
841 If Length > 0 and Destination is NULL, then ASSERT().\r
842 If Length > 0 and Source is NULL, then ASSERT().\r
843 If PcdMaximumAsciiStringLength is not zero and String contains more than\r
844 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
845 then ASSERT().\r
846\r
847 @param String Pointer to a Null-terminated ASCII string.\r
848\r
849 @return The length of String.\r
850\r
851**/\r
852UINTN\r
853EFIAPI\r
854AsciiStrLen (\r
855 IN CONST CHAR8 *String\r
856 );\r
857\r
858\r
859/**\r
860 Returns the size of a Null-terminated ASCII string in bytes, including the\r
861 Null terminator.\r
862\r
863 This function returns the size, in bytes, of the Null-terminated ASCII string\r
864 specified by String.\r
865\r
866 If String is NULL, then ASSERT().\r
867 If PcdMaximumAsciiStringLength is not zero and String contains more than\r
868 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
869 then ASSERT().\r
870\r
871 @param String Pointer to a Null-terminated ASCII string.\r
872\r
873 @return The size of String.\r
874\r
875**/\r
876UINTN\r
877EFIAPI\r
878AsciiStrSize (\r
879 IN CONST CHAR8 *String\r
880 );\r
881\r
882\r
883/**\r
884 Compares two Null-terminated ASCII strings, and returns the difference\r
885 between the first mismatched ASCII characters.\r
886\r
887 This function compares the Null-terminated ASCII string FirstString to the\r
888 Null-terminated ASCII string SecondString. If FirstString is identical to\r
889 SecondString, then 0 is returned. Otherwise, the value returned is the first\r
890 mismatched ASCII character in SecondString subtracted from the first\r
891 mismatched ASCII character in FirstString.\r
892\r
893 If FirstString is NULL, then ASSERT().\r
894 If SecondString is NULL, then ASSERT().\r
895 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r
896 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
897 then ASSERT().\r
898 If PcdMaximumAsciiStringLength is not zero and SecondString contains more\r
899 than PcdMaximumAsciiStringLength ASCII characters not including the\r
900 Null-terminator, then ASSERT().\r
901\r
902 @param FirstString Pointer to a Null-terminated ASCII string.\r
903 @param SecondString Pointer to a Null-terminated ASCII string.\r
904\r
17f695ed 905 @retval ==0 FirstString is identical to SecondString.\r
906 @retval !=0 FirstString is not identical to SecondString.\r
ac644614 907\r
908**/\r
909INTN\r
910EFIAPI\r
911AsciiStrCmp (\r
912 IN CONST CHAR8 *FirstString,\r
913 IN CONST CHAR8 *SecondString\r
914 );\r
915\r
916\r
917/**\r
918 Performs a case insensitive comparison of two Null-terminated ASCII strings,\r
919 and returns the difference between the first mismatched ASCII characters.\r
920\r
921 This function performs a case insensitive comparison of the Null-terminated\r
922 ASCII string FirstString to the Null-terminated ASCII string SecondString. If\r
923 FirstString is identical to SecondString, then 0 is returned. Otherwise, the\r
924 value returned is the first mismatched lower case ASCII character in\r
925 SecondString subtracted from the first mismatched lower case ASCII character\r
926 in FirstString.\r
927\r
928 If FirstString is NULL, then ASSERT().\r
929 If SecondString is NULL, then ASSERT().\r
930 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r
931 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
932 then ASSERT().\r
933 If PcdMaximumAsciiStringLength is not zero and SecondString contains more\r
934 than PcdMaximumAsciiStringLength ASCII characters not including the\r
935 Null-terminator, then ASSERT().\r
936\r
937 @param FirstString Pointer to a Null-terminated ASCII string.\r
938 @param SecondString Pointer to a Null-terminated ASCII string.\r
939\r
17f695ed 940 @retval ==0 FirstString is identical to SecondString using case insensitive\r
1106ffe1 941 comparisons.\r
17f695ed 942 @retval !=0 FirstString is not identical to SecondString using case\r
1106ffe1 943 insensitive comparisons.\r
ac644614 944\r
945**/\r
946INTN\r
947EFIAPI\r
948AsciiStriCmp (\r
949 IN CONST CHAR8 *FirstString,\r
950 IN CONST CHAR8 *SecondString\r
951 );\r
952\r
953\r
954/**\r
955 Compares two Null-terminated ASCII strings with maximum lengths, and returns\r
956 the difference between the first mismatched ASCII characters.\r
957\r
958 This function compares the Null-terminated ASCII string FirstString to the\r
959 Null-terminated ASCII string SecondString. At most, Length ASCII characters\r
960 will be compared. If Length is 0, then 0 is returned. If FirstString is\r
961 identical to SecondString, then 0 is returned. Otherwise, the value returned\r
962 is the first mismatched ASCII character in SecondString subtracted from the\r
963 first mismatched ASCII character in FirstString.\r
964\r
965 If Length > 0 and FirstString is NULL, then ASSERT().\r
966 If Length > 0 and SecondString is NULL, then ASSERT().\r
967 If PcdMaximumAsciiStringLength is not zero and FirstString contains more than\r
968 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
969 then ASSERT().\r
970 If PcdMaximumAsciiStringLength is not zero and SecondString contains more than\r
971 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
972 then ASSERT().\r
973\r
974 @param FirstString Pointer to a Null-terminated ASCII string.\r
975 @param SecondString Pointer to a Null-terminated ASCII string.\r
976 @param Length Maximum number of ASCII characters for compare.\r
977 \r
17f695ed 978 @retval ==0 FirstString is identical to SecondString.\r
979 @retval !=0 FirstString is not identical to SecondString.\r
ac644614 980\r
981**/\r
982INTN\r
983EFIAPI\r
984AsciiStrnCmp (\r
985 IN CONST CHAR8 *FirstString,\r
986 IN CONST CHAR8 *SecondString,\r
987 IN UINTN Length\r
988 );\r
989\r
990\r
991/**\r
992 Concatenates one Null-terminated ASCII string to another Null-terminated\r
993 ASCII string, and returns the concatenated ASCII string.\r
994\r
995 This function concatenates two Null-terminated ASCII strings. The contents of\r
996 Null-terminated ASCII string Source are concatenated to the end of Null-\r
997 terminated ASCII string Destination. The Null-terminated concatenated ASCII\r
998 String is returned.\r
999\r
1000 If Destination is NULL, then ASSERT().\r
1001 If Source is NULL, then ASSERT().\r
1002 If PcdMaximumAsciiStringLength is not zero and Destination contains more than\r
1003 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
1004 then ASSERT().\r
1005 If PcdMaximumAsciiStringLength is not zero and Source contains more than\r
1006 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
1007 then ASSERT().\r
1008 If PcdMaximumAsciiStringLength is not zero and concatenating Destination and\r
1009 Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
1010 ASCII characters, then ASSERT().\r
1011\r
1012 @param Destination Pointer to a Null-terminated ASCII string.\r
1013 @param Source Pointer to a Null-terminated ASCII string.\r
1014\r
1015 @return Destination\r
1016\r
1017**/\r
1018CHAR8 *\r
1019EFIAPI\r
1020AsciiStrCat (\r
1021 IN OUT CHAR8 *Destination,\r
1022 IN CONST CHAR8 *Source\r
1023 );\r
1024\r
1025\r
1026/**\r
17f695ed 1027 Concatenates up to a specified length one Null-terminated ASCII string to \r
1028 the end of another Null-terminated ASCII string, and returns the \r
1029 concatenated ASCII string.\r
ac644614 1030\r
1031 This function concatenates two Null-terminated ASCII strings. The contents\r
1032 of Null-terminated ASCII string Source are concatenated to the end of Null-\r
1033 terminated ASCII string Destination, and Destination is returned. At most,\r
1034 Length ASCII characters are concatenated from Source to the end of\r
1035 Destination, and Destination is always Null-terminated. If Length is 0, then\r
1036 Destination is returned unmodified. If Source and Destination overlap, then\r
1037 the results are undefined.\r
1038\r
1039 If Length > 0 and Destination is NULL, then ASSERT().\r
1040 If Length > 0 and Source is NULL, then ASSERT().\r
1041 If Source and Destination overlap, then ASSERT().\r
1042 If PcdMaximumAsciiStringLength is not zero, and Destination contains more than\r
1043 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
1044 then ASSERT().\r
1045 If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r
1046 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
1047 then ASSERT().\r
1048 If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and\r
1049 Source results in a ASCII string with more than PcdMaximumAsciiStringLength\r
1050 ASCII characters not including the Null-terminator, then ASSERT().\r
1051\r
1052 @param Destination Pointer to a Null-terminated ASCII string.\r
1053 @param Source Pointer to a Null-terminated ASCII string.\r
1054 @param Length Maximum number of ASCII characters to concatenate from\r
1055 Source.\r
1056\r
1057 @return Destination\r
1058\r
1059**/\r
1060CHAR8 *\r
1061EFIAPI\r
1062AsciiStrnCat (\r
1063 IN OUT CHAR8 *Destination,\r
1064 IN CONST CHAR8 *Source,\r
1065 IN UINTN Length\r
1066 );\r
1067\r
1068\r
1069/**\r
1070 Returns the first occurance of a Null-terminated ASCII sub-string\r
1071 in a Null-terminated ASCII string.\r
1072\r
1073 This function scans the contents of the ASCII string specified by String\r
1074 and returns the first occurrence of SearchString. If SearchString is not\r
1075 found in String, then NULL is returned. If the length of SearchString is zero,\r
1076 then String is returned.\r
1077\r
1078 If String is NULL, then ASSERT().\r
1079 If SearchString is NULL, then ASSERT().\r
1080\r
1081 If PcdMaximumAsciiStringLength is not zero, and SearchString or\r
1082 String contains more than PcdMaximumAsciiStringLength Unicode characters\r
1083 not including the Null-terminator, then ASSERT().\r
1084\r
1106ffe1 1085 @param String Pointer to a Null-terminated ASCII string.\r
1086 @param SearchString Pointer to a Null-terminated ASCII string to search for.\r
ac644614 1087\r
1088 @retval NULL If the SearchString does not appear in String.\r
17f695ed 1089 @retval others If there is a match return the first occurrence of SearchingString.\r
1090 If the lenth of SearchString is zero,return String.\r
ac644614 1091\r
1092**/\r
1093CHAR8 *\r
1094EFIAPI\r
1095AsciiStrStr (\r
17f695ed 1096 IN CONST CHAR8 *String,\r
1097 IN CONST CHAR8 *SearchString\r
ac644614 1098 );\r
1099\r
1100\r
1101/**\r
1102 Convert a Null-terminated ASCII decimal string to a value of type\r
1103 UINTN.\r
1104\r
1105 This function returns a value of type UINTN by interpreting the contents\r
1106 of the ASCII string String as a decimal number. The format of the input\r
1107 ASCII string String is:\r
1108\r
1109 [spaces] [decimal digits].\r
1110\r
1111 The valid decimal digit character is in the range [0-9]. The function will\r
1112 ignore the pad space, which includes spaces or tab characters, before the digits.\r
1113 The running zero in the beginning of [decimal digits] will be ignored. Then, the\r
1114 function stops at the first character that is a not a valid decimal character or\r
1115 Null-terminator, whichever on comes first.\r
1116\r
1117 If String has only pad spaces, then 0 is returned.\r
1118 If String has no pad spaces or valid decimal digits, then 0 is returned.\r
1119 If the number represented by String overflows according to the range defined by\r
1120 UINTN, then ASSERT().\r
1121 If String is NULL, then ASSERT().\r
1122 If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
1123 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
1124 then ASSERT().\r
1125\r
17f695ed 1126 @param String Pointer to a Null-terminated ASCII string.\r
ac644614 1127\r
38bbd3d9 1128 @retval Value translated from String.\r
ac644614 1129\r
1130**/\r
1131UINTN\r
1132EFIAPI\r
1133AsciiStrDecimalToUintn (\r
1134 IN CONST CHAR8 *String\r
1135 );\r
1136\r
1137\r
1138/**\r
1139 Convert a Null-terminated ASCII decimal string to a value of type\r
1140 UINT64.\r
1141\r
1142 This function returns a value of type UINT64 by interpreting the contents\r
1143 of the ASCII string String as a decimal number. The format of the input\r
1144 ASCII string String is:\r
1145\r
1146 [spaces] [decimal digits].\r
1147\r
1148 The valid decimal digit character is in the range [0-9]. The function will\r
1149 ignore the pad space, which includes spaces or tab characters, before the digits.\r
1150 The running zero in the beginning of [decimal digits] will be ignored. Then, the\r
1151 function stops at the first character that is a not a valid decimal character or\r
1152 Null-terminator, whichever on comes first.\r
1153\r
1154 If String has only pad spaces, then 0 is returned.\r
1155 If String has no pad spaces or valid decimal digits, then 0 is returned.\r
1156 If the number represented by String overflows according to the range defined by\r
1157 UINT64, then ASSERT().\r
1158 If String is NULL, then ASSERT().\r
1159 If PcdMaximumAsciiStringLength is not zero, and String contains more than\r
1160 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
1161 then ASSERT().\r
1162\r
17f695ed 1163 @param String Pointer to a Null-terminated ASCII string.\r
ac644614 1164\r
38bbd3d9 1165 @retval Value translated from String.\r
ac644614 1166\r
1167**/\r
1168UINT64\r
1169EFIAPI\r
1170AsciiStrDecimalToUint64 (\r
17f695ed 1171 IN CONST CHAR8 *String\r
ac644614 1172 );\r
1173\r
1174\r
1175/**\r
1176 Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.\r
1177\r
1178 This function returns a value of type UINTN by interpreting the contents of\r
1179 the ASCII string String as a hexadecimal number. The format of the input ASCII\r
1180 string String is:\r
1181\r
1182 [spaces][zeros][x][hexadecimal digits].\r
1183\r
1184 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
1185 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"\r
1186 appears in the input string, it must be prefixed with at least one 0. The function\r
1187 will ignore the pad space, which includes spaces or tab characters, before [zeros],\r
1188 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]\r
1189 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal\r
1190 digit. Then, the function stops at the first character that is a not a valid\r
1191 hexadecimal character or Null-terminator, whichever on comes first.\r
1192\r
1193 If String has only pad spaces, then 0 is returned.\r
1194 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then\r
1195 0 is returned.\r
1196\r
1197 If the number represented by String overflows according to the range defined by UINTN,\r
1198 then ASSERT().\r
1199 If String is NULL, then ASSERT().\r
1200 If PcdMaximumAsciiStringLength is not zero,\r
1201 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
1202 the Null-terminator, then ASSERT().\r
1203\r
17f695ed 1204 @param String Pointer to a Null-terminated ASCII string.\r
ac644614 1205\r
38bbd3d9 1206 @retval Value translated from String.\r
ac644614 1207\r
1208**/\r
1209UINTN\r
1210EFIAPI\r
1211AsciiStrHexToUintn (\r
17f695ed 1212 IN CONST CHAR8 *String\r
ac644614 1213 );\r
1214\r
1215\r
1216/**\r
1217 Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.\r
1218\r
1219 This function returns a value of type UINT64 by interpreting the contents of\r
1220 the ASCII string String as a hexadecimal number. The format of the input ASCII\r
1221 string String is:\r
1222\r
1223 [spaces][zeros][x][hexadecimal digits].\r
1224\r
1225 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
1226 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"\r
1227 appears in the input string, it must be prefixed with at least one 0. The function\r
1228 will ignore the pad space, which includes spaces or tab characters, before [zeros],\r
1229 [x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]\r
1230 will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal\r
1231 digit. Then, the function stops at the first character that is a not a valid\r
1232 hexadecimal character or Null-terminator, whichever on comes first.\r
1233\r
1234 If String has only pad spaces, then 0 is returned.\r
1235 If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then\r
1236 0 is returned.\r
1237\r
1238 If the number represented by String overflows according to the range defined by UINT64,\r
1239 then ASSERT().\r
1240 If String is NULL, then ASSERT().\r
1241 If PcdMaximumAsciiStringLength is not zero,\r
1242 and String contains more than PcdMaximumAsciiStringLength ASCII characters not including\r
1243 the Null-terminator, then ASSERT().\r
1244\r
17f695ed 1245 @param String Pointer to a Null-terminated ASCII string.\r
ac644614 1246\r
38bbd3d9 1247 @retval Value translated from String.\r
ac644614 1248\r
1249**/\r
1250UINT64\r
1251EFIAPI\r
1252AsciiStrHexToUint64 (\r
17f695ed 1253 IN CONST CHAR8 *String\r
ac644614 1254 );\r
1255\r
1256\r
1257/**\r
1258 Convert one Null-terminated ASCII string to a Null-terminated\r
1259 Unicode string and returns the Unicode string.\r
1260\r
1261 This function converts the contents of the ASCII string Source to the Unicode\r
1262 string Destination, and returns Destination. The function terminates the\r
1263 Unicode string Destination by appending a Null-terminator character at the end.\r
1264 The caller is responsible to make sure Destination points to a buffer with size\r
1265 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.\r
1266\r
1267 If Destination is NULL, then ASSERT().\r
1268 If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
1269 If Source is NULL, then ASSERT().\r
1270 If Source and Destination overlap, then ASSERT().\r
1271 If PcdMaximumAsciiStringLength is not zero, and Source contains more than\r
1272 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,\r
1273 then ASSERT().\r
1274 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
1275 PcdMaximumUnicodeStringLength ASCII characters not including the\r
1276 Null-terminator, then ASSERT().\r
1277\r
1278 @param Source Pointer to a Null-terminated ASCII string.\r
1279 @param Destination Pointer to a Null-terminated Unicode string.\r
1280\r
1281 @return Destination\r
1282\r
1283**/\r
1284CHAR16 *\r
1285EFIAPI\r
1286AsciiStrToUnicodeStr (\r
17f695ed 1287 IN CONST CHAR8 *Source,\r
1288 OUT CHAR16 *Destination\r
ac644614 1289 );\r
1290\r
1291\r
1292/**\r
1293 Converts an 8-bit value to an 8-bit BCD value.\r
1294\r
1295 Converts the 8-bit value specified by Value to BCD. The BCD value is\r
1296 returned.\r
1297\r
1298 If Value >= 100, then ASSERT().\r
1299\r
1300 @param Value The 8-bit value to convert to BCD. Range 0..99.\r
1301\r
1302 @return The BCD value\r
1303\r
1304**/\r
1305UINT8\r
1306EFIAPI\r
1307DecimalToBcd8 (\r
1308 IN UINT8 Value\r
1309 );\r
1310\r
1311\r
1312/**\r
1313 Converts an 8-bit BCD value to an 8-bit value.\r
1314\r
1315 Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit\r
1316 value is returned.\r
1317\r
1318 If Value >= 0xA0, then ASSERT().\r
1319 If (Value & 0x0F) >= 0x0A, then ASSERT().\r
1320\r
1321 @param Value The 8-bit BCD value to convert to an 8-bit value.\r
1322\r
1323 @return The 8-bit value is returned.\r
1324\r
1325**/\r
1326UINT8\r
1327EFIAPI\r
1328BcdToDecimal8 (\r
1329 IN UINT8 Value\r
1330 );\r
1331\r
1332\r
1333//\r
1334// Linked List Functions and Macros\r
1335//\r
1336\r
1337/**\r
1338 Initializes the head node of a doubly linked list that is declared as a\r
1339 global variable in a module.\r
1340\r
1341 Initializes the forward and backward links of a new linked list. After\r
1342 initializing a linked list with this macro, the other linked list functions\r
1343 may be used to add and remove nodes from the linked list. This macro results\r
1344 in smaller executables by initializing the linked list in the data section,\r
1345 instead if calling the InitializeListHead() function to perform the\r
1346 equivalent operation.\r
1347\r
1348 @param ListHead The head note of a list to initiailize.\r
1349\r
1350**/\r
17f695ed 1351#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&(ListHead), &(ListHead)}\r
ac644614 1352\r
1353\r
1354/**\r
1355 Initializes the head node of a doubly linked list, and returns the pointer to\r
1356 the head node of the doubly linked list.\r
1357\r
1358 Initializes the forward and backward links of a new linked list. After\r
1359 initializing a linked list with this function, the other linked list\r
1360 functions may be used to add and remove nodes from the linked list. It is up\r
1361 to the caller of this function to allocate the memory for ListHead.\r
1362\r
1363 If ListHead is NULL, then ASSERT().\r
1364\r
1365 @param ListHead A pointer to the head node of a new doubly linked list.\r
1366\r
1367 @return ListHead\r
1368\r
1369**/\r
1370LIST_ENTRY *\r
1371EFIAPI\r
1372InitializeListHead (\r
aa0583c7 1373 IN OUT LIST_ENTRY *ListHead\r
ac644614 1374 );\r
1375\r
1376\r
1377/**\r
1378 Adds a node to the beginning of a doubly linked list, and returns the pointer\r
1379 to the head node of the doubly linked list.\r
1380\r
1381 Adds the node Entry at the beginning of the doubly linked list denoted by\r
1382 ListHead, and returns ListHead.\r
1383\r
1384 If ListHead is NULL, then ASSERT().\r
1385 If Entry is NULL, then ASSERT().\r
17f695ed 1386 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
1387 InitializeListHead(), then ASSERT().\r
ac644614 1388 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
1389 of nodes in ListHead, including the ListHead node, is greater than or\r
1390 equal to PcdMaximumLinkedListLength, then ASSERT().\r
1391\r
1392 @param ListHead A pointer to the head node of a doubly linked list.\r
1393 @param Entry A pointer to a node that is to be inserted at the beginning\r
1394 of a doubly linked list.\r
1395\r
1396 @return ListHead\r
1397\r
1398**/\r
1399LIST_ENTRY *\r
1400EFIAPI\r
1401InsertHeadList (\r
aa0583c7 1402 IN OUT LIST_ENTRY *ListHead,\r
1403 IN OUT LIST_ENTRY *Entry\r
ac644614 1404 );\r
1405\r
1406\r
1407/**\r
1408 Adds a node to the end of a doubly linked list, and returns the pointer to\r
1409 the head node of the doubly linked list.\r
1410\r
1411 Adds the node Entry to the end of the doubly linked list denoted by ListHead,\r
1412 and returns ListHead.\r
1413\r
1414 If ListHead is NULL, then ASSERT().\r
1415 If Entry is NULL, then ASSERT().\r
17f695ed 1416 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
1417 InitializeListHead(), then ASSERT().\r
ac644614 1418 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
1419 of nodes in ListHead, including the ListHead node, is greater than or\r
1420 equal to PcdMaximumLinkedListLength, then ASSERT().\r
1421\r
1422 @param ListHead A pointer to the head node of a doubly linked list.\r
1423 @param Entry A pointer to a node that is to be added at the end of the\r
1424 doubly linked list.\r
1425\r
1426 @return ListHead\r
1427\r
1428**/\r
1429LIST_ENTRY *\r
1430EFIAPI\r
1431InsertTailList (\r
aa0583c7 1432 IN OUT LIST_ENTRY *ListHead,\r
1433 IN OUT LIST_ENTRY *Entry\r
ac644614 1434 );\r
1435\r
1436\r
1437/**\r
1438 Retrieves the first node of a doubly linked list.\r
1439\r
17f695ed 1440 Returns the first node of a doubly linked list. List must have been \r
1441 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
1442 If List is empty, then List is returned.\r
ac644614 1443\r
1444 If List is NULL, then ASSERT().\r
17f695ed 1445 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
1446 InitializeListHead(), then ASSERT().\r
ac644614 1447 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
1448 in List, including the List node, is greater than or equal to\r
1449 PcdMaximumLinkedListLength, then ASSERT().\r
1450\r
1451 @param List A pointer to the head node of a doubly linked list.\r
1452\r
1453 @return The first node of a doubly linked list.\r
1454 @retval NULL The list is empty.\r
1455\r
1456**/\r
1457LIST_ENTRY *\r
1458EFIAPI\r
1459GetFirstNode (\r
1460 IN CONST LIST_ENTRY *List\r
1461 );\r
1462\r
1463\r
1464/**\r
1465 Retrieves the next node of a doubly linked list.\r
1466\r
17f695ed 1467 Returns the node of a doubly linked list that follows Node. \r
1468 List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()\r
1469 or InitializeListHead(). If List is empty, then List is returned.\r
ac644614 1470\r
1471 If List is NULL, then ASSERT().\r
1472 If Node is NULL, then ASSERT().\r
17f695ed 1473 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
1474 InitializeListHead(), then ASSERT().\r
ac644614 1475 If PcdMaximumLinkedListLenth is not zero, and List contains more than\r
1476 PcdMaximumLinkedListLenth nodes, then ASSERT().\r
1477 If Node is not a node in List, then ASSERT().\r
1478\r
1479 @param List A pointer to the head node of a doubly linked list.\r
1480 @param Node A pointer to a node in the doubly linked list.\r
1481\r
1482 @return Pointer to the next node if one exists. Otherwise a null value which\r
1483 is actually List is returned.\r
1484\r
1485**/\r
1486LIST_ENTRY *\r
1487EFIAPI\r
1488GetNextNode (\r
1489 IN CONST LIST_ENTRY *List,\r
1490 IN CONST LIST_ENTRY *Node\r
1491 );\r
1492\r
1493\r
1494/**\r
1495 Checks to see if a doubly linked list is empty or not.\r
1496\r
1497 Checks to see if the doubly linked list is empty. If the linked list contains\r
1498 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.\r
1499\r
1500 If ListHead is NULL, then ASSERT().\r
17f695ed 1501 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or \r
1502 InitializeListHead(), then ASSERT().\r
ac644614 1503 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
1504 in List, including the List node, is greater than or equal to\r
1505 PcdMaximumLinkedListLength, then ASSERT().\r
1506\r
1507 @param ListHead A pointer to the head node of a doubly linked list.\r
1508\r
1509 @retval TRUE The linked list is empty.\r
1510 @retval FALSE The linked list is not empty.\r
1511\r
1512**/\r
1513BOOLEAN\r
1514EFIAPI\r
1515IsListEmpty (\r
1516 IN CONST LIST_ENTRY *ListHead\r
1517 );\r
1518\r
1519\r
1520/**\r
aa0583c7 1521 Determines if a node in a doubly linked list is the head node of a the same\r
1522 doubly linked list. This function is typically used to terminate a loop that\r
1523 traverses all the nodes in a doubly linked list starting with the head node.\r
ac644614 1524\r
aa0583c7 1525 Returns TRUE if Node is equal to List. Returns FALSE if Node is one of the\r
1526 nodes in the doubly linked list specified by List. List must have been\r
17f695ed 1527 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
ac644614 1528\r
1529 If List is NULL, then ASSERT().\r
1530 If Node is NULL, then ASSERT().\r
17f695ed 1531 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(), \r
1532 then ASSERT().\r
ac644614 1533 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
1534 in List, including the List node, is greater than or equal to\r
1535 PcdMaximumLinkedListLength, then ASSERT().\r
1536 If Node is not a node in List and Node is not equal to List, then ASSERT().\r
1537\r
1538 @param List A pointer to the head node of a doubly linked list.\r
1539 @param Node A pointer to a node in the doubly linked list.\r
1540\r
1541 @retval TRUE Node is one of the nodes in the doubly linked list.\r
1542 @retval FALSE Node is not one of the nodes in the doubly linked list.\r
1543\r
1544**/\r
1545BOOLEAN\r
1546EFIAPI\r
1547IsNull (\r
1548 IN CONST LIST_ENTRY *List,\r
1549 IN CONST LIST_ENTRY *Node\r
1550 );\r
1551\r
1552\r
1553/**\r
1554 Determines if a node the last node in a doubly linked list.\r
1555\r
1556 Returns TRUE if Node is the last node in the doubly linked list specified by\r
1557 List. Otherwise, FALSE is returned. List must have been initialized with\r
17f695ed 1558 INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
ac644614 1559\r
1560 If List is NULL, then ASSERT().\r
1561 If Node is NULL, then ASSERT().\r
17f695ed 1562 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
1563 InitializeListHead(), then ASSERT().\r
ac644614 1564 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
1565 in List, including the List node, is greater than or equal to\r
1566 PcdMaximumLinkedListLength, then ASSERT().\r
1567 If Node is not a node in List, then ASSERT().\r
1568\r
1569 @param List A pointer to the head node of a doubly linked list.\r
1570 @param Node A pointer to a node in the doubly linked list.\r
1571\r
1572 @retval TRUE Node is the last node in the linked list.\r
1573 @retval FALSE Node is not the last node in the linked list.\r
1574\r
1575**/\r
1576BOOLEAN\r
1577EFIAPI\r
1578IsNodeAtEnd (\r
1579 IN CONST LIST_ENTRY *List,\r
1580 IN CONST LIST_ENTRY *Node\r
1581 );\r
1582\r
1583\r
1584/**\r
1585 Swaps the location of two nodes in a doubly linked list, and returns the\r
1586 first node after the swap.\r
1587\r
1588 If FirstEntry is identical to SecondEntry, then SecondEntry is returned.\r
1589 Otherwise, the location of the FirstEntry node is swapped with the location\r
1590 of the SecondEntry node in a doubly linked list. SecondEntry must be in the\r
1591 same double linked list as FirstEntry and that double linked list must have\r
17f695ed 1592 been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(). \r
1593 SecondEntry is returned after the nodes are swapped.\r
ac644614 1594\r
1595 If FirstEntry is NULL, then ASSERT().\r
1596 If SecondEntry is NULL, then ASSERT().\r
1597 If SecondEntry and FirstEntry are not in the same linked list, then ASSERT().\r
1598 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r
1599 linked list containing the FirstEntry and SecondEntry nodes, including\r
1600 the FirstEntry and SecondEntry nodes, is greater than or equal to\r
1601 PcdMaximumLinkedListLength, then ASSERT().\r
1602\r
1603 @param FirstEntry A pointer to a node in a linked list.\r
1604 @param SecondEntry A pointer to another node in the same linked list.\r
38bbd3d9 1605 \r
1606 @return SecondEntry\r
ac644614 1607\r
1608**/\r
1609LIST_ENTRY *\r
1610EFIAPI\r
1611SwapListEntries (\r
aa0583c7 1612 IN OUT LIST_ENTRY *FirstEntry,\r
1613 IN OUT LIST_ENTRY *SecondEntry\r
ac644614 1614 );\r
1615\r
1616\r
1617/**\r
1618 Removes a node from a doubly linked list, and returns the node that follows\r
1619 the removed node.\r
1620\r
1621 Removes the node Entry from a doubly linked list. It is up to the caller of\r
1622 this function to release the memory used by this node if that is required. On\r
1623 exit, the node following Entry in the doubly linked list is returned. If\r
1624 Entry is the only node in the linked list, then the head node of the linked\r
1625 list is returned.\r
1626\r
1627 If Entry is NULL, then ASSERT().\r
1628 If Entry is the head node of an empty list, then ASSERT().\r
1629 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r
1630 linked list containing Entry, including the Entry node, is greater than\r
1631 or equal to PcdMaximumLinkedListLength, then ASSERT().\r
1632\r
1633 @param Entry A pointer to a node in a linked list\r
1634\r
1635 @return Entry\r
1636\r
1637**/\r
1638LIST_ENTRY *\r
1639EFIAPI\r
1640RemoveEntryList (\r
1641 IN CONST LIST_ENTRY *Entry\r
1642 );\r
1643\r
1644//\r
1645// Math Services\r
1646//\r
1647\r
1648/**\r
1649 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled\r
1650 with zeros. The shifted value is returned.\r
1651\r
1652 This function shifts the 64-bit value Operand to the left by Count bits. The\r
1653 low Count bits are set to zero. The shifted value is returned.\r
1654\r
1655 If Count is greater than 63, then ASSERT().\r
1656\r
1657 @param Operand The 64-bit operand to shift left.\r
1658 @param Count The number of bits to shift left.\r
1659\r
1660 @return Operand << Count\r
1661\r
1662**/\r
1663UINT64\r
1664EFIAPI\r
1665LShiftU64 (\r
1666 IN UINT64 Operand,\r
1667 IN UINTN Count\r
1668 );\r
1669\r
1670\r
1671/**\r
1672 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are\r
1673 filled with zeros. The shifted value is returned.\r
1674\r
1675 This function shifts the 64-bit value Operand to the right by Count bits. The\r
1676 high Count bits are set to zero. The shifted value is returned.\r
1677\r
1678 If Count is greater than 63, then ASSERT().\r
1679\r
1680 @param Operand The 64-bit operand to shift right.\r
1681 @param Count The number of bits to shift right.\r
1682\r
1683 @return Operand >> Count\r
1684\r
1685**/\r
1686UINT64\r
1687EFIAPI\r
1688RShiftU64 (\r
1689 IN UINT64 Operand,\r
1690 IN UINTN Count\r
1691 );\r
1692\r
1693\r
1694/**\r
1695 Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled\r
1696 with original integer's bit 63. The shifted value is returned.\r
1697\r
1698 This function shifts the 64-bit value Operand to the right by Count bits. The\r
1699 high Count bits are set to bit 63 of Operand. The shifted value is returned.\r
1700\r
1701 If Count is greater than 63, then ASSERT().\r
1702\r
1703 @param Operand The 64-bit operand to shift right.\r
1704 @param Count The number of bits to shift right.\r
1705\r
1706 @return Operand >> Count\r
1707\r
1708**/\r
1709UINT64\r
1710EFIAPI\r
1711ARShiftU64 (\r
1712 IN UINT64 Operand,\r
1713 IN UINTN Count\r
1714 );\r
1715\r
1716\r
1717/**\r
1718 Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits\r
1719 with the high bits that were rotated.\r
1720\r
1721 This function rotates the 32-bit value Operand to the left by Count bits. The\r
1722 low Count bits are fill with the high Count bits of Operand. The rotated\r
1723 value is returned.\r
1724\r
1725 If Count is greater than 31, then ASSERT().\r
1726\r
1727 @param Operand The 32-bit operand to rotate left.\r
1728 @param Count The number of bits to rotate left.\r
1729\r
17f695ed 1730 @return Operand << Count\r
ac644614 1731\r
1732**/\r
1733UINT32\r
1734EFIAPI\r
1735LRotU32 (\r
1736 IN UINT32 Operand,\r
1737 IN UINTN Count\r
1738 );\r
1739\r
1740\r
1741/**\r
1742 Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits\r
1743 with the low bits that were rotated.\r
1744\r
1745 This function rotates the 32-bit value Operand to the right by Count bits.\r
1746 The high Count bits are fill with the low Count bits of Operand. The rotated\r
1747 value is returned.\r
1748\r
1749 If Count is greater than 31, then ASSERT().\r
1750\r
1751 @param Operand The 32-bit operand to rotate right.\r
1752 @param Count The number of bits to rotate right.\r
1753\r
1754 @return Operand >>> Count\r
1755\r
1756**/\r
1757UINT32\r
1758EFIAPI\r
1759RRotU32 (\r
1760 IN UINT32 Operand,\r
1761 IN UINTN Count\r
1762 );\r
1763\r
1764\r
1765/**\r
1766 Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits\r
1767 with the high bits that were rotated.\r
1768\r
1769 This function rotates the 64-bit value Operand to the left by Count bits. The\r
1770 low Count bits are fill with the high Count bits of Operand. The rotated\r
1771 value is returned.\r
1772\r
1773 If Count is greater than 63, then ASSERT().\r
1774\r
1775 @param Operand The 64-bit operand to rotate left.\r
1776 @param Count The number of bits to rotate left.\r
1777\r
17f695ed 1778 @return Operand << Count\r
ac644614 1779\r
1780**/\r
1781UINT64\r
1782EFIAPI\r
1783LRotU64 (\r
1784 IN UINT64 Operand,\r
1785 IN UINTN Count\r
1786 );\r
1787\r
1788\r
1789/**\r
1790 Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits\r
1791 with the high low bits that were rotated.\r
1792\r
1793 This function rotates the 64-bit value Operand to the right by Count bits.\r
1794 The high Count bits are fill with the low Count bits of Operand. The rotated\r
1795 value is returned.\r
1796\r
1797 If Count is greater than 63, then ASSERT().\r
1798\r
1799 @param Operand The 64-bit operand to rotate right.\r
1800 @param Count The number of bits to rotate right.\r
1801\r
17f695ed 1802 @return Operand >> Count\r
ac644614 1803\r
1804**/\r
1805UINT64\r
1806EFIAPI\r
1807RRotU64 (\r
1808 IN UINT64 Operand,\r
1809 IN UINTN Count\r
1810 );\r
1811\r
1812\r
1813/**\r
1814 Returns the bit position of the lowest bit set in a 32-bit value.\r
1815\r
1816 This function computes the bit position of the lowest bit set in the 32-bit\r
1817 value specified by Operand. If Operand is zero, then -1 is returned.\r
1818 Otherwise, a value between 0 and 31 is returned.\r
1819\r
1820 @param Operand The 32-bit operand to evaluate.\r
1821\r
17f695ed 1822 @retval 0-31 The lowest bit set in Operand was found.\r
1823 @retval -1 Operand is zero.\r
ac644614 1824\r
1825**/\r
1826INTN\r
1827EFIAPI\r
1828LowBitSet32 (\r
1829 IN UINT32 Operand\r
1830 );\r
1831\r
1832\r
1833/**\r
1834 Returns the bit position of the lowest bit set in a 64-bit value.\r
1835\r
1836 This function computes the bit position of the lowest bit set in the 64-bit\r
1837 value specified by Operand. If Operand is zero, then -1 is returned.\r
1838 Otherwise, a value between 0 and 63 is returned.\r
1839\r
1840 @param Operand The 64-bit operand to evaluate.\r
1841\r
17f695ed 1842 @retval 0-63 The lowest bit set in Operand was found.\r
1843 @retval -1 Operand is zero.\r
1844\r
ac644614 1845\r
1846**/\r
1847INTN\r
1848EFIAPI\r
1849LowBitSet64 (\r
1850 IN UINT64 Operand\r
1851 );\r
1852\r
1853\r
1854/**\r
1855 Returns the bit position of the highest bit set in a 32-bit value. Equivalent\r
1856 to log2(x).\r
1857\r
1858 This function computes the bit position of the highest bit set in the 32-bit\r
1859 value specified by Operand. If Operand is zero, then -1 is returned.\r
1860 Otherwise, a value between 0 and 31 is returned.\r
1861\r
1862 @param Operand The 32-bit operand to evaluate.\r
1863\r
17f695ed 1864 @retval 0-31 Position of the highest bit set in Operand if found.\r
1865 @retval -1 Operand is zero.\r
ac644614 1866\r
1867**/\r
1868INTN\r
1869EFIAPI\r
1870HighBitSet32 (\r
1871 IN UINT32 Operand\r
1872 );\r
1873\r
1874\r
1875/**\r
1876 Returns the bit position of the highest bit set in a 64-bit value. Equivalent\r
1877 to log2(x).\r
1878\r
1879 This function computes the bit position of the highest bit set in the 64-bit\r
1880 value specified by Operand. If Operand is zero, then -1 is returned.\r
1881 Otherwise, a value between 0 and 63 is returned.\r
1882\r
1883 @param Operand The 64-bit operand to evaluate.\r
1884\r
17f695ed 1885 @retval 0-63 Position of the highest bit set in Operand if found.\r
1886 @retval -1 Operand is zero.\r
ac644614 1887\r
1888**/\r
1889INTN\r
1890EFIAPI\r
1891HighBitSet64 (\r
1892 IN UINT64 Operand\r
1893 );\r
1894\r
1895\r
1896/**\r
1897 Returns the value of the highest bit set in a 32-bit value. Equivalent to\r
17f695ed 1898 1 << log2(x).\r
ac644614 1899\r
1900 This function computes the value of the highest bit set in the 32-bit value\r
1901 specified by Operand. If Operand is zero, then zero is returned.\r
1902\r
1903 @param Operand The 32-bit operand to evaluate.\r
1904\r
1905 @return 1 << HighBitSet32(Operand)\r
1906 @retval 0 Operand is zero.\r
1907\r
1908**/\r
1909UINT32\r
1910EFIAPI\r
1911GetPowerOfTwo32 (\r
1912 IN UINT32 Operand\r
1913 );\r
1914\r
1915\r
1916/**\r
1917 Returns the value of the highest bit set in a 64-bit value. Equivalent to\r
17f695ed 1918 1 << log2(x).\r
ac644614 1919\r
1920 This function computes the value of the highest bit set in the 64-bit value\r
1921 specified by Operand. If Operand is zero, then zero is returned.\r
1922\r
1923 @param Operand The 64-bit operand to evaluate.\r
1924\r
1925 @return 1 << HighBitSet64(Operand)\r
1926 @retval 0 Operand is zero.\r
1927\r
1928**/\r
1929UINT64\r
1930EFIAPI\r
1931GetPowerOfTwo64 (\r
1932 IN UINT64 Operand\r
1933 );\r
1934\r
1935\r
1936/**\r
1937 Switches the endianess of a 16-bit integer.\r
1938\r
1939 This function swaps the bytes in a 16-bit unsigned value to switch the value\r
1940 from little endian to big endian or vice versa. The byte swapped value is\r
1941 returned.\r
1942\r
1943 @param Value Operand A 16-bit unsigned value.\r
1944\r
17f695ed 1945 @return The byte swapped Operand.\r
ac644614 1946\r
1947**/\r
1948UINT16\r
1949EFIAPI\r
1950SwapBytes16 (\r
1951 IN UINT16 Value\r
1952 );\r
1953\r
1954\r
1955/**\r
1956 Switches the endianess of a 32-bit integer.\r
1957\r
1958 This function swaps the bytes in a 32-bit unsigned value to switch the value\r
1959 from little endian to big endian or vice versa. The byte swapped value is\r
1960 returned.\r
1961\r
1962 @param Value Operand A 32-bit unsigned value.\r
1963\r
17f695ed 1964 @return The byte swapped Operand.\r
ac644614 1965\r
1966**/\r
1967UINT32\r
1968EFIAPI\r
1969SwapBytes32 (\r
1970 IN UINT32 Value\r
1971 );\r
1972\r
1973\r
1974/**\r
1975 Switches the endianess of a 64-bit integer.\r
1976\r
1977 This function swaps the bytes in a 64-bit unsigned value to switch the value\r
1978 from little endian to big endian or vice versa. The byte swapped value is\r
1979 returned.\r
1980\r
1981 @param Value Operand A 64-bit unsigned value.\r
1982\r
17f695ed 1983 @return The byte swapped Operand.\r
ac644614 1984\r
1985**/\r
1986UINT64\r
1987EFIAPI\r
1988SwapBytes64 (\r
1989 IN UINT64 Value\r
1990 );\r
1991\r
1992\r
1993/**\r
1994 Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and\r
1995 generates a 64-bit unsigned result.\r
1996\r
1997 This function multiples the 64-bit unsigned value Multiplicand by the 32-bit\r
1998 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
1999 bit unsigned result is returned.\r
2000\r
2001 If the result overflows, then ASSERT().\r
2002\r
2003 @param Multiplicand A 64-bit unsigned value.\r
2004 @param Multiplier A 32-bit unsigned value.\r
2005\r
2006 @return Multiplicand * Multiplier\r
2007\r
2008**/\r
2009UINT64\r
2010EFIAPI\r
2011MultU64x32 (\r
2012 IN UINT64 Multiplicand,\r
2013 IN UINT32 Multiplier\r
2014 );\r
2015\r
2016\r
2017/**\r
2018 Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and\r
2019 generates a 64-bit unsigned result.\r
2020\r
2021 This function multiples the 64-bit unsigned value Multiplicand by the 64-bit\r
2022 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
2023 bit unsigned result is returned.\r
2024\r
2025 If the result overflows, then ASSERT().\r
2026\r
2027 @param Multiplicand A 64-bit unsigned value.\r
2028 @param Multiplier A 64-bit unsigned value.\r
2029\r
2030 @return Multiplicand * Multiplier\r
2031\r
2032**/\r
2033UINT64\r
2034EFIAPI\r
2035MultU64x64 (\r
2036 IN UINT64 Multiplicand,\r
2037 IN UINT64 Multiplier\r
2038 );\r
2039\r
2040\r
2041/**\r
2042 Multiples a 64-bit signed integer by a 64-bit signed integer and generates a\r
2043 64-bit signed result.\r
2044\r
2045 This function multiples the 64-bit signed value Multiplicand by the 64-bit\r
2046 signed value Multiplier and generates a 64-bit signed result. This 64-bit\r
2047 signed result is returned.\r
2048\r
2049 If the result overflows, then ASSERT().\r
2050\r
2051 @param Multiplicand A 64-bit signed value.\r
2052 @param Multiplier A 64-bit signed value.\r
2053\r
2054 @return Multiplicand * Multiplier\r
2055\r
2056**/\r
2057INT64\r
2058EFIAPI\r
2059MultS64x64 (\r
2060 IN INT64 Multiplicand,\r
2061 IN INT64 Multiplier\r
2062 );\r
2063\r
2064\r
2065/**\r
2066 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
2067 a 64-bit unsigned result.\r
2068\r
2069 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
2070 unsigned value Divisor and generates a 64-bit unsigned quotient. This\r
2071 function returns the 64-bit unsigned quotient.\r
2072\r
2073 If Divisor is 0, then ASSERT().\r
2074\r
2075 @param Dividend A 64-bit unsigned value.\r
2076 @param Divisor A 32-bit unsigned value.\r
2077\r
2078 @return Dividend / Divisor\r
2079\r
2080**/\r
2081UINT64\r
2082EFIAPI\r
2083DivU64x32 (\r
2084 IN UINT64 Dividend,\r
2085 IN UINT32 Divisor\r
2086 );\r
2087\r
2088\r
2089/**\r
2090 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
2091 a 32-bit unsigned remainder.\r
2092\r
2093 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
2094 unsigned value Divisor and generates a 32-bit remainder. This function\r
2095 returns the 32-bit unsigned remainder.\r
2096\r
2097 If Divisor is 0, then ASSERT().\r
2098\r
2099 @param Dividend A 64-bit unsigned value.\r
2100 @param Divisor A 32-bit unsigned value.\r
2101\r
2102 @return Dividend % Divisor\r
2103\r
2104**/\r
2105UINT32\r
2106EFIAPI\r
2107ModU64x32 (\r
2108 IN UINT64 Dividend,\r
2109 IN UINT32 Divisor\r
2110 );\r
2111\r
2112\r
2113/**\r
2114 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
2115 a 64-bit unsigned result and an optional 32-bit unsigned remainder.\r
2116\r
2117 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
2118 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r
2119 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.\r
2120 This function returns the 64-bit unsigned quotient.\r
2121\r
2122 If Divisor is 0, then ASSERT().\r
2123\r
2124 @param Dividend A 64-bit unsigned value.\r
2125 @param Divisor A 32-bit unsigned value.\r
2126 @param Remainder A pointer to a 32-bit unsigned value. This parameter is\r
2127 optional and may be NULL.\r
2128\r
2129 @return Dividend / Divisor\r
2130\r
2131**/\r
2132UINT64\r
2133EFIAPI\r
2134DivU64x32Remainder (\r
2135 IN UINT64 Dividend,\r
2136 IN UINT32 Divisor,\r
2137 OUT UINT32 *Remainder OPTIONAL\r
2138 );\r
2139\r
2140\r
2141/**\r
2142 Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates\r
2143 a 64-bit unsigned result and an optional 64-bit unsigned remainder.\r
2144\r
2145 This function divides the 64-bit unsigned value Dividend by the 64-bit\r
2146 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r
2147 is not NULL, then the 64-bit unsigned remainder is returned in Remainder.\r
2148 This function returns the 64-bit unsigned quotient.\r
2149\r
2150 If Divisor is 0, then ASSERT().\r
2151\r
2152 @param Dividend A 64-bit unsigned value.\r
2153 @param Divisor A 64-bit unsigned value.\r
2154 @param Remainder A pointer to a 64-bit unsigned value. This parameter is\r
2155 optional and may be NULL.\r
2156\r
2157 @return Dividend / Divisor\r
2158\r
2159**/\r
2160UINT64\r
2161EFIAPI\r
2162DivU64x64Remainder (\r
2163 IN UINT64 Dividend,\r
2164 IN UINT64 Divisor,\r
2165 OUT UINT64 *Remainder OPTIONAL\r
2166 );\r
2167\r
2168\r
2169/**\r
2170 Divides a 64-bit signed integer by a 64-bit signed integer and generates a\r
2171 64-bit signed result and a optional 64-bit signed remainder.\r
2172\r
2173 This function divides the 64-bit signed value Dividend by the 64-bit signed\r
2174 value Divisor and generates a 64-bit signed quotient. If Remainder is not\r
2175 NULL, then the 64-bit signed remainder is returned in Remainder. This\r
2176 function returns the 64-bit signed quotient.\r
2177\r
17f695ed 2178