summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/GdbStub/Ia32/Processor.c
diff options
context:
space:
mode:
Diffstat (limited to 'EmbeddedPkg/GdbStub/Ia32/Processor.c')
-rw-r--r--EmbeddedPkg/GdbStub/Ia32/Processor.c443
1 files changed, 214 insertions, 229 deletions
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;
}
-