ARM7/9: rm arm7_9_get_arch_pointers()
authorDavid Brownell <dbrownell@users.sourceforge.net>
Fri, 13 Nov 2009 21:44:50 +0000 (13:44 -0800)
committerDavid Brownell <dbrownell@users.sourceforge.net>
Fri, 13 Nov 2009 21:44:50 +0000 (13:44 -0800)
Remove the last external user of arm7_9_get_arch_pointers(), and
that annoying downcast utility.  Add an is_arm7_9() predicate.

Stop returning specious success codes on various failure paths
in the ARM7/ARM9 commands which used that downcast utility.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
src/flash/ocl.c
src/target/arm7_9_common.c
src/target/arm7_9_common.h

index 26d28305824ca0a8f55ae2b07df3110bb2f9768e..0b492c64ab9f06dfb5124031e55ccb339066d112 100644 (file)
@@ -46,8 +46,6 @@ static int ocl_protect_check(struct flash_bank *bank)
 /* flash_bank ocl 0 0 0 0 <target#> */
 FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command)
 {
 /* flash_bank ocl 0 0 0 0 <target#> */
 FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command)
 {
-       int retval;
-       struct arm *armv4_5;
        struct arm7_9_common *arm7_9;
        struct ocl_priv *ocl;
 
        struct arm7_9_common *arm7_9;
        struct ocl_priv *ocl;
 
@@ -57,8 +55,9 @@ FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command)
                return ERROR_FLASH_BANK_INVALID;
        }
 
                return ERROR_FLASH_BANK_INVALID;
        }
 
-       if ((retval = arm7_9_get_arch_pointers(bank->target, &armv4_5, &arm7_9)) != ERROR_OK)
-               return retval;
+       arm7_9 = target_to_arm7_9(bank->target);
+       if (!is_arm7_9(arm7_9))
+               return ERROR_TARGET_INVALID;
 
        ocl = bank->driver_priv = malloc(sizeof(struct ocl_priv));
        ocl->jtag_info = &arm7_9->jtag_info;
 
        ocl = bank->driver_priv = malloc(sizeof(struct ocl_priv));
        ocl->jtag_info = &arm7_9->jtag_info;
index ce2d4f027fac0fcad4315eda5b5b9d2981d5f137..ea04f3f85bb74e2c58487eebc9afca0525afc8e7 100644 (file)
@@ -166,39 +166,6 @@ int arm7_9_setup(struct target *target)
        return arm7_9_clear_watchpoints(arm7_9);
 }
 
        return arm7_9_clear_watchpoints(arm7_9);
 }
 
-/**
- * Retrieves the architecture information pointers for ARMv4/5 and ARM7/9
- * targets.  A return of ERROR_OK signifies that the target is a valid target
- * and that the pointers have been set properly.
- *
- * @param target Pointer to the target device to get the pointers from
- * @param armv4_5_p Pointer to be filled in with the common struct for ARMV4/5
- *                  targets
- * @param arm7_9_p Pointer to be filled in with the common struct for ARM7/9
- *                 targets
- * @return ERROR_OK if successful
- */
-int arm7_9_get_arch_pointers(struct target *target, struct arm **armv4_5_p, struct arm7_9_common **arm7_9_p)
-{
-       struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
-       struct armv4_5_common_s *armv4_5 = &arm7_9->armv4_5_common;
-
-       /* FIXME stop using this routine; just target_to_arm7_9() and
-        * verify the resulting pointer using a replacement routine
-        * that emits a usage message.
-        */
-       if (armv4_5->common_magic != ARMV4_5_COMMON_MAGIC)
-               return ERROR_TARGET_INVALID;
-
-       if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC)
-               return ERROR_TARGET_INVALID;
-
-       *armv4_5_p = armv4_5;
-       *arm7_9_p = arm7_9;
-
-       return ERROR_OK;
-}
-
 /**
  * Set either a hardware or software breakpoint on an ARM7/9 target.  The
  * breakpoint is set up even if it is already set.  Some actions, e.g. reset,
 /**
  * Set either a hardware or software breakpoint on an ARM7/9 target.  The
  * breakpoint is set up even if it is already set.  Some actions, e.g. reset,
@@ -2877,25 +2844,24 @@ COMMAND_HANDLER(handle_arm7_9_write_xpsr_command)
        int spsr;
        int retval;
        struct target *target = get_current_target(cmd_ctx);
        int spsr;
        int retval;
        struct target *target = get_current_target(cmd_ctx);
-       struct arm *armv4_5;
-       struct arm7_9_common *arm7_9;
+       struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
 
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       if (!is_arm7_9(arm7_9))
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
-               return ERROR_OK;
+               return ERROR_TARGET_INVALID;
        }
 
        if (target->state != TARGET_HALTED)
        {
                command_print(cmd_ctx, "can't write registers while running");
        }
 
        if (target->state != TARGET_HALTED)
        {
                command_print(cmd_ctx, "can't write registers while running");
-               return ERROR_OK;
+               return ERROR_FAIL;
        }
 
        if (argc < 2)
        {
                command_print(cmd_ctx, "usage: write_xpsr <value> <not cpsr | spsr>");
        }
 
        if (argc < 2)
        {
                command_print(cmd_ctx, "usage: write_xpsr <value> <not cpsr | spsr>");
-               return ERROR_OK;
+               return ERROR_FAIL;
        }
 
        COMMAND_PARSE_NUMBER(u32, args[0], value);
        }
 
        COMMAND_PARSE_NUMBER(u32, args[0], value);
@@ -2922,25 +2888,24 @@ COMMAND_HANDLER(handle_arm7_9_write_xpsr_im8_command)
        int spsr;
        int retval;
        struct target *target = get_current_target(cmd_ctx);
        int spsr;
        int retval;
        struct target *target = get_current_target(cmd_ctx);
-       struct arm *armv4_5;
-       struct arm7_9_common *arm7_9;
+       struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
 
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       if (!is_arm7_9(arm7_9))
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
-               return ERROR_OK;
+               return ERROR_TARGET_INVALID;
        }
 
        if (target->state != TARGET_HALTED)
        {
                command_print(cmd_ctx, "can't write registers while running");
        }
 
        if (target->state != TARGET_HALTED)
        {
                command_print(cmd_ctx, "can't write registers while running");
-               return ERROR_OK;
+               return ERROR_FAIL;
        }
 
        if (argc < 3)
        {
                command_print(cmd_ctx, "usage: write_xpsr_im8 <im8> <rotate> <not cpsr | spsr>");
        }
 
        if (argc < 3)
        {
                command_print(cmd_ctx, "usage: write_xpsr_im8 <im8> <rotate> <not cpsr | spsr>");
-               return ERROR_OK;
+               return ERROR_FAIL;
        }
 
        COMMAND_PARSE_NUMBER(u32, args[0], value);
        }
 
        COMMAND_PARSE_NUMBER(u32, args[0], value);
@@ -2963,25 +2928,24 @@ COMMAND_HANDLER(handle_arm7_9_write_core_reg_command)
        uint32_t mode;
        int num;
        struct target *target = get_current_target(cmd_ctx);
        uint32_t mode;
        int num;
        struct target *target = get_current_target(cmd_ctx);
-       struct arm *armv4_5;
-       struct arm7_9_common *arm7_9;
+       struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
 
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       if (!is_arm7_9(arm7_9))
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
-               return ERROR_OK;
+               return ERROR_TARGET_INVALID;
        }
 
        if (target->state != TARGET_HALTED)
        {
                command_print(cmd_ctx, "can't write registers while running");
        }
 
        if (target->state != TARGET_HALTED)
        {
                command_print(cmd_ctx, "can't write registers while running");
-               return ERROR_OK;
+               return ERROR_FAIL;
        }
 
        if (argc < 3)
        {
                command_print(cmd_ctx, "usage: write_core_reg <num> <mode> <value>");
        }
 
        if (argc < 3)
        {
                command_print(cmd_ctx, "usage: write_core_reg <num> <mode> <value>");
-               return ERROR_OK;
+               return ERROR_FAIL;
        }
 
        COMMAND_PARSE_NUMBER(int, args[0], num);
        }
 
        COMMAND_PARSE_NUMBER(int, args[0], num);
@@ -2994,13 +2958,12 @@ COMMAND_HANDLER(handle_arm7_9_write_core_reg_command)
 COMMAND_HANDLER(handle_arm7_9_dbgrq_command)
 {
        struct target *target = get_current_target(cmd_ctx);
 COMMAND_HANDLER(handle_arm7_9_dbgrq_command)
 {
        struct target *target = get_current_target(cmd_ctx);
-       struct arm *armv4_5;
-       struct arm7_9_common *arm7_9;
+       struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
 
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       if (!is_arm7_9(arm7_9))
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
-               return ERROR_OK;
+               return ERROR_TARGET_INVALID;
        }
 
        if (argc > 0)
        }
 
        if (argc > 0)
@@ -3027,13 +2990,12 @@ COMMAND_HANDLER(handle_arm7_9_dbgrq_command)
 COMMAND_HANDLER(handle_arm7_9_fast_memory_access_command)
 {
        struct target *target = get_current_target(cmd_ctx);
 COMMAND_HANDLER(handle_arm7_9_fast_memory_access_command)
 {
        struct target *target = get_current_target(cmd_ctx);
-       struct arm *armv4_5;
-       struct arm7_9_common *arm7_9;
+       struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
 
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       if (!is_arm7_9(arm7_9))
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
-               return ERROR_OK;
+               return ERROR_TARGET_INVALID;
        }
 
        if (argc > 0)
        }
 
        if (argc > 0)
@@ -3060,13 +3022,12 @@ COMMAND_HANDLER(handle_arm7_9_fast_memory_access_command)
 COMMAND_HANDLER(handle_arm7_9_dcc_downloads_command)
 {
        struct target *target = get_current_target(cmd_ctx);
 COMMAND_HANDLER(handle_arm7_9_dcc_downloads_command)
 {
        struct target *target = get_current_target(cmd_ctx);
-       struct arm *armv4_5;
-       struct arm7_9_common *arm7_9;
+       struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
 
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       if (!is_arm7_9(arm7_9))
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
        {
                command_print(cmd_ctx, "current target isn't an ARM7/ARM9 target");
-               return ERROR_OK;
+               return ERROR_TARGET_INVALID;
        }
 
        if (argc > 0)
        }
 
        if (argc > 0)
index 035c5fe3ab8480f01e213ebafb0e8858eef0d898..e46da8872c40cbdf55b41d28037520328b81a000 100644 (file)
@@ -115,6 +115,11 @@ target_to_arm7_9(struct target *target)
                        armv4_5_common);
 }
 
                        armv4_5_common);
 }
 
+static inline bool is_arm7_9(struct arm7_9_common *arm7_9)
+{
+       return arm7_9->common_magic == ARM7_9_COMMON_MAGIC;
+}
+
 int arm7_9_register_commands(struct command_context *cmd_ctx);
 
 int arm7_9_poll(struct target *target);
 int arm7_9_register_commands(struct command_context *cmd_ctx);
 
 int arm7_9_poll(struct target *target);
@@ -154,6 +159,5 @@ void arm7_9_disable_eice_step(struct target *target);
 int arm7_9_execute_sys_speed(struct target *target);
 
 int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9);
 int arm7_9_execute_sys_speed(struct target *target);
 
 int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9);
-int arm7_9_get_arch_pointers(struct target *target, struct arm **armv4_5_p, struct arm7_9_common **arm7_9_p);
 
 #endif /* ARM7_9_COMMON_H */
 
 #endif /* ARM7_9_COMMON_H */

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)