OpenOCD
target_type.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2007-2010 Øyvind Harboe *
8  * oyvind.harboe@zylin.com *
9  * *
10  * Copyright (C) 2008 by Spencer Oliver *
11  * spen@spen-soft.co.uk *
12  ***************************************************************************/
13 
14 #ifndef OPENOCD_TARGET_TARGET_TYPE_H
15 #define OPENOCD_TARGET_TARGET_TYPE_H
16 
17 #include <helper/jim-nvp.h>
18 
19 struct target;
20 
26 struct target_type {
31  const char *name;
32 
33  /* poll current target status */
34  int (*poll)(struct target *target);
35  /* Invoked only from target_arch_state().
36  * Issue USER() w/architecture specific status. */
37  int (*arch_state)(struct target *target);
38 
39  /* target request support */
40  int (*target_request_data)(struct target *target, uint32_t size, uint8_t *buffer);
41 
42  /* halt will log a warning, but return ERROR_OK if the target is already halted. */
43  int (*halt)(struct target *target);
44  /* See target.c target_resume() for documentation. */
45  int (*resume)(struct target *target, bool current, target_addr_t address,
46  bool handle_breakpoints, bool debug_execution);
47  int (*step)(struct target *target, bool current, target_addr_t address,
48  bool handle_breakpoints);
49  /* target reset control. assert reset can be invoked when OpenOCD and
50  * the target is out of sync.
51  *
52  * A typical example is that the target was power cycled while OpenOCD
53  * thought the target was halted or running.
54  *
55  * assert_reset() can therefore make no assumptions whatsoever about the
56  * state of the target
57  *
58  * Before assert_reset() for the target is invoked, a TRST/tms and
59  * chain validation is executed. TRST should not be asserted
60  * during target assert unless there is no way around it due to
61  * the way reset's are configured.
62  *
63  */
64  int (*assert_reset)(struct target *target);
76  int (*deassert_reset)(struct target *target);
77  int (*soft_reset_halt)(struct target *target);
78 
86  const char *(*get_gdb_arch)(const struct target *target);
87 
99  int (*get_gdb_reg_list)(struct target *target, struct reg **reg_list[],
100  int *reg_list_size, enum target_register_class reg_class);
101 
106  struct reg **reg_list[], int *reg_list_size,
107  enum target_register_class reg_class);
108 
109  /* target memory access
110  * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit)
111  * count: number of items of <size>
112  */
113 
119  bool (*memory_ready)(struct target *target);
125  uint32_t size, uint32_t count, uint8_t *buffer);
131  uint32_t size, uint32_t count, const uint8_t *buffer);
132 
133  /* Default implementation will do some fancy alignment to improve performance, target can override */
135  uint32_t size, uint8_t *buffer);
136 
137  /* Default implementation will do some fancy alignment to improve performance, target can override */
139  uint32_t size, const uint8_t *buffer);
140 
142  uint32_t count, uint32_t *checksum);
144  struct target_memory_check_block *blocks, int num_blocks,
145  uint8_t erased_value);
146 
147  /*
148  * target break-/watchpoint control
149  * rw: 0 = write, 1 = read, 2 = access
150  *
151  * Target must be halted while this is invoked as this
152  * will actually set up breakpoints on target.
153  *
154  * The breakpoint hardware will be set up upon adding the
155  * first breakpoint.
156  *
157  * Upon GDB connection all breakpoints/watchpoints are cleared.
158  */
162 
163  /* remove breakpoint. hw will only be updated if the target
164  * is currently halted.
165  * However, this method can be invoked on unresponsive targets.
166  */
168 
169  /* add watchpoint ... see add_breakpoint() comment above. */
171 
172  /* remove watchpoint. hw will only be updated if the target
173  * is currently halted.
174  * However, this method can be invoked on unresponsive targets.
175  */
177 
178  /* Find out just hit watchpoint. After the target hits a watchpoint, the
179  * information could assist gdb to locate where the modified/accessed memory is.
180  */
182 
187  int (*run_algorithm)(struct target *target, int num_mem_params,
188  struct mem_param *mem_params, int num_reg_params,
189  struct reg_param *reg_param, target_addr_t entry_point,
190  target_addr_t exit_point, unsigned int timeout_ms, void *arch_info);
191  int (*start_algorithm)(struct target *target, int num_mem_params,
192  struct mem_param *mem_params, int num_reg_params,
193  struct reg_param *reg_param, target_addr_t entry_point,
194  target_addr_t exit_point, void *arch_info);
195  int (*wait_algorithm)(struct target *target, int num_mem_params,
196  struct mem_param *mem_params, int num_reg_params,
197  struct reg_param *reg_param, target_addr_t exit_point,
198  unsigned int timeout_ms, void *arch_info);
199 
201 
202  /* called when target is created */
203  int (*target_create)(struct target *target);
204 
205  /* called for various config parameters */
206  /* returns JIM_CONTINUE - if option not understood */
207  /* otherwise: JIM_OK, or JIM_ERR, */
208  int (*target_jim_configure)(struct target *target, struct jim_getopt_info *goi);
209 
224  int (*examine)(struct target *target);
225 
226  /* Set up structures for target.
227  *
228  * It is illegal to talk to the target at this stage as this fn is invoked
229  * before the JTAG chain has been examined/verified
230  * */
231  int (*init_target)(struct command_context *cmd_ctx, struct target *target);
232 
249  void (*deinit_target)(struct target *target);
250 
251  /* translate from virtual to physical address. Default implementation is successful
252  * no-op(i.e. virtual==physical).
253  */
255 
256  /* read directly from physical memory. caches are bypassed and untouched.
257  *
258  * If the target does not support disabling caches, leaving them untouched,
259  * then minimally the actual physical memory location will be read even
260  * if cache states are unchanged, flushed, etc.
261  *
262  * Default implementation is to call read_memory.
263  */
264  int (*read_phys_memory)(struct target *target, target_addr_t phys_address,
265  uint32_t size, uint32_t count, uint8_t *buffer);
266 
267  /*
268  * same as read_phys_memory, except that it writes...
269  */
270  int (*write_phys_memory)(struct target *target, target_addr_t phys_address,
271  uint32_t size, uint32_t count, const uint8_t *buffer);
272 
273  int (*mmu)(struct target *target, bool *enabled);
274 
275  /* after reset is complete, the target can check if things are properly set up.
276  *
277  * This can be used to check if e.g. DCC memory writes have been enabled for
278  * arm7/9 targets, which they really should except in the most contrived
279  * circumstances.
280  */
281  int (*check_reset)(struct target *target);
282 
283  /* get GDB file-I/O parameters from target
284  */
285  int (*get_gdb_fileio_info)(struct target *target, struct gdb_fileio_info *fileio_info);
286 
287  /* pass GDB file-I/O response to target
288  */
289  int (*gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c);
290 
291  /* Parse target-specific GDB query commands.
292  * The string pointer "response_p" is always assigned by the called function
293  * to a pointer to a NULL-terminated string, even when the function returns
294  * an error. The string memory is not freed by the caller, so this function
295  * must pay attention for possible memory leaks if the string memory is
296  * dynamically allocated.
297  */
298  int (*gdb_query_custom)(struct target *target, const char *packet, char **response_p);
299 
300  /* do target profiling
301  */
302  int (*profiling)(struct target *target, uint32_t *samples,
303  uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds);
304 
305  /* Return the number of address bits this target supports. This will
306  * typically be 32 for 32-bit targets, and 64 for 64-bit targets. If not
307  * implemented, it's assumed to be 32. */
308  unsigned int (*address_bits)(struct target *target);
309 
310  /* Return the number of system bus data bits this target supports. This
311  * will typically be 32 for 32-bit targets, and 64 for 64-bit targets. If
312  * not implemented, it's assumed to be 32. */
313  unsigned int (*data_bits)(struct target *target);
314 };
315 
316 // Keep in alphabetic order this list of targets
317 extern struct target_type aarch64_target;
318 extern struct target_type arcv2_target;
319 extern struct target_type arm11_target;
320 extern struct target_type arm720t_target;
321 extern struct target_type arm7tdmi_target;
322 extern struct target_type arm920t_target;
323 extern struct target_type arm926ejs_target;
324 extern struct target_type arm946e_target;
325 extern struct target_type arm966e_target;
326 extern struct target_type arm9tdmi_target;
327 extern struct target_type armv8r_target;
328 extern struct target_type avr32_ap7k_target;
329 extern struct target_type avr_target;
330 extern struct target_type cortexa_target;
331 extern struct target_type cortexm_target;
332 extern struct target_type cortexr4_target;
333 extern struct target_type dragonite_target;
334 extern struct target_type dsp563xx_target;
335 extern struct target_type dsp5680xx_target;
336 extern struct target_type esirisc_target;
337 extern struct target_type esp32s2_target;
338 extern struct target_type esp32s3_target;
339 extern struct target_type esp32_target;
340 extern struct target_type fa526_target;
341 extern struct target_type feroceon_target;
342 extern struct target_type hla_target;
343 extern struct target_type ls1_sap_target;
344 extern struct target_type mem_ap_target;
345 extern struct target_type mips_m4k_target;
346 extern struct target_type mips_mips64_target;
347 extern struct target_type or1k_target;
348 extern struct target_type quark_d20xx_target;
349 extern struct target_type quark_x10xx_target;
350 extern struct target_type riscv_target;
351 extern struct target_type stm8_target;
352 extern struct target_type testee_target;
353 extern struct target_type xscale_target;
354 extern struct target_type xtensa_chip_target;
355 
356 #endif /* OPENOCD_TARGET_TARGET_TYPE_H */
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
struct target * target
Definition: rtt/rtt.c:26
A TCL -ish GetOpt like code.
Definition: jim-nvp.h:136
Definition: register.h:111
This holds methods shared between all instances of a given target type.
Definition: target_type.h:26
int(* add_context_breakpoint)(struct target *target, struct breakpoint *breakpoint)
Definition: target_type.h:160
int(* add_breakpoint)(struct target *target, struct breakpoint *breakpoint)
Definition: target_type.h:159
int(* write_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Target memory write callback.
Definition: target_type.h:130
int(* hit_watchpoint)(struct target *target, struct watchpoint **hit_watchpoint)
Definition: target_type.h:181
const char * name
Name of this type of target.
Definition: target_type.h:31
int(* deassert_reset)(struct target *target)
The implementation is responsible for polling the target such that target->state reflects the state c...
Definition: target_type.h:76
int(* init_target)(struct command_context *cmd_ctx, struct target *target)
Definition: target_type.h:231
int(* get_gdb_reg_list)(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Target register access for GDB.
Definition: target_type.h:99
int(* target_request_data)(struct target *target, uint32_t size, uint8_t *buffer)
Definition: target_type.h:40
int(* resume)(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Definition: target_type.h:45
void(* deinit_target)(struct target *target)
Free all the resources allocated by the target.
Definition: target_type.h:249
int(* halt)(struct target *target)
Definition: target_type.h:43
int(* check_reset)(struct target *target)
Definition: target_type.h:281
int(* gdb_fileio_end)(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
Definition: target_type.h:289
int(* blank_check_memory)(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Definition: target_type.h:143
int(* assert_reset)(struct target *target)
Definition: target_type.h:64
int(* run_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Target algorithm support.
Definition: target_type.h:187
int(* wait_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Definition: target_type.h:195
const struct command_registration * commands
Definition: target_type.h:200
int(* profiling)(struct target *target, uint32_t *samples, uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
Definition: target_type.h:302
int(* soft_reset_halt)(struct target *target)
Definition: target_type.h:77
int(* arch_state)(struct target *target)
Definition: target_type.h:37
unsigned int(* address_bits)(struct target *target)
Definition: target_type.h:308
int(* read_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Target memory read callback.
Definition: target_type.h:124
int(* get_gdb_fileio_info)(struct target *target, struct gdb_fileio_info *fileio_info)
Definition: target_type.h:285
unsigned int(* data_bits)(struct target *target)
Definition: target_type.h:313
int(* target_jim_configure)(struct target *target, struct jim_getopt_info *goi)
Definition: target_type.h:208
int(* step)(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Definition: target_type.h:47
int(* read_phys_memory)(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: target_type.h:264
int(* get_gdb_reg_list_noread)(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Same as get_gdb_reg_list, but doesn't read the register values.
Definition: target_type.h:105
int(* start_algorithm)(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, void *arch_info)
Definition: target_type.h:191
int(* read_buffer)(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: target_type.h:134
int(* add_watchpoint)(struct target *target, struct watchpoint *watchpoint)
Definition: target_type.h:170
int(* target_create)(struct target *target)
Definition: target_type.h:203
bool(* memory_ready)(struct target *target)
Returns true if target memory is read to read/write.
Definition: target_type.h:119
int(* write_buffer)(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target_type.h:138
int(* poll)(struct target *target)
Definition: target_type.h:34
int(* mmu)(struct target *target, bool *enabled)
Definition: target_type.h:273
int(* add_hybrid_breakpoint)(struct target *target, struct breakpoint *breakpoint)
Definition: target_type.h:161
int(* examine)(struct target *target)
This method is used to perform target setup that requires JTAG access.
Definition: target_type.h:224
int(* write_phys_memory)(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: target_type.h:270
int(* remove_breakpoint)(struct target *target, struct breakpoint *breakpoint)
Definition: target_type.h:167
int(* gdb_query_custom)(struct target *target, const char *packet, char **response_p)
Definition: target_type.h:298
int(* virt2phys)(struct target *target, target_addr_t address, target_addr_t *physical)
Definition: target_type.h:254
int(* checksum_memory)(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Definition: target_type.h:141
int(* remove_watchpoint)(struct target *target, struct watchpoint *watchpoint)
Definition: target_type.h:176
Definition: target.h:119
target_register_class
Definition: target.h:113
struct target_type esp32s3_target
Holds methods for Xtensa targets.
Definition: esp32s3.c:382
struct target_type arm966e_target
Holds methods for ARM966 targets.
Definition: arm966e.c:245
struct target_type avr32_ap7k_target
Definition: avr32_ap7k.c:581
struct target_type testee_target
Definition: testee.c:53
struct target_type esirisc_target
Definition: esirisc.c:1834
struct target_type cortexm_target
Definition: cortex_m.c:3461
struct target_type arm926ejs_target
Holds methods for ARM926 targets.
Definition: arm926ejs.c:789
struct target_type mem_ap_target
Definition: mem_ap.c:265
struct target_type dragonite_target
Definition: feroceon.c:730
struct target_type stm8_target
Definition: stm8.c:2202
struct target_type arcv2_target
Definition: arc.c:2321
struct target_type cortexr4_target
Definition: cortex_a.c:3540
struct target_type quark_d20xx_target
Definition: quark_d20xx.c:79
struct target_type mips_mips64_target
Definition: mips_mips64.c:1151
struct target_type feroceon_target
Definition: feroceon.c:691
struct target_type arm9tdmi_target
Holds methods for ARM9TDMI targets.
Definition: arm9tdmi.c:888
struct target_type or1k_target
Definition: or1k.c:1416
struct target_type quark_x10xx_target
Definition: quark_x10xx.c:57
struct target_type esp32s2_target
Definition: esp32s2.c:498
struct target_type riscv_target
Definition: riscv.c:5892
struct target_type esp32_target
Holds methods for Xtensa targets.
Definition: esp32.c:461
struct target_type xtensa_chip_target
Methods for generic example of Xtensa-based chip-level targets.
Definition: xtensa_chip.c:151
struct target_type aarch64_target
Definition: aarch64.c:3279
struct target_type arm946e_target
Holds methods for ARM946 targets.
Definition: arm946e.c:738
struct target_type arm11_target
Holds methods for ARM11xx targets.
Definition: arm11.c:1341
struct target_type arm7tdmi_target
Holds methods for ARM7TDMI targets.
Definition: arm7tdmi.c:684
struct target_type arm920t_target
Holds methods for ARM920 targets.
Definition: arm920t.c:1592
struct target_type arm720t_target
Holds methods for ARM720 targets.
Definition: arm720t.c:462
struct target_type avr_target
Definition: avrt.c:39
struct target_type mips_m4k_target
Definition: mips_m4k.c:1451
struct target_type hla_target
Definition: hla_target.c:645
struct target_type armv8r_target
Definition: aarch64.c:3320
struct target_type dsp5680xx_target
Holds methods for dsp5680xx targets.
Definition: dsp5680xx.c:2245
struct target_type dsp563xx_target
Holds methods for DSP563XX targets.
Definition: dsp563xx.c:2248
struct target_type fa526_target
Holds methods for FA526 targets.
Definition: fa526.c:350
struct target_type ls1_sap_target
Definition: ls1_sap.c:216
struct target_type cortexa_target
Definition: cortex_a.c:3460
struct target_type xscale_target
Definition: xscale.c:3701
uint64_t target_addr_t
Definition: types.h:279
uint8_t count[4]
Definition: vdebug.c:22