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