/** @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
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
)\r
{\r
EFI_HOB_GUID_TYPE *GuidHob;\r
- UINT64 *MailboxLocation; \r
+ UINT64 *MailboxLocation;\r
DEBUG_AGENT_MAILBOX *Mailbox;\r
\r
GuidHob = GetFirstGuidHob (&gEfiDebugAgentGuid);\r
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
/**\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
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
//\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
//\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
}\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
// 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
//\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
\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