]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
4ea9375a HT |
3 | Copyright (c) 2004, 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 | Print.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Basic Ascii AvSPrintf() function named AvSPrint(). AvSPrint() enables very\r | |
19 | simple implemenation of debug prints.\r | |
20 | \r | |
21 | You can not Print more than PEI_LIB_MAX_PRINT_BUFFER characters at a \r | |
22 | time. This makes the implementation very simple.\r | |
23 | \r | |
24 | AvSPrint format specification has the follwoing form\r | |
25 | \r | |
26 | %[flags][width]type\r | |
27 | \r | |
28 | flags:\r | |
29 | '-' - Left justify\r | |
30 | '+' - Prefix a sign\r | |
31 | ' ' - Prefix a blank\r | |
32 | ',' - Place commas in numberss\r | |
33 | '0' - Prefix for width with zeros\r | |
34 | 'l' - UINT64\r | |
35 | 'L' - UINT64\r | |
36 | \r | |
37 | width:\r | |
38 | '*' - Get width from a UINTN argumnet from the argument list\r | |
39 | Decimal number that represents width of print\r | |
40 | \r | |
41 | type:\r | |
0f77dfb6 | 42 | 'p' - arugment is VOID *; printed as hex number\r |
3eb9473e | 43 | 'X' - argument is a UINTN hex number, prefix '0'\r |
44 | 'x' - argument is a hex number\r | |
45 | 'd' - argument is a decimal number\r | |
46 | 'a' - argument is an ascii string \r | |
47 | 'S', 's' - argument is an Unicode string\r | |
48 | 'g' - argument is a pointer to an EFI_GUID\r | |
49 | 't' - argument is a pointer to an EFI_TIME structure\r | |
50 | 'c' - argument is an ascii character\r | |
51 | 'r' - argument is EFI_STATUS\r | |
52 | '%' - Print a %\r | |
53 | \r | |
54 | --*/\r | |
55 | \r | |
56 | #include "Tiano.h"\r | |
57 | #include "Pei.h"\r | |
58 | #include "PeiLib.h"\r | |
59 | #include "Print.h"\r | |
60 | \r | |
61 | STATIC\r | |
62 | CHAR8 *\r | |
63 | GetFlagsAndWidth (\r | |
64 | IN CHAR8 *Format, \r | |
65 | OUT UINTN *Flags, \r | |
66 | OUT UINTN *Width,\r | |
67 | IN OUT VA_LIST *Marker\r | |
68 | );\r | |
69 | \r | |
70 | STATIC\r | |
71 | UINTN\r | |
72 | ValueToString (\r | |
73 | IN OUT CHAR8 *Buffer, \r | |
74 | IN INT64 Value, \r | |
75 | IN UINTN Flags, \r | |
76 | IN UINTN Width\r | |
77 | );\r | |
78 | \r | |
79 | STATIC\r | |
80 | UINTN\r | |
81 | ValueTomHexStr (\r | |
82 | IN OUT CHAR8 *Buffer, \r | |
83 | IN UINT64 Value, \r | |
84 | IN UINTN Flags, \r | |
85 | IN UINTN Width\r | |
86 | );\r | |
87 | \r | |
88 | STATIC\r | |
89 | UINTN\r | |
90 | GuidToString (\r | |
91 | IN EFI_GUID *Guid,\r | |
92 | IN OUT CHAR8 *Buffer,\r | |
93 | IN UINTN BufferSize\r | |
94 | );\r | |
95 | \r | |
96 | STATIC\r | |
97 | UINTN\r | |
98 | TimeToString (\r | |
99 | IN EFI_TIME *Time,\r | |
100 | IN OUT CHAR8 *Buffer,\r | |
101 | IN UINTN BufferSize\r | |
102 | );\r | |
103 | \r | |
104 | STATIC\r | |
105 | UINTN\r | |
106 | EfiStatusToString (\r | |
107 | IN EFI_STATUS Status,\r | |
108 | OUT CHAR8 *Buffer,\r | |
109 | IN UINTN BufferSize\r | |
110 | );\r | |
111 | \r | |
112 | \r | |
113 | UINTN\r | |
114 | ASPrint (\r | |
115 | OUT CHAR8 *Buffer,\r | |
116 | IN UINTN BufferSize,\r | |
117 | IN CONST CHAR8 *Format,\r | |
118 | ...\r | |
119 | )\r | |
120 | /*++\r | |
121 | \r | |
122 | Routine Description:\r | |
123 | \r | |
124 | ASPrint function to process format and place the results in Buffer.\r | |
125 | \r | |
126 | Arguments:\r | |
127 | \r | |
128 | Buffer - Ascii buffer to print the results of the parsing of Format into.\r | |
129 | \r | |
130 | BufferSize - Maximum number of characters to put into buffer. Zero means no \r | |
131 | limit.\r | |
132 | \r | |
133 | Format - Ascii format string see file header for more details.\r | |
134 | \r | |
135 | ... - Vararg list consumed by processing Format.\r | |
136 | \r | |
137 | Returns: \r | |
138 | \r | |
139 | Number of characters printed.\r | |
140 | \r | |
141 | --*/\r | |
142 | {\r | |
143 | UINTN Return;\r | |
144 | VA_LIST Marker;\r | |
145 | \r | |
146 | VA_START(Marker, Format);\r | |
147 | Return = AvSPrint(Buffer, BufferSize, Format, Marker);\r | |
148 | VA_END (Marker);\r | |
149 | \r | |
150 | return Return;\r | |
151 | }\r | |
152 | \r | |
153 | \r | |
154 | UINTN\r | |
155 | AvSPrint (\r | |
156 | OUT CHAR8 *StartOfBuffer,\r | |
157 | IN UINTN BufferSize,\r | |
158 | IN CONST CHAR8 *FormatString,\r | |
159 | IN VA_LIST Marker\r | |
160 | )\r | |
161 | /*++\r | |
162 | \r | |
163 | Routine Description:\r | |
164 | \r | |
165 | AvSPrint function to process format and place the results in Buffer. Since a \r | |
166 | VA_LIST is used this rountine allows the nesting of Vararg routines. Thus \r | |
167 | this is the main print working routine\r | |
168 | \r | |
169 | Arguments:\r | |
170 | \r | |
171 | StartOfBuffer - Ascii buffer to print the results of the parsing of Format into.\r | |
172 | \r | |
173 | BufferSize - Maximum number of characters to put into buffer. Zero means \r | |
174 | no limit.\r | |
175 | \r | |
176 | FormatString - Ascii format string see file header for more details.\r | |
177 | \r | |
178 | Marker - Vararg list consumed by processing Format.\r | |
179 | \r | |
180 | Returns: \r | |
181 | \r | |
182 | Number of characters printed.\r | |
183 | \r | |
184 | --*/\r | |
185 | {\r | |
186 | CHAR8 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];\r | |
187 | CHAR8 *Buffer;\r | |
188 | CHAR8 *AsciiStr;\r | |
189 | CHAR16 *UnicodeStr;\r | |
190 | CHAR8 *Format;\r | |
191 | UINTN Index;\r | |
192 | UINTN Flags;\r | |
193 | UINTN Width;\r | |
194 | UINTN Count;\r | |
195 | UINTN BufferLeft;\r | |
196 | UINT64 Value;\r | |
197 | EFI_GUID *TmpGUID;\r | |
198 | \r | |
199 | //\r | |
200 | // Process the format string. Stop if Buffer is over run.\r | |
201 | //\r | |
202 | Buffer = StartOfBuffer;\r | |
203 | Format = (CHAR8 *) FormatString;\r | |
204 | BufferLeft = BufferSize;\r | |
205 | for (Index = 0; (*Format != '\0') && (Index < BufferSize - 1); Format++) {\r | |
206 | if (*Format != '%') {\r | |
207 | if ((*Format == '\n') && (Index < BufferSize - 2)) {\r | |
208 | //\r | |
209 | // If carage return add line feed\r | |
210 | //\r | |
211 | Buffer[Index++] = '\r';\r | |
212 | BufferLeft -= sizeof (CHAR8);\r | |
213 | }\r | |
214 | \r | |
215 | Buffer[Index++] = *Format;\r | |
216 | BufferLeft -= sizeof (CHAR8);\r | |
217 | } else {\r | |
218 | \r | |
219 | //\r | |
220 | // Now it's time to parse what follows after %\r | |
221 | //\r | |
222 | Format = GetFlagsAndWidth (Format, &Flags, &Width, &Marker);\r | |
223 | switch (*Format) {\r | |
0f77dfb6 | 224 | case 'p':\r |
225 | //\r | |
226 | // Flag space, +, 0, L & l are invalid for type p.\r | |
227 | //\r | |
228 | Flags &= ~(PREFIX_BLANK| PREFIX_SIGN | LONG_TYPE);\r | |
229 | if (sizeof (VOID *) > 4) {\r | |
230 | Flags |= LONG_TYPE;\r | |
231 | Value = VA_ARG (Marker, UINT64);\r | |
232 | } else {\r | |
233 | Value = VA_ARG (Marker, UINTN);\r | |
234 | }\r | |
235 | Flags |= PREFIX_ZERO;\r | |
236 | \r | |
237 | ValueTomHexStr (TempBuffer, Value, Flags, Width);\r | |
238 | AsciiStr = TempBuffer;\r | |
239 | \r | |
240 | for (; (*AsciiStr != '\0') && (Index < BufferSize - 1); AsciiStr++) {\r | |
241 | Buffer[Index++] = *AsciiStr;\r | |
242 | }\r | |
243 | break;\r | |
3eb9473e | 244 | case 'X':\r |
245 | Flags |= PREFIX_ZERO;\r | |
246 | Width = sizeof (UINT64) * 2;\r | |
247 | \r | |
248 | //\r | |
249 | // break skiped on purpose\r | |
250 | //\r | |
251 | case 'x':\r | |
252 | if ((Flags & LONG_TYPE) == LONG_TYPE) {\r | |
253 | Value = VA_ARG (Marker, UINT64);\r | |
254 | } else {\r | |
255 | Value = VA_ARG (Marker, UINTN);\r | |
256 | }\r | |
257 | \r | |
258 | ValueTomHexStr (TempBuffer, Value, Flags, Width);\r | |
259 | AsciiStr = TempBuffer;\r | |
260 | \r | |
261 | for (; (*AsciiStr != '\0') && (Index < BufferSize - 1); AsciiStr++) {\r | |
262 | Buffer[Index++] = *AsciiStr;\r | |
263 | }\r | |
264 | break;\r | |
265 | \r | |
266 | case 'd':\r | |
267 | if ((Flags & LONG_TYPE) == LONG_TYPE) {\r | |
268 | Value = VA_ARG (Marker, UINT64);\r | |
269 | } else {\r | |
270 | Value = (UINTN) VA_ARG (Marker, UINTN);\r | |
271 | }\r | |
272 | \r | |
273 | ValueToString (TempBuffer, Value, Flags, Width);\r | |
274 | AsciiStr = TempBuffer;\r | |
275 | \r | |
276 | for (; (*AsciiStr != '\0') && (Index < BufferSize - 1); AsciiStr++) {\r | |
277 | Buffer[Index++] = *AsciiStr;\r | |
278 | }\r | |
279 | break;\r | |
280 | \r | |
281 | case 's':\r | |
282 | case 'S':\r | |
283 | UnicodeStr = (CHAR16 *) VA_ARG (Marker, CHAR8 *);\r | |
284 | if (UnicodeStr == NULL) {\r | |
285 | UnicodeStr = L"<null string>";\r | |
286 | }\r | |
287 | \r | |
288 | for (Count = 0; (*UnicodeStr != '\0') && (Index < BufferSize - 1); UnicodeStr++, Count++) {\r | |
289 | Buffer[Index++] = (CHAR8) *UnicodeStr;\r | |
290 | }\r | |
291 | //\r | |
292 | // Add padding if needed\r | |
293 | //\r | |
294 | for (; (Count < Width) && (Index < BufferSize - 1); Count++) {\r | |
295 | Buffer[Index++] = ' ';\r | |
296 | }\r | |
297 | \r | |
298 | break;\r | |
299 | \r | |
300 | case 'a':\r | |
301 | AsciiStr = (CHAR8 *) VA_ARG (Marker, CHAR8 *);\r | |
302 | if (AsciiStr == NULL) {\r | |
303 | AsciiStr = "<null string>";\r | |
304 | }\r | |
305 | \r | |
306 | for (Count = 0; (*AsciiStr != '\0') && (Index < BufferSize - 1); AsciiStr++, Count++) {\r | |
307 | Buffer[Index++] = *AsciiStr;\r | |
308 | }\r | |
309 | //\r | |
310 | // Add padding if needed\r | |
311 | //\r | |
312 | for (; (Count < Width) && (Index < BufferSize - 1); Count++) {\r | |
313 | Buffer[Index++] = ' ';\r | |
314 | }\r | |
315 | break;\r | |
316 | \r | |
317 | case 'c':\r | |
318 | Buffer[Index++] = (CHAR8) VA_ARG (Marker, UINTN);\r | |
319 | break;\r | |
320 | \r | |
321 | case 'g':\r | |
322 | TmpGUID = VA_ARG (Marker, EFI_GUID *);\r | |
323 | if (TmpGUID != NULL) {\r | |
324 | Index += GuidToString (\r | |
325 | TmpGUID,\r | |
326 | &Buffer[Index],\r | |
327 | BufferLeft\r | |
328 | );\r | |
329 | }\r | |
330 | break;\r | |
331 | \r | |
332 | case 't':\r | |
333 | Index += TimeToString (\r | |
334 | VA_ARG (Marker, EFI_TIME *), \r | |
335 | &Buffer[Index],\r | |
336 | BufferLeft\r | |
337 | );\r | |
338 | break;\r | |
339 | \r | |
340 | case 'r':\r | |
341 | Index += EfiStatusToString (\r | |
342 | VA_ARG (Marker, EFI_STATUS), \r | |
343 | &Buffer[Index],\r | |
344 | BufferLeft\r | |
345 | );\r | |
346 | break;\r | |
347 | \r | |
348 | case '%':\r | |
349 | Buffer[Index++] = *Format;\r | |
350 | break;\r | |
351 | \r | |
352 | default:\r | |
353 | //\r | |
354 | // if the type is unknown print it to the screen\r | |
355 | //\r | |
356 | Buffer[Index++] = *Format;\r | |
357 | }\r | |
358 | \r | |
359 | BufferLeft = BufferSize - Index;\r | |
360 | }\r | |
361 | }\r | |
362 | \r | |
363 | Buffer[Index++] = '\0';\r | |
364 | \r | |
365 | return &Buffer[Index] - StartOfBuffer;\r | |
366 | }\r | |
367 | \r | |
368 | \r | |
369 | \r | |
370 | STATIC\r | |
371 | CHAR8 *\r | |
372 | GetFlagsAndWidth (\r | |
373 | IN CHAR8 *Format, \r | |
374 | OUT UINTN *Flags, \r | |
375 | OUT UINTN *Width,\r | |
376 | IN OUT VA_LIST *Marker\r | |
377 | )\r | |
378 | /*++\r | |
379 | \r | |
380 | Routine Description:\r | |
381 | \r | |
382 | AvSPrint worker function that parses flag and width information from the \r | |
383 | Format string and returns the next index into the Format string that needs\r | |
384 | to be parsed. See file headed for details of Flag and Width.\r | |
385 | \r | |
386 | Arguments:\r | |
387 | \r | |
388 | Format - Current location in the AvSPrint format string.\r | |
389 | \r | |
390 | Flags - Returns flags\r | |
391 | \r | |
392 | Width - Returns width of element\r | |
393 | \r | |
394 | Marker - Vararg list that may be paritally consumed and returned.\r | |
395 | \r | |
396 | Returns: \r | |
397 | \r | |
398 | Pointer indexed into the Format string for all the information parsed\r | |
399 | by this routine.\r | |
400 | \r | |
401 | --*/\r | |
402 | {\r | |
403 | UINTN Count;\r | |
404 | BOOLEAN Done;\r | |
405 | \r | |
406 | *Flags = 0;\r | |
407 | *Width = 0;\r | |
408 | for (Done = FALSE; !Done; ) {\r | |
409 | Format++;\r | |
410 | \r | |
411 | switch (*Format) {\r | |
412 | \r | |
413 | case '-': *Flags |= LEFT_JUSTIFY; break;\r | |
414 | case '+': *Flags |= PREFIX_SIGN; break;\r | |
415 | case ' ': *Flags |= PREFIX_BLANK; break;\r | |
416 | case ',': *Flags |= COMMA_TYPE; break;\r | |
417 | case 'L':\r | |
418 | case 'l': *Flags |= LONG_TYPE; break;\r | |
419 | \r | |
420 | case '*':\r | |
421 | *Width = VA_ARG (*Marker, UINTN);\r | |
422 | break;\r | |
423 | \r | |
424 | case '0':\r | |
425 | *Flags |= PREFIX_ZERO;\r | |
426 | case '1':\r | |
427 | case '2':\r | |
428 | case '3':\r | |
429 | case '4':\r | |
430 | case '5':\r | |
431 | case '6':\r | |
432 | case '7':\r | |
433 | case '8':\r | |
434 | case '9':\r | |
435 | Count = 0;\r | |
436 | do {\r | |
437 | Count = (Count * 10) + *Format - '0';\r | |
438 | Format++;\r | |
439 | } while ((*Format >= '0') && (*Format <= '9'));\r | |
440 | Format--;\r | |
441 | *Width = Count;\r | |
442 | break;\r | |
443 | \r | |
444 | default:\r | |
445 | Done = TRUE;\r | |
446 | }\r | |
447 | }\r | |
448 | return Format;\r | |
449 | }\r | |
450 | \r | |
451 | static CHAR8 mHexStr[] = { '0','1','2','3','4','5','6','7',\r | |
452 | '8','9','A','B','C','D','E','F' };\r | |
453 | \r | |
454 | STATIC\r | |
455 | UINTN\r | |
456 | ValueTomHexStr (\r | |
457 | IN OUT CHAR8 *Buffer, \r | |
458 | IN UINT64 Value, \r | |
459 | IN UINTN Flags, \r | |
460 | IN UINTN Width\r | |
461 | )\r | |
462 | /*++\r | |
463 | \r | |
464 | Routine Description:\r | |
465 | \r | |
466 | AvSPrint worker function that prints a Value as a hex number in Buffer\r | |
467 | \r | |
468 | Arguments:\r | |
469 | \r | |
470 | Buffer - Location to place ascii hex string of Value.\r | |
471 | \r | |
472 | Value - Hex value to convert to a string in Buffer.\r | |
473 | \r | |
474 | Flags - Flags to use in printing Hex string, see file header for details.\r | |
475 | \r | |
476 | Width - Width of hex value.\r | |
477 | \r | |
478 | Returns: \r | |
479 | \r | |
480 | Number of characters printed. \r | |
481 | \r | |
482 | --*/\r | |
483 | {\r | |
484 | CHAR8 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];\r | |
485 | CHAR8 *TempStr;\r | |
486 | CHAR8 Prefix;\r | |
487 | CHAR8 *BufferPtr;\r | |
488 | UINTN Count;\r | |
489 | UINTN Index;\r | |
490 | \r | |
491 | TempStr = TempBuffer;\r | |
492 | BufferPtr = Buffer;\r | |
493 | \r | |
494 | //\r | |
495 | // Count starts at one since we will null terminate. Each iteration of the\r | |
496 | // loop picks off one nibble. Oh yea TempStr ends up backwards\r | |
497 | //\r | |
498 | Count = 0;\r | |
499 | do {\r | |
500 | *(TempStr++) = mHexStr[Value & 0x0f];\r | |
501 | Value = RShiftU64 (Value, 4);\r | |
502 | Count++;\r | |
503 | } while (Value != 0);\r | |
504 | \r | |
505 | if (Flags & PREFIX_ZERO) {\r | |
506 | Prefix = '0';\r | |
507 | } else if (!(Flags & LEFT_JUSTIFY)) { \r | |
508 | Prefix = ' ';\r | |
509 | } else {\r | |
510 | Prefix = 0x00;\r | |
511 | } \r | |
512 | for (Index = Count; Index < Width; Index++) {\r | |
513 | *(TempStr++) = Prefix;\r | |
514 | }\r | |
515 | \r | |
516 | //\r | |
517 | // Reverse temp string into Buffer.\r | |
518 | //\r | |
519 | if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {\r | |
520 | TempStr = TempBuffer + Width;\r | |
521 | }\r | |
522 | Index = 0;\r | |
523 | while (TempStr != TempBuffer) {\r | |
524 | *(BufferPtr++) = *(--TempStr);\r | |
525 | Index++;\r | |
526 | }\r | |
527 | \r | |
528 | *BufferPtr = 0;\r | |
529 | return Index;\r | |
530 | }\r | |
531 | \r | |
532 | STATIC\r | |
533 | UINTN\r | |
534 | ValueToString (\r | |
535 | IN OUT CHAR8 *Buffer, \r | |
536 | IN INT64 Value, \r | |
537 | IN UINTN Flags, \r | |
538 | IN UINTN Width\r | |
539 | )\r | |
540 | /*++\r | |
541 | \r | |
542 | Routine Description:\r | |
543 | \r | |
544 | AvSPrint worker function that prints a Value as a decimal number in Buffer\r | |
545 | \r | |
546 | Arguments:\r | |
547 | \r | |
548 | Buffer - Location to place ascii decimal number string of Value.\r | |
549 | \r | |
550 | Value - Decimal value to convert to a string in Buffer.\r | |
551 | \r | |
552 | Flags - Flags to use in printing decimal string, see file header for details.\r | |
553 | \r | |
554 | Width - Width of hex value.\r | |
555 | \r | |
556 | Returns: \r | |
557 | \r | |
558 | Number of characters printed. \r | |
559 | \r | |
560 | --*/\r | |
561 | {\r | |
562 | CHAR8 TempBuffer[CHARACTER_NUMBER_FOR_VALUE];\r | |
563 | CHAR8 *TempStr;\r | |
564 | CHAR8 *BufferPtr;\r | |
565 | UINTN Count;\r | |
566 | UINTN NumberCount;\r | |
567 | UINTN Remainder;\r | |
568 | BOOLEAN Negative;\r | |
569 | UINTN Index;\r | |
570 | \r | |
571 | Negative = FALSE;\r | |
572 | TempStr = TempBuffer;\r | |
573 | BufferPtr = Buffer;\r | |
574 | Count = 0;\r | |
575 | NumberCount = 0;\r | |
576 | \r | |
577 | if (Value < 0) {\r | |
578 | Negative = TRUE;\r | |
579 | Value = -Value;\r | |
580 | }\r | |
581 | \r | |
582 | do {\r | |
583 | Value = (INT64)DivU64x32 ((UINT64)Value, 10, &Remainder);\r | |
584 | *(TempStr++) = (CHAR8)(Remainder + '0');\r | |
585 | Count++;\r | |
586 | NumberCount++;\r | |
587 | if ((Flags & COMMA_TYPE) == COMMA_TYPE) {\r | |
588 | if (NumberCount % 3 == 0 && Value != 0) {\r | |
589 | *(TempStr++) = ',';\r | |
590 | Count++;\r | |
591 | }\r | |
592 | }\r | |
593 | } while (Value != 0);\r | |
594 | \r | |
595 | if (Negative) {\r | |
596 | *(BufferPtr++) = '-';\r | |
597 | Count++;\r | |
598 | }\r | |
599 | \r | |
600 | //\r | |
601 | // Reverse temp string into Buffer.\r | |
602 | //\r | |
603 | if (Width > 0 && (UINTN) (TempStr - TempBuffer) > Width) {\r | |
604 | TempStr = TempBuffer + Width;\r | |
605 | }\r | |
606 | Index = 0;\r | |
607 | while (TempStr != TempBuffer) {\r | |
608 | *(BufferPtr++) = *(--TempStr);\r | |
609 | } \r | |
610 | \r | |
611 | *BufferPtr = 0;\r | |
612 | return Index;\r | |
613 | }\r | |
614 | \r | |
615 | STATIC\r | |
616 | UINTN\r | |
617 | GuidToString (\r | |
618 | IN EFI_GUID *Guid,\r | |
619 | IN CHAR8 *Buffer,\r | |
620 | IN UINTN BufferSize\r | |
621 | )\r | |
622 | /*++\r | |
623 | \r | |
624 | Routine Description:\r | |
625 | \r | |
626 | AvSPrint worker function that prints an EFI_GUID.\r | |
627 | \r | |
628 | Arguments:\r | |
629 | \r | |
630 | Guid - Pointer to GUID to print.\r | |
631 | \r | |
632 | Buffer - Buffe to print Guid into.\r | |
633 | \r | |
634 | BufferSize - Size of Buffer.\r | |
635 | \r | |
636 | Returns: \r | |
637 | \r | |
638 | Number of characters printed. \r | |
639 | \r | |
640 | --*/\r | |
641 | {\r | |
642 | UINTN Size;\r | |
643 | \r | |
644 | Size = ASPrint (\r | |
645 | Buffer,\r | |
646 | BufferSize, \r | |
647 | "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r | |
648 | (UINTN)Guid->Data1, \r | |
649 | (UINTN)Guid->Data2,\r | |
650 | (UINTN)Guid->Data3,\r | |
651 | (UINTN)Guid->Data4[0],\r | |
652 | (UINTN)Guid->Data4[1],\r | |
653 | (UINTN)Guid->Data4[2],\r | |
654 | (UINTN)Guid->Data4[3],\r | |
655 | (UINTN)Guid->Data4[4],\r | |
656 | (UINTN)Guid->Data4[5],\r | |
657 | (UINTN)Guid->Data4[6],\r | |
658 | (UINTN)Guid->Data4[7]\r | |
659 | );\r | |
660 | \r | |
661 | //\r | |
662 | // ASPrint will null terminate the string. The -1 skips the null\r | |
663 | //\r | |
664 | return Size - 1;\r | |
665 | }\r | |
666 | \r | |
667 | \r | |
668 | STATIC\r | |
669 | UINTN\r | |
670 | TimeToString (\r | |
671 | IN EFI_TIME *Time,\r | |
672 | OUT CHAR8 *Buffer,\r | |
673 | IN UINTN BufferSize\r | |
674 | )\r | |
675 | /*++\r | |
676 | \r | |
677 | Routine Description:\r | |
678 | \r | |
679 | AvSPrint worker function that prints EFI_TIME.\r | |
680 | \r | |
681 | Arguments:\r | |
682 | \r | |
683 | Time - Pointer to EFI_TIME sturcture to print.\r | |
684 | \r | |
685 | Buffer - Buffer to print Time into.\r | |
686 | \r | |
687 | BufferSize - Size of Buffer.\r | |
688 | \r | |
689 | Returns: \r | |
690 | \r | |
691 | Number of characters printed. \r | |
692 | \r | |
693 | --*/\r | |
694 | { \r | |
695 | UINTN Size;\r | |
696 | \r | |
697 | Size = ASPrint (\r | |
698 | Buffer,\r | |
699 | BufferSize, \r | |
700 | "%02d/%02d/%04d %02d:%02d",\r | |
701 | (UINTN)Time->Month,\r | |
702 | (UINTN)Time->Day,\r | |
703 | (UINTN)Time->Year,\r | |
704 | (UINTN)Time->Hour,\r | |
705 | (UINTN)Time->Minute\r | |
706 | );\r | |
707 | \r | |
708 | //\r | |
709 | // ASPrint will null terminate the string. The -1 skips the null\r | |
710 | //\r | |
711 | return Size - 1;\r | |
712 | } \r | |
713 | \r | |
714 | STATIC\r | |
715 | UINTN\r | |
716 | EfiStatusToString (\r | |
717 | IN EFI_STATUS Status,\r | |
718 | OUT CHAR8 *Buffer,\r | |
719 | IN UINTN BufferSize\r | |
720 | )\r | |
721 | /*++\r | |
722 | \r | |
723 | Routine Description:\r | |
724 | \r | |
725 | AvSPrint worker function that prints EFI_STATUS as a string. If string is\r | |
726 | not known a hex value will be printed.\r | |
727 | \r | |
728 | Arguments:\r | |
729 | \r | |
730 | Status - EFI_STATUS sturcture to print.\r | |
731 | \r | |
732 | Buffer - Buffer to print EFI_STATUS message string into.\r | |
733 | \r | |
734 | BufferSize - Size of Buffer.\r | |
735 | \r | |
736 | Returns: \r | |
737 | \r | |
738 | Number of characters printed. \r | |
739 | \r | |
740 | --*/\r | |
741 | {\r | |
742 | UINTN Size;\r | |
743 | CHAR8 *Desc;\r | |
744 | \r | |
745 | if (Status == EFI_SUCCESS) {\r | |
746 | Desc = "Success";\r | |
747 | } else if (Status == EFI_LOAD_ERROR) {\r | |
748 | Desc = "Load Error";\r | |
749 | } else if (Status == EFI_INVALID_PARAMETER) {\r | |
750 | Desc = "Invalid Parameter";\r | |
751 | } else if (Status == EFI_UNSUPPORTED) {\r | |
752 | Desc = "Unsupported";\r | |
753 | } else if (Status == EFI_BAD_BUFFER_SIZE) {\r | |
754 | Desc = "Bad Buffer Size";\r | |
755 | } else if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
756 | Desc = "Buffer Too Small";\r | |
757 | } else if (Status == EFI_NOT_READY) {\r | |
758 | Desc = "Not Ready";\r | |
759 | } else if (Status == EFI_DEVICE_ERROR) {\r | |
760 | Desc = "Device Error";\r | |
761 | } else if (Status == EFI_WRITE_PROTECTED) {\r | |
762 | Desc = "Write Protected";\r | |
763 | } else if (Status == EFI_OUT_OF_RESOURCES) {\r | |
764 | Desc = "Out of Resources";\r | |
765 | } else if (Status == EFI_VOLUME_CORRUPTED) {\r | |
766 | Desc = "Volume Corrupt";\r | |
767 | } else if (Status == EFI_VOLUME_FULL) {\r | |
768 | Desc = "Volume Full";\r | |
769 | } else if (Status == EFI_NO_MEDIA) {\r | |
770 | Desc = "No Media";\r | |
771 | } else if (Status == EFI_MEDIA_CHANGED) {\r | |
772 | Desc = "Media changed";\r | |
773 | } else if (Status == EFI_NOT_FOUND) {\r | |
774 | Desc = "Not Found";\r | |
775 | } else if (Status == EFI_ACCESS_DENIED) {\r | |
776 | Desc = "Access Denied";\r | |
777 | } else if (Status == EFI_NO_RESPONSE) {\r | |
778 | Desc = "No Response";\r | |
779 | } else if (Status == EFI_NO_MAPPING) {\r | |
780 | Desc = "No mapping";\r | |
781 | } else if (Status == EFI_TIMEOUT) {\r | |
782 | Desc = "Time out";\r | |
783 | } else if (Status == EFI_NOT_STARTED) {\r | |
784 | Desc = "Not started";\r | |
785 | } else if (Status == EFI_ALREADY_STARTED) {\r | |
786 | Desc = "Already started";\r | |
787 | } else if (Status == EFI_ABORTED) {\r | |
788 | Desc = "Aborted";\r | |
789 | } else if (Status == EFI_ICMP_ERROR) {\r | |
790 | Desc = "ICMP Error";\r | |
791 | } else if (Status == EFI_TFTP_ERROR) {\r | |
792 | Desc = "TFTP Error";\r | |
793 | } else if (Status == EFI_PROTOCOL_ERROR) {\r | |
794 | Desc = "Protocol Error";\r | |
795 | } else if (Status == EFI_WARN_UNKNOWN_GLYPH) {\r | |
796 | Desc = "Warning Unknown Glyph";\r | |
797 | } else if (Status == EFI_WARN_DELETE_FAILURE) {\r | |
798 | Desc = "Warning Delete Failure";\r | |
799 | } else if (Status == EFI_WARN_WRITE_FAILURE) {\r | |
800 | Desc = "Warning Write Failure";\r | |
801 | } else if (Status == EFI_WARN_BUFFER_TOO_SMALL) {\r | |
802 | Desc = "Warning Buffer Too Small";\r | |
803 | } else {\r | |
804 | Desc = NULL;\r | |
805 | }\r | |
806 | //\r | |
807 | // If we found a match, copy the message to the user's buffer. Otherwise\r | |
808 | // sprint the hex status code to their buffer.\r | |
809 | //\r | |
810 | if (Desc != NULL) {\r | |
811 | Size = ASPrint (Buffer, BufferSize, "%a", Desc);\r | |
812 | } else {\r | |
813 | Size = ASPrint (Buffer, BufferSize, "%X", Status);\r | |
814 | }\r | |
815 | return Size - 1;\r | |
816 | }\r |