]>
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 based on the contents of the format string.
138 @return The number of Unicode characters in the produced output buffer not including the
145 OUT CHAR16
*StartOfBuffer
,
147 IN CONST CHAR16
*FormatString
,
153 VA_START (Marker
, FormatString
);
154 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
158 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
159 ASCII format string and a VA_LIST argument list
161 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
163 The Unicode string is produced by parsing the format string specified by FormatString.
164 Arguments are pulled from the variable argument list specified by Marker based on the
165 contents of the format string.
166 The number of Unicode characters in the produced output buffer is returned not including
168 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
170 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
171 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
172 If BufferSize > 1 and FormatString is NULL, then ASSERT().
173 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
174 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
176 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
177 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
178 Null-terminator, then ASSERT().
180 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
182 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
183 @param FormatString Null-terminated Unicode format string.
184 @param Marker VA_LIST marker for the variable argument list.
186 @return The number of Unicode characters in the produced output buffer not including the
192 UnicodeVSPrintAsciiFormat (
193 OUT CHAR16
*StartOfBuffer
,
195 IN CONST CHAR8
*FormatString
,
199 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
203 return gPrintProtocol
->UniVSPrintAscii (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
207 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
208 ASCII format string and variable argument list.
210 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
212 The Unicode string is produced by parsing the format string specified by FormatString.
213 Arguments are pulled from the variable argument list based on the contents of the
215 The number of Unicode characters in the produced output buffer is returned not including
217 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
219 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
220 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
221 If BufferSize > 1 and FormatString is NULL, then ASSERT().
222 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
223 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
225 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
226 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
227 Null-terminator, then ASSERT().
229 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
231 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
232 @param FormatString Null-terminated Unicode format string.
233 @param ... Variable argument list based on the contents of the format string.
235 @return The number of Unicode characters in the produced output buffer not including the
241 UnicodeSPrintAsciiFormat (
242 OUT CHAR16
*StartOfBuffer
,
244 IN CONST CHAR8
*FormatString
,
250 VA_START (Marker
, FormatString
);
251 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
255 Converts a decimal value to a Null-terminated Unicode string.
257 Converts the decimal number specified by Value to a Null-terminated Unicode
258 string specified by Buffer containing at most Width characters. No padding of spaces
259 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
260 The number of Unicode characters in Buffer is returned not including the Null-terminator.
261 If the conversion contains more than Width characters, then only the first
262 Width characters are returned, and the total number of characters
263 required to perform the conversion is returned.
264 Additional conversion parameters are specified in Flags.
266 The Flags bit LEFT_JUSTIFY is always ignored.
267 All conversions are left justified in Buffer.
268 If Width is 0, PREFIX_ZERO is ignored in Flags.
269 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
270 are inserted every 3rd digit starting from the right.
271 If HEX_RADIX is set in Flags, then the output buffer will be
272 formatted in hexadecimal format.
273 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
274 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
275 then Buffer is padded with '0' characters so the combination of the optional '-'
276 sign character, '0' characters, digit characters for Value, and the Null-terminator
277 add up to Width characters.
278 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
279 If Buffer is NULL, then ASSERT().
280 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
281 If unsupported bits are set in Flags, then ASSERT().
282 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
283 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
285 @param Buffer Pointer to the output buffer for the produced Null-terminated
287 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
288 @param Value The 64-bit signed value to convert to a string.
289 @param Width The maximum number of Unicode characters to place in Buffer, not including
292 @return The number of Unicode characters in Buffer not including the Null-terminator.
297 UnicodeValueToString (
298 IN OUT CHAR16
*Buffer
,
304 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
308 return gPrintProtocol
->UniValueToString (Buffer
, Flags
, Value
, Width
);
312 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
313 ASCII format string and a VA_LIST argument list.
315 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
317 The ASCII string is produced by parsing the format string specified by FormatString.
318 Arguments are pulled from the variable argument list specified by Marker based on
319 the contents of the format string.
320 The number of ASCII characters in the produced output buffer is returned not including
322 If BufferSize is 0, then no output buffer is produced and 0 is returned.
324 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
325 If BufferSize > 0 and FormatString is NULL, then ASSERT().
326 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
327 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
329 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
330 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
331 Null-terminator, then ASSERT().
333 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
335 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
336 @param FormatString Null-terminated Unicode format string.
337 @param Marker VA_LIST marker for the variable argument list.
339 @return The number of ASCII characters in the produced output buffer not including the
346 OUT CHAR8
*StartOfBuffer
,
348 IN CONST CHAR8
*FormatString
,
352 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
356 return gPrintProtocol
->AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
360 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
361 ASCII format string and variable argument list.
363 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
365 The ASCII string is produced by parsing the format string specified by FormatString.
366 Arguments are pulled from the variable argument list based on the contents of the
368 The number of ASCII characters in the produced output buffer is returned not including
370 If BufferSize is 0, then no output buffer is produced and 0 is returned.
372 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
373 If BufferSize > 0 and FormatString is NULL, then ASSERT().
374 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
375 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
377 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
378 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
379 Null-terminator, then ASSERT().
381 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
383 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
384 @param FormatString Null-terminated Unicode format string.
385 @param ... Variable argument list based on the contents of the format string.
387 @return The number of ASCII characters in the produced output buffer not including the
394 OUT CHAR8
*StartOfBuffer
,
396 IN CONST CHAR8
*FormatString
,
402 VA_START (Marker
, FormatString
);
403 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
407 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
408 ASCII format string and a VA_LIST argument list.
410 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
412 The ASCII string is produced by parsing the format string specified by FormatString.
413 Arguments are pulled from the variable argument list specified by Marker based on
414 the contents of the format string.
415 The number of ASCII characters in the produced output buffer is returned not including
417 If BufferSize is 0, then no output buffer is produced and 0 is returned.
419 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
420 If BufferSize > 0 and FormatString is NULL, then ASSERT().
421 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
422 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
423 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
425 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
426 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
427 Null-terminator, then ASSERT().
429 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
431 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
432 @param FormatString Null-terminated Unicode format string.
433 @param Marker VA_LIST marker for the variable argument list.
435 @return The number of ASCII characters in the produced output buffer not including the
441 AsciiVSPrintUnicodeFormat (
442 OUT CHAR8
*StartOfBuffer
,
444 IN CONST CHAR16
*FormatString
,
448 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
452 return gPrintProtocol
->AsciiVSPrintUni (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
456 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
457 ASCII format string and variable argument list.
459 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
461 The ASCII string is produced by parsing the format string specified by FormatString.
462 Arguments are pulled from the variable argument list based on the contents of the
464 The number of ASCII characters in the produced output buffer is returned not including
466 If BufferSize is 0, then no output buffer is produced and 0 is returned.
468 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
469 If BufferSize > 0 and FormatString is NULL, then ASSERT().
470 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
471 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
472 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
474 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
475 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
476 Null-terminator, then ASSERT().
478 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
480 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
481 @param FormatString Null-terminated Unicode format string.
482 @param ... Variable argument list based on the contents of the format string.
484 @return The number of ASCII characters in the produced output buffer not including the
490 AsciiSPrintUnicodeFormat (
491 OUT CHAR8
*StartOfBuffer
,
493 IN CONST CHAR16
*FormatString
,
499 VA_START (Marker
, FormatString
);
500 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
505 Converts a decimal value to a Null-terminated ASCII string.
507 Converts the decimal number specified by Value to a Null-terminated ASCII string
508 specified by Buffer containing at most Width characters. No padding of spaces
510 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
511 The number of ASCII characters in Buffer is returned not including the Null-terminator.
512 If the conversion contains more than Width characters, then only the first Width
513 characters are returned, and the total number of characters required to perform
514 the conversion is returned.
515 Additional conversion parameters are specified in Flags.
516 The Flags bit LEFT_JUSTIFY is always ignored.
517 All conversions are left justified in Buffer.
518 If Width is 0, PREFIX_ZERO is ignored in Flags.
519 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
520 are inserted every 3rd digit starting from the right.
521 If HEX_RADIX is set in Flags, then the output buffer will be
522 formatted in hexadecimal format.
523 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
524 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
525 then Buffer is padded with '0' characters so the combination of the optional '-'
526 sign character, '0' characters, digit characters for Value, and the Null-terminator
527 add up to Width characters.
529 If Buffer is NULL, then ASSERT().
530 If unsupported bits are set in Flags, then ASSERT().
531 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
532 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
534 @param Buffer Pointer to the output buffer for the produced Null-terminated
536 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
537 @param Value The 64-bit signed value to convert to a string.
538 @param Width The maximum number of ASCII characters to place in Buffer, not including
541 @return The number of ASCII characters in Buffer not including the Null-terminator.
547 IN OUT CHAR8
*Buffer
,
553 if (InternalLocatePrintProtocol() != EFI_SUCCESS
) {
557 return gPrintProtocol
->AsciiValueToString (Buffer
, Flags
, Value
, Width
);