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

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)