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;
527 #define RISCV_EBREAK_MODE_INVALID -1
530 { .
name =
"exception", .value =
false },
531 { .name =
"halt", .value =
true },
536 { .
name =
"off", .value =
false },
537 { .name =
"on", .value =
true },
538 { .name =
NULL, .value = -1 }
543 if (goi->
argc == 0) {
544 Jim_WrongNumArgs(goi->
interp, 1, goi->
argv - 1,
545 "[?execution_mode?] ?ebreak_action?");
548 struct jim_nvp *common_mode_nvp;
550 &common_mode_nvp) == JIM_OK) {
557 for (
int ebreak_ctl_i = 0; ebreak_ctl_i <
N_RISCV_MODE; ++ebreak_ctl_i)
558 config->dcsr_ebreak_fields[ebreak_ctl_i] = common_mode_nvp->
value;
566 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
594 const char *separator =
"";
597 const char *
const format =
"%s%s %s";
598 const char *
const priv_mode =
601 config->dcsr_ebreak_fields[ebreak_ctl_i])->
name;
603 len += snprintf(
NULL, 0, format, separator, priv_mode,
mode);
605 len += sprintf(
buffer + len, format, separator, priv_mode,
mode);
616 char *str = malloc(len + 1);
618 LOG_ERROR(
"Unable to allocate a string of %d bytes.", len + 1);
622 Jim_SetResultString(interp, str, len);
664 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
"");
682 Jim_SetResultString(goi->
interp,
687 assert(
false &&
"'jim_getopt_nvp' should have returned an error.");
697 info->cmd_ctx = cmd_ctx;
698 info->reset_delays_wait = -1;
707 if (ir_user4_raw == 0) {
730 for (
unsigned int i = 0; i < r->trigger_count; ++i) {
742 free(r->wp_triggers_negative_cache);
759 if (tt &&
info &&
info->version_specific)
768 free(
info->reserved_triggers);
808 bool size_power_of_2 = (
size & (
size - 1)) == 0;
809 bool addr_aligned = (
addr & (
size - 1)) == 0;
810 return size > 1 && size_power_of_2 && addr_aligned;
820 unsigned int num_found = 0;
821 unsigned int num_required = chained ? 2 : 1;
823 for (
unsigned int i = *idx; i < r->trigger_count; i++) {
824 if (r->trigger_unique_id[i] == -1) {
825 if (r->trigger_tinfo[i] & (1 <<
type)) {
827 if (num_required == num_found) {
829 *idx = i - (num_required - 1);
831 "%d trigger(s) of type %d found on index %u, "
833 num_required,
type, *idx,
834 chained ?
"true" :
"false");
853 for (
unsigned int i = 0; i < r->trigger_count; i++) {
854 if (r->trigger_unique_id[i] == unique_id)
862 const unsigned int riscv_reg_bits =
sizeof(
riscv_reg_t) * CHAR_BIT;
863 for (
unsigned int i = 0; i < riscv_reg_bits; i++) {
864 if ((1 & (
reg >> i)) == 0)
867 return riscv_reg_bits;
873 assert(r->reserved_triggers);
874 assert(idx < r->trigger_count);
875 if (r->reserved_triggers[idx]) {
877 "Trigger %u is reserved by 'reserve_trigger' command.", idx);
912 const bool tdata1_config_denied = (tdata1 & ~tdata1_ignore_mask) != (tdata1_rb & ~tdata1_ignore_mask);
917 bool unsupported_napot_range =
false;
919 if (!tdata1_config_denied) {
921 if (is_mcontrol && is_napot_match) {
924 if (maskmax_value < napot_size)
925 unsupported_napot_range =
true;
929 const bool tdata2_config_denied = tdata2 != tdata2_rb;
930 if (tdata1_config_denied || tdata2_config_denied || unsupported_napot_range) {
933 if (tdata1_config_denied)
935 "After writing 0x%" PRIx64
" to tdata1 it contains 0x%" PRIx64,
938 if (tdata2_config_denied)
940 "After writing 0x%" PRIx64
" to tdata2 it contains 0x%" PRIx64,
943 if (unsupported_napot_range)
945 "The requested NAPOT match range (tdata2=0x%" PRIx64
") exceeds maskmax_value=0x%" PRIx64,
946 tdata2, maskmax_value);
963 const uint32_t bpcontrol_x = 1<<0;
964 const uint32_t bpcontrol_w = 1<<1;
965 const uint32_t bpcontrol_r = 1<<2;
966 const uint32_t bpcontrol_u = 1<<3;
967 const uint32_t bpcontrol_s = 1<<4;
968 const uint32_t bpcontrol_h = 1<<5;
969 const uint32_t bpcontrol_m = 1<<6;
970 const uint32_t bpcontrol_bpmatch = 0xf << 7;
971 const uint32_t bpcontrol_bpaction = 0xff << 11;
973 unsigned int idx = 0;
980 if (tdata1 & (bpcontrol_r | bpcontrol_w | bpcontrol_x)) {
989 tdata1 =
set_field(tdata1, bpcontrol_u, !!(r->misa &
BIT(
'U' -
'A')));
990 tdata1 =
set_field(tdata1, bpcontrol_s, !!(r->misa &
BIT(
'S' -
'A')));
991 tdata1 =
set_field(tdata1, bpcontrol_h, !!(r->misa &
BIT(
'H' -
'A')));
992 tdata1 =
set_field(tdata1, bpcontrol_m, 1);
993 tdata1 =
set_field(tdata1, bpcontrol_bpaction, 0);
994 tdata1 =
set_field(tdata1, bpcontrol_bpmatch, 0);
1033 if (elem_2->
tdata2 == find_tdata2)
1043 if (elem_1->
tdata1 == find_tdata1)
1053 r->wp_triggers_negative_cache = (
struct list_head *)calloc(r->trigger_count,
1055 for (
unsigned int i = 0; i < r->trigger_count; ++i)
1118 for (
unsigned int idx = 0;
1146 for (
unsigned int idx = 0;
1275 if (r->wp_allow_napot_trigger) {
1287 "Use 'riscv set_enable_trigger_feature napot wp' to enable it.");
1291 if (r->wp_allow_ge_lt_trigger) {
1323 "Use 'riscv set_enable_trigger_feature ge_lt wp' to enable it.");
1327 if (r->wp_allow_equality_match_trigger) {
1339 "Use 'riscv set_enable_trigger_feature eq wp' to enable it.");
1344 ", but may not match accesses at addresses in the inclusive range from 0x%"
1348 if (!
info->range_trigger_fallback_encountered)
1353 "Could not set a trigger that will match a whole address range. "
1354 "As a fallback, this trigger (and maybe others) will only match "
1355 "against the first address of the range.");
1356 info->range_trigger_fallback_encountered =
true;
1388 bool m,
bool s,
bool u,
bool pending,
unsigned int count,
1408 unsigned int idx = 0;
1415 r->trigger_unique_id[idx] = unique_id;
1420 bool nmi,
bool m,
bool s,
bool u,
riscv_reg_t interrupts,
1441 unsigned int idx = 0;
1448 r->trigger_unique_id[idx] = unique_id;
1453 bool m,
bool s,
bool u,
riscv_reg_t exception_codes,
1471 tdata2 = exception_codes;
1473 unsigned int idx = 0;
1480 r->trigger_unique_id[idx] = unique_id;
1523 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1526 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1528 if (access_size <=
size &&
address % access_size == 0)
1532 unsigned int offset_head =
address % access_size;
1533 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1534 uint8_t helper_buf[n_blocks * access_size];
1541 memcpy(helper_buf + offset_head,
buffer,
size);
1550 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1553 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1555 if (access_size <=
size &&
address % access_size == 0)
1559 unsigned int offset_head =
address % access_size;
1560 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1561 uint8_t helper_buf[n_blocks * access_size];
1568 memcpy(
buffer, helper_buf + offset_head,
size);
1581 unsigned int preferred_size =
size;
1582 while (
address % preferred_size != 0)
1583 preferred_size /= 2;
1591 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1592 if (access_size == preferred_size)
1613 unsigned int preferred_size =
size;
1614 while (
address % preferred_size != 0)
1615 preferred_size /= 2;
1623 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1624 if (access_size == preferred_size)
1661 uint8_t buff[4] = { 0 };
1700 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1701 if (r->trigger_unique_id[i] ==
unique_id) {
1704 r->trigger_unique_id[i] = -1;
1712 "Couldn't find the hardware resources used by hardware trigger.");
1814 const uint32_t hit_info = (hit1 << 1) | hit0;
1837 for (uint64_t i = 0; i <
ARRAY_SIZE(tdata1_tests); ++i) {
1842 if (tdata1_test_rb == tdata1_tests[i]) {
1859 bool *need_single_step)
1867 assert(need_single_step);
1868 *need_single_step =
false;
1875 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1876 if (r->trigger_unique_id[i] == -1)
1887 uint64_t hit_mask = 0;
1894 *need_single_step =
true;
1899 *need_single_step =
true;
1907 *need_single_step =
true;
1926 if (tdata1 & hit_mask) {
1928 ") has hit bit set. (need_single_step=%s)",
1929 i, r->trigger_unique_id[i], (*need_single_step) ?
"yes" :
"no");
1951 uint16_t offset_4to2and7to6_bits =
1953 uint16_t offset_4to2_bits = offset_4to2and7to6_bits >> 2;
1954 uint16_t offset_7to6_bits = offset_4to2and7to6_bits & 0x3;
1956 return (offset_4to2_bits << 2) + (offset_5_bit << 5)
1957 + (offset_7to6_bits << 6);
1963 uint16_t offset_4to3and8to6_bits =
1965 uint16_t offset_4to3_bits = offset_4to3and8to6_bits >> 3;
1966 uint16_t offset_8to6_bits = offset_4to3and8to6_bits & 0x7;
1968 return (offset_4to3_bits << 3) + (offset_5_bit << 5)
1969 + (offset_8to6_bits << 6);
1975 uint16_t offset_5to2and7to6_bits =
1977 uint16_t offset_5to2_bits = offset_5to2and7to6_bits >> 2;
1978 uint16_t offset_7to6_bits = offset_5to2and7to6_bits & 0x3;
1979 return (offset_5to2_bits << 2) + (offset_7to6_bits << 6);
1985 uint16_t offset_5to3and8to6_bits =
1987 uint16_t offset_5to3_bits = offset_5to3and8to6_bits >> 3;
1988 uint16_t offset_8to6_bits = offset_5to3and8to6_bits & 0x7;
1989 return (offset_5to3_bits << 3) + (offset_8to6_bits << 6);
1996 uint16_t offset_2_bit = offset_2and6_bits >> 1;
1997 uint16_t offset_6_bit = offset_2and6_bits & 0x1;
1999 return (offset_2_bit << 2) + (offset_5to3_bits << 3) + (offset_6_bit << 6);
2007 return (offset_5to3_bits << 3) + (offset_7to6_bits << 6);
2014 uint16_t offset_5to4and8_bits =
2016 uint16_t offset_5to4_bits = offset_5to4and8_bits >> 1;
2017 uint16_t offset_8_bit = offset_5to4and8_bits & 0x1;
2018 return (offset_5to4_bits << 4) + (offset_7to6_bits << 6)
2019 + (offset_8_bit << 8);
2025 uint16_t offset_4and9to6_bits =
2027 uint16_t offset_4_bit = offset_4and9to6_bits >> 4;
2028 uint16_t offset_9to6_bits = offset_4and9to6_bits & 0xf;
2030 return (offset_4_bit << 4) + (offset_5_bit << 5) + (offset_9to6_bits << 6);
2036 uint16_t offset_5to4and9to6_bits =
2038 uint16_t offset_5to4_biits = offset_5to4and9to6_bits >> 4;
2039 uint16_t offset_9to6_bits = offset_5to4and9to6_bits & 0xf;
2040 return (offset_5to4_biits << 4) + (offset_9to6_bits << 6);
2058 if ((instruction & 0x03) < 0x03) {
2099 " store", instruction);
2213 " store", instruction);
2242 "The code points with rd = x0 are reserved for C.LWSP");
2252 "The code points with rd = x0 are reserved for C.LDSP");
2258 "have the \"F\" extension");
2269 "The code points with rd = x0 are reserved for C.LQSP");
2275 "have the \"D\" extension");
2290 "have the \"F\" extension");
2301 "have the \"D\" extension");
2316 "have the \"F\" extension");
2327 "have the \"D\" extension");
2342 "have the \"F\" extension");
2353 "have the \"D\" extension");
2362 " store", instruction);
2393 if (wp->unique_id == r->trigger_hit) {
2394 *hit_watchpoint = wp;
2402 const uint8_t
length = 4;
2415 for (
int i = 0; i <
length; i++) {
2417 instruction += (
buffer[i] << 8 * i);
2432 mem_addr += memoffset;
2445 if (mem_addr >= wp->
address &&
2447 *hit_watchpoint = wp;
2450 is_load ?
"Load from" :
"Store to", mem_addr,
2452 "read" : (wp->
rw ==
WPT_WRITE ?
"write" :
"access")),
2470 bool handle_breakpoints)
2486 handle_breakpoints ?
"true" :
"false");
2487 if (!r->get_hart_state)
2498 handle_breakpoints,
true );
2512 uint32_t dtmcontrol;
2523 info->dtm_version = dtm_version;
2536 if (
info->dtm_version != dtm_version) {
2560 if (!r->get_hart_state)
2578 if (bp->type ==
BKPT_HARD && bp->is_set && bp->address == dpc) {
2582 "can't derive debug reason for context-aware breakpoint: "
2584 ", asid = %" PRIx32
", linked = %d",
2585 bp->unique_id, bp->address, bp->asid, bp->linked_brp);
2599 r->trigger_hit = -1;
2600 r->need_single_step =
false;
2601 switch (halt_reason) {
2618 "Active hit bit is detected, trying to find trigger owner.");
2620 if (bp->unique_id == r->trigger_hit) {
2623 "Breakpoint with unique_id = %" PRIu32
" owns the trigger.",
2631 if (wp->unique_id == r->trigger_hit) {
2634 "Watchpoint with unique_id = %" PRIu32
" owns the trigger.",
2641 "No trigger hit found, deriving debug reason without it.");
2714 "the target is not halted!");
2729 if (!r->get_hart_state) {
2752 if (!r->get_hart_state) {
2829 memset(wp_is_set,
false, r->trigger_count);
2835 wp_is_set[i] ?
"true" :
"false");
2855 wp_is_set[i] ?
"needs " :
"does not need");
2879 if (handle_breakpoints) {
2890 && r->need_single_step)) {
2897 if (r->get_hart_state) {
2918 if (!r->get_hart_state) {
2939 "BUG: registers should have been flushed by this point.");
2957 bool handle_breakpoints,
2958 bool debug_execution,
2976 list_add(&single_target_entry.
lh, &single_target_list);
2977 targets = &single_target_list;
2982 current ?
"true" :
"false",
2984 handle_breakpoints ?
"true" :
"false",
2985 debug_execution ?
"true" :
"false");
3027 debug_execution,
false);
3046 assert(
false &&
"Unknown privilege mode");
3067 bool halted_in_m = dcsr_prv ==
PRV_M;
3106 }
else if (prv ==
PRV_U) {
3110 "which is a hardware bug", prv, mprv ?
"mstatus.MPP" :
"dcsr.prv");
3209 info->name, ppn,
virtual);
3212 assert(xlen >=
info->va_bits);
3215 if (masked_msbs != 0 && masked_msbs !=
mask) {
3217 "for %s mode.",
virtual,
info->name);
3223 int i =
info->level - 1;
3225 uint64_t vpn =
virtual >>
info->vpn_shift[i];
3226 vpn &=
info->vpn_mask[i];
3237 assert(
info->pte_shift <= 3);
3244 .count = (1 <<
info->pte_shift) / 4,
3246 int retval = r->access_memory(
target, args);
3250 if (
info->pte_shift == 2)
3260 "; mode=%s; i=%d", pte_address, pte,
info->name, i);
3282 while (i < info->level) {
3283 ppn = pte >>
info->pte_ppn_shift[i];
3284 ppn &=
info->pte_ppn_mask[i];
3286 info->pa_ppn_shift[i]);
3287 *physical |= (ppn <<
info->pa_ppn_shift[i]);
3291 info->name,
virtual, *physical);
3317 switch (vsatp_mode) {
3337 "vsatp mode %d is not supported. (vsatp: 0x%" PRIx64
")",
3344 switch (hgatp_mode) {
3364 "hgatp mode %d is not supported. (hgatp: 0x%" PRIx64
")",
3384 virtual, &guest_physical) !=
ERROR_OK)
3387 guest_physical =
virtual;
3397 guest_physical, physical) !=
ERROR_OK)
3400 *physical = guest_physical;
3410 *physical =
virtual;
3420 bool enabled =
false;
3424 *physical =
virtual;
3441 switch (satp_mode) {
3456 " (satp: 0x%" PRIx64
")", satp_value);
3460 " (satp: 0x%" PRIx64
")", satp_value);
3471 uint32_t
size, uint32_t
count,
bool is_write)
3476 if (is_misaligned && crosses_page_boundary) {
3478 " would access an element across page boundary. This is not supported.",
3497 return r->access_memory(
target, args);
3513 return r->access_memory(
target, args);
3521 if (args.
count == 0) {
3523 is_write ?
"write to" :
"read from", args.
address);
3541 "hardware: OpenOCD does not set mstatus.MPV yet. "
3542 "Use 'riscv virt2phys_mode sw'.");
3550 bool mmu_enabled =
false;
3563 uint32_t current_count = 0;
3565 while (current_count < args.
count) {
3576 uint32_t chunk_count =
MIN(args.
count - current_count,
3581 current_access.
address = physical_addr;
3582 current_access.
count = chunk_count;
3592 current_count += chunk_count;
3593 current_address += chunk_count * args.
size;
3630 return "riscv:rv32";
3632 return "riscv:rv64";
3639 struct reg **reg_list[],
int *reg_list_size,
3649 switch (reg_class) {
3651 *reg_list_size = 33;
3661 *reg_list = calloc(*reg_list_size,
sizeof(
struct reg *));
3665 for (
int i = 0; i < *reg_list_size; i++) {
3681 struct reg **reg_list[],
int *reg_list_size,
3689 struct reg **reg_list[],
int *reg_list_size,
3704 semihosting_active ?
" Semihosting is active." :
"");
3710 struct mem_param *mem_params,
int num_reg_params,
3712 target_addr_t exit_point,
unsigned int timeout_ms,
void *arch_info)
3722 for (
int i = 0; i < num_mem_params; i++) {
3728 " size=0x%" PRIx32, mem_params[i].
address, mem_params[i].
size);
3741 uint64_t saved_regs[32];
3742 for (
int i = 0; i < num_reg_params; i++) {
3750 if (r->
size != reg_params[i].
size) {
3752 reg_params[i].reg_name, r->
size, reg_params[i].
size);
3785 if (now -
start > timeout_ms) {
3801 for (
unsigned int i = 0; i <
ARRAY_SIZE(regnums); i++) {
3824 if (exit_point && final_pc != exit_point) {
3835 uint8_t buf[8] = { 0 };
3840 for (
int i = 0; i < num_reg_params; i++) {
3860 for (
int i = 0; i < num_mem_params; i++) {
3864 mem_params[i].
value);
3887 static const uint8_t riscv32_crc_code[] = {
3888 #include "../../../contrib/loaders/checksum/riscv32_crc.inc"
3890 static const uint8_t riscv64_crc_code[] = {
3891 #include "../../../contrib/loaders/checksum/riscv64_crc.inc"
3894 static const uint8_t *crc_code;
3897 unsigned int crc_code_size;
3899 crc_code = riscv32_crc_code;
3900 crc_code_size =
sizeof(riscv32_crc_code);
3902 crc_code = riscv64_crc_code;
3903 crc_code_size =
sizeof(riscv64_crc_code);
3906 if (
count < crc_code_size * 4) {
3930 crc_algorithm->
address, retval);
3941 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
4027 previous_target_state);
4053 if (r->handle_became_halted &&
4054 r->handle_became_halted(
target, previous_riscv_state) !=
ERROR_OK)
4063 r->halted_needs_event_callback =
true;
4077 if (r->handle_became_running &&
4078 r->handle_became_running(
target, previous_riscv_state) !=
ERROR_OK)
4086 if (r->handle_became_unavailable &&
4087 r->handle_became_unavailable(
target, previous_riscv_state) !=
ERROR_OK)
4105 if (!r->sample_buf.buf || !r->sample_config.enabled)
4113 if (r->sample_memory) {
4114 result = r->sample_memory(
target, &r->sample_buf, &r->sample_config,
4122 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
4123 if (r->sample_config.bucket[i].enabled &&
4124 r->sample_buf.used + 1 + r->sample_config.bucket[i].size_bytes < r->sample_buf.size) {
4126 r->sample_buf.buf[r->sample_buf.used] = i;
4128 r->sample_config.bucket[i].address,
4129 r->sample_config.bucket[i].size_bytes, 1,
4130 r->sample_buf.buf + r->sample_buf.used + 1);
4132 r->sample_buf.used += 1 + r->sample_config.bucket[i].size_bytes;
4143 r->sample_config.enabled =
false;
4168 list_add(&single_target_entry.
lh, &single_target_list);
4169 targets = &single_target_list;
4172 unsigned int should_remain_halted = 0;
4173 unsigned int should_resume = 0;
4175 unsigned int running = 0;
4176 unsigned int cause_groups = 0;
4184 info->halted_needs_event_callback =
false;
4193 switch (next_action) {
4202 should_remain_halted++;
4211 should_remain_halted, should_resume);
4212 if (should_remain_halted && should_resume) {
4214 should_remain_halted, should_resume);
4216 if (should_remain_halted) {
4218 should_remain_halted);
4220 }
else if (should_resume) {
4223 }
else if (
halted && running) {
4262 if (
halted == cause_groups) {
4287 if (
info->halted_needs_event_callback) {
4289 info->halted_needs_event_callback =
false;
4331 if (handle_breakpoints) {
4345 bool *wps_to_enable = calloc(r->trigger_count,
sizeof(*wps_to_enable));
4346 if (!wps_to_enable) {
4353 "watchpoints before single-step.");
4354 free(wps_to_enable);
4358 bool success =
true;
4381 "BUG: registers should have been flushed by this point.");
4396 "after single-step.");
4399 free(wps_to_enable);
4408 if (handle_callbacks)
4413 if (handle_callbacks)
4446 LOG_WARNING(
"The command 'riscv set_reset_timeout_sec' is deprecated! Please, use 'riscv set_command_timeout_sec'.");
4466 for (
unsigned int i = 0; i < r->num_enabled_mem_access_methods; i++) {
4470 switch (r->mem_access_methods[i]) {
4491 unsigned int progbuf_cnt = 0;
4492 unsigned int sysbus_cnt = 0;
4493 unsigned int abstract_cnt = 0;
4496 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4497 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0) {
4499 }
else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0) {
4501 }
else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0) {
4505 "must be one of: 'progbuf', 'sysbus' or 'abstract'",
CMD_ARGV[i]);
4509 if (progbuf_cnt > 1 || sysbus_cnt > 1 || abstract_cnt > 1) {
4515 r->num_enabled_mem_access_methods =
CMD_ARGC;
4516 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4517 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0)
4519 else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0)
4521 else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0)
4527 r->mem_access_warn[i] =
true;
4534 LOG_WARNING(
"DEPRECATED! use 'mem_access' not 'set_mem_access'");
4546 while (isspace((
unsigned char)reg_address_str[0]))
4549 bool is_hex_address = strncmp(reg_address_str,
"0x", 2) == 0 ||
4550 strncmp(reg_address_str,
"0X", 2) == 0;
4552 unsigned int scanned_chars;
4553 if (is_hex_address) {
4554 reg_address_str += 2;
4555 if (sscanf(reg_address_str,
"%x%n", reg_addr, &scanned_chars) != 1)
4564 if (reg_address_str[0] ==
'0' && strlen(reg_address_str) > 1)
4566 if (sscanf(reg_address_str,
"%u%n", reg_addr, &scanned_chars) != 1)
4569 return scanned_chars == strlen(reg_address_str);
4573 const char *
reg_type,
unsigned int max_val,
char **
const name_buffer)
4577 for (
char *arg = strtok(args,
","); arg; arg = strtok(
NULL,
",")) {
4578 unsigned int low = 0;
4579 unsigned int high = 0;
4582 char *dash = strchr(arg,
'-');
4583 char *equals = strchr(arg,
'=');
4585 if (!dash && !equals) {
4588 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
4591 }
else if (dash && !equals) {
4595 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4599 const char *high_num_in = dash + 1;
4601 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4606 LOG_ERROR(
"Incorrect range encountered [%u, %u].",
low, high);
4609 }
else if (!dash && equals) {
4613 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4618 const char *
const reg_name_in = equals + 1;
4619 const size_t reg_type_len = strlen(
reg_type);
4621 *name_buffer = calloc(1, strlen(reg_name_in) + reg_type_len + 2);
4622 name = *name_buffer;
4628 name[reg_type_len] =
'_';
4630 unsigned int scanned_chars;
4632 if (sscanf(reg_name_in,
"%[_a-zA-Z0-9]%n", scan_dst, &scanned_chars) != 1 ||
4633 scanned_chars != strlen(reg_name_in)) {
4634 LOG_ERROR(
"Invalid characters in register name '%s'.", reg_name_in);
4638 LOG_ERROR(
"Invalid argument '%s'.", arg);
4644 if (high > max_val) {
4645 LOG_ERROR(
"Cannot expose %s register number 0x%x, maximum allowed value is 0x%x.",
4653 if (entry->
low <= high && low <= entry->high) {
4656 "Register %u has already been exposed previously",
reg_type,
low);
4658 LOG_WARNING(
"Overlapping register ranges - Register range starting from %u overlaps "
4659 "with already exposed register/range at %u.",
low, entry->
low);
4678 *name_buffer =
NULL;
4686 const char *
reg_type,
unsigned int max_val)
4688 char *args = strdup(tcl_arg);
4693 char *name_buffer =
NULL;
4709 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4727 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4745 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4756 unsigned int index = 0;
4774 if (r->authdata_read) {
4789 unsigned int index = 0;
4804 if (!r->authdata_write) {
4809 return r->authdata_write(
target, value, index);
4816 if (!r || !r->get_dmi_address)
4818 return r->get_dmi_address(
target, dm_address);
4850 if (!r->dmi_write) {
4854 const int result = r->dmi_write(
target, dmi_address, value);
4862 const bool progbuf_touched =
4865 const bool dm_deactivated =
4868 if (progbuf_touched || dm_deactivated) {
4869 if (r->invalidate_cached_progbuf) {
4877 r->invalidate_cached_progbuf(
target);
4880 "invalidate_cached_progbuf() is not implemented.");
4891 uint32_t dmi_address;
4907 uint32_t dmi_address, value;
4920 uint32_t dm_address;
4937 uint32_t dm_address, value;
4958 r->reset_delays_wait = wait;
4970 if (!strcmp(
CMD_ARGV[0],
"idcode"))
4972 else if (!strcmp(
CMD_ARGV[0],
"dtmcs"))
4974 else if (!strcmp(
CMD_ARGV[0],
"dmi"))
4987 if (!strcmp(
CMD_ARGV[0],
"normal")) {
4989 }
else if (!strcmp(
CMD_ARGV[0],
"reversed")) {
5001 uint8_t irwidth = 0;
5004 if (CMD_ARGC < 1 || CMD_ARGC > 2)
5019 LOG_INFO(
"Nested Tap based Bscan Tunnel Selected");
5021 LOG_INFO(
"Simple Register based Bscan Tunnel Selected");
5023 LOG_INFO(
"Invalid Tunnel type selected ! : selecting default Nested Tap Type");
5040 LOG_INFO(
"Bscan tunnel IR 0x%x selected", ir_id);
5051 static const struct jim_nvp nvp_maskisr_modes[] = {
5054 { .name =
NULL, .value = -1 },
5091 const char *mode_str;
5103 assert(0 &&
"Unexpected execution mode");
5104 mode_str =
"unexpected";
5109 LOG_WARNING(
"DEPRECATED! use '%s cget -ebreak' not '%s'",
5112 config->dcsr_ebreak_fields[
mode] ?
"on" :
"off");
5120 config->dcsr_ebreak_fields[
mode] = ebreak_ctl;
5184 "doesn't support setting more than one at a time.");
5195 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5198 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5200 else if (!strcmp(
CMD_ARGV[i],
"nmi"))
5202 else if (!strcmp(
CMD_ARGV[i],
"m"))
5204 else if (!strcmp(
CMD_ARGV[i],
"s"))
5206 else if (!strcmp(
CMD_ARGV[i],
"u"))
5211 if (!nmi && interrupts == 0) {
5212 LOG_ERROR(
"Doesn't make sense to set itrigger with "
5213 "mie_bits=0 and without nmi.");
5215 }
else if (!vs && !vu && !m && !s && !u) {
5216 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5217 "least one of vs, vu, m, s, or u.");
5225 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5226 return riscv_clear_trigger(
CMD, ITRIGGER_UNIQUE_ID,
"itrigger");
5229 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5254 "doesn't support setting more than one at a time.");
5262 bool pending =
false;
5263 unsigned int count = 0;
5265 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5268 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5270 else if (!strcmp(
CMD_ARGV[i],
"pending"))
5272 else if (!strcmp(
CMD_ARGV[i],
"m"))
5274 else if (!strcmp(
CMD_ARGV[i],
"s"))
5276 else if (!strcmp(
CMD_ARGV[i],
"u"))
5282 LOG_ERROR(
"Doesn't make sense to set icount trigger with "
5285 }
else if (!vs && !vu && !m && !s && !u) {
5286 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5287 "least one of vs, vu, m, s, or u.");
5295 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5296 return riscv_clear_trigger(
CMD, ICOUNT_UNIQUE_ID,
"icount trigger");
5299 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5324 "doesn't support setting more than one at a time.");
5334 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5337 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5339 else if (!strcmp(
CMD_ARGV[i],
"m"))
5341 else if (!strcmp(
CMD_ARGV[i],
"s"))
5343 else if (!strcmp(
CMD_ARGV[i],
"u"))
5348 if (exception_codes == 0) {
5349 LOG_ERROR(
"Doesn't make sense to set etrigger with "
5350 "exception_codes=0.");
5352 }
else if (!vs && !vu && !m && !s && !u) {
5353 LOG_ERROR(
"Doesn't make sense to set etrigger without at "
5354 "least one of vs, vu, m, s, or u.");
5362 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5363 return riscv_clear_trigger(
CMD, ETRIGGER_UNIQUE_ID,
"etrigger");
5366 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5382 if (CMD_ARGC < 2 || CMD_ARGC > 3)
5409 int result = r->access_memory(
target, args);
5423 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
5424 if (r->sample_config.bucket[i].enabled) {
5426 r->sample_config.bucket[i].address,
5427 r->sample_config.bucket[i].size_bytes);
5440 if (bucket >
ARRAY_SIZE(r->sample_config.bucket)) {
5445 if (!strcmp(
CMD_ARGV[1],
"clear")) {
5446 r->sample_config.bucket[bucket].enabled =
false;
5452 if (r->sample_config.bucket[bucket].size_bytes != 4 &&
5453 r->sample_config.bucket[bucket].size_bytes != 8) {
5458 r->sample_config.bucket[bucket].size_bytes = 4;
5461 r->sample_config.bucket[bucket].enabled =
true;
5464 if (!r->sample_buf.buf) {
5465 r->sample_buf.size = 1024 * 1024;
5466 r->sample_buf.buf = malloc(r->sample_buf.size);
5470 r->sample_buf.used = 0;
5472 r->sample_config.enabled =
true;
5485 bool base64 =
false;
5487 if (!strcmp(
CMD_ARGV[0],
"base64")) {
5498 r->sample_buf.used,
NULL);
5508 while (i < r->sample_buf.used) {
5509 uint8_t
command = r->sample_buf.buf[i++];
5511 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5515 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5520 r->sample_config.bucket[
command].address);
5521 if (r->sample_config.bucket[
command].size_bytes == 4) {
5522 uint32_t value =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5525 }
else if (r->sample_config.bucket[
command].size_bytes == 8) {
5526 uint64_t value =
buf_get_u64(r->sample_buf.buf + i, 0, 64);
5531 r->sample_config.bucket[
command].size_bytes);
5546 r->sample_buf.used = 0;
5551 const char *key,
unsigned int value,
bool is_available)
5554 snprintf(full_key,
sizeof(full_key),
"%s.%s", section, key);
5578 const bool trigger_count_available =
5580 riscv_print_info_line_if_available(
CMD,
"hart",
"trigger_count",
5581 r->trigger_count, trigger_count_available);
5590 if (CMD_ARGC < 1 || CMD_ARGC > 16)
5603 "only supported on v0.13 or v1.0 targets.");
5609 "program buffer, target not halted.");
5622 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
5650 bool enable_for_wp =
true;
5653 enable_for_wp =
true;
5654 else if (!strcmp(
CMD_ARGV[1],
"none"))
5655 enable_for_wp =
false;
5660 r->wp_allow_equality_match_trigger = enable_for_wp;
5661 r->wp_allow_napot_trigger = enable_for_wp;
5662 r->wp_allow_ge_lt_trigger = enable_for_wp;
5663 }
else if (!strcmp(
CMD_ARGV[0],
"eq")) {
5664 r->wp_allow_equality_match_trigger = enable_for_wp;
5665 }
else if (!strcmp(
CMD_ARGV[0],
"napot")) {
5666 r->wp_allow_napot_trigger = enable_for_wp;
5667 }
else if (!strcmp(
CMD_ARGV[0],
"ge_lt")) {
5668 r->wp_allow_ge_lt_trigger = enable_for_wp;
5677 "Equality match trigger: for wp (%s)\n"
5678 "NAPOT trigger: for wp (%s)\n"
5679 "ge-lt chained triggers: for wp (%s)",
5680 r->wp_allow_equality_match_trigger ?
"enabled" :
"disabled",
5681 r->wp_allow_napot_trigger ?
"enabled" :
"disabled",
5682 r->wp_allow_ge_lt_trigger ?
"enabled" :
"disabled");
5692 const char *separator =
"";
5693 for (
riscv_reg_t t = 0; t < r->trigger_count; ++t) {
5694 if (r->reserved_triggers[t]) {
5723 if (r->trigger_count == 0) {
5727 if (t >= r->trigger_count) {
5729 " does not exist. There are only %u triggers"
5730 " on the target (with indexes 0 .. %u).",
5731 t, r->trigger_count, r->trigger_count - 1);
5734 if (r->trigger_unique_id[t] != -1) {
5736 " is already in use and can not be reserved.", t);
5775 .
name =
"dump_sample_buf",
5776 .handler = handle_dump_sample_buf_command,
5778 .usage =
"[base64]",
5779 .help =
"Print the contents of the sample buffer, and clear the buffer."
5783 .handler = handle_info,
5786 .help =
"Displays some information OpenOCD detected about the target."
5789 .name =
"memory_sample",
5790 .handler = handle_memory_sample_command,
5792 .usage =
"bucket address|clear [size=4]",
5793 .help =
"Causes OpenOCD to frequently read size bytes at the given address."
5796 .name =
"repeat_read",
5797 .handler = handle_repeat_read,
5799 .usage =
"count address [size=4]",
5800 .help =
"Repeatedly read the value at the given physical address."
5803 .name =
"set_command_timeout_sec",
5804 .handler = riscv_set_command_timeout_sec,
5807 .help =
"Set the wall-clock timeout (in seconds) for individual commands"
5810 .name =
"set_reset_timeout_sec",
5811 .handler = riscv_set_reset_timeout_sec,
5814 .help =
"DEPRECATED. Use 'riscv set_command_timeout_sec' instead."
5817 .name =
"set_mem_access",
5818 .handler = riscv_set_mem_access,
5820 .usage =
"method1 [method2] [method3]",
5821 .help =
"DEPRECATED: Use 'riscv mem_access' instead."
5824 .name =
"mem_access",
5825 .handler = riscv_mem_access,
5827 .usage =
"[method1 [method2 [method3]]]",
5828 .help =
"Configure which memory access methods shall be used and in which order "
5829 "of priority. Method can be one of: 'progbuf', 'sysbus' or 'abstract'."
5832 .name =
"expose_csrs",
5833 .handler = riscv_set_expose_csrs,
5835 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5836 .help =
"Configure a list of inclusive ranges for CSRs to expose in "
5837 "addition to the standard ones. This must be executed before "
5841 .name =
"expose_custom",
5842 .handler = riscv_set_expose_custom,
5844 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5845 .help =
"Configure a list of inclusive ranges for custom registers to "
5846 "expose. custom0 is accessed as abstract register number 0xc000, "
5847 "etc. This must be executed before `init`."
5850 .name =
"hide_csrs",
5851 .handler = riscv_hide_csrs,
5853 .usage =
"{n0|n-m0}[,n1|n-m1]......",
5854 .help =
"Configure a list of inclusive ranges for CSRs to hide from gdb. "
5855 "Hidden registers are still available, but are not listed in "
5856 "gdb target description and `reg` command output. "
5857 "This must be executed before `init`."
5860 .name =
"authdata_read",
5861 .handler = riscv_authdata_read,
5864 .help =
"Return the 32-bit value read from authdata or authdata0 "
5865 "(index=0), or authdata1 (index=1)."
5868 .name =
"authdata_write",
5869 .handler = riscv_authdata_write,
5871 .usage =
"[index] value",
5872 .help =
"Write the 32-bit value to authdata or authdata0 (index=0), "
5873 "or authdata1 (index=1)."
5877 .handler = handle_riscv_dmi_read,
5880 .help =
"Read and return 32-bit value from the given address on the "
5884 .name =
"dmi_write",
5885 .handler = handle_riscv_dmi_write,
5887 .usage =
"address value",
5888 .help =
"Write a 32-bit value to the given address on the RISC-V DMI bus."
5892 .handler = handle_riscv_dm_read,
5894 .usage =
"reg_address",
5895 .help =
"Read and return 32-bit value from a debug module's register "
5900 .handler = handle_riscv_dm_write,
5902 .usage =
"reg_address value",
5903 .help =
"Write a 32-bit value to the debug module's register at "
5907 .name =
"reset_delays",
5908 .handler = riscv_reset_delays,
5911 .help =
"OpenOCD learns how many Run-Test/Idle cycles are required "
5912 "between scans to avoid encountering the target being busy. This "
5913 "command resets those learned values after `wait` scans. It's only "
5914 "useful for testing OpenOCD itself."
5917 .name =
"resume_order",
5918 .handler = riscv_resume_order,
5920 .usage =
"normal|reversed",
5921 .help =
"Choose the order that harts are resumed in when `hasel` is not "
5922 "supported. Normal order is from lowest hart index to highest. "
5923 "Reversed order is from highest hart index to lowest."
5927 .handler = riscv_set_ir,
5929 .usage =
"idcode|dtmcs|dmi value",
5930 .help =
"Set IR value for specified JTAG register."
5933 .name =
"use_bscan_tunnel",
5934 .handler = riscv_use_bscan_tunnel,
5936 .usage =
"value [type]",
5937 .help =
"Enable or disable use of a BSCAN tunnel to reach DM."
5940 .name =
"set_bscan_tunnel_ir",
5941 .handler = riscv_set_bscan_tunnel_ir,
5944 .help =
"Specify the JTAG TAP IR used to access the bscan tunnel. "
5945 "By default it is 0x23 << (ir_length - 6), which map some "
5946 "Xilinx FPGA (IR USER4)"
5949 .name =
"set_maskisr",
5950 .handler = riscv_set_maskisr,
5952 .help =
"mask riscv interrupts",
5953 .usage =
"['off'|'steponly']",
5956 .name =
"set_ebreakm",
5957 .handler = riscv_set_ebreakm,
5959 .usage =
"[on|off]",
5960 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5961 "'<target_name> cget -ebreak'"
5964 .name =
"set_ebreaks",
5965 .handler = riscv_set_ebreaks,
5967 .usage =
"[on|off]",
5968 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5969 "'<target_name> cget -ebreak'"
5972 .name =
"set_ebreaku",
5973 .handler = riscv_set_ebreaku,
5975 .usage =
"[on|off]",
5976 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5977 "'<target_name> cget -ebreak'"
5981 .handler = riscv_etrigger,
5983 .usage =
"set [vs] [vu] [m] [s] [u] <exception_codes>|clear",
5984 .help =
"Set or clear a single exception trigger."
5988 .handler = riscv_icount,
5990 .usage =
"set [vs] [vu] [m] [s] [u] [pending] <count>|clear",
5991 .help =
"Set or clear a single instruction count trigger."
5995 .handler = riscv_itrigger,
5997 .usage =
"set [vs] [vu] [nmi] [m] [s] [u] <mie_bits>|clear",
5998 .help =
"Set or clear a single interrupt trigger."
6001 .name =
"exec_progbuf",
6002 .handler = riscv_exec_progbuf,
6004 .usage =
"instr1 [instr2 [... instr16]]",
6005 .help =
"Execute a sequence of 32-bit instructions using the program buffer. "
6006 "The final ebreak instruction is added automatically, if needed."
6009 .name =
"set_enable_trigger_feature",
6010 .handler = riscv_set_enable_trigger_feature,
6012 .usage =
"[('eq'|'napot'|'ge_lt'|'all') ('wp'|'none')]",
6013 .help =
"Control whether OpenOCD is allowed to use certain RISC-V trigger features for watchpoints."
6016 .name =
"reserve_trigger",
6017 .handler = handle_reserve_trigger,
6020 .usage =
"[index ('on'|'off')]",
6021 .help =
"Controls which RISC-V triggers shall not be touched by OpenOCD.",
6024 .name =
"virt2phys_mode",
6025 .handler = handle_riscv_virt2phys_mode,
6027 .usage =
"['sw'|'hw'|'off']",
6028 .help =
"Configure the virtual address translation mode: "
6029 "sw - translate vaddr to paddr by manually traversing page tables, "
6030 "hw - translate vaddr to paddr by hardware, "
6031 "off - no address translation."
6034 .name =
"autofence",
6035 .handler = riscv_set_autofence,
6037 .usage =
"[on|off]",
6038 .help =
"When on (default), OpenOCD will automatically execute fence instructions in some situations. "
6039 "When off, users need to take care of memory coherency themselves, for example by using "
6040 "`riscv exec_progbuf` to execute fence or CMO instructions."
6066 .help =
"RISC-V Command Group",
6073 .help =
"ARM Command Group",
6089 return r->data_bits(
target);
6103 *insn_set =
"riscv32";
6107 *insn_set =
"riscv64";
6175 memset(r, 0,
sizeof(*r));
6235 *old_mstatus = current_mstatus;
6250 LOG_TARGET_WARNING(
target,
"OpenOCD might have affected the program when it restored the interrupt bits after single-step.");
6251 LOG_TARGET_WARNING(
target,
"Hint: Use 'riscv set_maskisr off' to prevent OpenOCD from touching mstatus during single-step.");
6279 if (letter >=
'a' && letter <=
'z')
6281 else if (letter >=
'A' && letter <=
'Z')
6285 return r->misa &
BIT(num);
6303 assert(r->get_hart_state);
6314 return r->halt_reason(
target);
6320 return r->get_progbufsize(
target);
6326 return r->write_progbuf(
target, index, insn);
6332 return r->read_progbuf(
target, index);
6338 return r->execute_progbuf(
target, cmderr);
6344 r->fill_dmi_write(
target, buf, a, d);
6350 r->fill_dmi_read(
target, buf, a);
6356 r->fill_dm_nop(
target, buf);
6362 return r->get_dmi_address_bits(
target);
6376 if (tselect_rb != index)
6389 assert(trigger_tinfo);
6394 if (tinfo == 0 || tinfo & 0x1)
6396 *trigger_tinfo = tinfo;
6402 *trigger_tinfo = 1 <<
type;
6408 bool dmode_is_set =
false;
6413 dmode_is_set =
true;
6448 if (r->triggers_enumerated)
6462 "Assuming that triggers are not implemented.");
6463 r->triggers_enumerated =
true;
6464 r->trigger_count = 0;
6465 free(r->reserved_triggers);
6466 r->reserved_triggers =
NULL;
6484 for (; t <
ARRAY_SIZE(r->trigger_tinfo); ++t) {
6502 t, r->trigger_tinfo[t]);
6520 r->triggers_enumerated =
true;
6521 r->trigger_count = t;
6523 free(r->reserved_triggers);
6524 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
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)
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