From 6738e447c5c010c4b3451e3714df86e9ab653e1f Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 23 May 2018 00:55:03 +0200 Subject: [PATCH] target/arm_adi_v5: add command "dpreg" For very low level debug or development around DAP, it is useful to have direct access to DP registers. Add command "dpreg" by mimic the syntax of the existing "apreg" command: $dap_name dpreg reg [value] Change-Id: Ic4ab451eb5e74453133adee61050b4c6f656ffa3 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/4612 Tested-by: jenkins Reviewed-by: Tomas Vanek --- doc/openocd.texi | 12 ++++++++++++ src/target/arm_adi_v5.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/doc/openocd.texi b/doc/openocd.texi index 16aa26bf..def0c9d6 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4087,6 +4087,18 @@ or set a new value @var{value}. Select AP @var{num}, defaulting to 0. @end deffn +@deffn Command {$dap_name dpreg} reg [value] +Displays the content of DP register at address @var{reg}, or set it to a new +value @var{value}. + +In case of SWD, @var{reg} is a value in packed format +@math{dpbanksel << 4 | addr} and assumes values 0, 4, 8 ... 0xfc. +In case of JTAG it only assumes values 0, 4, 8 and 0xc. + +@emph{Note:} Consider using @command{poll off} to avoid any disturbing +background activity by OpenOCD while you are operating at such low-level. +@end deffn + @deffn Command {$dap_name baseaddr} [num] Displays debug base address from MEM-AP @var{num}, defaulting to the currently selected AP. diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 4dc2594c..dc5c8039 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -1772,6 +1772,37 @@ COMMAND_HANDLER(dap_apreg_command) return retval; } +COMMAND_HANDLER(dap_dpreg_command) +{ + struct adiv5_dap *dap = adiv5_get_dap(CMD_DATA); + uint32_t reg, value; + int retval; + + if (CMD_ARGC < 1 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; + + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], reg); + if (reg >= 256 || (reg & 3)) + return ERROR_COMMAND_SYNTAX_ERROR; + + if (CMD_ARGC == 2) { + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); + retval = dap_queue_dp_write(dap, reg, value); + } else { + retval = dap_queue_dp_read(dap, reg, &value); + } + if (retval == ERROR_OK) + retval = dap_run(dap); + + if (retval != ERROR_OK) + return retval; + + if (CMD_ARGC == 1) + command_print(CMD_CTX, "0x%08" PRIx32, value); + + return retval; +} + COMMAND_HANDLER(dap_ti_be_32_quirks_command) { struct adiv5_dap *dap = adiv5_get_dap(CMD_DATA); @@ -1836,6 +1867,14 @@ const struct command_registration dap_instance_commands[] = { "(reg is byte address of a word register, like 0 4 8...)", .usage = "ap_num reg [value]", }, + { + .name = "dpreg", + .handler = dap_dpreg_command, + .mode = COMMAND_EXEC, + .help = "read/write a register from DP " + "(reg is byte address (bank << 4 | reg) of a word register, like 0 4 8...)", + .usage = "reg [value]", + }, { .name = "baseaddr", .handler = dap_baseaddr_command, -- 2.39.5