2 Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
3 simple implemenation of SPrint() and Print() to support debug.
5 You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
6 time. This makes the implementation very simple.
8 VSPrint, Print, SPrint format specification has the follwoing form
13 'S','s' - argument is an Unicode string
14 'c' - argument is an ascii character
18 Copyright (c) 2004 - 2007, Intel Corporation
19 All rights reserved. This program and the accompanying materials
20 are licensed and made available under the terms and conditions of the BSD License
21 which accompanies this distribution. The full text of the license may be found at
22 http://opensource.org/licenses/bsd-license.php
24 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
25 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
32 VSPrint worker function that prints a Value as a decimal number in Buffer.
34 @param Buffer Location to place ascii decimal number string of Value.
35 @param Flags Flags to use in printing decimal string, see file header for
37 @param Value Decimal value to convert to a string in Buffer.
39 @return Number of characters printed.
44 IN OUT CHAR16
*Buffer
,
50 The internal function prints to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
53 @param Column The position of the output string.
54 @param Row The position of the output string.
55 @param Out The EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.
56 @param Fmt The format string.
57 @param Args The additional argument for the variables in the format string.
59 @return Number of Unicode character printed.
66 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Out
,
78 // For now, allocate an arbitrarily long buffer
80 Buffer
= AllocateZeroPool (0x10000);
81 BackupBuffer
= AllocateZeroPool (0x10000);
83 ASSERT (BackupBuffer
);
85 if (Column
!= (UINTN
) -1) {
86 Out
->SetCursorPosition (Out
, Column
, Row
);
89 UnicodeVSPrint (Buffer
, 0x10000, Fmt
, Args
);
91 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
& 0x7f;
93 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
100 for (; (Buffer
[Index
] != NARROW_CHAR
) && (Buffer
[Index
] != WIDE_CHAR
) && (Buffer
[Index
] != 0); Index
++) {
101 BackupBuffer
[Index
] = Buffer
[Index
];
104 if (Buffer
[Index
] == 0) {
108 // Null-terminate the temporary string
110 BackupBuffer
[Index
] = 0;
113 // Print this out, we are about to switch widths
115 Out
->OutputString (Out
, &BackupBuffer
[PreviousIndex
]);
116 Count
+= StrLen (&BackupBuffer
[PreviousIndex
]);
119 // Preserve the current index + 1, since this is where we will start printing from next
121 PreviousIndex
= Index
+ 1;
124 // We are at a narrow or wide character directive. Set attributes and strip it and print it
126 if (Buffer
[Index
] == NARROW_CHAR
) {
128 // Preserve bits 0 - 6 and zero out the rest
130 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
& 0x7f;
131 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
134 // Must be wide, set bit 7 ON
136 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
| EFI_WIDE_ATTRIBUTE
;
137 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
142 } while (Buffer
[Index
] != 0);
145 // We hit the end of the string - print it
147 Out
->OutputString (Out
, &BackupBuffer
[PreviousIndex
]);
148 Count
+= StrLen (&BackupBuffer
[PreviousIndex
]);
151 FreePool (BackupBuffer
);
157 Prints a formatted unicode string to the default console.
159 @param Fmt Format string
160 @param ... Variable argument list for format string.
162 @return Length of string printed to the console.
173 VA_START (Args
, Fmt
);
174 return PrintInternal ((UINTN
) -1, (UINTN
) -1, gST
->ConOut
, Fmt
, Args
);
179 Prints a unicode string to the default console,
182 @param String String pointer.
184 @return Length of string printed to the console
192 return ConsolePrint (L
"%s", String
);
197 Prints a chracter to the default console,
200 @param Character Character to print.
202 @return Length of string printed to the console.
210 return ConsolePrint (L
"%c", Character
);
215 Prints a formatted unicode string to the default console, at
216 the supplied cursor position.
218 @param Column The cursor position to print the string at.
219 @param Row The cursor position to print the string at.
220 @param Fmt Format string.
221 @param ... Variable argument list for format string.
223 @return Length of string printed to the console
236 VA_START (Args
, Fmt
);
237 return PrintInternal (Column
, Row
, gST
->ConOut
, Fmt
, Args
);
242 Prints a unicode string to the default console, at
243 the supplied cursor position, using L"%s" format.
245 @param Column The cursor position to print the string at.
246 @param Row The cursor position to print the string at
247 @param String String pointer.
249 @return Length of string printed to the console
259 return PrintAt (Column
, Row
, L
"%s", String
);
264 Prints a chracter to the default console, at
265 the supplied cursor position, using L"%c" format.
267 @param Column The cursor position to print the string at.
268 @param Row The cursor position to print the string at.
269 @param Character Character to print.
271 @return Length of string printed to the console.
281 return PrintAt (Column
, Row
, L
"%c", Character
);
286 VSPrint worker function that prints a Value as a decimal number in Buffer.
288 @param Buffer Location to place ascii decimal number string of Value.
289 @param Flags Flags to use in printing decimal string, see file header for
291 @param Value Decimal value to convert to a string in Buffer.
293 @return Number of characters printed.
298 IN OUT CHAR16
*Buffer
,
303 CHAR16 TempBuffer
[30];
312 TempStr
= TempBuffer
;
323 Value
= (INT64
) DivU64x32Remainder ((UINT64
) Value
, 10, &Remainder
);
324 *(TempStr
++) = (CHAR16
) (Remainder
+ '0');
327 if ((Flags
& COMMA_TYPE
) == COMMA_TYPE
) {
328 if (NumberCount
% 3 == 0 && Value
!= 0) {
333 } while (Value
!= 0);
336 *(BufferPtr
++) = '-';
341 // Reverse temp string into Buffer.
343 while (TempStr
!= TempBuffer
) {
344 *(BufferPtr
++) = *(--TempStr
);