more robust error reporting for DCC
[fw/openocd] / src / target / arm7tdmi.c
index f3e9fd5f9e4a119d39009550e733972171278ee5..4528a83f56a8a665e3c6ad1545e4c10942a3fd7c 100644 (file)
@@ -2,6 +2,9 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
+ *   Copyright (C) 2008 by Spencer Oliver                                  *
+ *   spen@spen-soft.co.uk                                                  *
+ *                                                                         *
  *   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     *
@@ -44,8 +47,8 @@
 int arm7tdmi_register_commands(struct command_context_s *cmd_ctx);
 
 /* forward declarations */
-int arm7tdmi_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct target_s *target);
-int arm7tdmi_target_create(Jim_Interp *interp, struct target_s *target);
+
+int arm7tdmi_target_create(struct target_s *target,Jim_Interp *interp);
 int arm7tdmi_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
 int arm7tdmi_quit(void);
 
@@ -85,9 +88,8 @@ target_type_t arm7tdmi_target =
        .add_watchpoint = arm7_9_add_watchpoint,
        .remove_watchpoint = arm7_9_remove_watchpoint,
 
-       .register_commands = arm7tdmi_register_commands,
-       .target_command = arm7tdmi_target_command,
-       // .target_create    = arm7tdmi_target_create,
+       .register_commands  = arm7tdmi_register_commands,
+       .target_create  = arm7tdmi_target_create,
        .init_target = arm7tdmi_init_target,
        .examine = arm7tdmi_examine,
        .quit = arm7tdmi_quit
@@ -95,6 +97,7 @@ target_type_t arm7tdmi_target =
 
 int arm7tdmi_examine_debug_reason(target_t *target)
 {
+       int retval = ERROR_OK;
        /* get pointers to arch-specific information */
        armv4_5_common_t *armv4_5 = target->arch_info;
        arm7_9_common_t *arm7_9 = armv4_5->arch_info;
@@ -129,11 +132,17 @@ int arm7tdmi_examine_debug_reason(target_t *target)
                fields[1].in_handler = NULL;
                fields[1].in_handler_priv = NULL;
                
-               arm_jtag_scann(&arm7_9->jtag_info, 0x1);
+               if((retval = arm_jtag_scann(&arm7_9->jtag_info, 0x1)) != ERROR_OK)
+               {
+                       return retval;
+               }
                arm_jtag_set_instr(&arm7_9->jtag_info, arm7_9->jtag_info.intest_instr, NULL);
 
                jtag_add_dr_scan(2, fields, TAP_PD);
-               jtag_execute_queue();
+               if((retval = jtag_execute_queue()) != ERROR_OK)
+               {
+                       return retval;
+               }
                
                fields[0].in_value = NULL;
                fields[0].out_value = &breakpoint;
@@ -180,10 +189,14 @@ static __inline int arm7tdmi_clock_out(arm_jtag_t *jtag_info, u32 out, u32 *depr
 /* clock the target, reading the databus */
 int arm7tdmi_clock_data_in(arm_jtag_t *jtag_info, u32 *in)
 {
+       int retval = ERROR_OK;
        scan_field_t fields[2];
 
        jtag_add_end_state(TAP_PD);
-       arm_jtag_scann(jtag_info, 0x1);
+       if((retval = arm_jtag_scann(jtag_info, 0x1)) != ERROR_OK)
+       {
+               return retval;
+       }
        arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
        
        fields[0].device = jtag_info->chain_pos;
@@ -212,7 +225,10 @@ int arm7tdmi_clock_data_in(arm_jtag_t *jtag_info, u32 *in)
        
 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
 {
-               jtag_execute_queue();
+               if((retval = jtag_execute_queue()) != ERROR_OK)
+               {
+                       return retval;
+               }
                        
                if (in)
                {
@@ -234,10 +250,14 @@ int arm7tdmi_clock_data_in(arm_jtag_t *jtag_info, u32 *in)
  */ 
 int arm7tdmi_clock_data_in_endianness(arm_jtag_t *jtag_info, void *in, int size, int be)
 {
+       int retval = ERROR_OK;
        scan_field_t fields[2];
 
        jtag_add_end_state(TAP_PD);
-       arm_jtag_scann(jtag_info, 0x1);
+       if((retval = arm_jtag_scann(jtag_info, 0x1)) != ERROR_OK)
+       {
+               return retval;
+       }
        arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
        
        fields[0].device = jtag_info->chain_pos;
@@ -277,7 +297,10 @@ int arm7tdmi_clock_data_in_endianness(arm_jtag_t *jtag_info, void *in, int size,
        
 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
 {
-               jtag_execute_queue();
+               if((retval = jtag_execute_queue()) != ERROR_OK)
+               {
+                       return retval;
+               }
                        
                if (in)
                {
@@ -829,32 +852,9 @@ int arm7tdmi_init_arch_info(target_t *target, arm7tdmi_common_t *arm7tdmi, int c
        return ERROR_OK;
 }
 
-/* target arm7tdmi <endianess> <startup_mode> <chain_pos> <variant> */
-int arm7tdmi_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct target_s *target)
-{
-       int chain_pos;
-       char *variant = NULL;
-       arm7tdmi_common_t *arm7tdmi = malloc(sizeof(arm7tdmi_common_t));
-       memset(arm7tdmi, 0, sizeof(*arm7tdmi));
 
-       if (argc < 4)
-       {
-               LOG_ERROR("'target arm7tdmi' requires at least one additional argument");
-               exit(-1);
-       }
-       
-       chain_pos = strtoul(args[3], NULL, 0);
-       
-       if (argc >= 5)
-               variant = args[4];
-       
-       arm7tdmi_init_arch_info(target, arm7tdmi, chain_pos, variant);
-       
-       return ERROR_OK;
-}
 
-int arm7tdmi_target_create(Jim_Interp *interp,
-                                                  struct target_s *target)
+int arm7tdmi_target_create( struct target_s *target, Jim_Interp *interp )
 {
        arm7tdmi_common_t *arm7tdmi;
        
@@ -866,21 +866,12 @@ int arm7tdmi_target_create(Jim_Interp *interp,
 }
 
 
-
 int arm7tdmi_register_commands(struct command_context_s *cmd_ctx)
 {
        int retval;
        
        retval = arm7_9_register_commands(cmd_ctx);
        
-       return ERROR_OK;
+       return retval;
 
 }
-
-
-/*
- * Local Variables: ***
- * c-basic-offset: 4 ***
- * tab-width: 4 ***
- * End: ***
- */