summaryrefslogtreecommitdiffstats
path: root/SourceLevelDebugPkg/Library
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2021-12-05 14:54:15 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-12-07 17:24:28 +0000
commitc1e126b1196de75e0a4cda21e4551ea9bb05e059 (patch)
treeda0e06602097dc7bb7e5a97a270d1834b6cf76e7 /SourceLevelDebugPkg/Library
parentb87864896714cf3062a7bc6d577d8fbd62d105e5 (diff)
downloadedk2-c1e126b1196de75e0a4cda21e4551ea9bb05e059.tar.gz
edk2-c1e126b1196de75e0a4cda21e4551ea9bb05e059.tar.bz2
edk2-c1e126b1196de75e0a4cda21e4551ea9bb05e059.zip
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>
Diffstat (limited to 'SourceLevelDebugPkg/Library')
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c1993
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h194
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c79
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.h55
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c41
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.h11
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c45
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.h8
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/DebugException.h34
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c61
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.h8
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/DebugException.h34
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c391
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c147
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c513
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.h11
-rw-r--r--SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c412
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c22
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c520
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c361
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c205
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h530
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c83
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c181
-rw-r--r--SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/Ia32/IntHandlerFuncs.c38
-rw-r--r--SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c51
-rw-r--r--SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.h21
-rw-r--r--SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/X64/IntHandlerFuncs.c50
28 files changed, 3134 insertions, 2965 deletions
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
index c29e4f2aa4..a1e61a6ef9 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
@@ -12,16 +12,16 @@
#include "DebugAgent.h"
#include "Ia32/DebugException.h"
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgVersionAlert[] = "\rThe SourceLevelDebugPkg you are using requires a newer version of the Intel(R) UDK Debugger Tool.\r\n";
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgSendInitPacket[] = "\rSend INIT break packet and try to connect the HOST (Intel(R) UDK Debugger Tool v1.5) ...\r\n";
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectOK[] = "HOST connection is successful!\r\n";
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectFail[] = "HOST connection is failed!\r\n";
-GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mWarningMsgIngoreBreakpoint[] = "Ignore break point in SMM for SMI issued during DXE debugging!\r\n";
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgVersionAlert[] = "\rThe SourceLevelDebugPkg you are using requires a newer version of the Intel(R) UDK Debugger Tool.\r\n";
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgSendInitPacket[] = "\rSend INIT break packet and try to connect the HOST (Intel(R) UDK Debugger Tool v1.5) ...\r\n";
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectOK[] = "HOST connection is successful!\r\n";
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mErrorMsgConnectFail[] = "HOST connection is failed!\r\n";
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 mWarningMsgIngoreBreakpoint[] = "Ignore break point in SMM for SMI issued during DXE debugging!\r\n";
//
// Vector Handoff Info list used by Debug Agent for persist
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAgent[] = {
{
DEBUG_EXCEPT_DIVIDE_ERROR, // Vector 0
EFI_VECTOR_HANDOFF_HOOK_BEFORE,
@@ -82,7 +82,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAge
EFI_VECTOR_HANDOFF_HOOK_BEFORE,
EFI_DEBUG_AGENT_GUID
},
- {
+ {
DEBUG_EXCEPT_PAGE_FAULT, // Vector 14
EFI_VECTOR_HANDOFF_HOOK_BEFORE,
EFI_DEBUG_AGENT_GUID
@@ -124,7 +124,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_VECTOR_HANDOFF_INFO mVectorHandoffInfoDebugAge
}
};
-GLOBAL_REMOVE_IF_UNREFERENCED UINTN mVectorHandoffInfoCount = sizeof (mVectorHandoffInfoDebugAgent) / sizeof (EFI_VECTOR_HANDOFF_INFO);
+GLOBAL_REMOVE_IF_UNREFERENCED UINTN mVectorHandoffInfoCount = sizeof (mVectorHandoffInfoDebugAgent) / sizeof (EFI_VECTOR_HANDOFF_INFO);
/**
Calculate CRC16 for target data.
@@ -151,16 +151,16 @@ CalculateCrc16 (
for (BitIndex = 0; BitIndex < 8; BitIndex++) {
if ((Crc & 0x8000) != 0) {
Crc <<= 1;
- Crc ^= 0x1021;
+ Crc ^= 0x1021;
} else {
Crc <<= 1;
}
}
}
+
return Crc;
}
-
/**
Read IDT entry to check if IDT entries are setup by Debug Agent.
@@ -173,10 +173,10 @@ IsDebugAgentInitialzed (
VOID
)
{
- UINTN InterruptHandler;
+ UINTN InterruptHandler;
- InterruptHandler = (UINTN) GetExceptionHandlerInIdtEntry (0);
- if (InterruptHandler >= 4 && *(UINT32 *)(InterruptHandler - 4) == AGENT_HANDLER_SIGNATURE) {
+ InterruptHandler = (UINTN)GetExceptionHandlerInIdtEntry (0);
+ if ((InterruptHandler >= 4) && (*(UINT32 *)(InterruptHandler - 4) == AGENT_HANDLER_SIGNATURE)) {
return TRUE;
} else {
return FALSE;
@@ -191,19 +191,19 @@ IsDebugAgentInitialzed (
**/
VOID
FindAndReportModuleImageInfo (
- IN UINTN AlignSize
+ IN UINTN AlignSize
)
{
- UINTN Pe32Data;
- PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
+ UINTN Pe32Data;
+ PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
//
// Find Image Base
//
- Pe32Data = PeCoffSearchImageBase ((UINTN) mErrorMsgVersionAlert);
+ Pe32Data = PeCoffSearchImageBase ((UINTN)mErrorMsgVersionAlert);
if (Pe32Data != 0) {
ImageContext.ImageAddress = Pe32Data;
- ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID*) (UINTN) ImageContext.ImageAddress);
+ ImageContext.PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)ImageContext.ImageAddress);
PeCoffLoaderRelocateImageExtraAction (&ImageContext);
}
}
@@ -216,11 +216,11 @@ FindAndReportModuleImageInfo (
**/
VOID
TriggerSoftInterrupt (
- IN UINT32 Signature
+ IN UINT32 Signature
)
{
- UINTN Dr0;
- UINTN Dr1;
+ UINTN Dr0;
+ UINTN Dr1;
//
// Save Debug Register State
@@ -245,7 +245,6 @@ TriggerSoftInterrupt (
//
AsmWriteDr0 (Dr0);
AsmWriteDr1 (Dr1);
-
}
/**
@@ -256,7 +255,7 @@ TriggerSoftInterrupt (
**/
VOID
UpdateMailboxChecksum (
- IN DEBUG_AGENT_MAILBOX *Mailbox
+ IN DEBUG_AGENT_MAILBOX *Mailbox
)
{
Mailbox->CheckSum = CalculateCheckSum8 ((UINT8 *)Mailbox, sizeof (DEBUG_AGENT_MAILBOX) - 2);
@@ -272,17 +271,17 @@ UpdateMailboxChecksum (
**/
VOID
VerifyMailboxChecksum (
- IN DEBUG_AGENT_MAILBOX *Mailbox
+ IN DEBUG_AGENT_MAILBOX *Mailbox
)
{
- UINT8 CheckSum;
+ UINT8 CheckSum;
- CheckSum = CalculateCheckSum8 ((UINT8 *) Mailbox, sizeof (DEBUG_AGENT_MAILBOX) - 2);
+ CheckSum = CalculateCheckSum8 ((UINT8 *)Mailbox, sizeof (DEBUG_AGENT_MAILBOX) - 2);
//
// The checksum updating process may be disturbed by hardware SMI, we need to check CheckSum field
// and ToBeCheckSum field to validate the mail box.
//
- if (CheckSum != Mailbox->CheckSum && CheckSum != Mailbox->ToBeCheckSum) {
+ if ((CheckSum != Mailbox->CheckSum) && (CheckSum != Mailbox->ToBeCheckSum)) {
DEBUG ((DEBUG_ERROR, "DebugAgent: Mailbox checksum error, stack or heap crashed!\n"));
DEBUG ((DEBUG_ERROR, "DebugAgent: CheckSum = %x, Mailbox->CheckSum = %x, Mailbox->ToBeCheckSum = %x\n", CheckSum, Mailbox->CheckSum, Mailbox->ToBeCheckSum));
CpuDeadLoop ();
@@ -299,49 +298,50 @@ VerifyMailboxChecksum (
**/
VOID
UpdateMailboxContent (
- IN DEBUG_AGENT_MAILBOX *Mailbox,
- IN UINTN Index,
- IN UINT64 Value
+ IN DEBUG_AGENT_MAILBOX *Mailbox,
+ IN UINTN Index,
+ IN UINT64 Value
)
{
AcquireMpSpinLock (&mDebugMpContext.MailboxSpinLock);
switch (Index) {
- case DEBUG_MAILBOX_DEBUG_FLAG_INDEX:
- Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->DebugFlag.Uint64, sizeof(UINT64))
- - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT64));
- Mailbox->DebugFlag.Uint64 = Value;
- break;
- case DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX:
- Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->DebugPortHandle, sizeof(UINTN))
- - CalculateSum8 ((UINT8 *)&Value, sizeof(UINTN));
- Mailbox->DebugPortHandle = (UINTN) Value;
- break;
- case DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX:
- Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->ExceptionBufferPointer, sizeof(UINTN))
- - CalculateSum8 ((UINT8 *)&Value, sizeof(UINTN));
- Mailbox->ExceptionBufferPointer = (UINTN) Value;
- break;
- case DEBUG_MAILBOX_LAST_ACK:
- Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->LastAck, sizeof(UINT8))
- - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT8));
- Mailbox->LastAck = (UINT8) Value;
- break;
- case DEBUG_MAILBOX_SEQUENCE_NO_INDEX:
- Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->SequenceNo, sizeof(UINT8))
- - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT8));
- Mailbox->SequenceNo = (UINT8) Value;
- break;
- case DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX:
- Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->HostSequenceNo, sizeof(UINT8))
- - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT8));
- Mailbox->HostSequenceNo = (UINT8) Value;
- break;
- case DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY:
- Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->DebugTimerFrequency, sizeof(UINT32))
- - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT32));
- Mailbox->DebugTimerFrequency = (UINT32) Value;
- break;
+ case DEBUG_MAILBOX_DEBUG_FLAG_INDEX:
+ Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->DebugFlag.Uint64, sizeof (UINT64))
+ - CalculateSum8 ((UINT8 *)&Value, sizeof (UINT64));
+ Mailbox->DebugFlag.Uint64 = Value;
+ break;
+ case DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX:
+ Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->DebugPortHandle, sizeof (UINTN))
+ - CalculateSum8 ((UINT8 *)&Value, sizeof (UINTN));
+ Mailbox->DebugPortHandle = (UINTN)Value;
+ break;
+ case DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX:
+ Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->ExceptionBufferPointer, sizeof (UINTN))
+ - CalculateSum8 ((UINT8 *)&Value, sizeof (UINTN));
+ Mailbox->ExceptionBufferPointer = (UINTN)Value;
+ break;
+ case DEBUG_MAILBOX_LAST_ACK:
+ Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->LastAck, sizeof (UINT8))
+ - CalculateSum8 ((UINT8 *)&Value, sizeof (UINT8));
+ Mailbox->LastAck = (UINT8)Value;
+ break;
+ case DEBUG_MAILBOX_SEQUENCE_NO_INDEX:
+ Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->SequenceNo, sizeof (UINT8))
+ - CalculateSum8 ((UINT8 *)&Value, sizeof (UINT8));
+ Mailbox->SequenceNo = (UINT8)Value;
+ break;
+ case DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX:
+ Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->HostSequenceNo, sizeof (UINT8))
+ - CalculateSum8 ((UINT8 *)&Value, sizeof (UINT8));
+ Mailbox->HostSequenceNo = (UINT8)Value;
+ break;
+ case DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY:
+ Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->DebugTimerFrequency, sizeof (UINT32))
+ - CalculateSum8 ((UINT8 *)&Value, sizeof (UINT32));
+ Mailbox->DebugTimerFrequency = (UINT32)Value;
+ break;
}
+
UpdateMailboxChecksum (Mailbox);
ReleaseMpSpinLock (&mDebugMpContext.MailboxSpinLock);
}
@@ -365,43 +365,45 @@ UpdateMailboxContent (
**/
UINTN
DebugAgentReadBuffer (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes,
- IN UINTN Timeout
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes,
+ IN UINTN Timeout
)
{
- UINTN Index;
- UINT32 Begin;
- UINT32 TimeoutTicker;
- UINT32 TimerRound;
- UINT32 TimerFrequency;
- UINT32 TimerCycle;
-
- Begin = 0;
- TimeoutTicker = 0;
- TimerRound = 0;
- TimerFrequency = GetMailboxPointer()->DebugTimerFrequency;
- TimerCycle = GetApicTimerInitCount ();
+ UINTN Index;
+ UINT32 Begin;
+ UINT32 TimeoutTicker;
+ UINT32 TimerRound;
+ UINT32 TimerFrequency;
+ UINT32 TimerCycle;
+
+ Begin = 0;
+ TimeoutTicker = 0;
+ TimerRound = 0;
+ TimerFrequency = GetMailboxPointer ()->DebugTimerFrequency;
+ TimerCycle = GetApicTimerInitCount ();
if (Timeout != 0) {
- Begin = GetApicTimerCurrentCount ();
- TimeoutTicker = (UINT32) DivU64x32 (
- MultU64x64 (
- TimerFrequency,
- Timeout
- ),
- 1000000u
- );
- TimerRound = (UINT32) DivU64x32Remainder (TimeoutTicker, TimerCycle / 2, &TimeoutTicker);
+ Begin = GetApicTimerCurrentCount ();
+ TimeoutTicker = (UINT32)DivU64x32 (
+ MultU64x64 (
+ TimerFrequency,
+ Timeout
+ ),
+ 1000000u
+ );
+ TimerRound = (UINT32)DivU64x32Remainder (TimeoutTicker, TimerCycle / 2, &TimeoutTicker);
}
+
Index = 0;
while (Index < NumberOfBytes) {
if (DebugPortPollBuffer (Handle)) {
DebugPortReadBuffer (Handle, Buffer + Index, 1, 0);
- Index ++;
+ Index++;
continue;
}
+
if (Timeout != 0) {
if (TimerRound == 0) {
if (IsDebugTimerTimeout (TimerCycle, Begin, TimeoutTicker)) {
@@ -412,7 +414,7 @@ DebugAgentReadBuffer (
}
} else {
if (IsDebugTimerTimeout (TimerCycle, Begin, TimerCycle / 2)) {
- TimerRound --;
+ TimerRound--;
Begin = GetApicTimerCurrentCount ();
}
}
@@ -431,16 +433,16 @@ DebugAgentReadBuffer (
**/
VOID
SetDebugFlag (
- IN UINT64 FlagMask,
- IN UINT32 FlagValue
+ IN UINT64 FlagMask,
+ IN UINT32 FlagValue
)
{
- DEBUG_AGENT_MAILBOX *Mailbox;
- UINT64 Data64;
+ DEBUG_AGENT_MAILBOX *Mailbox;
+ UINT64 Data64;
Mailbox = GetMailboxPointer ();
- Data64 = (Mailbox->DebugFlag.Uint64 & ~FlagMask) |
- (LShiftU64 ((UINT64)FlagValue, LowBitSet64 (FlagMask)) & FlagMask);
+ Data64 = (Mailbox->DebugFlag.Uint64 & ~FlagMask) |
+ (LShiftU64 ((UINT64)FlagValue, LowBitSet64 (FlagMask)) & FlagMask);
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_FLAG_INDEX, Data64);
}
@@ -454,14 +456,14 @@ SetDebugFlag (
**/
UINT32
GetDebugFlag (
- IN UINT64 FlagMask
+ IN UINT64 FlagMask
)
{
- DEBUG_AGENT_MAILBOX *Mailbox;
- UINT32 DebugFlag;
+ DEBUG_AGENT_MAILBOX *Mailbox;
+ UINT32 DebugFlag;
- Mailbox = GetMailboxPointer ();
- DebugFlag = (UINT32) RShiftU64 (Mailbox->DebugFlag.Uint64 & FlagMask, LowBitSet64 (FlagMask));
+ Mailbox = GetMailboxPointer ();
+ DebugFlag = (UINT32)RShiftU64 (Mailbox->DebugFlag.Uint64 & FlagMask, LowBitSet64 (FlagMask));
return DebugFlag;
}
@@ -475,22 +477,23 @@ GetDebugFlag (
**/
VOID
SendDebugMsgPacket (
- IN CHAR8 *Buffer,
- IN UINTN Length
+ IN CHAR8 *Buffer,
+ IN UINTN Length
)
{
DEBUG_PACKET_HEADER DebugHeader;
DEBUG_PORT_HANDLE Handle;
- Handle = GetDebugPortHandle();
+ Handle = GetDebugPortHandle ();
DebugHeader.StartSymbol = DEBUG_STARTING_SYMBOL_NORMAL;
DebugHeader.Command = DEBUG_COMMAND_PRINT_MESSAGE;
- DebugHeader.Length = sizeof (DEBUG_PACKET_HEADER) + (UINT8) Length;
+ DebugHeader.Length = sizeof (DEBUG_PACKET_HEADER) + (UINT8)Length;
DebugHeader.SequenceNo = 0xEE;
DebugHeader.Crc = 0;
DebugHeader.Crc = CalculateCrc16 (
- (UINT8 *)Buffer, Length,
+ (UINT8 *)Buffer,
+ Length,
CalculateCrc16 ((UINT8 *)&DebugHeader, sizeof (DEBUG_PACKET_HEADER), 0)
);
@@ -513,13 +516,13 @@ SendDebugMsgPacket (
VOID
EFIAPI
DebugAgentMsgPrint (
- IN UINT8 ErrorLevel,
- IN CHAR8 *Format,
+ IN UINT8 ErrorLevel,
+ IN CHAR8 *Format,
...
)
{
- CHAR8 Buffer[DEBUG_DATA_MAXIMUM_REAL_DATA];
- VA_LIST Marker;
+ CHAR8 Buffer[DEBUG_DATA_MAXIMUM_REAL_DATA];
+ VA_LIST Marker;
//
// Check driver debug mask value and global mask
@@ -556,15 +559,15 @@ DebugAgentMsgPrint (
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
)
{
- CHAR8 Buffer[DEBUG_DATA_MAXIMUM_REAL_DATA];
- CHAR8 *DestBuffer;
- UINTN Index;
+ CHAR8 Buffer[DEBUG_DATA_MAXIMUM_REAL_DATA];
+ CHAR8 *DestBuffer;
+ UINTN Index;
//
// Check driver debug mask value and global mask
@@ -590,13 +593,14 @@ DebugAgentDataMsgPrint (
SendDebugMsgPacket (Buffer, DestBuffer - Buffer);
DestBuffer = Buffer;
}
+
DestBuffer += AsciiSPrint (DestBuffer, DEBUG_DATA_MAXIMUM_REAL_DATA - (DestBuffer - Buffer), "%02x ", Data[Index]);
- Index ++;
+ Index++;
if (Index >= Length) {
//
// The last character of debug message has been formatted in buffer
//
- DestBuffer += AsciiSPrint(DestBuffer, DEBUG_DATA_MAXIMUM_REAL_DATA - (DestBuffer - Buffer), "]\n");
+ DestBuffer += AsciiSPrint (DestBuffer, DEBUG_DATA_MAXIMUM_REAL_DATA - (DestBuffer - Buffer), "]\n");
SendDebugMsgPacket (Buffer, DestBuffer - Buffer);
break;
}
@@ -617,12 +621,12 @@ 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
)
{
- UINT16 Crc;
- DEBUG_AGENT_MAILBOX *Mailbox;
+ UINT16 Crc;
+ DEBUG_AGENT_MAILBOX *Mailbox;
//
// Has received start symbol, try to read the rest part
@@ -635,22 +639,24 @@ ReadRemainingBreakPacket (
return EFI_TIMEOUT;
}
- Crc = DebugHeader->Crc;
+ Crc = DebugHeader->Crc;
DebugHeader->Crc = 0;
if (CalculateCrc16 ((UINT8 *)DebugHeader, DebugHeader->Length, 0) != Crc) {
- DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "Debug Timer CRC (%x) against (%x)\n", Crc, CalculateCrc16 ((UINT8 *) &DebugHeader, DebugHeader->Length, 0));
+ DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "Debug Timer CRC (%x) against (%x)\n", Crc, CalculateCrc16 ((UINT8 *)&DebugHeader, DebugHeader->Length, 0));
DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, FALSE, (UINT8 *)DebugHeader, DebugHeader->Length);
return EFI_CRC_ERROR;
}
- Mailbox = GetMailboxPointer();
+
+ Mailbox = GetMailboxPointer ();
if (IS_REQUEST (DebugHeader)) {
- if (DebugHeader->SequenceNo == (UINT8) (Mailbox->HostSequenceNo + 1)) {
+ if (DebugHeader->SequenceNo == (UINT8)(Mailbox->HostSequenceNo + 1)) {
//
// Only updagte HostSequenceNo for new command packet
//
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, DebugHeader->SequenceNo);
return EFI_SUCCESS;
}
+
if (DebugHeader->SequenceNo == Mailbox->HostSequenceNo) {
return EFI_SUCCESS;
}
@@ -671,7 +677,7 @@ IsHostAttached (
VOID
)
{
- return (BOOLEAN) (GetDebugFlag (DEBUG_AGENT_FLAG_HOST_ATTACHED) == 1);
+ return (BOOLEAN)(GetDebugFlag (DEBUG_AGENT_FLAG_HOST_ATTACHED) == 1);
}
/**
@@ -682,7 +688,7 @@ IsHostAttached (
**/
VOID
SetHostAttached (
- IN BOOLEAN Attached
+ IN BOOLEAN Attached
)
{
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Attach status is %d\n", Attached);
@@ -703,22 +709,23 @@ SetDebugSetting (
IN DEBUG_DATA_SET_DEBUG_SETTING *DebugSetting
)
{
- RETURN_STATUS Status;
+ RETURN_STATUS Status;
Status = RETURN_SUCCESS;
switch (DebugSetting->Key) {
- case DEBUG_AGENT_SETTING_SMM_ENTRY_BREAK:
- SetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI, DebugSetting->Value);
- break;
- case DEBUG_AGENT_SETTING_PRINT_ERROR_LEVEL:
- SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DebugSetting->Value);
- break;
- case DEBUG_AGENT_SETTING_BOOT_SCRIPT_ENTRY_BREAK:
- SetDebugFlag (DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT, DebugSetting->Value);
- break;
- default:
- Status = RETURN_UNSUPPORTED;
+ case DEBUG_AGENT_SETTING_SMM_ENTRY_BREAK:
+ SetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI, DebugSetting->Value);
+ break;
+ case DEBUG_AGENT_SETTING_PRINT_ERROR_LEVEL:
+ SetDebugFlag (DEBUG_AGENT_FLAG_PRINT_ERROR_LEVEL, DebugSetting->Value);
+ break;
+ case DEBUG_AGENT_SETTING_BOOT_SCRIPT_ENTRY_BREAK:
+ SetDebugFlag (DEBUG_AGENT_FLAG_BREAK_BOOT_SCRIPT, DebugSetting->Value);
+ break;
+ default:
+ Status = RETURN_UNSUPPORTED;
}
+
return Status;
}
@@ -730,12 +737,12 @@ SetDebugSetting (
**/
VOID
CommandGo (
- IN DEBUG_CPU_CONTEXT *CpuContext
+ IN DEBUG_CPU_CONTEXT *CpuContext
)
{
- IA32_EFLAGS32 *Eflags;
+ IA32_EFLAGS32 *Eflags;
- Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags;
+ Eflags = (IA32_EFLAGS32 *)&CpuContext->Eflags;
Eflags->Bits.TF = 0;
Eflags->Bits.RF = 1;
}
@@ -748,12 +755,12 @@ CommandGo (
**/
VOID
CommandStepping (
- IN DEBUG_CPU_CONTEXT *CpuContext
+ IN DEBUG_CPU_CONTEXT *CpuContext
)
{
- IA32_EFLAGS32 *Eflags;
+ IA32_EFLAGS32 *Eflags;
- Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags;
+ Eflags = (IA32_EFLAGS32 *)&CpuContext->Eflags;
Eflags->Bits.TF = 1;
Eflags->Bits.RF = 1;
//
@@ -775,12 +782,12 @@ CommandStepping (
**/
VOID
CommandSteppingCleanup (
- IN DEBUG_CPU_CONTEXT *CpuContext
+ IN DEBUG_CPU_CONTEXT *CpuContext
)
{
- IA32_EFLAGS32 *Eflags;
+ IA32_EFLAGS32 *Eflags;
- Eflags = (IA32_EFLAGS32 *) &CpuContext->Eflags;
+ Eflags = (IA32_EFLAGS32 *)&CpuContext->Eflags;
//
// Restore EFLAGS.IF
//
@@ -804,27 +811,27 @@ SetDebugRegister (
IN DEBUG_DATA_SET_HW_BREAKPOINT *SetHwBreakpoint
)
{
- UINT8 RegisterIndex;
- UINTN Dr7Value;
+ UINT8 RegisterIndex;
+ UINTN Dr7Value;
RegisterIndex = SetHwBreakpoint->Type.Index;
//
// Set debug address
//
- * ((UINTN *) &CpuContext->Dr0 + RegisterIndex) = (UINTN) SetHwBreakpoint->Address;
+ *((UINTN *)&CpuContext->Dr0 + RegisterIndex) = (UINTN)SetHwBreakpoint->Address;
Dr7Value = CpuContext->Dr7;
//
// Enable Gx, Lx
//
- Dr7Value |= (UINTN) (0x3 << (RegisterIndex * 2));
+ Dr7Value |= (UINTN)(0x3 << (RegisterIndex * 2));
//
// Set RWx and Lenx
//
- Dr7Value &= (UINTN) (~(0xf << (16 + RegisterIndex * 4)));
- Dr7Value |= (UINTN) ((SetHwBreakpoint->Type.Length << 2) | SetHwBreakpoint->Type.Access) << (16 + RegisterIndex * 4);
+ Dr7Value &= (UINTN)(~(0xf << (16 + RegisterIndex * 4)));
+ Dr7Value |= (UINTN)((SetHwBreakpoint->Type.Length << 2) | SetHwBreakpoint->Type.Access) << (16 + RegisterIndex * 4);
//
// Enable GE, LE
//
@@ -842,29 +849,31 @@ SetDebugRegister (
**/
VOID
ClearDebugRegister (
- IN DEBUG_CPU_CONTEXT *CpuContext,
- IN DEBUG_DATA_CLEAR_HW_BREAKPOINT *ClearHwBreakpoint
+ IN DEBUG_CPU_CONTEXT *CpuContext,
+ IN DEBUG_DATA_CLEAR_HW_BREAKPOINT *ClearHwBreakpoint
)
{
if ((ClearHwBreakpoint->IndexMask & BIT0) != 0) {
- CpuContext->Dr0 = 0;
+ CpuContext->Dr0 = 0;
CpuContext->Dr7 &= (UINTN)(~(0x3 << 0));
}
+
if ((ClearHwBreakpoint->IndexMask & BIT1) != 0) {
- CpuContext->Dr1 = 0;
+ CpuContext->Dr1 = 0;
CpuContext->Dr7 &= (UINTN)(~(0x3 << 2));
}
+
if ((ClearHwBreakpoint->IndexMask & BIT2) != 0) {
- CpuContext->Dr2 = 0;
+ CpuContext->Dr2 = 0;
CpuContext->Dr7 &= (UINTN)(~(0x3 << 4));
}
+
if ((ClearHwBreakpoint->IndexMask & BIT3) != 0) {
- CpuContext->Dr3 = 0;
+ CpuContext->Dr3 = 0;
CpuContext->Dr7 &= (UINTN)(~(0x3 << 6));
}
}
-
/**
Return the offset of FP / MMX / XMM registers in the FPU saved state by register index.
@@ -876,51 +885,51 @@ ClearDebugRegister (
**/
UINT16
ArchReadFxStatOffset (
- IN UINT8 Index,
- OUT UINT8 *Width
+ IN UINT8 Index,
+ OUT UINT8 *Width
)
{
if (Index < SOFT_DEBUGGER_REGISTER_ST0) {
switch (Index) {
- case SOFT_DEBUGGER_REGISTER_FP_FCW:
- *Width = (UINT8) sizeof (UINT16);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Fcw);
+ case SOFT_DEBUGGER_REGISTER_FP_FCW:
+ *Width = (UINT8)sizeof (UINT16);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Fcw);
- case SOFT_DEBUGGER_REGISTER_FP_FSW:
- *Width = (UINT8) sizeof (UINT16);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Fsw);
+ case SOFT_DEBUGGER_REGISTER_FP_FSW:
+ *Width = (UINT8)sizeof (UINT16);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Fsw);
- case SOFT_DEBUGGER_REGISTER_FP_FTW:
- *Width = (UINT8) sizeof (UINT16);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Ftw);
+ case SOFT_DEBUGGER_REGISTER_FP_FTW:
+ *Width = (UINT8)sizeof (UINT16);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Ftw);
- case SOFT_DEBUGGER_REGISTER_FP_OPCODE:
- *Width = (UINT8) sizeof (UINT16);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Opcode);
+ case SOFT_DEBUGGER_REGISTER_FP_OPCODE:
+ *Width = (UINT8)sizeof (UINT16);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Opcode);
- case SOFT_DEBUGGER_REGISTER_FP_EIP:
- *Width = (UINT8) sizeof (UINT32);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Eip);
+ case SOFT_DEBUGGER_REGISTER_FP_EIP:
+ *Width = (UINT8)sizeof (UINT32);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Eip);
- case SOFT_DEBUGGER_REGISTER_FP_CS:
- *Width = (UINT8) sizeof (UINT16);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Cs);
+ case SOFT_DEBUGGER_REGISTER_FP_CS:
+ *Width = (UINT8)sizeof (UINT16);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Cs);
- case SOFT_DEBUGGER_REGISTER_FP_DATAOFFSET:
- *Width = (UINT8) sizeof (UINT32);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, DataOffset);
+ case SOFT_DEBUGGER_REGISTER_FP_DATAOFFSET:
+ *Width = (UINT8)sizeof (UINT32);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, DataOffset);
- case SOFT_DEBUGGER_REGISTER_FP_DS:
- *Width = (UINT8) sizeof (UINT16);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Ds);
+ case SOFT_DEBUGGER_REGISTER_FP_DS:
+ *Width = (UINT8)sizeof (UINT16);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Ds);
- case SOFT_DEBUGGER_REGISTER_FP_MXCSR:
- *Width = (UINT8) sizeof (UINT32);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Mxcsr);
+ case SOFT_DEBUGGER_REGISTER_FP_MXCSR:
+ *Width = (UINT8)sizeof (UINT32);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Mxcsr);
- case SOFT_DEBUGGER_REGISTER_FP_MXCSR_MASK:
- *Width = (UINT8) sizeof (UINT32);
- return OFFSET_OF(DEBUG_DATA_FX_SAVE_STATE, Mxcsr_Mask);
+ case SOFT_DEBUGGER_REGISTER_FP_MXCSR_MASK:
+ *Width = (UINT8)sizeof (UINT32);
+ return OFFSET_OF (DEBUG_DATA_FX_SAVE_STATE, Mxcsr_Mask);
}
}
@@ -951,21 +960,21 @@ ArchReadFxStatOffset (
**/
UINT8 *
ArchReadRegisterBuffer (
- IN DEBUG_CPU_CONTEXT *CpuContext,
- IN UINT8 Index,
- OUT UINT8 *Width
+ IN DEBUG_CPU_CONTEXT *CpuContext,
+ IN UINT8 Index,
+ OUT UINT8 *Width
)
{
- UINT8 *Buffer;
+ UINT8 *Buffer;
if (Index < SOFT_DEBUGGER_REGISTER_FP_BASE) {
- Buffer = (UINT8 *) CpuContext + OFFSET_OF (DEBUG_CPU_CONTEXT, Dr0) + Index * sizeof (UINTN);
- *Width = (UINT8) sizeof (UINTN);
+ Buffer = (UINT8 *)CpuContext + OFFSET_OF (DEBUG_CPU_CONTEXT, Dr0) + Index * sizeof (UINTN);
+ *Width = (UINT8)sizeof (UINTN);
} else {
//
// FPU/MMX/XMM registers
//
- Buffer = (UINT8 *) CpuContext + OFFSET_OF (DEBUG_CPU_CONTEXT, FxSaveState) + ArchReadFxStatOffset (Index, Width);
+ Buffer = (UINT8 *)CpuContext + OFFSET_OF (DEBUG_CPU_CONTEXT, FxSaveState) + ArchReadFxStatOffset (Index, Width);
}
return Buffer;
@@ -980,14 +989,14 @@ ArchReadRegisterBuffer (
**/
VOID
SendPacketWithoutData (
- IN UINT8 CommandType,
- IN UINT8 SequenceNo
+ IN UINT8 CommandType,
+ IN UINT8 SequenceNo
)
{
- DEBUG_PACKET_HEADER DebugHeader;
- DEBUG_PORT_HANDLE Handle;
+ DEBUG_PACKET_HEADER DebugHeader;
+ DEBUG_PORT_HANDLE Handle;
- Handle = GetDebugPortHandle();
+ Handle = GetDebugPortHandle ();
DebugHeader.StartSymbol = DEBUG_STARTING_SYMBOL_NORMAL;
DebugHeader.Command = CommandType;
@@ -996,8 +1005,8 @@ SendPacketWithoutData (
DebugHeader.Crc = 0;
DebugHeader.Crc = CalculateCrc16 ((UINT8 *)&DebugHeader, sizeof (DEBUG_PACKET_HEADER), 0);
- DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, TRUE, (UINT8 *) &DebugHeader, DebugHeader.Length);
- DebugPortWriteBuffer (Handle, (UINT8 *) &DebugHeader, DebugHeader.Length);
+ DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, TRUE, (UINT8 *)&DebugHeader, DebugHeader.Length);
+ DebugPortWriteBuffer (Handle, (UINT8 *)&DebugHeader, DebugHeader.Length);
}
/**
@@ -1008,11 +1017,11 @@ SendPacketWithoutData (
**/
VOID
SendAckPacket (
- IN UINT8 AckCommand
+ IN UINT8 AckCommand
)
{
- UINT8 SequenceNo;
- DEBUG_AGENT_MAILBOX *Mailbox;
+ UINT8 SequenceNo;
+ DEBUG_AGENT_MAILBOX *Mailbox;
if (AckCommand != DEBUG_COMMAND_OK) {
//
@@ -1020,7 +1029,8 @@ SendAckPacket (
//
DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "Send ACK(%d)\n", AckCommand);
}
- Mailbox = GetMailboxPointer();
+
+ Mailbox = GetMailboxPointer ();
SequenceNo = Mailbox->HostSequenceNo;
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "SendAckPacket: SequenceNo = %x\n", SequenceNo);
SendPacketWithoutData (AckCommand, SequenceNo);
@@ -1038,30 +1048,31 @@ SendAckPacket (
**/
UINT8
DecompressDataInPlace (
- IN OUT UINT8 *Data,
- IN UINTN Length
+ IN OUT UINT8 *Data,
+ IN UINTN Length
)
{
- UINTN Index;
- UINT16 LastChar;
- UINTN LastCharCount;
- UINT8 CurrentChar;
+ UINTN Index;
+ UINT16 LastChar;
+ UINTN LastCharCount;
+ UINT8 CurrentChar;
- LastChar = (UINT16) -1;
+ LastChar = (UINT16)-1;
LastCharCount = 0;
for (Index = 0; Index < Length; Index++) {
CurrentChar = Data[Index];
if (LastCharCount == 2) {
LastCharCount = 0;
CopyMem (&Data[Index + CurrentChar], &Data[Index + 1], Length - Index - 1);
- SetMem (&Data[Index], CurrentChar, (UINT8) LastChar);
- LastChar = (UINT16) -1;
- Index += CurrentChar - 1;
- Length += CurrentChar - 1;
+ SetMem (&Data[Index], CurrentChar, (UINT8)LastChar);
+ LastChar = (UINT16)-1;
+ Index += CurrentChar - 1;
+ Length += CurrentChar - 1;
} else {
if (LastChar != CurrentChar) {
LastCharCount = 0;
}
+
LastCharCount++;
LastChar = CurrentChar;
}
@@ -1069,7 +1080,7 @@ DecompressDataInPlace (
ASSERT (Length <= DEBUG_DATA_MAXIMUM_REAL_DATA);
- return (UINT8) Length;
+ return (UINT8)Length;
}
/**
@@ -1092,27 +1103,27 @@ DecompressDataInPlace (
**/
RETURN_STATUS
ReceivePacket (
- OUT UINT8 *InputPacket,
- OUT BOOLEAN *BreakReceived,
- OUT BOOLEAN *IncompatibilityFlag OPTIONAL,
- IN UINTN Timeout,
- IN BOOLEAN SkipStartSymbol
+ OUT UINT8 *InputPacket,
+ OUT BOOLEAN *BreakReceived,
+ OUT BOOLEAN *IncompatibilityFlag OPTIONAL,
+ IN UINTN Timeout,
+ IN BOOLEAN SkipStartSymbol
)
{
- DEBUG_PACKET_HEADER *DebugHeader;
- UINTN Received;
- DEBUG_PORT_HANDLE Handle;
- UINT16 Crc;
- UINTN TimeoutForStartSymbol;
+ DEBUG_PACKET_HEADER *DebugHeader;
+ UINTN Received;
+ DEBUG_PORT_HANDLE Handle;
+ UINT16 Crc;
+ UINTN TimeoutForStartSymbol;
- Handle = GetDebugPortHandle();
+ Handle = GetDebugPortHandle ();
if (SkipStartSymbol) {
TimeoutForStartSymbol = 0;
} else {
TimeoutForStartSymbol = Timeout;
}
- DebugHeader = (DEBUG_PACKET_HEADER *) InputPacket;
+ DebugHeader = (DEBUG_PACKET_HEADER *)InputPacket;
while (TRUE) {
//
// Find the valid start symbol
@@ -1133,7 +1144,7 @@ ReceivePacket (
//
Received = DebugAgentReadBuffer (
Handle,
- (UINT8 *) DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command),
+ (UINT8 *)DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command),
OFFSET_OF (DEBUG_PACKET_HEADER, Length) + sizeof (DebugHeader->Length) - sizeof (DebugHeader->StartSymbol),
Timeout
);
@@ -1141,6 +1152,7 @@ ReceivePacket (
DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "DebugAgentReadBuffer(Command) timeout\n");
return RETURN_TIMEOUT;
}
+
if (DebugHeader->Length < sizeof (DEBUG_PACKET_HEADER)) {
if (IncompatibilityFlag != NULL) {
//
@@ -1157,32 +1169,36 @@ ReceivePacket (
//
// Read the payload data include the CRC field
//
- Received = DebugAgentReadBuffer (Handle, &DebugHeader->SequenceNo, (UINT8) (DebugHeader->Length - OFFSET_OF (DEBUG_PACKET_HEADER, SequenceNo)), Timeout);
+ Received = DebugAgentReadBuffer (Handle, &DebugHeader->SequenceNo, (UINT8)(DebugHeader->Length - OFFSET_OF (DEBUG_PACKET_HEADER, SequenceNo)), Timeout);
if (Received == 0) {
DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "DebugAgentReadBuffer(SequenceNo) timeout\n");
return RETURN_TIMEOUT;
}
+
//
// Calculate the CRC of Debug Packet
//
- Crc = DebugHeader->Crc;
+ Crc = DebugHeader->Crc;
DebugHeader->Crc = 0;
- if (Crc == CalculateCrc16 ((UINT8 *) DebugHeader, DebugHeader->Length, 0)) {
+ if (Crc == CalculateCrc16 ((UINT8 *)DebugHeader, DebugHeader->Length, 0)) {
break;
}
+
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "CRC Error (received CRC is %x)\n", Crc);
- DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, FALSE, (UINT8 *) DebugHeader, DebugHeader->Length);
+ DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, FALSE, (UINT8 *)DebugHeader, DebugHeader->Length);
}
}
- DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, FALSE, (UINT8 *) DebugHeader, DebugHeader->Length);
+ DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, FALSE, (UINT8 *)DebugHeader, DebugHeader->Length);
if (DebugHeader->StartSymbol == DEBUG_STARTING_SYMBOL_COMPRESS) {
DebugHeader->StartSymbol = DEBUG_STARTING_SYMBOL_NORMAL;
DebugHeader->Length = DecompressDataInPlace (
- (UINT8 *) (DebugHeader + 1), DebugHeader->Length - sizeof (DEBUG_PACKET_HEADER)
+ (UINT8 *)(DebugHeader + 1),
+ DebugHeader->Length - sizeof (DEBUG_PACKET_HEADER)
) + sizeof (DEBUG_PACKET_HEADER);
}
+
return RETURN_SUCCESS;
}
@@ -1206,53 +1222,57 @@ ReceivePacket (
**/
RETURN_STATUS
SendCommandAndWaitForAckOK (
- IN UINT8 Command,
- IN UINTN Timeout,
- OUT BOOLEAN *BreakReceived OPTIONAL,
- OUT BOOLEAN *IncompatibilityFlag OPTIONAL
+ IN UINT8 Command,
+ IN UINTN Timeout,
+ OUT BOOLEAN *BreakReceived OPTIONAL,
+ OUT BOOLEAN *IncompatibilityFlag OPTIONAL
)
{
- RETURN_STATUS Status;
- UINT8 InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT];
- DEBUG_PACKET_HEADER *DebugHeader;
- UINT8 SequenceNo;
- UINT8 HostSequenceNo;
- UINT8 RetryCount;
+ RETURN_STATUS Status;
+ UINT8 InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT];
+ DEBUG_PACKET_HEADER *DebugHeader;
+ UINT8 SequenceNo;
+ UINT8 HostSequenceNo;
+ UINT8 RetryCount;
RetryCount = 3;
- DebugHeader = (DEBUG_PACKET_HEADER *) InputPacketBuffer;
+ DebugHeader = (DEBUG_PACKET_HEADER *)InputPacketBuffer;
Status = RETURN_TIMEOUT;
while (RetryCount > 0) {
- SequenceNo = GetMailboxPointer()->SequenceNo;
- HostSequenceNo = GetMailboxPointer()->HostSequenceNo;
+ SequenceNo = GetMailboxPointer ()->SequenceNo;
+ HostSequenceNo = GetMailboxPointer ()->HostSequenceNo;
SendPacketWithoutData (Command, SequenceNo);
- Status = ReceivePacket ((UINT8 *) DebugHeader, BreakReceived, IncompatibilityFlag, Timeout, FALSE);
+ Status = ReceivePacket ((UINT8 *)DebugHeader, BreakReceived, IncompatibilityFlag, Timeout, FALSE);
if (Status == RETURN_TIMEOUT) {
if (Command == DEBUG_COMMAND_INIT_BREAK) {
RetryCount--;
} else {
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Timeout when waiting for ACK packet.\n");
}
+
continue;
}
+
ASSERT_EFI_ERROR (Status);
//
// Status == RETURN_SUCCESS
//
- if (DebugHeader->Command == DEBUG_COMMAND_OK && DebugHeader->SequenceNo == SequenceNo) {
+ if ((DebugHeader->Command == DEBUG_COMMAND_OK) && (DebugHeader->SequenceNo == SequenceNo)) {
//
// Received Ack OK
//
- UpdateMailboxContent (GetMailboxPointer(), DEBUG_MAILBOX_SEQUENCE_NO_INDEX, ++SequenceNo);
+ UpdateMailboxContent (GetMailboxPointer (), DEBUG_MAILBOX_SEQUENCE_NO_INDEX, ++SequenceNo);
return Status;
}
- if (DebugHeader->Command == DEBUG_COMMAND_GO && (DebugHeader->SequenceNo == HostSequenceNo || Command == DEBUG_COMMAND_INIT_BREAK)) {
+
+ if ((DebugHeader->Command == DEBUG_COMMAND_GO) && ((DebugHeader->SequenceNo == HostSequenceNo) || (Command == DEBUG_COMMAND_INIT_BREAK))) {
//
// Received Old GO
//
if (Command == DEBUG_COMMAND_INIT_BREAK) {
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Receive GO() in last boot\n");
}
+
SendPacketWithoutData (DEBUG_COMMAND_OK, DebugHeader->SequenceNo);
}
}
@@ -1272,89 +1292,89 @@ SendCommandAndWaitForAckOK (
**/
UINT8
GetBreakCause (
- IN UINTN Vector,
- IN DEBUG_CPU_CONTEXT *CpuContext
+ IN UINTN Vector,
+ IN DEBUG_CPU_CONTEXT *CpuContext
)
{
- UINT8 Cause;
+ UINT8 Cause;
Cause = DEBUG_DATA_BREAK_CAUSE_UNKNOWN;
switch (Vector) {
- case DEBUG_INT1_VECTOR:
- case DEBUG_INT3_VECTOR:
+ case DEBUG_INT1_VECTOR:
+ case DEBUG_INT3_VECTOR:
- if (Vector == DEBUG_INT1_VECTOR) {
- //
- // INT 1
- //
- if ((CpuContext->Dr6 & BIT14) != 0) {
- Cause = DEBUG_DATA_BREAK_CAUSE_STEPPING;
+ if (Vector == DEBUG_INT1_VECTOR) {
//
- // DR6.BIT14 Indicates (when set) that the debug exception was
- // triggered by the single step execution mode.
- // The single-step mode is the highest priority debug exception.
- // This is single step, no need to check DR0, to ensure single step
- // work in PeCoffExtraActionLib (right after triggering a breakpoint
- // to report image load/unload).
+ // INT 1
//
- return Cause;
-
+ if ((CpuContext->Dr6 & BIT14) != 0) {
+ Cause = DEBUG_DATA_BREAK_CAUSE_STEPPING;
+ //
+ // DR6.BIT14 Indicates (when set) that the debug exception was
+ // triggered by the single step execution mode.
+ // The single-step mode is the highest priority debug exception.
+ // This is single step, no need to check DR0, to ensure single step
+ // work in PeCoffExtraActionLib (right after triggering a breakpoint
+ // to report image load/unload).
+ //
+ return Cause;
+ } else {
+ Cause = DEBUG_DATA_BREAK_CAUSE_HW_BREAKPOINT;
+ }
} else {
- Cause = DEBUG_DATA_BREAK_CAUSE_HW_BREAKPOINT;
+ //
+ // INT 3
+ //
+ Cause = DEBUG_DATA_BREAK_CAUSE_SW_BREAKPOINT;
}
- } else {
- //
- // INT 3
- //
- Cause = DEBUG_DATA_BREAK_CAUSE_SW_BREAKPOINT;
- }
- switch (CpuContext->Dr0) {
- case IMAGE_LOAD_SIGNATURE:
- case IMAGE_UNLOAD_SIGNATURE:
+ switch (CpuContext->Dr0) {
+ case IMAGE_LOAD_SIGNATURE:
+ case IMAGE_UNLOAD_SIGNATURE:
- if (CpuContext->Dr3 == IO_PORT_BREAKPOINT_ADDRESS) {
+ if (CpuContext->Dr3 == IO_PORT_BREAKPOINT_ADDRESS) {
+ Cause = (UINT8)((CpuContext->Dr0 == IMAGE_LOAD_SIGNATURE) ?
+ DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD : DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD);
+ }
- Cause = (UINT8) ((CpuContext->Dr0 == IMAGE_LOAD_SIGNATURE) ?
- DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD : DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD);
- }
- break;
+ break;
- case SOFT_INTERRUPT_SIGNATURE:
+ case SOFT_INTERRUPT_SIGNATURE:
- if (CpuContext->Dr1 == MEMORY_READY_SIGNATURE) {
- Cause = DEBUG_DATA_BREAK_CAUSE_MEMORY_READY;
- CpuContext->Dr0 = 0;
- } else if (CpuContext->Dr1 == SYSTEM_RESET_SIGNATURE) {
- Cause = DEBUG_DATA_BREAK_CAUSE_SYSTEM_RESET;
- CpuContext->Dr0 = 0;
- }
- break;
+ if (CpuContext->Dr1 == MEMORY_READY_SIGNATURE) {
+ Cause = DEBUG_DATA_BREAK_CAUSE_MEMORY_READY;
+ CpuContext->Dr0 = 0;
+ } else if (CpuContext->Dr1 == SYSTEM_RESET_SIGNATURE) {
+ Cause = DEBUG_DATA_BREAK_CAUSE_SYSTEM_RESET;
+ CpuContext->Dr0 = 0;
+ }
- default:
- break;
+ break;
- }
+ default:
+ break;
+ }
- break;
+ break;
- case DEBUG_TIMER_VECTOR:
- Cause = DEBUG_DATA_BREAK_CAUSE_USER_HALT;
- break;
+ case DEBUG_TIMER_VECTOR:
+ Cause = DEBUG_DATA_BREAK_CAUSE_USER_HALT;
+ break;
- default:
- if (Vector < 20) {
- if (GetDebugFlag (DEBUG_AGENT_FLAG_STEPPING) == 1) {
- //
- // If stepping command is executing
- //
- Cause = DEBUG_DATA_BREAK_CAUSE_STEPPING;
- } else {
- Cause = DEBUG_DATA_BREAK_CAUSE_EXCEPTION;
+ default:
+ if (Vector < 20) {
+ if (GetDebugFlag (DEBUG_AGENT_FLAG_STEPPING) == 1) {
+ //
+ // If stepping command is executing
+ //
+ Cause = DEBUG_DATA_BREAK_CAUSE_STEPPING;
+ } else {
+ Cause = DEBUG_DATA_BREAK_CAUSE_EXCEPTION;
+ }
}
- }
- break;
+
+ break;
}
return Cause;
@@ -1371,15 +1391,15 @@ GetBreakCause (
**/
VOID
CopyMemByWidth (
- OUT UINT8 *Dest,
- IN UINT8 *Src,
- IN UINT16 Count,
- IN UINT8 Width
+ OUT UINT8 *Dest,
+ IN UINT8 *Src,
+ IN UINT16 Count,
+ IN UINT8 Width
)
{
- UINT8 *Destination;
- UINT8 *Source;
- INT8 Step;
+ UINT8 *Destination;
+ UINT8 *Source;
+ INT8 Step;
if (Src > Dest) {
Destination = Dest;
@@ -1396,21 +1416,22 @@ CopyMemByWidth (
while (Count-- != 0) {
switch (Width) {
- case 1:
- *(UINT8 *) Destination = MmioRead8 ((UINTN) Source);
- break;
- case 2:
- *(UINT16 *) Destination = MmioRead16 ((UINTN) Source);
- break;
- case 4:
- *(UINT32 *) Destination = MmioRead32 ((UINTN) Source);
- break;
- case 8:
- *(UINT64 *) Destination = MmioRead64 ((UINTN) Source);
- break;
- default:
- ASSERT (FALSE);
+ case 1:
+ *(UINT8 *)Destination = MmioRead8 ((UINTN)Source);
+ break;
+ case 2:
+ *(UINT16 *)Destination = MmioRead16 ((UINTN)Source);
+ break;
+ case 4:
+ *(UINT32 *)Destination = MmioRead32 ((UINTN)Source);
+ break;
+ case 8:
+ *(UINT64 *)Destination = MmioRead64 ((UINTN)Source);
+ break;
+ default:
+ ASSERT (FALSE);
}
+
Source += Step;
Destination += Step;
}
@@ -1437,19 +1458,19 @@ CopyMemByWidth (
**/
VOID
CompressData (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Data,
- IN UINT8 Length,
- IN BOOLEAN Send,
- OUT UINTN *CompressedLength OPTIONAL,
- OUT UINT16 *CompressedCrc OPTIONAL
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Data,
+ IN UINT8 Length,
+ IN BOOLEAN Send,
+ OUT UINTN *CompressedLength OPTIONAL,
+ OUT UINT16 *CompressedCrc OPTIONAL
)
{
- UINTN Index;
- UINT8 LastChar;
- UINT8 LastCharCount;
- UINT8 CurrentChar;
- UINTN CompressedIndex;
+ UINTN Index;
+ UINT8 LastChar;
+ UINT8 LastCharCount;
+ UINT8 CurrentChar;
+ UINTN CompressedIndex;
ASSERT (Length > 0);
LastChar = Data[0] + 1; // Just ensure it's different from the first byte.
@@ -1459,34 +1480,38 @@ CompressData (
if (Index < Length) {
CurrentChar = Data[Index];
} else {
- CurrentChar = (UINT8) LastChar + 1; // just ensure it's different from LastChar
+ CurrentChar = (UINT8)LastChar + 1; // just ensure it's different from LastChar
}
+
if (LastChar != CurrentChar) {
if (LastCharCount == 1) {
CompressedIndex++;
if (CompressedCrc != NULL) {
*CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);
}
+
if (Send) {
DebugPortWriteBuffer (Handle, &LastChar, 1);
}
-
} else if (LastCharCount >= 2) {
CompressedIndex += 3;
- LastCharCount -= 2;
+ LastCharCount -= 2;
if (CompressedCrc != NULL) {
*CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);
*CompressedCrc = CalculateCrc16 (&LastChar, 1, *CompressedCrc);
*CompressedCrc = CalculateCrc16 (&LastCharCount, 1, *CompressedCrc);
}
+
if (Send) {
DebugPortWriteBuffer (Handle, &LastChar, 1);
DebugPortWriteBuffer (Handle, &LastChar, 1);
DebugPortWriteBuffer (Handle, &LastCharCount, 1);
}
}
+
LastCharCount = 0;
}
+
LastCharCount++;
LastChar = CurrentChar;
}
@@ -1510,41 +1535,42 @@ CompressData (
**/
RETURN_STATUS
ReadMemoryAndSendResponsePacket (
- IN UINT8 *Data,
- IN UINT16 Count,
- IN UINT8 Width,
- IN DEBUG_PACKET_HEADER *DebugHeader
+ IN UINT8 *Data,
+ IN UINT16 Count,
+ IN UINT8 Width,
+ IN DEBUG_PACKET_HEADER *DebugHeader
)
{
- RETURN_STATUS Status;
- BOOLEAN LastPacket;
- DEBUG_PORT_HANDLE Handle;
- UINT8 SequenceNo;
- UINTN RemainingDataSize;
- UINT8 CurrentDataSize;
- UINTN CompressedDataSize;
+ RETURN_STATUS Status;
+ BOOLEAN LastPacket;
+ DEBUG_PORT_HANDLE Handle;
+ UINT8 SequenceNo;
+ UINTN RemainingDataSize;
+ UINT8 CurrentDataSize;
+ UINTN CompressedDataSize;
- Handle = GetDebugPortHandle();
+ Handle = GetDebugPortHandle ();
RemainingDataSize = Count * Width;
while (TRUE) {
- SequenceNo = GetMailboxPointer()->HostSequenceNo;
+ SequenceNo = GetMailboxPointer ()->HostSequenceNo;
if (RemainingDataSize <= DEBUG_DATA_MAXIMUM_REAL_DATA) {
//
// If the remaining data is less one real packet size, this is the last data packet
//
- CurrentDataSize = (UINT8) RemainingDataSize;
- LastPacket = TRUE;
+ CurrentDataSize = (UINT8)RemainingDataSize;
+ LastPacket = TRUE;
DebugHeader->Command = DEBUG_COMMAND_OK;
} else {
//
// Data is too larger to be sent in one packet, calculate the actual data size could
// be sent in one Maximum data packet
//
- CurrentDataSize = (DEBUG_DATA_MAXIMUM_REAL_DATA / Width) * Width;
- LastPacket = FALSE;
+ CurrentDataSize = (DEBUG_DATA_MAXIMUM_REAL_DATA / Width) * Width;
+ LastPacket = FALSE;
DebugHeader->Command = DEBUG_COMMAND_IN_PROGRESS;
}
+
//
// Construct the rest Debug header
//
@@ -1552,19 +1578,19 @@ ReadMemoryAndSendResponsePacket (
DebugHeader->Length = CurrentDataSize + sizeof (DEBUG_PACKET_HEADER);
DebugHeader->SequenceNo = SequenceNo;
DebugHeader->Crc = 0;
- CopyMemByWidth ((UINT8 *) (DebugHeader + 1), Data, CurrentDataSize / Width, Width);
+ CopyMemByWidth ((UINT8 *)(DebugHeader + 1), Data, CurrentDataSize / Width, Width);
//
// Compression/decompression support was added since revision 0.4.
// Revision 0.3 shouldn't compress the packet.
//
- if (PcdGet32(PcdTransferProtocolRevision) >= DEBUG_AGENT_REVISION_04) {
+ if (PcdGet32 (PcdTransferProtocolRevision) >= DEBUG_AGENT_REVISION_04) {
//
// Get the compressed data size without modifying the packet.
//
CompressData (
Handle,
- (UINT8 *) (DebugHeader + 1),
+ (UINT8 *)(DebugHeader + 1),
CurrentDataSize,
FALSE,
&CompressedDataSize,
@@ -1573,16 +1599,17 @@ ReadMemoryAndSendResponsePacket (
} else {
CompressedDataSize = CurrentDataSize;
}
+
if (CompressedDataSize < CurrentDataSize) {
- DebugHeader->Length = (UINT8) CompressedDataSize + sizeof (DEBUG_PACKET_HEADER);
+ DebugHeader->Length = (UINT8)CompressedDataSize + sizeof (DEBUG_PACKET_HEADER);
DebugHeader->StartSymbol = DEBUG_STARTING_SYMBOL_COMPRESS;
//
// Compute the CRC of the packet head without modifying the packet.
//
- DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, sizeof (DEBUG_PACKET_HEADER), 0);
+ DebugHeader->Crc = CalculateCrc16 ((UINT8 *)DebugHeader, sizeof (DEBUG_PACKET_HEADER), 0);
CompressData (
Handle,
- (UINT8 *) (DebugHeader + 1),
+ (UINT8 *)(DebugHeader + 1),
CurrentDataSize,
FALSE,
NULL,
@@ -1591,51 +1618,53 @@ ReadMemoryAndSendResponsePacket (
//
// Send out the packet head.
//
- DebugPortWriteBuffer (Handle, (UINT8 *) DebugHeader, sizeof (DEBUG_PACKET_HEADER));
+ DebugPortWriteBuffer (Handle, (UINT8 *)DebugHeader, sizeof (DEBUG_PACKET_HEADER));
//
// Compress and send out the packet data.
//
CompressData (
Handle,
- (UINT8 *) (DebugHeader + 1),
+ (UINT8 *)(DebugHeader + 1),
CurrentDataSize,
TRUE,
NULL,
NULL
);
} else {
-
//
// Calculate and fill the checksum, DebugHeader->Crc should be 0 before invoking CalculateCrc16 ()
//
- DebugHeader->Crc = CalculateCrc16 ((UINT8 *) DebugHeader, DebugHeader->Length, 0);
+ DebugHeader->Crc = CalculateCrc16 ((UINT8 *)DebugHeader, DebugHeader->Length, 0);
- DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, TRUE, (UINT8 *) DebugHeader, DebugHeader->Length);
+ DebugAgentDataMsgPrint (DEBUG_AGENT_VERBOSE, TRUE, (UINT8 *)DebugHeader, DebugHeader->Length);
- DebugPortWriteBuffer (Handle, (UINT8 *) DebugHeader, DebugHeader->Length);
+ DebugPortWriteBuffer (Handle, (UINT8 *)DebugHeader, DebugHeader->Length);
}
while (TRUE) {
- Status = ReceivePacket ((UINT8 *) DebugHeader, NULL, NULL, READ_PACKET_TIMEOUT, FALSE);
+ Status = ReceivePacket ((UINT8 *)DebugHeader, NULL, NULL, READ_PACKET_TIMEOUT, FALSE);
if (Status == RETURN_TIMEOUT) {
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Timeout in SendDataResponsePacket()\n");
break;
}
+
if ((DebugHeader->Command == DEBUG_COMMAND_OK) && (DebugHeader->SequenceNo == SequenceNo) && LastPacket) {
//
// If this is the last packet, return RETURN_SUCCESS.
//
return RETURN_SUCCESS;
}
- if ((DebugHeader->Command == DEBUG_COMMAND_CONTINUE) && (DebugHeader->SequenceNo == (UINT8) (SequenceNo + 1))) {
+
+ if ((DebugHeader->Command == DEBUG_COMMAND_CONTINUE) && (DebugHeader->SequenceNo == (UINT8)(SequenceNo + 1))) {
//
// Calculate the rest data size
//
Data += CurrentDataSize;
RemainingDataSize -= CurrentDataSize;
- UpdateMailboxContent (GetMailboxPointer(), DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, DebugHeader->SequenceNo);
+ UpdateMailboxContent (GetMailboxPointer (), DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, DebugHeader->SequenceNo);
break;
}
+
if (DebugHeader->SequenceNo >= SequenceNo) {
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Received one old or new command(SequenceNo is %x, last SequenceNo is %x)\n", SequenceNo, DebugHeader->SequenceNo);
break;
@@ -1657,9 +1686,9 @@ ReadMemoryAndSendResponsePacket (
**/
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
)
{
return ReadMemoryAndSendResponsePacket (Data, DataSize, 1, DebugHeader);
@@ -1682,45 +1711,47 @@ SendDataResponsePacket (
**/
RETURN_STATUS
AttachHost (
- IN UINT8 BreakCause,
- IN UINTN Timeout,
- OUT BOOLEAN *BreakReceived
+ IN UINT8 BreakCause,
+ IN UINTN Timeout,
+ OUT BOOLEAN *BreakReceived
)
{
- RETURN_STATUS Status;
- DEBUG_PORT_HANDLE Handle;
- BOOLEAN IncompatibilityFlag;
+ RETURN_STATUS Status;
+ DEBUG_PORT_HANDLE Handle;
+ BOOLEAN IncompatibilityFlag;
IncompatibilityFlag = FALSE;
- Handle = GetDebugPortHandle();
+ Handle = GetDebugPortHandle ();
//
// Send init break and wait ack in Timeout
//
- DebugPortWriteBuffer (Handle, (UINT8 *) mErrorMsgSendInitPacket, AsciiStrLen (mErrorMsgSendInitPacket));
+ DebugPortWriteBuffer (Handle, (UINT8 *)mErrorMsgSendInitPacket, AsciiStrLen (mErrorMsgSendInitPacket));
if (BreakCause == DEBUG_DATA_BREAK_CAUSE_SYSTEM_RESET) {
Status = SendCommandAndWaitForAckOK (DEBUG_COMMAND_INIT_BREAK, Timeout, BreakReceived, &IncompatibilityFlag);
} else {
Status = SendCommandAndWaitForAckOK (DEBUG_COMMAND_ATTACH_BREAK, Timeout, BreakReceived, &IncompatibilityFlag);
}
+
if (IncompatibilityFlag) {
//
// If the incompatible Debug Packet received, the HOST should be running transfer protocol before PcdTransferProtocolRevision.
// It could be UDK Debugger for Windows v1.1/v1.2 or for Linux v0.8/v1.2.
//
- DebugPortWriteBuffer (Handle, (UINT8 *) mErrorMsgVersionAlert, AsciiStrLen (mErrorMsgVersionAlert));
+ DebugPortWriteBuffer (Handle, (UINT8 *)mErrorMsgVersionAlert, AsciiStrLen (mErrorMsgVersionAlert));
CpuDeadLoop ();
}
if (RETURN_ERROR (Status)) {
- DebugPortWriteBuffer (Handle, (UINT8 *) mErrorMsgConnectFail, AsciiStrLen (mErrorMsgConnectFail));
+ DebugPortWriteBuffer (Handle, (UINT8 *)mErrorMsgConnectFail, AsciiStrLen (mErrorMsgConnectFail));
} else {
- DebugPortWriteBuffer (Handle, (UINT8 *) mErrorMsgConnectOK, AsciiStrLen (mErrorMsgConnectOK));
+ DebugPortWriteBuffer (Handle, (UINT8 *)mErrorMsgConnectOK, AsciiStrLen (mErrorMsgConnectOK));
//
// Set Attach flag
//
SetHostAttached (TRUE);
}
+
return Status;
}
@@ -1738,15 +1769,15 @@ AttachHost (
**/
VOID
SendBreakPacketToHost (
- IN UINT8 BreakCause,
- IN UINT32 ProcessorIndex,
- OUT BOOLEAN *BreakReceived
+ IN UINT8 BreakCause,
+ IN UINT32 ProcessorIndex,
+ OUT BOOLEAN *BreakReceived
)
{
- UINT8 InputCharacter;
- DEBUG_PORT_HANDLE Handle;
+ UINT8 InputCharacter;
+ DEBUG_PORT_HANDLE Handle;
- Handle = GetDebugPortHandle();
+ Handle = GetDebugPortHandle ();
if (IsHostAttached ()) {
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "processor[%x]:Send Break Packet to HOST.\n", ProcessorIndex);
@@ -1762,13 +1793,14 @@ SendBreakPacketToHost (
do {
DebugAgentReadBuffer (Handle, &InputCharacter, 1, 0);
} while (InputCharacter != DEBUG_STARTING_SYMBOL_ATTACH);
+
SendAckPacket (DEBUG_COMMAND_OK);
//
// Try to attach HOST
//
- while (AttachHost (BreakCause, 0, NULL) != RETURN_SUCCESS);
-
+ while (AttachHost (BreakCause, 0, NULL) != RETURN_SUCCESS) {
+ }
}
}
@@ -1785,46 +1817,46 @@ SendBreakPacketToHost (
**/
VOID
CommandCommunication (
- IN UINTN Vector,
- IN OUT DEBUG_CPU_CONTEXT *CpuContext,
- IN BOOLEAN BreakReceived
+ IN UINTN Vector,
+ IN OUT DEBUG_CPU_CONTEXT *CpuContext,
+ IN BOOLEAN BreakReceived
)
{
- RETURN_STATUS Status;
- UINT8 InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT + sizeof (UINT64) - 1];
- DEBUG_PACKET_HEADER *DebugHeader;
- UINT8 Width;
- UINT8 Data8;
- UINT32 Data32;
- UINT64 Data64;
- DEBUG_DATA_READ_MEMORY *MemoryRead;
- DEBUG_DATA_WRITE_MEMORY *MemoryWrite;
- DEBUG_DATA_READ_IO *IoRead;
- DEBUG_DATA_WRITE_IO *IoWrite;
- DEBUG_DATA_READ_REGISTER *RegisterRead;
- DEBUG_DATA_WRITE_REGISTER *RegisterWrite;
- UINT8 *RegisterBuffer;
- DEBUG_DATA_READ_MSR *MsrRegisterRead;
- DEBUG_DATA_WRITE_MSR *MsrRegisterWrite;
- DEBUG_DATA_CPUID *Cpuid;
- DEBUG_DATA_RESPONSE_BREAK_CAUSE BreakCause;
- DEBUG_DATA_RESPONSE_CPUID CpuidResponse;
- DEBUG_DATA_SEARCH_SIGNATURE *SearchSignature;
- DEBUG_DATA_RESPONSE_GET_EXCEPTION Exception;
- DEBUG_DATA_RESPONSE_GET_REVISION DebugAgentRevision;
- DEBUG_DATA_SET_VIEWPOINT *SetViewPoint;
- BOOLEAN HaltDeferred;
- UINT32 ProcessorIndex;
- DEBUG_AGENT_EXCEPTION_BUFFER AgentExceptionBuffer;
- UINT32 IssuedViewPoint;
- DEBUG_AGENT_MAILBOX *Mailbox;
- UINT8 *AlignedDataPtr;
+ RETURN_STATUS Status;
+ UINT8 InputPacketBuffer[DEBUG_DATA_UPPER_LIMIT + sizeof (UINT64) - 1];
+ DEBUG_PACKET_HEADER *DebugHeader;
+ UINT8 Width;
+ UINT8 Data8;
+ UINT32 Data32;
+ UINT64 Data64;
+ DEBUG_DATA_READ_MEMORY *MemoryRead;
+ DEBUG_DATA_WRITE_MEMORY *MemoryWrite;
+ DEBUG_DATA_READ_IO *IoRead;
+ DEBUG_DATA_WRITE_IO *IoWrite;
+ DEBUG_DATA_READ_REGISTER *RegisterRead;
+ DEBUG_DATA_WRITE_REGISTER *RegisterWrite;
+ UINT8 *RegisterBuffer;
+ DEBUG_DATA_READ_MSR *MsrRegisterRead;
+ DEBUG_DATA_WRITE_MSR *MsrRegisterWrite;
+ DEBUG_DATA_CPUID *Cpuid;
+ DEBUG_DATA_RESPONSE_BREAK_CAUSE BreakCause;
+ DEBUG_DATA_RESPONSE_CPUID CpuidResponse;
+ DEBUG_DATA_SEARCH_SIGNATURE *SearchSignature;
+ DEBUG_DATA_RESPONSE_GET_EXCEPTION Exception;
+ DEBUG_DATA_RESPONSE_GET_REVISION DebugAgentRevision;
+ DEBUG_DATA_SET_VIEWPOINT *SetViewPoint;
+ BOOLEAN HaltDeferred;
+ UINT32 ProcessorIndex;
+ DEBUG_AGENT_EXCEPTION_BUFFER AgentExceptionBuffer;
+ UINT32 IssuedViewPoint;
+ DEBUG_AGENT_MAILBOX *Mailbox;
+ UINT8 *AlignedDataPtr;
ProcessorIndex = 0;
IssuedViewPoint = 0;
HaltDeferred = BreakReceived;
- if (MultiProcessorDebugSupport()) {
+ if (MultiProcessorDebugSupport ()) {
ProcessorIndex = GetProcessorIndex ();
SetCpuStopFlagByIndex (ProcessorIndex, TRUE);
if (mDebugMpContext.ViewPointIndex == ProcessorIndex) {
@@ -1843,8 +1875,7 @@ CommandCommunication (
}
while (TRUE) {
-
- if (MultiProcessorDebugSupport()) {
+ if (MultiProcessorDebugSupport ()) {
//
// Check if the current processor is HOST view point
//
@@ -1868,11 +1899,11 @@ CommandCommunication (
AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- DebugHeader =(DEBUG_PACKET_HEADER *) InputPacketBuffer;
+ DebugHeader = (DEBUG_PACKET_HEADER *)InputPacketBuffer;
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "TARGET: Try to get command from HOST...\n");
- Status = ReceivePacket ((UINT8 *) DebugHeader, &BreakReceived, NULL, READ_PACKET_TIMEOUT, TRUE);
- if (Status != RETURN_SUCCESS || !IS_REQUEST (DebugHeader)) {
+ Status = ReceivePacket ((UINT8 *)DebugHeader, &BreakReceived, NULL, READ_PACKET_TIMEOUT, TRUE);
+ if ((Status != RETURN_SUCCESS) || !IS_REQUEST (DebugHeader)) {
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Get command[%x] sequenceno[%x] returned status is [%x] \n", DebugHeader->Command, DebugHeader->SequenceNo, Status);
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "TARGET: Get command failed or it's response packet not expected! \n");
ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
@@ -1885,8 +1916,8 @@ CommandCommunication (
SendAckPacket (Mailbox->LastAck);
ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
continue;
- } else if (DebugHeader->SequenceNo == (UINT8) (Mailbox->HostSequenceNo + 1)) {
- UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, (UINT8) DebugHeader->SequenceNo);
+ } else if (DebugHeader->SequenceNo == (UINT8)(Mailbox->HostSequenceNo + 1)) {
+ UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, (UINT8)DebugHeader->SequenceNo);
} else {
DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "Receive one invalid command[%x] against command[%x]\n", DebugHeader->SequenceNo, Mailbox->HostSequenceNo);
ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
@@ -1896,7 +1927,7 @@ CommandCommunication (
//
// Save CPU content before executing HOST command
//
- UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX, (UINT64)(UINTN) &AgentExceptionBuffer.JumpBuffer);
+ UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_EXCEPTION_BUFFER_POINTER_INDEX, (UINT64)(UINTN)&AgentExceptionBuffer.JumpBuffer);
if (SetJump (&AgentExceptionBuffer.JumpBuffer) != 0) {
//
// If HOST command failed, continue to wait for HOST's next command
@@ -1910,380 +1941,397 @@ CommandCommunication (
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Processor[%x]:Received one command(%x)\n", mDebugMpContext.ViewPointIndex, DebugHeader->Command);
switch (DebugHeader->Command) {
+ case DEBUG_COMMAND_HALT:
+ SendAckPacket (DEBUG_COMMAND_HALT_DEFERRED);
+ HaltDeferred = TRUE;
+ BreakReceived = FALSE;
+ Status = RETURN_SUCCESS;
+ break;
- case DEBUG_COMMAND_HALT:
- SendAckPacket (DEBUG_COMMAND_HALT_DEFERRED);
- HaltDeferred = TRUE;
- BreakReceived = FALSE;
- Status = RETURN_SUCCESS;
- break;
-
- case DEBUG_COMMAND_RESET:
- SendAckPacket (DEBUG_COMMAND_OK);
- SendAckPacket (DEBUG_COMMAND_OK);
- SendAckPacket (DEBUG_COMMAND_OK);
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
-
- ResetCold ();
- //
- // Assume system resets in 2 seconds, otherwise send TIMEOUT packet.
- // PCD can be used if 2 seconds isn't long enough for some platforms.
- //
- MicroSecondDelay (2000000);
- UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, Mailbox->HostSequenceNo + 1);
- SendAckPacket (DEBUG_COMMAND_TIMEOUT);
- SendAckPacket (DEBUG_COMMAND_TIMEOUT);
- SendAckPacket (DEBUG_COMMAND_TIMEOUT);
- break;
+ case DEBUG_COMMAND_RESET:
+ SendAckPacket (DEBUG_COMMAND_OK);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- case DEBUG_COMMAND_GO:
- CommandGo (CpuContext);
- //
- // Clear Dr0 to avoid to be recognized as IMAGE_LOAD/_UNLOAD again when hitting a breakpoint after GO
- // If HOST changed Dr0 before GO, we will not change Dr0 here
- //
- Data8 = GetBreakCause (Vector, CpuContext);
- if (Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD || Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD) {
- CpuContext->Dr0 = 0;
- }
+ ResetCold ();
+ //
+ // Assume system resets in 2 seconds, otherwise send TIMEOUT packet.
+ // PCD can be used if 2 seconds isn't long enough for some platforms.
+ //
+ MicroSecondDelay (2000000);
+ UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, Mailbox->HostSequenceNo + 1);
+ SendAckPacket (DEBUG_COMMAND_TIMEOUT);
+ SendAckPacket (DEBUG_COMMAND_TIMEOUT);
+ SendAckPacket (DEBUG_COMMAND_TIMEOUT);
+ break;
- if (!HaltDeferred) {
+ case DEBUG_COMMAND_GO:
+ CommandGo (CpuContext);
//
- // If no HALT command received when being in-active mode
+ // Clear Dr0 to avoid to be recognized as IMAGE_LOAD/_UNLOAD again when hitting a breakpoint after GO
+ // If HOST changed Dr0 before GO, we will not change Dr0 here
//
- if (MultiProcessorDebugSupport()) {
- Data32 = FindNextPendingBreakCpu ();
- if (Data32 != -1) {
+ Data8 = GetBreakCause (Vector, CpuContext);
+ if ((Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD) || (Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD)) {
+ CpuContext->Dr0 = 0;
+ }
+
+ if (!HaltDeferred) {
+ //
+ // If no HALT command received when being in-active mode
+ //
+ if (MultiProcessorDebugSupport ()) {
+ Data32 = FindNextPendingBreakCpu ();
+ if (Data32 != -1) {
+ //
+ // If there are still others processors being in break state,
+ // send OK packet to HOST to finish this go command
+ //
+ SendAckPacket (DEBUG_COMMAND_OK);
+ CpuPause ();
+ //
+ // Set current view to the next breaking processor
+ //
+ mDebugMpContext.ViewPointIndex = Data32;
+ mDebugMpContext.BreakAtCpuIndex = mDebugMpContext.ViewPointIndex;
+ SetCpuBreakFlagByIndex (mDebugMpContext.ViewPointIndex, FALSE);
+ //
+ // Send break packet to HOST to let HOST break again
+ //
+ SendBreakPacketToHost (DEBUG_DATA_BREAK_CAUSE_UNKNOWN, mDebugMpContext.BreakAtCpuIndex, &BreakReceived);
+ //
+ // Continue to run into loop to read command packet from HOST
+ //
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ break;
+ }
+
//
- // If there are still others processors being in break state,
- // send OK packet to HOST to finish this go command
+ // If no else processor break, set stop bitmask,
+ // and set Running flag for all processors.
//
- SendAckPacket (DEBUG_COMMAND_OK);
+ SetCpuStopFlagByIndex (ProcessorIndex, FALSE);
+ SetCpuRunningFlag (TRUE);
CpuPause ();
//
- // Set current view to the next breaking processor
+ // Wait for all processors are in running state
//
- mDebugMpContext.ViewPointIndex = Data32;
- mDebugMpContext.BreakAtCpuIndex = mDebugMpContext.ViewPointIndex;
- SetCpuBreakFlagByIndex (mDebugMpContext.ViewPointIndex, FALSE);
+ while (TRUE) {
+ if (IsAllCpuRunning ()) {
+ break;
+ }
+ }
+
//
- // Send break packet to HOST to let HOST break again
+ // Set BSP to be current view point.
//
- SendBreakPacketToHost (DEBUG_DATA_BREAK_CAUSE_UNKNOWN, mDebugMpContext.BreakAtCpuIndex, &BreakReceived);
+ SetDebugViewPoint (mDebugMpContext.BspIndex);
+ CpuPause ();
//
- // Continue to run into loop to read command packet from HOST
+ // Clear breaking processor index and running flag
//
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- break;
+ mDebugMpContext.BreakAtCpuIndex = (UINT32)(-1);
+ SetCpuRunningFlag (FALSE);
}
//
- // If no else processor break, set stop bitmask,
- // and set Running flag for all processors.
- //
- SetCpuStopFlagByIndex (ProcessorIndex, FALSE);
- SetCpuRunningFlag (TRUE);
- CpuPause ();
- //
- // Wait for all processors are in running state
+ // Send OK packet to HOST to finish this go command
//
- while (TRUE) {
- if (IsAllCpuRunning ()) {
- break;
- }
+ SendAckPacket (DEBUG_COMMAND_OK);
+
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+
+ if (!IsHostAttached ()) {
+ UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_SEQUENCE_NO_INDEX, 0);
+ UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, 0);
}
+
+ return;
+ } else {
//
- // Set BSP to be current view point.
- //
- SetDebugViewPoint (mDebugMpContext.BspIndex);
- CpuPause ();
- //
- // Clear breaking processor index and running flag
+ // If received HALT command, need to defer the GO command
//
- mDebugMpContext.BreakAtCpuIndex = (UINT32) (-1);
- SetCpuRunningFlag (FALSE);
+ SendAckPacket (DEBUG_COMMAND_HALT_PROCESSED);
+ HaltDeferred = FALSE;
+
+ Vector = DEBUG_TIMER_VECTOR;
}
- //
- // Send OK packet to HOST to finish this go command
- //
+ break;
+
+ case DEBUG_COMMAND_BREAK_CAUSE:
+ BreakCause.StopAddress = CpuContext->Eip;
+ if (MultiProcessorDebugSupport () && (ProcessorIndex != mDebugMpContext.BreakAtCpuIndex)) {
+ BreakCause.Cause = GetBreakCause (DEBUG_TIMER_VECTOR, CpuContext);
+ } else {
+ BreakCause.Cause = GetBreakCause (Vector, CpuContext);
+ }
+
+ SendDataResponsePacket ((UINT8 *)&BreakCause, (UINT16)sizeof (DEBUG_DATA_RESPONSE_BREAK_CAUSE), DebugHeader);
+ break;
+
+ case DEBUG_COMMAND_SET_HW_BREAKPOINT:
+ SetDebugRegister (CpuContext, (DEBUG_DATA_SET_HW_BREAKPOINT *)(DebugHeader + 1));
SendAckPacket (DEBUG_COMMAND_OK);
+ break;
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ case DEBUG_COMMAND_CLEAR_HW_BREAKPOINT:
+ ClearDebugRegister (CpuContext, (DEBUG_DATA_CLEAR_HW_BREAKPOINT *)(DebugHeader + 1));
+ SendAckPacket (DEBUG_COMMAND_OK);
+ break;
- if (!IsHostAttached()) {
- UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_SEQUENCE_NO_INDEX, 0);
- UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX, 0);
+ case DEBUG_COMMAND_SINGLE_STEPPING:
+ CommandStepping (CpuContext);
+ //
+ // Clear Dr0 to avoid to be recognized as IMAGE_LOAD/_UNLOAD again when hitting a breakpoint after GO
+ // If HOST changed Dr0 before GO, we will not change Dr0 here
+ //
+ Data8 = GetBreakCause (Vector, CpuContext);
+ if ((Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD) || (Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD)) {
+ CpuContext->Dr0 = 0;
}
- return;
- } else {
+ mDebugMpContext.BreakAtCpuIndex = (UINT32)(-1);
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
//
- // If received HALT command, need to defer the GO command
+ // Executing stepping command directly without sending ACK packet,
+ // ACK packet will be sent after stepping done.
//
- SendAckPacket (DEBUG_COMMAND_HALT_PROCESSED);
- HaltDeferred = FALSE;
-
- Vector = DEBUG_TIMER_VECTOR;
- }
- break;
-
- case DEBUG_COMMAND_BREAK_CAUSE:
- BreakCause.StopAddress = CpuContext->Eip;
- if (MultiProcessorDebugSupport() && ProcessorIndex != mDebugMpContext.BreakAtCpuIndex) {
- BreakCause.Cause = GetBreakCause (DEBUG_TIMER_VECTOR, CpuContext);
- } else {
- BreakCause.Cause = GetBreakCause (Vector, CpuContext);
- }
- SendDataResponsePacket ((UINT8 *) &BreakCause, (UINT16) sizeof (DEBUG_DATA_RESPONSE_BREAK_CAUSE), DebugHeader);
- break;
+ return;
- case DEBUG_COMMAND_SET_HW_BREAKPOINT:
- SetDebugRegister (CpuContext, (DEBUG_DATA_SET_HW_BREAKPOINT *) (DebugHeader + 1));
- SendAckPacket (DEBUG_COMMAND_OK);
- break;
+ case DEBUG_COMMAND_SET_SW_BREAKPOINT:
+ Data64 = (UINTN)(((DEBUG_DATA_SET_SW_BREAKPOINT *)(DebugHeader + 1))->Address);
+ Data8 = *(UINT8 *)(UINTN)Data64;
+ *(UINT8 *)(UINTN)Data64 = DEBUG_SW_BREAKPOINT_SYMBOL;
+ Status = SendDataResponsePacket ((UINT8 *)&Data8, (UINT16)sizeof (UINT8), DebugHeader);
+ break;
- case DEBUG_COMMAND_CLEAR_HW_BREAKPOINT:
- ClearDebugRegister (CpuContext, (DEBUG_DATA_CLEAR_HW_BREAKPOINT *) (DebugHeader + 1));
- SendAckPacket (DEBUG_COMMAND_OK);
- break;
+ case DEBUG_COMMAND_READ_MEMORY:
+ MemoryRead = (DEBUG_DATA_READ_MEMORY *)(DebugHeader + 1);
+ Status = ReadMemoryAndSendResponsePacket ((UINT8 *)(UINTN)MemoryRead->Address, MemoryRead->Count, MemoryRead->Width, DebugHeader);
+ break;
- case DEBUG_COMMAND_SINGLE_STEPPING:
- CommandStepping (CpuContext);
- //
- // Clear Dr0 to avoid to be recognized as IMAGE_LOAD/_UNLOAD again when hitting a breakpoint after GO
- // If HOST changed Dr0 before GO, we will not change Dr0 here
- //
- Data8 = GetBreakCause (Vector, CpuContext);
- if (Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD || Data8 == DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD) {
- CpuContext->Dr0 = 0;
- }
+ case DEBUG_COMMAND_WRITE_MEMORY:
+ MemoryWrite = (DEBUG_DATA_WRITE_MEMORY *)(DebugHeader + 1);
+ //
+ // Copy data into one memory with 8-byte alignment address
+ //
+ AlignedDataPtr = ALIGN_POINTER ((UINT8 *)&MemoryWrite->Data, sizeof (UINT64));
+ if (AlignedDataPtr != (UINT8 *)&MemoryWrite->Data) {
+ CopyMem (AlignedDataPtr, (UINT8 *)&MemoryWrite->Data, MemoryWrite->Count * MemoryWrite->Width);
+ }
- mDebugMpContext.BreakAtCpuIndex = (UINT32) (-1);
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- //
- // Executing stepping command directly without sending ACK packet,
- // ACK packet will be sent after stepping done.
- //
- return;
+ CopyMemByWidth ((UINT8 *)(UINTN)MemoryWrite->Address, AlignedDataPtr, MemoryWrite->Count, MemoryWrite->Width);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ break;
- case DEBUG_COMMAND_SET_SW_BREAKPOINT:
- Data64 = (UINTN) (((DEBUG_DATA_SET_SW_BREAKPOINT *) (DebugHeader + 1))->Address);
- Data8 = *(UINT8 *) (UINTN) Data64;
- *(UINT8 *) (UINTN) Data64 = DEBUG_SW_BREAKPOINT_SYMBOL;
- Status = SendDataResponsePacket ((UINT8 *) &Data8, (UINT16) sizeof (UINT8), DebugHeader);
- break;
+ case DEBUG_COMMAND_READ_IO:
+ IoRead = (DEBUG_DATA_READ_IO *)(DebugHeader + 1);
+ switch (IoRead->Width) {
+ case 1:
+ Data64 = IoRead8 ((UINTN)IoRead->Port);
+ break;
+ case 2:
+ Data64 = IoRead16 ((UINTN)IoRead->Port);
+ break;
+ case 4:
+ Data64 = IoRead32 ((UINTN)IoRead->Port);
+ break;
+ case 8:
+ Data64 = IoRead64 ((UINTN)IoRead->Port);
+ break;
+ default:
+ Data64 = (UINT64)-1;
+ }
- case DEBUG_COMMAND_READ_MEMORY:
- MemoryRead = (DEBUG_DATA_READ_MEMORY *) (DebugHeader + 1);
- Status = ReadMemoryAndSendResponsePacket ((UINT8 *) (UINTN) MemoryRead->Address, MemoryRead->Count, MemoryRead->Width, DebugHeader);
- break;
+ Status = SendDataResponsePacket ((UINT8 *)&Data64, IoRead->Width, DebugHeader);
+ break;
- case DEBUG_COMMAND_WRITE_MEMORY:
- MemoryWrite = (DEBUG_DATA_WRITE_MEMORY *) (DebugHeader + 1);
- //
- // Copy data into one memory with 8-byte alignment address
- //
- AlignedDataPtr = ALIGN_POINTER ((UINT8 *) &MemoryWrite->Data, sizeof (UINT64));
- if (AlignedDataPtr != (UINT8 *) &MemoryWrite->Data) {
- CopyMem (AlignedDataPtr, (UINT8 *) &MemoryWrite->Data, MemoryWrite->Count * MemoryWrite->Width);
- }
- CopyMemByWidth ((UINT8 *) (UINTN) MemoryWrite->Address, AlignedDataPtr, MemoryWrite->Count, MemoryWrite->Width);
- SendAckPacket (DEBUG_COMMAND_OK);
- break;
+ case DEBUG_COMMAND_WRITE_IO:
+ IoWrite = (DEBUG_DATA_WRITE_IO *)(DebugHeader + 1);
+ switch (IoWrite->Width) {
+ case 1:
+ Data64 = IoWrite8 ((UINTN)IoWrite->Port, *(UINT8 *)&IoWrite->Data);
+ break;
+ case 2:
+ Data64 = IoWrite16 ((UINTN)IoWrite->Port, *(UINT16 *)&IoWrite->Data);
+ break;
+ case 4:
+ Data64 = IoWrite32 ((UINTN)IoWrite->Port, *(UINT32 *)&IoWrite->Data);
+ break;
+ case 8:
+ Data64 = IoWrite64 ((UINTN)IoWrite->Port, *(UINT64 *)&IoWrite->Data);
+ break;
+ default:
+ Data64 = (UINT64)-1;
+ }
- case DEBUG_COMMAND_READ_IO:
- IoRead = (DEBUG_DATA_READ_IO *) (DebugHeader + 1);
- switch (IoRead->Width) {
- case 1:
- Data64 = IoRead8 ((UINTN) IoRead->Port);
- break;
- case 2:
- Data64 = IoRead16 ((UINTN) IoRead->Port);
- break;
- case 4:
- Data64 = IoRead32 ((UINTN) IoRead->Port);
- break;
- case 8:
- Data64 = IoRead64 ((UINTN) IoRead->Port);
+ SendAckPacket (DEBUG_COMMAND_OK);
break;
- default:
- Data64 = (UINT64) -1;
- }
- Status = SendDataResponsePacket ((UINT8 *) &Data64, IoRead->Width, DebugHeader);
- break;
- case DEBUG_COMMAND_WRITE_IO:
- IoWrite = (DEBUG_DATA_WRITE_IO *) (DebugHeader + 1);
- switch (IoWrite->Width) {
- case 1:
- Data64 = IoWrite8 ((UINTN) IoWrite->Port, *(UINT8 *) &IoWrite->Data);
- break;
- case 2:
- Data64 = IoWrite16 ((UINTN) IoWrite->Port, *(UINT16 *) &IoWrite->Data);
- break;
- case 4:
- Data64 = IoWrite32 ((UINTN) IoWrite->Port, *(UINT32 *) &IoWrite->Data);
- break;
- case 8:
- Data64 = IoWrite64 ((UINTN) IoWrite->Port, *(UINT64 *) &IoWrite->Data);
+ case DEBUG_COMMAND_READ_ALL_REGISTERS:
+ Status = SendDataResponsePacket ((UINT8 *)CpuContext, sizeof (*CpuContext), DebugHeader);
break;
- default:
- Data64 = (UINT64) -1;
- }
- SendAckPacket (DEBUG_COMMAND_OK);
- break;
- case DEBUG_COMMAND_READ_ALL_REGISTERS:
- Status = SendDataResponsePacket ((UINT8 *) CpuContext, sizeof (*CpuContext), DebugHeader);
- break;
+ case DEBUG_COMMAND_READ_REGISTER:
+ RegisterRead = (DEBUG_DATA_READ_REGISTER *)(DebugHeader + 1);
- case DEBUG_COMMAND_READ_REGISTER:
- RegisterRead = (DEBUG_DATA_READ_REGISTER *) (DebugHeader + 1);
+ if (RegisterRead->Index <= SOFT_DEBUGGER_REGISTER_MAX) {
+ RegisterBuffer = ArchReadRegisterBuffer (CpuContext, RegisterRead->Index, &Width);
+ Status = SendDataResponsePacket (RegisterBuffer, Width, DebugHeader);
+ } else {
+ Status = RETURN_UNSUPPORTED;
+ }
- if (RegisterRead->Index <= SOFT_DEBUGGER_REGISTER_MAX) {
- RegisterBuffer = ArchReadRegisterBuffer (CpuContext, RegisterRead->Index, &Width);
- Status = SendDataResponsePacket (RegisterBuffer, Width, DebugHeader);
- } else {
- Status = RETURN_UNSUPPORTED;
- }
- break;
+ break;
- case DEBUG_COMMAND_WRITE_REGISTER:
- RegisterWrite = (DEBUG_DATA_WRITE_REGISTER *) (DebugHeader + 1);
- if (RegisterWrite->Index <= SOFT_DEBUGGER_REGISTER_MAX) {
- RegisterBuffer = ArchReadRegisterBuffer (CpuContext, RegisterWrite->Index, &Width);
- ASSERT (Width == RegisterWrite->Length);
- CopyMem (RegisterBuffer, RegisterWrite->Data, Width);
- SendAckPacket (DEBUG_COMMAND_OK);
- } else {
- Status = RETURN_UNSUPPORTED;
- }
- break;
+ case DEBUG_COMMAND_WRITE_REGISTER:
+ RegisterWrite = (DEBUG_DATA_WRITE_REGISTER *)(DebugHeader + 1);
+ if (RegisterWrite->Index <= SOFT_DEBUGGER_REGISTER_MAX) {
+ RegisterBuffer = ArchReadRegisterBuffer (CpuContext, RegisterWrite->Index, &Width);
+ ASSERT (Width == RegisterWrite->Length);
+ CopyMem (RegisterBuffer, RegisterWrite->Data, Width);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ } else {
+ Status = RETURN_UNSUPPORTED;
+ }
- case DEBUG_COMMAND_ARCH_MODE:
- Data8 = DEBUG_ARCH_SYMBOL;
- Status = SendDataResponsePacket ((UINT8 *) &Data8, (UINT16) sizeof (UINT8), DebugHeader);
- break;
+ break;
- case DEBUG_COMMAND_READ_MSR:
- MsrRegisterRead = (DEBUG_DATA_READ_MSR *) (DebugHeader + 1);
- Data64 = AsmReadMsr64 (MsrRegisterRead->Index);
- Status = SendDataResponsePacket ((UINT8 *) &Data64, (UINT16) sizeof (UINT64), DebugHeader);
- break;
+ case DEBUG_COMMAND_ARCH_MODE:
+ Data8 = DEBUG_ARCH_SYMBOL;
+ Status = SendDataResponsePacket ((UINT8 *)&Data8, (UINT16)sizeof (UINT8), DebugHeader);
+ break;
- case DEBUG_COMMAND_WRITE_MSR:
- MsrRegisterWrite = (DEBUG_DATA_WRITE_MSR *) (DebugHeader + 1);
- AsmWriteMsr64 (MsrRegisterWrite->Index, MsrRegisterWrite->Value);
- SendAckPacket (DEBUG_COMMAND_OK);
- break;
+ case DEBUG_COMMAND_READ_MSR:
+ MsrRegisterRead = (DEBUG_DATA_READ_MSR *)(DebugHeader + 1);
+ Data64 = AsmReadMsr64 (MsrRegisterRead->Index);
+ Status = SendDataResponsePacket ((UINT8 *)&Data64, (UINT16)sizeof (UINT64), DebugHeader);
+ break;
- case DEBUG_COMMAND_SET_DEBUG_SETTING:
- Status = SetDebugSetting ((DEBUG_DATA_SET_DEBUG_SETTING *)(DebugHeader + 1));
- if (Status == RETURN_SUCCESS) {
+ case DEBUG_COMMAND_WRITE_MSR:
+ MsrRegisterWrite = (DEBUG_DATA_WRITE_MSR *)(DebugHeader + 1);
+ AsmWriteMsr64 (MsrRegisterWrite->Index, MsrRegisterWrite->Value);
SendAckPacket (DEBUG_COMMAND_OK);
- }
- break;
+ break;
- case DEBUG_COMMAND_GET_REVISION:
- DebugAgentRevision.Revision = PcdGet32(PcdTransferProtocolRevision);
- DebugAgentRevision.Capabilities = DEBUG_AGENT_CAPABILITIES;
- Status = SendDataResponsePacket ((UINT8 *) &DebugAgentRevision, (UINT16) sizeof (DEBUG_DATA_RESPONSE_GET_REVISION), DebugHeader);
- break;
+ case DEBUG_COMMAND_SET_DEBUG_SETTING:
+ Status = SetDebugSetting ((DEBUG_DATA_SET_DEBUG_SETTING *)(DebugHeader + 1));
+ if (Status == RETURN_SUCCESS) {
+ SendAckPacket (DEBUG_COMMAND_OK);
+ }
- case DEBUG_COMMAND_GET_EXCEPTION:
- Exception.ExceptionNum = (UINT8) Vector;
- Exception.ExceptionData = (UINT32) CpuContext->ExceptionData;
- Status = SendDataResponsePacket ((UINT8 *) &Exception, (UINT16) sizeof (DEBUG_DATA_RESPONSE_GET_EXCEPTION), DebugHeader);
- break;
+ break;
- case DEBUG_COMMAND_SET_VIEWPOINT:
- SetViewPoint = (DEBUG_DATA_SET_VIEWPOINT *) (DebugHeader + 1);
- if (MultiProcessorDebugSupport()) {
- if (IsCpuStopped (SetViewPoint->ViewPoint)) {
- SetDebugViewPoint (SetViewPoint->ViewPoint);
+ case DEBUG_COMMAND_GET_REVISION:
+ DebugAgentRevision.Revision = PcdGet32 (PcdTransferProtocolRevision);
+ DebugAgentRevision.Capabilities = DEBUG_AGENT_CAPABILITIES;
+ Status = SendDataResponsePacket ((UINT8 *)&DebugAgentRevision, (UINT16)sizeof (DEBUG_DATA_RESPONSE_GET_REVISION), DebugHeader);
+ break;
+
+ case DEBUG_COMMAND_GET_EXCEPTION:
+ Exception.ExceptionNum = (UINT8)Vector;
+ Exception.ExceptionData = (UINT32)CpuContext->ExceptionData;
+ Status = SendDataResponsePacket ((UINT8 *)&Exception, (UINT16)sizeof (DEBUG_DATA_RESPONSE_GET_EXCEPTION), DebugHeader);
+ break;
+
+ case DEBUG_COMMAND_SET_VIEWPOINT:
+ SetViewPoint = (DEBUG_DATA_SET_VIEWPOINT *)(DebugHeader + 1);
+ if (MultiProcessorDebugSupport ()) {
+ if (IsCpuStopped (SetViewPoint->ViewPoint)) {
+ SetDebugViewPoint (SetViewPoint->ViewPoint);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ } else {
+ //
+ // If CPU is not halted
+ //
+ SendAckPacket (DEBUG_COMMAND_NOT_SUPPORTED);
+ }
+ } else if (SetViewPoint->ViewPoint == 0) {
SendAckPacket (DEBUG_COMMAND_OK);
} else {
- //
- // If CPU is not halted
- //
SendAckPacket (DEBUG_COMMAND_NOT_SUPPORTED);
}
- } else if (SetViewPoint->ViewPoint == 0) {
- SendAckPacket (DEBUG_COMMAND_OK);
- } else {
- SendAckPacket (DEBUG_COMMAND_NOT_SUPPORTED);
- }
+ break;
- break;
+ case DEBUG_COMMAND_GET_VIEWPOINT:
+ Data32 = mDebugMpContext.ViewPointIndex;
+ SendDataResponsePacket ((UINT8 *)&Data32, (UINT16)sizeof (UINT32), DebugHeader);
+ break;
- case DEBUG_COMMAND_GET_VIEWPOINT:
- Data32 = mDebugMpContext.ViewPointIndex;
- SendDataResponsePacket((UINT8 *) &Data32, (UINT16) sizeof (UINT32), DebugHeader);
- break;
+ case DEBUG_COMMAND_MEMORY_READY:
+ Data8 = (UINT8)GetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY);
+ SendDataResponsePacket (&Data8, (UINT16)sizeof (UINT8), DebugHeader);
+ break;
- case DEBUG_COMMAND_MEMORY_READY:
- Data8 = (UINT8) GetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY);
- SendDataResponsePacket (&Data8, (UINT16) sizeof (UINT8), DebugHeader);
- break;
+ case DEBUG_COMMAND_DETACH:
+ SetHostAttached (FALSE);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ break;
- case DEBUG_COMMAND_DETACH:
- SetHostAttached (FALSE);
- SendAckPacket (DEBUG_COMMAND_OK);
- break;
+ case DEBUG_COMMAND_CPUID:
+ Cpuid = (DEBUG_DATA_CPUID *)(DebugHeader + 1);
+ AsmCpuidEx (
+ Cpuid->Eax,
+ Cpuid->Ecx,
+ &CpuidResponse.Eax,
+ &CpuidResponse.Ebx,
+ &CpuidResponse.Ecx,
+ &CpuidResponse.Edx
+ );
+ SendDataResponsePacket ((UINT8 *)&CpuidResponse, (UINT16)sizeof (CpuidResponse), DebugHeader);
+ break;
- case DEBUG_COMMAND_CPUID:
- Cpuid = (DEBUG_DATA_CPUID *) (DebugHeader + 1);
- AsmCpuidEx (
- Cpuid->Eax, Cpuid->Ecx,
- &CpuidResponse.Eax, &CpuidResponse.Ebx,
- &CpuidResponse.Ecx, &CpuidResponse.Edx
- );
- SendDataResponsePacket ((UINT8 *) &CpuidResponse, (UINT16) sizeof (CpuidResponse), DebugHeader);
- break;
+ case DEBUG_COMMAND_SEARCH_SIGNATURE:
+ SearchSignature = (DEBUG_DATA_SEARCH_SIGNATURE *)(DebugHeader + 1);
+ if ((SearchSignature->Alignment != 0) &&
+ (SearchSignature->Alignment == GetPowerOfTwo32 (SearchSignature->Alignment))
+ )
+ {
+ if (SearchSignature->Positive) {
+ for (
+ Data64 = ALIGN_VALUE ((UINTN)SearchSignature->Start, SearchSignature->Alignment);
+ Data64 <= SearchSignature->Start + SearchSignature->Count - SearchSignature->DataLength;
+ Data64 += SearchSignature->Alignment
+ )
+ {
+ if (CompareMem ((VOID *)(UINTN)Data64, &SearchSignature->Data, SearchSignature->DataLength) == 0) {
+ break;
+ }
+ }
- case DEBUG_COMMAND_SEARCH_SIGNATURE:
- SearchSignature = (DEBUG_DATA_SEARCH_SIGNATURE *) (DebugHeader + 1);
- if ((SearchSignature->Alignment != 0) &&
- (SearchSignature->Alignment == GetPowerOfTwo32 (SearchSignature->Alignment))
- ) {
- if (SearchSignature->Positive) {
- for (
- Data64 = ALIGN_VALUE ((UINTN) SearchSignature->Start, SearchSignature->Alignment);
- Data64 <= SearchSignature->Start + SearchSignature->Count - SearchSignature->DataLength;
- Data64 += SearchSignature->Alignment
- ) {
- if (CompareMem ((VOID *) (UINTN) Data64, &SearchSignature->Data, SearchSignature->DataLength) == 0) {
- break;
+ if (Data64 > SearchSignature->Start + SearchSignature->Count - SearchSignature->DataLength) {
+ Data64 = (UINT64)-1;
}
- }
- if (Data64 > SearchSignature->Start + SearchSignature->Count - SearchSignature->DataLength) {
- Data64 = (UINT64) -1;
- }
- } else {
- for (
- Data64 = ALIGN_VALUE ((UINTN) SearchSignature->Start - SearchSignature->Alignment, SearchSignature->Alignment);
- Data64 >= SearchSignature->Start - SearchSignature->Count;
- Data64 -= SearchSignature->Alignment
- ) {
- if (CompareMem ((VOID *) (UINTN) Data64, &SearchSignature->Data, SearchSignature->DataLength) == 0) {
- break;
+ } else {
+ for (
+ Data64 = ALIGN_VALUE ((UINTN)SearchSignature->Start - SearchSignature->Alignment, SearchSignature->Alignment);
+ Data64 >= SearchSignature->Start - SearchSignature->Count;
+ Data64 -= SearchSignature->Alignment
+ )
+ {
+ if (CompareMem ((VOID *)(UINTN)Data64, &SearchSignature->Data, SearchSignature->DataLength) == 0) {
+ break;
+ }
+ }
+
+ if (Data64 < SearchSignature->Start - SearchSignature->Count) {
+ Data64 = (UINT64)-1;
}
}
- if (Data64 < SearchSignature->Start - SearchSignature->Count) {
- Data64 = (UINT64) -1;
- }
+
+ SendDataResponsePacket ((UINT8 *)&Data64, (UINT16)sizeof (Data64), DebugHeader);
+ } else {
+ Status = RETURN_UNSUPPORTED;
}
- SendDataResponsePacket ((UINT8 *) &Data64, (UINT16) sizeof (Data64), DebugHeader);
- } else {
- Status = RETURN_UNSUPPORTED;
- }
- break;
- default:
- SendAckPacket (DEBUG_COMMAND_NOT_SUPPORTED);
- break;
+ break;
+
+ default:
+ SendAckPacket (DEBUG_COMMAND_NOT_SUPPORTED);
+ break;
}
if (Status == RETURN_UNSUPPORTED) {
@@ -2307,21 +2355,21 @@ CommandCommunication (
VOID
EFIAPI
InterruptProcess (
- IN UINT32 Vector,
- IN DEBUG_CPU_CONTEXT *CpuContext
+ IN UINT32 Vector,
+ IN DEBUG_CPU_CONTEXT *CpuContext
)
{
- UINT8 InputCharacter;
- UINT8 BreakCause;
- UINTN SavedEip;
- BOOLEAN BreakReceived;
- UINT32 ProcessorIndex;
- UINT32 CurrentDebugTimerInitCount;
- DEBUG_PORT_HANDLE Handle;
- UINT8 Data8;
- UINT8 *Al;
- UINT32 IssuedViewPoint;
- DEBUG_AGENT_EXCEPTION_BUFFER *ExceptionBuffer;
+ UINT8 InputCharacter;
+ UINT8 BreakCause;
+ UINTN SavedEip;
+ BOOLEAN BreakReceived;
+ UINT32 ProcessorIndex;
+ UINT32 CurrentDebugTimerInitCount;
+ DEBUG_PORT_HANDLE Handle;
+ UINT8 Data8;
+ UINT8 *Al;
+ UINT32 IssuedViewPoint;
+ DEBUG_AGENT_EXCEPTION_BUFFER *ExceptionBuffer;
InputCharacter = 0;
ProcessorIndex = 0;
@@ -2333,12 +2381,12 @@ InterruptProcess (
// If Skip Breakpoint flag is set, means communication is disturbed by hardware SMI, we need to ignore the break points in SMM
//
if ((Vector == DEBUG_INT1_VECTOR) || (Vector == DEBUG_INT3_VECTOR)) {
- DebugPortWriteBuffer (GetDebugPortHandle(), (UINT8 *) mWarningMsgIngoreBreakpoint, AsciiStrLen (mWarningMsgIngoreBreakpoint));
+ DebugPortWriteBuffer (GetDebugPortHandle (), (UINT8 *)mWarningMsgIngoreBreakpoint, AsciiStrLen (mWarningMsgIngoreBreakpoint));
return;
}
}
- if (MultiProcessorDebugSupport()) {
+ if (MultiProcessorDebugSupport ()) {
ProcessorIndex = GetProcessorIndex ();
//
// If this processor has already halted before, need to check it later
@@ -2348,7 +2396,7 @@ InterruptProcess (
}
}
- if (IssuedViewPoint == ProcessorIndex && GetDebugFlag (DEBUG_AGENT_FLAG_STEPPING) != 1) {
+ if ((IssuedViewPoint == ProcessorIndex) && (GetDebugFlag (DEBUG_AGENT_FLAG_STEPPING) != 1)) {
//
// Check if this exception is issued by Debug Agent itself
// If yes, fill the debug agent exception buffer and LongJump() back to
@@ -2363,14 +2411,14 @@ InterruptProcess (
Vector,
(UINTN)CpuContext->Eip
);
- ExceptionBuffer = (DEBUG_AGENT_EXCEPTION_BUFFER *) (UINTN) GetMailboxPointer()->ExceptionBufferPointer;
- ExceptionBuffer->ExceptionContent.ExceptionNum = (UINT8) Vector;
- ExceptionBuffer->ExceptionContent.ExceptionData = (UINT32) CpuContext->ExceptionData;
+ ExceptionBuffer = (DEBUG_AGENT_EXCEPTION_BUFFER *)(UINTN)GetMailboxPointer ()->ExceptionBufferPointer;
+ ExceptionBuffer->ExceptionContent.ExceptionNum = (UINT8)Vector;
+ ExceptionBuffer->ExceptionContent.ExceptionData = (UINT32)CpuContext->ExceptionData;
LongJump ((BASE_LIBRARY_JUMP_BUFFER *)(UINTN)(ExceptionBuffer), 1);
}
}
- if (MultiProcessorDebugSupport()) {
+ if (MultiProcessorDebugSupport ()) {
//
// If RUN command is executing, wait for it done.
//
@@ -2379,239 +2427,250 @@ InterruptProcess (
}
}
- Handle = GetDebugPortHandle();
+ Handle = GetDebugPortHandle ();
BreakCause = GetBreakCause (Vector, CpuContext);
switch (Vector) {
- case DEBUG_INT1_VECTOR:
- case DEBUG_INT3_VECTOR:
- switch (BreakCause) {
- case DEBUG_DATA_BREAK_CAUSE_SYSTEM_RESET:
- if (AttachHost (BreakCause, READ_PACKET_TIMEOUT, &BreakReceived) != RETURN_SUCCESS) {
- //
- // Try to connect HOST, return if fails
- //
- break;
- }
- CommandCommunication (Vector, CpuContext, BreakReceived);
- break;
+ case DEBUG_INT1_VECTOR:
+ case DEBUG_INT3_VECTOR:
+ switch (BreakCause) {
+ case DEBUG_DATA_BREAK_CAUSE_SYSTEM_RESET:
+ if (AttachHost (BreakCause, READ_PACKET_TIMEOUT, &BreakReceived) != RETURN_SUCCESS) {
+ //
+ // Try to connect HOST, return if fails
+ //
+ break;
+ }
- case DEBUG_DATA_BREAK_CAUSE_STEPPING:
- //
- // Stepping is finished, send Ack package.
- //
- if (MultiProcessorDebugSupport()) {
- mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;
- }
- //
- // Clear Stepping Flag and restore EFLAGS.IF
- //
- CommandSteppingCleanup (CpuContext);
- SendAckPacket (DEBUG_COMMAND_OK);
- CommandCommunication (Vector, CpuContext, BreakReceived);
- break;
+ CommandCommunication (Vector, CpuContext, BreakReceived);
+ break;
- case DEBUG_DATA_BREAK_CAUSE_MEMORY_READY:
- //
- // Memory is ready
- //
- SendCommandAndWaitForAckOK (DEBUG_COMMAND_MEMORY_READY, READ_PACKET_TIMEOUT, &BreakReceived, NULL);
- CommandCommunication (Vector, CpuContext, BreakReceived);
- break;
+ case DEBUG_DATA_BREAK_CAUSE_STEPPING:
+ //
+ // Stepping is finished, send Ack package.
+ //
+ if (MultiProcessorDebugSupport ()) {
+ mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;
+ }
- case DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD:
- case DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD:
- //
- // Set AL to DEBUG_AGENT_IMAGE_CONTINUE
- //
- Al = ArchReadRegisterBuffer (CpuContext, SOFT_DEBUGGER_REGISTER_AX, &Data8);
- *Al = DEBUG_AGENT_IMAGE_CONTINUE;
+ //
+ // Clear Stepping Flag and restore EFLAGS.IF
+ //
+ CommandSteppingCleanup (CpuContext);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ CommandCommunication (Vector, CpuContext, BreakReceived);
+ break;
- if (!IsHostAttached ()) {
- //
- // If HOST is not connected for image load/unload, return
- //
- break;
- }
- //
- // Continue to run the following common code
- //
+ case DEBUG_DATA_BREAK_CAUSE_MEMORY_READY:
+ //
+ // Memory is ready
+ //
+ SendCommandAndWaitForAckOK (DEBUG_COMMAND_MEMORY_READY, READ_PACKET_TIMEOUT, &BreakReceived, NULL);
+ CommandCommunication (Vector, CpuContext, BreakReceived);
+ break;
- case DEBUG_DATA_BREAK_CAUSE_HW_BREAKPOINT:
- case DEBUG_DATA_BREAK_CAUSE_SW_BREAKPOINT:
- default:
- //
- // Send Break packet to HOST
- //
- AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- //
- // Only the first breaking processor could send BREAK_POINT to HOST
- //
- if (IsFirstBreakProcessor (ProcessorIndex)) {
- SendBreakPacketToHost (BreakCause, ProcessorIndex, &BreakReceived);
- }
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ case DEBUG_DATA_BREAK_CAUSE_IMAGE_LOAD:
+ case DEBUG_DATA_BREAK_CAUSE_IMAGE_UNLOAD:
+ //
+ // Set AL to DEBUG_AGENT_IMAGE_CONTINUE
+ //
+ Al = ArchReadRegisterBuffer (CpuContext, SOFT_DEBUGGER_REGISTER_AX, &Data8);
+ *Al = DEBUG_AGENT_IMAGE_CONTINUE;
+
+ if (!IsHostAttached ()) {
+ //
+ // If HOST is not connected for image load/unload, return
+ //
+ break;
+ }
- if (Vector == DEBUG_INT3_VECTOR) {
//
- // go back address located "0xCC"
+ // Continue to run the following common code
//
- CpuContext->Eip--;
- SavedEip = CpuContext->Eip;
- CommandCommunication (Vector, CpuContext, BreakReceived);
- if ((SavedEip == CpuContext->Eip) &&
- (*(UINT8 *) (UINTN) CpuContext->Eip == DEBUG_SW_BREAKPOINT_SYMBOL)) {
+
+ case DEBUG_DATA_BREAK_CAUSE_HW_BREAKPOINT:
+ case DEBUG_DATA_BREAK_CAUSE_SW_BREAKPOINT:
+ default:
//
- // If this is not a software breakpoint set by HOST,
- // restore EIP
+ // Send Break packet to HOST
//
- CpuContext->Eip++;
- }
- } else {
- CommandCommunication (Vector, CpuContext, BreakReceived);
+ AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ //
+ // Only the first breaking processor could send BREAK_POINT to HOST
+ //
+ if (IsFirstBreakProcessor (ProcessorIndex)) {
+ SendBreakPacketToHost (BreakCause, ProcessorIndex, &BreakReceived);
+ }
+
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+
+ if (Vector == DEBUG_INT3_VECTOR) {
+ //
+ // go back address located "0xCC"
+ //
+ CpuContext->Eip--;
+ SavedEip = CpuContext->Eip;
+ CommandCommunication (Vector, CpuContext, BreakReceived);
+ if ((SavedEip == CpuContext->Eip) &&
+ (*(UINT8 *)(UINTN)CpuContext->Eip == DEBUG_SW_BREAKPOINT_SYMBOL))
+ {
+ //
+ // If this is not a software breakpoint set by HOST,
+ // restore EIP
+ //
+ CpuContext->Eip++;
+ }
+ } else {
+ CommandCommunication (Vector, CpuContext, BreakReceived);
+ }
+
+ break;
}
- break;
- }
- break;
+ break;
- case DEBUG_TIMER_VECTOR:
+ case DEBUG_TIMER_VECTOR:
- AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- if (MultiProcessorDebugSupport()) {
- if (DebugAgentIsBsp (ProcessorIndex)) {
- //
- // If current processor is BSP, check Apic timer's init count if changed,
- // it may be re-written when switching BSP.
- // If it changed, re-initialize debug timer
- //
- CurrentDebugTimerInitCount = GetApicTimerInitCount ();
- if (mDebugMpContext.DebugTimerInitCount != CurrentDebugTimerInitCount) {
- InitializeDebugTimer (NULL, FALSE);
- SaveAndSetDebugTimerInterrupt (TRUE);
+ if (MultiProcessorDebugSupport ()) {
+ if (DebugAgentIsBsp (ProcessorIndex)) {
+ //
+ // If current processor is BSP, check Apic timer's init count if changed,
+ // it may be re-written when switching BSP.
+ // If it changed, re-initialize debug timer
+ //
+ CurrentDebugTimerInitCount = GetApicTimerInitCount ();
+ if (mDebugMpContext.DebugTimerInitCount != CurrentDebugTimerInitCount) {
+ InitializeDebugTimer (NULL, FALSE);
+ SaveAndSetDebugTimerInterrupt (TRUE);
+ }
}
- }
- if (!DebugAgentIsBsp (ProcessorIndex) || mDebugMpContext.IpiSentByAp) {
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- //
- // If current processor is not BSP or this is one IPI sent by AP
- //
- if (mDebugMpContext.BreakAtCpuIndex != (UINT32) (-1)) {
- CommandCommunication (Vector, CpuContext, FALSE);
- }
+ if (!DebugAgentIsBsp (ProcessorIndex) || mDebugMpContext.IpiSentByAp) {
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ //
+ // If current processor is not BSP or this is one IPI sent by AP
+ //
+ if (mDebugMpContext.BreakAtCpuIndex != (UINT32)(-1)) {
+ CommandCommunication (Vector, CpuContext, FALSE);
+ }
- //
- // Clear EOI before exiting interrupt process routine.
- //
- SendApicEoi ();
- break;
+ //
+ // Clear EOI before exiting interrupt process routine.
+ //
+ SendApicEoi ();
+ break;
+ }
}
- }
- //
- // Only BSP could run here
- //
- while (TRUE) {
//
- // If there is data in debug port, will check whether it is break(attach/break-in) symbol,
- // If yes, go into communication mode with HOST.
- // If no, exit interrupt process.
+ // Only BSP could run here
//
- if (DebugReadBreakSymbol (Handle, &InputCharacter) == EFI_NOT_FOUND) {
- break;
- }
-
- if ((!IsHostAttached () && (InputCharacter == DEBUG_STARTING_SYMBOL_ATTACH)) ||
- (IsHostAttached () && (InputCharacter == DEBUG_COMMAND_HALT)) ||
- (IsHostAttached () && (InputCharacter == DEBUG_COMMAND_GO))
- ) {
- DebugAgentMsgPrint (DEBUG_AGENT_VERBOSE, "Received data [%02x]\n", InputCharacter);
- //
- // Ack OK for break-in symbol
- //
- SendAckPacket (DEBUG_COMMAND_OK);
-
+ while (TRUE) {
//
- // If receive GO command in Debug Timer, means HOST may lost ACK packet before.
+ // If there is data in debug port, will check whether it is break(attach/break-in) symbol,
+ // If yes, go into communication mode with HOST.
+ // If no, exit interrupt process.
//
- if (InputCharacter == DEBUG_COMMAND_GO) {
+ if (DebugReadBreakSymbol (Handle, &InputCharacter) == EFI_NOT_FOUND) {
break;
}
- if (!IsHostAttached ()) {
+ if ((!IsHostAttached () && (InputCharacter == DEBUG_STARTING_SYMBOL_ATTACH)) ||
+ (IsHostAttached () && (InputCharacter == DEBUG_COMMAND_HALT)) ||
+ (IsHostAttached () && (InputCharacter == DEBUG_COMMAND_GO))
+ )
+ {
+ DebugAgentMsgPrint (DEBUG_AGENT_VERBOSE, "Received data [%02x]\n", InputCharacter);
//
- // Try to attach HOST, if no ack received after 200ms, return
+ // Ack OK for break-in symbol
//
- if (AttachHost (BreakCause, READ_PACKET_TIMEOUT, &BreakReceived) != RETURN_SUCCESS) {
+ SendAckPacket (DEBUG_COMMAND_OK);
+
+ //
+ // If receive GO command in Debug Timer, means HOST may lost ACK packet before.
+ //
+ if (InputCharacter == DEBUG_COMMAND_GO) {
break;
}
- }
- if (MultiProcessorDebugSupport()) {
- if(FindNextPendingBreakCpu () != -1) {
- SetCpuBreakFlagByIndex (ProcessorIndex, TRUE);
- } else {
- HaltOtherProcessors (ProcessorIndex);
+ if (!IsHostAttached ()) {
+ //
+ // Try to attach HOST, if no ack received after 200ms, return
+ //
+ if (AttachHost (BreakCause, READ_PACKET_TIMEOUT, &BreakReceived) != RETURN_SUCCESS) {
+ break;
+ }
+ }
+
+ if (MultiProcessorDebugSupport ()) {
+ if (FindNextPendingBreakCpu () != -1) {
+ SetCpuBreakFlagByIndex (ProcessorIndex, TRUE);
+ } else {
+ HaltOtherProcessors (ProcessorIndex);
+ }
}
+
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ CommandCommunication (Vector, CpuContext, BreakReceived);
+ AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ break;
}
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- CommandCommunication (Vector, CpuContext, BreakReceived);
- AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- break;
}
- }
- //
- // Clear EOI before exiting interrupt process routine.
- //
- SendApicEoi ();
+ //
+ // Clear EOI before exiting interrupt process routine.
+ //
+ SendApicEoi ();
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- break;
+ break;
- default:
- if (Vector <= DEBUG_EXCEPT_SIMD) {
- DebugAgentMsgPrint (
- DEBUG_AGENT_ERROR,
- "Exception happened, ExceptionNum is %d, EIP = 0x%x.\n",
- Vector,
- (UINTN) CpuContext->Eip
- );
- if (BreakCause == DEBUG_DATA_BREAK_CAUSE_STEPPING) {
- //
- // If exception happened when executing Stepping, send Ack package.
- // HOST consider Stepping command was finished.
- //
- if (MultiProcessorDebugSupport()) {
- mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;
- }
- //
- // Clear Stepping flag and restore EFLAGS.IF
- //
- CommandSteppingCleanup (CpuContext);
- SendAckPacket (DEBUG_COMMAND_OK);
- } else {
- //
- // Exception occurs, send Break packet to HOST
- //
- AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
- //
- // Only the first breaking processor could send BREAK_POINT to HOST
- //
- if (IsFirstBreakProcessor (ProcessorIndex)) {
- SendBreakPacketToHost (BreakCause, ProcessorIndex, &BreakReceived);
+ default:
+ if (Vector <= DEBUG_EXCEPT_SIMD) {
+ DebugAgentMsgPrint (
+ DEBUG_AGENT_ERROR,
+ "Exception happened, ExceptionNum is %d, EIP = 0x%x.\n",
+ Vector,
+ (UINTN)CpuContext->Eip
+ );
+ if (BreakCause == DEBUG_DATA_BREAK_CAUSE_STEPPING) {
+ //
+ // If exception happened when executing Stepping, send Ack package.
+ // HOST consider Stepping command was finished.
+ //
+ if (MultiProcessorDebugSupport ()) {
+ mDebugMpContext.BreakAtCpuIndex = ProcessorIndex;
+ }
+
+ //
+ // Clear Stepping flag and restore EFLAGS.IF
+ //
+ CommandSteppingCleanup (CpuContext);
+ SendAckPacket (DEBUG_COMMAND_OK);
+ } else {
+ //
+ // Exception occurs, send Break packet to HOST
+ //
+ AcquireMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+ //
+ // Only the first breaking processor could send BREAK_POINT to HOST
+ //
+ if (IsFirstBreakProcessor (ProcessorIndex)) {
+ SendBreakPacketToHost (BreakCause, ProcessorIndex, &BreakReceived);
+ }
+
+ ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
}
- ReleaseMpSpinLock (&mDebugMpContext.DebugPortSpinLock);
+
+ CommandCommunication (Vector, CpuContext, BreakReceived);
}
- CommandCommunication (Vector, CpuContext, BreakReceived);
- }
- break;
+ break;
}
- if (MultiProcessorDebugSupport()) {
+ if (MultiProcessorDebugSupport ()) {
//
// Clear flag and wait for all processors run here
//
@@ -2628,7 +2687,7 @@ InterruptProcess (
}
}
- if (IssuedViewPoint == ProcessorIndex && GetDebugFlag (DEBUG_AGENT_FLAG_STEPPING) != 1) {
+ if ((IssuedViewPoint == ProcessorIndex) && (GetDebugFlag (DEBUG_AGENT_FLAG_STEPPING) != 1)) {
//
// If the command is not stepping, clean up AgentInProgress flag
//
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
index 741b2e4ab1..a0ede308ef 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
@@ -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
-
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
index 16c4595b82..89f922aba0 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
@@ -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;
}
-
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.h b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.h
index 07ddccad33..a0bc24ebfd 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.h
@@ -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
-
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
index eab8e153a1..833aa76a7d 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
@@ -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);
}
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.h b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.h
index cc79e1ba88..be9566643f 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.h
@@ -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
-
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c
index 55da3fe55e..99b9a7fa98 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c
@@ -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);
}
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.h b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.h
index 3acb0352bf..5205b23046 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.h
@@ -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
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/DebugException.h b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/DebugException.h
index 9147fabe6c..05cb45c78e 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/DebugException.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/DebugException.h
@@ -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
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c
index 6b6c71020c..bda113ecca 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c
@@ -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);
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.h b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.h
index 1e45941a99..b795202959 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.h
@@ -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
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/DebugException.h b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/DebugException.h
index 9147fabe6c..05cb45c78e 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/DebugException.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/DebugException.h
@@ -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
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
index 84258aa0f9..a41bba2c4b 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
@@ -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;
+ 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);
+ }
- case DEBUG_AGENT_INIT_DXE_UNLOAD:
- if (mDebugAgentInitialized) {
- if (IsHostAttached ()) {
- *(EFI_STATUS *)Context = EFI_ACCESS_DENIED;
- //
- // Enable Debug Timer interrupt again
- //
- SaveAndSetDebugTimerInterrupt (TRUE);
- } else {
+ //
+ // 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) {
//
- // Restore original IDT table
+ // If Boot Script entry break is set, code will be break at here.
//
- AsmReadIdtr (&IdtDescriptor);
- IdtDescriptor.Limit = (UINT16) (mSaveIdtTableSize - 1);
- CopyMem ((VOID *) IdtDescriptor.Base, mSavedIdtTable, mSaveIdtTableSize);
- AsmWriteIdtr (&IdtDescriptor);
- FreePool (mSavedIdtTable);
- mDebugAgentInitialized = FALSE;
- *(EFI_STATUS *)Context = EFI_SUCCESS;
+ CpuBreakpoint ();
}
- } else {
- *(EFI_STATUS *)Context = EFI_NOT_STARTED;
- }
- //
- // Restore interrupt state.
- //
- SetInterruptState (InterruptStatus);
- break;
+ 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) {
+ default:
//
- // If Boot Script entry break is set, code will be break at here.
+ // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this
+ // Debug Agent library instance.
//
- CpuBreakpoint ();
- }
- 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;
+ DEBUG ((DEBUG_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));
+ CpuDeadLoop ();
+ break;
}
}
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c
index a2fbf115d5..6661275cc3 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c
@@ -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
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
index ea3ae33f3f..b32754fc2a 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
@@ -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);
- 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"));
- 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;
- 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);
+ }
- 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
+ // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
//
- 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
- );
+ Status = PeiServicesInstallPpi (&mVectorHandoffInfoPpiList[0]);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to allocate pages!\n"));
+ DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\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)
- );
//
- // Initialize Debug Timer hardware and save its frequency
+ // Fix up Debug Port handle address and mailbox address
//
- InitializeDebugTimer (&DebugTimerFrequency, TRUE);
- UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
+ 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 pointer saved mailbox pointer
+ // 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);
- }
-
- Phase2Context.InitFlag = InitFlag;
- Phase2Context.Context = Context;
- Phase2Context.Function = Function;
- DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);
+ break;
- FindAndReportModuleImageInfo (4);
+ case DEBUG_AGENT_INIT_PEI:
+ if (Context == NULL) {
+ DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
+ CpuDeadLoop ();
+ }
- break;
+ //
+ // Check if Debug Agent has initialized before
+ //
+ if (IsDebugAgentInitialzed ()) {
+ DEBUG ((DEBUG_WARN, "Debug Agent: It has already initialized in SEC Core!\n"));
+ 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
+ // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
//
- VerifyMailboxChecksum (Mailbox);
+ 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;
-
- Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *) Context;
+ DEBUG_AGENT_PHASE2_CONTEXT *Phase2Context;
+ UINT64 *MailboxLocation;
+ DEBUG_AGENT_MAILBOX *Mailbox;
+ EFI_SEC_PEI_HAND_OFF *SecCoreData;
+ UINT16 BufferSize;
+ UINT64 NewDebugPortHandle;
+
+ Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *)Context;
MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry ();
- Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
- BufferSize = PcdGet16(PcdDebugPortHandleBufferSize);
- if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI && BufferSize != 0) {
+ 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
//
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.h b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.h
index 5ebc0a4b18..969348843a 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.h
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.h
@@ -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
-
diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
index 5f0fe05bad..f49a592d27 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
@@ -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;
-
-CHAR8 mWarningMsgIgnoreSmmEntryBreak[] = "Ignore smmentrybreak setting for SMI issued during DXE debugging!\r\n";
+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";
/**
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
+ //
+ 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.
//
- 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) {
+ ZeroMem (&mLocalMailbox, sizeof (DEBUG_AGENT_MAILBOX));
+ Mailbox = &mLocalMailbox;
//
- // We only need to initialize Debug IDT table at first SMI entry
- // after SMM relocation.
+ // Save original IDT entries
+ //
+ AsmReadIdtr (&IdtDescriptor);
+ CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));
+ //
+ // Initialized Debug Agent
//
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
+ // 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
//
- mSkipBreakpoint = TRUE;
- }
- if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI) == 1) {
- if (mSkipBreakpoint) {
+ TriggerSoftInterrupt (SYSTEM_RESET_SIGNATURE);
+
+ SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
+ //
+ // Memory has been ready
+ //
+ if (IsHostAttached ()) {
//
- // Print warning message if ignore smm entry break
+ // Trigger one software interrupt to inform HOST
//
- DebugPortWriteBuffer ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle,
- (UINT8 *)mWarningMsgIgnoreSmmEntryBreak,
- AsciiStrLen (mWarningMsgIgnoreSmmEntryBreak)
- );
- } else {
+ 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) {
//
- // If SMM entry break is set, SMM code will be break at here.
+ // We only need to initialize Debug IDT table at first SMI entry
+ // after SMM relocation.
//
- CpuBreakpoint ();
+ InitializeDebugIdt ();
+ mSmmDebugIdtInitFlag = TRUE;
}
- }
- 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.
+ // Check if CPU APIC Timer is working, otherwise initialize it.
//
- 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);
+ InitializeLocalApicSoftwareEnable (TRUE);
+ GetApicTimerState (&mApicTimerDivisor, &mPeriodicMode, &mVector);
+ mTimerCycle = GetApicTimerInitCount ();
+ if (!mPeriodicMode || (mTimerCycle == 0)) {
+ mApicTimerRestore = TRUE;
+ InitializeDebugTimer (NULL, FALSE);
}
- InitializeDebugIdt ();
+ 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 ();
//
- // Initialize Debug Timer hardware and save its frequency
+ // Clear Skip Breakpoint flag
//
- InitializeDebugTimer (&DebugTimerFrequency, TRUE);
- UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
+ mSkipBreakpoint = FALSE;
+ RestoreDebugRegister ();
//
- // Enable Debug Timer interrupt and CPU interrupt
+ // Restore APIC Timer
//
- SaveAndSetDebugTimerInterrupt (TRUE);
- EnableInterrupts ();
+ if (mApicTimerRestore) {
+ InitializeApicTimer (mApicTimerDivisor, mTimerCycle, mPeriodicMode, mVector);
+ mApicTimerRestore = FALSE;
+ }
- 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;
+ 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;
}
}
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
index 2b85559aef..34c269e6b5 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
@@ -55,10 +55,10 @@ DebugPortInitialize (
IN DEBUG_PORT_CONTINUE Function
)
{
- RETURN_STATUS Status;
+ RETURN_STATUS Status;
Status = SerialPortInitialize ();
- if (RETURN_ERROR(Status)) {
+ if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Debug Serial Port: Initialization failed!\n"));
}
@@ -89,13 +89,13 @@ DebugPortInitialize (
UINTN
EFIAPI
DebugPortReadBuffer (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes,
- IN UINTN Timeout
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes,
+ IN UINTN Timeout
)
{
- if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {
+ if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) {
return 0;
}
@@ -122,9 +122,9 @@ DebugPortReadBuffer (
UINTN
EFIAPI
DebugPortWriteBuffer (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes
)
{
return SerialPortWrite (Buffer, NumberOfBytes);
@@ -146,7 +146,7 @@ DebugPortWriteBuffer (
BOOLEAN
EFIAPI
DebugPortPollBuffer (
- IN DEBUG_PORT_HANDLE Handle
+ IN DEBUG_PORT_HANDLE Handle
)
{
return SerialPortPoll ();
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
index cc156baaa0..479757f5ba 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
@@ -18,144 +18,144 @@
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
-#define SETUP_PID 0x2D
-#define INPUT_PID 0x69
-#define OUTPUT_PID 0xE1
-#define ERROR_PID 0x55
-#define DATA0_PID 0xC3
-#define DATA1_PID 0x4B
-#define DATA2_PID 0x87
-#define MDATA_PID 0x0F
-#define ACK_PID 0xD2
-#define NAK_PID 0x5A
-#define STALL_PID 0x1E
-#define NYET_PID 0x96
-
-#define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A
-#define USB_DEBUG_PORT_MAX_PACKET_SIZE 0x08
-
-#define USB_DEBUG_PORT_IN_USE BIT10
-#define USB_DEBUG_PORT_ENABLE BIT28
-#define USB_DEBUG_PORT_OWNER BIT30
-
-#define USB_PORT_LINE_STATUS_LS 0x400
-#define USB_PORT_LINE_STATUS_MASK 0xC00
+#define SETUP_PID 0x2D
+#define INPUT_PID 0x69
+#define OUTPUT_PID 0xE1
+#define ERROR_PID 0x55
+#define DATA0_PID 0xC3
+#define DATA1_PID 0x4B
+#define DATA2_PID 0x87
+#define MDATA_PID 0x0F
+#define ACK_PID 0xD2
+#define NAK_PID 0x5A
+#define STALL_PID 0x1E
+#define NYET_PID 0x96
+
+#define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A
+#define USB_DEBUG_PORT_MAX_PACKET_SIZE 0x08
+
+#define USB_DEBUG_PORT_IN_USE BIT10
+#define USB_DEBUG_PORT_ENABLE BIT28
+#define USB_DEBUG_PORT_OWNER BIT30
+
+#define USB_PORT_LINE_STATUS_LS 0x400
+#define USB_PORT_LINE_STATUS_MASK 0xC00
//
// Usb debug device descriptor, which is defined at
// USB2 Debug Device Specification.
//
typedef struct _USB_DEBUG_PORT_DESCRIPTOR {
- UINT8 Length;
- UINT8 DescriptorType;
- UINT8 DebugInEndpoint;
- UINT8 DebugOutEndpoint;
-}USB_DEBUG_PORT_DESCRIPTOR;
+ UINT8 Length;
+ UINT8 DescriptorType;
+ UINT8 DebugInEndpoint;
+ UINT8 DebugOutEndpoint;
+} USB_DEBUG_PORT_DESCRIPTOR;
-USB_DEVICE_REQUEST mDebugCommunicationLibUsbGetDebugDescriptor = {
+USB_DEVICE_REQUEST mDebugCommunicationLibUsbGetDebugDescriptor = {
0x80,
USB_REQ_GET_DESCRIPTOR,
(UINT16)(0x0A << 8),
0x0000,
- sizeof(USB_DEBUG_PORT_DESCRIPTOR)
- };
+ sizeof (USB_DEBUG_PORT_DESCRIPTOR)
+};
-USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = {
+USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = {
0x0,
USB_REQ_SET_FEATURE,
(UINT16)(0x06),
0x0000,
0x0
- };
+};
-USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = {
+USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = {
0x0,
USB_REQ_SET_ADDRESS,
(UINT16)(0x7F),
0x0000,
0x0
- };
+};
//
// Usb debug port register file, which is defined at
// EHCI Specification.
//
typedef struct _USB_DEBUG_PORT_REGISTER {
- UINT32 ControlStatus;
- UINT8 TokenPid;
- UINT8 SendPid;
- UINT8 ReceivedPid;
- UINT8 Reserved1;
- UINT8 DataBuffer[8];
- UINT8 UsbEndPoint;
- UINT8 UsbAddress;
- UINT8 Reserved2;
- UINT8 Reserved3;
-}USB_DEBUG_PORT_REGISTER;
+ UINT32 ControlStatus;
+ UINT8 TokenPid;
+ UINT8 SendPid;
+ UINT8 ReceivedPid;
+ UINT8 Reserved1;
+ UINT8 DataBuffer[8];
+ UINT8 UsbEndPoint;
+ UINT8 UsbAddress;
+ UINT8 Reserved2;
+ UINT8 Reserved3;
+} USB_DEBUG_PORT_REGISTER;
//
// The state machine of usb debug port
//
-#define USBDBG_NO_DEV 0 // No device present at debug port
-#define USBDBG_NO_DBG_CAB 1 // The device attached is not usb debug cable
-#define USBDBG_DBG_CAB 2 // The device attached is usb debug cable
-#define USBDBG_INIT_DONE 4 // The usb debug cable device is initialized
-#define USBDBG_RESET 8 // The system is reset
+#define USBDBG_NO_DEV 0 // No device present at debug port
+#define USBDBG_NO_DBG_CAB 1 // The device attached is not usb debug cable
+#define USBDBG_DBG_CAB 2 // The device attached is usb debug cable
+#define USBDBG_INIT_DONE 4 // The usb debug cable device is initialized
+#define USBDBG_RESET 8 // The system is reset
#pragma pack(1)
//
// The internal data structure of DEBUG_PORT_HANDLE, which stores some
// important datum which are used across various phases.
//
-typedef struct _USB_DEBUG_PORT_HANDLE{
+typedef struct _USB_DEBUG_PORT_HANDLE {
//
// The usb debug port memory BAR number in EHCI configuration space.
//
- UINT8 DebugPortBarNumber;
- UINT8 Initialized;
+ UINT8 DebugPortBarNumber;
+ UINT8 Initialized;
//
// The offset of usb debug port registers in EHCI memory range.
//
- UINT16 DebugPortOffset;
+ UINT16 DebugPortOffset;
//
// The usb debug port memory BAR address.
//
- UINT32 UsbDebugPortMemoryBase;
+ UINT32 UsbDebugPortMemoryBase;
//
// The EHCI memory BAR address.
//
- UINT32 EhciMemoryBase;
+ UINT32 EhciMemoryBase;
//
// The usb debug device In endpoint.
//
- UINT8 InEndpoint;
+ UINT8 InEndpoint;
//
// The usb debug device Out endpoint.
//
- UINT8 OutEndpoint;
+ UINT8 OutEndpoint;
//
// The Bulk In endpoint toggle bit.
//
- UINT8 BulkInToggle;
+ UINT8 BulkInToggle;
//
// The Bulk Out endpoint toggle bit.
//
- UINT8 BulkOutToggle;
+ UINT8 BulkOutToggle;
//
// The available data length in the following data buffer.
//
- UINT8 DataCount;
+ UINT8 DataCount;
//
// The data buffer. Maximum length is 8 bytes.
//
- UINT8 Data[8];
+ UINT8 Data[8];
} USB_DEBUG_PORT_HANDLE;
#pragma pack()
//
// The global variable which can be used after memory is ready.
//
-USB_DEBUG_PORT_HANDLE mDebugCommunicationLibUsbDebugPortHandle;
+USB_DEBUG_PORT_HANDLE mDebugCommunicationLibUsbDebugPortHandle;
/**
Calculate the usb debug port bar address.
@@ -170,29 +170,29 @@ USB_DEBUG_PORT_HANDLE mDebugCommunicationLibUsbDebugPortHandle;
RETURN_STATUS
EFIAPI
CalculateUsbDebugPortBar (
- OUT UINT16 *DebugPortOffset,
- OUT UINT8 *DebugPortBarNumbar
- )
+ OUT UINT16 *DebugPortOffset,
+ OUT UINT8 *DebugPortBarNumbar
+ )
{
- UINT16 PciStatus;
- UINT16 VendorId;
- UINT16 DeviceId;
- UINT8 ProgInterface;
- UINT8 SubClassCode;
- UINT8 BaseCode;
- UINT8 CapabilityPtr;
- UINT8 CapabilityId;
-
- VendorId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET);
- DeviceId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET);
+ UINT16 PciStatus;
+ UINT16 VendorId;
+ UINT16 DeviceId;
+ UINT8 ProgInterface;
+ UINT8 SubClassCode;
+ UINT8 BaseCode;
+ UINT8 CapabilityPtr;
+ UINT8 CapabilityId;
+
+ VendorId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET);
+ DeviceId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET);
if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {
return RETURN_UNSUPPORTED;
}
- ProgInterface = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET);
- SubClassCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);
- BaseCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);
+ ProgInterface = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET);
+ SubClassCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);
+ BaseCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);
if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {
return RETURN_UNSUPPORTED;
@@ -201,7 +201,7 @@ CalculateUsbDebugPortBar (
//
// Enable Ehci Host Controller MMIO Space.
//
- PciStatus = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET);
+ PciStatus = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET);
if ((PciStatus & EFI_PCI_STATUS_CAPABILITY) == 0) {
//
@@ -213,17 +213,18 @@ CalculateUsbDebugPortBar (
//
// Get Pointer To Capability List
//
- CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET);
+ CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET);
//
// Find Capability ID 0xA, Which Is For Debug Port
//
while (CapabilityPtr != 0) {
- CapabilityId = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr);
+ CapabilityId = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr);
if (CapabilityId == PCI_CAPABILITY_ID_DEBUG_PORT) {
break;
}
- CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 1);
+
+ CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 1);
}
//
@@ -236,8 +237,8 @@ CalculateUsbDebugPortBar (
//
// Get The Base Address Of Debug Port Register In Debug Port Capability Register
//
- *DebugPortOffset = (UINT16)(PciRead16(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) & 0x1FFF);
- *DebugPortBarNumbar = (UINT8)((PciRead16(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) >> 13) - 1);
+ *DebugPortOffset = (UINT16)(PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 2) & 0x1FFF);
+ *DebugPortBarNumbar = (UINT8)((PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 2) >> 13) - 1);
return RETURN_SUCCESS;
}
@@ -261,20 +262,21 @@ CalculateUsbDebugPortBar (
RETURN_STATUS
EFIAPI
UsbDebugPortIn (
- IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,
- IN OUT UINT8 *Buffer,
- OUT UINT8 *Length,
- IN UINT8 Token,
- IN UINT8 Addr,
- IN UINT8 Ep,
- IN UINT8 DataToggle
+ IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,
+ IN OUT UINT8 *Buffer,
+ OUT UINT8 *Length,
+ IN UINT8 Token,
+ IN UINT8 Addr,
+ IN UINT8 Ep,
+ IN UINT8 DataToggle
)
{
- UINTN Index;
+ UINTN Index;
if (Length == NULL) {
return RETURN_INVALID_PARAMETER;
}
+
*Length = 0;
DebugPortRegister->TokenPid = Token;
@@ -290,19 +292,20 @@ UsbDebugPortIn (
//
// Clearing W/R bit to indicate it's a READ operation
//
- MmioAnd32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~BIT4);
+ MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32) ~BIT4);
//
// Setting GO bit as well as clearing DONE bit
//
- MmioOr32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5);
+ MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5);
//
// Wait for completing the request
//
- while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) {
- if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
- != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) {
+ while ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) {
+ if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
+ != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
+ {
return RETURN_DEVICE_ERROR;
}
}
@@ -310,23 +313,23 @@ UsbDebugPortIn (
//
// Clearing DONE bit by writing 1
//
- MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT16);
+ MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);
//
// Check if the request is executed successfully or not.
//
- if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
+ if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
return RETURN_DEVICE_ERROR;
}
//
// Make sure the received data are not beyond the allowable maximum length - 8 byte
//
- if (((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {
+ if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {
return RETURN_DEVICE_ERROR;
}
- *Length = (UINT8)(MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & 0xF);
+ *Length = (UINT8)(MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & 0xF);
if (*Length > 8) {
return RETURN_DEVICE_ERROR;
}
@@ -334,6 +337,7 @@ UsbDebugPortIn (
for (Index = 0; Index < *Length; Index++) {
Buffer[Index] = DebugPortRegister->DataBuffer[Index];
}
+
return RETURN_SUCCESS;
}
@@ -356,16 +360,16 @@ UsbDebugPortIn (
RETURN_STATUS
EFIAPI
UsbDebugPortOut (
- IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,
- IN UINT8 *Buffer,
- IN UINT8 Length,
- IN UINT8 Token,
- IN UINT8 Addr,
- IN UINT8 Ep,
- IN UINT8 DataToggle
+ IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,
+ IN UINT8 *Buffer,
+ IN UINT8 Length,
+ IN UINT8 Token,
+ IN UINT8 Addr,
+ IN UINT8 Ep,
+ IN UINT8 DataToggle
)
{
- UINT8 Index;
+ UINT8 Index;
if (Length > 8) {
return RETURN_INVALID_PARAMETER;
@@ -377,14 +381,15 @@ UsbDebugPortOut (
} else {
DebugPortRegister->SendPid = DATA0_PID;
}
+
DebugPortRegister->UsbAddress = (UINT8)(Addr & 0x7F);
DebugPortRegister->UsbEndPoint = (UINT8)(Ep & 0xF);
//
// Fill in the data length and corresponding data.
//
- MmioAnd32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~0xF);
- MmioOr32((UINTN)&DebugPortRegister->ControlStatus, Length & 0xF);
+ MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32) ~0xF);
+ MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, Length & 0xF);
for (Index = 0; Index < Length; Index++) {
DebugPortRegister->DataBuffer[Index] = Buffer[Index];
}
@@ -392,18 +397,19 @@ UsbDebugPortOut (
//
// Setting W/R bit to indicate it's a WRITE operation
//
- MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT4);
+ MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT4);
//
// Setting GO bit as well as clearing DONE bit
//
- MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT5);
+ MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT5);
//
// Wait for completing the request
//
- while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & BIT16) == 0) {
- if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
- != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) {
+ while ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & BIT16) == 0) {
+ if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
+ != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
+ {
return RETURN_DEVICE_ERROR;
}
}
@@ -411,19 +417,19 @@ UsbDebugPortOut (
//
// Clearing DONE bit by writing 1
//
- MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT16);
+ MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);
//
// Check if the request is executed successfully or not.
//
- if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
+ if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
return RETURN_DEVICE_ERROR;
}
//
// Make sure the sent data are not beyond the allowable maximum length - 8 byte
//
- if (((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {
+ if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {
return RETURN_DEVICE_ERROR;
}
@@ -448,23 +454,23 @@ UsbDebugPortOut (
RETURN_STATUS
EFIAPI
UsbDebugPortControlTransfer (
- IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,
- IN USB_DEVICE_REQUEST *SetupPacket,
- IN UINT8 Addr,
- IN UINT8 Ep,
- OUT UINT8 *Data,
- IN OUT UINT8 *DataLength
+ IN USB_DEBUG_PORT_REGISTER *DebugPortRegister,
+ IN USB_DEVICE_REQUEST *SetupPacket,
+ IN UINT8 Addr,
+ IN UINT8 Ep,
+ OUT UINT8 *Data,
+ IN OUT UINT8 *DataLength
)
{
- RETURN_STATUS Status;
- UINT8 Temp;
- UINT8 ReturnStatus[8];
+ RETURN_STATUS Status;
+ UINT8 Temp;
+ UINT8 ReturnStatus[8];
//
// Setup Phase
//
- Status = UsbDebugPortOut(DebugPortRegister, (UINT8 *)SetupPacket, (UINT8)sizeof(USB_DEVICE_REQUEST), SETUP_PID, Addr, Ep, 0);
- if (RETURN_ERROR(Status)) {
+ Status = UsbDebugPortOut (DebugPortRegister, (UINT8 *)SetupPacket, (UINT8)sizeof (USB_DEVICE_REQUEST), SETUP_PID, Addr, Ep, 0);
+ if (RETURN_ERROR (Status)) {
return Status;
}
@@ -476,16 +482,16 @@ UsbDebugPortControlTransfer (
//
// Get Data From Device
//
- Status = UsbDebugPortIn(DebugPortRegister, Data, DataLength, INPUT_PID, Addr, Ep, 1);
- if (RETURN_ERROR(Status)) {
+ Status = UsbDebugPortIn (DebugPortRegister, Data, DataLength, INPUT_PID, Addr, Ep, 1);
+ if (RETURN_ERROR (Status)) {
return Status;
}
} else {
//
// Send Data To Device
//
- Status = UsbDebugPortOut(DebugPortRegister, Data, *DataLength, OUTPUT_PID, Addr, Ep, 1);
- if (RETURN_ERROR(Status)) {
+ Status = UsbDebugPortOut (DebugPortRegister, Data, *DataLength, OUTPUT_PID, Addr, Ep, 1);
+ if (RETURN_ERROR (Status)) {
return Status;
}
}
@@ -498,12 +504,12 @@ UsbDebugPortControlTransfer (
//
// For READ operation, Data Toggle in Status Phase Should be 1.
//
- Status = UsbDebugPortOut(DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1);
+ Status = UsbDebugPortOut (DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1);
} else {
//
// For WRITE operation, Data Toggle in Status Phase Should be 1.
//
- Status = UsbDebugPortIn(DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);
+ Status = UsbDebugPortIn (DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);
}
return Status;
@@ -524,37 +530,37 @@ UsbDebugPortControlTransfer (
**/
BOOLEAN
EFIAPI
-NeedReinitializeHardware(
- IN USB_DEBUG_PORT_HANDLE *Handle
+NeedReinitializeHardware (
+ IN USB_DEBUG_PORT_HANDLE *Handle
)
{
- UINT16 PciCmd;
- UINT32 UsbDebugPortMemoryBase;
- UINT32 EhciMemoryBase;
- BOOLEAN Status;
- USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
+ UINT16 PciCmd;
+ UINT32 UsbDebugPortMemoryBase;
+ UINT32 EhciMemoryBase;
+ BOOLEAN Status;
+ USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
Status = FALSE;
- EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
+ EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
if (EhciMemoryBase != Handle->EhciMemoryBase) {
Handle->EhciMemoryBase = EhciMemoryBase;
- Status = TRUE;
+ Status = TRUE;
}
- UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle->DebugPortBarNumber * 4);
+ UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle->DebugPortBarNumber * 4);
if (UsbDebugPortMemoryBase != Handle->UsbDebugPortMemoryBase) {
Handle->UsbDebugPortMemoryBase = UsbDebugPortMemoryBase;
- Status = TRUE;
+ Status = TRUE;
}
//
// Enable Ehci Memory Space Access
//
- PciCmd = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);
+ PciCmd = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);
if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) {
PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER;
- PciWrite16(PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);
+ PciWrite16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);
Status = TRUE;
}
@@ -562,8 +568,9 @@ NeedReinitializeHardware(
// If the owner and in_use bit is not set, it means system is doing cold/warm boot or EHCI host controller is reset by system software.
//
UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
- if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE))
- != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) {
+ if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE))
+ != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE))
+ {
Status = TRUE;
}
@@ -572,6 +579,7 @@ NeedReinitializeHardware(
} else if (Handle->Initialized != USBDBG_INIT_DONE) {
Status = TRUE;
}
+
return Status;
}
@@ -593,88 +601,94 @@ NeedReinitializeHardware(
RETURN_STATUS
EFIAPI
InitializeUsbDebugHardware (
- IN USB_DEBUG_PORT_HANDLE *Handle
-)
+ IN USB_DEBUG_PORT_HANDLE *Handle
+ )
{
- RETURN_STATUS Status;
- USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
- USB_DEBUG_PORT_DESCRIPTOR UsbDebugPortDescriptor;
- UINT32 *PortStatus;
- UINT32 *UsbCmd;
- UINT32 *UsbStatus;
- UINT32 *UsbHCSParam;
- UINT8 DebugPortNumber;
- UINT8 Length;
+ RETURN_STATUS Status;
+ USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
+ USB_DEBUG_PORT_DESCRIPTOR UsbDebugPortDescriptor;
+ UINT32 *PortStatus;
+ UINT32 *UsbCmd;
+ UINT32 *UsbStatus;
+ UINT32 *UsbHCSParam;
+ UINT8 DebugPortNumber;
+ UINT8 Length;
UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
- UsbHCSParam = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x04);
- UsbCmd = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x20);
- UsbStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x24);
+ UsbHCSParam = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x04);
+ UsbCmd = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x20);
+ UsbStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x24);
//
// Check if the debug port is enabled and owned by myself.
//
- if (((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE))
- != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) || (Handle->Initialized == USBDBG_RESET)) {
+ if (((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE))
+ != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) || (Handle->Initialized == USBDBG_RESET))
+ {
DEBUG ((
DEBUG_INFO,
"UsbDbg: Need to reset the host controller. ControlStatus = %08x\n",
- MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus)
+ MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)
));
//
// If the host controller is halted, then reset and restart it.
//
- if ((MmioRead32((UINTN)UsbStatus) & BIT12) != 0) {
+ if ((MmioRead32 ((UINTN)UsbStatus) & BIT12) != 0) {
DEBUG ((DEBUG_INFO, "UsbDbg: Reset the host controller.\n"));
//
// reset the host controller.
//
- MmioOr32((UINTN)UsbCmd, BIT1);
+ MmioOr32 ((UINTN)UsbCmd, BIT1);
//
// ensure that the host controller is reset.
//
- while ((MmioRead32((UINTN)UsbCmd) & BIT1) != 0);
+ while ((MmioRead32 ((UINTN)UsbCmd) & BIT1) != 0) {
+ }
- MmioOr32((UINTN)UsbCmd, BIT0);
+ MmioOr32 ((UINTN)UsbCmd, BIT0);
// ensure that the host controller is started (HALTED bit must be cleared)
- while ((MmioRead32((UINTN)UsbStatus) & BIT12) != 0);
+ while ((MmioRead32 ((UINTN)UsbStatus) & BIT12) != 0) {
+ }
}
//
// First get the ownership of port 0.
//
- MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE);
+ MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE);
MicroSecondDelay (200000);
}
+
//
// Find out which port is used as debug port.
//
- DebugPortNumber = (UINT8)((MmioRead32((UINTN)UsbHCSParam) & 0x00F00000) >> 20);
+ DebugPortNumber = (UINT8)((MmioRead32 ((UINTN)UsbHCSParam) & 0x00F00000) >> 20);
//
// Should find a device is connected at debug port
//
PortStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4);
- if (!(MmioRead32((UINTN)PortStatus) & BIT0)) {
+ if (!(MmioRead32 ((UINTN)PortStatus) & BIT0)) {
Handle->Initialized = USBDBG_NO_DEV;
return RETURN_NOT_FOUND;
}
- if (Handle->Initialized != USBDBG_INIT_DONE ||
- (MmioRead32 ((UINTN) &UsbDebugPortRegister->ControlStatus) & USB_DEBUG_PORT_ENABLE) == 0) {
+ if ((Handle->Initialized != USBDBG_INIT_DONE) ||
+ ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & USB_DEBUG_PORT_ENABLE) == 0))
+ {
DEBUG ((DEBUG_INFO, "UsbDbg: Reset the debug port.\n"));
//
// Reset the debug port
//
- MmioOr32((UINTN)PortStatus, BIT8);
+ MmioOr32 ((UINTN)PortStatus, BIT8);
MicroSecondDelay (500000);
- MmioAnd32((UINTN)PortStatus, (UINT32)~BIT8);
- while (MmioRead32((UINTN)PortStatus) & BIT8);
+ MmioAnd32 ((UINTN)PortStatus, (UINT32) ~BIT8);
+ while (MmioRead32 ((UINTN)PortStatus) & BIT8) {
+ }
//
// The port enabled bit should be set by HW.
//
- if ((MmioRead32((UINTN)PortStatus) & BIT2) == 0) {
+ if ((MmioRead32 ((UINTN)PortStatus) & BIT2) == 0) {
Handle->Initialized = USBDBG_NO_DBG_CAB;
return RETURN_DEVICE_ERROR;
}
@@ -682,7 +696,7 @@ InitializeUsbDebugHardware (
//
// Enable Usb Debug Port Capability
//
- MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE);
+ MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE);
//
// initialize the data toggle used by bulk in/out endpoint.
@@ -694,7 +708,7 @@ InitializeUsbDebugHardware (
// set usb debug device address as 0x7F.
//
Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugAddress, 0x0, 0x0, NULL, NULL);
- if (RETURN_ERROR(Status)) {
+ if (RETURN_ERROR (Status)) {
//
// The device can not work well.
//
@@ -710,8 +724,8 @@ InitializeUsbDebugHardware (
//
// Get debug descriptor.
//
- Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbGetDebugDescriptor, 0x7F, 0x0, (UINT8*)&UsbDebugPortDescriptor, &Length);
- if (RETURN_ERROR(Status)) {
+ Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbGetDebugDescriptor, 0x7F, 0x0, (UINT8 *)&UsbDebugPortDescriptor, &Length);
+ if (RETURN_ERROR (Status)) {
//
// The device is not a usb debug device.
//
@@ -719,7 +733,7 @@ InitializeUsbDebugHardware (
return Status;
}
- if (Length != sizeof(USB_DEBUG_PORT_DESCRIPTOR)) {
+ if (Length != sizeof (USB_DEBUG_PORT_DESCRIPTOR)) {
Handle->Initialized = USBDBG_NO_DBG_CAB;
return RETURN_DEVICE_ERROR;
}
@@ -734,7 +748,7 @@ InitializeUsbDebugHardware (
// enable the usb debug feature.
//
Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugFeature, 0x7F, 0x0, NULL, NULL);
- if (RETURN_ERROR(Status)) {
+ if (RETURN_ERROR (Status)) {
//
// The device can not work well.
//
@@ -773,17 +787,17 @@ InitializeUsbDebugHardware (
UINTN
EFIAPI
DebugPortReadBuffer (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes,
- IN UINTN Timeout
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes,
+ IN UINTN Timeout
)
{
- USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
- RETURN_STATUS Status;
- UINT8 Index;
+ USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
+ RETURN_STATUS Status;
+ UINT8 Index;
- if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {
+ if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) {
return 0;
}
@@ -797,9 +811,9 @@ DebugPortReadBuffer (
UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;
}
- if (NeedReinitializeHardware(UsbDebugPortHandle)) {
+ if (NeedReinitializeHardware (UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
- if (RETURN_ERROR(Status)) {
+ if (RETURN_ERROR (Status)) {
return 0;
}
}
@@ -815,8 +829,10 @@ DebugPortReadBuffer (
if ((Index + 1) >= USB_DEBUG_PORT_MAX_PACKET_SIZE) {
return 0;
}
+
UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Index + 1];
}
+
UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);
return 1;
}
@@ -842,19 +858,19 @@ DebugPortReadBuffer (
UINTN
EFIAPI
DebugPortWriteBuffer (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes
)
{
- USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
- USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
- RETURN_STATUS Status;
- UINT8 Sent;
- UINTN Total;
- UINT8 ReceivedPid;
-
- if (NumberOfBytes == 0 || Buffer == NULL) {
+ USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
+ USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
+ RETURN_STATUS Status;
+ UINT8 Sent;
+ UINTN Total;
+ UINT8 ReceivedPid;
+
+ if ((NumberOfBytes == 0) || (Buffer == NULL)) {
return 0;
}
@@ -871,9 +887,9 @@ DebugPortWriteBuffer (
UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;
}
- if (NeedReinitializeHardware(UsbDebugPortHandle)) {
+ if (NeedReinitializeHardware (UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
- if (RETURN_ERROR(Status)) {
+ if (RETURN_ERROR (Status)) {
return 0;
}
}
@@ -887,13 +903,13 @@ DebugPortWriteBuffer (
Sent = (UINT8)(NumberOfBytes - Total);
}
- Status = UsbDebugPortOut(UsbDebugPortRegister, Buffer + Total, Sent, OUTPUT_PID, 0x7F, UsbDebugPortHandle->OutEndpoint, UsbDebugPortHandle->BulkOutToggle);
+ Status = UsbDebugPortOut (UsbDebugPortRegister, Buffer + Total, Sent, OUTPUT_PID, 0x7F, UsbDebugPortHandle->OutEndpoint, UsbDebugPortHandle->BulkOutToggle);
- if (RETURN_ERROR(Status)) {
+ if (RETURN_ERROR (Status)) {
return Total;
}
- ReceivedPid = (MmioRead8((UINTN)&UsbDebugPortRegister->ReceivedPid));
+ ReceivedPid = (MmioRead8 ((UINTN)&UsbDebugPortRegister->ReceivedPid));
//
// If received a NAK_PID on write transaction, it means the usb debug device is busy and can not handle this transaction.
// should send the packet again.
@@ -903,8 +919,10 @@ DebugPortWriteBuffer (
} else {
UsbDebugPortHandle->BulkOutToggle ^= 1;
}
+
Total += Sent;
}
+
return Total;
}
@@ -924,14 +942,14 @@ DebugPortWriteBuffer (
BOOLEAN
EFIAPI
DebugPortPollBuffer (
- IN DEBUG_PORT_HANDLE Handle
+ IN DEBUG_PORT_HANDLE Handle
)
{
- USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
- USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
- UINT8 Length;
- UINT8 Index;
- RETURN_STATUS Status;
+ USB_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
+ USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
+ UINT8 Length;
+ UINT8 Index;
+ RETURN_STATUS Status;
//
// If Handle is NULL, it means memory is ready for use.
@@ -943,9 +961,9 @@ DebugPortPollBuffer (
UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;
}
- if (NeedReinitializeHardware(UsbDebugPortHandle)) {
- Status = InitializeUsbDebugHardware(UsbDebugPortHandle);
- if (RETURN_ERROR(Status)) {
+ if (NeedReinitializeHardware (UsbDebugPortHandle)) {
+ Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
+ if (RETURN_ERROR (Status)) {
return FALSE;
}
}
@@ -962,37 +980,39 @@ DebugPortPollBuffer (
UsbDebugPortRegister->TokenPid = INPUT_PID;
if (UsbDebugPortHandle->BulkInToggle == 0) {
- UsbDebugPortRegister->SendPid = DATA0_PID;
+ UsbDebugPortRegister->SendPid = DATA0_PID;
} else {
- UsbDebugPortRegister->SendPid = DATA1_PID;
+ UsbDebugPortRegister->SendPid = DATA1_PID;
}
+
UsbDebugPortRegister->UsbAddress = 0x7F;
UsbDebugPortRegister->UsbEndPoint = UsbDebugPortHandle->InEndpoint & 0x0F;
//
// Clearing W/R bit to indicate it's a READ operation
//
- MmioAnd32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)~BIT4);
+ MmioAnd32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32) ~BIT4);
//
// Setting GO bit as well as clearing DONE bit
//
- MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5);
+ MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5);
//
// Wait for completing the request
//
- while ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) {
- if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
- != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) {
+ while ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) {
+ if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
+ != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
+ {
return FALSE;
}
}
- if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) {
+ if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) {
return FALSE;
}
- Length = (UINT8)(MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF);
+ Length = (UINT8)(MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF);
if (Length > 8) {
return FALSE;
@@ -1007,6 +1027,7 @@ DebugPortPollBuffer (
for (Index = 0; Index < Length; Index++) {
UsbDebugPortHandle->Data[Index] = UsbDebugPortRegister->DataBuffer[Index];
}
+
UsbDebugPortHandle->DataCount = Length;
return TRUE;
@@ -1043,51 +1064,52 @@ DebugPortInitialize (
IN DEBUG_PORT_CONTINUE Function
)
{
- RETURN_STATUS Status;
- USB_DEBUG_PORT_HANDLE Handle;
+ RETURN_STATUS Status;
+ USB_DEBUG_PORT_HANDLE Handle;
//
// Validate the PCD PcdDebugPortHandleBufferSize value
//
ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB_DEBUG_PORT_HANDLE));
- if (Function == NULL && Context != NULL) {
- return (DEBUG_PORT_HANDLE *) Context;
+ if ((Function == NULL) && (Context != NULL)) {
+ return (DEBUG_PORT_HANDLE *)Context;
}
- ZeroMem(&Handle, sizeof (USB_DEBUG_PORT_HANDLE));
- Status = CalculateUsbDebugPortBar(&Handle.DebugPortOffset, &Handle.DebugPortBarNumber);
+ ZeroMem (&Handle, sizeof (USB_DEBUG_PORT_HANDLE));
+
+ Status = CalculateUsbDebugPortBar (&Handle.DebugPortOffset, &Handle.DebugPortBarNumber);
if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "UsbDbg: the pci device pointed by PcdUsbEhciPciAddress is not EHCI host controller or does not support debug port capability!\n"));
goto Exit;
}
- Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
+ Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
if (Handle.EhciMemoryBase == 0) {
//
// Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero
//
- PciWrite32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, PcdGet32(PcdUsbEhciMemorySpaceBase));
- Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
+ PciWrite32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, PcdGet32 (PcdUsbEhciMemorySpaceBase));
+ Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
}
- Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);
+ Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);
if (Handle.UsbDebugPortMemoryBase == 0) {
//
// Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero
//
- PciWrite32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4, PcdGet32(PcdUsbDebugPortMemorySpaceBase));
- Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);
+ PciWrite32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4, PcdGet32 (PcdUsbDebugPortMemorySpaceBase));
+ Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);
}
Handle.Initialized = USBDBG_RESET;
- if (NeedReinitializeHardware(&Handle)) {
+ if (NeedReinitializeHardware (&Handle)) {
DEBUG ((DEBUG_ERROR, "UsbDbg: Start EHCI debug port initialization!\n"));
Status = InitializeUsbDebugHardware (&Handle);
- if (RETURN_ERROR(Status)) {
+ if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "UsbDbg: Failed, please check if USB debug cable is plugged into EHCI debug port correctly!\n"));
goto Exit;
}
@@ -1098,7 +1120,7 @@ Exit:
if (Function != NULL) {
Function (Context, &Handle);
} else {
- CopyMem(&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE));
+ CopyMem (&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE));
}
return (DEBUG_PORT_HANDLE)(UINTN)&mDebugCommunicationLibUsbDebugPortHandle;
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
index d76314a42a..3a3d16e4b9 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
@@ -8,27 +8,27 @@
#include "DebugCommunicationLibUsb3Internal.h"
-UINT16 mString0Desc[] = {
+UINT16 mString0Desc[] = {
// String Descriptor Type + Length
- ( USB_DESC_TYPE_STRING << 8 ) + STRING0_DESC_LEN,
+ (USB_DESC_TYPE_STRING << 8) + STRING0_DESC_LEN,
0x0409
};
-UINT16 mManufacturerStrDesc[] = {
+UINT16 mManufacturerStrDesc[] = {
// String Descriptor Type + Length
- ( USB_DESC_TYPE_STRING << 8 ) + MANU_DESC_LEN,
- 'I', 'n', 't', 'e', 'l'
+ (USB_DESC_TYPE_STRING << 8) + MANU_DESC_LEN,
+ 'I', 'n','t', 'e', 'l'
};
-UINT16 mProductStrDesc[] = {
+UINT16 mProductStrDesc[] = {
// String Descriptor Type + Length
- ( USB_DESC_TYPE_STRING << 8 ) + PRODUCT_DESC_LEN,
- 'U', 'S', 'B', ' ', '3', '.', '0', ' ', 'D', 'e', 'b', 'u', 'g', ' ', 'C', 'a', 'b', 'l', 'e'
+ (USB_DESC_TYPE_STRING << 8) + PRODUCT_DESC_LEN,
+ 'U', 'S','B', ' ', '3', '.', '0', ' ', 'D', 'e', 'b', 'u', 'g', ' ', 'C', 'a', 'b', 'l', 'e'
};
-UINT16 mSerialNumberStrDesc[] = {
+UINT16 mSerialNumberStrDesc[] = {
// String Descriptor Type + Length
- ( USB_DESC_TYPE_STRING << 8 ) + SERIAL_DESC_LEN,
+ (USB_DESC_TYPE_STRING << 8) + SERIAL_DESC_LEN,
'1'
};
@@ -39,14 +39,14 @@ UINT16 mSerialNumberStrDesc[] = {
@param[in] BitMask 32-bit mask
**/
VOID
-XhcSetR32Bit(
- IN OUT UINTN Register,
- IN UINT32 BitMask
+XhcSetR32Bit (
+ IN OUT UINTN Register,
+ IN UINT32 BitMask
)
{
- UINT32 RegisterValue;
+ UINT32 RegisterValue;
- RegisterValue = MmioRead32 (Register);
+ RegisterValue = MmioRead32 (Register);
RegisterValue |= (UINT32)(BitMask);
MmioWrite32 (Register, RegisterValue);
}
@@ -58,14 +58,14 @@ XhcSetR32Bit(
@param[in] BitMask 32-bit mask
**/
VOID
-XhcClearR32Bit(
- IN OUT UINTN Register,
- IN UINT32 BitMask
+XhcClearR32Bit (
+ IN OUT UINTN Register,
+ IN UINT32 BitMask
)
{
- UINT32 RegisterValue;
+ UINT32 RegisterValue;
- RegisterValue = MmioRead32 (Register);
+ RegisterValue = MmioRead32 (Register);
RegisterValue &= ~BitMask;
MmioWrite32 (Register, RegisterValue);
}
@@ -104,15 +104,15 @@ XhcWriteDebugReg (
**/
UINT32
XhcReadDebugReg (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN UINT32 Offset
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN UINT32 Offset
)
{
- UINT32 Data;
- EFI_PHYSICAL_ADDRESS DebugCapabilityBase;
+ UINT32 Data;
+ EFI_PHYSICAL_ADDRESS DebugCapabilityBase;
DebugCapabilityBase = Handle->DebugCapabilityBase;
- Data = MmioRead32 ((UINTN)(DebugCapabilityBase + Offset));
+ Data = MmioRead32 ((UINTN)(DebugCapabilityBase + Offset));
return Data;
}
@@ -127,12 +127,12 @@ XhcReadDebugReg (
**/
VOID
XhcSetDebugRegBit (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN UINT32 Offset,
- IN UINT32 Bit
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN UINT32 Offset,
+ IN UINT32 Bit
)
{
- UINT32 Data;
+ UINT32 Data;
Data = XhcReadDebugReg (Handle, Offset);
Data |= Bit;
@@ -149,15 +149,15 @@ XhcSetDebugRegBit (
**/
VOID
XhcClearDebugRegBit (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN UINT32 Offset,
- IN UINT32 Bit
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN UINT32 Offset,
+ IN UINT32 Bit
)
{
- UINT32 Data;
+ UINT32 Data;
Data = XhcReadDebugReg (Handle, Offset);
- Data &= ~Bit;
+ Data &= ~Bit;
XhcWriteDebugReg (Handle, Offset, Data);
}
@@ -172,26 +172,26 @@ ProgramXhciBaseAddress (
VOID
)
{
- UINT16 PciCmd;
- UINT32 Low;
- UINT32 High;
- EFI_PHYSICAL_ADDRESS XhciMmioBase;
-
- Low = PciRead32 (PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
- High = PciRead32 (PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4);
- XhciMmioBase = (EFI_PHYSICAL_ADDRESS) (LShiftU64 ((UINT64) High, 32) | Low);
+ UINT16 PciCmd;
+ UINT32 Low;
+ UINT32 High;
+ EFI_PHYSICAL_ADDRESS XhciMmioBase;
+
+ Low = PciRead32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
+ High = PciRead32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4);
+ XhciMmioBase = (EFI_PHYSICAL_ADDRESS)(LShiftU64 ((UINT64)High, 32) | Low);
XhciMmioBase &= XHCI_BASE_ADDRESS_64_BIT_MASK;
if ((XhciMmioBase == 0) || (XhciMmioBase == XHCI_BASE_ADDRESS_64_BIT_MASK)) {
- XhciMmioBase = PcdGet64(PcdUsbXhciMemorySpaceBase);
- PciWrite32(PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, XhciMmioBase & 0xFFFFFFFF);
- PciWrite32(PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4, (RShiftU64 (XhciMmioBase, 32) & 0xFFFFFFFF));
+ XhciMmioBase = PcdGet64 (PcdUsbXhciMemorySpaceBase);
+ PciWrite32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, XhciMmioBase & 0xFFFFFFFF);
+ PciWrite32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4, (RShiftU64 (XhciMmioBase, 32) & 0xFFFFFFFF));
}
- PciCmd = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET);
+ PciCmd = PciRead16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET);
if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) {
PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER;
- PciWrite16(PcdGet32(PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);
+ PciWrite16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);
}
return XhciMmioBase;
@@ -206,8 +206,8 @@ ProgramXhciBaseAddress (
**/
VOID
UpdateXhcResource (
- IN OUT USB3_DEBUG_PORT_HANDLE *Handle,
- IN EFI_PHYSICAL_ADDRESS XhciMmioBase
+ IN OUT USB3_DEBUG_PORT_HANDLE *Handle,
+ IN EFI_PHYSICAL_ADDRESS XhciMmioBase
)
{
if (Handle == NULL) {
@@ -234,18 +234,18 @@ UpdateXhcResource (
RETURN_STATUS
EFIAPI
CalculateUsbDebugPortMmioBase (
- USB3_DEBUG_PORT_HANDLE *Handle
- )
+ USB3_DEBUG_PORT_HANDLE *Handle
+ )
{
- UINT16 VendorId;
- UINT16 DeviceId;
- UINT8 ProgInterface;
- UINT8 SubClassCode;
- UINT8 BaseCode;
- BOOLEAN Flag;
- UINT32 Capability;
- EFI_PHYSICAL_ADDRESS CapabilityPointer;
- UINT8 CapLength;
+ UINT16 VendorId;
+ UINT16 DeviceId;
+ UINT8 ProgInterface;
+ UINT8 SubClassCode;
+ UINT8 BaseCode;
+ BOOLEAN Flag;
+ UINT32 Capability;
+ EFI_PHYSICAL_ADDRESS CapabilityPointer;
+ UINT8 CapLength;
if (Handle->Initialized != USB3DBG_UNINITIALIZED) {
if (Handle->Initialized == USB3DBG_NO_DBG_CAB) {
@@ -255,22 +255,22 @@ CalculateUsbDebugPortMmioBase (
}
}
- VendorId = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_VENDOR_ID_OFFSET);
- DeviceId = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_DEVICE_ID_OFFSET);
+ VendorId = PciRead16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_VENDOR_ID_OFFSET);
+ DeviceId = PciRead16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_DEVICE_ID_OFFSET);
if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {
goto Done;
}
- ProgInterface = PciRead8 (PcdGet32(PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET);
- SubClassCode = PciRead8 (PcdGet32(PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);
- BaseCode = PciRead8 (PcdGet32(PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);
+ ProgInterface = PciRead8 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET);
+ SubClassCode = PciRead8 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);
+ BaseCode = PciRead8 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);
if ((ProgInterface != PCI_IF_XHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {
goto Done;
}
- CapLength = MmioRead8 ((UINTN) Handle->XhciMmioBase);
+ CapLength = MmioRead8 ((UINTN)Handle->XhciMmioBase);
//
// Get capability pointer from HCCPARAMS at offset 0x10
@@ -280,21 +280,23 @@ CalculateUsbDebugPortMmioBase (
//
// Search XHCI debug capability
//
- Flag = FALSE;
+ Flag = FALSE;
Capability = MmioRead32 ((UINTN)CapabilityPointer);
while (TRUE) {
if ((Capability & XHC_CAPABILITY_ID_MASK) == PCI_CAPABILITY_ID_DEBUG_PORT) {
Flag = TRUE;
break;
}
+
if ((((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) & XHC_CAPABILITY_ID_MASK) == 0) {
//
// Reach the end of capability list, quit
//
break;
}
+
CapabilityPointer += ((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) * 4;
- Capability = MmioRead32 ((UINTN)CapabilityPointer);
+ Capability = MmioRead32 ((UINTN)CapabilityPointer);
}
if (!Flag) {
@@ -307,8 +309,8 @@ CalculateUsbDebugPortMmioBase (
Handle->DebugCapabilityBase = CapabilityPointer;
Handle->DebugCapabilityOffset = CapabilityPointer - Handle->XhciMmioBase;
Handle->XhciOpRegister = Handle->XhciMmioBase + CapLength;
- Handle->DebugSupport = TRUE;
- Handle->Initialized = USB3DBG_DBG_CAB;
+ Handle->DebugSupport = TRUE;
+ Handle->Initialized = USB3DBG_DBG_CAB;
return RETURN_SUCCESS;
Done:
@@ -331,12 +333,12 @@ Done:
**/
BOOLEAN
EFIAPI
-NeedReinitializeHardware(
- IN USB3_DEBUG_PORT_HANDLE *Handle
+NeedReinitializeHardware (
+ IN USB3_DEBUG_PORT_HANDLE *Handle
)
{
- BOOLEAN Result;
- volatile UINT32 Dcctrl;
+ BOOLEAN Result;
+ volatile UINT32 Dcctrl;
Result = FALSE;
@@ -347,7 +349,7 @@ NeedReinitializeHardware(
if ((Dcctrl & BIT0) == 0) {
Result = TRUE;
} else if (!Handle->Ready) {
- Handle->Ready = TRUE;
+ Handle->Ready = TRUE;
Handle->Initialized = USB3DBG_ENABLED;
}
@@ -363,8 +365,8 @@ NeedReinitializeHardware(
**/
EFI_STATUS
CreateEventRing (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- OUT EVENT_RING *EventRing
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ OUT EVENT_RING *EventRing
)
{
VOID *Buf;
@@ -377,13 +379,13 @@ CreateEventRing (
//
Buf = AllocateAlignBuffer (sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER);
ASSERT (Buf != NULL);
- ASSERT (((UINTN) Buf & 0x3F) == 0);
+ ASSERT (((UINTN)Buf & 0x3F) == 0);
ZeroMem (Buf, sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER);
- EventRing->EventRingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN) Buf;
+ EventRing->EventRingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN)Buf;
EventRing->TrbNumber = EVENT_RING_TRB_NUMBER;
- EventRing->EventRingDequeue = (EFI_PHYSICAL_ADDRESS)(UINTN) EventRing->EventRingSeg0;
- EventRing->EventRingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN) EventRing->EventRingSeg0;
+ EventRing->EventRingDequeue = (EFI_PHYSICAL_ADDRESS)(UINTN)EventRing->EventRingSeg0;
+ EventRing->EventRingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN)EventRing->EventRingSeg0;
//
// Software maintains an Event Ring Consumer Cycle State (CCS) bit, initializing it to '1'
@@ -396,11 +398,11 @@ CreateEventRing (
//
Buf = AllocateAlignBuffer (sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER);
ASSERT (Buf != NULL);
- ASSERT (((UINTN) Buf & 0x3F) == 0);
+ ASSERT (((UINTN)Buf & 0x3F) == 0);
ZeroMem (Buf, sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER);
- ERSTBase = (EVENT_RING_SEG_TABLE_ENTRY *) Buf;
- EventRing->ERSTBase = (EFI_PHYSICAL_ADDRESS)(UINTN) ERSTBase;
+ ERSTBase = (EVENT_RING_SEG_TABLE_ENTRY *)Buf;
+ EventRing->ERSTBase = (EFI_PHYSICAL_ADDRESS)(UINTN)ERSTBase;
//
// Fill Event Segment address
@@ -415,13 +417,13 @@ CreateEventRing (
XhcWriteDebugReg (
Handle,
XHC_DC_DCERDP,
- XHC_LOW_32BIT((UINT64)(UINTN)EventRing->EventRingDequeue)
+ XHC_LOW_32BIT ((UINT64)(UINTN)EventRing->EventRingDequeue)
);
XhcWriteDebugReg (
Handle,
XHC_DC_DCERDP + 4,
- XHC_HIGH_32BIT((UINT64)(UINTN)EventRing->EventRingDequeue)
+ XHC_HIGH_32BIT ((UINT64)(UINTN)EventRing->EventRingDequeue)
);
//
@@ -430,13 +432,13 @@ CreateEventRing (
XhcWriteDebugReg (
Handle,
XHC_DC_DCERSTBA,
- XHC_LOW_32BIT((UINT64)(UINTN)ERSTBase)
+ XHC_LOW_32BIT ((UINT64)(UINTN)ERSTBase)
);
XhcWriteDebugReg (
Handle,
XHC_DC_DCERSTBA + 4,
- XHC_HIGH_32BIT((UINT64)(UINTN)ERSTBase)
+ XHC_HIGH_32BIT ((UINT64)(UINTN)ERSTBase)
);
//
@@ -460,37 +462,37 @@ CreateEventRing (
**/
VOID
CreateTransferRing (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN UINT32 TrbNum,
- OUT TRANSFER_RING *TransferRing
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN UINT32 TrbNum,
+ OUT TRANSFER_RING *TransferRing
)
{
- VOID *Buf;
- LINK_TRB *EndTrb;
+ VOID *Buf;
+ LINK_TRB *EndTrb;
Buf = AllocateAlignBuffer (sizeof (TRB_TEMPLATE) * TrbNum);
ASSERT (Buf != NULL);
- ASSERT (((UINTN) Buf & 0xF) == 0);
+ ASSERT (((UINTN)Buf & 0xF) == 0);
ZeroMem (Buf, sizeof (TRB_TEMPLATE) * TrbNum);
- TransferRing->RingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN) Buf;
- TransferRing->TrbNumber = TrbNum;
- TransferRing->RingEnqueue = TransferRing->RingSeg0;
- TransferRing->RingDequeue = TransferRing->RingSeg0;
- TransferRing->RingPCS = 1;
+ TransferRing->RingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN)Buf;
+ TransferRing->TrbNumber = TrbNum;
+ TransferRing->RingEnqueue = TransferRing->RingSeg0;
+ TransferRing->RingDequeue = TransferRing->RingSeg0;
+ TransferRing->RingPCS = 1;
//
// 4.9.2 Transfer Ring Management
// To form a ring (or circular queue) a Link TRB may be inserted at the end of a ring to
// point to the first TRB in the ring.
//
- EndTrb = (LINK_TRB *) ((UINTN)Buf + sizeof (TRB_TEMPLATE) * (TrbNum - 1));
+ EndTrb = (LINK_TRB *)((UINTN)Buf + sizeof (TRB_TEMPLATE) * (TrbNum - 1));
EndTrb->Type = TRB_TYPE_LINK;
EndTrb->PtrLo = XHC_LOW_32BIT (Buf);
EndTrb->PtrHi = XHC_HIGH_32BIT (Buf);
//
// Toggle Cycle (TC). When set to '1', the xHC shall toggle its interpretation of the Cycle bit.
//
- EndTrb->TC = 1;
+ EndTrb->TC = 1;
//
// Set Cycle bit as other TRB PCS init value
//
@@ -508,26 +510,26 @@ CreateTransferRing (
**/
EFI_STATUS
CreateDebugCapabilityContext (
- IN USB3_DEBUG_PORT_HANDLE *Handle
+ IN USB3_DEBUG_PORT_HANDLE *Handle
)
{
- VOID *Buf;
- XHC_DC_CONTEXT *DebugCapabilityContext;
- UINT8 *String0Desc;
- UINT8 *ManufacturerStrDesc;
- UINT8 *ProductStrDesc;
- UINT8 *SerialNumberStrDesc;
+ VOID *Buf;
+ XHC_DC_CONTEXT *DebugCapabilityContext;
+ UINT8 *String0Desc;
+ UINT8 *ManufacturerStrDesc;
+ UINT8 *ProductStrDesc;
+ UINT8 *SerialNumberStrDesc;
//
// Allocate debug device context
//
Buf = AllocateAlignBuffer (sizeof (XHC_DC_CONTEXT));
ASSERT (Buf != NULL);
- ASSERT (((UINTN) Buf & 0xF) == 0);
+ ASSERT (((UINTN)Buf & 0xF) == 0);
ZeroMem (Buf, sizeof (XHC_DC_CONTEXT));
- DebugCapabilityContext = (XHC_DC_CONTEXT *)(UINTN) Buf;
- Handle->DebugCapabilityContext = (EFI_PHYSICAL_ADDRESS)(UINTN) DebugCapabilityContext;
+ DebugCapabilityContext = (XHC_DC_CONTEXT *)(UINTN)Buf;
+ Handle->DebugCapabilityContext = (EFI_PHYSICAL_ADDRESS)(UINTN)DebugCapabilityContext;
//
// Initialize DbcInfoContext.
@@ -556,7 +558,7 @@ CreateDebugCapabilityContext (
//
// Update string descriptor address
//
- String0Desc = (UINT8 *) AllocateAlignBuffer (STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN);
+ String0Desc = (UINT8 *)AllocateAlignBuffer (STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN);
ASSERT (String0Desc != NULL);
ZeroMem (String0Desc, STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN);
CopyMem (String0Desc, mString0Desc, STRING0_DESC_LEN);
@@ -596,12 +598,12 @@ CreateDebugCapabilityContext (
XhcWriteDebugReg (
Handle,
XHC_DC_DCCP,
- XHC_LOW_32BIT((UINT64)(UINTN)DebugCapabilityContext)
+ XHC_LOW_32BIT ((UINT64)(UINTN)DebugCapabilityContext)
);
XhcWriteDebugReg (
Handle,
XHC_DC_DCCP + 4,
- XHC_HIGH_32BIT((UINT64)(UINTN)DebugCapabilityContext)
+ XHC_HIGH_32BIT ((UINT64)(UINTN)DebugCapabilityContext)
);
return EFI_SUCCESS;
}
@@ -614,11 +616,11 @@ CreateDebugCapabilityContext (
**/
VOID
XhcDetectDebugCapabilityReady (
- IN USB3_DEBUG_PORT_HANDLE *Handle
+ IN USB3_DEBUG_PORT_HANDLE *Handle
)
{
- UINT64 TimeOut;
- volatile UINT32 Dcctrl;
+ UINT64 TimeOut;
+ volatile UINT32 Dcctrl;
TimeOut = 1;
if (Handle->Initialized == USB3DBG_DBG_CAB) {
@@ -642,6 +644,7 @@ XhcDetectDebugCapabilityReady (
Handle->Ready = TRUE;
break;
}
+
MicroSecondDelay (XHC_POLL_DELAY);
TimeOut--;
} while (TimeOut != 0);
@@ -659,27 +662,28 @@ XhcDetectDebugCapabilityReady (
RETURN_STATUS
EFIAPI
InitializeUsbDebugHardware (
- IN USB3_DEBUG_PORT_HANDLE *Handle
+ IN USB3_DEBUG_PORT_HANDLE *Handle
)
{
- RETURN_STATUS Status;
- UINT8 *Buffer;
- UINTN Index;
- UINT8 TotalUsb3Port;
- EFI_PHYSICAL_ADDRESS XhciOpRegister;
- UINT32 Dcddi1;
+ RETURN_STATUS Status;
+ UINT8 *Buffer;
+ UINTN Index;
+ UINT8 TotalUsb3Port;
+ EFI_PHYSICAL_ADDRESS XhciOpRegister;
+ UINT32 Dcddi1;
XhciOpRegister = Handle->XhciOpRegister;
- TotalUsb3Port = MmioRead32 (((UINTN) Handle->XhciMmioBase + XHC_HCSPARAMS1_OFFSET)) >> 24;
+ TotalUsb3Port = MmioRead32 (((UINTN)Handle->XhciMmioBase + XHC_HCSPARAMS1_OFFSET)) >> 24;
if (Handle->Initialized == USB3DBG_NOT_ENABLED) {
- Dcddi1 = XhcReadDebugReg (Handle,XHC_DC_DCDDI1);
+ Dcddi1 = XhcReadDebugReg (Handle, XHC_DC_DCDDI1);
if (Dcddi1 != (UINT32)((XHCI_DEBUG_DEVICE_VENDOR_ID << 16) | XHCI_DEBUG_DEVICE_PROTOCOL)) {
//
// The debug capability has been reset by other code, return device error.
//
return EFI_DEVICE_ERROR;
}
+
//
// If XHCI supports debug capability, hardware resource has been allocated,
// but it has not been enabled, try to enable again.
@@ -718,8 +722,8 @@ InitializeUsbDebugHardware (
//
// Construct the buffer for read, poll and write.
//
- Handle->UrbIn.Data = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer;
- Handle->Data = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
+ Handle->UrbIn.Data = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
+ Handle->Data = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
Handle->UrbOut.Data = Handle->UrbIn.Data + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2;
//
@@ -739,16 +743,16 @@ InitializeUsbDebugHardware (
// Init DCDDI1 and DCDDI2
//
XhcWriteDebugReg (
- Handle,
- XHC_DC_DCDDI1,
- (UINT32)((XHCI_DEBUG_DEVICE_VENDOR_ID << 16) | XHCI_DEBUG_DEVICE_PROTOCOL)
- );
+ Handle,
+ XHC_DC_DCDDI1,
+ (UINT32)((XHCI_DEBUG_DEVICE_VENDOR_ID << 16) | XHCI_DEBUG_DEVICE_PROTOCOL)
+ );
XhcWriteDebugReg (
- Handle,
- XHC_DC_DCDDI2,
- (UINT32)((XHCI_DEBUG_DEVICE_REVISION << 16) | XHCI_DEBUG_DEVICE_PRODUCT_ID)
- );
+ Handle,
+ XHC_DC_DCDDI2,
+ (UINT32)((XHCI_DEBUG_DEVICE_REVISION << 16) | XHCI_DEBUG_DEVICE_PRODUCT_ID)
+ );
Enable:
if ((Handle->Initialized == USB3DBG_NOT_ENABLED) && (!Handle->ChangePortPower)) {
@@ -775,7 +779,7 @@ Enable:
Status = RETURN_SUCCESS;
if (!Handle->Ready) {
Handle->Initialized = USB3DBG_NOT_ENABLED;
- Status = RETURN_NOT_READY;
+ Status = RETURN_NOT_READY;
} else {
Handle->Initialized = USB3DBG_ENABLED;
}
@@ -791,16 +795,16 @@ Enable:
**/
VOID
DiscoverInitializeUsbDebugPort (
- IN USB3_DEBUG_PORT_HANDLE *Handle
+ IN USB3_DEBUG_PORT_HANDLE *Handle
)
{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS XhciMmioBase;
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS XhciMmioBase;
//
// Read 64-bit MMIO base address
//
- XhciMmioBase = ProgramXhciBaseAddress ();
+ XhciMmioBase = ProgramXhciBaseAddress ();
Handle->XhciMmioBase = XhciMmioBase;
Status = CalculateUsbDebugPortMmioBase (Handle);
@@ -820,14 +824,14 @@ DiscoverInitializeUsbDebugPort (
**/
VOID
SetUsb3DebugPortInstance (
- IN USB3_DEBUG_PORT_HANDLE *Instance
+ IN USB3_DEBUG_PORT_HANDLE *Instance
)
{
- EFI_PHYSICAL_ADDRESS *AddrPtr;
+ EFI_PHYSICAL_ADDRESS *AddrPtr;
AddrPtr = GetUsb3DebugPortInstanceAddrPtr ();
ASSERT (AddrPtr != NULL);
- *AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance;
+ *AddrPtr = (EFI_PHYSICAL_ADDRESS)(UINTN)Instance;
}
/**
@@ -839,13 +843,13 @@ GetUsb3DebugPortInstance (
VOID
)
{
- EFI_PHYSICAL_ADDRESS *AddrPtr;
- USB3_DEBUG_PORT_HANDLE *Instance;
+ EFI_PHYSICAL_ADDRESS *AddrPtr;
+ USB3_DEBUG_PORT_HANDLE *Instance;
AddrPtr = GetUsb3DebugPortInstanceAddrPtr ();
ASSERT (AddrPtr != NULL);
- Instance = (USB3_DEBUG_PORT_HANDLE *) (UINTN) *AddrPtr;
+ Instance = (USB3_DEBUG_PORT_HANDLE *)(UINTN)*AddrPtr;
return Instance;
}
@@ -870,17 +874,17 @@ GetUsb3DebugPortInstance (
UINTN
EFIAPI
DebugPortReadBuffer (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes,
- IN UINTN Timeout
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes,
+ IN UINTN Timeout
)
{
- USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
- UINT8 Index;
- UINT8 *Data;
+ USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
+ UINT8 Index;
+ UINT8 *Data;
- if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {
+ if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) {
return 0;
}
@@ -889,11 +893,12 @@ DebugPortReadBuffer (
// If Handle is not NULL, use it and set the instance.
//
if (Handle != NULL) {
- UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle;
+ UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
SetUsb3DebugPortInstance (UsbDebugPortHandle);
} else {
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
}
+
if (UsbDebugPortHandle == NULL) {
return 0;
}
@@ -922,8 +927,10 @@ DebugPortReadBuffer (
if ((Index + 1) >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
return 0;
}
+
Data[Index] = Data[Index + 1];
}
+
UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);
return 1;
}
@@ -949,16 +956,16 @@ DebugPortReadBuffer (
UINTN
EFIAPI
DebugPortWriteBuffer (
- IN DEBUG_PORT_HANDLE Handle,
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes
+ IN DEBUG_PORT_HANDLE Handle,
+ IN UINT8 *Buffer,
+ IN UINTN NumberOfBytes
)
{
- USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
- UINTN Sent;
- UINTN Total;
+ USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
+ UINTN Sent;
+ UINTN Total;
- if (NumberOfBytes == 0 || Buffer == NULL) {
+ if ((NumberOfBytes == 0) || (Buffer == NULL)) {
return 0;
}
@@ -970,11 +977,12 @@ DebugPortWriteBuffer (
// If Handle is not NULL, use it and set the instance.
//
if (Handle != NULL) {
- UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle;
+ UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
SetUsb3DebugPortInstance (UsbDebugPortHandle);
} else {
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
}
+
if (UsbDebugPortHandle == NULL) {
return 0;
}
@@ -1001,6 +1009,7 @@ DebugPortWriteBuffer (
} else {
Sent = (UINT8)(NumberOfBytes - Total);
}
+
XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataOut, Buffer + Total, &Sent, DATA_TRANSFER_WRITE_TIMEOUT);
Total += Sent;
}
@@ -1024,22 +1033,23 @@ DebugPortWriteBuffer (
BOOLEAN
EFIAPI
DebugPortPollBuffer (
- IN DEBUG_PORT_HANDLE Handle
+ IN DEBUG_PORT_HANDLE Handle
)
{
- USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
- UINTN Length;
+ USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
+ UINTN Length;
//
// If Handle is NULL, get own instance.
// If Handle is not NULL, use it and set the instance.
//
if (Handle != NULL) {
- UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle;
+ UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
SetUsb3DebugPortInstance (UsbDebugPortHandle);
} else {
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
}
+
if (UsbDebugPortHandle == NULL) {
return FALSE;
}
@@ -1079,7 +1089,7 @@ DebugPortPollBuffer (
//
// Store data into internal buffer for use later
//
- UsbDebugPortHandle->DataCount = (UINT8) Length;
+ UsbDebugPortHandle->DataCount = (UINT8)Length;
return TRUE;
}
@@ -1114,17 +1124,18 @@ DebugPortInitialize (
IN DEBUG_PORT_CONTINUE Function
)
{
- USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
+ USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
//
// Validate the PCD PcdDebugPortHandleBufferSize value
//
ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB3_DEBUG_PORT_HANDLE));
- if (Function == NULL && Context != NULL) {
- SetUsb3DebugPortInstance ((USB3_DEBUG_PORT_HANDLE *) Context);
- return (DEBUG_PORT_HANDLE) Context;
+ if ((Function == NULL) && (Context != NULL)) {
+ SetUsb3DebugPortInstance ((USB3_DEBUG_PORT_HANDLE *)Context);
+ return (DEBUG_PORT_HANDLE)Context;
}
+
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
if (UsbDebugPortHandle == NULL) {
return NULL;
@@ -1133,8 +1144,8 @@ DebugPortInitialize (
DiscoverInitializeUsbDebugPort (UsbDebugPortHandle);
if (Function != NULL) {
- Function (Context, (DEBUG_PORT_HANDLE) UsbDebugPortHandle);
+ Function (Context, (DEBUG_PORT_HANDLE)UsbDebugPortHandle);
}
- return (DEBUG_PORT_HANDLE) UsbDebugPortHandle;
+ return (DEBUG_PORT_HANDLE)UsbDebugPortHandle;
}
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c
index d2ff2d52a7..4490526273 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.c
@@ -15,12 +15,12 @@
#include <Protocol/DxeSmmReadyToLock.h>
#include "DebugCommunicationLibUsb3Internal.h"
-GUID gUsb3DbgGuid = USB3_DBG_GUID;
+GUID gUsb3DbgGuid = USB3_DBG_GUID;
-USB3_DEBUG_PORT_HANDLE mUsb3Instance = {USB3DBG_UNINITIALIZED};
-EFI_PHYSICAL_ADDRESS mUsb3InstanceAddr = 0;
-EFI_PHYSICAL_ADDRESS *mUsb3InstanceAddrPtr = NULL;
-EFI_PCI_IO_PROTOCOL *mUsb3PciIo = NULL;
+USB3_DEBUG_PORT_HANDLE mUsb3Instance = { USB3DBG_UNINITIALIZED };
+EFI_PHYSICAL_ADDRESS mUsb3InstanceAddr = 0;
+EFI_PHYSICAL_ADDRESS *mUsb3InstanceAddrPtr = NULL;
+EFI_PCI_IO_PROTOCOL *mUsb3PciIo = NULL;
/**
Creates a named event that can be signaled.
@@ -71,7 +71,7 @@ Usb3NamedEventListen (
// Register for an installation of protocol interface
//
Status = gBS->RegisterProtocolNotify (
- (EFI_GUID *) Name,
+ (EFI_GUID *)Name,
*Event,
&RegistrationLocal
);
@@ -90,27 +90,27 @@ Usb3NamedEventListen (
**/
VOID
Usb3MapOneDmaBuffer (
- IN EFI_PCI_IO_PROTOCOL *PciIo,
- IN EFI_PHYSICAL_ADDRESS Address,
- IN UINTN NumberOfBytes
+ IN EFI_PCI_IO_PROTOCOL *PciIo,
+ IN EFI_PHYSICAL_ADDRESS Address,
+ IN UINTN NumberOfBytes
)
{
- EFI_STATUS Status;
- VOID *HostAddress;
- EFI_PHYSICAL_ADDRESS DeviceAddress;
- VOID *Mapping;
-
- HostAddress = (VOID *) (UINTN) Address;
- Status = PciIo->Map (
- PciIo,
- EfiPciIoOperationBusMasterCommonBuffer,
- HostAddress,
- &NumberOfBytes,
- &DeviceAddress,
- &Mapping
- );
+ EFI_STATUS Status;
+ VOID *HostAddress;
+ EFI_PHYSICAL_ADDRESS DeviceAddress;
+ VOID *Mapping;
+
+ HostAddress = (VOID *)(UINTN)Address;
+ Status = PciIo->Map (
+ PciIo,
+ EfiPciIoOperationBusMasterCommonBuffer,
+ HostAddress,
+ &NumberOfBytes,
+ &DeviceAddress,
+ &Mapping
+ );
ASSERT_EFI_ERROR (Status);
- ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress));
+ ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress));
}
/**
@@ -122,8 +122,8 @@ Usb3MapOneDmaBuffer (
**/
VOID
Usb3MapDmaBuffers (
- IN USB3_DEBUG_PORT_HANDLE *Instance,
- IN EFI_PCI_IO_PROTOCOL *PciIo
+ IN USB3_DEBUG_PORT_HANDLE *Instance,
+ IN EFI_PCI_IO_PROTOCOL *PciIo
)
{
Usb3MapOneDmaBuffer (
@@ -164,7 +164,7 @@ Usb3MapDmaBuffers (
Usb3MapOneDmaBuffer (
PciIo,
- ((XHC_DC_CONTEXT *) (UINTN) Instance->DebugCapabilityContext)->DbcInfoContext.String0DescAddress,
+ ((XHC_DC_CONTEXT *)(UINTN)Instance->DebugCapabilityContext)->DbcInfoContext.String0DescAddress,
STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN
);
}
@@ -180,11 +180,11 @@ Usb3MapDmaBuffers (
VOID
EFIAPI
Usb3DxeSmmReadyToLockNotify (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- USB3_DEBUG_PORT_HANDLE *Instance;
+ USB3_DEBUG_PORT_HANDLE *Instance;
DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));
@@ -221,15 +221,15 @@ Usb3GetIoMmu (
VOID
)
{
- EFI_STATUS Status;
- EDKII_IOMMU_PROTOCOL *IoMmu;
+ EFI_STATUS Status;
+ EDKII_IOMMU_PROTOCOL *IoMmu;
- IoMmu = NULL;
+ IoMmu = NULL;
Status = gBS->LocateProtocol (
- &gEdkiiIoMmuProtocolGuid,
- NULL,
- (VOID **) &IoMmu
- );
+ &gEdkiiIoMmuProtocolGuid,
+ NULL,
+ (VOID **)&IoMmu
+ );
if (!EFI_ERROR (Status) && (IoMmu != NULL)) {
return IoMmu;
}
@@ -248,22 +248,22 @@ Usb3GetIoMmu (
VOID
EFIAPI
Usb3PciIoNotify (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_STATUS Status;
- UINTN PciIoHandleCount;
- EFI_HANDLE *PciIoHandleBuffer;
- UINTN Index;
- EFI_PCI_IO_PROTOCOL *PciIo;
- UINTN PciSegment;
- UINTN PciBusNumber;
- UINTN PciDeviceNumber;
- UINTN PciFunctionNumber;
- UINT32 PciAddress;
- USB3_DEBUG_PORT_HANDLE *Instance;
- EFI_EVENT SmmReadyToLockEvent;
+ EFI_STATUS Status;
+ UINTN PciIoHandleCount;
+ EFI_HANDLE *PciIoHandleBuffer;
+ UINTN Index;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ UINTN PciSegment;
+ UINTN PciBusNumber;
+ UINTN PciDeviceNumber;
+ UINTN PciFunctionNumber;
+ UINT32 PciAddress;
+ USB3_DEBUG_PORT_HANDLE *Instance;
+ EFI_EVENT SmmReadyToLockEvent;
Status = gBS->LocateHandleBuffer (
ByProtocol,
@@ -274,18 +274,19 @@ Usb3PciIoNotify (
);
if (!EFI_ERROR (Status) &&
(PciIoHandleBuffer != NULL) &&
- (PciIoHandleCount != 0)) {
+ (PciIoHandleCount != 0))
+ {
for (Index = 0; Index < PciIoHandleCount; Index++) {
Status = gBS->HandleProtocol (
PciIoHandleBuffer[Index],
&gEfiPciIoProtocolGuid,
- (VOID **) &PciIo
+ (VOID **)&PciIo
);
ASSERT_EFI_ERROR (Status);
Status = PciIo->GetLocation (PciIo, &PciSegment, &PciBusNumber, &PciDeviceNumber, &PciFunctionNumber);
ASSERT_EFI_ERROR (Status);
- PciAddress = (UINT32) ((PciBusNumber << 20) | (PciDeviceNumber << 15) | (PciFunctionNumber << 12));
- if (PciAddress == PcdGet32(PcdUsbXhciPciAddress)) {
+ PciAddress = (UINT32)((PciBusNumber << 20) | (PciDeviceNumber << 15) | (PciFunctionNumber << 12));
+ if (PciAddress == PcdGet32 (PcdUsbXhciPciAddress)) {
//
// Found the PciIo for USB3 debug port.
//
@@ -309,6 +310,7 @@ Usb3PciIoNotify (
}
}
}
+
gBS->CloseEvent (Event);
break;
}
@@ -331,9 +333,10 @@ GetUsb3DebugPortInstanceAddrPtr (
//
// Use the local variables temporarily.
//
- mUsb3InstanceAddr = (EFI_PHYSICAL_ADDRESS) (UINTN) &mUsb3Instance;
+ mUsb3InstanceAddr = (EFI_PHYSICAL_ADDRESS)(UINTN)&mUsb3Instance;
mUsb3InstanceAddrPtr = &mUsb3InstanceAddr;
}
+
return mUsb3InstanceAddrPtr;
}
@@ -355,29 +358,30 @@ GetUsb3DebugPortInstanceAddrPtr (
**/
EFI_STATUS
Usb3AllocateDmaBuffer (
- IN EFI_PCI_IO_PROTOCOL *PciIo,
- IN UINTN Pages,
- OUT VOID **Address
+ IN EFI_PCI_IO_PROTOCOL *PciIo,
+ IN UINTN Pages,
+ OUT VOID **Address
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
*Address = NULL;
- Status = PciIo->AllocateBuffer (
- PciIo,
- AllocateAnyPages,
- EfiRuntimeServicesData,
- Pages,
- Address,
- 0
- );
+ Status = PciIo->AllocateBuffer (
+ PciIo,
+ AllocateAnyPages,
+ EfiRuntimeServicesData,
+ Pages,
+ Address,
+ 0
+ );
if (!EFI_ERROR (Status)) {
Usb3MapOneDmaBuffer (
PciIo,
- (EFI_PHYSICAL_ADDRESS) (UINTN) *Address,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)*Address,
EFI_PAGES_TO_SIZE (Pages)
);
}
+
return Status;
}
@@ -389,14 +393,14 @@ Usb3AllocateDmaBuffer (
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
-VOID*
+VOID *
AllocateAlignBuffer (
- IN UINTN BufferSize
+ IN UINTN BufferSize
)
{
- EFI_PHYSICAL_ADDRESS TmpAddr;
- EFI_STATUS Status;
- VOID *Buf;
+ EFI_PHYSICAL_ADDRESS TmpAddr;
+ EFI_STATUS Status;
+ VOID *Buf;
Buf = NULL;
@@ -409,14 +413,14 @@ AllocateAlignBuffer (
);
} else {
TmpAddr = 0xFFFFFFFF;
- Status = gBS->AllocatePages (
- AllocateMaxAddress,
- EfiACPIMemoryNVS,
- EFI_SIZE_TO_PAGES (BufferSize),
- &TmpAddr
- );
+ Status = gBS->AllocatePages (
+ AllocateMaxAddress,
+ EfiACPIMemoryNVS,
+ EFI_SIZE_TO_PAGES (BufferSize),
+ &TmpAddr
+ );
if (!EFI_ERROR (Status)) {
- Buf = (VOID *) (UINTN) TmpAddr;
+ Buf = (VOID *)(UINTN)TmpAddr;
}
}
}
@@ -440,34 +444,34 @@ DebugCommunicationUsb3DxeConstructor (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_PHYSICAL_ADDRESS *AddrPtr;
- USB3_DEBUG_PORT_HANDLE *Instance;
- EFI_PHYSICAL_ADDRESS Address;
- EFI_STATUS Status;
- EFI_EVENT Event;
+ EFI_PHYSICAL_ADDRESS *AddrPtr;
+ USB3_DEBUG_PORT_HANDLE *Instance;
+ EFI_PHYSICAL_ADDRESS Address;
+ EFI_STATUS Status;
+ EFI_EVENT Event;
- Status = EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **) &AddrPtr);
+ Status = EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **)&AddrPtr);
if (EFI_ERROR (Status) || (AddrPtr == NULL)) {
//
// Instead of using local variables, install system configuration table for
// the local instance and the buffer to save instance address pointer.
//
Address = SIZE_4GB;
- Status = gBS->AllocatePages (
- AllocateMaxAddress,
- EfiACPIMemoryNVS,
- EFI_SIZE_TO_PAGES (sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE)),
- &Address
- );
+ Status = gBS->AllocatePages (
+ AllocateMaxAddress,
+ EfiACPIMemoryNVS,
+ EFI_SIZE_TO_PAGES (sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE)),
+ &Address
+ );
if (EFI_ERROR (Status)) {
return Status;
}
- AddrPtr = (EFI_PHYSICAL_ADDRESS *) (UINTN) Address;
+ AddrPtr = (EFI_PHYSICAL_ADDRESS *)(UINTN)Address;
ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE));
- Instance = (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1);
+ Instance = (USB3_DEBUG_PORT_HANDLE *)(AddrPtr + 1);
CopyMem (Instance, &mUsb3Instance, sizeof (USB3_DEBUG_PORT_HANDLE));
- *AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance;
+ *AddrPtr = (EFI_PHYSICAL_ADDRESS)(UINTN)Instance;
Status = gBS->InstallConfigurationTable (&gUsb3DbgGuid, AddrPtr);
if (EFI_ERROR (Status)) {
@@ -478,6 +482,7 @@ DebugCommunicationUsb3DxeConstructor (
if (mUsb3InstanceAddrPtr != NULL) {
*AddrPtr = *mUsb3InstanceAddrPtr;
}
+
mUsb3InstanceAddrPtr = AddrPtr;
Instance = GetUsb3DebugPortInstance ();
@@ -491,7 +496,7 @@ DebugCommunicationUsb3DxeConstructor (
&Event
);
if (!EFI_ERROR (Status)) {
- Instance->PciIoEvent = (EFI_PHYSICAL_ADDRESS) (UINTN) Event;
+ Instance->PciIoEvent = (EFI_PHYSICAL_ADDRESS)(UINTN)Event;
}
}
@@ -514,7 +519,7 @@ DebugCommunicationUsb3DxeDestructor (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- USB3_DEBUG_PORT_HANDLE *Instance;
+ USB3_DEBUG_PORT_HANDLE *Instance;
Instance = GetUsb3DebugPortInstance ();
ASSERT (Instance != NULL);
@@ -523,9 +528,9 @@ DebugCommunicationUsb3DxeDestructor (
//
// Close the event created.
//
- gBS->CloseEvent ((EFI_EVENT) (UINTN) Instance->PciIoEvent);
+ gBS->CloseEvent ((EFI_EVENT)(UINTN)Instance->PciIoEvent);
Instance->PciIoEvent = 0;
}
+
return EFI_SUCCESS;
}
-
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
index df50220f33..c73233ea49 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
@@ -36,101 +36,101 @@
//
// The state machine of usb debug port
//
-#define USB3DBG_NO_DBG_CAB 0 // The XHCI host controller does not support debug capability
-#define USB3DBG_DBG_CAB 1 // The XHCI host controller supports debug capability
-#define USB3DBG_ENABLED 2 // The XHCI debug device is enabled
-#define USB3DBG_NOT_ENABLED 4 // The XHCI debug device is not enabled
-#define USB3DBG_UNINITIALIZED 255 // The XHCI debug device is uninitialized
+#define USB3DBG_NO_DBG_CAB 0 // The XHCI host controller does not support debug capability
+#define USB3DBG_DBG_CAB 1 // The XHCI host controller supports debug capability
+#define USB3DBG_ENABLED 2 // The XHCI debug device is enabled
+#define USB3DBG_NOT_ENABLED 4 // The XHCI debug device is not enabled
+#define USB3DBG_UNINITIALIZED 255 // The XHCI debug device is uninitialized
-#define USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE 0x08
+#define USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE 0x08
//
// MaxPacketSize for DbC Endpoint Descriptor IN and OUT
//
-#define XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE 0x400
+#define XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE 0x400
#define XHCI_DEBUG_DEVICE_VENDOR_ID 0x0525
#define XHCI_DEBUG_DEVICE_PRODUCT_ID 0x127A
#define XHCI_DEBUG_DEVICE_PROTOCOL 0xFF
#define XHCI_DEBUG_DEVICE_REVISION 0x00
-#define XHCI_BASE_ADDRESS_64_BIT_MASK 0xFFFFFFFFFFFF0000ULL
-#define XHCI_BASE_ADDRESS_32_BIT_MASK 0xFFFF0000
+#define XHCI_BASE_ADDRESS_64_BIT_MASK 0xFFFFFFFFFFFF0000ULL
+#define XHCI_BASE_ADDRESS_32_BIT_MASK 0xFFFF0000
#define PCI_CAPABILITY_ID_DEBUG_PORT 0x0A
#define XHC_HCCPARAMS_OFFSET 0x10
#define XHC_CAPABILITY_ID_MASK 0xFF
#define XHC_NEXT_CAPABILITY_MASK 0xFF00
-#define XHC_HCSPARAMS1_OFFSET 0x4 // Structural Parameters 1
-#define XHC_USBCMD_OFFSET 0x0 // USB Command Register Offset
-#define XHC_USBSTS_OFFSET 0x4 // USB Status Register Offset
-#define XHC_PORTSC_OFFSET 0x400 // Port Status and Control Register Offset
+#define XHC_HCSPARAMS1_OFFSET 0x4 // Structural Parameters 1
+#define XHC_USBCMD_OFFSET 0x0 // USB Command Register Offset
+#define XHC_USBSTS_OFFSET 0x4 // USB Status Register Offset
+#define XHC_PORTSC_OFFSET 0x400 // Port Status and Control Register Offset
-#define XHC_USBCMD_RUN BIT0 // Run/Stop
-#define XHC_USBCMD_RESET BIT1 // Host Controller Reset
+#define XHC_USBCMD_RUN BIT0 // Run/Stop
+#define XHC_USBCMD_RESET BIT1 // Host Controller Reset
-#define XHC_USBSTS_HALT BIT0
+#define XHC_USBSTS_HALT BIT0
//
// Indicate the timeout when data is transferred in microsecond. 0 means infinite timeout.
//
-#define DATA_TRANSFER_WRITE_TIMEOUT 0
-#define DATA_TRANSFER_READ_TIMEOUT 50000
-#define DATA_TRANSFER_POLL_TIMEOUT 1000
-#define XHC_DEBUG_PORT_1_MILLISECOND 1000
+#define DATA_TRANSFER_WRITE_TIMEOUT 0
+#define DATA_TRANSFER_READ_TIMEOUT 50000
+#define DATA_TRANSFER_POLL_TIMEOUT 1000
+#define XHC_DEBUG_PORT_1_MILLISECOND 1000
//
// XHCI port power off/on delay
//
-#define XHC_DEBUG_PORT_ON_OFF_DELAY 100000
+#define XHC_DEBUG_PORT_ON_OFF_DELAY 100000
//
// USB debug device string descriptor (header size + unicode string length)
//
-#define STRING0_DESC_LEN 4
-#define MANU_DESC_LEN 12
-#define PRODUCT_DESC_LEN 40
-#define SERIAL_DESC_LEN 4
+#define STRING0_DESC_LEN 4
+#define MANU_DESC_LEN 12
+#define PRODUCT_DESC_LEN 40
+#define SERIAL_DESC_LEN 4
//
// Debug Capability Register Offset
//
-#define XHC_DC_DCID 0x0
-#define XHC_DC_DCDB 0x4
-#define XHC_DC_DCERSTSZ 0x8
-#define XHC_DC_DCERSTBA 0x10
-#define XHC_DC_DCERDP 0x18
-#define XHC_DC_DCCTRL 0x20
-#define XHC_DC_DCST 0x24
-#define XHC_DC_DCPORTSC 0x28
-#define XHC_DC_DCCP 0x30
-#define XHC_DC_DCDDI1 0x38
-#define XHC_DC_DCDDI2 0x3C
+#define XHC_DC_DCID 0x0
+#define XHC_DC_DCDB 0x4
+#define XHC_DC_DCERSTSZ 0x8
+#define XHC_DC_DCERSTBA 0x10
+#define XHC_DC_DCERDP 0x18
+#define XHC_DC_DCCTRL 0x20
+#define XHC_DC_DCST 0x24
+#define XHC_DC_DCPORTSC 0x28
+#define XHC_DC_DCCP 0x30
+#define XHC_DC_DCDDI1 0x38
+#define XHC_DC_DCDDI2 0x3C
-#define TRB_TYPE_LINK 6
+#define TRB_TYPE_LINK 6
-#define ERST_NUMBER 0x01
-#define TR_RING_TRB_NUMBER 0x100
-#define EVENT_RING_TRB_NUMBER 0x200
+#define ERST_NUMBER 0x01
+#define TR_RING_TRB_NUMBER 0x100
+#define EVENT_RING_TRB_NUMBER 0x200
-#define ED_BULK_OUT 2
-#define ED_BULK_IN 6
+#define ED_BULK_OUT 2
+#define ED_BULK_IN 6
-#define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0xFFFFFFFF))
-#define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINT64)(UINTN)(Addr64), 32) & 0xFFFFFFFF))
-#define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
+#define XHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0xFFFFFFFF))
+#define XHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINT64)(UINTN)(Addr64), 32) & 0xFFFFFFFF))
+#define XHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
//
// Endpoint Type (EP Type).
//
-#define ED_NOT_VALID 0
-#define ED_ISOCH_OUT 1
-#define ED_BULK_OUT 2
-#define ED_INTERRUPT_OUT 3
-#define ED_CONTROL_BIDIR 4
-#define ED_ISOCH_IN 5
-#define ED_BULK_IN 6
-#define ED_INTERRUPT_IN 7
+#define ED_NOT_VALID 0
+#define ED_ISOCH_OUT 1
+#define ED_BULK_OUT 2
+#define ED_INTERRUPT_OUT 3
+#define ED_CONTROL_BIDIR 4
+#define ED_ISOCH_IN 5
+#define ED_BULK_IN 6
+#define ED_INTERRUPT_IN 7
//
// 6.4.5 TRB Completion Codes
@@ -147,67 +147,67 @@
//
// 6.4.6 TRB Types
//
-#define TRB_TYPE_NORMAL 1
-#define TRB_TYPE_SETUP_STAGE 2
-#define TRB_TYPE_DATA_STAGE 3
-#define TRB_TYPE_STATUS_STAGE 4
-#define TRB_TYPE_ISOCH 5
-#define TRB_TYPE_LINK 6
-#define TRB_TYPE_EVENT_DATA 7
-#define TRB_TYPE_NO_OP 8
-#define TRB_TYPE_EN_SLOT 9
-#define TRB_TYPE_DIS_SLOT 10
-#define TRB_TYPE_ADDRESS_DEV 11
-#define TRB_TYPE_CON_ENDPOINT 12
-#define TRB_TYPE_EVALU_CONTXT 13
-#define TRB_TYPE_RESET_ENDPOINT 14
-#define TRB_TYPE_STOP_ENDPOINT 15
-#define TRB_TYPE_SET_TR_DEQUE 16
-#define TRB_TYPE_RESET_DEV 17
-#define TRB_TYPE_GET_PORT_BANW 21
-#define TRB_TYPE_FORCE_HEADER 22
-#define TRB_TYPE_NO_OP_COMMAND 23
-#define TRB_TYPE_TRANS_EVENT 32
-#define TRB_TYPE_COMMAND_COMPLT_EVENT 33
-#define TRB_TYPE_PORT_STATUS_CHANGE_EVENT 34
-#define TRB_TYPE_HOST_CONTROLLER_EVENT 37
-#define TRB_TYPE_DEVICE_NOTIFI_EVENT 38
-#define TRB_TYPE_MFINDEX_WRAP_EVENT 39
+#define TRB_TYPE_NORMAL 1
+#define TRB_TYPE_SETUP_STAGE 2
+#define TRB_TYPE_DATA_STAGE 3
+#define TRB_TYPE_STATUS_STAGE 4
+#define TRB_TYPE_ISOCH 5
+#define TRB_TYPE_LINK 6
+#define TRB_TYPE_EVENT_DATA 7
+#define TRB_TYPE_NO_OP 8
+#define TRB_TYPE_EN_SLOT 9
+#define TRB_TYPE_DIS_SLOT 10
+#define TRB_TYPE_ADDRESS_DEV 11
+#define TRB_TYPE_CON_ENDPOINT 12
+#define TRB_TYPE_EVALU_CONTXT 13
+#define TRB_TYPE_RESET_ENDPOINT 14
+#define TRB_TYPE_STOP_ENDPOINT 15
+#define TRB_TYPE_SET_TR_DEQUE 16
+#define TRB_TYPE_RESET_DEV 17
+#define TRB_TYPE_GET_PORT_BANW 21
+#define TRB_TYPE_FORCE_HEADER 22
+#define TRB_TYPE_NO_OP_COMMAND 23
+#define TRB_TYPE_TRANS_EVENT 32
+#define TRB_TYPE_COMMAND_COMPLT_EVENT 33
+#define TRB_TYPE_PORT_STATUS_CHANGE_EVENT 34
+#define TRB_TYPE_HOST_CONTROLLER_EVENT 37
+#define TRB_TYPE_DEVICE_NOTIFI_EVENT 38
+#define TRB_TYPE_MFINDEX_WRAP_EVENT 39
//
// Convert millisecond to microsecond.
//
-#define XHC_1_MILLISECOND (1000)
-#define XHC_POLL_DELAY (1000)
-#define XHC_GENERIC_TIMEOUT (10 * 1000)
+#define XHC_1_MILLISECOND (1000)
+#define XHC_POLL_DELAY (1000)
+#define XHC_GENERIC_TIMEOUT (10 * 1000)
-#define EFI_USB_SPEED_FULL 0x0000 ///< 12 Mb/s, USB 1.1 OHCI and UHCI HC.
-#define EFI_USB_SPEED_LOW 0x0001 ///< 1 Mb/s, USB 1.1 OHCI and UHCI HC.
-#define EFI_USB_SPEED_HIGH 0x0002 ///< 480 Mb/s, USB 2.0 EHCI HC.
-#define EFI_USB_SPEED_SUPER 0x0003 ///< 4.8 Gb/s, USB 3.0 XHCI HC.
+#define EFI_USB_SPEED_FULL 0x0000 ///< 12 Mb/s, USB 1.1 OHCI and UHCI HC.
+#define EFI_USB_SPEED_LOW 0x0001 ///< 1 Mb/s, USB 1.1 OHCI and UHCI HC.
+#define EFI_USB_SPEED_HIGH 0x0002 ///< 480 Mb/s, USB 2.0 EHCI HC.
+#define EFI_USB_SPEED_SUPER 0x0003 ///< 4.8 Gb/s, USB 3.0 XHCI HC.
//
// Transfer types, used in URB to identify the transfer type
//
-#define XHC_CTRL_TRANSFER 0x01
-#define XHC_BULK_TRANSFER 0x02
-#define XHC_INT_TRANSFER_SYNC 0x04
-#define XHC_INT_TRANSFER_ASYNC 0x08
-#define XHC_INT_ONLY_TRANSFER_ASYNC 0x10
+#define XHC_CTRL_TRANSFER 0x01
+#define XHC_BULK_TRANSFER 0x02
+#define XHC_INT_TRANSFER_SYNC 0x04
+#define XHC_INT_TRANSFER_ASYNC 0x08
+#define XHC_INT_ONLY_TRANSFER_ASYNC 0x10
//
// USB Transfer Results
//
-#define EFI_USB_NOERROR 0x00
-#define EFI_USB_ERR_NOTEXECUTE 0x01
-#define EFI_USB_ERR_STALL 0x02
-#define EFI_USB_ERR_BUFFER 0x04
-#define EFI_USB_ERR_BABBLE 0x08
-#define EFI_USB_ERR_NAK 0x10
-#define EFI_USB_ERR_CRC 0x20
-#define EFI_USB_ERR_TIMEOUT 0x40
-#define EFI_USB_ERR_BITSTUFF 0x80
-#define EFI_USB_ERR_SYSTEM 0x100
+#define EFI_USB_NOERROR 0x00
+#define EFI_USB_ERR_NOTEXECUTE 0x01
+#define EFI_USB_ERR_STALL 0x02
+#define EFI_USB_ERR_BUFFER 0x04
+#define EFI_USB_ERR_BABBLE 0x08
+#define EFI_USB_ERR_NAK 0x10
+#define EFI_USB_ERR_CRC 0x20
+#define EFI_USB_ERR_TIMEOUT 0x40
+#define EFI_USB_ERR_BITSTUFF 0x80
+#define EFI_USB_ERR_SYSTEM 0x100
#pragma pack(1)
@@ -216,42 +216,42 @@
// 7.6.9.2 When used by the DbC it is always a 64 byte data structure
//
typedef struct _ENDPOINT_CONTEXT_64 {
- UINT32 EPState:3;
- UINT32 RsvdZ1:5;
- UINT32 Mult:2; // set to 0
- UINT32 MaxPStreams:5; // set to 0
- UINT32 LSA:1; // set to 0
- UINT32 Interval:8; // set to 0
- UINT32 RsvdZ2:8;
-
- UINT32 RsvdZ3:1;
- UINT32 CErr:2;
- UINT32 EPType:3;
- UINT32 RsvdZ4:1;
- UINT32 HID:1; // set to 0
- UINT32 MaxBurstSize:8;
- UINT32 MaxPacketSize:16;
-
- UINT32 PtrLo;
-
- UINT32 PtrHi;
-
- UINT32 AverageTRBLength:16;
- UINT32 MaxESITPayload:16; // set to 0
-
- UINT32 RsvdZ5; // Reserved
- UINT32 RsvdZ6;
- UINT32 RsvdZ7;
-
- UINT32 RsvdZ8;
- UINT32 RsvdZ9;
- UINT32 RsvdZ10;
- UINT32 RsvdZ11;
-
- UINT32 RsvdZ12;
- UINT32 RsvdZ13;
- UINT32 RsvdZ14;
- UINT32 RsvdZ15;
+ UINT32 EPState : 3;
+ UINT32 RsvdZ1 : 5;
+ UINT32 Mult : 2; // set to 0
+ UINT32 MaxPStreams : 5; // set to 0
+ UINT32 LSA : 1; // set to 0
+ UINT32 Interval : 8; // set to 0
+ UINT32 RsvdZ2 : 8;
+
+ UINT32 RsvdZ3 : 1;
+ UINT32 CErr : 2;
+ UINT32 EPType : 3;
+ UINT32 RsvdZ4 : 1;
+ UINT32 HID : 1; // set to 0
+ UINT32 MaxBurstSize : 8;
+ UINT32 MaxPacketSize : 16;
+
+ UINT32 PtrLo;
+
+ UINT32 PtrHi;
+
+ UINT32 AverageTRBLength : 16;
+ UINT32 MaxESITPayload : 16; // set to 0
+
+ UINT32 RsvdZ5; // Reserved
+ UINT32 RsvdZ6;
+ UINT32 RsvdZ7;
+
+ UINT32 RsvdZ8;
+ UINT32 RsvdZ9;
+ UINT32 RsvdZ10;
+ UINT32 RsvdZ11;
+
+ UINT32 RsvdZ12;
+ UINT32 RsvdZ13;
+ UINT32 RsvdZ14;
+ UINT32 RsvdZ15;
} ENDPOINT_CONTEXT_64;
//
@@ -261,25 +261,25 @@ typedef struct _ENDPOINT_CONTEXT_64 {
// Rings, and to define the Data stage information for Control Transfer Rings.
//
typedef struct _TRANSFER_TRB_NORMAL {
- UINT32 TRBPtrLo;
-
- UINT32 TRBPtrHi;
-
- UINT32 Length:17;
- UINT32 TDSize:5;
- UINT32 IntTarget:10;
-
- UINT32 CycleBit:1;
- UINT32 ENT:1;
- UINT32 ISP:1;
- UINT32 NS:1;
- UINT32 CH:1;
- UINT32 IOC:1;
- UINT32 IDT:1;
- UINT32 RsvdZ1:2;
- UINT32 BEI:1;
- UINT32 Type:6;
- UINT32 RsvdZ2:16;
+ UINT32 TRBPtrLo;
+
+ UINT32 TRBPtrHi;
+
+ UINT32 Length : 17;
+ UINT32 TDSize : 5;
+ UINT32 IntTarget : 10;
+
+ UINT32 CycleBit : 1;
+ UINT32 ENT : 1;
+ UINT32 ISP : 1;
+ UINT32 NS : 1;
+ UINT32 CH : 1;
+ UINT32 IOC : 1;
+ UINT32 IDT : 1;
+ UINT32 RsvdZ1 : 2;
+ UINT32 BEI : 1;
+ UINT32 Type : 6;
+ UINT32 RsvdZ2 : 16;
} TRANSFER_TRB_NORMAL;
//
@@ -288,21 +288,21 @@ typedef struct _TRANSFER_TRB_NORMAL {
// for more information on the use and operation of Transfer Events.
//
typedef struct _EVT_TRB_TRANSFER {
- UINT32 TRBPtrLo;
+ UINT32 TRBPtrLo;
- UINT32 TRBPtrHi;
+ UINT32 TRBPtrHi;
- UINT32 Length:24;
- UINT32 Completecode:8;
+ UINT32 Length : 24;
+ UINT32 Completecode : 8;
- UINT32 CycleBit:1;
- UINT32 RsvdZ1:1;
- UINT32 ED:1;
- UINT32 RsvdZ2:7;
- UINT32 Type:6;
- UINT32 EndpointId:5;
- UINT32 RsvdZ3:3;
- UINT32 SlotId:8;
+ UINT32 CycleBit : 1;
+ UINT32 RsvdZ1 : 1;
+ UINT32 ED : 1;
+ UINT32 RsvdZ2 : 7;
+ UINT32 Type : 6;
+ UINT32 EndpointId : 5;
+ UINT32 RsvdZ3 : 3;
+ UINT32 SlotId : 8;
} EVT_TRB_TRANSFER;
//
@@ -310,104 +310,104 @@ typedef struct _EVT_TRB_TRANSFER {
// A Link TRB provides support for non-contiguous TRB Rings.
//
typedef struct _LINK_TRB {
- UINT32 PtrLo;
+ UINT32 PtrLo;
- UINT32 PtrHi;
+ UINT32 PtrHi;
- UINT32 RsvdZ1:22;
- UINT32 InterTarget:10;
+ UINT32 RsvdZ1 : 22;
+ UINT32 InterTarget : 10;
- UINT32 CycleBit:1;
- UINT32 TC:1;
- UINT32 RsvdZ2:2;
- UINT32 CH:1;
- UINT32 IOC:1;
- UINT32 RsvdZ3:4;
- UINT32 Type:6;
- UINT32 RsvdZ4:16;
+ UINT32 CycleBit : 1;
+ UINT32 TC : 1;
+ UINT32 RsvdZ2 : 2;
+ UINT32 CH : 1;
+ UINT32 IOC : 1;
+ UINT32 RsvdZ3 : 4;
+ UINT32 Type : 6;
+ UINT32 RsvdZ4 : 16;
} LINK_TRB;
//
// TRB Template: 16 bytes
//
typedef struct _TRB_TEMPLATE {
- UINT32 Parameter1;
+ UINT32 Parameter1;
- UINT32 Parameter2;
+ UINT32 Parameter2;
- UINT32 Status;
+ UINT32 Status;
- UINT32 CycleBit:1;
- UINT32 RsvdZ1:9;
- UINT32 Type:6;
- UINT32 Control:16;
+ UINT32 CycleBit : 1;
+ UINT32 RsvdZ1 : 9;
+ UINT32 Type : 6;
+ UINT32 Control : 16;
} TRB_TEMPLATE;
//
// Refer to XHCI 6.5 Event Ring Segment Table: 16 bytes
//
typedef struct _EVENT_RING_SEG_TABLE_ENTRY {
- UINT32 PtrLo;
- UINT32 PtrHi;
- UINT32 RingTrbSize:16;
- UINT32 RsvdZ1:16;
- UINT32 RsvdZ2;
+ UINT32 PtrLo;
+ UINT32 PtrHi;
+ UINT32 RingTrbSize : 16;
+ UINT32 RsvdZ1 : 16;
+ UINT32 RsvdZ2;
} EVENT_RING_SEG_TABLE_ENTRY;
//
// Size: 40 bytes
//
typedef struct _EVENT_RING {
- EFI_PHYSICAL_ADDRESS ERSTBase;
- EFI_PHYSICAL_ADDRESS EventRingSeg0;
- UINT32 TrbNumber;
- EFI_PHYSICAL_ADDRESS EventRingEnqueue;
- EFI_PHYSICAL_ADDRESS EventRingDequeue;
- UINT32 EventRingCCS;
+ EFI_PHYSICAL_ADDRESS ERSTBase;
+ EFI_PHYSICAL_ADDRESS EventRingSeg0;
+ UINT32 TrbNumber;
+ EFI_PHYSICAL_ADDRESS EventRingEnqueue;
+ EFI_PHYSICAL_ADDRESS EventRingDequeue;
+ UINT32 EventRingCCS;
} EVENT_RING;
// Size: 32 bytes
typedef struct _TRANSFER_RING {
- EFI_PHYSICAL_ADDRESS RingSeg0;
- UINT32 TrbNumber;
- EFI_PHYSICAL_ADDRESS RingEnqueue;
- EFI_PHYSICAL_ADDRESS RingDequeue;
- UINT32 RingPCS;
+ EFI_PHYSICAL_ADDRESS RingSeg0;
+ UINT32 TrbNumber;
+ EFI_PHYSICAL_ADDRESS RingEnqueue;
+ EFI_PHYSICAL_ADDRESS RingDequeue;
+ UINT32 RingPCS;
} TRANSFER_RING;
//
// Size: 64 bytes
//
typedef struct _DBC_INFO_CONTEXT {
- UINT64 String0DescAddress;
- UINT64 ManufacturerStrDescAddress;
- UINT64 ProductStrDescAddress;
- UINT64 SerialNumberStrDescAddress;
- UINT64 String0Length:8;
- UINT64 ManufacturerStrLength:8;
- UINT64 ProductStrLength:8;
- UINT64 SerialNumberStrLength:8;
- UINT64 RsvdZ1:32;
- UINT64 RsvdZ2;
- UINT64 RsvdZ3;
- UINT64 RsvdZ4;
+ UINT64 String0DescAddress;
+ UINT64 ManufacturerStrDescAddress;
+ UINT64 ProductStrDescAddress;
+ UINT64 SerialNumberStrDescAddress;
+ UINT64 String0Length : 8;
+ UINT64 ManufacturerStrLength : 8;
+ UINT64 ProductStrLength : 8;
+ UINT64 SerialNumberStrLength : 8;
+ UINT64 RsvdZ1 : 32;
+ UINT64 RsvdZ2;
+ UINT64 RsvdZ3;
+ UINT64 RsvdZ4;
} DBC_INFO_CONTEXT;
//
// Debug Capability Context Data Structure: 192 bytes
//
typedef struct _XHC_DC_CONTEXT {
- DBC_INFO_CONTEXT DbcInfoContext;
- ENDPOINT_CONTEXT_64 EpOutContext;
- ENDPOINT_CONTEXT_64 EpInContext;
+ DBC_INFO_CONTEXT DbcInfoContext;
+ ENDPOINT_CONTEXT_64 EpOutContext;
+ ENDPOINT_CONTEXT_64 EpInContext;
} XHC_DC_CONTEXT;
//
// Size: 16 bytes
//
typedef union _TRB {
- TRB_TEMPLATE TrbTemplate;
- TRANSFER_TRB_NORMAL TrbNormal;
+ TRB_TEMPLATE TrbTemplate;
+ TRANSFER_TRB_NORMAL TrbNormal;
} TRB;
///
@@ -427,113 +427,113 @@ typedef struct _URB {
//
// Transfer data buffer
//
- EFI_PHYSICAL_ADDRESS Data;
- UINT32 DataLen;
+ EFI_PHYSICAL_ADDRESS Data;
+ UINT32 DataLen;
//
// Execute result
//
- UINT32 Result;
+ UINT32 Result;
//
// Completed data length
//
- UINT32 Completed;
+ UINT32 Completed;
//
// Tranfer Ring info
//
- EFI_PHYSICAL_ADDRESS Ring;
- EFI_PHYSICAL_ADDRESS Trb;
- BOOLEAN Finished;
- EFI_USB_DATA_DIRECTION Direction;
+ EFI_PHYSICAL_ADDRESS Ring;
+ EFI_PHYSICAL_ADDRESS Trb;
+ BOOLEAN Finished;
+ EFI_USB_DATA_DIRECTION Direction;
} URB;
typedef struct _USB3_DEBUG_PORT_INSTANCE {
- UINT8 Initialized;
+ UINT8 Initialized;
//
// The flag indicates debug capability is supported
//
- BOOLEAN DebugSupport;
+ BOOLEAN DebugSupport;
//
// The flag indicates debug device is ready
//
- BOOLEAN Ready;
+ BOOLEAN Ready;
//
// The flag indicates the instance is from HOB
//
- BOOLEAN FromHob;
+ BOOLEAN FromHob;
//
// Prevent notification being interrupted by debug timer
//
- BOOLEAN InNotify;
+ BOOLEAN InNotify;
//
// PciIo protocol event
//
- EFI_PHYSICAL_ADDRESS PciIoEvent;
+ EFI_PHYSICAL_ADDRESS PciIoEvent;
//
// The flag indicates if USB 3.0 ports has been turn off/on power
//
- BOOLEAN ChangePortPower;
+ BOOLEAN ChangePortPower;
//
// XHCI MMIO Base address
//
- EFI_PHYSICAL_ADDRESS XhciMmioBase;
+ EFI_PHYSICAL_ADDRESS XhciMmioBase;
//
// XHCI OP RegisterBase address
//
- EFI_PHYSICAL_ADDRESS XhciOpRegister;
+ EFI_PHYSICAL_ADDRESS XhciOpRegister;
//
// XHCI Debug Register Base Address
//
- EFI_PHYSICAL_ADDRESS DebugCapabilityBase;
+ EFI_PHYSICAL_ADDRESS DebugCapabilityBase;
//
// XHCI Debug Capability offset
//
- UINT64 DebugCapabilityOffset;
+ UINT64 DebugCapabilityOffset;
//
// XHCI Debug Context Address
//
- EFI_PHYSICAL_ADDRESS DebugCapabilityContext;
+ EFI_PHYSICAL_ADDRESS DebugCapabilityContext;
//
// Transfer Ring
//
- TRANSFER_RING TransferRingOut;
- TRANSFER_RING TransferRingIn;
+ TRANSFER_RING TransferRingOut;
+ TRANSFER_RING TransferRingIn;
//
// EventRing
//
- EVENT_RING EventRing;
+ EVENT_RING EventRing;
//
// URB - Read
//
- URB UrbOut;
+ URB UrbOut;
//
// URB - Write
//
- URB UrbIn;
+ URB UrbIn;
//
// The available data length in the following data buffer.
//
- UINT8 DataCount;
+ UINT8 DataCount;
//
// The data buffer address for data read and poll.
//
- EFI_PHYSICAL_ADDRESS Data;
+ EFI_PHYSICAL_ADDRESS Data;
} USB3_DEBUG_PORT_HANDLE;
#pragma pack()
@@ -549,8 +549,8 @@ typedef struct _USB3_DEBUG_PORT_INSTANCE {
**/
UINT32
XhcReadDebugReg (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN UINT32 Offset
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN UINT32 Offset
);
/**
@@ -578,9 +578,9 @@ XhcSetDebugRegBit (
**/
VOID
XhcWriteDebugReg (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN UINT32 Offset,
- IN UINT32 Data
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN UINT32 Offset,
+ IN UINT32 Data
);
/**
@@ -594,7 +594,7 @@ XhcWriteDebugReg (
is not enabled.
**/
BOOLEAN
-XhcIsBitSet(
+XhcIsBitSet (
UINTN Register,
UINT32 BitMask
);
@@ -606,7 +606,7 @@ XhcIsBitSet(
@param[in] BitMask 32-bit mask
**/
VOID
-XhcSetR32Bit(
+XhcSetR32Bit (
UINTN Register,
UINT32 BitMask
);
@@ -618,9 +618,9 @@ XhcSetR32Bit(
@param[in] BitMask 32-bit mask
**/
VOID
-XhcClearR32Bit(
- IN OUT UINTN Register,
- IN UINT32 BitMask
+XhcClearR32Bit (
+ IN OUT UINTN Register,
+ IN UINT32 BitMask
);
/**
@@ -654,9 +654,9 @@ GetXhciPciCommand (
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
-VOID*
+VOID *
AllocateAlignBuffer (
- IN UINTN BufferSize
+ IN UINTN BufferSize
);
/**
@@ -694,11 +694,11 @@ USB3InitializeReal (
EFI_STATUS
EFIAPI
XhcDataTransfer (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN EFI_USB_DATA_DIRECTION Direction,
- IN OUT VOID *Data,
- IN OUT UINTN *DataLength,
- IN UINTN Timeout
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN EFI_USB_DATA_DIRECTION Direction,
+ IN OUT VOID *Data,
+ IN OUT UINTN *DataLength,
+ IN UINTN Timeout
);
/**
@@ -713,7 +713,7 @@ XhcDataTransfer (
RETURN_STATUS
EFIAPI
InitializeUsbDebugHardware (
- IN USB3_DEBUG_PORT_HANDLE *Handle
+ IN USB3_DEBUG_PORT_HANDLE *Handle
);
/**
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
index cce676eb8a..15842a317e 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.c
@@ -13,7 +13,7 @@
#include <Ppi/IoMmu.h>
#include "DebugCommunicationLibUsb3Internal.h"
-GUID gUsb3DbgGuid = USB3_DBG_GUID;
+GUID gUsb3DbgGuid = USB3_DBG_GUID;
/**
USB3 IOMMU PPI notify.
@@ -33,7 +33,7 @@ Usb3IoMmuPpiNotify (
IN VOID *Ppi
)
{
- USB3_DEBUG_PORT_HANDLE *Instance;
+ USB3_DEBUG_PORT_HANDLE *Instance;
DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));
@@ -60,7 +60,7 @@ Usb3IoMmuPpiNotify (
return EFI_SUCCESS;
}
-EFI_PEI_NOTIFY_DESCRIPTOR mUsb3IoMmuPpiNotifyDesc = {
+EFI_PEI_NOTIFY_DESCRIPTOR mUsb3IoMmuPpiNotifyDesc = {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEdkiiIoMmuPpiGuid,
Usb3IoMmuPpiNotify
@@ -94,12 +94,12 @@ IoMmuAllocateBuffer (
OUT VOID **Mapping
)
{
- EFI_STATUS Status;
- UINTN NumberOfBytes;
+ EFI_STATUS Status;
+ UINTN NumberOfBytes;
- *HostAddress = NULL;
+ *HostAddress = NULL;
*DeviceAddress = 0;
- *Mapping = NULL;
+ *Mapping = NULL;
Status = IoMmu->AllocateBuffer (
IoMmu,
@@ -113,19 +113,20 @@ IoMmuAllocateBuffer (
}
NumberOfBytes = EFI_PAGES_TO_SIZE (Pages);
- Status = IoMmu->Map (
- IoMmu,
- EdkiiIoMmuOperationBusMasterCommonBuffer,
- *HostAddress,
- &NumberOfBytes,
- DeviceAddress,
- Mapping
- );
+ Status = IoMmu->Map (
+ IoMmu,
+ EdkiiIoMmuOperationBusMasterCommonBuffer,
+ *HostAddress,
+ &NumberOfBytes,
+ DeviceAddress,
+ Mapping
+ );
if (EFI_ERROR (Status)) {
IoMmu->FreeBuffer (IoMmu, Pages, *HostAddress);
*HostAddress = NULL;
return EFI_OUT_OF_RESOURCES;
}
+
Status = IoMmu->SetAttribute (
IoMmu,
*Mapping,
@@ -134,7 +135,7 @@ IoMmuAllocateBuffer (
if (EFI_ERROR (Status)) {
IoMmu->Unmap (IoMmu, *Mapping);
IoMmu->FreeBuffer (IoMmu, Pages, *HostAddress);
- *Mapping = NULL;
+ *Mapping = NULL;
*HostAddress = NULL;
return Status;
}
@@ -153,15 +154,15 @@ Usb3GetIoMmu (
VOID
)
{
- EFI_STATUS Status;
- EDKII_IOMMU_PPI *IoMmu;
+ EFI_STATUS Status;
+ EDKII_IOMMU_PPI *IoMmu;
- IoMmu = NULL;
+ IoMmu = NULL;
Status = PeiServicesLocatePpi (
&gEdkiiIoMmuPpiGuid,
0,
NULL,
- (VOID **) &IoMmu
+ (VOID **)&IoMmu
);
if (!EFI_ERROR (Status) && (IoMmu != NULL)) {
return IoMmu;
@@ -179,10 +180,10 @@ GetUsb3DebugPortInstanceAddrPtr (
VOID
)
{
- USB3_DEBUG_PORT_HANDLE *Instance;
- EFI_PHYSICAL_ADDRESS *AddrPtr;
- EFI_PEI_HOB_POINTERS Hob;
- EFI_STATUS Status;
+ USB3_DEBUG_PORT_HANDLE *Instance;
+ EFI_PHYSICAL_ADDRESS *AddrPtr;
+ EFI_PEI_HOB_POINTERS Hob;
+ EFI_STATUS Status;
Hob.Raw = GetFirstGuidHob (&gUsb3DbgGuid);
if (Hob.Raw == NULL) {
@@ -196,9 +197,9 @@ GetUsb3DebugPortInstanceAddrPtr (
);
ASSERT (AddrPtr != NULL);
ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE));
- Instance = (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1);
- *AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance;
- Instance->FromHob = TRUE;
+ Instance = (USB3_DEBUG_PORT_HANDLE *)(AddrPtr + 1);
+ *AddrPtr = (EFI_PHYSICAL_ADDRESS)(UINTN)Instance;
+ Instance->FromHob = TRUE;
Instance->Initialized = USB3DBG_UNINITIALIZED;
if (Usb3GetIoMmu () == NULL) {
Status = PeiServicesNotifyPpi (&mUsb3IoMmuPpiNotifyDesc);
@@ -219,18 +220,18 @@ GetUsb3DebugPortInstanceAddrPtr (
@return A pointer to the allocated buffer or NULL if allocation fails.
**/
-VOID*
+VOID *
AllocateAlignBuffer (
- IN UINTN BufferSize
+ IN UINTN BufferSize
)
{
- VOID *Buf;
- EFI_PHYSICAL_ADDRESS Address;
- EFI_STATUS Status;
- VOID *MemoryDiscoveredPpi;
- EDKII_IOMMU_PPI *IoMmu;
- VOID *HostAddress;
- VOID *Mapping;
+ VOID *Buf;
+ EFI_PHYSICAL_ADDRESS Address;
+ EFI_STATUS Status;
+ VOID *MemoryDiscoveredPpi;
+ EDKII_IOMMU_PPI *IoMmu;
+ VOID *HostAddress;
+ VOID *Mapping;
Buf = NULL;
@@ -241,7 +242,7 @@ AllocateAlignBuffer (
&gEfiPeiMemoryDiscoveredPpiGuid,
0,
NULL,
- (VOID **) &MemoryDiscoveredPpi
+ (VOID **)&MemoryDiscoveredPpi
);
if (!EFI_ERROR (Status)) {
IoMmu = Usb3GetIoMmu ();
@@ -254,8 +255,8 @@ AllocateAlignBuffer (
&Mapping
);
if (!EFI_ERROR (Status)) {
- ASSERT (Address == ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress));
- Buf = (VOID *)(UINTN) Address;
+ ASSERT (Address == ((EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress));
+ Buf = (VOID *)(UINTN)Address;
}
} else {
Status = PeiServicesAllocatePages (
@@ -264,10 +265,10 @@ AllocateAlignBuffer (
&Address
);
if (!EFI_ERROR (Status)) {
- Buf = (VOID *)(UINTN) Address;
+ Buf = (VOID *)(UINTN)Address;
}
}
}
+
return Buf;
}
-
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
index 262cfab3fb..a651e88271 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c
@@ -19,20 +19,20 @@
EFI_STATUS
EFIAPI
XhcSyncTrsRing (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN TRANSFER_RING *TrsRing
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN TRANSFER_RING *TrsRing
)
{
- UINTN Index;
- TRB_TEMPLATE *TrsTrb;
- UINT32 CycleBit;
+ UINTN Index;
+ TRB_TEMPLATE *TrsTrb;
+ UINT32 CycleBit;
ASSERT (TrsRing != NULL);
//
// Calculate the latest RingEnqueue and RingPCS
//
- TrsTrb = (TRB_TEMPLATE *)(UINTN) TrsRing->RingEnqueue;
+ TrsTrb = (TRB_TEMPLATE *)(UINTN)TrsRing->RingEnqueue;
ASSERT (TrsTrb != NULL);
@@ -40,13 +40,14 @@ XhcSyncTrsRing (
if (TrsTrb->CycleBit != (TrsRing->RingPCS & BIT0)) {
break;
}
+
TrsTrb++;
- if ((UINT8) TrsTrb->Type == TRB_TYPE_LINK) {
- ASSERT (((LINK_TRB*)TrsTrb)->TC != 0);
+ if ((UINT8)TrsTrb->Type == TRB_TYPE_LINK) {
+ ASSERT (((LINK_TRB *)TrsTrb)->TC != 0);
//
// set cycle bit in Link TRB as normal
//
- ((LINK_TRB*)TrsTrb)->CycleBit = TrsRing->RingPCS & BIT0;
+ ((LINK_TRB *)TrsTrb)->CycleBit = TrsRing->RingPCS & BIT0;
//
// Toggle PCS maintained by software
//
@@ -54,10 +55,11 @@ XhcSyncTrsRing (
TrsTrb = (TRB_TEMPLATE *)(UINTN)((TrsTrb->Parameter1 | LShiftU64 ((UINT64)TrsTrb->Parameter2, 32)) & ~0x0F);
}
}
+
ASSERT (Index != TrsRing->TrbNumber);
- if ((EFI_PHYSICAL_ADDRESS)(UINTN) TrsTrb != TrsRing->RingEnqueue) {
- TrsRing->RingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN) TrsTrb;
+ if ((EFI_PHYSICAL_ADDRESS)(UINTN)TrsTrb != TrsRing->RingEnqueue) {
+ TrsRing->RingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN)TrsTrb;
}
//
@@ -83,11 +85,11 @@ EFI_STATUS
EFIAPI
XhcSyncEventRing (
IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN EVENT_RING *EvtRing
+ IN EVENT_RING *EvtRing
)
{
- UINTN Index;
- TRB_TEMPLATE *EvtTrb1;
+ UINTN Index;
+ TRB_TEMPLATE *EvtTrb1;
ASSERT (EvtRing != NULL);
@@ -95,7 +97,7 @@ XhcSyncEventRing (
// Calculate the EventRingEnqueue and EventRingCCS.
// Note: only support single Segment
//
- EvtTrb1 = (TRB_TEMPLATE *)(UINTN) EvtRing->EventRingDequeue;
+ EvtTrb1 = (TRB_TEMPLATE *)(UINTN)EvtRing->EventRingDequeue;
for (Index = 0; Index < EvtRing->TrbNumber; Index++) {
if (EvtTrb1->CycleBit != EvtRing->EventRingCCS) {
@@ -104,8 +106,8 @@ XhcSyncEventRing (
EvtTrb1++;
- if ((UINTN)EvtTrb1 >= ((UINTN) EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) {
- EvtTrb1 = (TRB_TEMPLATE *)(UINTN) EvtRing->EventRingSeg0;
+ if ((UINTN)EvtTrb1 >= ((UINTN)EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) {
+ EvtTrb1 = (TRB_TEMPLATE *)(UINTN)EvtRing->EventRingSeg0;
EvtRing->EventRingCCS = (EvtRing->EventRingCCS) ? 0 : 1;
}
}
@@ -133,16 +135,16 @@ XhcSyncEventRing (
EFI_STATUS
EFIAPI
XhcCheckNewEvent (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN EVENT_RING *EvtRing,
- OUT TRB_TEMPLATE **NewEvtTrb
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN EVENT_RING *EvtRing,
+ OUT TRB_TEMPLATE **NewEvtTrb
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
ASSERT (EvtRing != NULL);
- *NewEvtTrb = (TRB_TEMPLATE *)(UINTN) EvtRing->EventRingDequeue;
+ *NewEvtTrb = (TRB_TEMPLATE *)(UINTN)EvtRing->EventRingDequeue;
if (EvtRing->EventRingDequeue == EvtRing->EventRingEnqueue) {
return EFI_NOT_READY;
@@ -154,7 +156,7 @@ XhcCheckNewEvent (
//
// If the dequeue pointer is beyond the ring, then roll-back it to the beginning of the ring.
//
- if ((UINTN)EvtRing->EventRingDequeue >= ((UINTN) EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) {
+ if ((UINTN)EvtRing->EventRingDequeue >= ((UINTN)EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) {
EvtRing->EventRingDequeue = EvtRing->EventRingSeg0;
}
@@ -173,14 +175,14 @@ XhcCheckNewEvent (
**/
BOOLEAN
IsTrbInTrsRing (
- IN TRANSFER_RING *Ring,
- IN TRB_TEMPLATE *Trb
+ IN TRANSFER_RING *Ring,
+ IN TRB_TEMPLATE *Trb
)
{
TRB_TEMPLATE *CheckedTrb;
UINTN Index;
- CheckedTrb = (TRB_TEMPLATE *)(UINTN) Ring->RingSeg0;
+ CheckedTrb = (TRB_TEMPLATE *)(UINTN)Ring->RingSeg0;
ASSERT (Ring->TrbNumber == TR_RING_TRB_NUMBER);
@@ -188,6 +190,7 @@ IsTrbInTrsRing (
if (Trb == CheckedTrb) {
return TRUE;
}
+
CheckedTrb++;
}
@@ -204,18 +207,18 @@ IsTrbInTrsRing (
**/
VOID
XhcCheckUrbResult (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN URB *Urb
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN URB *Urb
)
{
- EVT_TRB_TRANSFER *EvtTrb;
- TRB_TEMPLATE *TRBPtr;
- UINTN Index;
- EFI_STATUS Status;
- URB *CheckedUrb;
- UINT64 XhcDequeue;
- UINT32 High;
- UINT32 Low;
+ EVT_TRB_TRANSFER *EvtTrb;
+ TRB_TEMPLATE *TRBPtr;
+ UINTN Index;
+ EFI_STATUS Status;
+ URB *CheckedUrb;
+ UINT64 XhcDequeue;
+ UINT32 High;
+ UINT32 Low;
ASSERT ((Handle != NULL) && (Urb != NULL));
@@ -231,7 +234,6 @@ XhcCheckUrbResult (
XhcSyncEventRing (Handle, &Handle->EventRing);
for (Index = 0; Index < Handle->EventRing.TrbNumber; Index++) {
-
Status = XhcCheckNewEvent (Handle, &Handle->EventRing, ((TRB_TEMPLATE **)&EvtTrb));
if (Status == EFI_NOT_READY) {
//
@@ -244,7 +246,7 @@ XhcCheckUrbResult (
continue;
}
- TRBPtr = (TRB_TEMPLATE *)(UINTN)(EvtTrb->TRBPtrLo | LShiftU64 ((UINT64) EvtTrb->TRBPtrHi, 32));
+ TRBPtr = (TRB_TEMPLATE *)(UINTN)(EvtTrb->TRBPtrLo | LShiftU64 ((UINT64)EvtTrb->TRBPtrHi, 32));
if (IsTrbInTrsRing ((TRANSFER_RING *)(UINTN)(Urb->Ring), TRBPtr)) {
CheckedUrb = Urb;
@@ -253,7 +255,7 @@ XhcCheckUrbResult (
// If it is read event and it should be generated by poll, and current operation is write, we need save data into internal buffer.
// Internal buffer is used by next read.
//
- Handle->DataCount = (UINT8) (Handle->UrbIn.DataLen - EvtTrb->Length);
+ Handle->DataCount = (UINT8)(Handle->UrbIn.DataLen - EvtTrb->Length);
CopyMem ((VOID *)(UINTN)Handle->Data, (VOID *)(UINTN)Handle->UrbIn.Data, Handle->DataCount);
//
// Fill this TRB complete with CycleBit, otherwise next read will fail with old TRB.
@@ -265,14 +267,16 @@ XhcCheckUrbResult (
}
if ((EvtTrb->Completecode == TRB_COMPLETION_SHORT_PACKET) ||
- (EvtTrb->Completecode == TRB_COMPLETION_SUCCESS)) {
+ (EvtTrb->Completecode == TRB_COMPLETION_SUCCESS))
+ {
//
// The length of data which were transferred.
//
- CheckedUrb->Completed += (((TRANSFER_TRB_NORMAL*)TRBPtr)->Length - EvtTrb->Length);
+ CheckedUrb->Completed += (((TRANSFER_TRB_NORMAL *)TRBPtr)->Length - EvtTrb->Length);
} else {
- CheckedUrb->Result |= EFI_USB_ERR_TIMEOUT;
+ CheckedUrb->Result |= EFI_USB_ERR_TIMEOUT;
}
+
//
// This Urb has been processed
//
@@ -286,9 +290,9 @@ EXIT:
// Some 3rd party XHCI external cards don't support single 64-bytes width register access,
// So divide it to two 32-bytes width register access.
//
- Low = XhcReadDebugReg (Handle, XHC_DC_DCERDP);
- High = XhcReadDebugReg (Handle, XHC_DC_DCERDP + 4);
- XhcDequeue = (UINT64)(LShiftU64((UINT64)High, 32) | Low);
+ Low = XhcReadDebugReg (Handle, XHC_DC_DCERDP);
+ High = XhcReadDebugReg (Handle, XHC_DC_DCERDP + 4);
+ XhcDequeue = (UINT64)(LShiftU64 ((UINT64)High, 32) | Low);
if ((XhcDequeue & (~0x0F)) != ((UINT64)(UINTN)Handle->EventRing.EventRingDequeue & (~0x0F))) {
//
@@ -312,11 +316,11 @@ EXIT:
EFI_STATUS
EFIAPI
XhcRingDoorBell (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN URB *Urb
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN URB *Urb
)
{
- UINT32 Dcdb;
+ UINT32 Dcdb;
//
// 7.6.8.2 DCDB Register
@@ -342,20 +346,21 @@ XhcRingDoorBell (
**/
VOID
XhcExecTransfer (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN URB *Urb,
- IN UINTN Timeout
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN URB *Urb,
+ IN UINTN Timeout
)
{
- TRANSFER_RING *Ring;
- TRB_TEMPLATE *Trb;
- UINTN Loop;
- UINTN Index;
+ TRANSFER_RING *Ring;
+ TRB_TEMPLATE *Trb;
+ UINTN Loop;
+ UINTN Index;
Loop = Timeout / XHC_DEBUG_PORT_1_MILLISECOND;
if (Timeout == 0) {
Loop = 0xFFFFFFFF;
}
+
XhcRingDoorBell (Handle, Urb);
//
// Event Ring Not Empty bit can only be set to 1 by XHC after ringing door bell with some delay.
@@ -365,19 +370,22 @@ XhcExecTransfer (
if (Urb->Finished) {
break;
}
+
MicroSecondDelay (XHC_DEBUG_PORT_1_MILLISECOND);
}
+
if (Index == Loop) {
//
// If time out occurs.
//
Urb->Result |= EFI_USB_ERR_TIMEOUT;
}
+
//
// If URB transfer is error, restore transfer ring to original value before URB transfer
// This will make the current transfer TRB is always at the latest unused one in transfer ring.
//
- Ring = (TRANSFER_RING *)(UINTN) Urb->Ring;
+ Ring = (TRANSFER_RING *)(UINTN)Urb->Ring;
if ((Urb->Result != EFI_USB_NOERROR) && (Urb->Direction == EfiUsbDataIn)) {
//
// Adjust Enqueue pointer
@@ -386,7 +394,7 @@ XhcExecTransfer (
//
// Clear CCS flag for next use
//
- Trb = (TRB_TEMPLATE *)(UINTN) Urb->Trb;
+ Trb = (TRB_TEMPLATE *)(UINTN)Urb->Trb;
Trb->CycleBit = ((~Ring->RingPCS) & BIT0);
} else {
//
@@ -407,12 +415,12 @@ XhcExecTransfer (
**/
EFI_STATUS
XhcCreateTransferTrb (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN URB *Urb
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN URB *Urb
)
{
- TRANSFER_RING *EPRing;
- TRB *Trb;
+ TRANSFER_RING *EPRing;
+ TRB *Trb;
if (Urb->Direction == EfiUsbDataIn) {
EPRing = &Handle->TransferRingIn;
@@ -420,11 +428,11 @@ XhcCreateTransferTrb (
EPRing = &Handle->TransferRingOut;
}
- Urb->Ring = (EFI_PHYSICAL_ADDRESS)(UINTN) EPRing;
+ Urb->Ring = (EFI_PHYSICAL_ADDRESS)(UINTN)EPRing;
XhcSyncTrsRing (Handle, EPRing);
- Urb->Trb = EPRing->RingEnqueue;
- Trb = (TRB *)(UINTN)EPRing->RingEnqueue;
+ Urb->Trb = EPRing->RingEnqueue;
+ Trb = (TRB *)(UINTN)EPRing->RingEnqueue;
Trb->TrbNormal.TRBPtrLo = XHC_LOW_32BIT (Urb->Data);
Trb->TrbNormal.TRBPtrHi = XHC_HIGH_32BIT (Urb->Data);
Trb->TrbNormal.Length = Urb->DataLen;
@@ -453,17 +461,17 @@ XhcCreateTransferTrb (
@return Created URB or NULL
**/
-URB*
+URB *
XhcCreateUrb (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN EFI_USB_DATA_DIRECTION Direction,
- IN VOID *Data,
- IN UINTN DataLen
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN EFI_USB_DATA_DIRECTION Direction,
+ IN VOID *Data,
+ IN UINTN DataLen
)
{
- EFI_STATUS Status;
- URB *Urb;
- EFI_PHYSICAL_ADDRESS UrbData;
+ EFI_STATUS Status;
+ URB *Urb;
+ EFI_PHYSICAL_ADDRESS UrbData;
if (Direction == EfiUsbDataIn) {
Urb = &Handle->UrbIn;
@@ -471,7 +479,7 @@ XhcCreateUrb (
Urb = &Handle->UrbOut;
}
- UrbData = Urb->Data;
+ UrbData = Urb->Data;
ZeroMem (Urb, sizeof (URB));
Urb->Direction = Direction;
@@ -481,20 +489,20 @@ XhcCreateUrb (
// to make XHCI DMA successfully
// re-use the pre-allocate buffer in PEI to avoid DXE memory service or gBS are not ready
//
- Urb->Data = UrbData;
+ Urb->Data = UrbData;
if (Direction == EfiUsbDataIn) {
//
// Do not break URB data in buffer as it may contain the data which were just put in via DMA by XHC
//
- Urb->DataLen = (UINT32) DataLen;
+ Urb->DataLen = (UINT32)DataLen;
} else {
//
// Put data into URB data out buffer which will create TRBs
//
- ZeroMem ((VOID*)(UINTN) Urb->Data, DataLen);
- CopyMem ((VOID*)(UINTN) Urb->Data, Data, DataLen);
- Urb->DataLen = (UINT32) DataLen;
+ ZeroMem ((VOID *)(UINTN)Urb->Data, DataLen);
+ CopyMem ((VOID *)(UINTN)Urb->Data, Data, DataLen);
+ Urb->DataLen = (UINT32)DataLen;
}
Status = XhcCreateTransferTrb (Handle, Urb);
@@ -524,15 +532,15 @@ XhcCreateUrb (
EFI_STATUS
EFIAPI
XhcDataTransfer (
- IN USB3_DEBUG_PORT_HANDLE *Handle,
- IN EFI_USB_DATA_DIRECTION Direction,
- IN OUT VOID *Data,
- IN OUT UINTN *DataLength,
- IN UINTN Timeout
+ IN USB3_DEBUG_PORT_HANDLE *Handle,
+ IN EFI_USB_DATA_DIRECTION Direction,
+ IN OUT VOID *Data,
+ IN OUT UINTN *DataLength,
+ IN UINTN Timeout
)
{
- URB *Urb;
- EFI_STATUS Status;
+ URB *Urb;
+ EFI_STATUS Status;
//
// Validate the parameters
@@ -557,7 +565,7 @@ XhcDataTransfer (
return EFI_DEVICE_ERROR;
}
- *DataLength = Urb->Completed;
+ *DataLength = Urb->Completed;
Status = EFI_TIMEOUT;
if (Urb->Result == EFI_USB_NOERROR) {
@@ -574,4 +582,3 @@ XhcDataTransfer (
return Status;
}
-
diff --git a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/Ia32/IntHandlerFuncs.c b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/Ia32/IntHandlerFuncs.c
index 80bafca41b..600bde10d6 100644
--- a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/Ia32/IntHandlerFuncs.c
+++ b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/Ia32/IntHandlerFuncs.c
@@ -20,21 +20,21 @@
**/
BOOLEAN
CheckDebugAgentHandler (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- IN UINTN InterruptType
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ IN UINTN InterruptType
)
{
- IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
- UINTN InterruptHandler;
+ IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
+ UINTN InterruptHandler;
- IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
+ IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
if (IdtEntry == NULL) {
return FALSE;
}
InterruptHandler = IdtEntry[InterruptType].Bits.OffsetLow +
- (IdtEntry[InterruptType].Bits.OffsetHigh << 16);
- if (InterruptHandler >= sizeof (UINT32) && *(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE) {
+ (IdtEntry[InterruptType].Bits.OffsetHigh << 16);
+ if ((InterruptHandler >= sizeof (UINT32)) && (*(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE)) {
return TRUE;
} else {
return FALSE;
@@ -50,23 +50,23 @@ CheckDebugAgentHandler (
**/
VOID
SaveAndUpdateIdtEntry1 (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
)
{
- IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
- UINT16 CodeSegment;
- UINTN InterruptHandler;
+ IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
+ UINT16 CodeSegment;
+ UINTN InterruptHandler;
- IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
+ IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR));
- //
+ //
// Use current CS as the segment selector of interrupt gate in IDT
//
CodeSegment = AsmReadCs ();
- InterruptHandler = (UINTN) &AsmInterruptHandle;
+ InterruptHandler = (UINTN)&AsmInterruptHandle;
IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
IdtEntry[1].Bits.Selector = CodeSegment;
@@ -82,12 +82,12 @@ SaveAndUpdateIdtEntry1 (
**/
VOID
RestoreIdtEntry1 (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
)
{
- IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
+ IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
- IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
+ IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR));
}
diff --git a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c
index 766f6d75f7..2c80f7e22d 100644
--- a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c
+++ b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c
@@ -27,7 +27,7 @@ IsDrxEnabled (
IN UINTN Dr7
)
{
- return (BOOLEAN) (((Dr7 >> (RegisterIndex * 2)) & (BIT0 | BIT1)) == (BIT0 | BIT1));
+ return (BOOLEAN)(((Dr7 >> (RegisterIndex * 2)) & (BIT0 | BIT1)) == (BIT0 | BIT1));
}
/**
@@ -46,25 +46,25 @@ PeCoffLoaderExtraActionCommon (
IN UINTN Signature
)
{
- BOOLEAN InterruptState;
- UINTN Dr0;
- UINTN Dr1;
- UINTN Dr2;
- UINTN Dr3;
- UINTN Dr7;
- UINTN Cr4;
- UINTN NewDr7;
- UINT8 LoadImageMethod;
- UINT8 DebugAgentStatus;
- IA32_DESCRIPTOR IdtDescriptor;
- IA32_IDT_GATE_DESCRIPTOR OriginalIdtEntry;
- BOOLEAN IdtEntryHooked;
- UINT32 RegEdx;
+ BOOLEAN InterruptState;
+ UINTN Dr0;
+ UINTN Dr1;
+ UINTN Dr2;
+ UINTN Dr3;
+ UINTN Dr7;
+ UINTN Cr4;
+ UINTN NewDr7;
+ UINT8 LoadImageMethod;
+ UINT8 DebugAgentStatus;
+ IA32_DESCRIPTOR IdtDescriptor;
+ IA32_IDT_GATE_DESCRIPTOR OriginalIdtEntry;
+ BOOLEAN IdtEntryHooked;
+ UINT32 RegEdx;
ASSERT (ImageContext != NULL);
if (ImageContext->PdbPointer != NULL) {
- DEBUG((DEBUG_ERROR, " PDB = %a\n", ImageContext->PdbPointer));
+ DEBUG ((DEBUG_ERROR, " PDB = %a\n", ImageContext->PdbPointer));
}
//
@@ -84,6 +84,7 @@ PeCoffLoaderExtraActionCommon (
LoadImageMethod = DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3;
}
}
+
AsmReadIdtr (&IdtDescriptor);
if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) {
if (!CheckDebugAgentHandler (&IdtDescriptor, SOFT_INT_VECTOR_NUM)) {
@@ -122,8 +123,8 @@ PeCoffLoaderExtraActionCommon (
//
AsmWriteDr7 (BIT10);
AsmWriteDr0 (Signature);
- AsmWriteDr1 ((UINTN) ImageContext->PdbPointer);
- AsmWriteDr2 ((UINTN) ImageContext);
+ AsmWriteDr1 ((UINTN)ImageContext->PdbPointer);
+ AsmWriteDr2 ((UINTN)ImageContext);
AsmWriteDr3 (IO_PORT_BREAKPOINT_ADDRESS);
if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) {
@@ -136,7 +137,6 @@ PeCoffLoaderExtraActionCommon (
do {
DebugAgentStatus = IoRead8 (IO_PORT_BREAKPOINT_ADDRESS);
} while (DebugAgentStatus == DEBUG_AGENT_IMAGE_WAIT);
-
} else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) {
//
// Generate a software break point.
@@ -150,26 +150,31 @@ PeCoffLoaderExtraActionCommon (
// in the above exception handler
//
NewDr7 = AsmReadDr7 () | BIT10; // H/w sets bit 10, some simulators don't
- if (!IsDrxEnabled (0, NewDr7) && (AsmReadDr0 () == 0 || AsmReadDr0 () == Signature)) {
+ if (!IsDrxEnabled (0, NewDr7) && ((AsmReadDr0 () == 0) || (AsmReadDr0 () == Signature))) {
//
// If user changed Dr3 (by setting HW bp in the above exception handler,
// we will not set Dr0 to 0 in GO/STEP handler because the break cause is not IMAGE_LOAD/_UNLOAD.
//
AsmWriteDr0 (Dr0);
}
- if (!IsDrxEnabled (1, NewDr7) && (AsmReadDr1 () == (UINTN) ImageContext->PdbPointer)) {
+
+ if (!IsDrxEnabled (1, NewDr7) && (AsmReadDr1 () == (UINTN)ImageContext->PdbPointer)) {
AsmWriteDr1 (Dr1);
}
- if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN) ImageContext)) {
+
+ if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN)ImageContext)) {
AsmWriteDr2 (Dr2);
}
+
if (!IsDrxEnabled (3, NewDr7) && (AsmReadDr3 () == IO_PORT_BREAKPOINT_ADDRESS)) {
AsmWriteDr3 (Dr3);
}
+
if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) {
if (AsmReadCr4 () == (Cr4 | BIT3)) {
AsmWriteCr4 (Cr4);
}
+
if (NewDr7 == 0x20000480) {
AsmWriteDr7 (Dr7);
}
@@ -178,12 +183,14 @@ PeCoffLoaderExtraActionCommon (
AsmWriteDr7 (Dr7);
}
}
+
//
// Restore original IDT entry for INT1 if it was hooked.
//
if (IdtEntryHooked) {
RestoreIdtEntry1 (&IdtDescriptor, &OriginalIdtEntry);
}
+
//
// Restore the interrupt state
//
diff --git a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.h b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.h
index 9aeb005be9..149186b226 100644
--- a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.h
+++ b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.h
@@ -19,11 +19,11 @@
#include <ImageDebugSupport.h>
-#define DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT 1
-#define DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 2
+#define DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT 1
+#define DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 2
-#define IO_HW_BREAKPOINT_VECTOR_NUM 1
-#define SOFT_INT_VECTOR_NUM 3
+#define IO_HW_BREAKPOINT_VECTOR_NUM 1
+#define SOFT_INT_VECTOR_NUM 3
extern UINTN AsmInterruptHandle;
@@ -39,8 +39,8 @@ extern UINTN AsmInterruptHandle;
**/
BOOLEAN
CheckDebugAgentHandler (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- IN UINTN InterruptType
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ IN UINTN InterruptType
);
/**
@@ -52,8 +52,8 @@ CheckDebugAgentHandler (
**/
VOID
SaveAndUpdateIdtEntry1 (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
);
/**
@@ -65,9 +65,8 @@ SaveAndUpdateIdtEntry1 (
**/
VOID
RestoreIdtEntry1 (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
);
#endif
-
diff --git a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/X64/IntHandlerFuncs.c b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/X64/IntHandlerFuncs.c
index b470c07dd2..952285a8ea 100644
--- a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/X64/IntHandlerFuncs.c
+++ b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/X64/IntHandlerFuncs.c
@@ -20,22 +20,22 @@
**/
BOOLEAN
CheckDebugAgentHandler (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- IN UINTN InterruptType
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ IN UINTN InterruptType
)
{
- IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
- UINTN InterruptHandler;
+ IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
+ UINTN InterruptHandler;
- IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
+ IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
if (IdtEntry == NULL) {
return FALSE;
}
InterruptHandler = IdtEntry[InterruptType].Bits.OffsetLow +
- (((UINTN)IdtEntry[InterruptType].Bits.OffsetHigh) << 16) +
- (((UINTN)IdtEntry[InterruptType].Bits.OffsetUpper) << 32);
- if (InterruptHandler >= sizeof (UINT32) && *(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE) {
+ (((UINTN)IdtEntry[InterruptType].Bits.OffsetHigh) << 16) +
+ (((UINTN)IdtEntry[InterruptType].Bits.OffsetUpper) << 32);
+ if ((InterruptHandler >= sizeof (UINT32)) && (*(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE)) {
return TRUE;
} else {
return FALSE;
@@ -51,28 +51,28 @@ CheckDebugAgentHandler (
**/
VOID
SaveAndUpdateIdtEntry1 (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ OUT IA32_IDT_GATE_DESCRIPTOR *SavedIdtEntry
)
{
- IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
- UINT16 CodeSegment;
- UINTN InterruptHandler;
+ IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
+ UINT16 CodeSegment;
+ UINTN InterruptHandler;
- IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
+ IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR));
- //
+ //
// Use current CS as the segment selector of interrupt gate in IDT
//
CodeSegment = AsmReadCs ();
- InterruptHandler = (UINTN) &AsmInterruptHandle;
- IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
- IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
- IdtEntry[1].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
- IdtEntry[1].Bits.Selector = CodeSegment;
- IdtEntry[1].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
+ InterruptHandler = (UINTN)&AsmInterruptHandle;
+ IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
+ IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
+ IdtEntry[1].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
+ IdtEntry[1].Bits.Selector = CodeSegment;
+ IdtEntry[1].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
}
/**
@@ -84,12 +84,12 @@ SaveAndUpdateIdtEntry1 (
**/
VOID
RestoreIdtEntry1 (
- IN IA32_DESCRIPTOR *IdtDescriptor,
- IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
+ IN IA32_DESCRIPTOR *IdtDescriptor,
+ IN IA32_IDT_GATE_DESCRIPTOR *RestoredIdtEntry
)
{
- IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
+ IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
- IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base;
+ IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR));
}