]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibPrint.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[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 ... VARARG list consumed to process Format.
81 If Format is NULL, then ASSERT().
82 If Format is not aligned on a 16-bit boundary, then ASSERT().
83
84 **/
85 UINTN
86 EFIAPI
87 Print (
88 IN CONST CHAR16 *Format,
89 ...
90 )
91 {
92 VA_LIST Marker;
93 UINTN Return;
94
95 VA_START (Marker, Format);
96
97 Return = InternalPrint (Format, gST->ConOut, Marker);
98
99 VA_END (Marker);
100
101 return Return;
102 }
103
104 /**
105 Prints a formatted Unicode string to the console output device specified by
106 StdErr defined in the EFI_SYSTEM_TABLE.
107
108 This function prints a formatted Unicode string to the console output device
109 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of Unicode
110 characters that printed to StdErr. If the length of the formatted Unicode
111 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first
112 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.
113
114 @param Format Null-terminated Unicode format string.
115 @param ... VARARG list consumed to process Format.
116 If Format is NULL, then ASSERT().
117 If Format is not aligned on a 16-bit boundary, then ASSERT().
118
119 **/
120
121 UINTN
122 EFIAPI
123 ErrorPrint (
124 IN CONST CHAR16 *Format,
125 ...
126 )
127 {
128 VA_LIST Marker;
129 UINTN Return;
130
131 VA_START (Marker, Format);
132
133 Return = InternalPrint( Format, gST->StdErr, Marker);
134
135 VA_END (Marker);
136
137 return Return;
138 }
139
140
141 /**
142 Internal function which prints a formatted ASCII string to the console output device
143 specified by Console
144
145 This function prints a formatted ASCII string to the console output device
146 specified by Console and returns the number of ASCII characters that printed
147 to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,
148 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.
149
150 @param Format Null-terminated ASCII format string.
151 @param Console The output console.
152 @param Marker VA_LIST marker for the variable argument list.
153
154 If Format is NULL, then ASSERT().
155
156 **/
157
158 UINTN
159 AsciiInternalPrint (
160 IN CONST CHAR8 *Format,
161 IN EFI_SIMPLE_TEXT_OUTPUT_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 Console 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