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
1137 CHAR8
*OriginalBuffer
;
1139 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
1140 UINT32 BytesPerOutputCharacter
;
1141 UINTN BytesPerFormatCharacter
;
1143 UINTN FormatCharacter
;
1147 CONST CHAR8
*ArgumentString
;
1153 INTN BytesPerArgumentCharacter
;
1154 UINTN ArgumentCharacter
;
1162 RETURN_STATUS Status
;
1166 UINTN LengthToReturn
;
1169 // If you change this code be sure to match the 2 versions of this function.
1170 // Nearly identical logic is found in the BasePrintLib and
1171 // DxePrintLibPrint2Protocol (both PrintLib instances).
1174 ASSERT(Flags
& COUNT_ONLY_NO_PRINT
);
1176 if ((Flags
& OUTPUT_UNICODE
) != 0) {
1177 BytesPerOutputCharacter
= 2;
1179 BytesPerOutputCharacter
= 1;
1185 // Reserve space for the Null terminator.
1188 OriginalBuffer
= Buffer
;
1191 // Set the tag for the end of the input Buffer.
1193 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
1195 if ((Flags
& FORMAT_UNICODE
) != 0) {
1197 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
1198 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1200 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
1201 BytesPerFormatCharacter
= 2;
1202 FormatMask
= 0xffff;
1205 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
1206 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
1208 ASSERT (AsciiStrSize (Format
) != 0);
1209 BytesPerFormatCharacter
= 1;
1214 // Get the first character from the format string
1216 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1219 // Loop until the end of the format string is reached or the output buffer is full
1221 while (FormatCharacter
!= 0 && Buffer
< EndBuffer
) {
1223 // Clear all the flag bits except those that may have been passed in
1225 Flags
&= (OUTPUT_UNICODE
| FORMAT_UNICODE
| COUNT_ONLY_NO_PRINT
);
1228 // Set the default width to zero, and the default precision to 1
1238 switch (FormatCharacter
) {
1241 // Parse Flags and Width
1243 for (Done
= FALSE
; !Done
; ) {
1244 Format
+= BytesPerFormatCharacter
;
1245 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1246 switch (FormatCharacter
) {
1251 Flags
|= LEFT_JUSTIFY
;
1254 Flags
|= PREFIX_SIGN
;
1257 Flags
|= PREFIX_BLANK
;
1260 Flags
|= COMMA_TYPE
;
1267 if ((Flags
& PRECISION
) == 0) {
1268 Flags
|= PAD_TO_WIDTH
;
1269 if (BaseListMarker
== NULL
) {
1270 Width
= VA_ARG (VaListMarker
, UINTN
);
1272 Width
= BASE_ARG (BaseListMarker
, UINTN
);
1275 if (BaseListMarker
== NULL
) {
1276 Precision
= VA_ARG (VaListMarker
, UINTN
);
1278 Precision
= BASE_ARG (BaseListMarker
, UINTN
);
1283 if ((Flags
& PRECISION
) == 0) {
1284 Flags
|= PREFIX_ZERO
;
1295 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
1296 Count
= (Count
* 10) + FormatCharacter
- '0';
1297 Format
+= BytesPerFormatCharacter
;
1298 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1300 Format
-= BytesPerFormatCharacter
;
1301 if ((Flags
& PRECISION
) == 0) {
1302 Flags
|= PAD_TO_WIDTH
;
1311 // Make no output if Format string terminates unexpectedly when
1312 // looking up for flag, width, precision and type.
1314 Format
-= BytesPerFormatCharacter
;
1317 // break skipped on purpose.
1326 // Handle each argument type
1328 switch (FormatCharacter
) {
1331 // Flag space, +, 0, L & l are invalid for type p.
1333 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
);
1334 if (sizeof (VOID
*) > 4) {
1338 Flags
|= PREFIX_ZERO
;
1340 // break skipped on purpose
1345 // break skipped on purpose
1348 if ((Flags
& LONG_TYPE
) == 0) {
1350 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1351 // This assumption is made so the format string definition is compatible with the ANSI C
1352 // Specification for formatted strings. It is recommended that the Base Types be used
1353 // everywhere, but in this one case, compliance with ANSI C is more important, and
1354 // provides an implementation that is compatible with that largest possible set of CPU
1355 // architectures. This is why the type "int" is used in this one case.
1357 if (BaseListMarker
== NULL
) {
1358 Value
= VA_ARG (VaListMarker
, int);
1360 Value
= BASE_ARG (BaseListMarker
, int);
1363 if (BaseListMarker
== NULL
) {
1364 Value
= VA_ARG (VaListMarker
, INT64
);
1366 Value
= BASE_ARG (BaseListMarker
, INT64
);
1369 if ((Flags
& PREFIX_BLANK
) != 0) {
1372 if ((Flags
& PREFIX_SIGN
) != 0) {
1375 if ((Flags
& COMMA_TYPE
) != 0) {
1378 if ((Flags
& RADIX_HEX
) == 0) {
1381 Flags
&= (~PREFIX_ZERO
);
1385 Flags
|= PREFIX_SIGN
;
1392 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
1394 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1395 // This assumption is made so the format string definition is compatible with the ANSI C
1396 // Specification for formatted strings. It is recommended that the Base Types be used
1397 // everywhere, but in this one case, compliance with ANSI C is more important, and
1398 // provides an implementation that is compatible with that largest possible set of CPU
1399 // architectures. This is why the type "unsigned int" is used in this one case.
1401 Value
= (unsigned int)Value
;
1405 // Convert Value to a reversed string
1407 Count
= InternalPrintLibValueToString (ValueBuffer
, Value
, Radix
) - ValueBuffer
;
1408 if (Value
== 0 && Precision
== 0) {
1411 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
1415 Digits
= 3 - Digits
;
1417 if (Comma
&& Count
!= 0) {
1418 Count
+= ((Count
- 1) / 3);
1424 Flags
|= ARGUMENT_REVERSED
;
1426 if ((Flags
& PREFIX_ZERO
) != 0) {
1427 if ((Flags
& LEFT_JUSTIFY
) == 0) {
1428 if ((Flags
& PAD_TO_WIDTH
) != 0) {
1429 if ((Flags
& PRECISION
) == 0) {
1439 Flags
|= ARGUMENT_UNICODE
;
1441 // break skipped on purpose
1444 if (BaseListMarker
== NULL
) {
1445 ArgumentString
= VA_ARG (VaListMarker
, CHAR8
*);
1447 ArgumentString
= BASE_ARG (BaseListMarker
, CHAR8
*);
1449 if (ArgumentString
== NULL
) {
1450 Flags
&= (~ARGUMENT_UNICODE
);
1451 ArgumentString
= "<null string>";
1454 // Set the default precision for string to be zero if not specified.
1456 if ((Flags
& PRECISION
) == 0) {
1462 if (BaseListMarker
== NULL
) {
1463 Character
= VA_ARG (VaListMarker
, UINTN
) & 0xffff;
1465 Character
= BASE_ARG (BaseListMarker
, UINTN
) & 0xffff;
1467 ArgumentString
= (CHAR8
*)&Character
;
1468 Flags
|= ARGUMENT_UNICODE
;
1472 if (BaseListMarker
== NULL
) {
1473 TmpGuid
= VA_ARG (VaListMarker
, GUID
*);
1475 TmpGuid
= BASE_ARG (BaseListMarker
, GUID
*);
1477 if (TmpGuid
== NULL
) {
1478 ArgumentString
= "<null guid>";
1480 GuidData1
= ReadUnaligned32 (&(TmpGuid
->Data1
));
1481 GuidData2
= ReadUnaligned16 (&(TmpGuid
->Data2
));
1482 GuidData3
= ReadUnaligned16 (&(TmpGuid
->Data3
));
1483 InternalPrintLibSPrint (
1485 MAXIMUM_VALUE_CHARACTERS
,
1487 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1500 ArgumentString
= ValueBuffer
;
1505 if (BaseListMarker
== NULL
) {
1506 TmpTime
= VA_ARG (VaListMarker
, TIME
*);
1508 TmpTime
= BASE_ARG (BaseListMarker
, TIME
*);
1510 if (TmpTime
== NULL
) {
1511 ArgumentString
= "<null time>";
1513 InternalPrintLibSPrint (
1515 MAXIMUM_VALUE_CHARACTERS
,
1517 "%02d/%02d/%04d %02d:%02d",
1524 ArgumentString
= ValueBuffer
;
1529 if (BaseListMarker
== NULL
) {
1530 Status
= VA_ARG (VaListMarker
, RETURN_STATUS
);
1532 Status
= BASE_ARG (BaseListMarker
, RETURN_STATUS
);
1534 ArgumentString
= ValueBuffer
;
1535 if (RETURN_ERROR (Status
)) {
1539 Index
= Status
& ~MAX_BIT
;
1540 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
1541 ArgumentString
= mStatusString
[Index
+ WARNING_STATUS_NUMBER
];
1545 if (Index
<= WARNING_STATUS_NUMBER
) {
1546 ArgumentString
= mStatusString
[Index
];
1549 if (ArgumentString
== ValueBuffer
) {
1550 InternalPrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
1555 Format
+= BytesPerFormatCharacter
;
1556 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1557 if (FormatCharacter
== '\n') {
1559 // Translate '\r\n' to '\r\n'
1561 ArgumentString
= "\r\n";
1564 // Translate '\r' to '\r'
1566 ArgumentString
= "\r";
1567 Format
-= BytesPerFormatCharacter
;
1573 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1575 ArgumentString
= "\r\n";
1576 Format
+= BytesPerFormatCharacter
;
1577 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1578 if (FormatCharacter
!= '\r') {
1579 Format
-= BytesPerFormatCharacter
;
1586 // if the type is '%' or unknown, then print it to the screen
1588 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1589 Flags
|= ARGUMENT_UNICODE
;
1595 Format
+= BytesPerFormatCharacter
;
1596 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1597 if (FormatCharacter
== '\n') {
1599 // Translate '\r\n' to '\r\n'
1601 ArgumentString
= "\r\n";
1604 // Translate '\r' to '\r'
1606 ArgumentString
= "\r";
1607 Format
-= BytesPerFormatCharacter
;
1613 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1615 ArgumentString
= "\r\n";
1616 Format
+= BytesPerFormatCharacter
;
1617 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1618 if (FormatCharacter
!= '\r') {
1619 Format
-= BytesPerFormatCharacter
;
1624 ArgumentString
= (CHAR8
*)&FormatCharacter
;
1625 Flags
|= ARGUMENT_UNICODE
;
1630 // Retrieve the ArgumentString attriubutes
1632 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
1633 ArgumentMask
= 0xffff;
1634 BytesPerArgumentCharacter
= 2;
1636 ArgumentMask
= 0xff;
1637 BytesPerArgumentCharacter
= 1;
1639 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
1640 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
1643 // Compute the number of characters in ArgumentString and store it in Count
1644 // ArgumentString is either null-terminated, or it contains Precision characters
1646 for (Count
= 0; Count
< Precision
|| ((Flags
& PRECISION
) == 0); Count
++) {
1647 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
1648 if (ArgumentCharacter
== 0) {
1654 if (Precision
< Count
) {
1659 // Pad before the string
1661 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
1662 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1667 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1669 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1671 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
1673 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1678 // Output the Prefix character if it is present
1686 // Copy the string into the output buffer performing the required type conversions
1688 while (Index
< Count
) {
1689 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (*(ArgumentString
+ 1) << 8)) & ArgumentMask
;
1691 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1692 ArgumentString
+= BytesPerArgumentCharacter
;
1699 if (Index
< Count
) {
1700 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
1707 // Pad after the string
1709 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
1710 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
1714 // Get the next character from the format string
1716 Format
+= BytesPerFormatCharacter
;
1719 // Get the next character from the format string
1721 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
1724 return (LengthToReturn
/ BytesPerOutputCharacter
);
1728 Returns the number of characters that would be produced by if the formatted
1729 output were produced not including the Null-terminator.
1731 If FormatString is NULL, then ASSERT().
1732 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
1734 @param[in] FormatString A Null-terminated Unicode format string.
1735 @param[in] Marker VA_LIST marker for the variable argument list.
1737 @return The number of characters that would be produced, not including the
1743 IN CONST CHAR16
*FormatString
,
1747 ASSERT(FormatString
!= NULL
);
1748 return InternalPrintLibSPrintMarker (NULL
, 0, FORMAT_UNICODE
| OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);
1752 Returns the number of characters that would be produced by if the formatted
1753 output were produced not including the Null-terminator.
1755 If FormatString is NULL, then ASSERT().
1757 @param[in] FormatString A Null-terminated ASCII format string.
1758 @param[in] Marker VA_LIST marker for the variable argument list.
1760 @return The number of characters that would be produced, not including the
1765 SPrintLengthAsciiFormat (
1766 IN CONST CHAR8
*FormatString
,
1770 ASSERT(FormatString
!= NULL
);
1771 return InternalPrintLibSPrintMarker (NULL
, 0, OUTPUT_UNICODE
| COUNT_ONLY_NO_PRINT
, (CHAR8
*)FormatString
, Marker
, NULL
);