target: make handle_md_output() global

Remove a copy of handle_md_output() from src/target/dsp563xx.c

Change-Id: Iadd003fd1dcdbc7990d46a58ee2e7c30826ac6af
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5175
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Tomas Vanek 2018-11-22 19:05:04 +01:00
parent 9ce5e8bc26
commit 51ef02a5d1
3 changed files with 8 additions and 64 deletions

View File

@ -1875,67 +1875,6 @@ static int dsp563xx_remove_watchpoint(struct target *target, struct watchpoint *
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
static void handle_md_output(struct command_invocation *cmd,
struct target *target,
uint32_t address,
unsigned size,
unsigned count,
const uint8_t *buffer)
{
const unsigned line_bytecnt = 32;
unsigned line_modulo = line_bytecnt / size;
char output[line_bytecnt * 4 + 1];
unsigned output_len = 0;
const char *value_fmt;
switch (size) {
case 4:
value_fmt = "%8.8x ";
break;
case 2:
value_fmt = "%4.4x ";
break;
case 1:
value_fmt = "%2.2x ";
break;
default:
/* "can't happen", caller checked */
LOG_ERROR("invalid memory read size: %u", size);
return;
}
for (unsigned i = 0; i < count; i++) {
if (i % line_modulo == 0)
output_len += snprintf(output + output_len,
sizeof(output) - output_len,
"0x%8.8x: ",
(unsigned) (address + i));
uint32_t value = 0;
const uint8_t *value_ptr = buffer + i * size;
switch (size) {
case 4:
value = target_buffer_get_u32(target, value_ptr);
break;
case 2:
value = target_buffer_get_u16(target, value_ptr);
break;
case 1:
value = *value_ptr;
}
output_len += snprintf(output + output_len,
sizeof(output) - output_len,
value_fmt,
value);
if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) {
command_print(cmd, "%s", output);
output_len = 0;
}
}
}
static int dsp563xx_add_custom_watchpoint(struct target *target, uint32_t address, uint32_t memType,
enum watchpoint_rw rw, enum watchpoint_condition cond)
{
@ -2208,7 +2147,7 @@ COMMAND_HANDLER(dsp563xx_mem_command)
err = dsp563xx_read_memory(target, mem_type, address, sizeof(uint32_t),
count, buffer);
if (err == ERROR_OK)
handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer);
target_handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer);
} else {
b = buffer;

View File

@ -3119,7 +3119,7 @@ COMMAND_HANDLER(handle_step_command)
return target->type->step(target, current_pc, addr, 1);
}
static void handle_md_output(struct command_invocation *cmd,
void target_handle_md_output(struct command_invocation *cmd,
struct target *target, target_addr_t address, unsigned size,
unsigned count, const uint8_t *buffer)
{
@ -3234,7 +3234,7 @@ COMMAND_HANDLER(handle_md_command)
struct target *target = get_current_target(CMD_CTX);
int retval = fn(target, address, size, count, buffer);
if (ERROR_OK == retval)
handle_md_output(CMD, target, address, size, count, buffer);
target_handle_md_output(CMD, target, address, size, count, buffer);
free(buffer);

View File

@ -36,6 +36,7 @@
struct reg;
struct trace;
struct command_context;
struct command_invocation;
struct breakpoint;
struct watchpoint;
struct mem_param;
@ -729,6 +730,10 @@ int target_arch_state(struct target *target);
void target_handle_event(struct target *t, enum target_event e);
void target_handle_md_output(struct command_invocation *cmd,
struct target *target, target_addr_t address, unsigned size,
unsigned count, const uint8_t *buffer);
#define ERROR_TARGET_INVALID (-300)
#define ERROR_TARGET_INIT_FAILED (-301)
#define ERROR_TARGET_TIMEOUT (-302)