Fix "unused variable" warnings (errors) detected with GCC 4.7.0 - trivial fixes
[openocd.git] / src / target / armv4_5.c
index 36101b0208a6ebcc71d10852bc77b96638029f38..ef9b8397aa2ef56f7c5171c99374026e84f4b29f 100644 (file)
@@ -217,7 +217,7 @@ enum arm_mode armv4_5_number_to_mode(int number)
        }
 }
 
-const char *arm_state_strings[] =
+static const char *arm_state_strings[] =
 {
        "ARM", "Thumb", "Jazelle", "ThumbEE",
 };
@@ -612,7 +612,6 @@ COMMAND_HANDLER(handle_armv4_5_reg_command)
 {
        struct target *target = get_current_target(CMD_CTX);
        struct arm *armv4_5 = target_to_arm(target);
-       unsigned num_regs;
        struct reg *regs;
 
        if (!is_arm(armv4_5))
@@ -634,7 +633,10 @@ COMMAND_HANDLER(handle_armv4_5_reg_command)
        }
 
        if (!is_arm_mode(armv4_5->core_mode))
+       {
+               LOG_ERROR("not a valid arm core mode - communication failure?");
                return ERROR_FAIL;
+       }
 
        if (!armv4_5->full_context) {
                command_print(CMD_CTX, "error: target doesn't support %s",
@@ -642,7 +644,6 @@ COMMAND_HANDLER(handle_armv4_5_reg_command)
                return ERROR_FAIL;
        }
 
-       num_regs = armv4_5->core_cache->num_regs;
        regs = armv4_5->core_cache->reg_list;
 
        for (unsigned mode = 0; mode < ARRAY_SIZE(arm_mode_data); mode++) {
@@ -820,11 +821,9 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        struct arm *arm;
        int retval;
 
-       context = Jim_GetAssocData(interp, "context");
-       if (context == NULL) {
-               LOG_ERROR("%s: no command context", __func__);
-               return JIM_ERR;
-       }
+       context = current_command_context(interp);
+       assert( context != NULL);
+
        target = get_current_target(context);
        if (target == NULL) {
                LOG_ERROR("%s: no current target", __func__);
@@ -840,13 +839,6 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                return JIM_ERR;
        }
 
-       if (arm->core_type == ARM_MODE_THREAD)
-       {
-               /* armv7m not supported */
-               LOG_ERROR("Unsupported Command");
-               return ERROR_OK;
-       }
-
        if ((argc < 6) || (argc > 7)) {
                /* FIXME use the command name to verify # params... */
                LOG_ERROR("%s: wrong number of arguments", __func__);
@@ -951,6 +943,49 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        return JIM_OK;
 }
 
+COMMAND_HANDLER(handle_arm_semihosting_command)
+{
+       struct target *target = get_current_target(CMD_CTX);
+       struct arm *arm = target ? target_to_arm(target) : NULL;
+
+       if (!is_arm(arm)) {
+               command_print(CMD_CTX, "current target isn't an ARM");
+               return ERROR_FAIL;
+       }
+
+       if (!arm->setup_semihosting)
+       {
+               command_print(CMD_CTX, "semihosting not supported for current target");
+       }
+
+       if (CMD_ARGC > 0)
+       {
+               int semihosting;
+
+               COMMAND_PARSE_ENABLE(CMD_ARGV[0], semihosting);
+
+               if (!target_was_examined(target))
+               {
+                       LOG_ERROR("Target not examined yet");
+                       return ERROR_FAIL;
+               }
+
+               if (arm->setup_semihosting(target, semihosting) != ERROR_OK) {
+                       LOG_ERROR("Failed to Configure semihosting");
+                       return ERROR_FAIL;
+               }
+
+               /* FIXME never let that "catch" be dropped! */
+               arm->is_semihosting = semihosting;
+       }
+
+       command_print(CMD_CTX, "semihosting is %s",
+                       arm->is_semihosting
+                       ? "enabled" : "disabled");
+
+       return ERROR_OK;
+}
+
 static const struct command_registration arm_exec_command_handlers[] = {
        {
                .name = "reg",
@@ -985,6 +1020,13 @@ static const struct command_registration arm_exec_command_handlers[] = {
                .help = "read coprocessor register",
                .usage = "cpnum op1 CRn op2 CRm",
        },
+       {
+               "semihosting",
+               .handler = handle_arm_semihosting_command,
+               .mode = COMMAND_EXEC,
+               .usage = "['enable'|'disable']",
+               .help = "activate support for semihosting operations",
+       },
 
        COMMAND_REGISTRATION_DONE
 };
@@ -1005,7 +1047,10 @@ int arm_get_gdb_reg_list(struct target *target,
        int i;
 
        if (!is_arm_mode(armv4_5->core_mode))
+       {
+               LOG_ERROR("not a valid arm core mode - communication failure?");
                return ERROR_FAIL;
+       }
 
        *reg_list_size = 26;
        *reg_list = malloc(sizeof(struct reg*) * (*reg_list_size));
@@ -1086,7 +1131,10 @@ int armv4_5_run_algorithm_inner(struct target *target,
        }
 
        if (!is_arm_mode(armv4_5->core_mode))
+       {
+               LOG_ERROR("not a valid arm core mode - communication failure?");
                return ERROR_FAIL;
+       }
 
        /* armv5 and later can terminate with BKPT instruction; less overhead */
        if (!exit_point && armv4_5->is_armv4)
@@ -1245,16 +1293,19 @@ int armv4_5_run_algorithm(struct target *target, int num_mem_params, struct mem_
 /**
  * Runs ARM code in the target to calculate a CRC32 checksum.
  *
- * \todo On ARMv5+, rely on BKPT termination for reduced overhead.
  */
 int arm_checksum_memory(struct target *target,
                uint32_t address, uint32_t count, uint32_t *checksum)
 {
        struct working_area *crc_algorithm;
        struct arm_algorithm armv4_5_info;
+       struct arm *armv4_5 = target_to_arm(target);
        struct reg_param reg_params[2];
        int retval;
        uint32_t i;
+       uint32_t exit_var = 0;
+
+       /* see contib/loaders/checksum/armv4_5_crc.s for src */
 
        static const uint32_t arm_crc_code[] = {
                0xE1A02000,             /* mov          r2, r0 */
@@ -1280,7 +1331,7 @@ int arm_checksum_memory(struct target *target,
                0xE1540003,             /* cmp          r4, r3 */
                0x1AFFFFF1,             /* bne          nbyte */
                /* end: */
-               0xEAFFFFFE,             /* b            end */
+               0xe1200070,             /* bkpt         #0 */
                /* CRC32XOR: */
                0x04C11DB7              /* .word 0x04C11DB7 */
        };
@@ -1312,9 +1363,13 @@ int arm_checksum_memory(struct target *target,
        /* 20 second timeout/megabyte */
        int timeout = 20000 * (1 + (count / (1024 * 1024)));
 
+       /* armv4 must exit using a hardware breakpoint */
+       if (armv4_5->is_armv4)
+               exit_var = crc_algorithm->address + sizeof(arm_crc_code) - 8;
+
        retval = target_run_algorithm(target, 0, NULL, 2, reg_params,
                        crc_algorithm->address,
-                       crc_algorithm->address + sizeof(arm_crc_code) - 8,
+                       exit_var,
                        timeout, &armv4_5_info);
        if (retval != ERROR_OK) {
                LOG_ERROR("error executing ARM crc algorithm");
@@ -1339,7 +1394,6 @@ int arm_checksum_memory(struct target *target,
  * all ones.  NOR flash which has been erased, and thus may be written,
  * holds all ones.
  *
- * \todo On ARMv5+, rely on BKPT termination for reduced overhead.
  */
 int arm_blank_check_memory(struct target *target,
                uint32_t address, uint32_t count, uint32_t *blank)
@@ -1347,8 +1401,10 @@ int arm_blank_check_memory(struct target *target,
        struct working_area *check_algorithm;
        struct reg_param reg_params[3];
        struct arm_algorithm armv4_5_info;
+       struct arm *armv4_5 = target_to_arm(target);
        int retval;
        uint32_t i;
+       uint32_t exit_var = 0;
 
        static const uint32_t check_code[] = {
                /* loop: */
@@ -1357,7 +1413,7 @@ int arm_blank_check_memory(struct target *target,
                0xe2511001,             /* subs r1, r1, #1   */
                0x1afffffb,             /* bne loop          */
                /* end: */
-               0xeafffffe              /* b end             */
+               0xe1200070,             /* bkpt #0 */
        };
 
        /* make sure we have a working area */
@@ -1389,9 +1445,13 @@ int arm_blank_check_memory(struct target *target,
        init_reg_param(&reg_params[2], "r2", 32, PARAM_IN_OUT);
        buf_set_u32(reg_params[2].value, 0, 32, 0xff);
 
+       /* armv4 must exit using a hardware breakpoint */
+       if (armv4_5->is_armv4)
+               exit_var = check_algorithm->address + sizeof(check_code) - 4;
+
        retval = target_run_algorithm(target, 0, NULL, 3, reg_params,
                        check_algorithm->address,
-                       check_algorithm->address + sizeof(check_code) - 4,
+                       exit_var,
                        10000, &armv4_5_info);
        if (retval != ERROR_OK) {
                destroy_reg_param(&reg_params[0]);

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)