TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiLibPrint.c
Go to the documentation of this file.
1
10#include "UefiLibInternal.h"
11
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
51 IN CONST CHAR16 *Format,
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
69 if (Buffer == NULL) {
70 ASSERT (Buffer != NULL);
71 return 0;
72 }
73
74 Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
75
76 if ((Console != NULL) && (Return > 0)) {
77 //
78 // To be extra safe make sure Console has been initialized
79 //
80 Status = Console->OutputString (Console, Buffer);
81 if (EFI_ERROR (Status)) {
82 Return = 0;
83 }
84 }
85
86 FreePool (Buffer);
87
88 return Return;
89}
90
111UINTN
112EFIAPI
114 IN CONST CHAR16 *Format,
115 ...
116 )
117{
118 VA_LIST Marker;
119 UINTN Return;
120
121 VA_START (Marker, Format);
122
123 Return = InternalPrint (Format, gST->ConOut, Marker);
124
125 VA_END (Marker);
126
127 return Return;
128}
129
150UINTN
151EFIAPI
153 IN CONST CHAR16 *Format,
154 ...
155 )
156{
157 VA_LIST Marker;
158 UINTN Return;
159
160 VA_START (Marker, Format);
161
162 Return = InternalPrint (Format, gST->StdErr, Marker);
163
164 VA_END (Marker);
165
166 return Return;
167}
168
188UINTN
190 IN CONST CHAR8 *Format,
192 IN VA_LIST Marker
193 )
194{
195 EFI_STATUS Status;
196 UINTN Return;
197 CHAR16 *Buffer;
198 UINTN BufferSize;
199
200 ASSERT (Format != NULL);
201 ASSERT (Console != NULL);
202
203 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
204
205 Buffer = (CHAR16 *)AllocatePool (BufferSize);
206
207 if (Buffer == NULL) {
208 ASSERT (Buffer != NULL);
209 return 0;
210 }
211
212 Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
213
214 if (Console != NULL) {
215 //
216 // To be extra safe make sure Console has been initialized
217 //
218 Status = Console->OutputString (Console, Buffer);
219 if (EFI_ERROR (Status)) {
220 Return = 0;
221 }
222 }
223
224 FreePool (Buffer);
225
226 return Return;
227}
228
248UINTN
249EFIAPI
251 IN CONST CHAR8 *Format,
252 ...
253 )
254{
255 VA_LIST Marker;
256 UINTN Return;
257
258 ASSERT (Format != NULL);
259
260 VA_START (Marker, Format);
261
262 Return = AsciiInternalPrint (Format, gST->ConOut, Marker);
263
264 VA_END (Marker);
265
266 return Return;
267}
268
288UINTN
289EFIAPI
291 IN CONST CHAR8 *Format,
292 ...
293 )
294{
295 VA_LIST Marker;
296 UINTN Return;
297
298 ASSERT (Format != NULL);
299
300 VA_START (Marker, Format);
301
302 Return = AsciiInternalPrint (Format, gST->StdErr, Marker);
303
304 VA_END (Marker);
305
306 return Return;
307}
308
342UINTN
344 IN UINTN PointX,
345 IN UINTN PointY,
348 IN CHAR16 *Buffer,
349 IN UINTN PrintNum
350 )
351{
352 EFI_STATUS Status;
353 UINT32 HorizontalResolution;
354 UINT32 VerticalResolution;
355 UINT32 ColorDepth;
356 UINT32 RefreshRate;
357 EFI_HII_FONT_PROTOCOL *HiiFont;
358 EFI_IMAGE_OUTPUT *Blt;
359 EFI_FONT_DISPLAY_INFO FontInfo;
360 EFI_HII_ROW_INFO *RowInfoArray;
361 UINTN RowInfoArraySize;
362 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
363 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
365 EFI_HANDLE ConsoleHandle;
366 UINTN Width;
367 UINTN Height;
368 UINTN Delta;
369
370 HorizontalResolution = 0;
371 VerticalResolution = 0;
372 Blt = NULL;
373 RowInfoArray = NULL;
374
375 ConsoleHandle = gST->ConsoleOutHandle;
376
377 ASSERT (ConsoleHandle != NULL);
378
379 Status = gBS->HandleProtocol (
380 ConsoleHandle,
381 &gEfiGraphicsOutputProtocolGuid,
382 (VOID **)&GraphicsOutput
383 );
384
385 UgaDraw = NULL;
386 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
387 //
388 // If no GOP available, try to open UGA Draw protocol if supported.
389 //
390 GraphicsOutput = NULL;
391
392 Status = gBS->HandleProtocol (
393 ConsoleHandle,
394 &gEfiUgaDrawProtocolGuid,
395 (VOID **)&UgaDraw
396 );
397 }
398
399 if (EFI_ERROR (Status)) {
400 goto Error;
401 }
402
403 Status = gBS->HandleProtocol (
404 ConsoleHandle,
405 &gEfiSimpleTextOutProtocolGuid,
406 (VOID **)&Sto
407 );
408
409 if (EFI_ERROR (Status)) {
410 goto Error;
411 }
412
413 if (GraphicsOutput != NULL) {
414 HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
415 VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
416 } else if ((UgaDraw != NULL) && FeaturePcdGet (PcdUgaConsumeSupport)) {
417 UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);
418 } else {
419 goto Error;
420 }
421
422 ASSERT ((HorizontalResolution != 0) && (VerticalResolution != 0));
423
424 Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **)&HiiFont);
425 if (EFI_ERROR (Status)) {
426 goto Error;
427 }
428
430
431 if (Blt == NULL) {
432 ASSERT (Blt != NULL);
433 goto Error;
434 }
435
436 Blt->Width = (UINT16)(HorizontalResolution);
437 Blt->Height = (UINT16)(VerticalResolution);
438
439 ZeroMem (&FontInfo, sizeof (EFI_FONT_DISPLAY_INFO));
440
441 if (Foreground != NULL) {
442 CopyMem (&FontInfo.ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
443 } else {
444 CopyMem (
445 &FontInfo.ForegroundColor,
446 &mEfiColors[Sto->Mode->Attribute & 0x0f],
448 );
449 }
450
451 if (Background != NULL) {
452 CopyMem (&FontInfo.BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
453 } else {
454 CopyMem (
455 &FontInfo.BackgroundColor,
456 &mEfiColors[Sto->Mode->Attribute >> 4],
458 );
459 }
460
461 if (GraphicsOutput != NULL) {
462 Blt->Image.Screen = GraphicsOutput;
463
464 Status = HiiFont->StringToImage (
465 HiiFont,
466 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |
467 EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |
468 EFI_HII_IGNORE_LINE_BREAK | EFI_HII_DIRECT_TO_SCREEN,
469 Buffer,
470 &FontInfo,
471 &Blt,
472 PointX,
473 PointY,
474 &RowInfoArray,
475 &RowInfoArraySize,
476 NULL
477 );
478 if (EFI_ERROR (Status)) {
479 goto Error;
480 }
481 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
482 ASSERT (UgaDraw != NULL);
483
484 //
485 // Ensure Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow.
486 //
487 if (Blt->Width > DivU64x32 (MAX_UINTN, Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
488 goto Error;
489 }
490
491 Blt->Image.Bitmap = AllocateZeroPool ((UINT32)Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
492 ASSERT (Blt->Image.Bitmap != NULL);
493
494 //
495 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
496 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
497 //
498 Status = HiiFont->StringToImage (
499 HiiFont,
500 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |
501 EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |
502 EFI_HII_IGNORE_LINE_BREAK,
503 Buffer,
504 &FontInfo,
505 &Blt,
506 PointX,
507 PointY,
508 &RowInfoArray,
509 &RowInfoArraySize,
510 NULL
511 );
512
513 if (!EFI_ERROR (Status)) {
514 ASSERT (RowInfoArray != NULL);
515 //
516 // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will
517 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
518 //
519 ASSERT (RowInfoArraySize <= 1);
520
521 if (RowInfoArraySize != 0) {
522 Width = RowInfoArray[0].LineWidth;
523 Height = RowInfoArray[0].LineHeight;
524 Delta = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
525 } else {
526 Width = 0;
527 Height = 0;
528 Delta = 0;
529 }
530
531 Status = UgaDraw->Blt (
532 UgaDraw,
533 (EFI_UGA_PIXEL *)Blt->Image.Bitmap,
535 PointX,
536 PointY,
537 PointX,
538 PointY,
539 Width,
540 Height,
541 Delta
542 );
543 } else {
544 goto Error;
545 }
546
547 FreePool (Blt->Image.Bitmap);
548 } else {
549 goto Error;
550 }
551
552 //
553 // Calculate the number of actual printed characters
554 //
555 if (RowInfoArraySize != 0) {
556 PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;
557 } else {
558 PrintNum = 0;
559 }
560
561 FreePool (RowInfoArray);
562 FreePool (Blt);
563 return PrintNum;
564
565Error:
566 if (Blt != NULL) {
567 FreePool (Blt);
568 }
569
570 return 0;
571}
572
615UINTN
616EFIAPI
618 IN UINTN PointX,
619 IN UINTN PointY,
620 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL,
621 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL,
622 IN CONST CHAR16 *Format,
623 ...
624 )
625{
626 VA_LIST Marker;
627 CHAR16 *Buffer;
628 UINTN BufferSize;
629 UINTN PrintNum;
630 UINTN ReturnNum;
631
632 ASSERT (Format != NULL);
633 ASSERT (((UINTN)Format & BIT0) == 0);
634
635 VA_START (Marker, Format);
636
637 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
638
639 Buffer = (CHAR16 *)AllocatePool (BufferSize);
640
641 if (Buffer == NULL) {
642 ASSERT (Buffer != NULL);
643 return 0;
644 }
645
646 PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
647
648 VA_END (Marker);
649
650 ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);
651
652 FreePool (Buffer);
653
654 return ReturnNum;
655}
656
698UINTN
699EFIAPI
701 IN UINTN PointX,
702 IN UINTN PointY,
703 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL,
704 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL,
705 IN CONST CHAR8 *Format,
706 ...
707 )
708{
709 VA_LIST Marker;
710 CHAR16 *Buffer;
711 UINTN BufferSize;
712 UINTN PrintNum;
713 UINTN ReturnNum;
714
715 ASSERT (Format != NULL);
716
717 VA_START (Marker, Format);
718
719 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
720
721 Buffer = (CHAR16 *)AllocatePool (BufferSize);
722
723 if (Buffer == NULL) {
724 ASSERT (Buffer != NULL);
725 return 0;
726 }
727
728 PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
729
730 VA_END (Marker);
731
732 ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);
733
734 FreePool (Buffer);
735
736 return ReturnNum;
737}
738
760CHAR16 *
761EFIAPI
763 IN CHAR16 *String OPTIONAL,
764 IN CONST CHAR16 *FormatString,
765 IN VA_LIST Marker
766 )
767{
768 UINTN CharactersRequired;
769 UINTN SizeRequired;
770 CHAR16 *BufferToReturn;
771 VA_LIST ExtraMarker;
772
773 VA_COPY (ExtraMarker, Marker);
774 CharactersRequired = SPrintLength (FormatString, ExtraMarker);
775 VA_END (ExtraMarker);
776
777 if (String != NULL) {
778 SizeRequired = StrSize (String) + (CharactersRequired * sizeof (CHAR16));
779 } else {
780 SizeRequired = sizeof (CHAR16) + (CharactersRequired * sizeof (CHAR16));
781 }
782
783 BufferToReturn = AllocatePool (SizeRequired);
784
785 if (BufferToReturn == NULL) {
786 return NULL;
787 } else {
788 BufferToReturn[0] = L'\0';
789 }
790
791 if (String != NULL) {
792 StrCpyS (BufferToReturn, SizeRequired / sizeof (CHAR16), String);
793 }
794
795 UnicodeVSPrint (BufferToReturn + StrLen (BufferToReturn), (CharactersRequired+1) * sizeof (CHAR16), FormatString, Marker);
796
797 ASSERT (StrSize (BufferToReturn) == SizeRequired);
798
799 return (BufferToReturn);
800}
801
825CHAR16 *
826EFIAPI
828 IN CHAR16 *String OPTIONAL,
829 IN CONST CHAR16 *FormatString,
830 ...
831 )
832{
833 VA_LIST Marker;
834 CHAR16 *NewString;
835
836 VA_START (Marker, FormatString);
837 NewString = CatVSPrint (String, FormatString, Marker);
838 VA_END (Marker);
839 return NewString;
840}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:226
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI UnicodeVSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:287
UINTN EFIAPI UnicodeVSPrintAsciiFormat(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:465
UINTN EFIAPI UnicodeSPrintAsciiFormat(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:583
UINTN EFIAPI SPrintLength(IN CONST CHAR16 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:2091
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VA_START(Marker, Parameter)
Definition: Base.h:661
#define VA_COPY(Dest, Start)
Definition: Base.h:704
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define VA_END(Marker)
Definition: Base.h:691
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STRING_ID NewString(IN CHAR16 *String, IN EFI_HII_HANDLE HiiHandle)
Definition: Setup.c:981
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
UINTN AsciiInternalPrint(IN CONST CHAR8 *Format, IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console, IN VA_LIST Marker)
Definition: UefiLibPrint.c:189
UINTN EFIAPI PrintXY(IN UINTN PointX, IN UINTN PointY, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL, IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:617
CHAR16 *EFIAPI CatVSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString, IN VA_LIST Marker)
Definition: UefiLibPrint.c:762
UINTN EFIAPI AsciiErrorPrint(IN CONST CHAR8 *Format,...)
Definition: UefiLibPrint.c:290
UINTN EFIAPI AsciiPrint(IN CONST CHAR8 *Format,...)
Definition: UefiLibPrint.c:250
UINTN InternalPrintGraphic(IN UINTN PointX, IN UINTN PointY, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background, IN CHAR16 *Buffer, IN UINTN PrintNum)
Definition: UefiLibPrint.c:343
UINTN EFIAPI ErrorPrint(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:152
CHAR16 *EFIAPI CatSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString,...)
Definition: UefiLibPrint.c:827
UINTN InternalPrint(IN CONST CHAR16 *Format, IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console, IN VA_LIST Marker)
Definition: UefiLibPrint.c:50
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113
UINTN EFIAPI AsciiPrintXY(IN UINTN PointX, IN UINTN PointY, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL, IN CONST CHAR8 *Format,...)
Definition: UefiLibPrint.c:700
@ EfiUgaBltBufferToVideo
Definition: UgaDraw.h:96
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
UINTN StartIndex
Definition: HiiFont.h:46
UINTN LineHeight
The height of the line, in pixels.
Definition: HiiFont.h:52
UINTN LineWidth
The width of the text on the line, in pixels.
Definition: HiiFont.h:53
UINTN EndIndex
Definition: HiiFont.h:51
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * Info
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * StdErr
Definition: UefiSpec.h:2075
EFI_HANDLE ConsoleOutHandle
Definition: UefiSpec.h:2059
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064