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.
 
 
 
 
 
 

701 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. 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. bool ctibase_set; /* By default the debug base is not set */
  168. uint32_t ctibase; /* Really a Cortex-A specific option, but there is no
  169. * system in place to support target specific options
  170. * currently. */
  171. struct rtos *rtos; /* Instance of Real Time Operating System support */
  172. bool rtos_auto_detect; /* A flag that indicates that the RTOS has been specified as "auto"
  173. * and must be detected when symbols are offered */
  174. struct backoff_timer backoff;
  175. int smp; /* add some target attributes for smp support */
  176. struct target_list *head;
  177. /* the gdb service is there in case of smp, we have only one gdb server
  178. * for all smp target
  179. * the target attached to the gdb is changing dynamically by changing
  180. * gdb_service->target pointer */
  181. struct gdb_service *gdb_service;
  182. /* file-I/O information for host to do syscall */
  183. struct gdb_fileio_info *fileio_info;
  184. };
  185. struct target_list {
  186. struct target *target;
  187. struct target_list *next;
  188. };
  189. struct gdb_fileio_info {
  190. char *identifier;
  191. uint32_t param_1;
  192. uint32_t param_2;
  193. uint32_t param_3;
  194. uint32_t param_4;
  195. };
  196. /** Returns the instance-specific name of the specified target. */
  197. static inline const char *target_name(struct target *target)
  198. {
  199. return target->cmd_name;
  200. }
  201. const char *debug_reason_name(struct target *t);
  202. enum target_event {
  203. /* allow GDB to do stuff before others handle the halted event,
  204. * this is in lieu of defining ordering of invocation of events,
  205. * which would be more complicated
  206. *
  207. * Telling GDB to halt does not mean that the target stopped running,
  208. * simply that we're dropping out of GDB's waiting for step or continue.
  209. *
  210. * This can be useful when e.g. detecting power dropout.
  211. */
  212. TARGET_EVENT_GDB_HALT,
  213. TARGET_EVENT_HALTED, /* target entered debug state from normal execution or reset */
  214. TARGET_EVENT_RESUMED, /* target resumed to normal execution */
  215. TARGET_EVENT_RESUME_START,
  216. TARGET_EVENT_RESUME_END,
  217. TARGET_EVENT_GDB_START, /* debugger started execution (step/run) */
  218. TARGET_EVENT_GDB_END, /* debugger stopped execution (step/run) */
  219. TARGET_EVENT_RESET_START,
  220. TARGET_EVENT_RESET_ASSERT_PRE,
  221. TARGET_EVENT_RESET_ASSERT, /* C code uses this instead of SRST */
  222. TARGET_EVENT_RESET_ASSERT_POST,
  223. TARGET_EVENT_RESET_DEASSERT_PRE,
  224. TARGET_EVENT_RESET_DEASSERT_POST,
  225. TARGET_EVENT_RESET_HALT_PRE,
  226. TARGET_EVENT_RESET_HALT_POST,
  227. TARGET_EVENT_RESET_WAIT_PRE,
  228. TARGET_EVENT_RESET_WAIT_POST,
  229. TARGET_EVENT_RESET_INIT,
  230. TARGET_EVENT_RESET_END,
  231. TARGET_EVENT_DEBUG_HALTED, /* target entered debug state, but was executing on behalf of the debugger */
  232. TARGET_EVENT_DEBUG_RESUMED, /* target resumed to execute on behalf of the debugger */
  233. TARGET_EVENT_EXAMINE_START,
  234. TARGET_EVENT_EXAMINE_END,
  235. TARGET_EVENT_GDB_ATTACH,
  236. TARGET_EVENT_GDB_DETACH,
  237. TARGET_EVENT_GDB_FLASH_ERASE_START,
  238. TARGET_EVENT_GDB_FLASH_ERASE_END,
  239. TARGET_EVENT_GDB_FLASH_WRITE_START,
  240. TARGET_EVENT_GDB_FLASH_WRITE_END,
  241. TARGET_EVENT_TRACE_CONFIG,
  242. };
  243. struct target_event_action {
  244. enum target_event event;
  245. struct Jim_Interp *interp;
  246. struct Jim_Obj *body;
  247. int has_percent;
  248. struct target_event_action *next;
  249. };
  250. bool target_has_event_action(struct target *target, enum target_event event);
  251. struct target_event_callback {
  252. int (*callback)(struct target *target, enum target_event event, void *priv);
  253. void *priv;
  254. struct target_event_callback *next;
  255. };
  256. struct target_reset_callback {
  257. struct list_head list;
  258. void *priv;
  259. int (*callback)(struct target *target, enum target_reset_mode reset_mode, void *priv);
  260. };
  261. struct target_trace_callback {
  262. struct list_head list;
  263. void *priv;
  264. int (*callback)(struct target *target, size_t len, uint8_t *data, void *priv);
  265. };
  266. struct target_timer_callback {
  267. int (*callback)(void *priv);
  268. int time_ms;
  269. int periodic;
  270. bool removed;
  271. struct timeval when;
  272. void *priv;
  273. struct target_timer_callback *next;
  274. };
  275. int target_register_commands(struct command_context *cmd_ctx);
  276. int target_examine(void);
  277. int target_register_event_callback(
  278. int (*callback)(struct target *target,
  279. enum target_event event, void *priv),
  280. void *priv);
  281. int target_unregister_event_callback(
  282. int (*callback)(struct target *target,
  283. enum target_event event, void *priv),
  284. void *priv);
  285. int target_register_reset_callback(
  286. int (*callback)(struct target *target,
  287. enum target_reset_mode reset_mode, void *priv),
  288. void *priv);
  289. int target_unregister_reset_callback(
  290. int (*callback)(struct target *target,
  291. enum target_reset_mode reset_mode, void *priv),
  292. void *priv);
  293. int target_register_trace_callback(
  294. int (*callback)(struct target *target,
  295. size_t len, uint8_t *data, void *priv),
  296. void *priv);
  297. int target_unregister_trace_callback(
  298. int (*callback)(struct target *target,
  299. size_t len, uint8_t *data, void *priv),
  300. void *priv);
  301. /* Poll the status of the target, detect any error conditions and report them.
  302. *
  303. * Also note that this fn will clear such error conditions, so a subsequent
  304. * invocation will then succeed.
  305. *
  306. * These error conditions can be "sticky" error conditions. E.g. writing
  307. * to memory could be implemented as an open loop and if memory writes
  308. * fails, then a note is made of it, the error is sticky, but the memory
  309. * write loop still runs to completion. This improves performance in the
  310. * normal case as there is no need to verify that every single write succeed,
  311. * yet it is possible to detect error conditions.
  312. */
  313. int target_poll(struct target *target);
  314. int target_resume(struct target *target, int current, target_addr_t address,
  315. int handle_breakpoints, int debug_execution);
  316. int target_halt(struct target *target);
  317. int target_call_event_callbacks(struct target *target, enum target_event event);
  318. int target_call_reset_callbacks(struct target *target, enum target_reset_mode reset_mode);
  319. int target_call_trace_callbacks(struct target *target, size_t len, uint8_t *data);
  320. /**
  321. * The period is very approximate, the callback can happen much more often
  322. * or much more rarely than specified
  323. */
  324. int target_register_timer_callback(int (*callback)(void *priv),
  325. int time_ms, int periodic, void *priv);
  326. int target_unregister_timer_callback(int (*callback)(void *priv), void *priv);
  327. int target_call_timer_callbacks(void);
  328. /**
  329. * Invoke this to ensure that e.g. polling timer callbacks happen before
  330. * a synchronous command completes.
  331. */
  332. int target_call_timer_callbacks_now(void);
  333. struct target *get_target_by_num(int num);
  334. struct target *get_current_target(struct command_context *cmd_ctx);
  335. struct target *get_target(const char *id);
  336. /**
  337. * Get the target type name.
  338. *
  339. * This routine is a wrapper for the target->type->name field.
  340. * Note that this is not an instance-specific name for his target.
  341. */
  342. const char *target_type_name(struct target *target);
  343. /**
  344. * Examine the specified @a target, letting it perform any
  345. * Initialisation that requires JTAG access.
  346. *
  347. * This routine is a wrapper for target->type->examine.
  348. */
  349. int target_examine_one(struct target *target);
  350. /** @returns @c true if target_set_examined() has been called. */
  351. static inline bool target_was_examined(struct target *target)
  352. {
  353. return target->examined;
  354. }
  355. /** Sets the @c examined flag for the given target. */
  356. /** Use in target->type->examine() after one-time setup is done. */
  357. static inline void target_set_examined(struct target *target)
  358. {
  359. target->examined = true;
  360. }
  361. /**
  362. * Add the @a breakpoint for @a target.
  363. *
  364. * This routine is a wrapper for target->type->add_breakpoint.
  365. */
  366. int target_add_breakpoint(struct target *target,
  367. struct breakpoint *breakpoint);
  368. /**
  369. * Add the @a ContextID breakpoint for @a target.
  370. *
  371. * This routine is a wrapper for target->type->add_context_breakpoint.
  372. */
  373. int target_add_context_breakpoint(struct target *target,
  374. struct breakpoint *breakpoint);
  375. /**
  376. * Add the @a ContextID & IVA breakpoint for @a target.
  377. *
  378. * This routine is a wrapper for target->type->add_hybrid_breakpoint.
  379. */
  380. int target_add_hybrid_breakpoint(struct target *target,
  381. struct breakpoint *breakpoint);
  382. /**
  383. * Remove the @a breakpoint for @a target.
  384. *
  385. * This routine is a wrapper for target->type->remove_breakpoint.
  386. */
  387. int target_remove_breakpoint(struct target *target,
  388. struct breakpoint *breakpoint);
  389. /**
  390. * Add the @a watchpoint for @a target.
  391. *
  392. * This routine is a wrapper for target->type->add_watchpoint.
  393. */
  394. int target_add_watchpoint(struct target *target,
  395. struct watchpoint *watchpoint);
  396. /**
  397. * Remove the @a watchpoint for @a target.
  398. *
  399. * This routine is a wrapper for target->type->remove_watchpoint.
  400. */
  401. int target_remove_watchpoint(struct target *target,
  402. struct watchpoint *watchpoint);
  403. /**
  404. * Find out the just hit @a watchpoint for @a target.
  405. *
  406. * This routine is a wrapper for target->type->hit_watchpoint.
  407. */
  408. int target_hit_watchpoint(struct target *target,
  409. struct watchpoint **watchpoint);
  410. /**
  411. * Obtain the registers for GDB.
  412. *
  413. * This routine is a wrapper for target->type->get_gdb_reg_list.
  414. */
  415. int target_get_gdb_reg_list(struct target *target,
  416. struct reg **reg_list[], int *reg_list_size,
  417. enum target_register_class reg_class);
  418. /**
  419. * Step the target.
  420. *
  421. * This routine is a wrapper for target->type->step.
  422. */
  423. int target_step(struct target *target,
  424. int current, target_addr_t address, int handle_breakpoints);
  425. /**
  426. * Run an algorithm on the @a target given.
  427. *
  428. * This routine is a wrapper for target->type->run_algorithm.
  429. */
  430. int target_run_algorithm(struct target *target,
  431. int num_mem_params, struct mem_param *mem_params,
  432. int num_reg_params, struct reg_param *reg_param,
  433. uint32_t entry_point, uint32_t exit_point,
  434. int timeout_ms, void *arch_info);
  435. /**
  436. * Starts an algorithm in the background on the @a target given.
  437. *
  438. * This routine is a wrapper for target->type->start_algorithm.
  439. */
  440. int target_start_algorithm(struct target *target,
  441. int num_mem_params, struct mem_param *mem_params,
  442. int num_reg_params, struct reg_param *reg_params,
  443. uint32_t entry_point, uint32_t exit_point,
  444. void *arch_info);
  445. /**
  446. * Wait for an algorithm on the @a target given.
  447. *
  448. * This routine is a wrapper for target->type->wait_algorithm.
  449. */
  450. int target_wait_algorithm(struct target *target,
  451. int num_mem_params, struct mem_param *mem_params,
  452. int num_reg_params, struct reg_param *reg_params,
  453. uint32_t exit_point, int timeout_ms,
  454. void *arch_info);
  455. /**
  456. * This routine is a wrapper for asynchronous algorithms.
  457. *
  458. */
  459. int target_run_flash_async_algorithm(struct target *target,
  460. const uint8_t *buffer, uint32_t count, int block_size,
  461. int num_mem_params, struct mem_param *mem_params,
  462. int num_reg_params, struct reg_param *reg_params,
  463. uint32_t buffer_start, uint32_t buffer_size,
  464. uint32_t entry_point, uint32_t exit_point,
  465. void *arch_info);
  466. /**
  467. * Read @a count items of @a size bytes from the memory of @a target at
  468. * the @a address given.
  469. *
  470. * This routine is a wrapper for target->type->read_memory.
  471. */
  472. int target_read_memory(struct target *target,
  473. target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  474. int target_read_phys_memory(struct target *target,
  475. target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer);
  476. /**
  477. * Write @a count items of @a size bytes to the memory of @a target at
  478. * the @a address given. @a address must be aligned to @a size
  479. * in target memory.
  480. *
  481. * The endianness is the same in the host and target memory for this
  482. * function.
  483. *
  484. * \todo TODO:
  485. * Really @a buffer should have been defined as "const void *" and
  486. * @a buffer should have been aligned to @a size in the host memory.
  487. *
  488. * This is not enforced via e.g. assert's today and e.g. the
  489. * target_write_buffer fn breaks this assumption.
  490. *
  491. * This routine is wrapper for target->type->write_memory.
  492. */
  493. int target_write_memory(struct target *target,
  494. target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer);
  495. int target_write_phys_memory(struct target *target,
  496. target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer);
  497. /*
  498. * Write to target memory using the virtual address.
  499. *
  500. * Note that this fn is used to implement software breakpoints. Targets
  501. * can implement support for software breakpoints to memory marked as read
  502. * only by making this fn write to ram even if it is read only(MMU or
  503. * MPUs).
  504. *
  505. * It is sufficient to implement for writing a single word(16 or 32 in
  506. * ARM32/16 bit case) to write the breakpoint to ram.
  507. *
  508. * The target should also take care of "other things" to make sure that
  509. * software breakpoints can be written using this function. E.g.
  510. * when there is a separate instruction and data cache, this fn must
  511. * make sure that the instruction cache is synced up to the potential
  512. * code change that can happen as a result of the memory write(typically
  513. * by invalidating the cache).
  514. *
  515. * The high level wrapper fn in target.c will break down this memory write
  516. * request to multiple write requests to the target driver to e.g. guarantee
  517. * that writing 4 bytes to an aligned address happens with a single 32 bit
  518. * write operation, thus making this fn suitable to e.g. write to special
  519. * peripheral registers which do not support byte operations.
  520. */
  521. int target_write_buffer(struct target *target,
  522. target_addr_t address, uint32_t size, const uint8_t *buffer);
  523. int target_read_buffer(struct target *target,
  524. target_addr_t address, uint32_t size, uint8_t *buffer);
  525. int target_checksum_memory(struct target *target,
  526. target_addr_t address, uint32_t size, uint32_t *crc);
  527. int target_blank_check_memory(struct target *target,
  528. target_addr_t address, uint32_t size, uint32_t *blank, uint8_t erased_value);
  529. int target_wait_state(struct target *target, enum target_state state, int ms);
  530. /**
  531. * Obtain file-I/O information from target for GDB to do syscall.
  532. *
  533. * This routine is a wrapper for target->type->get_gdb_fileio_info.
  534. */
  535. int target_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info);
  536. /**
  537. * Pass GDB file-I/O response to target after finishing host syscall.
  538. *
  539. * This routine is a wrapper for target->type->gdb_fileio_end.
  540. */
  541. int target_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c);
  542. /** Return the *name* of this targets current state */
  543. const char *target_state_name(struct target *target);
  544. /** Return the *name* of a target event enumeration value */
  545. const char *target_event_name(enum target_event event);
  546. /** Return the *name* of a target reset reason enumeration value */
  547. const char *target_reset_mode_name(enum target_reset_mode reset_mode);
  548. /* DANGER!!!!!
  549. *
  550. * if "area" passed in to target_alloc_working_area() points to a memory
  551. * location that goes out of scope (e.g. a pointer on the stack), then
  552. * the caller of target_alloc_working_area() is responsible for invoking
  553. * target_free_working_area() before "area" goes out of scope.
  554. *
  555. * target_free_all_working_areas() will NULL out the "area" pointer
  556. * upon resuming or resetting the CPU.
  557. *
  558. */
  559. int target_alloc_working_area(struct target *target,
  560. uint32_t size, struct working_area **area);
  561. /* Same as target_alloc_working_area, except that no error is logged
  562. * when ERROR_TARGET_RESOURCE_NOT_AVAILABLE is returned.
  563. *
  564. * This allows the calling code to *try* to allocate target memory
  565. * and have a fallback to another behaviour(slower?).
  566. */
  567. int target_alloc_working_area_try(struct target *target,
  568. uint32_t size, struct working_area **area);
  569. int target_free_working_area(struct target *target, struct working_area *area);
  570. void target_free_all_working_areas(struct target *target);
  571. uint32_t target_get_working_area_avail(struct target *target);
  572. /**
  573. * Free all the resources allocated by targets and the target layer
  574. */
  575. void target_quit(void);
  576. extern struct target *all_targets;
  577. uint64_t target_buffer_get_u64(struct target *target, const uint8_t *buffer);
  578. uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer);
  579. uint32_t target_buffer_get_u24(struct target *target, const uint8_t *buffer);
  580. uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer);
  581. void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value);
  582. void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value);
  583. void target_buffer_set_u24(struct target *target, uint8_t *buffer, uint32_t value);
  584. void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value);
  585. void target_buffer_get_u64_array(struct target *target, const uint8_t *buffer, uint32_t count, uint64_t *dstbuf);
  586. void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf);
  587. void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, uint32_t count, uint16_t *dstbuf);
  588. void target_buffer_set_u64_array(struct target *target, uint8_t *buffer, uint32_t count, const uint64_t *srcbuf);
  589. void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf);
  590. void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf);
  591. int target_read_u64(struct target *target, target_addr_t address, uint64_t *value);
  592. int target_read_u32(struct target *target, target_addr_t address, uint32_t *value);
  593. int target_read_u16(struct target *target, target_addr_t address, uint16_t *value);
  594. int target_read_u8(struct target *target, target_addr_t address, uint8_t *value);
  595. int target_write_u64(struct target *target, target_addr_t address, uint64_t value);
  596. int target_write_u32(struct target *target, target_addr_t address, uint32_t value);
  597. int target_write_u16(struct target *target, target_addr_t address, uint16_t value);
  598. int target_write_u8(struct target *target, target_addr_t address, uint8_t value);
  599. int target_write_phys_u64(struct target *target, target_addr_t address, uint64_t value);
  600. int target_write_phys_u32(struct target *target, target_addr_t address, uint32_t value);
  601. int target_write_phys_u16(struct target *target, target_addr_t address, uint16_t value);
  602. int target_write_phys_u8(struct target *target, target_addr_t address, uint8_t value);
  603. /* Issues USER() statements with target state information */
  604. int target_arch_state(struct target *target);
  605. void target_handle_event(struct target *t, enum target_event e);
  606. #define ERROR_TARGET_INVALID (-300)
  607. #define ERROR_TARGET_INIT_FAILED (-301)
  608. #define ERROR_TARGET_TIMEOUT (-302)
  609. #define ERROR_TARGET_NOT_HALTED (-304)
  610. #define ERROR_TARGET_FAILURE (-305)
  611. #define ERROR_TARGET_UNALIGNED_ACCESS (-306)
  612. #define ERROR_TARGET_DATA_ABORT (-307)
  613. #define ERROR_TARGET_RESOURCE_NOT_AVAILABLE (-308)
  614. #define ERROR_TARGET_TRANSLATION_FAULT (-309)
  615. #define ERROR_TARGET_NOT_RUNNING (-310)
  616. #define ERROR_TARGET_NOT_EXAMINED (-311)
  617. extern bool get_target_reset_nag(void);
  618. #endif /* OPENOCD_TARGET_TARGET_H */