summaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-05-31 09:37:35 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-05-31 09:37:35 +0000
commitb6db182c0020051e0dc642ca0b1040ea7453dcd0 (patch)
tree17a4074984d6f72033f252e2e3361fd90cc8b96e /src/target
parent678519311834fd7a1126f8d217c734d4f5ffbb3d (diff)
downloadopenocd_libswd-b6db182c0020051e0dc642ca0b1040ea7453dcd0.tar.gz
openocd_libswd-b6db182c0020051e0dc642ca0b1040ea7453dcd0.tar.bz2
openocd_libswd-b6db182c0020051e0dc642ca0b1040ea7453dcd0.tar.xz
openocd_libswd-b6db182c0020051e0dc642ca0b1040ea7453dcd0.zip
Add target_read_memory wrapper:
- replaces all calls to target->type->read_memory. - add documentation in target_s to warn not to invoke callback directly. git-svn-id: svn://svn.berlios.de/openocd/trunk@1959 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/target')
-rw-r--r--src/target/arm7_9_common.c8
-rw-r--r--src/target/cortex_m3.c2
-rw-r--r--src/target/mips_m4k.c8
-rw-r--r--src/target/target.c30
-rw-r--r--src/target/target.h13
-rw-r--r--src/target/xscale.c4
6 files changed, 42 insertions, 23 deletions
diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c
index 12ee62f9..48263efe 100644
--- a/src/target/arm7_9_common.c
+++ b/src/target/arm7_9_common.c
@@ -274,7 +274,7 @@ int arm7_9_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
u32 verify = 0xffffffff;
/* keep the original instruction in target endianness */
- if ((retval = target->type->read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
+ if ((retval = target_read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
@@ -298,7 +298,7 @@ int arm7_9_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
u16 verify = 0xffff;
/* keep the original instruction in target endianness */
- if ((retval = target->type->read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
+ if ((retval = target_read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
@@ -373,7 +373,7 @@ int arm7_9_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
u32 current_instr;
/* check that user program as not modified breakpoint instruction */
- if ((retval = target->type->read_memory(target, breakpoint->address, 4, 1, (u8*)&current_instr)) != ERROR_OK)
+ if ((retval = target_read_memory(target, breakpoint->address, 4, 1, (u8*)&current_instr)) != ERROR_OK)
{
return retval;
}
@@ -387,7 +387,7 @@ int arm7_9_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
u16 current_instr;
/* check that user program as not modified breakpoint instruction */
- if ((retval = target->type->read_memory(target, breakpoint->address, 2, 1, (u8*)&current_instr)) != ERROR_OK)
+ if ((retval = target_read_memory(target, breakpoint->address, 2, 1, (u8*)&current_instr)) != ERROR_OK)
{
return retval;
}
diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c
index 4a032ee0..6f51d91b 100644
--- a/src/target/cortex_m3.c
+++ b/src/target/cortex_m3.c
@@ -930,7 +930,7 @@ int cortex_m3_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
u8 code[4];
buf_set_u32(code, 0, 32, ARMV7M_T_BKPT(0x11));
- if((retval = target->type->read_memory(target, breakpoint->address & 0xFFFFFFFE, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK)
+ if((retval = target_read_memory(target, breakpoint->address & 0xFFFFFFFE, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c
index 6d331d4e..a16590c8 100644
--- a/src/target/mips_m4k.c
+++ b/src/target/mips_m4k.c
@@ -529,7 +529,7 @@ int mips_m4k_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
u32 verify = 0xffffffff;
- if((retval = target->type->read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK)
+ if((retval = target_read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
@@ -552,7 +552,7 @@ int mips_m4k_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
u16 verify = 0xffff;
- if((retval = target->type->read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK)
+ if((retval = target_read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
@@ -611,7 +611,7 @@ int mips_m4k_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
u32 current_instr;
/* check that user program has not modified breakpoint instruction */
- if ((retval = target->type->read_memory(target, breakpoint->address, 4, 1, (u8*)&current_instr)) != ERROR_OK)
+ if ((retval = target_read_memory(target, breakpoint->address, 4, 1, (u8*)&current_instr)) != ERROR_OK)
{
return retval;
}
@@ -628,7 +628,7 @@ int mips_m4k_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
u16 current_instr;
/* check that user program has not modified breakpoint instruction */
- if ((retval = target->type->read_memory(target, breakpoint->address, 2, 1, (u8*)&current_instr)) != ERROR_OK)
+ if ((retval = target_read_memory(target, breakpoint->address, 2, 1, (u8*)&current_instr)) != ERROR_OK)
{
return retval;
}
diff --git a/src/target/target.c b/src/target/target.c
index d56f5e31..5b75c348 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -525,6 +525,12 @@ static int target_run_algorithm_imp(struct target_s *target, int num_mem_params,
return target->type->run_algorithm_imp(target, num_mem_params, mem_params, num_reg_params, reg_param, entry_point, exit_point, timeout_ms, arch_info);
}
+int target_read_memory(struct target_s *target,
+ u32 address, u32 size, u32 count, u8 *buffer)
+{
+ return target->type->read_memory(target, address, size, count, buffer);
+}
+
int target_init(struct command_context_s *cmd_ctx)
{
target_t *target = all_targets;
@@ -858,7 +864,7 @@ int target_alloc_working_area(struct target_s *target, u32 size, working_area_t
{
int retval;
new_wa->backup = malloc(new_wa->size);
- if((retval = target->type->read_memory(target, new_wa->address, 4, new_wa->size / 4, new_wa->backup)) != ERROR_OK)
+ if((retval = target_read_memory(target, new_wa->address, 4, new_wa->size / 4, new_wa->backup)) != ERROR_OK)
{
free(new_wa->backup);
free(new_wa);
@@ -1077,7 +1083,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
if (((address % 2) == 0) && (size == 2))
{
- return target->type->read_memory(target, address, 2, 1, buffer);
+ return target_read_memory(target, address, 2, 1, buffer);
}
/* handle unaligned head bytes */
@@ -1088,7 +1094,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
if (unaligned > size)
unaligned = size;
- if ((retval = target->type->read_memory(target, address, 1, unaligned, buffer)) != ERROR_OK)
+ if ((retval = target_read_memory(target, address, 1, unaligned, buffer)) != ERROR_OK)
return retval;
buffer += unaligned;
@@ -1101,7 +1107,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
{
int aligned = size - (size % 4);
- if ((retval = target->type->read_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
+ if ((retval = target_read_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
return retval;
buffer += aligned;
@@ -1112,7 +1118,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
/* handle tail writes of less than 4 bytes */
if (size > 0)
{
- if ((retval = target->type->read_memory(target, address, 1, size, buffer)) != ERROR_OK)
+ if ((retval = target_read_memory(target, address, 1, size, buffer)) != ERROR_OK)
return retval;
}
@@ -1190,7 +1196,7 @@ int target_read_u32(struct target_s *target, u32 address, u32 *value)
return ERROR_FAIL;
}
- int retval = target->type->read_memory(target, address, 4, 1, value_buf);
+ int retval = target_read_memory(target, address, 4, 1, value_buf);
if (retval == ERROR_OK)
{
@@ -1215,7 +1221,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value)
return ERROR_FAIL;
}
- int retval = target->type->read_memory(target, address, 2, 1, value_buf);
+ int retval = target_read_memory(target, address, 2, 1, value_buf);
if (retval == ERROR_OK)
{
@@ -1233,7 +1239,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value)
int target_read_u8(struct target_s *target, u32 address, u8 *value)
{
- int retval = target->type->read_memory(target, address, 1, 1, value);
+ int retval = target_read_memory(target, address, 1, 1, value);
if (!target->type->examined)
{
LOG_ERROR("Target not examined yet");
@@ -1914,7 +1920,7 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char
u8 *buffer = calloc(count, size);
target_t *target = get_current_target(cmd_ctx);
- int retval = target->type->read_memory(target,
+ int retval = target_read_memory(target,
address, size, count, buffer);
if (ERROR_OK == retval)
handle_md_output(cmd_ctx, target, address, size, count, buffer);
@@ -2256,7 +2262,7 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct
size *= 4;
count /= 4;
}
- retval = target->type->read_memory(target, image.sections[i].base_address, size, count, data);
+ retval = target_read_memory(target, image.sections[i].base_address, size, count, data);
if (retval == ERROR_OK)
{
u32 t;
@@ -2829,7 +2835,7 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_
count = (sizeof(buffer)/width);
}
- retval = target->type->read_memory( target, addr, width, count, buffer );
+ retval = target_read_memory( target, addr, width, count, buffer );
if (retval != ERROR_OK) {
/* BOO !*/
LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", addr, width, count);
@@ -3575,7 +3581,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
if( y > 16 ){
y = 16;
}
- e = target->type->read_memory( target, a, b, y / b, target_buf );
+ e = target_read_memory( target, a, b, y / b, target_buf );
if( e != ERROR_OK ){
Jim_SetResult_sprintf( interp, "error reading target @ 0x%08lx", (int)(a) );
return JIM_ERR;
diff --git a/src/target/target.h b/src/target/target.h
index 09f8e9c3..b11e2b6b 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -161,6 +161,10 @@ typedef struct target_type_s
* count: number of items of <size>
*/
int (*read_memory_imp)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
+ /**
+ * Target memory read callback. Do @b not call this function
+ * directly, use target_read_memory() instead.
+ */
int (*read_memory)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
int (*write_memory_imp)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
int (*write_memory)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
@@ -371,6 +375,15 @@ extern target_t* get_current_target(struct command_context_s *cmd_ctx);
extern int get_num_by_target(target_t *query_target);
extern target_t *get_target(const char *id);
+/**
+ * Read @count items of @a size bytes from the memory of @a target at
+ * the @a address given.
+ *
+ * This routine is a wrapper for target->type->read_memory.
+ */
+extern int target_read_memory(struct target_s *target,
+ u32 address, u32 size, u32 count, u8 *buffer);
+
extern int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer);
extern int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer);
extern int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32* crc);
diff --git a/src/target/xscale.c b/src/target/xscale.c
index 3947da0b..f200e8ce 100644
--- a/src/target/xscale.c
+++ b/src/target/xscale.c
@@ -2187,7 +2187,7 @@ int xscale_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
if (breakpoint->length == 4)
{
/* keep the original instruction in target endianness */
- if((retval = target->type->read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
+ if((retval = target_read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
@@ -2200,7 +2200,7 @@ int xscale_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
else
{
/* keep the original instruction in target endianness */
- if((retval = target->type->read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
+ if((retval = target_read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}