ARM11 command handling fixes
[fw/openocd] / src / target / etb.c
index 41f2f5c582c4b4d77dd083ae8980dfef0cec7a43..40bb34a14f7917e2d0bcc0d45458eac005485ad7 100644 (file)
@@ -96,6 +96,33 @@ static int etb_scann(etb_t *etb, uint32_t new_scan_chain)
        return ERROR_OK;
 }
 
+static int etb_read_reg_w_check(reg_t *, uint8_t *, uint8_t *);
+static int etb_set_reg_w_exec(reg_t *, uint8_t *);
+
+static int etb_read_reg(reg_t *reg)
+{
+       return etb_read_reg_w_check(reg, NULL, NULL);
+}
+
+static int etb_get_reg(reg_t *reg)
+{
+       int retval;
+
+       if ((retval = etb_read_reg(reg)) != ERROR_OK)
+       {
+               LOG_ERROR("BUG: error scheduling etm register read");
+               return retval;
+       }
+
+       if ((retval = jtag_execute_queue()) != ERROR_OK)
+       {
+               LOG_ERROR("register read failed");
+               return retval;
+       }
+
+       return ERROR_OK;
+}
+
 reg_cache_t* etb_build_reg_cache(etb_t *etb)
 {
        reg_cache_t *reg_cache = malloc(sizeof(reg_cache_t));
@@ -138,30 +165,11 @@ reg_cache_t* etb_build_reg_cache(etb_t *etb)
        return reg_cache;
 }
 
-static int etb_get_reg(reg_t *reg)
-{
-       int retval;
-
-       if ((retval = etb_read_reg(reg)) != ERROR_OK)
-       {
-               LOG_ERROR("BUG: error scheduling etm register read");
-               return retval;
-       }
-
-       if ((retval = jtag_execute_queue()) != ERROR_OK)
-       {
-               LOG_ERROR("register read failed");
-               return retval;
-       }
-
-       return ERROR_OK;
-}
-
-
 static void etb_getbuf(jtag_callback_data_t arg)
 {
-  uint8_t *in=(uint8_t *)arg;
-       *((uint32_t *)in)=buf_get_u32(in, 0, 32);
+       uint8_t *in = (uint8_t *)arg;
+
+       *((uint32_t *)in) = buf_get_u32(in, 0, 32);
 }
 
 
@@ -204,10 +212,10 @@ static int etb_read_ram(etb_t *etb, uint32_t *data, int num_frames)
                else
                        buf_set_u32(fields[1].out_value, 0, 7, 0);
 
-               fields[0].in_value = (uint8_t *)(data+i);
+               fields[0].in_value = (uint8_t *)(data + i);
                jtag_add_dr_scan(3, fields, jtag_get_end_state());
 
-               jtag_add_callback(etb_getbuf, (jtag_callback_data_t)(data+i));
+               jtag_add_callback(etb_getbuf, (jtag_callback_data_t)(data + i));
        }
 
        jtag_execute_queue();
@@ -218,7 +226,8 @@ static int etb_read_ram(etb_t *etb, uint32_t *data, int num_frames)
        return ERROR_OK;
 }
 
-int etb_read_reg_w_check(reg_t *reg, uint8_t* check_value, uint8_t* check_mask)
+static int etb_read_reg_w_check(reg_t *reg,
+               uint8_t* check_value, uint8_t* check_mask)
 {
        etb_reg_t *etb_reg = reg->arch_info;
        uint8_t reg_addr = etb_reg->addr & 0x7f;
@@ -271,12 +280,9 @@ int etb_read_reg_w_check(reg_t *reg, uint8_t* check_value, uint8_t* check_mask)
        return ERROR_OK;
 }
 
-int etb_read_reg(reg_t *reg)
-{
-       return etb_read_reg_w_check(reg, NULL, NULL);
-}
+static int etb_write_reg(reg_t *, uint32_t);
 
-int etb_set_reg(reg_t *reg, uint32_t value)
+static int etb_set_reg(reg_t *reg, uint32_t value)
 {
        int retval;
 
@@ -293,7 +299,7 @@ int etb_set_reg(reg_t *reg, uint32_t value)
        return ERROR_OK;
 }
 
-int etb_set_reg_w_exec(reg_t *reg, uint8_t *buf)
+static int etb_set_reg_w_exec(reg_t *reg, uint8_t *buf)
 {
        int retval;
 
@@ -307,7 +313,7 @@ int etb_set_reg_w_exec(reg_t *reg, uint8_t *buf)
        return ERROR_OK;
 }
 
-int etb_write_reg(reg_t *reg, uint32_t value)
+static int etb_write_reg(reg_t *reg, uint32_t value)
 {
        etb_reg_t *etb_reg = reg->arch_info;
        uint8_t reg_addr = etb_reg->addr & 0x7f;
@@ -345,11 +351,6 @@ int etb_write_reg(reg_t *reg, uint32_t value)
        return ERROR_OK;
 }
 
-int etb_store_reg(reg_t *reg)
-{
-       return etb_write_reg(reg, buf_get_u32(reg->value, 0, reg->size));
-}
-
 static int etb_register_commands(struct command_context_s *cmd_ctx)
 {
        command_t *etb_cmd;
@@ -387,10 +388,10 @@ static int handle_etb_config_command(struct command_context_s *cmd_ctx, char *cm
                return ERROR_FAIL;
        }
 
-       tap = jtag_tap_by_string( args[1] );
+       tap = jtag_tap_by_string(args[1]);
        if (tap == NULL)
        {
-               command_print(cmd_ctx, "Tap: %s does not exist", args[1] );
+               command_print(cmd_ctx, "Tap: %s does not exist", args[1]);
                return ERROR_FAIL;
        }
 
@@ -550,32 +551,32 @@ static int etb_read_trace(etm_context_t *etm_ctx)
                                etm_ctx->trace_data[j].flags |= ETMV1_TRIGGER_CYCLE;
                        }
 
-                       /* trace word j+1 */
-                       etm_ctx->trace_data[j+1].pipestat = (trace_data[i] & 0x100) >> 8;
-                       etm_ctx->trace_data[j+1].packet = (trace_data[i] & 0x7800) >> 11;
-                       etm_ctx->trace_data[j+1].flags = 0;
+                       /* trace word j + 1 */
+                       etm_ctx->trace_data[j + 1].pipestat = (trace_data[i] & 0x100) >> 8;
+                       etm_ctx->trace_data[j + 1].packet = (trace_data[i] & 0x7800) >> 11;
+                       etm_ctx->trace_data[j + 1].flags = 0;
                        if ((trace_data[i] & 0x8000) >> 15)
                        {
-                               etm_ctx->trace_data[j+1].flags |= ETMV1_TRACESYNC_CYCLE;
+                               etm_ctx->trace_data[j + 1].flags |= ETMV1_TRACESYNC_CYCLE;
                        }
-                       if (etm_ctx->trace_data[j+1].pipestat == STAT_TR)
+                       if (etm_ctx->trace_data[j + 1].pipestat == STAT_TR)
                        {
-                               etm_ctx->trace_data[j+1].pipestat = etm_ctx->trace_data[j+1].packet & 0x7;
-                               etm_ctx->trace_data[j+1].flags |= ETMV1_TRIGGER_CYCLE;
+                               etm_ctx->trace_data[j + 1].pipestat = etm_ctx->trace_data[j + 1].packet & 0x7;
+                               etm_ctx->trace_data[j + 1].flags |= ETMV1_TRIGGER_CYCLE;
                        }
 
-                       /* trace word j+2 */
-                       etm_ctx->trace_data[j+2].pipestat = (trace_data[i] & 0x10000) >> 16;
-                       etm_ctx->trace_data[j+2].packet = (trace_data[i] & 0x780000) >> 19;
-                       etm_ctx->trace_data[j+2].flags = 0;
+                       /* trace word j + 2 */
+                       etm_ctx->trace_data[j + 2].pipestat = (trace_data[i] & 0x10000) >> 16;
+                       etm_ctx->trace_data[j + 2].packet = (trace_data[i] & 0x780000) >> 19;
+                       etm_ctx->trace_data[j + 2].flags = 0;
                        if ((trace_data[i] & 0x800000) >> 23)
                        {
-                               etm_ctx->trace_data[j+2].flags |= ETMV1_TRACESYNC_CYCLE;
+                               etm_ctx->trace_data[j + 2].flags |= ETMV1_TRACESYNC_CYCLE;
                        }
-                       if (etm_ctx->trace_data[j+2].pipestat == STAT_TR)
+                       if (etm_ctx->trace_data[j + 2].pipestat == STAT_TR)
                        {
-                               etm_ctx->trace_data[j+2].pipestat = etm_ctx->trace_data[j+2].packet & 0x7;
-                               etm_ctx->trace_data[j+2].flags |= ETMV1_TRIGGER_CYCLE;
+                               etm_ctx->trace_data[j + 2].pipestat = etm_ctx->trace_data[j + 2].packet & 0x7;
+                               etm_ctx->trace_data[j + 2].flags |= ETMV1_TRIGGER_CYCLE;
                        }
 
                        j += 3;
@@ -596,18 +597,18 @@ static int etb_read_trace(etm_context_t *etm_ctx)
                                etm_ctx->trace_data[j].flags |= ETMV1_TRIGGER_CYCLE;
                        }
 
-                       /* trace word j+1 */
-                       etm_ctx->trace_data[j+1].pipestat = (trace_data[i] & 0x7000) >> 12;
-                       etm_ctx->trace_data[j+1].packet = (trace_data[i] & 0x7f8000) >> 15;
-                       etm_ctx->trace_data[j+1].flags = 0;
+                       /* trace word j + 1 */
+                       etm_ctx->trace_data[j + 1].pipestat = (trace_data[i] & 0x7000) >> 12;
+                       etm_ctx->trace_data[j + 1].packet = (trace_data[i] & 0x7f8000) >> 15;
+                       etm_ctx->trace_data[j + 1].flags = 0;
                        if ((trace_data[i] & 0x800000) >> 23)
                        {
-                               etm_ctx->trace_data[j+1].flags |= ETMV1_TRACESYNC_CYCLE;
+                               etm_ctx->trace_data[j + 1].flags |= ETMV1_TRACESYNC_CYCLE;
                        }
-                       if (etm_ctx->trace_data[j+1].pipestat == STAT_TR)
+                       if (etm_ctx->trace_data[j + 1].pipestat == STAT_TR)
                        {
-                               etm_ctx->trace_data[j+1].pipestat = etm_ctx->trace_data[j+1].packet & 0x7;
-                               etm_ctx->trace_data[j+1].flags |= ETMV1_TRIGGER_CYCLE;
+                               etm_ctx->trace_data[j + 1].pipestat = etm_ctx->trace_data[j + 1].packet & 0x7;
+                               etm_ctx->trace_data[j + 1].flags |= ETMV1_TRIGGER_CYCLE;
                        }
 
                        j += 2;