OpenOCD
mips32_pracc.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) 2009 by David N. Claffey <dnclaffey@gmail.com> *
10  * *
11  * Copyright (C) 2011 by Drasko DRASKOVIC *
12  * drasko.draskovic@gmail.com *
13  ***************************************************************************/
14 
15 /*
16  * This version has optimized assembly routines for 32 bit operations:
17  * - read word
18  * - write word
19  * - write array of words
20  *
21  * One thing to be aware of is that the MIPS32 cpu will execute the
22  * instruction after a branch instruction (one delay slot).
23  *
24  * For example:
25  * LW $2, ($5 +10)
26  * B foo
27  * LW $1, ($2 +100)
28  *
29  * The LW $1, ($2 +100) instruction is also executed. If this is
30  * not wanted a NOP can be inserted:
31  *
32  * LW $2, ($5 +10)
33  * B foo
34  * NOP
35  * LW $1, ($2 +100)
36  *
37  * or the code can be changed to:
38  *
39  * B foo
40  * LW $2, ($5 +10)
41  * LW $1, ($2 +100)
42  *
43  * The original code contained NOPs. I have removed these and moved
44  * the branches.
45  *
46  * These changes result in a 35% speed increase when programming an
47  * external flash.
48  *
49  * More improvement could be gained if the registers do no need
50  * to be preserved but in that case the routines should be aware
51  * OpenOCD is used as a flash programmer or as a debug tool.
52  *
53  * Nico Coesel
54  */
55 
56 #ifdef HAVE_CONFIG_H
57 #include "config.h"
58 #endif
59 
60 #include <helper/align.h>
61 #include <helper/time_support.h>
62 #include <jtag/adapter.h>
63 
64 #include "mips_cpu.h"
65 #include "mips32.h"
66 #include "mips32_pracc.h"
67 
68 static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info)
69 {
70  int64_t then = timeval_ms();
71 
72  /* wait for the PrAcc to become "1" */
74 
75  while (1) {
76  ejtag_info->pa_ctrl = ejtag_info->ejtag_ctrl;
77  int retval = mips_ejtag_drscan_32(ejtag_info, &ejtag_info->pa_ctrl);
78  if (retval != ERROR_OK)
79  return retval;
80 
81  if (ejtag_info->pa_ctrl & EJTAG_CTRL_PRACC)
82  break;
83 
84  int64_t timeout = timeval_ms() - then;
85  if (timeout > 1000) {
86  LOG_DEBUG("DEBUGMODULE: No memory access in progress!");
88  }
89  }
90 
91  return ERROR_OK;
92 }
93 
94 /* Shift in control and address for a new processor access, save them in ejtag_info */
95 static int mips32_pracc_read_ctrl_addr(struct mips_ejtag *ejtag_info)
96 {
97  int retval = wait_for_pracc_rw(ejtag_info);
98  if (retval != ERROR_OK)
99  return retval;
100 
102 
103  ejtag_info->pa_addr = 0;
104  return mips_ejtag_drscan_32(ejtag_info, &ejtag_info->pa_addr);
105 }
106 
107 /* Finish processor access */
108 static void mips32_pracc_finish(struct mips_ejtag *ejtag_info)
109 {
110  uint32_t ctrl = ejtag_info->ejtag_ctrl & ~EJTAG_CTRL_PRACC;
112  mips_ejtag_drscan_32_out(ejtag_info, ctrl);
113 }
114 
115 static int mips32_pracc_clean_text_jump(struct mips_ejtag *ejtag_info)
116 {
117  uint32_t jt_code = MIPS32_J(ejtag_info->isa, MIPS32_PRACC_TEXT);
118  pracc_swap16_array(ejtag_info, &jt_code, 1);
119  /* do 3 0/nops to clean pipeline before a jump to pracc text, NOP in delay slot */
120  for (int i = 0; i != 5; i++) {
121  /* Wait for pracc */
122  int retval = wait_for_pracc_rw(ejtag_info);
123  if (retval != ERROR_OK)
124  return retval;
125 
126  /* Data or instruction out */
128  uint32_t data = (i == 3) ? jt_code : MIPS32_NOP;
129  mips_ejtag_drscan_32_out(ejtag_info, data);
130 
131  /* finish pa */
132  mips32_pracc_finish(ejtag_info);
133  }
134 
135  if (ejtag_info->mode != 0) /* async mode support only for MIPS ... */
136  return ERROR_OK;
137 
138  for (int i = 0; i != 2; i++) {
139  int retval = mips32_pracc_read_ctrl_addr(ejtag_info);
140  if (retval != ERROR_OK)
141  return retval;
142 
143  if (ejtag_info->pa_addr != MIPS32_PRACC_TEXT) { /* LEXRA/BMIPS ?, shift out another NOP, max 2 */
146  mips32_pracc_finish(ejtag_info);
147  } else
148  break;
149  }
150 
151  return ERROR_OK;
152 }
153 
154 static int mips32_pracc_exec(struct mips_ejtag *ejtag_info, struct pracc_queue_info *ctx,
155  uint32_t *param_out, bool check_last)
156 {
157  int code_count = 0;
158  int store_pending = 0; /* increases with every store instr at dmseg, decreases with every store pa */
159  uint32_t max_store_addr = 0; /* for store pa address testing */
160  bool restart = 0; /* restarting control */
161  int restart_count = 0;
162  uint32_t instr = 0;
163  bool final_check = 0; /* set to 1 if in final checks after function code shifted out */
164  bool pass = 0; /* to check the pass through pracc text after function code sent */
165  int retval;
166 
167  while (1) {
168  if (restart) {
169  if (restart_count < 3) { /* max 3 restarts allowed */
170  retval = mips32_pracc_clean_text_jump(ejtag_info);
171  if (retval != ERROR_OK)
172  return retval;
173  } else
175  restart_count++;
176  restart = 0;
177  code_count = 0;
178  LOG_DEBUG("restarting code");
179  }
180 
181  retval = mips32_pracc_read_ctrl_addr(ejtag_info); /* update current pa info: control and address */
182  if (retval != ERROR_OK)
183  return retval;
184 
185  /* Check for read or write access */
186  if (ejtag_info->pa_ctrl & EJTAG_CTRL_PRNW) { /* write/store access */
187  /* Check for pending store from a previous store instruction at dmseg */
188  if (store_pending == 0) {
189  LOG_DEBUG("unexpected write at address %" PRIx32, ejtag_info->pa_addr);
190  if (code_count < 2) { /* allow for restart */
191  restart = 1;
192  continue;
193  } else
195  } else {
196  /* check address */
197  if (ejtag_info->pa_addr < MIPS32_PRACC_PARAM_OUT ||
198  ejtag_info->pa_addr > max_store_addr) {
199  LOG_DEBUG("writing at unexpected address %" PRIx32, ejtag_info->pa_addr);
201  }
202  }
203  /* read data */
204  uint32_t data = 0;
206  retval = mips_ejtag_drscan_32(ejtag_info, &data);
207  if (retval != ERROR_OK)
208  return retval;
209 
210  /* store data at param out, address based offset */
211  param_out[(ejtag_info->pa_addr - MIPS32_PRACC_PARAM_OUT) / 4] = data;
212  store_pending--;
213 
214  } else { /* read/fetch access */
215  if (!final_check) { /* executing function code */
216  /* check address */
217  if (ejtag_info->pa_addr != (MIPS32_PRACC_TEXT + code_count * 4)) {
218  LOG_DEBUG("reading at unexpected address %" PRIx32 ", expected %x",
219  ejtag_info->pa_addr, MIPS32_PRACC_TEXT + code_count * 4);
220 
221  /* restart code execution only in some cases */
222  if (code_count == 1 && ejtag_info->pa_addr == MIPS32_PRACC_TEXT &&
223  restart_count == 0) {
224  LOG_DEBUG("restarting, without clean jump");
225  restart_count++;
226  code_count = 0;
227  continue;
228  } else if (code_count < 2) {
229  restart = 1;
230  continue;
231  }
233  }
234  /* check for store instruction at dmseg */
235  uint32_t store_addr = ctx->pracc_list[code_count].addr;
236  if (store_addr != 0) {
237  if (store_addr > max_store_addr)
238  max_store_addr = store_addr;
239  store_pending++;
240  }
241 
242  instr = ctx->pracc_list[code_count++].instr;
243  if (code_count == ctx->code_count) /* last instruction, start final check */
244  final_check = 1;
245 
246  } else { /* final check after function code shifted out */
247  /* check address */
248  if (ejtag_info->pa_addr == MIPS32_PRACC_TEXT) {
249  if (!pass) { /* first pass through pracc text */
250  if (store_pending == 0) /* done, normal exit */
251  return ERROR_OK;
252  pass = 1; /* pracc text passed */
253  code_count = 0; /* restart code count */
254  } else {
255  LOG_DEBUG("unexpected second pass through pracc text");
257  }
258  } else {
259  if (ejtag_info->pa_addr != (MIPS32_PRACC_TEXT + code_count * 4)) {
260  LOG_DEBUG("unexpected read address in final check: %"
261  PRIx32 ", expected: %x", ejtag_info->pa_addr,
262  MIPS32_PRACC_TEXT + code_count * 4);
264  }
265  }
266  if (!pass) {
267  if ((code_count - ctx->code_count) > 1) { /* allow max 2 instr delay slot */
268  LOG_DEBUG("failed to jump back to pracc text");
270  }
271  } else
272  if (code_count > 10) { /* enough, abandon */
273  LOG_DEBUG("execution abandoned, store pending: %d", store_pending);
275  }
276  instr = MIPS32_NOP; /* shift out NOPs instructions */
277  code_count++;
278  }
279 
280  /* Send instruction out */
282  mips_ejtag_drscan_32_out(ejtag_info, instr);
283  }
284  /* finish processor access, let the processor eat! */
285  mips32_pracc_finish(ejtag_info);
286 
287  if (final_check && !check_last) /* last instr, don't check, execute and exit */
288  return jtag_execute_queue();
289 
290  if (store_pending == 0 && pass) { /* store access done, but after passing pracc text */
291  LOG_DEBUG("warning: store access pass pracc text");
292  return ERROR_OK;
293  }
294  }
295 }
296 
297 inline void pracc_queue_init(struct pracc_queue_info *ctx)
298 {
299  ctx->retval = ERROR_OK;
300  ctx->code_count = 0;
301  ctx->store_count = 0;
302  ctx->max_code = 0;
303  ctx->pracc_list = NULL;
304  ctx->isa = ctx->ejtag_info->isa ? 1 : 0;
305 }
306 
307 void pracc_add(struct pracc_queue_info *ctx, uint32_t addr, uint32_t instr)
308 {
309  if (ctx->retval != ERROR_OK) /* On previous out of memory, return */
310  return;
311  if (ctx->code_count == ctx->max_code) {
312  void *p = realloc(ctx->pracc_list, sizeof(struct pa_list) * (ctx->max_code + PRACC_BLOCK));
313  if (p) {
314  ctx->max_code += PRACC_BLOCK;
315  ctx->pracc_list = p;
316  } else {
317  ctx->retval = ERROR_FAIL; /* Out of memory */
318  return;
319  }
320  }
321  ctx->pracc_list[ctx->code_count].instr = instr;
322  ctx->pracc_list[ctx->code_count++].addr = addr;
323  if (addr)
324  ctx->store_count++;
325 }
326 
327 static void pracc_add_li32(struct pracc_queue_info *ctx, uint32_t reg_num, uint32_t data, bool optimize)
328 {
329  if (LOWER16(data) == 0 && optimize)
330  pracc_add(ctx, 0, MIPS32_LUI(ctx->isa, reg_num, UPPER16(data))); /* load only upper value */
331  else if (UPPER16(data) == 0 && optimize)
332  pracc_add(ctx, 0, MIPS32_ORI(ctx->isa, reg_num, 0, LOWER16(data))); /* load only lower */
333  else {
334  pracc_add(ctx, 0, MIPS32_LUI(ctx->isa, reg_num, UPPER16(data))); /* load upper and lower */
335  pracc_add(ctx, 0, MIPS32_ORI(ctx->isa, reg_num, reg_num, LOWER16(data)));
336  }
337 }
338 
339 inline void pracc_queue_free(struct pracc_queue_info *ctx)
340 {
341  free(ctx->pracc_list);
342 }
343 
344 int mips32_pracc_queue_exec(struct mips_ejtag *ejtag_info, struct pracc_queue_info *ctx,
345  uint32_t *buf, bool check_last)
346 {
347  if (ctx->retval != ERROR_OK) {
348  LOG_ERROR("Out of memory");
349  return ERROR_FAIL;
350  }
351 
352  if (ejtag_info->isa && ejtag_info->endianness)
353  for (int i = 0; i != ctx->code_count; i++)
354  ctx->pracc_list[i].instr = SWAP16(ctx->pracc_list[i].instr);
355 
356  if (ejtag_info->mode == 0)
357  return mips32_pracc_exec(ejtag_info, ctx, buf, check_last);
358 
359  union scan_in {
360  uint8_t scan_96[12];
361  struct {
362  uint8_t ctrl[4];
363  uint8_t data[4];
364  uint8_t addr[4];
365  } scan_32;
366 
367  } *scan_in = malloc(sizeof(union scan_in) * (ctx->code_count + ctx->store_count));
368  if (!scan_in) {
369  LOG_ERROR("Out of memory");
370  return ERROR_FAIL;
371  }
372 
373  unsigned int num_clocks =
374  ((uint64_t)(ejtag_info->scan_delay) * adapter_get_speed_khz() + 500000) / 1000000;
375 
376  uint32_t ejtag_ctrl = ejtag_info->ejtag_ctrl & ~EJTAG_CTRL_PRACC;
378 
379  int scan_count = 0;
380  for (int i = 0; i != ctx->code_count; i++) {
381  jtag_add_clocks(num_clocks);
382  mips_ejtag_add_scan_96(ejtag_info, ejtag_ctrl, ctx->pracc_list[i].instr,
383  scan_in[scan_count++].scan_96);
384 
385  /* Check store address from previous instruction, if not the first */
386  if (i > 0 && ctx->pracc_list[i - 1].addr) {
387  jtag_add_clocks(num_clocks);
388  mips_ejtag_add_scan_96(ejtag_info, ejtag_ctrl, 0, scan_in[scan_count++].scan_96);
389  }
390  }
391 
392  int retval = jtag_execute_queue(); /* execute queued scans */
393  if (retval != ERROR_OK)
394  goto exit;
395 
396  uint32_t fetch_addr = MIPS32_PRACC_TEXT; /* start address */
397  scan_count = 0;
398  for (int i = 0; i != ctx->code_count; i++) { /* verify every pracc access */
399  /* check pracc bit */
400  ejtag_ctrl = buf_get_u32(scan_in[scan_count].scan_32.ctrl, 0, 32);
401  uint32_t addr = buf_get_u32(scan_in[scan_count].scan_32.addr, 0, 32);
402  if (!(ejtag_ctrl & EJTAG_CTRL_PRACC)) {
403  LOG_ERROR("Error: access not pending count: %d", scan_count);
404  retval = ERROR_FAIL;
405  goto exit;
406  }
407  if (ejtag_ctrl & EJTAG_CTRL_PRNW) {
408  LOG_ERROR("Not a fetch/read access, count: %d", scan_count);
409  retval = ERROR_FAIL;
410  goto exit;
411  }
412  if (addr != fetch_addr) {
413  LOG_ERROR("Fetch addr mismatch, read: %" PRIx32 " expected: %" PRIx32 " count: %d",
414  addr, fetch_addr, scan_count);
415  retval = ERROR_FAIL;
416  goto exit;
417  }
418  fetch_addr += 4;
419  scan_count++;
420 
421  /* check if previous instruction is a store instruction at dmesg */
422  if (i > 0 && ctx->pracc_list[i - 1].addr) {
423  uint32_t store_addr = ctx->pracc_list[i - 1].addr;
424  ejtag_ctrl = buf_get_u32(scan_in[scan_count].scan_32.ctrl, 0, 32);
425  addr = buf_get_u32(scan_in[scan_count].scan_32.addr, 0, 32);
426 
427  if (!(ejtag_ctrl & EJTAG_CTRL_PRNW)) {
428  LOG_ERROR("Not a store/write access, count: %d", scan_count);
429  retval = ERROR_FAIL;
430  goto exit;
431  }
432  if (addr != store_addr) {
433  LOG_ERROR("Store address mismatch, read: %" PRIx32 " expected: %" PRIx32 " count: %d",
434  addr, store_addr, scan_count);
435  retval = ERROR_FAIL;
436  goto exit;
437  }
438  int buf_index = (addr - MIPS32_PRACC_PARAM_OUT) / 4;
439  buf[buf_index] = buf_get_u32(scan_in[scan_count].scan_32.data, 0, 32);
440  scan_count++;
441  }
442  }
443 exit:
444  free(scan_in);
445  return retval;
446 }
447 
448 static int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t *buf)
449 {
450  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
451  pracc_queue_init(&ctx);
452 
453  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, PRACC_UPPER_BASE_ADDR)); /* $15 = MIPS32_PRACC_BASE_ADDR */
454  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 8, UPPER16((addr + 0x8000)))); /* load $8 with modified upper addr */
455  pracc_add(&ctx, 0, MIPS32_LW(ctx.isa, 8, LOWER16(addr), 8)); /* lw $8, LOWER16(addr)($8) */
457  pracc_add(&ctx, 0, MIPS32_SYNC(ctx.isa));
459  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET, 15)); /* sw $8,PRACC_OUT_OFFSET($15) */
460  pracc_add_li32(&ctx, 8, ejtag_info->reg8, 0); /* restore $8 */
461  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
462  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* move COP0 DeSave to $15 */
463 
464  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, buf, 1);
465  pracc_queue_free(&ctx);
466  return ctx.retval;
467 }
468 
469 int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf)
470 {
471  if (count == 1 && size == 4)
472  return mips32_pracc_read_u32(ejtag_info, addr, (uint32_t *)buf);
473 
474  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
475  pracc_queue_init(&ctx);
476 
477  uint32_t *data = NULL;
478  if (size != 4) {
479  data = malloc(256 * sizeof(uint32_t));
480  if (!data) {
481  LOG_ERROR("Out of memory");
482  goto exit;
483  }
484  }
485 
486  uint32_t *buf32 = buf;
487  uint16_t *buf16 = buf;
488  uint8_t *buf8 = buf;
489 
490  while (count) {
491  ctx.code_count = 0;
492  ctx.store_count = 0;
493 
494  int this_round_count = (count > 256) ? 256 : count;
495  uint32_t last_upper_base_addr = UPPER16((addr + 0x8000));
496 
497  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, PRACC_UPPER_BASE_ADDR)); /* $15 = MIPS32_PRACC_BASE_ADDR */
498  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 9, last_upper_base_addr)); /* upper memory addr to $9 */
499 
500  for (int i = 0; i != this_round_count; i++) { /* Main code loop */
501  uint32_t upper_base_addr = UPPER16((addr + 0x8000));
502  if (last_upper_base_addr != upper_base_addr) { /* if needed, change upper addr in $9 */
503  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 9, upper_base_addr));
504  last_upper_base_addr = upper_base_addr;
505  }
506 
507  if (size == 4) /* load from memory to $8 */
508  pracc_add(&ctx, 0, MIPS32_LW(ctx.isa, 8, LOWER16(addr), 9));
509  else if (size == 2)
510  pracc_add(&ctx, 0, MIPS32_LHU(ctx.isa, 8, LOWER16(addr), 9));
511  else
512  pracc_add(&ctx, 0, MIPS32_LBU(ctx.isa, 8, LOWER16(addr), 9));
513 
515  pracc_add(&ctx, 0, MIPS32_SYNC(ctx.isa));
516  pracc_add(&ctx, MIPS32_PRACC_PARAM_OUT + i * 4, /* store $8 at param out */
517  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET + i * 4, 15));
518  addr += size;
519  }
520  pracc_add_li32(&ctx, 8, ejtag_info->reg8, 0); /* restore $8 */
521  pracc_add_li32(&ctx, 9, ejtag_info->reg9, 0); /* restore $9 */
522 
523  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
524  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* restore $15 from DeSave */
525 
526  if (size == 4) {
527  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, buf32, 1);
528  if (ctx.retval != ERROR_OK)
529  goto exit;
530  buf32 += this_round_count;
531  } else {
532  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, data, 1);
533  if (ctx.retval != ERROR_OK)
534  goto exit;
535 
536  uint32_t *data_p = data;
537  for (int i = 0; i != this_round_count; i++) {
538  if (size == 2)
539  *buf16++ = *data_p++;
540  else
541  *buf8++ = *data_p++;
542  }
543  }
544  count -= this_round_count;
545  }
546 exit:
547  pracc_queue_free(&ctx);
548  free(data);
549  return ctx.retval;
550 }
551 
552 int mips32_cp0_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp0_reg, uint32_t cp0_sel)
553 {
554  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
555  pracc_queue_init(&ctx);
556 
557  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, PRACC_UPPER_BASE_ADDR)); /* $15 = MIPS32_PRACC_BASE_ADDR */
559  pracc_add(&ctx, 0, MIPS32_EHB(ctx.isa));
560  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 8, cp0_reg, cp0_sel)); /* move cp0 reg / sel to $8 */
562  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET, 15)); /* store $8 to pracc_out */
563  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* restore $15 from DeSave */
564  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 8, UPPER16(ejtag_info->reg8))); /* restore upper 16 bits of $8 */
565  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
566  pracc_add(&ctx, 0, MIPS32_ORI(ctx.isa, 8, 8, LOWER16(ejtag_info->reg8))); /* restore lower 16 bits of $8 */
567 
568  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, val, 1);
569  pracc_queue_free(&ctx);
570  return ctx.retval;
571 }
572 
573 int mips32_cp0_write(struct mips_ejtag *ejtag_info, uint32_t val, uint32_t cp0_reg, uint32_t cp0_sel)
574 {
575  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
576  pracc_queue_init(&ctx);
577 
578  pracc_add_li32(&ctx, 15, val, 0); /* Load val to $15 */
579 
580  pracc_add(&ctx, 0, MIPS32_MTC0(ctx.isa, 15, cp0_reg, cp0_sel)); /* write $15 to cp0 reg / sel */
582  pracc_add(&ctx, 0, MIPS32_EHB(ctx.isa));
583  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
584  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* restore $15 from DeSave */
585 
587  pracc_queue_free(&ctx);
588  return ctx.retval;
589 }
590 
591 int mips32_cp1_control_read(struct mips_ejtag *ejtag_info, uint32_t *val, uint32_t cp1_c_reg)
592 {
593  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
594  pracc_queue_init(&ctx);
595 
596  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, PRACC_UPPER_BASE_ADDR)); /* $15 = MIPS32_PRACC_BASE_ADDR */
597  pracc_add(&ctx, 0, MIPS32_EHB(ctx.isa));
598  pracc_add(&ctx, 0, MIPS32_CFC1(ctx.isa, 8, cp1_c_reg)); /* move cp1c reg to $8 */
600  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET, 15)); /* store $8 to pracc_out */
601  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* restore $15 from DeSave */
602  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 8, UPPER16(ejtag_info->reg8))); /* restore upper 16 bits of $8 */
603  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
604  pracc_add(&ctx, 0, MIPS32_ORI(ctx.isa, 8, 8, LOWER16(ejtag_info->reg8))); /* restore lower 16 bits of $8 */
605 
606  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, val, 1);
607  pracc_queue_free(&ctx);
608  return ctx.retval;
609 }
610 
639  uint32_t start_addr, uint32_t end_addr, int cached, int rel)
640 {
641  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
642  pracc_queue_init(&ctx);
643 
645  uint32_t clsiz;
646  if (rel) { /* Release 2 (rel = 1) */
647  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, PRACC_UPPER_BASE_ADDR)); /* $15 = MIPS32_PRACC_BASE_ADDR */
648 
649  pracc_add(&ctx, 0, MIPS32_RDHWR(ctx.isa, 8, MIPS32_SYNCI_STEP)); /* load synci_step value to $8 */
650 
652  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET, 15)); /* store $8 to pracc_out */
653 
654  pracc_add_li32(&ctx, 8, ejtag_info->reg8, 0); /* restore $8 */
655 
656  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
657  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* restore $15 from DeSave */
658 
659  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, &clsiz, 1);
660  if (ctx.retval != ERROR_OK)
661  goto exit;
662 
663  } else { /* Release 1 (rel = 0) */
664  uint32_t conf;
665  ctx.retval = mips32_cp0_read(ejtag_info, &conf, 16, 1);
666  if (ctx.retval != ERROR_OK)
667  goto exit;
668 
669  uint32_t dl = (conf & MIPS32_CONFIG1_DL_MASK) >> MIPS32_CONFIG1_DL_SHIFT;
670 
671  /* dl encoding : dl=1 => 4 bytes, dl=2 => 8 bytes, etc... max dl=6 => 128 bytes cache line size */
672  clsiz = 0x2 << dl;
673  if (dl == 0)
674  clsiz = 0;
675  }
676 
677  if (clsiz == 0)
678  goto exit; /* Nothing to do */
679 
680  /* make sure clsiz is power of 2 */
681  if (!IS_PWR_OF_2(clsiz)) {
682  LOG_DEBUG("clsiz must be power of 2");
683  ctx.retval = ERROR_FAIL;
684  goto exit;
685  }
686 
687  /* make sure start_addr and end_addr have the same offset inside de cache line */
688  start_addr |= clsiz - 1;
689  end_addr |= clsiz - 1;
690 
691  ctx.code_count = 0;
692  ctx.store_count = 0;
693 
694  int count = 0;
695  uint32_t last_upper_base_addr = UPPER16((start_addr + 0x8000));
696 
697  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, last_upper_base_addr)); /* load upper memory base addr to $15 */
698 
699  while (start_addr <= end_addr) { /* main loop */
700  uint32_t upper_base_addr = UPPER16((start_addr + 0x8000));
701  if (last_upper_base_addr != upper_base_addr) { /* if needed, change upper addr in $15 */
702  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, upper_base_addr));
703  last_upper_base_addr = upper_base_addr;
704  }
705  if (rel) /* synci instruction, offset($15) */
706  pracc_add(&ctx, 0, MIPS32_SYNCI(ctx.isa, LOWER16(start_addr), 15));
707 
708  else {
709  if (cached == 3) /* cache Hit_Writeback_D, offset($15) */
711  LOWER16(start_addr), 15));
712  /* cache Hit_Invalidate_I, offset($15) */
714  LOWER16(start_addr), 15));
715  }
716  start_addr += clsiz;
717  count++;
718  if (count == 256 && start_addr <= end_addr) { /* more ?, then execute code list */
719  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* to start */
720  pracc_add(&ctx, 0, MIPS32_NOP); /* nop in delay slot */
721 
723  if (ctx.retval != ERROR_OK)
724  goto exit;
725 
726  ctx.code_count = 0; /* reset counters for another loop */
727  ctx.store_count = 0;
728  count = 0;
729  }
730  }
731  pracc_add(&ctx, 0, MIPS32_SYNC(ctx.isa));
732  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
733  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* restore $15 from DeSave*/
734 
736 exit:
737  pracc_queue_free(&ctx);
738  return ctx.retval;
739 }
740 
742  uint32_t addr, int size, int count, const void *buf)
743 {
744  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
745  pracc_queue_init(&ctx);
746 
747  const uint32_t *buf32 = buf;
748  const uint16_t *buf16 = buf;
749  const uint8_t *buf8 = buf;
750 
751  while (count) {
752  ctx.code_count = 0;
753  ctx.store_count = 0;
754 
755  int this_round_count = (count > 128) ? 128 : count;
756  uint32_t last_upper_base_addr = UPPER16((addr + 0x8000));
757  /* load $15 with memory base address */
758  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, last_upper_base_addr));
759 
760  for (int i = 0; i != this_round_count; i++) {
761  uint32_t upper_base_addr = UPPER16((addr + 0x8000));
762  if (last_upper_base_addr != upper_base_addr) { /* if needed, change upper address in $15*/
763  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 15, upper_base_addr));
764  last_upper_base_addr = upper_base_addr;
765  }
766 
767  if (size == 4) {
768  pracc_add_li32(&ctx, 8, *buf32, 1); /* load with li32, optimize */
769  pracc_add(&ctx, 0, MIPS32_SW(ctx.isa, 8, LOWER16(addr), 15)); /* store word to mem */
770  buf32++;
771 
772  } else if (size == 2) {
773  pracc_add(&ctx, 0, MIPS32_ORI(ctx.isa, 8, 0, *buf16)); /* load lower value */
774  pracc_add(&ctx, 0, MIPS32_SH(ctx.isa, 8, LOWER16(addr), 15)); /* store half word */
775  buf16++;
776 
777  } else {
778  pracc_add(&ctx, 0, MIPS32_ORI(ctx.isa, 8, 0, *buf8)); /* load lower value */
779  pracc_add(&ctx, 0, MIPS32_SB(ctx.isa, 8, LOWER16(addr), 15)); /* store byte */
780  buf8++;
781  }
782  addr += size;
783  }
784 
785  pracc_add_li32(&ctx, 8, ejtag_info->reg8, 0); /* restore $8 */
786 
787  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
788  pracc_add(&ctx, 0, MIPS32_MFC0(ctx.isa, 15, 31, 0)); /* restore $15 from DeSave */
789 
791  if (ctx.retval != ERROR_OK)
792  goto exit;
793  count -= this_round_count;
794  }
795 exit:
796  pracc_queue_free(&ctx);
797  return ctx.retval;
798 }
799 
800 int mips32_pracc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf)
801 {
803  if (retval != ERROR_OK)
804  return retval;
805 
812  uint32_t conf = 0;
813  int cached = 0;
814 
815  if ((KSEGX(addr) == KSEG1) || ((addr >= 0xff200000) && (addr <= 0xff3fffff)))
816  return retval; /*Nothing to do*/
817 
818  /* Reads Config0 */
819  mips32_cp0_read(ejtag_info, &conf, 16, 0);
820 
821  switch (KSEGX(addr)) {
822  case KUSEG:
823  cached = (conf & MIPS32_CONFIG0_KU_MASK) >> MIPS32_CONFIG0_KU_SHIFT;
824  break;
825  case KSEG0:
826  cached = (conf & MIPS32_CONFIG0_K0_MASK) >> MIPS32_CONFIG0_K0_SHIFT;
827  break;
828  case KSEG2:
829  case KSEG3:
831  break;
832  default:
833  /* what ? */
834  break;
835  }
836 
842  if (cached == 3 || cached == 0) { /* Write back cache or write through cache */
843  uint32_t start_addr = addr;
844  uint32_t end_addr = addr + count * size;
845  uint32_t rel = (conf & MIPS32_CONFIG0_AR_MASK) >> MIPS32_CONFIG0_AR_SHIFT;
846  /* FIXME: In MIPS Release 6, the encoding of CACHE instr has changed */
847  if (rel > MIPS32_RELEASE_2) {
848  LOG_DEBUG("Unsupported MIPS Release ( > 5)");
849  return ERROR_FAIL;
850  }
851  retval = mips32_pracc_synchronize_cache(ejtag_info, start_addr, end_addr, cached, rel);
852  } else {
853  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
854 
855  pracc_queue_init(&ctx);
857  pracc_add(&ctx, 0, MIPS32_SYNC(ctx.isa));
859  pracc_add(&ctx, 0, MIPS32_EHB(ctx.isa));
860  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa))); /* jump to start */
861  pracc_add(&ctx, 0, MIPS32_NOP);
863  if (ctx.retval != ERROR_OK) {
864  LOG_ERROR("Unable to barrier");
865  retval = ctx.retval;
866  }
867  pracc_queue_free(&ctx);
868  }
869 
870  return retval;
871 }
872 
874 {
875  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
876  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
877  uint32_t *gprs = mips32->core_regs.gpr;
878  uint32_t *c0rs = mips32->core_regs.cp0;
879  bool fpu_in_64bit = ((c0rs[0] & BIT(MIPS32_CP0_STATUS_FR_SHIFT)) != 0);
880  bool fp_enabled = ((c0rs[0] & BIT(MIPS32_CP0_STATUS_CU1_SHIFT)) != 0);
881  bool dsp_enabled = ((c0rs[0] & BIT(MIPS32_CP0_STATUS_MX_SHIFT)) != 0);
883 
884  pracc_queue_init(&ctx);
885 
886  uint32_t cp0_write_code[] = {
887  MIPS32_MTC0(ctx.isa, 1, 12, 0), /* move $1 to status */
888  MIPS32_MTLO(ctx.isa, 1), /* move $1 to lo */
889  MIPS32_MTHI(ctx.isa, 1), /* move $1 to hi */
890  MIPS32_MTC0(ctx.isa, 1, 8, 0), /* move $1 to badvaddr */
891  MIPS32_MTC0(ctx.isa, 1, 13, 0), /* move $1 to cause*/
892  MIPS32_MTC0(ctx.isa, 1, 24, 0), /* move $1 to depc (pc) */
893  };
894 
895  uint32_t cp0_write_data[] = {
896  /* status */
897  c0rs[0],
898  /* lo */
899  gprs[32],
900  /* hi */
901  gprs[33],
902  /* badvaddr */
903  c0rs[1],
904  /* cause */
905  c0rs[2],
906  /* depc (pc) */
907  c0rs[3],
908  };
909 
910  /* Write CP0 Status Register first, changes on EXL or ERL bits
911  * may lead to different behaviour on writing to other CP0 registers.
912  */
913  for (size_t i = 0; i < ARRAY_SIZE(cp0_write_code); i++) {
914  /* load CP0 value in $1 */
915  pracc_add_li32(&ctx, 1, cp0_write_data[i], 0);
916  /* write value from $1 to CP0 register */
917  pracc_add(&ctx, 0, cp0_write_code[i]);
918  }
919 
921  pracc_add(&ctx, 0, MIPS32_EHB(ctx.isa));
922 
923  /* store FPRs */
924  if (mips32->fp_imp && fp_enabled) {
925  uint64_t *fprs = mips32->core_regs.fpr;
926  if (fpu_in_64bit) {
927  for (int i = 0; i != MIPS32_REG_FP_COUNT; i++) {
928  uint32_t fp_lo = fprs[i] & 0xffffffff;
929  uint32_t fp_hi = (fprs[i] >> 32) & 0xffffffff;
930  pracc_add_li32(&ctx, 2, fp_lo, 0);
931  pracc_add_li32(&ctx, 3, fp_hi, 0);
932  pracc_add(&ctx, 0, MIPS32_MTC1(ctx.isa, 2, i));
933  pracc_add(&ctx, 0, MIPS32_MTHC1(ctx.isa, 3, i));
934  }
935  } else {
936  for (int i = 0; i != MIPS32_REG_FP_COUNT; i++) {
937  uint32_t fp_lo = fprs[i] & 0xffffffff;
938  pracc_add_li32(&ctx, 2, fp_lo, 0);
939  pracc_add(&ctx, 0, MIPS32_MTC1(ctx.isa, 2, i));
940  }
941  }
942 
943  if (rel > MIPS32_RELEASE_1)
944  pracc_add(&ctx, 0, MIPS32_EHB(ctx.isa));
945  }
946 
947  /* Store DSP Accumulators */
948  if (mips32->dsp_imp && dsp_enabled) {
949  /* Struct of mips32_dsp_regs: {ac{hi, lo}1-3, dspctl} */
950  uint32_t *dspr = mips32->core_regs.dsp;
951  size_t dsp_regs = ARRAY_SIZE(mips32->core_regs.dsp);
952 
953  /* Starts from ac1, core_regs.dsp contains dspctl register, therefore - 1 */
954  for (size_t index = 0; index != ((dsp_regs - 1) / 2); index++) {
955  /* Every accumulator have 2 registers, hi and lo, and core_regs.dsp stores ac[1~3] */
956  /* reads hi[ac] from core_regs array */
957  pracc_add_li32(&ctx, 2, dspr[index * 2], 0);
958  /* reads lo[ac] from core_regs array */
959  pracc_add_li32(&ctx, 3, dspr[(index * 2) + 1], 0);
960 
961  /* Write to accumulator 1~3 and index starts from 0, therefore ac = index + 1 */
962  size_t ac = index + 1;
963  pracc_add(&ctx, 0, MIPS32_DSP_MTHI(2, ac));
964  pracc_add(&ctx, 0, MIPS32_DSP_MTLO(3, ac));
965  }
966 
967  /* DSPCTL is the last element of register store */
968  pracc_add_li32(&ctx, 2, dspr[6], 0);
969  pracc_add(&ctx, 0, MIPS32_DSP_WRDSP(2, 0x1F));
970 
971  if (rel > MIPS32_RELEASE_1)
972  pracc_add(&ctx, 0, MIPS32_EHB(ctx.isa));
973  }
974 
975  /* load registers 2 to 31 with li32, optimize */
976  for (int i = 2; i < 32; i++)
977  pracc_add_li32(&ctx, i, gprs[i], 1);
978 
979  /* load $15 in DeSave */
980  pracc_add(&ctx, 0, MIPS32_MTC0(ctx.isa, 15, 31, 0));
981  /* load upper half word in $1 */
982  pracc_add(&ctx, 0, MIPS32_LUI(ctx.isa, 1, UPPER16((gprs[1]))));
983  /* jump to start */
984  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa)));
985  /* load lower half word in $1 */
986  pracc_add(&ctx, 0, MIPS32_ORI(ctx.isa, 1, 1, LOWER16((gprs[1]))));
987 
989 
990  ejtag_info->reg8 = gprs[8];
991  ejtag_info->reg9 = gprs[9];
992  pracc_queue_free(&ctx);
993  return ctx.retval;
994 }
995 
996 /* Saves content in `$1` to `DeSave(cp0.31.0)` and loads `MIPS32_PRACC_BASE_ADDR` into `$1` */
998 {
999  /* move $1 to COP0 DeSave */
1000  pracc_add(ctx, 0, MIPS32_MTC0(ctx->isa, 1, 31, 0));
1001  /* $1 = MIP32_PRACC_BASE_ADDR */
1002  pracc_add(ctx, 0, MIPS32_LUI(ctx->isa, 1, PRACC_UPPER_BASE_ADDR));
1003 }
1004 
1005 /* This function assumes the address for saving is stored in `$1`.
1006  * And that action is performed in `mips32_pracc_set_save_base_addr`.
1007  */
1008 static void mips32_pracc_store_regs_gpr(struct pracc_queue_info *ctx, unsigned int offset_gpr)
1009 {
1010  for (int i = 2; i != 32; i++)
1011  pracc_add(ctx, MIPS32_PRACC_PARAM_OUT + offset_gpr + (i * 4),
1012  MIPS32_SW(ctx->isa, i, PRACC_OUT_OFFSET + offset_gpr + (i * 4), 1));
1013 }
1014 
1016 {
1017  uint32_t lohi_read_code[] = {
1018  MIPS32_MFLO(ctx->isa, 8), /* move lo to $8 */
1019  MIPS32_MFHI(ctx->isa, 8), /* move hi to $8 */
1020  };
1021 
1022  /* store lo & hi */
1023  for (int i = 0; i < 2; i++) {
1024  /* load COP0 needed registers to $8 */
1025  pracc_add(ctx, 0, lohi_read_code[i]);
1026  /* store $8 at PARAM OUT */
1027  pracc_add(ctx, MIPS32_PRACC_PARAM_OUT + (i + 32) * 4,
1028  MIPS32_SW(ctx->isa, 8, PRACC_OUT_OFFSET + (i + 32) * 4, 1));
1029  }
1030 }
1031 
1032 /* Saves CP0 registers [status, badvaddr, cause, depc] */
1033 static void mips32_pracc_store_regs_cp0_context(struct pracc_queue_info *ctx, unsigned int offset_cp0)
1034 {
1035  uint32_t cp0_read_code[] = {
1036  MIPS32_MFC0(ctx->isa, 8, 12, 0), /* move status to $8 */
1037  MIPS32_MFC0(ctx->isa, 8, 8, 0), /* move badvaddr to $8 */
1038  MIPS32_MFC0(ctx->isa, 8, 13, 0), /* move cause to $8 */
1039  MIPS32_MFC0(ctx->isa, 8, 24, 0), /* move depc (pc) to $8 */
1040  };
1041 
1042  /* store cp0 */
1043  for (size_t i = 0; i < ARRAY_SIZE(cp0_read_code); i++) {
1044  size_t offset = offset_cp0 + (i * 4);
1045 
1046  /* load COP0 needed registers to $8 */
1047  pracc_add(ctx, 0, cp0_read_code[i]);
1048  /* store $8 at PARAM OUT */
1050  MIPS32_SW(ctx->isa, 8, PRACC_OUT_OFFSET + offset, 1));
1051  }
1052 }
1053 
1054 /* Loads original content of $1 into $8,
1055  * then store it to the batch data access address.
1056  * Finally it restores $1 from DeSave.
1057  */
1059 {
1060  /* move DeSave to $8, reg1 value */
1061  pracc_add(ctx, 0, MIPS32_MFC0(ctx->isa, 8, 31, 0));
1062  /* store reg1 value from $8 to param out */
1064  MIPS32_SW(ctx->isa, 8, PRACC_OUT_OFFSET + 4, 1));
1065 
1066  /* move COP0 DeSave to $1, restore reg1 */
1067  pracc_add(ctx, 0, MIPS32_MFC0(ctx->isa, 1, 31, 0));
1068 }
1069 
1070 /* This function performs following actions:
1071  * Saves `$1` to `DeSave`,
1072  * then load `PRACC_UPPER_BASE_ADDR` for saving the register data structure into `$1`,
1073  * Saves `$2` ~ `$31` to `PRACC_UPPER_BASE_ADDR + offset_gpr`
1074  * Saves HI and LO,
1075  * Saves necessary cp0 registers.
1076 */
1078  unsigned int offset_gpr, unsigned int offset_cp0)
1079 {
1081  mips32_pracc_store_regs_gpr(ctx, offset_gpr);
1083  mips32_pracc_store_regs_cp0_context(ctx, offset_cp0);
1085 }
1086 
1088 {
1089  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1090  struct pracc_queue_info ctx = {.ejtag_info = ejtag_info};
1091  struct mips32_core_regs *core_regs = &mips32->core_regs;
1092  unsigned int offset_gpr = ((uint8_t *)&core_regs->gpr[0]) - (uint8_t *)core_regs;
1093  unsigned int offset_cp0 = ((uint8_t *)&core_regs->cp0[0]) - (uint8_t *)core_regs;
1094  unsigned int offset_fpr = ((uint8_t *)&core_regs->fpr[0]) - (uint8_t *)core_regs;
1095  unsigned int offset_fpcr = ((uint8_t *)&core_regs->fpcr[0]) - (uint8_t *)core_regs;
1096  unsigned int offset_dsp = ((uint8_t *)&core_regs->dsp[0]) - (uint8_t *)core_regs;
1097  bool fp_enabled, dsp_enabled;
1098 
1099  /*
1100  * This procedure has to be in 3 distinctive steps, because we can
1101  * only know whether FP and DSP are enabled after reading CP0.
1102  *
1103  * Step 1: Read everything except CP1 and DSP stuff
1104  * Step 2: Read CP1 stuff if FP is implemented
1105  * Step 3: Read DSP registers if dsp is implemented
1106  */
1107 
1108  pracc_queue_init(&ctx);
1109 
1110  mips32_pracc_store_regs(&ctx, offset_gpr, offset_cp0);
1111 
1112  /* jump to start */
1113  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa)));
1114  /* load $15 in DeSave */
1115  pracc_add(&ctx, 0, MIPS32_MTC0(ctx.isa, 15, 31, 0));
1116 
1117  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, (uint32_t *)&mips32->core_regs, 1);
1118 
1119  pracc_queue_free(&ctx);
1120 
1121  /* reg8 is saved but not restored, next called function should restore it */
1122  ejtag_info->reg8 = mips32->core_regs.gpr[8];
1123  ejtag_info->reg9 = mips32->core_regs.gpr[9];
1124 
1125  if (ctx.retval != ERROR_OK)
1126  return ctx.retval;
1127 
1128  /* we only care if FP is actually impl'd and if cp1 is enabled */
1129  /* since we already read cp0 in the prev step */
1130  /* now we know what's in cp0.status */
1131  fp_enabled = (mips32->core_regs.cp0[0] & BIT(MIPS32_CP0_STATUS_CU1_SHIFT)) != 0;
1132  if (mips32->fp_imp && fp_enabled) {
1133  pracc_queue_init(&ctx);
1134 
1136 
1137  /* FCSR */
1138  pracc_add(&ctx, 0, MIPS32_CFC1(ctx.isa, 8, 31));
1139  pracc_add(&ctx, MIPS32_PRACC_PARAM_OUT + offset_fpcr,
1140  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET + offset_fpcr, 1));
1141 
1142  /* FIR */
1143  pracc_add(&ctx, 0, MIPS32_CFC1(ctx.isa, 8, 0));
1144  pracc_add(&ctx, MIPS32_PRACC_PARAM_OUT + offset_fpcr + 4,
1145  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET + offset_fpcr + 4, 1));
1146 
1147  /* f0 to f31 */
1148  if (mips32->fpu_in_64bit) {
1149  for (int i = 0; i != 32; i++) {
1150  size_t offset = offset_fpr + (i * 8);
1151  /* current pracc implementation (or EJTAG itself) only supports 32b access */
1152  /* so there is no way to use SDC1 */
1153 
1154  /* lower half */
1155  pracc_add(&ctx, 0, MIPS32_MFC1(ctx.isa, 8, i));
1157  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET + offset, 1));
1158 
1159  /* upper half */
1160  pracc_add(&ctx, 0, MIPS32_MFHC1(ctx.isa, 8, i));
1162  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET + offset + 4, 1));
1163  }
1164  } else {
1165  for (int i = 0; i != 32; i++) {
1166  size_t offset = offset_fpr + (i * 8);
1168  MIPS32_SWC1(ctx.isa, i, PRACC_OUT_OFFSET + offset, 1));
1169  }
1170  }
1171 
1173 
1174  /* jump to start */
1175  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa)));
1176  /* load $15 in DeSave */
1177  pracc_add(&ctx, 0, MIPS32_MTC0(ctx.isa, 15, 31, 0));
1178 
1179  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, (uint32_t *)&mips32->core_regs, 1);
1180 
1181  pracc_queue_free(&ctx);
1182  }
1183 
1184  dsp_enabled = (mips32->core_regs.cp0[MIPS32_REG_C0_STATUS_INDEX] & BIT(MIPS32_CP0_STATUS_MX_SHIFT)) != 0;
1185  if (mips32->dsp_imp && dsp_enabled) {
1186  pracc_queue_init(&ctx);
1187 
1189 
1190  /* Struct of mips32_dsp_regs[7]: {ac{hi, lo}1-3, dspctl} */
1191  size_t dsp_regs = ARRAY_SIZE(mips32->core_regs.dsp);
1192  /* Starts from ac1, core_regs.dsp have dspctl register, therefore - 1 */
1193  for (size_t index = 0; index != ((dsp_regs - 1) / 2); index++) {
1194  /* Every accumulator have 2 registers, hi&lo, and core_regs.dsp stores ac[1~3] */
1195  /* Reads offset of hi[ac] from core_regs array */
1196  size_t offset_hi = offset_dsp + ((index * 2) * sizeof(uint32_t));
1197  /* Reads offset of lo[ac] from core_regs array */
1198  size_t offset_lo = offset_dsp + (((index * 2) + 1) * sizeof(uint32_t));
1199 
1200  /* DSP Ac registers starts from 1 and index starts from 0, therefore ac = index + 1 */
1201  size_t ac = index + 1;
1202  pracc_add(&ctx, 0, MIPS32_DSP_MFHI(8, ac));
1203  pracc_add(&ctx, MIPS32_PRACC_PARAM_OUT + offset_hi,
1204  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET + offset_hi, 1));
1205  pracc_add(&ctx, 0, MIPS32_DSP_MFLO(8, ac));
1206  pracc_add(&ctx, MIPS32_PRACC_PARAM_OUT + offset_lo,
1207  MIPS32_SW(ctx.isa, 8, PRACC_OUT_OFFSET + offset_lo, 1));
1208  }
1209 
1210  /* DSPCTL is the last element of register store */
1211  pracc_add(&ctx, 0, MIPS32_DSP_RDDSP(8, 0x3F));
1212  pracc_add(&ctx, MIPS32_PRACC_PARAM_OUT + offset_dsp + ((dsp_regs - 1) * sizeof(uint32_t)),
1213  MIPS32_SW(ctx.isa, 8,
1214  PRACC_OUT_OFFSET + offset_dsp + ((dsp_regs - 1) * sizeof(uint32_t)), 1));
1215 
1217 
1218  /* jump to start */
1219  pracc_add(&ctx, 0, MIPS32_B(ctx.isa, NEG16((ctx.code_count + 1) << ctx.isa)));
1220  /* load $15 in DeSave */
1221  pracc_add(&ctx, 0, MIPS32_MTC0(ctx.isa, 15, 31, 0));
1222 
1223  ctx.retval = mips32_pracc_queue_exec(ejtag_info, &ctx, (uint32_t *)&mips32->core_regs, 1);
1224 
1225  pracc_queue_free(&ctx);
1226  }
1227  return ctx.retval;
1228 }
1229 
1246  uint32_t addr, int size, int count)
1247 {
1248  int retval = ERROR_OK;
1249 
1250  if ((KSEGX(addr) == KSEG1) || (addr >= 0xff200000 && addr <= 0xff3fffff)) // DESEG?
1251  return retval; /*Nothing to do*/
1252 
1253  int cached = 0;
1254  uint32_t conf = 0;
1255 
1256  mips32_cp0_read(ejtag_info, &conf, 16, 0);
1257 
1258  switch (KSEGX(addr)) {
1259  case KUSEG:
1260  cached = (conf & MIPS32_CONFIG0_KU_MASK) >> MIPS32_CONFIG0_KU_SHIFT;
1261  break;
1262  case KSEG0:
1263  cached = (conf & MIPS32_CONFIG0_K0_MASK) >> MIPS32_CONFIG0_K0_SHIFT;
1264  break;
1265  case KSEG2:
1266  case KSEG3:
1268  break;
1269  default:
1270  /* what ? */
1271  break;
1272  }
1273 
1279  if (cached == 3 || cached == 0) { /* Write back cache or write through cache */
1280  uint32_t start_addr = addr;
1281  uint32_t end_addr = addr + count * size;
1282  uint32_t rel = (conf & MIPS32_CONFIG0_AR_MASK) >> MIPS32_CONFIG0_AR_SHIFT;
1283  /* FIXME: In MIPS Release 6, the encoding of CACHE instr has changed */
1284  if (rel > MIPS32_RELEASE_2) {
1285  LOG_DEBUG("Unsupported MIPS Release ( > 5)");
1286  return ERROR_FAIL;
1287  }
1288  retval = mips32_pracc_synchronize_cache(ejtag_info, start_addr, end_addr, cached, rel);
1289  }
1290 
1291  return retval;
1292 }
1293 
1294 /* fastdata upload/download requires an initialized working area
1295  * to load the download code; it should not be called otherwise
1296  * fetch order from the fastdata area
1297  * 1. start addr
1298  * 2. end addr
1299  * 3. data ...
1300  */
1302  int write_t, uint32_t addr, int count, uint32_t *buf)
1303 {
1304  uint32_t isa = ejtag_info->isa ? 1 : 0;
1305  uint32_t handler_code[] = {
1306  /* r15 points to the start of this code */
1307  MIPS32_SW(isa, 8, MIPS32_FASTDATA_HANDLER_SIZE - 4, 15),
1308  MIPS32_SW(isa, 9, MIPS32_FASTDATA_HANDLER_SIZE - 8, 15),
1309  MIPS32_SW(isa, 10, MIPS32_FASTDATA_HANDLER_SIZE - 12, 15),
1310  MIPS32_SW(isa, 11, MIPS32_FASTDATA_HANDLER_SIZE - 16, 15),
1311  /* start of fastdata area in t0 */
1314  MIPS32_LW(isa, 9, 0, 8), /* start addr in t1 */
1315  mips32_cpu_support_sync(ejtag_info) ? MIPS32_SYNC(isa) : MIPS32_NOP, /* barrier for ordering */
1316  MIPS32_LW(isa, 10, 0, 8), /* end addr to t2 */
1317  mips32_cpu_support_sync(ejtag_info) ? MIPS32_SYNC(isa) : MIPS32_NOP, /* barrier for ordering */
1318  /* loop: */
1319  write_t ? MIPS32_LW(isa, 11, 0, 8) : MIPS32_LW(isa, 11, 0, 9), /* from xfer area : from memory */
1320  write_t ? MIPS32_SW(isa, 11, 0, 9) : MIPS32_SW(isa, 11, 0, 8), /* to memory : to xfer area */
1321 
1322  mips32_cpu_support_sync(ejtag_info) ? MIPS32_SYNC(isa) : MIPS32_NOP, /* barrier for ordering */
1323 
1324  MIPS32_BNE(isa, 10, 9, NEG16(4 << isa)), /* bne $t2,t1,loop */
1325  MIPS32_ADDI(isa, 9, 9, 4), /* addi t1,t1,4 */
1326 
1327  MIPS32_LW(isa, 8, MIPS32_FASTDATA_HANDLER_SIZE - 4, 15),
1328  MIPS32_LW(isa, 9, MIPS32_FASTDATA_HANDLER_SIZE - 8, 15),
1329  MIPS32_LW(isa, 10, MIPS32_FASTDATA_HANDLER_SIZE - 12, 15),
1330  MIPS32_LW(isa, 11, MIPS32_FASTDATA_HANDLER_SIZE - 16, 15),
1331 
1333  MIPS32_ORI(isa, 15, 15, LOWER16(MIPS32_PRACC_TEXT) | isa), /* isa bit for JR instr */
1335  ? MIPS32_JRHB(isa, 15)
1336  : MIPS32_JR(isa, 15), /* jr start */
1337  MIPS32_MFC0(isa, 15, 31, 0), /* move COP0 DeSave to $15 */
1338  };
1339 
1342 
1343  pracc_swap16_array(ejtag_info, handler_code, ARRAY_SIZE(handler_code));
1344  /* write program into RAM */
1345  if (write_t != ejtag_info->fast_access_save) {
1346  mips32_pracc_write_mem(ejtag_info, source->address, 4, ARRAY_SIZE(handler_code), handler_code);
1347  /* save previous operation to speed to any consecutive read/writes */
1348  ejtag_info->fast_access_save = write_t;
1349  }
1350 
1351  LOG_DEBUG("%s using 0x%.8" TARGET_PRIxADDR " for write handler", __func__, source->address);
1352 
1353  uint32_t jmp_code[] = {
1354  MIPS32_LUI(isa, 15, UPPER16(source->address)), /* load addr of jump in $15 */
1355  MIPS32_ORI(isa, 15, 15, LOWER16(source->address) | isa), /* isa bit for JR instr */
1357  ? MIPS32_JRHB(isa, 15)
1358  : MIPS32_JR(isa, 15), /* jump to ram program */
1359  isa ? MIPS32_XORI(isa, 15, 15, 1) : MIPS32_NOP, /* drop isa bit, needed for LW/SW instructions */
1360  };
1361 
1362  pracc_swap16_array(ejtag_info, jmp_code, ARRAY_SIZE(jmp_code));
1363 
1364  /* execute jump code, with no address check */
1365  for (unsigned int i = 0; i < ARRAY_SIZE(jmp_code); i++) {
1366  int retval = wait_for_pracc_rw(ejtag_info);
1367  if (retval != ERROR_OK)
1368  return retval;
1369 
1371  mips_ejtag_drscan_32_out(ejtag_info, jmp_code[i]);
1372 
1373  /* Clear the access pending bit (let the processor eat!) */
1374  mips32_pracc_finish(ejtag_info);
1375  }
1376 
1377  /* wait PrAcc pending bit for FASTDATA write, read address */
1378  int retval = mips32_pracc_read_ctrl_addr(ejtag_info);
1379  if (retval != ERROR_OK)
1380  return retval;
1381 
1382  /* next fetch to dmseg should be in FASTDATA_AREA, check */
1383  if (ejtag_info->pa_addr != MIPS32_PRACC_FASTDATA_AREA)
1384  return ERROR_FAIL;
1385 
1386  /* Send the load start address */
1387  uint32_t val = addr;
1389  mips_ejtag_fastdata_scan(ejtag_info, 1, &val);
1390 
1391  retval = wait_for_pracc_rw(ejtag_info);
1392  if (retval != ERROR_OK)
1393  return retval;
1394 
1395  /* Send the load end address */
1396  val = addr + (count - 1) * 4;
1398  mips_ejtag_fastdata_scan(ejtag_info, 1, &val);
1399 
1400  unsigned int num_clocks = 0; /* like in legacy code */
1401  if (ejtag_info->mode != 0)
1402  num_clocks = ((uint64_t)(ejtag_info->scan_delay) * adapter_get_speed_khz() + 500000) / 1000000;
1403 
1404  for (int i = 0; i < count; i++) {
1405  jtag_add_clocks(num_clocks);
1406  mips_ejtag_fastdata_scan(ejtag_info, write_t, buf++);
1407  }
1408 
1409  retval = jtag_execute_queue();
1410  if (retval != ERROR_OK) {
1411  LOG_ERROR("fastdata load failed");
1412  return retval;
1413  }
1414 
1415  retval = mips32_pracc_read_ctrl_addr(ejtag_info);
1416  if (retval != ERROR_OK)
1417  return retval;
1418 
1419  if (ejtag_info->pa_addr != MIPS32_PRACC_TEXT)
1420  LOG_ERROR("mini program did not return to start");
1421 
1423 }
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
Definition: adapter.c:207
#define IS_PWR_OF_2(x)
Definition: align.h:24
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
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1037
void jtag_add_clocks(unsigned int num_cycles)
Function jtag_add_clocks first checks that the state in which the clocks are to be issued is stable,...
Definition: jtag/core.c:599
#define ERROR_JTAG_DEVICE_ERROR
Definition: jtag.h:559
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:164
bool mips32_cpu_support_sync(struct mips_ejtag *ejtag_info)
mips32_cpu_support_sync - Checks CPU supports ordering
Definition: mips32.c:963
bool mips32_cpu_support_hazard_barrier(struct mips_ejtag *ejtag_info)
mips32_cpu_support_hazard_barrier - Checks CPU supports hazard barrier
Definition: mips32.c:976
#define MIPS32_NOP
Definition: mips32.h:719
#define KUSEG
Memory segments (32bit kernel mode addresses) These are the traditional names used in the 32-bit univ...
Definition: mips32.h:27
#define KSEG3
Definition: mips32.h:31
#define MIPS32_ADDI(isa, tar, src, val)
Definition: mips32.h:720
#define MIPS32_SYNC(isa)
Definition: mips32.h:772
#define KSEG2
Definition: mips32.h:30
#define MIPS32_MFHI(isa, reg)
Definition: mips32.h:750
#define MIPS32_DSP_MTLO(reg, ac)
Definition: mips32.h:799
#define MIPS32_SWC1(isa, reg, off, base)
Definition: mips32.h:761
#define MIPS32_SYNCI_STEP
Definition: mips32.h:776
#define MIPS32_MTHI(isa, reg)
Definition: mips32.h:752
#define MIPS32_CONFIG0_K0_SHIFT
Definition: mips32.h:40
#define MIPS32_MTHC1(isa, gpr, cpr)
Definition: mips32.h:748
#define MIPS32_MFC1(isa, gpr, cpr)
Definition: mips32.h:745
#define MIPS32_EHB(isa)
Definition: mips32.h:765
#define MIPS32_CP0_STATUS_CU1_SHIFT
Definition: mips32.h:83
#define MIPS32_CONFIG0_AR_SHIFT
Definition: mips32.h:46
#define KSEG1
Definition: mips32.h:29
#define MIPS32_BNE(isa, src, tar, off)
Definition: mips32.h:729
#define KSEGX(a)
Returns the kernel segment base of a given address.
Definition: mips32.h:34
#define MIPS32_CONFIG1_DL_MASK
Definition: mips32.h:53
#define MIPS32_RDHWR(isa, tar, dst)
Definition: mips32.h:757
#define MIPS32_REG_FP_COUNT
Definition: mips32.h:222
#define MIPS32_CONFIG0_KU_MASK
Definition: mips32.h:38
#define MIPS32_XORI(isa, tar, src, val)
Definition: mips32.h:774
#define MIPS32_JRHB(isa, reg)
Definition: mips32.h:735
#define MIPS32_SW(isa, reg, off, base)
Definition: mips32.h:760
#define MIPS32_MTLO(isa, reg)
Definition: mips32.h:751
#define MIPS32_CACHE_D_HIT_WRITEBACK
Cache operations definitions Operation field is 5 bits long : 1) bits 1..0 hold cache type 2) bits 4....
Definition: mips32.h:590
#define MIPS32_J(isa, tar)
Definition: mips32.h:733
#define MIPS32_LBU(isa, reg, off, base)
Definition: mips32.h:737
#define MIPS32_LHU(isa, reg, off, base)
Definition: mips32.h:738
#define MIPS32_CONFIG0_K23_SHIFT
Definition: mips32.h:43
#define MIPS32_MFLO(isa, reg)
Definition: mips32.h:749
#define MIPS32_CONFIG0_KU_SHIFT
CP0 CONFIG register fields.
Definition: mips32.h:37
#define MIPS32_SB(isa, reg, off, base)
Definition: mips32.h:758
#define MIPS32_CONFIG0_K23_MASK
Definition: mips32.h:44
#define MIPS32_MTC1(isa, gpr, cpr)
Definition: mips32.h:747
#define MIPS32_SH(isa, reg, off, base)
Definition: mips32.h:759
#define MIPS32_CFC1(isa, gpr, cpr)
Definition: mips32.h:731
#define MIPS32_REG_C0_STATUS_INDEX
Definition: mips32.h:239
#define MIPS32_MTC0(isa, gpr, cpr, sel)
Definition: mips32.h:744
#define MIPS32_CONFIG1_DL_SHIFT
Definition: mips32.h:52
#define MIPS32_CACHE_I_HIT_INVALIDATE
Definition: mips32.h:591
#define MIPS32_LUI(isa, reg, val)
Definition: mips32.h:741
#define MIPS32_CACHE(isa, op, off, base)
Definition: mips32.h:730
#define MIPS32_CONFIG0_AR_MASK
Definition: mips32.h:47
#define MIPS32_DSP_MFHI(reg, ac)
Definition: mips32.h:797
#define MIPS32_SYNCI(isa, off, base)
Definition: mips32.h:771
#define MIPS32_DSP_MTHI(reg, ac)
Definition: mips32.h:800
#define MIPS32_DSP_MFLO(reg, ac)
Definition: mips32.h:798
#define MIPS32_ORI(isa, tar, src, val)
Definition: mips32.h:756
#define MIPS32_MFC0(isa, gpr, cpr, sel)
Definition: mips32.h:743
#define MIPS32_MFHC1(isa, gpr, cpr)
Definition: mips32.h:746
#define MIPS32_CP0_STATUS_MX_SHIFT
Definition: mips32.h:81
@ MIPS32_RELEASE_1
Definition: mips32.h:268
@ MIPS32_RELEASE_2
Definition: mips32.h:269
#define MIPS32_JR(isa, reg)
Definition: mips32.h:734
#define MIPS32_B(isa, off)
Definition: mips32.h:726
#define KSEG0
Definition: mips32.h:28
#define MIPS32_LW(isa, reg, off, base)
Definition: mips32.h:739
#define MIPS32_CP0_STATUS_FR_SHIFT
Definition: mips32.h:82
#define MIPS32_CONFIG0_K0_MASK
Definition: mips32.h:41
#define MIPS32_DSP_WRDSP(rs, mask)
Definition: mips32.h:802
#define MIPS32_DSP_RDDSP(rt, mask)
Definition: mips32.h:801
static int mips32_pracc_read_u32(struct mips_ejtag *ejtag_info, uint32_t addr, uint32_t *buf)
Definition: mips32_pracc.c:448
static void mips32_pracc_store_regs_set_base_addr(struct pracc_queue_info *ctx)
Definition: mips32_pracc.c:997
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
static int mips32_pracc_fastdata_xfer_synchronize_cache(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count)
mips32_pracc_fastdata_xfer_synchronize_cache - Synchronize cache for fast data transfer
static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info)
Definition: mips32_pracc.c:68
static int mips32_pracc_read_ctrl_addr(struct mips_ejtag *ejtag_info)
Definition: mips32_pracc.c:95
static void mips32_pracc_store_regs_restore(struct pracc_queue_info *ctx)
int mips32_pracc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf)
Definition: mips32_pracc.c:800
static int mips32_pracc_exec(struct mips_ejtag *ejtag_info, struct pracc_queue_info *ctx, uint32_t *param_out, bool check_last)
Definition: mips32_pracc.c:154
int mips32_pracc_fastdata_xfer(struct mips_ejtag *ejtag_info, struct working_area *source, int write_t, uint32_t addr, int count, uint32_t *buf)
static void pracc_add_li32(struct pracc_queue_info *ctx, uint32_t reg_num, uint32_t data, bool optimize)
Definition: mips32_pracc.c:327
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)
static int mips32_pracc_synchronize_cache(struct mips_ejtag *ejtag_info, uint32_t start_addr, uint32_t end_addr, int cached, int rel)
mips32_pracc_sync_cache
Definition: mips32_pracc.c:638
void pracc_queue_init(struct pracc_queue_info *ctx)
Definition: mips32_pracc.c:297
int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf)
Definition: mips32_pracc.c:469
static int mips32_pracc_write_mem_generic(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf)
Definition: mips32_pracc.c:741
static void mips32_pracc_finish(struct mips_ejtag *ejtag_info)
Definition: mips32_pracc.c:108
static void mips32_pracc_store_regs_gpr(struct pracc_queue_info *ctx, unsigned int offset_gpr)
static int mips32_pracc_clean_text_jump(struct mips_ejtag *ejtag_info)
Definition: mips32_pracc.c:115
static void mips32_pracc_store_regs_cp0_context(struct pracc_queue_info *ctx, unsigned int offset_cp0)
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
static void mips32_pracc_store_regs(struct pracc_queue_info *ctx, unsigned int offset_gpr, unsigned int offset_cp0)
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
static void mips32_pracc_store_regs_lohi(struct pracc_queue_info *ctx)
#define MIPS32_PRACC_TEXT
Definition: mips32_pracc.h:22
#define PRACC_UPPER_BASE_ADDR
Definition: mips32_pracc.h:25
#define MIPS32_FASTDATA_HANDLER_SIZE
Definition: mips32_pracc.h:30
#define PRACC_BLOCK
Definition: mips32_pracc.h:37
#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 MIPS32_PRACC_FASTDATA_AREA
Definition: mips32_pracc.h:19
#define UPPER16(addr)
Definition: mips32_pracc.h:31
#define MIPS32_PRACC_PARAM_OUT
Definition: mips32_pracc.h:23
#define SWAP16(v)
Definition: mips32_pracc.h:34
#define NEG16(v)
Definition: mips32_pracc.h:33
int mips_ejtag_fastdata_scan(struct mips_ejtag *ejtag_info, int write_t, uint32_t *data)
Definition: mips_ejtag.c:414
void mips_ejtag_drscan_32_out(struct mips_ejtag *ejtag_info, uint32_t data)
Definition: mips_ejtag.c:145
void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, uint32_t new_instr)
Definition: mips_ejtag.c:22
int mips_ejtag_drscan_32(struct mips_ejtag *ejtag_info, uint32_t *data)
Definition: mips_ejtag.c:130
void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info, uint32_t ctrl, uint32_t data, uint8_t *in_scan_buf)
Definition: mips_ejtag.c:58
#define EJTAG_CTRL_PRNW
Definition: mips_ejtag.h:61
#define EJTAG_INST_ALL
Definition: mips_ejtag.h:21
#define EJTAG_INST_CONTROL
Definition: mips_ejtag.h:20
#define EJTAG_INST_FASTDATA
Definition: mips_ejtag.h:24
#define EJTAG_INST_DATA
Definition: mips_ejtag.h:19
#define EJTAG_CTRL_PRACC
Definition: mips_ejtag.h:60
#define EJTAG_INST_ADDRESS
Definition: mips_ejtag.h:18
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
struct rtt_control ctrl
Control block.
Definition: rtt/rtt.c:25
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
struct rtt_source source
Definition: rtt/rtt.c:23
#define BIT(nr)
Definition: stm32l4x.h:18
enum mips32_dsp_imp dsp_imp
Definition: mips32.h:404
enum mips32_fp_imp fp_imp
Definition: mips32.h:403
bool fpu_in_64bit
Definition: mips32.h:418
struct mips_ejtag ejtag_info
Definition: mips32.h:396
struct mips32_core_regs core_regs
Definition: mips32.h:398
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
uint32_t ejtag_ctrl
Definition: mips_ejtag.h:210
unsigned int scan_delay
Definition: mips_ejtag.h:217
uint32_t reg9
Definition: mips_ejtag.h:216
uint32_t config[4]
Definition: mips_ejtag.h:213
uint32_t endianness
Definition: mips_ejtag.h:223
uint32_t pa_ctrl
Definition: mips_ejtag.h:219
uint32_t reg8
Definition: mips_ejtag.h:215
uint32_t pa_addr
Definition: mips_ejtag.h:220
int fast_access_save
Definition: mips_ejtag.h:211
uint32_t isa
Definition: mips_ejtag.h:222
uint32_t addr
Definition: mips32_pracc.h:43
uint32_t instr
Definition: mips32_pracc.h:42
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
Definition: psoc6.c:83
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:794
int64_t timeval_ms(void)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define TARGET_PRIxADDR
Definition: types.h:340
#define NULL
Definition: usb.h:16
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22