Duane Ellis: "target as an [tcl] object" feature.
[fw/openocd] / src / target / xscale.c
index a83ab70de61dbc924e9927bf20c268ba9d3d5d1b..6b033cbd3e80f3c4bb9778154c25c79d5ec1f80c 100644 (file)
@@ -2,6 +2,9 @@
  *   Copyright (C) 2006, 2007 by Dominic Rath                              *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
+ *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                      *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
@@ -25,6 +28,7 @@
 
 #include "xscale.h"
 
+#include "arm7_9_common.h"
 #include "register.h"
 #include "target.h"
 #include "armv4_5.h"
@@ -49,9 +53,9 @@
 int xscale_register_commands(struct command_context_s *cmd_ctx);
 
 /* forward declarations */
-int xscale_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct target_s *target);
+int xscale_target_create(struct target_s *target, Jim_Interp *interp);
 int xscale_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
-int xscale_quit();
+int xscale_quit(void);
 
 int xscale_arch_state(struct target_s *target);
 int xscale_poll(target_t *target);
@@ -73,7 +77,6 @@ int xscale_write_core_reg(struct target_s *target, int num, enum armv4_5_mode mo
 int xscale_read_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
 int xscale_write_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
 int xscale_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffer);
-int xscale_checksum_memory(struct target_s *target, u32 address, u32 count, u32* checksum);
 
 int xscale_add_breakpoint(struct target_s *target, breakpoint_t *breakpoint);
 int xscale_remove_breakpoint(struct target_s *target, breakpoint_t *breakpoint);
@@ -110,8 +113,8 @@ target_type_t xscale_target =
        .read_memory = xscale_read_memory,
        .write_memory = xscale_write_memory,
        .bulk_write_memory = xscale_bulk_write_memory,
-       .checksum_memory = xscale_checksum_memory,
-       .blank_check_memory = NULL,
+       .checksum_memory = arm7_9_checksum_memory,
+       .blank_check_memory = arm7_9_blank_check_memory,
        
        .run_algorithm = armv4_5_run_algorithm,
 
@@ -121,7 +124,7 @@ target_type_t xscale_target =
        .remove_watchpoint = xscale_remove_watchpoint,
 
        .register_commands = xscale_register_commands,
-       .target_command = xscale_target_command,
+       .target_create = xscale_target_create,
        .init_target = xscale_init_target,
        .quit = xscale_quit,
        
@@ -484,41 +487,43 @@ int xscale_read_tx(target_t *target, int consume)
 
        for (;;)
        {
-               int i;
-               for (i=0; i<100; i++)
+               /* if we want to consume the register content (i.e. clear TX_READY),
+                * we have to go straight from Capture-DR to Shift-DR
+                * otherwise, we go from Capture-DR to Exit1-DR to Pause-DR
+               */
+               if (consume)
+                       jtag_add_pathmove(3, path);
+               else
                {
-                       /* if we want to consume the register content (i.e. clear TX_READY),
-                        * we have to go straight from Capture-DR to Shift-DR
-                        * otherwise, we go from Capture-DR to Exit1-DR to Pause-DR
-                       */
-                       if (consume)
-                               jtag_add_pathmove(3, path);
-                       else
-                       {
-                               jtag_add_pathmove(sizeof(noconsume_path)/sizeof(*noconsume_path), noconsume_path);
-                       }
-       
-                       jtag_add_dr_scan(3, fields, TAP_RTI);
-       
-                       if ((retval = jtag_execute_queue()) != ERROR_OK)
-                       {
-                               LOG_ERROR("JTAG error while reading TX");
-                               return ERROR_TARGET_TIMEOUT;
-                       }
-       
-                       gettimeofday(&now, NULL);
-                       if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec)&& (now.tv_usec > timeout.tv_usec)))
-                       {
-                               LOG_ERROR("time out reading TX register");
-                               return ERROR_TARGET_TIMEOUT;
-                       }
-                       if (!((!(field0_in & 1)) && consume))
-                       {
-                               goto done;
-                       }
+                       jtag_add_pathmove(sizeof(noconsume_path)/sizeof(*noconsume_path), noconsume_path);
+               }
+
+               jtag_add_dr_scan(3, fields, TAP_RTI);
+
+               if ((retval = jtag_execute_queue()) != ERROR_OK)
+               {
+                       LOG_ERROR("JTAG error while reading TX");
+                       return ERROR_TARGET_TIMEOUT;
+               }
+
+               gettimeofday(&now, NULL);
+               if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec)&& (now.tv_usec > timeout.tv_usec)))
+               {
+                       LOG_ERROR("time out reading TX register");
+                       return ERROR_TARGET_TIMEOUT;
+               }
+               if (!((!(field0_in & 1)) && consume))
+               {
+                       goto done;
+               }
+               if (debug_level>=3)
+               {
+                       LOG_DEBUG("waiting 100ms");
+                       alive_sleep(100); /* avoid flooding the logs */
+               } else
+               {
+                       keep_alive();
                }
-               LOG_DEBUG("waiting 10ms");
-               usleep(10*1000); /* avoid flooding the logs */
        } 
        done:
 
@@ -582,28 +587,30 @@ int xscale_write_rx(target_t *target)
        LOG_DEBUG("polling RX");
        for (;;)
        {
-               int i;
-               for (i=0; i<10; i++)
+               jtag_add_dr_scan(3, fields, TAP_RTI);
+
+               if ((retval = jtag_execute_queue()) != ERROR_OK)
                {
-                       jtag_add_dr_scan(3, fields, TAP_RTI);
-       
-                       if ((retval = jtag_execute_queue()) != ERROR_OK)
-                       {
-                               LOG_ERROR("JTAG error while writing RX");
-                               return retval;
-                       }
-       
-                       gettimeofday(&now, NULL);
-                       if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec)&& (now.tv_usec > timeout.tv_usec)))
-                       {
-                               LOG_ERROR("time out writing RX register");
-                               return ERROR_TARGET_TIMEOUT;
-                       }
-                       if (!(field0_in & 1))
-                               goto done;
+                       LOG_ERROR("JTAG error while writing RX");
+                       return retval;
+               }
+
+               gettimeofday(&now, NULL);
+               if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec)&& (now.tv_usec > timeout.tv_usec)))
+               {
+                       LOG_ERROR("time out writing RX register");
+                       return ERROR_TARGET_TIMEOUT;
+               }
+               if (!(field0_in & 1))
+                       goto done;
+               if (debug_level>=3)
+               {
+                       LOG_DEBUG("waiting 100ms");
+                       alive_sleep(100); /* avoid flooding the logs */
+               } else
+               {
+                       keep_alive();
                }
-               LOG_DEBUG("waiting 10ms");
-               usleep(10*1000); /* wait 10ms to avoid flooding the logs */
        }
        done:
        
@@ -976,7 +983,7 @@ int xscale_arch_state(struct target_s *target)
                        "MMU: %s, D-Cache: %s, I-Cache: %s"
                        "%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),
@@ -1218,7 +1225,8 @@ int xscale_halt(target_t *target)
        armv4_5_common_t *armv4_5 = target->arch_info;
        xscale_common_t *xscale = armv4_5->arch_info;
 
-       LOG_DEBUG("target->state: %s", target_state_strings[target->state]);
+       LOG_DEBUG("target->state: %s", 
+                 Jim_Nvp_value2name_simple( nvp_target_state, target->state )->name);
 
        if (target->state == TARGET_HALTED)
        {
@@ -1551,7 +1559,8 @@ int xscale_assert_reset(target_t *target)
        armv4_5_common_t *armv4_5 = target->arch_info;
        xscale_common_t *xscale = armv4_5->arch_info;
 
-       LOG_DEBUG("target->state: %s", target_state_strings[target->state]);
+       LOG_DEBUG("target->state: %s", 
+                 Jim_Nvp_value2name_simple( nvp_target_state, target->state )->name);
 
        /* select DCSR instruction (set endstate to R-T-I to ensure we don't
         * end up in T-L-R, which would reset JTAG
@@ -1577,6 +1586,13 @@ int xscale_assert_reset(target_t *target)
 
        target->state = TARGET_RESET;
 
+    if (target->reset_halt)
+    {
+       int retval;
+               if ((retval = target_halt(target))!=ERROR_OK)
+                       return retval;
+    }
+
        return ERROR_OK;
 }
 
@@ -1699,7 +1715,7 @@ int xscale_deassert_reset(target_t *target)
                xscale_write_dcsr(target, 0, 1);
                target->state = TARGET_RUNNING;
 
-               if ((target->reset_mode != RESET_HALT) && (target->reset_mode != RESET_INIT))
+               if (!target->reset_halt)
                {
                        jtag_add_sleep(10000);
 
@@ -2047,11 +2063,6 @@ int xscale_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffe
        return xscale_write_memory(target, address, 4, count, buffer);
 }
 
-int xscale_checksum_memory(struct target_s *target, u32 address, u32 count, u32* checksum)
-{
-       return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
-}
-
 u32 xscale_get_ttb(target_t *target)
 {
        armv4_5_common_t *armv4_5 = target->arch_info;
@@ -2984,13 +2995,13 @@ int xscale_init_target(struct command_context_s *cmd_ctx, struct target_s *targe
        return ERROR_OK;
 }
 
-int xscale_quit()
+int xscale_quit(void)
 {
 
        return ERROR_OK;
 }
 
-int xscale_init_arch_info(target_t *target, xscale_common_t *xscale, int chain_pos, char *variant)
+int xscale_init_arch_info(target_t *target, xscale_common_t *xscale, int chain_pos, const char *variant)
 {
        armv4_5_common_t *armv4_5;
        u32 high_reset_branch, low_reset_branch;
@@ -3101,24 +3112,11 @@ int xscale_init_arch_info(target_t *target, xscale_common_t *xscale, int chain_p
 }
 
 /* target xscale <endianess> <startup_mode> <chain_pos> <variant> */
-int xscale_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct target_s *target)
+int xscale_target_create(struct target_s *target, Jim_Interp *interp)
 {
-       int chain_pos;
-       char *variant = NULL;
-       xscale_common_t *xscale = malloc(sizeof(xscale_common_t));
-       memset(xscale, 0, sizeof(*xscale));
+       xscale_common_t *xscale = calloc(1,sizeof(xscale_common_t));
 
-       if (argc < 5)
-       {
-               LOG_ERROR("'target xscale' requires four arguments: <endianess> <startup_mode> <chain_pos> <variant>");
-               return ERROR_OK;
-       }
-
-       chain_pos = strtoul(args[3], NULL, 0);
-
-       variant = args[4];
-
-       xscale_init_arch_info(target, xscale, chain_pos, variant);
+       xscale_init_arch_info(target, xscale, target->chain_position, target->variant);
        xscale_build_reg_cache(target);
 
        return ERROR_OK;
@@ -3724,3 +3722,11 @@ int xscale_register_commands(struct command_context_s *cmd_ctx)
 
        return ERROR_OK;
 }
+
+
+/*
+ * Local Variables: ***
+ * c-basic-offset: 4 ***
+ * tab-width: 4 ***
+ * End: ***
+ */