]>
Commit | Line | Data |
---|---|---|
504214c4 | 1 | /** @file\r |
f0c74f5a | 2 | Instance of Print Library based on gEfiPrint2SProtocolGuid.\r |
a0afd019 | 3 | \r |
d1102dba | 4 | Implement the print library instance by wrap the interface\r |
f0c74f5a | 5 | provided in the Print2S protocol. This protocol is defined as the internal\r |
d1102dba | 6 | protocol related to this implementation, not in the public spec. So, this\r |
504214c4 LG |
7 | library instance is only for this code base.\r |
8 | \r | |
d1102dba | 9 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 10 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a0afd019 | 11 | \r |
504214c4 | 12 | **/\r |
a0afd019 | 13 | \r |
60c93673 | 14 | #include <Uefi.h>\r |
f405c067 | 15 | #include <Base.h>\r |
0ed0c867 | 16 | #include <Protocol/Print2.h>\r |
504dcb0a | 17 | \r |
18 | #include <Library/PrintLib.h>\r | |
19 | \r | |
20 | #include <Library/BaseLib.h>\r | |
bee67555 | 21 | #include <Library/DebugLib.h>\r |
50418baa HW |
22 | #include <Library/PcdLib.h>\r |
23 | \r | |
24 | #define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)\r | |
25 | \r | |
26 | //\r | |
27 | // Safe print checks\r | |
28 | //\r | |
29 | #define RSIZE_MAX (PcdGet32 (PcdMaximumUnicodeStringLength))\r | |
30 | #define ASCII_RSIZE_MAX (PcdGet32 (PcdMaximumAsciiStringLength))\r | |
31 | \r | |
32 | #define SAFE_PRINT_CONSTRAINT_CHECK(Expression, RetVal) \\r | |
33 | do { \\r | |
34 | ASSERT (Expression); \\r | |
35 | if (!(Expression)) { \\r | |
36 | return RetVal; \\r | |
37 | } \\r | |
38 | } while (FALSE)\r | |
a0afd019 | 39 | \r |
f0c74f5a | 40 | EFI_PRINT2S_PROTOCOL *mPrint2SProtocol = NULL;\r |
a0afd019 | 41 | \r |
ce95aa7a | 42 | /**\r |
f0c74f5a | 43 | The constructor function caches the pointer to Print2S protocol.\r |
d1102dba | 44 | \r |
f0c74f5a | 45 | The constructor function locates Print2S protocol from protocol database.\r |
d1102dba | 46 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r |
ce95aa7a | 47 | \r |
bee67555 | 48 | @param ImageHandle The firmware allocated handle for the EFI image.\r |
49 | @param SystemTable A pointer to the EFI System Table.\r | |
d1102dba | 50 | \r |
bee67555 | 51 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r |
ce95aa7a | 52 | \r |
53 | **/\r | |
2ad4dad0 LG |
54 | EFI_STATUS\r |
55 | EFIAPI\r | |
bee67555 | 56 | PrintLibConstructor (\r |
57 | IN EFI_HANDLE ImageHandle,\r | |
58 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
a0afd019 | 59 | )\r |
a0afd019 | 60 | {\r |
bee67555 | 61 | EFI_STATUS Status;\r |
62 | \r | |
35289219 | 63 | Status = SystemTable->BootServices->LocateProtocol (\r |
f0c74f5a | 64 | &gEfiPrint2SProtocolGuid,\r |
35289219 | 65 | NULL,\r |
f0c74f5a | 66 | (VOID**) &mPrint2SProtocol\r |
35289219 | 67 | );\r |
bee67555 | 68 | ASSERT_EFI_ERROR (Status);\r |
f0c74f5a | 69 | ASSERT (mPrint2SProtocol != NULL);\r |
bee67555 | 70 | \r |
71 | return Status;\r | |
2ad4dad0 LG |
72 | }\r |
73 | \r | |
bee67555 | 74 | \r |
504dcb0a | 75 | /**\r |
d1102dba | 76 | Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated\r |
504dcb0a | 77 | format string.\r |
78 | \r | |
79 | @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.\r | |
80 | @param Format Null-terminated format string.\r | |
81 | @param VaListMarker VA_LIST style variable argument list consumed by processing Format.\r | |
82 | @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.\r | |
83 | @param Size The size, in bytes, of the BaseListMarker buffer.\r | |
84 | \r | |
7c6075e2 HW |
85 | @return TRUE The VA_LIST has been converted to BASE_LIST.\r |
86 | @return FALSE The VA_LIST has not been converted to BASE_LIST.\r | |
504dcb0a | 87 | \r |
88 | **/\r | |
89 | BOOLEAN\r | |
90 | DxePrintLibPrint2ProtocolVaListToBaseList (\r | |
91 | IN BOOLEAN AsciiFormat,\r | |
92 | IN CONST CHAR8 *Format,\r | |
93 | IN VA_LIST VaListMarker,\r | |
94 | OUT BASE_LIST BaseListMarker,\r | |
95 | IN UINTN Size\r | |
96 | )\r | |
97 | {\r | |
98 | BASE_LIST BaseListStart;\r | |
99 | UINTN BytesPerFormatCharacter;\r | |
100 | UINTN FormatMask;\r | |
101 | UINTN FormatCharacter;\r | |
102 | BOOLEAN Long;\r | |
103 | BOOLEAN Done;\r | |
104 | \r | |
504dcb0a | 105 | ASSERT (BaseListMarker != NULL);\r |
50418baa | 106 | SAFE_PRINT_CONSTRAINT_CHECK ((Format != NULL), FALSE);\r |
504dcb0a | 107 | \r |
108 | BaseListStart = BaseListMarker;\r | |
109 | \r | |
110 | if (AsciiFormat) {\r | |
50418baa HW |
111 | if (ASCII_RSIZE_MAX != 0) {\r |
112 | SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX + 1) <= ASCII_RSIZE_MAX), FALSE);\r | |
113 | }\r | |
504dcb0a | 114 | BytesPerFormatCharacter = 1;\r |
115 | FormatMask = 0xff;\r | |
116 | } else {\r | |
50418baa HW |
117 | if (RSIZE_MAX != 0) {\r |
118 | SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX + 1) <= RSIZE_MAX), FALSE);\r | |
119 | }\r | |
504dcb0a | 120 | BytesPerFormatCharacter = 2;\r |
121 | FormatMask = 0xffff;\r | |
122 | }\r | |
123 | \r | |
124 | //\r | |
125 | // Get the first character from the format string\r | |
126 | //\r | |
213da0b5 | 127 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
504dcb0a | 128 | \r |
129 | while (FormatCharacter != 0) {\r | |
130 | if (FormatCharacter == '%') {\r | |
131 | Long = FALSE;\r | |
132 | \r | |
133 | //\r | |
134 | // Parse Flags and Width\r | |
135 | //\r | |
136 | for (Done = FALSE; !Done; ) {\r | |
137 | //\r | |
138 | // Get the next character from the format string\r | |
139 | //\r | |
140 | Format += BytesPerFormatCharacter;\r | |
141 | \r | |
142 | //\r | |
143 | // Get the next character from the format string\r | |
144 | //\r | |
213da0b5 | 145 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
504dcb0a | 146 | \r |
147 | switch (FormatCharacter) {\r | |
d1102dba LG |
148 | case '.':\r |
149 | case '-':\r | |
150 | case '+':\r | |
151 | case ' ':\r | |
152 | case ',':\r | |
504dcb0a | 153 | case '0':\r |
154 | case '1':\r | |
155 | case '2':\r | |
156 | case '3':\r | |
157 | case '4':\r | |
158 | case '5':\r | |
159 | case '6':\r | |
160 | case '7':\r | |
161 | case '8':\r | |
162 | case '9':\r | |
163 | break;\r | |
164 | case 'L':\r | |
d1102dba | 165 | case 'l':\r |
504dcb0a | 166 | Long = TRUE;\r |
167 | break;\r | |
168 | case '*':\r | |
169 | BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r | |
170 | break;\r | |
171 | case '\0':\r | |
172 | //\r | |
173 | // Make no output if Format string terminates unexpectedly when\r | |
d1102dba | 174 | // looking up for flag, width, precision and type.\r |
504dcb0a | 175 | //\r |
176 | Format -= BytesPerFormatCharacter;\r | |
177 | //\r | |
178 | // break skipped on purpose.\r | |
179 | //\r | |
180 | default:\r | |
181 | Done = TRUE;\r | |
182 | break;\r | |
183 | }\r | |
d1102dba LG |
184 | }\r |
185 | \r | |
504dcb0a | 186 | //\r |
187 | // Handle each argument type\r | |
188 | //\r | |
189 | switch (FormatCharacter) {\r | |
190 | case 'p':\r | |
191 | if (sizeof (VOID *) > 4) {\r | |
192 | Long = TRUE;\r | |
193 | }\r | |
194 | case 'X':\r | |
195 | case 'x':\r | |
796fecd8 | 196 | case 'u':\r |
504dcb0a | 197 | case 'd':\r |
198 | if (Long) {\r | |
199 | BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r | |
200 | } else {\r | |
201 | BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r | |
202 | }\r | |
203 | break;\r | |
204 | case 's':\r | |
205 | case 'S':\r | |
206 | case 'a':\r | |
207 | case 'g':\r | |
208 | case 't':\r | |
209 | BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r | |
210 | break;\r | |
211 | case 'c':\r | |
212 | BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r | |
213 | break;\r | |
214 | case 'r':\r | |
215 | BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r | |
216 | break;\r | |
217 | }\r | |
218 | }\r | |
219 | \r | |
220 | //\r | |
221 | // If BASE_LIST is larger than Size, then return FALSE\r | |
222 | //\r | |
809e2bbf | 223 | if (((UINTN)BaseListMarker - (UINTN)BaseListStart) > Size) {\r |
7c6075e2 | 224 | DEBUG ((DEBUG_ERROR, "The input variable argument list is too long. Please consider breaking into multiple print calls.\n"));\r |
504dcb0a | 225 | return FALSE;\r |
226 | }\r | |
227 | \r | |
228 | //\r | |
229 | // Get the next character from the format string\r | |
230 | //\r | |
231 | Format += BytesPerFormatCharacter;\r | |
232 | \r | |
233 | //\r | |
234 | // Get the next character from the format string\r | |
235 | //\r | |
213da0b5 | 236 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
504dcb0a | 237 | }\r |
238 | return TRUE;\r | |
239 | }\r | |
240 | \r | |
2ad4dad0 | 241 | /**\r |
50418baa HW |
242 | Produces a Null-terminated Unicode string in an output buffer based on\r |
243 | a Null-terminated Unicode format string and a VA_LIST argument list.\r | |
244 | \r | |
245 | This function is similar as vsnprintf_s defined in C11.\r | |
246 | \r | |
2ad4dad0 | 247 | Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r |
50418baa HW |
248 | and BufferSize.\r |
249 | The Unicode string is produced by parsing the format string specified by FormatString.\r | |
250 | Arguments are pulled from the variable argument list specified by Marker based on the\r | |
251 | contents of the format string.\r | |
2ad4dad0 LG |
252 | The number of Unicode characters in the produced output buffer is returned not including\r |
253 | the Null-terminator.\r | |
2ad4dad0 | 254 | \r |
50418baa HW |
255 | If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r |
256 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r | |
257 | \r | |
258 | If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
259 | unmodified and 0 is returned.\r | |
260 | If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
261 | unmodified and 0 is returned.\r | |
262 | If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r | |
263 | (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r | |
264 | buffer is unmodified and 0 is returned.\r | |
265 | If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r | |
2ad4dad0 | 266 | PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r |
50418baa HW |
267 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r |
268 | \r | |
269 | If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r | |
2ad4dad0 | 270 | \r |
50418baa | 271 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r |
2ad4dad0 LG |
272 | Unicode string.\r |
273 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 274 | @param FormatString A Null-terminated Unicode format string.\r |
2ad4dad0 | 275 | @param Marker VA_LIST marker for the variable argument list.\r |
50418baa | 276 | \r |
2ad4dad0 LG |
277 | @return The number of Unicode characters in the produced output buffer not including the\r |
278 | Null-terminator.\r | |
279 | \r | |
280 | **/\r | |
281 | UINTN\r | |
282 | EFIAPI\r | |
283 | UnicodeVSPrint (\r | |
284 | OUT CHAR16 *StartOfBuffer,\r | |
285 | IN UINTN BufferSize,\r | |
286 | IN CONST CHAR16 *FormatString,\r | |
287 | IN VA_LIST Marker\r | |
288 | )\r | |
289 | {\r | |
7c6075e2 HW |
290 | UINT64 BaseListMarker[256 / sizeof (UINT64)];\r |
291 | BOOLEAN Converted;\r | |
292 | \r | |
50418baa HW |
293 | ASSERT_UNICODE_BUFFER (StartOfBuffer);\r |
294 | ASSERT_UNICODE_BUFFER (FormatString);\r | |
295 | \r | |
7c6075e2 HW |
296 | Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r |
297 | FALSE,\r | |
298 | (CHAR8 *)FormatString,\r | |
299 | Marker,\r | |
300 | (BASE_LIST)BaseListMarker,\r | |
301 | sizeof (BaseListMarker) - 8\r | |
302 | );\r | |
303 | if (!Converted) {\r | |
304 | return 0;\r | |
305 | }\r | |
504dcb0a | 306 | \r |
307 | return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r | |
308 | }\r | |
309 | \r | |
310 | /**\r | |
50418baa HW |
311 | Produces a Null-terminated Unicode string in an output buffer based on\r |
312 | a Null-terminated Unicode format string and a BASE_LIST argument list.\r | |
313 | \r | |
504dcb0a | 314 | Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r |
50418baa HW |
315 | and BufferSize.\r |
316 | The Unicode string is produced by parsing the format string specified by FormatString.\r | |
317 | Arguments are pulled from the variable argument list specified by Marker based on the\r | |
318 | contents of the format string.\r | |
504dcb0a | 319 | The number of Unicode characters in the produced output buffer is returned not including\r |
320 | the Null-terminator.\r | |
504dcb0a | 321 | \r |
50418baa HW |
322 | If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r |
323 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r | |
324 | \r | |
325 | If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
326 | unmodified and 0 is returned.\r | |
327 | If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
328 | unmodified and 0 is returned.\r | |
329 | If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r | |
330 | (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r | |
331 | buffer is unmodified and 0 is returned.\r | |
332 | If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r | |
504dcb0a | 333 | PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r |
50418baa HW |
334 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r |
335 | \r | |
336 | If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r | |
504dcb0a | 337 | \r |
50418baa | 338 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r |
504dcb0a | 339 | Unicode string.\r |
340 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 341 | @param FormatString A Null-terminated Unicode format string.\r |
504dcb0a | 342 | @param Marker BASE_LIST marker for the variable argument list.\r |
50418baa | 343 | \r |
504dcb0a | 344 | @return The number of Unicode characters in the produced output buffer not including the\r |
345 | Null-terminator.\r | |
346 | \r | |
347 | **/\r | |
348 | UINTN\r | |
349 | EFIAPI\r | |
350 | UnicodeBSPrint (\r | |
351 | OUT CHAR16 *StartOfBuffer,\r | |
352 | IN UINTN BufferSize,\r | |
353 | IN CONST CHAR16 *FormatString,\r | |
354 | IN BASE_LIST Marker\r | |
355 | )\r | |
356 | {\r | |
50418baa HW |
357 | ASSERT_UNICODE_BUFFER (StartOfBuffer);\r |
358 | ASSERT_UNICODE_BUFFER (FormatString);\r | |
f0c74f5a | 359 | return mPrint2SProtocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r |
a0afd019 | 360 | }\r |
361 | \r | |
2ad4dad0 | 362 | /**\r |
50418baa | 363 | Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r |
2ad4dad0 | 364 | Unicode format string and variable argument list.\r |
50418baa HW |
365 | \r |
366 | This function is similar as snprintf_s defined in C11.\r | |
367 | \r | |
2ad4dad0 LG |
368 | Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r |
369 | and BufferSize.\r | |
370 | The Unicode string is produced by parsing the format string specified by FormatString.\r | |
371 | Arguments are pulled from the variable argument list based on the contents of the format string.\r | |
372 | The number of Unicode characters in the produced output buffer is returned not including\r | |
373 | the Null-terminator.\r | |
2ad4dad0 | 374 | \r |
50418baa HW |
375 | If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r |
376 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r | |
377 | \r | |
378 | If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
379 | unmodified and 0 is returned.\r | |
380 | If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
381 | unmodified and 0 is returned.\r | |
382 | If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r | |
383 | (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r | |
384 | buffer is unmodified and 0 is returned.\r | |
385 | If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r | |
2ad4dad0 | 386 | PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r |
50418baa HW |
387 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r |
388 | \r | |
389 | If BufferSize is 0 or 1, then the output buffer is unmodified and 0 is returned.\r | |
2ad4dad0 | 390 | \r |
50418baa | 391 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r |
2ad4dad0 LG |
392 | Unicode string.\r |
393 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa HW |
394 | @param FormatString A Null-terminated Unicode format string.\r |
395 | @param ... Variable argument list whose contents are accessed based on the\r | |
71898234 | 396 | format string specified by FormatString.\r |
ce95aa7a | 397 | \r |
2ad4dad0 LG |
398 | @return The number of Unicode characters in the produced output buffer not including the\r |
399 | Null-terminator.\r | |
400 | \r | |
401 | **/\r | |
a0afd019 | 402 | UINTN\r |
2ad4dad0 | 403 | EFIAPI\r |
a0afd019 | 404 | UnicodeSPrint (\r |
405 | OUT CHAR16 *StartOfBuffer,\r | |
406 | IN UINTN BufferSize,\r | |
2ad4dad0 | 407 | IN CONST CHAR16 *FormatString,\r |
a0afd019 | 408 | ...\r |
409 | )\r | |
a0afd019 | 410 | {\r |
2ad4dad0 | 411 | VA_LIST Marker;\r |
3bbe68a3 | 412 | UINTN NumberOfPrinted;\r |
a0afd019 | 413 | \r |
414 | VA_START (Marker, FormatString);\r | |
3bbe68a3 | 415 | NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r |
416 | VA_END (Marker);\r | |
417 | return NumberOfPrinted;\r | |
a0afd019 | 418 | }\r |
419 | \r | |
2ad4dad0 LG |
420 | /**\r |
421 | Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r | |
50418baa HW |
422 | ASCII format string and a VA_LIST argument list.\r |
423 | \r | |
424 | This function is similar as vsnprintf_s defined in C11.\r | |
425 | \r | |
2ad4dad0 LG |
426 | Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r |
427 | and BufferSize.\r | |
428 | The Unicode string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 429 | Arguments are pulled from the variable argument list specified by Marker based on the\r |
2ad4dad0 LG |
430 | contents of the format string.\r |
431 | The number of Unicode characters in the produced output buffer is returned not including\r | |
432 | the Null-terminator.\r | |
2ad4dad0 | 433 | \r |
50418baa HW |
434 | If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r |
435 | \r | |
436 | If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
437 | unmodified and 0 is returned.\r | |
438 | If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
439 | unmodified and 0 is returned.\r | |
440 | If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r | |
441 | (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r | |
442 | buffer is unmodified and 0 is returned.\r | |
2ad4dad0 | 443 | If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r |
50418baa HW |
444 | PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r |
445 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r | |
2ad4dad0 | 446 | \r |
50418baa HW |
447 | If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r |
448 | \r | |
449 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r | |
2ad4dad0 LG |
450 | Unicode string.\r |
451 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 452 | @param FormatString A Null-terminated ASCII format string.\r |
2ad4dad0 | 453 | @param Marker VA_LIST marker for the variable argument list.\r |
50418baa | 454 | \r |
2ad4dad0 LG |
455 | @return The number of Unicode characters in the produced output buffer not including the\r |
456 | Null-terminator.\r | |
457 | \r | |
458 | **/\r | |
a0afd019 | 459 | UINTN\r |
2ad4dad0 LG |
460 | EFIAPI\r |
461 | UnicodeVSPrintAsciiFormat (\r | |
462 | OUT CHAR16 *StartOfBuffer,\r | |
463 | IN UINTN BufferSize,\r | |
464 | IN CONST CHAR8 *FormatString,\r | |
465 | IN VA_LIST Marker\r | |
a0afd019 | 466 | )\r |
2ad4dad0 | 467 | {\r |
7c6075e2 HW |
468 | UINT64 BaseListMarker[256 / sizeof (UINT64)];\r |
469 | BOOLEAN Converted;\r | |
470 | \r | |
50418baa HW |
471 | ASSERT_UNICODE_BUFFER (StartOfBuffer);\r |
472 | \r | |
7c6075e2 HW |
473 | Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r |
474 | TRUE,\r | |
475 | FormatString,\r | |
476 | Marker,\r | |
477 | (BASE_LIST)BaseListMarker,\r | |
478 | sizeof (BaseListMarker) - 8\r | |
479 | );\r | |
480 | if (!Converted) {\r | |
481 | return 0;\r | |
482 | }\r | |
504dcb0a | 483 | \r |
484 | return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r | |
485 | }\r | |
486 | \r | |
487 | /**\r | |
488 | Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r | |
50418baa HW |
489 | ASCII format string and a BASE_LIST argument list.\r |
490 | \r | |
504dcb0a | 491 | Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r |
492 | and BufferSize.\r | |
493 | The Unicode string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 494 | Arguments are pulled from the variable argument list specified by Marker based on the\r |
504dcb0a | 495 | contents of the format string.\r |
496 | The number of Unicode characters in the produced output buffer is returned not including\r | |
497 | the Null-terminator.\r | |
504dcb0a | 498 | \r |
50418baa HW |
499 | If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r |
500 | \r | |
501 | If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
502 | unmodified and 0 is returned.\r | |
503 | If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
504 | unmodified and 0 is returned.\r | |
505 | If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r | |
506 | (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r | |
507 | buffer is unmodified and 0 is returned.\r | |
504dcb0a | 508 | If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r |
50418baa HW |
509 | PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r |
510 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r | |
511 | \r | |
512 | If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r | |
504dcb0a | 513 | \r |
50418baa | 514 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r |
504dcb0a | 515 | Unicode string.\r |
516 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 517 | @param FormatString A Null-terminated ASCII format string.\r |
504dcb0a | 518 | @param Marker BASE_LIST marker for the variable argument list.\r |
50418baa | 519 | \r |
504dcb0a | 520 | @return The number of Unicode characters in the produced output buffer not including the\r |
521 | Null-terminator.\r | |
522 | \r | |
523 | **/\r | |
524 | UINTN\r | |
525 | EFIAPI\r | |
526 | UnicodeBSPrintAsciiFormat (\r | |
527 | OUT CHAR16 *StartOfBuffer,\r | |
528 | IN UINTN BufferSize,\r | |
529 | IN CONST CHAR8 *FormatString,\r | |
530 | IN BASE_LIST Marker\r | |
531 | )\r | |
532 | {\r | |
50418baa | 533 | ASSERT_UNICODE_BUFFER (StartOfBuffer);\r |
f0c74f5a | 534 | return mPrint2SProtocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r |
2ad4dad0 | 535 | }\r |
a0afd019 | 536 | \r |
2ad4dad0 | 537 | /**\r |
50418baa | 538 | Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r |
2ad4dad0 | 539 | ASCII format string and variable argument list.\r |
50418baa HW |
540 | \r |
541 | This function is similar as snprintf_s defined in C11.\r | |
542 | \r | |
2ad4dad0 LG |
543 | Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r |
544 | and BufferSize.\r | |
545 | The Unicode string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 546 | Arguments are pulled from the variable argument list based on the contents of the\r |
2ad4dad0 LG |
547 | format string.\r |
548 | The number of Unicode characters in the produced output buffer is returned not including\r | |
549 | the Null-terminator.\r | |
2ad4dad0 | 550 | \r |
50418baa HW |
551 | If StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r |
552 | \r | |
553 | If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
554 | unmodified and 0 is returned.\r | |
555 | If BufferSize > 1 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
556 | unmodified and 0 is returned.\r | |
557 | If PcdMaximumUnicodeStringLength is not zero, and BufferSize >\r | |
558 | (PcdMaximumUnicodeStringLength * sizeof (CHAR16) + 1), then ASSERT(). Also, the output\r | |
559 | buffer is unmodified and 0 is returned.\r | |
2ad4dad0 | 560 | If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r |
50418baa HW |
561 | PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r |
562 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r | |
563 | \r | |
564 | If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r | |
2ad4dad0 | 565 | \r |
50418baa | 566 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r |
2ad4dad0 LG |
567 | Unicode string.\r |
568 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa HW |
569 | @param FormatString A Null-terminated ASCII format string.\r |
570 | @param ... Variable argument list whose contents are accessed based on the\r | |
71898234 | 571 | format string specified by FormatString.\r |
50418baa | 572 | \r |
2ad4dad0 LG |
573 | @return The number of Unicode characters in the produced output buffer not including the\r |
574 | Null-terminator.\r | |
575 | \r | |
576 | **/\r | |
577 | UINTN\r | |
578 | EFIAPI\r | |
579 | UnicodeSPrintAsciiFormat (\r | |
580 | OUT CHAR16 *StartOfBuffer,\r | |
581 | IN UINTN BufferSize,\r | |
582 | IN CONST CHAR8 *FormatString,\r | |
583 | ...\r | |
584 | )\r | |
585 | {\r | |
586 | VA_LIST Marker;\r | |
3bbe68a3 | 587 | UINTN NumberOfPrinted;\r |
a0afd019 | 588 | \r |
2ad4dad0 | 589 | VA_START (Marker, FormatString);\r |
3bbe68a3 | 590 | NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r |
591 | VA_END (Marker);\r | |
592 | return NumberOfPrinted;\r | |
2ad4dad0 | 593 | }\r |
a0afd019 | 594 | \r |
9e32e971 HW |
595 | /**\r |
596 | Converts a decimal value to a Null-terminated Unicode string.\r | |
597 | \r | |
598 | Converts the decimal number specified by Value to a Null-terminated Unicode\r | |
599 | string specified by Buffer containing at most Width characters. No padding of\r | |
600 | spaces is ever performed. If Width is 0 then a width of\r | |
601 | MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r | |
602 | Width characters, then only the first Width characters are placed in Buffer.\r | |
603 | Additional conversion parameters are specified in Flags.\r | |
604 | \r | |
605 | The Flags bit LEFT_JUSTIFY is always ignored.\r | |
606 | All conversions are left justified in Buffer.\r | |
607 | If Width is 0, PREFIX_ZERO is ignored in Flags.\r | |
608 | If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r | |
609 | commas are inserted every 3rd digit starting from the right.\r | |
610 | If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r | |
611 | hexadecimal format.\r | |
612 | If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r | |
613 | Buffer is a '-'.\r | |
614 | If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r | |
615 | Buffer is padded with '0' characters so the combination of the optional '-'\r | |
616 | sign character, '0' characters, digit characters for Value, and the\r | |
617 | Null-terminator add up to Width characters.\r | |
618 | \r | |
619 | If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r | |
620 | If an error would be returned, then the function will also ASSERT().\r | |
621 | \r | |
622 | @param Buffer The pointer to the output buffer for the produced\r | |
623 | Null-terminated Unicode string.\r | |
624 | @param BufferSize The size of Buffer in bytes, including the\r | |
625 | Null-terminator.\r | |
626 | @param Flags The bitmask of flags that specify left justification,\r | |
627 | zero pad, and commas.\r | |
628 | @param Value The 64-bit signed value to convert to a string.\r | |
629 | @param Width The maximum number of Unicode characters to place in\r | |
630 | Buffer, not including the Null-terminator.\r | |
631 | \r | |
632 | @retval RETURN_SUCCESS The decimal value is converted.\r | |
633 | @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted\r | |
634 | value.\r | |
635 | @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r | |
636 | If PcdMaximumUnicodeStringLength is not\r | |
637 | zero, and BufferSize is greater than\r | |
638 | (PcdMaximumUnicodeStringLength *\r | |
639 | sizeof (CHAR16) + 1).\r | |
640 | If unsupported bits are set in Flags.\r | |
641 | If both COMMA_TYPE and RADIX_HEX are set in\r | |
642 | Flags.\r | |
643 | If Width >= MAXIMUM_VALUE_CHARACTERS.\r | |
644 | \r | |
645 | **/\r | |
646 | RETURN_STATUS\r | |
647 | EFIAPI\r | |
648 | UnicodeValueToStringS (\r | |
649 | IN OUT CHAR16 *Buffer,\r | |
650 | IN UINTN BufferSize,\r | |
651 | IN UINTN Flags,\r | |
652 | IN INT64 Value,\r | |
653 | IN UINTN Width\r | |
654 | )\r | |
655 | {\r | |
656 | return mPrint2SProtocol->UnicodeValueToStringS (Buffer, BufferSize, Flags, Value, Width);\r | |
657 | }\r | |
658 | \r | |
2ad4dad0 LG |
659 | /**\r |
660 | Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r | |
661 | ASCII format string and a VA_LIST argument list.\r | |
50418baa HW |
662 | \r |
663 | This function is similar as vsnprintf_s defined in C11.\r | |
664 | \r | |
2ad4dad0 LG |
665 | Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r |
666 | and BufferSize.\r | |
667 | The ASCII string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 668 | Arguments are pulled from the variable argument list specified by Marker based on\r |
2ad4dad0 LG |
669 | the contents of the format string.\r |
670 | The number of ASCII characters in the produced output buffer is returned not including\r | |
671 | the Null-terminator.\r | |
2ad4dad0 | 672 | \r |
50418baa HW |
673 | If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r |
674 | unmodified and 0 is returned.\r | |
675 | If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
676 | unmodified and 0 is returned.\r | |
677 | If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r | |
678 | (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r | |
679 | is unmodified and 0 is returned.\r | |
2ad4dad0 | 680 | If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r |
50418baa HW |
681 | PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r |
682 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r | |
683 | \r | |
684 | If BufferSize is 0, then no output buffer is produced and 0 is returned.\r | |
2ad4dad0 | 685 | \r |
50418baa | 686 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r |
2ad4dad0 LG |
687 | ASCII string.\r |
688 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 689 | @param FormatString A Null-terminated ASCII format string.\r |
2ad4dad0 | 690 | @param Marker VA_LIST marker for the variable argument list.\r |
50418baa | 691 | \r |
2ad4dad0 LG |
692 | @return The number of ASCII characters in the produced output buffer not including the\r |
693 | Null-terminator.\r | |
694 | \r | |
695 | **/\r | |
696 | UINTN\r | |
697 | EFIAPI\r | |
698 | AsciiVSPrint (\r | |
699 | OUT CHAR8 *StartOfBuffer,\r | |
700 | IN UINTN BufferSize,\r | |
701 | IN CONST CHAR8 *FormatString,\r | |
702 | IN VA_LIST Marker\r | |
703 | )\r | |
a0afd019 | 704 | {\r |
7c6075e2 HW |
705 | UINT64 BaseListMarker[256 / sizeof (UINT64)];\r |
706 | BOOLEAN Converted;\r | |
707 | \r | |
708 | Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r | |
709 | TRUE,\r | |
710 | FormatString,\r | |
711 | Marker,\r | |
712 | (BASE_LIST)BaseListMarker,\r | |
713 | sizeof (BaseListMarker) - 8\r | |
714 | );\r | |
715 | if (!Converted) {\r | |
716 | return 0;\r | |
717 | }\r | |
504dcb0a | 718 | \r |
719 | return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r | |
720 | }\r | |
721 | \r | |
722 | /**\r | |
723 | Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r | |
724 | ASCII format string and a BASE_LIST argument list.\r | |
50418baa | 725 | \r |
504dcb0a | 726 | Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r |
727 | and BufferSize.\r | |
728 | The ASCII string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 729 | Arguments are pulled from the variable argument list specified by Marker based on\r |
504dcb0a | 730 | the contents of the format string.\r |
731 | The number of ASCII characters in the produced output buffer is returned not including\r | |
732 | the Null-terminator.\r | |
504dcb0a | 733 | \r |
50418baa HW |
734 | If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r |
735 | unmodified and 0 is returned.\r | |
736 | If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
737 | unmodified and 0 is returned.\r | |
738 | If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r | |
739 | (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r | |
740 | is unmodified and 0 is returned.\r | |
504dcb0a | 741 | If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r |
50418baa HW |
742 | PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r |
743 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r | |
504dcb0a | 744 | \r |
50418baa HW |
745 | If BufferSize is 0, then no output buffer is produced and 0 is returned.\r |
746 | \r | |
747 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r | |
504dcb0a | 748 | ASCII string.\r |
749 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 750 | @param FormatString A Null-terminated ASCII format string.\r |
504dcb0a | 751 | @param Marker BASE_LIST marker for the variable argument list.\r |
50418baa | 752 | \r |
504dcb0a | 753 | @return The number of ASCII characters in the produced output buffer not including the\r |
754 | Null-terminator.\r | |
755 | \r | |
756 | **/\r | |
757 | UINTN\r | |
758 | EFIAPI\r | |
759 | AsciiBSPrint (\r | |
760 | OUT CHAR8 *StartOfBuffer,\r | |
761 | IN UINTN BufferSize,\r | |
762 | IN CONST CHAR8 *FormatString,\r | |
763 | IN BASE_LIST Marker\r | |
764 | )\r | |
765 | {\r | |
f0c74f5a | 766 | return mPrint2SProtocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r |
a0afd019 | 767 | }\r |
768 | \r | |
2ad4dad0 LG |
769 | /**\r |
770 | Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r | |
771 | ASCII format string and variable argument list.\r | |
50418baa HW |
772 | \r |
773 | This function is similar as snprintf_s defined in C11.\r | |
774 | \r | |
2ad4dad0 LG |
775 | Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r |
776 | and BufferSize.\r | |
777 | The ASCII string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 778 | Arguments are pulled from the variable argument list based on the contents of the\r |
2ad4dad0 LG |
779 | format string.\r |
780 | The number of ASCII characters in the produced output buffer is returned not including\r | |
781 | the Null-terminator.\r | |
2ad4dad0 | 782 | \r |
50418baa HW |
783 | If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r |
784 | unmodified and 0 is returned.\r | |
785 | If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
786 | unmodified and 0 is returned.\r | |
787 | If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r | |
788 | (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r | |
789 | is unmodified and 0 is returned.\r | |
2ad4dad0 | 790 | If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r |
50418baa HW |
791 | PcdMaximumAsciiStringLength Ascii characters not including the Null-terminator, then\r |
792 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r | |
793 | \r | |
794 | If BufferSize is 0, then no output buffer is produced and 0 is returned.\r | |
2ad4dad0 | 795 | \r |
50418baa | 796 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r |
2ad4dad0 LG |
797 | ASCII string.\r |
798 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa HW |
799 | @param FormatString A Null-terminated ASCII format string.\r |
800 | @param ... Variable argument list whose contents are accessed based on the\r | |
71898234 | 801 | format string specified by FormatString.\r |
ce95aa7a | 802 | \r |
2ad4dad0 LG |
803 | @return The number of ASCII characters in the produced output buffer not including the\r |
804 | Null-terminator.\r | |
805 | \r | |
806 | **/\r | |
a0afd019 | 807 | UINTN\r |
2ad4dad0 | 808 | EFIAPI\r |
a0afd019 | 809 | AsciiSPrint (\r |
810 | OUT CHAR8 *StartOfBuffer,\r | |
811 | IN UINTN BufferSize,\r | |
2ad4dad0 | 812 | IN CONST CHAR8 *FormatString,\r |
a0afd019 | 813 | ...\r |
814 | )\r | |
2ad4dad0 LG |
815 | {\r |
816 | VA_LIST Marker;\r | |
3bbe68a3 | 817 | UINTN NumberOfPrinted;\r |
2ad4dad0 LG |
818 | \r |
819 | VA_START (Marker, FormatString);\r | |
3bbe68a3 | 820 | NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r |
821 | VA_END (Marker);\r | |
822 | return NumberOfPrinted;\r | |
2ad4dad0 | 823 | }\r |
a0afd019 | 824 | \r |
2ad4dad0 LG |
825 | /**\r |
826 | Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r | |
50418baa HW |
827 | Unicode format string and a VA_LIST argument list.\r |
828 | \r | |
829 | This function is similar as vsnprintf_s defined in C11.\r | |
830 | \r | |
2ad4dad0 LG |
831 | Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r |
832 | and BufferSize.\r | |
833 | The ASCII string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 834 | Arguments are pulled from the variable argument list specified by Marker based on\r |
2ad4dad0 LG |
835 | the contents of the format string.\r |
836 | The number of ASCII characters in the produced output buffer is returned not including\r | |
837 | the Null-terminator.\r | |
2ad4dad0 | 838 | \r |
50418baa HW |
839 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r |
840 | \r | |
841 | If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
842 | unmodified and 0 is returned.\r | |
843 | If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
844 | unmodified and 0 is returned.\r | |
845 | If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r | |
846 | (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r | |
847 | is unmodified and 0 is returned.\r | |
2ad4dad0 LG |
848 | If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r |
849 | PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r | |
50418baa | 850 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r |
2ad4dad0 | 851 | \r |
50418baa HW |
852 | If BufferSize is 0, then no output buffer is produced and 0 is returned.\r |
853 | \r | |
854 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r | |
2ad4dad0 LG |
855 | ASCII string.\r |
856 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 857 | @param FormatString A Null-terminated Unicode format string.\r |
2ad4dad0 | 858 | @param Marker VA_LIST marker for the variable argument list.\r |
50418baa | 859 | \r |
2ad4dad0 LG |
860 | @return The number of ASCII characters in the produced output buffer not including the\r |
861 | Null-terminator.\r | |
862 | \r | |
863 | **/\r | |
864 | UINTN\r | |
865 | EFIAPI\r | |
866 | AsciiVSPrintUnicodeFormat (\r | |
867 | OUT CHAR8 *StartOfBuffer,\r | |
868 | IN UINTN BufferSize,\r | |
869 | IN CONST CHAR16 *FormatString,\r | |
870 | IN VA_LIST Marker\r | |
871 | )\r | |
a0afd019 | 872 | {\r |
7c6075e2 HW |
873 | UINT64 BaseListMarker[256 / sizeof (UINT64)];\r |
874 | BOOLEAN Converted;\r | |
875 | \r | |
50418baa HW |
876 | ASSERT_UNICODE_BUFFER (FormatString);\r |
877 | \r | |
7c6075e2 HW |
878 | Converted = DxePrintLibPrint2ProtocolVaListToBaseList (\r |
879 | FALSE,\r | |
880 | (CHAR8 *)FormatString,\r | |
881 | Marker,\r | |
882 | (BASE_LIST)BaseListMarker,\r | |
883 | sizeof (BaseListMarker) - 8\r | |
884 | );\r | |
885 | if (!Converted) {\r | |
886 | return 0;\r | |
887 | }\r | |
504dcb0a | 888 | \r |
889 | return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r | |
890 | }\r | |
891 | \r | |
892 | /**\r | |
893 | Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r | |
50418baa HW |
894 | Unicode format string and a BASE_LIST argument list.\r |
895 | \r | |
504dcb0a | 896 | Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r |
897 | and BufferSize.\r | |
898 | The ASCII string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 899 | Arguments are pulled from the variable argument list specified by Marker based on\r |
504dcb0a | 900 | the contents of the format string.\r |
901 | The number of ASCII characters in the produced output buffer is returned not including\r | |
902 | the Null-terminator.\r | |
504dcb0a | 903 | \r |
50418baa HW |
904 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r |
905 | \r | |
906 | If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
907 | unmodified and 0 is returned.\r | |
908 | If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
909 | unmodified and 0 is returned.\r | |
910 | If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r | |
911 | (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r | |
912 | is unmodified and 0 is returned.\r | |
504dcb0a | 913 | If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r |
914 | PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r | |
50418baa | 915 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r |
504dcb0a | 916 | \r |
50418baa HW |
917 | If BufferSize is 0, then no output buffer is produced and 0 is returned.\r |
918 | \r | |
919 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r | |
504dcb0a | 920 | ASCII string.\r |
921 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa | 922 | @param FormatString A Null-terminated Unicode format string.\r |
504dcb0a | 923 | @param Marker BASE_LIST marker for the variable argument list.\r |
50418baa | 924 | \r |
504dcb0a | 925 | @return The number of ASCII characters in the produced output buffer not including the\r |
926 | Null-terminator.\r | |
927 | \r | |
928 | **/\r | |
929 | UINTN\r | |
930 | EFIAPI\r | |
931 | AsciiBSPrintUnicodeFormat (\r | |
932 | OUT CHAR8 *StartOfBuffer,\r | |
933 | IN UINTN BufferSize,\r | |
934 | IN CONST CHAR16 *FormatString,\r | |
935 | IN BASE_LIST Marker\r | |
936 | )\r | |
937 | {\r | |
50418baa | 938 | ASSERT_UNICODE_BUFFER (FormatString);\r |
f0c74f5a | 939 | return mPrint2SProtocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r |
2ad4dad0 LG |
940 | }\r |
941 | \r | |
942 | /**\r | |
943 | Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r | |
50418baa HW |
944 | Unicode format string and variable argument list.\r |
945 | \r | |
946 | This function is similar as snprintf_s defined in C11.\r | |
947 | \r | |
2ad4dad0 LG |
948 | Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r |
949 | and BufferSize.\r | |
950 | The ASCII string is produced by parsing the format string specified by FormatString.\r | |
50418baa | 951 | Arguments are pulled from the variable argument list based on the contents of the\r |
2ad4dad0 LG |
952 | format string.\r |
953 | The number of ASCII characters in the produced output buffer is returned not including\r | |
954 | the Null-terminator.\r | |
2ad4dad0 | 955 | \r |
50418baa HW |
956 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r |
957 | \r | |
958 | If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT(). Also, the output buffer is\r | |
959 | unmodified and 0 is returned.\r | |
960 | If BufferSize > 0 and FormatString is NULL, then ASSERT(). Also, the output buffer is\r | |
961 | unmodified and 0 is returned.\r | |
962 | If PcdMaximumAsciiStringLength is not zero, and BufferSize >\r | |
963 | (PcdMaximumAsciiStringLength * sizeof (CHAR8)), then ASSERT(). Also, the output buffer\r | |
964 | is unmodified and 0 is returned.\r | |
2ad4dad0 LG |
965 | If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r |
966 | PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r | |
50418baa | 967 | ASSERT(). Also, the output buffer is unmodified and 0 is returned.\r |
2ad4dad0 | 968 | \r |
50418baa HW |
969 | If BufferSize is 0, then no output buffer is produced and 0 is returned.\r |
970 | \r | |
971 | @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r | |
2ad4dad0 LG |
972 | ASCII string.\r |
973 | @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r | |
50418baa HW |
974 | @param FormatString A Null-terminated Unicode format string.\r |
975 | @param ... Variable argument list whose contents are accessed based on the\r | |
71898234 | 976 | format string specified by FormatString.\r |
ce95aa7a | 977 | \r |
2ad4dad0 LG |
978 | @return The number of ASCII characters in the produced output buffer not including the\r |
979 | Null-terminator.\r | |
980 | \r | |
981 | **/\r | |
982 | UINTN\r | |
983 | EFIAPI\r | |
984 | AsciiSPrintUnicodeFormat (\r | |
985 | OUT CHAR8 *StartOfBuffer,\r | |
986 | IN UINTN BufferSize,\r | |
987 | IN CONST CHAR16 *FormatString,\r | |
988 | ...\r | |
989 | )\r | |
990 | {\r | |
991 | VA_LIST Marker;\r | |
3bbe68a3 | 992 | UINTN NumberOfPrinted;\r |
a0afd019 | 993 | \r |
994 | VA_START (Marker, FormatString);\r | |
3bbe68a3 | 995 | NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r |
996 | VA_END (Marker);\r | |
997 | return NumberOfPrinted;\r | |
2ad4dad0 LG |
998 | }\r |
999 | \r | |
1000 | \r | |
9e32e971 HW |
1001 | /**\r |
1002 | Converts a decimal value to a Null-terminated Ascii string.\r | |
1003 | \r | |
1004 | Converts the decimal number specified by Value to a Null-terminated Ascii\r | |
1005 | string specified by Buffer containing at most Width characters. No padding of\r | |
1006 | spaces is ever performed. If Width is 0 then a width of\r | |
1007 | MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more than\r | |
1008 | Width characters, then only the first Width characters are placed in Buffer.\r | |
1009 | Additional conversion parameters are specified in Flags.\r | |
1010 | \r | |
1011 | The Flags bit LEFT_JUSTIFY is always ignored.\r | |
1012 | All conversions are left justified in Buffer.\r | |
1013 | If Width is 0, PREFIX_ZERO is ignored in Flags.\r | |
1014 | If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and\r | |
1015 | commas are inserted every 3rd digit starting from the right.\r | |
1016 | If RADIX_HEX is set in Flags, then the output buffer will be formatted in\r | |
1017 | hexadecimal format.\r | |
1018 | If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in\r | |
1019 | Buffer is a '-'.\r | |
1020 | If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then\r | |
1021 | Buffer is padded with '0' characters so the combination of the optional '-'\r | |
1022 | sign character, '0' characters, digit characters for Value, and the\r | |
1023 | Null-terminator add up to Width characters.\r | |
1024 | \r | |
ba5cd2ff | 1025 | If an error would be returned, then the function will ASSERT().\r |
9e32e971 HW |
1026 | \r |
1027 | @param Buffer The pointer to the output buffer for the produced\r | |
1028 | Null-terminated Ascii string.\r | |
1029 | @param BufferSize The size of Buffer in bytes, including the\r | |
1030 | Null-terminator.\r | |
1031 | @param Flags The bitmask of flags that specify left justification,\r | |
1032 | zero pad, and commas.\r | |
1033 | @param Value The 64-bit signed value to convert to a string.\r | |
1034 | @param Width The maximum number of Ascii characters to place in\r | |
1035 | Buffer, not including the Null-terminator.\r | |
1036 | \r | |
1037 | @retval RETURN_SUCCESS The decimal value is converted.\r | |
1038 | @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted\r | |
1039 | value.\r | |
1040 | @retval RETURN_INVALID_PARAMETER If Buffer is NULL.\r | |
1041 | If PcdMaximumAsciiStringLength is not\r | |
1042 | zero, and BufferSize is greater than\r | |
1043 | PcdMaximumAsciiStringLength.\r | |
1044 | If unsupported bits are set in Flags.\r | |
1045 | If both COMMA_TYPE and RADIX_HEX are set in\r | |
1046 | Flags.\r | |
1047 | If Width >= MAXIMUM_VALUE_CHARACTERS.\r | |
1048 | \r | |
1049 | **/\r | |
1050 | RETURN_STATUS\r | |
1051 | EFIAPI\r | |
1052 | AsciiValueToStringS (\r | |
1053 | IN OUT CHAR8 *Buffer,\r | |
1054 | IN UINTN BufferSize,\r | |
1055 | IN UINTN Flags,\r | |
1056 | IN INT64 Value,\r | |
1057 | IN UINTN Width\r | |
1058 | )\r | |
1059 | {\r | |
1060 | return mPrint2SProtocol->AsciiValueToStringS (Buffer, BufferSize, Flags, Value, Width);\r | |
1061 | }\r | |
1062 | \r | |
f405c067 | 1063 | #define PREFIX_SIGN BIT1\r |
1064 | #define PREFIX_BLANK BIT2\r | |
1065 | #define LONG_TYPE BIT4\r | |
1066 | #define OUTPUT_UNICODE BIT6\r | |
1067 | #define FORMAT_UNICODE BIT8\r | |
1068 | #define PAD_TO_WIDTH BIT9\r | |
1069 | #define ARGUMENT_UNICODE BIT10\r | |
1070 | #define PRECISION BIT11\r | |
1071 | #define ARGUMENT_REVERSED BIT12\r | |
1072 | #define COUNT_ONLY_NO_PRINT BIT13\r | |
796fecd8 | 1073 | #define UNSIGNED_TYPE BIT14\r |
f405c067 | 1074 | \r |
1075 | //\r | |
1076 | // Record date and time information\r | |
1077 | //\r | |
1078 | typedef struct {\r | |
1079 | UINT16 Year;\r | |
1080 | UINT8 Month;\r | |
1081 | UINT8 Day;\r | |
1082 | UINT8 Hour;\r | |
1083 | UINT8 Minute;\r | |
1084 | UINT8 Second;\r | |
1085 | UINT8 Pad1;\r | |
1086 | UINT32 Nanosecond;\r | |
1087 | INT16 TimeZone;\r | |
1088 | UINT8 Daylight;\r | |
1089 | UINT8 Pad2;\r | |
1090 | } TIME;\r | |
1091 | \r | |
1092 | GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r | |
1093 | \r | |
1094 | /**\r | |
1095 | Internal function that convert a number to a string in Buffer.\r | |
1096 | \r | |
1097 | Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.\r | |
1098 | \r | |
1099 | @param Buffer Location to place the ASCII string of Value.\r | |
1100 | @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.\r | |
1101 | @param Radix Radix of the value\r | |
1102 | \r | |
1103 | @return A pointer to the end of buffer filled with ASCII string.\r | |
1104 | \r | |
1105 | **/\r | |
1106 | CHAR8 *\r | |
1107 | InternalPrintLibValueToString (\r | |
d1102dba LG |
1108 | IN OUT CHAR8 *Buffer,\r |
1109 | IN INT64 Value,\r | |
f405c067 | 1110 | IN UINTN Radix\r |
1111 | )\r | |
1112 | {\r | |
1113 | UINT32 Remainder;\r | |
1114 | \r | |
1115 | //\r | |
1116 | // Loop to convert one digit at a time in reverse order\r | |
1117 | //\r | |
1118 | *Buffer = 0;\r | |
1119 | do {\r | |
1120 | Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);\r | |
1121 | *(++Buffer) = mHexStr[Remainder];\r | |
1122 | } while (Value != 0);\r | |
1123 | \r | |
1124 | //\r | |
1125 | // Return pointer of the end of filled buffer.\r | |
1126 | //\r | |
1127 | return Buffer;\r | |
1128 | }\r | |
1129 | \r | |
1130 | /**\r | |
d1102dba | 1131 | Worker function that produces a Null-terminated string in an output buffer\r |
f405c067 | 1132 | based on a Null-terminated format string and a VA_LIST argument list.\r |
1133 | \r | |
d1102dba LG |
1134 | VSPrint function to process format and place the results in Buffer. Since a\r |
1135 | VA_LIST is used this routine allows the nesting of Vararg routines. Thus\r | |
f405c067 | 1136 | this is the main print working routine.\r |
1137 | \r | |
1138 | If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r | |
1139 | \r | |
d1102dba | 1140 | @param[out] Buffer The character buffer to print the results of the\r |
f405c067 | 1141 | parsing of Format into.\r |
d1102dba | 1142 | @param[in] BufferSize The maximum number of characters to put into\r |
f405c067 | 1143 | buffer.\r |
1144 | @param[in] Flags Initial flags value.\r | |
d1102dba | 1145 | Can only have FORMAT_UNICODE, OUTPUT_UNICODE,\r |
f405c067 | 1146 | and COUNT_ONLY_NO_PRINT set.\r |
1147 | @param[in] Format A Null-terminated format string.\r | |
1148 | @param[in] VaListMarker VA_LIST style variable argument list consumed by\r | |
1149 | processing Format.\r | |
1150 | @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r | |
1151 | by processing Format.\r | |
1152 | \r | |
1153 | @return The number of characters printed not including the Null-terminator.\r | |
1154 | If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r | |
1155 | modification to Buffer.\r | |
1156 | \r | |
1157 | **/\r | |
1158 | UINTN\r | |
1159 | InternalPrintLibSPrintMarker (\r | |
1160 | OUT CHAR8 *Buffer,\r | |
1161 | IN UINTN BufferSize,\r | |
1162 | IN UINTN Flags,\r | |
1163 | IN CONST CHAR8 *Format,\r | |
1164 | IN VA_LIST VaListMarker, OPTIONAL\r | |
1165 | IN BASE_LIST BaseListMarker OPTIONAL\r | |
1166 | );\r | |
1167 | \r | |
1168 | /**\r | |
d1102dba | 1169 | Worker function that produces a Null-terminated string in an output buffer\r |
f405c067 | 1170 | based on a Null-terminated format string and variable argument list.\r |
1171 | \r | |
d1102dba LG |
1172 | VSPrint function to process format and place the results in Buffer. Since a\r |
1173 | VA_LIST is used this routine allows the nesting of Vararg routines. Thus\r | |
f405c067 | 1174 | this is the main print working routine\r |
1175 | \r | |
1176 | @param StartOfBuffer The character buffer to print the results of the parsing\r | |
1177 | of Format into.\r | |
1178 | @param BufferSize The maximum number of characters to put into buffer.\r | |
1179 | Zero means no limit.\r | |
1180 | @param Flags Initial flags value.\r | |
1181 | Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r | |
1182 | @param FormatString A Null-terminated format string.\r | |
1183 | @param ... The variable argument list.\r | |
1184 | \r | |
1185 | @return The number of characters printed.\r | |
1186 | \r | |
1187 | **/\r | |
1188 | UINTN\r | |
1189 | EFIAPI\r | |
1190 | InternalPrintLibSPrint (\r | |
1191 | OUT CHAR8 *StartOfBuffer,\r | |
1192 | IN UINTN BufferSize,\r | |
1193 | IN UINTN Flags,\r | |
1194 | IN CONST CHAR8 *FormatString,\r | |
1195 | ...\r | |
1196 | )\r | |
1197 | {\r | |
1198 | VA_LIST Marker;\r | |
3bbe68a3 | 1199 | UINTN NumberOfPrinted;\r |
f405c067 | 1200 | \r |
1201 | VA_START (Marker, FormatString);\r | |
3bbe68a3 | 1202 | NumberOfPrinted = InternalPrintLibSPrintMarker (StartOfBuffer, BufferSize, Flags, FormatString, Marker, NULL);\r |
1203 | VA_END (Marker);\r | |
1204 | return NumberOfPrinted;\r | |
f405c067 | 1205 | }\r |
1206 | \r | |
586d81d1 LG |
1207 | #define WARNING_STATUS_NUMBER 5\r |
1208 | #define ERROR_STATUS_NUMBER 33\r | |
f405c067 | 1209 | \r |
4c10f953 | 1210 | GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * CONST mStatusString[] = {\r |
f405c067 | 1211 | "Success", // RETURN_SUCCESS = 0\r |
1212 | "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1\r | |
1213 | "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2\r | |
1214 | "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3\r | |
1215 | "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4\r | |
586d81d1 | 1216 | "Warning Stale Data", // RETURN_WARN_STALE_DATA = 5\r |
f405c067 | 1217 | "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT\r |
1218 | "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT\r | |
1219 | "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT\r | |
1220 | "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT\r | |
1221 | "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT\r | |
1222 | "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT\r | |
1223 | "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT\r | |
1224 | "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT\r | |
1225 | "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT\r | |
1226 | "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT\r | |
1227 | "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT\r | |
1228 | "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT\r | |
1229 | "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT\r | |
1230 | "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT\r | |
1231 | "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT\r | |
1232 | "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT\r | |
1233 | "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT\r | |
1234 | "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT\r | |
1235 | "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT\r | |
1236 | "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT\r | |
1237 | "Aborted", // RETURN_ABORTED = 21 | MAX_BIT\r | |
1238 | "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT\r | |
1239 | "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT\r | |
586d81d1 LG |
1240 | "Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT\r |
1241 | "Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT\r | |
1242 | "Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT\r | |
1243 | "CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT\r | |
1244 | "End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT\r | |
1245 | "Reserved (29)", // RESERVED = 29 | MAX_BIT\r | |
1246 | "Reserved (30)", // RESERVED = 30 | MAX_BIT\r | |
1247 | "End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT\r | |
1248 | "Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT\r | |
1249 | "Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT\r | |
f405c067 | 1250 | };\r |
1251 | \r | |
586d81d1 LG |
1252 | /**\r |
1253 | Internal function that places the character into the Buffer.\r | |
1254 | \r | |
1255 | Internal function that places ASCII or Unicode character into the Buffer.\r | |
1256 | \r | |
1257 | @param Buffer The buffer to place the Unicode or ASCII string.\r | |
1258 | @param EndBuffer The end of the input Buffer. No characters will be\r | |
d1102dba | 1259 | placed after that.\r |
586d81d1 LG |
1260 | @param Length The count of character to be placed into Buffer.\r |
1261 | (Negative value indicates no buffer fill.)\r | |
1262 | @param Character The character to be placed into Buffer.\r | |
1263 | @param Increment The character increment in Buffer.\r | |
1264 | \r | |
1265 | @return Buffer.\r | |
1266 | \r | |
1267 | **/\r | |
1268 | CHAR8 *\r | |
1269 | InternalPrintLibFillBuffer (\r | |
1270 | OUT CHAR8 *Buffer,\r | |
1271 | IN CHAR8 *EndBuffer,\r | |
1272 | IN INTN Length,\r | |
1273 | IN UINTN Character,\r | |
1274 | IN INTN Increment\r | |
1275 | )\r | |
1276 | {\r | |
1277 | INTN Index;\r | |
d1102dba | 1278 | \r |
586d81d1 LG |
1279 | for (Index = 0; Index < Length && Buffer < EndBuffer; Index++) {\r |
1280 | *Buffer = (CHAR8) Character;\r | |
1281 | if (Increment != 1) {\r | |
1282 | *(Buffer + 1) = (CHAR8)(Character >> 8);\r | |
1283 | }\r | |
1284 | Buffer += Increment;\r | |
1285 | }\r | |
1286 | \r | |
1287 | return Buffer;\r | |
1288 | }\r | |
1289 | \r | |
f405c067 | 1290 | /**\r |
d1102dba | 1291 | Worker function that produces a Null-terminated string in an output buffer\r |
f405c067 | 1292 | based on a Null-terminated format string and a VA_LIST argument list.\r |
1293 | \r | |
d1102dba LG |
1294 | VSPrint function to process format and place the results in Buffer. Since a\r |
1295 | VA_LIST is used this routine allows the nesting of Vararg routines. Thus\r | |
f405c067 | 1296 | this is the main print working routine.\r |
1297 | \r | |
1298 | If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r | |
1299 | \r | |
d1102dba | 1300 | @param[out] Buffer The character buffer to print the results of the\r |
f405c067 | 1301 | parsing of Format into.\r |
d1102dba | 1302 | @param[in] BufferSize The maximum number of characters to put into\r |
f405c067 | 1303 | buffer.\r |
1304 | @param[in] Flags Initial flags value.\r | |
d1102dba | 1305 | Can only have FORMAT_UNICODE, OUTPUT_UNICODE,\r |
f405c067 | 1306 | and COUNT_ONLY_NO_PRINT set.\r |
1307 | @param[in] Format A Null-terminated format string.\r | |
1308 | @param[in] VaListMarker VA_LIST style variable argument list consumed by\r | |
1309 | processing Format.\r | |
1310 | @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r | |
1311 | by processing Format.\r | |
1312 | \r | |
1313 | @return The number of characters printed not including the Null-terminator.\r | |
1314 | If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r | |
1315 | modification to Buffer.\r | |
1316 | \r | |
1317 | **/\r | |
1318 | UINTN\r | |
1319 | InternalPrintLibSPrintMarker (\r | |
1320 | OUT CHAR8 *Buffer,\r | |
1321 | IN UINTN BufferSize,\r | |
1322 | IN UINTN Flags,\r | |
1323 | IN CONST CHAR8 *Format,\r | |
1324 | IN VA_LIST VaListMarker, OPTIONAL\r | |
1325 | IN BASE_LIST BaseListMarker OPTIONAL\r | |
1326 | )\r | |
1327 | {\r | |
586d81d1 | 1328 | CHAR8 *OriginalBuffer;\r |
f405c067 | 1329 | CHAR8 *EndBuffer;\r |
1330 | CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r | |
1331 | UINT32 BytesPerOutputCharacter;\r | |
1332 | UINTN BytesPerFormatCharacter;\r | |
1333 | UINTN FormatMask;\r | |
1334 | UINTN FormatCharacter;\r | |
1335 | UINTN Width;\r | |
1336 | UINTN Precision;\r | |
1337 | INT64 Value;\r | |
1338 | CONST CHAR8 *ArgumentString;\r | |
1339 | UINTN Character;\r | |
1340 | GUID *TmpGuid;\r | |
1341 | TIME *TmpTime;\r | |
1342 | UINTN Count;\r | |
1343 | UINTN ArgumentMask;\r | |
1344 | INTN BytesPerArgumentCharacter;\r | |
1345 | UINTN ArgumentCharacter;\r | |
1346 | BOOLEAN Done;\r | |
1347 | UINTN Index;\r | |
1348 | CHAR8 Prefix;\r | |
1349 | BOOLEAN ZeroPad;\r | |
1350 | BOOLEAN Comma;\r | |
1351 | UINTN Digits;\r | |
1352 | UINTN Radix;\r | |
1353 | RETURN_STATUS Status;\r | |
1354 | UINT32 GuidData1;\r | |
1355 | UINT16 GuidData2;\r | |
1356 | UINT16 GuidData3;\r | |
be5ec8c5 | 1357 | UINTN LengthToReturn;\r |
f405c067 | 1358 | \r |
1359 | //\r | |
1360 | // If you change this code be sure to match the 2 versions of this function.\r | |
d1102dba | 1361 | // Nearly identical logic is found in the BasePrintLib and\r |
f405c067 | 1362 | // DxePrintLibPrint2Protocol (both PrintLib instances).\r |
1363 | //\r | |
1364 | \r | |
50418baa HW |
1365 | //\r |
1366 | // 1. Buffer shall not be a null pointer when both BufferSize > 0 and\r | |
1367 | // COUNT_ONLY_NO_PRINT is not set in Flags.\r | |
1368 | //\r | |
1369 | if ((BufferSize > 0) && ((Flags & COUNT_ONLY_NO_PRINT) == 0)) {\r | |
1370 | SAFE_PRINT_CONSTRAINT_CHECK ((Buffer != NULL), 0);\r | |
1371 | }\r | |
1372 | \r | |
1373 | //\r | |
1374 | // 2. Format shall not be a null pointer when BufferSize > 0 or when\r | |
1375 | // COUNT_ONLY_NO_PRINT is set in Flags.\r | |
1376 | //\r | |
1377 | if ((BufferSize > 0) || ((Flags & COUNT_ONLY_NO_PRINT) != 0)) {\r | |
1378 | SAFE_PRINT_CONSTRAINT_CHECK ((Format != NULL), 0);\r | |
1379 | }\r | |
1380 | \r | |
1381 | //\r | |
1382 | // 3. BufferSize shall not be greater than RSIZE_MAX for Unicode output or\r | |
1383 | // ASCII_RSIZE_MAX for Ascii output.\r | |
1384 | //\r | |
1385 | if ((Flags & OUTPUT_UNICODE) != 0) {\r | |
1386 | if (RSIZE_MAX != 0) {\r | |
1387 | SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= RSIZE_MAX), 0);\r | |
1388 | }\r | |
1389 | BytesPerOutputCharacter = 2;\r | |
1390 | } else {\r | |
1391 | if (ASCII_RSIZE_MAX != 0) {\r | |
1392 | SAFE_PRINT_CONSTRAINT_CHECK ((BufferSize <= ASCII_RSIZE_MAX), 0);\r | |
1393 | }\r | |
1394 | BytesPerOutputCharacter = 1;\r | |
1395 | }\r | |
1396 | \r | |
1397 | //\r | |
1398 | // 4. Format shall not contain more than RSIZE_MAX Unicode characters or\r | |
1399 | // ASCII_RSIZE_MAX Ascii characters.\r | |
1400 | //\r | |
1401 | if ((Flags & FORMAT_UNICODE) != 0) {\r | |
1402 | if (RSIZE_MAX != 0) {\r | |
1403 | SAFE_PRINT_CONSTRAINT_CHECK ((StrnLenS ((CHAR16 *)Format, RSIZE_MAX + 1) <= RSIZE_MAX), 0);\r | |
1404 | }\r | |
1405 | BytesPerFormatCharacter = 2;\r | |
1406 | FormatMask = 0xffff;\r | |
1407 | } else {\r | |
1408 | if (ASCII_RSIZE_MAX != 0) {\r | |
1409 | SAFE_PRINT_CONSTRAINT_CHECK ((AsciiStrnLenS (Format, ASCII_RSIZE_MAX + 1) <= ASCII_RSIZE_MAX), 0);\r | |
1410 | }\r | |
1411 | BytesPerFormatCharacter = 1;\r | |
1412 | FormatMask = 0xff;\r | |
1413 | }\r | |
1414 | \r | |
586d81d1 LG |
1415 | if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {\r |
1416 | if (BufferSize == 0) {\r | |
1417 | Buffer = NULL;\r | |
1418 | }\r | |
1419 | } else {\r | |
1420 | //\r | |
1421 | // We can run without a Buffer for counting only.\r | |
1422 | //\r | |
1423 | if (BufferSize == 0) {\r | |
1424 | return 0;\r | |
1425 | }\r | |
f405c067 | 1426 | }\r |
1427 | \r | |
1428 | LengthToReturn = 0;\r | |
586d81d1 LG |
1429 | EndBuffer = NULL;\r |
1430 | OriginalBuffer = NULL;\r | |
f405c067 | 1431 | \r |
1432 | //\r | |
1433 | // Reserve space for the Null terminator.\r | |
1434 | //\r | |
586d81d1 LG |
1435 | if (Buffer != NULL) {\r |
1436 | BufferSize--;\r | |
1437 | OriginalBuffer = Buffer;\r | |
f405c067 | 1438 | \r |
586d81d1 LG |
1439 | //\r |
1440 | // Set the tag for the end of the input Buffer.\r | |
1441 | //\r | |
1442 | EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;\r | |
1443 | }\r | |
f405c067 | 1444 | \r |
f405c067 | 1445 | //\r |
1446 | // Get the first character from the format string\r | |
1447 | //\r | |
213da0b5 | 1448 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 1449 | \r |
1450 | //\r | |
1451 | // Loop until the end of the format string is reached or the output buffer is full\r | |
1452 | //\r | |
586d81d1 LG |
1453 | while (FormatCharacter != 0) {\r |
1454 | if ((Buffer != NULL) && (Buffer >= EndBuffer)) {\r | |
1455 | break;\r | |
1456 | }\r | |
f405c067 | 1457 | //\r |
1458 | // Clear all the flag bits except those that may have been passed in\r | |
1459 | //\r | |
586d81d1 | 1460 | Flags &= (UINTN) (OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);\r |
f405c067 | 1461 | \r |
1462 | //\r | |
1463 | // Set the default width to zero, and the default precision to 1\r | |
1464 | //\r | |
1465 | Width = 0;\r | |
1466 | Precision = 1;\r | |
1467 | Prefix = 0;\r | |
1468 | Comma = FALSE;\r | |
1469 | ZeroPad = FALSE;\r | |
1470 | Count = 0;\r | |
1471 | Digits = 0;\r | |
1472 | \r | |
1473 | switch (FormatCharacter) {\r | |
1474 | case '%':\r | |
1475 | //\r | |
1476 | // Parse Flags and Width\r | |
1477 | //\r | |
1478 | for (Done = FALSE; !Done; ) {\r | |
1479 | Format += BytesPerFormatCharacter;\r | |
213da0b5 | 1480 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 1481 | switch (FormatCharacter) {\r |
d1102dba LG |
1482 | case '.':\r |
1483 | Flags |= PRECISION;\r | |
f405c067 | 1484 | break;\r |
d1102dba LG |
1485 | case '-':\r |
1486 | Flags |= LEFT_JUSTIFY;\r | |
f405c067 | 1487 | break;\r |
d1102dba LG |
1488 | case '+':\r |
1489 | Flags |= PREFIX_SIGN;\r | |
f405c067 | 1490 | break;\r |
d1102dba LG |
1491 | case ' ':\r |
1492 | Flags |= PREFIX_BLANK;\r | |
f405c067 | 1493 | break;\r |
d1102dba LG |
1494 | case ',':\r |
1495 | Flags |= COMMA_TYPE;\r | |
f405c067 | 1496 | break;\r |
1497 | case 'L':\r | |
d1102dba LG |
1498 | case 'l':\r |
1499 | Flags |= LONG_TYPE;\r | |
f405c067 | 1500 | break;\r |
1501 | case '*':\r | |
1502 | if ((Flags & PRECISION) == 0) {\r | |
1503 | Flags |= PAD_TO_WIDTH;\r | |
1504 | if (BaseListMarker == NULL) {\r | |
1505 | Width = VA_ARG (VaListMarker, UINTN);\r | |
1506 | } else {\r | |
1507 | Width = BASE_ARG (BaseListMarker, UINTN);\r | |
1508 | }\r | |
1509 | } else {\r | |
1510 | if (BaseListMarker == NULL) {\r | |
1511 | Precision = VA_ARG (VaListMarker, UINTN);\r | |
1512 | } else {\r | |
1513 | Precision = BASE_ARG (BaseListMarker, UINTN);\r | |
1514 | }\r | |
1515 | }\r | |
1516 | break;\r | |
1517 | case '0':\r | |
1518 | if ((Flags & PRECISION) == 0) {\r | |
1519 | Flags |= PREFIX_ZERO;\r | |
1520 | }\r | |
1521 | case '1':\r | |
1522 | case '2':\r | |
1523 | case '3':\r | |
1524 | case '4':\r | |
1525 | case '5':\r | |
1526 | case '6':\r | |
1527 | case '7':\r | |
1528 | case '8':\r | |
1529 | case '9':\r | |
1530 | for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){\r | |
1531 | Count = (Count * 10) + FormatCharacter - '0';\r | |
1532 | Format += BytesPerFormatCharacter;\r | |
213da0b5 | 1533 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 1534 | }\r |
1535 | Format -= BytesPerFormatCharacter;\r | |
1536 | if ((Flags & PRECISION) == 0) {\r | |
1537 | Flags |= PAD_TO_WIDTH;\r | |
1538 | Width = Count;\r | |
1539 | } else {\r | |
1540 | Precision = Count;\r | |
1541 | }\r | |
1542 | break;\r | |
d1102dba | 1543 | \r |
f405c067 | 1544 | case '\0':\r |
1545 | //\r | |
1546 | // Make no output if Format string terminates unexpectedly when\r | |
d1102dba | 1547 | // looking up for flag, width, precision and type.\r |
f405c067 | 1548 | //\r |
1549 | Format -= BytesPerFormatCharacter;\r | |
1550 | Precision = 0;\r | |
1551 | //\r | |
1552 | // break skipped on purpose.\r | |
1553 | //\r | |
1554 | default:\r | |
1555 | Done = TRUE;\r | |
1556 | break;\r | |
1557 | }\r | |
d1102dba | 1558 | }\r |
f405c067 | 1559 | \r |
1560 | //\r | |
1561 | // Handle each argument type\r | |
1562 | //\r | |
1563 | switch (FormatCharacter) {\r | |
1564 | case 'p':\r | |
1565 | //\r | |
1566 | // Flag space, +, 0, L & l are invalid for type p.\r | |
1567 | //\r | |
586d81d1 | 1568 | Flags &= ~((UINTN) (PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE));\r |
f405c067 | 1569 | if (sizeof (VOID *) > 4) {\r |
1570 | Flags |= LONG_TYPE;\r | |
1571 | }\r | |
586d81d1 LG |
1572 | //\r |
1573 | // break skipped on purpose\r | |
1574 | //\r | |
f405c067 | 1575 | case 'X':\r |
1576 | Flags |= PREFIX_ZERO;\r | |
1577 | //\r | |
1578 | // break skipped on purpose\r | |
1579 | //\r | |
1580 | case 'x':\r | |
1581 | Flags |= RADIX_HEX;\r | |
1582 | //\r | |
1583 | // break skipped on purpose\r | |
1584 | //\r | |
796fecd8 QS |
1585 | case 'u':\r |
1586 | if ((Flags & RADIX_HEX) == 0) {\r | |
1587 | Flags &= ~((UINTN) (PREFIX_SIGN));\r | |
1588 | Flags |= UNSIGNED_TYPE;\r | |
1589 | }\r | |
1590 | //\r | |
1591 | // break skipped on purpose\r | |
1592 | //\r | |
f405c067 | 1593 | case 'd':\r |
1594 | if ((Flags & LONG_TYPE) == 0) {\r | |
1595 | //\r | |
796fecd8 | 1596 | // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r |
f405c067 | 1597 | // This assumption is made so the format string definition is compatible with the ANSI C\r |
d1102dba LG |
1598 | // Specification for formatted strings. It is recommended that the Base Types be used\r |
1599 | // everywhere, but in this one case, compliance with ANSI C is more important, and\r | |
1600 | // provides an implementation that is compatible with that largest possible set of CPU\r | |
f405c067 | 1601 | // architectures. This is why the type "int" is used in this one case.\r |
1602 | //\r | |
1603 | if (BaseListMarker == NULL) {\r | |
1604 | Value = VA_ARG (VaListMarker, int);\r | |
1605 | } else {\r | |
1606 | Value = BASE_ARG (BaseListMarker, int);\r | |
1607 | }\r | |
1608 | } else {\r | |
1609 | if (BaseListMarker == NULL) {\r | |
1610 | Value = VA_ARG (VaListMarker, INT64);\r | |
1611 | } else {\r | |
1612 | Value = BASE_ARG (BaseListMarker, INT64);\r | |
1613 | }\r | |
1614 | }\r | |
1615 | if ((Flags & PREFIX_BLANK) != 0) {\r | |
1616 | Prefix = ' ';\r | |
1617 | }\r | |
1618 | if ((Flags & PREFIX_SIGN) != 0) {\r | |
1619 | Prefix = '+';\r | |
1620 | }\r | |
1621 | if ((Flags & COMMA_TYPE) != 0) {\r | |
1622 | Comma = TRUE;\r | |
1623 | }\r | |
1624 | if ((Flags & RADIX_HEX) == 0) {\r | |
1625 | Radix = 10;\r | |
1626 | if (Comma) {\r | |
586d81d1 | 1627 | Flags &= ~((UINTN) PREFIX_ZERO);\r |
f405c067 | 1628 | Precision = 1;\r |
1629 | }\r | |
796fecd8 | 1630 | if (Value < 0 && (Flags & UNSIGNED_TYPE) == 0) {\r |
f405c067 | 1631 | Flags |= PREFIX_SIGN;\r |
1632 | Prefix = '-';\r | |
1633 | Value = -Value;\r | |
796fecd8 QS |
1634 | } else if ((Flags & UNSIGNED_TYPE) != 0 && (Flags & LONG_TYPE) == 0) {\r |
1635 | //\r | |
1636 | // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r | |
1637 | // This assumption is made so the format string definition is compatible with the ANSI C\r | |
d1102dba LG |
1638 | // Specification for formatted strings. It is recommended that the Base Types be used\r |
1639 | // everywhere, but in this one case, compliance with ANSI C is more important, and\r | |
1640 | // provides an implementation that is compatible with that largest possible set of CPU\r | |
796fecd8 QS |
1641 | // architectures. This is why the type "unsigned int" is used in this one case.\r |
1642 | //\r | |
1643 | Value = (unsigned int)Value;\r | |
f405c067 | 1644 | }\r |
1645 | } else {\r | |
1646 | Radix = 16;\r | |
1647 | Comma = FALSE;\r | |
1648 | if ((Flags & LONG_TYPE) == 0 && Value < 0) {\r | |
1649 | //\r | |
796fecd8 | 1650 | // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r |
f405c067 | 1651 | // This assumption is made so the format string definition is compatible with the ANSI C\r |
d1102dba LG |
1652 | // Specification for formatted strings. It is recommended that the Base Types be used\r |
1653 | // everywhere, but in this one case, compliance with ANSI C is more important, and\r | |
1654 | // provides an implementation that is compatible with that largest possible set of CPU\r | |
f405c067 | 1655 | // architectures. This is why the type "unsigned int" is used in this one case.\r |
1656 | //\r | |
1657 | Value = (unsigned int)Value;\r | |
1658 | }\r | |
1659 | }\r | |
1660 | //\r | |
1661 | // Convert Value to a reversed string\r | |
1662 | //\r | |
1663 | Count = InternalPrintLibValueToString (ValueBuffer, Value, Radix) - ValueBuffer;\r | |
1664 | if (Value == 0 && Precision == 0) {\r | |
1665 | Count = 0;\r | |
1666 | }\r | |
1667 | ArgumentString = (CHAR8 *)ValueBuffer + Count;\r | |
d1102dba | 1668 | \r |
f405c067 | 1669 | Digits = Count % 3;\r |
1670 | if (Digits != 0) {\r | |
1671 | Digits = 3 - Digits;\r | |
1672 | }\r | |
1673 | if (Comma && Count != 0) {\r | |
1674 | Count += ((Count - 1) / 3);\r | |
1675 | }\r | |
1676 | if (Prefix != 0) {\r | |
1677 | Count++;\r | |
1678 | Precision++;\r | |
1679 | }\r | |
1680 | Flags |= ARGUMENT_REVERSED;\r | |
1681 | ZeroPad = TRUE;\r | |
1682 | if ((Flags & PREFIX_ZERO) != 0) {\r | |
1683 | if ((Flags & LEFT_JUSTIFY) == 0) {\r | |
1684 | if ((Flags & PAD_TO_WIDTH) != 0) {\r | |
1685 | if ((Flags & PRECISION) == 0) {\r | |
1686 | Precision = Width;\r | |
1687 | }\r | |
1688 | }\r | |
1689 | }\r | |
1690 | }\r | |
1691 | break;\r | |
1692 | \r | |
1693 | case 's':\r | |
1694 | case 'S':\r | |
1695 | Flags |= ARGUMENT_UNICODE;\r | |
1696 | //\r | |
1697 | // break skipped on purpose\r | |
1698 | //\r | |
1699 | case 'a':\r | |
1700 | if (BaseListMarker == NULL) {\r | |
1701 | ArgumentString = VA_ARG (VaListMarker, CHAR8 *);\r | |
1702 | } else {\r | |
1703 | ArgumentString = BASE_ARG (BaseListMarker, CHAR8 *);\r | |
1704 | }\r | |
1705 | if (ArgumentString == NULL) {\r | |
6e1e5405 | 1706 | Flags &= (~(UINTN)ARGUMENT_UNICODE);\r |
f405c067 | 1707 | ArgumentString = "<null string>";\r |
1708 | }\r | |
1709 | //\r | |
1710 | // Set the default precision for string to be zero if not specified.\r | |
1711 | //\r | |
1712 | if ((Flags & PRECISION) == 0) {\r | |
1713 | Precision = 0;\r | |
1714 | }\r | |
1715 | break;\r | |
1716 | \r | |
1717 | case 'c':\r | |
1718 | if (BaseListMarker == NULL) {\r | |
1719 | Character = VA_ARG (VaListMarker, UINTN) & 0xffff;\r | |
1720 | } else {\r | |
1721 | Character = BASE_ARG (BaseListMarker, UINTN) & 0xffff;\r | |
1722 | }\r | |
1723 | ArgumentString = (CHAR8 *)&Character;\r | |
1724 | Flags |= ARGUMENT_UNICODE;\r | |
1725 | break;\r | |
1726 | \r | |
1727 | case 'g':\r | |
1728 | if (BaseListMarker == NULL) {\r | |
1729 | TmpGuid = VA_ARG (VaListMarker, GUID *);\r | |
1730 | } else {\r | |
1731 | TmpGuid = BASE_ARG (BaseListMarker, GUID *);\r | |
1732 | }\r | |
1733 | if (TmpGuid == NULL) {\r | |
1734 | ArgumentString = "<null guid>";\r | |
1735 | } else {\r | |
1736 | GuidData1 = ReadUnaligned32 (&(TmpGuid->Data1));\r | |
1737 | GuidData2 = ReadUnaligned16 (&(TmpGuid->Data2));\r | |
1738 | GuidData3 = ReadUnaligned16 (&(TmpGuid->Data3));\r | |
1739 | InternalPrintLibSPrint (\r | |
1740 | ValueBuffer,\r | |
d1102dba | 1741 | MAXIMUM_VALUE_CHARACTERS,\r |
f405c067 | 1742 | 0,\r |
1743 | "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r | |
1744 | GuidData1,\r | |
1745 | GuidData2,\r | |
1746 | GuidData3,\r | |
1747 | TmpGuid->Data4[0],\r | |
1748 | TmpGuid->Data4[1],\r | |
1749 | TmpGuid->Data4[2],\r | |
1750 | TmpGuid->Data4[3],\r | |
1751 | TmpGuid->Data4[4],\r | |
1752 | TmpGuid->Data4[5],\r | |
1753 | TmpGuid->Data4[6],\r | |
1754 | TmpGuid->Data4[7]\r | |
1755 | );\r | |
1756 | ArgumentString = ValueBuffer;\r | |
1757 | }\r | |
1758 | break;\r | |
1759 | \r | |
1760 | case 't':\r | |
1761 | if (BaseListMarker == NULL) {\r | |
d1102dba | 1762 | TmpTime = VA_ARG (VaListMarker, TIME *);\r |
f405c067 | 1763 | } else {\r |
d1102dba | 1764 | TmpTime = BASE_ARG (BaseListMarker, TIME *);\r |
f405c067 | 1765 | }\r |
1766 | if (TmpTime == NULL) {\r | |
1767 | ArgumentString = "<null time>";\r | |
1768 | } else {\r | |
1769 | InternalPrintLibSPrint (\r | |
1770 | ValueBuffer,\r | |
1771 | MAXIMUM_VALUE_CHARACTERS,\r | |
1772 | 0,\r | |
1773 | "%02d/%02d/%04d %02d:%02d",\r | |
1774 | TmpTime->Month,\r | |
1775 | TmpTime->Day,\r | |
1776 | TmpTime->Year,\r | |
1777 | TmpTime->Hour,\r | |
1778 | TmpTime->Minute\r | |
1779 | );\r | |
1780 | ArgumentString = ValueBuffer;\r | |
1781 | }\r | |
1782 | break;\r | |
1783 | \r | |
1784 | case 'r':\r | |
1785 | if (BaseListMarker == NULL) {\r | |
1786 | Status = VA_ARG (VaListMarker, RETURN_STATUS);\r | |
1787 | } else {\r | |
1788 | Status = BASE_ARG (BaseListMarker, RETURN_STATUS);\r | |
1789 | }\r | |
1790 | ArgumentString = ValueBuffer;\r | |
1791 | if (RETURN_ERROR (Status)) {\r | |
1792 | //\r | |
1793 | // Clear error bit\r | |
1794 | //\r | |
1795 | Index = Status & ~MAX_BIT;\r | |
1796 | if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {\r | |
1797 | ArgumentString = mStatusString [Index + WARNING_STATUS_NUMBER];\r | |
1798 | }\r | |
1799 | } else {\r | |
1800 | Index = Status;\r | |
1801 | if (Index <= WARNING_STATUS_NUMBER) {\r | |
1802 | ArgumentString = mStatusString [Index];\r | |
1803 | }\r | |
1804 | }\r | |
1805 | if (ArgumentString == ValueBuffer) {\r | |
1806 | InternalPrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);\r | |
1807 | }\r | |
1808 | break;\r | |
1809 | \r | |
1810 | case '\r':\r | |
1811 | Format += BytesPerFormatCharacter;\r | |
213da0b5 | 1812 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 1813 | if (FormatCharacter == '\n') {\r |
1814 | //\r | |
1815 | // Translate '\r\n' to '\r\n'\r | |
1816 | //\r | |
1817 | ArgumentString = "\r\n";\r | |
1818 | } else {\r | |
1819 | //\r | |
1820 | // Translate '\r' to '\r'\r | |
1821 | //\r | |
1822 | ArgumentString = "\r";\r | |
1823 | Format -= BytesPerFormatCharacter;\r | |
1824 | }\r | |
1825 | break;\r | |
1826 | \r | |
1827 | case '\n':\r | |
1828 | //\r | |
1829 | // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r | |
1830 | //\r | |
1831 | ArgumentString = "\r\n";\r | |
1832 | Format += BytesPerFormatCharacter;\r | |
213da0b5 | 1833 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 1834 | if (FormatCharacter != '\r') {\r |
1835 | Format -= BytesPerFormatCharacter;\r | |
1836 | }\r | |
1837 | break;\r | |
1838 | \r | |
1839 | case '%':\r | |
1840 | default:\r | |
1841 | //\r | |
1842 | // if the type is '%' or unknown, then print it to the screen\r | |
1843 | //\r | |
1844 | ArgumentString = (CHAR8 *)&FormatCharacter;\r | |
1845 | Flags |= ARGUMENT_UNICODE;\r | |
1846 | break;\r | |
1847 | }\r | |
1848 | break;\r | |
d1102dba | 1849 | \r |
f405c067 | 1850 | case '\r':\r |
1851 | Format += BytesPerFormatCharacter;\r | |
213da0b5 | 1852 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 1853 | if (FormatCharacter == '\n') {\r |
1854 | //\r | |
1855 | // Translate '\r\n' to '\r\n'\r | |
1856 | //\r | |
1857 | ArgumentString = "\r\n";\r | |
1858 | } else {\r | |
1859 | //\r | |
1860 | // Translate '\r' to '\r'\r | |
1861 | //\r | |
1862 | ArgumentString = "\r";\r | |
1863 | Format -= BytesPerFormatCharacter;\r | |
1864 | }\r | |
1865 | break;\r | |
1866 | \r | |
1867 | case '\n':\r | |
1868 | //\r | |
1869 | // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r | |
1870 | //\r | |
1871 | ArgumentString = "\r\n";\r | |
1872 | Format += BytesPerFormatCharacter;\r | |
213da0b5 | 1873 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 1874 | if (FormatCharacter != '\r') {\r |
1875 | Format -= BytesPerFormatCharacter;\r | |
1876 | }\r | |
1877 | break;\r | |
1878 | \r | |
1879 | default:\r | |
1880 | ArgumentString = (CHAR8 *)&FormatCharacter;\r | |
1881 | Flags |= ARGUMENT_UNICODE;\r | |
1882 | break;\r | |
1883 | }\r | |
1884 | \r | |
1885 | //\r | |
1886 | // Retrieve the ArgumentString attriubutes\r | |
1887 | //\r | |
1888 | if ((Flags & ARGUMENT_UNICODE) != 0) {\r | |
1889 | ArgumentMask = 0xffff;\r | |
1890 | BytesPerArgumentCharacter = 2;\r | |
1891 | } else {\r | |
1892 | ArgumentMask = 0xff;\r | |
1893 | BytesPerArgumentCharacter = 1;\r | |
1894 | }\r | |
1895 | if ((Flags & ARGUMENT_REVERSED) != 0) {\r | |
1896 | BytesPerArgumentCharacter = -BytesPerArgumentCharacter;\r | |
1897 | } else {\r | |
1898 | //\r | |
1899 | // Compute the number of characters in ArgumentString and store it in Count\r | |
1900 | // ArgumentString is either null-terminated, or it contains Precision characters\r | |
1901 | //\r | |
941b3c48 | 1902 | for (Count = 0;\r |
b2327613 WJ |
1903 | (ArgumentString[Count * BytesPerArgumentCharacter] != '\0' ||\r |
1904 | (BytesPerArgumentCharacter > 1 &&\r | |
1905 | ArgumentString[Count * BytesPerArgumentCharacter + 1]!= '\0')) &&\r | |
f0e60d26 | 1906 | (Count < Precision || ((Flags & PRECISION) == 0));\r |
941b3c48 | 1907 | Count++) {\r |
f405c067 | 1908 | ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;\r |
1909 | if (ArgumentCharacter == 0) {\r | |
1910 | break;\r | |
1911 | }\r | |
1912 | }\r | |
1913 | }\r | |
1914 | \r | |
1915 | if (Precision < Count) {\r | |
1916 | Precision = Count;\r | |
1917 | }\r | |
1918 | \r | |
1919 | //\r | |
1920 | // Pad before the string\r | |
1921 | //\r | |
1922 | if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r | |
6bae492f | 1923 | LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r |
586d81d1 LG |
1924 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1925 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r | |
1926 | }\r | |
f405c067 | 1927 | }\r |
1928 | \r | |
1929 | if (ZeroPad) {\r | |
1930 | if (Prefix != 0) {\r | |
6bae492f | 1931 | LengthToReturn += (1 * BytesPerOutputCharacter);\r |
586d81d1 LG |
1932 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1933 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r | |
1934 | }\r | |
f405c067 | 1935 | }\r |
6bae492f | 1936 | LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r |
586d81d1 LG |
1937 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1938 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);\r | |
1939 | }\r | |
f405c067 | 1940 | } else {\r |
6bae492f | 1941 | LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r |
586d81d1 LG |
1942 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1943 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);\r | |
1944 | }\r | |
f405c067 | 1945 | if (Prefix != 0) {\r |
6bae492f | 1946 | LengthToReturn += (1 * BytesPerOutputCharacter);\r |
586d81d1 LG |
1947 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1948 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r | |
1949 | }\r | |
f405c067 | 1950 | }\r |
1951 | }\r | |
1952 | \r | |
1953 | //\r | |
1954 | // Output the Prefix character if it is present\r | |
1955 | //\r | |
1956 | Index = 0;\r | |
1957 | if (Prefix != 0) {\r | |
1958 | Index++;\r | |
1959 | }\r | |
1960 | \r | |
1961 | //\r | |
1962 | // Copy the string into the output buffer performing the required type conversions\r | |
1963 | //\r | |
b2327613 WJ |
1964 | while (Index < Count &&\r |
1965 | (ArgumentString[0] != '\0' ||\r | |
1966 | (BytesPerArgumentCharacter > 1 && ArgumentString[1] != '\0'))) {\r | |
1dfb0bf2 | 1967 | ArgumentCharacter = ((*ArgumentString & 0xff) | (((UINT8)*(ArgumentString + 1)) << 8)) & ArgumentMask;\r |
f405c067 | 1968 | \r |
6bae492f | 1969 | LengthToReturn += (1 * BytesPerOutputCharacter);\r |
586d81d1 LG |
1970 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1971 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r | |
1972 | }\r | |
f405c067 | 1973 | ArgumentString += BytesPerArgumentCharacter;\r |
1974 | Index++;\r | |
1975 | if (Comma) {\r | |
1976 | Digits++;\r | |
1977 | if (Digits == 3) {\r | |
1978 | Digits = 0;\r | |
1979 | Index++;\r | |
1980 | if (Index < Count) {\r | |
6bae492f | 1981 | LengthToReturn += (1 * BytesPerOutputCharacter);\r |
586d81d1 LG |
1982 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1983 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);\r | |
1984 | }\r | |
f405c067 | 1985 | }\r |
1986 | }\r | |
1987 | }\r | |
1988 | }\r | |
1989 | \r | |
1990 | //\r | |
1991 | // Pad after the string\r | |
1992 | //\r | |
1993 | if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r | |
6bae492f | 1994 | LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r |
586d81d1 LG |
1995 | if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r |
1996 | Buffer = InternalPrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r | |
1997 | }\r | |
f405c067 | 1998 | }\r |
1999 | \r | |
2000 | //\r | |
2001 | // Get the next character from the format string\r | |
2002 | //\r | |
2003 | Format += BytesPerFormatCharacter;\r | |
2004 | \r | |
2005 | //\r | |
2006 | // Get the next character from the format string\r | |
2007 | //\r | |
213da0b5 | 2008 | FormatCharacter = ((*Format & 0xff) | ((BytesPerFormatCharacter == 1) ? 0 : (*(Format + 1) << 8))) & FormatMask;\r |
f405c067 | 2009 | }\r |
2010 | \r | |
586d81d1 LG |
2011 | if ((Flags & COUNT_ONLY_NO_PRINT) != 0) {\r |
2012 | return (LengthToReturn / BytesPerOutputCharacter);\r | |
2013 | }\r | |
2014 | \r | |
2015 | ASSERT (Buffer != NULL);\r | |
2016 | //\r | |
2017 | // Null terminate the Unicode or ASCII string\r | |
2018 | //\r | |
2019 | InternalPrintLibFillBuffer (Buffer, EndBuffer + BytesPerOutputCharacter, 1, 0, BytesPerOutputCharacter);\r | |
586d81d1 LG |
2020 | \r |
2021 | return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);\r | |
f405c067 | 2022 | }\r |
2023 | \r | |
2024 | /**\r | |
d1102dba | 2025 | Returns the number of characters that would be produced by if the formatted\r |
f405c067 | 2026 | output were produced not including the Null-terminator.\r |
2027 | \r | |
f405c067 | 2028 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r |
2029 | \r | |
50418baa HW |
2030 | If FormatString is NULL, then ASSERT() and 0 is returned.\r |
2031 | If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more\r | |
2032 | than PcdMaximumUnicodeStringLength Unicode characters not including the\r | |
2033 | Null-terminator, then ASSERT() and 0 is returned.\r | |
2034 | \r | |
f405c067 | 2035 | @param[in] FormatString A Null-terminated Unicode format string.\r |
2036 | @param[in] Marker VA_LIST marker for the variable argument list.\r | |
2037 | \r | |
d1102dba | 2038 | @return The number of characters that would be produced, not including the\r |
f405c067 | 2039 | Null-terminator.\r |
2040 | **/\r | |
2041 | UINTN\r | |
2042 | EFIAPI\r | |
2043 | SPrintLength (\r | |
2044 | IN CONST CHAR16 *FormatString,\r | |
2045 | IN VA_LIST Marker\r | |
2046 | )\r | |
2047 | {\r | |
50418baa | 2048 | ASSERT_UNICODE_BUFFER (FormatString);\r |
f405c067 | 2049 | return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r |
2050 | }\r | |
2051 | \r | |
2052 | /**\r | |
d1102dba | 2053 | Returns the number of characters that would be produced by if the formatted\r |
f405c067 | 2054 | output were produced not including the Null-terminator.\r |
2055 | \r | |
50418baa HW |
2056 | If FormatString is NULL, then ASSERT() and 0 is returned.\r |
2057 | If PcdMaximumAsciiStringLength is not zero, and FormatString contains more\r | |
2058 | than PcdMaximumAsciiStringLength Ascii characters not including the\r | |
2059 | Null-terminator, then ASSERT() and 0 is returned.\r | |
f405c067 | 2060 | \r |
2061 | @param[in] FormatString A Null-terminated ASCII format string.\r | |
2062 | @param[in] Marker VA_LIST marker for the variable argument list.\r | |
2063 | \r | |
d1102dba | 2064 | @return The number of characters that would be produced, not including the\r |
f405c067 | 2065 | Null-terminator.\r |
2066 | **/\r | |
2067 | UINTN\r | |
2068 | EFIAPI\r | |
2069 | SPrintLengthAsciiFormat (\r | |
2070 | IN CONST CHAR8 *FormatString,\r | |
2071 | IN VA_LIST Marker\r | |
2072 | )\r | |
2073 | {\r | |
f405c067 | 2074 | return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r |
2075 | }\r |