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.
 
 
 
 
 
 

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