2013-01-25 12:28:06 +01:00
|
|
|
|
/** @file
|
|
|
|
|
Private include file for GDB stub
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
|
|
|
|
|
2019-04-04 01:03:38 +02:00
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#ifndef __GDB_STUB_INTERNAL__
|
|
|
|
|
#define __GDB_STUB_INTERNAL__
|
|
|
|
|
|
|
|
|
|
#include <Uefi.h>
|
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
|
#include <Library/UefiLib.h>
|
|
|
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
|
#include <Library/GdbSerialLib.h>
|
|
|
|
|
#include <Library/PrintLib.h>
|
|
|
|
|
|
|
|
|
|
#include <Protocol/DebugSupport.h>
|
|
|
|
|
#include <Protocol/SerialIo.h>
|
|
|
|
|
#include <Protocol/LoadedImage.h>
|
|
|
|
|
#include <Protocol/LoadedImage.h>
|
|
|
|
|
#include <Guid/DebugImageInfoTable.h>
|
|
|
|
|
#include <IndustryStandard/PeImage.h>
|
|
|
|
|
|
2021-12-05 23:53:56 +01:00
|
|
|
|
extern CONST CHAR8 mHexToStr[];
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
// maximum size of input and output buffers
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// This value came from the show remote command of the gdb we tested against
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define MAX_BUF_SIZE 2000
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
// maximum size of address buffer
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define MAX_ADDR_SIZE 32
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
// maximum size of register number buffer
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define MAX_REG_NUM_BUF_SIZE 32
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
// maximum size of length buffer
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define MAX_LENGTH_SIZE 32
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
// maximum size of T signal members
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define MAX_T_SIGNAL_SIZE 64
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
// the mask used to clear all the cache
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define TF_BIT 0x00000100
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GDB Signal definitions - generic names for interrupts
|
|
|
|
|
//
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#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
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GDB File I/O Error values, zero means no error
|
|
|
|
|
// Includes all general GDB Unix like error values
|
|
|
|
|
//
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#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
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// These devices are open by GDB so we can just read and write to them
|
|
|
|
|
//
|
|
|
|
|
#define GDB_STDIN 0x00
|
|
|
|
|
#define GDB_STDOUT 0x01
|
|
|
|
|
#define GDB_STDERR 0x02
|
|
|
|
|
|
|
|
|
|
//
|
2021-12-05 23:53:56 +01:00
|
|
|
|
// Define Register size for different architectures
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
2014-08-19 15:29:52 +02:00
|
|
|
|
#if defined (MDE_CPU_IA32)
|
2013-01-25 12:28:06 +01:00
|
|
|
|
#define REG_SIZE 32
|
|
|
|
|
#elif defined (MDE_CPU_X64)
|
|
|
|
|
#define REG_SIZE 64
|
|
|
|
|
#elif defined (MDE_CPU_ARM)
|
|
|
|
|
#define REG_SIZE 32
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define GDB_SERIAL_DEV_SIGNATURE SIGNATURE_32 ('g', 'd', 'b', 's')
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
typedef struct {
|
2021-12-05 23:53:56 +01:00
|
|
|
|
VENDOR_DEVICE_PATH VendorDevice;
|
|
|
|
|
UINT32 Index; // Support more than one
|
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL End;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
} GDB_SERIAL_DEVICE_PATH;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Name: SERIAL_DEV
|
|
|
|
|
// Purpose: To provide device specific information
|
|
|
|
|
// Fields:
|
|
|
|
|
// Signature UINTN: The identity of the serial device
|
|
|
|
|
// SerialIo SERIAL_IO_PROTOCOL: Serial I/O protocol interface
|
|
|
|
|
// SerialMode SERIAL_IO_MODE:
|
|
|
|
|
// DevicePath EFI_DEVICE_PATH_PROTOCOL *: Device path of the serial device
|
|
|
|
|
//
|
|
|
|
|
typedef struct {
|
2021-12-05 23:53:56 +01:00
|
|
|
|
UINTN Signature;
|
|
|
|
|
EFI_HANDLE Handle;
|
|
|
|
|
EFI_SERIAL_IO_PROTOCOL SerialIo;
|
|
|
|
|
EFI_SERIAL_IO_MODE SerialMode;
|
|
|
|
|
GDB_SERIAL_DEVICE_PATH DevicePath;
|
|
|
|
|
INTN InFileDescriptor;
|
|
|
|
|
INTN OutFileDescriptor;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
} GDB_SERIAL_DEV;
|
|
|
|
|
|
2021-12-05 23:53:56 +01:00
|
|
|
|
#define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
typedef struct {
|
2021-12-05 23:53:56 +01:00
|
|
|
|
EFI_EXCEPTION_TYPE Exception;
|
|
|
|
|
UINT8 SignalNo;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
} EFI_EXCEPTION_TYPE_ENTRY;
|
|
|
|
|
|
|
|
|
|
#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Byte packed structure for DR6
|
|
|
|
|
// 32-bits on IA-32
|
|
|
|
|
// 64-bits on X64. The upper 32-bits on X64 are reserved
|
|
|
|
|
//
|
|
|
|
|
typedef union {
|
|
|
|
|
struct {
|
2021-12-05 23:53:56 +01:00
|
|
|
|
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
|
2013-01-25 12:28:06 +01:00
|
|
|
|
} Bits;
|
2021-12-05 23:53:56 +01:00
|
|
|
|
UINTN UintN;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
} IA32_DR6;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Byte packed structure for DR7
|
|
|
|
|
// 32-bits on IA-32
|
|
|
|
|
// 64-bits on X64. The upper 32-bits on X64 are reserved
|
|
|
|
|
//
|
|
|
|
|
typedef union {
|
|
|
|
|
struct {
|
2021-12-05 23:53:56 +01:00
|
|
|
|
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
|
2013-01-25 12:28:06 +01:00
|
|
|
|
} Bits;
|
2021-12-05 23:53:56 +01:00
|
|
|
|
UINTN UintN;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
} IA32_DR7;
|
|
|
|
|
|
|
|
|
|
#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
2021-12-05 23:53:56 +01:00
|
|
|
|
InstructionExecution, // Hardware breakpoint
|
|
|
|
|
DataWrite, // watch
|
|
|
|
|
DataRead, // rwatch
|
|
|
|
|
DataReadWrite, // awatch
|
|
|
|
|
SoftwareBreakpoint, // Software breakpoint
|
2013-01-25 12:28:06 +01:00
|
|
|
|
NotSupported
|
|
|
|
|
} BREAK_TYPE;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Array of exception types that need to be hooked by the debugger
|
|
|
|
|
//
|
2021-12-05 23:53:56 +01:00
|
|
|
|
extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c
|
2014-08-19 15:29:52 +02:00
|
|
|
|
// here we need to wait for the periodic callback to do this.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
2021-12-05 23:53:56 +01:00
|
|
|
|
extern BOOLEAN gCtrlCBreakFlag;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// If the periodic callback is called while we are processing an F packet we need
|
2019-07-03 15:25:30 +02:00
|
|
|
|
// to let the callback know to not read from the serial stream as it could steal
|
|
|
|
|
// characters from the F response packet
|
2013-01-25 12:28:06 +01:00
|
|
|
|
//
|
2021-12-05 23:53:56 +01:00
|
|
|
|
extern BOOLEAN gProcessingFPacket;
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
// The offsets of registers SystemContext.
|
|
|
|
|
// The fields in the array are in the gdb ordering.
|
|
|
|
|
//
|
2021-12-05 23:53:56 +01:00
|
|
|
|
extern UINTN gRegisterOffsets[];
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
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.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
MaxEfiException (
|
|
|
|
|
VOID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
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.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
MaxRegisterCount (
|
|
|
|
|
VOID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Check to see if the ISA is supported.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
ISA = Instruction Set Architecture
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@retval TRUE if Isa is supported,
|
|
|
|
|
FALSE otherwise.
|
|
|
|
|
**/
|
|
|
|
|
BOOLEAN
|
|
|
|
|
CheckIsa (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
@param GdbExceptionType GDB exception type
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
GdbSendTSignal (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
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
|
|
|
|
IN UINT8 GdbExceptionType
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Translates the EFI mapping to GDB mapping
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param EFIExceptionType EFI Exception that is being processed
|
|
|
|
|
@retval UINTN that corresponds to EFIExceptionType's GDB exception type number
|
|
|
|
|
**/
|
|
|
|
|
UINT8
|
2014-08-19 15:29:52 +02:00
|
|
|
|
ConvertEFItoGDBtype (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_EXCEPTION_TYPE EFIExceptionType
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Empties the given buffer
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param *Buf pointer to the first element in buffer to be emptied
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2014-08-19 15:29:52 +02:00
|
|
|
|
EmptyBuffer (
|
2013-01-25 12:28:06 +01:00
|
|
|
|
IN CHAR8 *Buf
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Converts an 8-bit Hex Char into a INTN.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param Char - the hex character to be converted into UINTN
|
2019-07-03 15:25:30 +02:00
|
|
|
|
@retval a INTN, from 0 to 15, that corresponds to Char
|
2013-01-25 12:28:06 +01:00
|
|
|
|
-1 if Char is not a hex character
|
|
|
|
|
**/
|
|
|
|
|
INTN
|
|
|
|
|
HexCharToInt (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN CHAR8 Char
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** '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.
|
|
|
|
|
ex: 162 will be sent as A2.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param errno the error number that will be sent
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
|
|
|
|
SendError (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN UINT8 ErrorNum
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send 'OK' when the function is done executing successfully.
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SendSuccess (
|
|
|
|
|
VOID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send empty packet to specify that particular command/functionality is not supported.
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SendNotSupported (
|
|
|
|
|
VOID
|
|
|
|
|
);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
/** ‘p n’
|
|
|
|
|
Reads the n-th register's value into an output buffer and sends it as a packet
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
@param InBuffer This is the input buffer received from gdb server
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
ReadNthRegister (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *InBuffer
|
|
|
|
|
);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
/** ‘g’
|
|
|
|
|
Reads the general registers into an output buffer and sends it as a packet
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2014-08-19 15:29:52 +02:00
|
|
|
|
ReadGeneralRegisters (
|
2013-01-25 12:28:06 +01:00
|
|
|
|
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
|
|
|
|
|
@param InBuffer This is the input buffer received from gdb server
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
WriteNthRegister (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
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
|
|
|
|
|
@param InBuffer Pointer to the input buffer received from gdb server
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
WriteGeneralRegisters (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *InBuffer
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** ‘m addr,length ’
|
2019-07-03 15:25:30 +02:00
|
|
|
|
Find the Length of the area to read and the start address. Finally, pass them to
|
2014-08-19 15:29:52 +02:00
|
|
|
|
another function, TransferFromMemToOutBufAndSend, that will read from that memory space and
|
2013-01-25 12:28:06 +01:00
|
|
|
|
send it as a packet.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param *PacketData Pointer to Payload data for the packet
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
ReadFromMemory (
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/** ‘M addr,length :XX...’
|
2019-07-03 15:25:30 +02:00
|
|
|
|
Find the Length of the area in bytes to write and the start address. Finally, pass them to
|
2013-01-25 12:28:06 +01:00
|
|
|
|
another function, TransferFromInBufToMem, that will write to that memory space the info in
|
|
|
|
|
the input buffer.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param PacketData Pointer to Payload data for the packet
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
WriteToMemory (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN CHAR8 *PacketData
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
/** ‘c [addr ]’
|
|
|
|
|
Continue. addr is Address to resume. If addr is omitted, resume at current
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Address.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
@param SystemContext Register content at time of the exception
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param *PacketData Pointer to PacketData
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
ContinueAtAddress (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
2013-01-25 12:28:06 +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
|
2013-01-25 12:28:06 +01:00
|
|
|
|
at same Address.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
@param PacketData Pointer to Payload data for the packet
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
2019-09-17 13:05:09 +02:00
|
|
|
|
EFIAPI
|
2013-01-25 12:28:06 +01:00
|
|
|
|
SingleStep (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
/**
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Insert Single Step in the SystemContext
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
AddSingleStep (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
|
);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2013-01-25 12:28:06 +01:00
|
|
|
|
Remove Single Step in the SystemContext
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
RemoveSingleStep (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
|
);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
/**
|
|
|
|
|
‘Z1, [addr], [length]’
|
|
|
|
|
‘Z2, [addr], [length]’
|
|
|
|
|
‘Z3, [addr], [length]’
|
|
|
|
|
‘Z4, [addr], [length]’
|
|
|
|
|
|
|
|
|
|
Insert hardware breakpoint/watchpoint at address addr of size length
|
|
|
|
|
|
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
@param *PacketData Pointer to the Payload data for the packet
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2021-12-05 23:53:56 +01:00
|
|
|
|
InsertBreakPoint (
|
2013-01-25 12:28:06 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
‘z1, [addr], [length]’
|
|
|
|
|
‘z2, [addr], [length]’
|
|
|
|
|
‘z3, [addr], [length]’
|
|
|
|
|
‘z4, [addr], [length]’
|
|
|
|
|
|
|
|
|
|
Remove hardware breakpoint/watchpoint at address addr of size length
|
|
|
|
|
|
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
@param *PacketData Pointer to the Payload data for the packet
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2021-12-05 23:53:56 +01:00
|
|
|
|
RemoveBreakPoint (
|
2013-01-25 12:28:06 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN CHAR8 *PacketData
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-03 15:25:30 +02:00
|
|
|
|
Exception Handler for GDB. It will be called for all exceptions
|
2013-01-25 12:28:06 +01:00
|
|
|
|
registered via the gExceptionType[] array.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param ExceptionType Exception that is being processed
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param SystemContext Register content at time of the exception
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2014-08-19 15:29:52 +02:00
|
|
|
|
GdbExceptionHandler (
|
|
|
|
|
IN EFI_EXCEPTION_TYPE ExceptionType,
|
|
|
|
|
IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Periodic callback for GDB. This function is used to catch a ctrl-c or other
|
2013-01-25 12:28:06 +01:00
|
|
|
|
break in type command from GDB.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@param SystemContext Register content at time of the call
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
**/
|
|
|
|
|
VOID
|
|
|
|
|
EFIAPI
|
2014-08-19 15:29:52 +02:00
|
|
|
|
GdbPeriodicCallBack (
|
|
|
|
|
IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-03 15:25:30 +02:00
|
|
|
|
Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
These console show up on the remote system running GDB
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
GdbInitializeSerialConsole (
|
|
|
|
|
VOID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Send a GDB Remote Serial Protocol Packet
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
$PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',
|
2019-07-03 15:25:30 +02:00
|
|
|
|
the packet terminating character '#' and the two digit checksum.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
If an ack '+' is not sent resend the packet, but timeout eventually so we don't end up
|
2019-07-03 15:25:30 +02:00
|
|
|
|
in an infinite loop. This is so if you unplug the debugger code just keeps running
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param PacketData Payload data for the packet
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@retval Number of bytes of packet data sent.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
SendPacket (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN CHAR8 *PacketData
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
/**
|
|
|
|
|
Receive a GDB Remote Serial Protocol Packet
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
$PacketData#checksum PacketData is passed in and this function adds the packet prefix '$',
|
2019-07-03 15:25:30 +02:00
|
|
|
|
the packet terminating character '#' and the two digit checksum.
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2016-10-19 09:01:14 +02:00
|
|
|
|
If host re-starts sending a packet without ending the previous packet, only the last valid packet is processed.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
(In other words, if received packet is '$12345$12345$123456#checksum', only '$123456#checksum' will be processed.)
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
If an ack '+' is not sent resend the packet
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
|
@param PacketData Payload data for the packet
|
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
@retval Number of bytes of packet data received.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
UINTN
|
|
|
|
|
ReceivePacket (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
OUT CHAR8 *PacketData,
|
|
|
|
|
IN UINTN PacketDataSize
|
|
|
|
|
);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates
|
2013-01-25 12:28:06 +01:00
|
|
|
|
the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.
|
|
|
|
|
|
|
|
|
|
@param FileDescriptor Device to talk to.
|
|
|
|
|
@param Buffer Buffer to hold Count bytes that were read
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param Count Number of bytes to transfer.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
@retval -1 Error
|
|
|
|
|
@retval {other} Number of bytes read.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
INTN
|
|
|
|
|
GdbRead (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN INTN FileDescriptor,
|
|
|
|
|
OUT VOID *Buffer,
|
|
|
|
|
IN UINTN Count
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
2013-01-25 12:28:06 +01:00
|
|
|
|
/**
|
2014-08-19 15:29:52 +02:00
|
|
|
|
Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates
|
|
|
|
|
nothing was written. On error -1 is returned.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
@param FileDescriptor Device to talk to.
|
|
|
|
|
@param Buffer Buffer to hold Count bytes that are to be written
|
2014-08-19 15:29:52 +02:00
|
|
|
|
@param Count Number of bytes to transfer.
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
@retval -1 Error
|
|
|
|
|
@retval {other} Number of bytes written.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
INTN
|
|
|
|
|
GdbWrite (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN INTN FileDescriptor,
|
|
|
|
|
OUT CONST VOID *Buffer,
|
|
|
|
|
IN UINTN Count
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
UINTN *
|
2013-01-25 12:28:06 +01:00
|
|
|
|
FindPointerToRegister (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN RegNumber
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
CHAR8 *
|
2013-01-25 12:28:06 +01:00
|
|
|
|
BasicReadRegister (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN RegNumber,
|
|
|
|
|
IN CHAR8 *OutBufPtr
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
TransferFromInBufToMem (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN UINTN Length,
|
|
|
|
|
IN UINT8 *Address,
|
|
|
|
|
IN CHAR8 *NewData
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
TransferFromMemToOutBufAndSend (
|
|
|
|
|
IN UINTN Length,
|
|
|
|
|
IN UINT8 *Address
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CHAR8 *
|
|
|
|
|
BasicWriteRegister (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN RegNumber,
|
|
|
|
|
IN CHAR8 *InBufPtr
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
2014-08-19 15:29:52 +02:00
|
|
|
|
VOID
|
2013-01-25 12:28:06 +01:00
|
|
|
|
PrintReg (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
EFI_SYSTEM_CONTEXT SystemContext
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
|
ParseBreakpointPacket (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN CHAR8 *PacketData,
|
|
|
|
|
OUT UINTN *Type,
|
|
|
|
|
OUT UINTN *Address,
|
|
|
|
|
OUT UINTN *Length
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
|
GetBreakpointDataAddress (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
2014-08-19 15:29:52 +02:00
|
|
|
|
IN UINTN BreakpointNumber
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
|
GetBreakpointDetected (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
BREAK_TYPE
|
|
|
|
|
GetBreakpointType (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
2014-08-19 15:29:52 +02:00
|
|
|
|
IN UINTN BreakpointNumber
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
UINTN
|
|
|
|
|
ConvertLengthData (
|
|
|
|
|
IN UINTN Length
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
|
FindNextFreeDebugRegister (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
OUT UINTN *Register
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
|
EnableDebugRegister (
|
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN Register,
|
|
|
|
|
IN UINTN Address,
|
|
|
|
|
IN UINTN Length,
|
|
|
|
|
IN UINTN Type
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
|
FindMatchingDebugRegister (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN Address,
|
|
|
|
|
IN UINTN Length,
|
|
|
|
|
IN UINTN Type,
|
|
|
|
|
OUT UINTN *Register
|
|
|
|
|
);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
|
DisableDebugRegister (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_SYSTEM_CONTEXT SystemContext,
|
|
|
|
|
IN UINTN Register
|
|
|
|
|
);
|
2013-01-25 12:28:06 +01:00
|
|
|
|
|
|
|
|
|
VOID
|
|
|
|
|
InitializeProcessor (
|
|
|
|
|
VOID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
|
ValidateAddress (
|
|
|
|
|
IN VOID *Address
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
|
ValidateException (
|
2021-12-05 23:53:56 +01:00
|
|
|
|
IN EFI_EXCEPTION_TYPE ExceptionType,
|
|
|
|
|
IN OUT EFI_SYSTEM_CONTEXT SystemContext
|
2013-01-25 12:28:06 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#endif
|