878ddf1f |
1 | /*++\r |
2 | \r |
3 | Copyright (c) 2006, Intel Corporation \r |
4 | All rights reserved. This program and the accompanying materials \r |
5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r |
7 | http://opensource.org/licenses/bsd-license.php \r |
8 | \r |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r |
11 | \r |
12 | Module Name:\r |
13 | \r |
14 | Print.c\r |
15 | \r |
16 | Abstract:\r |
17 | \r |
18 | Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very\r |
19 | simple implemenation of SPrint() and Print() to support debug. \r |
20 | \r |
21 | You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a \r |
22 | time. This makes the implementation very simple.\r |
23 | \r |
24 | VSPrint, Print, SPrint format specification has the follwoing form\r |
25 | \r |
26 | %type\r |
27 | \r |
28 | type:\r |
29 | 'S','s' - argument is an Unicode string\r |
30 | 'c' - argument is an ascii character\r |
31 | '%' - Print a %\r |
32 | \r |
33 | --*/\r |
34 | \r |
35 | #include "print.h"\r |
36 | \r |
37 | STATIC\r |
38 | UINTN\r |
39 | _IPrint (\r |
40 | IN UINTN Column,\r |
41 | IN UINTN Row,\r |
42 | IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *Out,\r |
43 | IN CHAR16 *fmt,\r |
44 | IN VA_LIST args\r |
45 | )\r |
46 | //\r |
47 | // Display string worker for: Print, PrintAt, IPrint, IPrintAt\r |
48 | //\r |
49 | {\r |
50 | CHAR16 *Buffer;\r |
51 | CHAR16 *BackupBuffer;\r |
52 | UINTN Index;\r |
53 | UINTN PreviousIndex;\r |
54 | \r |
55 | //\r |
56 | // For now, allocate an arbitrarily long buffer\r |
57 | //\r |
58 | Buffer = AllocateZeroPool (0x10000);\r |
59 | BackupBuffer = AllocateZeroPool (0x10000);\r |
60 | ASSERT (Buffer);\r |
61 | ASSERT (BackupBuffer);\r |
62 | \r |
63 | if (Column != (UINTN) -1) {\r |
64 | Out->SetCursorPosition (Out, Column, Row);\r |
65 | }\r |
66 | \r |
67 | UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r |
68 | \r |
69 | Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;\r |
70 | \r |
71 | Out->SetAttribute (Out, Out->Mode->Attribute);\r |
72 | \r |
73 | Index = 0;\r |
74 | PreviousIndex = 0;\r |
75 | \r |
76 | do {\r |
77 | for (; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {\r |
78 | BackupBuffer[Index] = Buffer[Index];\r |
79 | }\r |
80 | \r |
81 | if (Buffer[Index] == 0) {\r |
82 | break;\r |
83 | }\r |
84 | //\r |
85 | // Null-terminate the temporary string\r |
86 | //\r |
87 | BackupBuffer[Index] = 0;\r |
88 | \r |
89 | //\r |
90 | // Print this out, we are about to switch widths\r |
91 | //\r |
92 | Out->OutputString (Out, &BackupBuffer[PreviousIndex]);\r |
93 | \r |
94 | //\r |
95 | // Preserve the current index + 1, since this is where we will start printing from next\r |
96 | //\r |
97 | PreviousIndex = Index + 1;\r |
98 | \r |
99 | //\r |
100 | // We are at a narrow or wide character directive. Set attributes and strip it and print it\r |
101 | //\r |
102 | if (Buffer[Index] == NARROW_CHAR) {\r |
103 | //\r |
104 | // Preserve bits 0 - 6 and zero out the rest\r |
105 | //\r |
106 | Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;\r |
107 | Out->SetAttribute (Out, Out->Mode->Attribute);\r |
108 | } else {\r |
109 | //\r |
110 | // Must be wide, set bit 7 ON\r |
111 | //\r |
112 | Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;\r |
113 | Out->SetAttribute (Out, Out->Mode->Attribute);\r |
114 | }\r |
115 | \r |
116 | Index++;\r |
117 | \r |
118 | } while (Buffer[Index] != 0);\r |
119 | \r |
120 | //\r |
121 | // We hit the end of the string - print it\r |
122 | //\r |
123 | Out->OutputString (Out, &BackupBuffer[PreviousIndex]);\r |
124 | \r |
125 | gBS->FreePool (Buffer);\r |
126 | gBS->FreePool (BackupBuffer);\r |
127 | return EFI_SUCCESS;\r |
128 | }\r |
129 | \r |
130 | UINTN\r |
131 | Print (\r |
132 | IN CHAR16 *fmt,\r |
133 | ...\r |
134 | )\r |
135 | /*++\r |
136 | \r |
137 | Routine Description:\r |
138 | \r |
139 | Prints a formatted unicode string to the default console\r |
140 | \r |
141 | Arguments:\r |
142 | \r |
143 | fmt - Format string\r |
144 | \r |
145 | Returns:\r |
146 | \r |
147 | Length of string printed to the console\r |
148 | \r |
149 | --*/\r |
150 | {\r |
151 | VA_LIST args;\r |
152 | \r |
153 | VA_START (args, fmt);\r |
154 | return _IPrint ((UINTN) -1, (UINTN) -1, gST->ConOut, fmt, args);\r |
155 | }\r |
156 | \r |
157 | UINTN\r |
158 | PrintString (\r |
159 | CHAR16 *String\r |
160 | )\r |
161 | /*++\r |
162 | \r |
163 | Routine Description:\r |
164 | \r |
165 | Prints a unicode string to the default console,\r |
166 | using L"%s" format.\r |
167 | \r |
168 | Arguments:\r |
169 | \r |
170 | String - String pointer.\r |
171 | \r |
172 | Returns:\r |
173 | \r |
174 | Length of string printed to the console\r |
175 | \r |
176 | --*/\r |
177 | {\r |
178 | return Print ((CHAR16 *) L"%s", String);\r |
179 | }\r |
180 | \r |
181 | UINTN\r |
182 | PrintChar (\r |
183 | CHAR16 Character\r |
184 | )\r |
185 | /*++\r |
186 | \r |
187 | Routine Description:\r |
188 | \r |
189 | Prints a chracter to the default console,\r |
190 | using L"%c" format.\r |
191 | \r |
192 | Arguments:\r |
193 | \r |
194 | Character - Character to print.\r |
195 | \r |
196 | Returns:\r |
197 | \r |
198 | Length of string printed to the console.\r |
199 | \r |
200 | --*/\r |
201 | {\r |
202 | return Print ((CHAR16 *) L"%c", Character);\r |
203 | }\r |
204 | \r |
205 | /*\r |
206 | UINTN\r |
207 | PrintToken (\r |
208 | IN EFI_HII_HANDLE Handle,\r |
209 | IN UINT16 Token,\r |
210 | IN CHAR16 *Language,\r |
211 | ...\r |
212 | )\r |
213 | {\r |
214 | VA_LIST args;\r |
215 | UINTN NumberOfHiiHandles;\r |
216 | EFI_HANDLE *HandleBuffer;\r |
217 | EFI_HII_PROTOCOL *Hii;\r |
218 | \r |
219 | //\r |
220 | // There should only be one HII image\r |
221 | //\r |
222 | Status = gBS->LocateHandleBuffer (\r |
223 | ByProtocol, \r |
224 | &gEfiHiiProtocolGuid, \r |
225 | NULL,\r |
226 | &NumberOfHiiHandles, \r |
227 | &HandleBuffer\r |
228 | );\r |
229 | \r |
230 | if (EFI_ERROR (Status)) {\r |
231 | return Status;\r |
232 | }\r |
233 | \r |
234 | //\r |
235 | // Retrieve the Hii protocol interface\r |
236 | //\r |
237 | Status = gBS->HandleProtocol (\r |
238 | HandleBuffer[0], \r |
239 | &gEfiHiiProtocolGuid, \r |
240 | &Hii\r |
241 | );\r |
242 | \r |
243 | Hii->GetString (Hii, Handle, Token, FALSE, Language, \r |
244 | \r |
245 | VA_START (args, fmt);\r |
246 | return _IPrint ((UINTN) -1, (UINTN) -1, gST->ConOut, fmt, args);\r |
247 | }\r |
248 | \r |
249 | */\r |
250 | UINTN\r |
251 | PrintAt (\r |
252 | IN UINTN Column,\r |
253 | IN UINTN Row,\r |
254 | IN CHAR16 *fmt,\r |
255 | ...\r |
256 | )\r |
257 | /*++\r |
258 | \r |
259 | Routine Description:\r |
260 | \r |
261 | Prints a formatted unicode string to the default console, at \r |
262 | the supplied cursor position\r |
263 | \r |
264 | Arguments:\r |
265 | \r |
266 | Column, Row - The cursor position to print the string at\r |
267 | \r |
268 | fmt - Format string\r |
269 | \r |
270 | Returns:\r |
271 | \r |
272 | Length of string printed to the console\r |
273 | \r |
274 | --*/\r |
275 | {\r |
276 | VA_LIST args;\r |
277 | \r |
278 | VA_START (args, fmt);\r |
279 | return _IPrint (Column, Row, gST->ConOut, fmt, args);\r |
280 | }\r |
281 | \r |
282 | UINTN\r |
283 | PrintStringAt (\r |
284 | IN UINTN Column,\r |
285 | IN UINTN Row,\r |
286 | CHAR16 *String\r |
287 | )\r |
288 | /*++\r |
289 | \r |
290 | Routine Description:\r |
291 | \r |
292 | Prints a unicode string to the default console, at \r |
293 | the supplied cursor position, using L"%s" format.\r |
294 | \r |
295 | Arguments:\r |
296 | \r |
297 | Column, Row - The cursor position to print the string at\r |
298 | \r |
299 | String - String pointer.\r |
300 | \r |
301 | Returns:\r |
302 | \r |
303 | Length of string printed to the console\r |
304 | \r |
305 | --*/\r |
306 | {\r |
307 | return PrintAt (Column, Row, (CHAR16 *) L"%s", String);\r |
308 | }\r |
309 | \r |
310 | UINTN\r |
311 | PrintCharAt (\r |
312 | IN UINTN Column,\r |
313 | IN UINTN Row,\r |
314 | CHAR16 Character\r |
315 | )\r |
316 | /*++\r |
317 | \r |
318 | Routine Description:\r |
319 | \r |
320 | Prints a chracter to the default console, at \r |
321 | the supplied cursor position, using L"%c" format.\r |
322 | \r |
323 | Arguments:\r |
324 | \r |
325 | Column, Row - The cursor position to print the string at\r |
326 | \r |
327 | Character - Character to print.\r |
328 | \r |
329 | Returns:\r |
330 | \r |
331 | Length of string printed to the console.\r |
332 | \r |
333 | --*/\r |
334 | {\r |
335 | return PrintAt (Column, Row, (CHAR16 *) L"%c", Character);\r |
336 | }\r |
337 | \r |
338 | \r |