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.
 
 
 
 
 
 

1855 lines
48 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  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. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "etm.h"
  24. #include "etb.h"
  25. #include "image.h"
  26. #include "arm7_9_common.h"
  27. #include "arm_disassembler.h"
  28. /* ETM register access functionality
  29. *
  30. */
  31. #if 0
  32. static bitfield_desc_t etm_comms_ctrl_bitfield_desc[] =
  33. {
  34. {"R", 1},
  35. {"W", 1},
  36. {"reserved", 26},
  37. {"version", 4}
  38. };
  39. #endif
  40. static int etm_reg_arch_info[] =
  41. {
  42. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  43. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  45. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  46. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  47. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  48. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  49. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  50. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  51. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  52. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  53. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  54. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x67,
  55. 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  56. };
  57. static int etm_reg_arch_size_info[] =
  58. {
  59. 32, 32, 17, 8, 3, 9, 32, 16,
  60. 17, 26, 25, 8, 17, 32, 32, 17,
  61. 32, 32, 32, 32, 32, 32, 32, 32,
  62. 32, 32, 32, 32, 32, 32, 32, 32,
  63. 7, 7, 7, 7, 7, 7, 7, 7,
  64. 7, 7, 7, 7, 7, 7, 7, 7,
  65. 32, 32, 32, 32, 32, 32, 32, 32,
  66. 32, 32, 32, 32, 32, 32, 32, 32,
  67. 32, 32, 32, 32, 32, 32, 32, 32,
  68. 32, 32, 32, 32, 32, 32, 32, 32,
  69. 16, 16, 16, 16, 18, 18, 18, 18,
  70. 17, 17, 17, 17, 16, 16, 16, 16,
  71. 17, 17, 17, 17, 17, 17, 2,
  72. 17, 17, 17, 17, 32, 32, 32, 32
  73. };
  74. static char* etm_reg_list[] =
  75. {
  76. "ETM_CTRL",
  77. "ETM_CONFIG",
  78. "ETM_TRIG_EVENT",
  79. "ETM_MMD_CTRL",
  80. "ETM_STATUS",
  81. "ETM_SYS_CONFIG",
  82. "ETM_TRACE_RESOURCE_CTRL",
  83. "ETM_TRACE_EN_CTRL2",
  84. "ETM_TRACE_EN_EVENT",
  85. "ETM_TRACE_EN_CTRL1",
  86. "ETM_FIFOFULL_REGION",
  87. "ETM_FIFOFULL_LEVEL",
  88. "ETM_VIEWDATA_EVENT",
  89. "ETM_VIEWDATA_CTRL1",
  90. "ETM_VIEWDATA_CTRL2",
  91. "ETM_VIEWDATA_CTRL3",
  92. "ETM_ADDR_COMPARATOR_VALUE1",
  93. "ETM_ADDR_COMPARATOR_VALUE2",
  94. "ETM_ADDR_COMPARATOR_VALUE3",
  95. "ETM_ADDR_COMPARATOR_VALUE4",
  96. "ETM_ADDR_COMPARATOR_VALUE5",
  97. "ETM_ADDR_COMPARATOR_VALUE6",
  98. "ETM_ADDR_COMPARATOR_VALUE7",
  99. "ETM_ADDR_COMPARATOR_VALUE8",
  100. "ETM_ADDR_COMPARATOR_VALUE9",
  101. "ETM_ADDR_COMPARATOR_VALUE10",
  102. "ETM_ADDR_COMPARATOR_VALUE11",
  103. "ETM_ADDR_COMPARATOR_VALUE12",
  104. "ETM_ADDR_COMPARATOR_VALUE13",
  105. "ETM_ADDR_COMPARATOR_VALUE14",
  106. "ETM_ADDR_COMPARATOR_VALUE15",
  107. "ETM_ADDR_COMPARATOR_VALUE16",
  108. "ETM_ADDR_ACCESS_TYPE1",
  109. "ETM_ADDR_ACCESS_TYPE2",
  110. "ETM_ADDR_ACCESS_TYPE3",
  111. "ETM_ADDR_ACCESS_TYPE4",
  112. "ETM_ADDR_ACCESS_TYPE5",
  113. "ETM_ADDR_ACCESS_TYPE6",
  114. "ETM_ADDR_ACCESS_TYPE7",
  115. "ETM_ADDR_ACCESS_TYPE8",
  116. "ETM_ADDR_ACCESS_TYPE9",
  117. "ETM_ADDR_ACCESS_TYPE10",
  118. "ETM_ADDR_ACCESS_TYPE11",
  119. "ETM_ADDR_ACCESS_TYPE12",
  120. "ETM_ADDR_ACCESS_TYPE13",
  121. "ETM_ADDR_ACCESS_TYPE14",
  122. "ETM_ADDR_ACCESS_TYPE15",
  123. "ETM_ADDR_ACCESS_TYPE16",
  124. "ETM_DATA_COMPARATOR_VALUE1",
  125. "ETM_DATA_COMPARATOR_VALUE2",
  126. "ETM_DATA_COMPARATOR_VALUE3",
  127. "ETM_DATA_COMPARATOR_VALUE4",
  128. "ETM_DATA_COMPARATOR_VALUE5",
  129. "ETM_DATA_COMPARATOR_VALUE6",
  130. "ETM_DATA_COMPARATOR_VALUE7",
  131. "ETM_DATA_COMPARATOR_VALUE8",
  132. "ETM_DATA_COMPARATOR_VALUE9",
  133. "ETM_DATA_COMPARATOR_VALUE10",
  134. "ETM_DATA_COMPARATOR_VALUE11",
  135. "ETM_DATA_COMPARATOR_VALUE12",
  136. "ETM_DATA_COMPARATOR_VALUE13",
  137. "ETM_DATA_COMPARATOR_VALUE14",
  138. "ETM_DATA_COMPARATOR_VALUE15",
  139. "ETM_DATA_COMPARATOR_VALUE16",
  140. "ETM_DATA_COMPARATOR_MASK1",
  141. "ETM_DATA_COMPARATOR_MASK2",
  142. "ETM_DATA_COMPARATOR_MASK3",
  143. "ETM_DATA_COMPARATOR_MASK4",
  144. "ETM_DATA_COMPARATOR_MASK5",
  145. "ETM_DATA_COMPARATOR_MASK6",
  146. "ETM_DATA_COMPARATOR_MASK7",
  147. "ETM_DATA_COMPARATOR_MASK8",
  148. "ETM_DATA_COMPARATOR_MASK9",
  149. "ETM_DATA_COMPARATOR_MASK10",
  150. "ETM_DATA_COMPARATOR_MASK11",
  151. "ETM_DATA_COMPARATOR_MASK12",
  152. "ETM_DATA_COMPARATOR_MASK13",
  153. "ETM_DATA_COMPARATOR_MASK14",
  154. "ETM_DATA_COMPARATOR_MASK15",
  155. "ETM_DATA_COMPARATOR_MASK16",
  156. "ETM_COUNTER_INITAL_VALUE1",
  157. "ETM_COUNTER_INITAL_VALUE2",
  158. "ETM_COUNTER_INITAL_VALUE3",
  159. "ETM_COUNTER_INITAL_VALUE4",
  160. "ETM_COUNTER_ENABLE1",
  161. "ETM_COUNTER_ENABLE2",
  162. "ETM_COUNTER_ENABLE3",
  163. "ETM_COUNTER_ENABLE4",
  164. "ETM_COUNTER_RELOAD_VALUE1",
  165. "ETM_COUNTER_RELOAD_VALUE2",
  166. "ETM_COUNTER_RELOAD_VALUE3",
  167. "ETM_COUNTER_RELOAD_VALUE4",
  168. "ETM_COUNTER_VALUE1",
  169. "ETM_COUNTER_VALUE2",
  170. "ETM_COUNTER_VALUE3",
  171. "ETM_COUNTER_VALUE4",
  172. "ETM_SEQUENCER_CTRL1",
  173. "ETM_SEQUENCER_CTRL2",
  174. "ETM_SEQUENCER_CTRL3",
  175. "ETM_SEQUENCER_CTRL4",
  176. "ETM_SEQUENCER_CTRL5",
  177. "ETM_SEQUENCER_CTRL6",
  178. "ETM_SEQUENCER_STATE",
  179. "ETM_EXTERNAL_OUTPUT1",
  180. "ETM_EXTERNAL_OUTPUT2",
  181. "ETM_EXTERNAL_OUTPUT3",
  182. "ETM_EXTERNAL_OUTPUT4",
  183. "ETM_CONTEXTID_COMPARATOR_VALUE1",
  184. "ETM_CONTEXTID_COMPARATOR_VALUE2",
  185. "ETM_CONTEXTID_COMPARATOR_VALUE3",
  186. "ETM_CONTEXTID_COMPARATOR_MASK"
  187. };
  188. static int etm_reg_arch_type = -1;
  189. static int etm_get_reg(reg_t *reg);
  190. static command_t *etm_cmd = NULL;
  191. reg_cache_t* etm_build_reg_cache(target_t *target, arm_jtag_t *jtag_info, etm_context_t *etm_ctx)
  192. {
  193. reg_cache_t *reg_cache = malloc(sizeof(reg_cache_t));
  194. reg_t *reg_list = NULL;
  195. etm_reg_t *arch_info = NULL;
  196. int num_regs = sizeof(etm_reg_arch_info)/sizeof(int);
  197. int i;
  198. /* register a register arch-type for etm registers only once */
  199. if (etm_reg_arch_type == -1)
  200. etm_reg_arch_type = register_reg_arch_type(etm_get_reg, etm_set_reg_w_exec);
  201. /* the actual registers are kept in two arrays */
  202. reg_list = calloc(num_regs, sizeof(reg_t));
  203. arch_info = calloc(num_regs, sizeof(etm_reg_t));
  204. /* fill in values for the reg cache */
  205. reg_cache->name = "etm registers";
  206. reg_cache->next = NULL;
  207. reg_cache->reg_list = reg_list;
  208. reg_cache->num_regs = num_regs;
  209. /* set up registers */
  210. for (i = 0; i < num_regs; i++)
  211. {
  212. reg_list[i].name = etm_reg_list[i];
  213. reg_list[i].size = 32;
  214. reg_list[i].dirty = 0;
  215. reg_list[i].valid = 0;
  216. reg_list[i].bitfield_desc = NULL;
  217. reg_list[i].num_bitfields = 0;
  218. reg_list[i].value = calloc(1, 4);
  219. reg_list[i].arch_info = &arch_info[i];
  220. reg_list[i].arch_type = etm_reg_arch_type;
  221. reg_list[i].size = etm_reg_arch_size_info[i];
  222. arch_info[i].addr = etm_reg_arch_info[i];
  223. arch_info[i].jtag_info = jtag_info;
  224. }
  225. /* the ETM might have an ETB connected */
  226. if (strcmp(etm_ctx->capture_driver->name, "etb") == 0)
  227. {
  228. etb_t *etb = etm_ctx->capture_driver_priv;
  229. if (!etb)
  230. {
  231. LOG_ERROR("etb selected as etm capture driver, but no ETB configured");
  232. return ERROR_OK;
  233. }
  234. reg_cache->next = etb_build_reg_cache(etb);
  235. etb->reg_cache = reg_cache->next;
  236. }
  237. return reg_cache;
  238. }
  239. int etm_setup(target_t *target)
  240. {
  241. int retval;
  242. u32 etm_ctrl_value;
  243. armv4_5_common_t *armv4_5 = target->arch_info;
  244. arm7_9_common_t *arm7_9 = armv4_5->arch_info;
  245. etm_context_t *etm_ctx = arm7_9->etm_ctx;
  246. reg_t *etm_ctrl_reg = &arm7_9->etm_ctx->reg_cache->reg_list[ETM_CTRL];
  247. /* initialize some ETM control register settings */
  248. etm_get_reg(etm_ctrl_reg);
  249. etm_ctrl_value = buf_get_u32(etm_ctrl_reg->value, 0, etm_ctrl_reg->size);
  250. /* clear the ETM powerdown bit (0) */
  251. etm_ctrl_value &= ~0x1;
  252. /* configure port width (6:4), mode (17:16) and clocking (13) */
  253. etm_ctrl_value = (etm_ctrl_value &
  254. ~ETM_PORT_WIDTH_MASK & ~ETM_PORT_MODE_MASK & ~ETM_PORT_CLOCK_MASK)
  255. | etm_ctx->portmode;
  256. buf_set_u32(etm_ctrl_reg->value, 0, etm_ctrl_reg->size, etm_ctrl_value);
  257. etm_store_reg(etm_ctrl_reg);
  258. if ((retval=jtag_execute_queue())!=ERROR_OK)
  259. return retval;
  260. if ((retval=etm_ctx->capture_driver->init(etm_ctx)) != ERROR_OK)
  261. {
  262. LOG_ERROR("ETM capture driver initialization failed");
  263. return retval;
  264. }
  265. return ERROR_OK;
  266. }
  267. int etm_get_reg(reg_t *reg)
  268. {
  269. int retval;
  270. if ((retval = etm_read_reg(reg)) != ERROR_OK)
  271. {
  272. LOG_ERROR("BUG: error scheduling etm register read");
  273. return retval;
  274. }
  275. if ((retval = jtag_execute_queue()) != ERROR_OK)
  276. {
  277. LOG_ERROR("register read failed");
  278. return retval;
  279. }
  280. return ERROR_OK;
  281. }
  282. int etm_read_reg_w_check(reg_t *reg, u8* check_value, u8* check_mask)
  283. {
  284. etm_reg_t *etm_reg = reg->arch_info;
  285. u8 reg_addr = etm_reg->addr & 0x7f;
  286. scan_field_t fields[3];
  287. LOG_DEBUG("%i", etm_reg->addr);
  288. jtag_set_end_state(TAP_IDLE);
  289. arm_jtag_scann(etm_reg->jtag_info, 0x6);
  290. arm_jtag_set_instr(etm_reg->jtag_info, etm_reg->jtag_info->intest_instr, NULL);
  291. fields[0].tap = etm_reg->jtag_info->tap;
  292. fields[0].num_bits = 32;
  293. fields[0].out_value = reg->value;
  294. fields[0].in_value = NULL;
  295. fields[0].check_value = NULL;
  296. fields[0].check_mask = NULL;
  297. fields[1].tap = etm_reg->jtag_info->tap;
  298. fields[1].num_bits = 7;
  299. fields[1].out_value = malloc(1);
  300. buf_set_u32(fields[1].out_value, 0, 7, reg_addr);
  301. fields[1].in_value = NULL;
  302. fields[1].check_value = NULL;
  303. fields[1].check_mask = NULL;
  304. fields[2].tap = etm_reg->jtag_info->tap;
  305. fields[2].num_bits = 1;
  306. fields[2].out_value = malloc(1);
  307. buf_set_u32(fields[2].out_value, 0, 1, 0);
  308. fields[2].in_value = NULL;
  309. fields[2].check_value = NULL;
  310. fields[2].check_mask = NULL;
  311. jtag_add_dr_scan(3, fields, jtag_get_end_state());
  312. fields[0].in_value = reg->value;
  313. fields[0].check_value = check_value;
  314. fields[0].check_mask = check_mask;
  315. jtag_add_dr_scan_check(3, fields, jtag_get_end_state());
  316. free(fields[1].out_value);
  317. free(fields[2].out_value);
  318. return ERROR_OK;
  319. }
  320. int etm_read_reg(reg_t *reg)
  321. {
  322. return etm_read_reg_w_check(reg, NULL, NULL);
  323. }
  324. int etm_set_reg(reg_t *reg, u32 value)
  325. {
  326. int retval;
  327. if ((retval = etm_write_reg(reg, value)) != ERROR_OK)
  328. {
  329. LOG_ERROR("BUG: error scheduling etm register write");
  330. return retval;
  331. }
  332. buf_set_u32(reg->value, 0, reg->size, value);
  333. reg->valid = 1;
  334. reg->dirty = 0;
  335. return ERROR_OK;
  336. }
  337. int etm_set_reg_w_exec(reg_t *reg, u8 *buf)
  338. {
  339. int retval;
  340. etm_set_reg(reg, buf_get_u32(buf, 0, reg->size));
  341. if ((retval = jtag_execute_queue()) != ERROR_OK)
  342. {
  343. LOG_ERROR("register write failed");
  344. return retval;
  345. }
  346. return ERROR_OK;
  347. }
  348. int etm_write_reg(reg_t *reg, u32 value)
  349. {
  350. etm_reg_t *etm_reg = reg->arch_info;
  351. u8 reg_addr = etm_reg->addr & 0x7f;
  352. scan_field_t fields[3];
  353. LOG_DEBUG("%i: 0x%8.8x", etm_reg->addr, value);
  354. jtag_set_end_state(TAP_IDLE);
  355. arm_jtag_scann(etm_reg->jtag_info, 0x6);
  356. arm_jtag_set_instr(etm_reg->jtag_info, etm_reg->jtag_info->intest_instr, NULL);
  357. fields[0].tap = etm_reg->jtag_info->tap;
  358. fields[0].num_bits = 32;
  359. u8 tmp1[4];
  360. fields[0].out_value = tmp1;
  361. buf_set_u32(fields[0].out_value, 0, 32, value);
  362. fields[0].in_value = NULL;
  363. fields[1].tap = etm_reg->jtag_info->tap;
  364. fields[1].num_bits = 7;
  365. u8 tmp2;
  366. fields[1].out_value = &tmp2;
  367. buf_set_u32(fields[1].out_value, 0, 7, reg_addr);
  368. fields[1].in_value = NULL;
  369. fields[2].tap = etm_reg->jtag_info->tap;
  370. fields[2].num_bits = 1;
  371. u8 tmp3;
  372. fields[2].out_value = &tmp3;
  373. buf_set_u32(fields[2].out_value, 0, 1, 1);
  374. fields[2].in_value = NULL;
  375. jtag_add_dr_scan(3, fields, jtag_get_end_state());
  376. return ERROR_OK;
  377. }
  378. int etm_store_reg(reg_t *reg)
  379. {
  380. return etm_write_reg(reg, buf_get_u32(reg->value, 0, reg->size));
  381. }
  382. /* ETM trace analysis functionality
  383. *
  384. */
  385. extern etm_capture_driver_t etm_dummy_capture_driver;
  386. #if BUILD_OOCD_TRACE == 1
  387. extern etm_capture_driver_t oocd_trace_capture_driver;
  388. #endif
  389. static etm_capture_driver_t *etm_capture_drivers[] =
  390. {
  391. &etb_capture_driver,
  392. &etm_dummy_capture_driver,
  393. #if BUILD_OOCD_TRACE == 1
  394. &oocd_trace_capture_driver,
  395. #endif
  396. NULL
  397. };
  398. char *etmv1v1_branch_reason_strings[] =
  399. {
  400. "normal PC change",
  401. "tracing enabled",
  402. "trace restarted after overflow",
  403. "exit from debug",
  404. "periodic synchronization",
  405. "reserved",
  406. "reserved",
  407. "reserved",
  408. };
  409. static int etm_read_instruction(etm_context_t *ctx, arm_instruction_t *instruction)
  410. {
  411. int i;
  412. int section = -1;
  413. u32 size_read;
  414. u32 opcode;
  415. int retval;
  416. if (!ctx->image)
  417. return ERROR_TRACE_IMAGE_UNAVAILABLE;
  418. /* search for the section the current instruction belongs to */
  419. for (i = 0; i < ctx->image->num_sections; i++)
  420. {
  421. if ((ctx->image->sections[i].base_address <= ctx->current_pc) &&
  422. (ctx->image->sections[i].base_address + ctx->image->sections[i].size > ctx->current_pc))
  423. {
  424. section = i;
  425. break;
  426. }
  427. }
  428. if (section == -1)
  429. {
  430. /* current instruction couldn't be found in the image */
  431. return ERROR_TRACE_INSTRUCTION_UNAVAILABLE;
  432. }
  433. if (ctx->core_state == ARMV4_5_STATE_ARM)
  434. {
  435. u8 buf[4];
  436. if ((retval = image_read_section(ctx->image, section,
  437. ctx->current_pc - ctx->image->sections[section].base_address,
  438. 4, buf, &size_read)) != ERROR_OK)
  439. {
  440. LOG_ERROR("error while reading instruction: %i", retval);
  441. return ERROR_TRACE_INSTRUCTION_UNAVAILABLE;
  442. }
  443. opcode = target_buffer_get_u32(ctx->target, buf);
  444. arm_evaluate_opcode(opcode, ctx->current_pc, instruction);
  445. }
  446. else if (ctx->core_state == ARMV4_5_STATE_THUMB)
  447. {
  448. u8 buf[2];
  449. if ((retval = image_read_section(ctx->image, section,
  450. ctx->current_pc - ctx->image->sections[section].base_address,
  451. 2, buf, &size_read)) != ERROR_OK)
  452. {
  453. LOG_ERROR("error while reading instruction: %i", retval);
  454. return ERROR_TRACE_INSTRUCTION_UNAVAILABLE;
  455. }
  456. opcode = target_buffer_get_u16(ctx->target, buf);
  457. thumb_evaluate_opcode(opcode, ctx->current_pc, instruction);
  458. }
  459. else if (ctx->core_state == ARMV4_5_STATE_JAZELLE)
  460. {
  461. LOG_ERROR("BUG: tracing of jazelle code not supported");
  462. exit(-1);
  463. }
  464. else
  465. {
  466. LOG_ERROR("BUG: unknown core state encountered");
  467. exit(-1);
  468. }
  469. return ERROR_OK;
  470. }
  471. static int etmv1_next_packet(etm_context_t *ctx, u8 *packet, int apo)
  472. {
  473. while (ctx->data_index < ctx->trace_depth)
  474. {
  475. /* if the caller specified an address packet offset, skip until the
  476. * we reach the n-th cycle marked with tracesync */
  477. if (apo > 0)
  478. {
  479. if (ctx->trace_data[ctx->data_index].flags & ETMV1_TRACESYNC_CYCLE)
  480. apo--;
  481. if (apo > 0)
  482. {
  483. ctx->data_index++;
  484. ctx->data_half = 0;
  485. }
  486. continue;
  487. }
  488. /* no tracedata output during a TD cycle
  489. * or in a trigger cycle */
  490. if ((ctx->trace_data[ctx->data_index].pipestat == STAT_TD)
  491. || (ctx->trace_data[ctx->data_index].flags & ETMV1_TRIGGER_CYCLE))
  492. {
  493. ctx->data_index++;
  494. ctx->data_half = 0;
  495. continue;
  496. }
  497. if ((ctx->portmode & ETM_PORT_WIDTH_MASK) == ETM_PORT_16BIT)
  498. {
  499. if (ctx->data_half == 0)
  500. {
  501. *packet = ctx->trace_data[ctx->data_index].packet & 0xff;
  502. ctx->data_half = 1;
  503. }
  504. else
  505. {
  506. *packet = (ctx->trace_data[ctx->data_index].packet & 0xff00) >> 8;
  507. ctx->data_half = 0;
  508. ctx->data_index++;
  509. }
  510. }
  511. else if ((ctx->portmode & ETM_PORT_WIDTH_MASK) == ETM_PORT_8BIT)
  512. {
  513. *packet = ctx->trace_data[ctx->data_index].packet & 0xff;
  514. ctx->data_index++;
  515. }
  516. else
  517. {
  518. /* on a 4-bit port, a packet will be output during two consecutive cycles */
  519. if (ctx->data_index > (ctx->trace_depth - 2))
  520. return -1;
  521. *packet = ctx->trace_data[ctx->data_index].packet & 0xf;
  522. *packet |= (ctx->trace_data[ctx->data_index + 1].packet & 0xf) << 4;
  523. ctx->data_index += 2;
  524. }
  525. return 0;
  526. }
  527. return -1;
  528. }
  529. static int etmv1_branch_address(etm_context_t *ctx)
  530. {
  531. int retval;
  532. u8 packet;
  533. int shift = 0;
  534. int apo;
  535. u32 i;
  536. /* quit analysis if less than two cycles are left in the trace
  537. * because we can't extract the APO */
  538. if (ctx->data_index > (ctx->trace_depth - 2))
  539. return -1;
  540. /* a BE could be output during an APO cycle, skip the current
  541. * and continue with the new one */
  542. if (ctx->trace_data[ctx->pipe_index + 1].pipestat & 0x4)
  543. return 1;
  544. if (ctx->trace_data[ctx->pipe_index + 2].pipestat & 0x4)
  545. return 2;
  546. /* address packet offset encoded in the next two cycles' pipestat bits */
  547. apo = ctx->trace_data[ctx->pipe_index + 1].pipestat & 0x3;
  548. apo |= (ctx->trace_data[ctx->pipe_index + 2].pipestat & 0x3) << 2;
  549. /* count number of tracesync cycles between current pipe_index and data_index
  550. * i.e. the number of tracesyncs that data_index already passed by
  551. * to subtract them from the APO */
  552. for (i = ctx->pipe_index; i < ctx->data_index; i++)
  553. {
  554. if (ctx->trace_data[ctx->pipe_index + 1].pipestat & ETMV1_TRACESYNC_CYCLE)
  555. apo--;
  556. }
  557. /* extract up to four 7-bit packets */
  558. do {
  559. if ((retval = etmv1_next_packet(ctx, &packet, (shift == 0) ? apo + 1 : 0)) != 0)
  560. return -1;
  561. ctx->last_branch &= ~(0x7f << shift);
  562. ctx->last_branch |= (packet & 0x7f) << shift;
  563. shift += 7;
  564. } while ((packet & 0x80) && (shift < 28));
  565. /* one last packet holding 4 bits of the address, plus the branch reason code */
  566. if ((shift == 28) && (packet & 0x80))
  567. {
  568. if ((retval = etmv1_next_packet(ctx, &packet, 0)) != 0)
  569. return -1;
  570. ctx->last_branch &= 0x0fffffff;
  571. ctx->last_branch |= (packet & 0x0f) << 28;
  572. ctx->last_branch_reason = (packet & 0x70) >> 4;
  573. shift += 4;
  574. }
  575. else
  576. {
  577. ctx->last_branch_reason = 0;
  578. }
  579. if (shift == 32)
  580. {
  581. ctx->pc_ok = 1;
  582. }
  583. /* if a full address was output, we might have branched into Jazelle state */
  584. if ((shift == 32) && (packet & 0x80))
  585. {
  586. ctx->core_state = ARMV4_5_STATE_JAZELLE;
  587. }
  588. else
  589. {
  590. /* if we didn't branch into Jazelle state, the current processor state is
  591. * encoded in bit 0 of the branch target address */
  592. if (ctx->last_branch & 0x1)
  593. {
  594. ctx->core_state = ARMV4_5_STATE_THUMB;
  595. ctx->last_branch &= ~0x1;
  596. }
  597. else
  598. {
  599. ctx->core_state = ARMV4_5_STATE_ARM;
  600. ctx->last_branch &= ~0x3;
  601. }
  602. }
  603. return 0;
  604. }
  605. static int etmv1_data(etm_context_t *ctx, int size, u32 *data)
  606. {
  607. int j;
  608. u8 buf[4];
  609. int retval;
  610. for (j = 0; j < size; j++)
  611. {
  612. if ((retval = etmv1_next_packet(ctx, &buf[j], 0)) != 0)
  613. return -1;
  614. }
  615. if (size == 8)
  616. {
  617. LOG_ERROR("TODO: add support for 64-bit values");
  618. return -1;
  619. }
  620. else if (size == 4)
  621. *data = target_buffer_get_u32(ctx->target, buf);
  622. else if (size == 2)
  623. *data = target_buffer_get_u16(ctx->target, buf);
  624. else if (size == 1)
  625. *data = buf[0];
  626. else
  627. return -1;
  628. return 0;
  629. }
  630. static int etmv1_analyze_trace(etm_context_t *ctx, struct command_context_s *cmd_ctx)
  631. {
  632. int retval;
  633. arm_instruction_t instruction;
  634. /* read the trace data if it wasn't read already */
  635. if (ctx->trace_depth == 0)
  636. ctx->capture_driver->read_trace(ctx);
  637. /* start at the beginning of the captured trace */
  638. ctx->pipe_index = 0;
  639. ctx->data_index = 0;
  640. ctx->data_half = 0;
  641. /* neither the PC nor the data pointer are valid */
  642. ctx->pc_ok = 0;
  643. ctx->ptr_ok = 0;
  644. while (ctx->pipe_index < ctx->trace_depth)
  645. {
  646. u8 pipestat = ctx->trace_data[ctx->pipe_index].pipestat;
  647. u32 next_pc = ctx->current_pc;
  648. u32 old_data_index = ctx->data_index;
  649. u32 old_data_half = ctx->data_half;
  650. u32 old_index = ctx->pipe_index;
  651. u32 last_instruction = ctx->last_instruction;
  652. u32 cycles = 0;
  653. int current_pc_ok = ctx->pc_ok;
  654. if (ctx->trace_data[ctx->pipe_index].flags & ETMV1_TRIGGER_CYCLE)
  655. {
  656. command_print(cmd_ctx, "--- trigger ---");
  657. }
  658. /* instructions execute in IE/D or BE/D cycles */
  659. if ((pipestat == STAT_IE) || (pipestat == STAT_ID))
  660. ctx->last_instruction = ctx->pipe_index;
  661. /* if we don't have a valid pc skip until we reach an indirect branch */
  662. if ((!ctx->pc_ok) && (pipestat != STAT_BE))
  663. {
  664. ctx->pipe_index++;
  665. continue;
  666. }
  667. /* any indirect branch could have interrupted instruction flow
  668. * - the branch reason code could indicate a trace discontinuity
  669. * - a branch to the exception vectors indicates an exception
  670. */
  671. if ((pipestat == STAT_BE) || (pipestat == STAT_BD))
  672. {
  673. /* backup current data index, to be able to consume the branch address
  674. * before examining data address and values
  675. */
  676. old_data_index = ctx->data_index;
  677. old_data_half = ctx->data_half;
  678. ctx->last_instruction = ctx->pipe_index;
  679. if ((retval = etmv1_branch_address(ctx)) != 0)
  680. {
  681. /* negative return value from etmv1_branch_address means we ran out of packets,
  682. * quit analysing the trace */
  683. if (retval < 0)
  684. break;
  685. /* a positive return values means the current branch was abandoned,
  686. * and a new branch was encountered in cycle ctx->pipe_index + retval;
  687. */
  688. LOG_WARNING("abandoned branch encountered, correctnes of analysis uncertain");
  689. ctx->pipe_index += retval;
  690. continue;
  691. }
  692. /* skip over APO cycles */
  693. ctx->pipe_index += 2;
  694. switch (ctx->last_branch_reason)
  695. {
  696. case 0x0: /* normal PC change */
  697. next_pc = ctx->last_branch;
  698. break;
  699. case 0x1: /* tracing enabled */
  700. command_print(cmd_ctx, "--- tracing enabled at 0x%8.8x ---", ctx->last_branch);
  701. ctx->current_pc = ctx->last_branch;
  702. ctx->pipe_index++;
  703. continue;
  704. break;
  705. case 0x2: /* trace restarted after FIFO overflow */
  706. command_print(cmd_ctx, "--- trace restarted after FIFO overflow at 0x%8.8x ---", ctx->last_branch);
  707. ctx->current_pc = ctx->last_branch;
  708. ctx->pipe_index++;
  709. continue;
  710. break;
  711. case 0x3: /* exit from debug state */
  712. command_print(cmd_ctx, "--- exit from debug state at 0x%8.8x ---", ctx->last_branch);
  713. ctx->current_pc = ctx->last_branch;
  714. ctx->pipe_index++;
  715. continue;
  716. break;
  717. case 0x4: /* periodic synchronization point */
  718. next_pc = ctx->last_branch;
  719. /* if we had no valid PC prior to this synchronization point,
  720. * we have to move on with the next trace cycle
  721. */
  722. if (!current_pc_ok)
  723. {
  724. command_print(cmd_ctx, "--- periodic synchronization point at 0x%8.8x ---", next_pc);
  725. ctx->current_pc = next_pc;
  726. ctx->pipe_index++;
  727. continue;
  728. }
  729. break;
  730. default: /* reserved */
  731. LOG_ERROR("BUG: branch reason code 0x%x is reserved", ctx->last_branch_reason);
  732. exit(-1);
  733. break;
  734. }
  735. /* if we got here the branch was a normal PC change
  736. * (or a periodic synchronization point, which means the same for that matter)
  737. * if we didn't accquire a complete PC continue with the next cycle
  738. */
  739. if (!ctx->pc_ok)
  740. continue;
  741. /* indirect branch to the exception vector means an exception occured */
  742. if ((ctx->last_branch <= 0x20)
  743. || ((ctx->last_branch >= 0xffff0000) && (ctx->last_branch <= 0xffff0020)))
  744. {
  745. if ((ctx->last_branch & 0xff) == 0x10)
  746. {
  747. command_print(cmd_ctx, "data abort");
  748. }
  749. else
  750. {
  751. command_print(cmd_ctx, "exception vector 0x%2.2x", ctx->last_branch);
  752. ctx->current_pc = ctx->last_branch;
  753. ctx->pipe_index++;
  754. continue;
  755. }
  756. }
  757. }
  758. /* an instruction was executed (or not, depending on the condition flags)
  759. * retrieve it from the image for displaying */
  760. if (ctx->pc_ok && (pipestat != STAT_WT) && (pipestat != STAT_TD) &&
  761. !(((pipestat == STAT_BE) || (pipestat == STAT_BD)) &&
  762. ((ctx->last_branch_reason != 0x0) && (ctx->last_branch_reason != 0x4))))
  763. {
  764. if ((retval = etm_read_instruction(ctx, &instruction)) != ERROR_OK)
  765. {
  766. /* can't continue tracing with no image available */
  767. if (retval == ERROR_TRACE_IMAGE_UNAVAILABLE)
  768. {
  769. return retval;
  770. }
  771. else if (retval == ERROR_TRACE_INSTRUCTION_UNAVAILABLE)
  772. {
  773. /* TODO: handle incomplete images
  774. * for now we just quit the analsysis*/
  775. return retval;
  776. }
  777. }
  778. cycles = old_index - last_instruction;
  779. }
  780. if ((pipestat == STAT_ID) || (pipestat == STAT_BD))
  781. {
  782. u32 new_data_index = ctx->data_index;
  783. u32 new_data_half = ctx->data_half;
  784. /* in case of a branch with data, the branch target address was consumed before
  785. * we temporarily go back to the saved data index */
  786. if (pipestat == STAT_BD)
  787. {
  788. ctx->data_index = old_data_index;
  789. ctx->data_half = old_data_half;
  790. }
  791. if (ctx->tracemode & ETMV1_TRACE_ADDR)
  792. {
  793. u8 packet;
  794. int shift = 0;
  795. do {
  796. if ((retval = etmv1_next_packet(ctx, &packet, 0)) != 0)
  797. return ERROR_ETM_ANALYSIS_FAILED;
  798. ctx->last_ptr &= ~(0x7f << shift);
  799. ctx->last_ptr |= (packet & 0x7f) << shift;
  800. shift += 7;
  801. } while ((packet & 0x80) && (shift < 32));
  802. if (shift >= 32)
  803. ctx->ptr_ok = 1;
  804. if (ctx->ptr_ok)
  805. {
  806. command_print(cmd_ctx, "address: 0x%8.8x", ctx->last_ptr);
  807. }
  808. }
  809. if (ctx->tracemode & ETMV1_TRACE_DATA)
  810. {
  811. if ((instruction.type == ARM_LDM) || (instruction.type == ARM_STM))
  812. {
  813. int i;
  814. for (i = 0; i < 16; i++)
  815. {
  816. if (instruction.info.load_store_multiple.register_list & (1 << i))
  817. {
  818. u32 data;
  819. if (etmv1_data(ctx, 4, &data) != 0)
  820. return ERROR_ETM_ANALYSIS_FAILED;
  821. command_print(cmd_ctx, "data: 0x%8.8x", data);
  822. }
  823. }
  824. }
  825. else if ((instruction.type >= ARM_LDR) && (instruction.type <= ARM_STRH))
  826. {
  827. u32 data;
  828. if (etmv1_data(ctx, arm_access_size(&instruction), &data) != 0)
  829. return ERROR_ETM_ANALYSIS_FAILED;
  830. command_print(cmd_ctx, "data: 0x%8.8x", data);
  831. }
  832. }
  833. /* restore data index after consuming BD address and data */
  834. if (pipestat == STAT_BD)
  835. {
  836. ctx->data_index = new_data_index;
  837. ctx->data_half = new_data_half;
  838. }
  839. }
  840. /* adjust PC */
  841. if ((pipestat == STAT_IE) || (pipestat == STAT_ID))
  842. {
  843. if (((instruction.type == ARM_B) ||
  844. (instruction.type == ARM_BL) ||
  845. (instruction.type == ARM_BLX)) &&
  846. (instruction.info.b_bl_bx_blx.target_address != 0xffffffff))
  847. {
  848. next_pc = instruction.info.b_bl_bx_blx.target_address;
  849. }
  850. else
  851. {
  852. next_pc += (ctx->core_state == ARMV4_5_STATE_ARM) ? 4 : 2;
  853. }
  854. }
  855. else if (pipestat == STAT_IN)
  856. {
  857. next_pc += (ctx->core_state == ARMV4_5_STATE_ARM) ? 4 : 2;
  858. }
  859. if ((pipestat != STAT_TD) && (pipestat != STAT_WT))
  860. {
  861. char cycles_text[32] = "";
  862. /* if the trace was captured with cycle accurate tracing enabled,
  863. * output the number of cycles since the last executed instruction
  864. */
  865. if (ctx->tracemode & ETMV1_CYCLE_ACCURATE)
  866. {
  867. snprintf(cycles_text, 32, " (%i %s)",
  868. cycles,
  869. (cycles == 1) ? "cycle" : "cycles");
  870. }
  871. command_print(cmd_ctx, "%s%s%s",
  872. instruction.text,
  873. (pipestat == STAT_IN) ? " (not executed)" : "",
  874. cycles_text);
  875. ctx->current_pc = next_pc;
  876. /* packets for an instruction don't start on or before the preceding
  877. * functional pipestat (i.e. other than WT or TD)
  878. */
  879. if (ctx->data_index <= ctx->pipe_index)
  880. {
  881. ctx->data_index = ctx->pipe_index + 1;
  882. ctx->data_half = 0;
  883. }
  884. }
  885. ctx->pipe_index += 1;
  886. }
  887. return ERROR_OK;
  888. }
  889. static int handle_etm_tracemode_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  890. {
  891. target_t *target;
  892. armv4_5_common_t *armv4_5;
  893. arm7_9_common_t *arm7_9;
  894. etmv1_tracemode_t tracemode;
  895. target = get_current_target(cmd_ctx);
  896. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  897. {
  898. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  899. return ERROR_OK;
  900. }
  901. if (!arm7_9->etm_ctx)
  902. {
  903. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  904. return ERROR_OK;
  905. }
  906. tracemode = arm7_9->etm_ctx->tracemode;
  907. if (argc == 4)
  908. {
  909. if (strcmp(args[0], "none") == 0)
  910. {
  911. tracemode = ETMV1_TRACE_NONE;
  912. }
  913. else if (strcmp(args[0], "data") == 0)
  914. {
  915. tracemode = ETMV1_TRACE_DATA;
  916. }
  917. else if (strcmp(args[0], "address") == 0)
  918. {
  919. tracemode = ETMV1_TRACE_ADDR;
  920. }
  921. else if (strcmp(args[0], "all") == 0)
  922. {
  923. tracemode = ETMV1_TRACE_DATA | ETMV1_TRACE_ADDR;
  924. }
  925. else
  926. {
  927. command_print(cmd_ctx, "invalid option '%s'", args[0]);
  928. return ERROR_OK;
  929. }
  930. switch (strtol(args[1], NULL, 0))
  931. {
  932. case 0:
  933. tracemode |= ETMV1_CONTEXTID_NONE;
  934. break;
  935. case 8:
  936. tracemode |= ETMV1_CONTEXTID_8;
  937. break;
  938. case 16:
  939. tracemode |= ETMV1_CONTEXTID_16;
  940. break;
  941. case 32:
  942. tracemode |= ETMV1_CONTEXTID_32;
  943. break;
  944. default:
  945. command_print(cmd_ctx, "invalid option '%s'", args[1]);
  946. return ERROR_OK;
  947. }
  948. if (strcmp(args[2], "enable") == 0)
  949. {
  950. tracemode |= ETMV1_CYCLE_ACCURATE;
  951. }
  952. else if (strcmp(args[2], "disable") == 0)
  953. {
  954. tracemode |= 0;
  955. }
  956. else
  957. {
  958. command_print(cmd_ctx, "invalid option '%s'", args[2]);
  959. return ERROR_OK;
  960. }
  961. if (strcmp(args[3], "enable") == 0)
  962. {
  963. tracemode |= ETMV1_BRANCH_OUTPUT;
  964. }
  965. else if (strcmp(args[3], "disable") == 0)
  966. {
  967. tracemode |= 0;
  968. }
  969. else
  970. {
  971. command_print(cmd_ctx, "invalid option '%s'", args[2]);
  972. return ERROR_OK;
  973. }
  974. }
  975. else if (argc != 0)
  976. {
  977. command_print(cmd_ctx, "usage: configure trace mode <none|data|address|all> <context id bits> <cycle accurate> <branch output>");
  978. return ERROR_OK;
  979. }
  980. command_print(cmd_ctx, "current tracemode configuration:");
  981. switch (tracemode & ETMV1_TRACE_MASK)
  982. {
  983. case ETMV1_TRACE_NONE:
  984. command_print(cmd_ctx, "data tracing: none");
  985. break;
  986. case ETMV1_TRACE_DATA:
  987. command_print(cmd_ctx, "data tracing: data only");
  988. break;
  989. case ETMV1_TRACE_ADDR:
  990. command_print(cmd_ctx, "data tracing: address only");
  991. break;
  992. case ETMV1_TRACE_DATA | ETMV1_TRACE_ADDR:
  993. command_print(cmd_ctx, "data tracing: address and data");
  994. break;
  995. }
  996. switch (tracemode & ETMV1_CONTEXTID_MASK)
  997. {
  998. case ETMV1_CONTEXTID_NONE:
  999. command_print(cmd_ctx, "contextid tracing: none");
  1000. break;
  1001. case ETMV1_CONTEXTID_8:
  1002. command_print(cmd_ctx, "contextid tracing: 8 bit");
  1003. break;
  1004. case ETMV1_CONTEXTID_16:
  1005. command_print(cmd_ctx, "contextid tracing: 16 bit");
  1006. break;
  1007. case ETMV1_CONTEXTID_32:
  1008. command_print(cmd_ctx, "contextid tracing: 32 bit");
  1009. break;
  1010. }
  1011. if (tracemode & ETMV1_CYCLE_ACCURATE)
  1012. {
  1013. command_print(cmd_ctx, "cycle-accurate tracing enabled");
  1014. }
  1015. else
  1016. {
  1017. command_print(cmd_ctx, "cycle-accurate tracing disabled");
  1018. }
  1019. if (tracemode & ETMV1_BRANCH_OUTPUT)
  1020. {
  1021. command_print(cmd_ctx, "full branch address output enabled");
  1022. }
  1023. else
  1024. {
  1025. command_print(cmd_ctx, "full branch address output disabled");
  1026. }
  1027. /* only update ETM_CTRL register if tracemode changed */
  1028. if (arm7_9->etm_ctx->tracemode != tracemode)
  1029. {
  1030. reg_t *etm_ctrl_reg = &arm7_9->etm_ctx->reg_cache->reg_list[ETM_CTRL];
  1031. etm_get_reg(etm_ctrl_reg);
  1032. buf_set_u32(etm_ctrl_reg->value, 2, 2, tracemode & ETMV1_TRACE_MASK);
  1033. buf_set_u32(etm_ctrl_reg->value, 14, 2, (tracemode & ETMV1_CONTEXTID_MASK) >> 4);
  1034. buf_set_u32(etm_ctrl_reg->value, 12, 1, (tracemode & ETMV1_CYCLE_ACCURATE) >> 8);
  1035. buf_set_u32(etm_ctrl_reg->value, 8, 1, (tracemode & ETMV1_BRANCH_OUTPUT) >> 9);
  1036. etm_store_reg(etm_ctrl_reg);
  1037. arm7_9->etm_ctx->tracemode = tracemode;
  1038. /* invalidate old trace data */
  1039. arm7_9->etm_ctx->capture_status = TRACE_IDLE;
  1040. if (arm7_9->etm_ctx->trace_depth > 0)
  1041. {
  1042. free(arm7_9->etm_ctx->trace_data);
  1043. arm7_9->etm_ctx->trace_data = NULL;
  1044. }
  1045. arm7_9->etm_ctx->trace_depth = 0;
  1046. }
  1047. return ERROR_OK;
  1048. }
  1049. static int handle_etm_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1050. {
  1051. target_t *target;
  1052. armv4_5_common_t *armv4_5;
  1053. arm7_9_common_t *arm7_9;
  1054. etm_portmode_t portmode = 0x0;
  1055. etm_context_t *etm_ctx = malloc(sizeof(etm_context_t));
  1056. int i;
  1057. if (argc != 5)
  1058. {
  1059. return ERROR_COMMAND_SYNTAX_ERROR;
  1060. }
  1061. target = get_target(args[0]);
  1062. if (!target)
  1063. {
  1064. LOG_ERROR("target '%s' not defined", args[0]);
  1065. return ERROR_FAIL;
  1066. }
  1067. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1068. {
  1069. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1070. return ERROR_FAIL;
  1071. }
  1072. switch (strtoul(args[1], NULL, 0))
  1073. {
  1074. case 4:
  1075. portmode |= ETM_PORT_4BIT;
  1076. break;
  1077. case 8:
  1078. portmode |= ETM_PORT_8BIT;
  1079. break;
  1080. case 16:
  1081. portmode |= ETM_PORT_16BIT;
  1082. break;
  1083. default:
  1084. command_print(cmd_ctx, "unsupported ETM port width '%s', must be 4, 8 or 16", args[1]);
  1085. return ERROR_FAIL;
  1086. }
  1087. if (strcmp("normal", args[2]) == 0)
  1088. {
  1089. portmode |= ETM_PORT_NORMAL;
  1090. }
  1091. else if (strcmp("multiplexed", args[2]) == 0)
  1092. {
  1093. portmode |= ETM_PORT_MUXED;
  1094. }
  1095. else if (strcmp("demultiplexed", args[2]) == 0)
  1096. {
  1097. portmode |= ETM_PORT_DEMUXED;
  1098. }
  1099. else
  1100. {
  1101. command_print(cmd_ctx, "unsupported ETM port mode '%s', must be 'normal', 'multiplexed' or 'demultiplexed'", args[2]);
  1102. return ERROR_FAIL;
  1103. }
  1104. if (strcmp("half", args[3]) == 0)
  1105. {
  1106. portmode |= ETM_PORT_HALF_CLOCK;
  1107. }
  1108. else if (strcmp("full", args[3]) == 0)
  1109. {
  1110. portmode |= ETM_PORT_FULL_CLOCK;
  1111. }
  1112. else
  1113. {
  1114. command_print(cmd_ctx, "unsupported ETM port clocking '%s', must be 'full' or 'half'", args[3]);
  1115. return ERROR_FAIL;
  1116. }
  1117. for (i=0; etm_capture_drivers[i]; i++)
  1118. {
  1119. if (strcmp(args[4], etm_capture_drivers[i]->name) == 0)
  1120. {
  1121. int retval;
  1122. if ((retval=etm_capture_drivers[i]->register_commands(cmd_ctx)) != ERROR_OK)
  1123. {
  1124. free(etm_ctx);
  1125. return retval;
  1126. }
  1127. etm_ctx->capture_driver = etm_capture_drivers[i];
  1128. break;
  1129. }
  1130. }
  1131. if (!etm_capture_drivers[i])
  1132. {
  1133. /* no supported capture driver found, don't register an ETM */
  1134. free(etm_ctx);
  1135. LOG_ERROR("trace capture driver '%s' not found", args[4]);
  1136. return ERROR_FAIL;
  1137. }
  1138. etm_ctx->target = target;
  1139. etm_ctx->trigger_percent = 50;
  1140. etm_ctx->trace_data = NULL;
  1141. etm_ctx->trace_depth = 0;
  1142. etm_ctx->portmode = portmode;
  1143. etm_ctx->tracemode = 0x0;
  1144. etm_ctx->core_state = ARMV4_5_STATE_ARM;
  1145. etm_ctx->image = NULL;
  1146. etm_ctx->pipe_index = 0;
  1147. etm_ctx->data_index = 0;
  1148. etm_ctx->current_pc = 0x0;
  1149. etm_ctx->pc_ok = 0;
  1150. etm_ctx->last_branch = 0x0;
  1151. etm_ctx->last_branch_reason = 0x0;
  1152. etm_ctx->last_ptr = 0x0;
  1153. etm_ctx->ptr_ok = 0x0;
  1154. etm_ctx->context_id = 0x0;
  1155. etm_ctx->last_instruction = 0;
  1156. arm7_9->etm_ctx = etm_ctx;
  1157. return etm_register_user_commands(cmd_ctx);
  1158. }
  1159. int handle_etm_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1160. {
  1161. target_t *target;
  1162. armv4_5_common_t *armv4_5;
  1163. arm7_9_common_t *arm7_9;
  1164. reg_t *etm_config_reg;
  1165. reg_t *etm_sys_config_reg;
  1166. int max_port_size;
  1167. target = get_current_target(cmd_ctx);
  1168. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1169. {
  1170. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1171. return ERROR_OK;
  1172. }
  1173. if (!arm7_9->etm_ctx)
  1174. {
  1175. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1176. return ERROR_OK;
  1177. }
  1178. etm_config_reg = &arm7_9->etm_ctx->reg_cache->reg_list[ETM_CONFIG];
  1179. etm_sys_config_reg = &arm7_9->etm_ctx->reg_cache->reg_list[ETM_SYS_CONFIG];
  1180. etm_get_reg(etm_config_reg);
  1181. command_print(cmd_ctx, "pairs of address comparators: %i", buf_get_u32(etm_config_reg->value, 0, 4));
  1182. command_print(cmd_ctx, "pairs of data comparators: %i", buf_get_u32(etm_config_reg->value, 4, 4));
  1183. command_print(cmd_ctx, "memory map decoders: %i", buf_get_u32(etm_config_reg->value, 8, 5));
  1184. command_print(cmd_ctx, "number of counters: %i", buf_get_u32(etm_config_reg->value, 13, 3));
  1185. command_print(cmd_ctx, "sequencer %spresent",
  1186. (buf_get_u32(etm_config_reg->value, 16, 1) == 1) ? "" : "not ");
  1187. command_print(cmd_ctx, "number of ext. inputs: %i", buf_get_u32(etm_config_reg->value, 17, 3));
  1188. command_print(cmd_ctx, "number of ext. outputs: %i", buf_get_u32(etm_config_reg->value, 20, 3));
  1189. command_print(cmd_ctx, "FIFO full %spresent",
  1190. (buf_get_u32(etm_config_reg->value, 23, 1) == 1) ? "" : "not ");
  1191. command_print(cmd_ctx, "protocol version: %i", buf_get_u32(etm_config_reg->value, 28, 3));
  1192. etm_get_reg(etm_sys_config_reg);
  1193. switch (buf_get_u32(etm_sys_config_reg->value, 0, 3))
  1194. {
  1195. case 0:
  1196. max_port_size = 4;
  1197. break;
  1198. case 1:
  1199. max_port_size = 8;
  1200. break;
  1201. case 2:
  1202. max_port_size = 16;
  1203. break;
  1204. default:
  1205. LOG_ERROR("Illegal max_port_size");
  1206. exit(-1);
  1207. }
  1208. command_print(cmd_ctx, "max. port size: %i", max_port_size);
  1209. command_print(cmd_ctx, "half-rate clocking %ssupported",
  1210. (buf_get_u32(etm_sys_config_reg->value, 3, 1) == 1) ? "" : "not ");
  1211. command_print(cmd_ctx, "full-rate clocking %ssupported",
  1212. (buf_get_u32(etm_sys_config_reg->value, 4, 1) == 1) ? "" : "not ");
  1213. command_print(cmd_ctx, "normal trace format %ssupported",
  1214. (buf_get_u32(etm_sys_config_reg->value, 5, 1) == 1) ? "" : "not ");
  1215. command_print(cmd_ctx, "multiplex trace format %ssupported",
  1216. (buf_get_u32(etm_sys_config_reg->value, 6, 1) == 1) ? "" : "not ");
  1217. command_print(cmd_ctx, "demultiplex trace format %ssupported",
  1218. (buf_get_u32(etm_sys_config_reg->value, 7, 1) == 1) ? "" : "not ");
  1219. command_print(cmd_ctx, "FIFO full %ssupported",
  1220. (buf_get_u32(etm_sys_config_reg->value, 8, 1) == 1) ? "" : "not ");
  1221. return ERROR_OK;
  1222. }
  1223. static int handle_etm_status_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1224. {
  1225. target_t *target;
  1226. armv4_5_common_t *armv4_5;
  1227. arm7_9_common_t *arm7_9;
  1228. trace_status_t trace_status;
  1229. target = get_current_target(cmd_ctx);
  1230. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1231. {
  1232. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1233. return ERROR_OK;
  1234. }
  1235. if (!arm7_9->etm_ctx)
  1236. {
  1237. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1238. return ERROR_OK;
  1239. }
  1240. trace_status = arm7_9->etm_ctx->capture_driver->status(arm7_9->etm_ctx);
  1241. if (trace_status == TRACE_IDLE)
  1242. {
  1243. command_print(cmd_ctx, "tracing is idle");
  1244. }
  1245. else
  1246. {
  1247. static char *completed = " completed";
  1248. static char *running = " is running";
  1249. static char *overflowed = ", trace overflowed";
  1250. static char *triggered = ", trace triggered";
  1251. command_print(cmd_ctx, "trace collection%s%s%s",
  1252. (trace_status & TRACE_RUNNING) ? running : completed,
  1253. (trace_status & TRACE_OVERFLOWED) ? overflowed : "",
  1254. (trace_status & TRACE_TRIGGERED) ? triggered : "");
  1255. if (arm7_9->etm_ctx->trace_depth > 0)
  1256. {
  1257. command_print(cmd_ctx, "%i frames of trace data read", arm7_9->etm_ctx->trace_depth);
  1258. }
  1259. }
  1260. return ERROR_OK;
  1261. }
  1262. static int handle_etm_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1263. {
  1264. target_t *target;
  1265. armv4_5_common_t *armv4_5;
  1266. arm7_9_common_t *arm7_9;
  1267. etm_context_t *etm_ctx;
  1268. if (argc < 1)
  1269. {
  1270. command_print(cmd_ctx, "usage: etm image <file> [base address] [type]");
  1271. return ERROR_OK;
  1272. }
  1273. target = get_current_target(cmd_ctx);
  1274. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1275. {
  1276. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1277. return ERROR_OK;
  1278. }
  1279. if (!(etm_ctx = arm7_9->etm_ctx))
  1280. {
  1281. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1282. return ERROR_OK;
  1283. }
  1284. if (etm_ctx->image)
  1285. {
  1286. image_close(etm_ctx->image);
  1287. free(etm_ctx->image);
  1288. command_print(cmd_ctx, "previously loaded image found and closed");
  1289. }
  1290. etm_ctx->image = malloc(sizeof(image_t));
  1291. etm_ctx->image->base_address_set = 0;
  1292. etm_ctx->image->start_address_set = 0;
  1293. /* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
  1294. if (argc >= 2)
  1295. {
  1296. etm_ctx->image->base_address_set = 1;
  1297. etm_ctx->image->base_address = strtoul(args[1], NULL, 0);
  1298. }
  1299. else
  1300. {
  1301. etm_ctx->image->base_address_set = 0;
  1302. }
  1303. if (image_open(etm_ctx->image, args[0], (argc >= 3) ? args[2] : NULL) != ERROR_OK)
  1304. {
  1305. free(etm_ctx->image);
  1306. etm_ctx->image = NULL;
  1307. return ERROR_OK;
  1308. }
  1309. return ERROR_OK;
  1310. }
  1311. static int handle_etm_dump_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1312. {
  1313. fileio_t file;
  1314. target_t *target;
  1315. armv4_5_common_t *armv4_5;
  1316. arm7_9_common_t *arm7_9;
  1317. etm_context_t *etm_ctx;
  1318. u32 i;
  1319. if (argc != 1)
  1320. {
  1321. command_print(cmd_ctx, "usage: etm dump <file>");
  1322. return ERROR_OK;
  1323. }
  1324. target = get_current_target(cmd_ctx);
  1325. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1326. {
  1327. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1328. return ERROR_OK;
  1329. }
  1330. if (!(etm_ctx = arm7_9->etm_ctx))
  1331. {
  1332. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1333. return ERROR_OK;
  1334. }
  1335. if (etm_ctx->capture_driver->status == TRACE_IDLE)
  1336. {
  1337. command_print(cmd_ctx, "trace capture wasn't enabled, no trace data captured");
  1338. return ERROR_OK;
  1339. }
  1340. if (etm_ctx->capture_driver->status(etm_ctx) & TRACE_RUNNING)
  1341. {
  1342. /* TODO: if on-the-fly capture is to be supported, this needs to be changed */
  1343. command_print(cmd_ctx, "trace capture not completed");
  1344. return ERROR_OK;
  1345. }
  1346. /* read the trace data if it wasn't read already */
  1347. if (etm_ctx->trace_depth == 0)
  1348. etm_ctx->capture_driver->read_trace(etm_ctx);
  1349. if (fileio_open(&file, args[0], FILEIO_WRITE, FILEIO_BINARY) != ERROR_OK)
  1350. {
  1351. return ERROR_OK;
  1352. }
  1353. fileio_write_u32(&file, etm_ctx->capture_status);
  1354. fileio_write_u32(&file, etm_ctx->portmode);
  1355. fileio_write_u32(&file, etm_ctx->tracemode);
  1356. fileio_write_u32(&file, etm_ctx->trace_depth);
  1357. for (i = 0; i < etm_ctx->trace_depth; i++)
  1358. {
  1359. fileio_write_u32(&file, etm_ctx->trace_data[i].pipestat);
  1360. fileio_write_u32(&file, etm_ctx->trace_data[i].packet);
  1361. fileio_write_u32(&file, etm_ctx->trace_data[i].flags);
  1362. }
  1363. fileio_close(&file);
  1364. return ERROR_OK;
  1365. }
  1366. static int handle_etm_load_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1367. {
  1368. fileio_t file;
  1369. target_t *target;
  1370. armv4_5_common_t *armv4_5;
  1371. arm7_9_common_t *arm7_9;
  1372. etm_context_t *etm_ctx;
  1373. u32 i;
  1374. if (argc != 1)
  1375. {
  1376. command_print(cmd_ctx, "usage: etm load <file>");
  1377. return ERROR_OK;
  1378. }
  1379. target = get_current_target(cmd_ctx);
  1380. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1381. {
  1382. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1383. return ERROR_OK;
  1384. }
  1385. if (!(etm_ctx = arm7_9->etm_ctx))
  1386. {
  1387. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1388. return ERROR_OK;
  1389. }
  1390. if (etm_ctx->capture_driver->status(etm_ctx) & TRACE_RUNNING)
  1391. {
  1392. command_print(cmd_ctx, "trace capture running, stop first");
  1393. return ERROR_OK;
  1394. }
  1395. if (fileio_open(&file, args[0], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
  1396. {
  1397. return ERROR_OK;
  1398. }
  1399. if (file.size % 4)
  1400. {
  1401. command_print(cmd_ctx, "size isn't a multiple of 4, no valid trace data");
  1402. fileio_close(&file);
  1403. return ERROR_OK;
  1404. }
  1405. if (etm_ctx->trace_depth > 0)
  1406. {
  1407. free(etm_ctx->trace_data);
  1408. etm_ctx->trace_data = NULL;
  1409. }
  1410. fileio_read_u32(&file, &etm_ctx->capture_status);
  1411. fileio_read_u32(&file, &etm_ctx->portmode);
  1412. fileio_read_u32(&file, &etm_ctx->tracemode);
  1413. fileio_read_u32(&file, &etm_ctx->trace_depth);
  1414. etm_ctx->trace_data = malloc(sizeof(etmv1_trace_data_t) * etm_ctx->trace_depth);
  1415. if (etm_ctx->trace_data == NULL)
  1416. {
  1417. command_print(cmd_ctx, "not enough memory to perform operation");
  1418. fileio_close(&file);
  1419. return ERROR_OK;
  1420. }
  1421. for (i = 0; i < etm_ctx->trace_depth; i++)
  1422. {
  1423. u32 pipestat, packet, flags;
  1424. fileio_read_u32(&file, &pipestat);
  1425. fileio_read_u32(&file, &packet);
  1426. fileio_read_u32(&file, &flags);
  1427. etm_ctx->trace_data[i].pipestat = pipestat & 0xff;
  1428. etm_ctx->trace_data[i].packet = packet & 0xffff;
  1429. etm_ctx->trace_data[i].flags = flags;
  1430. }
  1431. fileio_close(&file);
  1432. return ERROR_OK;
  1433. }
  1434. static int handle_etm_trigger_percent_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1435. {
  1436. target_t *target;
  1437. armv4_5_common_t *armv4_5;
  1438. arm7_9_common_t *arm7_9;
  1439. etm_context_t *etm_ctx;
  1440. target = get_current_target(cmd_ctx);
  1441. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1442. {
  1443. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1444. return ERROR_OK;
  1445. }
  1446. if (!(etm_ctx = arm7_9->etm_ctx))
  1447. {
  1448. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1449. return ERROR_OK;
  1450. }
  1451. if (argc > 0)
  1452. {
  1453. u32 new_value = strtoul(args[0], NULL, 0);
  1454. if ((new_value < 2) || (new_value > 100))
  1455. {
  1456. command_print(cmd_ctx, "valid settings are 2%% to 100%%");
  1457. }
  1458. else
  1459. {
  1460. etm_ctx->trigger_percent = new_value;
  1461. }
  1462. }
  1463. command_print(cmd_ctx, "%i percent of the tracebuffer reserved for after the trigger", etm_ctx->trigger_percent);
  1464. return ERROR_OK;
  1465. }
  1466. static int handle_etm_start_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1467. {
  1468. target_t *target;
  1469. armv4_5_common_t *armv4_5;
  1470. arm7_9_common_t *arm7_9;
  1471. etm_context_t *etm_ctx;
  1472. reg_t *etm_ctrl_reg;
  1473. target = get_current_target(cmd_ctx);
  1474. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1475. {
  1476. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1477. return ERROR_OK;
  1478. }
  1479. if (!(etm_ctx = arm7_9->etm_ctx))
  1480. {
  1481. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1482. return ERROR_OK;
  1483. }
  1484. /* invalidate old tracing data */
  1485. arm7_9->etm_ctx->capture_status = TRACE_IDLE;
  1486. if (arm7_9->etm_ctx->trace_depth > 0)
  1487. {
  1488. free(arm7_9->etm_ctx->trace_data);
  1489. arm7_9->etm_ctx->trace_data = NULL;
  1490. }
  1491. arm7_9->etm_ctx->trace_depth = 0;
  1492. etm_ctrl_reg = &arm7_9->etm_ctx->reg_cache->reg_list[ETM_CTRL];
  1493. etm_get_reg(etm_ctrl_reg);
  1494. /* Clear programming bit (10), set port selection bit (11) */
  1495. buf_set_u32(etm_ctrl_reg->value, 10, 2, 0x2);
  1496. etm_store_reg(etm_ctrl_reg);
  1497. jtag_execute_queue();
  1498. etm_ctx->capture_driver->start_capture(etm_ctx);
  1499. return ERROR_OK;
  1500. }
  1501. static int handle_etm_stop_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1502. {
  1503. target_t *target;
  1504. armv4_5_common_t *armv4_5;
  1505. arm7_9_common_t *arm7_9;
  1506. etm_context_t *etm_ctx;
  1507. reg_t *etm_ctrl_reg;
  1508. target = get_current_target(cmd_ctx);
  1509. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1510. {
  1511. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1512. return ERROR_OK;
  1513. }
  1514. if (!(etm_ctx = arm7_9->etm_ctx))
  1515. {
  1516. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1517. return ERROR_OK;
  1518. }
  1519. etm_ctrl_reg = &arm7_9->etm_ctx->reg_cache->reg_list[ETM_CTRL];
  1520. etm_get_reg(etm_ctrl_reg);
  1521. /* Set programming bit (10), clear port selection bit (11) */
  1522. buf_set_u32(etm_ctrl_reg->value, 10, 2, 0x1);
  1523. etm_store_reg(etm_ctrl_reg);
  1524. jtag_execute_queue();
  1525. etm_ctx->capture_driver->stop_capture(etm_ctx);
  1526. return ERROR_OK;
  1527. }
  1528. static int handle_etm_analyze_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1529. {
  1530. target_t *target;
  1531. armv4_5_common_t *armv4_5;
  1532. arm7_9_common_t *arm7_9;
  1533. etm_context_t *etm_ctx;
  1534. int retval;
  1535. target = get_current_target(cmd_ctx);
  1536. if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
  1537. {
  1538. command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
  1539. return ERROR_OK;
  1540. }
  1541. if (!(etm_ctx = arm7_9->etm_ctx))
  1542. {
  1543. command_print(cmd_ctx, "current target doesn't have an ETM configured");
  1544. return ERROR_OK;
  1545. }
  1546. if ((retval = etmv1_analyze_trace(etm_ctx, cmd_ctx)) != ERROR_OK)
  1547. {
  1548. switch (retval)
  1549. {
  1550. case ERROR_ETM_ANALYSIS_FAILED:
  1551. command_print(cmd_ctx, "further analysis failed (corrupted trace data or just end of data");
  1552. break;
  1553. case ERROR_TRACE_INSTRUCTION_UNAVAILABLE:
  1554. command_print(cmd_ctx, "no instruction for current address available, analysis aborted");
  1555. break;
  1556. case ERROR_TRACE_IMAGE_UNAVAILABLE:
  1557. command_print(cmd_ctx, "no image available for trace analysis");
  1558. break;
  1559. default:
  1560. command_print(cmd_ctx, "unknown error: %i", retval);
  1561. }
  1562. }
  1563. return ERROR_OK;
  1564. }
  1565. int etm_register_commands(struct command_context_s *cmd_ctx)
  1566. {
  1567. etm_cmd = register_command(cmd_ctx, NULL, "etm", NULL, COMMAND_ANY, "Embedded Trace Macrocell");
  1568. register_command(cmd_ctx, etm_cmd, "config", handle_etm_config_command,
  1569. COMMAND_CONFIG, "etm config <target> <port_width> <port_mode> <clocking> <capture_driver>");
  1570. return ERROR_OK;
  1571. }
  1572. int etm_register_user_commands(struct command_context_s *cmd_ctx)
  1573. {
  1574. register_command(cmd_ctx, etm_cmd, "tracemode", handle_etm_tracemode_command,
  1575. COMMAND_EXEC, "configure trace mode <none|data|address|all> "
  1576. "<context_id_bits> <cycle_accurate> <branch_output>");
  1577. register_command(cmd_ctx, etm_cmd, "info", handle_etm_info_command,
  1578. COMMAND_EXEC, "display info about the current target's ETM");
  1579. register_command(cmd_ctx, etm_cmd, "trigger_percent", handle_etm_trigger_percent_command,
  1580. COMMAND_EXEC, "amount (<percent>) of trace buffer to be filled after the trigger occured");
  1581. register_command(cmd_ctx, etm_cmd, "status", handle_etm_status_command,
  1582. COMMAND_EXEC, "display current target's ETM status");
  1583. register_command(cmd_ctx, etm_cmd, "start", handle_etm_start_command,
  1584. COMMAND_EXEC, "start ETM trace collection");
  1585. register_command(cmd_ctx, etm_cmd, "stop", handle_etm_stop_command,
  1586. COMMAND_EXEC, "stop ETM trace collection");
  1587. register_command(cmd_ctx, etm_cmd, "analyze", handle_etm_analyze_command,
  1588. COMMAND_EXEC, "anaylze collected ETM trace");
  1589. register_command(cmd_ctx, etm_cmd, "image", handle_etm_image_command,
  1590. COMMAND_EXEC, "load image from <file> [base address]");
  1591. register_command(cmd_ctx, etm_cmd, "dump", handle_etm_dump_command,
  1592. COMMAND_EXEC, "dump captured trace data <file>");
  1593. register_command(cmd_ctx, etm_cmd, "load", handle_etm_load_command,
  1594. COMMAND_EXEC, "load trace data for analysis <file>");
  1595. return ERROR_OK;
  1596. }