target/aarch64: a64 disassembler
[fw/openocd] / src / target / stm8.c
index c06e0fae79db5f1403a6e2aa54c967656cdd02e0..78bf6a27ae682a1e36c8a7b05d9651ff41d6904e 100644 (file)
@@ -45,6 +45,8 @@ static int stm8_set_breakpoint(struct target *target,
 static void stm8_enable_watchpoints(struct target *target);
 static int stm8_unset_watchpoint(struct target *target,
                struct watchpoint *watchpoint);
+static int (*adapter_speed)(int speed);
+extern struct adapter_driver *adapter_driver;
 
 static const struct {
        unsigned id;
@@ -797,8 +799,35 @@ static int stm8_read_memory(struct target *target, target_addr_t address,
        return retval;
 }
 
+static int stm8_speed(int speed)
+{
+       int retval;
+       uint8_t csr;
+
+       LOG_DEBUG("stm8_speed: %d", speed);
+
+       csr = SAFE_MASK | SWIM_DM;
+       if (speed >= SWIM_FREQ_HIGH)
+               csr |= HS;
+
+       LOG_DEBUG("writing B0 to SWIM_CSR (SAFE_MASK + SWIM_DM + HS:%d)", csr & HS ? 1 : 0);
+       retval = stm8_write_u8(NULL, SWIM_CSR, csr);
+       if (retval != ERROR_OK)
+               return retval;
+       return adapter_speed(speed);
+}
+
 static int stm8_init(struct command_context *cmd_ctx, struct target *target)
 {
+       /*
+        * FIXME: this is a temporarily hack that needs better implementation.
+        * Being the only overwrite of adapter_driver, it prevents declaring const
+        * the struct adapter_driver.
+        * intercept adapter_driver->speed() calls
+        */
+       adapter_speed = adapter_driver->speed;
+       adapter_driver->speed = stm8_speed;
+
        stm8_build_reg_cache(target);
 
        return ERROR_OK;
@@ -938,7 +967,7 @@ static int stm8_reset_deassert(struct target *target)
        if (target->reset_halt)
                return ERROR_OK;
 
-       /* Instead of going thrugh saving context, polling and
+       /* Instead of going through saving context, polling and
           then resuming target again just clear stall and proceed. */
        target->state = TARGET_RUNNING;
        return stm8_exit_debug(target);
@@ -1114,7 +1143,7 @@ static int stm8_read_core_reg(struct target *target, unsigned int num)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        reg_value = stm8->core_regs[num];
-       LOG_DEBUG("read core reg %i value 0x%" PRIx32 "", num , reg_value);
+       LOG_DEBUG("read core reg %i value 0x%" PRIx32 "", num, reg_value);
        buf_set_u32(stm8->core_cache->reg_list[num].value, 0, 32, reg_value);
        stm8->core_cache->reg_list[num].valid = true;
        stm8->core_cache->reg_list[num].dirty = false;
@@ -1134,7 +1163,7 @@ static int stm8_write_core_reg(struct target *target, unsigned int num)
 
        reg_value = buf_get_u32(stm8->core_cache->reg_list[num].value, 0, 32);
        stm8->core_regs[num] = reg_value;
-       LOG_DEBUG("write core reg %i value 0x%" PRIx32 "", num , reg_value);
+       LOG_DEBUG("write core reg %i value 0x%" PRIx32 "", num, reg_value);
        stm8->core_cache->reg_list[num].valid = true;
        stm8->core_cache->reg_list[num].dirty = false;
 
@@ -1279,7 +1308,7 @@ static int stm8_arch_state(struct target *target)
 static int stm8_step(struct target *target, int current,
                target_addr_t address, int handle_breakpoints)
 {
-       LOG_DEBUG("%" PRIx32 " " TARGET_ADDR_FMT " %" PRIx32,
+       LOG_DEBUG("%x " TARGET_ADDR_FMT " %x",
                current, address, handle_breakpoints);
 
        /* get pointers to arch-specific information */
@@ -1660,17 +1689,6 @@ static int stm8_examine(struct target *target)
 
        if (!target_was_examined(target)) {
                if (!stm8->swim_configured) {
-                       /* set SWIM_CSR = 0xa0 (enable mem access & mask reset) */
-                       LOG_DEBUG("writing A0 to SWIM_CSR (SAFE_MASK + SWIM_DM)");
-                       retval = stm8_write_u8(target, SWIM_CSR, SAFE_MASK + SWIM_DM);
-                       if (retval != ERROR_OK)
-                               return retval;
-                       /* set high speed */
-                       LOG_DEBUG("writing B0 to SWIM_CSR (SAFE_MASK + SWIM_DM + HS)");
-                       retval = stm8_write_u8(target, SWIM_CSR, SAFE_MASK + SWIM_DM + HS);
-                       if (retval != ERROR_OK)
-                               return retval;
-                       jtag_config_khz(SWIM_FREQ_HIGH);
                        stm8->swim_configured = true;
                        /*
                                Now is the time to deassert reset if connect_under_reset.
@@ -1951,7 +1969,7 @@ int stm8_jim_configure(struct target *target, Jim_GetOptInfo *goi)
                        return e;
 
                stm8->blocksize = w;
-               LOG_DEBUG("blocksize=%8.8x", stm8->blocksize);
+               LOG_DEBUG("blocksize=%8.8" PRIx32, stm8->blocksize);
                return JIM_OK;
        }
        if (!strcmp(arg, "-flashstart")) {
@@ -1970,7 +1988,7 @@ int stm8_jim_configure(struct target *target, Jim_GetOptInfo *goi)
                        return e;
 
                stm8->flashstart = w;
-               LOG_DEBUG("flashstart=%8.8x", stm8->flashstart);
+               LOG_DEBUG("flashstart=%8.8" PRIx32, stm8->flashstart);
                return JIM_OK;
        }
        if (!strcmp(arg, "-flashend")) {
@@ -1989,7 +2007,7 @@ int stm8_jim_configure(struct target *target, Jim_GetOptInfo *goi)
                        return e;
 
                stm8->flashend = w;
-               LOG_DEBUG("flashend=%8.8x", stm8->flashend);
+               LOG_DEBUG("flashend=%8.8" PRIx32, stm8->flashend);
                return JIM_OK;
        }
        if (!strcmp(arg, "-eepromstart")) {
@@ -2008,7 +2026,7 @@ int stm8_jim_configure(struct target *target, Jim_GetOptInfo *goi)
                        return e;
 
                stm8->eepromstart = w;
-               LOG_DEBUG("eepromstart=%8.8x", stm8->eepromstart);
+               LOG_DEBUG("eepromstart=%8.8" PRIx32, stm8->eepromstart);
                return JIM_OK;
        }
        if (!strcmp(arg, "-eepromend")) {
@@ -2027,7 +2045,7 @@ int stm8_jim_configure(struct target *target, Jim_GetOptInfo *goi)
                        return e;
 
                stm8->eepromend = w;
-               LOG_DEBUG("eepromend=%8.8x", stm8->eepromend);
+               LOG_DEBUG("eepromend=%8.8" PRIx32, stm8->eepromend);
                return JIM_OK;
        }
        if (!strcmp(arg, "-optionstart")) {
@@ -2046,7 +2064,7 @@ int stm8_jim_configure(struct target *target, Jim_GetOptInfo *goi)
                        return e;
 
                stm8->optionstart = w;
-               LOG_DEBUG("optionstart=%8.8x", stm8->optionstart);
+               LOG_DEBUG("optionstart=%8.8" PRIx32, stm8->optionstart);
                return JIM_OK;
        }
        if (!strcmp(arg, "-optionend")) {
@@ -2065,7 +2083,7 @@ int stm8_jim_configure(struct target *target, Jim_GetOptInfo *goi)
                        return e;
 
                stm8->optionend = w;
-               LOG_DEBUG("optionend=%8.8x", stm8->optionend);
+               LOG_DEBUG("optionend=%8.8" PRIx32, stm8->optionend);
                return JIM_OK;
        }
        if (!strcmp(arg, "-enable_step_irq")) {