34e2778ad0c53d9e06c3937066add6b30a0e37f2
[openocd.git] / src / target / target_type.h
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
25 #ifndef OPENOCD_TARGET_TARGET_TYPE_H
26 #define OPENOCD_TARGET_TARGET_TYPE_H
27
28 #include <jim-nvp.h>
29
30 struct target;
31
32 /**
33 * This holds methods shared between all instances of a given target
34 * type. For example, all Cortex-M3 targets on a scan chain share
35 * the same method table.
36 */
37 struct target_type {
38 /**
39 * Name of this type of target. Do @b not access this
40 * field directly, use target_type_name() instead.
41 */
42 const char *name;
43 const char *deprecated_name;
44
45 /* poll current target status */
46 int (*poll)(struct target *target);
47 /* Invoked only from target_arch_state().
48 * Issue USER() w/architecture specific status. */
49 int (*arch_state)(struct target *target);
50
51 /* target request support */
52 int (*target_request_data)(struct target *target, uint32_t size, uint8_t *buffer);
53
54 /* halt will log a warning, but return ERROR_OK if the target is already halted. */
55 int (*halt)(struct target *target);
56 int (*resume)(struct target *target, int current, target_addr_t address,
57 int handle_breakpoints, int debug_execution);
58 int (*step)(struct target *target, int current, target_addr_t address,
59 int handle_breakpoints);
60 /* target reset control. assert reset can be invoked when OpenOCD and
61 * the target is out of sync.
62 *
63 * A typical example is that the target was power cycled while OpenOCD
64 * thought the target was halted or running.
65 *
66 * assert_reset() can therefore make no assumptions whatsoever about the
67 * state of the target
68 *
69 * Before assert_reset() for the target is invoked, a TRST/tms and
70 * chain validation is executed. TRST should not be asserted
71 * during target assert unless there is no way around it due to
72 * the way reset's are configured.
73 *
74 */
75 int (*assert_reset)(struct target *target);
76 /**
77 * The implementation is responsible for polling the
78 * target such that target->state reflects the
79 * state correctly.
80 *
81 * Otherwise the following would fail, as there will not
82 * be any "poll" invoked inbetween the "reset run" and
83 * "halt".
84 *
85 * reset run; halt
86 */
87 int (*deassert_reset)(struct target *target);
88 int (*soft_reset_halt)(struct target *target);
89
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 /* target memory access
105 * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit)
106 * count: number of items of <size>
107 */
108
109 /**
110 * Target memory read callback. Do @b not call this function
111 * directly, use target_read_memory() instead.
112 */
113 int (*read_memory)(struct target *target, target_addr_t address,
114 uint32_t size, uint32_t count, uint8_t *buffer);
115 /**
116 * Target memory write callback. Do @b not call this function
117 * directly, use target_write_memory() instead.
118 */
119 int (*write_memory)(struct target *target, target_addr_t address,
120 uint32_t size, uint32_t count, const uint8_t *buffer);
121
122 /* Default implementation will do some fancy alignment to improve performance, target can override */
123 int (*read_buffer)(struct target *target, target_addr_t address,
124 uint32_t size, uint8_t *buffer);
125
126 /* Default implementation will do some fancy alignment to improve performance, target can override */
127 int (*write_buffer)(struct target *target, target_addr_t address,
128 uint32_t size, const uint8_t *buffer);
129
130 int (*checksum_memory)(struct target *target, target_addr_t address,
131 uint32_t count, uint32_t *checksum);
132 int (*blank_check_memory)(struct target *target, target_addr_t address,
133 uint32_t count, uint32_t *blank, uint8_t erased_value);
134
135 /*
136 * target break-/watchpoint control
137 * rw: 0 = write, 1 = read, 2 = access
138 *
139 * Target must be halted while this is invoked as this
140 * will actually set up breakpoints on target.
141 *
142 * The breakpoint hardware will be set up upon adding the
143 * first breakpoint.
144 *
145 * Upon GDB connection all breakpoints/watchpoints are cleared.
146 */
147 int (*add_breakpoint)(struct target *target, struct breakpoint *breakpoint);
148 int (*add_context_breakpoint)(struct target *target, struct breakpoint *breakpoint);
149 int (*add_hybrid_breakpoint)(struct target *target, struct breakpoint *breakpoint);
150
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
157 /* add watchpoint ... see add_breakpoint() comment above. */
158 int (*add_watchpoint)(struct target *target, struct watchpoint *watchpoint);
159
160 /* remove watchpoint. hw will only be updated if the target
161 * is currently halted.
162 * However, this method can be invoked on unresponsive targets.
163 */
164 int (*remove_watchpoint)(struct target *target, struct watchpoint *watchpoint);
165
166 /* Find out just hit watchpoint. After the target hits a watchpoint, the
167 * information could assist gdb to locate where the modified/accessed memory is.
168 */
169 int (*hit_watchpoint)(struct target *target, struct watchpoint **hit_watchpoint);
170
171 /**
172 * Target algorithm support. Do @b not call this method directly,
173 * use target_run_algorithm() instead.
174 */
175 int (*run_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, int timeout_ms, void *arch_info);
179 int (*start_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 entry_point,
182 target_addr_t exit_point, void *arch_info);
183 int (*wait_algorithm)(struct target *target, int num_mem_params,
184 struct mem_param *mem_params, int num_reg_params,
185 struct reg_param *reg_param, target_addr_t exit_point,
186 int timeout_ms, void *arch_info);
187
188 const struct command_registration *commands;
189
190 /* called when target is created */
191 int (*target_create)(struct target *target, Jim_Interp *interp);
192
193 /* called for various config parameters */
194 /* returns JIM_CONTINUE - if option not understood */
195 /* otherwise: JIM_OK, or JIM_ERR, */
196 int (*target_jim_configure)(struct target *target, Jim_GetOptInfo *goi);
197
198 /* target commands specifically handled by the target */
199 /* returns JIM_OK, or JIM_ERR, or JIM_CONTINUE - if option not understood */
200 int (*target_jim_commands)(struct target *target, Jim_GetOptInfo *goi);
201
202 /**
203 * This method is used to perform target setup that requires
204 * JTAG access.
205 *
206 * This may be called multiple times. It is called after the
207 * scan chain is initially validated, or later after the target
208 * is enabled by a JRC. It may also be called during some
209 * parts of the reset sequence.
210 *
211 * For one-time initialization tasks, use target_was_examined()
212 * and target_set_examined(). For example, probe the hardware
213 * before setting up chip-specific state, and then set that
214 * flag so you don't do that again.
215 */
216 int (*examine)(struct target *target);
217
218 /* Set up structures for target.
219 *
220 * It is illegal to talk to the target at this stage as this fn is invoked
221 * before the JTAG chain has been examined/verified
222 * */
223 int (*init_target)(struct command_context *cmd_ctx, struct target *target);
224
225 /**
226 * Free all the resources allocated by the target.
227 *
228 * @param target The target to deinit
229 */
230 void (*deinit_target)(struct target *target);
231
232 /* translate from virtual to physical address. Default implementation is successful
233 * no-op(i.e. virtual==physical).
234 */
235 int (*virt2phys)(struct target *target, target_addr_t address, target_addr_t *physical);
236
237 /* read directly from physical memory. caches are bypassed and untouched.
238 *
239 * If the target does not support disabling caches, leaving them untouched,
240 * then minimally the actual physical memory location will be read even
241 * if cache states are unchanged, flushed, etc.
242 *
243 * Default implementation is to call read_memory.
244 */
245 int (*read_phys_memory)(struct target *target, target_addr_t phys_address,
246 uint32_t size, uint32_t count, uint8_t *buffer);
247
248 /*
249 * same as read_phys_memory, except that it writes...
250 */
251 int (*write_phys_memory)(struct target *target, target_addr_t phys_address,
252 uint32_t size, uint32_t count, const uint8_t *buffer);
253
254 int (*mmu)(struct target *target, int *enabled);
255
256 /* after reset is complete, the target can check if things are properly set up.
257 *
258 * This can be used to check if e.g. DCC memory writes have been enabled for
259 * arm7/9 targets, which they really should except in the most contrived
260 * circumstances.
261 */
262 int (*check_reset)(struct target *target);
263
264 /* get GDB file-I/O parameters from target
265 */
266 int (*get_gdb_fileio_info)(struct target *target, struct gdb_fileio_info *fileio_info);
267
268 /* pass GDB file-I/O response to target
269 */
270 int (*gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c);
271
272 /* do target profiling
273 */
274 int (*profiling)(struct target *target, uint32_t *samples,
275 uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds);
276 };
277
278 #endif /* OPENOCD_TARGET_TARGET_TYPE_H */