Commit 9cb3af61 authored by zwelch's avatar zwelch
Browse files

Add wrappers for target->type->examined:

- replace all checks of target->type->examined with target_was_examined().
- replace all setting of target->type->examined with target_set_examined().
- replace clearing of target->type->examined with target_reset_examined().
- add documentation in target_s to warn not to access field directly.


git-svn-id: svn://svn.berlios.de/openocd/trunk@1962 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent fbe8cf72
...@@ -1631,7 +1631,7 @@ int arm11_examine(struct target_s *target) ...@@ -1631,7 +1631,7 @@ int arm11_examine(struct target_s *target)
arm11_check_init(arm11, NULL); arm11_check_init(arm11, NULL);
target->type->examined = 1; target_set_examined(target);
return ERROR_OK; return ERROR_OK;
} }
......
...@@ -818,7 +818,7 @@ int arm7_9_handle_target_request(void *priv) ...@@ -818,7 +818,7 @@ int arm7_9_handle_target_request(void *priv)
{ {
int retval = ERROR_OK; int retval = ERROR_OK;
target_t *target = priv; target_t *target = priv;
if (!target->type->examined) if (!target_was_examined(target))
return ERROR_OK; return ERROR_OK;
armv4_5_common_t *armv4_5 = target->arch_info; armv4_5_common_t *armv4_5 = target->arch_info;
arm7_9_common_t *arm7_9 = armv4_5->arch_info; arm7_9_common_t *arm7_9 = armv4_5->arch_info;
......
...@@ -718,7 +718,7 @@ int arm7tdmi_examine(struct target_s *target) ...@@ -718,7 +718,7 @@ int arm7tdmi_examine(struct target_s *target)
int retval; int retval;
armv4_5_common_t *armv4_5 = target->arch_info; armv4_5_common_t *armv4_5 = target->arch_info;
arm7_9_common_t *arm7_9 = armv4_5->arch_info; arm7_9_common_t *arm7_9 = armv4_5->arch_info;
if (!target->type->examined) if (!target_was_examined(target))
{ {
/* get pointers to arch-specific information */ /* get pointers to arch-specific information */
reg_cache_t **cache_p = register_get_last_cache_p(&target->reg_cache); reg_cache_t **cache_p = register_get_last_cache_p(&target->reg_cache);
...@@ -735,7 +735,7 @@ int arm7tdmi_examine(struct target_s *target) ...@@ -735,7 +735,7 @@ int arm7tdmi_examine(struct target_s *target)
(*cache_p)->next = etm_build_reg_cache(target, jtag_info, arm7_9->etm_ctx); (*cache_p)->next = etm_build_reg_cache(target, jtag_info, arm7_9->etm_ctx);
arm7_9->etm_ctx->reg_cache = (*cache_p)->next; arm7_9->etm_ctx->reg_cache = (*cache_p)->next;
} }
target->type->examined = 1; target_set_examined(target);
} }
if ((retval=embeddedice_setup(target))!=ERROR_OK) if ((retval=embeddedice_setup(target))!=ERROR_OK)
return retval; return retval;
......
...@@ -810,7 +810,7 @@ int arm9tdmi_examine(struct target_s *target) ...@@ -810,7 +810,7 @@ int arm9tdmi_examine(struct target_s *target)
int retval; int retval;
armv4_5_common_t *armv4_5 = target->arch_info; armv4_5_common_t *armv4_5 = target->arch_info;
arm7_9_common_t *arm7_9 = armv4_5->arch_info; arm7_9_common_t *arm7_9 = armv4_5->arch_info;
if (!target->type->examined) if (!target_was_examined(target))
{ {
reg_cache_t **cache_p = register_get_last_cache_p(&target->reg_cache); reg_cache_t **cache_p = register_get_last_cache_p(&target->reg_cache);
reg_cache_t *t; reg_cache_t *t;
...@@ -827,7 +827,7 @@ int arm9tdmi_examine(struct target_s *target) ...@@ -827,7 +827,7 @@ int arm9tdmi_examine(struct target_s *target)
(*cache_p)->next = etm_build_reg_cache(target, jtag_info, arm7_9->etm_ctx); (*cache_p)->next = etm_build_reg_cache(target, jtag_info, arm7_9->etm_ctx);
arm7_9->etm_ctx->reg_cache = (*cache_p)->next; arm7_9->etm_ctx->reg_cache = (*cache_p)->next;
} }
target->type->examined = 1; target_set_examined(target);
} }
if ((retval=embeddedice_setup(target))!=ERROR_OK) if ((retval=embeddedice_setup(target))!=ERROR_OK)
return retval; return retval;
......
...@@ -168,7 +168,7 @@ int cortex_a8_write_memory(struct target_s *target, u32 address, u32 size, u32 c ...@@ -168,7 +168,7 @@ int cortex_a8_write_memory(struct target_s *target, u32 address, u32 size, u32 c
int cortex_a8_handle_target_request(void *priv) int cortex_a8_handle_target_request(void *priv)
{ {
target_t *target = priv; target_t *target = priv;
if (!target->type->examined) if (!target_was_examined(target))
return ERROR_OK; return ERROR_OK;
armv7m_common_t *armv7m = target->arch_info; armv7m_common_t *armv7m = target->arch_info;
swjdp_common_t *swjdp = &armv7m->swjdp_info; swjdp_common_t *swjdp = &armv7m->swjdp_info;
......
...@@ -1429,9 +1429,9 @@ int cortex_m3_examine(struct target_s *target) ...@@ -1429,9 +1429,9 @@ int cortex_m3_examine(struct target_s *target)
if ((retval = ahbap_debugport_init(swjdp)) != ERROR_OK) if ((retval = ahbap_debugport_init(swjdp)) != ERROR_OK)
return retval; return retval;
if (!target->type->examined) if (!target_was_examined(target))
{ {
target->type->examined = 1; target_set_examined(target);
/* Read from Device Identification Registers */ /* Read from Device Identification Registers */
if ((retval = target_read_u32(target, CPUID, &cpuid)) != ERROR_OK) if ((retval = target_read_u32(target, CPUID, &cpuid)) != ERROR_OK)
...@@ -1526,7 +1526,7 @@ int cortex_m3_target_request_data(target_t *target, u32 size, u8 *buffer) ...@@ -1526,7 +1526,7 @@ int cortex_m3_target_request_data(target_t *target, u32 size, u8 *buffer)
int cortex_m3_handle_target_request(void *priv) int cortex_m3_handle_target_request(void *priv)
{ {
target_t *target = priv; target_t *target = priv;
if (!target->type->examined) if (!target_was_examined(target))
return ERROR_OK; return ERROR_OK;
armv7m_common_t *armv7m = target->arch_info; armv7m_common_t *armv7m = target->arch_info;
swjdp_common_t *swjdp = &armv7m->swjdp_info; swjdp_common_t *swjdp = &armv7m->swjdp_info;
......
...@@ -346,9 +346,9 @@ int mips32_examine(struct target_s *target) ...@@ -346,9 +346,9 @@ int mips32_examine(struct target_s *target)
{ {
mips32_common_t *mips32 = target->arch_info; mips32_common_t *mips32 = target->arch_info;
if (!target->type->examined) if (target_was_examined(target))
{ {
target->type->examined = 1; target_set_examined(target);
/* we will configure later */ /* we will configure later */
mips32->bp_scanned = 0; mips32->bp_scanned = 0;
......
...@@ -854,7 +854,7 @@ int mips_m4k_examine(struct target_s *target) ...@@ -854,7 +854,7 @@ int mips_m4k_examine(struct target_s *target)
mips_ejtag_t *ejtag_info = &mips32->ejtag_info; mips_ejtag_t *ejtag_info = &mips32->ejtag_info;
u32 idcode = 0; u32 idcode = 0;
if (!target->type->examined) if (!target_was_examined(target))
{ {
mips_ejtag_get_idcode(ejtag_info, &idcode, NULL); mips_ejtag_get_idcode(ejtag_info, &idcode, NULL);
ejtag_info->idcode = idcode; ejtag_info->idcode = idcode;
......
...@@ -384,7 +384,7 @@ target_t* get_current_target(command_context_t *cmd_ctx) ...@@ -384,7 +384,7 @@ target_t* get_current_target(command_context_t *cmd_ctx)
int target_poll(struct target_s *target) int target_poll(struct target_s *target)
{ {
/* We can't poll until after examine */ /* We can't poll until after examine */
if (!target->type->examined) if (!target_was_examined(target))
{ {
/* Fail silently lest we pollute the log */ /* Fail silently lest we pollute the log */
return ERROR_FAIL; return ERROR_FAIL;
...@@ -395,7 +395,7 @@ int target_poll(struct target_s *target) ...@@ -395,7 +395,7 @@ int target_poll(struct target_s *target)
int target_halt(struct target_s *target) int target_halt(struct target_s *target)
{ {
/* We can't poll until after examine */ /* We can't poll until after examine */
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -408,7 +408,7 @@ int target_resume(struct target_s *target, int current, u32 address, int handle_ ...@@ -408,7 +408,7 @@ int target_resume(struct target_s *target, int current, u32 address, int handle_
int retval; int retval;
/* We can't poll until after examine */ /* We can't poll until after examine */
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -463,7 +463,7 @@ static int default_mmu(struct target_s *target, int *enabled) ...@@ -463,7 +463,7 @@ static int default_mmu(struct target_s *target, int *enabled)
static int default_examine(struct target_s *target) static int default_examine(struct target_s *target)
{ {
target->type->examined = 1; target_set_examined(target);
return ERROR_OK; return ERROR_OK;
} }
...@@ -487,7 +487,7 @@ int target_examine(void) ...@@ -487,7 +487,7 @@ int target_examine(void)
static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer) static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
{ {
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -497,7 +497,7 @@ static int target_write_memory_imp(struct target_s *target, u32 address, u32 siz ...@@ -497,7 +497,7 @@ static int target_write_memory_imp(struct target_s *target, u32 address, u32 siz
static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer) static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
{ {
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -507,7 +507,7 @@ static int target_read_memory_imp(struct target_s *target, u32 address, u32 size ...@@ -507,7 +507,7 @@ static int target_read_memory_imp(struct target_s *target, u32 address, u32 size
static int target_soft_reset_halt_imp(struct target_s *target) static int target_soft_reset_halt_imp(struct target_s *target)
{ {
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -517,7 +517,7 @@ static int target_soft_reset_halt_imp(struct target_s *target) ...@@ -517,7 +517,7 @@ static int target_soft_reset_halt_imp(struct target_s *target)
static int target_run_algorithm_imp(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_params, reg_param_t *reg_param, u32 entry_point, u32 exit_point, int timeout_ms, void *arch_info) static int target_run_algorithm_imp(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_params, reg_param_t *reg_param, u32 entry_point, u32 exit_point, int timeout_ms, void *arch_info)
{ {
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -548,6 +548,22 @@ int target_run_algorithm(struct target_s *target, ...@@ -548,6 +548,22 @@ int target_run_algorithm(struct target_s *target,
entry_point, exit_point, timeout_ms, arch_info); entry_point, exit_point, timeout_ms, arch_info);
} }
/// @returns @c true if the target has been examined.
bool target_was_examined(struct target_s *target)
{
return target->type->examined;
}
/// Sets the @c examined flag for the given target.
void target_set_examined(struct target_s *target)
{
target->type->examined = true;
}
// Reset the @c examined flag for the given target.
void target_reset_examined(struct target_s *target)
{
target->type->examined = false;
}
int target_init(struct command_context_s *cmd_ctx) int target_init(struct command_context_s *cmd_ctx)
{ {
...@@ -556,7 +572,7 @@ int target_init(struct command_context_s *cmd_ctx) ...@@ -556,7 +572,7 @@ int target_init(struct command_context_s *cmd_ctx)
while (target) while (target)
{ {
target->type->examined = 0; target_reset_examined(target);
if (target->type->examine == NULL) if (target->type->examine == NULL)
{ {
target->type->examine = default_examine; target->type->examine = default_examine;
...@@ -1003,7 +1019,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff ...@@ -1003,7 +1019,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
int retval; int retval;
LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address); LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address);
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1082,7 +1098,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe ...@@ -1082,7 +1098,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
int retval; int retval;
LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address); LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address);
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1149,7 +1165,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32* ...@@ -1149,7 +1165,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
int retval; int retval;
u32 i; u32 i;
u32 checksum = 0; u32 checksum = 0;
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1191,7 +1207,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32* ...@@ -1191,7 +1207,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank) int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank)
{ {
int retval; int retval;
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1208,7 +1224,7 @@ int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u3 ...@@ -1208,7 +1224,7 @@ int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u3
int target_read_u32(struct target_s *target, u32 address, u32 *value) int target_read_u32(struct target_s *target, u32 address, u32 *value)
{ {
u8 value_buf[4]; u8 value_buf[4];
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1233,7 +1249,7 @@ int target_read_u32(struct target_s *target, u32 address, u32 *value) ...@@ -1233,7 +1249,7 @@ int target_read_u32(struct target_s *target, u32 address, u32 *value)
int target_read_u16(struct target_s *target, u32 address, u16 *value) int target_read_u16(struct target_s *target, u32 address, u16 *value)
{ {
u8 value_buf[2]; u8 value_buf[2];
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1258,7 +1274,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value) ...@@ -1258,7 +1274,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 target_read_u8(struct target_s *target, u32 address, u8 *value)
{ {
int retval = target_read_memory(target, address, 1, 1, value); int retval = target_read_memory(target, address, 1, 1, value);
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1281,7 +1297,7 @@ int target_write_u32(struct target_s *target, u32 address, u32 value) ...@@ -1281,7 +1297,7 @@ int target_write_u32(struct target_s *target, u32 address, u32 value)
{ {
int retval; int retval;
u8 value_buf[4]; u8 value_buf[4];
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1302,7 +1318,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value) ...@@ -1302,7 +1318,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
{ {
int retval; int retval;
u8 value_buf[2]; u8 value_buf[2];
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -1322,7 +1338,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value) ...@@ -1322,7 +1338,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
int target_write_u8(struct target_s *target, u32 address, u8 value) int target_write_u8(struct target_s *target, u32 address, u8 value)
{ {
int retval; int retval;
if (!target->type->examined) if (!target_was_examined(target))
{ {
LOG_ERROR("Target not examined yet"); LOG_ERROR("Target not examined yet");
return ERROR_FAIL; return ERROR_FAIL;
...@@ -3682,7 +3698,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) ...@@ -3682,7 +3698,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]"); Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]");
return JIM_ERR; return JIM_ERR;
} }
if( !(target->type->examined) ){ if( !(target_was_examined(target)) ){
e = ERROR_TARGET_NOT_EXAMINED; e = ERROR_TARGET_NOT_EXAMINED;
} else { } else {
e = target->type->poll( target ); e = target->type->poll( target );
......
...@@ -109,6 +109,12 @@ typedef struct target_type_s ...@@ -109,6 +109,12 @@ typedef struct target_type_s
{ {
char *name; char *name;
/**
* Indicates whether this target has been examined.
*
* Do @b not access this field directly, use target_was_examined()
* target_set_examined(), and target_reset_examined().
*/
int examined; int examined;
/* poll current target status */ /* poll current target status */
...@@ -383,6 +389,13 @@ extern target_t* get_current_target(struct command_context_s *cmd_ctx); ...@@ -383,6 +389,13 @@ extern target_t* get_current_target(struct command_context_s *cmd_ctx);
extern int get_num_by_target(target_t *query_target); extern int get_num_by_target(target_t *query_target);
extern target_t *get_target(const char *id); extern target_t *get_target(const char *id);
/// @returns @c true if the target has been examined.
extern bool target_was_examined(struct target_s *target);
/// Sets the @c examined flag for the given target.
extern void target_set_examined(struct target_s *target);
/// Reset the @c examined flag for the given target.
extern void target_reset_examined(struct target_s *target);
/** /**
* Run an algorithm on the @a target given. * Run an algorithm on the @a target given.
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment