OpenOCD
arc_cmd.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 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include "arc.h"
16 #include <helper/nvp.h>
17 
18 /* --------------------------------------------------------------------------
19  *
20  * ARC targets expose command interface.
21  * It can be accessed via GDB through the (gdb) monitor command.
22  *
23  * ------------------------------------------------------------------------- */
24 
25 
29 };
30 /* Add flags register data type */
34 };
35 
36 static const struct nvp nvp_add_reg_type_flags_opts[] = {
37  { .name = "-name", .value = CFG_ADD_REG_TYPE_FLAGS_NAME },
38  { .name = "-flag", .value = CFG_ADD_REG_TYPE_FLAGS_FLAG },
39  { .name = NULL, .value = -1 }
40 };
41 
42 /* Helper function to check if all field required for register
43  * are set up */
44 static const char *validate_register(const struct arc_reg_desc * const reg, bool arch_num_set)
45 {
46  /* Check that required fields are set */
47  if (!reg->name)
48  return "-name option is required";
49  if (!reg->gdb_xml_feature)
50  return "-feature option is required";
51  if (!arch_num_set)
52  return "-num option is required";
53  if (reg->is_bcr && reg->is_core)
54  return "Register cannot be both -core and -bcr.";
55  return NULL;
56 }
57 
58 static COMMAND_HELPER(arc_handle_add_reg_type_flags_ops, struct arc_reg_data_type *type)
59 {
60  struct reg_data_type_flags_field *fields = type->reg_type_flags_field;
61  struct arc_reg_bitfield *bitfields = type->bitfields;
62  struct reg_data_type_flags *flags = &type->data_type_flags;
63  unsigned int cur_field = 0;
64 
65  while (CMD_ARGC) {
67  CMD_ARGC--;
68  CMD_ARGV++;
69  switch (n->value) {
71  if (!CMD_ARGC)
73 
74  const char *name = CMD_ARGV[0];
75  CMD_ARGC--;
76  CMD_ARGV++;
77 
78  if (strlen(name) >= REG_TYPE_MAX_NAME_LENGTH) {
79  command_print(CMD, "Reg type name is too big.");
81  }
82 
83  strcpy((void *)type->data_type.id, name);
84  break;
85 
87  if (CMD_ARGC < 2)
89 
90  uint32_t val;
91  const char *field_name = CMD_ARGV[0];
92  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], val);
93  CMD_ARGC -= 2;
94  CMD_ARGV += 2;
95  bitfields[cur_field].bitfield.start = val;
96  bitfields[cur_field].bitfield.end = val;
97 
98  if (strlen(field_name) >= REG_TYPE_MAX_NAME_LENGTH) {
99  command_print(CMD, "Reg type field_name is too big.");
101  }
102 
103  fields[cur_field].name = bitfields[cur_field].name;
104  strcpy(bitfields[cur_field].name, field_name);
105 
106  fields[cur_field].bitfield = &bitfields[cur_field].bitfield;
107  if (cur_field > 0)
108  fields[cur_field - 1].next = &fields[cur_field];
109  else
110  flags->fields = fields;
111 
112  cur_field += 1;
113  break;
114 
115  default:
118  }
119  }
120 
121  if (!type->data_type.id) {
122  command_print(CMD, "-name is a required option");
124  }
125 
126  return ERROR_OK;
127 }
128 
129 COMMAND_HANDLER(arc_handle_add_reg_type_flags)
130 {
131  int retval;
132 
133  LOG_DEBUG("-");
134 
136  if (!target) {
137  command_print(CMD, "No current target");
138  return ERROR_FAIL;
139  }
140 
141  /* Check if the amount of arguments is not zero */
142  if (CMD_ARGC == 0)
144 
145  /* Estimate number of registers as (argc - 2)/3 as each -flag option has 2
146  * arguments while -name is required. */
147  unsigned int fields_sz = (CMD_ARGC - 2) / 3;
148 
149  /* The maximum amount of bitfields is 32 */
150  if (fields_sz > 32) {
151  command_print(CMD, "The amount of bitfields exceed 32");
153  }
154 
155  struct arc_reg_data_type *type = calloc(1, sizeof(*type));
156  struct reg_data_type_flags_field *fields = calloc(fields_sz, sizeof(*fields));
157  struct arc_reg_bitfield *bitfields = calloc(fields_sz, sizeof(*bitfields));
158  if (!type || !fields || !bitfields) {
159  LOG_ERROR("Out of memory");
160  retval = ERROR_FAIL;
161  goto fail;
162  }
163  struct reg_data_type_flags *flags = &type->data_type_flags;
164  type->reg_type_flags_field = fields;
165 
166  /* Initialize type */
167  type->bitfields = bitfields;
168  type->data_type.id = type->data_type_id;
169  type->data_type.type = REG_TYPE_ARCH_DEFINED;
170  type->data_type.type_class = REG_TYPE_CLASS_FLAGS;
171  type->data_type.reg_type_flags = flags;
172  flags->size = 4; /* For now ARC has only 32-bit registers */
173 
174  retval = CALL_COMMAND_HANDLER(arc_handle_add_reg_type_flags_ops, type);
175  if (retval != ERROR_OK)
176  goto fail;
177 
179 
180  LOG_DEBUG("added flags type {name=%s}", type->data_type.id);
181 
182  return ERROR_OK;
183 
184 fail:
185  free(type);
186  free(fields);
187  free(bitfields);
188 
189  return retval;
190 }
191 
192 /* Add struct register data type */
196 };
197 
198 static const struct nvp nvp_add_reg_type_struct_opts[] = {
199  { .name = "-name", .value = CFG_ADD_REG_TYPE_STRUCT_NAME },
200  { .name = "-bitfield", .value = CFG_ADD_REG_TYPE_STRUCT_BITFIELD },
201  { .name = NULL, .value = -1 }
202 };
203 
204 COMMAND_HANDLER(arc_handle_set_aux_reg)
205 {
206  if (CMD_ARGC != 2)
208 
210  if (!target) {
211  command_print(CMD, "No current target");
212  return ERROR_FAIL;
213  }
214 
215  /* Register number */
216  uint32_t regnum;
217  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], regnum);
218 
219  /* Register value */
220  uint32_t value;
221  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
222 
223  struct arc_common *arc = target_to_arc(target);
224  assert(arc);
225 
226  CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc->jtag_info, regnum, value));
227 
228  return ERROR_OK;
229 }
230 
231 COMMAND_HANDLER(arc_handle_get_aux_reg)
232 {
233  if (CMD_ARGC != 1)
235 
237  if (!target) {
238  command_print(CMD, "No current target");
239  return ERROR_FAIL;
240  }
241 
242  /* Register number */
243  uint32_t regnum;
244  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], regnum);
245 
246  struct arc_common *arc = target_to_arc(target);
247  assert(arc);
248 
249  uint32_t value;
250  CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc->jtag_info, regnum, &value));
251 
252  command_print(CMD, "0x%" PRIx32, value);
253 
254  return ERROR_OK;
255 }
256 
257 COMMAND_HANDLER(arc_handle_get_core_reg)
258 {
259  if (CMD_ARGC != 1)
261 
263  if (!target) {
264  command_print(CMD, "No current target");
265  return ERROR_FAIL;
266  }
267 
268  /* Register number */
269  uint32_t regnum;
270  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], regnum);
271  if (regnum > CORE_REG_MAX_NUMBER || regnum == ARC_R61 || regnum == ARC_R62) {
272  command_print(CMD, "Core register number %i "
273  "is invalid. Must less then 64 and not 61 and 62.", regnum);
275  }
276 
277  struct arc_common *arc = target_to_arc(target);
278  assert(arc);
279 
280  /* Read value */
281  uint32_t value;
282  CHECK_RETVAL(arc_jtag_read_core_reg_one(&arc->jtag_info, regnum, &value));
283 
284  command_print(CMD, "0x%" PRIx32, value);
285 
286  return ERROR_OK;
287 }
288 
289 COMMAND_HANDLER(arc_handle_set_core_reg)
290 {
291  if (CMD_ARGC != 2)
293 
295  if (!target) {
296  command_print(CMD, "No current target");
297  return ERROR_FAIL;
298  }
299 
300  /* Register number */
301  uint32_t regnum;
302  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], regnum);
303  if (regnum > CORE_REG_MAX_NUMBER || regnum == ARC_R61 || regnum == ARC_R62) {
304  command_print(CMD, "Core register number %i "
305  "is invalid. Must less then 64 and not 61 and 62.", regnum);
307  }
308 
309  /* Register value */
310  uint32_t value;
311  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
312 
313  struct arc_common *arc = target_to_arc(target);
314  assert(arc);
315 
316  CHECK_RETVAL(arc_jtag_write_core_reg_one(&arc->jtag_info, regnum, value));
317 
318  return ERROR_OK;
319 }
320 
321 static const struct command_registration arc_jtag_command_group[] = {
322  {
323  .name = "get-aux-reg",
324  .handler = arc_handle_get_aux_reg,
325  .mode = COMMAND_EXEC,
326  .help = "Get AUX register by number. This command does a "
327  "raw JTAG request that bypasses OpenOCD register cache "
328  "and thus is unsafe and can have unexpected consequences. "
329  "Use at your own risk.",
330  .usage = "<regnum>"
331  },
332  {
333  .name = "set-aux-reg",
334  .handler = arc_handle_set_aux_reg,
335  .mode = COMMAND_EXEC,
336  .help = "Set AUX register by number. This command does a "
337  "raw JTAG request that bypasses OpenOCD register cache "
338  "and thus is unsafe and can have unexpected consequences. "
339  "Use at your own risk.",
340  .usage = "<regnum> <value>"
341  },
342  {
343  .name = "get-core-reg",
344  .handler = arc_handle_get_core_reg,
345  .mode = COMMAND_EXEC,
346  .help = "Get/Set core register by number. This command does a "
347  "raw JTAG request that bypasses OpenOCD register cache "
348  "and thus is unsafe and can have unexpected consequences. "
349  "Use at your own risk.",
350  .usage = "<regnum> [<value>]"
351  },
352  {
353  .name = "set-core-reg",
354  .handler = arc_handle_set_core_reg,
355  .mode = COMMAND_EXEC,
356  .help = "Get/Set core register by number. This command does a "
357  "raw JTAG request that bypasses OpenOCD register cache "
358  "and thus is unsafe and can have unexpected consequences. "
359  "Use at your own risk.",
360  .usage = "<regnum> [<value>]"
361  },
363 };
364 
365 
366 /* This function supports only bitfields. */
367 static COMMAND_HELPER(arc_handle_add_reg_type_struct_opts, struct arc_reg_data_type *type)
368 {
369  struct reg_data_type_struct_field *fields = type->reg_type_struct_field;
370  struct arc_reg_bitfield *bitfields = type->bitfields;
371  struct reg_data_type_struct *struct_type = &type->data_type_struct;
372  unsigned int cur_field = 0;
373 
374  while (CMD_ARGC) {
376  CMD_ARGC--;
377  CMD_ARGV++;
378  switch (n->value) {
380  if (!CMD_ARGC)
382 
383  const char *name = CMD_ARGV[0];
384  CMD_ARGC--;
385  CMD_ARGV++;
386 
387  if (strlen(name) >= REG_TYPE_MAX_NAME_LENGTH) {
388  command_print(CMD, "Reg type name is too big.");
390  }
391 
392  strcpy((void *)type->data_type.id, name);
393  break;
394 
396  if (CMD_ARGC < 3)
398 
399  uint32_t start_pos, end_pos;
400  const char *field_name = CMD_ARGV[0];
401  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], start_pos);
402  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], end_pos);
403  CMD_ARGC -= 3;
404  CMD_ARGV += 3;
405  bitfields[cur_field].bitfield.start = start_pos;
406  bitfields[cur_field].bitfield.end = end_pos;
407  bitfields[cur_field].bitfield.type = REG_TYPE_INT;
408 
409  if (strlen(field_name) >= REG_TYPE_MAX_NAME_LENGTH) {
410  command_print(CMD, "Reg type field_name is too big.");
412  }
413 
414  fields[cur_field].name = bitfields[cur_field].name;
415  strcpy(bitfields[cur_field].name, field_name);
416 
417  fields[cur_field].bitfield = &bitfields[cur_field].bitfield;
418  fields[cur_field].use_bitfields = true;
419  if (cur_field > 0)
420  fields[cur_field - 1].next = &fields[cur_field];
421  else
422  struct_type->fields = fields;
423 
424  cur_field += 1;
425 
426  break;
427 
428  default:
431  }
432  }
433 
434  if (!type->data_type.id) {
435  command_print(CMD, "-name is a required option");
437  }
438 
439  return ERROR_OK;
440 }
441 
442 COMMAND_HANDLER(arc_handle_add_reg_type_struct)
443 {
444  int retval;
445 
446  LOG_DEBUG("-");
447 
449  if (!target) {
450  command_print(CMD, "No current target");
451  return ERROR_FAIL;
452  }
453 
454  /* Check if the amount of arguments is not zero */
455  if (CMD_ARGC == 0)
457 
458  /* Estimate number of registers as (argc - 2)/4 as each -bitfield option has 3
459  * arguments while -name is required. */
460  unsigned int fields_sz = (CMD_ARGC - 2) / 4;
461 
462  /* The maximum amount of bitfields is 32 */
463  if (fields_sz > 32) {
464  command_print(CMD, "The amount of bitfields exceed 32");
466  }
467 
468  struct arc_reg_data_type *type = calloc(1, sizeof(*type));
469  struct reg_data_type_struct_field *fields = calloc(fields_sz, sizeof(*fields));
470  struct arc_reg_bitfield *bitfields = calloc(fields_sz, sizeof(*bitfields));
471  if (!type || !fields || !bitfields) {
472  LOG_ERROR("Out of memory");
473  retval = ERROR_FAIL;
474  goto fail;
475  }
476  struct reg_data_type_struct *struct_type = &type->data_type_struct;
477  type->reg_type_struct_field = fields;
478 
479  /* Initialize type */
480  type->data_type.id = type->data_type_id;
481  type->bitfields = bitfields;
482  type->data_type.type = REG_TYPE_ARCH_DEFINED;
483  type->data_type.type_class = REG_TYPE_CLASS_STRUCT;
484  type->data_type.reg_type_struct = struct_type;
485  struct_type->size = 4; /* For now ARC has only 32-bit registers */
486 
487  retval = CALL_COMMAND_HANDLER(arc_handle_add_reg_type_struct_opts, type);
488  if (retval != ERROR_OK)
489  goto fail;
490 
492 
493  LOG_DEBUG("added struct type {name=%s}", type->data_type.id);
494 
495  return ERROR_OK;
496 
497 fail:
498  free(type);
499  free(fields);
500  free(bitfields);
501 
502  return retval;
503 }
504 
505 /* Add register */
514 };
515 
516 static const struct nvp opts_nvp_add_reg[] = {
517  { .name = "-name", .value = CFG_ADD_REG_NAME },
518  { .name = "-num", .value = CFG_ADD_REG_ARCH_NUM },
519  { .name = "-core", .value = CFG_ADD_REG_IS_CORE },
520  { .name = "-bcr", .value = CFG_ADD_REG_IS_BCR },
521  { .name = "-feature", .value = CFG_ADD_REG_GDB_FEATURE },
522  { .name = "-type", .value = CFG_ADD_REG_TYPE },
523  { .name = "-g", .value = CFG_ADD_REG_GENERAL },
524  { .name = NULL, .value = -1 }
525 };
526 
528 {
529  free(r->name);
530  free(r->gdb_xml_feature);
531  free(r);
532 }
533 
534 static COMMAND_HELPER(arc_handle_add_reg_do, struct arc_reg_desc *reg)
535 {
536  /* There is no architecture number that we could treat as invalid, so
537  * separate variable required to ensure that arch num has been set. */
538  bool arch_num_set = false;
539  const char *type_name = "int"; /* Default type */
540 
541  /* At least we need to specify 4 parameters: name, number and gdb_feature,
542  * which means there should be 6 arguments. Also there can be additional parameters
543  * "-type <type>", "-g" and "-core" or "-bcr" which makes maximum 10 parameters. */
544  if (CMD_ARGC < 6 || CMD_ARGC > 10)
546 
547  /* Parse options. */
548  while (CMD_ARGC) {
549  const struct nvp *n = nvp_name2value(opts_nvp_add_reg, CMD_ARGV[0]);
550  CMD_ARGC--;
551  CMD_ARGV++;
552  switch (n->value) {
553  case CFG_ADD_REG_NAME:
554  if (!CMD_ARGC)
556 
557  reg->name = strdup(CMD_ARGV[0]);
558  if (!reg->name) {
559  LOG_ERROR("Out of memory");
560  return ERROR_FAIL;
561  }
562 
563  CMD_ARGC--;
564  CMD_ARGV++;
565  break;
566 
567  case CFG_ADD_REG_IS_CORE:
568  reg->is_core = true;
569  break;
570 
571  case CFG_ADD_REG_IS_BCR:
572  reg->is_bcr = true;
573  break;
574 
576  if (!CMD_ARGC)
578 
579  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], reg->arch_num);
580  CMD_ARGC--;
581  CMD_ARGV++;
582 
583  arch_num_set = true;
584  break;
585 
587  if (!CMD_ARGC)
589 
590  reg->gdb_xml_feature = strdup(CMD_ARGV[0]);
591  if (!reg->gdb_xml_feature) {
592  LOG_ERROR("Out of memory");
593  return ERROR_FAIL;
594  }
595 
596  CMD_ARGC--;
597  CMD_ARGV++;
598  break;
599 
600  case CFG_ADD_REG_TYPE:
601  if (!CMD_ARGC)
603 
604  type_name = CMD_ARGV[0];
605  CMD_ARGC--;
606  CMD_ARGV++;
607  break;
608 
609  case CFG_ADD_REG_GENERAL:
610  reg->is_general = true;
611  break;
612 
613  default:
616  }
617  }
618 
619  /* Check that required fields are set */
620  const char * const errmsg = validate_register(reg, arch_num_set);
621  if (errmsg) {
622  command_print(CMD, "%s", errmsg);
624  }
625 
626  /* Add new register */
628  if (!target) {
629  command_print(CMD, "No current target");
630  return ERROR_FAIL;
631  }
632 
633  reg->target = target;
634 
635  int retval = arc_reg_add(target, reg, type_name, strlen(type_name));
636  if (retval == ERROR_ARC_REGTYPE_NOT_FOUND) {
638  "Cannot find type `%s' for register `%s'.",
639  type_name, reg->name);
640  return retval;
641  }
642 
643  return ERROR_OK;
644 }
645 
646 COMMAND_HANDLER(arc_handle_add_reg)
647 {
648  struct arc_reg_desc *reg = calloc(1, sizeof(*reg));
649  if (!reg) {
650  LOG_ERROR("Out of memory");
651  return ERROR_FAIL;
652  }
653 
654  int retval = CALL_COMMAND_HANDLER(arc_handle_add_reg_do, reg);
655  if (retval != ERROR_OK) {
657  return retval;
658  }
659 
660  return ERROR_OK;
661 }
662 
663 /* arc set-reg-exists ($reg_name)+
664  * Accepts any amount of register names - will set them as existing in a loop.*/
665 COMMAND_HANDLER(arc_set_reg_exists)
666 {
667  struct target * const target = get_current_target(CMD_CTX);
668  if (!target) {
669  command_print(CMD, "Unable to get current target.");
670  return ERROR_FAIL;
671  }
672 
673  if (!CMD_ARGC) {
674  command_print(CMD, "At least one register name must be specified.");
676  }
677 
678  for (unsigned int i = 0; i < CMD_ARGC; i++) {
679  const char * const reg_name = CMD_ARGV[i];
680  struct reg * const r = arc_reg_get_by_name(target->reg_cache, reg_name, true);
681 
682  if (!r) {
683  command_print(CMD, "Register `%s' is not found.", reg_name);
685  }
686 
687  r->exist = true;
688  }
689 
690  return ERROR_OK;
691 }
692 
693 /* arc reg-field ($reg_name) ($reg_field)
694  * Reads struct type register field */
695 COMMAND_HANDLER(arc_handle_get_reg_field)
696 {
697  if (CMD_ARGC != 2)
699 
701  if (!target) {
702  command_print(CMD, "No current target");
703  return ERROR_FAIL;
704  }
705 
706  const char *reg_name = CMD_ARGV[0];
707  const char *field_name = CMD_ARGV[1];
708  uint32_t value;
709  int retval = arc_reg_get_field(target, reg_name, field_name, &value);
710 
711  switch (retval) {
712  case ERROR_OK:
713  break;
716  "Register `%s' has not been found.", reg_name);
720  "Register `%s' must have 'struct' type.", reg_name);
724  "Field `%s' has not been found in register `%s'.",
725  field_name, reg_name);
729  "Field `%s' is not a 'bitfield' field in a structure.",
730  field_name);
732  default:
733  /* Pass through other errors. */
734  return retval;
735  }
736 
737  command_print(CMD, "0x%" PRIx32, value);
738 
739  return ERROR_OK;
740 }
741 
742 COMMAND_HANDLER(arc_l1_cache_disable_auto_cmd)
743 {
744  bool value;
745  int retval = 0;
747  retval = CALL_COMMAND_HANDLER(handle_command_parse_bool,
748  &value, "target has caches enabled");
749  arc->has_l2cache = value;
750  arc->has_dcache = value;
751  arc->has_icache = value;
752  return retval;
753 }
754 
755 COMMAND_HANDLER(arc_l2_cache_disable_auto_cmd)
756 {
758  return CALL_COMMAND_HANDLER(handle_command_parse_bool,
759  &arc->has_l2cache, "target has l2 cache enabled");
760 }
761 
762 COMMAND_HANDLER(arc_handle_actionpoints_num)
763 {
764  LOG_DEBUG("-");
765 
766  if (CMD_ARGC >= 2)
768 
770  if (!target) {
771  command_print(CMD, "No current target");
772  return ERROR_FAIL;
773  }
774 
775  struct arc_common *arc = target_to_arc(target);
776  /* It is not possible to pass &arc->actionpoints_num directly to
777  * handle_command_parse_uint, because this value should be valid during
778  * "actionpoint reset, initiated by arc_set_actionpoints_num. */
779  uint32_t ap_num = arc->actionpoints_num;
780 
781  if (CMD_ARGC == 1) {
782  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], ap_num);
783  int e = arc_set_actionpoints_num(target, ap_num);
784  if (e != ERROR_OK) {
786  "Failed to set number of actionpoints");
787  return e;
788  }
789  }
790 
791  command_print(CMD, "%" PRIu32, ap_num);
792 
793  return ERROR_OK;
794 }
795 
796 /* ----- Exported target commands ------------------------------------------ */
797 
798 static const struct command_registration arc_l2_cache_group_handlers[] = {
799  {
800  .name = "auto",
801  .handler = arc_l2_cache_disable_auto_cmd,
802  .mode = COMMAND_ANY,
803  .usage = "(1|0)",
804  .help = "Disable or enable L2",
805  },
807 };
808 
809 static const struct command_registration arc_cache_group_handlers[] = {
810  {
811  .name = "auto",
812  .handler = arc_l1_cache_disable_auto_cmd,
813  .mode = COMMAND_ANY,
814  .help = "Disable or enable L1",
815  .usage = "(1|0)",
816  },
817  {
818  .name = "l2",
819  .mode = COMMAND_ANY,
820  .help = "L2 cache command group",
821  .usage = "",
823  },
825 };
826 
827 
828 static const struct command_registration arc_core_command_handlers[] = {
829  {
830  .name = "add-reg-type-flags",
831  .handler = arc_handle_add_reg_type_flags,
832  .mode = COMMAND_CONFIG,
833  .usage = "-name <string> -flag <name> <position> "
834  "[-flag <name> <position>]...",
835  .help = "Add new 'flags' register data type. Only single bit flags "
836  "are supported. Type name is global. Bitsize of register is fixed "
837  "at 32 bits.",
838  },
839  {
840  .name = "add-reg-type-struct",
841  .handler = arc_handle_add_reg_type_struct,
842  .mode = COMMAND_CONFIG,
843  .usage = "-name <string> -bitfield <name> <start> <end> "
844  "[-bitfield <name> <start> <end>]...",
845  .help = "Add new 'struct' register data type. Only bit-fields are "
846  "supported so far, which means that for each bitfield start and end "
847  "position bits must be specified. GDB also support type-fields, "
848  "where common type can be used instead. Type name is global. Bitsize of "
849  "register is fixed at 32 bits.",
850  },
851  {
852  .name = "add-reg",
853  .handler = arc_handle_add_reg,
854  .mode = COMMAND_CONFIG,
855  .usage = "-name <string> -num <int> -feature <string> [-gdbnum <int>] "
856  "[-core|-bcr] [-type <type_name>] [-g]",
857  .help = "Add new register. Name, architectural number and feature name "
858  "are required options. GDB regnum will default to previous register "
859  "(gdbnum + 1) and shouldn't be specified in most cases. Type "
860  "defaults to default GDB 'int'.",
861  },
862  {
863  .name = "set-reg-exists",
864  .handler = arc_set_reg_exists,
865  .mode = COMMAND_ANY,
866  .usage = "<register-name> [<register-name>]...",
867  .help = "Set that register exists. Accepts multiple register names as "
868  "arguments.",
869  },
870  {
871  .name = "get-reg-field",
872  .handler = arc_handle_get_reg_field,
873  .mode = COMMAND_ANY,
874  .usage = "<regname> <field_name>",
875  .help = "Returns value of field in a register with 'struct' type.",
876  },
877  {
878  .name = "jtag",
879  .mode = COMMAND_ANY,
880  .help = "ARC JTAG specific commands",
881  .usage = "",
882  .chain = arc_jtag_command_group,
883  },
884  {
885  .name = "cache",
886  .mode = COMMAND_ANY,
887  .help = "cache command group",
888  .usage = "",
889  .chain = arc_cache_group_handlers,
890  },
891  {
892  .name = "num-actionpoints",
893  .handler = arc_handle_actionpoints_num,
894  .mode = COMMAND_ANY,
895  .usage = "[<unsigned integer>]",
896  .help = "Prints or sets amount of actionpoints in the processor.",
897  },
899 };
900 
902  {
903  .name = "arc",
904  .mode = COMMAND_ANY,
905  .help = "ARC monitor command group",
906  .usage = "",
907  .chain = arc_core_command_handlers,
908  },
910 };
int arc_reg_get_field(struct target *target, const char *reg_name, const char *field_name, uint32_t *value_ptr)
Definition: arc.c:549
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
void arc_reg_data_type_add(struct target *target, struct arc_reg_data_type *data_type)
Definition: arc.c:61
int arc_set_actionpoints_num(struct target *target, uint32_t ap_num)
Definition: arc.c:1776
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 struct arc_common * target_to_arc(struct target *target)
Definition: arc.h:256
#define ERROR_ARC_REGTYPE_NOT_FOUND
Definition: arc.h:325
#define ERROR_ARC_REGISTER_FIELD_NOT_FOUND
Definition: arc.h:322
#define CORE_REG_MAX_NUMBER
Definition: arc.h:95
#define ERROR_ARC_REGISTER_IS_NOT_STRUCT
Definition: arc.h:323
#define ERROR_ARC_REGISTER_NOT_FOUND
Definition: arc.h:321
#define REG_TYPE_MAX_NAME_LENGTH
Definition: arc.h:98
#define CHECK_RETVAL(action)
Definition: arc.h:246
#define ERROR_ARC_FIELD_IS_NOT_BITFIELD
Definition: arc.h:324
@ ARC_R61
Definition: arc.h:85
@ ARC_R62
Definition: arc.h:86
static COMMAND_HELPER(arc_handle_add_reg_type_flags_ops, struct arc_reg_data_type *type)
Definition: arc_cmd.c:58
static const struct nvp opts_nvp_add_reg[]
Definition: arc_cmd.c:516
add_reg_type_struct
Definition: arc_cmd.c:193
@ CFG_ADD_REG_TYPE_STRUCT_BITFIELD
Definition: arc_cmd.c:195
@ CFG_ADD_REG_TYPE_STRUCT_NAME
Definition: arc_cmd.c:194
COMMAND_HANDLER(arc_handle_add_reg_type_flags)
Definition: arc_cmd.c:129
add_reg_type_flags
Definition: arc_cmd.c:31
@ CFG_ADD_REG_TYPE_FLAGS_FLAG
Definition: arc_cmd.c:33
@ CFG_ADD_REG_TYPE_FLAGS_NAME
Definition: arc_cmd.c:32
static const struct nvp nvp_add_reg_type_struct_opts[]
Definition: arc_cmd.c:198
static const struct command_registration arc_cache_group_handlers[]
Definition: arc_cmd.c:809
opts_add_reg
Definition: arc_cmd.c:506
@ CFG_ADD_REG_ARCH_NUM
Definition: arc_cmd.c:508
@ CFG_ADD_REG_NAME
Definition: arc_cmd.c:507
@ CFG_ADD_REG_GDB_FEATURE
Definition: arc_cmd.c:511
@ CFG_ADD_REG_GENERAL
Definition: arc_cmd.c:513
@ CFG_ADD_REG_IS_BCR
Definition: arc_cmd.c:510
@ CFG_ADD_REG_IS_CORE
Definition: arc_cmd.c:509
@ CFG_ADD_REG_TYPE
Definition: arc_cmd.c:512
static const struct nvp nvp_add_reg_type_flags_opts[]
Definition: arc_cmd.c:36
static const struct command_registration arc_core_command_handlers[]
Definition: arc_cmd.c:828
void free_reg_desc(struct arc_reg_desc *r)
Definition: arc_cmd.c:527
const struct command_registration arc_monitor_command_handlers[]
Definition: arc_cmd.c:901
static const char * validate_register(const struct arc_reg_desc *const reg, bool arch_num_set)
Definition: arc_cmd.c:44
static const struct command_registration arc_l2_cache_group_handlers[]
Definition: arc_cmd.c:798
static const struct command_registration arc_jtag_command_group[]
Definition: arc_cmd.c:321
add_reg_types
Definition: arc_cmd.c:26
@ CFG_ADD_REG_TYPE_STRUCT
Definition: arc_cmd.c:28
@ CFG_ADD_REG_TYPE_FLAG
Definition: arc_cmd.c:27
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_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_write_core_reg_one(struct arc_jtag *jtag_info, uint32_t addr, uint32_t value)
Wrapper function to ease writing of one core register.
Definition: arc_jtag.c:326
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
const char * name
Definition: armv4_5.c:76
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
Definition: command.h:118
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:442
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:404
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
uint8_t type
Definition: esp_usb_jtag.c:0
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
void nvp_unknown_command_print(struct command_invocation *cmd, const struct nvp *nvp, const char *param_name, const char *param_value)
Definition: nvp.c:49
const struct nvp * nvp_name2value(const struct nvp *p, const char *name)
Definition: nvp.c:29
@ REG_TYPE_INT
Definition: register.h:21
@ REG_TYPE_ARCH_DEFINED
Definition: register.h:38
@ REG_TYPE_CLASS_FLAGS
Definition: register.h:96
@ REG_TYPE_CLASS_STRUCT
Definition: register.h:95
struct target * target
Definition: rtt/rtt.c:26
bool has_icache
Definition: arc.h:195
bool has_l2cache
Definition: arc.h:196
unsigned int actionpoints_num
Definition: arc.h:240
bool has_dcache
Definition: arc.h:194
struct arc_jtag jtag_info
Definition: arc.h:188
char name[REG_TYPE_MAX_NAME_LENGTH]
Definition: arc.h:136
struct reg_data_type_bitfield bitfield
Definition: arc.h:135
char * gdb_xml_feature
Definition: arc.h:300
char * name
Definition: arc.h:291
const char * name
Definition: command.h:235
Name Value Pairs, aka: NVP.
Definition: nvp.h:61
int value
Definition: nvp.h:63
const char * name
Definition: nvp.h:62
enum reg_type type
Definition: register.h:63
struct reg_data_type_flags_field * next
Definition: register.h:84
struct reg_data_type_bitfield * bitfield
Definition: register.h:83
struct reg_data_type_flags_field * fields
Definition: register.h:89
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
Definition: register.h:111
bool exist
Definition: register.h:128
const char * name
Definition: register.h:113
Definition: target.h:116
struct reg_cache * reg_cache
Definition: target.h:158
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:458
#define NULL
Definition: usb.h:16