This is an automated email from Gerrit. Andreas Fritiofson ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/2284
-- gerrit commit 6fadfe5f258d2009ff1725f85f4adc42fea3c2e1 Author: Andreas Fritiofson <[email protected]> Date: Mon Aug 4 23:10:19 2014 +0200 Replace scratchpad API with a field in the target specific struct Change-Id: If163acc785804936c008ca37812b735d1647571f Signed-off-by: Andreas Fritiofson <[email protected]> diff --git a/src/target/armv7m.c b/src/target/armv7m.c index 94bfc07..9abd59e 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -44,13 +44,6 @@ #define _DEBUG_INSTRUCTION_EXECUTION_ #endif -struct armv7m_algorithm_scratchpad { - int common_magic; - enum arm_mode core_mode; - uint32_t context[ARMV7M_LAST_REG]; /* ARMV7M_NUM_REGS */ -}; - - static char *armv7m_exception_strings[] = { "", "Reset", "NMI", "HardFault", "MemManage", "BusFault", "UsageFault", "RESERVED", @@ -301,19 +294,12 @@ int armv7m_start_algorithm(struct target *target, uint32_t entry_point, uint32_t exit_point, void *arch_info) { - struct armv7m_algorithm_scratchpad *scratchpad; struct armv7m_common *armv7m = target_to_armv7m(target); + struct armv7m_algorithm_scratchpad *scratchpad = &armv7m->scratchpad; struct armv7m_algorithm *armv7m_algorithm_info = arch_info; enum arm_mode core_mode = armv7m->arm.core_mode; int retval = ERROR_OK; - scratchpad = target_allocate_algorithm_scratchpad(target, - sizeof(struct armv7m_algorithm_scratchpad)); - if (!scratchpad) { - LOG_ERROR("can't allocate a scratchpad area to run the algorithm"); - return ERROR_FAIL; - } - /* NOTE: armv7m_run_algorithm requires that each algorithm uses a software breakpoint * at the exit point */ @@ -322,8 +308,6 @@ int armv7m_start_algorithm(struct target *target, return ERROR_TARGET_INVALID; } - scratchpad->common_magic = armv7m_algorithm_info->common_magic; - if (target->state != TARGET_HALTED) { LOG_WARNING("target not halted"); return ERROR_TARGET_NOT_HALTED; @@ -331,7 +315,7 @@ int armv7m_start_algorithm(struct target *target, /* refresh core register cache * Not needed if core register cache is always consistent with target process state */ - for (unsigned i = 0; i < ARRAY_SIZE(scratchpad->context); i++) { + for (unsigned i = 0; i < ARMV7M_NUM_REGS; i++) { struct reg *r = &armv7m->arm.core_cache->reg_list[i]; scratchpad->context[i] = buf_get_u32(r->value, 0, 32); } @@ -396,39 +380,25 @@ int armv7m_wait_algorithm(struct target *target, uint32_t exit_point, int timeout_ms, void *arch_info) { - const struct armv7m_algorithm_scratchpad *scratchpad; struct armv7m_common *armv7m = target_to_armv7m(target); + const struct armv7m_algorithm_scratchpad *scratchpad = &armv7m->scratchpad; int retval = ERROR_OK; uint32_t pc; - scratchpad = target_get_algorithm_scratchpad(target); - - if (!scratchpad) { - LOG_ERROR("scratchpad area was not previously allocated"); - return ERROR_FAIL; - } - /* NOTE: armv7m_run_algorithm requires that each algorithm uses a software breakpoint * at the exit point */ - if (scratchpad->common_magic != ARMV7M_COMMON_MAGIC) { - LOG_ERROR("current target isn't an ARMV7M target"); - retval = ERROR_TARGET_INVALID; - goto free_scratchpad; - } - retval = target_wait_state(target, TARGET_HALTED, timeout_ms); /* If the target fails to halt due to the breakpoint, force a halt */ if (retval != ERROR_OK || target->state != TARGET_HALTED) { retval = target_halt(target); if (retval != ERROR_OK) - goto free_scratchpad; + return retval; retval = target_wait_state(target, TARGET_HALTED, 500); if (retval != ERROR_OK) - goto free_scratchpad; - retval = ERROR_TARGET_TIMEOUT; - goto free_scratchpad; + return retval; + return ERROR_TARGET_TIMEOUT; } armv7m->load_core_reg_u32(target, 15, &pc); @@ -436,8 +406,7 @@ int armv7m_wait_algorithm(struct target *target, LOG_DEBUG("failed algorithm halted at 0x%" PRIx32 ", expected 0x%" PRIx32, pc, exit_point); - retval = ERROR_TARGET_TIMEOUT; - goto free_scratchpad; + return ERROR_TARGET_TIMEOUT; } /* Read memory values to mem_params[] */ @@ -447,7 +416,7 @@ int armv7m_wait_algorithm(struct target *target, mem_params[i].size, mem_params[i].value); if (retval != ERROR_OK) - goto free_scratchpad; + return retval; } } @@ -460,16 +429,14 @@ int armv7m_wait_algorithm(struct target *target, if (!reg) { LOG_ERROR("BUG: register '%s' not found", reg_params[i].reg_name); - retval = ERROR_COMMAND_SYNTAX_ERROR; - goto free_scratchpad; + return ERROR_COMMAND_SYNTAX_ERROR; } if (reg->size != reg_params[i].size) { LOG_ERROR( "BUG: register '%s' size doesn't match reg_params[i].size", reg_params[i].reg_name); - retval = ERROR_COMMAND_SYNTAX_ERROR; - goto free_scratchpad; + return ERROR_COMMAND_SYNTAX_ERROR; } buf_set_u32(reg_params[i].value, 0, 32, buf_get_u32(reg->value, 0, 32)); @@ -503,8 +470,6 @@ int armv7m_wait_algorithm(struct target *target, armv7m->arm.core_mode = scratchpad->core_mode; -free_scratchpad: - target_free_algorithm_scratchpad(target); return retval; } diff --git a/src/target/armv7m.h b/src/target/armv7m.h index 2ebad87..7979056 100644 --- a/src/target/armv7m.h +++ b/src/target/armv7m.h @@ -139,6 +139,11 @@ enum { #define ARMV7M_COMMON_MAGIC 0x2A452A45 +struct armv7m_algorithm_scratchpad { + enum arm_mode core_mode; + uint32_t context[ARMV7M_LAST_REG]; /* ARMV7M_NUM_REGS */ +}; + struct armv7m_common { struct arm arm; @@ -149,6 +154,9 @@ struct armv7m_common { int fp_feature; uint32_t demcr; + /* Holds saved context during algorithm execution */ + struct armv7m_algorithm_scratchpad scratchpad; + /* stlink is a high level adapter, does not support all functions */ bool stlink; diff --git a/src/target/target.c b/src/target/target.c index 6c89138..8d84b84 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -809,28 +809,6 @@ done: return retval; } -void *target_allocate_algorithm_scratchpad(struct target *target, - size_t size) -{ - if (target->algorithm_scratchpad) { - LOG_WARNING("scratchpad area was not previously deallocated"); - free(target->algorithm_scratchpad); - } - - target->algorithm_scratchpad = calloc(1, size); - - return target->algorithm_scratchpad; -} -void target_free_algorithm_scratchpad(struct target *target) -{ - free(target->algorithm_scratchpad); - target->algorithm_scratchpad = NULL; -} -void *target_get_algorithm_scratchpad(struct target *target) -{ - return target->algorithm_scratchpad; -} - /** * Waits for an algorithm started with target_start_algorithm() to complete. * @@ -1191,8 +1169,6 @@ static int target_init_one(struct command_context *cmd_ctx, { target_reset_examined(target); - target->algorithm_scratchpad = NULL; - struct target_type *type = target->type; if (type->examine == NULL) type->examine = default_examine; diff --git a/src/target/target.h b/src/target/target.h index a7b5f2a..8e1c8f9 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -196,8 +196,6 @@ struct target { /* file-I/O information for host to do syscall */ struct gdb_fileio_info *fileio_info; - - void *algorithm_scratchpad; }; struct target_list { @@ -471,27 +469,6 @@ int target_wait_algorithm(struct target *target, uint32_t exit_point, int timeout_ms, void *arch_info); - -/** - * Allocate a chunk of memory that algorithm can use as a scratchpad - * and save information needed to return @a target to its original - * state after execution is finished - * - * Function returns pointer to a memory allocated on success and NULL - * pointer on failure - */ -void *target_allocate_algorithm_scratchpad(struct target *target, size_t size); - -/** - * Free the memory allocated for algorithm scratchpad - */ -void target_free_algorithm_scratchpad(struct target *target); - -/** - * Get previously allocated scratchpad area - */ -void *target_get_algorithm_scratchpad(struct target *target); - /** * This routine is a wrapper for asynchronous algorithms. * -- ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
