Duane Ellis: "target as an [tcl] object" feature.
[openocd.git] / src / target / arm926ejs.c
index 1b3a17b0a976d0141d32908aebc0e7cd0e4ae42c..c25a677de2dfec3175c796ab375b9c9292ac22ce 100644 (file)
 #include "arm926ejs.h"
 #include "jtag.h"
 #include "log.h"
+#include "time_support.h"
 
 #include <stdlib.h>
 #include <string.h>
 
-#if 1
+#if 0
 #define _DEBUG_INSTRUCTION_EXECUTION_
 #endif
 
@@ -46,9 +47,9 @@ int arm926ejs_handle_read_cache_command(struct command_context_s *cmd_ctx, char
 int arm926ejs_handle_read_mmu_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
 /* forward declarations */
-int arm926ejs_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct target_s *target);
+int arm926ejs_target_create(struct target_s *target, Jim_Interp *interp);
 int arm926ejs_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
-int arm926ejs_quit();
+int arm926ejs_quit(void);
 int arm926ejs_arch_state(struct target_s *target);
 int arm926ejs_read_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
 int arm926ejs_write_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
@@ -72,7 +73,6 @@ target_type_t arm926ejs_target =
        .assert_reset = arm7_9_assert_reset,
        .deassert_reset = arm7_9_deassert_reset,
        .soft_reset_halt = arm926ejs_soft_reset_halt,
-       .prepare_reset_halt = arm7_9_prepare_reset_halt,
        
        .get_gdb_reg_list = armv4_5_get_gdb_reg_list,
 
@@ -80,6 +80,7 @@ target_type_t arm926ejs_target =
        .write_memory = arm926ejs_write_memory,
        .bulk_write_memory = arm7_9_bulk_write_memory,
        .checksum_memory = arm7_9_checksum_memory,
+       .blank_check_memory = arm7_9_blank_check_memory,
        
        .run_algorithm = armv4_5_run_algorithm,
 
@@ -89,8 +90,9 @@ target_type_t arm926ejs_target =
        .remove_watchpoint = arm7_9_remove_watchpoint,
 
        .register_commands = arm926ejs_register_commands,
-       .target_command = arm926ejs_target_command,
+       .target_create = arm926ejs_target_create,
        .init_target = arm926ejs_init_target,
+       .examine = arm9tdmi_examine,
        .quit = arm926ejs_quit,
        .virt2phys = arm926ejs_virt2phys,
        .mmu = arm926ejs_mmu
@@ -108,7 +110,7 @@ int arm926ejs_catch_broken_irscan(u8 *captured, void *priv, scan_field_t *field)
        }
        else if ((t == 0x0f) || (t == 0x00))
        {
-               DEBUG("caught ARM926EJ-S invalid Capture-IR result after CP15 access");
+               LOG_DEBUG("caught ARM926EJ-S invalid Capture-IR result after CP15 access");
                return ERROR_OK;
        }
        return ERROR_JTAG_QUEUE_FAILED;;
@@ -178,6 +180,7 @@ int arm926ejs_cp15_read(target_t *target, u32 op1, u32 op2, u32 CRn, u32 CRm, u3
        fields[0].in_handler_priv = value;
        fields[0].in_handler = arm_jtag_buf_to_u32;
        
+       /*TODO: add timeout*/
        do
        {
                /* rescan with NOP, to wait for the access to complete */
@@ -188,7 +191,7 @@ int arm926ejs_cp15_read(target_t *target, u32 op1, u32 op2, u32 CRn, u32 CRm, u3
        } while (buf_get_u32(&access, 0, 1) != 1);
 
 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
-       DEBUG("addr: 0x%x value: %8.8x", address, *value);
+       LOG_DEBUG("addr: 0x%x value: %8.8x", address, *value);
 #endif
        
        arm_jtag_set_instr(jtag_info, 0xc, &arm926ejs_catch_broken_irscan);
@@ -256,7 +259,7 @@ int arm926ejs_cp15_write(target_t *target, u32 op1, u32 op2, u32 CRn, u32 CRm, u
        fields[3].in_handler_priv = NULL;
        
        jtag_add_dr_scan(4, fields, -1);
-
+       /*TODO: add timeout*/
        do
        {
                /* rescan with NOP, to wait for the access to complete */
@@ -267,7 +270,7 @@ int arm926ejs_cp15_write(target_t *target, u32 op1, u32 op2, u32 CRn, u32 CRm, u
        } while (buf_get_u32(&access, 0, 1) != 1);
 
 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
-       DEBUG("addr: 0x%x value: %8.8x", address, value);
+       LOG_DEBUG("addr: 0x%x value: %8.8x", address, value);
 #endif
 
        arm_jtag_set_instr(jtag_info, 0xf, &arm926ejs_catch_broken_irscan);
@@ -292,50 +295,50 @@ int arm926ejs_examine_debug_reason(target_t *target)
        switch (debug_reason)
        {
                case 1:
-                       DEBUG("breakpoint from EICE unit 0");
+                       LOG_DEBUG("breakpoint from EICE unit 0");
                        target->debug_reason = DBG_REASON_BREAKPOINT;
                        break;
                case 2:
-                       DEBUG("breakpoint from EICE unit 1");
+                       LOG_DEBUG("breakpoint from EICE unit 1");
                        target->debug_reason = DBG_REASON_BREAKPOINT;
                        break;
                case 3:
-                       DEBUG("soft breakpoint (BKPT instruction)");
+                       LOG_DEBUG("soft breakpoint (BKPT instruction)");
                        target->debug_reason = DBG_REASON_BREAKPOINT;
                        break;
                case 4:
-                       DEBUG("vector catch breakpoint");
+                       LOG_DEBUG("vector catch breakpoint");
                        target->debug_reason = DBG_REASON_BREAKPOINT;
                        break;
                case 5:
-                       DEBUG("external breakpoint");
+                       LOG_DEBUG("external breakpoint");
                        target->debug_reason = DBG_REASON_BREAKPOINT;
                        break;
                case 6:
-                       DEBUG("watchpoint from EICE unit 0");
+                       LOG_DEBUG("watchpoint from EICE unit 0");
                        target->debug_reason = DBG_REASON_WATCHPOINT;
                        break;
                case 7:
-                       DEBUG("watchpoint from EICE unit 1");
+                       LOG_DEBUG("watchpoint from EICE unit 1");
                        target->debug_reason = DBG_REASON_WATCHPOINT;
                        break;
                case 8:
-                       DEBUG("external watchpoint");
+                       LOG_DEBUG("external watchpoint");
                        target->debug_reason = DBG_REASON_WATCHPOINT;
                        break;
                case 9:
-                       DEBUG("internal debug request");
+                       LOG_DEBUG("internal debug request");
                        target->debug_reason = DBG_REASON_DBGRQ;
                        break;
                case 10:
-                       DEBUG("external debug request");
+                       LOG_DEBUG("external debug request");
                        target->debug_reason = DBG_REASON_DBGRQ;
                        break;
                case 11:
-                       ERROR("BUG: debug re-entry from system speed access shouldn't be handled here");
+                       LOG_ERROR("BUG: debug re-entry from system speed access shouldn't be handled here");
                        break;
                default:
-                       ERROR("BUG: unknown debug reason: 0x%x", debug_reason);
+                       LOG_ERROR("BUG: unknown debug reason: 0x%x", debug_reason);
                        target->debug_reason = DBG_REASON_DBGRQ;
                        retval = ERROR_TARGET_FAILURE;
                        break;
@@ -444,7 +447,7 @@ void arm926ejs_post_debug_entry(target_t *target)
        /* examine cp15 control reg */
        arm926ejs->read_cp15(target, 0, 0, 1, 0, &arm926ejs->cp15_control_reg);
        jtag_execute_queue();
-       DEBUG("cp15_control_reg: %8.8x", arm926ejs->cp15_control_reg);
+       LOG_DEBUG("cp15_control_reg: %8.8x", arm926ejs->cp15_control_reg);
 
        if (arm926ejs->armv4_5_mmu.armv4_5_cache.ctype == -1)
        {
@@ -464,7 +467,7 @@ void arm926ejs_post_debug_entry(target_t *target)
        arm926ejs->read_cp15(target, 0, 1, 5, 0, &arm926ejs->i_fsr);
        arm926ejs->read_cp15(target, 0, 0, 6, 0, &arm926ejs->d_far);
        
-       DEBUG("D FSR: 0x%8.8x, D FAR: 0x%8.8x, I FSR: 0x%8.8x",
+       LOG_DEBUG("D FSR: 0x%8.8x, D FAR: 0x%8.8x, I FSR: 0x%8.8x",
                arm926ejs->d_fsr, arm926ejs->d_far, arm926ejs->i_fsr);  
 
 
@@ -550,16 +553,16 @@ int arm926ejs_arch_state(struct target_s *target)
        
        if (armv4_5->common_magic != ARMV4_5_COMMON_MAGIC)
        {
-               ERROR("BUG: called for a non-ARMv4/5 target");
+               LOG_ERROR("BUG: called for a non-ARMv4/5 target");
                exit(-1);
        }
        
-       USER(
+       LOG_USER(
                        "target halted in %s state due to %s, current mode: %s\n"
                        "cpsr: 0x%8.8x pc: 0x%8.8x\n"
                        "MMU: %s, D-Cache: %s, I-Cache: %s",
                         armv4_5_state_strings[armv4_5->core_state],
-                        target_debug_reason_strings[target->debug_reason],
+                        Jim_Nvp_value2name_simple( nvp_target_debug_reason,target->debug_reason)->name,
                         armv4_5_mode_strings[armv4_5_mode_to_number(armv4_5->core_mode)],
                         buf_get_u32(armv4_5->core_cache->reg_list[ARMV4_5_CPSR].value, 0, 32),
                         buf_get_u32(armv4_5->core_cache->reg_list[15].value, 0, 32),
@@ -578,12 +581,33 @@ int arm926ejs_soft_reset_halt(struct target_s *target)
        arm926ejs_common_t *arm926ejs = arm9tdmi->arch_info;
        reg_t *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
        
-       target->type->halt(target);
+       target_halt(target);
        
-       while (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1) == 0)
+       long long then=timeval_ms();
+       int timeout;
+       while (!(timeout=((timeval_ms()-then)>1000)))
        {
-               embeddedice_read_reg(dbg_stat);
-               jtag_execute_queue();
+               if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1) == 0)
+               {
+                       embeddedice_read_reg(dbg_stat);
+                       jtag_execute_queue();
+               }  else
+               {
+                       break;
+               }
+               if (debug_level>=1)
+               {
+                       /* do not eat all CPU, time out after 1 se*/
+                       alive_sleep(100);
+               } else
+               {
+                       keep_alive();
+               }
+       }
+       if (timeout)
+       {
+               LOG_ERROR("Failed to halt CPU after 1 sec");
+               return ERROR_TARGET_TIMEOUT;
        }
        
        target->state = TARGET_HALTED;
@@ -650,13 +674,13 @@ int arm926ejs_init_target(struct command_context_s *cmd_ctx, struct target_s *ta
        
 }
 
-int arm926ejs_quit()
+int arm926ejs_quit(void)
 {
        
        return ERROR_OK;
 }
 
-int arm926ejs_init_arch_info(target_t *target, arm926ejs_common_t *arm926ejs, int chain_pos, char *variant)
+int arm926ejs_init_arch_info(target_t *target, arm926ejs_common_t *arm926ejs, int chain_pos, const char *variant)
 {
        arm9tdmi_common_t *arm9tdmi = &arm926ejs->arm9tdmi_common;
        arm7_9_common_t *arm7_9 = &arm9tdmi->arm7_9_common;
@@ -690,33 +714,14 @@ int arm926ejs_init_arch_info(target_t *target, arm926ejs_common_t *arm926ejs, in
        arm7_9->arm_bkpt = ARMV5_BKPT(0x0);
        arm7_9->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
        
-       arm7_9->sw_bkpts_use_wp = 0;
-       arm7_9->sw_bkpts_enabled = 1;
-       
        return ERROR_OK;
 }
 
-int arm926ejs_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct target_s *target)
+int arm926ejs_target_create(struct target_s *target, Jim_Interp *interp)
 {
-       int chain_pos;
-       char *variant = NULL;
-       arm926ejs_common_t *arm926ejs = malloc(sizeof(arm926ejs_common_t));
-       memset(arm926ejs, 0, sizeof(*arm926ejs));
-       
-       if (argc < 4)
-       {
-               ERROR("'target arm926ejs' requires at least one additional argument");
-               exit(-1);
-       }
-       
-       chain_pos = strtoul(args[3], NULL, 0);
-       
-       if (argc >= 5)
-               variant = args[4];
+       arm926ejs_common_t *arm926ejs = calloc(1,sizeof(arm926ejs_common_t));
        
-       DEBUG("chain_pos: %i, variant: %s", chain_pos, variant);
-       
-       arm926ejs_init_arch_info(target, arm926ejs, chain_pos, variant);
+       arm926ejs_init_arch_info(target, arm926ejs, target->chain_position, target->variant);
 
        return ERROR_OK;
 }
@@ -936,9 +941,16 @@ static int arm926ejs_mmu(struct target_s *target, int *enabled)
        
        if (target->state != TARGET_HALTED)
        {
-               ERROR("Target not halted");
+               LOG_ERROR("Target not halted");
                return ERROR_TARGET_INVALID;
        }
        *enabled = arm926ejs->armv4_5_mmu.mmu_enabled;
        return ERROR_OK;
 }
+
+/*
+ * Local Variables: ***
+ * c-basic-offset: 4 ***
+ * tab-width: 4 ***
+ * End: ***
+ */

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)