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.
 
 
 
 
 
 

212 lines
9.5 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 "types.h"
  29. struct target_s;
  30. struct target_type_s
  31. {
  32. /**
  33. * Name of the target. Do @b not access this field directly, use
  34. * target_get_name() instead.
  35. */
  36. char *name;
  37. /**
  38. * Indicates whether this target has been examined.
  39. *
  40. * Do @b not access this field directly, use target_was_examined()
  41. * target_set_examined(), and target_reset_examined().
  42. */
  43. int examined;
  44. /* poll current target status */
  45. int (*poll)(struct target_s *target);
  46. /* Invoked only from target_arch_state().
  47. * Issue USER() w/architecture specific status. */
  48. int (*arch_state)(struct target_s *target);
  49. /* target request support */
  50. int (*target_request_data)(struct target_s *target, uint32_t size, uint8_t *buffer);
  51. /* halt will log a warning, but return ERROR_OK if the target is already halted. */
  52. int (*halt)(struct target_s *target);
  53. int (*resume)(struct target_s *target, int current, uint32_t address, int handle_breakpoints, int debug_execution);
  54. int (*step)(struct target_s *target, int current, uint32_t address, int handle_breakpoints);
  55. /* target reset control. assert reset can be invoked when OpenOCD and
  56. * the target is out of sync.
  57. *
  58. * A typical example is that the target was power cycled while OpenOCD
  59. * thought the target was halted or running.
  60. *
  61. * assert_reset() can therefore make no assumptions whatsoever about the
  62. * state of the target
  63. *
  64. * Before assert_reset() for the target is invoked, a TRST/tms and
  65. * chain validation is executed. TRST should not be asserted
  66. * during target assert unless there is no way around it due to
  67. * the way reset's are configured.
  68. *
  69. */
  70. int (*assert_reset)(struct target_s *target);
  71. int (*deassert_reset)(struct target_s *target);
  72. int (*soft_reset_halt_imp)(struct target_s *target);
  73. int (*soft_reset_halt)(struct target_s *target);
  74. /**
  75. * Target register access for GDB. Do @b not call this function
  76. * directly, use target_get_gdb_reg_list() instead.
  77. *
  78. * Danger! this function will succeed even if the target is running
  79. * and return a register list with dummy values.
  80. *
  81. * The reason is that GDB connection will fail without a valid register
  82. * list, however it is after GDB is connected that monitor commands can
  83. * be run to properly initialize the target
  84. */
  85. int (*get_gdb_reg_list)(struct target_s *target, struct reg_s **reg_list[], int *reg_list_size);
  86. /* target memory access
  87. * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit)
  88. * count: number of items of <size>
  89. */
  90. int (*read_memory_imp)(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  91. /**
  92. * Target memory read callback. Do @b not call this function
  93. * directly, use target_read_memory() instead.
  94. */
  95. int (*read_memory)(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  96. int (*write_memory_imp)(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  97. /**
  98. * Target memory write callback. Do @b not call this function
  99. * directly, use target_write_memory() instead.
  100. */
  101. int (*write_memory)(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  102. /**
  103. * Write target memory in multiples of 4 bytes, optimized for
  104. * writing large quantities of data. Do @b not call this
  105. * function directly, use target_bulk_write_memory() instead.
  106. */
  107. int (*bulk_write_memory)(struct target_s *target, uint32_t address, uint32_t count, uint8_t *buffer);
  108. int (*checksum_memory)(struct target_s *target, uint32_t address, uint32_t count, uint32_t* checksum);
  109. int (*blank_check_memory)(struct target_s *target, uint32_t address, uint32_t count, uint32_t* blank);
  110. /*
  111. * target break-/watchpoint control
  112. * rw: 0 = write, 1 = read, 2 = access
  113. *
  114. * Target must be halted while this is invoked as this
  115. * will actually set up breakpoints on target.
  116. *
  117. * The breakpoint hardware will be set up upon adding the first breakpoint.
  118. *
  119. * Upon GDB connection all breakpoints/watchpoints are cleared.
  120. */
  121. int (*add_breakpoint)(struct target_s *target, struct breakpoint *breakpoint);
  122. /* remove breakpoint. hw will only be updated if the target is currently halted.
  123. * However, this method can be invoked on unresponsive targets.
  124. */
  125. int (*remove_breakpoint)(struct target_s *target, struct breakpoint *breakpoint);
  126. int (*add_watchpoint)(struct target_s *target, struct watchpoint *watchpoint);
  127. /* remove watchpoint. hw will only be updated if the target is currently halted.
  128. * However, this method can be invoked on unresponsive targets.
  129. */
  130. int (*remove_watchpoint)(struct target_s *target, struct watchpoint *watchpoint);
  131. /* target algorithm support */
  132. int (*run_algorithm_imp)(struct target_s *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);
  133. /**
  134. * Target algorithm support. Do @b not call this method directly,
  135. * use target_run_algorithm() instead.
  136. */
  137. int (*run_algorithm)(struct target_s *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);
  138. int (*register_commands)(struct command_context_s *cmd_ctx);
  139. /* called when target is created */
  140. int (*target_create)(struct target_s *target, Jim_Interp *interp);
  141. /* called for various config parameters */
  142. /* returns JIM_CONTINUE - if option not understood */
  143. /* otherwise: JIM_OK, or JIM_ERR, */
  144. int (*target_jim_configure)(struct target_s *target, Jim_GetOptInfo *goi);
  145. /* target commands specifically handled by the target */
  146. /* returns JIM_OK, or JIM_ERR, or JIM_CONTINUE - if option not understood */
  147. int (*target_jim_commands)(struct target_s *target, Jim_GetOptInfo *goi);
  148. /* invoked after JTAG chain has been examined & validated. During
  149. * this stage the target is examined and any additional setup is
  150. * performed.
  151. *
  152. * invoked every time after the jtag chain has been validated/examined
  153. */
  154. int (*examine)(struct target_s *target);
  155. /* Set up structures for target.
  156. *
  157. * It is illegal to talk to the target at this stage as this fn is invoked
  158. * before the JTAG chain has been examined/verified
  159. * */
  160. int (*init_target)(struct command_context_s *cmd_ctx, struct target_s *target);
  161. /* translate from virtual to physical address. Default implementation is successful
  162. * no-op(i.e. virtual==physical).
  163. */
  164. int (*virt2phys)(struct target_s *target, uint32_t address, uint32_t *physical);
  165. /* read directly from physical memory. caches are bypassed and untouched.
  166. *
  167. * If the target does not support disabling caches, leaving them untouched,
  168. * then minimally the actual physical memory location will be read even
  169. * if cache states are unchanged, flushed, etc.
  170. *
  171. * Default implementation is to call read_memory.
  172. */
  173. int (*read_phys_memory)(struct target_s *target, uint32_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer);
  174. /*
  175. * same as read_phys_memory, except that it writes...
  176. */
  177. int (*write_phys_memory)(struct target_s *target, uint32_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer);
  178. int (*mmu)(struct target_s *target, int *enabled);
  179. /* Read coprocessor - arm specific. Default implementation returns error. */
  180. int (*mrc)(struct target_s *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t *value);
  181. /* Write coprocessor. Default implementation returns error. */
  182. int (*mcr)(struct target_s *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t value);
  183. };
  184. #endif // TARGET_TYPE_H