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