]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Provides interface to shell console logger.\r | |
3 | \r | |
85a3fa3a | 4 | Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r |
8e4a89a3 | 5 | Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r |
a405b86d | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | **/\r | |
14 | \r | |
a405b86d | 15 | #include "Shell.h"\r |
16 | \r | |
a405b86d | 17 | /**\r |
18 | Install our intermediate ConOut into the system table to\r | |
19 | keep a log of all the info that is displayed to the user.\r | |
20 | \r | |
21 | @param[in] ScreensToSave Sets how many screen-worths of data to save.\r | |
22 | @param[out] ConsoleInfo The object to pass into later functions.\r | |
23 | \r | |
24 | @retval EFI_SUCCESS The operation was successful.\r | |
25 | @return other The operation failed.\r | |
26 | \r | |
27 | @sa ConsoleLoggerResetBuffers\r | |
28 | @sa InstallProtocolInterface\r | |
29 | **/\r | |
30 | EFI_STATUS\r | |
31 | EFIAPI\r | |
32 | ConsoleLoggerInstall(\r | |
33 | IN CONST UINTN ScreensToSave,\r | |
34 | OUT CONSOLE_LOGGER_PRIVATE_DATA **ConsoleInfo\r | |
35 | )\r | |
36 | {\r | |
37 | EFI_STATUS Status;\r | |
38 | ASSERT(ConsoleInfo != NULL);\r | |
39 | \r | |
733f138d | 40 | (*ConsoleInfo) = AllocateZeroPool(sizeof(CONSOLE_LOGGER_PRIVATE_DATA));\r |
3c865f20 | 41 | if ((*ConsoleInfo) == NULL) {\r |
42 | return (EFI_OUT_OF_RESOURCES);\r | |
43 | }\r | |
a405b86d | 44 | \r |
733f138d | 45 | (*ConsoleInfo)->Signature = CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE;\r |
46 | (*ConsoleInfo)->OldConOut = gST->ConOut;\r | |
47 | (*ConsoleInfo)->OldConHandle = gST->ConsoleOutHandle;\r | |
48 | (*ConsoleInfo)->Buffer = NULL;\r | |
49 | (*ConsoleInfo)->BufferSize = 0;\r | |
50 | (*ConsoleInfo)->OriginalStartRow = 0;\r | |
51 | (*ConsoleInfo)->CurrentStartRow = 0;\r | |
52 | (*ConsoleInfo)->RowsPerScreen = 0;\r | |
53 | (*ConsoleInfo)->ColsPerScreen = 0;\r | |
54 | (*ConsoleInfo)->Attributes = NULL;\r | |
55 | (*ConsoleInfo)->AttribSize = 0;\r | |
56 | (*ConsoleInfo)->ScreenCount = ScreensToSave;\r | |
57 | (*ConsoleInfo)->HistoryMode.MaxMode = 1;\r | |
58 | (*ConsoleInfo)->HistoryMode.Mode = 0;\r | |
59 | (*ConsoleInfo)->HistoryMode.Attribute = 0;\r | |
60 | (*ConsoleInfo)->HistoryMode.CursorColumn = 0;\r | |
61 | (*ConsoleInfo)->HistoryMode.CursorRow = 0;\r | |
62 | (*ConsoleInfo)->HistoryMode.CursorVisible = FALSE;\r | |
63 | (*ConsoleInfo)->OurConOut.Reset = ConsoleLoggerReset;\r | |
64 | (*ConsoleInfo)->OurConOut.OutputString = ConsoleLoggerOutputString;\r | |
65 | (*ConsoleInfo)->OurConOut.TestString = ConsoleLoggerTestString;\r | |
66 | (*ConsoleInfo)->OurConOut.QueryMode = ConsoleLoggerQueryMode;\r | |
67 | (*ConsoleInfo)->OurConOut.SetMode = ConsoleLoggerSetMode;\r | |
68 | (*ConsoleInfo)->OurConOut.SetAttribute = ConsoleLoggerSetAttribute;\r | |
69 | (*ConsoleInfo)->OurConOut.ClearScreen = ConsoleLoggerClearScreen;\r | |
a405b86d | 70 | (*ConsoleInfo)->OurConOut.SetCursorPosition = ConsoleLoggerSetCursorPosition;\r |
733f138d | 71 | (*ConsoleInfo)->OurConOut.EnableCursor = ConsoleLoggerEnableCursor;\r |
72 | (*ConsoleInfo)->OurConOut.Mode = gST->ConOut->Mode;\r | |
73 | (*ConsoleInfo)->Enabled = TRUE;\r | |
a405b86d | 74 | \r |
75 | Status = ConsoleLoggerResetBuffers(*ConsoleInfo);\r | |
76 | if (EFI_ERROR(Status)) {\r | |
8be0ba36 | 77 | SHELL_FREE_NON_NULL((*ConsoleInfo));\r |
78 | *ConsoleInfo = NULL;\r | |
a405b86d | 79 | return (Status);\r |
80 | }\r | |
81 | \r | |
82 | Status = gBS->InstallProtocolInterface(&gImageHandle, &gEfiSimpleTextOutProtocolGuid, EFI_NATIVE_INTERFACE, (VOID*)&((*ConsoleInfo)->OurConOut));\r | |
8be0ba36 | 83 | if (EFI_ERROR(Status)) {\r |
84 | SHELL_FREE_NON_NULL((*ConsoleInfo)->Buffer);\r | |
85 | SHELL_FREE_NON_NULL((*ConsoleInfo)->Attributes);\r | |
86 | SHELL_FREE_NON_NULL((*ConsoleInfo));\r | |
87 | *ConsoleInfo = NULL;\r | |
88 | return (Status);\r | |
89 | }\r | |
a405b86d | 90 | \r |
a405b86d | 91 | gST->ConsoleOutHandle = gImageHandle;\r |
733f138d | 92 | gST->ConOut = &(*ConsoleInfo)->OurConOut;\r |
a405b86d | 93 | \r |
94 | return (Status);\r | |
95 | }\r | |
96 | \r | |
97 | /**\r | |
98 | Return the system to the state it was before InstallConsoleLogger\r | |
99 | was installed.\r | |
100 | \r | |
733f138d | 101 | @param[in] ConsoleInfo The object from the install function.\r |
a405b86d | 102 | \r |
103 | @retval EFI_SUCCESS The operation was successful\r | |
104 | @return other The operation failed. This was from UninstallProtocolInterface.\r | |
105 | **/\r | |
106 | EFI_STATUS\r | |
107 | EFIAPI\r | |
108 | ConsoleLoggerUninstall(\r | |
109 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r | |
110 | )\r | |
111 | {\r | |
112 | ASSERT(ConsoleInfo != NULL);\r | |
113 | ASSERT(ConsoleInfo->OldConOut != NULL);\r | |
114 | \r | |
115 | if (ConsoleInfo->Buffer != NULL) {\r | |
116 | FreePool(ConsoleInfo->Buffer);\r | |
117 | DEBUG_CODE(ConsoleInfo->Buffer = NULL;);\r | |
118 | DEBUG_CODE(ConsoleInfo->BufferSize = 0;);\r | |
119 | }\r | |
120 | if (ConsoleInfo->Attributes != NULL) {\r | |
121 | FreePool(ConsoleInfo->Attributes);\r | |
122 | DEBUG_CODE(ConsoleInfo->Attributes = NULL;);\r | |
123 | DEBUG_CODE(ConsoleInfo->AttribSize = 0;);\r | |
124 | }\r | |
125 | \r | |
126 | gST->ConsoleOutHandle = ConsoleInfo->OldConHandle;\r | |
127 | gST->ConOut = ConsoleInfo->OldConOut;\r | |
128 | \r | |
129 | return (gBS->UninstallProtocolInterface(gImageHandle, &gEfiSimpleTextOutProtocolGuid, (VOID*)&ConsoleInfo->OurConOut));\r | |
130 | }\r | |
131 | \r | |
132 | /**\r | |
133 | Displays previously logged output back to the screen.\r | |
134 | \r | |
135 | This will scroll the screen forwards and backwards through the log of previous\r | |
136 | output. If Rows is 0 then the size of 1/2 the screen will be scrolled. If Rows\r | |
137 | is (UINTN)(-1) then the size of the screen will be scrolled.\r | |
138 | \r | |
139 | @param[in] Forward If TRUE then the log will be displayed forwards (scroll to newer).\r | |
140 | If FALSE then the log will be displayed backwards (scroll to older).\r | |
141 | @param[in] Rows Determines how many rows the log should scroll.\r | |
142 | @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r | |
143 | **/\r | |
144 | EFI_STATUS\r | |
145 | EFIAPI\r | |
146 | ConsoleLoggerDisplayHistory(\r | |
147 | IN CONST BOOLEAN Forward,\r | |
148 | IN CONST UINTN Rows,\r | |
149 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r | |
150 | )\r | |
151 | {\r | |
152 | UINTN RowChange;\r | |
153 | \r | |
154 | ASSERT(ConsoleInfo != NULL);\r | |
155 | \r | |
156 | //\r | |
157 | // Calculate the row number change\r | |
158 | //\r | |
159 | switch (Rows) {\r | |
160 | case ((UINTN)(-1)):\r | |
161 | RowChange = ConsoleInfo->RowsPerScreen;\r | |
162 | break;\r | |
163 | case (0):\r | |
164 | RowChange = ConsoleInfo->RowsPerScreen / 2;\r | |
165 | break;\r | |
166 | default:\r | |
167 | RowChange = Rows;\r | |
168 | break;\r | |
169 | }\r | |
170 | \r | |
171 | //\r | |
172 | // Do the math for direction\r | |
173 | //\r | |
174 | if (Forward) {\r | |
175 | if ((ConsoleInfo->OriginalStartRow - ConsoleInfo->CurrentStartRow) < RowChange) {\r | |
176 | RowChange = ConsoleInfo->OriginalStartRow - ConsoleInfo->CurrentStartRow;\r | |
177 | }\r | |
178 | } else {\r | |
179 | if (ConsoleInfo->CurrentStartRow < RowChange) {\r | |
180 | RowChange = ConsoleInfo->CurrentStartRow;\r | |
181 | }\r | |
182 | }\r | |
183 | \r | |
184 | //\r | |
185 | // If we are already at one end or the other\r | |
186 | //\r | |
187 | if (RowChange == 0) {\r | |
188 | return (EFI_SUCCESS);\r | |
189 | }\r | |
190 | \r | |
191 | //\r | |
192 | // Clear the screen\r | |
193 | //\r | |
194 | ConsoleInfo->OldConOut->ClearScreen(ConsoleInfo->OldConOut);\r | |
195 | \r | |
196 | //\r | |
197 | // Set the new start row\r | |
198 | //\r | |
199 | if (Forward) {\r | |
200 | ConsoleInfo->CurrentStartRow += RowChange;\r | |
201 | } else {\r | |
202 | ConsoleInfo->CurrentStartRow -= RowChange;\r | |
203 | }\r | |
204 | \r | |
205 | //\r | |
206 | // Change the screen\r | |
207 | //\r | |
208 | return (UpdateDisplayFromHistory(ConsoleInfo));\r | |
209 | }\r | |
210 | \r | |
211 | /**\r | |
212 | Function to return to normal output whent he scrolling is complete.\r | |
213 | @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r | |
214 | \r | |
215 | @retval EFI_SUCCESS The operation was successful.\r | |
216 | @return other The operation failed. See UpdateDisplayFromHistory.\r | |
217 | \r | |
218 | @sa UpdateDisplayFromHistory\r | |
219 | **/\r | |
220 | EFI_STATUS\r | |
221 | EFIAPI\r | |
222 | ConsoleLoggerStopHistory(\r | |
223 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r | |
224 | )\r | |
225 | {\r | |
226 | ASSERT(ConsoleInfo != NULL);\r | |
227 | if (ConsoleInfo->CurrentStartRow == ConsoleInfo->OriginalStartRow) {\r | |
228 | return (EFI_SUCCESS);\r | |
229 | }\r | |
230 | ConsoleInfo->CurrentStartRow = ConsoleInfo->OriginalStartRow;\r | |
231 | return (UpdateDisplayFromHistory(ConsoleInfo));\r | |
232 | }\r | |
233 | \r | |
234 | /**\r | |
235 | Updates the hidden ConOut to be displaying the correct stuff.\r | |
236 | @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r | |
237 | \r | |
238 | @retval EFI_SUCCESS The operation was successful.\r | |
239 | @return other The operation failed.\r | |
240 | **/\r | |
241 | EFI_STATUS\r | |
242 | EFIAPI\r | |
243 | UpdateDisplayFromHistory(\r | |
244 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r | |
245 | )\r | |
246 | {\r | |
247 | EFI_STATUS Status;\r | |
248 | EFI_STATUS RetVal;\r | |
249 | CHAR16 *Screen;\r | |
250 | INT32 *Attributes;\r | |
251 | UINTN CurrentRow;\r | |
252 | CHAR16 TempCharHolder;\r | |
253 | UINTN Column;\r | |
254 | INT32 CurrentAttrib;\r | |
255 | UINTN CurrentColumn;\r | |
256 | CHAR16 *StringSegment;\r | |
257 | CHAR16 *StringSegmentEnd;\r | |
258 | CHAR16 StringSegmentEndChar;\r | |
ad7782a4 | 259 | INT32 OrigAttribute;\r |
a405b86d | 260 | \r |
261 | ASSERT(ConsoleInfo != NULL);\r | |
262 | TempCharHolder = CHAR_NULL;\r | |
263 | RetVal = EFI_SUCCESS;\r | |
ad7782a4 | 264 | OrigAttribute = ConsoleInfo->OldConOut->Mode->Attribute;\r |
a405b86d | 265 | \r |
266 | //\r | |
267 | // Disable cursor visibility and move it to the top left corner\r | |
268 | //\r | |
269 | ConsoleInfo->OldConOut->EnableCursor (ConsoleInfo->OldConOut, FALSE);\r | |
270 | ConsoleInfo->OldConOut->SetCursorPosition (ConsoleInfo->OldConOut, 0, 0);\r | |
271 | \r | |
272 | Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->CurrentStartRow];\r | |
273 | Attributes = &ConsoleInfo->Attributes[ConsoleInfo->ColsPerScreen * ConsoleInfo->CurrentStartRow];\r | |
274 | for ( CurrentRow = 0\r | |
275 | ; CurrentRow < ConsoleInfo->RowsPerScreen\r | |
276 | ; CurrentRow++\r | |
277 | , Screen += (ConsoleInfo->ColsPerScreen + 2)\r | |
278 | , Attributes += ConsoleInfo->ColsPerScreen\r | |
279 | ){\r | |
280 | //\r | |
281 | // dont use the last char - prevents screen scroll\r | |
282 | //\r | |
283 | if (CurrentRow == (ConsoleInfo->RowsPerScreen-1)){\r | |
284 | TempCharHolder = Screen[ConsoleInfo->ColsPerScreen - 1];\r | |
285 | Screen[ConsoleInfo->ColsPerScreen - 1] = CHAR_NULL;\r | |
286 | }\r | |
287 | \r | |
288 | for ( Column = 0\r | |
289 | ; Column < ConsoleInfo->ColsPerScreen\r | |
290 | ; Column++\r | |
291 | ){\r | |
292 | if (Screen[Column] != CHAR_NULL) {\r | |
293 | CurrentAttrib = Attributes[Column];\r | |
294 | CurrentColumn = Column;\r | |
295 | StringSegment = &Screen[Column];\r | |
296 | \r | |
297 | //\r | |
298 | // Find the first char with a different arrribute and make that temporarily NULL\r | |
299 | // so we can do fewer printout statements. (later) restore that one and we will\r | |
300 | // start at that collumn on the next loop.\r | |
301 | //\r | |
302 | StringSegmentEndChar = CHAR_NULL;\r | |
303 | for ( StringSegmentEnd = StringSegment\r | |
304 | ; StringSegmentEnd != CHAR_NULL\r | |
305 | ; StringSegmentEnd++\r | |
306 | , Column++\r | |
307 | ){\r | |
308 | if (Attributes[Column] != CurrentAttrib) {\r | |
309 | StringSegmentEndChar = *StringSegmentEnd;\r | |
310 | *StringSegmentEnd = CHAR_NULL;\r | |
311 | break;\r | |
312 | }\r | |
313 | } // StringSegmentEnd loop\r | |
314 | \r | |
315 | //\r | |
316 | // Now write out as much as had the same Attributes\r | |
317 | //\r | |
318 | \r | |
319 | ConsoleInfo->OldConOut->SetAttribute(ConsoleInfo->OldConOut, CurrentAttrib);\r | |
320 | ConsoleInfo->OldConOut->SetCursorPosition(ConsoleInfo->OldConOut, CurrentColumn, CurrentRow);\r | |
321 | Status = ConsoleInfo->OldConOut->OutputString(ConsoleInfo->OldConOut, StringSegment);\r | |
322 | \r | |
323 | if (EFI_ERROR(Status)) {\r | |
324 | ASSERT(FALSE);\r | |
325 | RetVal = Status;\r | |
326 | }\r | |
327 | \r | |
328 | //\r | |
329 | // If we found a change in attribute put the character back and decrement the column\r | |
330 | // so when it increments it will point at that character and we will start printing\r | |
331 | // a segment with that new attribute\r | |
332 | //\r | |
333 | if (StringSegmentEndChar != CHAR_NULL) {\r | |
334 | *StringSegmentEnd = StringSegmentEndChar;\r | |
335 | StringSegmentEndChar = CHAR_NULL;\r | |
336 | Column--;\r | |
337 | }\r | |
338 | }\r | |
339 | } // column for loop\r | |
340 | \r | |
341 | //\r | |
342 | // If we removed the last char and this was the last row put it back\r | |
343 | //\r | |
344 | if (TempCharHolder != CHAR_NULL) {\r | |
345 | Screen[ConsoleInfo->ColsPerScreen - 1] = TempCharHolder;\r | |
346 | TempCharHolder = CHAR_NULL;\r | |
347 | }\r | |
348 | } // row for loop\r | |
349 | \r | |
350 | //\r | |
351 | // If we are setting the screen back to original turn on the cursor and make it visible\r | |
352 | // and set the attributes back to what they were\r | |
353 | //\r | |
354 | if (ConsoleInfo->CurrentStartRow == ConsoleInfo->OriginalStartRow) {\r | |
355 | ConsoleInfo->OldConOut->SetAttribute (\r | |
356 | ConsoleInfo->OldConOut,\r | |
357 | ConsoleInfo->HistoryMode.Attribute\r | |
358 | );\r | |
359 | ConsoleInfo->OldConOut->SetCursorPosition (\r | |
360 | ConsoleInfo->OldConOut,\r | |
361 | ConsoleInfo->HistoryMode.CursorColumn,\r | |
362 | ConsoleInfo->HistoryMode.CursorRow - ConsoleInfo->OriginalStartRow\r | |
363 | );\r | |
364 | \r | |
365 | Status = ConsoleInfo->OldConOut->EnableCursor (\r | |
366 | ConsoleInfo->OldConOut,\r | |
367 | ConsoleInfo->HistoryMode.CursorVisible\r | |
368 | );\r | |
369 | if (EFI_ERROR (Status)) {\r | |
370 | RetVal = Status;\r | |
371 | }\r | |
ad7782a4 | 372 | } else {\r |
373 | ConsoleInfo->OldConOut->SetAttribute (\r | |
374 | ConsoleInfo->OldConOut,\r | |
375 | OrigAttribute\r | |
376 | );\r | |
a405b86d | 377 | }\r |
378 | \r | |
379 | return (RetVal);\r | |
380 | }\r | |
381 | \r | |
382 | /**\r | |
383 | Reset the text output device hardware and optionaly run diagnostics\r | |
384 | \r | |
385 | @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r | |
386 | @param ExtendedVerification Indicates that a more extensive test may be performed\r | |
387 | \r | |
388 | @retval EFI_SUCCESS The text output device was reset.\r | |
389 | @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and\r | |
390 | could not be reset.\r | |
391 | **/\r | |
392 | EFI_STATUS\r | |
393 | EFIAPI\r | |
394 | ConsoleLoggerReset (\r | |
395 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r | |
396 | IN BOOLEAN ExtendedVerification\r | |
397 | )\r | |
398 | {\r | |
399 | EFI_STATUS Status;\r | |
400 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r | |
401 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r | |
402 | \r | |
403 | //\r | |
404 | // Forward the request to the original ConOut\r | |
405 | //\r | |
406 | Status = ConsoleInfo->OldConOut->Reset (ConsoleInfo->OldConOut, ExtendedVerification);\r | |
407 | \r | |
408 | //\r | |
409 | // Check that the buffers are still correct for logging\r | |
410 | //\r | |
411 | if (!EFI_ERROR (Status)) {\r | |
412 | ConsoleLoggerResetBuffers(ConsoleInfo);\r | |
413 | }\r | |
414 | \r | |
415 | return Status;\r | |
416 | }\r | |
417 | \r | |
418 | /**\r | |
419 | Appends a string to the history buffer. If the buffer is full then the oldest\r | |
420 | information in the buffer will be dropped. Information is added in a line by\r | |
421 | line manner such that an empty line takes up just as much space as a full line.\r | |
422 | \r | |
423 | @param[in] String String pointer to add.\r | |
424 | @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r | |
425 | **/\r | |
426 | EFI_STATUS\r | |
427 | EFIAPI\r | |
428 | AppendStringToHistory(\r | |
429 | IN CONST CHAR16 *String,\r | |
430 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r | |
431 | )\r | |
432 | {\r | |
433 | CONST CHAR16 *Walker;\r | |
434 | UINTN CopySize;\r | |
435 | UINTN PrintIndex;\r | |
436 | UINTN Index;\r | |
437 | \r | |
438 | ASSERT(ConsoleInfo != NULL);\r | |
439 | \r | |
440 | for ( Walker = String\r | |
441 | ; Walker != NULL && *Walker != CHAR_NULL\r | |
442 | ; Walker++\r | |
443 | ){\r | |
444 | switch (*Walker) {\r | |
445 | case (CHAR_BACKSPACE):\r | |
446 | if (ConsoleInfo->HistoryMode.CursorColumn > 0) {\r | |
447 | ConsoleInfo->HistoryMode.CursorColumn--;\r | |
448 | }\r | |
449 | break;\r | |
450 | case (CHAR_LINEFEED):\r | |
451 | if (ConsoleInfo->HistoryMode.CursorRow >= (INT32)((ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount)-1)) {\r | |
452 | //\r | |
453 | // Should never be bigger\r | |
454 | //\r | |
455 | ASSERT(ConsoleInfo->HistoryMode.CursorRow == (INT32)((ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount)-1));\r | |
456 | \r | |
457 | //\r | |
458 | // scroll history attributes 'up' 1 row and set the last row to default attribute\r | |
459 | //\r | |
460 | CopySize = ConsoleInfo->ColsPerScreen\r | |
461 | * ((ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount) - 1)\r | |
462 | * sizeof(ConsoleInfo->Attributes[0]);\r | |
463 | ASSERT(CopySize < ConsoleInfo->AttribSize);\r | |
464 | CopyMem(\r | |
465 | ConsoleInfo->Attributes,\r | |
466 | ConsoleInfo->Attributes + ConsoleInfo->ColsPerScreen,\r | |
467 | CopySize\r | |
468 | );\r | |
469 | \r | |
470 | for ( Index = 0\r | |
471 | ; Index < ConsoleInfo->ColsPerScreen\r | |
472 | ; Index++\r | |
473 | ){\r | |
81634bfb | 474 | *(ConsoleInfo->Attributes + (CopySize/sizeof(ConsoleInfo->Attributes[0])) + Index) = ConsoleInfo->HistoryMode.Attribute;\r |
a405b86d | 475 | }\r |
476 | \r | |
477 | //\r | |
478 | // scroll history buffer 'up' 1 row and set the last row to spaces (L' ')\r | |
479 | //\r | |
480 | CopySize = (ConsoleInfo->ColsPerScreen + 2)\r | |
481 | * ((ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount) - 1)\r | |
482 | * sizeof(ConsoleInfo->Buffer[0]);\r | |
483 | ASSERT(CopySize < ConsoleInfo->BufferSize);\r | |
484 | CopyMem(\r | |
485 | ConsoleInfo->Buffer,\r | |
486 | ConsoleInfo->Buffer + (ConsoleInfo->ColsPerScreen + 2),\r | |
487 | CopySize\r | |
488 | );\r | |
489 | \r | |
490 | //\r | |
491 | // Set that last row of chars to spaces\r | |
492 | //\r | |
493 | SetMem16(((UINT8*)ConsoleInfo->Buffer)+CopySize, ConsoleInfo->ColsPerScreen*sizeof(CHAR16), L' ');\r | |
494 | } else {\r | |
495 | //\r | |
496 | // we are not on the last row\r | |
497 | //\r | |
498 | \r | |
499 | //\r | |
500 | // We should not be scrolling history\r | |
501 | //\r | |
502 | ASSERT (ConsoleInfo->OriginalStartRow == ConsoleInfo->CurrentStartRow);\r | |
503 | //\r | |
504 | // are we at the end of a row?\r | |
505 | //\r | |
506 | if (ConsoleInfo->HistoryMode.CursorRow == (INT32) (ConsoleInfo->OriginalStartRow + ConsoleInfo->RowsPerScreen - 1)) {\r | |
507 | ConsoleInfo->OriginalStartRow++;\r | |
508 | ConsoleInfo->CurrentStartRow++;\r | |
509 | }\r | |
510 | ConsoleInfo->HistoryMode.CursorRow++;\r | |
511 | }\r | |
512 | break;\r | |
513 | case (CHAR_CARRIAGE_RETURN):\r | |
514 | //\r | |
515 | // Move the cursor to the beginning of the current row.\r | |
516 | //\r | |
517 | ConsoleInfo->HistoryMode.CursorColumn = 0;\r | |
518 | break;\r | |
519 | default:\r | |
520 | //\r | |
521 | // Acrtually print characters into the history buffer\r | |
522 | //\r | |
523 | \r | |
524 | PrintIndex = ConsoleInfo->HistoryMode.CursorRow * ConsoleInfo->ColsPerScreen + ConsoleInfo->HistoryMode.CursorColumn;\r | |
525 | \r | |
526 | for ( // no initializer needed\r | |
527 | ; ConsoleInfo->HistoryMode.CursorColumn < (INT32) ConsoleInfo->ColsPerScreen\r | |
528 | ; ConsoleInfo->HistoryMode.CursorColumn++\r | |
529 | , PrintIndex++\r | |
530 | , Walker++\r | |
531 | ){\r | |
532 | if (*Walker == CHAR_NULL\r | |
533 | ||*Walker == CHAR_BACKSPACE\r | |
534 | ||*Walker == CHAR_LINEFEED\r | |
535 | ||*Walker == CHAR_CARRIAGE_RETURN\r | |
536 | ){\r | |
537 | Walker--;\r | |
538 | break;\r | |
539 | }\r | |
540 | //\r | |
541 | // The buffer is 2*CursorRow more since it has that many \r\n characters at the end of each row.\r | |
542 | //\r | |
543 | \r | |
544 | ASSERT(PrintIndex + ConsoleInfo->HistoryMode.CursorRow < ConsoleInfo->BufferSize);\r | |
545 | ConsoleInfo->Buffer[PrintIndex + (2*ConsoleInfo->HistoryMode.CursorRow)] = *Walker;\r | |
546 | ASSERT(PrintIndex < ConsoleInfo->AttribSize);\r | |
547 | ConsoleInfo->Attributes[PrintIndex] = ConsoleInfo->HistoryMode.Attribute;\r | |
548 | } // for loop\r | |
549 | \r | |
550 | //\r | |
551 | // Add the carriage return and line feed at the end of the lines\r | |
552 | //\r | |
553 | if (ConsoleInfo->HistoryMode.CursorColumn >= (INT32)ConsoleInfo->ColsPerScreen) {\r | |
554 | AppendStringToHistory(L"\r\n", ConsoleInfo);\r | |
555 | Walker--;\r | |
556 | }\r | |
557 | \r | |
558 | break;\r | |
559 | } // switch for character\r | |
560 | } // for loop\r | |
561 | \r | |
562 | return (EFI_SUCCESS);\r | |
563 | }\r | |
564 | \r | |
565 | /**\r | |
566 | Worker function to handle printing the output to the screen\r | |
567 | and the history buffer\r | |
568 | \r | |
569 | @param[in] String The string to output\r | |
570 | @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r | |
571 | \r | |
572 | @retval EFI_SUCCESS The string was printed\r | |
573 | @retval EFI_DEVICE_ERROR The device reported an error while attempting to output\r | |
574 | the text.\r | |
575 | @retval EFI_UNSUPPORTED The output device's mode is not currently in a\r | |
576 | defined text mode.\r | |
577 | @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the\r | |
578 | characters in the Unicode string could not be\r | |
579 | rendered and were skipped.\r | |
580 | **/\r | |
581 | EFI_STATUS\r | |
582 | EFIAPI\r | |
583 | ConsoleLoggerOutputStringSplit(\r | |
584 | IN CONST CHAR16 *String,\r | |
585 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r | |
586 | )\r | |
587 | {\r | |
588 | EFI_STATUS Status;\r | |
589 | \r | |
590 | //\r | |
591 | // Forward the request to the original ConOut\r | |
592 | //\r | |
593 | Status = ConsoleInfo->OldConOut->OutputString (ConsoleInfo->OldConOut, (CHAR16*)String);\r | |
594 | \r | |
595 | if (EFI_ERROR(Status)) {\r | |
596 | return (Status);\r | |
597 | }\r | |
598 | \r | |
599 | return (AppendStringToHistory(String, ConsoleInfo));\r | |
600 | }\r | |
601 | \r | |
602 | /**\r | |
603 | Function to handle page break mode.\r | |
604 | \r | |
605 | This function will prompt for continue or break.\r | |
606 | \r | |
607 | @retval EFI_SUCCESS Continue was choosen\r | |
608 | @return other Break was choosen\r | |
609 | **/\r | |
610 | EFI_STATUS\r | |
611 | EFIAPI\r | |
612 | ConsoleLoggerDoPageBreak(\r | |
613 | VOID\r | |
614 | )\r | |
615 | {\r | |
616 | SHELL_PROMPT_RESPONSE *Resp;\r | |
617 | EFI_STATUS Status;\r | |
618 | \r | |
619 | Resp = NULL;\r | |
620 | ASSERT(ShellInfoObject.PageBreakEnabled);\r | |
621 | ShellInfoObject.PageBreakEnabled = FALSE;\r | |
622 | Status = ShellPromptForResponseHii(ShellPromptResponseTypeQuitContinue, STRING_TOKEN(STR_SHELL_QUIT_CONT), ShellInfoObject.HiiHandle, (VOID**)&Resp);\r | |
623 | ShellInfoObject.PageBreakEnabled = TRUE;\r | |
624 | ASSERT(Resp != NULL);\r | |
625 | if (Resp == NULL) {\r | |
626 | return (EFI_NOT_FOUND);\r | |
627 | }\r | |
628 | if (EFI_ERROR(Status)) {\r | |
629 | if (Resp != NULL) {\r | |
630 | FreePool(Resp);\r | |
631 | }\r | |
632 | return (Status);\r | |
633 | }\r | |
634 | if (*Resp == ShellPromptResponseContinue) {\r | |
635 | FreePool(Resp);\r | |
733f138d | 636 | ShellInfoObject.ConsoleInfo->RowCounter = 0;\r |
637 | // ShellInfoObject.ConsoleInfo->OurConOut.Mode->CursorRow = 0;\r | |
638 | // ShellInfoObject.ConsoleInfo->OurConOut.Mode->CursorColumn = 0;\r | |
639 | \r | |
a405b86d | 640 | return (EFI_SUCCESS);\r |
641 | } else if (*Resp == ShellPromptResponseQuit) {\r | |
642 | FreePool(Resp);\r | |
643 | ShellInfoObject.ConsoleInfo->Enabled = FALSE;\r | |
85a3fa3a CP |
644 | //\r |
645 | // When user wants to quit, the shell should stop running the command.\r | |
646 | //\r | |
647 | gBS->SignalEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);\r | |
a405b86d | 648 | return (EFI_DEVICE_ERROR);\r |
649 | } else {\r | |
650 | ASSERT(FALSE);\r | |
651 | }\r | |
652 | return (EFI_SUCCESS);\r | |
653 | }\r | |
654 | /**\r | |
655 | Worker function to handle printing the output with page breaks.\r | |
656 | \r | |
657 | @param[in] String The string to output\r | |
658 | @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r | |
659 | \r | |
660 | @retval EFI_SUCCESS The string was printed\r | |
661 | @retval EFI_DEVICE_ERROR The device reported an error while attempting to output\r | |
662 | the text.\r | |
663 | @retval EFI_UNSUPPORTED The output device's mode is not currently in a\r | |
664 | defined text mode.\r | |
665 | @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the\r | |
666 | characters in the Unicode string could not be\r | |
667 | rendered and were skipped.\r | |
668 | **/\r | |
669 | EFI_STATUS\r | |
670 | EFIAPI\r | |
671 | ConsoleLoggerPrintWithPageBreak(\r | |
733f138d | 672 | IN CONST CHAR16 *String,\r |
a405b86d | 673 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r |
674 | )\r | |
675 | {\r | |
676 | CONST CHAR16 *Walker;\r | |
677 | CONST CHAR16 *LineStart;\r | |
733f138d | 678 | CHAR16 *StringCopy;\r |
a405b86d | 679 | CHAR16 TempChar;\r |
680 | \r | |
733f138d | 681 | StringCopy = NULL;\r |
682 | StringCopy = StrnCatGrow(&StringCopy, NULL, String, 0);\r | |
683 | if (StringCopy == NULL) {\r | |
684 | return (EFI_OUT_OF_RESOURCES);\r | |
685 | }\r | |
686 | \r | |
687 | for ( Walker = StringCopy\r | |
688 | , LineStart = StringCopy\r | |
a405b86d | 689 | ; Walker != NULL && *Walker != CHAR_NULL\r |
690 | ; Walker++\r | |
691 | ){\r | |
692 | switch (*Walker) {\r | |
693 | case (CHAR_BACKSPACE):\r | |
694 | if (ConsoleInfo->OurConOut.Mode->CursorColumn > 0) {\r | |
695 | ConsoleInfo->OurConOut.Mode->CursorColumn--;\r | |
696 | }\r | |
697 | break;\r | |
698 | case (CHAR_LINEFEED):\r | |
699 | //\r | |
700 | // add a temp NULL terminator\r | |
701 | //\r | |
702 | TempChar = *(Walker + 1);\r | |
703 | *((CHAR16*)(Walker+1)) = CHAR_NULL;\r | |
704 | \r | |
705 | //\r | |
706 | // output the string\r | |
707 | //\r | |
708 | ConsoleLoggerOutputStringSplit (LineStart, ConsoleInfo);\r | |
709 | \r | |
710 | //\r | |
711 | // restore the temp NULL terminator to it's original character\r | |
712 | //\r | |
713 | *((CHAR16*)(Walker+1)) = TempChar;\r | |
714 | \r | |
715 | //\r | |
716 | // Update LineStart Variable\r | |
717 | //\r | |
718 | LineStart = Walker + 1;\r | |
719 | \r | |
720 | //\r | |
721 | // increment row count\r | |
722 | //\r | |
723 | ShellInfoObject.ConsoleInfo->RowCounter++;\r | |
724 | ConsoleInfo->OurConOut.Mode->CursorRow++;\r | |
725 | \r | |
726 | break;\r | |
727 | case (CHAR_CARRIAGE_RETURN):\r | |
728 | //\r | |
729 | // Move the cursor to the beginning of the current row.\r | |
730 | //\r | |
731 | ConsoleInfo->OurConOut.Mode->CursorColumn = 0;\r | |
732 | break;\r | |
733 | default:\r | |
734 | //\r | |
735 | // increment column count\r | |
736 | //\r | |
737 | ConsoleInfo->OurConOut.Mode->CursorColumn++;\r | |
738 | //\r | |
739 | // check if that is the last column\r | |
740 | //\r | |
a49f6a2f | 741 | if ((INTN)ConsoleInfo->ColsPerScreen == ConsoleInfo->OurConOut.Mode->CursorColumn + 1) {\r |
a405b86d | 742 | //\r |
743 | // output a line similar to the linefeed character.\r | |
744 | //\r | |
745 | \r | |
746 | //\r | |
747 | // add a temp NULL terminator\r | |
748 | //\r | |
749 | TempChar = *(Walker + 1);\r | |
750 | *((CHAR16*)(Walker+1)) = CHAR_NULL;\r | |
751 | \r | |
752 | //\r | |
753 | // output the string\r | |
754 | //\r | |
755 | ConsoleLoggerOutputStringSplit (LineStart, ConsoleInfo);\r | |
756 | \r | |
757 | //\r | |
758 | // restore the temp NULL terminator to it's original character\r | |
759 | //\r | |
760 | *((CHAR16*)(Walker+1)) = TempChar;\r | |
761 | \r | |
762 | //\r | |
763 | // Update LineStart Variable\r | |
764 | //\r | |
a49f6a2f | 765 | LineStart = Walker + 1;\r |
a405b86d | 766 | \r |
767 | //\r | |
768 | // increment row count and zero the column\r | |
769 | //\r | |
770 | ShellInfoObject.ConsoleInfo->RowCounter++;\r | |
771 | ConsoleInfo->OurConOut.Mode->CursorRow++;\r | |
772 | ConsoleInfo->OurConOut.Mode->CursorColumn = 0;\r | |
773 | } // last column on line\r | |
774 | break;\r | |
775 | } // switch for character\r | |
776 | \r | |
777 | //\r | |
778 | // check if that was the last printable row. If yes handle PageBreak mode\r | |
779 | //\r | |
780 | if ((ConsoleInfo->RowsPerScreen) -1 == ShellInfoObject.ConsoleInfo->RowCounter) {\r | |
781 | if (EFI_ERROR(ConsoleLoggerDoPageBreak())) {\r | |
782 | //\r | |
783 | // We got an error which means 'break' and halt the printing\r | |
784 | //\r | |
733f138d | 785 | SHELL_FREE_NON_NULL(StringCopy);\r |
a405b86d | 786 | return (EFI_DEVICE_ERROR);\r |
787 | }\r | |
788 | }\r | |
789 | } // for loop\r | |
790 | \r | |
791 | if (LineStart != NULL && *LineStart != CHAR_NULL) {\r | |
792 | ConsoleLoggerOutputStringSplit (LineStart, ConsoleInfo);\r | |
793 | }\r | |
794 | \r | |
733f138d | 795 | SHELL_FREE_NON_NULL(StringCopy);\r |
a405b86d | 796 | return (EFI_SUCCESS);\r |
797 | }\r | |
798 | \r | |
799 | /**\r | |
800 | Write a Unicode string to the output device.\r | |
801 | \r | |
802 | @param[in] This Protocol instance pointer.\r | |
803 | @param[in] WString The NULL-terminated Unicode string to be displayed on the output\r | |
804 | device(s). All output devices must also support the Unicode\r | |
805 | drawing defined in this file.\r | |
806 | @retval EFI_SUCCESS The string was output to the device.\r | |
807 | @retval EFI_DEVICE_ERROR The device reported an error while attempting to output\r | |
808 | the text.\r | |
809 | @retval EFI_UNSUPPORTED The output device's mode is not currently in a\r | |
810 | defined text mode.\r | |
811 | @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the\r | |
812 | characters in the Unicode string could not be\r | |
813 | rendered and were skipped.\r | |
814 | **/\r | |
815 | EFI_STATUS\r | |
816 | EFIAPI\r | |
817 | ConsoleLoggerOutputString (\r | |
818 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r | |
819 | IN CHAR16 *WString\r | |
820 | )\r | |
821 | {\r | |
31c2a2c7 RN |
822 | EFI_STATUS Status;\r |
823 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r | |
824 | EFI_KEY_DATA KeyData;\r | |
825 | UINTN EventIndex;\r | |
826 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r | |
827 | \r | |
a405b86d | 828 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r |
733f138d | 829 | if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r |
830 | return (EFI_UNSUPPORTED);\r | |
831 | }\r | |
a405b86d | 832 | ASSERT(ShellInfoObject.ConsoleInfo == ConsoleInfo);\r |
31c2a2c7 RN |
833 | \r |
834 | Status = gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r | |
835 | if (!EFI_ERROR (Status)) {\r | |
836 | while (ShellInfoObject.HaltOutput) {\r | |
837 | \r | |
838 | ShellInfoObject.HaltOutput = FALSE;\r | |
839 | //\r | |
840 | // just get some key\r | |
841 | //\r | |
842 | Status = gBS->WaitForEvent (1, &TxtInEx->WaitForKeyEx, &EventIndex);\r | |
843 | ASSERT_EFI_ERROR (Status);\r | |
844 | Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData);\r | |
8e4a89a3 JC |
845 | if (EFI_ERROR(Status)) {\r |
846 | break;\r | |
847 | }\r | |
31c2a2c7 RN |
848 | \r |
849 | if ((KeyData.Key.UnicodeChar == L's') && (KeyData.Key.ScanCode == SCAN_NULL) &&\r | |
850 | ((KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED)) ||\r | |
851 | (KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED))\r | |
852 | )\r | |
853 | ) {\r | |
854 | ShellInfoObject.HaltOutput = TRUE;\r | |
855 | }\r | |
856 | }\r | |
a49f6a2f | 857 | }\r |
31c2a2c7 | 858 | \r |
a405b86d | 859 | if (!ShellInfoObject.ConsoleInfo->Enabled) {\r |
860 | return (EFI_DEVICE_ERROR);\r | |
861 | } else if (ShellInfoObject.PageBreakEnabled) {\r | |
862 | return (ConsoleLoggerPrintWithPageBreak(WString, ConsoleInfo));\r | |
863 | } else {\r | |
864 | return (ConsoleLoggerOutputStringSplit(WString, ConsoleInfo));\r | |
865 | }\r | |
866 | }\r | |
867 | \r | |
868 | /**\r | |
869 | Verifies that all characters in a Unicode string can be output to the\r | |
870 | target device.\r | |
871 | \r | |
872 | @param[in] This Protocol instance pointer.\r | |
873 | @param[in] WString The NULL-terminated Unicode string to be examined for the output\r | |
874 | device(s).\r | |
875 | \r | |
876 | @retval EFI_SUCCESS The device(s) are capable of rendering the output string.\r | |
877 | @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be\r | |
878 | rendered by one or more of the output devices mapped\r | |
879 | by the EFI handle.\r | |
880 | \r | |
881 | **/\r | |
882 | EFI_STATUS\r | |
883 | EFIAPI\r | |
884 | ConsoleLoggerTestString (\r | |
885 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r | |
886 | IN CHAR16 *WString\r | |
887 | )\r | |
888 | {\r | |
889 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r | |
890 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r | |
891 | //\r | |
892 | // Forward the request to the original ConOut\r | |
893 | //\r | |
894 | return (ConsoleInfo->OldConOut->TestString (ConsoleInfo->OldConOut, WString));\r | |
895 | }\r | |
896 | \r | |
897 | /**\r | |
898 | Returns information for an available text mode that the output device(s)\r | |
899 | supports.\r | |
900 | \r | |
901 | @param[in] This Protocol instance pointer.\r | |
902 | @param[in] ModeNumber The mode number to return information on.\r | |
903 | @param[out] Columns Upon return, the number of columns in the selected geometry\r | |
904 | @param[out] Rows Upon return, the number of rows in the selected geometry\r | |
905 | \r | |
906 | @retval EFI_SUCCESS The requested mode information was returned.\r | |
907 | @retval EFI_DEVICE_ERROR The device had an error and could not\r | |
908 | complete the request.\r | |
909 | @retval EFI_UNSUPPORTED The mode number was not valid.\r | |
910 | **/\r | |
911 | EFI_STATUS\r | |
912 | EFIAPI\r | |
913 | ConsoleLoggerQueryMode (\r | |
914 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r | |
915 | IN UINTN ModeNumber,\r | |
916 | OUT UINTN *Columns,\r | |
917 | OUT UINTN *Rows\r | |
918 | )\r | |
919 | {\r | |
920 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r | |
921 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r | |
922 | //\r | |
923 | // Forward the request to the original ConOut\r | |
924 | //\r | |
925 | return (ConsoleInfo->OldConOut->QueryMode (\r | |
926 | ConsoleInfo->OldConOut,\r | |
927 | ModeNumber,\r | |
928 | Columns,\r | |
929 | Rows\r | |
930 | ));\r | |
931 | }\r | |
932 | \r | |
933 | /**\r | |
934 | Sets the output device(s) to a specified mode.\r | |
935 | \r | |
936 | @param[in] This Protocol instance pointer.\r | |
937 | @param[in] ModeNumber The mode number to set.\r | |
938 | \r | |
939 | \r | |
940 | @retval EFI_SUCCESS The requested text mode was set.\r | |
941 | @retval EFI_DEVICE_ERROR The device had an error and\r | |
942 | could not complete the request.\r | |
943 | @retval EFI_UNSUPPORTED The mode number was not valid.\r | |
944 | **/\r | |
945 | EFI_STATUS\r | |
946 | EFIAPI\r | |
947 | ConsoleLoggerSetMode (\r | |
733f138d | 948 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r |
949 | IN UINTN ModeNumber\r | |
a405b86d | 950 | )\r |
951 | {\r | |
952 | EFI_STATUS Status;\r | |
953 | \r | |
954 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r | |
955 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r | |
956 | \r | |
957 | //\r | |
958 | // Forward the request to the original ConOut\r | |
959 | //\r | |
960 | Status = ConsoleInfo->OldConOut->SetMode (ConsoleInfo->OldConOut, ModeNumber);\r | |
961 | \r | |
962 | //\r | |
963 | // Check that the buffers are still correct for logging\r | |
964 | //\r | |
965 | if (!EFI_ERROR (Status)) {\r | |
733f138d | 966 | ConsoleInfo->OurConOut.Mode = gST->ConOut->Mode;\r |
a405b86d | 967 | ConsoleLoggerResetBuffers(ConsoleInfo);\r |
968 | }\r | |
969 | \r | |
970 | return Status;\r | |
971 | }\r | |
972 | \r | |
973 | /**\r | |
974 | Sets the background and foreground colors for the OutputString () and\r | |
975 | ClearScreen () functions.\r | |
976 | \r | |
977 | @param[in] This Protocol instance pointer.\r | |
978 | @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and\r | |
979 | bits 4..6 are the background color. All other bits are undefined\r | |
980 | and must be zero. The valid Attributes are defined in this file.\r | |
981 | \r | |
982 | @retval EFI_SUCCESS The attribute was set.\r | |
983 | @retval EFI_DEVICE_ERROR The device had an error and\r | |
984 | could not complete the request.\r | |
985 | @retval EFI_UNSUPPORTED The attribute requested is not defined.\r | |
986 | \r | |
987 | **/\r | |
988 | EFI_STATUS\r | |
989 | EFIAPI\r | |
990 | ConsoleLoggerSetAttribute (\r | |
991 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r | |
992 | IN UINTN Attribute\r | |
993 | )\r | |
994 | {\r | |
995 | EFI_STATUS Status;\r | |
996 | \r | |
997 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r | |
998 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r | |
999 | \r | |
1000 | //\r | |
1001 | // Forward the request to the original ConOut\r | |
1002 | //\r | |
1003 | Status = ConsoleInfo->OldConOut->SetAttribute (ConsoleInfo->OldConOut, Attribute);\r | |
1004 | \r | |
1005 | //\r | |
1006 | // Record console output history\r | |
1007 | //\r | |
1008 | if (!EFI_ERROR (Status)) {\r | |
1009 | ConsoleInfo->HistoryMode.Attribute = (INT32) Attribute;\r | |
1010 | }\r | |
1011 | \r | |
1012 | return Status;\r | |
1013 | }\r | |
1014 | \r | |
1015 | /**\r | |
1016 | Clears the output device(s) display to the currently selected background\r | |
1017 | color.\r | |
1018 | \r | |
1019 | @param[in] This Protocol instance pointer.\r | |
1020 | \r | |
1021 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1022 | @retval EFI_DEVICE_ERROR The device had an error and\r | |
1023 | could not complete the request.\r | |
1024 | @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r | |
1025 | **/\r | |
1026 | EFI_STATUS\r | |
1027 | EFIAPI\r | |
1028 | ConsoleLoggerClearScreen (\r | |
1029 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r | |
1030 | )\r | |
1031 | {\r | |
1032 | EFI_STATUS Status;\r | |
1033 | CHAR16 *Screen;\r | |
1034 | INT32 *Attributes;\r | |
1035 | UINTN Row;\r | |
1036 | UINTN Column;\r | |
733f138d | 1037 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r |
a405b86d | 1038 | \r |
733f138d | 1039 | if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r |
1040 | return (EFI_UNSUPPORTED);\r | |
1041 | }\r | |
a405b86d | 1042 | \r |
a405b86d | 1043 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r |
1044 | \r | |
1045 | //\r | |
1046 | // Forward the request to the original ConOut\r | |
1047 | //\r | |
1048 | Status = ConsoleInfo->OldConOut->ClearScreen (ConsoleInfo->OldConOut);\r | |
1049 | \r | |
1050 | //\r | |
1051 | // Record console output history\r | |
1052 | //\r | |
1053 | if (!EFI_ERROR (Status)) {\r | |
1df5c64c | 1054 | Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->CurrentStartRow];\r |
a405b86d | 1055 | Attributes = &ConsoleInfo->Attributes[ConsoleInfo->ColsPerScreen * ConsoleInfo->CurrentStartRow];\r |
1056 | for ( Row = ConsoleInfo->OriginalStartRow\r | |
1057 | ; Row < (ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount)\r | |
1058 | ; Row++\r | |
1059 | ){\r | |
1060 | for ( Column = 0\r | |
1061 | ; Column < ConsoleInfo->ColsPerScreen\r | |
1062 | ; Column++\r | |
1063 | , Screen++\r | |
1064 | , Attributes++\r | |
1065 | ){\r | |
1066 | *Screen = L' ';\r | |
1067 | *Attributes = ConsoleInfo->OldConOut->Mode->Attribute;\r | |
1068 | }\r | |
1069 | //\r | |
1070 | // Skip the NULL on each column end in text buffer only\r | |
1071 | //\r | |
1df5c64c | 1072 | Screen += 2;\r |
a405b86d | 1073 | }\r |
1074 | ConsoleInfo->HistoryMode.CursorColumn = 0;\r | |
1075 | ConsoleInfo->HistoryMode.CursorRow = 0;\r | |
1076 | }\r | |
1077 | \r | |
1078 | return Status;\r | |
1079 | }\r | |
1080 | \r | |
1081 | /**\r | |
1082 | Sets the current coordinates of the cursor position\r | |
1083 | \r | |
1084 | @param[in] This Protocol instance pointer.\r | |
1085 | @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode\r | |
1086 | @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode\r | |
1087 | \r | |
1088 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1089 | @retval EFI_DEVICE_ERROR The device had an error and\r | |
1090 | could not complete the request.\r | |
1091 | @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the\r | |
1092 | cursor position is invalid for the current mode.\r | |
1093 | **/\r | |
1094 | EFI_STATUS\r | |
1095 | EFIAPI\r | |
1096 | ConsoleLoggerSetCursorPosition (\r | |
1097 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r | |
1098 | IN UINTN Column,\r | |
1099 | IN UINTN Row\r | |
1100 | )\r | |
1101 | {\r | |
1102 | EFI_STATUS Status;\r | |
a405b86d | 1103 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r |
733f138d | 1104 | \r |
1105 | if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r | |
1106 | return (EFI_UNSUPPORTED);\r | |
1107 | }\r | |
1108 | \r | |
a405b86d | 1109 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r |
1110 | //\r | |
1111 | // Forward the request to the original ConOut\r | |
1112 | //\r | |
1113 | Status = ConsoleInfo->OldConOut->SetCursorPosition (\r | |
1114 | ConsoleInfo->OldConOut,\r | |
1115 | Column,\r | |
1116 | Row\r | |
1117 | );\r | |
1118 | \r | |
1119 | //\r | |
1120 | // Record console output history\r | |
1121 | //\r | |
1122 | if (!EFI_ERROR (Status)) {\r | |
1123 | ConsoleInfo->HistoryMode.CursorColumn = (INT32)Column;\r | |
1124 | ConsoleInfo->HistoryMode.CursorRow = (INT32)(ConsoleInfo->OriginalStartRow + Row);\r | |
1125 | }\r | |
1126 | \r | |
1127 | return Status;\r | |
1128 | }\r | |
1129 | \r | |
1130 | /**\r | |
1131 | Makes the cursor visible or invisible\r | |
1132 | \r | |
1133 | @param[in] This Protocol instance pointer.\r | |
1134 | @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is\r | |
1135 | set to be invisible.\r | |
1136 | \r | |
1137 | @retval EFI_SUCCESS The operation completed successfully.\r | |
1138 | @retval EFI_DEVICE_ERROR The device had an error and could not complete the\r | |
1139 | request, or the device does not support changing\r | |
1140 | the cursor mode.\r | |
1141 | @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r | |
1142 | **/\r | |
1143 | EFI_STATUS\r | |
1144 | EFIAPI\r | |
1145 | ConsoleLoggerEnableCursor (\r | |
1146 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r | |
1147 | IN BOOLEAN Visible\r | |
1148 | )\r | |
1149 | {\r | |
1150 | EFI_STATUS Status;\r | |
1151 | \r | |
1152 | CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r | |
1153 | ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r | |
1154 | //\r | |
1155 | // Forward the request to the original ConOut\r | |
1156 | //\r | |
1157 | Status = ConsoleInfo->OldConOut->EnableCursor (ConsoleInfo->OldConOut, Visible);\r | |
1158 | \r | |
1159 | //\r | |
1160 | // Record console output history\r | |
1161 | //\r | |
1162 | if (!EFI_ERROR (Status)) {\r | |
1163 | ConsoleInfo->HistoryMode.CursorVisible = Visible;\r | |
1164 | }\r | |
1165 | \r | |
1166 | return Status;\r | |
1167 | }\r | |
1168 | \r | |
1169 | /**\r | |
1170 | Function to update and verify that the current buffers are correct.\r | |
1171 | \r | |
1172 | @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r | |
1173 | \r | |
1174 | This will be used when a mode has changed or a reset ocurred to verify all\r | |
1175 | history buffers.\r | |
1176 | **/\r | |
1177 | EFI_STATUS\r | |
1178 | EFIAPI\r | |
1179 | ConsoleLoggerResetBuffers(\r | |
1180 | IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r | |
1181 | )\r | |
1182 | {\r | |
1183 | EFI_STATUS Status;\r | |
1184 | \r | |
1185 | if (ConsoleInfo->Buffer != NULL) {\r | |
1186 | FreePool(ConsoleInfo->Buffer);\r | |
1187 | ConsoleInfo->Buffer = NULL;\r | |
1188 | ConsoleInfo->BufferSize = 0;\r | |
1189 | }\r | |
1190 | if (ConsoleInfo->Attributes != NULL) {\r | |
1191 | FreePool(ConsoleInfo->Attributes);\r | |
1192 | ConsoleInfo->Attributes = NULL;\r | |
1193 | ConsoleInfo->AttribSize = 0;\r | |
1194 | }\r | |
1195 | \r | |
1196 | Status = gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &ConsoleInfo->ColsPerScreen, &ConsoleInfo->RowsPerScreen);\r | |
1197 | if (EFI_ERROR(Status)){\r | |
1198 | return (Status);\r | |
1199 | }\r | |
1200 | \r | |
1201 | ConsoleInfo->BufferSize = (ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount * sizeof(ConsoleInfo->Buffer[0]);\r | |
1202 | ConsoleInfo->AttribSize = ConsoleInfo->ColsPerScreen * ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount * sizeof(ConsoleInfo->Attributes[0]);\r | |
1203 | \r | |
1204 | ConsoleInfo->Buffer = (CHAR16*)AllocateZeroPool(ConsoleInfo->BufferSize);\r | |
1205 | \r | |
1206 | if (ConsoleInfo->Buffer == NULL) {\r | |
1207 | return (EFI_OUT_OF_RESOURCES);\r | |
1208 | }\r | |
1209 | \r | |
1210 | ConsoleInfo->Attributes = (INT32*)AllocateZeroPool(ConsoleInfo->AttribSize);\r | |
1211 | if (ConsoleInfo->Attributes == NULL) {\r | |
1212 | FreePool(ConsoleInfo->Buffer);\r | |
1213 | ConsoleInfo->Buffer = NULL;\r | |
1214 | return (EFI_OUT_OF_RESOURCES);\r | |
1215 | }\r | |
1216 | \r | |
a405b86d | 1217 | CopyMem (&ConsoleInfo->HistoryMode, ConsoleInfo->OldConOut->Mode, sizeof (EFI_SIMPLE_TEXT_OUTPUT_MODE));\r |
1218 | \r | |
1219 | return (EFI_SUCCESS);\r | |
1220 | }\r |