]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
MdeModulePkg DxePrintLibPrint2Protocol Library SPrintLength() API issue.
[mirror_edk2.git] / MdeModulePkg / Library / DxePrintLibPrint2Protocol / PrintLib.c
CommitLineData
504214c4 1/** @file\r
bee67555 2 Instance of Print Library based on gEfiPrint2ProtocolGuid.\r
a0afd019 3\r
504214c4 4 Implement the print library instance by wrap the interface \r
bee67555 5 provided in the Print2 protocol. This protocol is defined as the internal\r
504214c4
LG
6 protocol related to this implementation, not in the public spec. So, this \r
7 library instance is only for this code base.\r
8\r
586d81d1 9Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 10This program and the accompanying materials\r
a0afd019 11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
14\r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
504214c4 18**/\r
a0afd019 19\r
60c93673 20#include <Uefi.h>\r
f405c067 21#include <Base.h>\r
0ed0c867 22#include <Protocol/Print2.h>\r
504dcb0a 23\r
24#include <Library/PrintLib.h>\r
25\r
26#include <Library/BaseLib.h>\r
bee67555 27#include <Library/DebugLib.h>\r
a0afd019 28\r
bee67555 29EFI_PRINT2_PROTOCOL *mPrint2Protocol = NULL;\r
a0afd019 30\r
ce95aa7a 31/**\r
bee67555 32 The constructor function caches the pointer to Print2 protocol.\r
33 \r
34 The constructor function locates Print2 protocol from protocol database.\r
35 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
ce95aa7a 36\r
bee67555 37 @param ImageHandle The firmware allocated handle for the EFI image.\r
38 @param SystemTable A pointer to the EFI System Table.\r
39 \r
40 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
ce95aa7a 41\r
42**/\r
2ad4dad0
LG
43EFI_STATUS\r
44EFIAPI\r
bee67555 45PrintLibConstructor (\r
46 IN EFI_HANDLE ImageHandle,\r
47 IN EFI_SYSTEM_TABLE *SystemTable\r
a0afd019 48 )\r
a0afd019 49{\r
bee67555 50 EFI_STATUS Status;\r
51\r
35289219 52 Status = SystemTable->BootServices->LocateProtocol (\r
53 &gEfiPrint2ProtocolGuid,\r
54 NULL,\r
55 (VOID**) &mPrint2Protocol\r
56 );\r
bee67555 57 ASSERT_EFI_ERROR (Status);\r
58 ASSERT (mPrint2Protocol != NULL);\r
59\r
60 return Status;\r
2ad4dad0
LG
61}\r
62\r
bee67555 63\r
504dcb0a 64/**\r
65 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated \r
66 format string.\r
67\r
68 @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.\r
69 @param Format Null-terminated format string.\r
70 @param VaListMarker VA_LIST style variable argument list consumed by processing Format.\r
71 @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.\r
72 @param Size The size, in bytes, of the BaseListMarker buffer.\r
73\r
74 @return The number of bytes in BaseListMarker. 0 if BaseListMarker is too small.\r
75\r
76**/\r
77BOOLEAN\r
78DxePrintLibPrint2ProtocolVaListToBaseList (\r
79 IN BOOLEAN AsciiFormat,\r
80 IN CONST CHAR8 *Format,\r
81 IN VA_LIST VaListMarker,\r
82 OUT BASE_LIST BaseListMarker,\r
83 IN UINTN Size\r
84 )\r
85{\r
86 BASE_LIST BaseListStart;\r
87 UINTN BytesPerFormatCharacter;\r
88 UINTN FormatMask;\r
89 UINTN FormatCharacter;\r
90 BOOLEAN Long;\r
91 BOOLEAN Done;\r
92\r
93 ASSERT (Format != NULL);\r
504dcb0a 94 ASSERT (BaseListMarker != NULL);\r
95\r
96 BaseListStart = BaseListMarker;\r
97\r
98 if (AsciiFormat) {\r
99 ASSERT (AsciiStrSize (Format) != 0);\r
100 BytesPerFormatCharacter = 1;\r
101 FormatMask = 0xff;\r
102 } else {\r
103 ASSERT (StrSize ((CHAR16 *) Format) != 0);\r
104 BytesPerFormatCharacter = 2;\r
105 FormatMask = 0xffff;\r
106 }\r
107\r
108 //\r
109 // Get the first character from the format string\r
110 //\r
111 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
112\r
113 while (FormatCharacter != 0) {\r
114 if (FormatCharacter == '%') {\r
115 Long = FALSE;\r
116\r
117 //\r
118 // Parse Flags and Width\r
119 //\r
120 for (Done = FALSE; !Done; ) {\r
121 //\r
122 // Get the next character from the format string\r
123 //\r
124 Format += BytesPerFormatCharacter;\r
125\r
126 //\r
127 // Get the next character from the format string\r
128 //\r
129 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
130\r
131 switch (FormatCharacter) {\r
132 case '.': \r
133 case '-': \r
134 case '+': \r
135 case ' ': \r
136 case ',': \r
137 case '0':\r
138 case '1':\r
139 case '2':\r
140 case '3':\r
141 case '4':\r
142 case '5':\r
143 case '6':\r
144 case '7':\r
145 case '8':\r
146 case '9':\r
147 break;\r
148 case 'L':\r
149 case 'l': \r
150 Long = TRUE;\r
151 break;\r
152 case '*':\r
153 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
154 break;\r
155 case '\0':\r
156 //\r
157 // Make no output if Format string terminates unexpectedly when\r
158 // looking up for flag, width, precision and type. \r
159 //\r
160 Format -= BytesPerFormatCharacter;\r
161 //\r
162 // break skipped on purpose.\r
163 //\r
164 default:\r
165 Done = TRUE;\r
166 break;\r
167 }\r
168 } \r
169 \r
170 //\r
171 // Handle each argument type\r
172 //\r
173 switch (FormatCharacter) {\r
174 case 'p':\r
175 if (sizeof (VOID *) > 4) {\r
176 Long = TRUE;\r
177 }\r
178 case 'X':\r
179 case 'x':\r
180 case 'd':\r
181 if (Long) {\r
182 BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r
183 } else {\r
184 BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r
185 }\r
186 break;\r
187 case 's':\r
188 case 'S':\r
189 case 'a':\r
190 case 'g':\r
191 case 't':\r
192 BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r
193 break;\r
194 case 'c':\r
195 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
196 break;\r
197 case 'r':\r
198 BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
199 break;\r
200 }\r
201 }\r
202\r
203 //\r
204 // If BASE_LIST is larger than Size, then return FALSE\r
205 //\r
206 if ((UINTN)((UINT8 *)BaseListMarker - (UINT8 *)BaseListStart) > Size) {\r
207 return FALSE;\r
208 }\r
209\r
210 //\r
211 // Get the next character from the format string\r
212 //\r
213 Format += BytesPerFormatCharacter;\r
214\r
215 //\r
216 // Get the next character from the format string\r
217 //\r
218 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
219 }\r
220 return TRUE;\r
221}\r
222\r
2ad4dad0
LG
223/**\r
224 Produces a Null-terminated Unicode string in an output buffer based on \r
225 a Null-terminated Unicode format string and a VA_LIST argument list\r
226 \r
227 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
228 and BufferSize. \r
229 The Unicode string is produced by parsing the format string specified by FormatString. \r
230 Arguments are pulled from the variable argument list specified by Marker based on the \r
231 contents of the format string. \r
232 The number of Unicode characters in the produced output buffer is returned not including\r
233 the Null-terminator.\r
234 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
235\r
236 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
237 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
238 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
239 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
240 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
241 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
242 ASSERT().\r
243 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
244 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
245 Null-terminator, then ASSERT().\r
246\r
247 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
248 Unicode string.\r
249 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
250 @param FormatString Null-terminated Unicode format string.\r
251 @param Marker VA_LIST marker for the variable argument list.\r
252 \r
253 @return The number of Unicode characters in the produced output buffer not including the\r
254 Null-terminator.\r
255\r
256**/\r
257UINTN\r
258EFIAPI\r
259UnicodeVSPrint (\r
260 OUT CHAR16 *StartOfBuffer,\r
261 IN UINTN BufferSize,\r
262 IN CONST CHAR16 *FormatString,\r
263 IN VA_LIST Marker\r
264 )\r
265{\r
97f77815 266 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 267\r
268 DxePrintLibPrint2ProtocolVaListToBaseList (\r
269 FALSE, \r
270 (CHAR8 *)FormatString, \r
271 Marker, \r
272 (BASE_LIST)BaseListMarker, \r
273 sizeof (BaseListMarker) - 8\r
274 );\r
275\r
276 return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
277}\r
278\r
279/**\r
280 Produces a Null-terminated Unicode string in an output buffer based on \r
281 a Null-terminated Unicode format string and a BASE_LIST argument list\r
282 \r
283 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
284 and BufferSize. \r
285 The Unicode string is produced by parsing the format string specified by FormatString. \r
286 Arguments are pulled from the variable argument list specified by Marker based on the \r
287 contents of the format string. \r
288 The number of Unicode characters in the produced output buffer is returned not including\r
289 the Null-terminator.\r
290 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
291\r
292 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
293 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
294 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
295 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
296 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
297 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
298 ASSERT().\r
299 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
300 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
301 Null-terminator, then ASSERT().\r
302\r
303 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
304 Unicode string.\r
305 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
306 @param FormatString Null-terminated Unicode format string.\r
307 @param Marker BASE_LIST marker for the variable argument list.\r
308 \r
309 @return The number of Unicode characters in the produced output buffer not including the\r
310 Null-terminator.\r
311\r
312**/\r
313UINTN\r
314EFIAPI\r
315UnicodeBSPrint (\r
316 OUT CHAR16 *StartOfBuffer,\r
317 IN UINTN BufferSize,\r
318 IN CONST CHAR16 *FormatString,\r
319 IN BASE_LIST Marker\r
320 )\r
321{\r
322 return mPrint2Protocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
a0afd019 323}\r
324\r
2ad4dad0
LG
325/**\r
326 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
327 Unicode format string and variable argument list.\r
328 \r
329 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
330 and BufferSize.\r
331 The Unicode string is produced by parsing the format string specified by FormatString.\r
332 Arguments are pulled from the variable argument list based on the contents of the format string.\r
333 The number of Unicode characters in the produced output buffer is returned not including\r
334 the Null-terminator.\r
335 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
336\r
337 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
338 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
339 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
340 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
341 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
342 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
343 ASSERT().\r
344 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
345 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
346 Null-terminator, then ASSERT().\r
347\r
348 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
349 Unicode string.\r
350 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
351 @param FormatString Null-terminated Unicode format string.\r
71898234 352 @param ... Variable argument list whose contents are accessed based on the \r
353 format string specified by FormatString.\r
ce95aa7a 354\r
2ad4dad0
LG
355 @return The number of Unicode characters in the produced output buffer not including the\r
356 Null-terminator.\r
357\r
358**/\r
a0afd019 359UINTN\r
2ad4dad0 360EFIAPI\r
a0afd019 361UnicodeSPrint (\r
362 OUT CHAR16 *StartOfBuffer,\r
363 IN UINTN BufferSize,\r
2ad4dad0 364 IN CONST CHAR16 *FormatString,\r
a0afd019 365 ...\r
366 )\r
a0afd019 367{\r
2ad4dad0 368 VA_LIST Marker;\r
3bbe68a3 369 UINTN NumberOfPrinted;\r
a0afd019 370\r
371 VA_START (Marker, FormatString);\r
3bbe68a3 372 NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
373 VA_END (Marker);\r
374 return NumberOfPrinted;\r
a0afd019 375}\r
376\r
2ad4dad0
LG
377/**\r
378 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
379 ASCII format string and a VA_LIST argument list\r
380 \r
381 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
382 and BufferSize.\r
383 The Unicode string is produced by parsing the format string specified by FormatString.\r
384 Arguments are pulled from the variable argument list specified by Marker based on the \r
385 contents of the format string.\r
386 The number of Unicode characters in the produced output buffer is returned not including\r
387 the Null-terminator.\r
388 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
389\r
390 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
391 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
392 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
393 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
394 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
395 ASSERT().\r
396 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
397 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
398 Null-terminator, then ASSERT().\r
399\r
400 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
401 Unicode string.\r
402 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
403 @param FormatString Null-terminated Unicode format string.\r
404 @param Marker VA_LIST marker for the variable argument list.\r
405 \r
406 @return The number of Unicode characters in the produced output buffer not including the\r
407 Null-terminator.\r
408\r
409**/\r
a0afd019 410UINTN\r
2ad4dad0
LG
411EFIAPI\r
412UnicodeVSPrintAsciiFormat (\r
413 OUT CHAR16 *StartOfBuffer,\r
414 IN UINTN BufferSize,\r
415 IN CONST CHAR8 *FormatString,\r
416 IN VA_LIST Marker\r
a0afd019 417 )\r
2ad4dad0 418{\r
97f77815 419 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 420\r
421 DxePrintLibPrint2ProtocolVaListToBaseList (\r
422 TRUE, \r
423 FormatString, \r
424 Marker, \r
425 (BASE_LIST)BaseListMarker, \r
426 sizeof (BaseListMarker) - 8\r
427 );\r
428\r
429 return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
430}\r
431\r
432/**\r
433 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
434 ASCII format string and a BASE_LIST argument list\r
435 \r
436 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
437 and BufferSize.\r
438 The Unicode string is produced by parsing the format string specified by FormatString.\r
439 Arguments are pulled from the variable argument list specified by Marker based on the \r
440 contents of the format string.\r
441 The number of Unicode characters in the produced output buffer is returned not including\r
442 the Null-terminator.\r
443 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
444\r
445 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
446 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
447 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
448 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
449 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
450 ASSERT().\r
451 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
452 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
453 Null-terminator, then ASSERT().\r
454\r
455 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
456 Unicode string.\r
457 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
458 @param FormatString Null-terminated Unicode format string.\r
459 @param Marker BASE_LIST marker for the variable argument list.\r
460 \r
461 @return The number of Unicode characters in the produced output buffer not including the\r
462 Null-terminator.\r
463\r
464**/\r
465UINTN\r
466EFIAPI\r
467UnicodeBSPrintAsciiFormat (\r
468 OUT CHAR16 *StartOfBuffer,\r
469 IN UINTN BufferSize,\r
470 IN CONST CHAR8 *FormatString,\r
471 IN BASE_LIST Marker\r
472 )\r
473{\r
474 return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
2ad4dad0 475}\r
a0afd019 476\r
2ad4dad0
LG
477/**\r
478 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
479 ASCII format string and variable argument list.\r
480 \r
481 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
482 and BufferSize.\r
483 The Unicode string is produced by parsing the format string specified by FormatString.\r
484 Arguments are pulled from the variable argument list based on the contents of the \r
485 format string.\r
486 The number of Unicode characters in the produced output buffer is returned not including\r
487 the Null-terminator.\r
488 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
489\r
490 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
491 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
492 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
493 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
494 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
495 ASSERT().\r
496 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
497 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
498 Null-terminator, then ASSERT().\r
499\r
500 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
501 Unicode string.\r
502 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
503 @param FormatString Null-terminated Unicode format string.\r
71898234 504 @param ... Variable argument list whose contents are accessed based on the \r
505 format string specified by FormatString.\r
2ad4dad0
LG
506 \r
507 @return The number of Unicode characters in the produced output buffer not including the\r
508 Null-terminator.\r
509\r
510**/\r
511UINTN\r
512EFIAPI\r
513UnicodeSPrintAsciiFormat (\r
514 OUT CHAR16 *StartOfBuffer,\r
515 IN UINTN BufferSize,\r
516 IN CONST CHAR8 *FormatString,\r
517 ...\r
518 )\r
519{\r
520 VA_LIST Marker;\r
3bbe68a3 521 UINTN NumberOfPrinted;\r
a0afd019 522\r
2ad4dad0 523 VA_START (Marker, FormatString);\r
3bbe68a3 524 NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
525 VA_END (Marker);\r
526 return NumberOfPrinted;\r
2ad4dad0 527}\r
a0afd019 528\r
2ad4dad0
LG
529/**\r
530 Converts a decimal value to a Null-terminated Unicode string.\r
531 \r
532 Converts the decimal number specified by Value to a Null-terminated Unicode \r
533 string specified by Buffer containing at most Width characters. No padding of spaces \r
534 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
535 The number of Unicode characters in Buffer is returned not including the Null-terminator.\r
536 If the conversion contains more than Width characters, then only the first\r
537 Width characters are returned, and the total number of characters \r
538 required to perform the conversion is returned.\r
539 Additional conversion parameters are specified in Flags. \r
540 \r
541 The Flags bit LEFT_JUSTIFY is always ignored.\r
542 All conversions are left justified in Buffer.\r
543 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
544 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
545 are inserted every 3rd digit starting from the right.\r
df8d0595 546 If RADIX_HEX is set in Flags, then the output buffer will be \r
2ad4dad0 547 formatted in hexadecimal format.\r
df8d0595 548 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
2ad4dad0
LG
549 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
550 then Buffer is padded with '0' characters so the combination of the optional '-' \r
551 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
552 add up to Width characters.\r
df8d0595 553 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
2ad4dad0
LG
554 If Buffer is NULL, then ASSERT().\r
555 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
556 If unsupported bits are set in Flags, then ASSERT().\r
df8d0595 557 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
2ad4dad0
LG
558 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
559\r
560 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
561 Unicode string.\r
562 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
563 @param Value The 64-bit signed value to convert to a string.\r
564 @param Width The maximum number of Unicode characters to place in Buffer, not including\r
565 the Null-terminator.\r
566 \r
567 @return The number of Unicode characters in Buffer not including the Null-terminator.\r
568\r
569**/\r
570UINTN\r
571EFIAPI\r
572UnicodeValueToString (\r
573 IN OUT CHAR16 *Buffer,\r
574 IN UINTN Flags,\r
575 IN INT64 Value,\r
576 IN UINTN Width\r
577 )\r
578{\r
bee67555 579 return mPrint2Protocol->UnicodeValueToString (Buffer, Flags, Value, Width);\r
2ad4dad0 580}\r
a0afd019 581\r
2ad4dad0
LG
582/**\r
583 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
584 ASCII format string and a VA_LIST argument list.\r
585 \r
586 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
587 and BufferSize.\r
588 The ASCII string is produced by parsing the format string specified by FormatString.\r
589 Arguments are pulled from the variable argument list specified by Marker based on \r
590 the contents of the format string.\r
591 The number of ASCII characters in the produced output buffer is returned not including\r
592 the Null-terminator.\r
593 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
594\r
595 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
596 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
597 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
598 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
599 ASSERT().\r
600 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
601 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
602 Null-terminator, then ASSERT().\r
603\r
604 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
605 ASCII string.\r
606 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
607 @param FormatString Null-terminated Unicode format string.\r
608 @param Marker VA_LIST marker for the variable argument list.\r
609 \r
610 @return The number of ASCII characters in the produced output buffer not including the\r
611 Null-terminator.\r
612\r
613**/\r
614UINTN\r
615EFIAPI\r
616AsciiVSPrint (\r
617 OUT CHAR8 *StartOfBuffer,\r
618 IN UINTN BufferSize,\r
619 IN CONST CHAR8 *FormatString,\r
620 IN VA_LIST Marker\r
621 )\r
a0afd019 622{\r
97f77815 623 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 624\r
625 DxePrintLibPrint2ProtocolVaListToBaseList (\r
626 TRUE, \r
627 FormatString, \r
628 Marker, \r
629 (BASE_LIST)BaseListMarker, \r
630 sizeof (BaseListMarker) - 8\r
631 );\r
632\r
633 return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
634}\r
635\r
636/**\r
637 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
638 ASCII format string and a BASE_LIST argument list.\r
639 \r
640 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
641 and BufferSize.\r
642 The ASCII string is produced by parsing the format string specified by FormatString.\r
643 Arguments are pulled from the variable argument list specified by Marker based on \r
644 the contents of the format string.\r
645 The number of ASCII characters in the produced output buffer is returned not including\r
646 the Null-terminator.\r
647 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
648\r
649 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
650 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
651 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
652 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
653 ASSERT().\r
654 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
655 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
656 Null-terminator, then ASSERT().\r
657\r
658 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
659 ASCII string.\r
660 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
661 @param FormatString Null-terminated Unicode format string.\r
662 @param Marker BASE_LIST marker for the variable argument list.\r
663 \r
664 @return The number of ASCII characters in the produced output buffer not including the\r
665 Null-terminator.\r
666\r
667**/\r
668UINTN\r
669EFIAPI\r
670AsciiBSPrint (\r
671 OUT CHAR8 *StartOfBuffer,\r
672 IN UINTN BufferSize,\r
673 IN CONST CHAR8 *FormatString,\r
674 IN BASE_LIST Marker\r
675 )\r
676{\r
677 return mPrint2Protocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
a0afd019 678}\r
679\r
2ad4dad0
LG
680/**\r
681 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
682 ASCII format string and variable argument list.\r
683 \r
684 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
685 and BufferSize.\r
686 The ASCII string is produced by parsing the format string specified by FormatString.\r
687 Arguments are pulled from the variable argument list based on the contents of the \r
688 format string.\r
689 The number of ASCII characters in the produced output buffer is returned not including\r
690 the Null-terminator.\r
691 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
692\r
693 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
694 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
695 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
696 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
697 ASSERT().\r
698 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
699 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
700 Null-terminator, then ASSERT().\r
701\r
702 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
703 ASCII string.\r
704 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
705 @param FormatString Null-terminated Unicode format string.\r
71898234 706 @param ... Variable argument list whose contents are accessed based on the \r
707 format string specified by FormatString.\r
ce95aa7a 708\r
2ad4dad0
LG
709 @return The number of ASCII characters in the produced output buffer not including the\r
710 Null-terminator.\r
711\r
712**/\r
a0afd019 713UINTN\r
2ad4dad0 714EFIAPI\r
a0afd019 715AsciiSPrint (\r
716 OUT CHAR8 *StartOfBuffer,\r
717 IN UINTN BufferSize,\r
2ad4dad0 718 IN CONST CHAR8 *FormatString,\r
a0afd019 719 ...\r
720 )\r
2ad4dad0
LG
721{\r
722 VA_LIST Marker;\r
3bbe68a3 723 UINTN NumberOfPrinted;\r
2ad4dad0
LG
724\r
725 VA_START (Marker, FormatString);\r
3bbe68a3 726 NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
727 VA_END (Marker);\r
728 return NumberOfPrinted;\r
2ad4dad0 729}\r
a0afd019 730\r
2ad4dad0
LG
731/**\r
732 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
733 ASCII format string and a VA_LIST argument list.\r
734 \r
735 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
736 and BufferSize.\r
737 The ASCII string is produced by parsing the format string specified by FormatString.\r
738 Arguments are pulled from the variable argument list specified by Marker based on \r
739 the contents of the format string.\r
740 The number of ASCII characters in the produced output buffer is returned not including\r
741 the Null-terminator.\r
742 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
743\r
744 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
745 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
746 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
747 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
748 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
749 ASSERT().\r
750 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
751 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
752 Null-terminator, then ASSERT().\r
753\r
754 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
755 ASCII string.\r
756 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
757 @param FormatString Null-terminated Unicode format string.\r
758 @param Marker VA_LIST marker for the variable argument list.\r
759 \r
760 @return The number of ASCII characters in the produced output buffer not including the\r
761 Null-terminator.\r
762\r
763**/\r
764UINTN\r
765EFIAPI\r
766AsciiVSPrintUnicodeFormat (\r
767 OUT CHAR8 *StartOfBuffer,\r
768 IN UINTN BufferSize,\r
769 IN CONST CHAR16 *FormatString,\r
770 IN VA_LIST Marker\r
771 )\r
a0afd019 772{\r
97f77815 773 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 774\r
775 DxePrintLibPrint2ProtocolVaListToBaseList (\r
776 FALSE, \r
777 (CHAR8 *)FormatString, \r
778 Marker, \r
779 (BASE_LIST)BaseListMarker, \r
780 sizeof (BaseListMarker) - 8\r
781 );\r
782\r
783 return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
784}\r
785\r
786/**\r
787 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
788 ASCII format string and a BASE_LIST argument list.\r
789 \r
790 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
791 and BufferSize.\r
792 The ASCII string is produced by parsing the format string specified by FormatString.\r
793 Arguments are pulled from the variable argument list specified by Marker based on \r
794 the contents of the format string.\r
795 The number of ASCII characters in the produced output buffer is returned not including\r
796 the Null-terminator.\r
797 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
798\r
799 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
800 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
801 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
802 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
803 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
804 ASSERT().\r
805 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
806 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
807 Null-terminator, then ASSERT().\r
808\r
809 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
810 ASCII string.\r
811 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
812 @param FormatString Null-terminated Unicode format string.\r
813 @param Marker BASE_LIST marker for the variable argument list.\r
814 \r
815 @return The number of ASCII characters in the produced output buffer not including the\r
816 Null-terminator.\r
817\r
818**/\r
819UINTN\r
820EFIAPI\r
821AsciiBSPrintUnicodeFormat (\r
822 OUT CHAR8 *StartOfBuffer,\r
823 IN UINTN BufferSize,\r
824 IN CONST CHAR16 *FormatString,\r
825 IN BASE_LIST Marker\r
826 )\r
827{\r
828 return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
2ad4dad0
LG
829}\r
830\r
831/**\r
832 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
833 ASCII format string and variable argument list.\r
834 \r
835 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
836 and BufferSize.\r
837 The ASCII string is produced by parsing the format string specified by FormatString.\r
838 Arguments are pulled from the variable argument list based on the contents of the \r
839 format string.\r
840 The number of ASCII characters in the produced output buffer is returned not including\r
841 the Null-terminator.\r
842 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
843\r
844 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
845 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
846 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
847 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
848 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
849 ASSERT().\r
850 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
851 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
852 Null-terminator, then ASSERT().\r
853\r
854 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
855 ASCII string.\r
856 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
857 @param FormatString Null-terminated Unicode format string.\r
71898234 858 @param ... Variable argument list whose contents are accessed based on the \r
859 format string specified by FormatString.\r
ce95aa7a 860\r
2ad4dad0
LG
861 @return The number of ASCII characters in the produced output buffer not including the\r
862 Null-terminator.\r
863\r
864**/\r
865UINTN\r
866EFIAPI\r
867AsciiSPrintUnicodeFormat (\r
868 OUT CHAR8 *StartOfBuffer,\r
869 IN UINTN BufferSize,\r
870 IN CONST CHAR16 *FormatString,\r
871 ...\r
872 )\r
873{\r
874 VA_LIST Marker;\r
3bbe68a3 875 UINTN NumberOfPrinted;\r
a0afd019 876\r
877 VA_START (Marker, FormatString);\r
3bbe68a3 878 NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
879 VA_END (Marker);\r
880 return NumberOfPrinted;\r
2ad4dad0
LG
881}\r
882\r
883\r
884/**\r
885 Converts a decimal value to a Null-terminated ASCII string.\r
886 \r
887 Converts the decimal number specified by Value to a Null-terminated ASCII string \r
888 specified by Buffer containing at most Width characters. No padding of spaces \r
889 is ever performed.\r
890 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
891 The number of ASCII characters in Buffer is returned not including the Null-terminator.\r
892 If the conversion contains more than Width characters, then only the first Width\r
893 characters are returned, and the total number of characters required to perform\r
894 the conversion is returned.\r
895 Additional conversion parameters are specified in Flags. \r
896 The Flags bit LEFT_JUSTIFY is always ignored.\r
897 All conversions are left justified in Buffer.\r
898 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
899 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
900 are inserted every 3rd digit starting from the right.\r
df8d0595 901 If RADIX_HEX is set in Flags, then the output buffer will be \r
2ad4dad0 902 formatted in hexadecimal format.\r
df8d0595 903 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
2ad4dad0
LG
904 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
905 then Buffer is padded with '0' characters so the combination of the optional '-' \r
906 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
907 add up to Width characters.\r
908 \r
909 If Buffer is NULL, then ASSERT().\r
910 If unsupported bits are set in Flags, then ASSERT().\r
df8d0595 911 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
2ad4dad0
LG
912 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
913\r
914 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
915 ASCII string.\r
916 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
917 @param Value The 64-bit signed value to convert to a string.\r
918 @param Width The maximum number of ASCII characters to place in Buffer, not including\r
919 the Null-terminator.\r
920 \r
921 @return The number of ASCII characters in Buffer not including the Null-terminator.\r
922\r
923**/\r
924UINTN\r
925EFIAPI\r
926AsciiValueToString (\r
ea99d5d1 927 OUT CHAR8 *Buffer,\r
928 IN UINTN Flags,\r
929 IN INT64 Value,\r
930 IN UINTN Width\r
2ad4dad0
LG
931 )\r
932{\r
bee67555 933 return mPrint2Protocol->AsciiValueToString (Buffer, Flags, Value, Width);\r
a0afd019 934}\r
f405c067 935\r
936#define PREFIX_SIGN BIT1\r
937#define PREFIX_BLANK BIT2\r
938#define LONG_TYPE BIT4\r
939#define OUTPUT_UNICODE BIT6\r
940#define FORMAT_UNICODE BIT8\r
941#define PAD_TO_WIDTH BIT9\r
942#define ARGUMENT_UNICODE BIT10\r
943#define PRECISION BIT11\r
944#define ARGUMENT_REVERSED BIT12\r
945#define COUNT_ONLY_NO_PRINT BIT13\r
946\r
947//\r
948// Record date and time information\r
949//\r
950typedef struct {\r
951 UINT16 Year;\r
952 UINT8 Month;\r
953 UINT8 Day;\r
954 UINT8 Hour;\r
955 UINT8 Minute;\r
956 UINT8 Second;\r
957 UINT8 Pad1;\r
958 UINT32 Nanosecond;\r
959 INT16 TimeZone;\r
960 UINT8 Daylight;\r
961 UINT8 Pad2;\r
962} TIME;\r
963\r
964GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
965\r
966/**\r
967 Internal function that convert a number to a string in Buffer.\r
968\r
969 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.\r
970\r
971 @param Buffer Location to place the ASCII string of Value.\r
972 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.\r
973 @param Radix Radix of the value\r
974\r
975 @return A pointer to the end of buffer filled with ASCII string.\r
976\r
977**/\r
978CHAR8 *\r
979InternalPrintLibValueToString (\r
980 IN OUT CHAR8 *Buffer, \r
981 IN INT64 Value, \r
982 IN UINTN Radix\r
983 )\r
984{\r
985 UINT32 Remainder;\r
986\r
987 //\r
988 // Loop to convert one digit at a time in reverse order\r
989 //\r
990 *Buffer = 0;\r
991 do {\r
992 Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);\r
993 *(++Buffer) = mHexStr[Remainder];\r
994 } while (Value != 0);\r
995\r
996 //\r
997 // Return pointer of the end of filled buffer.\r
998 //\r
999 return Buffer;\r
1000}\r
1001\r
1002/**\r
1003 Worker function that produces a Null-terminated string in an output buffer \r
1004 based on a Null-terminated format string and a VA_LIST argument list.\r
1005\r
1006 VSPrint function to process format and place the results in Buffer. Since a \r
1007 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1008 this is the main print working routine.\r
1009\r
1010 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r
1011\r
1012 @param[out] Buffer The character buffer to print the results of the \r
1013 parsing of Format into.\r
1014 @param[in] BufferSize The maximum number of characters to put into \r
1015 buffer.\r
1016 @param[in] Flags Initial flags value.\r
1017 Can only have FORMAT_UNICODE, OUTPUT_UNICODE, \r
1018 and COUNT_ONLY_NO_PRINT set.\r
1019 @param[in] Format A Null-terminated format string.\r
1020 @param[in] VaListMarker VA_LIST style variable argument list consumed by\r
1021 processing Format.\r
1022 @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r
1023 by processing Format.\r
1024\r
1025 @return The number of characters printed not including the Null-terminator.\r
1026 If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r
1027 modification to Buffer.\r
1028\r
1029**/\r
1030UINTN\r
1031InternalPrintLibSPrintMarker (\r
1032 OUT CHAR8 *Buffer,\r
1033 IN UINTN BufferSize,\r
1034 IN UINTN Flags,\r
1035 IN CONST CHAR8 *Format,\r
1036 IN VA_LIST VaListMarker, OPTIONAL\r
1037 IN BASE_LIST BaseListMarker OPTIONAL\r
1038 );\r
1039\r
1040/**\r
1041 Worker function that produces a Null-terminated string in an output buffer \r
1042 based on a Null-terminated format string and variable argument list.\r
1043\r
1044 VSPrint function to process format and place the results in Buffer. Since a \r
1045 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1046 this is the main print working routine\r
1047\r
1048 @param StartOfBuffer The character buffer to print the results of the parsing\r
1049 of Format into.\r
1050 @param BufferSize The maximum number of characters to put into buffer.\r
1051 Zero means no limit.\r
1052 @param Flags Initial flags value.\r
1053 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r
1054 @param FormatString A Null-terminated format string.\r
1055 @param ... The variable argument list.\r
1056\r
1057 @return The number of characters printed.\r
1058\r
1059**/\r
1060UINTN\r
1061EFIAPI\r
1062InternalPrintLibSPrint (\r
1063 OUT CHAR8 *StartOfBuffer,\r
1064 IN UINTN BufferSize,\r
1065 IN UINTN Flags,\r
1066 IN CONST CHAR8 *FormatString,\r
1067 ...\r
1068 )\r
1069{\r
1070 VA_LIST Marker;\r
3bbe68a3 1071 UINTN NumberOfPrinted;\r
f405c067 1072\r
1073 VA_START (Marker, FormatString);\r
3bbe68a3 1074 NumberOfPrinted = InternalPrintLibSPrintMarker (StartOfBuffer, BufferSize, Flags, FormatString, Marker, NULL);\r
1075 VA_END (Marker);\r
1076 return NumberOfPrinted;\r
f405c067 1077}\r
1078\r
586d81d1
LG
1079#define WARNING_STATUS_NUMBER 5\r
1080#define ERROR_STATUS_NUMBER 33\r
f405c067 1081\r
1082GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {\r
1083 "Success", // RETURN_SUCCESS = 0\r
1084 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1\r
1085 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2\r
1086 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3\r
1087 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4\r
586d81d1 1088 "Warning Stale Data", // RETURN_WARN_STALE_DATA = 5\r
f405c067 1089 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT\r
1090 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT\r
1091 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT\r
1092 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT\r
1093 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT\r
1094 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT\r
1095 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT\r
1096 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT\r
1097 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT\r
1098 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT\r
1099 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT\r
1100 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT\r
1101 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT\r
1102 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT\r
1103 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT\r
1104 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT\r
1105 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT\r
1106 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT\r
1107 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT\r
1108 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT\r
1109 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT\r
1110 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT\r
1111 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT\r
586d81d1
LG
1112 "Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT\r
1113 "Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT\r
1114 "Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT\r
1115 "CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT\r
1116 "End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT\r
1117 "Reserved (29)", // RESERVED = 29 | MAX_BIT\r
1118 "Reserved (30)", // RESERVED = 30 | MAX_BIT\r
1119 "End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT\r
1120 "Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT\r
1121 "Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT\r
f405c067 1122};\r
1123\r
586d81d1
LG
1124/**\r
1125 Internal function that places the character into the Buffer.\r
1126\r
1127 Internal function that places ASCII or Unicode character into the Buffer.\r
1128\r
1129 @param Buffer The buffer to place the Unicode or ASCII string.\r
1130 @param EndBuffer The end of the input Buffer. No characters will be\r
1131 placed after that. \r
1132 @param Length The count of character to be placed into Buffer.\r
1133 (Negative value indicates no buffer fill.)\r
1134 @param Character The character to be placed into Buffer.\r
1135 @param Increment The character increment in Buffer.\r
1136\r
1137 @return Buffer.\r
1138\r
1139**/\r
1140CHAR8 *\r
1141InternalPrintLibFillBuffer (\r
1142 OUT CHAR8 *Buffer,\r
1143 IN CHAR8 *EndBuffer,\r
1144 IN INTN Length,\r
1145 IN UINTN Character,\r
1146 IN INTN Increment\r
1147 )\r
1148{\r
1149 INTN Index;\r
1150 \r
1151 for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) {\r
1152 *Buffer = (CHAR8) Character;\r
1153 if (Increment != 1) {\r
1154 *(Buffer + 1) = (CHAR8)(Character >> 8);\r
1155 }\r
1156 Buffer += Increment;\r
1157 }\r
1158\r
1159 return Buffer;\r
1160}\r
1161\r
f405c067 1162/**\r
1163 Worker function that produces a Null-terminated string in an output buffer \r
1164 based on a Null-terminated format string and a VA_LIST argument list.\r
1165\r
1166 VSPrint function to process format and place the results in Buffer. Since a \r
1167 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1168 this is the main print working routine.\r
1169\r
1170 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r
1171\r
1172 @param[out] Buffer The character buffer to print the results of the \r
1173 parsing of Format into.\r
1174 @param[in] BufferSize The maximum number of characters to put into \r
1175 buffer.\r
1176 @param[in] Flags Initial flags value.\r
1177 Can only have FORMAT_UNICODE, OUTPUT_UNICODE, \r
1178 and COUNT_ONLY_NO_PRINT set.\r
1179 @param[in] Format A Null-terminated format string.\r
1180 @param[in] VaListMarker VA_LIST style variable argument list consumed by\r
1181 processing Format.\r
1182 @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r
1183 by processing Format.\r
1184\r
1185 @return The number of characters printed not including the Null-terminator.\r
1186 If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r
1187 modification to Buffer.\r
1188\r
1189**/\r
1190UINTN\r
1191InternalPrintLibSPrintMarker (\r
1192 OUT CHAR8 *Buffer,\r
1193 IN UINTN BufferSize,\r
1194 IN UINTN Flags,\r
1195 IN CONST CHAR8 *Format,\r
1196 IN VA_LIST VaListMarker, OPTIONAL\r
1197 IN BASE_LIST BaseListMarker OPTIONAL\r
1198 )\r
1199{\r
586d81d1 1200 CHAR8 *OriginalBuffer;\r
f405c067 1201 CHAR8 *EndBuffer;\r
1202 CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
1203 UINT32 BytesPerOutputCharacter;\r
1204 UINTN BytesPerFormatCharacter;\r
1205 UINTN FormatMask;\r
1206 UINTN FormatCharacter;\r
1207 UINTN Width;\r
1208 UINTN Precision;\r
1209 INT64 Value;\r
1210 CONST CHAR8 *ArgumentString;\r
1211 UINTN Character;\r
1212 GUID *TmpGuid;\r
1213 TIME *TmpTime;\r
1214 UINTN Count;\r
1215 UINTN ArgumentMask;\r
1216 INTN BytesPerArgumentCharacter;\r
1217 UINTN ArgumentCharacter;\r
1218 BOOLEAN Done;\r
1219 UINTN Index;\r
1220 CHAR8 Prefix;\r
1221 BOOLEAN ZeroPad;\r
1222 BOOLEAN Comma;\r
1223 UINTN Digits;\r
1224 UINTN Radix;\r
1225 RETURN_STATUS Status;\r
1226 UINT32 GuidData1;\r
1227 UINT16 GuidData2;\r
1228 UINT16 GuidData3;\r
be5ec8c5 1229 UINTN LengthToReturn;\r
f405c067 1230\r
1231 //\r
1232 // If you change this code be sure to match the 2 versions of this function.\r
1233 // Nearly identical logic is found in the BasePrintLib and \r
1234 // DxePrintLibPrint2Protocol (both PrintLib instances).\r
1235 //\r
1236\r
586d81d1
LG
1237 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {\r
1238 if (BufferSize == 0) {\r
1239 Buffer = NULL;\r
1240 }\r
1241 } else {\r
1242 //\r
1243 // We can run without a Buffer for counting only.\r
1244 //\r
1245 if (BufferSize == 0) {\r
1246 return 0;\r
1247 }\r
1248 ASSERT (Buffer != NULL);\r
1249 }\r
f405c067 1250\r
ad9aa87b 1251 if ((Flags & OUTPUT_UNICODE) != 0) {\r
f405c067 1252 BytesPerOutputCharacter = 2;\r
1253 } else {\r
1254 BytesPerOutputCharacter = 1;\r
1255 }\r
1256\r
1257 LengthToReturn = 0;\r
586d81d1
LG
1258 EndBuffer = NULL;\r
1259 OriginalBuffer = NULL;\r
f405c067 1260\r
1261 //\r
1262 // Reserve space for the Null terminator.\r
1263 //\r
586d81d1
LG
1264 if (Buffer != NULL) {\r
1265 BufferSize--;\r
1266 OriginalBuffer = Buffer;\r
f405c067 1267\r
586d81d1
LG
1268 //\r
1269 // Set the tag for the end of the input Buffer.\r
1270 //\r
1271 EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;\r
1272 }\r
f405c067 1273\r
1274 if ((Flags & FORMAT_UNICODE) != 0) {\r
1275 //\r
1276 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
1277 // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
1278 //\r
1279 ASSERT (StrSize ((CHAR16 *) Format) != 0);\r
1280 BytesPerFormatCharacter = 2;\r
1281 FormatMask = 0xffff;\r
1282 } else {\r
1283 //\r
1284 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength\r
1285 // Ascii characters if PcdMaximumAsciiStringLength is not zero. \r
1286 //\r
1287 ASSERT (AsciiStrSize (Format) != 0);\r
1288 BytesPerFormatCharacter = 1;\r
1289 FormatMask = 0xff;\r
1290 }\r
1291\r
1292 //\r
1293 // Get the first character from the format string\r
1294 //\r
1295 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1296\r
1297 //\r
1298 // Loop until the end of the format string is reached or the output buffer is full\r
1299 //\r
586d81d1
LG
1300 while (FormatCharacter != 0) {\r
1301 if ((Buffer != NULL) && (Buffer >= EndBuffer)) {\r
1302 break;\r
1303 }\r
f405c067 1304 //\r
1305 // Clear all the flag bits except those that may have been passed in\r
1306 //\r
586d81d1 1307 Flags &= (UINTN) (OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);\r
f405c067 1308\r
1309 //\r
1310 // Set the default width to zero, and the default precision to 1\r
1311 //\r
1312 Width = 0;\r
1313 Precision = 1;\r
1314 Prefix = 0;\r
1315 Comma = FALSE;\r
1316 ZeroPad = FALSE;\r
1317 Count = 0;\r
1318 Digits = 0;\r
1319\r
1320 switch (FormatCharacter) {\r
1321 case '%':\r
1322 //\r
1323 // Parse Flags and Width\r
1324 //\r
1325 for (Done = FALSE; !Done; ) {\r
1326 Format += BytesPerFormatCharacter;\r
1327 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1328 switch (FormatCharacter) {\r
1329 case '.': \r
1330 Flags |= PRECISION; \r
1331 break;\r
1332 case '-': \r
1333 Flags |= LEFT_JUSTIFY; \r
1334 break;\r
1335 case '+': \r
1336 Flags |= PREFIX_SIGN; \r
1337 break;\r
1338 case ' ': \r
1339 Flags |= PREFIX_BLANK; \r
1340 break;\r
1341 case ',': \r
1342 Flags |= COMMA_TYPE; \r
1343 break;\r
1344 case 'L':\r
1345 case 'l': \r
1346 Flags |= LONG_TYPE; \r
1347 break;\r
1348 case '*':\r
1349 if ((Flags & PRECISION) == 0) {\r
1350 Flags |= PAD_TO_WIDTH;\r
1351 if (BaseListMarker == NULL) {\r
1352 Width = VA_ARG (VaListMarker, UINTN);\r
1353 } else {\r
1354 Width = BASE_ARG (BaseListMarker, UINTN);\r
1355 }\r
1356 } else {\r
1357 if (BaseListMarker == NULL) {\r
1358 Precision = VA_ARG (VaListMarker, UINTN);\r
1359 } else {\r
1360 Precision = BASE_ARG (BaseListMarker, UINTN);\r
1361 }\r
1362 }\r
1363 break;\r
1364 case '0':\r
1365 if ((Flags & PRECISION) == 0) {\r
1366 Flags |= PREFIX_ZERO;\r
1367 }\r
1368 case '1':\r
1369 case '2':\r
1370 case '3':\r
1371 case '4':\r
1372 case '5':\r
1373 case '6':\r
1374 case '7':\r
1375 case '8':\r
1376 case '9':\r
1377 for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){\r
1378 Count = (Count * 10) + FormatCharacter - '0';\r
1379 Format += BytesPerFormatCharacter;\r
1380 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1381 }\r
1382 Format -= BytesPerFormatCharacter;\r
1383 if ((Flags & PRECISION) == 0) {\r
1384 Flags |= PAD_TO_WIDTH;\r
1385 Width = Count;\r
1386 } else {\r
1387 Precision = Count;\r
1388 }\r
1389 break;\r
1390 \r
1391 case '\0':\r
1392 //\r
1393 // Make no output if Format string terminates unexpectedly when\r
1394 // looking up for flag, width, precision and type. \r
1395 //\r
1396 Format -= BytesPerFormatCharacter;\r
1397 Precision = 0;\r
1398 //\r
1399 // break skipped on purpose.\r
1400 //\r
1401 default:\r
1402 Done = TRUE;\r
1403 break;\r
1404 }\r
1405 } \r
1406\r
1407 //\r
1408 // Handle each argument type\r
1409 //\r
1410 switch (FormatCharacter) {\r
1411 case 'p':\r
1412 //\r
1413 // Flag space, +, 0, L & l are invalid for type p.\r
1414 //\r
586d81d1 1415 Flags &= ~((UINTN) (PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE));\r
f405c067 1416 if (sizeof (VOID *) > 4) {\r
1417 Flags |= LONG_TYPE;\r
1418 }\r
586d81d1
LG
1419 //\r
1420 // break skipped on purpose\r
1421 //\r
f405c067 1422 case 'X':\r
1423 Flags |= PREFIX_ZERO;\r
1424 //\r
1425 // break skipped on purpose\r
1426 //\r
1427 case 'x':\r
1428 Flags |= RADIX_HEX;\r
1429 //\r
1430 // break skipped on purpose\r
1431 //\r
1432 case 'd':\r
1433 if ((Flags & LONG_TYPE) == 0) {\r
1434 //\r
1435 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r
1436 // This assumption is made so the format string definition is compatible with the ANSI C\r
1437 // Specification for formatted strings. It is recommended that the Base Types be used \r
1438 // everywhere, but in this one case, compliance with ANSI C is more important, and \r
1439 // provides an implementation that is compatible with that largest possible set of CPU \r
1440 // architectures. This is why the type "int" is used in this one case.\r
1441 //\r
1442 if (BaseListMarker == NULL) {\r
1443 Value = VA_ARG (VaListMarker, int);\r
1444 } else {\r
1445 Value = BASE_ARG (BaseListMarker, int);\r
1446 }\r
1447 } else {\r
1448 if (BaseListMarker == NULL) {\r
1449 Value = VA_ARG (VaListMarker, INT64);\r
1450 } else {\r
1451 Value = BASE_ARG (BaseListMarker, INT64);\r
1452 }\r
1453 }\r
1454 if ((Flags & PREFIX_BLANK) != 0) {\r
1455 Prefix = ' ';\r
1456 }\r
1457 if ((Flags & PREFIX_SIGN) != 0) {\r
1458 Prefix = '+';\r
1459 }\r
1460 if ((Flags & COMMA_TYPE) != 0) {\r
1461 Comma = TRUE;\r
1462 }\r
1463 if ((Flags & RADIX_HEX) == 0) {\r
1464 Radix = 10;\r
1465 if (Comma) {\r
586d81d1 1466 Flags &= ~((UINTN) PREFIX_ZERO);\r
f405c067 1467 Precision = 1;\r
1468 }\r
1469 if (Value < 0) {\r
1470 Flags |= PREFIX_SIGN;\r
1471 Prefix = '-';\r
1472 Value = -Value;\r
1473 }\r
1474 } else {\r
1475 Radix = 16;\r
1476 Comma = FALSE;\r
1477 if ((Flags & LONG_TYPE) == 0 && Value < 0) {\r
1478 //\r
1479 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r
1480 // This assumption is made so the format string definition is compatible with the ANSI C\r
1481 // Specification for formatted strings. It is recommended that the Base Types be used \r
1482 // everywhere, but in this one case, compliance with ANSI C is more important, and \r
1483 // provides an implementation that is compatible with that largest possible set of CPU \r
1484 // architectures. This is why the type "unsigned int" is used in this one case.\r
1485 //\r
1486 Value = (unsigned int)Value;\r
1487 }\r
1488 }\r
1489 //\r
1490 // Convert Value to a reversed string\r
1491 //\r
1492 Count = InternalPrintLibValueToString (ValueBuffer, Value, Radix) - ValueBuffer;\r
1493 if (Value == 0 && Precision == 0) {\r
1494 Count = 0;\r
1495 }\r
1496 ArgumentString = (CHAR8 *)ValueBuffer + Count;\r
1497 \r
1498 Digits = Count % 3;\r
1499 if (Digits != 0) {\r
1500 Digits = 3 - Digits;\r
1501 }\r
1502 if (Comma && Count != 0) {\r
1503 Count += ((Count - 1) / 3);\r
1504 }\r
1505 if (Prefix != 0) {\r
1506 Count++;\r
1507 Precision++;\r
1508 }\r
1509 Flags |= ARGUMENT_REVERSED;\r
1510 ZeroPad = TRUE;\r
1511 if ((Flags & PREFIX_ZERO) != 0) {\r
1512 if ((Flags & LEFT_JUSTIFY) == 0) {\r
1513 if ((Flags & PAD_TO_WIDTH) != 0) {\r
1514 if ((Flags & PRECISION) == 0) {\r
1515 Precision = Width;\r
1516 }\r
1517 }\r
1518 }\r
1519 }\r
1520 break;\r
1521\r
1522 case 's':\r
1523 case 'S':\r
1524 Flags |= ARGUMENT_UNICODE;\r
1525 //\r
1526 // break skipped on purpose\r
1527 //\r
1528 case 'a':\r
1529 if (BaseListMarker == NULL) {\r
1530 ArgumentString = VA_ARG (VaListMarker, CHAR8 *);\r
1531 } else {\r
1532 ArgumentString = BASE_ARG (BaseListMarker, CHAR8 *);\r
1533 }\r
1534 if (ArgumentString == NULL) {\r
6e1e5405 1535 Flags &= (~(UINTN)ARGUMENT_UNICODE);\r
f405c067 1536 ArgumentString = "<null string>";\r
1537 }\r
1538 //\r
1539 // Set the default precision for string to be zero if not specified.\r
1540 //\r
1541 if ((Flags & PRECISION) == 0) {\r
1542 Precision = 0;\r
1543 }\r
1544 break;\r
1545\r
1546 case 'c':\r
1547 if (BaseListMarker == NULL) {\r
1548 Character = VA_ARG (VaListMarker, UINTN) & 0xffff;\r
1549 } else {\r
1550 Character = BASE_ARG (BaseListMarker, UINTN) & 0xffff;\r
1551 }\r
1552 ArgumentString = (CHAR8 *)&Character;\r
1553 Flags |= ARGUMENT_UNICODE;\r
1554 break;\r
1555\r
1556 case 'g':\r
1557 if (BaseListMarker == NULL) {\r
1558 TmpGuid = VA_ARG (VaListMarker, GUID *);\r
1559 } else {\r
1560 TmpGuid = BASE_ARG (BaseListMarker, GUID *);\r
1561 }\r
1562 if (TmpGuid == NULL) {\r
1563 ArgumentString = "<null guid>";\r
1564 } else {\r
1565 GuidData1 = ReadUnaligned32 (&(TmpGuid->Data1));\r
1566 GuidData2 = ReadUnaligned16 (&(TmpGuid->Data2));\r
1567 GuidData3 = ReadUnaligned16 (&(TmpGuid->Data3));\r
1568 InternalPrintLibSPrint (\r
1569 ValueBuffer,\r
1570 MAXIMUM_VALUE_CHARACTERS, \r
1571 0,\r
1572 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r
1573 GuidData1,\r
1574 GuidData2,\r
1575 GuidData3,\r
1576 TmpGuid->Data4[0],\r
1577 TmpGuid->Data4[1],\r
1578 TmpGuid->Data4[2],\r
1579 TmpGuid->Data4[3],\r
1580 TmpGuid->Data4[4],\r
1581 TmpGuid->Data4[5],\r
1582 TmpGuid->Data4[6],\r
1583 TmpGuid->Data4[7]\r
1584 );\r
1585 ArgumentString = ValueBuffer;\r
1586 }\r
1587 break;\r
1588\r
1589 case 't':\r
1590 if (BaseListMarker == NULL) {\r
1591 TmpTime = VA_ARG (VaListMarker, TIME *); \r
1592 } else {\r
1593 TmpTime = BASE_ARG (BaseListMarker, TIME *); \r
1594 }\r
1595 if (TmpTime == NULL) {\r
1596 ArgumentString = "<null time>";\r
1597 } else {\r
1598 InternalPrintLibSPrint (\r
1599 ValueBuffer,\r
1600 MAXIMUM_VALUE_CHARACTERS,\r
1601 0,\r
1602 "%02d/%02d/%04d %02d:%02d",\r
1603 TmpTime->Month,\r
1604 TmpTime->Day,\r
1605 TmpTime->Year,\r
1606 TmpTime->Hour,\r
1607 TmpTime->Minute\r
1608 );\r
1609 ArgumentString = ValueBuffer;\r
1610 }\r
1611 break;\r
1612\r
1613 case 'r':\r
1614 if (BaseListMarker == NULL) {\r
1615 Status = VA_ARG (VaListMarker, RETURN_STATUS);\r
1616 } else {\r
1617 Status = BASE_ARG (BaseListMarker, RETURN_STATUS);\r
1618 }\r
1619 ArgumentString = ValueBuffer;\r
1620 if (RETURN_ERROR (Status)) {\r
1621 //\r
1622 // Clear error bit\r
1623 //\r
1624 Index = Status & ~MAX_BIT;\r
1625 if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {\r
1626 ArgumentString = mStatusString [Index + WARNING_STATUS_NUMBER];\r
1627 }\r
1628 } else {\r
1629 Index = Status;\r
1630 if (Index <= WARNING_STATUS_NUMBER) {\r
1631 ArgumentString = mStatusString [Index];\r
1632 }\r
1633 }\r
1634 if (ArgumentString == ValueBuffer) {\r
1635 InternalPrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);\r
1636 }\r
1637 break;\r
1638\r
1639 case '\r':\r
1640 Format += BytesPerFormatCharacter;\r
1641 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1642 if (FormatCharacter == '\n') {\r
1643 //\r
1644 // Translate '\r\n' to '\r\n'\r
1645 //\r
1646 ArgumentString = "\r\n";\r
1647 } else {\r
1648 //\r
1649 // Translate '\r' to '\r'\r
1650 //\r
1651 ArgumentString = "\r";\r
1652 Format -= BytesPerFormatCharacter;\r
1653 }\r
1654 break;\r
1655\r
1656 case '\n':\r
1657 //\r
1658 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r
1659 //\r
1660 ArgumentString = "\r\n";\r
1661 Format += BytesPerFormatCharacter;\r
1662 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1663 if (FormatCharacter != '\r') {\r
1664 Format -= BytesPerFormatCharacter;\r
1665 }\r
1666 break;\r
1667\r
1668 case '%':\r
1669 default:\r
1670 //\r
1671 // if the type is '%' or unknown, then print it to the screen\r
1672 //\r
1673 ArgumentString = (CHAR8 *)&FormatCharacter;\r
1674 Flags |= ARGUMENT_UNICODE;\r
1675 break;\r
1676 }\r
1677 break;\r
1678 \r
1679 case '\r':\r
1680 Format += BytesPerFormatCharacter;\r
1681 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1682 if (FormatCharacter == '\n') {\r
1683 //\r
1684 // Translate '\r\n' to '\r\n'\r
1685 //\r
1686 ArgumentString = "\r\n";\r
1687 } else {\r
1688 //\r
1689 // Translate '\r' to '\r'\r
1690 //\r
1691 ArgumentString = "\r";\r
1692 Format -= BytesPerFormatCharacter;\r
1693 }\r
1694 break;\r
1695\r
1696 case '\n':\r
1697 //\r
1698 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r
1699 //\r
1700 ArgumentString = "\r\n";\r
1701 Format += BytesPerFormatCharacter;\r
1702 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1703 if (FormatCharacter != '\r') {\r
1704 Format -= BytesPerFormatCharacter;\r
1705 }\r
1706 break;\r
1707\r
1708 default:\r
1709 ArgumentString = (CHAR8 *)&FormatCharacter;\r
1710 Flags |= ARGUMENT_UNICODE;\r
1711 break;\r
1712 }\r
1713\r
1714 //\r
1715 // Retrieve the ArgumentString attriubutes\r
1716 //\r
1717 if ((Flags & ARGUMENT_UNICODE) != 0) {\r
1718 ArgumentMask = 0xffff;\r
1719 BytesPerArgumentCharacter = 2;\r
1720 } else {\r
1721 ArgumentMask = 0xff;\r
1722 BytesPerArgumentCharacter = 1;\r
1723 }\r
1724 if ((Flags & ARGUMENT_REVERSED) != 0) {\r
1725 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;\r
1726 } else {\r
1727 //\r
1728 // Compute the number of characters in ArgumentString and store it in Count\r
1729 // ArgumentString is either null-terminated, or it contains Precision characters\r
1730 //\r
1731 for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {\r
1732 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;\r
1733 if (ArgumentCharacter == 0) {\r
1734 break;\r
1735 }\r
1736 }\r
1737 }\r
1738\r
1739 if (Precision < Count) {\r
1740 Precision = Count;\r
1741 }\r
1742\r
1743 //\r
1744 // Pad before the string\r
1745 //\r
1746 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r
6bae492f 1747 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
586d81d1
LG
1748 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1749 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
1750 }\r
f405c067 1751 }\r
1752\r
1753 if (ZeroPad) {\r
1754 if (Prefix != 0) {\r
6bae492f 1755 LengthToReturn += (1 * BytesPerOutputCharacter);\r
586d81d1
LG
1756 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1757 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
1758 }\r
f405c067 1759 }\r
6bae492f 1760 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
586d81d1
LG
1761 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1762 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);\r
1763 }\r
f405c067 1764 } else {\r
6bae492f 1765 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
586d81d1
LG
1766 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1767 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
1768 }\r
f405c067 1769 if (Prefix != 0) {\r
6bae492f 1770 LengthToReturn += (1 * BytesPerOutputCharacter);\r
586d81d1
LG
1771 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1772 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
1773 }\r
f405c067 1774 }\r
1775 }\r
1776\r
1777 //\r
1778 // Output the Prefix character if it is present\r
1779 //\r
1780 Index = 0;\r
1781 if (Prefix != 0) {\r
1782 Index++;\r
1783 }\r
1784\r
1785 //\r
1786 // Copy the string into the output buffer performing the required type conversions\r
1787 //\r
1788 while (Index < Count) {\r
1789 ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;\r
1790\r
6bae492f 1791 LengthToReturn += (1 * BytesPerOutputCharacter);\r
586d81d1
LG
1792 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1793 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
1794 }\r
f405c067 1795 ArgumentString += BytesPerArgumentCharacter;\r
1796 Index++;\r
1797 if (Comma) {\r
1798 Digits++;\r
1799 if (Digits == 3) {\r
1800 Digits = 0;\r
1801 Index++;\r
1802 if (Index < Count) {\r
6bae492f 1803 LengthToReturn += (1 * BytesPerOutputCharacter);\r
586d81d1
LG
1804 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1805 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);\r
1806 }\r
f405c067 1807 }\r
1808 }\r
1809 }\r
1810 }\r
1811\r
1812 //\r
1813 // Pad after the string\r
1814 //\r
1815 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r
6bae492f 1816 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
586d81d1
LG
1817 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
1818 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
1819 }\r
f405c067 1820 }\r
1821\r
1822 //\r
1823 // Get the next character from the format string\r
1824 //\r
1825 Format += BytesPerFormatCharacter;\r
1826\r
1827 //\r
1828 // Get the next character from the format string\r
1829 //\r
1830 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1831 }\r
1832\r
586d81d1
LG
1833 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {\r
1834 return (LengthToReturn / BytesPerOutputCharacter);\r
1835 }\r
1836\r
1837 ASSERT (Buffer != NULL);\r
1838 //\r
1839 // Null terminate the Unicode or ASCII string\r
1840 //\r
1841 InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);\r
1842 //\r
1843 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength\r
1844 // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
1845 //\r
1846 ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));\r
1847 //\r
1848 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength\r
1849 // ASCII characters if PcdMaximumAsciiStringLength is not zero. \r
1850 //\r
1851 ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));\r
1852\r
1853 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);\r
f405c067 1854}\r
1855\r
1856/**\r
1857 Returns the number of characters that would be produced by if the formatted \r
1858 output were produced not including the Null-terminator.\r
1859\r
1860 If FormatString is NULL, then ASSERT().\r
1861 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
1862\r
1863 @param[in] FormatString A Null-terminated Unicode format string.\r
1864 @param[in] Marker VA_LIST marker for the variable argument list.\r
1865\r
1866 @return The number of characters that would be produced, not including the \r
1867 Null-terminator.\r
1868**/\r
1869UINTN\r
1870EFIAPI\r
1871SPrintLength (\r
1872 IN CONST CHAR16 *FormatString,\r
1873 IN VA_LIST Marker\r
1874 )\r
1875{\r
1876 ASSERT(FormatString != NULL);\r
1877 return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
1878}\r
1879\r
1880/**\r
1881 Returns the number of characters that would be produced by if the formatted \r
1882 output were produced not including the Null-terminator.\r
1883\r
1884 If FormatString is NULL, then ASSERT().\r
1885\r
1886 @param[in] FormatString A Null-terminated ASCII format string.\r
1887 @param[in] Marker VA_LIST marker for the variable argument list.\r
1888\r
1889 @return The number of characters that would be produced, not including the \r
1890 Null-terminator.\r
1891**/\r
1892UINTN\r
1893EFIAPI\r
1894SPrintLengthAsciiFormat (\r
1895 IN CONST CHAR8 *FormatString,\r
1896 IN VA_LIST Marker\r
1897 )\r
1898{\r
1899 ASSERT(FormatString != NULL);\r
1900 return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
1901}\r