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 - 2011, 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/UefiBootServicesTableLib.h>
28 #include <Library/DebugLib.h>
30 EFI_PRINT2_PROTOCOL
*mPrint2Protocol
= NULL
;
33 The constructor function caches the pointer to Print2 protocol.
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.
38 @param ImageHandle The firmware allocated handle for the EFI image.
39 @param SystemTable A pointer to the EFI System Table.
41 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
47 IN EFI_HANDLE ImageHandle
,
48 IN EFI_SYSTEM_TABLE
*SystemTable
53 Status
= gBS
->LocateProtocol (
54 &gEfiPrint2ProtocolGuid
,
56 (VOID
**) &mPrint2Protocol
58 ASSERT_EFI_ERROR (Status
);
59 ASSERT (mPrint2Protocol
!= NULL
);
66 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated
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.
75 @return The number of bytes in BaseListMarker. 0 if BaseListMarker is too small.
79 DxePrintLibPrint2ProtocolVaListToBaseList (
80 IN BOOLEAN AsciiFormat
,
81 IN CONST CHAR8
*Format
,
82 IN VA_LIST VaListMarker
,
83 OUT BASE_LIST BaseListMarker
,
87 BASE_LIST BaseListStart
;
88 UINTN BytesPerFormatCharacter
;
90 UINTN FormatCharacter
;
94 ASSERT (Format
!= NULL
);
95 ASSERT (BaseListMarker
!= NULL
);
97 BaseListStart
= BaseListMarker
;
100 ASSERT (AsciiStrSize (Format
) != 0);
101 BytesPerFormatCharacter
= 1;
104 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
105 BytesPerFormatCharacter
= 2;
110 // Get the first character from the format string
112 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
114 while (FormatCharacter
!= 0) {
115 if (FormatCharacter
== '%') {
119 // Parse Flags and Width
121 for (Done
= FALSE
; !Done
; ) {
123 // Get the next character from the format string
125 Format
+= BytesPerFormatCharacter
;
128 // Get the next character from the format string
130 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
132 switch (FormatCharacter
) {
154 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
158 // Make no output if Format string terminates unexpectedly when
159 // looking up for flag, width, precision and type.
161 Format
-= BytesPerFormatCharacter
;
163 // break skipped on purpose.
172 // Handle each argument type
174 switch (FormatCharacter
) {
176 if (sizeof (VOID
*) > 4) {
183 BASE_ARG (BaseListMarker
, INT64
) = VA_ARG (VaListMarker
, INT64
);
185 BASE_ARG (BaseListMarker
, int) = VA_ARG (VaListMarker
, int);
193 BASE_ARG (BaseListMarker
, VOID
*) = VA_ARG (VaListMarker
, VOID
*);
196 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
199 BASE_ARG (BaseListMarker
, RETURN_STATUS
) = VA_ARG (VaListMarker
, RETURN_STATUS
);
205 // If BASE_LIST is larger than Size, then return FALSE
207 if ((UINTN
)((UINT8
*)BaseListMarker
- (UINT8
*)BaseListStart
) > Size
) {
212 // Get the next character from the format string
214 Format
+= BytesPerFormatCharacter
;
217 // Get the next character from the format string
219 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
225 Produces a Null-terminated Unicode string in an output buffer based on
226 a Null-terminated Unicode format string and a VA_LIST argument list
228 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
230 The Unicode string is produced by parsing the format string specified by FormatString.
231 Arguments are pulled from the variable argument list specified by Marker based on the
232 contents of the format string.
233 The number of Unicode characters in the produced output buffer is returned not including
235 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
237 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
238 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
239 If BufferSize > 1 and FormatString is NULL, then ASSERT().
240 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
241 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
242 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
244 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
245 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
246 Null-terminator, then ASSERT().
248 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
250 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
251 @param FormatString Null-terminated Unicode format string.
252 @param Marker VA_LIST marker for the variable argument list.
254 @return The number of Unicode characters in the produced output buffer not including the
261 OUT CHAR16
*StartOfBuffer
,
263 IN CONST CHAR16
*FormatString
,
267 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
269 DxePrintLibPrint2ProtocolVaListToBaseList (
271 (CHAR8
*)FormatString
,
273 (BASE_LIST
)BaseListMarker
,
274 sizeof (BaseListMarker
) - 8
277 return UnicodeBSPrint (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
281 Produces a Null-terminated Unicode string in an output buffer based on
282 a Null-terminated Unicode format string and a BASE_LIST argument list
284 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
286 The Unicode string is produced by parsing the format string specified by FormatString.
287 Arguments are pulled from the variable argument list specified by Marker based on the
288 contents of the format string.
289 The number of Unicode characters in the produced output buffer is returned not including
291 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
293 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
294 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
295 If BufferSize > 1 and FormatString is NULL, then ASSERT().
296 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
297 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
298 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
300 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
301 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
302 Null-terminator, then ASSERT().
304 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
306 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
307 @param FormatString Null-terminated Unicode format string.
308 @param Marker BASE_LIST marker for the variable argument list.
310 @return The number of Unicode characters in the produced output buffer not including the
317 OUT CHAR16
*StartOfBuffer
,
319 IN CONST CHAR16
*FormatString
,
323 return mPrint2Protocol
->UnicodeBSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
327 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
328 Unicode format string and variable argument list.
330 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
332 The Unicode string is produced by parsing the format string specified by FormatString.
333 Arguments are pulled from the variable argument list based on the contents of the format string.
334 The number of Unicode characters in the produced output buffer is returned not including
336 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
338 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
339 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
340 If BufferSize > 1 and FormatString is NULL, then ASSERT().
341 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
342 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
343 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
345 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
346 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
347 Null-terminator, then ASSERT().
349 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
351 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
352 @param FormatString Null-terminated Unicode format string.
353 @param ... Variable argument list whose contents are accessed based on the
354 format string specified by FormatString.
356 @return The number of Unicode characters in the produced output buffer not including the
363 OUT CHAR16
*StartOfBuffer
,
365 IN CONST CHAR16
*FormatString
,
371 VA_START (Marker
, FormatString
);
372 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
376 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
377 ASCII format string and a VA_LIST argument list
379 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
381 The Unicode string is produced by parsing the format string specified by FormatString.
382 Arguments are pulled from the variable argument list specified by Marker based on the
383 contents of the format string.
384 The number of Unicode characters in the produced output buffer is returned not including
386 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
388 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
389 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
390 If BufferSize > 1 and FormatString is NULL, then ASSERT().
391 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
392 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
394 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
395 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
396 Null-terminator, then ASSERT().
398 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
400 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
401 @param FormatString Null-terminated Unicode format string.
402 @param Marker VA_LIST marker for the variable argument list.
404 @return The number of Unicode characters in the produced output buffer not including the
410 UnicodeVSPrintAsciiFormat (
411 OUT CHAR16
*StartOfBuffer
,
413 IN CONST CHAR8
*FormatString
,
417 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
419 DxePrintLibPrint2ProtocolVaListToBaseList (
423 (BASE_LIST
)BaseListMarker
,
424 sizeof (BaseListMarker
) - 8
427 return UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
431 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
432 ASCII format string and a BASE_LIST argument list
434 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
436 The Unicode string is produced by parsing the format string specified by FormatString.
437 Arguments are pulled from the variable argument list specified by Marker based on the
438 contents of the format string.
439 The number of Unicode characters in the produced output buffer is returned not including
441 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
443 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
444 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
445 If BufferSize > 1 and FormatString is NULL, then ASSERT().
446 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
447 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
449 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
450 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
451 Null-terminator, then ASSERT().
453 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
455 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
456 @param FormatString Null-terminated Unicode format string.
457 @param Marker BASE_LIST marker for the variable argument list.
459 @return The number of Unicode characters in the produced output buffer not including the
465 UnicodeBSPrintAsciiFormat (
466 OUT CHAR16
*StartOfBuffer
,
468 IN CONST CHAR8
*FormatString
,
472 return mPrint2Protocol
->UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
476 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
477 ASCII format string and variable argument list.
479 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
481 The Unicode string is produced by parsing the format string specified by FormatString.
482 Arguments are pulled from the variable argument list based on the contents of the
484 The number of Unicode characters in the produced output buffer is returned not including
486 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
488 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
489 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
490 If BufferSize > 1 and FormatString is NULL, then ASSERT().
491 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
492 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
494 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
495 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
496 Null-terminator, then ASSERT().
498 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
500 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
501 @param FormatString Null-terminated Unicode format string.
502 @param ... Variable argument list whose contents are accessed based on the
503 format string specified by FormatString.
505 @return The number of Unicode characters in the produced output buffer not including the
511 UnicodeSPrintAsciiFormat (
512 OUT CHAR16
*StartOfBuffer
,
514 IN CONST CHAR8
*FormatString
,
520 VA_START (Marker
, FormatString
);
521 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
525 Converts a decimal value to a Null-terminated Unicode string.
527 Converts the decimal number specified by Value to a Null-terminated Unicode
528 string specified by Buffer containing at most Width characters. No padding of spaces
529 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
530 The number of Unicode characters in Buffer is returned not including the Null-terminator.
531 If the conversion contains more than Width characters, then only the first
532 Width characters are returned, and the total number of characters
533 required to perform the conversion is returned.
534 Additional conversion parameters are specified in Flags.
536 The Flags bit LEFT_JUSTIFY is always ignored.
537 All conversions are left justified in Buffer.
538 If Width is 0, PREFIX_ZERO is ignored in Flags.
539 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
540 are inserted every 3rd digit starting from the right.
541 If RADIX_HEX is set in Flags, then the output buffer will be
542 formatted in hexadecimal format.
543 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
544 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
545 then Buffer is padded with '0' characters so the combination of the optional '-'
546 sign character, '0' characters, digit characters for Value, and the Null-terminator
547 add up to Width characters.
548 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
549 If Buffer is NULL, then ASSERT().
550 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
551 If unsupported bits are set in Flags, then ASSERT().
552 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
553 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
555 @param Buffer Pointer to the output buffer for the produced Null-terminated
557 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
558 @param Value The 64-bit signed value to convert to a string.
559 @param Width The maximum number of Unicode characters to place in Buffer, not including
562 @return The number of Unicode characters in Buffer not including the Null-terminator.
567 UnicodeValueToString (
568 IN OUT CHAR16
*Buffer
,
574 return mPrint2Protocol
->UnicodeValueToString (Buffer
, Flags
, Value
, Width
);
578 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
579 ASCII format string and a VA_LIST argument list.
581 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
583 The ASCII string is produced by parsing the format string specified by FormatString.
584 Arguments are pulled from the variable argument list specified by Marker based on
585 the contents of the format string.
586 The number of ASCII characters in the produced output buffer is returned not including
588 If BufferSize is 0, then no output buffer is produced and 0 is returned.
590 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
591 If BufferSize > 0 and FormatString is NULL, then ASSERT().
592 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
593 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
595 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
596 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
597 Null-terminator, then ASSERT().
599 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
601 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
602 @param FormatString Null-terminated Unicode format string.
603 @param Marker VA_LIST marker for the variable argument list.
605 @return The number of ASCII characters in the produced output buffer not including the
612 OUT CHAR8
*StartOfBuffer
,
614 IN CONST CHAR8
*FormatString
,
618 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
620 DxePrintLibPrint2ProtocolVaListToBaseList (
624 (BASE_LIST
)BaseListMarker
,
625 sizeof (BaseListMarker
) - 8
628 return AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
632 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
633 ASCII format string and a BASE_LIST argument list.
635 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
637 The ASCII string is produced by parsing the format string specified by FormatString.
638 Arguments are pulled from the variable argument list specified by Marker based on
639 the contents of the format string.
640 The number of ASCII characters in the produced output buffer is returned not including
642 If BufferSize is 0, then no output buffer is produced and 0 is returned.
644 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
645 If BufferSize > 0 and FormatString is NULL, then ASSERT().
646 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
647 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
649 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
650 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
651 Null-terminator, then ASSERT().
653 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
655 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
656 @param FormatString Null-terminated Unicode format string.
657 @param Marker BASE_LIST marker for the variable argument list.
659 @return The number of ASCII characters in the produced output buffer not including the
666 OUT CHAR8
*StartOfBuffer
,
668 IN CONST CHAR8
*FormatString
,
672 return mPrint2Protocol
->AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
676 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
677 ASCII format string and variable argument list.
679 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
681 The ASCII string is produced by parsing the format string specified by FormatString.
682 Arguments are pulled from the variable argument list based on the contents of the
684 The number of ASCII characters in the produced output buffer is returned not including
686 If BufferSize is 0, then no output buffer is produced and 0 is returned.
688 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
689 If BufferSize > 0 and FormatString is NULL, then ASSERT().
690 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
691 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
693 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
694 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
695 Null-terminator, then ASSERT().
697 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
699 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
700 @param FormatString Null-terminated Unicode format string.
701 @param ... Variable argument list whose contents are accessed based on the
702 format string specified by FormatString.
704 @return The number of ASCII characters in the produced output buffer not including the
711 OUT CHAR8
*StartOfBuffer
,
713 IN CONST CHAR8
*FormatString
,
719 VA_START (Marker
, FormatString
);
720 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
724 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
725 ASCII format string and a VA_LIST argument list.
727 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
729 The ASCII string is produced by parsing the format string specified by FormatString.
730 Arguments are pulled from the variable argument list specified by Marker based on
731 the contents of the format string.
732 The number of ASCII characters in the produced output buffer is returned not including
734 If BufferSize is 0, then no output buffer is produced and 0 is returned.
736 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
737 If BufferSize > 0 and FormatString is NULL, then ASSERT().
738 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
739 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
740 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
742 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
743 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
744 Null-terminator, then ASSERT().
746 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
748 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
749 @param FormatString Null-terminated Unicode format string.
750 @param Marker VA_LIST marker for the variable argument list.
752 @return The number of ASCII characters in the produced output buffer not including the
758 AsciiVSPrintUnicodeFormat (
759 OUT CHAR8
*StartOfBuffer
,
761 IN CONST CHAR16
*FormatString
,
765 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
767 DxePrintLibPrint2ProtocolVaListToBaseList (
769 (CHAR8
*)FormatString
,
771 (BASE_LIST
)BaseListMarker
,
772 sizeof (BaseListMarker
) - 8
775 return AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
779 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
780 ASCII format string and a BASE_LIST argument list.
782 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
784 The ASCII string is produced by parsing the format string specified by FormatString.
785 Arguments are pulled from the variable argument list specified by Marker based on
786 the contents of the format string.
787 The number of ASCII characters in the produced output buffer is returned not including
789 If BufferSize is 0, then no output buffer is produced and 0 is returned.
791 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
792 If BufferSize > 0 and FormatString is NULL, then ASSERT().
793 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
794 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
795 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
797 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
798 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
799 Null-terminator, then ASSERT().
801 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
803 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
804 @param FormatString Null-terminated Unicode format string.
805 @param Marker BASE_LIST marker for the variable argument list.
807 @return The number of ASCII characters in the produced output buffer not including the
813 AsciiBSPrintUnicodeFormat (
814 OUT CHAR8
*StartOfBuffer
,
816 IN CONST CHAR16
*FormatString
,
820 return mPrint2Protocol
->AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
824 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
825 ASCII format string and variable argument list.
827 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
829 The ASCII string is produced by parsing the format string specified by FormatString.
830 Arguments are pulled from the variable argument list based on the contents of the
832 The number of ASCII characters in the produced output buffer is returned not including
834 If BufferSize is 0, then no output buffer is produced and 0 is returned.
836 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
837 If BufferSize > 0 and FormatString is NULL, then ASSERT().
838 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
839 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
840 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
842 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
843 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
844 Null-terminator, then ASSERT().
846 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
848 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
849 @param FormatString Null-terminated Unicode format string.
850 @param ... Variable argument list whose contents are accessed based on the
851 format string specified by FormatString.
853 @return The number of ASCII characters in the produced output buffer not including the
859 AsciiSPrintUnicodeFormat (
860 OUT CHAR8
*StartOfBuffer
,
862 IN CONST CHAR16
*FormatString
,
868 VA_START (Marker
, FormatString
);
869 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
874 Converts a decimal value to a Null-terminated ASCII string.
876 Converts the decimal number specified by Value to a Null-terminated ASCII string
877 specified by Buffer containing at most Width characters. No padding of spaces
879 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
880 The number of ASCII characters in Buffer is returned not including the Null-terminator.
881 If the conversion contains more than Width characters, then only the first Width
882 characters are returned, and the total number of characters required to perform
883 the conversion is returned.
884 Additional conversion parameters are specified in Flags.
885 The Flags bit LEFT_JUSTIFY is always ignored.
886 All conversions are left justified in Buffer.
887 If Width is 0, PREFIX_ZERO is ignored in Flags.
888 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
889 are inserted every 3rd digit starting from the right.
890 If RADIX_HEX is set in Flags, then the output buffer will be
891 formatted in hexadecimal format.
892 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
893 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
894 then Buffer is padded with '0' characters so the combination of the optional '-'
895 sign character, '0' characters, digit characters for Value, and the Null-terminator
896 add up to Width characters.
898 If Buffer is NULL, then ASSERT().
899 If unsupported bits are set in Flags, then ASSERT().
900 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
901 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
903 @param Buffer Pointer to the output buffer for the produced Null-terminated
905 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
906 @param Value The 64-bit signed value to convert to a string.
907 @param Width The maximum number of ASCII characters to place in Buffer, not including
910 @return The number of ASCII characters in Buffer not including the Null-terminator.
922 return mPrint2Protocol
->AsciiValueToString (Buffer
, Flags
, Value
, Width
);
925 #define PREFIX_SIGN BIT1
926 #define PREFIX_BLANK BIT2
927 #define LONG_TYPE BIT4
928 #define OUTPUT_UNICODE BIT6
929 #define FORMAT_UNICODE BIT8
930 #define PAD_TO_WIDTH BIT9
931 #define ARGUMENT_UNICODE BIT10
932 #define PRECISION BIT11
933 #define ARGUMENT_REVERSED BIT12
934 #define COUNT_ONLY_NO_PRINT BIT13
937 // Record date and time information
953 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
956 Internal function that convert a number to a string in Buffer.
958 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.
960 @param Buffer Location to place the ASCII string of Value.
961 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.
962 @param Radix Radix of the value
964 @return A pointer to the end of buffer filled with ASCII string.
968 InternalPrintLibValueToString (
969 IN OUT CHAR8
*Buffer
,
977 // Loop to convert one digit at a time in reverse order
981 Value
= (INT64
)DivU64x32Remainder ((UINT64
)Value
, (UINT32
)Radix
, &Remainder
);
982 *(++Buffer
) = mHexStr
[Remainder
];
983 } while (Value
!= 0);
986 // Return pointer of the end of filled buffer.
992 Worker function that produces a Null-terminated string in an output buffer
993 based on a Null-terminated format string and a VA_LIST argument list.
995 VSPrint function to process format and place the results in Buffer. Since a
996 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
997 this is the main print working routine.
999 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1001 @param[out] Buffer The character buffer to print the results of the
1002 parsing of Format into.
1003 @param[in] BufferSize The maximum number of characters to put into
1005 @param[in] Flags Initial flags value.
1006 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1007 and COUNT_ONLY_NO_PRINT set.
1008 @param[in] Format A Null-terminated format string.
1009 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1011 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1012 by processing Format.
1014 @return The number of characters printed not including the Null-terminator.
1015 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1016 modification to Buffer.
1020 InternalPrintLibSPrintMarker (
1022 IN UINTN BufferSize
,
1024 IN CONST CHAR8
*Format
,
1025 IN VA_LIST VaListMarker
, OPTIONAL
1026 IN BASE_LIST BaseListMarker OPTIONAL
1030 Worker function that produces a Null-terminated string in an output buffer
1031 based on a Null-terminated format string and variable argument list.
1033 VSPrint function to process format and place the results in Buffer. Since a
1034 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1035 this is the main print working routine
1037 @param StartOfBuffer The character buffer to print the results of the parsing
1039 @param BufferSize The maximum number of characters to put into buffer.
1040 Zero means no limit.
1041 @param Flags Initial flags value.
1042 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
1043 @param FormatString A Null-terminated format string.
1044 @param ... The variable argument list.
1046 @return The number of characters printed.
1051 InternalPrintLibSPrint (
1052 OUT CHAR8
*StartOfBuffer
,
1053 IN UINTN BufferSize
,
1055 IN CONST CHAR8
*FormatString
,
1061 VA_START (Marker
, FormatString
);
1062 return InternalPrintLibSPrintMarker (StartOfBuffer
, BufferSize
, Flags
, FormatString
, Marker
, NULL
);
1065 #define WARNING_STATUS_NUMBER 4
1066 #define ERROR_STATUS_NUMBER 24
1068 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8
*mStatusString
[] = {
1069 "Success", // RETURN_SUCCESS = 0
1070 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
1071 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
1072 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
1073 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
1074 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
1075 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
1076 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
1077 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
1078 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
1079 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
1080 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
1081 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
1082 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
1083 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
1084 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
1085 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
1086 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
1087 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
1088 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
1089 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
1090 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
1091 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
1092 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
1093 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
1094 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
1095 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
1096 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
1097 "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
1101 Worker function that produces a Null-terminated string in an output buffer
1102 based on a Null-terminated format string and a VA_LIST argument list.
1104 VSPrint function to process format and place the results in Buffer. Since a
1105 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1106 this is the main print working routine.
1108 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1110 @param[out] Buffer The character buffer to print the results of the
1111 parsing of Format into.
1112 @param[in] BufferSize The maximum number of characters to put into
1114 @param[in] Flags Initial flags value.
1115 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1116 and COUNT_ONLY_NO_PRINT set.
1117 @param[in] Format A Null-terminated format string.
1118 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1120 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1121 by processing Format.
1123 @return The number of characters printed not including the Null-terminator.
1124 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1125 modification to Buffer.
1129 InternalPrintLibSPrintMarker (
1131 IN UINTN BufferSize
,
1133 IN CONST CHAR8
*Format
,
1134 IN VA_LIST VaListMarker
, OPTIONAL
1135 IN BASE_LIST BaseListMarker OPTIONAL
1138 CHAR8
*OriginalBuffer
;
1140 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
1141 UINT32 BytesPerOutputCharacter
;
1142 UINTN BytesPerFormatCharacter
;
1144 UINTN FormatCharacter
;
1148 CONST CHAR8
*ArgumentString
;
1154 INTN BytesPerArgumentCharacter
;
1155 UINTN ArgumentCharacter
;
1163 RETURN_STATUS Status
;
1167 UINT32 LengthToReturn
;
1170 // If you change this code be sure to match the 2 versions of this function.
1171 // Nearly identical logic is found in the BasePrintLib and
1172 // DxePrintLibPrint2Protocol (both PrintLib instances).
1175 ASSERT(Flags
& COUNT_ONLY_NO_PRINT
);
1177 if (Flags
& OUTPUT_UNICODE
) {
1178 BytesPerOutputCharacter
= 2;
1180 BytesPerOutputCharacter
= 1;
1186 // Reserve space for the Null terminator.
1189 OriginalBuffer
= Buffer
;
1192 // Set the tag for the end of the input Buffer.
1194 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
1196 if ((Flags
& FORMAT_UNICODE
) != 0) {
1198 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
1199 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1201 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
1202 BytesPerFormatCharacter
= 2;
1203 FormatMask
= 0xffff;
1206 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
1207 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
1209 ASSERT (AsciiStrSize (Format
) != 0);
1210 BytesPerFormatCharacter
= 1;
1215 // Get the first character from the format string
1217 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1220 // Loop until the end of the format string is reached or the output buffer is full
1222 while (FormatCharacter
!= 0 && Buffer
< EndBuffer
) {
1224 // Clear all the flag bits except those that may have been passed in
1226 Flags
&= (OUTPUT_UNICODE
| FORMAT_UNICODE
| COUNT_ONLY_NO_PRINT
);
1229 // Set the default width to zero, and the default precision to 1
1239 switch (FormatCharacter
) {
1242 // Parse Flags and Width
1244 for (Done
= FALSE
; !Done
; ) {
1245 Format
+= BytesPerFormatCharacter
;
1246 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1247 switch (FormatCharacter
) {
1252 Flags
|= LEFT_JUSTIFY
;
1255 Flags
|= PREFIX_SIGN
;
1258 Flags
|= PREFIX_BLANK
;
1261 Flags
|= COMMA_TYPE
;
1268 if ((Flags
& PRECISION
) == 0) {
1269 Flags
|= PAD_TO_WIDTH
;
1270 if (BaseListMarker
== NULL
) {
1271 Width
= VA_ARG (VaListMarker
, UINTN
);
1273 Width
= BASE_ARG (BaseListMarker
, UINTN
);
1276 if (BaseListMarker
== NULL
) {
1277 Precision
= VA_ARG (VaListMarker
, UINTN
);
1279 Precision
= BASE_ARG (BaseListMarker
, UINTN
);
1284 if ((Flags
& PRECISION
) == 0) {
1285 Flags
|= PREFIX_ZERO
;
1296 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
1297 Count
= (Count
* 10) + FormatCharacter
- '0';
1298 Format
+= BytesPerFormatCharacter
;
1299 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1301 Format
-= BytesPerFormatCharacter
;
1302 if ((Flags
& PRECISION
) == 0) {
1303 Flags
|= PAD_TO_WIDTH
;
1312 // Make no output if Format string terminates unexpectedly when
1313 // looking up for flag, width, precision and type.
1315 Format
-= BytesPerFormatCharacter
;
1318 // break skipped on purpose.
1327 // Handle each argument type
1329 switch (FormatCharacter
) {
1332 // Flag space, +, 0, L & l are invalid for type p.
1334 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
);
1335 if (sizeof (VOID
*) > 4) {
1339 Flags
|= PREFIX_ZERO
;
1341 // break skipped on purpose
1346 // break skipped on purpose
1349 if ((Flags
& LONG_TYPE
) == 0) {
1351 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1352 // This assumption is made so the format string definition is compatible with the ANSI C
1353 // Specification for formatted strings. It is recommended that the Base Types be used
1354 // everywhere, but in this one case, compliance with ANSI C is more important, and
1355 // provides an implementation that is compatible with that largest possible set of CPU
1356 // architectures. This is why the type "int" is used in this one case.
1358 if (BaseListMarker
== NULL
) {
1359 Value
= VA_ARG (VaListMarker
, int);
1361 Value
= BASE_ARG (BaseListMarker
, int);
1364 if (BaseListMarker
== NULL
) {
1365 Value
= VA_ARG (VaListMarker
, INT64
);
1367 Value
= BASE_ARG (BaseListMarker
, INT64
);
1370 if ((Flags
& PREFIX_BLANK
) != 0) {
1373 if ((Flags
& PREFIX_SIGN
) != 0) {
1376 if ((Flags
& COMMA_TYPE
) != 0) {
1379 if ((Flags
& RADIX_HEX
) == 0) {
1382 Flags
&= (~PREFIX_ZERO
);
1386 Flags
|= PREFIX_SIGN
;
1393 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
1395 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1396 // This assumption is made so the format string definition is compatible with the ANSI C
1397 // Specification for formatted strings. It is recommended that the Base Types be used
1398 // everywhere, but in this one case, compliance with ANSI C is more important, and
1399 // provides an implementation that is compatible with that largest possible set of CPU
1400 // architectures. This is why the type "unsigned int" is used in this one case.
1402 Value
= (unsigned int)Value
;
1406 // Convert Value to a reversed string
1408 Count
= InternalPrintLibValueToString (ValueBuffer
, Value
, Radix
) - ValueBuffer
;
1409 if (Value
== 0 && Precision
== 0) {
1412 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
1416 Digits
= 3 - Digits
;
1418 if (Comma
&& Count
!= 0) {
1419 Count
+= ((Count
- 1) / 3);
1425 Flags
|= ARGUMENT_REVERSED
;
1427 if ((Flags
& PREFIX_ZERO
) != 0) {
1428 if ((Flags
& LEFT_JUSTIFY
) == 0) {
1429 if ((Flags
& PAD_TO_WIDTH
) != 0) {
1430 if ((Flags
& PRECISION
) == 0) {
1440 Flags
|= ARGUMENT_UNICODE
;
1442 // break skipped on purpose
1445 if (BaseListMarker
== NULL
) {
1446 ArgumentString
= VA_ARG (VaListMarker
, CHAR8
*);
1448 ArgumentString
= BASE_ARG (BaseListMarker
, CHAR8
*);
1450 if (ArgumentString
== NULL
) {
1451 Flags
&= (~ARGUMENT_UNICODE
);
1452 ArgumentString
= "<null string>";
1455 // Set the default precision for string to be zero if not specified.
1457 if ((Flags
& PRECISION
) == 0) {
1463 if (BaseListMarker
== NULL
) {
1464 Character
= VA_ARG (VaListMarker
, UINTN
) & 0xffff;
1466 Character
= BASE_ARG (BaseListMarker
, UINTN
) & 0xffff;
1468 ArgumentString
= (CHAR8
*)&Character
;
1469 Flags
|= ARGUMENT_UNICODE
;
1473 if (BaseListMarker
== NULL
) {
1474 TmpGuid
= VA_ARG (VaListMarker
, GUID
*);
1476 TmpGuid
= BASE_ARG (BaseListMarker
, GUID
*);
1478 if (TmpGuid
== NULL
) {
1479 ArgumentString
= "<null guid>";
1481 GuidData1
= ReadUnaligned32 (&(TmpGuid
->Data1
));
1482 GuidData2
= ReadUnaligned16 (&(TmpGuid
->Data2
));
1483 GuidData3
= ReadUnaligned16 (&(TmpGuid
->Data3
));
1484 InternalPrintLibSPrint (
1486 MAXIMUM_VALUE_CHARACTERS
,
1488 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1501 ArgumentString
= ValueBuffer
;
1506 if (BaseListMarker
== NULL
) {
1507 TmpTime
= VA_ARG (VaListMarker
, TIME
*);
1509 TmpTime
= BASE_ARG (BaseListMarker
, TIME
*);
1511 if (TmpTime
== NULL
) {
1512 ArgumentString
= "<null time>";
1514 InternalPrintLibSPrint (
1516 MAXIMUM_VALUE_CHARACTERS
,
1518 "%02d/%02d/%04d %02d:%02d",
1525 ArgumentString
= ValueBuffer
;
1530 if (BaseListMarker
== NULL
) {
1531 Status
= VA_ARG (VaListMarker
, RETURN_STATUS
);
1533 Status
= BASE_ARG (BaseListMarker
, RETURN_STATUS
);
1535 ArgumentString
= ValueBuffer
;
1536 if (RETURN_ERROR (Status
)) {
1540 Index
= Status
& ~MAX_BIT
;
1541 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
1542 ArgumentString
= mStatusString
[Index
+ WARNING_STATUS_NUMBER
];
1546 if (Index
<= WARNING_STATUS_NUMBER
) {
1547 ArgumentString
= mStatusString
[Index
];
1550 if (ArgumentString
== ValueBuffer
) {
1551 InternalPrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
1556 Format
+= BytesPerFormatCharacter
;
1557 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1558 if (FormatCharacter
== '\n') {
1560 // Translate '\r\n' to '\r\n'
1562 ArgumentString
= "\r\n";
1565 // Translate '\r' to '\r'
1567 ArgumentString
= "\r";
1568 Format
-= BytesPerFormatCharacter
;
1574 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1576 ArgumentString
= "\r\n";
1577 Format
+= BytesPerFormatCharacter
;
1578 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1579 if (FormatCharacter
!= '\r') {
1580 Format
-= BytesPerFormatCharacter
;
1587 // if the type is '%' or unknown, then print it to the screen
1589 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1590 Flags
|= ARGUMENT_UNICODE
;
1596 Format
+= BytesPerFormatCharacter
;
1597 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1598 if (FormatCharacter
== '\n') {
1600 // Translate '\r\n' to '\r\n'
1602 ArgumentString
= "\r\n";
1605 // Translate '\r' to '\r'
1607 ArgumentString
= "\r";
1608 Format
-= BytesPerFormatCharacter
;
1614 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1616 ArgumentString
= "\r\n";
1617 Format
+= BytesPerFormatCharacter
;
1618 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1619 if (FormatCharacter
!= '\r') {
1620 Format
-= BytesPerFormatCharacter
;
1625 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1626 Flags
|= ARGUMENT_UNICODE
;
1631 // Retrieve the ArgumentString attriubutes
1633 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
1634 ArgumentMask
= 0xffff;
1635 BytesPerArgumentCharacter
= 2;
1637 ArgumentMask
= 0xff;
1638 BytesPerArgumentCharacter
= 1;
1640 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
1641 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
1644 // Compute the number of characters in ArgumentString and store it in Count
1645 // ArgumentString is either null-terminated, or it contains Precision characters
1647 for (Count
= 0; Count
< Precision
|| ((Flags
& PRECISION
) == 0); Count
++) {
1648 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
1649 if (ArgumentCharacter
== 0) {
1655 if (Precision
< Count
) {
1660 // Pad before the string
1662 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
1663 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1668 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1670 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1672 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1674 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1679 // Output the Prefix character if it is present
1687 // Copy the string into the output buffer performing the required type conversions
1689 while (Index
< Count
) {
1690 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (*(ArgumentString
+ 1) << 8)) & ArgumentMask
;
1692 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1693 ArgumentString
+= BytesPerArgumentCharacter
;
1700 if (Index
< Count
) {
1701 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1708 // Pad after the string
1710 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
1711 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1715 // Get the next character from the format string
1717 Format
+= BytesPerFormatCharacter
;
1720 // Get the next character from the format string
1722 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1725 return (LengthToReturn
/ BytesPerOutputCharacter
);
1729 Returns the number of characters that would be produced by if the formatted
1730 output were produced not including the Null-terminator.
1732 If FormatString is NULL, then ASSERT().
1733 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
1735 @param[in] FormatString A Null-terminated Unicode format string.
1736 @param[in] Marker VA_LIST marker for the variable argument list.
1738 @return The number of characters that would be produced, not including the
1744 IN CONST CHAR16
*FormatString
,
1748 ASSERT(FormatString
!= NULL
);
1749 return InternalPrintLibSPrintMarker (NULL
, 0, FORMAT_UNICODE
| OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);
1753 Returns the number of characters that would be produced by if the formatted
1754 output were produced not including the Null-terminator.
1756 If FormatString is NULL, then ASSERT().
1758 @param[in] FormatString A Null-terminated ASCII format string.
1759 @param[in] Marker VA_LIST marker for the variable argument list.
1761 @return The number of characters that would be produced, not including the
1766 SPrintLengthAsciiFormat (
1767 IN CONST CHAR8
*FormatString
,
1771 ASSERT(FormatString
!= NULL
);
1772 return InternalPrintLibSPrintMarker (NULL
, 0, OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);