Processor specific parts of the GDB stub\r
\r
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
- \r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
//\r
EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {\r
{ EXCEPT_ARM_SOFTWARE_INTERRUPT, GDB_SIGTRAP }\r
-// { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP }, \r
-// { EXCEPT_ARM_PREFETCH_ABORT, GDB_SIGTRAP }, \r
-// { EXCEPT_ARM_DATA_ABORT, GDB_SIGEMT }, \r
-// { EXCEPT_ARM_RESERVED, GDB_SIGILL } \r
+// { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP },\r
+// { EXCEPT_ARM_PREFETCH_ABORT, GDB_SIGTRAP },\r
+// { EXCEPT_ARM_DATA_ABORT, GDB_SIGEMT },\r
+// { EXCEPT_ARM_RESERVED, GDB_SIGILL }\r
};\r
\r
// Shut up some annoying RVCT warnings\r
\r
/**\r
Return the number of entries in the gExceptionType[]\r
- \r
- @retval UINTN, the number of entries in the gExceptionType[] array. \r
+\r
+ @retval UINTN, the number of entries in the gExceptionType[] array.\r
**/\r
UINTN\r
MaxEfiException (\r
\r
/**\r
Return the number of entries in the gRegisters[]\r
- \r
- @retval UINTN, the number of entries (registers) in the gRegisters[] array. \r
+\r
+ @retval UINTN, the number of entries (registers) in the gRegisters[] array.\r
**/\r
UINTN\r
MaxRegisterCount (\r
\r
\r
/**\r
- Check to see if the ISA is supported. \r
+ Check to see if the ISA is supported.\r
ISA = Instruction Set Architecture\r
\r
- @retval TRUE if Isa is supported \r
+ @retval TRUE if Isa is supported\r
\r
**/\r
BOOLEAN\r
/**\r
This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering\r
It is, by default, set to find the register pointer of the ARM member\r
- @param SystemContext Register content at time of the exception \r
+ @param SystemContext Register content at time of the exception\r
@param RegNumber The register to which we want to find a pointer\r
@retval the pointer to the RegNumber-th pointer\r
- **/ \r
+ **/\r
UINTN *\r
FindPointerToRegister (\r
IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN RegNumber \r
+ IN UINTN RegNumber\r
)\r
{\r
UINT8 *TempPtr;\r
{\r
UINTN RegSize;\r
CHAR8 Char;\r
- \r
+\r
if (gRegisterOffsets[RegNumber] > 0xF00) {\r
AsciiSPrint (OutBufPtr, 9, "00000000");\r
OutBufPtr += 8;\r
Char = Char - 'A' + 'a';\r
}\r
*OutBufPtr++ = Char;\r
- \r
+\r
Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];\r
if ((Char >= 'A') && (Char <= 'F')) {\r
Char = Char - 'A' + 'a';\r
}\r
*OutBufPtr++ = Char;\r
- \r
+\r
RegSize = RegSize + 8;\r
}\r
return OutBufPtr;\r
\r
\r
/**\r
- Reads the n-th register's value into an output buffer and sends it as a packet \r
+ Reads the n-th register's value into an output buffer and sends it as a packet\r
@param SystemContext Register content at time of the exception\r
@param InBuffer Pointer to the input buffer received from gdb server\r
**/\r
UINTN RegNumber;\r
CHAR8 OutBuffer[9]; // 1 reg=8 hex chars, and the end '\0' (escape seq)\r
CHAR8 *OutBufPtr; // pointer to the output buffer\r
- \r
+\r
RegNumber = AsciiStrHexToUintn (&InBuffer[1]);\r
- \r
+\r
if (RegNumber >= MaxRegisterCount ()) {\r
- SendError (GDB_EINVALIDREGNUM); \r
+ SendError (GDB_EINVALIDREGNUM);\r
return;\r
}\r
- \r
+\r
OutBufPtr = OutBuffer;\r
OutBufPtr = BasicReadRegister (SystemContext, RegNumber, OutBufPtr);\r
- \r
+\r
*OutBufPtr = '\0'; // the end of the buffer\r
SendPacket (OutBuffer);\r
}\r
\r
\r
/**\r
- Reads the general registers into an output buffer and sends it as a packet \r
+ Reads the general registers into an output buffer and sends it as a packet\r
@param SystemContext Register content at time of the exception\r
**/\r
VOID\r
EFIAPI\r
-ReadGeneralRegisters ( \r
+ReadGeneralRegisters (\r
IN EFI_SYSTEM_CONTEXT SystemContext\r
)\r
{\r
CHAR8 *OutBuffer;\r
CHAR8 *OutBufPtr;\r
UINTN RegisterCount = MaxRegisterCount ();\r
- \r
+\r
// It is not safe to allocate pool here....\r
OutBuffer = AllocatePool ((RegisterCount * 8) + 1); // 8 bytes per register in string format plus a null to terminate\r
OutBufPtr = OutBuffer;\r
for (Index = 0; Index < RegisterCount; Index++) {\r
OutBufPtr = BasicReadRegister (SystemContext, Index, OutBufPtr);\r
}\r
- \r
+\r
*OutBufPtr = '\0';\r
SendPacket (OutBuffer);\r
FreePool (OutBuffer);\r
UINTN RegSize;\r
UINTN TempValue; // the value transferred from a hex char\r
UINT32 NewValue; // the new value of the RegNumber-th Register\r
- \r
+\r
if (gRegisterOffsets[RegNumber] > 0xF00) {\r
return InBufPtr + 8;\r
}\r
RegSize = 0;\r
while (RegSize < 32) {\r
TempValue = HexCharToInt (*InBufPtr++);\r
- \r
+\r
if ((INTN)TempValue < 0) {\r
- SendError (GDB_EBADMEMDATA); \r
+ SendError (GDB_EBADMEMDATA);\r
return NULL;\r
}\r
- \r
+\r
NewValue += (TempValue << (RegSize+4));\r
TempValue = HexCharToInt (*InBufPtr++);\r
- \r
+\r
if ((INTN)TempValue < 0) {\r
- SendError (GDB_EBADMEMDATA); \r
+ SendError (GDB_EBADMEMDATA);\r
return NULL;\r
}\r
- \r
- NewValue += (TempValue << RegSize); \r
+\r
+ NewValue += (TempValue << RegSize);\r
RegSize = RegSize + 8;\r
}\r
*(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;\r
/** ‘P n...=r...’\r
Writes the new value of n-th register received into the input buffer to the n-th register\r
@param SystemContext Register content at time of the exception\r
- @param InBuffer Ponter to the input buffer received from gdb server\r
+ @param InBuffer Pointer to the input buffer received from gdb server\r
**/\r
VOID\r
WriteNthRegister (\r
CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE]; // put the 'n..' part of the message into this array\r
CHAR8 *RegNumBufPtr;\r
CHAR8 *InBufPtr; // pointer to the input buffer\r
- \r
+\r
// find the register number to write\r
InBufPtr = &InBuffer[1];\r
RegNumBufPtr = RegNumBuffer;\r
while (*InBufPtr != '=') {\r
*RegNumBufPtr++ = *InBufPtr++;\r
- } \r
+ }\r
*RegNumBufPtr = '\0';\r
- RegNumber = AsciiStrHexToUintn (RegNumBuffer); \r
- \r
+ RegNumber = AsciiStrHexToUintn (RegNumBuffer);\r
+\r
// check if this is a valid Register Number\r
if (RegNumber >= MaxRegisterCount ()) {\r
- SendError (GDB_EINVALIDREGNUM); \r
+ SendError (GDB_EINVALIDREGNUM);\r
return;\r
}\r
InBufPtr++; // skips the '=' character\r
UINTN RegisterCount = MaxRegisterCount ();\r
\r
MinLength = (RegisterCount * 8) + 1; // 'G' plus the registers in ASCII format\r
- \r
+\r
if (AsciiStrLen (InBuffer) < MinLength) {\r
- //Bad message. Message is not the right length \r
- SendError (GDB_EBADBUFSIZE); \r
+ //Bad message. Message is not the right length\r
+ SendError (GDB_EBADBUFSIZE);\r
return;\r
}\r
- \r
+\r
InBufPtr = &InBuffer[1];\r
- \r
+\r
// Read the new values for the registers from the input buffer to an array, NewValueArray.\r
// The values in the array are in the gdb ordering\r
for (i = 0; i < RegisterCount; i++) {\r
InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr);\r
}\r
- \r
+\r
SendSuccess ();\r
}\r
\r
\r
LIST_ENTRY BreakpointList;\r
\r
-/** \r
+/**\r
Insert Single Step in the SystemContext\r
- \r
- @param SystemContext Register content at time of the exception\r
+\r
+ @param SystemContext Register content at time of the exception\r
**/\r
VOID\r
AddSingleStep (\r
return;\r
}\r
mSingleStepActive = TRUE;\r
- \r
+\r
mSingleStepPC = SystemContext.SystemContextArm->PC;\r
\r
mSingleStepDataSize = sizeof (UINT32);\r
- mSingleStepData = (*(UINT32 *)mSingleStepPC); \r
+ mSingleStepData = (*(UINT32 *)mSingleStepPC);\r
*(UINT32 *)mSingleStepPC = GDB_ARM_BKPT;\r
if (*(UINT32 *)mSingleStepPC != GDB_ARM_BKPT) {\r
// For some reason our breakpoint did not take\r
//DEBUG((EFI_D_ERROR, "AddSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, mSingleStepData, *(UINT32 *)mSingleStepPC));\r
}\r
\r
- \r
-/** \r
+\r
+/**\r
Remove Single Step in the SystemContext\r
- \r
- @param SystemContext Register content at time of the exception\r
+\r
+ @param SystemContext Register content at time of the exception\r
**/\r
VOID\r
RemoveSingleStep (\r
if (!mSingleStepActive) {\r
return;\r
}\r
- \r
+\r
if (mSingleStepDataSize == sizeof (UINT16)) {\r
*(UINT16 *)mSingleStepPC = (UINT16)mSingleStepData;\r
} else {\r
\r
\r
/**\r
- Continue. addr is Address to resume. If addr is omitted, resume at current \r
+ Continue. addr is Address to resume. If addr is omitted, resume at current\r
Address.\r
- \r
- @param SystemContext Register content at time of the exception \r
+\r
+ @param SystemContext Register content at time of the exception\r
**/\r
VOID\r
EFIAPI\r
{\r
if (PacketData[1] != '\0') {\r
SystemContext.SystemContextArm->PC = AsciiStrHexToUintn (&PacketData[1]);\r
- } \r
+ }\r
}\r
\r
\r
/** ‘s [addr ]’\r
- Single step. addr is the Address at which to resume. If addr is omitted, resume \r
+ Single step. addr is the Address at which to resume. If addr is omitted, resume\r
at same Address.\r
- \r
- @param SystemContext Register content at time of the exception \r
+\r
+ @param SystemContext Register content at time of the exception\r
**/\r
VOID\r
EFIAPI\r
Breakpoint->Signature = ARM_SOFTWARE_BREAKPOINT_SIGNATURE;\r
Breakpoint->Address = Address;\r
Breakpoint->Instruction = *(UINT32 *)Address;\r
- \r
+\r
// Add it to the list\r
InsertTailList (&BreakpointList, &Breakpoint->Link);\r
\r
switch (Type) {\r
case 0: //Software breakpoint\r
break;\r
- \r
+\r
default:\r
SendError (GDB_EINVALIDBRKPOINTTYPE);\r
return;\r
\r
BOOLEAN\r
ValidateException (\r
- IN EFI_EXCEPTION_TYPE ExceptionType, \r
- IN OUT EFI_SYSTEM_CONTEXT SystemContext \r
+ IN EFI_EXCEPTION_TYPE ExceptionType,\r
+ IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
)\r
{\r
UINT32 ExceptionAddress;\r
UINT32 Instruction;\r
- \r
+\r
// Is it a debugger SWI?\r
ExceptionAddress = SystemContext.SystemContextArm->PC -= 4;\r
Instruction = *(UINT32 *)ExceptionAddress;\r