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
36 //@MT:#include "Tiano.h"
37 //@MT:#include "EfiDriverLib.h"
38 //@MT:#include "EfiPrintLib.h"
39 //@MT:#include "EfiStdArg.h"
40 //@MT:#include "TianoHii.h"
45 IN OUT CHAR16
*Buffer
,
54 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Out
,
59 // Display string worker for: Print, PrintAt, IPrint, IPrintAt
68 // For now, allocate an arbitrarily long buffer
70 Buffer
= AllocateZeroPool (0x10000);
71 BackupBuffer
= AllocateZeroPool (0x10000);
73 ASSERT (BackupBuffer
);
75 if (Column
!= (UINTN
) -1) {
76 Out
->SetCursorPosition (Out
, Column
, Row
);
79 UnicodeVSPrint (Buffer
, 0x10000, fmt
, args
);
81 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
& 0x7f;
83 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
89 for (; (Buffer
[Index
] != NARROW_CHAR
) && (Buffer
[Index
] != WIDE_CHAR
) && (Buffer
[Index
] != 0); Index
++) {
90 BackupBuffer
[Index
] = Buffer
[Index
];
93 if (Buffer
[Index
] == 0) {
97 // Null-terminate the temporary string
99 BackupBuffer
[Index
] = 0;
102 // Print this out, we are about to switch widths
104 Out
->OutputString (Out
, &BackupBuffer
[PreviousIndex
]);
107 // Preserve the current index + 1, since this is where we will start printing from next
109 PreviousIndex
= Index
+ 1;
112 // We are at a narrow or wide character directive. Set attributes and strip it and print it
114 if (Buffer
[Index
] == NARROW_CHAR
) {
116 // Preserve bits 0 - 6 and zero out the rest
118 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
& 0x7f;
119 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
122 // Must be wide, set bit 7 ON
124 Out
->Mode
->Attribute
= Out
->Mode
->Attribute
| EFI_WIDE_ATTRIBUTE
;
125 Out
->SetAttribute (Out
, Out
->Mode
->Attribute
);
130 } while (Buffer
[Index
] != 0);
133 // We hit the end of the string - print it
135 Out
->OutputString (Out
, &BackupBuffer
[PreviousIndex
]);
137 gBS
->FreePool (Buffer
);
138 gBS
->FreePool (BackupBuffer
);
144 Prints a formatted unicode string to the default console
146 @param fmt Format string
148 @return Length of string printed to the console
159 VA_START (args
, fmt
);
160 return PrintInternal ((UINTN
) -1, (UINTN
) -1, gST
->ConOut
, fmt
, args
);
165 Prints a unicode string to the default console,
168 @param String String pointer.
170 @return Length of string printed to the console
178 return ConsolePrint (L
"%s", String
);
183 Prints a chracter to the default console,
186 @param Character Character to print.
188 @return Length of string printed to the console.
196 return ConsolePrint (L
"%c", Character
);
201 Prints a formatted unicode string to the default console, at
202 the supplied cursor position
204 @param Row The cursor position to print the string at
205 @param fmt Format string
207 @return Length of string printed to the console
220 VA_START (args
, fmt
);
221 return PrintInternal (Column
, Row
, gST
->ConOut
, fmt
, args
);
226 Prints a unicode string to the default console, at
227 the supplied cursor position, using L"%s" format.
229 @param Row The cursor position to print the string at
230 @param String String pointer.
232 @return Length of string printed to the console
242 return PrintAt (Column
, Row
, L
"%s", String
);
247 Prints a chracter to the default console, at
248 the supplied cursor position, using L"%c" format.
250 @param Row The cursor position to print the string at
251 @param Character Character to print.
253 @return Length of string printed to the console.
263 return PrintAt (Column
, Row
, L
"%c", Character
);
268 VSPrint worker function that prints a Value as a decimal number in Buffer
270 @param Buffer Location to place ascii decimal number string of Value.
271 @param Value Decimal value to convert to a string in Buffer.
272 @param Flags Flags to use in printing decimal string, see file header for
275 @return Number of characters printed.
280 IN OUT CHAR16
*Buffer
,
285 CHAR16 TempBuffer
[30];
294 TempStr
= TempBuffer
;
305 Value
= (INT64
) DivU64x32Remainder ((UINT64
) Value
, 10, &Remainder
);
306 *(TempStr
++) = (CHAR16
) (Remainder
+ '0');
309 if ((Flags
& COMMA_TYPE
) == COMMA_TYPE
) {
310 if (NumberCount
% 3 == 0 && Value
!= 0) {
315 } while (Value
!= 0);
318 *(BufferPtr
++) = '-';
323 // Reverse temp string into Buffer.
325 while (TempStr
!= TempBuffer
) {
326 *(BufferPtr
++) = *(--TempStr
);