OpenOCD
mips32.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2008 by Spencer Oliver *
5  * spen@spen-soft.co.uk *
6  * *
7  * Copyright (C) 2008 by David T.L. Wong *
8  * *
9  * Copyright (C) 2007,2008 Øyvind Harboe *
10  * oyvind.harboe@zylin.com *
11  * *
12  * Copyright (C) 2011 by Drasko DRASKOVIC *
13  * drasko.draskovic@gmail.com *
14  ***************************************************************************/
15 
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19 
20 #include "mips32.h"
21 #include "mips_cpu.h"
22 #include "breakpoints.h"
23 #include "algorithm.h"
24 #include "register.h"
25 
26 static const char *mips_isa_strings[] = {
27  "MIPS32", "MIPS16", "", "MICRO MIPS32",
28 };
29 
30 #define MIPS32_GDB_FP_REG 1
31 
32 /*
33  * GDB registers
34  * based on gdb-7.6.2/gdb/features/mips-{fpu,cp0,cpu,dsp}.xml
35  */
36 static const struct {
37  unsigned int id;
38  const char *name;
39  enum reg_type type;
40  const char *group;
41  const char *feature;
42  int size;
43 } mips32_regs[] = {
44  { 0, "r0", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
45  { 1, "r1", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
46  { 2, "r2", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
47  { 3, "r3", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
48  { 4, "r4", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
49  { 5, "r5", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
50  { 6, "r6", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
51  { 7, "r7", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
52  { 8, "r8", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
53  { 9, "r9", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
54  { 10, "r10", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
55  { 11, "r11", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
56  { 12, "r12", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
57  { 13, "r13", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
58  { 14, "r14", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
59  { 15, "r15", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
60  { 16, "r16", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
61  { 17, "r17", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
62  { 18, "r18", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
63  { 19, "r19", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
64  { 20, "r20", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
65  { 21, "r21", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
66  { 22, "r22", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
67  { 23, "r23", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
68  { 24, "r24", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
69  { 25, "r25", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
70  { 26, "r26", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
71  { 27, "r27", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
72  { 28, "r28", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
73  { 29, "r29", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
74  { 30, "r30", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
75  { 31, "r31", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
76  { 32, "lo", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
77  { 33, "hi", REG_TYPE_INT, NULL, "org.gnu.gdb.mips.cpu", 0 },
78 
80  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
82  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
84  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
86  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
88  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
90  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
92  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
94  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
96  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
98  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
100  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
102  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
104  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
106  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
108  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
110  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
112  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
114  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
116  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
118  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
120  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
122  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
124  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
126  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
128  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
130  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
132  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
134  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
136  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
138  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
140  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
142  "org.gnu.gdb.mips.fpu", MIPS32_GDB_FP_REG },
143 
144  { MIPS32_REGLIST_FPC_INDEX + 0, "fcsr", REG_TYPE_INT, "float",
145  "org.gnu.gdb.mips.fpu", 0 },
146  { MIPS32_REGLIST_FPC_INDEX + 1, "fir", REG_TYPE_INT, "float",
147  "org.gnu.gdb.mips.fpu", 0 },
148 
150  "org.gnu.gdb.mips.cp0", 0 },
152  "org.gnu.gdb.mips.cp0", 0 },
154  "org.gnu.gdb.mips.cp0", 0 },
156  "org.gnu.gdb.mips.cpu", 0 },
158  "org.gnu.gdb.mips.cp0", 0 },
159 
161  "org.gnu.gdb.mips.dsp", 0 },
163  "org.gnu.gdb.mips.dsp", 0 },
165  "org.gnu.gdb.mips.dsp", 0 },
167  "org.gnu.gdb.mips.dsp", 0 },
169  "org.gnu.gdb.mips.dsp", 0 },
171  "org.gnu.gdb.mips.dsp", 0 },
172 
174  "org.gnu.gdb.mips.dsp", 0 },
175 };
176 
177 #define MIPS32_NUM_REGS ARRAY_SIZE(mips32_regs)
178 
179 
180 
181 #define zero 0
182 
183 #define AT 1
184 
185 #define v0 2
186 #define v1 3
187 
188 #define a0 4
189 #define a1 5
190 #define a2 6
191 #define a3 7
192 #define t0 8
193 #define t1 9
194 #define t2 10
195 #define t3 11
196 #define t4 12
197 #define t5 13
198 #define t6 14
199 #define t7 15
200 #define ta0 12 /* alias for $t4 */
201 #define ta1 13 /* alias for $t5 */
202 #define ta2 14 /* alias for $t6 */
203 #define ta3 15 /* alias for $t7 */
204 
205 #define s0 16
206 #define s1 17
207 #define s2 18
208 #define s3 19
209 #define s4 20
210 #define s5 21
211 #define s6 22
212 #define s7 23
213 #define s8 30 /* == fp */
214 
215 #define t8 24
216 #define t9 25
217 #define k0 26
218 #define k1 27
219 
220 #define gp 28
221 
222 #define sp 29
223 #define fp 30
224 #define ra 31
225 
226 
227 static const struct {
228  const char *name;
230  { "hi1"},
231  { "lo1"},
232  { "hi2"},
233  { "lo2"},
234  { "hi3"},
235  { "lo3"},
236  { "control"},
237 };
238 
239 static int mips32_get_core_reg(struct reg *reg)
240 {
241  int retval;
242  struct mips32_core_reg *mips32_reg = reg->arch_info;
243  struct target *target = mips32_reg->target;
244  struct mips32_common *mips32_target = target_to_mips32(target);
245 
246  if (target->state != TARGET_HALTED)
248 
249  retval = mips32_target->read_core_reg(target, mips32_reg->num);
250 
251  return retval;
252 }
253 
254 static int mips32_set_core_reg(struct reg *reg, uint8_t *buf)
255 {
256  struct mips32_core_reg *mips32_reg = reg->arch_info;
257  struct target *target = mips32_reg->target;
258  uint64_t value;
259 
260  if (reg->size == 64)
261  value = buf_get_u64(buf, 0, 64);
262  else
263  value = buf_get_u32(buf, 0, 32);
264 
265  if (target->state != TARGET_HALTED)
267 
268  if (reg->size == 64)
269  buf_set_u64(reg->value, 0, 64, value);
270  else
271  buf_set_u32(reg->value, 0, 32, value);
272 
273  reg->dirty = true;
274  reg->valid = true;
275 
276  return ERROR_OK;
277 }
278 
286 static void mips32_set_all_fpr_width(struct mips32_common *mips32, bool fp64)
287 {
288  struct reg_cache *cache = mips32->core_cache;
289  struct reg *reg_list = cache->reg_list;
290  int i;
291 
293  reg_list[i].size = fp64 ? 64 : 32;
295  }
296 }
297 
307 static void mips32_detect_fpr_mode_change(struct mips32_common *mips32, uint32_t cp0_status)
308 {
309  if (!mips32->fp_imp)
310  return;
311 
312  /* CP0.Status.FR indicates the working mode of floating-point register.
313  * When FP = 0, fpr can contain any 32bit data type,
314  * 64bit data types are stored in even-odd register pairs.
315  * When FP = 1, fpr can contain any data types.*/
316  bool fpu_in_64bit = ((cp0_status & BIT(MIPS32_CP0_STATUS_FR_SHIFT)) != 0);
317 
318  /* CP0.Status.CU1 indicated whether CoProcessor1(which is FPU) is present. */
319  bool fp_enabled = ((cp0_status & BIT(MIPS32_CP0_STATUS_CU1_SHIFT)) != 0);
320 
321  if (mips32->fpu_in_64bit != fpu_in_64bit) {
322  mips32->fpu_in_64bit = fpu_in_64bit;
323  mips32_set_all_fpr_width(mips32, fpu_in_64bit);
324  LOG_WARNING("** FP mode changed to %sbit, you must reconnect GDB **", fpu_in_64bit ? "64" : "32");
325  }
326 
327  if (mips32->fpu_enabled != fp_enabled) {
328  mips32->fpu_enabled = fp_enabled;
329  const char *s = fp_enabled ? "enabled" : "disabled";
330  LOG_WARNING("** FP is %s, register update %s **", s, s);
331  }
332 }
333 
334 static int mips32_read_core_reg(struct target *target, unsigned int num)
335 {
336  unsigned int cnum;
337  uint64_t reg_value = 0;
338 
339  /* get pointers to arch-specific information */
340  struct mips32_common *mips32 = target_to_mips32(target);
341 
342  if (num >= MIPS32_NUM_REGS)
344 
345  if (num >= MIPS32_REGLIST_DSP_INDEX) {
346  /* DSP */
347  cnum = num - MIPS32_REGLIST_DSP_INDEX;
348  reg_value = mips32->core_regs.dsp[cnum];
349  buf_set_u32(mips32->core_cache->reg_list[num].value, 0, 32, reg_value);
350  } else if (num >= MIPS32_REGLIST_C0_INDEX) {
351  /* CP0 */
352  cnum = num - MIPS32_REGLIST_C0_INDEX;
353  reg_value = mips32->core_regs.cp0[cnum];
354  buf_set_u32(mips32->core_cache->reg_list[num].value, 0, 32, reg_value);
355  if (cnum == MIPS32_REG_C0_STATUS_INDEX)
356  mips32_detect_fpr_mode_change(mips32, reg_value);
357  } else if (num >= MIPS32_REGLIST_FPC_INDEX) {
358  /* FPCR */
359  cnum = num - MIPS32_REGLIST_FPC_INDEX;
360  reg_value = mips32->core_regs.fpcr[cnum];
361  buf_set_u32(mips32->core_cache->reg_list[num].value, 0, 32, reg_value);
362  } else if (num >= MIPS32_REGLIST_FP_INDEX) {
363  /* FPR */
364  cnum = num - MIPS32_REGLIST_FP_INDEX;
365  reg_value = mips32->core_regs.fpr[cnum];
366  buf_set_u64(mips32->core_cache->reg_list[num].value, 0, 64, reg_value);
367  } else {
368  /* GPR */
369  cnum = num - MIPS32_REGLIST_GP_INDEX;
370  reg_value = mips32->core_regs.gpr[cnum];
371  buf_set_u32(mips32->core_cache->reg_list[num].value, 0, 32, reg_value);
372  }
373 
374  mips32->core_cache->reg_list[num].valid = true;
375  mips32->core_cache->reg_list[num].dirty = false;
376 
377  LOG_DEBUG("read core reg %i value 0x%" PRIx64, num, reg_value);
378 
379  return ERROR_OK;
380 }
381 
382 static int mips32_write_core_reg(struct target *target, unsigned int num)
383 {
384  unsigned int cnum;
385  uint64_t reg_value;
386 
387  /* get pointers to arch-specific information */
388  struct mips32_common *mips32 = target_to_mips32(target);
389 
390  if (num >= MIPS32_NUM_REGS)
392 
393  if (num >= MIPS32_REGLIST_DSP_INDEX) {
394  /* DSP */
395  cnum = num - MIPS32_REGLIST_DSP_INDEX;
396  reg_value = buf_get_u32(mips32->core_cache->reg_list[num].value, 0, 32);
397  mips32->core_regs.dsp[cnum] = (uint32_t)reg_value;
398  } else if (num >= MIPS32_REGLIST_C0_INDEX) {
399  /* CP0 */
400  cnum = num - MIPS32_REGLIST_C0_INDEX;
401  reg_value = buf_get_u32(mips32->core_cache->reg_list[num].value, 0, 32);
402  mips32->core_regs.cp0[cnum] = (uint32_t)reg_value;
403  if (cnum == MIPS32_REG_C0_STATUS_INDEX)
404  mips32_detect_fpr_mode_change(mips32, reg_value);
405  } else if (num >= MIPS32_REGLIST_FPC_INDEX) {
406  /* FPCR */
407  cnum = num - MIPS32_REGLIST_FPC_INDEX;
408  reg_value = buf_get_u32(mips32->core_cache->reg_list[num].value, 0, 32);
409  mips32->core_regs.fpcr[cnum] = (uint32_t)reg_value;
410  } else if (num >= MIPS32_REGLIST_FP_INDEX) {
411  /* FPR */
412  cnum = num - MIPS32_REGLIST_FP_INDEX;
413  reg_value = buf_get_u64(mips32->core_cache->reg_list[num].value, 0, 64);
414  mips32->core_regs.fpr[cnum] = reg_value;
415  } else {
416  /* GPR */
417  cnum = num - MIPS32_REGLIST_GP_INDEX;
418  reg_value = buf_get_u32(mips32->core_cache->reg_list[num].value, 0, 32);
419  mips32->core_regs.gpr[cnum] = (uint32_t)reg_value;
420  }
421 
422  LOG_DEBUG("write core reg %i value 0x%" PRIx64, num, reg_value);
423  mips32->core_cache->reg_list[num].valid = true;
424  mips32->core_cache->reg_list[num].dirty = false;
425 
426  return ERROR_OK;
427 }
428 
429 int mips32_get_gdb_reg_list(struct target *target, struct reg **reg_list[],
430  int *reg_list_size, enum target_register_class reg_class)
431 {
432  /* get pointers to arch-specific information */
433  struct mips32_common *mips32 = target_to_mips32(target);
434  unsigned int i;
435 
436  /* include floating point registers */
437  *reg_list_size = MIPS32_NUM_REGS;
438  *reg_list = malloc(sizeof(struct reg *) * (*reg_list_size));
439 
440  for (i = 0; i < MIPS32_NUM_REGS; i++)
441  (*reg_list)[i] = &mips32->core_cache->reg_list[i];
442 
443  return ERROR_OK;
444 }
445 
447 {
448  unsigned int i;
449 
450  /* get pointers to arch-specific information */
451  struct mips32_common *mips32 = target_to_mips32(target);
452 
453  /* read core registers */
454  int retval = mips32_pracc_read_regs(mips32);
455  if (retval != ERROR_OK) {
456  LOG_ERROR("Could not read core registers from target");
457  return retval;
458  }
459 
460  for (i = 0; i < MIPS32_NUM_REGS; i++) {
461  if (!mips32->core_cache->reg_list[i].valid)
462  mips32->read_core_reg(target, i);
463  }
464 
465  return ERROR_OK;
466 }
467 
469 {
470  unsigned int i;
471 
472  /* get pointers to arch-specific information */
473  struct mips32_common *mips32 = target_to_mips32(target);
474 
475  for (i = 0; i < MIPS32_NUM_REGS; i++) {
476  if (mips32->core_cache->reg_list[i].dirty)
477  mips32->write_core_reg(target, i);
478  }
479 
480  /* write core regs */
481  return mips32_pracc_write_regs(mips32);
482 }
483 
485 {
486  struct mips32_common *mips32 = target_to_mips32(target);
487 
488  LOG_USER("target halted in %s mode due to %s, pc: 0x%8.8" PRIx32,
489  mips_isa_strings[mips32->isa_mode],
492 
493  return ERROR_OK;
494 }
495 
496 static const struct reg_arch_type mips32_reg_type = {
498  .set = mips32_set_core_reg,
499 };
500 
502 {
503  /* get pointers to arch-specific information */
504  struct mips32_common *mips32 = target_to_mips32(target);
505 
506  int num_regs = MIPS32_NUM_REGS;
507  struct reg_cache **cache_p = register_get_last_cache_p(&target->reg_cache);
508  struct reg_cache *cache = malloc(sizeof(struct reg_cache));
509  struct reg *reg_list = calloc(num_regs, sizeof(struct reg));
510  struct mips32_core_reg *arch_info = malloc(sizeof(struct mips32_core_reg) * num_regs);
511  struct reg_feature *feature;
512  int i;
513 
514  /* Build the process context cache */
515  cache->name = "mips32 registers";
516  cache->next = NULL;
517  cache->reg_list = reg_list;
518  cache->num_regs = num_regs;
519  (*cache_p) = cache;
520  mips32->core_cache = cache;
521 
522  for (i = 0; i < num_regs; i++) {
523  arch_info[i].num = mips32_regs[i].id;
524  arch_info[i].target = target;
525  arch_info[i].mips32_common = mips32;
526 
527  reg_list[i].name = mips32_regs[i].name;
528  reg_list[i].size = mips32_regs[i].size ? 64 : 32;
529 
530  reg_list[i].value = mips32_regs[i].size ? calloc(1, 8) : calloc(1, 4);
531  reg_list[i].valid = false;
532  reg_list[i].type = &mips32_reg_type;
533  reg_list[i].arch_info = &arch_info[i];
534 
535  reg_list[i].reg_data_type = calloc(1, sizeof(struct reg_data_type));
536  if (reg_list[i].reg_data_type)
537  reg_list[i].reg_data_type->type = mips32_regs[i].type;
538  else
539  LOG_ERROR("unable to allocate reg type list");
540 
541 
542  reg_list[i].dirty = false;
543 
544  reg_list[i].group = mips32_regs[i].group;
545  reg_list[i].number = i;
546  reg_list[i].exist = true;
547  reg_list[i].caller_save = true; /* gdb defaults to true */
548 
549  feature = calloc(1, sizeof(struct reg_feature));
550  if (feature) {
551  feature->name = mips32_regs[i].feature;
552  reg_list[i].feature = feature;
553  } else
554  LOG_ERROR("unable to allocate feature list");
555  }
556 
557  return cache;
558 }
559 
560 int mips32_init_arch_info(struct target *target, struct mips32_common *mips32, struct jtag_tap *tap)
561 {
562  target->arch_info = mips32;
564  mips32->fast_data_area = NULL;
565  mips32->isa_imp = MIPS32_ONLY; /* default */
566 
567  /* has breakpoint/watchpoint unit been scanned */
568  mips32->bp_scanned = 0;
569  mips32->data_break_list = NULL;
570 
571  mips32->ejtag_info.tap = tap;
574  /* if unknown endianness defaults to little endian, 1 */
577  mips32->ejtag_info.mode = 0; /* Initial default value */
578  mips32->ejtag_info.isa = 0; /* isa on debug mips32, updated by poll function */
579  mips32->ejtag_info.config_regs = 0; /* no config register read */
580  return ERROR_OK;
581 }
582 
583 /* run to exit point. return error if exit point was not reached. */
584 static int mips32_run_and_wait(struct target *target, target_addr_t entry_point,
585  unsigned int timeout_ms, target_addr_t exit_point, struct mips32_common *mips32)
586 {
587  uint32_t pc;
588  int retval;
589  /* This code relies on the target specific resume() and poll()->debug_entry()
590  * sequence to write register values to the processor and the read them back */
591  retval = target_resume(target, false, entry_point, false, true);
592  if (retval != ERROR_OK)
593  return retval;
594 
595  retval = target_wait_state(target, TARGET_HALTED, timeout_ms);
596  /* If the target fails to halt due to the breakpoint, force a halt */
597  if (retval != ERROR_OK || target->state != TARGET_HALTED) {
598  retval = target_halt(target);
599  if (retval != ERROR_OK)
600  return retval;
601  retval = target_wait_state(target, TARGET_HALTED, 500);
602  if (retval != ERROR_OK)
603  return retval;
604  return ERROR_TARGET_TIMEOUT;
605  }
606 
608  if (exit_point && (pc != exit_point)) {
609  LOG_DEBUG("failed algorithm halted at 0x%" PRIx32 " ", pc);
610  return ERROR_TARGET_TIMEOUT;
611  }
612 
613  return ERROR_OK;
614 }
615 
616 int mips32_run_algorithm(struct target *target, int num_mem_params,
617  struct mem_param *mem_params, int num_reg_params,
618  struct reg_param *reg_params, target_addr_t entry_point,
619  target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
620 {
621  struct mips32_common *mips32 = target_to_mips32(target);
622  struct mips32_algorithm *mips32_algorithm_info = arch_info;
623  enum mips32_isa_mode isa_mode = mips32->isa_mode;
624 
625  uint32_t context[MIPS32_NUM_REGS];
626  int retval = ERROR_OK;
627 
628  LOG_DEBUG("Running algorithm");
629 
630  /* NOTE: mips32_run_algorithm requires that each algorithm uses a software breakpoint
631  * at the exit point */
632 
633  if (mips32->common_magic != MIPS32_COMMON_MAGIC) {
634  LOG_ERROR("current target isn't a MIPS32 target");
635  return ERROR_TARGET_INVALID;
636  }
637 
638  if (target->state != TARGET_HALTED) {
639  LOG_TARGET_ERROR(target, "not halted (run target algo)");
641  }
642 
643  /* refresh core register cache */
644  for (unsigned int i = 0; i < MIPS32_NUM_REGS; i++) {
645  if (!mips32->core_cache->reg_list[i].valid)
646  mips32->read_core_reg(target, i);
647  context[i] = buf_get_u32(mips32->core_cache->reg_list[i].value, 0, 32);
648  }
649 
650  for (int i = 0; i < num_mem_params; i++) {
651  if (mem_params[i].direction == PARAM_IN)
652  continue;
653  retval = target_write_buffer(target, mem_params[i].address,
654  mem_params[i].size, mem_params[i].value);
655  if (retval != ERROR_OK)
656  return retval;
657  }
658 
659  for (int i = 0; i < num_reg_params; i++) {
660  if (reg_params[i].direction == PARAM_IN)
661  continue;
662 
663  struct reg *reg = register_get_by_name(mips32->core_cache, reg_params[i].reg_name, false);
664 
665  if (!reg) {
666  LOG_ERROR("BUG: register '%s' not found", reg_params[i].reg_name);
668  }
669 
670  if (reg->size != reg_params[i].size) {
671  LOG_ERROR("BUG: register '%s' size doesn't match reg_params[i].size",
672  reg_params[i].reg_name);
674  }
675 
676  mips32_set_core_reg(reg, reg_params[i].value);
677  }
678 
679  mips32->isa_mode = mips32_algorithm_info->isa_mode;
680 
681  retval = mips32_run_and_wait(target, entry_point, timeout_ms, exit_point, mips32);
682 
683  if (retval != ERROR_OK)
684  return retval;
685 
686  for (int i = 0; i < num_mem_params; i++) {
687  if (mem_params[i].direction != PARAM_OUT) {
688  retval = target_read_buffer(target, mem_params[i].address, mem_params[i].size,
689  mem_params[i].value);
690  if (retval != ERROR_OK)
691  return retval;
692  }
693  }
694 
695  for (int i = 0; i < num_reg_params; i++) {
696  if (reg_params[i].direction != PARAM_OUT) {
697  struct reg *reg = register_get_by_name(mips32->core_cache, reg_params[i].reg_name, false);
698  if (!reg) {
699  LOG_ERROR("BUG: register '%s' not found", reg_params[i].reg_name);
701  }
702 
703  if (reg->size != reg_params[i].size) {
704  LOG_ERROR("BUG: register '%s' size doesn't match reg_params[i].size",
705  reg_params[i].reg_name);
707  }
708 
709  buf_set_u32(reg_params[i].value, 0, 32, buf_get_u32(reg->value, 0, 32));
710  }
711  }
712 
713  /* restore everything we saved before */
714  for (unsigned int i = 0; i < MIPS32_NUM_REGS; i++) {
715  uint32_t regvalue;
716  regvalue = buf_get_u32(mips32->core_cache->reg_list[i].value, 0, 32);
717  if (regvalue != context[i]) {
718  LOG_DEBUG("restoring register %s with value 0x%8.8" PRIx32,
719  mips32->core_cache->reg_list[i].name, context[i]);
720  buf_set_u32(mips32->core_cache->reg_list[i].value,
721  0, 32, context[i]);
722  mips32->core_cache->reg_list[i].valid = true;
723  mips32->core_cache->reg_list[i].dirty = true;
724  }
725  }
726 
727  mips32->isa_mode = isa_mode;
728 
729  return ERROR_OK;
730 }
731 
733 {
734  struct mips32_common *mips32 = target_to_mips32(target);
735 
736  if (!target_was_examined(target)) {
737  /* we will configure later */
738  mips32->bp_scanned = 0;
739  mips32->num_inst_bpoints = 0;
740  mips32->num_data_bpoints = 0;
741  mips32->num_inst_bpoints_avail = 0;
742  mips32->num_data_bpoints_avail = 0;
743  }
744 
745  return ERROR_OK;
746 }
747 
748 static int mips32_configure_ibs(struct target *target)
749 {
750  struct mips32_common *mips32 = target_to_mips32(target);
751  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
752  int retval, i;
753  uint32_t bpinfo;
754 
755  /* get number of inst breakpoints */
756  retval = target_read_u32(target, ejtag_info->ejtag_ibs_addr, &bpinfo);
757  if (retval != ERROR_OK)
758  return retval;
759 
760  mips32->num_inst_bpoints = (bpinfo >> 24) & 0x0F;
761  mips32->num_inst_bpoints_avail = mips32->num_inst_bpoints;
762  mips32->inst_break_list = calloc(mips32->num_inst_bpoints,
763  sizeof(struct mips32_comparator));
764 
765  for (i = 0; i < mips32->num_inst_bpoints; i++)
766  mips32->inst_break_list[i].reg_address =
767  ejtag_info->ejtag_iba0_addr +
768  (ejtag_info->ejtag_iba_step_size * i);
769 
770  /* clear IBIS reg */
771  retval = target_write_u32(target, ejtag_info->ejtag_ibs_addr, 0);
772  return retval;
773 }
774 
775 static int mips32_configure_dbs(struct target *target)
776 {
777  struct mips32_common *mips32 = target_to_mips32(target);
778  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
779  int retval, i;
780  uint32_t bpinfo;
781 
782  /* get number of data breakpoints */
783  retval = target_read_u32(target, ejtag_info->ejtag_dbs_addr, &bpinfo);
784  if (retval != ERROR_OK)
785  return retval;
786 
787  mips32->num_data_bpoints = (bpinfo >> 24) & 0x0F;
788  mips32->num_data_bpoints_avail = mips32->num_data_bpoints;
789  mips32->data_break_list = calloc(mips32->num_data_bpoints,
790  sizeof(struct mips32_comparator));
791 
792  for (i = 0; i < mips32->num_data_bpoints; i++)
793  mips32->data_break_list[i].reg_address =
794  ejtag_info->ejtag_dba0_addr +
795  (ejtag_info->ejtag_dba_step_size * i);
796 
797  /* clear DBIS reg */
798  retval = target_write_u32(target, ejtag_info->ejtag_dbs_addr, 0);
799  return retval;
800 }
801 
803 {
804  /* get pointers to arch-specific information */
805  struct mips32_common *mips32 = target_to_mips32(target);
806  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
807  int retval;
808  uint32_t dcr;
809 
810  if (mips32->bp_scanned)
811  return ERROR_OK;
812 
813  /* get info about breakpoint support */
814  retval = target_read_u32(target, EJTAG_DCR, &dcr);
815  if (retval != ERROR_OK)
816  return retval;
817 
818  /* EJTAG 2.0 defines IB and DB bits in IMP instead of DCR. */
819  if (ejtag_info->ejtag_version == EJTAG_VERSION_20) {
820  ejtag_info->debug_caps = dcr & EJTAG_DCR_ENM;
821  if (!(ejtag_info->impcode & EJTAG_V20_IMP_NOIB))
822  ejtag_info->debug_caps |= EJTAG_DCR_IB;
823  if (!(ejtag_info->impcode & EJTAG_V20_IMP_NODB))
824  ejtag_info->debug_caps |= EJTAG_DCR_DB;
825  } else
826  /* keep debug caps for later use */
827  ejtag_info->debug_caps = dcr & (EJTAG_DCR_ENM
829 
830 
831  if (ejtag_info->debug_caps & EJTAG_DCR_IB) {
832  retval = mips32_configure_ibs(target);
833  if (retval != ERROR_OK)
834  return retval;
835  }
836 
837  if (ejtag_info->debug_caps & EJTAG_DCR_DB) {
838  retval = mips32_configure_dbs(target);
839  if (retval != ERROR_OK)
840  return retval;
841  }
842 
843  /* check if target endianness settings matches debug control register */
844  if (((ejtag_info->debug_caps & EJTAG_DCR_ENM)
846  (!(ejtag_info->debug_caps & EJTAG_DCR_ENM)
848  LOG_WARNING("DCR endianness settings does not match target settings");
849 
850  LOG_DEBUG("DCR 0x%" PRIx32 " numinst %i numdata %i", dcr, mips32->num_inst_bpoints,
851  mips32->num_data_bpoints);
852 
853  mips32->bp_scanned = 1;
854 
855  return ERROR_OK;
856 }
857 
858 int mips32_enable_interrupts(struct target *target, int enable)
859 {
860  int retval;
861  int update = 0;
862  uint32_t dcr;
863 
864  /* read debug control register */
865  retval = target_read_u32(target, EJTAG_DCR, &dcr);
866  if (retval != ERROR_OK)
867  return retval;
868 
869  if (enable) {
870  if (!(dcr & EJTAG_DCR_INTE)) {
871  /* enable interrupts */
872  dcr |= EJTAG_DCR_INTE;
873  update = 1;
874  }
875  } else {
876  if (dcr & EJTAG_DCR_INTE) {
877  /* disable interrupts */
878  dcr &= ~EJTAG_DCR_INTE;
879  update = 1;
880  }
881  }
882 
883  if (update) {
884  retval = target_write_u32(target, EJTAG_DCR, dcr);
885  if (retval != ERROR_OK)
886  return retval;
887  }
888 
889  return ERROR_OK;
890 }
891 
892 /* read processor identification cp0 register */
893 static int mips32_read_c0_prid(struct target *target)
894 {
895  struct mips32_common *mips32 = target_to_mips32(target);
896  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
897  int retval;
898 
899  retval = mips32_cp0_read(ejtag_info, &mips32->prid, 15, 0);
900  if (retval != ERROR_OK) {
901  LOG_ERROR("processor id not available, failed to read cp0 PRId register");
902  mips32->prid = 0;
903  }
904 
905  return retval;
906 }
907 
918 static const struct cpu_entry *mips32_find_cpu_by_prid(uint32_t prid)
919 {
920  /* AMD/Alchemy CPU uses Company Options instead of Processor ID.
921  * Therefore an extra transform step for prid to map it to an assigned ID,
922  */
924  /* Clears Processor ID field, then put Company Option field to its place */
925  prid = (prid & 0xFFFF00FF) | ((prid & 0xFF000000) >> 16);
926  }
927 
928  /* Mask out Company Option */
929  prid &= 0x00FFFFFF;
930 
931  for (unsigned int i = 0; i < MIPS32_NUM_CPU_ENTRIES; i++) {
932  const struct cpu_entry *entry = &mips32_cpu_entry[i];
933  if ((entry->prid & MIPS32_CORE_MASK) <= prid && prid <= entry->prid)
934  return entry;
935  }
936 
937  /* If nothing matched, then return unknown entry */
939 }
940 
941 static bool mips32_cpu_is_lexra(struct mips_ejtag *ejtag_info)
942 {
943  return (ejtag_info->prid & PRID_COMP_MASK) == PRID_COMP_LEXRA;
944 }
945 
946 static int mips32_cpu_get_release(struct mips_ejtag *ejtag_info)
947 {
948  return (ejtag_info->config[0] & MIPS32_CONFIG0_AR_MASK) >> MIPS32_CONFIG0_AR_SHIFT;
949 }
950 
961 bool mips32_cpu_support_sync(struct mips_ejtag *ejtag_info)
962 {
963  return !mips32_cpu_is_lexra(ejtag_info);
964 }
965 
975 {
976  return mips32_cpu_get_release(ejtag_info) > MIPS32_RELEASE_1;
977 }
978 
994 {
995  struct mips32_common *mips32 = target_to_mips32(target);
996  int retval;
997 
998  if (mips32->prid)
999  return ERROR_OK; /* Already probed once, return early. */
1000 
1001  retval = mips32_read_c0_prid(target);
1002  if (retval != ERROR_OK)
1003  return retval;
1004 
1005  const struct cpu_entry *entry = mips32_find_cpu_by_prid(mips32->prid);
1006 
1007  switch (mips32->prid & PRID_COMP_MASK) {
1008  case PRID_COMP_INGENIC_E1:
1009  switch (mips32->prid & PRID_IMP_MASK) {
1010  case PRID_IMP_XBURST_REV1:
1011  mips32->cpu_quirks |= EJTAG_QUIRK_PAD_DRET;
1012  break;
1013  default:
1014  break;
1015  }
1016  break;
1017 
1018  /* Determine which CP0 registers are available in the current processor core */
1019  case PRID_COMP_MTI:
1020  switch (entry->prid & PRID_IMP_MASK) {
1021  case PRID_IMP_MAPTIV_UC:
1022  mips32->cp0_mask = MIPS_CP0_MAPTIV_UC;
1023  break;
1024  case PRID_IMP_MAPTIV_UP:
1025  case PRID_IMP_M5150:
1026  mips32->cp0_mask = MIPS_CP0_MAPTIV_UP;
1027  break;
1028  case PRID_IMP_IAPTIV:
1029  case PRID_IMP_IAPTIV_CM:
1030  mips32->cp0_mask = MIPS_CP0_IAPTIV;
1031  break;
1032  default:
1033  /* CP0 mask should be the same as MK4 by default */
1034  mips32->cp0_mask = MIPS_CP0_MK4;
1035  break;
1036  }
1037 
1038  default:
1039  break;
1040  }
1041 
1042  mips32->cpu_info = entry;
1043  LOG_DEBUG("CPU: %s (PRId %08x)", entry->cpu_name, mips32->prid);
1044 
1045  return ERROR_OK;
1046 }
1047 
1048 /* reads dsp implementation info from CP0 Config3 register {DSPP, DSPREV}*/
1049 static void mips32_read_config_dsp(struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
1050 {
1051  uint32_t retval, status_value, dsp_present;
1052  bool dsp_enabled;
1053 
1054  retval = mips32_cp0_read(ejtag_info, &status_value, MIPS32_C0_STATUS, 0);
1055  if (retval != ERROR_OK) {
1056  LOG_ERROR("Failed to read cp0 status register");
1057  return;
1058  }
1059 
1060  dsp_present = ((ejtag_info->config[3] & MIPS32_CONFIG3_DSPP_MASK) >> MIPS32_CONFIG3_DSPP_SHIFT);
1061  dsp_enabled = (status_value & BIT(MIPS32_CP0_STATUS_MX_SHIFT)) != 0;
1062  if (dsp_present) {
1063  mips32->dsp_imp = ((ejtag_info->config[3] & MIPS32_CONFIG3_DSPREV_MASK) >> MIPS32_CONFIG3_DSPREV_SHIFT) + 1;
1064  LOG_USER("DSP implemented: rev %d, %s", mips32->dsp_imp, dsp_enabled ? "enabled" : "disabled");
1065  } else {
1066  LOG_USER("DSP implemented: %s", "no");
1067  }
1068 }
1069 
1070 /* read fpu implementation info from CP0 Config1 register {CU1, FP}*/
1071 static int mips32_read_config_fpu(struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
1072 {
1073  int retval;
1074  uint32_t fp_imp = (ejtag_info->config[1] & MIPS32_CONFIG1_FP_MASK) >> MIPS32_CONFIG1_FP_SHIFT;
1075  char buf[60] = {0};
1076  if (!fp_imp) {
1077  LOG_USER("FPU implemented: %s", "no");
1078  mips32->fp_imp = MIPS32_FP_IMP_NONE;
1079  return ERROR_OK;
1080  }
1081  uint32_t fir_value, status_value;
1082  bool fpu_in_64bit, fp_enabled;
1083 
1084  retval = mips32_cp0_read(ejtag_info, &status_value, MIPS32_C0_STATUS, 0);
1085  if (retval != ERROR_OK) {
1086  LOG_ERROR("Failed to read cp0 status register");
1087  return retval;
1088  }
1089 
1090  fpu_in_64bit = (status_value & BIT(MIPS32_CP0_STATUS_FR_SHIFT)) != 0;
1091  fp_enabled = (status_value & BIT(MIPS32_CP0_STATUS_CU1_SHIFT)) != 0;
1092  if (fp_enabled) {
1093  retval = mips32_cp1_control_read(ejtag_info, &fir_value, 0);
1094  if (retval != ERROR_OK) {
1095  LOG_ERROR("Failed to read cp1 FIR register");
1096  return retval;
1097  }
1098 
1099  if ((fir_value >> MIPS32_CP1_FIR_F64_SHIFT) & 0x1)
1100  fp_imp++;
1101  } else {
1102  /* This is the only condition that writes to buf */
1103  snprintf(buf, sizeof(buf), "yes, disabled");
1104  fp_imp = MIPS32_FP_IMP_UNKNOWN;
1105  }
1106 
1107  mips32->fpu_in_64bit = fpu_in_64bit;
1108  mips32->fpu_enabled = fp_enabled;
1109 
1110  mips32_set_all_fpr_width(mips32, fpu_in_64bit);
1111 
1112  /* If fpu is not disabled, print out more information */
1113  if (!buf[0])
1114  snprintf(buf, sizeof(buf), "yes, %sbit (%s, working in %sbit)",
1115  fp_imp == MIPS32_FP_IMP_64 ? "64" : "32",
1116  fp_enabled ? "enabled" : "disabled",
1117  fpu_in_64bit ? "64" : "32");
1118 
1119  LOG_USER("FPU implemented: %s", buf);
1120  mips32->fp_imp = fp_imp;
1121 
1122  return ERROR_OK;
1123 }
1124 
1141 static void mips32_read_config_fdc(struct mips32_common *mips32, struct mips_ejtag *ejtag_info, uint32_t dcr)
1142 {
1143  if (((ejtag_info->config[3] & MIPS32_CONFIG3_CDMM_MASK) != 0) && ((dcr & EJTAG_DCR_FDC) != 0)) {
1144  mips32->fdc = 1;
1145  mips32->semihosting = 1;
1146  } else {
1147  mips32->fdc = 0;
1148  mips32->semihosting = 0;
1149  }
1150 }
1151 
1152 /* read config to config3 cp0 registers and log isa implementation */
1154 {
1155  struct mips32_common *mips32 = target_to_mips32(target);
1156  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1157  char buf[60] = {0};
1158  int retval;
1159 
1160  if (ejtag_info->config_regs == 0)
1161  for (int i = 0; i != 4; i++) {
1162  retval = mips32_cp0_read(ejtag_info, &ejtag_info->config[i], 16, i);
1163  if (retval != ERROR_OK) {
1164  LOG_ERROR("isa info not available, failed to read cp0 config register: %" PRId32, i);
1165  ejtag_info->config_regs = 0;
1166  return retval;
1167  }
1168  ejtag_info->config_regs = i + 1;
1169  if ((ejtag_info->config[i] & (1 << 31)) == 0)
1170  break; /* no more config registers implemented */
1171  }
1172  else
1173  return ERROR_OK; /* already successfully read */
1174 
1175  LOG_DEBUG("read %"PRIu32" config registers", ejtag_info->config_regs);
1176 
1177  mips32->isa_rel = (ejtag_info->config[0] & MIPS32_CONFIG0_AR_MASK) >> MIPS32_CONFIG0_AR_SHIFT;
1178  snprintf(buf, sizeof(buf), ", release %s(AR=%d)",
1179  mips32->isa_rel == MIPS32_RELEASE_1 ? "1"
1180  : mips32->isa_rel == MIPS32_RELEASE_2 ? "2"
1181  : mips32->isa_rel == MIPS32_RELEASE_6 ? "6"
1182  : "unknown", mips32->isa_rel);
1183 
1184  if (ejtag_info->impcode & EJTAG_IMP_MIPS16) {
1185  mips32->isa_imp = MIPS32_MIPS16;
1186  LOG_USER("ISA implemented: %s%s", "MIPS32, MIPS16", buf);
1187  } else if (ejtag_info->config_regs >= 4) { /* config3 implemented */
1188  unsigned int isa_imp = (ejtag_info->config[3] & MIPS32_CONFIG3_ISA_MASK) >> MIPS32_CONFIG3_ISA_SHIFT;
1189  if (isa_imp == 1) {
1190  mips32->isa_imp = MMIPS32_ONLY;
1191  LOG_USER("ISA implemented: %s%s", "microMIPS32", buf);
1192 
1193  } else if (isa_imp != 0) {
1194  mips32->isa_imp = MIPS32_MMIPS32;
1195  LOG_USER("ISA implemented: %s%s", "MIPS32, microMIPS32", buf);
1196  }
1197  } else if (mips32->isa_imp == MIPS32_ONLY) {
1198  /* initial default value */
1199  LOG_USER("ISA implemented: %s%s", "MIPS32", buf);
1200  }
1201 
1202  /* Retrieve DSP info */
1203  mips32_read_config_dsp(mips32, ejtag_info);
1204 
1205  /* Retrieve if Float Point CoProcessor Implemented */
1206  retval = mips32_read_config_fpu(mips32, ejtag_info);
1207  if (retval != ERROR_OK) {
1208  LOG_ERROR("fpu info is not available, error while reading cp0 status");
1209  mips32->fp_imp = MIPS32_FP_IMP_NONE;
1210  return retval;
1211  }
1212 
1213  uint32_t dcr;
1214 
1215  retval = target_read_u32(target, EJTAG_DCR, &dcr);
1216  if (retval != ERROR_OK) {
1217  LOG_ERROR("failed to read EJTAG_DCR register");
1218  return retval;
1219  }
1220 
1221  /* Determine if FDC and CDMM are implemented for this core */
1222  mips32_read_config_fdc(mips32, ejtag_info, dcr);
1223 
1224  return ERROR_OK;
1225 }
1226 
1228  uint32_t count, uint32_t *checksum)
1229 {
1230  struct working_area *crc_algorithm;
1231  struct reg_param reg_params[2];
1232  struct mips32_algorithm mips32_info;
1233 
1234  struct mips32_common *mips32 = target_to_mips32(target);
1235  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1236 
1237  /* see contrib/loaders/checksum/mips32.s for src */
1238  uint32_t isa = ejtag_info->isa ? 1 : 0;
1239 
1240  uint32_t mips_crc_code[] = {
1241  MIPS32_ADDIU(isa, 12, 4, 0), /* addiu $t4, $a0, 0 */
1242  MIPS32_ADDIU(isa, 10, 5, 0), /* addiu $t2, $a1, 0 */
1243  MIPS32_ADDIU(isa, 4, 0, 0xFFFF), /* addiu $a0, $zero, 0xffff */
1244  MIPS32_BEQ(isa, 0, 0, 0x10 << isa), /* beq $zero, $zero, ncomp */
1245  MIPS32_ADDIU(isa, 11, 0, 0), /* addiu $t3, $zero, 0 */
1246  /* nbyte: */
1247  MIPS32_LB(isa, 5, 0, 12), /* lb $a1, ($t4) */
1248  MIPS32_ADDI(isa, 12, 12, 1), /* addi $t4, $t4, 1 */
1249  MIPS32_SLL(isa, 5, 5, 24), /* sll $a1, $a1, 24 */
1250  MIPS32_LUI(isa, 2, 0x04c1), /* lui $v0, 0x04c1 */
1251  MIPS32_XOR(isa, 4, 4, 5), /* xor $a0, $a0, $a1 */
1252  MIPS32_ORI(isa, 7, 2, 0x1db7), /* ori $a3, $v0, 0x1db7 */
1253  MIPS32_ADDU(isa, 6, 0, 0), /* addu $a2, $zero, $zero */
1254  /* loop */
1255  MIPS32_SLL(isa, 8, 4, 1), /* sll $t0, $a0, 1 */
1256  MIPS32_ADDIU(isa, 6, 6, 1), /* addiu $a2, $a2, 1 */
1257  MIPS32_SLTI(isa, 4, 4, 0), /* slti $a0, $a0, 0 */
1258  MIPS32_XOR(isa, 9, 8, 7), /* xor $t1, $t0, $a3 */
1259  MIPS32_MOVN(isa, 8, 9, 4), /* movn $t0, $t1, $a0 */
1260  MIPS32_SLTI(isa, 3, 6, 8), /* slti $v1, $a2, 8 */
1261  MIPS32_BNE(isa, 3, 0, NEG16(7 << isa)), /* bne $v1, $zero, loop */
1262  MIPS32_ADDU(isa, 4, 8, 0), /* addu $a0, $t0, $zero */
1263  /* ncomp */
1264  MIPS32_BNE(isa, 10, 11, NEG16(16 << isa)), /* bne $t2, $t3, nbyte */
1265  MIPS32_ADDIU(isa, 11, 11, 1), /* addiu $t3, $t3, 1 */
1266  MIPS32_SDBBP(isa),
1267  };
1268 
1269  /* make sure we have a working area */
1270  if (target_alloc_working_area(target, sizeof(mips_crc_code), &crc_algorithm) != ERROR_OK)
1272 
1273  pracc_swap16_array(ejtag_info, mips_crc_code, ARRAY_SIZE(mips_crc_code));
1274 
1275  /* convert mips crc code into a buffer in target endianness */
1276  uint8_t mips_crc_code_8[sizeof(mips_crc_code)];
1277  target_buffer_set_u32_array(target, mips_crc_code_8,
1278  ARRAY_SIZE(mips_crc_code), mips_crc_code);
1279 
1280  int retval = target_write_buffer(target, crc_algorithm->address, sizeof(mips_crc_code), mips_crc_code_8);
1281  if (retval != ERROR_OK)
1282  return retval;
1283 
1284  mips32_info.common_magic = MIPS32_COMMON_MAGIC;
1285  mips32_info.isa_mode = isa ? MIPS32_ISA_MMIPS32 : MIPS32_ISA_MIPS32; /* run isa as in debug mode */
1286 
1287  init_reg_param(&reg_params[0], "r4", 32, PARAM_IN_OUT);
1288  buf_set_u32(reg_params[0].value, 0, 32, address);
1289 
1290  init_reg_param(&reg_params[1], "r5", 32, PARAM_OUT);
1291  buf_set_u32(reg_params[1].value, 0, 32, count);
1292 
1293  unsigned int timeout = 20000 * (1 + (count / (1024 * 1024)));
1294 
1295  retval = target_run_algorithm(target, 0, NULL, 2, reg_params, crc_algorithm->address,
1296  crc_algorithm->address + (sizeof(mips_crc_code) - 4), timeout, &mips32_info);
1297 
1298  if (retval == ERROR_OK)
1299  *checksum = buf_get_u32(reg_params[0].value, 0, 32);
1300 
1301  destroy_reg_param(&reg_params[0]);
1302  destroy_reg_param(&reg_params[1]);
1303 
1304  target_free_working_area(target, crc_algorithm);
1305 
1306  return retval;
1307 }
1308 
1311  struct target_memory_check_block *blocks, unsigned int num_blocks,
1312  uint8_t erased_value, unsigned int *checked)
1313 {
1314  struct working_area *erase_check_algorithm;
1315  struct reg_param reg_params[3];
1316  struct mips32_algorithm mips32_info;
1317 
1318  struct mips32_common *mips32 = target_to_mips32(target);
1319  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1320 
1321  if (erased_value != 0xff) {
1322  LOG_ERROR("Erase value 0x%02" PRIx8 " not yet supported for MIPS32",
1323  erased_value);
1324  return ERROR_FAIL;
1325  }
1326  uint32_t isa = ejtag_info->isa ? 1 : 0;
1327  uint32_t erase_check_code[] = {
1328  /* nbyte: */
1329  MIPS32_LB(isa, 8, 0, 4), /* lb $t0, ($a0) */
1330  MIPS32_AND(isa, 6, 6, 8), /* and $a2, $a2, $t0 */
1331  MIPS32_ADDIU(isa, 5, 5, NEG16(1)), /* addiu $a1, $a1, -1 */
1332  MIPS32_BNE(isa, 5, 0, NEG16(4 << isa)), /* bne $a1, $zero, nbyte */
1333  MIPS32_ADDIU(isa, 4, 4, 1), /* addiu $a0, $a0, 1 */
1334  MIPS32_SDBBP(isa) /* sdbbp */
1335  };
1336 
1337  /* make sure we have a working area */
1338  if (target_alloc_working_area(target, sizeof(erase_check_code), &erase_check_algorithm) != ERROR_OK)
1340 
1341  pracc_swap16_array(ejtag_info, erase_check_code, ARRAY_SIZE(erase_check_code));
1342 
1343  /* convert erase check code into a buffer in target endianness */
1344  uint8_t erase_check_code_8[sizeof(erase_check_code)];
1345  target_buffer_set_u32_array(target, erase_check_code_8,
1346  ARRAY_SIZE(erase_check_code), erase_check_code);
1347 
1348  int retval = target_write_buffer(target, erase_check_algorithm->address,
1349  sizeof(erase_check_code), erase_check_code_8);
1350  if (retval != ERROR_OK)
1351  goto cleanup;
1352 
1353  mips32_info.common_magic = MIPS32_COMMON_MAGIC;
1355 
1356  init_reg_param(&reg_params[0], "r4", 32, PARAM_OUT);
1357  buf_set_u32(reg_params[0].value, 0, 32, blocks[0].address);
1358 
1359  init_reg_param(&reg_params[1], "r5", 32, PARAM_OUT);
1360  buf_set_u32(reg_params[1].value, 0, 32, blocks[0].size);
1361 
1362  init_reg_param(&reg_params[2], "r6", 32, PARAM_IN_OUT);
1363  buf_set_u32(reg_params[2].value, 0, 32, erased_value);
1364 
1365  retval = target_run_algorithm(target, 0, NULL, 3, reg_params, erase_check_algorithm->address,
1366  erase_check_algorithm->address + (sizeof(erase_check_code) - 4), 10000, &mips32_info);
1367 
1368  if (retval == ERROR_OK) {
1369  blocks[0].result = buf_get_u32(reg_params[2].value, 0, 32);
1370  *checked = 1; /* only one block has been checked */
1371  }
1372 
1373  destroy_reg_param(&reg_params[0]);
1374  destroy_reg_param(&reg_params[1]);
1375  destroy_reg_param(&reg_params[2]);
1376 
1377 cleanup:
1378  target_free_working_area(target, erase_check_algorithm);
1379 
1380  return retval;
1381 }
1382 
1384  struct mips32_common *mips32)
1385 {
1386  if (mips32->common_magic != MIPS32_COMMON_MAGIC) {
1387  command_print(cmd, "target is not an MIPS32");
1388  return ERROR_TARGET_INVALID;
1389  }
1390  return ERROR_OK;
1391 }
1392 
1402 static int mips32_read_config_mmu(struct mips_ejtag *ejtag_info)
1403 {
1404  uint32_t config4, tlb_entries = 0, ways = 0, sets = 0;
1405  uint32_t config0 = ejtag_info->config[0];
1406  uint32_t config1 = ejtag_info->config[1];
1407  uint32_t config3 = ejtag_info->config[3];
1408  uint32_t mmu_type = (config0 >> 7) & 7;
1409  uint32_t vz_present = (config3 & BIT(23));
1410 
1411  int retval = mips32_cp0_read(ejtag_info, &config4, 16, 4);
1412  if (retval != ERROR_OK)
1413  return retval;
1414 
1415  /* mmu type = 1: VTLB only (Note: Does not account for Config4.ExtVTLB)
1416  * mmu type = 3: root RPU/Fixed (Note: Only valid with VZ ASE)
1417  * mmu type = 4: VTLB and FTLB
1418  */
1419  if ((mmu_type == 1 || mmu_type == 4) || (mmu_type == 3 && vz_present)) {
1420  tlb_entries = (uint32_t)(((config1 >> 25) & 0x3f) + 1);
1421  if (mmu_type == 4) {
1422  /* Release 6 definition for Config4[0:15] (MD01251, page 243) */
1423  /* The FTLB ways field is defined as [2, 3, 4, 5, 6, 7, 8, ...0 (reserved)] */
1424  int index = ((config4 >> 4) & 0xf);
1425  ways = index > 6 ? 0 : index + 2;
1426 
1427  /* The FTLB sets field is defined as [1, 2, 4, 8, ..., 16384, 32768] (powers of 2) */
1428  index = (config4 & 0xf);
1429  sets = 1 << index;
1430  tlb_entries = tlb_entries + (ways * sets);
1431  }
1432  }
1433  LOG_USER("TLB Entries: %d (%d ways, %d sets per way)", tlb_entries, ways, sets);
1434 
1435  return ERROR_OK;
1436 }
1437 
1449 static const struct mips32_cp0 *mips32_cp0_find_register_by_name(uint32_t cp0_mask, const char *reg_name)
1450 {
1451  if (reg_name)
1452  for (unsigned int i = 0; i < MIPS32NUMCP0REGS; i++) {
1453  if ((mips32_cp0_regs[i].core & cp0_mask) == 0)
1454  continue;
1455 
1456  if (strcmp(mips32_cp0_regs[i].name, reg_name) == 0)
1457  return &mips32_cp0_regs[i];
1458  }
1459  return NULL;
1460 }
1461 
1473 static int mips32_cp0_get_all_regs(struct command_invocation *cmd, struct mips_ejtag *ejtag_info, uint32_t cp0_mask)
1474 {
1475  uint32_t value;
1476 
1477  for (unsigned int i = 0; i < MIPS32NUMCP0REGS; i++) {
1478  /* Register name not valid for this core */
1479  if ((mips32_cp0_regs[i].core & cp0_mask) == 0)
1480  continue;
1481 
1482  int retval = mips32_cp0_read(ejtag_info, &value, mips32_cp0_regs[i].reg, mips32_cp0_regs[i].sel);
1483  if (retval != ERROR_OK) {
1484  command_print(CMD, "Error: couldn't access reg %s", mips32_cp0_regs[i].name);
1485  return retval;
1486  }
1487 
1488  command_print(CMD, "%*s: 0x%8.8" PRIx32, 14, mips32_cp0_regs[i].name, value);
1489  }
1490  return ERROR_OK;
1491 }
1492 
1504 static int mips32_cp0_get_reg_by_name(struct command_invocation *cmd, struct mips_ejtag *ejtag_info, uint32_t cp0_mask)
1505 {
1506  const struct mips32_cp0 *cp0_regs = mips32_cp0_find_register_by_name(cp0_mask, CMD_ARGV[0]);
1507  if (!cp0_regs) {
1508  command_print(CMD, "Error: Register '%s' not found", CMD_ARGV[0]);
1510  }
1511 
1512  uint32_t value;
1513  int retval = mips32_cp0_read(ejtag_info, &value, cp0_regs->reg, cp0_regs->sel);
1514  if (retval != ERROR_OK) {
1515  command_print(CMD, "Error: Encounter an Error while reading cp0 reg %d sel %d",
1516  cp0_regs->reg, cp0_regs->sel);
1517  return retval;
1518  }
1519 
1520  command_print(CMD, "0x%8.8" PRIx32, value);
1521  return ERROR_OK;
1522 }
1523 
1534 static int mips32_cp0_get_reg_by_number(struct command_invocation *cmd, struct mips_ejtag *ejtag_info)
1535 {
1536  uint32_t cp0_reg, cp0_sel, value;
1537  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], cp0_reg);
1538  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], cp0_sel);
1539 
1540  int retval = mips32_cp0_read(ejtag_info, &value, cp0_reg, cp0_sel);
1541  if (retval != ERROR_OK) {
1543  "Error: couldn't access reg %" PRIu32,
1544  cp0_reg);
1545  return retval;
1546  }
1547 
1548  command_print(CMD, "cp0 reg %" PRIu32 ", select %" PRIu32 ": %8.8" PRIx32,
1549  cp0_reg, cp0_sel, value);
1550  return ERROR_OK;
1551 }
1552 
1565  struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
1566 {
1567  const struct mips32_cp0 *cp0_regs = mips32_cp0_find_register_by_name(mips32->cp0_mask, CMD_ARGV[0]);
1568  if (!cp0_regs) {
1569  command_print(CMD, "Error: Register '%s' not found", CMD_ARGV[0]);
1571  }
1572 
1573 
1574  uint32_t value;
1575  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
1576 
1577  if (cp0_regs->reg == MIPS32_C0_STATUS && cp0_regs->sel == 0) {
1578  /* Update cached Status register if user is writing to Status */
1579  mips32->core_regs.cp0[MIPS32_REG_C0_STATUS_INDEX] = value;
1581  } else if (cp0_regs->reg == MIPS32_C0_CAUSE && cp0_regs->sel == 0) {
1582  /* Update register cache with new value if its Cause */
1583  mips32->core_regs.cp0[MIPS32_REG_C0_CAUSE_INDEX] = value;
1585  } else if (cp0_regs->reg == MIPS32_C0_DEPC && cp0_regs->sel == 0) {
1586  /* Update cached PC if its DEPC */
1587  mips32->core_regs.cp0[MIPS32_REG_C0_PC_INDEX] = value;
1589  } else if (cp0_regs->reg == MIPS32_C0_GUESTCTL1 && cp0_regs->sel == 4) {
1590  /* Update cached guestCtl1 */
1591  mips32->core_regs.cp0[MIPS32_REG_C0_GUESTCTL1_INDEX] = value;
1593  }
1594 
1595  int retval = mips32_cp0_write(ejtag_info, value,
1596  cp0_regs->reg,
1597  cp0_regs->sel);
1598  if (retval != ERROR_OK) {
1599  command_print(CMD, "Error: Encounter an Error while writing to cp0 reg %d, sel %d",
1600  cp0_regs->reg, cp0_regs->sel);
1601  return retval;
1602  }
1603 
1604  command_print(CMD, "cp0 reg %s (%u, select %u: %8.8" PRIx32 ")",
1605  CMD_ARGV[0], cp0_regs->reg, cp0_regs->sel, value);
1606  return ERROR_OK;
1607 }
1608 
1621  struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
1622 {
1623  uint32_t cp0_reg, cp0_sel, value;
1624  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], cp0_reg);
1625  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], cp0_sel);
1626  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], value);
1627 
1628  if (cp0_reg == MIPS32_C0_STATUS && cp0_sel == 0) {
1629  /* Update cached status register if user is writing to Status register */
1630  mips32->core_regs.cp0[MIPS32_REG_C0_STATUS_INDEX] = value;
1632  } else if (cp0_reg == MIPS32_C0_CAUSE && cp0_sel == 0) {
1633  /* Update register cache with new value if its Cause register */
1634  mips32->core_regs.cp0[MIPS32_REG_C0_CAUSE_INDEX] = value;
1636  } else if (cp0_reg == MIPS32_C0_DEPC && cp0_sel == 0) {
1637  /* Update cached PC if its DEPC */
1638  mips32->core_regs.cp0[MIPS32_REG_C0_PC_INDEX] = value;
1640  } else if (cp0_reg == MIPS32_C0_GUESTCTL1 && cp0_sel == 4) {
1641  /* Update cached guestCtl1, too */
1642  mips32->core_regs.cp0[MIPS32_REG_C0_GUESTCTL1_INDEX] = value;
1644  }
1645 
1646  int retval = mips32_cp0_write(ejtag_info, value, cp0_reg, cp0_sel);
1647  if (retval != ERROR_OK) {
1649  "Error: couldn't access cp0 reg %" PRIu32 ", select %" PRIu32,
1650  cp0_reg, cp0_sel);
1651  return retval;
1652  }
1653 
1654  command_print(CMD, "cp0 reg %" PRIu32 ", select %" PRIu32 ": %8.8" PRIx32,
1655  cp0_reg, cp0_sel, value);
1656  return ERROR_OK;
1657 }
1658 
1669 COMMAND_HANDLER(mips32_handle_cp0_command)
1670 {
1671  int retval, tmp;
1673  struct mips32_common *mips32 = target_to_mips32(target);
1674  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1675 
1676 
1677  retval = mips32_verify_pointer(CMD, mips32);
1678  if (retval != ERROR_OK)
1679  return retval;
1680 
1681  if (target->state != TARGET_HALTED) {
1682  command_print(CMD, "Error: target must be stopped for \"%s\" command", CMD_NAME);
1683  return ERROR_TARGET_NOT_HALTED;
1684  }
1685 
1686  switch (CMD_ARGC) {
1687  case 0: /* No arg => print out all cp0 regs */
1688  retval = mips32_cp0_get_all_regs(CMD, ejtag_info, mips32->cp0_mask);
1689  break;
1690  case 1: /* 1 arg => get cp0 #reg/#sel value by name */
1691  retval = mips32_cp0_get_reg_by_name(CMD, ejtag_info, mips32->cp0_mask);
1692  break;
1693  case 2: /* 2 args => get cp0 reg/sel value or set value by name */
1694  tmp = *CMD_ARGV[0];
1695  if (isdigit(tmp)) /* starts from number then args are #reg and #sel */
1696  retval = mips32_cp0_get_reg_by_number(CMD, ejtag_info);
1697  else /* or set value by register name */
1698  retval = mips32_cp0_set_reg_by_name(CMD, mips32, ejtag_info);
1699  break;
1700  case 3: /* 3 args => set cp0 reg/sel value*/
1701  retval = mips32_cp0_set_reg_by_number(CMD, mips32, ejtag_info);
1702  break;
1703  default: /* Other argc => err */
1704  retval = ERROR_COMMAND_SYNTAX_ERROR;
1705  break;
1706  }
1707 
1708  return retval;
1709 }
1710 
1721 static void mips32_dsp_enable(struct pracc_queue_info *ctx, int isa)
1722 {
1723  /* Save Status Register */
1724  /* move status to $9 (t1) 2*/
1725  pracc_add(ctx, 0, MIPS32_MFC0(isa, 9, 12, 0));
1726 
1727  /* Read it again in order to modify it */
1728  /* move status to $0 (t0) 3*/
1729  pracc_add(ctx, 0, MIPS32_MFC0(isa, 8, 12, 0));
1730 
1731  /* Enable access to DSP registers by setting MX bit in status register */
1732  /* $15 = MIPS32_PRACC_STACK 4/5/6*/
1734  pracc_add(ctx, 0, MIPS32_ORI(isa, 15, 15, LOWER16(MIPS32_DSP_ENABLE)));
1735  pracc_add(ctx, 0, MIPS32_ISA_OR(8, 8, 15));
1736  /* Enable DSP - update status registers 7*/
1737  pracc_add(ctx, 0, MIPS32_MTC0(isa, 8, 12, 0));
1738 }
1739 
1750 static void mips32_dsp_restore(struct pracc_queue_info *ctx, int isa)
1751 {
1752  pracc_add(ctx, 0, MIPS32_MTC0(isa, 9, 12, 0)); /* Restore status registers to previous setting */
1753  pracc_add(ctx, 0, MIPS32_NOP); /* nop */
1754 }
1755 
1770 static int mips32_pracc_read_dsp_reg(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t reg)
1771 {
1772  int isa = 0;
1773 
1774  struct pracc_queue_info ctx = {
1775  .max_code = 48,
1776  .ejtag_info = ejtag_info
1777  };
1778 
1779  uint32_t dsp_read_code[] = {
1780  MIPS32_DSP_MFHI(t0, 1), /* mfhi t0,$ac1 - OPCODE - 0x00204010 */
1781  MIPS32_DSP_MFLO(t0, 1), /* mflo t0,$ac1 - OPCODE - 0x00204012 */
1782  MIPS32_DSP_MFHI(t0, 2), /* mfhi t0,$ac2 - OPCODE - 0x00404010 */
1783  MIPS32_DSP_MFLO(t0, 2), /* mflo t0,$ac2 - OPCODE - 0x00404012 */
1784  MIPS32_DSP_MFHI(t0, 3), /* mfhi t0,$ac3 - OPCODE - 0x00604010*/
1785  MIPS32_DSP_MFLO(t0, 3), /* mflo t0,$ac3 - OPCODE - 0x00604012 */
1786  MIPS32_DSP_RDDSP(t0, 0x3F), /* rddsp t0, 0x3f (DSPCtl) - OPCODE - 0x7c3f44b8 */
1787  };
1788 
1789  /* Check status register to determine if dsp register access is enabled */
1790  /* Get status register so it can be restored later */
1791 
1792  ctx.pracc_list = NULL;
1793 
1794  /* Init context queue */
1795  pracc_queue_init(&ctx);
1796 
1797  if (ctx.retval != ERROR_OK)
1798  goto exit;
1799 
1800  /* Enables DSP whether its already enabled or not */
1801  mips32_dsp_enable(&ctx, isa);
1802 
1803  /* move AC or Control to $8 (t0) 8*/
1804  pracc_add(&ctx, 0, dsp_read_code[reg]);
1805  /* Restore status registers to previous setting */
1806  mips32_dsp_restore(&ctx, isa);
1807 
1808  /* $15 = MIPS32_PRACC_BASE_ADDR 1*/
1810  /* store $8 to pracc_out 10*/
1812  /* move COP0 DeSave to $15 11*/
1813  pracc_add(&ctx, 0, MIPS32_MFC0(isa, 15, 31, 0));
1814  /* restore upper 16 of $8 12*/
1815  pracc_add(&ctx, 0, MIPS32_LUI(isa, 8, UPPER16(ejtag_info->reg8)));
1816  /* restore lower 16 of $8 13*/
1817  pracc_add(&ctx, 0, MIPS32_ORI(isa, 8, 8, LOWER16(ejtag_info->reg8)));
1818  /* restore upper 16 of $9 14*/
1819  pracc_add(&ctx, 0, MIPS32_LUI(isa, 9, UPPER16(ejtag_info->reg9)));
1820  pracc_add(&ctx, 0, MIPS32_SYNC(isa));
1821  /* jump to start 18*/
1822  pracc_add(&ctx, 0, MIPS32_B(isa, NEG16(ctx.code_count + 1)));
1823  /* restore lower 16 of $9 15*/
1824  pracc_add(&ctx, 0, MIPS32_ORI(isa, 9, 9, LOWER16(ejtag_info->reg9)));
1825 
1826  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, val, 1);
1827 exit:
1828  pracc_queue_free(&ctx);
1829  return ctx.retval;
1830 }
1831 
1845 static int mips32_pracc_write_dsp_reg(struct mips_ejtag *ejtag_info, uint32_t val, uint32_t reg)
1846 {
1847  int isa = 0;
1848 
1849  struct pracc_queue_info ctx = {
1850  .max_code = 48,
1851  .ejtag_info = ejtag_info
1852  };
1853 
1854  uint32_t dsp_write_code[] = {
1855  MIPS32_DSP_MTHI(t0, 1), /* mthi t0, $ac1 - OPCODE - 0x01000811 */
1856  MIPS32_DSP_MTLO(t0, 1), /* mtlo t0, $ac1 - OPCODE - 0x01000813 */
1857  MIPS32_DSP_MTHI(t0, 2), /* mthi t0, $ac2 - OPCODE - 0x01001011 */
1858  MIPS32_DSP_MTLO(t0, 2), /* mtlo t0, $ac2 - OPCODE - 0x01001013 */
1859  MIPS32_DSP_MTHI(t0, 3), /* mthi t0, $ac3 - OPCODE - 0x01001811 */
1860  MIPS32_DSP_MTLO(t0, 3), /* mtlo t0, $ac3 - OPCODE - 0x01001813 */
1861  MIPS32_DSP_WRDSP(t0, 0x1F), /* wrdsp t0, 0x1f (DSPCtl) - OPCODE - 0x7d00fcf8*/
1862  };
1863 
1864  /* Init context queue */
1865  pracc_queue_init(&ctx);
1866  if (ctx.retval != ERROR_OK)
1867  goto exit;
1868 
1869  /* Enables DSP whether its already enabled or not */
1870  mips32_dsp_enable(&ctx, isa);
1871 
1872  /* Load val to $8 (t0) */
1873  pracc_add(&ctx, 0, MIPS32_LUI(isa, 8, UPPER16(val)));
1874  pracc_add(&ctx, 0, MIPS32_ORI(isa, 8, 8, LOWER16(val)));
1875 
1876  /* move AC or Control to $8 (t0) */
1877  pracc_add(&ctx, 0, dsp_write_code[reg]);
1878 
1879  /* nop, delay in order to ensure write */
1880  pracc_add(&ctx, 0, MIPS32_NOP);
1881  /* Restore status registers to previous setting */
1882  mips32_dsp_restore(&ctx, isa);
1883 
1884  /* move COP0 DeSave to $15 */
1885  pracc_add(&ctx, 0, MIPS32_MFC0(isa, 15, 31, 0));
1886 
1887  /* restore $8 */
1888  pracc_add(&ctx, 0, MIPS32_LUI(isa, 8, UPPER16(ejtag_info->reg8)));
1889  pracc_add(&ctx, 0, MIPS32_ORI(isa, 8, 8, LOWER16(ejtag_info->reg8)));
1890 
1891  /* restore upper 16 of $9 */
1892  pracc_add(&ctx, 0, MIPS32_LUI(isa, 9, UPPER16(ejtag_info->reg9)));
1893 
1894  /* jump to start */
1895  pracc_add(&ctx, 0, MIPS32_B(isa, NEG16(ctx.code_count + 1)));
1896  /* restore lower 16 of $9 */
1897  pracc_add(&ctx, 0, MIPS32_ORI(isa, 9, 9, LOWER16(ejtag_info->reg9)));
1898 
1899  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, NULL, 1);
1900 exit:
1901  pracc_queue_free(&ctx);
1902  return ctx.retval;
1903 }
1904 
1914 COMMAND_HANDLER(mips32_handle_cpuinfo_command)
1915 {
1916  int retval;
1918  struct mips32_common *mips32 = target_to_mips32(target);
1919  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1920 
1921  uint32_t prid = mips32->prid; /* cp0 PRID - 15, 0 */
1922  uint32_t config0 = ejtag_info->config[0]; /* cp0 config - 16, 0 */
1923  uint32_t config1 = ejtag_info->config[1]; /* cp0 config - 16, 1 */
1924  uint32_t config3 = ejtag_info->config[3]; /* cp0 config - 16, 3 */
1925 
1926  /* Following configs are not read during probe */
1927  uint32_t config5; /* cp0 config - 16, 5 */
1928 
1929  /* No args for now */
1930  if (CMD_ARGC != 0)
1932 
1933  if (target->state != TARGET_HALTED) {
1934  command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME);
1935  return ERROR_TARGET_NOT_HALTED;
1936  }
1937 
1938  retval = mips32_cp0_read(ejtag_info, &config5, 16, 5);
1939  if (retval != ERROR_OK)
1940  return retval;
1941 
1942  /* Determine Core info */
1943  const struct cpu_entry *entry = mips32->cpu_info;
1944  /* Display Core Type info */
1945  command_print(CMD, "CPU Core: %s", entry->cpu_name);
1946 
1947  /* Display Core Vendor ID if it's unknown */
1948  if (entry == &mips32_cpu_entry[MIPS32_NUM_CPU_ENTRIES - 1])
1949  command_print(CMD, "Vendor: Unknown CPU vendor code %x.", ((prid & 0x00ffff00) >> 16));
1950  else
1951  command_print(CMD, "Vendor: %s", entry->vendor);
1952 
1953  /* If MIPS release 2 or above, then get exception base info */
1954  enum mips32_isa_rel ar = mips32->isa_rel;
1955  if (ar > MIPS32_RELEASE_1) { /* release 2 and above */
1956  uint32_t ebase;
1957  retval = mips32_cp0_read(ejtag_info, &ebase, 15, 1);
1958  if (retval != ERROR_OK)
1959  return retval;
1960 
1961  command_print(CMD, "Current CPU ID: %d", (ebase & 0x1ff));
1962  } else {
1963  command_print(CMD, "Current CPU ID: 0");
1964  }
1965 
1966  char *instr;
1967  switch ((config3 & MIPS32_CONFIG3_ISA_MASK) >> MIPS32_CONFIG3_ISA_SHIFT) {
1968  case 0:
1969  instr = "MIPS32";
1970  break;
1971  case 1:
1972  instr = "microMIPS";
1973  break;
1974  case 2:
1975  instr = "MIPS32 (at reset) and microMIPS";
1976  break;
1977  case 3:
1978  default:
1979  instr = "microMIPS (at reset) and MIPS32";
1980  break;
1981  }
1982 
1983  /* Display Instruction Set Info */
1984  command_print(CMD, "Instr set: %s", instr);
1985  command_print(CMD, "Instr rel: %s",
1986  ar == MIPS32_RELEASE_1 ? "1"
1987  : ar == MIPS32_RELEASE_2 ? "2"
1988  : ar == MIPS32_RELEASE_6 ? "6"
1989  : "unknown");
1990  command_print(CMD, "PRId: %x", prid);
1991  /* Some of MIPS CPU Revisions(for M74K) can be seen on MD00541, page 26 */
1992  uint32_t rev = prid & 0x000000ff;
1993  command_print(CMD, "RTL Rev: %d.%d.%d", (rev & 0xE0), (rev & 0x1C), (rev & 0x3));
1994 
1995  command_print(CMD, "Max Number of Instr Breakpoints: %d", mips32->num_inst_bpoints);
1996  command_print(CMD, "Max Number of Data Breakpoints: %d", mips32->num_data_bpoints);
1997 
1998  /* MMU Support */
1999  uint32_t mmu_type = (config0 >> 7) & 7; /* MMU Type Info */
2000  char *mmu;
2001  switch (mmu_type) {
2002  case MIPS32_MMU_TLB:
2003  mmu = "TLB";
2004  break;
2005  case MIPS32_MMU_BAT:
2006  mmu = "BAT";
2007  break;
2008  case MIPS32_MMU_FIXED:
2009  mmu = "FIXED";
2010  break;
2012  mmu = "DUAL VAR/FIXED";
2013  break;
2014  default:
2015  mmu = "Unknown";
2016  }
2017  command_print(CMD, "MMU Type: %s", mmu);
2018 
2019  retval = mips32_read_config_mmu(ejtag_info);
2020  if (retval != ERROR_OK)
2021  return retval;
2022 
2023  /* Definitions of I/D Cache Sizes are available on MD01251, page 224~226 */
2024  int index;
2025  uint32_t ways, sets, bpl;
2026 
2027  /* Determine Instr Cache Size */
2028  /* Ways mapping = [1, 2, 3, 4, 5, 6, 7, 8] */
2029  ways = ((config1 >> MIPS32_CFG1_IASHIFT) & 7);
2030 
2031  /* Sets per way = [64, 128, 256, 512, 1024, 2048, 4096, 32] */
2032  index = ((config1 >> MIPS32_CFG1_ISSHIFT) & 7);
2033  sets = index == 7 ? 32 : 32 << (index + 1);
2034 
2035  /* Bytes per line = [0, 4, 8, 16, 32, 64, 128, Reserved] */
2036  index = ((config1 >> MIPS32_CFG1_ILSHIFT) & 7);
2037  bpl = index == 0 ? 0 : 4 << (index - 1);
2038  command_print(CMD, "Instr Cache: %d (%d ways, %d lines, %d byte per line)", ways * sets * bpl, ways, sets, bpl);
2039 
2040  /* Determine data cache size, same as above */
2041  ways = ((config1 >> MIPS32_CFG1_DASHIFT) & 7);
2042 
2043  index = ((config1 >> MIPS32_CFG1_DSSHIFT) & 7);
2044  sets = index == 7 ? 32 : 32 << (index + 1);
2045 
2046  index = ((config1 >> MIPS32_CFG1_DLSHIFT) & 7);
2047  bpl = index == 0 ? 0 : 4 << (index - 1);
2048  command_print(CMD, " Data Cache: %d (%d ways, %d lines, %d byte per line)", ways * sets * bpl, ways, sets, bpl);
2049 
2050  /* does the core hava FPU*/
2051  mips32_read_config_fpu(mips32, ejtag_info);
2052 
2053  /* does the core support a DSP */
2054  mips32_read_config_dsp(mips32, ejtag_info);
2055 
2056  /* VZ module */
2057  uint32_t vzase = (config3 & BIT(23));
2058  if (vzase)
2059  command_print(CMD, "VZ implemented: yes");
2060  else
2061  command_print(CMD, "VZ implemented: no");
2062 
2063  /* multithreading */
2064  uint32_t mtase = (config3 & BIT(2));
2065  if (mtase) {
2066  command_print(CMD, "MT implemented: yes");
2067 
2068  /* Get VPE and Thread info */
2069  uint32_t tcbind;
2070  uint32_t mvpconf0;
2071 
2072  /* Read tcbind register */
2073  retval = mips32_cp0_read(ejtag_info, &tcbind, 2, 2);
2074  if (retval != ERROR_OK)
2075  return retval;
2076 
2077  command_print(CMD, " | Current VPE: %d", (tcbind & 0xf));
2078  command_print(CMD, " | Current TC: %d", ((tcbind >> 21) & 0xff));
2079 
2080  /* Read mvpconf0 register */
2081  retval = mips32_cp0_read(ejtag_info, &mvpconf0, 0, 2);
2082  if (retval != ERROR_OK)
2083  return retval;
2084 
2085  command_print(CMD, " | Total TC: %d", (mvpconf0 & 0xf) + 1);
2086  command_print(CMD, " | Total VPE: %d", ((mvpconf0 >> 10) & 0xf) + 1);
2087  } else {
2088  command_print(CMD, "MT implemented: no");
2089  }
2090 
2091  /* MIPS SIMD Architecture (MSA) */
2092  uint32_t msa = (config3 & BIT(28));
2093  command_print(CMD, "MSA implemented: %s", msa ? "yes" : "no");
2094 
2095  /* Move To/From High COP0 (MTHC0/MFHC0) instructions are implemented.
2096  * Implicates current ISA release >= 5.*/
2097  uint32_t mvh = (config5 & BIT(5));
2098  command_print(CMD, "MVH implemented: %s", mvh ? "yes" : "no");
2099 
2100  /* Common Device Memory Map implemented? */
2101  uint32_t cdmm = (config3 & BIT(3));
2102  command_print(CMD, "CDMM implemented: %s", cdmm ? "yes" : "no");
2103 
2104  return ERROR_OK;
2105 }
2106 
2116 static int mips32_dsp_find_register_by_name(const char *reg_name)
2117 {
2118  if (reg_name)
2119  for (int i = 0; i < MIPS32NUMDSPREGS; i++) {
2120  if (strcmp(mips32_dsp_regs[i].name, reg_name) == 0)
2121  return i;
2122  }
2123  return MIPS32NUMDSPREGS;
2124 }
2125 
2137 {
2138  uint32_t value = 0;
2139  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
2140  for (int i = 0; i < MIPS32NUMDSPREGS; i++) {
2141  int retval = mips32_pracc_read_dsp_reg(ejtag_info, &value, i);
2142  if (retval != ERROR_OK) {
2143  command_print(CMD, "couldn't access reg %s", mips32_dsp_regs[i].name);
2144  return retval;
2145  }
2146  mips32->core_regs.dsp[i] = value;
2148  command_print(CMD, "%*s: 0x%8.8x", 7, mips32_dsp_regs[i].name, value);
2149  }
2150  return ERROR_OK;
2151 }
2152 
2165 {
2166  uint32_t value = 0;
2168  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
2169  if (index == MIPS32NUMDSPREGS) {
2170  command_print(CMD, "ERROR: register '%s' not found", CMD_ARGV[0]);
2172  }
2173 
2174  int retval = mips32_pracc_read_dsp_reg(ejtag_info, &value, index);
2175  if (retval != ERROR_OK) {
2176  command_print(CMD, "ERROR: Could not access dsp register %s", CMD_ARGV[0]);
2177  return retval;
2178  }
2179 
2180  command_print(CMD, "0x%8.8x", value);
2181 
2182  if (mips32->core_regs.dsp[index] != value) {
2183  mips32->core_regs.dsp[index] = value;
2184  mips32->core_cache->reg_list[MIPS32_REGLIST_DSP_INDEX + index].dirty = 1;
2185  }
2186 
2187  return retval;
2188 }
2189 
2203 {
2204  uint32_t value;
2205  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
2207  if (index == MIPS32NUMDSPREGS) {
2208  command_print(CMD, "ERROR: register '%s' not found", CMD_ARGV[0]);
2210  }
2211 
2212  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
2213 
2214  int retval = mips32_pracc_write_dsp_reg(ejtag_info, value, index);
2215  if (retval != ERROR_OK) {
2216  command_print(CMD, "Error: could not write to dsp register %s", CMD_ARGV[0]);
2217  return retval;
2218  }
2219 
2220  mips32->core_regs.dsp[index] = value;
2221  mips32->core_cache->reg_list[MIPS32_REGLIST_DSP_INDEX + index].dirty = 1;
2222 
2223  return retval;
2224 }
2225 
2234 COMMAND_HANDLER(mips32_handle_dsp_command)
2235 {
2236  int retval, tmp;
2238  struct mips32_common *mips32 = target_to_mips32(target);
2239 
2240  retval = mips32_verify_pointer(CMD, mips32);
2241  if (retval != ERROR_OK)
2242  return retval;
2243 
2244  if (target->state != TARGET_HALTED) {
2245  command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME);
2246  return ERROR_OK;
2247  }
2248 
2249  /* Check for too many command args */
2250  if (CMD_ARGC >= 3)
2252 
2253  /* Check if DSP access supported or not */
2254  if (!mips32->dsp_imp) {
2255  /* Issue Error Message */
2256  command_print(CMD, "DSP not implemented by this processor");
2257  return ERROR_OK;
2258  }
2259 
2260  switch (CMD_ARGC) {
2261  case 0:
2262  retval = mips32_dsp_get_all_regs(CMD, mips32);
2263  break;
2264  case 1:
2265  retval = mips32_dsp_get_register(CMD, mips32);
2266  break;
2267  case 2:
2268  tmp = *CMD_ARGV[0];
2269  if (isdigit(tmp)) {
2270  command_print(CMD, "Error: invalid dsp command format");
2272  } else {
2273  retval = mips32_dsp_set_register(CMD, mips32);
2274  }
2275  break;
2276  default:
2277  command_print(CMD, "Error: invalid argument format, required 0-2, given %d", CMD_ARGC);
2279  break;
2280  }
2281  return retval;
2282 }
2283 
2292 COMMAND_HANDLER(mips32_handle_ejtag_reg_command)
2293 {
2295  struct mips32_common *mips32 = target_to_mips32(target);
2296  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
2297 
2298  uint32_t ejtag_ctrl;
2299  uint32_t dcr;
2300  int retval;
2301 
2302  retval = mips_ejtag_get_idcode(ejtag_info);
2303  if (retval != ERROR_OK)
2304  command_print(CMD, "Error: Encounter an Error while getting idcode");
2305  else
2306  command_print(CMD, " idcode: 0x%8.8" PRIx32, ejtag_info->idcode);
2307 
2308  retval = mips_ejtag_get_impcode(ejtag_info);
2309  if (retval != ERROR_OK)
2310  command_print(CMD, "Error: Encounter an Error while getting impcode");
2311  else
2312  command_print(CMD, " impcode: 0x%8.8" PRIx32, ejtag_info->impcode);
2313 
2315  ejtag_ctrl = ejtag_info->ejtag_ctrl;
2316  retval = mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl);
2317  if (retval != ERROR_OK)
2318  command_print(CMD, "Error: Encounter an Error while executing drscan reading EJTAG Control register");
2319  else
2320  command_print(CMD, "ejtag control: 0x%8.8" PRIx32, ejtag_ctrl);
2321 
2322  ejtag_main_print_imp(ejtag_info);
2323 
2324  /* Display current DCR */
2325  retval = target_read_u32(target, EJTAG_DCR, &dcr);
2326  if (retval != ERROR_OK)
2327  command_print(CMD, "Error: Encounter an Error while reading Debug Control Register");
2328  else
2329  command_print(CMD, " DCR: 0x%8.8" PRIx32, dcr);
2330 
2331  for (unsigned int i = 0; i < EJTAG_DCR_ENTRIES; i++) {
2332  if (dcr & BIT(dcr_features[i].bit))
2333  command_print(CMD, "%s supported", dcr_features[i].name);
2334  }
2335 
2336  return ERROR_OK;
2337 }
2338 
2347 COMMAND_HANDLER(mips32_handle_scan_delay_command)
2348 {
2350  struct mips32_common *mips32 = target_to_mips32(target);
2351  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
2352 
2353  if (CMD_ARGC == 1)
2354  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], ejtag_info->scan_delay);
2355  else if (CMD_ARGC > 1)
2357 
2358  command_print(CMD, "scan delay: %d nsec", ejtag_info->scan_delay);
2359  if (ejtag_info->scan_delay >= MIPS32_SCAN_DELAY_LEGACY_MODE) {
2360  ejtag_info->mode = 0;
2361  command_print(CMD, "running in legacy mode");
2362  } else {
2363  ejtag_info->mode = 1;
2364  command_print(CMD, "running in fast queued mode");
2365  }
2366 
2367  return ERROR_OK;
2368 }
2369 
2370 static const struct command_registration mips32_exec_command_handlers[] = {
2371  {
2372  .name = "cp0",
2373  .handler = mips32_handle_cp0_command,
2374  .mode = COMMAND_EXEC,
2375  .usage = "[[reg_name|regnum select] [value]]",
2376  .help = "display/modify cp0 register",
2377  },
2378  {
2379  .name = "cpuinfo",
2380  .handler = mips32_handle_cpuinfo_command,
2381  .mode = COMMAND_EXEC,
2382  .help = "display CPU information",
2383  .usage = "",
2384  },
2385  {
2386  .name = "dsp",
2387  .handler = mips32_handle_dsp_command,
2388  .mode = COMMAND_EXEC,
2389  .help = "display or set DSP register; "
2390  "with no arguments, displays all registers and their values",
2391  .usage = "[[register_name] [value]]",
2392  },
2393  {
2394  .name = "scan_delay",
2395  .handler = mips32_handle_scan_delay_command,
2396  .mode = COMMAND_ANY,
2397  .help = "display/set scan delay in nano seconds",
2398  .usage = "[value]",
2399  },
2400  {
2401  .name = "ejtag_reg",
2402  .handler = mips32_handle_ejtag_reg_command,
2403  .mode = COMMAND_ANY,
2404  .help = "read ejtag registers",
2405  .usage = "",
2406  },
2408 };
2409 
2411  {
2412  .name = "mips32",
2413  .mode = COMMAND_ANY,
2414  .help = "mips32 command group",
2415  .usage = "",
2417  },
2419 };
void init_reg_param(struct reg_param *param, const char *reg_name, uint32_t size, enum param_direction direction)
Definition: algorithm.c:29
void destroy_reg_param(struct reg_param *param)
Definition: algorithm.c:38
@ PARAM_OUT
Definition: algorithm.h:16
@ PARAM_IN
Definition: algorithm.h:15
@ PARAM_IN_OUT
Definition: algorithm.h:17
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
static uint64_t buf_get_u64(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 64-bit word.
Definition: binarybuffer.h:134
static void buf_set_u64(uint8_t *_buffer, unsigned int first, unsigned int num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:65
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:389
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:146
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
Definition: command.h:171
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:161
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:405
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:156
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:445
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:151
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:407
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
static uint16_t direction
Definition: ftdi.c:163
#define LOG_USER(expr ...)
Definition: log.h:150
#define LOG_WARNING(expr ...)
Definition: log.h:144
#define ERROR_FAIL
Definition: log.h:188
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:176
#define LOG_ERROR(expr ...)
Definition: log.h:147
#define LOG_DEBUG(expr ...)
Definition: log.h:124
#define ERROR_OK
Definition: log.h:182
struct reg_cache * mips32_build_reg_cache(struct target *target)
Definition: mips32.c:501
bool mips32_cpu_support_sync(struct mips_ejtag *ejtag_info)
mips32_cpu_support_sync - Checks CPU supports ordering
Definition: mips32.c:961
static int mips32_read_config_mmu(struct mips_ejtag *ejtag_info)
mips32_read_config_mmu - Reads MMU configuration and logs relevant information.
Definition: mips32.c:1402
const struct command_registration mips32_command_handlers[]
Definition: mips32.c:2410
int mips32_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, unsigned int num_blocks, uint8_t erased_value, unsigned int *checked)
Checks whether a memory region is erased.
Definition: mips32.c:1310
int mips32_read_config_regs(struct target *target)
Definition: mips32.c:1153
static const struct @116 mips32_dsp_regs[MIPS32NUMDSPREGS]
int mips32_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Definition: mips32.c:1227
static int mips32_set_core_reg(struct reg *reg, uint8_t *buf)
Definition: mips32.c:254
static void mips32_read_config_dsp(struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
Definition: mips32.c:1049
static int mips32_pracc_read_dsp_reg(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t reg)
mips32_pracc_read_dsp_reg - Read a value from a MIPS32 DSP register
Definition: mips32.c:1770
#define t0
Definition: mips32.c:192
static void mips32_dsp_restore(struct pracc_queue_info *ctx, int isa)
mips32_dsp_restore - Restore DSP status registers to the previous setting
Definition: mips32.c:1750
static int mips32_cp0_get_reg_by_number(struct command_invocation *cmd, struct mips_ejtag *ejtag_info)
mips32_cp0_get_reg_by_number - Read and print a CP0 register's value by number.
Definition: mips32.c:1534
int size
Definition: mips32.c:42
static int mips32_cp0_get_all_regs(struct command_invocation *cmd, struct mips_ejtag *ejtag_info, uint32_t cp0_mask)
mips32_cp0_get_all_regs - Print all CP0 registers and their values.
Definition: mips32.c:1473
static int mips32_dsp_get_register(struct command_invocation *cmd, struct mips32_common *mips32)
mips32_dsp_get_register - Get the value of a MIPS32 DSP register
Definition: mips32.c:2164
int mips32_configure_break_unit(struct target *target)
Definition: mips32.c:802
static int mips32_get_core_reg(struct reg *reg)
Definition: mips32.c:239
int mips32_arch_state(struct target *target)
Definition: mips32.c:484
COMMAND_HANDLER(mips32_handle_cp0_command)
mips32_handle_cp0_command - Handle commands related to CP0 registers.
Definition: mips32.c:1669
const char * group
Definition: mips32.c:40
static int mips32_cp0_set_reg_by_number(struct command_invocation *cmd, struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
mips32_cp0_set_reg_by_number - Write to a CP0 register identified by number.
Definition: mips32.c:1620
int mips32_cpu_probe(struct target *target)
mips32_cpu_probe - Detects processor type and applies necessary quirks.
Definition: mips32.c:993
int mips32_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: mips32.c:616
#define MIPS32_NUM_REGS
Definition: mips32.c:177
static int mips32_read_config_fpu(struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
Definition: mips32.c:1071
#define MIPS32_GDB_FP_REG
Definition: mips32.c:30
static int mips32_dsp_get_all_regs(struct command_invocation *cmd, struct mips32_common *mips32)
mips32_dsp_get_all_regs - Get values of all MIPS32 DSP registers
Definition: mips32.c:2136
static int mips32_configure_ibs(struct target *target)
Definition: mips32.c:748
int mips32_examine(struct target *target)
Definition: mips32.c:732
static void mips32_read_config_fdc(struct mips32_common *mips32, struct mips_ejtag *ejtag_info, uint32_t dcr)
mips32_read_config_fdc - Read Fast Debug Channel configuration
Definition: mips32.c:1141
int mips32_init_arch_info(struct target *target, struct mips32_common *mips32, struct jtag_tap *tap)
Definition: mips32.c:560
static const struct reg_arch_type mips32_reg_type
Definition: mips32.c:496
static int mips32_configure_dbs(struct target *target)
Definition: mips32.c:775
const char * name
Definition: mips32.c:38
bool mips32_cpu_support_hazard_barrier(struct mips_ejtag *ejtag_info)
mips32_cpu_support_hazard_barrier - Checks CPU supports hazard barrier
Definition: mips32.c:974
static int mips32_pracc_write_dsp_reg(struct mips_ejtag *ejtag_info, uint32_t val, uint32_t reg)
mips32_pracc_write_dsp_reg - Write a value to a MIPS32 DSP register
Definition: mips32.c:1845
static int mips32_read_c0_prid(struct target *target)
Definition: mips32.c:893
static void mips32_dsp_enable(struct pracc_queue_info *ctx, int isa)
mips32_dsp_enable - Enable access to DSP registers
Definition: mips32.c:1721
static const struct mips32_cp0 * mips32_cp0_find_register_by_name(uint32_t cp0_mask, const char *reg_name)
mips32_cp0_find_register_by_name - Find CP0 register by its name.
Definition: mips32.c:1449
static int mips32_write_core_reg(struct target *target, unsigned int num)
Definition: mips32.c:382
static void mips32_set_all_fpr_width(struct mips32_common *mips32, bool fp64)
mips32_set_all_fpr_width - Set the width of all floating-point registers
Definition: mips32.c:286
enum reg_type type
Definition: mips32.c:39
static int mips32_read_core_reg(struct target *target, unsigned int num)
Definition: mips32.c:334
static int mips32_run_and_wait(struct target *target, target_addr_t entry_point, unsigned int timeout_ms, target_addr_t exit_point, struct mips32_common *mips32)
Definition: mips32.c:584
int mips32_save_context(struct target *target)
Definition: mips32.c:446
unsigned int id
Definition: mips32.c:37
static int mips32_dsp_set_register(struct command_invocation *cmd, struct mips32_common *mips32)
mips32_dsp_set_register - Set the value of a MIPS32 DSP register
Definition: mips32.c:2202
int mips32_enable_interrupts(struct target *target, int enable)
Definition: mips32.c:858
static const char * mips_isa_strings[]
Definition: mips32.c:26
static const struct cpu_entry * mips32_find_cpu_by_prid(uint32_t prid)
mips32_find_cpu_by_prid - Find CPU information by processor ID.
Definition: mips32.c:918
static void mips32_detect_fpr_mode_change(struct mips32_common *mips32, uint32_t cp0_status)
mips32_detect_fpr_mode_change - Detect changes in floating-point register mode
Definition: mips32.c:307
static int mips32_cp0_set_reg_by_name(struct command_invocation *cmd, struct mips32_common *mips32, struct mips_ejtag *ejtag_info)
mips32_cp0_set_reg_by_name - Write to a CP0 register identified by name.
Definition: mips32.c:1564
static int mips32_dsp_find_register_by_name(const char *reg_name)
mips32_dsp_find_register_by_name - Find DSP register index by name
Definition: mips32.c:2116
static bool mips32_cpu_is_lexra(struct mips_ejtag *ejtag_info)
Definition: mips32.c:941
int mips32_restore_context(struct target *target)
Definition: mips32.c:468
static int mips32_verify_pointer(struct command_invocation *cmd, struct mips32_common *mips32)
Definition: mips32.c:1383
static const struct @115 mips32_regs[]
static int mips32_cp0_get_reg_by_name(struct command_invocation *cmd, struct mips_ejtag *ejtag_info, uint32_t cp0_mask)
mips32_cp0_get_reg_by_name - Read and print a CP0 register's value by name.
Definition: mips32.c:1504
int mips32_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Definition: mips32.c:429
const char * feature
Definition: mips32.c:41
static int mips32_cpu_get_release(struct mips_ejtag *ejtag_info)
Definition: mips32.c:946
static const struct command_registration mips32_exec_command_handlers[]
Definition: mips32.c:2370
#define MIPS32_CONFIG3_DSPP_MASK
Definition: mips32.h:59
#define MIPS32_CONFIG3_DSPREV_SHIFT
Definition: mips32.h:61
#define MIPS32_CONFIG3_DSPP_SHIFT
Definition: mips32.h:58
#define MIPS32_NOP
Definition: mips32.h:719
#define MIPS32_C0_CAUSE
Definition: mips32.h:860
#define MIPS32_SCAN_DELAY_LEGACY_MODE
Definition: mips32.h:70
#define MIPS32_REGLIST_DSP_DSPCTL_INDEX
Definition: mips32.h:245
#define MIPS32_CORE_MASK
Definition: mips32.h:282
#define MIPS32_ISA_OR(dst, src, val)
Definition: mips32.h:561
#define MIPS32_CONFIG3_DSPREV_MASK
Definition: mips32.h:62
#define MIPS32_REGLIST_FP_INDEX
Definition: mips32.h:228
#define MIPS32_CONFIG3_CDMM_MASK
Definition: mips32.h:56
#define MIPS32_ADDI(isa, tar, src, val)
Definition: mips32.h:720
#define MIPS32_SYNC(isa)
Definition: mips32.h:772
#define MIPS32_REG_C0_PC_INDEX
Definition: mips32.h:242
#define MIPS32_CONFIG3_ISA_MASK
Definition: mips32.h:65
#define MIPS32_REGLIST_C0_STATUS_INDEX
Definition: mips32.h:233
#define MIPS32_DSP_MTLO(reg, ac)
Definition: mips32.h:799
static struct mips32_common * target_to_mips32(struct target *target)
Definition: mips32.h:444
#define MIPS32_XOR(isa, reg, val1, val2)
Definition: mips32.h:773
#define EJTAG_QUIRK_PAD_DRET
Definition: mips32.h:209
#define MIPS32_DSP_ENABLE
Definition: mips32.h:787
#define MIPS32_COMMON_MAGIC
Definition: mips32.h:21
#define MIPS32_NUM_CPU_ENTRIES
Definition: mips32.h:362
#define MIPS32_CFG1_ILSHIFT
Definition: mips32.h:814
#define MIPS32_SDBBP(isa)
Definition: mips32.h:780
#define MIPS_CP0_MK4
Definition: mips32.h:75
@ MIPS32_FP_IMP_64
Definition: mips32.h:367
@ MIPS32_FP_IMP_NONE
Definition: mips32.h:365
@ MIPS32_FP_IMP_UNKNOWN
Definition: mips32.h:368
#define MIPS32_CFG1_DASHIFT
Definition: mips32.h:822
#define MIPS32_LB(isa, reg, off, base)
Definition: mips32.h:736
#define MIPS32_CP0_STATUS_CU1_SHIFT
Definition: mips32.h:83
#define MIPS32_REG_C0_GUESTCTL1_INDEX
Definition: mips32.h:243
#define MIPS32_REGLIST_C0_CAUSE_INDEX
Definition: mips32.h:235
#define MIPS32_CONFIG0_AR_SHIFT
Definition: mips32.h:46
#define MIPS32_CONFIG1_FP_SHIFT
Definition: mips32.h:49
#define MIPS32_BNE(isa, src, tar, off)
Definition: mips32.h:729
#define MIPS32_REG_C0_CAUSE_INDEX
Definition: mips32.h:241
#define MIPS32_REG_FP_COUNT
Definition: mips32.h:222
#define MIPS_CP0_IAPTIV
Definition: mips32.h:78
#define MIPS32_BEQ(isa, src, tar, off)
Definition: mips32.h:727
#define MIPS32_CP1_FIR_F64_SHIFT
Definition: mips32.h:86
#define MIPS32_C0_DEPC
Definition: mips32.h:874
#define MIPS_CP0_MAPTIV_UP
Definition: mips32.h:77
#define MIPS32_REGLIST_DSP_INDEX
Definition: mips32.h:231
#define MIPS32_REGLIST_C0_GUESTCTL1_INDEX
Definition: mips32.h:237
#define MIPS32_CONFIG3_ISA_SHIFT
Definition: mips32.h:64
#define MIPS32_SW(isa, reg, off, base)
Definition: mips32.h:760
#define MIPS32_MOVN(isa, dst, src, tar)
Definition: mips32.h:755
#define MIPS32_REGLIST_C0_PC_INDEX
Definition: mips32.h:236
#define MIPS32_C0_STATUS
Definition: mips32.h:855
#define MIPS32_REGLIST_FPC_INDEX
Definition: mips32.h:229
#define MIPS32NUMDSPREGS
Definition: mips32.h:72
#define MIPS32_MMU_TLB
Definition: mips32.h:895
#define MIPS32_CFG1_ISSHIFT
Definition: mips32.h:812
#define MIPS32_REGLIST_GP_INDEX
Definition: mips32.h:227
#define MIPS32_ADDU(isa, dst, src, tar)
Definition: mips32.h:722
@ MMIPS32_ONLY
Definition: mips32.h:257
@ MIPS32_MMIPS32
Definition: mips32.h:259
@ MIPS32_MIPS16
Definition: mips32.h:258
@ MIPS32_ONLY
Definition: mips32.h:256
#define MIPS32_CFG1_DSSHIFT
Definition: mips32.h:818
#define MIPS32_REG_C0_STATUS_INDEX
Definition: mips32.h:239
#define MIPS32_MTC0(isa, gpr, cpr, sel)
Definition: mips32.h:744
#define MIPS32_ADDIU(isa, tar, src, val)
Definition: mips32.h:721
#define MIPS32_LUI(isa, reg, val)
Definition: mips32.h:741
#define MIPS_CP0_MAPTIV_UC
Definition: mips32.h:76
#define MIPS32_C0_GUESTCTL1
Definition: mips32.h:853
#define MIPS32_MMU_DUAL_VTLB_FTLB
Definition: mips32.h:898
#define MIPS32_CONFIG0_AR_MASK
Definition: mips32.h:47
#define MIPS32_CFG1_DLSHIFT
Definition: mips32.h:820
#define MIPS32_MMU_FIXED
Definition: mips32.h:897
#define MIPS32_AND(isa, dst, src, tar)
Definition: mips32.h:723
#define MIPS32_DSP_MFHI(reg, ac)
Definition: mips32.h:797
#define MIPS32_REGLIST_C0_BADVADDR_INDEX
Definition: mips32.h:234
#define MIPS32_DSP_MTHI(reg, ac)
Definition: mips32.h:800
mips32_isa_mode
Definition: mips32.h:249
@ MIPS32_ISA_MMIPS32
Definition: mips32.h:252
@ MIPS32_ISA_MIPS32
Definition: mips32.h:250
#define MIPS32_DSP_MFLO(reg, ac)
Definition: mips32.h:798
#define MIPS32_ORI(isa, tar, src, val)
Definition: mips32.h:756
#define MIPS32_SLL(isa, dst, src, sa)
Definition: mips32.h:764
#define MIPS32_MFC0(isa, gpr, cpr, sel)
Definition: mips32.h:743
#define MIPS32_CP0_STATUS_MX_SHIFT
Definition: mips32.h:81
#define MIPS32_CFG1_IASHIFT
Definition: mips32.h:816
mips32_isa_rel
Definition: mips32.h:267
@ MIPS32_RELEASE_1
Definition: mips32.h:268
@ MIPS32_RELEASE_6
Definition: mips32.h:270
@ MIPS32_RELEASE_2
Definition: mips32.h:269
#define MIPS32_REGLIST_C0_INDEX
Definition: mips32.h:230
static const struct mips32_cp0 mips32_cp0_regs[]
static const struct cpu_entry mips32_cpu_entry[]
#define MIPS32_B(isa, off)
Definition: mips32.h:726
#define MIPS32_MMU_BAT
Definition: mips32.h:896
#define MIPS32_SLTI(isa, tar, src, val)
Definition: mips32.h:767
#define MIPS32_CONFIG1_FP_MASK
Definition: mips32.h:50
#define MIPS32_CP0_STATUS_FR_SHIFT
Definition: mips32.h:82
#define MIPS32_DSP_WRDSP(rs, mask)
Definition: mips32.h:802
#define MIPS32NUMCP0REGS
Definition: mips32.h:206
#define MIPS32_DSP_RDDSP(rt, mask)
Definition: mips32.h:801
void pracc_queue_free(struct pracc_queue_info *ctx)
Definition: mips32_pracc.c:339
int mips32_pracc_write_regs(struct mips32_common *mips32)
Definition: mips32_pracc.c:873
int mips32_pracc_queue_exec(struct mips_ejtag *ejtag_info, struct pracc_queue_info *ctx, uint32_t *buf, bool check_last)
Definition: mips32_pracc.c:344
int mips32_pracc_read_regs(struct mips32_common *mips32)
void pracc_queue_init(struct pracc_queue_info *ctx)
Definition: mips32_pracc.c:297
int mips32_cp0_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp0_reg, uint32_t cp0_sel)
mips32_cp0_read
Definition: mips32_pracc.c:552
void pracc_add(struct pracc_queue_info *ctx, uint32_t addr, uint32_t instr)
Definition: mips32_pracc.c:307
int mips32_cp1_control_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp1_c_reg)
mips32_cp1_control_read
Definition: mips32_pracc.c:591
int mips32_cp0_write(struct mips_ejtag *ejtag_info, uint32_t val, uint32_t cp0_reg, uint32_t cp0_sel)
mips32_cp0_write
Definition: mips32_pracc.c:573
#define PRACC_UPPER_BASE_ADDR
Definition: mips32_pracc.h:25
#define PRACC_OUT_OFFSET
Definition: mips32_pracc.h:28
#define LOWER16(addr)
Definition: mips32_pracc.h:32
static void pracc_swap16_array(struct mips_ejtag *ejtag_info, uint32_t *buf, int count)
Definition: mips32_pracc.h:121
#define UPPER16(addr)
Definition: mips32_pracc.h:31
#define MIPS32_PRACC_PARAM_OUT
Definition: mips32_pracc.h:23
#define NEG16(v)
Definition: mips32_pracc.h:33
#define PRID_IMP_MASK
Definition: mips_cpu.h:28
#define PRID_COMP_MASK
Definition: mips_cpu.h:13
#define PRID_COMP_LEXRA
Definition: mips_cpu.h:19
#define PRID_COMP_MTI
Definition: mips_cpu.h:16
#define PRID_IMP_MAPTIV_UP
Definition: mips_cpu.h:31
#define PRID_COMP_ALCHEMY
Definition: mips_cpu.h:18
#define PRID_IMP_M5150
Definition: mips_cpu.h:34
#define PRID_IMP_IAPTIV_CM
Definition: mips_cpu.h:32
#define PRID_COMP_INGENIC_E1
Definition: mips_cpu.h:21
#define PRID_IMP_XBURST_REV1
Definition: mips_cpu.h:36
#define PRID_IMP_IAPTIV
Definition: mips_cpu.h:33
#define PRID_IMP_MAPTIV_UC
Definition: mips_cpu.h:30
int mips_ejtag_get_idcode(struct mips_ejtag *ejtag_info)
Definition: mips_ejtag.c:42
void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, uint32_t new_instr)
Definition: mips_ejtag.c:22
int mips_ejtag_get_impcode(struct mips_ejtag *ejtag_info)
Definition: mips_ejtag.c:50
int mips_ejtag_drscan_32(struct mips_ejtag *ejtag_info, uint32_t *data)
Definition: mips_ejtag.c:130
void ejtag_main_print_imp(struct mips_ejtag *ejtag_info)
Definition: mips_ejtag.c:335
#define EJTAG_DCR_ENTRIES
Definition: mips_ejtag.h:203
#define EJTAG_V20_IMP_NODB
Definition: mips_ejtag.h:117
#define EJTAG_VERSION_20
Definition: mips_ejtag.h:168
#define EJTAG_INST_CONTROL
Definition: mips_ejtag.h:20
#define EJTAG_V20_IMP_NOIB
Definition: mips_ejtag.h:118
#define EJTAG_DCR_FDC
Definition: mips_ejtag.h:127
#define EJTAG_DCR_IB
Definition: mips_ejtag.h:129
#define EJTAG_DCR_DB
Definition: mips_ejtag.h:128
#define EJTAG_DCR_ENM
Definition: mips_ejtag.h:126
#define EJTAG_IMP_MIPS16
Definition: mips_ejtag.h:112
static const struct dcr_feature dcr_features[]
#define EJTAG_DCR
Definition: mips_ejtag.h:125
#define EJTAG_DCR_INTE
Definition: mips_ejtag.h:130
static uint32_t bit(uint32_t value, unsigned int b)
Definition: opcodes.h:39
struct reg * register_get_by_name(struct reg_cache *first, const char *name, bool search_all)
Definition: register.c:50
struct reg_cache ** register_get_last_cache_p(struct reg_cache **first)
Definition: register.c:72
reg_type
Definition: register.h:19
@ REG_TYPE_INT
Definition: register.h:21
@ REG_TYPE_IEEE_DOUBLE
Definition: register.h:37
@ REG_TYPE_IEEE_SINGLE
Definition: register.h:36
struct target * target
Definition: rtt/rtt.c:26
#define BIT(nr)
Definition: stm32l4x.h:18
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:239
Definition: mips32.h:293
const char * vendor
Definition: mips32.h:296
const char * cpu_name
Definition: mips32.h:297
uint32_t prid
Definition: mips32.h:294
Definition: jtag.h:101
enum mips32_isa_mode isa_mode
Definition: mips32.h:457
unsigned int common_magic
Definition: mips32.h:456
int bp_scanned
Definition: mips32.h:430
enum mips32_dsp_imp dsp_imp
Definition: mips32.h:404
enum mips32_fp_imp fp_imp
Definition: mips32.h:403
int(* write_core_reg)(struct target *target, unsigned int num)
Definition: mips32.h:440
int semihosting
Definition: mips32.h:407
unsigned int common_magic
Definition: mips32.h:392
uint32_t cpu_quirks
Definition: mips32.h:425
int num_data_bpoints
Definition: mips32.h:432
bool fpu_in_64bit
Definition: mips32.h:418
struct mips32_comparator * data_break_list
Definition: mips32.h:436
struct mips32_comparator * inst_break_list
Definition: mips32.h:435
struct mips_ejtag ejtag_info
Definition: mips32.h:396
struct working_area * fast_data_area
Definition: mips32.h:428
struct mips32_core_regs core_regs
Definition: mips32.h:398
int num_data_bpoints_avail
Definition: mips32.h:434
int num_inst_bpoints
Definition: mips32.h:431
uint32_t prid
Definition: mips32.h:421
bool fpu_enabled
Definition: mips32.h:416
uint32_t cp0_mask
Definition: mips32.h:413
int(* read_core_reg)(struct target *target, unsigned int num)
Definition: mips32.h:439
enum mips32_isa_imp isa_imp
Definition: mips32.h:401
enum mips32_isa_mode isa_mode
Definition: mips32.h:400
enum mips32_isa_rel isa_rel
Definition: mips32.h:402
struct reg_cache * core_cache
Definition: mips32.h:395
int num_inst_bpoints_avail
Definition: mips32.h:433
const struct cpu_entry * cpu_info
Definition: mips32.h:423
uint32_t reg_address
Definition: mips32.h:380
struct target * target
Definition: mips32.h:451
struct mips32_common * mips32_common
Definition: mips32.h:452
uint32_t num
Definition: mips32.h:450
uint64_t fpr[MIPS32_REG_FP_COUNT]
Definition: mips32.h:385
uint32_t gpr[MIPS32_REG_GP_COUNT]
Definition: mips32.h:384
uint32_t cp0[MIPS32_REG_C0_COUNT]
Definition: mips32.h:387
uint32_t dsp[MIPS32_REG_DSP_COUNT]
Definition: mips32.h:388
uint32_t fpcr[MIPS32_REG_FPC_COUNT]
Definition: mips32.h:386
unsigned int sel
Definition: mips32.h:90
unsigned int reg
Definition: mips32.h:89
const unsigned int core
Definition: mips32.h:92
uint32_t prid
Definition: mips_ejtag.h:209
uint32_t ejtag_ctrl
Definition: mips_ejtag.h:210
unsigned int scan_delay
Definition: mips_ejtag.h:217
uint32_t idcode
Definition: mips_ejtag.h:208
uint32_t reg9
Definition: mips_ejtag.h:216
uint32_t config[4]
Definition: mips_ejtag.h:213
unsigned int ejtag_version
Definition: mips_ejtag.h:221
uint32_t impcode
Definition: mips_ejtag.h:207
uint32_t ejtag_iba0_addr
Definition: mips_ejtag.h:229
uint32_t ejtag_iba_step_size
Definition: mips_ejtag.h:241
uint32_t endianness
Definition: mips_ejtag.h:223
struct jtag_tap * tap
Definition: mips_ejtag.h:206
uint32_t ejtag_dba_step_size
Definition: mips_ejtag.h:242
uint32_t reg8
Definition: mips_ejtag.h:215
uint32_t ejtag_ibs_addr
Definition: mips_ejtag.h:228
uint32_t config_regs
Definition: mips_ejtag.h:212
uint32_t ejtag_dbs_addr
Definition: mips_ejtag.h:234
uint32_t ejtag_dba0_addr
Definition: mips_ejtag.h:235
uint32_t debug_caps
Definition: mips_ejtag.h:227
uint32_t isa
Definition: mips_ejtag.h:222
struct pa_list * pracc_list
Definition: mips32_pracc.h:53
unsigned int isa
Definition: mips32_pracc.h:48
struct mips_ejtag * ejtag_info
Definition: mips32_pracc.h:47
int(* get)(struct reg *reg)
Definition: register.h:152
const char * name
Definition: register.h:145
unsigned int num_regs
Definition: register.h:148
struct reg * reg_list
Definition: register.h:147
struct reg_cache * next
Definition: register.h:146
enum reg_type type
Definition: register.h:100
uint32_t size
Definition: algorithm.h:29
const char * reg_name
Definition: algorithm.h:28
Definition: register.h:111
bool caller_save
Definition: register.h:119
bool valid
Definition: register.h:126
bool exist
Definition: register.h:128
uint32_t size
Definition: register.h:132
const char * group
Definition: register.h:138
uint8_t * value
Definition: register.h:122
struct reg_feature * feature
Definition: register.h:117
struct reg_data_type * reg_data_type
Definition: register.h:135
uint32_t number
Definition: register.h:115
void * arch_info
Definition: register.h:140
bool dirty
Definition: register.h:124
const struct reg_arch_type * type
Definition: register.h:141
const char * name
Definition: register.h:113
Definition: target.h:119
enum target_state state
Definition: target.h:167
enum target_endianness endianness
Definition: target.h:165
struct reg_cache * reg_cache
Definition: target.h:168
void * arch_info
Definition: target.h:174
Definition: psoc6.c:83
target_addr_t address
Definition: target.h:89
int target_halt(struct target *target)
Definition: target.c:516
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2368
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: target.c:2433
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
Definition: target.c:786
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
Definition: target.c:2087
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2634
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
Definition: target.c:2145
int target_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
Definition: target.c:565
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2560
const char * debug_reason_name(const struct target *t)
Definition: target.c:256
int target_wait_state(struct target *target, enum target_state state, unsigned int ms)
Definition: target.c:3173
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:467
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
Definition: target.c:426
target_register_class
Definition: target.h:113
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:814
static bool target_was_examined(const struct target *target)
Definition: target.h:440
#define ERROR_TARGET_INVALID
Definition: target.h:811
@ TARGET_HALTED
Definition: target.h:58
@ TARGET_BIG_ENDIAN
Definition: target.h:85
@ TARGET_LITTLE_ENDIAN
Definition: target.h:85
#define ERROR_TARGET_TIMEOUT
Definition: target.h:813
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:818
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
uint64_t target_addr_t
Definition: types.h:279
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t count[4]
Definition: vdebug.c:22