33 #define DTMCONTROL 0x10
34 #define DTMCONTROL_VERSION (0xf)
38 #define RISCV_TRIGGER_HIT_NOT_FOUND ((int64_t)-1)
40 #define RISCV_HALT_GROUP_REPOLL_LIMIT 5
59 #define BSCAN_TUNNEL_IR_WIDTH_NBITS 7
164 static const char *
const names[] = {
194 .vpn_shift = {12, 22},
195 .vpn_mask = {0x3ff, 0x3ff},
196 .pte_ppn_shift = {10, 20},
197 .pte_ppn_mask = {0x3ff, 0xfff},
198 .pa_ppn_shift = {12, 22},
199 .pa_ppn_mask = {0x3ff, 0xfff},
207 .vpn_shift = {12, 22},
208 .vpn_mask = {0x3ff, 0xfff},
209 .pte_ppn_shift = {10, 20},
210 .pte_ppn_mask = {0x3ff, 0xfff},
211 .pa_ppn_shift = {12, 22},
212 .pa_ppn_mask = {0x3ff, 0xfff},
220 .vpn_shift = {12, 21, 30},
221 .vpn_mask = {0x1ff, 0x1ff, 0x1ff},
222 .pte_ppn_shift = {10, 19, 28},
223 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
224 .pa_ppn_shift = {12, 21, 30},
225 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
233 .vpn_shift = {12, 21, 30},
234 .vpn_mask = {0x1ff, 0x1ff, 0x7ff},
235 .pte_ppn_shift = {10, 19, 28},
236 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
237 .pa_ppn_shift = {12, 21, 30},
238 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
246 .vpn_shift = {12, 21, 30, 39},
247 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff},
248 .pte_ppn_shift = {10, 19, 28, 37},
249 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
250 .pa_ppn_shift = {12, 21, 30, 39},
251 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
259 .vpn_shift = {12, 21, 30, 39},
260 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x7ff},
261 .pte_ppn_shift = {10, 19, 28, 37},
262 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
263 .pa_ppn_shift = {12, 21, 30, 39},
264 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
272 .vpn_shift = {12, 21, 30, 39, 48},
273 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
274 .pte_ppn_shift = {10, 19, 28, 37, 46},
275 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
276 .pa_ppn_shift = {12, 21, 30, 39, 48},
277 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x1ff},
285 .vpn_shift = {12, 21, 30, 39, 48},
286 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0x7ff},
287 .pte_ppn_shift = {10, 19, 28, 37, 46},
288 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
289 .pa_ppn_shift = {12, 21, 30, 39, 48},
290 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff, 0xff},
305 if (r->sample_buf.used + 5 < r->sample_buf.size) {
310 r->sample_buf.buf[r->sample_buf.used++] = now & 0xff;
311 r->sample_buf.buf[r->sample_buf.used++] = (now >> 8) & 0xff;
312 r->sample_buf.buf[r->sample_buf.used++] = (now >> 16) & 0xff;
313 r->sample_buf.buf[r->sample_buf.used++] = (now >> 24) & 0xff;
333 uint8_t tunneled_dr_width[4] = {32};
334 uint8_t out_value[5] = {0};
335 uint8_t in_value[5] = {0};
362 tunneled_dr[2].
out_value = tunneled_dr_width;
389 tunneled_dr[1].
out_value = tunneled_dr_width;
402 LOG_ERROR(
"failed jtag scan: %d", retval);
408 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
430 .in_value = in_ptr ? value :
NULL
439 LOG_ERROR(
"'dtmcs' scan failed on TAP %s, error code = %d",
447 LOG_DEBUG(
"TAP %s: DTMCS: 0x%" PRIx32
" -> 0x%" PRIx32,
464 switch (
info->dtm_version) {
487 config->dcsr_ebreak_fields[i] =
true;
520 #define RISCV_EBREAK_MODE_INVALID -1
523 { .
name =
"exception", .value =
false },
524 { .name =
"halt", .value =
true },
530 if (goi->
argc == 0) {
531 Jim_WrongNumArgs(goi->
interp, 1, goi->
argv - 1,
532 "[?execution_mode?] ?ebreak_action?");
535 struct jim_nvp *common_mode_nvp;
537 &common_mode_nvp) == JIM_OK) {
544 for (
int ebreak_ctl_i = 0; ebreak_ctl_i <
N_RISCV_MODE; ++ebreak_ctl_i)
545 config->dcsr_ebreak_fields[ebreak_ctl_i] = common_mode_nvp->
value;
553 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
581 const char *separator =
"";
584 const char *
const format =
"%s%s %s";
585 const char *
const priv_mode =
588 config->dcsr_ebreak_fields[ebreak_ctl_i])->
name;
590 len += snprintf(
NULL, 0, format, separator, priv_mode,
mode);
592 len += sprintf(
buffer + len, format, separator, priv_mode,
mode);
603 char *str = malloc(len + 1);
605 LOG_ERROR(
"Unable to allocate a string of %d bytes.", len + 1);
609 Jim_SetResultString(interp, str, len);
649 Jim_WrongNumArgs(goi->
interp, 2, goi->
argv - 2,
"");
658 assert(
false &&
"'jim_getopt_nvp' should have returned an error.");
668 info->cmd_ctx = cmd_ctx;
669 info->reset_delays_wait = -1;
678 if (ir_user4_raw == 0) {
701 for (
unsigned int i = 0; i < r->trigger_count; ++i) {
713 free(r->wp_triggers_negative_cache);
730 if (tt &&
info &&
info->version_specific)
739 free(
info->reserved_triggers);
779 bool size_power_of_2 = (
size & (
size - 1)) == 0;
780 bool addr_aligned = (
addr & (
size - 1)) == 0;
781 return size > 1 && size_power_of_2 && addr_aligned;
791 unsigned int num_found = 0;
792 unsigned int num_required = chained ? 2 : 1;
794 for (
unsigned int i = *idx; i < r->trigger_count; i++) {
795 if (r->trigger_unique_id[i] == -1) {
796 if (r->trigger_tinfo[i] & (1 <<
type)) {
798 if (num_required == num_found) {
800 *idx = i - (num_required - 1);
802 "%d trigger(s) of type %d found on index %u, "
804 num_required,
type, *idx,
805 chained ?
"true" :
"false");
824 for (
unsigned int i = 0; i < r->trigger_count; i++) {
825 if (r->trigger_unique_id[i] == unique_id)
833 const unsigned int riscv_reg_bits =
sizeof(
riscv_reg_t) * CHAR_BIT;
834 for (
unsigned int i = 0; i < riscv_reg_bits; i++) {
835 if ((1 & (
reg >> i)) == 0)
838 return riscv_reg_bits;
844 assert(r->reserved_triggers);
845 assert(idx < r->trigger_count);
846 if (r->reserved_triggers[idx]) {
848 "Trigger %u is reserved by 'reserve_trigger' command.", idx);
883 const bool tdata1_config_denied = (tdata1 & ~tdata1_ignore_mask) != (tdata1_rb & ~tdata1_ignore_mask);
888 bool unsupported_napot_range =
false;
890 if (!tdata1_config_denied) {
892 if (is_mcontrol && is_napot_match) {
895 if (maskmax_value < napot_size)
896 unsupported_napot_range =
true;
900 const bool tdata2_config_denied = tdata2 != tdata2_rb;
901 if (tdata1_config_denied || tdata2_config_denied || unsupported_napot_range) {
904 if (tdata1_config_denied)
906 "After writing 0x%" PRIx64
" to tdata1 it contains 0x%" PRIx64,
909 if (tdata2_config_denied)
911 "After writing 0x%" PRIx64
" to tdata2 it contains 0x%" PRIx64,
914 if (unsupported_napot_range)
916 "The requested NAPOT match range (tdata2=0x%" PRIx64
") exceeds maskmax_value=0x%" PRIx64,
917 tdata2, maskmax_value);
934 const uint32_t bpcontrol_x = 1<<0;
935 const uint32_t bpcontrol_w = 1<<1;
936 const uint32_t bpcontrol_r = 1<<2;
937 const uint32_t bpcontrol_u = 1<<3;
938 const uint32_t bpcontrol_s = 1<<4;
939 const uint32_t bpcontrol_h = 1<<5;
940 const uint32_t bpcontrol_m = 1<<6;
941 const uint32_t bpcontrol_bpmatch = 0xf << 7;
942 const uint32_t bpcontrol_bpaction = 0xff << 11;
944 unsigned int idx = 0;
951 if (tdata1 & (bpcontrol_r | bpcontrol_w | bpcontrol_x)) {
960 tdata1 =
set_field(tdata1, bpcontrol_u, !!(r->misa &
BIT(
'U' -
'A')));
961 tdata1 =
set_field(tdata1, bpcontrol_s, !!(r->misa &
BIT(
'S' -
'A')));
962 tdata1 =
set_field(tdata1, bpcontrol_h, !!(r->misa &
BIT(
'H' -
'A')));
963 tdata1 =
set_field(tdata1, bpcontrol_m, 1);
964 tdata1 =
set_field(tdata1, bpcontrol_bpaction, 0);
965 tdata1 =
set_field(tdata1, bpcontrol_bpmatch, 0);
1004 if (elem_2->
tdata2 == find_tdata2)
1014 if (elem_1->
tdata1 == find_tdata1)
1024 r->wp_triggers_negative_cache = (
struct list_head *)calloc(r->trigger_count,
1026 for (
unsigned int i = 0; i < r->trigger_count; ++i)
1089 for (
unsigned int idx = 0;
1117 for (
unsigned int idx = 0;
1246 if (r->wp_allow_napot_trigger) {
1258 "Use 'riscv set_enable_trigger_feature napot wp' to enable it.");
1262 if (r->wp_allow_ge_lt_trigger) {
1294 "Use 'riscv set_enable_trigger_feature ge_lt wp' to enable it.");
1298 if (r->wp_allow_equality_match_trigger) {
1310 "Use 'riscv set_enable_trigger_feature eq wp' to enable it.");
1315 ", but may not match accesses at addresses in the inclusive range from 0x%"
1319 if (!
info->range_trigger_fallback_encountered)
1324 "Could not set a trigger that will match a whole address range. "
1325 "As a fallback, this trigger (and maybe others) will only match "
1326 "against the first address of the range.");
1327 info->range_trigger_fallback_encountered =
true;
1359 bool m,
bool s,
bool u,
bool pending,
unsigned int count,
1379 unsigned int idx = 0;
1386 r->trigger_unique_id[idx] = unique_id;
1391 bool nmi,
bool m,
bool s,
bool u,
riscv_reg_t interrupts,
1412 unsigned int idx = 0;
1419 r->trigger_unique_id[idx] = unique_id;
1424 bool m,
bool s,
bool u,
riscv_reg_t exception_codes,
1442 tdata2 = exception_codes;
1444 unsigned int idx = 0;
1451 r->trigger_unique_id[idx] = unique_id;
1494 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1497 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1499 if (access_size <=
size &&
address % access_size == 0)
1503 unsigned int offset_head =
address % access_size;
1504 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1505 uint8_t helper_buf[n_blocks * access_size];
1512 memcpy(helper_buf + offset_head,
buffer,
size);
1521 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
1524 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
1526 if (access_size <=
size &&
address % access_size == 0)
1530 unsigned int offset_head =
address % access_size;
1531 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
1532 uint8_t helper_buf[n_blocks * access_size];
1539 memcpy(
buffer, helper_buf + offset_head,
size);
1552 unsigned int preferred_size =
size;
1553 while (
address % preferred_size != 0)
1554 preferred_size /= 2;
1562 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1563 if (access_size == preferred_size)
1584 unsigned int preferred_size =
size;
1585 while (
address % preferred_size != 0)
1586 preferred_size /= 2;
1594 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
1595 if (access_size == preferred_size)
1632 uint8_t buff[4] = { 0 };
1671 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1672 if (r->trigger_unique_id[i] ==
unique_id) {
1675 r->trigger_unique_id[i] = -1;
1683 "Couldn't find the hardware resources used by hardware trigger.");
1785 const uint32_t hit_info = (hit1 << 1) | hit0;
1808 for (uint64_t i = 0; i <
ARRAY_SIZE(tdata1_tests); ++i) {
1813 if (tdata1_test_rb == tdata1_tests[i]) {
1830 bool *need_single_step)
1838 assert(need_single_step);
1839 *need_single_step =
false;
1846 for (
unsigned int i = 0; i < r->trigger_count; i++) {
1847 if (r->trigger_unique_id[i] == -1)
1858 uint64_t hit_mask = 0;
1865 *need_single_step =
true;
1870 *need_single_step =
true;
1878 *need_single_step =
true;
1897 if (tdata1 & hit_mask) {
1899 ") has hit bit set. (need_single_step=%s)",
1900 i, r->trigger_unique_id[i], (*need_single_step) ?
"yes" :
"no");
1922 uint16_t offset_4to2and7to6_bits =
1924 uint16_t offset_4to2_bits = offset_4to2and7to6_bits >> 2;
1925 uint16_t offset_7to6_bits = offset_4to2and7to6_bits & 0x3;
1927 return (offset_4to2_bits << 2) + (offset_5_bit << 5)
1928 + (offset_7to6_bits << 6);
1934 uint16_t offset_4to3and8to6_bits =
1936 uint16_t offset_4to3_bits = offset_4to3and8to6_bits >> 3;
1937 uint16_t offset_8to6_bits = offset_4to3and8to6_bits & 0x7;
1939 return (offset_4to3_bits << 3) + (offset_5_bit << 5)
1940 + (offset_8to6_bits << 6);
1946 uint16_t offset_5to2and7to6_bits =
1948 uint16_t offset_5to2_bits = offset_5to2and7to6_bits >> 2;
1949 uint16_t offset_7to6_bits = offset_5to2and7to6_bits & 0x3;
1950 return (offset_5to2_bits << 2) + (offset_7to6_bits << 6);
1956 uint16_t offset_5to3and8to6_bits =
1958 uint16_t offset_5to3_bits = offset_5to3and8to6_bits >> 3;
1959 uint16_t offset_8to6_bits = offset_5to3and8to6_bits & 0x7;
1960 return (offset_5to3_bits << 3) + (offset_8to6_bits << 6);
1967 uint16_t offset_2_bit = offset_2and6_bits >> 1;
1968 uint16_t offset_6_bit = offset_2and6_bits & 0x1;
1970 return (offset_2_bit << 2) + (offset_5to3_bits << 3) + (offset_6_bit << 6);
1978 return (offset_5to3_bits << 3) + (offset_7to6_bits << 6);
1985 uint16_t offset_5to4and8_bits =
1987 uint16_t offset_5to4_bits = offset_5to4and8_bits >> 1;
1988 uint16_t offset_8_bit = offset_5to4and8_bits & 0x1;
1989 return (offset_5to4_bits << 4) + (offset_7to6_bits << 6)
1990 + (offset_8_bit << 8);
1996 uint16_t offset_4and9to6_bits =
1998 uint16_t offset_4_bit = offset_4and9to6_bits >> 4;
1999 uint16_t offset_9to6_bits = offset_4and9to6_bits & 0xf;
2001 return (offset_4_bit << 4) + (offset_5_bit << 5) + (offset_9to6_bits << 6);
2007 uint16_t offset_5to4and9to6_bits =
2009 uint16_t offset_5to4_biits = offset_5to4and9to6_bits >> 4;
2010 uint16_t offset_9to6_bits = offset_5to4and9to6_bits & 0xf;
2011 return (offset_5to4_biits << 4) + (offset_9to6_bits << 6);
2029 if ((instruction & 0x03) < 0x03) {
2070 " store", instruction);
2184 " store", instruction);
2213 "The code points with rd = x0 are reserved for C.LWSP");
2223 "The code points with rd = x0 are reserved for C.LDSP");
2229 "have the \"F\" extension");
2240 "The code points with rd = x0 are reserved for C.LQSP");
2246 "have the \"D\" extension");
2261 "have the \"F\" extension");
2272 "have the \"D\" extension");
2287 "have the \"F\" extension");
2298 "have the \"D\" extension");
2313 "have the \"F\" extension");
2324 "have the \"D\" extension");
2333 " store", instruction);
2364 if (wp->unique_id == r->trigger_hit) {
2365 *hit_watchpoint = wp;
2373 const uint8_t
length = 4;
2386 for (
int i = 0; i <
length; i++) {
2388 instruction += (
buffer[i] << 8 * i);
2403 mem_addr += memoffset;
2416 if (mem_addr >= wp->
address &&
2418 *hit_watchpoint = wp;
2421 is_load ?
"Load from" :
"Store to", mem_addr,
2423 "read" : (wp->
rw ==
WPT_WRITE ?
"write" :
"access")),
2441 bool handle_breakpoints)
2457 handle_breakpoints ?
"true" :
"false");
2458 if (!r->get_hart_state)
2469 handle_breakpoints,
true );
2483 uint32_t dtmcontrol;
2509 return examine_status;
2523 if (!r->get_hart_state)
2541 if (bp->type ==
BKPT_HARD && bp->is_set && bp->address == dpc) {
2545 "can't derive debug reason for context-aware breakpoint: "
2547 ", asid = %" PRIx32
", linked = %d",
2548 bp->unique_id, bp->address, bp->asid, bp->linked_brp);
2562 r->trigger_hit = -1;
2563 r->need_single_step =
false;
2564 switch (halt_reason) {
2581 "Active hit bit is detected, trying to find trigger owner.");
2583 if (bp->unique_id == r->trigger_hit) {
2586 "Breakpoint with unique_id = %" PRIu32
" owns the trigger.",
2594 if (wp->unique_id == r->trigger_hit) {
2597 "Watchpoint with unique_id = %" PRIu32
" owns the trigger.",
2604 "No trigger hit found, deriving debug reason without it.");
2674 "the target is not halted!");
2689 if (!r->get_hart_state) {
2712 if (!r->get_hart_state) {
2789 memset(wp_is_set,
false, r->trigger_count);
2795 wp_is_set[i] ?
"true" :
"false");
2815 wp_is_set[i] ?
"needs " :
"does not need");
2839 if (handle_breakpoints) {
2850 && r->need_single_step)) {
2857 if (r->get_hart_state) {
2878 if (!r->get_hart_state) {
2899 "BUG: registers should have been flushed by this point.");
2917 bool handle_breakpoints,
2918 bool debug_execution,
2936 list_add(&single_target_entry.
lh, &single_target_list);
2937 targets = &single_target_list;
2942 current ?
"true" :
"false",
2944 handle_breakpoints ?
"true" :
"false",
2945 debug_execution ?
"true" :
"false");
2987 debug_execution,
false);
3069 if (effective_mode ==
PRV_M) {
3103 info->name, ppn,
virtual);
3106 assert(xlen >=
info->va_bits);
3109 if (masked_msbs != 0 && masked_msbs !=
mask) {
3111 "for %s mode.",
virtual,
info->name);
3117 int i =
info->level - 1;
3119 uint64_t vpn =
virtual >>
info->vpn_shift[i];
3120 vpn &=
info->vpn_mask[i];
3131 assert(
info->pte_shift <= 3);
3137 .count = (1 <<
info->pte_shift) / 4,
3139 int retval = r->access_memory(
target, args);
3143 if (
info->pte_shift == 2)
3153 "; mode=%s; i=%d", pte_address, pte,
info->name, i);
3175 while (i < info->level) {
3176 ppn = pte >>
info->pte_ppn_shift[i];
3177 ppn &=
info->pte_ppn_mask[i];
3179 info->pa_ppn_shift[i]);
3180 *physical |= (ppn <<
info->pa_ppn_shift[i]);
3184 info->name,
virtual, *physical);
3210 switch (vsatp_mode) {
3230 "vsatp mode %d is not supported. (vsatp: 0x%" PRIx64
")",
3237 switch (hgatp_mode) {
3257 "hgatp mode %d is not supported. (hgatp: 0x%" PRIx64
")",
3277 virtual, &guest_physical) !=
ERROR_OK)
3280 guest_physical =
virtual;
3290 guest_physical, physical) !=
ERROR_OK)
3293 *physical = guest_physical;
3305 *physical =
virtual;
3328 switch (satp_mode) {
3343 " (satp: 0x%" PRIx64
")", satp_value);
3347 " (satp: 0x%" PRIx64
")", satp_value);
3358 uint32_t
size, uint32_t
count,
bool is_write)
3363 if (is_misaligned && crosses_page_boundary) {
3365 " would access an element across page boundary. This is not supported.",
3383 return r->access_memory(
target, args);
3398 return r->access_memory(
target, args);
3406 if (args.
count == 0) {
3408 is_write ?
"write to" :
"read from", args.
address);
3419 return r->access_memory(
target, args);
3426 uint32_t current_count = 0;
3428 while (current_count < args.
count) {
3439 uint32_t chunk_count =
MIN(args.
count - current_count,
3444 current_access.
address = physical_addr;
3445 current_access.
count = chunk_count;
3451 result = r->access_memory(
target, current_access);
3455 current_count += chunk_count;
3456 current_address += chunk_count * args.
size;
3493 return "riscv:rv32";
3495 return "riscv:rv64";
3502 struct reg **reg_list[],
int *reg_list_size,
3512 switch (reg_class) {
3514 *reg_list_size = 33;
3524 *reg_list = calloc(*reg_list_size,
sizeof(
struct reg *));
3528 for (
int i = 0; i < *reg_list_size; i++) {
3544 struct reg **reg_list[],
int *reg_list_size,
3552 struct reg **reg_list[],
int *reg_list_size,
3567 semihosting_active ?
" Semihosting is active." :
"");
3577 struct mem_param *mem_params,
int num_reg_params,
3579 target_addr_t exit_point,
unsigned int timeout_ms,
void *arch_info)
3589 for (
int i = 0; i < num_mem_params; i++) {
3595 " size=0x%" PRIx32, mem_params[i].
address, mem_params[i].
size);
3608 uint64_t saved_regs[32];
3609 for (
int i = 0; i < num_reg_params; i++) {
3617 if (r->
size != reg_params[i].
size) {
3619 reg_params[i].reg_name, r->
size, reg_params[i].
size);
3652 if (now -
start > timeout_ms) {
3668 for (
unsigned int i = 0; i <
ARRAY_SIZE(regnums); i++) {
3691 if (exit_point && final_pc != exit_point) {
3702 uint8_t buf[8] = { 0 };
3707 for (
int i = 0; i < num_reg_params; i++) {
3727 for (
int i = 0; i < num_mem_params; i++) {
3731 mem_params[i].
value);
3754 static const uint8_t riscv32_crc_code[] = {
3755 #include "../../../contrib/loaders/checksum/riscv32_crc.inc"
3757 static const uint8_t riscv64_crc_code[] = {
3758 #include "../../../contrib/loaders/checksum/riscv64_crc.inc"
3761 static const uint8_t *crc_code;
3764 unsigned int crc_code_size;
3766 crc_code = riscv32_crc_code;
3767 crc_code_size =
sizeof(riscv32_crc_code);
3769 crc_code = riscv64_crc_code;
3770 crc_code_size =
sizeof(riscv64_crc_code);
3773 if (
count < crc_code_size * 4) {
3797 crc_algorithm->
address, retval);
3808 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
3894 previous_target_state);
3920 if (r->handle_became_halted &&
3921 r->handle_became_halted(
target, previous_riscv_state) !=
ERROR_OK)
3930 r->halted_needs_event_callback =
true;
3944 if (r->handle_became_running &&
3945 r->handle_became_running(
target, previous_riscv_state) !=
ERROR_OK)
3953 if (r->handle_became_unavailable &&
3954 r->handle_became_unavailable(
target, previous_riscv_state) !=
ERROR_OK)
3972 if (!r->sample_buf.buf || !r->sample_config.enabled)
3980 if (r->sample_memory) {
3981 result = r->sample_memory(
target, &r->sample_buf, &r->sample_config,
3989 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
3990 if (r->sample_config.bucket[i].enabled &&
3991 r->sample_buf.used + 1 + r->sample_config.bucket[i].size_bytes < r->sample_buf.size) {
3993 r->sample_buf.buf[r->sample_buf.used] = i;
3995 r->sample_config.bucket[i].address,
3996 r->sample_config.bucket[i].size_bytes, 1,
3997 r->sample_buf.buf + r->sample_buf.used + 1);
3999 r->sample_buf.used += 1 + r->sample_config.bucket[i].size_bytes;
4010 r->sample_config.enabled =
false;
4035 list_add(&single_target_entry.
lh, &single_target_list);
4036 targets = &single_target_list;
4039 unsigned int should_remain_halted = 0;
4040 unsigned int should_resume = 0;
4042 unsigned int running = 0;
4043 unsigned int cause_groups = 0;
4051 info->halted_needs_event_callback =
false;
4060 switch (next_action) {
4069 should_remain_halted++;
4078 should_remain_halted, should_resume);
4079 if (should_remain_halted && should_resume) {
4081 should_remain_halted, should_resume);
4083 if (should_remain_halted) {
4085 should_remain_halted);
4087 }
else if (should_resume) {
4090 }
else if (
halted && running) {
4129 if (
halted == cause_groups) {
4154 if (
info->halted_needs_event_callback) {
4156 info->halted_needs_event_callback =
false;
4198 if (handle_breakpoints) {
4212 bool *wps_to_enable = calloc(r->trigger_count,
sizeof(*wps_to_enable));
4213 if (!wps_to_enable) {
4220 "watchpoints before single-step.");
4221 free(wps_to_enable);
4225 bool success =
true;
4248 "BUG: registers should have been flushed by this point.");
4263 "after single-step.");
4266 free(wps_to_enable);
4275 if (handle_callbacks)
4280 if (handle_callbacks)
4313 LOG_WARNING(
"The command 'riscv set_reset_timeout_sec' is deprecated! Please, use 'riscv set_command_timeout_sec'.");
4331 int progbuf_cnt = 0;
4333 int abstract_cnt = 0;
4342 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4343 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0) {
4345 }
else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0) {
4347 }
else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0) {
4351 "Must be one of: 'progbuf', 'sysbus' or 'abstract'.",
CMD_ARGV[i]);
4355 if (progbuf_cnt > 1 || sysbus_cnt > 1 || abstract_cnt > 1) {
4356 LOG_ERROR(
"Syntax error - duplicate arguments to `riscv set_mem_access`.");
4361 r->num_enabled_mem_access_methods =
CMD_ARGC;
4362 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4363 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0)
4365 else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0)
4367 else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0)
4373 r->mem_access_warn[i] =
true;
4383 while (isspace(reg_address_str[0]))
4386 bool is_hex_address = strncmp(reg_address_str,
"0x", 2) == 0 ||
4387 strncmp(reg_address_str,
"0X", 2) == 0;
4389 unsigned int scanned_chars;
4390 if (is_hex_address) {
4391 reg_address_str += 2;
4392 if (sscanf(reg_address_str,
"%x%n", reg_addr, &scanned_chars) != 1)
4401 if (reg_address_str[0] ==
'0' && strlen(reg_address_str) > 1)
4403 if (sscanf(reg_address_str,
"%u%n", reg_addr, &scanned_chars) != 1)
4406 return scanned_chars == strlen(reg_address_str);
4410 const char *
reg_type,
unsigned int max_val,
char **
const name_buffer)
4414 for (
char *arg = strtok(args,
","); arg; arg = strtok(
NULL,
",")) {
4415 unsigned int low = 0;
4416 unsigned int high = 0;
4419 char *dash = strchr(arg,
'-');
4420 char *equals = strchr(arg,
'=');
4422 if (!dash && !equals) {
4425 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
4428 }
else if (dash && !equals) {
4432 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4436 const char *high_num_in = dash + 1;
4438 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4443 LOG_ERROR(
"Incorrect range encountered [%u, %u].",
low, high);
4446 }
else if (!dash && equals) {
4450 LOG_ERROR(
"Failed to parse '%s' - not a valid decimal or hexadecimal number.",
4455 const char *
const reg_name_in = equals + 1;
4456 const size_t reg_type_len = strlen(
reg_type);
4458 *name_buffer = calloc(1, strlen(reg_name_in) + reg_type_len + 2);
4459 name = *name_buffer;
4465 name[reg_type_len] =
'_';
4467 unsigned int scanned_chars;
4469 if (sscanf(reg_name_in,
"%[_a-zA-Z0-9]%n", scan_dst, &scanned_chars) != 1 ||
4470 scanned_chars != strlen(reg_name_in)) {
4471 LOG_ERROR(
"Invalid characters in register name '%s'.", reg_name_in);
4475 LOG_ERROR(
"Invalid argument '%s'.", arg);
4481 if (high > max_val) {
4482 LOG_ERROR(
"Cannot expose %s register number 0x%x, maximum allowed value is 0x%x.",
4490 if (entry->
low <= high && low <= entry->high) {
4493 "Register %u has already been exposed previously",
reg_type,
low);
4495 LOG_WARNING(
"Overlapping register ranges - Register range starting from %u overlaps "
4496 "with already exposed register/range at %u.",
low, entry->
low);
4515 *name_buffer =
NULL;
4523 const char *
reg_type,
unsigned int max_val)
4525 char *args = strdup(tcl_arg);
4530 char *name_buffer =
NULL;
4546 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4564 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4582 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
4593 unsigned int index = 0;
4611 if (r->authdata_read) {
4626 unsigned int index = 0;
4641 if (!r->authdata_write) {
4646 return r->authdata_write(
target, value, index);
4653 if (!r || !r->get_dmi_address)
4655 return r->get_dmi_address(
target, dm_address);
4687 if (!r->dmi_write) {
4691 const int result = r->dmi_write(
target, dmi_address, value);
4699 const bool progbuf_touched =
4702 const bool dm_deactivated =
4705 if (progbuf_touched || dm_deactivated) {
4706 if (r->invalidate_cached_progbuf) {
4714 r->invalidate_cached_progbuf(
target);
4717 "invalidate_cached_progbuf() is not implemented.");
4728 uint32_t dmi_address;
4744 uint32_t dmi_address, value;
4757 uint32_t dm_address;
4774 uint32_t dm_address, value;
4795 r->reset_delays_wait = wait;
4807 if (!strcmp(
CMD_ARGV[0],
"idcode"))
4809 else if (!strcmp(
CMD_ARGV[0],
"dtmcs"))
4811 else if (!strcmp(
CMD_ARGV[0],
"dmi"))
4824 if (!strcmp(
CMD_ARGV[0],
"normal")) {
4826 }
else if (!strcmp(
CMD_ARGV[0],
"reversed")) {
4838 uint8_t irwidth = 0;
4841 if (CMD_ARGC < 1 || CMD_ARGC > 2)
4856 LOG_INFO(
"Nested Tap based Bscan Tunnel Selected");
4858 LOG_INFO(
"Simple Register based Bscan Tunnel Selected");
4860 LOG_INFO(
"Invalid Tunnel type selected ! : selecting default Nested Tap Type");
4877 LOG_INFO(
"Bscan tunnel IR 0x%x selected", ir_id);
4888 static const struct jim_nvp nvp_maskisr_modes[] = {
4891 { .name =
NULL, .value = -1 },
4928 const char *mode_str;
4940 assert(0 &&
"Unexpected execution mode");
4941 mode_str =
"unexpected";
4946 LOG_WARNING(
"DEPRECATED! use '%s cget -ebreak' not '%s'",
4949 config->dcsr_ebreak_fields[
mode] ?
"on" :
"off");
4957 config->dcsr_ebreak_fields[
mode] = ebreak_ctl;
5016 "doesn't support setting more than one at a time.");
5027 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5030 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5032 else if (!strcmp(
CMD_ARGV[i],
"nmi"))
5034 else if (!strcmp(
CMD_ARGV[i],
"m"))
5036 else if (!strcmp(
CMD_ARGV[i],
"s"))
5038 else if (!strcmp(
CMD_ARGV[i],
"u"))
5043 if (!nmi && interrupts == 0) {
5044 LOG_ERROR(
"Doesn't make sense to set itrigger with "
5045 "mie_bits=0 and without nmi.");
5047 }
else if (!vs && !vu && !m && !s && !u) {
5048 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5049 "least one of vs, vu, m, s, or u.");
5057 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5058 return riscv_clear_trigger(
CMD, ITRIGGER_UNIQUE_ID,
"itrigger");
5061 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5081 "doesn't support setting more than one at a time.");
5089 bool pending =
false;
5090 unsigned int count = 0;
5092 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5095 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5097 else if (!strcmp(
CMD_ARGV[i],
"pending"))
5099 else if (!strcmp(
CMD_ARGV[i],
"m"))
5101 else if (!strcmp(
CMD_ARGV[i],
"s"))
5103 else if (!strcmp(
CMD_ARGV[i],
"u"))
5109 LOG_ERROR(
"Doesn't make sense to set icount trigger with "
5112 }
else if (!vs && !vu && !m && !s && !u) {
5113 LOG_ERROR(
"Doesn't make sense to set itrigger without at "
5114 "least one of vs, vu, m, s, or u.");
5122 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5123 return riscv_clear_trigger(
CMD, ICOUNT_UNIQUE_ID,
"icount trigger");
5126 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5146 "doesn't support setting more than one at a time.");
5156 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
5159 else if (!strcmp(
CMD_ARGV[i],
"vu"))
5161 else if (!strcmp(
CMD_ARGV[i],
"m"))
5163 else if (!strcmp(
CMD_ARGV[i],
"s"))
5165 else if (!strcmp(
CMD_ARGV[i],
"u"))
5170 if (exception_codes == 0) {
5171 LOG_ERROR(
"Doesn't make sense to set etrigger with "
5172 "exception_codes=0.");
5174 }
else if (!vs && !vu && !m && !s && !u) {
5175 LOG_ERROR(
"Doesn't make sense to set etrigger without at "
5176 "least one of vs, vu, m, s, or u.");
5184 }
else if (!strcmp(
CMD_ARGV[0],
"clear")) {
5185 return riscv_clear_trigger(
CMD, ETRIGGER_UNIQUE_ID,
"etrigger");
5188 LOG_ERROR(
"First argument must be either 'set' or 'clear'.");
5199 if (CMD_ARGC < 2 || CMD_ARGC > 3)
5225 int result = r->access_memory(
target, args);
5239 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
5240 if (r->sample_config.bucket[i].enabled) {
5242 r->sample_config.bucket[i].address,
5243 r->sample_config.bucket[i].size_bytes);
5256 if (bucket >
ARRAY_SIZE(r->sample_config.bucket)) {
5261 if (!strcmp(
CMD_ARGV[1],
"clear")) {
5262 r->sample_config.bucket[bucket].enabled =
false;
5268 if (r->sample_config.bucket[bucket].size_bytes != 4 &&
5269 r->sample_config.bucket[bucket].size_bytes != 8) {
5274 r->sample_config.bucket[bucket].size_bytes = 4;
5277 r->sample_config.bucket[bucket].enabled =
true;
5280 if (!r->sample_buf.buf) {
5281 r->sample_buf.size = 1024 * 1024;
5282 r->sample_buf.buf = malloc(r->sample_buf.size);
5286 r->sample_buf.used = 0;
5288 r->sample_config.enabled =
true;
5301 bool base64 =
false;
5303 if (!strcmp(
CMD_ARGV[0],
"base64")) {
5314 r->sample_buf.used,
NULL);
5324 while (i < r->sample_buf.used) {
5325 uint8_t
command = r->sample_buf.buf[i++];
5327 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5331 uint32_t timestamp =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5336 r->sample_config.bucket[
command].address);
5337 if (r->sample_config.bucket[
command].size_bytes == 4) {
5338 uint32_t value =
buf_get_u32(r->sample_buf.buf + i, 0, 32);
5341 }
else if (r->sample_config.bucket[
command].size_bytes == 8) {
5342 uint64_t value =
buf_get_u64(r->sample_buf.buf + i, 0, 64);
5347 r->sample_config.bucket[
command].size_bytes);
5362 r->sample_buf.used = 0;
5367 const char *key,
unsigned int value,
bool is_available)
5370 snprintf(full_key,
sizeof(full_key),
"%s.%s", section, key);
5394 const bool trigger_count_available =
5396 riscv_print_info_line_if_available(
CMD,
"hart",
"trigger_count",
5397 r->trigger_count, trigger_count_available);
5406 if (CMD_ARGC < 1 || CMD_ARGC > 16)
5414 "only supported on v0.13 or v1.0 targets.");
5420 "program buffer, target not halted.");
5433 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
5461 bool enable_for_wp =
true;
5464 enable_for_wp =
true;
5465 else if (!strcmp(
CMD_ARGV[1],
"none"))
5466 enable_for_wp =
false;
5471 r->wp_allow_equality_match_trigger = enable_for_wp;
5472 r->wp_allow_napot_trigger = enable_for_wp;
5473 r->wp_allow_ge_lt_trigger = enable_for_wp;
5474 }
else if (!strcmp(
CMD_ARGV[0],
"eq")) {
5475 r->wp_allow_equality_match_trigger = enable_for_wp;
5476 }
else if (!strcmp(
CMD_ARGV[0],
"napot")) {
5477 r->wp_allow_napot_trigger = enable_for_wp;
5478 }
else if (!strcmp(
CMD_ARGV[0],
"ge_lt")) {
5479 r->wp_allow_ge_lt_trigger = enable_for_wp;
5488 "Equality match trigger: for wp (%s)\n"
5489 "NAPOT trigger: for wp (%s)\n"
5490 "ge-lt chained triggers: for wp (%s)",
5491 r->wp_allow_equality_match_trigger ?
"enabled" :
"disabled",
5492 r->wp_allow_napot_trigger ?
"enabled" :
"disabled",
5493 r->wp_allow_ge_lt_trigger ?
"enabled" :
"disabled");
5503 const char *separator =
"";
5504 for (
riscv_reg_t t = 0; t < r->trigger_count; ++t) {
5505 if (r->reserved_triggers[t]) {
5529 if (r->trigger_count == 0) {
5533 if (t >= r->trigger_count) {
5535 " does not exist. There are only %u triggers"
5536 " on the target (with indexes 0 .. %u).",
5537 t, r->trigger_count, r->trigger_count - 1);
5540 if (r->trigger_unique_id[t] != -1) {
5542 " is already in use and can not be reserved.", t);
5581 .
name =
"dump_sample_buf",
5582 .handler = handle_dump_sample_buf_command,
5584 .usage =
"[base64]",
5585 .help =
"Print the contents of the sample buffer, and clear the buffer."
5589 .handler = handle_info,
5592 .help =
"Displays some information OpenOCD detected about the target."
5595 .name =
"memory_sample",
5596 .handler = handle_memory_sample_command,
5598 .usage =
"bucket address|clear [size=4]",
5599 .help =
"Causes OpenOCD to frequently read size bytes at the given address."
5602 .name =
"repeat_read",
5603 .handler = handle_repeat_read,
5605 .usage =
"count address [size=4]",
5606 .help =
"Repeatedly read the value at address."
5609 .name =
"set_command_timeout_sec",
5610 .handler = riscv_set_command_timeout_sec,
5613 .help =
"Set the wall-clock timeout (in seconds) for individual commands"
5616 .name =
"set_reset_timeout_sec",
5617 .handler = riscv_set_reset_timeout_sec,
5620 .help =
"DEPRECATED. Use 'riscv set_command_timeout_sec' instead."
5623 .name =
"set_mem_access",
5624 .handler = riscv_set_mem_access,
5626 .usage =
"method1 [method2] [method3]",
5627 .help =
"Set which memory access methods shall be used and in which order "
5628 "of priority. Method can be one of: 'progbuf', 'sysbus' or 'abstract'."
5631 .name =
"expose_csrs",
5632 .handler = riscv_set_expose_csrs,
5634 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5635 .help =
"Configure a list of inclusive ranges for CSRs to expose in "
5636 "addition to the standard ones. This must be executed before "
5640 .name =
"expose_custom",
5641 .handler = riscv_set_expose_custom,
5643 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...[,n15[-m15|=name15]]",
5644 .help =
"Configure a list of inclusive ranges for custom registers to "
5645 "expose. custom0 is accessed as abstract register number 0xc000, "
5646 "etc. This must be executed before `init`."
5649 .name =
"hide_csrs",
5650 .handler = riscv_hide_csrs,
5652 .usage =
"{n0|n-m0}[,n1|n-m1]......",
5653 .help =
"Configure a list of inclusive ranges for CSRs to hide from gdb. "
5654 "Hidden registers are still available, but are not listed in "
5655 "gdb target description and `reg` command output. "
5656 "This must be executed before `init`."
5659 .name =
"authdata_read",
5660 .handler = riscv_authdata_read,
5663 .help =
"Return the 32-bit value read from authdata or authdata0 "
5664 "(index=0), or authdata1 (index=1)."
5667 .name =
"authdata_write",
5668 .handler = riscv_authdata_write,
5670 .usage =
"[index] value",
5671 .help =
"Write the 32-bit value to authdata or authdata0 (index=0), "
5672 "or authdata1 (index=1)."
5676 .handler = handle_riscv_dmi_read,
5679 .help =
"Read and return 32-bit value from the given address on the "
5683 .name =
"dmi_write",
5684 .handler = handle_riscv_dmi_write,
5686 .usage =
"address value",
5687 .help =
"Write a 32-bit value to the given address on the RISC-V DMI bus."
5691 .handler = handle_riscv_dm_read,
5693 .usage =
"reg_address",
5694 .help =
"Read and return 32-bit value from a debug module's register "
5699 .handler = handle_riscv_dm_write,
5701 .usage =
"reg_address value",
5702 .help =
"Write a 32-bit value to the debug module's register at "
5706 .name =
"reset_delays",
5707 .handler = riscv_reset_delays,
5710 .help =
"OpenOCD learns how many Run-Test/Idle cycles are required "
5711 "between scans to avoid encountering the target being busy. This "
5712 "command resets those learned values after `wait` scans. It's only "
5713 "useful for testing OpenOCD itself."
5716 .name =
"resume_order",
5717 .handler = riscv_resume_order,
5719 .usage =
"normal|reversed",
5720 .help =
"Choose the order that harts are resumed in when `hasel` is not "
5721 "supported. Normal order is from lowest hart index to highest. "
5722 "Reversed order is from highest hart index to lowest."
5726 .handler = riscv_set_ir,
5728 .usage =
"idcode|dtmcs|dmi value",
5729 .help =
"Set IR value for specified JTAG register."
5732 .name =
"use_bscan_tunnel",
5733 .handler = riscv_use_bscan_tunnel,
5735 .usage =
"value [type]",
5736 .help =
"Enable or disable use of a BSCAN tunnel to reach DM."
5739 .name =
"set_bscan_tunnel_ir",
5740 .handler = riscv_set_bscan_tunnel_ir,
5743 .help =
"Specify the JTAG TAP IR used to access the bscan tunnel. "
5744 "By default it is 0x23 << (ir_length - 6), which map some "
5745 "Xilinx FPGA (IR USER4)"
5748 .name =
"set_maskisr",
5749 .handler = riscv_set_maskisr,
5751 .help =
"mask riscv interrupts",
5752 .usage =
"['off'|'steponly']",
5755 .name =
"set_ebreakm",
5756 .handler = riscv_set_ebreakm,
5758 .usage =
"[on|off]",
5759 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5760 "'<target_name> cget -ebreak'"
5763 .name =
"set_ebreaks",
5764 .handler = riscv_set_ebreaks,
5766 .usage =
"[on|off]",
5767 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5768 "'<target_name> cget -ebreak'"
5771 .name =
"set_ebreaku",
5772 .handler = riscv_set_ebreaku,
5774 .usage =
"[on|off]",
5775 .help =
"DEPRECATED! use '<target_name> configure -ebreak' or "
5776 "'<target_name> cget -ebreak'"
5780 .handler = riscv_etrigger,
5782 .usage =
"set [vs] [vu] [m] [s] [u] <exception_codes>|clear",
5783 .help =
"Set or clear a single exception trigger."
5787 .handler = riscv_icount,
5789 .usage =
"set [vs] [vu] [m] [s] [u] [pending] <count>|clear",
5790 .help =
"Set or clear a single instruction count trigger."
5794 .handler = riscv_itrigger,
5796 .usage =
"set [vs] [vu] [nmi] [m] [s] [u] <mie_bits>|clear",
5797 .help =
"Set or clear a single interrupt trigger."
5800 .name =
"exec_progbuf",
5801 .handler = riscv_exec_progbuf,
5803 .usage =
"instr1 [instr2 [... instr16]]",
5804 .help =
"Execute a sequence of 32-bit instructions using the program buffer. "
5805 "The final ebreak instruction is added automatically, if needed."
5808 .name =
"set_enable_trigger_feature",
5809 .handler = riscv_set_enable_trigger_feature,
5811 .usage =
"[('eq'|'napot'|'ge_lt'|'all') ('wp'|'none')]",
5812 .help =
"Control whether OpenOCD is allowed to use certain RISC-V trigger features for watchpoints."
5815 .name =
"reserve_trigger",
5816 .handler = handle_reserve_trigger,
5819 .usage =
"[index ('on'|'off')]",
5820 .help =
"Controls which RISC-V triggers shall not be touched by OpenOCD.",
5823 .name =
"virt2phys_mode",
5824 .handler = handle_riscv_virt2phys_mode,
5826 .usage =
"['sw'|'hw'|'off']",
5827 .help =
"Configure the virtual address translation mode: "
5828 "sw - translate vaddr to paddr by manually traversing page tables, "
5829 "hw - translate vaddr to paddr by hardware, "
5830 "off - no address translation."
5833 .name =
"autofence",
5834 .handler = riscv_set_autofence,
5836 .usage =
"[on|off]",
5837 .help =
"When on (default), OpenOCD will automatically execute fence instructions in some situations. "
5838 "When off, users need to take care of memory coherency themselves, for example by using "
5839 "`riscv exec_progbuf` to execute fence or CMO instructions."
5865 .help =
"RISC-V Command Group",
5872 .help =
"ARM Command Group",
5888 return r->data_bits(
target);
5947 memset(r, 0,
sizeof(*r));
6007 *old_mstatus = current_mstatus;
6022 LOG_TARGET_WARNING(
target,
"OpenOCD might have affected the program when it restored the interrupt bits after single-step.");
6023 LOG_TARGET_WARNING(
target,
"Hint: Use 'riscv set_maskisr off' to prevent OpenOCD from touching mstatus during single-step.");
6051 if (letter >=
'a' && letter <=
'z')
6053 else if (letter >=
'A' && letter <=
'Z')
6057 return r->misa &
BIT(num);
6075 assert(r->get_hart_state);
6086 return r->halt_reason(
target);
6092 return r->get_progbufsize(
target);
6098 return r->write_progbuf(
target, index, insn);
6104 return r->read_progbuf(
target, index);
6110 return r->execute_progbuf(
target, cmderr);
6116 r->fill_dmi_write(
target, buf, a, d);
6122 r->fill_dmi_read(
target, buf, a);
6128 r->fill_dm_nop(
target, buf);
6134 return r->get_dmi_address_bits(
target);
6148 if (tselect_rb != index)
6161 assert(trigger_tinfo);
6166 if (tinfo == 0 || tinfo & 0x1)
6168 *trigger_tinfo = tinfo;
6174 *trigger_tinfo = 1 <<
type;
6180 bool dmode_is_set =
false;
6185 dmode_is_set =
true;
6220 if (r->triggers_enumerated)
6234 "Assuming that triggers are not implemented.");
6235 r->triggers_enumerated =
true;
6236 r->trigger_count = 0;
6237 free(r->reserved_triggers);
6238 r->reserved_triggers =
NULL;
6256 for (; t <
ARRAY_SIZE(r->trigger_tinfo); ++t) {
6274 t, r->trigger_tinfo[t]);
6283 r->triggers_enumerated =
true;
6284 r->trigger_count = t;
6286 free(r->reserved_triggers);
6287 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 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 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 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 enum @125 resume_order
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)
#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
A TCL -ish GetOpt like code.
Name Value Pairs, aka: NVP.
unsigned int ir_length
size of instruction register
struct match_triggers_tdata1_fields::@127 chain
struct match_triggers_tdata1_fields::@128 match
struct match_triggers_tdata1_fields::@126 size
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(* arch_state)(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 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