UefiLibPrint.c 28 KB

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