Fix regression in mdw output; identified by Magnus Lundin.
[openocd.git] / src / target / target.c
index d5a40195af2eb9247c8b5dc199ce84e9d81f5088..d672649281add2bf6a737b3fa553cda9ffb17833 100644 (file)
@@ -34,6 +34,7 @@
 #endif
 
 #include "target.h"
+#include "target_type.h"
 #include "target_request.h"
 #include "time_support.h"
 #include "register.h"
@@ -41,8 +42,6 @@
 #include "image.h"
 #include "jtag.h"
 
-#include <inttypes.h>
-
 
 static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
@@ -384,7 +383,7 @@ target_t* get_current_target(command_context_t *cmd_ctx)
 int target_poll(struct target_s *target)
 {
        /* We can't poll until after examine */
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                /* Fail silently lest we pollute the log */
                return ERROR_FAIL;
@@ -395,7 +394,7 @@ int target_poll(struct target_s *target)
 int target_halt(struct target_s *target)
 {
        /* We can't poll until after examine */
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -408,7 +407,7 @@ int target_resume(struct target_s *target, int current, u32 address, int handle_
        int retval;
 
        /* We can't poll until after examine */
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -463,10 +462,15 @@ static int default_mmu(struct target_s *target, int *enabled)
 
 static int default_examine(struct target_s *target)
 {
-       target->type->examined = 1;
+       target_set_examined(target);
        return ERROR_OK;
 }
 
+int target_examine_one(struct target_s *target)
+{
+       return target->type->examine(target);
+}
+
 /* Targets that correctly implement init+examine, i.e.
  * no communication with target during init:
  *
@@ -478,16 +482,20 @@ int target_examine(void)
        target_t *target = all_targets;
        while (target)
        {
-               if ((retval = target->type->examine(target))!=ERROR_OK)
+               if ((retval = target_examine_one(target)) != ERROR_OK)
                        return retval;
                target = target->next;
        }
        return retval;
 }
+const char *target_get_name(struct target_s *target)
+{
+       return target->type->name;
+}
 
 static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
 {
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -497,7 +505,7 @@ static int target_write_memory_imp(struct target_s *target, u32 address, u32 siz
 
 static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
 {
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -507,7 +515,7 @@ static int target_read_memory_imp(struct target_s *target, u32 address, u32 size
 
 static int target_soft_reset_halt_imp(struct target_s *target)
 {
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -517,7 +525,7 @@ static int target_soft_reset_halt_imp(struct target_s *target)
 
 static int target_run_algorithm_imp(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_params, reg_param_t *reg_param, u32 entry_point, u32 exit_point, int timeout_ms, void *arch_info)
 {
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -536,6 +544,72 @@ int target_write_memory(struct target_s *target,
 {
        return target->type->write_memory(target, address, size, count, buffer);
 }
+int target_bulk_write_memory(struct target_s *target,
+               u32 address, u32 count, u8 *buffer)
+{
+       return target->type->bulk_write_memory(target, address, count, buffer);
+}
+
+int target_add_breakpoint(struct target_s *target,
+               struct breakpoint_s *breakpoint)
+{
+       return target->type->add_breakpoint(target, breakpoint);
+}
+int target_remove_breakpoint(struct target_s *target,
+               struct breakpoint_s *breakpoint)
+{
+       return target->type->remove_breakpoint(target, breakpoint);
+}
+
+int target_add_watchpoint(struct target_s *target,
+               struct watchpoint_s *watchpoint)
+{
+       return target->type->add_watchpoint(target, watchpoint);
+}
+int target_remove_watchpoint(struct target_s *target,
+               struct watchpoint_s *watchpoint)
+{
+       return target->type->remove_watchpoint(target, watchpoint);
+}
+
+int target_get_gdb_reg_list(struct target_s *target,
+               struct reg_s **reg_list[], int *reg_list_size)
+{
+       return target->type->get_gdb_reg_list(target, reg_list, reg_list_size);
+}
+int target_step(struct target_s *target,
+               int current, u32 address, int handle_breakpoints)
+{
+       return target->type->step(target, current, address, handle_breakpoints);
+}
+
+
+int target_run_algorithm(struct target_s *target,
+               int num_mem_params, mem_param_t *mem_params,
+               int num_reg_params, reg_param_t *reg_param,
+               u32 entry_point, u32 exit_point,
+               int timeout_ms, void *arch_info)
+{
+       return target->type->run_algorithm(target,
+                       num_mem_params, mem_params, num_reg_params, reg_param,
+                       entry_point, exit_point, timeout_ms, arch_info);
+}
+
+/// @returns @c true if the target has been examined.
+bool target_was_examined(struct target_s *target)
+{
+       return target->type->examined;
+}
+/// Sets the @c examined flag for the given target.
+void target_set_examined(struct target_s *target)
+{
+       target->type->examined = true;
+}
+// Reset the @c examined flag for the given target.
+void target_reset_examined(struct target_s *target)
+{
+       target->type->examined = false;
+}
 
 
 int target_init(struct command_context_s *cmd_ctx)
@@ -545,7 +619,7 @@ int target_init(struct command_context_s *cmd_ctx)
 
        while (target)
        {
-               target->type->examined = 0;
+               target_reset_examined(target);
                if (target->type->examine == NULL)
                {
                        target->type->examine = default_examine;
@@ -553,7 +627,7 @@ int target_init(struct command_context_s *cmd_ctx)
 
                if ((retval = target->type->init_target(cmd_ctx, target)) != ERROR_OK)
                {
-                       LOG_ERROR("target '%s' init failed", target->type->name);
+                       LOG_ERROR("target '%s' init failed", target_get_name(target));
                        return retval;
                }
 
@@ -992,7 +1066,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
        int retval;
        LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address);
 
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1071,7 +1145,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe
        int retval;
        LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address);
 
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1138,7 +1212,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
        int retval;
        u32 i;
        u32 checksum = 0;
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1180,7 +1254,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
 int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank)
 {
        int retval;
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1197,7 +1271,7 @@ int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u3
 int target_read_u32(struct target_s *target, u32 address, u32 *value)
 {
        u8 value_buf[4];
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1222,7 +1296,7 @@ int target_read_u32(struct target_s *target, u32 address, u32 *value)
 int target_read_u16(struct target_s *target, u32 address, u16 *value)
 {
        u8 value_buf[2];
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1247,7 +1321,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value)
 int target_read_u8(struct target_s *target, u32 address, u8 *value)
 {
        int retval = target_read_memory(target, address, 1, 1, value);
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1270,7 +1344,7 @@ int target_write_u32(struct target_s *target, u32 address, u32 value)
 {
        int retval;
        u8 value_buf[4];
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1291,7 +1365,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
 {
        int retval;
        u8 value_buf[2];
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1311,7 +1385,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
 int target_write_u8(struct target_s *target, u32 address, u8 value)
 {
        int retval;
-       if (!target->type->examined)
+       if (!target_was_examined(target))
        {
                LOG_ERROR("Target not examined yet");
                return ERROR_FAIL;
@@ -1406,7 +1480,7 @@ DumpTargets:
                command_print(cmd_ctx, "%2d: %-10s %-10s %-10s %10d %14s %s",
                                          target->target_number,
                                          target->cmd_name,
-                                         target->type->name,
+                                         target_get_name(target),
                                          Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness )->name,
                                          target->tap->abs_chain_position,
                                          target->tap->dotted_name,
@@ -1869,9 +1943,9 @@ static void handle_md_output(struct command_context_s *cmd_ctx,
 
        const char *value_fmt;
        switch (size) {
-       case 4: value_fmt = "%8.8x"; break;
-       case 2: value_fmt = "%4.2x"; break;
-       case 1: value_fmt = "%2.2x"; break;
+       case 4: value_fmt = "%8.8x "; break;
+       case 2: value_fmt = "%4.2x "; break;
+       case 1: value_fmt = "%2.2x "; break;
        default:
                LOG_ERROR("invalid memory read size: %u", size);
                exit(-1);
@@ -1886,7 +1960,7 @@ static void handle_md_output(struct command_context_s *cmd_ctx,
                                        "0x%8.8x: ", address + (i*size));
                }
 
-               u32 value;
+               u32 value=0;
                const u8 *value_ptr = buffer + i * size;
                switch (size) {
                case 4: value = target_buffer_get_u32(target, value_ptr); break;
@@ -3086,7 +3160,7 @@ void target_handle_event( target_t *target, enum target_event e )
                        LOG_DEBUG( "target: (%d) %s (%s) event: %d (%s) action: %s\n",
                                           target->target_number,
                                           target->cmd_name,
-                                          target->type->name,
+                                          target_get_name(target),
                                           e,
                                           Jim_Nvp_value2name_simple( nvp_target_event, e )->name,
                                           Jim_GetString( teap->body, NULL ) );
@@ -3175,7 +3249,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target )
                                        return JIM_ERR;
                                }
                        }
-                       Jim_SetResultString( goi->interp, target->type->name, -1 );
+                       Jim_SetResultString( goi->interp, target_get_name(target), -1 );
                        /* loop for more */
                        break;
                case TCFG_EVENT:
@@ -3374,7 +3448,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target )
                                if( e != JIM_OK ){
                                        return e;
                                }
-                               tap = jtag_TapByJimObj( goi->interp, o );
+                               tap = jtag_tap_by_jim_obj( goi->interp, o );
                                if( tap == NULL ){
                                        return JIM_ERR;
                                }
@@ -3671,7 +3745,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
                        Jim_WrongNumArgs( goi.interp, 2, argv, "[no parameters]");
                        return JIM_ERR;
                }
-               if( !(target->type->examined) ){
+               if( !(target_was_examined(target)) ){
                        e = ERROR_TARGET_NOT_EXAMINED;
                } else {
                        e = target->type->poll( target );

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)