]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
SourceLevelDebugPkg/DebugAgent: Fix various typos
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / SmmDebugAgent / SmmDebugAgentLib.c
index 11afd329fad334c6f572fe0b9f5725dd4158ca54..37b0e8f397593f820dc88592d7711fc432489f17 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
-  Debug Agent library implementition.\r
+  Debug Agent library implementation.\r
 \r
-  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<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
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -20,6 +14,11 @@ UINTN                       mSavedDebugRegisters[6];
 IA32_IDT_GATE_DESCRIPTOR    mIdtEntryTable[33];\r
 BOOLEAN                     mSkipBreakpoint = FALSE;\r
 BOOLEAN                     mSmmDebugIdtInitFlag = FALSE;\r
+BOOLEAN                     mApicTimerRestore = FALSE;\r
+BOOLEAN                     mPeriodicMode;\r
+UINT32                      mTimerCycle;\r
+UINTN                       mApicTimerDivisor;\r
+UINT8                       mVector;\r
 \r
 CHAR8 mWarningMsgIgnoreSmmEntryBreak[] = "Ignore smmentrybreak setting for SMI issued during DXE debugging!\r\n";\r
 \r
@@ -72,7 +71,7 @@ GetMailboxFromHob (
   )\r
 {\r
   EFI_HOB_GUID_TYPE        *GuidHob;\r
-  UINT64                   *MailboxLocation;  \r
+  UINT64                   *MailboxLocation;\r
   DEBUG_AGENT_MAILBOX      *Mailbox;\r
 \r
   GuidHob = GetFirstGuidHob (&gEfiDebugAgentGuid);\r
@@ -82,7 +81,7 @@ GetMailboxFromHob (
   MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));\r
   Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
   VerifyMailboxChecksum (Mailbox);\r
-  \r
+\r
   return Mailbox;\r
 }\r
 \r
@@ -153,13 +152,13 @@ RestoreDebugRegister (
 /**\r
   Initialize debug agent.\r
 \r
-  This function is used to set up debug enviroment for source level debug\r
+  This function is used to set up debug environment for source level debug\r
   in SMM code.\r
 \r
-  If InitFlag is DEBUG_AGENT_INIT_SMM, it will overirde IDT table entries\r
+  If InitFlag is DEBUG_AGENT_INIT_SMM, it will override IDT table entries\r
   and initialize debug port. It will get debug agent Mailbox from GUIDed HOB,\r
   it it exists, debug agent wiil copied it into the local Mailbox in SMM space.\r
-  it will overirde IDT table entries and initialize debug port. Context will be\r
+  it will override IDT table entries and initialize debug port. Context will be\r
   NULL.\r
   If InitFlag is DEBUG_AGENT_INIT_ENTER_SMI, debug agent will save Debug\r
   Registers and get local Mailbox in SMM space. Context will be NULL.\r
@@ -191,8 +190,6 @@ InitializeDebugAgent (
   DEBUG_AGENT_MAILBOX           *Mailbox;\r
   UINT64                        *MailboxLocation;\r
   UINT32                        DebugTimerFrequency;\r
-  BOOLEAN                       PeriodicMode;\r
-  UINTN                         TimerCycle;\r
 \r
   switch (InitFlag) {\r
   case DEBUG_AGENT_INIT_SMM:\r
@@ -221,7 +218,7 @@ InitializeDebugAgent (
     //\r
     // Check if Debug Agent initialized in SEC/PEI phase\r
     //\r
-    Mailbox = GetMailboxFromHob (); \r
+    Mailbox = GetMailboxFromHob ();\r
     if (Mailbox != NULL) {\r
       mMailboxPointer = Mailbox;\r
       break;\r
@@ -234,7 +231,7 @@ InitializeDebugAgent (
     //\r
     // Save original IDT entries\r
     //\r
-    AsmReadIdtr (&IdtDescriptor);      \r
+    AsmReadIdtr (&IdtDescriptor);\r
     CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR));\r
     //\r
     // Initialized Debug Agent\r
@@ -266,11 +263,11 @@ InitializeDebugAgent (
     }\r
     //\r
     // Find and report PE/COFF image info to HOST\r
-    //  \r
+    //\r
     FindAndReportModuleImageInfo (SIZE_4KB);\r
     //\r
     // Restore saved IDT entries\r
-    //     \r
+    //\r
     CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR));\r
 \r
     break;\r
@@ -289,15 +286,16 @@ InitializeDebugAgent (
     // Check if CPU APIC Timer is working, otherwise initialize it.\r
     //\r
     InitializeLocalApicSoftwareEnable (TRUE);\r
-    GetApicTimerState (NULL, &PeriodicMode, NULL);\r
-    TimerCycle = GetApicTimerInitCount ();\r
-    if (!PeriodicMode || TimerCycle == 0) {\r
+    GetApicTimerState (&mApicTimerDivisor, &mPeriodicMode, &mVector);\r
+    mTimerCycle = GetApicTimerInitCount ();\r
+    if (!mPeriodicMode || mTimerCycle == 0) {\r
+      mApicTimerRestore = TRUE;\r
       InitializeDebugTimer (NULL, FALSE);\r
     }\r
     Mailbox = GetMailboxPointer ();\r
     if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {\r
       //\r
-      // If Debug Agent has been communicaton state with HOST, we need skip\r
+      // If Debug Agent has been communication state with HOST, we need skip\r
       // any break points set in SMM, set Skip Breakpoint flag\r
       //\r
       mSkipBreakpoint = TRUE;\r
@@ -327,6 +325,13 @@ InitializeDebugAgent (
     //\r
     mSkipBreakpoint = FALSE;\r
     RestoreDebugRegister ();\r
+    //\r
+    // Restore APIC Timer\r
+    //\r
+    if (mApicTimerRestore) {\r
+      InitializeApicTimer (mApicTimerDivisor, mTimerCycle, mPeriodicMode, mVector);\r
+      mApicTimerRestore = FALSE;\r
+    }\r
     break;\r
 \r
   case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:\r
@@ -370,12 +375,12 @@ InitializeDebugAgent (
 \r
   default:\r
     //\r
-    // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this \r
+    // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this\r
     // Debug Agent library instance.\r
     //\r
     DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));\r
     CpuDeadLoop ();\r
-    break;    \r
+    break;\r
   }\r
 }\r
 \r