010SecMain_InitializeDebugAgentPhase2
InitializeDebugAgentPhase2
进入到DEBUG Agent初始化第二阶段,这里做的事情主要处理以下事务
- 更新某些Mailbox信息,DebugPortHandle
- Trigger one software interrupt to inform HOST
- 开启Debug APCI timer中断
- 开启CPU中断
至此,Debug Agent初始化完成。
/**Caller provided function to be invoked at the end of DebugPortInitialize().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 Library.**/
VOID
EFIAPI
InitializeDebugAgentPhase2 (IN VOID *Context,IN DEBUG_PORT_HANDLE DebugPortHandle)
{DEBUG_AGENT_PHASE2_CONTEXT *Phase2Context;UINT64 *MailboxLocation;DEBUG_AGENT_MAILBOX *Mailbox;EFI_SEC_PEI_HAND_OFF *SecCoreData;UINT16 BufferSize;UINT64 NewDebugPortHandle;Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *)Context;MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry ();Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);BufferSize = PcdGet16 (PcdDebugPortHandleBufferSize);if ((Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI) && (BufferSize != 0)) {NewDebugPortHandle = (UINT64)(UINTN)AllocateCopyPool (BufferSize, DebugPortHandle);} else {NewDebugPortHandle = (UINT64)(UINTN)DebugPortHandle;}UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, NewDebugPortHandle);//// Trigger one software interrupt to inform HOST//TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PREMEM_SEC) {//// If Temporary RAM region is below 128 MB, then send message to// host to disable low memory filtering.//SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;if (((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB) && IsHostAttached ()) {SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);}//// Enable Debug Timer interrupt//SaveAndSetDebugTimerInterrupt (TRUE);//// Enable CPU interrupts so debug timer interrupts can be delivered//EnableInterrupts ();//// Call continuation function if it is not NULL.//Phase2Context->Function (Phase2Context->Context);}
}
TriggerSoftInterrupt
触发一次软件中断,看看是否可以正常触发中断。处理流程可以参考文章DebugAgent处理流程
/**Trigger one software interrupt to debug agent to handle it.@param[in] Signature Software interrupt signature.**/
VOID
TriggerSoftInterrupt (IN UINT32 Signature)
{UINTN Dr0;UINTN Dr1;//// Save Debug Register State//Dr0 = AsmReadDr0 ();Dr1 = AsmReadDr1 ();//// DR0 = Signature//AsmWriteDr0 (SOFT_INTERRUPT_SIGNATURE);AsmWriteDr1 (Signature);//// Do INT3 to communicate with HOST side//CpuBreakpoint ();//// Restore Debug Register State only when Host didn't change it inside exception handler.// Dr registers can only be changed by setting the HW breakpoint.//AsmWriteDr0 (Dr0);AsmWriteDr1 (Dr1);
}
SaveAndSetDebugTimerInterrupt
//// Enable Debug Timer interrupt//SaveAndSetDebugTimerInterrupt (TRUE);
启动APIC timer中断
EnableInterrupts
启用CPU中断,自此我们可以使用Source Debug了
//// Enable CPU interrupts so debug timer interrupts can be delivered//EnableInterrupts ();
/**Enables CPU interrupts.**/
VOID
EFIAPI
EnableInterrupts (VOID)
{_asm {sti}
}
Phase2Context->Function (Phase2Context->Context);
这是一个跳转函数,debug agent 初始化完成。该进入函数SecStartupPhase2,去初始化平台了。