ioutil: make the file compile on MacOS
[fw/openocd] / src / target / arm966e.c
index b4207c8c15df0e3e4946945b1f10e23bbfb2627f..90f241fc365c31e464ad5410817cf4e8726398f3 100644 (file)
@@ -20,6 +20,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -28,7 +29,6 @@
 #include "target_type.h"
 #include "arm_opcodes.h"
 
-
 #if 0
 #define _DEBUG_INSTRUCTION_EXECUTION_
 #endif
@@ -53,7 +53,7 @@ int arm966e_init_arch_info(struct target *target, struct arm966e_common *arm966e
 
 static int arm966e_target_create(struct target *target, Jim_Interp *interp)
 {
-       struct arm966e_common *arm966e = calloc(1,sizeof(struct arm966e_common));
+       struct arm966e_common *arm966e = calloc(1, sizeof(struct arm966e_common));
 
        return arm966e_init_arch_info(target, arm966e, target->tap);
 }
@@ -84,11 +84,12 @@ static int arm966e_read_cp15(struct target *target, int reg_addr, uint32_t *valu
        uint8_t reg_addr_buf = reg_addr & 0x3f;
        uint8_t nr_w_buf = 0;
 
-       if ((retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE)) != ERROR_OK)
-       {
+       retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       retval = arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL, TAP_IDLE);
+       if (retval != ERROR_OK)
                return retval;
-       }
-       arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL, TAP_IDLE);
 
        fields[0].num_bits = 32;
        /* REVISIT: table 7-2 shows that bits 31-31 need to be
@@ -115,17 +116,16 @@ static int arm966e_read_cp15(struct target *target, int reg_addr, uint32_t *valu
 
 
 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
-       if ((retval = jtag_execute_queue()) != ERROR_OK)
-       {
+       retval = jtag_execute_queue();
+       if (retval != ERROR_OK)
                return retval;
-       }
        LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, *value);
 #endif
 
        return ERROR_OK;
 }
 
-// EXPORTED to str9x (flash)
+/* EXPORTED to str9x (flash) */
 int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value)
 {
        int retval = ERROR_OK;
@@ -138,11 +138,12 @@ int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value)
 
        buf_set_u32(value_buf, 0, 32, value);
 
-       if ((retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE)) != ERROR_OK)
-       {
+       retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
+       if (retval != ERROR_OK)
+               return retval;
+       retval = arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL, TAP_IDLE);
+       if (retval != ERROR_OK)
                return retval;
-       }
-       arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL, TAP_IDLE);
 
        fields[0].num_bits = 32;
        fields[0].out_value = value_buf;
@@ -175,42 +176,36 @@ COMMAND_HANDLER(arm966e_handle_cp15_command)
        if (retval != ERROR_OK)
                return retval;
 
-       if (target->state != TARGET_HALTED)
-       {
+       if (target->state != TARGET_HALTED) {
                command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME);
                return ERROR_OK;
        }
 
        /* one or more argument, access a single register (write if second argument is given */
-       if (CMD_ARGC >= 1)
-       {
+       if (CMD_ARGC >= 1) {
                uint32_t address;
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
 
-               if (CMD_ARGC == 1)
-               {
+               if (CMD_ARGC == 1) {
                        uint32_t value;
-                       if ((retval = arm966e_read_cp15(target, address, &value)) != ERROR_OK)
-                       {
+                       retval = arm966e_read_cp15(target, address, &value);
+                       if (retval != ERROR_OK) {
                                command_print(CMD_CTX,
                                                "couldn't access reg %" PRIi32,
                                                address);
                                return ERROR_OK;
                        }
-                       if ((retval = jtag_execute_queue()) != ERROR_OK)
-                       {
+                       retval = jtag_execute_queue();
+                       if (retval != ERROR_OK)
                                return retval;
-                       }
 
                        command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32,
                                        address, value);
-               }
-               else if (CMD_ARGC == 2)
-               {
+               } else if (CMD_ARGC == 2) {
                        uint32_t value;
                        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
-                       if ((retval = arm966e_write_cp15(target, address, value)) != ERROR_OK)
-                       {
+                       retval = arm966e_write_cp15(target, address, value);
+                       if (retval != ERROR_OK) {
                                command_print(CMD_CTX,
                                                "couldn't access reg %" PRIi32,
                                                address);
@@ -243,14 +238,14 @@ const struct command_registration arm966e_command_handlers[] = {
                .name = "arm966e",
                .mode = COMMAND_ANY,
                .help = "arm966e command group",
+               .usage = "",
                .chain = arm966e_exec_command_handlers,
        },
        COMMAND_REGISTRATION_DONE
 };
 
 /** Holds methods for ARM966 targets. */
-struct target_type arm966e_target =
-{
+struct target_type arm966e_target = {
        .name = "arm966e",
 
        .poll = arm7_9_poll,