3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
19 simple implemenation of SPrint() and Print() to support debug.
21 You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
22 time. This makes the implementation very simple.
24 VSPrint, Print, SPrint format specification has the follwoing form
32 ',' - Place commas in numberss
33 '0' - Prefix for width with zeros
38 '*' - Get width from a UINTN argumnet from the argument list
39 Decimal number that represents width of print
42 'X' - argument is a UINTN hex number, prefix '0'
43 'x' - argument is a hex number
44 'd' - argument is a decimal number
45 'a' - argument is an ascii string
46 'S','s' - argument is an Unicode string
47 'g' - argument is a pointer to an EFI_GUID
48 't' - argument is a pointer to an EFI_TIME structure
49 'c' - argument is an ascii character
50 'r' - argument is EFI_STATUS
56 #include "EfiDriverLib.h"
57 #include "TianoCommon.h"
58 #include "EfiCommonLib.h"
59 #include "PrintWidth.h"
60 #include "EfiPrintLib.h"
62 #include EFI_PROTOCOL_DEFINITION (Hii)
64 static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors
[16] = {
65 0x00, 0x00, 0x00, 0x00,
66 0x98, 0x00, 0x00, 0x00,
67 0x00, 0x98, 0x00, 0x00,
68 0x98, 0x98, 0x00, 0x00,
69 0x00, 0x00, 0x98, 0x00,
70 0x98, 0x00, 0x98, 0x00,
71 0x00, 0x98, 0x98, 0x00,
72 0x98, 0x98, 0x98, 0x00,
73 0x10, 0x10, 0x10, 0x00,
74 0xff, 0x10, 0x10, 0x00,
75 0x10, 0xff, 0x10, 0x00,
76 0xff, 0xff, 0x10, 0x00,
77 0x10, 0x10, 0xff, 0x00,
78 0xf0, 0x10, 0xff, 0x00,
79 0x10, 0xff, 0xff, 0x00,
80 0xff, 0xff, 0xff, 0x00,
86 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
87 IN EFI_UGA_DRAW_PROTOCOL
*UgaDraw
,
88 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
,
91 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
92 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
,
100 Display string worker for: Print, PrintAt, IPrint, IPrintAt
104 GraphicsOutput - Graphics output protocol interface
106 UgaDraw - UGA draw protocol interface
108 Sto - Simple text out protocol interface
110 X - X coordinate to start printing
112 Y - Y coordinate to start printing
114 Foreground - Foreground color
116 Background - Background color
120 args - Print arguments
124 EFI_SUCCESS - success
125 EFI_OUT_OF_RESOURCES - out of resources
135 CHAR16
*UnicodeWeight
;
136 EFI_NARROW_GLYPH
*Glyph
;
137 EFI_HII_PROTOCOL
*Hii
;
138 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*LineBuffer
;
139 UINT32 HorizontalResolution
;
140 UINT32 VerticalResolution
;
149 // For now, allocate an arbitrarily long buffer
151 Buffer
= EfiLibAllocateZeroPool (0x10000);
152 if (Buffer
== NULL
) {
153 return EFI_OUT_OF_RESOURCES
;
156 if (GraphicsOutput
!= NULL
) {
157 HorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
158 VerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
160 UgaDraw
->GetMode (UgaDraw
, &HorizontalResolution
, &VerticalResolution
, &ColorDepth
, &RefreshRate
);
162 ASSERT ((HorizontalResolution
!= 0) && (VerticalResolution
!=0));
164 LineBufferLen
= sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * HorizontalResolution
* GLYPH_HEIGHT
;
165 LineBuffer
= EfiLibAllocatePool (LineBufferLen
);
166 if (LineBuffer
== NULL
) {
167 gBS
->FreePool (Buffer
);
168 return EFI_OUT_OF_RESOURCES
;
171 Status
= gBS
->LocateProtocol (&gEfiHiiProtocolGuid
, NULL
, &Hii
);
172 if (EFI_ERROR (Status
)) {
176 VSPrint (Buffer
, 0x10000, fmt
, args
);
178 UnicodeWeight
= (CHAR16
*) Buffer
;
180 for (Index
= 0; UnicodeWeight
[Index
] != 0; Index
++) {
181 if (UnicodeWeight
[Index
] == CHAR_BACKSPACE
||
182 UnicodeWeight
[Index
] == CHAR_LINEFEED
||
183 UnicodeWeight
[Index
] == CHAR_CARRIAGE_RETURN
) {
184 UnicodeWeight
[Index
] = 0;
188 BufferLen
= EfiStrLen (Buffer
);
190 if (GLYPH_WIDTH
* GLYPH_HEIGHT
* sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * BufferLen
> LineBufferLen
) {
191 Status
= EFI_INVALID_PARAMETER
;
195 for (Index
= 0; Index
< BufferLen
; Index
++) {
196 StringIndex
= (UINT16
) Index
;
197 Status
= Hii
->GetGlyph (Hii
, UnicodeWeight
, &StringIndex
, (UINT8
**) &Glyph
, &GlyphWidth
, &GlyphStatus
);
198 if (EFI_ERROR (Status
)) {
202 if (Foreground
== NULL
|| Background
== NULL
) {
203 Status
= Hii
->GlyphToBlt (
206 mEfiColors
[Sto
->Mode
->Attribute
& 0x0f],
207 mEfiColors
[Sto
->Mode
->Attribute
>> 4],
211 &LineBuffer
[Index
* GLYPH_WIDTH
]
214 Status
= Hii
->GlyphToBlt (
222 &LineBuffer
[Index
* GLYPH_WIDTH
]
228 // Blt a character to the screen
230 if (GraphicsOutput
!= NULL
) {
231 Status
= GraphicsOutput
->Blt (
239 GLYPH_WIDTH
* BufferLen
,
241 GLYPH_WIDTH
* BufferLen
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
244 Status
= UgaDraw
->Blt (
246 (EFI_UGA_PIXEL
*) LineBuffer
,
247 EfiUgaBltBufferToVideo
,
252 GLYPH_WIDTH
* BufferLen
,
254 GLYPH_WIDTH
* BufferLen
* sizeof (EFI_UGA_PIXEL
)
259 gBS
->FreePool (LineBuffer
);
260 gBS
->FreePool (Buffer
);
269 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*ForeGround
, OPTIONAL
270 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BackGround
, OPTIONAL
278 Prints a formatted unicode string to the default console
282 X - X coordinate to start printing
284 Y - Y coordinate to start printing
286 ForeGround - Foreground color
288 BackGround - Background color
292 ... - Print arguments
296 Length of string printed to the console
301 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
302 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
303 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
;
307 VA_START (Args
, Fmt
);
309 Handle
= gST
->ConsoleOutHandle
;
311 Status
= gBS
->HandleProtocol (
313 &gEfiGraphicsOutputProtocolGuid
,
318 if (EFI_ERROR (Status
)) {
319 GraphicsOutput
= NULL
;
321 Status
= gBS
->HandleProtocol (
323 &gEfiUgaDrawProtocolGuid
,
327 if (EFI_ERROR (Status
)) {
332 Status
= gBS
->HandleProtocol (
334 &gEfiSimpleTextOutProtocolGuid
,
338 if (EFI_ERROR (Status
)) {
342 return _IPrint (GraphicsOutput
, UgaDraw
, Sto
, X
, Y
, ForeGround
, BackGround
, Fmt
, Args
);
350 IN CONST CHAR_W
*Format
,
357 SPrint function to process format and place the results in Buffer.
361 Buffer - Wide char buffer to print the results of the parsing of Format into.
363 BufferSize - Maximum number of characters to put into buffer. Zero means no
366 Format - Format string see file header for more details.
368 ... - Vararg list consumed by processing Format.
372 Number of characters printed.
379 VA_START (Marker
, Format
);
380 Return
= VSPrint (Buffer
, BufferSize
, Format
, Marker
);
388 OUT CHAR_W
*StartOfBuffer
,
390 IN CONST CHAR_W
*FormatString
,
397 VSPrint function to process format and place the results in Buffer. Since a
398 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
399 this is the main print working routine
403 StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
405 BufferSize - Maximum number of characters to put into buffer. Zero means
408 FormatString - Unicode format string see file header for more details.
410 Marker - Vararg list consumed by processing Format.
414 Number of characters printed.
419 EFI_PRINT_PROTOCOL
*PrintProtocol
;
421 Status
= gBS
->LocateProtocol (
422 &gEfiPrintProtocolGuid
,
426 if (EFI_ERROR (Status
)) {
429 return PrintProtocol
->VSPrint (