OpenOCD
arm_dpm.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /*
4  * Copyright (C) 2009 by David Brownell
5  */
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 
11 #include "arm.h"
12 #include "arm_dpm.h"
13 #include "armv8_dpm.h"
14 #include <jtag/jtag.h>
15 #include "register.h"
16 #include "breakpoints.h"
17 #include "target_type.h"
18 #include "arm_opcodes.h"
19 
20 
34 /*----------------------------------------------------------------------*/
35 
36 /*
37  * Coprocessor support
38  */
39 
40 /* Read coprocessor */
41 static int dpm_mrc(struct target *target, int cpnum,
42  uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm,
43  uint32_t *value)
44 {
45  struct arm *arm = target_to_arm(target);
46  struct arm_dpm *dpm = arm->dpm;
47  int retval;
48 
49  retval = dpm->prepare(dpm);
50  if (retval != ERROR_OK)
51  return retval;
52 
53  LOG_TARGET_DEBUG(target, "MRC p%d, %" PRId32 ", r0, c%" PRId32 ", c%" PRId32 ", %" PRId32,
54  cpnum, op1, crn, crm, op2);
55 
56  /* read coprocessor register into R0; return via DCC */
57  retval = dpm->instr_read_data_r0(dpm,
58  ARMV4_5_MRC(cpnum, op1, 0, crn, crm, op2),
59  value);
60 
61  dpm->finish(dpm);
62  return retval;
63 }
64 
65 static int dpm_mrrc(struct target *target, int cpnum,
66  uint32_t op, uint32_t crm, uint64_t *value)
67 {
68  struct arm *arm = target_to_arm(target);
69  struct arm_dpm *dpm = arm->dpm;
70  int retval;
71 
72  retval = dpm->prepare(dpm);
73  if (retval != ERROR_OK)
74  return retval;
75 
76  LOG_TARGET_DEBUG(target, "MRRC p%d, %" PRId32 ", r0, r1, c%" PRId32,
77  cpnum, op, crm);
78 
79  /* read coprocessor register into R0, R1; return via DCC */
80  retval = dpm->instr_read_data_r0_r1(dpm,
81  ARMV5_T_MRRC(cpnum, op, 0, 1, crm),
82  value);
83 
84  dpm->finish(dpm);
85  return retval;
86 }
87 
88 static int dpm_mcr(struct target *target, int cpnum,
89  uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm,
90  uint32_t value)
91 {
92  struct arm *arm = target_to_arm(target);
93  struct arm_dpm *dpm = arm->dpm;
94  int retval;
95 
96  retval = dpm->prepare(dpm);
97  if (retval != ERROR_OK)
98  return retval;
99 
100  LOG_TARGET_DEBUG(target, "MCR p%d, %" PRId32 ", r0, c%" PRId32 ", c%" PRId32 ", %" PRId32,
101  cpnum, op1, crn, crm, op2);
102 
103  /* read DCC into r0; then write coprocessor register from R0 */
104  retval = dpm->instr_write_data_r0(dpm,
105  ARMV4_5_MCR(cpnum, op1, 0, crn, crm, op2),
106  value);
107 
108  dpm->finish(dpm);
109  return retval;
110 }
111 
112 static int dpm_mcrr(struct target *target, int cpnum,
113  uint32_t op, uint32_t crm, uint64_t value)
114 {
115  struct arm *arm = target_to_arm(target);
116  struct arm_dpm *dpm = arm->dpm;
117  int retval;
118 
119  retval = dpm->prepare(dpm);
120  if (retval != ERROR_OK)
121  return retval;
122 
123  LOG_TARGET_DEBUG(target, "MCRR p%d, %" PRId32 ", r0, r1, c%" PRId32,
124  cpnum, op, crm);
125 
126  /* read DCC into r0, r1; then write coprocessor register from R0, R1 */
127  retval = dpm->instr_write_data_r0_r1(dpm,
128  ARMV5_T_MCRR(cpnum, op, 0, 1, crm), value);
129 
130  dpm->finish(dpm);
131 
132  return retval;
133 }
134 
135 /*----------------------------------------------------------------------*/
136 
137 /*
138  * Register access utilities
139  */
140 
141 /* Toggles between recorded core mode (USR, SVC, etc) and a temporary one.
142  * Routines *must* restore the original mode before returning!!
143  */
144 int arm_dpm_modeswitch(struct arm_dpm *dpm, enum arm_mode mode)
145 {
146  int retval;
147  uint32_t cpsr;
148 
149  /* restore previous mode */
150  if (mode == ARM_MODE_ANY)
151  cpsr = buf_get_u32(dpm->arm->cpsr->value, 0, 32);
152 
153  /* else force to the specified mode */
154  else
155  cpsr = mode;
156 
157  retval = dpm->instr_write_data_r0(dpm, ARMV4_5_MSR_GP(0, 0xf, 0), cpsr);
158  if (retval != ERROR_OK)
159  return retval;
160 
161  if (dpm->instr_cpsr_sync)
162  retval = dpm->instr_cpsr_sync(dpm);
163 
164  return retval;
165 }
166 
167 /* Read 64bit VFP registers */
168 static int dpm_read_reg_u64(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
169 {
170  int retval = ERROR_FAIL;
171  uint32_t value_r0, value_r1;
172 
173  switch (regnum) {
174  case ARM_VFP_V3_D0 ... ARM_VFP_V3_D31:
175  /* move from double word register to r0:r1: "vmov r0, r1, vm"
176  * then read r0 via dcc
177  */
178  retval = dpm->instr_read_data_r0(dpm,
179  ARMV4_5_VMOV(1, 1, 0, ((regnum - ARM_VFP_V3_D0) >> 4),
180  ((regnum - ARM_VFP_V3_D0) & 0xf)), &value_r0);
181  if (retval != ERROR_OK)
182  break;
183 
184  /* read r1 via dcc */
185  retval = dpm->instr_read_data_dcc(dpm,
186  ARMV4_5_MCR(14, 0, 1, 0, 5, 0),
187  &value_r1);
188  break;
189  default:
190  break;
191  }
192 
193  if (retval == ERROR_OK) {
194  buf_set_u32(r->value, 0, 32, value_r0);
195  buf_set_u32(r->value + 4, 0, 32, value_r1);
196  r->valid = true;
197  r->dirty = false;
198  LOG_TARGET_DEBUG(dpm->arm->target, "READ: %s, %8.8" PRIx32 ", %8.8" PRIx32,
199  r->name, value_r0, value_r1);
200  }
201 
202  return retval;
203 }
204 
205 /* just read the register -- rely on the core mode being right */
206 int arm_dpm_read_reg(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
207 {
208  uint32_t value;
209  int retval;
210 
211  switch (regnum) {
212  case 0 ... 14:
213  /* return via DCC: "MCR p14, 0, Rnum, c0, c5, 0" */
214  retval = dpm->instr_read_data_dcc(dpm,
215  ARMV4_5_MCR(14, 0, regnum, 0, 5, 0),
216  &value);
217  break;
218  case 15:/* PC
219  * "MOV r0, pc"; then return via DCC */
220  retval = dpm->instr_read_data_r0(dpm, 0xe1a0000f, &value);
221 
222  /* NOTE: this seems like a slightly awkward place to update
223  * this value ... but if the PC gets written (the only way
224  * to change what we compute), the arch spec says subsequent
225  * reads return values which are "unpredictable". So this
226  * is always right except in those broken-by-intent cases.
227  */
228  switch (dpm->arm->core_state) {
229  case ARM_STATE_ARM:
230  value -= 8;
231  break;
232  case ARM_STATE_THUMB:
233  case ARM_STATE_THUMB_EE:
234  value -= 4;
235  break;
236  case ARM_STATE_JAZELLE:
237  /* core-specific ... ? */
238  LOG_TARGET_WARNING(dpm->arm->target, "Jazelle PC adjustment unknown");
239  break;
240  default:
241  LOG_TARGET_WARNING(dpm->arm->target, "unknown core state");
242  break;
243  }
244  break;
245  case ARM_VFP_V3_D0 ... ARM_VFP_V3_D31:
246  return dpm_read_reg_u64(dpm, r, regnum);
247  case ARM_VFP_V3_FPSCR:
248  /* "VMRS r0, FPSCR"; then return via DCC */
249  retval = dpm->instr_read_data_r0(dpm,
250  ARMV4_5_VMRS(0), &value);
251  break;
252  default:
253  /* 16: "MRS r0, CPSR"; then return via DCC
254  * 17: "MRS r0, SPSR"; then return via DCC
255  */
256  retval = dpm->instr_read_data_r0(dpm,
257  ARMV4_5_MRS(0, regnum & 1),
258  &value);
259  break;
260  }
261 
262  if (retval == ERROR_OK) {
263  buf_set_u32(r->value, 0, 32, value);
264  r->valid = true;
265  r->dirty = false;
266  LOG_TARGET_DEBUG(dpm->arm->target, "READ: %s, %8.8" PRIx32, r->name,
267  value);
268  }
269 
270  return retval;
271 }
272 
273 /* Write 64bit VFP registers */
274 static int dpm_write_reg_u64(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
275 {
276  int retval = ERROR_FAIL;
277  uint32_t value_r0 = buf_get_u32(r->value, 0, 32);
278  uint32_t value_r1 = buf_get_u32(r->value + 4, 0, 32);
279 
280  switch (regnum) {
281  case ARM_VFP_V3_D0 ... ARM_VFP_V3_D31:
282  /* write value_r1 to r1 via dcc */
283  retval = dpm->instr_write_data_dcc(dpm,
284  ARMV4_5_MRC(14, 0, 1, 0, 5, 0),
285  value_r1);
286  if (retval != ERROR_OK)
287  break;
288 
289  /* write value_r0 to r0 via dcc then,
290  * move to double word register from r0:r1: "vmov vm, r0, r1"
291  */
292  retval = dpm->instr_write_data_r0(dpm,
293  ARMV4_5_VMOV(0, 1, 0, ((regnum - ARM_VFP_V3_D0) >> 4),
294  ((regnum - ARM_VFP_V3_D0) & 0xf)), value_r0);
295  break;
296  default:
297  break;
298  }
299 
300  if (retval == ERROR_OK) {
301  r->dirty = false;
302  LOG_TARGET_DEBUG(dpm->arm->target, "WRITE: %s, %8.8" PRIx32 ", %8.8" PRIx32,
303  r->name, value_r0, value_r1);
304  }
305 
306  return retval;
307 }
308 
309 /* just write the register -- rely on the core mode being right */
310 static int dpm_write_reg(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
311 {
312  int retval;
313  uint32_t value = buf_get_u32(r->value, 0, 32);
314 
315  switch (regnum) {
316  case 0 ... 14:
317  /* load register from DCC: "MRC p14, 0, Rnum, c0, c5, 0" */
318  retval = dpm->instr_write_data_dcc(dpm,
319  ARMV4_5_MRC(14, 0, regnum, 0, 5, 0),
320  value);
321  break;
322  case 15:/* PC
323  * read r0 from DCC; then "MOV pc, r0" */
324  retval = dpm->instr_write_data_r0(dpm, 0xe1a0f000, value);
325  break;
326  case ARM_VFP_V3_D0 ... ARM_VFP_V3_D31:
327  return dpm_write_reg_u64(dpm, r, regnum);
328  case ARM_VFP_V3_FPSCR:
329  /* move to r0 from DCC, then "VMSR FPSCR, r0" */
330  retval = dpm->instr_write_data_r0(dpm,
331  ARMV4_5_VMSR(0), value);
332  break;
333  default:
334  /* 16: read r0 from DCC, then "MSR r0, CPSR_cxsf"
335  * 17: read r0 from DCC, then "MSR r0, SPSR_cxsf"
336  */
337  retval = dpm->instr_write_data_r0(dpm,
338  ARMV4_5_MSR_GP(0, 0xf, regnum & 1),
339  value);
340  if (retval != ERROR_OK)
341  return retval;
342 
343  if (regnum == 16 && dpm->instr_cpsr_sync)
344  retval = dpm->instr_cpsr_sync(dpm);
345 
346  break;
347  }
348 
349  if (retval == ERROR_OK) {
350  r->dirty = false;
351  LOG_TARGET_DEBUG(dpm->arm->target, "WRITE: %s, %8.8" PRIx32, r->name,
352  value);
353  }
354 
355  return retval;
356 }
357 
362 static int dpm_write_pc_core_state(struct arm_dpm *dpm, struct reg *r)
363 {
364  uint32_t value = buf_get_u32(r->value, 0, 32);
365 
366  /* read r0 from DCC; then "BX r0" */
367  return dpm->instr_write_data_r0(dpm, ARMV4_5_BX(0), value);
368 }
369 
378 {
379  struct arm *arm = dpm->arm;
380  uint32_t cpsr;
381  int retval;
382  struct reg *r;
383 
384  retval = dpm->prepare(dpm);
385  if (retval != ERROR_OK)
386  return retval;
387 
388  /* read R0 and R1 first (it's used for scratch), then CPSR */
389  for (unsigned int i = 0; i < 2; i++) {
390  r = arm->core_cache->reg_list + i;
391  if (!r->valid) {
392  retval = arm_dpm_read_reg(dpm, r, i);
393  if (retval != ERROR_OK)
394  goto fail;
395  }
396  r->dirty = true;
397  }
398 
399  retval = dpm->instr_read_data_r0(dpm, ARMV4_5_MRS(0, 0), &cpsr);
400  if (retval != ERROR_OK)
401  goto fail;
402 
403  /* update core mode and state, plus shadow mapping for R8..R14 */
404  arm_set_cpsr(arm, cpsr);
405 
406  /* REVISIT we can probably avoid reading R1..R14, saving time... */
407  for (unsigned int i = 2; i < 16; i++) {
408  r = arm_reg_current(arm, i);
409  if (r->valid)
410  continue;
411 
412  retval = arm_dpm_read_reg(dpm, r, i);
413  if (retval != ERROR_OK)
414  goto fail;
415  }
416 
417  /* NOTE: SPSR ignored (if it's even relevant). */
418 
419  /* REVISIT the debugger can trigger various exceptions. See the
420  * ARMv7A architecture spec, section C5.7, for more info about
421  * what defenses are needed; v6 debug has the most issues.
422  */
423 
424 fail:
425  dpm->finish(dpm);
426  return retval;
427 }
428 
429 /* Avoid needless I/O ... leave breakpoints and watchpoints alone
430  * unless they're removed, or need updating because of single-stepping
431  * or running debugger code.
432  */
433 static int dpm_maybe_update_bpwp(struct arm_dpm *dpm, bool bpwp,
434  struct dpm_bpwp *xp, bool *set_p)
435 {
436  int retval = ERROR_OK;
437  bool disable;
438 
439  if (!set_p) {
440  if (!xp->dirty)
441  goto done;
442  xp->dirty = false;
443  /* removed or startup; we must disable it */
444  disable = true;
445  } else if (bpwp) {
446  if (!xp->dirty)
447  goto done;
448  /* disabled, but we must set it */
449  xp->dirty = disable = false;
450  *set_p = true;
451  } else {
452  if (!*set_p)
453  goto done;
454  /* set, but we must temporarily disable it */
455  xp->dirty = disable = true;
456  *set_p = false;
457  }
458 
459  if (disable)
460  retval = dpm->bpwp_disable(dpm, xp->number);
461  else
462  retval = dpm->bpwp_enable(dpm, xp->number,
463  xp->address, xp->control);
464 
465  if (retval != ERROR_OK)
466  LOG_TARGET_ERROR(dpm->arm->target, "can't %s HW %spoint %d",
467  disable ? "disable" : "enable",
468  (xp->number < 16) ? "break" : "watch",
469  xp->number & 0xf);
470 done:
471  return retval;
472 }
473 
474 static int dpm_add_breakpoint(struct target *target, struct breakpoint *bp);
475 
484 int arm_dpm_write_dirty_registers(struct arm_dpm *dpm, bool bpwp)
485 {
486  struct arm *arm = dpm->arm;
487  struct reg_cache *cache = arm->core_cache;
488  int retval;
489  bool did_write;
490 
491  retval = dpm->prepare(dpm);
492  if (retval != ERROR_OK)
493  goto done;
494 
495  /* If we're managing hardware breakpoints for this core, enable
496  * or disable them as requested.
497  *
498  * REVISIT We don't yet manage them for ANY cores. Eventually
499  * we should be able to assume we handle them; but until then,
500  * cope with the hand-crafted breakpoint code.
501  */
503  for (unsigned int i = 0; i < dpm->nbp; i++) {
504  struct dpm_bp *dbp = dpm->dbp + i;
505  struct breakpoint *bp = dbp->bp;
506 
507  retval = dpm_maybe_update_bpwp(dpm, bpwp, &dbp->bpwp,
508  bp ? &bp->is_set : NULL);
509  if (retval != ERROR_OK)
510  goto done;
511  }
512  }
513 
514  /* enable/disable watchpoints */
515  for (unsigned int i = 0; i < dpm->nwp; i++) {
516  struct dpm_wp *dwp = dpm->dwp + i;
517  struct watchpoint *wp = dwp->wp;
518 
519  retval = dpm_maybe_update_bpwp(dpm, bpwp, &dwp->bpwp,
520  wp ? &wp->is_set : NULL);
521  if (retval != ERROR_OK)
522  goto done;
523  }
524 
525  /* NOTE: writes to breakpoint and watchpoint registers might
526  * be queued, and need (efficient/batched) flushing later.
527  */
528 
529  /* Scan the registers until we find one that's both dirty and
530  * eligible for flushing. Flush that and everything else that
531  * shares the same core mode setting. Typically this won't
532  * actually find anything to do...
533  */
534  do {
535  enum arm_mode mode = ARM_MODE_ANY;
536 
537  did_write = false;
538 
539  /* check everything except our scratch registers R0 and R1 */
540  for (unsigned int i = 2; i < cache->num_regs; i++) {
541  struct arm_reg *r;
542  unsigned int regnum;
543 
544  /* also skip PC, CPSR, and non-dirty */
545  if (i == 15)
546  continue;
547  if (arm->cpsr == cache->reg_list + i)
548  continue;
549  if (!cache->reg_list[i].exist || !cache->reg_list[i].dirty)
550  continue;
551 
552  r = cache->reg_list[i].arch_info;
553  regnum = r->num;
554 
555  /* may need to pick and set a mode */
556  if (!did_write) {
557  enum arm_mode tmode;
558 
559  did_write = true;
560  mode = tmode = r->mode;
561 
562  /* cope with special cases */
563  switch (regnum) {
564  case 8 ... 12:
565  /* r8..r12 "anything but FIQ" case;
566  * we "know" core mode is accurate
567  * since we haven't changed it yet
568  */
569  if (arm->core_mode == ARM_MODE_FIQ
570  && ARM_MODE_ANY
571  != mode)
572  tmode = ARM_MODE_USR;
573  break;
574  case 16:
575  /* SPSR */
576  regnum++;
577  break;
578  }
579 
580  /* REVISIT error checks */
581  if (tmode != ARM_MODE_ANY) {
582  retval = arm_dpm_modeswitch(dpm, tmode);
583  if (retval != ERROR_OK)
584  goto done;
585  }
586  }
587  if (r->mode != mode)
588  continue;
589 
590  retval = dpm_write_reg(dpm,
591  &cache->reg_list[i],
592  regnum);
593  if (retval != ERROR_OK)
594  goto done;
595  }
596 
597  } while (did_write);
598 
599  /* Restore original CPSR ... assuming either that we changed it,
600  * or it's dirty. Must write PC to ensure the return address is
601  * defined, and must not write it before CPSR.
602  */
603  retval = arm_dpm_modeswitch(dpm, ARM_MODE_ANY);
604  if (retval != ERROR_OK)
605  goto done;
606  arm->cpsr->dirty = false;
607 
608  /* restore the PC, make sure to also switch the core state
609  * to whatever it was set to with "arm core_state" command.
610  * target code will have set PC to an appropriate resume address.
611  */
612  retval = dpm_write_pc_core_state(dpm, arm->pc);
613  if (retval != ERROR_OK)
614  goto done;
615  /* on Cortex-A5 (as found on NXP VF610 SoC), BX instruction
616  * executed in debug state doesn't appear to set the PC,
617  * explicitly set it with a "MOV pc, r0". This doesn't influence
618  * CPSR on Cortex-A9 so it should be OK. Maybe due to different
619  * debug version?
620  */
621  retval = dpm_write_reg(dpm, arm->pc, 15);
622  if (retval != ERROR_OK)
623  goto done;
624  arm->pc->dirty = false;
625 
626  /* flush R0 and R1 (our scratch registers) */
627  for (unsigned int i = 0; i < 2; i++) {
628  retval = dpm_write_reg(dpm, &cache->reg_list[i], i);
629  if (retval != ERROR_OK)
630  goto done;
631  cache->reg_list[i].dirty = false;
632  }
633 
634  dpm->finish(dpm);
635 done:
636  return retval;
637 }
638 
639 /* Returns ARM_MODE_ANY or temporary mode to use while reading the
640  * specified register ... works around flakiness from ARM core calls.
641  * Caller already filtered out SPSR access; mode is never MODE_SYS
642  * or MODE_ANY.
643  */
644 static enum arm_mode dpm_mapmode(struct arm *arm,
645  unsigned int num, enum arm_mode mode)
646 {
647  enum arm_mode amode = arm->core_mode;
648 
649  /* don't switch if the mode is already correct */
650  if (amode == ARM_MODE_SYS)
651  amode = ARM_MODE_USR;
652  if (mode == amode)
653  return ARM_MODE_ANY;
654 
655  switch (num) {
656  /* don't switch for non-shadowed registers (r0..r7, r15/pc, cpsr) */
657  case 0 ... 7:
658  case 15:
659  case 16:
660  break;
661  /* r8..r12 aren't shadowed for anything except FIQ */
662  case 8 ... 12:
663  if (mode == ARM_MODE_FIQ)
664  return mode;
665  break;
666  /* r13/sp, and r14/lr are always shadowed */
667  case 13:
668  case 14:
670  return mode;
671  default:
672  LOG_TARGET_WARNING(arm->target, "invalid register #%u", num);
673  break;
674  }
675  return ARM_MODE_ANY;
676 }
677 
678 
679 /*
680  * Standard ARM register accessors ... there are three methods
681  * in "struct arm", to support individual read/write and bulk read
682  * of registers.
683  */
684 
685 static int arm_dpm_read_core_reg(struct target *target, struct reg *r,
686  int regnum, enum arm_mode mode)
687 {
688  struct arm_dpm *dpm = target_to_arm(target)->dpm;
689  int retval;
690 
691  if (regnum < 0 || (regnum > 16 && regnum < ARM_VFP_V3_D0) ||
692  (regnum > ARM_VFP_V3_FPSCR))
694 
695  if (regnum == 16) {
696  if (mode != ARM_MODE_ANY)
697  regnum = 17;
698  } else
699  mode = dpm_mapmode(dpm->arm, regnum, mode);
700 
701  /* REVISIT what happens if we try to read SPSR in a core mode
702  * which has no such register?
703  */
704 
705  retval = dpm->prepare(dpm);
706  if (retval != ERROR_OK)
707  return retval;
708 
709  if (mode != ARM_MODE_ANY) {
710  retval = arm_dpm_modeswitch(dpm, mode);
711  if (retval != ERROR_OK)
712  goto fail;
713  }
714 
715  retval = arm_dpm_read_reg(dpm, r, regnum);
716  if (retval != ERROR_OK)
717  goto fail;
718  /* always clean up, regardless of error */
719 
720  if (mode != ARM_MODE_ANY)
722 
723 fail:
724  dpm->finish(dpm);
725  return retval;
726 }
727 
728 static int arm_dpm_write_core_reg(struct target *target, struct reg *r,
729  int regnum, enum arm_mode mode, uint8_t *value)
730 {
731  struct arm_dpm *dpm = target_to_arm(target)->dpm;
732  int retval;
733 
734 
735  if (regnum < 0 || (regnum > 16 && regnum < ARM_VFP_V3_D0) ||
736  (regnum > ARM_VFP_V3_FPSCR))
738 
739  if (regnum == 16) {
740  if (mode != ARM_MODE_ANY)
741  regnum = 17;
742  } else
743  mode = dpm_mapmode(dpm->arm, regnum, mode);
744 
745  /* REVISIT what happens if we try to write SPSR in a core mode
746  * which has no such register?
747  */
748 
749  retval = dpm->prepare(dpm);
750  if (retval != ERROR_OK)
751  return retval;
752 
753  if (mode != ARM_MODE_ANY) {
754  retval = arm_dpm_modeswitch(dpm, mode);
755  if (retval != ERROR_OK)
756  goto fail;
757  }
758 
759  retval = dpm_write_reg(dpm, r, regnum);
760  /* always clean up, regardless of error */
761 
762  if (mode != ARM_MODE_ANY)
764 
765 fail:
766  dpm->finish(dpm);
767  return retval;
768 }
769 
770 static int arm_dpm_full_context(struct target *target)
771 {
772  struct arm *arm = target_to_arm(target);
773  struct arm_dpm *dpm = arm->dpm;
774  struct reg_cache *cache = arm->core_cache;
775  int retval;
776  bool did_read;
777 
778  retval = dpm->prepare(dpm);
779  if (retval != ERROR_OK)
780  goto done;
781 
782  do {
783  enum arm_mode mode = ARM_MODE_ANY;
784 
785  did_read = false;
786 
787  /* We "know" arm_dpm_read_current_registers() was called so
788  * the unmapped registers (R0..R7, PC, AND CPSR) and some
789  * view of R8..R14 are current. We also "know" oddities of
790  * register mapping: special cases for R8..R12 and SPSR.
791  *
792  * Pick some mode with unread registers and read them all.
793  * Repeat until done.
794  */
795  for (unsigned int i = 0; i < cache->num_regs; i++) {
796  struct arm_reg *r;
797 
798  if (!cache->reg_list[i].exist || cache->reg_list[i].valid)
799  continue;
800  r = cache->reg_list[i].arch_info;
801 
802  /* may need to pick a mode and set CPSR */
803  if (!did_read) {
804  did_read = true;
805  mode = r->mode;
806 
807  /* For regular (ARM_MODE_ANY) R8..R12
808  * in case we've entered debug state
809  * in FIQ mode we need to patch mode.
810  */
811  if (mode != ARM_MODE_ANY)
812  retval = arm_dpm_modeswitch(dpm, mode);
813  else
814  retval = arm_dpm_modeswitch(dpm, ARM_MODE_USR);
815 
816  if (retval != ERROR_OK)
817  goto done;
818  }
819  if (r->mode != mode)
820  continue;
821 
822  /* CPSR was read, so "R16" must mean SPSR */
823  retval = arm_dpm_read_reg(dpm,
824  &cache->reg_list[i],
825  (r->num == 16) ? 17 : r->num);
826  if (retval != ERROR_OK)
827  goto done;
828  }
829 
830  } while (did_read);
831 
832  retval = arm_dpm_modeswitch(dpm, ARM_MODE_ANY);
833  dpm->finish(dpm);
834 done:
835  return retval;
836 }
837 
838 
839 /*----------------------------------------------------------------------*/
840 
841 /*
842  * Breakpoint and Watchpoint support.
843  *
844  * Hardware {break,watch}points are usually left active, to minimize
845  * debug entry/exit costs. When they are set or cleared, it's done in
846  * batches. Also, DPM-conformant hardware can update debug registers
847  * regardless of whether the CPU is running or halted ... though that
848  * fact isn't currently leveraged.
849  */
850 
851 static int dpm_bpwp_setup(struct arm_dpm *dpm, struct dpm_bpwp *xp,
852  uint32_t addr, uint32_t length)
853 {
854  uint32_t control;
855 
856  control = (1 << 0) /* enable */
857  | (3 << 1); /* both user and privileged access */
858 
859  /* Match 1, 2, or all 4 byte addresses in this word.
860  *
861  * FIXME: v7 hardware allows lengths up to 2 GB for BP and WP.
862  * Support larger length, when addr is suitably aligned. In
863  * particular, allow watchpoints on 8 byte "double" values.
864  *
865  * REVISIT allow watchpoints on unaligned 2-bit values; and on
866  * v7 hardware, unaligned 4-byte ones too.
867  */
868  switch (length) {
869  case 1:
870  control |= (1 << (addr & 3)) << 5;
871  break;
872  case 2:
873  /* require 2-byte alignment */
874  if (!(addr & 1)) {
875  control |= (3 << (addr & 2)) << 5;
876  break;
877  }
878  /* FALL THROUGH */
879  case 4:
880  /* require 4-byte alignment */
881  if (!(addr & 3)) {
882  control |= 0xf << 5;
883  break;
884  }
885  /* FALL THROUGH */
886  default:
887  LOG_TARGET_ERROR(dpm->arm->target, "unsupported {break,watch}point length/alignment");
889  }
890 
891  /* other shared control bits:
892  * bits 15:14 == 0 ... both secure and nonsecure states (v6.1+ only)
893  * bit 20 == 0 ... not linked to a context ID
894  * bit 28:24 == 0 ... not ignoring N LSBs (v7 only)
895  */
896 
897  xp->address = addr & ~3;
898  xp->control = control;
899  xp->dirty = true;
900 
901  LOG_TARGET_DEBUG(dpm->arm->target, "BPWP: addr %8.8" PRIx32 ", control %" PRIx32 ", number %d",
902  xp->address, control, xp->number);
903 
904  /* hardware is updated in write_dirty_registers() */
905  return ERROR_OK;
906 }
907 
908 static int dpm_add_breakpoint(struct target *target, struct breakpoint *bp)
909 {
910  struct arm *arm = target_to_arm(target);
911  struct arm_dpm *dpm = arm->dpm;
913 
914  if (bp->length < 2)
916  if (!dpm->bpwp_enable)
917  return retval;
918 
919  /* FIXME we need a generic solution for software breakpoints. */
920  if (bp->type == BKPT_SOFT)
921  LOG_TARGET_DEBUG(dpm->arm->target, "using HW breakpoint instead of SW");
922 
923  for (unsigned int i = 0; i < dpm->nbp; i++) {
924  if (!dpm->dbp[i].bp) {
925  retval = dpm_bpwp_setup(dpm, &dpm->dbp[i].bpwp,
926  bp->address, bp->length);
927  if (retval == ERROR_OK)
928  dpm->dbp[i].bp = bp;
929  break;
930  }
931  }
932 
933  return retval;
934 }
935 
936 static int dpm_remove_breakpoint(struct target *target, struct breakpoint *bp)
937 {
938  struct arm *arm = target_to_arm(target);
939  struct arm_dpm *dpm = arm->dpm;
940  int retval = ERROR_COMMAND_SYNTAX_ERROR;
941 
942  for (unsigned int i = 0; i < dpm->nbp; i++) {
943  if (dpm->dbp[i].bp == bp) {
944  dpm->dbp[i].bp = NULL;
945  dpm->dbp[i].bpwp.dirty = true;
946 
947  /* hardware is updated in write_dirty_registers() */
948  retval = ERROR_OK;
949  break;
950  }
951  }
952 
953  return retval;
954 }
955 
956 static int dpm_watchpoint_setup(struct arm_dpm *dpm, unsigned int index_t,
957  struct watchpoint *wp)
958 {
959  int retval;
960  struct dpm_wp *dwp = dpm->dwp + index_t;
961  uint32_t control;
962 
963  /* this hardware doesn't support data value matching or masking */
965  LOG_TARGET_ERROR(dpm->arm->target, "watchpoint values and masking not supported");
967  }
968 
969  retval = dpm_bpwp_setup(dpm, &dwp->bpwp, wp->address, wp->length);
970  if (retval != ERROR_OK)
971  return retval;
972 
973  control = dwp->bpwp.control;
974  switch (wp->rw) {
975  case WPT_READ:
976  control |= 1 << 3;
977  break;
978  case WPT_WRITE:
979  control |= 2 << 3;
980  break;
981  case WPT_ACCESS:
982  control |= 3 << 3;
983  break;
984  }
985  dwp->bpwp.control = control;
986 
987  dpm->dwp[index_t].wp = wp;
988 
989  return retval;
990 }
991 
992 static int dpm_add_watchpoint(struct target *target, struct watchpoint *wp)
993 {
994  struct arm *arm = target_to_arm(target);
995  struct arm_dpm *dpm = arm->dpm;
997 
998  if (dpm->bpwp_enable) {
999  for (unsigned int i = 0; i < dpm->nwp; i++) {
1000  if (!dpm->dwp[i].wp) {
1001  retval = dpm_watchpoint_setup(dpm, i, wp);
1002  break;
1003  }
1004  }
1005  }
1006 
1007  return retval;
1008 }
1009 
1010 static int dpm_remove_watchpoint(struct target *target, struct watchpoint *wp)
1011 {
1012  struct arm *arm = target_to_arm(target);
1013  struct arm_dpm *dpm = arm->dpm;
1014  int retval = ERROR_COMMAND_SYNTAX_ERROR;
1015 
1016  for (unsigned int i = 0; i < dpm->nwp; i++) {
1017  if (dpm->dwp[i].wp == wp) {
1018  dpm->dwp[i].wp = NULL;
1019  dpm->dwp[i].bpwp.dirty = true;
1020 
1021  /* hardware is updated in write_dirty_registers() */
1022  retval = ERROR_OK;
1023  break;
1024  }
1025  }
1026 
1027  return retval;
1028 }
1029 
1030 void arm_dpm_report_wfar(struct arm_dpm *dpm, uint32_t addr)
1031 {
1032  switch (dpm->arm->core_state) {
1033  case ARM_STATE_ARM:
1034  addr -= 8;
1035  break;
1036  case ARM_STATE_THUMB:
1037  case ARM_STATE_THUMB_EE:
1038  addr -= 4;
1039  break;
1040  case ARM_STATE_JAZELLE:
1041  case ARM_STATE_AARCH64:
1042  /* ?? */
1043  break;
1044  }
1045  dpm->wp_addr = addr;
1046 }
1047 
1048 /*----------------------------------------------------------------------*/
1049 
1050 /*
1051  * Other debug and support utilities
1052  */
1053 
1054 void arm_dpm_report_dscr(struct arm_dpm *dpm, uint32_t dscr)
1055 {
1056  struct target *target = dpm->arm->target;
1057 
1058  dpm->dscr = dscr;
1059 
1060  /* Examine debug reason */
1061  switch (DSCR_ENTRY(dscr)) {
1062  case DSCR_ENTRY_HALT_REQ: /* HALT request from debugger */
1063  case DSCR_ENTRY_EXT_DBG_REQ: /* EDBGRQ */
1065  break;
1066  case DSCR_ENTRY_BREAKPOINT: /* HW breakpoint */
1067  case DSCR_ENTRY_BKPT_INSTR: /* vector catch */
1069  break;
1070  case DSCR_ENTRY_IMPRECISE_WATCHPT: /* asynch watchpoint */
1071  case DSCR_ENTRY_PRECISE_WATCHPT:/* precise watchpoint */
1073  break;
1074  default:
1076  break;
1077  }
1078 }
1079 
1080 /*----------------------------------------------------------------------*/
1081 
1082 /*
1083  * Setup and management support.
1084  */
1085 
1092 int arm_dpm_setup(struct arm_dpm *dpm)
1093 {
1094  struct arm *arm = dpm->arm;
1095  struct target *target = arm->target;
1096  struct reg_cache *cache = NULL;
1097 
1098  arm->dpm = dpm;
1099 
1100  /* register access setup */
1104 
1105  if (!arm->core_cache) {
1106  cache = arm_build_reg_cache(target, arm);
1107  if (!cache)
1108  return ERROR_FAIL;
1109 
1111  }
1112 
1113  /* coprocessor access setup */
1114  arm->mrc = dpm_mrc;
1115  arm->mcr = dpm_mcr;
1116  arm->mrrc = dpm_mrrc;
1117  arm->mcrr = dpm_mcrr;
1118 
1119  /* breakpoint setup -- optional until it works everywhere */
1120  if (!target->type->add_breakpoint) {
1123  }
1124 
1125  /* watchpoint setup -- optional until it works everywhere */
1126  if (!target->type->add_watchpoint) {
1129  }
1130 
1131  /* FIXME add vector catch support */
1132 
1133  dpm->nbp = 1 + ((dpm->didr >> 24) & 0xf);
1134  dpm->nwp = 1 + ((dpm->didr >> 28) & 0xf);
1135  dpm->dbp = calloc(dpm->nbp, sizeof(*dpm->dbp));
1136  dpm->dwp = calloc(dpm->nwp, sizeof(*dpm->dwp));
1137 
1138  if (!dpm->dbp || !dpm->dwp) {
1140  free(dpm->dbp);
1141  free(dpm->dwp);
1142  return ERROR_FAIL;
1143  }
1144 
1145  LOG_TARGET_INFO(target, "hardware has %d breakpoints, %d watchpoints",
1146  dpm->nbp, dpm->nwp);
1147 
1148  /* REVISIT ... and some of those breakpoints could match
1149  * execution context IDs...
1150  */
1151 
1152  return ERROR_OK;
1153 }
1154 
1159 int arm_dpm_initialize(struct arm_dpm *dpm)
1160 {
1161  /* Disable all breakpoints and watchpoints at startup. */
1162  if (dpm->bpwp_disable) {
1163  unsigned int i;
1164 
1165  for (i = 0; i < dpm->nbp; i++) {
1166  dpm->dbp[i].bpwp.number = i;
1167  (void) dpm->bpwp_disable(dpm, i);
1168  }
1169  for (i = 0; i < dpm->nwp; i++) {
1170  dpm->dwp[i].bpwp.number = 16 + i;
1171  (void) dpm->bpwp_disable(dpm, 16 + i);
1172  }
1173  } else
1174  LOG_TARGET_WARNING(dpm->arm->target, "can't disable breakpoints and watchpoints");
1175 
1176  return ERROR_OK;
1177 }
Holds the interface to ARM cores.
struct reg * arm_reg_current(struct arm *arm, unsigned int regnum)
Returns handle to the register currently mapped to a given number.
Definition: armv4_5.c:516
@ ARM_VFP_V3_D31
Definition: arm.h:142
@ ARM_VFP_V3_FPSCR
Definition: arm.h:143
@ ARM_VFP_V3_D0
Definition: arm.h:111
struct reg_cache * arm_build_reg_cache(struct target *target, struct arm *arm)
Definition: armv4_5.c:660
arm_mode
Represent state of an ARM core.
Definition: arm.h:82
@ ARM_MODE_SYS
Definition: arm.h:92
@ ARM_MODE_FIQ
Definition: arm.h:84
@ ARM_MODE_ANY
Definition: arm.h:106
@ ARM_MODE_USR
Definition: arm.h:83
void arm_free_reg_cache(struct arm *arm)
Definition: armv4_5.c:775
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:261
@ ARM_STATE_JAZELLE
Definition: arm.h:153
@ ARM_STATE_THUMB
Definition: arm.h:152
@ ARM_STATE_ARM
Definition: arm.h:151
@ ARM_STATE_AARCH64
Definition: arm.h:155
@ ARM_STATE_THUMB_EE
Definition: arm.h:154
void arm_set_cpsr(struct arm *arm, uint32_t cpsr)
Configures host-side ARM records to reflect the specified CPSR.
Definition: armv4_5.c:452
void arm_dpm_report_dscr(struct arm_dpm *dpm, uint32_t dscr)
Definition: arm_dpm.c:1054
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_modeswitch(struct arm_dpm *dpm, enum arm_mode mode)
Definition: arm_dpm.c:144
static enum arm_mode dpm_mapmode(struct arm *arm, unsigned int num, enum arm_mode mode)
Definition: arm_dpm.c:644
static int dpm_write_pc_core_state(struct arm_dpm *dpm, struct reg *r)
Write to program counter and switch the core state (arm/thumb) according to the address.
Definition: arm_dpm.c:362
int arm_dpm_setup(struct arm_dpm *dpm)
Hooks up this DPM to its associated target; call only once.
Definition: arm_dpm.c:1092
static int arm_dpm_full_context(struct target *target)
Definition: arm_dpm.c:770
static int dpm_remove_watchpoint(struct target *target, struct watchpoint *wp)
Definition: arm_dpm.c:1010
static int dpm_maybe_update_bpwp(struct arm_dpm *dpm, bool bpwp, struct dpm_bpwp *xp, bool *set_p)
Definition: arm_dpm.c:433
int arm_dpm_read_reg(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
Definition: arm_dpm.c:206
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:484
static int dpm_mcr(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
Definition: arm_dpm.c:88
static int dpm_write_reg_u64(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
Definition: arm_dpm.c:274
static int dpm_write_reg(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
Definition: arm_dpm.c:310
void arm_dpm_report_wfar(struct arm_dpm *dpm, uint32_t addr)
Definition: arm_dpm.c:1030
static int arm_dpm_write_core_reg(struct target *target, struct reg *r, int regnum, enum arm_mode mode, uint8_t *value)
Definition: arm_dpm.c:728
static int dpm_mrrc(struct target *target, int cpnum, uint32_t op, uint32_t crm, uint64_t *value)
Definition: arm_dpm.c:65
static int dpm_mrc(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
Definition: arm_dpm.c:41
static int dpm_mcrr(struct target *target, int cpnum, uint32_t op, uint32_t crm, uint64_t value)
Definition: arm_dpm.c:112
static int arm_dpm_read_core_reg(struct target *target, struct reg *r, int regnum, enum arm_mode mode)
Definition: arm_dpm.c:685
static int dpm_bpwp_setup(struct arm_dpm *dpm, struct dpm_bpwp *xp, uint32_t addr, uint32_t length)
Definition: arm_dpm.c:851
static int dpm_watchpoint_setup(struct arm_dpm *dpm, unsigned int index_t, struct watchpoint *wp)
Definition: arm_dpm.c:956
static int dpm_add_watchpoint(struct target *target, struct watchpoint *wp)
Definition: arm_dpm.c:992
static int dpm_read_reg_u64(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
Definition: arm_dpm.c:168
static int dpm_remove_breakpoint(struct target *target, struct breakpoint *bp)
Definition: arm_dpm.c:936
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:1159
static int dpm_add_breakpoint(struct target *target, struct breakpoint *bp)
Definition: arm_dpm.c:908
This is the interface to the Debug Programmers Model for ARMv6 and ARMv7 processors.
#define DSCR_ENTRY_BKPT_INSTR
Definition: arm_dpm.h:205
#define DSCR_ENTRY_IMPRECISE_WATCHPT
Definition: arm_dpm.h:204
#define DSCR_ENTRY(dscr)
Definition: arm_dpm.h:197
#define DSCR_ENTRY_PRECISE_WATCHPT
Definition: arm_dpm.h:211
#define DSCR_ENTRY_EXT_DBG_REQ
Definition: arm_dpm.h:206
#define DSCR_ENTRY_BREAKPOINT
Definition: arm_dpm.h:203
#define DSCR_ENTRY_HALT_REQ
Definition: arm_dpm.h:202
Macros used to generate various ARM or Thumb opcodes.
#define ARMV5_T_MCRR(cp, op, rt, rt2, crm)
Definition: arm_opcodes.h:220
#define ARMV4_5_BX(rm)
Definition: arm_opcodes.h:122
#define ARMV4_5_VMSR(rt)
Definition: arm_opcodes.h:146
#define ARMV5_T_MRRC(cp, op, rt, rt2, crm)
Definition: arm_opcodes.h:197
#define ARMV4_5_MRC(cp, op1, rd, crn, crm, op2)
Definition: arm_opcodes.h:186
#define ARMV4_5_MRS(rn, r)
Definition: arm_opcodes.h:52
#define ARMV4_5_MCR(cp, op1, rd, crn, crm, op2)
Definition: arm_opcodes.h:209
#define ARMV4_5_VMOV(op, rt2, rt, m, vm)
Definition: arm_opcodes.h:134
#define ARMV4_5_VMRS(rt)
Definition: arm_opcodes.h:141
#define ARMV4_5_MSR_GP(rm, field, r)
Definition: arm_opcodes.h:72
enum arm_mode mode
Definition: armv4_5.c:281
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 WATCHPOINT_IGNORE_DATA_VALUE_MASK
Definition: breakpoints.h:39
@ WPT_ACCESS
Definition: breakpoints.h:23
@ WPT_READ
Definition: breakpoints.h:23
@ WPT_WRITE
Definition: breakpoints.h:23
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:400
uint8_t length
Definition: esp_usb_jtag.c:1
The JTAG interface can be implemented with a software or hardware fifo.
uint64_t op
Definition: lakemont.c:68
#define LOG_TARGET_INFO(target, fmt_str,...)
Definition: log.h:153
#define LOG_TARGET_WARNING(target, fmt_str,...)
Definition: log.h:159
#define ERROR_FAIL
Definition: log.h:174
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:162
#define LOG_TARGET_DEBUG(target, fmt_str,...)
Definition: log.h:150
#define ERROR_OK
Definition: log.h:168
struct reg_cache ** register_get_last_cache_p(struct reg_cache **first)
Definition: register.c:72
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
This wraps an implementation of DPM primitives.
Definition: arm_dpm.h:47
target_addr_t wp_addr
Target dependent watchpoint address.
Definition: arm_dpm.h:147
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
int(* instr_read_data_r0_r1)(struct arm_dpm *dpm, uint32_t opcode, uint64_t *data)
Runs two instructions, reading data from r0 and r1 after execution.
Definition: arm_dpm.h:105
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
int(* instr_cpsr_sync)(struct arm_dpm *dpm)
Optional core-specific operation invoked after CPSR writes.
Definition: arm_dpm.h:86
int(* instr_write_data_r0_r1)(struct arm_dpm *dpm, uint32_t opcode, uint64_t data)
Runs two instructions, writing data to R0 and R1 before execution.
Definition: arm_dpm.h:78
uint32_t dscr
Recent value of DSCR.
Definition: arm_dpm.h:150
Definition: arm.h:280
int num
Definition: arm.h:281
enum arm_mode mode
Definition: arm.h:282
Represents a generic ARM core, with standard application registers.
Definition: arm.h:175
int(* full_context)(struct target *target)
Retrieve all core registers, for display.
Definition: arm.h:221
int(* mrrc)(struct target *target, int cpnum, uint32_t op, uint32_t crm, uint64_t *value)
Read coprocessor to two registers.
Definition: arm.h:236
int(* mrc)(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
Read coprocessor register.
Definition: arm.h:230
enum arm_mode core_mode
Record the current core mode: SVC, USR, or some other mode.
Definition: arm.h:196
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
Definition: arm.h:184
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:181
int(* write_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode, uint8_t *value)
Definition: arm.h:226
int(* mcrr)(struct target *target, int cpnum, uint32_t op, uint32_t crm, uint64_t value)
Write coprocessor from two registers.
Definition: arm.h:247
int(* read_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode)
Retrieve a single core register.
Definition: arm.h:224
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
int(* mcr)(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
Write coprocessor register.
Definition: arm.h:241
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
unsigned int length
Definition: breakpoints.h:29
enum breakpoint_type type
Definition: breakpoints.h:30
bool is_set
Definition: breakpoints.h:31
target_addr_t address
Definition: breakpoints.h:27
Definition: arm_dpm.h:29
struct dpm_bpwp bpwp
Definition: arm_dpm.h:31
struct breakpoint * bp
Definition: arm_dpm.h:30
uint32_t control
Definition: arm_dpm.h:24
unsigned int number
Definition: arm_dpm.h:22
bool dirty
Definition: arm_dpm.h:26
uint32_t address
Definition: arm_dpm.h:23
Definition: arm_dpm.h:34
struct watchpoint * wp
Definition: arm_dpm.h:35
struct dpm_bpwp bpwp
Definition: arm_dpm.h:36
unsigned int num_regs
Definition: register.h:148
struct reg * reg_list
Definition: register.h:147
Definition: register.h:111
bool valid
Definition: register.h:126
bool exist
Definition: register.h:128
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
int(* add_breakpoint)(struct target *target, struct breakpoint *breakpoint)
Definition: target_type.h:153
int(* add_watchpoint)(struct target *target, struct watchpoint *watchpoint)
Definition: target_type.h:164
int(* remove_breakpoint)(struct target *target, struct breakpoint *breakpoint)
Definition: target_type.h:161
int(* remove_watchpoint)(struct target *target, struct watchpoint *watchpoint)
Definition: target_type.h:170
Definition: target.h:119
enum target_debug_reason debug_reason
Definition: target.h:157
struct reg_cache * reg_cache
Definition: target.h:161
struct target_type * type
Definition: target.h:120
uint64_t mask
Definition: breakpoints.h:44
enum watchpoint_rw rw
Definition: breakpoints.h:46
bool is_set
Definition: breakpoints.h:47
unsigned int length
Definition: breakpoints.h:43
target_addr_t address
Definition: breakpoints.h:42
@ DBG_REASON_UNDEFINED
Definition: target.h:80
@ DBG_REASON_DBGRQ
Definition: target.h:72
@ DBG_REASON_WATCHPOINT
Definition: target.h:74
@ DBG_REASON_BREAKPOINT
Definition: target.h:73
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:790
#define NULL
Definition: usb.h:16