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