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/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
,
370 VA_START (Marker
, FormatString
);
371 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
375 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
376 ASCII format string and a VA_LIST argument list
378 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
380 The Unicode string is produced by parsing the format string specified by FormatString.
381 Arguments are pulled from the variable argument list specified by Marker based on the
382 contents of the format string.
383 The number of Unicode characters in the produced output buffer is returned not including
385 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
387 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
388 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
389 If BufferSize > 1 and FormatString is NULL, then ASSERT().
390 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
391 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
393 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
394 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
395 Null-terminator, then ASSERT().
397 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
399 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
400 @param FormatString Null-terminated Unicode format string.
401 @param Marker VA_LIST marker for the variable argument list.
403 @return The number of Unicode characters in the produced output buffer not including the
409 UnicodeVSPrintAsciiFormat (
410 OUT CHAR16
*StartOfBuffer
,
412 IN CONST CHAR8
*FormatString
,
416 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
418 DxePrintLibPrint2ProtocolVaListToBaseList (
422 (BASE_LIST
)BaseListMarker
,
423 sizeof (BaseListMarker
) - 8
426 return UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
430 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
431 ASCII format string and a BASE_LIST argument list
433 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
435 The Unicode string is produced by parsing the format string specified by FormatString.
436 Arguments are pulled from the variable argument list specified by Marker based on the
437 contents of the format string.
438 The number of Unicode characters in the produced output buffer is returned not including
440 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
442 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
443 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
444 If BufferSize > 1 and FormatString is NULL, then ASSERT().
445 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
446 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
448 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
449 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
450 Null-terminator, then ASSERT().
452 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
454 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
455 @param FormatString Null-terminated Unicode format string.
456 @param Marker BASE_LIST marker for the variable argument list.
458 @return The number of Unicode characters in the produced output buffer not including the
464 UnicodeBSPrintAsciiFormat (
465 OUT CHAR16
*StartOfBuffer
,
467 IN CONST CHAR8
*FormatString
,
471 return mPrint2Protocol
->UnicodeBSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
475 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
476 ASCII format string and variable argument list.
478 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
480 The Unicode string is produced by parsing the format string specified by FormatString.
481 Arguments are pulled from the variable argument list based on the contents of the
483 The number of Unicode characters in the produced output buffer is returned not including
485 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
487 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
488 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
489 If BufferSize > 1 and FormatString is NULL, then ASSERT().
490 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
491 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
493 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
494 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
495 Null-terminator, then ASSERT().
497 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
499 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
500 @param FormatString Null-terminated Unicode format string.
501 @param ... Variable argument list whose contents are accessed based on the
502 format string specified by FormatString.
504 @return The number of Unicode characters in the produced output buffer not including the
510 UnicodeSPrintAsciiFormat (
511 OUT CHAR16
*StartOfBuffer
,
513 IN CONST CHAR8
*FormatString
,
519 VA_START (Marker
, FormatString
);
520 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
524 Converts a decimal value to a Null-terminated Unicode string.
526 Converts the decimal number specified by Value to a Null-terminated Unicode
527 string specified by Buffer containing at most Width characters. No padding of spaces
528 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
529 The number of Unicode characters in Buffer is returned not including the Null-terminator.
530 If the conversion contains more than Width characters, then only the first
531 Width characters are returned, and the total number of characters
532 required to perform the conversion is returned.
533 Additional conversion parameters are specified in Flags.
535 The Flags bit LEFT_JUSTIFY is always ignored.
536 All conversions are left justified in Buffer.
537 If Width is 0, PREFIX_ZERO is ignored in Flags.
538 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
539 are inserted every 3rd digit starting from the right.
540 If RADIX_HEX is set in Flags, then the output buffer will be
541 formatted in hexadecimal format.
542 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
543 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
544 then Buffer is padded with '0' characters so the combination of the optional '-'
545 sign character, '0' characters, digit characters for Value, and the Null-terminator
546 add up to Width characters.
547 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
548 If Buffer is NULL, then ASSERT().
549 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
550 If unsupported bits are set in Flags, then ASSERT().
551 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
552 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
554 @param Buffer Pointer to the output buffer for the produced Null-terminated
556 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
557 @param Value The 64-bit signed value to convert to a string.
558 @param Width The maximum number of Unicode characters to place in Buffer, not including
561 @return The number of Unicode characters in Buffer not including the Null-terminator.
566 UnicodeValueToString (
567 IN OUT CHAR16
*Buffer
,
573 return mPrint2Protocol
->UnicodeValueToString (Buffer
, Flags
, Value
, Width
);
577 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
578 ASCII format string and a VA_LIST argument list.
580 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
582 The ASCII string is produced by parsing the format string specified by FormatString.
583 Arguments are pulled from the variable argument list specified by Marker based on
584 the contents of the format string.
585 The number of ASCII characters in the produced output buffer is returned not including
587 If BufferSize is 0, then no output buffer is produced and 0 is returned.
589 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
590 If BufferSize > 0 and FormatString is NULL, then ASSERT().
591 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
592 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
594 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
595 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
596 Null-terminator, then ASSERT().
598 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
600 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
601 @param FormatString Null-terminated Unicode format string.
602 @param Marker VA_LIST marker for the variable argument list.
604 @return The number of ASCII characters in the produced output buffer not including the
611 OUT CHAR8
*StartOfBuffer
,
613 IN CONST CHAR8
*FormatString
,
617 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
619 DxePrintLibPrint2ProtocolVaListToBaseList (
623 (BASE_LIST
)BaseListMarker
,
624 sizeof (BaseListMarker
) - 8
627 return AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
631 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
632 ASCII format string and a BASE_LIST argument list.
634 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
636 The ASCII string is produced by parsing the format string specified by FormatString.
637 Arguments are pulled from the variable argument list specified by Marker based on
638 the contents of the format string.
639 The number of ASCII characters in the produced output buffer is returned not including
641 If BufferSize is 0, then no output buffer is produced and 0 is returned.
643 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
644 If BufferSize > 0 and FormatString is NULL, then ASSERT().
645 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
646 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
648 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
649 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
650 Null-terminator, then ASSERT().
652 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
654 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
655 @param FormatString Null-terminated Unicode format string.
656 @param Marker BASE_LIST marker for the variable argument list.
658 @return The number of ASCII characters in the produced output buffer not including the
665 OUT CHAR8
*StartOfBuffer
,
667 IN CONST CHAR8
*FormatString
,
671 return mPrint2Protocol
->AsciiBSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
675 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
676 ASCII format string and variable argument list.
678 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
680 The ASCII string is produced by parsing the format string specified by FormatString.
681 Arguments are pulled from the variable argument list based on the contents of the
683 The number of ASCII characters in the produced output buffer is returned not including
685 If BufferSize is 0, then no output buffer is produced and 0 is returned.
687 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
688 If BufferSize > 0 and FormatString is NULL, then ASSERT().
689 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
690 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
692 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
693 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
694 Null-terminator, then ASSERT().
696 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
698 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
699 @param FormatString Null-terminated Unicode format string.
700 @param ... Variable argument list whose contents are accessed based on the
701 format string specified by FormatString.
703 @return The number of ASCII characters in the produced output buffer not including the
710 OUT CHAR8
*StartOfBuffer
,
712 IN CONST CHAR8
*FormatString
,
718 VA_START (Marker
, FormatString
);
719 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
723 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
724 ASCII format string and a VA_LIST argument list.
726 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
728 The ASCII string is produced by parsing the format string specified by FormatString.
729 Arguments are pulled from the variable argument list specified by Marker based on
730 the contents of the format string.
731 The number of ASCII characters in the produced output buffer is returned not including
733 If BufferSize is 0, then no output buffer is produced and 0 is returned.
735 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
736 If BufferSize > 0 and FormatString is NULL, then ASSERT().
737 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
738 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
739 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
741 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
742 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
743 Null-terminator, then ASSERT().
745 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
747 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
748 @param FormatString Null-terminated Unicode format string.
749 @param Marker VA_LIST marker for the variable argument list.
751 @return The number of ASCII characters in the produced output buffer not including the
757 AsciiVSPrintUnicodeFormat (
758 OUT CHAR8
*StartOfBuffer
,
760 IN CONST CHAR16
*FormatString
,
764 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
766 DxePrintLibPrint2ProtocolVaListToBaseList (
768 (CHAR8
*)FormatString
,
770 (BASE_LIST
)BaseListMarker
,
771 sizeof (BaseListMarker
) - 8
774 return AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, (BASE_LIST
)BaseListMarker
);
778 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
779 ASCII format string and a BASE_LIST argument list.
781 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
783 The ASCII string is produced by parsing the format string specified by FormatString.
784 Arguments are pulled from the variable argument list specified by Marker based on
785 the contents of the format string.
786 The number of ASCII characters in the produced output buffer is returned not including
788 If BufferSize is 0, then no output buffer is produced and 0 is returned.
790 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
791 If BufferSize > 0 and FormatString is NULL, then ASSERT().
792 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
793 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
794 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
796 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
797 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
798 Null-terminator, then ASSERT().
800 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
802 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
803 @param FormatString Null-terminated Unicode format string.
804 @param Marker BASE_LIST marker for the variable argument list.
806 @return The number of ASCII characters in the produced output buffer not including the
812 AsciiBSPrintUnicodeFormat (
813 OUT CHAR8
*StartOfBuffer
,
815 IN CONST CHAR16
*FormatString
,
819 return mPrint2Protocol
->AsciiBSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
823 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
824 ASCII format string and variable argument list.
826 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
828 The ASCII string is produced by parsing the format string specified by FormatString.
829 Arguments are pulled from the variable argument list based on the contents of the
831 The number of ASCII characters in the produced output buffer is returned not including
833 If BufferSize is 0, then no output buffer is produced and 0 is returned.
835 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
836 If BufferSize > 0 and FormatString is NULL, then ASSERT().
837 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
838 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
839 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
841 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
842 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
843 Null-terminator, then ASSERT().
845 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
847 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
848 @param FormatString Null-terminated Unicode format string.
849 @param ... Variable argument list whose contents are accessed based on the
850 format string specified by FormatString.
852 @return The number of ASCII characters in the produced output buffer not including the
858 AsciiSPrintUnicodeFormat (
859 OUT CHAR8
*StartOfBuffer
,
861 IN CONST CHAR16
*FormatString
,
867 VA_START (Marker
, FormatString
);
868 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
873 Converts a decimal value to a Null-terminated ASCII string.
875 Converts the decimal number specified by Value to a Null-terminated ASCII string
876 specified by Buffer containing at most Width characters. No padding of spaces
878 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
879 The number of ASCII characters in Buffer is returned not including the Null-terminator.
880 If the conversion contains more than Width characters, then only the first Width
881 characters are returned, and the total number of characters required to perform
882 the conversion is returned.
883 Additional conversion parameters are specified in Flags.
884 The Flags bit LEFT_JUSTIFY is always ignored.
885 All conversions are left justified in Buffer.
886 If Width is 0, PREFIX_ZERO is ignored in Flags.
887 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
888 are inserted every 3rd digit starting from the right.
889 If RADIX_HEX is set in Flags, then the output buffer will be
890 formatted in hexadecimal format.
891 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
892 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
893 then Buffer is padded with '0' characters so the combination of the optional '-'
894 sign character, '0' characters, digit characters for Value, and the Null-terminator
895 add up to Width characters.
897 If Buffer is NULL, then ASSERT().
898 If unsupported bits are set in Flags, then ASSERT().
899 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
900 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
902 @param Buffer Pointer to the output buffer for the produced Null-terminated
904 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
905 @param Value The 64-bit signed value to convert to a string.
906 @param Width The maximum number of ASCII characters to place in Buffer, not including
909 @return The number of ASCII characters in Buffer not including the Null-terminator.
921 return mPrint2Protocol
->AsciiValueToString (Buffer
, Flags
, Value
, Width
);
924 #define PREFIX_SIGN BIT1
925 #define PREFIX_BLANK BIT2
926 #define LONG_TYPE BIT4
927 #define OUTPUT_UNICODE BIT6
928 #define FORMAT_UNICODE BIT8
929 #define PAD_TO_WIDTH BIT9
930 #define ARGUMENT_UNICODE BIT10
931 #define PRECISION BIT11
932 #define ARGUMENT_REVERSED BIT12
933 #define COUNT_ONLY_NO_PRINT BIT13
936 // Record date and time information
952 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
955 Internal function that convert a number to a string in Buffer.
957 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.
959 @param Buffer Location to place the ASCII string of Value.
960 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.
961 @param Radix Radix of the value
963 @return A pointer to the end of buffer filled with ASCII string.
967 InternalPrintLibValueToString (
968 IN OUT CHAR8
*Buffer
,
976 // Loop to convert one digit at a time in reverse order
980 Value
= (INT64
)DivU64x32Remainder ((UINT64
)Value
, (UINT32
)Radix
, &Remainder
);
981 *(++Buffer
) = mHexStr
[Remainder
];
982 } while (Value
!= 0);
985 // Return pointer of the end of filled buffer.
991 Worker function that produces a Null-terminated string in an output buffer
992 based on a Null-terminated format string and a VA_LIST argument list.
994 VSPrint function to process format and place the results in Buffer. Since a
995 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
996 this is the main print working routine.
998 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1000 @param[out] Buffer The character buffer to print the results of the
1001 parsing of Format into.
1002 @param[in] BufferSize The maximum number of characters to put into
1004 @param[in] Flags Initial flags value.
1005 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1006 and COUNT_ONLY_NO_PRINT set.
1007 @param[in] Format A Null-terminated format string.
1008 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1010 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1011 by processing Format.
1013 @return The number of characters printed not including the Null-terminator.
1014 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1015 modification to Buffer.
1019 InternalPrintLibSPrintMarker (
1021 IN UINTN BufferSize
,
1023 IN CONST CHAR8
*Format
,
1024 IN VA_LIST VaListMarker
, OPTIONAL
1025 IN BASE_LIST BaseListMarker OPTIONAL
1029 Worker function that produces a Null-terminated string in an output buffer
1030 based on a Null-terminated format string and variable argument list.
1032 VSPrint function to process format and place the results in Buffer. Since a
1033 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1034 this is the main print working routine
1036 @param StartOfBuffer The character buffer to print the results of the parsing
1038 @param BufferSize The maximum number of characters to put into buffer.
1039 Zero means no limit.
1040 @param Flags Initial flags value.
1041 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
1042 @param FormatString A Null-terminated format string.
1043 @param ... The variable argument list.
1045 @return The number of characters printed.
1050 InternalPrintLibSPrint (
1051 OUT CHAR8
*StartOfBuffer
,
1052 IN UINTN BufferSize
,
1054 IN CONST CHAR8
*FormatString
,
1060 VA_START (Marker
, FormatString
);
1061 return InternalPrintLibSPrintMarker (StartOfBuffer
, BufferSize
, Flags
, FormatString
, Marker
, NULL
);
1064 #define WARNING_STATUS_NUMBER 4
1065 #define ERROR_STATUS_NUMBER 24
1067 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8
*mStatusString
[] = {
1068 "Success", // RETURN_SUCCESS = 0
1069 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
1070 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
1071 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
1072 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
1073 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
1074 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
1075 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
1076 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
1077 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
1078 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
1079 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
1080 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
1081 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
1082 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
1083 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
1084 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
1085 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
1086 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
1087 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
1088 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
1089 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
1090 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
1091 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
1092 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
1093 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
1094 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
1095 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
1096 "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
1100 Worker function that produces a Null-terminated string in an output buffer
1101 based on a Null-terminated format string and a VA_LIST argument list.
1103 VSPrint function to process format and place the results in Buffer. Since a
1104 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1105 this is the main print working routine.
1107 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1109 @param[out] Buffer The character buffer to print the results of the
1110 parsing of Format into.
1111 @param[in] BufferSize The maximum number of characters to put into
1113 @param[in] Flags Initial flags value.
1114 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1115 and COUNT_ONLY_NO_PRINT set.
1116 @param[in] Format A Null-terminated format string.
1117 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1119 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1120 by processing Format.
1122 @return The number of characters printed not including the Null-terminator.
1123 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1124 modification to Buffer.
1128 InternalPrintLibSPrintMarker (
1130 IN UINTN BufferSize
,
1132 IN CONST CHAR8
*Format
,
1133 IN VA_LIST VaListMarker
, OPTIONAL
1134 IN BASE_LIST BaseListMarker OPTIONAL
1138 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
1139 UINT32 BytesPerOutputCharacter
;
1140 UINTN BytesPerFormatCharacter
;
1142 UINTN FormatCharacter
;
1146 CONST CHAR8
*ArgumentString
;
1152 INTN BytesPerArgumentCharacter
;
1153 UINTN ArgumentCharacter
;
1161 RETURN_STATUS Status
;
1165 UINTN LengthToReturn
;
1168 // If you change this code be sure to match the 2 versions of this function.
1169 // Nearly identical logic is found in the BasePrintLib and
1170 // DxePrintLibPrint2Protocol (both PrintLib instances).
1173 ASSERT(Flags
& COUNT_ONLY_NO_PRINT
);
1175 if ((Flags
& OUTPUT_UNICODE
) != 0) {
1176 BytesPerOutputCharacter
= 2;
1178 BytesPerOutputCharacter
= 1;
1184 // Reserve space for the Null terminator.
1189 // Set the tag for the end of the input Buffer.
1191 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
1193 if ((Flags
& FORMAT_UNICODE
) != 0) {
1195 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
1196 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1198 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
1199 BytesPerFormatCharacter
= 2;
1200 FormatMask
= 0xffff;
1203 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
1204 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
1206 ASSERT (AsciiStrSize (Format
) != 0);
1207 BytesPerFormatCharacter
= 1;
1212 // Get the first character from the format string
1214 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1217 // Loop until the end of the format string is reached or the output buffer is full
1219 while (FormatCharacter
!= 0 && Buffer
< EndBuffer
) {
1221 // Clear all the flag bits except those that may have been passed in
1223 Flags
&= (OUTPUT_UNICODE
| FORMAT_UNICODE
| COUNT_ONLY_NO_PRINT
);
1226 // Set the default width to zero, and the default precision to 1
1236 switch (FormatCharacter
) {
1239 // Parse Flags and Width
1241 for (Done
= FALSE
; !Done
; ) {
1242 Format
+= BytesPerFormatCharacter
;
1243 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1244 switch (FormatCharacter
) {
1249 Flags
|= LEFT_JUSTIFY
;
1252 Flags
|= PREFIX_SIGN
;
1255 Flags
|= PREFIX_BLANK
;
1258 Flags
|= COMMA_TYPE
;
1265 if ((Flags
& PRECISION
) == 0) {
1266 Flags
|= PAD_TO_WIDTH
;
1267 if (BaseListMarker
== NULL
) {
1268 Width
= VA_ARG (VaListMarker
, UINTN
);
1270 Width
= BASE_ARG (BaseListMarker
, UINTN
);
1273 if (BaseListMarker
== NULL
) {
1274 Precision
= VA_ARG (VaListMarker
, UINTN
);
1276 Precision
= BASE_ARG (BaseListMarker
, UINTN
);
1281 if ((Flags
& PRECISION
) == 0) {
1282 Flags
|= PREFIX_ZERO
;
1293 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
1294 Count
= (Count
* 10) + FormatCharacter
- '0';
1295 Format
+= BytesPerFormatCharacter
;
1296 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1298 Format
-= BytesPerFormatCharacter
;
1299 if ((Flags
& PRECISION
) == 0) {
1300 Flags
|= PAD_TO_WIDTH
;
1309 // Make no output if Format string terminates unexpectedly when
1310 // looking up for flag, width, precision and type.
1312 Format
-= BytesPerFormatCharacter
;
1315 // break skipped on purpose.
1324 // Handle each argument type
1326 switch (FormatCharacter
) {
1329 // Flag space, +, 0, L & l are invalid for type p.
1331 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
);
1332 if (sizeof (VOID
*) > 4) {
1336 Flags
|= PREFIX_ZERO
;
1338 // break skipped on purpose
1343 // break skipped on purpose
1346 if ((Flags
& LONG_TYPE
) == 0) {
1348 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1349 // This assumption is made so the format string definition is compatible with the ANSI C
1350 // Specification for formatted strings. It is recommended that the Base Types be used
1351 // everywhere, but in this one case, compliance with ANSI C is more important, and
1352 // provides an implementation that is compatible with that largest possible set of CPU
1353 // architectures. This is why the type "int" is used in this one case.
1355 if (BaseListMarker
== NULL
) {
1356 Value
= VA_ARG (VaListMarker
, int);
1358 Value
= BASE_ARG (BaseListMarker
, int);
1361 if (BaseListMarker
== NULL
) {
1362 Value
= VA_ARG (VaListMarker
, INT64
);
1364 Value
= BASE_ARG (BaseListMarker
, INT64
);
1367 if ((Flags
& PREFIX_BLANK
) != 0) {
1370 if ((Flags
& PREFIX_SIGN
) != 0) {
1373 if ((Flags
& COMMA_TYPE
) != 0) {
1376 if ((Flags
& RADIX_HEX
) == 0) {
1379 Flags
&= (~PREFIX_ZERO
);
1383 Flags
|= PREFIX_SIGN
;
1390 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
1392 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1393 // This assumption is made so the format string definition is compatible with the ANSI C
1394 // Specification for formatted strings. It is recommended that the Base Types be used
1395 // everywhere, but in this one case, compliance with ANSI C is more important, and
1396 // provides an implementation that is compatible with that largest possible set of CPU
1397 // architectures. This is why the type "unsigned int" is used in this one case.
1399 Value
= (unsigned int)Value
;
1403 // Convert Value to a reversed string
1405 Count
= InternalPrintLibValueToString (ValueBuffer
, Value
, Radix
) - ValueBuffer
;
1406 if (Value
== 0 && Precision
== 0) {
1409 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
1413 Digits
= 3 - Digits
;
1415 if (Comma
&& Count
!= 0) {
1416 Count
+= ((Count
- 1) / 3);
1422 Flags
|= ARGUMENT_REVERSED
;
1424 if ((Flags
& PREFIX_ZERO
) != 0) {
1425 if ((Flags
& LEFT_JUSTIFY
) == 0) {
1426 if ((Flags
& PAD_TO_WIDTH
) != 0) {
1427 if ((Flags
& PRECISION
) == 0) {
1437 Flags
|= ARGUMENT_UNICODE
;
1439 // break skipped on purpose
1442 if (BaseListMarker
== NULL
) {
1443 ArgumentString
= VA_ARG (VaListMarker
, CHAR8
*);
1445 ArgumentString
= BASE_ARG (BaseListMarker
, CHAR8
*);
1447 if (ArgumentString
== NULL
) {
1448 Flags
&= (~ARGUMENT_UNICODE
);
1449 ArgumentString
= "<null string>";
1452 // Set the default precision for string to be zero if not specified.
1454 if ((Flags
& PRECISION
) == 0) {
1460 if (BaseListMarker
== NULL
) {
1461 Character
= VA_ARG (VaListMarker
, UINTN
) & 0xffff;
1463 Character
= BASE_ARG (BaseListMarker
, UINTN
) & 0xffff;
1465 ArgumentString
= (CHAR8
*)&Character
;
1466 Flags
|= ARGUMENT_UNICODE
;
1470 if (BaseListMarker
== NULL
) {
1471 TmpGuid
= VA_ARG (VaListMarker
, GUID
*);
1473 TmpGuid
= BASE_ARG (BaseListMarker
, GUID
*);
1475 if (TmpGuid
== NULL
) {
1476 ArgumentString
= "<null guid>";
1478 GuidData1
= ReadUnaligned32 (&(TmpGuid
->Data1
));
1479 GuidData2
= ReadUnaligned16 (&(TmpGuid
->Data2
));
1480 GuidData3
= ReadUnaligned16 (&(TmpGuid
->Data3
));
1481 InternalPrintLibSPrint (
1483 MAXIMUM_VALUE_CHARACTERS
,
1485 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1498 ArgumentString
= ValueBuffer
;
1503 if (BaseListMarker
== NULL
) {
1504 TmpTime
= VA_ARG (VaListMarker
, TIME
*);
1506 TmpTime
= BASE_ARG (BaseListMarker
, TIME
*);
1508 if (TmpTime
== NULL
) {
1509 ArgumentString
= "<null time>";
1511 InternalPrintLibSPrint (
1513 MAXIMUM_VALUE_CHARACTERS
,
1515 "%02d/%02d/%04d %02d:%02d",
1522 ArgumentString
= ValueBuffer
;
1527 if (BaseListMarker
== NULL
) {
1528 Status
= VA_ARG (VaListMarker
, RETURN_STATUS
);
1530 Status
= BASE_ARG (BaseListMarker
, RETURN_STATUS
);
1532 ArgumentString
= ValueBuffer
;
1533 if (RETURN_ERROR (Status
)) {
1537 Index
= Status
& ~MAX_BIT
;
1538 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
1539 ArgumentString
= mStatusString
[Index
+ WARNING_STATUS_NUMBER
];
1543 if (Index
<= WARNING_STATUS_NUMBER
) {
1544 ArgumentString
= mStatusString
[Index
];
1547 if (ArgumentString
== ValueBuffer
) {
1548 InternalPrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
1553 Format
+= BytesPerFormatCharacter
;
1554 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1555 if (FormatCharacter
== '\n') {
1557 // Translate '\r\n' to '\r\n'
1559 ArgumentString
= "\r\n";
1562 // Translate '\r' to '\r'
1564 ArgumentString
= "\r";
1565 Format
-= BytesPerFormatCharacter
;
1571 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1573 ArgumentString
= "\r\n";
1574 Format
+= BytesPerFormatCharacter
;
1575 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1576 if (FormatCharacter
!= '\r') {
1577 Format
-= BytesPerFormatCharacter
;
1584 // if the type is '%' or unknown, then print it to the screen
1586 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1587 Flags
|= ARGUMENT_UNICODE
;
1593 Format
+= BytesPerFormatCharacter
;
1594 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1595 if (FormatCharacter
== '\n') {
1597 // Translate '\r\n' to '\r\n'
1599 ArgumentString
= "\r\n";
1602 // Translate '\r' to '\r'
1604 ArgumentString
= "\r";
1605 Format
-= BytesPerFormatCharacter
;
1611 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1613 ArgumentString
= "\r\n";
1614 Format
+= BytesPerFormatCharacter
;
1615 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1616 if (FormatCharacter
!= '\r') {
1617 Format
-= BytesPerFormatCharacter
;
1622 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1623 Flags
|= ARGUMENT_UNICODE
;
1628 // Retrieve the ArgumentString attriubutes
1630 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
1631 ArgumentMask
= 0xffff;
1632 BytesPerArgumentCharacter
= 2;
1634 ArgumentMask
= 0xff;
1635 BytesPerArgumentCharacter
= 1;
1637 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
1638 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
1641 // Compute the number of characters in ArgumentString and store it in Count
1642 // ArgumentString is either null-terminated, or it contains Precision characters
1644 for (Count
= 0; Count
< Precision
|| ((Flags
& PRECISION
) == 0); Count
++) {
1645 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
1646 if (ArgumentCharacter
== 0) {
1652 if (Precision
< Count
) {
1657 // Pad before the string
1659 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
1660 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1665 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1667 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1669 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1671 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1676 // Output the Prefix character if it is present
1684 // Copy the string into the output buffer performing the required type conversions
1686 while (Index
< Count
) {
1687 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (*(ArgumentString
+ 1) << 8)) & ArgumentMask
;
1689 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1690 ArgumentString
+= BytesPerArgumentCharacter
;
1697 if (Index
< Count
) {
1698 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1705 // Pad after the string
1707 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
1708 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1712 // Get the next character from the format string
1714 Format
+= BytesPerFormatCharacter
;
1717 // Get the next character from the format string
1719 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1722 return (LengthToReturn
/ BytesPerOutputCharacter
);
1726 Returns the number of characters that would be produced by if the formatted
1727 output were produced not including the Null-terminator.
1729 If FormatString is NULL, then ASSERT().
1730 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
1732 @param[in] FormatString A Null-terminated Unicode format string.
1733 @param[in] Marker VA_LIST marker for the variable argument list.
1735 @return The number of characters that would be produced, not including the
1741 IN CONST CHAR16
*FormatString
,
1745 ASSERT(FormatString
!= NULL
);
1746 return InternalPrintLibSPrintMarker (NULL
, 0, FORMAT_UNICODE
| OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);
1750 Returns the number of characters that would be produced by if the formatted
1751 output were produced not including the Null-terminator.
1753 If FormatString is NULL, then ASSERT().
1755 @param[in] FormatString A Null-terminated ASCII format string.
1756 @param[in] Marker VA_LIST marker for the variable argument list.
1758 @return The number of characters that would be produced, not including the
1763 SPrintLengthAsciiFormat (
1764 IN CONST CHAR8
*FormatString
,
1768 ASSERT(FormatString
!= NULL
);
1769 return InternalPrintLibSPrintMarker (NULL
, 0, OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);