[RFC] target: Move bulk_write_memory to arm7_9
[openocd.git] / src / target / target.c
index 183005e4d08e2c5817eb990e5182ce7f4bb2ba8c..6aee09832e3983362d278c3caef9394c66cf7fed 100644 (file)
@@ -36,7 +36,7 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -56,6 +56,9 @@
 #include "image.h"
 #include "rtos/rtos.h"
 
+/* default halt wait timeout (ms) */
+#define DEFAULT_HALT_TIMEOUT 5000
+
 static int target_read_buffer_default(struct target *target, uint32_t address,
                uint32_t size, uint8_t *buffer);
 static int target_write_buffer_default(struct target *target, uint32_t address,
@@ -65,6 +68,10 @@ static int target_array2mem(Jim_Interp *interp, struct target *target,
 static int target_mem2array(Jim_Interp *interp, struct target *target,
                int argc, Jim_Obj * const *argv);
 static int target_register_user_commands(struct command_context *cmd_ctx);
+static int target_get_gdb_fileio_info_default(struct target *target,
+               struct gdb_fileio_info *fileio_info);
+static int target_gdb_fileio_end_default(struct target *target, int retcode,
+               int fileio_errno, bool ctrl_c);
 
 /* targets */
 extern struct target_type arm7tdmi_target;
@@ -80,6 +87,7 @@ extern struct target_type dragonite_target;
 extern struct target_type xscale_target;
 extern struct target_type cortexm3_target;
 extern struct target_type cortexa8_target;
+extern struct target_type cortexr4_target;
 extern struct target_type arm11_target;
 extern struct target_type mips_m4k_target;
 extern struct target_type avr_target;
@@ -88,6 +96,9 @@ extern struct target_type dsp5680xx_target;
 extern struct target_type testee_target;
 extern struct target_type avr32_ap7k_target;
 extern struct target_type hla_target;
+extern struct target_type nds32_v2_target;
+extern struct target_type nds32_v3_target;
+extern struct target_type nds32_v3m_target;
 
 static struct target_type *target_types[] = {
        &arm7tdmi_target,
@@ -103,6 +114,7 @@ static struct target_type *target_types[] = {
        &xscale_target,
        &cortexm3_target,
        &cortexa8_target,
+       &cortexr4_target,
        &arm11_target,
        &mips_m4k_target,
        &avr_target,
@@ -111,6 +123,9 @@ static struct target_type *target_types[] = {
        &testee_target,
        &avr32_ap7k_target,
        &hla_target,
+       &nds32_v2_target,
+       &nds32_v3_target,
+       &nds32_v3m_target,
        NULL,
 };
 
@@ -213,6 +228,7 @@ static const Jim_Nvp nvp_target_debug_reason[] = {
        { .name = "watchpoint-and-breakpoint", .value = DBG_REASON_WPTANDBKPT },
        { .name = "single-step"              , .value = DBG_REASON_SINGLESTEP },
        { .name = "target-not-halted"        , .value = DBG_REASON_NOTHALTED  },
+       { .name = "program-exit"             , .value = DBG_REASON_EXIT },
        { .name = "undefined"                , .value = DBG_REASON_UNDEFINED },
        { .name = NULL, .value = -1 },
 };
@@ -448,7 +464,7 @@ int target_poll(struct target *target)
                        target->halt_issued = false;
                else {
                        long long t = timeval_ms() - target->halt_issued_time;
-                       if (t > 1000) {
+                       if (t > DEFAULT_HALT_TIMEOUT) {
                                target->halt_issued = false;
                                LOG_INFO("Halt timed out, wake up GDB.");
                                target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
@@ -567,8 +583,10 @@ static int target_process_reset(struct command_context *cmd_ctx, enum target_res
        retval = target_call_timer_callbacks_now();
 
        struct target *target;
-       for (target = all_targets; target; target = target->next)
+       for (target = all_targets; target; target = target->next) {
                target->type->check_reset(target);
+               target->running_alg = false;
+       }
 
        return retval;
 }
@@ -657,16 +675,6 @@ const char *target_type_name(struct target *target)
        return target->type->name;
 }
 
-static int target_read_memory_imp(struct target *target, uint32_t address,
-               uint32_t size, uint32_t count, uint8_t *buffer)
-{
-       if (!target_was_examined(target)) {
-               LOG_ERROR("Target not examined yet");
-               return ERROR_FAIL;
-       }
-       return target->type->read_memory_imp(target, address, size, count, buffer);
-}
-
 static int target_soft_reset_halt(struct target *target)
 {
        if (!target_was_examined(target)) {
@@ -941,12 +949,20 @@ int target_run_flash_async_algorithm(struct target *target,
 int target_read_memory(struct target *target,
                uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
 {
+       if (!target_was_examined(target)) {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
        return target->type->read_memory(target, address, size, count, buffer);
 }
 
-static int target_read_phys_memory(struct target *target,
+int target_read_phys_memory(struct target *target,
                uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
 {
+       if (!target_was_examined(target)) {
+               LOG_ERROR("Target not examined yet");
+               return ERROR_FAIL;
+       }
        return target->type->read_phys_memory(target, address, size, count, buffer);
 }
 
@@ -960,7 +976,7 @@ int target_write_memory(struct target *target,
        return target->type->write_memory(target, address, size, count, buffer);
 }
 
-static int target_write_phys_memory(struct target *target,
+int target_write_phys_memory(struct target *target,
                uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        if (!target_was_examined(target)) {
@@ -970,12 +986,6 @@ static int target_write_phys_memory(struct target *target,
        return target->type->write_phys_memory(target, address, size, count, buffer);
 }
 
-int target_bulk_write_memory(struct target *target,
-               uint32_t address, uint32_t count, const uint8_t *buffer)
-{
-       return target->type->bulk_write_memory(target, address, count, buffer);
-}
-
 int target_add_breakpoint(struct target *target,
                struct breakpoint *breakpoint)
 {
@@ -1026,11 +1036,29 @@ int target_remove_watchpoint(struct target *target,
 {
        return target->type->remove_watchpoint(target, watchpoint);
 }
+int target_hit_watchpoint(struct target *target,
+               struct watchpoint **hit_watchpoint)
+{
+       if (target->state != TARGET_HALTED) {
+               LOG_WARNING("target %s is not halted", target->cmd_name);
+               return ERROR_TARGET_NOT_HALTED;
+       }
+
+       if (target->type->hit_watchpoint == NULL) {
+               /* For backward compatible, if hit_watchpoint is not implemented,
+                * return ERROR_FAIL such that gdb_server will not take the nonsense
+                * information. */
+               return ERROR_FAIL;
+       }
+
+       return target->type->hit_watchpoint(target, hit_watchpoint);
+}
 
 int target_get_gdb_reg_list(struct target *target,
-               struct reg **reg_list[], int *reg_list_size)
+               struct reg **reg_list[], int *reg_list_size,
+               enum target_register_class reg_class)
 {
-       return target->type->get_gdb_reg_list(target, reg_list, reg_list_size);
+       return target->type->get_gdb_reg_list(target, reg_list, reg_list_size, reg_class);
 }
 int target_step(struct target *target,
                int current, uint32_t address, int handle_breakpoints)
@@ -1038,6 +1066,24 @@ int target_step(struct target *target,
        return target->type->step(target, current, address, handle_breakpoints);
 }
 
+int target_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
+{
+       if (target->state != TARGET_HALTED) {
+               LOG_WARNING("target %s is not halted", target->cmd_name);
+               return ERROR_TARGET_NOT_HALTED;
+       }
+       return target->type->get_gdb_fileio_info(target, fileio_info);
+}
+
+int target_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
+{
+       if (target->state != TARGET_HALTED) {
+               LOG_WARNING("target %s is not halted", target->cmd_name);
+               return ERROR_TARGET_NOT_HALTED;
+       }
+       return target->type->gdb_fileio_end(target, retcode, fileio_errno, ctrl_c);
+}
+
 /**
  * Reset the @c examined flag for the given target.
  * Pure paranoia -- targets are zeroed on allocation.
@@ -1083,17 +1129,6 @@ static int target_init_one(struct command_context *cmd_ctx,
                return retval;
        }
 
-       /**
-        * @todo get rid of those *memory_imp() methods, now that all
-        * callers are using target_*_memory() accessors ... and make
-        * sure the "physical" paths handle the same issues.
-        */
-       /* a non-invasive way(in terms of patches) to add some code that
-        * runs before the type->write/read_memory implementation
-        */
-       type->read_memory_imp = target->type->read_memory;
-       type->read_memory = target_read_memory_imp;
-
        /* Sanity-check MMU support ... stub in what we must, to help
         * implement it in stages, but warn if we need to do so.
         */
@@ -1132,6 +1167,12 @@ static int target_init_one(struct command_context *cmd_ctx,
        if (target->type->write_buffer == NULL)
                target->type->write_buffer = target_write_buffer_default;
 
+       if (target->type->get_gdb_fileio_info == NULL)
+               target->type->get_gdb_fileio_info = target_get_gdb_fileio_info_default;
+
+       if (target->type->gdb_fileio_end == NULL)
+               target->type->gdb_fileio_end = target_gdb_fileio_end_default;
+
        return ERROR_OK;
 }
 
@@ -1681,6 +1722,22 @@ int target_arch_state(struct target *target)
        return retval;
 }
 
+static int target_get_gdb_fileio_info_default(struct target *target,
+               struct gdb_fileio_info *fileio_info)
+{
+       /* If target does not support semi-hosting function, target
+          has no need to provide .get_gdb_fileio_info callback.
+          It just return ERROR_FAIL and gdb_server will return "Txx"
+          as target halted every time.  */
+       return ERROR_FAIL;
+}
+
+static int target_gdb_fileio_end_default(struct target *target,
+               int retcode, int fileio_errno, bool ctrl_c)
+{
+       return ERROR_OK;
+}
+
 /* Single aligned words are guaranteed to use 16 or 32 bit access
  * mode respectively, otherwise data is handled as quickly as
  * possible
@@ -1736,16 +1793,9 @@ static int target_write_buffer_default(struct target *target, uint32_t address,
        if (size >= 4) {
                int aligned = size - (size % 4);
 
-               /* use bulk writes above a certain limit. This may have to be changed */
-               if (aligned > 128) {
-                       retval = target->type->bulk_write_memory(target, address, aligned / 4, buffer);
-                       if (retval != ERROR_OK)
-                               return retval;
-               } else {
-                       retval = target_write_memory(target, address, 4, aligned / 4, buffer);
-                       if (retval != ERROR_OK)
-                               return retval;
-               }
+               retval = target_write_memory(target, address, 4, aligned / 4, buffer);
+               if (retval != ERROR_OK)
+                       return retval;
 
                buffer += aligned;
                address += aligned;
@@ -2411,13 +2461,11 @@ COMMAND_HANDLER(handle_wait_halt_command)
        if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       unsigned ms = 5000;
+       unsigned ms = DEFAULT_HALT_TIMEOUT;
        if (1 == CMD_ARGC) {
                int retval = parse_uint(CMD_ARGV[0], &ms);
                if (ERROR_OK != retval)
                        return ERROR_COMMAND_SYNTAX_ERROR;
-               /* convert seconds (given) to milliseconds (needed) */
-               ms *= 1000;
        }
 
        struct target *target = get_current_target(CMD_CTX);
@@ -5024,7 +5072,7 @@ static int target_create(Jim_GetOptInfo *goi)
        }
 
        /* now - create the new target name command */
-       const const struct command_registration target_subcommands[] = {
+       const struct command_registration target_subcommands[] = {
                {
                        .chain = target_instance_command_handlers,
                },
@@ -5033,7 +5081,7 @@ static int target_create(Jim_GetOptInfo *goi)
                },
                COMMAND_REGISTRATION_DONE
        };
-       const const struct command_registration target_commands[] = {
+       const struct command_registration target_commands[] = {
                {
                        .name = cp,
                        .mode = COMMAND_ANY,
@@ -5537,7 +5585,7 @@ static const struct command_registration target_exec_command_handlers[] = {
                .handler = handle_wait_halt_command,
                .mode = COMMAND_EXEC,
                .help = "wait up to the specified number of milliseconds "
-                       "(default 5) for a previously requested halt",
+                       "(default 5000) for a previously requested halt",
                .usage = "[milliseconds]",
        },
        {
@@ -5545,7 +5593,7 @@ static const struct command_registration target_exec_command_handlers[] = {
                .handler = handle_halt_command,
                .mode = COMMAND_EXEC,
                .help = "request target to halt, then wait up to the specified"
-                       "number of milliseconds (default 5) for it to complete",
+                       "number of milliseconds (default 5000) for it to complete",
                .usage = "[milliseconds]",
        },
        {

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)