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;
403  if (debug_level >= 3) {
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;
474  if (debug_level >= 3) {
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  retval = xscale_send_u32(target, 0x53);
2031  return retval;
2032 }
2033 
2034 static int xscale_enable_mmu_caches(struct target *target, int mmu,
2035  int d_u_cache, int i_cache)
2036 {
2037  struct xscale_common *xscale = target_to_xscale(target);
2038  uint32_t cp15_control;
2039  int retval;
2040 
2041  /* read cp15 control register */
2042  retval = xscale_get_reg(&xscale->reg_cache->reg_list[XSCALE_CTRL]);
2043  if (retval != ERROR_OK)
2044  return retval;
2045  cp15_control = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_CTRL].value, 0, 32);
2046 
2047  if (mmu)
2048  cp15_control |= 0x1U;
2049 
2050  if (d_u_cache)
2051  cp15_control |= 0x4U;
2052 
2053  if (i_cache)
2054  cp15_control |= 0x1000U;
2055 
2056  /* write new cp15 control register */
2057  retval = xscale_set_reg_u32(&xscale->reg_cache->reg_list[XSCALE_CTRL], cp15_control);
2058  if (retval != ERROR_OK)
2059  return retval;
2060 
2061  /* execute cpwait to ensure outstanding operations complete */
2062  retval = xscale_send_u32(target, 0x53);
2063  return retval;
2064 }
2065 
2067  struct breakpoint *breakpoint)
2068 {
2069  int retval;
2070  struct xscale_common *xscale = target_to_xscale(target);
2071 
2072  if (target->state != TARGET_HALTED) {
2073  LOG_TARGET_ERROR(target, "not halted");
2074  return ERROR_TARGET_NOT_HALTED;
2075  }
2076 
2077  if (breakpoint->is_set) {
2078  LOG_WARNING("breakpoint already set");
2079  return ERROR_OK;
2080  }
2081 
2082  if (breakpoint->type == BKPT_HARD) {
2083  uint32_t value = breakpoint->address | 1;
2084  if (!xscale->ibcr0_used) {
2086  xscale->ibcr0_used = 1;
2087  /* breakpoint set on first breakpoint register */
2089  } else if (!xscale->ibcr1_used) {
2091  xscale->ibcr1_used = 1;
2092  /* breakpoint set on second breakpoint register */
2094  } else {/* bug: availability previously verified in xscale_add_breakpoint() */
2095  LOG_ERROR("BUG: no hardware comparator available");
2097  }
2098  } else if (breakpoint->type == BKPT_SOFT) {
2099  if (breakpoint->length == 4) {
2100  /* keep the original instruction in target endianness */
2101  retval = target_read_memory(target, breakpoint->address, 4, 1,
2103  if (retval != ERROR_OK)
2104  return retval;
2105  /* write the bkpt instruction in target endianness
2106  *(arm7_9->arm_bkpt is host endian) */
2108  xscale->arm_bkpt);
2109  if (retval != ERROR_OK)
2110  return retval;
2111  } else {
2112  /* keep the original instruction in target endianness */
2113  retval = target_read_memory(target, breakpoint->address, 2, 1,
2115  if (retval != ERROR_OK)
2116  return retval;
2117  /* write the bkpt instruction in target endianness
2118  *(arm7_9->arm_bkpt is host endian) */
2120  xscale->thumb_bkpt);
2121  if (retval != ERROR_OK)
2122  return retval;
2123  }
2124  breakpoint->is_set = true;
2125 
2126  xscale_send_u32(target, 0x50); /* clean dcache */
2128  xscale_send_u32(target, 0x51); /* invalidate dcache */
2129  xscale_send_u32(target, 0x52); /* invalidate icache and flush fetch buffers */
2130  }
2131 
2132  return ERROR_OK;
2133 }
2134 
2136  struct breakpoint *breakpoint)
2137 {
2138  struct xscale_common *xscale = target_to_xscale(target);
2139 
2140  if ((breakpoint->type == BKPT_HARD) && (xscale->ibcr_available < 1)) {
2141  LOG_ERROR("no breakpoint unit available for hardware breakpoint");
2143  }
2144 
2145  if ((breakpoint->length != 2) && (breakpoint->length != 4)) {
2146  LOG_ERROR("only breakpoints of two (Thumb) or four (ARM) bytes length supported");
2148  }
2149 
2150  if (breakpoint->type == BKPT_HARD)
2151  xscale->ibcr_available--;
2152 
2154 }
2155 
2157  struct breakpoint *breakpoint)
2158 {
2159  int retval;
2160  struct xscale_common *xscale = target_to_xscale(target);
2161 
2162  if (target->state != TARGET_HALTED) {
2163  LOG_TARGET_ERROR(target, "not halted");
2164  return ERROR_TARGET_NOT_HALTED;
2165  }
2166 
2167  if (!breakpoint->is_set) {
2168  LOG_WARNING("breakpoint not set");
2169  return ERROR_OK;
2170  }
2171 
2172  if (breakpoint->type == BKPT_HARD) {
2173  if (breakpoint->number == 0) {
2175  xscale->ibcr0_used = 0;
2176  } else if (breakpoint->number == 1) {
2178  xscale->ibcr1_used = 0;
2179  }
2180  breakpoint->is_set = false;
2181  } else {
2182  /* restore original instruction (kept in target endianness) */
2183  if (breakpoint->length == 4) {
2184  retval = target_write_memory(target, breakpoint->address, 4, 1,
2186  if (retval != ERROR_OK)
2187  return retval;
2188  } else {
2189  retval = target_write_memory(target, breakpoint->address, 2, 1,
2191  if (retval != ERROR_OK)
2192  return retval;
2193  }
2194  breakpoint->is_set = false;
2195 
2196  xscale_send_u32(target, 0x50); /* clean dcache */
2198  xscale_send_u32(target, 0x51); /* invalidate dcache */
2199  xscale_send_u32(target, 0x52); /* invalidate icache and flush fetch buffers */
2200  }
2201 
2202  return ERROR_OK;
2203 }
2204 
2206 {
2207  struct xscale_common *xscale = target_to_xscale(target);
2208 
2209  if (target->state != TARGET_HALTED) {
2210  LOG_TARGET_ERROR(target, "not halted");
2211  return ERROR_TARGET_NOT_HALTED;
2212  }
2213 
2214  if (breakpoint->is_set)
2216 
2217  if (breakpoint->type == BKPT_HARD)
2218  xscale->ibcr_available++;
2219 
2220  return ERROR_OK;
2221 }
2222 
2224  struct watchpoint *watchpoint)
2225 {
2226  struct xscale_common *xscale = target_to_xscale(target);
2227  uint32_t enable = 0;
2228  struct reg *dbcon = &xscale->reg_cache->reg_list[XSCALE_DBCON];
2229  uint32_t dbcon_value = buf_get_u32(dbcon->value, 0, 32);
2230 
2231  if (target->state != TARGET_HALTED) {
2232  LOG_TARGET_ERROR(target, "not halted");
2233  return ERROR_TARGET_NOT_HALTED;
2234  }
2235 
2236  switch (watchpoint->rw) {
2237  case WPT_READ:
2238  enable = 0x3;
2239  break;
2240  case WPT_ACCESS:
2241  enable = 0x2;
2242  break;
2243  case WPT_WRITE:
2244  enable = 0x1;
2245  break;
2246  default:
2247  LOG_ERROR("BUG: watchpoint->rw neither read, write nor access");
2248  }
2249 
2250  /* For watchpoint across more than one word, both DBR registers must
2251  be enlisted, with the second used as a mask. */
2252  if (watchpoint->length > 4) {
2253  if (xscale->dbr0_used || xscale->dbr1_used) {
2254  LOG_ERROR("BUG: sufficient hardware comparators unavailable");
2256  }
2257 
2258  /* Write mask value to DBR1, based on the length argument.
2259  * Address bits ignored by the comparator are those set in mask. */
2261  watchpoint->length - 1);
2262  xscale->dbr1_used = 1;
2263  enable |= 0x100; /* DBCON[M] */
2264  }
2265 
2266  if (!xscale->dbr0_used) {
2268  dbcon_value |= enable;
2269  xscale_set_reg_u32(dbcon, dbcon_value);
2271  xscale->dbr0_used = 1;
2272  } else if (!xscale->dbr1_used) {
2274  dbcon_value |= enable << 2;
2275  xscale_set_reg_u32(dbcon, dbcon_value);
2277  xscale->dbr1_used = 1;
2278  } else {
2279  LOG_ERROR("BUG: no hardware comparator available");
2281  }
2282 
2283  return ERROR_OK;
2284 }
2285 
2287  struct watchpoint *watchpoint)
2288 {
2289  struct xscale_common *xscale = target_to_xscale(target);
2290 
2291  if (xscale->dbr_available < 1) {
2292  LOG_ERROR("no more watchpoint registers available");
2294  }
2295 
2297  LOG_WARNING("xscale does not support value, mask arguments; ignoring");
2298 
2299  /* check that length is a power of two */
2300  for (uint32_t len = watchpoint->length; len != 1; len /= 2) {
2301  if (len % 2) {
2302  LOG_ERROR("xscale requires that watchpoint length is a power of two");
2304  }
2305  }
2306 
2307  if (watchpoint->length == 4) { /* single word watchpoint */
2308  xscale->dbr_available--;/* one DBR reg used */
2309  return ERROR_OK;
2310  }
2311 
2312  /* watchpoints across multiple words require both DBR registers */
2313  if (xscale->dbr_available < 2) {
2314  LOG_ERROR("insufficient watchpoint registers available");
2316  }
2317 
2318  if (watchpoint->length > watchpoint->address) {
2319  LOG_ERROR("xscale does not support watchpoints with length "
2320  "greater than address");
2322  }
2323 
2324  xscale->dbr_available = 0;
2325  return ERROR_OK;
2326 }
2327 
2329  struct watchpoint *watchpoint)
2330 {
2331  struct xscale_common *xscale = target_to_xscale(target);
2332  struct reg *dbcon = &xscale->reg_cache->reg_list[XSCALE_DBCON];
2333  uint32_t dbcon_value = buf_get_u32(dbcon->value, 0, 32);
2334 
2335  if (target->state != TARGET_HALTED) {
2336  LOG_TARGET_ERROR(target, "not halted");
2337  return ERROR_TARGET_NOT_HALTED;
2338  }
2339 
2340  if (!watchpoint->is_set) {
2341  LOG_WARNING("breakpoint not set");
2342  return ERROR_OK;
2343  }
2344 
2345  if (watchpoint->number == 0) {
2346  if (watchpoint->length > 4) {
2347  dbcon_value &= ~0x103; /* clear DBCON[M] as well */
2348  xscale->dbr1_used = 0; /* DBR1 was used for mask */
2349  } else
2350  dbcon_value &= ~0x3;
2351 
2352  xscale_set_reg_u32(dbcon, dbcon_value);
2353  xscale->dbr0_used = 0;
2354  } else if (watchpoint->number == 1) {
2355  dbcon_value &= ~0xc;
2356  xscale_set_reg_u32(dbcon, dbcon_value);
2357  xscale->dbr1_used = 0;
2358  }
2359  watchpoint->is_set = false;
2360 
2361  return ERROR_OK;
2362 }
2363 
2365 {
2366  struct xscale_common *xscale = target_to_xscale(target);
2367 
2368  if (target->state != TARGET_HALTED) {
2369  LOG_TARGET_ERROR(target, "not halted");
2370  return ERROR_TARGET_NOT_HALTED;
2371  }
2372 
2373  if (watchpoint->is_set)
2375 
2376  if (watchpoint->length > 4)
2377  xscale->dbr_available++;/* both DBR regs now available */
2378 
2379  xscale->dbr_available++;
2380 
2381  return ERROR_OK;
2382 }
2383 
2384 static int xscale_get_reg(struct reg *reg)
2385 {
2386  struct xscale_reg *arch_info = reg->arch_info;
2387  struct target *target = arch_info->target;
2388  struct xscale_common *xscale = target_to_xscale(target);
2389 
2390  /* DCSR, TX and RX are accessible via JTAG */
2391  if (strcmp(reg->name, "XSCALE_DCSR") == 0)
2392  return xscale_read_dcsr(arch_info->target);
2393  else if (strcmp(reg->name, "XSCALE_TX") == 0) {
2394  /* 1 = consume register content */
2395  return xscale_read_tx(arch_info->target, 1);
2396  } else if (strcmp(reg->name, "XSCALE_RX") == 0) {
2397  /* can't read from RX register (host -> debug handler) */
2398  return ERROR_OK;
2399  } else if (strcmp(reg->name, "XSCALE_TXRXCTRL") == 0) {
2400  /* can't (explicitly) read from TXRXCTRL register */
2401  return ERROR_OK;
2402  } else {/* Other DBG registers have to be transferred by the debug handler
2403  * send CP read request (command 0x40) */
2404  xscale_send_u32(target, 0x40);
2405 
2406  /* send CP register number */
2408 
2409  /* read register value */
2410  xscale_read_tx(target, 1);
2411  buf_cpy(xscale->reg_cache->reg_list[XSCALE_TX].value, reg->value, 32);
2412 
2413  reg->dirty = false;
2414  reg->valid = true;
2415  }
2416 
2417  return ERROR_OK;
2418 }
2419 
2420 static int xscale_set_reg(struct reg *reg, uint8_t *buf)
2421 {
2422  struct xscale_reg *arch_info = reg->arch_info;
2423  struct target *target = arch_info->target;
2424  struct xscale_common *xscale = target_to_xscale(target);
2425  uint32_t value = buf_get_u32(buf, 0, 32);
2426 
2427  /* DCSR, TX and RX are accessible via JTAG */
2428  if (strcmp(reg->name, "XSCALE_DCSR") == 0) {
2429  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 0, 32, value);
2430  return xscale_write_dcsr(arch_info->target, -1, -1);
2431  } else if (strcmp(reg->name, "XSCALE_RX") == 0) {
2432  buf_set_u32(xscale->reg_cache->reg_list[XSCALE_RX].value, 0, 32, value);
2433  return xscale_write_rx(arch_info->target);
2434  } else if (strcmp(reg->name, "XSCALE_TX") == 0) {
2435  /* can't write to TX register (debug-handler -> host) */
2436  return ERROR_OK;
2437  } else if (strcmp(reg->name, "XSCALE_TXRXCTRL") == 0) {
2438  /* can't (explicitly) write to TXRXCTRL register */
2439  return ERROR_OK;
2440  } else {/* Other DBG registers have to be transferred by the debug handler
2441  * send CP write request (command 0x41) */
2442  xscale_send_u32(target, 0x41);
2443 
2444  /* send CP register number */
2446 
2447  /* send CP register value */
2448  xscale_send_u32(target, value);
2449  buf_set_u32(reg->value, 0, 32, value);
2450  }
2451 
2452  return ERROR_OK;
2453 }
2454 
2455 static int xscale_write_dcsr_sw(struct target *target, uint32_t value)
2456 {
2457  struct xscale_common *xscale = target_to_xscale(target);
2458  struct reg *dcsr = &xscale->reg_cache->reg_list[XSCALE_DCSR];
2459  struct xscale_reg *dcsr_arch_info = dcsr->arch_info;
2460 
2461  /* send CP write request (command 0x41) */
2462  xscale_send_u32(target, 0x41);
2463 
2464  /* send CP register number */
2465  xscale_send_u32(target, dcsr_arch_info->dbg_handler_number);
2466 
2467  /* send CP register value */
2468  xscale_send_u32(target, value);
2469  buf_set_u32(dcsr->value, 0, 32, value);
2470 
2471  return ERROR_OK;
2472 }
2473 
2474 static int xscale_read_trace(struct target *target)
2475 {
2476  struct xscale_common *xscale = target_to_xscale(target);
2477  struct arm *arm = &xscale->arm;
2478  struct xscale_trace_data **trace_data_p;
2479 
2480  /* 258 words from debug handler
2481  * 256 trace buffer entries
2482  * 2 checkpoint addresses
2483  */
2484  uint32_t trace_buffer[258];
2485  int is_address[256];
2486  int i, j;
2487  unsigned int num_checkpoints = 0;
2488 
2489  if (target->state != TARGET_HALTED) {
2490  LOG_TARGET_ERROR(target, "must be stopped to read trace data");
2491  return ERROR_TARGET_NOT_HALTED;
2492  }
2493 
2494  /* send read trace buffer command (command 0x61) */
2495  xscale_send_u32(target, 0x61);
2496 
2497  /* receive trace buffer content */
2498  xscale_receive(target, trace_buffer, 258);
2499 
2500  /* parse buffer backwards to identify address entries */
2501  for (i = 255; i >= 0; i--) {
2502  /* also count number of checkpointed entries */
2503  if ((trace_buffer[i] & 0xe0) == 0xc0)
2504  num_checkpoints++;
2505 
2506  is_address[i] = 0;
2507  if (((trace_buffer[i] & 0xf0) == 0x90) ||
2508  ((trace_buffer[i] & 0xf0) == 0xd0)) {
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  if (i > 0)
2516  is_address[--i] = 1;
2517  }
2518  }
2519 
2520 
2521  /* search first non-zero entry that is not part of an address */
2522  for (j = 0; (j < 256) && (trace_buffer[j] == 0) && (!is_address[j]); j++)
2523  ;
2524 
2525  if (j == 256) {
2526  LOG_DEBUG("no trace data collected");
2528  }
2529 
2530  /* account for possible partial address at buffer start (wrap mode only) */
2531  if (is_address[0]) { /* first entry is address; complete set of 4? */
2532  i = 1;
2533  while (i < 4)
2534  if (!is_address[i++])
2535  break;
2536  if (i < 4)
2537  j += i; /* partial address; can't use it */
2538  }
2539 
2540  /* if first valid entry is indirect branch, can't use that either (no address) */
2541  if (((trace_buffer[j] & 0xf0) == 0x90) || ((trace_buffer[j] & 0xf0) == 0xd0))
2542  j++;
2543 
2544  /* walk linked list to terminating entry */
2545  for (trace_data_p = &xscale->trace.data; *trace_data_p;
2546  trace_data_p = &(*trace_data_p)->next)
2547  ;
2548 
2549  *trace_data_p = malloc(sizeof(struct xscale_trace_data));
2550  (*trace_data_p)->next = NULL;
2551  (*trace_data_p)->chkpt0 = trace_buffer[256];
2552  (*trace_data_p)->chkpt1 = trace_buffer[257];
2553  (*trace_data_p)->last_instruction = buf_get_u32(arm->pc->value, 0, 32);
2554  (*trace_data_p)->entries = malloc(sizeof(struct xscale_trace_entry) * (256 - j));
2555  (*trace_data_p)->depth = 256 - j;
2556  (*trace_data_p)->num_checkpoints = num_checkpoints;
2557 
2558  for (i = j; i < 256; i++) {
2559  (*trace_data_p)->entries[i - j].data = trace_buffer[i];
2560  if (is_address[i])
2561  (*trace_data_p)->entries[i - j].type = XSCALE_TRACE_ADDRESS;
2562  else
2563  (*trace_data_p)->entries[i - j].type = XSCALE_TRACE_MESSAGE;
2564  }
2565 
2566  return ERROR_OK;
2567 }
2568 
2569 static int xscale_read_instruction(struct target *target, uint32_t pc,
2570  struct arm_instruction *instruction)
2571 {
2572  struct xscale_common *const xscale = target_to_xscale(target);
2573  int section = -1;
2574  size_t size_read;
2575  uint32_t opcode;
2576  int retval;
2577 
2578  if (!xscale->trace.image)
2580 
2581  /* search for the section the current instruction belongs to */
2582  for (unsigned int i = 0; i < xscale->trace.image->num_sections; i++) {
2583  if ((xscale->trace.image->sections[i].base_address <= pc) &&
2584  (xscale->trace.image->sections[i].base_address +
2585  xscale->trace.image->sections[i].size > pc)) {
2586  section = i;
2587  break;
2588  }
2589  }
2590 
2591  if (section == -1) {
2592  /* current instruction couldn't be found in the image */
2594  }
2595 
2596  if (xscale->trace.core_state == ARM_STATE_ARM) {
2597  uint8_t buf[4];
2598  retval = image_read_section(xscale->trace.image, section,
2599  pc - xscale->trace.image->sections[section].base_address,
2600  4, buf, &size_read);
2601  if (retval != ERROR_OK) {
2602  LOG_ERROR("error while reading instruction");
2604  }
2605  opcode = target_buffer_get_u32(target, buf);
2606  arm_evaluate_opcode(opcode, pc, instruction);
2607  } else if (xscale->trace.core_state == ARM_STATE_THUMB) {
2608  uint8_t buf[2];
2609  retval = image_read_section(xscale->trace.image, section,
2610  pc - xscale->trace.image->sections[section].base_address,
2611  2, buf, &size_read);
2612  if (retval != ERROR_OK) {
2613  LOG_ERROR("error while reading instruction");
2615  }
2616  opcode = target_buffer_get_u16(target, buf);
2617  thumb_evaluate_opcode(opcode, pc, instruction);
2618  } else {
2619  LOG_ERROR("BUG: unknown core state encountered");
2620  exit(-1);
2621  }
2622 
2623  return ERROR_OK;
2624 }
2625 
2626 /* Extract address encoded into trace data.
2627  * Write result to address referenced by argument 'target', or 0 if incomplete. */
2628 static inline void xscale_branch_address(struct xscale_trace_data *trace_data,
2629  int i, uint32_t *target)
2630 {
2631  /* if there are less than four entries prior to the indirect branch message
2632  * we can't extract the address */
2633  if (i < 4)
2634  *target = 0;
2635  else {
2636  *target = (trace_data->entries[i-1].data) | (trace_data->entries[i-2].data << 8) |
2637  (trace_data->entries[i-3].data << 16) | (trace_data->entries[i-4].data << 24);
2638  }
2639 }
2640 
2641 static inline void xscale_display_instruction(struct target *target, uint32_t pc,
2642  struct arm_instruction *instruction,
2643  struct command_invocation *cmd)
2644 {
2645  int retval = xscale_read_instruction(target, pc, instruction);
2646  if (retval == ERROR_OK)
2647  command_print(cmd, "%s", instruction->text);
2648  else
2649  command_print(cmd, "0x%8.8" PRIx32 "\t<not found in image>", pc);
2650 }
2651 
2653 {
2654  struct xscale_common *xscale = target_to_xscale(target);
2655  struct xscale_trace_data *trace_data = xscale->trace.data;
2656  int i, retval;
2657  uint32_t breakpoint_pc = 0;
2658  struct arm_instruction instruction;
2659  uint32_t current_pc = 0;/* initialized when address determined */
2660 
2661  if (!xscale->trace.image)
2662  LOG_WARNING("No trace image loaded; use 'xscale trace_image'");
2663 
2664  /* loop for each trace buffer that was loaded from target */
2665  while (trace_data) {
2666  int chkpt = 0; /* incremented as checkpointed entries found */
2667  int j;
2668 
2669  /* FIXME: set this to correct mode when trace buffer is first enabled */
2670  xscale->trace.core_state = ARM_STATE_ARM;
2671 
2672  /* loop for each entry in this trace buffer */
2673  for (i = 0; i < trace_data->depth; i++) {
2674  int exception = 0;
2675  uint32_t chkpt_reg = 0x0;
2676  uint32_t branch_target = 0;
2677  int count;
2678 
2679  /* trace entry type is upper nybble of 'message byte' */
2680  int trace_msg_type = (trace_data->entries[i].data & 0xf0) >> 4;
2681 
2682  /* Target addresses of indirect branches are written into buffer
2683  * before the message byte representing the branch. Skip past it */
2684  if (trace_data->entries[i].type == XSCALE_TRACE_ADDRESS)
2685  continue;
2686 
2687  switch (trace_msg_type) {
2688  case 0: /* Exceptions */
2689  case 1:
2690  case 2:
2691  case 3:
2692  case 4:
2693  case 5:
2694  case 6:
2695  case 7:
2696  exception = (trace_data->entries[i].data & 0x70) >> 4;
2697 
2698  /* FIXME: vector table may be at ffff0000 */
2699  branch_target = (trace_data->entries[i].data & 0xf0) >> 2;
2700  break;
2701 
2702  case 8: /* Direct Branch */
2703  break;
2704 
2705  case 9: /* Indirect Branch */
2706  xscale_branch_address(trace_data, i, &branch_target);
2707  break;
2708 
2709  case 13: /* Checkpointed Indirect Branch */
2710  xscale_branch_address(trace_data, i, &branch_target);
2711  if ((trace_data->num_checkpoints == 2) && (chkpt == 0))
2712  chkpt_reg = trace_data->chkpt1; /* 2 chkpts, this is
2713  *oldest */
2714  else
2715  chkpt_reg = trace_data->chkpt0; /* 1 chkpt, or 2 and
2716  *newest */
2717 
2718  chkpt++;
2719  break;
2720 
2721  case 12: /* Checkpointed Direct Branch */
2722  if ((trace_data->num_checkpoints == 2) && (chkpt == 0))
2723  chkpt_reg = trace_data->chkpt1; /* 2 chkpts, this is
2724  *oldest */
2725  else
2726  chkpt_reg = trace_data->chkpt0; /* 1 chkpt, or 2 and
2727  *newest */
2728 
2729  /* if no current_pc, checkpoint will be starting point */
2730  if (current_pc == 0)
2731  branch_target = chkpt_reg;
2732 
2733  chkpt++;
2734  break;
2735 
2736  case 15:/* Roll-over */
2737  break;
2738 
2739  default:/* Reserved */
2740  LOG_WARNING("trace is suspect: invalid trace message byte");
2741  continue;
2742 
2743  }
2744 
2745  /* If we don't have the current_pc yet, but we did get the branch target
2746  * (either from the trace buffer on indirect branch, or from a checkpoint reg),
2747  * then we can start displaying instructions at the next iteration, with
2748  * branch_target as the starting point.
2749  */
2750  if (current_pc == 0) {
2751  current_pc = branch_target; /* remains 0 unless branch_target *obtained */
2752  continue;
2753  }
2754 
2755  /* We have current_pc. Read and display the instructions from the image.
2756  * First, display count instructions (lower nybble of message byte). */
2757  count = trace_data->entries[i].data & 0x0f;
2758  for (j = 0; j < count; j++) {
2759  xscale_display_instruction(target, current_pc, &instruction,
2760  cmd);
2761  current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2;
2762  }
2763 
2764  /* An additional instruction is implicitly added to count for
2765  * rollover and some exceptions: undef, swi, prefetch abort. */
2766  if ((trace_msg_type == 15) || (exception > 0 && exception < 4)) {
2767  xscale_display_instruction(target, current_pc, &instruction,
2768  cmd);
2769  current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2;
2770  }
2771 
2772  if (trace_msg_type == 15) /* rollover */
2773  continue;
2774 
2775  if (exception) {
2776  command_print(cmd, "--- exception %i ---", exception);
2777  continue;
2778  }
2779 
2780  /* not exception or rollover; next instruction is a branch and is
2781  * not included in the count */
2782  xscale_display_instruction(target, current_pc, &instruction, cmd);
2783 
2784  /* for direct branches, extract branch destination from instruction */
2785  if ((trace_msg_type == 8) || (trace_msg_type == 12)) {
2786  retval = xscale_read_instruction(target, current_pc, &instruction);
2787  if (retval == ERROR_OK)
2788  current_pc = instruction.info.b_bl_bx_blx.target_address;
2789  else
2790  current_pc = 0; /* branch destination unknown */
2791 
2792  /* direct branch w/ checkpoint; can also get from checkpoint reg */
2793  if (trace_msg_type == 12) {
2794  if (current_pc == 0)
2795  current_pc = chkpt_reg;
2796  else if (current_pc != chkpt_reg) /* sanity check */
2797  LOG_WARNING("trace is suspect: checkpoint register "
2798  "inconsistent with address from image");
2799  }
2800 
2801  if (current_pc == 0)
2802  command_print(cmd, "address unknown");
2803 
2804  continue;
2805  }
2806 
2807  /* indirect branch; the branch destination was read from trace buffer */
2808  if ((trace_msg_type == 9) || (trace_msg_type == 13)) {
2809  current_pc = branch_target;
2810 
2811  /* sanity check (checkpoint reg is redundant) */
2812  if ((trace_msg_type == 13) && (chkpt_reg != branch_target))
2813  LOG_WARNING("trace is suspect: checkpoint register "
2814  "inconsistent with address from trace buffer");
2815  }
2816 
2817  } /* END: for (i = 0; i < trace_data->depth; i++) */
2818 
2819  breakpoint_pc = trace_data->last_instruction; /* used below */
2820  trace_data = trace_data->next;
2821 
2822  } /* END: while (trace_data) */
2823 
2824  /* Finally... display all instructions up to the value of the pc when the
2825  * debug break occurred (saved when trace data was collected from target).
2826  * This is necessary because the trace only records execution branches and 16
2827  * consecutive instructions (rollovers), so last few typically missed.
2828  */
2829  if (current_pc == 0)
2830  return ERROR_OK;/* current_pc was never found */
2831 
2832  /* how many instructions remaining? */
2833  int gap_count = (breakpoint_pc - current_pc) /
2834  (xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2);
2835 
2836  /* should never be negative or over 16, but verify */
2837  if (gap_count < 0 || gap_count > 16) {
2838  LOG_WARNING("trace is suspect: excessive gap at end of trace");
2839  return ERROR_OK;/* bail; large number or negative value no good */
2840  }
2841 
2842  /* display remaining instructions */
2843  for (i = 0; i < gap_count; i++) {
2844  xscale_display_instruction(target, current_pc, &instruction, cmd);
2845  current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2;
2846  }
2847 
2848  return ERROR_OK;
2849 }
2850 
2851 static const struct reg_arch_type xscale_reg_type = {
2852  .get = xscale_get_reg,
2853  .set = xscale_set_reg,
2854 };
2855 
2857 {
2858  struct xscale_common *xscale = target_to_xscale(target);
2859  struct arm *arm = &xscale->arm;
2860  struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache);
2861  struct xscale_reg *arch_info = malloc(sizeof(xscale_reg_arch_info));
2862  int i;
2863  int num_regs = ARRAY_SIZE(xscale_reg_arch_info);
2864 
2865  (*cache_p) = arm_build_reg_cache(target, arm);
2866 
2867  (*cache_p)->next = malloc(sizeof(struct reg_cache));
2868  cache_p = &(*cache_p)->next;
2869 
2870  /* fill in values for the xscale reg cache */
2871  (*cache_p)->name = "XScale registers";
2872  (*cache_p)->next = NULL;
2873  (*cache_p)->reg_list = calloc(num_regs, sizeof(struct reg));
2874  (*cache_p)->num_regs = num_regs;
2875 
2876  for (i = 0; i < num_regs; i++) {
2877  (*cache_p)->reg_list[i].name = xscale_reg_list[i];
2878  (*cache_p)->reg_list[i].value = calloc(4, 1);
2879  (*cache_p)->reg_list[i].dirty = false;
2880  (*cache_p)->reg_list[i].valid = false;
2881  (*cache_p)->reg_list[i].size = 32;
2882  (*cache_p)->reg_list[i].arch_info = &arch_info[i];
2883  (*cache_p)->reg_list[i].type = &xscale_reg_type;
2884  (*cache_p)->reg_list[i].exist = true;
2885  arch_info[i] = xscale_reg_arch_info[i];
2886  arch_info[i].target = target;
2887  }
2888 
2889  xscale->reg_cache = (*cache_p);
2890 }
2891 
2893 {
2894  struct xscale_common *xscale = target_to_xscale(target);
2895  struct reg_cache *cache = xscale->reg_cache;
2896 
2897  for (unsigned int i = 0; i < ARRAY_SIZE(xscale_reg_arch_info); i++)
2898  free(cache->reg_list[i].value);
2899 
2900  free(cache->reg_list[0].arch_info);
2901  free(cache->reg_list);
2902  free(cache);
2903 
2904  arm_free_reg_cache(&xscale->arm);
2905 }
2906 
2907 static int xscale_init_target(struct command_context *cmd_ctx,
2908  struct target *target)
2909 {
2911  return ERROR_OK;
2912 }
2913 
2914 static void xscale_deinit_target(struct target *target)
2915 {
2916  struct xscale_common *xscale = target_to_xscale(target);
2917 
2919  free(xscale);
2920 }
2921 
2923  struct xscale_common *xscale, struct jtag_tap *tap)
2924 {
2925  struct arm *arm;
2926  uint32_t high_reset_branch, low_reset_branch;
2927  int i;
2928 
2929  arm = &xscale->arm;
2930 
2931  /* store architecture specific data */
2933 
2934  /* PXA3xx with 11 bit IR shifts the JTAG instructions */
2935  if (tap->ir_length == 11)
2936  xscale->xscale_variant = XSCALE_PXA3XX;
2937  else
2939 
2940  /* the debug handler isn't installed (and thus not running) at this time */
2941  xscale->handler_address = 0xfe000800;
2942 
2943  /* clear the vectors we keep locally for reference */
2944  memset(xscale->low_vectors, 0, sizeof(xscale->low_vectors));
2945  memset(xscale->high_vectors, 0, sizeof(xscale->high_vectors));
2946 
2947  /* no user-specified vectors have been configured yet */
2948  xscale->static_low_vectors_set = 0x0;
2949  xscale->static_high_vectors_set = 0x0;
2950 
2951  /* calculate branches to debug handler */
2952  low_reset_branch = (xscale->handler_address + 0x20 - 0x0 - 0x8) >> 2;
2953  high_reset_branch = (xscale->handler_address + 0x20 - 0xffff0000 - 0x8) >> 2;
2954 
2955  xscale->low_vectors[0] = ARMV4_5_B((low_reset_branch & 0xffffff), 0);
2956  xscale->high_vectors[0] = ARMV4_5_B((high_reset_branch & 0xffffff), 0);
2957 
2958  for (i = 1; i <= 7; i++) {
2959  xscale->low_vectors[i] = ARMV4_5_B(0xfffffe, 0);
2960  xscale->high_vectors[i] = ARMV4_5_B(0xfffffe, 0);
2961  }
2962 
2963  /* 64kB aligned region used for DCache cleaning */
2964  xscale->cache_clean_address = 0xfffe0000;
2965 
2966  xscale->hold_rst = 0;
2967  xscale->external_debug_break = 0;
2968 
2969  xscale->ibcr_available = 2;
2970  xscale->ibcr0_used = 0;
2971  xscale->ibcr1_used = 0;
2972 
2973  xscale->dbr_available = 2;
2974  xscale->dbr0_used = 0;
2975  xscale->dbr1_used = 0;
2976 
2977  LOG_INFO("%s: hardware has 2 breakpoints and 2 watchpoints",
2978  target_name(target));
2979 
2980  xscale->arm_bkpt = ARMV5_BKPT(0x0);
2981  xscale->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
2982 
2983  xscale->vector_catch = 0x1;
2984 
2985  xscale->trace.data = NULL;
2986  xscale->trace.image = NULL;
2987  xscale->trace.mode = XSCALE_TRACE_DISABLED;
2988  xscale->trace.buffer_fill = 0;
2989  xscale->trace.fill_counter = 0;
2990 
2991  /* prepare ARMv4/5 specific information */
2992  arm->arch_info = xscale;
2997 
2999 
3000  xscale->armv4_5_mmu.armv4_5_cache.ctype = -1;
3006  xscale->armv4_5_mmu.has_tiny_pages = 1;
3007  xscale->armv4_5_mmu.mmu_enabled = false;
3008 
3009  return ERROR_OK;
3010 }
3011 
3013 {
3014  struct xscale_common *xscale;
3015 
3016  if (sizeof(xscale_debug_handler) > 0x800) {
3017  LOG_ERROR("debug_handler.bin: larger than 2kb");
3018  return ERROR_FAIL;
3019  }
3020 
3021  xscale = calloc(1, sizeof(*xscale));
3022  if (!xscale)
3023  return ERROR_FAIL;
3024 
3025  return xscale_init_arch_info(target, xscale, target->tap);
3026 }
3027 
3028 COMMAND_HANDLER(xscale_handle_debug_handler_command)
3029 {
3030  struct target *target = NULL;
3031  struct xscale_common *xscale;
3032  int retval;
3033  uint32_t handler_address;
3034 
3035  if (CMD_ARGC < 2)
3037 
3038  target = get_target(CMD_ARGV[0]);
3039  if (!target) {
3040  LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
3041  return ERROR_FAIL;
3042  }
3043 
3044  xscale = target_to_xscale(target);
3045  retval = xscale_verify_pointer(CMD, xscale);
3046  if (retval != ERROR_OK)
3047  return retval;
3048 
3050 
3051  if (((handler_address >= 0x800) && (handler_address <= 0x1fef800)) ||
3052  ((handler_address >= 0xfe000800) && (handler_address <= 0xfffff800)))
3053  xscale->handler_address = handler_address;
3054  else {
3055  LOG_ERROR(
3056  "xscale debug_handler <address> must be between 0x800 and 0x1fef800 or between 0xfe000800 and 0xfffff800");
3057  return ERROR_FAIL;
3058  }
3059 
3060  return ERROR_OK;
3061 }
3062 
3063 COMMAND_HANDLER(xscale_handle_cache_clean_address_command)
3064 {
3065  struct target *target = NULL;
3066  struct xscale_common *xscale;
3067  int retval;
3068  uint32_t cache_clean_address;
3069 
3070  if (CMD_ARGC < 2)
3072 
3073  target = get_target(CMD_ARGV[0]);
3074  if (!target) {
3075  LOG_ERROR("target '%s' not defined", CMD_ARGV[0]);
3076  return ERROR_FAIL;
3077  }
3078  xscale = target_to_xscale(target);
3079  retval = xscale_verify_pointer(CMD, xscale);
3080  if (retval != ERROR_OK)
3081  return retval;
3082 
3084 
3085  if (cache_clean_address & 0xffff)
3086  LOG_ERROR("xscale cache_clean_address <address> must be 64kb aligned");
3087  else
3089 
3090  return ERROR_OK;
3091 }
3092 
3093 COMMAND_HANDLER(xscale_handle_cache_info_command)
3094 {
3096  struct xscale_common *xscale = target_to_xscale(target);
3097  int retval;
3098 
3099  retval = xscale_verify_pointer(CMD, xscale);
3100  if (retval != ERROR_OK)
3101  return retval;
3102 
3104 }
3105 
3106 static int xscale_virt2phys(struct target *target,
3107  target_addr_t virtual, target_addr_t *physical)
3108 {
3109  struct xscale_common *xscale = target_to_xscale(target);
3110  uint32_t cb;
3111 
3112  if (xscale->common_magic != XSCALE_COMMON_MAGIC) {
3114  return ERROR_TARGET_INVALID;
3115  }
3116 
3117  uint32_t ret;
3118  int retval = armv4_5_mmu_translate_va(target, &xscale->armv4_5_mmu,
3119  virtual, &cb, &ret);
3120  if (retval != ERROR_OK)
3121  return retval;
3122  *physical = ret;
3123  return ERROR_OK;
3124 }
3125 
3126 static int xscale_mmu(struct target *target, bool *enabled)
3127 {
3128  struct xscale_common *xscale = target_to_xscale(target);
3129 
3130  if (target->state != TARGET_HALTED) {
3131  LOG_TARGET_ERROR(target, "not halted");
3132  return ERROR_TARGET_NOT_HALTED;
3133  }
3134  *enabled = xscale->armv4_5_mmu.mmu_enabled;
3135  return ERROR_OK;
3136 }
3137 
3138 COMMAND_HANDLER(xscale_handle_mmu_command)
3139 {
3141  struct xscale_common *xscale = target_to_xscale(target);
3142  int retval;
3143 
3144  retval = xscale_verify_pointer(CMD, xscale);
3145  if (retval != ERROR_OK)
3146  return retval;
3147 
3148  if (target->state != TARGET_HALTED) {
3149  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3150  return ERROR_TARGET_NOT_HALTED;
3151  }
3152 
3153  if (CMD_ARGC >= 1) {
3154  bool enable;
3155  COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
3156  if (enable)
3157  xscale_enable_mmu_caches(target, 1, 0, 0);
3158  else
3160  xscale->armv4_5_mmu.mmu_enabled = enable;
3161  }
3162 
3163  command_print(CMD, "mmu %s",
3164  (xscale->armv4_5_mmu.mmu_enabled) ? "enabled" : "disabled");
3165 
3166  return ERROR_OK;
3167 }
3168 
3169 COMMAND_HANDLER(xscale_handle_idcache_command)
3170 {
3172  struct xscale_common *xscale = target_to_xscale(target);
3173 
3174  int retval = xscale_verify_pointer(CMD, xscale);
3175  if (retval != ERROR_OK)
3176  return retval;
3177 
3178  if (target->state != TARGET_HALTED) {
3179  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3180  return ERROR_TARGET_NOT_HALTED;
3181  }
3182 
3183  bool icache = false;
3184  if (strcmp(CMD_NAME, "icache") == 0)
3185  icache = true;
3186  if (CMD_ARGC >= 1) {
3187  bool enable;
3188  COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
3189  if (icache) {
3190  xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled = enable;
3191  if (enable)
3192  xscale_enable_mmu_caches(target, 0, 0, 1);
3193  else
3195  } else {
3196  xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = enable;
3197  if (enable)
3198  xscale_enable_mmu_caches(target, 0, 1, 0);
3199  else
3201  }
3202  }
3203 
3204  bool enabled = icache ?
3207  const char *msg = enabled ? "enabled" : "disabled";
3208  command_print(CMD, "%s %s", CMD_NAME, msg);
3209 
3210  return ERROR_OK;
3211 }
3212 
3213 static const struct {
3214  char name[15];
3215  unsigned int mask;
3216 } vec_ids[] = {
3217  { "fiq", DCSR_TF, },
3218  { "irq", DCSR_TI, },
3219  { "dabt", DCSR_TD, },
3220  { "pabt", DCSR_TA, },
3221  { "swi", DCSR_TS, },
3222  { "undef", DCSR_TU, },
3223  { "reset", DCSR_TR, },
3224 };
3225 
3226 COMMAND_HANDLER(xscale_handle_vector_catch_command)
3227 {
3229  struct xscale_common *xscale = target_to_xscale(target);
3230  int retval;
3231  uint32_t dcsr_value;
3232  uint32_t catch = 0;
3233  struct reg *dcsr_reg = &xscale->reg_cache->reg_list[XSCALE_DCSR];
3234 
3235  retval = xscale_verify_pointer(CMD, xscale);
3236  if (retval != ERROR_OK)
3237  return retval;
3238 
3239  if (CMD_ARGC > 0) {
3240  if (CMD_ARGC == 1) {
3241  if (strcmp(CMD_ARGV[0], "all") == 0) {
3242  catch = DCSR_TRAP_MASK;
3243  CMD_ARGC--;
3244  } else if (strcmp(CMD_ARGV[0], "none") == 0) {
3245  catch = 0;
3246  CMD_ARGC--;
3247  }
3248  }
3249  while (CMD_ARGC-- > 0) {
3250  unsigned int i;
3251  for (i = 0; i < ARRAY_SIZE(vec_ids); i++) {
3252  if (strcmp(CMD_ARGV[CMD_ARGC], vec_ids[i].name))
3253  continue;
3254  catch |= vec_ids[i].mask;
3255  break;
3256  }
3257  if (i == ARRAY_SIZE(vec_ids)) {
3258  LOG_ERROR("No vector '%s'", CMD_ARGV[CMD_ARGC]);
3260  }
3261  }
3262  buf_set_u32(dcsr_reg->value, 0, 32,
3263  (buf_get_u32(dcsr_reg->value, 0, 32) & ~DCSR_TRAP_MASK) | catch);
3264  xscale_write_dcsr(target, -1, -1);
3265  }
3266 
3267  dcsr_value = buf_get_u32(dcsr_reg->value, 0, 32);
3268  for (unsigned int i = 0; i < ARRAY_SIZE(vec_ids); i++) {
3269  command_print(CMD, "%15s: %s", vec_ids[i].name,
3270  (dcsr_value & vec_ids[i].mask) ? "catch" : "ignore");
3271  }
3272 
3273  return ERROR_OK;
3274 }
3275 
3276 
3277 COMMAND_HANDLER(xscale_handle_vector_table_command)
3278 {
3280  struct xscale_common *xscale = target_to_xscale(target);
3281  int err = 0;
3282  int retval;
3283 
3284  retval = xscale_verify_pointer(CMD, xscale);
3285  if (retval != ERROR_OK)
3286  return retval;
3287 
3288  if (CMD_ARGC == 0) { /* print current settings */
3289  int idx;
3290 
3291  command_print(CMD, "active user-set static vectors:");
3292  for (idx = 1; idx < 8; idx++)
3293  if (xscale->static_low_vectors_set & (1 << idx))
3295  "low %d: 0x%" PRIx32,
3296  idx,
3297  xscale->static_low_vectors[idx]);
3298  for (idx = 1; idx < 8; idx++)
3299  if (xscale->static_high_vectors_set & (1 << idx))
3301  "high %d: 0x%" PRIx32,
3302  idx,
3303  xscale->static_high_vectors[idx]);
3304  return ERROR_OK;
3305  }
3306 
3307  if (CMD_ARGC != 3)
3308  err = 1;
3309  else {
3310  int idx;
3311  COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], idx);
3312  uint32_t vec;
3313  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], vec);
3314 
3315  if (idx < 1 || idx >= 8)
3316  err = 1;
3317 
3318  if (!err && strcmp(CMD_ARGV[0], "low") == 0) {
3319  xscale->static_low_vectors_set |= (1<<idx);
3320  xscale->static_low_vectors[idx] = vec;
3321  } else if (!err && (strcmp(CMD_ARGV[0], "high") == 0)) {
3322  xscale->static_high_vectors_set |= (1<<idx);
3323  xscale->static_high_vectors[idx] = vec;
3324  } else
3325  err = 1;
3326  }
3327 
3328  if (err)
3330 
3331  return ERROR_OK;
3332 }
3333 
3334 
3335 COMMAND_HANDLER(xscale_handle_trace_buffer_command)
3336 {
3338  struct xscale_common *xscale = target_to_xscale(target);
3339  uint32_t dcsr_value;
3340  int retval;
3341 
3342  retval = xscale_verify_pointer(CMD, xscale);
3343  if (retval != ERROR_OK)
3344  return retval;
3345 
3346  if (target->state != TARGET_HALTED) {
3347  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3348  return ERROR_TARGET_NOT_HALTED;
3349  }
3350 
3351  if (CMD_ARGC >= 1) {
3352  if (strcmp("enable", CMD_ARGV[0]) == 0)
3353  xscale->trace.mode = XSCALE_TRACE_WRAP; /* default */
3354  else if (strcmp("disable", CMD_ARGV[0]) == 0)
3355  xscale->trace.mode = XSCALE_TRACE_DISABLED;
3356  else
3358  }
3359 
3360  if (CMD_ARGC >= 2 && xscale->trace.mode != XSCALE_TRACE_DISABLED) {
3361  if (strcmp("fill", CMD_ARGV[1]) == 0) {
3362  int buffcount = 1; /* default */
3363  if (CMD_ARGC >= 3)
3364  COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], buffcount);
3365  if (buffcount < 1) { /* invalid */
3366  command_print(CMD, "fill buffer count must be > 0");
3367  xscale->trace.mode = XSCALE_TRACE_DISABLED;
3369  }
3370  xscale->trace.buffer_fill = buffcount;
3371  xscale->trace.mode = XSCALE_TRACE_FILL;
3372  } else if (strcmp("wrap", CMD_ARGV[1]) == 0)
3373  xscale->trace.mode = XSCALE_TRACE_WRAP;
3374  else {
3375  xscale->trace.mode = XSCALE_TRACE_DISABLED;
3377  }
3378  }
3379 
3380  if (xscale->trace.mode != XSCALE_TRACE_DISABLED) {
3381  char fill_string[12];
3382  sprintf(fill_string, "fill %d", xscale->trace.buffer_fill);
3383  command_print(CMD, "trace buffer enabled (%s)",
3384  (xscale->trace.mode == XSCALE_TRACE_FILL)
3385  ? fill_string : "wrap");
3386  } else
3387  command_print(CMD, "trace buffer disabled");
3388 
3389  dcsr_value = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 0, 32);
3390  if (xscale->trace.mode == XSCALE_TRACE_FILL)
3391  xscale_write_dcsr_sw(target, (dcsr_value & 0xfffffffc) | 2);
3392  else
3393  xscale_write_dcsr_sw(target, dcsr_value & 0xfffffffc);
3394 
3395  return ERROR_OK;
3396 }
3397 
3398 COMMAND_HANDLER(xscale_handle_trace_image_command)
3399 {
3401  struct xscale_common *xscale = target_to_xscale(target);
3402  int retval;
3403 
3404  if (CMD_ARGC < 1)
3406 
3407  retval = xscale_verify_pointer(CMD, xscale);
3408  if (retval != ERROR_OK)
3409  return retval;
3410 
3411  if (xscale->trace.image) {
3412  image_close(xscale->trace.image);
3413  free(xscale->trace.image);
3414  command_print(CMD, "previously loaded image found and closed");
3415  }
3416 
3417  xscale->trace.image = malloc(sizeof(struct image));
3418  xscale->trace.image->base_address_set = false;
3419  xscale->trace.image->start_address_set = false;
3420 
3421  /* a base address isn't always necessary, default to 0x0 (i.e. don't relocate) */
3422  if (CMD_ARGC >= 2) {
3423  xscale->trace.image->base_address_set = true;
3424  COMMAND_PARSE_NUMBER(llong, CMD_ARGV[1], xscale->trace.image->base_address);
3425  } else
3426  xscale->trace.image->base_address_set = false;
3427 
3428  if (image_open(xscale->trace.image, CMD_ARGV[0],
3429  (CMD_ARGC >= 3) ? CMD_ARGV[2] : NULL) != ERROR_OK) {
3430  free(xscale->trace.image);
3431  xscale->trace.image = NULL;
3432  return ERROR_OK;
3433  }
3434 
3435  return ERROR_OK;
3436 }
3437 
3438 COMMAND_HANDLER(xscale_handle_dump_trace_command)
3439 {
3441  struct xscale_common *xscale = target_to_xscale(target);
3442  struct xscale_trace_data *trace_data;
3443  struct fileio *file;
3444  int retval;
3445 
3446  retval = xscale_verify_pointer(CMD, xscale);
3447  if (retval != ERROR_OK)
3448  return retval;
3449 
3450  if (target->state != TARGET_HALTED) {
3451  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3452  return ERROR_TARGET_NOT_HALTED;
3453  }
3454 
3455  if (CMD_ARGC < 1)
3457 
3458  trace_data = xscale->trace.data;
3459 
3460  if (!trace_data) {
3461  command_print(CMD, "no trace data collected");
3462  return ERROR_OK;
3463  }
3464 
3466  return ERROR_OK;
3467 
3468  while (trace_data) {
3469  int i;
3470 
3471  fileio_write_u32(file, trace_data->chkpt0);
3472  fileio_write_u32(file, trace_data->chkpt1);
3473  fileio_write_u32(file, trace_data->last_instruction);
3474  fileio_write_u32(file, trace_data->depth);
3475 
3476  for (i = 0; i < trace_data->depth; i++)
3477  fileio_write_u32(file, trace_data->entries[i].data |
3478  ((trace_data->entries[i].type & 0xffff) << 16));
3479 
3480  trace_data = trace_data->next;
3481  }
3482 
3483  fileio_close(file);
3484 
3485  return ERROR_OK;
3486 }
3487 
3488 COMMAND_HANDLER(xscale_handle_analyze_trace_buffer_command)
3489 {
3491  struct xscale_common *xscale = target_to_xscale(target);
3492  int retval;
3493 
3494  retval = xscale_verify_pointer(CMD, xscale);
3495  if (retval != ERROR_OK)
3496  return retval;
3497 
3499 
3500  return ERROR_OK;
3501 }
3502 
3503 COMMAND_HANDLER(xscale_handle_cp15)
3504 {
3506  struct xscale_common *xscale = target_to_xscale(target);
3507  int retval;
3508 
3509  retval = xscale_verify_pointer(CMD, xscale);
3510  if (retval != ERROR_OK)
3511  return retval;
3512 
3513  if (target->state != TARGET_HALTED) {
3514  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
3515  return ERROR_TARGET_NOT_HALTED;
3516  }
3517  uint32_t reg_no = 0;
3518  struct reg *reg = NULL;
3519  if (CMD_ARGC > 0) {
3520  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], reg_no);
3521  /*translate from xscale cp15 register no to openocd register*/
3522  switch (reg_no) {
3523  case 0:
3524  reg_no = XSCALE_MAINID;
3525  break;
3526  case 1:
3527  reg_no = XSCALE_CTRL;
3528  break;
3529  case 2:
3530  reg_no = XSCALE_TTB;
3531  break;
3532  case 3:
3533  reg_no = XSCALE_DAC;
3534  break;
3535  case 5:
3536  reg_no = XSCALE_FSR;
3537  break;
3538  case 6:
3539  reg_no = XSCALE_FAR;
3540  break;
3541  case 13:
3542  reg_no = XSCALE_PID;
3543  break;
3544  case 15:
3545  reg_no = XSCALE_CPACCESS;
3546  break;
3547  default:
3548  command_print(CMD, "invalid register number");
3550  }
3551  reg = &xscale->reg_cache->reg_list[reg_no];
3552 
3553  }
3554  if (CMD_ARGC == 1) {
3555  uint32_t value;
3556 
3557  /* read cp15 control register */
3559  value = buf_get_u32(reg->value, 0, 32);
3560  command_print(CMD, "%s (/%i): 0x%" PRIx32, reg->name, (int)(reg->size),
3561  value);
3562  } else if (CMD_ARGC == 2) {
3563  uint32_t value;
3565 
3566  /* send CP write request (command 0x41) */
3567  xscale_send_u32(target, 0x41);
3568 
3569  /* send CP register number */
3570  xscale_send_u32(target, reg_no);
3571 
3572  /* send CP register value */
3574 
3575  /* execute cpwait to ensure outstanding operations complete */
3576  xscale_send_u32(target, 0x53);
3577  } else
3579 
3580  return ERROR_OK;
3581 }
3582 
3583 static const struct command_registration xscale_exec_command_handlers[] = {
3584  {
3585  .name = "cache_info",
3586  .handler = xscale_handle_cache_info_command,
3587  .mode = COMMAND_EXEC,
3588  .help = "display information about CPU caches",
3589  .usage = "",
3590  },
3591  {
3592  .name = "mmu",
3593  .handler = xscale_handle_mmu_command,
3594  .mode = COMMAND_EXEC,
3595  .help = "enable or disable the MMU",
3596  .usage = "['enable'|'disable']",
3597  },
3598  {
3599  .name = "icache",
3600  .handler = xscale_handle_idcache_command,
3601  .mode = COMMAND_EXEC,
3602  .help = "display ICache state, optionally enabling or "
3603  "disabling it",
3604  .usage = "['enable'|'disable']",
3605  },
3606  {
3607  .name = "dcache",
3608  .handler = xscale_handle_idcache_command,
3609  .mode = COMMAND_EXEC,
3610  .help = "display DCache state, optionally enabling or "
3611  "disabling it",
3612  .usage = "['enable'|'disable']",
3613  },
3614  {
3615  .name = "vector_catch",
3616  .handler = xscale_handle_vector_catch_command,
3617  .mode = COMMAND_EXEC,
3618  .help = "set or display mask of vectors "
3619  "that should trigger debug entry",
3620  .usage = "['all'|'none'|'fiq'|'irq'|'dabt'|'pabt'|'swi'|'undef'|'reset']",
3621  },
3622  {
3623  .name = "vector_table",
3624  .handler = xscale_handle_vector_table_command,
3625  .mode = COMMAND_EXEC,
3626  .help = "set vector table entry in mini-ICache, "
3627  "or display current tables",
3628  .usage = "[('high'|'low') index code]",
3629  },
3630  {
3631  .name = "trace_buffer",
3632  .handler = xscale_handle_trace_buffer_command,
3633  .mode = COMMAND_EXEC,
3634  .help = "display trace buffer status, enable or disable "
3635  "tracing, and optionally reconfigure trace mode",
3636  .usage = "['enable'|'disable' ['fill' [number]|'wrap']]",
3637  },
3638  {
3639  .name = "dump_trace",
3640  .handler = xscale_handle_dump_trace_command,
3641  .mode = COMMAND_EXEC,
3642  .help = "dump content of trace buffer to file",
3643  .usage = "filename",
3644  },
3645  {
3646  .name = "analyze_trace",
3647  .handler = xscale_handle_analyze_trace_buffer_command,
3648  .mode = COMMAND_EXEC,
3649  .help = "analyze content of trace buffer",
3650  .usage = "",
3651  },
3652  {
3653  .name = "trace_image",
3654  .handler = xscale_handle_trace_image_command,
3655  .mode = COMMAND_EXEC,
3656  .help = "load image from file to address (default 0)",
3657  .usage = "filename [offset [filetype]]",
3658  },
3659  {
3660  .name = "cp15",
3661  .handler = xscale_handle_cp15,
3662  .mode = COMMAND_EXEC,
3663  .help = "Read or write coprocessor 15 register.",
3664  .usage = "register [value]",
3665  },
3667 };
3668 static const struct command_registration xscale_any_command_handlers[] = {
3669  {
3670  .name = "debug_handler",
3671  .handler = xscale_handle_debug_handler_command,
3672  .mode = COMMAND_ANY,
3673  .help = "Change address used for debug handler.",
3674  .usage = "<target> <address>",
3675  },
3676  {
3677  .name = "cache_clean_address",
3678  .handler = xscale_handle_cache_clean_address_command,
3679  .mode = COMMAND_ANY,
3680  .help = "Change address used for cleaning data cache.",
3681  .usage = "address",
3682  },
3683  {
3685  },
3687 };
3688 static const struct command_registration xscale_command_handlers[] = {
3689  {
3691  },
3692  {
3693  .name = "xscale",
3694  .mode = COMMAND_ANY,
3695  .help = "xscale command group",
3696  .usage = "",
3697  .chain = xscale_any_command_handlers,
3698  },
3700 };
3701 
3702 struct target_type xscale_target = {
3703  .name = "xscale",
3704 
3705  .poll = xscale_poll,
3706  .arch_state = xscale_arch_state,
3707 
3708  .halt = xscale_halt,
3709  .resume = xscale_resume,
3710  .step = xscale_step,
3711 
3712  .assert_reset = xscale_assert_reset,
3713  .deassert_reset = xscale_deassert_reset,
3714 
3715  /* REVISIT on some cores, allow exporting iwmmxt registers ... */
3716  .get_gdb_arch = arm_get_gdb_arch,
3717  .get_gdb_reg_list = arm_get_gdb_reg_list,
3718 
3719  .read_memory = xscale_read_memory,
3720  .read_phys_memory = xscale_read_phys_memory,
3721  .write_memory = xscale_write_memory,
3722  .write_phys_memory = xscale_write_phys_memory,
3723 
3724  .checksum_memory = arm_checksum_memory,
3725  .blank_check_memory = arm_blank_check_memory,
3726 
3727  .run_algorithm = armv4_5_run_algorithm,
3728 
3729  .add_breakpoint = xscale_add_breakpoint,
3730  .remove_breakpoint = xscale_remove_breakpoint,
3731  .add_watchpoint = xscale_add_watchpoint,
3732  .remove_watchpoint = xscale_remove_watchpoint,
3733 
3734  .commands = xscale_command_handlers,
3735  .target_create = xscale_target_create,
3736  .init_target = xscale_init_target,
3737  .deinit_target = xscale_deinit_target,
3738 
3739  .virt2phys = xscale_virt2phys,
3740  .mmu = xscale_mmu
3741 };
int arm_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Runs ARM code in the target to check whether a memory block holds all ones.
Definition: armv4_5.c:1686
struct reg * arm_reg_current(struct arm *arm, unsigned int regnum)
Returns handle to the register currently mapped to a given number.
Definition: armv4_5.c:516
int arm_arch_state(struct target *target)
Definition: armv4_5.c:796
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:166
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:1613
struct reg_cache * arm_build_reg_cache(struct target *target, struct arm *arm)
Definition: armv4_5.c:660
const char * arm_get_gdb_arch(const struct target *target)
Definition: armv4_5.c:1281
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:1286
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:775
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:261
@ ARM_STATE_THUMB
Definition: arm.h:152
@ ARM_STATE_ARM
Definition: arm.h:151
const struct command_registration arm_command_handlers[]
Definition: armv4_5.c:1261
int arm_init_arch_info(struct target *target, struct arm *arm)
Definition: armv4_5.c:1812
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:452
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:1587
@ 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:489
@ 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:83
#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:66
@ 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:375
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
Definition: command.h:166
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:400
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
Definition: command.h:531
#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:440
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:251
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:402
@ 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:1211
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:1079
int image_open(struct image *image, const char *url, const char *type_string)
Definition: image.c:957
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:445
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:771
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:598
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1050
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:523
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:457
void jtag_add_sleep(uint32_t us)
Definition: jtag/core.c:883
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:930
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:380
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
int debug_level
Definition: log.c:47
void alive_sleep(uint64_t ms)
Definition: log.c:468
void keep_alive(void)
Definition: log.c:427
#define LOG_USER(expr ...)
Definition: log.h:136
#define LOG_WARNING(expr ...)
Definition: log.h:130
#define ERROR_FAIL
Definition: log.h:174
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:162
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
#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::@70 info
struct arm_b_bl_bx_blx_instr b_bl_bx_blx
Represents a generic ARM core, with standard application registers.
Definition: arm.h:175
int(* full_context)(struct target *target)
Retrieve all core registers, for display.
Definition: arm.h:221
void * arch_info
Definition: arm.h:251
enum arm_core_type core_type
Indicates what registers are in the ARM state core register set.
Definition: arm.h:193
enum arm_mode core_mode
Record the current core mode: SVC, USR, or some other mode.
Definition: arm.h:196
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
Definition: arm.h:184
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:181
int(* write_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode, uint8_t *value)
Definition: arm.h:226
int(* read_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode)
Retrieve a single core register.
Definition: arm.h:224
struct reg_cache * core_cache
Definition: arm.h:178
struct reg * spsr
Handle to the SPSR; valid only in core modes with an SPSR.
Definition: arm.h:187
unsigned int common_magic
Definition: arm.h:176
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:234
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:247
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:157
enum target_state state
Definition: target.h:160
enum target_endianness endianness
Definition: target.h:158
struct reg_cache * reg_cache
Definition: target.h:161
struct breakpoint * breakpoints
Definition: target.h:162
struct watchpoint * watchpoints
Definition: target.h:163
void * arch_info
Definition: target.h:167
bool reset_halt
Definition: target.h:147
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:1774
struct target * get_target(const char *id)
Definition: target.c:442
void target_free_all_working_areas(struct target *target)
Definition: target.c:2160
int target_halt(struct target *target)
Definition: target.c:516
void target_buffer_set_u16(struct target *target, uint8_t *buffer, uint16_t value)
Definition: target.c:379
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
Definition: target.c:361
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2671
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:1275
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2650
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
Definition: target.c:269
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2559
uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer)
Definition: target.c:343
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:1247
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:467
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
Definition: target.c:325
@ 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:786
static bool target_was_examined(const struct target *target)
Definition: target.h:432
#define ERROR_TARGET_UNALIGNED_ACCESS
Definition: target.h:788
#define ERROR_TARGET_INVALID
Definition: target.h:783
@ TARGET_EVENT_DEBUG_RESUMED
Definition: target.h:275
@ TARGET_EVENT_HALTED
Definition: target.h:255
@ TARGET_EVENT_RESUMED
Definition: target.h:256
@ TARGET_EVENT_DEBUG_HALTED
Definition: target.h:274
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
Definition: target.h:236
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:793
@ TARGET_LITTLE_ENDIAN
Definition: target.h:85
#define ERROR_TARGET_TIMEOUT
Definition: target.h:785
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:790
#define ERROR_TARGET_DATA_ABORT
Definition: target.h:789
#define ERROR_TARGET_FAILURE
Definition: target.h:787
int timeval_compare(const struct timeval *x, const struct timeval *y)
Definition: time_support.c:55
int timeval_add_time(struct timeval *result, long sec, long usec)
Definition: time_support.c:41
#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:342
#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:335
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:3012
static int xscale_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical)
Definition: xscale.c:3106
static int xscale_init_arch_info(struct target *target, struct xscale_common *xscale, struct jtag_tap *tap)
Definition: xscale.c:2922
static int xscale_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: xscale.c:2135
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:2066
static int xscale_enable_mmu_caches(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: xscale.c:2034
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:2641
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:2914
static int xscale_analyze_trace(struct target *target, struct command_invocation *cmd)
Definition: xscale.c:2652
static int xscale_set_watchpoint(struct target *, struct watchpoint *)
Definition: xscale.c:2223
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:2474
COMMAND_HANDLER(xscale_handle_debug_handler_command)
Definition: xscale.c:3028
static int xscale_mmu(struct target *target, bool *enabled)
Definition: xscale.c:3126
static int xscale_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: xscale.c:2205
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:2420
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:3668
char name[15]
Definition: xscale.c:3214
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:2384
static const struct reg_arch_type xscale_reg_type
Definition: xscale.c:2851
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:3688
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:2455
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:2892
static int xscale_receive(struct target *target, uint32_t *buffer, int num_words)
Definition: xscale.c:229
static int xscale_unset_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: xscale.c:2328
unsigned int mask
Definition: xscale.c:3215
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:2856
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:2907
static const struct command_registration xscale_exec_command_handlers[]
Definition: xscale.c:3583
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:2569
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:2286
static int xscale_send(struct target *target, const uint8_t *buffer, int count, int size)
Definition: xscale.c:496
static const struct @126 vec_ids[]
static int xscale_unset_breakpoint(struct target *, struct breakpoint *)
Definition: xscale.c:2156
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:2628
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:2364
static int xscale_halt(struct target *target)
Definition: xscale.c:1005
struct target_type xscale_target
Definition: xscale.c:3702
#define XSCALE_SELDCSR
Definition: xscale.h:26
#define DCSR_TRAP_MASK
Definition: xscale.h:174
#define DCSR_TD
Definition: xscale.h:171
@ 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
@ 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
#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