SourceLevelDebugPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the SourceLevelDebugPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
committed by
mergify[bot]
parent
b878648967
commit
c1e126b119
File diff suppressed because it is too large
Load Diff
@@ -41,32 +41,32 @@
|
||||
//
|
||||
// These macros may be already defined in DebugAgentLib.h
|
||||
//
|
||||
#define DEBUG_AGENT_INIT_PEI 9
|
||||
#define DEBUG_AGENT_INIT_DXE_LOAD 10
|
||||
#define DEBUG_AGENT_INIT_DXE_UNLOAD 11
|
||||
#define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64 12
|
||||
#define DEBUG_AGENT_INIT_PEI 9
|
||||
#define DEBUG_AGENT_INIT_DXE_LOAD 10
|
||||
#define DEBUG_AGENT_INIT_DXE_UNLOAD 11
|
||||
#define DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64 12
|
||||
|
||||
#define DEBUG_INT1_VECTOR DEBUG_EXCEPT_DEBUG
|
||||
#define DEBUG_INT3_VECTOR DEBUG_EXCEPT_BREAKPOINT
|
||||
#define DEBUG_TIMER_VECTOR 32
|
||||
#define DEBUG_MAILBOX_VECTOR 33
|
||||
#define DEBUG_INT1_VECTOR DEBUG_EXCEPT_DEBUG
|
||||
#define DEBUG_INT3_VECTOR DEBUG_EXCEPT_BREAKPOINT
|
||||
#define DEBUG_TIMER_VECTOR 32
|
||||
#define DEBUG_MAILBOX_VECTOR 33
|
||||
|
||||
//
|
||||
// Timeout value for reading packet (unit is microsecond)
|
||||
//
|
||||
#define READ_PACKET_TIMEOUT (500 * 1000)
|
||||
#define DEBUG_TIMER_INTERVAL (100 * 1000)
|
||||
#define READ_PACKET_TIMEOUT (500 * 1000)
|
||||
#define DEBUG_TIMER_INTERVAL (100 * 1000)
|
||||
|
||||
#define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')
|
||||
#define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')
|
||||
#define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')
|
||||
#define SOFT_INTERRUPT_SIGNATURE SIGNATURE_32('S','O','F','T')
|
||||
#define SYSTEM_RESET_SIGNATURE SIGNATURE_32('S','Y','S','R')
|
||||
#define MEMORY_READY_SIGNATURE SIGNATURE_32('M','E','M','R')
|
||||
|
||||
extern UINTN Exception0Handle;
|
||||
extern UINTN TimerInterruptHandle;
|
||||
extern UINT32 ExceptionStubHeaderSize;
|
||||
extern BOOLEAN mSkipBreakpoint;
|
||||
extern EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent[];
|
||||
extern UINTN mVectorHandoffInfoCount;
|
||||
extern UINTN Exception0Handle;
|
||||
extern UINTN TimerInterruptHandle;
|
||||
extern UINT32 ExceptionStubHeaderSize;
|
||||
extern BOOLEAN mSkipBreakpoint;
|
||||
extern EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent[];
|
||||
extern UINTN mVectorHandoffInfoCount;
|
||||
|
||||
//
|
||||
// CPU exception information issued by debug agent
|
||||
@@ -75,11 +75,11 @@ typedef struct {
|
||||
//
|
||||
// This field is used to save CPU content before executing HOST command
|
||||
//
|
||||
BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
|
||||
BASE_LIBRARY_JUMP_BUFFER JumpBuffer;
|
||||
//
|
||||
// This field returns the exception information issued by the HOST command
|
||||
//
|
||||
DEBUG_DATA_RESPONSE_GET_EXCEPTION ExceptionContent;
|
||||
DEBUG_DATA_RESPONSE_GET_EXCEPTION ExceptionContent;
|
||||
} DEBUG_AGENT_EXCEPTION_BUFFER;
|
||||
|
||||
#define DEBUG_AGENT_FLAG_HOST_ATTACHED BIT0
|
||||
@@ -107,38 +107,38 @@ typedef union {
|
||||
//
|
||||
// Lower 32 bits to store the status of DebugAgent
|
||||
//
|
||||
UINT32 HostAttached : 1; // 1: HOST is attached
|
||||
UINT32 AgentInProgress : 1; // 1: Debug Agent is communicating with HOST
|
||||
UINT32 MemoryReady : 1; // 1: Memory is ready
|
||||
UINT32 SteppingFlag : 1; // 1: Agent is running stepping command
|
||||
UINT32 CheckMailboxInHob : 1; // 1: Need to check mailbox saved in HOB
|
||||
UINT32 InitArch : 2; // value of DEBUG_DATA_RESPONSE_ARCH_MODE
|
||||
UINT32 InterruptFlag : 1; // 1: EFLAGS.IF is set
|
||||
UINT32 Reserved1 : 24;
|
||||
UINT32 HostAttached : 1; // 1: HOST is attached
|
||||
UINT32 AgentInProgress : 1; // 1: Debug Agent is communicating with HOST
|
||||
UINT32 MemoryReady : 1; // 1: Memory is ready
|
||||
UINT32 SteppingFlag : 1; // 1: Agent is running stepping command
|
||||
UINT32 CheckMailboxInHob : 1; // 1: Need to check mailbox saved in HOB
|
||||
UINT32 InitArch : 2; // value of DEBUG_DATA_RESPONSE_ARCH_MODE
|
||||
UINT32 InterruptFlag : 1; // 1: EFLAGS.IF is set
|
||||
UINT32 Reserved1 : 24;
|
||||
//
|
||||
// Higher 32bits to control the behavior of DebugAgent
|
||||
//
|
||||
UINT32 BreakOnNextSmi : 1; // 1: Break on next SMI
|
||||
UINT32 PrintErrorLevel : 4; // Bitmask of print error level for debug message
|
||||
UINT32 BreakOnBootScript : 1; // 1: Break before executing boot script
|
||||
UINT32 Reserved2 : 26;
|
||||
UINT32 BreakOnNextSmi : 1; // 1: Break on next SMI
|
||||
UINT32 PrintErrorLevel : 4; // Bitmask of print error level for debug message
|
||||
UINT32 BreakOnBootScript : 1; // 1: Break before executing boot script
|
||||
UINT32 Reserved2 : 26;
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
UINT64 Uint64;
|
||||
} DEBUG_AGENT_FLAG;
|
||||
|
||||
typedef struct {
|
||||
DEBUG_AGENT_FLAG DebugFlag;
|
||||
UINT64 DebugPortHandle;
|
||||
DEBUG_AGENT_FLAG DebugFlag;
|
||||
UINT64 DebugPortHandle;
|
||||
//
|
||||
// Pointer to DEBUG_AGENT_EXCEPTION_BUFFER
|
||||
//
|
||||
UINT64 ExceptionBufferPointer;
|
||||
UINT8 LastAck; // The last ack packet type
|
||||
UINT8 SequenceNo;
|
||||
UINT8 HostSequenceNo;
|
||||
UINT32 DebugTimerFrequency;
|
||||
UINT8 CheckSum; // Mailbox checksum
|
||||
UINT8 ToBeCheckSum; // To be Mailbox checksum at the next
|
||||
UINT64 ExceptionBufferPointer;
|
||||
UINT8 LastAck; // The last ack packet type
|
||||
UINT8 SequenceNo;
|
||||
UINT8 HostSequenceNo;
|
||||
UINT32 DebugTimerFrequency;
|
||||
UINT8 CheckSum; // Mailbox checksum
|
||||
UINT8 ToBeCheckSum; // To be Mailbox checksum at the next
|
||||
} DEBUG_AGENT_MAILBOX;
|
||||
#pragma pack()
|
||||
|
||||
@@ -147,33 +147,32 @@ typedef struct {
|
||||
///
|
||||
typedef union {
|
||||
struct {
|
||||
UINT32 OffsetLow:16; ///< Offset bits 15..0.
|
||||
UINT32 Selector:16; ///< Selector.
|
||||
UINT32 Reserved_0:8; ///< Reserved.
|
||||
UINT32 GateType:8; ///< Gate Type. See #defines above.
|
||||
UINT32 OffsetHigh:16; ///< Offset bits 31..16.
|
||||
UINT32 OffsetLow : 16; ///< Offset bits 15..0.
|
||||
UINT32 Selector : 16; ///< Selector.
|
||||
UINT32 Reserved_0 : 8; ///< Reserved.
|
||||
UINT32 GateType : 8; ///< Gate Type. See #defines above.
|
||||
UINT32 OffsetHigh : 16; ///< Offset bits 31..16.
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
UINT64 Uint64;
|
||||
} IA32_IDT_ENTRY;
|
||||
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
UINT32 LimitLow : 16;
|
||||
UINT32 BaseLow : 16;
|
||||
UINT32 BaseMid : 8;
|
||||
UINT32 Type : 4;
|
||||
UINT32 System : 1;
|
||||
UINT32 Dpl : 2;
|
||||
UINT32 Present : 1;
|
||||
UINT32 LimitHigh : 4;
|
||||
UINT32 Software : 1;
|
||||
UINT32 Reserved : 1;
|
||||
UINT32 DefaultSize : 1;
|
||||
UINT32 Granularity : 1;
|
||||
UINT32 BaseHigh : 8;
|
||||
UINT32 LimitLow : 16;
|
||||
UINT32 BaseLow : 16;
|
||||
UINT32 BaseMid : 8;
|
||||
UINT32 Type : 4;
|
||||
UINT32 System : 1;
|
||||
UINT32 Dpl : 2;
|
||||
UINT32 Present : 1;
|
||||
UINT32 LimitHigh : 4;
|
||||
UINT32 Software : 1;
|
||||
UINT32 Reserved : 1;
|
||||
UINT32 DefaultSize : 1;
|
||||
UINT32 Granularity : 1;
|
||||
UINT32 BaseHigh : 8;
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
UINT64 Uint64;
|
||||
} IA32_GDT;
|
||||
|
||||
/**
|
||||
@@ -197,9 +196,9 @@ InitializeDebugIdt (
|
||||
**/
|
||||
UINT8 *
|
||||
ArchReadRegisterBuffer (
|
||||
IN DEBUG_CPU_CONTEXT *CpuContext,
|
||||
IN UINT8 Index,
|
||||
IN UINT8 *Width
|
||||
IN DEBUG_CPU_CONTEXT *CpuContext,
|
||||
IN UINT8 Index,
|
||||
IN UINT8 *Width
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -216,9 +215,9 @@ ArchReadRegisterBuffer (
|
||||
**/
|
||||
RETURN_STATUS
|
||||
SendDataResponsePacket (
|
||||
IN UINT8 *Data,
|
||||
IN UINT16 DataSize,
|
||||
IN OUT DEBUG_PACKET_HEADER *DebugHeader
|
||||
IN UINT8 *Data,
|
||||
IN UINT16 DataSize,
|
||||
IN OUT DEBUG_PACKET_HEADER *DebugHeader
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -267,8 +266,8 @@ GetDebugPortHandle (
|
||||
**/
|
||||
EFI_STATUS
|
||||
DebugReadBreakSymbol (
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -286,8 +285,8 @@ DebugReadBreakSymbol (
|
||||
VOID
|
||||
EFIAPI
|
||||
DebugAgentMsgPrint (
|
||||
IN UINT8 ErrorLevel,
|
||||
IN CHAR8 *Format,
|
||||
IN UINT8 ErrorLevel,
|
||||
IN CHAR8 *Format,
|
||||
...
|
||||
);
|
||||
|
||||
@@ -299,7 +298,7 @@ DebugAgentMsgPrint (
|
||||
**/
|
||||
VOID
|
||||
TriggerSoftInterrupt (
|
||||
IN UINT32 Signature
|
||||
IN UINT32 Signature
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -322,7 +321,7 @@ MultiProcessorDebugSupport (
|
||||
**/
|
||||
VOID
|
||||
FindAndReportModuleImageInfo (
|
||||
IN UINTN AlignSize
|
||||
IN UINTN AlignSize
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -345,7 +344,7 @@ IsDebugAgentInitialzed (
|
||||
**/
|
||||
VOID
|
||||
UpdateMailboxChecksum (
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -358,7 +357,7 @@ UpdateMailboxChecksum (
|
||||
**/
|
||||
VOID
|
||||
VerifyMailboxChecksum (
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -370,8 +369,8 @@ VerifyMailboxChecksum (
|
||||
**/
|
||||
VOID
|
||||
SetDebugFlag (
|
||||
IN UINT64 FlagMask,
|
||||
IN UINT32 FlagValue
|
||||
IN UINT64 FlagMask,
|
||||
IN UINT32 FlagValue
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -384,7 +383,7 @@ SetDebugFlag (
|
||||
**/
|
||||
UINT32
|
||||
GetDebugFlag (
|
||||
IN UINT64 FlagMask
|
||||
IN UINT64 FlagMask
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -397,9 +396,9 @@ GetDebugFlag (
|
||||
**/
|
||||
VOID
|
||||
UpdateMailboxContent (
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox,
|
||||
IN UINTN Index,
|
||||
IN UINT64 Value
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox,
|
||||
IN UINTN Index,
|
||||
IN UINT64 Value
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -412,7 +411,7 @@ UpdateMailboxContent (
|
||||
**/
|
||||
VOID *
|
||||
GetExceptionHandlerInIdtEntry (
|
||||
IN UINTN ExceptionNum
|
||||
IN UINTN ExceptionNum
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -424,8 +423,8 @@ GetExceptionHandlerInIdtEntry (
|
||||
**/
|
||||
VOID
|
||||
SetExceptionHandlerInIdtEntry (
|
||||
IN UINTN ExceptionNum,
|
||||
IN VOID *ExceptionHandler
|
||||
IN UINTN ExceptionNum,
|
||||
IN VOID *ExceptionHandler
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -446,10 +445,10 @@ SetExceptionHandlerInIdtEntry (
|
||||
VOID
|
||||
EFIAPI
|
||||
DebugAgentDataMsgPrint (
|
||||
IN UINT8 ErrorLevel,
|
||||
IN BOOLEAN IsSend,
|
||||
IN UINT8 *Data,
|
||||
IN UINT8 Length
|
||||
IN UINT8 ErrorLevel,
|
||||
IN BOOLEAN IsSend,
|
||||
IN UINT8 *Data,
|
||||
IN UINT8 Length
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -465,8 +464,8 @@ DebugAgentDataMsgPrint (
|
||||
**/
|
||||
EFI_STATUS
|
||||
ReadRemainingBreakPacket (
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
IN OUT DEBUG_PACKET_HEADER *DebugHeader
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
IN OUT DEBUG_PACKET_HEADER *DebugHeader
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -488,11 +487,10 @@ ReadRemainingBreakPacket (
|
||||
**/
|
||||
UINTN
|
||||
DebugAgentReadBuffer (
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
IN OUT UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes,
|
||||
IN UINTN Timeout
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
IN OUT UINT8 *Buffer,
|
||||
IN UINTN NumberOfBytes,
|
||||
IN UINTN Timeout
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -8,9 +8,9 @@
|
||||
|
||||
#include "DebugAgent.h"
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_MP_CONTEXT volatile mDebugMpContext = {0,0,0,{0},{0},0,0,0,0,FALSE,FALSE};
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_MP_CONTEXT volatile mDebugMpContext = { 0, 0, 0, { 0 }, { 0 }, 0, 0, 0, 0, FALSE, FALSE };
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_CPU_DATA volatile mDebugCpuData = {0};
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_CPU_DATA volatile mDebugCpuData = { 0 };
|
||||
|
||||
/**
|
||||
Acquire a spin lock when Multi-processor supported.
|
||||
@@ -23,10 +23,10 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_CPU_DATA volatile mDebugCpuData = {0};
|
||||
**/
|
||||
VOID
|
||||
AcquireMpSpinLock (
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
)
|
||||
{
|
||||
if (!MultiProcessorDebugSupport()) {
|
||||
if (!MultiProcessorDebugSupport ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ AcquireMpSpinLock (
|
||||
if (AcquireSpinLockOrFail (MpSpinLock)) {
|
||||
break;
|
||||
}
|
||||
|
||||
CpuPause ();
|
||||
continue;
|
||||
}
|
||||
@@ -47,10 +48,10 @@ AcquireMpSpinLock (
|
||||
**/
|
||||
VOID
|
||||
ReleaseMpSpinLock (
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
)
|
||||
{
|
||||
if (!MultiProcessorDebugSupport()) {
|
||||
if (!MultiProcessorDebugSupport ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,12 +66,12 @@ ReleaseMpSpinLock (
|
||||
**/
|
||||
VOID
|
||||
HaltOtherProcessors (
|
||||
IN UINT32 CurrentProcessorIndex
|
||||
IN UINT32 CurrentProcessorIndex
|
||||
)
|
||||
{
|
||||
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "processor[%x]:Try to halt other processors.\n", CurrentProcessorIndex);
|
||||
if (!DebugAgentIsBsp (CurrentProcessorIndex)) {
|
||||
SetIpiSentByApFlag (TRUE);;
|
||||
SetIpiSentByApFlag (TRUE);
|
||||
}
|
||||
|
||||
mDebugMpContext.BreakAtCpuIndex = CurrentProcessorIndex;
|
||||
@@ -84,7 +85,6 @@ HaltOtherProcessors (
|
||||
// Send fixed IPI to other processors.
|
||||
//
|
||||
SendFixedIpiAllExcludingSelf (DEBUG_TIMER_VECTOR);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,14 +98,14 @@ GetProcessorIndex (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINT32 Index;
|
||||
UINT16 LocalApicID;
|
||||
UINT32 Index;
|
||||
UINT16 LocalApicID;
|
||||
|
||||
LocalApicID = (UINT16) GetApicId ();
|
||||
LocalApicID = (UINT16)GetApicId ();
|
||||
|
||||
AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
|
||||
for (Index = 0; Index < mDebugCpuData.CpuCount; Index ++) {
|
||||
for (Index = 0; Index < mDebugCpuData.CpuCount; Index++) {
|
||||
if (mDebugCpuData.ApicID[Index] == LocalApicID) {
|
||||
break;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ GetProcessorIndex (
|
||||
|
||||
if (Index == mDebugCpuData.CpuCount) {
|
||||
mDebugCpuData.ApicID[Index] = LocalApicID;
|
||||
mDebugCpuData.CpuCount ++ ;
|
||||
mDebugCpuData.CpuCount++;
|
||||
}
|
||||
|
||||
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
@@ -153,6 +153,7 @@ DebugAgentIsBsp (
|
||||
mDebugMpContext.BspIndex = ProcessorIndex;
|
||||
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
@@ -169,12 +170,12 @@ DebugAgentIsBsp (
|
||||
**/
|
||||
VOID
|
||||
SetCpuStopFlagByIndex (
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN StopFlag
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN StopFlag
|
||||
)
|
||||
{
|
||||
UINT8 Value;
|
||||
UINTN Index;
|
||||
UINT8 Value;
|
||||
UINTN Index;
|
||||
|
||||
AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
|
||||
@@ -185,6 +186,7 @@ SetCpuStopFlagByIndex (
|
||||
} else {
|
||||
Value = BitFieldWrite8 (Value, Index, Index, 0);
|
||||
}
|
||||
|
||||
mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] = Value;
|
||||
|
||||
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
@@ -200,12 +202,12 @@ SetCpuStopFlagByIndex (
|
||||
**/
|
||||
VOID
|
||||
SetCpuBreakFlagByIndex (
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN BreakFlag
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN BreakFlag
|
||||
)
|
||||
{
|
||||
UINT8 Value;
|
||||
UINTN Index;
|
||||
UINT8 Value;
|
||||
UINTN Index;
|
||||
|
||||
AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
|
||||
@@ -216,6 +218,7 @@ SetCpuBreakFlagByIndex (
|
||||
} else {
|
||||
Value = BitFieldWrite8 (Value, Index, Index, 0);
|
||||
}
|
||||
|
||||
mDebugMpContext.CpuBreakMask[ProcessorIndex / 8] = Value;
|
||||
|
||||
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
@@ -232,12 +235,12 @@ SetCpuBreakFlagByIndex (
|
||||
**/
|
||||
BOOLEAN
|
||||
IsCpuStopped (
|
||||
IN UINT32 ProcessorIndex
|
||||
IN UINT32 ProcessorIndex
|
||||
)
|
||||
{
|
||||
UINT8 CpuMask;
|
||||
UINT8 CpuMask;
|
||||
|
||||
CpuMask = (UINT8) (1 << (ProcessorIndex % 8));
|
||||
CpuMask = (UINT8)(1 << (ProcessorIndex % 8));
|
||||
|
||||
if ((mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] & CpuMask) != 0) {
|
||||
return TRUE;
|
||||
@@ -255,7 +258,7 @@ IsCpuStopped (
|
||||
**/
|
||||
VOID
|
||||
SetCpuRunningFlag (
|
||||
IN BOOLEAN RunningFlag
|
||||
IN BOOLEAN RunningFlag
|
||||
)
|
||||
{
|
||||
AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
@@ -271,7 +274,7 @@ SetCpuRunningFlag (
|
||||
**/
|
||||
VOID
|
||||
SetDebugViewPoint (
|
||||
IN UINT32 ProcessorIndex
|
||||
IN UINT32 ProcessorIndex
|
||||
)
|
||||
{
|
||||
AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
@@ -288,7 +291,7 @@ SetDebugViewPoint (
|
||||
**/
|
||||
VOID
|
||||
SetIpiSentByApFlag (
|
||||
IN BOOLEAN IpiSentByApFlag
|
||||
IN BOOLEAN IpiSentByApFlag
|
||||
)
|
||||
{
|
||||
AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
@@ -309,13 +312,14 @@ FindNextPendingBreakCpu (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINT32 Index;
|
||||
UINT32 Index;
|
||||
|
||||
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index ++) {
|
||||
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index++) {
|
||||
if (mDebugMpContext.CpuBreakMask[Index] != 0) {
|
||||
return (UINT32) LowBitSet32 (mDebugMpContext.CpuBreakMask[Index]) + Index * 8;
|
||||
return (UINT32)LowBitSet32 (mDebugMpContext.CpuBreakMask[Index]) + Index * 8;
|
||||
}
|
||||
}
|
||||
|
||||
return (UINT32)-1;
|
||||
}
|
||||
|
||||
@@ -331,13 +335,14 @@ IsAllCpuRunning (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
UINTN Index;
|
||||
|
||||
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index ++) {
|
||||
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index++) {
|
||||
if (mDebugMpContext.CpuStopStatusMask[Index] != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -354,11 +359,11 @@ IsAllCpuRunning (
|
||||
**/
|
||||
BOOLEAN
|
||||
IsFirstBreakProcessor (
|
||||
IN UINT32 ProcessorIndex
|
||||
IN UINT32 ProcessorIndex
|
||||
)
|
||||
{
|
||||
if (MultiProcessorDebugSupport()) {
|
||||
if (mDebugMpContext.BreakAtCpuIndex != (UINT32) -1) {
|
||||
if (MultiProcessorDebugSupport ()) {
|
||||
if (mDebugMpContext.BreakAtCpuIndex != (UINT32)-1) {
|
||||
//
|
||||
// The current processor is not the first breaking one.
|
||||
//
|
||||
@@ -372,6 +377,6 @@ IsFirstBreakProcessor (
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#ifndef _DEBUG_MP_H_
|
||||
#define _DEBUG_MP_H_
|
||||
|
||||
#define DEBUG_CPU_MAX_COUNT 256
|
||||
#define DEBUG_CPU_MAX_COUNT 256
|
||||
|
||||
typedef struct {
|
||||
UINT32 CpuCount; ///< Processor count
|
||||
@@ -17,21 +17,21 @@ typedef struct {
|
||||
} DEBUG_CPU_DATA;
|
||||
|
||||
typedef struct {
|
||||
SPIN_LOCK MpContextSpinLock; ///< Lock for writing MP context
|
||||
SPIN_LOCK DebugPortSpinLock; ///< Lock for access debug port
|
||||
SPIN_LOCK MailboxSpinLock; ///< Lock for accessing mail box
|
||||
UINT8 CpuBreakMask[DEBUG_CPU_MAX_COUNT/8]; ///< Bitmask of all breaking CPUs
|
||||
UINT8 CpuStopStatusMask[DEBUG_CPU_MAX_COUNT/8]; ///< Bitmask of CPU stop status
|
||||
UINT32 ViewPointIndex; ///< Current view point to be debugged
|
||||
UINT32 BspIndex; ///< Processor index value of BSP
|
||||
UINT32 BreakAtCpuIndex; ///< Processor index value of the current breaking CPU
|
||||
UINT32 DebugTimerInitCount; ///< Record BSP's init timer count
|
||||
BOOLEAN IpiSentByAp; ///< TRUE: IPI is sent by AP. FALSE: IPI is sent by BSP
|
||||
BOOLEAN RunCommandSet; ///< TRUE: RUN command is executing. FALSE: RUN command has been executed.
|
||||
SPIN_LOCK MpContextSpinLock; ///< Lock for writing MP context
|
||||
SPIN_LOCK DebugPortSpinLock; ///< Lock for access debug port
|
||||
SPIN_LOCK MailboxSpinLock; ///< Lock for accessing mail box
|
||||
UINT8 CpuBreakMask[DEBUG_CPU_MAX_COUNT/8]; ///< Bitmask of all breaking CPUs
|
||||
UINT8 CpuStopStatusMask[DEBUG_CPU_MAX_COUNT/8]; ///< Bitmask of CPU stop status
|
||||
UINT32 ViewPointIndex; ///< Current view point to be debugged
|
||||
UINT32 BspIndex; ///< Processor index value of BSP
|
||||
UINT32 BreakAtCpuIndex; ///< Processor index value of the current breaking CPU
|
||||
UINT32 DebugTimerInitCount; ///< Record BSP's init timer count
|
||||
BOOLEAN IpiSentByAp; ///< TRUE: IPI is sent by AP. FALSE: IPI is sent by BSP
|
||||
BOOLEAN RunCommandSet; ///< TRUE: RUN command is executing. FALSE: RUN command has been executed.
|
||||
} DEBUG_MP_CONTEXT;
|
||||
|
||||
extern DEBUG_MP_CONTEXT volatile mDebugMpContext;
|
||||
extern DEBUG_CPU_DATA volatile mDebugCpuData;
|
||||
extern DEBUG_MP_CONTEXT volatile mDebugMpContext;
|
||||
extern DEBUG_CPU_DATA volatile mDebugCpuData;
|
||||
|
||||
/**
|
||||
Break the other processor by send IPI.
|
||||
@@ -41,7 +41,7 @@ extern DEBUG_CPU_DATA volatile mDebugCpuData;
|
||||
**/
|
||||
VOID
|
||||
HaltOtherProcessors (
|
||||
IN UINT32 CurrentProcessorIndex
|
||||
IN UINT32 CurrentProcessorIndex
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ GetProcessorIndex (
|
||||
**/
|
||||
VOID
|
||||
AcquireMpSpinLock (
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ AcquireMpSpinLock (
|
||||
**/
|
||||
VOID
|
||||
ReleaseMpSpinLock (
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
IN OUT SPIN_LOCK *MpSpinLock
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ ReleaseMpSpinLock (
|
||||
**/
|
||||
BOOLEAN
|
||||
DebugAgentIsBsp (
|
||||
IN UINT32 ProcessorIndex
|
||||
IN UINT32 ProcessorIndex
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -104,8 +104,8 @@ DebugAgentIsBsp (
|
||||
**/
|
||||
VOID
|
||||
SetCpuStopFlagByIndex (
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN StopFlag
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN StopFlag
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -118,8 +118,8 @@ SetCpuStopFlagByIndex (
|
||||
**/
|
||||
VOID
|
||||
SetCpuBreakFlagByIndex (
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN BreakFlag
|
||||
IN UINT32 ProcessorIndex,
|
||||
IN BOOLEAN BreakFlag
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -133,7 +133,7 @@ SetCpuBreakFlagByIndex (
|
||||
**/
|
||||
BOOLEAN
|
||||
IsCpuStopped (
|
||||
IN UINT32 ProcessorIndex
|
||||
IN UINT32 ProcessorIndex
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ IsCpuStopped (
|
||||
**/
|
||||
VOID
|
||||
SetCpuRunningFlag (
|
||||
IN BOOLEAN RunningFlag
|
||||
IN BOOLEAN RunningFlag
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -156,7 +156,7 @@ SetCpuRunningFlag (
|
||||
**/
|
||||
VOID
|
||||
SetDebugViewPoint (
|
||||
IN UINT32 ProcessorIndex
|
||||
IN UINT32 ProcessorIndex
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -168,7 +168,7 @@ SetDebugViewPoint (
|
||||
**/
|
||||
VOID
|
||||
SetIpiSentByApFlag (
|
||||
IN BOOLEAN IpiSentByApFlag
|
||||
IN BOOLEAN IpiSentByApFlag
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -209,8 +209,7 @@ IsAllCpuRunning (
|
||||
**/
|
||||
BOOLEAN
|
||||
IsFirstBreakProcessor (
|
||||
IN UINT32 ProcessorIndex
|
||||
IN UINT32 ProcessorIndex
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -18,27 +18,27 @@
|
||||
**/
|
||||
UINT32
|
||||
InitializeDebugTimer (
|
||||
OUT UINT32 *TimerFrequency,
|
||||
IN BOOLEAN DumpFlag
|
||||
OUT UINT32 *TimerFrequency,
|
||||
IN BOOLEAN DumpFlag
|
||||
)
|
||||
{
|
||||
UINTN ApicTimerDivisor;
|
||||
UINT32 InitialCount;
|
||||
UINT32 ApicTimerFrequency;
|
||||
UINTN ApicTimerDivisor;
|
||||
UINT32 InitialCount;
|
||||
UINT32 ApicTimerFrequency;
|
||||
|
||||
InitializeLocalApicSoftwareEnable (TRUE);
|
||||
GetApicTimerState (&ApicTimerDivisor, NULL, NULL);
|
||||
ApicTimerFrequency = PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor;
|
||||
ApicTimerFrequency = PcdGet32 (PcdFSBClock) / (UINT32)ApicTimerDivisor;
|
||||
//
|
||||
// Cpu Local Apic timer interrupt frequency, it is set to 0.1s
|
||||
//
|
||||
InitialCount = (UINT32)DivU64x32 (
|
||||
MultU64x64 (
|
||||
ApicTimerFrequency,
|
||||
DEBUG_TIMER_INTERVAL
|
||||
),
|
||||
1000000u
|
||||
);
|
||||
MultU64x64 (
|
||||
ApicTimerFrequency,
|
||||
DEBUG_TIMER_INTERVAL
|
||||
),
|
||||
1000000u
|
||||
);
|
||||
|
||||
InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);
|
||||
//
|
||||
@@ -48,14 +48,16 @@ InitializeDebugTimer (
|
||||
DisableApicTimerInterrupt ();
|
||||
|
||||
if (DumpFlag) {
|
||||
DEBUG ((DEBUG_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32(PcdFSBClock)));
|
||||
DEBUG ((DEBUG_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32 (PcdFSBClock)));
|
||||
DEBUG ((DEBUG_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor));
|
||||
DEBUG ((DEBUG_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency));
|
||||
DEBUG ((DEBUG_INFO, "Debug Timer: InitialCount = %d\n", InitialCount));
|
||||
}
|
||||
|
||||
if (TimerFrequency != NULL) {
|
||||
*TimerFrequency = ApicTimerFrequency;
|
||||
}
|
||||
|
||||
return InitialCount;
|
||||
}
|
||||
|
||||
@@ -75,10 +77,10 @@ InitializeDebugTimer (
|
||||
BOOLEAN
|
||||
EFIAPI
|
||||
SaveAndSetDebugTimerInterrupt (
|
||||
IN BOOLEAN EnableStatus
|
||||
IN BOOLEAN EnableStatus
|
||||
)
|
||||
{
|
||||
BOOLEAN OldDebugTimerInterruptState;
|
||||
BOOLEAN OldDebugTimerInterruptState;
|
||||
|
||||
OldDebugTimerInterruptState = GetApicTimerInterruptState ();
|
||||
|
||||
@@ -88,6 +90,7 @@ SaveAndSetDebugTimerInterrupt (
|
||||
} else {
|
||||
DisableApicTimerInterrupt ();
|
||||
}
|
||||
|
||||
//
|
||||
// Validate the Debug Timer interrupt state
|
||||
// This will make additional delay after Local Apic Timer interrupt state is changed.
|
||||
@@ -114,9 +117,9 @@ SaveAndSetDebugTimerInterrupt (
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDebugTimerTimeout (
|
||||
IN UINT32 TimerCycle,
|
||||
IN UINT32 Timer,
|
||||
IN UINT32 TimeoutTicker
|
||||
IN UINT32 TimerCycle,
|
||||
IN UINT32 Timer,
|
||||
IN UINT32 TimeoutTicker
|
||||
)
|
||||
{
|
||||
UINT64 CurrentTimer;
|
||||
@@ -138,5 +141,5 @@ IsDebugTimerTimeout (
|
||||
Delta = TimerCycle - (CurrentTimer - Timer) + 1;
|
||||
}
|
||||
|
||||
return (BOOLEAN) (Delta >= TimeoutTicker);
|
||||
return (BOOLEAN)(Delta >= TimeoutTicker);
|
||||
}
|
||||
|
@@ -19,8 +19,8 @@
|
||||
**/
|
||||
UINT32
|
||||
InitializeDebugTimer (
|
||||
OUT UINT32 *TimerFrequency,
|
||||
IN BOOLEAN DumpFlag
|
||||
OUT UINT32 *TimerFrequency,
|
||||
IN BOOLEAN DumpFlag
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -36,10 +36,9 @@ InitializeDebugTimer (
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDebugTimerTimeout (
|
||||
IN UINT32 TimerCycle,
|
||||
IN UINT32 Timer,
|
||||
IN UINT32 TimeoutTicker
|
||||
IN UINT32 TimerCycle,
|
||||
IN UINT32 Timer,
|
||||
IN UINT32 TimeoutTicker
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -17,12 +17,12 @@ InitializeDebugIdt (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
UINTN InterruptHandler;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN Index;
|
||||
UINT16 CodeSegment;
|
||||
UINT32 RegEdx;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
UINTN InterruptHandler;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN Index;
|
||||
UINT16 CodeSegment;
|
||||
UINT32 RegEdx;
|
||||
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
|
||||
@@ -31,23 +31,24 @@ InitializeDebugIdt (
|
||||
//
|
||||
CodeSegment = AsmReadCs ();
|
||||
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
|
||||
for (Index = 0; Index < 20; Index ++) {
|
||||
for (Index = 0; Index < 20; Index++) {
|
||||
if (((PcdGet32 (PcdExceptionsIgnoredByDebugger) & ~(BIT1 | BIT3)) & (1 << Index)) != 0) {
|
||||
//
|
||||
// If the exception is masked to be reserved except for INT1 and INT3, skip it
|
||||
//
|
||||
continue;
|
||||
}
|
||||
InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize;
|
||||
|
||||
InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize;
|
||||
IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry[Index].Bits.Selector = CodeSegment;
|
||||
IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
|
||||
}
|
||||
|
||||
InterruptHandler = (UINTN) &TimerInterruptHandle;
|
||||
InterruptHandler = (UINTN)&TimerInterruptHandle;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.Selector = CodeSegment;
|
||||
@@ -73,16 +74,16 @@ InitializeDebugIdt (
|
||||
**/
|
||||
VOID *
|
||||
GetExceptionHandlerInIdtEntry (
|
||||
IN UINTN ExceptionNum
|
||||
IN UINTN ExceptionNum
|
||||
)
|
||||
{
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
|
||||
return (VOID *) (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetLow) |
|
||||
return (VOID *)(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetLow) |
|
||||
(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16));
|
||||
}
|
||||
|
||||
@@ -95,16 +96,16 @@ GetExceptionHandlerInIdtEntry (
|
||||
**/
|
||||
VOID
|
||||
SetExceptionHandlerInIdtEntry (
|
||||
IN UINTN ExceptionNum,
|
||||
IN VOID *ExceptionHandler
|
||||
IN UINTN ExceptionNum,
|
||||
IN VOID *ExceptionHandler
|
||||
)
|
||||
{
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
|
||||
IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler;
|
||||
IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16);
|
||||
IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler;
|
||||
IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16);
|
||||
}
|
||||
|
@@ -12,10 +12,10 @@
|
||||
#include "ProcessorContext.h"
|
||||
#include "TransferProtocol.h"
|
||||
|
||||
#define DEBUG_SW_BREAKPOINT_SYMBOL 0xcc
|
||||
#define DEBUG_ARCH_SYMBOL DEBUG_DATA_BREAK_CPU_ARCH_IA32
|
||||
#define DEBUG_SW_BREAKPOINT_SYMBOL 0xcc
|
||||
#define DEBUG_ARCH_SYMBOL DEBUG_DATA_BREAK_CPU_ARCH_IA32
|
||||
|
||||
typedef DEBUG_DATA_IA32_FX_SAVE_STATE DEBUG_DATA_FX_SAVE_STATE;
|
||||
typedef DEBUG_DATA_IA32_SYSTEM_CONTEXT DEBUG_CPU_CONTEXT;
|
||||
typedef DEBUG_DATA_IA32_FX_SAVE_STATE DEBUG_DATA_FX_SAVE_STATE;
|
||||
typedef DEBUG_DATA_IA32_SYSTEM_CONTEXT DEBUG_CPU_CONTEXT;
|
||||
|
||||
#endif
|
||||
|
@@ -9,22 +9,22 @@
|
||||
#ifndef _DEBUG_EXCEPTION_H_
|
||||
#define _DEBUG_EXCEPTION_H_
|
||||
|
||||
#define DEBUG_EXCEPT_DIVIDE_ERROR 0
|
||||
#define DEBUG_EXCEPT_DEBUG 1
|
||||
#define DEBUG_EXCEPT_NMI 2
|
||||
#define DEBUG_EXCEPT_BREAKPOINT 3
|
||||
#define DEBUG_EXCEPT_OVERFLOW 4
|
||||
#define DEBUG_EXCEPT_BOUND 5
|
||||
#define DEBUG_EXCEPT_INVALID_OPCODE 6
|
||||
#define DEBUG_EXCEPT_DOUBLE_FAULT 8
|
||||
#define DEBUG_EXCEPT_INVALID_TSS 10
|
||||
#define DEBUG_EXCEPT_SEG_NOT_PRESENT 11
|
||||
#define DEBUG_EXCEPT_STACK_FAULT 12
|
||||
#define DEBUG_EXCEPT_GP_FAULT 13
|
||||
#define DEBUG_EXCEPT_PAGE_FAULT 14
|
||||
#define DEBUG_EXCEPT_FP_ERROR 16
|
||||
#define DEBUG_EXCEPT_ALIGNMENT_CHECK 17
|
||||
#define DEBUG_EXCEPT_MACHINE_CHECK 18
|
||||
#define DEBUG_EXCEPT_SIMD 19
|
||||
#define DEBUG_EXCEPT_DIVIDE_ERROR 0
|
||||
#define DEBUG_EXCEPT_DEBUG 1
|
||||
#define DEBUG_EXCEPT_NMI 2
|
||||
#define DEBUG_EXCEPT_BREAKPOINT 3
|
||||
#define DEBUG_EXCEPT_OVERFLOW 4
|
||||
#define DEBUG_EXCEPT_BOUND 5
|
||||
#define DEBUG_EXCEPT_INVALID_OPCODE 6
|
||||
#define DEBUG_EXCEPT_DOUBLE_FAULT 8
|
||||
#define DEBUG_EXCEPT_INVALID_TSS 10
|
||||
#define DEBUG_EXCEPT_SEG_NOT_PRESENT 11
|
||||
#define DEBUG_EXCEPT_STACK_FAULT 12
|
||||
#define DEBUG_EXCEPT_GP_FAULT 13
|
||||
#define DEBUG_EXCEPT_PAGE_FAULT 14
|
||||
#define DEBUG_EXCEPT_FP_ERROR 16
|
||||
#define DEBUG_EXCEPT_ALIGNMENT_CHECK 17
|
||||
#define DEBUG_EXCEPT_MACHINE_CHECK 18
|
||||
#define DEBUG_EXCEPT_SIMD 19
|
||||
|
||||
#endif
|
||||
|
@@ -17,12 +17,12 @@ InitializeDebugIdt (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
UINTN InterruptHandler;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN Index;
|
||||
UINT16 CodeSegment;
|
||||
UINT32 RegEdx;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
UINTN InterruptHandler;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN Index;
|
||||
UINT16 CodeSegment;
|
||||
UINT32 RegEdx;
|
||||
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
|
||||
@@ -31,29 +31,30 @@ InitializeDebugIdt (
|
||||
//
|
||||
CodeSegment = AsmReadCs ();
|
||||
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
|
||||
for (Index = 0; Index < 20; Index ++) {
|
||||
for (Index = 0; Index < 20; Index++) {
|
||||
if (((PcdGet32 (PcdExceptionsIgnoredByDebugger) & ~(BIT1 | BIT3)) & (1 << Index)) != 0) {
|
||||
//
|
||||
// If the exception is masked to be reserved except for INT1 and INT3, skip it
|
||||
//
|
||||
continue;
|
||||
}
|
||||
InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize;
|
||||
IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry[Index].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
|
||||
IdtEntry[Index].Bits.Selector = CodeSegment;
|
||||
IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
|
||||
|
||||
InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize;
|
||||
IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry[Index].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
|
||||
IdtEntry[Index].Bits.Selector = CodeSegment;
|
||||
IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
|
||||
}
|
||||
|
||||
InterruptHandler = (UINTN) &TimerInterruptHandle;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.Selector = CodeSegment;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
|
||||
InterruptHandler = (UINTN)&TimerInterruptHandle;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.Selector = CodeSegment;
|
||||
IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
|
||||
|
||||
//
|
||||
// If the CPU supports Debug Extensions(CPUID:01 EDX:BIT2), then
|
||||
@@ -75,16 +76,16 @@ InitializeDebugIdt (
|
||||
**/
|
||||
VOID *
|
||||
GetExceptionHandlerInIdtEntry (
|
||||
IN UINTN ExceptionNum
|
||||
IN UINTN ExceptionNum
|
||||
)
|
||||
{
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
|
||||
return (VOID *) (IdtEntry[ExceptionNum].Bits.OffsetLow |
|
||||
return (VOID *)(IdtEntry[ExceptionNum].Bits.OffsetLow |
|
||||
(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16) |
|
||||
(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetUpper) << 32));
|
||||
}
|
||||
@@ -98,15 +99,15 @@ GetExceptionHandlerInIdtEntry (
|
||||
**/
|
||||
VOID
|
||||
SetExceptionHandlerInIdtEntry (
|
||||
IN UINTN ExceptionNum,
|
||||
IN VOID *ExceptionHandler
|
||||
IN UINTN ExceptionNum,
|
||||
IN VOID *ExceptionHandler
|
||||
)
|
||||
{
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
|
||||
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
|
||||
IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler;
|
||||
IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16);
|
||||
|
@@ -12,10 +12,10 @@
|
||||
#include "ProcessorContext.h"
|
||||
#include "TransferProtocol.h"
|
||||
|
||||
#define DEBUG_SW_BREAKPOINT_SYMBOL 0xcc
|
||||
#define DEBUG_ARCH_SYMBOL DEBUG_DATA_BREAK_CPU_ARCH_X64
|
||||
#define DEBUG_SW_BREAKPOINT_SYMBOL 0xcc
|
||||
#define DEBUG_ARCH_SYMBOL DEBUG_DATA_BREAK_CPU_ARCH_X64
|
||||
|
||||
typedef DEBUG_DATA_X64_FX_SAVE_STATE DEBUG_DATA_FX_SAVE_STATE;
|
||||
typedef DEBUG_DATA_X64_SYSTEM_CONTEXT DEBUG_CPU_CONTEXT;
|
||||
typedef DEBUG_DATA_X64_FX_SAVE_STATE DEBUG_DATA_FX_SAVE_STATE;
|
||||
typedef DEBUG_DATA_X64_SYSTEM_CONTEXT DEBUG_CPU_CONTEXT;
|
||||
|
||||
#endif
|
||||
|
@@ -9,22 +9,22 @@
|
||||
#ifndef _DEBUG_EXCEPTION_H_
|
||||
#define _DEBUG_EXCEPTION_H_
|
||||
|
||||
#define DEBUG_EXCEPT_DIVIDE_ERROR 0
|
||||
#define DEBUG_EXCEPT_DEBUG 1
|
||||
#define DEBUG_EXCEPT_NMI 2
|
||||
#define DEBUG_EXCEPT_BREAKPOINT 3
|
||||
#define DEBUG_EXCEPT_OVERFLOW 4
|
||||
#define DEBUG_EXCEPT_BOUND 5
|
||||
#define DEBUG_EXCEPT_INVALID_OPCODE 6
|
||||
#define DEBUG_EXCEPT_DOUBLE_FAULT 8
|
||||
#define DEBUG_EXCEPT_INVALID_TSS 10
|
||||
#define DEBUG_EXCEPT_SEG_NOT_PRESENT 11
|
||||
#define DEBUG_EXCEPT_STACK_FAULT 12
|
||||
#define DEBUG_EXCEPT_GP_FAULT 13
|
||||
#define DEBUG_EXCEPT_PAGE_FAULT 14
|
||||
#define DEBUG_EXCEPT_FP_ERROR 16
|
||||
#define DEBUG_EXCEPT_ALIGNMENT_CHECK 17
|
||||
#define DEBUG_EXCEPT_MACHINE_CHECK 18
|
||||
#define DEBUG_EXCEPT_SIMD 19
|
||||
#define DEBUG_EXCEPT_DIVIDE_ERROR 0
|
||||
#define DEBUG_EXCEPT_DEBUG 1
|
||||
#define DEBUG_EXCEPT_NMI 2
|
||||
#define DEBUG_EXCEPT_BREAKPOINT 3
|
||||
#define DEBUG_EXCEPT_OVERFLOW 4
|
||||
#define DEBUG_EXCEPT_BOUND 5
|
||||
#define DEBUG_EXCEPT_INVALID_OPCODE 6
|
||||
#define DEBUG_EXCEPT_DOUBLE_FAULT 8
|
||||
#define DEBUG_EXCEPT_INVALID_TSS 10
|
||||
#define DEBUG_EXCEPT_SEG_NOT_PRESENT 11
|
||||
#define DEBUG_EXCEPT_STACK_FAULT 12
|
||||
#define DEBUG_EXCEPT_GP_FAULT 13
|
||||
#define DEBUG_EXCEPT_PAGE_FAULT 14
|
||||
#define DEBUG_EXCEPT_FP_ERROR 16
|
||||
#define DEBUG_EXCEPT_ALIGNMENT_CHECK 17
|
||||
#define DEBUG_EXCEPT_MACHINE_CHECK 18
|
||||
#define DEBUG_EXCEPT_SIMD 19
|
||||
|
||||
#endif
|
||||
|
@@ -8,15 +8,15 @@
|
||||
|
||||
#include "DxeDebugAgentLib.h"
|
||||
|
||||
DEBUG_AGENT_MAILBOX mMailbox;
|
||||
DEBUG_AGENT_MAILBOX *mMailboxPointer = NULL;
|
||||
IA32_IDT_GATE_DESCRIPTOR mIdtEntryTable[33];
|
||||
BOOLEAN mDxeCoreFlag = FALSE;
|
||||
BOOLEAN mMultiProcessorDebugSupport = FALSE;
|
||||
VOID *mSavedIdtTable = NULL;
|
||||
UINTN mSaveIdtTableSize = 0;
|
||||
BOOLEAN mDebugAgentInitialized = FALSE;
|
||||
BOOLEAN mSkipBreakpoint = FALSE;
|
||||
DEBUG_AGENT_MAILBOX mMailbox;
|
||||
DEBUG_AGENT_MAILBOX *mMailboxPointer = NULL;
|
||||
IA32_IDT_GATE_DESCRIPTOR mIdtEntryTable[33];
|
||||
BOOLEAN mDxeCoreFlag = FALSE;
|
||||
BOOLEAN mMultiProcessorDebugSupport = FALSE;
|
||||
VOID *mSavedIdtTable = NULL;
|
||||
UINTN mSaveIdtTableSize = 0;
|
||||
BOOLEAN mDebugAgentInitialized = FALSE;
|
||||
BOOLEAN mSkipBreakpoint = FALSE;
|
||||
|
||||
/**
|
||||
Check if debug agent support multi-processor.
|
||||
@@ -46,32 +46,33 @@ InternalConstructorWorker (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS Address;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
DEBUG_AGENT_MAILBOX *NewMailbox;
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
EFI_VECTOR_HANDOFF_INFO *VectorHandoffInfo;
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS Address;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
DEBUG_AGENT_MAILBOX *NewMailbox;
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
EFI_VECTOR_HANDOFF_INFO *VectorHandoffInfo;
|
||||
|
||||
//
|
||||
// Check persisted vector handoff info
|
||||
//
|
||||
Status = EFI_SUCCESS;
|
||||
Status = EFI_SUCCESS;
|
||||
GuidHob = GetFirstGuidHob (&gEfiVectorHandoffInfoPpiGuid);
|
||||
if (GuidHob != NULL && !mDxeCoreFlag) {
|
||||
if ((GuidHob != NULL) && !mDxeCoreFlag) {
|
||||
//
|
||||
// Check if configuration table is installed or not if GUIDed HOB existed,
|
||||
// only when Debug Agent is not linked by DXE Core
|
||||
//
|
||||
Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **) &VectorHandoffInfo);
|
||||
Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **)&VectorHandoffInfo);
|
||||
}
|
||||
if (GuidHob == NULL || Status != EFI_SUCCESS) {
|
||||
|
||||
if ((GuidHob == NULL) || (Status != EFI_SUCCESS)) {
|
||||
//
|
||||
// Install configuration table for persisted vector handoff info if GUIDed HOB cannot be found or
|
||||
// configuration table does not exist
|
||||
//
|
||||
Status = gBS->InstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) &mVectorHandoffInfoDebugAgent[0]);
|
||||
Status = gBS->InstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *)&mVectorHandoffInfoDebugAgent[0]);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));
|
||||
CpuDeadLoop ();
|
||||
@@ -84,12 +85,12 @@ InternalConstructorWorker (
|
||||
InstallSerialIo ();
|
||||
|
||||
Address = 0;
|
||||
Status = gBS->AllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiACPIMemoryNVS,
|
||||
EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),
|
||||
&Address
|
||||
);
|
||||
Status = gBS->AllocatePages (
|
||||
AllocateAnyPages,
|
||||
EfiACPIMemoryNVS,
|
||||
EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX) + PcdGet16 (PcdDebugPortHandleBufferSize)),
|
||||
&Address
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for mailbox!\n"));
|
||||
CpuDeadLoop ();
|
||||
@@ -97,14 +98,14 @@ InternalConstructorWorker (
|
||||
|
||||
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
|
||||
|
||||
NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
|
||||
NewMailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)Address;
|
||||
//
|
||||
// Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
|
||||
// and Debug Port Handle buffer may be free at runtime, SMM debug agent needs to access them
|
||||
//
|
||||
Mailbox = GetMailboxPointer ();
|
||||
CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));
|
||||
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16 (PcdDebugPortHandleBufferSize));
|
||||
//
|
||||
// Update Debug Port Handle in new Mailbox
|
||||
//
|
||||
@@ -113,7 +114,7 @@ InternalConstructorWorker (
|
||||
|
||||
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);
|
||||
|
||||
Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *) mMailboxPointer);
|
||||
Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *)mMailboxPointer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install configuration for mailbox!\n"));
|
||||
CpuDeadLoop ();
|
||||
@@ -157,11 +158,11 @@ GetMailboxFromConfigurationTable (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
EFI_STATUS Status;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
|
||||
Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &Mailbox);
|
||||
if (Status == EFI_SUCCESS && Mailbox != NULL) {
|
||||
Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **)&Mailbox);
|
||||
if ((Status == EFI_SUCCESS) && (Mailbox != NULL)) {
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
return Mailbox;
|
||||
} else {
|
||||
@@ -179,19 +180,20 @@ GetMailboxFromConfigurationTable (
|
||||
**/
|
||||
DEBUG_AGENT_MAILBOX *
|
||||
GetMailboxFromHob (
|
||||
IN VOID *HobStart
|
||||
IN VOID *HobStart
|
||||
)
|
||||
{
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
UINT64 *MailboxLocation;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
UINT64 *MailboxLocation;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
|
||||
GuidHob = GetNextGuidHob (&gEfiDebugAgentGuid, HobStart);
|
||||
if (GuidHob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
|
||||
MailboxLocation = (UINT64 *)(GET_GUID_HOB_DATA (GuidHob));
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
|
||||
return Mailbox;
|
||||
@@ -225,7 +227,7 @@ GetDebugPortHandle (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (DEBUG_PORT_HANDLE) (UINTN)(GetMailboxPointer ()->DebugPortHandle);
|
||||
return (DEBUG_PORT_HANDLE)(UINTN)(GetMailboxPointer ()->DebugPortHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,13 +242,13 @@ GetDebugPortHandle (
|
||||
**/
|
||||
VOID
|
||||
SetupDebugAgentEnvironment (
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox
|
||||
IN DEBUG_AGENT_MAILBOX *Mailbox
|
||||
)
|
||||
{
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
UINT16 IdtEntryCount;
|
||||
UINT64 DebugPortHandle;
|
||||
UINT32 DebugTimerFrequency;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
UINT16 IdtEntryCount;
|
||||
UINT64 DebugPortHandle;
|
||||
UINT32 DebugTimerFrequency;
|
||||
|
||||
if (mMultiProcessorDebugSupport) {
|
||||
InitializeSpinLock (&mDebugMpContext.MpContextSpinLock);
|
||||
@@ -255,26 +257,26 @@ SetupDebugAgentEnvironment (
|
||||
//
|
||||
// Clear Break CPU index value
|
||||
//
|
||||
mDebugMpContext.BreakAtCpuIndex = (UINT32) -1;
|
||||
mDebugMpContext.BreakAtCpuIndex = (UINT32)-1;
|
||||
}
|
||||
|
||||
//
|
||||
// Get original IDT address and size.
|
||||
//
|
||||
AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr);
|
||||
IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
|
||||
AsmReadIdtr ((IA32_DESCRIPTOR *)&Idtr);
|
||||
IdtEntryCount = (UINT16)((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
|
||||
if (IdtEntryCount < 33) {
|
||||
ZeroMem (&mIdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33);
|
||||
//
|
||||
// Copy original IDT table into new one
|
||||
//
|
||||
CopyMem (&mIdtEntryTable, (VOID *) Idtr.Base, Idtr.Limit + 1);
|
||||
CopyMem (&mIdtEntryTable, (VOID *)Idtr.Base, Idtr.Limit + 1);
|
||||
//
|
||||
// Load new IDT table
|
||||
//
|
||||
Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
|
||||
Idtr.Base = (UINTN) &mIdtEntryTable;
|
||||
AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr);
|
||||
Idtr.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
|
||||
Idtr.Base = (UINTN)&mIdtEntryTable;
|
||||
AsmWriteIdtr ((IA32_DESCRIPTOR *)&Idtr);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -294,6 +296,7 @@ SetupDebugAgentEnvironment (
|
||||
} else {
|
||||
ZeroMem (&mMailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
}
|
||||
|
||||
mMailboxPointer = &mMailbox;
|
||||
}
|
||||
|
||||
@@ -305,7 +308,7 @@ SetupDebugAgentEnvironment (
|
||||
//
|
||||
// Initialize debug communication port
|
||||
//
|
||||
DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)mMailboxPointer->DebugPortHandle, NULL);
|
||||
DebugPortHandle = (UINT64)(UINTN)DebugPortInitialize ((VOID *)(UINTN)mMailboxPointer->DebugPortHandle, NULL);
|
||||
UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
|
||||
|
||||
if (Mailbox == NULL) {
|
||||
@@ -326,7 +329,6 @@ SetupDebugAgentEnvironment (
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Initialize debug agent.
|
||||
|
||||
@@ -352,15 +354,15 @@ InitializeDebugAgent (
|
||||
IN DEBUG_AGENT_CONTINUE Function OPTIONAL
|
||||
)
|
||||
{
|
||||
UINT64 *MailboxLocation;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
BOOLEAN InterruptStatus;
|
||||
VOID *HobList;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_DESCRIPTOR *Ia32Idtr;
|
||||
IA32_IDT_ENTRY *Ia32IdtEntry;
|
||||
BOOLEAN PeriodicMode;
|
||||
UINTN TimerCycle;
|
||||
UINT64 *MailboxLocation;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
BOOLEAN InterruptStatus;
|
||||
VOID *HobList;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_DESCRIPTOR *Ia32Idtr;
|
||||
IA32_IDT_ENTRY *Ia32IdtEntry;
|
||||
BOOLEAN PeriodicMode;
|
||||
UINTN TimerCycle;
|
||||
|
||||
if (InitFlag == DEBUG_AGENT_INIT_DXE_AP) {
|
||||
//
|
||||
@@ -369,14 +371,15 @@ InitializeDebugAgent (
|
||||
InitializeLocalApicSoftwareEnable (TRUE);
|
||||
GetApicTimerState (NULL, &PeriodicMode, NULL);
|
||||
TimerCycle = GetApicTimerInitCount ();
|
||||
if (!PeriodicMode || TimerCycle == 0) {
|
||||
if (!PeriodicMode || (TimerCycle == 0)) {
|
||||
InitializeDebugTimer (NULL, FALSE);
|
||||
}
|
||||
|
||||
//
|
||||
// Invoked by AP, enable interrupt to let AP could receive IPI from other processors
|
||||
//
|
||||
EnableInterrupts ();
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -396,149 +399,151 @@ InitializeDebugAgent (
|
||||
MailboxLocation = NULL;
|
||||
|
||||
switch (InitFlag) {
|
||||
case DEBUG_AGENT_INIT_DXE_LOAD:
|
||||
//
|
||||
// Check if Debug Agent has been initialized before
|
||||
//
|
||||
if (IsDebugAgentInitialzed ()) {
|
||||
DEBUG ((DEBUG_INFO, "Debug Agent: The former agent will be overwritten by the new one!\n"));
|
||||
}
|
||||
|
||||
case DEBUG_AGENT_INIT_DXE_LOAD:
|
||||
//
|
||||
// Check if Debug Agent has been initialized before
|
||||
//
|
||||
if (IsDebugAgentInitialzed ()) {
|
||||
DEBUG ((DEBUG_INFO, "Debug Agent: The former agent will be overwritten by the new one!\n"));
|
||||
}
|
||||
mMultiProcessorDebugSupport = TRUE;
|
||||
//
|
||||
// Save original IDT table
|
||||
//
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
mSaveIdtTableSize = IdtDescriptor.Limit + 1;
|
||||
mSavedIdtTable = AllocateCopyPool (mSaveIdtTableSize, (VOID *)IdtDescriptor.Base);
|
||||
//
|
||||
// Check if Debug Agent initialized in DXE phase
|
||||
//
|
||||
Mailbox = GetMailboxFromConfigurationTable ();
|
||||
if (Mailbox == NULL) {
|
||||
//
|
||||
// Try to get mailbox from GUIDed HOB build in PEI
|
||||
//
|
||||
HobList = GetHobList ();
|
||||
Mailbox = GetMailboxFromHob (HobList);
|
||||
}
|
||||
|
||||
mMultiProcessorDebugSupport = TRUE;
|
||||
//
|
||||
// Save original IDT table
|
||||
//
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
mSaveIdtTableSize = IdtDescriptor.Limit + 1;
|
||||
mSavedIdtTable = AllocateCopyPool (mSaveIdtTableSize, (VOID *) IdtDescriptor.Base);
|
||||
//
|
||||
// Check if Debug Agent initialized in DXE phase
|
||||
//
|
||||
Mailbox = GetMailboxFromConfigurationTable ();
|
||||
if (Mailbox == NULL) {
|
||||
//
|
||||
// Set up Debug Agent Environment and try to connect HOST if required
|
||||
//
|
||||
SetupDebugAgentEnvironment (Mailbox);
|
||||
//
|
||||
// For DEBUG_AGENT_INIT_S3, needn't to install configuration table and EFI Serial IO protocol
|
||||
// For DEBUG_AGENT_INIT_DXE_CORE, InternalConstructorWorker() will invoked in Constructor()
|
||||
//
|
||||
InternalConstructorWorker ();
|
||||
//
|
||||
// Enable Debug Timer interrupt
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
//
|
||||
// Enable interrupt to receive Debug Timer interrupt
|
||||
//
|
||||
EnableInterrupts ();
|
||||
|
||||
mDebugAgentInitialized = TRUE;
|
||||
FindAndReportModuleImageInfo (SIZE_4KB);
|
||||
|
||||
*(EFI_STATUS *)Context = EFI_SUCCESS;
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_DXE_UNLOAD:
|
||||
if (mDebugAgentInitialized) {
|
||||
if (IsHostAttached ()) {
|
||||
*(EFI_STATUS *)Context = EFI_ACCESS_DENIED;
|
||||
//
|
||||
// Enable Debug Timer interrupt again
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
} else {
|
||||
//
|
||||
// Restore original IDT table
|
||||
//
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
IdtDescriptor.Limit = (UINT16)(mSaveIdtTableSize - 1);
|
||||
CopyMem ((VOID *)IdtDescriptor.Base, mSavedIdtTable, mSaveIdtTableSize);
|
||||
AsmWriteIdtr (&IdtDescriptor);
|
||||
FreePool (mSavedIdtTable);
|
||||
mDebugAgentInitialized = FALSE;
|
||||
*(EFI_STATUS *)Context = EFI_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
*(EFI_STATUS *)Context = EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
//
|
||||
// Restore interrupt state.
|
||||
//
|
||||
SetInterruptState (InterruptStatus);
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_DXE_CORE:
|
||||
mDxeCoreFlag = TRUE;
|
||||
mMultiProcessorDebugSupport = TRUE;
|
||||
//
|
||||
// Try to get mailbox from GUIDed HOB build in PEI
|
||||
//
|
||||
HobList = GetHobList ();
|
||||
HobList = Context;
|
||||
Mailbox = GetMailboxFromHob (HobList);
|
||||
}
|
||||
//
|
||||
// Set up Debug Agent Environment and try to connect HOST if required
|
||||
//
|
||||
SetupDebugAgentEnvironment (Mailbox);
|
||||
//
|
||||
// For DEBUG_AGENT_INIT_S3, needn't to install configuration table and EFI Serial IO protocol
|
||||
// For DEBUG_AGENT_INIT_DXE_CORE, InternalConstructorWorker() will invoked in Constructor()
|
||||
//
|
||||
InternalConstructorWorker ();
|
||||
//
|
||||
// Enable Debug Timer interrupt
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
//
|
||||
// Enable interrupt to receive Debug Timer interrupt
|
||||
//
|
||||
EnableInterrupts ();
|
||||
//
|
||||
// Set up Debug Agent Environment and try to connect HOST if required
|
||||
//
|
||||
SetupDebugAgentEnvironment (Mailbox);
|
||||
//
|
||||
// Enable Debug Timer interrupt
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
//
|
||||
// Enable interrupt to receive Debug Timer interrupt
|
||||
//
|
||||
EnableInterrupts ();
|
||||
|
||||
mDebugAgentInitialized = TRUE;
|
||||
FindAndReportModuleImageInfo (SIZE_4KB);
|
||||
break;
|
||||
|
||||
*(EFI_STATUS *)Context = EFI_SUCCESS;
|
||||
case DEBUG_AGENT_INIT_S3:
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_DXE_UNLOAD:
|
||||
if (mDebugAgentInitialized) {
|
||||
if (IsHostAttached ()) {
|
||||
*(EFI_STATUS *)Context = EFI_ACCESS_DENIED;
|
||||
//
|
||||
// Enable Debug Timer interrupt again
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
} else {
|
||||
//
|
||||
// Restore original IDT table
|
||||
//
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
IdtDescriptor.Limit = (UINT16) (mSaveIdtTableSize - 1);
|
||||
CopyMem ((VOID *) IdtDescriptor.Base, mSavedIdtTable, mSaveIdtTableSize);
|
||||
AsmWriteIdtr (&IdtDescriptor);
|
||||
FreePool (mSavedIdtTable);
|
||||
mDebugAgentInitialized = FALSE;
|
||||
*(EFI_STATUS *)Context = EFI_SUCCESS;
|
||||
if (Context != NULL) {
|
||||
Ia32Idtr = (IA32_DESCRIPTOR *)Context;
|
||||
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
|
||||
MailboxLocation = (UINT64 *)((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
|
||||
((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
}
|
||||
} else {
|
||||
*(EFI_STATUS *)Context = EFI_NOT_STARTED;
|
||||
}
|
||||
|
||||
//
|
||||
// Restore interrupt state.
|
||||
//
|
||||
SetInterruptState (InterruptStatus);
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_DXE_CORE:
|
||||
mDxeCoreFlag = TRUE;
|
||||
mMultiProcessorDebugSupport = TRUE;
|
||||
//
|
||||
// Try to get mailbox from GUIDed HOB build in PEI
|
||||
//
|
||||
HobList = Context;
|
||||
Mailbox = GetMailboxFromHob (HobList);
|
||||
//
|
||||
// Set up Debug Agent Environment and try to connect HOST if required
|
||||
//
|
||||
SetupDebugAgentEnvironment (Mailbox);
|
||||
//
|
||||
// Enable Debug Timer interrupt
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
//
|
||||
// Enable interrupt to receive Debug Timer interrupt
|
||||
//
|
||||
EnableInterrupts ();
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_S3:
|
||||
|
||||
if (Context != NULL) {
|
||||
Ia32Idtr = (IA32_DESCRIPTOR *) Context;
|
||||
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
|
||||
MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
|
||||
((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
}
|
||||
//
|
||||
// Save Mailbox pointer in global variable
|
||||
//
|
||||
mMailboxPointer = Mailbox;
|
||||
//
|
||||
// Set up Debug Agent Environment and try to connect HOST if required
|
||||
//
|
||||
SetupDebugAgentEnvironment (Mailbox);
|
||||
//
|
||||
// Disable interrupt
|
||||
//
|
||||
DisableInterrupts ();
|
||||
FindAndReportModuleImageInfo (SIZE_4KB);
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT) == 1) {
|
||||
//
|
||||
// If Boot Script entry break is set, code will be break at here.
|
||||
// Save Mailbox pointer in global variable
|
||||
//
|
||||
CpuBreakpoint ();
|
||||
}
|
||||
break;
|
||||
mMailboxPointer = Mailbox;
|
||||
//
|
||||
// Set up Debug Agent Environment and try to connect HOST if required
|
||||
//
|
||||
SetupDebugAgentEnvironment (Mailbox);
|
||||
//
|
||||
// Disable interrupt
|
||||
//
|
||||
DisableInterrupts ();
|
||||
FindAndReportModuleImageInfo (SIZE_4KB);
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT) == 1) {
|
||||
//
|
||||
// If Boot Script entry break is set, code will be break at here.
|
||||
//
|
||||
CpuBreakpoint ();
|
||||
}
|
||||
|
||||
default:
|
||||
//
|
||||
// Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
|
||||
// Debug Agent library instance.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
//
|
||||
// Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
|
||||
// Debug Agent library instance.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -153,7 +153,7 @@ EFI_SERIAL_IO_MODE mSerialIoMode = {
|
||||
//
|
||||
// EFI_SERIAL_IO_PROTOCOL instance
|
||||
//
|
||||
EFI_SERIAL_IO_PROTOCOL mSerialIo = {
|
||||
EFI_SERIAL_IO_PROTOCOL mSerialIo = {
|
||||
SERIAL_IO_INTERFACE_REVISION,
|
||||
SerialReset,
|
||||
SerialSetAttributes,
|
||||
@@ -168,22 +168,22 @@ EFI_SERIAL_IO_PROTOCOL mSerialIo = {
|
||||
// Serial IO Device Path definition
|
||||
//
|
||||
typedef struct {
|
||||
VENDOR_DEVICE_PATH VendorDevicePath;
|
||||
UART_DEVICE_PATH UartDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
|
||||
VENDOR_DEVICE_PATH VendorDevicePath;
|
||||
UART_DEVICE_PATH UartDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
|
||||
} SERIAL_IO_DEVICE_PATH;
|
||||
|
||||
//
|
||||
// Serial IO Device Patch instance
|
||||
//
|
||||
SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = {
|
||||
SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = {
|
||||
{
|
||||
{
|
||||
HARDWARE_DEVICE_PATH,
|
||||
HW_VENDOR_DP,
|
||||
{
|
||||
(UINT8) (sizeof (VENDOR_DEVICE_PATH)),
|
||||
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
||||
(UINT8)(sizeof (VENDOR_DEVICE_PATH)),
|
||||
(UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
||||
}
|
||||
},
|
||||
EFI_DEBUG_AGENT_GUID,
|
||||
@@ -193,8 +193,8 @@ SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = {
|
||||
MESSAGING_DEVICE_PATH,
|
||||
MSG_UART_DP,
|
||||
{
|
||||
(UINT8) (sizeof (UART_DEVICE_PATH)),
|
||||
(UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8)
|
||||
(UINT8)(sizeof (UART_DEVICE_PATH)),
|
||||
(UINT8)((sizeof (UART_DEVICE_PATH)) >> 8)
|
||||
}
|
||||
},
|
||||
0,
|
||||
@@ -213,7 +213,7 @@ SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = {
|
||||
}
|
||||
};
|
||||
|
||||
#define DEBGU_SERIAL_IO_FIFO_DEPTH 10
|
||||
#define DEBGU_SERIAL_IO_FIFO_DEPTH 10
|
||||
//
|
||||
// Data buffer for Terminal input character and Debug Symbols.
|
||||
// The depth is DEBGU_SERIAL_IO_FIFO_DEPTH.
|
||||
@@ -224,19 +224,23 @@ SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = {
|
||||
// Data[] UINT8: An array, which used to store data.
|
||||
//
|
||||
typedef struct {
|
||||
UINT8 First;
|
||||
UINT8 Last;
|
||||
UINT8 Surplus;
|
||||
UINT8 Data[DEBGU_SERIAL_IO_FIFO_DEPTH];
|
||||
UINT8 First;
|
||||
UINT8 Last;
|
||||
UINT8 Surplus;
|
||||
UINT8 Data[DEBGU_SERIAL_IO_FIFO_DEPTH];
|
||||
} DEBUG_SERIAL_FIFO;
|
||||
|
||||
//
|
||||
// Global Variables
|
||||
//
|
||||
EFI_HANDLE mSerialIoHandle = NULL;
|
||||
UINTN mLoopbackBuffer = 0;
|
||||
DEBUG_SERIAL_FIFO mSerialFifoForTerminal = {0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }};
|
||||
DEBUG_SERIAL_FIFO mSerialFifoForDebug = {0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }};
|
||||
EFI_HANDLE mSerialIoHandle = NULL;
|
||||
UINTN mLoopbackBuffer = 0;
|
||||
DEBUG_SERIAL_FIFO mSerialFifoForTerminal = {
|
||||
0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }
|
||||
};
|
||||
DEBUG_SERIAL_FIFO mSerialFifoForDebug = {
|
||||
0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }
|
||||
};
|
||||
|
||||
/**
|
||||
Detect whether specific FIFO is empty or not.
|
||||
@@ -248,7 +252,7 @@ DEBUG_SERIAL_FIFO mSerialFifoForDebug = {0, 0, DEBGU_SERIAL_IO_FIF
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDebugTermianlFifoEmpty (
|
||||
IN DEBUG_SERIAL_FIFO *Fifo
|
||||
IN DEBUG_SERIAL_FIFO *Fifo
|
||||
)
|
||||
{
|
||||
if (Fifo->Surplus == DEBGU_SERIAL_IO_FIFO_DEPTH) {
|
||||
@@ -268,7 +272,7 @@ IsDebugTermianlFifoEmpty (
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDebugTerminalFifoFull (
|
||||
IN DEBUG_SERIAL_FIFO *Fifo
|
||||
IN DEBUG_SERIAL_FIFO *Fifo
|
||||
)
|
||||
|
||||
{
|
||||
@@ -291,8 +295,8 @@ IsDebugTerminalFifoFull (
|
||||
**/
|
||||
EFI_STATUS
|
||||
DebugTerminalFifoAdd (
|
||||
IN DEBUG_SERIAL_FIFO *Fifo,
|
||||
IN UINT8 Data
|
||||
IN DEBUG_SERIAL_FIFO *Fifo,
|
||||
IN UINT8 Data
|
||||
)
|
||||
|
||||
{
|
||||
@@ -302,6 +306,7 @@ DebugTerminalFifoAdd (
|
||||
if (IsDebugTerminalFifoFull (Fifo)) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// FIFO is not full can add data
|
||||
//
|
||||
@@ -327,8 +332,8 @@ DebugTerminalFifoAdd (
|
||||
**/
|
||||
EFI_STATUS
|
||||
DebugTerminalFifoRemove (
|
||||
IN DEBUG_SERIAL_FIFO *Fifo,
|
||||
OUT UINT8 *Data
|
||||
IN DEBUG_SERIAL_FIFO *Fifo,
|
||||
OUT UINT8 *Data
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -337,6 +342,7 @@ DebugTerminalFifoRemove (
|
||||
if (IsDebugTermianlFifoEmpty (Fifo)) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// FIFO is not empty, can remove data
|
||||
//
|
||||
@@ -359,12 +365,14 @@ InstallSerialIo (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&mSerialIoHandle,
|
||||
&gEfiDevicePathProtocolGuid, &mSerialIoDevicePath,
|
||||
&gEfiSerialIoProtocolGuid, &mSerialIo,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
&mSerialIoDevicePath,
|
||||
&gEfiSerialIoProtocolGuid,
|
||||
&mSerialIo,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
@@ -387,7 +395,7 @@ SerialReset (
|
||||
)
|
||||
{
|
||||
mSerialIoMode.ControlMask = SERIAL_PORT_DEFAULT_CONTROL_MASK;
|
||||
mLoopbackBuffer = 0;
|
||||
mLoopbackBuffer = 0;
|
||||
//
|
||||
// Not reset serial device hardware indeed.
|
||||
//
|
||||
@@ -445,7 +453,7 @@ SerialSetAttributes (
|
||||
// SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH. The Debug Communication Library may actually be
|
||||
// using a larger FIFO, but there is no way to tell.
|
||||
//
|
||||
if (ReceiveFifoDepth == 0 || ReceiveFifoDepth >= SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH) {
|
||||
if ((ReceiveFifoDepth == 0) || (ReceiveFifoDepth >= SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH)) {
|
||||
mSerialIoMode.ReceiveFifoDepth = SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH;
|
||||
} else {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
@@ -478,6 +486,7 @@ SerialSetControl (
|
||||
if ((Control & (~EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE)) != 0) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mSerialIoMode.ControlMask = Control;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -498,9 +507,9 @@ SerialGetControl (
|
||||
OUT UINT32 *Control
|
||||
)
|
||||
{
|
||||
DEBUG_PORT_HANDLE Handle;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
EFI_TPL Tpl;
|
||||
DEBUG_PORT_HANDLE Handle;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
EFI_TPL Tpl;
|
||||
|
||||
//
|
||||
// Raise TPL to prevent recursion from EFI timer interrupts
|
||||
@@ -511,7 +520,7 @@ SerialGetControl (
|
||||
// Save and disable Debug Timer interrupt to avoid it to access Debug Port
|
||||
//
|
||||
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
|
||||
Handle = GetDebugPortHandle ();
|
||||
Handle = GetDebugPortHandle ();
|
||||
|
||||
//
|
||||
// Always assume the output buffer is empty and the Debug Communication Library can process
|
||||
@@ -561,9 +570,9 @@ SerialWrite (
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
DEBUG_PORT_HANDLE Handle;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
EFI_TPL Tpl;
|
||||
DEBUG_PORT_HANDLE Handle;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
EFI_TPL Tpl;
|
||||
|
||||
//
|
||||
// Raise TPL to prevent recursion from EFI timer interrupts
|
||||
@@ -574,18 +583,20 @@ SerialWrite (
|
||||
// Save and disable Debug Timer interrupt to avoid it to access Debug Port
|
||||
//
|
||||
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
|
||||
Handle = GetDebugPortHandle ();
|
||||
Handle = GetDebugPortHandle ();
|
||||
|
||||
if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) {
|
||||
if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) {
|
||||
if (*BufferSize == 0) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if ((mLoopbackBuffer & SERIAL_PORT_LOOPBACK_BUFFER_FULL) != 0) {
|
||||
*BufferSize = 0;
|
||||
return EFI_TIMEOUT;
|
||||
}
|
||||
|
||||
mLoopbackBuffer = SERIAL_PORT_LOOPBACK_BUFFER_FULL | *(UINT8 *)Buffer;
|
||||
*BufferSize = 1;
|
||||
*BufferSize = 1;
|
||||
} else {
|
||||
*BufferSize = DebugPortWriteBuffer (Handle, Buffer, *BufferSize);
|
||||
}
|
||||
@@ -624,14 +635,14 @@ SerialRead (
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
UINT8 *Uint8Buffer;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
EFI_TPL Tpl;
|
||||
DEBUG_PORT_HANDLE Handle;
|
||||
DEBUG_PACKET_HEADER DebugHeader;
|
||||
UINT8 *Data8;
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
UINT8 *Uint8Buffer;
|
||||
BOOLEAN DebugTimerInterruptState;
|
||||
EFI_TPL Tpl;
|
||||
DEBUG_PORT_HANDLE Handle;
|
||||
DEBUG_PACKET_HEADER DebugHeader;
|
||||
UINT8 *Data8;
|
||||
|
||||
//
|
||||
// Raise TPL to prevent recursion from EFI timer interrupts
|
||||
@@ -642,17 +653,18 @@ SerialRead (
|
||||
// Save and disable Debug Timer interrupt to avoid it to access Debug Port
|
||||
//
|
||||
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
|
||||
Handle = GetDebugPortHandle ();
|
||||
Handle = GetDebugPortHandle ();
|
||||
|
||||
Data8 = (UINT8 *) &DebugHeader;
|
||||
Data8 = (UINT8 *)&DebugHeader;
|
||||
Uint8Buffer = (UINT8 *)Buffer;
|
||||
if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) {
|
||||
if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) {
|
||||
if ((mLoopbackBuffer & SERIAL_PORT_LOOPBACK_BUFFER_FULL) == 0) {
|
||||
return EFI_TIMEOUT;
|
||||
}
|
||||
*Uint8Buffer = (UINT8)(mLoopbackBuffer & 0xff);
|
||||
|
||||
*Uint8Buffer = (UINT8)(mLoopbackBuffer & 0xff);
|
||||
mLoopbackBuffer = 0;
|
||||
*BufferSize = 1;
|
||||
*BufferSize = 1;
|
||||
} else {
|
||||
for (Index = 0; Index < *BufferSize; Index++) {
|
||||
//
|
||||
@@ -661,15 +673,17 @@ SerialRead (
|
||||
Status = DebugTerminalFifoRemove (&mSerialFifoForTerminal, Data8);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
*Uint8Buffer = *Data8;
|
||||
Uint8Buffer ++;
|
||||
Uint8Buffer++;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Read the input character from Debug Port
|
||||
//
|
||||
if (!DebugPortPollBuffer (Handle)) {
|
||||
break;
|
||||
}
|
||||
|
||||
DebugAgentReadBuffer (Handle, Data8, 1, 0);
|
||||
|
||||
if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {
|
||||
@@ -684,14 +698,16 @@ SerialRead (
|
||||
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Terminal Timer break symbol received %x", DebugHeader.Command);
|
||||
DebugTerminalFifoAdd (&mSerialFifoForDebug, DebugHeader.Command);
|
||||
}
|
||||
|
||||
if (Status == EFI_TIMEOUT) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
*Uint8Buffer = *Data8;
|
||||
Uint8Buffer ++;
|
||||
Uint8Buffer++;
|
||||
}
|
||||
}
|
||||
|
||||
*BufferSize = (UINTN)Uint8Buffer - (UINTN)Buffer;
|
||||
}
|
||||
|
||||
@@ -720,19 +736,19 @@ SerialRead (
|
||||
**/
|
||||
EFI_STATUS
|
||||
DebugReadBreakFromDebugPort (
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
DEBUG_PACKET_HEADER DebugHeader;
|
||||
UINT8 *Data8;
|
||||
EFI_STATUS Status;
|
||||
DEBUG_PACKET_HEADER DebugHeader;
|
||||
UINT8 *Data8;
|
||||
|
||||
*BreakSymbol = 0;
|
||||
//
|
||||
// If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty.
|
||||
//
|
||||
Data8 = (UINT8 *) &DebugHeader;
|
||||
Data8 = (UINT8 *)&DebugHeader;
|
||||
while (TRUE) {
|
||||
//
|
||||
// If start symbol is not received
|
||||
@@ -743,6 +759,7 @@ DebugReadBreakFromDebugPort (
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to read the start symbol
|
||||
//
|
||||
@@ -752,6 +769,7 @@ DebugReadBreakFromDebugPort (
|
||||
*BreakSymbol = *Data8;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {
|
||||
Status = ReadRemainingBreakPacket (Handle, &DebugHeader);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
@@ -759,6 +777,7 @@ DebugReadBreakFromDebugPort (
|
||||
*BreakSymbol = DebugHeader.Command;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if (Status == EFI_TIMEOUT) {
|
||||
break;
|
||||
}
|
||||
@@ -785,12 +804,12 @@ DebugReadBreakFromDebugPort (
|
||||
**/
|
||||
EFI_STATUS
|
||||
DebugReadBreakSymbol (
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT8 Data8;
|
||||
EFI_STATUS Status;
|
||||
UINT8 Data8;
|
||||
|
||||
//
|
||||
// Read break symbol from debug FIFO firstly
|
||||
|
@@ -10,15 +10,14 @@
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSkipBreakpoint = FALSE;
|
||||
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi = {
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi = {
|
||||
&mVectorHandoffInfoDebugAgent[0]
|
||||
};
|
||||
|
||||
//
|
||||
// Ppis to be installed
|
||||
//
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mVectorHandoffInfoPpiList[] = {
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mVectorHandoffInfoPpiList[] = {
|
||||
{
|
||||
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
||||
&gEfiVectorHandoffInfoPpiGuid,
|
||||
@@ -26,7 +25,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_PPI_DESCRIPTOR mVectorHandoffInf
|
||||
}
|
||||
};
|
||||
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mDebugAgentMemoryDiscoveredNotifyList[1] = {
|
||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mDebugAgentMemoryDiscoveredNotifyList[1] = {
|
||||
{
|
||||
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
||||
&gEfiPeiMemoryDiscoveredPpiGuid,
|
||||
@@ -61,19 +60,19 @@ MultiProcessorDebugSupport (
|
||||
**/
|
||||
EFI_STATUS
|
||||
DebugReadBreakSymbol (
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
DEBUG_PACKET_HEADER DebugHeader;
|
||||
UINT8 *Data8;
|
||||
EFI_STATUS Status;
|
||||
DEBUG_PACKET_HEADER DebugHeader;
|
||||
UINT8 *Data8;
|
||||
|
||||
*BreakSymbol = 0;
|
||||
//
|
||||
// If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty.
|
||||
//
|
||||
Data8 = (UINT8 *) &DebugHeader;
|
||||
Data8 = (UINT8 *)&DebugHeader;
|
||||
while (TRUE) {
|
||||
//
|
||||
// If start symbol is not received
|
||||
@@ -84,6 +83,7 @@ DebugReadBreakSymbol (
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to read the start symbol
|
||||
//
|
||||
@@ -93,6 +93,7 @@ DebugReadBreakSymbol (
|
||||
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *BreakSymbol);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {
|
||||
Status = ReadRemainingBreakPacket (Handle, &DebugHeader);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
@@ -100,6 +101,7 @@ DebugReadBreakSymbol (
|
||||
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer break symbol received %x", *BreakSymbol);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
if (Status == EFI_TIMEOUT) {
|
||||
break;
|
||||
}
|
||||
@@ -118,13 +120,13 @@ GetLocationSavedMailboxPointerInIdtEntry (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINTN *MailboxLocation;
|
||||
UINTN *MailboxLocation;
|
||||
|
||||
MailboxLocation = (UINTN *) GetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR);
|
||||
MailboxLocation = (UINTN *)GetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR);
|
||||
//
|
||||
// *MailboxLocation is the pointer to Mailbox
|
||||
//
|
||||
VerifyMailboxChecksum ((DEBUG_AGENT_MAILBOX *) (*MailboxLocation));
|
||||
VerifyMailboxChecksum ((DEBUG_AGENT_MAILBOX *)(*MailboxLocation));
|
||||
return MailboxLocation;
|
||||
}
|
||||
|
||||
@@ -136,7 +138,7 @@ GetLocationSavedMailboxPointerInIdtEntry (
|
||||
**/
|
||||
VOID
|
||||
SetLocationSavedMailboxPointerInIdtEntry (
|
||||
IN VOID *MailboxLocation
|
||||
IN VOID *MailboxLocation
|
||||
)
|
||||
{
|
||||
SetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR, MailboxLocation);
|
||||
@@ -153,13 +155,14 @@ GetMailboxLocationFromHob (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
|
||||
GuidHob = GetFirstGuidHob (&gEfiDebugAgentGuid);
|
||||
if (GuidHob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
|
||||
|
||||
return (UINT64 *)(GET_GUID_HOB_DATA (GuidHob));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,12 +185,13 @@ GetMailboxPointer (
|
||||
// Get mailbox from IDT entry firstly
|
||||
//
|
||||
MailboxLocationInIdt = GetLocationSavedMailboxPointerInIdtEntry ();
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInIdt);
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInIdt);
|
||||
//
|
||||
// Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() nested
|
||||
//
|
||||
if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1 ||
|
||||
Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL) {
|
||||
if ((Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1) ||
|
||||
(Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL))
|
||||
{
|
||||
//
|
||||
// If mailbox was setup in SEC or the current CPU arch is different from the init arch
|
||||
// Debug Agent initialized, return the mailbox from IDT entry directly.
|
||||
@@ -201,12 +205,12 @@ GetMailboxPointer (
|
||||
// Compare mailbox in IDT entry with mailbox in HOB,
|
||||
// need to fix mailbox location if HOB moved by PEI CORE
|
||||
//
|
||||
if (MailboxLocationInHob != MailboxLocationInIdt && MailboxLocationInHob != NULL) {
|
||||
if ((MailboxLocationInHob != MailboxLocationInIdt) && (MailboxLocationInHob != NULL)) {
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInHob);
|
||||
//
|
||||
// Fix up Debug Port handler and save new mailbox in IDT entry
|
||||
//
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + ((UINTN)(MailboxLocationInHob) - (UINTN)MailboxLocationInIdt));
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + ((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;
|
||||
@@ -232,11 +236,11 @@ GetDebugPortHandle (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
DEBUG_AGENT_MAILBOX *DebugAgentMailbox;
|
||||
DEBUG_AGENT_MAILBOX *DebugAgentMailbox;
|
||||
|
||||
DebugAgentMailbox = GetMailboxPointer ();
|
||||
|
||||
return (DEBUG_PORT_HANDLE) (UINTN)(DebugAgentMailbox->DebugPortHandle);
|
||||
return (DEBUG_PORT_HANDLE)(UINTN)(DebugAgentMailbox->DebugPortHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,17 +256,17 @@ GetDebugPortHandle (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DebugAgentCallbackMemoryDiscoveredPpi (
|
||||
IN EFI_PEI_SERVICES **PeiServices,
|
||||
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
||||
IN VOID *Ppi
|
||||
IN EFI_PEI_SERVICES **PeiServices,
|
||||
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
||||
IN VOID *Ppi
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
BOOLEAN InterruptStatus;
|
||||
EFI_PHYSICAL_ADDRESS Address;
|
||||
DEBUG_AGENT_MAILBOX *NewMailbox;
|
||||
UINT64 *MailboxLocationInHob;
|
||||
EFI_STATUS Status;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
BOOLEAN InterruptStatus;
|
||||
EFI_PHYSICAL_ADDRESS Address;
|
||||
DEBUG_AGENT_MAILBOX *NewMailbox;
|
||||
UINT64 *MailboxLocationInHob;
|
||||
|
||||
//
|
||||
// Save and disable original interrupt status
|
||||
@@ -274,11 +278,11 @@ DebugAgentCallbackMemoryDiscoveredPpi (
|
||||
//
|
||||
Status = PeiServicesAllocatePages (
|
||||
EfiACPIMemoryNVS,
|
||||
EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),
|
||||
EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX) + PcdGet16 (PcdDebugPortHandleBufferSize)),
|
||||
&Address
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
|
||||
NewMailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)Address;
|
||||
//
|
||||
// Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
|
||||
// and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
|
||||
@@ -286,7 +290,7 @@ DebugAgentCallbackMemoryDiscoveredPpi (
|
||||
//
|
||||
Mailbox = GetMailboxPointer ();
|
||||
CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));
|
||||
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16 (PcdDebugPortHandleBufferSize));
|
||||
//
|
||||
// Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one
|
||||
//
|
||||
@@ -375,238 +379,247 @@ InitializeDebugAgent (
|
||||
//
|
||||
// Disable interrupts and save current interrupt state
|
||||
//
|
||||
CpuInterruptState = SaveAndDisableInterrupts();
|
||||
CpuInterruptState = SaveAndDisableInterrupts ();
|
||||
|
||||
switch (InitFlag) {
|
||||
case DEBUG_AGENT_INIT_PREMEM_SEC:
|
||||
|
||||
case DEBUG_AGENT_INIT_PREMEM_SEC:
|
||||
InitializeDebugIdt ();
|
||||
|
||||
InitializeDebugIdt ();
|
||||
|
||||
MailboxLocation = (UINT64)(UINTN)&MailboxInStack;
|
||||
Mailbox = &MailboxInStack;
|
||||
ZeroMem ((VOID *) Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
//
|
||||
// Get and save debug port handle and set the length of memory block.
|
||||
//
|
||||
SetLocationSavedMailboxPointerInIdtEntry (&MailboxLocation);
|
||||
//
|
||||
// Force error message could be printed during the first shakehand between Target/HOST.
|
||||
//
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DEBUG_AGENT_ERROR);
|
||||
//
|
||||
// Save init arch type when debug agent initialized
|
||||
//
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
|
||||
//
|
||||
// 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;
|
||||
Phase2Context.Function = Function;
|
||||
DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);
|
||||
//
|
||||
// If reaches here, it means Debug Port initialization failed.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: Debug port initialization failed.\n"));
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_POSTMEM_SEC:
|
||||
Mailbox = GetMailboxPointer ();
|
||||
//
|
||||
// Memory has been ready
|
||||
//
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
|
||||
if (IsHostAttached ()) {
|
||||
MailboxLocation = (UINT64)(UINTN)&MailboxInStack;
|
||||
Mailbox = &MailboxInStack;
|
||||
ZeroMem ((VOID *)Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
//
|
||||
// Trigger one software interrupt to inform HOST
|
||||
// Get and save debug port handle and set the length of memory block.
|
||||
//
|
||||
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
|
||||
}
|
||||
//
|
||||
// Install Vector Handoff Info PPI to persist vectors used by Debug Agent
|
||||
//
|
||||
Status = PeiServicesInstallPpi (&mVectorHandoffInfoPpiList[0]);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
//
|
||||
// Fix up Debug Port handle address and mailbox address
|
||||
//
|
||||
DebugAgentContext = (DEBUG_AGENT_CONTEXT_POSTMEM_SEC *) Context;
|
||||
if (DebugAgentContext != NULL) {
|
||||
DebugPortHandle = (UINT64)(UINT32)(Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset);
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *) ((UINTN) Mailbox + DebugAgentContext->StackMigrateOffset);
|
||||
MailboxLocation = (UINT64)(UINTN)Mailbox;
|
||||
SetLocationSavedMailboxPointerInIdtEntry (&MailboxLocation);
|
||||
//
|
||||
// Build mailbox location in HOB and fix-up its address
|
||||
// Force error message could be printed during the first shakehand between Target/HOST.
|
||||
//
|
||||
MailboxLocationPointer = BuildGuidDataHob (
|
||||
&gEfiDebugAgentGuid,
|
||||
&MailboxLocation,
|
||||
sizeof (UINT64)
|
||||
);
|
||||
MailboxLocationPointer = (UINT64 *) ((UINTN) MailboxLocationPointer + DebugAgentContext->HeapMigrateOffset);
|
||||
} else {
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DEBUG_AGENT_ERROR);
|
||||
//
|
||||
// DebugAgentContext is NULL. Then, Mailbox can directly be copied into memory.
|
||||
// Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer
|
||||
// Save init arch type when debug agent initialized
|
||||
//
|
||||
Status = PeiServicesAllocatePages (
|
||||
EfiACPIMemoryNVS,
|
||||
EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)),
|
||||
&Address
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to allocate pages!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
|
||||
//
|
||||
// Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
|
||||
// and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
|
||||
// reallocates the HOB.
|
||||
//
|
||||
CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize));
|
||||
UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));
|
||||
MailboxLocation = (UINT64)(UINTN)NewMailbox;
|
||||
//
|
||||
// Build mailbox location in HOB
|
||||
//
|
||||
MailboxLocationPointer = BuildGuidDataHob (
|
||||
&gEfiDebugAgentGuid,
|
||||
&MailboxLocation,
|
||||
sizeof (UINT64)
|
||||
);
|
||||
}
|
||||
//
|
||||
// Update IDT entry to save the location saved mailbox pointer
|
||||
//
|
||||
SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_PEI:
|
||||
if (Context == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
//
|
||||
// Check if Debug Agent has initialized before
|
||||
//
|
||||
if (IsDebugAgentInitialzed()) {
|
||||
DEBUG ((DEBUG_WARN, "Debug Agent: It has already initialized in SEC Core!\n"));
|
||||
break;
|
||||
}
|
||||
//
|
||||
// Install Vector Handoff Info PPI to persist vectors used by Debug Agent
|
||||
//
|
||||
Status = PeiServicesInstallPpi (&mVectorHandoffInfoPpiList[0]);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
//
|
||||
// Set up IDT entries
|
||||
//
|
||||
InitializeDebugIdt ();
|
||||
//
|
||||
// Build mailbox in HOB and setup Mailbox Set In Pei flag
|
||||
//
|
||||
Mailbox = AllocateZeroPool (sizeof (DEBUG_AGENT_MAILBOX));
|
||||
if (Mailbox == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to allocate memory!\n"));
|
||||
CpuDeadLoop ();
|
||||
} else {
|
||||
MailboxLocation = (UINT64)(UINTN)Mailbox;
|
||||
MailboxLocationPointer = BuildGuidDataHob (
|
||||
&gEfiDebugAgentGuid,
|
||||
&MailboxLocation,
|
||||
sizeof (UINT64)
|
||||
);
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
|
||||
//
|
||||
// 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;
|
||||
Phase2Context.Function = Function;
|
||||
DebugPortInitialize ((VOID *)&Phase2Context, InitializeDebugAgentPhase2);
|
||||
//
|
||||
// Update IDT entry to save the location pointer saved mailbox pointer
|
||||
// If reaches here, it means Debug Port initialization failed.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: Debug port initialization failed.\n"));
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_POSTMEM_SEC:
|
||||
Mailbox = GetMailboxPointer ();
|
||||
//
|
||||
// Memory has been ready
|
||||
//
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
|
||||
if (IsHostAttached ()) {
|
||||
//
|
||||
// Trigger one software interrupt to inform HOST
|
||||
//
|
||||
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
|
||||
}
|
||||
|
||||
//
|
||||
// Install Vector Handoff Info PPI to persist vectors used by Debug Agent
|
||||
//
|
||||
Status = PeiServicesInstallPpi (&mVectorHandoffInfoPpiList[0]);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
//
|
||||
// Fix up Debug Port handle address and mailbox address
|
||||
//
|
||||
DebugAgentContext = (DEBUG_AGENT_CONTEXT_POSTMEM_SEC *)Context;
|
||||
if (DebugAgentContext != NULL) {
|
||||
DebugPortHandle = (UINT64)(UINT32)(Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset);
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + DebugAgentContext->StackMigrateOffset);
|
||||
MailboxLocation = (UINT64)(UINTN)Mailbox;
|
||||
//
|
||||
// Build mailbox location in HOB and fix-up its address
|
||||
//
|
||||
MailboxLocationPointer = BuildGuidDataHob (
|
||||
&gEfiDebugAgentGuid,
|
||||
&MailboxLocation,
|
||||
sizeof (UINT64)
|
||||
);
|
||||
MailboxLocationPointer = (UINT64 *)((UINTN)MailboxLocationPointer + DebugAgentContext->HeapMigrateOffset);
|
||||
} else {
|
||||
//
|
||||
// DebugAgentContext is NULL. Then, Mailbox can directly be copied into memory.
|
||||
// Allocate ACPI NVS memory for new Mailbox and Debug Port Handle buffer
|
||||
//
|
||||
Status = PeiServicesAllocatePages (
|
||||
EfiACPIMemoryNVS,
|
||||
EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX) + PcdGet16 (PcdDebugPortHandleBufferSize)),
|
||||
&Address
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to allocate pages!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
NewMailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)Address;
|
||||
//
|
||||
// Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
|
||||
// and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
|
||||
// reallocates the HOB.
|
||||
//
|
||||
CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16 (PcdDebugPortHandleBufferSize));
|
||||
UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));
|
||||
MailboxLocation = (UINT64)(UINTN)NewMailbox;
|
||||
//
|
||||
// Build mailbox location in HOB
|
||||
//
|
||||
MailboxLocationPointer = BuildGuidDataHob (
|
||||
&gEfiDebugAgentGuid,
|
||||
&MailboxLocation,
|
||||
sizeof (UINT64)
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Update IDT entry to save the location saved mailbox pointer
|
||||
//
|
||||
SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
|
||||
}
|
||||
//
|
||||
// Save init arch type when debug agent initialized
|
||||
//
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
|
||||
//
|
||||
// Register for a callback once memory has been initialized.
|
||||
// If memory has been ready, the callback function will be invoked immediately
|
||||
//
|
||||
Status = PeiServicesNotifyPpi (&mDebugAgentMemoryDiscoveredNotifyList[0]);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to register memory discovered callback function!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
//
|
||||
// Set HOB check flag if memory has not been ready yet
|
||||
//
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY) == 0) {
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
Phase2Context.InitFlag = InitFlag;
|
||||
Phase2Context.Context = Context;
|
||||
Phase2Context.Function = Function;
|
||||
DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);
|
||||
case DEBUG_AGENT_INIT_PEI:
|
||||
if (Context == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
FindAndReportModuleImageInfo (4);
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:
|
||||
if (Context == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
|
||||
CpuDeadLoop ();
|
||||
} else {
|
||||
Ia32Idtr = (IA32_DESCRIPTOR *) Context;
|
||||
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
|
||||
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
|
||||
// Check if Debug Agent has initialized before
|
||||
//
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
if (IsDebugAgentInitialzed ()) {
|
||||
DEBUG ((DEBUG_WARN, "Debug Agent: It has already initialized in SEC Core!\n"));
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Install Vector Handoff Info PPI to persist vectors used by Debug Agent
|
||||
//
|
||||
Status = PeiServicesInstallPpi (&mVectorHandoffInfoPpiList[0]);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)Mailbox->DebugPortHandle, NULL);
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
|
||||
//
|
||||
// Set up IDT entries
|
||||
//
|
||||
InitializeDebugIdt ();
|
||||
//
|
||||
// Update IDT entry to save location pointer saved the mailbox pointer
|
||||
// Build mailbox in HOB and setup Mailbox Set In Pei flag
|
||||
//
|
||||
SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
|
||||
Mailbox = AllocateZeroPool (sizeof (DEBUG_AGENT_MAILBOX));
|
||||
if (Mailbox == NULL) {
|
||||
DEBUG ((DEBUG_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
|
||||
//
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);
|
||||
//
|
||||
// Register for a callback once memory has been initialized.
|
||||
// If memory has been ready, the callback function will be invoked immediately
|
||||
//
|
||||
Status = PeiServicesNotifyPpi (&mDebugAgentMemoryDiscoveredNotifyList[0]);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to register memory discovered callback function!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
//
|
||||
// Set HOB check flag if memory has not been ready yet
|
||||
//
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY) == 0) {
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_CHECK_MAILBOX_IN_HOB, 1);
|
||||
}
|
||||
|
||||
Phase2Context.InitFlag = InitFlag;
|
||||
Phase2Context.Context = Context;
|
||||
Phase2Context.Function = Function;
|
||||
DebugPortInitialize ((VOID *)&Phase2Context, InitializeDebugAgentPhase2);
|
||||
|
||||
FindAndReportModuleImageInfo (4);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
//
|
||||
// Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
|
||||
// Debug Agent library instance.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:
|
||||
if (Context == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
|
||||
CpuDeadLoop ();
|
||||
} else {
|
||||
Ia32Idtr = (IA32_DESCRIPTOR *)Context;
|
||||
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
|
||||
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
|
||||
//
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
|
||||
DebugPortHandle = (UINT64)(UINTN)DebugPortInitialize ((VOID *)(UINTN)Mailbox->DebugPortHandle, NULL);
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
|
||||
//
|
||||
// Set up IDT entries
|
||||
//
|
||||
InitializeDebugIdt ();
|
||||
//
|
||||
// Update IDT entry to save location pointer saved the mailbox pointer
|
||||
//
|
||||
SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
|
||||
|
||||
FindAndReportModuleImageInfo (4);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
//
|
||||
// Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
|
||||
// Debug Agent library instance.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
}
|
||||
|
||||
if (InitFlag == DEBUG_AGENT_INIT_POSTMEM_SEC) {
|
||||
@@ -625,16 +638,18 @@ InitializeDebugAgent (
|
||||
//
|
||||
EnableInterrupts ();
|
||||
}
|
||||
|
||||
//
|
||||
// If Function is not NULL, invoke it always whatever debug agent was initialized successfully or not.
|
||||
//
|
||||
if (Function != NULL) {
|
||||
Function (Context);
|
||||
}
|
||||
|
||||
//
|
||||
// Set return status for DEBUG_AGENT_INIT_PEI
|
||||
//
|
||||
if (InitFlag == DEBUG_AGENT_INIT_PEI && Context != NULL) {
|
||||
if ((InitFlag == DEBUG_AGENT_INIT_PEI) && (Context != NULL)) {
|
||||
*(EFI_STATUS *)Context = EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -651,26 +666,27 @@ InitializeDebugAgent (
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeDebugAgentPhase2 (
|
||||
IN VOID *Context,
|
||||
IN DEBUG_PORT_HANDLE DebugPortHandle
|
||||
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;
|
||||
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;
|
||||
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) {
|
||||
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);
|
||||
|
||||
//
|
||||
@@ -684,10 +700,11 @@ InitializeDebugAgentPhase2 (
|
||||
// host to disable low memory filtering.
|
||||
//
|
||||
SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;
|
||||
if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB && IsHostAttached ()) {
|
||||
if (((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB) && IsHostAttached ()) {
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
|
||||
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
|
||||
}
|
||||
|
||||
//
|
||||
// Enable Debug Timer interrupt
|
||||
//
|
||||
|
@@ -33,8 +33,8 @@ typedef struct {
|
||||
VOID
|
||||
EFIAPI
|
||||
InitializeDebugAgentPhase2 (
|
||||
IN VOID *Context,
|
||||
IN DEBUG_PORT_HANDLE DebugPortHandle
|
||||
IN VOID *Context,
|
||||
IN DEBUG_PORT_HANDLE DebugPortHandle
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -50,10 +50,9 @@ InitializeDebugAgentPhase2 (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DebugAgentCallbackMemoryDiscoveredPpi (
|
||||
IN EFI_PEI_SERVICES **PeiServices,
|
||||
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
||||
IN VOID *Ppi
|
||||
IN EFI_PEI_SERVICES **PeiServices,
|
||||
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
||||
IN VOID *Ppi
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -8,19 +8,19 @@
|
||||
|
||||
#include "SmmDebugAgentLib.h"
|
||||
|
||||
DEBUG_AGENT_MAILBOX *mMailboxPointer = NULL;
|
||||
DEBUG_AGENT_MAILBOX mLocalMailbox;
|
||||
UINTN mSavedDebugRegisters[6];
|
||||
IA32_IDT_GATE_DESCRIPTOR mIdtEntryTable[33];
|
||||
BOOLEAN mSkipBreakpoint = FALSE;
|
||||
BOOLEAN mSmmDebugIdtInitFlag = FALSE;
|
||||
BOOLEAN mApicTimerRestore = FALSE;
|
||||
BOOLEAN mPeriodicMode;
|
||||
UINT32 mTimerCycle;
|
||||
UINTN mApicTimerDivisor;
|
||||
UINT8 mVector;
|
||||
DEBUG_AGENT_MAILBOX *mMailboxPointer = NULL;
|
||||
DEBUG_AGENT_MAILBOX mLocalMailbox;
|
||||
UINTN mSavedDebugRegisters[6];
|
||||
IA32_IDT_GATE_DESCRIPTOR mIdtEntryTable[33];
|
||||
BOOLEAN mSkipBreakpoint = FALSE;
|
||||
BOOLEAN mSmmDebugIdtInitFlag = FALSE;
|
||||
BOOLEAN mApicTimerRestore = FALSE;
|
||||
BOOLEAN mPeriodicMode;
|
||||
UINT32 mTimerCycle;
|
||||
UINTN mApicTimerDivisor;
|
||||
UINT8 mVector;
|
||||
|
||||
CHAR8 mWarningMsgIgnoreSmmEntryBreak[] = "Ignore smmentrybreak setting for SMI issued during DXE debugging!\r\n";
|
||||
CHAR8 mWarningMsgIgnoreSmmEntryBreak[] = "Ignore smmentrybreak setting for SMI issued during DXE debugging!\r\n";
|
||||
|
||||
/**
|
||||
Check if debug agent support multi-processor.
|
||||
@@ -49,8 +49,8 @@ MultiProcessorDebugSupport (
|
||||
**/
|
||||
EFI_STATUS
|
||||
DebugReadBreakSymbol (
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
IN DEBUG_PORT_HANDLE Handle,
|
||||
OUT UINT8 *BreakSymbol
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -70,16 +70,17 @@ GetMailboxFromHob (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
UINT64 *MailboxLocation;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
EFI_HOB_GUID_TYPE *GuidHob;
|
||||
UINT64 *MailboxLocation;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
|
||||
GuidHob = GetFirstGuidHob (&gEfiDebugAgentGuid);
|
||||
if (GuidHob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
|
||||
MailboxLocation = (UINT64 *)(GET_GUID_HOB_DATA (GuidHob));
|
||||
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
|
||||
return Mailbox;
|
||||
@@ -111,7 +112,7 @@ GetDebugPortHandle (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return (DEBUG_PORT_HANDLE) (UINTN)(GetMailboxPointer()->DebugPortHandle);
|
||||
return (DEBUG_PORT_HANDLE)(UINTN)(GetMailboxPointer ()->DebugPortHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,207 +180,218 @@ InitializeDebugAgent (
|
||||
IN DEBUG_AGENT_CONTINUE Function OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT64 DebugPortHandle;
|
||||
IA32_IDT_GATE_DESCRIPTOR IdtEntry[33];
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_DESCRIPTOR *Ia32Idtr;
|
||||
IA32_IDT_ENTRY *Ia32IdtEntry;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
UINT16 IdtEntryCount;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
UINT64 *MailboxLocation;
|
||||
UINT32 DebugTimerFrequency;
|
||||
EFI_STATUS Status;
|
||||
UINT64 DebugPortHandle;
|
||||
IA32_IDT_GATE_DESCRIPTOR IdtEntry[33];
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_DESCRIPTOR *Ia32Idtr;
|
||||
IA32_IDT_ENTRY *Ia32IdtEntry;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
UINT16 IdtEntryCount;
|
||||
DEBUG_AGENT_MAILBOX *Mailbox;
|
||||
UINT64 *MailboxLocation;
|
||||
UINT32 DebugTimerFrequency;
|
||||
|
||||
switch (InitFlag) {
|
||||
case DEBUG_AGENT_INIT_SMM:
|
||||
//
|
||||
// Install configuration table for persisted vector handoff info
|
||||
//
|
||||
Status = gSmst->SmmInstallConfigurationTable (
|
||||
gSmst,
|
||||
&gEfiVectorHandoffTableGuid,
|
||||
(VOID *) &mVectorHandoffInfoDebugAgent[0],
|
||||
sizeof (EFI_VECTOR_HANDOFF_INFO) * mVectorHandoffInfoCount
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
//
|
||||
// Check if Debug Agent initialized in DXE phase
|
||||
//
|
||||
Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &Mailbox);
|
||||
if (Status == EFI_SUCCESS && Mailbox != NULL) {
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
mMailboxPointer = Mailbox;
|
||||
break;
|
||||
}
|
||||
//
|
||||
// Check if Debug Agent initialized in SEC/PEI phase
|
||||
//
|
||||
Mailbox = GetMailboxFromHob ();
|
||||
if (Mailbox != NULL) {
|
||||
mMailboxPointer = Mailbox;
|
||||
break;
|
||||
}
|
||||
//
|
||||
// Debug Agent was not initialized before, use the local mailbox.
|
||||
//
|
||||
ZeroMem (&mLocalMailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
Mailbox = &mLocalMailbox;
|
||||
//
|
||||
// Save original IDT entries
|
||||
//
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR));
|
||||
//
|
||||
// Initialized Debug Agent
|
||||
//
|
||||
InitializeDebugIdt ();
|
||||
//
|
||||
// Initialize Debug Timer hardware and save its frequency
|
||||
//
|
||||
InitializeDebugTimer (&DebugTimerFrequency, TRUE);
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
|
||||
|
||||
DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle, NULL);
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
|
||||
mMailboxPointer = Mailbox;
|
||||
//
|
||||
// Trigger one software interrupt to inform HOST
|
||||
//
|
||||
TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);
|
||||
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
|
||||
//
|
||||
// Memory has been ready
|
||||
//
|
||||
if (IsHostAttached ()) {
|
||||
case DEBUG_AGENT_INIT_SMM:
|
||||
//
|
||||
// Trigger one software interrupt to inform HOST
|
||||
// Install configuration table for persisted vector handoff info
|
||||
//
|
||||
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
|
||||
}
|
||||
//
|
||||
// Find and report PE/COFF image info to HOST
|
||||
//
|
||||
FindAndReportModuleImageInfo (SIZE_4KB);
|
||||
//
|
||||
// Restore saved IDT entries
|
||||
//
|
||||
CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR));
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_ENTER_SMI:
|
||||
SaveDebugRegister ();
|
||||
if (!mSmmDebugIdtInitFlag) {
|
||||
//
|
||||
// We only need to initialize Debug IDT table at first SMI entry
|
||||
// after SMM relocation.
|
||||
//
|
||||
InitializeDebugIdt ();
|
||||
mSmmDebugIdtInitFlag = TRUE;
|
||||
}
|
||||
//
|
||||
// Check if CPU APIC Timer is working, otherwise initialize it.
|
||||
//
|
||||
InitializeLocalApicSoftwareEnable (TRUE);
|
||||
GetApicTimerState (&mApicTimerDivisor, &mPeriodicMode, &mVector);
|
||||
mTimerCycle = GetApicTimerInitCount ();
|
||||
if (!mPeriodicMode || mTimerCycle == 0) {
|
||||
mApicTimerRestore = TRUE;
|
||||
InitializeDebugTimer (NULL, FALSE);
|
||||
}
|
||||
Mailbox = GetMailboxPointer ();
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {
|
||||
//
|
||||
// If Debug Agent has been communication state with HOST, we need skip
|
||||
// any break points set in SMM, set Skip Breakpoint flag
|
||||
//
|
||||
mSkipBreakpoint = TRUE;
|
||||
}
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI) == 1) {
|
||||
if (mSkipBreakpoint) {
|
||||
//
|
||||
// Print warning message if ignore smm entry break
|
||||
//
|
||||
DebugPortWriteBuffer ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle,
|
||||
(UINT8 *)mWarningMsgIgnoreSmmEntryBreak,
|
||||
AsciiStrLen (mWarningMsgIgnoreSmmEntryBreak)
|
||||
);
|
||||
} else {
|
||||
//
|
||||
// If SMM entry break is set, SMM code will be break at here.
|
||||
//
|
||||
CpuBreakpoint ();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_EXIT_SMI:
|
||||
Mailbox = GetMailboxPointer ();
|
||||
//
|
||||
// Clear Skip Breakpoint flag
|
||||
//
|
||||
mSkipBreakpoint = FALSE;
|
||||
RestoreDebugRegister ();
|
||||
//
|
||||
// Restore APIC Timer
|
||||
//
|
||||
if (mApicTimerRestore) {
|
||||
InitializeApicTimer (mApicTimerDivisor, mTimerCycle, mPeriodicMode, mVector);
|
||||
mApicTimerRestore = FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:
|
||||
if (Context == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
|
||||
CpuDeadLoop ();
|
||||
} else {
|
||||
Ia32Idtr = (IA32_DESCRIPTOR *) Context;
|
||||
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
|
||||
MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
|
||||
((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
|
||||
mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
VerifyMailboxChecksum (mMailboxPointer);
|
||||
//
|
||||
// Get original IDT address and size.
|
||||
//
|
||||
AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr);
|
||||
IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
|
||||
if (IdtEntryCount < 33) {
|
||||
Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
|
||||
Idtr.Base = (UINTN) &mIdtEntryTable;
|
||||
ZeroMem (&mIdtEntryTable, Idtr.Limit + 1);
|
||||
AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr);
|
||||
Status = gSmst->SmmInstallConfigurationTable (
|
||||
gSmst,
|
||||
&gEfiVectorHandoffTableGuid,
|
||||
(VOID *)&mVectorHandoffInfoDebugAgent[0],
|
||||
sizeof (EFI_VECTOR_HANDOFF_INFO) * mVectorHandoffInfoCount
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
//
|
||||
// Check if Debug Agent initialized in DXE phase
|
||||
//
|
||||
Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **)&Mailbox);
|
||||
if ((Status == EFI_SUCCESS) && (Mailbox != NULL)) {
|
||||
VerifyMailboxChecksum (Mailbox);
|
||||
mMailboxPointer = Mailbox;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if Debug Agent initialized in SEC/PEI phase
|
||||
//
|
||||
Mailbox = GetMailboxFromHob ();
|
||||
if (Mailbox != NULL) {
|
||||
mMailboxPointer = Mailbox;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Debug Agent was not initialized before, use the local mailbox.
|
||||
//
|
||||
ZeroMem (&mLocalMailbox, sizeof (DEBUG_AGENT_MAILBOX));
|
||||
Mailbox = &mLocalMailbox;
|
||||
//
|
||||
// Save original IDT entries
|
||||
//
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));
|
||||
//
|
||||
// Initialized Debug Agent
|
||||
//
|
||||
InitializeDebugIdt ();
|
||||
//
|
||||
// Initialize Debug Timer hardware and save its frequency
|
||||
//
|
||||
InitializeDebugTimer (&DebugTimerFrequency, TRUE);
|
||||
UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
|
||||
//
|
||||
// Enable Debug Timer interrupt and CPU interrupt
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
EnableInterrupts ();
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
|
||||
|
||||
DebugPortHandle = (UINT64)(UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE)(UINTN)Mailbox->DebugPortHandle, NULL);
|
||||
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
|
||||
mMailboxPointer = Mailbox;
|
||||
//
|
||||
// Trigger one software interrupt to inform HOST
|
||||
//
|
||||
TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);
|
||||
|
||||
SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
|
||||
//
|
||||
// Memory has been ready
|
||||
//
|
||||
if (IsHostAttached ()) {
|
||||
//
|
||||
// Trigger one software interrupt to inform HOST
|
||||
//
|
||||
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
|
||||
}
|
||||
|
||||
//
|
||||
// Find and report PE/COFF image info to HOST
|
||||
//
|
||||
FindAndReportModuleImageInfo (SIZE_4KB);
|
||||
}
|
||||
break;
|
||||
//
|
||||
// Restore saved IDT entries
|
||||
//
|
||||
CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));
|
||||
|
||||
default:
|
||||
//
|
||||
// Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
|
||||
// Debug Agent library instance.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_ENTER_SMI:
|
||||
SaveDebugRegister ();
|
||||
if (!mSmmDebugIdtInitFlag) {
|
||||
//
|
||||
// We only need to initialize Debug IDT table at first SMI entry
|
||||
// after SMM relocation.
|
||||
//
|
||||
InitializeDebugIdt ();
|
||||
mSmmDebugIdtInitFlag = TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// Check if CPU APIC Timer is working, otherwise initialize it.
|
||||
//
|
||||
InitializeLocalApicSoftwareEnable (TRUE);
|
||||
GetApicTimerState (&mApicTimerDivisor, &mPeriodicMode, &mVector);
|
||||
mTimerCycle = GetApicTimerInitCount ();
|
||||
if (!mPeriodicMode || (mTimerCycle == 0)) {
|
||||
mApicTimerRestore = TRUE;
|
||||
InitializeDebugTimer (NULL, FALSE);
|
||||
}
|
||||
|
||||
Mailbox = GetMailboxPointer ();
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {
|
||||
//
|
||||
// If Debug Agent has been communication state with HOST, we need skip
|
||||
// any break points set in SMM, set Skip Breakpoint flag
|
||||
//
|
||||
mSkipBreakpoint = TRUE;
|
||||
}
|
||||
|
||||
if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI) == 1) {
|
||||
if (mSkipBreakpoint) {
|
||||
//
|
||||
// Print warning message if ignore smm entry break
|
||||
//
|
||||
DebugPortWriteBuffer (
|
||||
(DEBUG_PORT_HANDLE)(UINTN)Mailbox->DebugPortHandle,
|
||||
(UINT8 *)mWarningMsgIgnoreSmmEntryBreak,
|
||||
AsciiStrLen (mWarningMsgIgnoreSmmEntryBreak)
|
||||
);
|
||||
} else {
|
||||
//
|
||||
// If SMM entry break is set, SMM code will be break at here.
|
||||
//
|
||||
CpuBreakpoint ();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_EXIT_SMI:
|
||||
Mailbox = GetMailboxPointer ();
|
||||
//
|
||||
// Clear Skip Breakpoint flag
|
||||
//
|
||||
mSkipBreakpoint = FALSE;
|
||||
RestoreDebugRegister ();
|
||||
//
|
||||
// Restore APIC Timer
|
||||
//
|
||||
if (mApicTimerRestore) {
|
||||
InitializeApicTimer (mApicTimerDivisor, mTimerCycle, mPeriodicMode, mVector);
|
||||
mApicTimerRestore = FALSE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:
|
||||
if (Context == NULL) {
|
||||
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
|
||||
CpuDeadLoop ();
|
||||
} else {
|
||||
Ia32Idtr = (IA32_DESCRIPTOR *)Context;
|
||||
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
|
||||
MailboxLocation = (UINT64 *)((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
|
||||
((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
|
||||
mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
|
||||
VerifyMailboxChecksum (mMailboxPointer);
|
||||
//
|
||||
// Get original IDT address and size.
|
||||
//
|
||||
AsmReadIdtr ((IA32_DESCRIPTOR *)&Idtr);
|
||||
IdtEntryCount = (UINT16)((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
|
||||
if (IdtEntryCount < 33) {
|
||||
Idtr.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
|
||||
Idtr.Base = (UINTN)&mIdtEntryTable;
|
||||
ZeroMem (&mIdtEntryTable, Idtr.Limit + 1);
|
||||
AsmWriteIdtr ((IA32_DESCRIPTOR *)&Idtr);
|
||||
}
|
||||
|
||||
InitializeDebugIdt ();
|
||||
//
|
||||
// Initialize Debug Timer hardware and save its frequency
|
||||
//
|
||||
InitializeDebugTimer (&DebugTimerFrequency, TRUE);
|
||||
UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
|
||||
//
|
||||
// Enable Debug Timer interrupt and CPU interrupt
|
||||
//
|
||||
SaveAndSetDebugTimerInterrupt (TRUE);
|
||||
EnableInterrupts ();
|
||||
|
||||
FindAndReportModuleImageInfo (SIZE_4KB);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
//
|
||||
// Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
|
||||
// Debug Agent library instance.
|
||||
//
|
||||
DEBUG ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user