]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiLibPrint.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiLibPrint.c
1 /** @file
2 Mde UEFI library API implementation.
3 Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE
4
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "UefiLibInternal.h"
11
12 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
13 { 0x00, 0x00, 0x00, 0x00 },
14 { 0x98, 0x00, 0x00, 0x00 },
15 { 0x00, 0x98, 0x00, 0x00 },
16 { 0x98, 0x98, 0x00, 0x00 },
17 { 0x00, 0x00, 0x98, 0x00 },
18 { 0x98, 0x00, 0x98, 0x00 },
19 { 0x00, 0x98, 0x98, 0x00 },
20 { 0x98, 0x98, 0x98, 0x00 },
21 { 0x10, 0x10, 0x10, 0x00 },
22 { 0xff, 0x10, 0x10, 0x00 },
23 { 0x10, 0xff, 0x10, 0x00 },
24 { 0xff, 0xff, 0x10, 0x00 },
25 { 0x10, 0x10, 0xff, 0x00 },
26 { 0xf0, 0x10, 0xff, 0x00 },
27 { 0x10, 0xff, 0xff, 0x00 },
28 { 0xff, 0xff, 0xff, 0x00 }
29 };
30
31 /**
32 Internal function which prints a formatted Unicode string to the console output device
33 specified by Console
34
35 This function prints a formatted Unicode string to the console output device
36 specified by Console and returns the number of Unicode characters that printed
37 to it. If the length of the formatted Unicode string is greater than PcdUefiLibMaxPrintBufferSize,
38 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.
39 If Format is NULL, then ASSERT().
40 If Format is not aligned on a 16-bit boundary, then ASSERT().
41
42 @param Format A Null-terminated Unicode format string.
43 @param Console The output console.
44 @param Marker A VA_LIST marker for the variable argument list.
45
46 @return The number of Unicode characters in the produced
47 output buffer, not including the Null-terminator.
48 **/
49 UINTN
50 InternalPrint (
51 IN CONST CHAR16 *Format,
52 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,
53 IN VA_LIST Marker
54 )
55 {
56 EFI_STATUS Status;
57 UINTN Return;
58 CHAR16 *Buffer;
59 UINTN BufferSize;
60
61 ASSERT (Format != NULL);
62 ASSERT (((UINTN) Format & BIT0) == 0);
63 ASSERT (Console != NULL);
64
65 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
66
67 Buffer = (CHAR16 *) AllocatePool(BufferSize);
68 ASSERT (Buffer != NULL);
69
70 Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
71
72 if (Console != NULL && Return > 0) {
73 //
74 // To be extra safe make sure Console has been initialized
75 //
76 Status = Console->OutputString (Console, Buffer);
77 if (EFI_ERROR (Status)) {
78 Return = 0;
79 }
80 }
81
82 FreePool (Buffer);
83
84 return Return;
85 }
86
87 /**
88 Prints a formatted Unicode string to the console output device specified by
89 ConOut defined in the EFI_SYSTEM_TABLE.
90
91 This function prints a formatted Unicode string to the console output device
92 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of Unicode
93 characters that printed to ConOut. If the length of the formatted Unicode
94 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
95 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.
96 If Format is NULL, then ASSERT().
97 If Format is not aligned on a 16-bit boundary, then ASSERT().
98 If gST->ConOut is NULL, then ASSERT().
99
100 @param Format A Null-terminated Unicode format string.
101 @param ... A Variable argument list whose contents are accessed based
102 on the format string specified by Format.
103
104 @return The number of Unicode characters printed to ConOut.
105
106 **/
107 UINTN
108 EFIAPI
109 Print (
110 IN CONST CHAR16 *Format,
111 ...
112 )
113 {
114 VA_LIST Marker;
115 UINTN Return;
116
117 VA_START (Marker, Format);
118
119 Return = InternalPrint (Format, gST->ConOut, Marker);
120
121 VA_END (Marker);
122
123 return Return;
124 }
125
126 /**
127 Prints a formatted Unicode string to the console output device specified by
128 StdErr defined in the EFI_SYSTEM_TABLE.
129
130 This function prints a formatted Unicode string to the console output device
131 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of Unicode
132 characters that printed to StdErr. If the length of the formatted Unicode
133 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
134 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.
135 If Format is NULL, then ASSERT().
136 If Format is not aligned on a 16-bit boundary, then ASSERT().
137 If gST->StdErr is NULL, then ASSERT().
138
139 @param Format A Null-terminated Unicode format string.
140 @param ... Variable argument list whose contents are accessed based
141 on the format string specified by Format.
142
143 @return The number of Unicode characters printed to StdErr.
144
145 **/
146 UINTN
147 EFIAPI
148 ErrorPrint (
149 IN CONST CHAR16 *Format,
150 ...
151 )
152 {
153 VA_LIST Marker;
154 UINTN Return;
155
156 VA_START (Marker, Format);
157
158 Return = InternalPrint( Format, gST->StdErr, Marker);
159
160 VA_END (Marker);
161
162 return Return;
163 }
164
165
166 /**
167 Internal function which prints a formatted ASCII string to the console output device
168 specified by Console
169
170 This function prints a formatted ASCII string to the console output device
171 specified by Console and returns the number of ASCII characters that printed
172 to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,
173 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.
174
175 If Format is NULL, then ASSERT().
176
177 @param Format A Null-terminated ASCII format string.
178 @param Console The output console.
179 @param Marker VA_LIST marker for the variable argument list.
180
181 @return The number of Unicode characters in the produced
182 output buffer not including the Null-terminator.
183
184 **/
185 UINTN
186 AsciiInternalPrint (
187 IN CONST CHAR8 *Format,
188 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,
189 IN VA_LIST Marker
190 )
191 {
192 EFI_STATUS Status;
193 UINTN Return;
194 CHAR16 *Buffer;
195 UINTN BufferSize;
196
197 ASSERT (Format != NULL);
198 ASSERT (Console != NULL);
199
200 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
201
202 Buffer = (CHAR16 *) AllocatePool(BufferSize);
203 ASSERT (Buffer != NULL);
204
205 Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
206
207 if (Console != NULL) {
208 //
209 // To be extra safe make sure Console has been initialized
210 //
211 Status = Console->OutputString (Console, Buffer);
212 if (EFI_ERROR (Status)) {
213 Return = 0;
214 }
215 }
216
217 FreePool (Buffer);
218
219 return Return;
220 }
221
222 /**
223 Prints a formatted ASCII string to the console output device specified by
224 ConOut defined in the EFI_SYSTEM_TABLE.
225
226 This function prints a formatted ASCII string to the console output device
227 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII
228 characters that printed to ConOut. If the length of the formatted ASCII
229 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
230 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.
231 If Format is NULL, then ASSERT().
232 If gST->ConOut is NULL, then ASSERT().
233
234 @param Format A Null-terminated ASCII format string.
235 @param ... Variable argument list whose contents are accessed based
236 on the format string specified by Format.
237
238 @return The number of ASCII characters printed to ConOut.
239
240 **/
241 UINTN
242 EFIAPI
243 AsciiPrint (
244 IN CONST CHAR8 *Format,
245 ...
246 )
247 {
248 VA_LIST Marker;
249 UINTN Return;
250 ASSERT (Format != NULL);
251
252 VA_START (Marker, Format);
253
254 Return = AsciiInternalPrint( Format, gST->ConOut, Marker);
255
256 VA_END (Marker);
257
258 return Return;
259 }
260
261 /**
262 Prints a formatted ASCII string to the console output device specified by
263 StdErr defined in the EFI_SYSTEM_TABLE.
264
265 This function prints a formatted ASCII string to the console output device
266 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII
267 characters that printed to StdErr. If the length of the formatted ASCII
268 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
269 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.
270 If Format is NULL, then ASSERT().
271 If gST->StdErr is NULL, then ASSERT().
272
273 @param Format A Null-terminated ASCII format string.
274 @param ... Variable argument list whose contents are accessed based
275 on the format string specified by Format.
276
277 @return The number of ASCII characters printed to ConErr.
278
279 **/
280 UINTN
281 EFIAPI
282 AsciiErrorPrint (
283 IN CONST CHAR8 *Format,
284 ...
285 )
286 {
287 VA_LIST Marker;
288 UINTN Return;
289
290 ASSERT (Format != NULL);
291
292 VA_START (Marker, Format);
293
294 Return = AsciiInternalPrint( Format, gST->StdErr, Marker);
295
296 VA_END (Marker);
297
298 return Return;
299 }
300
301 /**
302 Internal function to print a formatted Unicode string to a graphics console device specified by
303 ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.
304
305 This function prints a formatted Unicode string to the graphics console device
306 specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of
307 Unicode characters printed. The EFI_HII_FONT_PROTOCOL is used to convert the
308 string to a bitmap using the glyphs registered with the
309 HII database. No wrapping is performed, so any portions of the string the fall
310 outside the active display region will not be displayed.
311
312 If a graphics console device is not associated with the ConsoleOutputHandle
313 defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.
314 If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no
315 string is printed, and 0 is returned.
316
317 @param PointX An X coordinate to print the string.
318 @param PointY A Y coordinate to print the string.
319 @param Foreground The foreground color of the string being printed. This is
320 an optional parameter that may be NULL. If it is NULL,
321 then the foreground color of the current ConOut device
322 in the EFI_SYSTEM_TABLE is used.
323 @param Background The background color of the string being printed. This is
324 an optional parameter that may be NULL. If it is NULL,
325 then the background color of the current ConOut device
326 in the EFI_SYSTEM_TABLE is used.
327 @param Buffer A Null-terminated Unicode formatted string.
328 @param PrintNum The number of Unicode formatted string to be printed.
329
330 @return The number of Unicode Characters printed. Zero means no any character
331 displayed successfully.
332
333 **/
334 UINTN
335 InternalPrintGraphic (
336 IN UINTN PointX,
337 IN UINTN PointY,
338 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
339 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background,
340 IN CHAR16 *Buffer,
341 IN UINTN PrintNum
342 )
343 {
344 EFI_STATUS Status;
345 UINT32 HorizontalResolution;
346 UINT32 VerticalResolution;
347 UINT32 ColorDepth;
348 UINT32 RefreshRate;
349 EFI_HII_FONT_PROTOCOL *HiiFont;
350 EFI_IMAGE_OUTPUT *Blt;
351 EFI_FONT_DISPLAY_INFO FontInfo;
352 EFI_HII_ROW_INFO *RowInfoArray;
353 UINTN RowInfoArraySize;
354 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
355 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
356 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
357 EFI_HANDLE ConsoleHandle;
358 UINTN Width;
359 UINTN Height;
360 UINTN Delta;
361
362 HorizontalResolution = 0;
363 VerticalResolution = 0;
364 Blt = NULL;
365 RowInfoArray = NULL;
366
367 ConsoleHandle = gST->ConsoleOutHandle;
368
369 ASSERT( ConsoleHandle != NULL);
370
371 Status = gBS->HandleProtocol (
372 ConsoleHandle,
373 &gEfiGraphicsOutputProtocolGuid,
374 (VOID **) &GraphicsOutput
375 );
376
377 UgaDraw = NULL;
378 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
379 //
380 // If no GOP available, try to open UGA Draw protocol if supported.
381 //
382 GraphicsOutput = NULL;
383
384 Status = gBS->HandleProtocol (
385 ConsoleHandle,
386 &gEfiUgaDrawProtocolGuid,
387 (VOID **) &UgaDraw
388 );
389 }
390 if (EFI_ERROR (Status)) {
391 goto Error;
392 }
393
394 Status = gBS->HandleProtocol (
395 ConsoleHandle,
396 &gEfiSimpleTextOutProtocolGuid,
397 (VOID **) &Sto
398 );
399
400 if (EFI_ERROR (Status)) {
401 goto Error;
402 }
403
404 if (GraphicsOutput != NULL) {
405 HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
406 VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
407 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
408 UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);
409 } else {
410 goto Error;
411 }
412
413 ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));
414
415 Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont);
416 if (EFI_ERROR (Status)) {
417 goto Error;
418 }
419
420 Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
421 ASSERT (Blt != NULL);
422
423 Blt->Width = (UINT16) (HorizontalResolution);
424 Blt->Height = (UINT16) (VerticalResolution);
425
426 ZeroMem (&FontInfo, sizeof (EFI_FONT_DISPLAY_INFO));
427
428 if (Foreground != NULL) {
429 CopyMem (&FontInfo.ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
430 } else {
431 CopyMem (
432 &FontInfo.ForegroundColor,
433 &mEfiColors[Sto->Mode->Attribute & 0x0f],
434 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
435 );
436 }
437 if (Background != NULL) {
438 CopyMem (&FontInfo.BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
439 } else {
440 CopyMem (
441 &FontInfo.BackgroundColor,
442 &mEfiColors[Sto->Mode->Attribute >> 4],
443 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
444 );
445 }
446
447 if (GraphicsOutput != NULL) {
448 Blt->Image.Screen = GraphicsOutput;
449
450 Status = HiiFont->StringToImage (
451 HiiFont,
452 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |
453 EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |
454 EFI_HII_IGNORE_LINE_BREAK | EFI_HII_DIRECT_TO_SCREEN,
455 Buffer,
456 &FontInfo,
457 &Blt,
458 PointX,
459 PointY,
460 &RowInfoArray,
461 &RowInfoArraySize,
462 NULL
463 );
464 if (EFI_ERROR (Status)) {
465 goto Error;
466 }
467
468 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
469 ASSERT (UgaDraw!= NULL);
470
471 //
472 // Ensure Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow.
473 //
474 if (Blt->Width > DivU64x32 (MAX_UINTN, Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
475 goto Error;
476 }
477
478 Blt->Image.Bitmap = AllocateZeroPool ((UINT32) Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
479 ASSERT (Blt->Image.Bitmap != NULL);
480
481 //
482 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
483 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
484 //
485 Status = HiiFont->StringToImage (
486 HiiFont,
487 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |
488 EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |
489 EFI_HII_IGNORE_LINE_BREAK,
490 Buffer,
491 &FontInfo,
492 &Blt,
493 PointX,
494 PointY,
495 &RowInfoArray,
496 &RowInfoArraySize,
497 NULL
498 );
499
500 if (!EFI_ERROR (Status)) {
501 ASSERT (RowInfoArray != NULL);
502 //
503 // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will
504 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
505 //
506 ASSERT (RowInfoArraySize <= 1);
507
508 if (RowInfoArraySize != 0) {
509 Width = RowInfoArray[0].LineWidth;
510 Height = RowInfoArray[0].LineHeight;
511 Delta = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
512 } else {
513 Width = 0;
514 Height = 0;
515 Delta = 0;
516 }
517 Status = UgaDraw->Blt (
518 UgaDraw,
519 (EFI_UGA_PIXEL *) Blt->Image.Bitmap,
520 EfiUgaBltBufferToVideo,
521 PointX,
522 PointY,
523 PointX,
524 PointY,
525 Width,
526 Height,
527 Delta
528 );
529 } else {
530 goto Error;
531 }
532 FreePool (Blt->Image.Bitmap);
533 } else {
534 goto Error;
535 }
536 //
537 // Calculate the number of actual printed characters
538 //
539 if (RowInfoArraySize != 0) {
540 PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;
541 } else {
542 PrintNum = 0;
543 }
544
545 FreePool (RowInfoArray);
546 FreePool (Blt);
547 return PrintNum;
548
549 Error:
550 if (Blt != NULL) {
551 FreePool (Blt);
552 }
553 return 0;
554 }
555
556 /**
557 Prints a formatted Unicode string to a graphics console device specified by
558 ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.
559
560 This function prints a formatted Unicode string to the graphics console device
561 specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of
562 Unicode characters displayed, not including partial characters that may be clipped
563 by the right edge of the display. If the length of the formatted Unicode string is
564 greater than PcdUefiLibMaxPrintBufferSize, then at most the first
565 PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL
566 StringToImage() service is used to convert the string to a bitmap using the glyphs
567 registered with the HII database. No wrapping is performed, so any portions of the
568 string the fall outside the active display region will not be displayed. Please see
569 Section 27.2.6 of the UEFI Specification for a description of the supported string
570 format including the set of control codes supported by the StringToImage() service.
571
572 If a graphics console device is not associated with the ConsoleOutputHandle
573 defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.
574 If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no
575 string is printed, and 0 is returned.
576 If Format is NULL, then ASSERT().
577 If Format is not aligned on a 16-bit boundary, then ASSERT().
578 If gST->ConsoleOutputHandle is NULL, then ASSERT().
579
580 @param PointX An X coordinate to print the string.
581 @param PointY A Y coordinate to print the string.
582 @param ForeGround The foreground color of the string being printed. This is
583 an optional parameter that may be NULL. If it is NULL,
584 then the foreground color of the current ConOut device
585 in the EFI_SYSTEM_TABLE is used.
586 @param BackGround The background color of the string being printed. This is
587 an optional parameter that may be NULL. If it is NULL,
588 then the background color of the current ConOut device
589 in the EFI_SYSTEM_TABLE is used.
590 @param Format A Null-terminated Unicode format string. See Print Library
591 for the supported format string syntax.
592 @param ... A Variable argument list whose contents are accessed based on
593 the format string specified by Format.
594
595 @return The number of Unicode characters printed.
596
597 **/
598 UINTN
599 EFIAPI
600 PrintXY (
601 IN UINTN PointX,
602 IN UINTN PointY,
603 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL
604 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL
605 IN CONST CHAR16 *Format,
606 ...
607 )
608 {
609 VA_LIST Marker;
610 CHAR16 *Buffer;
611 UINTN BufferSize;
612 UINTN PrintNum;
613 UINTN ReturnNum;
614
615 ASSERT (Format != NULL);
616 ASSERT (((UINTN) Format & BIT0) == 0);
617
618 VA_START (Marker, Format);
619
620 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
621
622 Buffer = (CHAR16 *) AllocatePool (BufferSize);
623 ASSERT (Buffer != NULL);
624
625 PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
626
627 VA_END (Marker);
628
629 ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);
630
631 FreePool (Buffer);
632
633 return ReturnNum;
634 }
635
636 /**
637 Prints a formatted ASCII string to a graphics console device specified by
638 ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.
639
640 This function prints a formatted ASCII string to the graphics console device
641 specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of
642 ASCII characters displayed, not including partial characters that may be clipped
643 by the right edge of the display. If the length of the formatted ASCII string is
644 greater than PcdUefiLibMaxPrintBufferSize, then at most the first
645 PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL
646 StringToImage() service is used to convert the string to a bitmap using the glyphs
647 registered with the HII database. No wrapping is performed, so any portions of the
648 string the fall outside the active display region will not be displayed. Please see
649 Section 27.2.6 of the UEFI Specification for a description of the supported string
650 format including the set of control codes supported by the StringToImage() service.
651
652 If a graphics console device is not associated with the ConsoleOutputHandle
653 defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.
654 If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no
655 string is printed, and 0 is returned.
656 If Format is NULL, then ASSERT().
657 If gST->ConsoleOutputHandle is NULL, then ASSERT().
658
659 @param PointX An X coordinate to print the string.
660 @param PointY A Y coordinate to print the string.
661 @param ForeGround The foreground color of the string being printed. This is
662 an optional parameter that may be NULL. If it is NULL,
663 then the foreground color of the current ConOut device
664 in the EFI_SYSTEM_TABLE is used.
665 @param BackGround The background color of the string being printed. This is
666 an optional parameter that may be NULL. If it is NULL,
667 then the background color of the current ConOut device
668 in the EFI_SYSTEM_TABLE is used.
669 @param Format A Null-terminated ASCII format string. See Print Library
670 for the supported format string syntax.
671 @param ... Variable argument list whose contents are accessed based on
672 the format string specified by Format.
673
674 @return The number of ASCII characters printed.
675
676 **/
677 UINTN
678 EFIAPI
679 AsciiPrintXY (
680 IN UINTN PointX,
681 IN UINTN PointY,
682 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL
683 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL
684 IN CONST CHAR8 *Format,
685 ...
686 )
687 {
688 VA_LIST Marker;
689 CHAR16 *Buffer;
690 UINTN BufferSize;
691 UINTN PrintNum;
692 UINTN ReturnNum;
693
694 ASSERT (Format != NULL);
695
696 VA_START (Marker, Format);
697
698 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
699
700 Buffer = (CHAR16 *) AllocatePool (BufferSize);
701 ASSERT (Buffer != NULL);
702
703 PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
704
705 VA_END (Marker);
706
707 ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);
708
709 FreePool (Buffer);
710
711 return ReturnNum;
712 }
713
714 /**
715 Appends a formatted Unicode string to a Null-terminated Unicode string
716
717 This function appends a formatted Unicode string to the Null-terminated
718 Unicode string specified by String. String is optional and may be NULL.
719 Storage for the formatted Unicode string returned is allocated using
720 AllocatePool(). The pointer to the appended string is returned. The caller
721 is responsible for freeing the returned string.
722
723 If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
724 If FormatString is NULL, then ASSERT().
725 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
726
727 @param[in] String A Null-terminated Unicode string.
728 @param[in] FormatString A Null-terminated Unicode format string.
729 @param[in] Marker VA_LIST marker for the variable argument list.
730
731 @retval NULL There was not enough available memory.
732 @return Null-terminated Unicode string is that is the formatted
733 string appended to String.
734 **/
735 CHAR16*
736 EFIAPI
737 CatVSPrint (
738 IN CHAR16 *String, OPTIONAL
739 IN CONST CHAR16 *FormatString,
740 IN VA_LIST Marker
741 )
742 {
743 UINTN CharactersRequired;
744 UINTN SizeRequired;
745 CHAR16 *BufferToReturn;
746 VA_LIST ExtraMarker;
747
748 VA_COPY (ExtraMarker, Marker);
749 CharactersRequired = SPrintLength(FormatString, ExtraMarker);
750 VA_END (ExtraMarker);
751
752 if (String != NULL) {
753 SizeRequired = StrSize(String) + (CharactersRequired * sizeof(CHAR16));
754 } else {
755 SizeRequired = sizeof(CHAR16) + (CharactersRequired * sizeof(CHAR16));
756 }
757
758 BufferToReturn = AllocatePool(SizeRequired);
759
760 if (BufferToReturn == NULL) {
761 return NULL;
762 } else {
763 BufferToReturn[0] = L'\0';
764 }
765
766 if (String != NULL) {
767 StrCpyS(BufferToReturn, SizeRequired / sizeof(CHAR16), String);
768 }
769
770 UnicodeVSPrint(BufferToReturn + StrLen(BufferToReturn), (CharactersRequired+1) * sizeof(CHAR16), FormatString, Marker);
771
772 ASSERT(StrSize(BufferToReturn)==SizeRequired);
773
774 return (BufferToReturn);
775 }
776
777 /**
778 Appends a formatted Unicode string to a Null-terminated Unicode string
779
780 This function appends a formatted Unicode string to the Null-terminated
781 Unicode string specified by String. String is optional and may be NULL.
782 Storage for the formatted Unicode string returned is allocated using
783 AllocatePool(). The pointer to the appended string is returned. The caller
784 is responsible for freeing the returned string.
785
786 If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
787 If FormatString is NULL, then ASSERT().
788 If FormatString is not aligned on a 16-bit boundary, then ASSERT().
789
790 @param[in] String A Null-terminated Unicode string.
791 @param[in] FormatString A Null-terminated Unicode format string.
792 @param[in] ... The variable argument list whose contents are
793 accessed based on the format string specified by
794 FormatString.
795
796 @retval NULL There was not enough available memory.
797 @return Null-terminated Unicode string is that is the formatted
798 string appended to String.
799 **/
800 CHAR16 *
801 EFIAPI
802 CatSPrint (
803 IN CHAR16 *String, OPTIONAL
804 IN CONST CHAR16 *FormatString,
805 ...
806 )
807 {
808 VA_LIST Marker;
809 CHAR16 *NewString;
810
811 VA_START (Marker, FormatString);
812 NewString = CatVSPrint(String, FormatString, Marker);
813 VA_END (Marker);
814 return NewString;
815 }
816