gdb-server: fix error reporting bugs
[openocd/genbsdl.git] / src / target / avrt.c
blob17f7c241e67308950b49da745d42878b71fb9ee1
1 /***************************************************************************
2 * Copyright (C) 2009 by Simon Qian *
3 * SimonQian@SimonQian.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "avrt.h"
25 #include "target.h"
26 #include "target_type.h"
29 #define AVR_JTAG_INS_LEN 4
31 /* forward declarations */
32 int avr_target_create(struct target *target, Jim_Interp *interp);
33 int avr_init_target(struct command_context *cmd_ctx, struct target *target);
35 int avr_arch_state(struct target *target);
36 int avr_poll(struct target *target);
37 int avr_halt(struct target *target);
38 int avr_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution);
39 int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints);
41 int avr_assert_reset(struct target *target);
42 int avr_deassert_reset(struct target *target);
43 int avr_soft_reset_halt(struct target *target);
45 /* IR and DR functions */
46 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out);
47 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int len);
49 int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
50 int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti);
51 int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
52 int mcu_write_dr_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int dr_len, int rti);
53 int mcu_write_ir_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int ir_len, int rti);
54 int mcu_write_dr_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int dr_len, int rti);
55 int mcu_write_ir_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int ir_len, int rti);
56 int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
57 int mcu_execute_queue(void);
59 struct target_type avr_target =
61 .name = "avr",
63 .poll = avr_poll,
64 .arch_state = avr_arch_state,
66 .target_request_data = NULL,
68 .halt = avr_halt,
69 .resume = avr_resume,
70 .step = avr_step,
72 .assert_reset = avr_assert_reset,
73 .deassert_reset = avr_deassert_reset,
74 .soft_reset_halt = avr_soft_reset_halt,
76 .get_gdb_reg_list = avr_get_gdb_reg_list,
78 .read_memory = avr_read_memory,
79 .write_memory = avr_write_memory,
80 .bulk_write_memory = avr_bulk_write_memory,
81 .checksum_memory = avr_checksum_memory,
82 .blank_check_memory = avr_blank_check_memory,
84 .run_algorithm = avr_run_algorithm,
86 .add_breakpoint = avr_add_breakpoint,
87 .remove_breakpoint = avr_remove_breakpoint,
88 .add_watchpoint = avr_add_watchpoint,
89 .remove_watchpoint = avr_remove_watchpoint,
91 .target_create = avr_target_create,
92 .init_target = avr_init_target,
95 int avr_target_create(struct target *target, Jim_Interp *interp)
97 struct avr_common *avr = calloc(1, sizeof(struct avr_common));
99 avr->jtag_info.tap = target->tap;
100 target->arch_info = avr;
102 return ERROR_OK;
105 int avr_init_target(struct command_context *cmd_ctx, struct target *target)
107 LOG_DEBUG("%s", __FUNCTION__);
108 return ERROR_OK;
111 int avr_arch_state(struct target *target)
113 LOG_DEBUG("%s", __FUNCTION__);
114 return ERROR_OK;
117 int avr_poll(struct target *target)
119 if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
121 target->state = TARGET_HALTED;
124 LOG_DEBUG("%s", __FUNCTION__);
125 return ERROR_OK;
128 int avr_halt(struct target *target)
130 LOG_DEBUG("%s", __FUNCTION__);
131 return ERROR_OK;
134 int avr_resume(struct target *target, int current, uint32_t address, int handle_breakpoints, int debug_execution)
136 LOG_DEBUG("%s", __FUNCTION__);
137 return ERROR_OK;
140 int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints)
142 LOG_DEBUG("%s", __FUNCTION__);
143 return ERROR_OK;
146 int avr_assert_reset(struct target *target)
148 target->state = TARGET_RESET;
150 LOG_DEBUG("%s", __FUNCTION__);
151 return ERROR_OK;
154 int avr_deassert_reset(struct target *target)
156 target->state = TARGET_RUNNING;
158 LOG_DEBUG("%s", __FUNCTION__);
159 return ERROR_OK;
162 int avr_soft_reset_halt(struct target *target)
164 LOG_DEBUG("%s", __FUNCTION__);
165 return ERROR_OK;
168 int avr_jtag_senddat(struct jtag_tap *tap, uint32_t* dr_in, uint32_t dr_out, int len)
170 return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
173 int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
175 return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
178 /* IR and DR functions */
179 int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti)
181 if (NULL == tap)
183 LOG_ERROR("invalid tap");
184 return ERROR_FAIL;
186 if (ir_len != tap->ir_length)
188 LOG_ERROR("invalid ir_len");
189 return ERROR_FAIL;
193 jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
196 return ERROR_OK;
199 int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti)
201 if (NULL == tap)
203 LOG_ERROR("invalid tap");
204 return ERROR_FAIL;
208 jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
211 return ERROR_OK;
214 int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti)
216 if (ir_len > 8)
218 LOG_ERROR("ir_len overflow, maxium is 8");
219 return ERROR_FAIL;
222 mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
224 return ERROR_OK;
227 int mcu_write_dr_u8(struct jtag_tap *tap, uint8_t *dr_in, uint8_t dr_out, int dr_len, int rti)
229 if (dr_len > 8)
231 LOG_ERROR("dr_len overflow, maxium is 8");
232 return ERROR_FAIL;
235 mcu_write_dr(tap, dr_in, &dr_out, dr_len, rti);
237 return ERROR_OK;
240 int mcu_write_ir_u16(struct jtag_tap *tap, uint16_t *ir_in, uint16_t ir_out, int ir_len, int rti)
242 if (ir_len > 16)
244 LOG_ERROR("ir_len overflow, maxium is 16");
245 return ERROR_FAIL;
248 mcu_write_ir(tap, (uint8_t*)ir_in, (uint8_t*)&ir_out, ir_len, rti);
250 return ERROR_OK;
253 int mcu_write_dr_u16(struct jtag_tap *tap, uint16_t *dr_in, uint16_t dr_out, int dr_len, int rti)
255 if (dr_len > 16)
257 LOG_ERROR("dr_len overflow, maxium is 16");
258 return ERROR_FAIL;
261 mcu_write_dr(tap, (uint8_t*)dr_in, (uint8_t*)&dr_out, dr_len, rti);
263 return ERROR_OK;
266 int mcu_write_ir_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int ir_len, int rti)
268 if (ir_len > 32)
270 LOG_ERROR("ir_len overflow, maxium is 32");
271 return ERROR_FAIL;
274 mcu_write_ir(tap, (uint8_t*)ir_in, (uint8_t*)&ir_out, ir_len, rti);
276 return ERROR_OK;
279 int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in, uint32_t dr_out, int dr_len, int rti)
281 if (dr_len > 32)
283 LOG_ERROR("dr_len overflow, maxium is 32");
284 return ERROR_FAIL;
287 mcu_write_dr(tap, (uint8_t*)dr_in, (uint8_t*)&dr_out, dr_len, rti);
289 return ERROR_OK;
292 int mcu_execute_queue(void)
294 return jtag_execute_queue();