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