X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Fetm.c;h=31b8bb2d0f7d54f2963eead0d2a2f57beafa44f9;hp=ee064ebc16e9364f68bf428b1016f46fa036bd3e;hb=f4788652e45662d1e43933dc0620561bc4cddae0;hpb=98723c4ecdbe06f90c66f3abec27b792c3b38e34 diff --git a/src/target/etm.c b/src/target/etm.c index ee064ebc16..31b8bb2d0f 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -22,9 +22,11 @@ #endif #include "armv4_5.h" +#include "etm.h" #include "etb.h" #include "image.h" #include "arm_disassembler.h" +#include "register.h" /* @@ -49,8 +51,6 @@ * ARM IHI 0014O ... Embedded Trace Macrocell, Architecture Specification */ -#define ARRAY_SIZE(x) ((int)(sizeof(x)/sizeof((x)[0]))) - enum { RO, /* read/only */ WO, /* write/only */ @@ -214,8 +214,6 @@ static const struct etm_reg_info etm_outputs[] = { { 0x6f, 32, RO, 0x20, "ETM_contextid_comparator_mask", } #endif -static int etm_reg_arch_type = -1; - static int etm_get_reg(struct reg *reg); static int etm_read_reg_w_check(struct reg *reg, uint8_t* check_value, uint8_t* check_mask); @@ -223,8 +221,12 @@ static int etm_register_user_commands(struct command_context *cmd_ctx); static int etm_set_reg_w_exec(struct reg *reg, uint8_t *buf); static int etm_write_reg(struct reg *reg, uint32_t value); -static command_t *etm_cmd; +static struct command *etm_cmd; +static const struct reg_arch_type etm_scan6_type = { + .get = etm_get_reg, + .set = etm_set_reg_w_exec, +}; /* Look up register by ID ... most ETM instances only * support a subset of the possible registers. @@ -269,7 +271,7 @@ static void etm_reg_add(unsigned bcd_vers, struct arm_jtag *jtag_info, reg->size = r->size; reg->value = &ereg->value; reg->arch_info = ereg; - reg->arch_type = etm_reg_arch_type; + reg->type = &etm_scan6_type; reg++; cache->num_regs++; @@ -287,11 +289,6 @@ struct reg_cache *etm_build_reg_cache(struct target *target, struct etm_reg *arch_info = NULL; unsigned bcd_vers, config; - /* register a register arch-type for etm registers only once */ - if (etm_reg_arch_type == -1) - etm_reg_arch_type = register_reg_arch_type(etm_get_reg, - etm_set_reg_w_exec); - /* the actual registers are kept in two arrays */ reg_list = calloc(128, sizeof(struct reg)); arch_info = calloc(128, sizeof(struct etm_reg)); @@ -349,10 +346,7 @@ struct reg_cache *etm_build_reg_cache(struct target *target, break; default: LOG_WARNING("Bad ETMv1 protocol %d", config >> 28); - free(reg_cache); - free(reg_list); - free(arch_info); - return ERROR_OK; + goto fail; } } etm_ctx->bcd_vers = bcd_vers; @@ -396,10 +390,7 @@ struct reg_cache *etm_build_reg_cache(struct target *target, if (!etb) { LOG_ERROR("etb selected as etm capture driver, but no ETB configured"); - free(reg_cache); - free(reg_list); - free(arch_info); - return ERROR_OK; + goto fail; } reg_cache->next = etb_build_reg_cache(etb); @@ -409,6 +400,12 @@ struct reg_cache *etm_build_reg_cache(struct target *target, etm_ctx->reg_cache = reg_cache; return reg_cache; + +fail: + free(reg_cache); + free(reg_list); + free(arch_info); + return NULL; } static int etm_read_reg(struct reg *reg) @@ -640,7 +637,7 @@ static int etm_read_instruction(struct etm_context *ctx, struct arm_instruction { int i; int section = -1; - uint32_t size_read; + size_t size_read; uint32_t opcode; int retval;