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  }
752 
753  return ERROR_OK;
754 }
755 
756 static int arc_exit_debug(struct target *target)
757 {
758  uint32_t value;
759  struct arc_common *arc = target_to_arc(target);
760 
761  /* Do read-modify-write sequence, or DEBUG.UB will be reset unintentionally. */
763  value |= SET_CORE_FORCE_HALT; /* set the HALT bit */
765  alive_sleep(1);
766 
769 
771  LOG_TARGET_DEBUG(target, "core stopped (halted) debug-reg: 0x%08" PRIx32, value);
773  LOG_TARGET_DEBUG(target, "core STATUS32: 0x%08" PRIx32, value);
774  }
775 
776  return ERROR_OK;
777 }
778 
779 static int arc_halt(struct target *target)
780 {
781  uint32_t value, irq_state;
782  struct arc_common *arc = target_to_arc(target);
783 
784  LOG_TARGET_DEBUG(target, "target->state: %s", target_state_name(target));
785 
786  if (target->state == TARGET_HALTED) {
787  LOG_TARGET_DEBUG(target, "target was already halted");
788  return ERROR_OK;
789  }
790 
791  if (target->state == TARGET_UNKNOWN)
792  LOG_TARGET_WARNING(target, "target was in unknown state when halt was requested");
793 
794  if (target->state == TARGET_RESET) {
796  LOG_TARGET_ERROR(target, "can't request a halt while in reset if nSRST pulls nTRST");
797  return ERROR_TARGET_FAILURE;
798  } else {
800  }
801  }
802 
803  /* Break (stop) processor.
804  * Do read-modify-write sequence, or DEBUG.UB will be reset unintentionally.
805  * We do not use here arc_get/set_core_reg functions here because they imply
806  * that the processor is already halted. */
808  value |= SET_CORE_FORCE_HALT; /* set the HALT bit */
810  alive_sleep(1);
811 
812  /* Save current IRQ state */
814 
816  arc->irq_state = 1;
817  else
818  arc->irq_state = 0;
819 
820  /* update state and notify gdb*/
823 
824  /* some more debug information */
826  LOG_TARGET_DEBUG(target, "core stopped (halted) DEGUB-REG: 0x%08" PRIx32, value);
827  CHECK_RETVAL(arc_get_register_value(target, "status32", &value));
828  LOG_TARGET_DEBUG(target, "core STATUS32: 0x%08" PRIx32, value);
829  }
830 
831  return ERROR_OK;
832 }
833 
840 static int arc_save_context(struct target *target)
841 {
842  int retval = ERROR_OK;
843  unsigned int i;
844  struct arc_common *arc = target_to_arc(target);
845  struct reg *reg_list = arc->core_and_aux_cache->reg_list;
846 
847  LOG_TARGET_DEBUG(target, "Saving aux and core registers values");
848  assert(reg_list);
849 
850  /* It is assumed that there is at least one AUX register in the list, for
851  * example PC. */
852  const uint32_t core_regs_size = arc->num_core_regs * sizeof(uint32_t);
853  /* last_general_reg is inclusive number. To get count of registers it is
854  * required to do +1. */
855  const uint32_t regs_to_scan =
856  MIN(arc->last_general_reg + 1, arc->num_regs);
857  const uint32_t aux_regs_size = arc->num_aux_regs * sizeof(uint32_t);
858  uint32_t *core_values = malloc(core_regs_size);
859  uint32_t *aux_values = malloc(aux_regs_size);
860  uint32_t *core_addrs = malloc(core_regs_size);
861  uint32_t *aux_addrs = malloc(aux_regs_size);
862  unsigned int core_cnt = 0;
863  unsigned int aux_cnt = 0;
864 
865  if (!core_values || !core_addrs || !aux_values || !aux_addrs) {
866  LOG_TARGET_ERROR(target, "Unable to allocate memory");
867  retval = ERROR_FAIL;
868  goto exit;
869  }
870 
871  memset(core_values, 0xff, core_regs_size);
872  memset(core_addrs, 0xff, core_regs_size);
873  memset(aux_values, 0xff, aux_regs_size);
874  memset(aux_addrs, 0xff, aux_regs_size);
875 
876  for (i = 0; i < MIN(arc->num_core_regs, regs_to_scan); i++) {
877  struct reg *reg = reg_list + i;
878  struct arc_reg_desc *arc_reg = reg->arch_info;
879  if (!reg->valid && reg->exist)
880  core_addrs[core_cnt++] = arc_reg->arch_num;
881  }
882 
883  for (i = arc->num_core_regs; i < regs_to_scan; i++) {
884  struct reg *reg = reg_list + i;
885  struct arc_reg_desc *arc_reg = reg->arch_info;
886  if (!reg->valid && reg->exist)
887  aux_addrs[aux_cnt++] = arc_reg->arch_num;
888  }
889 
890  /* Read data from target. */
891  if (core_cnt > 0) {
892  retval = arc_jtag_read_core_reg(&arc->jtag_info, core_addrs, core_cnt, core_values);
893  if (retval != ERROR_OK) {
894  LOG_TARGET_ERROR(target, "Attempt to read core registers failed");
895  retval = ERROR_FAIL;
896  goto exit;
897  }
898  }
899  if (aux_cnt > 0) {
900  retval = arc_jtag_read_aux_reg(&arc->jtag_info, aux_addrs, aux_cnt, aux_values);
901  if (retval != ERROR_OK) {
902  LOG_TARGET_ERROR(target, "Attempt to read aux registers failed");
903  retval = ERROR_FAIL;
904  goto exit;
905  }
906  }
907 
908  /* Parse core regs */
909  core_cnt = 0;
910  for (i = 0; i < MIN(arc->num_core_regs, regs_to_scan); i++) {
911  struct reg *reg = reg_list + i;
912  struct arc_reg_desc *arc_reg = reg->arch_info;
913  if (!reg->valid && reg->exist) {
914  target_buffer_set_u32(target, reg->value, core_values[core_cnt]);
915  reg->valid = true;
916  reg->dirty = false;
917  LOG_TARGET_DEBUG(target, "Get core register regnum=%u, name=%s, value=0x%08" PRIx32,
918  i, arc_reg->name, core_values[core_cnt]);
919  core_cnt++;
920  }
921  }
922 
923  /* Parse aux regs */
924  aux_cnt = 0;
925  for (i = arc->num_core_regs; i < regs_to_scan; i++) {
926  struct reg *reg = reg_list + i;
927  struct arc_reg_desc *arc_reg = reg->arch_info;
928  if (!reg->valid && reg->exist) {
929  target_buffer_set_u32(target, reg->value, aux_values[aux_cnt]);
930  reg->valid = true;
931  reg->dirty = false;
932  LOG_TARGET_DEBUG(target, "Get aux register regnum=%u, name=%s, value=0x%08" PRIx32,
933  i, arc_reg->name, aux_values[aux_cnt]);
934  aux_cnt++;
935  }
936  }
937 
938 exit:
939  free(core_values);
940  free(core_addrs);
941  free(aux_values);
942  free(aux_addrs);
943 
944  return retval;
945 }
946 
956  struct arc_actionpoint **actionpoint)
957 {
958  assert(target);
959  assert(actionpoint);
960 
961  uint32_t debug_ah;
962  /* Check if actionpoint caused halt */
963  CHECK_RETVAL(arc_reg_get_field(target, "debug", "ah",
964  &debug_ah));
965 
966  if (debug_ah) {
967  struct arc_common *arc = target_to_arc(target);
968  unsigned int ap;
969  uint32_t debug_asr;
971  "asr", &debug_asr));
972 
973  for (ap = 0; debug_asr > 1; debug_asr >>= 1)
974  ap += 1;
975 
976  assert(ap < arc->actionpoints_num);
977 
978  *actionpoint = &(arc->actionpoints_list[ap]);
979  } else {
980  *actionpoint = NULL;
981  }
982 
983  return ERROR_OK;
984 }
985 
987 {
988  uint32_t debug_bh;
989 
990  /* Only check for reason if don't know it already. */
991  /* BTW After singlestep at this point core is not marked as halted, so
992  * reading from memory to get current instruction wouldn't work anyway. */
995  return ERROR_OK;
996  }
997 
998  CHECK_RETVAL(arc_reg_get_field(target, "debug", "bh",
999  &debug_bh));
1000 
1001  if (debug_bh) {
1002  /* DEBUG.BH is set if core halted due to BRK instruction. */
1004  } else {
1005  struct arc_actionpoint *actionpoint = NULL;
1007 
1008  if (actionpoint) {
1009  if (!actionpoint->used)
1010  LOG_TARGET_WARNING(target, "Target halted by an unused actionpoint");
1011 
1012  if (actionpoint->type == ARC_AP_BREAKPOINT)
1014  else if (actionpoint->type == ARC_AP_WATCHPOINT)
1016  else
1017  LOG_TARGET_WARNING(target, "Unknown type of actionpoint");
1018  }
1019  }
1020 
1021  return ERROR_OK;
1022 }
1023 
1024 static int arc_debug_entry(struct target *target)
1025 {
1027 
1028  /* TODO: reset internal indicators of caches states, otherwise D$/I$
1029  * will not be flushed/invalidated when required. */
1032 
1033  return ERROR_OK;
1034 }
1035 
1036 static int arc_poll(struct target *target)
1037 {
1038  uint32_t status, value;
1039  struct arc_common *arc = target_to_arc(target);
1040 
1041  /* gdb calls continuously through this arc_poll() function */
1043 
1044  /* check for processor halted */
1045  if (status & ARC_JTAG_STAT_RU) {
1046  if (target->state != TARGET_RUNNING) {
1047  LOG_TARGET_WARNING(target, "target is still running");
1049  }
1050  return ERROR_OK;
1051  }
1052  /* In some cases JTAG status register indicates that
1053  * processor is in halt mode, but processor is still running.
1054  * We check halt bit of AUX STATUS32 register for setting correct state. */
1055  if ((target->state == TARGET_RUNNING) || (target->state == TARGET_RESET)) {
1056  CHECK_RETVAL(arc_get_register_value(target, "status32", &value));
1057  if (value & AUX_STATUS32_REG_HALT_BIT) {
1058  LOG_TARGET_DEBUG(target, "ARC core in halt or reset state");
1059  /* Save context if target was not in reset state */
1060  if (target->state == TARGET_RUNNING)
1064  } else {
1065  LOG_TARGET_DEBUG(target, "Discrepancy of STATUS32[0] HALT bit and ARC_JTAG_STAT_RU, "
1066  "target is still running");
1067  }
1068  } else if (target->state == TARGET_DEBUG_RUNNING) {
1070  LOG_TARGET_DEBUG(target, "ARC core is in debug running mode");
1071 
1073 
1075  }
1076 
1077  return ERROR_OK;
1078 }
1079 
1080 static int arc_assert_reset(struct target *target)
1081 {
1082  struct arc_common *arc = target_to_arc(target);
1084  bool srst_asserted = false;
1085 
1086  LOG_TARGET_DEBUG(target, "target->state: %s", target_state_name(target));
1087 
1089  /* allow scripts to override the reset event */
1090 
1093  /* An ARC target might be in halt state after reset, so
1094  * if script requested processor to resume, then it must
1095  * be manually started to ensure that this request
1096  * is satisfied. */
1097  if (target->state == TARGET_HALTED && !target->reset_halt) {
1098  /* Resume the target and continue from the current
1099  * PC register value. */
1100  LOG_TARGET_DEBUG(target, "Starting CPU execution after reset");
1101  CHECK_RETVAL(target_resume(target, true, 0, false, false));
1102  }
1104 
1105  return ERROR_OK;
1106  }
1107 
1108  /* some cores support connecting while srst is asserted
1109  * use that mode if it has been configured */
1112  jtag_add_reset(0, 1);
1113  srst_asserted = true;
1114  }
1115 
1117  /* should issue a srst only, but we may have to assert trst as well */
1119  jtag_add_reset(1, 1);
1120  else if (!srst_asserted)
1121  jtag_add_reset(0, 1);
1122  }
1123 
1125  jtag_add_sleep(50000);
1126 
1128 
1129  if (target->reset_halt)
1131 
1132  return ERROR_OK;
1133 }
1134 
1135 static int arc_deassert_reset(struct target *target)
1136 {
1137  LOG_TARGET_DEBUG(target, "target->state: %s", target_state_name(target));
1138 
1139  /* deassert reset lines */
1140  jtag_add_reset(0, 0);
1141 
1142  return ERROR_OK;
1143 }
1144 
1145 static int arc_arch_state(struct target *target)
1146 {
1147  uint32_t pc_value;
1148 
1150  return ERROR_OK;
1151 
1152  CHECK_RETVAL(arc_get_register_value(target, "pc", &pc_value));
1153 
1154  LOG_TARGET_DEBUG(target, "target state: %s; PC at: 0x%08" PRIx32,
1156  pc_value);
1157 
1158  return ERROR_OK;
1159 }
1160 
1166 static int arc_restore_context(struct target *target)
1167 {
1168  int retval = ERROR_OK;
1169  unsigned int i;
1170  struct arc_common *arc = target_to_arc(target);
1171  struct reg *reg_list = arc->core_and_aux_cache->reg_list;
1172 
1173  LOG_TARGET_DEBUG(target, "Restoring registers values");
1174  assert(reg_list);
1175 
1176  const uint32_t core_regs_size = arc->num_core_regs * sizeof(uint32_t);
1177  const uint32_t aux_regs_size = arc->num_aux_regs * sizeof(uint32_t);
1178  uint32_t *core_values = malloc(core_regs_size);
1179  uint32_t *aux_values = malloc(aux_regs_size);
1180  uint32_t *core_addrs = malloc(core_regs_size);
1181  uint32_t *aux_addrs = malloc(aux_regs_size);
1182  unsigned int core_cnt = 0;
1183  unsigned int aux_cnt = 0;
1184 
1185  if (!core_values || !core_addrs || !aux_values || !aux_addrs) {
1186  LOG_TARGET_ERROR(target, "Unable to allocate memory");
1187  retval = ERROR_FAIL;
1188  goto exit;
1189  }
1190 
1191  memset(core_values, 0xff, core_regs_size);
1192  memset(core_addrs, 0xff, core_regs_size);
1193  memset(aux_values, 0xff, aux_regs_size);
1194  memset(aux_addrs, 0xff, aux_regs_size);
1195 
1196  for (i = 0; i < arc->num_core_regs; i++) {
1197  struct reg *reg = &(reg_list[i]);
1198  struct arc_reg_desc *arc_reg = reg->arch_info;
1199  if (reg->valid && reg->exist && reg->dirty) {
1200  LOG_TARGET_DEBUG(target, "Will write regnum=%u", i);
1201  core_addrs[core_cnt] = arc_reg->arch_num;
1202  core_values[core_cnt] = target_buffer_get_u32(target, reg->value);
1203  core_cnt += 1;
1204  }
1205  }
1206 
1207  for (i = 0; i < arc->num_aux_regs; i++) {
1208  struct reg *reg = &(reg_list[arc->num_core_regs + i]);
1209  struct arc_reg_desc *arc_reg = reg->arch_info;
1210  if (reg->valid && reg->exist && reg->dirty) {
1211  LOG_TARGET_DEBUG(target, "Will write regnum=%lu", arc->num_core_regs + i);
1212  aux_addrs[aux_cnt] = arc_reg->arch_num;
1213  aux_values[aux_cnt] = target_buffer_get_u32(target, reg->value);
1214  aux_cnt += 1;
1215  }
1216  }
1217 
1218  /* Write data to target.
1219  * Check before write, if aux and core count is greater than 0. */
1220  if (core_cnt > 0) {
1221  retval = arc_jtag_write_core_reg(&arc->jtag_info, core_addrs, core_cnt, core_values);
1222  if (retval != ERROR_OK) {
1223  LOG_TARGET_ERROR(target, "Attempt to write to core registers failed");
1224  retval = ERROR_FAIL;
1225  goto exit;
1226  }
1227  }
1228 
1229  if (aux_cnt > 0) {
1230  retval = arc_jtag_write_aux_reg(&arc->jtag_info, aux_addrs, aux_cnt, aux_values);
1231  if (retval != ERROR_OK) {
1232  LOG_TARGET_ERROR(target, "Attempt to write to aux registers failed");
1233  retval = ERROR_FAIL;
1234  goto exit;
1235  }
1236  }
1237 
1238 exit:
1239  free(core_values);
1240  free(core_addrs);
1241  free(aux_values);
1242  free(aux_addrs);
1243 
1244  return retval;
1245 }
1246 
1247 static int arc_enable_interrupts(struct target *target, bool enable)
1248 {
1249  uint32_t value;
1250 
1251  struct arc_common *arc = target_to_arc(target);
1252 
1254 
1255  if (enable) {
1256  /* enable interrupts */
1257  value |= SET_CORE_ENABLE_INTERRUPTS;
1259  LOG_TARGET_DEBUG(target, "interrupts enabled");
1260  } else {
1261  /* disable interrupts */
1262  value &= ~SET_CORE_ENABLE_INTERRUPTS;
1264  LOG_TARGET_DEBUG(target, "interrupts disabled");
1265  }
1266 
1267  return ERROR_OK;
1268 }
1269 
1270 static int arc_resume(struct target *target, bool current, target_addr_t address,
1271  bool handle_breakpoints, bool debug_execution)
1272 {
1273  struct arc_common *arc = target_to_arc(target);
1274  uint32_t resume_pc = 0;
1275  uint32_t value;
1276  struct reg *pc = &arc->core_and_aux_cache->reg_list[arc->pc_index_in_cache];
1277 
1278  LOG_TARGET_DEBUG(target, "current:%i, address:0x%08" TARGET_PRIxADDR ", handle_breakpoints:%i,"
1279  " debug_execution:%i", current, address, handle_breakpoints, debug_execution);
1280 
1281  /* We need to reset ARC cache variables so caches
1282  * would be invalidated and actual data
1283  * would be fetched from memory. */
1285 
1286  if (target->state != TARGET_HALTED) {
1287  LOG_TARGET_ERROR(target, "not halted");
1288  return ERROR_TARGET_NOT_HALTED;
1289  }
1290 
1291  if (!debug_execution) {
1292  /* (gdb) continue = execute until we hit break/watch-point */
1296  }
1297 
1298  /* current = true: continue on current PC, otherwise continue at <address> */
1299  if (!current) {
1301  pc->dirty = true;
1302  pc->valid = true;
1303  LOG_TARGET_DEBUG(target, "Changing the value of current PC to 0x%08" TARGET_PRIxADDR, address);
1304  }
1305 
1306  if (!current)
1307  resume_pc = address;
1308  else
1309  resume_pc = target_buffer_get_u32(target, pc->value);
1310 
1312 
1313  LOG_TARGET_DEBUG(target, "Target resumes from PC=0x%" PRIx32 ", pc.dirty=%i, pc.valid=%i",
1314  resume_pc, pc->dirty, pc->valid);
1315 
1316  /* check if GDB tells to set our PC where to continue from */
1317  if (pc->valid && resume_pc == target_buffer_get_u32(target, pc->value)) {
1319  LOG_TARGET_DEBUG(target, "resume Core (when start-core) with PC @:0x%08" PRIx32, value);
1321  }
1322 
1323  /* the front-end may request us not to handle breakpoints here */
1324  if (handle_breakpoints) {
1325  /* Single step past breakpoint at current address */
1326  struct breakpoint *breakpoint = breakpoint_find(target, resume_pc);
1327  if (breakpoint) {
1328  LOG_TARGET_DEBUG(target, "skipping past breakpoint at 0x%08" TARGET_PRIxADDR,
1329  breakpoint->address);
1333  }
1334  }
1335 
1336  /* Restore IRQ state if not in debug_execution*/
1337  if (!debug_execution)
1339  else
1340  CHECK_RETVAL(arc_enable_interrupts(target, !debug_execution));
1341 
1343 
1344  /* ready to get us going again */
1347  value &= ~SET_CORE_HALT_BIT; /* clear the HALT bit */
1349  LOG_TARGET_DEBUG(target, "Core started to run");
1350 
1351  /* registers are now invalid */
1353 
1354  if (!debug_execution) {
1357  LOG_TARGET_DEBUG(target, "target resumed at 0x%08" PRIx32, resume_pc);
1358  } else {
1361  LOG_TARGET_DEBUG(target, "target debug resumed at 0x%08" PRIx32, resume_pc);
1362  }
1363 
1364  return ERROR_OK;
1365 }
1366 
1367 static int arc_init_target(struct command_context *cmd_ctx, struct target *target)
1368 {
1372  return ERROR_OK;
1373 }
1374 
1375 static void arc_free_reg_cache(struct reg_cache *cache)
1376 {
1377  free(cache->reg_list);
1378  free(cache);
1379 }
1380 
1381 static void arc_deinit_target(struct target *target)
1382 {
1383  struct arc_common *arc = target_to_arc(target);
1384 
1385  LOG_TARGET_DEBUG(target, "deinitialization of target");
1386  if (arc->core_aux_cache_built)
1388  if (arc->bcr_cache_built)
1390 
1391  struct arc_reg_data_type *type, *n;
1392  struct arc_reg_desc *desc, *k;
1393 
1394  /* Free arc-specific reg_data_types allocations*/
1396  if (type->data_type.type_class == REG_TYPE_CLASS_STRUCT) {
1397  free(type->reg_type_struct_field);
1398  free(type->bitfields);
1399  free(type);
1400  } else if (type->data_type.type_class == REG_TYPE_CLASS_FLAGS) {
1401  free(type->reg_type_flags_field);
1402  free(type->bitfields);
1403  free(type);
1404  }
1405  }
1406 
1407  /* Free standard_gdb_types reg_data_types allocations */
1409  free(type);
1410 
1412  free_reg_desc(desc);
1413 
1415  free_reg_desc(desc);
1416 
1418  free_reg_desc(desc);
1419 
1420  free(arc->actionpoints_list);
1421  free(arc);
1422 }
1423 
1424 
1425 static int arc_target_create(struct target *target)
1426 {
1427  struct arc_common *arc = calloc(1, sizeof(*arc));
1428 
1429  if (!arc) {
1430  LOG_TARGET_ERROR(target, "Unable to allocate memory");
1431  return ERROR_FAIL;
1432  }
1433 
1434  LOG_TARGET_DEBUG(target, "Entering");
1436 
1437  return ERROR_OK;
1438 }
1439 
1446 static int arc_write_instruction_u32(struct target *target, uint32_t address,
1447  uint32_t instr)
1448 {
1449  uint8_t value_buf[4];
1450  if (!target_was_examined(target)) {
1451  LOG_TARGET_ERROR(target, "Target not examined yet");
1452  return ERROR_FAIL;
1453  }
1454 
1455  LOG_TARGET_DEBUG(target, "Address: 0x%08" PRIx32 ", value: 0x%08" PRIx32, address,
1456  instr);
1457 
1459  arc_h_u32_to_me(value_buf, instr);
1460  else
1461  h_u32_to_be(value_buf, instr);
1462 
1464 
1465  return ERROR_OK;
1466 }
1467 
1473 static int arc_read_instruction_u32(struct target *target, uint32_t address,
1474  uint32_t *value)
1475 {
1476  uint8_t value_buf[4];
1477 
1478  if (!target_was_examined(target)) {
1479  LOG_TARGET_ERROR(target, "Target not examined yet");
1480  return ERROR_FAIL;
1481  }
1482 
1483  *value = 0;
1484  CHECK_RETVAL(target_read_buffer(target, address, 4, value_buf));
1485 
1487  *value = arc_me_to_h_u32(value_buf);
1488  else
1489  *value = be_to_h_u32(value_buf);
1490 
1491  LOG_TARGET_DEBUG(target, "Address: 0x%08" PRIx32 ", value: 0x%08" PRIx32, address,
1492  *value);
1493 
1494  return ERROR_OK;
1495 }
1496 
1497 /* Actionpoint mechanism allows to setup HW breakpoints
1498  * and watchpoints. Each actionpoint is controlled by
1499  * 3 aux registers: Actionpoint(AP) match mask(AP_AMM), AP match value(AP_AMV)
1500  * and AP control(AC).
1501  * This function is for setting/unsetting actionpoints:
1502  * at - actionpoint target: trigger on mem/reg access
1503  * tt - transaction type : trigger on r/w. */
1504 static int arc_configure_actionpoint(struct target *target, uint32_t ap_num,
1505  uint32_t match_value, uint32_t control_tt, uint32_t control_at)
1506 {
1507  struct arc_common *arc = target_to_arc(target);
1508 
1509  if (control_tt != AP_AC_TT_DISABLE) {
1510 
1511  if (arc->actionpoints_num_avail < 1) {
1512  LOG_TARGET_ERROR(target, "No free actionpoints, maximum amount is %u",
1513  arc->actionpoints_num);
1515  }
1516 
1517  /* Names of register to set - 24 chars should be enough. Looks a little
1518  * bit out-of-place for C code, but makes it aligned to the bigger
1519  * concept of "ARC registers are defined in TCL" as far as possible.
1520  */
1521  char ap_amv_reg_name[24], ap_amm_reg_name[24], ap_ac_reg_name[24];
1522  snprintf(ap_amv_reg_name, 24, "ap_amv%" PRIu32, ap_num);
1523  snprintf(ap_amm_reg_name, 24, "ap_amm%" PRIu32, ap_num);
1524  snprintf(ap_ac_reg_name, 24, "ap_ac%" PRIu32, ap_num);
1525  CHECK_RETVAL(arc_set_register_value(target, ap_amv_reg_name,
1526  match_value));
1527  CHECK_RETVAL(arc_set_register_value(target, ap_amm_reg_name, 0));
1528  CHECK_RETVAL(arc_set_register_value(target, ap_ac_reg_name,
1529  control_tt | control_at));
1530  arc->actionpoints_num_avail--;
1531  } else {
1532  char ap_ac_reg_name[24];
1533  snprintf(ap_ac_reg_name, 24, "ap_ac%" PRIu32, ap_num);
1534  CHECK_RETVAL(arc_set_register_value(target, ap_ac_reg_name,
1535  AP_AC_TT_DISABLE));
1536  arc->actionpoints_num_avail++;
1537  }
1538 
1539  return ERROR_OK;
1540 }
1541 
1542 static int arc_set_breakpoint(struct target *target,
1543  struct breakpoint *breakpoint)
1544 {
1545  if (breakpoint->is_set) {
1546  LOG_TARGET_WARNING(target, "breakpoint already set");
1547  return ERROR_OK;
1548  }
1549 
1550  if (breakpoint->type == BKPT_SOFT) {
1551  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32, breakpoint->unique_id);
1552 
1553  if (breakpoint->length == 4) {
1554  uint32_t verify = 0xffffffff;
1555 
1558 
1560  ARC_SDBBP_32));
1561 
1563 
1564  if (verify != ARC_SDBBP_32) {
1565  LOG_TARGET_ERROR(target, "Unable to set 32bit breakpoint at address @0x%" TARGET_PRIxADDR
1566  " - check that memory is read/writable", breakpoint->address);
1567  return ERROR_FAIL;
1568  }
1569  } else if (breakpoint->length == 2) {
1570  uint16_t verify = 0xffff;
1571 
1575 
1577  if (verify != ARC_SDBBP_16) {
1578  LOG_TARGET_ERROR(target, "Unable to set 16bit breakpoint at address @0x%" TARGET_PRIxADDR
1579  " - check that memory is read/writable", breakpoint->address);
1580  return ERROR_FAIL;
1581  }
1582  } else {
1583  LOG_TARGET_ERROR(target, "Invalid breakpoint length: target supports only 2 or 4");
1585  }
1586 
1587  breakpoint->is_set = true;
1588  } else if (breakpoint->type == BKPT_HARD) {
1589  struct arc_common *arc = target_to_arc(target);
1590  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1591  unsigned int bp_num;
1592 
1593  for (bp_num = 0; bp_num < arc->actionpoints_num; bp_num++) {
1594  if (!ap_list[bp_num].used)
1595  break;
1596  }
1597 
1598  if (bp_num >= arc->actionpoints_num) {
1599  LOG_TARGET_ERROR(target, "No free actionpoints, maximum amount is %u",
1600  arc->actionpoints_num);
1602  }
1603 
1604  int retval = arc_configure_actionpoint(target, bp_num,
1606 
1607  if (retval == ERROR_OK) {
1608  breakpoint_hw_set(breakpoint, bp_num);
1609  ap_list[bp_num].used = 1;
1610  ap_list[bp_num].bp_value = breakpoint->address;
1611  ap_list[bp_num].type = ARC_AP_BREAKPOINT;
1612 
1613  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32 ", bp_num %u bp_value 0x%" PRIx32,
1614  breakpoint->unique_id, bp_num, ap_list[bp_num].bp_value);
1615  }
1616 
1617  } else {
1618  LOG_TARGET_ERROR(target, "setting unknown breakpoint type");
1619  return ERROR_FAIL;
1620  }
1621 
1622  return ERROR_OK;
1623 }
1624 
1626  struct breakpoint *breakpoint)
1627 {
1628  int retval = ERROR_OK;
1629 
1630  if (!breakpoint->is_set) {
1631  LOG_TARGET_WARNING(target, "breakpoint not set");
1632  return ERROR_OK;
1633  }
1634 
1635  if (breakpoint->type == BKPT_SOFT) {
1636  /* restore original instruction (kept in target endianness) */
1637  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32, breakpoint->unique_id);
1638  if (breakpoint->length == 4) {
1639  uint32_t current_instr;
1640 
1641  /* check that user program has not modified breakpoint instruction */
1643 
1644  if (current_instr == ARC_SDBBP_32) {
1647  if (retval != ERROR_OK)
1648  return retval;
1649  } else {
1650  LOG_TARGET_WARNING(target, "Software breakpoint @0x%" TARGET_PRIxADDR
1651  " has been overwritten outside of debugger."
1652  "Expected: @0x%x, got: @0x%" PRIx32,
1653  breakpoint->address, ARC_SDBBP_32, current_instr);
1654  }
1655  } else if (breakpoint->length == 2) {
1656  uint16_t current_instr;
1657 
1658  /* check that user program has not modified breakpoint instruction */
1660  if (current_instr == ARC_SDBBP_16) {
1663  if (retval != ERROR_OK)
1664  return retval;
1665  } else {
1666  LOG_TARGET_WARNING(target, "Software breakpoint @0x%" TARGET_PRIxADDR
1667  " has been overwritten outside of debugger. "
1668  "Expected: 0x%04x, got: 0x%04" PRIx16,
1669  breakpoint->address, ARC_SDBBP_16, current_instr);
1670  }
1671  } else {
1672  LOG_TARGET_ERROR(target, "Invalid breakpoint length: target supports only 2 or 4");
1674  }
1675  breakpoint->is_set = false;
1676 
1677  } else if (breakpoint->type == BKPT_HARD) {
1678  struct arc_common *arc = target_to_arc(target);
1679  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1680  unsigned int bp_num = breakpoint->number;
1681 
1682  if (bp_num >= arc->actionpoints_num) {
1683  LOG_TARGET_DEBUG(target, "Invalid actionpoint ID: %u in breakpoint: %" PRIu32,
1684  bp_num, breakpoint->unique_id);
1685  return ERROR_OK;
1686  }
1687 
1688  retval = arc_configure_actionpoint(target, bp_num,
1690 
1691  if (retval == ERROR_OK) {
1692  breakpoint->is_set = false;
1693  ap_list[bp_num].used = 0;
1694  ap_list[bp_num].bp_value = 0;
1695 
1696  LOG_TARGET_DEBUG(target, "bpid: %" PRIu32 " - released actionpoint ID: %u",
1697  breakpoint->unique_id, bp_num);
1698  }
1699  } else {
1700  LOG_TARGET_ERROR(target, "unsetting unknown breakpoint type");
1701  return ERROR_FAIL;
1702  }
1703 
1704  return retval;
1705 }
1706 
1708 {
1710 
1711  /* set any pending breakpoints */
1712  while (breakpoint) {
1713  if (!breakpoint->is_set)
1716  }
1717 
1718  return ERROR_OK;
1719 }
1720 
1722 {
1723  if (target->state == TARGET_HALTED) {
1725 
1726  } else {
1727  LOG_TARGET_ERROR(target, "not halted (add breakpoint)");
1728  return ERROR_TARGET_NOT_HALTED;
1729  }
1730 }
1731 
1733  struct breakpoint *breakpoint)
1734 {
1735  if (target->state == TARGET_HALTED) {
1736  if (breakpoint->is_set)
1738  } else {
1739  LOG_TARGET_ERROR(target, "not halted (remove breakpoint)");
1740  return ERROR_TARGET_NOT_HALTED;
1741  }
1742 
1743  return ERROR_OK;
1744 }
1745 
1747 {
1748  struct arc_common *arc = target_to_arc(target);
1749  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1750  struct breakpoint *next_b;
1751  struct watchpoint *next_w;
1752 
1753  while (target->breakpoints) {
1754  next_b = target->breakpoints->next;
1756  free(target->breakpoints->orig_instr);
1757  free(target->breakpoints);
1758  target->breakpoints = next_b;
1759  }
1760  while (target->watchpoints) {
1761  next_w = target->watchpoints->next;
1763  free(target->watchpoints);
1764  target->watchpoints = next_w;
1765  }
1766  for (unsigned int i = 0; i < arc->actionpoints_num; i++) {
1767  if ((ap_list[i].used) && (ap_list[i].reg_address))
1768  arc_remove_auxreg_actionpoint(target, ap_list[i].reg_address);
1769  }
1770 }
1771 
1772 int arc_set_actionpoints_num(struct target *target, uint32_t ap_num)
1773 {
1774  LOG_TARGET_DEBUG(target, "actionpoints=%" PRIu32, ap_num);
1775  struct arc_common *arc = target_to_arc(target);
1776 
1777  /* Make sure that there are no enabled actionpoints in target. */
1779 
1780  /* Assume that all points have been removed from target. */
1781  free(arc->actionpoints_list);
1782 
1783  arc->actionpoints_num_avail = ap_num;
1784  arc->actionpoints_num = ap_num;
1785  /* calloc can be safely called when ncount == 0. */
1786  arc->actionpoints_list = calloc(ap_num, sizeof(struct arc_actionpoint));
1787 
1788  if (!arc->actionpoints_list) {
1789  LOG_TARGET_ERROR(target, "Unable to allocate memory");
1790  return ERROR_FAIL;
1791  }
1792  return ERROR_OK;
1793 }
1794 
1795 
1797  uint32_t auxreg_addr, uint32_t transaction)
1798 {
1799  unsigned int ap_num = 0;
1800  int retval = ERROR_OK;
1801 
1802  if (target->state != TARGET_HALTED)
1803  return ERROR_TARGET_NOT_HALTED;
1804 
1805  struct arc_common *arc = target_to_arc(target);
1806  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1807 
1808  while (ap_list[ap_num].used)
1809  ap_num++;
1810 
1811  if (ap_num >= arc->actionpoints_num) {
1812  LOG_TARGET_ERROR(target, "No actionpoint free, maximum amount is %u",
1813  arc->actionpoints_num);
1815  }
1816 
1817  retval = arc_configure_actionpoint(target, ap_num,
1818  auxreg_addr, transaction, AP_AC_AT_AUXREG_ADDR);
1819 
1820  if (retval == ERROR_OK) {
1821  ap_list[ap_num].used = 1;
1822  ap_list[ap_num].reg_address = auxreg_addr;
1823  }
1824 
1825  return retval;
1826 }
1827 
1828 int arc_remove_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr)
1829 {
1830  int retval = ERROR_OK;
1831  bool ap_found = false;
1832  unsigned int ap_num = 0;
1833 
1834  if (target->state != TARGET_HALTED)
1835  return ERROR_TARGET_NOT_HALTED;
1836 
1837  struct arc_common *arc = target_to_arc(target);
1838  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1839 
1840  while ((ap_list[ap_num].used) && (ap_num < arc->actionpoints_num)) {
1841  if (ap_list[ap_num].reg_address == auxreg_addr) {
1842  ap_found = true;
1843  break;
1844  }
1845  ap_num++;
1846  }
1847 
1848  if (ap_found) {
1849  retval = arc_configure_actionpoint(target, ap_num,
1850  auxreg_addr, AP_AC_TT_DISABLE, AP_AC_AT_AUXREG_ADDR);
1851 
1852  if (retval == ERROR_OK) {
1853  ap_list[ap_num].used = 0;
1854  ap_list[ap_num].bp_value = 0;
1855  }
1856  } else {
1857  LOG_TARGET_ERROR(target, "Register actionpoint not found");
1858  }
1859  return retval;
1860 }
1861 
1862 
1863 static int arc_set_watchpoint(struct target *target,
1864  struct watchpoint *watchpoint)
1865 {
1866  unsigned int wp_num;
1867  struct arc_common *arc = target_to_arc(target);
1868  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1869 
1870  if (watchpoint->is_set) {
1871  LOG_TARGET_WARNING(target, "watchpoint already set");
1872  return ERROR_OK;
1873  }
1874 
1875  for (wp_num = 0; wp_num < arc->actionpoints_num; wp_num++) {
1876  if (!ap_list[wp_num].used)
1877  break;
1878  }
1879 
1880  if (wp_num >= arc->actionpoints_num) {
1881  LOG_TARGET_ERROR(target, "No free actionpoints, maximum amount is %u",
1882  arc->actionpoints_num);
1884  }
1885 
1886  if (watchpoint->length != 4) {
1887  LOG_TARGET_ERROR(target, "Only watchpoints of length 4 are supported");
1889  }
1890 
1891  int enable = AP_AC_TT_DISABLE;
1892  switch (watchpoint->rw) {
1893  case WPT_READ:
1894  enable = AP_AC_TT_READ;
1895  break;
1896  case WPT_WRITE:
1897  enable = AP_AC_TT_WRITE;
1898  break;
1899  case WPT_ACCESS:
1900  enable = AP_AC_TT_READWRITE;
1901  break;
1902  default:
1903  LOG_TARGET_ERROR(target, "BUG: watchpoint->rw neither read, write nor access");
1904  return ERROR_FAIL;
1905  }
1906 
1907  int retval = arc_configure_actionpoint(target, wp_num,
1909 
1910  if (retval == ERROR_OK) {
1911  watchpoint_set(watchpoint, wp_num);
1912  ap_list[wp_num].used = 1;
1913  ap_list[wp_num].bp_value = watchpoint->address;
1914  ap_list[wp_num].type = ARC_AP_WATCHPOINT;
1915 
1916  LOG_TARGET_DEBUG(target, "wpid: %" PRIu32 ", wp_num %u wp_value 0x%" PRIx32,
1917  watchpoint->unique_id, wp_num, ap_list[wp_num].bp_value);
1918  }
1919 
1920  return retval;
1921 }
1922 
1924  struct watchpoint *watchpoint)
1925 {
1926  /* get pointers to arch-specific information */
1927  struct arc_common *arc = target_to_arc(target);
1928  struct arc_actionpoint *ap_list = arc->actionpoints_list;
1929 
1930  if (!watchpoint->is_set) {
1931  LOG_TARGET_WARNING(target, "watchpoint not set");
1932  return ERROR_OK;
1933  }
1934 
1935  unsigned int wp_num = watchpoint->number;
1936  if (wp_num >= arc->actionpoints_num) {
1937  LOG_TARGET_DEBUG(target, "Invalid actionpoint ID: %u in watchpoint: %" PRIu32,
1938  wp_num, watchpoint->unique_id);
1939  return ERROR_OK;
1940  }
1941 
1942  int retval = arc_configure_actionpoint(target, wp_num,
1944 
1945  if (retval == ERROR_OK) {
1946  watchpoint->is_set = false;
1947  ap_list[wp_num].used = 0;
1948  ap_list[wp_num].bp_value = 0;
1949 
1950  LOG_TARGET_DEBUG(target, "wpid: %" PRIu32 " - releasing actionpoint ID: %u",
1951  watchpoint->unique_id, wp_num);
1952  }
1953 
1954  return retval;
1955 }
1956 
1958 {
1960 
1961  /* set any pending watchpoints */
1962  while (watchpoint) {
1963  if (!watchpoint->is_set)
1966  }
1967 
1968  return ERROR_OK;
1969 }
1970 
1971 static int arc_add_watchpoint(struct target *target,
1972  struct watchpoint *watchpoint)
1973 {
1974  if (target->state != TARGET_HALTED) {
1975  LOG_TARGET_ERROR(target, "not halted");
1976  return ERROR_TARGET_NOT_HALTED;
1977  }
1978 
1980 
1981  return ERROR_OK;
1982 }
1983 
1985  struct watchpoint *watchpoint)
1986 {
1987  if (target->state != TARGET_HALTED) {
1988  LOG_TARGET_ERROR(target, "not halted");
1989  return ERROR_TARGET_NOT_HALTED;
1990  }
1991 
1992  if (watchpoint->is_set)
1994 
1995  return ERROR_OK;
1996 }
1997 
1998 static int arc_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
1999 {
2000  assert(target);
2001  assert(hit_watchpoint);
2002 
2003  struct arc_actionpoint *actionpoint = NULL;
2005 
2006  if (actionpoint) {
2007  if (!actionpoint->used)
2008  LOG_TARGET_WARNING(target, "Target halted by unused actionpoint");
2009 
2010  /* If this check fails - that is some sort of an error in OpenOCD. */
2011  if (actionpoint->type != ARC_AP_WATCHPOINT)
2012  LOG_TARGET_WARNING(target, "Target halted by breakpoint, but is treated as a watchpoint");
2013 
2014  for (struct watchpoint *watchpoint = target->watchpoints;
2015  watchpoint;
2016  watchpoint = watchpoint->next) {
2017  if (actionpoint->bp_value == watchpoint->address) {
2018  *hit_watchpoint = watchpoint;
2019  LOG_TARGET_DEBUG(target, "Hit watchpoint, wpid: %" PRIu32 ", watchpoint num: %u",
2021  return ERROR_OK;
2022  }
2023  }
2024  }
2025 
2026  return ERROR_FAIL;
2027 }
2028 
2029 /* Helper function which switches core to single_step mode by
2030  * doing aux r/w operations. */
2031 static int arc_config_step(struct target *target, bool enable_step)
2032 {
2033  uint32_t value;
2034 
2035  struct arc_common *arc = target_to_arc(target);
2036 
2037  /* enable core debug step mode */
2038  if (enable_step) {
2040  &value));
2041  value &= ~SET_CORE_AE_BIT; /* clear the AE bit */
2043  value));
2044  LOG_TARGET_DEBUG(target, " [status32:0x%08" PRIx32 "]", value);
2045 
2046  /* Doing read-modify-write, because DEBUG might contain manually set
2047  * bits like UB or ED, which should be preserved. */
2049  AUX_DEBUG_REG, &value));
2050  value |= SET_CORE_SINGLE_INSTR_STEP; /* set the IS bit */
2052  value));
2053  LOG_TARGET_DEBUG(target, "core debug step mode enabled [debug-reg:0x%08" PRIx32 "]", value);
2054 
2055  } else { /* disable core debug step mode */
2057  &value));
2058  value &= ~SET_CORE_SINGLE_INSTR_STEP; /* clear the IS bit */
2060  value));
2061  LOG_TARGET_DEBUG(target, "core debug step mode disabled");
2062  }
2063 
2064  return ERROR_OK;
2065 }
2066 
2068 {
2070 
2071  /* disable interrupts while stepping */
2073 
2074  /* configure single step mode */
2076 
2077  /* exit debug mode */
2079 
2080  return ERROR_OK;
2081 }
2082 
2083 static int arc_step(struct target *target, bool current, target_addr_t address,
2084  bool handle_breakpoints)
2085 {
2086  /* get pointers to arch-specific information */
2087  struct arc_common *arc = target_to_arc(target);
2088  struct breakpoint *breakpoint = NULL;
2089  struct reg *pc = &(arc->core_and_aux_cache->reg_list[arc->pc_index_in_cache]);
2090 
2091  if (target->state != TARGET_HALTED) {
2092  LOG_TARGET_ERROR(target, "not halted");
2093  return ERROR_TARGET_NOT_HALTED;
2094  }
2095 
2096  /* current = true: continue on current pc, otherwise continue at <address> */
2097  if (!current) {
2098  buf_set_u32(pc->value, 0, 32, address);
2099  pc->dirty = true;
2100  pc->valid = true;
2101  }
2102 
2103  LOG_TARGET_DEBUG(target, "Target steps one instruction from PC=0x%" PRIx32,
2104  buf_get_u32(pc->value, 0, 32));
2105 
2106  /* the front-end may request us not to handle breakpoints */
2107  if (handle_breakpoints) {
2109  if (breakpoint)
2111  }
2112 
2113  /* restore context */
2115 
2117 
2119 
2120  /* disable interrupts while stepping */
2122 
2123  /* do a single step */
2125 
2126  /* make sure we done our step */
2127  alive_sleep(1);
2128 
2129  /* registers are now invalid */
2131 
2132  if (breakpoint)
2134 
2135  LOG_TARGET_DEBUG(target, "target stepped");
2136 
2138 
2139  /* Saving context */
2142 
2143  return ERROR_OK;
2144 }
2145 
2146 
2147 /* This function invalidates icache. */
2149 {
2150  uint32_t value;
2151 
2152  struct arc_common *arc = target_to_arc(target);
2153 
2154  /* Don't waste time if already done. */
2155  if (!arc->has_icache || arc->icache_invalidated)
2156  return ERROR_OK;
2157 
2158  LOG_TARGET_DEBUG(target, "Invalidating I$");
2159 
2160  value = IC_IVIC_INVALIDATE; /* invalidate I$ */
2162 
2163  arc->icache_invalidated = true;
2164 
2165  return ERROR_OK;
2166 }
2167 
2168 /* This function invalidates dcache */
2170 {
2171  uint32_t value, dc_ctrl_value;
2172 
2173  struct arc_common *arc = target_to_arc(target);
2174 
2175  if (!arc->has_dcache || arc->dcache_invalidated)
2176  return ERROR_OK;
2177 
2178  LOG_TARGET_DEBUG(target, "Invalidating D$");
2179 
2181  dc_ctrl_value = value;
2182  value &= ~DC_CTRL_IM;
2183 
2184  /* set DC_CTRL invalidate mode to invalidate-only (no flushing!!) */
2186  value = DC_IVDC_INVALIDATE; /* invalidate D$ */
2188 
2189  /* restore DC_CTRL invalidate mode */
2191 
2192  arc->dcache_invalidated = true;
2193 
2194  return ERROR_OK;
2195 }
2196 
2197 /* This function invalidates l2 cache. */
2199 {
2200  uint32_t value, slc_ctrl_value;
2201 
2202  struct arc_common *arc = target_to_arc(target);
2203 
2204  if (!arc->has_l2cache || arc->l2cache_invalidated)
2205  return ERROR_OK;
2206 
2207  LOG_TARGET_DEBUG(target, "Invalidating L2$");
2208 
2210  slc_ctrl_value = value;
2211  value &= ~L2_CTRL_IM;
2212 
2213  /* set L2_CTRL invalidate mode to invalidate-only (no flushing!!) */
2215  /* invalidate L2$ */
2217 
2218  /* Wait until invalidate operation ends */
2219  do {
2220  LOG_TARGET_DEBUG(target, "Waiting for invalidation end");
2222  } while (value & L2_CTRL_BS);
2223 
2224  /* restore L2_CTRL invalidate mode */
2226 
2227  arc->l2cache_invalidated = true;
2228 
2229  return ERROR_OK;
2230 }
2231 
2232 
2234 {
2238 
2239  return ERROR_OK;
2240 }
2241 
2242 /* Flush data cache. This function is cheap to call and return quickly if D$
2243  * already has been flushed since target had been halted. JTAG debugger reads
2244  * values directly from memory, bypassing cache, so if there are unflushed
2245  * lines debugger will read invalid values, which will cause a lot of troubles.
2246  * */
2247 static int arc_dcache_flush(struct target *target)
2248 {
2249  uint32_t value, dc_ctrl_value;
2250  bool has_to_set_dc_ctrl_im;
2251 
2252  struct arc_common *arc = target_to_arc(target);
2253 
2254  /* Don't waste time if already done. */
2255  if (!arc->has_dcache || arc->dcache_flushed)
2256  return ERROR_OK;
2257 
2258  LOG_TARGET_DEBUG(target, "Flushing D$");
2259 
2260  /* Store current value of DC_CTRL */
2262 
2263  /* Set DC_CTRL invalidate mode to flush (if not already set) */
2264  has_to_set_dc_ctrl_im = (dc_ctrl_value & DC_CTRL_IM) == 0;
2265  if (has_to_set_dc_ctrl_im) {
2266  value = dc_ctrl_value | DC_CTRL_IM;
2268  }
2269 
2270  /* Flush D$ */
2271  value = DC_IVDC_INVALIDATE;
2273 
2274  /* Restore DC_CTRL invalidate mode (even of flush failed) */
2275  if (has_to_set_dc_ctrl_im)
2277 
2278  arc->dcache_flushed = true;
2279 
2280  return ERROR_OK;
2281 }
2282 
2283 /* This function flushes l2cache. */
2284 static int arc_l2cache_flush(struct target *target)
2285 {
2286  uint32_t value;
2287 
2288  struct arc_common *arc = target_to_arc(target);
2289 
2290  /* Don't waste time if already done. */
2291  if (!arc->has_l2cache || arc->l2cache_flushed)
2292  return ERROR_OK;
2293 
2294  LOG_TARGET_DEBUG(target, "Flushing L2$");
2295 
2296  /* Flush L2 cache */
2298 
2299  /* Wait until flush operation ends */
2300  do {
2301  LOG_TARGET_DEBUG(target, "Waiting for flushing end");
2303  } while (value & L2_CTRL_BS);
2304 
2305  arc->l2cache_flushed = true;
2306 
2307  return ERROR_OK;
2308 }
2309 
2311 {
2314 
2315  return ERROR_OK;
2316 }
2317 
2318 /* ARC v2 target */
2319 struct target_type arcv2_target = {
2320  .name = "arcv2",
2321 
2322  .poll = arc_poll,
2323 
2324  .arch_state = arc_arch_state,
2325 
2326  /* TODO That seems like something similar to metaware hostlink, so perhaps
2327  * we can exploit this in the future. */
2328  .target_request_data = NULL,
2329 
2330  .halt = arc_halt,
2331  .resume = arc_resume,
2332  .step = arc_step,
2333 
2334  .assert_reset = arc_assert_reset,
2335  .deassert_reset = arc_deassert_reset,
2336 
2337  /* TODO Implement soft_reset_halt */
2338  .soft_reset_halt = NULL,
2339 
2340  .get_gdb_reg_list = arc_get_gdb_reg_list,
2341 
2342  .read_memory = arc_mem_read,
2343  .write_memory = arc_mem_write,
2344  .checksum_memory = NULL,
2345  .blank_check_memory = NULL,
2346 
2347  .add_breakpoint = arc_add_breakpoint,
2348  .add_context_breakpoint = NULL,
2349  .add_hybrid_breakpoint = NULL,
2350  .remove_breakpoint = arc_remove_breakpoint,
2351  .add_watchpoint = arc_add_watchpoint,
2352  .remove_watchpoint = arc_remove_watchpoint,
2353  .hit_watchpoint = arc_hit_watchpoint,
2354 
2355  .run_algorithm = NULL,
2356  .start_algorithm = NULL,
2357  .wait_algorithm = NULL,
2358 
2359  .commands = arc_monitor_command_handlers,
2360 
2361  .target_create = arc_target_create,
2362  .init_target = arc_init_target,
2363  .deinit_target = arc_deinit_target,
2364  .examine = arc_examine,
2365 
2366  .virt2phys = NULL,
2367  .read_phys_memory = NULL,
2368  .write_phys_memory = NULL,
2369  .mmu = NULL,
2370 };
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:1166
static int arc_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Definition: arc.c:2083
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:1504
static int arc_save_context(struct target *target)
Read registers that are used in GDB g-packet.
Definition: arc.c:840
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:955
static int arc_enable_breakpoints(struct target *target)
Definition: arc.c:1707
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_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arc.c:1732
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_target_create(struct target *target)
Definition: arc.c:1425
static int arc_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1984
static int arc_unset_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arc.c:1625
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:2067
static int arc_assert_reset(struct target *target)
Definition: arc.c:1080
static const char *const reg_group_other
Definition: arc.c:300
struct target_type arcv2_target
Definition: arc.c:2319
static int arc_unset_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1923
int arc_cache_flush(struct target *target)
Definition: arc.c:2310
static int arc_debug_entry(struct target *target)
Definition: arc.c:1024
static int arc_set_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1863
static int arc_examine(struct target *target)
Definition: arc.c:735
static int arc_config_step(struct target *target, bool enable_step)
Definition: arc.c:2031
static int arc_enable_watchpoints(struct target *target)
Definition: arc.c:1957
static int arc_halt(struct target *target)
Definition: arc.c:779
static int arc_configure_dccm(struct target *target)
Definition: arc.c:638
static int arc_l2cache_flush(struct target *target)
Definition: arc.c:2284
int arc_cache_invalidate(struct target *target)
Definition: arc.c:2233
static int arc_deassert_reset(struct target *target)
Definition: arc.c:1135
static const char *const reg_group_general
Definition: arc.c:299
static int arc_l2cache_invalidate(struct target *target)
Definition: arc.c:2198
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:1375
static void arc_reset_actionpoints(struct target *target)
Definition: arc.c:1746
static int arc_poll(struct target *target)
Definition: arc.c:1036
static int arc_examine_debug_reason(struct target *target)
Definition: arc.c:986
static int arc_arch_state(struct target *target)
Definition: arc.c:1145
int arc_remove_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr)
Definition: arc.c:1828
static int arc_icache_invalidate(struct target *target)
Definition: arc.c:2148
static int arc_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: arc.c:1971
static int arc_dcache_invalidate(struct target *target)
Definition: arc.c:2169
static int arc_exit_debug(struct target *target)
Definition: arc.c:756
static int arc_write_instruction_u32(struct target *target, uint32_t address, uint32_t instr)
Write 4-byte instruction to memory.
Definition: arc.c:1446
static int arc_set_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: arc.c:1542
static int arc_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Definition: arc.c:1270
int arc_add_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr, uint32_t transaction)
Definition: arc.c:1796
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:1772
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:1473
static int arc_dcache_flush(struct target *target)
Definition: arc.c:2247
static void arc_deinit_target(struct target *target)
Definition: arc.c:1381
static int arc_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: arc.c:1367
static int arc_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
Definition: arc.c:1998
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:1721
static int arc_enable_interrupts(struct target *target, bool enable)
Definition: arc.c:1247
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:367
const char * name
Definition: armv4_5.c:76
const char * feature
Definition: armv4_5.c:368
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:472
@ BKPT_HARD
Definition: breakpoints.h:18
@ BKPT_SOFT
Definition: breakpoints.h:19
static void watchpoint_set(struct watchpoint *watchpoint, unsigned int number)
Definition: breakpoints.h:81
static void breakpoint_hw_set(struct breakpoint *breakpoint, unsigned int hw_number)
Definition: breakpoints.h:65
@ WPT_ACCESS
Definition: breakpoints.h:23
@ WPT_READ
Definition: breakpoints.h:23
@ WPT_WRITE
Definition: breakpoints.h:23
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:407
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:769
static enum reset_types jtag_reset_config
Definition: jtag/core.c:89
int jtag_get_srst(void)
Definition: jtag/core.c:1758
void jtag_add_sleep(uint32_t us)
Definition: jtag/core.c:881
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1745
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:181
#define list_first_entry(ptr, type, member)
Definition: list.h:131
static void list_add_tail(struct list_head *new, struct list_head *head)
Definition: list.h:203
static int list_empty(const struct list_head *head)
Definition: list.h:61
#define list_for_each_entry_safe(p, n, h, field)
Definition: list.h:159
#define list_for_each_entry(p, h, field)
Definition: list.h:155
static void INIT_LIST_HEAD(struct list_head *list)
Definition: list.h:54
void alive_sleep(uint64_t ms)
Definition: log.c:478
#define LOG_TARGET_WARNING(target, fmt_str,...)
Definition: log.h:173
#define ERROR_FAIL
Definition: log.h:188
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:176
#define LOG_TARGET_DEBUG(target, fmt_str,...)
Definition: log.h:164
#define LOG_LEVEL_IS(FOO)
Definition: log.h:112
#define ERROR_OK
Definition: log.h:182
@ LOG_LVL_DEBUG
Definition: log.h:55
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:119
struct jtag_tap * tap
Definition: target.h:122
enum target_debug_reason debug_reason
Definition: target.h:164
enum target_state state
Definition: target.h:167
enum target_endianness endianness
Definition: target.h:165
struct reg_cache * reg_cache
Definition: target.h:168
struct breakpoint * breakpoints
Definition: target.h:169
struct watchpoint * watchpoints
Definition: target.h:170
void * arch_info
Definition: target.h:174
bool reset_halt
Definition: target.h:154
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:1791
void target_free_all_working_areas(struct target *target)
Definition: target.c:2177
int target_halt(struct target *target)
Definition: target.c:516
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
Definition: target.c:361
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2368
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2651
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: target.c:2433
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
Definition: target.c:269
static int srst_asserted
Definition: target.c:2813
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
Definition: target.c:2580
int target_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
Definition: target.c:565
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:4803
void target_handle_event(struct target *target, enum target_event e)
Definition: target.c:4617
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
target_register_class
Definition: target.h:113
@ REG_CLASS_ALL
Definition: target.h:114
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:814
static bool target_was_examined(const struct target *target)
Definition: target.h:440
#define ERROR_TARGET_UNALIGNED_ACCESS
Definition: target.h:816
@ TARGET_EVENT_DEBUG_RESUMED
Definition: target.h:282
@ TARGET_EVENT_HALTED
Definition: target.h:262
@ TARGET_EVENT_RESUMED
Definition: target.h:263
@ TARGET_EVENT_DEBUG_HALTED
Definition: target.h:281
@ TARGET_EVENT_RESET_ASSERT
Definition: target.h:274
@ 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
@ TARGET_LITTLE_ENDIAN
Definition: target.h:85
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:818
#define ERROR_TARGET_FAILURE
Definition: target.h:815
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:279
#define TARGET_PRIxADDR
Definition: types.h:284
#define NULL
Definition: usb.h:16
uint8_t status[4]
Definition: vdebug.c:17