OpenOCD
arm11_dbgtap.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2008 digenius technology GmbH. *
5  * Michael Bruck *
6  * *
7  * Copyright (C) 2008,2009 Oyvind Harboe oyvind.harboe@zylin.com *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13 
14 #include "arm_jtag.h"
15 #include "arm11_dbgtap.h"
16 
17 #include <helper/time_support.h>
18 
19 #if 0
20 #define JTAG_DEBUG(expr ...) do { if (1) \
21  LOG_DEBUG(expr); } while (0)
22 #else
23 #define JTAG_DEBUG(expr ...) do { if (0) \
24  LOG_DEBUG(expr); } while (0)
25 #endif
26 
27 /*
28 This pathmove goes from Pause-IR to Shift-IR while avoiding RTI. The
29 behavior of the FTDI driver IIRC was to go via RTI.
30 
31 Conversely there may be other places in this code where the ARM11 code relies
32 on the driver to hit through RTI when coming from Update-?R.
33 */
36 };
37 
38 /* REVISIT no error handling here! */
39 static void arm11_add_ir_scan_vc(struct jtag_tap *tap, struct scan_field *fields,
41 {
45 
46  jtag_add_ir_scan(tap, fields, state);
47 }
48 
51 };
52 
53 /* REVISIT no error handling here! */
54 void arm11_add_dr_scan_vc(struct jtag_tap *tap, int num_fields, struct scan_field *fields,
56 {
60 
61  jtag_add_dr_scan(tap, num_fields, fields, state);
62 }
63 
64 
75 void arm11_setup_field(struct arm11_common *arm11, int num_bits,
76  void *out_data, void *in_data, struct scan_field *field)
77 {
78  field->num_bits = num_bits;
79  field->out_value = out_data;
80  field->in_value = in_data;
81 }
82 
83 static const char *arm11_ir_to_string(uint8_t ir)
84 {
85  const char *s = "unknown";
86 
87  switch (ir) {
88  case ARM11_EXTEST:
89  s = "EXTEST";
90  break;
91  case ARM11_SCAN_N:
92  s = "SCAN_N";
93  break;
94  case ARM11_RESTART:
95  s = "RESTART";
96  break;
97  case ARM11_HALT:
98  s = "HALT";
99  break;
100  case ARM11_INTEST:
101  s = "INTEST";
102  break;
103  case ARM11_ITRSEL:
104  s = "ITRSEL";
105  break;
106  case ARM11_IDCODE:
107  s = "IDCODE";
108  break;
109  case ARM11_BYPASS:
110  s = "BYPASS";
111  break;
112  }
113  return s;
114 }
115 
124 void arm11_add_ir(struct arm11_common *arm11, uint8_t instr, tap_state_t state)
125 {
126  struct jtag_tap *tap = arm11->arm.target->tap;
127 
128  if (buf_get_u32(tap->cur_instr, 0, 5) == instr) {
129  JTAG_DEBUG("IR <= 0x%02x SKIPPED", instr);
130  return;
131  }
132 
133  JTAG_DEBUG("IR <= %s (0x%02x)", arm11_ir_to_string(instr), instr);
134 
135  struct scan_field field;
136 
137  arm11_setup_field(arm11, 5, &instr, NULL, &field);
138 
140  &field,
142 }
143 
145 static void arm11_in_handler_scan_n(uint8_t *in_value)
146 {
147  /* Don't expect JTAG layer to modify bits we didn't ask it to read */
148  uint8_t v = *in_value & 0x1F;
149 
150  if (v != 0x10) {
151  LOG_ERROR("'arm11 target' JTAG error SCREG OUT 0x%02x", v);
153  }
154 }
155 
184  uint8_t chain, tap_state_t state)
185 {
186  /* Don't needlessly switch the scan chain.
187  * NOTE: the ITRSEL instruction fakes SCREG changing;
188  * but leaves its actual value unchanged.
189  */
190 #if 0
191  /* FIX!!! the optimization below is broken because we do not */
192  /* invalidate the cur_scan_chain upon a TRST/TMS. See arm_jtag.c */
193  /* for example on how to invalidate cur_scan_chain. Tested patches gladly */
194  /* accepted! */
195  if (arm11->jtag_info.cur_scan_chain == chain) {
196  JTAG_DEBUG("SCREG <= %d SKIPPED", chain);
198  ? TAP_DRPAUSE : state);
199  }
200 #endif
201  JTAG_DEBUG("SCREG <= %d", chain);
202 
204 
205  struct scan_field field;
206 
207  uint8_t tmp[1];
208  arm11_setup_field(arm11, 5, &chain, &tmp, &field);
209 
211  1,
212  &field,
214 
216 
218 
219  arm11->jtag_info.cur_scan_chain = chain;
220 
221  return jtag_execute_queue();
222 }
223 
242 static void arm11_add_debug_inst(struct arm11_common *arm11,
243  uint32_t inst, uint8_t *flag, tap_state_t state)
244 {
245  JTAG_DEBUG("INST <= 0x%08" PRIx32, inst);
246 
247  struct scan_field itr[2];
248 
249  arm11_setup_field(arm11, 32, &inst, NULL, itr + 0);
250  arm11_setup_field(arm11, 1, NULL, flag, itr + 1);
251 
252  arm11_add_dr_scan_vc(arm11->arm.target->tap, ARRAY_SIZE(itr), itr, state);
253 }
254 
265 int arm11_read_dscr(struct arm11_common *arm11)
266 {
267  int retval;
268 
269  retval = arm11_add_debug_scan_n(arm11, 0x01, ARM11_TAP_DEFAULT);
270  if (retval != ERROR_OK)
271  return retval;
272 
274 
275  uint32_t dscr;
276  struct scan_field chain1_field;
277 
278  arm11_setup_field(arm11, 32, NULL, &dscr, &chain1_field);
279 
280  arm11_add_dr_scan_vc(arm11->arm.target->tap, 1, &chain1_field, TAP_DRPAUSE);
281 
283 
284  if (arm11->dscr != dscr)
285  JTAG_DEBUG("DSCR = %08" PRIx32 " (OLD %08" PRIx32 ")", dscr, arm11->dscr);
286 
287  arm11->dscr = dscr;
288 
289  return ERROR_OK;
290 }
291 
301 int arm11_write_dscr(struct arm11_common *arm11, uint32_t dscr)
302 {
303  int retval;
304  retval = arm11_add_debug_scan_n(arm11, 0x01, ARM11_TAP_DEFAULT);
305  if (retval != ERROR_OK)
306  return retval;
307 
309 
310  struct scan_field chain1_field;
311 
312  arm11_setup_field(arm11, 32, &dscr, NULL, &chain1_field);
313 
314  arm11_add_dr_scan_vc(arm11->arm.target->tap, 1, &chain1_field, TAP_DRPAUSE);
315 
317 
318  JTAG_DEBUG("DSCR <= %08" PRIx32 " (OLD %08" PRIx32 ")", dscr, arm11->dscr);
319 
320  arm11->dscr = dscr;
321 
322  return ERROR_OK;
323 }
324 
340 {
341  return arm11_add_debug_scan_n(arm11, 0x05, ARM11_TAP_DEFAULT);
342 }
343 
359 {
360  return arm11_add_debug_scan_n(arm11, 0x00, ARM11_TAP_DEFAULT);
361 }
362 
376 static
378  uint32_t *opcode, size_t count)
379 {
381 
382  while (count--) {
383  arm11_add_debug_inst(arm11, *opcode++, NULL, TAP_IDLE);
384 
385  int i = 0;
386  while (1) {
387  uint8_t flag;
388 
390 
392 
393  if (flag)
394  break;
395 
396  int64_t then = 0;
397 
398  if (i == 1000)
399  then = timeval_ms();
400  if (i >= 1000) {
401  if ((timeval_ms()-then) > 1000) {
402  LOG_WARNING(
403  "Timeout (1000ms) waiting for instructions to complete");
404  return ERROR_FAIL;
405  }
406  }
407 
408  i++;
409  }
410  }
411 
412  return ERROR_OK;
413 }
414 
423 int arm11_run_instr_no_data1(struct arm11_common *arm11, uint32_t opcode)
424 {
425  return arm11_run_instr_no_data(arm11, &opcode, 1);
426 }
427 
428 
447  uint32_t opcode,
448  uint32_t *data,
449  size_t count)
450 {
452 
453  arm11_add_debug_inst(arm11, opcode, NULL, TAP_DRPAUSE);
454 
456 
457  struct scan_field chain5_fields[3];
458 
459  uint32_t _data;
460  uint8_t ready;
461  uint8_t n_retry;
462 
463  arm11_setup_field(arm11, 32, &_data, NULL, chain5_fields + 0);
464  arm11_setup_field(arm11, 1, NULL, &ready, chain5_fields + 1);
465  arm11_setup_field(arm11, 1, NULL, &n_retry, chain5_fields + 2);
466 
467  while (count--) {
468  int i = 0;
469  do {
470  _data = *data;
471 
473  chain5_fields), chain5_fields, TAP_IDLE);
474 
476 
477  JTAG_DEBUG("DTR ready %d n_retry %d", ready, n_retry);
478 
479  int64_t then = 0;
480 
481  if (i == 1000)
482  then = timeval_ms();
483  if (i >= 1000) {
484  if ((timeval_ms()-then) > 1000) {
485  LOG_WARNING(
486  "Timeout (1000ms) waiting for instructions to complete");
487  return ERROR_FAIL;
488  }
489  }
490 
491  i++;
492  } while (!ready);
493 
494  data++;
495  }
496 
498 
499  int i = 0;
500  do {
501  _data = 0;
502 
504  chain5_fields), chain5_fields, TAP_DRPAUSE);
505 
507 
508  JTAG_DEBUG("DTR _data %08" PRIx32 " ready %d n_retry %d",
509  _data, ready, n_retry);
510 
511  int64_t then = 0;
512 
513  if (i == 1000)
514  then = timeval_ms();
515  if (i >= 1000) {
516  if ((timeval_ms()-then) > 1000) {
517  LOG_WARNING("Timeout (1000ms) waiting for instructions to complete");
518  return ERROR_FAIL;
519  }
520  }
521 
522  i++;
523  } while (!ready);
524 
525  return ERROR_OK;
526 }
527 
548 };
549 
551  uint32_t opcode,
552  uint32_t *data,
553  size_t count)
554 {
555  struct scan_field chain5_fields[3];
556 
557  chain5_fields[0].num_bits = 32;
558  chain5_fields[0].out_value = NULL; /*&Data*/
559  chain5_fields[0].in_value = NULL;
560 
561  chain5_fields[1].num_bits = 1;
562  chain5_fields[1].out_value = NULL;
563  chain5_fields[1].in_value = NULL; /*&Ready*/
564 
565  chain5_fields[2].num_bits = 1;
566  chain5_fields[2].out_value = NULL;
567  chain5_fields[2].in_value = NULL;
568 
569  uint8_t *readies;
570  unsigned int readies_num = count;
571  unsigned int bytes = sizeof(*readies) * readies_num;
572 
573  readies = malloc(bytes);
574  if (!readies) {
575  LOG_ERROR("Out of memory allocating %u bytes", bytes);
576  return ERROR_FAIL;
577  }
578 
579  uint8_t *ready_pos = readies;
580  while (count--) {
581  chain5_fields[0].out_value = (uint8_t *)(data++);
582  chain5_fields[1].in_value = ready_pos++;
583 
584  if (count > 0) {
585  jtag_add_dr_scan(tap, ARRAY_SIZE(chain5_fields), chain5_fields,
586  TAP_DRPAUSE);
589  } else
590  jtag_add_dr_scan(tap, ARRAY_SIZE(chain5_fields), chain5_fields, TAP_IDLE);
591  }
592 
593  int retval = jtag_execute_queue();
594  if (retval == ERROR_OK) {
595  unsigned int error_count = 0;
596 
597  for (size_t i = 0; i < readies_num; i++) {
598  if (readies[i] != 1)
599  error_count++;
600  }
601 
602  if (error_count > 0) {
603  LOG_ERROR("%u words out of %u not transferred",
604  error_count, readies_num);
605  retval = ERROR_FAIL;
606  }
607  }
608  free(readies);
609 
610  return retval;
611 }
612 
633  uint32_t opcode,
634  uint32_t *data,
635  size_t count)
636 {
638 
639  arm11_add_debug_inst(arm11, opcode, NULL, TAP_DRPAUSE);
640 
642 
644  opcode,
645  data,
646  count);
647 
648  if (retval != ERROR_OK)
649  return retval;
650 
652 
653  struct scan_field chain5_fields[3];
654 
655  arm11_setup_field(arm11,
656  32,
657  NULL /*&Data*/,
658  NULL,
659  chain5_fields + 0);
660  arm11_setup_field(arm11,
661  1,
662  NULL,
663  NULL /*&Ready*/,
664  chain5_fields + 1);
665  arm11_setup_field(arm11,
666  1,
667  NULL,
668  NULL,
669  chain5_fields + 2);
670 
671  uint8_t ready_flag;
672  chain5_fields[1].in_value = &ready_flag;
673 
675  chain5_fields), chain5_fields, TAP_DRPAUSE);
676 
677  retval = jtag_execute_queue();
678  if (retval == ERROR_OK) {
679  if (ready_flag != 1) {
680  LOG_ERROR("last word not transferred");
681  retval = ERROR_FAIL;
682  }
683  }
684 
685  return retval;
686 }
687 
688 
700 int arm11_run_instr_data_to_core1(struct arm11_common *arm11, uint32_t opcode, uint32_t data)
701 {
702  return arm11_run_instr_data_to_core(arm11, opcode, &data, 1);
703 }
704 
705 
724  uint32_t opcode,
725  uint32_t *data,
726  size_t count)
727 {
729 
730  arm11_add_debug_inst(arm11, opcode, NULL, TAP_IDLE);
731 
733 
734  struct scan_field chain5_fields[3];
735 
736  uint32_t _data;
737  uint8_t ready;
738  uint8_t n_retry;
739 
740  arm11_setup_field(arm11, 32, NULL, &_data, chain5_fields + 0);
741  arm11_setup_field(arm11, 1, NULL, &ready, chain5_fields + 1);
742  arm11_setup_field(arm11, 1, NULL, &n_retry, chain5_fields + 2);
743 
744  while (count--) {
745  int i = 0;
746  do {
748  chain5_fields), chain5_fields,
750 
752 
753  JTAG_DEBUG("DTR _data %08" PRIx32 " ready %d n_retry %d",
754  _data, ready, n_retry);
755 
756  int64_t then = 0;
757 
758  if (i == 1000)
759  then = timeval_ms();
760  if (i >= 1000) {
761  if ((timeval_ms()-then) > 1000) {
762  LOG_WARNING(
763  "Timeout (1000ms) waiting for instructions to complete");
764  return ERROR_FAIL;
765  }
766  }
767 
768  i++;
769  } while (!ready);
770 
771  *data++ = _data;
772  }
773 
774  return ERROR_OK;
775 }
776 
790  uint32_t opcode,
791  uint32_t *data)
792 {
793  int retval;
794  retval = arm11_run_instr_no_data1(arm11, opcode);
795  if (retval != ERROR_OK)
796  return retval;
797 
798  /* MCR p14,0,R0,c0,c5,0 (move r0 -> wDTR -> local var) */
799  arm11_run_instr_data_from_core(arm11, 0xEE000E15, data, 1);
800 
801  return ERROR_OK;
802 }
803 
816 int arm11_run_instr_data_to_core_via_r0(struct arm11_common *arm11, uint32_t opcode, uint32_t data)
817 {
818  int retval;
819  /* MRC p14,0,r0,c0,c5,0 */
820  retval = arm11_run_instr_data_to_core1(arm11, 0xEE100E15, data);
821  if (retval != ERROR_OK)
822  return retval;
823 
824  retval = arm11_run_instr_no_data1(arm11, opcode);
825  if (retval != ERROR_OK)
826  return retval;
827 
828  return ERROR_OK;
829 }
830 
840 int arm11_sc7_run(struct arm11_common *arm11, struct arm11_sc7_action *actions, size_t count)
841 {
842  int retval;
843 
844  retval = arm11_add_debug_scan_n(arm11, 0x07, ARM11_TAP_DEFAULT);
845  if (retval != ERROR_OK)
846  return retval;
847 
849 
850  struct scan_field chain7_fields[3];
851 
852  uint8_t n_rw;
853  uint32_t data_out;
854  uint8_t address_out;
855  uint8_t ready;
856  uint32_t data_in;
857  uint8_t address_in;
858 
859  arm11_setup_field(arm11, 1, &n_rw, &ready, chain7_fields + 0);
860  arm11_setup_field(arm11, 32, &data_out, &data_in, chain7_fields + 1);
861  arm11_setup_field(arm11, 7, &address_out, &address_in, chain7_fields + 2);
862 
863  for (size_t i = 0; i < count + 1; i++) {
864  if (i < count) {
865  n_rw = actions[i].write ? 1 : 0;
866  data_out = actions[i].value;
867  address_out = actions[i].address;
868  } else {
869  n_rw = 1;
870  data_out = 0;
871  address_out = 0;
872  }
873 
874  /* Timeout here so we don't get stuck. */
875  int i_n = 0;
876  while (1) {
877  JTAG_DEBUG("SC7 <= c%-3" PRIu8 " Data %08" PRIx32 " %s",
878  address_out, data_out,
879  n_rw ? "write" : "read");
880 
881  arm11_add_dr_scan_vc(arm11->arm.target->tap, ARRAY_SIZE(chain7_fields),
882  chain7_fields, TAP_DRPAUSE);
883 
885 
886  /* 'n_rw' is 'ready' on read out */
887  if (ready)
888  break;
889 
890  int64_t then = 0;
891 
892  if (i_n == 1000)
893  then = timeval_ms();
894  if (i_n >= 1000) {
895  if ((timeval_ms()-then) > 1000) {
896  LOG_WARNING(
897  "Timeout (1000ms) waiting for instructions to complete");
898  return ERROR_FAIL;
899  }
900  }
901 
902  i_n++;
903  }
904 
905  if (!n_rw)
906  JTAG_DEBUG("SC7 => Data %08" PRIx32, data_in);
907 
908  if (i > 0) {
909  if (actions[i - 1].address != address_in)
910  LOG_WARNING("Scan chain 7 shifted out unexpected address");
911 
912  if (!actions[i - 1].write)
913  actions[i - 1].value = data_in;
914  else {
915  if (actions[i - 1].value != data_in)
916  LOG_WARNING("Scan chain 7 shifted out unexpected data");
917  }
918  }
919  }
920  return ERROR_OK;
921 }
922 
929 {
930  size_t clear_bw_size = arm11->brp + 1;
931  struct arm11_sc7_action *clear_bw = malloc(sizeof(struct arm11_sc7_action) * clear_bw_size);
932  struct arm11_sc7_action *pos = clear_bw;
933 
934  for (size_t i = 0; i < clear_bw_size; i++) {
935  clear_bw[i].write = true;
936  clear_bw[i].value = 0;
937  }
938 
939  for (size_t i = 0; i < arm11->brp; i++)
940  (pos++)->address = ARM11_SC7_BCR0 + i;
941 
942  (pos++)->address = ARM11_SC7_VCR;
943 
944  int retval;
945  retval = arm11_sc7_run(arm11, clear_bw, clear_bw_size);
946 
947  free(clear_bw);
948 
949  return retval;
950 }
951 
957 int arm11_sc7_set_vcr(struct arm11_common *arm11, uint32_t value)
958 {
959  struct arm11_sc7_action set_vcr;
960 
961  set_vcr.write = true;
962  set_vcr.address = ARM11_SC7_VCR;
963  set_vcr.value = value;
964 
965  return arm11_sc7_run(arm11, &set_vcr, 1);
966 }
967 
975 int arm11_read_memory_word(struct arm11_common *arm11, uint32_t address, uint32_t *result)
976 {
977  int retval;
978  retval = arm11_run_instr_data_prepare(arm11);
979  if (retval != ERROR_OK)
980  return retval;
981 
982  /* MRC p14,0,r0,c0,c5,0 (r0 = address) */
984 
985  /* LDC p14,c5,[R0],#4 (DTR = [r0]) */
986  CHECK_RETVAL(arm11_run_instr_data_from_core(arm11, 0xecb05e01, result, 1));
987 
988  return arm11_run_instr_data_finish(arm11);
989 }
990 
991 /************************************************************************/
992 
993 /*
994  * ARM11 provider for the OpenOCD implementation of the standard
995  * architectural ARM v6/v7 "Debug Programmer's Model" (DPM).
996  */
997 
998 static inline struct arm11_common *dpm_to_arm11(struct arm_dpm *dpm)
999 {
1000  return container_of(dpm, struct arm11_common, dpm);
1001 }
1002 
1003 static int arm11_dpm_prepare(struct arm_dpm *dpm)
1004 {
1006 }
1007 
1008 static int arm11_dpm_finish(struct arm_dpm *dpm)
1009 {
1011 }
1012 
1014  uint32_t opcode, uint32_t data)
1015 {
1017  opcode, &data, 1);
1018 }
1019 
1021  uint32_t opcode, uint32_t data)
1022 {
1024  opcode, data);
1025 }
1026 
1028  uint32_t opcode, uint32_t *data)
1029 {
1031  opcode, data, 1);
1032 }
1033 
1035  uint32_t opcode, uint32_t *data)
1036 {
1038  opcode, data);
1039 }
1040 
1041 /* Because arm11_sc7_run() takes a vector of actions, we batch breakpoint
1042  * and watchpoint operations instead of running them right away. Since we
1043  * pre-allocated our vector, we don't need to worry about space.
1044  */
1045 static int arm11_bpwp_enable(struct arm_dpm *dpm, unsigned int index_t,
1046  uint32_t addr, uint32_t control)
1047 {
1048  struct arm11_common *arm11 = dpm_to_arm11(dpm);
1049  struct arm11_sc7_action *action;
1050 
1051  action = arm11->bpwp_actions + arm11->bpwp_n;
1052 
1053  /* Invariant: this bp/wp is disabled.
1054  * It also happens that the core is halted here, but for
1055  * DPM-based cores we don't actually care about that.
1056  */
1057 
1058  action[0].write = action[1].write = true;
1059 
1060  action[0].value = addr;
1061  action[1].value = control;
1062 
1063  switch (index_t) {
1064  case 0 ... 15:
1065  action[0].address = ARM11_SC7_BVR0 + index_t;
1066  action[1].address = ARM11_SC7_BCR0 + index_t;
1067  break;
1068  case 16 ... 32:
1069  index_t -= 16;
1070  action[0].address = ARM11_SC7_WVR0 + index_t;
1071  action[1].address = ARM11_SC7_WCR0 + index_t;
1072  break;
1073  default:
1074  return ERROR_FAIL;
1075  }
1076 
1077  arm11->bpwp_n += 2;
1078 
1079  return ERROR_OK;
1080 }
1081 
1082 static int arm11_bpwp_disable(struct arm_dpm *dpm, unsigned int index_t)
1083 {
1084  struct arm11_common *arm11 = dpm_to_arm11(dpm);
1085  struct arm11_sc7_action *action;
1086 
1087  action = arm11->bpwp_actions + arm11->bpwp_n;
1088 
1089  action[0].write = true;
1090  action[0].value = 0;
1091 
1092  switch (index_t) {
1093  case 0 ... 15:
1094  action[0].address = ARM11_SC7_BCR0 + index_t;
1095  break;
1096  case 16 ... 32:
1097  index_t -= 16;
1098  action[0].address = ARM11_SC7_WCR0 + index_t;
1099  break;
1100  default:
1101  return ERROR_FAIL;
1102  }
1103 
1104  arm11->bpwp_n += 1;
1105 
1106  return ERROR_OK;
1107 }
1108 
1110 int arm11_bpwp_flush(struct arm11_common *arm11)
1111 {
1112  int retval;
1113 
1114  if (!arm11->bpwp_n)
1115  return ERROR_OK;
1116 
1117  retval = arm11_sc7_run(arm11, arm11->bpwp_actions, arm11->bpwp_n);
1118  arm11->bpwp_n = 0;
1119 
1120  return retval;
1121 }
1122 
1124 int arm11_dpm_init(struct arm11_common *arm11, uint32_t didr)
1125 {
1126  struct arm_dpm *dpm = &arm11->dpm;
1127  int retval;
1128 
1129  dpm->arm = &arm11->arm;
1130 
1131  dpm->didr = didr;
1132 
1133  dpm->prepare = arm11_dpm_prepare;
1134  dpm->finish = arm11_dpm_finish;
1135 
1138 
1141 
1144 
1145  retval = arm_dpm_setup(dpm);
1146  if (retval != ERROR_OK)
1147  return retval;
1148 
1149  /* alloc enough to enable all breakpoints and watchpoints at once */
1150  arm11->bpwp_actions = calloc(2 * (dpm->nbp + dpm->nwp),
1151  sizeof(*arm11->bpwp_actions));
1152  if (!arm11->bpwp_actions)
1153  return ERROR_FAIL;
1154 
1155  retval = arm_dpm_initialize(dpm);
1156  if (retval != ERROR_OK)
1157  return retval;
1158 
1159  return arm11_bpwp_flush(arm11);
1160 }
1161 
1162 void arm11_dpm_deinit(struct arm11_common *arm11)
1163 {
1164  struct arm_dpm *dpm = &arm11->dpm;
1165 
1166  free(arm11->bpwp_actions);
1167  arm_free_reg_cache(dpm->arm);
1168  free(dpm->dbp);
1169  free(dpm->dwp);
1170 }
#define CHECK_RETVAL(action)
Definition: arc.h:246
#define ARM11_TAP_DEFAULT
Definition: arm11.h:16
@ ARM11_SC7_WCR0
Definition: arm11.h:100
@ ARM11_SC7_BVR0
Definition: arm11.h:97
@ ARM11_SC7_WVR0
Definition: arm11.h:99
@ ARM11_SC7_BCR0
Definition: arm11.h:98
@ ARM11_SC7_VCR
Definition: arm11.h:95
@ ARM11_RESTART
Definition: arm11.h:85
@ ARM11_SCAN_N
Definition: arm11.h:84
@ ARM11_INTEST
Definition: arm11.h:87
@ ARM11_ITRSEL
Definition: arm11.h:88
@ ARM11_BYPASS
Definition: arm11.h:90
@ ARM11_IDCODE
Definition: arm11.h:89
@ ARM11_EXTEST
Definition: arm11.h:83
@ ARM11_HALT
Definition: arm11.h:86
int arm11_run_instr_data_to_core1(struct arm11_common *arm11, uint32_t opcode, uint32_t data)
Execute an instruction via ITR while handing data into the core via DTR.
Definition: arm11_dbgtap.c:700
int arm11_run_instr_data_to_core_noack(struct arm11_common *arm11, uint32_t opcode, uint32_t *data, size_t count)
Execute one instruction via ITR repeatedly while passing data to the core via DTR on each execution.
Definition: arm11_dbgtap.c:632
int arm11_run_instr_data_to_core_via_r0(struct arm11_common *arm11, uint32_t opcode, uint32_t data)
Load data into core via DTR then move it to r0 then execute one instruction via ITR.
Definition: arm11_dbgtap.c:816
void arm11_add_dr_scan_vc(struct jtag_tap *tap, int num_fields, struct scan_field *fields, tap_state_t state)
Definition: arm11_dbgtap.c:54
int arm11_bpwp_flush(struct arm11_common *arm11)
Flush any pending breakpoint and watchpoint updates.
static const char * arm11_ir_to_string(uint8_t ir)
Definition: arm11_dbgtap.c:83
int arm11_read_memory_word(struct arm11_common *arm11, uint32_t address, uint32_t *result)
Read word from address.
Definition: arm11_dbgtap.c:975
int arm11_read_dscr(struct arm11_common *arm11)
Read and save the Debug Status and Control Register (DSCR).
Definition: arm11_dbgtap.c:265
static int arm11_bpwp_enable(struct arm_dpm *dpm, unsigned int index_t, uint32_t addr, uint32_t control)
static int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, uint32_t opcode, uint32_t *data, size_t count)
Definition: arm11_dbgtap.c:550
int arm11_write_dscr(struct arm11_common *arm11, uint32_t dscr)
Write the Debug Status and Control Register (DSCR)
Definition: arm11_dbgtap.c:301
static void arm11_add_ir_scan_vc(struct jtag_tap *tap, struct scan_field *fields, tap_state_t state)
Definition: arm11_dbgtap.c:39
int arm11_run_instr_data_from_core(struct arm11_common *arm11, uint32_t opcode, uint32_t *data, size_t count)
Execute one instruction via ITR repeatedly while reading data from the core via DTR on each execution...
Definition: arm11_dbgtap.c:723
static void arm11_add_debug_inst(struct arm11_common *arm11, uint32_t inst, uint8_t *flag, tap_state_t state)
Queue a DR scan of the ITR register.
Definition: arm11_dbgtap.c:242
int arm11_sc7_clear_vbw(struct arm11_common *arm11)
Clear VCR and all breakpoints and watchpoints via scan chain 7.
Definition: arm11_dbgtap.c:928
static const tap_state_t arm11_move_pi_to_si_via_ci[]
Definition: arm11_dbgtap.c:34
int arm11_dpm_init(struct arm11_common *arm11, uint32_t didr)
Set up high-level debug module utilities.
void arm11_add_ir(struct arm11_common *arm11, uint8_t instr, tap_state_t state)
Write JTAG instruction register.
Definition: arm11_dbgtap.c:124
static int arm11_dpm_instr_write_data_r0(struct arm_dpm *dpm, uint32_t opcode, uint32_t data)
void arm11_setup_field(struct arm11_common *arm11, int num_bits, void *out_data, void *in_data, struct scan_field *field)
Code de-clutter: Construct struct scan_field to write out a value.
Definition: arm11_dbgtap.c:75
static struct arm11_common * dpm_to_arm11(struct arm_dpm *dpm)
Definition: arm11_dbgtap.c:998
int arm11_run_instr_data_finish(struct arm11_common *arm11)
Cleanup after ITR/DTR operations from the arm11_run_instr...
Definition: arm11_dbgtap.c:358
static int arm11_dpm_instr_write_data_dcc(struct arm_dpm *dpm, uint32_t opcode, uint32_t data)
int arm11_run_instr_data_prepare(struct arm11_common *arm11)
Prepare the stage for ITR/DTR operations from the arm11_run_instr...
Definition: arm11_dbgtap.c:339
#define JTAG_DEBUG(expr ...)
Definition: arm11_dbgtap.c:23
int arm11_run_instr_data_from_core_via_r0(struct arm11_common *arm11, uint32_t opcode, uint32_t *data)
Execute one instruction via ITR then load r0 into DTR and read DTR from core.
Definition: arm11_dbgtap.c:789
static int arm11_dpm_finish(struct arm_dpm *dpm)
int arm11_sc7_set_vcr(struct arm11_common *arm11, uint32_t value)
Write VCR register.
Definition: arm11_dbgtap.c:957
static void arm11_in_handler_scan_n(uint8_t *in_value)
Verify data shifted out from Scan Chain Register (SCREG).
Definition: arm11_dbgtap.c:145
static int arm11_dpm_instr_read_data_dcc(struct arm_dpm *dpm, uint32_t opcode, uint32_t *data)
static const tap_state_t arm11_move_pd_to_sd_via_cd[]
Definition: arm11_dbgtap.c:49
static const tap_state_t arm11_move_drpause_idle_drpause_with_delay[]
JTAG path for arm11_run_instr_data_to_core_noack.
Definition: arm11_dbgtap.c:545
static int arm11_bpwp_disable(struct arm_dpm *dpm, unsigned int index_t)
void arm11_dpm_deinit(struct arm11_common *arm11)
int arm11_run_instr_data_to_core(struct arm11_common *arm11, uint32_t opcode, uint32_t *data, size_t count)
Execute one instruction via ITR repeatedly while passing data to the core via DTR on each execution.
Definition: arm11_dbgtap.c:446
static int arm11_dpm_instr_read_data_r0(struct arm_dpm *dpm, uint32_t opcode, uint32_t *data)
static int arm11_dpm_prepare(struct arm_dpm *dpm)
int arm11_run_instr_no_data1(struct arm11_common *arm11, uint32_t opcode)
Execute one instruction via ITR.
Definition: arm11_dbgtap.c:423
int arm11_add_debug_scan_n(struct arm11_common *arm11, uint8_t chain, tap_state_t state)
Select and write to Scan Chain Register (SCREG)
Definition: arm11_dbgtap.c:183
int arm11_sc7_run(struct arm11_common *arm11, struct arm11_sc7_action *actions, size_t count)
Apply reads and writes to scan chain 7.
Definition: arm11_dbgtap.c:840
static int arm11_run_instr_no_data(struct arm11_common *arm11, uint32_t *opcode, size_t count)
Execute one or more instructions via ITR.
Definition: arm11_dbgtap.c:377
void arm_free_reg_cache(struct arm *arm)
Definition: armv4_5.c:761
int arm_dpm_setup(struct arm_dpm *dpm)
Hooks up this DPM to its associated target; call only once.
Definition: arm_dpm.c:1093
int arm_dpm_initialize(struct arm_dpm *dpm)
Reinitializes DPM state at the beginning of a new debug session or after a reset which may have affec...
Definition: arm_dpm.c:1160
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
void jtag_set_error(int error)
Set the current JTAG core execution error, unless one was set by a previous call previously.
Definition: jtag/core.c:123
void jtag_execute_queue_noclear(void)
same as jtag_execute_queue() but does not clear the error flag
Definition: jtag/core.c:1018
void jtag_add_pathmove(unsigned int num_states, const tap_state_t *path)
Application code must assume that interfaces will implement transitions between states with different...
Definition: jtag/core.c:517
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
tap_state_t cmd_queue_cur_state
The current TAP state of the pending JTAG command queue.
Definition: jtag/core.c:88
int jtag_add_statemove(tap_state_t goal_state)
jtag_add_statemove() moves from the current state to goal_state.
Definition: jtag/core.c:551
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap_state_t state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
Definition: jtag/core.c:374
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
Definition: jtag/core.c:451
@ TAP_IRCAPTURE
Definition: jtag.h:55
@ TAP_DRCAPTURE
Definition: jtag.h:47
@ TAP_DRSELECT
Definition: jtag.h:48
@ TAP_DRPAUSE
Definition: jtag.h:44
@ TAP_IRSELECT
Definition: jtag.h:45
@ TAP_IRUPDATE
Definition: jtag.h:54
@ TAP_IREXIT2
Definition: jtag.h:49
@ TAP_IRSHIFT
Definition: jtag.h:51
@ TAP_DREXIT2
Definition: jtag.h:41
@ TAP_IDLE
Definition: jtag.h:53
@ TAP_DRSHIFT
Definition: jtag.h:43
@ TAP_IRPAUSE
Definition: jtag.h:52
@ TAP_DRUPDATE
Definition: jtag.h:46
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_WARNING(expr ...)
Definition: log.h:129
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define ERROR_OK
Definition: log.h:164
int flag
Definition: mips64.c:29
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
unsigned int bpwp_n
Definition: arm11.h:42
struct arm11_sc7_action * bpwp_actions
Definition: arm11.h:41
size_t brp
Number of Breakpoint Register Pairs from DIDR
Definition: arm11.h:44
struct arm_dpm dpm
Debug module state.
Definition: arm11.h:40
struct arm arm
Definition: arm11.h:37
uint32_t dscr
Last retrieved DSCR value.
Definition: arm11.h:47
struct arm_jtag jtag_info
Definition: arm11.h:69
Used with arm11_sc7_run to make a list of read/write commands for scan chain 7.
Definition: arm11_dbgtap.h:49
uint8_t address
Register address mode.
Definition: arm11_dbgtap.h:51
uint32_t value
If write then set this to value to be written.
Definition: arm11_dbgtap.h:56
bool write
Access mode: true for write, false for read.
Definition: arm11_dbgtap.h:50
This wraps an implementation of DPM primitives.
Definition: arm_dpm.h:47
int(* instr_read_data_dcc)(struct arm_dpm *dpm, uint32_t opcode, uint32_t *data)
Runs one instruction, reading data from dcc after execution.
Definition: arm_dpm.h:91
uint64_t didr
Cache of DIDR.
Definition: arm_dpm.h:51
int(* instr_write_data_r0)(struct arm_dpm *dpm, uint32_t opcode, uint32_t data)
Runs one instruction, writing data to R0 before execution.
Definition: arm_dpm.h:72
struct arm * arm
Definition: arm_dpm.h:48
int(* bpwp_enable)(struct arm_dpm *dpm, unsigned int index_value, uint32_t addr, uint32_t control)
Enables one breakpoint or watchpoint by writing to the hardware registers.
Definition: arm_dpm.h:122
int(* finish)(struct arm_dpm *dpm)
Invoke after a series of instruction operations.
Definition: arm_dpm.h:57
struct dpm_bp * dbp
Definition: arm_dpm.h:139
int(* instr_write_data_dcc)(struct arm_dpm *dpm, uint32_t opcode, uint32_t data)
Runs one instruction, writing data to DCC before execution.
Definition: arm_dpm.h:65
unsigned int nwp
Definition: arm_dpm.h:138
int(* prepare)(struct arm_dpm *dpm)
Invoke before a series of instruction operations.
Definition: arm_dpm.h:54
int(* instr_read_data_r0)(struct arm_dpm *dpm, uint32_t opcode, uint32_t *data)
Runs one instruction, reading data from r0 after execution.
Definition: arm_dpm.h:98
unsigned int nbp
Definition: arm_dpm.h:137
struct dpm_wp * dwp
Definition: arm_dpm.h:140
int(* bpwp_disable)(struct arm_dpm *dpm, unsigned int index_value)
Disables one breakpoint or watchpoint by clearing its hardware control registers.
Definition: arm_dpm.h:130
uint32_t cur_scan_chain
Definition: arm_jtag.h:22
struct target * target
Backpointer to the target.
Definition: arm.h:210
Definition: jtag.h:101
uint8_t * cur_instr
current instruction
Definition: jtag.h:132
This structure defines a single scan field in the scan.
Definition: jtag.h:87
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:93
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:91
unsigned int num_bits
The number of bits this field specifies.
Definition: jtag.h:89
struct jtag_tap * tap
Definition: target.h:119
int64_t timeval_ms(void)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define container_of(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: types.h:68
#define NULL
Definition: usb.h:16
uint8_t state[4]
Definition: vdebug.c:21
uint8_t count[4]
Definition: vdebug.c:22