{
target_t *target = priv;
- target->type->halt(target);
+ target_halt(target);
return ERROR_OK;
}
+int target_poll(struct target_s *target)
+{
+ /* We can't poll until after examine */
+ if (!target->type->examined)
+ {
+ /* Fail silently lest we pollute the log */
+ return ERROR_FAIL;
+ }
+ return target->type->poll(target);
+}
+
+int target_halt(struct target_s *target)
+{
+ /* We can't poll until after examine */
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+ return target->type->halt(target);
+}
+
+int target_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution)
+{
+ /* We can't poll until after examine */
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+ return target->type->resume(target, current, address, handle_breakpoints, debug_execution);
+}
+
+
int target_process_reset(struct command_context_s *cmd_ctx)
{
int retval = ERROR_OK;
target_register_event_callback(target_init_handler, cmd_ctx);
break;
case RESET_HALT:
- target->type->halt(target);
+ target_halt(target);
break;
case RESET_INIT:
- target->type->halt(target);
+ target_halt(target);
target_register_event_callback(target_init_handler, cmd_ctx);
break;
default:
while (target)
{
LOG_DEBUG("Polling target");
- target->type->poll(target);
+ target_poll(target);
if ((target->reset_mode == RESET_RUN_AND_INIT) ||
(target->reset_mode == RESET_RUN_AND_HALT) ||
(target->reset_mode == RESET_HALT) ||
static int default_examine(struct command_context_s *cmd_ctx, struct target_s *target)
{
+ target->type->examined = 1;
return ERROR_OK;
}
+/* Targets that correctly implement init+examine, i.e.
+ * no communication with target during init:
+ *
+ * XScale
+ */
int target_examine(struct command_context_s *cmd_ctx)
{
int retval = ERROR_OK;
}
return retval;
}
+
+static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
+{
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+ return target->type->write_memory_imp(target, address, size, count, buffer);
+}
+
+static int target_read_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
+{
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+ return target->type->read_memory_imp(target, address, size, count, buffer);
+}
+
+static int target_soft_reset_halt_imp(struct target_s *target)
+{
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+ return target->type->soft_reset_halt_imp(target);
+}
+
+static int target_run_algorithm_imp(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_params, reg_param_t *reg_param, u32 entry_point, u32 exit_point, int timeout_ms, void *arch_info)
+{
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+ return target->type->run_algorithm_imp(target, num_mem_params, mem_params, num_reg_params, reg_param, entry_point, exit_point, timeout_ms, arch_info);
+}
+
int target_init(struct command_context_s *cmd_ctx)
{
target_t *target = targets;
{
target->type->virt2phys = default_virt2phys;
}
+ target->type->virt2phys = default_virt2phys;
+ /* a non-invasive way(in terms of patches) to add some code that
+ * runs before the type->write/read_memory implementation
+ */
+ target->type->write_memory_imp = target->type->write_memory;
+ target->type->write_memory = target_write_memory_imp;
+ target->type->read_memory_imp = target->type->read_memory;
+ target->type->read_memory = target_read_memory_imp;
+ target->type->soft_reset_halt_imp = target->type->soft_reset_halt;
+ target->type->soft_reset_halt = target_soft_reset_halt_imp;
+ target->type->run_algorithm_imp = target->type->run_algorithm;
+ target->type->run_algorithm = target_run_algorithm_imp;
+
+
if (target->type->mmu == NULL)
{
target->type->mmu = default_mmu;
int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer)
{
int retval;
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
LOG_DEBUG("writing buffer of %i byte at 0x%8.8x", size, address);
int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer)
{
int retval;
-
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+
LOG_DEBUG("reading buffer of %i byte at 0x%8.8x", size, address);
if (((address % 2) == 0) && (size == 2))
int retval;
int i;
u32 checksum = 0;
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
if ((retval = target->type->checksum_memory(target, address,
size, &checksum)) == ERROR_TARGET_RESOURCE_NOT_AVAILABLE)
int target_read_u32(struct target_s *target, u32 address, u32 *value)
{
u8 value_buf[4];
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
int retval = target->type->read_memory(target, address, 4, 1, value_buf);
int target_read_u16(struct target_s *target, u32 address, u16 *value)
{
u8 value_buf[2];
-
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+
int retval = target->type->read_memory(target, address, 2, 1, value_buf);
if (retval == ERROR_OK)
int target_read_u8(struct target_s *target, u32 address, u8 *value)
{
int retval = target->type->read_memory(target, address, 1, 1, value);
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
if (retval == ERROR_OK)
{
{
int retval;
u8 value_buf[4];
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value);
{
int retval;
u8 value_buf[2];
-
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+
LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value);
target_buffer_set_u16(target, value_buf, value);
int target_write_u8(struct target_s *target, u32 address, u8 value)
{
int retval;
-
+ if (!target->type->examined)
+ {
+ LOG_ERROR("Target not examined yet");
+ return ERROR_FAIL;
+ }
+
LOG_DEBUG("address: 0x%8.8x, value: 0x%2.2x", address, value);
if ((retval = target->type->read_memory(target, address, 1, 1, &value)) != ERROR_OK)
/* process target state changes */
int handle_target(void *priv)
{
- int retval;
target_t *target = targets;
while (target)
{
- /* only poll if target isn't already halted */
- if (target->state != TARGET_HALTED)
+ if (target_continous_poll)
{
- if (target_continous_poll)
- if ((retval = target->type->poll(target)) != ERROR_OK)
- {
- LOG_ERROR("couldn't poll target(%d). It's due for a reset.", retval);
- }
+ /* polling may fail silently until the target has been examined */
+ target_poll(target);
}
target = target->next;
if (argc == 0)
{
- target->type->poll(target);
+ target_poll(target);
target_arch_state(target);
}
else
static void target_process_events(struct command_context_s *cmd_ctx)
{
target_t *target = get_current_target(cmd_ctx);
- target->type->poll(target);
+ target_poll(target);
target_call_timer_callbacks_now();
}
target_t *target = get_current_target(cmd_ctx);
for (;;)
{
- if ((retval=target->type->poll(target))!=ERROR_OK)
+ if ((retval=target_poll(target))!=ERROR_OK)
return retval;
target_call_timer_callbacks_now();
if (target->state == state)
LOG_DEBUG("-");
- if ((retval = target->type->halt(target)) != ERROR_OK)
+ if ((retval = target_halt(target)) != ERROR_OK)
{
return retval;
}
target_t *target = get_current_target(cmd_ctx);
if (argc == 0)
- retval = target->type->resume(target, 1, 0, 1, 0); /* current pc, addr = 0, handle breakpoints, not debugging */
+ retval = target_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 */
+ retval = target_resume(target, 0, strtoul(args[0], NULL, 0), 1, 0); /* addr = args[0], handle breakpoints, not debugging */
else
{
return ERROR_COMMAND_SYNTAX_ERROR;
for (;;)
{
- target->type->poll(target);
+ target_poll(target);
if (target->state == TARGET_HALTED)
{
u32 t=*((u32 *)reg->value);
samples[numSamples++]=t;
- retval = target->type->resume(target, 1, 0, 0, 0); /* current pc, addr = 0, do not handle breakpoints, not debugging */
- target->type->poll(target);
+ retval = target_resume(target, 1, 0, 0, 0); /* current pc, addr = 0, do not handle breakpoints, not debugging */
+ target_poll(target);
usleep(10*1000); // sleep 10ms, i.e. <100 samples/second.
} else if (target->state == TARGET_RUNNING)
{
// We want to quickly sample the PC.
- target->type->halt(target);
+ target_halt(target);
} else
{
command_print(cmd_ctx, "Target not halted or running");
if ((numSamples>=maxSample) || ((now.tv_sec >= timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec)))
{
command_print(cmd_ctx, "Profiling completed. %d samples.", numSamples);
- target->type->poll(target);
+ target_poll(target);
if (target->state == TARGET_HALTED)
{
- target->type->resume(target, 1, 0, 0, 0); /* current pc, addr = 0, do not handle breakpoints, not debugging */
+ target_resume(target, 1, 0, 0, 0); /* current pc, addr = 0, do not handle breakpoints, not debugging */
}
- target->type->poll(target);
+ target_poll(target);
writeGmon(samples, numSamples, args[1]);
command_print(cmd_ctx, "Wrote %s", args[1]);
break;