X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=SourceLevelDebugPkg%2FLibrary%2FDebugAgent%2FSecPeiDebugAgent%2FSecPeiDebugAgentLib.c;h=9a827ef4db92119b796c0b75b86248ab65d2523e;hp=6e7ff8e22eda2d3268519568ff9498b3847426c6;hb=2b55daaef0f3f53059c5c858ca6fd53b03eb5d4c;hpb=4fe43eb3e99590c05ab0e4f73dd9d734b0e110ac diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c index 6e7ff8e22e..9a827ef4db 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c +++ b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c @@ -1,7 +1,7 @@ /** @file SEC Core Debug Agent Library instance implementition. - Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -32,7 +32,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mVectorHandoffInf } }; -GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mMemoryDiscoveredNotifyList[1] = { +GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mDebugAgentMemoryDiscoveredNotifyList[1] = { { (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiPeiMemoryDiscoveredPpiGuid, @@ -93,7 +93,7 @@ DebugReadBreakSymbol ( // // Try to read the start symbol // - DebugPortReadBuffer (Handle, Data8, 1, 0); + DebugAgentReadBuffer (Handle, Data8, 1, 0); if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) { *BreakSymbol = *Data8; DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *BreakSymbol); @@ -213,7 +213,7 @@ GetMailboxPointer ( // Fix up Debug Port handler and save new mailbox in IDT entry // Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt)); - DebugPortHandle = (UINT64)((UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt)); + DebugPortHandle = (UINTN)Mailbox->DebugPortHandle + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt); UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle); *MailboxLocationInHob = (UINT64)(UINTN)Mailbox; SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationInHob); @@ -343,7 +343,7 @@ DebugAgentCallbackMemoryDiscoveredPpi ( function and pass it into InitializeDebugAgent(). InitializeDebugAgent() is responsible to invoke the passing-in function at the end of InitializeDebugAgent(). - If the parameter Function is not NULL, Debug Agent Libary instance will invoke it by + If the parameter Function is not NULL, Debug Agent Library instance will invoke it by passing in the Context to be its parameter. If Function() is NULL, Debug Agent Library instance will return after setup debug @@ -375,8 +375,13 @@ InitializeDebugAgent ( UINT64 MailboxLocation; UINT64 *MailboxLocationPointer; EFI_PHYSICAL_ADDRESS Address; + UINT32 DebugTimerFrequency; + BOOLEAN CpuInterruptState; - DisableInterrupts (); + // + // Disable interrupts and save current interrupt state + // + CpuInterruptState = SaveAndDisableInterrupts(); switch (InitFlag) { @@ -399,8 +404,11 @@ InitializeDebugAgent ( // Save init arch type when debug agent initialized // SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL); - - InitializeDebugTimer (); + // + // Initialize Debug Timer hardware and save its frequency + // + InitializeDebugTimer (&DebugTimerFrequency, TRUE); + UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency); Phase2Context.InitFlag = InitFlag; Phase2Context.Context = Context; @@ -518,18 +526,26 @@ InitializeDebugAgent ( // Build mailbox in HOB and setup Mailbox Set In Pei flag // Mailbox = AllocateZeroPool (sizeof (DEBUG_AGENT_MAILBOX)); - MailboxLocation = (UINT64)(UINTN)Mailbox; - MailboxLocationPointer = BuildGuidDataHob ( - &gEfiDebugAgentGuid, - &MailboxLocation, - sizeof (UINT64) - ); - - InitializeDebugTimer (); - // - // Update IDT entry to save the location pointer saved mailbox pointer - // - SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer); + if (Mailbox == NULL) { + DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to allocate memory!\n")); + CpuDeadLoop (); + } else { + MailboxLocation = (UINT64)(UINTN)Mailbox; + MailboxLocationPointer = BuildGuidDataHob ( + &gEfiDebugAgentGuid, + &MailboxLocation, + sizeof (UINT64) + ); + // + // Initialize Debug Timer hardware and save its frequency + // + InitializeDebugTimer (&DebugTimerFrequency, TRUE); + UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency); + // + // Update IDT entry to save the location pointer saved mailbox pointer + // + SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer); + } // // Save init arch type when debug agent initialized // @@ -538,7 +554,7 @@ InitializeDebugAgent ( // Register for a callback once memory has been initialized. // If memery has been ready, the callback funtion will be invoked immediately // - Status = PeiServicesNotifyPpi (&mMemoryDiscoveredNotifyList[0]); + Status = PeiServicesNotifyPpi (&mDebugAgentMemoryDiscoveredNotifyList[0]); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "DebugAgent: Failed to register memory discovered callback function!\n")); CpuDeadLoop (); @@ -566,8 +582,8 @@ InitializeDebugAgent ( } else { Ia32Idtr = (IA32_DESCRIPTOR *) Context; Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base); - MailboxLocationPointer = (UINT64 *) (UINTN) (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + - (Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16)); + MailboxLocationPointer = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + + ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16)); Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer); // // Mailbox should valid and setup before executing thunk code @@ -599,11 +615,22 @@ InitializeDebugAgent ( break; } - // - // Enable CPU interrupts so debug timer interrupts can be delivered - // - EnableInterrupts (); - + if (InitFlag == DEBUG_AGENT_INIT_POSTMEM_SEC) { + // + // Restore CPU Interrupt state and keep debug timer interrupt state as is + // in DEBUG_AGENT_INIT_POSTMEM_SEC case + // + SetInterruptState (CpuInterruptState); + } else { + // + // Enable Debug Timer interrupt + // + SaveAndSetDebugTimerInterrupt (TRUE); + // + // Enable CPU interrupts so debug timer interrupts can be delivered + // + EnableInterrupts (); + } // // If Function is not NULL, invoke it always whatever debug agent was initialized sucesssfully or not. // @@ -621,10 +648,10 @@ InitializeDebugAgent ( /** Caller provided function to be invoked at the end of DebugPortInitialize(). - Refer to the descrption for DebugPortInitialize() for more details. + Refer to the description for DebugPortInitialize() for more details. @param[in] Context The first input argument of DebugPortInitialize(). - @param[in] DebugPortHandle Debug port handle created by Debug Communication Libary. + @param[in] DebugPortHandle Debug port handle created by Debug Communication Library. **/ VOID @@ -645,7 +672,7 @@ InitializeDebugAgentPhase2 ( MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry (); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation); BufferSize = PcdGet16(PcdDebugPortHandleBufferSize); - if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI) { + if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI && BufferSize != 0) { NewDebugPortHandle = (UINT64)(UINTN)AllocateCopyPool (BufferSize, DebugPortHandle); } else { NewDebugPortHandle = (UINT64)(UINTN)DebugPortHandle; @@ -668,6 +695,10 @@ InitializeDebugAgentPhase2 ( TriggerSoftInterrupt (MEMORY_READY_SIGNATURE); } // + // Enable Debug Timer interrupt + // + SaveAndSetDebugTimerInterrupt (TRUE); + // // Enable CPU interrupts so debug timer interrupts can be delivered // EnableInterrupts ();