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