Improve jtag command argument parsing.
[openocd.git] / src / target / arm920t.c
index 269513f5c66fe7c94570a5e2552602ee567b6bcf..255600244a5754ec6c726fda51792cec3d5012eb 100644 (file)
 /* cli handling */
 int arm920t_handle_cp15_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int arm920t_handle_cp15i_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-int arm920t_handle_virt2phys_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int arm920t_handle_cache_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-int arm920t_handle_md_phys_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
-int arm920t_handle_mw_phys_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
+int arm920t_read_phys_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
+int arm920t_write_phys_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
 
 int arm920t_handle_read_cache_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int arm920t_handle_read_mmu_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
@@ -44,10 +43,13 @@ int arm920t_handle_read_mmu_command(struct command_context_s *cmd_ctx, char *cmd
 /* forward declarations */
 int arm920t_target_create(struct target_s *target, Jim_Interp *interp);
 int arm920t_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
-int arm920t_quit(void);
 
 #define ARM920T_CP15_PHYS_ADDR(x, y, z) ((x << 5) | (y << 1) << (z))
 
+static int arm920t_mrc(target_t *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t *value);
+static int arm920t_mcr(target_t *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t value);
+
+
 target_type_t arm920t_target =
 {
        .name = "arm920t",
@@ -69,6 +71,8 @@ target_type_t arm920t_target =
 
        .read_memory = arm920t_read_memory,
        .write_memory = arm920t_write_memory,
+       .read_phys_memory = arm920t_read_phys_memory,
+       .write_phys_memory = arm920t_write_phys_memory,
        .bulk_write_memory = arm7_9_bulk_write_memory,
        .checksum_memory = arm7_9_checksum_memory,
        .blank_check_memory = arm7_9_blank_check_memory,
@@ -84,7 +88,8 @@ target_type_t arm920t_target =
        .target_create = arm920t_target_create,
        .init_target = arm920t_init_target,
        .examine = arm9tdmi_examine,
-       .quit = arm920t_quit
+       .mrc = arm920t_mrc,
+       .mcr = arm920t_mcr,
 };
 
 int arm920t_read_cp15_physical(target_t *target, int reg_addr, uint32_t *value)
@@ -381,7 +386,7 @@ void arm920t_post_debug_entry(target_t *target)
        /* examine cp15 control reg */
        arm920t_read_cp15_physical(target, 0x2, &arm920t->cp15_control_reg);
        jtag_execute_queue();
-       LOG_DEBUG("cp15_control_reg: %8.8x", arm920t->cp15_control_reg);
+       LOG_DEBUG("cp15_control_reg: %8.8" PRIx32 "", arm920t->cp15_control_reg);
 
        if (arm920t->armv4_5_mmu.armv4_5_cache.ctype == -1)
        {
@@ -402,7 +407,7 @@ void arm920t_post_debug_entry(target_t *target)
        arm920t_read_cp15_interpreted(target, 0xee160f10, 0x0, &arm920t->d_far);
        arm920t_read_cp15_interpreted(target, 0xee160f30, 0x0, &arm920t->i_far);
 
-       LOG_DEBUG("D FSR: 0x%8.8x, D FAR: 0x%8.8x, I FSR: 0x%8.8x, I FAR: 0x%8.8x",
+       LOG_DEBUG("D FSR: 0x%8.8" PRIx32 ", D FAR: 0x%8.8" PRIx32 ", I FSR: 0x%8.8" PRIx32 ", I FAR: 0x%8.8" PRIx32 "",
                arm920t->d_fsr, arm920t->d_far, arm920t->i_fsr, arm920t->i_far);
 
        if (arm920t->preserve_cache)
@@ -497,8 +502,8 @@ int arm920t_arch_state(struct target_s *target)
                exit(-1);
        }
 
-       LOG_USER(       "target halted in %s state due to %s, current mode: %s\n"
-                       "cpsr: 0x%8.8x pc: 0x%8.8x\n"
+       LOG_USER("target halted in %s state due to %s, current mode: %s\n"
+                       "cpsr: 0x%8.8" PRIx32 " pc: 0x%8.8" PRIx32 "\n"
                        "MMU: %s, D-Cache: %s, I-Cache: %s",
                         armv4_5_state_strings[armv4_5->core_state],
                         Jim_Nvp_value2name_simple(nvp_target_debug_reason, target->debug_reason)->name,
@@ -521,6 +526,28 @@ int arm920t_read_memory(struct target_s *target, uint32_t address, uint32_t size
        return retval;
 }
 
+
+int arm920t_read_phys_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+{
+       armv4_5_common_t *armv4_5 = target->arch_info;
+       arm7_9_common_t *arm7_9 = armv4_5->arch_info;
+       arm9tdmi_common_t *arm9tdmi = arm7_9->arch_info;
+       arm920t_common_t *arm920t = arm9tdmi->arch_info;
+
+       return armv4_5_mmu_read_physical(target, &arm920t->armv4_5_mmu, address, size, count, buffer);
+}
+
+int arm920t_write_phys_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+{
+       armv4_5_common_t *armv4_5 = target->arch_info;
+       arm7_9_common_t *arm7_9 = armv4_5->arch_info;
+       arm9tdmi_common_t *arm9tdmi = arm7_9->arch_info;
+       arm920t_common_t *arm920t = arm9tdmi->arch_info;
+
+       return armv4_5_mmu_write_physical(target, &arm920t->armv4_5_mmu, address, size, count, buffer);
+}
+
+
 int arm920t_write_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
 {
        int retval;
@@ -532,26 +559,25 @@ int arm920t_write_memory(struct target_s *target, uint32_t address, uint32_t siz
        if ((retval = arm7_9_write_memory(target, address, size, count, buffer)) != ERROR_OK)
                return retval;
 
+       /* This fn is used to write breakpoints, so we need to make sure that the
+        * datacache is flushed and the instruction cache is invalidated */
        if (((size == 4) || (size == 2)) && (count == 1))
        {
                if (arm920t->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled)
                {
-                       LOG_DEBUG("D-Cache enabled, writing through to main memory");
-                       uint32_t pa, cb, ap;
-                       int type, domain;
-
-                       pa = armv4_5_mmu_translate_va(target, &arm920t->armv4_5_mmu, address, &type, &cb, &domain, &ap);
-                       if (type == -1)
-                               return ERROR_OK;
-                       /* cacheable & bufferable means write-back region */
-                       if (cb == 3)
-                               armv4_5_mmu_write_physical(target, &arm920t->armv4_5_mmu, pa, size, count, buffer);
+                       LOG_DEBUG("D-Cache enabled, flush and invalidate cache line");
+                       /* MCR p15,0,Rd,c7,c10,2 */
+                       retval = arm920t_write_cp15_interpreted(target, 0xee070f5e, 0x0, address);
+                       if (retval != ERROR_OK)
+                               return retval;
                }
 
                if (arm920t->armv4_5_mmu.armv4_5_cache.i_cache_enabled)
                {
                        LOG_DEBUG("I-Cache enabled, invalidating affected I-Cache line");
-                       arm920t_write_cp15_interpreted(target, 0xee070f35, 0x0, address);
+                       retval = arm920t_write_cp15_interpreted(target, 0xee070f35, 0x0, address);
+                       if (retval != ERROR_OK)
+                               return retval;
                }
        }
 
@@ -572,9 +598,9 @@ int arm920t_soft_reset_halt(struct target_s *target)
                return retval;
        }
 
-       long long then=timeval_ms();
+       long long then = timeval_ms();
        int timeout;
-       while (!(timeout=((timeval_ms()-then)>1000)))
+       while (!(timeout = ((timeval_ms()-then) > 1000)))
        {
                if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1) == 0)
                {
@@ -587,7 +613,7 @@ int arm920t_soft_reset_halt(struct target_s *target)
                {
                        break;
                }
-               if (debug_level>=3)
+               if (debug_level >= 3)
                {
                        /* do not eat all CPU, time out after 1 se*/
                        alive_sleep(100);
@@ -637,11 +663,6 @@ int arm920t_init_target(struct command_context_s *cmd_ctx, struct target_s *targ
        return ERROR_OK;
 }
 
-int arm920t_quit(void)
-{
-       return ERROR_OK;
-}
-
 int arm920t_init_arch_info(target_t *target, arm920t_common_t *arm920t, jtag_tap_t *tap)
 {
        arm9tdmi_common_t *arm9tdmi = &arm920t->arm9tdmi_common;
@@ -700,15 +721,6 @@ int arm920t_register_commands(struct command_context_s *cmd_ctx)
        register_command(cmd_ctx, arm920t_cmd, "cp15", arm920t_handle_cp15_command, COMMAND_EXEC, "display/modify cp15 register <num> [value]");
        register_command(cmd_ctx, arm920t_cmd, "cp15i", arm920t_handle_cp15i_command, COMMAND_EXEC, "display/modify cp15 (interpreted access) <opcode> [value] [address]");
        register_command(cmd_ctx, arm920t_cmd, "cache_info", arm920t_handle_cache_info_command, COMMAND_EXEC, "display information about target caches");
-       register_command(cmd_ctx, arm920t_cmd, "virt2phys", arm920t_handle_virt2phys_command, COMMAND_EXEC, "translate va to pa <va>");
-
-       register_command(cmd_ctx, arm920t_cmd, "mdw_phys", arm920t_handle_md_phys_command, COMMAND_EXEC, "display memory words <physical addr> [count]");
-       register_command(cmd_ctx, arm920t_cmd, "mdh_phys", arm920t_handle_md_phys_command, COMMAND_EXEC, "display memory half-words <physical addr> [count]");
-       register_command(cmd_ctx, arm920t_cmd, "mdb_phys", arm920t_handle_md_phys_command, COMMAND_EXEC, "display memory bytes <physical addr> [count]");
-
-       register_command(cmd_ctx, arm920t_cmd, "mww_phys", arm920t_handle_mw_phys_command, COMMAND_EXEC, "write memory word <physical addr> <value>");
-       register_command(cmd_ctx, arm920t_cmd, "mwh_phys", arm920t_handle_mw_phys_command, COMMAND_EXEC, "write memory half-word <physical addr> <value>");
-       register_command(cmd_ctx, arm920t_cmd, "mwb_phys", arm920t_handle_mw_phys_command, COMMAND_EXEC, "write memory byte <physical addr> <value>");
 
        register_command(cmd_ctx, arm920t_cmd, "read_cache", arm920t_handle_read_cache_command, COMMAND_EXEC, "display I/D cache content");
        register_command(cmd_ctx, arm920t_cmd, "read_mmu", arm920t_handle_read_mmu_command, COMMAND_EXEC, "display I/D mmu content");
@@ -832,12 +844,12 @@ int arm920t_handle_read_cache_command(struct command_context_s *cmd_ctx, char *c
 
                        /* mask LFSR[6] */
                        regs[9] &= 0xfffffffe;
-                       fprintf(output, "\nsegment: %i, index: %i, CAM: 0x%8.8x, content (%s):\n", segment, index, regs[9], (regs[9] & 0x10) ? "valid" : "invalid");
+                       fprintf(output, "\nsegment: %i, index: %i, CAM: 0x%8.8" PRIx32 ", content (%s):\n", segment, index, regs[9], (regs[9] & 0x10) ? "valid" : "invalid");
 
                        for (i = 1; i < 9; i++)
                        {
                                 d_cache[segment][index].data[i] = regs[i];
-                                fprintf(output, "%i: 0x%8.8x\n", i-1, regs[i]);
+                                fprintf(output, "%i: 0x%8.8" PRIx32 "\n", i-1, regs[i]);
                        }
 
                }
@@ -918,12 +930,12 @@ int arm920t_handle_read_cache_command(struct command_context_s *cmd_ctx, char *c
 
                        /* mask LFSR[6] */
                        regs[9] &= 0xfffffffe;
-                       fprintf(output, "\nsegment: %i, index: %i, CAM: 0x%8.8x, content (%s):\n", segment, index, regs[9], (regs[9] & 0x10) ? "valid" : "invalid");
+                       fprintf(output, "\nsegment: %i, index: %i, CAM: 0x%8.8" PRIx32 ", content (%s):\n", segment, index, regs[9], (regs[9] & 0x10) ? "valid" : "invalid");
 
                        for (i = 1; i < 9; i++)
                        {
                                 i_cache[segment][index].data[i] = regs[i];
-                                fprintf(output, "%i: 0x%8.8x\n", i-1, regs[i]);
+                                fprintf(output, "%i: 0x%8.8" PRIx32 "\n", i-1, regs[i]);
                        }
                }
 
@@ -1226,13 +1238,13 @@ int arm920t_handle_read_mmu_command(struct command_context_s *cmd_ctx, char *cmd
        fprintf(output, "D TLB content:\n");
        for (i = 0; i < 64; i++)
        {
-               fprintf(output, "%i: 0x%8.8x 0x%8.8x 0x%8.8x %s\n", i, d_tlb[i].cam, d_tlb[i].ram1, d_tlb[i].ram2, (d_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)");
+               fprintf(output, "%i: 0x%8.8" PRIx32 " 0x%8.8" PRIx32 " 0x%8.8" PRIx32 " %s\n", i, d_tlb[i].cam, d_tlb[i].ram1, d_tlb[i].ram2, (d_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)");
        }
 
        fprintf(output, "\n\nI TLB content:\n");
        for (i = 0; i < 64; i++)
        {
-               fprintf(output, "%i: 0x%8.8x 0x%8.8x 0x%8.8x %s\n", i, i_tlb[i].cam, i_tlb[i].ram1, i_tlb[i].ram2, (i_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)");
+               fprintf(output, "%i: 0x%8.8" PRIx32 " 0x%8.8" PRIx32 " 0x%8.8" PRIx32 " %s\n", i, i_tlb[i].cam, i_tlb[i].ram1, i_tlb[i].ram2, (i_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)");
        }
 
        command_print(cmd_ctx, "mmu content successfully output to %s", args[0]);
@@ -1298,7 +1310,7 @@ int arm920t_handle_cp15_command(struct command_context_s *cmd_ctx, char *cmd, ch
                                return retval;
                        }
 
-                       command_print(cmd_ctx, "%i: %8.8x", address, value);
+                       command_print(cmd_ctx, "%i: %8.8" PRIx32 "", address, value);
                }
                else if (argc == 2)
                {
@@ -1308,7 +1320,7 @@ int arm920t_handle_cp15_command(struct command_context_s *cmd_ctx, char *cmd, ch
                                command_print(cmd_ctx, "couldn't access reg %i", address);
                                return ERROR_OK;
                        }
-                       command_print(cmd_ctx, "%i: %8.8x", address, value);
+                       command_print(cmd_ctx, "%i: %8.8" PRIx32 "", address, value);
                }
        }
 
@@ -1349,21 +1361,21 @@ int arm920t_handle_cp15i_command(struct command_context_s *cmd_ctx, char *cmd, c
                        uint32_t value;
                        if ((retval = arm920t_read_cp15_interpreted(target, opcode, 0x0, &value)) != ERROR_OK)
                        {
-                               command_print(cmd_ctx, "couldn't execute %8.8x", opcode);
+                               command_print(cmd_ctx, "couldn't execute %8.8" PRIx32 "", opcode);
                                return ERROR_OK;
                        }
 
-                       command_print(cmd_ctx, "%8.8x: %8.8x", opcode, value);
+                       command_print(cmd_ctx, "%8.8" PRIx32 ": %8.8" PRIx32 "", opcode, value);
                }
                else if (argc == 2)
                {
                        uint32_t value = strtoul(args[1], NULL, 0);
                        if ((retval = arm920t_write_cp15_interpreted(target, opcode, value, 0)) != ERROR_OK)
                        {
-                               command_print(cmd_ctx, "couldn't execute %8.8x", opcode);
+                               command_print(cmd_ctx, "couldn't execute %8.8" PRIx32 "", opcode);
                                return ERROR_OK;
                        }
-                       command_print(cmd_ctx, "%8.8x: %8.8x", opcode, value);
+                       command_print(cmd_ctx, "%8.8" PRIx32 ": %8.8" PRIx32 "", opcode, value);
                }
                else if (argc == 3)
                {
@@ -1371,10 +1383,10 @@ int arm920t_handle_cp15i_command(struct command_context_s *cmd_ctx, char *cmd, c
                        uint32_t address = strtoul(args[2], NULL, 0);
                        if ((retval = arm920t_write_cp15_interpreted(target, opcode, value, address)) != ERROR_OK)
                        {
-                               command_print(cmd_ctx, "couldn't execute %8.8x", opcode);
+                               command_print(cmd_ctx, "couldn't execute %8.8" PRIx32 "", opcode);
                                return ERROR_OK;
                        }
-                       command_print(cmd_ctx, "%8.8x: %8.8x %8.8x", opcode, value, address);
+                       command_print(cmd_ctx, "%8.8" PRIx32 ": %8.8" PRIx32 " %8.8" PRIx32 "", opcode, value, address);
                }
        }
        else
@@ -1402,80 +1414,25 @@ int arm920t_handle_cache_info_command(struct command_context_s *cmd_ctx, char *c
        return armv4_5_handle_cache_info_command(cmd_ctx, &arm920t->armv4_5_mmu.armv4_5_cache);
 }
 
-int arm920t_handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc)
-{
-       target_t *target = get_current_target(cmd_ctx);
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
-       arm9tdmi_common_t *arm9tdmi;
-       arm920t_common_t *arm920t;
-       arm_jtag_t *jtag_info;
 
-       if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
-       {
-               command_print(cmd_ctx, "current target isn't an ARM920t target");
-               return ERROR_OK;
-       }
-
-       jtag_info = &arm7_9->jtag_info;
-
-       if (target->state != TARGET_HALTED)
-       {
-               command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
-               return ERROR_OK;
-       }
-
-       return armv4_5_mmu_handle_virt2phys_command(cmd_ctx, cmd, args, argc, target, &arm920t->armv4_5_mmu);
-}
-
-int arm920t_handle_md_phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc)
+static int arm920t_mrc(target_t *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t *value)
 {
-       target_t *target = get_current_target(cmd_ctx);
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
-       arm9tdmi_common_t *arm9tdmi;
-       arm920t_common_t *arm920t;
-       arm_jtag_t *jtag_info;
-
-       if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
-       {
-               command_print(cmd_ctx, "current target isn't an ARM920t target");
-               return ERROR_OK;
-       }
-
-       jtag_info = &arm7_9->jtag_info;
-
-       if (target->state != TARGET_HALTED)
+       if (cpnum!=15)
        {
-               command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
-               return ERROR_OK;
+               LOG_ERROR("Only cp15 is supported");
+               return ERROR_FAIL;
        }
 
-       return armv4_5_mmu_handle_md_phys_command(cmd_ctx, cmd, args, argc, target, &arm920t->armv4_5_mmu);
+       return arm920t_read_cp15_interpreted(target, mrc_opcode(cpnum, op1, op2, CRn, CRm), 0, value);
 }
 
-int arm920t_handle_mw_phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc)
+static int arm920t_mcr(target_t *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t CRn, uint32_t CRm, uint32_t value)
 {
-       target_t *target = get_current_target(cmd_ctx);
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
-       arm9tdmi_common_t *arm9tdmi;
-       arm920t_common_t *arm920t;
-       arm_jtag_t *jtag_info;
-
-       if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
+       if (cpnum!=15)
        {
-               command_print(cmd_ctx, "current target isn't an ARM920t target");
-               return ERROR_OK;
-       }
-
-       jtag_info = &arm7_9->jtag_info;
-
-       if (target->state != TARGET_HALTED)
-       {
-               command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
-               return ERROR_OK;
+               LOG_ERROR("Only cp15 is supported");
+               return ERROR_FAIL;
        }
 
-       return armv4_5_mmu_handle_mw_phys_command(cmd_ctx, cmd, args, argc, target, &arm920t->armv4_5_mmu);
+       return arm920t_write_cp15_interpreted(target, mrc_opcode(cpnum, op1, op2, CRn, CRm), 0, value);
 }

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)