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.
 
 
 
 
 
 

219 lines
9.4 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * Copyright (C) 2007,2008,2009 √ė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, write to the *
  23. * Free Software Foundation, Inc., *
  24. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  25. ***************************************************************************/
  26. #ifndef TARGET_TYPE_H
  27. #define TARGET_TYPE_H
  28. #include <helper/types.h>
  29. struct target;
  30. /**
  31. * This holds methods shared between all instances of a given target
  32. * type. For example, all Cortex-M3 targets on a scan chain share
  33. * the same method table.
  34. */
  35. struct target_type
  36. {
  37. /**
  38. * Name of this type of target. Do @b not access this
  39. * field directly, use target_type_name() instead.
  40. */
  41. char *name;
  42. /* poll current target status */
  43. int (*poll)(struct target *target);
  44. /* Invoked only from target_arch_state().
  45. * Issue USER() w/architecture specific status. */
  46. int (*arch_state)(struct target *target);
  47. /* target request support */
  48. int (*target_request_data)(struct target *target, uint32_t size, uint8_t *buffer);
  49. /* halt will log a warning, but return ERROR_OK if the target is already halted. */
  50. int (*halt)(struct target *target);
  51. int (*resume)(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution);
  52. int (*step)(struct target *target, int current, uint32_t address, 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. int (*deassert_reset)(struct target *target);
  70. int (*soft_reset_halt_imp)(struct target *target);
  71. int (*soft_reset_halt)(struct target *target);
  72. /**
  73. * Target register access for GDB. Do @b not call this function
  74. * directly, use target_get_gdb_reg_list() instead.
  75. *
  76. * Danger! this function will succeed even if the target is running
  77. * and return a register list with dummy values.
  78. *
  79. * The reason is that GDB connection will fail without a valid register
  80. * list, however it is after GDB is connected that monitor commands can
  81. * be run to properly initialize the target
  82. */
  83. int (*get_gdb_reg_list)(struct target *target, struct reg **reg_list[], int *reg_list_size);
  84. /* target memory access
  85. * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit)
  86. * count: number of items of <size>
  87. */
  88. int (*read_memory_imp)(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  89. /**
  90. * Target memory read callback. Do @b not call this function
  91. * directly, use target_read_memory() instead.
  92. */
  93. int (*read_memory)(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  94. int (*write_memory_imp)(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  95. /**
  96. * Target memory write callback. Do @b not call this function
  97. * directly, use target_write_memory() instead.
  98. */
  99. int (*write_memory)(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  100. /**
  101. * Write target memory in multiples of 4 bytes, optimized for
  102. * writing large quantities of data. Do @b not call this
  103. * function directly, use target_bulk_write_memory() instead.
  104. */
  105. int (*bulk_write_memory)(struct target *target, uint32_t address, uint32_t count, uint8_t *buffer);
  106. int (*checksum_memory)(struct target *target, uint32_t address, uint32_t count, uint32_t* checksum);
  107. int (*blank_check_memory)(struct target *target, uint32_t address, uint32_t count, uint32_t* blank);
  108. /*
  109. * target break-/watchpoint control
  110. * rw: 0 = write, 1 = read, 2 = access
  111. *
  112. * Target must be halted while this is invoked as this
  113. * will actually set up breakpoints on target.
  114. *
  115. * The breakpoint hardware will be set up upon adding the
  116. * first breakpoint.
  117. *
  118. * Upon GDB connection all breakpoints/watchpoints are cleared.
  119. */
  120. int (*add_breakpoint)(struct target *target, struct breakpoint *breakpoint);
  121. /* remove breakpoint. hw will only be updated if the target
  122. * is currently halted.
  123. * However, this method can be invoked on unresponsive targets.
  124. */
  125. int (*remove_breakpoint)(struct target *target, struct breakpoint *breakpoint);
  126. /* add watchpoint ... see add_breakpoint() comment above. */
  127. int (*add_watchpoint)(struct target *target, struct watchpoint *watchpoint);
  128. /* remove watchpoint. hw will only be updated if the target
  129. * is currently halted.
  130. * However, this method can be invoked on unresponsive targets.
  131. */
  132. int (*remove_watchpoint)(struct target *target, struct watchpoint *watchpoint);
  133. /* target algorithm support */
  134. int (*run_algorithm_imp)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info);
  135. /**
  136. * Target algorithm support. Do @b not call this method directly,
  137. * use target_run_algorithm() instead.
  138. */
  139. int (*run_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info);
  140. const struct command_registration *commands;
  141. /* called when target is created */
  142. int (*target_create)(struct target *target, Jim_Interp *interp);
  143. /* called for various config parameters */
  144. /* returns JIM_CONTINUE - if option not understood */
  145. /* otherwise: JIM_OK, or JIM_ERR, */
  146. int (*target_jim_configure)(struct target *target, Jim_GetOptInfo *goi);
  147. /* target commands specifically handled by the target */
  148. /* returns JIM_OK, or JIM_ERR, or JIM_CONTINUE - if option not understood */
  149. int (*target_jim_commands)(struct target *target, Jim_GetOptInfo *goi);
  150. /**
  151. * This method is used to perform target setup that requires
  152. * JTAG access.
  153. *
  154. * This may be called multiple times. It is called after the
  155. * scan chain is initially validated, or later after the target
  156. * is enabled by a JRC. It may also be called during some
  157. * parts of the reset sequence.
  158. *
  159. * For one-time initialization tasks, use target_was_examined()
  160. * and target_set_examined(). For example, probe the hardware
  161. * before setting up chip-specific state, and then set that
  162. * flag so you don't do that again.
  163. */
  164. int (*examine)(struct target *target);
  165. /* Set up structures for target.
  166. *
  167. * It is illegal to talk to the target at this stage as this fn is invoked
  168. * before the JTAG chain has been examined/verified
  169. * */
  170. int (*init_target)(struct command_context *cmd_ctx, struct target *target);
  171. /* translate from virtual to physical address. Default implementation is successful
  172. * no-op(i.e. virtual==physical).
  173. */
  174. int (*virt2phys)(struct target *target, uint32_t address, uint32_t *physical);
  175. /* read directly from physical memory. caches are bypassed and untouched.
  176. *
  177. * If the target does not support disabling caches, leaving them untouched,
  178. * then minimally the actual physical memory location will be read even
  179. * if cache states are unchanged, flushed, etc.
  180. *
  181. * Default implementation is to call read_memory.
  182. */
  183. int (*read_phys_memory)(struct target *target, uint32_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer);
  184. /*
  185. * same as read_phys_memory, except that it writes...
  186. */
  187. int (*write_phys_memory)(struct target *target, uint32_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer);
  188. int (*mmu)(struct target *target, int *enabled);
  189. };
  190. #endif // TARGET_TYPE_H