2009-12-06 02:57:05 +01:00
|
|
|
|
/** @file
|
|
|
|
|
Processor specific parts of the GDB stub
|
|
|
|
|
|
2010-04-29 14:40:51 +02:00
|
|
|
|
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2010-04-29 14:40:51 +02:00
|
|
|
|
This program and the accompanying materials
|
2009-12-06 02:57:05 +01:00
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include <GdbStubInternal.h>
|
|
|
|
|
#include <Library/CacheMaintenanceLib.h>
|
|
|
|
|
#include <Library/PrintLib.h>
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 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 }
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// { EXCEPT_ARM_UNDEFINED_INSTRUCTION, GDB_SIGTRAP },
|
|
|
|
|
// { EXCEPT_ARM_PREFETCH_ABORT, GDB_SIGTRAP },
|
|
|
|
|
// { EXCEPT_ARM_DATA_ABORT, GDB_SIGEMT },
|
|
|
|
|
// { EXCEPT_ARM_RESERVED, GDB_SIGILL }
|
2009-12-06 02:57:05 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Shut up some annoying RVCT warnings
|
|
|
|
|
#ifdef __CC_ARM
|
|
|
|
|
#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
|
|
|
|
|
0x00000F02,
|
|
|
|
|
0x00000F03,
|
|
|
|
|
0x00000F11, // f1
|
|
|
|
|
0x00000F12,
|
|
|
|
|
0x00000F13,
|
|
|
|
|
0x00000F21, // f2
|
|
|
|
|
0x00000F22,
|
|
|
|
|
0x00000F23,
|
|
|
|
|
0x00000F31, // f3
|
|
|
|
|
0x00000F32,
|
|
|
|
|
0x00000F33,
|
|
|
|
|
0x00000F41, // f4
|
|
|
|
|
0x00000F42,
|
|
|
|
|
0x00000F43,
|
|
|
|
|
0x00000F51, // f5
|
|
|
|
|
0x00000F52,
|
|
|
|
|
0x00000F53,
|
|
|
|
|
0x00000F61, // f6
|
|
|
|
|
0x00000F62,
|
|
|
|
|
0x00000F63,
|
|
|
|
|
0x00000F71, // f7
|
|
|
|
|
0x00000F72,
|
|
|
|
|
0x00000F73,
|
|
|
|
|
0x00000FFF, // fps
|
|
|
|
|
OFFSET_OF(EFI_SYSTEM_CONTEXT_ARM, CPSR)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// restore warnings for RVCT
|
|
|
|
|
#ifdef __CC_ARM
|
|
|
|
|
#pragma diag_default 1296
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Return the number of entries in the gExceptionType[]
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
@retval UINTN, the number of entries in the gExceptionType[] array.
|
2009-12-06 02:57:05 +01:00
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
MaxEfiException (
|
|
|
|
|
VOID
|
|
|
|
|
)
|
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
|
return sizeof (gExceptionType) / sizeof (EFI_EXCEPTION_TYPE_ENTRY);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Return the number of entries in the gRegisters[]
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
@retval UINTN, the number of entries (registers) in the gRegisters[] array.
|
2009-12-06 02:57:05 +01:00
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
MaxRegisterCount (
|
|
|
|
|
VOID
|
|
|
|
|
)
|
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
|
return sizeof (gRegisterOffsets) / sizeof (UINTN);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Check to see if the ISA is supported.
|
2009-12-06 02:57:05 +01:00
|
|
|
|
ISA = Instruction Set Architecture
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@retval TRUE if Isa is supported
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
BOOLEAN
|
|
|
|
|
CheckIsa (
|
|
|
|
|
IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if (Isa == IsaArm) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
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
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
2009-12-06 02:57:05 +01:00
|
|
|
|
@param RegNumber The register to which we want to find a pointer
|
|
|
|
|
@retval the pointer to the RegNumber-th pointer
|
2014-08-19 15:29:52 +02:00
|
|
|
|
**/
|
2009-12-06 02:57:05 +01:00
|
|
|
|
UINTN *
|
2013-03-12 01:45:29 +01:00
|
|
|
|
FindPointerToRegister (
|
2009-12-06 02:57:05 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
2014-08-19 15:29:52 +02:00
|
|
|
|
IN UINTN RegNumber
|
2009-12-06 02:57:05 +01:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
@param RegNumber the number of the register that we want to read
|
|
|
|
|
@param OutBufPtr pointer to the output buffer's end. the new data will be added from this point on.
|
|
|
|
|
@retval the pointer to the next character of the output buffer that is available to be written on.
|
|
|
|
|
**/
|
|
|
|
|
CHAR8 *
|
|
|
|
|
BasicReadRegister (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN RegNumber,
|
|
|
|
|
IN CHAR8 *OutBufPtr
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN RegSize;
|
|
|
|
|
CHAR8 Char;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if (gRegisterOffsets[RegNumber] > 0xF00) {
|
2013-03-12 01:45:29 +01:00
|
|
|
|
AsciiSPrint (OutBufPtr, 9, "00000000");
|
2009-12-06 02:57:05 +01:00
|
|
|
|
OutBufPtr += 8;
|
|
|
|
|
return OutBufPtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegSize = 0;
|
|
|
|
|
while (RegSize < 32) {
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if ((Char >= 'A') && (Char <= 'F')) {
|
|
|
|
|
Char = Char - 'A' + 'a';
|
|
|
|
|
}
|
|
|
|
|
*OutBufPtr++ = Char;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if ((Char >= 'A') && (Char <= 'F')) {
|
|
|
|
|
Char = Char - 'A' + 'a';
|
|
|
|
|
}
|
|
|
|
|
*OutBufPtr++ = Char;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
RegSize = RegSize + 8;
|
|
|
|
|
}
|
|
|
|
|
return OutBufPtr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Reads the n-th register's value into an output buffer and sends it as a packet
|
2009-12-06 02:57:05 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
@param InBuffer Pointer to the input buffer received from gdb server
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
ReadNthRegister (
|
|
|
|
|
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
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
RegNumber = AsciiStrHexToUintn (&InBuffer[1]);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (RegNumber >= MaxRegisterCount ()) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EINVALIDREGNUM);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
OutBufPtr = OutBuffer;
|
|
|
|
|
OutBufPtr = BasicReadRegister (SystemContext, RegNumber, OutBufPtr);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
*OutBufPtr = '\0'; // the end of the buffer
|
2013-03-12 01:45:29 +01:00
|
|
|
|
SendPacket (OutBuffer);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Reads the general registers into an output buffer and sends it as a packet
|
2009-12-06 02:57:05 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2014-08-19 15:29:52 +02:00
|
|
|
|
ReadGeneralRegisters (
|
2009-12-06 02:57:05 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN Index;
|
|
|
|
|
CHAR8 *OutBuffer;
|
|
|
|
|
CHAR8 *OutBufPtr;
|
2013-03-12 01:45:29 +01:00
|
|
|
|
UINTN RegisterCount = MaxRegisterCount ();
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
// It is not safe to allocate pool here....
|
2013-03-12 01:45:29 +01:00
|
|
|
|
OutBuffer = AllocatePool ((RegisterCount * 8) + 1); // 8 bytes per register in string format plus a null to terminate
|
2009-12-06 02:57:05 +01:00
|
|
|
|
OutBufPtr = OutBuffer;
|
|
|
|
|
for (Index = 0; Index < RegisterCount; Index++) {
|
|
|
|
|
OutBufPtr = BasicReadRegister (SystemContext, Index, OutBufPtr);
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
*OutBufPtr = '\0';
|
2013-03-12 01:45:29 +01:00
|
|
|
|
SendPacket (OutBuffer);
|
|
|
|
|
FreePool (OutBuffer);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
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
|
|
|
|
|
@param RegNumber the number of the register that we want to write
|
|
|
|
|
@param InBufPtr pointer to the output buffer. the new data will be extracted from the input buffer from this point on.
|
|
|
|
|
@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
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN RegSize;
|
|
|
|
|
UINTN TempValue; // the value transferred from a hex char
|
|
|
|
|
UINT32 NewValue; // the new value of the RegNumber-th Register
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if (gRegisterOffsets[RegNumber] > 0xF00) {
|
|
|
|
|
return InBufPtr + 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NewValue = 0;
|
|
|
|
|
RegSize = 0;
|
|
|
|
|
while (RegSize < 32) {
|
2013-03-12 01:45:29 +01:00
|
|
|
|
TempValue = HexCharToInt (*InBufPtr++);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if ((INTN)TempValue < 0) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMDATA);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
NewValue += (TempValue << (RegSize+4));
|
2013-03-12 01:45:29 +01:00
|
|
|
|
TempValue = HexCharToInt (*InBufPtr++);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if ((INTN)TempValue < 0) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EBADMEMDATA);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
NewValue += (TempValue << RegSize);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
RegSize = RegSize + 8;
|
|
|
|
|
}
|
2013-03-12 01:45:29 +01:00
|
|
|
|
*(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;
|
2009-12-06 02:57:05 +01:00
|
|
|
|
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
|
|
|
|
|
@param InBuffer Ponter to the input buffer received from gdb server
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
WriteNthRegister (
|
|
|
|
|
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
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
// find the register number to write
|
|
|
|
|
InBufPtr = &InBuffer[1];
|
|
|
|
|
RegNumBufPtr = RegNumBuffer;
|
|
|
|
|
while (*InBufPtr != '=') {
|
|
|
|
|
*RegNumBufPtr++ = *InBufPtr++;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
}
|
2009-12-06 02:57:05 +01:00
|
|
|
|
*RegNumBufPtr = '\0';
|
2014-08-19 15:29:52 +02:00
|
|
|
|
RegNumber = AsciiStrHexToUintn (RegNumBuffer);
|
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
// check if this is a valid Register Number
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (RegNumber >= MaxRegisterCount ()) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
SendError (GDB_EINVALIDREGNUM);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
InBufPtr++; // skips the '=' character
|
|
|
|
|
BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
|
|
|
|
|
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 (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *InBuffer
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN i;
|
|
|
|
|
CHAR8 *InBufPtr; /// pointer to the input buffer
|
|
|
|
|
UINTN MinLength;
|
2013-03-12 01:45:29 +01:00
|
|
|
|
UINTN RegisterCount = MaxRegisterCount ();
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
MinLength = (RegisterCount * 8) + 1; // 'G' plus the registers in ASCII format
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
if (AsciiStrLen (InBuffer) < MinLength) {
|
2014-08-19 15:29:52 +02:00
|
|
|
|
//Bad message. Message is not the right length
|
|
|
|
|
SendError (GDB_EBADBUFSIZE);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
InBufPtr = &InBuffer[1];
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
// 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
|
2013-03-12 01:45:29 +01:00
|
|
|
|
for (i = 0; i < RegisterCount; i++) {
|
2009-12-06 02:57:05 +01:00
|
|
|
|
InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr);
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
SendSuccess ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// What about Thumb?
|
|
|
|
|
// Use SWI 0xdbdbdb as the debug instruction
|
|
|
|
|
#define GDB_ARM_BKPT 0xefdbdbdb
|
|
|
|
|
|
|
|
|
|
BOOLEAN mSingleStepActive = FALSE;
|
|
|
|
|
UINT32 mSingleStepPC;
|
|
|
|
|
UINT32 mSingleStepData;
|
|
|
|
|
UINTN mSingleStepDataSize;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
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_FROM_LINK(a) CR(a, ARM_SOFTWARE_BREAKPOINT, Link, ARM_SOFTWARE_BREAKPOINT_SIGNATURE)
|
|
|
|
|
|
|
|
|
|
LIST_ENTRY BreakpointList;
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
/**
|
2009-12-06 02:57:05 +01:00
|
|
|
|
Insert Single Step in the SystemContext
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
ARM Packages: Replace tabs by spaces for indentation
Replace tabs by spaces for indentation to comply to EDK2 coding standards.
Done in files with extension ".S", ".c", ".h", ".asm", ".dsc", ".inc", "*.inf",
"*.dec" or ".fdf" and located in ArmPkg, ArmPlatformPkg, EmbeddedPkg,
BeagleBoardPkg or Omap35xxPkg.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15901 6f19259b-4bc3-4df7-8a09-765794883524
2014-08-26 12:14:17 +02:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
2009-12-06 02:57:05 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
AddSingleStep (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if (mSingleStepActive) {
|
|
|
|
|
// Currently don't support nesting
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mSingleStepActive = TRUE;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
mSingleStepPC = SystemContext.SystemContextArm->PC;
|
|
|
|
|
|
|
|
|
|
mSingleStepDataSize = sizeof (UINT32);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
mSingleStepData = (*(UINT32 *)mSingleStepPC);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
*(UINT32 *)mSingleStepPC = GDB_ARM_BKPT;
|
|
|
|
|
if (*(UINT32 *)mSingleStepPC != GDB_ARM_BKPT) {
|
|
|
|
|
// For some reason our breakpoint did not take
|
|
|
|
|
mSingleStepActive = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
//DEBUG((EFI_D_ERROR, "AddSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, mSingleStepData, *(UINT32 *)mSingleStepPC));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2009-12-06 02:57:05 +01:00
|
|
|
|
Remove Single Step in the SystemContext
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
ARM Packages: Replace tabs by spaces for indentation
Replace tabs by spaces for indentation to comply to EDK2 coding standards.
Done in files with extension ".S", ".c", ".h", ".asm", ".dsc", ".inc", "*.inf",
"*.dec" or ".fdf" and located in ArmPkg, ArmPlatformPkg, EmbeddedPkg,
BeagleBoardPkg or Omap35xxPkg.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15901 6f19259b-4bc3-4df7-8a09-765794883524
2014-08-26 12:14:17 +02:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
2009-12-06 02:57:05 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
RemoveSingleStep (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if (!mSingleStepActive) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if (mSingleStepDataSize == sizeof (UINT16)) {
|
|
|
|
|
*(UINT16 *)mSingleStepPC = (UINT16)mSingleStepData;
|
|
|
|
|
} else {
|
|
|
|
|
//DEBUG((EFI_D_ERROR, "RemoveSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, *(UINT32 *)mSingleStepPC, mSingleStepData));
|
|
|
|
|
*(UINT32 *)mSingleStepPC = mSingleStepData;
|
|
|
|
|
}
|
2013-03-12 01:45:29 +01:00
|
|
|
|
InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
mSingleStepActive = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-23 00:53:54 +02:00
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Continue. addr is Address to resume. If addr is omitted, resume at current
|
2009-12-06 02:57:05 +01:00
|
|
|
|
Address.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
@param SystemContext Register content at time of the exception
|
2009-12-06 02:57:05 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
ContinueAtAddress (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if (PacketData[1] != '\0') {
|
2013-03-12 01:45:29 +01:00
|
|
|
|
SystemContext.SystemContextArm->PC = AsciiStrHexToUintn (&PacketData[1]);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
}
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** ‘s [addr ]’
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Single step. addr is the Address at which to resume. If addr is omitted, resume
|
2009-12-06 02:57:05 +01:00
|
|
|
|
at same Address.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
@param SystemContext Register content at time of the exception
|
2009-12-06 02:57:05 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
SingleStep (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
)
|
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
|
SendNotSupported ();
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
|
GetBreakpointDataAddress (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN BreakpointNumber
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
|
GetBreakpointDetected (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BREAK_TYPE
|
|
|
|
|
GetBreakpointType (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN BreakpointNumber
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return NotSupported;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ARM_SOFTWARE_BREAKPOINT *
|
|
|
|
|
SearchBreakpointList (
|
|
|
|
|
IN UINT32 Address
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
LIST_ENTRY *Current;
|
|
|
|
|
ARM_SOFTWARE_BREAKPOINT *Breakpoint;
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Current = GetFirstNode (&BreakpointList);
|
|
|
|
|
while (!IsNull (&BreakpointList, Current)) {
|
2009-12-06 02:57:05 +01:00
|
|
|
|
Breakpoint = ARM_SOFTWARE_BREAKPOINT_FROM_LINK(Current);
|
|
|
|
|
|
|
|
|
|
if (Address == Breakpoint->Address) {
|
|
|
|
|
return Breakpoint;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Current = GetNextNode (&BreakpointList, Current);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
SetBreakpoint (
|
|
|
|
|
IN UINT32 Address
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
ARM_SOFTWARE_BREAKPOINT *Breakpoint;
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Breakpoint = SearchBreakpointList (Address);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
if (Breakpoint != NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create and fill breakpoint structure
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Breakpoint = AllocatePool (sizeof(ARM_SOFTWARE_BREAKPOINT));
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
Breakpoint->Signature = ARM_SOFTWARE_BREAKPOINT_SIGNATURE;
|
|
|
|
|
Breakpoint->Address = Address;
|
|
|
|
|
Breakpoint->Instruction = *(UINT32 *)Address;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
// Add it to the list
|
2013-03-12 01:45:29 +01:00
|
|
|
|
InsertTailList (&BreakpointList, &Breakpoint->Link);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
// Insert the software breakpoint
|
|
|
|
|
*(UINT32 *)Address = GDB_ARM_BKPT;
|
2013-03-12 01:45:29 +01:00
|
|
|
|
InvalidateInstructionCacheRange ((VOID *)Address, 4);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
//DEBUG((EFI_D_ERROR, "SetBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, Breakpoint->Instruction, *(UINT32 *)Address));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
ClearBreakpoint (
|
|
|
|
|
IN UINT32 Address
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
ARM_SOFTWARE_BREAKPOINT *Breakpoint;
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
Breakpoint = SearchBreakpointList (Address);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
if (Breakpoint == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add it to the list
|
2013-03-12 01:45:29 +01:00
|
|
|
|
RemoveEntryList (&Breakpoint->Link);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
// Restore the original instruction
|
|
|
|
|
*(UINT32 *)Address = Breakpoint->Instruction;
|
2013-03-12 01:45:29 +01:00
|
|
|
|
InvalidateInstructionCacheRange ((VOID *)Address, 4);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
//DEBUG((EFI_D_ERROR, "ClearBreakpoint at 0x%08x (was: 0x%08x is:0x%08x)\n", Address, GDB_ARM_BKPT, *(UINT32 *)Address));
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
FreePool (Breakpoint);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
InsertBreakPoint (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN Type;
|
|
|
|
|
UINTN Address;
|
|
|
|
|
UINTN Length;
|
|
|
|
|
UINTN ErrorCode;
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
if (ErrorCode > 0) {
|
|
|
|
|
SendError ((UINT8)ErrorCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (Type) {
|
|
|
|
|
case 0: //Software breakpoint
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default :
|
|
|
|
|
DEBUG((EFI_D_ERROR, "Insert breakpoint default: %x\n", Type));
|
|
|
|
|
SendError (GDB_EINVALIDBRKPOINTTYPE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
SetBreakpoint (Address);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
SendSuccess ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
RemoveBreakPoint (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINTN Type;
|
|
|
|
|
UINTN Address;
|
|
|
|
|
UINTN Length;
|
|
|
|
|
UINTN ErrorCode;
|
|
|
|
|
|
|
|
|
|
//Parse breakpoint packet data
|
|
|
|
|
ErrorCode = ParseBreakpointPacket (PacketData, &Type, &Address, &Length);
|
|
|
|
|
if (ErrorCode > 0) {
|
|
|
|
|
SendError ((UINT8)ErrorCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (Type) {
|
|
|
|
|
case 0: //Software breakpoint
|
|
|
|
|
break;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
default:
|
|
|
|
|
SendError (GDB_EINVALIDBRKPOINTTYPE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
|
ClearBreakpoint (Address);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
SendSuccess ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
InitializeProcessor (
|
|
|
|
|
VOID
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
// Initialize breakpoint list
|
2013-03-12 01:45:29 +01:00
|
|
|
|
InitializeListHead (&BreakpointList);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
|
ValidateAddress (
|
|
|
|
|
IN VOID *Address
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
if ((UINT32)Address < 0x80000000) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
|
ValidateException (
|
2014-08-19 15:29:52 +02:00
|
|
|
|
IN EFI_EXCEPTION_TYPE ExceptionType,
|
|
|
|
|
IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
2009-12-06 02:57:05 +01:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
UINT32 ExceptionAddress;
|
|
|
|
|
UINT32 Instruction;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
// Is it a debugger SWI?
|
|
|
|
|
ExceptionAddress = SystemContext.SystemContextArm->PC -= 4;
|
|
|
|
|
Instruction = *(UINT32 *)ExceptionAddress;
|
|
|
|
|
if (Instruction != GDB_ARM_BKPT) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special for SWI-based exception handling. SWI sets up the context
|
|
|
|
|
// to return to the instruction following the SWI instruction - NOT what we want
|
|
|
|
|
// for a debugger!
|
|
|
|
|
SystemContext.SystemContextArm->PC = ExceptionAddress;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|