]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ConsoleLogger.c
ShellPkg: Clean up source files
[mirror_edk2.git] / ShellPkg / Application / Shell / ConsoleLogger.c
index 1c5ad7def28aa611b4cc87c15e97503d467c3e5a..07e52f42312f0488122b7787d9049dac557bf4ac 100644 (file)
@@ -1,7 +1,9 @@
 /** @file\r
   Provides interface to shell console logger.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2016 Hewlett-Packard Development Company, L.P.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 **/\r
 \r
-#include "ConsoleLogger.h"\r
 #include "Shell.h"\r
 \r
-STATIC CONST CHAR16                     mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
-\r
 /**\r
   Install our intermediate ConOut into the system table to\r
   keep a log of all the info that is displayed to the user.\r
@@ -30,7 +29,6 @@ STATIC CONST CHAR16                     mCrLfString[3] = { CHAR_CARRIAGE_RETURN,
   @sa InstallProtocolInterface\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerInstall(\r
   IN CONST UINTN ScreensToSave,\r
   OUT CONSOLE_LOGGER_PRIVATE_DATA **ConsoleInfo\r
@@ -93,6 +91,15 @@ ConsoleLoggerInstall(
   gST->ConsoleOutHandle = gImageHandle;\r
   gST->ConOut           = &(*ConsoleInfo)->OurConOut;\r
 \r
+  //\r
+  // Update the CRC32 in the EFI System Table header\r
+  //\r
+  gST->Hdr.CRC32 = 0;\r
+  gBS->CalculateCrc32 (\r
+        (UINT8 *)&gST->Hdr,\r
+        gST->Hdr.HeaderSize,\r
+        &gST->Hdr.CRC32\r
+        );\r
   return (Status);\r
 }\r
 \r
@@ -106,7 +113,6 @@ ConsoleLoggerInstall(
   @return other           The operation failed.  This was from UninstallProtocolInterface.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerUninstall(\r
   IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
   )\r
@@ -128,6 +134,16 @@ ConsoleLoggerUninstall(
   gST->ConsoleOutHandle = ConsoleInfo->OldConHandle;\r
   gST->ConOut = ConsoleInfo->OldConOut;\r
 \r
+  //\r
+  // Update the CRC32 in the EFI System Table header\r
+  //\r
+  gST->Hdr.CRC32 = 0;\r
+  gBS->CalculateCrc32 (\r
+        (UINT8 *)&gST->Hdr,\r
+        gST->Hdr.HeaderSize,\r
+        &gST->Hdr.CRC32\r
+        );\r
+\r
   return (gBS->UninstallProtocolInterface(gImageHandle, &gEfiSimpleTextOutProtocolGuid, (VOID*)&ConsoleInfo->OurConOut));\r
 }\r
 \r
@@ -144,7 +160,6 @@ ConsoleLoggerUninstall(
   @param[in] ConsoleInfo  The pointer to the instance of the console logger information.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerDisplayHistory(\r
   IN CONST BOOLEAN  Forward,\r
   IN CONST UINTN    Rows,\r
@@ -220,7 +235,6 @@ ConsoleLoggerDisplayHistory(
   @sa UpdateDisplayFromHistory\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerStopHistory(\r
   IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
   )\r
@@ -229,6 +243,12 @@ ConsoleLoggerStopHistory(
   if (ConsoleInfo->CurrentStartRow == ConsoleInfo->OriginalStartRow) {\r
     return (EFI_SUCCESS);\r
   }\r
+\r
+  //\r
+  // Clear the screen\r
+  //\r
+  ConsoleInfo->OldConOut->ClearScreen(ConsoleInfo->OldConOut);\r
+\r
   ConsoleInfo->CurrentStartRow = ConsoleInfo->OriginalStartRow;\r
   return (UpdateDisplayFromHistory(ConsoleInfo));\r
 }\r
@@ -241,7 +261,6 @@ ConsoleLoggerStopHistory(
   @return other           The operation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 UpdateDisplayFromHistory(\r
   IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
   )\r
@@ -303,7 +322,7 @@ UpdateDisplayFromHistory(
         //\r
         StringSegmentEndChar = CHAR_NULL;\r
         for ( StringSegmentEnd = StringSegment\r
-            ; StringSegmentEnd != CHAR_NULL\r
+            ; *StringSegmentEnd != CHAR_NULL\r
             ; StringSegmentEnd++\r
             , Column++\r
            ){\r
@@ -412,6 +431,10 @@ ConsoleLoggerReset (
   //\r
   if (!EFI_ERROR (Status)) {\r
     ConsoleLoggerResetBuffers(ConsoleInfo);\r
+    if (ExtendedVerification) {\r
+      ConsoleInfo->OriginalStartRow = 0;\r
+      ConsoleInfo->CurrentStartRow = 0;\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -426,7 +449,6 @@ ConsoleLoggerReset (
   @param[in] ConsoleInfo  The pointer to the instance of the console logger information.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 AppendStringToHistory(\r
   IN CONST CHAR16 *String,\r
   IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
@@ -473,7 +495,7 @@ AppendStringToHistory(
             ; Index < ConsoleInfo->ColsPerScreen\r
             ; Index++\r
            ){\r
-          *(ConsoleInfo->Attributes + (CopySize/sizeof(ConsoleInfo->Attributes)) + Index) = ConsoleInfo->HistoryMode.Attribute;\r
+          *(ConsoleInfo->Attributes + (CopySize/sizeof(ConsoleInfo->Attributes[0])) + Index) = ConsoleInfo->HistoryMode.Attribute;\r
         }\r
 \r
         //\r
@@ -581,7 +603,6 @@ AppendStringToHistory(
                                   rendered and were skipped.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerOutputStringSplit(\r
   IN CONST CHAR16   *String,\r
   IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
@@ -610,7 +631,6 @@ ConsoleLoggerOutputStringSplit(
   @return other         Break was choosen\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerDoPageBreak(\r
   VOID\r
   )\r
@@ -643,6 +663,10 @@ ConsoleLoggerDoPageBreak(
   } else if (*Resp == ShellPromptResponseQuit) {\r
     FreePool(Resp);\r
     ShellInfoObject.ConsoleInfo->Enabled = FALSE;\r
+    //\r
+    // When user wants to quit, the shell should stop running the command.\r
+    //\r
+    gBS->SignalEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);\r
     return (EFI_DEVICE_ERROR);\r
   } else {\r
     ASSERT(FALSE);\r
@@ -665,7 +689,6 @@ ConsoleLoggerDoPageBreak(
                                   rendered and were skipped.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerPrintWithPageBreak(\r
   IN CONST CHAR16   *String,\r
   IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
@@ -817,22 +840,43 @@ ConsoleLoggerOutputString (
   IN  CHAR16                          *WString\r
   )\r
 {\r
-  EFI_INPUT_KEY               Key;\r
-  UINTN                       EventIndex;\r
-  CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;\r
+  EFI_KEY_DATA                      KeyData;\r
+  UINTN                             EventIndex;\r
+  CONSOLE_LOGGER_PRIVATE_DATA       *ConsoleInfo;\r
+\r
   ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);\r
   if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r
     return (EFI_UNSUPPORTED);\r
   }\r
   ASSERT(ShellInfoObject.ConsoleInfo == ConsoleInfo);\r
-  if (ShellInfoObject.HaltOutput) {\r
-    //\r
-    // just get some key\r
-    //\r
-    gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
-    gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-    ShellInfoObject.HaltOutput = FALSE;\r
+\r
+  Status = gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);\r
+  if (!EFI_ERROR (Status)) {\r
+    while (ShellInfoObject.HaltOutput) {\r
+\r
+      ShellInfoObject.HaltOutput = FALSE;\r
+      //\r
+      // just get some key\r
+      //\r
+      Status = gBS->WaitForEvent (1, &TxtInEx->WaitForKeyEx, &EventIndex);\r
+      ASSERT_EFI_ERROR (Status);\r
+      Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData);\r
+      if (EFI_ERROR(Status)) {\r
+        break;\r
+      }\r
+\r
+      if ((KeyData.Key.UnicodeChar == L's') && (KeyData.Key.ScanCode == SCAN_NULL) &&\r
+          ((KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED)) ||\r
+           (KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED))\r
+          )\r
+         ) {\r
+        ShellInfoObject.HaltOutput = TRUE;\r
+      }\r
+    }\r
   }\r
+\r
   if (!ShellInfoObject.ConsoleInfo->Enabled) {\r
     return (EFI_DEVICE_ERROR);\r
   } else if (ShellInfoObject.PageBreakEnabled) {\r
@@ -940,8 +984,11 @@ ConsoleLoggerSetMode (
   // Check that the buffers are still correct for logging\r
   //\r
   if (!EFI_ERROR (Status)) {\r
-    ConsoleInfo->OurConOut.Mode = gST->ConOut->Mode;\r
+    ConsoleInfo->OurConOut.Mode = ConsoleInfo->OldConOut->Mode;\r
     ConsoleLoggerResetBuffers(ConsoleInfo);\r
+    ConsoleInfo->OriginalStartRow = 0;\r
+    ConsoleInfo->CurrentStartRow = 0;\r
+    ConsoleInfo->OurConOut.ClearScreen (&ConsoleInfo->OurConOut);\r
   }\r
 \r
   return Status;\r
@@ -1028,7 +1075,7 @@ ConsoleLoggerClearScreen (
   // Record console output history\r
   //\r
   if (!EFI_ERROR (Status)) {\r
-    Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 1) * ConsoleInfo->CurrentStartRow];\r
+    Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->CurrentStartRow];\r
     Attributes = &ConsoleInfo->Attributes[ConsoleInfo->ColsPerScreen * ConsoleInfo->CurrentStartRow];\r
     for ( Row = ConsoleInfo->OriginalStartRow\r
         ; Row < (ConsoleInfo->RowsPerScreen * ConsoleInfo->ScreenCount)\r
@@ -1046,7 +1093,7 @@ ConsoleLoggerClearScreen (
       //\r
       // Skip the NULL on each column end in text buffer only\r
       //\r
-      Screen++;\r
+      Screen += 2;\r
     }\r
     ConsoleInfo->HistoryMode.CursorColumn = 0;\r
     ConsoleInfo->HistoryMode.CursorRow    = 0;\r
@@ -1152,7 +1199,6 @@ ConsoleLoggerEnableCursor (
   history buffers.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ConsoleLoggerResetBuffers(\r
   IN CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo\r
   )\r