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.
 
 
 
 
 
 

390 lines
14 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2009 by Paulius Zaleckas *
  3. * paulius.zaleckas@gmail.com *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  19. ***************************************************************************/
  20. /*
  21. * FA526 is very similar to ARM920T with following differences:
  22. *
  23. * - execution pipeline is 6 steps
  24. * - Unified TLB
  25. * - has Branch Target Buffer
  26. * - does not support reading of I/D cache contents
  27. */
  28. #ifdef HAVE_CONFIG_H
  29. #include "config.h"
  30. #endif
  31. #include "arm920t.h"
  32. #include "target_type.h"
  33. #include "arm_opcodes.h"
  34. static void fa526_change_to_arm(struct target *target, uint32_t *r0, uint32_t *pc)
  35. {
  36. LOG_ERROR("%s: there is no Thumb state on FA526", __func__);
  37. }
  38. static void fa526_read_core_regs(struct target *target,
  39. uint32_t mask, uint32_t *core_regs[16])
  40. {
  41. int i;
  42. struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
  43. struct arm_jtag *jtag_info = &arm7_9->jtag_info;
  44. /* STMIA r0-15, [r0] at debug speed
  45. * register values will start to appear on 4th DCLK
  46. */
  47. arm9tdmi_clock_out(jtag_info, ARMV4_5_STMIA(0, mask & 0xffff, 0, 0), 0, NULL, 0);
  48. /* fetch NOP, STM in DECODE stage */
  49. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  50. /* fetch NOP, STM in SHIFT stage */
  51. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  52. /* fetch NOP, STM in EXECUTE stage (1st cycle) */
  53. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  54. for (i = 0; i <= 15; i++) {
  55. if (mask & (1 << i))
  56. /* nothing fetched, STM in MEMORY (i'th cycle) */
  57. arm9tdmi_clock_data_in(jtag_info, core_regs[i]);
  58. }
  59. }
  60. static void fa526_read_core_regs_target_buffer(struct target *target,
  61. uint32_t mask, void *buffer, int size)
  62. {
  63. int i;
  64. struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
  65. struct arm_jtag *jtag_info = &arm7_9->jtag_info;
  66. int be = (target->endianness == TARGET_BIG_ENDIAN) ? 1 : 0;
  67. uint32_t *buf_u32 = buffer;
  68. uint16_t *buf_u16 = buffer;
  69. uint8_t *buf_u8 = buffer;
  70. /* STMIA r0-15, [r0] at debug speed
  71. * register values will start to appear on 4th DCLK
  72. */
  73. arm9tdmi_clock_out(jtag_info, ARMV4_5_STMIA(0, mask & 0xffff, 0, 0), 0, NULL, 0);
  74. /* fetch NOP, STM in DECODE stage */
  75. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  76. /* fetch NOP, STM in SHIFT stage */
  77. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  78. /* fetch NOP, STM in EXECUTE stage (1st cycle) */
  79. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  80. for (i = 0; i <= 15; i++) {
  81. if (mask & (1 << i))
  82. /* nothing fetched, STM in MEMORY (i'th cycle) */
  83. switch (size) {
  84. case 4:
  85. arm9tdmi_clock_data_in_endianness(jtag_info, buf_u32++, 4, be);
  86. break;
  87. case 2:
  88. arm9tdmi_clock_data_in_endianness(jtag_info, buf_u16++, 2, be);
  89. break;
  90. case 1:
  91. arm9tdmi_clock_data_in_endianness(jtag_info, buf_u8++, 1, be);
  92. break;
  93. }
  94. }
  95. }
  96. static void fa526_read_xpsr(struct target *target, uint32_t *xpsr, int spsr)
  97. {
  98. struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
  99. struct arm_jtag *jtag_info = &arm7_9->jtag_info;
  100. /* MRS r0, cpsr */
  101. arm9tdmi_clock_out(jtag_info, ARMV4_5_MRS(0, spsr & 1), 0, NULL, 0);
  102. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  103. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  104. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  105. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  106. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  107. /* STR r0, [r15] */
  108. arm9tdmi_clock_out(jtag_info, ARMV4_5_STR(0, 15), 0, NULL, 0);
  109. /* fetch NOP, STR in DECODE stage */
  110. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  111. /* fetch NOP, STR in SHIFT stage */
  112. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  113. /* fetch NOP, STR in EXECUTE stage (1st cycle) */
  114. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  115. /* nothing fetched, STR in MEMORY */
  116. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, xpsr, 0);
  117. }
  118. static void fa526_write_xpsr(struct target *target, uint32_t xpsr, int spsr)
  119. {
  120. struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
  121. struct arm_jtag *jtag_info = &arm7_9->jtag_info;
  122. LOG_DEBUG("xpsr: %8.8" PRIx32 ", spsr: %i", xpsr, spsr);
  123. /* MSR1 fetched */
  124. arm9tdmi_clock_out(jtag_info, ARMV4_5_MSR_IM(xpsr & 0xff, 0, 1, spsr), 0, NULL, 0);
  125. /* MSR2 fetched, MSR1 in DECODE */
  126. arm9tdmi_clock_out(jtag_info, ARMV4_5_MSR_IM((xpsr & 0xff00) >> 8, 0xc, 2, spsr), 0, NULL, 0);
  127. /* MSR3 fetched, MSR1 in SHIFT, MSR2 in DECODE */
  128. arm9tdmi_clock_out(jtag_info, ARMV4_5_MSR_IM((xpsr & 0xff0000) >> 16, 0x8, 4, spsr), 0, NULL, 0);
  129. /* MSR4 fetched, MSR1 in EXECUTE (1), MSR2 in SHIFT, MSR3 in DECODE */
  130. arm9tdmi_clock_out(jtag_info, ARMV4_5_MSR_IM((xpsr & 0xff000000) >> 24, 0x4, 8, spsr), 0, NULL, 0);
  131. /* nothing fetched, MSR1 in EXECUTE (2) */
  132. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  133. /* nothing fetched, MSR1 in EXECUTE (3) */
  134. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  135. /* nothing fetched, MSR2 in EXECUTE (1), MSR3 in SHIFT, MSR4 in DECODE */
  136. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  137. /* nothing fetched, MSR2 in EXECUTE (2) */
  138. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  139. /* nothing fetched, MSR2 in EXECUTE (3) */
  140. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  141. /* NOP fetched, MSR3 in EXECUTE (1), MSR4 in SHIFT */
  142. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  143. /* nothing fetched, MSR3 in EXECUTE (2) */
  144. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  145. /* nothing fetched, MSR3 in EXECUTE (3) */
  146. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  147. /* NOP fetched, MSR4 in EXECUTE (1) */
  148. /* last MSR writes flags, which takes only one cycle */
  149. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  150. }
  151. static void fa526_write_xpsr_im8(struct target *target,
  152. uint8_t xpsr_im, int rot, int spsr)
  153. {
  154. struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
  155. struct arm_jtag *jtag_info = &arm7_9->jtag_info;
  156. LOG_DEBUG("xpsr_im: %2.2x, rot: %i, spsr: %i", xpsr_im, rot, spsr);
  157. /* MSR fetched */
  158. arm9tdmi_clock_out(jtag_info, ARMV4_5_MSR_IM(xpsr_im, rot, 1, spsr), 0, NULL, 0);
  159. /* NOP fetched, MSR in DECODE */
  160. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  161. /* NOP fetched, MSR in SHIFT */
  162. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  163. /* NOP fetched, MSR in EXECUTE (1) */
  164. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  165. /* rot == 4 writes flags, which takes only one cycle */
  166. if (rot != 4) {
  167. /* nothing fetched, MSR in EXECUTE (2) */
  168. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  169. /* nothing fetched, MSR in EXECUTE (3) */
  170. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  171. }
  172. }
  173. static void fa526_write_core_regs(struct target *target,
  174. uint32_t mask, uint32_t core_regs[16])
  175. {
  176. int i;
  177. struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
  178. struct arm_jtag *jtag_info = &arm7_9->jtag_info;
  179. /* LDMIA r0-15, [r0] at debug speed
  180. * register values will start to appear on 4th DCLK
  181. */
  182. arm9tdmi_clock_out(jtag_info, ARMV4_5_LDMIA(0, mask & 0xffff, 0, 0), 0, NULL, 0);
  183. /* fetch NOP, LDM in DECODE stage */
  184. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  185. /* fetch NOP, LDM in SHIFT stage */
  186. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  187. /* fetch NOP, LDM in EXECUTE stage (1st cycle) */
  188. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  189. for (i = 0; i <= 15; i++) {
  190. if (mask & (1 << i))
  191. /* nothing fetched, LDM still in EXECUTE (1 + i cycle) */
  192. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, core_regs[i], NULL, 0);
  193. }
  194. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  195. }
  196. static void fa526_write_pc(struct target *target, uint32_t pc)
  197. {
  198. struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
  199. struct arm_jtag *jtag_info = &arm7_9->jtag_info;
  200. /* LDMIA r0-15, [r0] at debug speed
  201. * register values will start to appear on 4th DCLK
  202. */
  203. arm9tdmi_clock_out(jtag_info, ARMV4_5_LDMIA(0, 0x8000, 0, 0), 0, NULL, 0);
  204. /* fetch NOP, LDM in DECODE stage */
  205. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  206. /* fetch NOP, LDM in SHIFT stage */
  207. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  208. /* fetch NOP, LDM in EXECUTE stage (1st cycle) */
  209. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  210. /* nothing fetched, LDM in EXECUTE stage (2nd cycle) (output data) */
  211. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, pc, NULL, 0);
  212. /* nothing fetched, LDM in EXECUTE stage (3rd cycle) */
  213. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  214. /* fetch NOP, LDM in EXECUTE stage (4th cycle) */
  215. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  216. /* fetch NOP, LDM in EXECUTE stage (5th cycle) */
  217. arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 0);
  218. }
  219. static void fa526_branch_resume_thumb(struct target *target)
  220. {
  221. LOG_ERROR("%s: there is no Thumb state on FA526", __func__);
  222. }
  223. static int fa526_init_arch_info_2(struct target *target,
  224. struct arm7_9_common *arm7_9, struct jtag_tap *tap)
  225. {
  226. /* prepare JTAG information for the new target */
  227. arm7_9->jtag_info.tap = tap;
  228. arm7_9->jtag_info.scann_size = 5;
  229. /* register arch-specific functions */
  230. arm7_9->examine_debug_reason = arm9tdmi_examine_debug_reason;
  231. arm7_9->change_to_arm = fa526_change_to_arm;
  232. arm7_9->read_core_regs = fa526_read_core_regs;
  233. arm7_9->read_core_regs_target_buffer = fa526_read_core_regs_target_buffer;
  234. arm7_9->read_xpsr = fa526_read_xpsr;
  235. arm7_9->write_xpsr = fa526_write_xpsr;
  236. arm7_9->write_xpsr_im8 = fa526_write_xpsr_im8;
  237. arm7_9->write_core_regs = fa526_write_core_regs;
  238. arm7_9->load_word_regs = arm9tdmi_load_word_regs;
  239. arm7_9->load_hword_reg = arm9tdmi_load_hword_reg;
  240. arm7_9->load_byte_reg = arm9tdmi_load_byte_reg;
  241. arm7_9->store_word_regs = arm9tdmi_store_word_regs;
  242. arm7_9->store_hword_reg = arm9tdmi_store_hword_reg;
  243. arm7_9->store_byte_reg = arm9tdmi_store_byte_reg;
  244. arm7_9->write_pc = fa526_write_pc;
  245. arm7_9->branch_resume = arm9tdmi_branch_resume;
  246. arm7_9->branch_resume_thumb = fa526_branch_resume_thumb;
  247. arm7_9->enable_single_step = arm9tdmi_enable_single_step;
  248. arm7_9->disable_single_step = arm9tdmi_disable_single_step;
  249. arm7_9->write_memory = arm920t_write_memory;
  250. arm7_9->bulk_write_memory = arm7_9_bulk_write_memory;
  251. arm7_9->post_debug_entry = NULL;
  252. arm7_9->pre_restore_context = NULL;
  253. /* initialize arch-specific breakpoint handling */
  254. arm7_9->arm_bkpt = 0xdeeedeee;
  255. arm7_9->thumb_bkpt = 0xdeee;
  256. arm7_9->dbgreq_adjust_pc = 3;
  257. arm7_9_init_arch_info(target, arm7_9);
  258. /* override use of DBGRQ, this is safe on ARM9TDMI */
  259. arm7_9->use_dbgrq = 1;
  260. /* all ARM9s have the vector catch register */
  261. arm7_9->has_vector_catch = 1;
  262. return ERROR_OK;
  263. }
  264. static int fa526_init_arch_info(struct target *target,
  265. struct arm920t_common *arm920t, struct jtag_tap *tap)
  266. {
  267. struct arm7_9_common *arm7_9 = &arm920t->arm7_9_common;
  268. /* initialize arm7/arm9 specific info (including armv4_5) */
  269. fa526_init_arch_info_2(target, arm7_9, tap);
  270. arm920t->common_magic = ARM920T_COMMON_MAGIC;
  271. arm7_9->post_debug_entry = arm920t_post_debug_entry;
  272. arm7_9->pre_restore_context = arm920t_pre_restore_context;
  273. arm920t->armv4_5_mmu.armv4_5_cache.ctype = -1;
  274. arm920t->armv4_5_mmu.get_ttb = arm920t_get_ttb;
  275. arm920t->armv4_5_mmu.read_memory = arm7_9_read_memory;
  276. arm920t->armv4_5_mmu.write_memory = arm7_9_write_memory;
  277. arm920t->armv4_5_mmu.disable_mmu_caches = arm920t_disable_mmu_caches;
  278. arm920t->armv4_5_mmu.enable_mmu_caches = arm920t_enable_mmu_caches;
  279. arm920t->armv4_5_mmu.has_tiny_pages = 1;
  280. arm920t->armv4_5_mmu.mmu_enabled = 0;
  281. /* disabling linefills leads to lockups, so keep them enabled for now
  282. * this doesn't affect correctness, but might affect timing issues, if
  283. * important data is evicted from the cache during the debug session
  284. * */
  285. arm920t->preserve_cache = 0;
  286. /* override hw single-step capability from ARM9TDMI */
  287. arm7_9->has_single_step = 1;
  288. return ERROR_OK;
  289. }
  290. static int fa526_target_create(struct target *target, Jim_Interp *interp)
  291. {
  292. struct arm920t_common *arm920t = calloc(1, sizeof(struct arm920t_common));
  293. return fa526_init_arch_info(target, arm920t, target->tap);
  294. }
  295. /** Holds methods for FA526 targets. */
  296. struct target_type fa526_target = {
  297. .name = "fa526",
  298. .poll = arm7_9_poll,
  299. .arch_state = arm920t_arch_state,
  300. .target_request_data = arm7_9_target_request_data,
  301. .halt = arm7_9_halt,
  302. .resume = arm7_9_resume,
  303. .step = arm7_9_step,
  304. .assert_reset = arm7_9_assert_reset,
  305. .deassert_reset = arm7_9_deassert_reset,
  306. .soft_reset_halt = arm920t_soft_reset_halt,
  307. .get_gdb_reg_list = arm_get_gdb_reg_list,
  308. .read_memory = arm920t_read_memory,
  309. .write_memory = arm7_9_write_memory_opt,
  310. .checksum_memory = arm_checksum_memory,
  311. .blank_check_memory = arm_blank_check_memory,
  312. .run_algorithm = armv4_5_run_algorithm,
  313. .add_breakpoint = arm7_9_add_breakpoint,
  314. .remove_breakpoint = arm7_9_remove_breakpoint,
  315. .add_watchpoint = arm7_9_add_watchpoint,
  316. .remove_watchpoint = arm7_9_remove_watchpoint,
  317. .commands = arm920t_command_handlers,
  318. .target_create = fa526_target_create,
  319. .init_target = arm9tdmi_init_target,
  320. .examine = arm7_9_examine,
  321. .check_reset = arm7_9_check_reset,
  322. };