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