+++ /dev/null
-/** @file\r
- Private include file for 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
-\r
-**/\r
-\r
-#ifndef __GCC_DEBUG_AGENT_INTERNAL__\r
-#define __GCC_DEBUG_AGENT_INTERNAL__\r
-\r
-#include <Uefi.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/GdbSerialLib.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/CacheMaintenanceLib.h>\r
-#include <Library/DebugAgentTimerLib.h>\r
-#include <Library/DebugAgentLib.h>\r
-\r
-#include <IndustryStandard/PeImage.h>\r
-#include <Protocol/DebugSupport.h>\r
-\r
-extern CONST CHAR8 mHexToStr[];\r
-\r
-// maximum size of input and output buffers\r
-// This value came from the show remote command of the gdb we tested against\r
-#define MAX_BUF_SIZE 2000\r
-\r
-// maximum size of address buffer\r
-#define MAX_ADDR_SIZE 32\r
-\r
-// maximum size of register number buffer\r
-#define MAX_REG_NUM_BUF_SIZE 32\r
-\r
-// maximum size of length buffer\r
-#define MAX_LENGTH_SIZE 32\r
-\r
-// maximum size of T signal members\r
-#define MAX_T_SIGNAL_SIZE 64\r
-\r
-// the mask used to clear all the cache\r
-#define TF_BIT 0x00000100\r
-\r
-\r
-//\r
-// GDB Signal definitions - generic names for interrupts\r
-//\r
-#define GDB_SIGINT 2 // Interrupt process via ctrl-c\r
-#define GDB_SIGILL 4 // Illegal instruction\r
-#define GDB_SIGTRAP 5 // Trace Trap (Breakpoint and SingleStep)\r
-#define GDB_SIGEMT 7 // Emulator Trap\r
-#define GDB_SIGFPE 8 // Floating point exception\r
-#define GDB_SIGSEGV 11 // Setgment violation, page fault\r
-\r
-\r
-//\r
-// GDB File I/O Error values, zero means no error\r
-// Includes all general GDB Unix like error values\r
-//\r
-#define GDB_EBADMEMADDRBUFSIZE 11 // the buffer that stores memory Address to be read from/written to is not the right size\r
-#define GDB_EBADMEMLENGBUFSIZE 12 // the buffer that stores Length is not the right size\r
-#define GDB_EBADMEMLENGTH 13 // Length, the given number of bytes to read or write, is not the right size\r
-#define GDB_EBADMEMDATA 14 // one of the bytes or nibbles of the memory is leess than 0\r
-#define GDB_EBADMEMDATASIZE 15 // the memory data, 'XX..', is too short or too long\r
-#define GDB_EBADBUFSIZE 21 // the buffer created is not the correct size\r
-#define GDB_EINVALIDARG 31 // argument is invalid\r
-#define GDB_ENOSPACE 41 //\r
-#define GDB_EINVALIDBRKPOINTTYPE 51 // the breakpoint type is not recognized\r
-#define GDB_EINVALIDREGNUM 61 // given register number is not valid: either <0 or >=Number of Registers\r
-#define GDB_EUNKNOWN 255 // unknown\r
-\r
-\r
-//\r
-// These devices are open by GDB so we can just read and write to them\r
-//\r
-#define GDB_STDIN 0x00\r
-#define GDB_STDOUT 0x01\r
-#define GDB_STDERR 0x02\r
-\r
-//\r
-//Define Register size for different architectures\r
-//\r
-#if defined (MDE_CPU_IA32)\r
-#define REG_SIZE 32\r
-#elif defined (MDE_CPU_X64)\r
-#define REG_SIZE 64\r
-#elif defined (MDE_CPU_ARM)\r
-#define REG_SIZE 32\r
-#endif\r
-\r
-\r
-typedef struct {\r
- EFI_EXCEPTION_TYPE Exception;\r
- UINT8 SignalNo;\r
-} EFI_EXCEPTION_TYPE_ENTRY;\r
-\r
-\r
-#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
-\r
-//\r
-// Byte packed structure for DR6\r
-// 32-bits on IA-32\r
-// 64-bits on X64. The upper 32-bits on X64 are reserved\r
-//\r
-typedef union {\r
- struct {\r
- UINT32 B0:1; // Breakpoint condition detected\r
- UINT32 B1:1; // Breakpoint condition detected\r
- UINT32 B2:1; // Breakpoint condition detected\r
- UINT32 B3:1; // Breakpoint condition detected\r
- UINT32 Reserved_1:9; // Reserved\r
- UINT32 BD:1; // Debug register access detected\r
- UINT32 BS:1; // Single step\r
- UINT32 BT:1; // Task switch\r
- UINT32 Reserved_2:16; // Reserved\r
- } Bits;\r
- UINTN UintN;\r
-} IA32_DR6;\r
-\r
-//\r
-// Byte packed structure for DR7\r
-// 32-bits on IA-32\r
-// 64-bits on X64. The upper 32-bits on X64 are reserved\r
-//\r
-typedef union {\r
- struct {\r
- UINT32 L0:1; // Local breakpoint enable\r
- UINT32 G0:1; // Global breakpoint enable\r
- UINT32 L1:1; // Local breakpoint enable\r
- UINT32 G1:1; // Global breakpoint enable\r
- UINT32 L2:1; // Local breakpoint enable\r
- UINT32 G2:1; // Global breakpoint enable\r
- UINT32 L3:1; // Local breakpoint enable\r
- UINT32 G3:1; // Global breakpoint enable\r
- UINT32 LE:1; // Local exact breakpoint enable\r
- UINT32 GE:1; // Global exact breakpoint enable\r
- UINT32 Reserved_1:3; // Reserved\r
- UINT32 GD:1; // Global detect enable\r
- UINT32 Reserved_2:2; // Reserved\r
- UINT32 RW0:2; // Read/Write field\r
- UINT32 LEN0:2; // Length field\r
- UINT32 RW1:2; // Read/Write field\r
- UINT32 LEN1:2; // Length field\r
- UINT32 RW2:2; // Read/Write field\r
- UINT32 LEN2:2; // Length field\r
- UINT32 RW3:2; // Read/Write field\r
- UINT32 LEN3:2; // Length field\r
- } Bits;\r
- UINTN UintN;\r
-} IA32_DR7;\r
-\r
-#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */\r
-\r
-typedef enum {\r
- InstructionExecution, //Hardware breakpoint\r
- DataWrite, //watch\r
- DataRead, //rwatch\r
- DataReadWrite, //awatch\r
- SoftwareBreakpoint, //Software breakpoint\r
- NotSupported\r
-} BREAK_TYPE;\r
-\r
-//\r
-// Array of exception types that need to be hooked by the debugger\r
-//\r
-extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];\r
-\r
-//\r
-// If the periodic callback is called while we are processing an F packet we need\r
-// to let the callback know to not read from the serail stream as it could steal\r
-// characters from the F reponse packet\r
-//\r
-extern BOOLEAN gProcessingFPacket;\r
-\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
-UINTN\r
-MaxEfiException (\r
- VOID\r
- );\r
-\r
-\r
-/**\r
- Check to see if the ISA is supported.\r
- ISA = Instruction Set Architecture\r
-\r
- @retval TRUE if Isa is supported,\r
- FALSE otherwise.\r
- **/\r
-BOOLEAN\r
-CheckIsa (\r
- IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa\r
- );\r
-\r
-\r
-/**\r
- Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints\r
-\r
- @param SystemContext Register content at time of the exception\r
- @param GdbExceptionType GDB exception type\r
- **/\r
-\r
-VOID\r
-GdbSendTSignal (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINT8 GdbExceptionType\r
- );\r
-\r
-\r
-/**\r
- Translates the EFI mapping to GDB mapping\r
-\r
- @param EFIExceptionType EFI Exception that is being processed\r
- @retval UINTN that corresponds to EFIExceptionType's GDB exception type number\r
- **/\r
-UINT8\r
-ConvertEFItoGDBtype (\r
- IN EFI_EXCEPTION_TYPE EFIExceptionType\r
- );\r
-\r
-\r
-/**\r
- Empties the given buffer\r
- @param *Buf pointer to the first element in buffer to be emptied\r
- **/\r
-VOID\r
-EmptyBuffer (\r
- IN CHAR8 *Buf\r
- );\r
-\r
-\r
-/**\r
- Converts an 8-bit Hex Char into a INTN.\r
-\r
- @param Char - the hex character to be converted into UINTN\r
- @retval a INTN, from 0 to 15, that corressponds to Char\r
- -1 if Char is not a hex character\r
- **/\r
-INTN\r
-HexCharToInt (\r
- IN CHAR8 Char\r
- );\r
-\r
-\r
-/** 'E NN'\r
- Send an error with the given error number after converting to hex.\r
- The error number is put into the buffer in hex. '255' is the biggest errno we can send.\r
- ex: 162 will be sent as A2.\r
-\r
- @param errno the error number that will be sent\r
- **/\r
-VOID\r
-EFIAPI\r
-SendError (\r
- IN UINT8 ErrorNum\r
- );\r
-\r
-\r
-/**\r
- Send 'OK' when the function is done executing successfully.\r
- **/\r
-VOID\r
-SendSuccess (\r
- VOID\r
- );\r
-\r
-\r
-/**\r
- Send empty packet to specify that particular command/functionality is not supported.\r
- **/\r
-VOID\r
-SendNotSupported (\r
- VOID\r
- );\r
-\r
-/** ‘p n’\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 This is the input buffer received from gdb server\r
- **/\r
-VOID\r
-ReadNthRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN CHAR8 *InBuffer\r
- );\r
-\r
-\r
-/** ‘g’\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
-ReadGeneralRegisters (\r
- IN EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-\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 This is the input buffer received from gdb server\r
- **/\r
-VOID\r
-WriteNthRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN CHAR8 *InBuffer\r
- );\r
-\r
-\r
-/** ‘G XX...’\r
- Writes the new values received into the input buffer to the general registers\r
- @param SystemContext Register content at time of the exception\r
- @param InBuffer Pointer to the input buffer received from gdb server\r
- **/\r
-\r
-VOID\r
-WriteGeneralRegisters (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN CHAR8 *InBuffer\r
- );\r
-\r
-\r
-/** ‘m addr,length ’\r
- Find the Length of the area to read and the start addres. Finally, pass them to\r
- another function, TransferFromMemToOutBufAndSend, that will read from that memory space and\r
- send it as a packet.\r
-\r
- @param *PacketData Pointer to Payload data for the packet\r
- **/\r
-VOID\r
-ReadFromMemory (\r
- IN CHAR8 *PacketData\r
- );\r
-\r
-\r
-/** ‘M addr,length :XX...’\r
- Find the Length of the area in bytes to write and the start addres. Finally, pass them to\r
- another function, TransferFromInBufToMem, that will write to that memory space the info in\r
- the input buffer.\r
-\r
- @param PacketData Pointer to Payload data for the packet\r
- **/\r
-VOID\r
-WriteToMemory (\r
- IN CHAR8 *PacketData\r
- );\r
-\r
-\r
-/** ‘c [addr ]’\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
- @param *PacketData Pointer to PacketData\r
- **/\r
-\r
-VOID\r
-ContinueAtAddress (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN CHAR8 *PacketData\r
- );\r
-\r
-\r
-/** ‘s [addr ]’\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
- @param PacketData Pointer to Payload data for the packet\r
- **/\r
-VOID\r
-SingleStep (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN CHAR8 *PacketData\r
- );\r
-\r
-/**\r
- Insert Single Step in the SystemContext\r
-\r
- @param SystemContext Register content at time of the exception\r
- **/\r
-VOID\r
-AddSingleStep (\r
- IN EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-/**\r
- Remove Single Step in the SystemContext\r
-\r
- @param SystemContext Register content at time of the exception\r
- **/\r
-VOID\r
-RemoveSingleStep (\r
- IN EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-\r
-/**\r
- ‘Z1, [addr], [length]’\r
- ‘Z2, [addr], [length]’\r
- ‘Z3, [addr], [length]’\r
- ‘Z4, [addr], [length]’\r
-\r
- Insert hardware breakpoint/watchpoint at address addr of size length\r
-\r
- @param SystemContext Register content at time of the exception\r
- @param *PacketData Pointer to the Payload data for the packet\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-InsertBreakPoint(\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN CHAR8 *PacketData\r
- );\r
-\r
-\r
-/**\r
- ‘z1, [addr], [length]’\r
- ‘z2, [addr], [length]’\r
- ‘z3, [addr], [length]’\r
- ‘z4, [addr], [length]’\r
-\r
- Remove hardware breakpoint/watchpoint at address addr of size length\r
-\r
- @param SystemContext Register content at time of the exception\r
- @param *PacketData Pointer to the Payload data for the packet\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-RemoveBreakPoint(\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN CHAR8 *PacketData\r
- );\r
-\r
-\r
-/**\r
- Exception Hanldler for GDB. It will be called for all exceptions\r
- registered via the gExceptionType[] array.\r
-\r
- @param ExceptionType Exception that is being processed\r
- @param SystemContext Register content at time of the exception\r
-\r
- **/\r
-VOID\r
-EFIAPI\r
-GdbExceptionHandler (\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-\r
-/**\r
- Periodic callback for GDB. This function is used to catch a ctrl-c or other\r
- break in type command from GDB.\r
-\r
- @param SystemContext Register content at time of the call\r
-\r
- **/\r
-VOID\r
-EFIAPI\r
-GdbPeriodicCallBack (\r
- IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-\r
-/**\r
- Make two serail consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.\r
-\r
- These console show up on the remote system running GDB\r
-\r
-**/\r
-\r
-VOID\r
-GdbInitializeSerialConsole (\r
- VOID\r
- );\r
-\r
-\r
-/**\r
- Send a GDB Remote Serial Protocol Packet\r
-\r
- $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',\r
- the packet teminating character '#' and the two digit checksum.\r
-\r
- If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up\r
- in an infinit loop. This is so if you unplug the debugger code just keeps running\r
-\r
- @param PacketData Payload data for the packet\r
-\r
- @retval Number of bytes of packet data sent.\r
-\r
-**/\r
-UINTN\r
-SendPacket (\r
- IN CHAR8 *PacketData\r
- );\r
-\r
-\r
-/**\r
- Receive a GDB Remote Serial Protocol Packet\r
-\r
- $PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',\r
- the packet teminating character '#' and the two digit checksum.\r
-\r
- If host re-starts sending a packet without ending the previous packet, only the last valid packet is processed.\r
- (In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)\r
-\r
- If an ack '+' is not sent resend the packet\r
-\r
- @param PacketData Payload data for the packet\r
-\r
- @retval Number of bytes of packet data received.\r
-\r
- **/\r
-UINTN\r
-ReceivePacket (\r
- OUT CHAR8 *PacketData,\r
- IN UINTN PacketDataSize\r
- );\r
-\r
-\r
-/**\r
- Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates\r
- the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.\r
-\r
- @param FileDescriptor Device to talk to.\r
- @param Buffer Buffer to hold Count bytes that were read\r
- @param Count Number of bytes to transfer.\r
-\r
- @retval -1 Error\r
- @retval {other} Number of bytes read.\r
-\r
-**/\r
-INTN\r
-GdbRead (\r
- IN INTN FileDescriptor,\r
- OUT VOID *Buffer,\r
- IN UINTN Count\r
- );\r
-\r
-\r
-/**\r
- Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates\r
- nothing was written. On error -1 is returned.\r
-\r
- @param FileDescriptor Device to talk to.\r
- @param Buffer Buffer to hold Count bytes that are to be written\r
- @param Count Number of bytes to transfer.\r
-\r
- @retval -1 Error\r
- @retval {other} Number of bytes written.\r
-\r
-**/\r
-INTN\r
-GdbWrite (\r
- IN INTN FileDescriptor,\r
- OUT CONST VOID *Buffer,\r
- IN UINTN Count\r
- );\r
-\r
-UINTN *\r
-FindPointerToRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN RegNumber\r
- );\r
-\r
-CHAR8 *\r
-BasicReadRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN RegNumber,\r
- IN CHAR8 *OutBufPtr\r
- );\r
-\r
-VOID\r
-TransferFromInBufToMem (\r
- IN UINTN Length,\r
- IN UINT8 *Address,\r
- IN CHAR8 *NewData\r
- );\r
-\r
-VOID\r
-TransferFromMemToOutBufAndSend (\r
- IN UINTN Length,\r
- IN UINT8 *Address\r
- );\r
-\r
-CHAR8 *\r
-BasicWriteRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN RegNumber,\r
- IN CHAR8 *InBufPtr\r
- );\r
-\r
-VOID\r
-PrintReg (\r
- EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-UINTN\r
-ParseBreakpointPacket (\r
- IN CHAR8 *PacketData,\r
- OUT UINTN *Type,\r
- OUT UINTN *Address,\r
- OUT UINTN *Length\r
- );\r
-\r
-UINTN\r
-GetBreakpointDataAddress (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN BreakpointNumber\r
- );\r
-\r
-UINTN\r
-GetBreakpointDetected (\r
- IN EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-BREAK_TYPE\r
-GetBreakpointType (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN BreakpointNumber\r
- );\r
-\r
-UINTN\r
-ConvertLengthData (\r
- IN UINTN Length\r
- );\r
-\r
-EFI_STATUS\r
-FindNextFreeDebugRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- OUT UINTN *Register\r
- );\r
-\r
-EFI_STATUS\r
-EnableDebugRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN Register,\r
- IN UINTN Address,\r
- IN UINTN Length,\r
- IN UINTN Type\r
- );\r
-\r
-EFI_STATUS\r
-FindMatchingDebugRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN Address,\r
- IN UINTN Length,\r
- IN UINTN Type,\r
- OUT UINTN *Register\r
- );\r
-\r
-EFI_STATUS\r
-DisableDebugRegister (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINTN Register\r
- );\r
-\r
-VOID\r
-InitializeProcessor (\r
- VOID\r
- );\r
-\r
-/**\r
- Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints\r
-\r
- @param SystemContext Register content at time of the exception\r
- @param GdbExceptionType GDB exception type\r
- **/\r
-VOID\r
-ProcessorSendTSignal (\r
- IN EFI_SYSTEM_CONTEXT SystemContext,\r
- IN UINT8 GdbExceptionType,\r
- IN OUT CHAR8 *TSignalPtr,\r
- IN UINTN SizeOfBuffer\r
- );\r
-\r
-/**\r
- Check to see if this exception is related to ctrl-c handling.\r
-\r
- @param ExceptionType Exception that is being processed\r
- @param SystemContext Register content at time of the exception\r
-\r
- @return TRUE This was a ctrl-c check that did not find a ctrl-c\r
- @return FALSE This was not a ctrl-c check or some one hit ctrl-c\r
- **/\r
-BOOLEAN\r
-ProcessorControlC (\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
- );\r
-\r
-\r
-/**\r
- Initialize debug agent.\r
-\r
- This function is used to set up debug enviroment. It may enable interrupts.\r
-\r
- @param[in] InitFlag Init flag is used to decide initialize process.\r
- @param[in] Context Context needed according to InitFlag, it was optional.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-DebugAgentHookExceptions (\r
- IN UINT32 InitFlag,\r
- IN VOID *Context OPTIONAL\r
- );\r
-\r
-\r
-#endif\r