]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/EdkDxePrintLib/PrintLib.c
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 #include <Protocol/Print.h>
26 #include <Library/PrintLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
29 static EFI_PRINT_PROTOCOL
*gPrintProtocol
= NULL
;
33 InternalLocatePrintProtocol (
36 EFI_STATUS Status
= EFI_SUCCESS
;
38 if (gPrintProtocol
== NULL
) {
39 Status
= gBS
->LocateProtocol (
40 &gEfiPrintProtocolGuid
,
42 (VOID
**)&gPrintProtocol
44 if (EFI_ERROR (Status
)) {
45 gPrintProtocol
= NULL
;
54 Produces a Null-terminated Unicode string in an output buffer based on
55 a Null-terminated Unicode format string and a VA_LIST argument list
57 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
59 The Unicode string is produced by parsing the format string specified by FormatString.
60 Arguments are pulled from the variable argument list specified by Marker based on the
61 contents of the format string.
62 The number of Unicode characters in the produced output buffer is returned not including
64 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
66 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
67 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
68 If BufferSize > 1 and FormatString is NULL, then ASSERT().
69 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
70 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
71 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
73 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
74 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
75 Null-terminator, then ASSERT().
77 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
79 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
80 @param FormatString Null-terminated Unicode format string.
81 @param Marker VA_LIST marker for the variable argument list.
83 @return The number of Unicode characters in the produced output buffer not including the
90 OUT CHAR16
*StartOfBuffer
,
92 IN CONST CHAR16
*FormatString
,
96 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
100 return gPrintProtocol
->VSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
104 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
105 Unicode format string and variable argument list.
107 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
109 The Unicode string is produced by parsing the format string specified by FormatString.
110 Arguments are pulled from the variable argument list based on the contents of the format string.
111 The number of Unicode characters in the produced output buffer is returned not including
113 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
115 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
116 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
117 If BufferSize > 1 and FormatString is NULL, then ASSERT().
118 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
119 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
120 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
122 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
123 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
124 Null-terminator, then ASSERT().
126 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
128 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
129 @param FormatString Null-terminated Unicode format string.
131 @return The number of Unicode characters in the produced output buffer not including the
138 OUT CHAR16
*StartOfBuffer
,
140 IN CONST CHAR16
*FormatString
,
146 VA_START (Marker
, FormatString
);
147 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
151 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
152 ASCII format string and a VA_LIST argument list
154 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
156 The Unicode string is produced by parsing the format string specified by FormatString.
157 Arguments are pulled from the variable argument list specified by Marker based on the
158 contents of the format string.
159 The number of Unicode characters in the produced output buffer is returned not including
161 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
163 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
164 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
165 If BufferSize > 1 and FormatString is NULL, then ASSERT().
166 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
167 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
169 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
170 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
171 Null-terminator, then ASSERT().
173 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
175 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
176 @param FormatString Null-terminated Unicode format string.
177 @param Marker VA_LIST marker for the variable argument list.
179 @return The number of Unicode characters in the produced output buffer not including the
185 UnicodeVSPrintAsciiFormat (
186 OUT CHAR16
*StartOfBuffer
,
188 IN CONST CHAR8
*FormatString
,
192 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
196 return gPrintProtocol
->UniVSPrintAscii (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
200 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
201 ASCII format string and variable argument list.
203 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
205 The Unicode string is produced by parsing the format string specified by FormatString.
206 Arguments are pulled from the variable argument list based on the contents of the
208 The number of Unicode characters in the produced output buffer is returned not including
210 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
212 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
213 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
214 If BufferSize > 1 and FormatString is NULL, then ASSERT().
215 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
216 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
218 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
219 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
220 Null-terminator, then ASSERT().
222 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
224 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
225 @param FormatString Null-terminated Unicode format string.
227 @return The number of Unicode characters in the produced output buffer not including the
233 UnicodeSPrintAsciiFormat (
234 OUT CHAR16
*StartOfBuffer
,
236 IN CONST CHAR8
*FormatString
,
242 VA_START (Marker
, FormatString
);
243 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
247 Converts a decimal value to a Null-terminated Unicode string.
249 Converts the decimal number specified by Value to a Null-terminated Unicode
250 string specified by Buffer containing at most Width characters. No padding of spaces
251 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
252 The number of Unicode characters in Buffer is returned not including the Null-terminator.
253 If the conversion contains more than Width characters, then only the first
254 Width characters are returned, and the total number of characters
255 required to perform the conversion is returned.
256 Additional conversion parameters are specified in Flags.
258 The Flags bit LEFT_JUSTIFY is always ignored.
259 All conversions are left justified in Buffer.
260 If Width is 0, PREFIX_ZERO is ignored in Flags.
261 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
262 are inserted every 3rd digit starting from the right.
263 If HEX_RADIX is set in Flags, then the output buffer will be
264 formatted in hexadecimal format.
265 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
266 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
267 then Buffer is padded with '0' characters so the combination of the optional '-'
268 sign character, '0' characters, digit characters for Value, and the Null-terminator
269 add up to Width characters.
270 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
271 If Buffer is NULL, then ASSERT().
272 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
273 If unsupported bits are set in Flags, then ASSERT().
274 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
275 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
277 @param Buffer Pointer to the output buffer for the produced Null-terminated
279 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
280 @param Value The 64-bit signed value to convert to a string.
281 @param Width The maximum number of Unicode characters to place in Buffer, not including
284 @return The number of Unicode characters in Buffer not including the Null-terminator.
289 UnicodeValueToString (
290 IN OUT CHAR16
*Buffer
,
296 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
300 return gPrintProtocol
->UniValueToString (Buffer
, Flags
, Value
, Width
);
304 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
305 ASCII format string and a VA_LIST argument list.
307 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
309 The ASCII string is produced by parsing the format string specified by FormatString.
310 Arguments are pulled from the variable argument list specified by Marker based on
311 the contents of the format string.
312 The number of ASCII characters in the produced output buffer is returned not including
314 If BufferSize is 0, then no output buffer is produced and 0 is returned.
316 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
317 If BufferSize > 0 and FormatString is NULL, then ASSERT().
318 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
319 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
321 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
322 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
323 Null-terminator, then ASSERT().
325 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
327 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
328 @param FormatString Null-terminated Unicode format string.
329 @param Marker VA_LIST marker for the variable argument list.
331 @return The number of ASCII characters in the produced output buffer not including the
338 OUT CHAR8
*StartOfBuffer
,
340 IN CONST CHAR8
*FormatString
,
344 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
348 return gPrintProtocol
->AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
352 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
353 ASCII format string and variable argument list.
355 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
357 The ASCII string is produced by parsing the format string specified by FormatString.
358 Arguments are pulled from the variable argument list based on the contents of the
360 The number of ASCII characters in the produced output buffer is returned not including
362 If BufferSize is 0, then no output buffer is produced and 0 is returned.
364 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
365 If BufferSize > 0 and FormatString is NULL, then ASSERT().
366 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
367 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
369 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
370 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
371 Null-terminator, then ASSERT().
373 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
375 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
376 @param FormatString Null-terminated Unicode format string.
378 @return The number of ASCII characters in the produced output buffer not including the
385 OUT CHAR8
*StartOfBuffer
,
387 IN CONST CHAR8
*FormatString
,
393 VA_START (Marker
, FormatString
);
394 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
398 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
399 ASCII format string and a VA_LIST argument list.
401 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
403 The ASCII string is produced by parsing the format string specified by FormatString.
404 Arguments are pulled from the variable argument list specified by Marker based on
405 the contents of the format string.
406 The number of ASCII characters in the produced output buffer is returned not including
408 If BufferSize is 0, then no output buffer is produced and 0 is returned.
410 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
411 If BufferSize > 0 and FormatString is NULL, then ASSERT().
412 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
413 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
414 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
416 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
417 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
418 Null-terminator, then ASSERT().
420 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
422 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
423 @param FormatString Null-terminated Unicode format string.
424 @param Marker VA_LIST marker for the variable argument list.
426 @return The number of ASCII characters in the produced output buffer not including the
432 AsciiVSPrintUnicodeFormat (
433 OUT CHAR8
*StartOfBuffer
,
435 IN CONST CHAR16
*FormatString
,
439 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
443 return gPrintProtocol
->AsciiVSPrintUni (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
447 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
448 ASCII format string and variable argument list.
450 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
452 The ASCII string is produced by parsing the format string specified by FormatString.
453 Arguments are pulled from the variable argument list based on the contents of the
455 The number of ASCII characters in the produced output buffer is returned not including
457 If BufferSize is 0, then no output buffer is produced and 0 is returned.
459 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
460 If BufferSize > 0 and FormatString is NULL, then ASSERT().
461 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
462 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
463 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
465 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
466 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
467 Null-terminator, then ASSERT().
469 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
471 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
472 @param FormatString Null-terminated Unicode format string.
474 @return The number of ASCII characters in the produced output buffer not including the
480 AsciiSPrintUnicodeFormat (
481 OUT CHAR8
*StartOfBuffer
,
483 IN CONST CHAR16
*FormatString
,
489 VA_START (Marker
, FormatString
);
490 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
495 Converts a decimal value to a Null-terminated ASCII string.
497 Converts the decimal number specified by Value to a Null-terminated ASCII string
498 specified by Buffer containing at most Width characters. No padding of spaces
500 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
501 The number of ASCII characters in Buffer is returned not including the Null-terminator.
502 If the conversion contains more than Width characters, then only the first Width
503 characters are returned, and the total number of characters required to perform
504 the conversion is returned.
505 Additional conversion parameters are specified in Flags.
506 The Flags bit LEFT_JUSTIFY is always ignored.
507 All conversions are left justified in Buffer.
508 If Width is 0, PREFIX_ZERO is ignored in Flags.
509 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
510 are inserted every 3rd digit starting from the right.
511 If HEX_RADIX is set in Flags, then the output buffer will be
512 formatted in hexadecimal format.
513 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
514 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
515 then Buffer is padded with '0' characters so the combination of the optional '-'
516 sign character, '0' characters, digit characters for Value, and the Null-terminator
517 add up to Width characters.
519 If Buffer is NULL, then ASSERT().
520 If unsupported bits are set in Flags, then ASSERT().
521 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
522 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
524 @param Buffer Pointer to the output buffer for the produced Null-terminated
526 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
527 @param Value The 64-bit signed value to convert to a string.
528 @param Width The maximum number of ASCII characters to place in Buffer, not including
531 @return The number of ASCII characters in Buffer not including the Null-terminator.
537 IN OUT CHAR8
*Buffer
,
543 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
547 return gPrintProtocol
->AsciiValueToString (Buffer
, Flags
, Value
, Width
);