]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
MdeModulePkg DxePrintLibPrint2Protocol Library SPrintLength() API issue.
[mirror_edk2.git] / MdeModulePkg / Library / DxePrintLibPrint2Protocol / PrintLib.c
1 /** @file
2 Instance of Print Library based on gEfiPrint2ProtocolGuid.
3
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.
8
9 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
14
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.
17
18 **/
19
20 #include <Uefi.h>
21 #include <Base.h>
22 #include <Protocol/Print2.h>
23
24 #include <Library/PrintLib.h>
25
26 #include <Library/BaseLib.h>
27 #include <Library/DebugLib.h>
28
29 EFI_PRINT2_PROTOCOL *mPrint2Protocol = NULL;
30
31 /**
32 The constructor function caches the pointer to Print2 protocol.
33
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.
36
37 @param ImageHandle The firmware allocated handle for the EFI image.
38 @param SystemTable A pointer to the EFI System Table.
39
40 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
41
42 **/
43 EFI_STATUS
44 EFIAPI
45 PrintLibConstructor (
46 IN EFI_HANDLE ImageHandle,
47 IN EFI_SYSTEM_TABLE *SystemTable
48 )
49 {
50 EFI_STATUS Status;
51
52 Status = SystemTable->BootServices->LocateProtocol (
53 &gEfiPrint2ProtocolGuid,
54 NULL,
55 (VOID**) &mPrint2Protocol
56 );
57 ASSERT_EFI_ERROR (Status);
58 ASSERT (mPrint2Protocol != NULL);
59
60 return Status;
61 }
62
63
64 /**
65 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated
66 format string.
67
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.
73
74 @return The number of bytes in BaseListMarker. 0 if BaseListMarker is too small.
75
76 **/
77 BOOLEAN
78 DxePrintLibPrint2ProtocolVaListToBaseList (
79 IN BOOLEAN AsciiFormat,
80 IN CONST CHAR8 *Format,
81 IN VA_LIST VaListMarker,
82 OUT BASE_LIST BaseListMarker,
83 IN UINTN Size
84 )
85 {
86 BASE_LIST BaseListStart;
87 UINTN BytesPerFormatCharacter;
88 UINTN FormatMask;
89 UINTN FormatCharacter;
90 BOOLEAN Long;
91 BOOLEAN Done;
92
93 ASSERT (Format != NULL);
94 ASSERT (BaseListMarker != NULL);
95
96 BaseListStart = BaseListMarker;
97
98 if (AsciiFormat) {
99 ASSERT (AsciiStrSize (Format) != 0);
100 BytesPerFormatCharacter = 1;
101 FormatMask = 0xff;
102 } else {
103 ASSERT (StrSize ((CHAR16 *) Format) != 0);
104 BytesPerFormatCharacter = 2;
105 FormatMask = 0xffff;
106 }
107
108 //
109 // Get the first character from the format string
110 //
111 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
112
113 while (FormatCharacter != 0) {
114 if (FormatCharacter == '%') {
115 Long = FALSE;
116
117 //
118 // Parse Flags and Width
119 //
120 for (Done = FALSE; !Done; ) {
121 //
122 // Get the next character from the format string
123 //
124 Format += BytesPerFormatCharacter;
125
126 //
127 // Get the next character from the format string
128 //
129 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
130
131 switch (FormatCharacter) {
132 case '.':
133 case '-':
134 case '+':
135 case ' ':
136 case ',':
137 case '0':
138 case '1':
139 case '2':
140 case '3':
141 case '4':
142 case '5':
143 case '6':
144 case '7':
145 case '8':
146 case '9':
147 break;
148 case 'L':
149 case 'l':
150 Long = TRUE;
151 break;
152 case '*':
153 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
154 break;
155 case '\0':
156 //
157 // Make no output if Format string terminates unexpectedly when
158 // looking up for flag, width, precision and type.
159 //
160 Format -= BytesPerFormatCharacter;
161 //
162 // break skipped on purpose.
163 //
164 default:
165 Done = TRUE;
166 break;
167 }
168 }
169
170 //
171 // Handle each argument type
172 //
173 switch (FormatCharacter) {
174 case 'p':
175 if (sizeof (VOID *) > 4) {
176 Long = TRUE;
177 }
178 case 'X':
179 case 'x':
180 case 'd':
181 if (Long) {
182 BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
183 } else {
184 BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
185 }
186 break;
187 case 's':
188 case 'S':
189 case 'a':
190 case 'g':
191 case 't':
192 BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
193 break;
194 case 'c':
195 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
196 break;
197 case 'r':
198 BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
199 break;
200 }
201 }
202
203 //
204 // If BASE_LIST is larger than Size, then return FALSE
205 //
206 if ((UINTN)((UINT8 *)BaseListMarker - (UINT8 *)BaseListStart) > Size) {
207 return FALSE;
208 }
209
210 //
211 // Get the next character from the format string
212 //
213 Format += BytesPerFormatCharacter;
214
215 //
216 // Get the next character from the format string
217 //
218 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
219 }
220 return TRUE;
221 }
222
223 /**
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
226
227 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
228 and BufferSize.
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
233 the Null-terminator.
234 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
235
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
242 ASSERT().
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().
246
247 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
248 Unicode string.
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.
252
253 @return The number of Unicode characters in the produced output buffer not including the
254 Null-terminator.
255
256 **/
257 UINTN
258 EFIAPI
259 UnicodeVSPrint (
260 OUT CHAR16 *StartOfBuffer,
261 IN UINTN BufferSize,
262 IN CONST CHAR16 *FormatString,
263 IN VA_LIST Marker
264 )
265 {
266 UINT64 BaseListMarker[256 / sizeof (UINT64)];
267
268 DxePrintLibPrint2ProtocolVaListToBaseList (
269 FALSE,
270 (CHAR8 *)FormatString,
271 Marker,
272 (BASE_LIST)BaseListMarker,
273 sizeof (BaseListMarker) - 8
274 );
275
276 return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
277 }
278
279 /**
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
282
283 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
284 and BufferSize.
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
289 the Null-terminator.
290 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
291
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
298 ASSERT().
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().
302
303 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
304 Unicode string.
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.
308
309 @return The number of Unicode characters in the produced output buffer not including the
310 Null-terminator.
311
312 **/
313 UINTN
314 EFIAPI
315 UnicodeBSPrint (
316 OUT CHAR16 *StartOfBuffer,
317 IN UINTN BufferSize,
318 IN CONST CHAR16 *FormatString,
319 IN BASE_LIST Marker
320 )
321 {
322 return mPrint2Protocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
323 }
324
325 /**
326 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
327 Unicode format string and variable argument list.
328
329 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
330 and BufferSize.
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
334 the Null-terminator.
335 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
336
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
343 ASSERT().
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().
347
348 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
349 Unicode string.
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.
354
355 @return The number of Unicode characters in the produced output buffer not including the
356 Null-terminator.
357
358 **/
359 UINTN
360 EFIAPI
361 UnicodeSPrint (
362 OUT CHAR16 *StartOfBuffer,
363 IN UINTN BufferSize,
364 IN CONST CHAR16 *FormatString,
365 ...
366 )
367 {
368 VA_LIST Marker;
369 UINTN NumberOfPrinted;
370
371 VA_START (Marker, FormatString);
372 NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
373 VA_END (Marker);
374 return NumberOfPrinted;
375 }
376
377 /**
378 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
379 ASCII format string and a VA_LIST argument list
380
381 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
382 and BufferSize.
383 The Unicode string is produced by parsing the format string specified by FormatString.
384 Arguments are pulled from the variable argument list specified by Marker based on the
385 contents of the format string.
386 The number of Unicode characters in the produced output buffer is returned not including
387 the Null-terminator.
388 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
389
390 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
391 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
392 If BufferSize > 1 and FormatString is NULL, then ASSERT().
393 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
394 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
395 ASSERT().
396 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
397 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
398 Null-terminator, then ASSERT().
399
400 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
401 Unicode string.
402 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
403 @param FormatString Null-terminated Unicode format string.
404 @param Marker VA_LIST marker for the variable argument list.
405
406 @return The number of Unicode characters in the produced output buffer not including the
407 Null-terminator.
408
409 **/
410 UINTN
411 EFIAPI
412 UnicodeVSPrintAsciiFormat (
413 OUT CHAR16 *StartOfBuffer,
414 IN UINTN BufferSize,
415 IN CONST CHAR8 *FormatString,
416 IN VA_LIST Marker
417 )
418 {
419 UINT64 BaseListMarker[256 / sizeof (UINT64)];
420
421 DxePrintLibPrint2ProtocolVaListToBaseList (
422 TRUE,
423 FormatString,
424 Marker,
425 (BASE_LIST)BaseListMarker,
426 sizeof (BaseListMarker) - 8
427 );
428
429 return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
430 }
431
432 /**
433 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
434 ASCII format string and a BASE_LIST argument list
435
436 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
437 and BufferSize.
438 The Unicode string is produced by parsing the format string specified by FormatString.
439 Arguments are pulled from the variable argument list specified by Marker based on the
440 contents of the format string.
441 The number of Unicode characters in the produced output buffer is returned not including
442 the Null-terminator.
443 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
444
445 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
446 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
447 If BufferSize > 1 and FormatString is NULL, then ASSERT().
448 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
449 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
450 ASSERT().
451 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
452 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
453 Null-terminator, then ASSERT().
454
455 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
456 Unicode string.
457 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
458 @param FormatString Null-terminated Unicode format string.
459 @param Marker BASE_LIST marker for the variable argument list.
460
461 @return The number of Unicode characters in the produced output buffer not including the
462 Null-terminator.
463
464 **/
465 UINTN
466 EFIAPI
467 UnicodeBSPrintAsciiFormat (
468 OUT CHAR16 *StartOfBuffer,
469 IN UINTN BufferSize,
470 IN CONST CHAR8 *FormatString,
471 IN BASE_LIST Marker
472 )
473 {
474 return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
475 }
476
477 /**
478 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
479 ASCII format string and variable argument list.
480
481 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
482 and BufferSize.
483 The Unicode string is produced by parsing the format string specified by FormatString.
484 Arguments are pulled from the variable argument list based on the contents of the
485 format string.
486 The number of Unicode characters in the produced output buffer is returned not including
487 the Null-terminator.
488 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
489
490 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
491 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
492 If BufferSize > 1 and FormatString is NULL, then ASSERT().
493 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
494 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
495 ASSERT().
496 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
497 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
498 Null-terminator, then ASSERT().
499
500 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
501 Unicode string.
502 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
503 @param FormatString Null-terminated Unicode format string.
504 @param ... Variable argument list whose contents are accessed based on the
505 format string specified by FormatString.
506
507 @return The number of Unicode characters in the produced output buffer not including the
508 Null-terminator.
509
510 **/
511 UINTN
512 EFIAPI
513 UnicodeSPrintAsciiFormat (
514 OUT CHAR16 *StartOfBuffer,
515 IN UINTN BufferSize,
516 IN CONST CHAR8 *FormatString,
517 ...
518 )
519 {
520 VA_LIST Marker;
521 UINTN NumberOfPrinted;
522
523 VA_START (Marker, FormatString);
524 NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
525 VA_END (Marker);
526 return NumberOfPrinted;
527 }
528
529 /**
530 Converts a decimal value to a Null-terminated Unicode string.
531
532 Converts the decimal number specified by Value to a Null-terminated Unicode
533 string specified by Buffer containing at most Width characters. No padding of spaces
534 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
535 The number of Unicode characters in Buffer is returned not including the Null-terminator.
536 If the conversion contains more than Width characters, then only the first
537 Width characters are returned, and the total number of characters
538 required to perform the conversion is returned.
539 Additional conversion parameters are specified in Flags.
540
541 The Flags bit LEFT_JUSTIFY is always ignored.
542 All conversions are left justified in Buffer.
543 If Width is 0, PREFIX_ZERO is ignored in Flags.
544 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
545 are inserted every 3rd digit starting from the right.
546 If RADIX_HEX is set in Flags, then the output buffer will be
547 formatted in hexadecimal format.
548 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
549 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
550 then Buffer is padded with '0' characters so the combination of the optional '-'
551 sign character, '0' characters, digit characters for Value, and the Null-terminator
552 add up to Width characters.
553 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
554 If Buffer is NULL, then ASSERT().
555 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
556 If unsupported bits are set in Flags, then ASSERT().
557 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
558 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
559
560 @param Buffer Pointer to the output buffer for the produced Null-terminated
561 Unicode string.
562 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
563 @param Value The 64-bit signed value to convert to a string.
564 @param Width The maximum number of Unicode characters to place in Buffer, not including
565 the Null-terminator.
566
567 @return The number of Unicode characters in Buffer not including the Null-terminator.
568
569 **/
570 UINTN
571 EFIAPI
572 UnicodeValueToString (
573 IN OUT CHAR16 *Buffer,
574 IN UINTN Flags,
575 IN INT64 Value,
576 IN UINTN Width
577 )
578 {
579 return mPrint2Protocol->UnicodeValueToString (Buffer, Flags, Value, Width);
580 }
581
582 /**
583 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
584 ASCII format string and a VA_LIST argument list.
585
586 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
587 and BufferSize.
588 The ASCII string is produced by parsing the format string specified by FormatString.
589 Arguments are pulled from the variable argument list specified by Marker based on
590 the contents of the format string.
591 The number of ASCII characters in the produced output buffer is returned not including
592 the Null-terminator.
593 If BufferSize is 0, then no output buffer is produced and 0 is returned.
594
595 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
596 If BufferSize > 0 and FormatString is NULL, then ASSERT().
597 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
598 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
599 ASSERT().
600 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
601 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
602 Null-terminator, then ASSERT().
603
604 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
605 ASCII string.
606 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
607 @param FormatString Null-terminated Unicode format string.
608 @param Marker VA_LIST marker for the variable argument list.
609
610 @return The number of ASCII characters in the produced output buffer not including the
611 Null-terminator.
612
613 **/
614 UINTN
615 EFIAPI
616 AsciiVSPrint (
617 OUT CHAR8 *StartOfBuffer,
618 IN UINTN BufferSize,
619 IN CONST CHAR8 *FormatString,
620 IN VA_LIST Marker
621 )
622 {
623 UINT64 BaseListMarker[256 / sizeof (UINT64)];
624
625 DxePrintLibPrint2ProtocolVaListToBaseList (
626 TRUE,
627 FormatString,
628 Marker,
629 (BASE_LIST)BaseListMarker,
630 sizeof (BaseListMarker) - 8
631 );
632
633 return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
634 }
635
636 /**
637 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
638 ASCII format string and a BASE_LIST argument list.
639
640 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
641 and BufferSize.
642 The ASCII string is produced by parsing the format string specified by FormatString.
643 Arguments are pulled from the variable argument list specified by Marker based on
644 the contents of the format string.
645 The number of ASCII characters in the produced output buffer is returned not including
646 the Null-terminator.
647 If BufferSize is 0, then no output buffer is produced and 0 is returned.
648
649 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
650 If BufferSize > 0 and FormatString is NULL, then ASSERT().
651 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
652 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
653 ASSERT().
654 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
655 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
656 Null-terminator, then ASSERT().
657
658 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
659 ASCII string.
660 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
661 @param FormatString Null-terminated Unicode format string.
662 @param Marker BASE_LIST marker for the variable argument list.
663
664 @return The number of ASCII characters in the produced output buffer not including the
665 Null-terminator.
666
667 **/
668 UINTN
669 EFIAPI
670 AsciiBSPrint (
671 OUT CHAR8 *StartOfBuffer,
672 IN UINTN BufferSize,
673 IN CONST CHAR8 *FormatString,
674 IN BASE_LIST Marker
675 )
676 {
677 return mPrint2Protocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
678 }
679
680 /**
681 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
682 ASCII format string and variable argument list.
683
684 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
685 and BufferSize.
686 The ASCII string is produced by parsing the format string specified by FormatString.
687 Arguments are pulled from the variable argument list based on the contents of the
688 format string.
689 The number of ASCII characters in the produced output buffer is returned not including
690 the Null-terminator.
691 If BufferSize is 0, then no output buffer is produced and 0 is returned.
692
693 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
694 If BufferSize > 0 and FormatString is NULL, then ASSERT().
695 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
696 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
697 ASSERT().
698 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
699 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
700 Null-terminator, then ASSERT().
701
702 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
703 ASCII string.
704 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
705 @param FormatString Null-terminated Unicode format string.
706 @param ... Variable argument list whose contents are accessed based on the
707 format string specified by FormatString.
708
709 @return The number of ASCII characters in the produced output buffer not including the
710 Null-terminator.
711
712 **/
713 UINTN
714 EFIAPI
715 AsciiSPrint (
716 OUT CHAR8 *StartOfBuffer,
717 IN UINTN BufferSize,
718 IN CONST CHAR8 *FormatString,
719 ...
720 )
721 {
722 VA_LIST Marker;
723 UINTN NumberOfPrinted;
724
725 VA_START (Marker, FormatString);
726 NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
727 VA_END (Marker);
728 return NumberOfPrinted;
729 }
730
731 /**
732 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
733 ASCII format string and a VA_LIST argument list.
734
735 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
736 and BufferSize.
737 The ASCII string is produced by parsing the format string specified by FormatString.
738 Arguments are pulled from the variable argument list specified by Marker based on
739 the contents of the format string.
740 The number of ASCII characters in the produced output buffer is returned not including
741 the Null-terminator.
742 If BufferSize is 0, then no output buffer is produced and 0 is returned.
743
744 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
745 If BufferSize > 0 and FormatString is NULL, then ASSERT().
746 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
747 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
748 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
749 ASSERT().
750 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
751 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
752 Null-terminator, then ASSERT().
753
754 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
755 ASCII string.
756 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
757 @param FormatString Null-terminated Unicode format string.
758 @param Marker VA_LIST marker for the variable argument list.
759
760 @return The number of ASCII characters in the produced output buffer not including the
761 Null-terminator.
762
763 **/
764 UINTN
765 EFIAPI
766 AsciiVSPrintUnicodeFormat (
767 OUT CHAR8 *StartOfBuffer,
768 IN UINTN BufferSize,
769 IN CONST CHAR16 *FormatString,
770 IN VA_LIST Marker
771 )
772 {
773 UINT64 BaseListMarker[256 / sizeof (UINT64)];
774
775 DxePrintLibPrint2ProtocolVaListToBaseList (
776 FALSE,
777 (CHAR8 *)FormatString,
778 Marker,
779 (BASE_LIST)BaseListMarker,
780 sizeof (BaseListMarker) - 8
781 );
782
783 return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
784 }
785
786 /**
787 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
788 ASCII format string and a BASE_LIST argument list.
789
790 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
791 and BufferSize.
792 The ASCII string is produced by parsing the format string specified by FormatString.
793 Arguments are pulled from the variable argument list specified by Marker based on
794 the contents of the format string.
795 The number of ASCII characters in the produced output buffer is returned not including
796 the Null-terminator.
797 If BufferSize is 0, then no output buffer is produced and 0 is returned.
798
799 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
800 If BufferSize > 0 and FormatString is NULL, then ASSERT().
801 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
802 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
803 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
804 ASSERT().
805 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
806 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
807 Null-terminator, then ASSERT().
808
809 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
810 ASCII string.
811 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
812 @param FormatString Null-terminated Unicode format string.
813 @param Marker BASE_LIST marker for the variable argument list.
814
815 @return The number of ASCII characters in the produced output buffer not including the
816 Null-terminator.
817
818 **/
819 UINTN
820 EFIAPI
821 AsciiBSPrintUnicodeFormat (
822 OUT CHAR8 *StartOfBuffer,
823 IN UINTN BufferSize,
824 IN CONST CHAR16 *FormatString,
825 IN BASE_LIST Marker
826 )
827 {
828 return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
829 }
830
831 /**
832 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
833 ASCII format string and variable argument list.
834
835 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
836 and BufferSize.
837 The ASCII string is produced by parsing the format string specified by FormatString.
838 Arguments are pulled from the variable argument list based on the contents of the
839 format string.
840 The number of ASCII characters in the produced output buffer is returned not including
841 the Null-terminator.
842 If BufferSize is 0, then no output buffer is produced and 0 is returned.
843
844 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
845 If BufferSize > 0 and FormatString is NULL, then ASSERT().
846 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
847 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
848 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
849 ASSERT().
850 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
851 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
852 Null-terminator, then ASSERT().
853
854 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
855 ASCII string.
856 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
857 @param FormatString Null-terminated Unicode format string.
858 @param ... Variable argument list whose contents are accessed based on the
859 format string specified by FormatString.
860
861 @return The number of ASCII characters in the produced output buffer not including the
862 Null-terminator.
863
864 **/
865 UINTN
866 EFIAPI
867 AsciiSPrintUnicodeFormat (
868 OUT CHAR8 *StartOfBuffer,
869 IN UINTN BufferSize,
870 IN CONST CHAR16 *FormatString,
871 ...
872 )
873 {
874 VA_LIST Marker;
875 UINTN NumberOfPrinted;
876
877 VA_START (Marker, FormatString);
878 NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
879 VA_END (Marker);
880 return NumberOfPrinted;
881 }
882
883
884 /**
885 Converts a decimal value to a Null-terminated ASCII string.
886
887 Converts the decimal number specified by Value to a Null-terminated ASCII string
888 specified by Buffer containing at most Width characters. No padding of spaces
889 is ever performed.
890 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
891 The number of ASCII characters in Buffer is returned not including the Null-terminator.
892 If the conversion contains more than Width characters, then only the first Width
893 characters are returned, and the total number of characters required to perform
894 the conversion is returned.
895 Additional conversion parameters are specified in Flags.
896 The Flags bit LEFT_JUSTIFY is always ignored.
897 All conversions are left justified in Buffer.
898 If Width is 0, PREFIX_ZERO is ignored in Flags.
899 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
900 are inserted every 3rd digit starting from the right.
901 If RADIX_HEX is set in Flags, then the output buffer will be
902 formatted in hexadecimal format.
903 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
904 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
905 then Buffer is padded with '0' characters so the combination of the optional '-'
906 sign character, '0' characters, digit characters for Value, and the Null-terminator
907 add up to Width characters.
908
909 If Buffer is NULL, then ASSERT().
910 If unsupported bits are set in Flags, then ASSERT().
911 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
912 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
913
914 @param Buffer Pointer to the output buffer for the produced Null-terminated
915 ASCII string.
916 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
917 @param Value The 64-bit signed value to convert to a string.
918 @param Width The maximum number of ASCII characters to place in Buffer, not including
919 the Null-terminator.
920
921 @return The number of ASCII characters in Buffer not including the Null-terminator.
922
923 **/
924 UINTN
925 EFIAPI
926 AsciiValueToString (
927 OUT CHAR8 *Buffer,
928 IN UINTN Flags,
929 IN INT64 Value,
930 IN UINTN Width
931 )
932 {
933 return mPrint2Protocol->AsciiValueToString (Buffer, Flags, Value, Width);
934 }
935
936 #define PREFIX_SIGN BIT1
937 #define PREFIX_BLANK BIT2
938 #define LONG_TYPE BIT4
939 #define OUTPUT_UNICODE BIT6
940 #define FORMAT_UNICODE BIT8
941 #define PAD_TO_WIDTH BIT9
942 #define ARGUMENT_UNICODE BIT10
943 #define PRECISION BIT11
944 #define ARGUMENT_REVERSED BIT12
945 #define COUNT_ONLY_NO_PRINT BIT13
946
947 //
948 // Record date and time information
949 //
950 typedef struct {
951 UINT16 Year;
952 UINT8 Month;
953 UINT8 Day;
954 UINT8 Hour;
955 UINT8 Minute;
956 UINT8 Second;
957 UINT8 Pad1;
958 UINT32 Nanosecond;
959 INT16 TimeZone;
960 UINT8 Daylight;
961 UINT8 Pad2;
962 } TIME;
963
964 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
965
966 /**
967 Internal function that convert a number to a string in Buffer.
968
969 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.
970
971 @param Buffer Location to place the ASCII string of Value.
972 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.
973 @param Radix Radix of the value
974
975 @return A pointer to the end of buffer filled with ASCII string.
976
977 **/
978 CHAR8 *
979 InternalPrintLibValueToString (
980 IN OUT CHAR8 *Buffer,
981 IN INT64 Value,
982 IN UINTN Radix
983 )
984 {
985 UINT32 Remainder;
986
987 //
988 // Loop to convert one digit at a time in reverse order
989 //
990 *Buffer = 0;
991 do {
992 Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);
993 *(++Buffer) = mHexStr[Remainder];
994 } while (Value != 0);
995
996 //
997 // Return pointer of the end of filled buffer.
998 //
999 return Buffer;
1000 }
1001
1002 /**
1003 Worker function that produces a Null-terminated string in an output buffer
1004 based on a Null-terminated format string and a VA_LIST argument list.
1005
1006 VSPrint function to process format and place the results in Buffer. Since a
1007 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1008 this is the main print working routine.
1009
1010 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1011
1012 @param[out] Buffer The character buffer to print the results of the
1013 parsing of Format into.
1014 @param[in] BufferSize The maximum number of characters to put into
1015 buffer.
1016 @param[in] Flags Initial flags value.
1017 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1018 and COUNT_ONLY_NO_PRINT set.
1019 @param[in] Format A Null-terminated format string.
1020 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1021 processing Format.
1022 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1023 by processing Format.
1024
1025 @return The number of characters printed not including the Null-terminator.
1026 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1027 modification to Buffer.
1028
1029 **/
1030 UINTN
1031 InternalPrintLibSPrintMarker (
1032 OUT CHAR8 *Buffer,
1033 IN UINTN BufferSize,
1034 IN UINTN Flags,
1035 IN CONST CHAR8 *Format,
1036 IN VA_LIST VaListMarker, OPTIONAL
1037 IN BASE_LIST BaseListMarker OPTIONAL
1038 );
1039
1040 /**
1041 Worker function that produces a Null-terminated string in an output buffer
1042 based on a Null-terminated format string and variable argument list.
1043
1044 VSPrint function to process format and place the results in Buffer. Since a
1045 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1046 this is the main print working routine
1047
1048 @param StartOfBuffer The character buffer to print the results of the parsing
1049 of Format into.
1050 @param BufferSize The maximum number of characters to put into buffer.
1051 Zero means no limit.
1052 @param Flags Initial flags value.
1053 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
1054 @param FormatString A Null-terminated format string.
1055 @param ... The variable argument list.
1056
1057 @return The number of characters printed.
1058
1059 **/
1060 UINTN
1061 EFIAPI
1062 InternalPrintLibSPrint (
1063 OUT CHAR8 *StartOfBuffer,
1064 IN UINTN BufferSize,
1065 IN UINTN Flags,
1066 IN CONST CHAR8 *FormatString,
1067 ...
1068 )
1069 {
1070 VA_LIST Marker;
1071 UINTN NumberOfPrinted;
1072
1073 VA_START (Marker, FormatString);
1074 NumberOfPrinted = InternalPrintLibSPrintMarker (StartOfBuffer, BufferSize, Flags, FormatString, Marker, NULL);
1075 VA_END (Marker);
1076 return NumberOfPrinted;
1077 }
1078
1079 #define WARNING_STATUS_NUMBER 5
1080 #define ERROR_STATUS_NUMBER 33
1081
1082 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {
1083 "Success", // RETURN_SUCCESS = 0
1084 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
1085 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
1086 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
1087 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
1088 "Warning Stale Data", // RETURN_WARN_STALE_DATA = 5
1089 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
1090 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
1091 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
1092 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
1093 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
1094 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
1095 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
1096 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
1097 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
1098 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
1099 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
1100 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
1101 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
1102 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
1103 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
1104 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
1105 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
1106 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
1107 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
1108 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
1109 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
1110 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
1111 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
1112 "Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
1113 "Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT
1114 "Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT
1115 "CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT
1116 "End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT
1117 "Reserved (29)", // RESERVED = 29 | MAX_BIT
1118 "Reserved (30)", // RESERVED = 30 | MAX_BIT
1119 "End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT
1120 "Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT
1121 "Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT
1122 };
1123
1124 /**
1125 Internal function that places the character into the Buffer.
1126
1127 Internal function that places ASCII or Unicode character into the Buffer.
1128
1129 @param Buffer The buffer to place the Unicode or ASCII string.
1130 @param EndBuffer The end of the input Buffer. No characters will be
1131 placed after that.
1132 @param Length The count of character to be placed into Buffer.
1133 (Negative value indicates no buffer fill.)
1134 @param Character The character to be placed into Buffer.
1135 @param Increment The character increment in Buffer.
1136
1137 @return Buffer.
1138
1139 **/
1140 CHAR8 *
1141 InternalPrintLibFillBuffer (
1142 OUT CHAR8 *Buffer,
1143 IN CHAR8 *EndBuffer,
1144 IN INTN Length,
1145 IN UINTN Character,
1146 IN INTN Increment
1147 )
1148 {
1149 INTN Index;
1150
1151 for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) {
1152 *Buffer = (CHAR8) Character;
1153 if (Increment != 1) {
1154 *(Buffer + 1) = (CHAR8)(Character >> 8);
1155 }
1156 Buffer += Increment;
1157 }
1158
1159 return Buffer;
1160 }
1161
1162 /**
1163 Worker function that produces a Null-terminated string in an output buffer
1164 based on a Null-terminated format string and a VA_LIST argument list.
1165
1166 VSPrint function to process format and place the results in Buffer. Since a
1167 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
1168 this is the main print working routine.
1169
1170 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
1171
1172 @param[out] Buffer The character buffer to print the results of the
1173 parsing of Format into.
1174 @param[in] BufferSize The maximum number of characters to put into
1175 buffer.
1176 @param[in] Flags Initial flags value.
1177 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
1178 and COUNT_ONLY_NO_PRINT set.
1179 @param[in] Format A Null-terminated format string.
1180 @param[in] VaListMarker VA_LIST style variable argument list consumed by
1181 processing Format.
1182 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
1183 by processing Format.
1184
1185 @return The number of characters printed not including the Null-terminator.
1186 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
1187 modification to Buffer.
1188
1189 **/
1190 UINTN
1191 InternalPrintLibSPrintMarker (
1192 OUT CHAR8 *Buffer,
1193 IN UINTN BufferSize,
1194 IN UINTN Flags,
1195 IN CONST CHAR8 *Format,
1196 IN VA_LIST VaListMarker, OPTIONAL
1197 IN BASE_LIST BaseListMarker OPTIONAL
1198 )
1199 {
1200 CHAR8 *OriginalBuffer;
1201 CHAR8 *EndBuffer;
1202 CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];
1203 UINT32 BytesPerOutputCharacter;
1204 UINTN BytesPerFormatCharacter;
1205 UINTN FormatMask;
1206 UINTN FormatCharacter;
1207 UINTN Width;
1208 UINTN Precision;
1209 INT64 Value;
1210 CONST CHAR8 *ArgumentString;
1211 UINTN Character;
1212 GUID *TmpGuid;
1213 TIME *TmpTime;
1214 UINTN Count;
1215 UINTN ArgumentMask;
1216 INTN BytesPerArgumentCharacter;
1217 UINTN ArgumentCharacter;
1218 BOOLEAN Done;
1219 UINTN Index;
1220 CHAR8 Prefix;
1221 BOOLEAN ZeroPad;
1222 BOOLEAN Comma;
1223 UINTN Digits;
1224 UINTN Radix;
1225 RETURN_STATUS Status;
1226 UINT32 GuidData1;
1227 UINT16 GuidData2;
1228 UINT16 GuidData3;
1229 UINTN LengthToReturn;
1230
1231 //
1232 // If you change this code be sure to match the 2 versions of this function.
1233 // Nearly identical logic is found in the BasePrintLib and
1234 // DxePrintLibPrint2Protocol (both PrintLib instances).
1235 //
1236
1237 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
1238 if (BufferSize == 0) {
1239 Buffer = NULL;
1240 }
1241 } else {
1242 //
1243 // We can run without a Buffer for counting only.
1244 //
1245 if (BufferSize == 0) {
1246 return 0;
1247 }
1248 ASSERT (Buffer != NULL);
1249 }
1250
1251 if ((Flags & OUTPUT_UNICODE) != 0) {
1252 BytesPerOutputCharacter = 2;
1253 } else {
1254 BytesPerOutputCharacter = 1;
1255 }
1256
1257 LengthToReturn = 0;
1258 EndBuffer = NULL;
1259 OriginalBuffer = NULL;
1260
1261 //
1262 // Reserve space for the Null terminator.
1263 //
1264 if (Buffer != NULL) {
1265 BufferSize--;
1266 OriginalBuffer = Buffer;
1267
1268 //
1269 // Set the tag for the end of the input Buffer.
1270 //
1271 EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;
1272 }
1273
1274 if ((Flags & FORMAT_UNICODE) != 0) {
1275 //
1276 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
1277 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1278 //
1279 ASSERT (StrSize ((CHAR16 *) Format) != 0);
1280 BytesPerFormatCharacter = 2;
1281 FormatMask = 0xffff;
1282 } else {
1283 //
1284 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
1285 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
1286 //
1287 ASSERT (AsciiStrSize (Format) != 0);
1288 BytesPerFormatCharacter = 1;
1289 FormatMask = 0xff;
1290 }
1291
1292 //
1293 // Get the first character from the format string
1294 //
1295 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1296
1297 //
1298 // Loop until the end of the format string is reached or the output buffer is full
1299 //
1300 while (FormatCharacter != 0) {
1301 if ((Buffer != NULL) && (Buffer >= EndBuffer)) {
1302 break;
1303 }
1304 //
1305 // Clear all the flag bits except those that may have been passed in
1306 //
1307 Flags &= (UINTN) (OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);
1308
1309 //
1310 // Set the default width to zero, and the default precision to 1
1311 //
1312 Width = 0;
1313 Precision = 1;
1314 Prefix = 0;
1315 Comma = FALSE;
1316 ZeroPad = FALSE;
1317 Count = 0;
1318 Digits = 0;
1319
1320 switch (FormatCharacter) {
1321 case '%':
1322 //
1323 // Parse Flags and Width
1324 //
1325 for (Done = FALSE; !Done; ) {
1326 Format += BytesPerFormatCharacter;
1327 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1328 switch (FormatCharacter) {
1329 case '.':
1330 Flags |= PRECISION;
1331 break;
1332 case '-':
1333 Flags |= LEFT_JUSTIFY;
1334 break;
1335 case '+':
1336 Flags |= PREFIX_SIGN;
1337 break;
1338 case ' ':
1339 Flags |= PREFIX_BLANK;
1340 break;
1341 case ',':
1342 Flags |= COMMA_TYPE;
1343 break;
1344 case 'L':
1345 case 'l':
1346 Flags |= LONG_TYPE;
1347 break;
1348 case '*':
1349 if ((Flags & PRECISION) == 0) {
1350 Flags |= PAD_TO_WIDTH;
1351 if (BaseListMarker == NULL) {
1352 Width = VA_ARG (VaListMarker, UINTN);
1353 } else {
1354 Width = BASE_ARG (BaseListMarker, UINTN);
1355 }
1356 } else {
1357 if (BaseListMarker == NULL) {
1358 Precision = VA_ARG (VaListMarker, UINTN);
1359 } else {
1360 Precision = BASE_ARG (BaseListMarker, UINTN);
1361 }
1362 }
1363 break;
1364 case '0':
1365 if ((Flags & PRECISION) == 0) {
1366 Flags |= PREFIX_ZERO;
1367 }
1368 case '1':
1369 case '2':
1370 case '3':
1371 case '4':
1372 case '5':
1373 case '6':
1374 case '7':
1375 case '8':
1376 case '9':
1377 for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){
1378 Count = (Count * 10) + FormatCharacter - '0';
1379 Format += BytesPerFormatCharacter;
1380 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1381 }
1382 Format -= BytesPerFormatCharacter;
1383 if ((Flags & PRECISION) == 0) {
1384 Flags |= PAD_TO_WIDTH;
1385 Width = Count;
1386 } else {
1387 Precision = Count;
1388 }
1389 break;
1390
1391 case '\0':
1392 //
1393 // Make no output if Format string terminates unexpectedly when
1394 // looking up for flag, width, precision and type.
1395 //
1396 Format -= BytesPerFormatCharacter;
1397 Precision = 0;
1398 //
1399 // break skipped on purpose.
1400 //
1401 default:
1402 Done = TRUE;
1403 break;
1404 }
1405 }
1406
1407 //
1408 // Handle each argument type
1409 //
1410 switch (FormatCharacter) {
1411 case 'p':
1412 //
1413 // Flag space, +, 0, L & l are invalid for type p.
1414 //
1415 Flags &= ~((UINTN) (PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE));
1416 if (sizeof (VOID *) > 4) {
1417 Flags |= LONG_TYPE;
1418 }
1419 //
1420 // break skipped on purpose
1421 //
1422 case 'X':
1423 Flags |= PREFIX_ZERO;
1424 //
1425 // break skipped on purpose
1426 //
1427 case 'x':
1428 Flags |= RADIX_HEX;
1429 //
1430 // break skipped on purpose
1431 //
1432 case 'd':
1433 if ((Flags & LONG_TYPE) == 0) {
1434 //
1435 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1436 // This assumption is made so the format string definition is compatible with the ANSI C
1437 // Specification for formatted strings. It is recommended that the Base Types be used
1438 // everywhere, but in this one case, compliance with ANSI C is more important, and
1439 // provides an implementation that is compatible with that largest possible set of CPU
1440 // architectures. This is why the type "int" is used in this one case.
1441 //
1442 if (BaseListMarker == NULL) {
1443 Value = VA_ARG (VaListMarker, int);
1444 } else {
1445 Value = BASE_ARG (BaseListMarker, int);
1446 }
1447 } else {
1448 if (BaseListMarker == NULL) {
1449 Value = VA_ARG (VaListMarker, INT64);
1450 } else {
1451 Value = BASE_ARG (BaseListMarker, INT64);
1452 }
1453 }
1454 if ((Flags & PREFIX_BLANK) != 0) {
1455 Prefix = ' ';
1456 }
1457 if ((Flags & PREFIX_SIGN) != 0) {
1458 Prefix = '+';
1459 }
1460 if ((Flags & COMMA_TYPE) != 0) {
1461 Comma = TRUE;
1462 }
1463 if ((Flags & RADIX_HEX) == 0) {
1464 Radix = 10;
1465 if (Comma) {
1466 Flags &= ~((UINTN) PREFIX_ZERO);
1467 Precision = 1;
1468 }
1469 if (Value < 0) {
1470 Flags |= PREFIX_SIGN;
1471 Prefix = '-';
1472 Value = -Value;
1473 }
1474 } else {
1475 Radix = 16;
1476 Comma = FALSE;
1477 if ((Flags & LONG_TYPE) == 0 && Value < 0) {
1478 //
1479 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
1480 // This assumption is made so the format string definition is compatible with the ANSI C
1481 // Specification for formatted strings. It is recommended that the Base Types be used
1482 // everywhere, but in this one case, compliance with ANSI C is more important, and
1483 // provides an implementation that is compatible with that largest possible set of CPU
1484 // architectures. This is why the type "unsigned int" is used in this one case.
1485 //
1486 Value = (unsigned int)Value;
1487 }
1488 }
1489 //
1490 // Convert Value to a reversed string
1491 //
1492 Count = InternalPrintLibValueToString (ValueBuffer, Value, Radix) - ValueBuffer;
1493 if (Value == 0 && Precision == 0) {
1494 Count = 0;
1495 }
1496 ArgumentString = (CHAR8 *)ValueBuffer + Count;
1497
1498 Digits = Count % 3;
1499 if (Digits != 0) {
1500 Digits = 3 - Digits;
1501 }
1502 if (Comma && Count != 0) {
1503 Count += ((Count - 1) / 3);
1504 }
1505 if (Prefix != 0) {
1506 Count++;
1507 Precision++;
1508 }
1509 Flags |= ARGUMENT_REVERSED;
1510 ZeroPad = TRUE;
1511 if ((Flags & PREFIX_ZERO) != 0) {
1512 if ((Flags & LEFT_JUSTIFY) == 0) {
1513 if ((Flags & PAD_TO_WIDTH) != 0) {
1514 if ((Flags & PRECISION) == 0) {
1515 Precision = Width;
1516 }
1517 }
1518 }
1519 }
1520 break;
1521
1522 case 's':
1523 case 'S':
1524 Flags |= ARGUMENT_UNICODE;
1525 //
1526 // break skipped on purpose
1527 //
1528 case 'a':
1529 if (BaseListMarker == NULL) {
1530 ArgumentString = VA_ARG (VaListMarker, CHAR8 *);
1531 } else {
1532 ArgumentString = BASE_ARG (BaseListMarker, CHAR8 *);
1533 }
1534 if (ArgumentString == NULL) {
1535 Flags &= (~(UINTN)ARGUMENT_UNICODE);
1536 ArgumentString = "<null string>";
1537 }
1538 //
1539 // Set the default precision for string to be zero if not specified.
1540 //
1541 if ((Flags & PRECISION) == 0) {
1542 Precision = 0;
1543 }
1544 break;
1545
1546 case 'c':
1547 if (BaseListMarker == NULL) {
1548 Character = VA_ARG (VaListMarker, UINTN) & 0xffff;
1549 } else {
1550 Character = BASE_ARG (BaseListMarker, UINTN) & 0xffff;
1551 }
1552 ArgumentString = (CHAR8 *)&Character;
1553 Flags |= ARGUMENT_UNICODE;
1554 break;
1555
1556 case 'g':
1557 if (BaseListMarker == NULL) {
1558 TmpGuid = VA_ARG (VaListMarker, GUID *);
1559 } else {
1560 TmpGuid = BASE_ARG (BaseListMarker, GUID *);
1561 }
1562 if (TmpGuid == NULL) {
1563 ArgumentString = "<null guid>";
1564 } else {
1565 GuidData1 = ReadUnaligned32 (&(TmpGuid->Data1));
1566 GuidData2 = ReadUnaligned16 (&(TmpGuid->Data2));
1567 GuidData3 = ReadUnaligned16 (&(TmpGuid->Data3));
1568 InternalPrintLibSPrint (
1569 ValueBuffer,
1570 MAXIMUM_VALUE_CHARACTERS,
1571 0,
1572 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1573 GuidData1,
1574 GuidData2,
1575 GuidData3,
1576 TmpGuid->Data4[0],
1577 TmpGuid->Data4[1],
1578 TmpGuid->Data4[2],
1579 TmpGuid->Data4[3],
1580 TmpGuid->Data4[4],
1581 TmpGuid->Data4[5],
1582 TmpGuid->Data4[6],
1583 TmpGuid->Data4[7]
1584 );
1585 ArgumentString = ValueBuffer;
1586 }
1587 break;
1588
1589 case 't':
1590 if (BaseListMarker == NULL) {
1591 TmpTime = VA_ARG (VaListMarker, TIME *);
1592 } else {
1593 TmpTime = BASE_ARG (BaseListMarker, TIME *);
1594 }
1595 if (TmpTime == NULL) {
1596 ArgumentString = "<null time>";
1597 } else {
1598 InternalPrintLibSPrint (
1599 ValueBuffer,
1600 MAXIMUM_VALUE_CHARACTERS,
1601 0,
1602 "%02d/%02d/%04d %02d:%02d",
1603 TmpTime->Month,
1604 TmpTime->Day,
1605 TmpTime->Year,
1606 TmpTime->Hour,
1607 TmpTime->Minute
1608 );
1609 ArgumentString = ValueBuffer;
1610 }
1611 break;
1612
1613 case 'r':
1614 if (BaseListMarker == NULL) {
1615 Status = VA_ARG (VaListMarker, RETURN_STATUS);
1616 } else {
1617 Status = BASE_ARG (BaseListMarker, RETURN_STATUS);
1618 }
1619 ArgumentString = ValueBuffer;
1620 if (RETURN_ERROR (Status)) {
1621 //
1622 // Clear error bit
1623 //
1624 Index = Status & ~MAX_BIT;
1625 if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {
1626 ArgumentString = mStatusString [Index + WARNING_STATUS_NUMBER];
1627 }
1628 } else {
1629 Index = Status;
1630 if (Index <= WARNING_STATUS_NUMBER) {
1631 ArgumentString = mStatusString [Index];
1632 }
1633 }
1634 if (ArgumentString == ValueBuffer) {
1635 InternalPrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);
1636 }
1637 break;
1638
1639 case '\r':
1640 Format += BytesPerFormatCharacter;
1641 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1642 if (FormatCharacter == '\n') {
1643 //
1644 // Translate '\r\n' to '\r\n'
1645 //
1646 ArgumentString = "\r\n";
1647 } else {
1648 //
1649 // Translate '\r' to '\r'
1650 //
1651 ArgumentString = "\r";
1652 Format -= BytesPerFormatCharacter;
1653 }
1654 break;
1655
1656 case '\n':
1657 //
1658 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1659 //
1660 ArgumentString = "\r\n";
1661 Format += BytesPerFormatCharacter;
1662 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1663 if (FormatCharacter != '\r') {
1664 Format -= BytesPerFormatCharacter;
1665 }
1666 break;
1667
1668 case '%':
1669 default:
1670 //
1671 // if the type is '%' or unknown, then print it to the screen
1672 //
1673 ArgumentString = (CHAR8 *)&FormatCharacter;
1674 Flags |= ARGUMENT_UNICODE;
1675 break;
1676 }
1677 break;
1678
1679 case '\r':
1680 Format += BytesPerFormatCharacter;
1681 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1682 if (FormatCharacter == '\n') {
1683 //
1684 // Translate '\r\n' to '\r\n'
1685 //
1686 ArgumentString = "\r\n";
1687 } else {
1688 //
1689 // Translate '\r' to '\r'
1690 //
1691 ArgumentString = "\r";
1692 Format -= BytesPerFormatCharacter;
1693 }
1694 break;
1695
1696 case '\n':
1697 //
1698 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
1699 //
1700 ArgumentString = "\r\n";
1701 Format += BytesPerFormatCharacter;
1702 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1703 if (FormatCharacter != '\r') {
1704 Format -= BytesPerFormatCharacter;
1705 }
1706 break;
1707
1708 default:
1709 ArgumentString = (CHAR8 *)&FormatCharacter;
1710 Flags |= ARGUMENT_UNICODE;
1711 break;
1712 }
1713
1714 //
1715 // Retrieve the ArgumentString attriubutes
1716 //
1717 if ((Flags & ARGUMENT_UNICODE) != 0) {
1718 ArgumentMask = 0xffff;
1719 BytesPerArgumentCharacter = 2;
1720 } else {
1721 ArgumentMask = 0xff;
1722 BytesPerArgumentCharacter = 1;
1723 }
1724 if ((Flags & ARGUMENT_REVERSED) != 0) {
1725 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;
1726 } else {
1727 //
1728 // Compute the number of characters in ArgumentString and store it in Count
1729 // ArgumentString is either null-terminated, or it contains Precision characters
1730 //
1731 for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {
1732 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
1733 if (ArgumentCharacter == 0) {
1734 break;
1735 }
1736 }
1737 }
1738
1739 if (Precision < Count) {
1740 Precision = Count;
1741 }
1742
1743 //
1744 // Pad before the string
1745 //
1746 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
1747 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
1748 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1749 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
1750 }
1751 }
1752
1753 if (ZeroPad) {
1754 if (Prefix != 0) {
1755 LengthToReturn += (1 * BytesPerOutputCharacter);
1756 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1757 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
1758 }
1759 }
1760 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
1761 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1762 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);
1763 }
1764 } else {
1765 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);
1766 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1767 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);
1768 }
1769 if (Prefix != 0) {
1770 LengthToReturn += (1 * BytesPerOutputCharacter);
1771 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1772 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
1773 }
1774 }
1775 }
1776
1777 //
1778 // Output the Prefix character if it is present
1779 //
1780 Index = 0;
1781 if (Prefix != 0) {
1782 Index++;
1783 }
1784
1785 //
1786 // Copy the string into the output buffer performing the required type conversions
1787 //
1788 while (Index < Count) {
1789 ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
1790
1791 LengthToReturn += (1 * BytesPerOutputCharacter);
1792 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1793 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
1794 }
1795 ArgumentString += BytesPerArgumentCharacter;
1796 Index++;
1797 if (Comma) {
1798 Digits++;
1799 if (Digits == 3) {
1800 Digits = 0;
1801 Index++;
1802 if (Index < Count) {
1803 LengthToReturn += (1 * BytesPerOutputCharacter);
1804 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1805 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);
1806 }
1807 }
1808 }
1809 }
1810 }
1811
1812 //
1813 // Pad after the string
1814 //
1815 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {
1816 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);
1817 if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {
1818 Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
1819 }
1820 }
1821
1822 //
1823 // Get the next character from the format string
1824 //
1825 Format += BytesPerFormatCharacter;
1826
1827 //
1828 // Get the next character from the format string
1829 //
1830 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
1831 }
1832
1833 if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {
1834 return (LengthToReturn / BytesPerOutputCharacter);
1835 }
1836
1837 ASSERT (Buffer != NULL);
1838 //
1839 // Null terminate the Unicode or ASCII string
1840 //
1841 InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);
1842 //
1843 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
1844 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
1845 //
1846 ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));
1847 //
1848 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
1849 // ASCII characters if PcdMaximumAsciiStringLength is not zero.
1850 //
1851 ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));
1852
1853 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
1854 }
1855
1856 /**
1857 Returns the number of characters that would be produced by if the formatted
1858 output were produced not including the Null-terminator.
1859
1860 If FormatString is NULL, then ASSERT().
1861 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
1862
1863 @param[in] FormatString A Null-terminated Unicode format string.
1864 @param[in] Marker VA_LIST marker for the variable argument list.
1865
1866 @return The number of characters that would be produced, not including the
1867 Null-terminator.
1868 **/
1869 UINTN
1870 EFIAPI
1871 SPrintLength (
1872 IN CONST CHAR16 *FormatString,
1873 IN VA_LIST Marker
1874 )
1875 {
1876 ASSERT(FormatString != NULL);
1877 return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);
1878 }
1879
1880 /**
1881 Returns the number of characters that would be produced by if the formatted
1882 output were produced not including the Null-terminator.
1883
1884 If FormatString is NULL, then ASSERT().
1885
1886 @param[in] FormatString A Null-terminated ASCII format string.
1887 @param[in] Marker VA_LIST marker for the variable argument list.
1888
1889 @return The number of characters that would be produced, not including the
1890 Null-terminator.
1891 **/
1892 UINTN
1893 EFIAPI
1894 SPrintLengthAsciiFormat (
1895 IN CONST CHAR8 *FormatString,
1896 IN VA_LIST Marker
1897 )
1898 {
1899 ASSERT(FormatString != NULL);
1900 return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);
1901 }