1 /***************************************************************************
\r
2 * Copyright (C) 2009 by Simon Qian *
\r
3 * SimonQian@SimonQian.com *
\r
5 * This program is free software; you can redistribute it and/or modify *
\r
6 * it under the terms of the GNU General Public License as published by *
\r
7 * the Free Software Foundation; either version 2 of the License, or *
\r
8 * (at your option) any later version. *
\r
10 * This program is distributed in the hope that it will be useful, *
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
13 * GNU General Public License for more details. *
\r
15 * You should have received a copy of the GNU General Public License *
\r
16 * along with this program; if not, write to the *
\r
17 * Free Software Foundation, Inc., *
\r
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
\r
19 ***************************************************************************/
\r
20 #ifdef HAVE_CONFIG_H
\r
24 #include "replacements.h"
\r
28 #include "register.h"
\r
32 #include "binarybuffer.h"
\r
33 #include "time_support.h"
\r
34 #include "breakpoints.h"
\r
40 #include <sys/types.h>
\r
44 #define AVR_JTAG_INS_LEN 4
\r
47 int avr_register_commands(struct command_context_s *cmd_ctx);
\r
49 /* forward declarations */
\r
50 int avr_target_create(struct target_s *target, Jim_Interp *interp);
\r
51 int avr_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
\r
54 int avr_arch_state(struct target_s *target);
\r
55 int avr_poll(target_t *target);
\r
56 int avr_halt(target_t *target);
\r
57 int avr_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution);
\r
58 int avr_step(struct target_s *target, int current, u32 address, int handle_breakpoints);
\r
60 int avr_assert_reset(target_t *target);
\r
61 int avr_deassert_reset(target_t *target);
\r
62 int avr_soft_reset_halt(struct target_s *target);
\r
64 /* IR and DR functions */
\r
65 int avr_jtag_sendinstr(jtag_tap_t *tap, u8 *ir_in, u8 ir_out);
\r
66 int avr_jtag_senddat(jtag_tap_t *tap, u32 *dr_in, u32 dr_out, int len);
\r
68 int mcu_write_ir(jtag_tap_t *tap, u8 *ir_in, u8 *ir_out, int ir_len, int rti);
\r
69 int mcu_write_dr(jtag_tap_t *tap, u8 *dr_in, u8 *dr_out, int dr_len, int rti);
\r
70 int mcu_write_ir_u8(jtag_tap_t *tap, u8 *ir_in, u8 ir_out, int ir_len, int rti);
\r
71 int mcu_write_dr_u8(jtag_tap_t *tap, u8 *ir_in, u8 ir_out, int dr_len, int rti);
\r
72 int mcu_write_ir_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int ir_len, int rti);
\r
73 int mcu_write_dr_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int dr_len, int rti);
\r
74 int mcu_write_ir_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int ir_len, int rti);
\r
75 int mcu_write_dr_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int dr_len, int rti);
\r
76 int mcu_execute_queue(void);
\r
78 target_type_t avr_target =
\r
83 .arch_state = avr_arch_state,
\r
85 .target_request_data = NULL,
\r
88 .resume = avr_resume,
\r
91 .assert_reset = avr_assert_reset,
\r
92 .deassert_reset = avr_deassert_reset,
\r
93 .soft_reset_halt = avr_soft_reset_halt,
\r
95 .get_gdb_reg_list = avr_get_gdb_reg_list,
\r
97 .read_memory = avr_read_memory,
\r
98 .write_memory = avr_write_memory,
\r
99 .bulk_write_memory = avr_bulk_write_memory,
\r
100 .checksum_memory = avr_checksum_memory,
\r
101 .blank_check_memory = avr_blank_check_memory,
\r
103 .run_algorithm = avr_run_algorithm,
\r
105 .add_breakpoint = avr_add_breakpoint,
\r
106 .remove_breakpoint = avr_remove_breakpoint,
\r
107 .add_watchpoint = avr_add_watchpoint,
\r
108 .remove_watchpoint = avr_remove_watchpoint,
\r
110 .register_commands = avr_register_commands,
\r
111 .target_create = avr_target_create,
\r
112 .init_target = avr_init_target,
\r
115 .virt2phys = avr_virt2phys,
\r
120 int avr_register_commands(struct command_context_s *cmd_ctx)
\r
122 LOG_DEBUG(__FUNCTION__);
\r
126 int avr_target_create(struct target_s *target, Jim_Interp *interp)
\r
128 avr_common_t *avr = calloc(1, sizeof(avr_common_t));
\r
130 avr->jtag_info.tap = target->tap;
\r
131 target->arch_info = avr;
\r
136 int avr_init_target(struct command_context_s *cmd_ctx, struct target_s *target)
\r
138 LOG_DEBUG(__FUNCTION__);
\r
144 LOG_DEBUG(__FUNCTION__);
\r
148 int avr_arch_state(struct target_s *target)
\r
150 LOG_DEBUG(__FUNCTION__);
\r
154 int avr_poll(target_t *target)
\r
156 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
\r
158 target->state = TARGET_HALTED;
\r
161 LOG_DEBUG(__FUNCTION__);
\r
165 int avr_halt(target_t *target)
\r
167 LOG_DEBUG(__FUNCTION__);
\r
171 int avr_resume(struct target_s *target, int current, u32 address, int handle_breakpoints, int debug_execution)
\r
173 LOG_DEBUG(__FUNCTION__);
\r
177 int avr_step(struct target_s *target, int current, u32 address, int handle_breakpoints)
\r
179 LOG_DEBUG(__FUNCTION__);
\r
183 int avr_assert_reset(target_t *target)
\r
185 target->state = TARGET_RESET;
\r
187 LOG_DEBUG(__FUNCTION__);
\r
191 int avr_deassert_reset(target_t *target)
\r
193 target->state = TARGET_RUNNING;
\r
195 LOG_DEBUG(__FUNCTION__);
\r
199 int avr_soft_reset_halt(struct target_s *target)
\r
201 LOG_DEBUG(__FUNCTION__);
\r
205 int avr_jtag_senddat(jtag_tap_t *tap, u32* dr_in, u32 dr_out, int len)
\r
207 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
\r
210 int avr_jtag_sendinstr(jtag_tap_t *tap, u8 *ir_in, u8 ir_out)
\r
212 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
\r
215 /* IR and DR functions */
\r
216 int mcu_write_ir(jtag_tap_t *tap, u8 *ir_in, u8 *ir_out, int ir_len, int rti)
\r
220 LOG_ERROR("invalid tap");
\r
223 if (ir_len != tap->ir_length)
\r
225 LOG_ERROR("invalid ir_len");
\r
230 scan_field_t field[1];
\r
232 field[0].tap = tap;
\r
233 field[0].num_bits = tap->ir_length;
\r
234 field[0].out_value = ir_out;
\r
235 field[0].out_mask = NULL;
\r
236 field[0].in_value = ir_in;
\r
237 field[0].in_check_value = NULL;
\r
238 field[0].in_check_mask = NULL;
\r
239 field[0].in_handler = NULL;
\r
240 field[0].in_handler_priv = NULL;
\r
241 jtag_add_plain_ir_scan(sizeof(field) / sizeof(field[0]), field, TAP_IDLE);
\r
247 int mcu_write_dr(jtag_tap_t *tap, u8 *dr_in, u8 *dr_out, int dr_len, int rti)
\r
251 LOG_ERROR("invalid tap");
\r
256 scan_field_t field[1];
\r
258 field[0].tap = tap;
\r
259 field[0].num_bits = dr_len;
\r
260 field[0].out_value = dr_out;
\r
261 field[0].out_mask = NULL;
\r
262 field[0].in_value = dr_in;
\r
263 field[0].in_check_value = NULL;
\r
264 field[0].in_check_mask = NULL;
\r
265 field[0].in_handler = NULL;
\r
266 field[0].in_handler_priv = NULL;
\r
267 jtag_add_plain_dr_scan(sizeof(field) / sizeof(field[0]), field, TAP_IDLE);
\r
273 int mcu_write_ir_u8(jtag_tap_t *tap, u8 *ir_in, u8 ir_out, int ir_len, int rti)
\r
277 LOG_ERROR("ir_len overflow, maxium is 8");
\r
281 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
\r
286 int mcu_write_dr_u8(jtag_tap_t *tap, u8 *dr_in, u8 dr_out, int dr_len, int rti)
\r
290 LOG_ERROR("dr_len overflow, maxium is 8");
\r
294 mcu_write_dr(tap, dr_in, &dr_out, dr_len, rti);
\r
299 int mcu_write_ir_u16(jtag_tap_t *tap, u16 *ir_in, u16 ir_out, int ir_len, int rti)
\r
303 LOG_ERROR("ir_len overflow, maxium is 16");
\r
307 mcu_write_ir(tap, (u8*)ir_in, (u8*)&ir_out, ir_len, rti);
\r
312 int mcu_write_dr_u16(jtag_tap_t *tap, u16 *dr_in, u16 dr_out, int dr_len, int rti)
\r
316 LOG_ERROR("dr_len overflow, maxium is 16");
\r
320 mcu_write_dr(tap, (u8*)dr_in, (u8*)&dr_out, dr_len, rti);
\r
325 int mcu_write_ir_u32(jtag_tap_t *tap, u32 *ir_in, u32 ir_out, int ir_len, int rti)
\r
329 LOG_ERROR("ir_len overflow, maxium is 32");
\r
333 mcu_write_ir(tap, (u8*)ir_in, (u8*)&ir_out, ir_len, rti);
\r
338 int mcu_write_dr_u32(jtag_tap_t *tap, u32 *dr_in, u32 dr_out, int dr_len, int rti)
\r
342 LOG_ERROR("dr_len overflow, maxium is 32");
\r
346 mcu_write_dr(tap, (u8*)dr_in, (u8*)&dr_out, dr_len, rti);
\r
351 int mcu_execute_queue(void)
\r
353 return jtag_execute_queue();
\r