Audit and eliminate redundant #include directives in arm target files.
[openocd.git] / 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
30 #if 0
31 #define _DEBUG_INSTRUCTION_EXECUTION_
32 #endif
33
34 /* cli handling */
35 int arm966e_register_commands(struct command_context_s *cmd_ctx);
36
37 /* forward declarations */
38 int arm966e_target_create(struct target_s *target, Jim_Interp *interp);
39 int arm966e_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
40 int arm966e_quit(void);
41
42 target_type_t arm966e_target =
43 {
44 .name = "arm966e",
45
46 .poll = arm7_9_poll,
47 .arch_state = armv4_5_arch_state,
48
49 .target_request_data = arm7_9_target_request_data,
50
51 .halt = arm7_9_halt,
52 .resume = arm7_9_resume,
53 .step = arm7_9_step,
54
55 .assert_reset = arm7_9_assert_reset,
56 .deassert_reset = arm7_9_deassert_reset,
57 .soft_reset_halt = arm7_9_soft_reset_halt,
58
59 .get_gdb_reg_list = armv4_5_get_gdb_reg_list,
60
61 .read_memory = arm7_9_read_memory,
62 .write_memory = arm7_9_write_memory,
63 .bulk_write_memory = arm7_9_bulk_write_memory,
64 .checksum_memory = arm7_9_checksum_memory,
65 .blank_check_memory = arm7_9_blank_check_memory,
66
67 .run_algorithm = armv4_5_run_algorithm,
68
69 .add_breakpoint = arm7_9_add_breakpoint,
70 .remove_breakpoint = arm7_9_remove_breakpoint,
71 .add_watchpoint = arm7_9_add_watchpoint,
72 .remove_watchpoint = arm7_9_remove_watchpoint,
73
74 .register_commands = arm966e_register_commands,
75 .target_create = arm966e_target_create,
76 .init_target = arm966e_init_target,
77 .examine = arm9tdmi_examine,
78 .quit = arm966e_quit,
79 };
80
81 int arm966e_init_target(struct command_context_s *cmd_ctx, struct target_s *target)
82 {
83 arm9tdmi_init_target(cmd_ctx, target);
84
85 return ERROR_OK;
86 }
87
88 int arm966e_quit(void)
89 {
90 return ERROR_OK;
91 }
92
93 int arm966e_init_arch_info(target_t *target, arm966e_common_t *arm966e, jtag_tap_t *tap)
94 {
95 arm9tdmi_common_t *arm9tdmi = &arm966e->arm9tdmi_common;
96 arm7_9_common_t *arm7_9 = &arm9tdmi->arm7_9_common;
97
98 arm9tdmi_init_arch_info(target, arm9tdmi, tap);
99
100 arm9tdmi->arch_info = arm966e;
101 arm966e->common_magic = ARM966E_COMMON_MAGIC;
102
103 /* The ARM966E-S implements the ARMv5TE architecture which
104 * has the BKPT instruction, so we don't have to use a watchpoint comparator
105 */
106 arm7_9->arm_bkpt = ARMV5_BKPT(0x0);
107 arm7_9->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
108
109 return ERROR_OK;
110 }
111
112 int arm966e_target_create( struct target_s *target, Jim_Interp *interp )
113 {
114 arm966e_common_t *arm966e = calloc(1,sizeof(arm966e_common_t));
115
116 arm966e_init_arch_info(target, arm966e, target->tap);
117
118 return ERROR_OK;
119 }
120
121 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)
122 {
123 armv4_5_common_t *armv4_5 = target->arch_info;
124 arm7_9_common_t *arm7_9;
125 arm9tdmi_common_t *arm9tdmi;
126 arm966e_common_t *arm966e;
127
128 if (armv4_5->common_magic != ARMV4_5_COMMON_MAGIC)
129 {
130 return -1;
131 }
132
133 arm7_9 = armv4_5->arch_info;
134 if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC)
135 {
136 return -1;
137 }
138
139 arm9tdmi = arm7_9->arch_info;
140 if (arm9tdmi->common_magic != ARM9TDMI_COMMON_MAGIC)
141 {
142 return -1;
143 }
144
145 arm966e = arm9tdmi->arch_info;
146 if (arm966e->common_magic != ARM966E_COMMON_MAGIC)
147 {
148 return -1;
149 }
150
151 *armv4_5_p = armv4_5;
152 *arm7_9_p = arm7_9;
153 *arm9tdmi_p = arm9tdmi;
154 *arm966e_p = arm966e;
155
156 return ERROR_OK;
157 }
158
159 int arm966e_read_cp15(target_t *target, int reg_addr, u32 *value)
160 {
161 int retval = ERROR_OK;
162 armv4_5_common_t *armv4_5 = target->arch_info;
163 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
164 arm_jtag_t *jtag_info = &arm7_9->jtag_info;
165 scan_field_t fields[3];
166 u8 reg_addr_buf = reg_addr & 0x3f;
167 u8 nr_w_buf = 0;
168
169 jtag_add_end_state(TAP_IDLE);
170 if ((retval = arm_jtag_scann(jtag_info, 0xf)) != ERROR_OK)
171 {
172 return retval;
173 }
174 arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
175
176 fields[0].tap = jtag_info->tap;
177 fields[0].num_bits = 32;
178 fields[0].out_value = NULL;
179 fields[0].in_value = NULL;
180
181 fields[1].tap = jtag_info->tap;
182 fields[1].num_bits = 6;
183 fields[1].out_value = &reg_addr_buf;
184 fields[1].in_value = NULL;
185
186 fields[2].tap = jtag_info->tap;
187 fields[2].num_bits = 1;
188 fields[2].out_value = &nr_w_buf;
189 fields[2].in_value = NULL;
190
191 jtag_add_dr_scan(3, fields, TAP_INVALID);
192
193 u8 tmp[4];
194 fields[1].in_value = tmp;
195
196 jtag_add_dr_scan_now(3, fields, TAP_INVALID);
197
198 *value=le_to_h_u32(tmp);
199
200
201 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
202 if ((retval = jtag_execute_queue()) != ERROR_OK)
203 {
204 return retval;
205 }
206 LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, *value);
207 #endif
208
209 return ERROR_OK;
210 }
211
212 int arm966e_write_cp15(target_t *target, int reg_addr, u32 value)
213 {
214 int retval = ERROR_OK;
215 armv4_5_common_t *armv4_5 = target->arch_info;
216 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
217 arm_jtag_t *jtag_info = &arm7_9->jtag_info;
218 scan_field_t fields[3];
219 u8 reg_addr_buf = reg_addr & 0x3f;
220 u8 nr_w_buf = 1;
221 u8 value_buf[4];
222
223 buf_set_u32(value_buf, 0, 32, value);
224
225 jtag_add_end_state(TAP_IDLE);
226 if ((retval = arm_jtag_scann(jtag_info, 0xf)) != ERROR_OK)
227 {
228 return retval;
229 }
230 arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
231
232 fields[0].tap = jtag_info->tap;
233 fields[0].num_bits = 32;
234 fields[0].out_value = value_buf;
235 fields[0].in_value = NULL;
236
237 fields[1].tap = jtag_info->tap;
238 fields[1].num_bits = 6;
239 fields[1].out_value = &reg_addr_buf;
240 fields[1].in_value = NULL;
241
242 fields[2].tap = jtag_info->tap;
243 fields[2].num_bits = 1;
244 fields[2].out_value = &nr_w_buf;
245 fields[2].in_value = NULL;
246
247 jtag_add_dr_scan(3, fields, TAP_INVALID);
248
249 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
250 LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, value);
251 #endif
252
253 return ERROR_OK;
254 }
255
256 int arm966e_handle_cp15_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
257 {
258 int retval;
259 target_t *target = get_current_target(cmd_ctx);
260 armv4_5_common_t *armv4_5;
261 arm7_9_common_t *arm7_9;
262 arm9tdmi_common_t *arm9tdmi;
263 arm966e_common_t *arm966e;
264 arm_jtag_t *jtag_info;
265
266 if (arm966e_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm966e) != ERROR_OK)
267 {
268 command_print(cmd_ctx, "current target isn't an ARM966e target");
269 return ERROR_OK;
270 }
271
272 jtag_info = &arm7_9->jtag_info;
273
274 if (target->state != TARGET_HALTED)
275 {
276 command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
277 return ERROR_OK;
278 }
279
280 /* one or more argument, access a single register (write if second argument is given */
281 if (argc >= 1)
282 {
283 int address = strtoul(args[0], NULL, 0);
284
285 if (argc == 1)
286 {
287 u32 value;
288 if ((retval = arm966e_read_cp15(target, address, &value)) != ERROR_OK)
289 {
290 command_print(cmd_ctx, "couldn't access reg %i", address);
291 return ERROR_OK;
292 }
293 if ((retval = jtag_execute_queue()) != ERROR_OK)
294 {
295 return retval;
296 }
297
298 command_print(cmd_ctx, "%i: %8.8x", address, value);
299 }
300 else if (argc == 2)
301 {
302 u32 value = strtoul(args[1], NULL, 0);
303 if ((retval = arm966e_write_cp15(target, address, value)) != ERROR_OK)
304 {
305 command_print(cmd_ctx, "couldn't access reg %i", address);
306 return ERROR_OK;
307 }
308 command_print(cmd_ctx, "%i: %8.8x", address, value);
309 }
310 }
311
312 return ERROR_OK;
313 }
314
315 int arm966e_register_commands(struct command_context_s *cmd_ctx)
316 {
317 int retval;
318 command_t *arm966e_cmd;
319
320 retval = arm9tdmi_register_commands(cmd_ctx);
321 arm966e_cmd = register_command(cmd_ctx, NULL, "arm966e", NULL, COMMAND_ANY, "arm966e specific commands");
322 register_command(cmd_ctx, arm966e_cmd, "cp15", arm966e_handle_cp15_command, COMMAND_EXEC, "display/modify cp15 register <num> [value]");
323
324 return retval;
325 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)