3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. 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
29 'S','s' - argument is an Unicode string
30 'c' - argument is an ascii character
40 IN OUT CHAR16
*Buffer
,
49 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Out
,
54 // Display string worker for: Print, PrintAt, IPrint, IPrintAt
63 // For now, allocate an arbitrarily long buffer
65 Buffer
= AllocateZeroPool (0x10000);
66 BackupBuffer
= AllocateZeroPool (0x10000);
68 ASSERT (BackupBuffer
);
70 if (Column
!= (UINTN
) -1) {
71 Out
->SetCursorPosition (Out
, Column
, Row
);
74 UnicodeVSPrint (Buffer
, 0x10000, fmt
, args
);
76 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
& 0x7f;
78 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
84 for (; (Buffer
[Index
] != NARROW_CHAR
) && (Buffer
[Index
] != WIDE_CHAR
) && (Buffer
[Index
] != 0); Index
++) {
85 BackupBuffer
[Index
] = Buffer
[Index
];
88 if (Buffer
[Index
] == 0) {
92 // Null-terminate the temporary string
94 BackupBuffer
[Index
] = 0;
97 // Print this out, we are about to switch widths
99 Out
->OutputString (Out
, &BackupBuffer
[PreviousIndex
]);
102 // Preserve the current index + 1, since this is where we will start printing from next
104 PreviousIndex
= Index
+ 1;
107 // We are at a narrow or wide character directive. Set attributes and strip it and print it
109 if (Buffer
[Index
] == NARROW_CHAR
) {
111 // Preserve bits 0 - 6 and zero out the rest
113 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
& 0x7f;
114 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
117 // Must be wide, set bit 7 ON
119 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
| EFI_WIDE_ATTRIBUTE
;
120 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
125 } while (Buffer
[Index
] != 0);
128 // We hit the end of the string - print it
130 Out
->OutputString (Out
, &BackupBuffer
[PreviousIndex
]);
132 gBS
->FreePool (Buffer
);
133 gBS
->FreePool (BackupBuffer
);
139 Prints a formatted unicode string to the default console
141 @param fmt Format string
143 @return Length of string printed to the console
154 VA_START (args
, fmt
);
155 return PrintInternal ((UINTN
) -1, (UINTN
) -1, gST
->ConOut
, fmt
, args
);
160 Prints a unicode string to the default console,
163 @param String String pointer.
165 @return Length of string printed to the console
173 return ConsolePrint (L
"%s", String
);
178 Prints a chracter to the default console,
181 @param Character Character to print.
183 @return Length of string printed to the console.
191 return ConsolePrint (L
"%c", Character
);
196 Prints a formatted unicode string to the default console, at
197 the supplied cursor position
199 @param Row The cursor position to print the string at
200 @param fmt Format string
202 @return Length of string printed to the console
215 VA_START (args
, fmt
);
216 return PrintInternal (Column
, Row
, gST
->ConOut
, fmt
, args
);
221 Prints a unicode string to the default console, at
222 the supplied cursor position, using L"%s" format.
224 @param Row The cursor position to print the string at
225 @param String String pointer.
227 @return Length of string printed to the console
237 return PrintAt (Column
, Row
, L
"%s", String
);
242 Prints a chracter to the default console, at
243 the supplied cursor position, using L"%c" format.
245 @param Row The cursor position to print the string at
246 @param Character Character to print.
248 @return Length of string printed to the console.
258 return PrintAt (Column
, Row
, L
"%c", Character
);
263 VSPrint worker function that prints a Value as a decimal number in Buffer
265 @param Buffer Location to place ascii decimal number string of Value.
266 @param Value Decimal value to convert to a string in Buffer.
267 @param Flags Flags to use in printing decimal string, see file header for
270 @return Number of characters printed.
275 IN OUT CHAR16
*Buffer
,
280 CHAR16 TempBuffer
[30];
289 TempStr
= TempBuffer
;
300 Value
= (INT64
) DivU64x32Remainder ((UINT64
) Value
, 10, &Remainder
);
301 *(TempStr
++) = (CHAR16
) (Remainder
+ '0');
304 if ((Flags
& COMMA_TYPE
) == COMMA_TYPE
) {
305 if (NumberCount
% 3 == 0 && Value
!= 0) {
310 } while (Value
!= 0);
313 *(BufferPtr
++) = '-';
318 // Reverse temp string into Buffer.
320 while (TempStr
!= TempBuffer
) {
321 *(BufferPtr
++) = *(--TempStr
);