34 #define DTMCONTROL 0x10
35 #define DTMCONTROL_VERSION (0xf)
39 #define RISCV_TRIGGER_HIT_NOT_FOUND ((int64_t)-1)
41 #define RISCV_HALT_GROUP_REPOLL_LIMIT 5
60 #define BSCAN_TUNNEL_IR_WIDTH_NBITS 7
171 static const char *
const names[] = {
201 .vpn_shift = {12, 22},
202 .vpn_mask = {0x3ff, 0x3ff},
203 .pte_ppn_shift = {10, 20},
204 .pte_ppn_mask = {0x3ff, 0xfff},
205 .pa_ppn_shift = {12, 22},
206 .pa_ppn_mask = {0x3ff, 0xfff},
214 .vpn_shift = {12, 22},
215 .vpn_mask = {0x3ff, 0xfff},
216 .pte_ppn_shift = {10, 20},
217 .pte_ppn_mask = {0x3ff, 0xfff},
218 .pa_ppn_shift = {12, 22},
219 .pa_ppn_mask = {0x3ff, 0xfff},
227 .vpn_shift = {12, 21, 30},
228 .vpn_mask = {0x1ff, 0x1ff, 0x1ff},
229 .pte_ppn_shift = {10, 19, 28},
230 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
231 .pa_ppn_shift = {12, 21, 30},
232 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
240 .vpn_shift = {12, 21, 30},
241 .vpn_mask = {0x1ff, 0x1ff, 0x7ff},
242 .pte_ppn_shift = {10, 19, 28},
243 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
244 .pa_ppn_shift = {12, 21, 30},
245 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
253 .vpn_shift = {12, 21, 30, 39},
254 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff},
255 .pte_ppn_shift = {10, 19, 28, 37},
256 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
257 .pa_ppn_shift = {12, 21, 30, 39},
258 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
266 .vpn_shift = {12, 21, 30, 39},
267 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x7ff},
268 .pte_ppn_shift = {10, 19, 28, 37},
269 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
270 .pa_ppn_shift = {12, 21, 30, 39},
271 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
279 .vpn_shift = {12, 21, 30, 39, 48},
280 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
281 .pte_ppn_shift = {10, 19, 28, 37, 46},
282 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
283 .pa_ppn_shift = {12, 21, 30, 39, 48},
284 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
292 .vpn_shift = {12, 21, 30, 39, 48},
293 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x7ff},
294 .pte_ppn_shift = {10, 19, 28, 37, 46},
295 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
296 .pa_ppn_shift = {12, 21, 30, 39, 48},
297 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
312 if (r->sample_buf.used + 5 < r->sample_buf.size) {
317 r->sample_buf.buf[r->sample_buf.used++] = now & 0xff;
318 r->sample_buf.buf[r->sample_buf.used++] = (now >> 8) & 0xff;
319 r->sample_buf.buf[r->sample_buf.used++] = (now >> 16) & 0xff;
320 r->sample_buf.buf[r->sample_buf.used++] = (now >> 24) & 0xff;
340 uint8_t tunneled_dr_width[4] = {32};
341 uint8_t out_value[5] = {0};
342 uint8_t in_value[5] = {0};
369 tunneled_dr[2].
out_value = tunneled_dr_width;
396 tunneled_dr[1].
out_value = tunneled_dr_width;
409 LOG_ERROR(
"failed jtag scan: %d", retval);
415 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
437 .in_value = in_ptr ? value :
NULL
446 LOG_ERROR(
"'dtmcs' scan failed on TAP %s, error code = %d",
454 LOG_DEBUG(
"TAP %s: DTMCS: 0x%" PRIx32
" -> 0x%" PRIx32,
471 switch (
info->dtm_version) {
494 config->dcsr_ebreak_fields[i] =
true;
496 config->detect_misa =
true;
529 #define RISCV_EBREAK_MODE_INVALID -1
532 { .
name =
"exception", .value =
false },
533 { .name =
"halt", .value =
true },
538 { .
name =
"off", .value =
false },
539 { .name =
"on", .value =
true },
540 { .name =
NULL, .value = -1 }
545 if (goi->
argc == 0) {
546 Jim_WrongNumArgs(goi->
interp, 1, goi->
argv - 1,
547 "[?execution_mode?] ?ebreak_action?");
550 struct jim_nvp *common_mode_nvp;
552 &common_mode_nvp) == JIM_OK) {
559 for (
int ebreak_ctl_i = 0; ebreak_ctl_i <
N_RISCV_MODE; ++ebreak_ctl_i)
560 config->dcsr_ebreak_fields[ebreak_ctl_i] = common_mode_nvp->
value;
568 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
596 const char *separator =
"";
599 const char *
const format =
"%s%s %s";
600 const char *
const priv_mode =
603 config->dcsr_ebreak_fields[ebreak_ctl_i])->
name;
605 len += snprintf(
NULL, 0, format, separator, priv_mode,
mode);
607 len += sprintf(
buffer + len, format, separator, priv_mode,
mode);
618 char *str = malloc(len + 1);
620 LOG_ERROR(
"Unable to allocate a string of %d bytes.", len + 1);
624 Jim_SetResultString(interp, str, len);
668 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
"");
686 Jim_SetResultString(goi->
interp,
700 Jim_SetResultString(goi->
interp,
705 assert(
false &&
"'jim_getopt_nvp' should have returned an error.");
715 info->cmd_ctx = cmd_ctx;
716 info->reset_delays_wait = -1;
725 if (ir_user4_raw == 0) {
748 for (
unsigned int i = 0; i < r->trigger_count; ++i) {
760 free(r->wp_triggers_negative_cache);
777 if (tt &&
info &&
info->version_specific)
786 free(
info->reserved_triggers);
826 bool size_power_of_2 = (
size & (
size - 1)) == 0;
827 bool addr_aligned = (
addr & (
size - 1)) == 0;
828 return size > 1 && size_power_of_2 && addr_aligned;
838 unsigned int num_found = 0;
839 unsigned int num_required = chained ? 2 : 1;
841 for (
unsigned int i = *idx; i < r->trigger_count; i++) {
842 if (r->trigger_unique_id[i] == -1) {
843 if (r->trigger_tinfo[i] & (1 <<
type)) {
845 if (num_required == num_found) {
847 *idx = i - (num_required - 1);
849 "%d trigger(s) of type %d found on index %u, "
851 num_required,
type, *idx,
852 chained ?
"true" :
"false");
871 for (
unsigned int i = 0; i < r->trigger_count; i++) {
872 if (r->trigger_unique_id[i] == unique_id)
880 const unsigned int riscv_reg_bits =
sizeof(
riscv_reg_t) * CHAR_BIT;
881 for (
unsigned int i = 0; i < riscv_reg_bits; i++) {
882 if ((1 & (
reg >> i)) == 0)
885 return riscv_reg_bits;
892 assert(r->reserved_triggers);
893 assert(idx < r->trigger_count);
894 if (r->reserved_triggers[idx]) {
896 "Trigger %u is reserved by 'reserve_trigger' command.", idx);
935 bool misa_s, misa_u, misa_h;
965 tdata1_ignore_mask |= !(misa_h && misa_s) ?
CSR_ICOUNT_VS : 0;
966 tdata1_ignore_mask |= !(misa_h && misa_u) ?
CSR_ICOUNT_VU : 0;
983 const bool tdata1_config_denied = (tdata1 & ~tdata1_ignore_mask) != (tdata1_rb & ~tdata1_ignore_mask);
989 bool unsupported_napot_range =
false;
991 if (!tdata1_config_denied) {
993 if (is_mcontrol && is_napot_match) {
996 if (maskmax_value < napot_size)
997 unsupported_napot_range =
true;
1001 const bool tdata2_config_denied = tdata2 != tdata2_rb;
1002 if (tdata1_config_denied || tdata2_config_denied || unsupported_napot_range) {
1005 if (tdata1_config_denied)
1007 "After writing 0x%" PRIx64
" to tdata1 it contains 0x%" PRIx64,
1010 if (tdata2_config_denied)
1012 "After writing 0x%" PRIx64
" to tdata2 it contains 0x%" PRIx64,
1015 if (unsupported_napot_range)
1017 "The requested NAPOT match range (tdata2=0x%" PRIx64
") exceeds maskmax_value=0x%" PRIx64,
1018 tdata2, maskmax_value);
1036 const uint32_t bpcontrol_x = 1<<0;
1037 const uint32_t bpcontrol_w = 1<<1;
1038 const uint32_t bpcontrol_r = 1<<2;
1039 const uint32_t bpcontrol_u = 1<<3;
1040 const uint32_t bpcontrol_s = 1<<4;
1041 const uint32_t bpcontrol_h = 1<<5;
1042 const uint32_t bpcontrol_m = 1<<6;
1043 const uint32_t bpcontrol_bpmatch = 0xf << 7;
1044 const uint32_t bpcontrol_bpaction = 0xff << 11;
1046 unsigned int idx = 0;
1053 if (tdata1 & (bpcontrol_r | bpcontrol_w | bpcontrol_x)) {
1062 tdata1 =
set_field(tdata1, bpcontrol_u, !!(r->misa &
BIT(
'U' -
'A')));
1063 tdata1 =
set_field(tdata1, bpcontrol_s, !!(r->misa &
BIT(
'S' -
'A')));
1064 tdata1 =
set_field(tdata1, bpcontrol_h, !!(r->misa &
BIT(
'H' -
'A')));
1065 tdata1 =
set_field(tdata1, bpcontrol_m, 1);
1066 tdata1 =
set_field(tdata1, bpcontrol_bpaction, 0);
1067 tdata1 =
set_field(tdata1, bpcontrol_bpmatch, 0);
1106 if (elem_2->
tdata2 == find_tdata2)
1116 if (elem_1->
tdata1 == find_tdata1)
1126 r->wp_triggers_negative_cache = (
struct list_head *)calloc(r->trigger_count,
1128 for (
unsigned int i = 0; i < r->trigger_count; ++i)
1191 for (
unsigned int idx = 0;
1219 for (
unsigned int idx = 0;
1348 if (r->wp_allow_napot_trigger) {
1360 "Use 'riscv set_enable_trigger_feature napot wp' to enable it.");
1364 if (r->wp_allow_ge_lt_trigger) {
1396 "Use 'riscv set_enable_trigger_feature ge_lt wp' to enable it.");
1400 if (r->wp_allow_equality_match_trigger) {
1412 "Use 'riscv set_enable_trigger_feature eq wp' to enable it.");
1417 ", but may not match accesses at addresses in the inclusive range from 0x%"
1421 if (!
info->range_trigger_fallback_encountered)
1426 "Could not set a trigger that will match a whole address range. "
1427 "As a fallback, this trigger (and maybe others) will only match "
1428 "against the first address of the range.");
1429 info->range_trigger_fallback_encountered =
true;
1461 bool m,
bool s,
bool u,
bool pending,
unsigned int count,
1481 unsigned int idx = 0;
1488 r->trigger_unique_id[idx] = unique_id;
1493 bool nmi,
bool m,
bool s,
bool u,
riscv_reg_t interrupts,
1514 unsigned int idx = 0;
1521 r->trigger_unique_id[idx] = unique_id;
1526 bool m,
bool s,
bool u,
riscv_reg_t exception_codes,
1544 tdata2 = exception_codes;
1546 unsigned int idx = 0;
1553 r->trigger_unique_id[idx] = unique_id;
1596 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1599 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1601 if (access_size <=
size &&
address % access_size == 0)
1605 unsigned int offset_head =
address % access_size;
1606 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1607 uint8_t helper_buf[n_blocks * access_size];
1614 memcpy(helper_buf + offset_head,
buffer,
size);
1623 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1626 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1628 if (access_size <=
size &&
address % access_size == 0)
1632 unsigned int offset_head =
address % access_size;
1633 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1634 uint8_t helper_buf[n_blocks * access_size];
1641 memcpy(
buffer, helper_buf + offset_head,
size);
1654 unsigned int preferred_size =
size;
1655 while (
address % preferred_size != 0)
1656 preferred_size /= 2;
1664 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1665 if (access_size == preferred_size)
1686 unsigned int preferred_size =
size;
1687 while (
address % preferred_size != 0)
1688 preferred_size /= 2;
1696 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1697 if (access_size == preferred_size)
1734 uint8_t buff[4] = { 0 };
1773 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1774 if (r->trigger_unique_id[i] ==
unique_id) {
1777 r->trigger_unique_id[i] = -1;
1785 "Couldn't find the hardware resources used by hardware trigger.");
1887 const uint32_t hit_info = (hit1 << 1) | hit0;
1910 for (uint64_t i = 0; i <
ARRAY_SIZE(tdata1_tests); ++i) {
1915 if (tdata1_test_rb == tdata1_tests[i]) {
1932 bool *need_single_step)
1940 assert(need_single_step);
1941 *need_single_step =
false;
1948 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1949 if (r->trigger_unique_id[i] == -1)
1960 uint64_t hit_mask = 0;
1967 *need_single_step =
true;
1972 *need_single_step =
true;
1980 *need_single_step =
true;
1999 if (tdata1 & hit_mask) {
2001 ") has hit bit set. (need_single_step=%s)",
2002 i, r->trigger_unique_id[i], (*need_single_step) ?
"yes" :
"no");
2024 uint16_t offset_4to2and7to6_bits =
2026 uint16_t offset_4to2_bits = offset_4to2and7to6_bits >> 2;
2027 uint16_t offset_7to6_bits = offset_4to2and7to6_bits & 0x3;
2029 return (offset_4to2_bits << 2) + (offset_5_bit << 5)
2030 + (offset_7to6_bits << 6);
2036 uint16_t offset_4to3and8to6_bits =
2038 uint16_t offset_4to3_bits = offset_4to3and8to6_bits >> 3;
2039 uint16_t offset_8to6_bits = offset_4to3and8to6_bits & 0x7;
2041 return (offset_4to3_bits << 3) + (offset_5_bit << 5)
2042 + (offset_8to6_bits << 6);
2048 uint16_t offset_5to2and7to6_bits =
2050 uint16_t offset_5to2_bits = offset_5to2and7to6_bits >> 2;
2051 uint16_t offset_7to6_bits = offset_5to2and7to6_bits & 0x3;
2052 return (offset_5to2_bits << 2) + (offset_7to6_bits << 6);
2058 uint16_t offset_5to3and8to6_bits =
2060 uint16_t offset_5to3_bits = offset_5to3and8to6_bits >> 3;
2061 uint16_t offset_8to6_bits = offset_5to3and8to6_bits & 0x7;
2062 return (offset_5to3_bits << 3) + (offset_8to6_bits << 6);
2069 uint16_t offset_2_bit = offset_2and6_bits >> 1;
2070 uint16_t offset_6_bit = offset_2and6_bits & 0x1;
2072 return (offset_2_bit << 2) + (offset_5to3_bits << 3) + (offset_6_bit << 6);
2080 return (offset_5to3_bits << 3) + (offset_7to6_bits << 6);
2087 uint16_t offset_5to4and8_bits =
2089 uint16_t offset_5to4_bits = offset_5to4and8_bits >> 1;
2090 uint16_t offset_8_bit = offset_5to4and8_bits & 0x1;
2091 return (offset_5to4_bits << 4) + (offset_7to6_bits << 6)
2092 + (offset_8_bit << 8);
2098 uint16_t offset_4and9to6_bits =
2100 uint16_t offset_4_bit = offset_4and9to6_bits >> 4;
2101 uint16_t offset_9to6_bits = offset_4and9to6_bits & 0xf;
2103 return (offset_4_bit << 4) + (offset_5_bit << 5) + (offset_9to6_bits << 6);
2109 uint16_t offset_5to4and9to6_bits =
2111 uint16_t offset_5to4_biits = offset_5to4and9to6_bits >> 4;
2112 uint16_t offset_9to6_bits = offset_5to4and9to6_bits & 0xf;
2113 return (offset_5to4_biits << 4) + (offset_9to6_bits << 6);
2131 if ((instruction & 0x03) < 0x03) {
2172 " store", instruction);
2286 " store", instruction);
2315 "The code points with rd = x0 are reserved for C.LWSP");
2325 "The code points with rd = x0 are reserved for C.LDSP");
2331 "have the \"F\" extension");
2342 "The code points with rd = x0 are reserved for C.LQSP");
2348 "have the \"D\" extension");
2363 "have the \"F\" extension");
2374 "have the \"D\" extension");
2389 "have the \"F\" extension");
2400 "have the \"D\" extension");
2415 "have the \"F\" extension");
2426 "have the \"D\" extension");
2435 " store", instruction);
2466 if (wp->unique_id == r->trigger_hit) {
2467 *hit_watchpoint = wp;
2475 const uint8_t
length = 4;
2488 for (
int i = 0; i <
length; i++) {
2490 instruction += (
buffer[i] << 8 * i);
2505 mem_addr += memoffset;
2518 if (mem_addr >= wp->
address &&
2520 *hit_watchpoint = wp;
2523 is_load ?
"Load from" :
"Store to", mem_addr,
2525 "read" : (wp->
rw ==
WPT_WRITE ?
"write" :
"access")),
2543 bool handle_breakpoints)
2559 handle_breakpoints ?
"true" :
"false");
2560 if (!r->get_hart_state)
2571 handle_breakpoints,
true );
2585 uint32_t dtmcontrol;
2596 info->dtm_version = dtm_version;
2609 if (
info->dtm_version != dtm_version) {
2633 if (!r->get_hart_state)
2651 if (bp->type ==
BKPT_HARD && bp->is_set && bp->address == dpc) {
2655 "can't derive debug reason for context-aware breakpoint: "
2657 ", asid = %" PRIx32
", linked = %d",
2658 bp->unique_id, bp->address, bp->asid, bp->linked_brp);
2672 r->trigger_hit = -1;
2673 r->need_single_step =
false;
2674 switch (halt_reason) {
2691 "Active hit bit is detected, trying to find trigger owner.");
2693 if (bp->unique_id == r->trigger_hit) {
2696 "Breakpoint with unique_id = %" PRIu32
" owns the trigger.",
2704 if (wp->unique_id == r->trigger_hit) {
2707 "Watchpoint with unique_id = %" PRIu32
" owns the trigger.",
2714 "No trigger hit found, deriving debug reason without it.");
2787 "the target is not halted!");
2802 if (!r->get_hart_state) {
2825 if (!r->get_hart_state) {
2902 memset(wp_is_set,
false, r->trigger_count);
2908 wp_is_set[i] ?
"true" :
"false");
2928 wp_is_set[i] ?
"needs " :
"does not need");
2952 if (handle_breakpoints) {
2963 && r->need_single_step)) {
2970 if (r->get_hart_state) {
2991 if (!r->get_hart_state) {
3012 "BUG: registers should have been flushed by this point.");
3030 bool handle_breakpoints,
3031 bool debug_execution,
3049 list_add(&single_target_entry.
lh, &single_target_list);
3050 targets = &single_target_list;
3055 current ?
"true" :
"false",
3057 handle_breakpoints ?
"true" :
"false",
3058 debug_execution ?
"true" :
"false");
3100 debug_execution,
false);
3119 assert(
false &&
"Unknown privilege mode");
3140 bool halted_in_m = dcsr_prv ==
PRV_M;
3179 }
else if (prv ==
PRV_U) {
3183 "which is a hardware bug", prv, mprv ?
"mstatus.MPP" :
"dcsr.prv");
3282 info->name, ppn,
virtual);
3285 assert(xlen >=
info->va_bits);
3288 if (masked_msbs != 0 && masked_msbs !=
mask) {
3290 "for %s mode.",
virtual,
info->name);
3296 int i =
info->level - 1;
3298 uint64_t vpn =
virtual >>
info->vpn_shift[i];
3299 vpn &=
info->vpn_mask[i];
3310 assert(
info->pte_shift <= 3);
3317 .count = (1 <<
info->pte_shift) / 4,
3319 int retval = r->access_memory(
target, args);
3323 if (
info->pte_shift == 2)
3333 "; mode=%s; i=%d", pte_address, pte,
info->name, i);
3355 while (i < info->level) {
3356 ppn = pte >>
info->pte_ppn_shift[i];
3357 ppn &=
info->pte_ppn_mask[i];
3359 info->pa_ppn_shift[i]);
3360 *physical |= (ppn <<
info->pa_ppn_shift[i]);
3364 info->name,
virtual, *physical);
3390 switch (vsatp_mode) {
3410 "vsatp mode %d is not supported. (vsatp: 0x%" PRIx64
")",
3417 switch (hgatp_mode) {
3437 "hgatp mode %d is not supported. (hgatp: 0x%" PRIx64
")",
3457 virtual, &guest_physical) !=
ERROR_OK)
3460 guest_physical =
virtual;
3470 guest_physical, physical) !=
ERROR_OK)
3473 *physical = guest_physical;
3483 *physical =
virtual;
3493 bool enabled =
false;
3497 *physical =
virtual;
3514 switch (satp_mode) {
3529 " (satp: 0x%" PRIx64
")", satp_value);
3533 " (satp: 0x%" PRIx64
")", satp_value);
3544 uint32_t
size, uint32_t
count,
bool is_write)
3549 if (is_misaligned && crosses_page_boundary) {
3551 " would access an element across page boundary. This is not supported.",
3570 return r->access_memory(
target, args);
3586 return r->access_memory(
target, args);
3594 if (args.
count == 0) {
3596 is_write ?
"write to" :
"read from", args.
address);
3614 "hardware: OpenOCD does not set mstatus.MPV yet. "
3615 "Use 'riscv virt2phys_mode sw'.");
3623 bool mmu_enabled =
false;
3636 uint32_t current_count = 0;
3638 while (current_count < args.
count) {
3649 uint32_t chunk_count =
MIN(args.
count - current_count,
3654 current_access.
address = physical_addr;
3655 current_access.
count = chunk_count;
3665 current_count += chunk_count;
3666 current_address += chunk_count * args.
size;
3703 return "riscv:rv32";
3705 return "riscv:rv64";
3712 struct reg **reg_list[],
int *reg_list_size,
3722 switch (reg_class) {
3724 *reg_list_size = 33;
3734 *reg_list = calloc(*reg_list_size,
sizeof(
struct reg *));
3738 for (
int i = 0; i < *reg_list_size; i++) {
3754 struct reg **reg_list[],
int *reg_list_size,
3762 struct reg **reg_list[],
int *reg_list_size,
3777 semihosting_active ?
" Semihosting is active." :
"");
3783 struct mem_param *mem_params,
int num_reg_params,
3785 target_addr_t exit_point,
unsigned int timeout_ms,
void *arch_info)
3795 for (
int i = 0; i < num_mem_params; i++) {
3801 " size=0x%" PRIx32, mem_params[i].
address, mem_params[i].
size);
3814 uint64_t saved_regs[32];
3815 for (
int i = 0; i < num_reg_params; i++) {
3823 if (r->
size != reg_params[i].
size) {
3825 reg_params[i].reg_name, r->
size, reg_params[i].
size);
3858 if (now -
start > timeout_ms) {
3874 for (
unsigned int i = 0; i <
ARRAY_SIZE(regnums); i++) {
3897 if (exit_point && final_pc != exit_point) {
3908 uint8_t buf[8] = { 0 };
3913 for (
int i = 0; i < num_reg_params; i++) {
3933 for (
int i = 0; i < num_mem_params; i++) {
3937 mem_params[i].
value);
3960 static const uint8_t riscv32_crc_code[] = {
3961 #include "../../../contrib/loaders/checksum/riscv32_crc.inc"
3963 static const uint8_t riscv64_crc_code[] = {
3964 #include "../../../contrib/loaders/checksum/riscv64_crc.inc"
3967 static const uint8_t *crc_code;
3970 unsigned int crc_code_size;
3972 crc_code = riscv32_crc_code;
3973 crc_code_size =
sizeof(riscv32_crc_code);
3975 crc_code = riscv64_crc_code;
3976 crc_code_size =
sizeof(riscv64_crc_code);
3979 if (
count < crc_code_size * 4) {
4003 crc_algorithm->
address, retval);
4014 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
4100 previous_target_state);
4126 if (r->handle_became_halted &&
4127 r->handle_became_halted(
target, previous_riscv_state) !=
ERROR_OK)
4136 r->halted_needs_event_callback =
true;
4150 if (r->handle_became_running &&
4151 r->handle_became_running(
target, previous_riscv_state) !=
ERROR_OK)
4159 if (r->handle_became_unavailable &&
4160 r->handle_became_unavailable(
target, previous_riscv_state) !=
ERROR_OK)
4178 if (!r->sample_buf.buf || !r->sample_config.enabled)
4186 if (r->sample_memory) {
4187 result = r->sample_memory(
target, &r->sample_buf, &r->sample_config,
4195 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
4196 if (r->sample_config.bucket[i].enabled &&
4197 r->sample_buf.used + 1 + r->sample_config.bucket[i].size_bytes < r->sample_buf.size) {
4199 r->sample_buf.buf[r->sample_buf.used] = i;
4201 r->sample_config.bucket[i].address,
4202 r->sample_config.bucket[i].size_bytes, 1,
4203 r->sample_buf.buf + r->sample_buf.used + 1);
4205 r->sample_buf.used += 1 + r->sample_config.bucket[i].size_bytes;
4216 r->sample_config.enabled =
false;
4241 list_add(&single_target_entry.
lh, &single_target_list);
4242 targets = &single_target_list;
4245 unsigned int should_remain_halted = 0;
4246 unsigned int should_resume = 0;
4248 unsigned int running = 0;
4249 unsigned int cause_groups = 0;
4257 info->halted_needs_event_callback =
false;
4266 switch (next_action) {
4275 should_remain_halted++;
4284 should_remain_halted, should_resume);
4285 if (should_remain_halted && should_resume) {
4287 should_remain_halted, should_resume);
4289 if (should_remain_halted) {
4291 should_remain_halted);
4293 }
else if (should_resume) {
4296 }
else if (
halted && running) {
4335 if (
halted == cause_groups) {
4360 if (
info->halted_needs_event_callback) {
4362 info->halted_needs_event_callback =
false;
4404 if (handle_breakpoints) {
4418 bool *wps_to_enable = calloc(r->trigger_count,
sizeof(*wps_to_enable));
4419 if (!wps_to_enable) {
4426 "watchpoints before single-step.");
4427 free(wps_to_enable);
4431 bool success =
true;
4454 "BUG: registers should have been flushed by this point.");
4469 "after single-step.");
4472 free(wps_to_enable);
4481 if (handle_callbacks)
4486 if (handle_callbacks)
4519 LOG_WARNING(
"The command 'riscv set_reset_timeout_sec' is deprecated! Please, use 'riscv set_command_timeout_sec'.");
4539 for (
unsigned int i = 0; i < r->num_enabled_mem_access_methods; i++) {
4543 switch (r->mem_access_methods[i]) {
4564 unsigned int progbuf_cnt = 0;
4565 unsigned int sysbus_cnt = 0;
4566 unsigned int abstract_cnt = 0;
4569 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4570 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0) {
4572 }
else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0) {
4574 }
else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0) {
4578 "must be one of: 'progbuf', 'sysbus' or 'abstract'",
CMD_ARGV[i]);
4582 if (progbuf_cnt > 1 || sysbus_cnt > 1 || abstract_cnt > 1) {
4588 r->num_enabled_mem_access_methods =
CMD_ARGC;
4589 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4590 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0)
4592 else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0)
4594 else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0)
4600 r->mem_access_warn[i] =
true;
4607 LOG_WARNING(
"DEPRECATED! use 'mem_access' not 'set_mem_access'");
4619 while (isspace((
unsigned char)reg_address_str[0]))
4622 bool is_hex_address = strncmp(reg_address_str,
"0x", 2) == 0 ||
4623 strncmp(reg_address_str,
"0X", 2) == 0;
4625 unsigned int scanned_chars;
4626 if (is_hex_address) {
4627 reg_address_str += 2;
4628 if (sscanf(reg_address_str,
"%x%n", reg_addr, &scanned_chars) != 1)
4637 if (reg_address_str[0] ==
'0' && strlen(reg_address_str) > 1)
4639 if (sscanf(reg_address_str,
"%u%n", reg_addr, &scanned_chars) != 1)
4642 return scanned_chars == strlen(reg_address_str);
4646 const char *
reg_type,
unsigned int max_val,
char **
const name_buffer)
4650 for (
char *arg = strtok(args,
","); arg; arg = strtok(
NULL,
",")) {
4651 unsigned int low = 0;
4652 unsigned int high = 0;
4655 char *dash = strchr(arg,
'-');
4656 char *equals = strchr(arg,
'=');
4658 if (!dash && !equals) {
4661 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
4664 }
else if (dash && !equals) {
4668 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4672 const char *high_num_in = dash + 1;
4674 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4679 LOG_ERROR(
"Incorrect range encountered [%u, %u].",
low, high);
4682 }
else if (!dash && equals) {
4686 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4691 const char *
const reg_name_in = equals + 1;
4692 const size_t reg_type_len = strlen(
reg_type);
4694 *name_buffer = calloc(1, strlen(reg_name_in) + reg_type_len + 2);
4695 name = *name_buffer;
4701 name[reg_type_len] =
'_';
4703 unsigned int scanned_chars;
4705 if (sscanf(reg_name_in,
"%[_a-zA-Z0-9]%n", scan_dst, &scanned_chars) != 1 ||
4706 scanned_chars != strlen(reg_name_in)) {
4707 LOG_ERROR(
"Invalid characters in register name '%s'.", reg_name_in);
4711 LOG_ERROR(
"Invalid argument '%s'.", arg);
4717 if (high > max_val) {
4718 LOG_ERROR(
"Cannot expose %s register number 0x%x, maximum allowed value is 0x%x.",
4726 if (entry->
low <= high && low <= entry->high) {
4729 "Register %u has already been exposed previously",
reg_type,
low);
4731 LOG_WARNING(
"Overlapping register ranges - Register range starting from %u overlaps "
4732 "with already exposed register/range at %u.",
low, entry->
low);
4751 *name_buffer =
NULL;
4759 const char *
reg_type,
unsigned int max_val)
4761 char *args = strdup(tcl_arg);
4766 char *name_buffer =
NULL;
4782 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4800 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4818 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4829 unsigned int index = 0;
4847 if (r->authdata_read) {
4862 unsigned int index = 0;
4877 if (!r->authdata_write) {
4882 return r->authdata_write(
target, value, index);
4889 if (!r || !r->get_dmi_address)
4891 return r->get_dmi_address(
target, dm_address);
4923 if (!r->dmi_write) {
4927 const int result = r->dmi_write(
target, dmi_address, value);
4935 const bool progbuf_touched =
4938 const bool dm_deactivated =
4941 if (progbuf_touched || dm_deactivated) {
4942 if (r->invalidate_cached_progbuf) {
4950 r->invalidate_cached_progbuf(
target);
4953 "invalidate_cached_progbuf() is not implemented.");
4964 uint32_t dmi_address;
4980 uint32_t dmi_address, value;
4993 uint32_t dm_address;
5010 uint32_t dm_address, value;
5031 r->reset_delays_wait = wait;
5043 if (!strcmp(
CMD_ARGV[0],
"idcode"))
5045 else if (!strcmp(
CMD_ARGV[0],
"dtmcs"))
5047 else if (!strcmp(
CMD_ARGV[0],
"dmi"))
5060 if (!strcmp(
CMD_ARGV[0],
"normal")) {
5062 }
else if (!strcmp(
CMD_ARGV[0],
"reversed")) {
5074 uint8_t irwidth = 0;
5077 if (CMD_ARGC < 1 || CMD_ARGC > 2)
5092 LOG_INFO(
"Nested Tap based Bscan Tunnel Selected");
5094 LOG_INFO(
"Simple Register based Bscan Tunnel Selected");
5096 LOG_INFO(
"Invalid Tunnel type selected ! : selecting default Nested Tap Type");
5113 LOG_INFO(
"Bscan tunnel IR 0x%x selected", ir_id);
5124 static const struct jim_nvp nvp_maskisr_modes[] = {
5127 { .name =
NULL, .value = -1 },
5164 const char *mode_str;
5176 assert(0 &&
"Unexpected execution mode");
5177 mode_str =
"unexpected";
5182 LOG_WARNING(
"DEPRECATED! use '%s cget -ebreak' not '%s'",
5185 config->dcsr_ebreak_fields[
mode] ?
"on" :
"off");
5193 config->dcsr_ebreak_fields[
mode] = ebreak_ctl;
5257 "doesn't support setting more than one at a time.");
5268 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5271 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5273 else if (!strcmp(
CMD_ARGV[i],
"nmi"))
5275 else if (!strcmp(
CMD_ARGV[i],
"m"))
5277 else if (!strcmp(
CMD_ARGV[i],
"s"))
5279 else if (!strcmp(
CMD_ARGV[i],
"u"))
5284 if (!nmi && interrupts == 0) {
5285 LOG_ERROR(
"Doesn't make sense to set itrigger with "
5286 "mie_bits=0 and without nmi.");
5288 }
else if (!vs && !vu && !m && !s && !u) {
5289 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5290 "least one of vs, vu, m, s, or u.");
5298 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5299 return riscv_clear_trigger(
CMD, ITRIGGER_UNIQUE_ID,
"itrigger");
5302 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5327 "doesn't support setting more than one at a time.");
5335 bool pending =
false;
5336 unsigned int count = 0;
5338 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5341 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5343 else if (!strcmp(
CMD_ARGV[i],
"pending"))
5345 else if (!strcmp(
CMD_ARGV[i],
"m"))
5347 else if (!strcmp(
CMD_ARGV[i],
"s"))
5349 else if (!strcmp(
CMD_ARGV[i],
"u"))
5355 LOG_ERROR(
"Doesn't make sense to set icount trigger with "
5358 }
else if (!vs && !vu && !m && !s && !u) {
5359 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5360 "least one of vs, vu, m, s, or u.");
5368 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5369 return riscv_clear_trigger(
CMD, ICOUNT_UNIQUE_ID,
"icount trigger");
5372 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5397 "doesn't support setting more than one at a time.");
5407 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5410 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5412 else if (!strcmp(
CMD_ARGV[i],
"m"))
5414 else if (!strcmp(
CMD_ARGV[i],
"s"))
5416 else if (!strcmp(
CMD_ARGV[i],
"u"))
5421 if (exception_codes == 0) {
5422 LOG_ERROR(
"Doesn't make sense to set etrigger with "
5423 "exception_codes=0.");
5425 }
else if (!vs && !vu && !m && !s && !u) {
5426 LOG_ERROR(
"Doesn't make sense to set etrigger without at "
5427 "least one of vs, vu, m, s, or u.");
5435 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5436 return riscv_clear_trigger(
CMD, ETRIGGER_UNIQUE_ID,
"etrigger");
5439 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5455 if (CMD_ARGC < 2 || CMD_ARGC > 3)
5482 int result = r->access_memory(
target, args);
5496 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
5497 if (r->sample_config.bucket[i].enabled) {
5499 r->sample_config.bucket[i].address,
5500 r->sample_config.bucket[i].size_bytes);
5513 if (bucket >
ARRAY_SIZE(r->sample_config.bucket)) {
5518 if (!strcmp(
CMD_ARGV[1],
"clear")) {
5519 r->sample_config.bucket[bucket].enabled =
false;
5525 if (r->sample_config.bucket[bucket].size_bytes != 4 &&
5526 r->sample_config.bucket[bucket].size_bytes != 8) {
5531 r->sample_config.bucket[bucket].size_bytes = 4;
5534 r->sample_config.bucket[bucket].enabled =
true;
5537 if (!r->sample_buf.buf) {
5538 r->sample_buf.size = 1024 * 1024;
5539 r->sample_buf.buf = malloc(r->sample_buf.size);
5543 r->sample_buf.used = 0;
5545 r->sample_config.enabled =
true;
5558 bool base64 =
false;
5560 if (!strcmp(
CMD_ARGV[0],
"base64")) {
5571 r->sample_buf.used,
NULL);
5581 while (i < r->sample_buf.used) {
5582 uint8_t
command = r->sample_buf.buf[i++];
5584 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5588 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5593 r->sample_config.bucket[
command].address);
5594 if (r->sample_config.bucket[
command].size_bytes == 4) {
5595 uint32_t value =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5598 }
else if (r->sample_config.bucket[
command].size_bytes == 8) {
5599 uint64_t value =
buf_get_u64(r->sample_buf.buf + i, 0, 64);
5604 r->sample_config.bucket[
command].size_bytes);
5619 r->sample_buf.used = 0;
5624 const char *key,
unsigned int value,
bool is_available)
5627 snprintf(full_key,
sizeof(full_key),
"%s.%s", section, key);
5651 const bool trigger_count_available =
5653 riscv_print_info_line_if_available(
CMD,
"hart",
"trigger_count",
5654 r->trigger_count, trigger_count_available);
5663 if (CMD_ARGC < 1 || CMD_ARGC > 16)
5676 "only supported on v0.13 or v1.0 targets.");
5682 "program buffer, target not halted.");
5695 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
5723 bool enable_for_wp =
true;
5726 enable_for_wp =
true;
5727 else if (!strcmp(
CMD_ARGV[1],
"none"))
5728 enable_for_wp =
false;
5733 r->wp_allow_equality_match_trigger = enable_for_wp;
5734 r->wp_allow_napot_trigger = enable_for_wp;
5735 r->wp_allow_ge_lt_trigger = enable_for_wp;
5736 }
else if (!strcmp(
CMD_ARGV[0],
"eq")) {
5737 r->wp_allow_equality_match_trigger = enable_for_wp;
5738 }
else if (!strcmp(
CMD_ARGV[0],
"napot")) {
5739 r->wp_allow_napot_trigger = enable_for_wp;
5740 }
else if (!strcmp(
CMD_ARGV[0],
"ge_lt")) {
5741 r->wp_allow_ge_lt_trigger = enable_for_wp;
5750 "Equality match trigger: for wp (%s)\n"
5751 "NAPOT trigger: for wp (%s)\n"
5752 "ge-lt chained triggers: for wp (%s)",
5753 r->wp_allow_equality_match_trigger ?
"enabled" :
"disabled",
5754 r->wp_allow_napot_trigger ?
"enabled" :
"disabled",
5755 r->wp_allow_ge_lt_trigger ?
"enabled" :
"disabled");
5765 const char *separator =
"";
5766 for (
riscv_reg_t t = 0; t < r->trigger_count; ++t) {
5767 if (r->reserved_triggers[t]) {
5796 if (r->trigger_count == 0) {
5800 if (t >= r->trigger_count) {
5802 " does not exist. There are only %u triggers"
5803 " on the target (with indexes 0 .. %u).",
5804 t, r->trigger_count, r->trigger_count - 1);
5807 if (r->trigger_unique_id[t] != -1) {
5809 " is already in use and can not be reserved.", t);
5848 .
name =
"dump_sample_buf",
5849 .handler = handle_dump_sample_buf_command,
5851 .usage =
"[base64]",
5852 .help =
"Print the contents of the sample buffer, and clear the buffer."
5856 .handler = handle_info,
5859 .help =
"Displays some information OpenOCD detected about the target."
5862 .name =
"memory_sample",
5863 .handler = handle_memory_sample_command,
5865 .usage =
"bucket address|clear [size=4]",
5866 .help =
"Causes OpenOCD to frequently read size bytes at the given address."
5869 .name =
"repeat_read",
5870 .handler = handle_repeat_read,
5872 .usage =
"count address [size=4]",
5873 .help =
"Repeatedly read the value at the given physical address."
5876 .name =
"set_command_timeout_sec",
5877 .handler = riscv_set_command_timeout_sec,
5880 .help =
"Set the wall-clock timeout (in seconds) for individual commands"
5883 .name =
"set_reset_timeout_sec",
5884 .handler = riscv_set_reset_timeout_sec,
5887 .help =
"DEPRECATED. Use 'riscv set_command_timeout_sec' instead."
5890 .name =
"set_mem_access",
5891 .handler = riscv_set_mem_access,
5893 .usage =
"method1 [method2] [method3]",
5894 .help =
"DEPRECATED: Use 'riscv mem_access' instead."
5897 .name =
"mem_access",
5898 .handler = riscv_mem_access,
5900 .usage =
"[method1 [method2 [method3]]]",
5901 .help =
"Configure which memory access methods shall be used and in which order "
5902 "of priority. Method can be one of: 'progbuf', 'sysbus' or 'abstract'."
5905 .name =
"expose_csrs",
5906 .handler = riscv_set_expose_csrs,
5908 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5909 .help =
"Configure a list of inclusive ranges for CSRs to expose in "
5910 "addition to the standard ones. This must be executed before "
5914 .name =
"expose_custom",
5915 .handler = riscv_set_expose_custom,
5917 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5918 .help =
"Configure a list of inclusive ranges for custom registers to "
5919 "expose. custom0 is accessed as abstract register number 0xc000, "
5920 "etc. This must be executed before `init`."
5923 .name =
"hide_csrs",
5924 .handler = riscv_hide_csrs,
5926 .usage =
"{n0|n-m0}[,n1|n-m1]......",
5927 .help =
"Configure a list of inclusive ranges for CSRs to hide from gdb. "
5928 "Hidden registers are still available, but are not listed in "
5929 "gdb target description and `reg` command output. "
5930 "This must be executed before `init`."
5933 .name =
"authdata_read",
5934 .handler = riscv_authdata_read,
5937 .help =
"Return the 32-bit value read from authdata or authdata0 "
5938 "(index=0), or authdata1 (index=1)."
5941 .name =
"authdata_write",
5942 .handler = riscv_authdata_write,
5944 .usage =
"[index] value",
5945 .help =
"Write the 32-bit value to authdata or authdata0 (index=0), "
5946 "or authdata1 (index=1)."
5950 .handler = handle_riscv_dmi_read,
5953 .help =
"Read and return 32-bit value from the given address on the "
5957 .name =
"dmi_write",
5958 .handler = handle_riscv_dmi_write,
5960 .usage =
"address value",
5961 .help =
"Write a 32-bit value to the given address on the RISC-V DMI bus."
5965 .handler = handle_riscv_dm_read,
5967 .usage =
"reg_address",
5968 .help =
"Read and return 32-bit value from a debug module's register "
5973 .handler = handle_riscv_dm_write,
5975 .usage =
"reg_address value",
5976 .help =
"Write a 32-bit value to the debug module's register at "
5980 .name =
"reset_delays",
5981 .handler = riscv_reset_delays,
5984 .help =
"OpenOCD learns how many Run-Test/Idle cycles are required "
5985 "between scans to avoid encountering the target being busy. This "
5986 "command resets those learned values after `wait` scans. It's only "
5987 "useful for testing OpenOCD itself."
5990 .name =
"resume_order",
5991 .handler = riscv_resume_order,
5993 .usage =
"normal|reversed",
5994 .help =
"Choose the order that harts are resumed in when `hasel` is not "
5995 "supported. Normal order is from lowest hart index to highest. "
5996 "Reversed order is from highest hart index to lowest."
6000 .handler = riscv_set_ir,
6002 .usage =
"idcode|dtmcs|dmi value",
6003 .help =
"Set IR value for specified JTAG register."
6006 .name =
"use_bscan_tunnel",
6007 .handler = riscv_use_bscan_tunnel,
6009 .usage =
"value [type]",
6010 .help =
"Enable or disable use of a BSCAN tunnel to reach DM."
6013 .name =
"set_bscan_tunnel_ir",
6014 .handler = riscv_set_bscan_tunnel_ir,
6017 .help =
"Specify the JTAG TAP IR used to access the bscan tunnel. "
6018 "By default it is 0x23 << (ir_length - 6), which map some "
6019 "Xilinx FPGA (IR USER4)"
6022 .name =
"set_maskisr",
6023 .handler = riscv_set_maskisr,
6025 .help =
"mask riscv interrupts",
6026 .usage =
"['off'|'steponly']",
6029 .name =
"set_ebreakm",
6030 .handler = riscv_set_ebreakm,
6032 .usage =
"[on|off]",
6033 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
6034 "'<target_name> cget -ebreak'"
6037 .name =
"set_ebreaks",
6038 .handler = riscv_set_ebreaks,
6040 .usage =
"[on|off]",
6041 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
6042 "'<target_name> cget -ebreak'"
6045 .name =
"set_ebreaku",
6046 .handler = riscv_set_ebreaku,
6048 .usage =
"[on|off]",
6049 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
6050 "'<target_name> cget -ebreak'"
6054 .handler = riscv_etrigger,
6056 .usage =
"set [vs] [vu] [m] [s] [u] <exception_codes>|clear",
6057 .help =
"Set or clear a single exception trigger."
6061 .handler = riscv_icount,
6063 .usage =
"set [vs] [vu] [m] [s] [u] [pending] <count>|clear",
6064 .help =
"Set or clear a single instruction count trigger."
6068 .handler = riscv_itrigger,
6070 .usage =
"set [vs] [vu] [nmi] [m] [s] [u] <mie_bits>|clear",
6071 .help =
"Set or clear a single interrupt trigger."
6074 .name =
"exec_progbuf",
6075 .handler = riscv_exec_progbuf,
6077 .usage =
"instr1 [instr2 [... instr16]]",
6078 .help =
"Execute a sequence of 32-bit instructions using the program buffer. "
6079 "The final ebreak instruction is added automatically, if needed."
6082 .name =
"set_enable_trigger_feature",
6083 .handler = riscv_set_enable_trigger_feature,
6085 .usage =
"[('eq'|'napot'|'ge_lt'|'all') ('wp'|'none')]",
6086 .help =
"Control whether OpenOCD is allowed to use certain RISC-V trigger features for watchpoints."
6089 .name =
"reserve_trigger",
6090 .handler = handle_reserve_trigger,
6093 .usage =
"[index ('on'|'off')]",
6094 .help =
"Controls which RISC-V triggers shall not be touched by OpenOCD.",
6097 .name =
"virt2phys_mode",
6098 .handler = handle_riscv_virt2phys_mode,
6100 .usage =
"['sw'|'hw'|'off']",
6101 .help =
"Configure the virtual address translation mode: "
6102 "sw - translate vaddr to paddr by manually traversing page tables, "
6103 "hw - translate vaddr to paddr by hardware, "
6104 "off - no address translation."
6107 .name =
"autofence",
6108 .handler = riscv_set_autofence,
6110 .usage =
"[on|off]",
6111 .help =
"When on (default), OpenOCD will automatically execute fence instructions in some situations. "
6112 "When off, users need to take care of memory coherency themselves, for example by using "
6113 "`riscv exec_progbuf` to execute fence or CMO instructions."
6139 .help =
"RISC-V Command Group",
6146 .help =
"ARM Command Group",
6162 return r->data_bits(
target);
6176 *insn_set =
"riscv32";
6180 *insn_set =
"riscv64";
6248 memset(r, 0,
sizeof(*r));
6308 *old_mstatus = current_mstatus;
6323 LOG_TARGET_WARNING(
target,
"OpenOCD might have affected the program when it restored the interrupt bits after single-step.");
6324 LOG_TARGET_WARNING(
target,
"Hint: Use 'riscv set_maskisr off' to prevent OpenOCD from touching mstatus during single-step.");
6351 if (letter >=
'a' && letter <=
'z')
6353 else if (letter >=
'A' && letter <=
'Z')
6358 return misa &
BIT(num);
6393 assert(r->get_hart_state);
6404 return r->halt_reason(
target);
6410 return r->get_progbufsize(
target);
6416 return r->write_progbuf(
target, index, insn);
6422 return r->read_progbuf(
target, index);
6428 return r->execute_progbuf(
target, cmderr);
6434 r->fill_dmi_write(
target, buf, a, d);
6440 r->fill_dmi_read(
target, buf, a);
6446 r->fill_dm_nop(
target, buf);
6452 return r->get_dmi_address_bits(
target);
6466 if (tselect_rb != index)
6479 assert(trigger_tinfo);
6484 if (tinfo == 0 || tinfo & 0x1)
6486 *trigger_tinfo = tinfo;
6492 *trigger_tinfo = 1 <<
type;
6498 bool dmode_is_set =
false;
6503 dmode_is_set =
true;
6538 if (r->triggers_enumerated)
6552 "Assuming that triggers are not implemented.");
6553 r->triggers_enumerated =
true;
6554 r->trigger_count = 0;
6555 free(r->reserved_triggers);
6556 r->reserved_triggers =
NULL;
6574 for (; t <
ARRAY_SIZE(r->trigger_tinfo); ++t) {
6592 t, r->trigger_tinfo[t]);
6610 r->triggers_enumerated =
true;
6611 r->trigger_count = t;
6613 free(r->reserved_triggers);
6614 r->reserved_triggers = calloc(t,
sizeof(*r->reserved_triggers));
void init_reg_param(struct reg_param *param, const char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
unsigned char * base64_encode(const unsigned char *src, size_t len, size_t *out_len)
base64_encode - Base64 encode @src: Data to be encoded @len: Length of the data to be encoded @out_le...
void * buf_cpy(const void *from, void *_to, unsigned int size)
Copies size bits out of from and into to.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
static void buf_set_u64(uint8_t *_buffer, unsigned int first, unsigned int num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
struct breakpoint * breakpoint_find(struct target *target, target_addr_t address)
static void watchpoint_set(struct watchpoint *watchpoint, unsigned int number)
#define WATCHPOINT_IGNORE_DATA_VALUE_MASK
static void breakpoint_hw_set(struct breakpoint *breakpoint, unsigned int hw_number)
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define COMMAND_PARSE_ADDRESS(in, out)
#define COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define ERROR_COMMAND_ARGUMENT_OVERFLOW
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
static int halted(struct target *target, const char *label)
#define CSR_MCONTROL_CHAIN
#define CSR_MCONTROL6_CHAIN
#define CSR_MCONTROL6_MATCH_NAPOT
#define CSR_ICOUNT_ACTION_DEBUG_MODE
#define CSR_MCONTROL6_HIT0_AFTER
#define CSR_MCONTROL6_SIZE_ANY
#define CSR_ITRIGGER_HIT(XLEN)
#define CSR_MCONTROL_LOAD
#define CSR_ITRIGGER_ACTION_DEBUG_MODE
#define CSR_ETRIGGER_ACTION
#define CSR_DCSR_CAUSE_GROUP
#define CSR_MCONTROL6_CHAIN_DISABLED
#define CSR_MCONTROL6_TYPE(XLEN)
#define CSR_MCONTROL6_LOAD
#define CSR_TDATA1_TYPE_ICOUNT
#define CSR_MCONTROL6_HIT0_FALSE
#define CSR_ITRIGGER_ACTION
#define CSR_MCONTROL_ACTION_DEBUG_MODE
#define CSR_MCONTROL6_ACTION
#define CSR_MCONTROL6_MATCH_GE
#define CSR_ETRIGGER_HIT(XLEN)
#define CSR_ETRIGGER_ACTION_DEBUG_MODE
#define CSR_ICOUNT_ACTION
#define CSR_MCONTROL_STORE
#define CSR_MCONTROL_CHAIN_DISABLED
#define CSR_MCONTROL_CHAIN_ENABLED
#define CSR_MCONTROL6_EXECUTE
#define CSR_MCONTROL_MATCH_LT
#define CSR_MCONTROL_MATCH_GE
#define CSR_ICOUNT_PENDING
#define CSR_ITRIGGER_DMODE(XLEN)
#define CSR_TDATA1_TYPE_MCONTROL6
#define CSR_MCONTROL6_STORE
#define CSR_MCONTROL_TYPE(XLEN)
#define CSR_MCONTROL_EXECUTE
#define CSR_ETRIGGER_DMODE(XLEN)
#define CSR_MCONTROL_ACTION
#define CSR_MCONTROL_SIZELO_ANY
#define CSR_TINFO_VERSION_0
#define CSR_MCONTROL_MASKMAX(XLEN)
#define CSR_MCONTROL6_MATCH_LT
#define CSR_TDATA1_TYPE_ETRIGGER
#define CSR_MCONTROL6_MATCH_EQUAL
#define DM_DMCONTROL_DMACTIVE
#define CSR_ETRIGGER_TYPE(XLEN)
#define CSR_TINFO_VERSION_1
#define CSR_MCONTROL6_MATCH
#define CSR_MCONTROL_DMODE(XLEN)
#define DTM_DTMCS_VERSION_0_11
#define CSR_MCONTROL_SIZELO
#define CSR_MCONTROL6_DMODE(XLEN)
#define CSR_MCONTROL_MATCH_NAPOT
#define CSR_TDATA1_TYPE_MCONTROL
#define CSR_ICOUNT_TYPE(XLEN)
#define CSR_MCONTROL6_HIT1
#define CSR_TDATA1_TYPE_LEGACY
#define CSR_TINFO_VERSION
#define CSR_ICOUNT_DMODE(XLEN)
#define CSR_ITRIGGER_TYPE(XLEN)
#define DTM_DTMCS_VERSION_1_0
#define CSR_MCONTROL6_HIT0
#define CSR_MCONTROL6_SIZE
#define CSR_TDATA1_TYPE_ITRIGGER
#define CSR_MCONTROL_SIZEHI
#define CSR_MCONTROL_MATCH
#define CSR_TDATA1_TYPE(XLEN)
#define CSR_MCONTROL6_HIT0_BEFORE
#define CSR_MCONTROL6_CHAIN_ENABLED
#define CSR_MCONTROL6_HIT0_IMMEDIATELY_AFTER
#define CSR_MCONTROL_MATCH_EQUAL
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t size
Size of dw_spi_transaction::buffer.
uint32_t address
Starting address. Sector aligned.
#define INSN_FIELD_C_UIMM9SP_S
#define INSN_FIELD_C_UIMM9SPLO
#define INSN_FIELD_C_SREG1
#define INSN_FIELD_C_UIMM8LO
#define INSN_FIELD_C_UIMM10SP_S
#define INSN_FIELD_C_UIMM7HI
#define INSN_FIELD_C_UIMM7LO
#define INSN_FIELD_C_UIMM8HI
#define INSN_FIELD_C_UIMM8SPLO
#define HGATP_MODE_SV57X4
#define INSN_FIELD_C_UIMM9SPHI
#define INSN_FIELD_IMM12HI
#define HGATP_MODE_SV32X4
#define INSN_FIELD_C_UIMM9HI
#define HGATP_MODE_SV39X4
#define INSN_FIELD_C_UIMM8SPHI
#define INSN_FIELD_C_UIMM10SPLO
#define INSN_FIELD_C_UIMM10SPHI
#define HGATP_MODE_SV48X4
#define INSN_FIELD_C_UIMM8SP_S
#define INSN_FIELD_OPCODE
#define INSN_FIELD_C_UIMM9LO
#define INSN_FIELD_IMM12LO
#define INSN_FIELD_FUNCT3
static struct esp_usb_jtag * priv
static uint64_t set_field(uint64_t reg, uint64_t mask, uint64_t val)
static uint64_t field_value(uint64_t mask, uint64_t val)
static uint32_t get_field32(uint64_t reg, uint64_t mask)
static uint64_t get_field(uint64_t reg, uint64_t mask)
static uint16_t direction
struct jim_nvp * jim_nvp_name2value_simple(const struct jim_nvp *p, const char *name)
int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *nvp, struct jim_nvp **puthere)
Remove argv[0] as NVP.
void jim_getopt_nvp_unknown(struct jim_getopt_info *goi, const struct jim_nvp *nvptable, int hadprefix)
Create an appropriate error message for an NVP.
int jim_nvp_name2value_obj(Jim_Interp *interp, const struct jim_nvp *p, Jim_Obj *o, struct jim_nvp **result)
int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
Remove argv[0] from the list.
struct jim_nvp * jim_nvp_value2name_simple(const struct jim_nvp *p, int value)
static struct device_config config
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
const char * jtag_tap_name(const struct jtag_tap *tap)
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, enum tap_state state)
Generate a DR SCAN using the fields passed to the function.
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, enum tap_state state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
The JTAG interface can be implemented with a software or hardware fifo.
static void list_add(struct list_head *new, struct list_head *head)
#define OOCD_LIST_HEAD(name)
static void list_add_tail(struct list_head *new, struct list_head *head)
#define list_for_each_entry_safe(p, n, h, field)
#define list_for_each_entry(p, h, field)
static void list_del(struct list_head *entry)
static void INIT_LIST_HEAD(struct list_head *list)
static void list_move(struct list_head *list, struct list_head *head)
void alive_sleep(uint64_t ms)
#define LOG_TARGET_INFO(target, fmt_str,...)
#define LOG_USER(expr ...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define ERROR_NOT_IMPLEMENTED
#define LOG_WARNING(expr ...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(target, fmt_str,...)
#define LOG_TARGET_DEBUG_IO(target, fmt_str,...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static uint32_t ebreak(void) __attribute__((unused))
static uint32_t ebreak_c(void) __attribute__((unused))
int riscv_program_insert(struct riscv_program *p, riscv_insn_t i)
int riscv_program_init(struct riscv_program *p, struct target *target)
int riscv_program_exec(struct riscv_program *p, struct target *t)
Add ebreak and execute the program.
struct reg * register_get_by_name(struct reg_cache *first, const char *name, bool search_all)
struct target_type riscv011_target
struct target_type riscv013_target
static int riscv_reset_timeout_sec
static enum target_debug_reason derive_debug_reason_without_hitbit(const struct target *target, riscv_reg_t dpc)
static int check_if_trigger_exists(struct target *target, unsigned int index)
static int halt_finish(struct target *target)
COMMAND_HELPER(ebreakx_deprecation_helper, enum riscv_priv_mode mode)
static bool parse_csr_address(const char *reg_address_str, unsigned int *reg_addr)
static struct scan_field _bscan_tunnel_data_register_select_dmi[]
static const virt2phys_info_t sv57
static struct tdata1_cache * tdata1_cache_alloc(struct list_head *tdata1_cache_head, riscv_reg_t tdata1)
struct scan_field select_idcode
int riscv_extension_enabled(struct target *target, char letter, bool *is_enabled)
static int verify_loadstore(struct target *target, const riscv_insn_t instruction, bool *is_read)
static const virt2phys_info_t sv48x4
static int riscv_mmu_impl(struct target *target, enum riscv_priv_mode mode, bool *enabled)
static int set_debug_reason(struct target *target, enum riscv_halt_reason halt_reason)
Set OpenOCD's generic debug reason from the RISC-V halt reason.
static uint32_t get_opcode(const riscv_insn_t instruction)
static struct jim_nvp nvp_ebreak_config_opts[]
unsigned int riscv_xlen(const struct target *target)
static struct scan_field select_user4
static bscan_tunnel_type_t bscan_tunnel_type
static int riscv_halt_go_all_harts(struct target *target)
struct scan_field select_dbus
static const virt2phys_info_t sv57x4
static int riscv_step_rtos_hart(struct target *target)
void riscv_add_bscan_tunneled_scan(struct jtag_tap *tap, const struct scan_field *field, riscv_bscan_tunneled_scan_context_t *ctxt)
static int riscv_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
static int get_trigger_types(struct target *target, unsigned int *trigger_tinfo, riscv_reg_t tdata1)
This function reads tinfo or tdata1, when reading tinfo fails, to determine trigger types supported b...
static int maybe_add_trigger_t2_t6_for_bp(struct target *target, struct trigger *trigger, struct match_triggers_tdata1_fields fields)
static int maybe_add_trigger_t2_t6_for_wp(struct target *target, struct trigger *trigger, struct match_triggers_tdata1_fields fields)
unsigned int riscv_get_dmi_address_bits(const struct target *target)
static int riscv_effective_privilege_mode(struct target *target, enum riscv_priv_mode *mode)
static int riscv_trigger_detect_hit_bits(struct target *target, int64_t *unique_id, bool *need_single_step)
Look at the trigger hit bits to find out which trigger is the reason we're halted.
static const virt2phys_info_t sv32x4
static uint16_t get_offset_csqsp(riscv_insn_t instruction)
static int get_loadstore_memoffset(struct target *target, const riscv_insn_t instruction, int16_t *memoffset)
static uint32_t bscan_tunnel_data_register_select_dmi_num_fields
bool riscv_supports_extension(const struct target *target, char letter)
static uint16_t get_offset_cswsp(riscv_insn_t instruction)
static int maybe_add_trigger_t2_t6(struct target *target, struct trigger *trigger, struct match_triggers_tdata1_fields fields)
static const struct command_registration riscv_command_handlers[]
static int riscv_command_timeout_sec_value
void select_dmi_via_bscan(struct jtag_tap *tap)
static bool misa_check_extension(riscv_reg_t misa, char letter)
int riscv_read_by_any_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Read one memory item using any memory access size that will work.
static int riscv_read_phys_memory(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer)
static int riscv_write_phys_memory(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, const uint8_t *buffer)
int riscv_halt(struct target *target)
static void create_wp_trigger_cache(struct target *target)
static int riscv_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
static void tdata2_cache_alloc(struct list_head *tdata2_cache_head, riscv_reg_t tdata2)
static int riscv_poll_hart(struct target *target, enum riscv_next_action *next_action)
static int add_trigger(struct target *target, struct trigger *trigger)
static uint16_t get_offset_cldsp(riscv_insn_t instruction)
static int remove_trigger(struct target *target, int unique_id)
static bool can_use_napot_match(struct trigger *trigger)
int riscv_write_by_any_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Write one memory item using any memory access size that will work.
static uint16_t get_offset_clqsp(riscv_insn_t instruction)
static void trigger_from_watchpoint(struct trigger *trigger, const struct watchpoint *watchpoint)
static int riscv_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution, bool single_hart)
unsigned int riscv_vlenb(const struct target *target)
int riscv_get_hart_state(struct target *target, enum riscv_hart_state *state)
static const virt2phys_info_t sv32
static int riscv_create_target(struct target *target)
static int riscv_init_target(struct command_context *cmd_ctx, struct target *target)
static struct jim_nvp nvp_config_opts[]
static int old_or_new_riscv_poll(struct target *target)
static int riscv_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
static int riscv_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
static struct jim_nvp nvp_on_off_opts[]
static void log_trigger_request_info(struct trigger_request_info trig_info)
static const riscv_reg_t mstatus_ie_mask
static int riscv_mmu(struct target *target, bool *enabled)
static int try_setup_chained_match_triggers(struct target *target, struct trigger *trigger, struct trigger_request_info t1, struct trigger_request_info t2)
static int jim_report_ebreak_config(const struct riscv_private_config *config, Jim_Interp *interp)
static int riscv_openocd_step_impl(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, int handle_callbacks)
static bool riscv_priv_mode_is_guest(enum riscv_priv_mode mode)
static void riscv_sample_buf_maybe_add_timestamp(struct target *target, bool before)
static int old_or_new_riscv_step_impl(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, int handle_callbacks)
static uint16_t get_offset_clwsp(riscv_insn_t instruction)
These functions are needed to extract individual bits (for offset) from the instruction.
static int riscv_virt2phys_v(struct target *target, target_addr_t virtual, target_addr_t *physical)
#define RISCV_EBREAK_MODE_INVALID
unsigned int riscv_progbuf_size(struct target *target)
static int parse_reg_ranges(struct list_head *ranges, const char *tcl_arg, const char *reg_type, unsigned int max_val)
static const virt2phys_info_t sv39x4
#define RISCV_TRIGGER_HIT_NOT_FOUND
static int riscv_address_translate(struct target *target, const virt2phys_info_t *info, target_addr_t ppn, const virt2phys_info_t *extra_info, target_addr_t extra_ppn, target_addr_t virtual, target_addr_t *physical)
struct tdata1_cache * tdata1_cache_search(struct list_head *tdata1_cache_head, riscv_reg_t find_tdata1)
static const virt2phys_info_t sv48
static int set_trigger(struct target *target, unsigned int idx, riscv_reg_t tdata1, riscv_reg_t tdata2)
static int ebreak_config_to_tcl_dict(const struct riscv_private_config *config, char *buffer)
Obtain dcsr.ebreak* configuration as a Tcl dictionary.
static int jim_configure_ebreak(struct riscv_private_config *config, struct jim_getopt_info *goi)
uint8_t bscan_tunnel_ir_width
static struct scan_field _bscan_tunnel_nested_tap_select_dmi[]
struct tdata2_cache * tdata2_cache_search(struct list_head *tdata2_cache_head, riscv_reg_t find_tdata2)
static enum mctrl6hitstatus check_mcontrol6_hit_status(struct target *target, riscv_reg_t tdata1, uint64_t hit_mask)
struct target_type riscv_target
static struct match_triggers_tdata1_fields fill_match_triggers_tdata1_fields_t6(struct target *target, struct trigger *trigger)
static int resume_prep(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Get everything ready to resume.
static int resume_finish(struct target *target, bool debug_execution)
struct scan_field select_dtmcontrol
static int check_virt_memory_access(struct target *target, target_addr_t address, uint32_t size, uint32_t count, bool is_write)
#define DTMCONTROL_VERSION
static int disable_watchpoints(struct target *target, bool *wp_is_set)
static const struct command_registration riscv_exec_command_handlers[]
static void riscv_info_init(struct target *target, struct riscv_info *r)
static uint8_t ir_dtmcontrol[4]
void riscv_fill_dmi_write(const struct target *target, uint8_t *buf, uint32_t a, uint32_t d)
static bool wp_triggers_cache_search(struct target *target, unsigned int idx, riscv_reg_t tdata1, riscv_reg_t tdata2)
int dtmcs_scan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr)
static int riscv_get_gdb_reg_list_internal(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class, bool is_read)
static int get_loadstore_membase_regno(struct target *target, const riscv_insn_t instruction, int *regid)
static int riscv_rw_memory(struct target *target, struct riscv_mem_access_args args)
static int riscv_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
static void free_wp_triggers_cache(struct target *target)
static int bscan_tunnel_ir_id
static int maybe_add_trigger_t5(struct target *target, bool vs, bool vu, bool m, bool s, bool u, riscv_reg_t exception_codes, int unique_id)
static uint16_t get_offset_clq(riscv_insn_t instruction)
const char * riscv_virt2phys_mode_to_str(enum riscv_virt2phys_mode mode)
static uint8_t ir_user4[4]
static enum @127 resume_order
static int riscv_target_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
int riscv_openocd_poll(struct target *target)
static int riscv_dmi_write(struct target *target, uint32_t dmi_address, uint32_t value)
static unsigned int riscv_xlen_nonconst(struct target *target)
int riscv_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
static int maybe_add_trigger_t3(struct target *target, bool vs, bool vu, bool m, bool s, bool u, bool pending, unsigned int count, int unique_id)
static int oldriscv_poll(struct target *target)
static int riscv_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
static int dtmcs_scan_via_bscan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr)
uint32_t riscv_get_dmi_address(const struct target *target, uint32_t dm_address)
int riscv_write_progbuf(struct target *target, unsigned int index, riscv_insn_t insn)
static int try_setup_single_match_trigger(struct target *target, struct trigger *trigger, struct trigger_request_info trig_info)
static uint16_t get_offset_cld(riscv_insn_t instruction)
static int halt_go(struct target *target)
static int riscv_assert_reset(struct target *target)
riscv_insn_t riscv_read_progbuf(struct target *target, int index)
static int read_by_given_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer, uint32_t access_size)
Read one memory item of given "size".
void riscv_fill_dm_nop(const struct target *target, uint8_t *buf)
static uint32_t bscan_tunnel_nested_tap_select_dmi_num_fields
static int halt_prep(struct target *target)
static int riscv_jim_configure(struct target *target, struct jim_getopt_info *goi)
static uint8_t ir_dbus[4]
static unsigned int riscv_data_bits(struct target *target)
COMMAND_HANDLER(riscv_set_command_timeout_sec)
#define RISCV_HALT_GROUP_REPOLL_LIMIT
static uint16_t get_offset_csdsp(riscv_insn_t instruction)
static int riscv_dmi_read(struct target *target, uint32_t *value, uint32_t address)
static int enable_watchpoints(struct target *target, bool *wp_is_set)
void riscv_fill_dmi_read(const struct target *target, uint8_t *buf, uint32_t a)
static struct jim_nvp nvp_ebreak_mode_opts[]
int riscv_execute_progbuf(struct target *target, uint32_t *cmderr)
static void riscv_deinit_target(struct target *target)
static const char * riscv_get_gdb_arch(const struct target *target)
#define BSCAN_TUNNEL_IR_WIDTH_NBITS
static int riscv_examine(struct target *target)
static bool riscv_virt2phys_mode_is_hw(const struct target *target)
static const char * riscv_priv_mode_to_str(enum riscv_priv_mode mode)
static int riscv_resume_go_all_harts(struct target *target)
static int parse_reg_ranges_impl(struct list_head *ranges, char *args, const char *reg_type, unsigned int max_val, char **const name_buffer)
static int riscv_insn_set(struct command_invocation *cmd, struct target *target, const char **insn_set)
static int maybe_add_trigger_t1(struct target *target, struct trigger *trigger)
static int maybe_add_trigger_t4(struct target *target, bool vs, bool vu, bool nmi, bool m, bool s, bool u, riscv_reg_t interrupts, int unique_id)
static int sample_memory(struct target *target)
static int try_use_trigger_and_cache_result(struct target *target, unsigned int idx, riscv_reg_t tdata1, riscv_reg_t tdata2)
static int find_next_free_trigger(struct target *target, int type, bool chained, unsigned int *idx)
static uint16_t get_offset_clw(riscv_insn_t instruction)
static unsigned int count_trailing_ones(riscv_reg_t reg)
static int riscv_arch_state(struct target *target)
static int riscv_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
static struct scan_field * bscan_tunnel_nested_tap_select_dmi
static int disable_trigger_if_dmode(struct target *target, riscv_reg_t tdata1)
static void wp_triggers_cache_add(struct target *target, unsigned int idx, riscv_reg_t tdata1, riscv_reg_t tdata2, int error_code)
int riscv_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
static int riscv_interrupts_restore(struct target *target, riscv_reg_t old_mstatus)
static struct match_triggers_tdata1_fields fill_match_triggers_tdata1_fields_t2(struct target *target, struct trigger *trigger)
static int riscv_get_gdb_reg_list_noread(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
static int oldriscv_step(struct target *target, bool current, uint32_t address, bool handle_breakpoints)
static struct target_type * get_target_type(struct target *target)
static bool riscv_virt2phys_mode_is_sw(const struct target *target)
static struct scan_field * bscan_tunnel_data_register_select_dmi
int riscv_get_command_timeout_sec(void)
static int find_first_trigger_by_id(struct target *target, int unique_id)
static void trigger_from_breakpoint(struct trigger *trigger, const struct breakpoint *breakpoint)
static const uint8_t bscan_zero[4]
static int riscv_interrupts_disable(struct target *target, riscv_reg_t *old_mstatus)
static int riscv_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int write_by_given_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer, uint32_t access_size)
Write one memory item of given "size".
int riscv_enumerate_triggers(struct target *target)
Count triggers, and initialize trigger_count for each hart.
int riscv_openocd_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
static struct riscv_private_config * alloc_default_riscv_private_config(void)
static int resume_go(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Resume all the harts that have been prepped, as close to instantaneous as possible.
static uint8_t ir_idcode[4]
static int riscv_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical)
static bool riscv_virt2phys_mode_is_off(const struct target *target)
static int old_or_new_riscv_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
static enum riscv_halt_reason riscv_halt_reason(struct target *target)
static const virt2phys_info_t sv39
static int riscv_deassert_reset(struct target *target)
static const uint8_t bscan_one[4]
static uint32_t get_rs1_c(riscv_insn_t instruction)
Decode rs1' register num for RVC.
static bool riscv_mem_access_is_valid(const struct riscv_mem_access_args args)
#define RISCV_SAMPLE_BUF_TIMESTAMP_BEFORE
static struct riscv_info * riscv_info(const struct target *target) __attribute__((unused))
void riscv_semihosting_init(struct target *target)
Initialize RISC-V semihosting.
@ RISCV_MEM_ACCESS_MAX_METHODS_NUM
@ RISCV_MEM_ACCESS_SYSBUS
@ RISCV_MEM_ACCESS_PROGBUF
@ RISCV_MEM_ACCESS_ABSTRACT
@ RISCV_STATE_UNAVAILABLE
@ RISCV_STATE_NON_EXISTENT
enum semihosting_result riscv_semihosting(struct target *target, int *retval)
Check for and process a semihosting request using the ARM protocol).
#define RISCV_SATP_PPN(xlen)
#define RISCV_TINFO_VERSION_UNKNOWN
#define RISCV_SAMPLE_BUF_TIMESTAMP_AFTER
#define RISCV_PGOFFSET(addr)
#define RISCV_PGBASE(addr)
#define RISCV_COMMON_MAGIC
static bool riscv_mem_access_is_write(const struct riscv_mem_access_args args)
#define DEFAULT_COMMAND_TIMEOUT_SEC
@ BSCAN_TUNNEL_NESTED_TAP
@ BSCAN_TUNNEL_DATA_REGISTER
static struct riscv_private_config * riscv_private_config(const struct target *target)
#define RISCV_SATP_MODE(xlen)
#define RISCV_HGATP_MODE(xlen)
@ RISCV_HALT_CRITICAL_ERROR
#define DTM_DTMCS_VERSION_UNKNOWN
#define RISCV_HGATP_PPN(xlen)
@ RISCV_VIRT2PHYS_MODE_HW
@ RISCV_VIRT2PHYS_MODE_OFF
@ RISCV_VIRT2PHYS_MODE_SW
int riscv_reg_set(struct target *target, enum gdb_regno regid, riscv_reg_t value)
This function is used to change the value of a register.
void riscv_reg_cache_invalidate_all(struct target *target)
Invalidate all registers - forget their cached register values.
const char * riscv_reg_gdb_regno_name(const struct target *target, enum gdb_regno regno)
This file describes the register cache interface available to the RISC-V target.
int riscv_reg_flush_all(struct target *target)
Write all dirty registers to the target.
int riscv_reg_get(struct target *target, riscv_reg_t *value, enum gdb_regno regid)
This function is used to get the value of a register.
void riscv_reg_free_all(struct target *target)
Free register cache and associated structures.
bool riscv_reg_cache_any_dirty(const struct target *target, int log_level)
Check whether there are any dirty registers in the OpenOCD's register cache.
target_addr_t addr
Start address to search for the control block.
const struct command_registration semihosting_common_handlers[]
const struct command_registration smp_command_handlers[]
#define foreach_smp_target(pos, head)
#define foreach_smp_target_direction(forward, pos, head)
enum breakpoint_type type
When run_command is called, a new instance will be created on the stack, filled with the proper value...
A TCL -ish GetOpt like code.
Name Value Pairs, aka: NVP.
unsigned int ir_length
size of instruction register
struct match_triggers_tdata1_fields::@128 size
struct match_triggers_tdata1_fields::@129 chain
struct match_triggers_tdata1_fields::@130 match
int(* get)(struct reg *reg)
int(* set)(struct reg *reg, uint8_t *buf)
const struct reg_arch_type * type
struct scan_field tunneled_dr[4]
uint8_t tunneled_dr_width
enum riscv_virt2phys_mode virt2phys_mode
bool wp_allow_equality_match_trigger
struct list_head expose_custom
unsigned int num_enabled_mem_access_methods
enum riscv_isrmasking_mode isrmask_mode
unsigned int halt_group_repoll_count
struct list_head expose_csr
enum yes_no_maybe vsew64_supported
unsigned int common_magic
bool mem_access_warn[RISCV_MEM_ACCESS_MAX_METHODS_NUM]
int64_t trigger_unique_id[RISCV_MAX_TRIGGERS]
int(* access_memory)(struct target *target, const struct riscv_mem_access_args args)
bool wp_allow_ge_lt_trigger
enum riscv_mem_access_method mem_access_methods[RISCV_MEM_ACCESS_MAX_METHODS_NUM]
bool wp_allow_napot_trigger
struct list_head hide_csr
const uint8_t * write_buffer
enum riscv_priv_mode mode
This structure defines a single scan field in the scan.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
unsigned int num_bits
The number of bits this field specifies.
bool is_active
A flag reporting whether semihosting is active.
This holds methods shared between all instances of a given target type.
const char * name
Name of this type of target.
int(* deassert_reset)(struct target *target)
The implementation is responsible for polling the target such that target->state reflects the state c...
int(* init_target)(struct command_context *cmd_ctx, struct target *target)
int(* resume)(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
void(* deinit_target)(struct target *target)
Free all the resources allocated by the target.
int(* halt)(struct target *target)
int(* assert_reset)(struct target *target)
int(* step)(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
int(* poll)(struct target *target)
int(* examine)(struct target *target)
This method is used to perform target setup that requires JTAG access.
int(* virt2phys)(struct target *target, target_addr_t address, target_addr_t *physical)
struct semihosting * semihosting
enum target_debug_reason debug_reason
struct reg_cache * reg_cache
struct list_head * smp_targets
struct breakpoint * breakpoints
struct target_type * type
struct watchpoint * watchpoints
struct list_head elem_tdata1
struct list_head tdata2_cache_head
struct list_head elem_tdata2
int target_call_event_callbacks(struct target *target, enum target_event event)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
const char * debug_reason_name(const struct target *t)
struct target * get_current_target(struct command_context *cmd_ctx)
void target_handle_md_output(struct command_invocation *cmd, struct target *target, target_addr_t address, unsigned int size, unsigned int count, const uint8_t *buffer, bool include_address)
#define ERROR_TARGET_NOT_HALTED
static bool target_was_examined(const struct target *target)
@ TARGET_EVENT_DEBUG_RESUMED
@ TARGET_EVENT_DEBUG_HALTED
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define ERROR_TARGET_NOT_EXAMINED
#define TARGET_DEFAULT_POLLING_INTERVAL
#define ERROR_TARGET_TIMEOUT
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
static void h_u32_to_le(uint8_t *buf, uint32_t val)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
static struct ublast_lowlevel low
static struct ublast_lowlevel_priv info