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