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