]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/EdkDxePrintLib/PrintLib.c
1659327dc511771c5e5ff056d0664eaa929c0cbc
3 Implement the print library instance by wrap the interface
4 provided in the Print protocol. This protocol is defined as the internal
5 protocol related to this implementation, not in the public spec. So, this
6 library instance is only for this code base.
8 Copyright (c) 2006 - 2008, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/Print2.h>
23 #include <Library/PrintLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
26 static EFI_PRINT2_PROTOCOL
*gPrintProtocol
= NULL
;
30 InternalLocatePrintProtocol (
33 EFI_STATUS Status
= EFI_SUCCESS
;
35 if (gPrintProtocol
== NULL
) {
36 Status
= gBS
->LocateProtocol (
37 &gEfiPrint2ProtocolGuid
,
39 (VOID
**)&gPrintProtocol
41 if (EFI_ERROR (Status
)) {
42 gPrintProtocol
= NULL
;
51 Produces a Null-terminated Unicode string in an output buffer based on
52 a Null-terminated Unicode format string and a VA_LIST argument list
54 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
56 The Unicode string is produced by parsing the format string specified by FormatString.
57 Arguments are pulled from the variable argument list specified by Marker based on the
58 contents of the format string.
59 The number of Unicode characters in the produced output buffer is returned not including
61 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
63 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
64 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
65 If BufferSize > 1 and FormatString is NULL, then ASSERT().
66 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
67 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
68 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
70 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
71 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
72 Null-terminator, then ASSERT().
74 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
76 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
77 @param FormatString Null-terminated Unicode format string.
78 @param Marker VA_LIST marker for the variable argument list.
80 @return The number of Unicode characters in the produced output buffer not including the
87 OUT CHAR16
*StartOfBuffer
,
89 IN CONST CHAR16
*FormatString
,
93 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
97 return gPrintProtocol
->VSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
101 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
102 Unicode format string and variable argument list.
104 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
106 The Unicode string is produced by parsing the format string specified by FormatString.
107 Arguments are pulled from the variable argument list based on the contents of the format string.
108 The number of Unicode characters in the produced output buffer is returned not including
110 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
112 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
113 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
114 If BufferSize > 1 and FormatString is NULL, then ASSERT().
115 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
116 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
117 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
119 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
120 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
121 Null-terminator, then ASSERT().
123 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
125 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
126 @param FormatString Null-terminated Unicode format string.
128 @return The number of Unicode characters in the produced output buffer not including the
135 OUT CHAR16
*StartOfBuffer
,
137 IN CONST CHAR16
*FormatString
,
143 VA_START (Marker
, FormatString
);
144 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
148 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
149 ASCII format string and a VA_LIST argument list
151 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
153 The Unicode string is produced by parsing the format string specified by FormatString.
154 Arguments are pulled from the variable argument list specified by Marker based on the
155 contents of the format string.
156 The number of Unicode characters in the produced output buffer is returned not including
158 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
160 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
161 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
162 If BufferSize > 1 and FormatString is NULL, then ASSERT().
163 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
164 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
166 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
167 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
168 Null-terminator, then ASSERT().
170 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
172 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
173 @param FormatString Null-terminated Unicode format string.
174 @param Marker VA_LIST marker for the variable argument list.
176 @return The number of Unicode characters in the produced output buffer not including the
182 UnicodeVSPrintAsciiFormat (
183 OUT CHAR16
*StartOfBuffer
,
185 IN CONST CHAR8
*FormatString
,
189 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
193 return gPrintProtocol
->UniVSPrintAscii (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
197 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
198 ASCII format string and variable argument list.
200 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
202 The Unicode string is produced by parsing the format string specified by FormatString.
203 Arguments are pulled from the variable argument list based on the contents of the
205 The number of Unicode characters in the produced output buffer is returned not including
207 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
209 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
210 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
211 If BufferSize > 1 and FormatString is NULL, then ASSERT().
212 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
213 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
215 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
216 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
217 Null-terminator, then ASSERT().
219 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
221 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
222 @param FormatString Null-terminated Unicode format string.
224 @return The number of Unicode characters in the produced output buffer not including the
230 UnicodeSPrintAsciiFormat (
231 OUT CHAR16
*StartOfBuffer
,
233 IN CONST CHAR8
*FormatString
,
239 VA_START (Marker
, FormatString
);
240 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
244 Converts a decimal value to a Null-terminated Unicode string.
246 Converts the decimal number specified by Value to a Null-terminated Unicode
247 string specified by Buffer containing at most Width characters. No padding of spaces
248 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
249 The number of Unicode characters in Buffer is returned not including the Null-terminator.
250 If the conversion contains more than Width characters, then only the first
251 Width characters are returned, and the total number of characters
252 required to perform the conversion is returned.
253 Additional conversion parameters are specified in Flags.
255 The Flags bit LEFT_JUSTIFY is always ignored.
256 All conversions are left justified in Buffer.
257 If Width is 0, PREFIX_ZERO is ignored in Flags.
258 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
259 are inserted every 3rd digit starting from the right.
260 If HEX_RADIX is set in Flags, then the output buffer will be
261 formatted in hexadecimal format.
262 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
263 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
264 then Buffer is padded with '0' characters so the combination of the optional '-'
265 sign character, '0' characters, digit characters for Value, and the Null-terminator
266 add up to Width characters.
267 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
268 If Buffer is NULL, then ASSERT().
269 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
270 If unsupported bits are set in Flags, then ASSERT().
271 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
272 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
274 @param Buffer Pointer to the output buffer for the produced Null-terminated
276 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
277 @param Value The 64-bit signed value to convert to a string.
278 @param Width The maximum number of Unicode characters to place in Buffer, not including
281 @return The number of Unicode characters in Buffer not including the Null-terminator.
286 UnicodeValueToString (
287 IN OUT CHAR16
*Buffer
,
293 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
297 return gPrintProtocol
->UniValueToString (Buffer
, Flags
, Value
, Width
);
301 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
302 ASCII format string and a VA_LIST argument list.
304 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
306 The ASCII string is produced by parsing the format string specified by FormatString.
307 Arguments are pulled from the variable argument list specified by Marker based on
308 the contents of the format string.
309 The number of ASCII characters in the produced output buffer is returned not including
311 If BufferSize is 0, then no output buffer is produced and 0 is returned.
313 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
314 If BufferSize > 0 and FormatString is NULL, then ASSERT().
315 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
316 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
318 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
319 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
320 Null-terminator, then ASSERT().
322 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
324 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
325 @param FormatString Null-terminated Unicode format string.
326 @param Marker VA_LIST marker for the variable argument list.
328 @return The number of ASCII characters in the produced output buffer not including the
335 OUT CHAR8
*StartOfBuffer
,
337 IN CONST CHAR8
*FormatString
,
341 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
345 return gPrintProtocol
->AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
349 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
350 ASCII format string and variable argument list.
352 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
354 The ASCII string is produced by parsing the format string specified by FormatString.
355 Arguments are pulled from the variable argument list based on the contents of the
357 The number of ASCII characters in the produced output buffer is returned not including
359 If BufferSize is 0, then no output buffer is produced and 0 is returned.
361 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
362 If BufferSize > 0 and FormatString is NULL, then ASSERT().
363 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
364 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
366 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
367 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
368 Null-terminator, then ASSERT().
370 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
372 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
373 @param FormatString Null-terminated Unicode format string.
375 @return The number of ASCII characters in the produced output buffer not including the
382 OUT CHAR8
*StartOfBuffer
,
384 IN CONST CHAR8
*FormatString
,
390 VA_START (Marker
, FormatString
);
391 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
395 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
396 ASCII format string and a VA_LIST argument list.
398 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
400 The ASCII string is produced by parsing the format string specified by FormatString.
401 Arguments are pulled from the variable argument list specified by Marker based on
402 the contents of the format string.
403 The number of ASCII characters in the produced output buffer is returned not including
405 If BufferSize is 0, then no output buffer is produced and 0 is returned.
407 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
408 If BufferSize > 0 and FormatString is NULL, then ASSERT().
409 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
410 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
411 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
413 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
414 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
415 Null-terminator, then ASSERT().
417 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
419 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
420 @param FormatString Null-terminated Unicode format string.
421 @param Marker VA_LIST marker for the variable argument list.
423 @return The number of ASCII characters in the produced output buffer not including the
429 AsciiVSPrintUnicodeFormat (
430 OUT CHAR8
*StartOfBuffer
,
432 IN CONST CHAR16
*FormatString
,
436 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
440 return gPrintProtocol
->AsciiVSPrintUni (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
444 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
445 ASCII format string and variable argument list.
447 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
449 The ASCII string is produced by parsing the format string specified by FormatString.
450 Arguments are pulled from the variable argument list based on the contents of the
452 The number of ASCII characters in the produced output buffer is returned not including
454 If BufferSize is 0, then no output buffer is produced and 0 is returned.
456 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
457 If BufferSize > 0 and FormatString is NULL, then ASSERT().
458 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
459 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
460 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
462 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
463 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
464 Null-terminator, then ASSERT().
466 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
468 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
469 @param FormatString Null-terminated Unicode format string.
471 @return The number of ASCII characters in the produced output buffer not including the
477 AsciiSPrintUnicodeFormat (
478 OUT CHAR8
*StartOfBuffer
,
480 IN CONST CHAR16
*FormatString
,
486 VA_START (Marker
, FormatString
);
487 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
492 Converts a decimal value to a Null-terminated ASCII string.
494 Converts the decimal number specified by Value to a Null-terminated ASCII string
495 specified by Buffer containing at most Width characters. No padding of spaces
497 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
498 The number of ASCII characters in Buffer is returned not including the Null-terminator.
499 If the conversion contains more than Width characters, then only the first Width
500 characters are returned, and the total number of characters required to perform
501 the conversion is returned.
502 Additional conversion parameters are specified in Flags.
503 The Flags bit LEFT_JUSTIFY is always ignored.
504 All conversions are left justified in Buffer.
505 If Width is 0, PREFIX_ZERO is ignored in Flags.
506 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
507 are inserted every 3rd digit starting from the right.
508 If HEX_RADIX is set in Flags, then the output buffer will be
509 formatted in hexadecimal format.
510 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
511 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
512 then Buffer is padded with '0' characters so the combination of the optional '-'
513 sign character, '0' characters, digit characters for Value, and the Null-terminator
514 add up to Width characters.
516 If Buffer is NULL, then ASSERT().
517 If unsupported bits are set in Flags, then ASSERT().
518 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
519 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
521 @param Buffer Pointer to the output buffer for the produced Null-terminated
523 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
524 @param Value The 64-bit signed value to convert to a string.
525 @param Width The maximum number of ASCII characters to place in Buffer, not including
528 @return The number of ASCII characters in Buffer not including the Null-terminator.
534 IN OUT CHAR8
*Buffer
,
540 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
544 return gPrintProtocol
->AsciiValueToString (Buffer
, Flags
, Value
, Width
);