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"
69 IN OUT VA_LIST
*Marker
76 IN OUT CHAR_W
*Buffer
,
84 IN OUT CHAR_W
*Buffer
,
100 IN CONST CHAR_W
*Format
,
107 SPrint function to process format and place the results in Buffer.
111 Buffer - Wide char buffer to print the results of the parsing of Format into.
113 BufferSize - Maximum number of characters to put into buffer. Zero means no
116 Format - Format string see file header for more details.
118 ... - Vararg list consumed by processing Format.
122 Number of characters printed.
129 VA_START (Marker
, Format
);
130 Return
= VSPrint (Buffer
, BufferSize
, Format
, Marker
);
140 OUT CHAR_W
*StartOfBuffer
,
142 IN CONST CHAR_W
*FormatString
,
149 VSPrint function to process format and place the results in Buffer. Since a
150 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
151 this is the main print working routine
155 StartOfBuffer - Unicode buffer to print the results of the parsing of Format into.
157 BufferSize - Maximum number of characters to put into buffer. Zero means
160 FormatString - Unicode format string see file header for more details.
162 Marker - Vararg list consumed by processing Format.
166 Number of characters printed.
170 CHAR16 TempBuffer
[CHARACTER_NUMBER_FOR_VALUE
];
179 UINTN NumberOfCharacters
;
185 // Process the format string. Stop if Buffer is over run.
188 Buffer
= StartOfBuffer
;
189 Format
= (CHAR_W
*)FormatString
;
190 NumberOfCharacters
= BufferSize
/sizeof(CHAR_W
);
191 BufferLeft
= BufferSize
;
192 for (Index
= 0; (*Format
!= '\0') && (Index
< NumberOfCharacters
- 1); Format
++) {
193 if (*Format
!= '%') {
194 if ((*Format
== '\n') && (Index
< NumberOfCharacters
- 2)) {
196 // If carage return add line feed
198 Buffer
[Index
++] = '\r';
199 BufferLeft
-= sizeof(CHAR_W
);
201 Buffer
[Index
++] = *Format
;
202 BufferLeft
-= sizeof(CHAR_W
);
206 // Now it's time to parse what follows after %
208 Format
= GetFlagsAndWidth (Format
, &Flags
, &Width
, &Marker
);
212 // Flag space, +, 0, L & l are invalid for type p.
214 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| LONG_TYPE
);
215 if (sizeof (VOID
*) > 4) {
217 Value
= VA_ARG (Marker
, UINT64
);
219 Value
= VA_ARG (Marker
, UINTN
);
221 Flags
|= PREFIX_ZERO
;
223 EfiValueToHexStr (TempBuffer
, Value
, Flags
, Width
);
224 UnicodeStr
= TempBuffer
;
226 for ( ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++) {
227 Buffer
[Index
++] = *UnicodeStr
;
232 Flags
|= PREFIX_ZERO
;
233 Width
= sizeof (UINT64
) * 2;
235 // break skiped on purpose
238 if ((Flags
& LONG_TYPE
) == LONG_TYPE
) {
239 Value
= VA_ARG (Marker
, UINT64
);
241 Value
= VA_ARG (Marker
, UINTN
);
244 EfiValueToHexStr (TempBuffer
, Value
, Flags
, Width
);
245 UnicodeStr
= TempBuffer
;
247 for ( ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++) {
248 Buffer
[Index
++] = *UnicodeStr
;
253 if ((Flags
& LONG_TYPE
) == LONG_TYPE
) {
254 Value
= VA_ARG (Marker
, UINT64
);
256 Value
= (UINTN
)VA_ARG (Marker
, UINTN
);
259 EfiValueToString (TempBuffer
, Value
, Flags
, Width
);
260 UnicodeStr
= TempBuffer
;
262 for ( ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++) {
263 Buffer
[Index
++] = *UnicodeStr
;
269 UnicodeStr
= (CHAR16
*)VA_ARG (Marker
, CHAR_W
*);
270 if (UnicodeStr
== NULL
) {
271 UnicodeStr
= L
"<null string>";
273 for (Count
= 0 ;(*UnicodeStr
!= '\0') && (Index
< NumberOfCharacters
- 1); UnicodeStr
++, Count
++) {
274 Buffer
[Index
++] = *UnicodeStr
;
277 // Add padding if needed
279 for (; (Count
< Width
) && (Index
< NumberOfCharacters
- 1); Count
++) {
280 Buffer
[Index
++] = ' ';
286 AsciiStr
= (CHAR8
*)VA_ARG (Marker
, CHAR8
*);
287 if (AsciiStr
== NULL
) {
288 AsciiStr
= (CHAR8
*) "<null string>";
290 for (Count
= 0 ;(*AsciiStr
!= '\0') && (Index
< NumberOfCharacters
- 1); AsciiStr
++, Count
++) {
291 Buffer
[Index
++] = (CHAR_W
)*AsciiStr
;
294 // Add padding if needed
296 for (;(Count
< Width
) && (Index
< NumberOfCharacters
- 1); Count
++) {
297 Buffer
[Index
++] = ' ';
302 Buffer
[Index
++] = (CHAR_W
)VA_ARG (Marker
, UINTN
);
306 TmpGUID
= VA_ARG (Marker
, EFI_GUID
*);
307 if (TmpGUID
!= NULL
) {
308 Index
+= GuidToString (
317 Index
+= TimeToString (
318 VA_ARG (Marker
, EFI_TIME
*),
325 Index
+= EfiStatusToString (
326 VA_ARG (Marker
, EFI_STATUS
),
333 Buffer
[Index
++] = *Format
;
338 // if the type is unknown print it to the screen
340 Buffer
[Index
++] = *Format
;
342 BufferLeft
= BufferSize
- Index
* sizeof(CHAR_W
) ;
345 Buffer
[Index
++] = '\0';
347 return &Buffer
[Index
] - StartOfBuffer
;
358 IN OUT VA_LIST
*Marker
364 VSPrint worker function that parses flag and width information from the
365 Format string and returns the next index into the Format string that needs
366 to be parsed. See file headed for details of Flag and Width.
370 Format - Current location in the VSPrint format string.
372 Flags - Returns flags
374 Width - Returns width of element
376 Marker - Vararg list that may be paritally consumed and returned.
380 Pointer indexed into the Format string for all the information parsed
390 for (Done
= FALSE
; !Done
; ) {
395 case '-': *Flags
|= LEFT_JUSTIFY
; break;
396 case '+': *Flags
|= PREFIX_SIGN
; break;
397 case ' ': *Flags
|= PREFIX_BLANK
; break;
398 case ',': *Flags
|= COMMA_TYPE
; break;
400 case 'l': *Flags
|= LONG_TYPE
; break;
403 *Width
= VA_ARG (*Marker
, UINTN
);
407 *Flags
|= PREFIX_ZERO
;
419 Count
= (Count
* 10) + *Format
- '0';
421 } while ((*Format
>= '0') && (*Format
<= '9'));
444 VSPrint worker function that prints an EFI_GUID.
448 Guid - Pointer to GUID to print.
450 Buffer - Buffe to print Guid into.
452 BufferSize - Size of Buffer.
456 Number of characters printed.
465 STRING_W ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"),
469 (UINTN
)Guid
->Data4
[0],
470 (UINTN
)Guid
->Data4
[1],
471 (UINTN
)Guid
->Data4
[2],
472 (UINTN
)Guid
->Data4
[3],
473 (UINTN
)Guid
->Data4
[4],
474 (UINTN
)Guid
->Data4
[5],
475 (UINTN
)Guid
->Data4
[6],
476 (UINTN
)Guid
->Data4
[7]
480 // SPrint will null terminate the string. The -1 skips the null
497 VSPrint worker function that prints EFI_TIME.
501 Time - Pointer to EFI_TIME sturcture to print.
503 Buffer - Buffer to print Time into.
505 BufferSize - Size of Buffer.
509 Number of characters printed.
518 STRING_W ("%02d/%02d/%04d %02d:%02d"),
527 // SPrint will null terminate the string. The -1 skips the null
535 IN EFI_STATUS Status
,
543 VSPrint worker function that prints EFI_STATUS as a string. If string is
544 not known a hex value will be printed.
548 Status - EFI_STATUS sturcture to print.
550 Buffer - Buffer to print EFI_STATUS message string into.
552 BufferSize - Size of Buffer.
556 Number of characters printed.
566 // Can't use global Status String Array as UINTN is not constant for EBC
568 if (Status
== EFI_SUCCESS
) { Desc
= (CHAR8
*) "Success"; } else
569 if (Status
== EFI_LOAD_ERROR
) { Desc
= (CHAR8
*) "Load Error"; } else
570 if (Status
== EFI_INVALID_PARAMETER
) { Desc
= (CHAR8
*) "Invalid Parameter"; } else
571 if (Status
== EFI_UNSUPPORTED
) { Desc
= (CHAR8
*) "Unsupported"; } else
572 if (Status
== EFI_BAD_BUFFER_SIZE
) { Desc
= (CHAR8
*) "Bad Buffer Size"; } else
573 if (Status
== EFI_BUFFER_TOO_SMALL
) { Desc
= (CHAR8
*) "Buffer Too Small"; } else
574 if (Status
== EFI_NOT_READY
) { Desc
= (CHAR8
*) "Not Ready"; } else
575 if (Status
== EFI_DEVICE_ERROR
) { Desc
= (CHAR8
*) "Device Error"; } else
576 if (Status
== EFI_WRITE_PROTECTED
) { Desc
= (CHAR8
*) "Write Protected"; } else
577 if (Status
== EFI_OUT_OF_RESOURCES
) { Desc
= (CHAR8
*) "Out of Resources"; } else
578 if (Status
== EFI_VOLUME_CORRUPTED
) { Desc
= (CHAR8
*) "Volume Corrupt"; } else
579 if (Status
== EFI_VOLUME_FULL
) { Desc
= (CHAR8
*) "Volume Full"; } else
580 if (Status
== EFI_NO_MEDIA
) { Desc
= (CHAR8
*) "No Media"; } else
581 if (Status
== EFI_MEDIA_CHANGED
) { Desc
= (CHAR8
*) "Media changed"; } else
582 if (Status
== EFI_NOT_FOUND
) { Desc
= (CHAR8
*) "Not Found"; } else
583 if (Status
== EFI_ACCESS_DENIED
) { Desc
= (CHAR8
*) "Access Denied"; } else
584 if (Status
== EFI_NO_RESPONSE
) { Desc
= (CHAR8
*) "No Response"; } else
585 if (Status
== EFI_NO_MAPPING
) { Desc
= (CHAR8
*) "No mapping"; } else
586 if (Status
== EFI_TIMEOUT
) { Desc
= (CHAR8
*) "Time out"; } else
587 if (Status
== EFI_NOT_STARTED
) { Desc
= (CHAR8
*) "Not started"; } else
588 if (Status
== EFI_ALREADY_STARTED
) { Desc
= (CHAR8
*) "Already started"; } else
589 if (Status
== EFI_ABORTED
) { Desc
= (CHAR8
*) "Aborted"; } else
590 if (Status
== EFI_ICMP_ERROR
) { Desc
= (CHAR8
*) "ICMP Error"; } else
591 if (Status
== EFI_TFTP_ERROR
) { Desc
= (CHAR8
*) "TFTP Error"; } else
592 if (Status
== EFI_PROTOCOL_ERROR
) { Desc
= (CHAR8
*) "Protocol Error"; } else
593 if (Status
== EFI_WARN_UNKNOWN_GLYPH
) { Desc
= (CHAR8
*) "Warning Unknown Glyph"; } else
594 if (Status
== EFI_WARN_DELETE_FAILURE
) { Desc
= (CHAR8
*) "Warning Delete Failure"; } else
595 if (Status
== EFI_WARN_WRITE_FAILURE
) { Desc
= (CHAR8
*) "Warning Write Failure"; } else
596 if (Status
== EFI_WARN_BUFFER_TOO_SMALL
) { Desc
= (CHAR8
*) "Warning Buffer Too Small"; }
599 // If we found a match, copy the message to the user's buffer. Otherwise
600 // sprint the hex status code to their buffer.
603 Size
= SPrint (Buffer
, BufferSize
, STRING_W ("%a"), Desc
);
605 Size
= SPrint (Buffer
, BufferSize
, STRING_W ("%X"), Status
);