]> git.gag.com Git - fw/openocd/blob - src/target/arm966e.c
retire out_mask - not used anywhere
[fw/openocd] / src / target / arm966e.c
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
5  *   Copyright (C) 2008 by Spencer Oliver                                  *
6  *   spen@spen-soft.co.uk                                                  *
7  *                                                                         *
8  *   This program is free software; you can redistribute it and/or modify  *
9  *   it under the terms of the GNU General Public License as published by  *
10  *   the Free Software Foundation; either version 2 of the License, or     *
11  *   (at your option) any later version.                                   *
12  *                                                                         *
13  *   This program is distributed in the hope that it will be useful,       *
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16  *   GNU General Public License for more details.                          *
17  *                                                                         *
18  *   You should have received a copy of the GNU General Public License     *
19  *   along with this program; if not, write to the                         *
20  *   Free Software Foundation, Inc.,                                       *
21  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
22  ***************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "arm966e.h"
28
29 #include "arm7_9_common.h"
30 #include "register.h"
31 #include "target.h"
32 #include "armv4_5.h"
33 #include "embeddedice.h"
34 #include "log.h"
35 #include "jtag.h"
36 #include "arm_jtag.h"
37
38 #include <stdlib.h>
39 #include <string.h>
40
41 #if 0
42 #define _DEBUG_INSTRUCTION_EXECUTION_
43 #endif
44
45 /* cli handling */
46 int arm966e_register_commands(struct command_context_s *cmd_ctx);
47
48 /* forward declarations */
49 int arm966e_target_create(struct target_s *target, Jim_Interp *interp);
50 int arm966e_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
51 int arm966e_quit(void);
52
53 target_type_t arm966e_target =
54 {
55         .name = "arm966e",
56
57         .poll = arm7_9_poll,
58         .arch_state = armv4_5_arch_state,
59
60         .target_request_data = arm7_9_target_request_data,
61
62         .halt = arm7_9_halt,
63         .resume = arm7_9_resume,
64         .step = arm7_9_step,
65
66         .assert_reset = arm7_9_assert_reset,
67         .deassert_reset = arm7_9_deassert_reset,
68         .soft_reset_halt = arm7_9_soft_reset_halt,
69
70         .get_gdb_reg_list = armv4_5_get_gdb_reg_list,
71
72         .read_memory = arm7_9_read_memory,
73         .write_memory = arm7_9_write_memory,
74         .bulk_write_memory = arm7_9_bulk_write_memory,
75         .checksum_memory = arm7_9_checksum_memory,
76         .blank_check_memory = arm7_9_blank_check_memory,
77
78         .run_algorithm = armv4_5_run_algorithm,
79
80         .add_breakpoint = arm7_9_add_breakpoint,
81         .remove_breakpoint = arm7_9_remove_breakpoint,
82         .add_watchpoint = arm7_9_add_watchpoint,
83         .remove_watchpoint = arm7_9_remove_watchpoint,
84
85         .register_commands = arm966e_register_commands,
86         .target_create = arm966e_target_create,
87         .init_target = arm966e_init_target,
88         .examine = arm9tdmi_examine,
89         .quit = arm966e_quit,
90 };
91
92 int arm966e_init_target(struct command_context_s *cmd_ctx, struct target_s *target)
93 {
94         arm9tdmi_init_target(cmd_ctx, target);
95
96         return ERROR_OK;
97 }
98
99 int arm966e_quit(void)
100 {
101         return ERROR_OK;
102 }
103
104 int arm966e_init_arch_info(target_t *target, arm966e_common_t *arm966e, jtag_tap_t *tap)
105 {
106         arm9tdmi_common_t *arm9tdmi = &arm966e->arm9tdmi_common;
107         arm7_9_common_t *arm7_9 = &arm9tdmi->arm7_9_common;
108
109         arm9tdmi_init_arch_info(target, arm9tdmi, tap);
110
111         arm9tdmi->arch_info = arm966e;
112         arm966e->common_magic = ARM966E_COMMON_MAGIC;
113
114         /* The ARM966E-S implements the ARMv5TE architecture which
115          * has the BKPT instruction, so we don't have to use a watchpoint comparator
116          */
117         arm7_9->arm_bkpt = ARMV5_BKPT(0x0);
118         arm7_9->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
119
120         return ERROR_OK;
121 }
122
123 int arm966e_target_create( struct target_s *target, Jim_Interp *interp )
124 {
125         arm966e_common_t *arm966e = calloc(1,sizeof(arm966e_common_t));
126
127         arm966e_init_arch_info(target, arm966e, target->tap);
128
129         return ERROR_OK;
130 }
131
132 int arm966e_get_arch_pointers(target_t *target, armv4_5_common_t **armv4_5_p, arm7_9_common_t **arm7_9_p, arm9tdmi_common_t **arm9tdmi_p, arm966e_common_t **arm966e_p)
133 {
134         armv4_5_common_t *armv4_5 = target->arch_info;
135         arm7_9_common_t *arm7_9;
136         arm9tdmi_common_t *arm9tdmi;
137         arm966e_common_t *arm966e;
138
139         if (armv4_5->common_magic != ARMV4_5_COMMON_MAGIC)
140         {
141                 return -1;
142         }
143
144         arm7_9 = armv4_5->arch_info;
145         if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC)
146         {
147                 return -1;
148         }
149
150         arm9tdmi = arm7_9->arch_info;
151         if (arm9tdmi->common_magic != ARM9TDMI_COMMON_MAGIC)
152         {
153                 return -1;
154         }
155
156         arm966e = arm9tdmi->arch_info;
157         if (arm966e->common_magic != ARM966E_COMMON_MAGIC)
158         {
159                 return -1;
160         }
161
162         *armv4_5_p = armv4_5;
163         *arm7_9_p = arm7_9;
164         *arm9tdmi_p = arm9tdmi;
165         *arm966e_p = arm966e;
166
167         return ERROR_OK;
168 }
169
170 int arm966e_read_cp15(target_t *target, int reg_addr, u32 *value)
171 {
172         int retval = ERROR_OK;
173         armv4_5_common_t *armv4_5 = target->arch_info;
174         arm7_9_common_t *arm7_9 = armv4_5->arch_info;
175         arm_jtag_t *jtag_info = &arm7_9->jtag_info;
176         scan_field_t fields[3];
177         u8 reg_addr_buf = reg_addr & 0x3f;
178         u8 nr_w_buf = 0;
179
180         jtag_add_end_state(TAP_IDLE);
181         if((retval = arm_jtag_scann(jtag_info, 0xf)) != ERROR_OK)
182         {
183                 return retval;
184         }
185         arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
186
187         fields[0].tap = jtag_info->tap;
188         fields[0].num_bits = 32;
189         fields[0].out_value = NULL;
190         
191         fields[0].in_value = NULL;
192         fields[0].in_check_value = NULL;
193         fields[0].in_check_mask = NULL;
194         fields[0].in_handler = NULL;
195         fields[0].in_handler_priv = NULL;
196
197         fields[1].tap = jtag_info->tap;
198         fields[1].num_bits = 6;
199         fields[1].out_value = &reg_addr_buf;
200         
201         fields[1].in_value = NULL;
202         fields[1].in_check_value = NULL;
203         fields[1].in_check_mask = NULL;
204         fields[1].in_handler = NULL;
205         fields[1].in_handler_priv = NULL;
206
207         fields[2].tap = jtag_info->tap;
208         fields[2].num_bits = 1;
209         fields[2].out_value = &nr_w_buf;
210         
211         fields[2].in_value = NULL;
212         fields[2].in_check_value = NULL;
213         fields[2].in_check_mask = NULL;
214         fields[2].in_handler = NULL;
215         fields[2].in_handler_priv = NULL;
216
217         jtag_add_dr_scan(3, fields, TAP_INVALID);
218
219         fields[0].in_handler_priv = value;
220         fields[0].in_handler = arm_jtag_buf_to_u32; /* deprecated! invoke this from user code! */
221
222         jtag_add_dr_scan(3, fields, TAP_INVALID);
223
224 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
225         if((retval = jtag_execute_queue()) != ERROR_OK)
226         {
227                 return retval;
228         }
229         LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, *value);
230 #endif
231
232         return ERROR_OK;
233 }
234
235 int arm966e_write_cp15(target_t *target, int reg_addr, u32 value)
236 {
237         int retval = ERROR_OK;
238         armv4_5_common_t *armv4_5 = target->arch_info;
239         arm7_9_common_t *arm7_9 = armv4_5->arch_info;
240         arm_jtag_t *jtag_info = &arm7_9->jtag_info;
241         scan_field_t fields[3];
242         u8 reg_addr_buf = reg_addr & 0x3f;
243         u8 nr_w_buf = 1;
244         u8 value_buf[4];
245
246         buf_set_u32(value_buf, 0, 32, value);
247
248         jtag_add_end_state(TAP_IDLE);
249         if((retval = arm_jtag_scann(jtag_info, 0xf)) != ERROR_OK)
250         {
251                 return retval;
252         }
253         arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
254
255         fields[0].tap = jtag_info->tap;
256         fields[0].num_bits = 32;
257         fields[0].out_value = value_buf;
258         
259         fields[0].in_value = NULL;
260         fields[0].in_check_value = NULL;
261         fields[0].in_check_mask = NULL;
262         fields[0].in_handler = NULL;
263         fields[0].in_handler_priv = NULL;
264
265         fields[1].tap = jtag_info->tap;
266         fields[1].num_bits = 6;
267         fields[1].out_value = &reg_addr_buf;
268         
269         fields[1].in_value = NULL;
270         fields[1].in_check_value = NULL;
271         fields[1].in_check_mask = NULL;
272         fields[1].in_handler = NULL;
273         fields[1].in_handler_priv = NULL;
274
275         fields[2].tap = jtag_info->tap;
276         fields[2].num_bits = 1;
277         fields[2].out_value = &nr_w_buf;
278         
279         fields[2].in_value = NULL;
280         fields[2].in_check_value = NULL;
281         fields[2].in_check_mask = NULL;
282         fields[2].in_handler = NULL;
283         fields[2].in_handler_priv = NULL;
284
285         jtag_add_dr_scan(3, fields, TAP_INVALID);
286
287 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
288         LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, value);
289 #endif
290
291         return ERROR_OK;
292 }
293
294 int arm966e_handle_cp15_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
295 {
296         int retval;
297         target_t *target = get_current_target(cmd_ctx);
298         armv4_5_common_t *armv4_5;
299         arm7_9_common_t *arm7_9;
300         arm9tdmi_common_t *arm9tdmi;
301         arm966e_common_t *arm966e;
302         arm_jtag_t *jtag_info;
303
304         if (arm966e_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm966e) != ERROR_OK)
305         {
306                 command_print(cmd_ctx, "current target isn't an ARM966e target");
307                 return ERROR_OK;
308         }
309
310         jtag_info = &arm7_9->jtag_info;
311
312         if (target->state != TARGET_HALTED)
313         {
314                 command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
315                 return ERROR_OK;
316         }
317
318         /* one or more argument, access a single register (write if second argument is given */
319         if (argc >= 1)
320         {
321                 int address = strtoul(args[0], NULL, 0);
322
323                 if (argc == 1)
324                 {
325                         u32 value;
326                         if ((retval = arm966e_read_cp15(target, address, &value)) != ERROR_OK)
327                         {
328                                 command_print(cmd_ctx, "couldn't access reg %i", address);
329                                 return ERROR_OK;
330                         }
331                         if((retval = jtag_execute_queue()) != ERROR_OK)
332                         {
333                                 return retval;
334                         }
335
336                         command_print(cmd_ctx, "%i: %8.8x", address, value);
337                 }
338                 else if (argc == 2)
339                 {
340                         u32 value = strtoul(args[1], NULL, 0);
341                         if ((retval = arm966e_write_cp15(target, address, value)) != ERROR_OK)
342                         {
343                                 command_print(cmd_ctx, "couldn't access reg %i", address);
344                                 return ERROR_OK;
345                         }
346                         command_print(cmd_ctx, "%i: %8.8x", address, value);
347                 }
348         }
349
350         return ERROR_OK;
351 }
352
353 int arm966e_register_commands(struct command_context_s *cmd_ctx)
354 {
355         int retval;
356         command_t *arm966e_cmd;
357
358         retval = arm9tdmi_register_commands(cmd_ctx);
359         arm966e_cmd = register_command(cmd_ctx, NULL, "arm966e", NULL, COMMAND_ANY, "arm966e specific commands");
360         register_command(cmd_ctx, arm966e_cmd, "cp15", arm966e_handle_cp15_command, COMMAND_EXEC, "display/modify cp15 register <num> [value]");
361
362         return retval;
363 }