2 Mde UEFI library API implementation.
3 Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE
5 Copyright (c) 2007 - 2009, Intel Corporation<BR>
6 All rights reserved. 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
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.
16 #include "UefiLibInternal.h"
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 }
38 Internal function which prints a formatted Unicode string to the console output device
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().
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.
52 @return The number of Unicode characters in the produced
53 output buffer not including the Null-terminator.
57 IN CONST CHAR16
*Format
,
58 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Console
,
66 ASSERT (Format
!= NULL
);
67 ASSERT (((UINTN
) Format
& BIT0
) == 0);
69 BufferSize
= (PcdGet32 (PcdUefiLibMaxPrintBufferSize
) + 1) * sizeof (CHAR16
);
71 Buffer
= (CHAR16
*) AllocatePool(BufferSize
);
72 ASSERT (Buffer
!= NULL
);
74 Return
= UnicodeVSPrint (Buffer
, BufferSize
, Format
, Marker
);
76 if (Console
!= NULL
&& Return
> 0) {
78 // To be extra safe make sure Console has been initialized
80 Console
->OutputString (Console
, Buffer
);
89 Prints a formatted Unicode string to the console output device specified by
90 ConOut defined in the EFI_SYSTEM_TABLE.
92 This function prints a formatted Unicode string to the console output device
93 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of Unicode
94 characters that printed to ConOut. If the length of the formatted Unicode
95 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
96 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.
97 If Format is NULL, then ASSERT().
98 If Format is not aligned on a 16-bit boundary, then ASSERT().
100 @param Format Null-terminated Unicode format string.
101 @param ... Variable argument list whose contents are accessed based
102 on the format string specified by Format.
104 @return Number of Unicode characters printed to ConOut.
110 IN CONST CHAR16
*Format
,
117 VA_START (Marker
, Format
);
119 Return
= InternalPrint (Format
, gST
->ConOut
, Marker
);
127 Prints a formatted Unicode string to the console output device specified by
128 StdErr defined in the EFI_SYSTEM_TABLE.
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().
138 @param Format Null-terminated Unicode format string.
139 @param ... Variable argument list whose contents are accessed based
140 on the format string specified by Format.
142 @return Number of Unicode characters printed to StdErr.
148 IN CONST CHAR16
*Format
,
155 VA_START (Marker
, Format
);
157 Return
= InternalPrint( Format
, gST
->StdErr
, Marker
);
166 Internal function which prints a formatted ASCII string to the console output device
169 This function prints a formatted ASCII string to the console output device
170 specified by Console and returns the number of ASCII characters that printed
171 to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,
172 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.
174 If Format is NULL, then ASSERT().
176 @param Format Null-terminated ASCII format string.
177 @param Console The output console.
178 @param Marker VA_LIST marker for the variable argument list.
180 @return The number of Unicode characters in the produced
181 output buffer not including the Null-terminator.
186 IN CONST CHAR8
*Format
,
187 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Console
,
195 ASSERT (Format
!= NULL
);
197 BufferSize
= (PcdGet32 (PcdUefiLibMaxPrintBufferSize
) + 1) * sizeof (CHAR16
);
199 Buffer
= (CHAR16
*) AllocatePool(BufferSize
);
200 ASSERT (Buffer
!= NULL
);
202 Return
= UnicodeVSPrintAsciiFormat (Buffer
, BufferSize
, Format
, Marker
);
204 if (Console
!= NULL
) {
206 // To be extra safe make sure Console has been initialized
208 Console
->OutputString (Console
, Buffer
);
217 Prints a formatted ASCII string to the console output device specified by
218 ConOut defined in the EFI_SYSTEM_TABLE.
220 This function prints a formatted ASCII string to the console output device
221 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII
222 characters that printed to ConOut. If the length of the formatted ASCII
223 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
224 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.
225 If Format is NULL, then ASSERT().
227 @param Format Null-terminated ASCII format string.
228 @param ... Variable argument list whose contents are accessed based
229 on the format string specified by Format.
231 @return Number of ASCII characters printed to ConOut.
237 IN CONST CHAR8
*Format
,
243 ASSERT (Format
!= NULL
);
245 VA_START (Marker
, Format
);
247 Return
= AsciiInternalPrint( Format
, gST
->ConOut
, Marker
);
255 Prints a formatted ASCII string to the console output device specified by
256 StdErr defined in the EFI_SYSTEM_TABLE.
258 This function prints a formatted ASCII string to the console output device
259 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII
260 characters that printed to StdErr. If the length of the formatted ASCII
261 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
262 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.
263 If Format is NULL, then ASSERT().
265 @param Format Null-terminated ASCII format string.
266 @param ... Variable argument list whose contents are accessed based
267 on the format string specified by Format.
269 @return Number of ASCII characters printed to ConErr.
275 IN CONST CHAR8
*Format
,
282 ASSERT (Format
!= NULL
);
284 VA_START (Marker
, Format
);
286 Return
= AsciiInternalPrint( Format
, gST
->StdErr
, Marker
);
294 Internal function to print a formatted Unicode string to a graphics console device specified by
295 ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.
297 This function prints a formatted Unicode string to the graphics console device
298 specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of
299 Unicode characters printed. The EFI_HII_FONT_PROTOCOL is used to convert the
300 string to a bitmap using the glyphs registered with the
301 HII database. No wrapping is performed, so any portions of the string the fall
302 outside the active display region will not be displayed.
304 If a graphics console device is not associated with the ConsoleOutputHandle
305 defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.
306 If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no
307 string is printed, and 0 is returned.
309 @param PointX X coordinate to print the string.
310 @param PointY Y coordinate to print the string.
311 @param Foreground The foreground color of the string being printed. This is
312 an optional parameter that may be NULL. If it is NULL,
313 then the foreground color of the current ConOut device
314 in the EFI_SYSTEM_TABLE is used.
315 @param Background The background color of the string being printed. This is
316 an optional parameter that may be NULL. If it is NULL,
317 then the background color of the current ConOut device
318 in the EFI_SYSTEM_TABLE is used.
319 @param Buffer Null-terminated Unicode formatted string.
320 @param PrintNum The number of Unicode formatted string to be printed.
322 @return Number of Unicode Characters printed. Zero means no any character
323 displayed successfully.
327 InternalPrintGraphic (
330 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
331 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
,
337 UINT32 HorizontalResolution
;
338 UINT32 VerticalResolution
;
341 EFI_HII_FONT_PROTOCOL
*HiiFont
;
342 EFI_IMAGE_OUTPUT
*Blt
;
343 EFI_FONT_DISPLAY_INFO FontInfo
;
344 EFI_HII_ROW_INFO
*RowInfoArray
;
345 UINTN RowInfoArraySize
;
346 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
347 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
348 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Sto
;
349 EFI_HANDLE ConsoleHandle
;
351 HorizontalResolution
= 0;
352 VerticalResolution
= 0;
356 ConsoleHandle
= gST
->ConsoleOutHandle
;
358 Status
= gBS
->HandleProtocol (
360 &gEfiGraphicsOutputProtocolGuid
,
361 (VOID
**) &GraphicsOutput
365 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
367 // If no GOP available, try to open UGA Draw protocol if supported.
369 GraphicsOutput
= NULL
;
371 Status
= gBS
->HandleProtocol (
373 &gEfiUgaDrawProtocolGuid
,
377 if (EFI_ERROR (Status
)) {
381 Status
= gBS
->HandleProtocol (
383 &gEfiSimpleTextOutProtocolGuid
,
387 if (EFI_ERROR (Status
)) {
391 if (GraphicsOutput
!= NULL
) {
392 HorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
393 VerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
394 } else if (UgaDraw
!= NULL
&& FeaturePcdGet (PcdUgaConsumeSupport
)) {
395 UgaDraw
->GetMode (UgaDraw
, &HorizontalResolution
, &VerticalResolution
, &ColorDepth
, &RefreshRate
);
400 ASSERT ((HorizontalResolution
!= 0) && (VerticalResolution
!=0));
402 Status
= gBS
->LocateProtocol (&gEfiHiiFontProtocolGuid
, NULL
, (VOID
**) &HiiFont
);
403 if (EFI_ERROR (Status
)) {
407 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
408 ASSERT (Blt
!= NULL
);
410 Blt
->Width
= (UINT16
) (HorizontalResolution
);
411 Blt
->Height
= (UINT16
) (VerticalResolution
);
413 ZeroMem (&FontInfo
, sizeof (EFI_FONT_DISPLAY_INFO
));
415 if (Foreground
!= NULL
) {
416 CopyMem (&FontInfo
.ForegroundColor
, Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
419 &FontInfo
.ForegroundColor
,
420 &mEfiColors
[Sto
->Mode
->Attribute
& 0x0f],
421 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
424 if (Background
!= NULL
) {
425 CopyMem (&FontInfo
.BackgroundColor
, Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
428 &FontInfo
.BackgroundColor
,
429 &mEfiColors
[Sto
->Mode
->Attribute
>> 4],
430 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
434 if (GraphicsOutput
!= NULL
) {
435 Blt
->Image
.Screen
= GraphicsOutput
;
437 Status
= HiiFont
->StringToImage (
439 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_OUT_FLAG_CLIP
|
440 EFI_HII_OUT_FLAG_CLIP_CLEAN_X
| EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
|
441 EFI_HII_IGNORE_LINE_BREAK
| EFI_HII_DIRECT_TO_SCREEN
,
451 if (EFI_ERROR (Status
)) {
455 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
456 ASSERT (UgaDraw
!= NULL
);
458 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
459 ASSERT (Blt
->Image
.Bitmap
!= NULL
);
462 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
463 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
465 Status
= HiiFont
->StringToImage (
467 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_OUT_FLAG_CLIP
|
468 EFI_HII_OUT_FLAG_CLIP_CLEAN_X
| EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
|
469 EFI_HII_IGNORE_LINE_BREAK
,
480 if (!EFI_ERROR (Status
)) {
481 ASSERT (RowInfoArray
!= NULL
);
483 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
484 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
486 ASSERT (RowInfoArraySize
<= 1);
488 Status
= UgaDraw
->Blt (
490 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
491 EfiUgaBltBufferToVideo
,
496 RowInfoArray
[0].LineWidth
,
497 RowInfoArray
[0].LineHeight
,
498 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
503 FreePool (Blt
->Image
.Bitmap
);
508 // Calculate the number of actual printed characters
510 PrintNum
= RowInfoArray
[0].EndIndex
- RowInfoArray
[0].StartIndex
+ 1;
512 FreePool (RowInfoArray
);
524 Prints a formatted Unicode string to a graphics console device specified by
525 ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.
527 This function prints a formatted Unicode string to the graphics console device
528 specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of
529 Unicode characters displayed, not including partial characters that may be clipped
530 by the right edge of the display. If the length of the formatted Unicode string is
531 greater than PcdUefiLibMaxPrintBufferSize, then at most the first
532 PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL
533 StringToImage() service is used to convert the string to a bitmap using the glyphs
534 registered with the HII database. No wrapping is performed, so any portions of the
535 string the fall outside the active display region will not be displayed. Please see
536 Section 27.2.6 of the UEFI Specification for a description of the supported string
537 format including the set of control codes supported by the StringToImage() service.
539 If a graphics console device is not associated with the ConsoleOutputHandle
540 defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.
541 If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no
542 string is printed, and 0 is returned.
543 If Format is NULL, then ASSERT().
544 If Format is not aligned on a 16-bit boundary, then ASSERT().
546 @param PointX X coordinate to print the string.
547 @param PointY Y coordinate to print the string.
548 @param ForeGround The foreground color of the string being printed. This is
549 an optional parameter that may be NULL. If it is NULL,
550 then the foreground color of the current ConOut device
551 in the EFI_SYSTEM_TABLE is used.
552 @param BackGround The background color of the string being printed. This is
553 an optional parameter that may be NULL. If it is NULL,
554 then the background color of the current ConOut device
555 in the EFI_SYSTEM_TABLE is used.
556 @param Format Null-terminated Unicode format string. See Print Library
557 for the supported format string syntax.
558 @param ... Variable argument list whose contents are accessed based on
559 the format string specified by Format.
561 @return The number of Unicode characters printed.
569 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*ForeGround
, OPTIONAL
570 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BackGround
, OPTIONAL
571 IN CONST CHAR16
*Format
,
581 ASSERT (Format
!= NULL
);
582 ASSERT (((UINTN
) Format
& BIT0
) == 0);
584 VA_START (Marker
, Format
);
586 BufferSize
= (PcdGet32 (PcdUefiLibMaxPrintBufferSize
) + 1) * sizeof (CHAR16
);
588 Buffer
= (CHAR16
*) AllocatePool (BufferSize
);
589 ASSERT (Buffer
!= NULL
);
591 PrintNum
= UnicodeVSPrint (Buffer
, BufferSize
, Format
, Marker
);
593 ReturnNum
= InternalPrintGraphic (PointX
, PointY
, ForeGround
, BackGround
, Buffer
, PrintNum
);
601 Prints a formatted ASCII string to a graphics console device specified by
602 ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.
604 This function prints a formatted ASCII string to the graphics console device
605 specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of
606 ASCII characters displayed, not including partial characters that may be clipped
607 by the right edge of the display. If the length of the formatted ASCII string is
608 greater than PcdUefiLibMaxPrintBufferSize, then at most the first
609 PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL
610 StringToImage() service is used to convert the string to a bitmap using the glyphs
611 registered with the HII database. No wrapping is performed, so any portions of the
612 string the fall outside the active display region will not be displayed. Please see
613 Section 27.2.6 of the UEFI Specification for a description of the supported string
614 format including the set of control codes supported by the StringToImage() service.
616 If a graphics console device is not associated with the ConsoleOutputHandle
617 defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.
618 If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no
619 string is printed, and 0 is returned.
620 If Format is NULL, then ASSERT().
622 @param PointX X coordinate to print the string.
623 @param PointY Y coordinate to print the string.
624 @param ForeGround The foreground color of the string being printed. This is
625 an optional parameter that may be NULL. If it is NULL,
626 then the foreground color of the current ConOut device
627 in the EFI_SYSTEM_TABLE is used.
628 @param BackGround The background color of the string being printed. This is
629 an optional parameter that may be NULL. If it is NULL,
630 then the background color of the current ConOut device
631 in the EFI_SYSTEM_TABLE is used.
632 @param Format Null-terminated ASCII format string. See Print Library
633 for the supported format string syntax.
634 @param ... Variable argument list whose contents are accessed based on
635 the format string specified by Format.
637 @return The number of ASCII characters printed.
645 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*ForeGround
, OPTIONAL
646 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BackGround
, OPTIONAL
647 IN CONST CHAR8
*Format
,
657 ASSERT (Format
!= NULL
);
659 VA_START (Marker
, Format
);
661 BufferSize
= (PcdGet32 (PcdUefiLibMaxPrintBufferSize
) + 1) * sizeof (CHAR16
);
663 Buffer
= (CHAR16
*) AllocatePool (BufferSize
);
664 ASSERT (Buffer
!= NULL
);
666 PrintNum
= UnicodeSPrintAsciiFormat (Buffer
, BufferSize
, Format
, Marker
);
668 ReturnNum
= InternalPrintGraphic (PointX
, PointY
, ForeGround
, BackGround
, Buffer
, PrintNum
);