From 994140183fc622631d305a216b3fbfa776137b8e Mon Sep 17 00:00:00 2001 From: Jeff Fan Date: Mon, 27 Apr 2015 05:23:43 +0000 Subject: SourceLevelDebugPkg/DebugAgent: Clear/Restore EFLAGS.IF Clear EFLAGS.IF before executing Stepping command and save original value in DEBUG_AGENT_FLAG. It could avoid pending interrupt issued during executing Stepping command. Restore EFLAGS.IF after Stepping command execution finished. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Jordan Justen git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17204 6f19259b-4bc3-4df7-8a09-765794883524 --- .../DebugAgent/DebugAgentCommon/DebugAgent.c | 49 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c index f51ad4b456..7f597352f1 100644 --- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c +++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c @@ -785,7 +785,7 @@ CommandGo ( } /** - Exectue Stepping command. + Execute Stepping command. @param[in] CpuContext Pointer to saved CPU context. @@ -800,6 +800,39 @@ CommandStepping ( Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags; Eflags->Bits.TF = 1; Eflags->Bits.RF = 1; + // + // Save and clear EFLAGS.IF to avoid interrupt happen when executing Stepping + // + SetDebugFlag (DEBUG_AGENT_FLAG_INTERRUPT_FLAG, Eflags->Bits.IF); + Eflags->Bits.IF = 0; + // + // Set Stepping Flag + // + SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 1); +} + +/** + Do some cleanup after Stepping command done. + + @param[in] CpuContext Pointer to saved CPU context. + +**/ +VOID +CommandSteppingCleanup ( + IN DEBUG_CPU_CONTEXT *CpuContext + ) +{ + IA32_EFLAGS32 *Eflags; + + Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags; + // + // Restore EFLAGS.IF + // + Eflags->Bits.IF = GetDebugFlag (DEBUG_AGENT_FLAG_INTERRUPT_FLAG); + // + // Clear Stepping flag + // + SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 0); } /** @@ -2066,10 +2099,6 @@ CommandCommunication ( } mDebugMpContext.BreakAtCpuIndex = (UINT32) (-1); - // - // Set Stepping Flag - // - SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 1); ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock); // // Executing stepping command directly without sending ACK packet, @@ -2405,11 +2434,11 @@ InterruptProcess ( if (MultiProcessorDebugSupport()) { mDebugMpContext.BreakAtCpuIndex = ProcessorIndex; } - SendAckPacket (DEBUG_COMMAND_OK); // - // Clear Stepping Flag + // Clear Stepping Flag and restore EFLAGS.IF // - SetDebugFlag (DEBUG_AGENT_FLAG_STEPPING, 0); + CommandSteppingCleanup (CpuContext); + SendAckPacket (DEBUG_COMMAND_OK); CommandCommunication (Vector, CpuContext, BreakReceived); break; @@ -2582,6 +2611,10 @@ InterruptProcess ( if (MultiProcessorDebugSupport()) { mDebugMpContext.BreakAtCpuIndex = ProcessorIndex; } + // + // Clear Stepping flag and restore EFLAGS.IF + // + CommandSteppingCleanup (CpuContext); SendAckPacket (DEBUG_COMMAND_OK); } else { // -- cgit v1.2.3