How to set register from a variable value in openocd

78 views Asked by At

I wish to set a register value from a variable. In the following it is the stack pointer, but should be the same for any other register.

To set a register value there is a set_reg function: https://openocd.org/doc/html/General-Commands.html#:~:text=Command%3A%20set_reg%20dict

Which works with:

> set_reg {sp 0x1337}
> get_reg sp
sp 0x1337

However it does not seem to work, if I instead try to set it from a variable value:

> set new_sp 0x1337
> echo $new_sp
0x1337
> set_reg {sp $new_sp}
> get_reg sp
sp 0x00001337

So, how do you set register values from a variable?

1

There are 1 answers

0
Heneer On

The "set_reg" command takes a dictionary as argument. So one way is to first create a dictionary with the values and then use that to set the registers.

> set new_sp 0x1337
> dict set dict_register sp $new_sp
> set_reg $dict_register
> get_reg sp
sp 0x00001337

See: https://www.tcl-lang.org/man/tcl8.5/tutorial/Tcl23a.html