Cortex-M3: don't exit()
[fw/openocd] / src / target / etm.c
index 0aa1a73911554a8f4fa827d9efe5aea0679d38a2..fa7a71b2c4972c76d587d756aa3d22841128682b 100644 (file)
 #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 */
@@ -219,11 +219,11 @@ 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);
-static int etm_register_user_commands(struct command_context_s *cmd_ctx);
+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;
 
 
 /* Look up register by ID ... most ETM instances only
@@ -279,7 +279,7 @@ static void etm_reg_add(unsigned bcd_vers, struct arm_jtag *jtag_info,
        }
 }
 
-struct reg_cache *etm_build_reg_cache(target_t *target,
+struct reg_cache *etm_build_reg_cache(struct target *target,
                struct arm_jtag *jtag_info, struct etm_context *etm_ctx)
 {
        struct reg_cache *reg_cache = malloc(sizeof(struct reg_cache));
@@ -349,10 +349,7 @@ struct reg_cache *etm_build_reg_cache(target_t *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 +393,7 @@ struct reg_cache *etm_build_reg_cache(target_t *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 +403,12 @@ struct reg_cache *etm_build_reg_cache(target_t *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)
@@ -421,7 +421,7 @@ static int etm_store_reg(struct reg *reg)
        return etm_write_reg(reg, buf_get_u32(reg->value, 0, reg->size));
 }
 
-int etm_setup(target_t *target)
+int etm_setup(struct target *target)
 {
        int retval;
        uint32_t etm_ctrl_value;
@@ -640,7 +640,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;
 
@@ -884,7 +884,7 @@ static int etmv1_data(struct etm_context *ctx, int size, uint32_t *data)
        return 0;
 }
 
-static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context_s *cmd_ctx)
+static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *cmd_ctx)
 {
        int retval;
        struct arm_instruction instruction;
@@ -1249,7 +1249,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update,
 
 COMMAND_HANDLER(handle_etm_tracemode_command)
 {
-       target_t *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd_ctx);
        struct arm *arm = target_to_arm(target);
        struct etm_context *etm;
 
@@ -1371,7 +1371,7 @@ COMMAND_HANDLER(handle_etm_tracemode_command)
 
 COMMAND_HANDLER(handle_etm_config_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        etm_portmode_t portmode = 0x0;
        struct etm_context *etm_ctx;
@@ -1521,7 +1521,7 @@ COMMAND_HANDLER(handle_etm_config_command)
 
 COMMAND_HANDLER(handle_etm_info_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm;
        struct reg *etm_sys_config_reg;
@@ -1653,7 +1653,7 @@ COMMAND_HANDLER(handle_etm_info_command)
 
 COMMAND_HANDLER(handle_etm_status_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm;
        trace_status_t trace_status;
@@ -1729,7 +1729,7 @@ COMMAND_HANDLER(handle_etm_status_command)
 
 COMMAND_HANDLER(handle_etm_image_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
 
@@ -1789,7 +1789,7 @@ COMMAND_HANDLER(handle_etm_image_command)
 COMMAND_HANDLER(handle_etm_dump_command)
 {
        struct fileio file;
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
        uint32_t i;
@@ -1857,7 +1857,7 @@ COMMAND_HANDLER(handle_etm_dump_command)
 COMMAND_HANDLER(handle_etm_load_command)
 {
        struct fileio file;
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
        uint32_t i;
@@ -1940,7 +1940,7 @@ COMMAND_HANDLER(handle_etm_load_command)
 
 COMMAND_HANDLER(handle_etm_trigger_percent_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
 
@@ -1981,7 +1981,7 @@ COMMAND_HANDLER(handle_etm_trigger_percent_command)
 
 COMMAND_HANDLER(handle_etm_start_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
        struct reg *etm_ctrl_reg;
@@ -2029,7 +2029,7 @@ COMMAND_HANDLER(handle_etm_start_command)
 
 COMMAND_HANDLER(handle_etm_stop_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
        struct reg *etm_ctrl_reg;
@@ -2068,7 +2068,7 @@ COMMAND_HANDLER(handle_etm_stop_command)
 
 COMMAND_HANDLER(handle_etm_analyze_command)
 {
-       target_t *target;
+       struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
        int retval;
@@ -2109,7 +2109,7 @@ COMMAND_HANDLER(handle_etm_analyze_command)
        return retval;
 }
 
-int etm_register_commands(struct command_context_s *cmd_ctx)
+int etm_register_commands(struct command_context *cmd_ctx)
 {
        etm_cmd = register_command(cmd_ctx, NULL, "etm", NULL, COMMAND_ANY, "Embedded Trace Macrocell");
 
@@ -2119,7 +2119,7 @@ int etm_register_commands(struct command_context_s *cmd_ctx)
        return ERROR_OK;
 }
 
-static int etm_register_user_commands(struct command_context_s *cmd_ctx)
+static int etm_register_user_commands(struct command_context *cmd_ctx)
 {
        register_command(cmd_ctx, etm_cmd, "tracemode", handle_etm_tracemode_command,
                COMMAND_EXEC, "configure/display trace mode: "