1 // SPDX-License-Identifier: GPL-2.0-or-later
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 ***************************************************************************/
17 /* --------------------------------------------------------------------------
19 * ARC targets expose command interface.
20 * It can be accessed via GDB through the (gdb) monitor command.
22 * ------------------------------------------------------------------------- */
25 static int arc_cmd_jim_get_uint32(struct jim_getopt_info
*goi
, uint32_t *value
)
28 JIM_CHECK_RETVAL(jim_getopt_wide(goi
, &value_wide
));
29 *value
= (uint32_t)value_wide
;
34 CFG_ADD_REG_TYPE_FLAG
,
35 CFG_ADD_REG_TYPE_STRUCT
,
37 /* Add flags register data type */
38 enum add_reg_type_flags
{
39 CFG_ADD_REG_TYPE_FLAGS_NAME
,
40 CFG_ADD_REG_TYPE_FLAGS_FLAG
,
43 static struct jim_nvp nvp_add_reg_type_flags_opts
[] = {
44 { .name
= "-name", .value
= CFG_ADD_REG_TYPE_FLAGS_NAME
},
45 { .name
= "-flag", .value
= CFG_ADD_REG_TYPE_FLAGS_FLAG
},
46 { .name
= NULL
, .value
= -1 }
49 /* Helper function to check if all field required for register
51 static const char *validate_register(const struct arc_reg_desc
* const reg
, bool arch_num_set
)
53 /* Check that required fields are set */
55 return "-name option is required";
56 if (!reg
->gdb_xml_feature
)
57 return "-feature option is required";
59 return "-num option is required";
60 if (reg
->is_bcr
&& reg
->is_core
)
61 return "Register cannot be both -core and -bcr.";
65 /* Helper function to read the name of register type or register from
67 static int jim_arc_read_reg_name_field(struct jim_getopt_info
*goi
,
68 const char **name
, int *name_len
)
73 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-name <name> ...");
76 e
= jim_getopt_string(goi
, name
, name_len
);
80 /* Helper function to read bitfields/flags of register type. */
81 static int jim_arc_read_reg_type_field(struct jim_getopt_info
*goi
, const char **field_name
, int *field_name_len
,
82 struct arc_reg_bitfield
*bitfields
, int cur_field
, int type
)
84 jim_wide start_pos
, end_pos
;
87 if ((type
== CFG_ADD_REG_TYPE_STRUCT
&& goi
->argc
< 3) ||
88 (type
== CFG_ADD_REG_TYPE_FLAG
&& goi
->argc
< 2)) {
89 Jim_SetResultFormatted(goi
->interp
, "Not enough arguments after -flag/-bitfield");
93 e
= jim_getopt_string(goi
, field_name
, field_name_len
);
97 /* read start position of bitfield/flag */
98 e
= jim_getopt_wide(goi
, &start_pos
);
104 /* Check if any arguments remain,
105 * set bitfields[cur_field].end if flag is multibit */
107 /* Check current argv[0], if it is equal to "-flag",
108 * than bitfields[cur_field].end remains start */
109 if ((strcmp(Jim_String(goi
->argv
[0]), "-flag") && type
== CFG_ADD_REG_TYPE_FLAG
)
110 || (type
== CFG_ADD_REG_TYPE_STRUCT
)) {
111 e
= jim_getopt_wide(goi
, &end_pos
);
113 Jim_SetResultFormatted(goi
->interp
, "Error reading end position");
118 bitfields
[cur_field
].bitfield
.start
= start_pos
;
119 bitfields
[cur_field
].bitfield
.end
= end_pos
;
120 if ((end_pos
!= start_pos
) || (type
== CFG_ADD_REG_TYPE_STRUCT
))
121 bitfields
[cur_field
].bitfield
.type
= REG_TYPE_INT
;
125 static int jim_arc_add_reg_type_flags(Jim_Interp
*interp
, int argc
,
126 Jim_Obj
* const *argv
)
128 struct jim_getopt_info goi
;
129 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
133 struct command_context
*ctx
;
134 struct target
*target
;
136 ctx
= current_command_context(interp
);
138 target
= get_current_target(ctx
);
140 Jim_SetResultFormatted(goi
.interp
, "No current target");
146 /* Check if the amount of arguments is not zero */
148 Jim_SetResultFormatted(goi
.interp
, "The command has no arguments");
152 /* Estimate number of registers as (argc - 2)/3 as each -flag option has 2
153 * arguments while -name is required. */
154 unsigned int fields_sz
= (goi
.argc
- 2) / 3;
155 unsigned int cur_field
= 0;
157 /* The maximum amount of bitfields is 32 */
158 if (fields_sz
> 32) {
159 Jim_SetResultFormatted(goi
.interp
, "The amount of bitfields exceed 32");
163 struct arc_reg_data_type
*type
= calloc(1, sizeof(*type
));
164 struct reg_data_type_flags
*flags
= &type
->data_type_flags
;
165 struct reg_data_type_flags_field
*fields
= calloc(fields_sz
, sizeof(*fields
));
166 type
->reg_type_flags_field
= fields
;
167 struct arc_reg_bitfield
*bitfields
= calloc(fields_sz
, sizeof(*bitfields
));
168 if (!(type
&& fields
&& bitfields
)) {
169 Jim_SetResultFormatted(goi
.interp
, "Failed to allocate memory.");
173 /* Initialize type */
174 type
->bitfields
= bitfields
;
175 type
->data_type
.id
= type
->data_type_id
;
176 type
->data_type
.type
= REG_TYPE_ARCH_DEFINED
;
177 type
->data_type
.type_class
= REG_TYPE_CLASS_FLAGS
;
178 type
->data_type
.reg_type_flags
= flags
;
179 flags
->size
= 4; /* For now ARC has only 32-bit registers */
181 while (goi
.argc
> 0 && e
== JIM_OK
) {
183 e
= jim_getopt_nvp(&goi
, nvp_add_reg_type_flags_opts
, &n
);
185 jim_getopt_nvp_unknown(&goi
, nvp_add_reg_type_flags_opts
, 0);
190 case CFG_ADD_REG_TYPE_FLAGS_NAME
:
192 const char *name
= NULL
;
195 e
= jim_arc_read_reg_name_field(&goi
, &name
, &name_len
);
197 Jim_SetResultFormatted(goi
.interp
, "Unable to read reg name.");
201 if (name_len
> REG_TYPE_MAX_NAME_LENGTH
) {
202 Jim_SetResultFormatted(goi
.interp
, "Reg type name is too big.");
206 strncpy((void *)type
->data_type
.id
, name
, name_len
);
207 if (!type
->data_type
.id
) {
208 Jim_SetResultFormatted(goi
.interp
, "Unable to setup reg type name.");
215 case CFG_ADD_REG_TYPE_FLAGS_FLAG
:
217 const char *field_name
= NULL
;
218 int field_name_len
= 0;
220 e
= jim_arc_read_reg_type_field(&goi
, &field_name
, &field_name_len
, bitfields
,
221 cur_field
, CFG_ADD_REG_TYPE_FLAG
);
223 Jim_SetResultFormatted(goi
.interp
, "Unable to add reg_type_flag field.");
227 if (field_name_len
> REG_TYPE_MAX_NAME_LENGTH
) {
228 Jim_SetResultFormatted(goi
.interp
, "Reg type field_name_len is too big.");
232 fields
[cur_field
].name
= bitfields
[cur_field
].name
;
233 strncpy(bitfields
[cur_field
].name
, field_name
, field_name_len
);
234 if (!fields
[cur_field
].name
) {
235 Jim_SetResultFormatted(goi
.interp
, "Unable to setup field name. ");
239 fields
[cur_field
].bitfield
= &(bitfields
[cur_field
].bitfield
);
241 fields
[cur_field
- 1].next
= &(fields
[cur_field
]);
243 flags
->fields
= fields
;
251 if (!type
->data_type
.id
) {
252 Jim_SetResultFormatted(goi
.interp
, "-name is a required option");
256 arc_reg_data_type_add(target
, type
);
258 LOG_DEBUG("added flags type {name=%s}", type
->data_type
.id
);
269 /* Add struct register data type */
270 enum add_reg_type_struct
{
271 CFG_ADD_REG_TYPE_STRUCT_NAME
,
272 CFG_ADD_REG_TYPE_STRUCT_BITFIELD
,
275 static struct jim_nvp nvp_add_reg_type_struct_opts
[] = {
276 { .name
= "-name", .value
= CFG_ADD_REG_TYPE_STRUCT_NAME
},
277 { .name
= "-bitfield", .value
= CFG_ADD_REG_TYPE_STRUCT_BITFIELD
},
278 { .name
= NULL
, .value
= -1 }
281 static int jim_arc_set_aux_reg(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *argv
)
284 struct command_context
*context
;
285 struct target
*target
;
289 struct jim_getopt_info goi
;
290 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
293 Jim_SetResultFormatted(goi
.interp
,
294 "usage: %s <aux_reg_num> <aux_reg_value>", Jim_GetString(argv
[0], NULL
));
298 context
= current_command_context(interp
);
301 target
= get_current_target(context
);
303 Jim_SetResultFormatted(goi
.interp
, "No current target");
307 /* Register number */
308 JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi
, ®num
));
311 JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi
, &value
));
313 struct arc_common
*arc
= target_to_arc(target
);
316 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, regnum
, value
));
321 static int jim_arc_get_aux_reg(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *argv
)
323 struct command_context
*context
;
324 struct target
*target
;
328 struct jim_getopt_info goi
;
329 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
332 Jim_SetResultFormatted(goi
.interp
,
333 "usage: %s <aux_reg_num>", Jim_GetString(argv
[0], NULL
));
337 context
= current_command_context(interp
);
340 target
= get_current_target(context
);
342 Jim_SetResultFormatted(goi
.interp
, "No current target");
346 /* Register number */
347 JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi
, ®num
));
349 struct arc_common
*arc
= target_to_arc(target
);
352 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, regnum
, &value
));
353 Jim_SetResultInt(interp
, value
);
358 static int jim_arc_get_core_reg(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *argv
)
360 struct command_context
*context
;
361 struct target
*target
;
365 struct jim_getopt_info goi
;
366 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
369 Jim_SetResultFormatted(goi
.interp
,
370 "usage: %s <core_reg_num>", Jim_GetString(argv
[0], NULL
));
374 context
= current_command_context(interp
);
377 target
= get_current_target(context
);
379 Jim_SetResultFormatted(goi
.interp
, "No current target");
383 /* Register number */
384 JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi
, ®num
));
385 if (regnum
> CORE_REG_MAX_NUMBER
|| regnum
== ARC_R61
|| regnum
== ARC_R62
) {
386 Jim_SetResultFormatted(goi
.interp
, "Core register number %i "
387 "is invalid. Must less then 64 and not 61 and 62.", regnum
);
391 struct arc_common
*arc
= target_to_arc(target
);
395 CHECK_RETVAL(arc_jtag_read_core_reg_one(&arc
->jtag_info
, regnum
, &value
));
396 Jim_SetResultInt(interp
, value
);
401 static int jim_arc_set_core_reg(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *argv
)
403 struct command_context
*context
;
404 struct target
*target
;
408 struct jim_getopt_info goi
;
409 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
412 Jim_SetResultFormatted(goi
.interp
,
413 "usage: %s <core_reg_num> <core_reg_value>", Jim_GetString(argv
[0], NULL
));
417 context
= current_command_context(interp
);
420 target
= get_current_target(context
);
422 Jim_SetResultFormatted(goi
.interp
, "No current target");
426 /* Register number */
427 JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi
, ®num
));
428 if (regnum
> CORE_REG_MAX_NUMBER
|| regnum
== ARC_R61
|| regnum
== ARC_R62
) {
429 Jim_SetResultFormatted(goi
.interp
, "Core register number %i "
430 "is invalid. Must less then 64 and not 61 and 62.", regnum
);
435 JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi
, &value
));
437 struct arc_common
*arc
= target_to_arc(target
);
440 CHECK_RETVAL(arc_jtag_write_core_reg_one(&arc
->jtag_info
, regnum
, value
));
445 static const struct command_registration arc_jtag_command_group
[] = {
447 .name
= "get-aux-reg",
448 .jim_handler
= jim_arc_get_aux_reg
,
449 .mode
= COMMAND_EXEC
,
450 .help
= "Get AUX register by number. This command does a "
451 "raw JTAG request that bypasses OpenOCD register cache "
452 "and thus is unsafe and can have unexpected consequences. "
453 "Use at your own risk.",
457 .name
= "set-aux-reg",
458 .jim_handler
= jim_arc_set_aux_reg
,
459 .mode
= COMMAND_EXEC
,
460 .help
= "Set AUX register by number. This command does a "
461 "raw JTAG request that bypasses OpenOCD register cache "
462 "and thus is unsafe and can have unexpected consequences. "
463 "Use at your own risk.",
464 .usage
= "<regnum> <value>"
467 .name
= "get-core-reg",
468 .jim_handler
= jim_arc_get_core_reg
,
469 .mode
= COMMAND_EXEC
,
470 .help
= "Get/Set core register by number. This command does a "
471 "raw JTAG request that bypasses OpenOCD register cache "
472 "and thus is unsafe and can have unexpected consequences. "
473 "Use at your own risk.",
474 .usage
= "<regnum> [<value>]"
477 .name
= "set-core-reg",
478 .jim_handler
= jim_arc_set_core_reg
,
479 .mode
= COMMAND_EXEC
,
480 .help
= "Get/Set core register by number. This command does a "
481 "raw JTAG request that bypasses OpenOCD register cache "
482 "and thus is unsafe and can have unexpected consequences. "
483 "Use at your own risk.",
484 .usage
= "<regnum> [<value>]"
486 COMMAND_REGISTRATION_DONE
490 /* This function supports only bitfields. */
491 static int jim_arc_add_reg_type_struct(Jim_Interp
*interp
, int argc
,
492 Jim_Obj
* const *argv
)
494 struct jim_getopt_info goi
;
495 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
499 struct command_context
*ctx
;
500 struct target
*target
;
502 ctx
= current_command_context(interp
);
504 target
= get_current_target(ctx
);
506 Jim_SetResultFormatted(goi
.interp
, "No current target");
512 /* Check if the amount of arguments is not zero */
514 Jim_SetResultFormatted(goi
.interp
, "The command has no arguments");
518 /* Estimate number of registers as (argc - 2)/4 as each -bitfield option has 3
519 * arguments while -name is required. */
520 unsigned int fields_sz
= (goi
.argc
- 2) / 4;
521 unsigned int cur_field
= 0;
523 /* The maximum amount of bitfields is 32 */
524 if (fields_sz
> 32) {
525 Jim_SetResultFormatted(goi
.interp
, "The amount of bitfields exceed 32");
529 struct arc_reg_data_type
*type
= calloc(1, sizeof(*type
));
530 struct reg_data_type_struct
*struct_type
= &type
->data_type_struct
;
531 struct reg_data_type_struct_field
*fields
= calloc(fields_sz
, sizeof(*fields
));
532 type
->reg_type_struct_field
= fields
;
533 struct arc_reg_bitfield
*bitfields
= calloc(fields_sz
, sizeof(*bitfields
));
534 if (!(type
&& fields
&& bitfields
)) {
535 Jim_SetResultFormatted(goi
.interp
, "Failed to allocate memory.");
539 /* Initialize type */
540 type
->data_type
.id
= type
->data_type_id
;
541 type
->bitfields
= bitfields
;
542 type
->data_type
.type
= REG_TYPE_ARCH_DEFINED
;
543 type
->data_type
.type_class
= REG_TYPE_CLASS_STRUCT
;
544 type
->data_type
.reg_type_struct
= struct_type
;
545 struct_type
->size
= 4; /* For now ARC has only 32-bit registers */
547 while (goi
.argc
> 0 && e
== JIM_OK
) {
549 e
= jim_getopt_nvp(&goi
, nvp_add_reg_type_struct_opts
, &n
);
551 jim_getopt_nvp_unknown(&goi
, nvp_add_reg_type_struct_opts
, 0);
556 case CFG_ADD_REG_TYPE_STRUCT_NAME
:
558 const char *name
= NULL
;
561 e
= jim_arc_read_reg_name_field(&goi
, &name
, &name_len
);
563 Jim_SetResultFormatted(goi
.interp
, "Unable to read reg name.");
567 if (name_len
> REG_TYPE_MAX_NAME_LENGTH
) {
568 Jim_SetResultFormatted(goi
.interp
, "Reg type name is too big.");
572 strncpy((void *)type
->data_type
.id
, name
, name_len
);
573 if (!type
->data_type
.id
) {
574 Jim_SetResultFormatted(goi
.interp
, "Unable to setup reg type name.");
580 case CFG_ADD_REG_TYPE_STRUCT_BITFIELD
:
582 const char *field_name
= NULL
;
583 int field_name_len
= 0;
584 e
= jim_arc_read_reg_type_field(&goi
, &field_name
, &field_name_len
, bitfields
,
585 cur_field
, CFG_ADD_REG_TYPE_STRUCT
);
587 Jim_SetResultFormatted(goi
.interp
, "Unable to add reg_type_struct field.");
591 if (field_name_len
> REG_TYPE_MAX_NAME_LENGTH
) {
592 Jim_SetResultFormatted(goi
.interp
, "Reg type field_name_len is too big.");
596 fields
[cur_field
].name
= bitfields
[cur_field
].name
;
597 strncpy(bitfields
[cur_field
].name
, field_name
, field_name_len
);
598 if (!fields
[cur_field
].name
) {
599 Jim_SetResultFormatted(goi
.interp
, "Unable to setup field name. ");
603 fields
[cur_field
].bitfield
= &(bitfields
[cur_field
].bitfield
);
604 fields
[cur_field
].use_bitfields
= true;
606 fields
[cur_field
- 1].next
= &(fields
[cur_field
]);
608 struct_type
->fields
= fields
;
617 if (!type
->data_type
.id
) {
618 Jim_SetResultFormatted(goi
.interp
, "-name is a required option");
622 arc_reg_data_type_add(target
, type
);
623 LOG_DEBUG("added struct type {name=%s}", type
->data_type
.id
);
637 CFG_ADD_REG_ARCH_NUM
,
640 CFG_ADD_REG_GDB_FEATURE
,
645 static struct jim_nvp opts_nvp_add_reg
[] = {
646 { .name
= "-name", .value
= CFG_ADD_REG_NAME
},
647 { .name
= "-num", .value
= CFG_ADD_REG_ARCH_NUM
},
648 { .name
= "-core", .value
= CFG_ADD_REG_IS_CORE
},
649 { .name
= "-bcr", .value
= CFG_ADD_REG_IS_BCR
},
650 { .name
= "-feature", .value
= CFG_ADD_REG_GDB_FEATURE
},
651 { .name
= "-type", .value
= CFG_ADD_REG_TYPE
},
652 { .name
= "-g", .value
= CFG_ADD_REG_GENERAL
},
653 { .name
= NULL
, .value
= -1 }
656 void free_reg_desc(struct arc_reg_desc
*r
)
659 free(r
->gdb_xml_feature
);
663 static int jim_arc_add_reg(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *argv
)
665 struct jim_getopt_info goi
;
666 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
668 struct arc_reg_desc
*reg
= calloc(1, sizeof(*reg
));
670 Jim_SetResultFormatted(goi
.interp
, "Failed to allocate memory.");
674 /* There is no architecture number that we could treat as invalid, so
675 * separate variable required to ensure that arch num has been set. */
676 bool arch_num_set
= false;
677 const char *type_name
= "int"; /* Default type */
678 int type_name_len
= strlen(type_name
);
681 /* At least we need to specify 4 parameters: name, number and gdb_feature,
682 * which means there should be 6 arguments. Also there can be additional parameters
683 * "-type <type>", "-g" and "-core" or "-bcr" which makes maximum 10 parameters. */
684 if (goi
.argc
< 6 || goi
.argc
> 10) {
686 Jim_SetResultFormatted(goi
.interp
,
687 "Should be at least 6 arguments and not greater than 10: "
688 " -name <name> -num <num> -feature <gdb_feature> "
689 " [-type <type_name>] [-core|-bcr] [-g].");
694 while (goi
.argc
> 0) {
696 e
= jim_getopt_nvp(&goi
, opts_nvp_add_reg
, &n
);
698 jim_getopt_nvp_unknown(&goi
, opts_nvp_add_reg
, 0);
704 case CFG_ADD_REG_NAME
:
706 const char *reg_name
= NULL
;
707 int reg_name_len
= 0;
709 e
= jim_arc_read_reg_name_field(&goi
, ®_name
, ®_name_len
);
711 Jim_SetResultFormatted(goi
.interp
, "Unable to read register name.");
716 reg
->name
= strndup(reg_name
, reg_name_len
);
719 case CFG_ADD_REG_IS_CORE
:
722 case CFG_ADD_REG_IS_BCR
:
725 case CFG_ADD_REG_ARCH_NUM
:
731 Jim_WrongNumArgs(interp
, goi
.argc
, goi
.argv
, "-num <int> ...");
735 e
= jim_getopt_wide(&goi
, &archnum
);
741 reg
->arch_num
= archnum
;
745 case CFG_ADD_REG_GDB_FEATURE
:
747 const char *feature
= NULL
;
750 e
= jim_arc_read_reg_name_field(&goi
, &feature
, &feature_len
);
752 Jim_SetResultFormatted(goi
.interp
, "Unable to read gdb_feature.");
757 reg
->gdb_xml_feature
= strndup(feature
, feature_len
);
760 case CFG_ADD_REG_TYPE
:
761 e
= jim_arc_read_reg_name_field(&goi
, &type_name
, &type_name_len
);
763 Jim_SetResultFormatted(goi
.interp
, "Unable to read register type.");
769 case CFG_ADD_REG_GENERAL
:
770 reg
->is_general
= true;
773 LOG_DEBUG("Error: Unknown parameter");
779 /* Check that required fields are set */
780 const char * const errmsg
= validate_register(reg
, arch_num_set
);
782 Jim_SetResultFormatted(goi
.interp
, errmsg
);
787 /* Add new register */
788 struct command_context
*ctx
;
789 struct target
*target
;
791 ctx
= current_command_context(interp
);
793 target
= get_current_target(ctx
);
795 Jim_SetResultFormatted(goi
.interp
, "No current target");
800 reg
->target
= target
;
802 e
= arc_reg_add(target
, reg
, type_name
, type_name_len
);
803 if (e
== ERROR_ARC_REGTYPE_NOT_FOUND
) {
804 Jim_SetResultFormatted(goi
.interp
,
805 "Cannot find type `%s' for register `%s'.",
806 type_name
, reg
->name
);
814 /* arc set-reg-exists ($reg_name)+
815 * Accepts any amount of register names - will set them as existing in a loop.*/
816 COMMAND_HANDLER(arc_set_reg_exists
)
818 struct target
* const target
= get_current_target(CMD_CTX
);
820 command_print(CMD
, "Unable to get current target.");
825 command_print(CMD
, "At least one register name must be specified.");
826 return ERROR_COMMAND_SYNTAX_ERROR
;
829 for (unsigned int i
= 0; i
< CMD_ARGC
; i
++) {
830 const char * const reg_name
= CMD_ARGV
[i
];
831 struct reg
* const r
= arc_reg_get_by_name(target
->reg_cache
, reg_name
, true);
834 command_print(CMD
, "Register `%s' is not found.", reg_name
);
835 return ERROR_COMMAND_ARGUMENT_INVALID
;
844 /* arc reg-field ($reg_name) ($reg_field)
845 * Reads struct type register field */
846 static int jim_arc_get_reg_field(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *argv
)
848 struct jim_getopt_info goi
;
849 const char *reg_name
, *field_name
;
853 JIM_CHECK_RETVAL(jim_getopt_setup(&goi
, interp
, argc
-1, argv
+1));
855 LOG_DEBUG("Reading register field");
858 Jim_WrongNumArgs(interp
, goi
.argc
, goi
.argv
, "<regname> <fieldname>");
859 else if (goi
.argc
== 1)
860 Jim_WrongNumArgs(interp
, goi
.argc
, goi
.argv
, "<fieldname>");
862 Jim_WrongNumArgs(interp
, goi
.argc
, goi
.argv
, "<regname> <fieldname>");
863 return ERROR_COMMAND_SYNTAX_ERROR
;
866 JIM_CHECK_RETVAL(jim_getopt_string(&goi
, ®_name
, NULL
));
867 JIM_CHECK_RETVAL(jim_getopt_string(&goi
, &field_name
, NULL
));
871 struct command_context
* const ctx
= current_command_context(interp
);
873 struct target
* const target
= get_current_target(ctx
);
875 Jim_SetResultFormatted(goi
.interp
, "No current target");
879 retval
= arc_reg_get_field(target
, reg_name
, field_name
, &value
);
884 case ERROR_ARC_REGISTER_NOT_FOUND
:
885 Jim_SetResultFormatted(goi
.interp
,
886 "Register `%s' has not been found.", reg_name
);
887 return ERROR_COMMAND_ARGUMENT_INVALID
;
888 case ERROR_ARC_REGISTER_IS_NOT_STRUCT
:
889 Jim_SetResultFormatted(goi
.interp
,
890 "Register `%s' must have 'struct' type.", reg_name
);
891 return ERROR_COMMAND_ARGUMENT_INVALID
;
892 case ERROR_ARC_REGISTER_FIELD_NOT_FOUND
:
893 Jim_SetResultFormatted(goi
.interp
,
894 "Field `%s' has not been found in register `%s'.",
895 field_name
, reg_name
);
896 return ERROR_COMMAND_ARGUMENT_INVALID
;
897 case ERROR_ARC_FIELD_IS_NOT_BITFIELD
:
898 Jim_SetResultFormatted(goi
.interp
,
899 "Field `%s' is not a 'bitfield' field in a structure.",
901 return ERROR_COMMAND_ARGUMENT_INVALID
;
903 /* Pass through other errors. */
907 Jim_SetResultInt(interp
, value
);
912 COMMAND_HANDLER(arc_l1_cache_disable_auto_cmd
)
916 struct arc_common
*arc
= target_to_arc(get_current_target(CMD_CTX
));
917 retval
= CALL_COMMAND_HANDLER(handle_command_parse_bool
,
918 &value
, "target has caches enabled");
919 arc
->has_l2cache
= value
;
920 arc
->has_dcache
= value
;
921 arc
->has_icache
= value
;
925 COMMAND_HANDLER(arc_l2_cache_disable_auto_cmd
)
927 struct arc_common
*arc
= target_to_arc(get_current_target(CMD_CTX
));
928 return CALL_COMMAND_HANDLER(handle_command_parse_bool
,
929 &arc
->has_l2cache
, "target has l2 cache enabled");
932 static int jim_handle_actionpoints_num(Jim_Interp
*interp
, int argc
,
933 Jim_Obj
* const *argv
)
935 struct jim_getopt_info goi
;
936 jim_getopt_setup(&goi
, interp
, argc
- 1, argv
+ 1);
941 Jim_WrongNumArgs(interp
, goi
.argc
, goi
.argv
, "[<unsigned integer>]");
945 struct command_context
*context
= current_command_context(interp
);
948 struct target
*target
= get_current_target(context
);
951 Jim_SetResultFormatted(goi
.interp
, "No current target");
955 struct arc_common
*arc
= target_to_arc(target
);
956 /* It is not possible to pass &arc->actionpoints_num directly to
957 * handle_command_parse_uint, because this value should be valid during
958 * "actionpoint reset, initiated by arc_set_actionpoints_num. */
959 uint32_t ap_num
= arc
->actionpoints_num
;
962 JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi
, &ap_num
));
963 int e
= arc_set_actionpoints_num(target
, ap_num
);
965 Jim_SetResultFormatted(goi
.interp
,
966 "Failed to set number of actionpoints");
971 Jim_SetResultInt(interp
, ap_num
);
976 /* ----- Exported target commands ------------------------------------------ */
978 static const struct command_registration arc_l2_cache_group_handlers
[] = {
981 .handler
= arc_l2_cache_disable_auto_cmd
,
984 .help
= "Disable or enable L2",
986 COMMAND_REGISTRATION_DONE
989 static const struct command_registration arc_cache_group_handlers
[] = {
992 .handler
= arc_l1_cache_disable_auto_cmd
,
994 .help
= "Disable or enable L1",
1000 .help
= "L2 cache command group",
1002 .chain
= arc_l2_cache_group_handlers
,
1004 COMMAND_REGISTRATION_DONE
1008 static const struct command_registration arc_core_command_handlers
[] = {
1010 .name
= "add-reg-type-flags",
1011 .jim_handler
= jim_arc_add_reg_type_flags
,
1012 .mode
= COMMAND_CONFIG
,
1013 .usage
= "-name <string> -flag <name> <position> "
1014 "[-flag <name> <position>]...",
1015 .help
= "Add new 'flags' register data type. Only single bit flags "
1016 "are supported. Type name is global. Bitsize of register is fixed "
1020 .name
= "add-reg-type-struct",
1021 .jim_handler
= jim_arc_add_reg_type_struct
,
1022 .mode
= COMMAND_CONFIG
,
1023 .usage
= "-name <string> -bitfield <name> <start> <end> "
1024 "[-bitfield <name> <start> <end>]...",
1025 .help
= "Add new 'struct' register data type. Only bit-fields are "
1026 "supported so far, which means that for each bitfield start and end "
1027 "position bits must be specified. GDB also support type-fields, "
1028 "where common type can be used instead. Type name is global. Bitsize of "
1029 "register is fixed at 32 bits.",
1033 .jim_handler
= jim_arc_add_reg
,
1034 .mode
= COMMAND_CONFIG
,
1035 .usage
= "-name <string> -num <int> -feature <string> [-gdbnum <int>] "
1036 "[-core|-bcr] [-type <type_name>] [-g]",
1037 .help
= "Add new register. Name, architectural number and feature name "
1038 "are required options. GDB regnum will default to previous register "
1039 "(gdbnum + 1) and shouldn't be specified in most cases. Type "
1040 "defaults to default GDB 'int'.",
1043 .name
= "set-reg-exists",
1044 .handler
= arc_set_reg_exists
,
1045 .mode
= COMMAND_ANY
,
1046 .usage
= "<register-name> [<register-name>]...",
1047 .help
= "Set that register exists. Accepts multiple register names as "
1051 .name
= "get-reg-field",
1052 .jim_handler
= jim_arc_get_reg_field
,
1053 .mode
= COMMAND_ANY
,
1054 .usage
= "<regname> <field_name>",
1055 .help
= "Returns value of field in a register with 'struct' type.",
1059 .mode
= COMMAND_ANY
,
1060 .help
= "ARC JTAG specific commands",
1062 .chain
= arc_jtag_command_group
,
1066 .mode
= COMMAND_ANY
,
1067 .help
= "cache command group",
1069 .chain
= arc_cache_group_handlers
,
1072 .name
= "num-actionpoints",
1073 .jim_handler
= jim_handle_actionpoints_num
,
1074 .mode
= COMMAND_ANY
,
1075 .usage
= "[<unsigned integer>]",
1076 .help
= "Prints or sets amount of actionpoints in the processor.",
1078 COMMAND_REGISTRATION_DONE
1081 const struct command_registration arc_monitor_command_handlers
[] = {
1084 .mode
= COMMAND_ANY
,
1085 .help
= "ARC monitor command group",
1087 .chain
= arc_core_command_handlers
,
1089 COMMAND_REGISTRATION_DONE
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)