TianoCore EDK2 master
Loading...
Searching...
No Matches
GdbStubInternal.h
Go to the documentation of this file.
1
10#ifndef __GDB_STUB_INTERNAL__
11#define __GDB_STUB_INTERNAL__
12
13#include <Uefi.h>
14#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
18#include <Library/UefiLib.h>
20#include <Library/PcdLib.h>
22#include <Library/PrintLib.h>
23
25#include <Protocol/SerialIo.h>
30
31extern CONST CHAR8 mHexToStr[];
32
33// maximum size of input and output buffers
34// This value came from the show remote command of the gdb we tested against
35#define MAX_BUF_SIZE 2000
36
37// maximum size of address buffer
38#define MAX_ADDR_SIZE 32
39
40// maximum size of register number buffer
41#define MAX_REG_NUM_BUF_SIZE 32
42
43// maximum size of length buffer
44#define MAX_LENGTH_SIZE 32
45
46// maximum size of T signal members
47#define MAX_T_SIGNAL_SIZE 64
48
49// the mask used to clear all the cache
50#define TF_BIT 0x00000100
51
52//
53// GDB Signal definitions - generic names for interrupts
54//
55#define GDB_SIGILL 4 // Illegal instruction
56#define GDB_SIGTRAP 5 // Trace Trap (Breakpoint and SingleStep)
57#define GDB_SIGEMT 7 // Emulator Trap
58#define GDB_SIGFPE 8 // Floating point exception
59#define GDB_SIGSEGV 11 // Segment violation, page fault
60
61//
62// GDB File I/O Error values, zero means no error
63// Includes all general GDB Unix like error values
64//
65#define GDB_EBADMEMADDRBUFSIZE 11 // the buffer that stores memory Address to be read from/written to is not the right size
66#define GDB_EBADMEMLENGBUFSIZE 12 // the buffer that stores Length is not the right size
67#define GDB_EBADMEMLENGTH 13 // Length, the given number of bytes to read or write, is not the right size
68#define GDB_EBADMEMDATA 14 // one of the bytes or nibbles of the memory is less than 0
69#define GDB_EBADMEMDATASIZE 15 // the memory data, 'XX..', is too short or too long
70#define GDB_EBADBUFSIZE 21 // the buffer created is not the correct size
71#define GDB_EINVALIDARG 31 // argument is invalid
72#define GDB_ENOSPACE 41 //
73#define GDB_EINVALIDBRKPOINTTYPE 51 // the breakpoint type is not recognized
74#define GDB_EINVALIDREGNUM 61 // given register number is not valid: either <0 or >=Number of Registers
75#define GDB_EUNKNOWN 255 // unknown
76
77//
78// These devices are open by GDB so we can just read and write to them
79//
80#define GDB_STDIN 0x00
81#define GDB_STDOUT 0x01
82#define GDB_STDERR 0x02
83
84//
85// Define Register size for different architectures
86//
87#if defined (MDE_CPU_IA32)
88#define REG_SIZE 32
89#elif defined (MDE_CPU_X64)
90#define REG_SIZE 64
91#elif defined (MDE_CPU_ARM)
92#define REG_SIZE 32
93#endif
94
95#define GDB_SERIAL_DEV_SIGNATURE SIGNATURE_32 ('g', 'd', 'b', 's')
96
97typedef struct {
98 VENDOR_DEVICE_PATH VendorDevice;
99 UINT32 Index; // Support more than one
102
103//
104// Name: SERIAL_DEV
105// Purpose: To provide device specific information
106// Fields:
107// Signature UINTN: The identity of the serial device
108// SerialIo SERIAL_IO_PROTOCOL: Serial I/O protocol interface
109// SerialMode SERIAL_IO_MODE:
110// DevicePath EFI_DEVICE_PATH_PROTOCOL *: Device path of the serial device
111//
112typedef struct {
113 UINTN Signature;
114 EFI_HANDLE Handle;
115 EFI_SERIAL_IO_PROTOCOL SerialIo;
116 EFI_SERIAL_IO_MODE SerialMode;
117 GDB_SERIAL_DEVICE_PATH DevicePath;
118 INTN InFileDescriptor;
119 INTN OutFileDescriptor;
121
122#define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)
123
124typedef struct {
125 EFI_EXCEPTION_TYPE Exception;
126 UINT8 SignalNo;
128
129#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
130
131//
132// Byte packed structure for DR6
133// 32-bits on IA-32
134// 64-bits on X64. The upper 32-bits on X64 are reserved
135//
136typedef union {
137 struct {
138 UINT32 B0 : 1; // Breakpoint condition detected
139 UINT32 B1 : 1; // Breakpoint condition detected
140 UINT32 B2 : 1; // Breakpoint condition detected
141 UINT32 B3 : 1; // Breakpoint condition detected
142 UINT32 Reserved_1 : 9; // Reserved
143 UINT32 BD : 1; // Debug register access detected
144 UINT32 BS : 1; // Single step
145 UINT32 BT : 1; // Task switch
146 UINT32 Reserved_2 : 16; // Reserved
147 } Bits;
148 UINTN UintN;
149} IA32_DR6;
150
151//
152// Byte packed structure for DR7
153// 32-bits on IA-32
154// 64-bits on X64. The upper 32-bits on X64 are reserved
155//
156typedef union {
157 struct {
158 UINT32 L0 : 1; // Local breakpoint enable
159 UINT32 G0 : 1; // Global breakpoint enable
160 UINT32 L1 : 1; // Local breakpoint enable
161 UINT32 G1 : 1; // Global breakpoint enable
162 UINT32 L2 : 1; // Local breakpoint enable
163 UINT32 G2 : 1; // Global breakpoint enable
164 UINT32 L3 : 1; // Local breakpoint enable
165 UINT32 G3 : 1; // Global breakpoint enable
166 UINT32 LE : 1; // Local exact breakpoint enable
167 UINT32 GE : 1; // Global exact breakpoint enable
168 UINT32 Reserved_1 : 3; // Reserved
169 UINT32 GD : 1; // Global detect enable
170 UINT32 Reserved_2 : 2; // Reserved
171 UINT32 RW0 : 2; // Read/Write field
172 UINT32 LEN0 : 2; // Length field
173 UINT32 RW1 : 2; // Read/Write field
174 UINT32 LEN1 : 2; // Length field
175 UINT32 RW2 : 2; // Read/Write field
176 UINT32 LEN2 : 2; // Length field
177 UINT32 RW3 : 2; // Read/Write field
178 UINT32 LEN3 : 2; // Length field
179 } Bits;
180 UINTN UintN;
181} IA32_DR7;
182
183#endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */
184
185typedef enum {
186 InstructionExecution, // Hardware breakpoint
187 DataWrite, // watch
188 DataRead, // rwatch
189 DataReadWrite, // awatch
190 SoftwareBreakpoint, // Software breakpoint
191 NotSupported
192} BREAK_TYPE;
193
194//
195// Array of exception types that need to be hooked by the debugger
196//
197extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];
198
199//
200// Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c
201// here we need to wait for the periodic callback to do this.
202//
203extern BOOLEAN gCtrlCBreakFlag;
204
205//
206// If the periodic callback is called while we are processing an F packet we need
207// to let the callback know to not read from the serial stream as it could steal
208// characters from the F response packet
209//
210extern BOOLEAN gProcessingFPacket;
211
212// The offsets of registers SystemContext.
213// The fields in the array are in the gdb ordering.
214//
215extern UINTN gRegisterOffsets[];
216
222UINTN
224 VOID
225 );
226
232UINTN
234 VOID
235 );
236
244BOOLEAN
245CheckIsa (
247 );
248
256VOID
258 IN EFI_SYSTEM_CONTEXT SystemContext,
259 IN UINT8 GdbExceptionType
260 );
261
268UINT8
270 IN EFI_EXCEPTION_TYPE EFIExceptionType
271 );
272
277VOID
279 IN CHAR8 *Buf
280 );
281
289INTN
291 IN CHAR8 Char
292 );
293
301VOID
302EFIAPI
303SendError (
304 IN UINT8 ErrorNum
305 );
306
310VOID
311EFIAPI
313 VOID
314 );
315
319VOID
320EFIAPI
322 VOID
323 );
324
330VOID
332 IN EFI_SYSTEM_CONTEXT SystemContext,
333 IN CHAR8 *InBuffer
334 );
335
340VOID
341EFIAPI
343 IN EFI_SYSTEM_CONTEXT SystemContext
344 );
345
351VOID
352EFIAPI
354 IN EFI_SYSTEM_CONTEXT SystemContext,
355 IN CHAR8 *InBuffer
356 );
357
364VOID
365EFIAPI
367 IN EFI_SYSTEM_CONTEXT SystemContext,
368 IN CHAR8 *InBuffer
369 );
370
378VOID
379EFIAPI
381 IN CHAR8 *PacketData
382 );
383
391VOID
392EFIAPI
394 IN CHAR8 *PacketData
395 );
396
405VOID
406EFIAPI
408 IN EFI_SYSTEM_CONTEXT SystemContext,
409 IN CHAR8 *PacketData
410 );
411
419VOID
420EFIAPI
422 IN EFI_SYSTEM_CONTEXT SystemContext,
423 IN CHAR8 *PacketData
424 );
425
431VOID
433 IN EFI_SYSTEM_CONTEXT SystemContext
434 );
435
441VOID
443 IN EFI_SYSTEM_CONTEXT SystemContext
444 );
445
458VOID
459EFIAPI
461 IN EFI_SYSTEM_CONTEXT SystemContext,
462 IN CHAR8 *PacketData
463 );
464
477VOID
478EFIAPI
480 IN EFI_SYSTEM_CONTEXT SystemContext,
481 IN CHAR8 *PacketData
482 );
483
492VOID
493EFIAPI
495 IN EFI_EXCEPTION_TYPE ExceptionType,
496 IN OUT EFI_SYSTEM_CONTEXT SystemContext
497 );
498
506VOID
507EFIAPI
509 IN OUT EFI_SYSTEM_CONTEXT SystemContext
510 );
511
519VOID
521 VOID
522 );
523
538UINTN
540 IN CHAR8 *PacketData
541 );
542
559UINTN
561 OUT CHAR8 *PacketData,
562 IN UINTN PacketDataSize
563 );
564
577INTN
578GdbRead (
579 IN INTN FileDescriptor,
580 OUT VOID *Buffer,
581 IN UINTN Count
582 );
583
596INTN
597GdbWrite (
598 IN INTN FileDescriptor,
599 OUT CONST VOID *Buffer,
600 IN UINTN Count
601 );
602
603UINTN *
605 IN EFI_SYSTEM_CONTEXT SystemContext,
606 IN UINTN RegNumber
607 );
608
609CHAR8 *
611 IN EFI_SYSTEM_CONTEXT SystemContext,
612 IN UINTN RegNumber,
613 IN CHAR8 *OutBufPtr
614 );
615
616VOID
618 IN UINTN Length,
619 IN UINT8 *Address,
620 IN CHAR8 *NewData
621 );
622
623VOID
625 IN UINTN Length,
626 IN UINT8 *Address
627 );
628
629CHAR8 *
631 IN EFI_SYSTEM_CONTEXT SystemContext,
632 IN UINTN RegNumber,
633 IN CHAR8 *InBufPtr
634 );
635
636VOID
637PrintReg (
638 EFI_SYSTEM_CONTEXT SystemContext
639 );
640
641UINTN
643 IN CHAR8 *PacketData,
644 OUT UINTN *Type,
645 OUT UINTN *Address,
646 OUT UINTN *Length
647 );
648
649UINTN
651 IN EFI_SYSTEM_CONTEXT SystemContext,
652 IN UINTN BreakpointNumber
653 );
654
655UINTN
657 IN EFI_SYSTEM_CONTEXT SystemContext
658 );
659
660BREAK_TYPE
662 IN EFI_SYSTEM_CONTEXT SystemContext,
663 IN UINTN BreakpointNumber
664 );
665
666UINTN
668 IN UINTN Length
669 );
670
673 IN EFI_SYSTEM_CONTEXT SystemContext,
675 );
676
679 IN EFI_SYSTEM_CONTEXT SystemContext,
681 IN UINTN Address,
682 IN UINTN Length,
683 IN UINTN Type
684 );
685
688 IN EFI_SYSTEM_CONTEXT SystemContext,
689 IN UINTN Address,
690 IN UINTN Length,
691 IN UINTN Type,
693 );
694
697 IN EFI_SYSTEM_CONTEXT SystemContext,
699 );
700
701VOID
702InitializeProcessor (
703 VOID
704 );
705
706BOOLEAN
707ValidateAddress (
708 IN VOID *Address
709 );
710
711BOOLEAN
712ValidateException (
713 IN EFI_EXCEPTION_TYPE ExceptionType,
714 IN OUT EFI_SYSTEM_CONTEXT SystemContext
715 );
716
717#endif
UINT64 UINTN
INT64 INTN
UINTN MaxEfiException(VOID)
Definition: Processor.c:77
UINT8 ConvertEFItoGDBtype(IN EFI_EXCEPTION_TYPE EFIExceptionType)
Definition: GdbStub.c:571
VOID EFIAPI RemoveBreakPoint(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
Definition: Processor.c:608
VOID EFIAPI WriteToMemory(IN CHAR8 *PacketData)
Definition: GdbStub.c:640
UINTN MaxRegisterCount(VOID)
Definition: Processor.c:90
VOID EFIAPI WriteGeneralRegisters(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer)
Definition: Processor.c:330
VOID GdbInitializeSerialConsole(VOID)
Definition: SerialIo.c:498
CHAR8 * BasicReadRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN RegNumber, IN CHAR8 *OutBufPtr)
Definition: Processor.c:144
BREAK_TYPE GetBreakpointType(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN BreakpointNumber)
Definition: Processor.c:488
VOID EFIAPI InsertBreakPoint(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
Definition: Processor.c:575
VOID TransferFromInBufToMem(IN UINTN Length, IN UINT8 *Address, IN CHAR8 *NewData)
Definition: GdbStub.c:182
VOID ReadNthRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer)
Definition: Processor.c:187
CHAR8 * BasicWriteRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN RegNumber, IN CHAR8 *InBufPtr)
Definition: Processor.c:246
UINTN ParseBreakpointPacket(IN CHAR8 *PacketData, OUT UINTN *Type, OUT UINTN *Address, OUT UINTN *Length)
Definition: GdbStub.c:719
VOID EFIAPI SendNotSupported(VOID)
Definition: GdbStub.c:466
BOOLEAN CheckIsa(IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa)
Definition: Processor.c:105
VOID EFIAPI ReadGeneralRegisters(IN EFI_SYSTEM_CONTEXT SystemContext)
Definition: Processor.c:216
VOID EFIAPI WriteNthRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer)
Definition: Processor.c:292
UINTN ConvertLengthData(IN UINTN Length)
Definition: Processor.c:530
VOID EFIAPI GdbExceptionHandler(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
Definition: GdbStub.c:1088
UINTN SendPacket(IN CHAR8 *PacketData)
Definition: GdbStub.c:270
EFI_STATUS FindMatchingDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN Address, IN UINTN Length, IN UINTN Type, OUT UINTN *Register)
Definition: Processor.c:675
VOID RemoveSingleStep(IN EFI_SYSTEM_CONTEXT SystemContext)
Definition: Processor.c:417
VOID AddSingleStep(IN EFI_SYSTEM_CONTEXT SystemContext)
Definition: Processor.c:386
VOID EFIAPI SingleStep(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
Definition: Processor.c:462
VOID EFIAPI SendSuccess(VOID)
Definition: GdbStub.c:454
UINTN GetBreakpointDataAddress(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN BreakpointNumber)
Definition: Processor.c:471
EFI_STATUS DisableDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN Register)
Definition: Processor.c:740
INTN GdbWrite(IN INTN FileDescriptor, OUT CONST VOID *Buffer, IN UINTN Count)
Definition: SerialIo.c:197
VOID GdbSendTSignal(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINT8 GdbExceptionType)
Definition: GdbStub.c:480
VOID EmptyBuffer(IN CHAR8 *Buf)
Definition: GdbStub.c:393
UINTN ReceivePacket(OUT CHAR8 *PacketData, IN UINTN PacketDataSize)
Definition: GdbStub.c:327
INTN HexCharToInt(IN CHAR8 Char)
Definition: GdbStub.c:408
EFI_STATUS EnableDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN Register, IN UINTN Address, IN UINTN Length, IN UINTN Type)
Definition: Processor.c:598
INTN GdbRead(IN INTN FileDescriptor, OUT VOID *Buffer, IN UINTN Count)
Definition: SerialIo.c:115
VOID EFIAPI ReadFromMemory(IN CHAR8 *PacketData)
EFI_STATUS FindNextFreeDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, OUT UINTN *Register)
Definition: Processor.c:560
UINTN * FindPointerToRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN RegNumber)
Definition: Processor.c:124
VOID EFIAPI SendError(IN UINT8 ErrorNum)
Definition: GdbStub.c:436
UINTN GetBreakpointDetected(IN EFI_SYSTEM_CONTEXT SystemContext)
Definition: Processor.c:480
VOID EFIAPI GdbPeriodicCallBack(IN OUT EFI_SYSTEM_CONTEXT SystemContext)
Definition: GdbStub.c:1199
VOID TransferFromMemToOutBufAndSend(IN UINTN Length, IN UINT8 *Address)
Definition: GdbStub.c:215
VOID EFIAPI ContinueAtAddress(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
Definition: Processor.c:444
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
INTN EFI_EXCEPTION_TYPE
Definition: DebugSupport.h:35
EFI_INSTRUCTION_SET_ARCHITECTURE
Definition: DebugSupport.h:836
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33