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