gdb_stub.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * This provides the functions that GDB needs to share between
  3. * different portions.
  4. *
  5. * GDB stub.
  6. *
  7. * Migarte form linux to rt-thread by Wzyy2
  8. * Original edition : KGDB stub
  9. *
  10. * File : gdb_stub.h
  11. * This file is part of RT-Thread RTOS
  12. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  13. *
  14. * The license and distribution terms for this file may be
  15. * found in the file LICENSE in this distribution or at
  16. * http://www.rt-thread.org/license/LICENSE
  17. *
  18. * Change Logs:
  19. * Date Author Notes
  20. * 2014-07-04 Wzyy2 first version
  21. */
  22. #ifndef __GDB_STUB_H__
  23. #define __GDB_STUB_H__
  24. #include <rtthread.h>
  25. #include <arch_gdb.h>
  26. #ifndef RT_GDB_MAX_BREAKPOINTS
  27. #define GDB_MAX_BREAKPOINTS 20
  28. #else
  29. #define GDB_MAX_BREAKPOINTS RT_GDB_MAX_BREAKPOINTS
  30. #endif
  31. // Signal definitions
  32. #define SIGHUP 1 /* hangup */
  33. #define SIGINT 2 /* interrupt */ //irq or fiq
  34. #define SIGQUIT 3 /* quit */
  35. #define SIGILL 4 /* illegal instruction (not reset when caught) */
  36. #define SIGTRAP 5 /* trace trap (not reset when caught) */
  37. #define SIGIOT 6 /* IOT instruction */
  38. #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
  39. #define SIGEMT 7 /* EMT instruction */
  40. #define SIGFPE 8 /* floating point exception */
  41. #define SIGKILL 9 /* kill (cannot be caught or ignored) */
  42. #define SIGBUS 10 /* bus error */ //abort or reserved
  43. #define SIGSEGV 11 /* segmentation violation */
  44. #define SIGSYS 12 /* bad argument to system call */
  45. #define SIGPIPE 13 /* write on a pipe with no one to read it */
  46. #define SIGALRM 14 /* alarm clock */
  47. #define SIGTERM 15 /* software termination signal from kill */
  48. enum gdb_bptype {
  49. BP_BREAKPOINT = 0,
  50. BP_HARDWARE_BREAKPOINT,
  51. BP_WRITE_WATCHPOINT,
  52. BP_READ_WATCHPOINT,
  53. BP_ACCESS_WATCHPOINT,
  54. BP_POKE_BREAKPOINT,
  55. };
  56. enum gdb_bpstate {
  57. BP_UNDEFINED = 0,
  58. BP_REMOVED,
  59. BP_SET,
  60. BP_ACTIVE
  61. };
  62. struct gdb_bkpt {
  63. unsigned long bpt_addr;
  64. unsigned char saved_instr[BREAK_INSTR_SIZE];
  65. enum gdb_bptype type;
  66. enum gdb_bpstate state;
  67. };
  68. /**
  69. * struct gdb_arch - Describe architecture specific values.
  70. * @gdb_bpt_instr: The instruction to trigger a breakpoint.
  71. * @flags: Flags for the breakpoint, currently just %GDB_HW_BREAKPOINT.
  72. * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
  73. * breakpoint.
  74. * @remove_hw_breakpoint: Allow an architecture to specify how to remove a
  75. * hardware breakpoint.
  76. * @remove_all_hw_break: Allow an architecture to specify how to remove all
  77. * hardware breakpoints.
  78. */
  79. struct gdb_arch {
  80. unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
  81. unsigned long flags;
  82. int (*set_hw_breakpoint)(unsigned long, int, enum gdb_bptype);
  83. int (*remove_hw_breakpoint)(unsigned long, int, enum gdb_bptype);
  84. void (*remove_all_hw_break)(void);
  85. };
  86. /**
  87. * struct gdb_io - Describe the interface for an I/O driver to talk with KGDB.
  88. * @read_char: Pointer to a function that will return one char.
  89. * @write_char: Pointer to a function that will write one char.
  90. * @flush: Pointer to a function that will flush any pending writes.
  91. * @init: Pointer to a function that will initialize the device.
  92. */
  93. struct gdb_io {
  94. int (*read_char) (void);
  95. void (*write_char) (char);
  96. void (*flush) (void);
  97. int (*init) (void);
  98. };
  99. extern int gdb_connected;
  100. extern void* volatile gdb_mem_fault_handler;
  101. int gdb_hex2long(char **ptr, unsigned long *long_val);
  102. int gdb_mem2hex(char *mem, char *buf, int count);
  103. int gdb_hex2mem(char *buf, char *mem, int count);
  104. int gdb_ebin2mem(char *buf, char *mem, int count);
  105. int gdb_set_sw_break(unsigned long addr);
  106. int gdb_remove_sw_break(unsigned long addr);
  107. int gdb_isremovedbreak(unsigned long addr);
  108. void gdb_console_write(const char *s, unsigned count);
  109. int gdb_handle_exception(int signo, void *regs);
  110. /* hal */
  111. extern struct gdb_io gdb_io_ops;
  112. extern rt_device_t gdb_dev;
  113. void gdb_start();
  114. void gdb_set_device(const char* device_name);
  115. #endif /* __GDB_STUB_H__ */