]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
Add plain-text ReadMe files and delete the PDF version.
[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, 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
22 #include <Protocol/Print2.h>
23
24 #include <Library/PrintLib.h>
25
26 #include <Library/BaseLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/DebugLib.h>
29
30 EFI_PRINT2_PROTOCOL *mPrint2Protocol = NULL;
31
32 /**
33 The constructor function caches the pointer to Print2 protocol.
34
35 The constructor function locates Print2 protocol from protocol database.
36 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
37
38 @param ImageHandle The firmware allocated handle for the EFI image.
39 @param SystemTable A pointer to the EFI System Table.
40
41 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
42
43 **/
44 EFI_STATUS
45 EFIAPI
46 PrintLibConstructor (
47 IN EFI_HANDLE ImageHandle,
48 IN EFI_SYSTEM_TABLE *SystemTable
49 )
50 {
51 EFI_STATUS Status;
52
53 Status = gBS->LocateProtocol (
54 &gEfiPrint2ProtocolGuid,
55 NULL,
56 (VOID**) &mPrint2Protocol
57 );
58 ASSERT_EFI_ERROR (Status);
59 ASSERT (mPrint2Protocol != NULL);
60
61 return Status;
62 }
63
64
65 /**
66 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated
67 format string.
68
69 @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.
70 @param Format Null-terminated format string.
71 @param VaListMarker VA_LIST style variable argument list consumed by processing Format.
72 @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.
73 @param Size The size, in bytes, of the BaseListMarker buffer.
74
75 @return The number of bytes in BaseListMarker. 0 if BaseListMarker is too small.
76
77 **/
78 BOOLEAN
79 DxePrintLibPrint2ProtocolVaListToBaseList (
80 IN BOOLEAN AsciiFormat,
81 IN CONST CHAR8 *Format,
82 IN VA_LIST VaListMarker,
83 OUT BASE_LIST BaseListMarker,
84 IN UINTN Size
85 )
86 {
87 BASE_LIST BaseListStart;
88 UINTN BytesPerFormatCharacter;
89 UINTN FormatMask;
90 UINTN FormatCharacter;
91 BOOLEAN Long;
92 BOOLEAN Done;
93
94 ASSERT (Format != NULL);
95 ASSERT (BaseListMarker != NULL);
96
97 BaseListStart = BaseListMarker;
98
99 if (AsciiFormat) {
100 ASSERT (AsciiStrSize (Format) != 0);
101 BytesPerFormatCharacter = 1;
102 FormatMask = 0xff;
103 } else {
104 ASSERT (StrSize ((CHAR16 *) Format) != 0);
105 BytesPerFormatCharacter = 2;
106 FormatMask = 0xffff;
107 }
108
109 //
110 // Get the first character from the format string
111 //
112 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
113
114 while (FormatCharacter != 0) {
115 if (FormatCharacter == '%') {
116 Long = FALSE;
117
118 //
119 // Parse Flags and Width
120 //
121 for (Done = FALSE; !Done; ) {
122 //
123 // Get the next character from the format string
124 //
125 Format += BytesPerFormatCharacter;
126
127 //
128 // Get the next character from the format string
129 //
130 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
131
132 switch (FormatCharacter) {
133 case '.':
134 case '-':
135 case '+':
136 case ' ':
137 case ',':
138 case '0':
139 case '1':
140 case '2':
141 case '3':
142 case '4':
143 case '5':
144 case '6':
145 case '7':
146 case '8':
147 case '9':
148 break;
149 case 'L':
150 case 'l':
151 Long = TRUE;
152 break;
153 case '*':
154 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
155 break;
156 case '\0':
157 //
158 // Make no output if Format string terminates unexpectedly when
159 // looking up for flag, width, precision and type.
160 //
161 Format -= BytesPerFormatCharacter;
162 //
163 // break skipped on purpose.
164 //
165 default:
166 Done = TRUE;
167 break;
168 }
169 }
170
171 //
172 // Handle each argument type
173 //
174 switch (FormatCharacter) {
175 case 'p':
176 if (sizeof (VOID *) > 4) {
177 Long = TRUE;
178 }
179 case 'X':
180 case 'x':
181 case 'd':
182 if (Long) {
183 BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
184 } else {
185 BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
186 }
187 break;
188 case 's':
189 case 'S':
190 case 'a':
191 case 'g':
192 case 't':
193 BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
194 break;
195 case 'c':
196 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
197 break;
198 case 'r':
199 BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
200 break;
201 }
202 }
203
204 //
205 // If BASE_LIST is larger than Size, then return FALSE
206 //
207 if ((UINTN)((UINT8 *)BaseListMarker - (UINT8 *)BaseListStart) > Size) {
208 return FALSE;
209 }
210
211 //
212 // Get the next character from the format string
213 //
214 Format += BytesPerFormatCharacter;
215
216 //
217 // Get the next character from the format string
218 //
219 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;
220 }
221 return TRUE;
222 }
223
224 /**
225 Produces a Null-terminated Unicode string in an output buffer based on
226 a Null-terminated Unicode format string and a VA_LIST argument list
227
228 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
229 and BufferSize.
230 The Unicode string is produced by parsing the format string specified by FormatString.
231 Arguments are pulled from the variable argument list specified by Marker based on the
232 contents of the format string.
233 The number of Unicode characters in the produced output buffer is returned not including
234 the Null-terminator.
235 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
236
237 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
238 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
239 If BufferSize > 1 and FormatString is NULL, then ASSERT().
240 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
241 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
242 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
243 ASSERT().
244 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
245 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
246 Null-terminator, then ASSERT().
247
248 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
249 Unicode string.
250 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
251 @param FormatString Null-terminated Unicode format string.
252 @param Marker VA_LIST marker for the variable argument list.
253
254 @return The number of Unicode characters in the produced output buffer not including the
255 Null-terminator.
256
257 **/
258 UINTN
259 EFIAPI
260 UnicodeVSPrint (
261 OUT CHAR16 *StartOfBuffer,
262 IN UINTN BufferSize,
263 IN CONST CHAR16 *FormatString,
264 IN VA_LIST Marker
265 )
266 {
267 UINT64 BaseListMarker[256 / sizeof (UINT64)];
268
269 DxePrintLibPrint2ProtocolVaListToBaseList (
270 FALSE,
271 (CHAR8 *)FormatString,
272 Marker,
273 (BASE_LIST)BaseListMarker,
274 sizeof (BaseListMarker) - 8
275 );
276
277 return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
278 }
279
280 /**
281 Produces a Null-terminated Unicode string in an output buffer based on
282 a Null-terminated Unicode format string and a BASE_LIST argument list
283
284 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
285 and BufferSize.
286 The Unicode string is produced by parsing the format string specified by FormatString.
287 Arguments are pulled from the variable argument list specified by Marker based on the
288 contents of the format string.
289 The number of Unicode characters in the produced output buffer is returned not including
290 the Null-terminator.
291 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
292
293 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
294 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
295 If BufferSize > 1 and FormatString is NULL, then ASSERT().
296 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
297 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
298 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
299 ASSERT().
300 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
301 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
302 Null-terminator, then ASSERT().
303
304 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
305 Unicode string.
306 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
307 @param FormatString Null-terminated Unicode format string.
308 @param Marker BASE_LIST marker for the variable argument list.
309
310 @return The number of Unicode characters in the produced output buffer not including the
311 Null-terminator.
312
313 **/
314 UINTN
315 EFIAPI
316 UnicodeBSPrint (
317 OUT CHAR16 *StartOfBuffer,
318 IN UINTN BufferSize,
319 IN CONST CHAR16 *FormatString,
320 IN BASE_LIST Marker
321 )
322 {
323 return mPrint2Protocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
324 }
325
326 /**
327 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
328 Unicode format string and variable argument list.
329
330 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
331 and BufferSize.
332 The Unicode string is produced by parsing the format string specified by FormatString.
333 Arguments are pulled from the variable argument list based on the contents of the format string.
334 The number of Unicode characters in the produced output buffer is returned not including
335 the Null-terminator.
336 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
337
338 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
339 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
340 If BufferSize > 1 and FormatString is NULL, then ASSERT().
341 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
342 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
343 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
344 ASSERT().
345 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
346 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
347 Null-terminator, then ASSERT().
348
349 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
350 Unicode string.
351 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
352 @param FormatString Null-terminated Unicode format string.
353 @param ... Variable argument list whose contents are accessed based on the
354 format string specified by FormatString.
355
356 @return The number of Unicode characters in the produced output buffer not including the
357 Null-terminator.
358
359 **/
360 UINTN
361 EFIAPI
362 UnicodeSPrint (
363 OUT CHAR16 *StartOfBuffer,
364 IN UINTN BufferSize,
365 IN CONST CHAR16 *FormatString,
366 ...
367 )
368 {
369 VA_LIST Marker;
370
371 VA_START (Marker, FormatString);
372 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
373 }
374
375 /**
376 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
377 ASCII format string and a VA_LIST argument list
378
379 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
380 and BufferSize.
381 The Unicode string is produced by parsing the format string specified by FormatString.
382 Arguments are pulled from the variable argument list specified by Marker based on the
383 contents of the format string.
384 The number of Unicode characters in the produced output buffer is returned not including
385 the Null-terminator.
386 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
387
388 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
389 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
390 If BufferSize > 1 and FormatString is NULL, then ASSERT().
391 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
392 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
393 ASSERT().
394 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
395 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
396 Null-terminator, then ASSERT().
397
398 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
399 Unicode string.
400 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
401 @param FormatString Null-terminated Unicode format string.
402 @param Marker VA_LIST marker for the variable argument list.
403
404 @return The number of Unicode characters in the produced output buffer not including the
405 Null-terminator.
406
407 **/
408 UINTN
409 EFIAPI
410 UnicodeVSPrintAsciiFormat (
411 OUT CHAR16 *StartOfBuffer,
412 IN UINTN BufferSize,
413 IN CONST CHAR8 *FormatString,
414 IN VA_LIST Marker
415 )
416 {
417 UINT64 BaseListMarker[256 / sizeof (UINT64)];
418
419 DxePrintLibPrint2ProtocolVaListToBaseList (
420 TRUE,
421 FormatString,
422 Marker,
423 (BASE_LIST)BaseListMarker,
424 sizeof (BaseListMarker) - 8
425 );
426
427 return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
428 }
429
430 /**
431 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
432 ASCII format string and a BASE_LIST argument list
433
434 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
435 and BufferSize.
436 The Unicode string is produced by parsing the format string specified by FormatString.
437 Arguments are pulled from the variable argument list specified by Marker based on the
438 contents of the format string.
439 The number of Unicode characters in the produced output buffer is returned not including
440 the Null-terminator.
441 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
442
443 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
444 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
445 If BufferSize > 1 and FormatString is NULL, then ASSERT().
446 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
447 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
448 ASSERT().
449 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
450 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
451 Null-terminator, then ASSERT().
452
453 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
454 Unicode string.
455 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
456 @param FormatString Null-terminated Unicode format string.
457 @param Marker BASE_LIST marker for the variable argument list.
458
459 @return The number of Unicode characters in the produced output buffer not including the
460 Null-terminator.
461
462 **/
463 UINTN
464 EFIAPI
465 UnicodeBSPrintAsciiFormat (
466 OUT CHAR16 *StartOfBuffer,
467 IN UINTN BufferSize,
468 IN CONST CHAR8 *FormatString,
469 IN BASE_LIST Marker
470 )
471 {
472 return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
473 }
474
475 /**
476 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
477 ASCII format string and variable argument list.
478
479 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
480 and BufferSize.
481 The Unicode string is produced by parsing the format string specified by FormatString.
482 Arguments are pulled from the variable argument list based on the contents of the
483 format string.
484 The number of Unicode characters in the produced output buffer is returned not including
485 the Null-terminator.
486 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
487
488 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
489 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
490 If BufferSize > 1 and FormatString is NULL, then ASSERT().
491 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
492 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
493 ASSERT().
494 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
495 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
496 Null-terminator, then ASSERT().
497
498 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
499 Unicode string.
500 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
501 @param FormatString Null-terminated Unicode format string.
502 @param ... Variable argument list whose contents are accessed based on the
503 format string specified by FormatString.
504
505 @return The number of Unicode characters in the produced output buffer not including the
506 Null-terminator.
507
508 **/
509 UINTN
510 EFIAPI
511 UnicodeSPrintAsciiFormat (
512 OUT CHAR16 *StartOfBuffer,
513 IN UINTN BufferSize,
514 IN CONST CHAR8 *FormatString,
515 ...
516 )
517 {
518 VA_LIST Marker;
519
520 VA_START (Marker, FormatString);
521 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
522 }
523
524 /**
525 Converts a decimal value to a Null-terminated Unicode string.
526
527 Converts the decimal number specified by Value to a Null-terminated Unicode
528 string specified by Buffer containing at most Width characters. No padding of spaces
529 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
530 The number of Unicode characters in Buffer is returned not including the Null-terminator.
531 If the conversion contains more than Width characters, then only the first
532 Width characters are returned, and the total number of characters
533 required to perform the conversion is returned.
534 Additional conversion parameters are specified in Flags.
535
536 The Flags bit LEFT_JUSTIFY is always ignored.
537 All conversions are left justified in Buffer.
538 If Width is 0, PREFIX_ZERO is ignored in Flags.
539 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
540 are inserted every 3rd digit starting from the right.
541 If RADIX_HEX is set in Flags, then the output buffer will be
542 formatted in hexadecimal format.
543 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
544 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
545 then Buffer is padded with '0' characters so the combination of the optional '-'
546 sign character, '0' characters, digit characters for Value, and the Null-terminator
547 add up to Width characters.
548 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
549 If Buffer is NULL, then ASSERT().
550 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
551 If unsupported bits are set in Flags, then ASSERT().
552 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
553 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
554
555 @param Buffer Pointer to the output buffer for the produced Null-terminated
556 Unicode string.
557 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
558 @param Value The 64-bit signed value to convert to a string.
559 @param Width The maximum number of Unicode characters to place in Buffer, not including
560 the Null-terminator.
561
562 @return The number of Unicode characters in Buffer not including the Null-terminator.
563
564 **/
565 UINTN
566 EFIAPI
567 UnicodeValueToString (
568 IN OUT CHAR16 *Buffer,
569 IN UINTN Flags,
570 IN INT64 Value,
571 IN UINTN Width
572 )
573 {
574 return mPrint2Protocol->UnicodeValueToString (Buffer, Flags, Value, Width);
575 }
576
577 /**
578 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
579 ASCII format string and a VA_LIST argument list.
580
581 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
582 and BufferSize.
583 The ASCII string is produced by parsing the format string specified by FormatString.
584 Arguments are pulled from the variable argument list specified by Marker based on
585 the contents of the format string.
586 The number of ASCII characters in the produced output buffer is returned not including
587 the Null-terminator.
588 If BufferSize is 0, then no output buffer is produced and 0 is returned.
589
590 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
591 If BufferSize > 0 and FormatString is NULL, then ASSERT().
592 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
593 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
594 ASSERT().
595 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
596 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
597 Null-terminator, then ASSERT().
598
599 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
600 ASCII string.
601 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
602 @param FormatString Null-terminated Unicode format string.
603 @param Marker VA_LIST marker for the variable argument list.
604
605 @return The number of ASCII characters in the produced output buffer not including the
606 Null-terminator.
607
608 **/
609 UINTN
610 EFIAPI
611 AsciiVSPrint (
612 OUT CHAR8 *StartOfBuffer,
613 IN UINTN BufferSize,
614 IN CONST CHAR8 *FormatString,
615 IN VA_LIST Marker
616 )
617 {
618 UINT64 BaseListMarker[256 / sizeof (UINT64)];
619
620 DxePrintLibPrint2ProtocolVaListToBaseList (
621 TRUE,
622 FormatString,
623 Marker,
624 (BASE_LIST)BaseListMarker,
625 sizeof (BaseListMarker) - 8
626 );
627
628 return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
629 }
630
631 /**
632 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
633 ASCII format string and a BASE_LIST argument list.
634
635 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
636 and BufferSize.
637 The ASCII string is produced by parsing the format string specified by FormatString.
638 Arguments are pulled from the variable argument list specified by Marker based on
639 the contents of the format string.
640 The number of ASCII characters in the produced output buffer is returned not including
641 the Null-terminator.
642 If BufferSize is 0, then no output buffer is produced and 0 is returned.
643
644 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
645 If BufferSize > 0 and FormatString is NULL, then ASSERT().
646 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
647 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
648 ASSERT().
649 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
650 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
651 Null-terminator, then ASSERT().
652
653 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
654 ASCII string.
655 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
656 @param FormatString Null-terminated Unicode format string.
657 @param Marker BASE_LIST marker for the variable argument list.
658
659 @return The number of ASCII characters in the produced output buffer not including the
660 Null-terminator.
661
662 **/
663 UINTN
664 EFIAPI
665 AsciiBSPrint (
666 OUT CHAR8 *StartOfBuffer,
667 IN UINTN BufferSize,
668 IN CONST CHAR8 *FormatString,
669 IN BASE_LIST Marker
670 )
671 {
672 return mPrint2Protocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
673 }
674
675 /**
676 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
677 ASCII format string and variable argument list.
678
679 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
680 and BufferSize.
681 The ASCII string is produced by parsing the format string specified by FormatString.
682 Arguments are pulled from the variable argument list based on the contents of the
683 format string.
684 The number of ASCII characters in the produced output buffer is returned not including
685 the Null-terminator.
686 If BufferSize is 0, then no output buffer is produced and 0 is returned.
687
688 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
689 If BufferSize > 0 and FormatString is NULL, then ASSERT().
690 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
691 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
692 ASSERT().
693 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
694 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
695 Null-terminator, then ASSERT().
696
697 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
698 ASCII string.
699 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
700 @param FormatString Null-terminated Unicode format string.
701 @param ... Variable argument list whose contents are accessed based on the
702 format string specified by FormatString.
703
704 @return The number of ASCII characters in the produced output buffer not including the
705 Null-terminator.
706
707 **/
708 UINTN
709 EFIAPI
710 AsciiSPrint (
711 OUT CHAR8 *StartOfBuffer,
712 IN UINTN BufferSize,
713 IN CONST CHAR8 *FormatString,
714 ...
715 )
716 {
717 VA_LIST Marker;
718
719 VA_START (Marker, FormatString);
720 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
721 }
722
723 /**
724 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
725 ASCII format string and a VA_LIST argument list.
726
727 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
728 and BufferSize.
729 The ASCII string is produced by parsing the format string specified by FormatString.
730 Arguments are pulled from the variable argument list specified by Marker based on
731 the contents of the format string.
732 The number of ASCII characters in the produced output buffer is returned not including
733 the Null-terminator.
734 If BufferSize is 0, then no output buffer is produced and 0 is returned.
735
736 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
737 If BufferSize > 0 and FormatString is NULL, then ASSERT().
738 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
739 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
740 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
741 ASSERT().
742 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
743 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
744 Null-terminator, then ASSERT().
745
746 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
747 ASCII string.
748 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
749 @param FormatString Null-terminated Unicode format string.
750 @param Marker VA_LIST marker for the variable argument list.
751
752 @return The number of ASCII characters in the produced output buffer not including the
753 Null-terminator.
754
755 **/
756 UINTN
757 EFIAPI
758 AsciiVSPrintUnicodeFormat (
759 OUT CHAR8 *StartOfBuffer,
760 IN UINTN BufferSize,
761 IN CONST CHAR16 *FormatString,
762 IN VA_LIST Marker
763 )
764 {
765 UINT64 BaseListMarker[256 / sizeof (UINT64)];
766
767 DxePrintLibPrint2ProtocolVaListToBaseList (
768 FALSE,
769 (CHAR8 *)FormatString,
770 Marker,
771 (BASE_LIST)BaseListMarker,
772 sizeof (BaseListMarker) - 8
773 );
774
775 return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);
776 }
777
778 /**
779 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
780 ASCII format string and a BASE_LIST argument list.
781
782 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
783 and BufferSize.
784 The ASCII string is produced by parsing the format string specified by FormatString.
785 Arguments are pulled from the variable argument list specified by Marker based on
786 the contents of the format string.
787 The number of ASCII characters in the produced output buffer is returned not including
788 the Null-terminator.
789 If BufferSize is 0, then no output buffer is produced and 0 is returned.
790
791 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
792 If BufferSize > 0 and FormatString is NULL, then ASSERT().
793 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
794 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
795 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
796 ASSERT().
797 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
798 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
799 Null-terminator, then ASSERT().
800
801 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
802 ASCII string.
803 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
804 @param FormatString Null-terminated Unicode format string.
805 @param Marker BASE_LIST marker for the variable argument list.
806
807 @return The number of ASCII characters in the produced output buffer not including the
808 Null-terminator.
809
810 **/
811 UINTN
812 EFIAPI
813 AsciiBSPrintUnicodeFormat (
814 OUT CHAR8 *StartOfBuffer,
815 IN UINTN BufferSize,
816 IN CONST CHAR16 *FormatString,
817 IN BASE_LIST Marker
818 )
819 {
820 return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
821 }
822
823 /**
824 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
825 ASCII format string and variable argument list.
826
827 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
828 and BufferSize.
829 The ASCII string is produced by parsing the format string specified by FormatString.
830 Arguments are pulled from the variable argument list based on the contents of the
831 format string.
832 The number of ASCII characters in the produced output buffer is returned not including
833 the Null-terminator.
834 If BufferSize is 0, then no output buffer is produced and 0 is returned.
835
836 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
837 If BufferSize > 0 and FormatString is NULL, then ASSERT().
838 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
839 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
840 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
841 ASSERT().
842 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
843 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
844 Null-terminator, then ASSERT().
845
846 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
847 ASCII string.
848 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
849 @param FormatString Null-terminated Unicode format string.
850 @param ... Variable argument list whose contents are accessed based on the
851 format string specified by FormatString.
852
853 @return The number of ASCII characters in the produced output buffer not including the
854 Null-terminator.
855
856 **/
857 UINTN
858 EFIAPI
859 AsciiSPrintUnicodeFormat (
860 OUT CHAR8 *StartOfBuffer,
861 IN UINTN BufferSize,
862 IN CONST CHAR16 *FormatString,
863 ...
864 )
865 {
866 VA_LIST Marker;
867
868 VA_START (Marker, FormatString);
869 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
870 }
871
872
873 /**
874 Converts a decimal value to a Null-terminated ASCII string.
875
876 Converts the decimal number specified by Value to a Null-terminated ASCII string
877 specified by Buffer containing at most Width characters. No padding of spaces
878 is ever performed.
879 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
880 The number of ASCII characters in Buffer is returned not including the Null-terminator.
881 If the conversion contains more than Width characters, then only the first Width
882 characters are returned, and the total number of characters required to perform
883 the conversion is returned.
884 Additional conversion parameters are specified in Flags.
885 The Flags bit LEFT_JUSTIFY is always ignored.
886 All conversions are left justified in Buffer.
887 If Width is 0, PREFIX_ZERO is ignored in Flags.
888 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
889 are inserted every 3rd digit starting from the right.
890 If RADIX_HEX is set in Flags, then the output buffer will be
891 formatted in hexadecimal format.
892 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
893 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
894 then Buffer is padded with '0' characters so the combination of the optional '-'
895 sign character, '0' characters, digit characters for Value, and the Null-terminator
896 add up to Width characters.
897
898 If Buffer is NULL, then ASSERT().
899 If unsupported bits are set in Flags, then ASSERT().
900 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
901 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
902
903 @param Buffer Pointer to the output buffer for the produced Null-terminated
904 ASCII string.
905 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
906 @param Value The 64-bit signed value to convert to a string.
907 @param Width The maximum number of ASCII characters to place in Buffer, not including
908 the Null-terminator.
909
910 @return The number of ASCII characters in Buffer not including the Null-terminator.
911
912 **/
913 UINTN
914 EFIAPI
915 AsciiValueToString (
916 OUT CHAR8 *Buffer,
917 IN UINTN Flags,
918 IN INT64 Value,
919 IN UINTN Width
920 )
921 {
922 return mPrint2Protocol->AsciiValueToString (Buffer, Flags, Value, Width);
923 }