diff options
Diffstat (limited to 'SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent')
-rw-r--r-- | SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c | 391 | ||||
-rw-r--r-- | SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c | 147 |
2 files changed, 281 insertions, 257 deletions
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
|