]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
1. Add CPU arch type in Mailbox, debug agent will not access HOB if CPU arch changed.
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / SecPeiDebugAgent / SecPeiDebugAgentLib.c
index 828407304f2c090df8c54fab2ae66f8896aaefe7..0132942dea6b7e6cbb9f1fdce727de3c09b0e273 100644 (file)
@@ -174,19 +174,22 @@ GetMailboxPointer (
   MailboxLocationInIdt = GetLocationSavedMailboxPointerInIdtEntry ();\r
   Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInIdt);\r
   //\r
-  // Check if mailbox was setup in PEI firstly, cannot used GetDebugFlag() to \r
-  // get CheckMailboxInHob flag to avoid GetMailboxPointer() nesting.\r
+  // Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() nested\r
   //\r
-  if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1) {\r
-    //\r
-    // If mailbox in IDT entry has already been the final one\r
+  if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1 ||\r
+      Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL) {\r
     //\r
+    // If mailbox was setup in SEC or the current CPU arch is different from the init arch\r
+    // Debug Agent initialized, return the mailbox from IDT entry directly.\r
+    // Otherwise, we need to check the mailbox location saved in GUIDed HOB further.\r
+    // \r
     return Mailbox;\r
   }\r
 \r
   MailboxLocationInHob = GetMailboxLocationFromHob ();\r
   //\r
-  // Compare mailbox in IDT enry with mailbox in HOB\r
+  // Compare mailbox in IDT enry with mailbox in HOB,\r
+  // need to fix mailbox location if HOB moved by PEI CORE\r
   //\r
   if (MailboxLocationInHob != MailboxLocationInIdt && MailboxLocationInHob != NULL) {\r
     Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInHob);\r
@@ -247,7 +250,7 @@ DebugAgentCallbackMemoryDiscoveredPpi (
   EFI_STATUS                     Status;\r
   DEBUG_AGENT_MAILBOX            *Mailbox;\r
   BOOLEAN                        InterruptStatus;\r
-  EFI_PHYSICAL_ADDRESS           Memory\r
+  EFI_PHYSICAL_ADDRESS           Address\r
   DEBUG_AGENT_MAILBOX            *NewMailbox;\r
   UINT64                         *MailboxLocationInHob;\r
 \r
@@ -262,10 +265,10 @@ DebugAgentCallbackMemoryDiscoveredPpi (
   Status = PeiServicesAllocatePages (\r
              EfiACPIMemoryNVS,\r
              EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),\r
-             &Memory\r
+             &Address\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
-  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Memory;\r
+  NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;\r
   //\r
   // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox\r
   // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core\r
@@ -369,7 +372,14 @@ InitializeDebugAgent (
     // Get and save debug port handle and set the length of memory block.\r
     //\r
     SetLocationSavedMailboxPointerInIdtEntry (&MailboxLocation);\r
+    //\r
+    // Force error message could be printed during the first shakehand between Target/HOST.\r
+    //\r
     SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DEBUG_AGENT_ERROR);\r
+    //\r
+    // Save init arch type when debug agent initialized\r
+    //\r
+    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, sizeof (UINTN) / 4);\r
 \r
     InitializeDebugTimer ();\r
 \r
@@ -453,6 +463,10 @@ InitializeDebugAgent (
     //\r
     SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);\r
     //\r
+    // Save init arch type when debug agent initialized\r
+    //\r
+    SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);\r
+    //\r
     // Register for a callback once memory has been initialized.\r
     // If memery has been ready, the callback funtion will be invoked immediately\r
     //\r
@@ -483,6 +497,9 @@ InitializeDebugAgent (
       MailboxLocationPointer = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +\r
                                                 (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));\r
       Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer);\r
+      //\r
+      // Mailbox should valid and setup before executing thunk code\r
+      //\r
       VerifyMailboxChecksum (Mailbox);\r
 \r
       DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)Mailbox->DebugPortHandle, NULL);\r
@@ -508,7 +525,6 @@ InitializeDebugAgent (
     DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));\r
     CpuDeadLoop ();\r
     break;\r
-\r
   }\r
 \r
   EnableInterrupts ();\r