]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/EdkDxePrintLib/PrintLib.c
1. Update internal EfiPrint protocol to contain all print interfaces provided by...
[mirror_edk2.git] / MdeModulePkg / Library / EdkDxePrintLib / PrintLib.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 PrintLib.c
15
16 Abstract:
17
18 Print Library
19
20 --*/
21
22 #include <PiDxe.h>
23
24 #include <Protocol/Print.h>
25
26 #include <Library/PrintLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28
29 static EFI_PRINT_PROTOCOL *gPrintProtocol = NULL;
30
31 EFI_STATUS
32 EFIAPI
33 InternalLocatePrintProtocol (
34 )
35 {
36 EFI_STATUS Status = EFI_SUCCESS;
37
38 if (gPrintProtocol == NULL) {
39 Status = gBS->LocateProtocol (
40 &gEfiPrintProtocolGuid,
41 NULL,
42 (VOID **)&gPrintProtocol
43 );
44 if (EFI_ERROR (Status)) {
45 gPrintProtocol = NULL;
46 return Status;
47 }
48 }
49
50 return EFI_SUCCESS;
51 }
52
53 /**
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
56
57 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
58 and BufferSize.
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
63 the Null-terminator.
64 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
65
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
72 ASSERT().
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().
76
77 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
78 Unicode string.
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.
82
83 @return The number of Unicode characters in the produced output buffer not including the
84 Null-terminator.
85
86 **/
87 UINTN
88 EFIAPI
89 UnicodeVSPrint (
90 OUT CHAR16 *StartOfBuffer,
91 IN UINTN BufferSize,
92 IN CONST CHAR16 *FormatString,
93 IN VA_LIST Marker
94 )
95 {
96 if (InternalLocatePrintProtocol() != EFI_SUCCESS) {
97 return 0;
98 }
99
100 return gPrintProtocol->VSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
101 }
102
103 /**
104 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
105 Unicode format string and variable argument list.
106
107 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
108 and BufferSize.
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
112 the Null-terminator.
113 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
114
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
121 ASSERT().
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().
125
126 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
127 Unicode string.
128 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
129 @param FormatString Null-terminated Unicode format string.
130
131 @return The number of Unicode characters in the produced output buffer not including the
132 Null-terminator.
133
134 **/
135 UINTN
136 EFIAPI
137 UnicodeSPrint (
138 OUT CHAR16 *StartOfBuffer,
139 IN UINTN BufferSize,
140 IN CONST CHAR16 *FormatString,
141 ...
142 )
143 {
144 VA_LIST Marker;
145
146 VA_START (Marker, FormatString);
147 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
148 }
149
150 /**
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
153
154 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
155 and BufferSize.
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
160 the Null-terminator.
161 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
162
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
168 ASSERT().
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().
172
173 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
174 Unicode string.
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.
178
179 @return The number of Unicode characters in the produced output buffer not including the
180 Null-terminator.
181
182 **/
183 UINTN
184 EFIAPI
185 UnicodeVSPrintAsciiFormat (
186 OUT CHAR16 *StartOfBuffer,
187 IN UINTN BufferSize,
188 IN CONST CHAR8 *FormatString,
189 IN VA_LIST Marker
190 )
191 {
192 if (InternalLocatePrintProtocol() != EFI_SUCCESS) {
193 return 0;
194 }
195
196 return gPrintProtocol->UniVSPrintAscii (StartOfBuffer, BufferSize, FormatString, Marker);
197 }
198
199 /**
200 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
201 ASCII format string and variable argument list.
202
203 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
204 and BufferSize.
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
207 format string.
208 The number of Unicode characters in the produced output buffer is returned not including
209 the Null-terminator.
210 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
211
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
217 ASSERT().
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().
221
222 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
223 Unicode string.
224 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
225 @param FormatString Null-terminated Unicode format string.
226
227 @return The number of Unicode characters in the produced output buffer not including the
228 Null-terminator.
229
230 **/
231 UINTN
232 EFIAPI
233 UnicodeSPrintAsciiFormat (
234 OUT CHAR16 *StartOfBuffer,
235 IN UINTN BufferSize,
236 IN CONST CHAR8 *FormatString,
237 ...
238 )
239 {
240 VA_LIST Marker;
241
242 VA_START (Marker, FormatString);
243 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
244 }
245
246 /**
247 Converts a decimal value to a Null-terminated Unicode string.
248
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.
257
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()
276
277 @param Buffer Pointer to the output buffer for the produced Null-terminated
278 Unicode string.
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
282 the Null-terminator.
283
284 @return The number of Unicode characters in Buffer not including the Null-terminator.
285
286 **/
287 UINTN
288 EFIAPI
289 UnicodeValueToString (
290 IN OUT CHAR16 *Buffer,
291 IN UINTN Flags,
292 IN INT64 Value,
293 IN UINTN Width
294 )
295 {
296 if (InternalLocatePrintProtocol() != EFI_SUCCESS) {
297 return 0;
298 }
299
300 return gPrintProtocol->UniValueToString (Buffer, Flags, Value, Width);
301 }
302
303 /**
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.
306
307 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
308 and BufferSize.
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
313 the Null-terminator.
314 If BufferSize is 0, then no output buffer is produced and 0 is returned.
315
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
320 ASSERT().
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().
324
325 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
326 ASCII string.
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.
330
331 @return The number of ASCII characters in the produced output buffer not including the
332 Null-terminator.
333
334 **/
335 UINTN
336 EFIAPI
337 AsciiVSPrint (
338 OUT CHAR8 *StartOfBuffer,
339 IN UINTN BufferSize,
340 IN CONST CHAR8 *FormatString,
341 IN VA_LIST Marker
342 )
343 {
344 if (InternalLocatePrintProtocol() != EFI_SUCCESS) {
345 return 0;
346 }
347
348 return gPrintProtocol->AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
349 }
350
351 /**
352 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
353 ASCII format string and variable argument list.
354
355 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
356 and BufferSize.
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
359 format string.
360 The number of ASCII characters in the produced output buffer is returned not including
361 the Null-terminator.
362 If BufferSize is 0, then no output buffer is produced and 0 is returned.
363
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
368 ASSERT().
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().
372
373 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
374 ASCII string.
375 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
376 @param FormatString Null-terminated Unicode format string.
377
378 @return The number of ASCII characters in the produced output buffer not including the
379 Null-terminator.
380
381 **/
382 UINTN
383 EFIAPI
384 AsciiSPrint (
385 OUT CHAR8 *StartOfBuffer,
386 IN UINTN BufferSize,
387 IN CONST CHAR8 *FormatString,
388 ...
389 )
390 {
391 VA_LIST Marker;
392
393 VA_START (Marker, FormatString);
394 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
395 }
396
397 /**
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.
400
401 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
402 and BufferSize.
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
407 the Null-terminator.
408 If BufferSize is 0, then no output buffer is produced and 0 is returned.
409
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
415 ASSERT().
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().
419
420 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
421 ASCII string.
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.
425
426 @return The number of ASCII characters in the produced output buffer not including the
427 Null-terminator.
428
429 **/
430 UINTN
431 EFIAPI
432 AsciiVSPrintUnicodeFormat (
433 OUT CHAR8 *StartOfBuffer,
434 IN UINTN BufferSize,
435 IN CONST CHAR16 *FormatString,
436 IN VA_LIST Marker
437 )
438 {
439 if (InternalLocatePrintProtocol() != EFI_SUCCESS) {
440 return 0;
441 }
442
443 return gPrintProtocol->AsciiVSPrintUni (StartOfBuffer, BufferSize, FormatString, Marker);
444 }
445
446 /**
447 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
448 ASCII format string and variable argument list.
449
450 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
451 and BufferSize.
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
454 format string.
455 The number of ASCII characters in the produced output buffer is returned not including
456 the Null-terminator.
457 If BufferSize is 0, then no output buffer is produced and 0 is returned.
458
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
464 ASSERT().
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().
468
469 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
470 ASCII string.
471 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
472 @param FormatString Null-terminated Unicode format string.
473
474 @return The number of ASCII characters in the produced output buffer not including the
475 Null-terminator.
476
477 **/
478 UINTN
479 EFIAPI
480 AsciiSPrintUnicodeFormat (
481 OUT CHAR8 *StartOfBuffer,
482 IN UINTN BufferSize,
483 IN CONST CHAR16 *FormatString,
484 ...
485 )
486 {
487 VA_LIST Marker;
488
489 VA_START (Marker, FormatString);
490 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
491 }
492
493
494 /**
495 Converts a decimal value to a Null-terminated ASCII string.
496
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
499 is ever performed.
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.
518
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()
523
524 @param Buffer Pointer to the output buffer for the produced Null-terminated
525 ASCII string.
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
529 the Null-terminator.
530
531 @return The number of ASCII characters in Buffer not including the Null-terminator.
532
533 **/
534 UINTN
535 EFIAPI
536 AsciiValueToString (
537 IN OUT CHAR8 *Buffer,
538 IN UINTN Flags,
539 IN INT64 Value,
540 IN UINTN Width
541 )
542 {
543 if (InternalLocatePrintProtocol() != EFI_SUCCESS) {
544 return 0;
545 }
546
547 return gPrintProtocol->AsciiValueToString (Buffer, Flags, Value, Width);
548 }