OpenOCD
arc.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2013-2015,2019-2020 Synopsys, Inc. *
5  * Frank Dols <frank.dols@synopsys.com> *
6  * Mischa Jonker <mischa.jonker@synopsys.com> *
7  * Anton Kolesov <anton.kolesov@synopsys.com> *
8  * Evgeniy Didin <didin@synopsys.com> *
9  ***************************************************************************/
10 
11 
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include "arc.h"
17 
18 
19 
20 /*
21  * ARC architecture specific details.
22  *
23  * ARC has two types of registers:
24  * 1) core registers(e.g. r0,r1..) [is_core = true]
25  * 2) Auxiliary registers [is_core = false]..
26  *
27  * Auxiliary registers at the same time can be divided into
28  * read-only BCR(build configuration regs, e.g. isa_config, mpu_build) and
29  * R/RW non-BCR ("control" register, e.g. pc, status32_t, debug).
30  *
31  * The way of accessing to Core and AUX registers differs on Jtag level.
32  * BCR/non-BCR describes if the register is immutable and that reading
33  * unexisting register is safe RAZ, rather then an error.
34  * Note, core registers cannot be BCR.
35  *
36  * In arc/cpu/ tcl files all registers are defined as core, non-BCR aux
37  * and BCR aux, in "add-reg" command they are passed to three lists
38  * respectively: core_reg_descriptions, aux_reg_descriptions,
39  * bcr_reg_descriptions.
40  *
41  * Due to the specifics of accessing to BCR/non-BCR registers there are two
42  * register caches:
43  * 1) core_and_aux_cache - includes registers described in
44  * core_reg_descriptions and aux_reg_descriptions lists.
45  * Used during save/restore context step.
46  * 2) bcr_cache - includes registers described bcr_reg_descriptions.
47  * Currently used internally during configure step.
48  */
49 
50 
51 static int arc_remove_watchpoint(struct target *target,
52  struct watchpoint *watchpoint);
53 static int arc_enable_watchpoints(struct target *target);
54 static int arc_enable_breakpoints(struct target *target);
55 static int arc_unset_breakpoint(struct target *target,
56  struct breakpoint *breakpoint);
57 static int arc_set_breakpoint(struct target *target,
58  struct breakpoint *breakpoint);
59 static int arc_single_step_core(struct target *target);
60 
63 {
64  LOG_TARGET_DEBUG(target, "Adding %s reg_data_type", data_type->data_type.id);
65  struct arc_common *arc = target_to_arc(target);
66  assert(arc);
67 
68  list_add_tail(&data_type->list, &arc->reg_data_types);
69 }
70 
77 struct reg *arc_reg_get_by_name(struct reg_cache *first,
78  const char *name, bool search_all)
79 {
80  unsigned int i;
81  struct reg_cache *cache = first;
82 
83  while (cache) {
84  for (i = 0; i < cache->num_regs; i++) {
85  if (!strcmp(cache->reg_list[i].name, name))
86  return &(cache->reg_list[i]);
87  }
88 
89  if (search_all)
90  cache = cache->next;
91  else
92  break;
93  }
94 
95  return NULL;
96 }
97 
104 {
105  struct arc_common *arc = target_to_arc(target);
106 
107  LOG_TARGET_DEBUG(target, "Resetting internal variables of caches states");
108 
109  /* Reset caches states. */
110  arc->dcache_flushed = false;
111  arc->l2cache_flushed = false;
112  arc->icache_invalidated = false;
113  arc->dcache_invalidated = false;
114  arc->l2cache_invalidated = false;
115 
116  return ERROR_OK;
117 }
118 
119 /* Initialize arc_common structure, which passes to openocd target instance */
120 static int arc_init_arch_info(struct target *target, struct arc_common *arc,
121  struct jtag_tap *tap)
122 {
124  target->arch_info = arc;
125 
126  arc->jtag_info.tap = tap;
127 
128  /* The only allowed ir_length is 4 for ARC jtag. */
129  if (tap->ir_length != 4) {
130  LOG_TARGET_ERROR(target, "ARC jtag instruction length should be equal to 4");
131  return ERROR_FAIL;
132  }
133 
134  /* On most ARC targets there is a dcache, so we enable its flushing
135  * by default. If there no dcache, there will be no error, just a slight
136  * performance penalty from unnecessary JTAG operations. */
137  arc->has_dcache = true;
138  arc->has_icache = true;
139  /* L2$ is not available in a target by default. */
140  arc->has_l2cache = false;
142 
143  /* Add standard GDB data types */
145  struct arc_reg_data_type *std_types = calloc(ARRAY_SIZE(standard_gdb_types),
146  sizeof(*std_types));
147 
148  if (!std_types) {
149  LOG_TARGET_ERROR(target, "Unable to allocate memory");
150  return ERROR_FAIL;
151  }
152 
153  for (unsigned int i = 0; i < ARRAY_SIZE(standard_gdb_types); i++) {
154  std_types[i].data_type.type = standard_gdb_types[i].type;
155  std_types[i].data_type.id = standard_gdb_types[i].id;
156  arc_reg_data_type_add(target, &(std_types[i]));
157  }
158 
159  /* Fields related to target descriptions */
163  arc->num_regs = 0;
164  arc->num_core_regs = 0;
165  arc->num_aux_regs = 0;
166  arc->num_bcr_regs = 0;
167  arc->last_general_reg = ULONG_MAX;
168  arc->pc_index_in_cache = ULONG_MAX;
169  arc->debug_index_in_cache = ULONG_MAX;
170 
171  return ERROR_OK;
172 }
173 
174 int arc_reg_add(struct target *target, struct arc_reg_desc *arc_reg,
175  const char * const type_name, const size_t type_name_len)
176 {
177  assert(target);
178  assert(arc_reg);
179 
180  struct arc_common *arc = target_to_arc(target);
181  assert(arc);
182 
183  /* Find register type */
184  {
185  struct arc_reg_data_type *type;
187  if (!strncmp(type->data_type.id, type_name, type_name_len)) {
188  arc_reg->data_type = &(type->data_type);
189  break;
190  }
191 
192  if (!arc_reg->data_type)
194  }
195 
196  if (arc_reg->is_core) {
197  list_add_tail(&arc_reg->list, &arc->core_reg_descriptions);
198  arc->num_core_regs += 1;
199  } else if (arc_reg->is_bcr) {
200  list_add_tail(&arc_reg->list, &arc->bcr_reg_descriptions);
201  arc->num_bcr_regs += 1;
202  } else {
203  list_add_tail(&arc_reg->list, &arc->aux_reg_descriptions);
204  arc->num_aux_regs += 1;
205  }
206  arc->num_regs += 1;
207 
209  "added register {name=%s, num=0x%" PRIx32 ", type=%s%s%s%s}",
210  arc_reg->name, arc_reg->arch_num, arc_reg->data_type->id,
211  arc_reg->is_core ? ", core" : "", arc_reg->is_bcr ? ", bcr" : "",
212  arc_reg->is_general ? ", general" : ""
213  );
214 
215  return ERROR_OK;
216 }
217 
218 /* Reading core or aux register */
219 static int arc_get_register(struct reg *reg)
220 {
221  assert(reg);
222 
223  struct arc_reg_desc *desc = reg->arch_info;
224  struct target *target = desc->target;
225  struct arc_common *arc = target_to_arc(target);
226 
227  uint32_t value;
228 
229  if (reg->valid) {
230  LOG_TARGET_DEBUG(target, "Get register (cached) gdb_num=%" PRIu32 ", name=%s, value=0x%" PRIx32,
232  return ERROR_OK;
233  }
234 
235  if (desc->is_core) {
236  /* Accessing to R61/R62 registers causes Jtag hang */
237  if (desc->arch_num == ARC_R61 || desc->arch_num == ARC_R62) {
238  LOG_TARGET_ERROR(target, "It is forbidden to read core registers 61 and 62");
239  return ERROR_FAIL;
240  }
242  &value));
243  } else {
245  &value));
246  }
247 
249 
250  /* If target is unhalted all register reads should be uncached. */
251  if (target->state == TARGET_HALTED)
252  reg->valid = true;
253  else
254  reg->valid = false;
255 
256  reg->dirty = false;
257 
258  LOG_TARGET_DEBUG(target, "Get register gdb_num=%" PRIu32 ", name=%s, value=0x%" PRIx32,
259  reg->number, desc->name, value);
260 
261 
262  return ERROR_OK;
263 }
264 
265 /* Writing core or aux register */
266 static int arc_set_register(struct reg *reg, uint8_t *buf)
267 {
268  struct arc_reg_desc *desc = reg->arch_info;
269  struct target *target = desc->target;
270  uint32_t value = target_buffer_get_u32(target, buf);
271  /* Unlike "get" function "set" is supported only if target
272  * is in halt mode. Async writes are not supported yet. */
273  if (target->state != TARGET_HALTED)
275 
276  /* Accessing to R61/R62 registers causes Jtag hang */
277  if (desc->is_core && (desc->arch_num == ARC_R61 ||
278  desc->arch_num == ARC_R62)) {
279  LOG_TARGET_ERROR(target, "It is forbidden to write core registers 61 and 62");
280  return ERROR_FAIL;
281  }
283 
284  LOG_TARGET_DEBUG(target, "Set register gdb_num=%" PRIu32 ", name=%s, value=0x%08" PRIx32,
285  reg->number, desc->name, value);
286 
287  reg->valid = true;
288  reg->dirty = true;
289 
290  return ERROR_OK;
291 }
292 
293 static const struct reg_arch_type arc_reg_type = {
295  .set = arc_set_register,
296 };
297 
298 /* GDB register groups. For now we support only general and "empty" */
299 static const char * const reg_group_general = "general";
300 static const char * const reg_group_other = "";
301 
302 /* Common code to initialize `struct reg` for different registers: core, aux, bcr. */
303 static int arc_init_reg(struct target *target, struct reg *reg,
304  struct arc_reg_desc *reg_desc, unsigned long number)
305 {
306  assert(target);
307  assert(reg);
308  assert(reg_desc);
309 
310  struct arc_common *arc = target_to_arc(target);
311 
312  /* Initialize struct reg */
313  reg->name = reg_desc->name;
314  reg->size = 32; /* All register in ARC are 32-bit */
315  reg->value = reg_desc->reg_value;
316  reg->type = &arc_reg_type;
317  reg->arch_info = reg_desc;
318  reg->caller_save = true; /* @todo should be configurable. */
319  reg->reg_data_type = reg_desc->data_type;
320  reg->feature = &reg_desc->feature;
321 
322  reg->feature->name = reg_desc->gdb_xml_feature;
323 
324  /* reg->number is used by OpenOCD as value for @regnum. Thus when setting
325  * value of a register GDB will use it as a number of register in
326  * P-packet. OpenOCD gdbserver will then use number of register in
327  * P-packet as an array index in the reg_list returned by
328  * arc_regs_get_gdb_reg_list. So to ensure that registers are assigned
329  * correctly it would be required to either sort registers in
330  * arc_regs_get_gdb_reg_list or to assign numbers sequentially here and
331  * according to how registers will be sorted in
332  * arc_regs_get_gdb_reg_list. Second options is much more simpler. */
333  reg->number = number;
334 
335  if (reg_desc->is_general) {
336  arc->last_general_reg = reg->number;
338  } else {
340  }
341 
342  return ERROR_OK;
343 }
344 
345 /* Building aux/core reg_cache */
346 static int arc_build_reg_cache(struct target *target)
347 {
348  unsigned long i = 0;
349  struct arc_reg_desc *reg_desc;
350  /* get pointers to arch-specific information */
351  struct arc_common *arc = target_to_arc(target);
352  const unsigned long num_regs = arc->num_core_regs + arc->num_aux_regs;
353  struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache);
354  struct reg_cache *cache = calloc(1, sizeof(*cache));
355  struct reg *reg_list = calloc(num_regs, sizeof(*reg_list));
356 
357  if (!cache || !reg_list) {
358  LOG_TARGET_ERROR(target, "Not enough memory");
359  goto fail;
360  }
361 
362  /* Build the process context cache */
363  cache->name = "arc registers";
364  cache->next = NULL;
365  cache->reg_list = reg_list;
366  cache->num_regs = num_regs;
367  arc->core_and_aux_cache = cache;
368  (*cache_p) = cache;
369 
370  if (list_empty(&arc->core_reg_descriptions)) {
371  LOG_TARGET_ERROR(target, "No core registers were defined");
372  goto fail;
373  }
374 
375  list_for_each_entry(reg_desc, &arc->core_reg_descriptions, list) {
376  CHECK_RETVAL(arc_init_reg(target, &reg_list[i], reg_desc, i));
377 
378  LOG_TARGET_DEBUG(target, "reg n=%3li name=%3s group=%s feature=%s", i,
379  reg_list[i].name, reg_list[i].group,
380  reg_list[i].feature->name);
381 
382  i += 1;
383  }
384 
385  if (list_empty(&arc->aux_reg_descriptions)) {
386  LOG_TARGET_ERROR(target, "No aux registers were defined");
387  goto fail;
388  }
389 
390  list_for_each_entry(reg_desc, &arc->aux_reg_descriptions, list) {
391  CHECK_RETVAL(arc_init_reg(target, &reg_list[i], reg_desc, i));
392 
393  LOG_TARGET_DEBUG(target, "reg n=%3li name=%3s group=%s feature=%s", i,
394  reg_list[i].name, reg_list[i].group,
395  reg_list[i].feature->name);
396 
397  /* PC and DEBUG are essential so we search for them. */
398  if (!strcmp("pc", reg_desc->name)) {
399  if (arc->pc_index_in_cache != ULONG_MAX) {
400  LOG_TARGET_ERROR(target, "Double definition of PC in configuration");
401  goto fail;
402  }
403  arc->pc_index_in_cache = i;
404  } else if (!strcmp("debug", reg_desc->name)) {
405  if (arc->debug_index_in_cache != ULONG_MAX) {
406  LOG_TARGET_ERROR(target, "Double definition of DEBUG in configuration");
407  goto fail;
408  }
409  arc->debug_index_in_cache = i;
410  }
411  i += 1;
412  }
413 
414  if (arc->pc_index_in_cache == ULONG_MAX
415  || arc->debug_index_in_cache == ULONG_MAX) {
416  LOG_TARGET_ERROR(target, "`pc' and `debug' registers must be present in target description");
417  goto fail;
418  }
419 
420  assert(i == (arc->num_core_regs + arc->num_aux_regs));
421 
422  arc->core_aux_cache_built = true;
423 
424  return ERROR_OK;
425 
426 fail:
427  free(cache);
428  free(reg_list);
429 
430  return ERROR_FAIL;
431 }
432 
433 /* Build bcr reg_cache.
434  * This function must be called only after arc_build_reg_cache */
436 {
437  /* get pointers to arch-specific information */
438  struct arc_common *arc = target_to_arc(target);
439  const unsigned long num_regs = arc->num_bcr_regs;
440  struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache);
441  struct reg_cache *cache = malloc(sizeof(*cache));
442  struct reg *reg_list = calloc(num_regs, sizeof(*reg_list));
443 
444  struct arc_reg_desc *reg_desc;
445  unsigned long i = 0;
446  unsigned long gdb_regnum = arc->core_and_aux_cache->num_regs;
447 
448  if (!cache || !reg_list) {
449  LOG_TARGET_ERROR(target, "Unable to allocate memory");
450  goto fail;
451  }
452 
453  /* Build the process context cache */
454  cache->name = "arc.bcr";
455  cache->next = NULL;
456  cache->reg_list = reg_list;
457  cache->num_regs = num_regs;
458  arc->bcr_cache = cache;
459  (*cache_p) = cache;
460 
461  if (list_empty(&arc->bcr_reg_descriptions)) {
462  LOG_TARGET_ERROR(target, "No BCR registers are defined");
463  goto fail;
464  }
465 
466  list_for_each_entry(reg_desc, &arc->bcr_reg_descriptions, list) {
467  CHECK_RETVAL(arc_init_reg(target, &reg_list[i], reg_desc, gdb_regnum));
468  /* BCRs always semantically, they are just read-as-zero, if there is
469  * not real register. */
470  reg_list[i].exist = true;
471 
472  LOG_TARGET_DEBUG(target, "reg n=%3li name=%3s group=%s feature=%s", i,
473  reg_list[i].name, reg_list[i].group,
474  reg_list[i].feature->name);
475  i += 1;
476  gdb_regnum += 1;
477  }
478 
479  assert(i == arc->num_bcr_regs);
480 
481  arc->bcr_cache_built = true;
482 
483 
484  return ERROR_OK;
485 fail:
486  free(cache);
487  free(reg_list);
488 
489  return ERROR_FAIL;
490 }
491 
492 
493 static int arc_get_gdb_reg_list(struct target *target, struct reg **reg_list[],
494  int *reg_list_size, enum target_register_class reg_class)
495 {
496  assert(target->reg_cache);
497  struct arc_common *arc = target_to_arc(target);
498 
499  /* get pointers to arch-specific information storage */
500  *reg_list_size = arc->num_regs;
501  *reg_list = calloc(*reg_list_size, sizeof(struct reg *));
502 
503  if (!*reg_list) {
504  LOG_TARGET_ERROR(target, "Unable to allocate memory");
505  return ERROR_FAIL;
506  }
507 
508  /* OpenOCD gdb_server API seems to be inconsistent here: when it generates
509  * XML tdesc it filters out !exist registers, however when creating a
510  * g-packet it doesn't do so. REG_CLASS_ALL is used in first case, and
511  * REG_CLASS_GENERAL used in the latter one. Due to this we had to filter
512  * out !exist register for "general", but not for "all". Attempts to filter out
513  * !exist for "all" as well will cause a failed check in OpenOCD GDB
514  * server. */
515  if (reg_class == REG_CLASS_ALL) {
516  unsigned long i = 0;
517  struct reg_cache *reg_cache = target->reg_cache;
518  while (reg_cache) {
519  for (unsigned int j = 0; j < reg_cache->num_regs; j++, i++)
520  (*reg_list)[i] = &reg_cache->reg_list[j];
522  }
523  assert(i == arc->num_regs);
524  LOG_TARGET_DEBUG(target, "REG_CLASS_ALL: number of regs=%i", *reg_list_size);
525  } else {
526  unsigned long i = 0;
527  unsigned long gdb_reg_number = 0;
528  struct reg_cache *reg_cache = target->reg_cache;
529  while (reg_cache) {
530  for (unsigned int j = 0;
531  j < reg_cache->num_regs && gdb_reg_number <= arc->last_general_reg;
532  j++) {
533  if (reg_cache->reg_list[j].exist) {
534  (*reg_list)[i] = &reg_cache->reg_list[j];
535  i++;
536  }
537  gdb_reg_number += 1;
538  }
540  }
541  *reg_list_size = i;
542  LOG_TARGET_DEBUG(target, "REG_CLASS_GENERAL: number of regs=%i", *reg_list_size);
543  }
544 
545  return ERROR_OK;
546 }
547 
548 /* Reading field of struct_type register */
549 int arc_reg_get_field(struct target *target, const char *reg_name,
550  const char *field_name, uint32_t *value_ptr)
551 {
552  struct reg_data_type_struct_field *field;
553 
554  LOG_TARGET_DEBUG(target, "getting register field (reg_name=%s, field_name=%s)", reg_name, field_name);
555 
556  /* Get register */
557  struct reg *reg = arc_reg_get_by_name(target->reg_cache, reg_name, true);
558 
559  if (!reg) {
560  LOG_TARGET_ERROR(target, "Requested register `%s' doesn't exist", reg_name);
562  }
563 
567 
568  /* Get field in a register */
569  struct reg_data_type_struct *reg_struct =
571  for (field = reg_struct->fields;
572  field;
573  field = field->next) {
574  if (!strcmp(field->name, field_name))
575  break;
576  }
577 
578  if (!field)
580 
581  if (!field->use_bitfields)
583 
584  if (!reg->valid)
586 
587  /* First do endianness-safe read of register value
588  * then convert it to binary buffer for further
589  * field extraction */
590 
591  *value_ptr = buf_get_u32(reg->value, field->bitfield->start,
592  field->bitfield->end - field->bitfield->start + 1);
593 
594  return ERROR_OK;
595 }
596 
597 static int arc_get_register_value(struct target *target, const char *reg_name,
598  uint32_t *value_ptr)
599 {
600  LOG_TARGET_DEBUG(target, "reg_name=%s", reg_name);
601 
602  struct reg *reg = arc_reg_get_by_name(target->reg_cache, reg_name, true);
603 
604  if (!reg)
606 
607  if (!reg->valid)
609 
610  *value_ptr = target_buffer_get_u32(target, reg->value);
611 
612  return ERROR_OK;
613 }
614 
615 static int arc_set_register_value(struct target *target, const char *reg_name,
616  uint32_t value)
617 {
618  LOG_TARGET_DEBUG(target, "reg_name=%s value=0x%08" PRIx32, reg_name, value);
619 
620  if (!(target && reg_name)) {
621  LOG_TARGET_ERROR(target, "Arguments cannot be NULL");
622  return ERROR_FAIL;
623  }
624 
625  struct reg *reg = arc_reg_get_by_name(target->reg_cache, reg_name, true);
626 
627  if (!reg)
629 
630  uint8_t value_buf[4];
631  buf_set_u32(value_buf, 0, 32, value);
632  CHECK_RETVAL(reg->type->set(reg, value_buf));
633 
634  return ERROR_OK;
635 }
636 
637 /* Configure DCCM's */
638 static int arc_configure_dccm(struct target *target)
639 {
640  struct arc_common *arc = target_to_arc(target);
641 
642  uint32_t dccm_build_version, dccm_build_size0, dccm_build_size1;
643  CHECK_RETVAL(arc_reg_get_field(target, "dccm_build", "version",
644  &dccm_build_version));
645  CHECK_RETVAL(arc_reg_get_field(target, "dccm_build", "size0",
646  &dccm_build_size0));
647  CHECK_RETVAL(arc_reg_get_field(target, "dccm_build", "size1",
648  &dccm_build_size1));
649  /* There is no yet support of configurable number of cycles,
650  * So there is no difference between v3 and v4 */
651  if ((dccm_build_version == 3 || dccm_build_version == 4) && dccm_build_size0 > 0) {
652  CHECK_RETVAL(arc_get_register_value(target, "aux_dccm", &(arc->dccm_start)));
653  uint32_t dccm_size = 0x100;
654  dccm_size <<= dccm_build_size0;
655  if (dccm_build_size0 == 0xF)
656  dccm_size <<= dccm_build_size1;
657  arc->dccm_end = arc->dccm_start + dccm_size;
658  LOG_TARGET_DEBUG(target, "DCCM detected start=0x%" PRIx32 " end=0x%" PRIx32,
659  arc->dccm_start, arc->dccm_end);
660 
661  }
662  return ERROR_OK;
663 }
664 
665 
666 /* Configure ICCM's */
667 
668 static int arc_configure_iccm(struct target *target)
669 {
670  struct arc_common *arc = target_to_arc(target);
671 
672  /* ICCM0 */
673  uint32_t iccm_build_version, iccm_build_size00, iccm_build_size01;
674  uint32_t aux_iccm = 0;
675  CHECK_RETVAL(arc_reg_get_field(target, "iccm_build", "version",
676  &iccm_build_version));
677  CHECK_RETVAL(arc_reg_get_field(target, "iccm_build", "iccm0_size0",
678  &iccm_build_size00));
679  CHECK_RETVAL(arc_reg_get_field(target, "iccm_build", "iccm0_size1",
680  &iccm_build_size01));
681  if (iccm_build_version == 4 && iccm_build_size00 > 0) {
682  CHECK_RETVAL(arc_get_register_value(target, "aux_iccm", &aux_iccm));
683  uint32_t iccm0_size = 0x100;
684  iccm0_size <<= iccm_build_size00;
685  if (iccm_build_size00 == 0xF)
686  iccm0_size <<= iccm_build_size01;
687  /* iccm0 start is located in highest 4 bits of aux_iccm */
688  arc->iccm0_start = aux_iccm & 0xF0000000;
689  arc->iccm0_end = arc->iccm0_start + iccm0_size;
690  LOG_TARGET_DEBUG(target, "ICCM0 detected start=0x%" PRIx32 " end=0x%" PRIx32,
691  arc->iccm0_start, arc->iccm0_end);
692  }
693 
694  /* ICCM1 */
695  uint32_t iccm_build_size10, iccm_build_size11;
696  CHECK_RETVAL(arc_reg_get_field(target, "iccm_build", "iccm1_size0",
697  &iccm_build_size10));
698  CHECK_RETVAL(arc_reg_get_field(target, "iccm_build", "iccm1_size1",
699  &iccm_build_size11));
700  if (iccm_build_version == 4 && iccm_build_size10 > 0) {
701  /* Use value read for ICCM0 */
702  if (!aux_iccm)
703  CHECK_RETVAL(arc_get_register_value(target, "aux_iccm", &aux_iccm));
704  uint32_t iccm1_size = 0x100;
705  iccm1_size <<= iccm_build_size10;
706  if (iccm_build_size10 == 0xF)
707  iccm1_size <<= iccm_build_size11;
708  arc->iccm1_start = aux_iccm & 0x0F000000;
709  arc->iccm1_end = arc->iccm1_start + iccm1_size;
710  LOG_TARGET_DEBUG(target, "ICCM1 detected start=0x%" PRIx32 " end=0x%" PRIx32,
711  arc->iccm1_start, arc->iccm1_end);
712  }
713  return ERROR_OK;
714 }
715 
716 /* Configure some core features, depending on BCRs. */
717 static int arc_configure(struct target *target)
718 {
719  LOG_TARGET_DEBUG(target, "Configuring ARC ICCM and DCCM");
720 
721  /* Configuring DCCM if DCCM_BUILD and AUX_DCCM are known registers. */
722  if (arc_reg_get_by_name(target->reg_cache, "dccm_build", true)
723  && arc_reg_get_by_name(target->reg_cache, "aux_dccm", true))
725 
726  /* Configuring ICCM if ICCM_BUILD and AUX_ICCM are known registers. */
727  if (arc_reg_get_by_name(target->reg_cache, "iccm_build", true)
728  && arc_reg_get_by_name(target->reg_cache, "aux_iccm", true))
730 
731  return ERROR_OK;
732 }
733 
734 /* arc_examine is function, which is used for all arc targets*/
735 static int arc_examine(struct target *target)
736 {
737  uint32_t status;
738  struct arc_common *arc = target_to_arc(target);
739 
741 
742  if (!target_was_examined(target)) {
744  if (status & ARC_JTAG_STAT_RU)
746  else
748 
749  /* Read BCRs and configure optional registers. */
751 
753  }
754 
755  return ERROR_OK;
756 }
757 
758 static int arc_exit_debug(struct target *target)
759 {
760  uint32_t value;
761  struct arc_common *arc = target_to_arc(target);
762 
763  /* Do read-modify-write sequence, or DEBUG.UB will be reset unintentionally. */
765  value |= SET_CORE_FORCE_HALT; /* set the HALT bit */
767  alive_sleep(1);
768 
771 
772  if (debug_level >= LOG_LVL_DEBUG) {
773  LOG_TARGET_DEBUG(target, "core stopped (halted) debug-reg: 0x%08" PRIx32, value);
775  LOG_TARGET_DEBUG(target, "core STATUS32: 0x%08" PRIx32, value);
776  }
777 
778  return ERROR_OK;
779 }
780 
781 static int arc_halt(struct target *target)
782 {
783  uint32_t value, irq_state;
784  struct arc_common *arc = target_to_arc(target);
785 
786  LOG_TARGET_DEBUG(target, "target->state: %s", target_state_name(target));
787 
788  if (target->state == TARGET_HALTED) {
789  LOG_TARGET_DEBUG(target, "target was already halted");
790  return ERROR_OK;
791  }
792 
793  if (target->state == TARGET_UNKNOWN)
794  LOG_TARGET_WARNING(target, "target was in unknown state when halt was requested");
795 
796  if (target->state == TARGET_RESET) {
798  LOG_TARGET_ERROR(target, "can't request a halt while in reset if nSRST pulls nTRST");
799  return ERROR_TARGET_FAILURE;
800  } else {
802  }
803  }
804 
805  /* Break (stop) processor.
806  * Do read-modify-write sequence, or DEBUG.UB will be reset unintentionally.
807  * We do not use here arc_get/set_core_reg functions here because they imply
808  * that the processor is already halted. */
810  value |= SET_CORE_FORCE_HALT; /* set the HALT bit */
812  alive_sleep(1);
813 
814  /* Save current IRQ state */
816 
818  arc->irq_state = 1;
819  else
820  arc->irq_state = 0;
821 
822  /* update state and notify gdb*/
825 
826  /* some more debug information */
827  if (debug_level >= LOG_LVL_DEBUG) {
828  LOG_TARGET_DEBUG(target, "core stopped (halted) DEGUB-REG: 0x%08" PRIx32, value);
829  CHECK_RETVAL(arc_get_register_value(target, "status32", &value));
830  LOG_TARGET_DEBUG(target, "core STATUS32: 0x%08" PRIx32, value);
831  }
832 
833  return ERROR_OK;
834 }
835 
842 static int arc_save_context(struct target *target)
843 {
844  int retval = ERROR_OK;
845  unsigned int i;
846  struct arc_common *arc = target_to_arc(target);
847  struct reg *reg_list = arc->core_and_aux_cache->reg_list;
848 
849  LOG_TARGET_DEBUG(target, "Saving aux and core registers values");
850  assert(reg_list);
851 
852  /* It is assumed that there is at least one AUX register in the list, for
853  * example PC. */
854  const uint32_t core_regs_size = arc->num_core_regs * sizeof(uint32_t);
855  /* last_general_reg is inclusive number. To get count of registers it is
856  * required to do +1. */
857  const uint32_t regs_to_scan =
858  MIN(arc->last_general_reg + 1, arc->num_regs);
859  const uint32_t aux_regs_size = arc->num_aux_regs * sizeof(uint32_t);
860  uint32_t *core_values = malloc(core_regs_size);
861  uint32_t *aux_values = malloc(aux_regs_size);
862  uint32_t *core_addrs = malloc(core_regs_size);
863  uint32_t *aux_addrs = malloc(aux_regs_size);
864  unsigned int core_cnt = 0;
865  unsigned int aux_cnt = 0;
866 
867  if (!core_values || !core_addrs || !aux_values || !aux_addrs) {
868  LOG_TARGET_ERROR(target, "Unable to allocate memory");
869  retval = ERROR_FAIL;
870  goto exit;
871  }
872 
873  memset(core_values, 0xff, core_regs_size);
874  memset(core_addrs, 0xff, core_regs_size);
875  memset(aux_values, 0xff, aux_regs_size);
876  memset(aux_addrs, 0xff, aux_regs_size);
877 
878  for (i = 0; i < MIN(arc->num_core_regs, regs_to_scan); i++) {
879  struct reg *reg = reg_list + i;
880  struct arc_reg_desc *arc_reg = reg->arch_info;
881  if (!reg->valid && reg->exist)
882  core_addrs[core_cnt++] = arc_reg->arch_num;
883  }
884 
885  for (i = arc->num_core_regs; i < regs_to_scan; i++) {
886  struct reg *reg = reg_list + i;
887  struct arc_reg_desc *arc_reg = reg->arch_info;
888  if (!reg->valid && reg->exist)
889  aux_addrs[aux_cnt++] = arc_reg->arch_num;
890  }
891 
892  /* Read data from target. */
893  if (core_cnt > 0) {
894  retval = arc_jtag_read_core_reg(&arc->jtag_info, core_addrs, core_cnt, core_values);
895  if (retval != ERROR_OK) {
896  LOG_TARGET_ERROR(target, "Attempt to read core registers failed");
897  retval = ERROR_FAIL;
898  goto exit;
899  }
900  }
901  if (aux_cnt > 0) {
902  retval = arc_jtag_read_aux_reg(&arc->jtag_info, aux_addrs, aux_cnt, aux_values);
903  if (retval != ERROR_OK) {
904  LOG_TARGET_ERROR(target, "Attempt to read aux registers failed");
905  retval = ERROR_FAIL;
906  goto exit;
907  }
908  }
909 
910  /* Parse core regs */
911  core_cnt = 0;
912  for (i = 0; i < MIN(arc->num_core_regs, regs_to_scan); i++) {
913  struct reg *reg = reg_list + i;
914  struct arc_reg_desc *arc_reg = reg->arch_info;
915  if (!reg->valid && reg->exist) {
916  target_buffer_set_u32(target, reg->value, core_values[core_cnt]);
917  reg->valid = true;
918  reg->dirty = false;
919  LOG_TARGET_DEBUG(target, "Get core register regnum=%u, name=%s, value=0x%08" PRIx32,
920  i, arc_reg->name, core_values[core_cnt]);
921  core_cnt++;
922  }
923  }
924 
925  /* Parse aux regs */
926  aux_cnt = 0;
927  for (i = arc->num_core_regs; i < regs_to_scan; i++) {
928  struct reg *reg = reg_list + i;
929  struct arc_reg_desc *arc_reg = reg->arch_info;
930  if (!reg->valid && reg->exist) {
931  target_buffer_set_u32(target, reg->value, aux_values[aux_cnt]);
932  reg->valid = true;
933  reg->dirty = false;
934  LOG_TARGET_DEBUG(target, "Get aux register regnum=%u, name=%s, value=0x%08" PRIx32,
935  i, arc_reg->name, aux_values[aux_cnt]);
936  aux_cnt++;
937  }
938  }
939 
940 exit:
941  free(core_values);
942  free(core_addrs);
943  free(aux_values);
944  free(aux_addrs);
945 
946  return retval;
947 }
948 
958  struct arc_actionpoint **actionpoint)
959 {
960  assert(target);
961  assert(actionpoint);
962 
963  uint32_t debug_ah;
964  /* Check if actionpoint caused halt */
965  CHECK_RETVAL(arc_reg_get_field(target, "debug", "ah",
966  &debug_ah));
967 
968  if (debug_ah) {
969  struct arc_common *arc = target_to_arc(target);
970  unsigned int ap;
971  uint32_t debug_asr;
973  "asr", &debug_asr));
974 
975  for (ap = 0; debug_asr > 1; debug_asr >>= 1)
976  ap += 1;
977 
978  assert(ap < arc->actionpoints_num);
979 
980  *actionpoint = &(arc->actionpoints_list[ap]);
981  } else {
982  *actionpoint = NULL;
983  }
984 
985  return ERROR_OK;
986 }
987 
989 {
990  uint32_t debug_bh;
991 
992  /* Only check for reason if don't know it already. */
993  /* BTW After singlestep at this point core is not marked as halted, so
994  * reading from memory to get current instruction wouldn't work anyway. */
997  return ERROR_OK;
998  }
999 
1000  CHECK_RETVAL(arc_reg_get_field(target, "debug", "bh",
1001  &debug_bh));
1002 
1003  if (debug_bh) {
1004  /* DEBUG.BH is set if core halted due to BRK instruction. */
1006  } else {
1007  struct arc_actionpoint *actionpoint = NULL;
1009 
1010  if (actionpoint) {
1011  if (!actionpoint->used)
1012  LOG_TARGET_WARNING(target, "Target halted by an unused actionpoint");
1013 
1014  if (actionpoint->type == ARC_AP_BREAKPOINT)
1016  else if (actionpoint->type == ARC_AP_WATCHPOINT)
1018  else
1019  LOG_TARGET_WARNING(target, "Unknown type of actionpoint");
1020  }
1021  }
1022 
1023  return ERROR_OK;
1024 }
1025 
1026 static int arc_debug_entry(struct target *target)
1027 {
1029 
1030  /* TODO: reset internal indicators of caches states, otherwise D$/I$
1031  * will not be flushed/invalidated when required. */
1034 
1035  return ERROR_OK;
1036 }
1037 
1038 static int arc_poll(struct target *target)
1039 {
1040  uint32_t status, value;
1041  struct arc_common *arc = target_to_arc(target);
1042 
1043  /* gdb calls continuously through this arc_poll() function */
1045 
1046  /* check for processor halted */
1047  if (status & ARC_JTAG_STAT_RU) {
1048  if (target->state != TARGET_RUNNING) {
1049  LOG_TARGET_WARNING(target, "target is still running");
1051  }
1052  return ERROR_OK;
1053  }
1054  /* In some cases JTAG status register indicates that
1055  * processor is in halt mode, but processor is still running.
1056  * We check halt bit of AUX STATUS32 register for setting correct state. */
1057  if ((target->state == TARGET_RUNNING) || (target->state == TARGET_RESET)) {
1058  CHECK_RETVAL(arc_get_register_value(target, "status32", &value));
1059  if (value & AUX_STATUS32_REG_HALT_BIT) {
1060  LOG_TARGET_DEBUG(target, "ARC core in halt or reset state");
1061  /* Save context if target was not in reset state */
1062  if (target->state == TARGET_RUNNING)
1066  } else {
1067  LOG_TARGET_DEBUG(target, "Discrepancy of STATUS32[0] HALT bit and ARC_JTAG_STAT_RU, "
1068  "target is still running");
1069  }
1070  } else if (target->state == TARGET_DEBUG_RUNNING) {
1072  LOG_TARGET_DEBUG(target, "ARC core is in debug running mode");
1073 
1075 
1077  }
1078 
1079  return ERROR_OK;
1080 }
1081 
1082 static int arc_assert_reset(struct target *target)
1083 {
1084  struct arc_common *arc = target_to_arc(target);
1086  bool srst_asserted = false;
1087 
1088  LOG_TARGET_DEBUG(target, "target->state: %s", target_state_name(target));
1089 
1091  /* allow scripts to override the reset event */
1092 
1095  /* An ARC target might be in halt state after reset, so
1096  * if script requested processor to resume, then it must
1097  * be manually started to ensure that this request
1098  * is satisfied. */
1099  if (target->state == TARGET_HALTED && !target->reset_halt) {
1100  /* Resume the target and continue from the current
1101  * PC register value. */
1102  LOG_TARGET_DEBUG(target, "Starting CPU execution after reset");
1103  CHECK_RETVAL(target_resume(target, 1, 0, 0, 0));
1104  }
1106 
1107  return ERROR_OK;
1108  }
1109 
1110  /* some cores support connecting while srst is asserted
1111  * use that mode if it has been configured */
1114  jtag_add_reset(0, 1);
1115  srst_asserted = true;
1116  }
1117 
1119  /* should issue a srst only, but we may have to assert trst as well */
1121  jtag_add_reset(1, 1);
1122  else if (!srst_asserted)
1123  jtag_add_reset(0, 1);
1124  }
1125 
1127  jtag_add_sleep(50000);
1128 
1130 
1131  if (target->reset_halt)
1133 
1134  return ERROR_OK;
1135 }
1136 
1137 static int arc_deassert_reset(struct target *target)
1138 {
1139  LOG_TARGET_DEBUG(target, "target->state: %s", target_state_name(target));
1140 
1141  /* deassert reset lines */
1142  jtag_add_reset(0, 0);
1143 
1144  return ERROR_OK;
1145 }
1146 
1147 static int arc_arch_state(struct target *target)
1148 {
1149  uint32_t pc_value;
1150 
1151  if (debug_level < LOG_LVL_DEBUG)
1152  return ERROR_OK;
1153 
1154  CHECK_RETVAL(arc_get_register_value(target, "pc", &pc_value));
1155 
1156  LOG_TARGET_DEBUG(target, "target state: %s; PC at: 0x%08" PRIx32,
1158  pc_value);
1159 
1160  return ERROR_OK;
1161 }
1162 
1168 static int arc_restore_context(struct target *target)
1169 {
1170  int retval = ERROR_OK;
1171  unsigned int i;
1172  struct arc_common *arc = target_to_arc(target);
1173  struct reg *reg_list = arc->core_and_aux_cache->reg_list;
1174 
1175  LOG_TARGET_DEBUG(target, "Restoring registers values");
1176  assert(reg_list);
1177 
1178  const uint32_t core_regs_size = arc->num_core_regs * sizeof(uint32_t);
1179  const uint32_t aux_regs_size = arc->num_aux_regs * sizeof(uint32_t);
1180  uint32_t *core_values = malloc(core_regs_size);
1181  uint32_t *aux_values = malloc(aux_regs_size);
1182  uint32_t *core_addrs = malloc(core_regs_size);
1183  uint32_t *aux_addrs = malloc(aux_regs_size);
1184  unsigned int core_cnt = 0;
1185  unsigned int aux_cnt = 0;
1186 
1187  if (!core_values || !core_addrs || !aux_values || !aux_addrs) {
1188  LOG_TARGET_ERROR(target, "Unable to allocate memory");
1189  retval = ERROR_FAIL;
1190  goto exit;
1191  }
1192 
1193  memset(core_values, 0xff, core_regs_size);
1194  memset(core_addrs, 0xff, core_regs_size);
1195  memset(aux_values, 0xff, aux_regs_size);
1196  memset(aux_addrs, 0xff, aux_regs_size);
1197 
1198  for (i = 0; i < arc->num_core_regs; i++) {
1199  struct reg *reg = &(reg_list[i]);
1200  struct arc_reg_desc *arc_reg = reg->arch_info;
1201  if (reg->valid && reg->exist && reg->dirty) {
1202  LOG_TARGET_DEBUG(target, "Will write regnum=%u", i);
1203  core_addrs[core_cnt] = arc_reg->arch_num;
1204  core_values[core_cnt] = target_buffer_get_u32(target, reg->value);
1205  core_cnt += 1;
1206  }
1207  }
1208 
1209  for (i = 0; i < arc->num_aux_regs; i++) {
1210  struct reg *reg = &(reg_list[arc->num_core_regs + i]);
1211  struct arc_reg_desc *arc_reg = reg->arch_info;
1212  if (reg->valid && reg->exist && reg->dirty) {
1213  LOG_TARGET_DEBUG(target, "Will write regnum=%lu", arc->num_core_regs + i);
1214  aux_addrs[aux_cnt] = arc_reg->arch_num;
1215  aux_values[aux_cnt] = target_buffer_get_u32(target, reg->value);
1216  aux_cnt += 1;
1217  }
1218  }
1219 
1220  /* Write data to target.
1221  * Check before write, if aux and core count is greater than 0. */
1222  if (core_cnt > 0) {
1223  retval = arc_jtag_write_core_reg(&arc->jtag_info, core_addrs, core_cnt, core_values);
1224  if (retval != ERROR_OK) {
1225  LOG_TARGET_ERROR(target, "Attempt to write to core registers failed");
1226  retval = ERROR_FAIL;
1227  goto exit;
1228  }
1229  }
1230 
1231  if (aux_cnt > 0) {
1232  retval = arc_jtag_write_aux_reg(&arc->jtag_info, aux_addrs, aux_cnt, aux_values);
1233  if (retval != ERROR_OK) {
1234  LOG_TARGET_ERROR(target, "Attempt to write to aux registers failed");
1235  retval = ERROR_FAIL;
1236  goto exit;
1237  }
1238  }
1239 
1240 exit:
1241  free(core_values);
1242  free(core_addrs);
1243  free(aux_values);
1244  free(aux_addrs);
1245 
1246  return retval;
1247 }
1248 
1249 static int arc_enable_interrupts(struct target *target, int enable)
1250 {
1251  uint32_t value;
1252 
1253  struct arc_common *arc = target_to_arc(target);
1254 
1256 
1257  if (enable) {
1258  /* enable interrupts */
1259  value |= SET_CORE_ENABLE_INTERRUPTS;
1261  LOG_TARGET_DEBUG(target, "interrupts enabled");
1262  } else {
1263  /* disable interrupts */
1264  value &= ~SET_CORE_ENABLE_INTERRUPTS;
1266  LOG_TARGET_DEBUG(target, "interrupts disabled");
1267  }
1268 
1269  return ERROR_OK;
1270 }
1271 
1272 static int arc_resume(struct target *target, int current, target_addr_t address,
1273  int handle_breakpoints, int debug_execution)
1274 {
1275  struct arc_common *arc = target_to_arc(target);
1276  uint32_t resume_pc = 0;
1277  uint32_t value;
1278  struct reg *pc = &arc->core_and_aux_cache->reg_list[arc->pc_index_in_cache];
1279 
1280  LOG_TARGET_DEBUG(target, "current:%i, address:0x%08" TARGET_PRIxADDR ", handle_breakpoints:%i,"
1281  " debug_execution:%i", current, address, handle_breakpoints, debug_execution);
1282 
1283  /* We need to reset ARC cache variables so caches
1284  * would be invalidated and actual data
1285  * would be fetched from memory. */
1287 
1288  if (target->state != TARGET_HALTED) {
1289  LOG_TARGET_ERROR(target, "not halted");
1290  return ERROR_TARGET_NOT_HALTED;
1291  }
1292 
1293  if (!debug_execution) {
1294  /* (gdb) continue = execute until we hit break/watch-point */
1298  }
1299 
1300  /* current = 1: continue on current PC, otherwise continue at <address> */
1301  if (!current) {
1303  pc->dirty = true;
1304  pc->valid = true;
1305  LOG_TARGET_DEBUG(target, "Changing the value of current PC to 0x%08" TARGET_PRIxADDR, address);
1306  }
1307 
1308  if (!current)
1309  resume_pc = address;
1310  else
1311  resume_pc = target_buffer_get_u32(target, pc->value);
1312 
1314 
1315  LOG_TARGET_DEBUG(target, "Target resumes from PC=0x%" PRIx32 ", pc.dirty=%i, pc.valid=%i",
1316  resume_pc, pc->dirty, pc->valid);
1317 
1318  /* check if GDB tells to set our PC where to continue from */
1319  if (pc->valid && resume_pc == target_buffer_get_u32(target, pc->value)) {
1321  LOG_TARGET_DEBUG(target, "resume Core (when start-core) with PC @:0x%08" PRIx32, value);
1323  }
1324 
1325  /* the front-end may request us not to handle breakpoints here */
1326  if (handle_breakpoints) {
1327  /* Single step past breakpoint at current address */
1328  struct breakpoint *breakpoint = breakpoint_find(target, resume_pc);
1329  if (breakpoint) {
1330  LOG_TARGET_DEBUG(target, "skipping past breakpoint at 0x%08" TARGET_PRIxADDR,
1331  breakpoint->address);
1335  }
1336  }
1337 
1338  /* Restore IRQ state if not in debug_execution*/
1339  if (!debug_execution)
1341  else
1342  CHECK_RETVAL(arc_enable_interrupts(target, !debug_execution));
1343 
1345 
1346  /* ready to get us going again */
1349  value &= ~SET_CORE_HALT_BIT; /* clear the HALT bit */
1351  LOG_TARGET_DEBUG(target, "Core started to run");
1352 
1353  /* registers are now invalid */
1355 
1356  if (!debug_execution) {
1359  LOG_TARGET_DEBUG(target, "target resumed at 0x%08" PRIx32, resume_pc);
1360  } else {
1363  LOG_TARGET_DEBUG(target, "target debug resumed at 0x%08" PRIx32, resume_pc);
1364  }
1365 
1366  return ERROR_OK;
1367 }
1368 
1369 static int arc_init_target(struct command_context *cmd_ctx, struct target *target)
1370 {
1374  return ERROR_OK;
1375 }
1376 
1377 static void arc_free_reg_cache(struct reg_cache *cache)
1378 {
1379  free(cache->reg_list);
1380  free(cache);
1381 }
1382 
1383 static void arc_deinit_target(struct target *target)
1384 {
1385  struct arc_common *arc = target_to_arc(target);
1386 
1387  LOG_TARGET_DEBUG(target, "deinitialization of target");
1388  if (arc->core_aux_cache_built)
1390  if (arc->bcr_cache_built)
1392 
1393  struct arc_reg_data_type *type, *n;
1394  struct arc_reg_desc *desc, *k;
1395 
1396  /* Free arc-specific reg_data_types allocations*/
1398  if (type->data_type.type_class == REG_TYPE_CLASS_STRUCT) {
1399  free(type->reg_type_struct_field);
1400  free(type->bitfields);
1401  free(type);
1402  } else if (type->data_type.type_class == REG_TYPE_CLASS_FLAGS) {
1403  free(type->reg_type_flags_field);
1404  free(type->bitfields);
1405  free(type);
1406  }
1407  }
1408 
1409  /* Free standard_gdb_types reg_data_types allocations */
1411  free(type);
1412 
1414  free_reg_desc(desc);
1415 
1417  free_reg_desc(desc);
1418 
1420  free_reg_desc(desc);
1421 
1422  free(arc->actionpoints_list);
1423  free(arc);
1424 }
1425 
1426 
1427 static int arc_target_create(struct target *target, Jim_Interp *interp)
1428 {
1429  struct arc_common *arc = calloc(1, sizeof(*arc));
1430 
1431  if (!arc) {
1432  LOG_TARGET_ERROR(target, "Unable to allocate memory");
1433  return ERROR_FAIL;
1434  }
1435 
1436  LOG_TARGET_DEBUG(target, "Entering");
1438 
1439  return ERROR_OK;
1440 }
1441 
1448 static int arc_write_instruction_u32(struct target *target, uint32_t address,
1449  uint32_t instr)
1450 {
1451  uint8_t value_buf[4];
1452  if (!target_was_examined(target)) {
1453  LOG_TARGET_ERROR(target, "Target not examined yet");
1454  return ERROR_FAIL;
1455  }
1456 
1457  LOG_TARGET_DEBUG(target, "Address: 0x%08" PRIx32 ", value: 0x%08" PRIx32, address,
1458  instr);
1459 
1461  arc_h_u32_to_me(value_buf, instr);
1462  else
1463  h_u32_to_be(value_buf, instr);
1464 
1466 
1467  return ERROR_OK;
1468 }
1469 
1475 static int arc_read_instruction_u32(struct target *target, uint32_t address,
1476  uint32_t *value)
1477 {
1478  uint8_t value_buf[4];
1479 
1480  if (!target_was_examined(target)) {
1481  LOG_TARGET_ERROR(target, "Target not examined yet");
1482  return ERROR_FAIL;
1483  }
1484 
1485  *value = 0;
1486  CHECK_RETVAL(target_read_buffer(target, address, 4, value_buf));
1487 
1489  *value = arc_me_to_h_u32(value_buf);
1490  else
1491  *value = be_to_h_u32(value_buf);
1492 
1493  LOG_TARGET_DEBUG(target, "Address: 0x%08" PRIx32 ", value: 0x%08" PRIx32, address,
1494  *value);
1495 
1496  return ERROR_OK;
1497 }
1498 
1499 /* Actionpoint mechanism allows to setup HW breakpoints
1500  * and watchpoints. Each actionpoint is controlled by
1501  * 3 aux registers: Actionpoint(AP) match mask(AP_AMM), AP match value(AP_AMV)
1502  * and AP control(AC).
1503  * This function is for setting/unsetting actionpoints:
1504  * at - actionpoint target: trigger on mem/reg access
1505  * tt - transaction type : trigger on r/w. */
1506 static int arc_configure_actionpoint(struct target *target, uint32_t ap_num,
1507  uint32_t match_value, uint32_t control_tt, uint32_t control_at)
1508 {
1509  struct arc_common *arc = target_to_arc(target);
1510 
1511  if (control_tt != AP_AC_TT_DISABLE) {
1512 
1513  if (arc->actionpoints_num_avail < 1) {
1514  LOG_TARGET_ERROR(target, "No free actionpoints, maximum amount is %u",
1515  arc->actionpoints_num);
1517  }
1518 
1519  /* Names of register to set - 24 chars should be enough. Looks a little
1520  * bit out-of-place for C code, but makes it aligned to the bigger
1521  * concept of "ARC registers are defined in TCL" as far as possible.
1522  */
1523  char ap_amv_reg_name[24], ap_amm_reg_name[24], ap_ac_reg_name[24];
1524  snprintf(ap_amv_reg_name, 24, "ap_amv%" PRIu32, ap_num);
1525  snprintf(ap_amm_reg_name, 24, "ap_amm%" PRIu32, ap_num);
1526  snprintf(ap_ac_reg_name, 24, "ap_ac%" PRIu32, ap_num);
1527  CHECK_RETVAL(arc_set_register_value(target, ap_amv_reg_name,
1528  match_value));
1529  CHECK_RETVAL(arc_set_register_value(target, ap_amm_reg_name, 0));
1530  CHECK_RETVAL(arc_set_register_value(target, ap_ac_reg_name,
1531  control_tt | control_at));
1532  arc->actionpoints_num_avail--;
1533  } else {
1534  char ap_ac_reg_name[24];
1535  snprintf(ap_ac_reg_name, 24, "ap_ac%" PRIu32, ap_num);
1536  CHECK_RETVAL(arc_set_register_value(target, ap_ac_reg_name,
1537  AP_AC_TT_DISABLE));
1538  arc->actionpoints_num_avail++;
1539  }
1540 
1541  return ERROR_OK;
1542 }
1543 
1544 static int arc_set_breakpoint(struct target *target,
1545  struct breakpoint *breakpoint)
1546 {
1547  if (breakpoint->is_set) {
1548  LOG_TARGET_WARNING(target, "breakpoint already set");
1549  return ERROR_OK;
1550  }
1551 
1552  if (breakpoint->type == BKPT_SOFT) {
1553  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32, breakpoint->unique_id);
1554 
1555  if (breakpoint->length == 4) {
1556  uint32_t verify = 0xffffffff;
1557 
1560 
1562  ARC_SDBBP_32));
1563 
1565 
1566  if (verify != ARC_SDBBP_32) {
1567  LOG_TARGET_ERROR(target, "Unable to set 32bit breakpoint at address @0x%" TARGET_PRIxADDR
1568  " - check that memory is read/writable", breakpoint->address);
1569  return ERROR_FAIL;
1570  }
1571  } else if (breakpoint->length == 2) {
1572  uint16_t verify = 0xffff;
1573 
1577 
1579  if (verify != ARC_SDBBP_16) {
1580  LOG_TARGET_ERROR(target, "Unable to set 16bit breakpoint at address @0x%" TARGET_PRIxADDR
1581  " - check that memory is read/writable", breakpoint->address);
1582  return ERROR_FAIL;
1583  }
1584  } else {
1585  LOG_TARGET_ERROR(target, "Invalid breakpoint length: target supports only 2 or 4");
1587  }
1588 
1589  breakpoint->is_set = true;
1590  } else if (breakpoint->type == BKPT_HARD) {
1591  struct arc_common *arc = target_to_arc(target);
1592  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1593  unsigned int bp_num;
1594 
1595  for (bp_num = 0; bp_num < arc->actionpoints_num; bp_num++) {
1596  if (!ap_list[bp_num].used)
1597  break;
1598  }
1599 
1600  if (bp_num >= arc->actionpoints_num) {
1601  LOG_TARGET_ERROR(target, "No free actionpoints, maximum amount is %u",
1602  arc->actionpoints_num);
1604  }
1605 
1606  int retval = arc_configure_actionpoint(target, bp_num,
1608 
1609  if (retval == ERROR_OK) {
1610  breakpoint_hw_set(breakpoint, bp_num);
1611  ap_list[bp_num].used = 1;
1612  ap_list[bp_num].bp_value = breakpoint->address;
1613  ap_list[bp_num].type = ARC_AP_BREAKPOINT;
1614 
1615  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32 ", bp_num %u bp_value 0x%" PRIx32,
1616  breakpoint->unique_id, bp_num, ap_list[bp_num].bp_value);
1617  }
1618 
1619  } else {
1620  LOG_TARGET_ERROR(target, "setting unknown breakpoint type");
1621  return ERROR_FAIL;
1622  }
1623 
1624  return ERROR_OK;
1625 }
1626 
1628  struct breakpoint *breakpoint)
1629 {
1630  int retval = ERROR_OK;
1631 
1632  if (!breakpoint->is_set) {
1633  LOG_TARGET_WARNING(target, "breakpoint not set");
1634  return ERROR_OK;
1635  }
1636 
1637  if (breakpoint->type == BKPT_SOFT) {
1638  /* restore original instruction (kept in target endianness) */
1639  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32, breakpoint->unique_id);
1640  if (breakpoint->length == 4) {
1641  uint32_t current_instr;
1642 
1643  /* check that user program has not modified breakpoint instruction */
1645 
1646  if (current_instr == ARC_SDBBP_32) {
1649  if (retval != ERROR_OK)
1650  return retval;
1651  } else {
1652  LOG_TARGET_WARNING(target, "Software breakpoint @0x%" TARGET_PRIxADDR
1653  " has been overwritten outside of debugger."
1654  "Expected: @0x%x, got: @0x%" PRIx32,
1655  breakpoint->address, ARC_SDBBP_32, current_instr);
1656  }
1657  } else if (breakpoint->length == 2) {
1658  uint16_t current_instr;
1659 
1660  /* check that user program has not modified breakpoint instruction */
1662  if (current_instr == ARC_SDBBP_16) {
1665  if (retval != ERROR_OK)
1666  return retval;
1667  } else {
1668  LOG_TARGET_WARNING(target, "Software breakpoint @0x%" TARGET_PRIxADDR
1669  " has been overwritten outside of debugger. "
1670  "Expected: 0x%04x, got: 0x%04" PRIx16,
1671  breakpoint->address, ARC_SDBBP_16, current_instr);
1672  }
1673  } else {
1674  LOG_TARGET_ERROR(target, "Invalid breakpoint length: target supports only 2 or 4");
1676  }
1677  breakpoint->is_set = false;
1678 
1679  } else if (breakpoint->type == BKPT_HARD) {
1680  struct arc_common *arc = target_to_arc(target);
1681  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1682  unsigned int bp_num = breakpoint->number;
1683 
1684  if (bp_num >= arc->actionpoints_num) {
1685  LOG_TARGET_DEBUG(target, "Invalid actionpoint ID: %u in breakpoint: %" PRIu32,
1686  bp_num, breakpoint->unique_id);
1687  return ERROR_OK;
1688  }
1689 
1690  retval = arc_configure_actionpoint(target, bp_num,
1692 
1693  if (retval == ERROR_OK) {
1694  breakpoint->is_set = false;
1695  ap_list[bp_num].used = 0;
1696  ap_list[bp_num].bp_value = 0;
1697 
1698  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32 " - released actionpoint ID: %u",
1699  breakpoint->unique_id, bp_num);
1700  }
1701  } else {
1702  LOG_TARGET_ERROR(target, "unsetting unknown breakpoint type");
1703  return ERROR_FAIL;
1704  }
1705 
1706  return retval;
1707 }
1708 
1710 {
1712 
1713  /* set any pending breakpoints */
1714  while (breakpoint) {
1715  if (!breakpoint->is_set)
1718  }
1719 
1720  return ERROR_OK;
1721 }
1722 
1724 {
1725  if (target->state == TARGET_HALTED) {
1727 
1728  } else {
1729  LOG_TARGET_ERROR(target, "not halted (add breakpoint)");
1730  return ERROR_TARGET_NOT_HALTED;
1731  }
1732 }
1733 
1735  struct breakpoint *breakpoint)
1736 {
1737  if (target->state == TARGET_HALTED) {
1738  if (breakpoint->is_set)
1740  } else {
1741  LOG_TARGET_ERROR(target, "not halted (remove breakpoint)");
1742  return ERROR_TARGET_NOT_HALTED;
1743  }
1744 
1745  return ERROR_OK;
1746 }
1747 
1749 {
1750  struct arc_common *arc = target_to_arc(target);
1751  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1752  struct breakpoint *next_b;
1753  struct watchpoint *next_w;
1754 
1755  while (target->breakpoints) {
1756  next_b = target->breakpoints->next;
1758  free(target->breakpoints->orig_instr);
1759  free(target->breakpoints);
1760  target->breakpoints = next_b;
1761  }
1762  while (target->watchpoints) {
1763  next_w = target->watchpoints->next;
1765  free(target->watchpoints);
1766  target->watchpoints = next_w;
1767  }
1768  for (unsigned int i = 0; i < arc->actionpoints_num; i++) {
1769  if ((ap_list[i].used) && (ap_list[i].reg_address))
1770  arc_remove_auxreg_actionpoint(target, ap_list[i].reg_address);
1771  }
1772 }
1773 
1774 int arc_set_actionpoints_num(struct target *target, uint32_t ap_num)
1775 {
1776  LOG_TARGET_DEBUG(target, "actionpoints=%" PRIu32, ap_num);
1777  struct arc_common *arc = target_to_arc(target);
1778 
1779  /* Make sure that there are no enabled actionpoints in target. */
1781 
1782  /* Assume that all points have been removed from target. */
1783  free(arc->actionpoints_list);
1784 
1785  arc->actionpoints_num_avail = ap_num;
1786  arc->actionpoints_num = ap_num;
1787  /* calloc can be safely called when ncount == 0. */
1788  arc->actionpoints_list = calloc(ap_num, sizeof(struct arc_actionpoint));
1789 
1790  if (!arc->actionpoints_list) {
1791  LOG_TARGET_ERROR(target, "Unable to allocate memory");
1792  return ERROR_FAIL;
1793  }
1794  return ERROR_OK;
1795 }
1796 
1797 
1799  uint32_t auxreg_addr, uint32_t transaction)
1800 {
1801  unsigned int ap_num = 0;
1802  int retval = ERROR_OK;
1803 
1804  if (target->state != TARGET_HALTED)
1805  return ERROR_TARGET_NOT_HALTED;
1806 
1807  struct arc_common *arc = target_to_arc(target);
1808  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1809 
1810  while (ap_list[ap_num].used)
1811  ap_num++;
1812 
1813  if (ap_num >= arc->actionpoints_num) {
1814  LOG_TARGET_ERROR(target, "No actionpoint free, maximum amount is %u",
1815  arc->actionpoints_num);
1817  }
1818 
1819  retval = arc_configure_actionpoint(target, ap_num,
1820  auxreg_addr, transaction, AP_AC_AT_AUXREG_ADDR);
1821 
1822  if (retval == ERROR_OK) {
1823  ap_list[ap_num].used = 1;
1824  ap_list[ap_num].reg_address = auxreg_addr;
1825  }
1826 
1827  return retval;
1828 }
1829 
1830 int arc_remove_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr)
1831 {
1832  int retval = ERROR_OK;
1833  bool ap_found = false;
1834  unsigned int ap_num = 0;
1835 
1836  if (target->state != TARGET_HALTED)
1837  return ERROR_TARGET_NOT_HALTED;
1838 
1839  struct arc_common *arc = target_to_arc(target);
1840  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1841 
1842  while ((ap_list[ap_num].used) && (ap_num < arc->actionpoints_num)) {
1843  if (ap_list[ap_num].reg_address == auxreg_addr) {
1844  ap_found = true;
1845  break;
1846  }
1847  ap_num++;
1848  }
1849 
1850  if (ap_found) {
1851  retval = arc_configure_actionpoint(target, ap_num,
1852  auxreg_addr, AP_AC_TT_DISABLE, AP_AC_AT_AUXREG_ADDR);
1853 
1854  if (retval == ERROR_OK) {
1855  ap_list[ap_num].used = 0;
1856  ap_list[ap_num].bp_value = 0;
1857  }
1858  } else {
1859  LOG_TARGET_ERROR(target, "Register actionpoint not found");
1860  }
1861  return retval;
1862 }
1863 
1864 
1865 static int arc_set_watchpoint(struct target *target,
1866  struct watchpoint *watchpoint)
1867 {
1868  unsigned int wp_num;
1869  struct arc_common *arc = target_to_arc(target);
1870  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1871 
1872  if (watchpoint->is_set) {
1873  LOG_TARGET_WARNING(target, "watchpoint already set");
1874  return ERROR_OK;
1875  }
1876 
1877  for (wp_num = 0; wp_num < arc->actionpoints_num; wp_num++) {
1878  if (!ap_list[wp_num].used)
1879  break;
1880  }
1881 
1882  if (wp_num >= arc->actionpoints_num) {
1883  LOG_TARGET_ERROR(target, "No free actionpoints, maximum amount is %u",
1884  arc->actionpoints_num);
1886  }
1887 
1888  if (watchpoint->length != 4) {
1889  LOG_TARGET_ERROR(target, "Only watchpoints of length 4 are supported");
1891  }
1892 
1893  int enable = AP_AC_TT_DISABLE;
1894  switch (watchpoint->rw) {
1895  case WPT_READ:
1896  enable = AP_AC_TT_READ;
1897  break;
1898  case WPT_WRITE:
1899  enable = AP_AC_TT_WRITE;
1900  break;
1901  case WPT_ACCESS:
1902  enable = AP_AC_TT_READWRITE;
1903  break;
1904  default:
1905  LOG_TARGET_ERROR(target, "BUG: watchpoint->rw neither read, write nor access");
1906  return ERROR_FAIL;
1907  }
1908 
1909  int retval = arc_configure_actionpoint(target, wp_num,
1911 
1912  if (retval == ERROR_OK) {
1913  watchpoint_set(watchpoint, wp_num);
1914  ap_list[wp_num].used = 1;
1915  ap_list[wp_num].bp_value = watchpoint->address;
1916  ap_list[wp_num].type = ARC_AP_WATCHPOINT;
1917 
1918  LOG_TARGET_DEBUG(target, "wpid: %" PRIu32 ", wp_num %u wp_value 0x%" PRIx32,
1919  watchpoint->unique_id, wp_num, ap_list[wp_num].bp_value);
1920  }
1921 
1922  return retval;
1923 }
1924 
1926  struct watchpoint *watchpoint)
1927 {
1928  /* get pointers to arch-specific information */
1929  struct arc_common *arc = target_to_arc(target);
1930  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1931 
1932  if (!watchpoint->is_set) {
1933  LOG_TARGET_WARNING(target, "watchpoint not set");
1934  return ERROR_OK;
1935  }
1936 
1937  unsigned int wp_num = watchpoint->number;
1938  if (wp_num >= arc->actionpoints_num) {
1939  LOG_TARGET_DEBUG(target, "Invalid actionpoint ID: %u in watchpoint: %" PRIu32,
1940  wp_num, watchpoint->unique_id);
1941  return ERROR_OK;
1942  }
1943 
1944  int retval = arc_configure_actionpoint(target, wp_num,
1946 
1947  if (retval == ERROR_OK) {
1948  watchpoint->is_set = false;
1949  ap_list[wp_num].used = 0;
1950  ap_list[wp_num].bp_value = 0;
1951 
1952  LOG_TARGET_DEBUG(target, "wpid: %" PRIu32 " - releasing actionpoint ID: %u",
1953  watchpoint->unique_id, wp_num);
1954  }
1955 
1956  return retval;
1957 }
1958 
1960 {
1962 
1963  /* set any pending watchpoints */
1964  while (watchpoint) {
1965  if (!watchpoint->is_set)
1968  }
1969 
1970  return ERROR_OK;
1971 }
1972 
1973 static int arc_add_watchpoint(struct target *target,
1974  struct watchpoint *watchpoint)
1975 {
1976  if (target->state != TARGET_HALTED) {
1977  LOG_TARGET_ERROR(target, "not halted");
1978  return ERROR_TARGET_NOT_HALTED;
1979  }
1980 
1982 
1983  return ERROR_OK;
1984 }
1985 
1987  struct watchpoint *watchpoint)
1988 {
1989  if (target->state != TARGET_HALTED) {
1990  LOG_TARGET_ERROR(target, "not halted");
1991  return ERROR_TARGET_NOT_HALTED;
1992  }
1993 
1994  if (watchpoint->is_set)
1996 
1997  return ERROR_OK;
1998 }
1999 
2000 static int arc_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
2001 {
2002  assert(target);
2003  assert(hit_watchpoint);
2004 
2005  struct arc_actionpoint *actionpoint = NULL;
2007 
2008  if (actionpoint) {
2009  if (!actionpoint->used)
2010  LOG_TARGET_WARNING(target, "Target halted by unused actionpoint");
2011 
2012  /* If this check fails - that is some sort of an error in OpenOCD. */
2013  if (actionpoint->type != ARC_AP_WATCHPOINT)
2014  LOG_TARGET_WARNING(target, "Target halted by breakpoint, but is treated as a watchpoint");
2015 
2016  for (struct watchpoint *watchpoint = target->watchpoints;
2017  watchpoint;
2018  watchpoint = watchpoint->next) {
2019  if (actionpoint->bp_value == watchpoint->address) {
2020  *hit_watchpoint = watchpoint;
2021  LOG_TARGET_DEBUG(target, "Hit watchpoint, wpid: %" PRIu32 ", watchpoint num: %u",
2023  return ERROR_OK;
2024  }
2025  }
2026  }
2027 
2028  return ERROR_FAIL;
2029 }
2030 
2031 /* Helper function which switches core to single_step mode by
2032  * doing aux r/w operations. */
2033 static int arc_config_step(struct target *target, int enable_step)
2034 {
2035  uint32_t value;
2036 
2037  struct arc_common *arc = target_to_arc(target);
2038 
2039  /* enable core debug step mode */
2040  if (enable_step) {
2042  &value));
2043  value &= ~SET_CORE_AE_BIT; /* clear the AE bit */
2045  value));
2046  LOG_TARGET_DEBUG(target, " [status32:0x%08" PRIx32 "]", value);
2047 
2048  /* Doing read-modify-write, because DEBUG might contain manually set
2049  * bits like UB or ED, which should be preserved. */
2051  AUX_DEBUG_REG, &value));
2052  value |= SET_CORE_SINGLE_INSTR_STEP; /* set the IS bit */
2054  value));
2055  LOG_TARGET_DEBUG(target, "core debug step mode enabled [debug-reg:0x%08" PRIx32 "]", value);
2056 
2057  } else { /* disable core debug step mode */
2059  &value));
2060  value &= ~SET_CORE_SINGLE_INSTR_STEP; /* clear the IS bit */
2062  value));
2063  LOG_TARGET_DEBUG(target, "core debug step mode disabled");
2064  }
2065 
2066  return ERROR_OK;
2067 }
2068 
2070 {
2072 
2073  /* disable interrupts while stepping */
2075 
2076  /* configure single step mode */
2078 
2079  /* exit debug mode */
2081 
2082  return ERROR_OK;
2083 }
2084 
2085 static int arc_step(struct target *target, int current, target_addr_t address,
2086  int handle_breakpoints)
2087 {
2088  /* get pointers to arch-specific information */
2089  struct arc_common *arc = target_to_arc(target);
2090  struct breakpoint *breakpoint = NULL;
2091  struct reg *pc = &(arc->core_and_aux_cache->reg_list[arc->pc_index_in_cache]);
2092 
2093  if (target->state != TARGET_HALTED) {
2094  LOG_TARGET_ERROR(target, "not halted");
2095  return ERROR_TARGET_NOT_HALTED;
2096  }
2097 
2098  /* current = 1: continue on current pc, otherwise continue at <address> */
2099  if (!current) {
2100  buf_set_u32(pc->value, 0, 32, address);
2101  pc->dirty = true;
2102  pc->valid = true;
2103  }
2104 
2105  LOG_TARGET_DEBUG(target, "Target steps one instruction from PC=0x%" PRIx32,
2106  buf_get_u32(pc->value, 0, 32));
2107 
2108  /* the front-end may request us not to handle breakpoints */
2109  if (handle_breakpoints) {
2111  if (breakpoint)
2113  }
2114 
2115  /* restore context */
2117 
2119 
2121 
2122  /* disable interrupts while stepping */
2124 
2125  /* do a single step */
2127 
2128  /* make sure we done our step */
2129  alive_sleep(1);
2130 
2131  /* registers are now invalid */
2133 
2134  if (breakpoint)
2136 
2137  LOG_TARGET_DEBUG(target, "target stepped");
2138 
2140 
2141  /* Saving context */
2144 
2145  return ERROR_OK;
2146 }
2147 
2148 
2149 /* This function invalidates icache. */
2151 {
2152  uint32_t value;
2153 
2154  struct arc_common *arc = target_to_arc(target);
2155 
2156  /* Don't waste time if already done. */
2157  if (!arc->has_icache || arc->icache_invalidated)
2158  return ERROR_OK;
2159 
2160  LOG_TARGET_DEBUG(target, "Invalidating I$");
2161 
2162  value = IC_IVIC_INVALIDATE; /* invalidate I$ */
2164 
2165  arc->icache_invalidated = true;
2166 
2167  return ERROR_OK;
2168 }
2169 
2170 /* This function invalidates dcache */
2172 {
2173  uint32_t value, dc_ctrl_value;
2174 
2175  struct arc_common *arc = target_to_arc(target);
2176 
2177  if (!arc->has_dcache || arc->dcache_invalidated)
2178  return ERROR_OK;
2179 
2180  LOG_TARGET_DEBUG(target, "Invalidating D$");
2181 
2183  dc_ctrl_value = value;
2184  value &= ~DC_CTRL_IM;
2185 
2186  /* set DC_CTRL invalidate mode to invalidate-only (no flushing!!) */
2188  value = DC_IVDC_INVALIDATE; /* invalidate D$ */
2190 
2191  /* restore DC_CTRL invalidate mode */
2193 
2194  arc->dcache_invalidated = true;
2195 
2196  return ERROR_OK;
2197 }
2198 
2199 /* This function invalidates l2 cache. */
2201 {
2202  uint32_t value, slc_ctrl_value;
2203 
2204  struct arc_common *arc = target_to_arc(target);
2205 
2206  if (!arc->has_l2cache || arc->l2cache_invalidated)
2207  return ERROR_OK;
2208 
2209  LOG_TARGET_DEBUG(target, "Invalidating L2$");
2210 
2212  slc_ctrl_value = value;
2213  value &= ~L2_CTRL_IM;
2214 
2215  /* set L2_CTRL invalidate mode to invalidate-only (no flushing!!) */
2217  /* invalidate L2$ */
2219 
2220  /* Wait until invalidate operation ends */
2221  do {
2222  LOG_TARGET_DEBUG(target, "Waiting for invalidation end");
2224  } while (value & L2_CTRL_BS);
2225 
2226  /* restore L2_CTRL invalidate mode */
2228 
2229  arc->l2cache_invalidated = true;
2230 
2231  return ERROR_OK;
2232 }
2233 
2234 
2236 {
2240 
2241  return ERROR_OK;
2242 }
2243 
2244 /* Flush data cache. This function is cheap to call and return quickly if D$
2245  * already has been flushed since target had been halted. JTAG debugger reads
2246  * values directly from memory, bypassing cache, so if there are unflushed
2247  * lines debugger will read invalid values, which will cause a lot of troubles.
2248  * */
2249 static int arc_dcache_flush(struct target *target)
2250 {
2251  uint32_t value, dc_ctrl_value;
2252  bool has_to_set_dc_ctrl_im;
2253 
2254  struct arc_common *arc = target_to_arc(target);
2255 
2256  /* Don't waste time if already done. */
2257  if (!arc->has_dcache || arc->dcache_flushed)
2258  return ERROR_OK;
2259 
2260  LOG_TARGET_DEBUG(target, "Flushing D$");
2261 
2262  /* Store current value of DC_CTRL */
2264 
2265  /* Set DC_CTRL invalidate mode to flush (if not already set) */
2266  has_to_set_dc_ctrl_im = (dc_ctrl_value & DC_CTRL_IM) == 0;
2267  if (has_to_set_dc_ctrl_im) {
2268  value = dc_ctrl_value | DC_CTRL_IM;
2270  }
2271 
2272  /* Flush D$ */
2273  value = DC_IVDC_INVALIDATE;
2275 
2276  /* Restore DC_CTRL invalidate mode (even of flush failed) */
2277  if (has_to_set_dc_ctrl_im)
2279 
2280  arc->dcache_flushed = true;
2281 
2282  return ERROR_OK;
2283 }
2284 
2285 /* This function flushes l2cache. */
2286 static int arc_l2cache_flush(struct target *target)
2287 {
2288  uint32_t value;
2289 
2290  struct arc_common *arc = target_to_arc(target);
2291 
2292  /* Don't waste time if already done. */
2293  if (!arc->has_l2cache || arc->l2cache_flushed)
2294  return ERROR_OK;
2295 
2296  LOG_TARGET_DEBUG(target, "Flushing L2$");
2297 
2298  /* Flush L2 cache */
2300 
2301  /* Wait until flush operation ends */
2302  do {
2303  LOG_TARGET_DEBUG(target, "Waiting for flushing end");
2305  } while (value & L2_CTRL_BS);
2306 
2307  arc->l2cache_flushed = true;
2308 
2309  return ERROR_OK;
2310 }
2311 
2313 {
2316 
2317  return ERROR_OK;
2318 }
2319 
2320 /* ARC v2 target */
2321 struct target_type arcv2_target = {
2322  .name = "arcv2",
2323 
2324  .poll = arc_poll,
2325 
2326  .arch_state = arc_arch_state,
2327 
2328  /* TODO That seems like something similar to metaware hostlink, so perhaps
2329  * we can exploit this in the future. */
2330  .target_request_data = NULL,
2331 
2332  .halt = arc_halt,
2333  .resume = arc_resume,
2334  .step = arc_step,
2335 
2336  .assert_reset = arc_assert_reset,
2337  .deassert_reset = arc_deassert_reset,
2338 
2339  /* TODO Implement soft_reset_halt */
2340  .soft_reset_halt = NULL,
2341 
2342  .get_gdb_reg_list = arc_get_gdb_reg_list,
2343 
2344  .read_memory = arc_mem_read,
2345  .write_memory = arc_mem_write,
2346  .checksum_memory = NULL,
2347  .blank_check_memory = NULL,
2348 
2349  .add_breakpoint = arc_add_breakpoint,
2350  .add_context_breakpoint = NULL,
2351  .add_hybrid_breakpoint = NULL,
2352  .remove_breakpoint = arc_remove_breakpoint,
2353  .add_watchpoint = arc_add_watchpoint,
2354  .remove_watchpoint = arc_remove_watchpoint,
2355  .hit_watchpoint = arc_hit_watchpoint,
2356 
2357  .run_algorithm = NULL,
2358  .start_algorithm = NULL,
2359  .wait_algorithm = NULL,
2360 
2361  .commands = arc_monitor_command_handlers,
2362 
2363  .target_create = arc_target_create,
2364  .init_target = arc_init_target,
2365  .deinit_target = arc_deinit_target,
2366  .examine = arc_examine,
2367 
2368  .virt2phys = NULL,
2369  .read_phys_memory = NULL,
2370  .write_phys_memory = NULL,
2371  .mmu = NULL,
2372 };
static int arc_set_register(struct reg *reg, uint8_t *buf)
Definition: arc.c:266
static int arc_restore_context(struct target *target)
See arc_save_context() for reason why we want to dump all regs at once.
Definition: arc.c:1168
static int arc_build_bcr_reg_cache(struct target *target)
Definition: arc.c:435
int arc_reg_get_field(struct target *target, const char *reg_name, const char *field_name, uint32_t *value_ptr)
Definition: arc.c:549
static int arc_configure_actionpoint(struct target *target, uint32_t ap_num, uint32_t match_value, uint32_t control_tt, uint32_t control_at)
Definition: arc.c:1506
static int arc_save_context(struct target *target)
Read registers that are used in GDB g-packet.
Definition: arc.c:842
static int get_current_actionpoint(struct target *target, struct arc_actionpoint **actionpoint)
Finds an actionpoint that triggered last actionpoint event, as specified by DEBUG....
Definition: arc.c:957
static int arc_enable_breakpoints(struct target *target)
Definition: arc.c:1709
int arc_reg_add(struct target *target, struct arc_reg_desc *arc_reg, const char *const type_name, const size_t type_name_len)
Definition: arc.c:174
static int arc_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Definition: arc.c:493
static int arc_config_step(struct target *target, int enable_step)
Definition: arc.c:2033
static int arc_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arc.c:1734
static int arc_configure(struct target *target)
Definition: arc.c:717
static int arc_get_register(struct reg *reg)
Definition: arc.c:219
static const struct reg_arch_type arc_reg_type
Definition: arc.c:293
static int arc_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1986
static int arc_unset_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arc.c:1627
static int arc_build_reg_cache(struct target *target)
Definition: arc.c:346
void arc_reg_data_type_add(struct target *target, struct arc_reg_data_type *data_type)
Definition: arc.c:61
static int arc_configure_iccm(struct target *target)
Definition: arc.c:668
static int arc_single_step_core(struct target *target)
Definition: arc.c:2069
static int arc_assert_reset(struct target *target)
Definition: arc.c:1082
static const char *const reg_group_other
Definition: arc.c:300
struct target_type arcv2_target
Definition: arc.c:2321
static int arc_unset_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1925
int arc_cache_flush(struct target *target)
Definition: arc.c:2312
static int arc_debug_entry(struct target *target)
Definition: arc.c:1026
static int arc_set_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1865
static int arc_examine(struct target *target)
Definition: arc.c:735
static int arc_enable_interrupts(struct target *target, int enable)
Definition: arc.c:1249
static int arc_enable_watchpoints(struct target *target)
Definition: arc.c:1959
static int arc_halt(struct target *target)
Definition: arc.c:781
static int arc_configure_dccm(struct target *target)
Definition: arc.c:638
static int arc_l2cache_flush(struct target *target)
Definition: arc.c:2286
int arc_cache_invalidate(struct target *target)
Definition: arc.c:2235
static int arc_deassert_reset(struct target *target)
Definition: arc.c:1137
static int arc_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
Definition: arc.c:2085
static const char *const reg_group_general
Definition: arc.c:299
static int arc_l2cache_invalidate(struct target *target)
Definition: arc.c:2200
static int arc_init_arch_info(struct target *target, struct arc_common *arc, struct jtag_tap *tap)
Definition: arc.c:120
static void arc_free_reg_cache(struct reg_cache *cache)
Definition: arc.c:1377
static void arc_reset_actionpoints(struct target *target)
Definition: arc.c:1748
static int arc_poll(struct target *target)
Definition: arc.c:1038
static int arc_examine_debug_reason(struct target *target)
Definition: arc.c:988
static int arc_arch_state(struct target *target)
Definition: arc.c:1147
int arc_remove_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr)
Definition: arc.c:1830
static int arc_icache_invalidate(struct target *target)
Definition: arc.c:2150
static int arc_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1973
static int arc_dcache_invalidate(struct target *target)
Definition: arc.c:2171
static int arc_exit_debug(struct target *target)
Definition: arc.c:758
static int arc_write_instruction_u32(struct target *target, uint32_t address, uint32_t instr)
Write 4-byte instruction to memory.
Definition: arc.c:1448
static int arc_target_create(struct target *target, Jim_Interp *interp)
Definition: arc.c:1427
static int arc_set_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arc.c:1544
int arc_add_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr, uint32_t transaction)
Definition: arc.c:1798
static int arc_set_register_value(struct target *target, const char *reg_name, uint32_t value)
Definition: arc.c:615
int arc_set_actionpoints_num(struct target *target, uint32_t ap_num)
Definition: arc.c:1774
static int arc_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Definition: arc.c:1272
static int arc_reset_caches_states(struct target *target)
Reset internal states of caches.
Definition: arc.c:103
static int arc_read_instruction_u32(struct target *target, uint32_t address, uint32_t *value)
Read 32-bit instruction from memory.
Definition: arc.c:1475
static int arc_dcache_flush(struct target *target)
Definition: arc.c:2249
static void arc_deinit_target(struct target *target)
Definition: arc.c:1383
static int arc_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: arc.c:1369
static int arc_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
Definition: arc.c:2000
static int arc_init_reg(struct target *target, struct reg *reg, struct arc_reg_desc *reg_desc, unsigned long number)
Definition: arc.c:303
struct reg * arc_reg_get_by_name(struct reg_cache *first, const char *name, bool search_all)
Private implementation of register_get_by_name() for ARC that doesn't skip not [yet] existing registe...
Definition: arc.c:77
static int arc_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arc.c:1723
static int arc_get_register_value(struct target *target, const char *reg_name, uint32_t *value_ptr)
Definition: arc.c:597
#define AUX_STATUS32_REG_IE_BIT
Definition: arc.h:47
static struct arc_common * target_to_arc(struct target *target)
Definition: arc.h:257
#define AUX_DC_CTRL_REG
Definition: arc.h:113
#define ERROR_ARC_REGTYPE_NOT_FOUND
Definition: arc.h:326
#define ERROR_ARC_REGISTER_FIELD_NOT_FOUND
Definition: arc.h:323
#define AP_AC_TT_READWRITE
Definition: arc.h:133
#define SET_CORE_SINGLE_INSTR_STEP
Definition: arc.h:44
#define AUX_STATUS32_REG_HALT_BIT
Definition: arc.h:46
#define AP_AC_TT_READ
Definition: arc.h:132
static void arc_h_u32_to_me(uint8_t *buf, int val)
Convert data in host endianness to the middle endian.
Definition: arc.h:268
#define L2_CTRL_BS
Definition: arc.h:119
#define IC_IVIC_INVALIDATE
Definition: arc.h:109
#define AP_AC_AT_INST_ADDR
Definition: arc.h:126
#define SLC_AUX_CACHE_FLUSH
Definition: arc.h:120
#define DC_CTRL_IM
Definition: arc.h:114
#define L2_FLUSH_FL
Definition: arc.h:121
#define L2_INV_IV
Definition: arc.h:123
#define AUX_DEBUG_REG
Definition: arc.h:33
#define ERROR_ARC_REGISTER_IS_NOT_STRUCT
Definition: arc.h:324
static const struct reg_data_type standard_gdb_types[]
Definition: arc.h:154
#define ARC_SDBBP_16
Definition: arc.h:105
#define AUX_IC_IVIC_REG
Definition: arc.h:108
#define AP_AC_AT_MEMORY_ADDR
Definition: arc.h:127
#define AUX_STATUS32_REG
Definition: arc.h:35
#define SLC_AUX_CACHE_CTRL
Definition: arc.h:117
#define AP_AC_AT_AUXREG_ADDR
Definition: arc.h:128
#define AUX_DC_IVDC_REG
Definition: arc.h:111
static uint32_t arc_me_to_h_u32(const uint8_t *buf)
Convert data in middle endian to host endian.
Definition: arc.h:280
#define SET_CORE_ENABLE_INTERRUPTS
Definition: arc.h:40
@ ARC_AP_BREAKPOINT
Definition: arc.h:174
@ ARC_AP_WATCHPOINT
Definition: arc.h:175
#define SLC_AUX_CACHE_INV
Definition: arc.h:122
#define ERROR_ARC_REGISTER_NOT_FOUND
Definition: arc.h:322
#define SET_CORE_AE_BIT
Definition: arc.h:42
void free_reg_desc(struct arc_reg_desc *r)
Definition: arc_cmd.c:527
#define ARC_COMMON_MAGIC
Definition: arc.h:31
#define AUX_PC_REG
Definition: arc.h:34
#define SET_CORE_FORCE_HALT
Definition: arc.h:38
#define AP_AC_TT_DISABLE
Definition: arc.h:130
#define CHECK_RETVAL(action)
Definition: arc.h:247
#define ERROR_ARC_FIELD_IS_NOT_BITFIELD
Definition: arc.h:325
#define ARC_SDBBP_32
Definition: arc.h:102
#define SET_CORE_HALT_BIT
Definition: arc.h:39
#define L2_CTRL_IM
Definition: arc.h:118
#define AP_AC_TT_WRITE
Definition: arc.h:131
@ ARC_R61
Definition: arc.h:86
@ ARC_R62
Definition: arc.h:87
#define DC_IVDC_INVALIDATE
Definition: arc.h:112
const struct command_registration arc_monitor_command_handlers[]
Definition: arc_cmd.c:901
int arc_jtag_startup(struct arc_jtag *jtag_info)
Definition: arc_jtag.c:169
int arc_jtag_write_core_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, const uint32_t *buffer)
Write core registers.
Definition: arc_jtag.c:342
int arc_jtag_read_core_reg_one(struct arc_jtag *jtag_info, uint32_t addr, uint32_t *value)
Wrapper function to ease reading of one core register.
Definition: arc_jtag.c:350
int arc_jtag_status(struct arc_jtag *const jtag_info, uint32_t *const value)
Read STATUS register.
Definition: arc_jtag.c:179
int arc_jtag_write_aux_reg_one(struct arc_jtag *jtag_info, uint32_t addr, uint32_t value)
Wrapper function to ease writing of one AUX register.
Definition: arc_jtag.c:374
int arc_jtag_read_core_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, uint32_t *buffer)
Read core registers.
Definition: arc_jtag.c:366
int arc_jtag_read_aux_reg_one(struct arc_jtag *jtag_info, uint32_t addr, uint32_t *value)
Wrapper function to ease reading of one AUX register.
Definition: arc_jtag.c:398
int arc_jtag_write_aux_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, const uint32_t *buffer)
Write AUX registers.
Definition: arc_jtag.c:390
int arc_jtag_read_aux_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, uint32_t *buffer)
Read AUX registers.
Definition: arc_jtag.c:414
#define ARC_JTAG_STAT_RU
Definition: arc_jtag.h:23
int arc_mem_read(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: arc_mem.c:232
int arc_mem_write(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: arc_mem.c:155
const char * group
Definition: armv4_5.c:366
const char * name
Definition: armv4_5.c:76
const char * feature
Definition: armv4_5.c:367
struct reg_data_type * data_type
Definition: armv7m.c:105
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
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
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:404
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
enum esirisc_reg_num number
Definition: esirisc.c:87
uint8_t type
Definition: esp_usb_jtag.c:0
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
static enum reset_types jtag_reset_config
Definition: jtag/core.c:89
int jtag_get_srst(void)
Definition: jtag/core.c:1760
void jtag_add_sleep(uint32_t us)
Definition: jtag/core.c:883
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1747
reset_types
Definition: jtag.h:215
@ RESET_SRST_NO_GATING
Definition: jtag.h:224
@ RESET_HAS_SRST
Definition: jtag.h:218
@ RESET_SRST_PULLS_TRST
Definition: jtag.h:220
#define list_for_each_entry_safe_reverse(p, n, h, field)
Definition: list.h:177
#define list_first_entry(ptr, type, member)
Definition: list.h:127
static void list_add_tail(struct list_head *new, struct list_head *head)
Definition: list.h:199
static int list_empty(const struct list_head *head)
Definition: list.h:60
#define list_for_each_entry_safe(p, n, h, field)
Definition: list.h:155
#define list_for_each_entry(p, h, field)
Definition: list.h:151
static void INIT_LIST_HEAD(struct list_head *list)
Definition: list.h:53
int debug_level
Definition: log.c:47
void alive_sleep(uint64_t ms)
Definition: log.c:467
#define LOG_TARGET_WARNING(target, fmt_str,...)
Definition: log.h:158
#define ERROR_FAIL
Definition: log.h:173
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:161
#define LOG_TARGET_DEBUG(target, fmt_str,...)
Definition: log.h:149
#define ERROR_OK
Definition: log.h:167
@ LOG_LVL_DEBUG
Definition: log.h:47
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
@ REG_TYPE_ARCH_DEFINED
Definition: register.h:38
@ REG_TYPE_CLASS_FLAGS
Definition: register.h:96
@ REG_TYPE_CLASS_STRUCT
Definition: register.h:95
#define MIN(a, b)
Definition: replacements.h:22
int used
Definition: arc.h:180
uint32_t reg_address
Definition: arc.h:182
uint32_t bp_value
Definition: arc.h:181
enum arc_actionpointype type
Definition: arc.h:183
uint32_t dccm_start
Definition: arc.h:219
unsigned long num_core_regs
Definition: arc.h:230
bool has_icache
Definition: arc.h:196
uint32_t dccm_end
Definition: arc.h:220
bool dcache_flushed
Definition: arc.h:200
struct list_head core_reg_descriptions
Definition: arc.h:226
unsigned long debug_index_in_cache
Definition: arc.h:238
bool l2cache_flushed
Definition: arc.h:203
unsigned long num_aux_regs
Definition: arc.h:231
uint32_t iccm1_end
Definition: arc.h:218
bool dcache_invalidated
Definition: arc.h:207
bool has_l2cache
Definition: arc.h:197
int irq_state
Definition: arc.h:222
unsigned int actionpoints_num
Definition: arc.h:241
unsigned long pc_index_in_cache
Definition: arc.h:236
unsigned int actionpoints_num_avail
Definition: arc.h:242
unsigned long num_regs
Definition: arc.h:229
struct reg_cache * core_and_aux_cache
Definition: arc.h:191
bool icache_invalidated
Definition: arc.h:206
uint32_t iccm0_end
Definition: arc.h:216
bool core_aux_cache_built
Definition: arc.h:211
bool has_dcache
Definition: arc.h:195
unsigned long num_bcr_regs
Definition: arc.h:232
uint32_t iccm1_start
Definition: arc.h:217
unsigned int common_magic
Definition: arc.h:187
struct reg_cache * bcr_cache
Definition: arc.h:192
struct arc_jtag jtag_info
Definition: arc.h:189
struct arc_actionpoint * actionpoints_list
Definition: arc.h:243
uint32_t iccm0_start
Definition: arc.h:215
unsigned long last_general_reg
Definition: arc.h:233
struct list_head reg_data_types
Definition: arc.h:225
bool bcr_cache_built
Definition: arc.h:212
bool l2cache_invalidated
Definition: arc.h:208
struct list_head aux_reg_descriptions
Definition: arc.h:227
struct list_head bcr_reg_descriptions
Definition: arc.h:228
struct jtag_tap * tap
Definition: arc_jtag.h:39
struct reg_data_type data_type
Definition: arc.h:142
struct list_head list
Definition: arc.h:141
struct list_head list
Definition: arc.h:318
char * gdb_xml_feature
Definition: arc.h:301
uint8_t reg_value[4]
Definition: arc.h:295
struct reg_data_type * data_type
Definition: arc.h:316
uint32_t arch_num
Definition: arc.h:307
bool is_general
Definition: arc.h:304
struct target * target
Definition: arc.h:289
bool is_core
Definition: arc.h:310
char * name
Definition: arc.h:292
bool is_bcr
Definition: arc.h:313
struct reg_feature feature
Definition: arc.h:298
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
uint32_t unique_id
Definition: breakpoints.h:35
bool is_set
Definition: breakpoints.h:31
unsigned int number
Definition: breakpoints.h:32
target_addr_t address
Definition: breakpoints.h:27
Definition: jtag.h:101
unsigned int ir_length
size of instruction register
Definition: jtag.h:110
int(* get)(struct reg *reg)
Definition: register.h:152
int(* set)(struct reg *reg, uint8_t *buf)
Definition: register.h:153
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
struct reg_data_type_bitfield * bitfield
Definition: register.h:70
struct reg_data_type_struct_field * next
Definition: register.h:73
struct reg_data_type_struct_field * fields
Definition: register.h:78
enum reg_type type
Definition: register.h:100
enum reg_data_type_class type_class
Definition: register.h:102
const char * id
Definition: register.h:101
struct reg_data_type_struct * reg_type_struct
Definition: register.h:106
const char * name
Definition: register.h:42
Definition: register.h:111
bool caller_save
Definition: register.h:119
bool valid
Definition: register.h:126
bool exist
Definition: register.h:128
uint32_t size
Definition: register.h:132
const char * group
Definition: register.h:138
uint8_t * value
Definition: register.h:122
struct reg_feature * feature
Definition: register.h:117
struct reg_data_type * reg_data_type
Definition: register.h:135
uint32_t number
Definition: register.h:115
void * arch_info
Definition: register.h:140
bool dirty
Definition: register.h:124
const struct reg_arch_type * type
Definition: register.h:141
const char * name
Definition: register.h:113
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:116
struct jtag_tap * tap
Definition: target.h:119
enum target_debug_reason debug_reason
Definition: target.h:154
enum target_state state
Definition: target.h:157
enum target_endianness endianness
Definition: target.h:155
struct reg_cache * reg_cache
Definition: target.h:158
struct breakpoint * breakpoints
Definition: target.h:159
struct watchpoint * watchpoints
Definition: target.h:160
void * arch_info
Definition: target.h:164
bool reset_halt
Definition: target.h:144
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
int unique_id
Definition: breakpoints.h:50
unsigned int number
Definition: breakpoints.h:48
target_addr_t address
Definition: breakpoints.h:42
int target_call_event_callbacks(struct target *target, enum target_event event)
Definition: target.c:1764
void target_free_all_working_areas(struct target *target)
Definition: target.c:2150
int target_halt(struct target *target)
Definition: target.c:507
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
Definition: target.c:352
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2342
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2662
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: target.c:2407
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
Definition: target.c:260
static int srst_asserted
Definition: target.c:2849
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
Definition: target.c:2574
bool target_has_event_action(const struct target *target, enum target_event event)
Returns true only if the target has a handler for the specified event.
Definition: target.c:4860
void target_handle_event(struct target *target, enum target_event e)
Definition: target.c:4667
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
Definition: target.c:316
int target_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
Definition: target.c:556
@ DBG_REASON_NOTHALTED
Definition: target.h:74
@ DBG_REASON_DBGRQ
Definition: target.h:69
@ DBG_REASON_SINGLESTEP
Definition: target.h:73
@ DBG_REASON_WATCHPOINT
Definition: target.h:71
@ DBG_REASON_BREAKPOINT
Definition: target.h:70
target_register_class
Definition: target.h:110
@ REG_CLASS_ALL
Definition: target.h:111
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:790
static bool target_was_examined(const struct target *target)
Definition: target.h:436
#define ERROR_TARGET_UNALIGNED_ACCESS
Definition: target.h:792
@ TARGET_EVENT_DEBUG_RESUMED
Definition: target.h:272
@ TARGET_EVENT_HALTED
Definition: target.h:252
@ TARGET_EVENT_RESUMED
Definition: target.h:253
@ TARGET_EVENT_DEBUG_HALTED
Definition: target.h:271
@ TARGET_EVENT_RESET_ASSERT
Definition: target.h:264
@ TARGET_RESET
Definition: target.h:57
@ TARGET_DEBUG_RUNNING
Definition: target.h:58
@ TARGET_UNKNOWN
Definition: target.h:54
@ TARGET_HALTED
Definition: target.h:56
@ TARGET_RUNNING
Definition: target.h:55
@ TARGET_LITTLE_ENDIAN
Definition: target.h:82
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:794
static void target_set_examined(struct target *target)
Sets the examined flag for the given target.
Definition: target.h:443
#define ERROR_TARGET_FAILURE
Definition: target.h:791
static void h_u32_to_be(uint8_t *buf, uint32_t val)
Definition: types.h:186
#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
#define TARGET_PRIxADDR
Definition: types.h:340
#define NULL
Definition: usb.h:16
uint8_t status[4]
Definition: vdebug.c:17