summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/GdbStub
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2021-12-05 14:53:56 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-12-07 17:24:28 +0000
commite7108d0e9655b1795c94ac372b0449f28dd907df (patch)
treeb153716589979b9e42e9b85281ff8b7511ba272f /EmbeddedPkg/GdbStub
parent731c67e1d77b7741a91762d17659fc9fbcb9e305 (diff)
downloadedk2-e7108d0e9655b1795c94ac372b0449f28dd907df.tar.gz
edk2-e7108d0e9655b1795c94ac372b0449f28dd907df.tar.bz2
edk2-e7108d0e9655b1795c94ac372b0449f28dd907df.zip
EmbeddedPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the EmbeddedPkg 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: Andrew Fish <afish@apple.com>
Diffstat (limited to 'EmbeddedPkg/GdbStub')
-rw-r--r--EmbeddedPkg/GdbStub/Arm/Processor.c250
-rw-r--r--EmbeddedPkg/GdbStub/GdbStub.c495
-rw-r--r--EmbeddedPkg/GdbStub/GdbStubInternal.h282
-rw-r--r--EmbeddedPkg/GdbStub/Ia32/Processor.c443
-rw-r--r--EmbeddedPkg/GdbStub/SerialIo.c159
-rw-r--r--EmbeddedPkg/GdbStub/X64/Processor.c438
6 files changed, 995 insertions, 1072 deletions
diff --git a/EmbeddedPkg/GdbStub/Arm/Processor.c b/EmbeddedPkg/GdbStub/Arm/Processor.c
index bb956b7e79..ec160903a5 100644
--- a/EmbeddedPkg/GdbStub/Arm/Processor.c
+++ b/EmbeddedPkg/GdbStub/Arm/Processor.c
@@ -15,67 +15,67 @@
// Array of exception types that need to be hooked by the debugger
// (efi, gdb) //efi number
//
-EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
- { EXCEPT_ARM_SOFTWARE_INTERRUPT, GDB_SIGTRAP }
-// { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP },
-// { EXCEPT_ARM_PREFETCH_ABORT, GDB_SIGTRAP },
-// { EXCEPT_ARM_DATA_ABORT, GDB_SIGEMT },
-// { EXCEPT_ARM_RESERVED, GDB_SIGILL }
+EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
+ { EXCEPT_ARM_SOFTWARE_INTERRUPT, GDB_SIGTRAP }
+ // { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP },
+ // { EXCEPT_ARM_PREFETCH_ABORT, GDB_SIGTRAP },
+ // { EXCEPT_ARM_DATA_ABORT, GDB_SIGEMT },
+ // { EXCEPT_ARM_RESERVED, GDB_SIGILL }
};
// Shut up some annoying RVCT warnings
#ifdef __CC_ARM
-#pragma diag_suppress 1296
+ #pragma diag_suppress 1296
#endif
-UINTN gRegisterOffsets[] = {
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R0),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R1),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R2),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R3),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R4),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R5),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R6),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R7),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R8),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R9),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R10),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R11),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, R12),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, SP),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, LR),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, PC),
- 0x00000F01, // f0
+UINTN gRegisterOffsets[] = {
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R0),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R1),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R2),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R3),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R4),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R5),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R6),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R7),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R8),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R9),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R10),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R11),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, R12),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, SP),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, LR),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, PC),
+ 0x00000F01, // f0
0x00000F02,
0x00000F03,
- 0x00000F11, // f1
+ 0x00000F11, // f1
0x00000F12,
0x00000F13,
- 0x00000F21, // f2
+ 0x00000F21, // f2
0x00000F22,
0x00000F23,
- 0x00000F31, // f3
+ 0x00000F31, // f3
0x00000F32,
0x00000F33,
- 0x00000F41, // f4
+ 0x00000F41, // f4
0x00000F42,
0x00000F43,
- 0x00000F51, // f5
+ 0x00000F51, // f5
0x00000F52,
0x00000F53,
- 0x00000F61, // f6
+ 0x00000F61, // f6
0x00000F62,
0x00000F63,
- 0x00000F71, // f7
+ 0x00000F71, // f7
0x00000F72,
0x00000F73,
- 0x00000FFF, // fps
- OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, CPSR)
+ 0x00000FFF, // fps
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_ARM, CPSR)
};
// restore warnings for RVCT
#ifdef __CC_ARM
-#pragma diag_default 1296
+ #pragma diag_default 1296
#endif
/**
@@ -91,7 +91,6 @@ MaxEfiException (
return sizeof (gExceptionType) / sizeof (EFI_EXCEPTION_TYPE_ENTRY);
}
-
/**
Return the number of entries in the gRegisters[]
@@ -105,7 +104,6 @@ MaxRegisterCount (
return sizeof (gRegisterOffsets) / sizeof (UINTN);
}
-
/**
Check to see if the ISA is supported.
ISA = Instruction Set Architecture
@@ -125,7 +123,6 @@ CheckIsa (
}
}
-
/**
This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
It is, by default, set to find the register pointer of the ARM member
@@ -135,17 +132,17 @@ CheckIsa (
**/
UINTN *
FindPointerToRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber
)
{
- UINT8 *TempPtr;
- ASSERT(gRegisterOffsets[RegNumber] < 0xF00);
+ UINT8 *TempPtr;
+
+ ASSERT (gRegisterOffsets[RegNumber] < 0xF00);
TempPtr = ((UINT8 *)SystemContext.SystemContextArm) + gRegisterOffsets[RegNumber];
return (UINT32 *)TempPtr;
}
-
/**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@param SystemContext Register content at time of the exception
@@ -160,8 +157,8 @@ BasicReadRegister (
IN CHAR8 *OutBufPtr
)
{
- UINTN RegSize;
- CHAR8 Char;
+ UINTN RegSize;
+ CHAR8 Char;
if (gRegisterOffsets[RegNumber] > 0xF00) {
AsciiSPrint (OutBufPtr, 9, "00000000");
@@ -175,20 +172,22 @@ BasicReadRegister (
if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a';
}
+
*OutBufPtr++ = Char;
Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];
if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a';
}
+
*OutBufPtr++ = Char;
RegSize = RegSize + 8;
}
+
return OutBufPtr;
}
-
/**
Reads the n-th register's value into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception
@@ -200,9 +199,9 @@ ReadNthRegister (
IN CHAR8 *InBuffer
)
{
- UINTN RegNumber;
- CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)
- CHAR8 *OutBufPtr; // pointer to the output buffer
+ UINTN RegNumber;
+ CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)
+ CHAR8 *OutBufPtr; // pointer to the output buffer
RegNumber = AsciiStrHexToUintn (&InBuffer[1]);
@@ -218,7 +217,6 @@ ReadNthRegister (
SendPacket (OutBuffer);
}
-
/**
Reads the general registers into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception
@@ -226,13 +224,13 @@ ReadNthRegister (
VOID
EFIAPI
ReadGeneralRegisters (
- IN EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_SYSTEM_CONTEXT SystemContext
)
{
- UINTN Index;
- CHAR8 *OutBuffer;
- CHAR8 *OutBufPtr;
- UINTN RegisterCount = MaxRegisterCount ();
+ UINTN Index;
+ CHAR8 *OutBuffer;
+ CHAR8 *OutBufPtr;
+ UINTN RegisterCount = MaxRegisterCount ();
// It is not safe to allocate pool here....
OutBuffer = AllocatePool ((RegisterCount * 8) + 1); // 8 bytes per register in string format plus a null to terminate
@@ -246,7 +244,6 @@ ReadGeneralRegisters (
FreePool (OutBuffer);
}
-
/**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@param SystemContext Register content at time of the exception
@@ -255,22 +252,23 @@ ReadGeneralRegisters (
@retval the pointer to the next character of the input buffer that can be used
**/
CHAR8
-*BasicWriteRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber,
- IN CHAR8 *InBufPtr
+*
+BasicWriteRegister (
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber,
+ IN CHAR8 *InBufPtr
)
{
- UINTN RegSize;
- UINTN TempValue; // the value transferred from a hex char
- UINT32 NewValue; // the new value of the RegNumber-th Register
+ UINTN RegSize;
+ UINTN TempValue; // the value transferred from a hex char
+ UINT32 NewValue; // the new value of the RegNumber-th Register
if (gRegisterOffsets[RegNumber] > 0xF00) {
return InBufPtr + 8;
}
NewValue = 0;
- RegSize = 0;
+ RegSize = 0;
while (RegSize < 32) {
TempValue = HexCharToInt (*InBufPtr++);
@@ -288,13 +286,13 @@ CHAR8
}
NewValue += (TempValue << RegSize);
- RegSize = RegSize + 8;
+ RegSize = RegSize + 8;
}
+
*(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;
return InBufPtr;
}
-
/** ‘P n...=r...’
Writes the new value of n-th register received into the input buffer to the n-th register
@param SystemContext Register content at time of the exception
@@ -302,41 +300,41 @@ CHAR8
**/
VOID
WriteNthRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *InBuffer
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *InBuffer
)
{
- UINTN RegNumber;
- CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array
- CHAR8 *RegNumBufPtr;
- CHAR8 *InBufPtr; // pointer to the input buffer
+ UINTN RegNumber;
+ CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array
+ CHAR8 *RegNumBufPtr;
+ CHAR8 *InBufPtr; // pointer to the input buffer
// find the register number to write
- InBufPtr = &InBuffer[1];
+ InBufPtr = &InBuffer[1];
RegNumBufPtr = RegNumBuffer;
while (*InBufPtr != '=') {
*RegNumBufPtr++ = *InBufPtr++;
}
+
*RegNumBufPtr = '\0';
- RegNumber = AsciiStrHexToUintn (RegNumBuffer);
+ RegNumber = AsciiStrHexToUintn (RegNumBuffer);
// check if this is a valid Register Number
if (RegNumber >= MaxRegisterCount ()) {
SendError (GDB_EINVALIDREGNUM);
return;
}
+
InBufPtr++; // skips the '=' character
BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
- SendSuccess();
+ SendSuccess ();
}
-
/** ‘G XX...’
Writes the new values received into the input buffer to the general registers
@param SystemContext Register content at time of the exception
@param InBuffer Pointer to the input buffer received from gdb server
**/
-
VOID
EFIAPI
WriteGeneralRegisters (
@@ -352,7 +350,7 @@ WriteGeneralRegisters (
MinLength = (RegisterCount * 8) + 1; // 'G' plus the registers in ASCII format
if (AsciiStrLen (InBuffer) < MinLength) {
- //Bad message. Message is not the right length
+ // Bad message. Message is not the right length
SendError (GDB_EBADBUFSIZE);
return;
}
@@ -370,21 +368,21 @@ WriteGeneralRegisters (
// What about Thumb?
// Use SWI 0xdbdbdb as the debug instruction
-#define GDB_ARM_BKPT 0xefdbdbdb
+#define GDB_ARM_BKPT 0xefdbdbdb
-BOOLEAN mSingleStepActive = FALSE;
-UINT32 mSingleStepPC;
-UINT32 mSingleStepData;
-UINTN mSingleStepDataSize;
+BOOLEAN mSingleStepActive = FALSE;
+UINT32 mSingleStepPC;
+UINT32 mSingleStepData;
+UINTN mSingleStepDataSize;
typedef struct {
- LIST_ENTRY Link;
- UINT64 Signature;
- UINT32 Address;
- UINT32 Instruction;
+ LIST_ENTRY Link;
+ UINT64 Signature;
+ UINT32 Address;
+ UINT32 Instruction;
} ARM_SOFTWARE_BREAKPOINT;
-#define ARM_SOFTWARE_BREAKPOINT_SIGNATURE SIGNATURE_64('A', 'R', 'M', 'B', 'R', 'K', 'P', 'T')
+#define ARM_SOFTWARE_BREAKPOINT_SIGNATURE SIGNATURE_64('A', 'R', 'M', 'B', 'R', 'K', 'P', 'T')
#define ARM_SOFTWARE_BREAKPOINT_FROM_LINK(a) CR(a, ARM_SOFTWARE_BREAKPOINT, Link, ARM_SOFTWARE_BREAKPOINT_SIGNATURE)
LIST_ENTRY BreakpointList;
@@ -396,19 +394,20 @@ LIST_ENTRY BreakpointList;
**/
VOID
AddSingleStep (
- IN EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_SYSTEM_CONTEXT SystemContext
)
{
if (mSingleStepActive) {
// Currently don't support nesting
return;
}
+
mSingleStepActive = TRUE;
mSingleStepPC = SystemContext.SystemContextArm->PC;
- mSingleStepDataSize = sizeof (UINT32);
- mSingleStepData = (*(UINT32 *)mSingleStepPC);
+ mSingleStepDataSize = sizeof (UINT32);
+ mSingleStepData = (*(UINT32 *)mSingleStepPC);
*(UINT32 *)mSingleStepPC = GDB_ARM_BKPT;
if (*(UINT32 *)mSingleStepPC != GDB_ARM_BKPT) {
// For some reason our breakpoint did not take
@@ -416,10 +415,9 @@ AddSingleStep (
}
InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize);
- //DEBUG((DEBUG_ERROR, "AddSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, mSingleStepData, *(UINT32 *)mSingleStepPC));
+ // DEBUG((DEBUG_ERROR, "AddSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, mSingleStepData, *(UINT32 *)mSingleStepPC));
}
-
/**
Remove Single Step in the SystemContext
@@ -437,15 +435,14 @@ RemoveSingleStep (
if (mSingleStepDataSize == sizeof (UINT16)) {
*(UINT16 *)mSingleStepPC = (UINT16)mSingleStepData;
} else {
- //DEBUG((DEBUG_ERROR, "RemoveSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, *(UINT32 *)mSingleStepPC, mSingleStepData));
+ // DEBUG((DEBUG_ERROR, "RemoveSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, *(UINT32 *)mSingleStepPC, mSingleStepData));
*(UINT32 *)mSingleStepPC = mSingleStepData;
}
+
InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize);
mSingleStepActive = FALSE;
}
-
-
/**
Continue. addr is Address to resume. If addr is omitted, resume at current
Address.
@@ -455,8 +452,8 @@ RemoveSingleStep (
VOID
EFIAPI
ContinueAtAddress (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *PacketData
)
{
if (PacketData[1] != '\0') {
@@ -464,7 +461,6 @@ ContinueAtAddress (
}
}
-
/** ‘s [addr ]’
Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address.
@@ -474,8 +470,8 @@ ContinueAtAddress (
VOID
EFIAPI
SingleStep (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *PacketData
)
{
SendNotSupported ();
@@ -512,12 +508,12 @@ SearchBreakpointList (
IN UINT32 Address
)
{
- LIST_ENTRY *Current;
- ARM_SOFTWARE_BREAKPOINT *Breakpoint;
+ LIST_ENTRY *Current;
+ ARM_SOFTWARE_BREAKPOINT *Breakpoint;
Current = GetFirstNode (&BreakpointList);
while (!IsNull (&BreakpointList, Current)) {
- Breakpoint = ARM_SOFTWARE_BREAKPOINT_FROM_LINK(Current);
+ Breakpoint = ARM_SOFTWARE_BREAKPOINT_FROM_LINK (Current);
if (Address == Breakpoint->Address) {
return Breakpoint;
@@ -531,10 +527,10 @@ SearchBreakpointList (
VOID
SetBreakpoint (
- IN UINT32 Address
+ IN UINT32 Address
)
{
- ARM_SOFTWARE_BREAKPOINT *Breakpoint;
+ ARM_SOFTWARE_BREAKPOINT *Breakpoint;
Breakpoint = SearchBreakpointList (Address);
@@ -543,7 +539,7 @@ SetBreakpoint (
}
// create and fill breakpoint structure
- Breakpoint = AllocatePool (sizeof(ARM_SOFTWARE_BREAKPOINT));
+ Breakpoint = AllocatePool (sizeof (ARM_SOFTWARE_BREAKPOINT));
Breakpoint->Signature = ARM_SOFTWARE_BREAKPOINT_SIGNATURE;
Breakpoint->Address = Address;
@@ -556,15 +552,15 @@ SetBreakpoint (
*(UINT32 *)Address = GDB_ARM_BKPT;
InvalidateInstructionCacheRange ((VOID *)Address, 4);
- //DEBUG((DEBUG_ERROR, "SetBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, Breakpoint->Instruction, *(UINT32 *)Address));
+ // DEBUG((DEBUG_ERROR, "SetBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, Breakpoint->Instruction, *(UINT32 *)Address));
}
VOID
ClearBreakpoint (
- IN UINT32 Address
+ IN UINT32 Address
)
{
- ARM_SOFTWARE_BREAKPOINT *Breakpoint;
+ ARM_SOFTWARE_BREAKPOINT *Breakpoint;
Breakpoint = SearchBreakpointList (Address);
@@ -579,7 +575,7 @@ ClearBreakpoint (
*(UINT32 *)Address = Breakpoint->Instruction;
InvalidateInstructionCacheRange ((VOID *)Address, 4);
- //DEBUG((DEBUG_ERROR, "ClearBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, GDB_ARM_BKPT, *(UINT32 *)Address));
+ // DEBUG((DEBUG_ERROR, "ClearBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, GDB_ARM_BKPT, *(UINT32 *)Address));
FreePool (Breakpoint);
}
@@ -588,13 +584,13 @@ VOID
EFIAPI
InsertBreakPoint (
IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN CHAR8 *PacketData
)
{
- UINTN Type;
- UINTN Address;
- UINTN Length;
- UINTN ErrorCode;
+ UINTN Type;
+ UINTN Address;
+ UINTN Length;
+ UINTN ErrorCode;
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
if (ErrorCode > 0) {
@@ -603,11 +599,11 @@ InsertBreakPoint (
}
switch (Type) {
- case 0: //Software breakpoint
+ case 0: // Software breakpoint
break;
- default :
- DEBUG((DEBUG_ERROR, "Insert breakpoint default: %x\n", Type));
+ default:
+ DEBUG ((DEBUG_ERROR, "Insert breakpoint default: %x\n", Type));
SendError (GDB_EINVALIDBRKPOINTTYPE);
return;
}
@@ -624,12 +620,12 @@ RemoveBreakPoint (
IN CHAR8 *PacketData
)
{
- UINTN Type;
- UINTN Address;
- UINTN Length;
- UINTN ErrorCode;
+ UINTN Type;
+ UINTN Address;
+ UINTN Length;
+ UINTN ErrorCode;
- //Parse breakpoint packet data
+ // Parse breakpoint packet data
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
if (ErrorCode > 0) {
SendError ((UINT8)ErrorCode);
@@ -637,7 +633,7 @@ RemoveBreakPoint (
}
switch (Type) {
- case 0: //Software breakpoint
+ case 0: // Software breakpoint
break;
default:
@@ -673,8 +669,8 @@ ValidateAddress (
BOOLEAN
ValidateException (
- IN EFI_EXCEPTION_TYPE ExceptionType,
- IN OUT EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_EXCEPTION_TYPE ExceptionType,
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext
)
{
UINT32 ExceptionAddress;
diff --git a/EmbeddedPkg/GdbStub/GdbStub.c b/EmbeddedPkg/GdbStub/GdbStub.c
index dd035271a7..e6e07b87b6 100644
--- a/EmbeddedPkg/GdbStub/GdbStub.c
+++ b/EmbeddedPkg/GdbStub/GdbStub.c
@@ -14,43 +14,40 @@
#include <GdbStubInternal.h>
#include <Protocol/DebugPort.h>
-
-UINTN gMaxProcessorIndex = 0;
+UINTN gMaxProcessorIndex = 0;
//
// Buffers for basic gdb communication
//
-CHAR8 gInBuffer[MAX_BUF_SIZE];
-CHAR8 gOutBuffer[MAX_BUF_SIZE];
+CHAR8 gInBuffer[MAX_BUF_SIZE];
+CHAR8 gOutBuffer[MAX_BUF_SIZE];
// Assume gdb does a "qXfer:libraries:read::offset,length" when it connects so we can default
// this value to FALSE. Since gdb can reconnect its self a global default is not good enough
-BOOLEAN gSymbolTableUpdate = FALSE;
-EFI_EVENT gEvent;
-VOID *gGdbSymbolEventHandlerRegistration = NULL;
+BOOLEAN gSymbolTableUpdate = FALSE;
+EFI_EVENT gEvent;
+VOID *gGdbSymbolEventHandlerRegistration = NULL;
//
// Globals for returning XML from qXfer:libraries:read packet
//
-UINTN gPacketqXferLibraryOffset = 0;
-UINTN gEfiDebugImageTableEntry = 0;
-EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;
-EFI_DEBUG_IMAGE_INFO *gDebugTable = NULL;
-CHAR8 gXferLibraryBuffer[2000];
-
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
+UINTN gPacketqXferLibraryOffset = 0;
+UINTN gEfiDebugImageTableEntry = 0;
+EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;
+EFI_DEBUG_IMAGE_INFO *gDebugTable = NULL;
+CHAR8 gXferLibraryBuffer[2000];
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
VOID
EFIAPI
GdbSymbolEventHandler (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
}
-
/**
The user Entry Point for Application. The user code starts with this function
as the real entry point for the image goes into a library that calls this
@@ -103,7 +100,7 @@ GdbStubEntry (
Status = gBS->HandleProtocol (
Handles[HandleCount],
&gEfiDebugSupportProtocolGuid,
- (VOID **) &DebugSupport
+ (VOID **)&DebugSupport
);
if (!EFI_ERROR (Status)) {
if (CheckIsa (DebugSupport->Isa)) {
@@ -113,6 +110,7 @@ GdbStubEntry (
}
}
} while (HandleCount > 0);
+
FreePool (Handles);
if (!IsaSupported) {
@@ -132,9 +130,10 @@ GdbStubEntry (
for (Processor = 0; Processor <= gMaxProcessorIndex; Processor++) {
for (Index = 0; Index < MaxEfiException (); Index++) {
- Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor, GdbExceptionHandler, gExceptionType[Index].Exception);
+ Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor, GdbExceptionHandler, gExceptionType[Index].Exception);
ASSERT_EFI_ERROR (Status);
}
+
//
// Current edk2 DebugPort is not interrupt context safe so we can not use it
//
@@ -165,10 +164,9 @@ GdbStubEntry (
);
ASSERT_EFI_ERROR (Status);
-
- if (PcdGetBool (PcdGdbSerial)) {
- GdbInitializeSerialConsole ();
- }
+ if (PcdGetBool (PcdGdbSerial)) {
+ GdbInitializeSerialConsole ();
+ }
return EFI_SUCCESS;
}
@@ -180,16 +178,15 @@ GdbStubEntry (
@param *address the start address of the transferring/writing the memory
@param *new_data the new data to be written to memory
**/
-
VOID
TransferFromInBufToMem (
- IN UINTN Length,
- IN unsigned char *Address,
- IN CHAR8 *NewData
+ IN UINTN Length,
+ IN unsigned char *Address,
+ IN CHAR8 *NewData
)
{
- CHAR8 c1;
- CHAR8 c2;
+ CHAR8 c1;
+ CHAR8 c2;
while (Length-- > 0) {
c1 = (CHAR8)HexCharToInt (*NewData++);
@@ -200,13 +197,13 @@ TransferFromInBufToMem (
SendError (GDB_EBADMEMDATA);
return;
}
+
*Address++ = (UINT8)((c1 << 4) + c2);
}
- SendSuccess();
+ SendSuccess ();
}
-
/**
Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer
as a packet.
@@ -214,48 +211,46 @@ TransferFromInBufToMem (
@param Length the number of the bytes to be transferred/read
@param *address pointer to the start address of the transferring/reading the memory
**/
-
VOID
TransferFromMemToOutBufAndSend (
- IN UINTN Length,
- IN unsigned char *Address
+ IN UINTN Length,
+ IN unsigned char *Address
)
{
// there are Length bytes and every byte is represented as 2 hex chars
- CHAR8 OutBuffer[MAX_BUF_SIZE];
- CHAR8 *OutBufPtr; // pointer to the output buffer
- CHAR8 Char;
+ CHAR8 OutBuffer[MAX_BUF_SIZE];
+ CHAR8 *OutBufPtr; // pointer to the output buffer
+ CHAR8 Char;
- if (ValidateAddress(Address) == FALSE) {
- SendError(14);
+ if (ValidateAddress (Address) == FALSE) {
+ SendError (14);
return;
}
OutBufPtr = OutBuffer;
while (Length > 0) {
-
Char = mHexToStr[*Address >> 4];
if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a';
}
+
*OutBufPtr++ = Char;
Char = mHexToStr[*Address & 0x0f];
if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a';
}
+
*OutBufPtr++ = Char;
Address++;
Length--;
}
- *OutBufPtr = '\0' ; // the end of the buffer
+ *OutBufPtr = '\0'; // the end of the buffer
SendPacket (OutBuffer);
}
-
-
/**
Send a GDB Remote Serial Protocol Packet
@@ -273,20 +268,19 @@ TransferFromMemToOutBufAndSend (
**/
UINTN
SendPacket (
- IN CHAR8 *PacketData
+ IN CHAR8 *PacketData
)
{
- UINT8 CheckSum;
- UINTN Timeout;
- CHAR8 *Ptr;
- CHAR8 TestChar;
- UINTN Count;
+ UINT8 CheckSum;
+ UINTN Timeout;
+ CHAR8 *Ptr;
+ CHAR8 TestChar;
+ UINTN Count;
Timeout = PcdGet32 (PcdGdbMaxPacketRetryCount);
Count = 0;
do {
-
Ptr = PacketData;
if (Timeout-- == 0) {
@@ -297,7 +291,7 @@ SendPacket (
// Packet prefix
GdbPutChar ('$');
- for (CheckSum = 0, Count =0 ; *Ptr != '\0'; Ptr++, Count++) {
+ for (CheckSum = 0, Count = 0; *Ptr != '\0'; Ptr++, Count++) {
GdbPutChar (*Ptr);
CheckSum = CheckSum + *Ptr;
}
@@ -331,38 +325,40 @@ SendPacket (
**/
UINTN
ReceivePacket (
- OUT CHAR8 *PacketData,
- IN UINTN PacketDataSize
- )
+ OUT CHAR8 *PacketData,
+ IN UINTN PacketDataSize
+ )
{
- UINT8 CheckSum;
- UINTN Index;
- CHAR8 Char;
- CHAR8 SumString[3];
- CHAR8 TestChar;
+ UINT8 CheckSum;
+ UINTN Index;
+ CHAR8 Char;
+ CHAR8 SumString[3];
+ CHAR8 TestChar;
ZeroMem (PacketData, PacketDataSize);
- for (;;) {
- // wait for the start of a packet
+ for ( ; ;) {
+ // wait for the start of a packet
TestChar = GdbGetChar ();
while (TestChar != '$') {
TestChar = GdbGetChar ();
- };
+ }
- retry:
+retry:
for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) {
Char = GdbGetChar ();
if (Char == '$') {
goto retry;
}
+
if (Char == '#') {
break;
}
PacketData[Index] = Char;
- CheckSum = CheckSum + Char;
+ CheckSum = CheckSum + Char;
}
+
PacketData[Index] = '\0';
if (Index == PacketDataSize) {
@@ -386,23 +382,21 @@ ReceivePacket (
}
}
- //return 0;
+ // return 0;
}
-
/**
Empties the given buffer
@param Buf pointer to the first element in buffer to be emptied
**/
VOID
EmptyBuffer (
- IN CHAR8 *Buf
+ IN CHAR8 *Buf
)
{
*Buf = '\0';
}
-
/**
Converts an 8-bit Hex Char into a INTN.
@@ -412,7 +406,7 @@ EmptyBuffer (
**/
INTN
HexCharToInt (
- IN CHAR8 Char
+ IN CHAR8 Char
)
{
if ((Char >= 'A') && (Char <= 'F')) {
@@ -421,13 +415,14 @@ HexCharToInt (
return Char - 'a' + 10;
} else if ((Char >= '0') && (Char <= '9')) {
return Char - '0';
- } else { // if not a hex value, return a negative value
+ } else {
+ // if not a hex value, return a negative value
return -1;
}
}
- // 'E' + the biggest error number is 255, so its 2 hex digits + buffer end
-CHAR8 *gError = "E__";
+// 'E' + the biggest error number is 255, so its 2 hex digits + buffer end
+CHAR8 *gError = "E__";
/** 'E NN'
Send an error with the given error number after converting to hex.
@@ -439,20 +434,18 @@ CHAR8 *gError = "E__";
VOID
EFIAPI
SendError (
- IN UINT8 ErrorNum
+ IN UINT8 ErrorNum
)
{
//
// Replace _, or old data, with current errno
//
- gError[1] = mHexToStr [ErrorNum >> 4];
- gError[2] = mHexToStr [ErrorNum & 0x0f];
+ gError[1] = mHexToStr[ErrorNum >> 4];
+ gError[2] = mHexToStr[ErrorNum & 0x0f];
SendPacket (gError); // send buffer
}
-
-
/**
Send 'OK' when the function is done executing successfully.
**/
@@ -465,7 +458,6 @@ SendSuccess (
SendPacket ("OK"); // send buffer
}
-
/**
Send empty packet to specify that particular command/functionality is not supported.
**/
@@ -478,7 +470,6 @@ SendNotSupported (
SendPacket ("");
}
-
/**
Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
@@ -491,24 +482,24 @@ GdbSendTSignal (
IN UINT8 GdbExceptionType
)
{
- CHAR8 TSignalBuffer[128];
- CHAR8 *TSignalPtr;
- UINTN BreakpointDetected;
- BREAK_TYPE BreakType;
- UINTN DataAddress;
- CHAR8 *WatchStrPtr = NULL;
- UINTN RegSize;
+ CHAR8 TSignalBuffer[128];
+ CHAR8 *TSignalPtr;
+ UINTN BreakpointDetected;
+ BREAK_TYPE BreakType;
+ UINTN DataAddress;
+ CHAR8 *WatchStrPtr = NULL;
+ UINTN RegSize;
TSignalPtr = &TSignalBuffer[0];
- //Construct TSignal packet
+ // Construct TSignal packet
*TSignalPtr++ = 'T';
//
// replace _, or previous value, with Exception type
//
- *TSignalPtr++ = mHexToStr [GdbExceptionType >> 4];
- *TSignalPtr++ = mHexToStr [GdbExceptionType & 0x0f];
+ *TSignalPtr++ = mHexToStr[GdbExceptionType >> 4];
+ *TSignalPtr++ = mHexToStr[GdbExceptionType & 0x0f];
if (GdbExceptionType == GDB_SIGTRAP) {
if (gSymbolTableUpdate) {
@@ -519,27 +510,25 @@ GdbSendTSignal (
while (*WatchStrPtr != '\0') {
*TSignalPtr++ = *WatchStrPtr++;
}
+
gSymbolTableUpdate = FALSE;
} else {
-
-
//
// possible n:r pairs
//
- //Retrieve the breakpoint number
+ // Retrieve the breakpoint number
BreakpointDetected = GetBreakpointDetected (SystemContext);
- //Figure out if the exception is happend due to watch, rwatch or awatch.
+ // Figure out if the exception is happend due to watch, rwatch or awatch.
BreakType = GetBreakpointType (SystemContext, BreakpointDetected);
- //INFO: rwatch is not supported due to the way IA32 debug registers work
+ // INFO: rwatch is not supported due to the way IA32 debug registers work
if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) {
-
- //Construct n:r pair
+ // Construct n:r pair
DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected);
- //Assign appropriate buffer to print particular watchpoint type
+ // Assign appropriate buffer to print particular watchpoint type
if (BreakType == DataWrite) {
WatchStrPtr = "watch";
} else if (BreakType == DataRead) {
@@ -554,14 +543,14 @@ GdbSendTSignal (
*TSignalPtr++ = ':';
- //Set up series of bytes in big-endian byte order. "awatch" won't work with little-endian byte order.
+ // Set up series of bytes in big-endian byte order. "awatch" won't work with little-endian byte order.
RegSize = REG_SIZE;
while (RegSize > 0) {
- RegSize = RegSize-4;
+ RegSize = RegSize-4;
*TSignalPtr++ = mHexToStr[(UINT8)(DataAddress >> RegSize) & 0xf];
}
- //Always end n:r pair with ';'
+ // Always end n:r pair with ';'
*TSignalPtr++ = ';';
}
}
@@ -572,7 +561,6 @@ GdbSendTSignal (
SendPacket (TSignalBuffer);
}
-
/**
Translates the EFI mapping to GDB mapping
@@ -581,68 +569,67 @@ GdbSendTSignal (
**/
UINT8
ConvertEFItoGDBtype (
- IN EFI_EXCEPTION_TYPE EFIExceptionType
+ IN EFI_EXCEPTION_TYPE EFIExceptionType
)
{
- UINTN Index;
+ UINTN Index;
- for (Index = 0; Index < MaxEfiException () ; Index++) {
+ for (Index = 0; Index < MaxEfiException (); Index++) {
if (gExceptionType[Index].Exception == EFIExceptionType) {
return gExceptionType[Index].SignalNo;
}
}
+
return GDB_SIGTRAP; // this is a GDB trap
}
-
/** "m addr,length"
Find the Length of the area to read and the start address. Finally, pass them to
another function, TransferFromMemToOutBufAndSend, that will read from that memory space and
send it as a packet.
**/
-
VOID
EFIAPI
ReadFromMemory (
- CHAR8 *PacketData
+ CHAR8 *PacketData
)
{
- UINTN Address;
- UINTN Length;
- CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars
- CHAR8 *AddrBufPtr; // pointer to the address buffer
- CHAR8 *InBufPtr; /// pointer to the input buffer
+ UINTN Address;
+ UINTN Length;
+ CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the address in hex chars
+ CHAR8 *AddrBufPtr; // pointer to the address buffer
+ CHAR8 *InBufPtr; /// pointer to the input buffer
AddrBufPtr = AddressBuffer;
- InBufPtr = &PacketData[1];
+ InBufPtr = &PacketData[1];
while (*InBufPtr != ',') {
*AddrBufPtr++ = *InBufPtr++;
}
+
*AddrBufPtr = '\0';
InBufPtr++; // this skips ',' in the buffer
/* Error checking */
if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {
- Print((CHAR16 *)L"Address is too long\n");
+ Print ((CHAR16 *)L"Address is too long\n");
SendError (GDB_EBADMEMADDRBUFSIZE);
return;
}
// 2 = 'm' + ','
if (AsciiStrLen (PacketData) - AsciiStrLen (AddressBuffer) - 2 >= MAX_LENGTH_SIZE) {
- Print((CHAR16 *)L"Length is too long\n");
+ Print ((CHAR16 *)L"Length is too long\n");
SendError (GDB_EBADMEMLENGTH);
return;
}
Address = AsciiStrHexToUintn (AddressBuffer);
- Length = AsciiStrHexToUintn (InBufPtr);
+ Length = AsciiStrHexToUintn (InBufPtr);
TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address);
}
-
/** "M addr,length :XX..."
Find the Length of the area in bytes to write and the start address. Finally, pass them to
another function, TransferFromInBufToMem, that will write to that memory space the info in
@@ -651,25 +638,26 @@ ReadFromMemory (
VOID
EFIAPI
WriteToMemory (
- IN CHAR8 *PacketData
+ IN CHAR8 *PacketData
)
{
- UINTN Address;
- UINTN Length;
- UINTN MessageLength;
- CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the Address in hex chars
- CHAR8 LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars
- CHAR8 *AddrBufPtr; // pointer to the Address buffer
- CHAR8 *LengthBufPtr; // pointer to the Length buffer
- CHAR8 *InBufPtr; /// pointer to the input buffer
-
- AddrBufPtr = AddressBuffer;
+ UINTN Address;
+ UINTN Length;
+ UINTN MessageLength;
+ CHAR8 AddressBuffer[MAX_ADDR_SIZE]; // the buffer that will hold the Address in hex chars
+ CHAR8 LengthBuffer[MAX_LENGTH_SIZE]; // the buffer that will hold the Length in hex chars
+ CHAR8 *AddrBufPtr; // pointer to the Address buffer
+ CHAR8 *LengthBufPtr; // pointer to the Length buffer
+ CHAR8 *InBufPtr; /// pointer to the input buffer
+
+ AddrBufPtr = AddressBuffer;
LengthBufPtr = LengthBuffer;
- InBufPtr = &PacketData[1];
+ InBufPtr = &PacketData[1];
while (*InBufPtr != ',') {
*AddrBufPtr++ = *InBufPtr++;
}
+
*AddrBufPtr = '\0';
InBufPtr++; // this skips ',' in the buffer
@@ -677,23 +665,24 @@ WriteToMemory (
while (*InBufPtr != ':') {
*LengthBufPtr++ = *InBufPtr++;
}
+
*LengthBufPtr = '\0';
InBufPtr++; // this skips ':' in the buffer
Address = AsciiStrHexToUintn (AddressBuffer);
- Length = AsciiStrHexToUintn (LengthBuffer);
+ Length = AsciiStrHexToUintn (LengthBuffer);
/* Error checking */
- //Check if Address is not too long.
+ // Check if Address is not too long.
if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {
Print ((CHAR16 *)L"Address too long..\n");
SendError (GDB_EBADMEMADDRBUFSIZE);
return;
}
- //Check if message length is not too long
+ // Check if message length is not too long
if (AsciiStrLen (LengthBuffer) >= MAX_LENGTH_SIZE) {
Print ((CHAR16 *)L"Length too long..\n");
SendError (GDB_EBADMEMLENGBUFSIZE);
@@ -704,10 +693,11 @@ WriteToMemory (
// 3 = 'M' + ',' + ':'
MessageLength = (AsciiStrLen (PacketData) - AsciiStrLen (AddressBuffer) - AsciiStrLen (LengthBuffer) - 3);
if (MessageLength != (2*Length)) {
- //Message too long/short. New data is not the right size.
+ // Message too long/short. New data is not the right size.
SendError (GDB_EBADMEMDATASIZE);
return;
}
+
TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr);
}
@@ -727,72 +717,74 @@ WriteToMemory (
**/
UINTN
ParseBreakpointPacket (
- IN CHAR8 *PacketData,
- OUT UINTN *Type,
- OUT UINTN *Address,
- OUT UINTN *Length
+ IN CHAR8 *PacketData,
+ OUT UINTN *Type,
+ OUT UINTN *Address,
+ OUT UINTN *Length
)
{
- CHAR8 AddressBuffer[MAX_ADDR_SIZE];
- CHAR8 *AddressBufferPtr;
- CHAR8 *PacketDataPtr;
+ CHAR8 AddressBuffer[MAX_ADDR_SIZE];
+ CHAR8 *AddressBufferPtr;
+ CHAR8 *PacketDataPtr;
- PacketDataPtr = &PacketData[1];
+ PacketDataPtr = &PacketData[1];
AddressBufferPtr = AddressBuffer;
*Type = AsciiStrHexToUintn (PacketDataPtr);
- //Breakpoint/watchpoint type should be between 0 to 4
+ // Breakpoint/watchpoint type should be between 0 to 4
if (*Type > 4) {
Print ((CHAR16 *)L"Type is invalid\n");
- return 22; //EINVAL: Invalid argument.
+ return 22; // EINVAL: Invalid argument.
}
- //Skip ',' in the buffer.
- while (*PacketDataPtr++ != ',');
+ // Skip ',' in the buffer.
+ while (*PacketDataPtr++ != ',') {
+ }
- //Parse Address information
+ // Parse Address information
while (*PacketDataPtr != ',') {
*AddressBufferPtr++ = *PacketDataPtr++;
}
+
*AddressBufferPtr = '\0';
- //Check if Address is not too long.
+ // Check if Address is not too long.
if (AsciiStrLen (AddressBuffer) >= MAX_ADDR_SIZE) {
Print ((CHAR16 *)L"Address too long..\n");
- return 40; //EMSGSIZE: Message size too long.
+ return 40; // EMSGSIZE: Message size too long.
}
*Address = AsciiStrHexToUintn (AddressBuffer);
- PacketDataPtr++; //This skips , in the buffer
+ PacketDataPtr++; // This skips , in the buffer
- //Parse Length information
+ // Parse Length information
*Length = AsciiStrHexToUintn (PacketDataPtr);
- //Length should be 1, 2 or 4 bytes
+ // Length should be 1, 2 or 4 bytes
if (*Length > 4) {
Print ((CHAR16 *)L"Length is invalid\n");
- return 22; //EINVAL: Invalid argument
+ return 22; // EINVAL: Invalid argument
}
- return 0; //0 = No error
+ return 0; // 0 = No error
}
UINTN
gXferObjectReadResponse (
- IN CHAR8 Type,
- IN CHAR8 *Str
+ IN CHAR8 Type,
+ IN CHAR8 *Str
)
{
- CHAR8 *OutBufPtr; // pointer to the output buffer
- CHAR8 Char;
- UINTN Count;
+ CHAR8 *OutBufPtr; // pointer to the output buffer
+ CHAR8 Char;
+ UINTN Count;
// Response starts with 'm' or 'l' if it is the end
- OutBufPtr = gOutBuffer;
+ OutBufPtr = gOutBuffer;
*OutBufPtr++ = Type;
- Count = 1;
+ Count = 1;
// Binary data encoding
OutBufPtr = gOutBuffer;
@@ -804,17 +796,17 @@ gXferObjectReadResponse (
Char ^= 0x20;
}
+
*OutBufPtr++ = Char;
Count++;
}
- *OutBufPtr = '\0' ; // the end of the buffer
+ *OutBufPtr = '\0'; // the end of the buffer
SendPacket (gOutBuffer);
return Count;
}
-
/**
Note: This should be a library function. In the Apple case you have to add
the size of the PE/COFF header into the starting address to make things work
@@ -844,20 +836,20 @@ gXferObjectReadResponse (
VOID *
EFIAPI
PeCoffLoaderGetDebuggerInfo (
- IN VOID *Pe32Data,
- OUT VOID **DebugBase
+ IN VOID *Pe32Data,
+ OUT VOID **DebugBase
)
{
- EFI_IMAGE_DOS_HEADER *DosHdr;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
- EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
- EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
- UINTN DirCount;
- VOID *CodeViewEntryPointer;
- INTN TEImageAdjust;
- UINT32 NumberOfRvaAndSizes;
- UINT16 Magic;
- UINTN SizeOfHeaders;
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
+ EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
+ UINTN DirCount;
+ VOID *CodeViewEntryPointer;
+ INTN TEImageAdjust;
+ UINT32 NumberOfRvaAndSizes;
+ UINT16 Magic;
+ UINTN SizeOfHeaders;
ASSERT (Pe32Data != NULL);
@@ -872,7 +864,7 @@ PeCoffLoaderGetDebuggerInfo (
//
// DOS image header is present, so read the PE header after the DOS image header.
//
- Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHdr->e_lfanew) & 0x0ffff));
} else {
//
// DOS image header is not present, so PE header is at the image base.
@@ -882,91 +874,90 @@ PeCoffLoaderGetDebuggerInfo (
if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
- DirectoryEntry = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
- TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;
- DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +
- Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
- TEImageAdjust);
+ DirectoryEntry = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
+ TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN)Hdr.Te +
+ Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
+ TEImageAdjust);
}
+
SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
// __APPLE__ check this math...
*DebugBase = ((CHAR8 *)Pe32Data) - TEImageAdjust;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
-
*DebugBase = Pe32Data;
-
//
// NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.
// It is due to backward-compatibility, for some system might
// generate PE32+ image with PE32 Magic.
//
switch (Hdr.Pe32->FileHeader.Machine) {
- case EFI_IMAGE_MACHINE_IA32:
- //
- // Assume PE32 image with IA32 Machine field.
- //
- Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
- break;
- case EFI_IMAGE_MACHINE_X64:
- case EFI_IMAGE_MACHINE_IA64:
- //
- // Assume PE32+ image with X64 or IPF Machine field
- //
- Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
- break;
- default:
- //
- // For unknown Machine field, use Magic in optional Header
- //
- Magic = Hdr.Pe32->OptionalHeader.Magic;
+ case EFI_IMAGE_MACHINE_IA32:
+ //
+ // Assume PE32 image with IA32 Machine field.
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
+ break;
+ case EFI_IMAGE_MACHINE_X64:
+ case EFI_IMAGE_MACHINE_IA64:
+ //
+ // Assume PE32+ image with X64 or IPF Machine field
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
+ break;
+ default:
+ //
+ // For unknown Machine field, use Magic in optional Header
+ //
+ Magic = Hdr.Pe32->OptionalHeader.Magic;
}
if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
//
// Use PE32 offset get Debug Directory Entry
//
- SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
+ SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders;
NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;
- DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
- DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN)Pe32Data + DirectoryEntry->VirtualAddress);
} else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
//
// Use PE32+ offset get Debug Directory Entry
//
- SizeOfHeaders = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;
+ SizeOfHeaders = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;
NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
- DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
- DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN)Pe32Data + DirectoryEntry->VirtualAddress);
}
if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
DirectoryEntry = NULL;
- DebugEntry = NULL;
+ DebugEntry = NULL;
}
} else {
return NULL;
}
- if (DebugEntry == NULL || DirectoryEntry == NULL) {
+ if ((DebugEntry == NULL) || (DirectoryEntry == NULL)) {
return NULL;
}
for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
if (DebugEntry->SizeOfData > 0) {
- CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);
- switch (* (UINT32 *) CodeViewEntryPointer) {
- case CODEVIEW_SIGNATURE_NB10:
- return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));
- case CODEVIEW_SIGNATURE_RSDS:
- return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));
- case CODEVIEW_SIGNATURE_MTOC:
- *DebugBase = (VOID *)(UINTN)((UINTN)DebugBase - SizeOfHeaders);
- return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));
- default:
- break;
+ CodeViewEntryPointer = (VOID *)((UINTN)DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);
+ switch (*(UINT32 *)CodeViewEntryPointer) {
+ case CODEVIEW_SIGNATURE_NB10:
+ return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));
+ case CODEVIEW_SIGNATURE_RSDS:
+ return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));
+ case CODEVIEW_SIGNATURE_MTOC:
+ *DebugBase = (VOID *)(UINTN)((UINTN)DebugBase - SizeOfHeaders);
+ return (VOID *)((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY));
+ default:
+ break;
}
}
}
@@ -976,7 +967,6 @@ PeCoffLoaderGetDebuggerInfo (
return NULL;
}
-
/**
Process "qXfer:object:read:annex:offset,length" request.
@@ -1012,13 +1002,13 @@ PeCoffLoaderGetDebuggerInfo (
**/
VOID
QxferLibrary (
- IN UINTN Offset,
- IN UINTN Length
+ IN UINTN Offset,
+ IN UINTN Length
)
{
- VOID *LoadAddress;
- CHAR8 *Pdb;
- UINTN Size;
+ VOID *LoadAddress;
+ CHAR8 *Pdb;
+ UINTN Size;
if (Offset != gPacketqXferLibraryOffset) {
SendError (GDB_EINVALIDARG);
@@ -1036,28 +1026,29 @@ QxferLibrary (
// The owner of the table may have had to ralloc it so grab a fresh copy every time
// we assume qXferLibrary will get called over and over again until the entire XML table is
// returned in a tight loop. Since we are in the debugger the table should not get updated
- gDebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;
+ gDebugTable = gDebugImageTableHeader->EfiDebugImageInfoTable;
gEfiDebugImageTableEntry = 0;
return;
}
if (gDebugTable != NULL) {
- for (; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {
+ for ( ; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {
if (gDebugTable->NormalImage != NULL) {
if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
- (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) {
+ (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL))
+ {
Pdb = PeCoffLoaderGetDebuggerInfo (
- gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase,
- &LoadAddress
- );
+ gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase,
+ &LoadAddress
+ );
if (Pdb != NULL) {
Size = AsciiSPrint (
- gXferLibraryBuffer,
- sizeof (gXferLibraryBuffer),
- " <library name=\"%a\"><segment address=\"0x%p\"/></library>\n",
- Pdb,
- LoadAddress
- );
+ gXferLibraryBuffer,
+ sizeof (gXferLibraryBuffer),
+ " <library name=\"%a\"><segment address=\"0x%p\"/></library>\n",
+ Pdb,
+ LoadAddress
+ );
if ((Size != 0) && (Size != (sizeof (gXferLibraryBuffer) - 1))) {
gPacketqXferLibraryOffset += gXferObjectReadResponse ('m', gXferLibraryBuffer);
@@ -1080,13 +1071,11 @@ QxferLibrary (
}
}
-
gXferObjectReadResponse ('l', "</library-list>\n");
gPacketqXferLibraryOffset = 0;
return;
}
-
/**
Exception Handler for GDB. It will be called for all exceptions
registered via the gExceptionType[] array.
@@ -1097,13 +1086,12 @@ QxferLibrary (
VOID
EFIAPI
GdbExceptionHandler (
- IN EFI_EXCEPTION_TYPE ExceptionType,
- IN OUT EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_EXCEPTION_TYPE ExceptionType,
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext
)
{
- UINT8 GdbExceptionType;
- CHAR8 *Ptr;
-
+ UINT8 GdbExceptionType;
+ CHAR8 *Ptr;
if (ValidateException (ExceptionType, SystemContext) == FALSE) {
return;
@@ -1114,7 +1102,7 @@ GdbExceptionHandler (
GdbExceptionType = ConvertEFItoGDBtype (ExceptionType);
GdbSendTSignal (SystemContext, GdbExceptionType);
- for( ; ; ) {
+ for ( ; ; ) {
ReceivePacket (gInBuffer, MAX_BUF_SIZE);
switch (gInBuffer[0]) {
@@ -1135,7 +1123,7 @@ GdbExceptionHandler (
break;
case 'H':
- //Return "OK" packet since we don't have more than one thread.
+ // Return "OK" packet since we don't have more than one thread.
SendSuccess ();
break;
@@ -1163,17 +1151,21 @@ GdbExceptionHandler (
} else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) {
// ‘qXfer:libraries:read::offset,length
// gInBuffer[22] is offset string, ++Ptr is length string’
- for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++);
+ for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++) {
+ }
// Not sure if multi-radix support is required. Currently only support decimal
QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr));
- } if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {
+ }
+
+ if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {
AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000");
SendPacket (gOutBuffer);
} else {
- //Send empty packet
+ // Send empty packet
SendNotSupported ();
}
+
break;
case 's':
@@ -1189,14 +1181,13 @@ GdbExceptionHandler (
break;
default:
- //Send empty packet
+ // Send empty packet
SendNotSupported ();
break;
}
}
}
-
/**
Periodic callback for GDB. This function is used to catch a ctrl-c or other
break in type command from GDB.
@@ -1206,7 +1197,7 @@ GdbExceptionHandler (
VOID
EFIAPI
GdbPeriodicCallBack (
- IN OUT EFI_SYSTEM_CONTEXT SystemContext
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext
)
{
//
diff --git a/EmbeddedPkg/GdbStub/GdbStubInternal.h b/EmbeddedPkg/GdbStub/GdbStubInternal.h
index b08159302c..9c3929c812 100644
--- a/EmbeddedPkg/GdbStub/GdbStubInternal.h
+++ b/EmbeddedPkg/GdbStub/GdbStubInternal.h
@@ -28,54 +28,51 @@
#include <Guid/DebugImageInfoTable.h>
#include <IndustryStandard/PeImage.h>
-extern CONST CHAR8 mHexToStr[];
+extern CONST CHAR8 mHexToStr[];
// maximum size of input and output buffers
// This value came from the show remote command of the gdb we tested against
-#define MAX_BUF_SIZE 2000
+#define MAX_BUF_SIZE 2000
// maximum size of address buffer
-#define MAX_ADDR_SIZE 32
+#define MAX_ADDR_SIZE 32
// maximum size of register number buffer
-#define MAX_REG_NUM_BUF_SIZE 32
+#define MAX_REG_NUM_BUF_SIZE 32
// maximum size of length buffer
-#define MAX_LENGTH_SIZE 32
+#define MAX_LENGTH_SIZE 32
// maximum size of T signal members
-#define MAX_T_SIGNAL_SIZE 64
+#define MAX_T_SIGNAL_SIZE 64
// the mask used to clear all the cache
-#define TF_BIT 0x00000100
-
+#define TF_BIT 0x00000100
//
// GDB Signal definitions - generic names for interrupts
//
-#define GDB_SIGILL 4 // Illegal instruction
-#define GDB_SIGTRAP 5 // Trace Trap (Breakpoint and SingleStep)
-#define GDB_SIGEMT 7 // Emulator Trap
-#define GDB_SIGFPE 8 // Floating point exception
-#define GDB_SIGSEGV 11 // Segment violation, page fault
-
+#define GDB_SIGILL 4 // Illegal instruction
+#define GDB_SIGTRAP 5 // Trace Trap (Breakpoint and SingleStep)
+#define GDB_SIGEMT 7 // Emulator Trap
+#define GDB_SIGFPE 8 // Floating point exception
+#define GDB_SIGSEGV 11 // Segment violation, page fault
//
// GDB File I/O Error values, zero means no error
// Includes all general GDB Unix like error values
//
-#define GDB_EBADMEMADDRBUFSIZE 11 // the buffer that stores memory Address to be read from/written to is not the right size
-#define GDB_EBADMEMLENGBUFSIZE 12 // the buffer that stores Length is not the right size
-#define GDB_EBADMEMLENGTH 13 // Length, the given number of bytes to read or write, is not the right size
-#define GDB_EBADMEMDATA 14 // one of the bytes or nibbles of the memory is less than 0
-#define GDB_EBADMEMDATASIZE 15 // the memory data, 'XX..', is too short or too long
-#define GDB_EBADBUFSIZE 21 // the buffer created is not the correct size
-#define GDB_EINVALIDARG 31 // argument is invalid
-#define GDB_ENOSPACE 41 //
-#define GDB_EINVALIDBRKPOINTTYPE 51 // the breakpoint type is not recognized
-#define GDB_EINVALIDREGNUM 61 // given register number is not valid: either <0 or >=Number of Registers
-#define GDB_EUNKNOWN 255 // unknown
-
+#define GDB_EBADMEMADDRBUFSIZE 11 // the buffer that stores memory Address to be read from/written to is not the right size
+#define GDB_EBADMEMLENGBUFSIZE 12 // the buffer that stores Length is not the right size
+#define GDB_EBADMEMLENGTH 13 // Length, the given number of bytes to read or write, is not the right size
+#define GDB_EBADMEMDATA 14 // one of the bytes or nibbles of the memory is less than 0
+#define GDB_EBADMEMDATASIZE 15 // the memory data, 'XX..', is too short or too long
+#define GDB_EBADBUFSIZE 21 // the buffer created is not the correct size
+#define GDB_EINVALIDARG 31 // argument is invalid
+#define GDB_ENOSPACE 41 //
+#define GDB_EINVALIDBRKPOINTTYPE 51 // the breakpoint type is not recognized
+#define GDB_EINVALIDREGNUM 61 // given register number is not valid: either <0 or >=Number of Registers
+#define GDB_EUNKNOWN 255 // unknown
//
// These devices are open by GDB so we can just read and write to them
@@ -85,7 +82,7 @@ extern CONST CHAR8 mHexToStr[];
#define GDB_STDERR 0x02
//
-//Define Register size for different architectures
+// Define Register size for different architectures
//
#if defined (MDE_CPU_IA32)
#define REG_SIZE 32
@@ -95,12 +92,12 @@ extern CONST CHAR8 mHexToStr[];
#define REG_SIZE 32
#endif
-#define GDB_SERIAL_DEV_SIGNATURE SIGNATURE_32 ('g', 'd', 'b', 's')
+#define GDB_SERIAL_DEV_SIGNATURE SIGNATURE_32 ('g', 'd', 'b', 's')
typedef struct {
- VENDOR_DEVICE_PATH VendorDevice;
- UINT32 Index; // Support more than one
- EFI_DEVICE_PATH_PROTOCOL End;
+ VENDOR_DEVICE_PATH VendorDevice;
+ UINT32 Index; // Support more than one
+ EFI_DEVICE_PATH_PROTOCOL End;
} GDB_SERIAL_DEVICE_PATH;
//
@@ -113,25 +110,22 @@ typedef struct {
// DevicePath EFI_DEVICE_PATH_PROTOCOL *: Device path of the serial device
//
typedef struct {
- UINTN Signature;
- EFI_HANDLE Handle;
- EFI_SERIAL_IO_PROTOCOL SerialIo;
- EFI_SERIAL_IO_MODE SerialMode;
- GDB_SERIAL_DEVICE_PATH DevicePath;
- INTN InFileDescriptor;
- INTN OutFileDescriptor;
+ UINTN Signature;
+ EFI_HANDLE Handle;
+ EFI_SERIAL_IO_PROTOCOL SerialIo;
+ EFI_SERIAL_IO_MODE SerialMode;
+ GDB_SERIAL_DEVICE_PATH DevicePath;
+ INTN InFileDescriptor;
+ INTN OutFileDescriptor;
} GDB_SERIAL_DEV;
-
-#define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)
-
+#define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)
typedef struct {
- EFI_EXCEPTION_TYPE Exception;
- UINT8 SignalNo;
+ EFI_EXCEPTION_TYPE Exception;
+ UINT8 SignalNo;
} EFI_EXCEPTION_TYPE_ENTRY;
-
#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
//
@@ -141,17 +135,17 @@ typedef struct {
//
typedef union {
struct {
- UINT32 B0:1; // Breakpoint condition detected
- UINT32 B1:1; // Breakpoint condition detected
- UINT32 B2:1; // Breakpoint condition detected
- UINT32 B3:1; // Breakpoint condition detected
- UINT32 Reserved_1:9; // Reserved
- UINT32 BD:1; // Debug register access detected
- UINT32 BS:1; // Single step
- UINT32 BT:1; // Task switch
- UINT32 Reserved_2:16; // Reserved
+ UINT32 B0 : 1; // Breakpoint condition detected
+ UINT32 B1 : 1; // Breakpoint condition detected
+ UINT32 B2 : 1; // Breakpoint condition detected
+ UINT32 B3 : 1; // Breakpoint condition detected
+ UINT32 Reserved_1 : 9; // Reserved
+ UINT32 BD : 1; // Debug register access detected
+ UINT32 BS : 1; // Single step
+ UINT32 BT : 1; // Task switch
+ UINT32 Reserved_2 : 16; // Reserved
} Bits;
- UINTN UintN;
+ UINTN UintN;
} IA32_DR6;
//
@@ -161,65 +155,64 @@ typedef union {
//
typedef union {
struct {
- UINT32 L0:1; // Local breakpoint enable
- UINT32 G0:1; // Global breakpoint enable
- UINT32 L1:1; // Local breakpoint enable
- UINT32 G1:1; // Global breakpoint enable
- UINT32 L2:1; // Local breakpoint enable
- UINT32 G2:1; // Global breakpoint enable
- UINT32 L3:1; // Local breakpoint enable
- UINT32 G3:1; // Global breakpoint enable
- UINT32 LE:1; // Local exact breakpoint enable
- UINT32 GE:1; // Global exact breakpoint enable
- UINT32 Reserved_1:3; // Reserved
- UINT32 GD:1; // Global detect enable
- UINT32 Reserved_2:2; // Reserved
- UINT32 RW0:2; // Read/Write field
- UINT32 LEN0:2; // Length field
- UINT32 RW1:2; // Read/Write field
- UINT32 LEN1:2; // Length field
- UINT32 RW2:2; // Read/Write field
- UINT32 LEN2:2; // Length field
- UINT32 RW3:2; // Read/Write field
- UINT32 LEN3:2; // Length field
+ UINT32 L0 : 1; // Local breakpoint enable
+ UINT32 G0 : 1; // Global breakpoint enable
+ UINT32 L1 : 1; // Local breakpoint enable
+ UINT32 G1 : 1; // Global breakpoint enable
+ UINT32 L2 : 1; // Local breakpoint enable
+ UINT32 G2 : 1; // Global breakpoint enable
+ UINT32 L3 : 1; // Local breakpoint enable
+ UINT32 G3 : 1; // Global breakpoint enable
+ UINT32 LE : 1; // Local exact breakpoint enable
+ UINT32 GE : 1; // Global exact breakpoint enable
+ UINT32 Reserved_1 : 3; // Reserved
+ UINT32 GD : 1; // Global detect enable
+ UINT32 Reserved_2 : 2; // Reserved
+ UINT32 RW0 : 2; // Read/Write field
+ UINT32 LEN0 : 2; // Length field
+ UINT32 RW1 : 2; // Read/Write field
+ UINT32 LEN1 : 2; // Length field
+ UINT32 RW2 : 2; // Read/Write field
+ UINT32 LEN2 : 2; // Length field
+ UINT32 RW3 : 2; // Read/Write field
+ UINT32 LEN3 : 2; // Length field
} Bits;
- UINTN UintN;
+ UINTN UintN;
} IA32_DR7;
#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */
typedef enum {
- InstructionExecution, //Hardware breakpoint
- DataWrite, //watch
- DataRead, //rwatch
- DataReadWrite, //awatch
- SoftwareBreakpoint, //Software breakpoint
+ InstructionExecution, // Hardware breakpoint
+ DataWrite, // watch
+ DataRead, // rwatch
+ DataReadWrite, // awatch
+ SoftwareBreakpoint, // Software breakpoint
NotSupported
} BREAK_TYPE;
//
// Array of exception types that need to be hooked by the debugger
//
-extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];
+extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];
//
// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c
// here we need to wait for the periodic callback to do this.
//
-extern BOOLEAN gCtrlCBreakFlag;
+extern BOOLEAN gCtrlCBreakFlag;
//
// If the periodic callback is called while we are processing an F packet we need
// to let the callback know to not read from the serial stream as it could steal
// characters from the F response packet
//
-extern BOOLEAN gProcessingFPacket;
-
+extern BOOLEAN gProcessingFPacket;
// The offsets of registers SystemContext.
// The fields in the array are in the gdb ordering.
//
-extern UINTN gRegisterOffsets[];
+extern UINTN gRegisterOffsets[];
/**
Return the number of entries in the gExceptionType[]
@@ -231,7 +224,6 @@ MaxEfiException (
VOID
);
-
/**
Return the number of entries in the gRegisters[]
@@ -242,7 +234,6 @@ MaxRegisterCount (
VOID
);
-
/**
Check to see if the ISA is supported.
ISA = Instruction Set Architecture
@@ -252,10 +243,9 @@ MaxRegisterCount (
**/
BOOLEAN
CheckIsa (
- IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa
+ IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa
);
-
/**
Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
@@ -269,7 +259,6 @@ GdbSendTSignal (
IN UINT8 GdbExceptionType
);
-
/**
Translates the EFI mapping to GDB mapping
@@ -278,10 +267,9 @@ GdbSendTSignal (
**/
UINT8
ConvertEFItoGDBtype (
- IN EFI_EXCEPTION_TYPE EFIExceptionType
+ IN EFI_EXCEPTION_TYPE EFIExceptionType
);
-
/**
Empties the given buffer
@param *Buf pointer to the first element in buffer to be emptied
@@ -291,7 +279,6 @@ EmptyBuffer (
IN CHAR8 *Buf
);
-
/**
Converts an 8-bit Hex Char into a INTN.
@@ -301,10 +288,9 @@ EmptyBuffer (
**/
INTN
HexCharToInt (
- IN CHAR8 Char
+ IN CHAR8 Char
);
-
/** 'E NN'
Send an error with the given error number after converting to hex.
The error number is put into the buffer in hex. '255' is the biggest errno we can send.
@@ -315,10 +301,9 @@ HexCharToInt (
VOID
EFIAPI
SendError (
- IN UINT8 ErrorNum
+ IN UINT8 ErrorNum
);
-
/**
Send 'OK' when the function is done executing successfully.
**/
@@ -328,7 +313,6 @@ SendSuccess (
VOID
);
-
/**
Send empty packet to specify that particular command/functionality is not supported.
**/
@@ -349,7 +333,6 @@ ReadNthRegister (
IN CHAR8 *InBuffer
);
-
/** ‘g’
Reads the general registers into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception
@@ -360,7 +343,6 @@ ReadGeneralRegisters (
IN EFI_SYSTEM_CONTEXT SystemContext
);
-
/** ‘P n...=r...’
Writes the new value of n-th register received into the input buffer to the n-th register
@param SystemContext Register content at time of the exception
@@ -373,7 +355,6 @@ WriteNthRegister (
IN CHAR8 *InBuffer
);
-
/** ‘G XX...’
Writes the new values received into the input buffer to the general registers
@param SystemContext Register content at time of the exception
@@ -387,7 +368,6 @@ WriteGeneralRegisters (
IN CHAR8 *InBuffer
);
-
/** ‘m addr,length ’
Find the Length of the area to read and the start address. Finally, pass them to
another function, TransferFromMemToOutBufAndSend, that will read from that memory space and
@@ -401,7 +381,6 @@ ReadFromMemory (
IN CHAR8 *PacketData
);
-
/** ‘M addr,length :XX...’
Find the Length of the area in bytes to write and the start address. Finally, pass them to
another function, TransferFromInBufToMem, that will write to that memory space the info in
@@ -412,10 +391,9 @@ ReadFromMemory (
VOID
EFIAPI
WriteToMemory (
- IN CHAR8 *PacketData
+ IN CHAR8 *PacketData
);
-
/** ‘c [addr ]’
Continue. addr is Address to resume. If addr is omitted, resume at current
Address.
@@ -427,11 +405,10 @@ WriteToMemory (
VOID
EFIAPI
ContinueAtAddress (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *PacketData
);
-
/** ‘s [addr ]’
Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address.
@@ -466,7 +443,6 @@ RemoveSingleStep (
IN EFI_SYSTEM_CONTEXT SystemContext
);
-
/**
‘Z1, [addr], [length]’
‘Z2, [addr], [length]’
@@ -481,12 +457,11 @@ RemoveSingleStep (
**/
VOID
EFIAPI
-InsertBreakPoint(
+InsertBreakPoint (
IN EFI_SYSTEM_CONTEXT SystemContext,
IN CHAR8 *PacketData
);
-
/**
‘z1, [addr], [length]’
‘z2, [addr], [length]’
@@ -501,12 +476,11 @@ InsertBreakPoint(
**/
VOID
EFIAPI
-RemoveBreakPoint(
+RemoveBreakPoint (
IN EFI_SYSTEM_CONTEXT SystemContext,
IN CHAR8 *PacketData
);
-
/**
Exception Handler for GDB. It will be called for all exceptions
registered via the gExceptionType[] array.
@@ -522,7 +496,6 @@ GdbExceptionHandler (
IN OUT EFI_SYSTEM_CONTEXT SystemContext
);
-
/**
Periodic callback for GDB. This function is used to catch a ctrl-c or other
break in type command from GDB.
@@ -536,7 +509,6 @@ GdbPeriodicCallBack (
IN OUT EFI_SYSTEM_CONTEXT SystemContext
);
-
/**
Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
@@ -549,7 +521,6 @@ GdbInitializeSerialConsole (
VOID
);
-
/**
Send a GDB Remote Serial Protocol Packet
@@ -566,10 +537,9 @@ GdbInitializeSerialConsole (
**/
UINTN
SendPacket (
- IN CHAR8 *PacketData
+ IN CHAR8 *PacketData
);
-
/**
Receive a GDB Remote Serial Protocol Packet
@@ -588,10 +558,9 @@ SendPacket (
**/
UINTN
ReceivePacket (
- OUT CHAR8 *PacketData,
- IN UINTN PacketDataSize
- );
-
+ OUT CHAR8 *PacketData,
+ IN UINTN PacketDataSize
+ );
/**
Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates
@@ -607,12 +576,11 @@ ReceivePacket (
**/
INTN
GdbRead (
- IN INTN FileDescriptor,
- OUT VOID *Buffer,
- IN UINTN Count
+ IN INTN FileDescriptor,
+ OUT VOID *Buffer,
+ IN UINTN Count
);
-
/**
Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates
nothing was written. On error -1 is returned.
@@ -627,29 +595,29 @@ GdbRead (
**/
INTN
GdbWrite (
- IN INTN FileDescriptor,
- OUT CONST VOID *Buffer,
- IN UINTN Count
+ IN INTN FileDescriptor,
+ OUT CONST VOID *Buffer,
+ IN UINTN Count
);
UINTN *
FindPointerToRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber
);
CHAR8 *
BasicReadRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber,
- IN CHAR8 *OutBufPtr
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber,
+ IN CHAR8 *OutBufPtr
);
VOID
TransferFromInBufToMem (
- IN UINTN Length,
- IN UINT8 *Address,
- IN CHAR8 *NewData
+ IN UINTN Length,
+ IN UINT8 *Address,
+ IN CHAR8 *NewData
);
VOID
@@ -660,22 +628,22 @@ TransferFromMemToOutBufAndSend (
CHAR8 *
BasicWriteRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber,
- IN CHAR8 *InBufPtr
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber,
+ IN CHAR8 *InBufPtr
);
VOID
PrintReg (
- EFI_SYSTEM_CONTEXT SystemContext
+ EFI_SYSTEM_CONTEXT SystemContext
);
UINTN
ParseBreakpointPacket (
- IN CHAR8 *PacketData,
- OUT UINTN *Type,
- OUT UINTN *Address,
- OUT UINTN *Length
+ IN CHAR8 *PacketData,
+ OUT UINTN *Type,
+ OUT UINTN *Address,
+ OUT UINTN *Length
);
UINTN
@@ -717,18 +685,18 @@ EnableDebugRegister (
EFI_STATUS
FindMatchingDebugRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN Address,
- IN UINTN Length,
- IN UINTN Type,
- OUT UINTN *Register
- );
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN Address,
+ IN UINTN Length,
+ IN UINTN Type,
+ OUT UINTN *Register
+ );
EFI_STATUS
DisableDebugRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN Register
- );
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN Register
+ );
VOID
InitializeProcessor (
@@ -742,8 +710,8 @@ ValidateAddress (
BOOLEAN
ValidateException (
- IN EFI_EXCEPTION_TYPE ExceptionType,
- IN OUT EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_EXCEPTION_TYPE ExceptionType,
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext
);
#endif
diff --git a/EmbeddedPkg/GdbStub/Ia32/Processor.c b/EmbeddedPkg/GdbStub/Ia32/Processor.c
index 8dc768f180..a3406b03f3 100644
--- a/EmbeddedPkg/GdbStub/Ia32/Processor.c
+++ b/EmbeddedPkg/GdbStub/Ia32/Processor.c
@@ -13,52 +13,50 @@
// Array of exception types that need to be hooked by the debugger
// {EFI mapping, GDB mapping}
//
-EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
- { EXCEPT_IA32_DIVIDE_ERROR, GDB_SIGFPE },
- { EXCEPT_IA32_DEBUG, GDB_SIGTRAP },
- { EXCEPT_IA32_NMI, GDB_SIGEMT },
- { EXCEPT_IA32_BREAKPOINT, GDB_SIGTRAP },
- { EXCEPT_IA32_OVERFLOW, GDB_SIGSEGV },
- { EXCEPT_IA32_BOUND, GDB_SIGSEGV },
- { EXCEPT_IA32_INVALID_OPCODE, GDB_SIGILL },
- { EXCEPT_IA32_DOUBLE_FAULT, GDB_SIGEMT },
- { EXCEPT_IA32_STACK_FAULT, GDB_SIGSEGV },
- { EXCEPT_IA32_GP_FAULT, GDB_SIGSEGV },
- { EXCEPT_IA32_PAGE_FAULT, GDB_SIGSEGV },
- { EXCEPT_IA32_FP_ERROR, GDB_SIGEMT },
- { EXCEPT_IA32_ALIGNMENT_CHECK, GDB_SIGEMT },
- { EXCEPT_IA32_MACHINE_CHECK, GDB_SIGEMT }
+EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
+ { EXCEPT_IA32_DIVIDE_ERROR, GDB_SIGFPE },
+ { EXCEPT_IA32_DEBUG, GDB_SIGTRAP },
+ { EXCEPT_IA32_NMI, GDB_SIGEMT },
+ { EXCEPT_IA32_BREAKPOINT, GDB_SIGTRAP },
+ { EXCEPT_IA32_OVERFLOW, GDB_SIGSEGV },
+ { EXCEPT_IA32_BOUND, GDB_SIGSEGV },
+ { EXCEPT_IA32_INVALID_OPCODE, GDB_SIGILL },
+ { EXCEPT_IA32_DOUBLE_FAULT, GDB_SIGEMT },
+ { EXCEPT_IA32_STACK_FAULT, GDB_SIGSEGV },
+ { EXCEPT_IA32_GP_FAULT, GDB_SIGSEGV },
+ { EXCEPT_IA32_PAGE_FAULT, GDB_SIGSEGV },
+ { EXCEPT_IA32_FP_ERROR, GDB_SIGEMT },
+ { EXCEPT_IA32_ALIGNMENT_CHECK, GDB_SIGEMT },
+ { EXCEPT_IA32_MACHINE_CHECK, GDB_SIGEMT }
};
-
// The offsets of registers SystemContext.
// The fields in the array are in the gdb ordering.
//
-//16 regs
-UINTN gRegisterOffsets[] = {
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eax),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ecx),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edx),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebx),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esp),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ebp),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Esi),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Edi),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eip),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Eflags),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Cs),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ss),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Ds),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Es),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Fs),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_IA32, Gs)
+// 16 regs
+UINTN gRegisterOffsets[] = {
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Eax),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Ecx),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Edx),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Ebx),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Esp),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Ebp),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Esi),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Edi),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Eip),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Eflags),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Cs),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Ss),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Ds),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Es),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Fs),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Gs)
};
-
-//Debug only..
+// Debug only..
VOID
PrintReg (
- IN EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_SYSTEM_CONTEXT SystemContext
)
{
Print ((CHAR16 *)L"EAX: %x ", SystemContext.SystemContextIa32->Eax);
@@ -73,10 +71,10 @@ PrintReg (
Print ((CHAR16 *)L"EFlags: %x\n", SystemContext.SystemContextIa32->Eflags);
}
-//Debug only..
+// Debug only..
VOID
PrintDRreg (
- IN EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_SYSTEM_CONTEXT SystemContext
)
{
Print ((CHAR16 *)L"DR0: %x ", SystemContext.SystemContextIa32->Dr0);
@@ -87,7 +85,6 @@ PrintDRreg (
Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7);
}
-
/**
Return the number of entries in the gExceptionType[]
@@ -101,7 +98,6 @@ MaxEfiException (
return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);
}
-
/**
Return the number of entries in the gRegisters[]
@@ -115,7 +111,6 @@ MaxRegisterCount (
return sizeof (gRegisterOffsets)/sizeof (UINTN);
}
-
/**
Check to see if the ISA is supported.
ISA = Instruction Set Architecture
@@ -131,7 +126,6 @@ CheckIsa (
return (BOOLEAN)(Isa == IsaIa32);
}
-
/**
This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
It is, by default, set to find the register pointer of the IA32 member
@@ -146,12 +140,12 @@ FindPointerToRegister (
IN UINTN RegNumber
)
{
- UINT8 *TempPtr;
+ UINT8 *TempPtr;
+
TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber];
return (UINTN *)TempPtr;
}
-
/**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@@ -162,23 +156,23 @@ FindPointerToRegister (
**/
CHAR8 *
BasicReadRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber,
- IN CHAR8 *OutBufPtr
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber,
+ IN CHAR8 *OutBufPtr
)
{
- UINTN RegSize;
+ UINTN RegSize;
RegSize = 0;
while (RegSize < REG_SIZE) {
*OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];
*OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];
- RegSize = RegSize + 8;
+ RegSize = RegSize + 8;
}
+
return OutBufPtr;
}
-
/** ‘p n’
Reads the n-th register's value into an output buffer and sends it as a packet
@@ -188,17 +182,17 @@ BasicReadRegister (
VOID
EFIAPI
ReadNthRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *InBuffer
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *InBuffer
)
{
- UINTN RegNumber;
- CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)
- CHAR8 *OutBufPtr; // pointer to the output buffer
+ UINTN RegNumber;
+ CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)
+ CHAR8 *OutBufPtr; // pointer to the output buffer
RegNumber = AsciiStrHexToUintn (&InBuffer[1]);
- if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {
+ if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount ())) {
SendError (GDB_EINVALIDREGNUM);
return;
}
@@ -207,10 +201,9 @@ ReadNthRegister (
OutBufPtr = BasicReadRegister (SystemContext, RegNumber, OutBufPtr);
*OutBufPtr = '\0'; // the end of the buffer
- SendPacket(OutBuffer);
+ SendPacket (OutBuffer);
}
-
/** ‘g’
Reads the general registers into an output buffer and sends it as a packet
@@ -219,23 +212,23 @@ ReadNthRegister (
VOID
EFIAPI
ReadGeneralRegisters (
- IN EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_SYSTEM_CONTEXT SystemContext
)
{
- UINTN i;
- CHAR8 OutBuffer[129]; // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
- CHAR8 *OutBufPtr; // pointer to the output buffer
+ UINTN i;
+ CHAR8 OutBuffer[129]; // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
+ CHAR8 *OutBufPtr; // pointer to the output buffer
OutBufPtr = OutBuffer;
- for (i = 0 ; i < MaxRegisterCount() ; i++) { // there are only 16 registers to read
+ for (i = 0; i < MaxRegisterCount (); i++) {
+ // there are only 16 registers to read
OutBufPtr = BasicReadRegister (SystemContext, i, OutBufPtr);
}
*OutBufPtr = '\0'; // the end of the buffer
- SendPacket(OutBuffer);
+ SendPacket (OutBuffer);
}
-
/**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@@ -246,27 +239,27 @@ ReadGeneralRegisters (
**/
CHAR8 *
BasicWriteRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber,
- IN CHAR8 *InBufPtr
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber,
+ IN CHAR8 *InBufPtr
)
{
- UINTN RegSize;
- UINTN TempValue; // the value transferred from a hex char
- UINT32 NewValue; // the new value of the RegNumber-th Register
+ UINTN RegSize;
+ UINTN TempValue; // the value transferred from a hex char
+ UINT32 NewValue; // the new value of the RegNumber-th Register
NewValue = 0;
- RegSize = 0;
+ RegSize = 0;
while (RegSize < REG_SIZE) {
- TempValue = HexCharToInt(*InBufPtr++);
+ TempValue = HexCharToInt (*InBufPtr++);
- if (TempValue < 0) {
+ if (TempValue < 0) {
SendError (GDB_EBADMEMDATA);
return NULL;
}
NewValue += (TempValue << (RegSize+4));
- TempValue = HexCharToInt(*InBufPtr++);
+ TempValue = HexCharToInt (*InBufPtr++);
if (TempValue < 0) {
SendError (GDB_EBADMEMDATA);
@@ -274,13 +267,13 @@ BasicWriteRegister (
}
NewValue += (TempValue << RegSize);
- RegSize = RegSize + 8;
+ RegSize = RegSize + 8;
}
+
*(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;
return InBufPtr;
}
-
/** ‘P n...=r...’
Writes the new value of n-th register received into the input buffer to the n-th register
@@ -290,35 +283,36 @@ BasicWriteRegister (
VOID
EFIAPI
WriteNthRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *InBuffer
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *InBuffer
)
{
- UINTN RegNumber;
- CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array
- CHAR8 *RegNumBufPtr;
- CHAR8 *InBufPtr; // pointer to the input buffer
+ UINTN RegNumber;
+ CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array
+ CHAR8 *RegNumBufPtr;
+ CHAR8 *InBufPtr; // pointer to the input buffer
// find the register number to write
- InBufPtr = &InBuffer[1];
+ InBufPtr = &InBuffer[1];
RegNumBufPtr = RegNumBuffer;
while (*InBufPtr != '=') {
*RegNumBufPtr++ = *InBufPtr++;
}
+
*RegNumBufPtr = '\0';
- RegNumber = AsciiStrHexToUintn (RegNumBuffer);
+ RegNumber = AsciiStrHexToUintn (RegNumBuffer);
// check if this is a valid Register Number
- if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {
+ if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount ())) {
SendError (GDB_EINVALIDREGNUM);
return;
}
+
InBufPtr++; // skips the '=' character
BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
- SendSuccess();
+ SendSuccess ();
}
-
/** ‘G XX...’
Writes the new values received into the input buffer to the general registers
@@ -328,17 +322,18 @@ WriteNthRegister (
VOID
EFIAPI
WriteGeneralRegisters (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *InBuffer
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *InBuffer
)
{
UINTN i;
- CHAR8 *InBufPtr; /// pointer to the input buffer
+ CHAR8 *InBufPtr; /// pointer to the input buffer
// check to see if the buffer is the right size which is
// 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129
- if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
- //Bad message. Message is not the right length
+ if (AsciiStrLen (InBuffer) != 129) {
+ // 16 regs, 8 hex chars each, and the end '\0' (escape seq)
+ // Bad message. Message is not the right length
SendError (GDB_EBADBUFSIZE);
return;
}
@@ -347,14 +342,14 @@ WriteGeneralRegisters (
// Read the new values for the registers from the input buffer to an array, NewValueArray.
// The values in the array are in the gdb ordering
- for (i=0; i < MaxRegisterCount(); i++) { // there are only 16 registers to write
+ for (i = 0; i < MaxRegisterCount (); i++) {
+ // there are only 16 registers to write
InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr);
}
- SendSuccess();
+ SendSuccess ();
}
-
/**
Insert Single Step in the SystemContext
@@ -365,10 +360,9 @@ AddSingleStep (
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
- SystemContext.SystemContextIa32->Eflags |= TF_BIT; //Setting the TF bit.
+ SystemContext.SystemContextIa32->Eflags |= TF_BIT; // Setting the TF bit.
}
-
/**
Remove Single Step in the SystemContext
@@ -382,8 +376,6 @@ RemoveSingleStep (
SystemContext.SystemContextIa32->Eflags &= ~TF_BIT; // clearing the TF bit.
}
-
-
/** ‘c [addr ]’
Continue. addr is Address to resume. If addr is omitted, resume at current
Address.
@@ -393,8 +385,8 @@ RemoveSingleStep (
VOID
EFIAPI
ContinueAtAddress (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *PacketData
)
{
if (PacketData[1] != '\0') {
@@ -402,7 +394,6 @@ ContinueAtAddress (
}
}
-
/** ‘s [addr ]’
Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address.
@@ -412,8 +403,8 @@ ContinueAtAddress (
VOID
EFIAPI
SingleStep (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *PacketData
)
{
if (PacketData[1] != '\0') {
@@ -423,7 +414,6 @@ SingleStep (
AddSingleStep (SystemContext);
}
-
/**
Returns breakpoint data address from DR0-DR3 based on the input breakpoint number
@@ -439,7 +429,7 @@ GetBreakpointDataAddress (
IN UINTN BreakpointNumber
)
{
- UINTN Address;
+ UINTN Address;
if (BreakpointNumber == 1) {
Address = SystemContext.SystemContextIa32->Dr0;
@@ -456,7 +446,6 @@ GetBreakpointDataAddress (
return Address;
}
-
/**
Returns currently detected breakpoint value based on the register DR6 B0-B3 field.
If no breakpoint is detected then it returns 0.
@@ -472,8 +461,8 @@ GetBreakpointDetected (
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
- IA32_DR6 Dr6;
- UINTN BreakpointNumber;
+ IA32_DR6 Dr6;
+ UINTN BreakpointNumber;
Dr6.UintN = SystemContext.SystemContextIa32->Dr6;
@@ -486,13 +475,12 @@ GetBreakpointDetected (
} else if (Dr6.Bits.B3 == 1) {
BreakpointNumber = 4;
} else {
- BreakpointNumber = 0; //No breakpoint detected
+ BreakpointNumber = 0; // No breakpoint detected
}
return BreakpointNumber;
}
-
/**
Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite)
based on the Breakpoint number
@@ -510,25 +498,24 @@ GetBreakpointType (
IN UINTN BreakpointNumber
)
{
- IA32_DR7 Dr7;
- BREAK_TYPE Type = NotSupported; //Default is NotSupported type
+ IA32_DR7 Dr7;
+ BREAK_TYPE Type = NotSupported; // Default is NotSupported type
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if (BreakpointNumber == 1) {
- Type = (BREAK_TYPE) Dr7.Bits.RW0;
+ Type = (BREAK_TYPE)Dr7.Bits.RW0;
} else if (BreakpointNumber == 2) {
- Type = (BREAK_TYPE) Dr7.Bits.RW1;
+ Type = (BREAK_TYPE)Dr7.Bits.RW1;
} else if (BreakpointNumber == 3) {
- Type = (BREAK_TYPE) Dr7.Bits.RW2;
+ Type = (BREAK_TYPE)Dr7.Bits.RW2;
} else if (BreakpointNumber == 4) {
- Type = (BREAK_TYPE) Dr7.Bits.RW3;
+ Type = (BREAK_TYPE)Dr7.Bits.RW3;
}
return Type;
}
-
/**
Parses Length and returns the length which DR7 LENn field accepts.
For example: If we receive 1-Byte length then we should return 0.
@@ -541,21 +528,24 @@ GetBreakpointType (
**/
UINTN
ConvertLengthData (
- IN UINTN Length
+ IN UINTN Length
)
{
- if (Length == 1) { //1-Byte length
+ if (Length == 1) {
+ // 1-Byte length
return 0;
- } else if (Length == 2) { //2-Byte length
+ } else if (Length == 2) {
+ // 2-Byte length
return 1;
- } else if (Length == 4) { //4-Byte length
+ } else if (Length == 4) {
+ // 4-Byte length
return 3;
- } else { //Undefined or 8-byte length
+ } else {
+ // Undefined or 8-byte length
return 2;
}
}
-
/**
Finds the next free debug register. If all the registers are occupied then
EFI_OUT_OF_RESOURCES is returned.
@@ -572,7 +562,7 @@ FindNextFreeDebugRegister (
OUT UINTN *Register
)
{
- IA32_DR7 Dr7;
+ IA32_DR7 Dr7;
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
@@ -591,7 +581,6 @@ FindNextFreeDebugRegister (
return EFI_SUCCESS;
}
-
/**
Enables the debug register. Writes Address value to appropriate DR0-3 register.
Sets LENn, Gn, RWn bits in DR7 register.
@@ -616,56 +605,56 @@ EnableDebugRegister (
{
IA32_DR7 Dr7;
- //Convert length data
+ // Convert length data
Length = ConvertLengthData (Length);
- //For Instruction execution, length should be 0
- //(Ref. Intel reference manual 18.2.4)
+ // For Instruction execution, length should be 0
+ // (Ref. Intel reference manual 18.2.4)
if ((Type == 0) && (Length != 0)) {
return EFI_INVALID_PARAMETER;
}
- //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
- //software breakpoint. We should send empty packet in both these cases.
+ // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
+ // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) ||
- (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
+ (Type == (BREAK_TYPE)SoftwareBreakpoint))
+ {
return EFI_UNSUPPORTED;
}
- //Read DR7 so appropriate Gn, RWn and LENn bits can be modified.
+ // Read DR7 so appropriate Gn, RWn and LENn bits can be modified.
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if (Register == 0) {
SystemContext.SystemContextIa32->Dr0 = Address;
- Dr7.Bits.G0 = 1;
- Dr7.Bits.RW0 = Type;
- Dr7.Bits.LEN0 = Length;
+ Dr7.Bits.G0 = 1;
+ Dr7.Bits.RW0 = Type;
+ Dr7.Bits.LEN0 = Length;
} else if (Register == 1) {
SystemContext.SystemContextIa32->Dr1 = Address;
- Dr7.Bits.G1 = 1;
- Dr7.Bits.RW1 = Type;
- Dr7.Bits.LEN1 = Length;
+ Dr7.Bits.G1 = 1;
+ Dr7.Bits.RW1 = Type;
+ Dr7.Bits.LEN1 = Length;
} else if (Register == 2) {
SystemContext.SystemContextIa32->Dr2 = Address;
- Dr7.Bits.G2 = 1;
- Dr7.Bits.RW2 = Type;
- Dr7.Bits.LEN2 = Length;
+ Dr7.Bits.G2 = 1;
+ Dr7.Bits.RW2 = Type;
+ Dr7.Bits.LEN2 = Length;
} else if (Register == 3) {
SystemContext.SystemContextIa32->Dr3 = Address;
- Dr7.Bits.G3 = 1;
- Dr7.Bits.RW3 = Type;
- Dr7.Bits.LEN3 = Length;
+ Dr7.Bits.G3 = 1;
+ Dr7.Bits.RW3 = Type;
+ Dr7.Bits.LEN3 = Length;
} else {
return EFI_INVALID_PARAMETER;
}
- //Update Dr7 with appropriate Gn, RWn and LENn bits
+ // Update Dr7 with appropriate Gn, RWn and LENn bits
SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
return EFI_SUCCESS;
}
-
/**
Returns register number 0 - 3 for the matching debug register.
This function compares incoming Address, Type, Length and
@@ -684,46 +673,51 @@ EnableDebugRegister (
**/
EFI_STATUS
FindMatchingDebugRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN Address,
- IN UINTN Length,
- IN UINTN Type,
- OUT UINTN *Register
- )
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN Address,
+ IN UINTN Length,
+ IN UINTN Type,
+ OUT UINTN *Register
+ )
{
- IA32_DR7 Dr7;
+ IA32_DR7 Dr7;
- //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
- //software breakpoint. We should send empty packet in both these cases.
+ // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
+ // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) ||
- (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
+ (Type == (BREAK_TYPE)SoftwareBreakpoint))
+ {
return EFI_UNSUPPORTED;
}
- //Convert length data
- Length = ConvertLengthData(Length);
+ // Convert length data
+ Length = ConvertLengthData (Length);
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if ((Dr7.Bits.G0 == 1) &&
(Dr7.Bits.LEN0 == Length) &&
(Dr7.Bits.RW0 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr0)) {
+ (Address == SystemContext.SystemContextIa32->Dr0))
+ {
*Register = 0;
} else if ((Dr7.Bits.G1 == 1) &&
(Dr7.Bits.LEN1 == Length) &&
(Dr7.Bits.RW1 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr1)) {
+ (Address == SystemContext.SystemContextIa32->Dr1))
+ {
*Register = 1;
} else if ((Dr7.Bits.G2 == 1) &&
(Dr7.Bits.LEN2 == Length) &&
(Dr7.Bits.RW2 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr2)) {
+ (Address == SystemContext.SystemContextIa32->Dr2))
+ {
*Register = 2;
} else if ((Dr7.Bits.G3 == 1) &&
(Dr7.Bits.LEN3 == Length) &&
(Dr7.Bits.RW3 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr3)) {
+ (Address == SystemContext.SystemContextIa32->Dr3))
+ {
*Register = 3;
} else {
Print ((CHAR16 *)L"No match found..\n");
@@ -733,7 +727,6 @@ FindMatchingDebugRegister (
return EFI_SUCCESS;
}
-
/**
Disables the particular debug register.
@@ -745,47 +738,46 @@ FindMatchingDebugRegister (
**/
EFI_STATUS
DisableDebugRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN Register
- )
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN Register
+ )
{
IA32_DR7 Dr7;
- UINTN Address = 0;
+ UINTN Address = 0;
- //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
+ // Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if (Register == 0) {
SystemContext.SystemContextIa32->Dr0 = Address;
- Dr7.Bits.G0 = 0;
- Dr7.Bits.RW0 = 0;
- Dr7.Bits.LEN0 = 0;
+ Dr7.Bits.G0 = 0;
+ Dr7.Bits.RW0 = 0;
+ Dr7.Bits.LEN0 = 0;
} else if (Register == 1) {
SystemContext.SystemContextIa32->Dr1 = Address;
- Dr7.Bits.G1 = 0;
- Dr7.Bits.RW1 = 0;
- Dr7.Bits.LEN1 = 0;
+ Dr7.Bits.G1 = 0;
+ Dr7.Bits.RW1 = 0;
+ Dr7.Bits.LEN1 = 0;
} else if (Register == 2) {
SystemContext.SystemContextIa32->Dr2 = Address;
- Dr7.Bits.G2 = 0;
- Dr7.Bits.RW2 = 0;
- Dr7.Bits.LEN2 = 0;
+ Dr7.Bits.G2 = 0;
+ Dr7.Bits.RW2 = 0;
+ Dr7.Bits.LEN2 = 0;
} else if (Register == 3) {
SystemContext.SystemContextIa32->Dr3 = Address;
- Dr7.Bits.G3 = 0;
- Dr7.Bits.RW3 = 0;
- Dr7.Bits.LEN3 = 0;
+ Dr7.Bits.G3 = 0;
+ Dr7.Bits.RW3 = 0;
+ Dr7.Bits.LEN3 = 0;
} else {
return EFI_INVALID_PARAMETER;
}
- //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
+ // Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
return EFI_SUCCESS;
}
-
/**
‘Z1, [addr], [length]’
‘Z2, [addr], [length]’
@@ -802,16 +794,16 @@ VOID
EFIAPI
InsertBreakPoint (
IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN CHAR8 *PacketData
)
{
- UINTN Type;
- UINTN Address;
- UINTN Length;
- UINTN Register;
- EFI_STATUS Status;
- BREAK_TYPE BreakType = NotSupported;
- UINTN ErrorCode;
+ UINTN Type;
+ UINTN Address;
+ UINTN Length;
+ UINTN Register;
+ EFI_STATUS Status;
+ BREAK_TYPE BreakType = NotSupported;
+ UINTN ErrorCode;
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
if (ErrorCode > 0) {
@@ -820,28 +812,27 @@ InsertBreakPoint (
}
switch (Type) {
-
- case 0: //Software breakpoint
+ case 0: // Software breakpoint
BreakType = SoftwareBreakpoint;
break;
- case 1: //Hardware breakpoint
+ case 1: // Hardware breakpoint
BreakType = InstructionExecution;
break;
- case 2: //Write watchpoint
+ case 2: // Write watchpoint
BreakType = DataWrite;
break;
- case 3: //Read watchpoint
+ case 3: // Read watchpoint
BreakType = DataRead;
break;
- case 4: //Access watchpoint
+ case 4: // Access watchpoint
BreakType = DataReadWrite;
break;
- default :
+ default:
Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type);
SendError (GDB_EINVALIDBRKPOINTTYPE);
return;
@@ -849,7 +840,7 @@ InsertBreakPoint (
// Find next free debug register
Status = FindNextFreeDebugRegister (SystemContext, &Register);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
Print ((CHAR16 *)L"No space left on device\n");
SendError (GDB_ENOSPACE);
return;
@@ -857,8 +848,7 @@ InsertBreakPoint (
// Write Address, length data at particular DR register
Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);
- if (EFI_ERROR(Status)) {
-
+ if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported\n");
SendNotSupported ();
@@ -873,7 +863,6 @@ InsertBreakPoint (
SendSuccess ();
}
-
/**
‘z1, [addr], [length]’
‘z2, [addr], [length]’
@@ -892,15 +881,15 @@ RemoveBreakPoint (
IN CHAR8 *PacketData
)
{
- UINTN Type;
- UINTN Address;
- UINTN Length;
- UINTN Register;
- BREAK_TYPE BreakType = NotSupported;
- EFI_STATUS Status;
- UINTN ErrorCode;
-
- //Parse breakpoint packet data
+ UINTN Type;
+ UINTN Address;
+ UINTN Length;
+ UINTN Register;
+ BREAK_TYPE BreakType = NotSupported;
+ EFI_STATUS Status;
+ UINTN ErrorCode;
+
+ // Parse breakpoint packet data
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
if (ErrorCode > 0) {
SendError ((UINT8)ErrorCode);
@@ -908,36 +897,34 @@ RemoveBreakPoint (
}
switch (Type) {
-
- case 0: //Software breakpoint
+ case 0: // Software breakpoint
BreakType = SoftwareBreakpoint;
break;
- case 1: //Hardware breakpoint
+ case 1: // Hardware breakpoint
BreakType = InstructionExecution;
break;
- case 2: //Write watchpoint
+ case 2: // Write watchpoint
BreakType = DataWrite;
break;
- case 3: //Read watchpoint
+ case 3: // Read watchpoint
BreakType = DataRead;
break;
- case 4: //Access watchpoint
+ case 4: // Access watchpoint
BreakType = DataReadWrite;
break;
- default :
+ default:
SendError (GDB_EINVALIDBRKPOINTTYPE);
return;
}
- //Find matching debug register
+ // Find matching debug register
Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);
- if (EFI_ERROR(Status)) {
-
+ if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported.\n");
SendNotSupported ();
@@ -949,9 +936,9 @@ RemoveBreakPoint (
return;
}
- //Remove breakpoint
+ // Remove breakpoint
Status = DisableDebugRegister (SystemContext, Register);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
Print ((CHAR16 *)L"Invalid argument.\n");
SendError (GDB_EINVALIDARG);
return;
@@ -960,7 +947,6 @@ RemoveBreakPoint (
SendSuccess ();
}
-
VOID
InitializeProcessor (
VOID
@@ -978,10 +964,9 @@ ValidateAddress (
BOOLEAN
ValidateException (
- IN EFI_EXCEPTION_TYPE ExceptionType,
- IN OUT EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_EXCEPTION_TYPE ExceptionType,
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext
)
{
return TRUE;
}
-
diff --git a/EmbeddedPkg/GdbStub/SerialIo.c b/EmbeddedPkg/GdbStub/SerialIo.c
index 08d1763c30..9970ab687e 100644
--- a/EmbeddedPkg/GdbStub/SerialIo.c
+++ b/EmbeddedPkg/GdbStub/SerialIo.c
@@ -18,14 +18,14 @@
// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c
// here we need to wait for the periodic callback to do this.
//
-BOOLEAN gCtrlCBreakFlag = FALSE;
+BOOLEAN gCtrlCBreakFlag = FALSE;
//
// If the periodic callback is called while we are processing an F packet we need
// to let the callback know to not read from the serial stream as it could steal
// characters from the F response packet
//
-BOOLEAN gProcessingFPacket = FALSE;
+BOOLEAN gProcessingFPacket = FALSE;
/**
Process a control-C break message.
@@ -35,21 +35,19 @@ BOOLEAN gProcessingFPacket = FALSE;
@param ErrNo Error information from the F reply packet or other source
**/
-
VOID
GdbCtrlCBreakMessage (
- IN UINTN ErrNo
+ IN UINTN ErrNo
)
{
// See D.10.5 of gdb.pdf
// This should look like a break message. Should look like SIGINT
/* TODO: Make sure if we should do anything with ErrNo */
- //Turn on the global Ctrl-C flag.
+ // Turn on the global Ctrl-C flag.
gCtrlCBreakFlag = TRUE;
}
-
/**
Parse the F reply packet and extract the return value and an ErrNo if it exists.
@@ -62,11 +60,11 @@ GdbCtrlCBreakMessage (
**/
INTN
GdbParseFReplyPacket (
- IN CHAR8 *Packet,
- OUT UINTN *ErrNo
+ IN CHAR8 *Packet,
+ OUT UINTN *ErrNo
)
{
- INTN RetCode;
+ INTN RetCode;
if (Packet[0] != 'F') {
// A valid response would be an F packet
@@ -76,7 +74,9 @@ GdbParseFReplyPacket (
RetCode = AsciiStrHexToUintn (&Packet[1]);
// Find 1st comma
- for (;*Packet != '\0' && *Packet != ','; Packet++);
+ for ( ; *Packet != '\0' && *Packet != ','; Packet++) {
+ }
+
if (*Packet == '\0') {
*ErrNo = 0;
return RetCode;
@@ -85,7 +85,9 @@ GdbParseFReplyPacket (
*ErrNo = AsciiStrHexToUintn (++Packet);
// Find 2nd comma
- for (;*Packet != '\0' && *Packet != ','; Packet++);
+ for ( ; *Packet != '\0' && *Packet != ','; Packet++) {
+ }
+
if (*Packet == '\0') {
return RetCode;
}
@@ -97,7 +99,6 @@ GdbParseFReplyPacket (
return RetCode;
}
-
/**
Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates
the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.
@@ -112,16 +113,16 @@ GdbParseFReplyPacket (
**/
INTN
GdbRead (
- IN INTN FileDescriptor,
- OUT VOID *Buffer,
- IN UINTN Count
+ IN INTN FileDescriptor,
+ OUT VOID *Buffer,
+ IN UINTN Count
)
{
- CHAR8 Packet[128];
- UINTN Size;
- INTN RetCode;
- UINTN ErrNo;
- BOOLEAN ReceiveDone = FALSE;
+ CHAR8 Packet[128];
+ UINTN Size;
+ INTN RetCode;
+ UINTN ErrNo;
+ BOOLEAN ReceiveDone = FALSE;
// Send:
// "Fread,XX,YYYYYYYY,XX
@@ -146,23 +147,23 @@ GdbRead (
// Process GDB commands
switch (Packet[0]) {
- //Write memory command.
- //M addr,length:XX...
+ // Write memory command.
+ // M addr,length:XX...
case 'M':
WriteToMemory (Packet);
break;
- //Fretcode, errno, Ctrl-C flag
- //retcode - Count read
+ // Fretcode, errno, Ctrl-C flag
+ // retcode - Count read
case 'F':
- //Once target receives F reply packet that means the previous
- //transactions are finished.
+ // Once target receives F reply packet that means the previous
+ // transactions are finished.
ReceiveDone = TRUE;
break;
- //Send empty buffer
- default :
- SendNotSupported();
+ // Send empty buffer
+ default:
+ SendNotSupported ();
break;
}
} while (ReceiveDone == FALSE);
@@ -171,7 +172,7 @@ GdbRead (
Print ((CHAR16 *)L"RetCode: %x..ErrNo: %x..\n", RetCode, ErrNo);
if (ErrNo > 0) {
- //Send error to the host if there is any.
+ // Send error to the host if there is any.
SendError ((UINT8)ErrNo);
}
@@ -180,7 +181,6 @@ GdbRead (
return RetCode;
}
-
/**
Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates
nothing was written. On error -1 is returned.
@@ -195,16 +195,16 @@ GdbRead (
**/
INTN
GdbWrite (
- IN INTN FileDescriptor,
- OUT CONST VOID *Buffer,
- IN UINTN Count
+ IN INTN FileDescriptor,
+ OUT CONST VOID *Buffer,
+ IN UINTN Count
)
{
- CHAR8 Packet[128];
- UINTN Size;
- INTN RetCode;
- UINTN ErrNo;
- BOOLEAN ReceiveDone = FALSE;
+ CHAR8 Packet[128];
+ UINTN Size;
+ INTN RetCode;
+ UINTN ErrNo;
+ BOOLEAN ReceiveDone = FALSE;
// Send:
// #Fwrite,XX,YYYYYYYY,XX$SS
@@ -228,23 +228,23 @@ GdbWrite (
// Process GDB commands
switch (Packet[0]) {
- //Read memory command.
- //m addr,length.
+ // Read memory command.
+ // m addr,length.
case 'm':
ReadFromMemory (Packet);
break;
- //Fretcode, errno, Ctrl-C flag
- //retcode - Count read
+ // Fretcode, errno, Ctrl-C flag
+ // retcode - Count read
case 'F':
- //Once target receives F reply packet that means the previous
- //transactions are finished.
+ // Once target receives F reply packet that means the previous
+ // transactions are finished.
ReceiveDone = TRUE;
break;
- //Send empty buffer
- default :
- SendNotSupported();
+ // Send empty buffer
+ default:
+ SendNotSupported ();
break;
}
} while (ReceiveDone == FALSE);
@@ -252,15 +252,14 @@ GdbWrite (
RetCode = GdbParseFReplyPacket (Packet, &ErrNo);
Print ((CHAR16 *)L"RetCode: %x..ErrNo: %x..\n", RetCode, ErrNo);
- //Send error to the host if there is any.
+ // Send error to the host if there is any.
if (ErrNo > 0) {
- SendError((UINT8)ErrNo);
+ SendError ((UINT8)ErrNo);
}
return RetCode;
}
-
/**
Reset the serial device.
@@ -279,7 +278,6 @@ GdbSerialReset (
return EFI_SUCCESS;
}
-
/**
Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
data buts, and stop bits on a serial device.
@@ -321,7 +319,6 @@ GdbSerialSetAttributes (
return EFI_UNSUPPORTED;
}
-
/**
Set the control bits on a serial device
@@ -343,7 +340,6 @@ GdbSerialSetControl (
return EFI_UNSUPPORTED;
}
-
/**
Retrieves the status of the control bits on a serial device
@@ -364,7 +360,6 @@ GdbSerialGetControl (
return EFI_UNSUPPORTED;
}
-
/**
Writes data to a serial device.
@@ -387,7 +382,7 @@ GdbSerialWrite (
)
{
GDB_SERIAL_DEV *SerialDev;
- UINTN Return;
+ UINTN Return;
SerialDev = GDB_SERIAL_DEV_FROM_THIS (This);
@@ -416,7 +411,6 @@ GdbSerialWrite (
@retval EFI_TIMEOUT The data write was stopped due to a timeout.
**/
-
EFI_STATUS
EFIAPI
GdbSerialRead (
@@ -426,7 +420,7 @@ GdbSerialRead (
)
{
GDB_SERIAL_DEV *SerialDev;
- UINTN Return;
+ UINTN Return;
SerialDev = GDB_SERIAL_DEV_FROM_THIS (This);
@@ -442,11 +436,10 @@ GdbSerialRead (
return EFI_SUCCESS;
}
-
//
// Template used to initialize the GDB Serial IO protocols
//
-GDB_SERIAL_DEV gdbSerialDevTemplate = {
+GDB_SERIAL_DEV gdbSerialDevTemplate = {
GDB_SERIAL_DEV_SIGNATURE,
NULL,
@@ -460,14 +453,14 @@ GDB_SERIAL_DEV gdbSerialDevTemplate = {
GdbSerialRead,
NULL
},
- { // SerialMode
- 0, // ControlMask
- 0, // Timeout
- 0, // BaudRate
- 1, // RceiveFifoDepth
- 0, // DataBits
- 0, // Parity
- 0 // StopBits
+ { // SerialMode
+ 0, // ControlMask
+ 0, // Timeout
+ 0, // BaudRate
+ 1, // RceiveFifoDepth
+ 0, // DataBits
+ 0, // Parity
+ 0 // StopBits
},
{
{
@@ -475,8 +468,8 @@ GDB_SERIAL_DEV gdbSerialDevTemplate = {
HARDWARE_DEVICE_PATH,
HW_VENDOR_DP,
{
- (UINT8) (sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)),
- (UINT8) ((sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)) >> 8)
+ (UINT8)(sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)),
+ (UINT8)((sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32)) >> 8)
},
},
EFI_SERIAL_IO_PROTOCOL_GUID
@@ -486,8 +479,8 @@ GDB_SERIAL_DEV gdbSerialDevTemplate = {
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{
- (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL)),
- (UINT8) (sizeof (EFI_DEVICE_PATH_PROTOCOL) >> 8)
+ (UINT8)(sizeof (EFI_DEVICE_PATH_PROTOCOL)),
+ (UINT8)(sizeof (EFI_DEVICE_PATH_PROTOCOL) >> 8)
}
},
},
@@ -495,7 +488,6 @@ GDB_SERIAL_DEV gdbSerialDevTemplate = {
GDB_STDOUT
};
-
/**
Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
@@ -512,25 +504,27 @@ GdbInitializeSerialConsole (
GDB_SERIAL_DEV *StdErrSerialDev;
// Use the template to make a copy of the Serial Console private data structure.
- StdOutSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV), &gdbSerialDevTemplate);
+ StdOutSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV), &gdbSerialDevTemplate);
ASSERT (StdOutSerialDev != NULL);
// Fixup pointer after the copy
StdOutSerialDev->SerialIo.Mode = &StdOutSerialDev->SerialMode;
- StdErrSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV), &gdbSerialDevTemplate);
+ StdErrSerialDev = AllocateCopyPool (sizeof (GDB_SERIAL_DEV), &gdbSerialDevTemplate);
ASSERT (StdErrSerialDev != NULL);
// Fixup pointer and modify stuff that is different for StdError
- StdErrSerialDev->SerialIo.Mode = &StdErrSerialDev->SerialMode;
- StdErrSerialDev->DevicePath.Index = 1;
+ StdErrSerialDev->SerialIo.Mode = &StdErrSerialDev->SerialMode;
+ StdErrSerialDev->DevicePath.Index = 1;
StdErrSerialDev->OutFileDescriptor = GDB_STDERR;
// Make a new handle with Serial IO protocol and its device path on it.
Status = gBS->InstallMultipleProtocolInterfaces (
&StdOutSerialDev->Handle,
- &gEfiSerialIoProtocolGuid, &StdOutSerialDev->SerialIo,
- &gEfiDevicePathProtocolGuid, &StdOutSerialDev->DevicePath,
+ &gEfiSerialIoProtocolGuid,
+ &StdOutSerialDev->SerialIo,
+ &gEfiDevicePathProtocolGuid,
+ &StdOutSerialDev->DevicePath,
NULL
);
ASSERT_EFI_ERROR (Status);
@@ -538,10 +532,11 @@ GdbInitializeSerialConsole (
// Make a new handle with Serial IO protocol and its device path on it.
Status = gBS->InstallMultipleProtocolInterfaces (
&StdErrSerialDev->Handle,
- &gEfiSerialIoProtocolGuid, &StdErrSerialDev->SerialIo,
- &gEfiDevicePathProtocolGuid, &StdErrSerialDev->DevicePath,
+ &gEfiSerialIoProtocolGuid,
+ &StdErrSerialDev->SerialIo,
+ &gEfiDevicePathProtocolGuid,
+ &StdErrSerialDev->DevicePath,
NULL
);
ASSERT_EFI_ERROR (Status);
}
-
diff --git a/EmbeddedPkg/GdbStub/X64/Processor.c b/EmbeddedPkg/GdbStub/X64/Processor.c
index c6599a2b2b..4ff79abe42 100644
--- a/EmbeddedPkg/GdbStub/X64/Processor.c
+++ b/EmbeddedPkg/GdbStub/X64/Processor.c
@@ -12,7 +12,7 @@
//
// Array of exception types that need to be hooked by the debugger
//
-EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
+EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
{ EXCEPT_X64_DIVIDE_ERROR, GDB_SIGFPE },
{ EXCEPT_X64_DEBUG, GDB_SIGTRAP },
{ EXCEPT_X64_NMI, GDB_SIGEMT },
@@ -29,39 +29,37 @@ EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
{ EXCEPT_X64_MACHINE_CHECK, GDB_SIGEMT }
};
-
// The offsets of registers SystemContextX64.
// The fields in the array are in the gdb ordering.
// HAVE TO DOUBLE-CHECK THE ORDER of the 24 regs
//
-UINTN gRegisterOffsets[] = {
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rax),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rcx),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rdx),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rbx),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rsp),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rbp),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rsi),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rdi),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rip),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Rflags),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Cs),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Ss),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Ds),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Es),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Fs),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, Gs),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R8),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R9),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R10),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R11),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R12),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R13),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R14),
- OFFSET_OF(EFI_SYSTEM_CONTEXT_X64, R15)
+UINTN gRegisterOffsets[] = {
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rax),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rcx),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rdx),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rbx),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rsp),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rbp),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rsi),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rdi),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rip),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Rflags),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Cs),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Ss),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Ds),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Es),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Fs),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, Gs),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R8),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R9),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R10),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R11),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R12),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R13),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R14),
+ OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R15)
};
-
/**
Return the number of entries in the gExceptionType[]
@@ -75,7 +73,6 @@ MaxEfiException (
return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);
}
-
/**
Return the number of entries in the gRegisters[]
@@ -89,7 +86,6 @@ MaxRegisterCount (
return sizeof (gRegisterOffsets)/sizeof (UINTN);
}
-
/**
Check to see if the ISA is supported.
ISA = Instruction Set Architecture
@@ -104,7 +100,6 @@ CheckIsa (
return (BOOLEAN)(Isa == IsaX64);
}
-
/**
This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
It is, by default, set to find the register pointer of the X64 member
@@ -113,17 +108,17 @@ CheckIsa (
@retval the pointer to the RegNumber-th pointer
**/
UINTN *
-FindPointerToRegister(
+FindPointerToRegister (
IN EFI_SYSTEM_CONTEXT SystemContext,
IN UINTN RegNumber
)
{
- UINT8 *TempPtr;
+ UINT8 *TempPtr;
+
TempPtr = ((UINT8 *)SystemContext.SystemContextX64) + gRegisterOffsets[RegNumber];
return (UINTN *)TempPtr;
}
-
/**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@param SystemContext Register content at time of the exception
@@ -133,23 +128,23 @@ FindPointerToRegister(
**/
CHAR8 *
BasicReadRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN RegNumber,
- IN CHAR8 *OutBufPtr
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN RegNumber,
+ IN CHAR8 *OutBufPtr
)
{
- UINTN RegSize;
+ UINTN RegSize;
RegSize = 0;
while (RegSize < 64) {
- *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];
- *OutBufPtr++ = mHexToStr[((*FindPointerToRegister(SystemContext, RegNumber) >> RegSize) & 0xf)];
- RegSize = RegSize + 8;
+ *OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];
+ *OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];
+ RegSize = RegSize + 8;
}
+
return OutBufPtr;
}
-
/** ‘p n’
Reads the n-th register's value into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception
@@ -157,29 +152,28 @@ BasicReadRegister (
**/
VOID
ReadNthRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *InBuffer
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *InBuffer
)
{
- UINTN RegNumber;
- CHAR8 OutBuffer[17]; // 1 reg=16 hex chars, and the end '\0' (escape seq)
- CHAR8 *OutBufPtr; // pointer to the output buffer
+ UINTN RegNumber;
+ CHAR8 OutBuffer[17]; // 1 reg=16 hex chars, and the end '\0' (escape seq)
+ CHAR8 *OutBufPtr; // pointer to the output buffer
RegNumber = AsciiStrHexToUintn (&InBuffer[1]);
- if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {
+ if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount ())) {
SendError (GDB_EINVALIDREGNUM);
return;
}
OutBufPtr = OutBuffer;
- OutBufPtr = BasicReadRegister(SystemContext, RegNumber, OutBufPtr);
+ OutBufPtr = BasicReadRegister (SystemContext, RegNumber, OutBufPtr);
*OutBufPtr = '\0'; // the end of the buffer
SendPacket (OutBuffer);
}
-
/** ‘g’
Reads the general registers into an output buffer and sends it as a packet
@@ -188,23 +182,23 @@ ReadNthRegister (
VOID
EFIAPI
ReadGeneralRegisters (
- IN EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_SYSTEM_CONTEXT SystemContext
)
{
- UINTN i;
- CHAR8 OutBuffer[385]; // 24 regs, 16 hex chars each, and the end '\0' (escape seq)
- CHAR8 *OutBufPtr; // pointer to the output buffer
+ UINTN i;
+ CHAR8 OutBuffer[385]; // 24 regs, 16 hex chars each, and the end '\0' (escape seq)
+ CHAR8 *OutBufPtr; // pointer to the output buffer
OutBufPtr = OutBuffer;
- for(i = 0 ; i < MaxRegisterCount() ; i++) { // there are only 24 registers to read
- OutBufPtr = BasicReadRegister(SystemContext, i, OutBufPtr);
+ for (i = 0; i < MaxRegisterCount (); i++) {
+ // there are only 24 registers to read
+ OutBufPtr = BasicReadRegister (SystemContext, i, OutBufPtr);
}
*OutBufPtr = '\0'; // the end of the buffer
SendPacket (OutBuffer);
}
-
/**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@@ -220,14 +214,14 @@ BasicWriteRegister (
IN CHAR8 *InBufPtr
)
{
- UINTN RegSize;
- UINTN TempValue; // the value transferred from a hex char
- UINT64 NewValue; // the new value of the RegNumber-th Register
+ UINTN RegSize;
+ UINTN TempValue; // the value transferred from a hex char
+ UINT64 NewValue; // the new value of the RegNumber-th Register
NewValue = 0;
- RegSize = 0;
+ RegSize = 0;
while (RegSize < 64) {
- TempValue = HexCharToInt(*InBufPtr++);
+ TempValue = HexCharToInt (*InBufPtr++);
if (TempValue < 0) {
SendError (GDB_EBADMEMDATA);
@@ -235,21 +229,21 @@ BasicWriteRegister (
}
NewValue += (TempValue << (RegSize+4));
- TempValue = HexCharToInt(*InBufPtr++);
+ TempValue = HexCharToInt (*InBufPtr++);
if (TempValue < 0) {
SendError (GDB_EBADMEMDATA);
return NULL;
- }
+ }
NewValue += (TempValue << RegSize);
- RegSize = RegSize + 8;
+ RegSize = RegSize + 8;
}
- *(FindPointerToRegister(SystemContext, RegNumber)) = NewValue;
+
+ *(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;
return InBufPtr;
}
-
/** ‘P n...=r...’
Writes the new value of n-th register received into the input buffer to the n-th register
@@ -259,35 +253,36 @@ BasicWriteRegister (
VOID
EFIAPI
WriteNthRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *InBuffer
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *InBuffer
)
{
- UINTN RegNumber;
- CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array
- CHAR8 *RegNumBufPtr;
- CHAR8 *InBufPtr; // pointer to the input buffer
+ UINTN RegNumber;
+ CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array
+ CHAR8 *RegNumBufPtr;
+ CHAR8 *InBufPtr; // pointer to the input buffer
// find the register number to write
- InBufPtr = &InBuffer[1];
+ InBufPtr = &InBuffer[1];
RegNumBufPtr = RegNumBuffer;
while (*InBufPtr != '=') {
*RegNumBufPtr++ = *InBufPtr++;
}
+
*RegNumBufPtr = '\0';
- RegNumber = AsciiStrHexToUintn (RegNumBuffer);
+ RegNumber = AsciiStrHexToUintn (RegNumBuffer);
// check if this is a valid Register Number
- if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount())) {
+ if ((RegNumber < 0) || (RegNumber >= MaxRegisterCount ())) {
SendError (GDB_EINVALIDREGNUM);
return;
}
+
InBufPtr++; // skips the '=' character
BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
- SendSuccess();
+ SendSuccess ();
}
-
/** ‘G XX...’
Writes the new values received into the input buffer to the general registers
@@ -297,17 +292,18 @@ WriteNthRegister (
VOID
EFIAPI
WriteGeneralRegisters (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *InBuffer
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *InBuffer
)
{
UINTN i;
- CHAR8 *InBufPtr; /// pointer to the input buffer
+ CHAR8 *InBufPtr; /// pointer to the input buffer
// check to see if the buffer is the right size which is
// 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 385
- if (AsciiStrLen(InBuffer) != 385) { // 24 regs, 16 hex chars each, and the end '\0' (escape seq)
- //Bad message. Message is not the right length
+ if (AsciiStrLen (InBuffer) != 385) {
+ // 24 regs, 16 hex chars each, and the end '\0' (escape seq)
+ // Bad message. Message is not the right length
SendError (GDB_EBADBUFSIZE);
return;
}
@@ -316,29 +312,27 @@ WriteGeneralRegisters (
// Read the new values for the registers from the input buffer to an array, NewValueArray.
// The values in the array are in the gdb ordering
- for(i=0; i < MaxRegisterCount(); i++) { // there are only 16 registers to write
- InBufPtr = BasicWriteRegister(SystemContext, i, InBufPtr);
+ for (i = 0; i < MaxRegisterCount (); i++) {
+ // there are only 16 registers to write
+ InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr);
}
- SendSuccess();
+ SendSuccess ();
}
+/**
+Insert Single Step in the SystemContext
- /**
- Insert Single Step in the SystemContext
-
- @param SystemContext Register content at time of the exception
- **/
+@param SystemContext Register content at time of the exception
+**/
VOID
AddSingleStep (
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
- SystemContext.SystemContextX64->Rflags |= TF_BIT; //Setting the TF bit.
+ SystemContext.SystemContextX64->Rflags |= TF_BIT; // Setting the TF bit.
}
-
-
/**
Remove Single Step in the SystemContext
@@ -352,8 +346,6 @@ RemoveSingleStep (
SystemContext.SystemContextX64->Rflags &= ~TF_BIT; // clearing the TF bit.
}
-
-
/** ‘c [addr ]’
Continue. addr is Address to resume. If addr is omitted, resume at current
Address.
@@ -363,16 +355,15 @@ RemoveSingleStep (
VOID
EFIAPI
ContinueAtAddress (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *PacketData
)
{
if (PacketData[1] != '\0') {
- SystemContext.SystemContextX64->Rip = AsciiStrHexToUintn(&PacketData[1]);
+ SystemContext.SystemContextX64->Rip = AsciiStrHexToUintn (&PacketData[1]);
}
}
-
/** ‘s [addr ]’
Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address.
@@ -382,8 +373,8 @@ ContinueAtAddress (
VOID
EFIAPI
SingleStep (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN CHAR8 *PacketData
)
{
if (PacketData[1] != '\0') {
@@ -393,7 +384,6 @@ SingleStep (
AddSingleStep (SystemContext);
}
-
/**
Returns breakpoint data address from DR0-DR3 based on the input breakpoint
number
@@ -411,7 +401,7 @@ GetBreakpointDataAddress (
IN UINTN BreakpointNumber
)
{
- UINTN Address;
+ UINTN Address;
if (BreakpointNumber == 1) {
Address = SystemContext.SystemContextIa32->Dr0;
@@ -444,8 +434,8 @@ GetBreakpointDetected (
IN EFI_SYSTEM_CONTEXT SystemContext
)
{
- IA32_DR6 Dr6;
- UINTN BreakpointNumber;
+ IA32_DR6 Dr6;
+ UINTN BreakpointNumber;
Dr6.UintN = SystemContext.SystemContextIa32->Dr6;
@@ -458,7 +448,7 @@ GetBreakpointDetected (
} else if (Dr6.Bits.B3 == 1) {
BreakpointNumber = 4;
} else {
- BreakpointNumber = 0; //No breakpoint detected
+ BreakpointNumber = 0; // No breakpoint detected
}
return BreakpointNumber;
@@ -481,25 +471,24 @@ GetBreakpointType (
IN UINTN BreakpointNumber
)
{
- IA32_DR7 Dr7;
- BREAK_TYPE Type = NotSupported; //Default is NotSupported type
+ IA32_DR7 Dr7;
+ BREAK_TYPE Type = NotSupported; // Default is NotSupported type
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if (BreakpointNumber == 1) {
- Type = (BREAK_TYPE) Dr7.Bits.RW0;
+ Type = (BREAK_TYPE)Dr7.Bits.RW0;
} else if (BreakpointNumber == 2) {
- Type = (BREAK_TYPE) Dr7.Bits.RW1;
+ Type = (BREAK_TYPE)Dr7.Bits.RW1;
} else if (BreakpointNumber == 3) {
- Type = (BREAK_TYPE) Dr7.Bits.RW2;
+ Type = (BREAK_TYPE)Dr7.Bits.RW2;
} else if (BreakpointNumber == 4) {
- Type = (BREAK_TYPE) Dr7.Bits.RW3;
+ Type = (BREAK_TYPE)Dr7.Bits.RW3;
}
return Type;
}
-
/**
Parses Length and returns the length which DR7 LENn field accepts.
For example: If we receive 1-Byte length then we should return 0.
@@ -512,21 +501,24 @@ GetBreakpointType (
**/
UINTN
ConvertLengthData (
- IN UINTN Length
+ IN UINTN Length
)
{
- if (Length == 1) { //1-Byte length
+ if (Length == 1) {
+ // 1-Byte length
return 0;
- } else if (Length == 2) { //2-Byte length
+ } else if (Length == 2) {
+ // 2-Byte length
return 1;
- } else if (Length == 4) { //4-Byte length
+ } else if (Length == 4) {
+ // 4-Byte length
return 3;
- } else { //Undefined or 8-byte length
+ } else {
+ // Undefined or 8-byte length
return 2;
}
}
-
/**
Finds the next free debug register. If all the registers are occupied then
EFI_OUT_OF_RESOURCES is returned.
@@ -543,7 +535,7 @@ FindNextFreeDebugRegister (
OUT UINTN *Register
)
{
- IA32_DR7 Dr7;
+ IA32_DR7 Dr7;
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
@@ -562,7 +554,6 @@ FindNextFreeDebugRegister (
return EFI_SUCCESS;
}
-
/**
Enables the debug register. Writes Address value to appropriate DR0-3 register.
Sets LENn, Gn, RWn bits in DR7 register.
@@ -587,56 +578,56 @@ EnableDebugRegister (
{
IA32_DR7 Dr7;
- //Convert length data
+ // Convert length data
Length = ConvertLengthData (Length);
- //For Instruction execution, length should be 0
- //(Ref. Intel reference manual 18.2.4)
+ // For Instruction execution, length should be 0
+ // (Ref. Intel reference manual 18.2.4)
if ((Type == 0) && (Length != 0)) {
return EFI_INVALID_PARAMETER;
}
- //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
- //software breakpoint. We should send empty packet in both these cases.
+ // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
+ // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) ||
- (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
+ (Type == (BREAK_TYPE)SoftwareBreakpoint))
+ {
return EFI_UNSUPPORTED;
}
- //Read DR7 so appropriate Gn, RWn and LENn bits can be modified.
+ // Read DR7 so appropriate Gn, RWn and LENn bits can be modified.
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if (Register == 0) {
SystemContext.SystemContextIa32->Dr0 = Address;
- Dr7.Bits.G0 = 1;
- Dr7.Bits.RW0 = Type;
- Dr7.Bits.LEN0 = Length;
+ Dr7.Bits.G0 = 1;
+ Dr7.Bits.RW0 = Type;
+ Dr7.Bits.LEN0 = Length;
} else if (Register == 1) {
SystemContext.SystemContextIa32->Dr1 = Address;
- Dr7.Bits.G1 = 1;
- Dr7.Bits.RW1 = Type;
- Dr7.Bits.LEN1 = Length;
+ Dr7.Bits.G1 = 1;
+ Dr7.Bits.RW1 = Type;
+ Dr7.Bits.LEN1 = Length;
} else if (Register == 2) {
SystemContext.SystemContextIa32->Dr2 = Address;
- Dr7.Bits.G2 = 1;
- Dr7.Bits.RW2 = Type;
- Dr7.Bits.LEN2 = Length;
+ Dr7.Bits.G2 = 1;
+ Dr7.Bits.RW2 = Type;
+ Dr7.Bits.LEN2 = Length;
} else if (Register == 3) {
SystemContext.SystemContextIa32->Dr3 = Address;
- Dr7.Bits.G3 = 1;
- Dr7.Bits.RW3 = Type;
- Dr7.Bits.LEN3 = Length;
+ Dr7.Bits.G3 = 1;
+ Dr7.Bits.RW3 = Type;
+ Dr7.Bits.LEN3 = Length;
} else {
return EFI_INVALID_PARAMETER;
}
- //Update Dr7 with appropriate Gn, RWn and LENn bits
+ // Update Dr7 with appropriate Gn, RWn and LENn bits
SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
return EFI_SUCCESS;
}
-
/**
Returns register number 0 - 3 for the matching debug register.
This function compares incoming Address, Type, Length and
@@ -655,46 +646,51 @@ EnableDebugRegister (
**/
EFI_STATUS
FindMatchingDebugRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN Address,
- IN UINTN Length,
- IN UINTN Type,
- OUT UINTN *Register
- )
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN Address,
+ IN UINTN Length,
+ IN UINTN Type,
+ OUT UINTN *Register
+ )
{
- IA32_DR7 Dr7;
+ IA32_DR7 Dr7;
- //Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
- //software breakpoint. We should send empty packet in both these cases.
+ // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
+ // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) ||
- (Type == (BREAK_TYPE)SoftwareBreakpoint)) {
+ (Type == (BREAK_TYPE)SoftwareBreakpoint))
+ {
return EFI_UNSUPPORTED;
}
- //Convert length data
- Length = ConvertLengthData(Length);
+ // Convert length data
+ Length = ConvertLengthData (Length);
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if ((Dr7.Bits.G0 == 1) &&
(Dr7.Bits.LEN0 == Length) &&
(Dr7.Bits.RW0 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr0)) {
+ (Address == SystemContext.SystemContextIa32->Dr0))
+ {
*Register = 0;
} else if ((Dr7.Bits.G1 == 1) &&
(Dr7.Bits.LEN1 == Length) &&
(Dr7.Bits.RW1 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr1)) {
+ (Address == SystemContext.SystemContextIa32->Dr1))
+ {
*Register = 1;
} else if ((Dr7.Bits.G2 == 1) &&
(Dr7.Bits.LEN2 == Length) &&
(Dr7.Bits.RW2 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr2)) {
+ (Address == SystemContext.SystemContextIa32->Dr2))
+ {
*Register = 2;
} else if ((Dr7.Bits.G3 == 1) &&
(Dr7.Bits.LEN3 == Length) &&
(Dr7.Bits.RW3 == Type) &&
- (Address == SystemContext.SystemContextIa32->Dr3)) {
+ (Address == SystemContext.SystemContextIa32->Dr3))
+ {
*Register = 3;
} else {
Print ((CHAR16 *)L"No match found..\n");
@@ -704,7 +700,6 @@ FindMatchingDebugRegister (
return EFI_SUCCESS;
}
-
/**
Disables the particular debug register.
@@ -716,41 +711,41 @@ FindMatchingDebugRegister (
**/
EFI_STATUS
DisableDebugRegister (
- IN EFI_SYSTEM_CONTEXT SystemContext,
- IN UINTN Register
- )
+ IN EFI_SYSTEM_CONTEXT SystemContext,
+ IN UINTN Register
+ )
{
IA32_DR7 Dr7;
- UINTN Address = 0;
+ UINTN Address = 0;
- //Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
+ // Read DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
if (Register == 0) {
SystemContext.SystemContextIa32->Dr0 = Address;
- Dr7.Bits.G0 = 0;
- Dr7.Bits.RW0 = 0;
- Dr7.Bits.LEN0 = 0;
+ Dr7.Bits.G0 = 0;
+ Dr7.Bits.RW0 = 0;
+ Dr7.Bits.LEN0 = 0;
} else if (Register == 1) {
SystemContext.SystemContextIa32->Dr1 = Address;
- Dr7.Bits.G1 = 0;
- Dr7.Bits.RW1 = 0;
- Dr7.Bits.LEN1 = 0;
+ Dr7.Bits.G1 = 0;
+ Dr7.Bits.RW1 = 0;
+ Dr7.Bits.LEN1 = 0;
} else if (Register == 2) {
SystemContext.SystemContextIa32->Dr2 = Address;
- Dr7.Bits.G2 = 0;
- Dr7.Bits.RW2 = 0;
- Dr7.Bits.LEN2 = 0;
+ Dr7.Bits.G2 = 0;
+ Dr7.Bits.RW2 = 0;
+ Dr7.Bits.LEN2 = 0;
} else if (Register == 3) {
SystemContext.SystemContextIa32->Dr3 = Address;
- Dr7.Bits.G3 = 0;
- Dr7.Bits.RW3 = 0;
- Dr7.Bits.LEN3 = 0;
+ Dr7.Bits.G3 = 0;
+ Dr7.Bits.RW3 = 0;
+ Dr7.Bits.LEN3 = 0;
} else {
return EFI_INVALID_PARAMETER;
}
- //Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
+ // Update DR7 register so appropriate Gn, RWn and LENn bits can be turned off.
SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
return EFI_SUCCESS;
@@ -772,16 +767,16 @@ VOID
EFIAPI
InsertBreakPoint (
IN EFI_SYSTEM_CONTEXT SystemContext,
- IN CHAR8 *PacketData
+ IN CHAR8 *PacketData
)
{
- UINTN Type;
- UINTN Address;
- UINTN Length;
- UINTN Register;
- EFI_STATUS Status;
- BREAK_TYPE BreakType = NotSupported;
- UINTN ErrorCode;
+ UINTN Type;
+ UINTN Address;
+ UINTN Length;
+ UINTN Register;
+ EFI_STATUS Status;
+ BREAK_TYPE BreakType = NotSupported;
+ UINTN ErrorCode;
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
if (ErrorCode > 0) {
@@ -790,28 +785,27 @@ InsertBreakPoint (
}
switch (Type) {
-
- case 0: //Software breakpoint
+ case 0: // Software breakpoint
BreakType = SoftwareBreakpoint;
break;
- case 1: //Hardware breakpoint
+ case 1: // Hardware breakpoint
BreakType = InstructionExecution;
break;
- case 2: //Write watchpoint
+ case 2: // Write watchpoint
BreakType = DataWrite;
break;
- case 3: //Read watchpoint
+ case 3: // Read watchpoint
BreakType = DataRead;
break;
- case 4: //Access watchpoint
+ case 4: // Access watchpoint
BreakType = DataReadWrite;
break;
- default :
+ default:
Print ((CHAR16 *)L"Insert breakpoint default: %x\n", Type);
SendError (GDB_EINVALIDBRKPOINTTYPE);
return;
@@ -819,7 +813,7 @@ InsertBreakPoint (
// Find next free debug register
Status = FindNextFreeDebugRegister (SystemContext, &Register);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
Print ((CHAR16 *)L"No space left on device\n");
SendError (GDB_ENOSPACE);
return;
@@ -827,11 +821,10 @@ InsertBreakPoint (
// Write Address, length data at particular DR register
Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);
- if (EFI_ERROR(Status)) {
-
+ if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported\n");
- SendNotSupported();
+ SendNotSupported ();
return;
}
@@ -843,7 +836,6 @@ InsertBreakPoint (
SendSuccess ();
}
-
/**
‘z1, [addr], [length]’
‘z2, [addr], [length]’
@@ -862,15 +854,15 @@ RemoveBreakPoint (
IN CHAR8 *PacketData
)
{
- UINTN Type;
- UINTN Address;
- UINTN Length;
- UINTN Register;
- BREAK_TYPE BreakType = NotSupported;
- EFI_STATUS Status;
- UINTN ErrorCode;
-
- //Parse breakpoint packet data
+ UINTN Type;
+ UINTN Address;
+ UINTN Length;
+ UINTN Register;
+ BREAK_TYPE BreakType = NotSupported;
+ EFI_STATUS Status;
+ UINTN ErrorCode;
+
+ // Parse breakpoint packet data
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
if (ErrorCode > 0) {
SendError ((UINT8)ErrorCode);
@@ -878,39 +870,37 @@ RemoveBreakPoint (
}
switch (Type) {
-
- case 0: //Software breakpoint
+ case 0: // Software breakpoint
BreakType = SoftwareBreakpoint;
break;
- case 1: //Hardware breakpoint
+ case 1: // Hardware breakpoint
BreakType = InstructionExecution;
break;
- case 2: //Write watchpoint
+ case 2: // Write watchpoint
BreakType = DataWrite;
break;
- case 3: //Read watchpoint
+ case 3: // Read watchpoint
BreakType = DataRead;
break;
- case 4: //Access watchpoint
+ case 4: // Access watchpoint
BreakType = DataReadWrite;
break;
- default :
+ default:
SendError (GDB_EINVALIDBRKPOINTTYPE);
return;
}
- //Find matching debug register
+ // Find matching debug register
Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);
- if (EFI_ERROR(Status)) {
-
+ if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported.\n");
- SendNotSupported();
+ SendNotSupported ();
return;
}
@@ -919,9 +909,9 @@ RemoveBreakPoint (
return;
}
- //Remove breakpoint
- Status = DisableDebugRegister(SystemContext, Register);
- if (EFI_ERROR(Status)) {
+ // Remove breakpoint
+ Status = DisableDebugRegister (SystemContext, Register);
+ if (EFI_ERROR (Status)) {
Print ((CHAR16 *)L"Invalid argument.\n");
SendError (GDB_EINVALIDARG);
return;
@@ -930,7 +920,6 @@ RemoveBreakPoint (
SendSuccess ();
}
-
VOID
InitializeProcessor (
VOID
@@ -948,10 +937,9 @@ ValidateAddress (
BOOLEAN
ValidateException (
- IN EFI_EXCEPTION_TYPE ExceptionType,
- IN OUT EFI_SYSTEM_CONTEXT SystemContext
+ IN EFI_EXCEPTION_TYPE ExceptionType,
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext
)
{
return TRUE;
}
-