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