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