arch_gdb.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * CORTEXM GDB support
  3. * arch-specific portion of GDB stub
  4. *
  5. * File : arch_gdb.h(cortexm)
  6. * This file is part of RT-Thread RTOS
  7. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  8. *
  9. * The license and distribution terms for this file may be
  10. * found in the file LICENSE in this distribution or at
  11. * http://www.rt-thread.org/license/LICENSE
  12. *
  13. * Change Logs:
  14. * Date Author Notes
  15. * 2014-07-04 wzyy2 first version
  16. */
  17. #ifndef __ARM_GDB_H__
  18. #define __ARM_GDB_H__
  19. #include <rtthread.h>
  20. #ifndef RT_GDB_HAVE_HWBP
  21. #define RT_GDB_HAVE_HWBP 1
  22. #endif
  23. #ifndef RT_GDB_HAVE_SWBP
  24. #define RT_GDB_HAVE_SWBP 0
  25. #endif
  26. #ifndef GDB_CORTEXM_PRIORITY_MAX
  27. #define GDB_CORTEXM_PRIORITY_MAX (1 << 6)
  28. #endif
  29. #define GDB_DATA_ACCESS
  30. #define BREAK_INSTR_SIZE 4
  31. #define ARM_GP_REGS 16
  32. #define ARM_FP_REGS 8
  33. #define ARM_EXTRA_REGS 2
  34. #define GDB_MAX_REGS (ARM_GP_REGS + (ARM_FP_REGS * 3) + ARM_EXTRA_REGS)
  35. #define NUMREGBYTES (GDB_MAX_REGS << 2)
  36. #define HBP_NUM 6 //Max hardware breakpoint
  37. #define HWP_NUM 4 //Max hardware watchpoint
  38. //#define BUFMAX ((NUMREGBYTES << 1) + 10)
  39. #define BUFMAX 400
  40. #define GDB_DEBUG_REG_BASE 0xE000EDF0
  41. #define GDB_DEBUG_REG_DHSR 0x00
  42. #define GDB_DEBUG_REG_DCRSR 0x04
  43. #define GDB_DEBUG_REG_DCRDR 0x08
  44. #define GDB_DEBUG_REG_DEMCR 0x0c
  45. #define GDB_DEBUG_REG_DEMCR_MON_EN (1UL << 16)
  46. #define GDB_DEBUG_REG_DEMCR_MON_PEND (1UL << 17)
  47. #define GDB_DEBUG_REG_DEMCR_MON_STEP (1UL << 18)
  48. #define GDB_DEBUG_REG_DEMCR_TRCENA (1UL << 24)
  49. #define GDB_NVIC_REG_BASE 0xE000E000
  50. #define GDB_NVIC_REG_SHCSR 0xD24
  51. #define GDB_NVIC_REG_DFSR 0xD30
  52. #define GDB_NVIC_REG_SHCSR_MEMFAULTENA (1 << 16)
  53. #define GDB_FPB_REG_BASE 0xE0002000
  54. #define GDB_FPB_REG_CTRL 0x0
  55. #define GDB_FPB_REG_REMAP 0x4
  56. #define GDB_FPB_REG_COMP 0x8
  57. #define GDB_FPB_REG_CTRL_KEY (1UL << 1)
  58. #define GDB_FPB_REG_CTRL_ENABLE 1
  59. #define GDB_FPB_REG_COMP_ENABLE 1
  60. #define GDB_FPB_REG_COMP_ADDR (((1UL << 29) -1) << 2)
  61. #define GDB_FPB_REG_COMP_REPLACE (((1UL << 32) -1) << 30)
  62. #define GDB_DWT_REG_BASE 0xE0001000
  63. #define GDB_DWT_REG_CTRL 0x0
  64. #define GDB_DWT_REG_COMP 0x20
  65. #define GDB_DWT_REG_MASK 0x24
  66. #define GDB_DWT_REG_FUNCTION 0x28
  67. #define GDB_DWT_REG_FUNCTION_FUC (((1UL << 4) -1) << 0)
  68. enum regnames {
  69. GDB_R0, /*0*/
  70. GDB_R1, /*1*/
  71. GDB_R2, /*2*/
  72. GDB_R3, /*3*/
  73. GDB_R4, /*4*/
  74. GDB_R5, /*5*/
  75. GDB_R6, /*6*/
  76. GDB_R7, /*7*/
  77. GDB_R8, /*8*/
  78. GDB_R9, /*9*/
  79. GDB_R10, /*10*/
  80. GDB_FP, /*11*/
  81. GDB_IP, /*12*/
  82. GDB_SPT, /*13*/
  83. GDB_LR, /*14*/
  84. GDB_PC, /*15*/
  85. GDB_F0, /*16*/
  86. GDB_F1, /*17*/
  87. GDB_F2, /*18*/
  88. GDB_F3, /*19*/
  89. GDB_F4, /*20*/
  90. GDB_F5, /*21*/
  91. GDB_F6, /*22*/
  92. GDB_F7, /*23*/
  93. GDB_FPS, /*24*/
  94. GDB_CPSR = GDB_MAX_REGS-1
  95. };
  96. typedef struct
  97. {
  98. unsigned long type; // State type
  99. unsigned long vector; // Exception vector number
  100. unsigned long basepri; // BASEPRI
  101. unsigned long r4; // Remaining CPU registers
  102. unsigned long r5; // Remaining CPU registers
  103. unsigned long r6; // Remaining CPU registers
  104. unsigned long r7; // Remaining CPU registers
  105. unsigned long r8; // Remaining CPU registers
  106. unsigned long r9; // Remaining CPU registers
  107. unsigned long r10; // Remaining CPU registers
  108. unsigned long r11; // Remaining CPU registers
  109. unsigned long sp; // Remaining CPU registers
  110. unsigned long xlr; // Exception return LR
  111. // The following are saved and restored automatically by the CPU
  112. // for exceptions or interrupts.
  113. unsigned long r0;
  114. unsigned long r1;
  115. unsigned long r2;
  116. unsigned long r3;
  117. unsigned long r12;
  118. unsigned long lr;
  119. unsigned long pc;
  120. unsigned long psr;
  121. } Gdb_SavedRegisters;
  122. /* arch */
  123. extern struct gdb_arch arch_gdb_ops;
  124. void gdb_breakpoint();
  125. void gdb_get_register(unsigned long *gdb_regs);
  126. void gdb_put_register(unsigned long *gdb_regs);
  127. void gdb_set_register(void *hw_regs);
  128. int gdb_arch_handle_exception(char *remcom_in_buffer,
  129. char *remcom_out_buffer);
  130. int gdb_permit_data_access(unsigned long addr, unsigned long count);
  131. void gdb_arch_exit();
  132. void gdb_arch_late();
  133. #endif /* __CORTEXM_GDB_H__ */