]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiLibPrint.c
HiiLibGetCurrentLanguage returns the current UEFI variable "PlatformLang" (if this...
[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
128 UINTN
129 EFIAPI
130 ErrorPrint (
131 IN CONST CHAR16 *Format,
132 ...
133 )
134 {
135 VA_LIST Marker;
136 UINTN Return;
137
138 VA_START (Marker, Format);
139
140 Return = InternalPrint( Format, gST->StdErr, Marker);
141
142 VA_END (Marker);
143
144 return Return;
145 }
146
147
148 /**
149 Internal function which prints a formatted ASCII string to the console output device
150 specified by Console
151
152 This function prints a formatted ASCII string to the console output device
153 specified by Console and returns the number of ASCII characters that printed
154 to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,
155 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.
156 If Format is NULL, then ASSERT().
157
158 If Format is NULL, then ASSERT().
159 If Format is not aligned on a 16-bit boundary, then ASSERT().
160
161
162 @param Format Null-terminated ASCII format string.
163 @param Console The output console.
164 @param Marker VA_LIST marker for the variable argument list.
165
166 @return The number of Unicode characters in the produced
167 output buffer not including the Null-terminator.
168
169 **/
170 UINTN
171 EFIAPI
172 AsciiInternalPrint (
173 IN CONST CHAR8 *Format,
174 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,
175 IN VA_LIST Marker
176 )
177 {
178 UINTN Return;
179 CHAR16 *Buffer;
180 UINTN BufferSize;
181
182 ASSERT (Format != NULL);
183
184 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);
185
186 Buffer = (CHAR16 *) AllocatePool(BufferSize);
187 ASSERT (Buffer != NULL);
188
189 Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);
190
191 if (Console != NULL) {
192 //
193 // To be extra safe make sure Console has been initialized
194 //
195 Console->OutputString (Console, Buffer);
196 }
197
198 FreePool (Buffer);
199
200 return Return;
201 }
202
203 /**
204 Prints a formatted ASCII string to the console output device specified by
205 ConOut defined in the EFI_SYSTEM_TABLE.
206
207 This function prints a formatted ASCII string to the console output device
208 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII
209 characters that printed to ConOut. If the length of the formatted ASCII
210 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
211 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.
212 If Format is NULL, then ASSERT().
213
214 @param Format Null-terminated ASCII format string.
215 @param ... VARARG list consumed to process Format.
216
217 @return The number of Ascii characters in the produced
218 output buffer not including the Null-terminator.
219
220 **/
221 UINTN
222 EFIAPI
223 AsciiPrint (
224 IN CONST CHAR8 *Format,
225 ...
226 )
227 {
228 VA_LIST Marker;
229 UINTN Return;
230 ASSERT (Format != NULL);
231
232 VA_START (Marker, Format);
233
234 Return = AsciiInternalPrint( Format, gST->ConOut, Marker);
235
236 VA_END (Marker);
237
238 return Return;
239 }
240
241 /**
242 Prints a formatted ASCII string to the console output device specified by
243 StdErr defined in the EFI_SYSTEM_TABLE.
244
245 This function prints a formatted ASCII string to the console output device
246 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII
247 characters that printed to StdErr. If the length of the formatted ASCII
248 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
249 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.
250 If Format is NULL, then ASSERT().
251
252 @param Format Null-terminated ASCII format string.
253 @param ... VARARG list consumed to process Format.
254
255 @return The number of Ascii characters in the produced output
256 buffer not including the Null-terminator.
257
258 **/
259 UINTN
260 EFIAPI
261 AsciiErrorPrint (
262 IN CONST CHAR8 *Format,
263 ...
264 )
265 {
266 VA_LIST Marker;
267 UINTN Return;
268
269 ASSERT (Format != NULL);
270
271 VA_START (Marker, Format);
272
273 Return = AsciiInternalPrint( Format, gST->StdErr, Marker);
274
275 VA_END (Marker);
276
277 return Return;
278 }
279