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 - 2012, 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 4
1080 #define ERROR_STATUS_NUMBER 24
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 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
1089 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
1090 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
1091 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
1092 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
1093 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
1094 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
1095 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
1096 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
1097 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
1098 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
1099 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
1100 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
1101 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
1102 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
1103 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
1104 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
1105 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
1106 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
1107 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
1108 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
1109 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
1110 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
1111 "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
1115 Worker function that produces a Null-terminated string in an output buffer
1116 based on a Null-terminated format string and a VA_LIST argument list.
1118 VSPrint function to process format and place the results in Buffer. Since a
1119 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1120 this is the main print working routine.
1122 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1124 @param[out] Buffer The character buffer to print the results of the
1125 parsing of Format into.
1126 @param[in] BufferSize The maximum number of characters to put into
1128 @param[in] Flags Initial flags value.
1129 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1130 and COUNT_ONLY_NO_PRINT set.
1131 @param[in] Format A Null-terminated format string.
1132 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1134 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1135 by processing Format.
1137 @return The number of characters printed not including the Null-terminator.
1138 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1139 modification to Buffer.
1143 InternalPrintLibSPrintMarker (
1145 IN UINTN BufferSize
,
1147 IN CONST CHAR8
*Format
,
1148 IN VA_LIST VaListMarker
, OPTIONAL
1149 IN BASE_LIST BaseListMarker OPTIONAL
1153 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
1154 UINT32 BytesPerOutputCharacter
;
1155 UINTN BytesPerFormatCharacter
;
1157 UINTN FormatCharacter
;
1161 CONST CHAR8
*ArgumentString
;
1167 INTN BytesPerArgumentCharacter
;
1168 UINTN ArgumentCharacter
;
1176 RETURN_STATUS Status
;
1180 UINTN LengthToReturn
;
1183 // If you change this code be sure to match the 2 versions of this function.
1184 // Nearly identical logic is found in the BasePrintLib and
1185 // DxePrintLibPrint2Protocol (both PrintLib instances).
1188 ASSERT(Flags
& COUNT_ONLY_NO_PRINT
);
1190 if ((Flags
& OUTPUT_UNICODE
) != 0) {
1191 BytesPerOutputCharacter
= 2;
1193 BytesPerOutputCharacter
= 1;
1199 // Reserve space for the Null terminator.
1204 // Set the tag for the end of the input Buffer.
1206 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
1208 if ((Flags
& FORMAT_UNICODE
) != 0) {
1210 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
1211 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1213 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
1214 BytesPerFormatCharacter
= 2;
1215 FormatMask
= 0xffff;
1218 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
1219 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
1221 ASSERT (AsciiStrSize (Format
) != 0);
1222 BytesPerFormatCharacter
= 1;
1227 // Get the first character from the format string
1229 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1232 // Loop until the end of the format string is reached or the output buffer is full
1234 while (FormatCharacter
!= 0 && Buffer
< EndBuffer
) {
1236 // Clear all the flag bits except those that may have been passed in
1238 Flags
&= (OUTPUT_UNICODE
| FORMAT_UNICODE
| COUNT_ONLY_NO_PRINT
);
1241 // Set the default width to zero, and the default precision to 1
1251 switch (FormatCharacter
) {
1254 // Parse Flags and Width
1256 for (Done
= FALSE
; !Done
; ) {
1257 Format
+= BytesPerFormatCharacter
;
1258 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1259 switch (FormatCharacter
) {
1264 Flags
|= LEFT_JUSTIFY
;
1267 Flags
|= PREFIX_SIGN
;
1270 Flags
|= PREFIX_BLANK
;
1273 Flags
|= COMMA_TYPE
;
1280 if ((Flags
& PRECISION
) == 0) {
1281 Flags
|= PAD_TO_WIDTH
;
1282 if (BaseListMarker
== NULL
) {
1283 Width
= VA_ARG (VaListMarker
, UINTN
);
1285 Width
= BASE_ARG (BaseListMarker
, UINTN
);
1288 if (BaseListMarker
== NULL
) {
1289 Precision
= VA_ARG (VaListMarker
, UINTN
);
1291 Precision
= BASE_ARG (BaseListMarker
, UINTN
);
1296 if ((Flags
& PRECISION
) == 0) {
1297 Flags
|= PREFIX_ZERO
;
1308 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
1309 Count
= (Count
* 10) + FormatCharacter
- '0';
1310 Format
+= BytesPerFormatCharacter
;
1311 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1313 Format
-= BytesPerFormatCharacter
;
1314 if ((Flags
& PRECISION
) == 0) {
1315 Flags
|= PAD_TO_WIDTH
;
1324 // Make no output if Format string terminates unexpectedly when
1325 // looking up for flag, width, precision and type.
1327 Format
-= BytesPerFormatCharacter
;
1330 // break skipped on purpose.
1339 // Handle each argument type
1341 switch (FormatCharacter
) {
1344 // Flag space, +, 0, L & l are invalid for type p.
1346 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
);
1347 if (sizeof (VOID
*) > 4) {
1351 Flags
|= PREFIX_ZERO
;
1353 // break skipped on purpose
1358 // break skipped on purpose
1361 if ((Flags
& LONG_TYPE
) == 0) {
1363 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1364 // This assumption is made so the format string definition is compatible with the ANSI C
1365 // Specification for formatted strings. It is recommended that the Base Types be used
1366 // everywhere, but in this one case, compliance with ANSI C is more important, and
1367 // provides an implementation that is compatible with that largest possible set of CPU
1368 // architectures. This is why the type "int" is used in this one case.
1370 if (BaseListMarker
== NULL
) {
1371 Value
= VA_ARG (VaListMarker
, int);
1373 Value
= BASE_ARG (BaseListMarker
, int);
1376 if (BaseListMarker
== NULL
) {
1377 Value
= VA_ARG (VaListMarker
, INT64
);
1379 Value
= BASE_ARG (BaseListMarker
, INT64
);
1382 if ((Flags
& PREFIX_BLANK
) != 0) {
1385 if ((Flags
& PREFIX_SIGN
) != 0) {
1388 if ((Flags
& COMMA_TYPE
) != 0) {
1391 if ((Flags
& RADIX_HEX
) == 0) {
1394 Flags
&= (~PREFIX_ZERO
);
1398 Flags
|= PREFIX_SIGN
;
1405 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
1407 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1408 // This assumption is made so the format string definition is compatible with the ANSI C
1409 // Specification for formatted strings. It is recommended that the Base Types be used
1410 // everywhere, but in this one case, compliance with ANSI C is more important, and
1411 // provides an implementation that is compatible with that largest possible set of CPU
1412 // architectures. This is why the type "unsigned int" is used in this one case.
1414 Value
= (unsigned int)Value
;
1418 // Convert Value to a reversed string
1420 Count
= InternalPrintLibValueToString (ValueBuffer
, Value
, Radix
) - ValueBuffer
;
1421 if (Value
== 0 && Precision
== 0) {
1424 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
1428 Digits
= 3 - Digits
;
1430 if (Comma
&& Count
!= 0) {
1431 Count
+= ((Count
- 1) / 3);
1437 Flags
|= ARGUMENT_REVERSED
;
1439 if ((Flags
& PREFIX_ZERO
) != 0) {
1440 if ((Flags
& LEFT_JUSTIFY
) == 0) {
1441 if ((Flags
& PAD_TO_WIDTH
) != 0) {
1442 if ((Flags
& PRECISION
) == 0) {
1452 Flags
|= ARGUMENT_UNICODE
;
1454 // break skipped on purpose
1457 if (BaseListMarker
== NULL
) {
1458 ArgumentString
= VA_ARG (VaListMarker
, CHAR8
*);
1460 ArgumentString
= BASE_ARG (BaseListMarker
, CHAR8
*);
1462 if (ArgumentString
== NULL
) {
1463 Flags
&= (~ARGUMENT_UNICODE
);
1464 ArgumentString
= "<null string>";
1467 // Set the default precision for string to be zero if not specified.
1469 if ((Flags
& PRECISION
) == 0) {
1475 if (BaseListMarker
== NULL
) {
1476 Character
= VA_ARG (VaListMarker
, UINTN
) & 0xffff;
1478 Character
= BASE_ARG (BaseListMarker
, UINTN
) & 0xffff;
1480 ArgumentString
= (CHAR8
*)&Character
;
1481 Flags
|= ARGUMENT_UNICODE
;
1485 if (BaseListMarker
== NULL
) {
1486 TmpGuid
= VA_ARG (VaListMarker
, GUID
*);
1488 TmpGuid
= BASE_ARG (BaseListMarker
, GUID
*);
1490 if (TmpGuid
== NULL
) {
1491 ArgumentString
= "<null guid>";
1493 GuidData1
= ReadUnaligned32 (&(TmpGuid
->Data1
));
1494 GuidData2
= ReadUnaligned16 (&(TmpGuid
->Data2
));
1495 GuidData3
= ReadUnaligned16 (&(TmpGuid
->Data3
));
1496 InternalPrintLibSPrint (
1498 MAXIMUM_VALUE_CHARACTERS
,
1500 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1513 ArgumentString
= ValueBuffer
;
1518 if (BaseListMarker
== NULL
) {
1519 TmpTime
= VA_ARG (VaListMarker
, TIME
*);
1521 TmpTime
= BASE_ARG (BaseListMarker
, TIME
*);
1523 if (TmpTime
== NULL
) {
1524 ArgumentString
= "<null time>";
1526 InternalPrintLibSPrint (
1528 MAXIMUM_VALUE_CHARACTERS
,
1530 "%02d/%02d/%04d %02d:%02d",
1537 ArgumentString
= ValueBuffer
;
1542 if (BaseListMarker
== NULL
) {
1543 Status
= VA_ARG (VaListMarker
, RETURN_STATUS
);
1545 Status
= BASE_ARG (BaseListMarker
, RETURN_STATUS
);
1547 ArgumentString
= ValueBuffer
;
1548 if (RETURN_ERROR (Status
)) {
1552 Index
= Status
& ~MAX_BIT
;
1553 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
1554 ArgumentString
= mStatusString
[Index
+ WARNING_STATUS_NUMBER
];
1558 if (Index
<= WARNING_STATUS_NUMBER
) {
1559 ArgumentString
= mStatusString
[Index
];
1562 if (ArgumentString
== ValueBuffer
) {
1563 InternalPrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
1568 Format
+= BytesPerFormatCharacter
;
1569 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1570 if (FormatCharacter
== '\n') {
1572 // Translate '\r\n' to '\r\n'
1574 ArgumentString
= "\r\n";
1577 // Translate '\r' to '\r'
1579 ArgumentString
= "\r";
1580 Format
-= BytesPerFormatCharacter
;
1586 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1588 ArgumentString
= "\r\n";
1589 Format
+= BytesPerFormatCharacter
;
1590 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1591 if (FormatCharacter
!= '\r') {
1592 Format
-= BytesPerFormatCharacter
;
1599 // if the type is '%' or unknown, then print it to the screen
1601 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1602 Flags
|= ARGUMENT_UNICODE
;
1608 Format
+= BytesPerFormatCharacter
;
1609 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1610 if (FormatCharacter
== '\n') {
1612 // Translate '\r\n' to '\r\n'
1614 ArgumentString
= "\r\n";
1617 // Translate '\r' to '\r'
1619 ArgumentString
= "\r";
1620 Format
-= BytesPerFormatCharacter
;
1626 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1628 ArgumentString
= "\r\n";
1629 Format
+= BytesPerFormatCharacter
;
1630 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1631 if (FormatCharacter
!= '\r') {
1632 Format
-= BytesPerFormatCharacter
;
1637 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1638 Flags
|= ARGUMENT_UNICODE
;
1643 // Retrieve the ArgumentString attriubutes
1645 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
1646 ArgumentMask
= 0xffff;
1647 BytesPerArgumentCharacter
= 2;
1649 ArgumentMask
= 0xff;
1650 BytesPerArgumentCharacter
= 1;
1652 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
1653 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
1656 // Compute the number of characters in ArgumentString and store it in Count
1657 // ArgumentString is either null-terminated, or it contains Precision characters
1659 for (Count
= 0; Count
< Precision
|| ((Flags
& PRECISION
) == 0); Count
++) {
1660 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
1661 if (ArgumentCharacter
== 0) {
1667 if (Precision
< Count
) {
1672 // Pad before the string
1674 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
1675 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1680 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1682 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1684 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1686 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1691 // Output the Prefix character if it is present
1699 // Copy the string into the output buffer performing the required type conversions
1701 while (Index
< Count
) {
1702 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (*(ArgumentString
+ 1) << 8)) & ArgumentMask
;
1704 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1705 ArgumentString
+= BytesPerArgumentCharacter
;
1712 if (Index
< Count
) {
1713 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1720 // Pad after the string
1722 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
1723 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1727 // Get the next character from the format string
1729 Format
+= BytesPerFormatCharacter
;
1732 // Get the next character from the format string
1734 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1737 return (LengthToReturn
/ BytesPerOutputCharacter
);
1741 Returns the number of characters that would be produced by if the formatted
1742 output were produced not including the Null-terminator.
1744 If FormatString is NULL, then ASSERT().
1745 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
1747 @param[in] FormatString A Null-terminated Unicode format string.
1748 @param[in] Marker VA_LIST marker for the variable argument list.
1750 @return The number of characters that would be produced, not including the
1756 IN CONST CHAR16
*FormatString
,
1760 ASSERT(FormatString
!= NULL
);
1761 return InternalPrintLibSPrintMarker (NULL
, 0, FORMAT_UNICODE
| OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);
1765 Returns the number of characters that would be produced by if the formatted
1766 output were produced not including the Null-terminator.
1768 If FormatString is NULL, then ASSERT().
1770 @param[in] FormatString A Null-terminated ASCII format string.
1771 @param[in] Marker VA_LIST marker for the variable argument list.
1773 @return The number of characters that would be produced, not including the
1778 SPrintLengthAsciiFormat (
1779 IN CONST CHAR8
*FormatString
,
1783 ASSERT(FormatString
!= NULL
);
1784 return InternalPrintLibSPrintMarker (NULL
, 0, OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);