OpenOCD
arm11.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  * Copyright (C) 2008 Georg Acher <acher@in.tum.de> *
10  * *
11  * Copyright (C) 2009 David Brownell *
12  ***************************************************************************/
13 
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include "etm.h"
19 #include "breakpoints.h"
20 #include "arm11_dbgtap.h"
21 #include "arm_simulator.h"
22 #include <helper/time_support.h>
23 #include "target_type.h"
24 #include "algorithm.h"
25 #include "register.h"
26 #include "arm_opcodes.h"
27 
28 #if 0
29 #define _DEBUG_INSTRUCTION_EXECUTION_
30 #endif
31 
32 
33 static int arm11_step(struct target *target, int current,
34  target_addr_t address, int handle_breakpoints);
35 
36 
41 static int arm11_check_init(struct arm11_common *arm11)
42 {
44 
45  if (!(arm11->dscr & DSCR_HALT_DBG_MODE)) {
46  LOG_DEBUG("DSCR %08" PRIx32, arm11->dscr);
47  LOG_DEBUG("Bringing target into debug mode");
48 
49  arm11->dscr |= DSCR_HALT_DBG_MODE;
50  CHECK_RETVAL(arm11_write_dscr(arm11, arm11->dscr));
51 
52  /* add further reset initialization here */
53 
54  arm11->simulate_reset_on_next_halt = true;
55 
56  if (arm11->dscr & DSCR_CORE_HALTED) {
63  arm11->arm.target->state = TARGET_HALTED;
64  arm_dpm_report_dscr(arm11->arm.dpm, arm11->dscr);
65  } else {
66  arm11->arm.target->state = TARGET_RUNNING;
68  }
69 
71  }
72 
73  return ERROR_OK;
74 }
75 
81 static int arm11_debug_entry(struct arm11_common *arm11)
82 {
83  int retval;
84 
85  arm11->arm.target->state = TARGET_HALTED;
86  arm_dpm_report_dscr(arm11->arm.dpm, arm11->dscr);
87 
88  /* REVISIT entire cache should already be invalid !!! */
90 
91  /* See e.g. ARM1136 TRM, "14.8.4 Entering Debug state" */
92 
93  /* maybe save wDTR (pending DCC write to debug SW, e.g. libdcc) */
94  arm11->is_wdtr_saved = !!(arm11->dscr & DSCR_DTR_TX_FULL);
95  if (arm11->is_wdtr_saved) {
97 
99 
100  struct scan_field chain5_fields[3];
101 
102  arm11_setup_field(arm11, 32, NULL,
103  &arm11->saved_wdtr, chain5_fields + 0);
104  arm11_setup_field(arm11, 1, NULL, NULL, chain5_fields + 1);
105  arm11_setup_field(arm11, 1, NULL, NULL, chain5_fields + 2);
106 
108  chain5_fields), chain5_fields, TAP_DRPAUSE);
109 
110  }
111 
112  /* DSCR: set the Execute ARM instruction enable bit.
113  *
114  * ARM1176 spec says this is needed only for wDTR/rDTR's "ITR mode",
115  * but not to issue ITRs(?). The ARMv7 arch spec says it's required
116  * for executing instructions via ITR.
117  */
118  CHECK_RETVAL(arm11_write_dscr(arm11, DSCR_ITR_EN | arm11->dscr));
119 
120 
121  /* From the spec:
122  Before executing any instruction in debug state you have to drain the write buffer.
123  This ensures that no imprecise Data Aborts can return at a later point:*/
124 
127 #if 0
128  while (1) {
129  /* MRC p14,0,R0,c5,c10,0 */
130  /* arm11_run_instr_no_data1(arm11, / *0xee150e1a* /0xe320f000); */
131 
132  /* mcr 15, 0, r0, cr7, cr10, {4} */
133  arm11_run_instr_no_data1(arm11, 0xee070f9a);
134 
135  uint32_t dscr = arm11_read_dscr(arm11);
136 
137  LOG_DEBUG("DRAIN, DSCR %08x", dscr);
138 
139  if (dscr & ARM11_DSCR_STICKY_IMPRECISE_DATA_ABORT) {
140  arm11_run_instr_no_data1(arm11, 0xe320f000);
141 
142  dscr = arm11_read_dscr(arm11);
143 
144  LOG_DEBUG("DRAIN, DSCR %08x (DONE)", dscr);
145 
146  break;
147  }
148  }
149 #endif
150 
151  /* Save registers.
152  *
153  * NOTE: ARM1136 TRM suggests saving just R0 here now, then
154  * CPSR and PC after the rDTR stuff. We do it all at once.
155  */
156  retval = arm_dpm_read_current_registers(&arm11->dpm);
157  if (retval != ERROR_OK)
158  LOG_ERROR("DPM REG READ -- fail");
159 
160  retval = arm11_run_instr_data_prepare(arm11);
161  if (retval != ERROR_OK)
162  return retval;
163 
164  /* maybe save rDTR (pending DCC read from debug SW, e.g. libdcc) */
165  arm11->is_rdtr_saved = !!(arm11->dscr & DSCR_DTR_RX_FULL);
166  if (arm11->is_rdtr_saved) {
167  /* MRC p14,0,R0,c0,c5,0 (move rDTR -> r0 (-> wDTR -> local var)) */
169  0xEE100E15, &arm11->saved_rdtr);
170  if (retval != ERROR_OK)
171  return retval;
172  }
173 
174  /* REVISIT Now that we've saved core state, there's may also
175  * be MMU and cache state to care about ...
176  */
177 
178  if (arm11->simulate_reset_on_next_halt) {
179  arm11->simulate_reset_on_next_halt = false;
180 
181  LOG_DEBUG("Reset c1 Control Register");
182 
183  /* Write 0 (reset value) to Control register 0 to disable MMU/Cache etc. */
184 
185  /* MCR p15,0,R0,c1,c0,0 */
186  retval = arm11_run_instr_data_to_core_via_r0(arm11, 0xee010f10, 0);
187  if (retval != ERROR_OK)
188  return retval;
189 
190  }
191 
192  if (arm11->arm.target->debug_reason == DBG_REASON_WATCHPOINT) {
193  uint32_t wfar;
194 
195  /* MRC p15, 0, <Rd>, c6, c0, 1 ; Read WFAR */
197  ARMV4_5_MRC(15, 0, 0, 6, 0, 1),
198  &wfar);
199  if (retval != ERROR_OK)
200  return retval;
201  arm_dpm_report_wfar(arm11->arm.dpm, wfar);
202  }
203 
204 
205  retval = arm11_run_instr_data_finish(arm11);
206  if (retval != ERROR_OK)
207  return retval;
208 
209  return ERROR_OK;
210 }
211 
216 static int arm11_leave_debug_state(struct arm11_common *arm11, bool bpwp)
217 {
218  int retval;
219 
220  /* See e.g. ARM1136 TRM, "14.8.5 Leaving Debug state" */
221 
222  /* NOTE: the ARM1136 TRM suggests restoring all registers
223  * except R0/PC/CPSR right now. Instead, we do them all
224  * at once, just a bit later on.
225  */
226 
227  /* REVISIT once we start caring about MMU and cache state,
228  * address it here ...
229  */
230 
231  /* spec says clear wDTR and rDTR; we assume they are clear as
232  otherwise our programming would be sloppy */
233  {
235 
236  if (arm11->dscr & (DSCR_DTR_RX_FULL | DSCR_DTR_TX_FULL)) {
237  /*
238  The wDTR/rDTR two registers that are used to send/receive data to/from
239  the core in tandem with corresponding instruction codes that are
240  written into the core. The RDTR FULL/WDTR FULL flag indicates that the
241  registers hold data that was written by one side (CPU or JTAG) and not
242  read out by the other side.
243  */
244  LOG_ERROR("wDTR/rDTR inconsistent (DSCR %08" PRIx32 ")", arm11->dscr);
245  return ERROR_FAIL;
246  }
247  }
248 
249  /* maybe restore original wDTR */
250  if (arm11->is_wdtr_saved) {
251  retval = arm11_run_instr_data_prepare(arm11);
252  if (retval != ERROR_OK)
253  return retval;
254 
255  /* MCR p14,0,R0,c0,c5,0 */
257  0xee000e15, arm11->saved_wdtr);
258  if (retval != ERROR_OK)
259  return retval;
260 
261  retval = arm11_run_instr_data_finish(arm11);
262  if (retval != ERROR_OK)
263  return retval;
264  }
265 
266  /* restore CPSR, PC, and R0 ... after flushing any modified
267  * registers.
268  */
270 
272 
274 
275  /* restore DSCR */
276  CHECK_RETVAL(arm11_write_dscr(arm11, arm11->dscr));
277 
278  /* maybe restore rDTR */
279  if (arm11->is_rdtr_saved) {
281 
283 
284  struct scan_field chain5_fields[3];
285 
286  uint8_t ready = 0; /* ignored */
287  uint8_t valid = 0; /* ignored */
288 
289  arm11_setup_field(arm11, 32, &arm11->saved_rdtr,
290  NULL, chain5_fields + 0);
291  arm11_setup_field(arm11, 1, &ready, NULL, chain5_fields + 1);
292  arm11_setup_field(arm11, 1, &valid, NULL, chain5_fields + 2);
293 
295  chain5_fields), chain5_fields, TAP_DRPAUSE);
296  }
297 
298  /* now processor is ready to RESTART */
299 
300  return ERROR_OK;
301 }
302 
303 /* poll current target status */
304 static int arm11_poll(struct target *target)
305 {
306  int retval;
307  struct arm11_common *arm11 = target_to_arm11(target);
308 
310 
311  if (arm11->dscr & DSCR_CORE_HALTED) {
312  if (target->state != TARGET_HALTED) {
313  enum target_state old_state = target->state;
314 
315  LOG_DEBUG("enter TARGET_HALTED");
316  retval = arm11_debug_entry(arm11);
317  if (retval != ERROR_OK)
318  return retval;
319 
321  (old_state == TARGET_DEBUG_RUNNING)
324  }
325  } else {
327  LOG_DEBUG("enter TARGET_RUNNING");
330  }
331  }
332 
333  return ERROR_OK;
334 }
335 /* architecture specific status reply */
336 static int arm11_arch_state(struct target *target)
337 {
338  struct arm11_common *arm11 = target_to_arm11(target);
339  int retval;
340 
341  retval = arm_arch_state(target);
342 
343  /* REVISIT also display ARM11-specific MMU and cache status ... */
344 
346  LOG_USER("Watchpoint triggered at PC " TARGET_ADDR_FMT, arm11->dpm.wp_addr);
347 
348  return retval;
349 }
350 
351 /* target execution control */
352 static int arm11_halt(struct target *target)
353 {
354  struct arm11_common *arm11 = target_to_arm11(target);
355 
356  LOG_DEBUG("target->state: %s",
358 
359  if (target->state == TARGET_UNKNOWN)
360  arm11->simulate_reset_on_next_halt = true;
361 
362  if (target->state == TARGET_HALTED) {
363  LOG_DEBUG("target was already halted");
364  return ERROR_OK;
365  }
366 
368 
370 
371  int i = 0;
372 
373  while (1) {
375 
376  if (arm11->dscr & DSCR_CORE_HALTED)
377  break;
378 
379 
380  int64_t then = 0;
381  if (i == 1000)
382  then = timeval_ms();
383  if (i >= 1000) {
384  if ((timeval_ms()-then) > 1000) {
385  LOG_WARNING("Timeout (1000ms) waiting for instructions to complete");
386  return ERROR_FAIL;
387  }
388  }
389  i++;
390  }
391 
392  enum target_state old_state = target->state;
393 
395 
396  CHECK_RETVAL(
398  old_state ==
400 
401  return ERROR_OK;
402 }
403 
404 static uint32_t arm11_nextpc(struct arm11_common *arm11, int current, uint32_t address)
405 {
406  void *value = arm11->arm.pc->value;
407 
408  /* use the current program counter */
409  if (current)
410  address = buf_get_u32(value, 0, 32);
411 
412  /* Make sure that the gdb thumb fixup does not
413  * kill the return address
414  */
415  switch (arm11->arm.core_state) {
416  case ARM_STATE_ARM:
417  address &= 0xFFFFFFFC;
418  break;
419  case ARM_STATE_THUMB:
420  /* When the return address is loaded into PC
421  * bit 0 must be 1 to stay in Thumb state
422  */
423  address |= 0x1;
424  break;
425 
426  /* catch-all for JAZELLE and THUMB_EE */
427  default:
428  break;
429  }
430 
431  buf_set_u32(value, 0, 32, address);
432  arm11->arm.pc->dirty = true;
433  arm11->arm.pc->valid = true;
434 
435  return address;
436 }
437 
438 static int arm11_resume(struct target *target, int current,
439  target_addr_t address, int handle_breakpoints, int debug_execution)
440 {
441  /* LOG_DEBUG("current %d address %08x handle_breakpoints %d debug_execution %d", */
442  /* current, address, handle_breakpoints, debug_execution); */
443 
444  struct arm11_common *arm11 = target_to_arm11(target);
445 
446  LOG_DEBUG("target->state: %s",
448 
449 
450  if (target->state != TARGET_HALTED) {
451  LOG_TARGET_ERROR(target, "not halted");
453  }
454 
455  address = arm11_nextpc(arm11, current, address);
456 
457  LOG_DEBUG("RESUME PC %08" TARGET_PRIxADDR "%s", address, !current ? "!" : "");
458 
459  /* clear breakpoints/watchpoints and VCR*/
461 
462  if (!debug_execution)
464 
465  /* Should we skip over breakpoints matching the PC? */
466  if (handle_breakpoints) {
467  struct breakpoint *bp;
468 
469  for (bp = target->breakpoints; bp; bp = bp->next) {
470  if (bp->address == address) {
471  LOG_DEBUG("must step over %08" TARGET_PRIxADDR "", bp->address);
472  arm11_step(target, 1, 0, 0);
473  break;
474  }
475  }
476  }
477 
478  /* activate all breakpoints */
479  if (true) {
480  struct breakpoint *bp;
481  unsigned int brp_num = 0;
482 
483  for (bp = target->breakpoints; bp; bp = bp->next) {
484  struct arm11_sc7_action brp[2];
485 
486  brp[0].write = 1;
487  brp[0].address = ARM11_SC7_BVR0 + brp_num;
488  brp[0].value = bp->address;
489  brp[1].write = 1;
490  brp[1].address = ARM11_SC7_BCR0 + brp_num;
491  brp[1].value = 0x1 |
492  (3 <<
493  1) | (0x0F << 5) | (0 << 14) | (0 << 16) | (0 << 20) | (0 << 21);
494 
495  CHECK_RETVAL(arm11_sc7_run(arm11, brp, ARRAY_SIZE(brp)));
496 
497  LOG_DEBUG("Add BP %d at %08" TARGET_PRIxADDR, brp_num,
498  bp->address);
499 
500  brp_num++;
501  }
502 
503  if (arm11->vcr)
504  CHECK_RETVAL(arm11_sc7_set_vcr(arm11, arm11->vcr));
505  }
506 
507  /* activate all watchpoints and breakpoints */
509 
511 
513 
514  int i = 0;
515  while (1) {
517 
518  LOG_DEBUG("DSCR %08" PRIx32, arm11->dscr);
519 
520  if (arm11->dscr & DSCR_CORE_RESTARTED)
521  break;
522 
523 
524  int64_t then = 0;
525  if (i == 1000)
526  then = timeval_ms();
527  if (i >= 1000) {
528  if ((timeval_ms()-then) > 1000) {
529  LOG_WARNING("Timeout (1000ms) waiting for instructions to complete");
530  return ERROR_FAIL;
531  }
532  }
533  i++;
534  }
535 
537  if (!debug_execution)
539  else
542 
543  return ERROR_OK;
544 }
545 
546 static int arm11_step(struct target *target, int current,
547  target_addr_t address, int handle_breakpoints)
548 {
549  LOG_DEBUG("target->state: %s",
551 
552  if (target->state != TARGET_HALTED) {
553  LOG_TARGET_ERROR(target, "not halted");
555  }
556 
557  struct arm11_common *arm11 = target_to_arm11(target);
558 
559  address = arm11_nextpc(arm11, current, address);
560 
561  LOG_DEBUG("STEP PC %08" TARGET_PRIxADDR "%s", address, !current ? "!" : "");
562 
563 
566  uint32_t next_instruction;
567 
568  CHECK_RETVAL(arm11_read_memory_word(arm11, address, &next_instruction));
569 
570  /* skip over BKPT */
571  if ((next_instruction & 0xFFF00070) == 0xe1200070) {
572  address = arm11_nextpc(arm11, 0, address + 4);
573  LOG_DEBUG("Skipping BKPT %08" TARGET_PRIxADDR, address);
574  }
575  /* skip over Wait for interrupt / Standby
576  * mcr 15, 0, r?, cr7, cr0, {4} */
577  else if ((next_instruction & 0xFFFF0FFF) == 0xee070f90) {
578  address = arm11_nextpc(arm11, 0, address + 4);
579  LOG_DEBUG("Skipping WFI %08" TARGET_PRIxADDR, address);
580  }
581  /* ignore B to self */
582  else if ((next_instruction & 0xFEFFFFFF) == 0xeafffffe)
583  LOG_DEBUG("Not stepping jump to self");
584  else {
592  /* Set up breakpoint for stepping */
593 
594  struct arm11_sc7_action brp[2];
595 
596  brp[0].write = 1;
597  brp[0].address = ARM11_SC7_BVR0;
598  brp[1].write = 1;
599  brp[1].address = ARM11_SC7_BCR0;
600 
601  if (arm11->hardware_step) {
602  /* Hardware single stepping ("instruction address
603  * mismatch") is used if enabled. It's not quite
604  * exactly "run one instruction"; "branch to here"
605  * loops won't break, neither will some other cases,
606  * but it's probably the best default.
607  *
608  * Hardware single stepping isn't supported on v6
609  * debug modules. ARM1176 and v7 can support it...
610  *
611  * FIXME Thumb stepping likely needs to use 0x03
612  * or 0xc0 byte masks, not 0x0f.
613  */
614  brp[0].value = address;
615  brp[1].value = 0x1 | (3 << 1) | (0x0F << 5)
616  | (0 << 14) | (0 << 16) | (0 << 20)
617  | (2 << 21);
618  } else {
619  /* Sets a breakpoint on the next PC, as calculated
620  * by instruction set simulation.
621  *
622  * REVISIT stepping Thumb on ARM1156 requires Thumb2
623  * support from the simulator.
624  */
625  uint32_t next_pc;
626  int retval;
627 
628  retval = arm_simulate_step(target, &next_pc);
629  if (retval != ERROR_OK)
630  return retval;
631 
632  brp[0].value = next_pc;
633  brp[1].value = 0x1 | (3 << 1) | (0x0F << 5)
634  | (0 << 14) | (0 << 16) | (0 << 20)
635  | (0 << 21);
636  }
637 
638  CHECK_RETVAL(arm11_sc7_run(arm11, brp, ARRAY_SIZE(brp)));
639 
640  /* resume */
641 
642 
643  if (arm11->step_irq_enable)
644  /* this disable should be redundant ... */
645  arm11->dscr &= ~DSCR_INT_DIS;
646  else
647  arm11->dscr |= DSCR_INT_DIS;
648 
649 
650  CHECK_RETVAL(arm11_leave_debug_state(arm11, handle_breakpoints));
651 
653 
655 
656  /* wait for halt */
657  int i = 0;
658 
659  while (1) {
660  const uint32_t mask = DSCR_CORE_RESTARTED
662 
664  LOG_DEBUG("DSCR %08" PRIx32 " e", arm11->dscr);
665 
666  if ((arm11->dscr & mask) == mask)
667  break;
668 
669  long long then = 0;
670  if (i == 1000)
671  then = timeval_ms();
672  if (i >= 1000) {
673  if ((timeval_ms()-then) > 1000) {
674  LOG_WARNING(
675  "Timeout (1000ms) waiting for instructions to complete");
676  return ERROR_FAIL;
677  }
678  }
679  i++;
680  }
681 
682  /* clear breakpoint */
684 
685  /* save state */
687 
688  /* restore default state */
689  arm11->dscr &= ~DSCR_INT_DIS;
690 
691  }
692 
694 
696 
697  return ERROR_OK;
698 }
699 
700 static int arm11_assert_reset(struct target *target)
701 {
702  struct arm11_common *arm11 = target_to_arm11(target);
703 
704  if (!(target_was_examined(target))) {
706  jtag_add_reset(0, 1);
707  else {
708  LOG_WARNING("Reset is not asserted because the target is not examined.");
709  LOG_WARNING("Use a reset button or power cycle the target.");
711  }
712  } else {
713 
714  /* optionally catch reset vector */
715  if (target->reset_halt && !(arm11->vcr & 1))
716  CHECK_RETVAL(arm11_sc7_set_vcr(arm11, arm11->vcr | 1));
717 
718  /* Issue some kind of warm reset. */
721  else if (jtag_get_reset_config() & RESET_HAS_SRST) {
722  /* REVISIT handle "pulls" cases, if there's
723  * hardware that needs them to work.
724  */
725  jtag_add_reset(0, 1);
726  } else {
727  LOG_ERROR("%s: how to reset?", target_name(target));
728  return ERROR_FAIL;
729  }
730  }
731 
732  /* registers are now invalid */
734 
736 
737  return ERROR_OK;
738 }
739 
740 /*
741  * - There is another bug in the arm11 core. (iMX31 specific again?)
742  * When you generate an access to external logic (for example DDR
743  * controller via AHB bus) and that block is not configured (perhaps
744  * it is still held in reset), that transaction will never complete.
745  * This will hang arm11 core but it will also hang JTAG controller.
746  * Nothing short of srst assertion will bring it out of this.
747  */
748 
749 static int arm11_deassert_reset(struct target *target)
750 {
751  struct arm11_common *arm11 = target_to_arm11(target);
752  int retval;
753 
754  /* be certain SRST is off */
755  jtag_add_reset(0, 0);
756 
757  /* WORKAROUND i.MX31 problems: SRST goofs the TAP, and resets
758  * at least DSCR. OMAP24xx doesn't show that problem, though
759  * SRST-only reset seems to be problematic for other reasons.
760  * (Secure boot sequences being one likelihood!)
761  */
762  jtag_add_tlr();
763 
765 
766  if (target->reset_halt) {
767  if (target->state != TARGET_HALTED) {
768  LOG_WARNING("%s: ran after reset and before halt ...",
770  retval = target_halt(target);
771  if (retval != ERROR_OK)
772  return retval;
773  }
774  }
775 
776  /* maybe restore vector catch config */
777  if (target->reset_halt && !(arm11->vcr & 1))
778  CHECK_RETVAL(arm11_sc7_set_vcr(arm11, arm11->vcr));
779 
780  return ERROR_OK;
781 }
782 
783 /* target memory access
784  * size: 1 = byte (8bit), 2 = half-word (16bit), 4 = word (32bit)
785  * count: number of items of <size>
786  *
787  * arm11_config_memrw_no_increment - in the future we may want to be able
788  * to read/write a range of data to a "port". a "port" is an action on
789  * read memory address for some peripheral.
790  */
792  uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer,
793  bool arm11_config_memrw_no_increment)
794 {
797  int retval;
798 
799  if (target->state != TARGET_HALTED) {
800  LOG_TARGET_ERROR(target, "not halted");
802  }
803 
804  LOG_DEBUG("ADDR %08" PRIx32 " SIZE %08" PRIx32 " COUNT %08" PRIx32 "",
805  address,
806  size,
807  count);
808 
809  struct arm11_common *arm11 = target_to_arm11(target);
810 
811  retval = arm11_run_instr_data_prepare(arm11);
812  if (retval != ERROR_OK)
813  return retval;
814 
815  /* MRC p14,0,r0,c0,c5,0 */
816  retval = arm11_run_instr_data_to_core1(arm11, 0xee100e15, address);
817  if (retval != ERROR_OK)
818  return retval;
819 
820  switch (size) {
821  case 1:
822  arm11->arm.core_cache->reg_list[1].dirty = true;
823 
824  for (size_t i = 0; i < count; i++) {
825  /* ldrb r1, [r0], #1 */
826  /* ldrb r1, [r0] */
828  !arm11_config_memrw_no_increment ? 0xe4d01001 : 0xe5d01000));
829 
830  uint32_t res;
831  /* MCR p14,0,R1,c0,c5,0 */
832  CHECK_RETVAL(arm11_run_instr_data_from_core(arm11, 0xEE001E15, &res, 1));
833 
834  *buffer++ = res;
835  }
836 
837  break;
838 
839  case 2:
840  {
841  arm11->arm.core_cache->reg_list[1].dirty = true;
842 
843  for (size_t i = 0; i < count; i++) {
844  /* ldrh r1, [r0], #2 */
846  !arm11_config_memrw_no_increment ? 0xe0d010b2 : 0xe1d010b0));
847 
848  uint32_t res;
849 
850  /* MCR p14,0,R1,c0,c5,0 */
851  CHECK_RETVAL(arm11_run_instr_data_from_core(arm11, 0xEE001E15, &res, 1));
852 
853  uint16_t svalue = res;
854  memcpy(buffer + i * sizeof(uint16_t), &svalue, sizeof(uint16_t));
855  }
856 
857  break;
858  }
859 
860  case 4:
861  {
862  uint32_t instr = !arm11_config_memrw_no_increment ? 0xecb05e01 : 0xed905e00;
864  uint32_t *words = (uint32_t *)(void *)buffer;
865 
866  /* LDC p14,c5,[R0],#4 */
867  /* LDC p14,c5,[R0] */
868  CHECK_RETVAL(arm11_run_instr_data_from_core(arm11, instr, words, count));
869  break;
870  }
871  }
872 
873  return arm11_run_instr_data_finish(arm11);
874 }
875 
876 static int arm11_read_memory(struct target *target,
877  target_addr_t address,
878  uint32_t size,
879  uint32_t count,
880  uint8_t *buffer)
881 {
882  return arm11_read_memory_inner(target, address, size, count, buffer, false);
883 }
884 
885 /*
886 * no_increment - in the future we may want to be able
887 * to read/write a range of data to a "port". a "port" is an action on
888 * read memory address for some peripheral.
889 */
891  uint32_t address, uint32_t size,
892  uint32_t count, const uint8_t *buffer,
893  bool no_increment)
894 {
895  int retval;
896 
897  if (target->state != TARGET_HALTED) {
898  LOG_TARGET_ERROR(target, "not halted");
900  }
901 
902  LOG_DEBUG("ADDR %08" PRIx32 " SIZE %08" PRIx32 " COUNT %08" PRIx32 "",
903  address,
904  size,
905  count);
906 
907  struct arm11_common *arm11 = target_to_arm11(target);
908 
909  retval = arm11_run_instr_data_prepare(arm11);
910  if (retval != ERROR_OK)
911  return retval;
912 
913  /* load r0 with buffer address
914  * MRC p14,0,r0,c0,c5,0 */
915  retval = arm11_run_instr_data_to_core1(arm11, 0xee100e15, address);
916  if (retval != ERROR_OK)
917  return retval;
918 
919  /* burst writes are not used for single words as those may well be
920  * reset init script writes.
921  *
922  * The other advantage is that as burst writes are default, we'll
923  * now exercise both burst and non-burst code paths with the
924  * default settings, increasing code coverage.
925  */
926  bool burst = arm11->memwrite_burst && (count > 1);
927 
928  switch (size) {
929  case 1:
930  {
931  arm11->arm.core_cache->reg_list[1].dirty = true;
932 
933  for (size_t i = 0; i < count; i++) {
934  /* load r1 from DCC with byte data */
935  /* MRC p14,0,r1,c0,c5,0 */
936  retval = arm11_run_instr_data_to_core1(arm11, 0xee101e15, *buffer++);
937  if (retval != ERROR_OK)
938  return retval;
939 
940  /* write r1 to memory */
941  /* strb r1, [r0], #1 */
942  /* strb r1, [r0] */
943  retval = arm11_run_instr_no_data1(arm11,
944  !no_increment ? 0xe4c01001 : 0xe5c01000);
945  if (retval != ERROR_OK)
946  return retval;
947  }
948 
949  break;
950  }
951 
952  case 2:
953  {
954  arm11->arm.core_cache->reg_list[1].dirty = true;
955 
956  for (size_t i = 0; i < count; i++) {
957  uint16_t value;
958  memcpy(&value, buffer + i * sizeof(uint16_t), sizeof(uint16_t));
959 
960  /* load r1 from DCC with halfword data */
961  /* MRC p14,0,r1,c0,c5,0 */
962  retval = arm11_run_instr_data_to_core1(arm11, 0xee101e15, value);
963  if (retval != ERROR_OK)
964  return retval;
965 
966  /* write r1 to memory */
967  /* strh r1, [r0], #2 */
968  /* strh r1, [r0] */
969  retval = arm11_run_instr_no_data1(arm11,
970  !no_increment ? 0xe0c010b2 : 0xe1c010b0);
971  if (retval != ERROR_OK)
972  return retval;
973  }
974 
975  break;
976  }
977 
978  case 4: {
979  /* stream word data through DCC directly to memory */
980  /* increment: STC p14,c5,[R0],#4 */
981  /* no increment: STC p14,c5,[R0]*/
982  uint32_t instr = !no_increment ? 0xeca05e01 : 0xed805e00;
983 
985  uint32_t *words = (uint32_t *)(void *)buffer;
986 
987  /* "burst" here just means trusting each instruction executes
988  * fully before we run the next one: per-word roundtrips, to
989  * check the Ready flag, are not used.
990  */
991  if (!burst)
992  retval = arm11_run_instr_data_to_core(arm11,
993  instr, words, count);
994  else
995  retval = arm11_run_instr_data_to_core_noack(arm11,
996  instr, words, count);
997  if (retval != ERROR_OK)
998  return retval;
999 
1000  break;
1001  }
1002  }
1003 
1004  /* r0 verification */
1005  if (!no_increment) {
1006  uint32_t r0;
1007 
1008  /* MCR p14,0,R0,c0,c5,0 */
1009  retval = arm11_run_instr_data_from_core(arm11, 0xEE000E15, &r0, 1);
1010  if (retval != ERROR_OK)
1011  return retval;
1012 
1013  if (address + size * count != r0) {
1014  LOG_ERROR("Data transfer failed. Expected end address 0x%08" PRIx32 ", got 0x%08" PRIx32,
1015  address + size * count, r0);
1016 
1017  if (burst)
1018  LOG_ERROR(
1019  "use 'arm11 memwrite burst disable' to disable fast burst mode");
1020 
1021 
1022  if (arm11->memwrite_error_fatal)
1023  return ERROR_FAIL;
1024  }
1025  }
1026 
1027  return arm11_run_instr_data_finish(arm11);
1028 }
1029 
1030 static int arm11_write_memory(struct target *target,
1031  target_addr_t address, uint32_t size,
1032  uint32_t count, const uint8_t *buffer)
1033 {
1034  /* pointer increment matters only for multi-unit writes ...
1035  * not e.g. to a "reset the chip" controller.
1036  */
1037  return arm11_write_memory_inner(target, address, size,
1038  count, buffer, count == 1);
1039 }
1040 
1041 /* target break-/watchpoint control
1042 * rw: 0 = write, 1 = read, 2 = access
1043 */
1045  struct breakpoint *breakpoint)
1046 {
1047  struct arm11_common *arm11 = target_to_arm11(target);
1048 
1049 #if 0
1050  if (breakpoint->type == BKPT_SOFT) {
1051  LOG_INFO("sw breakpoint requested, but software breakpoints not enabled");
1053  }
1054 #endif
1055 
1056  if (!arm11->free_brps) {
1057  LOG_DEBUG("no breakpoint unit available for hardware breakpoint");
1059  }
1060 
1061  if (breakpoint->length != 4) {
1062  LOG_DEBUG("only breakpoints of four bytes length supported");
1064  }
1065 
1066  arm11->free_brps--;
1067 
1068  return ERROR_OK;
1069 }
1070 
1072  struct breakpoint *breakpoint)
1073 {
1074  struct arm11_common *arm11 = target_to_arm11(target);
1075 
1076  arm11->free_brps++;
1077 
1078  return ERROR_OK;
1079 }
1080 
1081 static int arm11_target_create(struct target *target, Jim_Interp *interp)
1082 {
1083  struct arm11_common *arm11;
1084 
1085  if (!target->tap)
1086  return ERROR_FAIL;
1087 
1088  if (target->tap->ir_length != 5) {
1089  LOG_ERROR("'target arm11' expects IR LENGTH = 5");
1091  }
1092 
1093  arm11 = calloc(1, sizeof(*arm11));
1094  if (!arm11)
1095  return ERROR_FAIL;
1096 
1097  arm11->arm.core_type = ARM_CORE_TYPE_STD;
1098  arm_init_arch_info(target, &arm11->arm);
1099 
1100  arm11->jtag_info.tap = target->tap;
1101  arm11->jtag_info.scann_size = 5;
1103  arm11->jtag_info.cur_scan_chain = ~0; /* invalid/unknown */
1105 
1106  arm11->memwrite_burst = true;
1107  arm11->memwrite_error_fatal = true;
1108 
1109  return ERROR_OK;
1110 }
1111 
1112 static int arm11_init_target(struct command_context *cmd_ctx,
1113  struct target *target)
1114 {
1115  /* Initialize anything we can set up without talking to the target */
1116  return ERROR_OK;
1117 }
1118 
1119 static void arm11_deinit_target(struct target *target)
1120 {
1121  struct arm11_common *arm11 = target_to_arm11(target);
1122 
1123  arm11_dpm_deinit(arm11);
1124  free(arm11);
1125 }
1126 
1127 /* talk to the target and set things up */
1128 static int arm11_examine(struct target *target)
1129 {
1130  int retval;
1131  char *type;
1132  struct arm11_common *arm11 = target_to_arm11(target);
1133  uint32_t didr, device_id;
1134  uint8_t implementor;
1135 
1136  /* FIXME split into do-first-time and do-every-time logic ... */
1137 
1138  /* check IDCODE */
1139 
1141 
1142  struct scan_field idcode_field;
1143 
1144  arm11_setup_field(arm11, 32, NULL, &device_id, &idcode_field);
1145 
1146  arm11_add_dr_scan_vc(arm11->arm.target->tap, 1, &idcode_field, TAP_DRPAUSE);
1147 
1148  /* check DIDR */
1149 
1151 
1153 
1154  struct scan_field chain0_fields[2];
1155 
1156  arm11_setup_field(arm11, 32, NULL, &didr, chain0_fields + 0);
1157  arm11_setup_field(arm11, 8, NULL, &implementor, chain0_fields + 1);
1158 
1160  chain0_fields), chain0_fields, TAP_IDLE);
1161 
1163 
1164  /* assume the manufacturer id is ok; check the part # */
1165  switch ((device_id >> 12) & 0xFFFF) {
1166  case 0x7B36:
1167  type = "ARM1136";
1168  break;
1169  case 0x7B37:
1170  type = "ARM11 MPCore";
1171  break;
1172  case 0x7B56:
1173  type = "ARM1156";
1174  break;
1175  case 0x7B76:
1177  /* NOTE: could default arm11->hardware_step to true */
1178  type = "ARM1176";
1179  break;
1180  default:
1181  LOG_ERROR("unexpected ARM11 ID code");
1182  return ERROR_FAIL;
1183  }
1184  LOG_INFO("found %s", type);
1185 
1186  /* unlikely this could ever fail, but ... */
1187  switch ((didr >> 16) & 0x0F) {
1188  case ARM11_DEBUG_V6:
1189  case ARM11_DEBUG_V61: /* supports security extensions */
1190  break;
1191  default:
1192  LOG_ERROR("Only ARM v6 and v6.1 debug supported.");
1193  return ERROR_FAIL;
1194  }
1195 
1196  arm11->brp = ((didr >> 24) & 0x0F) + 1;
1197 
1199  arm11->free_brps = arm11->brp;
1200 
1201  LOG_DEBUG("IDCODE %08" PRIx32 " IMPLEMENTOR %02x DIDR %08" PRIx32,
1202  device_id, implementor, didr);
1203 
1204  /* Build register cache "late", after target_init(), since we
1205  * want to know if this core supports Secure Monitor mode.
1206  */
1208  CHECK_RETVAL(arm11_dpm_init(arm11, didr));
1209 
1210  /* as a side-effect this reads DSCR and thus
1211  * clears the ARM11_DSCR_STICKY_PRECISE_DATA_ABORT / Sticky Precise Data Abort Flag
1212  * as suggested by the spec.
1213  */
1214 
1215  retval = arm11_check_init(arm11);
1216  if (retval != ERROR_OK)
1217  return retval;
1218 
1219  /* ETM on ARM11 still uses original scanchain 6 access mode */
1220  if (arm11->arm.etm && !target_was_examined(target)) {
1223  arm11->arm.etm);
1225  }
1226 
1228 
1229  return ERROR_OK;
1230 }
1231 
1232 #define ARM11_BOOL_WRAPPER(name, print_name) \
1233  COMMAND_HANDLER(arm11_handle_bool_ ## name) \
1234  { \
1235  struct target *target = get_current_target(CMD_CTX); \
1236  struct arm11_common *arm11 = target_to_arm11(target); \
1237  \
1238  return CALL_COMMAND_HANDLER(handle_command_parse_bool, \
1239  &arm11->name, print_name); \
1240  }
1241 
1242 ARM11_BOOL_WRAPPER(memwrite_burst, "memory write burst mode")
1243 ARM11_BOOL_WRAPPER(memwrite_error_fatal, "fatal error mode for memory writes")
1244 ARM11_BOOL_WRAPPER(step_irq_enable, "IRQs while stepping")
1245 ARM11_BOOL_WRAPPER(hardware_step, "hardware single step")
1246 
1247 /* REVISIT handle the VCR bits like other ARMs: use symbols for
1248  * input and output values.
1249  */
1250 
1251 COMMAND_HANDLER(arm11_handle_vcr)
1252 {
1254  struct arm11_common *arm11 = target_to_arm11(target);
1255 
1256  switch (CMD_ARGC) {
1257  case 0:
1258  break;
1259  case 1:
1260  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], arm11->vcr);
1261  break;
1262  default:
1264  }
1265 
1266  LOG_INFO("VCR 0x%08" PRIx32 "", arm11->vcr);
1267  return ERROR_OK;
1268 }
1269 
1270 static const struct command_registration arm11_mw_command_handlers[] = {
1271  {
1272  .name = "burst",
1273  .handler = arm11_handle_bool_memwrite_burst,
1274  .mode = COMMAND_ANY,
1275  .help = "Display or modify flag controlling potentially "
1276  "risky fast burst mode (default: enabled)",
1277  .usage = "['enable'|'disable']",
1278  },
1279  {
1280  .name = "error_fatal",
1281  .handler = arm11_handle_bool_memwrite_error_fatal,
1282  .mode = COMMAND_ANY,
1283  .help = "Display or modify flag controlling transfer "
1284  "termination on transfer errors"
1285  " (default: enabled)",
1286  .usage = "['enable'|'disable']",
1287  },
1289 };
1290 static const struct command_registration arm11_any_command_handlers[] = {
1291  {
1292  /* "hardware_step" is only here to check if the default
1293  * simulate + breakpoint implementation is broken.
1294  * TEMPORARY! NOT DOCUMENTED! */
1295  .name = "hardware_step",
1296  .handler = arm11_handle_bool_hardware_step,
1297  .mode = COMMAND_ANY,
1298  .help = "DEBUG ONLY - Hardware single stepping"
1299  " (default: disabled)",
1300  .usage = "['enable'|'disable']",
1301  },
1302  {
1303  .name = "memwrite",
1304  .mode = COMMAND_ANY,
1305  .help = "memwrite command group",
1306  .usage = "",
1307  .chain = arm11_mw_command_handlers,
1308  },
1309  {
1310  .name = "step_irq_enable",
1311  .handler = arm11_handle_bool_step_irq_enable,
1312  .mode = COMMAND_ANY,
1313  .help = "Display or modify flag controlling interrupt "
1314  "enable while stepping (default: disabled)",
1315  .usage = "['enable'|'disable']",
1316  },
1317  {
1318  .name = "vcr",
1319  .handler = arm11_handle_vcr,
1320  .mode = COMMAND_ANY,
1321  .help = "Display or modify Vector Catch Register",
1322  .usage = "[value]",
1323  },
1325 };
1326 
1327 static const struct command_registration arm11_command_handlers[] = {
1328  {
1330  },
1331  {
1333  },
1334  {
1335  .name = "arm11",
1336  .mode = COMMAND_ANY,
1337  .help = "ARM11 command group",
1338  .usage = "",
1339  .chain = arm11_any_command_handlers,
1340  },
1342 };
1343 
1345 struct target_type arm11_target = {
1346  .name = "arm11",
1347 
1348  .poll = arm11_poll,
1349  .arch_state = arm11_arch_state,
1350 
1351  .halt = arm11_halt,
1352  .resume = arm11_resume,
1353  .step = arm11_step,
1354 
1355  .assert_reset = arm11_assert_reset,
1356  .deassert_reset = arm11_deassert_reset,
1357 
1358  .get_gdb_arch = arm_get_gdb_arch,
1359  .get_gdb_reg_list = arm_get_gdb_reg_list,
1360 
1361  .read_memory = arm11_read_memory,
1362  .write_memory = arm11_write_memory,
1363 
1364  .checksum_memory = arm_checksum_memory,
1365  .blank_check_memory = arm_blank_check_memory,
1366 
1367  .add_breakpoint = arm11_add_breakpoint,
1368  .remove_breakpoint = arm11_remove_breakpoint,
1369 
1370  .run_algorithm = armv4_5_run_algorithm,
1371 
1372  .commands = arm11_command_handlers,
1373  .target_create = arm11_target_create,
1374  .init_target = arm11_init_target,
1375  .deinit_target = arm11_deinit_target,
1376  .examine = arm11_examine,
1377 };
#define CHECK_RETVAL(action)
Definition: arc.h:246
static int arm11_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: arm11.c:876
static int arm11_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
Definition: arm11.c:546
static int arm11_examine(struct target *target)
Definition: arm11.c:1128
COMMAND_HANDLER(arm11_handle_vcr)
Definition: arm11.c:1251
static int arm11_poll(struct target *target)
Definition: arm11.c:304
static int arm11_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Definition: arm11.c:438
static const struct command_registration arm11_mw_command_handlers[]
Definition: arm11.c:1270
static const struct command_registration arm11_command_handlers[]
Definition: arm11.c:1327
static void arm11_deinit_target(struct target *target)
Definition: arm11.c:1119
static int arm11_halt(struct target *target)
Definition: arm11.c:352
static int arm11_write_memory_inner(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer, bool no_increment)
Definition: arm11.c:890
static int arm11_leave_debug_state(struct arm11_common *arm11, bool bpwp)
Restore processor state.
Definition: arm11.c:216
static int arm11_assert_reset(struct target *target)
Definition: arm11.c:700
static int arm11_arch_state(struct target *target)
Definition: arm11.c:336
#define ARM11_BOOL_WRAPPER(name, print_name)
Definition: arm11.c:1232
static int arm11_read_memory_inner(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer, bool arm11_config_memrw_no_increment)
Definition: arm11.c:791
static int arm11_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: arm11.c:1112
static int arm11_deassert_reset(struct target *target)
Definition: arm11.c:749
struct target_type arm11_target
Holds methods for ARM11xx targets.
Definition: arm11.c:1345
static int arm11_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arm11.c:1044
static int arm11_debug_entry(struct arm11_common *arm11)
Save processor state.
Definition: arm11.c:81
static uint32_t arm11_nextpc(struct arm11_common *arm11, int current, uint32_t address)
Definition: arm11.c:404
static int arm11_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arm11.c:1071
static const struct command_registration arm11_any_command_handlers[]
Definition: arm11.c:1290
static int arm11_target_create(struct target *target, Jim_Interp *interp)
Definition: arm11.c:1081
static int arm11_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: arm11.c:1030
static int arm11_check_init(struct arm11_common *arm11)
Check and if necessary take control of the system.
Definition: arm11.c:41
#define ARM11_TAP_DEFAULT
Definition: arm11.h:16
static struct arm11_common * target_to_arm11(struct target *target)
Definition: arm11.h:72
@ ARM11_DEBUG_V61
Definition: arm11.h:31
@ ARM11_DEBUG_V6
Definition: arm11.h:30
@ ARM11_SC7_BVR0
Definition: arm11.h:97
@ ARM11_SC7_BCR0
Definition: arm11.h:98
@ ARM11_RESTART
Definition: arm11.h:85
@ ARM11_SCAN_N
Definition: arm11.h:84
@ ARM11_INTEST
Definition: arm11.h:87
@ 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.
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
int arm11_write_dscr(struct arm11_common *arm11, uint32_t dscr)
Write the Debug Status and Control Register (DSCR)
Definition: arm11_dbgtap.c:301
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
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
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
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
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
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
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
int arm11_sc7_set_vcr(struct arm11_common *arm11, uint32_t value)
Write VCR register.
Definition: arm11_dbgtap.c:957
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
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
int arm_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Runs ARM code in the target to check whether a memory block holds all ones.
Definition: armv4_5.c:1673
int arm_arch_state(struct target *target)
Definition: armv4_5.c:782
int arm_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Runs ARM code in the target to calculate a CRC32 checksum.
Definition: armv4_5.c:1600
const char * arm_get_gdb_arch(const struct target *target)
Definition: armv4_5.c:1267
int arm_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Definition: armv4_5.c:1272
@ ARM_STATE_THUMB
Definition: arm.h:152
@ ARM_STATE_ARM
Definition: arm.h:151
const struct command_registration arm_command_handlers[]
Definition: armv4_5.c:1247
int arm_init_arch_info(struct target *target, struct arm *arm)
Definition: armv4_5.c:1799
int armv4_5_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Definition: armv4_5.c:1574
@ ARM_CORE_TYPE_SEC_EXT
Definition: arm.h:47
@ ARM_CORE_TYPE_STD
Definition: arm.h:46
void arm_dpm_report_dscr(struct arm_dpm *dpm, uint32_t dscr)
Definition: arm_dpm.c:1055
int arm_dpm_read_current_registers(struct arm_dpm *dpm)
Read basic registers of the current context: R0 to R15, and CPSR; sets the core mode (such as USR or ...
Definition: arm_dpm.c:377
int arm_dpm_write_dirty_registers(struct arm_dpm *dpm, bool bpwp)
Writes all modified core registers for all processor modes.
Definition: arm_dpm.c:485
void arm_dpm_report_wfar(struct arm_dpm *dpm, uint32_t addr)
Definition: arm_dpm.c:1031
#define DSCR_INT_DIS
Definition: arm_dpm.h:180
#define DSCR_DTR_TX_FULL
Definition: arm_dpm.h:194
#define DSCR_CORE_HALTED
Definition: arm_dpm.h:172
#define DSCR_ITR_EN
Definition: arm_dpm.h:182
#define DSCR_DTR_RX_FULL
Definition: arm_dpm.h:195
#define DSCR_CORE_RESTARTED
Definition: arm_dpm.h:173
#define DSCR_HALT_DBG_MODE
Definition: arm_dpm.h:183
Macros used to generate various ARM or Thumb opcodes.
#define ARMV4_5_MRC(cp, op1, rd, crn, crm, op2)
Definition: arm_opcodes.h:186
int arm_simulate_step(struct target *target, uint32_t *dry_run_pc)
enum arm_mode mode
Definition: armv4_5.c:277
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
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
@ BKPT_SOFT
Definition: breakpoints.h:19
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:442
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
int mask
Definition: esirisc.c:1741
uint8_t type
Definition: esp_usb_jtag.c:0
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:416
const struct command_registration etm_command_handlers[]
Definition: etm.c:2007
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:764
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1043
void jtag_add_tlr(void)
Run a TAP_RESET reset where the end state is TAP_RESET, regardless of the start state.
Definition: jtag/core.c:484
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1740
@ TAP_DRPAUSE
Definition: jtag.h:44
@ TAP_IDLE
Definition: jtag.h:53
@ RESET_HAS_SRST
Definition: jtag.h:218
#define LOG_USER(expr ...)
Definition: log.h:135
#define LOG_WARNING(expr ...)
Definition: log.h:129
#define ERROR_FAIL
Definition: log.h:170
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:158
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_INFO(expr ...)
Definition: log.h:126
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
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
static int step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
Definition: riscv-011.c:1442
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
bool memwrite_burst
Definition: arm11.h:61
uint32_t vcr
Configured Vector Catch Register settings.
Definition: arm11.h:67
bool simulate_reset_on_next_halt
Perform cleanups of the ARM state on next halt.
Definition: arm11.h:55
size_t brp
Number of Breakpoint Register Pairs from DIDR
Definition: arm11.h:44
bool is_wdtr_saved
Definition: arm11.h:53
size_t free_brps
Number of breakpoints allocated.
Definition: arm11.h:45
struct arm_dpm dpm
Debug module state.
Definition: arm11.h:40
bool step_irq_enable
Definition: arm11.h:63
struct arm arm
Definition: arm11.h:37
uint32_t dscr
Last retrieved DSCR value.
Definition: arm11.h:47
bool hardware_step
Definition: arm11.h:64
bool memwrite_error_fatal
Definition: arm11.h:62
struct arm_jtag jtag_info
Definition: arm11.h:69
uint32_t saved_wdtr
Definition: arm11.h:50
bool is_rdtr_saved
Definition: arm11.h:52
uint32_t saved_rdtr
Definition: arm11.h:49
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
target_addr_t wp_addr
Target dependent watchpoint address.
Definition: arm_dpm.h:147
uint32_t scann_size
Definition: arm_jtag.h:20
uint32_t scann_instr
Definition: arm_jtag.h:21
uint32_t intest_instr
Definition: arm_jtag.h:24
struct jtag_tap * tap
Definition: arm_jtag.h:18
uint32_t cur_scan_chain
Definition: arm_jtag.h:22
struct etm_context * etm
Handle for the Embedded Trace Module, if one is present.
Definition: arm.h:216
enum arm_core_type core_type
Indicates what registers are in the ARM state core register set.
Definition: arm.h:193
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:181
struct reg_cache * core_cache
Definition: arm.h:178
struct arm_dpm * dpm
Handle for the debug module, if one is present.
Definition: arm.h:213
struct target * target
Backpointer to the target.
Definition: arm.h:210
enum arm_state core_state
Record the current core state: ARM, Thumb, or otherwise.
Definition: arm.h:199
struct breakpoint * next
Definition: breakpoints.h:34
unsigned int length
Definition: breakpoints.h:29
enum breakpoint_type type
Definition: breakpoints.h:30
target_addr_t address
Definition: breakpoints.h:27
const char * name
Definition: command.h:235
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:249
unsigned int ir_length
size of instruction register
Definition: jtag.h:110
struct reg * reg_list
Definition: register.h:147
bool valid
Definition: register.h:126
uint8_t * value
Definition: register.h:122
bool dirty
Definition: register.h:124
This structure defines a single scan field in the scan.
Definition: jtag.h:87
This holds methods shared between all instances of a given target type.
Definition: target_type.h:26
const char * name
Name of this type of target.
Definition: target_type.h:31
Definition: target.h:116
struct jtag_tap * tap
Definition: target.h:119
enum target_debug_reason debug_reason
Definition: target.h:154
enum target_state state
Definition: target.h:157
struct reg_cache * reg_cache
Definition: target.h:158
struct breakpoint * breakpoints
Definition: target.h:159
bool reset_halt
Definition: target.h:144
int target_call_event_callbacks(struct target *target, enum target_event event)
Definition: target.c:1764
void target_free_all_working_areas(struct target *target)
Definition: target.c:2150
int target_halt(struct target *target)
Definition: target.c:507
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
Definition: target.c:260
bool target_has_event_action(const struct target *target, enum target_event event)
Returns true only if the target has a handler for the specified event.
Definition: target.c:4860
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:458
void target_handle_event(struct target *target, enum target_event e)
Definition: target.c:4667
@ DBG_REASON_NOTHALTED
Definition: target.h:74
@ DBG_REASON_SINGLESTEP
Definition: target.h:73
@ DBG_REASON_WATCHPOINT
Definition: target.h:71
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:790
static bool target_was_examined(const struct target *target)
Definition: target.h:436
@ TARGET_EVENT_HALTED
Definition: target.h:252
@ TARGET_EVENT_RESUMED
Definition: target.h:253
@ TARGET_EVENT_DEBUG_HALTED
Definition: target.h:271
@ TARGET_EVENT_RESET_ASSERT
Definition: target.h:264
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
Definition: target.h:233
target_state
Definition: target.h:53
@ TARGET_RESET
Definition: target.h:57
@ TARGET_DEBUG_RUNNING
Definition: target.h:58
@ TARGET_UNKNOWN
Definition: target.h:54
@ TARGET_HALTED
Definition: target.h:56
@ TARGET_RUNNING
Definition: target.h:55
#define ERROR_TARGET_NOT_EXAMINED
Definition: target.h:797
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:794
static void target_set_examined(struct target *target)
Sets the examined flag for the given target.
Definition: target.h:443
int64_t timeval_ms(void)
#define TARGET_ADDR_FMT
Definition: types.h:342
#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
#define TARGET_PRIxADDR
Definition: types.h:340
#define NULL
Definition: usb.h:16
uint8_t count[4]
Definition: vdebug.c:22