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 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;
362 EFI_HANDLE ConsoleHandle;
363
364 HorizontalResolution = 0;
365 VerticalResolution = 0;
366 Blt = NULL;
367 RowInfoArray = NULL;
368
369 ConsoleHandle = gST->ConsoleOutHandle;
370
371 ASSERT (ConsoleHandle != NULL);
372
373 Status = gBS->HandleProtocol (
374 ConsoleHandle,
375 &gEfiGraphicsOutputProtocolGuid,
376 (VOID **)&GraphicsOutput
377 );
378 if (EFI_ERROR (Status)) {
379 goto Error;
380 }
381
382 Status = gBS->HandleProtocol (
383 ConsoleHandle,
384 &gEfiSimpleTextOutProtocolGuid,
385 (VOID **)&Sto
386 );
387
388 if (EFI_ERROR (Status)) {
389 goto Error;
390 }
391
392 if (GraphicsOutput != NULL) {
393 HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
394 VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
395 } else {
396 goto Error;
397 }
398
399 ASSERT ((HorizontalResolution != 0) && (VerticalResolution != 0));
400
401 Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **)&HiiFont);
402 if (EFI_ERROR (Status)) {
403 goto Error;
404 }
405
407
408 if (Blt == NULL) {
409 ASSERT (Blt != NULL);
410 goto Error;
411 }
412
413 Blt->Width = (UINT16)(HorizontalResolution);
414 Blt->Height = (UINT16)(VerticalResolution);
415
416 ZeroMem (&FontInfo, sizeof (EFI_FONT_DISPLAY_INFO));
417
418 if (Foreground != NULL) {
419 CopyMem (&FontInfo.ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
420 } else {
421 CopyMem (
422 &FontInfo.ForegroundColor,
423 &mEfiColors[Sto->Mode->Attribute & 0x0f],
425 );
426 }
427
428 if (Background != NULL) {
429 CopyMem (&FontInfo.BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
430 } else {
431 CopyMem (
432 &FontInfo.BackgroundColor,
433 &mEfiColors[Sto->Mode->Attribute >> 4],
435 );
436 }
437
438 if (GraphicsOutput != NULL) {
439 Blt->Image.Screen = GraphicsOutput;
440
441 Status = HiiFont->StringToImage (
442 HiiFont,
443 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |
444 EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |
445 EFI_HII_IGNORE_LINE_BREAK | EFI_HII_DIRECT_TO_SCREEN,
446 Buffer,
447 &FontInfo,
448 &Blt,
449 PointX,
450 PointY,
451 &RowInfoArray,
452 &RowInfoArraySize,
453 NULL
454 );
455 if (EFI_ERROR (Status)) {
456 goto Error;
457 }
458 } else {
459 goto Error;
460 }
461
462 //
463 // Calculate the number of actual printed characters
464 //
465 if (RowInfoArraySize != 0) {
466 PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;
467 } else {
468 PrintNum = 0;
469 }
470
471 FreePool (RowInfoArray);
472 FreePool (Blt);
473 return PrintNum;
474
475Error:
476 if (Blt != NULL) {
477 FreePool (Blt);
478 }
479
480 return 0;
481}
482
525UINTN
526EFIAPI
528 IN UINTN PointX,
529 IN UINTN PointY,
530 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL,
531 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL,
532 IN CONST CHAR16 *Format,
533 ...
534 )
535{
536 VA_LIST Marker;
537 CHAR16 *Buffer;
538 UINTN BufferSize;
539 UINTN PrintNum;
540 UINTN ReturnNum;
541
542 ASSERT (Format != NULL);
543 ASSERT (((UINTN)Format & BIT0) == 0);
544
545 VA_START (Marker, Format);
546
547 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
548
549 Buffer = (CHAR16 *)AllocatePool (BufferSize);
550
551 if (Buffer == NULL) {
552 ASSERT (Buffer != NULL);
553 return 0;
554 }
555
556 PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);
557
558 VA_END (Marker);
559
560 ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);
561
562 FreePool (Buffer);
563
564 return ReturnNum;
565}
566
608UINTN
609EFIAPI
611 IN UINTN PointX,
612 IN UINTN PointY,
613 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL,
614 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL,
615 IN CONST CHAR8 *Format,
616 ...
617 )
618{
619 VA_LIST Marker;
620 CHAR16 *Buffer;
621 UINTN BufferSize;
622 UINTN PrintNum;
623 UINTN ReturnNum;
624
625 ASSERT (Format != NULL);
626
627 VA_START (Marker, Format);
628
629 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
630
631 Buffer = (CHAR16 *)AllocatePool (BufferSize);
632
633 if (Buffer == NULL) {
634 ASSERT (Buffer != NULL);
635 return 0;
636 }
637
638 PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
639
640 VA_END (Marker);
641
642 ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);
643
644 FreePool (Buffer);
645
646 return ReturnNum;
647}
648
670CHAR16 *
671EFIAPI
673 IN CHAR16 *String OPTIONAL,
674 IN CONST CHAR16 *FormatString,
675 IN VA_LIST Marker
676 )
677{
678 UINTN CharactersRequired;
679 UINTN SizeRequired;
680 CHAR16 *BufferToReturn;
681 VA_LIST ExtraMarker;
682
683 VA_COPY (ExtraMarker, Marker);
684 CharactersRequired = SPrintLength (FormatString, ExtraMarker);
685 VA_END (ExtraMarker);
686
687 if (String != NULL) {
688 SizeRequired = StrSize (String) + (CharactersRequired * sizeof (CHAR16));
689 } else {
690 SizeRequired = sizeof (CHAR16) + (CharactersRequired * sizeof (CHAR16));
691 }
692
693 BufferToReturn = AllocatePool (SizeRequired);
694
695 if (BufferToReturn == NULL) {
696 return NULL;
697 } else {
698 BufferToReturn[0] = L'\0';
699 }
700
701 if (String != NULL) {
702 StrCpyS (BufferToReturn, SizeRequired / sizeof (CHAR16), String);
703 }
704
705 UnicodeVSPrint (BufferToReturn + StrLen (BufferToReturn), (CharactersRequired+1) * sizeof (CHAR16), FormatString, Marker);
706
707 ASSERT (StrSize (BufferToReturn) == SizeRequired);
708
709 return (BufferToReturn);
710}
711
735CHAR16 *
736EFIAPI
738 IN CHAR16 *String OPTIONAL,
739 IN CONST CHAR16 *FormatString,
740 ...
741 )
742{
743 VA_LIST Marker;
744 CHAR16 *NewString;
745
746 VA_START (Marker, FormatString);
747 NewString = CatVSPrint (String, FormatString, Marker);
748 VA_END (Marker);
749 return NewString;
750}
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
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 VOID
Definition: Base.h:269
#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
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STRING_ID NewString(IN CHAR16 *String, IN EFI_HII_HANDLE HiiHandle)
Definition: Setup.c:1012
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:527
CHAR16 *EFIAPI CatVSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString, IN VA_LIST Marker)
Definition: UefiLibPrint.c:672
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:737
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:610
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
UINTN StartIndex
Definition: HiiFont.h:46
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:2088
EFI_HANDLE ConsoleOutHandle
Definition: UefiSpec.h:2072
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2077