]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiLib/UefiLibPrint.c
add SerialPortLib.h
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiLibPrint.c
CommitLineData
e386b444 1/** @file\r
2 Mde UEFI library API implemention.\r
3 Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE\r
4\r
5 Copyright (c) 2007, Intel Corporation<BR>\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16//\r
17// Include common header file for this module.\r
18//\r
19#include "CommonHeader.h"\r
20\r
21/**\r
22 Internal function which prints a formatted Unicode string to the console output device\r
23 specified by Console\r
24\r
25 This function prints a formatted Unicode string to the console output device\r
26 specified by Console and returns the number of Unicode characters that printed\r
27 to it. If the length of the formatted Unicode string is greater than PcdUefiLibMaxPrintBufferSize,\r
28 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r
29\r
30 @param Format Null-terminated Unicode format string.\r
31 @param Console The output console.\r
32 @param Marker VA_LIST marker for the variable argument list.\r
33\r
34 If Format is NULL, then ASSERT().\r
35 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
36\r
37**/\r
38\r
39STATIC\r
40UINTN\r
41InternalPrint (\r
42 IN CONST CHAR16 *Format,\r
43 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r
44 IN VA_LIST Marker\r
45 )\r
46{\r
47 UINTN Return;\r
48 CHAR16 *Buffer;\r
49 UINTN BufferSize;\r
50\r
51 ASSERT (Format != NULL);\r
52 ASSERT (((UINTN) Format & 0x01) == 0);\r
53\r
54 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
55\r
56 Buffer = (CHAR16 *) AllocatePool(BufferSize);\r
57 ASSERT (Buffer != NULL);\r
58\r
59 Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r
60\r
61 if (Console != NULL) {\r
62 //\r
63 // To be extra safe make sure Console has been initialized\r
64 //\r
65 Console->OutputString (Console, Buffer);\r
66 }\r
67\r
68 FreePool (Buffer);\r
69\r
70 return Return;\r
71}\r
72\r
73/**\r
74 Prints a formatted Unicode string to the console output device specified by\r
75 ConOut defined in the EFI_SYSTEM_TABLE.\r
76\r
77 This function prints a formatted Unicode string to the console output device\r
78 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of Unicode\r
79 characters that printed to ConOut. If the length of the formatted Unicode\r
80 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
81 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
82\r
83 @param Format Null-terminated Unicode format string.\r
84 @param ... VARARG list consumed to process Format.\r
85 If Format is NULL, then ASSERT().\r
86 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
87\r
88**/\r
89UINTN\r
90EFIAPI\r
91Print (\r
92 IN CONST CHAR16 *Format,\r
93 ...\r
94 )\r
95{\r
96 VA_LIST Marker;\r
97 UINTN Return;\r
98\r
99 VA_START (Marker, Format);\r
100\r
101 Return = InternalPrint (Format, gST->ConOut, Marker);\r
102\r
103 VA_END (Marker);\r
104\r
105 return Return;\r
106}\r
107\r
108/**\r
109 Prints a formatted Unicode string to the console output device specified by\r
110 StdErr defined in the EFI_SYSTEM_TABLE.\r
111\r
112 This function prints a formatted Unicode string to the console output device\r
113 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of Unicode\r
114 characters that printed to StdErr. If the length of the formatted Unicode\r
115 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
116 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
117\r
118 @param Format Null-terminated Unicode format string.\r
119 @param ... VARARG list consumed to process Format.\r
120 If Format is NULL, then ASSERT().\r
121 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
122\r
123**/\r
124\r
125UINTN\r
126EFIAPI\r
127ErrorPrint (\r
128 IN CONST CHAR16 *Format,\r
129 ...\r
130 )\r
131{\r
132 VA_LIST Marker;\r
133 UINTN Return;\r
134\r
135 VA_START (Marker, Format);\r
136\r
137 Return = InternalPrint( Format, gST->StdErr, Marker);\r
138\r
139 VA_END (Marker);\r
140\r
141 return Return;\r
142}\r
143\r
144\r
145/**\r
146 Internal function which prints a formatted ASCII string to the console output device\r
147 specified by Console\r
148\r
149 This function prints a formatted ASCII string to the console output device\r
150 specified by Console and returns the number of ASCII characters that printed\r
151 to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,\r
152 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r
153\r
154 @param Format Null-terminated ASCII format string.\r
155 @param Console The output console.\r
156 @param Marker VA_LIST marker for the variable argument list.\r
157\r
158 If Format is NULL, then ASSERT().\r
159\r
160**/\r
161\r
162STATIC\r
163UINTN\r
164AsciiInternalPrint (\r
165 IN CONST CHAR8 *Format,\r
166 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r
167 IN VA_LIST Marker\r
168 )\r
169{\r
170 UINTN Return;\r
171 CHAR16 *Buffer;\r
172 UINTN BufferSize;\r
173\r
174 ASSERT (Format != NULL);\r
175\r
176 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
177\r
178 Buffer = (CHAR16 *) AllocatePool(BufferSize);\r
179 ASSERT (Buffer != NULL);\r
180\r
181 Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r
182\r
183 if (Console != NULL) {\r
184 //\r
185 // To be extra safe make sure Console has been initialized\r
186 //\r
187 Console->OutputString (Console, Buffer);\r
188 }\r
189\r
190 FreePool (Buffer);\r
191\r
192 return Return;\r
193}\r
194\r
195/**\r
196 Prints a formatted ASCII string to the console output device specified by\r
197 ConOut defined in the EFI_SYSTEM_TABLE.\r
198\r
199 This function prints a formatted ASCII string to the console output device\r
200 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII\r
201 characters that printed to ConOut. If the length of the formatted ASCII\r
202 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
203 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
204\r
205 @param Format Null-terminated ASCII format string.\r
206 @param ... VARARG list consumed to process Format.\r
207 If Format is NULL, then ASSERT().\r
208 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
209\r
210**/\r
211UINTN\r
212EFIAPI\r
213AsciiPrint (\r
214 IN CONST CHAR8 *Format,\r
215 ...\r
216 )\r
217{\r
218 VA_LIST Marker;\r
219 UINTN Return;\r
220\r
221 VA_START (Marker, Format);\r
222\r
223 Return = AsciiInternalPrint( Format, gST->ConOut, Marker);\r
224\r
225 VA_END (Marker);\r
226\r
227 return Return;\r
228}\r
229\r
230/**\r
231 Prints a formatted ASCII string to the console output device specified by\r
232 StdErr defined in the EFI_SYSTEM_TABLE.\r
233\r
234 This function prints a formatted ASCII string to the console output device\r
235 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII\r
236 characters that printed to StdErr. If the length of the formatted ASCII\r
237 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
238 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
239\r
240 @param Format Null-terminated ASCII format string.\r
241 @param ... VARARG list consumed to process Format.\r
242 If Format is NULL, then ASSERT().\r
243 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
244\r
245**/\r
246UINTN\r
247EFIAPI\r
248AsciiErrorPrint (\r
249 IN CONST CHAR8 *Format,\r
250 ...\r
251 )\r
252{\r
253 VA_LIST Marker;\r
254 UINTN Return;\r
255\r
256 VA_START (Marker, Format);\r
257\r
258 Return = AsciiInternalPrint( Format, gST->StdErr, Marker);\r
259\r
260 VA_END (Marker);\r
261\r
262 return Return;\r
263}\r
264\r