ARM: rename some generic routines
[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 #include "arm_opcodes.h"
30
31
32 #if 0
33 #define _DEBUG_INSTRUCTION_EXECUTION_
34 #endif
35
36 int arm966e_init_arch_info(struct target *target, struct arm966e_common *arm966e, struct jtag_tap *tap)
37 {
38 struct arm7_9_common *arm7_9 = &arm966e->arm7_9_common;
39
40 /* initialize arm7/arm9 specific info (including armv4_5) */
41 arm9tdmi_init_arch_info(target, arm7_9, tap);
42
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 *target, Jim_Interp *interp)
55 {
56 struct arm966e_common *arm966e = calloc(1,sizeof(struct arm966e_common));
57
58 return arm966e_init_arch_info(target, arm966e, target->tap);
59 }
60
61 static int arm966e_verify_pointer(struct command_context *cmd_ctx,
62 struct arm966e_common *arm966e)
63 {
64 if (arm966e->common_magic != ARM966E_COMMON_MAGIC) {
65 command_print(cmd_ctx, "target is not an ARM966");
66 return ERROR_TARGET_INVALID;
67 }
68 return ERROR_OK;
69 }
70
71 static int arm966e_read_cp15(struct target *target, int reg_addr, uint32_t *value)
72 {
73 int retval = ERROR_OK;
74 struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
75 struct arm_jtag *jtag_info = &arm7_9->jtag_info;
76 struct scan_field fields[3];
77 uint8_t reg_addr_buf = reg_addr & 0x3f;
78 uint8_t nr_w_buf = 0;
79
80 jtag_set_end_state(TAP_IDLE);
81 if ((retval = arm_jtag_scann(jtag_info, 0xf)) != ERROR_OK)
82 {
83 return retval;
84 }
85 arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
86
87 fields[0].tap = jtag_info->tap;
88 fields[0].num_bits = 32;
89 fields[0].out_value = NULL;
90 fields[0].in_value = NULL;
91
92 fields[1].tap = jtag_info->tap;
93 fields[1].num_bits = 6;
94 fields[1].out_value = &reg_addr_buf;
95 fields[1].in_value = NULL;
96
97 fields[2].tap = jtag_info->tap;
98 fields[2].num_bits = 1;
99 fields[2].out_value = &nr_w_buf;
100 fields[2].in_value = NULL;
101
102 jtag_add_dr_scan(3, fields, jtag_get_end_state());
103
104 fields[1].in_value = (uint8_t *)value;
105
106 jtag_add_dr_scan(3, fields, jtag_get_end_state());
107
108 jtag_add_callback(arm_le_to_h_u32, (jtag_callback_data_t)value);
109
110
111 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
112 if ((retval = jtag_execute_queue()) != ERROR_OK)
113 {
114 return retval;
115 }
116 LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, *value);
117 #endif
118
119 return ERROR_OK;
120 }
121
122 // EXPORTED to str9x (flash)
123 int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value)
124 {
125 int retval = ERROR_OK;
126 struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
127 struct arm_jtag *jtag_info = &arm7_9->jtag_info;
128 struct scan_field fields[3];
129 uint8_t reg_addr_buf = reg_addr & 0x3f;
130 uint8_t nr_w_buf = 1;
131 uint8_t value_buf[4];
132
133 buf_set_u32(value_buf, 0, 32, value);
134
135 jtag_set_end_state(TAP_IDLE);
136 if ((retval = arm_jtag_scann(jtag_info, 0xf)) != ERROR_OK)
137 {
138 return retval;
139 }
140 arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
141
142 fields[0].tap = jtag_info->tap;
143 fields[0].num_bits = 32;
144 fields[0].out_value = value_buf;
145 fields[0].in_value = NULL;
146
147 fields[1].tap = jtag_info->tap;
148 fields[1].num_bits = 6;
149 fields[1].out_value = &reg_addr_buf;
150 fields[1].in_value = NULL;
151
152 fields[2].tap = jtag_info->tap;
153 fields[2].num_bits = 1;
154 fields[2].out_value = &nr_w_buf;
155 fields[2].in_value = NULL;
156
157 jtag_add_dr_scan(3, fields, jtag_get_end_state());
158
159 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
160 LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, value);
161 #endif
162
163 return ERROR_OK;
164 }
165
166 COMMAND_HANDLER(arm966e_handle_cp15_command)
167 {
168 int retval;
169 struct target *target = get_current_target(CMD_CTX);
170 struct arm966e_common *arm966e = target_to_arm966(target);
171
172 retval = arm966e_verify_pointer(CMD_CTX, arm966e);
173 if (retval != ERROR_OK)
174 return retval;
175
176 if (target->state != TARGET_HALTED)
177 {
178 command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME);
179 return ERROR_OK;
180 }
181
182 /* one or more argument, access a single register (write if second argument is given */
183 if (CMD_ARGC >= 1)
184 {
185 uint32_t address;
186 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
187
188 if (CMD_ARGC == 1)
189 {
190 uint32_t value;
191 if ((retval = arm966e_read_cp15(target, address, &value)) != ERROR_OK)
192 {
193 command_print(CMD_CTX,
194 "couldn't access reg %" PRIi32,
195 address);
196 return ERROR_OK;
197 }
198 if ((retval = jtag_execute_queue()) != ERROR_OK)
199 {
200 return retval;
201 }
202
203 command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32,
204 address, value);
205 }
206 else if (CMD_ARGC == 2)
207 {
208 uint32_t value;
209 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
210 if ((retval = arm966e_write_cp15(target, address, value)) != ERROR_OK)
211 {
212 command_print(CMD_CTX,
213 "couldn't access reg %" PRIi32,
214 address);
215 return ERROR_OK;
216 }
217 command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32,
218 address, value);
219 }
220 }
221
222 return ERROR_OK;
223 }
224
225 static const struct command_registration arm966e_exec_command_handlers[] = {
226 {
227 .name = "cp15",
228 .handler = arm966e_handle_cp15_command,
229 .mode = COMMAND_EXEC,
230 .usage = "<opcode> [value]",
231 .help = "display/modify cp15 register",
232 },
233 COMMAND_REGISTRATION_DONE
234 };
235
236 const struct command_registration arm966e_command_handlers[] = {
237 {
238 .chain = arm9tdmi_command_handlers,
239 },
240 {
241 .name = "arm966e",
242 .mode = COMMAND_ANY,
243 .help = "arm966e command group",
244 .chain = arm966e_exec_command_handlers,
245 },
246 COMMAND_REGISTRATION_DONE
247 };
248
249 /** Holds methods for ARM966 targets. */
250 struct target_type arm966e_target =
251 {
252 .name = "arm966e",
253
254 .poll = arm7_9_poll,
255 .arch_state = arm_arch_state,
256
257 .target_request_data = arm7_9_target_request_data,
258
259 .halt = arm7_9_halt,
260 .resume = arm7_9_resume,
261 .step = arm7_9_step,
262
263 .assert_reset = arm7_9_assert_reset,
264 .deassert_reset = arm7_9_deassert_reset,
265 .soft_reset_halt = arm7_9_soft_reset_halt,
266
267 .get_gdb_reg_list = arm_get_gdb_reg_list,
268
269 .read_memory = arm7_9_read_memory,
270 .write_memory = arm7_9_write_memory,
271 .bulk_write_memory = arm7_9_bulk_write_memory,
272
273 .checksum_memory = arm_checksum_memory,
274 .blank_check_memory = arm_blank_check_memory,
275
276 .run_algorithm = armv4_5_run_algorithm,
277
278 .add_breakpoint = arm7_9_add_breakpoint,
279 .remove_breakpoint = arm7_9_remove_breakpoint,
280 .add_watchpoint = arm7_9_add_watchpoint,
281 .remove_watchpoint = arm7_9_remove_watchpoint,
282
283 .commands = arm966e_command_handlers,
284 .target_create = arm966e_target_create,
285 .init_target = arm9tdmi_init_target,
286 .examine = arm7_9_examine,
287 };

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)