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