EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

EmbeddedPkg/GdbStub/GdbStubInternal.h

Go to the documentation of this file.
00001 
00016 #ifndef __GDB_STUB_INTERNAL__
00017 #define __GDB_STUB_INTERNAL__
00018 
00019 #include <Uefi.h>
00020 #include <Library/BaseLib.h>
00021 #include <Library/BaseMemoryLib.h>
00022 #include <Library/MemoryAllocationLib.h>
00023 #include <Library/DebugLib.h>
00024 #include <Library/UefiLib.h>
00025 #include <Library/UefiBootServicesTableLib.h>
00026 #include <Library/PcdLib.h>
00027 #include <Library/GdbSerialLib.h>
00028 #include <Library/PrintLib.h>
00029 
00030 #include <Protocol/DebugSupport.h>
00031 #include <Protocol/SerialIo.h>
00032 #include <Protocol/LoadedImage.h>
00033 #include <Protocol/LoadedImage.h>
00034 #include <Guid/DebugImageInfoTable.h>
00035 #include <IndustryStandard/PeImage.h>
00036 
00037 extern CONST CHAR8 mHexToStr[];
00038 
00039 // maximum size of input and output buffers
00040 // This value came from the show remote command of the gdb we tested against 
00041 #define MAX_BUF_SIZE 2000
00042 
00043 // maximum size of address buffer
00044 #define MAX_ADDR_SIZE 32
00045 
00046 // maximum size of register number buffer
00047 #define MAX_REG_NUM_BUF_SIZE 32
00048 
00049 // maximum size of length buffer
00050 #define MAX_LENGTH_SIZE 32
00051 
00052 // maximum size of T signal members
00053 #define MAX_T_SIGNAL_SIZE 64
00054 
00055 // the mask used to clear all the cache
00056 #define TF_BIT 0x00000100
00057 
00058 
00059 //
00060 // GDB Signal definitions - generic names for interrupts
00061 //
00062 #define GDB_SIGILL      4  // Illegal instruction       
00063 #define GDB_SIGTRAP     5  // Trace Trap (Breakpoint and SingleStep)
00064 #define GDB_SIGEMT      7  // Emulator Trap
00065 #define GDB_SIGFPE      8  // Floating point exception
00066 #define GDB_SIGSEGV     11 // Setgment violation, page fault 
00067 
00068 
00069 //
00070 // GDB File I/O Error values, zero means no error
00071 // Includes all general GDB Unix like error values
00072 //
00073 #define GDB_EBADMEMADDRBUFSIZE   11  // the buffer that stores memory Address to be read from/written to is not the right size
00074 #define GDB_EBADMEMLENGBUFSIZE   12  // the buffer that stores Length is not the right size 
00075 #define GDB_EBADMEMLENGTH        13  // Length, the given number of bytes to read or write, is not the right size
00076 #define GDB_EBADMEMDATA          14  // one of the bytes or nibbles of the memory is leess than 0 
00077 #define GDB_EBADMEMDATASIZE      15  // the memory data, 'XX..', is too short or too long
00078 #define GDB_EBADBUFSIZE          21  // the buffer created is not the correct size
00079 #define GDB_EINVALIDARG          31  // argument is invalid
00080 #define GDB_ENOSPACE             41  //
00081 #define GDB_EINVALIDBRKPOINTTYPE 51  // the breakpoint type is not recognized
00082 #define GDB_EINVALIDREGNUM       61  // given register number is not valid: either <0 or >=Number of Registers
00083 #define GDB_EUNKNOWN             255 // unknown
00084 
00085 
00086 //
00087 // These devices are open by GDB so we can just read and write to them
00088 //
00089 #define GDB_STDIN   0x00
00090 #define GDB_STDOUT  0x01
00091 #define GDB_STDERR  0x02
00092 
00093 //
00094 //Define Register size for different architectures
00095 //
00096 #if defined (MDE_CPU_IA32) 
00097 #define REG_SIZE  32
00098 #elif defined (MDE_CPU_X64)
00099 #define REG_SIZE  64
00100 #elif defined (MDE_CPU_ARM)
00101 #define REG_SIZE  32
00102 #endif
00103 
00104 #define GDB_SERIAL_DEV_SIGNATURE    SIGNATURE_32 ('g', 'd', 'b', 's')
00105 
00106 typedef struct {
00107   VENDOR_DEVICE_PATH                     VendorDevice;
00108   UINT32                                 Index;         // Suport more than one
00109   EFI_DEVICE_PATH_PROTOCOL               End;
00110 } GDB_SERIAL_DEVICE_PATH;
00111 
00112 //
00113 //  Name:   SERIAL_DEV
00114 //  Purpose:  To provide device specific information
00115 //  Fields:
00116 //      Signature UINTN: The identity of the serial device
00117 //      SerialIo  SERIAL_IO_PROTOCOL: Serial I/O protocol interface
00118 //      SerialMode  SERIAL_IO_MODE:
00119 //      DevicePath  EFI_DEVICE_PATH_PROTOCOL *: Device path of the serial device
00120 //
00121 typedef struct {
00122   UINTN                                  Signature;
00123   EFI_HANDLE                             Handle;
00124   EFI_SERIAL_IO_PROTOCOL                 SerialIo;
00125   EFI_SERIAL_IO_MODE                     SerialMode;
00126   GDB_SERIAL_DEVICE_PATH                 DevicePath;
00127   INTN                                   InFileDescriptor;
00128   INTN                                   OutFileDescriptor;
00129 } GDB_SERIAL_DEV;
00130 
00131 
00132 #define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)
00133 
00134 
00135 typedef struct {
00136     EFI_EXCEPTION_TYPE  Exception;
00137     UINT8               SignalNo;
00138 } EFI_EXCEPTION_TYPE_ENTRY;
00139 
00140 
00141 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
00142 
00143 //
00144 // Byte packed structure for DR6
00145 // 32-bits on IA-32
00146 // 64-bits on X64.  The upper 32-bits on X64 are reserved
00147 //
00148 typedef union {
00149   struct {
00150     UINT32  B0:1;           // Breakpoint condition detected
00151     UINT32  B1:1;           // Breakpoint condition detected
00152     UINT32  B2:1;           // Breakpoint condition detected
00153     UINT32  B3:1;           // Breakpoint condition detected
00154     UINT32  Reserved_1:9;   // Reserved 
00155     UINT32  BD:1;           // Debug register access detected
00156     UINT32  BS:1;           // Single step
00157     UINT32  BT:1;           // Task switch
00158     UINT32  Reserved_2:16;  // Reserved
00159   } Bits;
00160   UINTN     UintN;
00161 } IA32_DR6;
00162 
00163 //
00164 // Byte packed structure for DR7
00165 // 32-bits on IA-32
00166 // 64-bits on X64.  The upper 32-bits on X64 are reserved
00167 //
00168 typedef union {
00169   struct {
00170     UINT32  L0:1;           // Local breakpoint enable
00171     UINT32  G0:1;           // Global breakpoint enable
00172     UINT32  L1:1;           // Local breakpoint enable
00173     UINT32  G1:1;           // Global breakpoint enable
00174     UINT32  L2:1;           // Local breakpoint enable
00175     UINT32  G2:1;           // Global breakpoint enable
00176     UINT32  L3:1;           // Local breakpoint enable
00177     UINT32  G3:1;           // Global breakpoint enable
00178     UINT32  LE:1;           // Local exact breakpoint enable
00179     UINT32  GE:1;           // Global exact breakpoint enable
00180     UINT32  Reserved_1:3;   // Reserved
00181     UINT32  GD:1;           // Global detect enable
00182     UINT32  Reserved_2:2;   // Reserved
00183     UINT32  RW0:2;          // Read/Write field
00184     UINT32  LEN0:2;         // Length field
00185     UINT32  RW1:2;          // Read/Write field
00186     UINT32  LEN1:2;         // Length field
00187     UINT32  RW2:2;          // Read/Write field
00188     UINT32  LEN2:2;         // Length field
00189     UINT32  RW3:2;          // Read/Write field
00190     UINT32  LEN3:2;         // Length field
00191   } Bits;
00192   UINTN     UintN;
00193 } IA32_DR7;
00194 
00195 #endif /* if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) */
00196 
00197 typedef enum {
00198   InstructionExecution,   //Hardware breakpoint
00199   DataWrite,              //watch
00200   DataRead,               //rwatch
00201   DataReadWrite,          //awatch
00202   SoftwareBreakpoint,     //Software breakpoint
00203   NotSupported
00204 } BREAK_TYPE;
00205 
00206 //
00207 // Array of exception types that need to be hooked by the debugger
00208 //
00209 extern EFI_EXCEPTION_TYPE_ENTRY gExceptionType[];
00210 
00211 //
00212 // Set TRUE if F Reply package signals a ctrl-c. We can not process the Ctrl-c
00213 // here we need to wait for the periodic callback to do this. 
00214 //
00215 extern BOOLEAN gCtrlCBreakFlag;
00216 
00217 //
00218 // If the periodic callback is called while we are processing an F packet we need
00219 // to let the callback know to not read from the serail stream as it could steal
00220 // characters from the F reponse packet
00221 //
00222 extern BOOLEAN gProcessingFPacket;
00223 
00224 
00225 // The offsets of registers SystemContext.
00226 // The fields in the array are in the gdb ordering.
00227 //
00228 extern UINTN    gRegisterOffsets[];
00229 
00235 UINTN
00236 MaxEfiException (
00237   VOID
00238   );
00239 
00240 
00246 UINTN
00247 MaxRegisterCount (
00248   VOID
00249   );
00250 
00251 
00259 BOOLEAN
00260 CheckIsa (
00261   IN    EFI_INSTRUCTION_SET_ARCHITECTURE    Isa
00262   );
00263 
00264 
00272 VOID
00273 GdbSendTSignal (
00274   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00275   IN  UINT8                   GdbExceptionType
00276   );
00277 
00278 
00285 UINT8
00286 ConvertEFItoGDBtype ( 
00287   IN  EFI_EXCEPTION_TYPE EFIExceptionType
00288   );
00289 
00290 
00295 VOID
00296 EmptyBuffer ( 
00297   IN CHAR8  *Buf
00298   );
00299 
00300 
00308 INTN
00309 HexCharToInt (
00310   IN  CHAR8 Char
00311   );
00312 
00313 
00321 VOID
00322 EFIAPI
00323 SendError (
00324   IN  UINT8     ErrorNum
00325   );
00326 
00327 
00331 VOID
00332 SendSuccess (
00333   VOID
00334   );
00335 
00336 
00340 VOID
00341 SendNotSupported (
00342   VOID
00343   );
00344 
00350 VOID
00351 ReadNthRegister (
00352   IN    EFI_SYSTEM_CONTEXT  SystemContext,
00353   IN    CHAR8               *InBuffer
00354   );
00355 
00356 
00361 VOID
00362 ReadGeneralRegisters (  
00363   IN    EFI_SYSTEM_CONTEXT  SystemContext
00364   );
00365 
00366 
00372 VOID
00373 WriteNthRegister (
00374   IN    EFI_SYSTEM_CONTEXT  SystemContext,
00375   IN    CHAR8               *InBuffer
00376   );
00377 
00378 
00385 VOID
00386 WriteGeneralRegisters (
00387   IN    EFI_SYSTEM_CONTEXT  SystemContext,
00388   IN    CHAR8               *InBuffer
00389   );
00390 
00391 
00399 VOID
00400 ReadFromMemory (
00401   IN  CHAR8  *PacketData
00402   );
00403 
00404 
00412 VOID
00413 WriteToMemory (
00414   IN CHAR8 *PacketData
00415   );
00416 
00417 
00426 VOID
00427 ContinueAtAddress (
00428   IN  EFI_SYSTEM_CONTEXT   SystemContext,
00429   IN  CHAR8                *PacketData
00430   );
00431 
00432 
00440 VOID
00441 SingleStep (
00442   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00443   IN  CHAR8               *PacketData
00444   );
00445 
00451 VOID
00452 AddSingleStep (
00453   IN  EFI_SYSTEM_CONTEXT  SystemContext
00454   );
00455   
00461 VOID
00462 RemoveSingleStep (
00463   IN  EFI_SYSTEM_CONTEXT  SystemContext
00464   );
00465   
00466   
00479 VOID
00480 EFIAPI
00481 InsertBreakPoint(
00482   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00483   IN  CHAR8               *PacketData
00484   );
00485 
00486 
00499 VOID
00500 EFIAPI
00501 RemoveBreakPoint(
00502   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00503   IN  CHAR8               *PacketData
00504   );
00505 
00506 
00515 VOID
00516 EFIAPI
00517 GdbExceptionHandler ( 
00518   IN     EFI_EXCEPTION_TYPE  ExceptionType, 
00519   IN OUT EFI_SYSTEM_CONTEXT  SystemContext 
00520   );
00521 
00522 
00530 VOID
00531 EFIAPI
00532 GdbPeriodicCallBack ( 
00533   IN OUT EFI_SYSTEM_CONTEXT  SystemContext 
00534   );
00535 
00536 
00544 VOID
00545 GdbInitializeSerialConsole (
00546   VOID
00547   );
00548 
00549 
00564 UINTN
00565 SendPacket (
00566   IN  CHAR8 *PacketData
00567   );
00568   
00569 
00586 UINTN
00587 ReceivePacket (
00588  OUT  CHAR8 *PacketData,
00589  IN   UINTN PacketDataSize
00590  );
00591   
00592 
00605 INTN
00606 GdbRead (
00607   IN  INTN    FileDescriptor,
00608   OUT VOID    *Buffer,
00609   IN  UINTN   Count
00610   );
00611   
00612 
00625 INTN
00626 GdbWrite (
00627   IN  INTN          FileDescriptor,
00628   OUT CONST VOID    *Buffer,
00629   IN  UINTN         Count
00630   );
00631 
00632 UINTN *  
00633 FindPointerToRegister (
00634   IN  EFI_SYSTEM_CONTEXT    SystemContext,
00635   IN  UINTN                 RegNumber  
00636   );
00637 
00638 CHAR8 * 
00639 BasicReadRegister (
00640   IN  EFI_SYSTEM_CONTEXT      SystemContext,
00641   IN  UINTN                   RegNumber,
00642   IN  CHAR8                   *OutBufPtr
00643   );
00644 
00645 VOID
00646 TransferFromInBufToMem (
00647   IN  UINTN   Length,
00648   IN  UINT8   *Address,
00649   IN  CHAR8   *NewData
00650   );
00651 
00652 VOID
00653 TransferFromMemToOutBufAndSend (
00654   IN  UINTN  Length,
00655   IN  UINT8  *Address
00656   );
00657 
00658 CHAR8 *
00659 BasicWriteRegister (
00660   IN  EFI_SYSTEM_CONTEXT    SystemContext,
00661   IN  UINTN                 RegNumber,
00662   IN  CHAR8                 *InBufPtr
00663   );
00664 
00665 VOID  
00666 PrintReg (
00667   EFI_SYSTEM_CONTEXT SystemContext
00668   );
00669 
00670 UINTN
00671 ParseBreakpointPacket (
00672   IN  CHAR8 *PacketData,
00673   OUT UINTN *Type,
00674   OUT UINTN *Address,
00675   OUT UINTN *Length
00676   );
00677 
00678 UINTN
00679 GetBreakpointDataAddress (
00680   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00681   IN  UINTN               BreakpointNumber 
00682   );
00683 
00684 UINTN
00685 GetBreakpointDetected (
00686   IN  EFI_SYSTEM_CONTEXT  SystemContext
00687   );
00688 
00689 BREAK_TYPE
00690 GetBreakpointType (
00691   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00692   IN  UINTN               BreakpointNumber  
00693   );
00694 
00695 UINTN
00696 ConvertLengthData (
00697   IN  UINTN  Length
00698   );
00699 
00700 EFI_STATUS
00701 FindNextFreeDebugRegister (
00702   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00703   OUT UINTN               *Register
00704   );
00705 
00706 EFI_STATUS
00707 EnableDebugRegister (
00708   IN  EFI_SYSTEM_CONTEXT  SystemContext,
00709   IN  UINTN               Register,
00710   IN  UINTN               Address,
00711   IN  UINTN               Length,
00712   IN  UINTN               Type
00713   );
00714 
00715 EFI_STATUS
00716 FindMatchingDebugRegister (
00717  IN  EFI_SYSTEM_CONTEXT  SystemContext,
00718  IN  UINTN               Address,
00719  IN  UINTN               Length,
00720  IN  UINTN               Type,
00721  OUT UINTN               *Register
00722  );
00723 
00724 EFI_STATUS
00725 DisableDebugRegister (
00726  IN  EFI_SYSTEM_CONTEXT  SystemContext,
00727  IN  UINTN               Register
00728  );
00729 
00730 VOID
00731 InitializeProcessor (
00732   VOID
00733   );
00734 
00735 BOOLEAN
00736 ValidateAddress (
00737   IN  VOID  *Address
00738   );
00739 
00740 BOOLEAN
00741 ValidateException (
00742   IN  EFI_EXCEPTION_TYPE    ExceptionType, 
00743   IN OUT EFI_SYSTEM_CONTEXT SystemContext 
00744   );
00745 
00746 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines