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
165 static const char *
const names[] = {
195 .vpn_shift = {12, 22},
196 .vpn_mask = {0x3ff, 0x3ff},
197 .pte_ppn_shift = {10, 20},
198 .pte_ppn_mask = {0x3ff, 0xfff},
199 .pa_ppn_shift = {12, 22},
200 .pa_ppn_mask = {0x3ff, 0xfff},
208 .vpn_shift = {12, 22},
209 .vpn_mask = {0x3ff, 0xfff},
210 .pte_ppn_shift = {10, 20},
211 .pte_ppn_mask = {0x3ff, 0xfff},
212 .pa_ppn_shift = {12, 22},
213 .pa_ppn_mask = {0x3ff, 0xfff},
221 .vpn_shift = {12, 21, 30},
222 .vpn_mask = {0x1ff, 0x1ff, 0x1ff},
223 .pte_ppn_shift = {10, 19, 28},
224 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
225 .pa_ppn_shift = {12, 21, 30},
226 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
234 .vpn_shift = {12, 21, 30},
235 .vpn_mask = {0x1ff, 0x1ff, 0x7ff},
236 .pte_ppn_shift = {10, 19, 28},
237 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
238 .pa_ppn_shift = {12, 21, 30},
239 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
247 .vpn_shift = {12, 21, 30, 39},
248 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff},
249 .pte_ppn_shift = {10, 19, 28, 37},
250 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
251 .pa_ppn_shift = {12, 21, 30, 39},
252 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
260 .vpn_shift = {12, 21, 30, 39},
261 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x7ff},
262 .pte_ppn_shift = {10, 19, 28, 37},
263 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
264 .pa_ppn_shift = {12, 21, 30, 39},
265 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
273 .vpn_shift = {12, 21, 30, 39, 48},
274 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
275 .pte_ppn_shift = {10, 19, 28, 37, 46},
276 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
277 .pa_ppn_shift = {12, 21, 30, 39, 48},
278 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
286 .vpn_shift = {12, 21, 30, 39, 48},
287 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x7ff},
288 .pte_ppn_shift = {10, 19, 28, 37, 46},
289 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
290 .pa_ppn_shift = {12, 21, 30, 39, 48},
291 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
306 if (r->sample_buf.used + 5 < r->sample_buf.size) {
311 r->sample_buf.buf[r->sample_buf.used++] = now & 0xff;
312 r->sample_buf.buf[r->sample_buf.used++] = (now >> 8) & 0xff;
313 r->sample_buf.buf[r->sample_buf.used++] = (now >> 16) & 0xff;
314 r->sample_buf.buf[r->sample_buf.used++] = (now >> 24) & 0xff;
334 uint8_t tunneled_dr_width[4] = {32};
335 uint8_t out_value[5] = {0};
336 uint8_t in_value[5] = {0};
363 tunneled_dr[2].
out_value = tunneled_dr_width;
390 tunneled_dr[1].
out_value = tunneled_dr_width;
403 LOG_ERROR(
"failed jtag scan: %d", retval);
409 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
431 .in_value = in_ptr ? value :
NULL
440 LOG_ERROR(
"'dtmcs' scan failed on TAP %s, error code = %d",
448 LOG_DEBUG(
"TAP %s: DTMCS: 0x%" PRIx32
" -> 0x%" PRIx32,
465 switch (
info->dtm_version) {
488 config->dcsr_ebreak_fields[i] =
true;
521 #define RISCV_EBREAK_MODE_INVALID -1
524 { .
name =
"exception", .value =
false },
525 { .name =
"halt", .value =
true },
530 { .
name =
"off", .value =
false },
531 { .name =
"on", .value =
true },
532 { .name =
NULL, .value = -1 }
537 if (goi->
argc == 0) {
538 Jim_WrongNumArgs(goi->
interp, 1, goi->
argv - 1,
539 "[?execution_mode?] ?ebreak_action?");
542 struct jim_nvp *common_mode_nvp;
544 &common_mode_nvp) == JIM_OK) {
551 for (
int ebreak_ctl_i = 0; ebreak_ctl_i <
N_RISCV_MODE; ++ebreak_ctl_i)
552 config->dcsr_ebreak_fields[ebreak_ctl_i] = common_mode_nvp->
value;
560 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
588 const char *separator =
"";
591 const char *
const format =
"%s%s %s";
592 const char *
const priv_mode =
595 config->dcsr_ebreak_fields[ebreak_ctl_i])->
name;
597 len += snprintf(
NULL, 0, format, separator, priv_mode,
mode);
599 len += sprintf(
buffer + len, format, separator, priv_mode,
mode);
610 char *str = malloc(len + 1);
612 LOG_ERROR(
"Unable to allocate a string of %d bytes.", len + 1);
616 Jim_SetResultString(interp, str, len);
658 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
"");
676 Jim_SetResultString(goi->
interp,
681 assert(
false &&
"'jim_getopt_nvp' should have returned an error.");
691 info->cmd_ctx = cmd_ctx;
692 info->reset_delays_wait = -1;
701 if (ir_user4_raw == 0) {
724 for (
unsigned int i = 0; i < r->trigger_count; ++i) {
736 free(r->wp_triggers_negative_cache);
753 if (tt &&
info &&
info->version_specific)
762 free(
info->reserved_triggers);
802 bool size_power_of_2 = (
size & (
size - 1)) == 0;
803 bool addr_aligned = (
addr & (
size - 1)) == 0;
804 return size > 1 && size_power_of_2 && addr_aligned;
814 unsigned int num_found = 0;
815 unsigned int num_required = chained ? 2 : 1;
817 for (
unsigned int i = *idx; i < r->trigger_count; i++) {
818 if (r->trigger_unique_id[i] == -1) {
819 if (r->trigger_tinfo[i] & (1 <<
type)) {
821 if (num_required == num_found) {
823 *idx = i - (num_required - 1);
825 "%d trigger(s) of type %d found on index %u, "
827 num_required,
type, *idx,
828 chained ?
"true" :
"false");
847 for (
unsigned int i = 0; i < r->trigger_count; i++) {
848 if (r->trigger_unique_id[i] == unique_id)
856 const unsigned int riscv_reg_bits =
sizeof(
riscv_reg_t) * CHAR_BIT;
857 for (
unsigned int i = 0; i < riscv_reg_bits; i++) {
858 if ((1 & (
reg >> i)) == 0)
861 return riscv_reg_bits;
867 assert(r->reserved_triggers);
868 assert(idx < r->trigger_count);
869 if (r->reserved_triggers[idx]) {
871 "Trigger %u is reserved by 'reserve_trigger' command.", idx);
906 const bool tdata1_config_denied = (tdata1 & ~tdata1_ignore_mask) != (tdata1_rb & ~tdata1_ignore_mask);
911 bool unsupported_napot_range =
false;
913 if (!tdata1_config_denied) {
915 if (is_mcontrol && is_napot_match) {
918 if (maskmax_value < napot_size)
919 unsupported_napot_range =
true;
923 const bool tdata2_config_denied = tdata2 != tdata2_rb;
924 if (tdata1_config_denied || tdata2_config_denied || unsupported_napot_range) {
927 if (tdata1_config_denied)
929 "After writing 0x%" PRIx64
" to tdata1 it contains 0x%" PRIx64,
932 if (tdata2_config_denied)
934 "After writing 0x%" PRIx64
" to tdata2 it contains 0x%" PRIx64,
937 if (unsupported_napot_range)
939 "The requested NAPOT match range (tdata2=0x%" PRIx64
") exceeds maskmax_value=0x%" PRIx64,
940 tdata2, maskmax_value);
957 const uint32_t bpcontrol_x = 1<<0;
958 const uint32_t bpcontrol_w = 1<<1;
959 const uint32_t bpcontrol_r = 1<<2;
960 const uint32_t bpcontrol_u = 1<<3;
961 const uint32_t bpcontrol_s = 1<<4;
962 const uint32_t bpcontrol_h = 1<<5;
963 const uint32_t bpcontrol_m = 1<<6;
964 const uint32_t bpcontrol_bpmatch = 0xf << 7;
965 const uint32_t bpcontrol_bpaction = 0xff << 11;
967 unsigned int idx = 0;
974 if (tdata1 & (bpcontrol_r | bpcontrol_w | bpcontrol_x)) {
983 tdata1 =
set_field(tdata1, bpcontrol_u, !!(r->misa &
BIT(
'U' -
'A')));
984 tdata1 =
set_field(tdata1, bpcontrol_s, !!(r->misa &
BIT(
'S' -
'A')));
985 tdata1 =
set_field(tdata1, bpcontrol_h, !!(r->misa &
BIT(
'H' -
'A')));
986 tdata1 =
set_field(tdata1, bpcontrol_m, 1);
987 tdata1 =
set_field(tdata1, bpcontrol_bpaction, 0);
988 tdata1 =
set_field(tdata1, bpcontrol_bpmatch, 0);
1027 if (elem_2->
tdata2 == find_tdata2)
1037 if (elem_1->
tdata1 == find_tdata1)
1047 r->wp_triggers_negative_cache = (
struct list_head *)calloc(r->trigger_count,
1049 for (
unsigned int i = 0; i < r->trigger_count; ++i)
1112 for (
unsigned int idx = 0;
1140 for (
unsigned int idx = 0;
1269 if (r->wp_allow_napot_trigger) {
1281 "Use 'riscv set_enable_trigger_feature napot wp' to enable it.");
1285 if (r->wp_allow_ge_lt_trigger) {
1317 "Use 'riscv set_enable_trigger_feature ge_lt wp' to enable it.");
1321 if (r->wp_allow_equality_match_trigger) {
1333 "Use 'riscv set_enable_trigger_feature eq wp' to enable it.");
1338 ", but may not match accesses at addresses in the inclusive range from 0x%"
1342 if (!
info->range_trigger_fallback_encountered)
1347 "Could not set a trigger that will match a whole address range. "
1348 "As a fallback, this trigger (and maybe others) will only match "
1349 "against the first address of the range.");
1350 info->range_trigger_fallback_encountered =
true;
1382 bool m,
bool s,
bool u,
bool pending,
unsigned int count,
1402 unsigned int idx = 0;
1409 r->trigger_unique_id[idx] = unique_id;
1414 bool nmi,
bool m,
bool s,
bool u,
riscv_reg_t interrupts,
1435 unsigned int idx = 0;
1442 r->trigger_unique_id[idx] = unique_id;
1447 bool m,
bool s,
bool u,
riscv_reg_t exception_codes,
1465 tdata2 = exception_codes;
1467 unsigned int idx = 0;
1474 r->trigger_unique_id[idx] = unique_id;
1517 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1520 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1522 if (access_size <=
size &&
address % access_size == 0)
1526 unsigned int offset_head =
address % access_size;
1527 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1528 uint8_t helper_buf[n_blocks * access_size];
1535 memcpy(helper_buf + offset_head,
buffer,
size);
1544 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1547 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1549 if (access_size <=
size &&
address % access_size == 0)
1553 unsigned int offset_head =
address % access_size;
1554 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1555 uint8_t helper_buf[n_blocks * access_size];
1562 memcpy(
buffer, helper_buf + offset_head,
size);
1575 unsigned int preferred_size =
size;
1576 while (
address % preferred_size != 0)
1577 preferred_size /= 2;
1585 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1586 if (access_size == preferred_size)
1607 unsigned int preferred_size =
size;
1608 while (
address % preferred_size != 0)
1609 preferred_size /= 2;
1617 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1618 if (access_size == preferred_size)
1655 uint8_t buff[4] = { 0 };
1694 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1695 if (r->trigger_unique_id[i] ==
unique_id) {
1698 r->trigger_unique_id[i] = -1;
1706 "Couldn't find the hardware resources used by hardware trigger.");
1808 const uint32_t hit_info = (hit1 << 1) | hit0;
1831 for (uint64_t i = 0; i <
ARRAY_SIZE(tdata1_tests); ++i) {
1836 if (tdata1_test_rb == tdata1_tests[i]) {
1853 bool *need_single_step)
1861 assert(need_single_step);
1862 *need_single_step =
false;
1869 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1870 if (r->trigger_unique_id[i] == -1)
1881 uint64_t hit_mask = 0;
1888 *need_single_step =
true;
1893 *need_single_step =
true;
1901 *need_single_step =
true;
1920 if (tdata1 & hit_mask) {
1922 ") has hit bit set. (need_single_step=%s)",
1923 i, r->trigger_unique_id[i], (*need_single_step) ?
"yes" :
"no");
1945 uint16_t offset_4to2and7to6_bits =
1947 uint16_t offset_4to2_bits = offset_4to2and7to6_bits >> 2;
1948 uint16_t offset_7to6_bits = offset_4to2and7to6_bits & 0x3;
1950 return (offset_4to2_bits << 2) + (offset_5_bit << 5)
1951 + (offset_7to6_bits << 6);
1957 uint16_t offset_4to3and8to6_bits =
1959 uint16_t offset_4to3_bits = offset_4to3and8to6_bits >> 3;
1960 uint16_t offset_8to6_bits = offset_4to3and8to6_bits & 0x7;
1962 return (offset_4to3_bits << 3) + (offset_5_bit << 5)
1963 + (offset_8to6_bits << 6);
1969 uint16_t offset_5to2and7to6_bits =
1971 uint16_t offset_5to2_bits = offset_5to2and7to6_bits >> 2;
1972 uint16_t offset_7to6_bits = offset_5to2and7to6_bits & 0x3;
1973 return (offset_5to2_bits << 2) + (offset_7to6_bits << 6);
1979 uint16_t offset_5to3and8to6_bits =
1981 uint16_t offset_5to3_bits = offset_5to3and8to6_bits >> 3;
1982 uint16_t offset_8to6_bits = offset_5to3and8to6_bits & 0x7;
1983 return (offset_5to3_bits << 3) + (offset_8to6_bits << 6);
1990 uint16_t offset_2_bit = offset_2and6_bits >> 1;
1991 uint16_t offset_6_bit = offset_2and6_bits & 0x1;
1993 return (offset_2_bit << 2) + (offset_5to3_bits << 3) + (offset_6_bit << 6);
2001 return (offset_5to3_bits << 3) + (offset_7to6_bits << 6);
2008 uint16_t offset_5to4and8_bits =
2010 uint16_t offset_5to4_bits = offset_5to4and8_bits >> 1;
2011 uint16_t offset_8_bit = offset_5to4and8_bits & 0x1;
2012 return (offset_5to4_bits << 4) + (offset_7to6_bits << 6)
2013 + (offset_8_bit << 8);
2019 uint16_t offset_4and9to6_bits =
2021 uint16_t offset_4_bit = offset_4and9to6_bits >> 4;
2022 uint16_t offset_9to6_bits = offset_4and9to6_bits & 0xf;
2024 return (offset_4_bit << 4) + (offset_5_bit << 5) + (offset_9to6_bits << 6);
2030 uint16_t offset_5to4and9to6_bits =
2032 uint16_t offset_5to4_biits = offset_5to4and9to6_bits >> 4;
2033 uint16_t offset_9to6_bits = offset_5to4and9to6_bits & 0xf;
2034 return (offset_5to4_biits << 4) + (offset_9to6_bits << 6);
2052 if ((instruction & 0x03) < 0x03) {
2093 " store", instruction);
2207 " store", instruction);
2236 "The code points with rd = x0 are reserved for C.LWSP");
2246 "The code points with rd = x0 are reserved for C.LDSP");
2252 "have the \"F\" extension");
2263 "The code points with rd = x0 are reserved for C.LQSP");
2269 "have the \"D\" extension");
2284 "have the \"F\" extension");
2295 "have the \"D\" extension");
2310 "have the \"F\" extension");
2321 "have the \"D\" extension");
2336 "have the \"F\" extension");
2347 "have the \"D\" extension");
2356 " store", instruction);
2387 if (wp->unique_id == r->trigger_hit) {
2388 *hit_watchpoint = wp;
2396 const uint8_t
length = 4;
2409 for (
int i = 0; i <
length; i++) {
2411 instruction += (
buffer[i] << 8 * i);
2426 mem_addr += memoffset;
2439 if (mem_addr >= wp->
address &&
2441 *hit_watchpoint = wp;
2444 is_load ?
"Load from" :
"Store to", mem_addr,
2446 "read" : (wp->
rw ==
WPT_WRITE ?
"write" :
"access")),
2464 bool handle_breakpoints)
2480 handle_breakpoints ?
"true" :
"false");
2481 if (!r->get_hart_state)
2492 handle_breakpoints,
true );
2506 uint32_t dtmcontrol;
2517 info->dtm_version = dtm_version;
2530 if (
info->dtm_version != dtm_version) {
2554 if (!r->get_hart_state)
2572 if (bp->type ==
BKPT_HARD && bp->is_set && bp->address == dpc) {
2576 "can't derive debug reason for context-aware breakpoint: "
2578 ", asid = %" PRIx32
", linked = %d",
2579 bp->unique_id, bp->address, bp->asid, bp->linked_brp);
2593 r->trigger_hit = -1;
2594 r->need_single_step =
false;
2595 switch (halt_reason) {
2612 "Active hit bit is detected, trying to find trigger owner.");
2614 if (bp->unique_id == r->trigger_hit) {
2617 "Breakpoint with unique_id = %" PRIu32
" owns the trigger.",
2625 if (wp->unique_id == r->trigger_hit) {
2628 "Watchpoint with unique_id = %" PRIu32
" owns the trigger.",
2635 "No trigger hit found, deriving debug reason without it.");
2708 "the target is not halted!");
2723 if (!r->get_hart_state) {
2746 if (!r->get_hart_state) {
2823 memset(wp_is_set,
false, r->trigger_count);
2829 wp_is_set[i] ?
"true" :
"false");
2849 wp_is_set[i] ?
"needs " :
"does not need");
2873 if (handle_breakpoints) {
2884 && r->need_single_step)) {
2891 if (r->get_hart_state) {
2912 if (!r->get_hart_state) {
2933 "BUG: registers should have been flushed by this point.");
2951 bool handle_breakpoints,
2952 bool debug_execution,
2970 list_add(&single_target_entry.
lh, &single_target_list);
2971 targets = &single_target_list;
2976 current ?
"true" :
"false",
2978 handle_breakpoints ?
"true" :
"false",
2979 debug_execution ?
"true" :
"false");
3021 debug_execution,
false);
3103 if (effective_mode ==
PRV_M) {
3137 info->name, ppn,
virtual);
3140 assert(xlen >=
info->va_bits);
3143 if (masked_msbs != 0 && masked_msbs !=
mask) {
3145 "for %s mode.",
virtual,
info->name);
3151 int i =
info->level - 1;
3153 uint64_t vpn =
virtual >>
info->vpn_shift[i];
3154 vpn &=
info->vpn_mask[i];
3165 assert(
info->pte_shift <= 3);
3171 .count = (1 <<
info->pte_shift) / 4,
3173 int retval = r->access_memory(
target, args);
3177 if (
info->pte_shift == 2)
3187 "; mode=%s; i=%d", pte_address, pte,
info->name, i);
3209 while (i < info->level) {
3210 ppn = pte >>
info->pte_ppn_shift[i];
3211 ppn &=
info->pte_ppn_mask[i];
3213 info->pa_ppn_shift[i]);
3214 *physical |= (ppn <<
info->pa_ppn_shift[i]);
3218 info->name,
virtual, *physical);
3244 switch (vsatp_mode) {
3264 "vsatp mode %d is not supported. (vsatp: 0x%" PRIx64
")",
3271 switch (hgatp_mode) {
3291 "hgatp mode %d is not supported. (hgatp: 0x%" PRIx64
")",
3311 virtual, &guest_physical) !=
ERROR_OK)
3314 guest_physical =
virtual;
3324 guest_physical, physical) !=
ERROR_OK)
3327 *physical = guest_physical;
3339 *physical =
virtual;
3362 switch (satp_mode) {
3377 " (satp: 0x%" PRIx64
")", satp_value);
3381 " (satp: 0x%" PRIx64
")", satp_value);
3392 uint32_t
size, uint32_t
count,
bool is_write)
3397 if (is_misaligned && crosses_page_boundary) {
3399 " would access an element across page boundary. This is not supported.",
3417 return r->access_memory(
target, args);
3432 return r->access_memory(
target, args);
3440 if (args.
count == 0) {
3442 is_write ?
"write to" :
"read from", args.
address);
3453 return r->access_memory(
target, args);
3460 uint32_t current_count = 0;
3462 while (current_count < args.
count) {
3473 uint32_t chunk_count =
MIN(args.
count - current_count,
3478 current_access.
address = physical_addr;
3479 current_access.
count = chunk_count;
3485 result = r->access_memory(
target, current_access);
3489 current_count += chunk_count;
3490 current_address += chunk_count * args.
size;
3527 return "riscv:rv32";
3529 return "riscv:rv64";
3536 struct reg **reg_list[],
int *reg_list_size,
3546 switch (reg_class) {
3548 *reg_list_size = 33;
3558 *reg_list = calloc(*reg_list_size,
sizeof(
struct reg *));
3562 for (
int i = 0; i < *reg_list_size; i++) {
3578 struct reg **reg_list[],
int *reg_list_size,
3586 struct reg **reg_list[],
int *reg_list_size,
3601 semihosting_active ?
" Semihosting is active." :
"");
3607 struct mem_param *mem_params,
int num_reg_params,
3609 target_addr_t exit_point,
unsigned int timeout_ms,
void *arch_info)
3619 for (
int i = 0; i < num_mem_params; i++) {
3625 " size=0x%" PRIx32, mem_params[i].
address, mem_params[i].
size);
3638 uint64_t saved_regs[32];
3639 for (
int i = 0; i < num_reg_params; i++) {
3647 if (r->
size != reg_params[i].
size) {
3649 reg_params[i].reg_name, r->
size, reg_params[i].
size);
3682 if (now -
start > timeout_ms) {
3698 for (
unsigned int i = 0; i <
ARRAY_SIZE(regnums); i++) {
3721 if (exit_point && final_pc != exit_point) {
3732 uint8_t buf[8] = { 0 };
3737 for (
int i = 0; i < num_reg_params; i++) {
3757 for (
int i = 0; i < num_mem_params; i++) {
3761 mem_params[i].
value);
3784 static const uint8_t riscv32_crc_code[] = {
3785 #include "../../../contrib/loaders/checksum/riscv32_crc.inc"
3787 static const uint8_t riscv64_crc_code[] = {
3788 #include "../../../contrib/loaders/checksum/riscv64_crc.inc"
3791 static const uint8_t *crc_code;
3794 unsigned int crc_code_size;
3796 crc_code = riscv32_crc_code;
3797 crc_code_size =
sizeof(riscv32_crc_code);
3799 crc_code = riscv64_crc_code;
3800 crc_code_size =
sizeof(riscv64_crc_code);
3803 if (
count < crc_code_size * 4) {
3827 crc_algorithm->
address, retval);
3838 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
3924 previous_target_state);
3950 if (r->handle_became_halted &&
3951 r->handle_became_halted(
target, previous_riscv_state) !=
ERROR_OK)
3960 r->halted_needs_event_callback =
true;
3974 if (r->handle_became_running &&
3975 r->handle_became_running(
target, previous_riscv_state) !=
ERROR_OK)
3983 if (r->handle_became_unavailable &&
3984 r->handle_became_unavailable(
target, previous_riscv_state) !=
ERROR_OK)
4002 if (!r->sample_buf.buf || !r->sample_config.enabled)
4010 if (r->sample_memory) {
4011 result = r->sample_memory(
target, &r->sample_buf, &r->sample_config,
4019 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
4020 if (r->sample_config.bucket[i].enabled &&
4021 r->sample_buf.used + 1 + r->sample_config.bucket[i].size_bytes < r->sample_buf.size) {
4023 r->sample_buf.buf[r->sample_buf.used] = i;
4025 r->sample_config.bucket[i].address,
4026 r->sample_config.bucket[i].size_bytes, 1,
4027 r->sample_buf.buf + r->sample_buf.used + 1);
4029 r->sample_buf.used += 1 + r->sample_config.bucket[i].size_bytes;
4040 r->sample_config.enabled =
false;
4065 list_add(&single_target_entry.
lh, &single_target_list);
4066 targets = &single_target_list;
4069 unsigned int should_remain_halted = 0;
4070 unsigned int should_resume = 0;
4072 unsigned int running = 0;
4073 unsigned int cause_groups = 0;
4081 info->halted_needs_event_callback =
false;
4090 switch (next_action) {
4099 should_remain_halted++;
4108 should_remain_halted, should_resume);
4109 if (should_remain_halted && should_resume) {
4111 should_remain_halted, should_resume);
4113 if (should_remain_halted) {
4115 should_remain_halted);
4117 }
else if (should_resume) {
4120 }
else if (
halted && running) {
4159 if (
halted == cause_groups) {
4184 if (
info->halted_needs_event_callback) {
4186 info->halted_needs_event_callback =
false;
4228 if (handle_breakpoints) {
4242 bool *wps_to_enable = calloc(r->trigger_count,
sizeof(*wps_to_enable));
4243 if (!wps_to_enable) {
4250 "watchpoints before single-step.");
4251 free(wps_to_enable);
4255 bool success =
true;
4278 "BUG: registers should have been flushed by this point.");
4293 "after single-step.");
4296 free(wps_to_enable);
4305 if (handle_callbacks)
4310 if (handle_callbacks)
4343 LOG_WARNING(
"The command 'riscv set_reset_timeout_sec' is deprecated! Please, use 'riscv set_command_timeout_sec'.");
4361 int progbuf_cnt = 0;
4363 int abstract_cnt = 0;
4372 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4373 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0) {
4375 }
else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0) {
4377 }
else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0) {
4381 "Must be one of: 'progbuf', 'sysbus' or 'abstract'.",
CMD_ARGV[i]);
4385 if (progbuf_cnt > 1 || sysbus_cnt > 1 || abstract_cnt > 1) {
4386 LOG_ERROR(
"Syntax error - duplicate arguments to `riscv set_mem_access`.");
4391 r->num_enabled_mem_access_methods =
CMD_ARGC;
4392 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4393 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0)
4395 else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0)
4397 else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0)
4403 r->mem_access_warn[i] =
true;
4413 while (isspace((
unsigned char)reg_address_str[0]))
4416 bool is_hex_address = strncmp(reg_address_str,
"0x", 2) == 0 ||
4417 strncmp(reg_address_str,
"0X", 2) == 0;
4419 unsigned int scanned_chars;
4420 if (is_hex_address) {
4421 reg_address_str += 2;
4422 if (sscanf(reg_address_str,
"%x%n", reg_addr, &scanned_chars) != 1)
4431 if (reg_address_str[0] ==
'0' && strlen(reg_address_str) > 1)
4433 if (sscanf(reg_address_str,
"%u%n", reg_addr, &scanned_chars) != 1)
4436 return scanned_chars == strlen(reg_address_str);
4440 const char *
reg_type,
unsigned int max_val,
char **
const name_buffer)
4444 for (
char *arg = strtok(args,
","); arg; arg = strtok(
NULL,
",")) {
4445 unsigned int low = 0;
4446 unsigned int high = 0;
4449 char *dash = strchr(arg,
'-');
4450 char *equals = strchr(arg,
'=');
4452 if (!dash && !equals) {
4455 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
4458 }
else if (dash && !equals) {
4462 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4466 const char *high_num_in = dash + 1;
4468 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4473 LOG_ERROR(
"Incorrect range encountered [%u, %u].",
low, high);
4476 }
else if (!dash && equals) {
4480 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4485 const char *
const reg_name_in = equals + 1;
4486 const size_t reg_type_len = strlen(
reg_type);
4488 *name_buffer = calloc(1, strlen(reg_name_in) + reg_type_len + 2);
4489 name = *name_buffer;
4495 name[reg_type_len] =
'_';
4497 unsigned int scanned_chars;
4499 if (sscanf(reg_name_in,
"%[_a-zA-Z0-9]%n", scan_dst, &scanned_chars) != 1 ||
4500 scanned_chars != strlen(reg_name_in)) {
4501 LOG_ERROR(
"Invalid characters in register name '%s'.", reg_name_in);
4505 LOG_ERROR(
"Invalid argument '%s'.", arg);
4511 if (high > max_val) {
4512 LOG_ERROR(
"Cannot expose %s register number 0x%x, maximum allowed value is 0x%x.",
4520 if (entry->
low <= high && low <= entry->high) {
4523 "Register %u has already been exposed previously",
reg_type,
low);
4525 LOG_WARNING(
"Overlapping register ranges - Register range starting from %u overlaps "
4526 "with already exposed register/range at %u.",
low, entry->
low);
4545 *name_buffer =
NULL;
4553 const char *
reg_type,
unsigned int max_val)
4555 char *args = strdup(tcl_arg);
4560 char *name_buffer =
NULL;
4576 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4594 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4612 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4623 unsigned int index = 0;
4641 if (r->authdata_read) {
4656 unsigned int index = 0;
4671 if (!r->authdata_write) {
4676 return r->authdata_write(
target, value, index);
4683 if (!r || !r->get_dmi_address)
4685 return r->get_dmi_address(
target, dm_address);
4717 if (!r->dmi_write) {
4721 const int result = r->dmi_write(
target, dmi_address, value);
4729 const bool progbuf_touched =
4732 const bool dm_deactivated =
4735 if (progbuf_touched || dm_deactivated) {
4736 if (r->invalidate_cached_progbuf) {
4744 r->invalidate_cached_progbuf(
target);
4747 "invalidate_cached_progbuf() is not implemented.");
4758 uint32_t dmi_address;
4774 uint32_t dmi_address, value;
4787 uint32_t dm_address;
4804 uint32_t dm_address, value;
4825 r->reset_delays_wait = wait;
4837 if (!strcmp(
CMD_ARGV[0],
"idcode"))
4839 else if (!strcmp(
CMD_ARGV[0],
"dtmcs"))
4841 else if (!strcmp(
CMD_ARGV[0],
"dmi"))
4854 if (!strcmp(
CMD_ARGV[0],
"normal")) {
4856 }
else if (!strcmp(
CMD_ARGV[0],
"reversed")) {
4868 uint8_t irwidth = 0;
4871 if (CMD_ARGC < 1 || CMD_ARGC > 2)
4886 LOG_INFO(
"Nested Tap based Bscan Tunnel Selected");
4888 LOG_INFO(
"Simple Register based Bscan Tunnel Selected");
4890 LOG_INFO(
"Invalid Tunnel type selected ! : selecting default Nested Tap Type");
4907 LOG_INFO(
"Bscan tunnel IR 0x%x selected", ir_id);
4918 static const struct jim_nvp nvp_maskisr_modes[] = {
4921 { .name =
NULL, .value = -1 },
4958 const char *mode_str;
4970 assert(0 &&
"Unexpected execution mode");
4971 mode_str =
"unexpected";
4976 LOG_WARNING(
"DEPRECATED! use '%s cget -ebreak' not '%s'",
4979 config->dcsr_ebreak_fields[
mode] ?
"on" :
"off");
4987 config->dcsr_ebreak_fields[
mode] = ebreak_ctl;
5051 "doesn't support setting more than one at a time.");
5062 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5065 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5067 else if (!strcmp(
CMD_ARGV[i],
"nmi"))
5069 else if (!strcmp(
CMD_ARGV[i],
"m"))
5071 else if (!strcmp(
CMD_ARGV[i],
"s"))
5073 else if (!strcmp(
CMD_ARGV[i],
"u"))
5078 if (!nmi && interrupts == 0) {
5079 LOG_ERROR(
"Doesn't make sense to set itrigger with "
5080 "mie_bits=0 and without nmi.");
5082 }
else if (!vs && !vu && !m && !s && !u) {
5083 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5084 "least one of vs, vu, m, s, or u.");
5092 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5093 return riscv_clear_trigger(
CMD, ITRIGGER_UNIQUE_ID,
"itrigger");
5096 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5121 "doesn't support setting more than one at a time.");
5129 bool pending =
false;
5130 unsigned int count = 0;
5132 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5135 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5137 else if (!strcmp(
CMD_ARGV[i],
"pending"))
5139 else if (!strcmp(
CMD_ARGV[i],
"m"))
5141 else if (!strcmp(
CMD_ARGV[i],
"s"))
5143 else if (!strcmp(
CMD_ARGV[i],
"u"))
5149 LOG_ERROR(
"Doesn't make sense to set icount trigger with "
5152 }
else if (!vs && !vu && !m && !s && !u) {
5153 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5154 "least one of vs, vu, m, s, or u.");
5162 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5163 return riscv_clear_trigger(
CMD, ICOUNT_UNIQUE_ID,
"icount trigger");
5166 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5191 "doesn't support setting more than one at a time.");
5201 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5204 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5206 else if (!strcmp(
CMD_ARGV[i],
"m"))
5208 else if (!strcmp(
CMD_ARGV[i],
"s"))
5210 else if (!strcmp(
CMD_ARGV[i],
"u"))
5215 if (exception_codes == 0) {
5216 LOG_ERROR(
"Doesn't make sense to set etrigger with "
5217 "exception_codes=0.");
5219 }
else if (!vs && !vu && !m && !s && !u) {
5220 LOG_ERROR(
"Doesn't make sense to set etrigger without at "
5221 "least one of vs, vu, m, s, or u.");
5229 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5230 return riscv_clear_trigger(
CMD, ETRIGGER_UNIQUE_ID,
"etrigger");
5233 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5249 if (CMD_ARGC < 2 || CMD_ARGC > 3)
5275 int result = r->access_memory(
target, args);
5289 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
5290 if (r->sample_config.bucket[i].enabled) {
5292 r->sample_config.bucket[i].address,
5293 r->sample_config.bucket[i].size_bytes);
5306 if (bucket >
ARRAY_SIZE(r->sample_config.bucket)) {
5311 if (!strcmp(
CMD_ARGV[1],
"clear")) {
5312 r->sample_config.bucket[bucket].enabled =
false;
5318 if (r->sample_config.bucket[bucket].size_bytes != 4 &&
5319 r->sample_config.bucket[bucket].size_bytes != 8) {
5324 r->sample_config.bucket[bucket].size_bytes = 4;
5327 r->sample_config.bucket[bucket].enabled =
true;
5330 if (!r->sample_buf.buf) {
5331 r->sample_buf.size = 1024 * 1024;
5332 r->sample_buf.buf = malloc(r->sample_buf.size);
5336 r->sample_buf.used = 0;
5338 r->sample_config.enabled =
true;
5351 bool base64 =
false;
5353 if (!strcmp(
CMD_ARGV[0],
"base64")) {
5364 r->sample_buf.used,
NULL);
5374 while (i < r->sample_buf.used) {
5375 uint8_t
command = r->sample_buf.buf[i++];
5377 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5381 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5386 r->sample_config.bucket[
command].address);
5387 if (r->sample_config.bucket[
command].size_bytes == 4) {
5388 uint32_t value =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5391 }
else if (r->sample_config.bucket[
command].size_bytes == 8) {
5392 uint64_t value =
buf_get_u64(r->sample_buf.buf + i, 0, 64);
5397 r->sample_config.bucket[
command].size_bytes);
5412 r->sample_buf.used = 0;
5417 const char *key,
unsigned int value,
bool is_available)
5420 snprintf(full_key,
sizeof(full_key),
"%s.%s", section, key);
5444 const bool trigger_count_available =
5446 riscv_print_info_line_if_available(
CMD,
"hart",
"trigger_count",
5447 r->trigger_count, trigger_count_available);
5456 if (CMD_ARGC < 1 || CMD_ARGC > 16)
5469 "only supported on v0.13 or v1.0 targets.");
5475 "program buffer, target not halted.");
5488 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
5516 bool enable_for_wp =
true;
5519 enable_for_wp =
true;
5520 else if (!strcmp(
CMD_ARGV[1],
"none"))
5521 enable_for_wp =
false;
5526 r->wp_allow_equality_match_trigger = enable_for_wp;
5527 r->wp_allow_napot_trigger = enable_for_wp;
5528 r->wp_allow_ge_lt_trigger = enable_for_wp;
5529 }
else if (!strcmp(
CMD_ARGV[0],
"eq")) {
5530 r->wp_allow_equality_match_trigger = enable_for_wp;
5531 }
else if (!strcmp(
CMD_ARGV[0],
"napot")) {
5532 r->wp_allow_napot_trigger = enable_for_wp;
5533 }
else if (!strcmp(
CMD_ARGV[0],
"ge_lt")) {
5534 r->wp_allow_ge_lt_trigger = enable_for_wp;
5543 "Equality match trigger: for wp (%s)\n"
5544 "NAPOT trigger: for wp (%s)\n"
5545 "ge-lt chained triggers: for wp (%s)",
5546 r->wp_allow_equality_match_trigger ?
"enabled" :
"disabled",
5547 r->wp_allow_napot_trigger ?
"enabled" :
"disabled",
5548 r->wp_allow_ge_lt_trigger ?
"enabled" :
"disabled");
5558 const char *separator =
"";
5559 for (
riscv_reg_t t = 0; t < r->trigger_count; ++t) {
5560 if (r->reserved_triggers[t]) {
5589 if (r->trigger_count == 0) {
5593 if (t >= r->trigger_count) {
5595 " does not exist. There are only %u triggers"
5596 " on the target (with indexes 0 .. %u).",
5597 t, r->trigger_count, r->trigger_count - 1);
5600 if (r->trigger_unique_id[t] != -1) {
5602 " is already in use and can not be reserved.", t);
5641 .
name =
"dump_sample_buf",
5642 .handler = handle_dump_sample_buf_command,
5644 .usage =
"[base64]",
5645 .help =
"Print the contents of the sample buffer, and clear the buffer."
5649 .handler = handle_info,
5652 .help =
"Displays some information OpenOCD detected about the target."
5655 .name =
"memory_sample",
5656 .handler = handle_memory_sample_command,
5658 .usage =
"bucket address|clear [size=4]",
5659 .help =
"Causes OpenOCD to frequently read size bytes at the given address."
5662 .name =
"repeat_read",
5663 .handler = handle_repeat_read,
5665 .usage =
"count address [size=4]",
5666 .help =
"Repeatedly read the value at address."
5669 .name =
"set_command_timeout_sec",
5670 .handler = riscv_set_command_timeout_sec,
5673 .help =
"Set the wall-clock timeout (in seconds) for individual commands"
5676 .name =
"set_reset_timeout_sec",
5677 .handler = riscv_set_reset_timeout_sec,
5680 .help =
"DEPRECATED. Use 'riscv set_command_timeout_sec' instead."
5683 .name =
"set_mem_access",
5684 .handler = riscv_set_mem_access,
5686 .usage =
"method1 [method2] [method3]",
5687 .help =
"Set which memory access methods shall be used and in which order "
5688 "of priority. Method can be one of: 'progbuf', 'sysbus' or 'abstract'."
5691 .name =
"expose_csrs",
5692 .handler = riscv_set_expose_csrs,
5694 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5695 .help =
"Configure a list of inclusive ranges for CSRs to expose in "
5696 "addition to the standard ones. This must be executed before "
5700 .name =
"expose_custom",
5701 .handler = riscv_set_expose_custom,
5703 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5704 .help =
"Configure a list of inclusive ranges for custom registers to "
5705 "expose. custom0 is accessed as abstract register number 0xc000, "
5706 "etc. This must be executed before `init`."
5709 .name =
"hide_csrs",
5710 .handler = riscv_hide_csrs,
5712 .usage =
"{n0|n-m0}[,n1|n-m1]......",
5713 .help =
"Configure a list of inclusive ranges for CSRs to hide from gdb. "
5714 "Hidden registers are still available, but are not listed in "
5715 "gdb target description and `reg` command output. "
5716 "This must be executed before `init`."
5719 .name =
"authdata_read",
5720 .handler = riscv_authdata_read,
5723 .help =
"Return the 32-bit value read from authdata or authdata0 "
5724 "(index=0), or authdata1 (index=1)."
5727 .name =
"authdata_write",
5728 .handler = riscv_authdata_write,
5730 .usage =
"[index] value",
5731 .help =
"Write the 32-bit value to authdata or authdata0 (index=0), "
5732 "or authdata1 (index=1)."
5736 .handler = handle_riscv_dmi_read,
5739 .help =
"Read and return 32-bit value from the given address on the "
5743 .name =
"dmi_write",
5744 .handler = handle_riscv_dmi_write,
5746 .usage =
"address value",
5747 .help =
"Write a 32-bit value to the given address on the RISC-V DMI bus."
5751 .handler = handle_riscv_dm_read,
5753 .usage =
"reg_address",
5754 .help =
"Read and return 32-bit value from a debug module's register "
5759 .handler = handle_riscv_dm_write,
5761 .usage =
"reg_address value",
5762 .help =
"Write a 32-bit value to the debug module's register at "
5766 .name =
"reset_delays",
5767 .handler = riscv_reset_delays,
5770 .help =
"OpenOCD learns how many Run-Test/Idle cycles are required "
5771 "between scans to avoid encountering the target being busy. This "
5772 "command resets those learned values after `wait` scans. It's only "
5773 "useful for testing OpenOCD itself."
5776 .name =
"resume_order",
5777 .handler = riscv_resume_order,
5779 .usage =
"normal|reversed",
5780 .help =
"Choose the order that harts are resumed in when `hasel` is not "
5781 "supported. Normal order is from lowest hart index to highest. "
5782 "Reversed order is from highest hart index to lowest."
5786 .handler = riscv_set_ir,
5788 .usage =
"idcode|dtmcs|dmi value",
5789 .help =
"Set IR value for specified JTAG register."
5792 .name =
"use_bscan_tunnel",
5793 .handler = riscv_use_bscan_tunnel,
5795 .usage =
"value [type]",
5796 .help =
"Enable or disable use of a BSCAN tunnel to reach DM."
5799 .name =
"set_bscan_tunnel_ir",
5800 .handler = riscv_set_bscan_tunnel_ir,
5803 .help =
"Specify the JTAG TAP IR used to access the bscan tunnel. "
5804 "By default it is 0x23 << (ir_length - 6), which map some "
5805 "Xilinx FPGA (IR USER4)"
5808 .name =
"set_maskisr",
5809 .handler = riscv_set_maskisr,
5811 .help =
"mask riscv interrupts",
5812 .usage =
"['off'|'steponly']",
5815 .name =
"set_ebreakm",
5816 .handler = riscv_set_ebreakm,
5818 .usage =
"[on|off]",
5819 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5820 "'<target_name> cget -ebreak'"
5823 .name =
"set_ebreaks",
5824 .handler = riscv_set_ebreaks,
5826 .usage =
"[on|off]",
5827 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5828 "'<target_name> cget -ebreak'"
5831 .name =
"set_ebreaku",
5832 .handler = riscv_set_ebreaku,
5834 .usage =
"[on|off]",
5835 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5836 "'<target_name> cget -ebreak'"
5840 .handler = riscv_etrigger,
5842 .usage =
"set [vs] [vu] [m] [s] [u] <exception_codes>|clear",
5843 .help =
"Set or clear a single exception trigger."
5847 .handler = riscv_icount,
5849 .usage =
"set [vs] [vu] [m] [s] [u] [pending] <count>|clear",
5850 .help =
"Set or clear a single instruction count trigger."
5854 .handler = riscv_itrigger,
5856 .usage =
"set [vs] [vu] [nmi] [m] [s] [u] <mie_bits>|clear",
5857 .help =
"Set or clear a single interrupt trigger."
5860 .name =
"exec_progbuf",
5861 .handler = riscv_exec_progbuf,
5863 .usage =
"instr1 [instr2 [... instr16]]",
5864 .help =
"Execute a sequence of 32-bit instructions using the program buffer. "
5865 "The final ebreak instruction is added automatically, if needed."
5868 .name =
"set_enable_trigger_feature",
5869 .handler = riscv_set_enable_trigger_feature,
5871 .usage =
"[('eq'|'napot'|'ge_lt'|'all') ('wp'|'none')]",
5872 .help =
"Control whether OpenOCD is allowed to use certain RISC-V trigger features for watchpoints."
5875 .name =
"reserve_trigger",
5876 .handler = handle_reserve_trigger,
5879 .usage =
"[index ('on'|'off')]",
5880 .help =
"Controls which RISC-V triggers shall not be touched by OpenOCD.",
5883 .name =
"virt2phys_mode",
5884 .handler = handle_riscv_virt2phys_mode,
5886 .usage =
"['sw'|'hw'|'off']",
5887 .help =
"Configure the virtual address translation mode: "
5888 "sw - translate vaddr to paddr by manually traversing page tables, "
5889 "hw - translate vaddr to paddr by hardware, "
5890 "off - no address translation."
5893 .name =
"autofence",
5894 .handler = riscv_set_autofence,
5896 .usage =
"[on|off]",
5897 .help =
"When on (default), OpenOCD will automatically execute fence instructions in some situations. "
5898 "When off, users need to take care of memory coherency themselves, for example by using "
5899 "`riscv exec_progbuf` to execute fence or CMO instructions."
5925 .help =
"RISC-V Command Group",
5932 .help =
"ARM Command Group",
5948 return r->data_bits(
target);
5962 *insn_set =
"riscv32";
5966 *insn_set =
"riscv64";
6034 memset(r, 0,
sizeof(*r));
6094 *old_mstatus = current_mstatus;
6109 LOG_TARGET_WARNING(
target,
"OpenOCD might have affected the program when it restored the interrupt bits after single-step.");
6110 LOG_TARGET_WARNING(
target,
"Hint: Use 'riscv set_maskisr off' to prevent OpenOCD from touching mstatus during single-step.");
6138 if (letter >=
'a' && letter <=
'z')
6140 else if (letter >=
'A' && letter <=
'Z')
6144 return r->misa &
BIT(num);
6162 assert(r->get_hart_state);
6173 return r->halt_reason(
target);
6179 return r->get_progbufsize(
target);
6185 return r->write_progbuf(
target, index, insn);
6191 return r->read_progbuf(
target, index);
6197 return r->execute_progbuf(
target, cmderr);
6203 r->fill_dmi_write(
target, buf, a, d);
6209 r->fill_dmi_read(
target, buf, a);
6215 r->fill_dm_nop(
target, buf);
6221 return r->get_dmi_address_bits(
target);
6235 if (tselect_rb != index)
6248 assert(trigger_tinfo);
6253 if (tinfo == 0 || tinfo & 0x1)
6255 *trigger_tinfo = tinfo;
6261 *trigger_tinfo = 1 <<
type;
6267 bool dmode_is_set =
false;
6272 dmode_is_set =
true;
6307 if (r->triggers_enumerated)
6321 "Assuming that triggers are not implemented.");
6322 r->triggers_enumerated =
true;
6323 r->trigger_count = 0;
6324 free(r->reserved_triggers);
6325 r->reserved_triggers =
NULL;
6343 for (; t <
ARRAY_SIZE(r->trigger_tinfo); ++t) {
6361 t, r->trigger_tinfo[t]);
6370 r->triggers_enumerated =
true;
6371 r->trigger_count = t;
6373 free(r->reserved_triggers);
6374 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_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 int riscv_rw_memory(struct target *target, const struct riscv_mem_access_args args)
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 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_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)
bool riscv_virt2phys_mode_is_hw(const struct target *target)
static int riscv_openocd_step_impl(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, int handle_callbacks)
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 int riscv_effective_privilege_mode(struct target *target, int *v_mode, int *effective_mode)
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_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)
bool riscv_virt2phys_mode_is_sw(const struct target *target)
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 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 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
int64_t trigger_unique_id[RISCV_MAX_HWBPS]
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]
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
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