1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2013-2015,2019-2020 Synopsys, Inc. *
5 * Frank Dols <frank.dols@synopsys.com> *
6 * Mischa Jonker <mischa.jonker@synopsys.com> *
7 * Anton Kolesov <anton.kolesov@synopsys.com> *
8 * Evgeniy Didin <didin@synopsys.com> *
9 ***************************************************************************/
21 * ARC architecture specific details.
23 * ARC has two types of registers:
24 * 1) core registers(e.g. r0,r1..) [is_core = true]
25 * 2) Auxiliary registers [is_core = false]..
27 * Auxiliary registers at the same time can be divided into
28 * read-only BCR(build configuration regs, e.g. isa_config, mpu_build) and
29 * R/RW non-BCR ("control" register, e.g. pc, status32_t, debug).
31 * The way of accessing to Core and AUX registers differs on Jtag level.
32 * BCR/non-BCR describes if the register is immutable and that reading
33 * unexisting register is safe RAZ, rather then an error.
34 * Note, core registers cannot be BCR.
36 * In arc/cpu/ tcl files all registers are defined as core, non-BCR aux
37 * and BCR aux, in "add-reg" command they are passed to three lists
38 * respectively: core_reg_descriptions, aux_reg_descriptions,
39 * bcr_reg_descriptions.
41 * Due to the specifics of accessing to BCR/non-BCR registers there are two
43 * 1) core_and_aux_cache - includes registers described in
44 * core_reg_descriptions and aux_reg_descriptions lists.
45 * Used during save/restore context step.
46 * 2) bcr_cache - includes registers described bcr_reg_descriptions.
47 * Currently used internally during configure step.
51 static int arc_remove_watchpoint(struct target
*target
,
52 struct watchpoint
*watchpoint
);
53 static int arc_enable_watchpoints(struct target
*target
);
54 static int arc_enable_breakpoints(struct target
*target
);
55 static int arc_unset_breakpoint(struct target
*target
,
56 struct breakpoint
*breakpoint
);
57 static int arc_set_breakpoint(struct target
*target
,
58 struct breakpoint
*breakpoint
);
59 static int arc_single_step_core(struct target
*target
);
61 void arc_reg_data_type_add(struct target
*target
,
62 struct arc_reg_data_type
*data_type
)
64 LOG_DEBUG("Adding %s reg_data_type", data_type
->data_type
.id
);
65 struct arc_common
*arc
= target_to_arc(target
);
68 list_add_tail(&data_type
->list
, &arc
->reg_data_types
);
72 * Private implementation of register_get_by_name() for ARC that
73 * doesn't skip not [yet] existing registers. Used in many places
74 * for iteration through registers and even for marking required registers as
77 struct reg
*arc_reg_get_by_name(struct reg_cache
*first
,
78 const char *name
, bool search_all
)
81 struct reg_cache
*cache
= first
;
84 for (i
= 0; i
< cache
->num_regs
; i
++) {
85 if (!strcmp(cache
->reg_list
[i
].name
, name
))
86 return &(cache
->reg_list
[i
]);
99 * Reset internal states of caches. Must be called when entering debugging.
101 * @param target Target for which to reset caches states.
103 static int arc_reset_caches_states(struct target
*target
)
105 struct arc_common
*arc
= target_to_arc(target
);
107 LOG_DEBUG("Resetting internal variables of caches states");
109 /* Reset caches states. */
110 arc
->dcache_flushed
= false;
111 arc
->l2cache_flushed
= false;
112 arc
->icache_invalidated
= false;
113 arc
->dcache_invalidated
= false;
114 arc
->l2cache_invalidated
= false;
119 /* Initialize arc_common structure, which passes to openocd target instance */
120 static int arc_init_arch_info(struct target
*target
, struct arc_common
*arc
,
121 struct jtag_tap
*tap
)
123 arc
->common_magic
= ARC_COMMON_MAGIC
;
124 target
->arch_info
= arc
;
126 arc
->jtag_info
.tap
= tap
;
128 /* The only allowed ir_length is 4 for ARC jtag. */
129 if (tap
->ir_length
!= 4) {
130 LOG_ERROR("ARC jtag instruction length should be equal to 4");
134 /* On most ARC targets there is a dcache, so we enable its flushing
135 * by default. If there no dcache, there will be no error, just a slight
136 * performance penalty from unnecessary JTAG operations. */
137 arc
->has_dcache
= true;
138 arc
->has_icache
= true;
139 /* L2$ is not available in a target by default. */
140 arc
->has_l2cache
= false;
141 arc_reset_caches_states(target
);
143 /* Add standard GDB data types */
144 INIT_LIST_HEAD(&arc
->reg_data_types
);
145 struct arc_reg_data_type
*std_types
= calloc(ARRAY_SIZE(standard_gdb_types
),
149 LOG_ERROR("Unable to allocate memory");
153 for (unsigned int i
= 0; i
< ARRAY_SIZE(standard_gdb_types
); i
++) {
154 std_types
[i
].data_type
.type
= standard_gdb_types
[i
].type
;
155 std_types
[i
].data_type
.id
= standard_gdb_types
[i
].id
;
156 arc_reg_data_type_add(target
, &(std_types
[i
]));
159 /* Fields related to target descriptions */
160 INIT_LIST_HEAD(&arc
->core_reg_descriptions
);
161 INIT_LIST_HEAD(&arc
->aux_reg_descriptions
);
162 INIT_LIST_HEAD(&arc
->bcr_reg_descriptions
);
164 arc
->num_core_regs
= 0;
165 arc
->num_aux_regs
= 0;
166 arc
->num_bcr_regs
= 0;
167 arc
->last_general_reg
= ULONG_MAX
;
168 arc
->pc_index_in_cache
= ULONG_MAX
;
169 arc
->debug_index_in_cache
= ULONG_MAX
;
174 int arc_reg_add(struct target
*target
, struct arc_reg_desc
*arc_reg
,
175 const char * const type_name
, const size_t type_name_len
)
180 struct arc_common
*arc
= target_to_arc(target
);
183 /* Find register type */
185 struct arc_reg_data_type
*type
;
186 list_for_each_entry(type
, &arc
->reg_data_types
, list
)
187 if (!strncmp(type
->data_type
.id
, type_name
, type_name_len
)) {
188 arc_reg
->data_type
= &(type
->data_type
);
192 if (!arc_reg
->data_type
)
193 return ERROR_ARC_REGTYPE_NOT_FOUND
;
196 if (arc_reg
->is_core
) {
197 list_add_tail(&arc_reg
->list
, &arc
->core_reg_descriptions
);
198 arc
->num_core_regs
+= 1;
199 } else if (arc_reg
->is_bcr
) {
200 list_add_tail(&arc_reg
->list
, &arc
->bcr_reg_descriptions
);
201 arc
->num_bcr_regs
+= 1;
203 list_add_tail(&arc_reg
->list
, &arc
->aux_reg_descriptions
);
204 arc
->num_aux_regs
+= 1;
209 "added register {name=%s, num=0x%" PRIx32
", type=%s%s%s%s}",
210 arc_reg
->name
, arc_reg
->arch_num
, arc_reg
->data_type
->id
,
211 arc_reg
->is_core
? ", core" : "", arc_reg
->is_bcr
? ", bcr" : "",
212 arc_reg
->is_general
? ", general" : ""
218 /* Reading core or aux register */
219 static int arc_get_register(struct reg
*reg
)
223 struct arc_reg_desc
*desc
= reg
->arch_info
;
224 struct target
*target
= desc
->target
;
225 struct arc_common
*arc
= target_to_arc(target
);
230 LOG_DEBUG("Get register (cached) gdb_num=%" PRIu32
", name=%s, value=0x%" PRIx32
,
231 reg
->number
, desc
->name
, target_buffer_get_u32(target
, reg
->value
));
236 /* Accessing to R61/R62 registers causes Jtag hang */
237 if (desc
->arch_num
== ARC_R61
|| desc
->arch_num
== ARC_R62
) {
238 LOG_ERROR("It is forbidden to read core registers 61 and 62.");
241 CHECK_RETVAL(arc_jtag_read_core_reg_one(&arc
->jtag_info
, desc
->arch_num
,
244 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, desc
->arch_num
,
248 target_buffer_set_u32(target
, reg
->value
, value
);
250 /* If target is unhalted all register reads should be uncached. */
251 if (target
->state
== TARGET_HALTED
)
258 LOG_DEBUG("Get register gdb_num=%" PRIu32
", name=%s, value=0x%" PRIx32
,
259 reg
->number
, desc
->name
, value
);
265 /* Writing core or aux register */
266 static int arc_set_register(struct reg
*reg
, uint8_t *buf
)
268 struct arc_reg_desc
*desc
= reg
->arch_info
;
269 struct target
*target
= desc
->target
;
270 uint32_t value
= target_buffer_get_u32(target
, buf
);
271 /* Unlike "get" function "set" is supported only if target
272 * is in halt mode. Async writes are not supported yet. */
273 if (target
->state
!= TARGET_HALTED
)
274 return ERROR_TARGET_NOT_HALTED
;
276 /* Accessing to R61/R62 registers causes Jtag hang */
277 if (desc
->is_core
&& (desc
->arch_num
== ARC_R61
||
278 desc
->arch_num
== ARC_R62
)) {
279 LOG_ERROR("It is forbidden to write core registers 61 and 62.");
282 target_buffer_set_u32(target
, reg
->value
, value
);
284 LOG_DEBUG("Set register gdb_num=%" PRIu32
", name=%s, value=0x%08" PRIx32
,
285 reg
->number
, desc
->name
, value
);
293 static const struct reg_arch_type arc_reg_type
= {
294 .get
= arc_get_register
,
295 .set
= arc_set_register
,
298 /* GDB register groups. For now we support only general and "empty" */
299 static const char * const reg_group_general
= "general";
300 static const char * const reg_group_other
= "";
302 /* Common code to initialize `struct reg` for different registers: core, aux, bcr. */
303 static int arc_init_reg(struct target
*target
, struct reg
*reg
,
304 struct arc_reg_desc
*reg_desc
, unsigned long number
)
310 struct arc_common
*arc
= target_to_arc(target
);
312 /* Initialize struct reg */
313 reg
->name
= reg_desc
->name
;
314 reg
->size
= 32; /* All register in ARC are 32-bit */
315 reg
->value
= reg_desc
->reg_value
;
316 reg
->type
= &arc_reg_type
;
317 reg
->arch_info
= reg_desc
;
318 reg
->caller_save
= true; /* @todo should be configurable. */
319 reg
->reg_data_type
= reg_desc
->data_type
;
320 reg
->feature
= ®_desc
->feature
;
322 reg
->feature
->name
= reg_desc
->gdb_xml_feature
;
324 /* reg->number is used by OpenOCD as value for @regnum. Thus when setting
325 * value of a register GDB will use it as a number of register in
326 * P-packet. OpenOCD gdbserver will then use number of register in
327 * P-packet as an array index in the reg_list returned by
328 * arc_regs_get_gdb_reg_list. So to ensure that registers are assigned
329 * correctly it would be required to either sort registers in
330 * arc_regs_get_gdb_reg_list or to assign numbers sequentially here and
331 * according to how registers will be sorted in
332 * arc_regs_get_gdb_reg_list. Second options is much more simpler. */
333 reg
->number
= number
;
335 if (reg_desc
->is_general
) {
336 arc
->last_general_reg
= reg
->number
;
337 reg
->group
= reg_group_general
;
339 reg
->group
= reg_group_other
;
345 /* Building aux/core reg_cache */
346 static int arc_build_reg_cache(struct target
*target
)
349 struct arc_reg_desc
*reg_desc
;
350 /* get pointers to arch-specific information */
351 struct arc_common
*arc
= target_to_arc(target
);
352 const unsigned long num_regs
= arc
->num_core_regs
+ arc
->num_aux_regs
;
353 struct reg_cache
**cache_p
= register_get_last_cache_p(&target
->reg_cache
);
354 struct reg_cache
*cache
= calloc(1, sizeof(*cache
));
355 struct reg
*reg_list
= calloc(num_regs
, sizeof(*reg_list
));
357 if (!cache
|| !reg_list
) {
358 LOG_ERROR("Not enough memory");
362 /* Build the process context cache */
363 cache
->name
= "arc registers";
365 cache
->reg_list
= reg_list
;
366 cache
->num_regs
= num_regs
;
367 arc
->core_and_aux_cache
= cache
;
370 if (list_empty(&arc
->core_reg_descriptions
)) {
371 LOG_ERROR("No core registers were defined");
375 list_for_each_entry(reg_desc
, &arc
->core_reg_descriptions
, list
) {
376 CHECK_RETVAL(arc_init_reg(target
, ®_list
[i
], reg_desc
, i
));
378 LOG_DEBUG("reg n=%3li name=%3s group=%s feature=%s", i
,
379 reg_list
[i
].name
, reg_list
[i
].group
,
380 reg_list
[i
].feature
->name
);
385 if (list_empty(&arc
->aux_reg_descriptions
)) {
386 LOG_ERROR("No aux registers were defined");
390 list_for_each_entry(reg_desc
, &arc
->aux_reg_descriptions
, list
) {
391 CHECK_RETVAL(arc_init_reg(target
, ®_list
[i
], reg_desc
, i
));
393 LOG_DEBUG("reg n=%3li name=%3s group=%s feature=%s", i
,
394 reg_list
[i
].name
, reg_list
[i
].group
,
395 reg_list
[i
].feature
->name
);
397 /* PC and DEBUG are essential so we search for them. */
398 if (!strcmp("pc", reg_desc
->name
)) {
399 if (arc
->pc_index_in_cache
!= ULONG_MAX
) {
400 LOG_ERROR("Double definition of PC in configuration");
403 arc
->pc_index_in_cache
= i
;
404 } else if (!strcmp("debug", reg_desc
->name
)) {
405 if (arc
->debug_index_in_cache
!= ULONG_MAX
) {
406 LOG_ERROR("Double definition of DEBUG in configuration");
409 arc
->debug_index_in_cache
= i
;
414 if (arc
->pc_index_in_cache
== ULONG_MAX
415 || arc
->debug_index_in_cache
== ULONG_MAX
) {
416 LOG_ERROR("`pc' and `debug' registers must be present in target description.");
420 assert(i
== (arc
->num_core_regs
+ arc
->num_aux_regs
));
422 arc
->core_aux_cache_built
= true;
433 /* Build bcr reg_cache.
434 * This function must be called only after arc_build_reg_cache */
435 static int arc_build_bcr_reg_cache(struct target
*target
)
437 /* get pointers to arch-specific information */
438 struct arc_common
*arc
= target_to_arc(target
);
439 const unsigned long num_regs
= arc
->num_bcr_regs
;
440 struct reg_cache
**cache_p
= register_get_last_cache_p(&target
->reg_cache
);
441 struct reg_cache
*cache
= malloc(sizeof(*cache
));
442 struct reg
*reg_list
= calloc(num_regs
, sizeof(*reg_list
));
444 struct arc_reg_desc
*reg_desc
;
446 unsigned long gdb_regnum
= arc
->core_and_aux_cache
->num_regs
;
448 if (!cache
|| !reg_list
) {
449 LOG_ERROR("Unable to allocate memory");
453 /* Build the process context cache */
454 cache
->name
= "arc.bcr";
456 cache
->reg_list
= reg_list
;
457 cache
->num_regs
= num_regs
;
458 arc
->bcr_cache
= cache
;
461 if (list_empty(&arc
->bcr_reg_descriptions
)) {
462 LOG_ERROR("No BCR registers are defined");
466 list_for_each_entry(reg_desc
, &arc
->bcr_reg_descriptions
, list
) {
467 CHECK_RETVAL(arc_init_reg(target
, ®_list
[i
], reg_desc
, gdb_regnum
));
468 /* BCRs always semantically, they are just read-as-zero, if there is
469 * not real register. */
470 reg_list
[i
].exist
= true;
472 LOG_DEBUG("reg n=%3li name=%3s group=%s feature=%s", i
,
473 reg_list
[i
].name
, reg_list
[i
].group
,
474 reg_list
[i
].feature
->name
);
479 assert(i
== arc
->num_bcr_regs
);
481 arc
->bcr_cache_built
= true;
493 static int arc_get_gdb_reg_list(struct target
*target
, struct reg
**reg_list
[],
494 int *reg_list_size
, enum target_register_class reg_class
)
496 assert(target
->reg_cache
);
497 struct arc_common
*arc
= target_to_arc(target
);
499 /* get pointers to arch-specific information storage */
500 *reg_list_size
= arc
->num_regs
;
501 *reg_list
= calloc(*reg_list_size
, sizeof(struct reg
*));
504 LOG_ERROR("Unable to allocate memory");
508 /* OpenOCD gdb_server API seems to be inconsistent here: when it generates
509 * XML tdesc it filters out !exist registers, however when creating a
510 * g-packet it doesn't do so. REG_CLASS_ALL is used in first case, and
511 * REG_CLASS_GENERAL used in the latter one. Due to this we had to filter
512 * out !exist register for "general", but not for "all". Attempts to filter out
513 * !exist for "all" as well will cause a failed check in OpenOCD GDB
515 if (reg_class
== REG_CLASS_ALL
) {
517 struct reg_cache
*reg_cache
= target
->reg_cache
;
519 for (unsigned j
= 0; j
< reg_cache
->num_regs
; j
++, i
++)
520 (*reg_list
)[i
] = ®_cache
->reg_list
[j
];
521 reg_cache
= reg_cache
->next
;
523 assert(i
== arc
->num_regs
);
524 LOG_DEBUG("REG_CLASS_ALL: number of regs=%i", *reg_list_size
);
527 unsigned long gdb_reg_number
= 0;
528 struct reg_cache
*reg_cache
= target
->reg_cache
;
531 j
< reg_cache
->num_regs
&& gdb_reg_number
<= arc
->last_general_reg
;
533 if (reg_cache
->reg_list
[j
].exist
) {
534 (*reg_list
)[i
] = ®_cache
->reg_list
[j
];
539 reg_cache
= reg_cache
->next
;
542 LOG_DEBUG("REG_CLASS_GENERAL: number of regs=%i", *reg_list_size
);
548 /* Reading field of struct_type register */
549 int arc_reg_get_field(struct target
*target
, const char *reg_name
,
550 const char *field_name
, uint32_t *value_ptr
)
552 struct reg_data_type_struct_field
*field
;
554 LOG_DEBUG("getting register field (reg_name=%s, field_name=%s)", reg_name
, field_name
);
557 struct reg
*reg
= arc_reg_get_by_name(target
->reg_cache
, reg_name
, true);
560 LOG_ERROR("Requested register `%s' doesn't exist.", reg_name
);
561 return ERROR_ARC_REGISTER_NOT_FOUND
;
564 if (reg
->reg_data_type
->type
!= REG_TYPE_ARCH_DEFINED
565 || reg
->reg_data_type
->type_class
!= REG_TYPE_CLASS_STRUCT
)
566 return ERROR_ARC_REGISTER_IS_NOT_STRUCT
;
568 /* Get field in a register */
569 struct reg_data_type_struct
*reg_struct
=
570 reg
->reg_data_type
->reg_type_struct
;
571 for (field
= reg_struct
->fields
;
573 field
= field
->next
) {
574 if (!strcmp(field
->name
, field_name
))
579 return ERROR_ARC_REGISTER_FIELD_NOT_FOUND
;
581 if (!field
->use_bitfields
)
582 return ERROR_ARC_FIELD_IS_NOT_BITFIELD
;
585 CHECK_RETVAL(reg
->type
->get(reg
));
587 /* First do endianness-safe read of register value
588 * then convert it to binary buffer for further
589 * field extraction */
591 *value_ptr
= buf_get_u32(reg
->value
, field
->bitfield
->start
,
592 field
->bitfield
->end
- field
->bitfield
->start
+ 1);
597 static int arc_get_register_value(struct target
*target
, const char *reg_name
,
600 LOG_DEBUG("reg_name=%s", reg_name
);
602 struct reg
*reg
= arc_reg_get_by_name(target
->reg_cache
, reg_name
, true);
605 return ERROR_ARC_REGISTER_NOT_FOUND
;
608 CHECK_RETVAL(reg
->type
->get(reg
));
610 *value_ptr
= target_buffer_get_u32(target
, reg
->value
);
615 static int arc_set_register_value(struct target
*target
, const char *reg_name
,
618 LOG_DEBUG("reg_name=%s value=0x%08" PRIx32
, reg_name
, value
);
620 if (!(target
&& reg_name
)) {
621 LOG_ERROR("Arguments cannot be NULL.");
625 struct reg
*reg
= arc_reg_get_by_name(target
->reg_cache
, reg_name
, true);
628 return ERROR_ARC_REGISTER_NOT_FOUND
;
630 uint8_t value_buf
[4];
631 buf_set_u32(value_buf
, 0, 32, value
);
632 CHECK_RETVAL(reg
->type
->set(reg
, value_buf
));
637 /* Configure DCCM's */
638 static int arc_configure_dccm(struct target
*target
)
640 struct arc_common
*arc
= target_to_arc(target
);
642 uint32_t dccm_build_version
, dccm_build_size0
, dccm_build_size1
;
643 CHECK_RETVAL(arc_reg_get_field(target
, "dccm_build", "version",
644 &dccm_build_version
));
645 CHECK_RETVAL(arc_reg_get_field(target
, "dccm_build", "size0",
647 CHECK_RETVAL(arc_reg_get_field(target
, "dccm_build", "size1",
649 /* There is no yet support of configurable number of cycles,
650 * So there is no difference between v3 and v4 */
651 if ((dccm_build_version
== 3 || dccm_build_version
== 4) && dccm_build_size0
> 0) {
652 CHECK_RETVAL(arc_get_register_value(target
, "aux_dccm", &(arc
->dccm_start
)));
653 uint32_t dccm_size
= 0x100;
654 dccm_size
<<= dccm_build_size0
;
655 if (dccm_build_size0
== 0xF)
656 dccm_size
<<= dccm_build_size1
;
657 arc
->dccm_end
= arc
->dccm_start
+ dccm_size
;
658 LOG_DEBUG("DCCM detected start=0x%" PRIx32
" end=0x%" PRIx32
,
659 arc
->dccm_start
, arc
->dccm_end
);
666 /* Configure ICCM's */
668 static int arc_configure_iccm(struct target
*target
)
670 struct arc_common
*arc
= target_to_arc(target
);
673 uint32_t iccm_build_version
, iccm_build_size00
, iccm_build_size01
;
674 uint32_t aux_iccm
= 0;
675 CHECK_RETVAL(arc_reg_get_field(target
, "iccm_build", "version",
676 &iccm_build_version
));
677 CHECK_RETVAL(arc_reg_get_field(target
, "iccm_build", "iccm0_size0",
678 &iccm_build_size00
));
679 CHECK_RETVAL(arc_reg_get_field(target
, "iccm_build", "iccm0_size1",
680 &iccm_build_size01
));
681 if (iccm_build_version
== 4 && iccm_build_size00
> 0) {
682 CHECK_RETVAL(arc_get_register_value(target
, "aux_iccm", &aux_iccm
));
683 uint32_t iccm0_size
= 0x100;
684 iccm0_size
<<= iccm_build_size00
;
685 if (iccm_build_size00
== 0xF)
686 iccm0_size
<<= iccm_build_size01
;
687 /* iccm0 start is located in highest 4 bits of aux_iccm */
688 arc
->iccm0_start
= aux_iccm
& 0xF0000000;
689 arc
->iccm0_end
= arc
->iccm0_start
+ iccm0_size
;
690 LOG_DEBUG("ICCM0 detected start=0x%" PRIx32
" end=0x%" PRIx32
,
691 arc
->iccm0_start
, arc
->iccm0_end
);
695 uint32_t iccm_build_size10
, iccm_build_size11
;
696 CHECK_RETVAL(arc_reg_get_field(target
, "iccm_build", "iccm1_size0",
697 &iccm_build_size10
));
698 CHECK_RETVAL(arc_reg_get_field(target
, "iccm_build", "iccm1_size1",
699 &iccm_build_size11
));
700 if (iccm_build_version
== 4 && iccm_build_size10
> 0) {
701 /* Use value read for ICCM0 */
703 CHECK_RETVAL(arc_get_register_value(target
, "aux_iccm", &aux_iccm
));
704 uint32_t iccm1_size
= 0x100;
705 iccm1_size
<<= iccm_build_size10
;
706 if (iccm_build_size10
== 0xF)
707 iccm1_size
<<= iccm_build_size11
;
708 arc
->iccm1_start
= aux_iccm
& 0x0F000000;
709 arc
->iccm1_end
= arc
->iccm1_start
+ iccm1_size
;
710 LOG_DEBUG("ICCM1 detected start=0x%" PRIx32
" end=0x%" PRIx32
,
711 arc
->iccm1_start
, arc
->iccm1_end
);
716 /* Configure some core features, depending on BCRs. */
717 static int arc_configure(struct target
*target
)
719 LOG_DEBUG("Configuring ARC ICCM and DCCM");
721 /* Configuring DCCM if DCCM_BUILD and AUX_DCCM are known registers. */
722 if (arc_reg_get_by_name(target
->reg_cache
, "dccm_build", true) &&
723 arc_reg_get_by_name(target
->reg_cache
, "aux_dccm", true))
724 CHECK_RETVAL(arc_configure_dccm(target
));
726 /* Configuring ICCM if ICCM_BUILD and AUX_ICCM are known registers. */
727 if (arc_reg_get_by_name(target
->reg_cache
, "iccm_build", true) &&
728 arc_reg_get_by_name(target
->reg_cache
, "aux_iccm", true))
729 CHECK_RETVAL(arc_configure_iccm(target
));
734 /* arc_examine is function, which is used for all arc targets*/
735 static int arc_examine(struct target
*target
)
738 struct arc_common
*arc
= target_to_arc(target
);
740 CHECK_RETVAL(arc_jtag_startup(&arc
->jtag_info
));
742 if (!target_was_examined(target
)) {
743 CHECK_RETVAL(arc_jtag_status(&arc
->jtag_info
, &status
));
744 if (status
& ARC_JTAG_STAT_RU
)
745 target
->state
= TARGET_RUNNING
;
747 target
->state
= TARGET_HALTED
;
749 /* Read BCRs and configure optional registers. */
750 CHECK_RETVAL(arc_configure(target
));
752 target_set_examined(target
);
758 static int arc_exit_debug(struct target
*target
)
761 struct arc_common
*arc
= target_to_arc(target
);
763 /* Do read-modify-write sequence, or DEBUG.UB will be reset unintentionally. */
764 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_DEBUG_REG
, &value
));
765 value
|= SET_CORE_FORCE_HALT
; /* set the HALT bit */
766 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DEBUG_REG
, value
));
769 target
->state
= TARGET_HALTED
;
770 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_HALTED
));
772 if (debug_level
>= LOG_LVL_DEBUG
) {
773 LOG_DEBUG("core stopped (halted) debug-reg: 0x%08" PRIx32
, value
);
774 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
, &value
));
775 LOG_DEBUG("core STATUS32: 0x%08" PRIx32
, value
);
781 static int arc_halt(struct target
*target
)
783 uint32_t value
, irq_state
;
784 struct arc_common
*arc
= target_to_arc(target
);
786 LOG_DEBUG("target->state: %s", target_state_name(target
));
788 if (target
->state
== TARGET_HALTED
) {
789 LOG_DEBUG("target was already halted");
793 if (target
->state
== TARGET_UNKNOWN
)
794 LOG_WARNING("target was in unknown state when halt was requested");
796 if (target
->state
== TARGET_RESET
) {
797 if ((jtag_get_reset_config() & RESET_SRST_PULLS_TRST
) && jtag_get_srst()) {
798 LOG_ERROR("can't request a halt while in reset if nSRST pulls nTRST");
799 return ERROR_TARGET_FAILURE
;
801 target
->debug_reason
= DBG_REASON_DBGRQ
;
805 /* Break (stop) processor.
806 * Do read-modify-write sequence, or DEBUG.UB will be reset unintentionally.
807 * We do not use here arc_get/set_core_reg functions here because they imply
808 * that the processor is already halted. */
809 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_DEBUG_REG
, &value
));
810 value
|= SET_CORE_FORCE_HALT
; /* set the HALT bit */
811 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DEBUG_REG
, value
));
814 /* Save current IRQ state */
815 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
, &irq_state
));
817 if (irq_state
& AUX_STATUS32_REG_IE_BIT
)
822 /* update state and notify gdb*/
823 target
->state
= TARGET_HALTED
;
824 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_HALTED
));
826 /* some more debug information */
827 if (debug_level
>= LOG_LVL_DEBUG
) {
828 LOG_DEBUG("core stopped (halted) DEGUB-REG: 0x%08" PRIx32
, value
);
829 CHECK_RETVAL(arc_get_register_value(target
, "status32", &value
));
830 LOG_DEBUG("core STATUS32: 0x%08" PRIx32
, value
);
837 * Read registers that are used in GDB g-packet. We don't read them one-by-one,
838 * but do that in one batch operation to improve speed. Calls to JTAG layer are
839 * expensive so it is better to make one big call that reads all necessary
840 * registers, instead of many calls, one for one register.
842 static int arc_save_context(struct target
*target
)
844 int retval
= ERROR_OK
;
846 struct arc_common
*arc
= target_to_arc(target
);
847 struct reg
*reg_list
= arc
->core_and_aux_cache
->reg_list
;
849 LOG_DEBUG("Saving aux and core registers values");
852 /* It is assumed that there is at least one AUX register in the list, for
854 const uint32_t core_regs_size
= arc
->num_core_regs
* sizeof(uint32_t);
855 /* last_general_reg is inclusive number. To get count of registers it is
856 * required to do +1. */
857 const uint32_t regs_to_scan
=
858 MIN(arc
->last_general_reg
+ 1, arc
->num_regs
);
859 const uint32_t aux_regs_size
= arc
->num_aux_regs
* sizeof(uint32_t);
860 uint32_t *core_values
= malloc(core_regs_size
);
861 uint32_t *aux_values
= malloc(aux_regs_size
);
862 uint32_t *core_addrs
= malloc(core_regs_size
);
863 uint32_t *aux_addrs
= malloc(aux_regs_size
);
864 unsigned int core_cnt
= 0;
865 unsigned int aux_cnt
= 0;
867 if (!core_values
|| !core_addrs
|| !aux_values
|| !aux_addrs
) {
868 LOG_ERROR("Unable to allocate memory");
873 memset(core_values
, 0xff, core_regs_size
);
874 memset(core_addrs
, 0xff, core_regs_size
);
875 memset(aux_values
, 0xff, aux_regs_size
);
876 memset(aux_addrs
, 0xff, aux_regs_size
);
878 for (i
= 0; i
< MIN(arc
->num_core_regs
, regs_to_scan
); i
++) {
879 struct reg
*reg
= reg_list
+ i
;
880 struct arc_reg_desc
*arc_reg
= reg
->arch_info
;
881 if (!reg
->valid
&& reg
->exist
)
882 core_addrs
[core_cnt
++] = arc_reg
->arch_num
;
885 for (i
= arc
->num_core_regs
; i
< regs_to_scan
; i
++) {
886 struct reg
*reg
= reg_list
+ i
;
887 struct arc_reg_desc
*arc_reg
= reg
->arch_info
;
888 if (!reg
->valid
&& reg
->exist
)
889 aux_addrs
[aux_cnt
++] = arc_reg
->arch_num
;
892 /* Read data from target. */
894 retval
= arc_jtag_read_core_reg(&arc
->jtag_info
, core_addrs
, core_cnt
, core_values
);
895 if (retval
!= ERROR_OK
) {
896 LOG_ERROR("Attempt to read core registers failed.");
902 retval
= arc_jtag_read_aux_reg(&arc
->jtag_info
, aux_addrs
, aux_cnt
, aux_values
);
903 if (retval
!= ERROR_OK
) {
904 LOG_ERROR("Attempt to read aux registers failed.");
910 /* Parse core regs */
912 for (i
= 0; i
< MIN(arc
->num_core_regs
, regs_to_scan
); i
++) {
913 struct reg
*reg
= reg_list
+ i
;
914 struct arc_reg_desc
*arc_reg
= reg
->arch_info
;
915 if (!reg
->valid
&& reg
->exist
) {
916 target_buffer_set_u32(target
, reg
->value
, core_values
[core_cnt
]);
919 LOG_DEBUG("Get core register regnum=%u, name=%s, value=0x%08" PRIx32
,
920 i
, arc_reg
->name
, core_values
[core_cnt
]);
927 for (i
= arc
->num_core_regs
; i
< regs_to_scan
; i
++) {
928 struct reg
*reg
= reg_list
+ i
;
929 struct arc_reg_desc
*arc_reg
= reg
->arch_info
;
930 if (!reg
->valid
&& reg
->exist
) {
931 target_buffer_set_u32(target
, reg
->value
, aux_values
[aux_cnt
]);
934 LOG_DEBUG("Get aux register regnum=%u, name=%s, value=0x%08" PRIx32
,
935 i
, arc_reg
->name
, aux_values
[aux_cnt
]);
950 * Finds an actionpoint that triggered last actionpoint event, as specified by
954 * @param actionpoint Pointer to be set to last active actionpoint. Pointer
955 * will be set to NULL if DEBUG.AH is 0.
957 static int get_current_actionpoint(struct target
*target
,
958 struct arc_actionpoint
**actionpoint
)
964 /* Check if actionpoint caused halt */
965 CHECK_RETVAL(arc_reg_get_field(target
, "debug", "ah",
969 struct arc_common
*arc
= target_to_arc(target
);
972 CHECK_RETVAL(arc_reg_get_field(target
, "debug",
975 for (ap
= 0; debug_asr
> 1; debug_asr
>>= 1)
978 assert(ap
< arc
->actionpoints_num
);
980 *actionpoint
= &(arc
->actionpoints_list
[ap
]);
988 static int arc_examine_debug_reason(struct target
*target
)
992 /* Only check for reason if don't know it already. */
993 /* BTW After singlestep at this point core is not marked as halted, so
994 * reading from memory to get current instruction wouldn't work anyway. */
995 if (target
->debug_reason
== DBG_REASON_DBGRQ
||
996 target
->debug_reason
== DBG_REASON_SINGLESTEP
) {
1000 CHECK_RETVAL(arc_reg_get_field(target
, "debug", "bh",
1004 /* DEBUG.BH is set if core halted due to BRK instruction. */
1005 target
->debug_reason
= DBG_REASON_BREAKPOINT
;
1007 struct arc_actionpoint
*actionpoint
= NULL
;
1008 CHECK_RETVAL(get_current_actionpoint(target
, &actionpoint
));
1011 if (!actionpoint
->used
)
1012 LOG_WARNING("Target halted by an unused actionpoint.");
1014 if (actionpoint
->type
== ARC_AP_BREAKPOINT
)
1015 target
->debug_reason
= DBG_REASON_BREAKPOINT
;
1016 else if (actionpoint
->type
== ARC_AP_WATCHPOINT
)
1017 target
->debug_reason
= DBG_REASON_WATCHPOINT
;
1019 LOG_WARNING("Unknown type of actionpoint.");
1026 static int arc_debug_entry(struct target
*target
)
1028 CHECK_RETVAL(arc_save_context(target
));
1030 /* TODO: reset internal indicators of caches states, otherwise D$/I$
1031 * will not be flushed/invalidated when required. */
1032 CHECK_RETVAL(arc_reset_caches_states(target
));
1033 CHECK_RETVAL(arc_examine_debug_reason(target
));
1038 static int arc_poll(struct target
*target
)
1040 uint32_t status
, value
;
1041 struct arc_common
*arc
= target_to_arc(target
);
1043 /* gdb calls continuously through this arc_poll() function */
1044 CHECK_RETVAL(arc_jtag_status(&arc
->jtag_info
, &status
));
1046 /* check for processor halted */
1047 if (status
& ARC_JTAG_STAT_RU
) {
1048 if (target
->state
!= TARGET_RUNNING
) {
1049 LOG_WARNING("target is still running!");
1050 target
->state
= TARGET_RUNNING
;
1054 /* In some cases JTAG status register indicates that
1055 * processor is in halt mode, but processor is still running.
1056 * We check halt bit of AUX STATUS32 register for setting correct state. */
1057 if ((target
->state
== TARGET_RUNNING
) || (target
->state
== TARGET_RESET
)) {
1058 CHECK_RETVAL(arc_get_register_value(target
, "status32", &value
));
1059 if (value
& AUX_STATUS32_REG_HALT_BIT
) {
1060 LOG_DEBUG("ARC core in halt or reset state.");
1061 /* Save context if target was not in reset state */
1062 if (target
->state
== TARGET_RUNNING
)
1063 CHECK_RETVAL(arc_debug_entry(target
));
1064 target
->state
= TARGET_HALTED
;
1065 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_HALTED
));
1067 LOG_DEBUG("Discrepancy of STATUS32[0] HALT bit and ARC_JTAG_STAT_RU, "
1068 "target is still running");
1071 } else if (target
->state
== TARGET_DEBUG_RUNNING
) {
1073 target
->state
= TARGET_HALTED
;
1074 LOG_DEBUG("ARC core is in debug running mode");
1076 CHECK_RETVAL(arc_debug_entry(target
));
1078 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_DEBUG_HALTED
));
1084 static int arc_assert_reset(struct target
*target
)
1086 struct arc_common
*arc
= target_to_arc(target
);
1087 enum reset_types jtag_reset_config
= jtag_get_reset_config();
1088 bool srst_asserted
= false;
1090 LOG_DEBUG("target->state: %s", target_state_name(target
));
1092 if (target_has_event_action(target
, TARGET_EVENT_RESET_ASSERT
)) {
1093 /* allow scripts to override the reset event */
1095 target_handle_event(target
, TARGET_EVENT_RESET_ASSERT
);
1096 register_cache_invalidate(arc
->core_and_aux_cache
);
1097 /* An ARC target might be in halt state after reset, so
1098 * if script requested processor to resume, then it must
1099 * be manually started to ensure that this request
1101 if (target
->state
== TARGET_HALTED
&& !target
->reset_halt
) {
1102 /* Resume the target and continue from the current
1103 * PC register value. */
1104 LOG_DEBUG("Starting CPU execution after reset");
1105 CHECK_RETVAL(target_resume(target
, 1, 0, 0, 0));
1107 target
->state
= TARGET_RESET
;
1112 /* some cores support connecting while srst is asserted
1113 * use that mode if it has been configured */
1114 if (!(jtag_reset_config
& RESET_SRST_PULLS_TRST
) &&
1115 (jtag_reset_config
& RESET_SRST_NO_GATING
)) {
1116 jtag_add_reset(0, 1);
1117 srst_asserted
= true;
1120 if (jtag_reset_config
& RESET_HAS_SRST
) {
1121 /* should issue a srst only, but we may have to assert trst as well */
1122 if (jtag_reset_config
& RESET_SRST_PULLS_TRST
)
1123 jtag_add_reset(1, 1);
1124 else if (!srst_asserted
)
1125 jtag_add_reset(0, 1);
1128 target
->state
= TARGET_RESET
;
1129 jtag_add_sleep(50000);
1131 register_cache_invalidate(arc
->core_and_aux_cache
);
1133 if (target
->reset_halt
)
1134 CHECK_RETVAL(target_halt(target
));
1139 static int arc_deassert_reset(struct target
*target
)
1141 LOG_DEBUG("target->state: %s", target_state_name(target
));
1143 /* deassert reset lines */
1144 jtag_add_reset(0, 0);
1149 static int arc_arch_state(struct target
*target
)
1153 if (debug_level
< LOG_LVL_DEBUG
)
1156 CHECK_RETVAL(arc_get_register_value(target
, "pc", &pc_value
));
1158 LOG_DEBUG("target state: %s; PC at: 0x%08" PRIx32
,
1159 target_state_name(target
),
1166 * See arc_save_context() for reason why we want to dump all regs at once.
1167 * This however means that if there are dependencies between registers they
1168 * will not be observable until target will be resumed.
1170 static int arc_restore_context(struct target
*target
)
1172 int retval
= ERROR_OK
;
1174 struct arc_common
*arc
= target_to_arc(target
);
1175 struct reg
*reg_list
= arc
->core_and_aux_cache
->reg_list
;
1177 LOG_DEBUG("Restoring registers values");
1180 const uint32_t core_regs_size
= arc
->num_core_regs
* sizeof(uint32_t);
1181 const uint32_t aux_regs_size
= arc
->num_aux_regs
* sizeof(uint32_t);
1182 uint32_t *core_values
= malloc(core_regs_size
);
1183 uint32_t *aux_values
= malloc(aux_regs_size
);
1184 uint32_t *core_addrs
= malloc(core_regs_size
);
1185 uint32_t *aux_addrs
= malloc(aux_regs_size
);
1186 unsigned int core_cnt
= 0;
1187 unsigned int aux_cnt
= 0;
1189 if (!core_values
|| !core_addrs
|| !aux_values
|| !aux_addrs
) {
1190 LOG_ERROR("Unable to allocate memory");
1191 retval
= ERROR_FAIL
;
1195 memset(core_values
, 0xff, core_regs_size
);
1196 memset(core_addrs
, 0xff, core_regs_size
);
1197 memset(aux_values
, 0xff, aux_regs_size
);
1198 memset(aux_addrs
, 0xff, aux_regs_size
);
1200 for (i
= 0; i
< arc
->num_core_regs
; i
++) {
1201 struct reg
*reg
= &(reg_list
[i
]);
1202 struct arc_reg_desc
*arc_reg
= reg
->arch_info
;
1203 if (reg
->valid
&& reg
->exist
&& reg
->dirty
) {
1204 LOG_DEBUG("Will write regnum=%u", i
);
1205 core_addrs
[core_cnt
] = arc_reg
->arch_num
;
1206 core_values
[core_cnt
] = target_buffer_get_u32(target
, reg
->value
);
1211 for (i
= 0; i
< arc
->num_aux_regs
; i
++) {
1212 struct reg
*reg
= &(reg_list
[arc
->num_core_regs
+ i
]);
1213 struct arc_reg_desc
*arc_reg
= reg
->arch_info
;
1214 if (reg
->valid
&& reg
->exist
&& reg
->dirty
) {
1215 LOG_DEBUG("Will write regnum=%lu", arc
->num_core_regs
+ i
);
1216 aux_addrs
[aux_cnt
] = arc_reg
->arch_num
;
1217 aux_values
[aux_cnt
] = target_buffer_get_u32(target
, reg
->value
);
1222 /* Write data to target.
1223 * Check before write, if aux and core count is greater than 0. */
1225 retval
= arc_jtag_write_core_reg(&arc
->jtag_info
, core_addrs
, core_cnt
, core_values
);
1226 if (retval
!= ERROR_OK
) {
1227 LOG_ERROR("Attempt to write to core registers failed.");
1228 retval
= ERROR_FAIL
;
1234 retval
= arc_jtag_write_aux_reg(&arc
->jtag_info
, aux_addrs
, aux_cnt
, aux_values
);
1235 if (retval
!= ERROR_OK
) {
1236 LOG_ERROR("Attempt to write to aux registers failed.");
1237 retval
= ERROR_FAIL
;
1251 static int arc_enable_interrupts(struct target
*target
, int enable
)
1255 struct arc_common
*arc
= target_to_arc(target
);
1257 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
, &value
));
1260 /* enable interrupts */
1261 value
|= SET_CORE_ENABLE_INTERRUPTS
;
1262 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
, value
));
1263 LOG_DEBUG("interrupts enabled");
1265 /* disable interrupts */
1266 value
&= ~SET_CORE_ENABLE_INTERRUPTS
;
1267 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
, value
));
1268 LOG_DEBUG("interrupts disabled");
1274 static int arc_resume(struct target
*target
, int current
, target_addr_t address
,
1275 int handle_breakpoints
, int debug_execution
)
1277 struct arc_common
*arc
= target_to_arc(target
);
1278 uint32_t resume_pc
= 0;
1280 struct reg
*pc
= &arc
->core_and_aux_cache
->reg_list
[arc
->pc_index_in_cache
];
1282 LOG_DEBUG("current:%i, address:0x%08" TARGET_PRIxADDR
", handle_breakpoints:%i,"
1283 " debug_execution:%i", current
, address
, handle_breakpoints
, debug_execution
);
1285 /* We need to reset ARC cache variables so caches
1286 * would be invalidated and actual data
1287 * would be fetched from memory. */
1288 CHECK_RETVAL(arc_reset_caches_states(target
));
1290 if (target
->state
!= TARGET_HALTED
) {
1291 LOG_TARGET_ERROR(target
, "not halted");
1292 return ERROR_TARGET_NOT_HALTED
;
1295 if (!debug_execution
) {
1296 /* (gdb) continue = execute until we hit break/watch-point */
1297 target_free_all_working_areas(target
);
1298 CHECK_RETVAL(arc_enable_breakpoints(target
));
1299 CHECK_RETVAL(arc_enable_watchpoints(target
));
1302 /* current = 1: continue on current PC, otherwise continue at <address> */
1304 target_buffer_set_u32(target
, pc
->value
, address
);
1307 LOG_DEBUG("Changing the value of current PC to 0x%08" TARGET_PRIxADDR
, address
);
1311 resume_pc
= address
;
1313 resume_pc
= target_buffer_get_u32(target
, pc
->value
);
1315 CHECK_RETVAL(arc_restore_context(target
));
1317 LOG_DEBUG("Target resumes from PC=0x%" PRIx32
", pc.dirty=%i, pc.valid=%i",
1318 resume_pc
, pc
->dirty
, pc
->valid
);
1320 /* check if GDB tells to set our PC where to continue from */
1321 if (pc
->valid
&& resume_pc
== target_buffer_get_u32(target
, pc
->value
)) {
1322 value
= target_buffer_get_u32(target
, pc
->value
);
1323 LOG_DEBUG("resume Core (when start-core) with PC @:0x%08" PRIx32
, value
);
1324 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_PC_REG
, value
));
1327 /* the front-end may request us not to handle breakpoints here */
1328 if (handle_breakpoints
) {
1329 /* Single step past breakpoint at current address */
1330 struct breakpoint
*breakpoint
= breakpoint_find(target
, resume_pc
);
1332 LOG_DEBUG("skipping past breakpoint at 0x%08" TARGET_PRIxADDR
,
1333 breakpoint
->address
);
1334 CHECK_RETVAL(arc_unset_breakpoint(target
, breakpoint
));
1335 CHECK_RETVAL(arc_single_step_core(target
));
1336 CHECK_RETVAL(arc_set_breakpoint(target
, breakpoint
));
1340 /* Restore IRQ state if not in debug_execution*/
1341 if (!debug_execution
)
1342 CHECK_RETVAL(arc_enable_interrupts(target
, arc
->irq_state
));
1344 CHECK_RETVAL(arc_enable_interrupts(target
, !debug_execution
));
1346 target
->debug_reason
= DBG_REASON_NOTHALTED
;
1348 /* ready to get us going again */
1349 target
->state
= TARGET_RUNNING
;
1350 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
, &value
));
1351 value
&= ~SET_CORE_HALT_BIT
; /* clear the HALT bit */
1352 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
, value
));
1353 LOG_DEBUG("Core started to run");
1355 /* registers are now invalid */
1356 register_cache_invalidate(arc
->core_and_aux_cache
);
1358 if (!debug_execution
) {
1359 target
->state
= TARGET_RUNNING
;
1360 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_RESUMED
));
1361 LOG_DEBUG("target resumed at 0x%08" PRIx32
, resume_pc
);
1363 target
->state
= TARGET_DEBUG_RUNNING
;
1364 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_DEBUG_RESUMED
));
1365 LOG_DEBUG("target debug resumed at 0x%08" PRIx32
, resume_pc
);
1371 static int arc_init_target(struct command_context
*cmd_ctx
, struct target
*target
)
1373 CHECK_RETVAL(arc_build_reg_cache(target
));
1374 CHECK_RETVAL(arc_build_bcr_reg_cache(target
));
1375 target
->debug_reason
= DBG_REASON_DBGRQ
;
1379 static void arc_free_reg_cache(struct reg_cache
*cache
)
1381 free(cache
->reg_list
);
1385 static void arc_deinit_target(struct target
*target
)
1387 struct arc_common
*arc
= target_to_arc(target
);
1389 LOG_DEBUG("deinitialization of target");
1390 if (arc
->core_aux_cache_built
)
1391 arc_free_reg_cache(arc
->core_and_aux_cache
);
1392 if (arc
->bcr_cache_built
)
1393 arc_free_reg_cache(arc
->bcr_cache
);
1395 struct arc_reg_data_type
*type
, *n
;
1396 struct arc_reg_desc
*desc
, *k
;
1398 /* Free arc-specific reg_data_types allocations*/
1399 list_for_each_entry_safe_reverse(type
, n
, &arc
->reg_data_types
, list
) {
1400 if (type
->data_type
.type_class
== REG_TYPE_CLASS_STRUCT
) {
1401 free(type
->reg_type_struct_field
);
1402 free(type
->bitfields
);
1404 } else if (type
->data_type
.type_class
== REG_TYPE_CLASS_FLAGS
) {
1405 free(type
->reg_type_flags_field
);
1406 free(type
->bitfields
);
1411 /* Free standard_gdb_types reg_data_types allocations */
1412 type
= list_first_entry(&arc
->reg_data_types
, struct arc_reg_data_type
, list
);
1415 list_for_each_entry_safe(desc
, k
, &arc
->aux_reg_descriptions
, list
)
1416 free_reg_desc(desc
);
1418 list_for_each_entry_safe(desc
, k
, &arc
->core_reg_descriptions
, list
)
1419 free_reg_desc(desc
);
1421 list_for_each_entry_safe(desc
, k
, &arc
->bcr_reg_descriptions
, list
)
1422 free_reg_desc(desc
);
1424 free(arc
->actionpoints_list
);
1429 static int arc_target_create(struct target
*target
, Jim_Interp
*interp
)
1431 struct arc_common
*arc
= calloc(1, sizeof(*arc
));
1434 LOG_ERROR("Unable to allocate memory");
1438 LOG_DEBUG("Entering");
1439 CHECK_RETVAL(arc_init_arch_info(target
, arc
, target
->tap
));
1445 * Write 4-byte instruction to memory. This is like target_write_u32, however
1446 * in case of little endian ARC instructions are in middle endian format, not
1447 * little endian, so different type of conversion should be done.
1448 * Middle endian: instruction "aabbccdd", stored as "bbaaddcc"
1450 static int arc_write_instruction_u32(struct target
*target
, uint32_t address
,
1453 uint8_t value_buf
[4];
1454 if (!target_was_examined(target
)) {
1455 LOG_ERROR("Target not examined yet");
1459 LOG_DEBUG("Address: 0x%08" PRIx32
", value: 0x%08" PRIx32
, address
,
1462 if (target
->endianness
== TARGET_LITTLE_ENDIAN
)
1463 arc_h_u32_to_me(value_buf
, instr
);
1465 h_u32_to_be(value_buf
, instr
);
1467 CHECK_RETVAL(target_write_buffer(target
, address
, 4, value_buf
));
1473 * Read 32-bit instruction from memory. It is like target_read_u32, however in
1474 * case of little endian ARC instructions are in middle endian format, so
1475 * different type of conversion should be done.
1477 static int arc_read_instruction_u32(struct target
*target
, uint32_t address
,
1480 uint8_t value_buf
[4];
1482 if (!target_was_examined(target
)) {
1483 LOG_ERROR("Target not examined yet");
1488 CHECK_RETVAL(target_read_buffer(target
, address
, 4, value_buf
));
1490 if (target
->endianness
== TARGET_LITTLE_ENDIAN
)
1491 *value
= arc_me_to_h_u32(value_buf
);
1493 *value
= be_to_h_u32(value_buf
);
1495 LOG_DEBUG("Address: 0x%08" PRIx32
", value: 0x%08" PRIx32
, address
,
1501 /* Actionpoint mechanism allows to setup HW breakpoints
1502 * and watchpoints. Each actionpoint is controlled by
1503 * 3 aux registers: Actionpoint(AP) match mask(AP_AMM), AP match value(AP_AMV)
1504 * and AP control(AC).
1505 * This function is for setting/unsetting actionpoints:
1506 * at - actionpoint target: trigger on mem/reg access
1507 * tt - transaction type : trigger on r/w. */
1508 static int arc_configure_actionpoint(struct target
*target
, uint32_t ap_num
,
1509 uint32_t match_value
, uint32_t control_tt
, uint32_t control_at
)
1511 struct arc_common
*arc
= target_to_arc(target
);
1513 if (control_tt
!= AP_AC_TT_DISABLE
) {
1515 if (arc
->actionpoints_num_avail
< 1) {
1516 LOG_ERROR("No free actionpoints, maximum amount is %u",
1517 arc
->actionpoints_num
);
1518 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
1521 /* Names of register to set - 24 chars should be enough. Looks a little
1522 * bit out-of-place for C code, but makes it aligned to the bigger
1523 * concept of "ARC registers are defined in TCL" as far as possible.
1525 char ap_amv_reg_name
[24], ap_amm_reg_name
[24], ap_ac_reg_name
[24];
1526 snprintf(ap_amv_reg_name
, 24, "ap_amv%" PRIu32
, ap_num
);
1527 snprintf(ap_amm_reg_name
, 24, "ap_amm%" PRIu32
, ap_num
);
1528 snprintf(ap_ac_reg_name
, 24, "ap_ac%" PRIu32
, ap_num
);
1529 CHECK_RETVAL(arc_set_register_value(target
, ap_amv_reg_name
,
1531 CHECK_RETVAL(arc_set_register_value(target
, ap_amm_reg_name
, 0));
1532 CHECK_RETVAL(arc_set_register_value(target
, ap_ac_reg_name
,
1533 control_tt
| control_at
));
1534 arc
->actionpoints_num_avail
--;
1536 char ap_ac_reg_name
[24];
1537 snprintf(ap_ac_reg_name
, 24, "ap_ac%" PRIu32
, ap_num
);
1538 CHECK_RETVAL(arc_set_register_value(target
, ap_ac_reg_name
,
1540 arc
->actionpoints_num_avail
++;
1546 static int arc_set_breakpoint(struct target
*target
,
1547 struct breakpoint
*breakpoint
)
1549 if (breakpoint
->is_set
) {
1550 LOG_WARNING("breakpoint already set");
1554 if (breakpoint
->type
== BKPT_SOFT
) {
1555 LOG_DEBUG("bpid: %" PRIu32
, breakpoint
->unique_id
);
1557 if (breakpoint
->length
== 4) {
1558 uint32_t verify
= 0xffffffff;
1560 CHECK_RETVAL(target_read_buffer(target
, breakpoint
->address
, breakpoint
->length
,
1561 breakpoint
->orig_instr
));
1563 CHECK_RETVAL(arc_write_instruction_u32(target
, breakpoint
->address
,
1566 CHECK_RETVAL(arc_read_instruction_u32(target
, breakpoint
->address
, &verify
));
1568 if (verify
!= ARC_SDBBP_32
) {
1569 LOG_ERROR("Unable to set 32bit breakpoint at address @0x%" TARGET_PRIxADDR
1570 " - check that memory is read/writable", breakpoint
->address
);
1573 } else if (breakpoint
->length
== 2) {
1574 uint16_t verify
= 0xffff;
1576 CHECK_RETVAL(target_read_buffer(target
, breakpoint
->address
, breakpoint
->length
,
1577 breakpoint
->orig_instr
));
1578 CHECK_RETVAL(target_write_u16(target
, breakpoint
->address
, ARC_SDBBP_16
));
1580 CHECK_RETVAL(target_read_u16(target
, breakpoint
->address
, &verify
));
1581 if (verify
!= ARC_SDBBP_16
) {
1582 LOG_ERROR("Unable to set 16bit breakpoint at address @0x%" TARGET_PRIxADDR
1583 " - check that memory is read/writable", breakpoint
->address
);
1587 LOG_ERROR("Invalid breakpoint length: target supports only 2 or 4");
1588 return ERROR_COMMAND_ARGUMENT_INVALID
;
1591 breakpoint
->is_set
= true;
1592 } else if (breakpoint
->type
== BKPT_HARD
) {
1593 struct arc_common
*arc
= target_to_arc(target
);
1594 struct arc_actionpoint
*ap_list
= arc
->actionpoints_list
;
1595 unsigned int bp_num
;
1597 for (bp_num
= 0; bp_num
< arc
->actionpoints_num
; bp_num
++) {
1598 if (!ap_list
[bp_num
].used
)
1602 if (bp_num
>= arc
->actionpoints_num
) {
1603 LOG_ERROR("No free actionpoints, maximum amount is %u",
1604 arc
->actionpoints_num
);
1605 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
1608 int retval
= arc_configure_actionpoint(target
, bp_num
,
1609 breakpoint
->address
, AP_AC_TT_READWRITE
, AP_AC_AT_INST_ADDR
);
1611 if (retval
== ERROR_OK
) {
1612 breakpoint_hw_set(breakpoint
, bp_num
);
1613 ap_list
[bp_num
].used
= 1;
1614 ap_list
[bp_num
].bp_value
= breakpoint
->address
;
1615 ap_list
[bp_num
].type
= ARC_AP_BREAKPOINT
;
1617 LOG_DEBUG("bpid: %" PRIu32
", bp_num %u bp_value 0x%" PRIx32
,
1618 breakpoint
->unique_id
, bp_num
, ap_list
[bp_num
].bp_value
);
1622 LOG_DEBUG("ERROR: setting unknown breakpoint type");
1629 static int arc_unset_breakpoint(struct target
*target
,
1630 struct breakpoint
*breakpoint
)
1632 int retval
= ERROR_OK
;
1634 if (!breakpoint
->is_set
) {
1635 LOG_WARNING("breakpoint not set");
1639 if (breakpoint
->type
== BKPT_SOFT
) {
1640 /* restore original instruction (kept in target endianness) */
1641 LOG_DEBUG("bpid: %" PRIu32
, breakpoint
->unique_id
);
1642 if (breakpoint
->length
== 4) {
1643 uint32_t current_instr
;
1645 /* check that user program has not modified breakpoint instruction */
1646 CHECK_RETVAL(arc_read_instruction_u32(target
, breakpoint
->address
, ¤t_instr
));
1648 if (current_instr
== ARC_SDBBP_32
) {
1649 retval
= target_write_buffer(target
, breakpoint
->address
,
1650 breakpoint
->length
, breakpoint
->orig_instr
);
1651 if (retval
!= ERROR_OK
)
1654 LOG_WARNING("Software breakpoint @0x%" TARGET_PRIxADDR
1655 " has been overwritten outside of debugger."
1656 "Expected: @0x%x, got: @0x%" PRIx32
,
1657 breakpoint
->address
, ARC_SDBBP_32
, current_instr
);
1659 } else if (breakpoint
->length
== 2) {
1660 uint16_t current_instr
;
1662 /* check that user program has not modified breakpoint instruction */
1663 CHECK_RETVAL(target_read_u16(target
, breakpoint
->address
, ¤t_instr
));
1664 if (current_instr
== ARC_SDBBP_16
) {
1665 retval
= target_write_buffer(target
, breakpoint
->address
,
1666 breakpoint
->length
, breakpoint
->orig_instr
);
1667 if (retval
!= ERROR_OK
)
1670 LOG_WARNING("Software breakpoint @0x%" TARGET_PRIxADDR
1671 " has been overwritten outside of debugger. "
1672 "Expected: 0x%04x, got: 0x%04" PRIx16
,
1673 breakpoint
->address
, ARC_SDBBP_16
, current_instr
);
1676 LOG_ERROR("Invalid breakpoint length: target supports only 2 or 4");
1677 return ERROR_COMMAND_ARGUMENT_INVALID
;
1679 breakpoint
->is_set
= false;
1681 } else if (breakpoint
->type
== BKPT_HARD
) {
1682 struct arc_common
*arc
= target_to_arc(target
);
1683 struct arc_actionpoint
*ap_list
= arc
->actionpoints_list
;
1684 unsigned int bp_num
= breakpoint
->number
;
1686 if (bp_num
>= arc
->actionpoints_num
) {
1687 LOG_DEBUG("Invalid actionpoint ID: %u in breakpoint: %" PRIu32
,
1688 bp_num
, breakpoint
->unique_id
);
1692 retval
= arc_configure_actionpoint(target
, bp_num
,
1693 breakpoint
->address
, AP_AC_TT_DISABLE
, AP_AC_AT_INST_ADDR
);
1695 if (retval
== ERROR_OK
) {
1696 breakpoint
->is_set
= false;
1697 ap_list
[bp_num
].used
= 0;
1698 ap_list
[bp_num
].bp_value
= 0;
1700 LOG_DEBUG("bpid: %" PRIu32
" - released actionpoint ID: %u",
1701 breakpoint
->unique_id
, bp_num
);
1704 LOG_DEBUG("ERROR: unsetting unknown breakpoint type");
1711 static int arc_enable_breakpoints(struct target
*target
)
1713 struct breakpoint
*breakpoint
= target
->breakpoints
;
1715 /* set any pending breakpoints */
1716 while (breakpoint
) {
1717 if (!breakpoint
->is_set
)
1718 CHECK_RETVAL(arc_set_breakpoint(target
, breakpoint
));
1719 breakpoint
= breakpoint
->next
;
1725 static int arc_add_breakpoint(struct target
*target
, struct breakpoint
*breakpoint
)
1727 if (target
->state
== TARGET_HALTED
) {
1728 return arc_set_breakpoint(target
, breakpoint
);
1731 LOG_TARGET_ERROR(target
, "not halted (add breakpoint)");
1732 return ERROR_TARGET_NOT_HALTED
;
1736 static int arc_remove_breakpoint(struct target
*target
,
1737 struct breakpoint
*breakpoint
)
1739 if (target
->state
== TARGET_HALTED
) {
1740 if (breakpoint
->is_set
)
1741 CHECK_RETVAL(arc_unset_breakpoint(target
, breakpoint
));
1743 LOG_TARGET_ERROR(target
, "not halted (remove breakpoint)");
1744 return ERROR_TARGET_NOT_HALTED
;
1750 static void arc_reset_actionpoints(struct target
*target
)
1752 struct arc_common
*arc
= target_to_arc(target
);
1753 struct arc_actionpoint
*ap_list
= arc
->actionpoints_list
;
1754 struct breakpoint
*next_b
;
1755 struct watchpoint
*next_w
;
1757 while (target
->breakpoints
) {
1758 next_b
= target
->breakpoints
->next
;
1759 arc_remove_breakpoint(target
, target
->breakpoints
);
1760 free(target
->breakpoints
->orig_instr
);
1761 free(target
->breakpoints
);
1762 target
->breakpoints
= next_b
;
1764 while (target
->watchpoints
) {
1765 next_w
= target
->watchpoints
->next
;
1766 arc_remove_watchpoint(target
, target
->watchpoints
);
1767 free(target
->watchpoints
);
1768 target
->watchpoints
= next_w
;
1770 for (unsigned int i
= 0; i
< arc
->actionpoints_num
; i
++) {
1771 if ((ap_list
[i
].used
) && (ap_list
[i
].reg_address
))
1772 arc_remove_auxreg_actionpoint(target
, ap_list
[i
].reg_address
);
1776 int arc_set_actionpoints_num(struct target
*target
, uint32_t ap_num
)
1778 LOG_DEBUG("target=%s actionpoints=%" PRIu32
, target_name(target
), ap_num
);
1779 struct arc_common
*arc
= target_to_arc(target
);
1781 /* Make sure that there are no enabled actionpoints in target. */
1782 arc_reset_actionpoints(target
);
1784 /* Assume that all points have been removed from target. */
1785 free(arc
->actionpoints_list
);
1787 arc
->actionpoints_num_avail
= ap_num
;
1788 arc
->actionpoints_num
= ap_num
;
1789 /* calloc can be safely called when ncount == 0. */
1790 arc
->actionpoints_list
= calloc(ap_num
, sizeof(struct arc_actionpoint
));
1792 if (!arc
->actionpoints_list
) {
1793 LOG_ERROR("Unable to allocate memory");
1800 int arc_add_auxreg_actionpoint(struct target
*target
,
1801 uint32_t auxreg_addr
, uint32_t transaction
)
1803 unsigned int ap_num
= 0;
1804 int retval
= ERROR_OK
;
1806 if (target
->state
!= TARGET_HALTED
)
1807 return ERROR_TARGET_NOT_HALTED
;
1809 struct arc_common
*arc
= target_to_arc(target
);
1810 struct arc_actionpoint
*ap_list
= arc
->actionpoints_list
;
1812 while (ap_list
[ap_num
].used
)
1815 if (ap_num
>= arc
->actionpoints_num
) {
1816 LOG_ERROR("No actionpoint free, maximum amount is %u",
1817 arc
->actionpoints_num
);
1818 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
1821 retval
= arc_configure_actionpoint(target
, ap_num
,
1822 auxreg_addr
, transaction
, AP_AC_AT_AUXREG_ADDR
);
1824 if (retval
== ERROR_OK
) {
1825 ap_list
[ap_num
].used
= 1;
1826 ap_list
[ap_num
].reg_address
= auxreg_addr
;
1832 int arc_remove_auxreg_actionpoint(struct target
*target
, uint32_t auxreg_addr
)
1834 int retval
= ERROR_OK
;
1835 bool ap_found
= false;
1836 unsigned int ap_num
= 0;
1838 if (target
->state
!= TARGET_HALTED
)
1839 return ERROR_TARGET_NOT_HALTED
;
1841 struct arc_common
*arc
= target_to_arc(target
);
1842 struct arc_actionpoint
*ap_list
= arc
->actionpoints_list
;
1844 while ((ap_list
[ap_num
].used
) && (ap_num
< arc
->actionpoints_num
)) {
1845 if (ap_list
[ap_num
].reg_address
== auxreg_addr
) {
1853 retval
= arc_configure_actionpoint(target
, ap_num
,
1854 auxreg_addr
, AP_AC_TT_DISABLE
, AP_AC_AT_AUXREG_ADDR
);
1856 if (retval
== ERROR_OK
) {
1857 ap_list
[ap_num
].used
= 0;
1858 ap_list
[ap_num
].bp_value
= 0;
1861 LOG_ERROR("Register actionpoint not found");
1867 static int arc_set_watchpoint(struct target
*target
,
1868 struct watchpoint
*watchpoint
)
1870 unsigned int wp_num
;
1871 struct arc_common
*arc
= target_to_arc(target
);
1872 struct arc_actionpoint
*ap_list
= arc
->actionpoints_list
;
1874 if (watchpoint
->is_set
) {
1875 LOG_WARNING("watchpoint already set");
1879 for (wp_num
= 0; wp_num
< arc
->actionpoints_num
; wp_num
++) {
1880 if (!ap_list
[wp_num
].used
)
1884 if (wp_num
>= arc
->actionpoints_num
) {
1885 LOG_ERROR("No free actionpoints, maximum amount is %u",
1886 arc
->actionpoints_num
);
1887 return ERROR_TARGET_RESOURCE_NOT_AVAILABLE
;
1890 if (watchpoint
->length
!= 4) {
1891 LOG_ERROR("Only watchpoints of length 4 are supported");
1892 return ERROR_TARGET_UNALIGNED_ACCESS
;
1895 int enable
= AP_AC_TT_DISABLE
;
1896 switch (watchpoint
->rw
) {
1898 enable
= AP_AC_TT_READ
;
1901 enable
= AP_AC_TT_WRITE
;
1904 enable
= AP_AC_TT_READWRITE
;
1907 LOG_ERROR("BUG: watchpoint->rw neither read, write nor access");
1911 int retval
= arc_configure_actionpoint(target
, wp_num
,
1912 watchpoint
->address
, enable
, AP_AC_AT_MEMORY_ADDR
);
1914 if (retval
== ERROR_OK
) {
1915 watchpoint_set(watchpoint
, wp_num
);
1916 ap_list
[wp_num
].used
= 1;
1917 ap_list
[wp_num
].bp_value
= watchpoint
->address
;
1918 ap_list
[wp_num
].type
= ARC_AP_WATCHPOINT
;
1920 LOG_DEBUG("wpid: %" PRIu32
", wp_num %u wp_value 0x%" PRIx32
,
1921 watchpoint
->unique_id
, wp_num
, ap_list
[wp_num
].bp_value
);
1927 static int arc_unset_watchpoint(struct target
*target
,
1928 struct watchpoint
*watchpoint
)
1930 /* get pointers to arch-specific information */
1931 struct arc_common
*arc
= target_to_arc(target
);
1932 struct arc_actionpoint
*ap_list
= arc
->actionpoints_list
;
1934 if (!watchpoint
->is_set
) {
1935 LOG_WARNING("watchpoint not set");
1939 unsigned int wp_num
= watchpoint
->number
;
1940 if (wp_num
>= arc
->actionpoints_num
) {
1941 LOG_DEBUG("Invalid actionpoint ID: %u in watchpoint: %" PRIu32
,
1942 wp_num
, watchpoint
->unique_id
);
1946 int retval
= arc_configure_actionpoint(target
, wp_num
,
1947 watchpoint
->address
, AP_AC_TT_DISABLE
, AP_AC_AT_MEMORY_ADDR
);
1949 if (retval
== ERROR_OK
) {
1950 watchpoint
->is_set
= false;
1951 ap_list
[wp_num
].used
= 0;
1952 ap_list
[wp_num
].bp_value
= 0;
1954 LOG_DEBUG("wpid: %" PRIu32
" - releasing actionpoint ID: %u",
1955 watchpoint
->unique_id
, wp_num
);
1961 static int arc_enable_watchpoints(struct target
*target
)
1963 struct watchpoint
*watchpoint
= target
->watchpoints
;
1965 /* set any pending watchpoints */
1966 while (watchpoint
) {
1967 if (!watchpoint
->is_set
)
1968 CHECK_RETVAL(arc_set_watchpoint(target
, watchpoint
));
1969 watchpoint
= watchpoint
->next
;
1975 static int arc_add_watchpoint(struct target
*target
,
1976 struct watchpoint
*watchpoint
)
1978 if (target
->state
!= TARGET_HALTED
) {
1979 LOG_TARGET_ERROR(target
, "not halted");
1980 return ERROR_TARGET_NOT_HALTED
;
1983 CHECK_RETVAL(arc_set_watchpoint(target
, watchpoint
));
1988 static int arc_remove_watchpoint(struct target
*target
,
1989 struct watchpoint
*watchpoint
)
1991 if (target
->state
!= TARGET_HALTED
) {
1992 LOG_TARGET_ERROR(target
, "not halted");
1993 return ERROR_TARGET_NOT_HALTED
;
1996 if (watchpoint
->is_set
)
1997 CHECK_RETVAL(arc_unset_watchpoint(target
, watchpoint
));
2002 static int arc_hit_watchpoint(struct target
*target
, struct watchpoint
**hit_watchpoint
)
2005 assert(hit_watchpoint
);
2007 struct arc_actionpoint
*actionpoint
= NULL
;
2008 CHECK_RETVAL(get_current_actionpoint(target
, &actionpoint
));
2011 if (!actionpoint
->used
)
2012 LOG_WARNING("Target halted by unused actionpoint.");
2014 /* If this check fails - that is some sort of an error in OpenOCD. */
2015 if (actionpoint
->type
!= ARC_AP_WATCHPOINT
)
2016 LOG_WARNING("Target halted by breakpoint, but is treated as a watchpoint.");
2018 for (struct watchpoint
*watchpoint
= target
->watchpoints
;
2020 watchpoint
= watchpoint
->next
) {
2021 if (actionpoint
->bp_value
== watchpoint
->address
) {
2022 *hit_watchpoint
= watchpoint
;
2023 LOG_DEBUG("Hit watchpoint, wpid: %" PRIu32
", watchpoint num: %u",
2024 watchpoint
->unique_id
, watchpoint
->number
);
2033 /* Helper function which switches core to single_step mode by
2034 * doing aux r/w operations. */
2035 static int arc_config_step(struct target
*target
, int enable_step
)
2039 struct arc_common
*arc
= target_to_arc(target
);
2041 /* enable core debug step mode */
2043 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
,
2045 value
&= ~SET_CORE_AE_BIT
; /* clear the AE bit */
2046 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_STATUS32_REG
,
2048 LOG_DEBUG(" [status32:0x%08" PRIx32
"]", value
);
2050 /* Doing read-modify-write, because DEBUG might contain manually set
2051 * bits like UB or ED, which should be preserved. */
2052 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
,
2053 AUX_DEBUG_REG
, &value
));
2054 value
|= SET_CORE_SINGLE_INSTR_STEP
; /* set the IS bit */
2055 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DEBUG_REG
,
2057 LOG_DEBUG("core debug step mode enabled [debug-reg:0x%08" PRIx32
"]", value
);
2059 } else { /* disable core debug step mode */
2060 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_DEBUG_REG
,
2062 value
&= ~SET_CORE_SINGLE_INSTR_STEP
; /* clear the IS bit */
2063 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DEBUG_REG
,
2065 LOG_DEBUG("core debug step mode disabled");
2071 static int arc_single_step_core(struct target
*target
)
2073 CHECK_RETVAL(arc_debug_entry(target
));
2075 /* disable interrupts while stepping */
2076 CHECK_RETVAL(arc_enable_interrupts(target
, 0));
2078 /* configure single step mode */
2079 CHECK_RETVAL(arc_config_step(target
, 1));
2081 /* exit debug mode */
2082 CHECK_RETVAL(arc_exit_debug(target
));
2087 static int arc_step(struct target
*target
, int current
, target_addr_t address
,
2088 int handle_breakpoints
)
2090 /* get pointers to arch-specific information */
2091 struct arc_common
*arc
= target_to_arc(target
);
2092 struct breakpoint
*breakpoint
= NULL
;
2093 struct reg
*pc
= &(arc
->core_and_aux_cache
->reg_list
[arc
->pc_index_in_cache
]);
2095 if (target
->state
!= TARGET_HALTED
) {
2096 LOG_TARGET_ERROR(target
, "not halted");
2097 return ERROR_TARGET_NOT_HALTED
;
2100 /* current = 1: continue on current pc, otherwise continue at <address> */
2102 buf_set_u32(pc
->value
, 0, 32, address
);
2107 LOG_DEBUG("Target steps one instruction from PC=0x%" PRIx32
,
2108 buf_get_u32(pc
->value
, 0, 32));
2110 /* the front-end may request us not to handle breakpoints */
2111 if (handle_breakpoints
) {
2112 breakpoint
= breakpoint_find(target
, buf_get_u32(pc
->value
, 0, 32));
2114 CHECK_RETVAL(arc_unset_breakpoint(target
, breakpoint
));
2117 /* restore context */
2118 CHECK_RETVAL(arc_restore_context(target
));
2120 target
->debug_reason
= DBG_REASON_SINGLESTEP
;
2122 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_RESUMED
));
2124 /* disable interrupts while stepping */
2125 CHECK_RETVAL(arc_enable_interrupts(target
, 0));
2127 /* do a single step */
2128 CHECK_RETVAL(arc_config_step(target
, 1));
2130 /* make sure we done our step */
2133 /* registers are now invalid */
2134 register_cache_invalidate(arc
->core_and_aux_cache
);
2137 CHECK_RETVAL(arc_set_breakpoint(target
, breakpoint
));
2139 LOG_DEBUG("target stepped ");
2141 target
->state
= TARGET_HALTED
;
2143 /* Saving context */
2144 CHECK_RETVAL(arc_debug_entry(target
));
2145 CHECK_RETVAL(target_call_event_callbacks(target
, TARGET_EVENT_HALTED
));
2151 /* This function invalidates icache. */
2152 static int arc_icache_invalidate(struct target
*target
)
2156 struct arc_common
*arc
= target_to_arc(target
);
2158 /* Don't waste time if already done. */
2159 if (!arc
->has_icache
|| arc
->icache_invalidated
)
2162 LOG_DEBUG("Invalidating I$.");
2164 value
= IC_IVIC_INVALIDATE
; /* invalidate I$ */
2165 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_IC_IVIC_REG
, value
));
2167 arc
->icache_invalidated
= true;
2172 /* This function invalidates dcache */
2173 static int arc_dcache_invalidate(struct target
*target
)
2175 uint32_t value
, dc_ctrl_value
;
2177 struct arc_common
*arc
= target_to_arc(target
);
2179 if (!arc
->has_dcache
|| arc
->dcache_invalidated
)
2182 LOG_DEBUG("Invalidating D$.");
2184 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_DC_CTRL_REG
, &value
));
2185 dc_ctrl_value
= value
;
2186 value
&= ~DC_CTRL_IM
;
2188 /* set DC_CTRL invalidate mode to invalidate-only (no flushing!!) */
2189 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DC_CTRL_REG
, value
));
2190 value
= DC_IVDC_INVALIDATE
; /* invalidate D$ */
2191 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DC_IVDC_REG
, value
));
2193 /* restore DC_CTRL invalidate mode */
2194 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DC_CTRL_REG
, dc_ctrl_value
));
2196 arc
->dcache_invalidated
= true;
2201 /* This function invalidates l2 cache. */
2202 static int arc_l2cache_invalidate(struct target
*target
)
2204 uint32_t value
, slc_ctrl_value
;
2206 struct arc_common
*arc
= target_to_arc(target
);
2208 if (!arc
->has_l2cache
|| arc
->l2cache_invalidated
)
2211 LOG_DEBUG("Invalidating L2$.");
2213 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, SLC_AUX_CACHE_CTRL
, &value
));
2214 slc_ctrl_value
= value
;
2215 value
&= ~L2_CTRL_IM
;
2217 /* set L2_CTRL invalidate mode to invalidate-only (no flushing!!) */
2218 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, SLC_AUX_CACHE_CTRL
, value
));
2219 /* invalidate L2$ */
2220 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, SLC_AUX_CACHE_INV
, L2_INV_IV
));
2222 /* Wait until invalidate operation ends */
2224 LOG_DEBUG("Waiting for invalidation end.");
2225 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, SLC_AUX_CACHE_CTRL
, &value
));
2226 } while (value
& L2_CTRL_BS
);
2228 /* restore L2_CTRL invalidate mode */
2229 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, SLC_AUX_CACHE_CTRL
, slc_ctrl_value
));
2231 arc
->l2cache_invalidated
= true;
2237 int arc_cache_invalidate(struct target
*target
)
2239 CHECK_RETVAL(arc_icache_invalidate(target
));
2240 CHECK_RETVAL(arc_dcache_invalidate(target
));
2241 CHECK_RETVAL(arc_l2cache_invalidate(target
));
2246 /* Flush data cache. This function is cheap to call and return quickly if D$
2247 * already has been flushed since target had been halted. JTAG debugger reads
2248 * values directly from memory, bypassing cache, so if there are unflushed
2249 * lines debugger will read invalid values, which will cause a lot of troubles.
2251 static int arc_dcache_flush(struct target
*target
)
2253 uint32_t value
, dc_ctrl_value
;
2254 bool has_to_set_dc_ctrl_im
;
2256 struct arc_common
*arc
= target_to_arc(target
);
2258 /* Don't waste time if already done. */
2259 if (!arc
->has_dcache
|| arc
->dcache_flushed
)
2262 LOG_DEBUG("Flushing D$.");
2264 /* Store current value of DC_CTRL */
2265 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, AUX_DC_CTRL_REG
, &dc_ctrl_value
));
2267 /* Set DC_CTRL invalidate mode to flush (if not already set) */
2268 has_to_set_dc_ctrl_im
= (dc_ctrl_value
& DC_CTRL_IM
) == 0;
2269 if (has_to_set_dc_ctrl_im
) {
2270 value
= dc_ctrl_value
| DC_CTRL_IM
;
2271 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DC_CTRL_REG
, value
));
2275 value
= DC_IVDC_INVALIDATE
;
2276 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DC_IVDC_REG
, value
));
2278 /* Restore DC_CTRL invalidate mode (even of flush failed) */
2279 if (has_to_set_dc_ctrl_im
)
2280 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, AUX_DC_CTRL_REG
, dc_ctrl_value
));
2282 arc
->dcache_flushed
= true;
2287 /* This function flushes l2cache. */
2288 static int arc_l2cache_flush(struct target
*target
)
2292 struct arc_common
*arc
= target_to_arc(target
);
2294 /* Don't waste time if already done. */
2295 if (!arc
->has_l2cache
|| arc
->l2cache_flushed
)
2298 LOG_DEBUG("Flushing L2$.");
2300 /* Flush L2 cache */
2301 CHECK_RETVAL(arc_jtag_write_aux_reg_one(&arc
->jtag_info
, SLC_AUX_CACHE_FLUSH
, L2_FLUSH_FL
));
2303 /* Wait until flush operation ends */
2305 LOG_DEBUG("Waiting for flushing end.");
2306 CHECK_RETVAL(arc_jtag_read_aux_reg_one(&arc
->jtag_info
, SLC_AUX_CACHE_CTRL
, &value
));
2307 } while (value
& L2_CTRL_BS
);
2309 arc
->l2cache_flushed
= true;
2314 int arc_cache_flush(struct target
*target
)
2316 CHECK_RETVAL(arc_dcache_flush(target
));
2317 CHECK_RETVAL(arc_l2cache_flush(target
));
2323 struct target_type arcv2_target
= {
2328 .arch_state
= arc_arch_state
,
2330 /* TODO That seems like something similar to metaware hostlink, so perhaps
2331 * we can exploit this in the future. */
2332 .target_request_data
= NULL
,
2335 .resume
= arc_resume
,
2338 .assert_reset
= arc_assert_reset
,
2339 .deassert_reset
= arc_deassert_reset
,
2341 /* TODO Implement soft_reset_halt */
2342 .soft_reset_halt
= NULL
,
2344 .get_gdb_reg_list
= arc_get_gdb_reg_list
,
2346 .read_memory
= arc_mem_read
,
2347 .write_memory
= arc_mem_write
,
2348 .checksum_memory
= NULL
,
2349 .blank_check_memory
= NULL
,
2351 .add_breakpoint
= arc_add_breakpoint
,
2352 .add_context_breakpoint
= NULL
,
2353 .add_hybrid_breakpoint
= NULL
,
2354 .remove_breakpoint
= arc_remove_breakpoint
,
2355 .add_watchpoint
= arc_add_watchpoint
,
2356 .remove_watchpoint
= arc_remove_watchpoint
,
2357 .hit_watchpoint
= arc_hit_watchpoint
,
2359 .run_algorithm
= NULL
,
2360 .start_algorithm
= NULL
,
2361 .wait_algorithm
= NULL
,
2363 .commands
= arc_monitor_command_handlers
,
2365 .target_create
= arc_target_create
,
2366 .init_target
= arc_init_target
,
2367 .deinit_target
= arc_deinit_target
,
2368 .examine
= arc_examine
,
2371 .read_phys_memory
= NULL
,
2372 .write_phys_memory
= NULL
,
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)