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