OpenOCD
mips_m4k.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 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include "breakpoints.h"
20 #include "mips32.h"
21 #include "mips_m4k.h"
22 #include "mips32_dmaacc.h"
23 #include "target_type.h"
24 #include "register.h"
25 #include "smp.h"
26 
27 static void mips_m4k_enable_breakpoints(struct target *target);
28 static void mips_m4k_enable_watchpoints(struct target *target);
29 static int mips_m4k_set_breakpoint(struct target *target,
30  struct breakpoint *breakpoint);
31 static int mips_m4k_unset_breakpoint(struct target *target,
32  struct breakpoint *breakpoint);
33 static int mips_m4k_internal_restore(struct target *target, bool current,
34  target_addr_t address, bool handle_breakpoints,
35  bool debug_execution);
36 static int mips_m4k_halt(struct target *target);
38  uint32_t count, const uint8_t *buffer);
40  uint32_t count, uint8_t *buffer);
41 
43 {
44  struct mips32_common *mips32 = target_to_mips32(target);
45  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
46  uint32_t break_status;
47  int retval;
48 
51  if (ejtag_info->debug_caps & EJTAG_DCR_IB) {
52  /* get info about inst breakpoint support */
53  retval = target_read_u32(target,
54  ejtag_info->ejtag_ibs_addr, &break_status);
55  if (retval != ERROR_OK)
56  return retval;
57  if (break_status & 0x1f) {
58  /* we have halted on a breakpoint */
59  retval = target_write_u32(target,
60  ejtag_info->ejtag_ibs_addr, 0);
61  if (retval != ERROR_OK)
62  return retval;
64  }
65  }
66 
67  if (ejtag_info->debug_caps & EJTAG_DCR_DB) {
68  /* get info about data breakpoint support */
69  retval = target_read_u32(target,
70  ejtag_info->ejtag_dbs_addr, &break_status);
71  if (retval != ERROR_OK)
72  return retval;
73  if (break_status & 0x1f) {
74  /* we have halted on a breakpoint */
75  retval = target_write_u32(target,
76  ejtag_info->ejtag_dbs_addr, 0);
77  if (retval != ERROR_OK)
78  return retval;
80  }
81  }
82  }
83 
84  return ERROR_OK;
85 }
86 
87 static int mips_m4k_debug_entry(struct target *target)
88 {
89  struct mips32_common *mips32 = target_to_mips32(target);
90  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
91 
93 
94  /* make sure stepping disabled, SSt bit in CP0 debug register cleared */
95  mips_ejtag_config_step(ejtag_info, 0);
96 
97  /* make sure break unit configured */
99 
100  /* attempt to find halt reason */
102 
104 
106 
107  /* default to mips32 isa, it will be changed below if required */
108  mips32->isa_mode = MIPS32_ISA_MIPS32;
109 
110  /* other than mips32 only and isa bit set ? */
111  if (mips32->isa_imp && buf_get_u32(mips32->core_cache->reg_list[MIPS32_REGLIST_C0_PC_INDEX].value, 0, 1))
112  mips32->isa_mode = mips32->isa_imp == 2 ? MIPS32_ISA_MIPS16E : MIPS32_ISA_MMIPS32;
113 
114  LOG_DEBUG("entered debug state at PC 0x%" PRIx32 ", target->state: %s",
117 
118  return ERROR_OK;
119 }
120 
121 static struct target *get_mips_m4k(struct target *target, int32_t coreid)
122 {
123  struct target_list *head;
124 
126  struct target *curr = head->target;
127  if ((curr->coreid == coreid) && (curr->state == TARGET_HALTED))
128  return curr;
129  }
130  return target;
131 }
132 
133 static int mips_m4k_halt_smp(struct target *target)
134 {
135  int retval = ERROR_OK;
136  struct target_list *head;
137 
139  int ret = ERROR_OK;
140  struct target *curr = head->target;
141  if ((curr != target) && (curr->state != TARGET_HALTED))
142  ret = mips_m4k_halt(curr);
143 
144  if (ret != ERROR_OK) {
145  LOG_TARGET_ERROR(curr, "halt failed.");
146  retval = ret;
147  }
148  }
149  return retval;
150 }
151 
152 static int update_halt_gdb(struct target *target)
153 {
154  int retval = ERROR_OK;
155  if (target->gdb_service->core[0] == -1) {
158  retval = mips_m4k_halt_smp(target);
159  }
160  return retval;
161 }
162 
163 static int mips_m4k_poll(struct target *target)
164 {
165  int retval = ERROR_OK;
166  struct mips32_common *mips32 = target_to_mips32(target);
167  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
168  uint32_t ejtag_ctrl = ejtag_info->ejtag_ctrl;
169  enum target_state prev_target_state = target->state;
170 
171  /* toggle to another core is done by gdb as follow */
172  /* maint packet J core_id */
173  /* continue */
174  /* the next polling trigger an halt event sent to gdb */
175  if ((target->state == TARGET_HALTED) && (target->smp) &&
176  (target->gdb_service) &&
177  (!target->gdb_service->target)) {
181  return retval;
182  }
183 
184  /* read ejtag control reg */
186  retval = mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl);
187  if (retval != ERROR_OK)
188  return retval;
189 
190  ejtag_info->isa = (ejtag_ctrl & EJTAG_CTRL_DBGISA) ? 1 : 0;
191 
192  /* clear this bit before handling polling
193  * as after reset registers will read zero */
194  if (ejtag_ctrl & EJTAG_CTRL_ROCC) {
195  /* we have detected a reset, clear flag
196  * otherwise ejtag will not work */
197  ejtag_ctrl = ejtag_info->ejtag_ctrl & ~EJTAG_CTRL_ROCC;
198 
200  retval = mips_ejtag_drscan_32(ejtag_info, &ejtag_ctrl);
201  if (retval != ERROR_OK)
202  return retval;
203  LOG_DEBUG("Reset Detected");
204  }
205 
206  /* check for processor halted */
208  if ((target->state != TARGET_HALTED)
209  && (target->state != TARGET_DEBUG_RUNNING)) {
210  if (target->state == TARGET_UNKNOWN)
211  LOG_DEBUG("EJTAG_CTRL_BRKST already set during server startup.");
212 
213  /* OpenOCD was was probably started on the board with EJTAG_CTRL_BRKST already set
214  * (maybe put on by HALT-ing the board in the previous session).
215  *
216  * Force enable debug entry for this session.
217  */
220  retval = mips_m4k_debug_entry(target);
221  if (retval != ERROR_OK)
222  return retval;
223 
224  if (target->smp &&
225  ((prev_target_state == TARGET_RUNNING)
226  || (prev_target_state == TARGET_RESET))) {
227  retval = update_halt_gdb(target);
228  if (retval != ERROR_OK)
229  return retval;
230  }
232  } else if (target->state == TARGET_DEBUG_RUNNING) {
234 
235  retval = mips_m4k_debug_entry(target);
236  if (retval != ERROR_OK)
237  return retval;
238 
239  if (target->smp) {
240  retval = update_halt_gdb(target);
241  if (retval != ERROR_OK)
242  return retval;
243  }
244 
246  }
247  } else
249 
250 /* LOG_DEBUG("ctrl = 0x%08X", ejtag_ctrl); */
251 
252  return ERROR_OK;
253 }
254 
255 static int mips_m4k_halt(struct target *target)
256 {
257  struct mips32_common *mips32 = target_to_mips32(target);
258  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
259 
260  LOG_DEBUG("target->state: %s", target_state_name(target));
261 
262  if (target->state == TARGET_HALTED) {
263  LOG_DEBUG("target was already halted");
264  return ERROR_OK;
265  }
266 
267  if (target->state == TARGET_UNKNOWN)
268  LOG_WARNING("target was in unknown state when halt was requested");
269 
270  if (target->state == TARGET_RESET) {
272  LOG_ERROR("can't request a halt while in reset if nSRST pulls nTRST");
273  return ERROR_TARGET_FAILURE;
274  } else {
275  /* we came here in a reset_halt or reset_init sequence
276  * debug entry was already prepared in mips_m4k_assert_reset()
277  */
279 
280  return ERROR_OK;
281  }
282  }
283 
284  /* break processor */
285  mips_ejtag_enter_debug(ejtag_info);
286 
288 
289  return ERROR_OK;
290 }
291 
293 {
294  struct mips_m4k_common *mips_m4k = target_to_m4k(target);
295  struct mips_ejtag *ejtag_info = &mips_m4k->mips32.ejtag_info;
296 
297  /* TODO: apply hw reset signal in not examined state */
298  if (!(target_was_examined(target))) {
299  LOG_WARNING("Reset is not asserted because the target is not examined.");
300  LOG_WARNING("Use a reset button or power cycle the target.");
302  }
303 
304  LOG_DEBUG("target->state: %s",
306 
308 
309  /* some cores support connecting while srst is asserted
310  * use that mode is it has been configured */
311 
312  bool srst_asserted = false;
313 
316  jtag_add_reset(0, 1);
317  srst_asserted = true;
318  }
319 
320 
321  /* EJTAG before v2.5/2.6 does not support EJTAGBOOT or NORMALBOOT */
322  if (ejtag_info->ejtag_version != EJTAG_VERSION_20) {
323  if (target->reset_halt) {
324  /* use hardware to catch reset */
326  } else
328  }
329 
331  /* here we should issue a srst only, but we may have to assert trst as well */
333  jtag_add_reset(1, 1);
334  else if (!srst_asserted)
335  jtag_add_reset(0, 1);
338  } else {
339  if (mips_m4k->is_pic32mx) {
340  LOG_DEBUG("Using MTAP reset to reset processor...");
341 
342  /* use microchip specific MTAP reset */
343  mips_ejtag_set_instr(ejtag_info, MTAP_SW_MTAP);
344  mips_ejtag_set_instr(ejtag_info, MTAP_COMMAND);
345 
348  mips_ejtag_set_instr(ejtag_info, MTAP_SW_ETAP);
349  } else {
350  /* use ejtag reset - not supported by all cores */
351  uint32_t ejtag_ctrl = ejtag_info->ejtag_ctrl | EJTAG_CTRL_PRRST | EJTAG_CTRL_PERRST;
352  LOG_DEBUG("Using EJTAG reset (PRRST) to reset processor...");
355  }
356  }
357 
359  jtag_add_sleep(50000);
360 
362 
363  if (target->reset_halt) {
364  int retval = target_halt(target);
365  if (retval != ERROR_OK)
366  return retval;
367  }
368 
369  return ERROR_OK;
370 }
371 
373 {
374  LOG_DEBUG("target->state: %s", target_state_name(target));
375 
376  /* deassert reset lines */
377  jtag_add_reset(0, 0);
378 
379  return ERROR_OK;
380 }
381 
383 {
384  struct mips32_common *mips32 = target_to_mips32(target);
385  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
386 
387  /* configure single step mode */
388  mips_ejtag_config_step(ejtag_info, 1);
389 
390  /* disable interrupts while stepping */
392 
393  /* exit debug mode */
394  mips_ejtag_exit_debug(ejtag_info);
395 
397 
398  return ERROR_OK;
399 }
400 
401 static int mips_m4k_restore_smp(struct target *target, uint32_t address,
402  bool handle_breakpoints)
403 {
404  int retval = ERROR_OK;
405  struct target_list *head;
406 
408  int ret = ERROR_OK;
409  struct target *curr = head->target;
410  if ((curr != target) && (curr->state != TARGET_RUNNING)) {
411  /* resume current address , not in step mode */
412  ret = mips_m4k_internal_restore(curr, true, address,
413  handle_breakpoints, false);
414 
415  if (ret != ERROR_OK) {
416  LOG_TARGET_ERROR(curr, "failed to resume at address: 0x%" PRIx32,
417  address);
418  retval = ret;
419  }
420  }
421  }
422  return retval;
423 }
424 
425 static int mips_m4k_internal_restore(struct target *target, bool current,
426  target_addr_t address, bool handle_breakpoints,
427  bool debug_execution)
428 {
429  struct mips32_common *mips32 = target_to_mips32(target);
430  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
431  struct breakpoint *breakpoint = NULL;
432  uint32_t resume_pc;
433 
434  if (target->state != TARGET_HALTED) {
435  LOG_WARNING("target not halted");
437  }
438 
439  if (!debug_execution) {
443  }
444 
445  /* current = true: continue on current pc, otherwise continue at <address> */
446  if (!current) {
451  }
452 
453  if (mips32->isa_imp > 1 && debug_execution) /* if more than one isa supported */
455 
456  if (!current)
457  resume_pc = address;
458  else
459  resume_pc = buf_get_u32(mips32->core_cache->reg_list[MIPS32_REGLIST_C0_PC_INDEX].value, 0, 32);
460 
462 
463  /* the front-end may request us not to handle breakpoints */
464  if (handle_breakpoints) {
465  /* Single step past breakpoint at current address */
466  breakpoint = breakpoint_find(target, resume_pc);
467  if (breakpoint) {
468  LOG_DEBUG("unset breakpoint at " TARGET_ADDR_FMT "",
473  }
474  }
475 
476  /* enable interrupts if we are running */
477  mips32_enable_interrupts(target, !debug_execution);
478 
479  /* exit debug mode */
480  mips_ejtag_exit_debug(ejtag_info);
482 
483  /* registers are now invalid */
485 
486  if (!debug_execution) {
489  LOG_DEBUG("target resumed at 0x%" PRIx32 "", resume_pc);
490  } else {
493  LOG_DEBUG("target debug resumed at 0x%" PRIx32 "", resume_pc);
494  }
495 
496  return ERROR_OK;
497 }
498 
499 static int mips_m4k_resume(struct target *target, bool current,
500  target_addr_t address, bool handle_breakpoints, bool debug_execution)
501 {
502  int retval = ERROR_OK;
503 
504  /* dummy resume for smp toggle in order to reduce gdb impact */
505  if ((target->smp) && (target->gdb_service->core[1] != -1)) {
506  /* simulate a start and halt of target */
509  /* fake resume at next poll we play the target core[1], see poll*/
511  return retval;
512  }
513 
514  retval = mips_m4k_internal_restore(target, current, address,
515  handle_breakpoints,
516  debug_execution);
517 
518  if (retval == ERROR_OK && target->smp) {
519  target->gdb_service->core[0] = -1;
520  retval = mips_m4k_restore_smp(target, address, handle_breakpoints);
521  }
522 
523  return retval;
524 }
525 
526 static int mips_m4k_step(struct target *target, bool current,
527  target_addr_t address, bool handle_breakpoints)
528 {
529  /* get pointers to arch-specific information */
530  struct mips32_common *mips32 = target_to_mips32(target);
531  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
532  struct breakpoint *breakpoint = NULL;
533 
534  if (target->state != TARGET_HALTED) {
535  LOG_WARNING("target not halted");
537  }
538 
539  /* current = true: continue on current pc, otherwise continue at <address> */
540  if (!current) {
545  }
546 
547  /* the front-end may request us not to handle breakpoints */
548  if (handle_breakpoints) {
551  if (breakpoint)
553  }
554 
555  /* restore context */
557 
558  /* configure single step mode */
559  mips_ejtag_config_step(ejtag_info, 1);
560 
562 
564 
565  /* disable interrupts while stepping */
567 
568  /* exit debug mode */
569  mips_ejtag_exit_debug(ejtag_info);
570 
571  /* registers are now invalid */
573 
574  LOG_DEBUG("target stepped ");
576 
577  if (breakpoint)
579 
581 
582  return ERROR_OK;
583 }
584 
586 {
588 
589  /* set any pending breakpoints */
590  while (breakpoint) {
591  if (!breakpoint->is_set)
594  }
595 }
596 
598  struct breakpoint *breakpoint)
599 {
600  struct mips32_common *mips32 = target_to_mips32(target);
601  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
602  struct mips32_comparator *comparator_list = mips32->inst_break_list;
603  int retval;
604 
605  if (breakpoint->is_set) {
606  LOG_WARNING("breakpoint already set");
607  return ERROR_OK;
608  }
609 
610  if (breakpoint->type == BKPT_HARD) {
611  int bp_num = 0;
612 
613  while (comparator_list[bp_num].used && (bp_num < mips32->num_inst_bpoints))
614  bp_num++;
615  if (bp_num >= mips32->num_inst_bpoints) {
616  LOG_ERROR("Can not find free FP Comparator(bpid: %" PRIu32 ")",
619  }
620  breakpoint_hw_set(breakpoint, bp_num);
621  comparator_list[bp_num].used = 1;
622  comparator_list[bp_num].bp_value = breakpoint->address;
623 
624  if (breakpoint->length != 4) /* make sure isa bit set */
625  comparator_list[bp_num].bp_value |= 1;
626  else /* make sure isa bit cleared */
627  comparator_list[bp_num].bp_value &= ~1;
628 
629  /* EJTAG 2.0 uses 30bit IBA. First 2 bits are reserved.
630  * Warning: there is no IB ASID registers in 2.0.
631  * Do not set it! :) */
632  if (ejtag_info->ejtag_version == EJTAG_VERSION_20)
633  comparator_list[bp_num].bp_value &= 0xFFFFFFFC;
634 
635  target_write_u32(target, comparator_list[bp_num].reg_address,
636  comparator_list[bp_num].bp_value);
637  target_write_u32(target, comparator_list[bp_num].reg_address +
638  ejtag_info->ejtag_ibm_offs, 0x00000000);
639  target_write_u32(target, comparator_list[bp_num].reg_address +
640  ejtag_info->ejtag_ibc_offs, 1);
641  LOG_DEBUG("bpid: %" PRIu32 ", bp_num %i bp_value 0x%" PRIx32 "",
643  bp_num, comparator_list[bp_num].bp_value);
644  } else if (breakpoint->type == BKPT_SOFT) {
645  LOG_DEBUG("bpid: %" PRIu32, breakpoint->unique_id);
646 
647  uint32_t isa_req = breakpoint->length & 1; /* micro mips request bit */
648  uint32_t bplength = breakpoint->length & ~1; /* drop micro mips request bit for length */
649  uint32_t bpaddr = breakpoint->address & ~1; /* drop isa bit from address, if set */
650 
651  if (bplength == 4) {
652  uint32_t verify = 0xffffffff;
653  uint32_t sdbbp32_instr = MIPS32_SDBBP(isa_req);
654  if (ejtag_info->endianness && isa_req)
655  sdbbp32_instr = SWAP16(sdbbp32_instr);
656 
657  if ((breakpoint->address & 3) == 0) { /* word aligned */
658 
659  retval = target_read_memory(target, bpaddr, bplength, 1, breakpoint->orig_instr);
660  if (retval != ERROR_OK)
661  return retval;
662 
663  retval = target_write_u32(target, bpaddr, sdbbp32_instr);
664  if (retval != ERROR_OK)
665  return retval;
666 
667  retval = target_read_u32(target, bpaddr, &verify);
668  if (retval != ERROR_OK)
669  return retval;
670 
671  if (verify != sdbbp32_instr)
672  verify = 0;
673 
674  } else { /* 16 bit aligned */
675  retval = target_read_memory(target, bpaddr, 2, 2, breakpoint->orig_instr);
676  if (retval != ERROR_OK)
677  return retval;
678 
679  uint8_t sdbbp_buf[4];
680  target_buffer_set_u32(target, sdbbp_buf, sdbbp32_instr);
681 
682  retval = target_write_memory(target, bpaddr, 2, 2, sdbbp_buf);
683  if (retval != ERROR_OK)
684  return retval;
685 
686  retval = target_read_memory(target, bpaddr, 2, 2, sdbbp_buf);
687  if (retval != ERROR_OK)
688  return retval;
689 
690  if (target_buffer_get_u32(target, sdbbp_buf) != sdbbp32_instr)
691  verify = 0;
692  }
693 
694  if (verify == 0) {
695  LOG_ERROR("Unable to set 32bit breakpoint at address %08" TARGET_PRIxADDR
696  " - check that memory is read/writable", breakpoint->address);
697  return ERROR_OK;
698  }
699 
700  } else {
701  uint16_t verify = 0xffff;
702 
703  retval = target_read_memory(target, bpaddr, bplength, 1, breakpoint->orig_instr);
704  if (retval != ERROR_OK)
705  return retval;
706 
707  retval = target_write_u16(target, bpaddr, MIPS16_SDBBP(isa_req));
708  if (retval != ERROR_OK)
709  return retval;
710 
711  retval = target_read_u16(target, bpaddr, &verify);
712  if (retval != ERROR_OK)
713  return retval;
714 
715  if (verify != MIPS16_SDBBP(isa_req)) {
716  LOG_ERROR("Unable to set 16bit breakpoint at address %08" TARGET_PRIxADDR
717  " - check that memory is read/writable", breakpoint->address);
718  return ERROR_OK;
719  }
720  }
721 
722  breakpoint->is_set = true;
723  }
724 
725  return ERROR_OK;
726 }
727 
729  struct breakpoint *breakpoint)
730 {
731  /* get pointers to arch-specific information */
732  struct mips32_common *mips32 = target_to_mips32(target);
733  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
734  struct mips32_comparator *comparator_list = mips32->inst_break_list;
735  int retval;
736 
737  if (!breakpoint->is_set) {
738  LOG_WARNING("breakpoint not set");
739  return ERROR_OK;
740  }
741 
742  if (breakpoint->type == BKPT_HARD) {
743  int bp_num = breakpoint->number;
744  if (bp_num >= mips32->num_inst_bpoints) {
745  LOG_DEBUG("Invalid FP Comparator number in breakpoint (bpid: %" PRIu32 ")",
747  return ERROR_OK;
748  }
749  LOG_DEBUG("bpid: %" PRIu32 " - releasing hw: %d",
751  bp_num);
752  comparator_list[bp_num].used = 0;
753  comparator_list[bp_num].bp_value = 0;
754  target_write_u32(target, comparator_list[bp_num].reg_address +
755  ejtag_info->ejtag_ibc_offs, 0);
756 
757  } else {
758  /* restore original instruction (kept in target endianness) */
759  uint32_t isa_req = breakpoint->length & 1;
760  uint32_t bplength = breakpoint->length & ~1;
761  uint8_t current_instr[4];
762  LOG_DEBUG("bpid: %" PRIu32, breakpoint->unique_id);
763  if (bplength == 4) {
764  uint32_t sdbbp32_instr = MIPS32_SDBBP(isa_req);
765  if (ejtag_info->endianness && isa_req)
766  sdbbp32_instr = SWAP16(sdbbp32_instr);
767 
768  if ((breakpoint->address & 3) == 0) { /* 32bit aligned */
769  /* check that user program has not modified breakpoint instruction */
770  retval = target_read_memory(target, breakpoint->address, 4, 1, current_instr);
771  if (retval != ERROR_OK)
772  return retval;
778  if (sdbbp32_instr == target_buffer_get_u32(target, current_instr)) {
779  retval = target_write_memory(target, breakpoint->address, 4, 1,
781  if (retval != ERROR_OK)
782  return retval;
783  }
784  } else { /* 16bit aligned */
785  retval = target_read_memory(target, breakpoint->address, 2, 2, current_instr);
786  if (retval != ERROR_OK)
787  return retval;
788 
789  if (sdbbp32_instr == target_buffer_get_u32(target, current_instr)) {
790  retval = target_write_memory(target, breakpoint->address, 2, 2,
792  if (retval != ERROR_OK)
793  return retval;
794  }
795  }
796  } else {
797  /* check that user program has not modified breakpoint instruction */
798  retval = target_read_memory(target, breakpoint->address, 2, 1, current_instr);
799  if (retval != ERROR_OK)
800  return retval;
801 
802  if (target_buffer_get_u16(target, current_instr) == MIPS16_SDBBP(isa_req)) {
803  retval = target_write_memory(target, breakpoint->address, 2, 1,
805  if (retval != ERROR_OK)
806  return retval;
807  }
808  }
809  }
810 
811  breakpoint->is_set = false;
812 
813  return ERROR_OK;
814 }
815 
817 {
818  struct mips32_common *mips32 = target_to_mips32(target);
819 
820  if ((breakpoint->length > 5 || breakpoint->length < 2) || /* out of range */
821  (breakpoint->length == 4 && (breakpoint->address & 2)) || /* mips32 unaligned */
822  (mips32->isa_imp == MIPS32_ONLY && breakpoint->length != 4) || /* misp32 specific */
823  ((mips32->isa_imp & 1) != (breakpoint->length & 1))) /* isa not implemented */
825 
826  if (breakpoint->type == BKPT_HARD) {
827  if (mips32->num_inst_bpoints_avail < 1) {
828  LOG_INFO("no hardware breakpoint available");
830  }
831 
832  mips32->num_inst_bpoints_avail--;
833  }
834 
836 }
837 
839  struct breakpoint *breakpoint)
840 {
841  /* get pointers to arch-specific information */
842  struct mips32_common *mips32 = target_to_mips32(target);
843 
844  if (target->state != TARGET_HALTED) {
845  LOG_WARNING("target not halted");
847  }
848 
849  if (breakpoint->is_set)
851 
852  if (breakpoint->type == BKPT_HARD)
853  mips32->num_inst_bpoints_avail++;
854 
855  return ERROR_OK;
856 }
857 
859  struct watchpoint *watchpoint)
860 {
861  struct mips32_common *mips32 = target_to_mips32(target);
862  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
863  struct mips32_comparator *comparator_list = mips32->data_break_list;
864  int wp_num = 0;
865  /*
866  * watchpoint enabled, ignore all byte lanes in value register
867  * and exclude both load and store accesses from watchpoint
868  * condition evaluation
869  */
871  (0xff << EJTAG_DBCN_BLM_SHIFT);
872 
873  if (watchpoint->is_set) {
874  LOG_WARNING("watchpoint already set");
875  return ERROR_OK;
876  }
877 
878  while (comparator_list[wp_num].used && (wp_num < mips32->num_data_bpoints))
879  wp_num++;
880  if (wp_num >= mips32->num_data_bpoints) {
881  LOG_ERROR("Can not find free FP Comparator");
882  return ERROR_FAIL;
883  }
884 
885  if (watchpoint->length != 4) {
886  LOG_ERROR("Only watchpoints of length 4 are supported");
888  }
889 
890  if (watchpoint->address % 4) {
891  LOG_ERROR("Watchpoints address should be word aligned");
893  }
894 
895  switch (watchpoint->rw) {
896  case WPT_READ:
897  enable &= ~EJTAG_DBCN_NOLB;
898  break;
899  case WPT_WRITE:
900  enable &= ~EJTAG_DBCN_NOSB;
901  break;
902  case WPT_ACCESS:
903  enable &= ~(EJTAG_DBCN_NOLB | EJTAG_DBCN_NOSB);
904  break;
905  default:
906  LOG_ERROR("BUG: watchpoint->rw neither read, write nor access");
907  }
908 
909  watchpoint_set(watchpoint, wp_num);
910  comparator_list[wp_num].used = 1;
911  comparator_list[wp_num].bp_value = watchpoint->address;
912 
913  /* EJTAG 2.0 uses 29bit DBA. First 3 bits are reserved.
914  * There is as well no ASID register support. */
915  if (ejtag_info->ejtag_version == EJTAG_VERSION_20)
916  comparator_list[wp_num].bp_value &= 0xFFFFFFF8;
917  else
918  target_write_u32(target, comparator_list[wp_num].reg_address +
919  ejtag_info->ejtag_dbasid_offs, 0x00000000);
920 
921  target_write_u32(target, comparator_list[wp_num].reg_address,
922  comparator_list[wp_num].bp_value);
923  target_write_u32(target, comparator_list[wp_num].reg_address +
924  ejtag_info->ejtag_dbm_offs, 0x00000000);
925 
926  target_write_u32(target, comparator_list[wp_num].reg_address +
927  ejtag_info->ejtag_dbc_offs, enable);
928  /* TODO: probably this value is ignored on 2.0 */
929  target_write_u32(target, comparator_list[wp_num].reg_address +
930  ejtag_info->ejtag_dbv_offs, 0);
931  LOG_DEBUG("wp_num %i bp_value 0x%" PRIx32 "", wp_num, comparator_list[wp_num].bp_value);
932 
933  return ERROR_OK;
934 }
935 
937  struct watchpoint *watchpoint)
938 {
939  /* get pointers to arch-specific information */
940  struct mips32_common *mips32 = target_to_mips32(target);
941  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
942  struct mips32_comparator *comparator_list = mips32->data_break_list;
943 
944  if (!watchpoint->is_set) {
945  LOG_WARNING("watchpoint not set");
946  return ERROR_OK;
947  }
948 
949  int wp_num = watchpoint->number;
950  if (wp_num >= mips32->num_data_bpoints) {
951  LOG_DEBUG("Invalid FP Comparator number in watchpoint");
952  return ERROR_OK;
953  }
954  comparator_list[wp_num].used = 0;
955  comparator_list[wp_num].bp_value = 0;
956  target_write_u32(target, comparator_list[wp_num].reg_address +
957  ejtag_info->ejtag_dbc_offs, 0);
958  watchpoint->is_set = false;
959 
960  return ERROR_OK;
961 }
962 
964 {
965  struct mips32_common *mips32 = target_to_mips32(target);
966 
967  if (mips32->num_data_bpoints_avail < 1) {
968  LOG_INFO("no hardware watchpoints available");
970  }
971 
972  mips32->num_data_bpoints_avail--;
973 
975  return ERROR_OK;
976 }
977 
979  struct watchpoint *watchpoint)
980 {
981  /* get pointers to arch-specific information */
982  struct mips32_common *mips32 = target_to_mips32(target);
983 
984  if (target->state != TARGET_HALTED) {
985  LOG_WARNING("target not halted");
987  }
988 
989  if (watchpoint->is_set)
991 
992  mips32->num_data_bpoints_avail++;
993 
994  return ERROR_OK;
995 }
996 
998 {
1000 
1001  /* set any pending watchpoints */
1002  while (watchpoint) {
1003  if (!watchpoint->is_set)
1006  }
1007 }
1008 
1010  uint32_t size, uint32_t count, uint8_t *buffer)
1011 {
1012  struct mips32_common *mips32 = target_to_mips32(target);
1013  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1014 
1015  LOG_DEBUG("address: " TARGET_ADDR_FMT ", size: 0x%8.8" PRIx32 ", count: 0x%8.8" PRIx32 "",
1016  address, size, count);
1017 
1018  if (target->state != TARGET_HALTED) {
1019  LOG_WARNING("target not halted");
1020  return ERROR_TARGET_NOT_HALTED;
1021  }
1022 
1023  /* sanitize arguments */
1024  if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !(buffer))
1026 
1027  if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u)))
1029 
1030  if (size == 4 && count > 32) {
1032  if (retval == ERROR_OK)
1033  return ERROR_OK;
1034  LOG_WARNING("Falling back to non-bulk read");
1035  }
1036  /* since we don't know if buffer is aligned, we allocate new mem that is always aligned */
1037  void *t = NULL;
1038 
1039  if (size > 1) {
1040  t = malloc(count * size * sizeof(uint8_t));
1041  if (!t) {
1042  LOG_ERROR("Out of memory");
1043  return ERROR_FAIL;
1044  }
1045  } else
1046  t = buffer;
1047 
1048  /* if noDMA off, use DMAACC mode for memory read */
1049  int retval;
1050  if (ejtag_info->impcode & EJTAG_IMP_NODMA)
1051  retval = mips32_pracc_read_mem(ejtag_info, address, size, count, t);
1052  else
1053  retval = mips32_dmaacc_read_mem(ejtag_info, address, size, count, t);
1054 
1055  /* mips32_..._read_mem with size 4/2 returns uint32_t/uint16_t in host */
1056  /* endianness, but byte array should represent target endianness */
1057  if (retval == ERROR_OK) {
1058  switch (size) {
1059  case 4:
1061  break;
1062  case 2:
1064  break;
1065  }
1066  }
1067 
1068  if (size > 1)
1069  free(t);
1070 
1071  return retval;
1072 }
1073 
1075  uint32_t size, uint32_t count, const uint8_t *buffer)
1076 {
1077  struct mips32_common *mips32 = target_to_mips32(target);
1078  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1079 
1080  LOG_DEBUG("address: " TARGET_ADDR_FMT ", size: 0x%8.8" PRIx32 ", count: 0x%8.8" PRIx32 "",
1081  address, size, count);
1082 
1083  if (target->state != TARGET_HALTED) {
1084  LOG_WARNING("target not halted");
1085  return ERROR_TARGET_NOT_HALTED;
1086  }
1087 
1088  if (size == 4 && count > 32) {
1090  if (retval == ERROR_OK)
1091  return ERROR_OK;
1092  LOG_WARNING("Falling back to non-bulk write");
1093  }
1094 
1095  /* sanitize arguments */
1096  if (((size != 4) && (size != 2) && (size != 1)) || (count == 0) || !(buffer))
1098 
1099  if (((size == 4) && (address & 0x3u)) || ((size == 2) && (address & 0x1u)))
1101 
1103  void *t = NULL;
1104  if (size > 1) {
1105  /* mips32_..._write_mem with size 4/2 requires uint32_t/uint16_t in host */
1106  /* endianness, but byte array represents target endianness */
1107  t = malloc(count * size * sizeof(uint8_t));
1108  if (!t) {
1109  LOG_ERROR("Out of memory");
1110  return ERROR_FAIL;
1111  }
1112 
1113  switch (size) {
1114  case 4:
1115  target_buffer_get_u32_array(target, buffer, count, (uint32_t *)t);
1116  break;
1117  case 2:
1118  target_buffer_get_u16_array(target, buffer, count, (uint16_t *)t);
1119  break;
1120  }
1121  buffer = t;
1122  }
1123 
1124  /* if noDMA off, use DMAACC mode for memory write */
1125  int retval;
1126  if (ejtag_info->impcode & EJTAG_IMP_NODMA)
1127  retval = mips32_pracc_write_mem(ejtag_info, address, size, count, buffer);
1128  else
1129  retval = mips32_dmaacc_write_mem(ejtag_info, address, size, count, buffer);
1130 
1131  free(t);
1132 
1133  if (retval != ERROR_OK)
1134  return retval;
1135 
1136  return ERROR_OK;
1137 }
1138 
1139 static int mips_m4k_init_target(struct command_context *cmd_ctx,
1140  struct target *target)
1141 {
1143 
1144  return ERROR_OK;
1145 }
1146 
1148  struct mips_m4k_common *mips_m4k, struct jtag_tap *tap)
1149 {
1150  struct mips32_common *mips32 = &mips_m4k->mips32;
1151 
1152  mips_m4k->common_magic = MIPSM4K_COMMON_MAGIC;
1153 
1154  /* initialize mips4k specific info */
1155  mips32_init_arch_info(target, mips32, tap);
1156  mips32->arch_info = mips_m4k;
1157 
1158  return ERROR_OK;
1159 }
1160 
1161 static int mips_m4k_target_create(struct target *target, Jim_Interp *interp)
1162 {
1163  struct mips_m4k_common *mips_m4k = calloc(1, sizeof(struct mips_m4k_common));
1164 
1166 
1167  return ERROR_OK;
1168 }
1169 
1170 static int mips_m4k_examine(struct target *target)
1171 {
1172  struct mips_m4k_common *mips_m4k = target_to_m4k(target);
1173  struct mips_ejtag *ejtag_info = &mips_m4k->mips32.ejtag_info;
1174 
1175  if (!target_was_examined(target)) {
1176  int retval = mips_ejtag_get_idcode(ejtag_info);
1177  if (retval != ERROR_OK) {
1178  LOG_ERROR("idcode read failed");
1179  return retval;
1180  }
1181  if (((ejtag_info->idcode >> 1) & 0x7FF) == 0x29) {
1182  /* we are using a pic32mx so select ejtag port
1183  * as it is not selected by default */
1184  mips_ejtag_set_instr(ejtag_info, MTAP_SW_ETAP);
1185  LOG_DEBUG("PIC32 Detected - using EJTAG Interface");
1186  mips_m4k->is_pic32mx = true;
1187  }
1188  }
1189 
1190  /* init rest of ejtag interface */
1191  int retval = mips_ejtag_init(ejtag_info);
1192  if (retval != ERROR_OK)
1193  return retval;
1194 
1195  return mips32_examine(target);
1196 }
1197 
1199  uint32_t count, const uint8_t *buffer)
1200 {
1201  struct mips32_common *mips32 = target_to_mips32(target);
1202  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1203  struct working_area *fast_data_area;
1204  int retval;
1205  int write_t = 1;
1206 
1207  LOG_DEBUG("address: " TARGET_ADDR_FMT ", count: 0x%8.8" PRIx32 "",
1208  address, count);
1209 
1210  /* check alignment */
1211  if (address & 0x3u)
1213 
1214  if (!mips32->fast_data_area) {
1215  /* Get memory for block write handler
1216  * we preserve this area between calls and gain a speed increase
1217  * of about 3kb/sec when writing flash
1218  * this will be released/nulled by the system when the target is resumed or reset */
1221  &mips32->fast_data_area);
1222  if (retval != ERROR_OK) {
1223  LOG_ERROR("No working area available");
1224  return retval;
1225  }
1226 
1227  /* reset fastadata state so the algo get reloaded */
1228  ejtag_info->fast_access_save = -1;
1229  }
1230 
1231  fast_data_area = mips32->fast_data_area;
1232 
1233  if (address < (fast_data_area->address + fast_data_area->size) &&
1234  fast_data_area->address < (address + count)) {
1235  LOG_ERROR("fast_data (" TARGET_ADDR_FMT ") is within write area "
1236  "(" TARGET_ADDR_FMT "-" TARGET_ADDR_FMT ").",
1237  fast_data_area->address, address, address + count);
1238  LOG_ERROR("Change work-area-phys or load_image address!");
1239  return ERROR_FAIL;
1240  }
1241 
1242  /* mips32_pracc_fastdata_xfer requires uint32_t in host endianness, */
1243  /* but byte array represents target endianness */
1244  uint32_t *t = NULL;
1245  t = malloc(count * sizeof(uint32_t));
1246  if (!t) {
1247  LOG_ERROR("Out of memory");
1248  return ERROR_FAIL;
1249  }
1250 
1252 
1253  retval = mips32_pracc_fastdata_xfer(ejtag_info, mips32->fast_data_area, write_t, address,
1254  count, t);
1255 
1256  free(t);
1257 
1258  if (retval != ERROR_OK)
1259  LOG_ERROR("Fastdata access Failed");
1260 
1261  return retval;
1262 }
1263 
1265  uint32_t count, uint8_t *buffer)
1266 {
1267  struct mips32_common *mips32 = target_to_mips32(target);
1268  struct mips_ejtag *ejtag_info = &mips32->ejtag_info;
1269  struct working_area *fast_data_area;
1270  int retval;
1271  int write_t = 0;
1272 
1273  LOG_DEBUG("address: " TARGET_ADDR_FMT ", count: 0x%8.8" PRIx32 "",
1274  address, count);
1275 
1276  /* check alignment */
1277  if (address & 0x3u)
1279 
1280  if (!mips32->fast_data_area) {
1281  /* Get memory for block read handler
1282  * we preserve this area between calls and gain a speed increase
1283  * of about 3kb/sec when reading flash
1284  * this will be released/nulled by the system when the target is resumed or reset */
1287  &mips32->fast_data_area);
1288  if (retval != ERROR_OK) {
1289  LOG_ERROR("No working area available");
1290  return retval;
1291  }
1292 
1293  /* reset fastadata state so the algo get reloaded */
1294  ejtag_info->fast_access_save = -1;
1295  }
1296 
1297  fast_data_area = mips32->fast_data_area;
1298 
1299  if (address < (fast_data_area->address + fast_data_area->size) &&
1300  fast_data_area->address < (address + count)) {
1301  LOG_ERROR("fast_data (" TARGET_ADDR_FMT ") is within read area "
1302  "(" TARGET_ADDR_FMT "-" TARGET_ADDR_FMT ").",
1303  fast_data_area->address, address, address + count);
1304  LOG_ERROR("Change work-area-phys or load_image address!");
1305  return ERROR_FAIL;
1306  }
1307 
1308  /* mips32_pracc_fastdata_xfer requires uint32_t in host endianness, */
1309  /* but byte array represents target endianness */
1310  uint32_t *t = malloc(count * sizeof(uint32_t));
1311  if (!t) {
1312  LOG_ERROR("Out of memory");
1313  return ERROR_FAIL;
1314  }
1315 
1316  retval = mips32_pracc_fastdata_xfer(ejtag_info, mips32->fast_data_area, write_t, address,
1317  count, t);
1318 
1320 
1321  free(t);
1322 
1323  if (retval != ERROR_OK)
1324  LOG_ERROR("Fastdata access Failed");
1325 
1326  return retval;
1327 }
1328 
1330  struct mips_m4k_common *mips_m4k)
1331 {
1332  if (mips_m4k->common_magic != MIPSM4K_COMMON_MAGIC) {
1333  command_print(cmd, "target is not an MIPS_M4K");
1334  return ERROR_TARGET_INVALID;
1335  }
1336  return ERROR_OK;
1337 }
1338 
1339 COMMAND_HANDLER(mips_m4k_handle_cp0_command)
1340 {
1341  int retval;
1343  struct mips_m4k_common *mips_m4k = target_to_m4k(target);
1344  struct mips_ejtag *ejtag_info = &mips_m4k->mips32.ejtag_info;
1345 
1346  retval = mips_m4k_verify_pointer(CMD, mips_m4k);
1347  if (retval != ERROR_OK)
1348  return retval;
1349 
1350  if (target->state != TARGET_HALTED) {
1351  command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME);
1352  return ERROR_OK;
1353  }
1354 
1355  /* two or more argument, access a single register/select (write if third argument is given) */
1356  if (CMD_ARGC < 2)
1358  else {
1359  uint32_t cp0_reg, cp0_sel;
1360  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], cp0_reg);
1361  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], cp0_sel);
1362 
1363  if (CMD_ARGC == 2) {
1364  uint32_t value;
1365  retval = mips32_cp0_read(ejtag_info, &value, cp0_reg, cp0_sel);
1366  if (retval != ERROR_OK) {
1368  "couldn't access reg %" PRIu32,
1369  cp0_reg);
1370  return ERROR_OK;
1371  }
1372  command_print(CMD, "cp0 reg %" PRIu32 ", select %" PRIu32 ": %8.8" PRIx32,
1373  cp0_reg, cp0_sel, value);
1374 
1375  } else if (CMD_ARGC == 3) {
1376  uint32_t value;
1377  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], value);
1378  retval = mips32_cp0_write(ejtag_info, value, cp0_reg, cp0_sel);
1379  if (retval != ERROR_OK) {
1381  "couldn't access cp0 reg %" PRIu32 ", select %" PRIu32,
1382  cp0_reg, cp0_sel);
1383  return ERROR_OK;
1384  }
1385  command_print(CMD, "cp0 reg %" PRIu32 ", select %" PRIu32 ": %8.8" PRIx32,
1386  cp0_reg, cp0_sel, value);
1387  }
1388  }
1389 
1390  return ERROR_OK;
1391 }
1392 
1393 COMMAND_HANDLER(mips_m4k_handle_scan_delay_command)
1394 {
1396  struct mips_m4k_common *mips_m4k = target_to_m4k(target);
1397  struct mips_ejtag *ejtag_info = &mips_m4k->mips32.ejtag_info;
1398 
1399  if (CMD_ARGC == 1)
1400  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], ejtag_info->scan_delay);
1401  else if (CMD_ARGC > 1)
1403 
1404  command_print(CMD, "scan delay: %d nsec", ejtag_info->scan_delay);
1405  if (ejtag_info->scan_delay >= MIPS32_SCAN_DELAY_LEGACY_MODE) {
1406  ejtag_info->mode = 0;
1407  command_print(CMD, "running in legacy mode");
1408  } else {
1409  ejtag_info->mode = 1;
1410  command_print(CMD, "running in fast queued mode");
1411  }
1412 
1413  return ERROR_OK;
1414 }
1415 
1416 static const struct command_registration mips_m4k_exec_command_handlers[] = {
1417  {
1418  .name = "cp0",
1419  .handler = mips_m4k_handle_cp0_command,
1420  .mode = COMMAND_EXEC,
1421  .usage = "regnum [value]",
1422  .help = "display/modify cp0 register",
1423  },
1424  {
1425  .name = "scan_delay",
1426  .handler = mips_m4k_handle_scan_delay_command,
1427  .mode = COMMAND_ANY,
1428  .help = "display/set scan delay in nano seconds",
1429  .usage = "[value]",
1430  },
1431  {
1432  .chain = smp_command_handlers,
1433  },
1435 };
1436 
1437 static const struct command_registration mips_m4k_command_handlers[] = {
1438  {
1440  },
1441  {
1442  .name = "mips_m4k",
1443  .mode = COMMAND_ANY,
1444  .help = "mips_m4k command group",
1445  .usage = "",
1447  },
1449 };
1450 
1451 struct target_type mips_m4k_target = {
1452  .name = "mips_m4k",
1453 
1454  .poll = mips_m4k_poll,
1455  .arch_state = mips32_arch_state,
1456 
1457  .halt = mips_m4k_halt,
1458  .resume = mips_m4k_resume,
1459  .step = mips_m4k_step,
1460 
1461  .assert_reset = mips_m4k_assert_reset,
1462  .deassert_reset = mips_m4k_deassert_reset,
1463 
1464  .get_gdb_reg_list = mips32_get_gdb_reg_list,
1465 
1466  .read_memory = mips_m4k_read_memory,
1467  .write_memory = mips_m4k_write_memory,
1468  .checksum_memory = mips32_checksum_memory,
1469  .blank_check_memory = mips32_blank_check_memory,
1470 
1471  .run_algorithm = mips32_run_algorithm,
1472 
1473  .add_breakpoint = mips_m4k_add_breakpoint,
1474  .remove_breakpoint = mips_m4k_remove_breakpoint,
1475  .add_watchpoint = mips_m4k_add_watchpoint,
1476  .remove_watchpoint = mips_m4k_remove_watchpoint,
1477 
1478  .commands = mips_m4k_command_handlers,
1479  .target_create = mips_m4k_target_create,
1480  .init_target = mips_m4k_init_target,
1481  .examine = mips_m4k_examine,
1482 };
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
struct breakpoint * breakpoint_find(struct target *target, target_addr_t address)
Definition: breakpoints.c:489
@ BKPT_HARD
Definition: breakpoints.h:18
@ BKPT_SOFT
Definition: breakpoints.h:19
static void watchpoint_set(struct watchpoint *watchpoint, unsigned int number)
Definition: breakpoints.h:83
static void breakpoint_hw_set(struct breakpoint *breakpoint, unsigned int hw_number)
Definition: breakpoints.h:66
@ WPT_ACCESS
Definition: breakpoints.h:23
@ WPT_READ
Definition: breakpoints.h:23
@ WPT_WRITE
Definition: breakpoints.h:23
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
Definition: command.h:166
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#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:442
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
void jtag_add_reset(int req_tlr_or_trst, int req_srst)
A reset of the TAP state machine can be requested.
Definition: jtag/core.c:771
static enum reset_types jtag_reset_config
Definition: jtag/core.c:89
int jtag_get_srst(void)
Definition: jtag/core.c:1760
void jtag_add_sleep(uint32_t us)
Definition: jtag/core.c:883
enum reset_types jtag_get_reset_config(void)
Definition: jtag/core.c:1747
reset_types
Definition: jtag.h:215
@ RESET_SRST_NO_GATING
Definition: jtag.h:224
@ RESET_HAS_SRST
Definition: jtag.h:218
@ RESET_SRST_PULLS_TRST
Definition: jtag.h:220
#define LOG_WARNING(expr ...)
Definition: log.h:130
#define ERROR_FAIL
Definition: log.h:174
#define LOG_TARGET_ERROR(target, fmt_str,...)
Definition: log.h:162
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
struct reg_cache * mips32_build_reg_cache(struct target *target)
Definition: mips32.c:501
const struct command_registration mips32_command_handlers[]
Definition: mips32.c:2414
int mips32_read_config_regs(struct target *target)
Definition: mips32.c:1155
int mips32_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Definition: mips32.c:1229
int mips32_configure_break_unit(struct target *target)
Definition: mips32.c:804
int mips32_arch_state(struct target *target)
Definition: mips32.c:484
int mips32_cpu_probe(struct target *target)
mips32_cpu_probe - Detects processor type and applies necessary quirks.
Definition: mips32.c:995
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
int mips32_examine(struct target *target)
Definition: mips32.c:732
int mips32_init_arch_info(struct target *target, struct mips32_common *mips32, struct jtag_tap *tap)
Definition: mips32.c:560
int mips32_save_context(struct target *target)
Definition: mips32.c:446
int mips32_enable_interrupts(struct target *target, int enable)
Definition: mips32.c:860
int mips32_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Checks whether a memory region is erased.
Definition: mips32.c:1312
int mips32_restore_context(struct target *target)
Definition: mips32.c:468
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
#define MIPS32_SCAN_DELAY_LEGACY_MODE
Definition: mips32.h:70
static struct mips32_common * target_to_mips32(struct target *target)
Definition: mips32.h:444
#define MIPS32_SDBBP(isa)
Definition: mips32.h:780
#define MIPS32_REGLIST_C0_PC_INDEX
Definition: mips32.h:236
@ MIPS32_ONLY
Definition: mips32.h:256
@ MIPS32_ISA_MIPS16E
Definition: mips32.h:251
@ MIPS32_ISA_MMIPS32
Definition: mips32.h:252
@ MIPS32_ISA_MIPS32
Definition: mips32.h:250
#define MIPS16_SDBBP(isa)
Definition: mips32.h:782
int mips32_dmaacc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf)
int mips32_dmaacc_write_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, const void *buf)
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
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)
int mips32_pracc_read_mem(struct mips_ejtag *ejtag_info, uint32_t addr, int size, int count, void *buf)
Definition: mips32_pracc.c:469
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
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 MIPS32_FASTDATA_HANDLER_SIZE
Definition: mips32_pracc.h:30
#define SWAP16(v)
Definition: mips32_pracc.h:34
int mips_ejtag_get_idcode(struct mips_ejtag *ejtag_info)
Definition: mips_ejtag.c:42
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_drscan_8_out(struct mips_ejtag *ejtag_info, uint8_t data)
Definition: mips_ejtag.c:171
int mips_ejtag_exit_debug(struct mips_ejtag *ejtag_info)
Definition: mips_ejtag.c:258
int mips_ejtag_enter_debug(struct mips_ejtag *ejtag_info)
Definition: mips_ejtag.c:231
int mips_ejtag_config_step(struct mips_ejtag *ejtag_info, int enable_step)
Definition: mips_ejtag.c:186
int mips_ejtag_init(struct mips_ejtag *ejtag_info)
Definition: mips_ejtag.c:360
#define EJTAG_VERSION_20
Definition: mips_ejtag.h:168
#define EJTAG_INST_CONTROL
Definition: mips_ejtag.h:20
#define EJTAG_CTRL_DBGISA
Definition: mips_ejtag.h:55
#define EJTAG_INST_NORMALBOOT
Definition: mips_ejtag.h:23
#define MTAP_SW_ETAP
Definition: mips_ejtag.h:37
#define EJTAG_DCR_IB
Definition: mips_ejtag.h:129
#define EJTAG_CTRL_PERRST
Definition: mips_ejtag.h:62
#define EJTAG_DBCN_NOSB
Definition: mips_ejtag.h:162
#define MCHP_DE_ASSERT_RST
Definition: mips_ejtag.h:42
#define EJTAG_CTRL_BRKST
Definition: mips_ejtag.h:49
#define EJTAG_CTRL_ROCC
Definition: mips_ejtag.h:65
#define EJTAG_DBCN_BLM_SHIFT
Definition: mips_ejtag.h:165
#define EJTAG_DBCN_BE
Definition: mips_ejtag.h:166
#define EJTAG_DCR_DB
Definition: mips_ejtag.h:128
#define MTAP_COMMAND
Definition: mips_ejtag.h:38
#define EJTAG_DBCN_NOLB
Definition: mips_ejtag.h:163
#define EJTAG_INST_EJTAGBOOT
Definition: mips_ejtag.h:22
#define MCHP_ASERT_RST
Definition: mips_ejtag.h:41
#define EJTAG_IMP_NODMA
Definition: mips_ejtag.h:113
#define EJTAG_CTRL_PRRST
Definition: mips_ejtag.h:58
#define MTAP_SW_MTAP
Definition: mips_ejtag.h:36
static int mips_m4k_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Definition: mips_m4k.c:526
static int mips_m4k_deassert_reset(struct target *target)
Definition: mips_m4k.c:372
static int mips_m4k_bulk_write_memory(struct target *target, target_addr_t address, uint32_t count, const uint8_t *buffer)
Definition: mips_m4k.c:1198
static int mips_m4k_assert_reset(struct target *target)
Definition: mips_m4k.c:292
static int mips_m4k_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: mips_m4k.c:963
static int mips_m4k_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: mips_m4k.c:978
static int mips_m4k_bulk_read_memory(struct target *target, target_addr_t address, uint32_t count, uint8_t *buffer)
Definition: mips_m4k.c:1264
static int mips_m4k_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: mips_m4k.c:816
static int mips_m4k_examine_debug_reason(struct target *target)
Definition: mips_m4k.c:42
static int mips_m4k_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: mips_m4k.c:1074
static int mips_m4k_single_step_core(struct target *target)
Definition: mips_m4k.c:382
static int mips_m4k_verify_pointer(struct command_invocation *cmd, struct mips_m4k_common *mips_m4k)
Definition: mips_m4k.c:1329
static int update_halt_gdb(struct target *target)
Definition: mips_m4k.c:152
static int mips_m4k_halt_smp(struct target *target)
Definition: mips_m4k.c:133
static int mips_m4k_examine(struct target *target)
Definition: mips_m4k.c:1170
static int mips_m4k_init_arch_info(struct target *target, struct mips_m4k_common *mips_m4k, struct jtag_tap *tap)
Definition: mips_m4k.c:1147
static int mips_m4k_unset_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: mips_m4k.c:728
static struct target * get_mips_m4k(struct target *target, int32_t coreid)
Definition: mips_m4k.c:121
static int mips_m4k_restore_smp(struct target *target, uint32_t address, bool handle_breakpoints)
Definition: mips_m4k.c:401
static int mips_m4k_set_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: mips_m4k.c:597
static int mips_m4k_debug_entry(struct target *target)
Definition: mips_m4k.c:87
static const struct command_registration mips_m4k_exec_command_handlers[]
Definition: mips_m4k.c:1416
static const struct command_registration mips_m4k_command_handlers[]
Definition: mips_m4k.c:1437
static int mips_m4k_unset_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: mips_m4k.c:936
static int mips_m4k_set_watchpoint(struct target *target, struct watchpoint *watchpoint)
Definition: mips_m4k.c:858
static int mips_m4k_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: mips_m4k.c:1139
static int mips_m4k_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Definition: mips_m4k.c:499
static int mips_m4k_target_create(struct target *target, Jim_Interp *interp)
Definition: mips_m4k.c:1161
static int mips_m4k_halt(struct target *target)
Definition: mips_m4k.c:255
COMMAND_HANDLER(mips_m4k_handle_cp0_command)
Definition: mips_m4k.c:1339
static int mips_m4k_poll(struct target *target)
Definition: mips_m4k.c:163
struct target_type mips_m4k_target
Definition: mips_m4k.c:1451
static int mips_m4k_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: mips_m4k.c:1009
static void mips_m4k_enable_breakpoints(struct target *target)
Definition: mips_m4k.c:585
static int mips_m4k_internal_restore(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Definition: mips_m4k.c:425
static int mips_m4k_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: mips_m4k.c:838
static void mips_m4k_enable_watchpoints(struct target *target)
Definition: mips_m4k.c:997
static struct mips_m4k_common * target_to_m4k(struct target *target)
Definition: mips_m4k.h:29
#define MIPSM4K_COMMON_MAGIC
Definition: mips_m4k.h:18
static void mips_m4k_isa_filter(enum mips32_isa_imp isa_imp, target_addr_t *addr)
Definition: mips_m4k.h:35
void register_cache_invalidate(struct reg_cache *cache)
Marks the contents of the register cache as invalid (and clean).
Definition: register.c:94
struct target * target
Definition: rtt/rtt.c:26
const struct command_registration smp_command_handlers[]
Definition: smp.c:153
#define foreach_smp_target(pos, head)
Definition: smp.h:15
struct breakpoint * next
Definition: breakpoints.h:34
unsigned int length
Definition: breakpoints.h:29
uint8_t * orig_instr
Definition: breakpoints.h:33
enum breakpoint_type type
Definition: breakpoints.h:30
uint32_t unique_id
Definition: breakpoints.h:35
bool is_set
Definition: breakpoints.h:31
unsigned int number
Definition: breakpoints.h:32
target_addr_t address
Definition: breakpoints.h:27
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:235
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
Definition: command.h:249
int32_t core[2]
Definition: target.h:100
struct target * target
Definition: target.h:95
Definition: jtag.h:101
int num_data_bpoints
Definition: mips32.h:432
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
int num_data_bpoints_avail
Definition: mips32.h:434
int num_inst_bpoints
Definition: mips32.h:431
enum mips32_isa_imp isa_imp
Definition: mips32.h:401
enum mips32_isa_mode isa_mode
Definition: mips32.h:400
void * arch_info
Definition: mips32.h:394
struct reg_cache * core_cache
Definition: mips32.h:395
int num_inst_bpoints_avail
Definition: mips32.h:433
uint32_t bp_value
Definition: mips32.h:379
uint32_t reg_address
Definition: mips32.h:380
uint32_t ejtag_dbm_offs
Definition: mips_ejtag.h:237
uint32_t ejtag_ctrl
Definition: mips_ejtag.h:210
uint32_t ejtag_ibm_offs
Definition: mips_ejtag.h:231
unsigned int scan_delay
Definition: mips_ejtag.h:217
uint32_t idcode
Definition: mips_ejtag.h:208
uint32_t ejtag_dbasid_offs
Definition: mips_ejtag.h:239
unsigned int ejtag_version
Definition: mips_ejtag.h:221
uint32_t impcode
Definition: mips_ejtag.h:207
uint32_t ejtag_ibc_offs
Definition: mips_ejtag.h:230
uint32_t endianness
Definition: mips_ejtag.h:223
struct jtag_tap * tap
Definition: mips_ejtag.h:206
uint32_t ejtag_dbv_offs
Definition: mips_ejtag.h:238
uint32_t ejtag_ibs_addr
Definition: mips_ejtag.h:228
int fast_access_save
Definition: mips_ejtag.h:211
uint32_t ejtag_dbc_offs
Definition: mips_ejtag.h:236
uint32_t ejtag_dbs_addr
Definition: mips_ejtag.h:234
uint32_t debug_caps
Definition: mips_ejtag.h:227
uint32_t isa
Definition: mips_ejtag.h:222
bool is_pic32mx
Definition: mips_m4k.h:25
struct mips32_common mips32
Definition: mips_m4k.h:23
unsigned int common_magic
Definition: mips_m4k.h:21
struct reg * reg_list
Definition: register.h:147
bool valid
Definition: register.h:126
uint8_t * value
Definition: register.h:122
bool dirty
Definition: register.h:124
struct target * target
Definition: target.h:214
This holds methods shared between all instances of a given target type.
Definition: target_type.h:26
const char * name
Name of this type of target.
Definition: target_type.h:31
Definition: target.h:116
int32_t coreid
Definition: target.h:120
struct gdb_service * gdb_service
Definition: target.h:199
struct jtag_tap * tap
Definition: target.h:119
enum target_debug_reason debug_reason
Definition: target.h:154
enum target_state state
Definition: target.h:157
struct list_head * smp_targets
Definition: target.h:188
struct breakpoint * breakpoints
Definition: target.h:159
unsigned int smp
Definition: target.h:187
struct watchpoint * watchpoints
Definition: target.h:160
bool reset_halt
Definition: target.h:144
enum watchpoint_rw rw
Definition: breakpoints.h:46
bool is_set
Definition: breakpoints.h:47
struct watchpoint * next
Definition: breakpoints.h:49
unsigned int length
Definition: breakpoints.h:43
unsigned int number
Definition: breakpoints.h:48
target_addr_t address
Definition: breakpoints.h:42
uint32_t size
Definition: target.h:87
bool free
Definition: target.h:88
target_addr_t address
Definition: target.h:86
void target_buffer_get_u16_array(struct target *target, const uint8_t *buffer, uint32_t count, uint16_t *dstbuf)
Definition: target.c:401
int target_call_event_callbacks(struct target *target, enum target_event event)
Definition: target.c:1765
void target_free_all_working_areas(struct target *target)
Definition: target.c:2151
int target_halt(struct target *target)
Definition: target.c:507
void target_buffer_set_u32(struct target *target, uint8_t *buffer, uint32_t value)
Definition: target.c:352
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
Definition: target.c:2663
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
Definition: target.c:1266
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
Definition: target.c:2061
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
Definition: target.c:2642
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
Definition: target.c:260
static int srst_asserted
Definition: target.c:2850
int target_read_u16(struct target *target, target_addr_t address, uint16_t *value)
Definition: target.c:2575
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
Definition: target.c:2551
uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer)
Definition: target.c:334
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
Definition: target.c:1238
bool target_has_event_action(const struct target *target, enum target_event event)
Returns true only if the target has a handler for the specified event.
Definition: target.c:4867
void target_buffer_set_u16_array(struct target *target, uint8_t *buffer, uint32_t count, const uint16_t *srcbuf)
Definition: target.c:425
void target_buffer_get_u32_array(struct target *target, const uint8_t *buffer, uint32_t count, uint32_t *dstbuf)
Definition: target.c:393
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:458
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
Definition: target.c:417
void target_handle_event(struct target *target, enum target_event e)
Definition: target.c:4674
uint32_t target_buffer_get_u32(struct target *target, const uint8_t *buffer)
Definition: target.c:316
@ DBG_REASON_NOTHALTED
Definition: target.h:74
@ DBG_REASON_DBGRQ
Definition: target.h:69
@ DBG_REASON_SINGLESTEP
Definition: target.h:73
@ DBG_REASON_WATCHPOINT
Definition: target.h:71
@ DBG_REASON_BREAKPOINT
Definition: target.h:70
#define ERROR_TARGET_NOT_HALTED
Definition: target.h:790
static bool target_was_examined(const struct target *target)
Definition: target.h:436
#define ERROR_TARGET_UNALIGNED_ACCESS
Definition: target.h:792
#define ERROR_TARGET_INVALID
Definition: target.h:787
@ TARGET_EVENT_DEBUG_RESUMED
Definition: target.h:272
@ TARGET_EVENT_HALTED
Definition: target.h:252
@ TARGET_EVENT_RESUMED
Definition: target.h:253
@ TARGET_EVENT_DEBUG_HALTED
Definition: target.h:271
@ TARGET_EVENT_RESET_ASSERT
Definition: target.h:264
target_state
Definition: target.h:53
@ TARGET_RESET
Definition: target.h:57
@ TARGET_DEBUG_RUNNING
Definition: target.h:58
@ TARGET_UNKNOWN
Definition: target.h:54
@ TARGET_HALTED
Definition: target.h:56
@ TARGET_RUNNING
Definition: target.h:55
#define ERROR_TARGET_NOT_EXAMINED
Definition: target.h:797
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
Definition: target.h:794
#define ERROR_TARGET_FAILURE
Definition: target.h:791
#define TARGET_ADDR_FMT
Definition: types.h:342
uint64_t target_addr_t
Definition: types.h:335
#define TARGET_PRIxADDR
Definition: types.h:340
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t count[4]
Definition: vdebug.c:22