]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
4ea9375a HT |
3 | Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
3eb9473e | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | EfiCommonLib.h\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Light weight lib to support EFI drivers.\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #ifndef _EFI_COMMON_LIB_H_\r | |
23 | #define _EFI_COMMON_LIB_H_\r | |
24 | \r | |
25 | EFI_STATUS\r | |
26 | EfiLibGetSystemConfigurationTable (\r | |
27 | IN EFI_GUID *TableGuid,\r | |
28 | IN OUT VOID **Table\r | |
29 | )\r | |
30 | /*++\r | |
31 | \r | |
32 | Routine Description:\r | |
33 | \r | |
34 | Return the EFI 1.0 System Tabl entry with TableGuid\r | |
35 | \r | |
36 | Arguments:\r | |
37 | \r | |
38 | TableGuid - Name of entry to return in the system table\r | |
39 | Table - Pointer in EFI system table associated with TableGuid\r | |
40 | \r | |
41 | Returns: \r | |
42 | \r | |
43 | EFI_SUCCESS - Table returned;\r | |
44 | EFI_NOT_FOUND - TableGuid not in EFI system table\r | |
45 | \r | |
46 | --*/\r | |
47 | ;\r | |
48 | \r | |
49 | //\r | |
50 | // ASPrint and AvSPrint definitions you must include the specific library\r | |
51 | // to get the expected behavior from the two functions\r | |
52 | // PEI: PeiLib\r | |
53 | // Graphics: Dxe\Graphics\Unicode Dxe\Graphics\ASCII\r | |
54 | // ASCII: Dxe\Print\ASCII\r | |
55 | // Unicode: Dxe\Print\Unicode\r | |
56 | //\r | |
57 | UINTN\r | |
58 | ASPrint (\r | |
59 | OUT CHAR8 *Buffer,\r | |
60 | IN UINTN BufferSize,\r | |
61 | IN CONST CHAR8 *Format,\r | |
62 | ...\r | |
63 | )\r | |
64 | /*++\r | |
65 | \r | |
66 | Routine Description:\r | |
67 | \r | |
68 | Process format and place the results in Buffer for narrow chars.\r | |
69 | \r | |
70 | Arguments:\r | |
71 | \r | |
72 | Buffer - Narrow char buffer to print the results of the parsing of Format into.\r | |
73 | BufferSize - Maximum number of characters to put into buffer.\r | |
74 | Format - Format string\r | |
75 | ... - Vararg list consumed by processing Format.\r | |
76 | \r | |
77 | Returns:\r | |
78 | \r | |
79 | Number of characters printed.\r | |
80 | \r | |
81 | --*/\r | |
82 | ;\r | |
83 | \r | |
84 | UINTN\r | |
85 | AvSPrint (\r | |
86 | OUT CHAR8 *StartOfBuffer,\r | |
87 | IN UINTN StrSize,\r | |
88 | IN CONST CHAR8 *Format,\r | |
89 | IN VA_LIST Marker\r | |
90 | )\r | |
91 | /*++\r | |
92 | \r | |
93 | Routine Description:\r | |
94 | \r | |
95 | Internal implementation of ASPrint. \r | |
96 | Process format and place the results in Buffer for narrow chars.\r | |
97 | \r | |
98 | Arguments:\r | |
99 | \r | |
100 | StartOfBuffer - Narrow char buffer to print the results of the parsing of Format into.\r | |
101 | StrSize - Maximum number of characters to put into buffer.\r | |
102 | FormatString - Format string\r | |
103 | Marker - Vararg list consumed by processing Format.\r | |
104 | \r | |
105 | Returns:\r | |
106 | \r | |
107 | Number of characters printed.\r | |
108 | \r | |
109 | --*/\r | |
110 | ;\r | |
111 | \r | |
112 | //\r | |
113 | // Lib functions which can be used in both PEI and DXE pahse\r | |
114 | //\r | |
115 | EFI_STATUS\r | |
116 | EfiInitializeCommonDriverLib (\r | |
117 | IN EFI_HANDLE ImageHandle,\r | |
118 | IN VOID *SystemTable\r | |
119 | )\r | |
120 | /*++\r | |
121 | \r | |
122 | Routine Description:\r | |
123 | \r | |
124 | Initialize lib function calling phase: PEI or DXE\r | |
125 | \r | |
126 | Arguments:\r | |
127 | \r | |
128 | ImageHandle - The firmware allocated handle for the EFI image.\r | |
129 | \r | |
130 | SystemTable - A pointer to the EFI System Table.\r | |
131 | \r | |
132 | Returns: \r | |
133 | \r | |
134 | EFI_STATUS always returns EFI_SUCCESS\r | |
135 | \r | |
136 | --*/\r | |
137 | ;\r | |
138 | \r | |
139 | EFI_STATUS\r | |
140 | EfiCommonIoRead (\r | |
141 | IN UINT8 Width,\r | |
142 | IN UINTN Address,\r | |
143 | IN UINTN Count,\r | |
144 | IN OUT VOID *Buffer\r | |
145 | )\r | |
146 | /*++\r | |
147 | \r | |
148 | Routine Description:\r | |
149 | \r | |
150 | Io read operation.\r | |
151 | \r | |
152 | Arguments:\r | |
153 | \r | |
154 | Width - Width of read operation\r | |
155 | Address - Start IO address to read\r | |
156 | Count - Read count\r | |
157 | Buffer - Buffer to store result\r | |
158 | \r | |
159 | Returns:\r | |
160 | \r | |
161 | Status code\r | |
162 | \r | |
163 | --*/\r | |
164 | ;\r | |
165 | \r | |
166 | EFI_STATUS\r | |
167 | EfiCommonIoWrite (\r | |
168 | IN UINT8 Width,\r | |
169 | IN UINTN Address,\r | |
170 | IN UINTN Count,\r | |
171 | IN OUT VOID *Buffer\r | |
172 | )\r | |
173 | /*++\r | |
174 | \r | |
175 | Routine Description:\r | |
176 | \r | |
177 | Io write operation.\r | |
178 | \r | |
179 | Arguments:\r | |
180 | \r | |
181 | Width - Width of write operation\r | |
182 | Address - Start IO address to write\r | |
183 | Count - Write count\r | |
184 | Buffer - Buffer to write to the address\r | |
185 | \r | |
186 | Returns:\r | |
187 | \r | |
188 | Status code\r | |
189 | \r | |
190 | --*/\r | |
191 | ;\r | |
192 | \r | |
193 | EFI_STATUS\r | |
194 | EfiCommonPciRead (\r | |
195 | IN UINT8 Width,\r | |
196 | IN UINT64 Address,\r | |
197 | IN UINTN Count,\r | |
198 | IN OUT VOID *Buffer\r | |
199 | )\r | |
200 | /*++\r | |
201 | \r | |
202 | Routine Description:\r | |
203 | \r | |
204 | Pci read operation\r | |
205 | \r | |
206 | Arguments:\r | |
207 | \r | |
208 | Width - Width of PCI read\r | |
209 | Address - PCI address to read\r | |
210 | Count - Read count\r | |
211 | Buffer - Output buffer for the read\r | |
212 | \r | |
213 | Returns:\r | |
214 | \r | |
215 | Status code\r | |
216 | \r | |
217 | --*/\r | |
218 | ;\r | |
219 | \r | |
220 | EFI_STATUS\r | |
221 | EfiCommonPciWrite (\r | |
222 | IN UINT8 Width,\r | |
223 | IN UINT64 Address,\r | |
224 | IN UINTN Count,\r | |
225 | IN OUT VOID *Buffer\r | |
226 | )\r | |
227 | /*++\r | |
228 | \r | |
229 | Routine Description:\r | |
230 | \r | |
231 | Pci write operation\r | |
232 | \r | |
233 | Arguments:\r | |
234 | \r | |
235 | Width - Width of PCI write\r | |
236 | Address - PCI address to write\r | |
237 | Count - Write count\r | |
238 | Buffer - Buffer to write to the address\r | |
239 | \r | |
240 | Returns:\r | |
241 | \r | |
242 | Status code\r | |
243 | \r | |
244 | --*/\r | |
245 | ;\r | |
246 | \r | |
247 | BOOLEAN\r | |
248 | EfiCompareGuid (\r | |
249 | IN EFI_GUID *Guid1,\r | |
250 | IN EFI_GUID *Guid2\r | |
251 | )\r | |
252 | /*++\r | |
253 | \r | |
254 | Routine Description:\r | |
255 | \r | |
256 | Compares two GUIDs\r | |
257 | \r | |
258 | Arguments:\r | |
259 | \r | |
260 | Guid1 - guid to compare\r | |
261 | \r | |
262 | Guid2 - guid to compare\r | |
263 | \r | |
264 | Returns:\r | |
265 | TRUE if Guid1 == Guid2\r | |
266 | FALSE if Guid1 != Guid2\r | |
267 | \r | |
268 | --*/\r | |
269 | ;\r | |
270 | \r | |
271 | VOID\r | |
272 | EfiCommonLibSetMem (\r | |
273 | IN VOID *Buffer,\r | |
274 | IN UINTN Size,\r | |
275 | IN UINT8 Value\r | |
276 | )\r | |
277 | /*++\r | |
278 | \r | |
279 | Routine Description:\r | |
280 | \r | |
281 | Set Buffer to Value for Size bytes.\r | |
282 | \r | |
283 | Arguments:\r | |
284 | \r | |
285 | Buffer - Memory to set.\r | |
286 | \r | |
287 | Size - Number of bytes to set\r | |
288 | \r | |
289 | Value - Value of the set operation.\r | |
290 | \r | |
291 | Returns:\r | |
292 | \r | |
293 | None\r | |
294 | \r | |
295 | --*/\r | |
296 | ;\r | |
297 | \r | |
298 | VOID\r | |
299 | EfiCommonLibCopyMem (\r | |
300 | IN VOID *Destination,\r | |
301 | IN VOID *Source,\r | |
302 | IN UINTN Length\r | |
303 | )\r | |
304 | /*++\r | |
305 | \r | |
306 | Routine Description:\r | |
307 | \r | |
308 | Copy Length bytes from Source to Destination.\r | |
309 | \r | |
310 | Arguments:\r | |
311 | \r | |
312 | Destination - Target of copy\r | |
313 | \r | |
314 | Source - Place to copy from\r | |
315 | \r | |
316 | Length - Number of bytes to copy\r | |
317 | \r | |
318 | Returns:\r | |
319 | \r | |
320 | None\r | |
321 | \r | |
322 | --*/\r | |
323 | ;\r | |
324 | \r | |
325 | INTN\r | |
326 | EfiCompareMem (\r | |
327 | IN VOID *MemOne,\r | |
328 | IN VOID *MemTwo,\r | |
329 | IN UINTN Len\r | |
330 | )\r | |
331 | /*++\r | |
332 | \r | |
333 | Routine Description:\r | |
334 | \r | |
335 | Compares two memory buffers of a given length.\r | |
336 | \r | |
337 | Arguments:\r | |
338 | \r | |
339 | MemOne - First memory buffer\r | |
340 | \r | |
341 | MemTwo - Second memory buffer\r | |
342 | \r | |
343 | Len - Length of Mem1 and Mem2 memory regions to compare\r | |
344 | \r | |
345 | Returns:\r | |
346 | \r | |
347 | = 0 if MemOne == MemTwo\r | |
348 | \r | |
349 | > 0 if MemOne > MemTwo\r | |
350 | \r | |
351 | < 0 if MemOne < MemTwo\r | |
352 | \r | |
353 | --*/\r | |
354 | ;\r | |
355 | \r | |
356 | VOID\r | |
357 | EfiCommonLibZeroMem (\r | |
358 | IN VOID *Buffer,\r | |
359 | IN UINTN Size\r | |
360 | )\r | |
361 | /*++\r | |
362 | \r | |
363 | Routine Description:\r | |
364 | \r | |
365 | Set Buffer to 0 for Size bytes.\r | |
366 | \r | |
367 | Arguments:\r | |
368 | \r | |
369 | Buffer - Memory to set.\r | |
370 | \r | |
371 | Size - Number of bytes to set\r | |
372 | \r | |
373 | Returns:\r | |
374 | \r | |
375 | None\r | |
376 | \r | |
377 | --*/\r | |
378 | ;\r | |
379 | \r | |
380 | //\r | |
381 | // Min Max\r | |
382 | //\r | |
383 | #define EFI_MIN(a, b) (((a) < (b)) ? (a) : (b))\r | |
384 | #define EFI_MAX(a, b) (((a) > (b)) ? (a) : (b))\r | |
385 | \r | |
386 | //\r | |
387 | // Align a pointer. The pointer represented by ptr is aligned to the bound.\r | |
388 | // The resulting pointer is always equal or greater (by no more than bound-1)\r | |
389 | // than the ptr. I.e., if the ptr is already aligned, the result will be equal to ptr.\r | |
390 | // Valid values for bound are powers of two: 2, 4, 8, 16, 32 etc.\r | |
391 | // The returned pointer is VOID* this assignment-compatible with all pointer types.\r | |
392 | //\r | |
393 | #define EFI_ALIGN(ptr, bound) ((VOID *) (((UINTN) (ptr) + ((UINTN) (bound) - 1)) &~((UINTN) (bound) - 1)))\r | |
394 | \r | |
395 | //\r | |
396 | // Alignment tests.\r | |
397 | //\r | |
398 | #define EFI_UINTN_ALIGN_MASK (sizeof (UINTN) - 1)\r | |
399 | #define EFI_UINTN_ALIGNED(ptr) (((UINTN) (ptr)) & EFI_UINTN_ALIGN_MASK)\r | |
400 | \r | |
401 | //\r | |
402 | // Integer division with rounding to the nearest rather than truncating.\r | |
403 | // For example 8/3=2 but EFI_IDIV_ROUND(8,3)=3. 1/3=0 and EFI_IDIV_ROUND(1,3)=0.\r | |
404 | // A half is rounded up e.g., EFI_IDIV_ROUND(1,2)=1 but 1/2=0.\r | |
405 | //\r | |
406 | #define EFI_IDIV_ROUND(r, s) ((r) / (s) + (((2 * ((r) % (s))) < (s)) ? 0 : 1))\r | |
407 | \r | |
408 | //\r | |
409 | // ReportStatusCode.c init\r | |
410 | //\r | |
411 | VOID *\r | |
412 | EfiConstructStatusCodeData (\r | |
413 | IN UINT16 DataSize,\r | |
414 | IN EFI_GUID *TypeGuid,\r | |
415 | IN OUT EFI_STATUS_CODE_DATA *Data\r | |
416 | )\r | |
417 | /*++\r | |
418 | \r | |
419 | Routine Description:\r | |
420 | \r | |
421 | Construct stanader header for optional data passed into ReportStatusCode\r | |
422 | \r | |
423 | Arguments:\r | |
424 | \r | |
425 | DataSize - Size of optional data. Does not include EFI_STATUS_CODE_DATA header\r | |
426 | TypeGuid - GUID to place in EFI_STATUS_CODE_DATA\r | |
427 | Data - Buffer to use.\r | |
428 | \r | |
429 | Returns:\r | |
430 | \r | |
431 | Return pointer to Data buffer pointing past the end of EFI_STATUS_CODE_DATA\r | |
432 | \r | |
433 | --*/\r | |
434 | ;\r | |
435 | \r | |
436 | EFI_STATUS\r | |
437 | EfiDebugVPrintWorker (\r | |
438 | IN UINTN ErrorLevel,\r | |
439 | IN CHAR8 *Format,\r | |
440 | IN VA_LIST Marker,\r | |
441 | IN UINTN BufferSize,\r | |
442 | IN OUT VOID *Buffer\r | |
443 | )\r | |
444 | /*++\r | |
445 | \r | |
446 | Routine Description:\r | |
447 | \r | |
448 | Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT\r | |
449 | information. If Error Logging hub is not loaded do nothing.\r | |
450 | \r | |
451 | We use UINT64 buffers due to IPF alignment concerns.\r | |
452 | \r | |
453 | Arguments:\r | |
454 | \r | |
455 | ErrorLevel - If error level is set do the debug print.\r | |
456 | \r | |
457 | Format - String to use for the print, followed by Print arguments.\r | |
458 | \r | |
459 | Marker - VarArgs\r | |
460 | \r | |
461 | BufferSize - Size of Buffer.\r | |
462 | \r | |
463 | Buffer - Caller allocated buffer, contains ReportStatusCode extended data\r | |
464 | \r | |
465 | Returns:\r | |
466 | \r | |
467 | Status code\r | |
468 | \r | |
469 | --*/\r | |
470 | ;\r | |
471 | \r | |
472 | EFI_STATUS\r | |
473 | EfiDebugAssertWorker (\r | |
474 | IN CHAR8 *FileName,\r | |
475 | IN INTN LineNumber,\r | |
476 | IN CHAR8 *Description,\r | |
477 | IN UINTN BufferSize,\r | |
478 | IN OUT VOID *Buffer\r | |
479 | )\r | |
480 | /*++\r | |
481 | \r | |
482 | Routine Description:\r | |
483 | \r | |
484 | Worker function for ASSERT (). If Error Logging hub is loaded log ASSERT\r | |
485 | information. If Error Logging hub is not loaded DEADLOOP ().\r | |
486 | \r | |
487 | We use UINT64 buffers due to IPF alignment concerns.\r | |
488 | \r | |
489 | Arguments:\r | |
490 | \r | |
491 | FileName - File name of failing routine.\r | |
492 | \r | |
493 | LineNumber - Line number of failing ASSERT().\r | |
494 | \r | |
495 | Description - Description, usually the assertion,\r | |
496 | \r | |
497 | BufferSize - Size of Buffer.\r | |
498 | \r | |
499 | Buffer - Caller allocated buffer, contains ReportStatusCode extendecd data\r | |
500 | \r | |
501 | Returns:\r | |
502 | \r | |
503 | Status code\r | |
504 | \r | |
505 | --*/\r | |
506 | ;\r | |
507 | \r | |
508 | BOOLEAN\r | |
509 | ReportStatusCodeExtractAssertInfo (\r | |
510 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
511 | IN EFI_STATUS_CODE_VALUE Value,\r | |
512 | IN EFI_STATUS_CODE_DATA *Data,\r | |
513 | OUT CHAR8 **Filename,\r | |
514 | OUT CHAR8 **Description,\r | |
515 | OUT UINT32 *LineNumber\r | |
516 | )\r | |
517 | /*++\r | |
518 | \r | |
519 | Routine Description:\r | |
520 | \r | |
521 | Extract assert information from status code data.\r | |
522 | \r | |
523 | Arguments:\r | |
524 | \r | |
525 | CodeType - Code type\r | |
526 | Value - Code value\r | |
527 | Data - Optional data associated with this status code.\r | |
528 | Filename - Filename extracted from Data\r | |
529 | Description - Description extracted from Data\r | |
530 | LineNumber - Line number extracted from Data\r | |
531 | \r | |
532 | Returns:\r | |
533 | \r | |
534 | TRUE - Successfully extracted\r | |
535 | \r | |
536 | FALSE - Extraction failed\r | |
537 | \r | |
538 | --*/\r | |
539 | ;\r | |
540 | \r | |
541 | BOOLEAN\r | |
542 | ReportStatusCodeExtractDebugInfo (\r | |
543 | IN EFI_STATUS_CODE_DATA *Data,\r | |
544 | OUT UINT32 *ErrorLevel,\r | |
545 | OUT VA_LIST *Marker,\r | |
546 | OUT CHAR8 **Format\r | |
547 | )\r | |
548 | /*++\r | |
549 | \r | |
550 | Routine Description:\r | |
551 | \r | |
552 | Extract debug information from status code data.\r | |
553 | \r | |
554 | Arguments:\r | |
555 | \r | |
556 | Data - Optional data associated with status code.\r | |
557 | ErrorLevel - Error level extracted from Data\r | |
558 | Marker - VA_LIST extracted from Data\r | |
559 | Format - Format string extracted from Data\r | |
560 | \r | |
561 | Returns:\r | |
562 | \r | |
563 | TRUE - Successfully extracted\r | |
564 | \r | |
565 | FALSE - Extraction failed\r | |
566 | \r | |
567 | --*/\r | |
568 | ;\r | |
569 | \r | |
570 | BOOLEAN\r | |
571 | CodeTypeToPostCode (\r | |
572 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
573 | IN EFI_STATUS_CODE_VALUE Value,\r | |
574 | OUT UINT8 *PostCode\r | |
575 | )\r | |
576 | /*++\r | |
577 | \r | |
578 | Routine Description:\r | |
579 | \r | |
580 | Convert code value to an 8 bit post code\r | |
581 | \r | |
582 | Arguments:\r | |
583 | \r | |
584 | CodeType - Code type\r | |
585 | Value - Code value\r | |
586 | PostCode - Post code as output\r | |
587 | \r | |
588 | Returns:\r | |
589 | \r | |
590 | TRUE - Successfully converted\r | |
591 | \r | |
592 | FALSE - Convertion failed\r | |
593 | \r | |
594 | --*/\r | |
595 | ;\r | |
596 | \r | |
597 | //\r | |
598 | // math.c\r | |
599 | //\r | |
600 | UINT64\r | |
601 | MultU64x32 (\r | |
602 | IN UINT64 Multiplicand,\r | |
603 | IN UINTN Multiplier\r | |
604 | )\r | |
605 | /*++ \r | |
606 | \r | |
607 | Routine Description:\r | |
608 | \r | |
609 | This routine allows a 64 bit value to be multiplied with a 32 bit \r | |
610 | value returns 64bit result.\r | |
611 | No checking if the result is greater than 64bits\r | |
612 | \r | |
613 | Arguments:\r | |
614 | \r | |
615 | Multiplicand - multiplicand\r | |
616 | Multiplier - multiplier\r | |
617 | \r | |
618 | Returns:\r | |
619 | \r | |
620 | Multiplicand * Multiplier\r | |
621 | \r | |
622 | --*/\r | |
623 | ;\r | |
624 | \r | |
625 | UINT64\r | |
626 | DivU64x32 (\r | |
627 | IN UINT64 Dividend,\r | |
628 | IN UINTN Divisor,\r | |
629 | OUT UINTN *Remainder OPTIONAL\r | |
630 | )\r | |
631 | /*++\r | |
632 | \r | |
633 | Routine Description:\r | |
634 | \r | |
635 | This routine allows a 64 bit value to be divided with a 32 bit value returns \r | |
636 | 64bit result and the Remainder.\r | |
637 | \r | |
638 | Arguments:\r | |
639 | \r | |
640 | Dividend - dividend\r | |
641 | Divisor - divisor\r | |
642 | Remainder - buffer for remainder\r | |
643 | \r | |
644 | Returns:\r | |
645 | \r | |
646 | Dividend / Divisor\r | |
647 | Remainder = Dividend mod Divisor\r | |
648 | \r | |
649 | --*/\r | |
650 | ;\r | |
651 | \r | |
652 | UINT64\r | |
653 | RShiftU64 (\r | |
654 | IN UINT64 Operand,\r | |
655 | IN UINTN Count\r | |
656 | )\r | |
657 | /*++\r | |
658 | \r | |
659 | Routine Description:\r | |
660 | \r | |
661 | This routine allows a 64 bit value to be right shifted by 32 bits and returns the \r | |
662 | shifted value.\r | |
663 | Count is valid up 63. (Only Bits 0-5 is valid for Count)\r | |
664 | \r | |
665 | Arguments:\r | |
666 | \r | |
667 | Operand - Value to be shifted\r | |
668 | Count - Number of times to shift right.\r | |
669 | \r | |
670 | Returns:\r | |
671 | \r | |
672 | Value shifted right identified by the Count.\r | |
673 | \r | |
674 | --*/\r | |
675 | ;\r | |
676 | \r | |
677 | UINT64\r | |
678 | LShiftU64 (\r | |
679 | IN UINT64 Operand,\r | |
680 | IN UINTN Count\r | |
681 | )\r | |
682 | /*++\r | |
683 | \r | |
684 | Routine Description:\r | |
685 | \r | |
686 | This routine allows a 64 bit value to be left shifted by 32 bits and \r | |
687 | returns the shifted value.\r | |
688 | Count is valid up 63. (Only Bits 0-5 is valid for Count)\r | |
689 | \r | |
690 | Arguments:\r | |
691 | \r | |
692 | Operand - Value to be shifted\r | |
693 | Count - Number of times to shift left.\r | |
694 | \r | |
695 | Returns:\r | |
696 | \r | |
697 | Value shifted left identified by the Count.\r | |
698 | \r | |
699 | --*/\r | |
700 | ;\r | |
701 | \r | |
702 | UINT64\r | |
703 | Power10U64 (\r | |
704 | IN UINT64 Operand,\r | |
705 | IN UINTN Power\r | |
706 | )\r | |
707 | /*++\r | |
708 | \r | |
709 | Routine Description:\r | |
710 | \r | |
711 | Raise 10 to the power of Power, and multiply the result with Operand\r | |
712 | \r | |
713 | Arguments:\r | |
714 | \r | |
715 | Operand - multiplicand\r | |
716 | Power - power\r | |
717 | \r | |
718 | Returns:\r | |
719 | \r | |
720 | Operand * 10 ^ Power\r | |
721 | \r | |
722 | --*/\r | |
723 | ;\r | |
724 | \r | |
725 | UINT8\r | |
726 | Log2 (\r | |
727 | IN UINT64 Operand\r | |
728 | )\r | |
729 | /*++\r | |
730 | \r | |
731 | Routine Description:\r | |
732 | \r | |
733 | Calculates and floors logarithms based on 2\r | |
734 | \r | |
735 | Arguments:\r | |
736 | \r | |
737 | Operand - value to calculate logarithm\r | |
738 | \r | |
739 | Returns:\r | |
740 | \r | |
741 | The largest integer that is less than or equal\r | |
742 | to the logarithm of Operand based on 2 \r | |
743 | \r | |
744 | --*/\r | |
745 | ;\r | |
746 | \r | |
747 | UINT64\r | |
748 | GetPowerOfTwo (\r | |
749 | IN UINT64 Input\r | |
750 | )\r | |
751 | /*++\r | |
752 | \r | |
753 | Routine Description:\r | |
754 | \r | |
755 | Calculates the largest integer that is both \r | |
756 | a power of two and less than Input\r | |
757 | \r | |
758 | Arguments:\r | |
759 | \r | |
760 | Input - value to calculate power of two\r | |
761 | \r | |
762 | Returns:\r | |
763 | \r | |
764 | the largest integer that is both a power of \r | |
765 | two and less than Input\r | |
766 | \r | |
767 | --*/\r | |
768 | ;\r | |
769 | \r | |
770 | //\r | |
771 | // Unicode String primatives\r | |
772 | //\r | |
773 | VOID\r | |
774 | EfiStrCpy (\r | |
775 | IN CHAR16 *Destination,\r | |
776 | IN CHAR16 *Source\r | |
777 | )\r | |
778 | /*++\r | |
779 | \r | |
780 | Routine Description:\r | |
781 | Copy the Unicode string Source to Destination.\r | |
782 | \r | |
783 | Arguments:\r | |
784 | Destination - Location to copy string\r | |
785 | Source - String to copy\r | |
786 | \r | |
787 | Returns:\r | |
788 | NONE\r | |
789 | \r | |
790 | --*/\r | |
791 | ;\r | |
792 | \r | |
793 | VOID\r | |
794 | EfiStrnCpy (\r | |
795 | OUT CHAR16 *Dst,\r | |
796 | IN CHAR16 *Src,\r | |
797 | IN UINTN Length\r | |
798 | )\r | |
799 | /*++\r | |
800 | \r | |
801 | Routine Description:\r | |
802 | Copy a string from source to destination\r | |
803 | \r | |
804 | Arguments:\r | |
805 | Dst Destination string\r | |
806 | Src Source string\r | |
807 | Length Length of destination string\r | |
808 | \r | |
809 | Returns:\r | |
810 | \r | |
811 | --*/\r | |
812 | ;\r | |
813 | \r | |
814 | UINTN\r | |
815 | EfiStrLen (\r | |
816 | IN CHAR16 *String\r | |
817 | )\r | |
818 | /*++\r | |
819 | \r | |
820 | Routine Description:\r | |
821 | Return the number of Unicode characters in String. This is not the same as\r | |
822 | the length of the string in bytes.\r | |
823 | \r | |
824 | Arguments:\r | |
825 | String - String to process\r | |
826 | \r | |
827 | Returns:\r | |
828 | Number of Unicode characters in String\r | |
829 | \r | |
830 | --*/\r | |
831 | ;\r | |
832 | \r | |
833 | UINTN\r | |
834 | EfiStrSize (\r | |
835 | IN CHAR16 *String\r | |
836 | )\r | |
837 | /*++\r | |
838 | \r | |
839 | Routine Description:\r | |
840 | Return the number bytes in the Unicode String. This is not the same as\r | |
841 | the length of the string in characters. The string size includes the NULL\r | |
842 | \r | |
843 | Arguments:\r | |
844 | String - String to process\r | |
845 | \r | |
846 | Returns:\r | |
847 | Number of bytes in String\r | |
848 | \r | |
849 | --*/\r | |
850 | ;\r | |
851 | \r | |
852 | INTN\r | |
853 | EfiStrCmp (\r | |
854 | IN CHAR16 *String,\r | |
855 | IN CHAR16 *String2\r | |
856 | )\r | |
857 | /*++\r | |
858 | \r | |
859 | Routine Description:\r | |
860 | Return the alphabetic relationship between two stirngs. \r | |
861 | \r | |
862 | Arguments:\r | |
863 | String - Compare to String2\r | |
864 | \r | |
865 | String2 - Compare to String\r | |
866 | \r | |
867 | Returns:\r | |
868 | 0 - Identical\r | |
869 | \r | |
870 | > 0 - String is alphabeticly greater than String2\r | |
871 | \r | |
872 | < 0 - String is alphabeticly less than String2\r | |
873 | \r | |
874 | --*/\r | |
875 | ;\r | |
876 | \r | |
877 | INTN\r | |
878 | EfiStrnCmp (\r | |
879 | IN CHAR16 *String,\r | |
880 | IN CHAR16 *String2,\r | |
881 | IN UINTN Length\r | |
882 | )\r | |
883 | /*++\r | |
884 | \r | |
885 | Routine Description:\r | |
886 | This function compares the Unicode string String to the Unicode\r | |
887 | string String2 for len characters. If the first len characters\r | |
888 | of String is identical to the first len characters of String2,\r | |
889 | then 0 is returned. If substring of String sorts lexicographically\r | |
890 | after String2, the function returns a number greater than 0. If\r | |
891 | substring of String sorts lexicographically before String2, the\r | |
892 | function returns a number less than 0.\r | |
893 | \r | |
894 | Arguments:\r | |
895 | String - Compare to String2\r | |
896 | String2 - Compare to String\r | |
897 | Length - Number of Unicode characters to compare\r | |
898 | \r | |
899 | Returns:\r | |
900 | 0 - The substring of String and String2 is identical.\r | |
901 | > 0 - The substring of String sorts lexicographically after String2\r | |
902 | < 0 - The substring of String sorts lexicographically before String2\r | |
903 | \r | |
904 | --*/\r | |
905 | ;\r | |
906 | \r | |
907 | VOID\r | |
908 | EfiStrCat (\r | |
909 | IN CHAR16 *Destination,\r | |
910 | IN CHAR16 *Source\r | |
911 | )\r | |
912 | /*++\r | |
913 | \r | |
914 | Routine Description:\r | |
915 | Concatinate Source on the end of Destination\r | |
916 | \r | |
917 | Arguments:\r | |
918 | Destination - String to added to the end of.\r | |
919 | Source - String to concatinate.\r | |
920 | \r | |
921 | Returns:\r | |
922 | NONE\r | |
923 | \r | |
924 | --*/\r | |
925 | ;\r | |
926 | \r | |
927 | VOID\r | |
928 | EfiStrnCat (\r | |
929 | IN CHAR16 *Dest,\r | |
930 | IN CHAR16 *Src,\r | |
931 | IN UINTN Length\r | |
932 | )\r | |
933 | /*++\r | |
934 | \r | |
935 | Routine Description:\r | |
936 | Concatinate Source on the end of Destination\r | |
937 | \r | |
938 | Arguments:\r | |
939 | Dst Destination string\r | |
940 | Src Source string\r | |
941 | Length Length of destination string\r | |
942 | \r | |
943 | Returns:\r | |
944 | \r | |
945 | --*/\r | |
946 | ;\r | |
947 | \r | |
948 | UINTN\r | |
949 | EfiAsciiStrLen (\r | |
950 | IN CHAR8 *String\r | |
951 | )\r | |
952 | /*++\r | |
953 | \r | |
954 | Routine Description:\r | |
955 | Return the number of Ascii characters in String. This is not the same as\r | |
956 | the length of the string in bytes.\r | |
957 | \r | |
958 | Arguments:\r | |
959 | String - String to process\r | |
960 | \r | |
961 | Returns:\r | |
962 | Number of Unicode characters in String\r | |
963 | \r | |
964 | --*/\r | |
965 | ;\r | |
966 | \r | |
967 | CHAR8 *\r | |
968 | EfiAsciiStrCpy (\r | |
969 | IN CHAR8 *Destination,\r | |
970 | IN CHAR8 *Source\r | |
971 | )\r | |
972 | /*++\r | |
973 | \r | |
974 | Routine Description:\r | |
975 | Copy the Ascii string Source to Destination.\r | |
976 | \r | |
977 | Arguments:\r | |
978 | Destination - Location to copy string\r | |
979 | Source - String to copy\r | |
980 | \r | |
981 | Returns:\r | |
982 | Pointer just pass the end of Destination\r | |
983 | \r | |
984 | --*/\r | |
985 | ;\r | |
986 | \r | |
987 | VOID\r | |
988 | EfiAsciiStrnCpy (\r | |
989 | OUT CHAR8 *Dst,\r | |
990 | IN CHAR8 *Src,\r | |
991 | IN UINTN Length\r | |
992 | )\r | |
993 | /*++\r | |
994 | \r | |
995 | Routine Description:\r | |
996 | Copy the Ascii string from source to destination\r | |
997 | \r | |
998 | Arguments:\r | |
999 | Dst Destination string\r | |
1000 | Src Source string\r | |
1001 | Length Length of destination string\r | |
1002 | \r | |
1003 | Returns:\r | |
1004 | \r | |
1005 | --*/\r | |
1006 | ;\r | |
1007 | \r | |
1008 | UINTN\r | |
1009 | EfiAsciiStrSize (\r | |
1010 | IN CHAR8 *String\r | |
1011 | )\r | |
1012 | /*++\r | |
1013 | \r | |
1014 | Routine Description:\r | |
1015 | Return the number bytes in the Ascii String. This is not the same as\r | |
1016 | the length of the string in characters. The string size includes the NULL\r | |
1017 | \r | |
1018 | Arguments:\r | |
1019 | String - String to process\r | |
1020 | \r | |
1021 | Returns:\r | |
1022 | Number of bytes in String\r | |
1023 | \r | |
1024 | --*/\r | |
1025 | ;\r | |
1026 | \r | |
1027 | \r | |
1028 | INTN\r | |
1029 | EfiAsciiStrCmp (\r | |
1030 | IN CHAR8 *String,\r | |
1031 | IN CHAR8 *String2\r | |
1032 | )\r | |
1033 | /*++\r | |
1034 | \r | |
1035 | Routine Description:\r | |
1036 | Compare the Ascii string pointed by String to the string pointed by String2. \r | |
1037 | \r | |
1038 | Arguments:\r | |
1039 | String - String to process\r | |
1040 | \r | |
1041 | String2 - The other string to process\r | |
1042 | \r | |
1043 | Returns:\r | |
1044 | Return a positive integer if String is lexicall greater than String2; Zero if \r | |
1045 | the two strings are identical; and a negative interger if String is lexically \r | |
1046 | less than String2.\r | |
1047 | --*/\r | |
1048 | ;\r | |
1049 | \r | |
1050 | INTN\r | |
1051 | EfiAsciiStrnCmp (\r | |
1052 | IN CHAR8 *String,\r | |
1053 | IN CHAR8 *String2,\r | |
1054 | IN UINTN Length\r | |
1055 | )\r | |
1056 | /*++\r | |
1057 | \r | |
1058 | Routine Description:\r | |
1059 | This function compares the ASCII string String to the ASCII\r | |
1060 | string String2 for len characters. If the first len characters\r | |
1061 | of String is identical to the first len characters of String2,\r | |
1062 | then 0 is returned. If substring of String sorts lexicographically\r | |
1063 | after String2, the function returns a number greater than 0. If\r | |
1064 | substring of String sorts lexicographically before String2, the\r | |
1065 | function returns a number less than 0.\r | |
1066 | \r | |
1067 | Arguments:\r | |
1068 | String - Compare to String2\r | |
1069 | String2 - Compare to String\r | |
1070 | Length - Number of ASCII characters to compare\r | |
1071 | \r | |
1072 | Returns:\r | |
1073 | 0 - The substring of String and String2 is identical.\r | |
1074 | > 0 - The substring of String sorts lexicographically after String2\r | |
1075 | < 0 - The substring of String sorts lexicographically before String2\r | |
1076 | \r | |
1077 | --*/\r | |
1078 | ;\r | |
1079 | \r | |
1080 | VOID\r | |
1081 | EfiAsciiStrCat (\r | |
1082 | IN CHAR8 *Destination,\r | |
1083 | IN CHAR8 *Source\r | |
1084 | )\r | |
1085 | /*++\r | |
1086 | \r | |
1087 | Routine Description:\r | |
1088 | Concatinate Source on the end of Destination\r | |
1089 | \r | |
1090 | Arguments:\r | |
1091 | Destination - String to added to the end of.\r | |
1092 | Source - String to concatinate.\r | |
1093 | \r | |
1094 | Returns:\r | |
1095 | NONE\r | |
1096 | \r | |
1097 | --*/\r | |
1098 | ;\r | |
1099 | \r | |
1100 | VOID\r | |
1101 | EfiAsciiStrnCat (\r | |
1102 | IN CHAR8 *Destination,\r | |
1103 | IN CHAR8 *Source,\r | |
1104 | IN UINTN Length\r | |
1105 | )\r | |
1106 | /*++\r | |
1107 | \r | |
1108 | Routine Description:\r | |
1109 | Concatinate Source on the end of Destination\r | |
1110 | \r | |
1111 | Arguments:\r | |
1112 | Destination - String to added to the end of.\r | |
1113 | Source - String to concatinate.\r | |
1114 | \r | |
1115 | Returns:\r | |
1116 | NONE\r | |
1117 | \r | |
1118 | --*/\r | |
1119 | ;\r | |
1120 | \r | |
1121 | //\r | |
1122 | // Print primitives\r | |
1123 | //\r | |
1124 | #define LEFT_JUSTIFY 0x01\r | |
1125 | #define PREFIX_SIGN 0x02\r | |
1126 | #define PREFIX_BLANK 0x04\r | |
1127 | #define COMMA_TYPE 0x08\r | |
1128 | #define LONG_TYPE 0x10\r | |
1129 | #define PREFIX_ZERO 0x20\r | |
1130 | \r | |
1131 | //\r | |
1132 | // Length of temp string buffer to store value string.\r | |
1133 | //\r | |
1134 | #define CHARACTER_NUMBER_FOR_VALUE 30\r | |
1135 | \r | |
1136 | UINTN\r | |
1137 | EfiValueToHexStr (\r | |
1138 | IN OUT CHAR16 *Buffer,\r | |
1139 | IN UINT64 Value,\r | |
1140 | IN UINTN Flags,\r | |
1141 | IN UINTN Width\r | |
1142 | )\r | |
1143 | /*++\r | |
1144 | \r | |
1145 | Routine Description:\r | |
1146 | \r | |
1147 | VSPrint worker function that prints a Value as a hex number in Buffer\r | |
1148 | \r | |
1149 | Arguments:\r | |
1150 | \r | |
1151 | Buffer - Location to place ascii hex string of Value.\r | |
1152 | \r | |
1153 | Value - Hex value to convert to a string in Buffer.\r | |
1154 | \r | |
1155 | Flags - Flags to use in printing Hex string, see file header for details.\r | |
1156 | \r | |
1157 | Width - Width of hex value.\r | |
1158 | \r | |
1159 | Returns: \r | |
1160 | \r | |
1161 | Number of characters printed. \r | |
1162 | \r | |
1163 | --*/\r | |
1164 | ;\r | |
1165 | \r | |
1166 | UINTN\r | |
1167 | EfiValueToString (\r | |
1168 | IN OUT CHAR16 *Buffer,\r | |
1169 | IN INT64 Value,\r | |
1170 | IN UINTN Flags,\r | |
1171 | IN UINTN Width\r | |
1172 | )\r | |
1173 | /*++\r | |
1174 | \r | |
1175 | Routine Description:\r | |
1176 | \r | |
1177 | VSPrint worker function that prints a Value as a decimal number in Buffer\r | |
1178 | \r | |
1179 | Arguments:\r | |
1180 | \r | |
1181 | Buffer - Location to place ascii decimal number string of Value.\r | |
1182 | \r | |
1183 | Value - Decimal value to convert to a string in Buffer.\r | |
1184 | \r | |
1185 | Flags - Flags to use in printing decimal string, see file header for details.\r | |
1186 | \r | |
1187 | Width - Width of hex value.\r | |
1188 | \r | |
1189 | Returns: \r | |
1190 | \r | |
1191 | Number of characters printed. \r | |
1192 | \r | |
1193 | --*/\r | |
1194 | ;\r | |
1195 | \r | |
1196 | BOOLEAN\r | |
1197 | IsHexDigit (\r | |
1198 | OUT UINT8 *Digit,\r | |
1199 | IN CHAR16 Char\r | |
1200 | )\r | |
1201 | /*++\r | |
1202 | \r | |
1203 | Routine Description:\r | |
1204 | Determines if a Unicode character is a hexadecimal digit.\r | |
1205 | The test is case insensitive.\r | |
1206 | \r | |
1207 | Arguments:\r | |
1208 | Digit - Pointer to byte that receives the value of the hex character.\r | |
1209 | Char - Unicode character to test.\r | |
1210 | \r | |
1211 | Returns:\r | |
1212 | TRUE - If the character is a hexadecimal digit.\r | |
1213 | FALSE - Otherwise.\r | |
1214 | \r | |
1215 | --*/\r | |
1216 | ;\r | |
1217 | \r | |
1218 | CHAR16\r | |
1219 | NibbleToHexChar (\r | |
1220 | UINT8 Nibble\r | |
1221 | )\r | |
1222 | /*++\r | |
1223 | \r | |
1224 | Routine Description:\r | |
1225 | Converts the low nibble of a byte to hex unicode character.\r | |
1226 | \r | |
1227 | Arguments:\r | |
1228 | Nibble - lower nibble of a byte.\r | |
1229 | \r | |
1230 | Returns:\r | |
1231 | Hex unicode character.\r | |
1232 | \r | |
1233 | --*/\r | |
1234 | ;\r | |
1235 | \r | |
1236 | EFI_STATUS\r | |
1237 | HexStringToBuf (\r | |
1238 | IN OUT UINT8 *Buf,\r | |
1239 | IN OUT UINTN *Len,\r | |
1240 | IN CHAR16 *Str,\r | |
1241 | OUT UINTN *ConvertedStrLen OPTIONAL\r | |
1242 | )\r | |
1243 | /*++\r | |
1244 | \r | |
1245 | Routine Description:\r | |
1246 | Converts Unicode string to binary buffer.\r | |
1247 | The conversion may be partial.\r | |
1248 | The first character in the string that is not hex digit stops the conversion.\r | |
1249 | At a minimum, any blob of data could be represented as a hex string.\r | |
1250 | \r | |
1251 | Arguments:\r | |
1252 | Buf - Pointer to buffer that receives the data.\r | |
1253 | Len - Length in bytes of the buffer to hold converted data.\r | |
1254 | If routine return with EFI_SUCCESS, containing length of converted data.\r | |
1255 | If routine return with EFI_BUFFER_TOO_SMALL, containg length of buffer desired.\r | |
1256 | Str - String to be converted from.\r | |
1257 | ConvertedStrLen - Length of the Hex String consumed.\r | |
1258 | \r | |
1259 | Returns:\r | |
1260 | EFI_SUCCESS: Routine Success.\r | |
1261 | EFI_BUFFER_TOO_SMALL: The buffer is too small to hold converted data.\r | |
1262 | EFI_\r | |
1263 | \r | |
1264 | --*/\r | |
1265 | ;\r | |
1266 | \r | |
1267 | EFI_STATUS\r | |
1268 | BufToHexString (\r | |
1269 | IN OUT CHAR16 *Str,\r | |
1270 | IN OUT UINTN *HexStringBufferLength,\r | |
1271 | IN UINT8 *Buf,\r | |
1272 | IN UINTN Len\r | |
1273 | )\r | |
1274 | /*++\r | |
1275 | \r | |
1276 | Routine Description:\r | |
1277 | Converts binary buffer to Unicode string.\r | |
1278 | At a minimum, any blob of data could be represented as a hex string.\r | |
1279 | \r | |
1280 | Arguments:\r | |
1281 | Str - Pointer to the string.\r | |
1282 | HexStringBufferLength - Length in bytes of buffer to hold the hex string. Includes tailing '\0' character.\r | |
1283 | If routine return with EFI_SUCCESS, containing length of hex string buffer.\r | |
1284 | If routine return with EFI_BUFFER_TOO_SMALL, containg length of hex string buffer desired.\r | |
1285 | Buf - Buffer to be converted from.\r | |
1286 | Len - Length in bytes of the buffer to be converted.\r | |
1287 | \r | |
1288 | Returns:\r | |
1289 | EFI_SUCCESS: Routine success.\r | |
1290 | EFI_BUFFER_TOO_SMALL: The hex string buffer is too small.\r | |
1291 | \r | |
1292 | --*/\r | |
1293 | ;\r | |
1294 | \r | |
1295 | VOID\r | |
1296 | EfiStrTrim (\r | |
1297 | IN OUT CHAR16 *str,\r | |
1298 | IN CHAR16 CharC\r | |
1299 | )\r | |
1300 | /*++\r | |
1301 | \r | |
1302 | Routine Description:\r | |
1303 | \r | |
1304 | Removes (trims) specified leading and trailing characters from a string.\r | |
1305 | \r | |
1306 | Arguments: \r | |
1307 | \r | |
1308 | str - Pointer to the null-terminated string to be trimmed. On return, \r | |
1309 | str will hold the trimmed string. \r | |
1310 | CharC - Character will be trimmed from str.\r | |
1311 | \r | |
1312 | Returns:\r | |
1313 | \r | |
1314 | None\r | |
1315 | \r | |
1316 | --*/\r | |
1317 | ;\r | |
1318 | CHAR16*\r | |
1319 | EfiStrStr (\r | |
1320 | IN CHAR16 *String,\r | |
1321 | IN CHAR16 *StrCharSet\r | |
1322 | )\r | |
1323 | /*++\r | |
1324 | \r | |
1325 | Routine Description:\r | |
1326 | \r | |
1327 | Find a substring.\r | |
1328 | \r | |
1329 | Arguments: \r | |
1330 | \r | |
1331 | String - Null-terminated string to search.\r | |
1332 | StrCharSet - Null-terminated string to search for.\r | |
1333 | \r | |
1334 | Returns:\r | |
1335 | The address of the first occurrence of the matching substring if successful, or NULL otherwise.\r | |
1336 | --*/\r | |
1337 | ;\r | |
1338 | \r | |
1339 | CHAR8*\r | |
1340 | EfiAsciiStrStr (\r | |
1341 | IN CHAR8 *String,\r | |
1342 | IN CHAR8 *StrCharSet\r | |
1343 | )\r | |
1344 | /*++\r | |
1345 | \r | |
1346 | Routine Description:\r | |
1347 | \r | |
1348 | Find a Ascii substring.\r | |
1349 | \r | |
1350 | Arguments: \r | |
1351 | \r | |
1352 | String - Null-terminated Ascii string to search.\r | |
1353 | StrCharSet - Null-terminated Ascii string to search for.\r | |
1354 | \r | |
1355 | Returns:\r | |
1356 | The address of the first occurrence of the matching Ascii substring if successful, or NULL otherwise.\r | |
1357 | --*/\r | |
1358 | ;\r | |
1359 | #endif\r |