]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/EdkDxePrintLib/PrintLib.c
2 Instance of Print Library based on EFI_PRINT2_PROTOCOL.
4 Implement the print library instance by wrap the interface
5 provided in the Print protocol. This protocol is defined as the internal
6 protocol related to this implementation, not in the public spec. So, this
7 library instance is only for this code base.
9 Copyright (c) 2006 - 2008, Intel Corporation
10 All rights reserved. This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Protocol/Print2.h>
24 #include <Library/PrintLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
27 EFI_PRINT2_PROTOCOL
*gPrintProtocol
= NULL
;
30 Internal function to locate the EFI_PRINT2_PROTOCOL.
32 @retval EFI_SUCCESS EFI_PRINT2_PROTOCOL is successfuly located.
33 @retval EFI_NOT_FOUND EFI_PRINT2_PROTOCOL cannot be found.
38 InternalLocatePrintProtocol (
44 if (gPrintProtocol
== NULL
) {
45 Status
= gBS
->LocateProtocol (
46 &gEfiPrint2ProtocolGuid
,
48 (VOID
**)&gPrintProtocol
50 if (EFI_ERROR (Status
)) {
51 gPrintProtocol
= NULL
;
60 Produces a Null-terminated Unicode string in an output buffer based on
61 a Null-terminated Unicode format string and a VA_LIST argument list
63 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
65 The Unicode string is produced by parsing the format string specified by FormatString.
66 Arguments are pulled from the variable argument list specified by Marker based on the
67 contents of the format string.
68 The number of Unicode characters in the produced output buffer is returned not including
70 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
72 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
73 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
74 If BufferSize > 1 and FormatString is NULL, then ASSERT().
75 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
76 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
77 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
79 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
80 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
81 Null-terminator, then ASSERT().
83 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
85 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
86 @param FormatString Null-terminated Unicode format string.
87 @param Marker VA_LIST marker for the variable argument list.
89 @return The number of Unicode characters in the produced output buffer not including the
96 OUT CHAR16
*StartOfBuffer
,
98 IN CONST CHAR16
*FormatString
,
102 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
106 return gPrintProtocol
->VSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
110 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
111 Unicode format string and variable argument list.
113 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
115 The Unicode string is produced by parsing the format string specified by FormatString.
116 Arguments are pulled from the variable argument list based on the contents of the format string.
117 The number of Unicode characters in the produced output buffer is returned not including
119 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
121 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
122 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
123 If BufferSize > 1 and FormatString is NULL, then ASSERT().
124 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
125 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
126 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
128 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
129 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
130 Null-terminator, then ASSERT().
132 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
134 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
135 @param FormatString Null-terminated Unicode format string.
136 @param ... Variable argument list whose contents are accessed based on the
137 format string specified by FormatString.
139 @return The number of Unicode characters in the produced output buffer not including the
146 OUT CHAR16
*StartOfBuffer
,
148 IN CONST CHAR16
*FormatString
,
154 VA_START (Marker
, FormatString
);
155 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
159 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
160 ASCII format string and a VA_LIST argument list
162 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
164 The Unicode string is produced by parsing the format string specified by FormatString.
165 Arguments are pulled from the variable argument list specified by Marker based on the
166 contents of the format string.
167 The number of Unicode characters in the produced output buffer is returned not including
169 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
171 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
172 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
173 If BufferSize > 1 and FormatString is NULL, then ASSERT().
174 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
175 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
177 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
178 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
179 Null-terminator, then ASSERT().
181 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
183 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
184 @param FormatString Null-terminated Unicode format string.
185 @param Marker VA_LIST marker for the variable argument list.
187 @return The number of Unicode characters in the produced output buffer not including the
193 UnicodeVSPrintAsciiFormat (
194 OUT CHAR16
*StartOfBuffer
,
196 IN CONST CHAR8
*FormatString
,
200 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
204 return gPrintProtocol
->UniVSPrintAscii (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
208 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
209 ASCII format string and variable argument list.
211 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
213 The Unicode string is produced by parsing the format string specified by FormatString.
214 Arguments are pulled from the variable argument list based on the contents of the
216 The number of Unicode characters in the produced output buffer is returned not including
218 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
220 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
221 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
222 If BufferSize > 1 and FormatString is NULL, then ASSERT().
223 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
224 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
226 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
227 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
228 Null-terminator, then ASSERT().
230 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
232 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
233 @param FormatString Null-terminated Unicode format string.
234 @param ... Variable argument list whose contents are accessed based on the
235 format string specified by FormatString.
237 @return The number of Unicode characters in the produced output buffer not including the
243 UnicodeSPrintAsciiFormat (
244 OUT CHAR16
*StartOfBuffer
,
246 IN CONST CHAR8
*FormatString
,
252 VA_START (Marker
, FormatString
);
253 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
257 Converts a decimal value to a Null-terminated Unicode string.
259 Converts the decimal number specified by Value to a Null-terminated Unicode
260 string specified by Buffer containing at most Width characters. No padding of spaces
261 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
262 The number of Unicode characters in Buffer is returned not including the Null-terminator.
263 If the conversion contains more than Width characters, then only the first
264 Width characters are returned, and the total number of characters
265 required to perform the conversion is returned.
266 Additional conversion parameters are specified in Flags.
268 The Flags bit LEFT_JUSTIFY is always ignored.
269 All conversions are left justified in Buffer.
270 If Width is 0, PREFIX_ZERO is ignored in Flags.
271 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
272 are inserted every 3rd digit starting from the right.
273 If HEX_RADIX is set in Flags, then the output buffer will be
274 formatted in hexadecimal format.
275 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
276 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
277 then Buffer is padded with '0' characters so the combination of the optional '-'
278 sign character, '0' characters, digit characters for Value, and the Null-terminator
279 add up to Width characters.
280 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
281 If Buffer is NULL, then ASSERT().
282 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
283 If unsupported bits are set in Flags, then ASSERT().
284 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
285 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
287 @param Buffer Pointer to the output buffer for the produced Null-terminated
289 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
290 @param Value The 64-bit signed value to convert to a string.
291 @param Width The maximum number of Unicode characters to place in Buffer, not including
294 @return The number of Unicode characters in Buffer not including the Null-terminator.
299 UnicodeValueToString (
300 IN OUT CHAR16
*Buffer
,
306 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
310 return gPrintProtocol
->UniValueToString (Buffer
, Flags
, Value
, Width
);
314 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
315 ASCII format string and a VA_LIST argument list.
317 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
319 The ASCII string is produced by parsing the format string specified by FormatString.
320 Arguments are pulled from the variable argument list specified by Marker based on
321 the contents of the format string.
322 The number of ASCII characters in the produced output buffer is returned not including
324 If BufferSize is 0, then no output buffer is produced and 0 is returned.
326 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
327 If BufferSize > 0 and FormatString is NULL, then ASSERT().
328 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
329 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
331 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
332 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
333 Null-terminator, then ASSERT().
335 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
337 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
338 @param FormatString Null-terminated Unicode format string.
339 @param Marker VA_LIST marker for the variable argument list.
341 @return The number of ASCII characters in the produced output buffer not including the
348 OUT CHAR8
*StartOfBuffer
,
350 IN CONST CHAR8
*FormatString
,
354 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
358 return gPrintProtocol
->AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
362 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
363 ASCII format string and variable argument list.
365 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
367 The ASCII string is produced by parsing the format string specified by FormatString.
368 Arguments are pulled from the variable argument list based on the contents of the
370 The number of ASCII characters in the produced output buffer is returned not including
372 If BufferSize is 0, then no output buffer is produced and 0 is returned.
374 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
375 If BufferSize > 0 and FormatString is NULL, then ASSERT().
376 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
377 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
379 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
380 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
381 Null-terminator, then ASSERT().
383 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
385 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
386 @param FormatString Null-terminated Unicode format string.
387 @param ... Variable argument list whose contents are accessed based on the
388 format string specified by FormatString.
390 @return The number of ASCII characters in the produced output buffer not including the
397 OUT CHAR8
*StartOfBuffer
,
399 IN CONST CHAR8
*FormatString
,
405 VA_START (Marker
, FormatString
);
406 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
410 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
411 ASCII format string and a VA_LIST argument list.
413 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
415 The ASCII string is produced by parsing the format string specified by FormatString.
416 Arguments are pulled from the variable argument list specified by Marker based on
417 the contents of the format string.
418 The number of ASCII characters in the produced output buffer is returned not including
420 If BufferSize is 0, then no output buffer is produced and 0 is returned.
422 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
423 If BufferSize > 0 and FormatString is NULL, then ASSERT().
424 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
425 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
426 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
428 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
429 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
430 Null-terminator, then ASSERT().
432 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
434 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
435 @param FormatString Null-terminated Unicode format string.
436 @param Marker VA_LIST marker for the variable argument list.
438 @return The number of ASCII characters in the produced output buffer not including the
444 AsciiVSPrintUnicodeFormat (
445 OUT CHAR8
*StartOfBuffer
,
447 IN CONST CHAR16
*FormatString
,
451 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
455 return gPrintProtocol
->AsciiVSPrintUni (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
459 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
460 ASCII format string and variable argument list.
462 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
464 The ASCII string is produced by parsing the format string specified by FormatString.
465 Arguments are pulled from the variable argument list based on the contents of the
467 The number of ASCII characters in the produced output buffer is returned not including
469 If BufferSize is 0, then no output buffer is produced and 0 is returned.
471 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
472 If BufferSize > 0 and FormatString is NULL, then ASSERT().
473 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
474 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
475 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
477 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
478 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
479 Null-terminator, then ASSERT().
481 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
483 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
484 @param FormatString Null-terminated Unicode format string.
485 @param ... Variable argument list whose contents are accessed based on the
486 format string specified by FormatString.
488 @return The number of ASCII characters in the produced output buffer not including the
494 AsciiSPrintUnicodeFormat (
495 OUT CHAR8
*StartOfBuffer
,
497 IN CONST CHAR16
*FormatString
,
503 VA_START (Marker
, FormatString
);
504 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
509 Converts a decimal value to a Null-terminated ASCII string.
511 Converts the decimal number specified by Value to a Null-terminated ASCII string
512 specified by Buffer containing at most Width characters. No padding of spaces
514 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
515 The number of ASCII characters in Buffer is returned not including the Null-terminator.
516 If the conversion contains more than Width characters, then only the first Width
517 characters are returned, and the total number of characters required to perform
518 the conversion is returned.
519 Additional conversion parameters are specified in Flags.
520 The Flags bit LEFT_JUSTIFY is always ignored.
521 All conversions are left justified in Buffer.
522 If Width is 0, PREFIX_ZERO is ignored in Flags.
523 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
524 are inserted every 3rd digit starting from the right.
525 If HEX_RADIX is set in Flags, then the output buffer will be
526 formatted in hexadecimal format.
527 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
528 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
529 then Buffer is padded with '0' characters so the combination of the optional '-'
530 sign character, '0' characters, digit characters for Value, and the Null-terminator
531 add up to Width characters.
533 If Buffer is NULL, then ASSERT().
534 If unsupported bits are set in Flags, then ASSERT().
535 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
536 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
538 @param Buffer Pointer to the output buffer for the produced Null-terminated
540 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
541 @param Value The 64-bit signed value to convert to a string.
542 @param Width The maximum number of ASCII characters to place in Buffer, not including
545 @return The number of ASCII characters in Buffer not including the Null-terminator.
557 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
561 return gPrintProtocol
->AsciiValueToString (Buffer
, Flags
, Value
, Width
);