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