]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
Rename EdkPrintLib to DxePrintLibPrint2Protocol to better reflect its functionality.
[mirror_edk2.git] / MdeModulePkg / Library / DxePrintLibPrint2Protocol / PrintLib.c
1 /** @file
2 Instance of Print Library based on gEfiPrint2ProtocolGuid.
3
4 Implement the print library instance by wrap the interface
5 provided in the Print2 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.
8
9 Copyright (c) 2009, 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
14
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.
17
18 **/
19
20 #include <Uefi.h>
21 #include <Protocol/Print2.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/DebugLib.h>
24
25 EFI_PRINT2_PROTOCOL *mPrint2Protocol = NULL;
26
27 /**
28 The constructor function caches the pointer to Print2 protocol.
29
30 The constructor function locates Print2 protocol from protocol database.
31 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
32
33 @param ImageHandle The firmware allocated handle for the EFI image.
34 @param SystemTable A pointer to the EFI System Table.
35
36 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
37
38 **/
39 EFI_STATUS
40 EFIAPI
41 PrintLibConstructor (
42 IN EFI_HANDLE ImageHandle,
43 IN EFI_SYSTEM_TABLE *SystemTable
44 )
45 {
46 EFI_STATUS Status;
47
48 Status = gBS->LocateProtocol (
49 &gEfiPrint2ProtocolGuid,
50 NULL,
51 (VOID**) &mPrint2Protocol
52 );
53 ASSERT_EFI_ERROR (Status);
54 ASSERT (mPrint2Protocol != NULL);
55
56 return Status;
57 }
58
59
60 /**
61 Produces a Null-terminated Unicode string in an output buffer based on
62 a Null-terminated Unicode format string and a VA_LIST argument list
63
64 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
65 and BufferSize.
66 The Unicode string is produced by parsing the format string specified by FormatString.
67 Arguments are pulled from the variable argument list specified by Marker based on the
68 contents of the format string.
69 The number of Unicode characters in the produced output buffer is returned not including
70 the Null-terminator.
71 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
72
73 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
74 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
75 If BufferSize > 1 and FormatString is NULL, then ASSERT().
76 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
77 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
78 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
79 ASSERT().
80 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
81 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
82 Null-terminator, then ASSERT().
83
84 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
85 Unicode string.
86 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
87 @param FormatString Null-terminated Unicode format string.
88 @param Marker VA_LIST marker for the variable argument list.
89
90 @return The number of Unicode characters in the produced output buffer not including the
91 Null-terminator.
92
93 **/
94 UINTN
95 EFIAPI
96 UnicodeVSPrint (
97 OUT CHAR16 *StartOfBuffer,
98 IN UINTN BufferSize,
99 IN CONST CHAR16 *FormatString,
100 IN VA_LIST Marker
101 )
102 {
103 return mPrint2Protocol->UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
104 }
105
106 /**
107 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
108 Unicode format string and variable argument list.
109
110 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
111 and BufferSize.
112 The Unicode string is produced by parsing the format string specified by FormatString.
113 Arguments are pulled from the variable argument list based on the contents of the format string.
114 The number of Unicode characters in the produced output buffer is returned not including
115 the Null-terminator.
116 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
117
118 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
119 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
120 If BufferSize > 1 and FormatString is NULL, then ASSERT().
121 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
122 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
123 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
124 ASSERT().
125 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
126 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
127 Null-terminator, then ASSERT().
128
129 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
130 Unicode string.
131 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
132 @param FormatString Null-terminated Unicode format string.
133 @param ... Variable argument list whose contents are accessed based on the
134 format string specified by FormatString.
135
136 @return The number of Unicode characters in the produced output buffer not including the
137 Null-terminator.
138
139 **/
140 UINTN
141 EFIAPI
142 UnicodeSPrint (
143 OUT CHAR16 *StartOfBuffer,
144 IN UINTN BufferSize,
145 IN CONST CHAR16 *FormatString,
146 ...
147 )
148 {
149 VA_LIST Marker;
150
151 VA_START (Marker, FormatString);
152 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
153 }
154
155 /**
156 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
157 ASCII format string and a VA_LIST argument list
158
159 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
160 and BufferSize.
161 The Unicode string is produced by parsing the format string specified by FormatString.
162 Arguments are pulled from the variable argument list specified by Marker based on the
163 contents of the format string.
164 The number of Unicode characters in the produced output buffer is returned not including
165 the Null-terminator.
166 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
167
168 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
169 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
170 If BufferSize > 1 and FormatString is NULL, then ASSERT().
171 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
172 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
173 ASSERT().
174 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
175 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
176 Null-terminator, then ASSERT().
177
178 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
179 Unicode string.
180 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
181 @param FormatString Null-terminated Unicode format string.
182 @param Marker VA_LIST marker for the variable argument list.
183
184 @return The number of Unicode characters in the produced output buffer not including the
185 Null-terminator.
186
187 **/
188 UINTN
189 EFIAPI
190 UnicodeVSPrintAsciiFormat (
191 OUT CHAR16 *StartOfBuffer,
192 IN UINTN BufferSize,
193 IN CONST CHAR8 *FormatString,
194 IN VA_LIST Marker
195 )
196 {
197 return mPrint2Protocol->UnicodeSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
198 }
199
200 /**
201 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
202 ASCII format string and variable argument list.
203
204 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
205 and BufferSize.
206 The Unicode string is produced by parsing the format string specified by FormatString.
207 Arguments are pulled from the variable argument list based on the contents of the
208 format string.
209 The number of Unicode characters in the produced output buffer is returned not including
210 the Null-terminator.
211 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
212
213 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
214 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
215 If BufferSize > 1 and FormatString is NULL, then ASSERT().
216 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
217 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
218 ASSERT().
219 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
220 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
221 Null-terminator, then ASSERT().
222
223 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
224 Unicode string.
225 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
226 @param FormatString Null-terminated Unicode format string.
227 @param ... Variable argument list whose contents are accessed based on the
228 format string specified by FormatString.
229
230 @return The number of Unicode characters in the produced output buffer not including the
231 Null-terminator.
232
233 **/
234 UINTN
235 EFIAPI
236 UnicodeSPrintAsciiFormat (
237 OUT CHAR16 *StartOfBuffer,
238 IN UINTN BufferSize,
239 IN CONST CHAR8 *FormatString,
240 ...
241 )
242 {
243 VA_LIST Marker;
244
245 VA_START (Marker, FormatString);
246 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
247 }
248
249 /**
250 Converts a decimal value to a Null-terminated Unicode string.
251
252 Converts the decimal number specified by Value to a Null-terminated Unicode
253 string specified by Buffer containing at most Width characters. No padding of spaces
254 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
255 The number of Unicode characters in Buffer is returned not including the Null-terminator.
256 If the conversion contains more than Width characters, then only the first
257 Width characters are returned, and the total number of characters
258 required to perform the conversion is returned.
259 Additional conversion parameters are specified in Flags.
260
261 The Flags bit LEFT_JUSTIFY is always ignored.
262 All conversions are left justified in Buffer.
263 If Width is 0, PREFIX_ZERO is ignored in Flags.
264 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
265 are inserted every 3rd digit starting from the right.
266 If HEX_RADIX is set in Flags, then the output buffer will be
267 formatted in hexadecimal format.
268 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
269 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
270 then Buffer is padded with '0' characters so the combination of the optional '-'
271 sign character, '0' characters, digit characters for Value, and the Null-terminator
272 add up to Width characters.
273 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
274 If Buffer is NULL, then ASSERT().
275 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
276 If unsupported bits are set in Flags, then ASSERT().
277 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
278 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
279
280 @param Buffer Pointer to the output buffer for the produced Null-terminated
281 Unicode string.
282 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
283 @param Value The 64-bit signed value to convert to a string.
284 @param Width The maximum number of Unicode characters to place in Buffer, not including
285 the Null-terminator.
286
287 @return The number of Unicode characters in Buffer not including the Null-terminator.
288
289 **/
290 UINTN
291 EFIAPI
292 UnicodeValueToString (
293 IN OUT CHAR16 *Buffer,
294 IN UINTN Flags,
295 IN INT64 Value,
296 IN UINTN Width
297 )
298 {
299 return mPrint2Protocol->UnicodeValueToString (Buffer, Flags, Value, Width);
300 }
301
302 /**
303 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
304 ASCII format string and a VA_LIST argument list.
305
306 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
307 and BufferSize.
308 The ASCII string is produced by parsing the format string specified by FormatString.
309 Arguments are pulled from the variable argument list specified by Marker based on
310 the contents of the format string.
311 The number of ASCII characters in the produced output buffer is returned not including
312 the Null-terminator.
313 If BufferSize is 0, then no output buffer is produced and 0 is returned.
314
315 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
316 If BufferSize > 0 and FormatString is NULL, then ASSERT().
317 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
318 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
319 ASSERT().
320 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
321 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
322 Null-terminator, then ASSERT().
323
324 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
325 ASCII string.
326 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
327 @param FormatString Null-terminated Unicode format string.
328 @param Marker VA_LIST marker for the variable argument list.
329
330 @return The number of ASCII characters in the produced output buffer not including the
331 Null-terminator.
332
333 **/
334 UINTN
335 EFIAPI
336 AsciiVSPrint (
337 OUT CHAR8 *StartOfBuffer,
338 IN UINTN BufferSize,
339 IN CONST CHAR8 *FormatString,
340 IN VA_LIST Marker
341 )
342 {
343 return mPrint2Protocol->AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
344 }
345
346 /**
347 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
348 ASCII format string and variable argument list.
349
350 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
351 and BufferSize.
352 The ASCII string is produced by parsing the format string specified by FormatString.
353 Arguments are pulled from the variable argument list based on the contents of the
354 format string.
355 The number of ASCII characters in the produced output buffer is returned not including
356 the Null-terminator.
357 If BufferSize is 0, then no output buffer is produced and 0 is returned.
358
359 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
360 If BufferSize > 0 and FormatString is NULL, then ASSERT().
361 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
362 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
363 ASSERT().
364 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
365 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
366 Null-terminator, then ASSERT().
367
368 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
369 ASCII string.
370 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
371 @param FormatString Null-terminated Unicode format string.
372 @param ... Variable argument list whose contents are accessed based on the
373 format string specified by FormatString.
374
375 @return The number of ASCII characters in the produced output buffer not including the
376 Null-terminator.
377
378 **/
379 UINTN
380 EFIAPI
381 AsciiSPrint (
382 OUT CHAR8 *StartOfBuffer,
383 IN UINTN BufferSize,
384 IN CONST CHAR8 *FormatString,
385 ...
386 )
387 {
388 VA_LIST Marker;
389
390 VA_START (Marker, FormatString);
391 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
392 }
393
394 /**
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.
397
398 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
399 and BufferSize.
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
404 the Null-terminator.
405 If BufferSize is 0, then no output buffer is produced and 0 is returned.
406
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
412 ASSERT().
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().
416
417 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
418 ASCII string.
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.
422
423 @return The number of ASCII characters in the produced output buffer not including the
424 Null-terminator.
425
426 **/
427 UINTN
428 EFIAPI
429 AsciiVSPrintUnicodeFormat (
430 OUT CHAR8 *StartOfBuffer,
431 IN UINTN BufferSize,
432 IN CONST CHAR16 *FormatString,
433 IN VA_LIST Marker
434 )
435 {
436 return mPrint2Protocol->AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
437 }
438
439 /**
440 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
441 ASCII format string and variable argument list.
442
443 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
444 and BufferSize.
445 The ASCII string is produced by parsing the format string specified by FormatString.
446 Arguments are pulled from the variable argument list based on the contents of the
447 format string.
448 The number of ASCII characters in the produced output buffer is returned not including
449 the Null-terminator.
450 If BufferSize is 0, then no output buffer is produced and 0 is returned.
451
452 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
453 If BufferSize > 0 and FormatString is NULL, then ASSERT().
454 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
455 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
456 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
457 ASSERT().
458 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
459 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
460 Null-terminator, then ASSERT().
461
462 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
463 ASCII string.
464 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
465 @param FormatString Null-terminated Unicode format string.
466 @param ... Variable argument list whose contents are accessed based on the
467 format string specified by FormatString.
468
469 @return The number of ASCII characters in the produced output buffer not including the
470 Null-terminator.
471
472 **/
473 UINTN
474 EFIAPI
475 AsciiSPrintUnicodeFormat (
476 OUT CHAR8 *StartOfBuffer,
477 IN UINTN BufferSize,
478 IN CONST CHAR16 *FormatString,
479 ...
480 )
481 {
482 VA_LIST Marker;
483
484 VA_START (Marker, FormatString);
485 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
486 }
487
488
489 /**
490 Converts a decimal value to a Null-terminated ASCII string.
491
492 Converts the decimal number specified by Value to a Null-terminated ASCII string
493 specified by Buffer containing at most Width characters. No padding of spaces
494 is ever performed.
495 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
496 The number of ASCII characters in Buffer is returned not including the Null-terminator.
497 If the conversion contains more than Width characters, then only the first Width
498 characters are returned, and the total number of characters required to perform
499 the conversion is returned.
500 Additional conversion parameters are specified in Flags.
501 The Flags bit LEFT_JUSTIFY is always ignored.
502 All conversions are left justified in Buffer.
503 If Width is 0, PREFIX_ZERO is ignored in Flags.
504 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
505 are inserted every 3rd digit starting from the right.
506 If HEX_RADIX is set in Flags, then the output buffer will be
507 formatted in hexadecimal format.
508 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
509 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
510 then Buffer is padded with '0' characters so the combination of the optional '-'
511 sign character, '0' characters, digit characters for Value, and the Null-terminator
512 add up to Width characters.
513
514 If Buffer is NULL, then ASSERT().
515 If unsupported bits are set in Flags, then ASSERT().
516 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
517 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
518
519 @param Buffer Pointer to the output buffer for the produced Null-terminated
520 ASCII string.
521 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
522 @param Value The 64-bit signed value to convert to a string.
523 @param Width The maximum number of ASCII characters to place in Buffer, not including
524 the Null-terminator.
525
526 @return The number of ASCII characters in Buffer not including the Null-terminator.
527
528 **/
529 UINTN
530 EFIAPI
531 AsciiValueToString (
532 OUT CHAR8 *Buffer,
533 IN UINTN Flags,
534 IN INT64 Value,
535 IN UINTN Width
536 )
537 {
538 return mPrint2Protocol->AsciiValueToString (Buffer, Flags, Value, Width);
539 }