1 /***************************************************************************
2 * Copyright (C) 2008 by Spencer Oliver *
3 * spen@spen-soft.co.uk *
5 * Copyright (C) 2008 by David T.L. Wong *
7 * Copyright (C) 2009 by David N. Claffey <dnclaffey@gmail.com> *
9 * Copyright (C) 2011 by Drasko DRASKOVIC *
10 * drasko.draskovic@gmail.com *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 * This program is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20 * GNU General Public License for more details. *
22 * You should have received a copy of the GNU General Public License *
23 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
24 ***************************************************************************/
30 #include "breakpoints.h"
33 #include "mips32_dmaacc.h"
34 #include "target_type.h"
37 static void mips_m4k_enable_breakpoints(struct target
*target
);
38 static void mips_m4k_enable_watchpoints(struct target
*target
);
39 static int mips_m4k_set_breakpoint(struct target
*target
,
40 struct breakpoint
*breakpoint
);
41 static int mips_m4k_unset_breakpoint(struct target
*target
,
42 struct breakpoint
*breakpoint
);
43 static int mips_m4k_internal_restore(struct target
*target
, int current
,
44 target_addr_t address
, int handle_breakpoints
,
46 static int mips_m4k_halt(struct target
*target
);
47 static int mips_m4k_bulk_write_memory(struct target
*target
, target_addr_t address
,
48 uint32_t count
, const uint8_t *buffer
);
50 static int mips_m4k_examine_debug_reason(struct target
*target
)
52 struct mips32_common
*mips32
= target_to_mips32(target
);
53 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
54 uint32_t break_status
;
57 if ((target
->debug_reason
!= DBG_REASON_DBGRQ
)
58 && (target
->debug_reason
!= DBG_REASON_SINGLESTEP
)) {
59 if (ejtag_info
->debug_caps
& EJTAG_DCR_IB
) {
60 /* get info about inst breakpoint support */
61 retval
= target_read_u32(target
,
62 ejtag_info
->ejtag_ibs_addr
, &break_status
);
63 if (retval
!= ERROR_OK
)
65 if (break_status
& 0x1f) {
66 /* we have halted on a breakpoint */
67 retval
= target_write_u32(target
,
68 ejtag_info
->ejtag_ibs_addr
, 0);
69 if (retval
!= ERROR_OK
)
71 target
->debug_reason
= DBG_REASON_BREAKPOINT
;
75 if (ejtag_info
->debug_caps
& EJTAG_DCR_DB
) {
76 /* get info about data breakpoint support */
77 retval
= target_read_u32(target
,
78 ejtag_info
->ejtag_dbs_addr
, &break_status
);
79 if (retval
!= ERROR_OK
)
81 if (break_status
& 0x1f) {
82 /* we have halted on a breakpoint */
83 retval
= target_write_u32(target
,
84 ejtag_info
->ejtag_dbs_addr
, 0);
85 if (retval
!= ERROR_OK
)
87 target
->debug_reason
= DBG_REASON_WATCHPOINT
;
95 static int mips_m4k_debug_entry(struct target
*target
)
97 struct mips32_common
*mips32
= target_to_mips32(target
);
98 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
100 mips32_save_context(target
);
102 /* make sure stepping disabled, SSt bit in CP0 debug register cleared */
103 mips_ejtag_config_step(ejtag_info
, 0);
105 /* make sure break unit configured */
106 mips32_configure_break_unit(target
);
108 /* attempt to find halt reason */
109 mips_m4k_examine_debug_reason(target
);
111 mips32_read_config_regs(target
);
113 /* default to mips32 isa, it will be changed below if required */
114 mips32
->isa_mode
= MIPS32_ISA_MIPS32
;
116 /* other than mips32 only and isa bit set ? */
117 if (mips32
->isa_imp
&& buf_get_u32(mips32
->core_cache
->reg_list
[MIPS32_PC
].value
, 0, 1))
118 mips32
->isa_mode
= mips32
->isa_imp
== 2 ? MIPS32_ISA_MIPS16E
: MIPS32_ISA_MMIPS32
;
120 LOG_DEBUG("entered debug state at PC 0x%" PRIx32
", target->state: %s",
121 buf_get_u32(mips32
->core_cache
->reg_list
[MIPS32_PC
].value
, 0, 32),
122 target_state_name(target
));
127 static struct target
*get_mips_m4k(struct target
*target
, int32_t coreid
)
129 struct target_list
*head
;
133 while (head
!= (struct target_list
*)NULL
) {
135 if ((curr
->coreid
== coreid
) && (curr
->state
== TARGET_HALTED
))
142 static int mips_m4k_halt_smp(struct target
*target
)
144 int retval
= ERROR_OK
;
145 struct target_list
*head
;
148 while (head
!= (struct target_list
*)NULL
) {
151 if ((curr
!= target
) && (curr
->state
!= TARGET_HALTED
))
152 ret
= mips_m4k_halt(curr
);
154 if (ret
!= ERROR_OK
) {
155 LOG_ERROR("halt failed target->coreid: %" PRId32
, curr
->coreid
);
163 static int update_halt_gdb(struct target
*target
)
165 int retval
= ERROR_OK
;
166 if (target
->gdb_service
->core
[0] == -1) {
167 target
->gdb_service
->target
= target
;
168 target
->gdb_service
->core
[0] = target
->coreid
;
169 retval
= mips_m4k_halt_smp(target
);
174 static int mips_m4k_poll(struct target
*target
)
176 int retval
= ERROR_OK
;
177 struct mips32_common
*mips32
= target_to_mips32(target
);
178 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
179 uint32_t ejtag_ctrl
= ejtag_info
->ejtag_ctrl
;
180 enum target_state prev_target_state
= target
->state
;
182 /* toggle to another core is done by gdb as follow */
183 /* maint packet J core_id */
185 /* the next polling trigger an halt event sent to gdb */
186 if ((target
->state
== TARGET_HALTED
) && (target
->smp
) &&
187 (target
->gdb_service
) &&
188 (target
->gdb_service
->target
== NULL
)) {
189 target
->gdb_service
->target
=
190 get_mips_m4k(target
, target
->gdb_service
->core
[1]);
191 target_call_event_callbacks(target
, TARGET_EVENT_HALTED
);
195 /* read ejtag control reg */
196 mips_ejtag_set_instr(ejtag_info
, EJTAG_INST_CONTROL
);
197 retval
= mips_ejtag_drscan_32(ejtag_info
, &ejtag_ctrl
);
198 if (retval
!= ERROR_OK
)
201 ejtag_info
->isa
= (ejtag_ctrl
& EJTAG_CTRL_DBGISA
) ? 1 : 0;
203 /* clear this bit before handling polling
204 * as after reset registers will read zero */
205 if (ejtag_ctrl
& EJTAG_CTRL_ROCC
) {
206 /* we have detected a reset, clear flag
207 * otherwise ejtag will not work */
208 ejtag_ctrl
= ejtag_info
->ejtag_ctrl
& ~EJTAG_CTRL_ROCC
;
210 mips_ejtag_set_instr(ejtag_info
, EJTAG_INST_CONTROL
);
211 retval
= mips_ejtag_drscan_32(ejtag_info
, &ejtag_ctrl
);
212 if (retval
!= ERROR_OK
)
214 LOG_DEBUG("Reset Detected");
217 /* check for processor halted */
218 if (ejtag_ctrl
& EJTAG_CTRL_BRKST
) {
219 if ((target
->state
!= TARGET_HALTED
)
220 && (target
->state
!= TARGET_DEBUG_RUNNING
)) {
221 if (target
->state
== TARGET_UNKNOWN
)
222 LOG_DEBUG("EJTAG_CTRL_BRKST already set during server startup.");
224 /* OpenOCD was was probably started on the board with EJTAG_CTRL_BRKST already set
225 * (maybe put on by HALT-ing the board in the previous session).
227 * Force enable debug entry for this session.
229 mips_ejtag_set_instr(ejtag_info
, EJTAG_INST_NORMALBOOT
);
230 target
->state
= TARGET_HALTED
;
231 retval
= mips_m4k_debug_entry(target
);
232 if (retval
!= ERROR_OK
)
236 ((prev_target_state
== TARGET_RUNNING
)
237 || (prev_target_state
== TARGET_RESET
))) {
238 retval
= update_halt_gdb(target
);
239 if (retval
!= ERROR_OK
)
242 target_call_event_callbacks(target
, TARGET_EVENT_HALTED
);
243 } else if (target
->state
== TARGET_DEBUG_RUNNING
) {
244 target
->state
= TARGET_HALTED
;
246 retval
= mips_m4k_debug_entry(target
);
247 if (retval
!= ERROR_OK
)
251 retval
= update_halt_gdb(target
);
252 if (retval
!= ERROR_OK
)
256 target_call_event_callbacks(target
, TARGET_EVENT_DEBUG_HALTED
);
259 target
->state
= TARGET_RUNNING
;
261 /* LOG_DEBUG("ctrl = 0x%08X", ejtag_ctrl); */
266 static int mips_m4k_halt(struct target
*target
)
268 struct mips32_common
*mips32
= target_to_mips32(target
);
269 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
271 LOG_DEBUG("target->state: %s", target_state_name(target
));
273 if (target
->state
== TARGET_HALTED
) {
274 LOG_DEBUG("target was already halted");
278 if (target
->state
== TARGET_UNKNOWN
)
279 LOG_WARNING("target was in unknown state when halt was requested");
281 if (target
->state
== TARGET_RESET
) {
282 if ((jtag_get_reset_config() & RESET_SRST_PULLS_TRST
) && jtag_get_srst()) {
283 LOG_ERROR("can't request a halt while in reset if nSRST pulls nTRST");
284 return ERROR_TARGET_FAILURE
;
286 /* we came here in a reset_halt or reset_init sequence
287 * debug entry was already prepared in mips_m4k_assert_reset()
289 target
->debug_reason
= DBG_REASON_DBGRQ
;
295 /* break processor */
296 mips_ejtag_enter_debug(ejtag_info
);
298 target
->debug_reason
= DBG_REASON_DBGRQ
;
303 static int mips_m4k_assert_reset(struct target
*target
)
305 struct mips_m4k_common
*mips_m4k
= target_to_m4k(target
);
306 struct mips_ejtag
*ejtag_info
= &mips_m4k
->mips32
.ejtag_info
;
308 /* TODO: apply hw reset signal in not examined state */
309 if (!(target_was_examined(target
))) {
310 LOG_WARNING("Reset is not asserted because the target is not examined.");
311 LOG_WARNING("Use a reset button or power cycle the target.");
312 return ERROR_TARGET_NOT_EXAMINED
;
315 LOG_DEBUG("target->state: %s",
316 target_state_name(target
));
318 enum reset_types jtag_reset_config
= jtag_get_reset_config();
320 /* some cores support connecting while srst is asserted
321 * use that mode is it has been configured */
323 bool srst_asserted
= false;
325 if (!(jtag_reset_config
& RESET_SRST_PULLS_TRST
) &&
326 (jtag_reset_config
& RESET_SRST_NO_GATING
)) {
327 jtag_add_reset(0, 1);
328 srst_asserted
= true;
332 /* EJTAG before v2.5/2.6 does not support EJTAGBOOT or NORMALBOOT */
333 if (ejtag_info
->ejtag_version
!= EJTAG_VERSION_20
) {
334 if (target
->reset_halt
) {
335 /* use hardware to catch reset */
336 mips_ejtag_set_instr(ejtag_info
, EJTAG_INST_EJTAGBOOT
);
338 mips_ejtag_set_instr(ejtag_info
, EJTAG_INST_NORMALBOOT
);
341 if (jtag_reset_config
& RESET_HAS_SRST
) {
342 /* here we should issue a srst only, but we may have to assert trst as well */
343 if (jtag_reset_config
& RESET_SRST_PULLS_TRST
)
344 jtag_add_reset(1, 1);
345 else if (!srst_asserted
)
346 jtag_add_reset(0, 1);
348 if (mips_m4k
->is_pic32mx
) {
349 LOG_DEBUG("Using MTAP reset to reset processor...");
351 /* use microchip specific MTAP reset */
352 mips_ejtag_set_instr(ejtag_info
, MTAP_SW_MTAP
);
353 mips_ejtag_set_instr(ejtag_info
, MTAP_COMMAND
);
355 mips_ejtag_drscan_8_out(ejtag_info
, MCHP_ASERT_RST
);
356 mips_ejtag_drscan_8_out(ejtag_info
, MCHP_DE_ASSERT_RST
);
357 mips_ejtag_set_instr(ejtag_info
, MTAP_SW_ETAP
);
359 /* use ejtag reset - not supported by all cores */
360 uint32_t ejtag_ctrl
= ejtag_info
->ejtag_ctrl
| EJTAG_CTRL_PRRST
| EJTAG_CTRL_PERRST
;
361 LOG_DEBUG("Using EJTAG reset (PRRST) to reset processor...");
362 mips_ejtag_set_instr(ejtag_info
, EJTAG_INST_CONTROL
);
363 mips_ejtag_drscan_32_out(ejtag_info
, ejtag_ctrl
);
367 target
->state
= TARGET_RESET
;
368 jtag_add_sleep(50000);
370 register_cache_invalidate(mips_m4k
->mips32
.core_cache
);
372 if (target
->reset_halt
) {
373 int retval
= target_halt(target
);
374 if (retval
!= ERROR_OK
)
381 static int mips_m4k_deassert_reset(struct target
*target
)
383 LOG_DEBUG("target->state: %s", target_state_name(target
));
385 /* deassert reset lines */
386 jtag_add_reset(0, 0);
391 static int mips_m4k_single_step_core(struct target
*target
)
393 struct mips32_common
*mips32
= target_to_mips32(target
);
394 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
396 /* configure single step mode */
397 mips_ejtag_config_step(ejtag_info
, 1);
399 /* disable interrupts while stepping */
400 mips32_enable_interrupts(target
, 0);
402 /* exit debug mode */
403 mips_ejtag_exit_debug(ejtag_info
);
405 mips_m4k_debug_entry(target
);
410 static int mips_m4k_restore_smp(struct target
*target
, uint32_t address
, int handle_breakpoints
)
412 int retval
= ERROR_OK
;
413 struct target_list
*head
;
417 while (head
!= (struct target_list
*)NULL
) {
420 if ((curr
!= target
) && (curr
->state
!= TARGET_RUNNING
)) {
421 /* resume current address , not in step mode */
422 ret
= mips_m4k_internal_restore(curr
, 1, address
,
423 handle_breakpoints
, 0);
425 if (ret
!= ERROR_OK
) {
426 LOG_ERROR("target->coreid :%" PRId32
" failed to resume at address :0x%" PRIx32
,
427 curr
->coreid
, address
);
436 static int mips_m4k_internal_restore(struct target
*target
, int current
,
437 target_addr_t address
, int handle_breakpoints
, int debug_execution
)
439 struct mips32_common
*mips32
= target_to_mips32(target
);
440 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
441 struct breakpoint
*breakpoint
= NULL
;
444 if (target
->state
!= TARGET_HALTED
) {
445 LOG_WARNING("target not halted");
446 return ERROR_TARGET_NOT_HALTED
;
449 if (!debug_execution
) {
450 target_free_all_working_areas(target
);
451 mips_m4k_enable_breakpoints(target
);
452 mips_m4k_enable_watchpoints(target
);
455 /* current = 1: continue on current pc, otherwise continue at <address> */
457 mips_m4k_isa_filter(mips32
->isa_imp
, &address
);
458 buf_set_u32(mips32
->core_cache
->reg_list
[MIPS32_PC
].value
, 0, 32, address
);
459 mips32
->core_cache
->reg_list
[MIPS32_PC
].dirty
= 1;
460 mips32
->core_cache
->reg_list
[MIPS32_PC
].valid
= 1;
463 if ((mips32
->isa_imp
> 1) && debug_execution
) /* if more than one isa supported */
464 buf_set_u32(mips32
->core_cache
->reg_list
[MIPS32_PC
].value
, 0, 1, mips32
->isa_mode
);
469 resume_pc
= buf_get_u32(mips32
->core_cache
->reg_list
[MIPS32_PC
].value
, 0, 32);
471 mips32_restore_context(target
);
473 /* the front-end may request us not to handle breakpoints */
474 if (handle_breakpoints
) {
475 /* Single step past breakpoint at current address */
476 breakpoint
= breakpoint_find(target
, resume_pc
);
478 LOG_DEBUG("unset breakpoint at " TARGET_ADDR_FMT
"",
479 breakpoint
->address
);
480 mips_m4k_unset_breakpoint(target
, breakpoint
);
481 mips_m4k_single_step_core(target
);
482 mips_m4k_set_breakpoint(target
, breakpoint
);
486 /* enable interrupts if we are running */
487 mips32_enable_interrupts(target
, !debug_execution
);
489 /* exit debug mode */
490 mips_ejtag_exit_debug(ejtag_info
);
491 target
->debug_reason
= DBG_REASON_NOTHALTED
;
493 /* registers are now invalid */
494 register_cache_invalidate(mips32
->core_cache
);
496 if (!debug_execution
) {
497 target
->state
= TARGET_RUNNING
;
498 target_call_event_callbacks(target
, TARGET_EVENT_RESUMED
);
499 LOG_DEBUG("target resumed at 0x%" PRIx32
"", resume_pc
);
501 target
->state
= TARGET_DEBUG_RUNNING
;
502 target_call_event_callbacks(target
, TARGET_EVENT_DEBUG_RESUMED
);
503 LOG_DEBUG("target debug resumed at 0x%" PRIx32
"", resume_pc
);
509 static int mips_m4k_resume(struct target
*target
, int current
,
510 target_addr_t address
, int handle_breakpoints
, int debug_execution
)
512 int retval
= ERROR_OK
;
514 /* dummy resume for smp toggle in order to reduce gdb impact */
515 if ((target
->smp
) && (target
->gdb_service
->core
[1] != -1)) {
516 /* simulate a start and halt of target */
517 target
->gdb_service
->target
= NULL
;
518 target
->gdb_service
->core
[0] = target
->gdb_service
->core
[1];
519 /* fake resume at next poll we play the target core[1], see poll*/
520 target_call_event_callbacks(target
, TARGET_EVENT_RESUMED
);
524 retval
= mips_m4k_internal_restore(target
, current
, address
,
528 if (retval
== ERROR_OK
&& target
->smp
) {
529 target
->gdb_service
->core
[0] = -1;
530 retval
= mips_m4k_restore_smp(target
, address
, handle_breakpoints
);
536 static int mips_m4k_step(struct target
*target
, int current
,
537 target_addr_t address
, int handle_breakpoints
)
539 /* get pointers to arch-specific information */
540 struct mips32_common
*mips32
= target_to_mips32(target
);
541 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
542 struct breakpoint
*breakpoint
= NULL
;
544 if (target
->state
!= TARGET_HALTED
) {
545 LOG_WARNING("target not halted");
546 return ERROR_TARGET_NOT_HALTED
;
549 /* current = 1: continue on current pc, otherwise continue at <address> */
551 mips_m4k_isa_filter(mips32
->isa_imp
, &address
);
552 buf_set_u32(mips32
->core_cache
->reg_list
[MIPS32_PC
].value
, 0, 32, address
);
553 mips32
->core_cache
->reg_list
[MIPS32_PC
].dirty
= 1;
554 mips32
->core_cache
->reg_list
[MIPS32_PC
].valid
= 1;
557 /* the front-end may request us not to handle breakpoints */
558 if (handle_breakpoints
) {
559 breakpoint
= breakpoint_find(target
,
560 buf_get_u32(mips32
->core_cache
->reg_list
[MIPS32_PC
].value
, 0, 32));
562 mips_m4k_unset_breakpoint(target
, breakpoint
);
565 /* restore context */
566 mips32_restore_context(target
);
568 /* configure single step mode */
569 mips_ejtag_config_step(ejtag_info
, 1);
571 target
->debug_reason
= DBG_REASON_SINGLESTEP
;
573 target_call_event_callbacks(target
, TARGET_EVENT_RESUMED
);
575 /* disable interrupts while stepping */
576 mips32_enable_interrupts(target
, 0);
578 /* exit debug mode */
579 mips_ejtag_exit_debug(ejtag_info
);
581 /* registers are now invalid */
582 register_cache_invalidate(mips32
->core_cache
);
584 LOG_DEBUG("target stepped ");
585 mips_m4k_debug_entry(target
);
588 mips_m4k_set_breakpoint(target
, breakpoint
);
590 target_call_event_callbacks(target
, TARGET_EVENT_HALTED
);
595 static void mips_m4k_enable_breakpoints(struct target
*target
)
597 struct breakpoint
*breakpoint
= target
->breakpoints
;
599 /* set any pending breakpoints */
601 if (breakpoint
->set
== 0)
602 mips_m4k_set_breakpoint(target
, breakpoint
);
603 breakpoint
= breakpoint
->next
;
607 static int mips_m4k_set_breakpoint(struct target
*target
,
608 struct breakpoint
*breakpoint
)
610 struct mips32_common
*mips32
= target_to_mips32(target
);
611 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
612 struct mips32_comparator
*comparator_list
= mips32
->inst_break_list
;
615 if (breakpoint
->set
) {
616 LOG_WARNING("breakpoint already set");
620 if (breakpoint
->type
== BKPT_HARD
) {
623 while (comparator_list
[bp_num
].used
&& (bp_num
< mips32
->num_inst_bpoints
))
625 if (bp_num
>= mips32
->num_inst_bpoints
) {
626 LOG_ERROR("Can not find free FP Comparator(bpid: %" PRIu32
")",
627 breakpoint
->unique_id
);
628 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
630 breakpoint
->set
= bp_num
+ 1;
631 comparator_list
[bp_num
].used
= 1;
632 comparator_list
[bp_num
].bp_value
= breakpoint
->address
;
634 if (breakpoint
->length
!= 4) /* make sure isa bit set */
635 comparator_list
[bp_num
].bp_value
|= 1;
636 else /* make sure isa bit cleared */
637 comparator_list
[bp_num
].bp_value
&= ~1;
639 /* EJTAG 2.0 uses 30bit IBA. First 2 bits are reserved.
640 * Warning: there is no IB ASID registers in 2.0.
641 * Do not set it! :) */
642 if (ejtag_info
->ejtag_version
== EJTAG_VERSION_20
)
643 comparator_list
[bp_num
].bp_value
&= 0xFFFFFFFC;
645 target_write_u32(target
, comparator_list
[bp_num
].reg_address
,
646 comparator_list
[bp_num
].bp_value
);
647 target_write_u32(target
, comparator_list
[bp_num
].reg_address
+
648 ejtag_info
->ejtag_ibm_offs
, 0x00000000);
649 target_write_u32(target
, comparator_list
[bp_num
].reg_address
+
650 ejtag_info
->ejtag_ibc_offs
, 1);
651 LOG_DEBUG("bpid: %" PRIu32
", bp_num %i bp_value 0x%" PRIx32
"",
652 breakpoint
->unique_id
,
653 bp_num
, comparator_list
[bp_num
].bp_value
);
654 } else if (breakpoint
->type
== BKPT_SOFT
) {
655 LOG_DEBUG("bpid: %" PRIu32
, breakpoint
->unique_id
);
657 uint32_t isa_req
= breakpoint
->length
& 1; /* micro mips request bit */
658 uint32_t bplength
= breakpoint
->length
& ~1; /* drop micro mips request bit for length */
659 uint32_t bpaddr
= breakpoint
->address
& ~1; /* drop isa bit from address, if set */
662 uint32_t verify
= 0xffffffff;
663 uint32_t sdbbp32_instr
= MIPS32_SDBBP(isa_req
);
664 if (ejtag_info
->endianness
&& isa_req
)
665 sdbbp32_instr
= SWAP16(sdbbp32_instr
);
667 if ((breakpoint
->address
& 3) == 0) { /* word alligned */
669 retval
= target_read_memory(target
, bpaddr
, bplength
, 1, breakpoint
->orig_instr
);
670 if (retval
!= ERROR_OK
)
673 retval
= target_write_u32(target
, bpaddr
, sdbbp32_instr
);
674 if (retval
!= ERROR_OK
)
677 retval
= target_read_u32(target
, bpaddr
, &verify
);
678 if (retval
!= ERROR_OK
)
681 if (verify
!= sdbbp32_instr
)
684 } else { /* 16 bit aligned */
685 retval
= target_read_memory(target
, bpaddr
, 2, 2, breakpoint
->orig_instr
);
686 if (retval
!= ERROR_OK
)
689 uint8_t sdbbp_buf
[4];
690 target_buffer_set_u32(target
, sdbbp_buf
, sdbbp32_instr
);
692 retval
= target_write_memory(target
, bpaddr
, 2, 2, sdbbp_buf
);
693 if (retval
!= ERROR_OK
)
696 retval
= target_read_memory(target
, bpaddr
, 2, 2, sdbbp_buf
);
697 if (retval
!= ERROR_OK
)
700 if (target_buffer_get_u32(target
, sdbbp_buf
) != sdbbp32_instr
)
705 LOG_ERROR("Unable to set 32bit breakpoint at address %08" PRIx64
706 " - check that memory is read/writable", breakpoint
->address
);
711 uint16_t verify
= 0xffff;
713 retval
= target_read_memory(target
, bpaddr
, bplength
, 1, breakpoint
->orig_instr
);
714 if (retval
!= ERROR_OK
)
717 retval
= target_write_u16(target
, bpaddr
, MIPS16_SDBBP(isa_req
));
718 if (retval
!= ERROR_OK
)
721 retval
= target_read_u16(target
, bpaddr
, &verify
);
722 if (retval
!= ERROR_OK
)
725 if (verify
!= MIPS16_SDBBP(isa_req
)) {
726 LOG_ERROR("Unable to set 16bit breakpoint at address %08" PRIx64
727 " - check that memory is read/writable", breakpoint
->address
);
732 breakpoint
->set
= 20; /* Any nice value but 0 */
738 static int mips_m4k_unset_breakpoint(struct target
*target
,
739 struct breakpoint
*breakpoint
)
741 /* get pointers to arch-specific information */
742 struct mips32_common
*mips32
= target_to_mips32(target
);
743 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
744 struct mips32_comparator
*comparator_list
= mips32
->inst_break_list
;
747 if (!breakpoint
->set
) {
748 LOG_WARNING("breakpoint not set");
752 if (breakpoint
->type
== BKPT_HARD
) {
753 int bp_num
= breakpoint
->set
- 1;
754 if ((bp_num
< 0) || (bp_num
>= mips32
->num_inst_bpoints
)) {
755 LOG_DEBUG("Invalid FP Comparator number in breakpoint (bpid: %" PRIu32
")",
756 breakpoint
->unique_id
);
759 LOG_DEBUG("bpid: %" PRIu32
" - releasing hw: %d",
760 breakpoint
->unique_id
,
762 comparator_list
[bp_num
].used
= 0;
763 comparator_list
[bp_num
].bp_value
= 0;
764 target_write_u32(target
, comparator_list
[bp_num
].reg_address
+
765 ejtag_info
->ejtag_ibc_offs
, 0);
768 /* restore original instruction (kept in target endianness) */
769 uint32_t isa_req
= breakpoint
->length
& 1;
770 uint32_t bplength
= breakpoint
->length
& ~1;
771 uint8_t current_instr
[4];
772 LOG_DEBUG("bpid: %" PRIu32
, breakpoint
->unique_id
);
774 uint32_t sdbbp32_instr
= MIPS32_SDBBP(isa_req
);
775 if (ejtag_info
->endianness
&& isa_req
)
776 sdbbp32_instr
= SWAP16(sdbbp32_instr
);
778 if ((breakpoint
->address
& 3) == 0) { /* 32bit aligned */
779 /* check that user program has not modified breakpoint instruction */
780 retval
= target_read_memory(target
, breakpoint
->address
, 4, 1, current_instr
);
781 if (retval
!= ERROR_OK
)
784 * target_read_memory() gets us data in _target_ endianess.
785 * If we want to use this data on the host for comparisons with some macros
786 * we must first transform it to _host_ endianess using target_buffer_get_u16().
788 if (sdbbp32_instr
== target_buffer_get_u32(target
, current_instr
)) {
789 retval
= target_write_memory(target
, breakpoint
->address
, 4, 1,
790 breakpoint
->orig_instr
);
791 if (retval
!= ERROR_OK
)
794 } else { /* 16bit alligned */
795 retval
= target_read_memory(target
, breakpoint
->address
, 2, 2, current_instr
);
796 if (retval
!= ERROR_OK
)
799 if (sdbbp32_instr
== target_buffer_get_u32(target
, current_instr
)) {
800 retval
= target_write_memory(target
, breakpoint
->address
, 2, 2,
801 breakpoint
->orig_instr
);
802 if (retval
!= ERROR_OK
)
807 /* check that user program has not modified breakpoint instruction */
808 retval
= target_read_memory(target
, breakpoint
->address
, 2, 1, current_instr
);
809 if (retval
!= ERROR_OK
)
812 if (target_buffer_get_u16(target
, current_instr
) == MIPS16_SDBBP(isa_req
)) {
813 retval
= target_write_memory(target
, breakpoint
->address
, 2, 1,
814 breakpoint
->orig_instr
);
815 if (retval
!= ERROR_OK
)
826 static int mips_m4k_add_breakpoint(struct target
*target
, struct breakpoint
*breakpoint
)
828 struct mips32_common
*mips32
= target_to_mips32(target
);
830 if ((breakpoint
->length
> 5 || breakpoint
->length
< 2) || /* out of range */
831 (breakpoint
->length
== 4 && (breakpoint
->address
& 2)) || /* mips32 unaligned */
832 (mips32
->isa_imp
== MIPS32_ONLY
&& breakpoint
->length
!= 4) || /* misp32 specific */
833 ((mips32
->isa_imp
& 1) != (breakpoint
->length
& 1))) /* isa not implemented */
834 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
836 if (breakpoint
->type
== BKPT_HARD
) {
837 if (mips32
->num_inst_bpoints_avail
< 1) {
838 LOG_INFO("no hardware breakpoint available");
839 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
842 mips32
->num_inst_bpoints_avail
--;
845 return mips_m4k_set_breakpoint(target
, breakpoint
);
848 static int mips_m4k_remove_breakpoint(struct target
*target
,
849 struct breakpoint
*breakpoint
)
851 /* get pointers to arch-specific information */
852 struct mips32_common
*mips32
= target_to_mips32(target
);
854 if (target
->state
!= TARGET_HALTED
) {
855 LOG_WARNING("target not halted");
856 return ERROR_TARGET_NOT_HALTED
;
860 mips_m4k_unset_breakpoint(target
, breakpoint
);
862 if (breakpoint
->type
== BKPT_HARD
)
863 mips32
->num_inst_bpoints_avail
++;
868 static int mips_m4k_set_watchpoint(struct target
*target
,
869 struct watchpoint
*watchpoint
)
871 struct mips32_common
*mips32
= target_to_mips32(target
);
872 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
873 struct mips32_comparator
*comparator_list
= mips32
->data_break_list
;
876 * watchpoint enabled, ignore all byte lanes in value register
877 * and exclude both load and store accesses from watchpoint
878 * condition evaluation
880 int enable
= EJTAG_DBCn_NOSB
| EJTAG_DBCn_NOLB
| EJTAG_DBCn_BE
|
881 (0xff << EJTAG_DBCn_BLM_SHIFT
);
883 if (watchpoint
->set
) {
884 LOG_WARNING("watchpoint already set");
888 while (comparator_list
[wp_num
].used
&& (wp_num
< mips32
->num_data_bpoints
))
890 if (wp_num
>= mips32
->num_data_bpoints
) {
891 LOG_ERROR("Can not find free FP Comparator");
895 if (watchpoint
->length
!= 4) {
896 LOG_ERROR("Only watchpoints of length 4 are supported");
897 return ERROR_TARGET_UNALIGNED_ACCESS
;
900 if (watchpoint
->address
% 4) {
901 LOG_ERROR("Watchpoints address should be word aligned");
902 return ERROR_TARGET_UNALIGNED_ACCESS
;
905 switch (watchpoint
->rw
) {
907 enable
&= ~EJTAG_DBCn_NOLB
;
910 enable
&= ~EJTAG_DBCn_NOSB
;
913 enable
&= ~(EJTAG_DBCn_NOLB
| EJTAG_DBCn_NOSB
);
916 LOG_ERROR("BUG: watchpoint->rw neither read, write nor access");
919 watchpoint
->set
= wp_num
+ 1;
920 comparator_list
[wp_num
].used
= 1;
921 comparator_list
[wp_num
].bp_value
= watchpoint
->address
;
923 /* EJTAG 2.0 uses 29bit DBA. First 3 bits are reserved.
924 * There is as well no ASID register support. */
925 if (ejtag_info
->ejtag_version
== EJTAG_VERSION_20
)
926 comparator_list
[wp_num
].bp_value
&= 0xFFFFFFF8;
928 target_write_u32(target
, comparator_list
[wp_num
].reg_address
+
929 ejtag_info
->ejtag_dbasid_offs
, 0x00000000);
931 target_write_u32(target
, comparator_list
[wp_num
].reg_address
,
932 comparator_list
[wp_num
].bp_value
);
933 target_write_u32(target
, comparator_list
[wp_num
].reg_address
+
934 ejtag_info
->ejtag_dbm_offs
, 0x00000000);
936 target_write_u32(target
, comparator_list
[wp_num
].reg_address
+
937 ejtag_info
->ejtag_dbc_offs
, enable
);
938 /* TODO: probably this value is ignored on 2.0 */
939 target_write_u32(target
, comparator_list
[wp_num
].reg_address
+
940 ejtag_info
->ejtag_dbv_offs
, 0);
941 LOG_DEBUG("wp_num %i bp_value 0x%" PRIx32
"", wp_num
, comparator_list
[wp_num
].bp_value
);
946 static int mips_m4k_unset_watchpoint(struct target
*target
,
947 struct watchpoint
*watchpoint
)
949 /* get pointers to arch-specific information */
950 struct mips32_common
*mips32
= target_to_mips32(target
);
951 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
952 struct mips32_comparator
*comparator_list
= mips32
->data_break_list
;
954 if (!watchpoint
->set
) {
955 LOG_WARNING("watchpoint not set");
959 int wp_num
= watchpoint
->set
- 1;
960 if ((wp_num
< 0) || (wp_num
>= mips32
->num_data_bpoints
)) {
961 LOG_DEBUG("Invalid FP Comparator number in watchpoint");
964 comparator_list
[wp_num
].used
= 0;
965 comparator_list
[wp_num
].bp_value
= 0;
966 target_write_u32(target
, comparator_list
[wp_num
].reg_address
+
967 ejtag_info
->ejtag_dbc_offs
, 0);
973 static int mips_m4k_add_watchpoint(struct target
*target
, struct watchpoint
*watchpoint
)
975 struct mips32_common
*mips32
= target_to_mips32(target
);
977 if (mips32
->num_data_bpoints_avail
< 1) {
978 LOG_INFO("no hardware watchpoints available");
979 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
982 mips32
->num_data_bpoints_avail
--;
984 mips_m4k_set_watchpoint(target
, watchpoint
);
988 static int mips_m4k_remove_watchpoint(struct target
*target
,
989 struct watchpoint
*watchpoint
)
991 /* get pointers to arch-specific information */
992 struct mips32_common
*mips32
= target_to_mips32(target
);
994 if (target
->state
!= TARGET_HALTED
) {
995 LOG_WARNING("target not halted");
996 return ERROR_TARGET_NOT_HALTED
;
1000 mips_m4k_unset_watchpoint(target
, watchpoint
);
1002 mips32
->num_data_bpoints_avail
++;
1007 static void mips_m4k_enable_watchpoints(struct target
*target
)
1009 struct watchpoint
*watchpoint
= target
->watchpoints
;
1011 /* set any pending watchpoints */
1012 while (watchpoint
) {
1013 if (watchpoint
->set
== 0)
1014 mips_m4k_set_watchpoint(target
, watchpoint
);
1015 watchpoint
= watchpoint
->next
;
1019 static int mips_m4k_read_memory(struct target
*target
, target_addr_t address
,
1020 uint32_t size
, uint32_t count
, uint8_t *buffer
)
1022 struct mips32_common
*mips32
= target_to_mips32(target
);
1023 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
1025 LOG_DEBUG("address: " TARGET_ADDR_FMT
", size: 0x%8.8" PRIx32
", count: 0x%8.8" PRIx32
"",
1026 address
, size
, count
);
1028 if (target
->state
!= TARGET_HALTED
) {
1029 LOG_WARNING("target not halted");
1030 return ERROR_TARGET_NOT_HALTED
;
1033 /* sanitize arguments */
1034 if (((size
!= 4) && (size
!= 2) && (size
!= 1)) || (count
== 0) || !(buffer
))
1035 return ERROR_COMMAND_SYNTAX_ERROR
;
1037 if (((size
== 4) && (address
& 0x3u
)) || ((size
== 2) && (address
& 0x1u
)))
1038 return ERROR_TARGET_UNALIGNED_ACCESS
;
1040 /* since we don't know if buffer is aligned, we allocate new mem that is always aligned */
1044 t
= malloc(count
* size
* sizeof(uint8_t));
1046 LOG_ERROR("Out of memory");
1052 /* if noDMA off, use DMAACC mode for memory read */
1054 if (ejtag_info
->impcode
& EJTAG_IMP_NODMA
)
1055 retval
= mips32_pracc_read_mem(ejtag_info
, address
, size
, count
, t
);
1057 retval
= mips32_dmaacc_read_mem(ejtag_info
, address
, size
, count
, t
);
1059 /* mips32_..._read_mem with size 4/2 returns uint32_t/uint16_t in host */
1060 /* endianness, but byte array should represent target endianness */
1061 if (ERROR_OK
== retval
) {
1064 target_buffer_set_u32_array(target
, buffer
, count
, t
);
1067 target_buffer_set_u16_array(target
, buffer
, count
, t
);
1072 if ((size
> 1) && (t
!= NULL
))
1078 static int mips_m4k_write_memory(struct target
*target
, target_addr_t address
,
1079 uint32_t size
, uint32_t count
, const uint8_t *buffer
)
1081 struct mips32_common
*mips32
= target_to_mips32(target
);
1082 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
1084 LOG_DEBUG("address: " TARGET_ADDR_FMT
", size: 0x%8.8" PRIx32
", count: 0x%8.8" PRIx32
"",
1085 address
, size
, count
);
1087 if (target
->state
!= TARGET_HALTED
) {
1088 LOG_WARNING("target not halted");
1089 return ERROR_TARGET_NOT_HALTED
;
1092 if (size
== 4 && count
> 32) {
1093 int retval
= mips_m4k_bulk_write_memory(target
, address
, count
, buffer
);
1094 if (retval
== ERROR_OK
)
1096 LOG_WARNING("Falling back to non-bulk write");
1099 /* sanitize arguments */
1100 if (((size
!= 4) && (size
!= 2) && (size
!= 1)) || (count
== 0) || !(buffer
))
1101 return ERROR_COMMAND_SYNTAX_ERROR
;
1103 if (((size
== 4) && (address
& 0x3u
)) || ((size
== 2) && (address
& 0x1u
)))
1104 return ERROR_TARGET_UNALIGNED_ACCESS
;
1106 /** correct endianess if we have word or hword access */
1109 /* mips32_..._write_mem with size 4/2 requires uint32_t/uint16_t in host */
1110 /* endianness, but byte array represents target endianness */
1111 t
= malloc(count
* size
* sizeof(uint8_t));
1113 LOG_ERROR("Out of memory");
1119 target_buffer_get_u32_array(target
, buffer
, count
, (uint32_t *)t
);
1122 target_buffer_get_u16_array(target
, buffer
, count
, (uint16_t *)t
);
1128 /* if noDMA off, use DMAACC mode for memory write */
1130 if (ejtag_info
->impcode
& EJTAG_IMP_NODMA
)
1131 retval
= mips32_pracc_write_mem(ejtag_info
, address
, size
, count
, buffer
);
1133 retval
= mips32_dmaacc_write_mem(ejtag_info
, address
, size
, count
, buffer
);
1138 if (ERROR_OK
!= retval
)
1144 static int mips_m4k_init_target(struct command_context
*cmd_ctx
,
1145 struct target
*target
)
1147 mips32_build_reg_cache(target
);
1152 static int mips_m4k_init_arch_info(struct target
*target
,
1153 struct mips_m4k_common
*mips_m4k
, struct jtag_tap
*tap
)
1155 struct mips32_common
*mips32
= &mips_m4k
->mips32
;
1157 mips_m4k
->common_magic
= MIPSM4K_COMMON_MAGIC
;
1159 /* initialize mips4k specific info */
1160 mips32_init_arch_info(target
, mips32
, tap
);
1161 mips32
->arch_info
= mips_m4k
;
1166 static int mips_m4k_target_create(struct target
*target
, Jim_Interp
*interp
)
1168 struct mips_m4k_common
*mips_m4k
= calloc(1, sizeof(struct mips_m4k_common
));
1170 mips_m4k_init_arch_info(target
, mips_m4k
, target
->tap
);
1175 static int mips_m4k_examine(struct target
*target
)
1178 struct mips_m4k_common
*mips_m4k
= target_to_m4k(target
);
1179 struct mips_ejtag
*ejtag_info
= &mips_m4k
->mips32
.ejtag_info
;
1180 uint32_t idcode
= 0;
1182 if (!target_was_examined(target
)) {
1183 retval
= mips_ejtag_get_idcode(ejtag_info
, &idcode
);
1184 if (retval
!= ERROR_OK
)
1186 ejtag_info
->idcode
= idcode
;
1188 if (((idcode
>> 1) & 0x7FF) == 0x29) {
1189 /* we are using a pic32mx so select ejtag port
1190 * as it is not selected by default */
1191 mips_ejtag_set_instr(ejtag_info
, MTAP_SW_ETAP
);
1192 LOG_DEBUG("PIC32MX Detected - using EJTAG Interface");
1193 mips_m4k
->is_pic32mx
= true;
1197 /* init rest of ejtag interface */
1198 retval
= mips_ejtag_init(ejtag_info
);
1199 if (retval
!= ERROR_OK
)
1202 retval
= mips32_examine(target
);
1203 if (retval
!= ERROR_OK
)
1209 static int mips_m4k_bulk_write_memory(struct target
*target
, target_addr_t address
,
1210 uint32_t count
, const uint8_t *buffer
)
1212 struct mips32_common
*mips32
= target_to_mips32(target
);
1213 struct mips_ejtag
*ejtag_info
= &mips32
->ejtag_info
;
1214 struct working_area
*fast_data_area
;
1218 LOG_DEBUG("address: " TARGET_ADDR_FMT
", count: 0x%8.8" PRIx32
"",
1221 /* check alignment */
1223 return ERROR_TARGET_UNALIGNED_ACCESS
;
1225 if (mips32
->fast_data_area
== NULL
) {
1226 /* Get memory for block write handler
1227 * we preserve this area between calls and gain a speed increase
1228 * of about 3kb/sec when writing flash
1229 * this will be released/nulled by the system when the target is resumed or reset */
1230 retval
= target_alloc_working_area(target
,
1231 MIPS32_FASTDATA_HANDLER_SIZE
,
1232 &mips32
->fast_data_area
);
1233 if (retval
!= ERROR_OK
) {
1234 LOG_ERROR("No working area available");
1238 /* reset fastadata state so the algo get reloaded */
1239 ejtag_info
->fast_access_save
= -1;
1242 fast_data_area
= mips32
->fast_data_area
;
1244 if (address
<= fast_data_area
->address
+ fast_data_area
->size
&&
1245 fast_data_area
->address
<= address
+ count
) {
1246 LOG_ERROR("fast_data (" TARGET_ADDR_FMT
") is within write area "
1247 "(" TARGET_ADDR_FMT
"-" TARGET_ADDR_FMT
").",
1248 fast_data_area
->address
, address
, address
+ count
);
1249 LOG_ERROR("Change work-area-phys or load_image address!");
1253 /* mips32_pracc_fastdata_xfer requires uint32_t in host endianness, */
1254 /* but byte array represents target endianness */
1256 t
= malloc(count
* sizeof(uint32_t));
1258 LOG_ERROR("Out of memory");
1262 target_buffer_get_u32_array(target
, buffer
, count
, t
);
1264 retval
= mips32_pracc_fastdata_xfer(ejtag_info
, mips32
->fast_data_area
, write_t
, address
,
1270 if (retval
!= ERROR_OK
)
1271 LOG_ERROR("Fastdata access Failed");
1276 static int mips_m4k_verify_pointer(struct command_context
*cmd_ctx
,
1277 struct mips_m4k_common
*mips_m4k
)
1279 if (mips_m4k
->common_magic
!= MIPSM4K_COMMON_MAGIC
) {
1280 command_print(cmd_ctx
, "target is not an MIPS_M4K");
1281 return ERROR_TARGET_INVALID
;
1286 COMMAND_HANDLER(mips_m4k_handle_cp0_command
)
1289 struct target
*target
= get_current_target(CMD_CTX
);
1290 struct mips_m4k_common
*mips_m4k
= target_to_m4k(target
);
1291 struct mips_ejtag
*ejtag_info
= &mips_m4k
->mips32
.ejtag_info
;
1293 retval
= mips_m4k_verify_pointer(CMD_CTX
, mips_m4k
);
1294 if (retval
!= ERROR_OK
)
1297 if (target
->state
!= TARGET_HALTED
) {
1298 command_print(CMD_CTX
, "target must be stopped for \"%s\" command", CMD_NAME
);
1302 /* two or more argument, access a single register/select (write if third argument is given) */
1304 return ERROR_COMMAND_SYNTAX_ERROR
;
1306 uint32_t cp0_reg
, cp0_sel
;
1307 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], cp0_reg
);
1308 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[1], cp0_sel
);
1310 if (CMD_ARGC
== 2) {
1312 retval
= mips32_cp0_read(ejtag_info
, &value
, cp0_reg
, cp0_sel
);
1313 if (retval
!= ERROR_OK
) {
1314 command_print(CMD_CTX
,
1315 "couldn't access reg %" PRIi32
,
1319 command_print(CMD_CTX
, "cp0 reg %" PRIi32
", select %" PRIi32
": %8.8" PRIx32
,
1320 cp0_reg
, cp0_sel
, value
);
1322 } else if (CMD_ARGC
== 3) {
1324 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[2], value
);
1325 retval
= mips32_cp0_write(ejtag_info
, value
, cp0_reg
, cp0_sel
);
1326 if (retval
!= ERROR_OK
) {
1327 command_print(CMD_CTX
,
1328 "couldn't access cp0 reg %" PRIi32
", select %" PRIi32
,
1332 command_print(CMD_CTX
, "cp0 reg %" PRIi32
", select %" PRIi32
": %8.8" PRIx32
,
1333 cp0_reg
, cp0_sel
, value
);
1340 COMMAND_HANDLER(mips_m4k_handle_smp_off_command
)
1342 struct target
*target
= get_current_target(CMD_CTX
);
1343 /* check target is an smp target */
1344 struct target_list
*head
;
1345 struct target
*curr
;
1346 head
= target
->head
;
1348 if (head
!= (struct target_list
*)NULL
) {
1349 while (head
!= (struct target_list
*)NULL
) {
1350 curr
= head
->target
;
1354 /* fixes the target display to the debugger */
1355 target
->gdb_service
->target
= target
;
1360 COMMAND_HANDLER(mips_m4k_handle_smp_on_command
)
1362 struct target
*target
= get_current_target(CMD_CTX
);
1363 struct target_list
*head
;
1364 struct target
*curr
;
1365 head
= target
->head
;
1366 if (head
!= (struct target_list
*)NULL
) {
1368 while (head
!= (struct target_list
*)NULL
) {
1369 curr
= head
->target
;
1377 COMMAND_HANDLER(mips_m4k_handle_smp_gdb_command
)
1379 struct target
*target
= get_current_target(CMD_CTX
);
1380 int retval
= ERROR_OK
;
1381 struct target_list
*head
;
1382 head
= target
->head
;
1383 if (head
!= (struct target_list
*)NULL
) {
1384 if (CMD_ARGC
== 1) {
1386 COMMAND_PARSE_NUMBER(int, CMD_ARGV
[0], coreid
);
1387 if (ERROR_OK
!= retval
)
1389 target
->gdb_service
->core
[1] = coreid
;
1392 command_print(CMD_CTX
, "gdb coreid %" PRId32
" -> %" PRId32
, target
->gdb_service
->core
[0]
1393 , target
->gdb_service
->core
[1]);
1398 COMMAND_HANDLER(mips_m4k_handle_scan_delay_command
)
1400 struct target
*target
= get_current_target(CMD_CTX
);
1401 struct mips_m4k_common
*mips_m4k
= target_to_m4k(target
);
1402 struct mips_ejtag
*ejtag_info
= &mips_m4k
->mips32
.ejtag_info
;
1405 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], ejtag_info
->scan_delay
);
1406 else if (CMD_ARGC
> 1)
1407 return ERROR_COMMAND_SYNTAX_ERROR
;
1409 command_print(CMD_CTX
, "scan delay: %d nsec", ejtag_info
->scan_delay
);
1410 if (ejtag_info
->scan_delay
>= MIPS32_SCAN_DELAY_LEGACY_MODE
) {
1411 ejtag_info
->mode
= 0;
1412 command_print(CMD_CTX
, "running in legacy mode");
1414 ejtag_info
->mode
= 1;
1415 command_print(CMD_CTX
, "running in fast queued mode");
1421 static const struct command_registration mips_m4k_exec_command_handlers
[] = {
1424 .handler
= mips_m4k_handle_cp0_command
,
1425 .mode
= COMMAND_EXEC
,
1426 .usage
= "regnum [value]",
1427 .help
= "display/modify cp0 register",
1431 .handler
= mips_m4k_handle_smp_off_command
,
1432 .mode
= COMMAND_EXEC
,
1433 .help
= "Stop smp handling",
1438 .handler
= mips_m4k_handle_smp_on_command
,
1439 .mode
= COMMAND_EXEC
,
1440 .help
= "Restart smp handling",
1445 .handler
= mips_m4k_handle_smp_gdb_command
,
1446 .mode
= COMMAND_EXEC
,
1447 .help
= "display/fix current core played to gdb",
1451 .name
= "scan_delay",
1452 .handler
= mips_m4k_handle_scan_delay_command
,
1453 .mode
= COMMAND_ANY
,
1454 .help
= "display/set scan delay in nano seconds",
1457 COMMAND_REGISTRATION_DONE
1460 const struct command_registration mips_m4k_command_handlers
[] = {
1462 .chain
= mips32_command_handlers
,
1466 .mode
= COMMAND_ANY
,
1467 .help
= "mips_m4k command group",
1469 .chain
= mips_m4k_exec_command_handlers
,
1471 COMMAND_REGISTRATION_DONE
1474 struct target_type mips_m4k_target
= {
1477 .poll
= mips_m4k_poll
,
1478 .arch_state
= mips32_arch_state
,
1480 .halt
= mips_m4k_halt
,
1481 .resume
= mips_m4k_resume
,
1482 .step
= mips_m4k_step
,
1484 .assert_reset
= mips_m4k_assert_reset
,
1485 .deassert_reset
= mips_m4k_deassert_reset
,
1487 .get_gdb_reg_list
= mips32_get_gdb_reg_list
,
1489 .read_memory
= mips_m4k_read_memory
,
1490 .write_memory
= mips_m4k_write_memory
,
1491 .checksum_memory
= mips32_checksum_memory
,
1492 .blank_check_memory
= mips32_blank_check_memory
,
1494 .run_algorithm
= mips32_run_algorithm
,
1496 .add_breakpoint
= mips_m4k_add_breakpoint
,
1497 .remove_breakpoint
= mips_m4k_remove_breakpoint
,
1498 .add_watchpoint
= mips_m4k_add_watchpoint
,
1499 .remove_watchpoint
= mips_m4k_remove_watchpoint
,
1501 .commands
= mips_m4k_command_handlers
,
1502 .target_create
= mips_m4k_target_create
,
1503 .init_target
= mips_m4k_init_target
,
1504 .examine
= mips_m4k_examine
,