IN VOID *Ppi\r
)\r
{\r
+ EFI_STATUS Status;\r
DEBUG_AGENT_MAILBOX *Mailbox;\r
BOOLEAN InterruptStatus;\r
- \r
+ EFI_PHYSICAL_ADDRESS Memory; \r
+ DEBUG_AGENT_MAILBOX *NewMailbox;\r
+ UINT64 *MailboxLocationInHob;\r
+\r
//\r
// Save and disable original interrupt status\r
//\r
InterruptStatus = SaveAndDisableInterrupts ();\r
- \r
+\r
//\r
- // Set physical memory ready flag\r
+ // Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer\r
+ //\r
+ Status = PeiServicesAllocatePages (\r
+ EfiACPIMemoryNVS,\r
+ EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),\r
+ &Memory\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Memory;\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
+ // reallocates the HOB.\r
//\r
Mailbox = GetMailboxPointer ();\r
- SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);\r
-\r
+ CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));\r
+ CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));\r
//\r
- // Memory has been ready\r
+ // Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one\r
//\r
+ MailboxLocationInHob = GetMailboxLocationFromHob ();\r
+ *MailboxLocationInHob = (UINT64)(UINTN)NewMailbox;\r
+ SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob);\r
+ //\r
+ // Update Debug Port Handle in new Mailbox\r
+ //\r
+ UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));\r
+ //\r
+ // Set physical memory ready flag\r
+ //\r
+ SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);\r
+\r
if (IsHostAttached ()) {\r
//\r
// Trigger one software interrupt to inform HOST\r