]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
SourceLevelDebugPkg: Apply uncrustify changes
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / SmmDebugAgent / SmmDebugAgentLib.c
index 03a88e62517b7ffd529a0a0c4e55ef79d355978a..f49a592d276292b1f7a9f2f9e240f546099a9467 100644 (file)
@@ -1,32 +1,26 @@
 /** @file\r
-  Debug Agent library implementition.\r
+  Debug Agent library implementation.\r
 \r
   Copyright (c) 2010 - 2018, 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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "SmmDebugAgentLib.h"\r
 \r
-DEBUG_AGENT_MAILBOX         *mMailboxPointer = NULL;\r
-DEBUG_AGENT_MAILBOX         mLocalMailbox;\r
-UINTN                       mSavedDebugRegisters[6];\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
+DEBUG_AGENT_MAILBOX       *mMailboxPointer = NULL;\r
+DEBUG_AGENT_MAILBOX       mLocalMailbox;\r
+UINTN                     mSavedDebugRegisters[6];\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
+CHAR8  mWarningMsgIgnoreSmmEntryBreak[] = "Ignore smmentrybreak setting for SMI issued during DXE debugging!\r\n";\r
 \r
 /**\r
   Check if debug agent support multi-processor.\r
@@ -55,8 +49,8 @@ MultiProcessorDebugSupport (
 **/\r
 EFI_STATUS\r
 DebugReadBreakSymbol (\r
-  IN  DEBUG_PORT_HANDLE      Handle,\r
-  OUT UINT8                  *BreakSymbol\r
+  IN  DEBUG_PORT_HANDLE  Handle,\r
+  OUT UINT8              *BreakSymbol\r
   )\r
 {\r
   //\r
@@ -76,16 +70,17 @@ GetMailboxFromHob (
   VOID\r
   )\r
 {\r
-  EFI_HOB_GUID_TYPE        *GuidHob;\r
-  UINT64                   *MailboxLocation;\r
-  DEBUG_AGENT_MAILBOX      *Mailbox;\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+  UINT64               *MailboxLocation;\r
+  DEBUG_AGENT_MAILBOX  *Mailbox;\r
 \r
   GuidHob = GetFirstGuidHob (&gEfiDebugAgentGuid);\r
   if (GuidHob == NULL) {\r
     return NULL;\r
   }\r
-  MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));\r
-  Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
+\r
+  MailboxLocation = (UINT64 *)(GET_GUID_HOB_DATA (GuidHob));\r
+  Mailbox         = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
   VerifyMailboxChecksum (Mailbox);\r
 \r
   return Mailbox;\r
@@ -117,7 +112,7 @@ GetDebugPortHandle (
   VOID\r
   )\r
 {\r
-  return (DEBUG_PORT_HANDLE) (UINTN)(GetMailboxPointer()->DebugPortHandle);\r
+  return (DEBUG_PORT_HANDLE)(UINTN)(GetMailboxPointer ()->DebugPortHandle);\r
 }\r
 \r
 /**\r
@@ -158,13 +153,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
@@ -181,212 +176,222 @@ VOID
 EFIAPI\r
 InitializeDebugAgent (\r
   IN UINT32                InitFlag,\r
-  IN VOID                  *Context, OPTIONAL\r
+  IN VOID                  *Context  OPTIONAL,\r
   IN DEBUG_AGENT_CONTINUE  Function  OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  UINT64                        DebugPortHandle;\r
-  IA32_IDT_GATE_DESCRIPTOR      IdtEntry[33];\r
-  IA32_DESCRIPTOR               IdtDescriptor;\r
-  IA32_DESCRIPTOR               *Ia32Idtr;\r
-  IA32_IDT_ENTRY                *Ia32IdtEntry;\r
-  IA32_DESCRIPTOR               Idtr;\r
-  UINT16                        IdtEntryCount;\r
-  DEBUG_AGENT_MAILBOX           *Mailbox;\r
-  UINT64                        *MailboxLocation;\r
-  UINT32                        DebugTimerFrequency;\r
+  EFI_STATUS                Status;\r
+  UINT64                    DebugPortHandle;\r
+  IA32_IDT_GATE_DESCRIPTOR  IdtEntry[33];\r
+  IA32_DESCRIPTOR           IdtDescriptor;\r
+  IA32_DESCRIPTOR           *Ia32Idtr;\r
+  IA32_IDT_ENTRY            *Ia32IdtEntry;\r
+  IA32_DESCRIPTOR           Idtr;\r
+  UINT16                    IdtEntryCount;\r
+  DEBUG_AGENT_MAILBOX       *Mailbox;\r
+  UINT64                    *MailboxLocation;\r
+  UINT32                    DebugTimerFrequency;\r
 \r
   switch (InitFlag) {\r
-  case DEBUG_AGENT_INIT_SMM:\r
-    //\r
-    // Install configuration table for persisted vector handoff info\r
-    //\r
-    Status = gSmst->SmmInstallConfigurationTable (\r
-                      gSmst,\r
-                      &gEfiVectorHandoffTableGuid,\r
-                      (VOID *) &mVectorHandoffInfoDebugAgent[0],\r
-                      sizeof (EFI_VECTOR_HANDOFF_INFO) * mVectorHandoffInfoCount\r
-                      );\r
-    if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));\r
-      CpuDeadLoop ();\r
-    }\r
-    //\r
-    // Check if Debug Agent initialized in DXE phase\r
-    //\r
-    Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &Mailbox);\r
-    if (Status == EFI_SUCCESS && Mailbox != NULL) {\r
-      VerifyMailboxChecksum (Mailbox);\r
-      mMailboxPointer = Mailbox;\r
-      break;\r
-    }\r
-    //\r
-    // Check if Debug Agent initialized in SEC/PEI phase\r
-    //\r
-    Mailbox = GetMailboxFromHob ();\r
-    if (Mailbox != NULL) {\r
-      mMailboxPointer = Mailbox;\r
-      break;\r
-    }\r
-    //\r
-    // Debug Agent was not initialized before, use the local mailbox.\r
-    //\r
-    ZeroMem (&mLocalMailbox, sizeof (DEBUG_AGENT_MAILBOX));\r
-    Mailbox = &mLocalMailbox;\r
-    //\r
-    // Save original IDT entries\r
-    //\r
-    AsmReadIdtr (&IdtDescriptor);\r
-    CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR));\r
-    //\r
-    // Initialized Debug Agent\r
-    //\r
-    InitializeDebugIdt ();\r
-    //\r
-    // Initialize Debug Timer hardware and save its frequency\r
-    //\r
-    InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
-    UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
-\r
-    DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle, NULL);\r
-    UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);\r
-    mMailboxPointer = Mailbox;\r
-    //\r
-    // Trigger one software interrupt to inform HOST\r
-    //\r
-    TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);\r
-\r
-    SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);\r
-    //\r
-    // Memory has been ready\r
-    //\r
-    if (IsHostAttached ()) {\r
+    case DEBUG_AGENT_INIT_SMM:\r
       //\r
-      // Trigger one software interrupt to inform HOST\r
+      // Install configuration table for persisted vector handoff info\r
+      //\r
+      Status = gSmst->SmmInstallConfigurationTable (\r
+                        gSmst,\r
+                        &gEfiVectorHandoffTableGuid,\r
+                        (VOID *)&mVectorHandoffInfoDebugAgent[0],\r
+                        sizeof (EFI_VECTOR_HANDOFF_INFO) * mVectorHandoffInfoCount\r
+                        );\r
+      if (EFI_ERROR (Status)) {\r
+        DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));\r
+        CpuDeadLoop ();\r
+      }\r
+\r
+      //\r
+      // Check if Debug Agent initialized in DXE phase\r
+      //\r
+      Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **)&Mailbox);\r
+      if ((Status == EFI_SUCCESS) && (Mailbox != NULL)) {\r
+        VerifyMailboxChecksum (Mailbox);\r
+        mMailboxPointer = Mailbox;\r
+        break;\r
+      }\r
+\r
+      //\r
+      // Check if Debug Agent initialized in SEC/PEI phase\r
+      //\r
+      Mailbox = GetMailboxFromHob ();\r
+      if (Mailbox != NULL) {\r
+        mMailboxPointer = Mailbox;\r
+        break;\r
+      }\r
+\r
+      //\r
+      // Debug Agent was not initialized before, use the local mailbox.\r
       //\r
-      TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);\r
-    }\r
-    //\r
-    // Find and report PE/COFF image info to HOST\r
-    //\r
-    FindAndReportModuleImageInfo (SIZE_4KB);\r
-    //\r
-    // Restore saved IDT entries\r
-    //\r
-    CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR));\r
-\r
-    break;\r
-\r
-  case DEBUG_AGENT_INIT_ENTER_SMI:\r
-    SaveDebugRegister ();\r
-    if (!mSmmDebugIdtInitFlag) {\r
+      ZeroMem (&mLocalMailbox, sizeof (DEBUG_AGENT_MAILBOX));\r
+      Mailbox = &mLocalMailbox;\r
       //\r
-      // We only need to initialize Debug IDT table at first SMI entry\r
-      // after SMM relocation.\r
+      // Save original IDT entries\r
+      //\r
+      AsmReadIdtr (&IdtDescriptor);\r
+      CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));\r
+      //\r
+      // Initialized Debug Agent\r
       //\r
       InitializeDebugIdt ();\r
-      mSmmDebugIdtInitFlag = TRUE;\r
-    }\r
-    //\r
-    // Check if CPU APIC Timer is working, otherwise initialize it.\r
-    //\r
-    InitializeLocalApicSoftwareEnable (TRUE);\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
-      // any break points set in SMM, set Skip Breakpoint flag\r
+      // Initialize Debug Timer hardware and save its frequency\r
+      //\r
+      InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
+      UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
+\r
+      DebugPortHandle = (UINT64)(UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE)(UINTN)Mailbox->DebugPortHandle, NULL);\r
+      UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);\r
+      mMailboxPointer = Mailbox;\r
+      //\r
+      // Trigger one software interrupt to inform HOST\r
       //\r
-      mSkipBreakpoint = TRUE;\r
-    }\r
-    if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI) == 1) {\r
-      if (mSkipBreakpoint) {\r
+      TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);\r
+\r
+      SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);\r
+      //\r
+      // Memory has been ready\r
+      //\r
+      if (IsHostAttached ()) {\r
         //\r
-        // Print warning message if ignore smm entry break\r
+        // Trigger one software interrupt to inform HOST\r
         //\r
-        DebugPortWriteBuffer ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle,\r
-                               (UINT8 *)mWarningMsgIgnoreSmmEntryBreak,\r
-                               AsciiStrLen (mWarningMsgIgnoreSmmEntryBreak)\r
-                               );\r
-      } else {\r
+        TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);\r
+      }\r
+\r
+      //\r
+      // Find and report PE/COFF image info to HOST\r
+      //\r
+      FindAndReportModuleImageInfo (SIZE_4KB);\r
+      //\r
+      // Restore saved IDT entries\r
+      //\r
+      CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));\r
+\r
+      break;\r
+\r
+    case DEBUG_AGENT_INIT_ENTER_SMI:\r
+      SaveDebugRegister ();\r
+      if (!mSmmDebugIdtInitFlag) {\r
         //\r
-        // If SMM entry break is set, SMM code will be break at here.\r
+        // We only need to initialize Debug IDT table at first SMI entry\r
+        // after SMM relocation.\r
         //\r
-        CpuBreakpoint ();\r
+        InitializeDebugIdt ();\r
+        mSmmDebugIdtInitFlag = TRUE;\r
       }\r
-    }\r
-    break;\r
-\r
-  case DEBUG_AGENT_INIT_EXIT_SMI:\r
-    Mailbox = GetMailboxPointer ();\r
-    //\r
-    // Clear Skip Breakpoint flag\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
-    if (Context == NULL) {\r
-      DEBUG ((EFI_D_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));\r
-      CpuDeadLoop ();\r
-    } else {\r
-      Ia32Idtr =  (IA32_DESCRIPTOR *) Context;\r
-      Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);\r
-      MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
-                                   ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r
-      mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
-      VerifyMailboxChecksum (mMailboxPointer);\r
+\r
       //\r
-      // Get original IDT address and size.\r
+      // Check if CPU APIC Timer is working, otherwise initialize it.\r
       //\r
-      AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr);\r
-      IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));\r
-      if (IdtEntryCount < 33) {\r
-        Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);\r
-        Idtr.Base  = (UINTN) &mIdtEntryTable;\r
-        ZeroMem (&mIdtEntryTable, Idtr.Limit + 1);\r
-        AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr);\r
+      InitializeLocalApicSoftwareEnable (TRUE);\r
+      GetApicTimerState (&mApicTimerDivisor, &mPeriodicMode, &mVector);\r
+      mTimerCycle = GetApicTimerInitCount ();\r
+      if (!mPeriodicMode || (mTimerCycle == 0)) {\r
+        mApicTimerRestore = TRUE;\r
+        InitializeDebugTimer (NULL, FALSE);\r
       }\r
 \r
-      InitializeDebugIdt ();\r
+      Mailbox = GetMailboxPointer ();\r
+      if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {\r
+        //\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
+\r
+      if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI) == 1) {\r
+        if (mSkipBreakpoint) {\r
+          //\r
+          // Print warning message if ignore smm entry break\r
+          //\r
+          DebugPortWriteBuffer (\r
+            (DEBUG_PORT_HANDLE)(UINTN)Mailbox->DebugPortHandle,\r
+            (UINT8 *)mWarningMsgIgnoreSmmEntryBreak,\r
+            AsciiStrLen (mWarningMsgIgnoreSmmEntryBreak)\r
+            );\r
+        } else {\r
+          //\r
+          // If SMM entry break is set, SMM code will be break at here.\r
+          //\r
+          CpuBreakpoint ();\r
+        }\r
+      }\r
+\r
+      break;\r
+\r
+    case DEBUG_AGENT_INIT_EXIT_SMI:\r
+      Mailbox = GetMailboxPointer ();\r
       //\r
-      // Initialize Debug Timer hardware and save its frequency\r
+      // Clear Skip Breakpoint flag\r
       //\r
-      InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
-      UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
+      mSkipBreakpoint = FALSE;\r
+      RestoreDebugRegister ();\r
       //\r
-      // Enable Debug Timer interrupt and CPU interrupt\r
+      // Restore APIC Timer\r
       //\r
-      SaveAndSetDebugTimerInterrupt (TRUE);\r
-      EnableInterrupts ();\r
+      if (mApicTimerRestore) {\r
+        InitializeApicTimer (mApicTimerDivisor, mTimerCycle, mPeriodicMode, mVector);\r
+        mApicTimerRestore = FALSE;\r
+      }\r
 \r
-      FindAndReportModuleImageInfo (SIZE_4KB);\r
-    }\r
-    break;\r
-\r
-  default:\r
-    //\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
+    case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:\r
+      if (Context == NULL) {\r
+        DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));\r
+        CpuDeadLoop ();\r
+      } else {\r
+        Ia32Idtr        =  (IA32_DESCRIPTOR *)Context;\r
+        Ia32IdtEntry    = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);\r
+        MailboxLocation = (UINT64 *)((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
+                                     ((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r
+        mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);\r
+        VerifyMailboxChecksum (mMailboxPointer);\r
+        //\r
+        // Get original IDT address and size.\r
+        //\r
+        AsmReadIdtr ((IA32_DESCRIPTOR *)&Idtr);\r
+        IdtEntryCount = (UINT16)((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));\r
+        if (IdtEntryCount < 33) {\r
+          Idtr.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);\r
+          Idtr.Base  = (UINTN)&mIdtEntryTable;\r
+          ZeroMem (&mIdtEntryTable, Idtr.Limit + 1);\r
+          AsmWriteIdtr ((IA32_DESCRIPTOR *)&Idtr);\r
+        }\r
+\r
+        InitializeDebugIdt ();\r
+        //\r
+        // Initialize Debug Timer hardware and save its frequency\r
+        //\r
+        InitializeDebugTimer (&DebugTimerFrequency, TRUE);\r
+        UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
+        //\r
+        // Enable Debug Timer interrupt and CPU interrupt\r
+        //\r
+        SaveAndSetDebugTimerInterrupt (TRUE);\r
+        EnableInterrupts ();\r
+\r
+        FindAndReportModuleImageInfo (SIZE_4KB);\r
+      }\r
+\r
+      break;\r
+\r
+    default:\r
+      //\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 ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));\r
+      CpuDeadLoop ();\r
+      break;\r
   }\r
 }\r
-\r