OpenOCD
xscale.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2006, 2007 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2007,2008 Øyvind Harboe *
8  * oyvind.harboe@zylin.com *
9  * *
10  * Copyright (C) 2009 Michael Schwingen *
11  * michael@schwingen.org *
12  ***************************************************************************/
13 
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include "breakpoints.h"
19 #include "xscale.h"
20 #include "target_type.h"
21 #include "arm_jtag.h"
22 #include "arm_simulator.h"
23 #include "arm_disassembler.h"
24 #include <helper/time_support.h>
25 #include <helper/string_choices.h>
26 #include "register.h"
27 #include "image.h"
28 #include "arm_opcodes.h"
29 #include "armv4_5.h"
30 
31 /*
32  * Important XScale documents available as of October 2009 include:
33  *
34  * Intel XScale® Core Developer’s Manual, January 2004
35  * Order Number: 273473-002
36  * This has a chapter detailing debug facilities, and punts some
37  * details to chip-specific microarchitecture documents.
38  *
39  * Hot-Debug for Intel XScale® Core Debug White Paper, May 2005
40  * Document Number: 273539-005
41  * Less detailed than the developer's manual, but summarizes those
42  * missing details (for most XScales) and gives LOTS of notes about
43  * debugger/handler interaction issues. Presents a simpler reset
44  * and load-handler sequence than the arch doc. (Note, OpenOCD
45  * doesn't currently support "Hot-Debug" as defined there.)
46  *
47  * Chip-specific microarchitecture documents may also be useful.
48  */
49 
50 /* forward declarations */
51 static int xscale_resume(struct target *, bool current,
52  target_addr_t address, bool handle_breakpoints, bool debug_execution);
53 static int xscale_debug_entry(struct target *);
54 static int xscale_restore_banked(struct target *);
55 static int xscale_get_reg(struct reg *reg);
56 static int xscale_set_reg(struct reg *reg, uint8_t *buf);
57 static int xscale_set_breakpoint(struct target *, struct breakpoint *);
58 static int xscale_set_watchpoint(struct target *, struct watchpoint *);
59 static int xscale_unset_breakpoint(struct target *, struct breakpoint *);
60 static int xscale_read_trace(struct target *);
61 
62 /* This XScale "debug handler" is loaded into the processor's
63  * mini-ICache, which is 2K of code writable only via JTAG.
64  */
65 static const uint8_t xscale_debug_handler[] = {
66 #include "../../contrib/loaders/debug/xscale/debug_handler.inc"
67 };
68 
69 static const char *const xscale_reg_list[] = {
70  "XSCALE_MAINID", /* 0 */
71  "XSCALE_CACHETYPE",
72  "XSCALE_CTRL",
73  "XSCALE_AUXCTRL",
74  "XSCALE_TTB",
75  "XSCALE_DAC",
76  "XSCALE_FSR",
77  "XSCALE_FAR",
78  "XSCALE_PID",
79  "XSCALE_CPACCESS",
80  "XSCALE_IBCR0", /* 10 */
81  "XSCALE_IBCR1",
82  "XSCALE_DBR0",
83  "XSCALE_DBR1",
84  "XSCALE_DBCON",
85  "XSCALE_TBREG",
86  "XSCALE_CHKPT0",
87  "XSCALE_CHKPT1",
88  "XSCALE_DCSR",
89  "XSCALE_TX",
90  "XSCALE_RX", /* 20 */
91  "XSCALE_TXRXCTRL",
92 };
93 
94 static const struct xscale_reg xscale_reg_arch_info[] = {
97  {XSCALE_CTRL, NULL},
99  {XSCALE_TTB, NULL},
100  {XSCALE_DAC, NULL},
101  {XSCALE_FSR, NULL},
102  {XSCALE_FAR, NULL},
103  {XSCALE_PID, NULL},
105  {XSCALE_IBCR0, NULL},
106  {XSCALE_IBCR1, NULL},
107  {XSCALE_DBR0, NULL},
108  {XSCALE_DBR1, NULL},
109  {XSCALE_DBCON, NULL},
110  {XSCALE_TBREG, NULL},
111  {XSCALE_CHKPT0, NULL},
112  {XSCALE_CHKPT1, NULL},
113  {XSCALE_DCSR, NULL}, /* DCSR accessed via JTAG or SW */
114  {-1, NULL}, /* TX accessed via JTAG */
115  {-1, NULL}, /* RX accessed via JTAG */
116  {-1, NULL}, /* TXRXCTRL implicit access via JTAG */
117 };
118 
119 /* convenience wrapper to access XScale specific registers */
120 static int xscale_set_reg_u32(struct reg *reg, uint32_t value)
121 {
122  uint8_t buf[4] = { 0 };
123 
124  buf_set_u32(buf, 0, 32, value);
125 
126  return xscale_set_reg(reg, buf);
127 }
128 
129 static const char xscale_not[] = "target is not an XScale";
130 
132  struct xscale_common *xscale)
133 {
134  if (xscale->common_magic != XSCALE_COMMON_MAGIC) {
136  return ERROR_TARGET_INVALID;
137  }
138  return ERROR_OK;
139 }
140 
141 static int xscale_jtag_set_instr(struct jtag_tap *tap, uint32_t new_instr, enum tap_state end_state)
142 {
143  assert(tap);
144 
145  if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) != new_instr) {
146  struct scan_field field;
147  uint8_t scratch[4] = { 0 };
148 
149  memset(&field, 0, sizeof(field));
150  field.num_bits = tap->ir_length;
151  field.out_value = scratch;
152  buf_set_u32(scratch, 0, field.num_bits, new_instr);
153 
154  jtag_add_ir_scan(tap, &field, end_state);
155  }
156 
157  return ERROR_OK;
158 }
159 
160 static int xscale_read_dcsr(struct target *target)
161 {
162  struct xscale_common *xscale = target_to_xscale(target);
163  int retval;
164  struct scan_field fields[3];
165  uint8_t field0 = 0x0;
166  uint8_t field0_check_value = 0x2;
167  uint8_t field0_check_mask = 0x7;
168  uint8_t field2 = 0x0;
169  uint8_t field2_check_value = 0x0;
170  uint8_t field2_check_mask = 0x1;
171 
173  XSCALE_SELDCSR << xscale->xscale_variant,
174  TAP_DRPAUSE);
175 
176  buf_set_u32(&field0, 1, 1, xscale->hold_rst);
177  buf_set_u32(&field0, 2, 1, xscale->external_debug_break);
178 
179  memset(&fields, 0, sizeof(fields));
180 
181  fields[0].num_bits = 3;
182  fields[0].out_value = &field0;
183  uint8_t tmp;
184  fields[0].in_value = &tmp;
185 
186  fields[1].num_bits = 32;
187  fields[1].in_value = xscale->reg_cache->reg_list[XSCALE_DCSR].value;
188 
189  fields[2].num_bits = 1;
190  fields[2].out_value = &field2;
191  uint8_t tmp2;
192  fields[2].in_value = &tmp2;
193 
194  jtag_add_dr_scan(target->tap, 3, fields, TAP_DRPAUSE);
195 
196  jtag_check_value_mask(fields + 0, &field0_check_value, &field0_check_mask);
197  jtag_check_value_mask(fields + 2, &field2_check_value, &field2_check_mask);
198 
199  retval = jtag_execute_queue();
200  if (retval != ERROR_OK) {
201  LOG_ERROR("JTAG error while reading DCSR");
202  return retval;
203  }
204 
205  xscale->reg_cache->reg_list[XSCALE_DCSR].dirty = false;
206  xscale->reg_cache->reg_list[XSCALE_DCSR].valid = true;
207 
208  /* write the register with the value we just read
209  * on this second pass, only the first bit of field0 is guaranteed to be 0)
210  */
211  field0_check_mask = 0x1;
212  fields[1].out_value = xscale->reg_cache->reg_list[XSCALE_DCSR].value;
213  fields[1].in_value = NULL;
214 
215  jtag_add_dr_scan(target->tap, 3, fields, TAP_DRPAUSE);
216 
217  /* DANGER!!! this must be here. It will make sure that the arguments
218  * to jtag_set_check_value() does not go out of scope! */
219  return jtag_execute_queue();
220 }
221 
222 
224 {
225  uint8_t *in = (uint8_t *)arg;
226  *((uint32_t *)arg) = buf_get_u32(in, 0, 32);
227 }
228 
229 static int xscale_receive(struct target *target, uint32_t *buffer, int num_words)
230 {
231  if (num_words == 0)
233 
234  struct xscale_common *xscale = target_to_xscale(target);
235  int retval = ERROR_OK;
236  enum tap_state path[3];
237  struct scan_field fields[3];
238  uint8_t *field0 = malloc(num_words * 1);
239  uint8_t field0_check_value = 0x2;
240  uint8_t field0_check_mask = 0x6;
241  uint32_t *field1 = malloc(num_words * 4);
242  uint8_t field2_check_value = 0x0;
243  uint8_t field2_check_mask = 0x1;
244  int words_done = 0;
245  int words_scheduled = 0;
246  int i;
247 
248  path[0] = TAP_DRSELECT;
249  path[1] = TAP_DRCAPTURE;
250  path[2] = TAP_DRSHIFT;
251 
252  memset(&fields, 0, sizeof(fields));
253 
254  fields[0].num_bits = 3;
255  uint8_t tmp;
256  fields[0].in_value = &tmp;
257  fields[0].check_value = &field0_check_value;
258  fields[0].check_mask = &field0_check_mask;
259 
260  fields[1].num_bits = 32;
261 
262  fields[2].num_bits = 1;
263  uint8_t tmp2;
264  fields[2].in_value = &tmp2;
265  fields[2].check_value = &field2_check_value;
266  fields[2].check_mask = &field2_check_mask;
267 
269  XSCALE_DBGTX << xscale->xscale_variant,
270  TAP_IDLE);
271  jtag_add_runtest(1, TAP_IDLE); /* ensures that we're in the TAP_IDLE state as the above
272  *could be a no-op */
273 
274  /* repeat until all words have been collected */
275  int attempts = 0;
276  while (words_done < num_words) {
277  /* schedule reads */
278  words_scheduled = 0;
279  for (i = words_done; i < num_words; i++) {
280  fields[0].in_value = &field0[i];
281 
282  jtag_add_pathmove(3, path);
283 
284  fields[1].in_value = (uint8_t *)(field1 + i);
285 
287 
289 
290  words_scheduled++;
291  }
292 
293  retval = jtag_execute_queue();
294  if (retval != ERROR_OK) {
295  LOG_ERROR("JTAG error while receiving data from debug handler");
296  break;
297  }
298 
299  /* examine results */
300  for (i = words_done; i < num_words; i++) {
301  if (!(field0[i] & 1)) {
302  /* move backwards if necessary */
303  int j;
304  for (j = i; j < num_words - 1; j++) {
305  field0[j] = field0[j + 1];
306  field1[j] = field1[j + 1];
307  }
308  words_scheduled--;
309  }
310  }
311  if (words_scheduled == 0) {
312  if (attempts++ == 1000) {
313  LOG_ERROR(
314  "Failed to receiving data from debug handler after 1000 attempts");
315  retval = ERROR_TARGET_TIMEOUT;
316  break;
317  }
318  }
319 
320  words_done += words_scheduled;
321  }
322 
323  for (i = 0; i < num_words; i++)
324  *(buffer++) = buf_get_u32((uint8_t *)&field1[i], 0, 32);
325 
326  free(field1);
327 
328  return retval;
329 }
330 
331 static int xscale_read_tx(struct target *target, int consume)
332 {
333  struct xscale_common *xscale = target_to_xscale(target);
334  enum tap_state path[3];
335  enum tap_state noconsume_path[6];
336  int retval;
337  struct timeval timeout, now;
338  struct scan_field fields[3];
339  uint8_t field0_in = 0x0;
340  uint8_t field0_check_value = 0x2;
341  uint8_t field0_check_mask = 0x6;
342  uint8_t field2_check_value = 0x0;
343  uint8_t field2_check_mask = 0x1;
344 
346  XSCALE_DBGTX << xscale->xscale_variant,
347  TAP_IDLE);
348 
349  path[0] = TAP_DRSELECT;
350  path[1] = TAP_DRCAPTURE;
351  path[2] = TAP_DRSHIFT;
352 
353  noconsume_path[0] = TAP_DRSELECT;
354  noconsume_path[1] = TAP_DRCAPTURE;
355  noconsume_path[2] = TAP_DREXIT1;
356  noconsume_path[3] = TAP_DRPAUSE;
357  noconsume_path[4] = TAP_DREXIT2;
358  noconsume_path[5] = TAP_DRSHIFT;
359 
360  memset(&fields, 0, sizeof(fields));
361 
362  fields[0].num_bits = 3;
363  fields[0].in_value = &field0_in;
364 
365  fields[1].num_bits = 32;
366  fields[1].in_value = xscale->reg_cache->reg_list[XSCALE_TX].value;
367 
368  fields[2].num_bits = 1;
369  uint8_t tmp;
370  fields[2].in_value = &tmp;
371 
373  timeval_add_time(&timeout, 1, 0);
374 
375  for (;; ) {
376  /* if we want to consume the register content (i.e. clear TX_READY),
377  * we have to go straight from Capture-DR to Shift-DR
378  * otherwise, we go from Capture-DR to Exit1-DR to Pause-DR
379  */
380  if (consume)
381  jtag_add_pathmove(3, path);
382  else
383  jtag_add_pathmove(ARRAY_SIZE(noconsume_path), noconsume_path);
384 
385  jtag_add_dr_scan(target->tap, 3, fields, TAP_IDLE);
386 
387  jtag_check_value_mask(fields + 0, &field0_check_value, &field0_check_mask);
388  jtag_check_value_mask(fields + 2, &field2_check_value, &field2_check_mask);
389 
390  retval = jtag_execute_queue();
391  if (retval != ERROR_OK) {
392  LOG_ERROR("JTAG error while reading TX");
393  return ERROR_TARGET_TIMEOUT;
394  }
395 
396  gettimeofday(&now, NULL);
397  if (timeval_compare(&now, &timeout) > 0) {
398  LOG_ERROR("time out reading TX register");
399  return ERROR_TARGET_TIMEOUT;
400  }
401  if (!((!(field0_in & 1)) && consume))
402  goto done;
404  LOG_DEBUG("waiting 100ms");
405  alive_sleep(100); /* avoid flooding the logs */
406  } else
407  keep_alive();
408  }
409 done:
410 
411  if (!(field0_in & 1))
413 
414  return ERROR_OK;
415 }
416 
417 static int xscale_write_rx(struct target *target)
418 {
419  struct xscale_common *xscale = target_to_xscale(target);
420  int retval;
421  struct timeval timeout, now;
422  struct scan_field fields[3];
423  uint8_t field0_out = 0x0;
424  uint8_t field0_in = 0x0;
425  uint8_t field0_check_value = 0x2;
426  uint8_t field0_check_mask = 0x6;
427  uint8_t field2 = 0x0;
428  uint8_t field2_check_value = 0x0;
429  uint8_t field2_check_mask = 0x1;
430 
432  XSCALE_DBGRX << xscale->xscale_variant,
433  TAP_IDLE);
434 
435  memset(&fields, 0, sizeof(fields));
436 
437  fields[0].num_bits = 3;
438  fields[0].out_value = &field0_out;
439  fields[0].in_value = &field0_in;
440 
441  fields[1].num_bits = 32;
442  fields[1].out_value = xscale->reg_cache->reg_list[XSCALE_RX].value;
443 
444  fields[2].num_bits = 1;
445  fields[2].out_value = &field2;
446  uint8_t tmp;
447  fields[2].in_value = &tmp;
448 
450  timeval_add_time(&timeout, 1, 0);
451 
452  /* poll until rx_read is low */
453  LOG_DEBUG("polling RX");
454  for (;;) {
455  jtag_add_dr_scan(target->tap, 3, fields, TAP_IDLE);
456 
457  jtag_check_value_mask(fields + 0, &field0_check_value, &field0_check_mask);
458  jtag_check_value_mask(fields + 2, &field2_check_value, &field2_check_mask);
459 
460  retval = jtag_execute_queue();
461  if (retval != ERROR_OK) {
462  LOG_ERROR("JTAG error while writing RX");
463  return retval;
464  }
465 
466  gettimeofday(&now, NULL);
467  if ((now.tv_sec > timeout.tv_sec) ||
468  ((now.tv_sec == timeout.tv_sec) && (now.tv_usec > timeout.tv_usec))) {
469  LOG_ERROR("time out writing RX register");
470  return ERROR_TARGET_TIMEOUT;
471  }
472  if (!(field0_in & 1))
473  goto done;
475  LOG_DEBUG("waiting 100ms");
476  alive_sleep(100); /* avoid flooding the logs */
477  } else
478  keep_alive();
479  }
480 done:
481 
482  /* set rx_valid */
483  field2 = 0x1;
484  jtag_add_dr_scan(target->tap, 3, fields, TAP_IDLE);
485 
486  retval = jtag_execute_queue();
487  if (retval != ERROR_OK) {
488  LOG_ERROR("JTAG error while writing RX");
489  return retval;
490  }
491 
492  return ERROR_OK;
493 }
494 
495 /* send count elements of size byte to the debug handler */
496 static int xscale_send(struct target *target, const uint8_t *buffer, int count, int size)
497 {
498  struct xscale_common *xscale = target_to_xscale(target);
499  int retval;
500  int done_count = 0;
501 
503  XSCALE_DBGRX << xscale->xscale_variant,
504  TAP_IDLE);
505 
506  static const uint8_t t0;
507  uint8_t t1[4] = { 0 };
508  static const uint8_t t2 = 1;
509  struct scan_field fields[3] = {
510  { .num_bits = 3, .out_value = &t0 },
511  { .num_bits = 32, .out_value = t1 },
512  { .num_bits = 1, .out_value = &t2 },
513  };
514 
515  int endianness = target->endianness;
516  while (done_count++ < count) {
517  uint32_t t;
518 
519  switch (size) {
520  case 4:
521  if (endianness == TARGET_LITTLE_ENDIAN)
522  t = le_to_h_u32(buffer);
523  else
524  t = be_to_h_u32(buffer);
525  break;
526  case 2:
527  if (endianness == TARGET_LITTLE_ENDIAN)
528  t = le_to_h_u16(buffer);
529  else
530  t = be_to_h_u16(buffer);
531  break;
532  case 1:
533  t = buffer[0];
534  break;
535  default:
536  LOG_ERROR("BUG: size neither 4, 2 nor 1");
538  }
539 
540  buf_set_u32(t1, 0, 32, t);
541 
543  3,
544  fields,
545  TAP_IDLE);
546  buffer += size;
547  }
548 
549  retval = jtag_execute_queue();
550  if (retval != ERROR_OK) {
551  LOG_ERROR("JTAG error while sending data to debug handler");
552  return retval;
553  }
554 
555  return ERROR_OK;
556 }
557 
558 static int xscale_send_u32(struct target *target, uint32_t value)
559 {
560  struct xscale_common *xscale = target_to_xscale(target);
561 
562  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_RX].value, 0, 32, value);
563  return xscale_write_rx(target);
564 }
565 
566 static int xscale_write_dcsr(struct target *target, int hold_rst, int ext_dbg_brk)
567 {
568  struct xscale_common *xscale = target_to_xscale(target);
569  int retval;
570  struct scan_field fields[3];
571  uint8_t field0 = 0x0;
572  uint8_t field0_check_value = 0x2;
573  uint8_t field0_check_mask = 0x7;
574  uint8_t field2 = 0x0;
575  uint8_t field2_check_value = 0x0;
576  uint8_t field2_check_mask = 0x1;
577 
578  if (hold_rst != -1)
579  xscale->hold_rst = hold_rst;
580 
581  if (ext_dbg_brk != -1)
582  xscale->external_debug_break = ext_dbg_brk;
583 
585  XSCALE_SELDCSR << xscale->xscale_variant,
586  TAP_IDLE);
587 
588  buf_set_u32(&field0, 1, 1, xscale->hold_rst);
589  buf_set_u32(&field0, 2, 1, xscale->external_debug_break);
590 
591  memset(&fields, 0, sizeof(fields));
592 
593  fields[0].num_bits = 3;
594  fields[0].out_value = &field0;
595  uint8_t tmp;
596  fields[0].in_value = &tmp;
597 
598  fields[1].num_bits = 32;
599  fields[1].out_value = xscale->reg_cache->reg_list[XSCALE_DCSR].value;
600 
601  fields[2].num_bits = 1;
602  fields[2].out_value = &field2;
603  uint8_t tmp2;
604  fields[2].in_value = &tmp2;
605 
606  jtag_add_dr_scan(target->tap, 3, fields, TAP_IDLE);
607 
608  jtag_check_value_mask(fields + 0, &field0_check_value, &field0_check_mask);
609  jtag_check_value_mask(fields + 2, &field2_check_value, &field2_check_mask);
610 
611  retval = jtag_execute_queue();
612  if (retval != ERROR_OK) {
613  LOG_ERROR("JTAG error while writing DCSR");
614  return retval;
615  }
616 
617  xscale->reg_cache->reg_list[XSCALE_DCSR].dirty = false;
618  xscale->reg_cache->reg_list[XSCALE_DCSR].valid = true;
619 
620  return ERROR_OK;
621 }
622 
623 /* parity of the number of bits 0 if even; 1 if odd. for 32 bit words */
624 static unsigned int parity(unsigned int v)
625 {
626  /* unsigned int ov = v; */
627  v ^= v >> 16;
628  v ^= v >> 8;
629  v ^= v >> 4;
630  v &= 0xf;
631  /* LOG_DEBUG("parity of 0x%x is %i", ov, (0x6996 >> v) & 1); */
632  return (0x6996 >> v) & 1;
633 }
634 
635 static int xscale_load_ic(struct target *target, uint32_t va, uint32_t buffer[8])
636 {
637  struct xscale_common *xscale = target_to_xscale(target);
638  uint8_t packet[4] = { 0 };
639  uint8_t cmd = 0;
640  int word;
641  struct scan_field fields[2];
642 
643  LOG_DEBUG("loading miniIC at 0x%8.8" PRIx32, va);
644 
645  /* LDIC into IR */
647  XSCALE_LDIC << xscale->xscale_variant,
648  TAP_IDLE);
649 
650  /* CMD is b011 to load a cacheline into the Mini ICache.
651  * Loading into the main ICache is deprecated, and unused.
652  * It's followed by three zero bits, and 27 address bits.
653  */
654  buf_set_u32(&cmd, 0, 6, 0x3);
655 
656  /* virtual address of desired cache line */
657  buf_set_u32(packet, 0, 27, va >> 5);
658 
659  memset(&fields, 0, sizeof(fields));
660 
661  fields[0].num_bits = 6;
662  fields[0].out_value = &cmd;
663 
664  fields[1].num_bits = 27;
665  fields[1].out_value = packet;
666 
667  jtag_add_dr_scan(target->tap, 2, fields, TAP_IDLE);
668 
669  /* rest of packet is a cacheline: 8 instructions, with parity */
670  fields[0].num_bits = 32;
671  fields[0].out_value = packet;
672 
673  fields[1].num_bits = 1;
674  fields[1].out_value = &cmd;
675 
676  for (word = 0; word < 8; word++) {
677  buf_set_u32(packet, 0, 32, buffer[word]);
678 
679  uint32_t value;
680  memcpy(&value, packet, sizeof(uint32_t));
681  cmd = parity(value);
682 
683  jtag_add_dr_scan(target->tap, 2, fields, TAP_IDLE);
684  }
685 
686  return jtag_execute_queue();
687 }
688 
689 static int xscale_invalidate_ic_line(struct target *target, uint32_t va)
690 {
691  struct xscale_common *xscale = target_to_xscale(target);
692  uint8_t packet[4] = { 0 };
693  uint8_t cmd = 0;
694  struct scan_field fields[2];
695 
697  XSCALE_LDIC << xscale->xscale_variant,
698  TAP_IDLE);
699 
700  /* CMD for invalidate IC line b000, bits [6:4] b000 */
701  buf_set_u32(&cmd, 0, 6, 0x0);
702 
703  /* virtual address of desired cache line */
704  buf_set_u32(packet, 0, 27, va >> 5);
705 
706  memset(&fields, 0, sizeof(fields));
707 
708  fields[0].num_bits = 6;
709  fields[0].out_value = &cmd;
710 
711  fields[1].num_bits = 27;
712  fields[1].out_value = packet;
713 
714  jtag_add_dr_scan(target->tap, 2, fields, TAP_IDLE);
715 
716  return ERROR_OK;
717 }
718 
720 {
721  struct xscale_common *xscale = target_to_xscale(target);
722  int i;
723  int retval;
724 
725  uint32_t low_reset_branch, high_reset_branch;
726 
727  for (i = 1; i < 8; i++) {
728  /* if there's a static vector specified for this exception, override */
729  if (xscale->static_high_vectors_set & (1 << i))
730  xscale->high_vectors[i] = xscale->static_high_vectors[i];
731  else {
732  retval = target_read_u32(target, 0xffff0000 + 4*i, &xscale->high_vectors[i]);
733  if (retval == ERROR_TARGET_TIMEOUT)
734  return retval;
735  if (retval != ERROR_OK) {
736  /* Some of these reads will fail as part of normal execution */
737  xscale->high_vectors[i] = ARMV4_5_B(0xfffffe, 0);
738  }
739  }
740  }
741 
742  for (i = 1; i < 8; i++) {
743  if (xscale->static_low_vectors_set & (1 << i))
744  xscale->low_vectors[i] = xscale->static_low_vectors[i];
745  else {
746  retval = target_read_u32(target, 0x0 + 4*i, &xscale->low_vectors[i]);
747  if (retval == ERROR_TARGET_TIMEOUT)
748  return retval;
749  if (retval != ERROR_OK) {
750  /* Some of these reads will fail as part of normal execution */
751  xscale->low_vectors[i] = ARMV4_5_B(0xfffffe, 0);
752  }
753  }
754  }
755 
756  /* calculate branches to debug handler */
757  low_reset_branch = (xscale->handler_address + 0x20 - 0x0 - 0x8) >> 2;
758  high_reset_branch = (xscale->handler_address + 0x20 - 0xffff0000 - 0x8) >> 2;
759 
760  xscale->low_vectors[0] = ARMV4_5_B((low_reset_branch & 0xffffff), 0);
761  xscale->high_vectors[0] = ARMV4_5_B((high_reset_branch & 0xffffff), 0);
762 
763  /* invalidate and load exception vectors in mini i-cache */
765  xscale_invalidate_ic_line(target, 0xffff0000);
766 
767  xscale_load_ic(target, 0x0, xscale->low_vectors);
768  xscale_load_ic(target, 0xffff0000, xscale->high_vectors);
769 
770  return ERROR_OK;
771 }
772 
773 static int xscale_arch_state(struct target *target)
774 {
775  struct xscale_common *xscale = target_to_xscale(target);
776  struct arm *arm = &xscale->arm;
777 
778  static const char *arch_dbg_reason[] = {
779  "", "\n(processor reset)", "\n(trace buffer full)"
780  };
781 
783  LOG_ERROR("BUG: called for a non-ARMv4/5 target");
785  }
786 
788  LOG_USER("MMU: %s, D-Cache: %s, I-Cache: %s%s",
792  arch_dbg_reason[xscale->arch_debug_reason]);
793 
794  return ERROR_OK;
795 }
796 
797 static int xscale_poll(struct target *target)
798 {
799  int retval = ERROR_OK;
800 
802  enum target_state previous_state = target->state;
803  retval = xscale_read_tx(target, 0);
804  if (retval == ERROR_OK) {
805 
806  /* there's data to read from the tx register, we entered debug state */
808 
809  /* process debug entry, fetching current mode regs */
810  retval = xscale_debug_entry(target);
811  } else if (retval != ERROR_TARGET_RESOURCE_NOT_AVAILABLE) {
812  LOG_USER("error while polling TX register, reset CPU");
813  /* here we "lie" so GDB won't get stuck and a reset can be performed */
815  }
816 
817  /* debug_entry could have overwritten target state (i.e. immediate resume)
818  * don't signal event handlers in that case
819  */
820  if (target->state != TARGET_HALTED)
821  return ERROR_OK;
822 
823  /* if target was running, signal that we halted
824  * otherwise we reentered from debug execution */
825  if (previous_state == TARGET_RUNNING)
827  else
829  }
830 
831  return retval;
832 }
833 
834 static int xscale_debug_entry(struct target *target)
835 {
836  struct xscale_common *xscale = target_to_xscale(target);
837  struct arm *arm = &xscale->arm;
838  uint32_t pc;
839  uint32_t buffer[10];
840  unsigned int i;
841  int retval;
842  uint32_t moe;
843 
844  /* clear external dbg break (will be written on next DCSR read) */
845  xscale->external_debug_break = 0;
846  retval = xscale_read_dcsr(target);
847  if (retval != ERROR_OK)
848  return retval;
849 
850  /* get r0, pc, r1 to r7 and cpsr */
851  retval = xscale_receive(target, buffer, 10);
852  if (retval != ERROR_OK)
853  return retval;
854 
855  /* move r0 from buffer to register cache */
856  buf_set_u32(arm->core_cache->reg_list[0].value, 0, 32, buffer[0]);
857  arm->core_cache->reg_list[0].dirty = true;
858  arm->core_cache->reg_list[0].valid = true;
859  LOG_DEBUG("r0: 0x%8.8" PRIx32, buffer[0]);
860 
861  /* move pc from buffer to register cache */
862  buf_set_u32(arm->pc->value, 0, 32, buffer[1]);
863  arm->pc->dirty = true;
864  arm->pc->valid = true;
865  LOG_DEBUG("pc: 0x%8.8" PRIx32, buffer[1]);
866 
867  /* move data from buffer to register cache */
868  for (i = 1; i <= 7; i++) {
869  buf_set_u32(arm->core_cache->reg_list[i].value, 0, 32, buffer[1 + i]);
870  arm->core_cache->reg_list[i].dirty = true;
871  arm->core_cache->reg_list[i].valid = true;
872  LOG_DEBUG("r%i: 0x%8.8" PRIx32, i, buffer[i + 1]);
873  }
874 
875  arm_set_cpsr(arm, buffer[9]);
876  LOG_DEBUG("cpsr: 0x%8.8" PRIx32, buffer[9]);
877 
878  if (!is_arm_mode(arm->core_mode)) {
880  LOG_ERROR("cpsr contains invalid mode value - communication failure");
881  return ERROR_TARGET_FAILURE;
882  }
883  LOG_DEBUG("target entered debug state in %s mode",
885 
886  /* get banked registers, r8 to r14, and spsr if not in USR/SYS mode */
887  if (arm->spsr) {
889  buf_set_u32(arm->spsr->value, 0, 32, buffer[7]);
890  arm->spsr->dirty = false;
891  arm->spsr->valid = true;
892  } else {
893  /* r8 to r14, but no spsr */
895  }
896 
897  /* move data from buffer to right banked register in cache */
898  for (i = 8; i <= 14; i++) {
899  struct reg *r = arm_reg_current(arm, i);
900 
901  buf_set_u32(r->value, 0, 32, buffer[i - 8]);
902  r->dirty = false;
903  r->valid = true;
904  }
905 
906  /* mark xscale regs invalid to ensure they are retrieved from the
907  * debug handler if requested */
908  for (i = 0; i < xscale->reg_cache->num_regs; i++)
909  xscale->reg_cache->reg_list[i].valid = false;
910 
911  /* examine debug reason */
913  moe = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 2, 3);
914 
915  /* stored PC (for calculating fixup) */
916  pc = buf_get_u32(arm->pc->value, 0, 32);
917 
918  switch (moe) {
919  case 0x0: /* Processor reset */
922  pc -= 4;
923  break;
924  case 0x1: /* Instruction breakpoint hit */
927  pc -= 4;
928  break;
929  case 0x2: /* Data breakpoint hit */
932  pc -= 4;
933  break;
934  case 0x3: /* BKPT instruction executed */
937  pc -= 4;
938  break;
939  case 0x4: /* Ext. debug event */
942  pc -= 4;
943  break;
944  case 0x5: /* Vector trap occurred */
947  pc -= 4;
948  break;
949  case 0x6: /* Trace buffer full break */
952  pc -= 4;
953  break;
954  case 0x7: /* Reserved (may flag Hot-Debug support) */
955  default:
956  LOG_ERROR("Method of Entry is 'Reserved'");
957  exit(-1);
958  break;
959  }
960 
961  /* apply PC fixup */
962  buf_set_u32(arm->pc->value, 0, 32, pc);
963 
964  /* on the first debug entry, identify cache type */
965  if (xscale->armv4_5_mmu.armv4_5_cache.ctype == -1) {
966  uint32_t cache_type_reg;
967 
968  /* read cp15 cache type register */
970  cache_type_reg = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_CACHETYPE].value,
971  0,
972  32);
973 
974  armv4_5_identify_cache(cache_type_reg, &xscale->armv4_5_mmu.armv4_5_cache);
975  }
976 
977  /* examine MMU and Cache settings
978  * read cp15 control register */
980  xscale->cp15_control_reg =
981  buf_get_u32(xscale->reg_cache->reg_list[XSCALE_CTRL].value, 0, 32);
982  xscale->armv4_5_mmu.mmu_enabled = xscale->cp15_control_reg & 0x1U;
984  xscale->cp15_control_reg & 0x4U;
986  xscale->cp15_control_reg & 0x1000U;
987 
988  /* tracing enabled, read collected trace data */
989  if (xscale->trace.mode != XSCALE_TRACE_DISABLED) {
991 
992  /* Resume if entered debug due to buffer fill and we're still collecting
993  * trace data. Note that a debug exception due to trace buffer full
994  * can only happen in fill mode. */
996  if (--xscale->trace.fill_counter > 0)
997  xscale_resume(target, true, 0x0, true, false);
998  } else /* entered debug for other reason; reset counter */
999  xscale->trace.fill_counter = 0;
1000  }
1001 
1002  return ERROR_OK;
1003 }
1004 
1005 static int xscale_halt(struct target *target)
1006 {
1007  struct xscale_common *xscale = target_to_xscale(target);
1008 
1009  LOG_DEBUG("target->state: %s",
1011 
1012  if (target->state == TARGET_HALTED) {
1013  LOG_DEBUG("target was already halted");
1014  return ERROR_OK;
1015  } else if (target->state == TARGET_UNKNOWN) {
1016  /* this must not happen for a xscale target */
1017  LOG_ERROR("target was in unknown state when halt was requested");
1018  return ERROR_TARGET_INVALID;
1019  } else if (target->state == TARGET_RESET)
1020  LOG_DEBUG("target->state == TARGET_RESET");
1021  else {
1022  /* assert external dbg break */
1023  xscale->external_debug_break = 1;
1025 
1027  }
1028 
1029  return ERROR_OK;
1030 }
1031 
1032 static int xscale_enable_single_step(struct target *target, uint32_t next_pc)
1033 {
1034  struct xscale_common *xscale = target_to_xscale(target);
1035  struct reg *ibcr0 = &xscale->reg_cache->reg_list[XSCALE_IBCR0];
1036  int retval;
1037 
1038  if (xscale->ibcr0_used) {
1039  struct breakpoint *ibcr0_bp =
1040  breakpoint_find(target, buf_get_u32(ibcr0->value, 0, 32) & 0xfffffffe);
1041 
1042  if (ibcr0_bp)
1043  xscale_unset_breakpoint(target, ibcr0_bp);
1044  else {
1045  LOG_ERROR(
1046  "BUG: xscale->ibcr0_used is set, but no breakpoint with that address found");
1047  exit(-1);
1048  }
1049  }
1050 
1051  retval = xscale_set_reg_u32(ibcr0, next_pc | 0x1);
1052  if (retval != ERROR_OK)
1053  return retval;
1054 
1055  return ERROR_OK;
1056 }
1057 
1059 {
1060  struct xscale_common *xscale = target_to_xscale(target);
1061  struct reg *ibcr0 = &xscale->reg_cache->reg_list[XSCALE_IBCR0];
1062  int retval;
1063 
1064  retval = xscale_set_reg_u32(ibcr0, 0x0);
1065  if (retval != ERROR_OK)
1066  return retval;
1067 
1068  return ERROR_OK;
1069 }
1070 
1072 {
1074 
1075  while (watchpoint) {
1076  if (!watchpoint->is_set)
1079  }
1080 }
1081 
1083 {
1085 
1086  /* set any pending breakpoints */
1087  while (breakpoint) {
1088  if (!breakpoint->is_set)
1091  }
1092 }
1093 
1094 static void xscale_free_trace_data(struct xscale_common *xscale)
1095 {
1096  struct xscale_trace_data *td = xscale->trace.data;
1097  while (td) {
1098  struct xscale_trace_data *next_td = td->next;
1099  free(td->entries);
1100  free(td);
1101  td = next_td;
1102  }
1103  xscale->trace.data = NULL;
1104 }
1105 
1106 static int xscale_resume(struct target *target, bool current,
1107  target_addr_t address, bool handle_breakpoints, bool debug_execution)
1108 {
1109  struct xscale_common *xscale = target_to_xscale(target);
1110  struct arm *arm = &xscale->arm;
1111  uint32_t current_pc;
1112  int retval;
1113  int i;
1114 
1115  LOG_DEBUG("-");
1116 
1117  if (target->state != TARGET_HALTED) {
1118  LOG_TARGET_ERROR(target, "not halted");
1119  return ERROR_TARGET_NOT_HALTED;
1120  }
1121 
1122  if (!debug_execution)
1124 
1125  /* update vector tables */
1126  retval = xscale_update_vectors(target);
1127  if (retval != ERROR_OK)
1128  return retval;
1129 
1130  /* current = true: continue on current pc, otherwise continue at <address> */
1131  if (!current)
1132  buf_set_u32(arm->pc->value, 0, 32, address);
1133 
1134  current_pc = buf_get_u32(arm->pc->value, 0, 32);
1135 
1136  /* if we're at the reset vector, we have to simulate the branch */
1137  if (current_pc == 0x0) {
1139  current_pc = buf_get_u32(arm->pc->value, 0, 32);
1140  }
1141 
1142  /* the front-end may request us not to handle breakpoints */
1143  if (handle_breakpoints) {
1144  struct breakpoint *breakpoint;
1146  buf_get_u32(arm->pc->value, 0, 32));
1147  if (breakpoint) {
1148  uint32_t next_pc;
1149  enum trace_mode saved_trace_mode;
1150 
1151  /* there's a breakpoint at the current PC, we have to step over it */
1152  LOG_DEBUG("unset breakpoint at " TARGET_ADDR_FMT "",
1153  breakpoint->address);
1155 
1156  /* calculate PC of next instruction */
1157  retval = arm_simulate_step(target, &next_pc);
1158  if (retval != ERROR_OK) {
1159  uint32_t current_opcode;
1160  target_read_u32(target, current_pc, &current_opcode);
1161  LOG_ERROR(
1162  "BUG: couldn't calculate PC of next instruction, current opcode was 0x%8.8" PRIx32,
1163  current_opcode);
1164  }
1165 
1166  LOG_DEBUG("enable single-step");
1168 
1169  /* restore banked registers */
1170  retval = xscale_restore_banked(target);
1171  if (retval != ERROR_OK)
1172  return retval;
1173 
1174  /* send resume request */
1175  xscale_send_u32(target, 0x30);
1176 
1177  /* send CPSR */
1179  buf_get_u32(arm->cpsr->value, 0, 32));
1180  LOG_DEBUG("writing cpsr with value 0x%8.8" PRIx32,
1181  buf_get_u32(arm->cpsr->value, 0, 32));
1182 
1183  for (i = 7; i >= 0; i--) {
1184  /* send register */
1186  buf_get_u32(arm->core_cache->reg_list[i].value, 0, 32));
1187  LOG_DEBUG("writing r%i with value 0x%8.8" PRIx32,
1188  i, buf_get_u32(arm->core_cache->reg_list[i].value, 0, 32));
1189  }
1190 
1191  /* send PC */
1193  buf_get_u32(arm->pc->value, 0, 32));
1194  LOG_DEBUG("writing PC with value 0x%8.8" PRIx32,
1195  buf_get_u32(arm->pc->value, 0, 32));
1196 
1197  /* disable trace data collection in xscale_debug_entry() */
1198  saved_trace_mode = xscale->trace.mode;
1199  xscale->trace.mode = XSCALE_TRACE_DISABLED;
1200 
1201  /* wait for and process debug entry */
1203 
1204  /* re-enable trace buffer, if enabled previously */
1205  xscale->trace.mode = saved_trace_mode;
1206 
1207  LOG_DEBUG("disable single-step");
1209 
1210  LOG_DEBUG("set breakpoint at " TARGET_ADDR_FMT "",
1211  breakpoint->address);
1213  }
1214  }
1215 
1216  /* enable any pending breakpoints and watchpoints */
1219 
1220  /* restore banked registers */
1221  retval = xscale_restore_banked(target);
1222  if (retval != ERROR_OK)
1223  return retval;
1224 
1225  /* send resume request (command 0x30 or 0x31)
1226  * clean the trace buffer if it is to be enabled (0x62) */
1227  if (xscale->trace.mode != XSCALE_TRACE_DISABLED) {
1228  if (xscale->trace.mode == XSCALE_TRACE_FILL) {
1229  /* If trace enabled in fill mode and starting collection of new set
1230  * of buffers, initialize buffer counter and free previous buffers */
1231  if (xscale->trace.fill_counter == 0) {
1232  xscale->trace.fill_counter = xscale->trace.buffer_fill;
1233  xscale_free_trace_data(xscale);
1234  }
1235  } else /* wrap mode; free previous buffer */
1236  xscale_free_trace_data(xscale);
1237 
1238  xscale_send_u32(target, 0x62);
1239  xscale_send_u32(target, 0x31);
1240  } else
1241  xscale_send_u32(target, 0x30);
1242 
1243  /* send CPSR */
1245  LOG_DEBUG("writing cpsr with value 0x%8.8" PRIx32,
1246  buf_get_u32(arm->cpsr->value, 0, 32));
1247 
1248  for (i = 7; i >= 0; i--) {
1249  /* send register */
1251  LOG_DEBUG("writing r%i with value 0x%8.8" PRIx32,
1252  i, buf_get_u32(arm->core_cache->reg_list[i].value, 0, 32));
1253  }
1254 
1255  /* send PC */
1257  LOG_DEBUG("wrote PC with value 0x%8.8" PRIx32,
1258  buf_get_u32(arm->pc->value, 0, 32));
1259 
1261 
1262  if (!debug_execution) {
1263  /* registers are now invalid */
1267  } else {
1270  }
1271 
1272  LOG_DEBUG("target resumed");
1273 
1274  return ERROR_OK;
1275 }
1276 
1277 static int xscale_step_inner(struct target *target, bool current,
1278  uint32_t address, bool handle_breakpoints)
1279 {
1280  struct xscale_common *xscale = target_to_xscale(target);
1281  struct arm *arm = &xscale->arm;
1282  uint32_t next_pc;
1283  int retval;
1284  int i;
1285 
1287 
1288  /* calculate PC of next instruction */
1289  retval = arm_simulate_step(target, &next_pc);
1290  if (retval != ERROR_OK) {
1291  uint32_t current_opcode, current_pc;
1292  current_pc = buf_get_u32(arm->pc->value, 0, 32);
1293 
1294  target_read_u32(target, current_pc, &current_opcode);
1295  LOG_ERROR(
1296  "BUG: couldn't calculate PC of next instruction, current opcode was 0x%8.8" PRIx32,
1297  current_opcode);
1298  return retval;
1299  }
1300 
1301  LOG_DEBUG("enable single-step");
1302  retval = xscale_enable_single_step(target, next_pc);
1303  if (retval != ERROR_OK)
1304  return retval;
1305 
1306  /* restore banked registers */
1307  retval = xscale_restore_banked(target);
1308  if (retval != ERROR_OK)
1309  return retval;
1310 
1311  /* send resume request (command 0x30 or 0x31)
1312  * clean the trace buffer if it is to be enabled (0x62) */
1313  if (xscale->trace.mode != XSCALE_TRACE_DISABLED) {
1314  retval = xscale_send_u32(target, 0x62);
1315  if (retval != ERROR_OK)
1316  return retval;
1317  retval = xscale_send_u32(target, 0x31);
1318  if (retval != ERROR_OK)
1319  return retval;
1320  } else {
1321  retval = xscale_send_u32(target, 0x30);
1322  if (retval != ERROR_OK)
1323  return retval;
1324  }
1325 
1326  /* send CPSR */
1327  retval = xscale_send_u32(target,
1328  buf_get_u32(arm->cpsr->value, 0, 32));
1329  if (retval != ERROR_OK)
1330  return retval;
1331  LOG_DEBUG("writing cpsr with value 0x%8.8" PRIx32,
1332  buf_get_u32(arm->cpsr->value, 0, 32));
1333 
1334  for (i = 7; i >= 0; i--) {
1335  /* send register */
1336  retval = xscale_send_u32(target,
1337  buf_get_u32(arm->core_cache->reg_list[i].value, 0, 32));
1338  if (retval != ERROR_OK)
1339  return retval;
1340  LOG_DEBUG("writing r%i with value 0x%8.8" PRIx32, i,
1341  buf_get_u32(arm->core_cache->reg_list[i].value, 0, 32));
1342  }
1343 
1344  /* send PC */
1345  retval = xscale_send_u32(target,
1346  buf_get_u32(arm->pc->value, 0, 32));
1347  if (retval != ERROR_OK)
1348  return retval;
1349  LOG_DEBUG("wrote PC with value 0x%8.8" PRIx32,
1350  buf_get_u32(arm->pc->value, 0, 32));
1351 
1353 
1354  /* registers are now invalid */
1356 
1357  /* wait for and process debug entry */
1358  retval = xscale_debug_entry(target);
1359  if (retval != ERROR_OK)
1360  return retval;
1361 
1362  LOG_DEBUG("disable single-step");
1364  if (retval != ERROR_OK)
1365  return retval;
1366 
1368 
1369  return ERROR_OK;
1370 }
1371 
1372 static int xscale_step(struct target *target, bool current,
1373  target_addr_t address, bool handle_breakpoints)
1374 {
1375  struct arm *arm = target_to_arm(target);
1376  struct breakpoint *breakpoint = NULL;
1377 
1378  uint32_t current_pc;
1379  int retval;
1380 
1381  if (target->state != TARGET_HALTED) {
1382  LOG_TARGET_ERROR(target, "not halted");
1383  return ERROR_TARGET_NOT_HALTED;
1384  }
1385 
1386  /* current = true: continue on current pc, otherwise continue at <address> */
1387  if (!current)
1388  buf_set_u32(arm->pc->value, 0, 32, address);
1389 
1390  current_pc = buf_get_u32(arm->pc->value, 0, 32);
1391 
1392  /* if we're at the reset vector, we have to simulate the step */
1393  if (current_pc == 0x0) {
1394  retval = arm_simulate_step(target, NULL);
1395  if (retval != ERROR_OK)
1396  return retval;
1397  current_pc = buf_get_u32(arm->pc->value, 0, 32);
1398  LOG_DEBUG("current pc %" PRIx32, current_pc);
1399 
1402 
1403  return ERROR_OK;
1404  }
1405 
1406  /* the front-end may request us not to handle breakpoints */
1407  if (handle_breakpoints)
1409  buf_get_u32(arm->pc->value, 0, 32));
1410  if (breakpoint) {
1412  if (retval != ERROR_OK)
1413  return retval;
1414  }
1415 
1416  retval = xscale_step_inner(target, current, address, handle_breakpoints);
1417  if (retval != ERROR_OK)
1418  return retval;
1419 
1420  if (breakpoint)
1422 
1423  LOG_DEBUG("target stepped");
1424 
1425  return ERROR_OK;
1426 
1427 }
1428 
1429 static int xscale_assert_reset(struct target *target)
1430 {
1431  struct xscale_common *xscale = target_to_xscale(target);
1432 
1433  /* TODO: apply hw reset signal in not examined state */
1434  if (!(target_was_examined(target))) {
1435  LOG_WARNING("Reset is not asserted because the target is not examined.");
1436  LOG_WARNING("Use a reset button or power cycle the target.");
1438  }
1439 
1440  LOG_DEBUG("target->state: %s",
1442 
1443  /* assert reset */
1444  jtag_add_reset(0, 1);
1445 
1446  /* sleep 1ms, to be sure we fulfill any requirements */
1447  jtag_add_sleep(1000);
1449 
1450  /* select DCSR instruction (set endstate to R-T-I to ensure we don't
1451  * end up in T-L-R, which would reset JTAG
1452  */
1454  XSCALE_SELDCSR << xscale->xscale_variant,
1455  TAP_IDLE);
1456 
1457  /* set Hold reset, Halt mode and Trap Reset */
1458  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 30, 1, 0x1);
1459  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 16, 1, 0x1);
1460  xscale_write_dcsr(target, 1, 0);
1461 
1462  /* select BYPASS, because having DCSR selected caused problems on the PXA27x */
1465 
1467 
1468  if (target->reset_halt) {
1469  int retval = target_halt(target);
1470  if (retval != ERROR_OK)
1471  return retval;
1472  }
1473 
1474  return ERROR_OK;
1475 }
1476 
1478 {
1479  struct xscale_common *xscale = target_to_xscale(target);
1481 
1482  LOG_DEBUG("-");
1483 
1484  xscale->ibcr_available = 2;
1485  xscale->ibcr0_used = 0;
1486  xscale->ibcr1_used = 0;
1487 
1488  xscale->dbr_available = 2;
1489  xscale->dbr0_used = 0;
1490  xscale->dbr1_used = 0;
1491 
1492  /* mark all hardware breakpoints as unset */
1493  while (breakpoint) {
1494  if (breakpoint->type == BKPT_HARD)
1495  breakpoint->is_set = false;
1497  }
1498 
1499  xscale->trace.mode = XSCALE_TRACE_DISABLED;
1500  xscale_free_trace_data(xscale);
1501 
1503 
1504  /* FIXME mark hardware watchpoints got unset too. Also,
1505  * at least some of the XScale registers are invalid...
1506  */
1507 
1508  /*
1509  * REVISIT: *assumes* we had a SRST+TRST reset so the mini-icache
1510  * contents got invalidated. Safer to force that, so writing new
1511  * contents can't ever fail..
1512  */
1513  {
1514  uint32_t address;
1515  unsigned int buf_cnt;
1516  const uint8_t *buffer = xscale_debug_handler;
1517  int retval;
1518 
1519  /* release SRST */
1520  jtag_add_reset(0, 0);
1521 
1522  /* wait 300ms; 150 and 100ms were not enough */
1523  jtag_add_sleep(300*1000);
1524 
1525  jtag_add_runtest(2030, TAP_IDLE);
1527 
1528  /* set Hold reset, Halt mode and Trap Reset */
1529  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 30, 1, 0x1);
1530  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 16, 1, 0x1);
1531  xscale_write_dcsr(target, 1, 0);
1532 
1533  /* Load the debug handler into the mini-icache. Since
1534  * it's using halt mode (not monitor mode), it runs in
1535  * "Special Debug State" for access to registers, memory,
1536  * coprocessors, trace data, etc.
1537  */
1538  address = xscale->handler_address;
1539  for (unsigned int binary_size = sizeof(xscale_debug_handler);
1540  binary_size > 0;
1541  binary_size -= buf_cnt, buffer += buf_cnt) {
1542  uint32_t cache_line[8];
1543  unsigned int i;
1544 
1545  buf_cnt = binary_size;
1546  if (buf_cnt > 32)
1547  buf_cnt = 32;
1548 
1549  for (i = 0; i < buf_cnt; i += 4) {
1550  /* convert LE buffer to host-endian uint32_t */
1551  cache_line[i / 4] = le_to_h_u32(&buffer[i]);
1552  }
1553 
1554  for (; i < 32; i += 4)
1555  cache_line[i / 4] = 0xe1a08008;
1556 
1557  /* only load addresses other than the reset vectors */
1558  if ((address % 0x400) != 0x0) {
1559  retval = xscale_load_ic(target, address,
1560  cache_line);
1561  if (retval != ERROR_OK)
1562  return retval;
1563  }
1564 
1565  address += buf_cnt;
1566  }
1567 
1568  retval = xscale_load_ic(target, 0x0,
1569  xscale->low_vectors);
1570  if (retval != ERROR_OK)
1571  return retval;
1572  retval = xscale_load_ic(target, 0xffff0000,
1573  xscale->high_vectors);
1574  if (retval != ERROR_OK)
1575  return retval;
1576 
1578 
1579  jtag_add_sleep(100000);
1580 
1581  /* set Hold reset, Halt mode and Trap Reset */
1582  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 30, 1, 0x1);
1583  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 16, 1, 0x1);
1584  xscale_write_dcsr(target, 1, 0);
1585 
1586  /* clear Hold reset to let the target run (should enter debug handler) */
1587  xscale_write_dcsr(target, 0, 1);
1589 
1590  if (!target->reset_halt) {
1591  jtag_add_sleep(10000);
1592 
1593  /* we should have entered debug now */
1596 
1597  /* resume the target */
1598  xscale_resume(target, true, 0x0, true, false);
1599  }
1600  }
1601 
1602  return ERROR_OK;
1603 }
1604 
1605 static int xscale_read_core_reg(struct target *target, struct reg *r,
1606  int num, enum arm_mode mode)
1607 {
1609  LOG_ERROR("not implemented");
1610  return ERROR_OK;
1611 }
1612 
1613 static int xscale_write_core_reg(struct target *target, struct reg *r,
1614  int num, enum arm_mode mode, uint8_t *value)
1615 {
1617  LOG_ERROR("not implemented");
1618  return ERROR_OK;
1619 }
1620 
1621 static int xscale_full_context(struct target *target)
1622 {
1623  struct arm *arm = target_to_arm(target);
1624 
1625  uint32_t *buffer;
1626 
1627  int i, j;
1628 
1629  LOG_DEBUG("-");
1630 
1631  if (target->state != TARGET_HALTED) {
1632  LOG_TARGET_ERROR(target, "not halted");
1633  return ERROR_TARGET_NOT_HALTED;
1634  }
1635 
1636  buffer = malloc(4 * 8);
1637 
1638  /* iterate through processor modes (FIQ, IRQ, SVC, ABT, UND and SYS)
1639  * we can't enter User mode on an XScale (unpredictable),
1640  * but User shares registers with SYS
1641  */
1642  for (i = 1; i < 7; i++) {
1644  bool valid = true;
1645  struct reg *r;
1646 
1647  if (mode == ARM_MODE_USR)
1648  continue;
1649 
1650  /* check if there are invalid registers in the current mode
1651  */
1652  for (j = 0; valid && j <= 16; j++) {
1654  mode, j).valid)
1655  valid = false;
1656  }
1657  if (valid)
1658  continue;
1659 
1660  /* request banked registers */
1661  xscale_send_u32(target, 0x0);
1662 
1663  /* send CPSR for desired bank mode */
1664  xscale_send_u32(target, mode | 0xc0 /* I/F bits */);
1665 
1666  /* get banked registers: r8 to r14; and SPSR
1667  * except in USR/SYS mode
1668  */
1669  if (mode != ARM_MODE_SYS) {
1670  /* SPSR */
1672  mode, 16);
1673 
1675 
1676  buf_set_u32(r->value, 0, 32, buffer[7]);
1677  r->dirty = false;
1678  r->valid = true;
1679  } else
1681 
1682  /* move data from buffer to register cache */
1683  for (j = 8; j <= 14; j++) {
1685  mode, j);
1686 
1687  buf_set_u32(r->value, 0, 32, buffer[j - 8]);
1688  r->dirty = false;
1689  r->valid = true;
1690  }
1691  }
1692 
1693  free(buffer);
1694 
1695  return ERROR_OK;
1696 }
1697 
1699 {
1700  struct arm *arm = target_to_arm(target);
1701 
1702  int i, j;
1703 
1704  if (target->state != TARGET_HALTED) {
1705  LOG_TARGET_ERROR(target, "not halted");
1706  return ERROR_TARGET_NOT_HALTED;
1707  }
1708 
1709  /* iterate through processor modes (FIQ, IRQ, SVC, ABT, UND and SYS)
1710  * and check if any banked registers need to be written. Ignore
1711  * USR mode (number 0) in favor of SYS; we can't enter User mode on
1712  * an XScale (unpredictable), but they share all registers.
1713  */
1714  for (i = 1; i < 7; i++) {
1716  struct reg *r;
1717 
1718  if (mode == ARM_MODE_USR)
1719  continue;
1720 
1721  /* check if there are dirty registers in this mode */
1722  for (j = 8; j <= 14; j++) {
1724  mode, j).dirty)
1725  goto dirty;
1726  }
1727 
1728  /* if not USR/SYS, check if the SPSR needs to be written */
1729  if (mode != ARM_MODE_SYS) {
1731  mode, 16).dirty)
1732  goto dirty;
1733  }
1734 
1735  /* there's nothing to flush for this mode */
1736  continue;
1737 
1738 dirty:
1739  /* command 0x1: "send banked registers" */
1740  xscale_send_u32(target, 0x1);
1741 
1742  /* send CPSR for desired mode */
1743  xscale_send_u32(target, mode | 0xc0 /* I/F bits */);
1744 
1745  /* send r8 to r14/lr ... only FIQ needs more than r13..r14,
1746  * but this protocol doesn't understand that nuance.
1747  */
1748  for (j = 8; j <= 14; j++) {
1750  mode, j);
1751  xscale_send_u32(target, buf_get_u32(r->value, 0, 32));
1752  r->dirty = false;
1753  }
1754 
1755  /* send spsr if not in USR/SYS mode */
1756  if (mode != ARM_MODE_SYS) {
1758  mode, 16);
1759  xscale_send_u32(target, buf_get_u32(r->value, 0, 32));
1760  r->dirty = false;
1761  }
1762  }
1763 
1764  return ERROR_OK;
1765 }
1766 
1768  uint32_t size, uint32_t count, uint8_t *buffer)
1769 {
1770  struct xscale_common *xscale = target_to_xscale(target);
1771  uint32_t *buf32;
1772  uint32_t i;
1773  int retval;
1774 
1775  LOG_DEBUG("address: " TARGET_ADDR_FMT ", size: 0x%8.8" PRIx32 ", count: 0x%8.8" PRIx32,
1776  address,
1777  size,
1778  count);
1779 
1780  if (target->state != TARGET_HALTED) {
1781  LOG_TARGET_ERROR(target, "not halted");
1782  return ERROR_TARGET_NOT_HALTED;
1783  }
1784 
1785  /* sanitize arguments */
1786  if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !(buffer))
1788 
1789  if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u)))
1791 
1792  /* send memory read request (command 0x1n, n: access size) */
1793  retval = xscale_send_u32(target, 0x10 | size);
1794  if (retval != ERROR_OK)
1795  return retval;
1796 
1797  /* send base address for read request */
1798  retval = xscale_send_u32(target, address);
1799  if (retval != ERROR_OK)
1800  return retval;
1801 
1802  /* send number of requested data words */
1803  retval = xscale_send_u32(target, count);
1804  if (retval != ERROR_OK)
1805  return retval;
1806 
1807  /* receive data from target (count times 32-bit words in host endianness) */
1808  buf32 = malloc(4 * count);
1809  retval = xscale_receive(target, buf32, count);
1810  if (retval != ERROR_OK) {
1811  free(buf32);
1812  return retval;
1813  }
1814 
1815  /* extract data from host-endian buffer into byte stream */
1816  for (i = 0; i < count; i++) {
1817  switch (size) {
1818  case 4:
1819  target_buffer_set_u32(target, buffer, buf32[i]);
1820  buffer += 4;
1821  break;
1822  case 2:
1823  target_buffer_set_u16(target, buffer, buf32[i] & 0xffff);
1824  buffer += 2;
1825  break;
1826  case 1:
1827  *buffer++ = buf32[i] & 0xff;
1828  break;
1829  default:
1830  LOG_ERROR("invalid read size");
1832  }
1833  }
1834 
1835  free(buf32);
1836 
1837  /* examine DCSR, to see if Sticky Abort (SA) got set */
1838  retval = xscale_read_dcsr(target);
1839  if (retval != ERROR_OK)
1840  return retval;
1841  if (buf_get_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 5, 1) == 1) {
1842  /* clear SA bit */
1843  retval = xscale_send_u32(target, 0x60);
1844  if (retval != ERROR_OK)
1845  return retval;
1846 
1847  return ERROR_TARGET_DATA_ABORT;
1848  }
1849 
1850  return ERROR_OK;
1851 }
1852 
1854  uint32_t size, uint32_t count, uint8_t *buffer)
1855 {
1856  struct xscale_common *xscale = target_to_xscale(target);
1857 
1858  /* with MMU inactive, there are only physical addresses */
1859  if (!xscale->armv4_5_mmu.mmu_enabled)
1861 
1863  LOG_ERROR("%s: %s is not implemented. Disable MMU?",
1864  target_name(target), __func__);
1865  return ERROR_FAIL;
1866 }
1867 
1869  uint32_t size, uint32_t count, const uint8_t *buffer)
1870 {
1871  struct xscale_common *xscale = target_to_xscale(target);
1872  int retval;
1873 
1874  LOG_DEBUG("address: " TARGET_ADDR_FMT ", size: 0x%8.8" PRIx32 ", count: 0x%8.8" PRIx32,
1875  address,
1876  size,
1877  count);
1878 
1879  if (target->state != TARGET_HALTED) {
1880  LOG_TARGET_ERROR(target, "not halted");
1881  return ERROR_TARGET_NOT_HALTED;
1882  }
1883 
1884  /* sanitize arguments */
1885  if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !(buffer))
1887 
1888  if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u)))
1890 
1891  /* send memory write request (command 0x2n, n: access size) */
1892  retval = xscale_send_u32(target, 0x20 | size);
1893  if (retval != ERROR_OK)
1894  return retval;
1895 
1896  /* send base address for read request */
1897  retval = xscale_send_u32(target, address);
1898  if (retval != ERROR_OK)
1899  return retval;
1900 
1901  /* send number of requested data words to be written*/
1902  retval = xscale_send_u32(target, count);
1903  if (retval != ERROR_OK)
1904  return retval;
1905 
1906  /* extract data from host-endian buffer into byte stream */
1907 #if 0
1908  for (i = 0; i < count; i++) {
1909  switch (size) {
1910  case 4:
1912  xscale_send_u32(target, value);
1913  buffer += 4;
1914  break;
1915  case 2:
1917  xscale_send_u32(target, value);
1918  buffer += 2;
1919  break;
1920  case 1:
1921  value = *buffer;
1922  xscale_send_u32(target, value);
1923  buffer += 1;
1924  break;
1925  default:
1926  LOG_ERROR("should never get here");
1927  exit(-1);
1928  }
1929  }
1930 #endif
1931  retval = xscale_send(target, buffer, count, size);
1932  if (retval != ERROR_OK)
1933  return retval;
1934 
1935  /* examine DCSR, to see if Sticky Abort (SA) got set */
1936  retval = xscale_read_dcsr(target);
1937  if (retval != ERROR_OK)
1938  return retval;
1939  if (buf_get_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 5, 1) == 1) {
1940  /* clear SA bit */
1941  retval = xscale_send_u32(target, 0x60);
1942  if (retval != ERROR_OK)
1943  return retval;
1944 
1945  LOG_ERROR("data abort writing memory");
1946  return ERROR_TARGET_DATA_ABORT;
1947  }
1948 
1949  return ERROR_OK;
1950 }
1951 
1953  uint32_t size, uint32_t count, const uint8_t *buffer)
1954 {
1955  struct xscale_common *xscale = target_to_xscale(target);
1956 
1957  /* with MMU inactive, there are only physical addresses */
1958  if (!xscale->armv4_5_mmu.mmu_enabled)
1960 
1962  LOG_ERROR("%s: %s is not implemented. Disable MMU?",
1963  target_name(target), __func__);
1964  return ERROR_FAIL;
1965 }
1966 
1967 static int xscale_get_ttb(struct target *target, uint32_t *result)
1968 {
1969  struct xscale_common *xscale = target_to_xscale(target);
1970  uint32_t ttb;
1971  int retval;
1972 
1973  retval = xscale_get_reg(&xscale->reg_cache->reg_list[XSCALE_TTB]);
1974  if (retval != ERROR_OK)
1975  return retval;
1976  ttb = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_TTB].value, 0, 32);
1977 
1978  *result = ttb;
1979 
1980  return ERROR_OK;
1981 }
1982 
1983 static int xscale_disable_mmu_caches(struct target *target, int mmu,
1984  int d_u_cache, int i_cache)
1985 {
1986  struct xscale_common *xscale = target_to_xscale(target);
1987  uint32_t cp15_control;
1988  int retval;
1989 
1990  /* read cp15 control register */
1991  retval = xscale_get_reg(&xscale->reg_cache->reg_list[XSCALE_CTRL]);
1992  if (retval != ERROR_OK)
1993  return retval;
1994  cp15_control = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_CTRL].value, 0, 32);
1995 
1996  if (mmu)
1997  cp15_control &= ~0x1U;
1998 
1999  if (d_u_cache) {
2000  /* clean DCache */
2001  retval = xscale_send_u32(target, 0x50);
2002  if (retval != ERROR_OK)
2003  return retval;
2004  retval = xscale_send_u32(target, xscale->cache_clean_address);
2005  if (retval != ERROR_OK)
2006  return retval;
2007 
2008  /* invalidate DCache */
2009  retval = xscale_send_u32(target, 0x51);
2010  if (retval != ERROR_OK)
2011  return retval;
2012 
2013  cp15_control &= ~0x4U;
2014  }
2015 
2016  if (i_cache) {
2017  /* invalidate ICache */
2018  retval = xscale_send_u32(target, 0x52);
2019  if (retval != ERROR_OK)
2020  return retval;
2021  cp15_control &= ~0x1000U;
2022  }
2023 
2024  /* write new cp15 control register */
2025  retval = xscale_set_reg_u32(&xscale->reg_cache->reg_list[XSCALE_CTRL], cp15_control);
2026  if (retval != ERROR_OK)
2027  return retval;
2028 
2029  /* execute cpwait to ensure outstanding operations complete */
2030  return xscale_send_u32(target, 0x53);
2031 }
2032 
2033 static int xscale_enable_mmu_caches(struct target *target, int mmu,
2034  int d_u_cache, int i_cache)
2035 {
2036  struct xscale_common *xscale = target_to_xscale(target);
2037  uint32_t cp15_control;
2038  int retval;
2039 
2040  /* read cp15 control register */
2041  retval = xscale_get_reg(&xscale->reg_cache->reg_list[XSCALE_CTRL]);
2042  if (retval != ERROR_OK)
2043  return retval;
2044  cp15_control = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_CTRL].value, 0, 32);
2045 
2046  if (mmu)
2047  cp15_control |= 0x1U;
2048 
2049  if (d_u_cache)
2050  cp15_control |= 0x4U;
2051 
2052  if (i_cache)
2053  cp15_control |= 0x1000U;
2054 
2055  /* write new cp15 control register */
2056  retval = xscale_set_reg_u32(&xscale->reg_cache->reg_list[XSCALE_CTRL], cp15_control);
2057  if (retval != ERROR_OK)
2058  return retval;
2059 
2060  /* execute cpwait to ensure outstanding operations complete */
2061  return xscale_send_u32(target, 0x53);
2062 }
2063 
2065  struct breakpoint *breakpoint)
2066 {
2067  int retval;
2068  struct xscale_common *xscale = target_to_xscale(target);
2069 
2070  if (target->state != TARGET_HALTED) {
2071  LOG_TARGET_ERROR(target, "not halted");
2072  return ERROR_TARGET_NOT_HALTED;
2073  }
2074 
2075  if (breakpoint->is_set) {
2076  LOG_WARNING("breakpoint already set");
2077  return ERROR_OK;
2078  }
2079 
2080  if (breakpoint->type == BKPT_HARD) {
2081  uint32_t value = breakpoint->address | 1;
2082  if (!xscale->ibcr0_used) {
2084  xscale->ibcr0_used = 1;
2085  /* breakpoint set on first breakpoint register */
2087  } else if (!xscale->ibcr1_used) {
2089  xscale->ibcr1_used = 1;
2090  /* breakpoint set on second breakpoint register */
2092  } else {/* bug: availability previously verified in xscale_add_breakpoint() */
2093  LOG_ERROR("BUG: no hardware comparator available");
2095  }
2096  } else if (breakpoint->type == BKPT_SOFT) {
2097  if (breakpoint->length == 4) {
2098  /* keep the original instruction in target endianness */
2099  retval = target_read_memory(target, breakpoint->address, 4, 1,
2101  if (retval != ERROR_OK)
2102  return retval;
2103  /* write the bkpt instruction in target endianness
2104  *(arm7_9->arm_bkpt is host endian) */
2106  xscale->arm_bkpt);
2107  if (retval != ERROR_OK)
2108  return retval;
2109  } else {
2110  /* keep the original instruction in target endianness */
2111  retval = target_read_memory(target, breakpoint->address, 2, 1,
2113  if (retval != ERROR_OK)
2114  return retval;
2115  /* write the bkpt instruction in target endianness
2116  *(arm7_9->arm_bkpt is host endian) */
2118  xscale->thumb_bkpt);
2119  if (retval != ERROR_OK)
2120  return retval;
2121  }
2122  breakpoint->is_set = true;
2123 
2124  xscale_send_u32(target, 0x50); /* clean dcache */
2126  xscale_send_u32(target, 0x51); /* invalidate dcache */
2127  xscale_send_u32(target, 0x52); /* invalidate icache and flush fetch buffers */
2128  }
2129 
2130  return ERROR_OK;
2131 }
2132 
2134  struct breakpoint *breakpoint)
2135 {
2136  struct xscale_common *xscale = target_to_xscale(target);
2137 
2138  if ((breakpoint->type == BKPT_HARD) && (xscale->ibcr_available < 1)) {
2139  LOG_ERROR("no breakpoint unit available for hardware breakpoint");
2141  }
2142 
2143  if ((breakpoint->length != 2) && (breakpoint->length != 4)) {
2144  LOG_ERROR("only breakpoints of two (Thumb) or four (ARM) bytes length supported");
2146  }
2147 
2148  if (breakpoint->type == BKPT_HARD)
2149  xscale->ibcr_available--;
2150 
2152 }
2153 
2155  struct breakpoint *breakpoint)
2156 {
2157  int retval;
2158  struct xscale_common *xscale = target_to_xscale(target);
2159 
2160  if (target->state != TARGET_HALTED) {
2161  LOG_TARGET_ERROR(target, "not halted");
2162  return ERROR_TARGET_NOT_HALTED;
2163  }
2164 
2165  if (!breakpoint->is_set) {
2166  LOG_WARNING("breakpoint not set");
2167  return ERROR_OK;
2168  }
2169 
2170  if (breakpoint->type == BKPT_HARD) {
2171  if (breakpoint->number == 0) {
2173  xscale->ibcr0_used = 0;
2174  } else if (breakpoint->number == 1) {
2176  xscale->ibcr1_used = 0;
2177  }
2178  breakpoint->is_set = false;
2179  } else {
2180  /* restore original instruction (kept in target endianness) */
2181  if (breakpoint->length == 4) {
2182  retval = target_write_memory(target, breakpoint->address, 4, 1,
2184  if (retval != ERROR_OK)
2185  return retval;
2186  } else {
2187  retval = target_write_memory(target, breakpoint->address, 2, 1,
2189  if (retval != ERROR_OK)
2190  return retval;
2191  }
2192  breakpoint->is_set = false;
2193 
2194  xscale_send_u32(target, 0x50); /* clean dcache */
2196  xscale_send_u32(target, 0x51); /* invalidate dcache */
2197  xscale_send_u32(target, 0x52); /* invalidate icache and flush fetch buffers */
2198  }
2199 
2200  return ERROR_OK;
2201 }
2202 
2204 {
2205  struct xscale_common *xscale = target_to_xscale(target);
2206 
2207  if (target->state != TARGET_HALTED) {
2208  LOG_TARGET_ERROR(target, "not halted");
2209  return ERROR_TARGET_NOT_HALTED;
2210  }
2211 
2212  if (breakpoint->is_set)
2214 
2215  if (breakpoint->type == BKPT_HARD)
2216  xscale->ibcr_available++;
2217 
2218  return ERROR_OK;
2219 }
2220 
2222  struct watchpoint *watchpoint)
2223 {
2224  struct xscale_common *xscale = target_to_xscale(target);
2225  uint32_t enable = 0;
2226  struct reg *dbcon = &xscale->reg_cache->reg_list[XSCALE_DBCON];
2227  uint32_t dbcon_value = buf_get_u32(dbcon->value, 0, 32);
2228 
2229  if (target->state != TARGET_HALTED) {
2230  LOG_TARGET_ERROR(target, "not halted");
2231  return ERROR_TARGET_NOT_HALTED;
2232  }
2233 
2234  switch (watchpoint->rw) {
2235  case WPT_READ:
2236  enable = 0x3;
2237  break;
2238  case WPT_ACCESS:
2239  enable = 0x2;
2240  break;
2241  case WPT_WRITE:
2242  enable = 0x1;
2243  break;
2244  default:
2245  LOG_ERROR("BUG: watchpoint->rw neither read, write nor access");
2246  }
2247 
2248  /* For watchpoint across more than one word, both DBR registers must
2249  be enlisted, with the second used as a mask. */
2250  if (watchpoint->length > 4) {
2251  if (xscale->dbr0_used || xscale->dbr1_used) {
2252  LOG_ERROR("BUG: sufficient hardware comparators unavailable");
2254  }
2255 
2256  /* Write mask value to DBR1, based on the length argument.
2257  * Address bits ignored by the comparator are those set in mask. */
2259  watchpoint->length - 1);
2260  xscale->dbr1_used = 1;
2261  enable |= 0x100; /* DBCON[M] */
2262  }
2263 
2264  if (!xscale->dbr0_used) {
2266  dbcon_value |= enable;
2267  xscale_set_reg_u32(dbcon, dbcon_value);
2269  xscale->dbr0_used = 1;
2270  } else if (!xscale->dbr1_used) {
2272  dbcon_value |= enable << 2;
2273  xscale_set_reg_u32(dbcon, dbcon_value);
2275  xscale->dbr1_used = 1;
2276  } else {
2277  LOG_ERROR("BUG: no hardware comparator available");
2279  }
2280 
2281  return ERROR_OK;
2282 }
2283 
2285  struct watchpoint *watchpoint)
2286 {
2287  struct xscale_common *xscale = target_to_xscale(target);
2288 
2289  if (xscale->dbr_available < 1) {
2290  LOG_ERROR("no more watchpoint registers available");
2292  }
2293 
2295  LOG_WARNING("xscale does not support value, mask arguments; ignoring");
2296 
2297  /* check that length is a power of two */
2298  for (uint32_t len = watchpoint->length; len != 1; len /= 2) {
2299  if (len % 2) {
2300  LOG_ERROR("xscale requires that watchpoint length is a power of two");
2302  }
2303  }
2304 
2305  if (watchpoint->length == 4) { /* single word watchpoint */
2306  xscale->dbr_available--;/* one DBR reg used */
2307  return ERROR_OK;
2308  }
2309 
2310  /* watchpoints across multiple words require both DBR registers */
2311  if (xscale->dbr_available < 2) {
2312  LOG_ERROR("insufficient watchpoint registers available");
2314  }
2315 
2316  if (watchpoint->length > watchpoint->address) {
2317  LOG_ERROR("xscale does not support watchpoints with length "
2318  "greater than address");
2320  }
2321 
2322  xscale->dbr_available = 0;
2323  return ERROR_OK;
2324 }
2325 
2327  struct watchpoint *watchpoint)
2328 {
2329  struct xscale_common *xscale = target_to_xscale(target);
2330  struct reg *dbcon = &xscale->reg_cache->reg_list[XSCALE_DBCON];
2331  uint32_t dbcon_value = buf_get_u32(dbcon->value, 0, 32);
2332 
2333  if (target->state != TARGET_HALTED) {
2334  LOG_TARGET_ERROR(target, "not halted");
2335  return ERROR_TARGET_NOT_HALTED;
2336  }
2337 
2338  if (!watchpoint->is_set) {
2339  LOG_WARNING("breakpoint not set");
2340  return ERROR_OK;
2341  }
2342 
2343  if (watchpoint->number == 0) {
2344  if (watchpoint->length > 4) {
2345  dbcon_value &= ~0x103; /* clear DBCON[M] as well */
2346  xscale->dbr1_used = 0; /* DBR1 was used for mask */
2347  } else
2348  dbcon_value &= ~0x3;
2349 
2350  xscale_set_reg_u32(dbcon, dbcon_value);
2351  xscale->dbr0_used = 0;
2352  } else if (watchpoint->number == 1) {
2353  dbcon_value &= ~0xc;
2354  xscale_set_reg_u32(dbcon, dbcon_value);
2355  xscale->dbr1_used = 0;
2356  }
2357  watchpoint->is_set = false;
2358 
2359  return ERROR_OK;
2360 }
2361 
2363 {
2364  struct xscale_common *xscale = target_to_xscale(target);
2365 
2366  if (target->state != TARGET_HALTED) {
2367  LOG_TARGET_ERROR(target, "not halted");
2368  return ERROR_TARGET_NOT_HALTED;
2369  }
2370 
2371  if (watchpoint->is_set)
2373 
2374  if (watchpoint->length > 4)
2375  xscale->dbr_available++;/* both DBR regs now available */
2376 
2377  xscale->dbr_available++;
2378 
2379  return ERROR_OK;
2380 }
2381 
2382 static int xscale_get_reg(struct reg *reg)
2383 {
2384  struct xscale_reg *arch_info = reg->arch_info;
2385  struct target *target = arch_info->target;
2386  struct xscale_common *xscale = target_to_xscale(target);
2387 
2388  /* DCSR, TX and RX are accessible via JTAG */
2389  if (strcmp(reg->name, "XSCALE_DCSR") == 0)
2390  return xscale_read_dcsr(arch_info->target);
2391  else if (strcmp(reg->name, "XSCALE_TX") == 0) {
2392  /* 1 = consume register content */
2393  return xscale_read_tx(arch_info->target, 1);
2394  } else if (strcmp(reg->name, "XSCALE_RX") == 0) {
2395  /* can't read from RX register (host -> debug handler) */
2396  return ERROR_OK;
2397  } else if (strcmp(reg->name, "XSCALE_TXRXCTRL") == 0) {
2398  /* can't (explicitly) read from TXRXCTRL register */
2399  return ERROR_OK;
2400  } else {/* Other DBG registers have to be transferred by the debug handler
2401  * send CP read request (command 0x40) */
2402  xscale_send_u32(target, 0x40);
2403 
2404  /* send CP register number */
2406 
2407  /* read register value */
2408  xscale_read_tx(target, 1);
2409  buf_cpy(xscale->reg_cache->reg_list[XSCALE_TX].value, reg->value, 32);
2410 
2411  reg->dirty = false;
2412  reg->valid = true;
2413  }
2414 
2415  return ERROR_OK;
2416 }
2417 
2418 static int xscale_set_reg(struct reg *reg, uint8_t *buf)
2419 {
2420  struct xscale_reg *arch_info = reg->arch_info;
2421  struct target *target = arch_info->target;
2422  struct xscale_common *xscale = target_to_xscale(target);
2423  uint32_t value = buf_get_u32(buf, 0, 32);
2424 
2425  /* DCSR, TX and RX are accessible via JTAG */
2426  if (strcmp(reg->name, "XSCALE_DCSR") == 0) {
2427  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 0, 32, value);
2428  return xscale_write_dcsr(arch_info->target, -1, -1);
2429  } else if (strcmp(reg->name, "XSCALE_RX") == 0) {
2430  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_RX].value, 0, 32, value);
2431  return xscale_write_rx(arch_info->target);
2432  } else if (strcmp(reg->name, "XSCALE_TX") == 0) {
2433  /* can't write to TX register (debug-handler -> host) */
2434  return ERROR_OK;
2435  } else if (strcmp(reg->name, "XSCALE_TXRXCTRL") == 0) {
2436  /* can't (explicitly) write to TXRXCTRL register */
2437  return ERROR_OK;
2438  } else {/* Other DBG registers have to be transferred by the debug handler
2439  * send CP write request (command 0x41) */
2440  xscale_send_u32(target, 0x41);
2441 
2442  /* send CP register number */
2444 
2445  /* send CP register value */
2446  xscale_send_u32(target, value);
2447  buf_set_u32(reg->value, 0, 32, value);
2448  }
2449 
2450  return ERROR_OK;
2451 }
2452 
2453 static int xscale_write_dcsr_sw(struct target *target, uint32_t value)
2454 {
2455  struct xscale_common *xscale = target_to_xscale(target);
2456  struct reg *dcsr = &xscale->reg_cache->reg_list[XSCALE_DCSR];
2457  struct xscale_reg *dcsr_arch_info = dcsr->arch_info;
2458 
2459  /* send CP write request (command 0x41) */
2460  xscale_send_u32(target, 0x41);
2461 
2462  /* send CP register number */
2463  xscale_send_u32(target, dcsr_arch_info->dbg_handler_number);
2464 
2465  /* send CP register value */
2466  xscale_send_u32(target, value);
2467  buf_set_u32(dcsr->value, 0, 32, value);
2468 
2469  return ERROR_OK;
2470 }
2471 
2472 static int xscale_read_trace(struct target *target)
2473 {
2474  struct xscale_common *xscale = target_to_xscale(target);
2475  struct arm *arm = &xscale->arm;
2476  struct xscale_trace_data **trace_data_p;
2477 
2478  /* 258 words from debug handler
2479  * 256 trace buffer entries
2480  * 2 checkpoint addresses
2481  */
2482  uint32_t trace_buffer[258];
2483  int is_address[256];
2484  int i, j;
2485  unsigned int num_checkpoints = 0;
2486 
2487  if (target->state != TARGET_HALTED) {
2488  LOG_TARGET_ERROR(target, "must be stopped to read trace data");
2489  return ERROR_TARGET_NOT_HALTED;
2490  }
2491 
2492  /* send read trace buffer command (command 0x61) */
2493  xscale_send_u32(target, 0x61);
2494 
2495  /* receive trace buffer content */
2496  xscale_receive(target, trace_buffer, 258);
2497 
2498  /* parse buffer backwards to identify address entries */
2499  for (i = 255; i >= 0; i--) {
2500  /* also count number of checkpointed entries */
2501  if ((trace_buffer[i] & 0xe0) == 0xc0)
2502  num_checkpoints++;
2503 
2504  is_address[i] = 0;
2505  if (((trace_buffer[i] & 0xf0) == 0x90) ||
2506  ((trace_buffer[i] & 0xf0) == 0xd0)) {
2507  if (i > 0)
2508  is_address[--i] = 1;
2509  if (i > 0)
2510  is_address[--i] = 1;
2511  if (i > 0)
2512  is_address[--i] = 1;
2513  if (i > 0)
2514  is_address[--i] = 1;
2515  }
2516  }
2517 
2518 
2519  /* search first non-zero entry that is not part of an address */
2520  for (j = 0; (j < 256) && (trace_buffer[j] == 0) && (!is_address[j]); j++)
2521  ;
2522 
2523  if (j == 256) {
2524  LOG_DEBUG("no trace data collected");
2526  }
2527 
2528  /* account for possible partial address at buffer start (wrap mode only) */
2529  if (is_address[0]) { /* first entry is address; complete set of 4? */
2530  i = 1;
2531  while (i < 4)
2532  if (!is_address[i++])
2533  break;
2534  if (i < 4)
2535  j += i; /* partial address; can't use it */
2536  }
2537 
2538  /* if first valid entry is indirect branch, can't use that either (no address) */
2539  if (((trace_buffer[j] & 0xf0) == 0x90) || ((trace_buffer[j] & 0xf0) == 0xd0))
2540  j++;
2541 
2542  /* walk linked list to terminating entry */
2543  for (trace_data_p = &xscale->trace.data; *trace_data_p;
2544  trace_data_p = &(*trace_data_p)->next)
2545  ;
2546 
2547  *trace_data_p = malloc(sizeof(struct xscale_trace_data));
2548  (*trace_data_p)->next = NULL;
2549  (*trace_data_p)->chkpt0 = trace_buffer[256];
2550  (*trace_data_p)->chkpt1 = trace_buffer[257];
2551  (*trace_data_p)->last_instruction = buf_get_u32(arm->pc->value, 0, 32);
2552  (*trace_data_p)->entries = malloc(sizeof(struct xscale_trace_entry) * (256 - j));
2553  (*trace_data_p)->depth = 256 - j;
2554  (*trace_data_p)->num_checkpoints = num_checkpoints;
2555 
2556  for (i = j; i < 256; i++) {
2557  (*trace_data_p)->entries[i - j].data = trace_buffer[i];
2558  if (is_address[i])
2559  (*trace_data_p)->entries[i - j].type = XSCALE_TRACE_ADDRESS;
2560  else
2561  (*trace_data_p)->entries[i - j].type = XSCALE_TRACE_MESSAGE;
2562  }
2563 
2564  return ERROR_OK;
2565 }
2566 
2567 static int xscale_read_instruction(struct target *target, uint32_t pc,
2568  struct arm_instruction *instruction)
2569 {
2570  struct xscale_common *const xscale = target_to_xscale(target);
2571  int section = -1;
2572  size_t size_read;
2573  uint32_t opcode;
2574  int retval;
2575 
2576  if (!xscale->trace.image)
2578 
2579  /* search for the section the current instruction belongs to */
2580  for (unsigned int i = 0; i < xscale->trace.image->num_sections; i++) {
2581  if ((xscale->trace.image->sections[i].base_address <= pc) &&
2582  (xscale->trace.image->sections[i].base_address +
2583  xscale->trace.image->sections[i].size > pc)) {
2584  section = i;
2585  break;
2586  }
2587  }
2588 
2589  if (section == -1) {
2590  /* current instruction couldn't be found in the image */
2592  }
2593 
2594  if (xscale->trace.core_state == ARM_STATE_ARM) {
2595  uint8_t buf[4];
2596  retval = image_read_section(xscale->trace.image, section,
2597  pc - xscale->trace.image->sections[section].base_address,
2598  4, buf, &size_read);
2599  if (retval != ERROR_OK) {
2600  LOG_ERROR("error while reading instruction");
2602  }
2603  opcode = target_buffer_get_u32(target, buf);
2604  arm_evaluate_opcode(opcode, pc, instruction);
2605  } else if (xscale->trace.core_state == ARM_STATE_THUMB) {
2606  uint8_t buf[2];
2607  retval = image_read_section(xscale->trace.image, section,
2608  pc - xscale->trace.image->sections[section].base_address,
2609  2, buf, &size_read);
2610  if (retval != ERROR_OK) {
2611  LOG_ERROR("error while reading instruction");
2613  }
2614  opcode = target_buffer_get_u16(target, buf);
2615  thumb_evaluate_opcode(opcode, pc, instruction);
2616  } else {
2617  LOG_ERROR("BUG: unknown core state encountered");
2618  exit(-1);
2619  }
2620 
2621  return ERROR_OK;
2622 }
2623 
2624 /* Extract address encoded into trace data.
2625  * Write result to address referenced by argument 'target', or 0 if incomplete. */
2626 static inline void xscale_branch_address(struct xscale_trace_data *trace_data,
2627  int i, uint32_t *target)
2628 {
2629  /* if there are less than four entries prior to the indirect branch message
2630  * we can't extract the address */
2631  if (i < 4)
2632  *target = 0;
2633  else {
2634  *target = (trace_data->entries[i-1].data) | (trace_data->entries[i-2].data << 8) |
2635  (trace_data->entries[i-3].data << 16) | (trace_data->entries[i-4].data << 24);
2636  }
2637 }
2638 
2639 static inline void xscale_display_instruction(struct target *target, uint32_t pc,
2640  struct arm_instruction *instruction,
2641  struct command_invocation *cmd)
2642 {
2643  int retval = xscale_read_instruction(target, pc, instruction);
2644  if (retval == ERROR_OK)
2645  command_print(cmd, "%s", instruction->text);
2646  else
2647  command_print(cmd, "0x%8.8" PRIx32 "\t<not found in image>", pc);
2648 }
2649 
2651 {
2652  struct xscale_common *xscale = target_to_xscale(target);
2653  struct xscale_trace_data *trace_data = xscale->trace.data;
2654  int i, retval;
2655  uint32_t breakpoint_pc = 0;
2656  struct arm_instruction instruction;
2657  uint32_t current_pc = 0;/* initialized when address determined */
2658 
2659  if (!xscale->trace.image)
2660  LOG_WARNING("No trace image loaded; use 'xscale trace_image'");
2661 
2662  /* loop for each trace buffer that was loaded from target */
2663  while (trace_data) {
2664  int chkpt = 0; /* incremented as checkpointed entries found */
2665  int j;
2666 
2667  /* FIXME: set this to correct mode when trace buffer is first enabled */
2668  xscale->trace.core_state = ARM_STATE_ARM;
2669 
2670  /* loop for each entry in this trace buffer */
2671  for (i = 0; i < trace_data->depth; i++) {
2672  int exception = 0;
2673  uint32_t chkpt_reg = 0x0;
2674  uint32_t branch_target = 0;
2675  int count;
2676 
2677  /* trace entry type is upper nybble of 'message byte' */
2678  int trace_msg_type = (trace_data->entries[i].data & 0xf0) >> 4;
2679 
2680  /* Target addresses of indirect branches are written into buffer
2681  * before the message byte representing the branch. Skip past it */
2682  if (trace_data->entries[i].type == XSCALE_TRACE_ADDRESS)
2683  continue;
2684 
2685  switch (trace_msg_type) {
2686  case 0: /* Exceptions */
2687  case 1:
2688  case 2:
2689  case 3:
2690  case 4:
2691  case 5:
2692  case 6:
2693  case 7:
2694  exception = (trace_data->entries[i].data & 0x70) >> 4;
2695 
2696  /* FIXME: vector table may be at ffff0000 */
2697  branch_target = (trace_data->entries[i].data & 0xf0) >> 2;
2698  break;
2699 
2700  case 8: /* Direct Branch */
2701  break;
2702 
2703  case 9: /* Indirect Branch */
2704  xscale_branch_address(trace_data, i, &branch_target);
2705  break;
2706 
2707  case 13: /* Checkpointed Indirect Branch */
2708  xscale_branch_address(trace_data, i, &branch_target);
2709  if (trace_data->num_checkpoints == 2 && chkpt == 0)
2710  chkpt_reg = trace_data->chkpt1; /* 2 chkpts, this is
2711  *oldest */
2712  else
2713  chkpt_reg = trace_data->chkpt0; /* 1 chkpt, or 2 and
2714  *newest */
2715 
2716  chkpt++;
2717  break;
2718 
2719  case 12: /* Checkpointed Direct Branch */
2720  if (trace_data->num_checkpoints == 2 && chkpt == 0)
2721  chkpt_reg = trace_data->chkpt1; /* 2 chkpts, this is
2722  *oldest */
2723  else
2724  chkpt_reg = trace_data->chkpt0; /* 1 chkpt, or 2 and
2725  *newest */
2726 
2727  /* if no current_pc, checkpoint will be starting point */
2728  if (current_pc == 0)
2729  branch_target = chkpt_reg;
2730 
2731  chkpt++;
2732  break;
2733 
2734  case 15:/* Roll-over */
2735  break;
2736 
2737  default:/* Reserved */
2738  LOG_WARNING("trace is suspect: invalid trace message byte");
2739  continue;
2740  }
2741 
2742  /* If we don't have the current_pc yet, but we did get the branch target
2743  * (either from the trace buffer on indirect branch, or from a checkpoint reg),
2744  * then we can start displaying instructions at the next iteration, with
2745  * branch_target as the starting point.
2746  */
2747  if (current_pc == 0) {
2748  current_pc = branch_target; /* remains 0 unless branch_target *obtained */
2749  continue;
2750  }
2751 
2752  /* We have current_pc. Read and display the instructions from the image.
2753  * First, display count instructions (lower nybble of message byte). */
2754  count = trace_data->entries[i].data & 0x0f;
2755  for (j = 0; j < count; j++) {
2756  xscale_display_instruction(target, current_pc, &instruction,
2757  cmd);
2758  current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2;
2759  }
2760 
2761  /* An additional instruction is implicitly added to count for
2762  * rollover and some exceptions: undef, swi, prefetch abort. */
2763  if ((trace_msg_type == 15) || (exception > 0 && exception < 4)) {
2764  xscale_display_instruction(target, current_pc, &instruction,
2765  cmd);
2766  current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2;
2767  }
2768 
2769  if (trace_msg_type == 15) /* rollover */
2770  continue;
2771 
2772  if (exception) {
2773  command_print(cmd, "--- exception %i ---", exception);
2774  continue;
2775  }
2776 
2777  /* not exception or rollover; next instruction is a branch and is
2778  * not included in the count */
2779  xscale_display_instruction(target, current_pc, &instruction, cmd);
2780 
2781  /* for direct branches, extract branch destination from instruction */
2782  if ((trace_msg_type == 8) || (trace_msg_type == 12)) {
2783  retval = xscale_read_instruction(target, current_pc, &instruction);
2784  if (retval == ERROR_OK)
2785  current_pc = instruction.info.b_bl_bx_blx.target_address;
2786  else
2787  current_pc = 0; /* branch destination unknown */
2788 
2789  /* direct branch w/ checkpoint; can also get from checkpoint reg */
2790  if (trace_msg_type == 12) {
2791  if (current_pc == 0)
2792  current_pc = chkpt_reg;
2793  else if (current_pc != chkpt_reg) /* sanity check */
2794  LOG_WARNING("trace is suspect: checkpoint register "
2795  "inconsistent with address from image");
2796  }
2797 
2798  if (current_pc == 0)
2799  command_print(cmd, "address unknown");
2800 
2801  continue;
2802  }
2803 
2804  /* indirect branch; the branch destination was read from trace buffer */
2805  if ((trace_msg_type == 9) || (trace_msg_type == 13)) {
2806  current_pc = branch_target;
2807 
2808  /* sanity check (checkpoint reg is redundant) */
2809  if ((trace_msg_type == 13) && (chkpt_reg != branch_target))
2810  LOG_WARNING("trace is suspect: checkpoint register "
2811  "inconsistent with address from trace buffer");
2812  }
2813 
2814  } /* END: for (i = 0; i < trace_data->depth; i++) */
2815 
2816  breakpoint_pc = trace_data->last_instruction; /* used below */
2817  trace_data = trace_data->next;
2818 
2819  } /* END: while (trace_data) */
2820 
2821  /* Finally... display all instructions up to the value of the pc when the
2822  * debug break occurred (saved when trace data was collected from target).
2823  * This is necessary because the trace only records execution branches and 16
2824  * consecutive instructions (rollovers), so last few typically missed.
2825  */
2826  if (current_pc == 0)
2827  return ERROR_OK;/* current_pc was never found */
2828 
2829  /* how many instructions remaining? */
2830  int gap_count = (breakpoint_pc - current_pc) /
2831  (xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2);
2832 
2833  /* should never be negative or over 16, but verify */
2834  if (gap_count < 0 || gap_count > 16) {
2835  LOG_WARNING("trace is suspect: excessive gap at end of trace");
2836  return ERROR_OK;/* bail; large number or negative value no good */
2837  }
2838 
2839  /* display remaining instructions */
2840  for (i = 0; i < gap_count; i++) {
2841  xscale_display_instruction(target, current_pc, &instruction, cmd);
2842  current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2;
2843  }
2844 
2845  return ERROR_OK;
2846 }
2847 
2848 static const struct reg_arch_type xscale_reg_type = {
2849  .get = xscale_get_reg,
2850  .set = xscale_set_reg,
2851 };
2852 
2854 {
2855  struct xscale_common *xscale = target_to_xscale(target);
2856  struct arm *arm = &xscale->arm;
2857  struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache);
2858  struct xscale_reg *arch_info = malloc(sizeof(xscale_reg_arch_info));
2859  int i;
2860  int num_regs = ARRAY_SIZE(xscale_reg_arch_info);
2861 
2862  (*cache_p) = arm_build_reg_cache(target, arm);
2863 
2864  (*cache_p)->next = malloc(sizeof(struct reg_cache));
2865  cache_p = &(*cache_p)->next;
2866 
2867  /* fill in values for the xscale reg cache */
2868  (*cache_p)->name = "XScale registers";
2869  (*cache_p)->next = NULL;
2870  (*cache_p)->reg_list = calloc(num_regs, sizeof(struct reg));
2871  (*cache_p)->num_regs = num_regs;
2872 
2873  for (i = 0; i < num_regs; i++) {
2874  (*cache_p)->reg_list[i].name = xscale_reg_list[i];
2875  (*cache_p)->reg_list[i].value = calloc(4, 1);
2876  (*cache_p)->reg_list[i].dirty = false;
2877  (*cache_p)->reg_list[i].valid = false;
2878  (*cache_p)->reg_list[i].size = 32;
2879  (*cache_p)->reg_list[i].arch_info = &arch_info[i];
2880  (*cache_p)->reg_list[i].type = &xscale_reg_type;
2881  (*cache_p)->reg_list[i].exist = true;
2882  arch_info[i] = xscale_reg_arch_info[i];
2883  arch_info[i].target = target;
2884  }
2885 
2886  xscale->reg_cache = (*cache_p);
2887 }
2888 
2890 {
2891  struct xscale_common *xscale = target_to_xscale(target);
2892  struct reg_cache *cache = xscale->reg_cache;
2893 
2894  for (unsigned int i = 0; i < ARRAY_SIZE(xscale_reg_arch_info); i++)
2895  free(cache->reg_list[i].value);
2896 
2897  free(cache->reg_list[0].arch_info);
2898  free(cache->reg_list);
2899  free(cache);
2900 
2901  arm_free_reg_cache(&xscale->arm);
2902 }
2903 
2904 static int xscale_init_target(struct command_context *cmd_ctx,
2905  struct target *target)
2906 {
2908  return ERROR_OK;
2909 }
2910 
2911 static void xscale_deinit_target(struct target *target)
2912 {
2913  struct xscale_common *xscale = target_to_xscale(target);
2914 
2916  free(xscale);
2917 }
2918 
2920  struct xscale_common *xscale, struct jtag_tap *tap)
2921 {
2922  struct arm *arm;
2923  uint32_t high_reset_branch, low_reset_branch;
2924  int i;
2925 
2926  arm = &xscale->arm;
2927 
2928  /* store architecture specific data */
2930 
2931  /* PXA3xx with 11 bit IR shifts the JTAG instructions */
2932  if (tap->ir_length == 11)
2933  xscale->xscale_variant = XSCALE_PXA3XX;
2934  else
2936 
2937  /* the debug handler isn't installed (and thus not running) at this time */
2938  xscale->handler_address = 0xfe000800;
2939 
2940  /* clear the vectors we keep locally for reference */
2941  memset(xscale->low_vectors, 0, sizeof(xscale->low_vectors));
2942  memset(xscale->high_vectors, 0, sizeof(xscale->high_vectors));
2943 
2944  /* no user-specified vectors have been configured yet */
2945  xscale->static_low_vectors_set = 0x0;
2946  xscale->static_high_vectors_set = 0x0;
2947 
2948  /* calculate branches to debug handler */
2949  low_reset_branch = (xscale->handler_address + 0x20 - 0x0 - 0x8) >> 2;
2950  high_reset_branch = (xscale->handler_address + 0x20 - 0xffff0000 - 0x8) >> 2;
2951 
2952  xscale->low_vectors[0] = ARMV4_5_B((low_reset_branch & 0xffffff), 0);
2953  xscale->high_vectors[0] = ARMV4_5_B((high_reset_branch & 0xffffff), 0);
2954 
2955  for (i = 1; i <= 7; i++) {
2956  xscale->low_vectors[i] = ARMV4_5_B(0xfffffe, 0);
2957  xscale->high_vectors[i] = ARMV4_5_B(0xfffffe, 0);
2958  }
2959 
2960  /* 64kB aligned region used for DCache cleaning */
2961  xscale->cache_clean_address = 0xfffe0000;
2962 
2963  xscale->hold_rst = 0;
2964  xscale->external_debug_break = 0;
2965 
2966  xscale->ibcr_available = 2;
2967  xscale->ibcr0_used = 0;
2968  xscale->ibcr1_used = 0;
2969 
2970  xscale->dbr_available = 2;
2971  xscale->dbr0_used = 0;
2972  xscale->dbr1_used = 0;
2973 
2974  LOG_INFO("%s: hardware has 2 breakpoints and 2 watchpoints",
2975  target_name(target));
2976 
2977  xscale->arm_bkpt = ARMV5_BKPT(0x0);
2978  xscale->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
2979 
2980  xscale->vector_catch = 0x1;
2981 
2982  xscale->trace.data = NULL;
2983  xscale->trace.image = NULL;
2984  xscale->trace.mode = XSCALE_TRACE_DISABLED;
2985  xscale->trace.buffer_fill = 0;
2986  xscale->trace.fill_counter = 0;
2987 
2988  /* prepare ARMv4/5 specific information */
2989  arm->arch_info = xscale;
2994 
2996 
2997  xscale->armv4_5_mmu.armv4_5_cache.ctype = -1;
3003  xscale->armv4_5_mmu.has_tiny_pages = 1;
3004  xscale->armv4_5_mmu.mmu_enabled = false;
3005 
3006  return ERROR_OK;
3007 }
3008 
3010 {
3011  struct xscale_common *xscale;
3012 
3013  if (sizeof(xscale_debug_handler) > 0x800) {
3014  LOG_ERROR("debug_handler.bin: larger than 2kb");
3015  return ERROR_FAIL;
3016  }
3017 
3018  xscale = calloc(1, sizeof(*xscale));
3019  if (!xscale)
3020  return ERROR_FAIL;
3021 
3022  return xscale_init_arch_info(target, xscale, target->tap);
3023 }
3024 
3025 COMMAND_HANDLER(xscale_handle_debug_handler_command)
3026 {
3027  struct target *target = NULL;
3028  struct xscale_common *xscale;
3029  int retval;
3030  uint32_t handler_address;
3031 
3032  if (CMD_ARGC < 2)
3034 
3035  target = get_target(CMD_ARGV[0]);
3036  if (!target) {
3037  LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
3038  return ERROR_FAIL;
3039  }
3040 
3041  xscale = target_to_xscale(target);
3042  retval = xscale_verify_pointer(CMD, xscale);
3043  if (retval != ERROR_OK)
3044  return retval;
3045 
3047 
3048  if (((handler_address >= 0x800) && (handler_address <= 0x1fef800)) ||
3049  ((handler_address >= 0xfe000800) && (handler_address <= 0xfffff800)))
3050  xscale->handler_address = handler_address;
3051  else {
3052  LOG_ERROR(
3053  "xscale debug_handler <address> must be between 0x800 and 0x1fef800 or between 0xfe000800 and 0xfffff800");
3054  return ERROR_FAIL;
3055  }
3056 
3057  return ERROR_OK;
3058 }
3059 
3060 COMMAND_HANDLER(xscale_handle_cache_clean_address_command)
3061 {
3062  struct target *target = NULL;
3063  struct xscale_common *xscale;
3064  int retval;
3065  uint32_t cache_clean_address;
3066 
3067  if (CMD_ARGC < 2)
3069 
3070  target = get_target(CMD_ARGV[0]);
3071  if (!target) {
3072  LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
3073  return ERROR_FAIL;
3074  }
3075  xscale = target_to_xscale(target);
3076  retval = xscale_verify_pointer(CMD, xscale);
3077  if (retval != ERROR_OK)
3078  return retval;
3079 
3081 
3082  if (cache_clean_address & 0xffff)
3083  LOG_ERROR("xscale cache_clean_address <address> must be 64kb aligned");
3084  else
3086 
3087  return ERROR_OK;
3088 }
3089 
3090 COMMAND_HANDLER(xscale_handle_cache_info_command)
3091 {
3093  struct xscale_common *xscale = target_to_xscale(target);
3094  int retval;
3095 
3096  retval = xscale_verify_pointer(CMD, xscale);
3097  if (retval != ERROR_OK)
3098  return retval;
3099 
3101 }
3102 
3103 static int xscale_virt2phys(struct target *target,
3104  target_addr_t virtual, target_addr_t *physical)
3105 {
3106  struct xscale_common *xscale = target_to_xscale(target);
3107  uint32_t cb;
3108 
3109  if (xscale->common_magic != XSCALE_COMMON_MAGIC) {
3111  return ERROR_TARGET_INVALID;
3112  }
3113 
3114  uint32_t ret;
3115  int retval = armv4_5_mmu_translate_va(target, &xscale->armv4_5_mmu,
3116  virtual, &cb, &ret);
3117  if (retval != ERROR_OK)
3118  return retval;
3119  *physical = ret;
3120  return ERROR_OK;
3121 }
3122 
3123 static int xscale_mmu(struct target *target, bool *enabled)
3124 {
3125  struct xscale_common *xscale = target_to_xscale(target);
3126 
3127  if (target->state != TARGET_HALTED) {
3128  LOG_TARGET_ERROR(target, "not halted");
3129  return ERROR_TARGET_NOT_HALTED;
3130  }
3131  *enabled = xscale->armv4_5_mmu.mmu_enabled;
3132  return ERROR_OK;
3133 }
3134 
3135 COMMAND_HANDLER(xscale_handle_mmu_command)
3136 {
3138  struct xscale_common *xscale = target_to_xscale(target);
3139  int retval;
3140 
3141  retval = xscale_verify_pointer(CMD, xscale);
3142  if (retval != ERROR_OK)
3143  return retval;
3144 
3145  if (target->state != TARGET_HALTED) {
3146  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3147  return ERROR_TARGET_NOT_HALTED;
3148  }
3149 
3150  if (CMD_ARGC >= 1) {
3151  bool enable;
3152  COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
3153  if (enable)
3154  xscale_enable_mmu_caches(target, 1, 0, 0);
3155  else
3157  xscale->armv4_5_mmu.mmu_enabled = enable;
3158  }
3159 
3160  command_print(CMD, "mmu %s",
3161  (xscale->armv4_5_mmu.mmu_enabled) ? "enabled" : "disabled");
3162 
3163  return ERROR_OK;
3164 }
3165 
3166 COMMAND_HANDLER(xscale_handle_idcache_command)
3167 {
3169  struct xscale_common *xscale = target_to_xscale(target);
3170 
3171  int retval = xscale_verify_pointer(CMD, xscale);
3172  if (retval != ERROR_OK)
3173  return retval;
3174 
3175  if (target->state != TARGET_HALTED) {
3176  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3177  return ERROR_TARGET_NOT_HALTED;
3178  }
3179 
3180  bool icache = false;
3181  if (strcmp(CMD_NAME, "icache") == 0)
3182  icache = true;
3183  if (CMD_ARGC >= 1) {
3184  bool enable;
3185  COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
3186  if (icache) {
3187  xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled = enable;
3188  if (enable)
3189  xscale_enable_mmu_caches(target, 0, 0, 1);
3190  else
3192  } else {
3193  xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = enable;
3194  if (enable)
3195  xscale_enable_mmu_caches(target, 0, 1, 0);
3196  else
3198  }
3199  }
3200 
3201  bool enabled = icache ?
3204  const char *msg = enabled ? "enabled" : "disabled";
3205  command_print(CMD, "%s %s", CMD_NAME, msg);
3206 
3207  return ERROR_OK;
3208 }
3209 
3210 static const struct {
3211  char name[15];
3212  unsigned int mask;
3213 } vec_ids[] = {
3214  { "fiq", DCSR_TF, },
3215  { "irq", DCSR_TI, },
3216  { "dabt", DCSR_TD, },
3217  { "pabt", DCSR_TA, },
3218  { "swi", DCSR_TS, },
3219  { "undef", DCSR_TU, },
3220  { "reset", DCSR_TR, },
3221 };
3222 
3223 COMMAND_HANDLER(xscale_handle_vector_catch_command)
3224 {
3226  struct xscale_common *xscale = target_to_xscale(target);
3227  int retval;
3228  uint32_t dcsr_value;
3229  uint32_t catch = 0;
3230  struct reg *dcsr_reg = &xscale->reg_cache->reg_list[XSCALE_DCSR];
3231 
3232  retval = xscale_verify_pointer(CMD, xscale);
3233  if (retval != ERROR_OK)
3234  return retval;
3235 
3236  if (CMD_ARGC > 0) {
3237  if (CMD_ARGC == 1) {
3238  if (strcmp(CMD_ARGV[0], "all") == 0) {
3239  catch = DCSR_TRAP_MASK;
3240  CMD_ARGC--;
3241  } else if (strcmp(CMD_ARGV[0], "none") == 0) {
3242  catch = 0;
3243  CMD_ARGC--;
3244  }
3245  }
3246  while (CMD_ARGC-- > 0) {
3247  unsigned int i;
3248  for (i = 0; i < ARRAY_SIZE(vec_ids); i++) {
3249  if (strcmp(CMD_ARGV[CMD_ARGC], vec_ids[i].name))
3250  continue;
3251  catch |= vec_ids[i].mask;
3252  break;
3253  }
3254  if (i == ARRAY_SIZE(vec_ids)) {
3255  LOG_ERROR("No vector '%s'", CMD_ARGV[CMD_ARGC]);
3257  }
3258  }
3259  buf_set_u32(dcsr_reg->value, 0, 32,
3260  (buf_get_u32(dcsr_reg->value, 0, 32) & ~DCSR_TRAP_MASK) | catch);
3261  xscale_write_dcsr(target, -1, -1);
3262  }
3263 
3264  dcsr_value = buf_get_u32(dcsr_reg->value, 0, 32);
3265  for (unsigned int i = 0; i < ARRAY_SIZE(vec_ids); i++) {
3266  command_print(CMD, "%15s: %s", vec_ids[i].name,
3267  (dcsr_value & vec_ids[i].mask) ? "catch" : "ignore");
3268  }
3269 
3270  return ERROR_OK;
3271 }
3272 
3273 
3274 COMMAND_HANDLER(xscale_handle_vector_table_command)
3275 {
3277  struct xscale_common *xscale = target_to_xscale(target);
3278  int err = 0;
3279  int retval;
3280 
3281  retval = xscale_verify_pointer(CMD, xscale);
3282  if (retval != ERROR_OK)
3283  return retval;
3284 
3285  if (CMD_ARGC == 0) { /* print current settings */
3286  int idx;
3287 
3288  command_print(CMD, "active user-set static vectors:");
3289  for (idx = 1; idx < 8; idx++)
3290  if (xscale->static_low_vectors_set & (1 << idx))
3292  "low %d: 0x%" PRIx32,
3293  idx,
3294  xscale->static_low_vectors[idx]);
3295  for (idx = 1; idx < 8; idx++)
3296  if (xscale->static_high_vectors_set & (1 << idx))
3298  "high %d: 0x%" PRIx32,
3299  idx,
3300  xscale->static_high_vectors[idx]);
3301  return ERROR_OK;
3302  }
3303 
3304  if (CMD_ARGC != 3)
3305  err = 1;
3306  else {
3307  int idx;
3308  COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], idx);
3309  uint32_t vec;
3310  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], vec);
3311 
3312  if (idx < 1 || idx >= 8)
3313  err = 1;
3314 
3315  if (!err && strcmp(CMD_ARGV[0], "low") == 0) {
3316  xscale->static_low_vectors_set |= (1<<idx);
3317  xscale->static_low_vectors[idx] = vec;
3318  } else if (!err && (strcmp(CMD_ARGV[0], "high") == 0)) {
3319  xscale->static_high_vectors_set |= (1<<idx);
3320  xscale->static_high_vectors[idx] = vec;
3321  } else
3322  err = 1;
3323  }
3324 
3325  if (err)
3327 
3328  return ERROR_OK;
3329 }
3330 
3331 
3332 COMMAND_HANDLER(xscale_handle_trace_buffer_command)
3333 {
3335  struct xscale_common *xscale = target_to_xscale(target);
3336  uint32_t dcsr_value;
3337  int retval;
3338 
3339  retval = xscale_verify_pointer(CMD, xscale);
3340  if (retval != ERROR_OK)
3341  return retval;
3342 
3343  if (target->state != TARGET_HALTED) {
3344  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3345  return ERROR_TARGET_NOT_HALTED;
3346  }
3347 
3348  if (CMD_ARGC >= 1) {
3349  if (strcmp("enable", CMD_ARGV[0]) == 0)
3350  xscale->trace.mode = XSCALE_TRACE_WRAP; /* default */
3351  else if (strcmp("disable", CMD_ARGV[0]) == 0)
3352  xscale->trace.mode = XSCALE_TRACE_DISABLED;
3353  else
3355  }
3356 
3357  if (CMD_ARGC >= 2 && xscale->trace.mode != XSCALE_TRACE_DISABLED) {
3358  if (strcmp("fill", CMD_ARGV[1]) == 0) {
3359  int buffcount = 1; /* default */
3360  if (CMD_ARGC >= 3)
3361  COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], buffcount);
3362  if (buffcount < 1) { /* invalid */
3363  command_print(CMD, "fill buffer count must be > 0");
3364  xscale->trace.mode = XSCALE_TRACE_DISABLED;
3366  }
3367  xscale->trace.buffer_fill = buffcount;
3368  xscale->trace.mode = XSCALE_TRACE_FILL;
3369  } else if (strcmp("wrap", CMD_ARGV[1]) == 0)
3370  xscale->trace.mode = XSCALE_TRACE_WRAP;
3371  else {
3372  xscale->trace.mode = XSCALE_TRACE_DISABLED;
3374  }
3375  }
3376 
3377  if (xscale->trace.mode != XSCALE_TRACE_DISABLED) {
3378  char fill_string[12];
3379  sprintf(fill_string, "fill %d", xscale->trace.buffer_fill);
3380  command_print(CMD, "trace buffer enabled (%s)",
3381  (xscale->trace.mode == XSCALE_TRACE_FILL)
3382  ? fill_string : "wrap");
3383  } else
3384  command_print(CMD, "trace buffer disabled");
3385 
3386  dcsr_value = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 0, 32);
3387  if (xscale->trace.mode == XSCALE_TRACE_FILL)
3388  xscale_write_dcsr_sw(target, (dcsr_value & 0xfffffffc) | 2);
3389  else
3390  xscale_write_dcsr_sw(target, dcsr_value & 0xfffffffc);
3391 
3392  return ERROR_OK;
3393 }
3394 
3395 COMMAND_HANDLER(xscale_handle_trace_image_command)
3396 {
3398  struct xscale_common *xscale = target_to_xscale(target);
3399  int retval;
3400 
3401  if (CMD_ARGC < 1)
3403 
3404  retval = xscale_verify_pointer(CMD, xscale);
3405  if (retval != ERROR_OK)
3406  return retval;
3407 
3408  if (xscale->trace.image) {
3409  image_close(xscale->trace.image);
3410  free(xscale->trace.image);
3411  command_print(CMD, "previously loaded image found and closed");
3412  }
3413 
3414  xscale->trace.image = malloc(sizeof(struct image));
3415  xscale->trace.image->base_address_set = false;
3416  xscale->trace.image->start_address_set = false;
3417 
3418  /* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
3419  if (CMD_ARGC >= 2) {
3420  xscale->trace.image->base_address_set = true;
3421  COMMAND_PARSE_NUMBER(llong, CMD_ARGV[1], xscale->trace.image->base_address);
3422  } else
3423  xscale->trace.image->base_address_set = false;
3424 
3425  if (image_open(xscale->trace.image, CMD_ARGV[0],
3426  (CMD_ARGC >= 3) ? CMD_ARGV[2] : NULL) != ERROR_OK) {
3427  free(xscale->trace.image);
3428  xscale->trace.image = NULL;
3429  return ERROR_OK;
3430  }
3431 
3432  return ERROR_OK;
3433 }
3434 
3435 COMMAND_HANDLER(xscale_handle_dump_trace_command)
3436 {
3438  struct xscale_common *xscale = target_to_xscale(target);
3439  struct xscale_trace_data *trace_data;
3440  struct fileio *file;
3441  int retval;
3442 
3443  retval = xscale_verify_pointer(CMD, xscale);
3444  if (retval != ERROR_OK)
3445  return retval;
3446 
3447  if (target->state != TARGET_HALTED) {
3448  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3449  return ERROR_TARGET_NOT_HALTED;
3450  }
3451 
3452  if (CMD_ARGC < 1)
3454 
3455  trace_data = xscale->trace.data;
3456 
3457  if (!trace_data) {
3458  command_print(CMD, "no trace data collected");
3459  return ERROR_OK;
3460  }
3461 
3463  return ERROR_OK;
3464 
3465  while (trace_data) {
3466  int i;
3467 
3468  fileio_write_u32(file, trace_data->chkpt0);
3469  fileio_write_u32(file, trace_data->chkpt1);
3470  fileio_write_u32(file, trace_data->last_instruction);
3471  fileio_write_u32(file, trace_data->depth);
3472 
3473  for (i = 0; i < trace_data->depth; i++)
3474  fileio_write_u32(file, trace_data->entries[i].data |
3475  ((trace_data->entries[i].type & 0xffff) << 16));
3476 
3477  trace_data = trace_data->next;
3478  }
3479 
3480  fileio_close(file);
3481 
3482  return ERROR_OK;
3483 }
3484 
3485 COMMAND_HANDLER(xscale_handle_analyze_trace_buffer_command)
3486 {
3488  struct xscale_common *xscale = target_to_xscale(target);
3489  int retval;
3490 
3491  retval = xscale_verify_pointer(CMD, xscale);
3492  if (retval != ERROR_OK)
3493  return retval;
3494 
3496 
3497  return ERROR_OK;
3498 }
3499 
3500 COMMAND_HANDLER(xscale_handle_cp15)
3501 {
3503  struct xscale_common *xscale = target_to_xscale(target);
3504  int retval;
3505 
3506  retval = xscale_verify_pointer(CMD, xscale);
3507  if (retval != ERROR_OK)
3508  return retval;
3509 
3510  if (target->state != TARGET_HALTED) {
3511  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3512  return ERROR_TARGET_NOT_HALTED;
3513  }
3514  uint32_t reg_no = 0;
3515  struct reg *reg = NULL;
3516  if (CMD_ARGC > 0) {
3517  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], reg_no);
3518  /*translate from xscale cp15 register no to openocd register*/
3519  switch (reg_no) {
3520  case 0:
3521  reg_no = XSCALE_MAINID;
3522  break;
3523  case 1:
3524  reg_no = XSCALE_CTRL;
3525  break;
3526  case 2:
3527  reg_no = XSCALE_TTB;
3528  break;
3529  case 3:
3530  reg_no = XSCALE_DAC;
3531  break;
3532  case 5:
3533  reg_no = XSCALE_FSR;
3534  break;
3535  case 6:
3536  reg_no = XSCALE_FAR;
3537  break;
3538  case 13:
3539  reg_no = XSCALE_PID;
3540  break;
3541  case 15:
3542  reg_no = XSCALE_CPACCESS;
3543  break;
3544  default:
3545  command_print(CMD, "invalid register number");
3547  }
3548  reg = &xscale->reg_cache->reg_list[reg_no];
3549 
3550  }
3551  if (CMD_ARGC == 1) {
3552  uint32_t value;
3553 
3554  /* read cp15 control register */
3556  value = buf_get_u32(reg->value, 0, 32);
3557  command_print(CMD, "%s (/%i): 0x%" PRIx32, reg->name, (int)(reg->size),
3558  value);
3559  } else if (CMD_ARGC == 2) {
3560  uint32_t value;
3562 
3563  /* send CP write request (command 0x41) */
3564  xscale_send_u32(target, 0x41);
3565 
3566  /* send CP register number */
3567  xscale_send_u32(target, reg_no);
3568 
3569  /* send CP register value */
3571 
3572  /* execute cpwait to ensure outstanding operations complete */
3573  xscale_send_u32(target, 0x53);
3574  } else
3576 
3577  return ERROR_OK;
3578 }
3579 
3580 static const struct command_registration xscale_exec_command_handlers[] = {
3581  {
3582  .name = "cache_info",
3583  .handler = xscale_handle_cache_info_command,
3584  .mode = COMMAND_EXEC,
3585  .help = "display information about CPU caches",
3586  .usage = "",
3587  },
3588  {
3589  .name = "mmu",
3590  .handler = xscale_handle_mmu_command,
3591  .mode = COMMAND_EXEC,
3592  .help = "enable or disable the MMU",
3593  .usage = "['enable'|'disable']",
3594  },
3595  {
3596  .name = "icache",
3597  .handler = xscale_handle_idcache_command,
3598  .mode = COMMAND_EXEC,
3599  .help = "display ICache state, optionally enabling or "
3600  "disabling it",
3601  .usage = "['enable'|'disable']",
3602  },
3603  {
3604  .name = "dcache",
3605  .handler = xscale_handle_idcache_command,
3606  .mode = COMMAND_EXEC,
3607  .help = "display DCache state, optionally enabling or "
3608  "disabling it",
3609  .usage = "['enable'|'disable']",
3610  },
3611  {
3612  .name = "vector_catch",
3613  .handler = xscale_handle_vector_catch_command,
3614  .mode = COMMAND_EXEC,
3615  .help = "set or display mask of vectors "
3616  "that should trigger debug entry",
3617  .usage = "['all'|'none'|'fiq'|'irq'|'dabt'|'pabt'|'swi'|'undef'|'reset']",
3618  },
3619  {
3620  .name = "vector_table",
3621  .handler = xscale_handle_vector_table_command,
3622  .mode = COMMAND_EXEC,
3623  .help = "set vector table entry in mini-ICache, "
3624  "or display current tables",
3625  .usage = "[('high'|'low') index code]",
3626  },
3627  {
3628  .name = "trace_buffer",
3629  .handler = xscale_handle_trace_buffer_command,
3630  .mode = COMMAND_EXEC,
3631  .help = "display trace buffer status, enable or disable "
3632  "tracing, and optionally reconfigure trace mode",
3633  .usage = "['enable'|'disable' ['fill' [number]|'wrap']]",
3634  },
3635  {
3636  .name = "dump_trace",
3637  .handler = xscale_handle_dump_trace_command,
3638  .mode = COMMAND_EXEC,
3639  .help = "dump content of trace buffer to file",
3640  .usage = "filename",
3641  },
3642  {
3643  .name = "analyze_trace",
3644  .handler = xscale_handle_analyze_trace_buffer_command,
3645  .mode = COMMAND_EXEC,
3646  .help = "analyze content of trace buffer",
3647  .usage = "",
3648  },
3649  {
3650  .name = "trace_image",
3651  .handler = xscale_handle_trace_image_command,
3652  .mode = COMMAND_EXEC,
3653  .help = "load image from file to address (default 0)",
3654  .usage = "filename [offset [filetype]]",
3655  },
3656  {
3657  .name = "cp15",
3658  .handler = xscale_handle_cp15,
3659  .mode = COMMAND_EXEC,
3660  .help = "Read or write coprocessor 15 register.",
3661  .usage = "register [value]",
3662  },
3664 };
3665 static const struct command_registration xscale_any_command_handlers[] = {
3666  {
3667  .name = "debug_handler",
3668  .handler = xscale_handle_debug_handler_command,
3669  .mode = COMMAND_ANY,
3670  .help = "Change address used for debug handler.",
3671  .usage = "<target> <address>",
3672  },
3673  {
3674  .name = "cache_clean_address",
3675  .handler = xscale_handle_cache_clean_address_command,
3676  .mode = COMMAND_ANY,
3677  .help = "Change address used for cleaning data cache.",
3678  .usage = "address",
3679  },
3680  {
3682  },
3684 };
3685 static const struct command_registration xscale_command_handlers[] = {
3686  {
3688  },
3689  {
3690  .name = "xscale",
3691  .mode = COMMAND_ANY,
3692  .help = "xscale command group",
3693  .usage = "",
3694  .chain = xscale_any_command_handlers,
3695  },
3697 };
3698 
3699 struct target_type xscale_target = {
3700  .name = "xscale",
3701 
3702  .poll = xscale_poll,
3703  .arch_state = xscale_arch_state,
3704 
3705  .halt = xscale_halt,
3706  .resume = xscale_resume,
3707  .step = xscale_step,
3708 
3709  .assert_reset = xscale_assert_reset,
3710  .deassert_reset = xscale_deassert_reset,
3711 
3712  /* REVISIT on some cores, allow exporting iwmmxt registers ... */
3713  .get_gdb_arch = arm_get_gdb_arch,
3714  .get_gdb_reg_list = arm_get_gdb_reg_list,
3715 
3716  .read_memory = xscale_read_memory,
3717  .read_phys_memory = xscale_read_phys_memory,
3718  .write_memory = xscale_write_memory,
3719  .write_phys_memory = xscale_write_phys_memory,
3720 
3721  .checksum_memory = arm_checksum_memory,
3722  .blank_check_memory = arm_blank_check_memory,
3723 
3724  .run_algorithm = armv4_5_run_algorithm,
3725 
3726  .add_breakpoint = xscale_add_breakpoint,
3727  .remove_breakpoint = xscale_remove_breakpoint,
3728  .add_watchpoint = xscale_add_watchpoint,
3729  .remove_watchpoint = xscale_remove_watchpoint,
3730 
3731  .commands = xscale_command_handlers,
3732  .target_create = xscale_target_create,
3733  .init_target = xscale_init_target,
3734  .deinit_target = xscale_deinit_target,
3735 
3736  .virt2phys = xscale_virt2phys,
3737  .mmu = xscale_mmu
3738 };
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:517
int arm_arch_state(struct target *target)
Definition: armv4_5.c:798
bool is_arm_mode(unsigned int psr_mode)
Return true iff the parameter denotes a valid ARM processor mode.
Definition: armv4_5.c:182
#define ARM_COMMON_MAGIC
Definition: arm.h:167
int arm_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Runs ARM code in the target to calculate a CRC32 checksum.
Definition: armv4_5.c:1614
struct reg_cache * arm_build_reg_cache(struct target *target, struct arm *arm)
Definition: armv4_5.c:661
int arm_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, unsigned int num_blocks, uint8_t erased_value, unsigned int *checked)
Runs ARM code in the target to check whether a memory block holds all ones.
Definition: armv4_5.c:1688
const char * arm_get_gdb_arch(const struct target *target)
Definition: armv4_5.c:1283
int arm_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Definition: armv4_5.c:1288
arm_mode
Represent state of an ARM core.
Definition: arm.h:82
@ ARM_MODE_SYS
Definition: arm.h:92
@ ARM_MODE_USR
Definition: arm.h:83
void arm_free_reg_cache(struct arm *arm)
Definition: armv4_5.c:777
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:262
@ ARM_STATE_THUMB
Definition: arm.h:153
@ ARM_STATE_ARM
Definition: arm.h:152
const struct command_registration arm_command_handlers[]
Definition: armv4_5.c:1263
int arm_init_arch_info(struct target *target, struct arm *arm)
Definition: armv4_5.c:1815
const char * arm_mode_name(unsigned int psr_mode)
Map PSR mode bits to the name of an ARM processor operating mode.
Definition: armv4_5.c:171
void arm_set_cpsr(struct arm *arm, uint32_t cpsr)
Configures host-side ARM records to reflect the specified CPSR.
Definition: armv4_5.c:453
int armv4_5_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Definition: armv4_5.c:1588
@ ARM_CORE_TYPE_STD
Definition: arm.h:46
int arm_evaluate_opcode(uint32_t opcode, uint32_t address, struct arm_instruction *instruction)
int thumb_evaluate_opcode(uint16_t opcode, uint32_t address, struct arm_instruction *instruction)
Macros used to generate various ARM or Thumb opcodes.
#define ARMV5_BKPT(im)
Definition: arm_opcodes.h:227
#define ARMV5_T_BKPT(im)
Definition: arm_opcodes.h:313
#define ARMV4_5_B(im, l)
Definition: arm_opcodes.h:117
int arm_simulate_step(struct target *target, uint32_t *dry_run_pc)
enum arm_mode mode
Definition: armv4_5.c:281
enum arm_mode armv4_5_number_to_mode(int number)
Map linear number indexing armv4_5_core_reg_map to PSR mode bits.
Definition: armv4_5.c:223
#define ARMV4_5_CORE_REG_MODE(cache, mode, num)
Definition: armv4_5.h:32
int armv4_5_identify_cache(uint32_t cache_type_reg, struct armv4_5_cache_common *cache)
Definition: armv4_5_cache.c:15
int armv4_5_handle_cache_info_command(struct command_invocation *cmd, struct armv4_5_cache_common *armv4_5_cache)
Definition: armv4_5_cache.c:68
int armv4_5_mmu_translate_va(struct target *target, struct armv4_5_mmu_common *armv4_5_mmu, uint32_t va, uint32_t *cb, uint32_t *val)
Definition: armv4_5_mmu.c:16
void * buf_cpy(const void *from, void *_to, unsigned int size)
Copies size bits out of from and into to.
Definition: binarybuffer.c:43
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
struct breakpoint * breakpoint_find(struct target *target, target_addr_t address)
Definition: breakpoints.c:472
@ BKPT_HARD
Definition: breakpoints.h:18
@ BKPT_SOFT
Definition: breakpoints.h:19
static void watchpoint_set(struct watchpoint *watchpoint, unsigned int number)
Definition: breakpoints.h:81
#define WATCHPOINT_IGNORE_DATA_VALUE_MASK
Definition: breakpoints.h:39
static void breakpoint_hw_set(struct breakpoint *breakpoint, unsigned int hw_number)
Definition: breakpoints.h:65
@ WPT_ACCESS
Definition: breakpoints.h:23
@ WPT_READ
Definition: breakpoints.h:23
@ WPT_WRITE
Definition: breakpoints.h:23
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:389
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:146
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
Definition: command.h:171
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:161
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:405
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:156
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
Definition: command.h:536
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:445
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:151
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:407
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
int fileio_write_u32(struct fileio *fileio, uint32_t data)
int fileio_close(struct fileio *fileio)
int fileio_open(struct fileio **fileio, const char *url, enum fileio_access access_type, enum fileio_type type)
@ FILEIO_WRITE
Definition: helper/fileio.h:29
@ FILEIO_BINARY
Definition: helper/fileio.h:23
void image_close(struct image *image)
Definition: image.c:1210
int image_read_section(struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
Definition: image.c:1078
int image_open(struct image *image, const char *url, const char *type_string)
Definition: image.c:956
void jtag_add_dr_scan_check(struct jtag_tap *active, int in_num_fields, struct scan_field *in_fields, enum tap_state state)
A version of jtag_add_dr_scan() that uses the check_value/mask fields.
Definition: jtag/core.c:440
void jtag_add_reset(int req_tlr_or_trst, int req_srst)
A reset of the TAP state machine can be requested.
Definition: jtag/core.c:766
void jtag_add_runtest(unsigned int num_cycles, enum tap_state state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
Definition: jtag/core.c:593
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1045
void jtag_add_pathmove(unsigned int num_states, const enum tap_state *path)
Application code must assume that interfaces will implement transitions between states with different...
Definition: jtag/core.c:518
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, enum tap_state state)
Generate a DR SCAN using the fields passed to the function.
Definition: jtag/core.c:452
void jtag_add_sleep(uint32_t us)
Definition: jtag/core.c:878
void jtag_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *mask)
Execute jtag queue and check value with an optional mask.
Definition: jtag/core.c:925
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, enum tap_state state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
Definition: jtag/core.c:375
void jtag_add_callback(jtag_callback1_t f, jtag_callback_data_t data0)
A simpler version of jtag_add_callback4().
tap_state
Defines JTAG Test Access Port states.
Definition: jtag.h:37
@ TAP_DRCAPTURE
Definition: jtag.h:47
@ TAP_DRSELECT
Definition: jtag.h:48
@ TAP_DREXIT1
Definition: jtag.h:42
@ TAP_DRPAUSE
Definition: jtag.h:44
@ TAP_DREXIT2
Definition: jtag.h:41
@ TAP_IDLE
Definition: jtag.h:53
@ TAP_DRSHIFT
Definition: jtag.h:43
intptr_t jtag_callback_data_t
Defines the type of data passed to the jtag_callback_t interface.
Definition: jtag.h:336
void alive_sleep(uint64_t ms)
Definition: log.c:478
void keep_alive(void)
Definition: log.c:437
#define LOG_USER(expr ...)
Definition: log.h:150
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define ERROR_FAIL
Definition: log.h:188
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:176
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_LEVEL_IS(FOO)
Definition: log.h:112
#define LOG_INFO(expr ...)
Definition: log.h:141
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
@ LOG_LVL_DEBUG
Definition: log.h:55
#define t0
Definition: mips32.c:192
#define t1
Definition: mips32.c:193
#define t2
Definition: mips32.c:194
struct reg_cache ** register_get_last_cache_p(struct reg_cache **first)
Definition: register.c:72
void register_cache_invalidate(struct reg_cache *cache)
Marks the contents of the register cache as invalid (and clean).
Definition: register.c:94
int gettimeofday(struct timeval *tv, struct timezone *tz)
struct target * target
Definition: rtt/rtt.c:26
static const char * str_enabled_disabled(bool value)
union arm_instruction::@73 info
struct arm_b_bl_bx_blx_instr b_bl_bx_blx
Represents a generic ARM core, with standard application registers.
Definition: arm.h:176
int(* full_context)(struct target *target)
Retrieve all core registers, for display.
Definition: arm.h:222
void * arch_info
Definition: arm.h:252
enum arm_core_type core_type
Indicates what registers are in the ARM state core register set.
Definition: arm.h:194
enum arm_mode core_mode
Record the current core mode: SVC, USR, or some other mode.
Definition: arm.h:197
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
Definition: arm.h:185
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:182
int(* write_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode, uint8_t *value)
Definition: arm.h:227
int(* read_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode)
Retrieve a single core register.
Definition: arm.h:225
struct reg_cache * core_cache
Definition: arm.h:179
struct reg * spsr
Handle to the SPSR; valid only in core modes with an SPSR.
Definition: arm.h:188
unsigned int common_magic
Definition: arm.h:177
int(* write_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: armv4_5_mmu.h:18
int(* read_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: armv4_5_mmu.h:17
int(* get_ttb)(struct target *target, uint32_t *result)
Definition: armv4_5_mmu.h:16
int(* enable_mmu_caches)(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: armv4_5_mmu.h:21
int(* disable_mmu_caches)(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: armv4_5_mmu.h:20
struct armv4_5_cache_common armv4_5_cache
Definition: armv4_5_mmu.h:22
struct breakpoint * next
Definition: breakpoints.h:34
unsigned int length
Definition: breakpoints.h:29
uint8_t * orig_instr
Definition: breakpoints.h:33
enum breakpoint_type type
Definition: breakpoints.h:30
bool is_set
Definition: breakpoints.h:31
unsigned int number
Definition: breakpoints.h:32
target_addr_t address
Definition: breakpoints.h:27
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
const char * name
Definition: command.h:239
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
Definition: command.h:252
FILE * file
Definition: helper/fileio.c:28
Definition: image.h:48
unsigned int num_sections
Definition: image.h:51
bool start_address_set
Definition: image.h:55
struct imagesection * sections
Definition: image.h:52
long long base_address
Definition: image.h:54
bool base_address_set
Definition: image.h:53
target_addr_t base_address
Definition: image.h:42
uint32_t size
Definition: image.h:43
Definition: jtag.h:101
uint8_t * cur_instr
current instruction
Definition: jtag.h:132
unsigned int ir_length
size of instruction register
Definition: jtag.h:110
int(* get)(struct reg *reg)
Definition: register.h:152
const char * name
Definition: register.h:145
unsigned int num_regs
Definition: register.h:148
struct reg * reg_list
Definition: register.h:147
struct reg_cache * next
Definition: register.h:146
Definition: register.h:111
bool valid
Definition: register.h:126
uint32_t size
Definition: register.h:132
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
This structure defines a single scan field in the scan.
Definition: jtag.h:87
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:93
uint8_t * check_value
The value used to check the data scanned out.
Definition: jtag.h:96
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:91
unsigned int num_bits
The number of bits this field specifies.
Definition: jtag.h:89
uint8_t * check_mask
The mask to go with check_value.
Definition: jtag.h:98
This holds methods shared between all instances of a given target type.
Definition: target_type.h:26
const char * name
Name of this type of target.
Definition: target_type.h:31
Definition: target.h:119
struct jtag_tap * tap
Definition: target.h:122
enum target_debug_reason debug_reason
Definition: target.h:164
enum target_state state
Definition: target.h:167
enum target_endianness endianness
Definition: target.h:165
struct reg_cache * reg_cache
Definition: target.h:168
struct breakpoint * breakpoints
Definition: target.h:169
struct watchpoint * watchpoints
Definition: target.h:170
void * arch_info
Definition: target.h:174
bool reset_halt
Definition: target.h:154
Definition: psoc6.c:83
long tv_sec
Definition: replacements.h:46
long tv_usec
Definition: replacements.h:47
uint64_t mask
Definition: breakpoints.h:44
enum watchpoint_rw rw
Definition: breakpoints.h:46
bool is_set
Definition: breakpoints.h:47
struct watchpoint * next
Definition: breakpoints.h:49
unsigned int length
Definition: breakpoints.h:43
unsigned int number
Definition: breakpoints.h:48
target_addr_t address
Definition: breakpoints.h:42
uint8_t static_low_vectors_set
Definition: xscale.h:90
uint16_t thumb_bkpt
Definition: xscale.h:110
uint32_t static_high_vectors[8]
Definition: xscale.h:93
uint32_t low_vectors[8]
Definition: xscale.h:86
int arch_debug_reason
Definition: xscale.h:116
int xscale_variant
Definition: xscale.h:125
uint32_t static_low_vectors[8]
Definition: xscale.h:92
uint32_t cache_clean_address
Definition: xscale.h:96
uint32_t cp15_control_reg
Definition: xscale.h:120
int ibcr_available
Definition: xscale.h:106
int dbr0_used
Definition: xscale.h:104
uint8_t static_high_vectors_set
Definition: xscale.h:91
int external_debug_break
Definition: xscale.h:100
int dbr1_used
Definition: xscale.h:105
uint32_t handler_address
Definition: xscale.h:83
int ibcr1_used
Definition: xscale.h:108
int dbr_available
Definition: xscale.h:103
uint32_t high_vectors[8]
Definition: xscale.h:87
int ibcr0_used
Definition: xscale.h:107
uint32_t arm_bkpt
Definition: xscale.h:109
uint8_t vector_catch
Definition: xscale.h:112
int hold_rst
Definition: xscale.h:99
struct reg_cache * reg_cache
Definition: xscale.h:80
struct armv4_5_mmu_common armv4_5_mmu
Definition: xscale.h:119
struct arm arm
Definition: xscale.h:77
unsigned int common_magic
Definition: xscale.h:74
struct xscale_trace trace
Definition: xscale.h:114
int dbg_handler_number
Definition: xscale.h:135
struct target * target
Definition: xscale.h:136
unsigned int num_checkpoints
Definition: xscale.h:54
struct xscale_trace_data * next
Definition: xscale.h:55
uint32_t chkpt0
Definition: xscale.h:51
uint32_t chkpt1
Definition: xscale.h:52
struct xscale_trace_entry * entries
Definition: xscale.h:49
uint32_t last_instruction
Definition: xscale.h:53
Definition: xscale.h:43
uint8_t data
Definition: xscale.h:44
enum xscale_trace_entry_type type
Definition: xscale.h:45
enum trace_mode mode
Definition: xscale.h:69
struct xscale_trace_data * data
Definition: xscale.h:66
int buffer_fill
Definition: xscale.h:67
enum arm_state core_state
Definition: xscale.h:70
struct image * image
Definition: xscale.h:65
int fill_counter
Definition: xscale.h:68
int target_call_event_callbacks(struct target *target, enum target_event event)
Definition: target.c:1794
struct target * get_target(const char *id)
Definition: target.c:443
void target_free_all_working_areas(struct target *target)
Definition: target.c:2180
int target_halt(struct target *target)
Definition: target.c:517
void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value)
Definition: target.c:380
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
Definition: target.c:362
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2652
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
Definition: target.c:1288
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2635
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
Definition: target.c:270
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2561
uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer)
Definition: target.c:344
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
Definition: target.c:1260
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:468
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
Definition: target.c:326
@ DBG_REASON_NOTHALTED
Definition: target.h:77
@ DBG_REASON_DBGRQ
Definition: target.h:72
@ DBG_REASON_SINGLESTEP
Definition: target.h:76
@ DBG_REASON_WATCHPOINT
Definition: target.h:74
@ DBG_REASON_BREAKPOINT
Definition: target.h:73
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:817
static bool target_was_examined(const struct target *target)
Definition: target.h:443
#define ERROR_TARGET_UNALIGNED_ACCESS
Definition: target.h:819
#define ERROR_TARGET_INVALID
Definition: target.h:814
@ TARGET_EVENT_DEBUG_RESUMED
Definition: target.h:285
@ TARGET_EVENT_HALTED
Definition: target.h:265
@ TARGET_EVENT_RESUMED
Definition: target.h:266
@ TARGET_EVENT_DEBUG_HALTED
Definition: target.h:284
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
Definition: target.h:246
target_state
Definition: target.h:55
@ TARGET_RESET
Definition: target.h:59
@ TARGET_DEBUG_RUNNING
Definition: target.h:60
@ TARGET_UNKNOWN
Definition: target.h:56
@ TARGET_HALTED
Definition: target.h:58
@ TARGET_RUNNING
Definition: target.h:57
#define ERROR_TARGET_NOT_EXAMINED
Definition: target.h:824
@ TARGET_LITTLE_ENDIAN
Definition: target.h:85
#define ERROR_TARGET_TIMEOUT
Definition: target.h:816
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:821
#define ERROR_TARGET_DATA_ABORT
Definition: target.h:820
#define ERROR_TARGET_FAILURE
Definition: target.h:818
int timeval_compare(const struct timeval *x, const struct timeval *y)
Definition: time_support.c:57
int timeval_add_time(struct timeval *result, long sec, long usec)
Definition: time_support.c:43
#define ERROR_TRACE_INSTRUCTION_UNAVAILABLE
Definition: trace.h:48
#define ERROR_TRACE_IMAGE_UNAVAILABLE
Definition: trace.h:47
static uint16_t le_to_h_u16(const uint8_t *buf)
Definition: types.h:122
#define TARGET_ADDR_FMT
Definition: types.h:286
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
static uint32_t be_to_h_u32(const uint8_t *buf)
Definition: types.h:139
uint64_t target_addr_t
Definition: types.h:279
static uint16_t be_to_h_u16(const uint8_t *buf)
Definition: types.h:149
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t count[4]
Definition: vdebug.c:22
static int xscale_enable_single_step(struct target *target, uint32_t next_pc)
Definition: xscale.c:1032
static int xscale_target_create(struct target *target)
Definition: xscale.c:3009
static int xscale_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical)
Definition: xscale.c:3103
static int xscale_init_arch_info(struct target *target, struct xscale_common *xscale, struct jtag_tap *tap)
Definition: xscale.c:2919
static int xscale_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: xscale.c:2133
static int xscale_assert_reset(struct target *target)
Definition: xscale.c:1429
static int xscale_jtag_set_instr(struct jtag_tap *tap, uint32_t new_instr, enum tap_state end_state)
Definition: xscale.c:141
static int xscale_set_breakpoint(struct target *, struct breakpoint *)
Definition: xscale.c:2064
static int xscale_enable_mmu_caches(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: xscale.c:2033
static int xscale_load_ic(struct target *target, uint32_t va, uint32_t buffer[8])
Definition: xscale.c:635
static void xscale_display_instruction(struct target *target, uint32_t pc, struct arm_instruction *instruction, struct command_invocation *cmd)
Definition: xscale.c:2639
static int xscale_write_dcsr(struct target *target, int hold_rst, int ext_dbg_brk)
Definition: xscale.c:566
static int xscale_full_context(struct target *target)
Definition: xscale.c:1621
static void xscale_deinit_target(struct target *target)
Definition: xscale.c:2911
static int xscale_analyze_trace(struct target *target, struct command_invocation *cmd)
Definition: xscale.c:2650
static int xscale_set_watchpoint(struct target *, struct watchpoint *)
Definition: xscale.c:2221
static int xscale_verify_pointer(struct command_invocation *cmd, struct xscale_common *xscale)
Definition: xscale.c:131
static int xscale_read_tx(struct target *target, int consume)
Definition: xscale.c:331
static int xscale_arch_state(struct target *target)
Definition: xscale.c:773
static int xscale_set_reg_u32(struct reg *reg, uint32_t value)
Definition: xscale.c:120
static int xscale_deassert_reset(struct target *target)
Definition: xscale.c:1477
static int xscale_read_trace(struct target *)
Definition: xscale.c:2472
COMMAND_HANDLER(xscale_handle_debug_handler_command)
Definition: xscale.c:3025
static int xscale_mmu(struct target *target, bool *enabled)
Definition: xscale.c:3123
static int xscale_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: xscale.c:2203
static int xscale_read_dcsr(struct target *target)
Definition: xscale.c:160
static const uint8_t xscale_debug_handler[]
Definition: xscale.c:65
static int xscale_set_reg(struct reg *reg, uint8_t *buf)
Definition: xscale.c:2418
static int xscale_get_ttb(struct target *target, uint32_t *result)
Definition: xscale.c:1967
static int xscale_read_core_reg(struct target *target, struct reg *r, int num, enum arm_mode mode)
Definition: xscale.c:1605
static int xscale_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Definition: xscale.c:1372
static unsigned int parity(unsigned int v)
Definition: xscale.c:624
static int xscale_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: xscale.c:1868
static const struct command_registration xscale_any_command_handlers[]
Definition: xscale.c:3665
char name[15]
Definition: xscale.c:3211
static int xscale_disable_mmu_caches(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: xscale.c:1983
static int xscale_get_reg(struct reg *reg)
Definition: xscale.c:2382
static const struct reg_arch_type xscale_reg_type
Definition: xscale.c:2848
static const struct xscale_reg xscale_reg_arch_info[]
Definition: xscale.c:94
static void xscale_enable_breakpoints(struct target *target)
Definition: xscale.c:1082
static const struct command_registration xscale_command_handlers[]
Definition: xscale.c:3685
static int xscale_write_rx(struct target *target)
Definition: xscale.c:417
static void xscale_free_trace_data(struct xscale_common *xscale)
Definition: xscale.c:1094
static int xscale_write_dcsr_sw(struct target *target, uint32_t value)
Definition: xscale.c:2453
static void xscale_getbuf(jtag_callback_data_t arg)
Definition: xscale.c:223
static void xscale_free_reg_cache(struct target *target)
Definition: xscale.c:2889
static int xscale_receive(struct target *target, uint32_t *buffer, int num_words)
Definition: xscale.c:229
static const struct @135 vec_ids[]
static int xscale_unset_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: xscale.c:2326
unsigned int mask
Definition: xscale.c:3212
static int xscale_poll(struct target *target)
Definition: xscale.c:797
static void xscale_enable_watchpoints(struct target *target)
Definition: xscale.c:1071
static void xscale_build_reg_cache(struct target *target)
Definition: xscale.c:2853
static int xscale_write_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: xscale.c:1952
static const char xscale_not[]
Definition: xscale.c:129
static int xscale_send_u32(struct target *target, uint32_t value)
Definition: xscale.c:558
static int xscale_restore_banked(struct target *)
Definition: xscale.c:1698
static int xscale_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: xscale.c:2904
static const struct command_registration xscale_exec_command_handlers[]
Definition: xscale.c:3580
static int xscale_resume(struct target *, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Definition: xscale.c:1106
static int xscale_disable_single_step(struct target *target)
Definition: xscale.c:1058
static int xscale_invalidate_ic_line(struct target *target, uint32_t va)
Definition: xscale.c:689
static int xscale_read_instruction(struct target *target, uint32_t pc, struct arm_instruction *instruction)
Definition: xscale.c:2567
static int xscale_update_vectors(struct target *target)
Definition: xscale.c:719
static int xscale_debug_entry(struct target *)
Definition: xscale.c:834
static int xscale_write_core_reg(struct target *target, struct reg *r, int num, enum arm_mode mode, uint8_t *value)
Definition: xscale.c:1613
static int xscale_read_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: xscale.c:1853
static int xscale_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: xscale.c:2284
static int xscale_send(struct target *target, const uint8_t *buffer, int count, int size)
Definition: xscale.c:496
static int xscale_unset_breakpoint(struct target *, struct breakpoint *)
Definition: xscale.c:2154
static int xscale_step_inner(struct target *target, bool current, uint32_t address, bool handle_breakpoints)
Definition: xscale.c:1277
static void xscale_branch_address(struct xscale_trace_data *trace_data, int i, uint32_t *target)
Definition: xscale.c:2626
static const char *const xscale_reg_list[]
Definition: xscale.c:69
static int xscale_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: xscale.c:1767
static int xscale_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: xscale.c:2362
static int xscale_halt(struct target *target)
Definition: xscale.c:1005
struct target_type xscale_target
Definition: xscale.c:3699
#define XSCALE_SELDCSR
Definition: xscale.h:26
#define DCSR_TRAP_MASK
Definition: xscale.h:174
#define DCSR_TD
Definition: xscale.h:171
@ XSCALE_DBG_REASON_RESET
Definition: xscale.h:34
@ XSCALE_DBG_REASON_TB_FULL
Definition: xscale.h:35
@ XSCALE_DBG_REASON_GENERIC
Definition: xscale.h:33
@ XSCALE_TX
Definition: xscale.h:159
@ XSCALE_FSR
Definition: xscale.h:146
@ XSCALE_CHKPT1
Definition: xscale.h:157
@ XSCALE_IBCR1
Definition: xscale.h:151
@ XSCALE_FAR
Definition: xscale.h:147
@ XSCALE_DBCON
Definition: xscale.h:154
@ XSCALE_DAC
Definition: xscale.h:145
@ XSCALE_CTRL
Definition: xscale.h:142
@ XSCALE_TBREG
Definition: xscale.h:155
@ XSCALE_RX
Definition: xscale.h:160
@ XSCALE_DBR1
Definition: xscale.h:153
@ XSCALE_CHKPT0
Definition: xscale.h:156
@ XSCALE_AUXCTRL
Definition: xscale.h:143
@ XSCALE_CPACCESS
Definition: xscale.h:149
@ XSCALE_MAINID
Definition: xscale.h:140
@ XSCALE_CACHETYPE
Definition: xscale.h:141
@ XSCALE_DBR0
Definition: xscale.h:152
@ XSCALE_TTB
Definition: xscale.h:144
@ XSCALE_IBCR0
Definition: xscale.h:150
@ XSCALE_PID
Definition: xscale.h:148
@ XSCALE_DCSR
Definition: xscale.h:158
#define DCSR_TS
Definition: xscale.h:169
#define XSCALE_PXA3XX
Definition: xscale.h:30
#define DCSR_TF
Definition: xscale.h:173
#define DCSR_TA
Definition: xscale.h:170
#define XSCALE_LDIC
Definition: xscale.h:25
#define XSCALE_IXP4XX_PXA2XX
Definition: xscale.h:29
#define XSCALE_DBGRX
Definition: xscale.h:23
@ XSCALE_TRACE_MESSAGE
Definition: xscale.h:39
@ XSCALE_TRACE_ADDRESS
Definition: xscale.h:40
#define ERROR_XSCALE_NO_TRACE_DATA
Definition: xscale.h:164
#define DCSR_TR
Definition: xscale.h:167
#define DCSR_TI
Definition: xscale.h:172
static struct xscale_common * target_to_xscale(struct target *target)
Definition: xscale.h:129
#define XSCALE_COMMON_MAGIC
Definition: xscale.h:18
#define DCSR_TU
Definition: xscale.h:168
#define XSCALE_DBGTX
Definition: xscale.h:24
trace_mode
Definition: xscale.h:58
@ XSCALE_TRACE_DISABLED
Definition: xscale.h:59
@ XSCALE_TRACE_FILL
Definition: xscale.h:60
@ XSCALE_TRACE_WRAP
Definition: xscale.h:61