Remove FSF address from GPL notices
[openocd.git] / src / target / target_type.h
blob3ad6ab0ad340ffdc147712cdc784467d8396ac68
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 ***************************************************************************/
25 #ifndef TARGET_TYPE_H
26 #define TARGET_TYPE_H
28 #include <jim-nvp.h>
30 struct target;
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.
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.
42 const char *name;
43 const char *deprecated_name;
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);
51 /* target request support */
52 int (*target_request_data)(struct target *target, uint32_t size, uint8_t *buffer);
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, uint32_t address,
57 int handle_breakpoints, int debug_execution);
58 int (*step)(struct target *target, int current, uint32_t address,
59 int handle_breakpoints);
61 /* target reset control. assert reset can be invoked when OpenOCD and
62 * the target is out of sync.
64 * A typical example is that the target was power cycled while OpenOCD
65 * thought the target was halted or running.
67 * assert_reset() can therefore make no assumptions whatsoever about the
68 * state of the target
70 * Before assert_reset() for the target is invoked, a TRST/tms and
71 * chain validation is executed. TRST should not be asserted
72 * during target assert unless there is no way around it due to
73 * the way reset's are configured.
76 int (*assert_reset)(struct target *target);
77 /**
78 * The implementation is responsible for polling the
79 * target such that target->state reflects the
80 * state correctly.
82 * Otherwise the following would fail, as there will not
83 * be any "poll" invoked inbetween the "reset run" and
84 * "halt".
86 * reset run; halt
88 int (*deassert_reset)(struct target *target);
89 int (*soft_reset_halt)(struct target *target);
91 /**
92 * Target register access for GDB. Do @b not call this function
93 * directly, use target_get_gdb_reg_list() instead.
95 * Danger! this function will succeed even if the target is running
96 * and return a register list with dummy values.
98 * The reason is that GDB connection will fail without a valid register
99 * list, however it is after GDB is connected that monitor commands can
100 * be run to properly initialize the target
102 int (*get_gdb_reg_list)(struct target *target, struct reg **reg_list[],
103 int *reg_list_size, enum target_register_class reg_class);
105 /* target memory access
106 * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit)
107 * count: number of items of <size>
111 * Target memory read callback. Do @b not call this function
112 * directly, use target_read_memory() instead.
114 int (*read_memory)(struct target *target, uint32_t address,
115 uint32_t size, uint32_t count, uint8_t *buffer);
117 * Target memory write callback. Do @b not call this function
118 * directly, use target_write_memory() instead.
120 int (*write_memory)(struct target *target, uint32_t address,
121 uint32_t size, uint32_t count, const uint8_t *buffer);
123 /* Default implementation will do some fancy alignment to improve performance, target can override */
124 int (*read_buffer)(struct target *target, uint32_t address,
125 uint32_t size, uint8_t *buffer);
127 /* Default implementation will do some fancy alignment to improve performance, target can override */
128 int (*write_buffer)(struct target *target, uint32_t address,
129 uint32_t size, const uint8_t *buffer);
131 int (*checksum_memory)(struct target *target, uint32_t address,
132 uint32_t count, uint32_t *checksum);
133 int (*blank_check_memory)(struct target *target, uint32_t address,
134 uint32_t count, uint32_t *blank);
137 * target break-/watchpoint control
138 * rw: 0 = write, 1 = read, 2 = access
140 * Target must be halted while this is invoked as this
141 * will actually set up breakpoints on target.
143 * The breakpoint hardware will be set up upon adding the
144 * first breakpoint.
146 * Upon GDB connection all breakpoints/watchpoints are cleared.
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);
152 /* remove breakpoint. hw will only be updated if the target
153 * is currently halted.
154 * However, this method can be invoked on unresponsive targets.
156 int (*remove_breakpoint)(struct target *target, struct breakpoint *breakpoint);
158 /* add watchpoint ... see add_breakpoint() comment above. */
159 int (*add_watchpoint)(struct target *target, struct watchpoint *watchpoint);
161 /* remove watchpoint. hw will only be updated if the target
162 * is currently halted.
163 * However, this method can be invoked on unresponsive targets.
165 int (*remove_watchpoint)(struct target *target, struct watchpoint *watchpoint);
167 /* Find out just hit watchpoint. After the target hits a watchpoint, the
168 * information could assist gdb to locate where the modified/accessed memory is.
170 int (*hit_watchpoint)(struct target *target, struct watchpoint **hit_watchpoint);
173 * Target algorithm support. Do @b not call this method directly,
174 * use target_run_algorithm() instead.
176 int (*run_algorithm)(struct target *target, int num_mem_params,
177 struct mem_param *mem_params, int num_reg_params,
178 struct reg_param *reg_param, uint32_t entry_point,
179 uint32_t exit_point, int timeout_ms, void *arch_info);
180 int (*start_algorithm)(struct target *target, int num_mem_params,
181 struct mem_param *mem_params, int num_reg_params,
182 struct reg_param *reg_param, uint32_t entry_point,
183 uint32_t exit_point, void *arch_info);
184 int (*wait_algorithm)(struct target *target, int num_mem_params,
185 struct mem_param *mem_params, int num_reg_params,
186 struct reg_param *reg_param, uint32_t exit_point,
187 int timeout_ms, void *arch_info);
189 const struct command_registration *commands;
191 /* called when target is created */
192 int (*target_create)(struct target *target, Jim_Interp *interp);
194 /* called for various config parameters */
195 /* returns JIM_CONTINUE - if option not understood */
196 /* otherwise: JIM_OK, or JIM_ERR, */
197 int (*target_jim_configure)(struct target *target, Jim_GetOptInfo *goi);
199 /* target commands specifically handled by the target */
200 /* returns JIM_OK, or JIM_ERR, or JIM_CONTINUE - if option not understood */
201 int (*target_jim_commands)(struct target *target, Jim_GetOptInfo *goi);
204 * This method is used to perform target setup that requires
205 * JTAG access.
207 * This may be called multiple times. It is called after the
208 * scan chain is initially validated, or later after the target
209 * is enabled by a JRC. It may also be called during some
210 * parts of the reset sequence.
212 * For one-time initialization tasks, use target_was_examined()
213 * and target_set_examined(). For example, probe the hardware
214 * before setting up chip-specific state, and then set that
215 * flag so you don't do that again.
217 int (*examine)(struct target *target);
219 /* Set up structures for target.
221 * It is illegal to talk to the target at this stage as this fn is invoked
222 * before the JTAG chain has been examined/verified
223 * */
224 int (*init_target)(struct command_context *cmd_ctx, struct target *target);
227 * Free all the resources allocated by the target.
229 * @param target The target to deinit
231 void (*deinit_target)(struct target *target);
233 /* translate from virtual to physical address. Default implementation is successful
234 * no-op(i.e. virtual==physical).
236 int (*virt2phys)(struct target *target, uint32_t address, uint32_t *physical);
238 /* read directly from physical memory. caches are bypassed and untouched.
240 * If the target does not support disabling caches, leaving them untouched,
241 * then minimally the actual physical memory location will be read even
242 * if cache states are unchanged, flushed, etc.
244 * Default implementation is to call read_memory.
246 int (*read_phys_memory)(struct target *target, uint32_t phys_address,
247 uint32_t size, uint32_t count, uint8_t *buffer);
250 * same as read_phys_memory, except that it writes...
252 int (*write_phys_memory)(struct target *target, uint32_t phys_address,
253 uint32_t size, uint32_t count, const uint8_t *buffer);
255 int (*mmu)(struct target *target, int *enabled);
257 /* after reset is complete, the target can check if things are properly set up.
259 * This can be used to check if e.g. DCC memory writes have been enabled for
260 * arm7/9 targets, which they really should except in the most contrived
261 * circumstances.
263 int (*check_reset)(struct target *target);
265 /* get GDB file-I/O parameters from target
267 int (*get_gdb_fileio_info)(struct target *target, struct gdb_fileio_info *fileio_info);
269 /* pass GDB file-I/O response to target
271 int (*gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c);
273 /* do target profiling
275 int (*profiling)(struct target *target, uint32_t *samples,
276 uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds);
279 #endif /* TARGET_TYPE_H */