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