1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
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. *
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. *
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 ***************************************************************************/
27 #include "time_support.h"
33 #define _DEBUG_INSTRUCTION_EXECUTION_
37 int arm920t_register_commands(struct command_context_s *cmd_ctx);
39 int arm920t_handle_cp15_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
40 int arm920t_handle_cp15i_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
41 int arm920t_handle_virt2phys_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
42 int arm920t_handle_cache_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
43 int arm920t_handle_md_phys_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
44 int arm920t_handle_mw_phys_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
46 int arm920t_handle_read_cache_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
47 int arm920t_handle_read_mmu_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
49 /* forward declarations */
50 int arm920t_target_create(struct target_s *target, Jim_Interp *interp);
51 int arm920t_init_target(struct command_context_s *cmd_ctx, struct target_s *target);
52 int arm920t_quit(void);
53 int arm920t_arch_state(struct target_s *target);
54 int arm920t_read_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
55 int arm920t_write_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
56 int arm920t_soft_reset_halt(struct target_s *target);
58 #define ARM920T_CP15_PHYS_ADDR(x, y, z) ((x << 5) | (y << 1) << (z))
60 target_type_t arm920t_target =
65 .arch_state = arm920t_arch_state,
67 .target_request_data = arm7_9_target_request_data,
70 .resume = arm7_9_resume,
73 .assert_reset = arm7_9_assert_reset,
74 .deassert_reset = arm7_9_deassert_reset,
75 .soft_reset_halt = arm920t_soft_reset_halt,
77 .get_gdb_reg_list = armv4_5_get_gdb_reg_list,
79 .read_memory = arm920t_read_memory,
80 .write_memory = arm920t_write_memory,
81 .bulk_write_memory = arm7_9_bulk_write_memory,
82 .checksum_memory = arm7_9_checksum_memory,
83 .blank_check_memory = arm7_9_blank_check_memory,
85 .run_algorithm = armv4_5_run_algorithm,
87 .add_breakpoint = arm7_9_add_breakpoint,
88 .remove_breakpoint = arm7_9_remove_breakpoint,
89 .add_watchpoint = arm7_9_add_watchpoint,
90 .remove_watchpoint = arm7_9_remove_watchpoint,
92 .register_commands = arm920t_register_commands,
93 .target_create = arm920t_target_create,
94 .init_target = arm920t_init_target,
95 .examine = arm9tdmi_examine,
99 int arm920t_read_cp15_physical(target_t *target, int reg_addr, u32 *value)
101 armv4_5_common_t *armv4_5 = target->arch_info;
102 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
103 arm_jtag_t *jtag_info = &arm7_9->jtag_info;
104 scan_field_t fields[4];
105 u8 access_type_buf = 1;
106 u8 reg_addr_buf = reg_addr & 0x3f;
109 jtag_add_end_state(TAP_RTI);
110 arm_jtag_scann(jtag_info, 0xf);
111 arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
113 fields[0].device = jtag_info->chain_pos;
114 fields[0].num_bits = 1;
115 fields[0].out_value = &access_type_buf;
116 fields[0].out_mask = NULL;
117 fields[0].in_value = NULL;
118 fields[0].in_check_value = NULL;
119 fields[0].in_check_mask = NULL;
120 fields[0].in_handler = NULL;
121 fields[0].in_handler_priv = NULL;
123 fields[1].device = jtag_info->chain_pos;
124 fields[1].num_bits = 32;
125 fields[1].out_value = NULL;
126 fields[1].out_mask = NULL;
127 fields[1].in_value = NULL;
128 fields[1].in_check_value = NULL;
129 fields[1].in_check_mask = NULL;
130 fields[1].in_handler = NULL;
131 fields[1].in_handler_priv = NULL;
133 fields[2].device = jtag_info->chain_pos;
134 fields[2].num_bits = 6;
135 fields[2].out_value = ®_addr_buf;
136 fields[2].out_mask = NULL;
137 fields[2].in_value = NULL;
138 fields[2].in_check_value = NULL;
139 fields[2].in_check_mask = NULL;
140 fields[2].in_handler = NULL;
141 fields[2].in_handler_priv = NULL;
143 fields[3].device = jtag_info->chain_pos;
144 fields[3].num_bits = 1;
145 fields[3].out_value = &nr_w_buf;
146 fields[3].out_mask = NULL;
147 fields[3].in_value = NULL;
148 fields[3].in_check_value = NULL;
149 fields[3].in_check_mask = NULL;
150 fields[3].in_handler = NULL;
151 fields[3].in_handler_priv = NULL;
153 jtag_add_dr_scan(4, fields, -1);
155 fields[1].in_handler_priv = value;
156 fields[1].in_handler = arm_jtag_buf_to_u32;
158 jtag_add_dr_scan(4, fields, -1);
160 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
161 jtag_execute_queue();
162 LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, *value);
168 int arm920t_write_cp15_physical(target_t *target, int reg_addr, u32 value)
170 armv4_5_common_t *armv4_5 = target->arch_info;
171 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
172 arm_jtag_t *jtag_info = &arm7_9->jtag_info;
173 scan_field_t fields[4];
174 u8 access_type_buf = 1;
175 u8 reg_addr_buf = reg_addr & 0x3f;
179 buf_set_u32(value_buf, 0, 32, value);
181 jtag_add_end_state(TAP_RTI);
182 arm_jtag_scann(jtag_info, 0xf);
183 arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
185 fields[0].device = jtag_info->chain_pos;
186 fields[0].num_bits = 1;
187 fields[0].out_value = &access_type_buf;
188 fields[0].out_mask = NULL;
189 fields[0].in_value = NULL;
190 fields[0].in_check_value = NULL;
191 fields[0].in_check_mask = NULL;
192 fields[0].in_handler = NULL;
193 fields[0].in_handler_priv = NULL;
195 fields[1].device = jtag_info->chain_pos;
196 fields[1].num_bits = 32;
197 fields[1].out_value = value_buf;
198 fields[1].out_mask = NULL;
199 fields[1].in_value = NULL;
200 fields[1].in_check_value = NULL;
201 fields[1].in_check_mask = NULL;
202 fields[1].in_handler = NULL;
203 fields[1].in_handler_priv = NULL;
205 fields[2].device = jtag_info->chain_pos;
206 fields[2].num_bits = 6;
207 fields[2].out_value = ®_addr_buf;
208 fields[2].out_mask = NULL;
209 fields[2].in_value = NULL;
210 fields[2].in_check_value = NULL;
211 fields[2].in_check_mask = NULL;
212 fields[2].in_handler = NULL;
213 fields[2].in_handler_priv = NULL;
215 fields[3].device = jtag_info->chain_pos;
216 fields[3].num_bits = 1;
217 fields[3].out_value = &nr_w_buf;
218 fields[3].out_mask = NULL;
219 fields[3].in_value = NULL;
220 fields[3].in_check_value = NULL;
221 fields[3].in_check_mask = NULL;
222 fields[3].in_handler = NULL;
223 fields[3].in_handler_priv = NULL;
225 jtag_add_dr_scan(4, fields, -1);
227 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
228 LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, value);
234 int arm920t_execute_cp15(target_t *target, u32 cp15_opcode, u32 arm_opcode)
236 armv4_5_common_t *armv4_5 = target->arch_info;
237 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
238 arm_jtag_t *jtag_info = &arm7_9->jtag_info;
239 scan_field_t fields[4];
240 u8 access_type_buf = 0; /* interpreted access */
241 u8 reg_addr_buf = 0x0;
243 u8 cp15_opcode_buf[4];
245 jtag_add_end_state(TAP_RTI);
246 arm_jtag_scann(jtag_info, 0xf);
247 arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL);
249 buf_set_u32(cp15_opcode_buf, 0, 32, cp15_opcode);
251 fields[0].device = jtag_info->chain_pos;
252 fields[0].num_bits = 1;
253 fields[0].out_value = &access_type_buf;
254 fields[0].out_mask = NULL;
255 fields[0].in_value = NULL;
256 fields[0].in_check_value = NULL;
257 fields[0].in_check_mask = NULL;
258 fields[0].in_handler = NULL;
259 fields[0].in_handler_priv = NULL;
261 fields[1].device = jtag_info->chain_pos;
262 fields[1].num_bits = 32;
263 fields[1].out_value = cp15_opcode_buf;
264 fields[1].out_mask = NULL;
265 fields[1].in_value = NULL;
266 fields[1].in_check_value = NULL;
267 fields[1].in_check_mask = NULL;
268 fields[1].in_handler = NULL;
269 fields[1].in_handler_priv = NULL;
271 fields[2].device = jtag_info->chain_pos;
272 fields[2].num_bits = 6;
273 fields[2].out_value = ®_addr_buf;
274 fields[2].out_mask = NULL;
275 fields[2].in_value = NULL;
276 fields[2].in_check_value = NULL;
277 fields[2].in_check_mask = NULL;
278 fields[2].in_handler = NULL;
279 fields[2].in_handler_priv = NULL;
281 fields[3].device = jtag_info->chain_pos;
282 fields[3].num_bits = 1;
283 fields[3].out_value = &nr_w_buf;
284 fields[3].out_mask = NULL;
285 fields[3].in_value = NULL;
286 fields[3].in_check_value = NULL;
287 fields[3].in_check_mask = NULL;
288 fields[3].in_handler = NULL;
289 fields[3].in_handler_priv = NULL;
291 jtag_add_dr_scan(4, fields, -1);
293 arm9tdmi_clock_out(jtag_info, arm_opcode, 0, NULL, 0);
294 arm9tdmi_clock_out(jtag_info, ARMV4_5_NOP, 0, NULL, 1);
295 arm7_9_execute_sys_speed(target);
297 if (jtag_execute_queue() != ERROR_OK)
299 LOG_ERROR("failed executing JTAG queue, exiting");
306 int arm920t_read_cp15_interpreted(target_t *target, u32 cp15_opcode, u32 address, u32 *value)
308 armv4_5_common_t *armv4_5 = target->arch_info;
313 /* load address into R1 */
315 arm9tdmi_write_core_regs(target, 0x2, regs);
317 /* read-modify-write CP15 test state register
318 * to enable interpreted access mode */
319 arm920t_read_cp15_physical(target, 0x1e, &cp15c15);
320 jtag_execute_queue();
321 cp15c15 |= 1; /* set interpret mode */
322 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
324 /* execute CP15 instruction and ARM load (reading from coprocessor) */
325 arm920t_execute_cp15(target, cp15_opcode, ARMV4_5_LDR(0, 1));
327 /* disable interpreted access mode */
328 cp15c15 &= ~1U; /* clear interpret mode */
329 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
331 /* retrieve value from R0 */
333 arm9tdmi_read_core_regs(target, 0x1, regs_p);
334 jtag_execute_queue();
336 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
337 LOG_DEBUG("cp15_opcode: %8.8x, address: %8.8x, value: %8.8x", cp15_opcode, address, *value);
340 if (armv4_5_mode_to_number(armv4_5->core_mode)==-1)
343 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = 1;
344 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = 1;
349 int arm920t_write_cp15_interpreted(target_t *target, u32 cp15_opcode, u32 value, u32 address)
352 armv4_5_common_t *armv4_5 = target->arch_info;
355 /* load value, address into R0, R1 */
358 arm9tdmi_write_core_regs(target, 0x3, regs);
360 /* read-modify-write CP15 test state register
361 * to enable interpreted access mode */
362 arm920t_read_cp15_physical(target, 0x1e, &cp15c15);
363 jtag_execute_queue();
364 cp15c15 |= 1; /* set interpret mode */
365 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
367 /* execute CP15 instruction and ARM store (writing to coprocessor) */
368 arm920t_execute_cp15(target, cp15_opcode, ARMV4_5_STR(0, 1));
370 /* disable interpreted access mode */
371 cp15c15 &= ~1U; /* set interpret mode */
372 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
374 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
375 LOG_DEBUG("cp15_opcode: %8.8x, value: %8.8x, address: %8.8x", cp15_opcode, value, address);
378 if (armv4_5_mode_to_number(armv4_5->core_mode)==-1)
381 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = 1;
382 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = 1;
387 u32 arm920t_get_ttb(target_t *target)
392 if ((retval = arm920t_read_cp15_interpreted(target, 0xeebf0f51, 0x0, &ttb)) != ERROR_OK)
398 void arm920t_disable_mmu_caches(target_t *target, int mmu, int d_u_cache, int i_cache)
402 /* read cp15 control register */
403 arm920t_read_cp15_physical(target, 0x2, &cp15_control);
404 jtag_execute_queue();
407 cp15_control &= ~0x1U;
410 cp15_control &= ~0x4U;
413 cp15_control &= ~0x1000U;
415 arm920t_write_cp15_physical(target, 0x2, cp15_control);
418 void arm920t_enable_mmu_caches(target_t *target, int mmu, int d_u_cache, int i_cache)
422 /* read cp15 control register */
423 arm920t_read_cp15_physical(target, 0x2, &cp15_control);
424 jtag_execute_queue();
427 cp15_control |= 0x1U;
430 cp15_control |= 0x4U;
433 cp15_control |= 0x1000U;
435 arm920t_write_cp15_physical(target, 0x2, cp15_control);
438 void arm920t_post_debug_entry(target_t *target)
441 armv4_5_common_t *armv4_5 = target->arch_info;
442 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
443 arm9tdmi_common_t *arm9tdmi = arm7_9->arch_info;
444 arm920t_common_t *arm920t = arm9tdmi->arch_info;
446 /* examine cp15 control reg */
447 arm920t_read_cp15_physical(target, 0x2, &arm920t->cp15_control_reg);
448 jtag_execute_queue();
449 LOG_DEBUG("cp15_control_reg: %8.8x", arm920t->cp15_control_reg);
451 if (arm920t->armv4_5_mmu.armv4_5_cache.ctype == -1)
454 /* identify caches */
455 arm920t_read_cp15_physical(target, 0x1, &cache_type_reg);
456 jtag_execute_queue();
457 armv4_5_identify_cache(cache_type_reg, &arm920t->armv4_5_mmu.armv4_5_cache);
460 arm920t->armv4_5_mmu.mmu_enabled = (arm920t->cp15_control_reg & 0x1U) ? 1 : 0;
461 arm920t->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = (arm920t->cp15_control_reg & 0x4U) ? 1 : 0;
462 arm920t->armv4_5_mmu.armv4_5_cache.i_cache_enabled = (arm920t->cp15_control_reg & 0x1000U) ? 1 : 0;
464 /* save i/d fault status and address register */
465 arm920t_read_cp15_interpreted(target, 0xee150f10, 0x0, &arm920t->d_fsr);
466 arm920t_read_cp15_interpreted(target, 0xee150f30, 0x0, &arm920t->i_fsr);
467 arm920t_read_cp15_interpreted(target, 0xee160f10, 0x0, &arm920t->d_far);
468 arm920t_read_cp15_interpreted(target, 0xee160f30, 0x0, &arm920t->i_far);
470 LOG_DEBUG("D FSR: 0x%8.8x, D FAR: 0x%8.8x, I FSR: 0x%8.8x, I FAR: 0x%8.8x",
471 arm920t->d_fsr, arm920t->d_far, arm920t->i_fsr, arm920t->i_far);
473 if (arm920t->preserve_cache)
475 /* read-modify-write CP15 test state register
476 * to disable I/D-cache linefills */
477 arm920t_read_cp15_physical(target, 0x1e, &cp15c15);
478 jtag_execute_queue();
480 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
484 void arm920t_pre_restore_context(target_t *target)
487 armv4_5_common_t *armv4_5 = target->arch_info;
488 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
489 arm9tdmi_common_t *arm9tdmi = arm7_9->arch_info;
490 arm920t_common_t *arm920t = arm9tdmi->arch_info;
492 /* restore i/d fault status and address register */
493 arm920t_write_cp15_interpreted(target, 0xee050f10, arm920t->d_fsr, 0x0);
494 arm920t_write_cp15_interpreted(target, 0xee050f30, arm920t->i_fsr, 0x0);
495 arm920t_write_cp15_interpreted(target, 0xee060f10, arm920t->d_far, 0x0);
496 arm920t_write_cp15_interpreted(target, 0xee060f30, arm920t->i_far, 0x0);
498 /* read-modify-write CP15 test state register
499 * to reenable I/D-cache linefills */
500 if (arm920t->preserve_cache)
502 arm920t_read_cp15_physical(target, 0x1e, &cp15c15);
503 jtag_execute_queue();
505 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
509 int arm920t_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, arm920t_common_t **arm920t_p)
511 armv4_5_common_t *armv4_5 = target->arch_info;
512 arm7_9_common_t *arm7_9;
513 arm9tdmi_common_t *arm9tdmi;
514 arm920t_common_t *arm920t;
516 if (armv4_5->common_magic != ARMV4_5_COMMON_MAGIC)
521 arm7_9 = armv4_5->arch_info;
522 if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC)
527 arm9tdmi = arm7_9->arch_info;
528 if (arm9tdmi->common_magic != ARM9TDMI_COMMON_MAGIC)
533 arm920t = arm9tdmi->arch_info;
534 if (arm920t->common_magic != ARM920T_COMMON_MAGIC)
539 *armv4_5_p = armv4_5;
541 *arm9tdmi_p = arm9tdmi;
542 *arm920t_p = arm920t;
547 int arm920t_arch_state(struct target_s *target)
549 armv4_5_common_t *armv4_5 = target->arch_info;
550 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
551 arm9tdmi_common_t *arm9tdmi = arm7_9->arch_info;
552 arm920t_common_t *arm920t = arm9tdmi->arch_info;
556 "disabled", "enabled"
559 if (armv4_5->common_magic != ARMV4_5_COMMON_MAGIC)
561 LOG_ERROR("BUG: called for a non-ARMv4/5 target");
565 LOG_USER( "target halted in %s state due to %s, current mode: %s\n"
566 "cpsr: 0x%8.8x pc: 0x%8.8x\n"
567 "MMU: %s, D-Cache: %s, I-Cache: %s",
568 armv4_5_state_strings[armv4_5->core_state],
569 Jim_Nvp_value2name_simple(nvp_target_debug_reason, target->debug_reason)->name,
570 armv4_5_mode_strings[armv4_5_mode_to_number(armv4_5->core_mode)],
571 buf_get_u32(armv4_5->core_cache->reg_list[ARMV4_5_CPSR].value, 0, 32),
572 buf_get_u32(armv4_5->core_cache->reg_list[15].value, 0, 32),
573 state[arm920t->armv4_5_mmu.mmu_enabled],
574 state[arm920t->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled],
575 state[arm920t->armv4_5_mmu.armv4_5_cache.i_cache_enabled]);
580 int arm920t_read_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
584 retval = arm7_9_read_memory(target, address, size, count, buffer);
589 int arm920t_write_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
592 armv4_5_common_t *armv4_5 = target->arch_info;
593 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
594 arm9tdmi_common_t *arm9tdmi = arm7_9->arch_info;
595 arm920t_common_t *arm920t = arm9tdmi->arch_info;
597 if ((retval = arm7_9_write_memory(target, address, size, count, buffer)) != ERROR_OK)
600 if (((size == 4) || (size == 2)) && (count == 1))
602 if (arm920t->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled)
604 LOG_DEBUG("D-Cache enabled, writing through to main memory");
608 pa = armv4_5_mmu_translate_va(target, &arm920t->armv4_5_mmu, address, &type, &cb, &domain, &ap);
611 /* cacheable & bufferable means write-back region */
613 armv4_5_mmu_write_physical(target, &arm920t->armv4_5_mmu, pa, size, count, buffer);
616 if (arm920t->armv4_5_mmu.armv4_5_cache.i_cache_enabled)
618 LOG_DEBUG("I-Cache enabled, invalidating affected I-Cache line");
619 arm920t_write_cp15_interpreted(target, 0xee070f35, 0x0, address);
626 int arm920t_soft_reset_halt(struct target_s *target)
628 armv4_5_common_t *armv4_5 = target->arch_info;
629 arm7_9_common_t *arm7_9 = armv4_5->arch_info;
630 arm9tdmi_common_t *arm9tdmi = arm7_9->arch_info;
631 arm920t_common_t *arm920t = arm9tdmi->arch_info;
632 reg_t *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
636 long long then=timeval_ms();
638 while (!(timeout=((timeval_ms()-then)>1000)))
640 if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1) == 0)
642 embeddedice_read_reg(dbg_stat);
643 jtag_execute_queue();
650 /* do not eat all CPU, time out after 1 se*/
659 LOG_ERROR("Failed to halt CPU after 1 sec");
660 return ERROR_TARGET_TIMEOUT;
663 target->state = TARGET_HALTED;
665 /* SVC, ARM state, IRQ and FIQ disabled */
666 buf_set_u32(armv4_5->core_cache->reg_list[ARMV4_5_CPSR].value, 0, 8, 0xd3);
667 armv4_5->core_cache->reg_list[ARMV4_5_CPSR].dirty = 1;
668 armv4_5->core_cache->reg_list[ARMV4_5_CPSR].valid = 1;
670 /* start fetching from 0x0 */
671 buf_set_u32(armv4_5->core_cache->reg_list[15].value, 0, 32, 0x0);
672 armv4_5->core_cache->reg_list[15].dirty = 1;
673 armv4_5->core_cache->reg_list[15].valid = 1;
675 armv4_5->core_mode = ARMV4_5_MODE_SVC;
676 armv4_5->core_state = ARMV4_5_STATE_ARM;
678 arm920t_disable_mmu_caches(target, 1, 1, 1);
679 arm920t->armv4_5_mmu.mmu_enabled = 0;
680 arm920t->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = 0;
681 arm920t->armv4_5_mmu.armv4_5_cache.i_cache_enabled = 0;
683 target_call_event_callbacks(target, TARGET_EVENT_HALTED);
688 int arm920t_init_target(struct command_context_s *cmd_ctx, struct target_s *target)
690 arm9tdmi_init_target(cmd_ctx, target);
696 int arm920t_quit(void)
702 int arm920t_init_arch_info(target_t *target, arm920t_common_t *arm920t, int chain_pos, const char *variant)
704 arm9tdmi_common_t *arm9tdmi = &arm920t->arm9tdmi_common;
705 arm7_9_common_t *arm7_9 = &arm9tdmi->arm7_9_common;
707 /* initialize arm9tdmi specific info (including arm7_9 and armv4_5)
709 arm9tdmi_init_arch_info(target, arm9tdmi, chain_pos, variant);
711 arm9tdmi->arch_info = arm920t;
712 arm920t->common_magic = ARM920T_COMMON_MAGIC;
714 arm7_9->post_debug_entry = arm920t_post_debug_entry;
715 arm7_9->pre_restore_context = arm920t_pre_restore_context;
717 arm920t->armv4_5_mmu.armv4_5_cache.ctype = -1;
718 arm920t->armv4_5_mmu.get_ttb = arm920t_get_ttb;
719 arm920t->armv4_5_mmu.read_memory = arm7_9_read_memory;
720 arm920t->armv4_5_mmu.write_memory = arm7_9_write_memory;
721 arm920t->armv4_5_mmu.disable_mmu_caches = arm920t_disable_mmu_caches;
722 arm920t->armv4_5_mmu.enable_mmu_caches = arm920t_enable_mmu_caches;
723 arm920t->armv4_5_mmu.has_tiny_pages = 1;
724 arm920t->armv4_5_mmu.mmu_enabled = 0;
726 /* disabling linefills leads to lockups, so keep them enabled for now
727 * this doesn't affect correctness, but might affect timing issues, if
728 * important data is evicted from the cache during the debug session
730 arm920t->preserve_cache = 0;
732 /* override hw single-step capability from ARM9TDMI */
733 arm7_9->has_single_step = 1;
738 int arm920t_target_create(struct target_s *target, Jim_Interp *interp)
740 arm920t_common_t *arm920t = calloc(1,sizeof(arm920t_common_t));
742 arm920t_init_arch_info(target, arm920t, target->chain_position, target->variant);
747 int arm920t_register_commands(struct command_context_s *cmd_ctx)
750 command_t *arm920t_cmd;
753 retval = arm9tdmi_register_commands(cmd_ctx);
755 arm920t_cmd = register_command(cmd_ctx, NULL, "arm920t", NULL, COMMAND_ANY, "arm920t specific commands");
757 register_command(cmd_ctx, arm920t_cmd, "cp15", arm920t_handle_cp15_command, COMMAND_EXEC, "display/modify cp15 register <num> [value]");
758 register_command(cmd_ctx, arm920t_cmd, "cp15i", arm920t_handle_cp15i_command, COMMAND_EXEC, "display/modify cp15 (interpreted access) <opcode> [value] [address]");
759 register_command(cmd_ctx, arm920t_cmd, "cache_info", arm920t_handle_cache_info_command, COMMAND_EXEC, "display information about target caches");
760 register_command(cmd_ctx, arm920t_cmd, "virt2phys", arm920t_handle_virt2phys_command, COMMAND_EXEC, "translate va to pa <va>");
762 register_command(cmd_ctx, arm920t_cmd, "mdw_phys", arm920t_handle_md_phys_command, COMMAND_EXEC, "display memory words <physical addr> [count]");
763 register_command(cmd_ctx, arm920t_cmd, "mdh_phys", arm920t_handle_md_phys_command, COMMAND_EXEC, "display memory half-words <physical addr> [count]");
764 register_command(cmd_ctx, arm920t_cmd, "mdb_phys", arm920t_handle_md_phys_command, COMMAND_EXEC, "display memory bytes <physical addr> [count]");
766 register_command(cmd_ctx, arm920t_cmd, "mww_phys", arm920t_handle_mw_phys_command, COMMAND_EXEC, "write memory word <physical addr> <value>");
767 register_command(cmd_ctx, arm920t_cmd, "mwh_phys", arm920t_handle_mw_phys_command, COMMAND_EXEC, "write memory half-word <physical addr> <value>");
768 register_command(cmd_ctx, arm920t_cmd, "mwb_phys", arm920t_handle_mw_phys_command, COMMAND_EXEC, "write memory byte <physical addr> <value>");
770 register_command(cmd_ctx, arm920t_cmd, "read_cache", arm920t_handle_read_cache_command, COMMAND_EXEC, "display I/D cache content");
771 register_command(cmd_ctx, arm920t_cmd, "read_mmu", arm920t_handle_read_mmu_command, COMMAND_EXEC, "display I/D mmu content");
776 int arm920t_handle_read_cache_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
778 target_t *target = get_current_target(cmd_ctx);
779 armv4_5_common_t *armv4_5;
780 arm7_9_common_t *arm7_9;
781 arm9tdmi_common_t *arm9tdmi;
782 arm920t_common_t *arm920t;
783 arm_jtag_t *jtag_info;
785 u32 cp15_ctrl, cp15_ctrl_saved;
788 u32 C15_C_D_Ind, C15_C_I_Ind;
791 arm920t_cache_line_t d_cache[8][64], i_cache[8][64];
796 command_print(cmd_ctx, "usage: arm920t read_cache <filename>");
800 if ((output = fopen(args[0], "w")) == NULL)
802 LOG_DEBUG("error opening cache content file");
806 for (i = 0; i < 16; i++)
807 regs_p[i] = ®s[i];
809 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
811 command_print(cmd_ctx, "current target isn't an ARM920t target");
815 jtag_info = &arm7_9->jtag_info;
817 /* disable MMU and Caches */
818 arm920t_read_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0x1, 0), &cp15_ctrl);
819 jtag_execute_queue();
820 cp15_ctrl_saved = cp15_ctrl;
821 cp15_ctrl &= ~(ARMV4_5_MMU_ENABLED | ARMV4_5_D_U_CACHE_ENABLED | ARMV4_5_I_CACHE_ENABLED);
822 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0x1, 0), cp15_ctrl);
824 /* read CP15 test state register */
825 arm920t_read_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), &cp15c15);
826 jtag_execute_queue();
828 /* read DCache content */
829 fprintf(output, "DCache:\n");
831 /* go through segments 0 to nsets (8 on ARM920T, 4 on ARM922T) */
832 for (segment = 0; segment < arm920t->armv4_5_mmu.armv4_5_cache.d_u_size.nsets; segment++)
834 fprintf(output, "\nsegment: %i\n----------", segment);
836 /* Ra: r0 = SBZ(31:8):segment(7:5):SBZ(4:0) */
837 regs[0] = 0x0 | (segment << 5);
838 arm9tdmi_write_core_regs(target, 0x1, regs);
840 /* set interpret mode */
842 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
844 /* D CAM Read, loads current victim into C15.C.D.Ind */
845 arm920t_execute_cp15(target, ARMV4_5_MCR(15,2,0,15,6,2), ARMV4_5_LDR(1, 0));
847 /* read current victim */
848 arm920t_read_cp15_physical(target, 0x3d, &C15_C_D_Ind);
850 /* clear interpret mode */
852 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
854 for (index = 0; index < 64; index++)
856 /* Ra: r0 = index(31:26):SBZ(25:8):segment(7:5):SBZ(4:0) */
857 regs[0] = 0x0 | (segment << 5) | (index << 26);
858 arm9tdmi_write_core_regs(target, 0x1, regs);
860 /* set interpret mode */
862 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
864 /* Write DCache victim */
865 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,9,1,0), ARMV4_5_LDR(1, 0));
868 arm920t_execute_cp15(target, ARMV4_5_MCR(15,2,0,15,10,2), ARMV4_5_LDMIA(0, 0x1fe, 0, 0));
871 arm920t_execute_cp15(target, ARMV4_5_MCR(15,2,0,15,6,2), ARMV4_5_LDR(9, 0));
873 /* clear interpret mode */
875 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
877 /* read D RAM and CAM content */
878 arm9tdmi_read_core_regs(target, 0x3fe, regs_p);
879 jtag_execute_queue();
881 d_cache[segment][index].cam = regs[9];
884 regs[9] &= 0xfffffffe;
885 fprintf(output, "\nsegment: %i, index: %i, CAM: 0x%8.8x, content (%s):\n", segment, index, regs[9], (regs[9] & 0x10) ? "valid" : "invalid");
887 for (i = 1; i < 9; i++)
889 d_cache[segment][index].data[i] = regs[i];
890 fprintf(output, "%i: 0x%8.8x\n", i-1, regs[i]);
895 /* Ra: r0 = index(31:26):SBZ(25:8):segment(7:5):SBZ(4:0) */
896 regs[0] = 0x0 | (segment << 5) | (C15_C_D_Ind << 26);
897 arm9tdmi_write_core_regs(target, 0x1, regs);
899 /* set interpret mode */
901 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
903 /* Write DCache victim */
904 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,9,1,0), ARMV4_5_LDR(1, 0));
906 /* clear interpret mode */
908 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
911 /* read ICache content */
912 fprintf(output, "ICache:\n");
914 /* go through segments 0 to nsets (8 on ARM920T, 4 on ARM922T) */
915 for (segment = 0; segment < arm920t->armv4_5_mmu.armv4_5_cache.d_u_size.nsets; segment++)
917 fprintf(output, "segment: %i\n----------", segment);
919 /* Ra: r0 = SBZ(31:8):segment(7:5):SBZ(4:0) */
920 regs[0] = 0x0 | (segment << 5);
921 arm9tdmi_write_core_regs(target, 0x1, regs);
923 /* set interpret mode */
925 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
927 /* I CAM Read, loads current victim into C15.C.I.Ind */
928 arm920t_execute_cp15(target, ARMV4_5_MCR(15,2,0,15,5,2), ARMV4_5_LDR(1, 0));
930 /* read current victim */
931 arm920t_read_cp15_physical(target, 0x3b, &C15_C_I_Ind);
933 /* clear interpret mode */
935 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
937 for (index = 0; index < 64; index++)
939 /* Ra: r0 = index(31:26):SBZ(25:8):segment(7:5):SBZ(4:0) */
940 regs[0] = 0x0 | (segment << 5) | (index << 26);
941 arm9tdmi_write_core_regs(target, 0x1, regs);
943 /* set interpret mode */
945 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
947 /* Write ICache victim */
948 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,9,1,1), ARMV4_5_LDR(1, 0));
951 arm920t_execute_cp15(target, ARMV4_5_MCR(15,2,0,15,9,2), ARMV4_5_LDMIA(0, 0x1fe, 0, 0));
954 arm920t_execute_cp15(target, ARMV4_5_MCR(15,2,0,15,5,2), ARMV4_5_LDR(9, 0));
956 /* clear interpret mode */
958 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
960 /* read I RAM and CAM content */
961 arm9tdmi_read_core_regs(target, 0x3fe, regs_p);
962 jtag_execute_queue();
964 i_cache[segment][index].cam = regs[9];
967 regs[9] &= 0xfffffffe;
968 fprintf(output, "\nsegment: %i, index: %i, CAM: 0x%8.8x, content (%s):\n", segment, index, regs[9], (regs[9] & 0x10) ? "valid" : "invalid");
970 for (i = 1; i < 9; i++)
972 i_cache[segment][index].data[i] = regs[i];
973 fprintf(output, "%i: 0x%8.8x\n", i-1, regs[i]);
979 /* Ra: r0 = index(31:26):SBZ(25:8):segment(7:5):SBZ(4:0) */
980 regs[0] = 0x0 | (segment << 5) | (C15_C_D_Ind << 26);
981 arm9tdmi_write_core_regs(target, 0x1, regs);
983 /* set interpret mode */
985 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
987 /* Write ICache victim */
988 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,9,1,1), ARMV4_5_LDR(1, 0));
990 /* clear interpret mode */
992 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
995 /* restore CP15 MMU and Cache settings */
996 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0x1, 0), cp15_ctrl_saved);
998 command_print(cmd_ctx, "cache content successfully output to %s", args[0]);
1002 if (armv4_5_mode_to_number(armv4_5->core_mode)==-1)
1005 /* mark registers dirty. */
1006 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).valid;
1007 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).valid;
1008 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).valid;
1009 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).valid;
1010 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).valid;
1011 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).valid;
1012 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).valid;
1013 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).valid;
1014 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).valid;
1015 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).valid;
1020 int arm920t_handle_read_mmu_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1022 target_t *target = get_current_target(cmd_ctx);
1023 armv4_5_common_t *armv4_5;
1024 arm7_9_common_t *arm7_9;
1025 arm9tdmi_common_t *arm9tdmi;
1026 arm920t_common_t *arm920t;
1027 arm_jtag_t *jtag_info;
1029 u32 cp15_ctrl, cp15_ctrl_saved;
1034 u32 Dlockdown, Ilockdown;
1035 arm920t_tlb_entry_t d_tlb[64], i_tlb[64];
1040 command_print(cmd_ctx, "usage: arm920t read_mmu <filename>");
1044 if ((output = fopen(args[0], "w")) == NULL)
1046 LOG_DEBUG("error opening mmu content file");
1050 for (i = 0; i < 16; i++)
1051 regs_p[i] = ®s[i];
1053 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
1055 command_print(cmd_ctx, "current target isn't an ARM920t target");
1059 jtag_info = &arm7_9->jtag_info;
1061 /* disable MMU and Caches */
1062 arm920t_read_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0x1, 0), &cp15_ctrl);
1063 jtag_execute_queue();
1064 cp15_ctrl_saved = cp15_ctrl;
1065 cp15_ctrl &= ~(ARMV4_5_MMU_ENABLED | ARMV4_5_D_U_CACHE_ENABLED | ARMV4_5_I_CACHE_ENABLED);
1066 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0x1, 0), cp15_ctrl);
1068 /* read CP15 test state register */
1069 arm920t_read_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), &cp15c15);
1070 jtag_execute_queue();
1072 /* prepare reading D TLB content
1075 /* set interpret mode */
1077 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
1079 /* Read D TLB lockdown */
1080 arm920t_execute_cp15(target, ARMV4_5_MRC(15,0,0,10,0,0), ARMV4_5_LDR(1, 0));
1082 /* clear interpret mode */
1084 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
1086 /* read D TLB lockdown stored to r1 */
1087 arm9tdmi_read_core_regs(target, 0x2, regs_p);
1088 jtag_execute_queue();
1089 Dlockdown = regs[1];
1091 for (victim = 0; victim < 64; victim += 8)
1093 /* new lockdown value: base[31:26]:victim[25:20]:SBZ[19:1]:p[0]
1094 * base remains unchanged, victim goes through entries 0 to 63 */
1095 regs[1] = (Dlockdown & 0xfc000000) | (victim << 20);
1096 arm9tdmi_write_core_regs(target, 0x2, regs);
1098 /* set interpret mode */
1100 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
1102 /* Write D TLB lockdown */
1103 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,10,0,0), ARMV4_5_STR(1, 0));
1105 /* Read D TLB CAM */
1106 arm920t_execute_cp15(target, ARMV4_5_MCR(15,4,0,15,6,4), ARMV4_5_LDMIA(0, 0x3fc, 0, 0));
1108 /* clear interpret mode */
1110 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
1112 /* read D TLB CAM content stored to r2-r9 */
1113 arm9tdmi_read_core_regs(target, 0x3fc, regs_p);
1114 jtag_execute_queue();
1116 for (i = 0; i < 8; i++)
1117 d_tlb[victim + i].cam = regs[i + 2];
1120 for (victim = 0; victim < 64; victim++)
1122 /* new lockdown value: base[31:26]:victim[25:20]:SBZ[19:1]:p[0]
1123 * base remains unchanged, victim goes through entries 0 to 63 */
1124 regs[1] = (Dlockdown & 0xfc000000) | (victim << 20);
1125 arm9tdmi_write_core_regs(target, 0x2, regs);
1127 /* set interpret mode */
1129 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
1131 /* Write D TLB lockdown */
1132 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,10,0,0), ARMV4_5_STR(1, 0));
1134 /* Read D TLB RAM1 */
1135 arm920t_execute_cp15(target, ARMV4_5_MCR(15,4,0,15,10,4), ARMV4_5_LDR(2,0));
1137 /* Read D TLB RAM2 */
1138 arm920t_execute_cp15(target, ARMV4_5_MCR(15,4,0,15,2,5), ARMV4_5_LDR(3,0));
1140 /* clear interpret mode */
1142 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
1144 /* read D TLB RAM content stored to r2 and r3 */
1145 arm9tdmi_read_core_regs(target, 0xc, regs_p);
1146 jtag_execute_queue();
1148 d_tlb[victim].ram1 = regs[2];
1149 d_tlb[victim].ram2 = regs[3];
1152 /* restore D TLB lockdown */
1153 regs[1] = Dlockdown;
1154 arm9tdmi_write_core_regs(target, 0x2, regs);
1156 /* Write D TLB lockdown */
1157 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,10,0,0), ARMV4_5_STR(1, 0));
1159 /* prepare reading I TLB content
1162 /* set interpret mode */
1164 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
1166 /* Read I TLB lockdown */
1167 arm920t_execute_cp15(target, ARMV4_5_MRC(15,0,0,10,0,1), ARMV4_5_LDR(1, 0));
1169 /* clear interpret mode */
1171 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
1173 /* read I TLB lockdown stored to r1 */
1174 arm9tdmi_read_core_regs(target, 0x2, regs_p);
1175 jtag_execute_queue();
1176 Ilockdown = regs[1];
1178 for (victim = 0; victim < 64; victim += 8)
1180 /* new lockdown value: base[31:26]:victim[25:20]:SBZ[19:1]:p[0]
1181 * base remains unchanged, victim goes through entries 0 to 63 */
1182 regs[1] = (Ilockdown & 0xfc000000) | (victim << 20);
1183 arm9tdmi_write_core_regs(target, 0x2, regs);
1185 /* set interpret mode */
1187 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
1189 /* Write I TLB lockdown */
1190 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,10,0,1), ARMV4_5_STR(1, 0));
1192 /* Read I TLB CAM */
1193 arm920t_execute_cp15(target, ARMV4_5_MCR(15,4,0,15,5,4), ARMV4_5_LDMIA(0, 0x3fc, 0, 0));
1195 /* clear interpret mode */
1197 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
1199 /* read I TLB CAM content stored to r2-r9 */
1200 arm9tdmi_read_core_regs(target, 0x3fc, regs_p);
1201 jtag_execute_queue();
1203 for (i = 0; i < 8; i++)
1204 i_tlb[i + victim].cam = regs[i + 2];
1207 for (victim = 0; victim < 64; victim++)
1209 /* new lockdown value: base[31:26]:victim[25:20]:SBZ[19:1]:p[0]
1210 * base remains unchanged, victim goes through entries 0 to 63 */
1211 regs[1] = (Dlockdown & 0xfc000000) | (victim << 20);
1212 arm9tdmi_write_core_regs(target, 0x2, regs);
1214 /* set interpret mode */
1216 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0xf, 0), cp15c15);
1218 /* Write I TLB lockdown */
1219 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,10,0,1), ARMV4_5_STR(1, 0));
1221 /* Read I TLB RAM1 */
1222 arm920t_execute_cp15(target, ARMV4_5_MCR(15,4,0,15,9,4), ARMV4_5_LDR(2,0));
1224 /* Read I TLB RAM2 */
1225 arm920t_execute_cp15(target, ARMV4_5_MCR(15,4,0,15,1,5), ARMV4_5_LDR(3,0));
1227 /* clear interpret mode */
1229 arm920t_write_cp15_physical(target, 0x1e, cp15c15);
1231 /* read I TLB RAM content stored to r2 and r3 */
1232 arm9tdmi_read_core_regs(target, 0xc, regs_p);
1233 jtag_execute_queue();
1235 i_tlb[victim].ram1 = regs[2];
1236 i_tlb[victim].ram2 = regs[3];
1239 /* restore I TLB lockdown */
1240 regs[1] = Ilockdown;
1241 arm9tdmi_write_core_regs(target, 0x2, regs);
1243 /* Write I TLB lockdown */
1244 arm920t_execute_cp15(target, ARMV4_5_MCR(15,0,0,10,0,1), ARMV4_5_STR(1, 0));
1246 /* restore CP15 MMU and Cache settings */
1247 arm920t_write_cp15_physical(target, ARM920T_CP15_PHYS_ADDR(0, 0x1, 0), cp15_ctrl_saved);
1249 /* output data to file */
1250 fprintf(output, "D TLB content:\n");
1251 for (i = 0; i < 64; i++)
1253 fprintf(output, "%i: 0x%8.8x 0x%8.8x 0x%8.8x %s\n", i, d_tlb[i].cam, d_tlb[i].ram1, d_tlb[i].ram2, (d_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)");
1256 fprintf(output, "\n\nI TLB content:\n");
1257 for (i = 0; i < 64; i++)
1259 fprintf(output, "%i: 0x%8.8x 0x%8.8x 0x%8.8x %s\n", i, i_tlb[i].cam, i_tlb[i].ram1, i_tlb[i].ram2, (i_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)");
1262 command_print(cmd_ctx, "mmu content successfully output to %s", args[0]);
1266 if (armv4_5_mode_to_number(armv4_5->core_mode)==-1)
1269 /* mark registers dirty */
1270 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 0).valid;
1271 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 1).valid;
1272 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 2).valid;
1273 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 3).valid;
1274 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 4).valid;
1275 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 5).valid;
1276 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 6).valid;
1277 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 7).valid;
1278 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 8).valid;
1279 ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).dirty = ARMV4_5_CORE_REG_MODE(armv4_5->core_cache, armv4_5->core_mode, 9).valid;
1283 int arm920t_handle_cp15_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1286 target_t *target = get_current_target(cmd_ctx);
1287 armv4_5_common_t *armv4_5;
1288 arm7_9_common_t *arm7_9;
1289 arm9tdmi_common_t *arm9tdmi;
1290 arm920t_common_t *arm920t;
1291 arm_jtag_t *jtag_info;
1293 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
1295 command_print(cmd_ctx, "current target isn't an ARM920t target");
1299 jtag_info = &arm7_9->jtag_info;
1301 if (target->state != TARGET_HALTED)
1303 command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
1307 /* one or more argument, access a single register (write if second argument is given */
1310 int address = strtoul(args[0], NULL, 0);
1315 if ((retval = arm920t_read_cp15_physical(target, address, &value)) != ERROR_OK)
1317 command_print(cmd_ctx, "couldn't access reg %i", address);
1320 jtag_execute_queue();
1322 command_print(cmd_ctx, "%i: %8.8x", address, value);
1326 u32 value = strtoul(args[1], NULL, 0);
1327 if ((retval = arm920t_write_cp15_physical(target, address, value)) != ERROR_OK)
1329 command_print(cmd_ctx, "couldn't access reg %i", address);
1332 command_print(cmd_ctx, "%i: %8.8x", address, value);
1339 int arm920t_handle_cp15i_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1342 target_t *target = get_current_target(cmd_ctx);
1343 armv4_5_common_t *armv4_5;
1344 arm7_9_common_t *arm7_9;
1345 arm9tdmi_common_t *arm9tdmi;
1346 arm920t_common_t *arm920t;
1347 arm_jtag_t *jtag_info;
1349 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
1351 command_print(cmd_ctx, "current target isn't an ARM920t target");
1355 jtag_info = &arm7_9->jtag_info;
1357 if (target->state != TARGET_HALTED)
1359 command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
1363 /* one or more argument, access a single register (write if second argument is given */
1366 u32 opcode = strtoul(args[0], NULL, 0);
1371 if ((retval = arm920t_read_cp15_interpreted(target, opcode, 0x0, &value)) != ERROR_OK)
1373 command_print(cmd_ctx, "couldn't execute %8.8x", opcode);
1377 command_print(cmd_ctx, "%8.8x: %8.8x", opcode, value);
1381 u32 value = strtoul(args[1], NULL, 0);
1382 if ((retval = arm920t_write_cp15_interpreted(target, opcode, value, 0)) != ERROR_OK)
1384 command_print(cmd_ctx, "couldn't execute %8.8x", opcode);
1387 command_print(cmd_ctx, "%8.8x: %8.8x", opcode, value);
1391 u32 value = strtoul(args[1], NULL, 0);
1392 u32 address = strtoul(args[2], NULL, 0);
1393 if ((retval = arm920t_write_cp15_interpreted(target, opcode, value, address)) != ERROR_OK)
1395 command_print(cmd_ctx, "couldn't execute %8.8x", opcode);
1398 command_print(cmd_ctx, "%8.8x: %8.8x %8.8x", opcode, value, address);
1403 command_print(cmd_ctx, "usage: arm920t cp15i <opcode> [value] [address]");
1409 int arm920t_handle_cache_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1411 target_t *target = get_current_target(cmd_ctx);
1412 armv4_5_common_t *armv4_5;
1413 arm7_9_common_t *arm7_9;
1414 arm9tdmi_common_t *arm9tdmi;
1415 arm920t_common_t *arm920t;
1417 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
1419 command_print(cmd_ctx, "current target isn't an ARM920t target");
1423 return armv4_5_handle_cache_info_command(cmd_ctx, &arm920t->armv4_5_mmu.armv4_5_cache);
1426 int arm920t_handle_virt2phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc)
1428 target_t *target = get_current_target(cmd_ctx);
1429 armv4_5_common_t *armv4_5;
1430 arm7_9_common_t *arm7_9;
1431 arm9tdmi_common_t *arm9tdmi;
1432 arm920t_common_t *arm920t;
1433 arm_jtag_t *jtag_info;
1435 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
1437 command_print(cmd_ctx, "current target isn't an ARM920t target");
1441 jtag_info = &arm7_9->jtag_info;
1443 if (target->state != TARGET_HALTED)
1445 command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
1449 return armv4_5_mmu_handle_virt2phys_command(cmd_ctx, cmd, args, argc, target, &arm920t->armv4_5_mmu);
1452 int arm920t_handle_md_phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc)
1454 target_t *target = get_current_target(cmd_ctx);
1455 armv4_5_common_t *armv4_5;
1456 arm7_9_common_t *arm7_9;
1457 arm9tdmi_common_t *arm9tdmi;
1458 arm920t_common_t *arm920t;
1459 arm_jtag_t *jtag_info;
1461 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
1463 command_print(cmd_ctx, "current target isn't an ARM920t target");
1467 jtag_info = &arm7_9->jtag_info;
1469 if (target->state != TARGET_HALTED)
1471 command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
1475 return armv4_5_mmu_handle_md_phys_command(cmd_ctx, cmd, args, argc, target, &arm920t->armv4_5_mmu);
1478 int arm920t_handle_mw_phys_command(command_context_t *cmd_ctx, char *cmd, char **args, int argc)
1480 target_t *target = get_current_target(cmd_ctx);
1481 armv4_5_common_t *armv4_5;
1482 arm7_9_common_t *arm7_9;
1483 arm9tdmi_common_t *arm9tdmi;
1484 arm920t_common_t *arm920t;
1485 arm_jtag_t *jtag_info;
1487 if (arm920t_get_arch_pointers(target, &armv4_5, &arm7_9, &arm9tdmi, &arm920t) != ERROR_OK)
1489 command_print(cmd_ctx, "current target isn't an ARM920t target");
1493 jtag_info = &arm7_9->jtag_info;
1495 if (target->state != TARGET_HALTED)
1497 command_print(cmd_ctx, "target must be stopped for \"%s\" command", cmd);
1501 return armv4_5_mmu_handle_mw_phys_command(cmd_ctx, cmd, args, argc, target, &arm920t->armv4_5_mmu);