OpenOCD
arm7_9_common.c
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  * Copyright (C) 2008 by Hongtao Zheng *
14  * hontor@126.com *
15  * *
16  * Copyright (C) 2009 by David Brownell *
17  ***************************************************************************/
18 
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include "breakpoints.h"
24 #include "embeddedice.h"
25 #include "target_request.h"
26 #include "etm.h"
27 #include <helper/time_support.h>
28 #include "arm_simulator.h"
29 #include "arm_semihosting.h"
30 #include "algorithm.h"
31 #include "register.h"
32 #include "armv4_5.h"
33 
52 static int arm7_9_debug_entry(struct target *target);
53 
60 static int arm7_9_clear_watchpoints(struct arm7_9_common *arm7_9)
61 {
62  LOG_DEBUG("-");
65  arm7_9->sw_breakpoint_count = 0;
66  arm7_9->sw_breakpoints_added = 0;
67  arm7_9->wp0_used = 0;
68  arm7_9->wp1_used = arm7_9->wp1_used_default;
69  arm7_9->wp_available = arm7_9->wp_available_max;
70 
71  return jtag_execute_queue();
72 }
73 
81 static void arm7_9_assign_wp(struct arm7_9_common *arm7_9, struct breakpoint *breakpoint)
82 {
83  if (!arm7_9->wp0_used) {
84  arm7_9->wp0_used = 1;
86  arm7_9->wp_available--;
87  } else if (!arm7_9->wp1_used) {
88  arm7_9->wp1_used = 1;
90  arm7_9->wp_available--;
91  } else {
92  LOG_ERROR("BUG: no hardware comparator available");
93  }
94 
95  LOG_DEBUG("BPID: %" PRIu32 " (0x%08" TARGET_PRIxADDR ") using hw wp: %u",
99 }
100 
109 {
110  if (arm7_9->sw_breakpoints_added)
111  return ERROR_OK;
112  if (arm7_9->wp_available < 1) {
113  LOG_WARNING("can't enable sw breakpoints with no watchpoint unit available");
115  }
116  arm7_9->wp_available--;
117 
118  /* pick a breakpoint unit */
119  if (!arm7_9->wp0_used) {
120  arm7_9->sw_breakpoints_added = 1;
121  arm7_9->wp0_used = 3;
122  } else if (!arm7_9->wp1_used) {
123  arm7_9->sw_breakpoints_added = 2;
124  arm7_9->wp1_used = 3;
125  } else {
126  LOG_ERROR("BUG: both watchpoints used, but wp_available >= 1");
127  return ERROR_FAIL;
128  }
129 
130  if (arm7_9->sw_breakpoints_added == 1) {
133  embeddedice_set_reg(&arm7_9->eice_cache->reg_list[EICE_W0_ADDR_MASK], 0xffffffffu);
136  } else if (arm7_9->sw_breakpoints_added == 2) {
139  embeddedice_set_reg(&arm7_9->eice_cache->reg_list[EICE_W1_ADDR_MASK], 0xffffffffu);
142  } else {
143  LOG_ERROR("BUG: both watchpoints used, but wp_available >= 1");
144  return ERROR_FAIL;
145  }
146  LOG_DEBUG("SW BP using hw wp: %d",
147  arm7_9->sw_breakpoints_added);
148 
149  return jtag_execute_queue();
150 }
151 
158 static int arm7_9_setup(struct target *target)
159 {
160  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
161 
162  return arm7_9_clear_watchpoints(arm7_9);
163 }
164 
177 {
178  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
179  int retval = ERROR_OK;
180 
181  LOG_DEBUG("BPID: %" PRIu32 ", Address: 0x%08" TARGET_PRIxADDR ", Type: %d",
184  breakpoint->type);
185 
186  if (target->state != TARGET_HALTED) {
187  LOG_WARNING("target not halted");
189  }
190 
191  if (breakpoint->type == BKPT_HARD) {
192  /* either an ARM (4 byte) or Thumb (2 byte) breakpoint */
193  uint32_t mask = (breakpoint->length == 4) ? 0x3u : 0x1u;
194 
195  /* reassign a hw breakpoint */
196  if (!breakpoint->is_set)
197  arm7_9_assign_wp(arm7_9, breakpoint);
198 
199  if (breakpoint->number == 0) {
202  embeddedice_set_reg(&arm7_9->eice_cache->reg_list[EICE_W0_DATA_MASK], 0xffffffffu);
205  } else if (breakpoint->number == 1) {
208  embeddedice_set_reg(&arm7_9->eice_cache->reg_list[EICE_W1_DATA_MASK], 0xffffffffu);
211  } else {
212  LOG_ERROR("BUG: no hardware comparator available");
213  return ERROR_OK;
214  }
215 
216  retval = jtag_execute_queue();
217  } else if (breakpoint->type == BKPT_SOFT) {
218  /* did we already set this breakpoint? */
219  if (breakpoint->is_set)
220  return ERROR_OK;
221 
222  if (breakpoint->length == 4) {
223  uint32_t verify = 0xffffffff;
224  /* keep the original instruction in target endianness */
226  if (retval != ERROR_OK)
227  return retval;
228  /* write the breakpoint instruction in target
229  * endianness (arm7_9->arm_bkpt is host endian) */
230  retval = target_write_u32(target, breakpoint->address, arm7_9->arm_bkpt);
231  if (retval != ERROR_OK)
232  return retval;
233 
234  retval = target_read_u32(target, breakpoint->address, &verify);
235  if (retval != ERROR_OK)
236  return retval;
237  if (verify != arm7_9->arm_bkpt) {
238  LOG_ERROR("Unable to set 32 bit software breakpoint at address %08" TARGET_PRIxADDR
239  " - check that memory is read/writable", breakpoint->address);
240  return ERROR_OK;
241  }
242  } else {
243  uint16_t verify = 0xffff;
244  /* keep the original instruction in target endianness */
246  if (retval != ERROR_OK)
247  return retval;
248  /* write the breakpoint instruction in target
249  * endianness (arm7_9->thumb_bkpt is host endian) */
250  retval = target_write_u16(target, breakpoint->address, arm7_9->thumb_bkpt);
251  if (retval != ERROR_OK)
252  return retval;
253 
254  retval = target_read_u16(target, breakpoint->address, &verify);
255  if (retval != ERROR_OK)
256  return retval;
257  if (verify != arm7_9->thumb_bkpt) {
258  LOG_ERROR("Unable to set thumb software breakpoint at address %08" TARGET_PRIxADDR
259  " - check that memory is read/writable", breakpoint->address);
260  return ERROR_OK;
261  }
262  }
263 
264  retval = arm7_9_set_software_breakpoints(arm7_9);
265  if (retval != ERROR_OK)
266  return retval;
267 
268  arm7_9->sw_breakpoint_count++;
269 
270  breakpoint->is_set = true;
271  }
272 
273  return retval;
274 }
275 
289 {
290  int retval = ERROR_OK;
291  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
292 
293  LOG_DEBUG("BPID: %" PRIu32 ", Address: 0x%08" TARGET_PRIxADDR,
296 
297  if (!breakpoint->is_set) {
298  LOG_WARNING("breakpoint not set");
299  return ERROR_OK;
300  }
301 
302  if (breakpoint->type == BKPT_HARD) {
303  LOG_DEBUG("BPID: %" PRIu32 " Releasing hw wp: %d",
305  breakpoint->is_set);
306  if (breakpoint->number == 0) {
308  arm7_9->wp0_used = 0;
309  arm7_9->wp_available++;
310  } else if (breakpoint->number == 1) {
312  arm7_9->wp1_used = 0;
313  arm7_9->wp_available++;
314  }
315  retval = jtag_execute_queue();
316  breakpoint->is_set = false;
317  } else {
318  /* restore original instruction (kept in target endianness) */
319  if (breakpoint->length == 4) {
320  uint32_t current_instr;
321  /* check that user program as not modified breakpoint instruction */
322  retval = target_read_memory(target,
323  breakpoint->address, 4, 1, (uint8_t *)&current_instr);
324  if (retval != ERROR_OK)
325  return retval;
326  current_instr = target_buffer_get_u32(target, (uint8_t *)&current_instr);
327  if (current_instr == arm7_9->arm_bkpt) {
328  retval = target_write_memory(target,
330  if (retval != ERROR_OK)
331  return retval;
332  }
333 
334  } else {
335  uint16_t current_instr;
336  /* check that user program as not modified breakpoint instruction */
337  retval = target_read_memory(target,
338  breakpoint->address, 2, 1, (uint8_t *)&current_instr);
339  if (retval != ERROR_OK)
340  return retval;
341  current_instr = target_buffer_get_u16(target, (uint8_t *)&current_instr);
342  if (current_instr == arm7_9->thumb_bkpt) {
343  retval = target_write_memory(target,
345  if (retval != ERROR_OK)
346  return retval;
347  }
348  }
349 
350  if (--arm7_9->sw_breakpoint_count == 0) {
351  /* We have removed the last sw breakpoint, clear the hw breakpoint we used
352  *to implement it */
353  if (arm7_9->sw_breakpoints_added == 1)
356  else if (arm7_9->sw_breakpoints_added == 2)
359  }
360 
361  breakpoint->is_set = false;
362  }
363 
364  return retval;
365 }
366 
377 {
378  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
379 
380  if (arm7_9->breakpoint_count == 0) {
381  /* make sure we don't have any dangling breakpoints. This is vital upon
382  * GDB connect/disconnect
383  */
384  arm7_9_clear_watchpoints(arm7_9);
385  }
386 
387  if ((breakpoint->type == BKPT_HARD) && (arm7_9->wp_available < 1)) {
388  LOG_INFO("no watchpoint unit available for hardware breakpoint");
390  }
391 
392  if ((breakpoint->length != 2) && (breakpoint->length != 4)) {
393  LOG_INFO("only breakpoints of two (Thumb) or four (ARM) bytes length supported");
395  }
396 
397  if (breakpoint->type == BKPT_HARD)
398  arm7_9_assign_wp(arm7_9, breakpoint);
399 
400  arm7_9->breakpoint_count++;
401 
403 }
404 
416 {
417  int retval = ERROR_OK;
418  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
419 
421  if (retval != ERROR_OK)
422  return retval;
423 
424  if (breakpoint->type == BKPT_HARD)
425  arm7_9->wp_available++;
426 
427  arm7_9->breakpoint_count--;
428  if (arm7_9->breakpoint_count == 0) {
429  /* make sure we don't have any dangling breakpoints */
430  retval = arm7_9_clear_watchpoints(arm7_9);
431  if (retval != ERROR_OK)
432  return retval;
433  }
434 
435  return ERROR_OK;
436 }
437 
449 {
450  int retval = ERROR_OK;
451  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
452  int rw_mask = 1;
453  uint32_t mask;
454 
455  mask = watchpoint->length - 1;
456 
457  if (target->state != TARGET_HALTED) {
458  LOG_WARNING("target not halted");
460  }
461 
462  if (watchpoint->rw == WPT_ACCESS)
463  rw_mask = 0;
464  else
465  rw_mask = 1;
466 
467  if (!arm7_9->wp0_used) {
472  watchpoint->mask);
473  if (watchpoint->mask != 0xffffffffu)
475  watchpoint->value);
477  0xff & ~EICE_W_CTRL_NOPC & ~rw_mask);
480 
481  retval = jtag_execute_queue();
482  if (retval != ERROR_OK)
483  return retval;
485  arm7_9->wp0_used = 2;
486  } else if (!arm7_9->wp1_used) {
491  watchpoint->mask);
492  if (watchpoint->mask != 0xffffffffu)
494  watchpoint->value);
496  0xff & ~EICE_W_CTRL_NOPC & ~rw_mask);
499 
500  retval = jtag_execute_queue();
501  if (retval != ERROR_OK)
502  return retval;
504  arm7_9->wp1_used = 2;
505  } else {
506  LOG_ERROR("BUG: no hardware comparator available");
507  return ERROR_OK;
508  }
509 
510  return ERROR_OK;
511 }
512 
522 {
523  int retval = ERROR_OK;
524  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
525 
526  if (target->state != TARGET_HALTED) {
527  LOG_WARNING("target not halted");
529  }
530 
531  if (!watchpoint->is_set) {
532  LOG_WARNING("breakpoint not set");
533  return ERROR_OK;
534  }
535 
536  if (watchpoint->number == 1) {
538  retval = jtag_execute_queue();
539  if (retval != ERROR_OK)
540  return retval;
541  arm7_9->wp0_used = 0;
542  } else if (watchpoint->number == 2) {
544  retval = jtag_execute_queue();
545  if (retval != ERROR_OK)
546  return retval;
547  arm7_9->wp1_used = 0;
548  }
549  watchpoint->is_set = false;
550 
551  return ERROR_OK;
552 }
553 
563 {
564  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
565 
566  if (arm7_9->wp_available < 1)
568 
569  if ((watchpoint->length != 1) && (watchpoint->length != 2) && (watchpoint->length != 4))
571 
572  arm7_9->wp_available--;
573 
574  return ERROR_OK;
575 }
576 
586 {
587  int retval = ERROR_OK;
588  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
589 
590  if (watchpoint->is_set) {
592  if (retval != ERROR_OK)
593  return retval;
594  }
595 
596  arm7_9->wp_available++;
597 
598  return ERROR_OK;
599 }
600 
611 {
612  int retval;
613  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
614  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
615  struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
616 
617  /* set RESTART instruction */
618  if (arm7_9->need_bypass_before_restart) {
619  arm7_9->need_bypass_before_restart = 0;
620  retval = arm_jtag_set_instr(jtag_info->tap, 0xf, NULL, TAP_IDLE);
621  if (retval != ERROR_OK)
622  return retval;
623  }
624  retval = arm_jtag_set_instr(jtag_info->tap, 0x4, NULL, TAP_IDLE);
625  if (retval != ERROR_OK)
626  return retval;
627 
628  int64_t then = timeval_ms();
629  bool timeout;
630  while (!(timeout = ((timeval_ms()-then) > 1000))) {
631  /* read debug status register */
632  embeddedice_read_reg(dbg_stat);
633  retval = jtag_execute_queue();
634  if (retval != ERROR_OK)
635  return retval;
636  if ((buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1))
637  && (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_SYSCOMP, 1)))
638  break;
639  if (debug_level >= 3)
640  alive_sleep(100);
641  else
642  keep_alive();
643  }
644  if (timeout) {
645  LOG_ERROR("timeout waiting for SYSCOMP & DBGACK, last DBG_STATUS: %" PRIx32 "",
646  buf_get_u32(dbg_stat->value, 0, dbg_stat->size));
647  return ERROR_TARGET_TIMEOUT;
648  }
649 
650  return ERROR_OK;
651 }
652 
662 {
663  static int set;
664  static uint8_t check_value[4], check_mask[4];
665 
666  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
667  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
668  struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
669  int retval;
670 
671  /* set RESTART instruction */
672  if (arm7_9->need_bypass_before_restart) {
673  arm7_9->need_bypass_before_restart = 0;
674  retval = arm_jtag_set_instr(jtag_info->tap, 0xf, NULL, TAP_IDLE);
675  if (retval != ERROR_OK)
676  return retval;
677  }
678  retval = arm_jtag_set_instr(jtag_info->tap, 0x4, NULL, TAP_IDLE);
679  if (retval != ERROR_OK)
680  return retval;
681 
682  if (!set) {
683  /* check for DBGACK and SYSCOMP set (others don't care) */
684 
685  /* NB! These are constants that must be available until after next jtag_execute() and
686  * we evaluate the values upon first execution in lieu of setting up these constants
687  * during early setup.
688  * */
689  buf_set_u32(check_value, 0, 32, 0x9);
690  buf_set_u32(check_mask, 0, 32, 0x9);
691  set = 1;
692  }
693 
694  /* read debug status register */
695  embeddedice_read_reg_w_check(dbg_stat, check_value, check_mask);
696 
697  return ERROR_OK;
698 }
699 
708 int arm7_9_target_request_data(struct target *target, uint32_t size, uint8_t *buffer)
709 {
710  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
711  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
712  uint32_t *data;
713  int retval = ERROR_OK;
714  uint32_t i;
715 
716  data = malloc(size * (sizeof(uint32_t)));
717 
718  retval = embeddedice_receive(jtag_info, data, size);
719 
720  /* return the 32-bit ints in the 8-bit array */
721  for (i = 0; i < size; i++)
722  h_u32_to_le(buffer + (i * 4), data[i]);
723 
724  free(data);
725 
726  return retval;
727 }
728 
739 {
740  int retval = ERROR_OK;
741  struct target *target = priv;
743  return ERROR_OK;
744  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
745  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
746  struct reg *dcc_control = &arm7_9->eice_cache->reg_list[EICE_COMMS_CTRL];
747 
748  if (!target->dbg_msg_enabled)
749  return ERROR_OK;
750 
751  if (target->state == TARGET_RUNNING) {
752  /* read DCC control register */
753  embeddedice_read_reg(dcc_control);
754  retval = jtag_execute_queue();
755  if (retval != ERROR_OK)
756  return retval;
757 
758  /* check W bit */
759  if (buf_get_u32(dcc_control->value, 1, 1) == 1) {
760  uint32_t request;
761 
762  retval = embeddedice_receive(jtag_info, &request, 1);
763  if (retval != ERROR_OK)
764  return retval;
765  retval = target_request(target, request);
766  if (retval != ERROR_OK)
767  return retval;
768  }
769  }
770 
771  return ERROR_OK;
772 }
773 
796 {
797  int retval;
798  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
799  struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
800 
801  /* read debug status register */
802  embeddedice_read_reg(dbg_stat);
803  retval = jtag_execute_queue();
804  if (retval != ERROR_OK)
805  return retval;
806 
807  if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1)) {
808  /* LOG_DEBUG("DBGACK set, dbg_state->value: 0x%x", buf_get_u32(dbg_stat->value, 0, *32));*/
809  if (target->state == TARGET_UNKNOWN) {
810  /* Starting OpenOCD with target in debug-halt */
812  LOG_DEBUG("DBGACK already set during server startup.");
813  }
814  if ((target->state == TARGET_RUNNING) || (target->state == TARGET_RESET)) {
816 
817  retval = arm7_9_debug_entry(target);
818  if (retval != ERROR_OK)
819  return retval;
820 
821  if (arm_semihosting(target, &retval) != 0)
822  return retval;
823 
825  if (retval != ERROR_OK)
826  return retval;
827  }
830  retval = arm7_9_debug_entry(target);
831  if (retval != ERROR_OK)
832  return retval;
833 
835  if (retval != ERROR_OK)
836  return retval;
837  }
838  if (target->state != TARGET_HALTED)
839  LOG_WARNING(
840  "DBGACK set, but the target did not end up in the halted state %d",
841  target->state);
842  } else {
845  }
846 
847  return ERROR_OK;
848 }
849 
862 {
863  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
865  bool use_event = false;
866 
867  /* TODO: apply hw reset signal in not examined state */
868  if (!(target_was_examined(target))) {
869  LOG_WARNING("Reset is not asserted because the target is not examined.");
870  LOG_WARNING("Use a reset button or power cycle the target.");
872  }
873 
874  LOG_DEBUG("target->state: %s", target_state_name(target));
875 
877  use_event = true;
878  else if (!(jtag_reset_config & RESET_HAS_SRST)) {
879  LOG_ERROR("%s: how to reset?", target_name(target));
880  return ERROR_FAIL;
881  }
882 
883  /* At this point trst has been asserted/deasserted once. We would
884  * like to program EmbeddedICE while SRST is asserted, instead of
885  * depending on SRST to leave that module alone. However, many CPUs
886  * gate the JTAG clock while SRST is asserted; or JTAG may need
887  * clock stability guarantees (adaptive clocking might help).
888  *
889  * So we assume JTAG access during SRST is off the menu unless it's
890  * been specifically enabled.
891  */
892  bool srst_asserted = false;
893 
894  if (!use_event && !(jtag_reset_config & RESET_SRST_PULLS_TRST)
896  jtag_add_reset(0, 1);
897  srst_asserted = true;
898  }
899 
900  if (target->reset_halt) {
901  /*
902  * For targets that don't support communication while SRST is
903  * asserted, we need to set up the reset vector catch first.
904  *
905  * When we use TRST+SRST and that's equivalent to a power-up
906  * reset, these settings may well be reset anyway; so setting
907  * them here won't matter.
908  */
909  if (arm7_9->has_vector_catch) {
910  /* program vector catch register to catch reset */
912 
913  /* extra runtest added as issues were found with
914  * certain ARM9 cores (maybe more) - AT91SAM9260
915  * and STR9
916  */
918  } else {
919  /* program watchpoint unit to match on reset vector
920  * address
921  */
927  }
928  }
929 
930  if (use_event)
932  else {
933  /* If we use SRST ... we'd like to issue just SRST, but the
934  * board or chip may be set up so we have to assert TRST as
935  * well. On some chips that combination is equivalent to a
936  * power-up reset, and generally clobbers EICE state.
937  */
939  jtag_add_reset(1, 1);
940  else if (!srst_asserted)
941  jtag_add_reset(0, 1);
942  jtag_add_sleep(50000);
943  }
944 
947 
948  /* REVISIT why isn't standard debug entry logic sufficient?? */
949  if (target->reset_halt && (!(jtag_reset_config & RESET_SRST_PULLS_TRST) || use_event)) {
950  /* debug entry was prepared above */
952  }
953 
954  return ERROR_OK;
955 }
956 
967 {
968  int retval = ERROR_OK;
969  LOG_DEBUG("target->state: %s", target_state_name(target));
970 
971  /* deassert reset lines */
972  jtag_add_reset(0, 0);
973 
974  /* In case polling is disabled, we need to examine the
975  * target and poll here for this target to work correctly.
976  *
977  * Otherwise, e.g. halt will fail afterwards with bogus
978  * error messages as halt will believe that reset is
979  * still in effect.
980  */
981  retval = target_examine_one(target);
982  if (retval != ERROR_OK)
983  return retval;
984 
985  retval = target_poll(target);
986  if (retval != ERROR_OK)
987  return retval;
988 
991  LOG_WARNING(
992  "srst pulls trst - can not reset into halted mode. Issuing halt after reset.");
993  retval = target_halt(target);
994  if (retval != ERROR_OK)
995  return retval;
996  }
997  return retval;
998 }
999 
1009 static int arm7_9_clear_halt(struct target *target)
1010 {
1011  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1012  struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL];
1013 
1014  /* we used DBGRQ only if we didn't come out of reset */
1015  if (!arm7_9->debug_entry_from_reset && arm7_9->use_dbgrq) {
1016  /* program EmbeddedICE Debug Control Register to deassert DBGRQ
1017  */
1018  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGRQ, 1, 0);
1019  embeddedice_store_reg(dbg_ctrl);
1020  } else {
1021  if (arm7_9->debug_entry_from_reset && arm7_9->has_vector_catch) {
1022  /* if we came out of reset, and vector catch is supported, we used
1023  * vector catch to enter debug state
1024  * restore the register in that case
1025  */
1027  } else {
1028  /* restore registers if watchpoint unit 0 was in use
1029  */
1030  if (arm7_9->wp0_used) {
1031  if (arm7_9->debug_entry_from_reset)
1040  }
1041  /* control value always has to be restored, as it was either disabled,
1042  * or enabled with possibly different bits
1043  */
1045  }
1046  }
1047 
1048  return ERROR_OK;
1049 }
1050 
1062 {
1063  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1064  struct arm *arm = &arm7_9->arm;
1065  struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
1066  struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL];
1067  int i;
1068  int retval;
1069 
1070  /* FIX!!! replace some of this code with tcl commands
1071  *
1072  * halt # the halt command is synchronous
1073  * armv4_5 core_state arm
1074  *
1075  */
1076 
1077  retval = target_halt(target);
1078  if (retval != ERROR_OK)
1079  return retval;
1080 
1081  long long then = timeval_ms();
1082  int timeout;
1083  while (!(timeout = ((timeval_ms()-then) > 1000))) {
1084  if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1) != 0)
1085  break;
1086  embeddedice_read_reg(dbg_stat);
1087  retval = jtag_execute_queue();
1088  if (retval != ERROR_OK)
1089  return retval;
1090  if (debug_level >= 3)
1091  alive_sleep(100);
1092  else
1093  keep_alive();
1094  }
1095  if (timeout) {
1096  LOG_ERROR("Failed to halt CPU after 1 sec");
1097  return ERROR_TARGET_TIMEOUT;
1098  }
1100 
1101  /* program EmbeddedICE Debug Control Register to assert DBGACK and INTDIS
1102  * ensure that DBGRQ is cleared
1103  */
1104  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGACK, 1, 1);
1105  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGRQ, 1, 0);
1106  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_INTDIS, 1, 1);
1107  embeddedice_store_reg(dbg_ctrl);
1108 
1109  retval = arm7_9_clear_halt(target);
1110  if (retval != ERROR_OK)
1111  return retval;
1112 
1113  /* if the target is in Thumb state, change to ARM state */
1114  if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_ITBIT, 1)) {
1115  uint32_t r0_thumb, pc_thumb;
1116  LOG_DEBUG("target entered debug from Thumb state, changing to ARM");
1117  /* Entered debug from Thumb mode */
1119  arm7_9->change_to_arm(target, &r0_thumb, &pc_thumb);
1120  }
1121 
1122  /* REVISIT likewise for bit 5 -- switch Jazelle-to-ARM */
1123 
1124  /* all register content is now invalid */
1126 
1127  /* SVC, ARM state, IRQ and FIQ disabled */
1128  uint32_t cpsr;
1129 
1130  cpsr = buf_get_u32(arm->cpsr->value, 0, 32);
1131  cpsr &= ~0xff;
1132  cpsr |= 0xd3;
1133  arm_set_cpsr(arm, cpsr);
1134  arm->cpsr->dirty = true;
1135 
1136  /* start fetching from 0x0 */
1137  buf_set_u32(arm->pc->value, 0, 32, 0x0);
1138  arm->pc->dirty = true;
1139  arm->pc->valid = true;
1140 
1141  /* reset registers */
1142  for (i = 0; i <= 14; i++) {
1143  struct reg *r = arm_reg_current(arm, i);
1144 
1145  buf_set_u32(r->value, 0, 32, 0xffffffff);
1146  r->dirty = true;
1147  r->valid = true;
1148  }
1149 
1151  if (retval != ERROR_OK)
1152  return retval;
1153 
1154  return ERROR_OK;
1155 }
1156 
1167 {
1168  if (target->state == TARGET_RESET) {
1169  LOG_ERROR(
1170  "BUG: arm7/9 does not support halt during reset. This is handled in arm7_9_assert_reset()");
1171  return ERROR_OK;
1172  }
1173 
1174  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1175  struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL];
1176 
1177  LOG_DEBUG("target->state: %s",
1179 
1180  if (target->state == TARGET_HALTED) {
1181  LOG_DEBUG("target was already halted");
1182  return ERROR_OK;
1183  }
1184 
1185  if (target->state == TARGET_UNKNOWN)
1186  LOG_WARNING("target was in unknown state when halt was requested");
1187 
1188  if (arm7_9->use_dbgrq) {
1189  /* program EmbeddedICE Debug Control Register to assert DBGRQ
1190  */
1191  if (arm7_9->set_special_dbgrq)
1192  arm7_9->set_special_dbgrq(target);
1193  else {
1194  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGRQ, 1, 1);
1195  embeddedice_store_reg(dbg_ctrl);
1196  }
1197  } else {
1198  /* program watchpoint unit to match on any address
1199  */
1205  ~EICE_W_CTRL_NOPC & 0xff);
1206  }
1207 
1209 
1210  return ERROR_OK;
1211 }
1212 
1224 static int arm7_9_debug_entry(struct target *target)
1225 {
1226  int i;
1227  uint32_t context[16];
1228  uint32_t *context_p[16];
1229  uint32_t r0_thumb, pc_thumb;
1230  uint32_t cpsr, cpsr_mask = 0;
1231  int retval;
1232  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1233  struct arm *arm = &arm7_9->arm;
1234  struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
1235  struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL];
1236 
1237 #ifdef _DEBUG_ARM7_9_
1238  LOG_DEBUG("-");
1239 #endif
1240 
1241  /* program EmbeddedICE Debug Control Register to assert DBGACK and INTDIS
1242  * ensure that DBGRQ is cleared
1243  */
1244  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGACK, 1, 1);
1245  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGRQ, 1, 0);
1246  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_INTDIS, 1, 1);
1247  embeddedice_store_reg(dbg_ctrl);
1248 
1249  retval = arm7_9_clear_halt(target);
1250  if (retval != ERROR_OK)
1251  return retval;
1252 
1253  retval = jtag_execute_queue();
1254  if (retval != ERROR_OK)
1255  return retval;
1256 
1257  retval = arm7_9->examine_debug_reason(target);
1258  if (retval != ERROR_OK)
1259  return retval;
1260 
1261  if (target->state != TARGET_HALTED) {
1262  LOG_WARNING("target not halted");
1263  return ERROR_TARGET_NOT_HALTED;
1264  }
1265 
1266  /* if the target is in Thumb state, change to ARM state */
1267  if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_ITBIT, 1)) {
1268  LOG_DEBUG("target entered debug from Thumb state");
1269  /* Entered debug from Thumb mode */
1271  cpsr_mask = 1 << 5;
1272  arm7_9->change_to_arm(target, &r0_thumb, &pc_thumb);
1273  LOG_DEBUG("r0_thumb: 0x%8.8" PRIx32
1274  ", pc_thumb: 0x%8.8" PRIx32, r0_thumb, pc_thumb);
1275  } else if (buf_get_u32(dbg_stat->value, 5, 1)) {
1276  /* \todo Get some vaguely correct handling of Jazelle, if
1277  * anyone ever uses it and full info becomes available.
1278  * See ARM9EJS TRM B.7.1 for how to switch J->ARM; and
1279  * B.7.3 for the reverse. That'd be the bare minimum...
1280  */
1281  LOG_DEBUG("target entered debug from Jazelle state");
1283  cpsr_mask = 1 << 24;
1284  LOG_ERROR("Jazelle debug entry -- BROKEN!");
1285  } else {
1286  LOG_DEBUG("target entered debug from ARM state");
1287  /* Entered debug from ARM mode */
1289  }
1290 
1291  for (i = 0; i < 16; i++)
1292  context_p[i] = &context[i];
1293  /* save core registers (r0 - r15 of current core mode) */
1294  arm7_9->read_core_regs(target, 0xffff, context_p);
1295 
1296  arm7_9->read_xpsr(target, &cpsr, 0);
1297 
1298  retval = jtag_execute_queue();
1299  if (retval != ERROR_OK)
1300  return retval;
1301 
1302  /* Sync our CPSR copy with J or T bits EICE reported, but
1303  * which we then erased by putting the core into ARM mode.
1304  */
1305  arm_set_cpsr(arm, cpsr | cpsr_mask);
1306 
1307  if (!is_arm_mode(arm->core_mode)) {
1309  LOG_ERROR("cpsr contains invalid mode value - communication failure");
1310  return ERROR_TARGET_FAILURE;
1311  }
1312 
1313  LOG_DEBUG("target entered debug state in %s mode",
1315 
1316  if (arm->core_state == ARM_STATE_THUMB) {
1317  LOG_DEBUG("thumb state, applying fixups");
1318  context[0] = r0_thumb;
1319  context[15] = pc_thumb;
1320  } else if (arm->core_state == ARM_STATE_ARM) {
1321  /* adjust value stored by STM */
1322  context[15] -= 3 * 4;
1323  }
1324 
1325  if ((target->debug_reason != DBG_REASON_DBGRQ) || (!arm7_9->use_dbgrq))
1326  context[15] -= 3 * ((arm->core_state == ARM_STATE_ARM) ? 4 : 2);
1327  else
1328  context[15] -= arm7_9->dbgreq_adjust_pc *
1329  ((arm->core_state == ARM_STATE_ARM) ? 4 : 2);
1330 
1331  for (i = 0; i <= 15; i++) {
1332  struct reg *r = arm_reg_current(arm, i);
1333 
1334  LOG_DEBUG("r%i: 0x%8.8" PRIx32 "", i, context[i]);
1335 
1336  buf_set_u32(r->value, 0, 32, context[i]);
1337  /* r0 and r15 (pc) have to be restored later */
1338  r->dirty = (i == 0) || (i == 15);
1339  r->valid = true;
1340  }
1341 
1342  LOG_DEBUG("entered debug state at PC 0x%" PRIx32 "", context[15]);
1343 
1344  /* exceptions other than USR & SYS have a saved program status register */
1345  if (arm->spsr) {
1346  uint32_t spsr;
1347  arm7_9->read_xpsr(target, &spsr, 1);
1348  retval = jtag_execute_queue();
1349  if (retval != ERROR_OK)
1350  return retval;
1351  buf_set_u32(arm->spsr->value, 0, 32, spsr);
1352  arm->spsr->dirty = false;
1353  arm->spsr->valid = true;
1354  }
1355 
1356  retval = jtag_execute_queue();
1357  if (retval != ERROR_OK)
1358  return retval;
1359 
1360  if (arm7_9->post_debug_entry) {
1361  retval = arm7_9->post_debug_entry(target);
1362  if (retval != ERROR_OK)
1363  return retval;
1364  }
1365 
1366  return ERROR_OK;
1367 }
1368 
1378 static int arm7_9_full_context(struct target *target)
1379 {
1380  int i;
1381  int retval;
1382  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1383  struct arm *arm = &arm7_9->arm;
1384  struct {
1385  uint32_t value;
1386  uint8_t *reg_p;
1387  } read_cache[6 * (16 + 1)];
1388  int read_cache_idx = 0;
1389 
1390  LOG_DEBUG("-");
1391 
1392  if (target->state != TARGET_HALTED) {
1393  LOG_WARNING("target not halted");
1394  return ERROR_TARGET_NOT_HALTED;
1395  }
1396 
1397  if (!is_arm_mode(arm->core_mode)) {
1398  LOG_ERROR("not a valid arm core mode - communication failure?");
1399  return ERROR_FAIL;
1400  }
1401 
1402  /* iterate through processor modes (User, FIQ, IRQ, SVC, ABT, UND)
1403  * SYS shares registers with User, so we don't touch SYS
1404  */
1405  for (i = 0; i < 6; i++) {
1406  uint32_t mask = 0;
1407  uint32_t *reg_p[16];
1408  int j;
1409  bool valid = true;
1410 
1411  /* check if there are invalid registers in the current mode
1412  */
1413  for (j = 0; j <= 16; j++) {
1415  valid = false;
1416  }
1417 
1418  if (!valid) {
1419  uint32_t tmp_cpsr;
1420 
1421  /* change processor mode (and mask T bit) */
1422  tmp_cpsr = buf_get_u32(arm->cpsr->value, 0, 8)
1423  & 0xe0;
1424  tmp_cpsr |= armv4_5_number_to_mode(i);
1425  tmp_cpsr &= ~0x20;
1426  arm7_9->write_xpsr_im8(target, tmp_cpsr & 0xff, 0, 0);
1427 
1428  for (j = 0; j < 15; j++) {
1430  armv4_5_number_to_mode(i), j).valid) {
1431  read_cache[read_cache_idx].reg_p = ARMV4_5_CORE_REG_MODE(
1432  arm->core_cache,
1434  j).value;
1435  reg_p[j] = &read_cache[read_cache_idx].value;
1436  read_cache_idx++;
1437  mask |= 1 << j;
1440  j).valid = true;
1443  j).dirty = false;
1444  }
1445  }
1446 
1447  /* if only the PSR is invalid, mask is all zeroes */
1448  if (mask)
1449  arm7_9->read_core_regs(target, mask, reg_p);
1450 
1451  /* check if the PSR has to be read */
1453  16).valid) {
1454  read_cache[read_cache_idx].reg_p = ARMV4_5_CORE_REG_MODE(arm->core_cache,
1455  armv4_5_number_to_mode(i), 16).value;
1456  arm7_9->read_xpsr(target, &read_cache[read_cache_idx].value, 1);
1457  read_cache_idx++;
1459  16).valid = true;
1461  16).dirty = false;
1462  }
1463  }
1464  }
1465 
1466  /* restore processor mode (mask T bit) */
1467  arm7_9->write_xpsr_im8(target,
1468  buf_get_u32(arm->cpsr->value, 0, 8) & ~0x20, 0, 0);
1469 
1470  retval = jtag_execute_queue();
1471  if (retval != ERROR_OK)
1472  return retval;
1473  /*
1474  * FIXME: regs in cache should be tagged as 'valid' only now,
1475  * not before the jtag_execute_queue()
1476  */
1477  while (read_cache_idx) {
1478  read_cache_idx--;
1479  buf_set_u32(read_cache[read_cache_idx].reg_p, 0, 32, read_cache[read_cache_idx].value);
1480  }
1481  return ERROR_OK;
1482 }
1483 
1497 {
1498  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1499  struct arm *arm = &arm7_9->arm;
1500  struct reg *reg;
1501  enum arm_mode current_mode = arm->core_mode;
1502  int i, j;
1503  bool dirty;
1504  int mode_change;
1505 
1506  LOG_DEBUG("-");
1507 
1508  if (target->state != TARGET_HALTED) {
1509  LOG_WARNING("target not halted");
1510  return ERROR_TARGET_NOT_HALTED;
1511  }
1512 
1513  if (arm7_9->pre_restore_context)
1514  arm7_9->pre_restore_context(target);
1515 
1516  if (!is_arm_mode(arm->core_mode)) {
1517  LOG_ERROR("not a valid arm core mode - communication failure?");
1518  return ERROR_FAIL;
1519  }
1520 
1521  /* iterate through processor modes (User, FIQ, IRQ, SVC, ABT, UND)
1522  * SYS shares registers with User, so we don't touch SYS
1523  */
1524  for (i = 0; i < 6; i++) {
1525  LOG_DEBUG("examining %s mode",
1527  dirty = false;
1528  mode_change = 0;
1529  /* check if there are dirty registers in the current mode
1530  */
1531  for (j = 0; j <= 16; j++) {
1533  if (reg->dirty) {
1534  if (reg->valid) {
1535  dirty = true;
1536  LOG_DEBUG("examining dirty reg: %s", reg->name);
1537  struct arm_reg *reg_arch_info;
1538  reg_arch_info = reg->arch_info;
1539  if ((reg_arch_info->mode != ARM_MODE_ANY)
1540  && (reg_arch_info->mode != current_mode)
1541  && !((reg_arch_info->mode == ARM_MODE_USR)
1542  && (arm->core_mode == ARM_MODE_SYS))
1543  && !((reg_arch_info->mode == ARM_MODE_SYS)
1544  && (arm->core_mode == ARM_MODE_USR))) {
1545  mode_change = 1;
1546  LOG_DEBUG("require mode change");
1547  }
1548  } else
1549  LOG_ERROR("BUG: dirty register '%s', but no valid data",
1550  reg->name);
1551  }
1552  }
1553 
1554  if (dirty) {
1555  uint32_t mask = 0x0;
1556  int num_regs = 0;
1557  uint32_t regs[16];
1558 
1559  if (mode_change) {
1560  uint32_t tmp_cpsr;
1561 
1562  /* change processor mode (mask T bit) */
1563  tmp_cpsr = buf_get_u32(arm->cpsr->value,
1564  0, 8) & 0xe0;
1565  tmp_cpsr |= armv4_5_number_to_mode(i);
1566  tmp_cpsr &= ~0x20;
1567  arm7_9->write_xpsr_im8(target, tmp_cpsr & 0xff, 0, 0);
1568  current_mode = armv4_5_number_to_mode(i);
1569  }
1570 
1571  for (j = 0; j <= 14; j++) {
1574  j);
1575 
1576  if (reg->dirty) {
1577  regs[j] = buf_get_u32(reg->value, 0, 32);
1578  mask |= 1 << j;
1579  num_regs++;
1580  reg->dirty = false;
1581  reg->valid = true;
1582  LOG_DEBUG("writing register %i mode %s "
1583  "with value 0x%8.8" PRIx32, j,
1585  regs[j]);
1586  }
1587  }
1588 
1589  if (mask)
1590  arm7_9->write_core_regs(target, mask, regs);
1591 
1592  reg =
1594  i), 16);
1595  struct arm_reg *reg_arch_info;
1596  reg_arch_info = reg->arch_info;
1597  if ((reg->dirty) && (reg_arch_info->mode != ARM_MODE_ANY)) {
1598  LOG_DEBUG("writing SPSR of mode %i with value 0x%8.8" PRIx32 "",
1599  i,
1600  buf_get_u32(reg->value, 0, 32));
1601  arm7_9->write_xpsr(target, buf_get_u32(reg->value, 0, 32), 1);
1602  }
1603  }
1604  }
1605 
1606  if (!arm->cpsr->dirty && (arm->core_mode != current_mode)) {
1607  /* restore processor mode (mask T bit) */
1608  uint32_t tmp_cpsr;
1609 
1610  tmp_cpsr = buf_get_u32(arm->cpsr->value, 0, 8) & 0xE0;
1611  tmp_cpsr |= armv4_5_number_to_mode(i);
1612  tmp_cpsr &= ~0x20;
1613  LOG_DEBUG("writing lower 8 bit of cpsr with value 0x%2.2x", (unsigned)(tmp_cpsr));
1614  arm7_9->write_xpsr_im8(target, tmp_cpsr & 0xff, 0, 0);
1615 
1616  } else if (arm->cpsr->dirty) {
1617  /* CPSR has been changed, full restore necessary (mask T bit) */
1618  LOG_DEBUG("writing cpsr with value 0x%8.8" PRIx32,
1619  buf_get_u32(arm->cpsr->value, 0, 32));
1620  arm7_9->write_xpsr(target,
1621  buf_get_u32(arm->cpsr->value, 0, 32)
1622  & ~0x20, 0);
1623  arm->cpsr->dirty = false;
1624  arm->cpsr->valid = true;
1625  }
1626 
1627  /* restore PC */
1628  LOG_DEBUG("writing PC with value 0x%8.8" PRIx32,
1629  buf_get_u32(arm->pc->value, 0, 32));
1630  arm7_9->write_pc(target, buf_get_u32(arm->pc->value, 0, 32));
1631  arm->pc->dirty = false;
1632 
1633  return ERROR_OK;
1634 }
1635 
1644 static int arm7_9_restart_core(struct target *target)
1645 {
1646  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1647  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
1648  int retval;
1649 
1650  /* set RESTART instruction */
1651  if (arm7_9->need_bypass_before_restart) {
1652  arm7_9->need_bypass_before_restart = 0;
1653 
1654  retval = arm_jtag_set_instr(jtag_info->tap, 0xf, NULL, TAP_IDLE);
1655  if (retval != ERROR_OK)
1656  return retval;
1657  }
1658  retval = arm_jtag_set_instr(jtag_info->tap, 0x4, NULL, TAP_IDLE);
1659  if (retval != ERROR_OK)
1660  return retval;
1661 
1663  return jtag_execute_queue();
1664 }
1665 
1673 {
1675 
1676  while (watchpoint) {
1677  if (!watchpoint->is_set)
1680  }
1681 }
1682 
1690 {
1692 
1693  /* set any pending breakpoints */
1694  while (breakpoint) {
1697  }
1698 }
1699 
1701  int current,
1703  int handle_breakpoints,
1704  int debug_execution)
1705 {
1706  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1707  struct arm *arm = &arm7_9->arm;
1708  struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL];
1709  int err, retval = ERROR_OK;
1710 
1711  LOG_DEBUG("-");
1712 
1713  if (target->state != TARGET_HALTED) {
1714  LOG_WARNING("target not halted");
1715  return ERROR_TARGET_NOT_HALTED;
1716  }
1717 
1718  if (!debug_execution)
1720 
1721  /* current = 1: continue on current pc, otherwise continue at <address> */
1722  if (!current)
1723  buf_set_u32(arm->pc->value, 0, 32, address);
1724 
1725  uint32_t current_pc;
1726  current_pc = buf_get_u32(arm->pc->value, 0, 32);
1727 
1728  /* the front-end may request us not to handle breakpoints */
1729  if (handle_breakpoints) {
1730  struct breakpoint *breakpoint;
1732  buf_get_u32(arm->pc->value, 0, 32));
1733  if (breakpoint) {
1734  LOG_DEBUG("unset breakpoint at 0x%8.8" TARGET_PRIxADDR " (id: %" PRIu32,
1738  if (retval != ERROR_OK)
1739  return retval;
1740 
1741  /* calculate PC of next instruction */
1742  uint32_t next_pc;
1743  retval = arm_simulate_step(target, &next_pc);
1744  if (retval != ERROR_OK) {
1745  uint32_t current_opcode;
1746  target_read_u32(target, current_pc, &current_opcode);
1747  LOG_ERROR(
1748  "Couldn't calculate PC of next instruction, current opcode was 0x%8.8" PRIx32 "",
1749  current_opcode);
1750  return retval;
1751  }
1752 
1753  LOG_DEBUG("enable single-step");
1754  arm7_9->enable_single_step(target, next_pc);
1755 
1757 
1758  retval = arm7_9_restore_context(target);
1759  if (retval != ERROR_OK)
1760  return retval;
1761 
1762  if (arm->core_state == ARM_STATE_ARM)
1763  arm7_9->branch_resume(target);
1764  else if (arm->core_state == ARM_STATE_THUMB)
1765  arm7_9->branch_resume_thumb(target);
1766  else {
1767  LOG_ERROR("unhandled core state");
1768  return ERROR_FAIL;
1769  }
1770 
1771  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGACK, 1, 0);
1772  embeddedice_write_reg(dbg_ctrl,
1773  buf_get_u32(dbg_ctrl->value, 0, dbg_ctrl->size));
1775 
1776  LOG_DEBUG("disable single-step");
1777  arm7_9->disable_single_step(target);
1778 
1779  if (err != ERROR_OK) {
1781  if (retval != ERROR_OK)
1782  return retval;
1784  return err;
1785  }
1786 
1787  retval = arm7_9_debug_entry(target);
1788  if (retval != ERROR_OK)
1789  return retval;
1790  LOG_DEBUG("new PC after step: 0x%8.8" PRIx32,
1791  buf_get_u32(arm->pc->value, 0, 32));
1792 
1793  LOG_DEBUG("set breakpoint at 0x%8.8" TARGET_PRIxADDR "", breakpoint->address);
1795  if (retval != ERROR_OK)
1796  return retval;
1797  }
1798  }
1799 
1800  /* enable any pending breakpoints and watchpoints */
1803 
1804  retval = arm7_9_restore_context(target);
1805  if (retval != ERROR_OK)
1806  return retval;
1807 
1808  if (arm->core_state == ARM_STATE_ARM)
1809  arm7_9->branch_resume(target);
1810  else if (arm->core_state == ARM_STATE_THUMB)
1811  arm7_9->branch_resume_thumb(target);
1812  else {
1813  LOG_ERROR("unhandled core state");
1814  return ERROR_FAIL;
1815  }
1816 
1817  /* deassert DBGACK and INTDIS */
1818  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGACK, 1, 0);
1819  /* INTDIS only when we really resume, not during debug execution */
1820  if (!debug_execution)
1821  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_INTDIS, 1, 0);
1822  embeddedice_write_reg(dbg_ctrl, buf_get_u32(dbg_ctrl->value, 0, dbg_ctrl->size));
1823 
1824  retval = arm7_9_restart_core(target);
1825  if (retval != ERROR_OK)
1826  return retval;
1827 
1829 
1830  if (!debug_execution) {
1831  /* registers are now invalid */
1835  if (retval != ERROR_OK)
1836  return retval;
1837  } else {
1840  if (retval != ERROR_OK)
1841  return retval;
1842  }
1843 
1844  LOG_DEBUG("target resumed");
1845 
1846  return ERROR_OK;
1847 }
1848 
1849 void arm7_9_enable_eice_step(struct target *target, uint32_t next_pc)
1850 {
1851  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1852  struct arm *arm = &arm7_9->arm;
1853  uint32_t current_pc;
1854  current_pc = buf_get_u32(arm->pc->value, 0, 32);
1855 
1856  if (next_pc != current_pc) {
1857  /* setup an inverse breakpoint on the current PC
1858  * - comparator 1 matches the current address
1859  * - rangeout from comparator 1 is connected to comparator 0 rangein
1860  * - comparator 0 matches any address, as long as rangein is low */
1866  ~(EICE_W_CTRL_RANGE | EICE_W_CTRL_NOPC) & 0xff);
1868  current_pc);
1873  ~EICE_W_CTRL_NOPC & 0xff);
1874  } else {
1885  ~EICE_W_CTRL_NOPC & 0xff);
1886  }
1887 }
1888 
1890 {
1891  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1892 
1902 }
1903 
1904 int arm7_9_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
1905 {
1906  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1907  struct arm *arm = &arm7_9->arm;
1908  struct breakpoint *breakpoint = NULL;
1909  int err, retval;
1910 
1911  if (target->state != TARGET_HALTED) {
1912  LOG_WARNING("target not halted");
1913  return ERROR_TARGET_NOT_HALTED;
1914  }
1915 
1916  /* current = 1: continue on current pc, otherwise continue at <address> */
1917  if (!current)
1918  buf_set_u32(arm->pc->value, 0, 32, address);
1919 
1920  uint32_t current_pc = buf_get_u32(arm->pc->value, 0, 32);
1921 
1922  /* the front-end may request us not to handle breakpoints */
1923  if (handle_breakpoints)
1924  breakpoint = breakpoint_find(target, current_pc);
1925  if (breakpoint) {
1927  if (retval != ERROR_OK)
1928  return retval;
1929  }
1930 
1932 
1933  /* calculate PC of next instruction */
1934  uint32_t next_pc;
1935  retval = arm_simulate_step(target, &next_pc);
1936  if (retval != ERROR_OK) {
1937  uint32_t current_opcode;
1938  target_read_u32(target, current_pc, &current_opcode);
1939  LOG_ERROR(
1940  "Couldn't calculate PC of next instruction, current opcode was 0x%8.8" PRIx32 "",
1941  current_opcode);
1942  return retval;
1943  }
1944 
1945  retval = arm7_9_restore_context(target);
1946  if (retval != ERROR_OK)
1947  return retval;
1948 
1949  arm7_9->enable_single_step(target, next_pc);
1950 
1951  if (arm->core_state == ARM_STATE_ARM)
1952  arm7_9->branch_resume(target);
1953  else if (arm->core_state == ARM_STATE_THUMB)
1954  arm7_9->branch_resume_thumb(target);
1955  else {
1956  LOG_ERROR("unhandled core state");
1957  return ERROR_FAIL;
1958  }
1959 
1961  if (retval != ERROR_OK)
1962  return retval;
1963 
1965  arm7_9->disable_single_step(target);
1966 
1967  /* registers are now invalid */
1969 
1970  if (err != ERROR_OK)
1972  else {
1973  retval = arm7_9_debug_entry(target);
1974  if (retval != ERROR_OK)
1975  return retval;
1977  if (retval != ERROR_OK)
1978  return retval;
1979  LOG_DEBUG("target stepped");
1980  }
1981 
1982  if (breakpoint) {
1984  if (retval != ERROR_OK)
1985  return retval;
1986  }
1987 
1988  return err;
1989 }
1990 
1991 static int arm7_9_read_core_reg(struct target *target, struct reg *r,
1992  int num, enum arm_mode mode)
1993 {
1994  uint32_t *reg_p[16];
1995  int retval;
1996  struct arm_reg *areg = r->arch_info;
1997  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
1998  struct arm *arm = &arm7_9->arm;
1999 
2000  if (!is_arm_mode(arm->core_mode))
2001  return ERROR_FAIL;
2002  if ((num < 0) || (num > 16))
2004 
2005  if ((mode != ARM_MODE_ANY) && (mode != arm->core_mode)
2006  && (areg->mode != ARM_MODE_ANY)) {
2007  uint32_t tmp_cpsr;
2008 
2009  /* change processor mode (mask T bit) */
2010  tmp_cpsr = buf_get_u32(arm->cpsr->value, 0, 8) & 0xE0;
2011  tmp_cpsr |= mode;
2012  tmp_cpsr &= ~0x20;
2013  arm7_9->write_xpsr_im8(target, tmp_cpsr & 0xff, 0, 0);
2014  }
2015 
2016  uint32_t value = 0;
2017  if ((num >= 0) && (num <= 15)) {
2018  /* read a normal core register */
2019  reg_p[num] = &value;
2020 
2021  arm7_9->read_core_regs(target, 1 << num, reg_p);
2022  } else {
2023  /* read a program status register
2024  * if the register mode is MODE_ANY, we read the cpsr, otherwise a spsr
2025  */
2026  arm7_9->read_xpsr(target, &value, areg->mode != ARM_MODE_ANY);
2027  }
2028 
2029  retval = jtag_execute_queue();
2030  if (retval != ERROR_OK)
2031  return retval;
2032 
2033  r->valid = true;
2034  r->dirty = false;
2035  buf_set_u32(r->value, 0, 32, value);
2036 
2037  if ((mode != ARM_MODE_ANY) && (mode != arm->core_mode)
2038  && (areg->mode != ARM_MODE_ANY)) {
2039  /* restore processor mode (mask T bit) */
2040  arm7_9->write_xpsr_im8(target,
2041  buf_get_u32(arm->cpsr->value, 0, 8) & ~0x20, 0, 0);
2042  }
2043 
2044  return ERROR_OK;
2045 }
2046 
2047 static int arm7_9_write_core_reg(struct target *target, struct reg *r,
2048  int num, enum arm_mode mode, uint8_t *value)
2049 {
2050  uint32_t reg[16];
2051  struct arm_reg *areg = r->arch_info;
2052  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2053  struct arm *arm = &arm7_9->arm;
2054 
2055  if (!is_arm_mode(arm->core_mode))
2056  return ERROR_FAIL;
2057  if ((num < 0) || (num > 16))
2059 
2060  if ((mode != ARM_MODE_ANY) && (mode != arm->core_mode)
2061  && (areg->mode != ARM_MODE_ANY)) {
2062  uint32_t tmp_cpsr;
2063 
2064  /* change processor mode (mask T bit) */
2065  tmp_cpsr = buf_get_u32(arm->cpsr->value, 0, 8) & 0xE0;
2066  tmp_cpsr |= mode;
2067  tmp_cpsr &= ~0x20;
2068  arm7_9->write_xpsr_im8(target, tmp_cpsr & 0xff, 0, 0);
2069  }
2070 
2071  if ((num >= 0) && (num <= 15)) {
2072  /* write a normal core register */
2073  reg[num] = buf_get_u32(value, 0, 32);
2074 
2075  arm7_9->write_core_regs(target, 1 << num, reg);
2076  } else {
2077  /* write a program status register
2078  * if the register mode is MODE_ANY, we write the cpsr, otherwise a spsr
2079  */
2080  int spsr = (areg->mode != ARM_MODE_ANY);
2081 
2082  uint32_t t = buf_get_u32(value, 0, 32);
2083  /* if we're writing the CPSR, mask the T bit */
2084  if (!spsr)
2085  t &= ~0x20;
2086 
2087  arm7_9->write_xpsr(target, t, spsr);
2088  }
2089 
2090  r->valid = true;
2091  r->dirty = false;
2092 
2093  if ((mode != ARM_MODE_ANY) && (mode != arm->core_mode)
2094  && (areg->mode != ARM_MODE_ANY)) {
2095  /* restore processor mode (mask T bit) */
2096  arm7_9->write_xpsr_im8(target,
2097  buf_get_u32(arm->cpsr->value, 0, 8) & ~0x20, 0, 0);
2098  }
2099 
2100  return jtag_execute_queue();
2101 }
2102 
2104  target_addr_t address,
2105  uint32_t size,
2106  uint32_t count,
2107  uint8_t *buffer)
2108 {
2109  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2110  struct arm *arm = &arm7_9->arm;
2111  uint32_t reg[16];
2112  uint32_t num_accesses = 0;
2113  int thisrun_accesses;
2114  int i;
2115  uint32_t cpsr;
2116  int retval;
2117  int last_reg = 0;
2118 
2119  LOG_DEBUG("address: 0x%8.8" TARGET_PRIxADDR ", size: 0x%8.8" PRIx32 ", count: 0x%8.8" PRIx32 "",
2120  address, size, count);
2121 
2122  if (target->state != TARGET_HALTED) {
2123  LOG_WARNING("target not halted");
2124  return ERROR_TARGET_NOT_HALTED;
2125  }
2126 
2127  /* sanitize arguments */
2128  if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !(buffer))
2130 
2131  if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u)))
2133 
2134  /* load the base register with the address of the first word */
2135  reg[0] = address;
2136  arm7_9->write_core_regs(target, 0x1, reg);
2137 
2138  int j = 0;
2139 
2140  switch (size) {
2141  case 4:
2142  while (num_accesses < count) {
2143  uint32_t reg_list;
2144  thisrun_accesses =
2145  ((count - num_accesses) >= 14) ? 14 : (count - num_accesses);
2146  reg_list = (0xffff >> (15 - thisrun_accesses)) & 0xfffe;
2147 
2148  if (last_reg <= thisrun_accesses)
2149  last_reg = thisrun_accesses;
2150 
2151  arm7_9->load_word_regs(target, reg_list);
2152 
2153  /* fast memory reads are only safe when the target is running
2154  * from a sufficiently high clock (32 kHz is usually too slow)
2155  */
2156  if (arm7_9->fast_memory_access)
2158  else
2159  retval = arm7_9_execute_sys_speed(target);
2160  if (retval != ERROR_OK)
2161  return retval;
2162 
2163  arm7_9->read_core_regs_target_buffer(target, reg_list, buffer, 4);
2164 
2165  /* advance buffer, count number of accesses */
2166  buffer += thisrun_accesses * 4;
2167  num_accesses += thisrun_accesses;
2168 
2169  if ((j++%1024) == 0)
2170  keep_alive();
2171  }
2172  break;
2173  case 2:
2174  while (num_accesses < count) {
2175  uint32_t reg_list;
2176  thisrun_accesses =
2177  ((count - num_accesses) >= 14) ? 14 : (count - num_accesses);
2178  reg_list = (0xffff >> (15 - thisrun_accesses)) & 0xfffe;
2179 
2180  for (i = 1; i <= thisrun_accesses; i++) {
2181  if (i > last_reg)
2182  last_reg = i;
2183  arm7_9->load_hword_reg(target, i);
2184  /* fast memory reads are only safe when the target is running
2185  * from a sufficiently high clock (32 kHz is usually too slow)
2186  */
2187  if (arm7_9->fast_memory_access)
2189  else
2190  retval = arm7_9_execute_sys_speed(target);
2191  if (retval != ERROR_OK)
2192  return retval;
2193 
2194  }
2195 
2196  arm7_9->read_core_regs_target_buffer(target, reg_list, buffer, 2);
2197 
2198  /* advance buffer, count number of accesses */
2199  buffer += thisrun_accesses * 2;
2200  num_accesses += thisrun_accesses;
2201 
2202  if ((j++%1024) == 0)
2203  keep_alive();
2204  }
2205  break;
2206  case 1:
2207  while (num_accesses < count) {
2208  uint32_t reg_list;
2209  thisrun_accesses =
2210  ((count - num_accesses) >= 14) ? 14 : (count - num_accesses);
2211  reg_list = (0xffff >> (15 - thisrun_accesses)) & 0xfffe;
2212 
2213  for (i = 1; i <= thisrun_accesses; i++) {
2214  if (i > last_reg)
2215  last_reg = i;
2216  arm7_9->load_byte_reg(target, i);
2217  /* fast memory reads are only safe when the target is running
2218  * from a sufficiently high clock (32 kHz is usually too slow)
2219  */
2220  if (arm7_9->fast_memory_access)
2222  else
2223  retval = arm7_9_execute_sys_speed(target);
2224  if (retval != ERROR_OK)
2225  return retval;
2226  }
2227 
2228  arm7_9->read_core_regs_target_buffer(target, reg_list, buffer, 1);
2229 
2230  /* advance buffer, count number of accesses */
2231  buffer += thisrun_accesses * 1;
2232  num_accesses += thisrun_accesses;
2233 
2234  if ((j++%1024) == 0)
2235  keep_alive();
2236  }
2237  break;
2238  }
2239 
2240  if (!is_arm_mode(arm->core_mode))
2241  return ERROR_FAIL;
2242 
2243  for (i = 0; i <= last_reg; i++) {
2244  struct reg *r = arm_reg_current(arm, i);
2245  r->dirty = r->valid;
2246  }
2247 
2248  arm7_9->read_xpsr(target, &cpsr, 0);
2249  retval = jtag_execute_queue();
2250  if (retval != ERROR_OK) {
2251  LOG_ERROR("JTAG error while reading cpsr");
2252  return ERROR_TARGET_DATA_ABORT;
2253  }
2254 
2255  if (((cpsr & 0x1f) == ARM_MODE_ABT) && (arm->core_mode != ARM_MODE_ABT)) {
2256  LOG_WARNING(
2257  "memory read caused data abort "
2258  "(address: 0x%8.8" TARGET_PRIxADDR ", size: 0x%" PRIx32 ", count: 0x%" PRIx32 ")",
2259  address,
2260  size,
2261  count);
2262 
2263  arm7_9->write_xpsr_im8(target,
2264  buf_get_u32(arm->cpsr->value, 0, 8)
2265  & ~0x20, 0, 0);
2266 
2267  return ERROR_TARGET_DATA_ABORT;
2268  }
2269 
2270  return ERROR_OK;
2271 }
2272 
2274  target_addr_t address,
2275  uint32_t size,
2276  uint32_t count,
2277  const uint8_t *buffer)
2278 {
2279  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2280  struct arm *arm = &arm7_9->arm;
2281  struct reg *dbg_ctrl = &arm7_9->eice_cache->reg_list[EICE_DBG_CTRL];
2282 
2283  uint32_t reg[16];
2284  uint32_t num_accesses = 0;
2285  int thisrun_accesses;
2286  int i;
2287  uint32_t cpsr;
2288  int retval;
2289  int last_reg = 0;
2290 
2291 #ifdef _DEBUG_ARM7_9_
2292  LOG_DEBUG("address: 0x%8.8x, size: 0x%8.8x, count: 0x%8.8x", address, size, count);
2293 #endif
2294 
2295  if (target->state != TARGET_HALTED) {
2296  LOG_WARNING("target not halted");
2297  return ERROR_TARGET_NOT_HALTED;
2298  }
2299 
2300  /* sanitize arguments */
2301  if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !(buffer))
2303 
2304  if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u)))
2306 
2307  /* load the base register with the address of the first word */
2308  reg[0] = address;
2309  arm7_9->write_core_regs(target, 0x1, reg);
2310 
2311  /* Clear DBGACK, to make sure memory fetches work as expected */
2312  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGACK, 1, 0);
2313  embeddedice_store_reg(dbg_ctrl);
2314 
2315  switch (size) {
2316  case 4:
2317  while (num_accesses < count) {
2318  uint32_t reg_list;
2319  thisrun_accesses =
2320  ((count - num_accesses) >= 14) ? 14 : (count - num_accesses);
2321  reg_list = (0xffff >> (15 - thisrun_accesses)) & 0xfffe;
2322 
2323  for (i = 1; i <= thisrun_accesses; i++) {
2324  if (i > last_reg)
2325  last_reg = i;
2327  buffer += 4;
2328  }
2329 
2330  arm7_9->write_core_regs(target, reg_list, reg);
2331 
2332  arm7_9->store_word_regs(target, reg_list);
2333 
2334  /* fast memory writes are only safe when the target is running
2335  * from a sufficiently high clock (32 kHz is usually too slow)
2336  */
2337  if (arm7_9->fast_memory_access)
2339  else {
2340  retval = arm7_9_execute_sys_speed(target);
2341 
2342  /*
2343  * if memory writes are made when the clock is running slow
2344  * (i.e. 32 kHz) which is necessary in some scripts to reconfigure
2345  * processor operations after a "reset halt" or "reset init",
2346  * need to immediately stroke the keep alive or will end up with
2347  * gdb "keep alive not sent error message" problem.
2348  */
2349 
2350  keep_alive();
2351  }
2352 
2353  if (retval != ERROR_OK)
2354  return retval;
2355 
2356  num_accesses += thisrun_accesses;
2357  }
2358  break;
2359  case 2:
2360  while (num_accesses < count) {
2361  uint32_t reg_list;
2362  thisrun_accesses =
2363  ((count - num_accesses) >= 14) ? 14 : (count - num_accesses);
2364  reg_list = (0xffff >> (15 - thisrun_accesses)) & 0xfffe;
2365 
2366  for (i = 1; i <= thisrun_accesses; i++) {
2367  if (i > last_reg)
2368  last_reg = i;
2369  reg[i] = target_buffer_get_u16(target, buffer) & 0xffff;
2370  buffer += 2;
2371  }
2372 
2373  arm7_9->write_core_regs(target, reg_list, reg);
2374 
2375  for (i = 1; i <= thisrun_accesses; i++) {
2376  arm7_9->store_hword_reg(target, i);
2377 
2378  /* fast memory writes are only safe when the target is running
2379  * from a sufficiently high clock (32 kHz is usually too slow)
2380  */
2381  if (arm7_9->fast_memory_access)
2383  else {
2384  retval = arm7_9_execute_sys_speed(target);
2385 
2386  /*
2387  * if memory writes are made when the clock is running slow
2388  * (i.e. 32 kHz) which is necessary in some scripts to reconfigure
2389  * processor operations after a "reset halt" or "reset init",
2390  * need to immediately stroke the keep alive or will end up with
2391  * gdb "keep alive not sent error message" problem.
2392  */
2393 
2394  keep_alive();
2395  }
2396 
2397  if (retval != ERROR_OK)
2398  return retval;
2399  }
2400 
2401  num_accesses += thisrun_accesses;
2402  }
2403  break;
2404  case 1:
2405  while (num_accesses < count) {
2406  uint32_t reg_list;
2407  thisrun_accesses =
2408  ((count - num_accesses) >= 14) ? 14 : (count - num_accesses);
2409  reg_list = (0xffff >> (15 - thisrun_accesses)) & 0xfffe;
2410 
2411  for (i = 1; i <= thisrun_accesses; i++) {
2412  if (i > last_reg)
2413  last_reg = i;
2414  reg[i] = *buffer++ & 0xff;
2415  }
2416 
2417  arm7_9->write_core_regs(target, reg_list, reg);
2418 
2419  for (i = 1; i <= thisrun_accesses; i++) {
2420  arm7_9->store_byte_reg(target, i);
2421  /* fast memory writes are only safe when the target is running
2422  * from a sufficiently high clock (32 kHz is usually too slow)
2423  */
2424  if (arm7_9->fast_memory_access)
2426  else {
2427  retval = arm7_9_execute_sys_speed(target);
2428 
2429  /*
2430  * if memory writes are made when the clock is running slow
2431  * (i.e. 32 kHz) which is necessary in some scripts to reconfigure
2432  * processor operations after a "reset halt" or "reset init",
2433  * need to immediately stroke the keep alive or will end up with
2434  * gdb "keep alive not sent error message" problem.
2435  */
2436 
2437  keep_alive();
2438  }
2439 
2440  if (retval != ERROR_OK)
2441  return retval;
2442 
2443  }
2444 
2445  num_accesses += thisrun_accesses;
2446  }
2447  break;
2448  }
2449 
2450  /* Re-Set DBGACK */
2451  buf_set_u32(dbg_ctrl->value, EICE_DBG_CONTROL_DBGACK, 1, 1);
2452  embeddedice_store_reg(dbg_ctrl);
2453 
2454  if (!is_arm_mode(arm->core_mode))
2455  return ERROR_FAIL;
2456 
2457  for (i = 0; i <= last_reg; i++) {
2458  struct reg *r = arm_reg_current(arm, i);
2459  r->dirty = r->valid;
2460  }
2461 
2462  arm7_9->read_xpsr(target, &cpsr, 0);
2463  retval = jtag_execute_queue();
2464  if (retval != ERROR_OK) {
2465  LOG_ERROR("JTAG error while reading cpsr");
2466  return ERROR_TARGET_DATA_ABORT;
2467  }
2468 
2469  if (((cpsr & 0x1f) == ARM_MODE_ABT) && (arm->core_mode != ARM_MODE_ABT)) {
2470  LOG_WARNING(
2471  "memory write caused data abort "
2472  "(address: 0x%8.8" TARGET_PRIxADDR ", size: 0x%" PRIx32 ", count: 0x%" PRIx32 ")",
2473  address,
2474  size,
2475  count);
2476 
2477  arm7_9->write_xpsr_im8(target,
2478  buf_get_u32(arm->cpsr->value, 0, 8)
2479  & ~0x20, 0, 0);
2480 
2481  return ERROR_TARGET_DATA_ABORT;
2482  }
2483 
2484  return ERROR_OK;
2485 }
2486 
2488  target_addr_t address,
2489  uint32_t size,
2490  uint32_t count,
2491  const uint8_t *buffer)
2492 {
2493  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2494  int retval;
2495 
2496  if (size == 4 && count > 32 && arm7_9->bulk_write_memory) {
2497  /* Attempt to do a bulk write */
2498  retval = arm7_9->bulk_write_memory(target, address, count, buffer);
2499 
2500  if (retval == ERROR_OK)
2501  return ERROR_OK;
2502  }
2503 
2504  return arm7_9->write_memory(target, address, size, count, buffer);
2505 }
2506 
2508  uint32_t address,
2509  uint32_t size,
2510  uint32_t count,
2511  const uint8_t *buffer)
2512 {
2513  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2514 
2515  return arm7_9->write_memory(target, address, size, count, buffer);
2516 }
2517 
2518 static int dcc_count;
2519 static const uint8_t *dcc_buffer;
2520 
2522  uint32_t exit_point,
2523  int timeout_ms,
2524  void *arch_info)
2525 {
2526  int retval = ERROR_OK;
2527  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2528 
2530  if (retval != ERROR_OK)
2531  return retval;
2532 
2533  int little = target->endianness == TARGET_LITTLE_ENDIAN;
2534  int count = dcc_count;
2535  const uint8_t *buffer = dcc_buffer;
2536  if (count > 2) {
2537  /* Handle first & last using standard embeddedice_write_reg and the middle ones w/the
2538  * core function repeated. */
2541  buffer += 4;
2542 
2543  struct embeddedice_reg *ice_reg =
2545  uint8_t reg_addr = ice_reg->addr & 0x1f;
2546  struct jtag_tap *tap;
2547  tap = ice_reg->jtag_info->tap;
2548 
2549  embeddedice_write_dcc(tap, reg_addr, buffer, little, count-2);
2550  buffer += (count-2)*4;
2551 
2554  } else {
2555  int i;
2556  for (i = 0; i < count; i++) {
2559  buffer += 4;
2560  }
2561  }
2562 
2563  retval = target_halt(target);
2564  if (retval != ERROR_OK)
2565  return retval;
2566  return target_wait_state(target, TARGET_HALTED, 500);
2567 }
2568 
2569 static const uint32_t dcc_code[] = {
2570  /* r0 == input, points to memory buffer
2571  * r1 == scratch
2572  */
2573 
2574  /* spin until DCC control (c0) reports data arrived */
2575  0xee101e10, /* w: mrc p14, #0, r1, c0, c0 */
2576  0xe3110001, /* tst r1, #1 */
2577  0x0afffffc, /* bne w */
2578 
2579  /* read word from DCC (c1), write to memory */
2580  0xee111e10, /* mrc p14, #0, r1, c1, c0 */
2581  0xe4801004, /* str r1, [r0], #4 */
2582 
2583  /* repeat */
2584  0xeafffff9 /* b w */
2585 };
2586 
2588  target_addr_t address,
2589  uint32_t count,
2590  const uint8_t *buffer)
2591 {
2592  int retval;
2593  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2594 
2595  if (address % 4 != 0)
2597 
2598  if (!arm7_9->dcc_downloads)
2600 
2601  /* regrab previously allocated working_area, or allocate a new one */
2602  if (!arm7_9->dcc_working_area) {
2603  uint8_t dcc_code_buf[6 * 4];
2604 
2605  /* make sure we have a working area */
2607  LOG_INFO("no working area available, falling back to memory writes");
2609  }
2610 
2611  /* copy target instructions to target endianness */
2613 
2614  /* write DCC code to working area, using the non-optimized
2615  * memory write to avoid ending up here again */
2617  arm7_9->dcc_working_area->address, 4, 6, dcc_code_buf);
2618  if (retval != ERROR_OK)
2619  return retval;
2620  }
2621 
2622  struct arm_algorithm arm_algo;
2623  struct reg_param reg_params[1];
2624 
2625  arm_algo.common_magic = ARM_COMMON_MAGIC;
2626  arm_algo.core_mode = ARM_MODE_SVC;
2627  arm_algo.core_state = ARM_STATE_ARM;
2628 
2629  init_reg_param(&reg_params[0], "r0", 32, PARAM_IN_OUT);
2630 
2631  buf_set_u32(reg_params[0].value, 0, 32, address);
2632 
2633  dcc_count = count;
2634  dcc_buffer = buffer;
2635  retval = armv4_5_run_algorithm_inner(target, 0, NULL, 1, reg_params,
2636  arm7_9->dcc_working_area->address,
2637  arm7_9->dcc_working_area->address + 6*4,
2638  20*1000, &arm_algo, arm7_9_dcc_completion);
2639 
2640  if (retval == ERROR_OK) {
2641  uint32_t endaddress = buf_get_u32(reg_params[0].value, 0, 32);
2642  if (endaddress != (address + count*4)) {
2643  LOG_ERROR(
2644  "DCC write failed, expected end address 0x%08" TARGET_PRIxADDR " got 0x%0" PRIx32 "",
2645  (address + count*4),
2646  endaddress);
2647  retval = ERROR_FAIL;
2648  }
2649  }
2650 
2651  destroy_reg_param(&reg_params[0]);
2652 
2653  return retval;
2654 }
2655 
2660 {
2661  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2662  int retval;
2663 
2664  if (!target_was_examined(target)) {
2665  struct reg_cache *t, **cache_p;
2666 
2667  t = embeddedice_build_reg_cache(target, arm7_9);
2668  if (!t)
2669  return ERROR_FAIL;
2670 
2672  (*cache_p) = t;
2673  arm7_9->eice_cache = (*cache_p);
2674 
2675  if (arm7_9->arm.etm)
2676  (*cache_p)->next = etm_build_reg_cache(target,
2677  &arm7_9->jtag_info,
2678  arm7_9->arm.etm);
2679 
2681  }
2682 
2683  retval = embeddedice_setup(target);
2684  if (retval == ERROR_OK)
2685  retval = arm7_9_setup(target);
2686  if (retval == ERROR_OK && arm7_9->arm.etm)
2687  retval = etm_setup(target);
2688  return retval;
2689 }
2690 
2692 {
2693  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2694 
2697 
2699 }
2700 
2702 {
2703  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2704 
2705  if (get_target_reset_nag() && !arm7_9->dcc_downloads)
2706  LOG_WARNING(
2707  "NOTE! DCC downloads have not been enabled, defaulting to slow memory writes. Type 'help dcc'.");
2708 
2710  LOG_WARNING("NOTE! Severe performance degradation without working memory enabled.");
2711 
2712  if (get_target_reset_nag() && !arm7_9->fast_memory_access)
2713  LOG_WARNING(
2714  "NOTE! Severe performance degradation without fast memory access enabled. Type 'help fast'.");
2715 
2716  return ERROR_OK;
2717 }
2718 
2721  jtag_callback_data_t i_flip)
2722 {
2723  uint8_t *in = (uint8_t *)pu8_in;
2724  int size = (int)i_size;
2725  int be = (int)i_be;
2726  int flip = (int)i_flip;
2727  uint32_t readback;
2728 
2729  switch (size) {
2730  case 4:
2731  readback = le_to_h_u32(in);
2732  if (flip)
2733  readback = flip_u32(readback, 32);
2734  if (be)
2735  h_u32_to_be(in, readback);
2736  else
2737  h_u32_to_le(in, readback);
2738  break;
2739  case 2:
2740  readback = le_to_h_u16(in);
2741  if (flip)
2742  readback = flip_u32(readback, 16);
2743  if (be)
2744  h_u16_to_be(in, readback & 0xffff);
2745  else
2746  h_u16_to_le(in, readback & 0xffff);
2747  break;
2748  case 1:
2749  readback = *in;
2750  if (flip)
2751  readback = flip_u32(readback, 8);
2752  *in = readback & 0xff;
2753  break;
2754  }
2755 
2756  return ERROR_OK;
2757 }
2758 
2759 COMMAND_HANDLER(handle_arm7_9_dbgrq_command)
2760 {
2762  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2763 
2764  if (!is_arm7_9(arm7_9)) {
2765  command_print(CMD, "current target isn't an ARM7/ARM9 target");
2766  return ERROR_TARGET_INVALID;
2767  }
2768 
2769  if (CMD_ARGC > 0)
2771 
2773  "use of EmbeddedICE dbgrq instead of breakpoint for target halt %s",
2774  (arm7_9->use_dbgrq) ? "enabled" : "disabled");
2775 
2776  return ERROR_OK;
2777 }
2778 
2779 COMMAND_HANDLER(handle_arm7_9_fast_memory_access_command)
2780 {
2782  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2783 
2784  if (!is_arm7_9(arm7_9)) {
2785  command_print(CMD, "current target isn't an ARM7/ARM9 target");
2786  return ERROR_TARGET_INVALID;
2787  }
2788 
2789  if (CMD_ARGC > 0)
2791 
2793  "fast memory access is %s",
2794  (arm7_9->fast_memory_access) ? "enabled" : "disabled");
2795 
2796  return ERROR_OK;
2797 }
2798 
2799 COMMAND_HANDLER(handle_arm7_9_dcc_downloads_command)
2800 {
2802  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2803 
2804  if (!is_arm7_9(arm7_9)) {
2805  command_print(CMD, "current target isn't an ARM7/ARM9 target");
2806  return ERROR_TARGET_INVALID;
2807  }
2808 
2809  if (CMD_ARGC > 0)
2811 
2813  "dcc downloads are %s",
2814  (arm7_9->dcc_downloads) ? "enabled" : "disabled");
2815 
2816  return ERROR_OK;
2817 }
2818 
2819 static int arm7_9_setup_semihosting(struct target *target, int enable)
2820 {
2821  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
2822 
2823  if (!is_arm7_9(arm7_9)) {
2824  LOG_USER("current target isn't an ARM7/ARM9 target");
2825  return ERROR_TARGET_INVALID;
2826  }
2827 
2828  if (arm7_9->has_vector_catch) {
2829  struct reg *vector_catch = &arm7_9->eice_cache
2831 
2832  if (!vector_catch->valid)
2833  embeddedice_read_reg(vector_catch);
2834  buf_set_u32(vector_catch->value, 2, 1, enable);
2835  embeddedice_store_reg(vector_catch);
2836  } else {
2837  /* TODO: allow optional high vectors and/or BKPT_HARD */
2838  if (enable)
2840  else
2842  }
2843 
2844  return ERROR_OK;
2845 }
2846 
2847 int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9)
2848 {
2849  int retval = ERROR_OK;
2850  struct arm *arm = &arm7_9->arm;
2851 
2853 
2854  retval = arm_jtag_setup_connection(&arm7_9->jtag_info);
2855  if (retval != ERROR_OK)
2856  return retval;
2857 
2858  /* caller must have allocated via calloc(), so everything's zeroed */
2859 
2860  arm7_9->wp_available_max = 2;
2861 
2862  arm7_9->fast_memory_access = false;
2863  arm7_9->dcc_downloads = false;
2864 
2865  arm->arch_info = arm7_9;
2871 
2872  retval = arm_init_arch_info(target, arm);
2873  if (retval != ERROR_OK)
2874  return retval;
2875 
2878 }
2879 
2880 static const struct command_registration arm7_9_any_command_handlers[] = {
2881  {
2882  .name = "dbgrq",
2883  .handler = handle_arm7_9_dbgrq_command,
2884  .mode = COMMAND_ANY,
2885  .usage = "['enable'|'disable']",
2886  .help = "use EmbeddedICE dbgrq instead of breakpoint "
2887  "for target halt requests",
2888  },
2889  {
2890  .name = "fast_memory_access",
2891  .handler = handle_arm7_9_fast_memory_access_command,
2892  .mode = COMMAND_ANY,
2893  .usage = "['enable'|'disable']",
2894  .help = "use fast memory accesses instead of slower "
2895  "but potentially safer accesses",
2896  },
2897  {
2898  .name = "dcc_downloads",
2899  .handler = handle_arm7_9_dcc_downloads_command,
2900  .mode = COMMAND_ANY,
2901  .usage = "['enable'|'disable']",
2902  .help = "use DCC downloads for larger memory writes",
2903  },
2905 };
2907  {
2909  },
2910  {
2912  },
2913  {
2914  .name = "arm7_9",
2915  .mode = COMMAND_ANY,
2916  .help = "arm7/9 specific commands",
2917  .usage = "",
2918  .chain = arm7_9_any_command_handlers,
2919  },
2921 };
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
Definition: algorithm.c:29
void destroy_reg_param(struct reg_param *param)
Definition: algorithm.c:37
@ PARAM_IN_OUT
Definition: algorithm.h:17
static void arm7_9_enable_watchpoints(struct target *target)
Enable the watchpoints on an ARM7/9 target.
static int arm7_9_read_core_reg(struct target *target, struct reg *r, int num, enum arm_mode mode)
static int dcc_count
static int arm7_9_execute_fast_sys_speed(struct target *target)
Restarts the target by sending a RESTART instruction and moving the JTAG state to IDLE.
int arm7_9_endianness_callback(jtag_callback_data_t pu8_in, jtag_callback_data_t i_size, jtag_callback_data_t i_be, jtag_callback_data_t i_flip)
static int arm7_9_unset_watchpoint(struct target *target, struct watchpoint *watchpoint)
Unset an existing watchpoint and clear the used watchpoint unit.
static int arm7_9_set_software_breakpoints(struct arm7_9_common *arm7_9)
Setup an ARM7/9 target's embedded ICE registers for software breakpoints.
static const uint8_t * dcc_buffer
int arm7_9_write_memory_opt(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int arm7_9_full_context(struct target *target)
Validate the full context for an ARM7/9 target in all processor modes.
static int arm7_9_clear_halt(struct target *target)
Clears the halt condition for an ARM7/9 target.
static int arm7_9_unset_breakpoint(struct target *target, struct breakpoint *breakpoint)
Unsets an existing breakpoint on an ARM7/9 target.
static int arm7_9_clear_watchpoints(struct arm7_9_common *arm7_9)
Clear watchpoints for an ARM7/9 target.
Definition: arm7_9_common.c:60
int arm7_9_examine(struct target *target)
Perform per-target setup that requires JTAG access.
void arm7_9_disable_eice_step(struct target *target)
void arm7_9_deinit(struct target *target)
int arm7_9_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
int arm7_9_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Add a breakpoint to an ARM7/9 target.
int arm7_9_soft_reset_halt(struct target *target)
Issue a software reset and halt to an ARM7/9 target.
const struct command_registration arm7_9_command_handlers[]
static void arm7_9_assign_wp(struct arm7_9_common *arm7_9, struct breakpoint *breakpoint)
Assign a watchpoint to one of the two available hardware comparators in an ARM7 or ARM9 target.
Definition: arm7_9_common.c:81
static const struct command_registration arm7_9_any_command_handlers[]
int arm7_9_assert_reset(struct target *target)
Asserts the reset (SRST) on an ARM7/9 target.
static const uint32_t dcc_code[]
int arm7_9_poll(struct target *target)
Polls an ARM7/9 target for its current status.
int arm7_9_execute_sys_speed(struct target *target)
Restarts the target by sending a RESTART instruction and moving the JTAG state to IDLE.
static int arm7_9_dcc_completion(struct target *target, uint32_t exit_point, int timeout_ms, void *arch_info)
int arm7_9_halt(struct target *target)
Halt an ARM7/9 target.
int arm7_9_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Removes a breakpoint from an ARM7/9 target.
int arm7_9_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Remove a watchpoint from an ARM7/9 target.
static int arm7_9_setup(struct target *target)
Setup the common pieces for an ARM7/9 target after reset or on startup.
int arm7_9_deassert_reset(struct target *target)
Deassert the reset (SRST) signal on an ARM7/9 target.
int arm7_9_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int arm7_9_setup_semihosting(struct target *target, int enable)
void arm7_9_enable_eice_step(struct target *target, uint32_t next_pc)
static void arm7_9_enable_breakpoints(struct target *target)
Enable the breakpoints on an ARM7/9 target.
static int arm7_9_set_breakpoint(struct target *target, struct breakpoint *breakpoint)
Set either a hardware or software breakpoint on an ARM7/9 target.
int arm7_9_bulk_write_memory(struct target *target, target_addr_t address, uint32_t count, const uint8_t *buffer)
static int arm7_9_debug_entry(struct target *target)
Handle an ARM7/9 target's entry into debug mode.
int arm7_9_write_memory_no_opt(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int arm7_9_restart_core(struct target *target)
Restart the core of an ARM7/9 target.
int arm7_9_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
int arm7_9_target_request_data(struct target *target, uint32_t size, uint8_t *buffer)
Get some data from the ARM7/9 target.
COMMAND_HANDLER(handle_arm7_9_dbgrq_command)
int arm7_9_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Add a watchpoint to an ARM7/9 target.
int arm7_9_check_reset(struct target *target)
static int arm7_9_set_watchpoint(struct target *target, struct watchpoint *watchpoint)
Sets a watchpoint for an ARM7/9 target in one of the watchpoint units.
static int arm7_9_handle_target_request(void *priv)
Handles requests to an ARM7/9 target.
static int arm7_9_write_core_reg(struct target *target, struct reg *r, int num, enum arm_mode mode, uint8_t *value)
int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9)
int arm7_9_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
static int arm7_9_restore_context(struct target *target)
Restore the processor context on an ARM7/9 target.
#define ARM7_9_COMMON_MAGIC
Definition: arm7_9_common.h:23
static struct arm7_9_common * target_to_arm7_9(struct target *target)
static bool is_arm7_9(struct arm7_9_common *arm7_9)
#define ARM_COMMON_MAGIC
Definition: arm.h:158
arm_mode
Represent state of an ARM core.
Definition: arm.h:74
@ ARM_MODE_SYS
Definition: arm.h:84
@ ARM_MODE_ANY
Definition: arm.h:98
@ ARM_MODE_USR
Definition: arm.h:75
@ ARM_MODE_SVC
Definition: arm.h:78
@ ARM_MODE_ABT
Definition: arm.h:80
@ ARM_STATE_JAZELLE
Definition: arm.h:145
@ ARM_STATE_THUMB
Definition: arm.h:144
@ ARM_STATE_ARM
Definition: arm.h:143
bool is_arm_mode(unsigned psr_mode)
Return true iff the parameter denotes a valid ARM processor mode.
Definition: armv4_5.c:182
const struct command_registration arm_command_handlers[]
Definition: armv4_5.c:1169
const char * arm_mode_name(unsigned psr_mode)
Map PSR mode bits to the name of an ARM processor operating mode.
Definition: armv4_5.c:171
int arm_init_arch_info(struct target *target, struct arm *arm)
Definition: armv4_5.c:1705
void arm_set_cpsr(struct arm *arm, uint32_t cpsr)
Configures host-side ARM records to reflect the specified CPSR.
Definition: armv4_5.c:438
int armv4_5_run_algorithm_inner(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info, int(*run_it)(struct target *target, uint32_t exit_point, int timeout_ms, void *arch_info))
Definition: armv4_5.c:1311
struct reg * arm_reg_current(struct arm *arm, unsigned regnum)
Returns handle to the register currently mapped to a given number.
Definition: armv4_5.c:502
@ ARM_CORE_TYPE_STD
Definition: arm.h:46
int arm_jtag_setup_connection(struct arm_jtag *jtag_info)
Definition: arm_jtag.c:76
int arm_jtag_close_connection(struct arm_jtag *jtag_info)
Definition: arm_jtag.c:85
static int arm_jtag_set_instr(struct jtag_tap *tap, uint32_t new_instr, void *no_verify_capture, tap_state_t end_state)
Definition: arm_jtag.h:31
int arm_semihosting(struct target *target, int *retval)
Checks for and processes an ARM semihosting request.
int arm_simulate_step(struct target *target, uint32_t *dry_run_pc)
enum arm_mode mode
Definition: armv4_5.c:277
enum arm_mode armv4_5_number_to_mode(int number)
Map linear number indexing armv4_5_core_reg_map to PSR mode bits.
Definition: armv4_5.c:223
#define ARMV4_5_CORE_REG_MODE(cache, mode, num)
Definition: armv4_5.h:32
uint32_t flip_u32(uint32_t value, unsigned int num)
Definition: binarybuffer.c:166
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:98
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:30
static uint32_t fast_target_buffer_get_u32(const void *p, bool le)
Definition: binarybuffer.h:196
void breakpoint_remove(struct target *target, target_addr_t address)
Definition: breakpoints.c:329
int breakpoint_add(struct target *target, target_addr_t address, uint32_t length, enum breakpoint_type type)
Definition: breakpoints.c:204
struct breakpoint * breakpoint_find(struct target *target, target_addr_t address)
Definition: breakpoints.c:382
@ BKPT_HARD
Definition: breakpoints.h:18
@ BKPT_SOFT
Definition: breakpoints.h:19
static void watchpoint_set(struct watchpoint *watchpoint, unsigned int number)
Definition: breakpoints.h:79
static void breakpoint_hw_set(struct breakpoint *breakpoint, unsigned int hw_number)
Definition: breakpoints.h:63
@ WPT_ACCESS
Definition: breakpoints.h:23
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:473
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:140
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:155
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:385
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:150
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
Definition: command.h:507
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:145
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42
void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, const uint8_t *buffer, int little, int count)
This is an inner loop of the open loop DCC write of data to target.
Definition: embeddedice.c:640
void embeddedice_set_reg(struct reg *reg, uint32_t value)
Queue a write for an EmbeddedICE register, updating the register cache.
Definition: embeddedice.c:473
void embeddedice_free_reg_cache(struct reg_cache *reg_cache)
Free all memory allocated for EmbeddedICE register cache.
Definition: embeddedice.c:298
int embeddedice_setup(struct target *target)
Initialize EmbeddedICE module, if needed.
Definition: embeddedice.c:314
struct reg_cache * embeddedice_build_reg_cache(struct target *target, struct arm7_9_common *arm7_9)
Probe EmbeddedICE module and set up local records of its registers.
Definition: embeddedice.c:162
void embeddedice_write_reg(struct reg *reg, uint32_t value)
Queue a write for an EmbeddedICE register, bypassing the register cache.
Definition: embeddedice.c:501
int embeddedice_receive(struct arm_jtag *jtag_info, uint32_t *data, uint32_t size)
Receive a block of size 32-bit words from the DCC.
Definition: embeddedice.c:412
void embeddedice_store_reg(struct reg *reg)
Queue a write for an EmbeddedICE register, using cached value.
Definition: embeddedice.c:519
int embeddedice_read_reg(struct reg *reg)
Queue a read for an EmbeddedICE register into the register cache, not checking the value read.
Definition: embeddedice.c:464
int embeddedice_read_reg_w_check(struct reg *reg, uint8_t *check_value, uint8_t *check_mask)
Queue a read for an EmbeddedICE register into the register cache, optionally checking the value read.
Definition: embeddedice.c:342
@ EICE_W0_CONTROL_MASK
Definition: embeddedice.h:29
@ EICE_W1_CONTROL_VALUE
Definition: embeddedice.h:34
@ EICE_W1_DATA_VALUE
Definition: embeddedice.h:32
@ EICE_W0_CONTROL_VALUE
Definition: embeddedice.h:28
@ EICE_W0_DATA_MASK
Definition: embeddedice.h:27
@ EICE_W0_ADDR_MASK
Definition: embeddedice.h:25
@ EICE_DBG_CTRL
Definition: embeddedice.h:20
@ EICE_COMMS_DATA
Definition: embeddedice.h:23
@ EICE_W1_ADDR_VALUE
Definition: embeddedice.h:30
@ EICE_W1_ADDR_MASK
Definition: embeddedice.h:31
@ EICE_W0_ADDR_VALUE
Definition: embeddedice.h:24
@ EICE_COMMS_CTRL
Definition: embeddedice.h:22
@ EICE_W0_DATA_VALUE
Definition: embeddedice.h:26
@ EICE_W1_CONTROL_MASK
Definition: embeddedice.h:35
@ EICE_VEC_CATCH
Definition: embeddedice.h:36
@ EICE_W1_DATA_MASK
Definition: embeddedice.h:33
@ EICE_DBG_STAT
Definition: embeddedice.h:21
@ EICE_W_CTRL_NOPC
Definition: embeddedice.h:62
@ EICE_W_CTRL_ENABLE
Definition: embeddedice.h:57
@ EICE_W_CTRL_RANGE
Definition: embeddedice.h:58
@ EICE_DBG_CONTROL_DBGRQ
Definition: embeddedice.h:43
@ EICE_DBG_CONTROL_DBGACK
Definition: embeddedice.h:44
@ EICE_DBG_CONTROL_INTDIS
Definition: embeddedice.h:42
@ EICE_DBG_STATUS_SYSCOMP
Definition: embeddedice.h:50
@ EICE_DBG_STATUS_ITBIT
Definition: embeddedice.h:49
@ EICE_DBG_STATUS_DBGACK
Definition: embeddedice.h:53
int mask
Definition: esirisc.c:1698
static struct esp_usb_jtag * priv
Definition: esp_usb_jtag.c:219
struct reg_cache * etm_build_reg_cache(struct target *target, struct arm_jtag *jtag_info, struct etm_context *etm_ctx)
Definition: etm.c:278
int etm_setup(struct target *target)
Definition: etm.c:417
const struct command_registration etm_command_handlers[]
Definition: etm.c:2008
void jtag_add_reset(int req_tlr_or_trst, int req_srst)
A reset of the TAP state machine can be requested.
Definition: jtag/core.c:758
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1037
static enum reset_types jtag_reset_config
Definition: jtag/core.c:87
void jtag_add_sleep(uint32_t us)
Definition: jtag/core.c:870
void jtag_add_runtest(int num_cycles, tap_state_t state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
Definition: jtag/core.c:592
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1734
@ TAP_IDLE
Definition: jtag.h:52
reset_types
Definition: jtag.h:212
@ RESET_SRST_NO_GATING
Definition: jtag.h:221
@ RESET_HAS_SRST
Definition: jtag.h:215
@ RESET_SRST_PULLS_TRST
Definition: jtag.h:217
intptr_t jtag_callback_data_t
Defines the type of data passed to the jtag_callback_t interface.
Definition: jtag.h:333
static const struct @101 regs[]
int debug_level
Definition: log.c:34
void alive_sleep(uint64_t ms)
Definition: log.c:460
void keep_alive(void)
Definition: log.c:419
#define LOG_USER(expr ...)
Definition: log.h:126
#define LOG_WARNING(expr ...)
Definition: log.h:120
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_INFO(expr ...)
Definition: log.h:117
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
struct reg_cache ** register_get_last_cache_p(struct reg_cache **first)
Definition: register.c:72
void register_cache_invalidate(struct reg_cache *cache)
Marks the contents of the register cache as invalid (and clean).
Definition: register.c:94
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
Structure for items that are common between both ARM7 and ARM9 targets.
Definition: arm7_9_common.h:28
void(* enable_single_step)(struct target *target, uint32_t next_pc)
Definition: arm7_9_common.h:98
bool has_vector_catch
Specifies if the target has a reset vector catch.
Definition: arm7_9_common.h:53
struct arm arm
Definition: arm7_9_common.h:31
void(* read_xpsr)(struct target *target, uint32_t *xpsr, int spsr)
Function for reading CPSR or SPSR.
Definition: arm7_9_common.h:73
unsigned int common_magic
Definition: arm7_9_common.h:29
void(* store_hword_reg)(struct target *target, int num)
Definition: arm7_9_common.h:89
void(* write_xpsr_im8)(struct target *target, uint8_t xpsr_im, int rot, int spsr)
Function for writing an immediate value to CPSR or SPSR.
Definition: arm7_9_common.h:79
void(* write_core_regs)(struct target *target, uint32_t mask, uint32_t core_regs[16])
Definition: arm7_9_common.h:82
uint32_t arm_bkpt
ARM breakpoint instruction.
Definition: arm7_9_common.h:36
bool debug_entry_from_reset
Specifies if debug entry was from a reset.
Definition: arm7_9_common.h:55
bool use_dbgrq
Specifies if DBGRQ should be used to halt the target.
Definition: arm7_9_common.h:48
struct working_area * dcc_working_area
Definition: arm7_9_common.h:60
int(* bulk_write_memory)(struct target *target, target_addr_t address, uint32_t count, const uint8_t *buffer)
Write target memory in multiples of 4 bytes, optimized for writing large quantities of data.
void(* branch_resume)(struct target *target)
Definition: arm7_9_common.h:95
int sw_breakpoints_added
Specifies which watchpoint software breakpoints are setup on.
Definition: arm7_9_common.h:39
int breakpoint_count
Current number of set breakpoints.
Definition: arm7_9_common.h:41
int(* write_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Variant specific memory write function that does not dispatch to bulk_write_memory.
struct arm_jtag jtag_info
JTAG information for target.
Definition: arm7_9_common.h:33
void(* set_special_dbgrq)(struct target *target)
Function for setting DBGRQ if the normal way won't work.
void(* read_core_regs_target_buffer)(struct target *target, uint32_t mask, void *buffer, int size)
Definition: arm7_9_common.h:71
int wp1_used
Specifies if and how watchpoint unit 1 is used.
Definition: arm7_9_common.h:45
void(* store_byte_reg)(struct target *target, int num)
Definition: arm7_9_common.h:90
bool need_bypass_before_restart
Specifies if there should be a bypass before a JTAG restart.
Definition: arm7_9_common.h:49
struct reg_cache * eice_cache
Embedded ICE register cache.
Definition: arm7_9_common.h:34
int(* post_debug_entry)(struct target *target)
Callback function called after entering debug mode.
void(* load_word_regs)(struct target *target, uint32_t mask)
Definition: arm7_9_common.h:84
void(* load_byte_reg)(struct target *target, int num)
Definition: arm7_9_common.h:86
void(* read_core_regs)(struct target *target, uint32_t mask, uint32_t *core_regs[16])
Function for reading the core registers.
Definition: arm7_9_common.h:68
int wp1_used_default
Specifies if and how watchpoint unit 1 is used by default.
Definition: arm7_9_common.h:46
bool fast_memory_access
Definition: arm7_9_common.h:57
int sw_breakpoint_count
keep track of number of software breakpoints we have set
Definition: arm7_9_common.h:40
void(* load_hword_reg)(struct target *target, int num)
Definition: arm7_9_common.h:85
void(* disable_single_step)(struct target *target)
Definition: arm7_9_common.h:99
void(* write_pc)(struct target *target, uint32_t pc)
Function for writing to the program counter.
Definition: arm7_9_common.h:92
int wp0_used
Specifies if and how watchpoint unit 0 is used.
Definition: arm7_9_common.h:44
uint16_t thumb_bkpt
Thumb breakpoint instruction.
Definition: arm7_9_common.h:37
void(* store_word_regs)(struct target *target, uint32_t mask)
Definition: arm7_9_common.h:88
void(* pre_restore_context)(struct target *target)
Callback function called before restoring the processor context.
int dbgreq_adjust_pc
Amount of PC adjustment caused by a DBGREQ.
Definition: arm7_9_common.h:47
int(* examine_debug_reason)(struct target *target)
Function for determining why debug state was entered.
Definition: arm7_9_common.h:62
int wp_available_max
Maximum number of available watchpoint units.
Definition: arm7_9_common.h:43
void(* branch_resume_thumb)(struct target *target)
Definition: arm7_9_common.h:96
void(* change_to_arm)(struct target *target, uint32_t *r0, uint32_t *pc)
Function for changing from Thumb to ARM mode.
Definition: arm7_9_common.h:65
void(* write_xpsr)(struct target *target, uint32_t xpsr, int spsr)
Function for writing to CPSR or SPSR.
Definition: arm7_9_common.h:76
int wp_available
Current number of available watchpoint units.
Definition: arm7_9_common.h:42
unsigned int common_magic
Definition: arm.h:256
enum arm_mode core_mode
Definition: arm.h:258
enum arm_state core_state
Definition: arm.h:259
struct jtag_tap * tap
Definition: arm_jtag.h:18
Definition: arm.h:262
enum arm_mode mode
Definition: arm.h:264
Represents a generic ARM core, with standard application registers.
Definition: arm.h:167
int(* full_context)(struct target *target)
Retrieve all core registers, for display.
Definition: arm.h:213
void * arch_info
Definition: arm.h:233
struct etm_context * etm
Handle for the Embedded Trace Module, if one is present.
Definition: arm.h:208
enum arm_core_type core_type
Indicates what registers are in the ARM state core register set.
Definition: arm.h:185
enum arm_mode core_mode
Record the current core mode: SVC, USR, or some other mode.
Definition: arm.h:188
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
Definition: arm.h:176
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:173
int(* write_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode, uint8_t *value)
Definition: arm.h:218
int(* setup_semihosting)(struct target *target, int enable)
Definition: arm.h:199
int(* read_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode)
Retrieve a single core register.
Definition: arm.h:216
struct reg_cache * core_cache
Definition: arm.h:170
struct reg * spsr
Handle to the SPSR; valid only in core modes with an SPSR.
Definition: arm.h:179
enum arm_state core_state
Record the current core state: ARM, Thumb, or otherwise.
Definition: arm.h:191
struct breakpoint * next
Definition: breakpoints.h:34
uint8_t * orig_instr
Definition: breakpoints.h:33
enum breakpoint_type type
Definition: breakpoints.h:30
uint32_t unique_id
Definition: breakpoints.h:35
bool is_set
Definition: breakpoints.h:31
unsigned int number
Definition: breakpoints.h:32
target_addr_t address
Definition: breakpoints.h:27
const char * name
Definition: command.h:229
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
Definition: command.h:243
struct arm_jtag * jtag_info
Definition: embeddedice.h:75
Definition: jtag.h:100
struct reg * reg_list
Definition: register.h:147
struct reg_cache * next
Definition: register.h:146
uint8_t * value
Definition: algorithm.h:30
Definition: register.h:111
bool valid
Definition: register.h:126
uint32_t size
Definition: register.h:132
uint8_t * value
Definition: register.h:122
void * arch_info
Definition: register.h:140
bool dirty
Definition: register.h:124
const char * name
Definition: register.h:113
Definition: target.h:120
uint32_t working_area_size
Definition: target.h:156
enum target_debug_reason debug_reason
Definition: target.h:159
enum target_state state
Definition: target.h:162
enum target_endianness endianness
Definition: target.h:160
struct reg_cache * reg_cache
Definition: target.h:163
struct breakpoint * breakpoints
Definition: target.h:164
struct watchpoint * watchpoints
Definition: target.h:165
uint32_t dbg_msg_enabled
Definition: target.h:168
bool reset_halt
Definition: target.h:149
Definition: psoc6.c:84
enum watchpoint_rw rw
Definition: breakpoints.h:44
uint32_t mask
Definition: breakpoints.h:42
bool is_set
Definition: breakpoints.h:45
struct watchpoint * next
Definition: breakpoints.h:47
uint32_t value
Definition: breakpoints.h:43
unsigned int number
Definition: breakpoints.h:46
uint32_t length
Definition: breakpoints.h:41
target_addr_t address
Definition: breakpoints.h:40
target_addr_t address
Definition: target.h:90
int target_call_event_callbacks(struct target *target, enum target_event event)
Definition: target.c:1833
void target_free_all_working_areas(struct target *target)
Definition: target.c:2219
const char * target_state_name(struct target *t)
Return the name of this targets current state.
Definition: target.c:302
int target_halt(struct target *target)
Definition: target.c:585
bool target_has_event_action(struct target *target, enum target_event event)
Returns true only if the target has a handler for the specified event.
Definition: target.c:5287
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2728
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
Definition: target.c:1334
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
Definition: target.c:2129
bool get_target_reset_nag(void)
Definition: target.c:6764
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2707
int target_examine_one(struct target *target)
Examine the specified target, letting it perform any Initialisation that requires JTAG access.
Definition: target.c:750
int target_poll(struct target *target)
Definition: target.c:555
static int srst_asserted
Definition: target.c:2916
int target_register_timer_callback(int(*callback)(void *priv), unsigned int time_ms, enum target_timer_type type, void *priv)
The period is very approximate, the callback can happen much more often or much more rarely than spec...
Definition: target.c:1727
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
Definition: target.c:2640
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2616
uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer)
Definition: target.c:393
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
Definition: target.c:1306
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:536
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
Definition: target.c:476
void target_handle_event(struct target *target, enum target_event e)
Definition: target.c:5092
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
Definition: target.c:375
int target_wait_state(struct target *target, enum target_state state, int ms)
Definition: target.c:3270
@ DBG_REASON_NOTHALTED
Definition: target.h:78
@ DBG_REASON_DBGRQ
Definition: target.h:73
@ DBG_REASON_SINGLESTEP
Definition: target.h:77
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:792
#define ERROR_TARGET_UNALIGNED_ACCESS
Definition: target.h:794
#define ERROR_TARGET_INVALID
Definition: target.h:789
@ TARGET_TIMER_TYPE_PERIODIC
Definition: target.h:328
@ TARGET_EVENT_DEBUG_RESUMED
Definition: target.h:273
@ TARGET_EVENT_HALTED
Definition: target.h:253
@ TARGET_EVENT_RESUMED
Definition: target.h:254
@ TARGET_EVENT_DEBUG_HALTED
Definition: target.h:272
@ TARGET_EVENT_RESET_ASSERT
Definition: target.h:265
@ TARGET_RESET
Definition: target.h:56
@ TARGET_DEBUG_RUNNING
Definition: target.h:57
@ TARGET_UNKNOWN
Definition: target.h:53
@ TARGET_HALTED
Definition: target.h:55
@ TARGET_RUNNING
Definition: target.h:54
#define ERROR_TARGET_NOT_EXAMINED
Definition: target.h:799
@ TARGET_LITTLE_ENDIAN
Definition: target.h:86
static const char * target_name(struct target *target)
Returns the instance-specific name of the specified target.
Definition: target.h:234
#define ERROR_TARGET_TIMEOUT
Definition: target.h:791
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:796
static void target_set_examined(struct target *target)
Sets the examined flag for the given target.
Definition: target.h:445
static bool target_was_examined(struct target *target)
Definition: target.h:438
#define ERROR_TARGET_DATA_ABORT
Definition: target.h:795
#define ERROR_TARGET_FAILURE
Definition: target.h:793
int target_request(struct target *target, uint32_t request)
int64_t timeval_ms(void)
static void h_u32_to_be(uint8_t *buf, uint32_t val)
Definition: types.h:186
static void h_u16_to_be(uint8_t *buf, uint16_t val)
Definition: types.h:214
static uint16_t le_to_h_u16(const uint8_t *buf)
Definition: types.h:122
static void h_u32_to_le(uint8_t *buf, uint32_t val)
Definition: types.h:178
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
uint64_t target_addr_t
Definition: types.h:335
static void h_u16_to_le(uint8_t *buf, uint16_t val)
Definition: types.h:208
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112
#define TARGET_PRIxADDR
Definition: types.h:340
#define NULL
Definition: usb.h:16
uint8_t count[4]
Definition: vdebug.c:22