2 Instance of Print Library based on gEfiPrint2ProtocolGuid.
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.
9 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
10 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
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.
22 #include <Protocol/Print2.h>
24 #include <Library/PrintLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/DebugLib.h>
29 EFI_PRINT2_PROTOCOL
*mPrint2Protocol
= NULL
;
32 The constructor function caches the pointer to Print2 protocol.
34 The constructor function locates Print2 protocol from protocol database.
35 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
37 @param ImageHandle The firmware allocated handle for the EFI image.
38 @param SystemTable A pointer to the EFI System Table.
40 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
46 IN EFI_HANDLE ImageHandle
,
47 IN EFI_SYSTEM_TABLE
*SystemTable
52 Status
= SystemTable
->BootServices
->LocateProtocol (
53 &gEfiPrint2ProtocolGuid
,
55 (VOID
**) &mPrint2Protocol
57 ASSERT_EFI_ERROR (Status
);
58 ASSERT (mPrint2Protocol
!= NULL
);
65 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated
68 @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.
69 @param Format Null-terminated format string.
70 @param VaListMarker VA_LIST style variable argument list consumed by processing Format.
71 @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.
72 @param Size The size, in bytes, of the BaseListMarker buffer.
74 @return The number of bytes in BaseListMarker. 0 if BaseListMarker is too small.
78 DxePrintLibPrint2ProtocolVaListToBaseList (
79 IN BOOLEAN AsciiFormat
,
80 IN CONST CHAR8
*Format
,
81 IN VA_LIST VaListMarker
,
82 OUT BASE_LIST BaseListMarker
,
86 BASE_LIST BaseListStart
;
87 UINTN BytesPerFormatCharacter
;
89 UINTN FormatCharacter
;
93 ASSERT (Format
!= NULL
);
94 ASSERT (BaseListMarker
!= NULL
);
96 BaseListStart
= BaseListMarker
;
99 ASSERT (AsciiStrSize (Format
) != 0);
100 BytesPerFormatCharacter
= 1;
103 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
104 BytesPerFormatCharacter
= 2;
109 // Get the first character from the format string
111 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
113 while (FormatCharacter
!= 0) {
114 if (FormatCharacter
== '%') {
118 // Parse Flags and Width
120 for (Done
= FALSE
; !Done
; ) {
122 // Get the next character from the format string
124 Format
+= BytesPerFormatCharacter
;
127 // Get the next character from the format string
129 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
131 switch (FormatCharacter
) {
153 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
157 // Make no output if Format string terminates unexpectedly when
158 // looking up for flag, width, precision and type.
160 Format
-= BytesPerFormatCharacter
;
162 // break skipped on purpose.
171 // Handle each argument type
173 switch (FormatCharacter
) {
175 if (sizeof (VOID
*) > 4) {
182 BASE_ARG (BaseListMarker
, INT64
) = VA_ARG (VaListMarker
, INT64
);
184 BASE_ARG (BaseListMarker
, int) = VA_ARG (VaListMarker
, int);
192 BASE_ARG (BaseListMarker
, VOID
*) = VA_ARG (VaListMarker
, VOID
*);
195 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
198 BASE_ARG (BaseListMarker
, RETURN_STATUS
) = VA_ARG (VaListMarker
, RETURN_STATUS
);
204 // If BASE_LIST is larger than Size, then return FALSE
206 if ((UINTN
)((UINT8
*)BaseListMarker
- (UINT8
*)BaseListStart
) > Size
) {
211 // Get the next character from the format string
213 Format
+= BytesPerFormatCharacter
;
216 // Get the next character from the format string
218 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
224 Produces a Null-terminated Unicode string in an output buffer based on
225 a Null-terminated Unicode format string and a VA_LIST argument list
227 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
229 The Unicode string is produced by parsing the format string specified by FormatString.
230 Arguments are pulled from the variable argument list specified by Marker based on the
231 contents of the format string.
232 The number of Unicode characters in the produced output buffer is returned not including
234 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
236 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
237 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
238 If BufferSize > 1 and FormatString is NULL, then ASSERT().
239 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
240 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
241 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
243 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
244 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
245 Null-terminator, then ASSERT().
247 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
249 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
250 @param FormatString Null-terminated Unicode format string.
251 @param Marker VA_LIST marker for the variable argument list.
253 @return The number of Unicode characters in the produced output buffer not including the
260 OUT CHAR16
*StartOfBuffer
,
262 IN CONST CHAR16
*FormatString
,
266 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
268 DxePrintLibPrint2ProtocolVaListToBaseList (
270 (CHAR8
*)FormatString
,
272 (BASE_LIST
)BaseListMarker
,
273 sizeof (BaseListMarker
) - 8
276 return UnicodeBSPrint (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
280 Produces a Null-terminated Unicode string in an output buffer based on
281 a Null-terminated Unicode format string and a BASE_LIST argument list
283 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
285 The Unicode string is produced by parsing the format string specified by FormatString.
286 Arguments are pulled from the variable argument list specified by Marker based on the
287 contents of the format string.
288 The number of Unicode characters in the produced output buffer is returned not including
290 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
292 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
293 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
294 If BufferSize > 1 and FormatString is NULL, then ASSERT().
295 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
296 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
297 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
299 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
300 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
301 Null-terminator, then ASSERT().
303 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
305 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
306 @param FormatString Null-terminated Unicode format string.
307 @param Marker BASE_LIST marker for the variable argument list.
309 @return The number of Unicode characters in the produced output buffer not including the
316 OUT CHAR16
*StartOfBuffer
,
318 IN CONST CHAR16
*FormatString
,
322 return mPrint2Protocol
->UnicodeBSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
326 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
327 Unicode format string and variable argument list.
329 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
331 The Unicode string is produced by parsing the format string specified by FormatString.
332 Arguments are pulled from the variable argument list based on the contents of the format string.
333 The number of Unicode characters in the produced output buffer is returned not including
335 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
337 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
338 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
339 If BufferSize > 1 and FormatString is NULL, then ASSERT().
340 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
341 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
342 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
344 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
345 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
346 Null-terminator, then ASSERT().
348 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
350 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
351 @param FormatString Null-terminated Unicode format string.
352 @param ... Variable argument list whose contents are accessed based on the
353 format string specified by FormatString.
355 @return The number of Unicode characters in the produced output buffer not including the
362 OUT CHAR16
*StartOfBuffer
,
364 IN CONST CHAR16
*FormatString
,
369 UINTN NumberOfPrinted
;
371 VA_START (Marker
, FormatString
);
372 NumberOfPrinted
= UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
374 return NumberOfPrinted
;
378 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
379 ASCII format string and a VA_LIST argument list
381 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
383 The Unicode string is produced by parsing the format string specified by FormatString.
384 Arguments are pulled from the variable argument list specified by Marker based on the
385 contents of the format string.
386 The number of Unicode characters in the produced output buffer is returned not including
388 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
390 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
391 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
392 If BufferSize > 1 and FormatString is NULL, then ASSERT().
393 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
394 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
396 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
397 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
398 Null-terminator, then ASSERT().
400 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
402 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
403 @param FormatString Null-terminated Unicode format string.
404 @param Marker VA_LIST marker for the variable argument list.
406 @return The number of Unicode characters in the produced output buffer not including the
412 UnicodeVSPrintAsciiFormat (
413 OUT CHAR16
*StartOfBuffer
,
415 IN CONST CHAR8
*FormatString
,
419 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
421 DxePrintLibPrint2ProtocolVaListToBaseList (
425 (BASE_LIST
)BaseListMarker
,
426 sizeof (BaseListMarker
) - 8
429 return UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
433 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
434 ASCII format string and a BASE_LIST argument list
436 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
438 The Unicode string is produced by parsing the format string specified by FormatString.
439 Arguments are pulled from the variable argument list specified by Marker based on the
440 contents of the format string.
441 The number of Unicode characters in the produced output buffer is returned not including
443 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
445 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
446 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
447 If BufferSize > 1 and FormatString is NULL, then ASSERT().
448 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
449 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
451 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
452 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
453 Null-terminator, then ASSERT().
455 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
457 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
458 @param FormatString Null-terminated Unicode format string.
459 @param Marker BASE_LIST marker for the variable argument list.
461 @return The number of Unicode characters in the produced output buffer not including the
467 UnicodeBSPrintAsciiFormat (
468 OUT CHAR16
*StartOfBuffer
,
470 IN CONST CHAR8
*FormatString
,
474 return mPrint2Protocol
->UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
478 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
479 ASCII format string and variable argument list.
481 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
483 The Unicode string is produced by parsing the format string specified by FormatString.
484 Arguments are pulled from the variable argument list based on the contents of the
486 The number of Unicode characters in the produced output buffer is returned not including
488 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
490 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
491 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
492 If BufferSize > 1 and FormatString is NULL, then ASSERT().
493 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
494 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
496 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
497 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
498 Null-terminator, then ASSERT().
500 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
502 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
503 @param FormatString Null-terminated Unicode format string.
504 @param ... Variable argument list whose contents are accessed based on the
505 format string specified by FormatString.
507 @return The number of Unicode characters in the produced output buffer not including the
513 UnicodeSPrintAsciiFormat (
514 OUT CHAR16
*StartOfBuffer
,
516 IN CONST CHAR8
*FormatString
,
521 UINTN NumberOfPrinted
;
523 VA_START (Marker
, FormatString
);
524 NumberOfPrinted
= UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
526 return NumberOfPrinted
;
530 Converts a decimal value to a Null-terminated Unicode string.
532 Converts the decimal number specified by Value to a Null-terminated Unicode
533 string specified by Buffer containing at most Width characters. No padding of spaces
534 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
535 The number of Unicode characters in Buffer is returned not including the Null-terminator.
536 If the conversion contains more than Width characters, then only the first
537 Width characters are returned, and the total number of characters
538 required to perform the conversion is returned.
539 Additional conversion parameters are specified in Flags.
541 The Flags bit LEFT_JUSTIFY is always ignored.
542 All conversions are left justified in Buffer.
543 If Width is 0, PREFIX_ZERO is ignored in Flags.
544 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
545 are inserted every 3rd digit starting from the right.
546 If RADIX_HEX is set in Flags, then the output buffer will be
547 formatted in hexadecimal format.
548 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
549 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
550 then Buffer is padded with '0' characters so the combination of the optional '-'
551 sign character, '0' characters, digit characters for Value, and the Null-terminator
552 add up to Width characters.
553 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
554 If Buffer is NULL, then ASSERT().
555 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
556 If unsupported bits are set in Flags, then ASSERT().
557 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
558 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
560 @param Buffer Pointer to the output buffer for the produced Null-terminated
562 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
563 @param Value The 64-bit signed value to convert to a string.
564 @param Width The maximum number of Unicode characters to place in Buffer, not including
567 @return The number of Unicode characters in Buffer not including the Null-terminator.
572 UnicodeValueToString (
573 IN OUT CHAR16
*Buffer
,
579 return mPrint2Protocol
->UnicodeValueToString (Buffer
, Flags
, Value
, Width
);
583 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
584 ASCII format string and a VA_LIST argument list.
586 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
588 The ASCII string is produced by parsing the format string specified by FormatString.
589 Arguments are pulled from the variable argument list specified by Marker based on
590 the contents of the format string.
591 The number of ASCII characters in the produced output buffer is returned not including
593 If BufferSize is 0, then no output buffer is produced and 0 is returned.
595 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
596 If BufferSize > 0 and FormatString is NULL, then ASSERT().
597 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
598 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
600 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
601 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
602 Null-terminator, then ASSERT().
604 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
606 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
607 @param FormatString Null-terminated Unicode format string.
608 @param Marker VA_LIST marker for the variable argument list.
610 @return The number of ASCII characters in the produced output buffer not including the
617 OUT CHAR8
*StartOfBuffer
,
619 IN CONST CHAR8
*FormatString
,
623 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
625 DxePrintLibPrint2ProtocolVaListToBaseList (
629 (BASE_LIST
)BaseListMarker
,
630 sizeof (BaseListMarker
) - 8
633 return AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
637 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
638 ASCII format string and a BASE_LIST argument list.
640 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
642 The ASCII string is produced by parsing the format string specified by FormatString.
643 Arguments are pulled from the variable argument list specified by Marker based on
644 the contents of the format string.
645 The number of ASCII characters in the produced output buffer is returned not including
647 If BufferSize is 0, then no output buffer is produced and 0 is returned.
649 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
650 If BufferSize > 0 and FormatString is NULL, then ASSERT().
651 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
652 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
654 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
655 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
656 Null-terminator, then ASSERT().
658 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
660 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
661 @param FormatString Null-terminated Unicode format string.
662 @param Marker BASE_LIST marker for the variable argument list.
664 @return The number of ASCII characters in the produced output buffer not including the
671 OUT CHAR8
*StartOfBuffer
,
673 IN CONST CHAR8
*FormatString
,
677 return mPrint2Protocol
->AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
681 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
682 ASCII format string and variable argument list.
684 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
686 The ASCII string is produced by parsing the format string specified by FormatString.
687 Arguments are pulled from the variable argument list based on the contents of the
689 The number of ASCII characters in the produced output buffer is returned not including
691 If BufferSize is 0, then no output buffer is produced and 0 is returned.
693 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
694 If BufferSize > 0 and FormatString is NULL, then ASSERT().
695 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
696 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
698 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
699 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
700 Null-terminator, then ASSERT().
702 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
704 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
705 @param FormatString Null-terminated Unicode format string.
706 @param ... Variable argument list whose contents are accessed based on the
707 format string specified by FormatString.
709 @return The number of ASCII characters in the produced output buffer not including the
716 OUT CHAR8
*StartOfBuffer
,
718 IN CONST CHAR8
*FormatString
,
723 UINTN NumberOfPrinted
;
725 VA_START (Marker
, FormatString
);
726 NumberOfPrinted
= AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
728 return NumberOfPrinted
;
732 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
733 ASCII format string and a VA_LIST argument list.
735 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
737 The ASCII string is produced by parsing the format string specified by FormatString.
738 Arguments are pulled from the variable argument list specified by Marker based on
739 the contents of the format string.
740 The number of ASCII characters in the produced output buffer is returned not including
742 If BufferSize is 0, then no output buffer is produced and 0 is returned.
744 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
745 If BufferSize > 0 and FormatString is NULL, then ASSERT().
746 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
747 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
748 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
750 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
751 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
752 Null-terminator, then ASSERT().
754 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
756 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
757 @param FormatString Null-terminated Unicode format string.
758 @param Marker VA_LIST marker for the variable argument list.
760 @return The number of ASCII characters in the produced output buffer not including the
766 AsciiVSPrintUnicodeFormat (
767 OUT CHAR8
*StartOfBuffer
,
769 IN CONST CHAR16
*FormatString
,
773 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
775 DxePrintLibPrint2ProtocolVaListToBaseList (
777 (CHAR8
*)FormatString
,
779 (BASE_LIST
)BaseListMarker
,
780 sizeof (BaseListMarker
) - 8
783 return AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
787 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
788 ASCII format string and a BASE_LIST argument list.
790 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
792 The ASCII string is produced by parsing the format string specified by FormatString.
793 Arguments are pulled from the variable argument list specified by Marker based on
794 the contents of the format string.
795 The number of ASCII characters in the produced output buffer is returned not including
797 If BufferSize is 0, then no output buffer is produced and 0 is returned.
799 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
800 If BufferSize > 0 and FormatString is NULL, then ASSERT().
801 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
802 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
803 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
805 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
806 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
807 Null-terminator, then ASSERT().
809 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
811 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
812 @param FormatString Null-terminated Unicode format string.
813 @param Marker BASE_LIST marker for the variable argument list.
815 @return The number of ASCII characters in the produced output buffer not including the
821 AsciiBSPrintUnicodeFormat (
822 OUT CHAR8
*StartOfBuffer
,
824 IN CONST CHAR16
*FormatString
,
828 return mPrint2Protocol
->AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
832 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
833 ASCII format string and variable argument list.
835 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
837 The ASCII string is produced by parsing the format string specified by FormatString.
838 Arguments are pulled from the variable argument list based on the contents of the
840 The number of ASCII characters in the produced output buffer is returned not including
842 If BufferSize is 0, then no output buffer is produced and 0 is returned.
844 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
845 If BufferSize > 0 and FormatString is NULL, then ASSERT().
846 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
847 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
848 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
850 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
851 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
852 Null-terminator, then ASSERT().
854 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
856 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
857 @param FormatString Null-terminated Unicode format string.
858 @param ... Variable argument list whose contents are accessed based on the
859 format string specified by FormatString.
861 @return The number of ASCII characters in the produced output buffer not including the
867 AsciiSPrintUnicodeFormat (
868 OUT CHAR8
*StartOfBuffer
,
870 IN CONST CHAR16
*FormatString
,
875 UINTN NumberOfPrinted
;
877 VA_START (Marker
, FormatString
);
878 NumberOfPrinted
= AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
880 return NumberOfPrinted
;
885 Converts a decimal value to a Null-terminated ASCII string.
887 Converts the decimal number specified by Value to a Null-terminated ASCII string
888 specified by Buffer containing at most Width characters. No padding of spaces
890 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
891 The number of ASCII characters in Buffer is returned not including the Null-terminator.
892 If the conversion contains more than Width characters, then only the first Width
893 characters are returned, and the total number of characters required to perform
894 the conversion is returned.
895 Additional conversion parameters are specified in Flags.
896 The Flags bit LEFT_JUSTIFY is always ignored.
897 All conversions are left justified in Buffer.
898 If Width is 0, PREFIX_ZERO is ignored in Flags.
899 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
900 are inserted every 3rd digit starting from the right.
901 If RADIX_HEX is set in Flags, then the output buffer will be
902 formatted in hexadecimal format.
903 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
904 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
905 then Buffer is padded with '0' characters so the combination of the optional '-'
906 sign character, '0' characters, digit characters for Value, and the Null-terminator
907 add up to Width characters.
909 If Buffer is NULL, then ASSERT().
910 If unsupported bits are set in Flags, then ASSERT().
911 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
912 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
914 @param Buffer Pointer to the output buffer for the produced Null-terminated
916 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
917 @param Value The 64-bit signed value to convert to a string.
918 @param Width The maximum number of ASCII characters to place in Buffer, not including
921 @return The number of ASCII characters in Buffer not including the Null-terminator.
933 return mPrint2Protocol
->AsciiValueToString (Buffer
, Flags
, Value
, Width
);
936 #define PREFIX_SIGN BIT1
937 #define PREFIX_BLANK BIT2
938 #define LONG_TYPE BIT4
939 #define OUTPUT_UNICODE BIT6
940 #define FORMAT_UNICODE BIT8
941 #define PAD_TO_WIDTH BIT9
942 #define ARGUMENT_UNICODE BIT10
943 #define PRECISION BIT11
944 #define ARGUMENT_REVERSED BIT12
945 #define COUNT_ONLY_NO_PRINT BIT13
948 // Record date and time information
964 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
967 Internal function that convert a number to a string in Buffer.
969 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.
971 @param Buffer Location to place the ASCII string of Value.
972 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.
973 @param Radix Radix of the value
975 @return A pointer to the end of buffer filled with ASCII string.
979 InternalPrintLibValueToString (
980 IN OUT CHAR8
*Buffer
,
988 // Loop to convert one digit at a time in reverse order
992 Value
= (INT64
)DivU64x32Remainder ((UINT64
)Value
, (UINT32
)Radix
, &Remainder
);
993 *(++Buffer
) = mHexStr
[Remainder
];
994 } while (Value
!= 0);
997 // Return pointer of the end of filled buffer.
1003 Worker function that produces a Null-terminated string in an output buffer
1004 based on a Null-terminated format string and a VA_LIST argument list.
1006 VSPrint function to process format and place the results in Buffer. Since a
1007 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1008 this is the main print working routine.
1010 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1012 @param[out] Buffer The character buffer to print the results of the
1013 parsing of Format into.
1014 @param[in] BufferSize The maximum number of characters to put into
1016 @param[in] Flags Initial flags value.
1017 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1018 and COUNT_ONLY_NO_PRINT set.
1019 @param[in] Format A Null-terminated format string.
1020 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1022 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1023 by processing Format.
1025 @return The number of characters printed not including the Null-terminator.
1026 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1027 modification to Buffer.
1031 InternalPrintLibSPrintMarker (
1033 IN UINTN BufferSize
,
1035 IN CONST CHAR8
*Format
,
1036 IN VA_LIST VaListMarker
, OPTIONAL
1037 IN BASE_LIST BaseListMarker OPTIONAL
1041 Worker function that produces a Null-terminated string in an output buffer
1042 based on a Null-terminated format string and variable argument list.
1044 VSPrint function to process format and place the results in Buffer. Since a
1045 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1046 this is the main print working routine
1048 @param StartOfBuffer The character buffer to print the results of the parsing
1050 @param BufferSize The maximum number of characters to put into buffer.
1051 Zero means no limit.
1052 @param Flags Initial flags value.
1053 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
1054 @param FormatString A Null-terminated format string.
1055 @param ... The variable argument list.
1057 @return The number of characters printed.
1062 InternalPrintLibSPrint (
1063 OUT CHAR8
*StartOfBuffer
,
1064 IN UINTN BufferSize
,
1066 IN CONST CHAR8
*FormatString
,
1071 UINTN NumberOfPrinted
;
1073 VA_START (Marker
, FormatString
);
1074 NumberOfPrinted
= InternalPrintLibSPrintMarker (StartOfBuffer
, BufferSize
, Flags
, FormatString
, Marker
, NULL
);
1076 return NumberOfPrinted
;
1079 #define WARNING_STATUS_NUMBER 5
1080 #define ERROR_STATUS_NUMBER 33
1082 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8
*mStatusString
[] = {
1083 "Success", // RETURN_SUCCESS = 0
1084 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
1085 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
1086 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
1087 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
1088 "Warning Stale Data", // RETURN_WARN_STALE_DATA = 5
1089 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
1090 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
1091 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
1092 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
1093 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
1094 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
1095 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
1096 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
1097 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
1098 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
1099 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
1100 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
1101 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
1102 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
1103 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
1104 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
1105 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
1106 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
1107 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
1108 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
1109 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
1110 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
1111 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
1112 "Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
1113 "Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT
1114 "Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT
1115 "CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT
1116 "End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT
1117 "Reserved (29)", // RESERVED = 29 | MAX_BIT
1118 "Reserved (30)", // RESERVED = 30 | MAX_BIT
1119 "End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT
1120 "Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT
1121 "Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT
1125 Internal function that places the character into the Buffer.
1127 Internal function that places ASCII or Unicode character into the Buffer.
1129 @param Buffer The buffer to place the Unicode or ASCII string.
1130 @param EndBuffer The end of the input Buffer. No characters will be
1132 @param Length The count of character to be placed into Buffer.
1133 (Negative value indicates no buffer fill.)
1134 @param Character The character to be placed into Buffer.
1135 @param Increment The character increment in Buffer.
1141 InternalPrintLibFillBuffer (
1143 IN CHAR8
*EndBuffer
,
1151 for (Index
= 0; Index
< Length
&& Buffer
< EndBuffer
; Index
++) {
1152 *Buffer
= (CHAR8
) Character
;
1153 if (Increment
!= 1) {
1154 *(Buffer
+ 1) = (CHAR8
)(Character
>> 8);
1156 Buffer
+= Increment
;
1163 Worker function that produces a Null-terminated string in an output buffer
1164 based on a Null-terminated format string and a VA_LIST argument list.
1166 VSPrint function to process format and place the results in Buffer. Since a
1167 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1168 this is the main print working routine.
1170 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1172 @param[out] Buffer The character buffer to print the results of the
1173 parsing of Format into.
1174 @param[in] BufferSize The maximum number of characters to put into
1176 @param[in] Flags Initial flags value.
1177 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1178 and COUNT_ONLY_NO_PRINT set.
1179 @param[in] Format A Null-terminated format string.
1180 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1182 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1183 by processing Format.
1185 @return The number of characters printed not including the Null-terminator.
1186 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1187 modification to Buffer.
1191 InternalPrintLibSPrintMarker (
1193 IN UINTN BufferSize
,
1195 IN CONST CHAR8
*Format
,
1196 IN VA_LIST VaListMarker
, OPTIONAL
1197 IN BASE_LIST BaseListMarker OPTIONAL
1200 CHAR8
*OriginalBuffer
;
1202 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
1203 UINT32 BytesPerOutputCharacter
;
1204 UINTN BytesPerFormatCharacter
;
1206 UINTN FormatCharacter
;
1210 CONST CHAR8
*ArgumentString
;
1216 INTN BytesPerArgumentCharacter
;
1217 UINTN ArgumentCharacter
;
1225 RETURN_STATUS Status
;
1229 UINTN LengthToReturn
;
1232 // If you change this code be sure to match the 2 versions of this function.
1233 // Nearly identical logic is found in the BasePrintLib and
1234 // DxePrintLibPrint2Protocol (both PrintLib instances).
1237 if ((Flags
& COUNT_ONLY_NO_PRINT
) != 0) {
1238 if (BufferSize
== 0) {
1243 // We can run without a Buffer for counting only.
1245 if (BufferSize
== 0) {
1248 ASSERT (Buffer
!= NULL
);
1251 if ((Flags
& OUTPUT_UNICODE
) != 0) {
1252 BytesPerOutputCharacter
= 2;
1254 BytesPerOutputCharacter
= 1;
1259 OriginalBuffer
= NULL
;
1262 // Reserve space for the Null terminator.
1264 if (Buffer
!= NULL
) {
1266 OriginalBuffer
= Buffer
;
1269 // Set the tag for the end of the input Buffer.
1271 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
1274 if ((Flags
& FORMAT_UNICODE
) != 0) {
1276 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
1277 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1279 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
1280 BytesPerFormatCharacter
= 2;
1281 FormatMask
= 0xffff;
1284 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
1285 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
1287 ASSERT (AsciiStrSize (Format
) != 0);
1288 BytesPerFormatCharacter
= 1;
1293 // Get the first character from the format string
1295 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1298 // Loop until the end of the format string is reached or the output buffer is full
1300 while (FormatCharacter
!= 0) {
1301 if ((Buffer
!= NULL
) && (Buffer
>= EndBuffer
)) {
1305 // Clear all the flag bits except those that may have been passed in
1307 Flags
&= (UINTN
) (OUTPUT_UNICODE
| FORMAT_UNICODE
| COUNT_ONLY_NO_PRINT
);
1310 // Set the default width to zero, and the default precision to 1
1320 switch (FormatCharacter
) {
1323 // Parse Flags and Width
1325 for (Done
= FALSE
; !Done
; ) {
1326 Format
+= BytesPerFormatCharacter
;
1327 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1328 switch (FormatCharacter
) {
1333 Flags
|= LEFT_JUSTIFY
;
1336 Flags
|= PREFIX_SIGN
;
1339 Flags
|= PREFIX_BLANK
;
1342 Flags
|= COMMA_TYPE
;
1349 if ((Flags
& PRECISION
) == 0) {
1350 Flags
|= PAD_TO_WIDTH
;
1351 if (BaseListMarker
== NULL
) {
1352 Width
= VA_ARG (VaListMarker
, UINTN
);
1354 Width
= BASE_ARG (BaseListMarker
, UINTN
);
1357 if (BaseListMarker
== NULL
) {
1358 Precision
= VA_ARG (VaListMarker
, UINTN
);
1360 Precision
= BASE_ARG (BaseListMarker
, UINTN
);
1365 if ((Flags
& PRECISION
) == 0) {
1366 Flags
|= PREFIX_ZERO
;
1377 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
1378 Count
= (Count
* 10) + FormatCharacter
- '0';
1379 Format
+= BytesPerFormatCharacter
;
1380 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1382 Format
-= BytesPerFormatCharacter
;
1383 if ((Flags
& PRECISION
) == 0) {
1384 Flags
|= PAD_TO_WIDTH
;
1393 // Make no output if Format string terminates unexpectedly when
1394 // looking up for flag, width, precision and type.
1396 Format
-= BytesPerFormatCharacter
;
1399 // break skipped on purpose.
1408 // Handle each argument type
1410 switch (FormatCharacter
) {
1413 // Flag space, +, 0, L & l are invalid for type p.
1415 Flags
&= ~((UINTN
) (PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
));
1416 if (sizeof (VOID
*) > 4) {
1420 // break skipped on purpose
1423 Flags
|= PREFIX_ZERO
;
1425 // break skipped on purpose
1430 // break skipped on purpose
1433 if ((Flags
& LONG_TYPE
) == 0) {
1435 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1436 // This assumption is made so the format string definition is compatible with the ANSI C
1437 // Specification for formatted strings. It is recommended that the Base Types be used
1438 // everywhere, but in this one case, compliance with ANSI C is more important, and
1439 // provides an implementation that is compatible with that largest possible set of CPU
1440 // architectures. This is why the type "int" is used in this one case.
1442 if (BaseListMarker
== NULL
) {
1443 Value
= VA_ARG (VaListMarker
, int);
1445 Value
= BASE_ARG (BaseListMarker
, int);
1448 if (BaseListMarker
== NULL
) {
1449 Value
= VA_ARG (VaListMarker
, INT64
);
1451 Value
= BASE_ARG (BaseListMarker
, INT64
);
1454 if ((Flags
& PREFIX_BLANK
) != 0) {
1457 if ((Flags
& PREFIX_SIGN
) != 0) {
1460 if ((Flags
& COMMA_TYPE
) != 0) {
1463 if ((Flags
& RADIX_HEX
) == 0) {
1466 Flags
&= ~((UINTN
) PREFIX_ZERO
);
1470 Flags
|= PREFIX_SIGN
;
1477 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
1479 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1480 // This assumption is made so the format string definition is compatible with the ANSI C
1481 // Specification for formatted strings. It is recommended that the Base Types be used
1482 // everywhere, but in this one case, compliance with ANSI C is more important, and
1483 // provides an implementation that is compatible with that largest possible set of CPU
1484 // architectures. This is why the type "unsigned int" is used in this one case.
1486 Value
= (unsigned int)Value
;
1490 // Convert Value to a reversed string
1492 Count
= InternalPrintLibValueToString (ValueBuffer
, Value
, Radix
) - ValueBuffer
;
1493 if (Value
== 0 && Precision
== 0) {
1496 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
1500 Digits
= 3 - Digits
;
1502 if (Comma
&& Count
!= 0) {
1503 Count
+= ((Count
- 1) / 3);
1509 Flags
|= ARGUMENT_REVERSED
;
1511 if ((Flags
& PREFIX_ZERO
) != 0) {
1512 if ((Flags
& LEFT_JUSTIFY
) == 0) {
1513 if ((Flags
& PAD_TO_WIDTH
) != 0) {
1514 if ((Flags
& PRECISION
) == 0) {
1524 Flags
|= ARGUMENT_UNICODE
;
1526 // break skipped on purpose
1529 if (BaseListMarker
== NULL
) {
1530 ArgumentString
= VA_ARG (VaListMarker
, CHAR8
*);
1532 ArgumentString
= BASE_ARG (BaseListMarker
, CHAR8
*);
1534 if (ArgumentString
== NULL
) {
1535 Flags
&= (~(UINTN
)ARGUMENT_UNICODE
);
1536 ArgumentString
= "<null string>";
1539 // Set the default precision for string to be zero if not specified.
1541 if ((Flags
& PRECISION
) == 0) {
1547 if (BaseListMarker
== NULL
) {
1548 Character
= VA_ARG (VaListMarker
, UINTN
) & 0xffff;
1550 Character
= BASE_ARG (BaseListMarker
, UINTN
) & 0xffff;
1552 ArgumentString
= (CHAR8
*)&Character
;
1553 Flags
|= ARGUMENT_UNICODE
;
1557 if (BaseListMarker
== NULL
) {
1558 TmpGuid
= VA_ARG (VaListMarker
, GUID
*);
1560 TmpGuid
= BASE_ARG (BaseListMarker
, GUID
*);
1562 if (TmpGuid
== NULL
) {
1563 ArgumentString
= "<null guid>";
1565 GuidData1
= ReadUnaligned32 (&(TmpGuid
->Data1
));
1566 GuidData2
= ReadUnaligned16 (&(TmpGuid
->Data2
));
1567 GuidData3
= ReadUnaligned16 (&(TmpGuid
->Data3
));
1568 InternalPrintLibSPrint (
1570 MAXIMUM_VALUE_CHARACTERS
,
1572 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1585 ArgumentString
= ValueBuffer
;
1590 if (BaseListMarker
== NULL
) {
1591 TmpTime
= VA_ARG (VaListMarker
, TIME
*);
1593 TmpTime
= BASE_ARG (BaseListMarker
, TIME
*);
1595 if (TmpTime
== NULL
) {
1596 ArgumentString
= "<null time>";
1598 InternalPrintLibSPrint (
1600 MAXIMUM_VALUE_CHARACTERS
,
1602 "%02d/%02d/%04d %02d:%02d",
1609 ArgumentString
= ValueBuffer
;
1614 if (BaseListMarker
== NULL
) {
1615 Status
= VA_ARG (VaListMarker
, RETURN_STATUS
);
1617 Status
= BASE_ARG (BaseListMarker
, RETURN_STATUS
);
1619 ArgumentString
= ValueBuffer
;
1620 if (RETURN_ERROR (Status
)) {
1624 Index
= Status
& ~MAX_BIT
;
1625 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
1626 ArgumentString
= mStatusString
[Index
+ WARNING_STATUS_NUMBER
];
1630 if (Index
<= WARNING_STATUS_NUMBER
) {
1631 ArgumentString
= mStatusString
[Index
];
1634 if (ArgumentString
== ValueBuffer
) {
1635 InternalPrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
1640 Format
+= BytesPerFormatCharacter
;
1641 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1642 if (FormatCharacter
== '\n') {
1644 // Translate '\r\n' to '\r\n'
1646 ArgumentString
= "\r\n";
1649 // Translate '\r' to '\r'
1651 ArgumentString
= "\r";
1652 Format
-= BytesPerFormatCharacter
;
1658 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1660 ArgumentString
= "\r\n";
1661 Format
+= BytesPerFormatCharacter
;
1662 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1663 if (FormatCharacter
!= '\r') {
1664 Format
-= BytesPerFormatCharacter
;
1671 // if the type is '%' or unknown, then print it to the screen
1673 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1674 Flags
|= ARGUMENT_UNICODE
;
1680 Format
+= BytesPerFormatCharacter
;
1681 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1682 if (FormatCharacter
== '\n') {
1684 // Translate '\r\n' to '\r\n'
1686 ArgumentString
= "\r\n";
1689 // Translate '\r' to '\r'
1691 ArgumentString
= "\r";
1692 Format
-= BytesPerFormatCharacter
;
1698 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1700 ArgumentString
= "\r\n";
1701 Format
+= BytesPerFormatCharacter
;
1702 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1703 if (FormatCharacter
!= '\r') {
1704 Format
-= BytesPerFormatCharacter
;
1709 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1710 Flags
|= ARGUMENT_UNICODE
;
1715 // Retrieve the ArgumentString attriubutes
1717 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
1718 ArgumentMask
= 0xffff;
1719 BytesPerArgumentCharacter
= 2;
1721 ArgumentMask
= 0xff;
1722 BytesPerArgumentCharacter
= 1;
1724 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
1725 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
1728 // Compute the number of characters in ArgumentString and store it in Count
1729 // ArgumentString is either null-terminated, or it contains Precision characters
1731 for (Count
= 0; Count
< Precision
|| ((Flags
& PRECISION
) == 0); Count
++) {
1732 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
1733 if (ArgumentCharacter
== 0) {
1739 if (Precision
< Count
) {
1744 // Pad before the string
1746 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
1747 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1748 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1749 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
1755 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1756 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1757 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
1760 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1761 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1762 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, '0', BytesPerOutputCharacter
);
1765 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1766 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1767 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, ' ', BytesPerOutputCharacter
);
1770 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1771 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1772 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
1778 // Output the Prefix character if it is present
1786 // Copy the string into the output buffer performing the required type conversions
1788 while (Index
< Count
) {
1789 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (*(ArgumentString
+ 1) << 8)) & ArgumentMask
;
1791 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1792 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1793 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, ArgumentCharacter
, BytesPerOutputCharacter
);
1795 ArgumentString
+= BytesPerArgumentCharacter
;
1802 if (Index
< Count
) {
1803 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1804 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1805 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, 1, ',', BytesPerOutputCharacter
);
1813 // Pad after the string
1815 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
1816 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1817 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
1818 Buffer
= InternalPrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
1823 // Get the next character from the format string
1825 Format
+= BytesPerFormatCharacter
;
1828 // Get the next character from the format string
1830 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1833 if ((Flags
& COUNT_ONLY_NO_PRINT
) != 0) {
1834 return (LengthToReturn
/ BytesPerOutputCharacter
);
1837 ASSERT (Buffer
!= NULL
);
1839 // Null terminate the Unicode or ASCII string
1841 InternalPrintLibFillBuffer (Buffer
, EndBuffer
+ BytesPerOutputCharacter
, 1, 0, BytesPerOutputCharacter
);
1843 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
1844 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1846 ASSERT ((((Flags
& OUTPUT_UNICODE
) == 0)) || (StrSize ((CHAR16
*) OriginalBuffer
) != 0));
1848 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
1849 // ASCII characters if PcdMaximumAsciiStringLength is not zero.
1851 ASSERT ((((Flags
& OUTPUT_UNICODE
) != 0)) || (AsciiStrSize (OriginalBuffer
) != 0));
1853 return ((Buffer
- OriginalBuffer
) / BytesPerOutputCharacter
);
1857 Returns the number of characters that would be produced by if the formatted
1858 output were produced not including the Null-terminator.
1860 If FormatString is NULL, then ASSERT().
1861 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
1863 @param[in] FormatString A Null-terminated Unicode format string.
1864 @param[in] Marker VA_LIST marker for the variable argument list.
1866 @return The number of characters that would be produced, not including the
1872 IN CONST CHAR16
*FormatString
,
1876 ASSERT(FormatString
!= NULL
);
1877 return InternalPrintLibSPrintMarker (NULL
, 0, FORMAT_UNICODE
| OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);
1881 Returns the number of characters that would be produced by if the formatted
1882 output were produced not including the Null-terminator.
1884 If FormatString is NULL, then ASSERT().
1886 @param[in] FormatString A Null-terminated ASCII format string.
1887 @param[in] Marker VA_LIST marker for the variable argument list.
1889 @return The number of characters that would be produced, not including the
1894 SPrintLengthAsciiFormat (
1895 IN CONST CHAR8
*FormatString
,
1899 ASSERT(FormatString
!= NULL
);
1900 return InternalPrintLibSPrintMarker (NULL
, 0, OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);