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.
 
 
 
 
 
 

696 lines
26 KiB

  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. * Copyright (C) 2011 by Broadcom Corporation *
  12. * Evan Hunter - ehunter@broadcom.com *
  13. * *
  14. * Copyright (C) ST-Ericsson SA 2011 *
  15. * michel.jaouen@stericsson.com : smp minimum support *
  16. * *
  17. * This program is free software; you can redistribute it and/or modify *
  18. * it under the terms of the GNU General Public License as published by *
  19. * the Free Software Foundation; either version 2 of the License, or *
  20. * (at your option) any later version. *
  21. * *
  22. * This program is distributed in the hope that it will be useful, *
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  25. * GNU General Public License for more details. *
  26. * *
  27. * You should have received a copy of the GNU General Public License *
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  29. ***************************************************************************/
  30. #ifndef OPENOCD_TARGET_TARGET_H
  31. #define OPENOCD_TARGET_TARGET_H
  32. #include <helper/list.h>
  33. struct reg;
  34. struct trace;
  35. struct command_context;
  36. struct breakpoint;
  37. struct watchpoint;
  38. struct mem_param;
  39. struct reg_param;
  40. struct target_list;
  41. struct gdb_fileio_info;
  42. /*
  43. * TARGET_UNKNOWN = 0: we don't know anything about the target yet
  44. * TARGET_RUNNING = 1: the target is executing user code
  45. * TARGET_HALTED = 2: the target is not executing code, and ready to talk to the
  46. * debugger. on an xscale it means that the debug handler is executing
  47. * TARGET_RESET = 3: the target is being held in reset (only a temporary state,
  48. * not sure how this is used with all the recent changes)
  49. * TARGET_DEBUG_RUNNING = 4: the target is running, but it is executing code on
  50. * behalf of the debugger (e.g. algorithm for flashing)
  51. *
  52. * also see: target_state_name();
  53. */
  54. enum target_state {
  55. TARGET_UNKNOWN = 0,
  56. TARGET_RUNNING = 1,
  57. TARGET_HALTED = 2,
  58. TARGET_RESET = 3,
  59. TARGET_DEBUG_RUNNING = 4,
  60. };
  61. enum nvp_assert {
  62. NVP_DEASSERT,
  63. NVP_ASSERT,
  64. };
  65. enum target_reset_mode {
  66. RESET_UNKNOWN = 0,
  67. RESET_RUN = 1, /* reset and let target run */
  68. RESET_HALT = 2, /* reset and halt target out of reset */
  69. RESET_INIT = 3, /* reset and halt target out of reset, then run init script */
  70. };
  71. enum target_debug_reason {
  72. DBG_REASON_DBGRQ = 0,
  73. DBG_REASON_BREAKPOINT = 1,
  74. DBG_REASON_WATCHPOINT = 2,
  75. DBG_REASON_WPTANDBKPT = 3,
  76. DBG_REASON_SINGLESTEP = 4,
  77. DBG_REASON_NOTHALTED = 5,
  78. DBG_REASON_EXIT = 6,
  79. DBG_REASON_UNDEFINED = 7,
  80. };
  81. enum target_endianness {
  82. TARGET_ENDIAN_UNKNOWN = 0,
  83. TARGET_BIG_ENDIAN = 1, TARGET_LITTLE_ENDIAN = 2
  84. };
  85. struct working_area {
  86. target_addr_t address;
  87. uint32_t size;
  88. bool free;
  89. uint8_t *backup;
  90. struct working_area **user;
  91. struct working_area *next;
  92. };
  93. struct gdb_service {
  94. struct target *target;
  95. /* field for smp display */
  96. /* element 0 coreid currently displayed ( 1 till n) */
  97. /* element 1 coreid to be displayed at next resume 1 till n 0 means resume
  98. * all cores core displayed */
  99. int32_t core[2];
  100. };
  101. /* target back off timer */
  102. struct backoff_timer {
  103. int times;
  104. int count;
  105. };
  106. /* split target registers into multiple class */
  107. enum target_register_class {
  108. REG_CLASS_ALL,
  109. REG_CLASS_GENERAL,
  110. };
  111. /* target_type.h contains the full definition of struct target_type */
  112. struct target {
  113. struct target_type *type; /* target type definition (name, access functions) */
  114. const char *cmd_name; /* tcl Name of target */
  115. int target_number; /* DO NOT USE! field to be removed in 2010 */
  116. struct jtag_tap *tap; /* where on the jtag chain is this */
  117. int32_t coreid; /* which device on the TAP? */
  118. /** Should we defer examine to later */
  119. bool defer_examine;
  120. /**
  121. * Indicates whether this target has been examined.
  122. *
  123. * Do @b not access this field directly, use target_was_examined()
  124. * or target_set_examined().
  125. */
  126. bool examined;
  127. /**
  128. * true if the target is currently running a downloaded
  129. * "algorithm" instead of arbitrary user code. OpenOCD code
  130. * invoking algorithms is trusted to maintain correctness of
  131. * any cached state (e.g. for flash status), which arbitrary
  132. * code will have no reason to know about.
  133. */
  134. bool running_alg;
  135. struct target_event_action *event_action;
  136. int reset_halt; /* attempt resetting the CPU into the halted mode? */
  137. uint32_t working_area; /* working area (initialised RAM). Evaluated
  138. * upon first allocation from virtual/physical address. */
  139. bool working_area_virt_spec; /* virtual address specified? */
  140. target_addr_t working_area_virt; /* virtual address */
  141. bool working_area_phys_spec; /* physical address specified? */
  142. target_addr_t working_area_phys; /* physical address */
  143. uint32_t working_area_size; /* size in bytes */
  144. uint32_t backup_working_area; /* whether the content of the working area has to be preserved */
  145. struct working_area *working_areas;/* list of allocated working areas */
  146. enum target_debug_reason debug_reason;/* reason why the target entered debug state */
  147. enum target_endianness endianness; /* target endianness */
  148. /* also see: target_state_name() */
  149. enum target_state state; /* the current backend-state (running, halted, ...) */
  150. struct reg_cache *reg_cache; /* the first register cache of the target (core regs) */
  151. struct breakpoint *breakpoints; /* list of breakpoints */
  152. struct watchpoint *watchpoints; /* list of watchpoints */
  153. struct trace *trace_info; /* generic trace information */
  154. struct debug_msg_receiver *dbgmsg; /* list of debug message receivers */
  155. uint32_t dbg_msg_enabled; /* debug message status */
  156. void *arch_info; /* architecture specific information */
  157. void *private_config; /* pointer to target specific config data (for jim_configure hook) */
  158. struct target *next; /* next target in list */
  159. int display; /* display async info in telnet session. Do not display
  160. * lots of halted/resumed info when stepping in debugger. */
  161. bool halt_issued; /* did we transition to halted state? */
  162. int64_t halt_issued_time; /* Note time when halt was issued */
  163. bool dbgbase_set; /* By default the debug base is not set */
  164. uint32_t dbgbase; /* Really a Cortex-A specific option, but there is no
  165. * system in place to support target specific options
  166. * currently. */
  167. struct rtos *rtos; /* Instance of Real Time Operating System support */
  168. bool rtos_auto_detect; /* A flag that indicates that the RTOS has been specified as "auto"
  169. * and must be detected when symbols are offered */
  170. struct backoff_timer backoff;
  171. int smp; /* add some target attributes for smp support */
  172. struct target_list *head;
  173. /* the gdb service is there in case of smp, we have only one gdb server
  174. * for all smp target
  175. * the target attached to the gdb is changing dynamically by changing
  176. * gdb_service->target pointer */
  177. struct gdb_service *gdb_service;
  178. /* file-I/O information for host to do syscall */
  179. struct gdb_fileio_info *fileio_info;
  180. };
  181. struct target_list {
  182. struct target *target;
  183. struct target_list *next;
  184. };
  185. struct gdb_fileio_info {
  186. char *identifier;
  187. uint32_t param_1;
  188. uint32_t param_2;
  189. uint32_t param_3;
  190. uint32_t param_4;
  191. };
  192. /** Returns the instance-specific name of the specified target. */
  193. static inline const char *target_name(struct target *target)
  194. {
  195. return target->cmd_name;
  196. }
  197. const char *debug_reason_name(struct target *t);
  198. enum target_event {
  199. /* allow GDB to do stuff before others handle the halted event,
  200. * this is in lieu of defining ordering of invocation of events,
  201. * which would be more complicated
  202. *
  203. * Telling GDB to halt does not mean that the target stopped running,
  204. * simply that we're dropping out of GDB's waiting for step or continue.
  205. *
  206. * This can be useful when e.g. detecting power dropout.
  207. */
  208. TARGET_EVENT_GDB_HALT,
  209. TARGET_EVENT_HALTED, /* target entered debug state from normal execution or reset */
  210. TARGET_EVENT_RESUMED, /* target resumed to normal execution */
  211. TARGET_EVENT_RESUME_START,
  212. TARGET_EVENT_RESUME_END,
  213. TARGET_EVENT_GDB_START, /* debugger started execution (step/run) */
  214. TARGET_EVENT_GDB_END, /* debugger stopped execution (step/run) */
  215. TARGET_EVENT_RESET_START,
  216. TARGET_EVENT_RESET_ASSERT_PRE,
  217. TARGET_EVENT_RESET_ASSERT, /* C code uses this instead of SRST */
  218. TARGET_EVENT_RESET_ASSERT_POST,
  219. TARGET_EVENT_RESET_DEASSERT_PRE,
  220. TARGET_EVENT_RESET_DEASSERT_POST,
  221. TARGET_EVENT_RESET_HALT_PRE,
  222. TARGET_EVENT_RESET_HALT_POST,
  223. TARGET_EVENT_RESET_WAIT_PRE,
  224. TARGET_EVENT_RESET_WAIT_POST,
  225. TARGET_EVENT_RESET_INIT,
  226. TARGET_EVENT_RESET_END,
  227. TARGET_EVENT_DEBUG_HALTED, /* target entered debug state, but was executing on behalf of the debugger */
  228. TARGET_EVENT_DEBUG_RESUMED, /* target resumed to execute on behalf of the debugger */
  229. TARGET_EVENT_EXAMINE_START,
  230. TARGET_EVENT_EXAMINE_END,
  231. TARGET_EVENT_GDB_ATTACH,
  232. TARGET_EVENT_GDB_DETACH,
  233. TARGET_EVENT_GDB_FLASH_ERASE_START,
  234. TARGET_EVENT_GDB_FLASH_ERASE_END,
  235. TARGET_EVENT_GDB_FLASH_WRITE_START,
  236. TARGET_EVENT_GDB_FLASH_WRITE_END,
  237. TARGET_EVENT_TRACE_CONFIG,
  238. };
  239. struct target_event_action {
  240. enum target_event event;
  241. struct Jim_Interp *interp;
  242. struct Jim_Obj *body;
  243. int has_percent;
  244. struct target_event_action *next;
  245. };
  246. bool target_has_event_action(struct target *target, enum target_event event);
  247. struct target_event_callback {
  248. int (*callback)(struct target *target, enum target_event event, void *priv);
  249. void *priv;
  250. struct target_event_callback *next;
  251. };
  252. struct target_reset_callback {
  253. struct list_head list;
  254. void *priv;
  255. int (*callback)(struct target *target, enum target_reset_mode reset_mode, void *priv);
  256. };
  257. struct target_trace_callback {
  258. struct list_head list;
  259. void *priv;
  260. int (*callback)(struct target *target, size_t len, uint8_t *data, void *priv);
  261. };
  262. struct target_timer_callback {
  263. int (*callback)(void *priv);
  264. int time_ms;
  265. int periodic;
  266. bool removed;
  267. struct timeval when;
  268. void *priv;
  269. struct target_timer_callback *next;
  270. };
  271. int target_register_commands(struct command_context *cmd_ctx);
  272. int target_examine(void);
  273. int target_register_event_callback(
  274. int (*callback)(struct target *target,
  275. enum target_event event, void *priv),
  276. void *priv);
  277. int target_unregister_event_callback(
  278. int (*callback)(struct target *target,
  279. enum target_event event, void *priv),
  280. void *priv);
  281. int target_register_reset_callback(
  282. int (*callback)(struct target *target,
  283. enum target_reset_mode reset_mode, void *priv),
  284. void *priv);
  285. int target_unregister_reset_callback(
  286. int (*callback)(struct target *target,
  287. enum target_reset_mode reset_mode, void *priv),
  288. void *priv);
  289. int target_register_trace_callback(
  290. int (*callback)(struct target *target,
  291. size_t len, uint8_t *data, void *priv),
  292. void *priv);
  293. int target_unregister_trace_callback(
  294. int (*callback)(struct target *target,
  295. size_t len, uint8_t *data, void *priv),
  296. void *priv);
  297. /* Poll the status of the target, detect any error conditions and report them.
  298. *
  299. * Also note that this fn will clear such error conditions, so a subsequent
  300. * invocation will then succeed.
  301. *
  302. * These error conditions can be "sticky" error conditions. E.g. writing
  303. * to memory could be implemented as an open loop and if memory writes
  304. * fails, then a note is made of it, the error is sticky, but the memory
  305. * write loop still runs to completion. This improves performance in the
  306. * normal case as there is no need to verify that every single write succeed,
  307. * yet it is possible to detect error conditions.
  308. */
  309. int target_poll(struct target *target);
  310. int target_resume(struct target *target, int current, target_addr_t address,
  311. int handle_breakpoints, int debug_execution);
  312. int target_halt(struct target *target);
  313. int target_call_event_callbacks(struct target *target, enum target_event event);
  314. int target_call_reset_callbacks(struct target *target, enum target_reset_mode reset_mode);
  315. int target_call_trace_callbacks(struct target *target, size_t len, uint8_t *data);
  316. /**
  317. * The period is very approximate, the callback can happen much more often
  318. * or much more rarely than specified
  319. */
  320. int target_register_timer_callback(int (*callback)(void *priv),
  321. int time_ms, int periodic, void *priv);
  322. int target_unregister_timer_callback(int (*callback)(void *priv), void *priv);
  323. int target_call_timer_callbacks(void);
  324. /**
  325. * Invoke this to ensure that e.g. polling timer callbacks happen before
  326. * a synchronous command completes.
  327. */
  328. int target_call_timer_callbacks_now(void);
  329. struct target *get_target_by_num(int num);
  330. struct target *get_current_target(struct command_context *cmd_ctx);
  331. struct target *get_target(const char *id);
  332. /**
  333. * Get the target type name.
  334. *
  335. * This routine is a wrapper for the target->type->name field.
  336. * Note that this is not an instance-specific name for his target.
  337. */
  338. const char *target_type_name(struct target *target);
  339. /**
  340. * Examine the specified @a target, letting it perform any
  341. * Initialisation that requires JTAG access.
  342. *
  343. * This routine is a wrapper for target->type->examine.
  344. */
  345. int target_examine_one(struct target *target);
  346. /** @returns @c true if target_set_examined() has been called. */
  347. static inline bool target_was_examined(struct target *target)
  348. {
  349. return target->examined;
  350. }
  351. /** Sets the @c examined flag for the given target. */
  352. /** Use in target->type->examine() after one-time setup is done. */
  353. static inline void target_set_examined(struct target *target)
  354. {
  355. target->examined = true;
  356. }
  357. /**
  358. * Add the @a breakpoint for @a target.
  359. *
  360. * This routine is a wrapper for target->type->add_breakpoint.
  361. */
  362. int target_add_breakpoint(struct target *target,
  363. struct breakpoint *breakpoint);
  364. /**
  365. * Add the @a ContextID breakpoint for @a target.
  366. *
  367. * This routine is a wrapper for target->type->add_context_breakpoint.
  368. */
  369. int target_add_context_breakpoint(struct target *target,
  370. struct breakpoint *breakpoint);
  371. /**
  372. * Add the @a ContextID & IVA breakpoint for @a target.
  373. *
  374. * This routine is a wrapper for target->type->add_hybrid_breakpoint.
  375. */
  376. int target_add_hybrid_breakpoint(struct target *target,
  377. struct breakpoint *breakpoint);
  378. /**
  379. * Remove the @a breakpoint for @a target.
  380. *
  381. * This routine is a wrapper for target->type->remove_breakpoint.
  382. */
  383. int target_remove_breakpoint(struct target *target,
  384. struct breakpoint *breakpoint);
  385. /**
  386. * Add the @a watchpoint for @a target.
  387. *
  388. * This routine is a wrapper for target->type->add_watchpoint.
  389. */
  390. int target_add_watchpoint(struct target *target,
  391. struct watchpoint *watchpoint);
  392. /**
  393. * Remove the @a watchpoint for @a target.
  394. *
  395. * This routine is a wrapper for target->type->remove_watchpoint.
  396. */
  397. int target_remove_watchpoint(struct target *target,
  398. struct watchpoint *watchpoint);
  399. /**
  400. * Find out the just hit @a watchpoint for @a target.
  401. *
  402. * This routine is a wrapper for target->type->hit_watchpoint.
  403. */
  404. int target_hit_watchpoint(struct target *target,
  405. struct watchpoint **watchpoint);
  406. /**
  407. * Obtain the registers for GDB.
  408. *
  409. * This routine is a wrapper for target->type->get_gdb_reg_list.
  410. */
  411. int target_get_gdb_reg_list(struct target *target,
  412. struct reg **reg_list[], int *reg_list_size,
  413. enum target_register_class reg_class);
  414. /**
  415. * Step the target.
  416. *
  417. * This routine is a wrapper for target->type->step.
  418. */
  419. int target_step(struct target *target,
  420. int current, target_addr_t address, int handle_breakpoints);
  421. /**
  422. * Run an algorithm on the @a target given.
  423. *
  424. * This routine is a wrapper for target->type->run_algorithm.
  425. */
  426. int target_run_algorithm(struct target *target,
  427. int num_mem_params, struct mem_param *mem_params,
  428. int num_reg_params, struct reg_param *reg_param,
  429. uint32_t entry_point, uint32_t exit_point,
  430. int timeout_ms, void *arch_info);
  431. /**
  432. * Starts an algorithm in the background on the @a target given.
  433. *
  434. * This routine is a wrapper for target->type->start_algorithm.
  435. */
  436. int target_start_algorithm(struct target *target,
  437. int num_mem_params, struct mem_param *mem_params,
  438. int num_reg_params, struct reg_param *reg_params,
  439. uint32_t entry_point, uint32_t exit_point,
  440. void *arch_info);
  441. /**
  442. * Wait for an algorithm on the @a target given.
  443. *
  444. * This routine is a wrapper for target->type->wait_algorithm.
  445. */
  446. int target_wait_algorithm(struct target *target,
  447. int num_mem_params, struct mem_param *mem_params,
  448. int num_reg_params, struct reg_param *reg_params,
  449. uint32_t exit_point, int timeout_ms,
  450. void *arch_info);
  451. /**
  452. * This routine is a wrapper for asynchronous algorithms.
  453. *
  454. */
  455. int target_run_flash_async_algorithm(struct target *target,
  456. const uint8_t *buffer, uint32_t count, int block_size,
  457. int num_mem_params, struct mem_param *mem_params,
  458. int num_reg_params, struct reg_param *reg_params,
  459. uint32_t buffer_start, uint32_t buffer_size,
  460. uint32_t entry_point, uint32_t exit_point,
  461. void *arch_info);
  462. /**
  463. * Read @a count items of @a size bytes from the memory of @a target at
  464. * the @a address given.
  465. *
  466. * This routine is a wrapper for target->type->read_memory.
  467. */
  468. int target_read_memory(struct target *target,
  469. target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  470. int target_read_phys_memory(struct target *target,
  471. target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  472. /**
  473. * Write @a count items of @a size bytes to the memory of @a target at
  474. * the @a address given. @a address must be aligned to @a size
  475. * in target memory.
  476. *
  477. * The endianness is the same in the host and target memory for this
  478. * function.
  479. *
  480. * \todo TODO:
  481. * Really @a buffer should have been defined as "const void *" and
  482. * @a buffer should have been aligned to @a size in the host memory.
  483. *
  484. * This is not enforced via e.g. assert's today and e.g. the
  485. * target_write_buffer fn breaks this assumption.
  486. *
  487. * This routine is wrapper for target->type->write_memory.
  488. */
  489. int target_write_memory(struct target *target,
  490. target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer);
  491. int target_write_phys_memory(struct target *target,
  492. target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer);
  493. /*
  494. * Write to target memory using the virtual address.
  495. *
  496. * Note that this fn is used to implement software breakpoints. Targets
  497. * can implement support for software breakpoints to memory marked as read
  498. * only by making this fn write to ram even if it is read only(MMU or
  499. * MPUs).
  500. *
  501. * It is sufficient to implement for writing a single word(16 or 32 in
  502. * ARM32/16 bit case) to write the breakpoint to ram.
  503. *
  504. * The target should also take care of "other things" to make sure that
  505. * software breakpoints can be written using this function. E.g.
  506. * when there is a separate instruction and data cache, this fn must
  507. * make sure that the instruction cache is synced up to the potential
  508. * code change that can happen as a result of the memory write(typically
  509. * by invalidating the cache).
  510. *
  511. * The high level wrapper fn in target.c will break down this memory write
  512. * request to multiple write requests to the target driver to e.g. guarantee
  513. * that writing 4 bytes to an aligned address happens with a single 32 bit
  514. * write operation, thus making this fn suitable to e.g. write to special
  515. * peripheral registers which do not support byte operations.
  516. */
  517. int target_write_buffer(struct target *target,
  518. target_addr_t address, uint32_t size, const uint8_t *buffer);
  519. int target_read_buffer(struct target *target,
  520. target_addr_t address, uint32_t size, uint8_t *buffer);
  521. int target_checksum_memory(struct target *target,
  522. target_addr_t address, uint32_t size, uint32_t *crc);
  523. int target_blank_check_memory(struct target *target,
  524. target_addr_t address, uint32_t size, uint32_t *blank, uint8_t erased_value);
  525. int target_wait_state(struct target *target, enum target_state state, int ms);
  526. /**
  527. * Obtain file-I/O information from target for GDB to do syscall.
  528. *
  529. * This routine is a wrapper for target->type->get_gdb_fileio_info.
  530. */
  531. int target_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info);
  532. /**
  533. * Pass GDB file-I/O response to target after finishing host syscall.
  534. *
  535. * This routine is a wrapper for target->type->gdb_fileio_end.
  536. */
  537. int target_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c);
  538. /** Return the *name* of this targets current state */
  539. const char *target_state_name(struct target *target);
  540. /** Return the *name* of a target event enumeration value */
  541. const char *target_event_name(enum target_event event);
  542. /** Return the *name* of a target reset reason enumeration value */
  543. const char *target_reset_mode_name(enum target_reset_mode reset_mode);
  544. /* DANGER!!!!!
  545. *
  546. * if "area" passed in to target_alloc_working_area() points to a memory
  547. * location that goes out of scope (e.g. a pointer on the stack), then
  548. * the caller of target_alloc_working_area() is responsible for invoking
  549. * target_free_working_area() before "area" goes out of scope.
  550. *
  551. * target_free_all_working_areas() will NULL out the "area" pointer
  552. * upon resuming or resetting the CPU.
  553. *
  554. */
  555. int target_alloc_working_area(struct target *target,
  556. uint32_t size, struct working_area **area);
  557. /* Same as target_alloc_working_area, except that no error is logged
  558. * when ERROR_TARGET_RESOURCE_NOT_AVAILABLE is returned.
  559. *
  560. * This allows the calling code to *try* to allocate target memory
  561. * and have a fallback to another behaviour(slower?).
  562. */
  563. int target_alloc_working_area_try(struct target *target,
  564. uint32_t size, struct working_area **area);
  565. int target_free_working_area(struct target *target, struct working_area *area);
  566. void target_free_all_working_areas(struct target *target);
  567. uint32_t target_get_working_area_avail(struct target *target);
  568. /**
  569. * Free all the resources allocated by targets and the target layer
  570. */
  571. void target_quit(void);
  572. extern struct target *all_targets;
  573. uint64_t target_buffer_get_u64(struct target *target, const uint8_t *buffer);
  574. uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer);
  575. uint32_t target_buffer_get_u24(struct target *target, const uint8_t *buffer);
  576. uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer);
  577. void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value);
  578. void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value);
  579. void target_buffer_set_u24(struct target *target, uint8_t *buffer, uint32_t value);
  580. void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value);
  581. void target_buffer_get_u64_array(struct target *target, const uint8_t *buffer, uint32_t count, uint64_t *dstbuf);
  582. void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf);
  583. void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, uint32_t count, uint16_t *dstbuf);
  584. void target_buffer_set_u64_array(struct target *target, uint8_t *buffer, uint32_t count, const uint64_t *srcbuf);
  585. void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf);
  586. void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf);
  587. int target_read_u64(struct target *target, target_addr_t address, uint64_t *value);
  588. int target_read_u32(struct target *target, target_addr_t address, uint32_t *value);
  589. int target_read_u16(struct target *target, target_addr_t address, uint16_t *value);
  590. int target_read_u8(struct target *target, target_addr_t address, uint8_t *value);
  591. int target_write_u64(struct target *target, target_addr_t address, uint64_t value);
  592. int target_write_u32(struct target *target, target_addr_t address, uint32_t value);
  593. int target_write_u16(struct target *target, target_addr_t address, uint16_t value);
  594. int target_write_u8(struct target *target, target_addr_t address, uint8_t value);
  595. int target_write_phys_u64(struct target *target, target_addr_t address, uint64_t value);
  596. int target_write_phys_u32(struct target *target, target_addr_t address, uint32_t value);
  597. int target_write_phys_u16(struct target *target, target_addr_t address, uint16_t value);
  598. int target_write_phys_u8(struct target *target, target_addr_t address, uint8_t value);
  599. /* Issues USER() statements with target state information */
  600. int target_arch_state(struct target *target);
  601. void target_handle_event(struct target *t, enum target_event e);
  602. #define ERROR_TARGET_INVALID (-300)
  603. #define ERROR_TARGET_INIT_FAILED (-301)
  604. #define ERROR_TARGET_TIMEOUT (-302)
  605. #define ERROR_TARGET_NOT_HALTED (-304)
  606. #define ERROR_TARGET_FAILURE (-305)
  607. #define ERROR_TARGET_UNALIGNED_ACCESS (-306)
  608. #define ERROR_TARGET_DATA_ABORT (-307)
  609. #define ERROR_TARGET_RESOURCE_NOT_AVAILABLE (-308)
  610. #define ERROR_TARGET_TRANSLATION_FAULT (-309)
  611. #define ERROR_TARGET_NOT_RUNNING (-310)
  612. #define ERROR_TARGET_NOT_EXAMINED (-311)
  613. extern bool get_target_reset_nag(void);
  614. #endif /* OPENOCD_TARGET_TARGET_H */