]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
Update GenFw tool to zero time/date by default.
[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
bee67555 9Copyright (c) 2009, Intel Corporation\r
a0afd019 10All rights reserved. This program and the accompanying materials\r
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
504dcb0a 21\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
a0afd019 27#include <Library/UefiBootServicesTableLib.h>\r
bee67555 28#include <Library/DebugLib.h>\r
a0afd019 29\r
bee67555 30EFI_PRINT2_PROTOCOL *mPrint2Protocol = NULL;\r
a0afd019 31\r
ce95aa7a 32/**\r
bee67555 33 The constructor function caches the pointer to Print2 protocol.\r
34 \r
35 The constructor function locates Print2 protocol from protocol database.\r
36 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
ce95aa7a 37\r
bee67555 38 @param ImageHandle The firmware allocated handle for the EFI image.\r
39 @param SystemTable A pointer to the EFI System Table.\r
40 \r
41 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
ce95aa7a 42\r
43**/\r
2ad4dad0
LG
44EFI_STATUS\r
45EFIAPI\r
bee67555 46PrintLibConstructor (\r
47 IN EFI_HANDLE ImageHandle,\r
48 IN EFI_SYSTEM_TABLE *SystemTable\r
a0afd019 49 )\r
a0afd019 50{\r
bee67555 51 EFI_STATUS Status;\r
52\r
53 Status = gBS->LocateProtocol (\r
54 &gEfiPrint2ProtocolGuid,\r
55 NULL,\r
56 (VOID**) &mPrint2Protocol\r
57 );\r
58 ASSERT_EFI_ERROR (Status);\r
59 ASSERT (mPrint2Protocol != NULL);\r
60\r
61 return Status;\r
2ad4dad0
LG
62}\r
63\r
bee67555 64\r
504dcb0a 65/**\r
66 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated \r
67 format string.\r
68\r
69 @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.\r
70 @param Format Null-terminated format string.\r
71 @param VaListMarker VA_LIST style variable argument list consumed by processing Format.\r
72 @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.\r
73 @param Size The size, in bytes, of the BaseListMarker buffer.\r
74\r
75 @return The number of bytes in BaseListMarker. 0 if BaseListMarker is too small.\r
76\r
77**/\r
78BOOLEAN\r
79DxePrintLibPrint2ProtocolVaListToBaseList (\r
80 IN BOOLEAN AsciiFormat,\r
81 IN CONST CHAR8 *Format,\r
82 IN VA_LIST VaListMarker,\r
83 OUT BASE_LIST BaseListMarker,\r
84 IN UINTN Size\r
85 )\r
86{\r
87 BASE_LIST BaseListStart;\r
88 UINTN BytesPerFormatCharacter;\r
89 UINTN FormatMask;\r
90 UINTN FormatCharacter;\r
91 BOOLEAN Long;\r
92 BOOLEAN Done;\r
93\r
94 ASSERT (Format != NULL);\r
95 ASSERT (VaListMarker != NULL);\r
96 ASSERT (BaseListMarker != NULL);\r
97\r
98 BaseListStart = BaseListMarker;\r
99\r
100 if (AsciiFormat) {\r
101 ASSERT (AsciiStrSize (Format) != 0);\r
102 BytesPerFormatCharacter = 1;\r
103 FormatMask = 0xff;\r
104 } else {\r
105 ASSERT (StrSize ((CHAR16 *) Format) != 0);\r
106 BytesPerFormatCharacter = 2;\r
107 FormatMask = 0xffff;\r
108 }\r
109\r
110 //\r
111 // Get the first character from the format string\r
112 //\r
113 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
114\r
115 while (FormatCharacter != 0) {\r
116 if (FormatCharacter == '%') {\r
117 Long = FALSE;\r
118\r
119 //\r
120 // Parse Flags and Width\r
121 //\r
122 for (Done = FALSE; !Done; ) {\r
123 //\r
124 // Get the next character from the format string\r
125 //\r
126 Format += BytesPerFormatCharacter;\r
127\r
128 //\r
129 // Get the next character from the format string\r
130 //\r
131 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
132\r
133 switch (FormatCharacter) {\r
134 case '.': \r
135 case '-': \r
136 case '+': \r
137 case ' ': \r
138 case ',': \r
139 case '0':\r
140 case '1':\r
141 case '2':\r
142 case '3':\r
143 case '4':\r
144 case '5':\r
145 case '6':\r
146 case '7':\r
147 case '8':\r
148 case '9':\r
149 break;\r
150 case 'L':\r
151 case 'l': \r
152 Long = TRUE;\r
153 break;\r
154 case '*':\r
155 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
156 break;\r
157 case '\0':\r
158 //\r
159 // Make no output if Format string terminates unexpectedly when\r
160 // looking up for flag, width, precision and type. \r
161 //\r
162 Format -= BytesPerFormatCharacter;\r
163 //\r
164 // break skipped on purpose.\r
165 //\r
166 default:\r
167 Done = TRUE;\r
168 break;\r
169 }\r
170 } \r
171 \r
172 //\r
173 // Handle each argument type\r
174 //\r
175 switch (FormatCharacter) {\r
176 case 'p':\r
177 if (sizeof (VOID *) > 4) {\r
178 Long = TRUE;\r
179 }\r
180 case 'X':\r
181 case 'x':\r
182 case 'd':\r
183 if (Long) {\r
184 BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r
185 } else {\r
186 BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r
187 }\r
188 break;\r
189 case 's':\r
190 case 'S':\r
191 case 'a':\r
192 case 'g':\r
193 case 't':\r
194 BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r
195 break;\r
196 case 'c':\r
197 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
198 break;\r
199 case 'r':\r
200 BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
201 break;\r
202 }\r
203 }\r
204\r
205 //\r
206 // If BASE_LIST is larger than Size, then return FALSE\r
207 //\r
208 if ((UINTN)((UINT8 *)BaseListMarker - (UINT8 *)BaseListStart) > Size) {\r
209 return FALSE;\r
210 }\r
211\r
212 //\r
213 // Get the next character from the format string\r
214 //\r
215 Format += BytesPerFormatCharacter;\r
216\r
217 //\r
218 // Get the next character from the format string\r
219 //\r
220 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
221 }\r
222 return TRUE;\r
223}\r
224\r
2ad4dad0
LG
225/**\r
226 Produces a Null-terminated Unicode string in an output buffer based on \r
227 a Null-terminated Unicode format string and a VA_LIST argument list\r
228 \r
229 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
230 and BufferSize. \r
231 The Unicode string is produced by parsing the format string specified by FormatString. \r
232 Arguments are pulled from the variable argument list specified by Marker based on the \r
233 contents of the format string. \r
234 The number of Unicode characters in the produced output buffer is returned not including\r
235 the Null-terminator.\r
236 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
237\r
238 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
239 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
240 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
241 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
242 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
243 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
244 ASSERT().\r
245 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
246 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
247 Null-terminator, then ASSERT().\r
248\r
249 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
250 Unicode string.\r
251 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
252 @param FormatString Null-terminated Unicode format string.\r
253 @param Marker VA_LIST marker for the variable argument list.\r
254 \r
255 @return The number of Unicode characters in the produced output buffer not including the\r
256 Null-terminator.\r
257\r
258**/\r
259UINTN\r
260EFIAPI\r
261UnicodeVSPrint (\r
262 OUT CHAR16 *StartOfBuffer,\r
263 IN UINTN BufferSize,\r
264 IN CONST CHAR16 *FormatString,\r
265 IN VA_LIST Marker\r
266 )\r
267{\r
504dcb0a 268 UINT8 BaseListMarker[256];\r
269\r
270 DxePrintLibPrint2ProtocolVaListToBaseList (\r
271 FALSE, \r
272 (CHAR8 *)FormatString, \r
273 Marker, \r
274 (BASE_LIST)BaseListMarker, \r
275 sizeof (BaseListMarker) - 8\r
276 );\r
277\r
278 return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
279}\r
280\r
281/**\r
282 Produces a Null-terminated Unicode string in an output buffer based on \r
283 a Null-terminated Unicode format string and a BASE_LIST argument list\r
284 \r
285 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
286 and BufferSize. \r
287 The Unicode string is produced by parsing the format string specified by FormatString. \r
288 Arguments are pulled from the variable argument list specified by Marker based on the \r
289 contents of the format string. \r
290 The number of Unicode characters in the produced output buffer is returned not including\r
291 the Null-terminator.\r
292 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
293\r
294 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
295 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
296 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
297 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
298 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
299 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
300 ASSERT().\r
301 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
302 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
303 Null-terminator, then ASSERT().\r
304\r
305 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
306 Unicode string.\r
307 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
308 @param FormatString Null-terminated Unicode format string.\r
309 @param Marker BASE_LIST marker for the variable argument list.\r
310 \r
311 @return The number of Unicode characters in the produced output buffer not including the\r
312 Null-terminator.\r
313\r
314**/\r
315UINTN\r
316EFIAPI\r
317UnicodeBSPrint (\r
318 OUT CHAR16 *StartOfBuffer,\r
319 IN UINTN BufferSize,\r
320 IN CONST CHAR16 *FormatString,\r
321 IN BASE_LIST Marker\r
322 )\r
323{\r
324 return mPrint2Protocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
a0afd019 325}\r
326\r
2ad4dad0
LG
327/**\r
328 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
329 Unicode format string and variable argument list.\r
330 \r
331 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
332 and BufferSize.\r
333 The Unicode string is produced by parsing the format string specified by FormatString.\r
334 Arguments are pulled from the variable argument list based on the contents of the format string.\r
335 The number of Unicode characters in the produced output buffer is returned not including\r
336 the Null-terminator.\r
337 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
338\r
339 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
340 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
341 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
342 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
343 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
344 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
345 ASSERT().\r
346 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
347 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
348 Null-terminator, then ASSERT().\r
349\r
350 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
351 Unicode string.\r
352 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
353 @param FormatString Null-terminated Unicode format string.\r
71898234 354 @param ... Variable argument list whose contents are accessed based on the \r
355 format string specified by FormatString.\r
ce95aa7a 356\r
2ad4dad0
LG
357 @return The number of Unicode characters in the produced output buffer not including the\r
358 Null-terminator.\r
359\r
360**/\r
a0afd019 361UINTN\r
2ad4dad0 362EFIAPI\r
a0afd019 363UnicodeSPrint (\r
364 OUT CHAR16 *StartOfBuffer,\r
365 IN UINTN BufferSize,\r
2ad4dad0 366 IN CONST CHAR16 *FormatString,\r
a0afd019 367 ...\r
368 )\r
a0afd019 369{\r
2ad4dad0 370 VA_LIST Marker;\r
a0afd019 371\r
372 VA_START (Marker, FormatString);\r
2ad4dad0 373 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
a0afd019 374}\r
375\r
2ad4dad0
LG
376/**\r
377 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
378 ASCII format string and a VA_LIST argument list\r
379 \r
380 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
381 and BufferSize.\r
382 The Unicode string is produced by parsing the format string specified by FormatString.\r
383 Arguments are pulled from the variable argument list specified by Marker based on the \r
384 contents of the format string.\r
385 The number of Unicode characters in the produced output buffer is returned not including\r
386 the Null-terminator.\r
387 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
388\r
389 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
390 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
391 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
392 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
393 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
394 ASSERT().\r
395 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
396 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
397 Null-terminator, then ASSERT().\r
398\r
399 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
400 Unicode string.\r
401 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
402 @param FormatString Null-terminated Unicode format string.\r
403 @param Marker VA_LIST marker for the variable argument list.\r
404 \r
405 @return The number of Unicode characters in the produced output buffer not including the\r
406 Null-terminator.\r
407\r
408**/\r
a0afd019 409UINTN\r
2ad4dad0
LG
410EFIAPI\r
411UnicodeVSPrintAsciiFormat (\r
412 OUT CHAR16 *StartOfBuffer,\r
413 IN UINTN BufferSize,\r
414 IN CONST CHAR8 *FormatString,\r
415 IN VA_LIST Marker\r
a0afd019 416 )\r
2ad4dad0 417{\r
504dcb0a 418 UINT8 BaseListMarker[256];\r
419\r
420 DxePrintLibPrint2ProtocolVaListToBaseList (\r
421 TRUE, \r
422 FormatString, \r
423 Marker, \r
424 (BASE_LIST)BaseListMarker, \r
425 sizeof (BaseListMarker) - 8\r
426 );\r
427\r
428 return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
429}\r
430\r
431/**\r
432 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
433 ASCII format string and a BASE_LIST argument list\r
434 \r
435 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
436 and BufferSize.\r
437 The Unicode string is produced by parsing the format string specified by FormatString.\r
438 Arguments are pulled from the variable argument list specified by Marker based on the \r
439 contents of the format string.\r
440 The number of Unicode characters in the produced output buffer is returned not including\r
441 the Null-terminator.\r
442 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
443\r
444 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
445 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
446 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
447 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
448 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
449 ASSERT().\r
450 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
451 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
452 Null-terminator, then ASSERT().\r
453\r
454 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
455 Unicode string.\r
456 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
457 @param FormatString Null-terminated Unicode format string.\r
458 @param Marker BASE_LIST marker for the variable argument list.\r
459 \r
460 @return The number of Unicode characters in the produced output buffer not including the\r
461 Null-terminator.\r
462\r
463**/\r
464UINTN\r
465EFIAPI\r
466UnicodeBSPrintAsciiFormat (\r
467 OUT CHAR16 *StartOfBuffer,\r
468 IN UINTN BufferSize,\r
469 IN CONST CHAR8 *FormatString,\r
470 IN BASE_LIST Marker\r
471 )\r
472{\r
473 return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
2ad4dad0 474}\r
a0afd019 475\r
2ad4dad0
LG
476/**\r
477 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
478 ASCII format string and variable argument list.\r
479 \r
480 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
481 and BufferSize.\r
482 The Unicode string is produced by parsing the format string specified by FormatString.\r
483 Arguments are pulled from the variable argument list based on the contents of the \r
484 format string.\r
485 The number of Unicode characters in the produced output buffer is returned not including\r
486 the Null-terminator.\r
487 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
488\r
489 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
490 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
491 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
492 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
493 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
494 ASSERT().\r
495 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
496 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
497 Null-terminator, then ASSERT().\r
498\r
499 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
500 Unicode string.\r
501 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
502 @param FormatString Null-terminated Unicode format string.\r
71898234 503 @param ... Variable argument list whose contents are accessed based on the \r
504 format string specified by FormatString.\r
2ad4dad0
LG
505 \r
506 @return The number of Unicode characters in the produced output buffer not including the\r
507 Null-terminator.\r
508\r
509**/\r
510UINTN\r
511EFIAPI\r
512UnicodeSPrintAsciiFormat (\r
513 OUT CHAR16 *StartOfBuffer,\r
514 IN UINTN BufferSize,\r
515 IN CONST CHAR8 *FormatString,\r
516 ...\r
517 )\r
518{\r
519 VA_LIST Marker;\r
a0afd019 520\r
2ad4dad0
LG
521 VA_START (Marker, FormatString);\r
522 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
523}\r
a0afd019 524\r
2ad4dad0
LG
525/**\r
526 Converts a decimal value to a Null-terminated Unicode string.\r
527 \r
528 Converts the decimal number specified by Value to a Null-terminated Unicode \r
529 string specified by Buffer containing at most Width characters. No padding of spaces \r
530 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
531 The number of Unicode characters in Buffer is returned not including the Null-terminator.\r
532 If the conversion contains more than Width characters, then only the first\r
533 Width characters are returned, and the total number of characters \r
534 required to perform the conversion is returned.\r
535 Additional conversion parameters are specified in Flags. \r
536 \r
537 The Flags bit LEFT_JUSTIFY is always ignored.\r
538 All conversions are left justified in Buffer.\r
539 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
540 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
541 are inserted every 3rd digit starting from the right.\r
542 If HEX_RADIX is set in Flags, then the output buffer will be \r
543 formatted in hexadecimal format.\r
544 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.\r
545 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
546 then Buffer is padded with '0' characters so the combination of the optional '-' \r
547 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
548 add up to Width characters.\r
549 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().\r
550 If Buffer is NULL, then ASSERT().\r
551 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
552 If unsupported bits are set in Flags, then ASSERT().\r
553 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().\r
554 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
555\r
556 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
557 Unicode string.\r
558 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
559 @param Value The 64-bit signed value to convert to a string.\r
560 @param Width The maximum number of Unicode characters to place in Buffer, not including\r
561 the Null-terminator.\r
562 \r
563 @return The number of Unicode characters in Buffer not including the Null-terminator.\r
564\r
565**/\r
566UINTN\r
567EFIAPI\r
568UnicodeValueToString (\r
569 IN OUT CHAR16 *Buffer,\r
570 IN UINTN Flags,\r
571 IN INT64 Value,\r
572 IN UINTN Width\r
573 )\r
574{\r
bee67555 575 return mPrint2Protocol->UnicodeValueToString (Buffer, Flags, Value, Width);\r
2ad4dad0 576}\r
a0afd019 577\r
2ad4dad0
LG
578/**\r
579 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
580 ASCII format string and a VA_LIST argument list.\r
581 \r
582 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
583 and BufferSize.\r
584 The ASCII string is produced by parsing the format string specified by FormatString.\r
585 Arguments are pulled from the variable argument list specified by Marker based on \r
586 the contents of the format string.\r
587 The number of ASCII characters in the produced output buffer is returned not including\r
588 the Null-terminator.\r
589 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
590\r
591 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
592 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
593 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
594 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
595 ASSERT().\r
596 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
597 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
598 Null-terminator, then ASSERT().\r
599\r
600 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
601 ASCII string.\r
602 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
603 @param FormatString Null-terminated Unicode format string.\r
604 @param Marker VA_LIST marker for the variable argument list.\r
605 \r
606 @return The number of ASCII characters in the produced output buffer not including the\r
607 Null-terminator.\r
608\r
609**/\r
610UINTN\r
611EFIAPI\r
612AsciiVSPrint (\r
613 OUT CHAR8 *StartOfBuffer,\r
614 IN UINTN BufferSize,\r
615 IN CONST CHAR8 *FormatString,\r
616 IN VA_LIST Marker\r
617 )\r
a0afd019 618{\r
504dcb0a 619 UINT8 BaseListMarker[256];\r
620\r
621 DxePrintLibPrint2ProtocolVaListToBaseList (\r
622 TRUE, \r
623 FormatString, \r
624 Marker, \r
625 (BASE_LIST)BaseListMarker, \r
626 sizeof (BaseListMarker) - 8\r
627 );\r
628\r
629 return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
630}\r
631\r
632/**\r
633 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
634 ASCII format string and a BASE_LIST argument list.\r
635 \r
636 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
637 and BufferSize.\r
638 The ASCII string is produced by parsing the format string specified by FormatString.\r
639 Arguments are pulled from the variable argument list specified by Marker based on \r
640 the contents of the format string.\r
641 The number of ASCII characters in the produced output buffer is returned not including\r
642 the Null-terminator.\r
643 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
644\r
645 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
646 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
647 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
648 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
649 ASSERT().\r
650 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
651 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
652 Null-terminator, then ASSERT().\r
653\r
654 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
655 ASCII string.\r
656 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
657 @param FormatString Null-terminated Unicode format string.\r
658 @param Marker BASE_LIST marker for the variable argument list.\r
659 \r
660 @return The number of ASCII characters in the produced output buffer not including the\r
661 Null-terminator.\r
662\r
663**/\r
664UINTN\r
665EFIAPI\r
666AsciiBSPrint (\r
667 OUT CHAR8 *StartOfBuffer,\r
668 IN UINTN BufferSize,\r
669 IN CONST CHAR8 *FormatString,\r
670 IN BASE_LIST Marker\r
671 )\r
672{\r
673 return mPrint2Protocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
a0afd019 674}\r
675\r
2ad4dad0
LG
676/**\r
677 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
678 ASCII format string and variable argument list.\r
679 \r
680 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
681 and BufferSize.\r
682 The ASCII string is produced by parsing the format string specified by FormatString.\r
683 Arguments are pulled from the variable argument list based on the contents of the \r
684 format string.\r
685 The number of ASCII characters in the produced output buffer is returned not including\r
686 the Null-terminator.\r
687 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
688\r
689 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
690 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
691 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
692 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
693 ASSERT().\r
694 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
695 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
696 Null-terminator, then ASSERT().\r
697\r
698 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
699 ASCII string.\r
700 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
701 @param FormatString Null-terminated Unicode format string.\r
71898234 702 @param ... Variable argument list whose contents are accessed based on the \r
703 format string specified by FormatString.\r
ce95aa7a 704\r
2ad4dad0
LG
705 @return The number of ASCII characters in the produced output buffer not including the\r
706 Null-terminator.\r
707\r
708**/\r
a0afd019 709UINTN\r
2ad4dad0 710EFIAPI\r
a0afd019 711AsciiSPrint (\r
712 OUT CHAR8 *StartOfBuffer,\r
713 IN UINTN BufferSize,\r
2ad4dad0 714 IN CONST CHAR8 *FormatString,\r
a0afd019 715 ...\r
716 )\r
2ad4dad0
LG
717{\r
718 VA_LIST Marker;\r
719\r
720 VA_START (Marker, FormatString);\r
721 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
722}\r
a0afd019 723\r
2ad4dad0
LG
724/**\r
725 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
726 ASCII format string and a VA_LIST argument list.\r
727 \r
728 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
729 and BufferSize.\r
730 The ASCII string is produced by parsing the format string specified by FormatString.\r
731 Arguments are pulled from the variable argument list specified by Marker based on \r
732 the contents of the format string.\r
733 The number of ASCII characters in the produced output buffer is returned not including\r
734 the Null-terminator.\r
735 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
736\r
737 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
738 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
739 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
740 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
741 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
742 ASSERT().\r
743 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
744 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
745 Null-terminator, then ASSERT().\r
746\r
747 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
748 ASCII string.\r
749 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
750 @param FormatString Null-terminated Unicode format string.\r
751 @param Marker VA_LIST marker for the variable argument list.\r
752 \r
753 @return The number of ASCII characters in the produced output buffer not including the\r
754 Null-terminator.\r
755\r
756**/\r
757UINTN\r
758EFIAPI\r
759AsciiVSPrintUnicodeFormat (\r
760 OUT CHAR8 *StartOfBuffer,\r
761 IN UINTN BufferSize,\r
762 IN CONST CHAR16 *FormatString,\r
763 IN VA_LIST Marker\r
764 )\r
a0afd019 765{\r
504dcb0a 766 UINT8 BaseListMarker[256];\r
767\r
768 DxePrintLibPrint2ProtocolVaListToBaseList (\r
769 FALSE, \r
770 (CHAR8 *)FormatString, \r
771 Marker, \r
772 (BASE_LIST)BaseListMarker, \r
773 sizeof (BaseListMarker) - 8\r
774 );\r
775\r
776 return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
777}\r
778\r
779/**\r
780 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
781 ASCII format string and a BASE_LIST argument list.\r
782 \r
783 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
784 and BufferSize.\r
785 The ASCII string is produced by parsing the format string specified by FormatString.\r
786 Arguments are pulled from the variable argument list specified by Marker based on \r
787 the contents of the format string.\r
788 The number of ASCII characters in the produced output buffer is returned not including\r
789 the Null-terminator.\r
790 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
791\r
792 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
793 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
794 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
795 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
796 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
797 ASSERT().\r
798 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
799 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
800 Null-terminator, then ASSERT().\r
801\r
802 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
803 ASCII string.\r
804 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
805 @param FormatString Null-terminated Unicode format string.\r
806 @param Marker BASE_LIST marker for the variable argument list.\r
807 \r
808 @return The number of ASCII characters in the produced output buffer not including the\r
809 Null-terminator.\r
810\r
811**/\r
812UINTN\r
813EFIAPI\r
814AsciiBSPrintUnicodeFormat (\r
815 OUT CHAR8 *StartOfBuffer,\r
816 IN UINTN BufferSize,\r
817 IN CONST CHAR16 *FormatString,\r
818 IN BASE_LIST Marker\r
819 )\r
820{\r
821 return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
2ad4dad0
LG
822}\r
823\r
824/**\r
825 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
826 ASCII format string and variable argument list.\r
827 \r
828 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
829 and BufferSize.\r
830 The ASCII string is produced by parsing the format string specified by FormatString.\r
831 Arguments are pulled from the variable argument list based on the contents of the \r
832 format string.\r
833 The number of ASCII characters in the produced output buffer is returned not including\r
834 the Null-terminator.\r
835 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
836\r
837 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
838 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
839 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
840 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
841 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
842 ASSERT().\r
843 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
844 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
845 Null-terminator, then ASSERT().\r
846\r
847 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
848 ASCII string.\r
849 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
850 @param FormatString Null-terminated Unicode format string.\r
71898234 851 @param ... Variable argument list whose contents are accessed based on the \r
852 format string specified by FormatString.\r
ce95aa7a 853\r
2ad4dad0
LG
854 @return The number of ASCII characters in the produced output buffer not including the\r
855 Null-terminator.\r
856\r
857**/\r
858UINTN\r
859EFIAPI\r
860AsciiSPrintUnicodeFormat (\r
861 OUT CHAR8 *StartOfBuffer,\r
862 IN UINTN BufferSize,\r
863 IN CONST CHAR16 *FormatString,\r
864 ...\r
865 )\r
866{\r
867 VA_LIST Marker;\r
a0afd019 868\r
869 VA_START (Marker, FormatString);\r
2ad4dad0
LG
870 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
871}\r
872\r
873\r
874/**\r
875 Converts a decimal value to a Null-terminated ASCII string.\r
876 \r
877 Converts the decimal number specified by Value to a Null-terminated ASCII string \r
878 specified by Buffer containing at most Width characters. No padding of spaces \r
879 is ever performed.\r
880 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
881 The number of ASCII characters in Buffer is returned not including the Null-terminator.\r
882 If the conversion contains more than Width characters, then only the first Width\r
883 characters are returned, and the total number of characters required to perform\r
884 the conversion is returned.\r
885 Additional conversion parameters are specified in Flags. \r
886 The Flags bit LEFT_JUSTIFY is always ignored.\r
887 All conversions are left justified in Buffer.\r
888 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
889 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
890 are inserted every 3rd digit starting from the right.\r
891 If HEX_RADIX is set in Flags, then the output buffer will be \r
892 formatted in hexadecimal format.\r
893 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.\r
894 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
895 then Buffer is padded with '0' characters so the combination of the optional '-' \r
896 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
897 add up to Width characters.\r
898 \r
899 If Buffer is NULL, then ASSERT().\r
900 If unsupported bits are set in Flags, then ASSERT().\r
901 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().\r
902 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
903\r
904 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
905 ASCII string.\r
906 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
907 @param Value The 64-bit signed value to convert to a string.\r
908 @param Width The maximum number of ASCII characters to place in Buffer, not including\r
909 the Null-terminator.\r
910 \r
911 @return The number of ASCII characters in Buffer not including the Null-terminator.\r
912\r
913**/\r
914UINTN\r
915EFIAPI\r
916AsciiValueToString (\r
ea99d5d1 917 OUT CHAR8 *Buffer,\r
918 IN UINTN Flags,\r
919 IN INT64 Value,\r
920 IN UINTN Width\r
2ad4dad0
LG
921 )\r
922{\r
bee67555 923 return mPrint2Protocol->AsciiValueToString (Buffer, Flags, Value, Width);\r
a0afd019 924}\r