]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/FCE/Common.h
Revert "BaseTools/FMMT: Add a tool FMMT"
[mirror_edk2.git] / BaseTools / Source / C / FCE / Common.h
CommitLineData
3c59d946
SZ
1/** @file\r
2\r
3 Common library.\r
4\r
5 Copyright (c) 2011-2019, Intel Corporation. All rights reserved.<BR>\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8**/\r
9#ifndef _COMMON_LIB_H_\r
10#define _COMMON_LIB_H_\r
11\r
12#include <stdio.h>\r
13#include <stdlib.h>\r
14#include <string.h>\r
15#ifdef __GNUC__\r
16#include <unistd.h>\r
17#else\r
18#include <io.h>\r
19#include <direct.h>\r
20#endif\r
21#include <ctype.h>\r
22#include <assert.h>\r
23#include <math.h>\r
24#include "CommonLib.h"\r
25#include <Common/UefiBaseTypes.h>\r
26\r
27#define MAX_QUI_PARAM_LEN 2000\r
28#define ERROR_INFO_LENGTH 400\r
29#define MAX_STR_LEN_FOR_PICK_UQI 200\r
30#define MAX_PLATFORM_DEFAULT_ID_NUM 1000\r
31#define _MAX_BUILD_VERSION 100\r
32#define _MAXIMUM_SECTION_FILE_NUM 1000\r
33\r
34#ifndef _MAX_PATH\r
35#define _MAX_PATH 500\r
36#endif\r
37\r
38///\r
39/// Variable attributes.\r
40///\r
41#define EFI_VARIABLE_NON_VOLATILE 0x00000001\r
42#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002\r
43#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004\r
44\r
45///\r
46/// This attribute is identified by the mnemonic 'HR'\r
47/// elsewhere in this specification.\r
48///\r
49#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010\r
50\r
51#define VARSTORE_LIST_TYPE 0x0000000000000001ULL\r
52#define EFI_VARSTORE_LIST_TYPE 0x0000000000000002ULL\r
53#define PLATFORM_DEFAULT_ID_TYPE 0x0000000000000004ULL\r
54#define UQI_LIST_TYPE 0x0000000000000008ULL\r
55#define HII_OBJ_LIST_TYPE 0x0000000000000010ULL\r
56\r
57///\r
58/// LIST_ENTRY structure definition.\r
59///\r
60typedef struct _LIST_ENTRY {\r
61 struct _LIST_ENTRY *ForwardLink;\r
62 struct _LIST_ENTRY *BackLink;\r
63} LIST_ENTRY;\r
64\r
65#define CR(Record, TYPE, Field, TestSignature) ((TYPE *) ((CHAR8 *) (Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))\r
66#define AllocateZeroPool(a) calloc(a, sizeof (CHAR8))\r
67#define FreePool(a) free(a)\r
68#define CopyMem(a, b, c) memcpy(a, b, c)\r
69#define ZeroMem(a, b) memset(a, 0, b)\r
70#define CompareMem(a, b, c) memcmp(a, b, c)\r
71#define AllocatePool(a) malloc(a)\r
72\r
73/**\r
74 Returns a 16-bit signature built from 2 ASCII characters.\r
75\r
76 This macro returns a 16-bit value built from the two ASCII characters specified\r
77 by A and B.\r
78\r
79 @param A The first ASCII character.\r
80 @param B The second ASCII character.\r
81\r
82 @return A 16-bit value built from the two ASCII characters specified by A and B.\r
83\r
84**/\r
85#define SIGNATURE_16(A, B) ((A) | (B << 8))\r
86\r
87/**\r
88 Returns a 32-bit signature built from 4 ASCII characters.\r
89\r
90 This macro returns a 32-bit value built from the four ASCII characters specified\r
91 by A, B, C, and D.\r
92\r
93 @param A The first ASCII character.\r
94 @param B The second ASCII character.\r
95 @param C The third ASCII character.\r
96 @param D The fourth ASCII character.\r
97\r
98 @return A 32-bit value built from the two ASCII characters specified by A, B,\r
99 C and D.\r
100\r
101**/\r
102#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C, D) << 16))\r
103\r
104#define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)\r
105\r
106/**\r
107 Returns an argument of a specified type from a variable argument list and updates\r
108 the pointer to the variable argument list to point to the next argument.\r
109\r
110 This function returns an argument of the type specified by TYPE from the beginning\r
111 of the variable argument list specified by Marker. Marker is then updated to point\r
112 to the next argument in the variable argument list. The method for computing the\r
113 pointer to the next argument in the argument list is CPU specific following the EFIAPI ABI.\r
114\r
115 @param Marker The pointer to the beginning of a variable argument list.\r
116 @param TYPE The type of argument to retrieve from the beginning\r
117 of the variable argument list.\r
118\r
119 @return An argument of the type specified by TYPE.\r
120\r
121**/\r
122#define BASE_ARG(Marker, TYPE) (*(TYPE *) ((Marker += _BASE_INT_SIZE_OF (TYPE)) - _BASE_INT_SIZE_OF (TYPE)))\r
123\r
124///\r
125/// Define the maximum number of characters that are required to\r
126/// encode with a NULL terminator a decimal, hexadecimal, GUID,\r
127/// or TIME value.\r
128///\r
129/// Maximum Length Decimal String = 28\r
130/// "-9,223,372,036,854,775,808"\r
131/// Maximum Length Hexadecimal String = 17\r
132/// "FFFFFFFFFFFFFFFF"\r
133/// Maximum Length GUID = 37\r
134/// "00000000-0000-0000-0000-000000000000"\r
135/// Maximum Length TIME = 18\r
136/// "12/12/2006 12:12"\r
137///\r
138#define MAXIMUM_VALUE_CHARACTERS 38\r
139\r
140///\r
141/// Pointer to the start of a variable argument list stored in a memory buffer. Same as UINT8 *.\r
142///\r
143typedef UINTN *BASE_LIST;\r
144\r
145/**\r
146 Returns the size of a data type in sizeof(UINTN) units rounded up to the nearest UINTN boundary.\r
147\r
148 @param TYPE The date type to determine the size of.\r
149\r
150 @return The size of TYPE in sizeof (UINTN) units rounded up to the nearest UINTN boundary.\r
151**/\r
152#define _BASE_INT_SIZE_OF(TYPE) ((sizeof (TYPE) + sizeof (UINTN) - 1) / sizeof (UINTN))\r
153\r
154//\r
155// Print primitives\r
156//\r
157#define PREFIX_SIGN BIT1\r
158#define PREFIX_BLANK BIT2\r
159#define LONG_TYPE BIT4\r
160#define OUTPUT_UNICODE BIT6\r
161#define FORMAT_UNICODE BIT8\r
162#define PAD_TO_WIDTH BIT9\r
163#define ARGUMENT_UNICODE BIT10\r
164#define PRECISION BIT11\r
165#define ARGUMENT_REVERSED BIT12\r
166#define COUNT_ONLY_NO_PRINT BIT13\r
167\r
168///\r
169/// Flags bitmask values use in UnicodeValueToString() and\r
170/// AsciiValueToString()\r
171///\r
172#define LEFT_JUSTIFY 0x01\r
173#define COMMA_TYPE 0x08\r
174#define PREFIX_ZERO 0x20\r
175#define RADIX_HEX 0x80\r
176\r
177//\r
178// Record date and time information\r
179//\r
180typedef struct {\r
181 UINT16 Year;\r
182 UINT8 Month;\r
183 UINT8 Day;\r
184 UINT8 Hour;\r
185 UINT8 Minute;\r
186 UINT8 Second;\r
187 UINT8 Pad1;\r
188 UINT32 Nanosecond;\r
189 INT16 TimeZone;\r
190 UINT8 Daylight;\r
191 UINT8 Pad2;\r
192} TIME;\r
193\r
194\r
195/**\r
196 Copies one Null-terminated Unicode string to another Null-terminated Unicode\r
197 string and returns the new Unicode string.\r
198\r
199 This function copies the contents of the Unicode string Source to the Unicode\r
200 string Destination, and returns Destination. If Source and Destination\r
201 overlap, then the results are undefined.\r
202\r
203 If Destination is NULL, then return NULL.\r
204 If Destination is not aligned on a 16-bit boundary, then return NULL.\r
205\r
206 @param Destination A pointer to a Null-terminated Unicode string.\r
207 @param Source A pointer to a Null-terminated Unicode string.\r
208\r
209 @return Destination.\r
210\r
211**/\r
212CHAR16 *\r
213StrCpy (\r
214 OUT CHAR16 *Destination,\r
215 IN CONST CHAR16 *Source\r
216 );\r
217\r
218/**\r
219 Returns the length of a Null-terminated Unicode string.\r
220\r
221 This function returns the number of Unicode characters in the Null-terminated\r
222 Unicode string specified by String.\r
223\r
224 If String is NULL, then return 0.\r
225\r
226 @param String A pointer to a Null-terminated Unicode string.\r
227\r
228 @return The length of String.\r
229\r
230**/\r
231UINTN\r
232FceStrLen (\r
233 IN CONST CHAR16 *String\r
234 );\r
235\r
236/**\r
237 Returns the size of a Null-terminated Unicode string in bytes, including the\r
238 Null terminator.\r
239\r
240 This function returns the size, in bytes, of the Null-terminated Unicode string\r
241 specified by String.\r
242\r
243 If String is NULL, then ASSERT().\r
244 If String is not aligned on a 16-bit boundary, then ASSERT().\r
245 If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
246 PcdMaximumUnicodeStringLength Unicode characters, not including the\r
247 Null-terminator, then ASSERT().\r
248\r
249 @param String A pointer to a Null-terminated Unicode string.\r
250\r
251 @return The size of String.\r
252\r
253**/\r
254UINTN\r
255FceStrSize (\r
256 IN CONST CHAR16 *String\r
257 );\r
258\r
259/**\r
260 Compares two Null-terminated Unicode strings, and returns the difference\r
261 between the first mismatched Unicode characters.\r
262\r
263 This function compares the Null-terminated Unicode string FirstString to the\r
264 Null-terminated Unicode string SecondString. If FirstString is identical to\r
265 SecondString, then 0 is returned. Otherwise, the value returned is the first\r
266 mismatched Unicode character in SecondString subtracted from the first\r
267 mismatched Unicode character in FirstString.\r
268\r
269 @param FirstString A pointer to a Null-terminated Unicode string.\r
270 @param SecondString A pointer to a Null-terminated Unicode string.\r
271\r
272 @retval 0 FirstString is identical to SecondString.\r
273 @return others FirstString is not identical to SecondString.\r
274\r
275**/\r
276INTN\r
277FceStrCmp (\r
278 IN CONST CHAR16 *FirstString,\r
279 IN CONST CHAR16 *SecondString\r
280 );\r
281\r
282/**\r
283 Concatenates one Null-terminated Unicode string to another Null-terminated\r
284 Unicode string, and returns the concatenated Unicode string.\r
285\r
286 This function concatenates two Null-terminated Unicode strings. The contents\r
287 of Null-terminated Unicode string Source are concatenated to the end of\r
288 Null-terminated Unicode string Destination. The Null-terminated concatenated\r
289 Unicode String is returned. If Source and Destination overlap, then the\r
290 results are undefined.\r
291\r
292 If Destination is NULL, then ASSERT().\r
293 If Destination is not aligned on a 16-bit boundary, then ASSERT().\r
294 If Source is NULL, then ASSERT().\r
295 If Source is not aligned on a 16-bit boundary, then ASSERT().\r
296 If Source and Destination overlap, then ASSERT().\r
297 If PcdMaximumUnicodeStringLength is not zero, and Destination contains more\r
298 than PcdMaximumUnicodeStringLength Unicode characters, not including the\r
299 Null-terminator, then ASSERT().\r
300 If PcdMaximumUnicodeStringLength is not zero, and Source contains more than\r
301 PcdMaximumUnicodeStringLength Unicode characters, not including the\r
302 Null-terminator, then ASSERT().\r
303 If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination\r
304 and Source results in a Unicode string with more than\r
305 PcdMaximumUnicodeStringLength Unicode characters, not including the\r
306 Null-terminator, then ASSERT().\r
307\r
308 @param Destination A pointer to a Null-terminated Unicode string.\r
309 @param Source A pointer to a Null-terminated Unicode string.\r
310\r
311 @return Destination.\r
312\r
313**/\r
314CHAR16 *\r
315StrCat (\r
316 IN OUT CHAR16 *Destination,\r
317 IN CONST CHAR16 *Source\r
318 );\r
319\r
320/**\r
321 Returns the first occurrence of a Null-terminated Unicode sub-string\r
322 in a Null-terminated Unicode string.\r
323\r
324 This function scans the contents of the Null-terminated Unicode string\r
325 specified by String and returns the first occurrence of SearchString.\r
326 If SearchString is not found in String, then NULL is returned. If\r
327 the length of SearchString is zero, then String is\r
328 returned.\r
329\r
330 If String is NULL, then ASSERT().\r
331 If String is not aligned on a 16-bit boundary, then ASSERT().\r
332 If SearchString is NULL, then ASSERT().\r
333 If SearchString is not aligned on a 16-bit boundary, then ASSERT().\r
334\r
335 If PcdMaximumUnicodeStringLength is not zero, and SearchString\r
336 or String contains more than PcdMaximumUnicodeStringLength Unicode\r
337 characters, not including the Null-terminator, then ASSERT().\r
338\r
339 @param String A pointer to a Null-terminated Unicode string.\r
340 @param SearchString A pointer to a Null-terminated Unicode string to search for.\r
341\r
342 @retval NULL If the SearchString does not appear in String.\r
343 @return others If there is a match.\r
344\r
345**/\r
346CHAR16 *\r
347StrStr (\r
348 IN CONST CHAR16 *String,\r
349 IN CONST CHAR16 *SearchString\r
350 );\r
351\r
352/**\r
353 Convert a Null-terminated Unicode decimal string to a value of\r
354 type UINT64.\r
355\r
356 This function returns a value of type UINT64 by interpreting the contents\r
357 of the Unicode string specified by String as a decimal number. The format\r
358 of the input Unicode string String is:\r
359\r
360 [spaces] [decimal digits].\r
361\r
362 The valid decimal digit character is in the range [0-9]. The\r
363 function will ignore the pad space, which includes spaces or\r
364 tab characters, before [decimal digits]. The running zero in the\r
365 beginning of [decimal digits] will be ignored. Then, the function\r
366 stops at the first character that is a not a valid decimal character\r
367 or a Null-terminator, whichever one comes first.\r
368\r
369 If String is NULL, then ASSERT().\r
370 If String is not aligned in a 16-bit boundary, then ASSERT().\r
371 If String has only pad spaces, then 0 is returned.\r
372 If String has no pad spaces or valid decimal digits,\r
373 then 0 is returned.\r
374 If the number represented by String overflows according\r
375 to the range defined by UINT64, then ASSERT().\r
376\r
377 If PcdMaximumUnicodeStringLength is not zero, and String contains\r
378 more than PcdMaximumUnicodeStringLength Unicode characters, not including\r
379 the Null-terminator, then ASSERT().\r
380\r
381 @param String A pointer to a Null-terminated Unicode string.\r
382\r
383 @retval Value translated from String.\r
384\r
385**/\r
386UINT64\r
387FceStrDecimalToUint64 (\r
388 IN CONST CHAR16 *String\r
389 );\r
390\r
391\r
392/**\r
393 Convert one Null-terminated ASCII string to a Null-terminated\r
394 Unicode string and returns the Unicode string.\r
395\r
396 This function converts the contents of the ASCII string Source to the Unicode\r
397 string Destination, and returns Destination. The function terminates the\r
398 Unicode string Destination by appending a Null-terminator character at the end.\r
399 The caller is responsible to make sure Destination points to a buffer with size\r
400 equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.\r
401\r
402 @param Source A pointer to a Null-terminated ASCII string.\r
403 @param Destination A pointer to a Null-terminated Unicode string.\r
404\r
405 @return Destination.\r
406 @return NULL If Destination or Source is NULL, return NULL.\r
407\r
408**/\r
409CHAR16 *\r
410AsciiStrToUnicodeStr (\r
411 IN CONST CHAR8 *Source,\r
412 OUT CHAR16 *Destination\r
413 );\r
414\r
415/**\r
416 Worker function that produces a Null-terminated string in an output buffer\r
417 based on a Null-terminated format string and variable argument list.\r
418\r
419 VSPrint function to process format and place the results in Buffer. Since a\r
420 VA_LIST is used this routine allows the nesting of Vararg routines. Thus\r
421 this is the main print working routine\r
422\r
423 @param StartOfBuffer The character buffer to print the results of the parsing\r
424 of Format into.\r
425 @param BufferSize The maximum number of characters to put into buffer.\r
426 Zero means no limit.\r
427 @param Flags Initial flags value.\r
428 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r
429 @param FormatString A Null-terminated format string.\r
430 @param ... The variable argument list.\r
431\r
432 @return The number of characters printed.\r
433\r
434**/\r
435UINTN\r
436BasePrintLibSPrint (\r
437 OUT CHAR8 *StartOfBuffer,\r
438 IN UINTN BufferSize,\r
439 IN UINTN Flags,\r
440 IN CONST CHAR8 *FormatString,\r
441 ...\r
442 );\r
443\r
444/**\r
445 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
446 Unicode format string and variable argument list.\r
447\r
448 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
449 and BufferSize.\r
450 The Unicode string is produced by parsing the format string specified by FormatString.\r
451 Arguments are pulled from the variable argument list based on the contents of the format string.\r
452 The number of Unicode characters in the produced output buffer is returned not including\r
453 the Null-terminator.\r
454 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
455\r
456 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
457 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
458 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
459 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
460 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
461 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
462 ASSERT().\r
463 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
464 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
465 Null-terminator, then ASSERT().\r
466\r
467 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
468 Unicode string.\r
469 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
470 @param FormatString A Null-terminated Unicode format string.\r
471 @param ... Variable argument list whose contents are accessed based on the\r
472 format string specified by FormatString.\r
473\r
474 @return The number of Unicode characters in the produced output buffer not including the\r
475 Null-terminator.\r
476\r
477**/\r
478UINTN\r
479UnicodeSPrint (\r
480 OUT CHAR16 *StartOfBuffer,\r
481 IN UINTN BufferSize,\r
482 IN CONST CHAR16 *FormatString,\r
483 ...\r
484 );\r
485\r
486/**\r
487 Convert a Null-terminated Unicode string to a Null-terminated\r
488 ASCII string and returns the ASCII string.\r
489\r
490 This function converts the content of the Unicode string Source\r
491 to the ASCII string Destination by copying the lower 8 bits of\r
492 each Unicode character. It returns Destination. The function terminates\r
493 the ASCII string Destination by appending a Null-terminator character\r
494 at the end. The caller is responsible to make sure Destination points\r
495 to a buffer with size equal or greater than (FceStrLen (Source) + 1) in bytes.\r
496\r
497 If Destination is NULL, then ASSERT().\r
498 If Source is NULL, then ASSERT().\r
499 If Source is not aligned on a 16-bit boundary, then ASSERT().\r
500 If Source and Destination overlap, then ASSERT().\r
501\r
502 If any Unicode characters in Source contain non-zero value in\r
503 the upper 8 bits, then ASSERT().\r
504\r
505 @param Source Pointer to a Null-terminated Unicode string.\r
506 @param Destination Pointer to a Null-terminated ASCII string.\r
507\r
508 @reture Destination\r
509\r
510**/\r
511CHAR8 *\r
512UnicodeStrToAsciiStr (\r
513 IN CONST CHAR16 *Source,\r
514 OUT CHAR8 *Destination\r
515 );\r
516\r
517/**\r
518 Allocate new memory and then copy the Unicode string Source to Destination.\r
519\r
520 @param Dest Location to copy string\r
521 @param Src String to copy\r
522\r
523**/\r
524VOID\r
525NewStringCpy (\r
526 IN OUT CHAR16 **Dest,\r
527 IN CHAR16 *Src\r
528 );\r
529\r
530/**\r
531 Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.\r
532\r
533 This function returns a value of type UINT64 by interpreting the contents\r
534 of the Unicode string specified by String as a hexadecimal number.\r
535 The format of the input Unicode string String is\r
536\r
537 [spaces][zeros][x][hexadecimal digits].\r
538\r
539 The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].\r
540 The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.\r
541 If "x" appears in the input string, it must be prefixed with at least one 0.\r
542 The function will ignore the pad space, which includes spaces or tab characters,\r
543 before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or\r
544 [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the\r
545 first valid hexadecimal digit. Then, the function stops at the first character that is\r
546 a not a valid hexadecimal character or NULL, whichever one comes first.\r
547\r
548 If String is NULL, then ASSERT().\r
549 If String is not aligned in a 16-bit boundary, then ASSERT().\r
550 If String has only pad spaces, then zero is returned.\r
551 If String has no leading pad spaces, leading zeros or valid hexadecimal digits,\r
552 then zero is returned.\r
553 If the number represented by String overflows according to the range defined by\r
554 UINT64, then ASSERT().\r
555\r
556 If PcdMaximumUnicodeStringLength is not zero, and String contains more than\r
557 PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,\r
558 then ASSERT().\r
559\r
560 @param String A pointer to a Null-terminated Unicode string.\r
561\r
562 @retval Value translated from String.\r
563\r
564**/\r
565UINT64\r
566FceStrHexToUint64 (\r
567 IN CONST CHAR16 *String\r
568 );\r
569\r
570\r
571CHAR16\r
572ToUpper (\r
573 CHAR16 a\r
574 );\r
575\r
576CHAR16\r
577ToLower (\r
578 CHAR16 a\r
579 );\r
580\r
581/**\r
582 Performs a case-insensitive comparison between a Null-terminated\r
583 Unicode pattern string and a Null-terminated Unicode string.\r
584\r
585 @param String - A pointer to a Null-terminated Unicode string.\r
586 @param Pattern - A pointer to a Null-terminated Unicode pattern string.\r
587\r
588\r
589 @retval TRUE - Pattern was found in String.\r
590 @retval FALSE - Pattern was not found in String.\r
591\r
592**/\r
593BOOLEAN\r
594MetaiMatch (\r
595 IN CHAR16 *String,\r
596 IN CHAR16 *Pattern\r
597 );\r
598\r
599/**\r
600 Multiplies a 64-bit unsigned integer by a 32-bit unsigned integer and\r
601 generates a 64-bit unsigned result.\r
602\r
603 This function multiplies the 64-bit unsigned value Multiplicand by the 32-bit\r
604 unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r
605 bit unsigned result is returned.\r
606\r
607 @param Multiplicand A 64-bit unsigned value.\r
608 @param Multiplier A 32-bit unsigned value.\r
609\r
610 @return Multiplicand * Multiplier.\r
611\r
612**/\r
613UINT64\r
614MultU64x32 (\r
615 IN UINT64 Multiplicand,\r
616 IN UINT32 Multiplier\r
617 );\r
618\r
619/**\r
620 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
621 a 64-bit unsigned result.\r
622\r
623 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
624 unsigned value Divisor and generates a 64-bit unsigned quotient. This\r
625 function returns the 64-bit unsigned quotient.\r
626\r
627 If Divisor is 0, then ASSERT().\r
628\r
629 @param Dividend A 64-bit unsigned value.\r
630 @param Divisor A 32-bit unsigned value.\r
631\r
632 @return Dividend / Divisor\r
633\r
634**/\r
635UINT64\r
636DivU64x32 (\r
637 IN UINT64 Dividend,\r
638 IN UINT32 Divisor\r
639 );\r
640\r
641/**\r
642 Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled\r
643 with zeros. The shifted value is returned.\r
644\r
645 This function shifts the 64-bit value Operand to the left by Count bits. The\r
646 low Count bits are set to zero. The shifted value is returned.\r
647\r
648 If Count is greater than 63, then ASSERT().\r
649\r
650 @param Operand The 64-bit operand to shift left.\r
651 @param Count The number of bits to shift left.\r
652\r
653 @return Operand << Count.\r
654\r
655**/\r
656UINT64\r
657LShiftU64 (\r
658 IN UINT64 Operand,\r
659 IN UINTN Count\r
660 );\r
661\r
662/**\r
663 Shifts a 64-bit integer right between 0 and 63 bits. This high bits are\r
664 filled with zeros. The shifted value is returned.\r
665\r
666 This function shifts the 64-bit value Operand to the right by Count bits. The\r
667 high Count bits are set to zero. The shifted value is returned.\r
668\r
669 If Count is greater than 63, then ASSERT().\r
670\r
671 @param Operand The 64-bit operand to shift right.\r
672 @param Count The number of bits to shift right.\r
673\r
674 @return Operand >> Count.\r
675\r
676**/\r
677UINT64\r
678RShiftU64 (\r
679 IN UINT64 Operand,\r
680 IN UINTN Count\r
681 );\r
682\r
683\r
684/**\r
685 Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates\r
686 a 64-bit unsigned result and an optional 32-bit unsigned remainder.\r
687\r
688 This function divides the 64-bit unsigned value Dividend by the 32-bit\r
689 unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r
690 is not NULL, then the 32-bit unsigned remainder is returned in Remainder.\r
691 This function returns the 64-bit unsigned quotient.\r
692\r
693 If Divisor is 0, then ASSERT().\r
694\r
695 @param Dividend A 64-bit unsigned value.\r
696 @param Divisor A 32-bit unsigned value.\r
697 @param Remainder A pointer to a 32-bit unsigned value. This parameter is\r
698 optional and may be NULL.\r
699\r
700 @return Dividend / Divisor\r
701\r
702**/\r
703UINT64\r
704DivU64x32Remainder (\r
705 IN UINT64 Dividend,\r
706 IN UINT32 Divisor,\r
707 OUT UINT32 *Remainder\r
708 );\r
709\r
710/**\r
711 Copies a buffer to an allocated buffer.\r
712\r
713 Allocates the number bytes specified by AllocationSize, copies allocationSize bytes\r
714 from Buffer to the newly allocated buffer, and returns a pointer to the allocated\r
715 buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there\r
716 is not enough memory remaining to satisfy the request, then NULL is returned.\r
717\r
718 If Buffer is NULL, then ASSERT().\r
719\r
720 @param AllocationSize The number of bytes to allocate and zero.\r
721 @param Buffer The buffer to copy to the allocated buffer.\r
722\r
723 @return A pointer to the allocated buffer or NULL if allocation fails.\r
724\r
725**/\r
726VOID *\r
727FceAllocateCopyPool (\r
728 IN UINTN AllocationSize,\r
729 IN CONST VOID *Buffer\r
730 );\r
731\r
732/**\r
733 Initializes the head node of a doubly-linked list, and returns the pointer to\r
734 the head node of the doubly-linked list.\r
735\r
736 Initializes the forward and backward links of a new linked list. After\r
737 initializing a linked list with this function, the other linked list\r
738 functions may be used to add and remove nodes from the linked list. It is up\r
739 to the caller of this function to allocate the memory for ListHead.\r
740\r
741 If ListHead is NULL, then ASSERT().\r
742\r
743 @param ListHead A pointer to the head node of a new doubly-linked list.\r
744\r
745 @return ListHead\r
746\r
747**/\r
748LIST_ENTRY *\r
749InitializeListHead (\r
750 IN OUT LIST_ENTRY *ListHead\r
751 );\r
752\r
753/**\r
754 Adds a node to the beginning of a doubly-linked list, and returns the pointer\r
755 to the head node of the doubly-linked list.\r
756\r
757 Adds the node Entry at the beginning of the doubly-linked list denoted by\r
758 ListHead, and returns ListHead.\r
759\r
760 If ListHead is NULL, then ASSERT().\r
761 If Entry is NULL, then ASSERT().\r
762 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
763 InitializeListHead(), then ASSERT().\r
764 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
765 of nodes in ListHead, including the ListHead node, is greater than or\r
766 equal to PcdMaximumLinkedListLength, then ASSERT().\r
767\r
768 @param ListHead A pointer to the head node of a doubly-linked list.\r
769 @param Entry A pointer to a node that is to be inserted at the beginning\r
770 of a doubly-linked list.\r
771\r
772 @return ListHead\r
773\r
774**/\r
775LIST_ENTRY *\r
776InsertHeadList (\r
777 IN OUT LIST_ENTRY *ListHead,\r
778 IN OUT LIST_ENTRY *Entry\r
779 );\r
780\r
781/**\r
782 Adds a node to the end of a doubly-linked list, and returns the pointer to\r
783 the head node of the doubly-linked list.\r
784\r
785 Adds the node Entry to the end of the doubly-linked list denoted by ListHead,\r
786 and returns ListHead.\r
787\r
788 If ListHead is NULL, then ASSERT().\r
789 If Entry is NULL, then ASSERT().\r
790 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
791 InitializeListHead(), then ASSERT().\r
792 If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r
793 of nodes in ListHead, including the ListHead node, is greater than or\r
794 equal to PcdMaximumLinkedListLength, then ASSERT().\r
795\r
796 @param ListHead A pointer to the head node of a doubly-linked list.\r
797 @param Entry A pointer to a node that is to be added at the end of the\r
798 doubly-linked list.\r
799\r
800 @return ListHead\r
801\r
802**/\r
803LIST_ENTRY *\r
804InsertTailList (\r
805 IN OUT LIST_ENTRY *ListHead,\r
806 IN OUT LIST_ENTRY *Entry\r
807 );\r
808\r
809/**\r
810 Retrieves the first node of a doubly-linked list.\r
811\r
812 Returns the first node of a doubly-linked list. List must have been\r
813 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
814 If List is empty, then List is returned.\r
815\r
816 If List is NULL, then ASSERT().\r
817 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
818 InitializeListHead(), then ASSERT().\r
819 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
820 in List, including the List node, is greater than or equal to\r
821 PcdMaximumLinkedListLength, then ASSERT().\r
822\r
823 @param List A pointer to the head node of a doubly-linked list.\r
824\r
825 @return The first node of a doubly-linked list.\r
826 @retval NULL The list is empty.\r
827\r
828**/\r
829LIST_ENTRY *\r
830GetFirstNode (\r
831 IN CONST LIST_ENTRY *List\r
832 );\r
833\r
834/**\r
835 Retrieves the next node of a doubly-linked list.\r
836\r
837 Returns the node of a doubly-linked list that follows Node.\r
838 List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()\r
839 or InitializeListHead(). If List is empty, then List is returned.\r
840\r
841 If List is NULL, then ASSERT().\r
842 If Node is NULL, then ASSERT().\r
843 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
844 InitializeListHead(), then ASSERT().\r
845 If PcdMaximumLinkedListLenth is not zero, and List contains more than\r
846 PcdMaximumLinkedListLenth nodes, then ASSERT().\r
847 If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
848\r
849 @param List A pointer to the head node of a doubly-linked list.\r
850 @param Node A pointer to a node in the doubly-linked list.\r
851\r
852 @return A pointer to the next node if one exists. Otherwise List is returned.\r
853\r
854**/\r
855LIST_ENTRY *\r
856GetNextNode (\r
857 IN CONST LIST_ENTRY *List,\r
858 IN CONST LIST_ENTRY *Node\r
859 );\r
860\r
861/**\r
862 Retrieves the previous node of a doubly-linked list.\r
863\r
864 Returns the node of a doubly-linked list that precedes Node.\r
865 List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()\r
866 or InitializeListHead(). If List is empty, then List is returned.\r
867\r
868 If List is NULL, then ASSERT().\r
869 If Node is NULL, then ASSERT().\r
870 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
871 InitializeListHead(), then ASSERT().\r
872 If PcdMaximumLinkedListLenth is not zero, and List contains more than\r
873 PcdMaximumLinkedListLenth nodes, then ASSERT().\r
874 If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
875\r
876 @param List A pointer to the head node of a doubly-linked list.\r
877 @param Node A pointer to a node in the doubly-linked list.\r
878\r
879 @return A pointer to the previous node if one exists. Otherwise List is returned.\r
880\r
881**/\r
882LIST_ENTRY *\r
883GetPreviousNode (\r
884 IN CONST LIST_ENTRY *List,\r
885 IN CONST LIST_ENTRY *Node\r
886 );\r
887\r
888/**\r
889 Checks to see if a doubly-linked list is empty or not.\r
890\r
891 Checks to see if the doubly-linked list is empty. If the linked list contains\r
892 zero nodes, this function returns TRUE. Otherwise, it returns FALSE.\r
893\r
894 If ListHead is NULL, then ASSERT().\r
895 If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
896 InitializeListHead(), then ASSERT().\r
897 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
898 in List, including the List node, is greater than or equal to\r
899 PcdMaximumLinkedListLength, then ASSERT().\r
900\r
901 @param ListHead A pointer to the head node of a doubly-linked list.\r
902\r
903 @retval TRUE The linked list is empty.\r
904 @retval FALSE The linked list is not empty.\r
905\r
906**/\r
907BOOLEAN\r
908IsListEmpty (\r
909 IN CONST LIST_ENTRY *ListHead\r
910 );\r
911\r
912/**\r
913 Determines if a node in a doubly-linked list is the head node of a the same\r
914 doubly-linked list. This function is typically used to terminate a loop that\r
915 traverses all the nodes in a doubly-linked list starting with the head node.\r
916\r
917 Returns TRUE if Node is equal to List. Returns FALSE if Node is one of the\r
918 nodes in the doubly-linked list specified by List. List must have been\r
919 initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
920\r
921 If List is NULL, then ASSERT().\r
922 If Node is NULL, then ASSERT().\r
923 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(),\r
924 then ASSERT().\r
925 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
926 in List, including the List node, is greater than or equal to\r
927 PcdMaximumLinkedListLength, then ASSERT().\r
928 If PcdVerifyNodeInList is TRUE and Node is not a node in List and Node is not\r
929 equal to List, then ASSERT().\r
930\r
931 @param List A pointer to the head node of a doubly-linked list.\r
932 @param Node A pointer to a node in the doubly-linked list.\r
933\r
934 @retval TRUE Node is the head of the doubly-linked list pointed by List.\r
935 @retval FALSE Node is not the head of the doubly-linked list pointed by List.\r
936\r
937**/\r
938BOOLEAN\r
939IsNull (\r
940 IN CONST LIST_ENTRY *List,\r
941 IN CONST LIST_ENTRY *Node\r
942 );\r
943\r
944/**\r
945 Determines if a node the last node in a doubly-linked list.\r
946\r
947 Returns TRUE if Node is the last node in the doubly-linked list specified by\r
948 List. Otherwise, FALSE is returned. List must have been initialized with\r
949 INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().\r
950\r
951 If List is NULL, then ASSERT().\r
952 If Node is NULL, then ASSERT().\r
953 If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or\r
954 InitializeListHead(), then ASSERT().\r
955 If PcdMaximumLinkedListLenth is not zero, and the number of nodes\r
956 in List, including the List node, is greater than or equal to\r
957 PcdMaximumLinkedListLength, then ASSERT().\r
958 If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().\r
959\r
960 @param List A pointer to the head node of a doubly-linked list.\r
961 @param Node A pointer to a node in the doubly-linked list.\r
962\r
963 @retval TRUE Node is the last node in the linked list.\r
964 @retval FALSE Node is not the last node in the linked list.\r
965\r
966**/\r
967BOOLEAN\r
968IsNodeAtEnd (\r
969 IN CONST LIST_ENTRY *List,\r
970 IN CONST LIST_ENTRY *Node\r
971 );\r
972\r
973/**\r
974 Removes a node from a doubly-linked list, and returns the node that follows\r
975 the removed node.\r
976\r
977 Removes the node Entry from a doubly-linked list. It is up to the caller of\r
978 this function to release the memory used by this node if that is required. On\r
979 exit, the node following Entry in the doubly-linked list is returned. If\r
980 Entry is the only node in the linked list, then the head node of the linked\r
981 list is returned.\r
982\r
983 If Entry is NULL, then ASSERT().\r
984 If Entry is the head node of an empty list, then ASSERT().\r
985 If PcdMaximumLinkedListLength is not zero, and the number of nodes in the\r
986 linked list containing Entry, including the Entry node, is greater than\r
987 or equal to PcdMaximumLinkedListLength, then ASSERT().\r
988\r
989 @param Entry A pointer to a node in a linked list.\r
990\r
991 @return Entry.\r
992\r
993**/\r
994LIST_ENTRY *\r
995RemoveEntryList (\r
996 IN CONST LIST_ENTRY *Entry\r
997 );\r
998\r
999#endif\r