ultragdb.h 5.93 KB
#ifndef __ultragdb__
#define __ultragdb__

#include "ultratypes.h"
#include "os.h"
#include "os_internal.h"
#include "dbgproto.h"
#include "sptask.h"

typedef void (* VFUNPTR)();

#define GDB_PRINTF      osSyncPrintf

#define GDB_DBG_BUF_SIZE  2048
#define GDB_STACKSIZE     0x1000
#define __GDB_BUFMAX    GDB_DBG_BUF_SIZE

#define TMP_BREAK       0x0000000d
#define CNX_BREAK       0x0001000d
#define NUM_REGS 71

#define GDB_BREAKMASK 0xfc00003f
#define GDB_USE_THREADID       0

/*
 *Messages that may be sent to the GDB message queue
 */

#define MSG_BREAKPOINT		0x02
#define MSG_SPBREAKPOINT	0x04
#define MSG_CPUFAULT		0x08
#define MSG_THREADCREATE	0x10
#define MSG_THREADDESTROY	0x20

/* GDB reply status codes */
#define GDB_RESP_STATUS_OK             "OK"
#define GDB_RESP_ERR_PKT_FORMAT        "E01"
#define GDB_RESP_ERR_NO_THREAD         "E02"
#define GDB_RESP_ERR_INVALID_ADDR      "E03"
#define GDB_RESP_ERR_INVALID_THREAD_OP "E04"
#define GDB_RESP_ERR_NO_MORE_SLOTS     "E05"   /* No more breakpoint slots */
#define GDB_RESP_ERR_OP_FAILED         "E06"   /* Operation failed for some reason */

/* GDB error codes (similar to RMON's TV_ERROR_... codes */
#define GDB_ERROR_NO_ERROR		     0
#define GDB_ERROR_INVALID_ID		-2
#define GDB_ERROR_OP_FAILED  		-3 /* TV_ERROR_INVALID_TYPE */
#define GDB_ERROR_OP_PROTECTED		-4
#define GDB_ERROR_INVALID_ADDRESS	-5
#define GDB_ERROR_NO_MORE_IDS		-10

/* GDB breakpoint types - currently only type 0 is supported */
#define GDB_BREAKPT_MEMORY    0
#define GDB_BREAKPT_HARDWARE  1
#define GDB_WATCHPT_WRITE     2
#define GDB_WATCHPT_READ      3
#define GDB_WATCHPT_ACCESS    4

#define __GDB_THREAD_LIST_LIMIT  32

/* Use -1 to indicate we are interested in all threads */
#define GDB_ALL_THREADS       (OSThread*) -1

/* GDB debug verbosity masks */
#define GDB_DEBUG_SHOW_INFO   0x01
#define GDB_DEBUG_SHOW_ERROR  0x02
#define GDB_DEBUG_SHOW_PACKET 0x10
#define GDB_DEBUG_SHOW_CHAR   0x20

/* Macros for identifying different classes of threads 
   Thread t should be checked to be not NULL before using macros */
#define __OS_IS_IDLE_THREAD(t)    (t->priority == OS_PRIORITY_IDLE)
#define __OS_IS_USER_THREAD(t)    \
((t->priority > 0) && (t->priority <= OS_PRIORITY_APPMAX))
#define __OS_IS_SYSTEM_THREAD(t)  \
((t->priority > OS_PRIORITY_APPMAX) && (t->priority <= OS_PRIORITY_MAX))

/* the order of the registers follows GDB's tm-mips.h */

typedef struct {
    /* General purpose registers */
    u32 zero; u32 at; u32 v0; u32 v1; u32 a0; u32 a1; u32 a2; u32 a3; /* 0-7 */
    u32 t0;   u32 t1; u32 t2; u32 t3; u32 t4; u32 t5; u32 t6; u32 t7; /* 8-15 */
    u32 s0;   u32 s1; u32 s2; u32 s3; u32 s4; u32 s5; u32 s6; u32 s7; /* 16-23 */
    u32 t8;   u32 t9; u32 k0; u32 k1; u32 gp; u32 sp; u32 s8; u32 ra; /* 24-31 */
    
    /* Special registers */
    u32 sr;   u32 hi; u32 lo; u32 bad; u32 cause; u32 pc;             /* 32-37 */

    /* Floating point registers */
    u32 f0;   u32 f1; u32 f2; u32 f3; u32 f4; u32 f5; u32 f6; u32 f7;        /* 38-45 */
    u32 f8;   u32 f9; u32 f10; u32 f11; u32 f12; u32 f13; u32 f14; u32 f15;  /* 46-53 */

    u32 f16;  u32 f17; u32 f18; u32 f19; u32 f20; u32 f21; u32 f22; u32 f23; /* 54-61 */
    u32 f24;  u32 f25; u32 f26; u32 f27; u32 f28; u32 f29; u32 f30; u32 f31; /* 62-69 */

    u32 fsr;  u32 fir; /* 70-71 */ 
} Registers;

typedef struct {
    char* name;
    u32   addr;
} gdbSymbol;

extern char* gdb_module_name;

extern int gdbDebug;
extern int gdbShowAllThreadsFlag;
extern int gdbStopUserThreadsFlag;
extern int gdbWaitToSendBreakFlag;

extern OSThread *__gdb_curRunThread;
extern OSThread *__gdb_curThread;

/* Function prototypes */

void    gdbWritebackDCache(void *, s32);
void    gdbInvalICache(void *, s32);

/* from gdbutil.c */
char *strcpy (char *s1, const char *s2);
char* mem2hex(char *mem, char *buf, int count);
int   hex(char ch);
int   hexToInt(char **ptr, int *intValue);
char* hex2mem(char *buf, char *mem, int count);

/* from gdbbrk.c */
int  gdbRemoveAllBreakpoints();
int  gdbRemoveBreakpoint(int type, u32* addr, int length);
int  gdbInsertBreakpoint(int type, u32* addr, int length);
int  __gdbSetSingleStep(OSThread* thread, u32 * instptr);
void __gdbHitBreak( void );
void __gdbHitCpuFault( void );

/* from gdbregs.c */
u32  __gdbGetRegisterContents(OSThread* tptr, int regNumber);
int  __gdbSetRegister(OSThread* thread, int reg, int value);
void gdbProcSetRegisterPkt(char* ptr, char *resp);
void gdbAssembleRegisters(char *resp);

/* from gdbio.c */
void __gdbSendFault( OSThread * thread );
void __gdbIOflush( void );
int  __gdbSend(char *s, int n);
char __gdbPutDebugChar(char c);
int  __gdbGetDebugChar(void);
u32  __gdbGetPacket(char *buffer, u32 bufsize, int* psig);
void __gdbPutPacket(char *buffer);
void __gdbIOhandler(void);

/* from gdbhandler.c */
char* __gdbWriteThreadID(char* buf, int threadID);
char* __gdbWriteThreadInfo(char *buf, int threadID);
char* __gdbWriteSignal(char *buf, int sigval); 
char* __gdbWriteSRThreadID(char *buf, int threadID); 
char* __gdbStartThreadSignalReply(char *buf, int sigval); 
void  gdbWriteSignalReply(char *buf, int sigval);
void  gdbWriteThreadSignalReply(char *buf, int sigval, int threadID); 
int   gdbWriteThreadList(char *ptr, u32 limit, int restart);
void  gdbQuerySymbol(char* buf, gdbSymbol *symbol);
int   gdbAddSymbol(char* hex_symname, gdbSymbol *symbol, u32 addr);
void  gdbProcSetThreadPkt(char* ptr, char *resp);
void  gdbProcBreakPkt(char cmd, char* ptr, char *resp);
void  gdbProcPacket();


/* from gdbthreads.c */
OSThread* __gdbGetActiveQueue(void);
int       __gdbGetThreadID(OSThread* t);
OSThread* __gdbFindIdleThread();
OSThread* __gdbFindUserThread();
OSThread* __gdbIDToThread(int threadID);
void      __gdbMaskIdleThreadInts( void );
int       __gdbGetCurrentThreadID();
int       __gdbSetRequestedThread(OSThread** thread, int tid);
OSThread* getOneCurrentThread();
int       gdbRunThread(OSThread* thread, int flags, int addr);
void      gdbFindFaultedThreads( void );
int       gdbStopUserThread(OSThread* tptr);

#endif /* __ultragdb__ */