35 #define DTMCONTROL 0x10
36 #define DTMCONTROL_VERSION (0xf)
40 #define RISCV_TRIGGER_HIT_NOT_FOUND ((int64_t)-1)
42 #define RISCV_HALT_GROUP_REPOLL_LIMIT 5
61 #define BSCAN_TUNNEL_IR_WIDTH_NBITS 7
172 static const char *
const names[] = {
202 .vpn_shift = {12, 22},
203 .vpn_mask = {0x3ff, 0x3ff},
204 .pte_ppn_shift = {10, 20},
205 .pte_ppn_mask = {0x3ff, 0xfff},
206 .pa_ppn_shift = {12, 22},
207 .pa_ppn_mask = {0x3ff, 0xfff},
215 .vpn_shift = {12, 22},
216 .vpn_mask = {0x3ff, 0xfff},
217 .pte_ppn_shift = {10, 20},
218 .pte_ppn_mask = {0x3ff, 0xfff},
219 .pa_ppn_shift = {12, 22},
220 .pa_ppn_mask = {0x3ff, 0xfff},
228 .vpn_shift = {12, 21, 30},
229 .vpn_mask = {0x1ff, 0x1ff, 0x1ff},
230 .pte_ppn_shift = {10, 19, 28},
231 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
232 .pa_ppn_shift = {12, 21, 30},
233 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
241 .vpn_shift = {12, 21, 30},
242 .vpn_mask = {0x1ff, 0x1ff, 0x7ff},
243 .pte_ppn_shift = {10, 19, 28},
244 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
245 .pa_ppn_shift = {12, 21, 30},
246 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
254 .vpn_shift = {12, 21, 30, 39},
255 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff},
256 .pte_ppn_shift = {10, 19, 28, 37},
257 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
258 .pa_ppn_shift = {12, 21, 30, 39},
259 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
267 .vpn_shift = {12, 21, 30, 39},
268 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x7ff},
269 .pte_ppn_shift = {10, 19, 28, 37},
270 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
271 .pa_ppn_shift = {12, 21, 30, 39},
272 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
280 .vpn_shift = {12, 21, 30, 39, 48},
281 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
282 .pte_ppn_shift = {10, 19, 28, 37, 46},
283 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
284 .pa_ppn_shift = {12, 21, 30, 39, 48},
285 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
293 .vpn_shift = {12, 21, 30, 39, 48},
294 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x7ff},
295 .pte_ppn_shift = {10, 19, 28, 37, 46},
296 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
297 .pa_ppn_shift = {12, 21, 30, 39, 48},
298 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
313 if (r->sample_buf.used + 5 < r->sample_buf.size) {
318 r->sample_buf.buf[r->sample_buf.used++] = now & 0xff;
319 r->sample_buf.buf[r->sample_buf.used++] = (now >> 8) & 0xff;
320 r->sample_buf.buf[r->sample_buf.used++] = (now >> 16) & 0xff;
321 r->sample_buf.buf[r->sample_buf.used++] = (now >> 24) & 0xff;
341 uint8_t tunneled_dr_width[4] = {32};
342 uint8_t out_value[5] = {0};
343 uint8_t in_value[5] = {0};
370 tunneled_dr[2].
out_value = tunneled_dr_width;
397 tunneled_dr[1].
out_value = tunneled_dr_width;
410 LOG_ERROR(
"failed jtag scan: %d", retval);
416 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
438 .in_value = in_ptr ? value :
NULL
447 LOG_ERROR(
"'dtmcs' scan failed on TAP %s, error code = %d",
455 LOG_DEBUG(
"TAP %s: DTMCS: 0x%" PRIx32
" -> 0x%" PRIx32,
472 switch (
info->dtm_version) {
495 config->dcsr_ebreak_fields[i] =
true;
497 config->detect_misa =
true;
530 #define RISCV_EBREAK_MODE_INVALID -1
533 { .
name =
"exception", .value =
false },
534 { .name =
"halt", .value =
true },
539 { .
name =
"off", .value =
false },
540 { .name =
"on", .value =
true },
541 { .name =
NULL, .value = -1 }
546 if (goi->
argc == 0) {
547 Jim_WrongNumArgs(goi->
interp, 1, goi->
argv - 1,
548 "[?execution_mode?] ?ebreak_action?");
551 struct jim_nvp *common_mode_nvp;
553 &common_mode_nvp) == JIM_OK) {
560 for (
int ebreak_ctl_i = 0; ebreak_ctl_i <
N_RISCV_MODE; ++ebreak_ctl_i)
561 config->dcsr_ebreak_fields[ebreak_ctl_i] = common_mode_nvp->
value;
569 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
597 const char *separator =
"";
600 const char *
const format =
"%s%s %s";
601 const char *
const priv_mode =
604 config->dcsr_ebreak_fields[ebreak_ctl_i])->
name;
606 len += snprintf(
NULL, 0, format, separator, priv_mode,
mode);
608 len += sprintf(
buffer + len, format, separator, priv_mode,
mode);
619 char *str = malloc(len + 1);
621 LOG_ERROR(
"Unable to allocate a string of %d bytes.", len + 1);
625 Jim_SetResultString(interp, str, len);
638 if (group_num < 0 || group_num > 31) {
639 Jim_SetResultString(goi->
interp,
640 "Invalid group number (must be 0-31)!", -1);
695 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
"");
713 Jim_SetResultString(goi->
interp,
727 Jim_SetResultString(goi->
interp,
741 Jim_SetResultString(goi->
interp,
751 assert(
false &&
"'jim_getopt_nvp' should have returned an error.");
761 info->cmd_ctx = cmd_ctx;
762 info->reset_delays_wait = -1;
771 if (ir_user4_raw == 0) {
794 for (
unsigned int i = 0; i < r->trigger_count; ++i) {
806 free(r->wp_triggers_negative_cache);
823 if (tt &&
info &&
info->version_specific)
832 free(
info->reserved_triggers);
872 bool size_power_of_2 = (
size & (
size - 1)) == 0;
873 bool addr_aligned = (
addr & (
size - 1)) == 0;
874 return size > 1 && size_power_of_2 && addr_aligned;
884 unsigned int num_found = 0;
885 unsigned int num_required = chained ? 2 : 1;
887 for (
unsigned int i = *idx; i < r->trigger_count; i++) {
888 if (r->trigger_unique_id[i] == -1) {
889 if (r->trigger_tinfo[i] & (1 <<
type)) {
891 if (num_required == num_found) {
893 *idx = i - (num_required - 1);
895 "%d trigger(s) of type %d found on index %u, "
897 num_required,
type, *idx,
898 chained ?
"true" :
"false");
917 for (
unsigned int i = 0; i < r->trigger_count; i++) {
918 if (r->trigger_unique_id[i] == unique_id)
926 const unsigned int riscv_reg_bits =
sizeof(
riscv_reg_t) * CHAR_BIT;
927 for (
unsigned int i = 0; i < riscv_reg_bits; i++) {
928 if ((1 & (
reg >> i)) == 0)
931 return riscv_reg_bits;
938 assert(r->reserved_triggers);
939 assert(idx < r->trigger_count);
940 if (r->reserved_triggers[idx]) {
942 "Trigger %u is reserved by 'reserve_trigger' command.", idx);
981 bool misa_s, misa_u, misa_h;
1011 tdata1_ignore_mask |= !(misa_h && misa_s) ?
CSR_ICOUNT_VS : 0;
1012 tdata1_ignore_mask |= !(misa_h && misa_u) ?
CSR_ICOUNT_VU : 0;
1029 const bool tdata1_config_denied = (tdata1 & ~tdata1_ignore_mask) != (tdata1_rb & ~tdata1_ignore_mask);
1035 bool unsupported_napot_range =
false;
1037 if (!tdata1_config_denied) {
1039 if (is_mcontrol && is_napot_match) {
1042 if (maskmax_value < napot_size)
1043 unsupported_napot_range =
true;
1047 const bool tdata2_config_denied = tdata2 != tdata2_rb;
1048 if (tdata1_config_denied || tdata2_config_denied || unsupported_napot_range) {
1051 if (tdata1_config_denied)
1053 "After writing 0x%" PRIx64
" to tdata1 it contains 0x%" PRIx64,
1056 if (tdata2_config_denied)
1058 "After writing 0x%" PRIx64
" to tdata2 it contains 0x%" PRIx64,
1061 if (unsupported_napot_range)
1063 "The requested NAPOT match range (tdata2=0x%" PRIx64
") exceeds maskmax_value=0x%" PRIx64,
1064 tdata2, maskmax_value);
1082 const uint32_t bpcontrol_x = 1<<0;
1083 const uint32_t bpcontrol_w = 1<<1;
1084 const uint32_t bpcontrol_r = 1<<2;
1085 const uint32_t bpcontrol_u = 1<<3;
1086 const uint32_t bpcontrol_s = 1<<4;
1087 const uint32_t bpcontrol_h = 1<<5;
1088 const uint32_t bpcontrol_m = 1<<6;
1089 const uint32_t bpcontrol_bpmatch = 0xf << 7;
1090 const uint32_t bpcontrol_bpaction = 0xff << 11;
1092 unsigned int idx = 0;
1099 if (tdata1 & (bpcontrol_r | bpcontrol_w | bpcontrol_x)) {
1108 tdata1 =
set_field(tdata1, bpcontrol_u, !!(r->misa &
BIT(
'U' -
'A')));
1109 tdata1 =
set_field(tdata1, bpcontrol_s, !!(r->misa &
BIT(
'S' -
'A')));
1110 tdata1 =
set_field(tdata1, bpcontrol_h, !!(r->misa &
BIT(
'H' -
'A')));
1111 tdata1 =
set_field(tdata1, bpcontrol_m, 1);
1112 tdata1 =
set_field(tdata1, bpcontrol_bpaction, 0);
1113 tdata1 =
set_field(tdata1, bpcontrol_bpmatch, 0);
1152 if (elem_2->
tdata2 == find_tdata2)
1162 if (elem_1->
tdata1 == find_tdata1)
1172 r->wp_triggers_negative_cache = (
struct list_head *)calloc(r->trigger_count,
1174 for (
unsigned int i = 0; i < r->trigger_count; ++i)
1237 for (
unsigned int idx = 0;
1265 for (
unsigned int idx = 0;
1394 if (r->wp_allow_napot_trigger) {
1406 "Use 'riscv set_enable_trigger_feature napot wp' to enable it.");
1410 if (r->wp_allow_ge_lt_trigger) {
1442 "Use 'riscv set_enable_trigger_feature ge_lt wp' to enable it.");
1446 if (r->wp_allow_equality_match_trigger) {
1458 "Use 'riscv set_enable_trigger_feature eq wp' to enable it.");
1463 ", but may not match accesses at addresses in the inclusive range from 0x%"
1467 if (!
info->range_trigger_fallback_encountered)
1472 "Could not set a trigger that will match a whole address range. "
1473 "As a fallback, this trigger (and maybe others) will only match "
1474 "against the first address of the range.");
1475 info->range_trigger_fallback_encountered =
true;
1507 bool m,
bool s,
bool u,
bool pending,
unsigned int count,
1527 unsigned int idx = 0;
1534 r->trigger_unique_id[idx] = unique_id;
1539 bool nmi,
bool m,
bool s,
bool u,
riscv_reg_t interrupts,
1560 unsigned int idx = 0;
1567 r->trigger_unique_id[idx] = unique_id;
1572 bool m,
bool s,
bool u,
riscv_reg_t exception_codes,
1590 tdata2 = exception_codes;
1592 unsigned int idx = 0;
1599 r->trigger_unique_id[idx] = unique_id;
1642 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1645 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1647 if (access_size <=
size &&
address % access_size == 0)
1651 unsigned int offset_head =
address % access_size;
1652 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1653 uint8_t helper_buf[n_blocks * access_size];
1660 memcpy(helper_buf + offset_head,
buffer,
size);
1669 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1672 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1674 if (access_size <=
size &&
address % access_size == 0)
1678 unsigned int offset_head =
address % access_size;
1679 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1680 uint8_t helper_buf[n_blocks * access_size];
1687 memcpy(
buffer, helper_buf + offset_head,
size);
1700 unsigned int preferred_size =
size;
1701 while (
address % preferred_size != 0)
1702 preferred_size /= 2;
1710 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1711 if (access_size == preferred_size)
1732 unsigned int preferred_size =
size;
1733 while (
address % preferred_size != 0)
1734 preferred_size /= 2;
1742 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1743 if (access_size == preferred_size)
1780 uint8_t buff[4] = { 0 };
1819 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1820 if (r->trigger_unique_id[i] ==
unique_id) {
1823 r->trigger_unique_id[i] = -1;
1831 "Couldn't find the hardware resources used by hardware trigger.");
1933 const uint32_t hit_info = (hit1 << 1) | hit0;
1956 for (uint64_t i = 0; i <
ARRAY_SIZE(tdata1_tests); ++i) {
1961 if (tdata1_test_rb == tdata1_tests[i]) {
1978 bool *need_single_step)
1986 assert(need_single_step);
1987 *need_single_step =
false;
1994 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1995 if (r->trigger_unique_id[i] == -1)
2006 uint64_t hit_mask = 0;
2013 *need_single_step =
true;
2018 *need_single_step =
true;
2026 *need_single_step =
true;
2045 if (tdata1 & hit_mask) {
2047 ") has hit bit set. (need_single_step=%s)",
2048 i, r->trigger_unique_id[i], (*need_single_step) ?
"yes" :
"no");
2070 uint16_t offset_4to2and7to6_bits =
2072 uint16_t offset_4to2_bits = offset_4to2and7to6_bits >> 2;
2073 uint16_t offset_7to6_bits = offset_4to2and7to6_bits & 0x3;
2075 return (offset_4to2_bits << 2) + (offset_5_bit << 5)
2076 + (offset_7to6_bits << 6);
2082 uint16_t offset_4to3and8to6_bits =
2084 uint16_t offset_4to3_bits = offset_4to3and8to6_bits >> 3;
2085 uint16_t offset_8to6_bits = offset_4to3and8to6_bits & 0x7;
2087 return (offset_4to3_bits << 3) + (offset_5_bit << 5)
2088 + (offset_8to6_bits << 6);
2094 uint16_t offset_5to2and7to6_bits =
2096 uint16_t offset_5to2_bits = offset_5to2and7to6_bits >> 2;
2097 uint16_t offset_7to6_bits = offset_5to2and7to6_bits & 0x3;
2098 return (offset_5to2_bits << 2) + (offset_7to6_bits << 6);
2104 uint16_t offset_5to3and8to6_bits =
2106 uint16_t offset_5to3_bits = offset_5to3and8to6_bits >> 3;
2107 uint16_t offset_8to6_bits = offset_5to3and8to6_bits & 0x7;
2108 return (offset_5to3_bits << 3) + (offset_8to6_bits << 6);
2115 uint16_t offset_2_bit = offset_2and6_bits >> 1;
2116 uint16_t offset_6_bit = offset_2and6_bits & 0x1;
2118 return (offset_2_bit << 2) + (offset_5to3_bits << 3) + (offset_6_bit << 6);
2126 return (offset_5to3_bits << 3) + (offset_7to6_bits << 6);
2133 uint16_t offset_5to4and8_bits =
2135 uint16_t offset_5to4_bits = offset_5to4and8_bits >> 1;
2136 uint16_t offset_8_bit = offset_5to4and8_bits & 0x1;
2137 return (offset_5to4_bits << 4) + (offset_7to6_bits << 6)
2138 + (offset_8_bit << 8);
2144 uint16_t offset_4and9to6_bits =
2146 uint16_t offset_4_bit = offset_4and9to6_bits >> 4;
2147 uint16_t offset_9to6_bits = offset_4and9to6_bits & 0xf;
2149 return (offset_4_bit << 4) + (offset_5_bit << 5) + (offset_9to6_bits << 6);
2155 uint16_t offset_5to4and9to6_bits =
2157 uint16_t offset_5to4_biits = offset_5to4and9to6_bits >> 4;
2158 uint16_t offset_9to6_bits = offset_5to4and9to6_bits & 0xf;
2159 return (offset_5to4_biits << 4) + (offset_9to6_bits << 6);
2177 if ((instruction & 0x03) < 0x03) {
2218 " store", instruction);
2332 " store", instruction);
2361 "The code points with rd = x0 are reserved for C.LWSP");
2371 "The code points with rd = x0 are reserved for C.LDSP");
2377 "have the \"F\" extension");
2388 "The code points with rd = x0 are reserved for C.LQSP");
2394 "have the \"D\" extension");
2409 "have the \"F\" extension");
2420 "have the \"D\" extension");
2435 "have the \"F\" extension");
2446 "have the \"D\" extension");
2461 "have the \"F\" extension");
2472 "have the \"D\" extension");
2481 " store", instruction);
2512 if (wp->unique_id == r->trigger_hit) {
2513 *hit_watchpoint = wp;
2521 const uint8_t
length = 4;
2534 for (
int i = 0; i <
length; i++) {
2536 instruction += (
buffer[i] << 8 * i);
2551 mem_addr += memoffset;
2564 if (mem_addr >= wp->
address &&
2566 *hit_watchpoint = wp;
2569 is_load ?
"Load from" :
"Store to", mem_addr,
2571 "read" : (wp->
rw ==
WPT_WRITE ?
"write" :
"access")),
2589 bool handle_breakpoints)
2605 handle_breakpoints ?
"true" :
"false");
2606 if (!r->get_hart_state)
2617 handle_breakpoints,
true );
2631 uint32_t dtmcontrol;
2642 info->dtm_version = dtm_version;
2655 if (
info->dtm_version != dtm_version) {
2679 if (!r->get_hart_state)
2697 if (bp->type ==
BKPT_HARD && bp->is_set && bp->address == dpc) {
2701 "can't derive debug reason for context-aware breakpoint: "
2703 ", asid = %" PRIx32
", linked = %d",
2704 bp->unique_id, bp->address, bp->asid, bp->linked_brp);
2718 r->trigger_hit = -1;
2719 r->need_single_step =
false;
2720 switch (halt_reason) {
2737 "Active hit bit is detected, trying to find trigger owner.");
2739 if (bp->unique_id == r->trigger_hit) {
2742 "Breakpoint with unique_id = %" PRIu32
" owns the trigger.",
2750 if (wp->unique_id == r->trigger_hit) {
2753 "Watchpoint with unique_id = %" PRIu32
" owns the trigger.",
2760 "No trigger hit found, deriving debug reason without it.");
2833 "the target is not halted!");
2848 if (!r->get_hart_state) {
2871 if (!r->get_hart_state) {
2948 memset(wp_is_set,
false, r->trigger_count);
2954 wp_is_set[i] ?
"true" :
"false");
2974 wp_is_set[i] ?
"needs " :
"does not need");
2998 if (handle_breakpoints) {
3009 && r->need_single_step)) {
3016 if (r->get_hart_state) {
3037 if (!r->get_hart_state) {
3058 "BUG: registers should have been flushed by this point.");
3076 bool handle_breakpoints,
3077 bool debug_execution,
3095 list_add(&single_target_entry.
lh, &single_target_list);
3096 targets = &single_target_list;
3101 current ?
"true" :
"false",
3103 handle_breakpoints ?
"true" :
"false",
3104 debug_execution ?
"true" :
"false");
3146 debug_execution,
false);
3165 assert(
false &&
"Unknown privilege mode");
3186 bool halted_in_m = dcsr_prv ==
PRV_M;
3225 }
else if (prv ==
PRV_U) {
3229 "which is a hardware bug", prv, mprv ?
"mstatus.MPP" :
"dcsr.prv");
3328 info->name, ppn,
virtual);
3331 assert(xlen >=
info->va_bits);
3334 if (masked_msbs != 0 && masked_msbs !=
mask) {
3336 "for %s mode.",
virtual,
info->name);
3342 int i =
info->level - 1;
3344 uint64_t vpn =
virtual >>
info->vpn_shift[i];
3345 vpn &=
info->vpn_mask[i];
3356 assert(
info->pte_shift <= 3);
3363 .count = (1 <<
info->pte_shift) / 4,
3365 int retval = r->access_memory(
target, args);
3369 if (
info->pte_shift == 2)
3379 "; mode=%s; i=%d", pte_address, pte,
info->name, i);
3401 while (i < info->level) {
3402 ppn = pte >>
info->pte_ppn_shift[i];
3403 ppn &=
info->pte_ppn_mask[i];
3405 info->pa_ppn_shift[i]);
3406 *physical |= (ppn <<
info->pa_ppn_shift[i]);
3410 info->name,
virtual, *physical);
3436 switch (vsatp_mode) {
3456 "vsatp mode %d is not supported. (vsatp: 0x%" PRIx64
")",
3463 switch (hgatp_mode) {
3483 "hgatp mode %d is not supported. (hgatp: 0x%" PRIx64
")",
3503 virtual, &guest_physical) !=
ERROR_OK)
3506 guest_physical =
virtual;
3516 guest_physical, physical) !=
ERROR_OK)
3519 *physical = guest_physical;
3529 *physical =
virtual;
3539 bool enabled =
false;
3543 *physical =
virtual;
3560 switch (satp_mode) {
3575 " (satp: 0x%" PRIx64
")", satp_value);
3579 " (satp: 0x%" PRIx64
")", satp_value);
3590 uint32_t
size, uint32_t
count,
bool is_write)
3595 if (is_misaligned && crosses_page_boundary) {
3597 " would access an element across page boundary. This is not supported.",
3616 return r->access_memory(
target, args);
3632 return r->access_memory(
target, args);
3640 if (args.
count == 0) {
3642 is_write ?
"write to" :
"read from", args.
address);
3660 "hardware: OpenOCD does not set mstatus.MPV yet. "
3661 "Use 'riscv virt2phys_mode sw'.");
3669 bool mmu_enabled =
false;
3682 uint32_t current_count = 0;
3684 while (current_count < args.
count) {
3695 uint32_t chunk_count = MIN(args.
count - current_count,
3700 current_access.
address = physical_addr;
3701 current_access.
count = chunk_count;
3711 current_count += chunk_count;
3712 current_address += chunk_count * args.
size;
3749 return "riscv:rv32";
3751 return "riscv:rv64";
3758 struct reg **reg_list[],
int *reg_list_size,
3768 switch (reg_class) {
3770 *reg_list_size = 33;
3780 *reg_list = calloc(*reg_list_size,
sizeof(
struct reg *));
3784 for (
int i = 0; i < *reg_list_size; i++) {
3800 struct reg **reg_list[],
int *reg_list_size,
3808 struct reg **reg_list[],
int *reg_list_size,
3823 semihosting_active ?
" Semihosting is active." :
"");
3829 struct mem_param *mem_params,
int num_reg_params,
3845 for (
int i = 0; i < num_mem_params; i++) {
3851 " size=0x%" PRIx32, mem_params[i].
address, mem_params[i].
size);
3864 for (
int i = 0; i < num_reg_params; i++) {
3872 if (r->
size != reg_params[i].
size) {
3874 reg_params[i].reg_name, r->
size, reg_params[i].
size);
3903 int num_mem_params,
struct mem_param *mem_params,
3904 int num_reg_params,
struct reg_param *reg_params,
3919 if (now -
start > timeout_ms) {
3935 for (
unsigned int i = 0; i <
ARRAY_SIZE(regnums); i++) {
3955 if (exit_point && final_pc != exit_point) {
3966 uint8_t buf[8] = { 0 };
3971 for (
int i = 0; i < num_reg_params; i++) {
3991 for (
int i = 0; i < num_mem_params; i++) {
3995 mem_params[i].
value);
4018 static const uint8_t riscv32_crc_code[] = {
4019 #include "../../../contrib/loaders/checksum/riscv32_crc.inc"
4021 static const uint8_t riscv64_crc_code[] = {
4022 #include "../../../contrib/loaders/checksum/riscv64_crc.inc"
4025 static const uint8_t *crc_code;
4028 unsigned int crc_code_size;
4030 crc_code = riscv32_crc_code;
4031 crc_code_size =
sizeof(riscv32_crc_code);
4033 crc_code = riscv64_crc_code;
4034 crc_code_size =
sizeof(riscv64_crc_code);
4037 if (
count < crc_code_size * 4) {
4061 crc_algorithm->
address, retval);
4076 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
4084 *checksum =
buf_get_u32(reg_params[0].value, 0, 32);
4162 previous_target_state);
4188 if (r->handle_became_halted &&
4189 r->handle_became_halted(
target, previous_riscv_state) !=
ERROR_OK)
4198 r->halted_needs_event_callback =
true;
4212 if (r->handle_became_running &&
4213 r->handle_became_running(
target, previous_riscv_state) !=
ERROR_OK)
4221 if (r->handle_became_unavailable &&
4222 r->handle_became_unavailable(
target, previous_riscv_state) !=
ERROR_OK)
4240 if (!r->sample_buf.buf || !r->sample_config.enabled)
4248 if (r->sample_memory) {
4249 result = r->sample_memory(
target, &r->sample_buf, &r->sample_config,
4257 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
4258 if (r->sample_config.bucket[i].enabled &&
4259 r->sample_buf.used + 1 + r->sample_config.bucket[i].size_bytes < r->sample_buf.size) {
4261 r->sample_buf.buf[r->sample_buf.used] = i;
4263 r->sample_config.bucket[i].address,
4264 r->sample_config.bucket[i].size_bytes, 1,
4265 r->sample_buf.buf + r->sample_buf.used + 1);
4267 r->sample_buf.used += 1 + r->sample_config.bucket[i].size_bytes;
4278 r->sample_config.enabled =
false;
4303 list_add(&single_target_entry.
lh, &single_target_list);
4304 targets = &single_target_list;
4307 unsigned int should_remain_halted = 0;
4308 unsigned int should_resume = 0;
4310 unsigned int running = 0;
4311 unsigned int running_under_debug = 0;
4312 unsigned int cause_groups = 0;
4320 info->halted_needs_event_callback =
false;
4329 switch (next_action) {
4337 running_under_debug++;
4340 should_remain_halted++;
4349 should_remain_halted, should_resume);
4350 if (should_remain_halted && should_resume) {
4352 should_remain_halted, should_resume);
4354 if (should_remain_halted) {
4356 should_remain_halted);
4358 }
else if (should_resume) {
4361 }
else if (
halted && running && (running_under_debug == running)) {
4367 }
else if (
halted && running) {
4406 if (
halted == cause_groups) {
4431 if (
info->halted_needs_event_callback) {
4433 info->halted_needs_event_callback =
false;
4475 if (handle_breakpoints) {
4489 bool *wps_to_enable = calloc(r->trigger_count,
sizeof(*wps_to_enable));
4490 if (!wps_to_enable) {
4497 "watchpoints before single-step.");
4498 free(wps_to_enable);
4502 bool success =
true;
4525 "BUG: registers should have been flushed by this point.");
4540 "after single-step.");
4543 free(wps_to_enable);
4552 if (handle_callbacks)
4557 if (handle_callbacks)
4590 LOG_WARNING(
"The command 'riscv set_reset_timeout_sec' is deprecated! Please, use 'riscv set_command_timeout_sec'.");
4610 for (
unsigned int i = 0; i < r->num_enabled_mem_access_methods; i++) {
4614 switch (r->mem_access_methods[i]) {
4635 unsigned int progbuf_cnt = 0;
4636 unsigned int sysbus_cnt = 0;
4637 unsigned int abstract_cnt = 0;
4640 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4641 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0) {
4643 }
else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0) {
4645 }
else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0) {
4649 "must be one of: 'progbuf', 'sysbus' or 'abstract'",
CMD_ARGV[i]);
4653 if (progbuf_cnt > 1 || sysbus_cnt > 1 || abstract_cnt > 1) {
4659 r->num_enabled_mem_access_methods =
CMD_ARGC;
4660 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4661 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0)
4663 else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0)
4665 else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0)
4671 r->mem_access_warn[i] =
true;
4678 LOG_WARNING(
"DEPRECATED! use 'mem_access' not 'set_mem_access'");
4690 while (isspace((
unsigned char)reg_address_str[0]))
4693 bool is_hex_address = strncmp(reg_address_str,
"0x", 2) == 0 ||
4694 strncmp(reg_address_str,
"0X", 2) == 0;
4696 unsigned int scanned_chars;
4697 if (is_hex_address) {
4698 reg_address_str += 2;
4699 if (sscanf(reg_address_str,
"%x%n", reg_addr, &scanned_chars) != 1)
4708 if (reg_address_str[0] ==
'0' && strlen(reg_address_str) > 1)
4710 if (sscanf(reg_address_str,
"%u%n", reg_addr, &scanned_chars) != 1)
4713 return scanned_chars == strlen(reg_address_str);
4717 const char *
reg_type,
unsigned int max_val,
char **
const name_buffer)
4721 for (
char *arg = strtok(args,
","); arg; arg = strtok(
NULL,
",")) {
4722 unsigned int low = 0;
4723 unsigned int high = 0;
4726 char *dash = strchr(arg,
'-');
4727 char *equals = strchr(arg,
'=');
4729 if (!dash && !equals) {
4732 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
4735 }
else if (dash && !equals) {
4739 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4743 const char *high_num_in = dash + 1;
4745 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4750 LOG_ERROR(
"Incorrect range encountered [%u, %u].",
low, high);
4753 }
else if (!dash && equals) {
4757 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4762 const char *
const reg_name_in = equals + 1;
4763 const size_t reg_type_len = strlen(
reg_type);
4765 *name_buffer = calloc(1, strlen(reg_name_in) + reg_type_len + 2);
4766 name = *name_buffer;
4772 name[reg_type_len] =
'_';
4774 unsigned int scanned_chars;
4776 if (sscanf(reg_name_in,
"%[_a-zA-Z0-9]%n", scan_dst, &scanned_chars) != 1 ||
4777 scanned_chars != strlen(reg_name_in)) {
4778 LOG_ERROR(
"Invalid characters in register name '%s'.", reg_name_in);
4782 LOG_ERROR(
"Invalid argument '%s'.", arg);
4786 high = MAX(high,
low);
4788 if (high > max_val) {
4789 LOG_ERROR(
"Cannot expose %s register number 0x%x, maximum allowed value is 0x%x.",
4797 if (entry->
low <= high && low <= entry->high) {
4800 "Register %u has already been exposed previously",
reg_type,
low);
4802 LOG_WARNING(
"Overlapping register ranges - Register range starting from %u overlaps "
4803 "with already exposed register/range at %u.",
low, entry->
low);
4822 *name_buffer =
NULL;
4830 const char *
reg_type,
unsigned int max_val)
4832 char *args = strdup(tcl_arg);
4837 char *name_buffer =
NULL;
4853 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4871 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4889 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4900 unsigned int index = 0;
4918 if (r->authdata_read) {
4933 unsigned int index = 0;
4948 if (!r->authdata_write) {
4953 return r->authdata_write(
target, value, index);
4960 if (!r || !r->get_dmi_address)
4962 return r->get_dmi_address(
target, dm_address);
4994 if (!r->dmi_write) {
4998 const int result = r->dmi_write(
target, dmi_address, value);
5006 const bool progbuf_touched =
5009 const bool dm_deactivated =
5012 if (progbuf_touched || dm_deactivated) {
5013 if (r->invalidate_cached_progbuf) {
5021 r->invalidate_cached_progbuf(
target);
5024 "invalidate_cached_progbuf() is not implemented.");
5035 uint32_t dmi_address;
5051 uint32_t dmi_address, value;
5064 uint32_t dm_address;
5081 uint32_t dm_address, value;
5102 r->reset_delays_wait = wait;
5114 if (!strcmp(
CMD_ARGV[0],
"idcode"))
5116 else if (!strcmp(
CMD_ARGV[0],
"dtmcs"))
5118 else if (!strcmp(
CMD_ARGV[0],
"dmi"))
5131 if (!strcmp(
CMD_ARGV[0],
"normal")) {
5133 }
else if (!strcmp(
CMD_ARGV[0],
"reversed")) {
5145 uint8_t irwidth = 0;
5148 if (CMD_ARGC < 1 || CMD_ARGC > 2)
5163 LOG_INFO(
"Nested Tap based Bscan Tunnel Selected");
5165 LOG_INFO(
"Simple Register based Bscan Tunnel Selected");
5167 LOG_INFO(
"Invalid Tunnel type selected ! : selecting default Nested Tap Type");
5184 LOG_INFO(
"Bscan tunnel IR 0x%x selected", ir_id);
5195 static const struct jim_nvp nvp_maskisr_modes[] = {
5198 { .name =
NULL, .value = -1 },
5235 const char *mode_str;
5247 assert(0 &&
"Unexpected execution mode");
5248 mode_str =
"unexpected";
5253 LOG_WARNING(
"DEPRECATED! use '%s cget -ebreak' not '%s'",
5256 config->dcsr_ebreak_fields[
mode] ?
"on" :
"off");
5264 config->dcsr_ebreak_fields[
mode] = ebreak_ctl;
5328 "doesn't support setting more than one at a time.");
5339 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5342 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5344 else if (!strcmp(
CMD_ARGV[i],
"nmi"))
5346 else if (!strcmp(
CMD_ARGV[i],
"m"))
5348 else if (!strcmp(
CMD_ARGV[i],
"s"))
5350 else if (!strcmp(
CMD_ARGV[i],
"u"))
5355 if (!nmi && interrupts == 0) {
5356 LOG_ERROR(
"Doesn't make sense to set itrigger with "
5357 "mie_bits=0 and without nmi.");
5359 }
else if (!vs && !vu && !m && !s && !u) {
5360 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5361 "least one of vs, vu, m, s, or u.");
5369 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5370 return riscv_clear_trigger(
CMD, ITRIGGER_UNIQUE_ID,
"itrigger");
5373 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5398 "doesn't support setting more than one at a time.");
5406 bool pending =
false;
5407 unsigned int count = 0;
5409 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5412 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5414 else if (!strcmp(
CMD_ARGV[i],
"pending"))
5416 else if (!strcmp(
CMD_ARGV[i],
"m"))
5418 else if (!strcmp(
CMD_ARGV[i],
"s"))
5420 else if (!strcmp(
CMD_ARGV[i],
"u"))
5426 LOG_ERROR(
"Doesn't make sense to set icount trigger with "
5429 }
else if (!vs && !vu && !m && !s && !u) {
5430 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5431 "least one of vs, vu, m, s, or u.");
5439 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5440 return riscv_clear_trigger(
CMD, ICOUNT_UNIQUE_ID,
"icount trigger");
5443 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5468 "doesn't support setting more than one at a time.");
5478 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5481 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5483 else if (!strcmp(
CMD_ARGV[i],
"m"))
5485 else if (!strcmp(
CMD_ARGV[i],
"s"))
5487 else if (!strcmp(
CMD_ARGV[i],
"u"))
5492 if (exception_codes == 0) {
5493 LOG_ERROR(
"Doesn't make sense to set etrigger with "
5494 "exception_codes=0.");
5496 }
else if (!vs && !vu && !m && !s && !u) {
5497 LOG_ERROR(
"Doesn't make sense to set etrigger without at "
5498 "least one of vs, vu, m, s, or u.");
5506 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5507 return riscv_clear_trigger(
CMD, ETRIGGER_UNIQUE_ID,
"etrigger");
5510 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5526 if (CMD_ARGC < 2 || CMD_ARGC > 3)
5553 int result = r->access_memory(
target, args);
5567 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
5568 if (r->sample_config.bucket[i].enabled) {
5570 r->sample_config.bucket[i].address,
5571 r->sample_config.bucket[i].size_bytes);
5584 if (bucket >
ARRAY_SIZE(r->sample_config.bucket)) {
5589 if (!strcmp(
CMD_ARGV[1],
"clear")) {
5590 r->sample_config.bucket[bucket].enabled =
false;
5596 if (r->sample_config.bucket[bucket].size_bytes != 4 &&
5597 r->sample_config.bucket[bucket].size_bytes != 8) {
5602 r->sample_config.bucket[bucket].size_bytes = 4;
5605 r->sample_config.bucket[bucket].enabled =
true;
5608 if (!r->sample_buf.buf) {
5609 r->sample_buf.size = 1024 * 1024;
5610 r->sample_buf.buf = malloc(r->sample_buf.size);
5614 r->sample_buf.used = 0;
5616 r->sample_config.enabled =
true;
5629 bool base64 =
false;
5631 if (!strcmp(
CMD_ARGV[0],
"base64")) {
5642 r->sample_buf.used,
NULL);
5652 while (i < r->sample_buf.used) {
5653 uint8_t
command = r->sample_buf.buf[i++];
5655 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5659 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5664 r->sample_config.bucket[
command].address);
5665 if (r->sample_config.bucket[
command].size_bytes == 4) {
5666 uint32_t value =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5669 }
else if (r->sample_config.bucket[
command].size_bytes == 8) {
5670 uint64_t value =
buf_get_u64(r->sample_buf.buf + i, 0, 64);
5675 r->sample_config.bucket[
command].size_bytes);
5690 r->sample_buf.used = 0;
5695 const char *key,
unsigned int value,
bool is_available)
5698 snprintf(full_key,
sizeof(full_key),
"%s.%s", section, key);
5722 const bool trigger_count_available =
5724 riscv_print_info_line_if_available(
CMD,
"hart",
"trigger_count",
5725 r->trigger_count, trigger_count_available);
5734 if (CMD_ARGC < 1 || CMD_ARGC > 16)
5747 "only supported on v0.13 or v1.0 targets.");
5753 "program buffer, target not halted.");
5766 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
5794 bool enable_for_wp =
true;
5797 enable_for_wp =
true;
5798 else if (!strcmp(
CMD_ARGV[1],
"none"))
5799 enable_for_wp =
false;
5804 r->wp_allow_equality_match_trigger = enable_for_wp;
5805 r->wp_allow_napot_trigger = enable_for_wp;
5806 r->wp_allow_ge_lt_trigger = enable_for_wp;
5807 }
else if (!strcmp(
CMD_ARGV[0],
"eq")) {
5808 r->wp_allow_equality_match_trigger = enable_for_wp;
5809 }
else if (!strcmp(
CMD_ARGV[0],
"napot")) {
5810 r->wp_allow_napot_trigger = enable_for_wp;
5811 }
else if (!strcmp(
CMD_ARGV[0],
"ge_lt")) {
5812 r->wp_allow_ge_lt_trigger = enable_for_wp;
5821 "Equality match trigger: for wp (%s)\n"
5822 "NAPOT trigger: for wp (%s)\n"
5823 "ge-lt chained triggers: for wp (%s)",
5824 r->wp_allow_equality_match_trigger ?
"enabled" :
"disabled",
5825 r->wp_allow_napot_trigger ?
"enabled" :
"disabled",
5826 r->wp_allow_ge_lt_trigger ?
"enabled" :
"disabled");
5836 const char *separator =
"";
5837 for (
riscv_reg_t t = 0; t < r->trigger_count; ++t) {
5838 if (r->reserved_triggers[t]) {
5867 if (r->trigger_count == 0) {
5871 if (t >= r->trigger_count) {
5873 " does not exist. There are only %u triggers"
5874 " on the target (with indexes 0 .. %u).",
5875 t, r->trigger_count, r->trigger_count - 1);
5878 if (r->trigger_unique_id[t] != -1) {
5880 " is already in use and can not be reserved.", t);
5919 .
name =
"dump_sample_buf",
5920 .handler = handle_dump_sample_buf_command,
5922 .usage =
"[base64]",
5923 .help =
"Print the contents of the sample buffer, and clear the buffer."
5927 .handler = handle_info,
5930 .help =
"Displays some information OpenOCD detected about the target."
5933 .name =
"memory_sample",
5934 .handler = handle_memory_sample_command,
5936 .usage =
"bucket address|clear [size=4]",
5937 .help =
"Causes OpenOCD to frequently read size bytes at the given address."
5940 .name =
"repeat_read",
5941 .handler = handle_repeat_read,
5943 .usage =
"count address [size=4]",
5944 .help =
"Repeatedly read the value at the given physical address."
5947 .name =
"set_command_timeout_sec",
5948 .handler = riscv_set_command_timeout_sec,
5951 .help =
"Set the wall-clock timeout (in seconds) for individual commands"
5954 .name =
"set_reset_timeout_sec",
5955 .handler = riscv_set_reset_timeout_sec,
5958 .help =
"DEPRECATED. Use 'riscv set_command_timeout_sec' instead."
5961 .name =
"set_mem_access",
5962 .handler = riscv_set_mem_access,
5964 .usage =
"method1 [method2] [method3]",
5965 .help =
"DEPRECATED: Use 'riscv mem_access' instead."
5968 .name =
"mem_access",
5969 .handler = riscv_mem_access,
5971 .usage =
"[method1 [method2 [method3]]]",
5972 .help =
"Configure which memory access methods shall be used and in which order "
5973 "of priority. Method can be one of: 'progbuf', 'sysbus' or 'abstract'."
5976 .name =
"expose_csrs",
5977 .handler = riscv_set_expose_csrs,
5979 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5980 .help =
"Configure a list of inclusive ranges for CSRs to expose in "
5981 "addition to the standard ones. This must be executed before "
5985 .name =
"expose_custom",
5986 .handler = riscv_set_expose_custom,
5988 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5989 .help =
"Configure a list of inclusive ranges for custom registers to "
5990 "expose. custom0 is accessed as abstract register number 0xc000, "
5991 "etc. This must be executed before `init`."
5994 .name =
"hide_csrs",
5995 .handler = riscv_hide_csrs,
5997 .usage =
"{n0|n-m0}[,n1|n-m1]......",
5998 .help =
"Configure a list of inclusive ranges for CSRs to hide from gdb. "
5999 "Hidden registers are still available, but are not listed in "
6000 "gdb target description and `reg` command output. "
6001 "This must be executed before `init`."
6004 .name =
"authdata_read",
6005 .handler = riscv_authdata_read,
6008 .help =
"Return the 32-bit value read from authdata or authdata0 "
6009 "(index=0), or authdata1 (index=1)."
6012 .name =
"authdata_write",
6013 .handler = riscv_authdata_write,
6015 .usage =
"[index] value",
6016 .help =
"Write the 32-bit value to authdata or authdata0 (index=0), "
6017 "or authdata1 (index=1)."
6021 .handler = handle_riscv_dmi_read,
6024 .help =
"Read and return 32-bit value from the given address on the "
6028 .name =
"dmi_write",
6029 .handler = handle_riscv_dmi_write,
6031 .usage =
"address value",
6032 .help =
"Write a 32-bit value to the given address on the RISC-V DMI bus."
6036 .handler = handle_riscv_dm_read,
6038 .usage =
"reg_address",
6039 .help =
"Read and return 32-bit value from a debug module's register "
6044 .handler = handle_riscv_dm_write,
6046 .usage =
"reg_address value",
6047 .help =
"Write a 32-bit value to the debug module's register at "
6051 .name =
"reset_delays",
6052 .handler = riscv_reset_delays,
6055 .help =
"OpenOCD learns how many Run-Test/Idle cycles are required "
6056 "between scans to avoid encountering the target being busy. This "
6057 "command resets those learned values after `wait` scans. It's only "
6058 "useful for testing OpenOCD itself."
6061 .name =
"resume_order",
6062 .handler = riscv_resume_order,
6064 .usage =
"normal|reversed",
6065 .help =
"Choose the order that harts are resumed in when `hasel` is not "
6066 "supported. Normal order is from lowest hart index to highest. "
6067 "Reversed order is from highest hart index to lowest."
6071 .handler = riscv_set_ir,
6073 .usage =
"idcode|dtmcs|dmi value",
6074 .help =
"Set IR value for specified JTAG register."
6077 .name =
"use_bscan_tunnel",
6078 .handler = riscv_use_bscan_tunnel,
6080 .usage =
"value [type]",
6081 .help =
"Enable or disable use of a BSCAN tunnel to reach DM."
6084 .name =
"set_bscan_tunnel_ir",
6085 .handler = riscv_set_bscan_tunnel_ir,
6088 .help =
"Specify the JTAG TAP IR used to access the bscan tunnel. "
6089 "By default it is 0x23 << (ir_length - 6), which map some "
6090 "Xilinx FPGA (IR USER4)"
6093 .name =
"set_maskisr",
6094 .handler = riscv_set_maskisr,
6096 .help =
"mask riscv interrupts",
6097 .usage =
"['off'|'steponly']",
6100 .name =
"set_ebreakm",
6101 .handler = riscv_set_ebreakm,
6103 .usage =
"[on|off]",
6104 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
6105 "'<target_name> cget -ebreak'"
6108 .name =
"set_ebreaks",
6109 .handler = riscv_set_ebreaks,
6111 .usage =
"[on|off]",
6112 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
6113 "'<target_name> cget -ebreak'"
6116 .name =
"set_ebreaku",
6117 .handler = riscv_set_ebreaku,
6119 .usage =
"[on|off]",
6120 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
6121 "'<target_name> cget -ebreak'"
6125 .handler = riscv_etrigger,
6127 .usage =
"set [vs] [vu] [m] [s] [u] <exception_codes>|clear",
6128 .help =
"Set or clear a single exception trigger."
6132 .handler = riscv_icount,
6134 .usage =
"set [vs] [vu] [m] [s] [u] [pending] <count>|clear",
6135 .help =
"Set or clear a single instruction count trigger."
6139 .handler = riscv_itrigger,
6141 .usage =
"set [vs] [vu] [nmi] [m] [s] [u] <mie_bits>|clear",
6142 .help =
"Set or clear a single interrupt trigger."
6145 .name =
"exec_progbuf",
6146 .handler = riscv_exec_progbuf,
6148 .usage =
"instr1 [instr2 [... instr16]]",
6149 .help =
"Execute a sequence of 32-bit instructions using the program buffer. "
6150 "The final ebreak instruction is added automatically, if needed."
6153 .name =
"set_enable_trigger_feature",
6154 .handler = riscv_set_enable_trigger_feature,
6156 .usage =
"[('eq'|'napot'|'ge_lt'|'all') ('wp'|'none')]",
6157 .help =
"Control whether OpenOCD is allowed to use certain RISC-V trigger features for watchpoints."
6160 .name =
"reserve_trigger",
6161 .handler = handle_reserve_trigger,
6164 .usage =
"[index ('on'|'off')]",
6165 .help =
"Controls which RISC-V triggers shall not be touched by OpenOCD.",
6168 .name =
"virt2phys_mode",
6169 .handler = handle_riscv_virt2phys_mode,
6171 .usage =
"['sw'|'hw'|'off']",
6172 .help =
"Configure the virtual address translation mode: "
6173 "sw - translate vaddr to paddr by manually traversing page tables, "
6174 "hw - translate vaddr to paddr by hardware, "
6175 "off - no address translation."
6178 .name =
"autofence",
6179 .handler = riscv_set_autofence,
6181 .usage =
"[on|off]",
6182 .help =
"When on (default), OpenOCD will automatically execute fence instructions in some situations. "
6183 "When off, users need to take care of memory coherency themselves, for example by using "
6184 "`riscv exec_progbuf` to execute fence or CMO instructions."
6210 .help =
"RISC-V Command Group",
6217 .help =
"ARM Command Group",
6236 return r->data_bits(
target);
6250 *insn_set =
"riscv32";
6254 *insn_set =
"riscv64";
6323 memset(r, 0,
sizeof(*r));
6383 *old_mstatus = current_mstatus;
6398 LOG_TARGET_WARNING(
target,
"OpenOCD might have affected the program when it restored the interrupt bits after single-step.");
6399 LOG_TARGET_WARNING(
target,
"Hint: Use 'riscv set_maskisr off' to prevent OpenOCD from touching mstatus during single-step.");
6426 if (letter >=
'a' && letter <=
'z')
6428 else if (letter >=
'A' && letter <=
'Z')
6433 return misa &
BIT(num);
6468 assert(r->get_hart_state);
6479 return r->halt_reason(
target);
6485 return r->get_progbufsize(
target);
6491 return r->write_progbuf(
target, index, insn);
6497 return r->read_progbuf(
target, index);
6503 return r->execute_progbuf(
target, cmderr);
6509 r->fill_dmi_write(
target, buf, a, d);
6515 r->fill_dmi_read(
target, buf, a);
6521 r->fill_dm_nop(
target, buf);
6527 return r->get_dmi_address_bits(
target);
6541 if (tselect_rb != index)
6554 assert(trigger_tinfo);
6559 if (tinfo == 0 || tinfo & 0x1)
6561 *trigger_tinfo = tinfo;
6567 *trigger_tinfo = 1 <<
type;
6573 bool dmode_is_set =
false;
6578 dmode_is_set =
true;
6613 if (r->triggers_enumerated)
6627 "Assuming that triggers are not implemented.");
6628 r->triggers_enumerated =
true;
6629 r->trigger_count = 0;
6630 free(r->reserved_triggers);
6631 r->reserved_triggers =
NULL;
6649 for (; t <
ARRAY_SIZE(r->trigger_tinfo); ++t) {
6667 t, r->trigger_tinfo[t]);
6685 r->triggers_enumerated =
true;
6686 r->trigger_count = t;
6688 free(r->reserved_triggers);
6689 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
int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Remove argv[0] as wide.
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_jim_configure_group(struct jim_getopt_info *goi, unsigned int *group)
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 enum @128 resume_order
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 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 riscv_wait_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 exit_point, unsigned int timeout_ms, void *arch_info)
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 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.
@ RISCV_CFG_SBA_FLUSH_CACHE
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 int riscv_start_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, void *arch_info)
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 rtt_target_command_handlers[]
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 stldr_func_type type
enum breakpoint_type type
When run_command is called, a new instance will be created on the stack, filled with the proper value...
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
A TCL -ish GetOpt like code.
Name Value Pairs, aka: NVP.
unsigned int ir_length
size of instruction register
struct match_triggers_tdata1_fields::@131 match
struct match_triggers_tdata1_fields::@129 size
struct match_triggers_tdata1_fields::@130 chain
int(* get)(struct reg *reg)
int(* set)(struct reg *reg, uint8_t *buf)
const struct reg_arch_type * type
Architecture info for RISC-V algorithms.
riscv_reg_t saved_gpr[32]
riscv_reg_t saved_mstatus
unsigned int common_magic
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)
#define ERROR_TARGET_INVALID
@ 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
#define ERROR_TARGET_ALGO_EXIT
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