1.Fix SetMem64.S to not use SSE3 instruction
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLib.c
1 /** @file
2 Print Library.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: PrintLib.c
14
15 **/
16
17 #include "PrintLibInternal.h"
18
19 #define WARNING_STATUS_NUMBER 4
20 #define ERROR_STATUS_NUMBER 24
21
22 STATIC CONST CHAR8 *StatusString [] = {
23 "Success", // RETURN_SUCCESS = 0
24 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
25 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
26 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
27 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
28 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
29 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
30 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
31 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
32 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
33 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
34 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
35 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
36 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
37 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
38 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
39 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
40 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
41 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
42 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
43 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
44 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
45 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
46 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
47 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
48 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
49 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
50 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
51 "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
52 };
53
54 /**
55 Worker function that produces a Null-terminated string in an output buffer
56 based on a Null-terminated format string and a VA_LIST argument list.
57
58 VSPrint function to process format and place the results in Buffer. Since a
59 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
60 this is the main print working routine.
61
62 @param Buffer Character buffer to print the results of the parsing
63 of Format into.
64 @param BufferSize Maximum number of characters to put into buffer.
65 @param Flags Intial flags value.
66 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set.
67 @param Format Null-terminated format string.
68 @param Marker Vararg list consumed by processing Format.
69
70 @return Number of characters printed not including the Null-terminator.
71
72 **/
73 UINTN
74 BasePrintLibVSPrint (
75 OUT CHAR8 *Buffer,
76 IN UINTN BufferSize,
77 IN UINTN Flags,
78 IN CONST CHAR8 *Format,
79 IN VA_LIST Marker
80 )
81 {
82 CHAR8 *OriginalBuffer;
83 CHAR8 *EndBuffer;
84 CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];
85 UINTN BytesPerOutputCharacter;
86 UINTN BytesPerFormatCharacter;
87 UINTN FormatMask;
88 UINTN FormatCharacter;
89 UINTN Width;
90 UINTN Precision;
91 INT64 Value;
92 CONST CHAR8 *ArgumentString;
93 UINTN Character;
94 GUID *TmpGuid;
95 TIME *TmpTime;
96 UINTN Count;
97 UINTN ArgumentMask;
98 INTN BytesPerArgumentCharacter;
99 UINTN ArgumentCharacter;
100 BOOLEAN Done;
101 UINTN Index;
102 CHAR8 Prefix;
103 BOOLEAN ZeroPad;
104 BOOLEAN Comma;
105 UINTN Digits;
106 UINTN Radix;
107 RETURN_STATUS Status;
108
109 if (BufferSize == 0) {
110 return 0;
111 }
112 ASSERT (Buffer != NULL);
113
114 if ((Flags & OUTPUT_UNICODE) != 0) {
115 BytesPerOutputCharacter = 2;
116 } else {
117 BytesPerOutputCharacter = 1;
118 }
119
120 //
121 // Reserve space for the Null terminator.
122 //
123 BufferSize--;
124 OriginalBuffer = Buffer;
125 //
126 // Set the tag for the end of the input Buffer.
127 //
128 EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;
129
130 if ((Flags & FORMAT_UNICODE) != 0) {
131 //
132 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
133 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
134 //
135 ASSERT (StrSize ((CHAR16 *) Format) != 0);
136 BytesPerFormatCharacter = 2;
137 FormatMask = 0xffff;
138 } else {
139 //
140 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
141 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
142 //
143 ASSERT (AsciiStrSize (Format) != 0);
144 BytesPerFormatCharacter = 1;
145 FormatMask = 0xff;
146 }
147
148
149
150 //
151 // Get the first character from the format string
152 //
153 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
154
155 //
156 // Loop until the end of the format string is reached or the output buffer is full
157 //
158 while (FormatCharacter != 0 && Buffer < EndBuffer) {
159 //
160 // Clear all the flag bits except those that may have been passed in
161 //
162 Flags &= (OUTPUT_UNICODE | FORMAT_UNICODE);
163
164 //
165 // Set the default width to zero, and the default precision to 1
166 //
167 Width = 0;
168 Precision = 1;
169 Prefix = 0;
170 Comma = FALSE;
171 ZeroPad = FALSE;
172 Count = 0;
173 Digits = 0;
174
175 switch (FormatCharacter) {
176 case '%':
177 //
178 // Parse Flags and Width
179 //
180 for (Done = FALSE; !Done; ) {
181 Format += BytesPerFormatCharacter;
182 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
183 switch (FormatCharacter) {
184 case '.':
185 Flags |= PRECISION;
186 break;
187 case '-':
188 Flags |= LEFT_JUSTIFY;
189 break;
190 case '+':
191 Flags |= PREFIX_SIGN;
192 break;
193 case ' ':
194 Flags |= PREFIX_BLANK;
195 break;
196 case ',':
197 Flags |= COMMA_TYPE;
198 break;
199 case 'L':
200 case 'l':
201 Flags |= LONG_TYPE;
202 break;
203 case '*':
204 if ((Flags & PRECISION) == 0) {
205 Flags |= PAD_TO_WIDTH;
206 Width = VA_ARG (Marker, UINTN);
207 } else {
208 Precision = VA_ARG (Marker, UINTN);
209 }
210 break;
211 case '0':
212 if ((Flags & PRECISION) == 0) {
213 Flags |= PREFIX_ZERO;
214 }
215 case '1':
216 case '2':
217 case '3':
218 case '4':
219 case '5':
220 case '6':
221 case '7':
222 case '8':
223 case '9':
224 for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){
225 Count = (Count * 10) + FormatCharacter - '0';
226 Format += BytesPerFormatCharacter;
227 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
228 }
229 Format -= BytesPerFormatCharacter;
230 if ((Flags & PRECISION) == 0) {
231 Flags |= PAD_TO_WIDTH;
232 Width = Count;
233 } else {
234 Precision = Count;
235 }
236 break;
237
238 case '\0':
239 //
240 // Make no output if Format string terminates unexpectedly when
241 // looking up for flag, width, precision and type.
242 //
243 Format -= BytesPerFormatCharacter;
244 Precision = 0;
245 //
246 // break skipped on purpose.
247 //
248 default:
249 Done = TRUE;
250 break;
251 }
252 }
253
254 //
255 // Handle each argument type
256 //
257 switch (FormatCharacter) {
258 case 'p':
259 //
260 // Flag space, +, 0, L & l are invalid for type p.
261 //
262 Flags &= ~(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE);
263 if (sizeof (VOID *) > 4) {
264 Flags |= LONG_TYPE;
265 }
266 case 'X':
267 Flags |= PREFIX_ZERO;
268 //
269 // break skipped on purpose
270 //
271 case 'x':
272 Flags |= RADIX_HEX;
273 //
274 // break skipped on purpose
275 //
276 case 'd':
277 if ((Flags & LONG_TYPE) == 0) {
278 Value = (VA_ARG (Marker, int));
279 } else {
280 Value = VA_ARG (Marker, INT64);
281 }
282 if ((Flags & PREFIX_BLANK) != 0) {
283 Prefix = ' ';
284 }
285 if ((Flags & PREFIX_SIGN) != 0) {
286 Prefix = '+';
287 }
288 if ((Flags & COMMA_TYPE) != 0) {
289 Comma = TRUE;
290 }
291 if ((Flags & RADIX_HEX) == 0) {
292 Radix = 10;
293 if (Comma) {
294 Flags &= (~PREFIX_ZERO);
295 Precision = 1;
296 }
297 if (Value < 0) {
298 Flags |= PREFIX_SIGN;
299 Prefix = '-';
300 Value = -Value;
301 }
302 } else {
303 Radix = 16;
304 Comma = FALSE;
305 if ((Flags & LONG_TYPE) == 0 && Value < 0) {
306 Value = (unsigned int)Value;
307 }
308 }
309 //
310 // Convert Value to a reversed string
311 //
312 Count = BasePrintLibValueToString (ValueBuffer, Value, Radix);
313 if (Value == 0 && Precision == 0) {
314 Count = 0;
315 }
316 ArgumentString = (CHAR8 *)ValueBuffer + Count;
317
318 Digits = Count % 3;
319 if (Digits != 0) {
320 Digits = 3 - Digits;
321 }
322 if (Comma && Count != 0) {
323 Count += ((Count - 1) / 3);
324 }
325 if (Prefix != 0) {
326 Count++;
327 Precision++;
328 }
329 Flags |= ARGUMENT_REVERSED;
330 ZeroPad = TRUE;
331 if ((Flags & PREFIX_ZERO) != 0) {
332 if ((Flags & LEFT_JUSTIFY) == 0) {
333 if ((Flags & PAD_TO_WIDTH) != 0) {
334 if ((Flags & PRECISION) == 0) {
335 Precision = Width;
336 }
337 }
338 }
339 }
340 break;
341
342 case 's':
343 case 'S':
344 Flags |= ARGUMENT_UNICODE;
345 //
346 // break skipped on purpose
347 //
348 case 'a':
349 ArgumentString = (CHAR8 *)VA_ARG (Marker, CHAR8 *);
350 if (ArgumentString == NULL) {
351 Flags &= (~ARGUMENT_UNICODE);
352 ArgumentString = "<null string>";
353 }
354 break;
355
356 case 'c':
357 Character = VA_ARG (Marker, UINTN) & 0xffff;
358 ArgumentString = (CHAR8 *)&Character;
359 Flags |= ARGUMENT_UNICODE;
360 break;
361
362 case 'g':
363 TmpGuid = VA_ARG (Marker, GUID *);
364 if (TmpGuid == NULL) {
365 ArgumentString = "<null guid>";
366 } else {
367 BasePrintLibSPrint (
368 ValueBuffer,
369 MAXIMUM_VALUE_CHARACTERS,
370 0,
371 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
372 TmpGuid->Data1,
373 TmpGuid->Data2,
374 TmpGuid->Data3,
375 TmpGuid->Data4[0],
376 TmpGuid->Data4[1],
377 TmpGuid->Data4[2],
378 TmpGuid->Data4[3],
379 TmpGuid->Data4[4],
380 TmpGuid->Data4[5],
381 TmpGuid->Data4[6],
382 TmpGuid->Data4[7]
383 );
384 ArgumentString = ValueBuffer;
385 }
386 break;
387
388 case 't':
389 TmpTime = VA_ARG (Marker, TIME *);
390 if (TmpTime == NULL) {
391 ArgumentString = "<null time>";
392 } else {
393 BasePrintLibSPrint (
394 ValueBuffer,
395 MAXIMUM_VALUE_CHARACTERS,
396 0,
397 "%02d/%02d/%04d %02d:%02d",
398 TmpTime->Month,
399 TmpTime->Day,
400 TmpTime->Year,
401 TmpTime->Hour,
402 TmpTime->Minute
403 );
404 ArgumentString = ValueBuffer;
405 }
406 break;
407
408 case 'r':
409 Status = VA_ARG (Marker, RETURN_STATUS);
410 ArgumentString = ValueBuffer;
411 if (RETURN_ERROR (Status)) {
412 //
413 // Clear error bit
414 //
415 Index = Status & ~MAX_BIT;
416 if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {
417 ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER];
418 }
419 } else {
420 Index = Status;
421 if (Index <= WARNING_STATUS_NUMBER) {
422 ArgumentString = StatusString [Index];
423 }
424 }
425 if (ArgumentString == ValueBuffer) {
426 BasePrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);
427 }
428 break;
429
430 case '\n':
431 ArgumentString = "\n\r";
432 break;
433
434 case '%':
435 default:
436 //
437 // if the type is '%' or unknown, then print it to the screen
438 //
439 ArgumentString = (CHAR8 *)&FormatCharacter;
440 Flags |= ARGUMENT_UNICODE;
441 break;
442 }
443 break;
444
445 case '\n':
446 ArgumentString = "\n\r";
447 break;
448
449 default:
450 ArgumentString = (CHAR8 *)&FormatCharacter;
451 Flags |= ARGUMENT_UNICODE;
452 break;
453 }
454
455 //
456 // Retrieve the ArgumentString attriubutes
457 //
458 if ((Flags & ARGUMENT_UNICODE) != 0) {
459 ArgumentMask = 0xffff;
460 BytesPerArgumentCharacter = 2;
461 } else {
462 ArgumentMask = 0xff;
463 BytesPerArgumentCharacter = 1;
464 }
465 if ((Flags & ARGUMENT_REVERSED) != 0) {
466 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;
467 } else {
468 //
469 // Compute the number of characters in ArgumentString and store it in Count
470 // ArgumentString is either null-terminated, or it contains Precision characters
471 //
472 for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {
473 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
474 if (ArgumentCharacter == 0) {
475 break;
476 }
477 }
478 }
479
480 if (Precision < Count) {
481 Precision = Count;
482 }
483
484 //
485 // Pad before the string
486 //
487 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
488 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
489 }
490
491 if (ZeroPad) {
492 if (Prefix != 0) {
493 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
494 }
495 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);
496 } else {
497 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);
498 if (Prefix != 0) {
499 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);
500 }
501 }
502
503 //
504 // Output the Prefix character if it is present
505 //
506 Index = 0;
507 if (Prefix != 0) {
508 Index++;
509 }
510
511 //
512 // Copy the string into the output buffer performing the required type conversions
513 //
514 while (Index < Count) {
515 ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
516
517 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
518 ArgumentString += BytesPerArgumentCharacter;
519 Index++;
520 if (Comma) {
521 Digits++;
522 if (Digits == 3) {
523 Digits = 0;
524 Index++;
525 if (Index < Count) {
526 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);
527 }
528 }
529 }
530 }
531
532 //
533 // Pad after the string
534 //
535 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {
536 Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);
537 }
538
539 //
540 // Get the next character from the format string
541 //
542 Format += BytesPerFormatCharacter;
543
544 //
545 // Get the next character from the format string
546 //
547 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
548 }
549
550 //
551 // Null terminate the Unicode or ASCII string
552 //
553 BasePrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);
554 //
555 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
556 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
557 //
558 ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));
559 //
560 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
561 // ASCII characters if PcdMaximumAsciiStringLength is not zero.
562 //
563 ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));
564
565 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
566 }
567
568 /**
569 Worker function that produces a Null-terminated string in an output buffer
570 based on a Null-terminated format string and variable argument list.
571
572 VSPrint function to process format and place the results in Buffer. Since a
573 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
574 this is the main print working routine.
575
576 @param Buffer Character buffer to print the results of the parsing
577 of Format into.
578 @param BufferSize Maximum number of characters to put into buffer.
579 Zero means no limit.
580 @param Flags Intial flags value.
581 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
582 @param FormatString Null-terminated format string.
583
584 @return Number of characters printed not including the Null-terminator.
585
586 **/
587 UINTN
588 BasePrintLibSPrint (
589 OUT CHAR8 *StartOfBuffer,
590 IN UINTN BufferSize,
591 IN UINTN Flags,
592 IN CONST CHAR8 *FormatString,
593 ...
594 )
595 {
596 VA_LIST Marker;
597
598 VA_START (Marker, FormatString);
599 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, Flags, FormatString, Marker);
600 }
601
602 /**
603 Produces a Null-terminated Unicode string in an output buffer based on
604 a Null-terminated Unicode format string and a VA_LIST argument list
605
606 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
607 and BufferSize.
608 The Unicode string is produced by parsing the format string specified by FormatString.
609 Arguments are pulled from the variable argument list specified by Marker based on the
610 contents of the format string.
611 The number of Unicode characters in the produced output buffer is returned not including
612 the Null-terminator.
613 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
614
615 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
616 If BufferSize > 1 and FormatString is NULL, then ASSERT().
617 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
618 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
619 ASSERT().
620 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
621 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
622 Null-terminator, then ASSERT().
623
624 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
625 Unicode string.
626 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
627 @param FormatString Null-terminated Unicode format string.
628 @param Marker VA_LIST marker for the variable argument list.
629
630 @return The number of Unicode characters in the produced output buffer not including the
631 Null-terminator.
632
633 **/
634 UINTN
635 EFIAPI
636 UnicodeVSPrint (
637 OUT CHAR16 *StartOfBuffer,
638 IN UINTN BufferSize,
639 IN CONST CHAR16 *FormatString,
640 IN VA_LIST Marker
641 )
642 {
643 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker);
644 }
645
646 /**
647 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
648 Unicode format string and variable argument list.
649
650 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
651 and BufferSize.
652 The Unicode string is produced by parsing the format string specified by FormatString.
653 Arguments are pulled from the variable argument list based on the contents of the format string.
654 The number of Unicode characters in the produced output buffer is returned not including
655 the Null-terminator.
656 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
657
658 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
659 If BufferSize > 1 and FormatString is NULL, then ASSERT().
660 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
661 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
662 ASSERT().
663 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
664 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
665 Null-terminator, then ASSERT().
666
667 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
668 Unicode string.
669 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
670 @param FormatString Null-terminated Unicode format string.
671
672 @return The number of Unicode characters in the produced output buffer not including the
673 Null-terminator.
674
675 **/
676 UINTN
677 EFIAPI
678 UnicodeSPrint (
679 OUT CHAR16 *StartOfBuffer,
680 IN UINTN BufferSize,
681 IN CONST CHAR16 *FormatString,
682 ...
683 )
684 {
685 VA_LIST Marker;
686
687 VA_START (Marker, FormatString);
688 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
689 }
690
691 /**
692 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
693 ASCII format string and a VA_LIST argument list
694
695 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
696 and BufferSize.
697 The Unicode string is produced by parsing the format string specified by FormatString.
698 Arguments are pulled from the variable argument list specified by Marker based on the
699 contents of the format string.
700 The number of Unicode characters in the produced output buffer is returned not including
701 the Null-terminator.
702 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
703
704 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
705 If BufferSize > 1 and FormatString is NULL, then ASSERT().
706 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
707 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
708 ASSERT().
709 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
710 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
711 Null-terminator, then ASSERT().
712
713 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
714 Unicode string.
715 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
716 @param FormatString Null-terminated Unicode format string.
717 @param Marker VA_LIST marker for the variable argument list.
718
719 @return The number of Unicode characters in the produced output buffer not including the
720 Null-terminator.
721
722 **/
723 UINTN
724 EFIAPI
725 UnicodeVSPrintAsciiFormat (
726 OUT CHAR16 *StartOfBuffer,
727 IN UINTN BufferSize,
728 IN CONST CHAR8 *FormatString,
729 IN VA_LIST Marker
730 )
731 {
732 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE,FormatString, Marker);
733 }
734
735 /**
736 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
737 ASCII format string and variable argument list.
738
739 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
740 and BufferSize.
741 The Unicode string is produced by parsing the format string specified by FormatString.
742 Arguments are pulled from the variable argument list based on the contents of the
743 format string.
744 The number of Unicode characters in the produced output buffer is returned not including
745 the Null-terminator.
746 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
747
748 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
749 If BufferSize > 1 and FormatString is NULL, then ASSERT().
750 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
751 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
752 ASSERT().
753 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
754 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
755 Null-terminator, then ASSERT().
756
757 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
758 Unicode string.
759 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
760 @param FormatString Null-terminated Unicode format string.
761
762 @return The number of Unicode characters in the produced output buffer not including the
763 Null-terminator.
764
765 **/
766 UINTN
767 EFIAPI
768 UnicodeSPrintAsciiFormat (
769 OUT CHAR16 *StartOfBuffer,
770 IN UINTN BufferSize,
771 IN CONST CHAR8 *FormatString,
772 ...
773 )
774 {
775 VA_LIST Marker;
776
777 VA_START (Marker, FormatString);
778 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
779 }
780
781 /**
782 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
783 ASCII format string and a VA_LIST argument list.
784
785 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
786 and BufferSize.
787 The ASCII string is produced by parsing the format string specified by FormatString.
788 Arguments are pulled from the variable argument list specified by Marker based on
789 the contents of the format string.
790 The number of ASCII characters in the produced output buffer is returned not including
791 the Null-terminator.
792 If BufferSize is 0, then no output buffer is produced and 0 is returned.
793
794 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
795 If BufferSize > 0 and FormatString is NULL, then ASSERT().
796 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
797 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
798 ASSERT().
799 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
800 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
801 Null-terminator, then ASSERT().
802
803 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
804 ASCII string.
805 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
806 @param FormatString Null-terminated Unicode format string.
807 @param Marker VA_LIST marker for the variable argument list.
808
809 @return The number of ASCII characters in the produced output buffer not including the
810 Null-terminator.
811
812 **/
813 UINTN
814 EFIAPI
815 AsciiVSPrint (
816 OUT CHAR8 *StartOfBuffer,
817 IN UINTN BufferSize,
818 IN CONST CHAR8 *FormatString,
819 IN VA_LIST Marker
820 )
821 {
822 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, 0, FormatString, Marker);
823 }
824
825 /**
826 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
827 ASCII format string and variable argument list.
828
829 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
830 and BufferSize.
831 The ASCII string is produced by parsing the format string specified by FormatString.
832 Arguments are pulled from the variable argument list based on the contents of the
833 format string.
834 The number of ASCII characters in the produced output buffer is returned not including
835 the Null-terminator.
836 If BufferSize is 0, then no output buffer is produced and 0 is returned.
837
838 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
839 If BufferSize > 0 and FormatString is NULL, then ASSERT().
840 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
841 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
842 ASSERT().
843 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
844 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
845 Null-terminator, then ASSERT().
846
847 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
848 ASCII string.
849 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
850 @param FormatString Null-terminated Unicode format string.
851
852 @return The number of ASCII characters in the produced output buffer not including the
853 Null-terminator.
854
855 **/
856 UINTN
857 EFIAPI
858 AsciiSPrint (
859 OUT CHAR8 *StartOfBuffer,
860 IN UINTN BufferSize,
861 IN CONST CHAR8 *FormatString,
862 ...
863 )
864 {
865 VA_LIST Marker;
866
867 VA_START (Marker, FormatString);
868 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
869 }
870
871 /**
872 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
873 ASCII format string and a VA_LIST argument list.
874
875 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
876 and BufferSize.
877 The ASCII string is produced by parsing the format string specified by FormatString.
878 Arguments are pulled from the variable argument list specified by Marker based on
879 the contents of the format string.
880 The number of ASCII characters in the produced output buffer is returned not including
881 the Null-terminator.
882 If BufferSize is 0, then no output buffer is produced and 0 is returned.
883
884 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
885 If BufferSize > 0 and FormatString is NULL, then ASSERT().
886 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
887 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
888 ASSERT().
889 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
890 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
891 Null-terminator, then ASSERT().
892
893 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
894 ASCII string.
895 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
896 @param FormatString Null-terminated Unicode format string.
897 @param Marker VA_LIST marker for the variable argument list.
898
899 @return The number of ASCII characters in the produced output buffer not including the
900 Null-terminator.
901
902 **/
903 UINTN
904 EFIAPI
905 AsciiVSPrintUnicodeFormat (
906 OUT CHAR8 *StartOfBuffer,
907 IN UINTN BufferSize,
908 IN CONST CHAR16 *FormatString,
909 IN VA_LIST Marker
910 )
911 {
912 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, Marker);
913 }
914
915 /**
916 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
917 ASCII format string and variable argument list.
918
919 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
920 and BufferSize.
921 The ASCII string is produced by parsing the format string specified by FormatString.
922 Arguments are pulled from the variable argument list based on the contents of the
923 format string.
924 The number of ASCII characters in the produced output buffer is returned not including
925 the Null-terminator.
926 If BufferSize is 0, then no output buffer is produced and 0 is returned.
927
928 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
929 If BufferSize > 0 and FormatString is NULL, then ASSERT().
930 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
931 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
932 ASSERT().
933 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
934 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
935 Null-terminator, then ASSERT().
936
937 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
938 ASCII string.
939 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
940 @param FormatString Null-terminated Unicode format string.
941
942 @return The number of ASCII characters in the produced output buffer not including the
943 Null-terminator.
944
945 **/
946 UINTN
947 EFIAPI
948 AsciiSPrintUnicodeFormat (
949 OUT CHAR8 *StartOfBuffer,
950 IN UINTN BufferSize,
951 IN CONST CHAR16 *FormatString,
952 ...
953 )
954 {
955 VA_LIST Marker;
956
957 VA_START (Marker, FormatString);
958 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
959 }
960
961 /**
962 Converts a decimal value to a Null-terminated Unicode string.
963
964 Converts the decimal number specified by Value to a Null-terminated Unicode
965 string specified by Buffer containing at most Width characters.
966 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
967 The number of Unicode characters in Buffer is returned not including the Null-terminator.
968 If the conversion contains more than Width characters, then only the first
969 Width characters are returned, and the total number of characters
970 required to perform the conversion is returned.
971 Additional conversion parameters are specified in Flags.
972 The Flags bit LEFT_JUSTIFY is always ignored.
973 All conversions are left justified in Buffer.
974 If Width is 0, PREFIX_ZERO is ignored in Flags.
975 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
976 are inserted every 3rd digit starting from the right.
977 If Value is < 0, then the fist character in Buffer is a '-'.
978 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
979 then Buffer is padded with '0' characters so the combination of the optional '-'
980 sign character, '0' characters, digit characters for Value, and the Null-terminator
981 add up to Width characters.
982
983 If Buffer is NULL, then ASSERT().
984 If unsupported bits are set in Flags, then ASSERT().
985 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
986
987 @param Buffer Pointer to the output buffer for the produced Null-terminated
988 Unicode string.
989 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
990 @param Value The 64-bit signed value to convert to a string.
991 @param Width The maximum number of Unicode characters to place in Buffer, not including
992 the Null-terminator.
993
994 @return The number of Unicode characters in Buffer not including the Null-terminator.
995
996 **/
997 UINTN
998 EFIAPI
999 UnicodeValueToString (
1000 IN OUT CHAR16 *Buffer,
1001 IN UINTN Flags,
1002 IN INT64 Value,
1003 IN UINTN Width
1004 )
1005 {
1006 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);
1007 }
1008
1009 /**
1010 Converts a decimal value to a Null-terminated ASCII string.
1011
1012 Converts the decimal number specified by Value to a Null-terminated ASCII string
1013 specified by Buffer containing at most Width characters.
1014 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
1015 The number of ASCII characters in Buffer is returned not including the Null-terminator.
1016 If the conversion contains more than Width characters, then only the first Width
1017 characters are returned, and the total number of characters required to perform
1018 the conversion is returned.
1019 Additional conversion parameters are specified in Flags.
1020 The Flags bit LEFT_JUSTIFY is always ignored.
1021 All conversions are left justified in Buffer.
1022 If Width is 0, PREFIX_ZERO is ignored in Flags.
1023 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
1024 are inserted every 3rd digit starting from the right.
1025 If Value is < 0, then the fist character in Buffer is a '-'.
1026 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then Buffer
1027 is padded with '0' characters so the combination of the optional '-'
1028 sign character, '0' characters, digit characters for Value, and the
1029 Null-terminator add up to Width characters.
1030
1031 If Buffer is NULL, then ASSERT().
1032 If unsupported bits are set in Flags, then ASSERT().
1033 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
1034
1035 @param Buffer Pointer to the output buffer for the produced Null-terminated
1036 ASCII string.
1037 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
1038 @param Value The 64-bit signed value to convert to a string.
1039 @param Width The maximum number of ASCII characters to place in Buffer, not including
1040 the Null-terminator.
1041
1042 @return The number of ASCII characters in Buffer not including the Null-terminator.
1043
1044 **/
1045 UINTN
1046 EFIAPI
1047 AsciiValueToString (
1048 IN OUT CHAR8 *Buffer,
1049 IN UINTN Flags,
1050 IN INT64 Value,
1051 IN UINTN Width
1052 )
1053 {
1054 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);
1055 }