return i;
}
-int buf_to_u32_handler(u8 *in_buf, void *priv)
+int buf_to_u32_handler(u8 *in_buf, void *priv, struct scan_field_s *field)
{
u32 *dest = priv;
extern int str_to_buf(char* str, int len, u8 *bin_buf, int buf_size, int radix);
extern char* buf_to_str(u8 *buf, int size, int radix);
-extern int buf_to_u32_handler(u8 *in_buf, void *priv);
+struct scan_field_s;
+extern int buf_to_u32_handler(u8 *in_buf, void *priv, struct scan_field_s *field);
#define CEIL(m, n) ((m + n - 1) / n)
}
-int field_le_to_host(u8 *buffer, void *priv)
+int field_le_to_host(u8 *buffer, void *priv, struct scan_field_s *dummy)
{
var_field_t *field = priv;
field->value = buf_get_u32(buffer, 0, field->num_bits);
extern var_t *variables;
-extern int field_le_to_host(u8 *buffer, void *priv);
+struct scan_field_s;
+extern int field_le_to_host(u8 *buffer, void *priv, struct scan_field_s *field);
extern var_t* get_var_by_namenum(char *namenum);
extern int interpreter_register_commands(struct command_context_s *cmd_ctx);
if (field->in_handler && bitq_in_state.status==ERROR_OK) {
- bitq_in_state.status=(*field->in_handler)(in_buff, field->in_handler_priv);
+ bitq_in_state.status=(*field->in_handler)(in_buff, field->in_handler_priv, field);
}
}
offset = (*p_page)->used;
(*p_page)->used += size;
- return ((*p_page)->address) + offset;
+ u8 *t=(u8 *)((*p_page)->address);
+ return t + offset;
}
void cmd_queue_free()
(*last_cmd)->cmd.scan->fields[i].device = i;
(*last_cmd)->cmd.scan->fields[i].num_bits = scan_size;
(*last_cmd)->cmd.scan->fields[i].in_value = NULL;
- (*last_cmd)->cmd.scan->fields[i].in_handler = NULL;
- (*last_cmd)->cmd.scan->fields[i].in_handler_priv = NULL;
- if (jtag_verify_capture_ir)
+ if ((jtag_verify_capture_ir)&&(fields[i].in_handler==NULL))
{
jtag_set_check_value((*last_cmd)->cmd.scan->fields+i, device->expected, device->expected_mask, NULL);
+ } else if (jtag_verify_capture_ir)
+ {
+ (*last_cmd)->cmd.scan->fields[i].in_handler = fields[i].in_handler;
+ (*last_cmd)->cmd.scan->fields[i].in_handler_priv = fields[i].in_handler_priv;
+ (*last_cmd)->cmd.scan->fields[i].in_check_value = device->expected;
+ (*last_cmd)->cmd.scan->fields[i].in_check_mask = device->expected_mask;
}
/* search the list */
}
-extern int jtag_check_value(u8 *captured, void *priv);
-
int jtag_read_buffer(u8 *buffer, scan_command_t *cmd)
{
int i;
free(char_buf);
#endif
- void *priv = cmd->fields[i].in_handler_priv;
- if (cmd->fields[i].in_handler == &jtag_check_value)
- {
- /* Yuk! we want to pass in the pointer to cmd->fields[i] which is not known
- * when jtag_check_value is invoked
- *
- * Not pretty, but this is part of synthesizing check_mask via in_handler
- * with a minimum of code impact.
- *
- * A cleaner change would be to modify the in_handler to always take field
- * as an argument. Perhaps later...
- *
- * Change in_handler to be varargs and have fields+i as the first vararg?
- *
- */
- priv = cmd->fields + i;
- }
if (cmd->fields[i].in_value)
{
buf_cpy(captured, cmd->fields[i].in_value, num_bits);
if (cmd->fields[i].in_handler)
{
- if (cmd->fields[i].in_handler(cmd->fields[i].in_value, priv) != ERROR_OK)
+ if (cmd->fields[i].in_handler(cmd->fields[i].in_value, cmd->fields[i].in_handler_priv, cmd->fields+i) != ERROR_OK)
{
WARNING("in_handler reported a failed check");
retval = ERROR_JTAG_QUEUE_FAILED;
/* no in_value specified, but a handler takes care of the scanned data */
if (cmd->fields[i].in_handler && (!cmd->fields[i].in_value))
{
- if (cmd->fields[i].in_handler(captured, priv) != ERROR_OK)
+ if (cmd->fields[i].in_handler(captured, cmd->fields[i].in_handler_priv, cmd->fields+i) != ERROR_OK)
{
/* We're going to call the error:handler later, but if the in_handler
* reported an error we report this failure upstream
return retval;
}
-int jtag_check_value(u8 *captured, void *priv)
+int jtag_check_value(u8 *captured, void *priv, scan_field_t *field)
{
int retval = ERROR_OK;
- scan_field_t *field=(scan_field_t *)priv;
int num_bits = field->num_bits;
int compare_failed = 0;
compare_failed = buf_cmp(captured, field->in_check_value, num_bits);
if (compare_failed)
- {
- if (field->in_handler_error_handler.error_handler)
{
- /* ask the error handler if once has been specified if this is a real problem */
- if (field->in_handler_error_handler.error_handler(captured, field->in_handler_error_handler.error_handler_priv) != ERROR_OK)
- retval = ERROR_JTAG_QUEUE_FAILED;
- else
- compare_failed = 0;
- }
- else
- {
- /* if there wasn't a handler specified, we report a failure */
- retval = ERROR_JTAG_QUEUE_FAILED;
- }
-
/* An error handler could have caught the failing check
* only report a problem when there wasn't a handler, or if the handler
* acknowledged the error
field->in_handler_priv = NULL; /* this will be filled in at the invocation site to point to the field duplicate */
field->in_check_value = value;
field->in_check_mask = mask;
- if (in_error_handler)
- field->in_handler_error_handler = *in_error_handler;
- else
- field->in_handler_error_handler.error_handler = NULL;
}
enum scan_type jtag_scan_type(scan_command_t *cmd)
#define TAP_MOVE(from, to) tap_move[tap_move_map[from]][tap_move_map[to]]
-typedef struct error_handler_s
-{
- int (*error_handler)(u8 *in_value, void *priv); /* handle failed checks */
- void *error_handler_priv; /* additional information for the check_handler */
-} error_handler_t;
+typedef void * error_handler_t; /* Later on we can delete error_handler_t, but keep it for now to make patches more readable */
+
+struct scan_field_s;
+typedef int (*in_handler_t)(u8 *in_value, void *priv, struct scan_field_s *field);
typedef struct scan_field_s
{
u8 *out_mask; /* only masked bits care */
u8 *in_value; /* pointer to a 32-bit memory location to take data scanned out */
/* in_check_value/mask, in_handler_error_handler, in_handler_priv can be used by the in handler, otherwise they contain garbage */
- error_handler_t in_handler_error_handler;
u8 *in_check_value; /* used to validate scan results */
u8 *in_check_mask; /* check specified bits against check_value */
- int (*in_handler)(u8 *in_value, void *priv); /* process received buffer using this handler */
+ in_handler_t in_handler; /* process received buffer using this handler */
void *in_handler_priv; /* additional information for the in_handler */
} scan_field_t;
extern int jtag_call_event_callbacks(enum jtag_event event);
extern int jtag_register_event_callback(int (*callback)(enum jtag_event event, void *priv), void *priv);
+extern int jtag_verify_capture_ir;
+
+
/* error codes
* JTAG subsystem uses codes between -100 and -199 */
return ERROR_OK;
}
-int virtex2_jtag_buf_to_u32(u8 *in_buf, void *priv)
+int virtex2_jtag_buf_to_u32(u8 *in_buf, void *priv, struct scan_field_s *field)
{
u32 *dest = priv;
*dest = flip_u32(le_to_h_u32(in_buf), 32);
.quit = arm926ejs_quit
};
-int arm926ejs_catch_broken_irscan(u8 *in_value, void *priv)
+
+int arm926ejs_catch_broken_irscan(u8 *captured, void *priv, scan_field_t *field)
{
- /* The ARM926EJ-S' instruction register is 4 bits wide */
- *in_value &= 0xf;
+ u8 *in_value=field->in_check_value;
- if ((*in_value == 0x0f) || (*in_value == 0x00))
+ /* The ARM926EJ-S' instruction register is 4 bits wide */
+ u8 t=*in_value & 0xf;
+ if ((t == 0x0f) || (t == 0x00))
{
DEBUG("caught ARM926EJ-S invalid Capture-IR result after CP15 access");
return ERROR_OK;
u8 address_buf[2];
u8 nr_w_buf = 0;
u8 access = 1;
- error_handler_t error_handler;
buf_set_u32(address_buf, 0, 14, address);
#ifdef _DEBUG_INSTRUCTION_EXECUTION_
DEBUG("addr: 0x%x value: %8.8x", address, *value);
#endif
-
- error_handler.error_handler = arm926ejs_catch_broken_irscan;
- error_handler.error_handler_priv = NULL;
- arm_jtag_set_instr(jtag_info, 0xc, &error_handler);
+ arm_jtag_set_instr(jtag_info, 0xc, &arm926ejs_catch_broken_irscan);
return ERROR_OK;
}
u8 address_buf[2];
u8 nr_w_buf = 1;
u8 access = 1;
- error_handler_t error_handler;
buf_set_u32(address_buf, 0, 14, address);
buf_set_u32(value_buf, 0, 32, value);
DEBUG("addr: 0x%x value: %8.8x", address, value);
#endif
- error_handler.error_handler = arm926ejs_catch_broken_irscan;
- error_handler.error_handler_priv = NULL;
-
- arm_jtag_set_instr(jtag_info, 0xf, &error_handler);
+ arm_jtag_set_instr(jtag_info, 0xf, &arm926ejs_catch_broken_irscan);
return ERROR_OK;
}
{0, 0},
};
-int arm9tdmi_jtag_error_handler(u8 *in_value, void *priv)
-{
- char *caller = priv;
-
- DEBUG("caller: %s", caller);
-
- return ERROR_JTAG_QUEUE_FAILED;
-}
-
int arm9tdmi_examine_debug_reason(target_t *target)
{
/* get pointers to arch-specific information */
#define _ARM_JTAG_SCAN_N_CHECK_
#endif
-int arm_jtag_set_instr_error_handler(u8 *in_value, void *priv)
-{
- ERROR("setting the new JTAG instruction failed, debugging is likely to be broken");
-
- return ERROR_OK;
-}
-
-int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, error_handler_t *caller_error_handler)
+int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, in_handler_t handler)
{
jtag_device_t *device = jtag_get_device(jtag_info->chain_pos);
field.in_value = NULL;
field.in_check_value = NULL;
field.in_check_mask = NULL;
- field.in_handler = NULL;
+ field.in_handler = handler;
field.in_handler_priv = NULL;
-
-
-
- if (caller_error_handler)
- {
- jtag_set_check_value(&field, NULL, NULL, caller_error_handler);
- }
- else
- {
- error_handler_t error_handler;
- error_handler.error_handler = arm_jtag_set_instr_error_handler;
- error_handler.error_handler_priv = NULL;
- jtag_set_check_value(&field, NULL, NULL, &error_handler);
- }
jtag_add_ir_scan(1, &field, -1, NULL);
}
/* read JTAG buffer into host-endian u32, flipping bit-order */
-int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
{
u32 *dest = priv;
*dest = flip_u32(le_to_h_u32(in_buf), 32);
}
/* read JTAG buffer into little-endian u32, flipping bit-order */
-int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u32_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
return ERROR_OK;
}
/* read JTAG buffer into little-endian u16, flipping bit-order */
-int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u16_to_le(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
return ERROR_OK;
}
/* read JTAG buffer into big-endian u32, flipping bit-order */
-int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u32_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32));
return ERROR_OK;
}
/* read JTAG buffer into big-endian u16, flipping bit-order */
-int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u16_to_be(((u8*)priv), flip_u32(le_to_h_u32(in_buf), 32) & 0xffff);
return ERROR_OK;
}
/* read JTAG buffer into u8, flipping bit-order */
-int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv, struct scan_field_s *field)
{
u8 *dest = priv;
*dest = flip_u32(le_to_h_u32(in_buf), 32) & 0xff;
/* not-flipping variants */
/* read JTAG buffer into host-endian u32 */
-int arm_jtag_buf_to_u32(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_u32(u8 *in_buf, void *priv, struct scan_field_s *field)
{
u32 *dest = priv;
*dest = le_to_h_u32(in_buf);
}
/* read JTAG buffer into little-endian u32 */
-int arm_jtag_buf_to_le32(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_le32(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u32_to_le(((u8*)priv), le_to_h_u32(in_buf));
return ERROR_OK;
}
/* read JTAG buffer into little-endian u16 */
-int arm_jtag_buf_to_le16(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_le16(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u16_to_le(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
return ERROR_OK;
}
/* read JTAG buffer into big-endian u32 */
-int arm_jtag_buf_to_be32(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_be32(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u32_to_be(((u8*)priv), le_to_h_u32(in_buf));
return ERROR_OK;
}
/* read JTAG buffer into big-endian u16 */
-int arm_jtag_buf_to_be16(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_be16(u8 *in_buf, void *priv, struct scan_field_s *field)
{
h_u16_to_be(((u8*)priv), le_to_h_u32(in_buf) & 0xffff);
return ERROR_OK;
}
/* read JTAG buffer into u8 */
-int arm_jtag_buf_to_8(u8 *in_buf, void *priv)
+int arm_jtag_buf_to_8(u8 *in_buf, void *priv, struct scan_field_s *field)
{
u8 *dest = priv;
*dest = le_to_h_u32(in_buf) & 0xff;
u32 intest_instr;
} arm_jtag_t;
-extern int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, error_handler_t *error_handler);
+extern int arm_jtag_set_instr(arm_jtag_t *jtag_info, u32 new_instr, in_handler_t handler);
extern int arm_jtag_scann(arm_jtag_t *jtag_info, u32 new_scan_chain);
extern int arm_jtag_setup_connection(arm_jtag_t *jtag_info);
/* JTAG buffers to host, be and le buffers, flipping variants */
-int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv);
+int arm_jtag_buf_to_u32_flip(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_le32_flip(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_le16_flip(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_be32_flip(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_be16_flip(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_8_flip(u8 *in_buf, void *priv, struct scan_field_s *field);
/* JTAG buffers to host, be and le buffers */
-int arm_jtag_buf_to_u32(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_le32(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_le16(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_be32(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_be16(u8 *in_buf, void *priv);
-int arm_jtag_buf_to_8(u8 *in_buf, void *priv);
+int arm_jtag_buf_to_u32(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_le32(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_le16(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_be32(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_be16(u8 *in_buf, void *priv, struct scan_field_s *field);
+int arm_jtag_buf_to_8(u8 *in_buf, void *priv, struct scan_field_s *field);
#endif /* ARM_JTAG */
{
if (trace->trace_points)
free(trace->trace_points);
- trace->num_trace_points = NULL;
+ trace->num_trace_points = 0;
trace->trace_points_size = 0;
return ERROR_OK;