X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Ftarget.c;h=61fac56b23ae336021800bf834eae9e53c1c85b7;hp=ce2d08564307bee2d72b4ba2472f231c943aeb48;hb=4febcd8313cf46bea03bd5eacb3f287f19eb2961;hpb=3c58540e0283a452a7606ba22e693df10d746d54 diff --git a/src/target/target.c b/src/target/target.c index ce2d085643..61fac56b23 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -49,6 +49,7 @@ int cli_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv); + int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_daemon_startup_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); @@ -87,6 +88,7 @@ extern target_type_t arm926ejs_target; extern target_type_t feroceon_target; extern target_type_t xscale_target; extern target_type_t cortexm3_target; +extern target_type_t arm11_target; target_type_t *target_types[] = { @@ -99,6 +101,7 @@ target_type_t *target_types[] = &feroceon_target, &xscale_target, &cortexm3_target, + &arm11_target, NULL, }; @@ -387,7 +390,6 @@ static int default_virt2phys(struct target_s *target, u32 virtual, u32 *physical static int default_mmu(struct target_s *target, int *enabled) { - USER("No MMU present"); *enabled = 0; return ERROR_OK; } @@ -752,6 +754,24 @@ int target_register_commands(struct command_context_s *cmd_ctx) return ERROR_OK; } +int target_arch_state(struct target_s *target) +{ + int retval; + if (target==NULL) + { + USER("No target has been configured"); + return ERROR_OK; + } + + USER("target state: %s", target_state_strings[target->state]); + + if (target->state!=TARGET_HALTED) + return ERROR_OK; + + retval=target->type->arch_state(target); + return retval; +} + /* Single aligned words are guaranteed to use 16 or 32 bit access * mode respectively, otherwise data is handled as quickly as * possible @@ -1325,9 +1345,9 @@ int handle_target(void *priv) if (target->state != TARGET_HALTED) { if (target_continous_poll) - if ((retval = target->type->poll(target)) < 0) + if ((retval = target->type->poll(target)) != ERROR_OK) { - ERROR("couldn't poll target. It's due for a reset."); + ERROR("couldn't poll target(%d). It's due for a reset.", retval); } } @@ -1464,17 +1484,11 @@ static int wait_state(struct command_context_s *cmd_ctx, char *cmd, enum target_ int handle_poll_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { target_t *target = get_current_target(cmd_ctx); - char buffer[512]; if (argc == 0) { - command_print(cmd_ctx, "target state: %s", target_state_strings[target->type->poll(target)]); - if (target->state == TARGET_HALTED) - { - target->type->arch_state(target, buffer, 512); - buffer[511] = 0; - command_print(cmd_ctx, "%s", buffer); - } + target->type->poll(target); + target_arch_state(target); } else { @@ -1524,21 +1538,23 @@ static void target_process_events(struct command_context_s *cmd_ctx) static int wait_state(struct command_context_s *cmd_ctx, char *cmd, enum target_state state, int ms) { + int retval; struct timeval timeout, now; gettimeofday(&timeout, NULL); timeval_add_time(&timeout, 0, ms * 1000); - command_print(cmd_ctx, "waiting for target %s...", target_state_strings[state]); target_t *target = get_current_target(cmd_ctx); - while (target->type->poll(target)) + for (;;) { + if ((retval=target->type->poll(target))!=ERROR_OK) + return retval; target_call_timer_callbacks(); if (target->state == state) { - command_print(cmd_ctx, "target %s", target_state_strings[state]); break; } + command_print(cmd_ctx, "waiting for target %s...", target_state_strings[state]); gettimeofday(&now, NULL); if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec))) @@ -1681,34 +1697,20 @@ int handle_resume_command(struct command_context_s *cmd_ctx, char *cmd, char **a int retval; target_t *target = get_current_target(cmd_ctx); - DEBUG("-"); - if (argc == 0) retval = target->type->resume(target, 1, 0, 1, 0); /* current pc, addr = 0, handle breakpoints, not debugging */ else if (argc == 1) retval = target->type->resume(target, 0, strtoul(args[0], NULL, 0), 1, 0); /* addr = args[0], handle breakpoints, not debugging */ else { - command_print(cmd_ctx, "usage: resume [address]"); - return ERROR_OK; - } - - if (retval != ERROR_OK) - { - switch (retval) - { - case ERROR_TARGET_NOT_HALTED: - command_print(cmd_ctx, "target not halted"); - break; - default: - command_print(cmd_ctx, "unknown error... shutting down"); - exit(-1); - } + return ERROR_COMMAND_SYNTAX_ERROR; } target_process_events(cmd_ctx); - return ERROR_OK; + target_arch_state(target); + + return retval; } int handle_step_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)