3 Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
19 simple implemenation of SPrint() and Print() to support debug.
21 You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
22 time. This makes the implementation very simple.
24 VSPrint, Print, SPrint format specification has the follwoing form
32 ',' - Place commas in numberss
33 '0' - Prefix for width with zeros
38 '*' - Get width from a UINTN argumnet from the argument list
39 Decimal number that represents width of print
42 'p' - arugment is VOID *; printed as hex number
43 'X' - argument is a UINTN hex number, prefix '0'
44 'x' - argument is a hex number
45 'd' - argument is a decimal number
46 'a' - argument is an ascii string
47 'S','s' - argument is an Unicode string
48 'g' - argument is a pointer to an EFI_GUID
49 't' - argument is a pointer to an EFI_TIME structure
50 'c' - argument is an ascii character
51 'r' - argument is EFI_STATUS
56 #include "TianoCommon.h"
57 #include "EfiCommonLib.h"
58 #include "PrintWidth.h"
59 #include "EfiPrintLib.h"
67 IN OUT CHAR_W
*Buffer
,
75 IN OUT CHAR_W
*Buffer
,
91 IN CONST CHAR_W
*Format
,
98 SPrint function to process format and place the results in Buffer.
102 Buffer - Wide char buffer to print the results of the parsing of Format into.
104 BufferSize - Maximum number of characters to put into buffer. Zero means no
107 Format - Format string see file header for more details.
109 ... - Vararg list consumed by processing Format.
113 Number of characters printed.
120 VA_START (Marker
, Format
);
121 Return
= VSPrint (Buffer
, BufferSize
, Format
, Marker
);
131 OUT CHAR_W
*StartOfBuffer
,
133 IN CONST CHAR_W
*FormatString
,
140 VSPrint function to process format and place the results in Buffer. Since a
141 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
142 this is the main print working routine
146 StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
148 BufferSize - Maximum number of characters to put into buffer. Zero means
151 FormatString - Unicode format string see file header for more details.
153 Marker - Vararg list consumed by processing Format.
157 Number of characters printed.
161 CHAR16 TempBuffer
[CHARACTER_NUMBER_FOR_VALUE
];
170 UINTN NumberOfCharacters
;
177 // Process the format string. Stop if Buffer is over run.
180 Buffer
= StartOfBuffer
;
181 Format
= (CHAR_W
*)FormatString
;
182 NumberOfCharacters
= BufferSize
/sizeof(CHAR_W
);
183 BufferLeft
= BufferSize
;
184 for (Index
= 0; (*Format
!= '\0') && (Index
< NumberOfCharacters
- 1); Format
++) {
185 if (*Format
!= '%') {
186 if ((*Format
== '\n') && (Index
< NumberOfCharacters
- 2)) {
188 // If carage return add line feed
190 Buffer
[Index
++] = '\r';
191 BufferLeft
-= sizeof(CHAR_W
);
193 Buffer
[Index
++] = *Format
;
194 BufferLeft
-= sizeof(CHAR_W
);
198 // Now it's time to parse what follows after %
202 for (Done
= FALSE
; !Done
; ) {
207 case '-': Flags
|= LEFT_JUSTIFY
; break;
208 case '+': Flags
|= PREFIX_SIGN
; break;
209 case ' ': Flags
|= PREFIX_BLANK
; break;
210 case ',': Flags
|= COMMA_TYPE
; break;
212 case 'l': Flags
|= LONG_TYPE
; break;
215 Width
= VA_ARG (Marker
, UINTN
);
219 Flags
|= PREFIX_ZERO
;
231 Count
= (Count
* 10) + *Format
- '0';
233 } while ((*Format
>= '0') && (*Format
<= '9'));
246 // Flag space, +, 0, L & l are invalid for type p.
248 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| LONG_TYPE
);
249 if (sizeof (VOID
*) > 4) {
251 Value
= VA_ARG (Marker
, UINT64
);
253 Value
= VA_ARG (Marker
, UINTN
);
255 Flags
|= PREFIX_ZERO
;
257 EfiValueToHexStr (TempBuffer
, Value
, Flags
, Width
);
258 UnicodeStr
= TempBuffer
;
260 for ( ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++) {
261 Buffer
[Index
++] = *UnicodeStr
;
266 Flags
|= PREFIX_ZERO
;
267 Width
= sizeof (UINT64
) * 2;
269 // break skiped on purpose
272 if ((Flags
& LONG_TYPE
) == LONG_TYPE
) {
273 Value
= VA_ARG (Marker
, UINT64
);
275 Value
= VA_ARG (Marker
, UINTN
);
278 EfiValueToHexStr (TempBuffer
, Value
, Flags
, Width
);
279 UnicodeStr
= TempBuffer
;
281 for ( ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++) {
282 Buffer
[Index
++] = *UnicodeStr
;
287 if ((Flags
& LONG_TYPE
) == LONG_TYPE
) {
288 Value
= VA_ARG (Marker
, UINT64
);
290 Value
= (UINTN
)VA_ARG (Marker
, UINTN
);
293 EfiValueToString (TempBuffer
, Value
, Flags
, Width
);
294 UnicodeStr
= TempBuffer
;
296 for ( ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++) {
297 Buffer
[Index
++] = *UnicodeStr
;
303 UnicodeStr
= (CHAR16
*)VA_ARG (Marker
, CHAR_W
*);
304 if (UnicodeStr
== NULL
) {
305 UnicodeStr
= L
"<null string>";
307 for (Count
= 0 ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++, Count
++) {
308 Buffer
[Index
++] = *UnicodeStr
;
311 // Add padding if needed
313 for (; (Count
< Width
) && (Index
< NumberOfCharacters
- 1); Count
++) {
314 Buffer
[Index
++] = ' ';
320 AsciiStr
= (CHAR8
*)VA_ARG (Marker
, CHAR8
*);
321 if (AsciiStr
== NULL
) {
322 AsciiStr
= (CHAR8
*) "<null string>";
324 for (Count
= 0 ;(*AsciiStr
!= '\0') && (Index
< NumberOfCharacters
- 1); AsciiStr
++, Count
++) {
325 Buffer
[Index
++] = (CHAR_W
)*AsciiStr
;
328 // Add padding if needed
330 for (;(Count
< Width
) && (Index
< NumberOfCharacters
- 1); Count
++) {
331 Buffer
[Index
++] = ' ';
336 Buffer
[Index
++] = (CHAR_W
)VA_ARG (Marker
, UINTN
);
340 TmpGUID
= VA_ARG (Marker
, EFI_GUID
*);
341 if (TmpGUID
!= NULL
) {
342 Index
+= GuidToString (
351 Index
+= TimeToString (
352 VA_ARG (Marker
, EFI_TIME
*),
359 Index
+= EfiStatusToString (
360 VA_ARG (Marker
, EFI_STATUS
),
367 Buffer
[Index
++] = *Format
;
372 // if the type is unknown print it to the screen
374 Buffer
[Index
++] = *Format
;
376 BufferLeft
= BufferSize
- Index
* sizeof(CHAR_W
) ;
379 Buffer
[Index
++] = '\0';
381 return &Buffer
[Index
] - StartOfBuffer
;
395 VSPrint worker function that prints an EFI_GUID.
399 Guid - Pointer to GUID to print.
401 Buffer - Buffe to print Guid into.
403 BufferSize - Size of Buffer.
407 Number of characters printed.
416 STRING_W ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"),
420 (UINTN
)Guid
->Data4
[0],
421 (UINTN
)Guid
->Data4
[1],
422 (UINTN
)Guid
->Data4
[2],
423 (UINTN
)Guid
->Data4
[3],
424 (UINTN
)Guid
->Data4
[4],
425 (UINTN
)Guid
->Data4
[5],
426 (UINTN
)Guid
->Data4
[6],
427 (UINTN
)Guid
->Data4
[7]
431 // SPrint will null terminate the string. The -1 skips the null
448 VSPrint worker function that prints EFI_TIME.
452 Time - Pointer to EFI_TIME sturcture to print.
454 Buffer - Buffer to print Time into.
456 BufferSize - Size of Buffer.
460 Number of characters printed.
469 STRING_W ("%02d/%02d/%04d %02d:%02d"),
478 // SPrint will null terminate the string. The -1 skips the null
486 IN EFI_STATUS Status
,
494 VSPrint worker function that prints EFI_STATUS as a string. If string is
495 not known a hex value will be printed.
499 Status - EFI_STATUS sturcture to print.
501 Buffer - Buffer to print EFI_STATUS message string into.
503 BufferSize - Size of Buffer.
507 Number of characters printed.
517 // Can't use global Status String Array as UINTN is not constant for EBC
519 if (Status
== EFI_SUCCESS
) { Desc
= (CHAR8
*) "Success"; } else
520 if (Status
== EFI_LOAD_ERROR
) { Desc
= (CHAR8
*) "Load Error"; } else
521 if (Status
== EFI_INVALID_PARAMETER
) { Desc
= (CHAR8
*) "Invalid Parameter"; } else
522 if (Status
== EFI_UNSUPPORTED
) { Desc
= (CHAR8
*) "Unsupported"; } else
523 if (Status
== EFI_BAD_BUFFER_SIZE
) { Desc
= (CHAR8
*) "Bad Buffer Size"; } else
524 if (Status
== EFI_BUFFER_TOO_SMALL
) { Desc
= (CHAR8
*) "Buffer Too Small"; } else
525 if (Status
== EFI_NOT_READY
) { Desc
= (CHAR8
*) "Not Ready"; } else
526 if (Status
== EFI_DEVICE_ERROR
) { Desc
= (CHAR8
*) "Device Error"; } else
527 if (Status
== EFI_WRITE_PROTECTED
) { Desc
= (CHAR8
*) "Write Protected"; } else
528 if (Status
== EFI_OUT_OF_RESOURCES
) { Desc
= (CHAR8
*) "Out of Resources"; } else
529 if (Status
== EFI_VOLUME_CORRUPTED
) { Desc
= (CHAR8
*) "Volume Corrupt"; } else
530 if (Status
== EFI_VOLUME_FULL
) { Desc
= (CHAR8
*) "Volume Full"; } else
531 if (Status
== EFI_NO_MEDIA
) { Desc
= (CHAR8
*) "No Media"; } else
532 if (Status
== EFI_MEDIA_CHANGED
) { Desc
= (CHAR8
*) "Media changed"; } else
533 if (Status
== EFI_NOT_FOUND
) { Desc
= (CHAR8
*) "Not Found"; } else
534 if (Status
== EFI_ACCESS_DENIED
) { Desc
= (CHAR8
*) "Access Denied"; } else
535 if (Status
== EFI_NO_RESPONSE
) { Desc
= (CHAR8
*) "No Response"; } else
536 if (Status
== EFI_NO_MAPPING
) { Desc
= (CHAR8
*) "No mapping"; } else
537 if (Status
== EFI_TIMEOUT
) { Desc
= (CHAR8
*) "Time out"; } else
538 if (Status
== EFI_NOT_STARTED
) { Desc
= (CHAR8
*) "Not started"; } else
539 if (Status
== EFI_ALREADY_STARTED
) { Desc
= (CHAR8
*) "Already started"; } else
540 if (Status
== EFI_ABORTED
) { Desc
= (CHAR8
*) "Aborted"; } else
541 if (Status
== EFI_ICMP_ERROR
) { Desc
= (CHAR8
*) "ICMP Error"; } else
542 if (Status
== EFI_TFTP_ERROR
) { Desc
= (CHAR8
*) "TFTP Error"; } else
543 if (Status
== EFI_PROTOCOL_ERROR
) { Desc
= (CHAR8
*) "Protocol Error"; } else
544 if (Status
== EFI_WARN_UNKNOWN_GLYPH
) { Desc
= (CHAR8
*) "Warning Unknown Glyph"; } else
545 if (Status
== EFI_WARN_DELETE_FAILURE
) { Desc
= (CHAR8
*) "Warning Delete Failure"; } else
546 if (Status
== EFI_WARN_WRITE_FAILURE
) { Desc
= (CHAR8
*) "Warning Write Failure"; } else
547 if (Status
== EFI_WARN_BUFFER_TOO_SMALL
) { Desc
= (CHAR8
*) "Warning Buffer Too Small"; }
550 // If we found a match, copy the message to the user's buffer. Otherwise
551 // sprint the hex status code to their buffer.
554 Size
= SPrint (Buffer
, BufferSize
, STRING_W ("%a"), Desc
);
556 Size
= SPrint (Buffer
, BufferSize
, STRING_W ("%X"), Status
);