target/tcl: Add set_reg function
Change-Id: I97a01b93046cb7af289792489f77f5580312585a Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: https://review.openocd.org/c/openocd/+/5313 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
parent
8b740af10d
commit
da73280101
|
@ -5003,6 +5003,21 @@ and neither store nor return those values.
|
||||||
@end itemize
|
@end itemize
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn {Command} {$target_name set_reg} dict
|
||||||
|
Set register values of the target.
|
||||||
|
|
||||||
|
@itemize
|
||||||
|
@item @var{dict} ... Tcl dictionary with pairs of register names and values.
|
||||||
|
@end itemize
|
||||||
|
|
||||||
|
For example, the following command sets the value 0 to the program counter (pc)
|
||||||
|
register and 0x1000 to the stack pointer (sp) register:
|
||||||
|
|
||||||
|
@example
|
||||||
|
set_reg @{pc 0 sp 0x1000@}
|
||||||
|
@end example
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deffn {Command} {$target_name cget} queryparm
|
@deffn {Command} {$target_name cget} queryparm
|
||||||
Each configuration parameter accepted by
|
Each configuration parameter accepted by
|
||||||
@command{$target_name configure}
|
@command{$target_name configure}
|
||||||
|
@ -8491,6 +8506,21 @@ Debug and trace infrastructure:
|
||||||
@end example
|
@end example
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn {Command} {set_reg} dict
|
||||||
|
Set register values of the target.
|
||||||
|
|
||||||
|
@itemize
|
||||||
|
@item @var{dict} ... Tcl dictionary with pairs of register names and values.
|
||||||
|
@end itemize
|
||||||
|
|
||||||
|
For example, the following command sets the value 0 to the program counter (pc)
|
||||||
|
register and 0x1000 to the stack pointer (sp) register:
|
||||||
|
|
||||||
|
@example
|
||||||
|
set_reg @{pc 0 sp 0x1000@}
|
||||||
|
@end example
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deffn {Command} {halt} [ms]
|
@deffn {Command} {halt} [ms]
|
||||||
@deffnx {Command} {wait_halt} [ms]
|
@deffnx {Command} {wait_halt} [ms]
|
||||||
The @command{halt} command first sends a halt request to the target,
|
The @command{halt} command first sends a halt request to the target,
|
||||||
|
|
|
@ -4863,6 +4863,57 @@ void target_handle_event(struct target *target, enum target_event e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int target_jim_set_reg(Jim_Interp *interp, int argc,
|
||||||
|
Jim_Obj * const *argv)
|
||||||
|
{
|
||||||
|
if (argc != 2) {
|
||||||
|
Jim_WrongNumArgs(interp, 1, argv, "dict");
|
||||||
|
return JIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tmp;
|
||||||
|
Jim_Obj **dict = Jim_DictPairs(interp, argv[1], &tmp);
|
||||||
|
|
||||||
|
if (!dict)
|
||||||
|
return JIM_ERR;
|
||||||
|
|
||||||
|
const unsigned int length = tmp;
|
||||||
|
struct command_context *cmd_ctx = current_command_context(interp);
|
||||||
|
assert(cmd_ctx);
|
||||||
|
const struct target *target = get_current_target(cmd_ctx);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < length; i += 2) {
|
||||||
|
const char *reg_name = Jim_String(dict[i]);
|
||||||
|
const char *reg_value = Jim_String(dict[i + 1]);
|
||||||
|
struct reg *reg = register_get_by_name(target->reg_cache, reg_name,
|
||||||
|
false);
|
||||||
|
|
||||||
|
if (!reg || !reg->exist) {
|
||||||
|
Jim_SetResultFormatted(interp, "unknown register '%s'", reg_name);
|
||||||
|
return JIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *buf = malloc(DIV_ROUND_UP(reg->size, 8));
|
||||||
|
|
||||||
|
if (!buf) {
|
||||||
|
LOG_ERROR("Failed to allocate memory");
|
||||||
|
return JIM_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
str_to_buf(reg_value, strlen(reg_value), buf, reg->size, 0);
|
||||||
|
int retval = reg->type->set(reg, buf);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
if (retval != ERROR_OK) {
|
||||||
|
Jim_SetResultFormatted(interp, "failed to set '%s' to register '%s'",
|
||||||
|
reg_value, reg_name);
|
||||||
|
return JIM_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return JIM_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true only if the target has a handler for the specified event.
|
* Returns true only if the target has a handler for the specified event.
|
||||||
*/
|
*/
|
||||||
|
@ -5645,6 +5696,13 @@ static const struct command_registration target_instance_command_handlers[] = {
|
||||||
"from target memory",
|
"from target memory",
|
||||||
.usage = "arrayname bitwidth address count",
|
.usage = "arrayname bitwidth address count",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "set_reg",
|
||||||
|
.mode = COMMAND_EXEC,
|
||||||
|
.jim_handler = target_jim_set_reg,
|
||||||
|
.help = "Set target register values",
|
||||||
|
.usage = "dict",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = "eventlist",
|
.name = "eventlist",
|
||||||
.handler = handle_target_event_list,
|
.handler = handle_target_event_list,
|
||||||
|
@ -6727,6 +6785,13 @@ static const struct command_registration target_exec_command_handlers[] = {
|
||||||
"and write the 8/16/32 bit values",
|
"and write the 8/16/32 bit values",
|
||||||
.usage = "arrayname bitwidth address count",
|
.usage = "arrayname bitwidth address count",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "set_reg",
|
||||||
|
.mode = COMMAND_EXEC,
|
||||||
|
.jim_handler = target_jim_set_reg,
|
||||||
|
.help = "Set target register values",
|
||||||
|
.usage = "dict",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = "reset_nag",
|
.name = "reset_nag",
|
||||||
.handler = handle_target_reset_nag,
|
.handler = handle_target_reset_nag,
|
||||||
|
|
Loading…
Reference in New Issue