diff options
Diffstat (limited to 'EDK/Foundation/Library/Dxe/Print')
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Ascii/PrintAscii.cif | 9 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Ascii/PrintWidth.h | 88 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Ascii/Sprint.c | 144 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/BoxDraw.c | 212 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Print.c | 596 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Print.h | 37 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/PrintLib.cif | 19 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/PrintLib.inf | 50 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/PrintLib.mak | 70 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/PrintLib.sdl | 26 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/StdErr.c | 287 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Unicode/PrintUnicode.cif | 9 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Unicode/PrintWidth.h | 35 | ||||
-rw-r--r-- | EDK/Foundation/Library/Dxe/Print/Unicode/Sprint.c | 147 |
14 files changed, 1729 insertions, 0 deletions
diff --git a/EDK/Foundation/Library/Dxe/Print/Ascii/PrintAscii.cif b/EDK/Foundation/Library/Dxe/Print/Ascii/PrintAscii.cif new file mode 100644 index 0000000..3d79f4c --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Ascii/PrintAscii.cif @@ -0,0 +1,9 @@ +<component> + name = "PrintAscii" + category = ModulePart + LocalRoot = "EDK\Foundation\Library\Dxe\Print\Ascii" + RefName = "PrintAscii" +[files] +"PrintWidth.h" +"Sprint.c" +<endComponent> diff --git a/EDK/Foundation/Library/Dxe/Print/Ascii/PrintWidth.h b/EDK/Foundation/Library/Dxe/Print/Ascii/PrintWidth.h new file mode 100644 index 0000000..07901dc --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Ascii/PrintWidth.h @@ -0,0 +1,88 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + PrintWidth.h + +Abstract: + + Unicde option for generic width. + CHAR_W is Ascii + STRING_W is "" + +--*/ + +#ifndef _PRINT_WIDTH_H_ +#define _PRINT_WIDTH_H_ + +typedef CHAR8 CHAR_W; +#define STRING_W(_s) _s + +#define ASPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format) +#define AvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker) + +UINTN +UvSPrint ( + OUT CHAR16 *StartOfBuffer, + IN UINTN StrLen, + IN CONST CHAR16 *Format, + IN VA_LIST Marker + ) +/*++ + +Routine Description: + + Internal implementation of USPrint. + Process format and place the results in Buffer for wide chars. + +Arguments: + + StartOfBuffer - Wide char buffer to print the results of the parsing of Format into. + StrLen - Maximum number of characters to put into buffer. + Format - Format string + Marker - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +; + +UINTN +USPrint ( + OUT CHAR16 *Buffer, + IN UINTN BufferSize, + IN CONST CHAR16 *Format, + ... + ) +/*++ + +Routine Description: + + Process format and place the results in Buffer for wide chars. + +Arguments: + + Buffer - Wide char buffer to print the results of the parsing of Format into. + BufferSize - Maximum number of characters to put into buffer. + Format - Format string + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +; + +#endif diff --git a/EDK/Foundation/Library/Dxe/Print/Ascii/Sprint.c b/EDK/Foundation/Library/Dxe/Print/Ascii/Sprint.c new file mode 100644 index 0000000..bb4bb1e --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Ascii/Sprint.c @@ -0,0 +1,144 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + Sprint.c + +Abstract: + + Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very + simple implemenation of SPrint() and Print() to support debug. + + You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a + time. This makes the implementation very simple. + + VSPrint, Print, SPrint format specification has the follwoing form + + %[flags][width]type + + flags: + '-' - Left justify + '+' - Prefix a sign + ' ' - Prefix a blank + ',' - Place commas in numberss + '0' - Prefix for width with zeros + 'l' - UINT64 + 'L' - UINT64 + + width: + '*' - Get width from a UINTN argumnet from the argument list + Decimal number that represents width of print + + type: + 'X' - argument is a UINTN hex number, prefix '0' + 'x' - argument is a hex number + 'd' - argument is a decimal number + 'a' - argument is an ascii string + 'S','s' - argument is an Unicode string + 'g' - argument is a pointer to an EFI_GUID + 't' - argument is a pointer to an EFI_TIME structure + 'c' - argument is an ascii character + 'r' - argument is EFI_STATUS + '%' - Print a % + +--*/ + +#include "TianoCommon.h" +#include "PrintWidth.h" +#include "EfiPrintLib.h" +#include "Print.h" + + +UINTN +USPrint ( + OUT CHAR16 *Buffer, + IN UINTN BufferSize, + IN CONST CHAR16 *Format, + ... + ) +/*++ + +Routine Description: + + Process format and place the results in Buffer for wide chars. + +Arguments: + + Buffer - Wide char buffer to print the results of the parsing of Format into. + BufferSize - Maximum number of characters to put into buffer. + Format - Format string + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Return; + VA_LIST Marker; + + VA_START (Marker, Format); + Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker); + VA_END (Marker); + + return Return; +} + + +UINTN +UvSPrint ( + OUT CHAR16 *Buffer, + IN UINTN BufferSize, + IN CONST CHAR16 *FormatString, + IN VA_LIST Marker + ) +/*++ + +Routine Description: + + Internal implementation of USPrint. + Process format and place the results in Buffer for wide chars. + +Arguments: + + Buffer - Wide char buffer to print the results of the parsing of Format into. + BufferSize - Maximum number of characters to put into buffer. + FormatString - Format string + Marker - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Index; + CHAR8 AsciiFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; + CHAR8 AsciiResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; + + for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) { + AsciiFormat[Index] = (CHAR8) FormatString[Index]; + } + + AsciiFormat[Index] = '\0'; + + Index = VSPrint (AsciiResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, AsciiFormat, Marker); + + for (Index = 0; (Index < (BufferSize - 1)) && AsciiResult[Index] != '\0'; Index++) { + Buffer[Index] = (CHAR16) AsciiResult[Index]; + } + + Buffer[Index] = '\0'; + + return Index++; +} diff --git a/EDK/Foundation/Library/Dxe/Print/BoxDraw.c b/EDK/Foundation/Library/Dxe/Print/BoxDraw.c new file mode 100644 index 0000000..fdcd073 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/BoxDraw.c @@ -0,0 +1,212 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + BoxDraw.c + +Abstract: + Lib functions to support Box Draw Unicode code pages. + + + +Revision History + +--*/ + +#include "Tiano.h" +#include "EfiDriverLib.h" + + + +typedef struct { + CHAR16 Unicode; + CHAR8 PcAnsi; + CHAR8 Ascii; +} UNICODE_TO_CHAR; + + +// +// This list is used to define the valid extend chars. +// It also provides a mapping from Unicode to PCANSI or +// ASCII. The ASCII mapping we just made up. +// +// + +static UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = { + BOXDRAW_HORIZONTAL, 0xc4, L'-', + BOXDRAW_VERTICAL, 0xb3, L'|', + BOXDRAW_DOWN_RIGHT, 0xda, L'/', + BOXDRAW_DOWN_LEFT, 0xbf, L'\\', + BOXDRAW_UP_RIGHT, 0xc0, L'\\', + BOXDRAW_UP_LEFT, 0xd9, L'/', + BOXDRAW_VERTICAL_RIGHT, 0xc3, L'|', + BOXDRAW_VERTICAL_LEFT, 0xb4, L'|', + BOXDRAW_DOWN_HORIZONTAL, 0xc2, L'+', + BOXDRAW_UP_HORIZONTAL, 0xc1, L'+', + BOXDRAW_VERTICAL_HORIZONTAL, 0xc5, L'+', + BOXDRAW_DOUBLE_HORIZONTAL, 0xcd, L'-', + BOXDRAW_DOUBLE_VERTICAL, 0xba, L'|', + BOXDRAW_DOWN_RIGHT_DOUBLE, 0xd5, L'/', + BOXDRAW_DOWN_DOUBLE_RIGHT, 0xd6, L'/', + BOXDRAW_DOUBLE_DOWN_RIGHT, 0xc9, L'/', + BOXDRAW_DOWN_LEFT_DOUBLE, 0xb8, L'\\', + BOXDRAW_DOWN_DOUBLE_LEFT, 0xb7, L'\\', + BOXDRAW_DOUBLE_DOWN_LEFT, 0xbb, L'\\', + BOXDRAW_UP_RIGHT_DOUBLE, 0xd4, L'\\', + BOXDRAW_UP_DOUBLE_RIGHT, 0xd3, L'\\', + BOXDRAW_DOUBLE_UP_RIGHT, 0xc8, L'\\', + BOXDRAW_UP_LEFT_DOUBLE, 0xbe, L'/', + BOXDRAW_UP_DOUBLE_LEFT, 0xbd, L'/', + BOXDRAW_DOUBLE_UP_LEFT, 0xbc, L'/', + BOXDRAW_VERTICAL_RIGHT_DOUBLE, 0xc6, L'|', + BOXDRAW_VERTICAL_DOUBLE_RIGHT, 0xc7, L'|', + BOXDRAW_DOUBLE_VERTICAL_RIGHT, 0xcc, L'|', + BOXDRAW_VERTICAL_LEFT_DOUBLE, 0xb5, L'|', + BOXDRAW_VERTICAL_DOUBLE_LEFT, 0xb6, L'|', + BOXDRAW_DOUBLE_VERTICAL_LEFT, 0xb9, L'|', + BOXDRAW_DOWN_HORIZONTAL_DOUBLE, 0xd1, L'+', + BOXDRAW_DOWN_DOUBLE_HORIZONTAL, 0xd2, L'+', + BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+', + BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+', + BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+', + BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+', + BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+', + BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+', + BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+', + + BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*', + BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+', + + GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^', + GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>', + GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v', + GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<', + + ARROW_LEFT, 0x3c, L'<', + + ARROW_UP, 0x18, L'^', + + ARROW_RIGHT, 0x3e, L'>', + + ARROW_DOWN, 0x19, L'v', + + 0x0000, 0x00 +}; + + +BOOLEAN +LibIsValidTextGraphics ( + IN CHAR16 Graphic, + OUT CHAR8 *PcAnsi, OPTIONAL + OUT CHAR8 *Ascii OPTIONAL + ) +/*++ + +Routine Description: + + Detects if a Unicode char is for Box Drawing text graphics. + +Arguments: + + Grphic - Unicode char to test. + + PcAnsi - Optional pointer to return PCANSI equivalent of Graphic. + + Asci - Optional pointer to return Ascii equivalent of Graphic. + +Returns: + + TRUE if Gpaphic is a supported Unicode Box Drawing character. + +--*/ +{ + UNICODE_TO_CHAR *Table; + + if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) { + + // + // Unicode drawing code charts are all in the 0x25xx range, + // arrows are 0x21xx + // + return FALSE; + } + + for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) { + if (Graphic == Table->Unicode) { + if (PcAnsi != NULL) { + *PcAnsi = Table->PcAnsi; + } + if (Ascii != NULL) { + *Ascii = Table->Ascii; + } + return TRUE; + } + } + return FALSE; +} + + +BOOLEAN +IsValidAscii ( + IN CHAR16 Ascii + ) +/*++ + +Routine Description: + + Is it valid ascii char? + +Arguments: + + Ascii - The char to check + +Returns: + + TRUE - Is a ascii char + FALSE - Not a ascii char + +--*/ +{ + if ((Ascii >= 0x20) && (Ascii <= 0x7f)) { + return TRUE; + } + return FALSE; +} + + +BOOLEAN +IsValidEfiCntlChar ( + IN CHAR16 CharC + ) +/*++ + +Routine Description: + + Is it valid EFI control char? + +Arguments: + + Ascii - The char to check + +Returns: + + TRUE - Is a valid EFI control char + FALSE - Not a valid EFI control char + +--*/ +{ + if (CharC == CHAR_NULL || CharC == CHAR_BACKSPACE || CharC == CHAR_LINEFEED || CharC == CHAR_CARRIAGE_RETURN) { + return TRUE; + } + return FALSE; +} + diff --git a/EDK/Foundation/Library/Dxe/Print/Print.c b/EDK/Foundation/Library/Dxe/Print/Print.c new file mode 100644 index 0000000..d939be5 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Print.c @@ -0,0 +1,596 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + Print.c + +Abstract: + + Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very + simple implemenation of SPrint() and Print() to support debug. + + You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a + time. This makes the implementation very simple. + + VSPrint, Print, SPrint format specification has the follwoing form + + %[flags][width]type + + flags: + '-' - Left justify + '+' - Prefix a sign + ' ' - Prefix a blank + ',' - Place commas in numberss + '0' - Prefix for width with zeros + 'l' - UINT64 + 'L' - UINT64 + + width: + '*' - Get width from a UINTN argumnet from the argument list + Decimal number that represents width of print + + type: + 'X' - argument is a UINTN hex number, prefix '0' + 'x' - argument is a hex number + 'd' - argument is a decimal number + 'a' - argument is an ascii string + 'S','s' - argument is an Unicode string + 'g' - argument is a pointer to an EFI_GUID + 't' - argument is a pointer to an EFI_TIME structure + 'c' - argument is an ascii character + 'r' - argument is EFI_STATUS + '%' - Print a % + +--*/ + +#include "TianoCommon.h" +#include "EfiCommonLib.h" +#include "PrintWidth.h" +#include "EfiPrintLib.h" +#include "Print.h" + + +STATIC +CHAR_W * +GetFlagsAndWidth ( + IN CHAR_W *Format, + OUT UINTN *Flags, + OUT UINTN *Width, + IN OUT VA_LIST *Marker + ); + +STATIC +UINTN +GuidToString ( + IN EFI_GUID *Guid, + IN OUT CHAR_W *Buffer, + IN UINTN BufferSize + ); + +STATIC +UINTN +TimeToString ( + IN EFI_TIME *Time, + IN OUT CHAR_W *Buffer, + IN UINTN BufferSize + ); + +STATIC +UINTN +EfiStatusToString ( + IN EFI_STATUS Status, + OUT CHAR_W *Buffer, + IN UINTN BufferSize + ); + +STATIC +UINTN +Atoi ( + CHAR_W *String + ); + + + +UINTN +SPrint ( + OUT CHAR_W *Buffer, + IN UINTN BufferSize, + IN CONST CHAR_W *Format, + ... + ) +/*++ + +Routine Description: + + SPrint function to process format and place the results in Buffer. + +Arguments: + + Buffer - Wide char buffer to print the results of the parsing of Format into. + + BufferSize - Maximum number of characters to put into buffer. Zero means no + limit. + + Format - Format string see file header for more details. + + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Return; + VA_LIST Marker; + + VA_START (Marker, Format); + Return = VSPrint (Buffer, BufferSize, Format, Marker); + VA_END (Marker); + + return Return; +} + + +UINTN +VSPrint ( + OUT CHAR_W *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR_W *FormatString, + IN VA_LIST Marker + ) +/*++ + +Routine Description: + + VSPrint function to process format and place the results in Buffer. Since a + VA_LIST is used this rountine allows the nesting of Vararg routines. Thus + this is the main print working routine + +Arguments: + + StartOfBuffer - Unicode buffer to print the results of the parsing of Format into. + + BufferSize - Maximum number of characters to put into buffer. Zero means + no limit. + + FormatString - Unicode format string see file header for more details. + + Marker - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + CHAR16 TempBuffer[CHARACTER_NUMBER_FOR_VALUE]; + CHAR_W *Buffer; + CHAR8 *AsciiStr; + CHAR16 *UnicodeStr; + CHAR_W *Format; + UINTN Index; + UINTN Flags; + UINTN Width; + UINTN Count; + UINTN NumberOfCharacters; + UINTN BufferLeft; + UINT64 Value; + EFI_GUID *TmpGUID; + + // + // Process the format string. Stop if Buffer is over run. + // + + Buffer = StartOfBuffer; + Format = (CHAR_W *)FormatString; + NumberOfCharacters = BufferSize/sizeof(CHAR_W); + BufferLeft = BufferSize; + for (Index = 0; (*Format != '\0') && (Index < NumberOfCharacters - 1); Format++) { + if (*Format != '%') { + if ((*Format == '\n') && (Index < NumberOfCharacters - 2)) { + // + // If carage return add line feed + // + Buffer[Index++] = '\r'; + BufferLeft -= sizeof(CHAR_W); + } + Buffer[Index++] = *Format; + BufferLeft -= sizeof(CHAR_W); + } else { + + // + // Now it's time to parse what follows after % + // + Format = GetFlagsAndWidth (Format, &Flags, &Width, &Marker); + switch (*Format) { + case 'X': + Flags |= PREFIX_ZERO; + Width = sizeof (UINT64) * 2; + // + // break skiped on purpose + // + case 'x': + if ((Flags & LONG_TYPE) == LONG_TYPE) { + Value = VA_ARG (Marker, UINT64); + } else { + Value = VA_ARG (Marker, UINTN); + Value &= 0xFFFFFFFF; + } + + EfiValueToHexStr (TempBuffer, Value, Flags, Width); + UnicodeStr = TempBuffer; + + for ( ;(*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) { + Buffer[Index++] = *UnicodeStr; + } + break; + + case 'd': + if ((Flags & LONG_TYPE) == LONG_TYPE) { + Value = VA_ARG (Marker, UINT64); + } else { + Value = (UINTN)VA_ARG (Marker, UINTN); + Value &= 0xFFFFFFFF; + Value = (INT32)Value; + } + + EfiValueToString (TempBuffer, Value, Flags, Width); + UnicodeStr = TempBuffer; + + for ( ;(*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++) { + Buffer[Index++] = *UnicodeStr; + } + break; + + case 's': + case 'S': + UnicodeStr = (CHAR16 *)VA_ARG (Marker, CHAR_W *); + if (UnicodeStr == NULL) { + UnicodeStr = L"<null string>"; + } + for (Count = 0 ;(*UnicodeStr != '\0') && (Index < NumberOfCharacters - 1); UnicodeStr++, Count++) { + Buffer[Index++] = *UnicodeStr; + } + // + // Add padding if needed + // + for (; (Count < Width) && (Index < NumberOfCharacters - 1); Count++) { + Buffer[Index++] = ' '; + } + + break; + + case 'a': + AsciiStr = (CHAR8 *)VA_ARG (Marker, CHAR8 *); + if (AsciiStr == NULL) { + AsciiStr = "<null string>"; + } + for (Count = 0 ;(*AsciiStr != '\0') && (Index < NumberOfCharacters - 1); AsciiStr++, Count++) { + Buffer[Index++] = (CHAR_W)*AsciiStr; + } + // + // Add padding if needed + // + for (;(Count < Width) && (Index < NumberOfCharacters - 1); Count++) { + Buffer[Index++] = ' '; + } + break; + + case 'c': + Buffer[Index++] = (CHAR_W)VA_ARG (Marker, UINTN); + break; + + case 'g': + TmpGUID = VA_ARG (Marker, EFI_GUID *); + if (TmpGUID != NULL) { + Index += GuidToString ( + TmpGUID, + &Buffer[Index], + BufferLeft + ); + } + break; + + case 't': + Index += TimeToString ( + VA_ARG (Marker, EFI_TIME *), + &Buffer[Index], + BufferLeft + ); + break; + + case 'r': + Index += EfiStatusToString ( + VA_ARG (Marker, EFI_STATUS), + &Buffer[Index], + BufferLeft + ); + break; + + case '%': + Buffer[Index++] = *Format; + break; + + default: + // + // if the type is unknown print it to the screen + // + Buffer[Index++] = *Format; + } + BufferLeft = BufferSize - Index * sizeof(CHAR_W) ; + } + } + Buffer[Index++] = '\0'; + + return &Buffer[Index] - StartOfBuffer; +} + + + +STATIC +CHAR_W * +GetFlagsAndWidth ( + IN CHAR_W *Format, + OUT UINTN *Flags, + OUT UINTN *Width, + IN OUT VA_LIST *Marker + ) +/*++ + +Routine Description: + + VSPrint worker function that parses flag and width information from the + Format string and returns the next index into the Format string that needs + to be parsed. See file headed for details of Flag and Width. + +Arguments: + + Format - Current location in the VSPrint format string. + + Flags - Returns flags + + Width - Returns width of element + + Marker - Vararg list that may be paritally consumed and returned. + +Returns: + + Pointer indexed into the Format string for all the information parsed + by this routine. + +--*/ +{ + UINTN Count; + BOOLEAN Done; + + *Flags = 0; + *Width = 0; + for (Done = FALSE; !Done; ) { + Format++; + + switch (*Format) { + + case '-': *Flags |= LEFT_JUSTIFY; break; + case '+': *Flags |= PREFIX_SIGN; break; + case ' ': *Flags |= PREFIX_BLANK; break; + case ',': *Flags |= COMMA_TYPE; break; + case 'L': + case 'l': *Flags |= LONG_TYPE; break; + + case '*': + *Width = VA_ARG (*Marker, UINTN); + break; + + case '0': + *Flags |= PREFIX_ZERO; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + Count = 0; + do { + Count = (Count * 10) + *Format - '0'; + Format++; + } while ((*Format >= '0') && (*Format <= '9')); + Format--; + *Width = Count; + break; + + default: + Done = TRUE; + } + } + return Format; +} + +STATIC +UINTN +GuidToString ( + IN EFI_GUID *Guid, + IN CHAR_W *Buffer, + IN UINTN BufferSize + ) +/*++ + +Routine Description: + + VSPrint worker function that prints an EFI_GUID. + +Arguments: + + Guid - Pointer to GUID to print. + + Buffer - Buffe to print Guid into. + + BufferSize - Size of Buffer. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Size; + + Size = SPrint ( + Buffer, + BufferSize, + STRING_W ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"), + (UINTN)Guid->Data1, + (UINTN)Guid->Data2, + (UINTN)Guid->Data3, + (UINTN)Guid->Data4[0], + (UINTN)Guid->Data4[1], + (UINTN)Guid->Data4[2], + (UINTN)Guid->Data4[3], + (UINTN)Guid->Data4[4], + (UINTN)Guid->Data4[5], + (UINTN)Guid->Data4[6], + (UINTN)Guid->Data4[7] + ); + + // + // SPrint will null terminate the string. The -1 skips the null + // + return Size - 1; +} + + +STATIC +UINTN +TimeToString ( + IN EFI_TIME *Time, + OUT CHAR_W *Buffer, + IN UINTN BufferSize + ) +/*++ + +Routine Description: + + VSPrint worker function that prints EFI_TIME. + +Arguments: + + Time - Pointer to EFI_TIME sturcture to print. + + Buffer - Buffer to print Time into. + + BufferSize - Size of Buffer. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Size; + + Size = SPrint ( + Buffer, + BufferSize, + STRING_W ("%02d/%02d/%04d %02d:%02d"), + (UINTN)Time->Month, + (UINTN)Time->Day, + (UINTN)Time->Year, + (UINTN)Time->Hour, + (UINTN)Time->Minute + ); + + // + // SPrint will null terminate the string. The -1 skips the null + // + return Size - 1; +} + +STATIC +UINTN +EfiStatusToString ( + IN EFI_STATUS Status, + OUT CHAR_W *Buffer, + IN UINTN BufferSize + ) +/*++ + +Routine Description: + + VSPrint worker function that prints EFI_STATUS as a string. If string is + not known a hex value will be printed. + +Arguments: + + Status - EFI_STATUS sturcture to print. + + Buffer - Buffer to print EFI_STATUS message string into. + + BufferSize - Size of Buffer. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Size; + CHAR8 *Desc; + + Desc = NULL; + + // + // Can't use global Status String Array as UINTN is not constant for EBC + // + if (Status == EFI_SUCCESS) { Desc = "Success"; } else + if (Status == EFI_LOAD_ERROR) { Desc = "Load Error"; } else + if (Status == EFI_INVALID_PARAMETER) { Desc = "Invalid Parameter"; } else + if (Status == EFI_UNSUPPORTED) { Desc = "Unsupported"; } else + if (Status == EFI_BAD_BUFFER_SIZE) { Desc = "Bad Buffer Size"; } else + if (Status == EFI_BUFFER_TOO_SMALL) { Desc = "Buffer Too Small"; } else + if (Status == EFI_NOT_READY) { Desc = "Not Ready"; } else + if (Status == EFI_DEVICE_ERROR) { Desc = "Device Error"; } else + if (Status == EFI_WRITE_PROTECTED) { Desc = "Write Protected"; } else + if (Status == EFI_OUT_OF_RESOURCES) { Desc = "Out of Resources"; } else + if (Status == EFI_VOLUME_CORRUPTED) { Desc = "Volume Corrupt"; } else + if (Status == EFI_VOLUME_FULL) { Desc = "Volume Full"; } else + if (Status == EFI_NO_MEDIA) { Desc = "No Media"; } else + if (Status == EFI_MEDIA_CHANGED) { Desc = "Media changed"; } else + if (Status == EFI_NOT_FOUND) { Desc = "Not Found"; } else + if (Status == EFI_ACCESS_DENIED) { Desc = "Access Denied"; } else + if (Status == EFI_NO_RESPONSE) { Desc = "No Response"; } else + if (Status == EFI_NO_MAPPING) { Desc = "No mapping"; } else + if (Status == EFI_TIMEOUT) { Desc = "Time out"; } else + if (Status == EFI_NOT_STARTED) { Desc = "Not started"; } else + if (Status == EFI_ALREADY_STARTED) { Desc = "Already started"; } else + if (Status == EFI_ABORTED) { Desc = "Aborted"; } else + if (Status == EFI_ICMP_ERROR) { Desc = "ICMP Error"; } else + if (Status == EFI_TFTP_ERROR) { Desc = "TFTP Error"; } else + if (Status == EFI_PROTOCOL_ERROR) { Desc = "Protocol Error"; } else + if (Status == EFI_WARN_UNKNOWN_GLYPH) { Desc = "Warning Unknown Glyph"; } else + if (Status == EFI_WARN_DELETE_FAILURE) { Desc = "Warning Delete Failure"; } else + if (Status == EFI_WARN_WRITE_FAILURE) { Desc = "Warning Write Failure"; } else + if (Status == EFI_WARN_BUFFER_TOO_SMALL) { Desc = "Warning Buffer Too Small"; } + + // + // If we found a match, copy the message to the user's buffer. Otherwise + // sprint the hex status code to their buffer. + // + if (Desc != NULL) { + Size = SPrint (Buffer, BufferSize, STRING_W ("%a"), Desc); + } else { + Size = SPrint (Buffer, BufferSize, STRING_W ("%X"), Status); + } + return Size - 1; +} diff --git a/EDK/Foundation/Library/Dxe/Print/Print.h b/EDK/Foundation/Library/Dxe/Print/Print.h new file mode 100644 index 0000000..ad54aa8 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Print.h @@ -0,0 +1,37 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + Print.h + +Abstract: + + Private data for Print.c + +--*/ + +#ifndef _PRINT_H_ +#define _PRINT_H_ + +#define LEFT_JUSTIFY 0x01 +#define PREFIX_SIGN 0x02 +#define PREFIX_BLANK 0x04 +#define COMMA_TYPE 0x08 +#define LONG_TYPE 0x10 +#define PREFIX_ZERO 0x20 + +// +// Largest number of characters that can be printed out. +// +#define EFI_DRIVER_LIB_MAX_PRINT_BUFFER (80 * 4) + +#endif diff --git a/EDK/Foundation/Library/Dxe/Print/PrintLib.cif b/EDK/Foundation/Library/Dxe/Print/PrintLib.cif new file mode 100644 index 0000000..4692aae --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/PrintLib.cif @@ -0,0 +1,19 @@ +<component> + name = "PrintLib" + category = ModulePart + LocalRoot = "EDK\Foundation\Library\Dxe\Print\" + RefName = "PrintLib" +[files] +"PrintLib.sdl" +"PrintLib.mak" +"BoxDraw.c" +"Print.c" +"Print.h" +"StdErr.c" +"PrintLib.inf" +[parts] +"PrintAscii" +"PrintUnicode" +"PrintAscii" +"PrintUnicode" +<endComponent> diff --git a/EDK/Foundation/Library/Dxe/Print/PrintLib.inf b/EDK/Foundation/Library/Dxe/Print/PrintLib.inf new file mode 100644 index 0000000..b06e272 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/PrintLib.inf @@ -0,0 +1,50 @@ +#/*++ +# +# Copyright (c) 2004, Intel Corporation +# All rights reserved. This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# Module Name: +# +# PrintLib.inf +# +# Abstract: +# +# Component description file. +# +#--*/ + +[defines] +BASE_NAME = PrintLib +COMPONENT_TYPE = LIBRARY + +[sources.common] + BoxDraw.c + Print.c + Print.h + StdErr.c + Unicode\PrintWidth.h + Unicode\SPrint.c + +[includes.common] + $(EDK_SOURCE)\Foundation + $(EDK_SOURCE)\Foundation\Framework + $(EDK_SOURCE)\Foundation\Efi + . + $(EDK_SOURCE)\Foundation\Include + $(EDK_SOURCE)\Foundation\Efi\Include + $(EDK_SOURCE)\Foundation\Framework\Include + $(EDK_SOURCE)\Foundation\Include\IndustryStandard + $(EDK_SOURCE)\Foundation\Library\Dxe\Include + $(EDK_SOURCE)\Foundation\Library\Dxe\Print\Unicode + $(EDK_SOURCE)\Foundation\Core\Dxe + +[libraries.common] + +[nmake.common] + C_STD_INCLUDE= diff --git a/EDK/Foundation/Library/Dxe/Print/PrintLib.mak b/EDK/Foundation/Library/Dxe/Print/PrintLib.mak new file mode 100644 index 0000000..dc019ce --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/PrintLib.mak @@ -0,0 +1,70 @@ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2009, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** + +#********************************************************************** +# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/IntelEDK/PrintLib/PrintLib.mak 1 1/20/12 4:08a Jeffch $ +# +# $Revision: 1 $ +# +# $Date: 1/20/12 4:08a $ +#********************************************************************** +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/IntelEDK/PrintLib/PrintLib.mak $ +# +# 1 1/20/12 4:08a Jeffch +# Create Intel EDK 1117 Patch 7. +# +# 1 9/27/11 6:31a Wesleychen +# Intel EDK initially releases. +# +# 2 9/02/09 3:52a Iminglin +# EIP24919 +# +#********************************************************************** +#<AMI_FHDR_START> +# +# Name: PrintLib.mak +# +# Description: +# +#<AMI_FHDR_END> +#********************************************************************** +$(PRINTLIB) : PrintLib + +$(BUILD_DIR)\PrintLib.lib : PrintLib + +PrintLib : $(BUILD_DIR)\PrintLib.mak PrintLibBin + +$(BUILD_DIR)\PrintLib.mak : $(PrintLib_DIR)\$(@B).cif $(PrintLib_DIR)\$(@B).mak $(BUILD_RULES) $(PrintLib_DIR)\Unicode\PrintUnicode.cif + $(CIF2MAK) $(PrintLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) $(PrintLib_DIR)\Unicode\PrintUnicode.cif + +PrintLibBin : + $(MAKE) /$(MAKEFLAGS) $(EDK_DEFAULTS)\ + /f $(BUILD_DIR)\PrintLib.mak all\ + "MY_INCLUDES=/I$(PrintLib_DIR) /I$(PrintLib_DIR)\Unicode"\ + TYPE=LIBRARY \ +#********************************************************************** +#********************************************************************** +#** ** +#** (C)Copyright 1985-2009, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#********************************************************************** +#********************************************************************** diff --git a/EDK/Foundation/Library/Dxe/Print/PrintLib.sdl b/EDK/Foundation/Library/Dxe/Print/PrintLib.sdl new file mode 100644 index 0000000..6920785 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/PrintLib.sdl @@ -0,0 +1,26 @@ +TOKEN + Name = "PrintLib_SUPPORT" + Value = "1" + Help = "Main switch to enable PrintLib support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +TOKEN + Name = "PRINTLIB" + Value = "$(BUILD_DIR)\PrintLib.lib" + TokenType = Expression + TargetMAK = Yes +End + +PATH + Name = "PrintLib_DIR" +End + +MODULE + Help = "Includes PrintLib.mak to Project" + File = "PrintLib.mak" +End + diff --git a/EDK/Foundation/Library/Dxe/Print/StdErr.c b/EDK/Foundation/Library/Dxe/Print/StdErr.c new file mode 100644 index 0000000..14d6ba9 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/StdErr.c @@ -0,0 +1,287 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + StdErr.c + +Abstract: + + Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very + simple implemenation of SPrint() and Print() to support debug. + + You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a + time. This makes the implementation very simple. + + VSPrint, Print, SPrint format specification has the follwoing form + + %[flags][width]type + + flags: + '-' - Left justify + '+' - Prefix a sign + ' ' - Prefix a blank + ',' - Place commas in numberss + '0' - Prefix for width with zeros + 'l' - UINT64 + 'L' - UINT64 + + width: + '*' - Get width from a UINTN argumnet from the argument list + Decimal number that represents width of print + + type: + 'X' - argument is a UINTN hex number, prefix '0' + 'x' - argument is a hex number + 'd' - argument is a decimal number + 'a' - argument is an ascii string + 'S','s' - argument is an Unicode string + 'g' - argument is a pointer to an EFI_GUID + 't' - argument is a pointer to an EFI_TIME structure + 'c' - argument is an ascii character + 'r' - argument is EFI_STATUS + '%' - Print a % + +--*/ + +#include "Tiano.h" +#include "EfiDriverLib.h" +#include "EfiCommonLib.h" +#include "EfiPrintLib.h" +#include "Print.h" + + +UINTN +ErrorPrint ( + IN CONST CHAR16 *ErrorString, + IN CONST CHAR8 *Format, + ... + ) +/*++ + +Routine Description: + + Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii + characters. + +Arguments: + + ErrorString - String of error infomation. + + Format - Ascii format string see file header for more details. + + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Return; + VA_LIST Marker; + UINTN Index; + UINTN MaxIndex; + // + // Increase array size of 'UnicodeFormat' and 'Buffer' by 1 as there is a possibility of buffer overflow. + // + CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1]; + CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1]; + + MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format); + if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) { + // + // Format string was too long for use to process. + // + return 0; + } + + if (ErrorString != '\0') { + if (gST->StdErr != NULL) { + // + // To be extra safe make sure StdErr has been initialized + // + gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_RED, EFI_BLACK)); + gST->StdErr->OutputString (gST->StdErr, (CHAR16 *) ErrorString); + gST->StdErr->SetAttribute (gST->StdErr, EFI_TEXT_ATTR (EFI_WHITE, EFI_BLACK)); + } + } + + for (Index = 0; Index < MaxIndex; Index++) { + UnicodeFormat[Index] = (CHAR16) Format[Index]; + } + + UnicodeFormat[Index] = 0; + + VA_START (Marker, Format); + Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker); + VA_END (Marker); + + // + // Need to convert to Unicode to do an OutputString + // + + if (gST->StdErr != NULL) { + // + // To be extra safe make sure StdErr has been initialized + // + gST->StdErr->OutputString (gST->StdErr, Buffer); + } + + return Return; +} + + +UINTN +Aprint ( + IN CONST CHAR8 *Format, + ... + ) +/*++ + +Routine Description: + + Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii + characters. + +Arguments: + + Format - Ascii format string see file header for more details. + + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Return; + VA_LIST Marker; + UINTN Index; + UINTN MaxIndex; + CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; + CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; + + MaxIndex = EfiAsciiStrLen ((CHAR8 *) Format); + if (MaxIndex >= EFI_DRIVER_LIB_MAX_PRINT_BUFFER) { + // + // Format string was too long for use to process. + // + return 0; + } + + for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER; Index++) { + UnicodeFormat[Index] = (CHAR16) Format[Index]; + } + + VA_START (Marker, Format); + Return = VSPrint (Buffer, sizeof (Buffer), UnicodeFormat, Marker); + VA_END (Marker); + + // + // Need to convert to Unicode to do an OutputString + // + + if (gST->ConOut != NULL) { + // + // To be extra safe make sure ConOut has been initialized + // + gST->ConOut->OutputString (gST->ConOut, Buffer); + } + + return Return; +} + + +UINTN +Print ( + IN CONST CHAR16 *Format, + ... + ) +/*++ + +Routine Description: + + Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii + characters. + +Arguments: + + Format - Ascii format string see file header for more details. + + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Return; + VA_LIST Marker; + CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; + + VA_START (Marker, Format); + Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker); + VA_END (Marker); + + if (gST->ConOut != NULL) { + // + // To be extra safe make sure ConOut has been initialized + // + gST->ConOut->OutputString (gST->ConOut, Buffer); + } + + return Return; +} + +UINTN +UPrint ( + IN CONST CHAR16 *Format, + ... + ) +/*++ + +Routine Description: + + Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii + characters. + +Arguments: + + Format - Ascii format string see file header for more details. + + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Return; + VA_LIST Marker; + CHAR16 Buffer[EFI_DRIVER_LIB_MAX_PRINT_BUFFER]; + + VA_START (Marker, Format); + Return = VSPrint (Buffer, sizeof (Buffer), Format, Marker); + VA_END (Marker); + + if (gST->ConOut != NULL) { + // + // To be extra safe make sure ConOut has been initialized + // + gST->ConOut->OutputString (gST->ConOut, Buffer); + } + + return Return; +} diff --git a/EDK/Foundation/Library/Dxe/Print/Unicode/PrintUnicode.cif b/EDK/Foundation/Library/Dxe/Print/Unicode/PrintUnicode.cif new file mode 100644 index 0000000..01c6e6d --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Unicode/PrintUnicode.cif @@ -0,0 +1,9 @@ +<component> + name = "PrintUnicode" + category = ModulePart + LocalRoot = "EDK\Foundation\Library\Dxe\Print\Unicode" + RefName = "PrintUnicode" +[files] +"PrintWidth.h" +"Sprint.c" +<endComponent> diff --git a/EDK/Foundation/Library/Dxe/Print/Unicode/PrintWidth.h b/EDK/Foundation/Library/Dxe/Print/Unicode/PrintWidth.h new file mode 100644 index 0000000..fef9ea9 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Unicode/PrintWidth.h @@ -0,0 +1,35 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + PrintWidth.h + +Abstract: + + Unicde option for generic width. + CHAR_W is Unicode + STRING_W is L"" + +--*/ + +#ifndef _PRINT_WIDTH_H_ +#define _PRINT_WIDTH_H_ + +typedef CHAR16 CHAR_W; +#define STRING_W(_s) L##_s + +#define USPrint(Buffer, BufferSize, Format) SPrint (Buffer, BufferSize, Format) +#define UvSPrint(Buffer, BufferSize, Format, Marker) VSPrint (Buffer, BufferSize, Format, Marker) + +#include "EfiCommonLib.h" + +#endif diff --git a/EDK/Foundation/Library/Dxe/Print/Unicode/Sprint.c b/EDK/Foundation/Library/Dxe/Print/Unicode/Sprint.c new file mode 100644 index 0000000..e3b8738 --- /dev/null +++ b/EDK/Foundation/Library/Dxe/Print/Unicode/Sprint.c @@ -0,0 +1,147 @@ +/*++ + +Copyright (c) 2004, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + Sprint.c + +Abstract: + + Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very + simple implemenation of SPrint() and Print() to support debug. + + You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a + time. This makes the implementation very simple. + + VSPrint, Print, SPrint format specification has the follwoing form + + %[flags][width]type + + flags: + '-' - Left justify + '+' - Prefix a sign + ' ' - Prefix a blank + ',' - Place commas in numberss + '0' - Prefix for width with zeros + 'l' - UINT64 + 'L' - UINT64 + + width: + '*' - Get width from a UINTN argumnet from the argument list + Decimal number that represents width of print + + type: + 'X' - argument is a UINTN hex number, prefix '0' + 'x' - argument is a hex number + 'd' - argument is a decimal number + 'a' - argument is an ascii string + 'S','s' - argument is an Unicode string + 'g' - argument is a pointer to an EFI_GUID + 't' - argument is a pointer to an EFI_TIME structure + 'c' - argument is an ascii character + 'r' - argument is EFI_STATUS + '%' - Print a % + +--*/ + +#include "TianoCommon.h" +#include "PrintWidth.h" +#include "EfiPrintLib.h" +#include "Print.h" + + +UINTN +ASPrint ( + OUT CHAR8 *Buffer, + IN UINTN BufferSize, + IN CONST CHAR8 *Format, + ... + ) +/*++ + +Routine Description: + + Process format and place the results in Buffer for narrow chars. + +Arguments: + + Buffer - Narrow char buffer to print the results of the parsing of Format into. + BufferSize - Maximum number of characters to put into buffer. + Format - Format string + ... - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Return; + VA_LIST Marker; + + VA_START (Marker, Format); + Return = AvSPrint (Buffer, BufferSize, Format, Marker); + VA_END (Marker); + + return Return; +} + + +UINTN +AvSPrint ( + OUT CHAR8 *Buffer, + IN UINTN BufferSize, + IN CONST CHAR8 *FormatString, + IN VA_LIST Marker + ) +/*++ + +Routine Description: + + Internal implementation of ASPrint. + Process format and place the results in Buffer for narrow chars. + +Arguments: + + Buffer - Narrow char buffer to print the results of the parsing of Format into. + BufferSize - Maximum number of characters to put into buffer. + FormatString - Format string + Marker - Vararg list consumed by processing Format. + +Returns: + + Number of characters printed. + +--*/ +{ + UINTN Index; + // + // Increase array size of 'UnicodeFormat' and 'UnicodeResult' by 1 as there is a possibility of buffer overflow. + // + CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1]; + CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1]; + + for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) { + UnicodeFormat[Index] = (CHAR16) FormatString[Index]; + } + + UnicodeFormat[Index] = '\0'; + + Index = VSPrint (UnicodeResult, sizeof (UnicodeResult)/sizeof (CHAR16), UnicodeFormat, Marker); + + for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) { + Buffer[Index] = (CHAR8) UnicodeResult[Index]; + } + + Buffer[Index] = '\0'; + + return Index++; +} |