OpenOCD
arm926ejs.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2007 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2007,2008,2009 by Øyvind Harboe *
8  * oyvind.harboe@zylin.com *
9  ***************************************************************************/
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include "arm926ejs.h"
16 #include <helper/time_support.h>
17 #include <helper/string_choices.h>
18 #include "target_type.h"
19 #include "register.h"
20 #include "arm_opcodes.h"
21 
22 
23 /*
24  * The ARM926 is built around the ARM9EJ-S core, and most JTAG docs
25  * are in the ARM9EJ-S Technical Reference Manual (ARM DDI 0222B) not
26  * the ARM926 manual (ARM DDI 0198E). The scan chains are:
27  *
28  * 1 ... core debugging
29  * 2 ... EmbeddedICE
30  * 3 ... external boundary scan (SoC-specific, unused here)
31  * 6 ... ETM
32  * 15 ... coprocessor 15
33  */
34 
35 #if 0
36 #define _DEBUG_INSTRUCTION_EXECUTION_
37 #endif
38 
39 #define ARM926EJS_CP15_ADDR(opcode_1, opcode_2, crn, crm) ((opcode_1 << 11) | (opcode_2 << 8) | (crn << 4) | (crm << 0))
40 
41 static int arm926ejs_cp15_read(struct target *target, uint32_t op1, uint32_t op2,
42  uint32_t crn, uint32_t crm, uint32_t *value)
43 {
44  int retval = ERROR_OK;
45  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
46  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
47  uint32_t address = ARM926EJS_CP15_ADDR(op1, op2, crn, crm);
48  struct scan_field fields[4];
49  uint8_t address_buf[2] = {0, 0};
50  uint8_t nr_w_buf = 0;
51  uint8_t access_t = 1;
52 
53  buf_set_u32(address_buf, 0, 14, address);
54 
55  retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
56  if (retval != ERROR_OK)
57  return retval;
58  retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
59  if (retval != ERROR_OK)
60  return retval;
61 
62  fields[0].num_bits = 32;
63  fields[0].out_value = NULL;
64  fields[0].in_value = (uint8_t *)value;
65 
66  fields[1].num_bits = 1;
67  fields[1].out_value = &access_t;
68  fields[1].in_value = &access_t;
69 
70  fields[2].num_bits = 14;
71  fields[2].out_value = address_buf;
72  fields[2].in_value = NULL;
73 
74  fields[3].num_bits = 1;
75  fields[3].out_value = &nr_w_buf;
76  fields[3].in_value = NULL;
77 
78  jtag_add_dr_scan(jtag_info->tap, 4, fields, TAP_IDLE);
79 
80  int64_t then = timeval_ms();
81 
82  for (;;) {
83  /* rescan with NOP, to wait for the access to complete */
84  access_t = 0;
85  nr_w_buf = 0;
86  jtag_add_dr_scan(jtag_info->tap, 4, fields, TAP_IDLE);
87 
89 
90  retval = jtag_execute_queue();
91  if (retval != ERROR_OK)
92  return retval;
93 
94  if (buf_get_u32(&access_t, 0, 1) == 1)
95  break;
96 
97  /* 10ms timeout */
98  if ((timeval_ms()-then) > 10) {
99  LOG_ERROR("cp15 read operation timed out");
100  return ERROR_FAIL;
101  }
102  }
103 
104 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
105  LOG_DEBUG("addr: 0x%x value: %8.8x", address, *value);
106 #endif
107 
108  retval = arm_jtag_set_instr(jtag_info->tap, 0xc, NULL, TAP_IDLE);
109  if (retval != ERROR_OK)
110  return retval;
111 
112  return ERROR_OK;
113 }
114 
115 static int arm926ejs_mrc(struct target *target, int cpnum, uint32_t op1,
116  uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
117 {
118  if (cpnum != 15) {
119  LOG_ERROR("Only cp15 is supported");
120  return ERROR_FAIL;
121  }
122  return arm926ejs_cp15_read(target, op1, op2, crn, crm, value);
123 }
124 
125 static int arm926ejs_cp15_write(struct target *target, uint32_t op1, uint32_t op2,
126  uint32_t crn, uint32_t crm, uint32_t value)
127 {
128  int retval = ERROR_OK;
129  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
130  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
131  uint32_t address = ARM926EJS_CP15_ADDR(op1, op2, crn, crm);
132  struct scan_field fields[4];
133  uint8_t value_buf[4];
134  uint8_t address_buf[2] = {0, 0};
135  uint8_t nr_w_buf = 1;
136  uint8_t access_t = 1;
137 
138  buf_set_u32(address_buf, 0, 14, address);
139  buf_set_u32(value_buf, 0, 32, value);
140 
141  retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
142  if (retval != ERROR_OK)
143  return retval;
144  retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
145  if (retval != ERROR_OK)
146  return retval;
147 
148  fields[0].num_bits = 32;
149  fields[0].out_value = value_buf;
150  fields[0].in_value = NULL;
151 
152  fields[1].num_bits = 1;
153  fields[1].out_value = &access_t;
154  fields[1].in_value = &access_t;
155 
156  fields[2].num_bits = 14;
157  fields[2].out_value = address_buf;
158  fields[2].in_value = NULL;
159 
160  fields[3].num_bits = 1;
161  fields[3].out_value = &nr_w_buf;
162  fields[3].in_value = NULL;
163 
164  jtag_add_dr_scan(jtag_info->tap, 4, fields, TAP_IDLE);
165 
166  int64_t then = timeval_ms();
167 
168  for (;;) {
169  /* rescan with NOP, to wait for the access to complete */
170  access_t = 0;
171  nr_w_buf = 0;
172  jtag_add_dr_scan(jtag_info->tap, 4, fields, TAP_IDLE);
173  retval = jtag_execute_queue();
174  if (retval != ERROR_OK)
175  return retval;
176 
177  if (buf_get_u32(&access_t, 0, 1) == 1)
178  break;
179 
180  /* 10ms timeout */
181  if ((timeval_ms()-then) > 10) {
182  LOG_ERROR("cp15 write operation timed out");
183  return ERROR_FAIL;
184  }
185  }
186 
187 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
188  LOG_DEBUG("addr: 0x%x value: %8.8x", address, value);
189 #endif
190 
191  retval = arm_jtag_set_instr(jtag_info->tap, 0xf, NULL, TAP_IDLE);
192  if (retval != ERROR_OK)
193  return retval;
194 
195  return ERROR_OK;
196 }
197 
198 static int arm926ejs_mcr(struct target *target, int cpnum, uint32_t op1,
199  uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
200 {
201  if (cpnum != 15) {
202  LOG_ERROR("Only cp15 is supported");
203  return ERROR_FAIL;
204  }
205  return arm926ejs_cp15_write(target, op1, op2, crn, crm, value);
206 }
207 
209 {
210  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
211  struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
212  int debug_reason;
213  int retval;
214 
215  embeddedice_read_reg(dbg_stat);
216  retval = jtag_execute_queue();
217  if (retval != ERROR_OK)
218  return retval;
219 
220  /* Method-Of-Entry (MOE) field */
221  debug_reason = buf_get_u32(dbg_stat->value, 6, 4);
222 
223  switch (debug_reason) {
224  case 0:
225  LOG_DEBUG("no *NEW* debug entry (?missed one?)");
226  /* ... since last restart or debug reset ... */
228  break;
229  case 1:
230  LOG_DEBUG("breakpoint from EICE unit 0");
232  break;
233  case 2:
234  LOG_DEBUG("breakpoint from EICE unit 1");
236  break;
237  case 3:
238  LOG_DEBUG("soft breakpoint (BKPT instruction)");
240  break;
241  case 4:
242  LOG_DEBUG("vector catch breakpoint");
244  break;
245  case 5:
246  LOG_DEBUG("external breakpoint");
248  break;
249  case 6:
250  LOG_DEBUG("watchpoint from EICE unit 0");
252  break;
253  case 7:
254  LOG_DEBUG("watchpoint from EICE unit 1");
256  break;
257  case 8:
258  LOG_DEBUG("external watchpoint");
260  break;
261  case 9:
262  LOG_DEBUG("internal debug request");
264  break;
265  case 10:
266  LOG_DEBUG("external debug request");
268  break;
269  case 11:
270  LOG_DEBUG("debug re-entry from system speed access");
271  /* This is normal when connecting to something that's
272  * already halted, or in some related code paths, but
273  * otherwise is surprising (and presumably wrong).
274  */
275  switch (target->debug_reason) {
276  case DBG_REASON_DBGRQ:
277  break;
278  default:
279  LOG_ERROR("unexpected -- debug re-entry");
280  /* FALLTHROUGH */
283  break;
284  }
285  break;
286  case 12:
287  /* FIX!!!! here be dragons!!! We need to fail here so
288  * the target will interpreted as halted but we won't
289  * try to talk to it right now... a resume + halt seems
290  * to sync things up again. Please send an email to
291  * openocd development mailing list if you have hardware
292  * to donate to look into this problem....
293  */
294  LOG_WARNING("WARNING: mystery debug reason MOE = 0xc. Try issuing a resume + halt.");
296  break;
297  default:
298  LOG_WARNING("WARNING: unknown debug reason: 0x%x", debug_reason);
299  /* Oh agony! should we interpret this as a halt request or
300  * that the target stopped on it's own accord?
301  */
303  /* if we fail here, we won't talk to the target and it will
304  * be reported to be in the halted state */
305  break;
306  }
307 
308  return ERROR_OK;
309 }
310 
311 static int arm926ejs_get_ttb(struct target *target, uint32_t *result)
312 {
313  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
314  int retval;
315  uint32_t ttb = 0x0;
316 
317  retval = arm926ejs->read_cp15(target, 0, 0, 2, 0, &ttb);
318  if (retval != ERROR_OK)
319  return retval;
320 
321  *result = ttb;
322 
323  return ERROR_OK;
324 }
325 
326 static int arm926ejs_disable_mmu_caches(struct target *target, int mmu,
327  int d_u_cache, int i_cache)
328 {
329  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
330  uint32_t cp15_control;
331  int retval;
332 
333  /* read cp15 control register */
334  retval = arm926ejs->read_cp15(target, 0, 0, 1, 0, &cp15_control);
335  if (retval != ERROR_OK)
336  return retval;
337  retval = jtag_execute_queue();
338  if (retval != ERROR_OK)
339  return retval;
340 
341  if (mmu) {
342  /* invalidate TLB */
343  retval = arm926ejs->write_cp15(target, 0, 0, 8, 7, 0x0);
344  if (retval != ERROR_OK)
345  return retval;
346 
347  cp15_control &= ~0x1U;
348  }
349 
350  if (d_u_cache) {
351  uint32_t debug_override;
352  /* read-modify-write CP15 debug override register
353  * to enable "test and clean all" */
354  retval = arm926ejs->read_cp15(target, 0, 0, 15, 0, &debug_override);
355  if (retval != ERROR_OK)
356  return retval;
357  debug_override |= 0x80000;
358  retval = arm926ejs->write_cp15(target, 0, 0, 15, 0, debug_override);
359  if (retval != ERROR_OK)
360  return retval;
361 
362  /* clean and invalidate DCache */
363  retval = arm926ejs->write_cp15(target, 0, 0, 7, 5, 0x0);
364  if (retval != ERROR_OK)
365  return retval;
366 
367  /* write CP15 debug override register
368  * to disable "test and clean all" */
369  debug_override &= ~0x80000;
370  retval = arm926ejs->write_cp15(target, 0, 0, 15, 0, debug_override);
371  if (retval != ERROR_OK)
372  return retval;
373 
374  cp15_control &= ~0x4U;
375  }
376 
377  if (i_cache) {
378  /* invalidate ICache */
379  retval = arm926ejs->write_cp15(target, 0, 0, 7, 5, 0x0);
380  if (retval != ERROR_OK)
381  return retval;
382 
383  cp15_control &= ~0x1000U;
384  }
385 
386  retval = arm926ejs->write_cp15(target, 0, 0, 1, 0, cp15_control);
387  return retval;
388 }
389 
390 static int arm926ejs_enable_mmu_caches(struct target *target, int mmu,
391  int d_u_cache, int i_cache)
392 {
393  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
394  uint32_t cp15_control;
395  int retval;
396 
397  /* read cp15 control register */
398  retval = arm926ejs->read_cp15(target, 0, 0, 1, 0, &cp15_control);
399  if (retval != ERROR_OK)
400  return retval;
401  retval = jtag_execute_queue();
402  if (retval != ERROR_OK)
403  return retval;
404 
405  if (mmu)
406  cp15_control |= 0x1U;
407 
408  if (d_u_cache)
409  cp15_control |= 0x4U;
410 
411  if (i_cache)
412  cp15_control |= 0x1000U;
413 
414  retval = arm926ejs->write_cp15(target, 0, 0, 1, 0, cp15_control);
415  return retval;
416 }
417 
419 {
420  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
421  int retval;
422 
423  /* examine cp15 control reg */
424  retval = arm926ejs->read_cp15(target, 0, 0, 1, 0, &arm926ejs->cp15_control_reg);
425  if (retval != ERROR_OK)
426  return retval;
427  retval = jtag_execute_queue();
428  if (retval != ERROR_OK)
429  return retval;
430  LOG_DEBUG("cp15_control_reg: %8.8" PRIx32, arm926ejs->cp15_control_reg);
431 
432  if (arm926ejs->armv4_5_mmu.armv4_5_cache.ctype == -1) {
433  uint32_t cache_type_reg;
434  /* identify caches */
435  retval = arm926ejs->read_cp15(target, 0, 1, 0, 0, &cache_type_reg);
436  if (retval != ERROR_OK)
437  return retval;
438  retval = jtag_execute_queue();
439  if (retval != ERROR_OK)
440  return retval;
441  armv4_5_identify_cache(cache_type_reg, &arm926ejs->armv4_5_mmu.armv4_5_cache);
442  }
443 
444  arm926ejs->armv4_5_mmu.mmu_enabled = arm926ejs->cp15_control_reg & 0x1U;
446  arm926ejs->cp15_control_reg & 0x4U;
448  arm926ejs->cp15_control_reg & 0x1000U;
449 
450  /* save i/d fault status and address register */
451  retval = arm926ejs->read_cp15(target, 0, 0, 5, 0, &arm926ejs->d_fsr);
452  if (retval != ERROR_OK)
453  return retval;
454  retval = arm926ejs->read_cp15(target, 0, 1, 5, 0, &arm926ejs->i_fsr);
455  if (retval != ERROR_OK)
456  return retval;
457  retval = arm926ejs->read_cp15(target, 0, 0, 6, 0, &arm926ejs->d_far);
458  if (retval != ERROR_OK)
459  return retval;
460 
461  LOG_DEBUG("D FSR: 0x%8.8" PRIx32 ", D FAR: 0x%8.8" PRIx32 ", I FSR: 0x%8.8" PRIx32,
462  arm926ejs->d_fsr, arm926ejs->d_far, arm926ejs->i_fsr);
463 
464  uint32_t cache_dbg_ctrl;
465 
466  /* read-modify-write CP15 cache debug control register
467  * to disable I/D-cache linefills and force WT */
468  retval = arm926ejs->read_cp15(target, 7, 0, 15, 0, &cache_dbg_ctrl);
469  if (retval != ERROR_OK)
470  return retval;
471  cache_dbg_ctrl |= 0x7;
472  retval = arm926ejs->write_cp15(target, 7, 0, 15, 0, cache_dbg_ctrl);
473  return retval;
474 }
475 
477 {
478  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
479 
480  /* restore i/d fault status and address register */
481  arm926ejs->write_cp15(target, 0, 0, 5, 0, arm926ejs->d_fsr);
482  arm926ejs->write_cp15(target, 0, 1, 5, 0, arm926ejs->i_fsr);
483  arm926ejs->write_cp15(target, 0, 0, 6, 0, arm926ejs->d_far);
484 
485  uint32_t cache_dbg_ctrl;
486 
487  /* read-modify-write CP15 cache debug control register
488  * to reenable I/D-cache linefills and disable WT */
489  arm926ejs->read_cp15(target, 7, 0, 15, 0, &cache_dbg_ctrl);
490  cache_dbg_ctrl &= ~0x7;
491  arm926ejs->write_cp15(target, 7, 0, 15, 0, cache_dbg_ctrl);
492 }
493 
494 static const char arm926_not[] = "target is not an ARM926";
495 
497  struct arm926ejs_common *arm926)
498 {
499  if (arm926->common_magic != ARM926EJS_COMMON_MAGIC) {
501  return ERROR_TARGET_INVALID;
502  }
503  return ERROR_OK;
504 }
505 
508 {
509  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
510 
511  if (arm926ejs->common_magic != ARM926EJS_COMMON_MAGIC) {
512  LOG_ERROR("BUG: %s", arm926_not);
513  return ERROR_TARGET_INVALID;
514  }
515 
517  LOG_USER("MMU: %s, D-Cache: %s, I-Cache: %s",
521 
522  return ERROR_OK;
523 }
524 
526 {
527  int retval = ERROR_OK;
528  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
529  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
530  struct arm *arm = &arm7_9->arm;
531  struct reg *dbg_stat = &arm7_9->eice_cache->reg_list[EICE_DBG_STAT];
532 
533  retval = target_halt(target);
534  if (retval != ERROR_OK)
535  return retval;
536 
537  int64_t then = timeval_ms();
538  int timeout;
539  while (!(timeout = ((timeval_ms()-then) > 1000))) {
540  if (buf_get_u32(dbg_stat->value, EICE_DBG_STATUS_DBGACK, 1) == 0) {
541  embeddedice_read_reg(dbg_stat);
542  retval = jtag_execute_queue();
543  if (retval != ERROR_OK)
544  return retval;
545  } else
546  break;
547  if (debug_level >= 1) {
548  /* do not eat all CPU, time out after 1 se*/
549  alive_sleep(100);
550  } else
551  keep_alive();
552  }
553  if (timeout) {
554  LOG_ERROR("Failed to halt CPU after 1 sec");
555  return ERROR_TARGET_TIMEOUT;
556  }
557 
559 
560  /* SVC, ARM state, IRQ and FIQ disabled */
561  uint32_t cpsr;
562 
563  cpsr = buf_get_u32(arm->cpsr->value, 0, 32);
564  cpsr &= ~0xff;
565  cpsr |= 0xd3;
566  arm_set_cpsr(arm, cpsr);
567  arm->cpsr->dirty = true;
568 
569  /* start fetching from 0x0 */
570  buf_set_u32(arm->pc->value, 0, 32, 0x0);
571  arm->pc->dirty = true;
572  arm->pc->valid = true;
573 
574  retval = arm926ejs_disable_mmu_caches(target, 1, 1, 1);
575  if (retval != ERROR_OK)
576  return retval;
577  arm926ejs->armv4_5_mmu.mmu_enabled = false;
578  arm926ejs->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled = false;
579  arm926ejs->armv4_5_mmu.armv4_5_cache.i_cache_enabled = false;
580 
582 }
583 
586  uint32_t size, uint32_t count, const uint8_t *buffer)
587 {
588  int retval;
589  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
590 
591  /* FIX!!!! this should be cleaned up and made much more general. The
592  * plan is to write up and test on arm926ejs specifically and
593  * then generalize and clean up afterwards.
594  *
595  *
596  * Also it should be moved to the callbacks that handle breakpoints
597  * specifically and not the generic memory write fn's. See XScale code.
598  **/
599  if (arm926ejs->armv4_5_mmu.mmu_enabled && (count == 1) && ((size == 2) || (size == 4))) {
600  /* special case the handling of single word writes to bypass MMU
601  * to allow implementation of breakpoints in memory marked read only
602  * by MMU */
604  /* flush and invalidate data cache
605  *
606  * MCR p15,0,p,c7,c10,1 - clean cache line using virtual address
607  *
608  */
609  retval = arm926ejs->write_cp15(target, 0, 1, 7, 10, address&~0x3);
610  if (retval != ERROR_OK)
611  return retval;
612  }
613 
614  target_addr_t pa;
615  retval = target->type->virt2phys(target, address, &pa);
616  if (retval != ERROR_OK)
617  return retval;
618 
619  /* write directly to physical memory bypassing any read only MMU bits, etc. */
620  retval = armv4_5_mmu_write_physical(target, &arm926ejs->armv4_5_mmu, pa, size, count, buffer);
621  if (retval != ERROR_OK)
622  return retval;
623  } else {
625  if (retval != ERROR_OK)
626  return retval;
627  }
628 
629  /* If ICache is enabled, we have to invalidate affected ICache lines
630  * the DCache is forced to write-through, so we don't have to clean it here
631  */
632  if (arm926ejs->armv4_5_mmu.armv4_5_cache.i_cache_enabled) {
633  if (count <= 1) {
634  /* invalidate ICache single entry with MVA */
635  arm926ejs->write_cp15(target, 0, 1, 7, 5, address);
636  } else {
637  /* invalidate ICache */
638  arm926ejs->write_cp15(target, 0, 0, 7, 5, address);
639  }
640  }
641 
642  return retval;
643 }
644 
646  target_addr_t address, uint32_t size,
647  uint32_t count, const uint8_t *buffer)
648 {
649  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
650 
651  return armv4_5_mmu_write_physical(target, &arm926ejs->armv4_5_mmu,
652  address, size, count, buffer);
653 }
654 
656  target_addr_t address, uint32_t size,
657  uint32_t count, uint8_t *buffer)
658 {
659  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
660 
661  return armv4_5_mmu_read_physical(target, &arm926ejs->armv4_5_mmu,
662  address, size, count, buffer);
663 }
664 
666  struct jtag_tap *tap)
667 {
668  struct arm7_9_common *arm7_9 = &arm926ejs->arm7_9_common;
669 
670  arm7_9->arm.mrc = arm926ejs_mrc;
671  arm7_9->arm.mcr = arm926ejs_mcr;
672 
673  /* initialize arm7/arm9 specific info (including armv4_5) */
674  arm9tdmi_init_arch_info(target, arm7_9, tap);
675 
677 
681 
682  arm926ejs->read_cp15 = arm926ejs_cp15_read;
683  arm926ejs->write_cp15 = arm926ejs_cp15_write;
684  arm926ejs->armv4_5_mmu.armv4_5_cache.ctype = -1;
690  arm926ejs->armv4_5_mmu.has_tiny_pages = 1;
691  arm926ejs->armv4_5_mmu.mmu_enabled = false;
692 
694 
695  /* The ARM926EJ-S implements the ARMv5TE architecture which
696  * has the BKPT instruction, so we don't have to use a watchpoint comparator
697  */
698  arm7_9->arm_bkpt = ARMV5_BKPT(0x0);
699  arm7_9->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
700 
701  return ERROR_OK;
702 }
703 
705 {
706  struct arm926ejs_common *arm926ejs = calloc(1, sizeof(struct arm926ejs_common));
707 
708  /* ARM9EJ-S core always reports 0x1 in Capture-IR */
709  target->tap->ir_capture_mask = 0x0f;
710 
711  return arm926ejs_init_arch_info(target, arm926ejs, target->tap);
712 }
713 
715 {
716  struct arm *arm = target_to_arm(target);
717  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
718 
721  free(arm926ejs);
722 }
723 
724 COMMAND_HANDLER(arm926ejs_handle_cache_info_command)
725 {
726  int retval;
728  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
729 
730  retval = arm926ejs_verify_pointer(CMD, arm926ejs);
731  if (retval != ERROR_OK)
732  return retval;
733 
735 }
736 
737 static int arm926ejs_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical)
738 {
739  uint32_t cb;
740  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
741 
742  uint32_t ret;
743  int retval = armv4_5_mmu_translate_va(target, &arm926ejs->armv4_5_mmu,
744  virtual, &cb, &ret);
745  if (retval != ERROR_OK)
746  return retval;
747  *physical = ret;
748  return ERROR_OK;
749 }
750 
751 static int arm926ejs_mmu(struct target *target, bool *enabled)
752 {
753  struct arm926ejs_common *arm926ejs = target_to_arm926(target);
754 
755  if (target->state != TARGET_HALTED) {
756  LOG_TARGET_ERROR(target, "not halted");
758  }
759  *enabled = arm926ejs->armv4_5_mmu.mmu_enabled;
760  return ERROR_OK;
761 }
762 
764  {
765  .name = "cache_info",
766  .handler = arm926ejs_handle_cache_info_command,
767  .mode = COMMAND_EXEC,
768  .usage = "",
769  .help = "display information about target caches",
770 
771  },
773 };
775  {
777  },
778  {
779  .name = "arm926ejs",
780  .mode = COMMAND_ANY,
781  .help = "arm926ejs command group",
782  .usage = "",
784  },
786 };
787 
789 struct target_type arm926ejs_target = {
790  .name = "arm926ejs",
791 
792  .poll = arm7_9_poll,
793  .arch_state = arm926ejs_arch_state,
794 
795  .target_request_data = arm7_9_target_request_data,
796 
797  .halt = arm7_9_halt,
798  .resume = arm7_9_resume,
799  .step = arm7_9_step,
800 
801  .assert_reset = arm7_9_assert_reset,
802  .deassert_reset = arm7_9_deassert_reset,
803  .soft_reset_halt = arm926ejs_soft_reset_halt,
804 
805  .get_gdb_arch = arm_get_gdb_arch,
806  .get_gdb_reg_list = arm_get_gdb_reg_list,
807 
808  .read_memory = arm7_9_read_memory,
809  .write_memory = arm7_9_write_memory_opt,
810 
811  .checksum_memory = arm_checksum_memory,
812  .blank_check_memory = arm_blank_check_memory,
813 
814  .run_algorithm = armv4_5_run_algorithm,
815 
816  .add_breakpoint = arm7_9_add_breakpoint,
817  .remove_breakpoint = arm7_9_remove_breakpoint,
818  .add_watchpoint = arm7_9_add_watchpoint,
819  .remove_watchpoint = arm7_9_remove_watchpoint,
820 
821  .commands = arm926ejs_command_handlers,
822  .target_create = arm926ejs_target_create,
823  .init_target = arm9tdmi_init_target,
824  .deinit_target = arm926ejs_deinit_target,
825  .examine = arm7_9_examine,
826  .check_reset = arm7_9_check_reset,
827  .virt2phys = arm926ejs_virt2phys,
828  .mmu = arm926ejs_mmu,
829 
830  .read_phys_memory = arm926ejs_read_phys_memory,
831  .write_phys_memory = arm926ejs_write_phys_memory,
832 };
int arm7_9_write_memory_opt(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
int arm7_9_examine(struct target *target)
Perform per-target setup that requires JTAG access.
void arm7_9_deinit(struct target *target)
int arm7_9_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
int arm7_9_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Add a breakpoint to an ARM7/9 target.
int arm7_9_assert_reset(struct target *target)
Asserts the reset (SRST) on an ARM7/9 target.
int arm7_9_poll(struct target *target)
Polls an ARM7/9 target for its current status.
int arm7_9_halt(struct target *target)
Halt an ARM7/9 target.
int arm7_9_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Removes a breakpoint from an ARM7/9 target.
int arm7_9_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Remove a watchpoint from an ARM7/9 target.
int arm7_9_deassert_reset(struct target *target)
Deassert the reset (SRST) signal on an ARM7/9 target.
int arm7_9_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
int arm7_9_target_request_data(struct target *target, uint32_t size, uint8_t *buffer)
Get some data from the ARM7/9 target.
int arm7_9_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
int arm7_9_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Add a watchpoint to an ARM7/9 target.
int arm7_9_check_reset(struct target *target)
int arm7_9_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
static struct arm7_9_common * target_to_arm7_9(struct target *target)
static int arm926ejs_cp15_write(struct target *target, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
Definition: arm926ejs.c:125
static const char arm926_not[]
Definition: arm926ejs.c:494
static int arm926ejs_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical)
Definition: arm926ejs.c:737
static int arm926ejs_disable_mmu_caches(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: arm926ejs.c:326
int arm926ejs_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Writes a buffer, in the specified word size, with current MMU settings.
Definition: arm926ejs.c:585
struct target_type arm926ejs_target
Holds methods for ARM926 targets.
Definition: arm926ejs.c:789
static int arm926ejs_post_debug_entry(struct target *target)
Definition: arm926ejs.c:418
static int arm926ejs_mcr(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
Definition: arm926ejs.c:198
static int arm926ejs_mmu(struct target *target, bool *enabled)
Definition: arm926ejs.c:751
#define ARM926EJS_CP15_ADDR(opcode_1, opcode_2, crn, crm)
Definition: arm926ejs.c:39
static int arm926ejs_verify_pointer(struct command_invocation *cmd, struct arm926ejs_common *arm926)
Definition: arm926ejs.c:496
static const struct command_registration arm926ejs_exec_command_handlers[]
Definition: arm926ejs.c:763
static int arm926ejs_target_create(struct target *target)
Definition: arm926ejs.c:704
static int arm926ejs_read_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: arm926ejs.c:655
const struct command_registration arm926ejs_command_handlers[]
Definition: arm926ejs.c:774
int arm926ejs_init_arch_info(struct target *target, struct arm926ejs_common *arm926ejs, struct jtag_tap *tap)
Definition: arm926ejs.c:665
static int arm926ejs_get_ttb(struct target *target, uint32_t *result)
Definition: arm926ejs.c:311
static int arm926ejs_examine_debug_reason(struct target *target)
Definition: arm926ejs.c:208
static void arm926ejs_pre_restore_context(struct target *target)
Definition: arm926ejs.c:476
static int arm926ejs_cp15_read(struct target *target, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
Definition: arm926ejs.c:41
static void arm926ejs_deinit_target(struct target *target)
Definition: arm926ejs.c:714
int arm926ejs_arch_state(struct target *target)
Logs summary of ARM926 state for a halted target.
Definition: arm926ejs.c:507
static int arm926ejs_write_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: arm926ejs.c:645
static int arm926ejs_mrc(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
Definition: arm926ejs.c:115
static int arm926ejs_enable_mmu_caches(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: arm926ejs.c:390
int arm926ejs_soft_reset_halt(struct target *target)
Definition: arm926ejs.c:525
COMMAND_HANDLER(arm926ejs_handle_cache_info_command)
Definition: arm926ejs.c:724
#define ARM926EJS_COMMON_MAGIC
Definition: arm926ejs.h:14
static struct arm926ejs_common * target_to_arm926(struct target *target)
Definition: arm926ejs.h:31
int arm9tdmi_init_arch_info(struct target *target, struct arm7_9_common *arm7_9, struct jtag_tap *tap)
Definition: arm9tdmi.c:711
int arm9tdmi_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: arm9tdmi.c:703
const struct command_registration arm9tdmi_command_handlers[]
Definition: arm9tdmi.c:873
int arm_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Runs ARM code in the target to check whether a memory block holds all ones.
Definition: armv4_5.c:1686
int arm_arch_state(struct target *target)
Definition: armv4_5.c:796
int arm_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Runs ARM code in the target to calculate a CRC32 checksum.
Definition: armv4_5.c:1613
const char * arm_get_gdb_arch(const struct target *target)
Definition: armv4_5.c:1281
int arm_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Definition: armv4_5.c:1286
void arm_free_reg_cache(struct arm *arm)
Definition: armv4_5.c:775
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:261
void arm_set_cpsr(struct arm *arm, uint32_t cpsr)
Configures host-side ARM records to reflect the specified CPSR.
Definition: armv4_5.c:452
int armv4_5_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Definition: armv4_5.c:1587
static int arm_jtag_scann(struct arm_jtag *jtag_info, uint32_t new_scan_chain, enum tap_state end_state)
Definition: arm_jtag.h:43
static int arm_jtag_set_instr(struct jtag_tap *tap, uint32_t new_instr, void *no_verify_capture, enum tap_state end_state)
Definition: arm_jtag.h:31
static void arm_le_to_h_u32(jtag_callback_data_t arg)
Definition: arm_jtag.h:63
Macros used to generate various ARM or Thumb opcodes.
#define ARMV5_BKPT(im)
Definition: arm_opcodes.h:227
#define ARMV5_T_BKPT(im)
Definition: arm_opcodes.h:313
int armv4_5_identify_cache(uint32_t cache_type_reg, struct armv4_5_cache_common *cache)
Definition: armv4_5_cache.c:15
int armv4_5_handle_cache_info_command(struct command_invocation *cmd, struct armv4_5_cache_common *armv4_5_cache)
Definition: armv4_5_cache.c:68
int armv4_5_mmu_read_physical(struct target *target, struct armv4_5_mmu_common *armv4_5_mmu, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: armv4_5_mmu.c:104
int armv4_5_mmu_write_physical(struct target *target, struct armv4_5_mmu_common *armv4_5_mmu, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: armv4_5_mmu.c:134
int armv4_5_mmu_translate_va(struct target *target, struct armv4_5_mmu_common *armv4_5_mmu, uint32_t va, uint32_t *cb, uint32_t *val)
Definition: armv4_5_mmu.c:16
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:104
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:375
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:251
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
int embeddedice_read_reg(struct reg *reg)
Queue a read for an EmbeddedICE register into the register cache, not checking the value read.
Definition: embeddedice.c:464
@ EICE_DBG_STAT
Definition: embeddedice.h:21
@ EICE_DBG_STATUS_DBGACK
Definition: embeddedice.h:53
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1050
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, enum tap_state state)
Generate a DR SCAN using the fields passed to the function.
Definition: jtag/core.c:457
void jtag_add_callback(jtag_callback1_t f, jtag_callback_data_t data0)
A simpler version of jtag_add_callback4().
@ TAP_IDLE
Definition: jtag.h:53
intptr_t jtag_callback_data_t
Defines the type of data passed to the jtag_callback_t interface.
Definition: jtag.h:336
int debug_level
Definition: log.c:47
void alive_sleep(uint64_t ms)
Definition: log.c:468
void keep_alive(void)
Definition: log.c:427
#define LOG_USER(expr ...)
Definition: log.h:136
#define LOG_WARNING(expr ...)
Definition: log.h:130
#define ERROR_FAIL
Definition: log.h:174
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:162
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
static const char * str_enabled_disabled(bool value)
Structure for items that are common between both ARM7 and ARM9 targets.
Definition: arm7_9_common.h:28
struct arm arm
Definition: arm7_9_common.h:31
uint32_t arm_bkpt
ARM breakpoint instruction.
Definition: arm7_9_common.h:36
int(* write_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Variant specific memory write function that does not dispatch to bulk_write_memory.
struct arm_jtag jtag_info
JTAG information for target.
Definition: arm7_9_common.h:33
struct reg_cache * eice_cache
Embedded ICE register cache.
Definition: arm7_9_common.h:34
int(* post_debug_entry)(struct target *target)
Callback function called after entering debug mode.
uint16_t thumb_bkpt
Thumb breakpoint instruction.
Definition: arm7_9_common.h:37
void(* pre_restore_context)(struct target *target)
Callback function called before restoring the processor context.
int(* examine_debug_reason)(struct target *target)
Function for determining why debug state was entered.
Definition: arm7_9_common.h:62
uint32_t cp15_control_reg
Definition: arm926ejs.h:25
int(* write_cp15)(struct target *target, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
Definition: arm926ejs.h:23
int(* read_cp15)(struct target *target, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
Definition: arm926ejs.h:21
struct arm7_9_common arm7_9_common
Definition: arm926ejs.h:19
uint32_t d_fsr
Definition: arm926ejs.h:26
struct armv4_5_mmu_common armv4_5_mmu
Definition: arm926ejs.h:20
uint32_t i_fsr
Definition: arm926ejs.h:27
uint32_t d_far
Definition: arm926ejs.h:28
unsigned int common_magic
Definition: arm926ejs.h:17
uint32_t intest_instr
Definition: arm_jtag.h:24
struct jtag_tap * tap
Definition: arm_jtag.h:18
Represents a generic ARM core, with standard application registers.
Definition: arm.h:175
int(* mrc)(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
Read coprocessor register.
Definition: arm.h:230
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
Definition: arm.h:184
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:181
int(* mcr)(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
Write coprocessor register.
Definition: arm.h:241
int(* write_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: armv4_5_mmu.h:18
int(* read_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: armv4_5_mmu.h:17
int(* get_ttb)(struct target *target, uint32_t *result)
Definition: armv4_5_mmu.h:16
int(* enable_mmu_caches)(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: armv4_5_mmu.h:21
int(* disable_mmu_caches)(struct target *target, int mmu, int d_u_cache, int i_cache)
Definition: armv4_5_mmu.h:20
struct armv4_5_cache_common armv4_5_cache
Definition: armv4_5_mmu.h:22
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
const char * name
Definition: command.h:234
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
Definition: command.h:247
Definition: jtag.h:101
uint32_t ir_capture_mask
Definition: jtag.h:113
struct reg * reg_list
Definition: register.h:147
Definition: register.h:111
bool valid
Definition: register.h:126
uint8_t * value
Definition: register.h:122
bool dirty
Definition: register.h:124
This structure defines a single scan field in the scan.
Definition: jtag.h:87
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:93
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:91
unsigned int num_bits
The number of bits this field specifies.
Definition: jtag.h:89
This holds methods shared between all instances of a given target type.
Definition: target_type.h:26
const char * name
Name of this type of target.
Definition: target_type.h:31
int(* virt2phys)(struct target *target, target_addr_t address, target_addr_t *physical)
Definition: target_type.h:248
Definition: target.h:119
struct jtag_tap * tap
Definition: target.h:122
enum target_debug_reason debug_reason
Definition: target.h:157
enum target_state state
Definition: target.h:160
struct target_type * type
Definition: target.h:120
Definition: psoc6.c:83
int target_call_event_callbacks(struct target *target, enum target_event event)
Definition: target.c:1774
int target_halt(struct target *target)
Definition: target.c:516
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:467
@ DBG_REASON_UNDEFINED
Definition: target.h:80
@ DBG_REASON_DBGRQ
Definition: target.h:72
@ DBG_REASON_WATCHPOINT
Definition: target.h:74
@ DBG_REASON_BREAKPOINT
Definition: target.h:73
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:786
#define ERROR_TARGET_INVALID
Definition: target.h:783
@ TARGET_EVENT_HALTED
Definition: target.h:255
@ TARGET_HALTED
Definition: target.h:58
#define ERROR_TARGET_TIMEOUT
Definition: target.h:785
int64_t timeval_ms(void)
uint64_t target_addr_t
Definition: types.h:335
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t count[4]
Definition: vdebug.c:22