You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

217 lines
6.7 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * Copyright (C) 2006 by Magnus Lundin *
  5. * lundin@mlu.mine.nu *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; either version 2 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * You should have received a copy of the GNU General Public License *
  18. * along with this program; if not, write to the *
  19. * Free Software Foundation, Inc., *
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  21. ***************************************************************************/
  22. #ifndef CORTEX_M3_H
  23. #define CORTEX_M3_H
  24. #include "register.h"
  25. #include "target.h"
  26. #include "armv7m.h"
  27. #include "cortex_swjdp.h"
  28. extern char* cortex_m3_state_strings[];
  29. #define CORTEX_M3_COMMON_MAGIC 0x1A451A45
  30. #define SYSTEM_CONTROL_BASE 0x400FE000
  31. #define CPUID 0xE000ED00
  32. /* Debug Control Block */
  33. #define DCB_DHCSR 0xE000EDF0
  34. #define DCB_DCRSR 0xE000EDF4
  35. #define DCB_DCRDR 0xE000EDF8
  36. #define DCB_DEMCR 0xE000EDFC
  37. #define DCRSR_WnR (1<<16)
  38. #define DWT_CTRL 0xE0001000
  39. #define DWT_COMP0 0xE0001020
  40. #define DWT_MASK0 0xE0001024
  41. #define DWT_FUNCTION0 0xE0001028
  42. #define FP_CTRL 0xE0002000
  43. #define FP_REMAP 0xE0002004
  44. #define FP_COMP0 0xE0002008
  45. #define FP_COMP1 0xE000200C
  46. #define FP_COMP2 0xE0002010
  47. #define FP_COMP3 0xE0002014
  48. #define FP_COMP4 0xE0002018
  49. #define FP_COMP5 0xE000201C
  50. #define FP_COMP6 0xE0002020
  51. #define FP_COMP7 0xE0002024
  52. #define DWT_CTRL 0xE0001000
  53. /* DCB_DHCSR bit and field definitions */
  54. #define DBGKEY (0xA05F<<16)
  55. #define C_DEBUGEN (1<<0)
  56. #define C_HALT (1<<1)
  57. #define C_STEP (1<<2)
  58. #define C_MASKINTS (1<<3)
  59. #define S_REGRDY (1<<16)
  60. #define S_HALT (1<<17)
  61. #define S_SLEEP (1<<18)
  62. #define S_LOCKUP (1<<19)
  63. #define S_RETIRE_ST (1<<24)
  64. #define S_RESET_ST (1<<25)
  65. /* DCB_DEMCR bit and field definitions */
  66. #define TRCENA (1<<24)
  67. #define VC_HARDERR (1<<10)
  68. #define VC_BUSERR (1<<8)
  69. #define VC_CORERESET (1<<0)
  70. #define NVIC_ICTR 0xE000E004
  71. #define NVIC_ISE0 0xE000E100
  72. #define NVIC_ICSR 0xE000ED04
  73. #define NVIC_AIRCR 0xE000ED0C
  74. #define NVIC_SHCSR 0xE000ED24
  75. #define NVIC_CFSR 0xE000ED28
  76. #define NVIC_MMFSRb 0xE000ED28
  77. #define NVIC_BFSRb 0xE000ED29
  78. #define NVIC_USFSRh 0xE000ED2A
  79. #define NVIC_HFSR 0xE000ED2C
  80. #define NVIC_DFSR 0xE000ED30
  81. #define NVIC_MMFAR 0xE000ED34
  82. #define NVIC_BFAR 0xE000ED38
  83. /* NVIC_AIRCR bits */
  84. #define AIRCR_VECTKEY (0x5FA<<16)
  85. #define AIRCR_SYSRESETREQ (1<<2)
  86. #define AIRCR_VECTCLRACTIVE (1<<1)
  87. #define AIRCR_VECTRESET (1<<0)
  88. /* NVIC_SHCSR bits */
  89. #define SHCSR_BUSFAULTENA (1<<17)
  90. /* NVIC_DFSR bits */
  91. #define DFSR_HALTED 1
  92. #define DFSR_BKPT 2
  93. #define DFSR_DWTTRAP 4
  94. #define DFSR_VCATCH 8
  95. #define FPCR_CODE 0
  96. #define FPCR_LITERAL 1
  97. #define FPCR_REPLACE_REMAP (0<<30)
  98. #define FPCR_REPLACE_BKPT_LOW (1<<30)
  99. #define FPCR_REPLACE_BKPT_HIGH (2<<30)
  100. #define FPCR_REPLACE_BKPT_BOTH (3<<30)
  101. typedef struct cortex_m3_fp_comparator_s
  102. {
  103. int used;
  104. int type;
  105. u32 fpcr_value;
  106. u32 fpcr_address;
  107. } cortex_m3_fp_comparator_t;
  108. typedef struct cortex_m3_dwt_comparator_s
  109. {
  110. int used;
  111. u32 comp;
  112. u32 mask;
  113. u32 function;
  114. u32 dwt_comparator_address;
  115. } cortex_m3_dwt_comparator_t;
  116. typedef struct cortex_m3_common_s
  117. {
  118. int common_magic;
  119. // int (*full_context)(struct target_s *target);
  120. arm_jtag_t jtag_info;
  121. /* Context information */
  122. u32 dcb_dhcsr;
  123. u32 nvic_dfsr; /* Debug Fault Status Register - shows reason for debug halt */
  124. u32 nvic_icsr; /* Interrupt Control State Register - shows active and pending IRQ */
  125. /* Flash Patch and Breakpoint */
  126. int fp_num_lit;
  127. int fp_num_code;
  128. int fp_code_available;
  129. int auto_bp_type;
  130. cortex_m3_fp_comparator_t *fp_comparator_list;
  131. /* DWT */
  132. int dwt_num_comp;
  133. int dwt_comp_available;
  134. cortex_m3_dwt_comparator_t *dwt_comparator_list;
  135. /* Interrupts */
  136. int intlinesnum;
  137. u32 *intsetenable;
  138. /*
  139. u32 arm_bkpt;
  140. u16 thumb_bkpt;
  141. int sw_bkpts_use_wp;
  142. int wp_available;
  143. int wp0_used;
  144. int wp1_used;
  145. int force_hw_bkpts;
  146. int dbgreq_adjust_pc;
  147. int use_dbgrq;
  148. int has_etm;
  149. int reinit_embeddedice;
  150. struct working_area_s *dcc_working_area;
  151. int fast_memory_access;
  152. int dcc_downloads;
  153. */
  154. /* breakpoint use map */
  155. int sw_bkpts_enabled;
  156. armv7m_common_t armv7m;
  157. swjdp_common_t swjdp_info;
  158. void *arch_info;
  159. } cortex_m3_common_t;
  160. extern void cortex_m3_build_reg_cache(target_t *target);
  161. enum target_state cortex_m3_poll(target_t *target);
  162. int cortex_m3_halt(target_t *target);
  163. int cortex_m3_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution);
  164. int cortex_m3_step(struct target_s *target, int current, u32 address, int handle_breakpoints);
  165. int cortex_m3_assert_reset(target_t *target);
  166. int cortex_m3_deassert_reset(target_t *target);
  167. int cortex_m3_soft_reset_halt(struct target_s *target);
  168. int cortex_m3_prepare_reset_halt(struct target_s *target);
  169. int cortex_m3_read_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
  170. int cortex_m3_write_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
  171. int cortex_m3_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffer);
  172. int cortex_m3_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint);
  173. int cortex_m3_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint);
  174. int cortex_m3_add_breakpoint(struct target_s *target, breakpoint_t *breakpoint);
  175. int cortex_m3_remove_breakpoint(struct target_s *target, breakpoint_t *breakpoint);
  176. int cortex_m3_add_watchpoint(struct target_s *target, watchpoint_t *watchpoint);
  177. int cortex_m3_remove_watchpoint(struct target_s *target, watchpoint_t *watchpoint);
  178. extern int cortex_m3_register_commands(struct command_context_s *cmd_ctx);
  179. extern int cortex_m3_init_arch_info(target_t *target, cortex_m3_common_t *cortex_m3, int chain_pos, char *variant);
  180. #endif /* CORTEX_M3_H */