]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ConsoleLogger.c
Enhance Shell 2.0 to not depend on keyboard driver implementation to fix the "CTRL...
[mirror_edk2.git] / ShellPkg / Application / Shell / ConsoleLogger.c
CommitLineData
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
31c2a2c7 5 Copyright (c) 2009 - 2013, 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
30EFI_STATUS\r
31EFIAPI\r
32ConsoleLoggerInstall(\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
106EFI_STATUS\r
107EFIAPI\r
108ConsoleLoggerUninstall(\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
144EFI_STATUS\r
145EFIAPI\r
146ConsoleLoggerDisplayHistory(\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
220EFI_STATUS\r
221EFIAPI\r
222ConsoleLoggerStopHistory(\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
241EFI_STATUS\r
242EFIAPI\r
243UpdateDisplayFromHistory(\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
392EFI_STATUS\r
393EFIAPI\r
394ConsoleLoggerReset (\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
426EFI_STATUS\r
427EFIAPI\r
428AppendStringToHistory(\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
581EFI_STATUS\r
582EFIAPI\r
583ConsoleLoggerOutputStringSplit(\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
610EFI_STATUS\r
611EFIAPI\r
612ConsoleLoggerDoPageBreak(\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
669EFI_STATUS\r
670EFIAPI\r
671ConsoleLoggerPrintWithPageBreak(\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
815EFI_STATUS\r
816EFIAPI\r
817ConsoleLoggerOutputString (\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
845 ASSERT_EFI_ERROR (Status);\r
846\r
847 if ((KeyData.Key.UnicodeChar == L's') && (KeyData.Key.ScanCode == SCAN_NULL) &&\r
848 ((KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED)) ||\r
849 (KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED))\r
850 )\r
851 ) {\r
852 ShellInfoObject.HaltOutput = TRUE;\r
853 }\r
854 }\r
a49f6a2f 855 }\r
31c2a2c7 856\r
a405b86d 857 if (!ShellInfoObject.ConsoleInfo->Enabled) {\r
858 return (EFI_DEVICE_ERROR);\r
859 } else if (ShellInfoObject.PageBreakEnabled) {\r
860 return (ConsoleLoggerPrintWithPageBreak(WString, ConsoleInfo));\r
861 } else {\r
862 return (ConsoleLoggerOutputStringSplit(WString, ConsoleInfo));\r
863 }\r
864}\r
865\r
866/**\r
867 Verifies that all characters in a Unicode string can be output to the\r
868 target device.\r
869\r
870 @param[in] This Protocol instance pointer.\r
871 @param[in] WString The NULL-terminated Unicode string to be examined for the output\r
872 device(s).\r
873\r
874 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.\r
875 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be\r
876 rendered by one or more of the output devices mapped\r
877 by the EFI handle.\r
878\r
879**/\r
880EFI_STATUS\r
881EFIAPI\r
882ConsoleLoggerTestString (\r
883 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
884 IN CHAR16 *WString\r
885 )\r
886{\r
887 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
888 ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
889 //\r
890 // Forward the request to the original ConOut\r
891 //\r
892 return (ConsoleInfo->OldConOut->TestString (ConsoleInfo->OldConOut, WString));\r
893}\r
894\r
895/**\r
896 Returns information for an available text mode that the output device(s)\r
897 supports.\r
898\r
899 @param[in] This Protocol instance pointer.\r
900 @param[in] ModeNumber The mode number to return information on.\r
901 @param[out] Columns Upon return, the number of columns in the selected geometry\r
902 @param[out] Rows Upon return, the number of rows in the selected geometry\r
903\r
904 @retval EFI_SUCCESS The requested mode information was returned.\r
905 @retval EFI_DEVICE_ERROR The device had an error and could not\r
906 complete the request.\r
907 @retval EFI_UNSUPPORTED The mode number was not valid.\r
908**/\r
909EFI_STATUS\r
910EFIAPI\r
911ConsoleLoggerQueryMode (\r
912 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
913 IN UINTN ModeNumber,\r
914 OUT UINTN *Columns,\r
915 OUT UINTN *Rows\r
916 )\r
917{\r
918 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
919 ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
920 //\r
921 // Forward the request to the original ConOut\r
922 //\r
923 return (ConsoleInfo->OldConOut->QueryMode (\r
924 ConsoleInfo->OldConOut,\r
925 ModeNumber,\r
926 Columns,\r
927 Rows\r
928 ));\r
929}\r
930\r
931/**\r
932 Sets the output device(s) to a specified mode.\r
933\r
934 @param[in] This Protocol instance pointer.\r
935 @param[in] ModeNumber The mode number to set.\r
936\r
937\r
938 @retval EFI_SUCCESS The requested text mode was set.\r
939 @retval EFI_DEVICE_ERROR The device had an error and\r
940 could not complete the request.\r
941 @retval EFI_UNSUPPORTED The mode number was not valid.\r
942**/\r
943EFI_STATUS\r
944EFIAPI\r
945ConsoleLoggerSetMode (\r
733f138d 946 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
947 IN UINTN ModeNumber\r
a405b86d 948 )\r
949{\r
950 EFI_STATUS Status;\r
951\r
952 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
953 ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
954\r
955 //\r
956 // Forward the request to the original ConOut\r
957 //\r
958 Status = ConsoleInfo->OldConOut->SetMode (ConsoleInfo->OldConOut, ModeNumber);\r
959\r
960 //\r
961 // Check that the buffers are still correct for logging\r
962 //\r
963 if (!EFI_ERROR (Status)) {\r
733f138d 964 ConsoleInfo->OurConOut.Mode = gST->ConOut->Mode;\r
a405b86d 965 ConsoleLoggerResetBuffers(ConsoleInfo);\r
966 }\r
967\r
968 return Status;\r
969}\r
970\r
971/**\r
972 Sets the background and foreground colors for the OutputString () and\r
973 ClearScreen () functions.\r
974\r
975 @param[in] This Protocol instance pointer.\r
976 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and\r
977 bits 4..6 are the background color. All other bits are undefined\r
978 and must be zero. The valid Attributes are defined in this file.\r
979\r
980 @retval EFI_SUCCESS The attribute was set.\r
981 @retval EFI_DEVICE_ERROR The device had an error and\r
982 could not complete the request.\r
983 @retval EFI_UNSUPPORTED The attribute requested is not defined.\r
984\r
985**/\r
986EFI_STATUS\r
987EFIAPI\r
988ConsoleLoggerSetAttribute (\r
989 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
990 IN UINTN Attribute\r
991 )\r
992{\r
993 EFI_STATUS Status;\r
994\r
995 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
996 ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
997\r
998 //\r
999 // Forward the request to the original ConOut\r
1000 //\r
1001 Status = ConsoleInfo->OldConOut->SetAttribute (ConsoleInfo->OldConOut, Attribute);\r
1002\r
1003 //\r
1004 // Record console output history\r
1005 //\r
1006 if (!EFI_ERROR (Status)) {\r
1007 ConsoleInfo->HistoryMode.Attribute = (INT32) Attribute;\r
1008 }\r
1009\r
1010 return Status;\r
1011}\r
1012\r
1013/**\r
1014 Clears the output device(s) display to the currently selected background\r
1015 color.\r
1016\r
1017 @param[in] This Protocol instance pointer.\r
1018\r
1019 @retval EFI_SUCCESS The operation completed successfully.\r
1020 @retval EFI_DEVICE_ERROR The device had an error and\r
1021 could not complete the request.\r
1022 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
1023**/\r
1024EFI_STATUS\r
1025EFIAPI\r
1026ConsoleLoggerClearScreen (\r
1027 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
1028 )\r
1029{\r
1030 EFI_STATUS Status;\r
1031 CHAR16 *Screen;\r
1032 INT32 *Attributes;\r
1033 UINTN Row;\r
1034 UINTN Column;\r
733f138d 1035 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
a405b86d 1036\r
733f138d 1037 if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r
1038 return (EFI_UNSUPPORTED);\r
1039 }\r
a405b86d 1040\r
a405b86d 1041 ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
1042\r
1043 //\r
1044 // Forward the request to the original ConOut\r
1045 //\r
1046 Status = ConsoleInfo->OldConOut->ClearScreen (ConsoleInfo->OldConOut);\r
1047\r
1048 //\r
1049 // Record console output history\r
1050 //\r
1051 if (!EFI_ERROR (Status)) {\r
1df5c64c 1052 Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->CurrentStartRow];\r
a405b86d 1053 Attributes = &ConsoleInfo->Attributes[ConsoleInfo->ColsPerScreen * ConsoleInfo->CurrentStartRow];\r
1054 for ( Row = ConsoleInfo->OriginalStartRow\r
1055 ; Row < (ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount)\r
1056 ; Row++\r
1057 ){\r
1058 for ( Column = 0\r
1059 ; Column < ConsoleInfo->ColsPerScreen\r
1060 ; Column++\r
1061 , Screen++\r
1062 , Attributes++\r
1063 ){\r
1064 *Screen = L' ';\r
1065 *Attributes = ConsoleInfo->OldConOut->Mode->Attribute;\r
1066 }\r
1067 //\r
1068 // Skip the NULL on each column end in text buffer only\r
1069 //\r
1df5c64c 1070 Screen += 2;\r
a405b86d 1071 }\r
1072 ConsoleInfo->HistoryMode.CursorColumn = 0;\r
1073 ConsoleInfo->HistoryMode.CursorRow = 0;\r
1074 }\r
1075\r
1076 return Status;\r
1077}\r
1078\r
1079/**\r
1080 Sets the current coordinates of the cursor position\r
1081\r
1082 @param[in] This Protocol instance pointer.\r
1083 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode\r
1084 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode\r
1085\r
1086 @retval EFI_SUCCESS The operation completed successfully.\r
1087 @retval EFI_DEVICE_ERROR The device had an error and\r
1088 could not complete the request.\r
1089 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the\r
1090 cursor position is invalid for the current mode.\r
1091**/\r
1092EFI_STATUS\r
1093EFIAPI\r
1094ConsoleLoggerSetCursorPosition (\r
1095 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1096 IN UINTN Column,\r
1097 IN UINTN Row\r
1098 )\r
1099{\r
1100 EFI_STATUS Status;\r
a405b86d 1101 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
733f138d 1102\r
1103 if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r
1104 return (EFI_UNSUPPORTED);\r
1105 }\r
1106\r
a405b86d 1107 ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
1108 //\r
1109 // Forward the request to the original ConOut\r
1110 //\r
1111 Status = ConsoleInfo->OldConOut->SetCursorPosition (\r
1112 ConsoleInfo->OldConOut,\r
1113 Column,\r
1114 Row\r
1115 );\r
1116\r
1117 //\r
1118 // Record console output history\r
1119 //\r
1120 if (!EFI_ERROR (Status)) {\r
1121 ConsoleInfo->HistoryMode.CursorColumn = (INT32)Column;\r
1122 ConsoleInfo->HistoryMode.CursorRow = (INT32)(ConsoleInfo->OriginalStartRow + Row);\r
1123 }\r
1124\r
1125 return Status;\r
1126}\r
1127\r
1128/**\r
1129 Makes the cursor visible or invisible\r
1130\r
1131 @param[in] This Protocol instance pointer.\r
1132 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is\r
1133 set to be invisible.\r
1134\r
1135 @retval EFI_SUCCESS The operation completed successfully.\r
1136 @retval EFI_DEVICE_ERROR The device had an error and could not complete the\r
1137 request, or the device does not support changing\r
1138 the cursor mode.\r
1139 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
1140**/\r
1141EFI_STATUS\r
1142EFIAPI\r
1143ConsoleLoggerEnableCursor (\r
1144 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
1145 IN BOOLEAN Visible\r
1146 )\r
1147{\r
1148 EFI_STATUS Status;\r
1149\r
1150 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
1151 ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
1152 //\r
1153 // Forward the request to the original ConOut\r
1154 //\r
1155 Status = ConsoleInfo->OldConOut->EnableCursor (ConsoleInfo->OldConOut, Visible);\r
1156\r
1157 //\r
1158 // Record console output history\r
1159 //\r
1160 if (!EFI_ERROR (Status)) {\r
1161 ConsoleInfo->HistoryMode.CursorVisible = Visible;\r
1162 }\r
1163\r
1164 return Status;\r
1165}\r
1166\r
1167/**\r
1168 Function to update and verify that the current buffers are correct.\r
1169\r
1170 @param[in] ConsoleInfo The pointer to the instance of the console logger information.\r
1171\r
1172 This will be used when a mode has changed or a reset ocurred to verify all\r
1173 history buffers.\r
1174**/\r
1175EFI_STATUS\r
1176EFIAPI\r
1177ConsoleLoggerResetBuffers(\r
1178 IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
1179 )\r
1180{\r
1181 EFI_STATUS Status;\r
1182\r
1183 if (ConsoleInfo->Buffer != NULL) {\r
1184 FreePool(ConsoleInfo->Buffer);\r
1185 ConsoleInfo->Buffer = NULL;\r
1186 ConsoleInfo->BufferSize = 0;\r
1187 }\r
1188 if (ConsoleInfo->Attributes != NULL) {\r
1189 FreePool(ConsoleInfo->Attributes);\r
1190 ConsoleInfo->Attributes = NULL;\r
1191 ConsoleInfo->AttribSize = 0;\r
1192 }\r
1193\r
1194 Status = gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &ConsoleInfo->ColsPerScreen, &ConsoleInfo->RowsPerScreen);\r
1195 if (EFI_ERROR(Status)){\r
1196 return (Status);\r
1197 }\r
1198\r
1199 ConsoleInfo->BufferSize = (ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount * sizeof(ConsoleInfo->Buffer[0]);\r
1200 ConsoleInfo->AttribSize = ConsoleInfo->ColsPerScreen * ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount * sizeof(ConsoleInfo->Attributes[0]);\r
1201\r
1202 ConsoleInfo->Buffer = (CHAR16*)AllocateZeroPool(ConsoleInfo->BufferSize);\r
1203\r
1204 if (ConsoleInfo->Buffer == NULL) {\r
1205 return (EFI_OUT_OF_RESOURCES);\r
1206 }\r
1207\r
1208 ConsoleInfo->Attributes = (INT32*)AllocateZeroPool(ConsoleInfo->AttribSize);\r
1209 if (ConsoleInfo->Attributes == NULL) {\r
1210 FreePool(ConsoleInfo->Buffer);\r
1211 ConsoleInfo->Buffer = NULL;\r
1212 return (EFI_OUT_OF_RESOURCES);\r
1213 }\r
1214\r
a405b86d 1215 CopyMem (&ConsoleInfo->HistoryMode, ConsoleInfo->OldConOut->Mode, sizeof (EFI_SIMPLE_TEXT_OUTPUT_MODE));\r
1216\r
1217 return (EFI_SUCCESS);\r
1218}\r