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.
 
 
 
 
 
 

306 lines
12 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * Copyright (C) 2007-2010 Øyvind Harboe *
  6. * oyvind.harboe@zylin.com *
  7. * *
  8. * Copyright (C) 2008 by Spencer Oliver *
  9. * spen@spen-soft.co.uk *
  10. * *
  11. * This program is free software; you can redistribute it and/or modify *
  12. * it under the terms of the GNU General Public License as published by *
  13. * the Free Software Foundation; either version 2 of the License, or *
  14. * (at your option) any later version. *
  15. * *
  16. * This program is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  19. * GNU General Public License for more details. *
  20. * *
  21. * You should have received a copy of the GNU General Public License *
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  23. ***************************************************************************/
  24. #ifndef OPENOCD_TARGET_TARGET_TYPE_H
  25. #define OPENOCD_TARGET_TARGET_TYPE_H
  26. #include <jim-nvp.h>
  27. struct target;
  28. /**
  29. * This holds methods shared between all instances of a given target
  30. * type. For example, all Cortex-M3 targets on a scan chain share
  31. * the same method table.
  32. */
  33. struct target_type {
  34. /**
  35. * Name of this type of target. Do @b not access this
  36. * field directly, use target_type_name() instead.
  37. */
  38. const char *name;
  39. /* poll current target status */
  40. int (*poll)(struct target *target);
  41. /* Invoked only from target_arch_state().
  42. * Issue USER() w/architecture specific status. */
  43. int (*arch_state)(struct target *target);
  44. /* target request support */
  45. int (*target_request_data)(struct target *target, uint32_t size, uint8_t *buffer);
  46. /* halt will log a warning, but return ERROR_OK if the target is already halted. */
  47. int (*halt)(struct target *target);
  48. /* See target.c target_resume() for documentation. */
  49. int (*resume)(struct target *target, int current, target_addr_t address,
  50. int handle_breakpoints, int debug_execution);
  51. int (*step)(struct target *target, int current, target_addr_t address,
  52. int handle_breakpoints);
  53. /* target reset control. assert reset can be invoked when OpenOCD and
  54. * the target is out of sync.
  55. *
  56. * A typical example is that the target was power cycled while OpenOCD
  57. * thought the target was halted or running.
  58. *
  59. * assert_reset() can therefore make no assumptions whatsoever about the
  60. * state of the target
  61. *
  62. * Before assert_reset() for the target is invoked, a TRST/tms and
  63. * chain validation is executed. TRST should not be asserted
  64. * during target assert unless there is no way around it due to
  65. * the way reset's are configured.
  66. *
  67. */
  68. int (*assert_reset)(struct target *target);
  69. /**
  70. * The implementation is responsible for polling the
  71. * target such that target->state reflects the
  72. * state correctly.
  73. *
  74. * Otherwise the following would fail, as there will not
  75. * be any "poll" invoked between the "reset run" and
  76. * "halt".
  77. *
  78. * reset run; halt
  79. */
  80. int (*deassert_reset)(struct target *target);
  81. int (*soft_reset_halt)(struct target *target);
  82. /**
  83. * Target architecture for GDB.
  84. *
  85. * The string returned by this function will not be automatically freed;
  86. * if dynamic allocation is used for this value, it must be managed by
  87. * the target, ideally by caching the result for subsequent calls.
  88. */
  89. const char *(*get_gdb_arch)(struct target *target);
  90. /**
  91. * Target register access for GDB. Do @b not call this function
  92. * directly, use target_get_gdb_reg_list() instead.
  93. *
  94. * Danger! this function will succeed even if the target is running
  95. * and return a register list with dummy values.
  96. *
  97. * The reason is that GDB connection will fail without a valid register
  98. * list, however it is after GDB is connected that monitor commands can
  99. * be run to properly initialize the target
  100. */
  101. int (*get_gdb_reg_list)(struct target *target, struct reg **reg_list[],
  102. int *reg_list_size, enum target_register_class reg_class);
  103. /**
  104. * Same as get_gdb_reg_list, but doesn't read the register values.
  105. * */
  106. int (*get_gdb_reg_list_noread)(struct target *target,
  107. struct reg **reg_list[], int *reg_list_size,
  108. enum target_register_class reg_class);
  109. /* target memory access
  110. * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit)
  111. * count: number of items of <size>
  112. */
  113. /**
  114. * Target memory read callback. Do @b not call this function
  115. * directly, use target_read_memory() instead.
  116. */
  117. int (*read_memory)(struct target *target, target_addr_t address,
  118. uint32_t size, uint32_t count, uint8_t *buffer);
  119. /**
  120. * Target memory write callback. Do @b not call this function
  121. * directly, use target_write_memory() instead.
  122. */
  123. int (*write_memory)(struct target *target, target_addr_t address,
  124. uint32_t size, uint32_t count, const uint8_t *buffer);
  125. /* Default implementation will do some fancy alignment to improve performance, target can override */
  126. int (*read_buffer)(struct target *target, target_addr_t address,
  127. uint32_t size, uint8_t *buffer);
  128. /* Default implementation will do some fancy alignment to improve performance, target can override */
  129. int (*write_buffer)(struct target *target, target_addr_t address,
  130. uint32_t size, const uint8_t *buffer);
  131. int (*checksum_memory)(struct target *target, target_addr_t address,
  132. uint32_t count, uint32_t *checksum);
  133. int (*blank_check_memory)(struct target *target,
  134. struct target_memory_check_block *blocks, int num_blocks,
  135. uint8_t erased_value);
  136. /*
  137. * target break-/watchpoint control
  138. * rw: 0 = write, 1 = read, 2 = access
  139. *
  140. * Target must be halted while this is invoked as this
  141. * will actually set up breakpoints on target.
  142. *
  143. * The breakpoint hardware will be set up upon adding the
  144. * first breakpoint.
  145. *
  146. * Upon GDB connection all breakpoints/watchpoints are cleared.
  147. */
  148. int (*add_breakpoint)(struct target *target, struct breakpoint *breakpoint);
  149. int (*add_context_breakpoint)(struct target *target, struct breakpoint *breakpoint);
  150. int (*add_hybrid_breakpoint)(struct target *target, struct breakpoint *breakpoint);
  151. /* remove breakpoint. hw will only be updated if the target
  152. * is currently halted.
  153. * However, this method can be invoked on unresponsive targets.
  154. */
  155. int (*remove_breakpoint)(struct target *target, struct breakpoint *breakpoint);
  156. /* add watchpoint ... see add_breakpoint() comment above. */
  157. int (*add_watchpoint)(struct target *target, struct watchpoint *watchpoint);
  158. /* remove watchpoint. hw will only be updated if the target
  159. * is currently halted.
  160. * However, this method can be invoked on unresponsive targets.
  161. */
  162. int (*remove_watchpoint)(struct target *target, struct watchpoint *watchpoint);
  163. /* Find out just hit watchpoint. After the target hits a watchpoint, the
  164. * information could assist gdb to locate where the modified/accessed memory is.
  165. */
  166. int (*hit_watchpoint)(struct target *target, struct watchpoint **hit_watchpoint);
  167. /**
  168. * Target algorithm support. Do @b not call this method directly,
  169. * use target_run_algorithm() instead.
  170. */
  171. int (*run_algorithm)(struct target *target, int num_mem_params,
  172. struct mem_param *mem_params, int num_reg_params,
  173. struct reg_param *reg_param, target_addr_t entry_point,
  174. target_addr_t exit_point, int timeout_ms, void *arch_info);
  175. int (*start_algorithm)(struct target *target, int num_mem_params,
  176. struct mem_param *mem_params, int num_reg_params,
  177. struct reg_param *reg_param, target_addr_t entry_point,
  178. target_addr_t exit_point, void *arch_info);
  179. int (*wait_algorithm)(struct target *target, int num_mem_params,
  180. struct mem_param *mem_params, int num_reg_params,
  181. struct reg_param *reg_param, target_addr_t exit_point,
  182. int timeout_ms, void *arch_info);
  183. const struct command_registration *commands;
  184. /* called when target is created */
  185. int (*target_create)(struct target *target, Jim_Interp *interp);
  186. /* called for various config parameters */
  187. /* returns JIM_CONTINUE - if option not understood */
  188. /* otherwise: JIM_OK, or JIM_ERR, */
  189. int (*target_jim_configure)(struct target *target, struct jim_getopt_info *goi);
  190. /* target commands specifically handled by the target */
  191. /* returns JIM_OK, or JIM_ERR, or JIM_CONTINUE - if option not understood */
  192. int (*target_jim_commands)(struct target *target, struct jim_getopt_info *goi);
  193. /**
  194. * This method is used to perform target setup that requires
  195. * JTAG access.
  196. *
  197. * This may be called multiple times. It is called after the
  198. * scan chain is initially validated, or later after the target
  199. * is enabled by a JRC. It may also be called during some
  200. * parts of the reset sequence.
  201. *
  202. * For one-time initialization tasks, use target_was_examined()
  203. * and target_set_examined(). For example, probe the hardware
  204. * before setting up chip-specific state, and then set that
  205. * flag so you don't do that again.
  206. */
  207. int (*examine)(struct target *target);
  208. /* Set up structures for target.
  209. *
  210. * It is illegal to talk to the target at this stage as this fn is invoked
  211. * before the JTAG chain has been examined/verified
  212. * */
  213. int (*init_target)(struct command_context *cmd_ctx, struct target *target);
  214. /**
  215. * Free all the resources allocated by the target.
  216. *
  217. * @param target The target to deinit
  218. */
  219. void (*deinit_target)(struct target *target);
  220. /* translate from virtual to physical address. Default implementation is successful
  221. * no-op(i.e. virtual==physical).
  222. */
  223. int (*virt2phys)(struct target *target, target_addr_t address, target_addr_t *physical);
  224. /* read directly from physical memory. caches are bypassed and untouched.
  225. *
  226. * If the target does not support disabling caches, leaving them untouched,
  227. * then minimally the actual physical memory location will be read even
  228. * if cache states are unchanged, flushed, etc.
  229. *
  230. * Default implementation is to call read_memory.
  231. */
  232. int (*read_phys_memory)(struct target *target, target_addr_t phys_address,
  233. uint32_t size, uint32_t count, uint8_t *buffer);
  234. /*
  235. * same as read_phys_memory, except that it writes...
  236. */
  237. int (*write_phys_memory)(struct target *target, target_addr_t phys_address,
  238. uint32_t size, uint32_t count, const uint8_t *buffer);
  239. int (*mmu)(struct target *target, int *enabled);
  240. /* after reset is complete, the target can check if things are properly set up.
  241. *
  242. * This can be used to check if e.g. DCC memory writes have been enabled for
  243. * arm7/9 targets, which they really should except in the most contrived
  244. * circumstances.
  245. */
  246. int (*check_reset)(struct target *target);
  247. /* get GDB file-I/O parameters from target
  248. */
  249. int (*get_gdb_fileio_info)(struct target *target, struct gdb_fileio_info *fileio_info);
  250. /* pass GDB file-I/O response to target
  251. */
  252. int (*gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c);
  253. /* do target profiling
  254. */
  255. int (*profiling)(struct target *target, uint32_t *samples,
  256. uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds);
  257. /* Return the number of address bits this target supports. This will
  258. * typically be 32 for 32-bit targets, and 64 for 64-bit targets. If not
  259. * implemented, it's assumed to be 32. */
  260. unsigned (*address_bits)(struct target *target);
  261. /* Return the number of system bus data bits this target supports. This
  262. * will typically be 32 for 32-bit targets, and 64 for 64-bit targets. If
  263. * not implemented, it's assumed to be 32. */
  264. unsigned int (*data_bits)(struct target *target);
  265. };
  266. #endif /* OPENOCD_TARGET_TARGET_TYPE_H */