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_DEBUG("MRC p%d, %d, r0, c%d, c%d, %d", cpnum,
54  (int) op1, (int) crn,
55  (int) crm, (int) op2);
56 
57  /* read coprocessor register into R0; return via DCC */
58  retval = dpm->instr_read_data_r0(dpm,
59  ARMV4_5_MRC(cpnum, op1, 0, crn, crm, op2),
60  value);
61 
62  dpm->finish(dpm);
63  return retval;
64 }
65 
66 static int dpm_mrrc(struct target *target, int cpnum,
67  uint32_t op, uint32_t crm, uint64_t *value)
68 {
69  struct arm *arm = target_to_arm(target);
70  struct arm_dpm *dpm = arm->dpm;
71  int retval;
72 
73  retval = dpm->prepare(dpm);
74  if (retval != ERROR_OK)
75  return retval;
76 
77  LOG_DEBUG("MRRC p%d, %d, r0, r1, c%d", cpnum,
78  (int)op, (int)crm);
79 
80  /* read coprocessor register into R0, R1; return via DCC */
81  retval = dpm->instr_read_data_r0_r1(dpm,
82  ARMV5_T_MRRC(cpnum, op, 0, 1, crm),
83  value);
84 
85  dpm->finish(dpm);
86  return retval;
87 }
88 
89 static int dpm_mcr(struct target *target, int cpnum,
90  uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm,
91  uint32_t value)
92 {
93  struct arm *arm = target_to_arm(target);
94  struct arm_dpm *dpm = arm->dpm;
95  int retval;
96 
97  retval = dpm->prepare(dpm);
98  if (retval != ERROR_OK)
99  return retval;
100 
101  LOG_DEBUG("MCR p%d, %d, r0, c%d, c%d, %d", cpnum,
102  (int) op1, (int) crn,
103  (int) crm, (int) op2);
104 
105  /* read DCC into r0; then write coprocessor register from R0 */
106  retval = dpm->instr_write_data_r0(dpm,
107  ARMV4_5_MCR(cpnum, op1, 0, crn, crm, op2),
108  value);
109 
110  dpm->finish(dpm);
111  return retval;
112 }
113 
114 static int dpm_mcrr(struct target *target, int cpnum,
115  uint32_t op, uint32_t crm, uint64_t value)
116 {
117  struct arm *arm = target_to_arm(target);
118  struct arm_dpm *dpm = arm->dpm;
119  int retval;
120 
121  retval = dpm->prepare(dpm);
122  if (retval != ERROR_OK)
123  return retval;
124 
125  LOG_DEBUG("MCRR p%d, %d, r0, r1, c%d", cpnum,
126  (int)op, (int)crm);
127 
128  /* read DCC into r0, r1; then write coprocessor register from R0, R1 */
129  retval = dpm->instr_write_data_r0_r1(dpm,
130  ARMV5_T_MCRR(cpnum, op, 0, 1, crm), value);
131 
132  dpm->finish(dpm);
133 
134  return retval;
135 }
136 
137 /*----------------------------------------------------------------------*/
138 
139 /*
140  * Register access utilities
141  */
142 
143 /* Toggles between recorded core mode (USR, SVC, etc) and a temporary one.
144  * Routines *must* restore the original mode before returning!!
145  */
146 int arm_dpm_modeswitch(struct arm_dpm *dpm, enum arm_mode mode)
147 {
148  int retval;
149  uint32_t cpsr;
150 
151  /* restore previous mode */
152  if (mode == ARM_MODE_ANY)
153  cpsr = buf_get_u32(dpm->arm->cpsr->value, 0, 32);
154 
155  /* else force to the specified mode */
156  else
157  cpsr = mode;
158 
159  retval = dpm->instr_write_data_r0(dpm, ARMV4_5_MSR_GP(0, 0xf, 0), cpsr);
160  if (retval != ERROR_OK)
161  return retval;
162 
163  if (dpm->instr_cpsr_sync)
164  retval = dpm->instr_cpsr_sync(dpm);
165 
166  return retval;
167 }
168 
169 /* Read 64bit VFP registers */
170 static int dpm_read_reg_u64(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
171 {
172  int retval = ERROR_FAIL;
173  uint32_t value_r0, value_r1;
174 
175  switch (regnum) {
176  case ARM_VFP_V3_D0 ... ARM_VFP_V3_D31:
177  /* move from double word register to r0:r1: "vmov r0, r1, vm"
178  * then read r0 via dcc
179  */
180  retval = dpm->instr_read_data_r0(dpm,
181  ARMV4_5_VMOV(1, 1, 0, ((regnum - ARM_VFP_V3_D0) >> 4),
182  ((regnum - ARM_VFP_V3_D0) & 0xf)), &value_r0);
183  if (retval != ERROR_OK)
184  break;
185 
186  /* read r1 via dcc */
187  retval = dpm->instr_read_data_dcc(dpm,
188  ARMV4_5_MCR(14, 0, 1, 0, 5, 0),
189  &value_r1);
190  break;
191  default:
192 
193  break;
194  }
195 
196  if (retval == ERROR_OK) {
197  buf_set_u32(r->value, 0, 32, value_r0);
198  buf_set_u32(r->value + 4, 0, 32, value_r1);
199  r->valid = true;
200  r->dirty = false;
201  LOG_DEBUG("READ: %s, %8.8" PRIx32 ", %8.8" PRIx32, r->name, value_r0, value_r1);
202  }
203 
204  return retval;
205 }
206 
207 /* just read the register -- rely on the core mode being right */
208 int arm_dpm_read_reg(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
209 {
210  uint32_t value;
211  int retval;
212 
213  switch (regnum) {
214  case 0 ... 14:
215  /* return via DCC: "MCR p14, 0, Rnum, c0, c5, 0" */
216  retval = dpm->instr_read_data_dcc(dpm,
217  ARMV4_5_MCR(14, 0, regnum, 0, 5, 0),
218  &value);
219  break;
220  case 15:/* PC
221  * "MOV r0, pc"; then return via DCC */
222  retval = dpm->instr_read_data_r0(dpm, 0xe1a0000f, &value);
223 
224  /* NOTE: this seems like a slightly awkward place to update
225  * this value ... but if the PC gets written (the only way
226  * to change what we compute), the arch spec says subsequent
227  * reads return values which are "unpredictable". So this
228  * is always right except in those broken-by-intent cases.
229  */
230  switch (dpm->arm->core_state) {
231  case ARM_STATE_ARM:
232  value -= 8;
233  break;
234  case ARM_STATE_THUMB:
235  case ARM_STATE_THUMB_EE:
236  value -= 4;
237  break;
238  case ARM_STATE_JAZELLE:
239  /* core-specific ... ? */
240  LOG_WARNING("Jazelle PC adjustment unknown");
241  break;
242  default:
243  LOG_WARNING("unknown core state");
244  break;
245  }
246  break;
247  case ARM_VFP_V3_D0 ... ARM_VFP_V3_D31:
248  return dpm_read_reg_u64(dpm, r, regnum);
249  case ARM_VFP_V3_FPSCR:
250  /* "VMRS r0, FPSCR"; then return via DCC */
251  retval = dpm->instr_read_data_r0(dpm,
252  ARMV4_5_VMRS(0), &value);
253  break;
254  default:
255  /* 16: "MRS r0, CPSR"; then return via DCC
256  * 17: "MRS r0, SPSR"; then return via DCC
257  */
258  retval = dpm->instr_read_data_r0(dpm,
259  ARMV4_5_MRS(0, regnum & 1),
260  &value);
261  break;
262  }
263 
264  if (retval == ERROR_OK) {
265  buf_set_u32(r->value, 0, 32, value);
266  r->valid = true;
267  r->dirty = false;
268  LOG_DEBUG("READ: %s, %8.8" PRIx32, r->name, 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_DEBUG("WRITE: %s, %8.8" PRIx32 ", %8.8" PRIx32, r->name, value_r0, value_r1);
305  }
306 
307  return retval;
308 }
309 
310 /* just write the register -- rely on the core mode being right */
311 static int dpm_write_reg(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
312 {
313  int retval;
314  uint32_t value = buf_get_u32(r->value, 0, 32);
315 
316  switch (regnum) {
317  case 0 ... 14:
318  /* load register from DCC: "MRC p14, 0, Rnum, c0, c5, 0" */
319  retval = dpm->instr_write_data_dcc(dpm,
320  ARMV4_5_MRC(14, 0, regnum, 0, 5, 0),
321  value);
322  break;
323  case 15:/* PC
324  * read r0 from DCC; then "MOV pc, r0" */
325  retval = dpm->instr_write_data_r0(dpm, 0xe1a0f000, value);
326  break;
327  case ARM_VFP_V3_D0 ... ARM_VFP_V3_D31:
328  return dpm_write_reg_u64(dpm, r, regnum);
329  case ARM_VFP_V3_FPSCR:
330  /* move to r0 from DCC, then "VMSR FPSCR, r0" */
331  retval = dpm->instr_write_data_r0(dpm,
332  ARMV4_5_VMSR(0), value);
333  break;
334  default:
335  /* 16: read r0 from DCC, then "MSR r0, CPSR_cxsf"
336  * 17: read r0 from DCC, then "MSR r0, SPSR_cxsf"
337  */
338  retval = dpm->instr_write_data_r0(dpm,
339  ARMV4_5_MSR_GP(0, 0xf, regnum & 1),
340  value);
341  if (retval != ERROR_OK)
342  return retval;
343 
344  if (regnum == 16 && dpm->instr_cpsr_sync)
345  retval = dpm->instr_cpsr_sync(dpm);
346 
347  break;
348  }
349 
350  if (retval == ERROR_OK) {
351  r->dirty = false;
352  LOG_DEBUG("WRITE: %s, %8.8" PRIx32, r->name, 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_ERROR("%s: can't %s HW %spoint %d",
467  disable ? "disable" : "enable",
468  target_name(dpm->arm->target),
469  (xp->number < 16) ? "break" : "watch",
470  xp->number & 0xf);
471 done:
472  return retval;
473 }
474 
475 static int dpm_add_breakpoint(struct target *target, struct breakpoint *bp);
476 
485 int arm_dpm_write_dirty_registers(struct arm_dpm *dpm, bool bpwp)
486 {
487  struct arm *arm = dpm->arm;
488  struct reg_cache *cache = arm->core_cache;
489  int retval;
490  bool did_write;
491 
492  retval = dpm->prepare(dpm);
493  if (retval != ERROR_OK)
494  goto done;
495 
496  /* If we're managing hardware breakpoints for this core, enable
497  * or disable them as requested.
498  *
499  * REVISIT We don't yet manage them for ANY cores. Eventually
500  * we should be able to assume we handle them; but until then,
501  * cope with the hand-crafted breakpoint code.
502  */
504  for (unsigned int i = 0; i < dpm->nbp; i++) {
505  struct dpm_bp *dbp = dpm->dbp + i;
506  struct breakpoint *bp = dbp->bp;
507 
508  retval = dpm_maybe_update_bpwp(dpm, bpwp, &dbp->bpwp,
509  bp ? &bp->is_set : NULL);
510  if (retval != ERROR_OK)
511  goto done;
512  }
513  }
514 
515  /* enable/disable watchpoints */
516  for (unsigned int i = 0; i < dpm->nwp; i++) {
517  struct dpm_wp *dwp = dpm->dwp + i;
518  struct watchpoint *wp = dwp->wp;
519 
520  retval = dpm_maybe_update_bpwp(dpm, bpwp, &dwp->bpwp,
521  wp ? &wp->is_set : NULL);
522  if (retval != ERROR_OK)
523  goto done;
524  }
525 
526  /* NOTE: writes to breakpoint and watchpoint registers might
527  * be queued, and need (efficient/batched) flushing later.
528  */
529 
530  /* Scan the registers until we find one that's both dirty and
531  * eligible for flushing. Flush that and everything else that
532  * shares the same core mode setting. Typically this won't
533  * actually find anything to do...
534  */
535  do {
536  enum arm_mode mode = ARM_MODE_ANY;
537 
538  did_write = false;
539 
540  /* check everything except our scratch registers R0 and R1 */
541  for (unsigned int i = 2; i < cache->num_regs; i++) {
542  struct arm_reg *r;
543  unsigned int regnum;
544 
545  /* also skip PC, CPSR, and non-dirty */
546  if (i == 15)
547  continue;
548  if (arm->cpsr == cache->reg_list + i)
549  continue;
550  if (!cache->reg_list[i].exist || !cache->reg_list[i].dirty)
551  continue;
552 
553  r = cache->reg_list[i].arch_info;
554  regnum = r->num;
555 
556  /* may need to pick and set a mode */
557  if (!did_write) {
558  enum arm_mode tmode;
559 
560  did_write = true;
561  mode = tmode = r->mode;
562 
563  /* cope with special cases */
564  switch (regnum) {
565  case 8 ... 12:
566  /* r8..r12 "anything but FIQ" case;
567  * we "know" core mode is accurate
568  * since we haven't changed it yet
569  */
570  if (arm->core_mode == ARM_MODE_FIQ
571  && ARM_MODE_ANY
572  != mode)
573  tmode = ARM_MODE_USR;
574  break;
575  case 16:
576  /* SPSR */
577  regnum++;
578  break;
579  }
580 
581  /* REVISIT error checks */
582  if (tmode != ARM_MODE_ANY) {
583  retval = arm_dpm_modeswitch(dpm, tmode);
584  if (retval != ERROR_OK)
585  goto done;
586  }
587  }
588  if (r->mode != mode)
589  continue;
590 
591  retval = dpm_write_reg(dpm,
592  &cache->reg_list[i],
593  regnum);
594  if (retval != ERROR_OK)
595  goto done;
596  }
597 
598  } while (did_write);
599 
600  /* Restore original CPSR ... assuming either that we changed it,
601  * or it's dirty. Must write PC to ensure the return address is
602  * defined, and must not write it before CPSR.
603  */
604  retval = arm_dpm_modeswitch(dpm, ARM_MODE_ANY);
605  if (retval != ERROR_OK)
606  goto done;
607  arm->cpsr->dirty = false;
608 
609  /* restore the PC, make sure to also switch the core state
610  * to whatever it was set to with "arm core_state" command.
611  * target code will have set PC to an appropriate resume address.
612  */
613  retval = dpm_write_pc_core_state(dpm, arm->pc);
614  if (retval != ERROR_OK)
615  goto done;
616  /* on Cortex-A5 (as found on NXP VF610 SoC), BX instruction
617  * executed in debug state doesn't appear to set the PC,
618  * explicitly set it with a "MOV pc, r0". This doesn't influence
619  * CPSR on Cortex-A9 so it should be OK. Maybe due to different
620  * debug version?
621  */
622  retval = dpm_write_reg(dpm, arm->pc, 15);
623  if (retval != ERROR_OK)
624  goto done;
625  arm->pc->dirty = false;
626 
627  /* flush R0 and R1 (our scratch registers) */
628  for (unsigned int i = 0; i < 2; i++) {
629  retval = dpm_write_reg(dpm, &cache->reg_list[i], i);
630  if (retval != ERROR_OK)
631  goto done;
632  cache->reg_list[i].dirty = false;
633  }
634 
635  dpm->finish(dpm);
636 done:
637  return retval;
638 }
639 
640 /* Returns ARM_MODE_ANY or temporary mode to use while reading the
641  * specified register ... works around flakiness from ARM core calls.
642  * Caller already filtered out SPSR access; mode is never MODE_SYS
643  * or MODE_ANY.
644  */
645 static enum arm_mode dpm_mapmode(struct arm *arm,
646  unsigned int num, enum arm_mode mode)
647 {
648  enum arm_mode amode = arm->core_mode;
649 
650  /* don't switch if the mode is already correct */
651  if (amode == ARM_MODE_SYS)
652  amode = ARM_MODE_USR;
653  if (mode == amode)
654  return ARM_MODE_ANY;
655 
656  switch (num) {
657  /* don't switch for non-shadowed registers (r0..r7, r15/pc, cpsr) */
658  case 0 ... 7:
659  case 15:
660  case 16:
661  break;
662  /* r8..r12 aren't shadowed for anything except FIQ */
663  case 8 ... 12:
664  if (mode == ARM_MODE_FIQ)
665  return mode;
666  break;
667  /* r13/sp, and r14/lr are always shadowed */
668  case 13:
669  case 14:
671  return mode;
672  default:
673  LOG_WARNING("invalid register #%u", num);
674  break;
675  }
676  return ARM_MODE_ANY;
677 }
678 
679 
680 /*
681  * Standard ARM register accessors ... there are three methods
682  * in "struct arm", to support individual read/write and bulk read
683  * of registers.
684  */
685 
686 static int arm_dpm_read_core_reg(struct target *target, struct reg *r,
687  int regnum, enum arm_mode mode)
688 {
689  struct arm_dpm *dpm = target_to_arm(target)->dpm;
690  int retval;
691 
692  if (regnum < 0 || (regnum > 16 && regnum < ARM_VFP_V3_D0) ||
693  (regnum > ARM_VFP_V3_FPSCR))
695 
696  if (regnum == 16) {
697  if (mode != ARM_MODE_ANY)
698  regnum = 17;
699  } else
700  mode = dpm_mapmode(dpm->arm, regnum, mode);
701 
702  /* REVISIT what happens if we try to read SPSR in a core mode
703  * which has no such register?
704  */
705 
706  retval = dpm->prepare(dpm);
707  if (retval != ERROR_OK)
708  return retval;
709 
710  if (mode != ARM_MODE_ANY) {
711  retval = arm_dpm_modeswitch(dpm, mode);
712  if (retval != ERROR_OK)
713  goto fail;
714  }
715 
716  retval = arm_dpm_read_reg(dpm, r, regnum);
717  if (retval != ERROR_OK)
718  goto fail;
719  /* always clean up, regardless of error */
720 
721  if (mode != ARM_MODE_ANY)
723 
724 fail:
725  dpm->finish(dpm);
726  return retval;
727 }
728 
729 static int arm_dpm_write_core_reg(struct target *target, struct reg *r,
730  int regnum, enum arm_mode mode, uint8_t *value)
731 {
732  struct arm_dpm *dpm = target_to_arm(target)->dpm;
733  int retval;
734 
735 
736  if (regnum < 0 || (regnum > 16 && regnum < ARM_VFP_V3_D0) ||
737  (regnum > ARM_VFP_V3_FPSCR))
739 
740  if (regnum == 16) {
741  if (mode != ARM_MODE_ANY)
742  regnum = 17;
743  } else
744  mode = dpm_mapmode(dpm->arm, regnum, mode);
745 
746  /* REVISIT what happens if we try to write SPSR in a core mode
747  * which has no such register?
748  */
749 
750  retval = dpm->prepare(dpm);
751  if (retval != ERROR_OK)
752  return retval;
753 
754  if (mode != ARM_MODE_ANY) {
755  retval = arm_dpm_modeswitch(dpm, mode);
756  if (retval != ERROR_OK)
757  goto fail;
758  }
759 
760  retval = dpm_write_reg(dpm, r, regnum);
761  /* always clean up, regardless of error */
762 
763  if (mode != ARM_MODE_ANY)
765 
766 fail:
767  dpm->finish(dpm);
768  return retval;
769 }
770 
771 static int arm_dpm_full_context(struct target *target)
772 {
773  struct arm *arm = target_to_arm(target);
774  struct arm_dpm *dpm = arm->dpm;
775  struct reg_cache *cache = arm->core_cache;
776  int retval;
777  bool did_read;
778 
779  retval = dpm->prepare(dpm);
780  if (retval != ERROR_OK)
781  goto done;
782 
783  do {
784  enum arm_mode mode = ARM_MODE_ANY;
785 
786  did_read = false;
787 
788  /* We "know" arm_dpm_read_current_registers() was called so
789  * the unmapped registers (R0..R7, PC, AND CPSR) and some
790  * view of R8..R14 are current. We also "know" oddities of
791  * register mapping: special cases for R8..R12 and SPSR.
792  *
793  * Pick some mode with unread registers and read them all.
794  * Repeat until done.
795  */
796  for (unsigned int i = 0; i < cache->num_regs; i++) {
797  struct arm_reg *r;
798 
799  if (!cache->reg_list[i].exist || cache->reg_list[i].valid)
800  continue;
801  r = cache->reg_list[i].arch_info;
802 
803  /* may need to pick a mode and set CPSR */
804  if (!did_read) {
805  did_read = true;
806  mode = r->mode;
807 
808  /* For regular (ARM_MODE_ANY) R8..R12
809  * in case we've entered debug state
810  * in FIQ mode we need to patch mode.
811  */
812  if (mode != ARM_MODE_ANY)
813  retval = arm_dpm_modeswitch(dpm, mode);
814  else
815  retval = arm_dpm_modeswitch(dpm, ARM_MODE_USR);
816 
817  if (retval != ERROR_OK)
818  goto done;
819  }
820  if (r->mode != mode)
821  continue;
822 
823  /* CPSR was read, so "R16" must mean SPSR */
824  retval = arm_dpm_read_reg(dpm,
825  &cache->reg_list[i],
826  (r->num == 16) ? 17 : r->num);
827  if (retval != ERROR_OK)
828  goto done;
829  }
830 
831  } while (did_read);
832 
833  retval = arm_dpm_modeswitch(dpm, ARM_MODE_ANY);
834  dpm->finish(dpm);
835 done:
836  return retval;
837 }
838 
839 
840 /*----------------------------------------------------------------------*/
841 
842 /*
843  * Breakpoint and Watchpoint support.
844  *
845  * Hardware {break,watch}points are usually left active, to minimize
846  * debug entry/exit costs. When they are set or cleared, it's done in
847  * batches. Also, DPM-conformant hardware can update debug registers
848  * regardless of whether the CPU is running or halted ... though that
849  * fact isn't currently leveraged.
850  */
851 
852 static int dpm_bpwp_setup(struct arm_dpm *dpm, struct dpm_bpwp *xp,
853  uint32_t addr, uint32_t length)
854 {
855  uint32_t control;
856 
857  control = (1 << 0) /* enable */
858  | (3 << 1); /* both user and privileged access */
859 
860  /* Match 1, 2, or all 4 byte addresses in this word.
861  *
862  * FIXME: v7 hardware allows lengths up to 2 GB for BP and WP.
863  * Support larger length, when addr is suitably aligned. In
864  * particular, allow watchpoints on 8 byte "double" values.
865  *
866  * REVISIT allow watchpoints on unaligned 2-bit values; and on
867  * v7 hardware, unaligned 4-byte ones too.
868  */
869  switch (length) {
870  case 1:
871  control |= (1 << (addr & 3)) << 5;
872  break;
873  case 2:
874  /* require 2-byte alignment */
875  if (!(addr & 1)) {
876  control |= (3 << (addr & 2)) << 5;
877  break;
878  }
879  /* FALL THROUGH */
880  case 4:
881  /* require 4-byte alignment */
882  if (!(addr & 3)) {
883  control |= 0xf << 5;
884  break;
885  }
886  /* FALL THROUGH */
887  default:
888  LOG_ERROR("unsupported {break,watch}point length/alignment");
890  }
891 
892  /* other shared control bits:
893  * bits 15:14 == 0 ... both secure and nonsecure states (v6.1+ only)
894  * bit 20 == 0 ... not linked to a context ID
895  * bit 28:24 == 0 ... not ignoring N LSBs (v7 only)
896  */
897 
898  xp->address = addr & ~3;
899  xp->control = control;
900  xp->dirty = true;
901 
902  LOG_DEBUG("BPWP: addr %8.8" PRIx32 ", control %" PRIx32 ", number %d",
903  xp->address, control, xp->number);
904 
905  /* hardware is updated in write_dirty_registers() */
906  return ERROR_OK;
907 }
908 
909 static int dpm_add_breakpoint(struct target *target, struct breakpoint *bp)
910 {
911  struct arm *arm = target_to_arm(target);
912  struct arm_dpm *dpm = arm->dpm;
914 
915  if (bp->length < 2)
917  if (!dpm->bpwp_enable)
918  return retval;
919 
920  /* FIXME we need a generic solution for software breakpoints. */
921  if (bp->type == BKPT_SOFT)
922  LOG_DEBUG("using HW bkpt, not SW...");
923 
924  for (unsigned int i = 0; i < dpm->nbp; i++) {
925  if (!dpm->dbp[i].bp) {
926  retval = dpm_bpwp_setup(dpm, &dpm->dbp[i].bpwp,
927  bp->address, bp->length);
928  if (retval == ERROR_OK)
929  dpm->dbp[i].bp = bp;
930  break;
931  }
932  }
933 
934  return retval;
935 }
936 
937 static int dpm_remove_breakpoint(struct target *target, struct breakpoint *bp)
938 {
939  struct arm *arm = target_to_arm(target);
940  struct arm_dpm *dpm = arm->dpm;
941  int retval = ERROR_COMMAND_SYNTAX_ERROR;
942 
943  for (unsigned int i = 0; i < dpm->nbp; i++) {
944  if (dpm->dbp[i].bp == bp) {
945  dpm->dbp[i].bp = NULL;
946  dpm->dbp[i].bpwp.dirty = true;
947 
948  /* hardware is updated in write_dirty_registers() */
949  retval = ERROR_OK;
950  break;
951  }
952  }
953 
954  return retval;
955 }
956 
957 static int dpm_watchpoint_setup(struct arm_dpm *dpm, unsigned int index_t,
958  struct watchpoint *wp)
959 {
960  int retval;
961  struct dpm_wp *dwp = dpm->dwp + index_t;
962  uint32_t control;
963 
964  /* this hardware doesn't support data value matching or masking */
966  LOG_DEBUG("watchpoint values and masking not supported");
968  }
969 
970  retval = dpm_bpwp_setup(dpm, &dwp->bpwp, wp->address, wp->length);
971  if (retval != ERROR_OK)
972  return retval;
973 
974  control = dwp->bpwp.control;
975  switch (wp->rw) {
976  case WPT_READ:
977  control |= 1 << 3;
978  break;
979  case WPT_WRITE:
980  control |= 2 << 3;
981  break;
982  case WPT_ACCESS:
983  control |= 3 << 3;
984  break;
985  }
986  dwp->bpwp.control = control;
987 
988  dpm->dwp[index_t].wp = wp;
989 
990  return retval;
991 }
992 
993 static int dpm_add_watchpoint(struct target *target, struct watchpoint *wp)
994 {
995  struct arm *arm = target_to_arm(target);
996  struct arm_dpm *dpm = arm->dpm;
998 
999  if (dpm->bpwp_enable) {
1000  for (unsigned int i = 0; i < dpm->nwp; i++) {
1001  if (!dpm->dwp[i].wp) {
1002  retval = dpm_watchpoint_setup(dpm, i, wp);
1003  break;
1004  }
1005  }
1006  }
1007 
1008  return retval;
1009 }
1010 
1011 static int dpm_remove_watchpoint(struct target *target, struct watchpoint *wp)
1012 {
1013  struct arm *arm = target_to_arm(target);
1014  struct arm_dpm *dpm = arm->dpm;
1015  int retval = ERROR_COMMAND_SYNTAX_ERROR;
1016 
1017  for (unsigned int i = 0; i < dpm->nwp; i++) {
1018  if (dpm->dwp[i].wp == wp) {
1019  dpm->dwp[i].wp = NULL;
1020  dpm->dwp[i].bpwp.dirty = true;
1021 
1022  /* hardware is updated in write_dirty_registers() */
1023  retval = ERROR_OK;
1024  break;
1025  }
1026  }
1027 
1028  return retval;
1029 }
1030 
1031 void arm_dpm_report_wfar(struct arm_dpm *dpm, uint32_t addr)
1032 {
1033  switch (dpm->arm->core_state) {
1034  case ARM_STATE_ARM:
1035  addr -= 8;
1036  break;
1037  case ARM_STATE_THUMB:
1038  case ARM_STATE_THUMB_EE:
1039  addr -= 4;
1040  break;
1041  case ARM_STATE_JAZELLE:
1042  case ARM_STATE_AARCH64:
1043  /* ?? */
1044  break;
1045  }
1046  dpm->wp_addr = addr;
1047 }
1048 
1049 /*----------------------------------------------------------------------*/
1050 
1051 /*
1052  * Other debug and support utilities
1053  */
1054 
1055 void arm_dpm_report_dscr(struct arm_dpm *dpm, uint32_t dscr)
1056 {
1057  struct target *target = dpm->arm->target;
1058 
1059  dpm->dscr = dscr;
1060 
1061  /* Examine debug reason */
1062  switch (DSCR_ENTRY(dscr)) {
1063  case DSCR_ENTRY_HALT_REQ: /* HALT request from debugger */
1064  case DSCR_ENTRY_EXT_DBG_REQ: /* EDBGRQ */
1066  break;
1067  case DSCR_ENTRY_BREAKPOINT: /* HW breakpoint */
1068  case DSCR_ENTRY_BKPT_INSTR: /* vector catch */
1070  break;
1071  case DSCR_ENTRY_IMPRECISE_WATCHPT: /* asynch watchpoint */
1072  case DSCR_ENTRY_PRECISE_WATCHPT:/* precise watchpoint */
1074  break;
1075  default:
1077  break;
1078  }
1079 }
1080 
1081 /*----------------------------------------------------------------------*/
1082 
1083 /*
1084  * Setup and management support.
1085  */
1086 
1093 int arm_dpm_setup(struct arm_dpm *dpm)
1094 {
1095  struct arm *arm = dpm->arm;
1096  struct target *target = arm->target;
1097  struct reg_cache *cache = NULL;
1098 
1099  arm->dpm = dpm;
1100 
1101  /* register access setup */
1105 
1106  if (!arm->core_cache) {
1107  cache = arm_build_reg_cache(target, arm);
1108  if (!cache)
1109  return ERROR_FAIL;
1110 
1112  }
1113 
1114  /* coprocessor access setup */
1115  arm->mrc = dpm_mrc;
1116  arm->mcr = dpm_mcr;
1117  arm->mrrc = dpm_mrrc;
1118  arm->mcrr = dpm_mcrr;
1119 
1120  /* breakpoint setup -- optional until it works everywhere */
1121  if (!target->type->add_breakpoint) {
1124  }
1125 
1126  /* watchpoint setup -- optional until it works everywhere */
1127  if (!target->type->add_watchpoint) {
1130  }
1131 
1132  /* FIXME add vector catch support */
1133 
1134  dpm->nbp = 1 + ((dpm->didr >> 24) & 0xf);
1135  dpm->nwp = 1 + ((dpm->didr >> 28) & 0xf);
1136  dpm->dbp = calloc(dpm->nbp, sizeof(*dpm->dbp));
1137  dpm->dwp = calloc(dpm->nwp, sizeof(*dpm->dwp));
1138 
1139  if (!dpm->dbp || !dpm->dwp) {
1141  free(dpm->dbp);
1142  free(dpm->dwp);
1143  return ERROR_FAIL;
1144  }
1145 
1146  LOG_INFO("%s: hardware has %d breakpoints, %d watchpoints",
1147  target_name(target), dpm->nbp, dpm->nwp);
1148 
1149  /* REVISIT ... and some of those breakpoints could match
1150  * execution context IDs...
1151  */
1152 
1153  return ERROR_OK;
1154 }
1155 
1160 int arm_dpm_initialize(struct arm_dpm *dpm)
1161 {
1162  /* Disable all breakpoints and watchpoints at startup. */
1163  if (dpm->bpwp_disable) {
1164  unsigned int i;
1165 
1166  for (i = 0; i < dpm->nbp; i++) {
1167  dpm->dbp[i].bpwp.number = i;
1168  (void) dpm->bpwp_disable(dpm, i);
1169  }
1170  for (i = 0; i < dpm->nwp; i++) {
1171  dpm->dwp[i].bpwp.number = 16 + i;
1172  (void) dpm->bpwp_disable(dpm, 16 + i);
1173  }
1174  } else
1175  LOG_WARNING("%s: can't disable breakpoints and watchpoints",
1176  target_name(dpm->arm->target));
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:502
struct reg_cache * arm_build_reg_cache(struct target *target, struct arm *arm)
Definition: armv4_5.c:646
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:761
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:261
@ ARM_VFP_V3_D31
Definition: arm.h:142
@ ARM_VFP_V3_FPSCR
Definition: arm.h:143
@ ARM_VFP_V3_D0
Definition: arm.h:111
@ 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:438
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_modeswitch(struct arm_dpm *dpm, enum arm_mode mode)
Definition: arm_dpm.c:146
static enum arm_mode dpm_mapmode(struct arm *arm, unsigned int num, enum arm_mode mode)
Definition: arm_dpm.c:645
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:1093
static int arm_dpm_full_context(struct target *target)
Definition: arm_dpm.c:771
static int dpm_remove_watchpoint(struct target *target, struct watchpoint *wp)
Definition: arm_dpm.c:1011
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:208
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
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:89
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:311
void arm_dpm_report_wfar(struct arm_dpm *dpm, uint32_t addr)
Definition: arm_dpm.c:1031
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:729
static int dpm_mrrc(struct target *target, int cpnum, uint32_t op, uint32_t crm, uint64_t *value)
Definition: arm_dpm.c:66
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:114
static int arm_dpm_read_core_reg(struct target *target, struct reg *r, int regnum, enum arm_mode mode)
Definition: arm_dpm.c:686
static int dpm_bpwp_setup(struct arm_dpm *dpm, struct dpm_bpwp *xp, uint32_t addr, uint32_t length)
Definition: arm_dpm.c:852
static int dpm_watchpoint_setup(struct arm_dpm *dpm, unsigned int index_t, struct watchpoint *wp)
Definition: arm_dpm.c:957
static int dpm_add_watchpoint(struct target *target, struct watchpoint *wp)
Definition: arm_dpm.c:993
static int dpm_read_reg_u64(struct arm_dpm *dpm, struct reg *r, unsigned int regnum)
Definition: arm_dpm.c:170
static int dpm_remove_breakpoint(struct target *target, struct breakpoint *bp)
Definition: arm_dpm.c:937
int arm_dpm_initialize(struct arm_dpm *dpm)
Reinitializes DPM state at the beginning of a new debug session or after a reset which may have affec...
Definition: arm_dpm.c:1160
static int dpm_add_breakpoint(struct target *target, struct breakpoint *bp)
Definition: arm_dpm.c:909
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: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 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:402
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_WARNING(expr ...)
Definition: log.h:129
#define ERROR_FAIL
Definition: log.h:170
#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
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:116
enum target_debug_reason debug_reason
Definition: target.h:154
struct reg_cache * reg_cache
Definition: target.h:158
struct target_type * type
Definition: target.h:117
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:77
@ DBG_REASON_DBGRQ
Definition: target.h:69
@ DBG_REASON_WATCHPOINT
Definition: target.h:71
@ DBG_REASON_BREAKPOINT
Definition: target.h:70
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
Definition: target.h:233
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:794
#define NULL
Definition: usb.h:16