85 #define RISCV013_INFO(r) riscv013_info_t *r = get_info(target)
103 #define CMDERR_NONE DM_ABSTRACTCS_CMDERR_NONE
104 #define CMDERR_BUSY DM_ABSTRACTCS_CMDERR_BUSY
105 #define CMDERR_NOT_SUPPORTED DM_ABSTRACTCS_CMDERR_NOT_SUPPORTED
106 #define CMDERR_EXCEPTION DM_ABSTRACTCS_CMDERR_EXCEPTION
107 #define CMDERR_HALT_RESUME DM_ABSTRACTCS_CMDERR_HALT_RESUME
108 #define CMDERR_OTHER DM_ABSTRACTCS_CMDERR_OTHER
110 #define HART_INDEX_MULTIPLE -1
111 #define HART_INDEX_UNKNOWN -2
134 uint32_t progbuf_cache[16];
155 uint32_t lhs = *(
const uint32_t *)p_lhs;
156 uint32_t rhs = *(
const uint32_t *)p_rhs;
184 size_t old_size = cache->
size;
185 size_t new_size = old_size + 1;
186 size_t entry_size =
sizeof(*cache->
commands);
190 LOG_ERROR(
"Reallocation to %zu bytes failed", new_size * entry_size);
196 cache->
size = new_size;
229 unsigned int dtmcs_idle;
238 struct ac_cache ac_not_supported_cache;
268 assert(
info->version_specific);
269 return info->version_specific;
318 target_entry = calloc(1,
sizeof(*target_entry));
356 return default_context;
363 .abits = { .value =
info->abits, .is_set =
true },
384 #define LOG_DEBUG_REG(t, r, v) log_debug_reg(t, r##_ORDINAL, v, __FILE__, __LINE__, __func__)
390 if (hart_index >= 0) {
418 bool need_ir_scan =
false;
422 if (other_tap != tap) {
424 if (!other_tap->bypass) {
457 memset(&
info->learned_delays, 0,
sizeof(
info->learned_delays));
463 if (r->reset_delays_wait < 0) {
464 assert(r->reset_delays_wait == -1);
467 if ((
size_t)r->reset_delays_wait >= finished_scans) {
468 r->reset_delays_wait -= finished_scans;
471 r->reset_delays_wait = -1;
473 "resetting learned delays (reset_delays_wait counter expired)");
483 base =
info->dm->base;
537 uint32_t next_dm = 0;
538 unsigned int count = 1;
543 uint32_t current_dm = next_dm;
554 if (next_dm >>
info->abits) {
556 "which is the width of the DMI bus address. This is a HW bug",
576 if (dmstatus_version != 2 && dmstatus_version != 3) {
577 LOG_ERROR(
"OpenOCD only supports Debug Module version 2 (0.13) and 3 (1.0), not "
578 "%" PRId32
" (dmstatus=0x%" PRIx32
"). This error might be caused by a JTAG "
579 "signal issue. Try reducing the JTAG clock speed.",
582 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
583 "(dmstatus=0x%x). Use `riscv authdata_read` and "
584 "`riscv authdata_write` commands to authenticate.", *dmstatus);
619 LOG_ERROR(
"BUG: Target %s is not assigned to any RISC-V debug module",
632 "potentially unrecoverable error detected - could not read abstractcs");
643 "Timed out after %ds waiting for busy to go low (abstractcs=0x%" PRIx32
"). "
644 "Increase the timeout with riscv set_command_timeout_sec.",
650 "BUG: dm->abstract_cmd_maybe_busy had not been set when starting an abstract command.");
662 #define ABSTRACT_COMMAND_BATCH_SIZE 2
675 const struct riscv_batch *batch,
size_t abstractcs_read_key,
679 abstractcs_read_key);
693 LOG_ERROR(
"BUG: Target %s is not assigned to any RISC-V debug module",
704 "Abstract Command execution failed (abstractcs.cmderr = %" PRIx32
").",
724 assert(
false &&
"Unknown command type value");
732 "command 0x%" PRIx32
" as not supported",
command);
734 command, __FILE__, __LINE__, __func__);
770 abstractcs_read_key, cmderr);
788 unsigned int size_bits)
790 assert(size_bits >= 32);
791 assert(size_bits % 32 == 0);
792 const unsigned int size_in_words = size_bits / 32;
793 const unsigned int offset = index * size_in_words;
794 for (
unsigned int i = 0; i < size_in_words; ++i) {
801 unsigned int index,
unsigned int size_bits)
803 assert(size_bits >= 32);
804 assert(size_bits % 32 == 0);
805 const unsigned int size_in_words = size_bits / 32;
806 assert(size_in_words *
sizeof(uint32_t) <=
sizeof(
riscv_reg_t));
808 for (
unsigned int i = 0; i < size_in_words; ++i) {
816 unsigned int index,
unsigned int size_bits)
819 assert(size_bits >= 32);
820 assert(size_bits % 32 == 0);
821 const unsigned char size_in_words = size_bits / 32;
840 riscv_reg_t value,
unsigned int index,
unsigned int size_bits)
842 assert(size_bits % 32 == 0);
843 const unsigned int size_in_words = size_bits / 32;
844 assert(value <= UINT32_MAX || size_in_words > 1);
845 const unsigned int offset = index * size_in_words;
847 for (
unsigned int i = 0; i < size_in_words; ++i) {
860 unsigned int offset = index * size_bits / 32;
878 unsigned int size, uint32_t flags)
926 PRIx32
" is cached as not supported",
command);
928 command, __FILE__, __LINE__, __func__);
978 assert(size_bits % 32 == 0);
979 const unsigned int size_in_words = size_bits / 32;
980 const unsigned int batch_size = size_in_words
995 abstractcs_read_key, &cmderr);
1031 unsigned int width,
bool postincrement,
bool is_write)
1052 if (
info->progbufsize < 1) {
1084 if (written == (uint32_t)
info->progbuf_address) {
1086 info->progbuf_address);
1091 info->progbuf_address);
1121 assert(orig_mstatus);
1136 "The target must be halted to modify and then restore mstatus");
1144 if ((new_mstatus & field_mask) != 0)
1147 new_mstatus =
set_field(new_mstatus, field_mask, 1);
1190 unsigned int size_bytes)
1193 while (alignment < size_bytes)
1201 if (
info->dataaccess == 1) {
1204 if (
info->dataaddr & (1<<11))
1223 scratch->
hart_address = (
info->progbuf_address + program_size + alignment - 1) &
1227 info->progbufsize)) {
1244 "a work area with 'configure -work-area-phys'.", size_bytes);
1265 *value |= ((uint64_t)v) << 32;
1273 *value |= ((uint64_t)v) << 32;
1672 "Increase the timeout with riscv set_command_timeout_sec.",
1694 original_dcsr = dcsr;
1702 if (dcsr != original_dcsr &&
1705 info->dcsr_ebreak_is_set =
true;
1738 if (
info->haltgroup_supported) {
1744 "Some harts may be unexpectedly halted.");
1760 if (
info->haltgroup_supported) {
1766 "Some harts may be unexpectedly halted.",
target->
smp);
1787 free(
info->version_specific);
1796 assert(
group <= 31);
1821 uint32_t abstractcs;
1839 assert(dm &&
"DM is expected to be already allocated.");
1840 assert(!dm->
was_reset &&
"Attempt to reset an already-reset debug module.");
1869 "Increase the timeout with 'riscv set_command_timeout_sec'.",
1891 "Increase the timeout with 'riscv set_command_timeout_sec'.",
1947 for (
int i = 0; i < max_hart_count; ++i) {
2002 uint32_t dtmcontrol;
2032 if (
info->abits == 0) {
2034 "dtmcs.abits is zero. Check JTAG connectivity/board power");
2046 "lower than the minimum:");
2073 if (dmstatus_version != 2 && dmstatus_version != 3) {
2088 "(dmstatus=0x%x). Use `riscv authdata_read` and "
2089 "`riscv authdata_write` commands to authenticate.", dmstatus);
2097 uint32_t abstractcs;
2104 info->datacount,
info->progbufsize);
2110 "target. Memory may not always appear consistent. "
2111 "(progbufsize=%d, impebreak=%d)",
info->progbufsize,
2123 const bool hart_halted_at_examine_start = state_at_examine_start ==
RISCV_STATE_HALTED;
2124 if (!hart_halted_at_examine_start) {
2128 info->index, __func__);
2155 if (
info->haltgroup_supported)
2191 uint32_t before, after;
2224 for (
unsigned int i = 0; i < r->num_enabled_mem_access_methods; i++) {
2271 riscv_print_info_line(
CMD,
"dm",
"abits",
info->abits);
2272 riscv_print_info_line(
CMD,
"dm",
"progbufsize",
info->progbufsize);
2291 unsigned int encoded_vsew =
2300 if (encoded_vsew == 3 && r->vsew64_supported ==
YNM_MAYBE) {
2307 r->vsew64_supported =
YNM_NO;
2311 r->vsew64_supported =
YNM_YES;
2313 *debug_vsew = encoded_vsew == 3 ? 64 : 32;
2319 unsigned int *debug_vl,
unsigned int *debug_vsew)
2321 assert(orig_mstatus);
2330 "Unable to access vector register: target not halted");
2371 unsigned int debug_vl, debug_vsew;
2374 &debug_vl, &debug_vsew) !=
ERROR_OK)
2383 for (
unsigned int i = 0; i < debug_vl; i++) {
2402 buf_set_u64(value, debug_vsew * i, debug_vsew, v);
2405 "Failed to execute vmv/vslide1down while reading %s",
2418 const uint8_t *value)
2426 unsigned int debug_vl, debug_vsew;
2429 &debug_vl, &debug_vsew) !=
ERROR_OK)
2441 for (
unsigned int i = 0; i < debug_vl; i++) {
2458 switch (size_bytes) {
2488 const uint32_t values[] = {(uint32_t)
address, (uint32_t)(
address >> 32), 0, 0};
2490 assert(reg_count > 0);
2494 for (
unsigned int i = reg_count - 1; i > 0; --i)
2519 r->reset_delays_wait >= 0,
2520 r->reset_delays_wait);
2526 const size_t finished_scans = batch->
used_scans;
2542 size_t finished_scans = 0;
2550 &
info->learned_delays,
2551 r->reset_delays_wait >= 0,
2552 r->reset_delays_wait);
2556 assert(new_finished_scans >= finished_scans);
2558 finished_scans = new_finished_scans;
2579 "The target is either really slow or broken. You could increase "
2580 "the timeout with riscv set_command_timeout_sec.",
2588 switch (size_bytes) {
2611 if (sbasize == 0 || sbasize > 64) {
2622 uint32_t sbcs_valid =
false;
2624 uint32_t sbaddress0 = 0;
2625 bool sbaddress0_valid =
false;
2626 uint32_t sbaddress1 = 0;
2627 bool sbaddress1_valid =
false;
2630 const unsigned int repeat = 5;
2632 unsigned int enabled_count = 0;
2634 if (
config->bucket[i].enabled)
2645 target, 1 + enabled_count * 5 * repeat);
2649 unsigned int result_bytes = 0;
2650 for (
unsigned int n = 0; n < repeat; n++) {
2652 if (
config->bucket[i].enabled) {
2655 config->bucket[i].size_bytes);
2660 if (enabled_count == 1)
2663 if (!sbcs_valid || sbcs_write != sbcs) {
2671 (!sbaddress1_valid ||
2672 sbaddress1 !=
config->bucket[i].address >> 32)) {
2673 sbaddress1 =
config->bucket[i].address >> 32;
2676 sbaddress1_valid =
true;
2678 if (!sbaddress0_valid ||
2679 sbaddress0 != (
config->bucket[i].address & 0xffffffff)) {
2680 sbaddress0 =
config->bucket[i].address;
2684 sbaddress0_valid =
true;
2686 if (
config->bucket[i].size_bytes > 4)
2691 result_bytes += 1 +
config->bucket[i].size_bytes;
2696 if (buf->
used + result_bytes >= buf->
size) {
2742 unsigned int read_count = 0;
2743 for (
unsigned int n = 0; n < repeat; n++) {
2745 if (
config->bucket[i].enabled) {
2748 if (
config->bucket[i].size_bytes > 4)
2754 buf->
used += 1 +
config->bucket[i].size_bytes;
2787 info->dcsr_ebreak_is_set =
false;
2834 "(due to target becoming unavailable).");
2838 info->dcsr_ebreak_is_set =
false;
2845 if (!
info->dcsr_ebreak_is_set &&
2877 generic_info->dmi_read = &
dmi_read;
2882 generic_info->print_info = &riscv013_print_info;
2887 generic_info->tick = &
tick;
2889 if (!generic_info->version_specific) {
2891 if (!generic_info->version_specific)
2897 info->progbufsize = -1;
2951 if (
config->dcsr_ebreak_fields[i])
2966 uint32_t control = 0;
2974 if (hartsel_changed) {
2995 "dmstatus=0x%x (allunavail=%s, allhavereset=%s); "
2996 "Increase the timeout with riscv set_command_timeout_sec.",
3092 uint64_t value_l,
bool is_read)
3098 sprintf(fmt,
"M[0x%" TARGET_PRIxADDR "] %ss 0x%%016" PRIx64
"%%016" PRIx64,
3099 address, is_read ?
"read" :
"write");
3104 unsigned int size_bytes,
bool is_read)
3111 address, is_read ?
"read" :
"write", size_bytes * 2);
3112 switch (size_bytes) {
3120 value &= 0xffffffffUL;
3130 unsigned int size_bytes,
bool is_read)
3132 if (size_bytes == 16) {
3133 uint64_t value_h = ((uint64_t)sbvalue[3] << 32) | sbvalue[2];
3134 uint64_t value_l = ((uint64_t)sbvalue[1] << 32) | sbvalue[0];
3137 uint64_t value = ((uint64_t)sbvalue[1] << 32) | sbvalue[0];
3148 uint32_t sbvalue[4] = { 0 };
3151 for (
int i = (
size - 1) / 4; i >= 0; i--) {
3187 "Increase the timeout with riscv set_command_timeout_sec.",
3199 assert(mstatus_old);
3213 *mstatus_old = *mstatus;
3226 if (*mstatus != *mstatus_old &&
3234 if (*dcsr != *dcsr_old &&
3248 if (mstatus != mstatus_old &&
3253 if (dcsr != dcsr_old &&
3274 uint32_t access = 0;
3276 const int DM_SBCS_SBSINGLEREAD_OFFSET = 20;
3277 const uint32_t DM_SBCS_SBSINGLEREAD = (0x1U << DM_SBCS_SBSINGLEREAD_OFFSET);
3279 const int DM_SBCS_SBAUTOREAD_OFFSET = 15;
3280 const uint32_t DM_SBCS_SBAUTOREAD = (0x1U << DM_SBCS_SBAUTOREAD_OFFSET);
3283 if (args.
count == 1) {
3284 for (uint32_t i = 0; i < args.
count; i++) {
3290 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
3299 t_buffer += args.
size;
3300 cur_addr += args.
size;
3314 access =
set_field(access, DM_SBCS_SBAUTOREAD, 1);
3315 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
3320 while (cur_addr < fin_addr) {
3322 PRIx64, args.
size, args.
count, cur_addr);
3328 cur_addr += args.
size;
3329 t_buffer += args.
size;
3332 if (cur_addr == fin_addr && args.
count != 1) {
3355 const uint32_t increment = args.
increment;
3360 if (increment !=
size && increment != 0) {
3379 while (next_address < end_address) {
3382 if (increment ==
size)
3402 uint32_t sbvalue[4] = {0};
3411 for (uint32_t j = size_in_words - 1; j > 0; --j)
3422 for (
size_t k = 0; k <= last_key; ++k) {
3432 uint32_t sbcs_read = 0;
3483 next_address = end_address;
3504 snprintf(msg, 60,
"%s to %s memory via %s.",
3505 success ?
"Succeeded" :
"Failed",
3506 is_read ?
"read" :
"write",
3512 warn = r->mem_access_warn[method];
3513 r->mem_access_warn[method] =
false;
3530 #define LIST_OF_MEM_ACCESS_RESULTS \
3531 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_OK, OK, "ok") \
3532 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_DISABLED, DISABLED, "disabled") \
3533 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED, SKIPPED, "skipped") \
3534 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_ABSTRACT_ACCESS_CMDERR, \
3535 SKIPPED, "skipped (abstract access cmderr)") \
3536 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGBUF_NOT_PRESENT, \
3537 SKIPPED, "skipped (progbuf not present)") \
3538 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGBUF_INSUFFICIENT, \
3539 SKIPPED, "skipped (insufficient progbuf)") \
3540 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_UNSUPPORTED_ACCESS_SIZE, \
3541 SKIPPED, "skipped (unsupported access size)") \
3542 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_XLEN_TOO_SHORT, \
3543 SKIPPED, "skipped (xlen too short)") \
3544 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_TARGET_NOT_HALTED, \
3545 SKIPPED, "skipped (target not halted)") \
3546 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_TOO_LARGE_ADDRESS, \
3547 SKIPPED, "skipped (address too large)") \
3548 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_UNSUPPORTED_INCREMENT_SIZE, \
3549 SKIPPED, "skipped (increment size not supported)") \
3550 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_TARGET_SELECT_FAILED, \
3551 SKIPPED, "skipped (dm target select failed)") \
3552 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_FENCE_EXEC_FAILED, \
3553 SKIPPED, "skipped (fence execution failed)") \
3554 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_SYSBUS_ACCESS_FAILED, \
3555 SKIPPED, "skipped (sysbus access failed)") \
3556 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_REG_SAVE_FAILED, \
3557 SKIPPED, "skipped (register save failed)") \
3558 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_UNKNOWN_SYSBUS_VERSION, \
3559 SKIPPED, "skipped (unknown sysbus version)") \
3560 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGRAM_WRITE_FAILED, \
3561 SKIPPED, "skipped (program write failed)") \
3562 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGBUF_FILL_FAILED, \
3563 SKIPPED, "skipped (progbuf fill failed)") \
3564 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_WRITE_ABSTRACT_ARG_FAILED, \
3565 SKIPPED, "skipped (abstract command argument write failed)") \
3566 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PRIV_MOD_FAILED, \
3567 SKIPPED, "skipped (privilege modification failed)") \
3568 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED, FAILED, "failed") \
3569 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_DM_ACCESS_FAILED, \
3570 FAILED, "failed (DM register access failed)") \
3571 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PRIV_MOD_FAILED, \
3572 FAILED, "failed (privilege modification failed)") \
3573 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_REG_READ_FAILED, \
3574 FAILED, "failed (register read failed)") \
3575 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PROGBUF_STARTUP_FAILED, \
3576 FAILED, "failed (progbuf startup failed)") \
3577 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PROGBUF_INNER_FAILED, \
3578 FAILED, "failed (progbuf inner failed)") \
3579 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PROGBUF_TEARDOWN_FAILED, \
3580 FAILED, "failed (progbuf teardown failed)") \
3581 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_EXECUTE_ABSTRACT_FAILED, \
3582 FAILED, "failed (execute abstract failed)") \
3583 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_NO_FORWARD_PROGRESS, \
3584 FAILED, "failed (no forward progress)") \
3585 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_FENCE_EXEC_FAILED, \
3586 FAILED, "failed (fence execution failed)") \
3589 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) name,
3593 #undef MEM_ACCESS_RESULT_HANDLER
3603 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3604 case name: return MEM_ACCESS_RESULT_TYPE_##kind \
3605 == MEM_ACCESS_RESULT_TYPE_OK;
3610 #undef MEM_ACCESS_RESULT_HANDLER
3613 assert(
false &&
"Unknown memory access status");
3619 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3620 case name: return MEM_ACCESS_RESULT_TYPE_##kind \
3621 == MEM_ACCESS_RESULT_TYPE_FAILED;
3626 #undef MEM_ACCESS_RESULT_HANDLER
3629 assert(
false &&
"Unknown memory access status");
3635 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3636 case name: return MEM_ACCESS_RESULT_TYPE_##kind \
3637 == MEM_ACCESS_RESULT_TYPE_SKIPPED;
3642 #undef MEM_ACCESS_RESULT_HANDLER
3644 assert(
false &&
"Unknown memory access status");
3650 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3652 static const char *
const table[] = {
3655 #undef MEM_ACCESS_RESULT_HANDLER
3658 return table[
status.value];
3671 const char *
const access_type =
3676 "- progbuf not present", access_type);
3681 "insufficient progbuf size.", access_type);
3686 "target not halted.", access_type);
3691 "XLEN (%d) is too short for %d-bit memory args.",
3695 if (args.size > 8) {
3697 "unsupported size.", access_type);
3717 const char *
const access_type = is_read ?
"read" :
"write";
3721 "unsupported size.", access_type);
3725 if ((
sizeof(args.address) * 8 > sbasize)
3726 && (args.address >> sbasize)) {
3728 "sba only supports %u-bit address.", access_type, sbasize);
3731 if (is_read && args.increment != args.size
3733 || args.increment != 0)) {
3735 "sba %ss only support (size == increment) or also "
3736 "size==0 for sba v1.", access_type, access_type);
3749 const char *
const access_type = is_read ?
"read" :
"write";
3750 if (args.size > 8) {
3754 "unsupported size: %d bits", access_type, args.size * 8);
3760 "abstract access only supports %u-bit address.",
3764 if (is_read && args.size != args.increment) {
3766 "abstract command %ss only support (size == increment).",
3767 access_type, access_type);
3783 memset(args.read_buffer, 0, args.count * args.size);
3786 unsigned int width = args.size << 3;
3789 width,
true,
false);
3791 if (!use_aampostincrement)
3798 width,
false,
false);
3801 uint8_t *p = args.read_buffer;
3803 bool updateaddr =
true;
3804 unsigned int width32 =
MAX(
width, 32);
3805 for (uint32_t c = 0; c < args.count; c++) {
3819 if (use_aampostincrement && result !=
ERROR_OK &&
3822 "read command, but without aampostincrement");
3823 use_aampostincrement =
false;
3825 width,
false,
false);
3842 if (use_aampostincrement)
3863 unsigned int width = args.size << 3;
3868 if (!use_aampostincrement)
3875 width,
false,
true);
3878 const uint8_t *p = args.write_buffer;
3879 bool updateaddr =
true;
3880 for (uint32_t c = 0; c < args.count; c++) {
3902 if (use_aampostincrement && result !=
ERROR_OK &&
3905 "write command, but without aampostincrement");
3906 use_aampostincrement =
false;
3908 width,
false,
true);
3918 if (use_aampostincrement)
3946 if ( increment == 0 &&
3974 goto clear_abstractauto_and_fail;
3976 uint32_t abstractcs;
3978 goto clear_abstractauto_and_fail;
3990 goto clear_abstractauto_and_fail;
3992 clear_abstractauto_and_fail:
4006 uint32_t start_index, uint32_t *elements_read,
4022 uint32_t index_on_target;
4030 index_on_target = counter;
4036 index_on_target = (address_on_target - args.
address) /
4044 const uint32_t min_index_on_target = start_index + 2;
4045 if (index_on_target < min_index_on_target) {
4048 }
else if (index_on_target == min_index_on_target) {
4051 const uint32_t next_index = (index_on_target - 2);
4052 *elements_read = next_index - start_index;
4065 uint32_t start_index, uint32_t next_start_index,
4071 PRIu32
", %" PRIu32
")", start_index, next_start_index);
4072 if (start_index == next_start_index)
4086 uint32_t start_index, uint32_t elements_to_read, uint32_t *elements_read,
4091 const bool two_reads_per_element = args.
size > 4;
4092 const uint32_t reads_per_element = (two_reads_per_element ? 2 : 1);
4094 assert(elements_to_read <= UINT32_MAX / reads_per_element);
4095 const uint32_t nreads = elements_to_read * reads_per_element;
4096 for (uint32_t curr_idx = start_index, read = 0; read < nreads; ++read) {
4099 *elements_read = curr_idx - start_index;
4104 "Batch memory read encountered DMI_STATUS_FAILED on read %"
4114 curr_idx * args.
size;
4120 const bool is_odd_read = read % 2;
4122 if (two_reads_per_element && !is_odd_read) {
4126 const bool is_second_read = two_reads_per_element;
4133 *elements_read = elements_to_read;
4145 uint32_t start_index, uint32_t elements_to_read, uint32_t *elements_read)
4158 uint32_t abstractcs;
4162 uint32_t elements_to_extract_from_batch;
4168 PRIu32
", %" PRIu32
")", start_index, start_index + elements_to_read);
4169 elements_to_extract_from_batch = elements_to_read;
4174 &elements_to_extract_from_batch, args)
4185 elements_to_extract_from_batch, elements_read, args) !=
ERROR_OK)
4196 const uint32_t one_reg_used[] = {
DM_DATA0};
4197 const uint32_t reads_per_element =
size > 4 ? 2 : 1;
4198 const uint32_t *
const used_regs =
size > 4 ? two_regs_used : one_reg_used;
4200 const uint32_t end =
MIN(batch_capacity,
count);
4202 for (uint32_t j = 0; j < end; ++j) {
4207 for (uint32_t i = 0; i < reads_per_element; ++i)
4216 uint32_t index, uint32_t loop_count)
4225 loop_count - index, args.
size);
4228 args, index, elements_to_read, elements_read);
4243 "Executing one loop iteration to ensure forward progress (index=%"
4244 PRIu32
")", start_index);
4247 uint8_t *
const curr_buffer_address = args.
read_buffer +
4248 start_index * args.
size;
4251 .address = curr_target_address,
4255 uint32_t elements_read;
4260 if (elements_read != 1) {
4261 assert(elements_read == 0);
4272 uint32_t index, uint64_t value)
4290 assert(args.
size <= 8);
4293 args.
size > 4 ? 64 : 32);
4313 uint32_t increment, uint32_t
size)
4315 const bool is_repeated_read = increment == 0;
4329 if (is_repeated_read) {
4356 assert(args.count > 1 &&
"If count == 1, read_memory_progbuf_inner_one must be called");
4359 args.increment, args.size) !=
ERROR_OK)
4375 const uint32_t loop_count = args.count - 2;
4377 for (uint32_t index = 0; index < loop_count;) {
4378 uint32_t elements_read;
4384 if (elements_read == 0) {
4392 index += elements_read;
4393 assert(index <= loop_count);
4452 memset(args.read_buffer, 0, args.count * args.size);
4457 return (args.count == 1) ?
4473 const char *
const access_type = is_read ?
"reading" :
"writing";
4476 args.size, args.address);
4486 &mstatus, &mstatus_old, &dcsr, &dcsr_old) !=
ERROR_OK)
4494 mstatus, mstatus_old, dcsr, dcsr_old) !=
ERROR_OK)
4521 }
else if (sbver == 1) {
4530 MEM_ACCESS_OK : MEM_ACCESS_SKIPPED_SYSBUS_ACCESS_FAILED);
4543 const char *
const access_type = is_read ?
"reading" :
"writing";
4546 args.size, args.address);
4558 const char *
const access_type = is_read ?
"read" :
"write";
4566 "memory %s: %d", access_type, args.
size);
4577 for (
unsigned int i = 0; i < r->num_enabled_mem_access_methods; ++i) {
4591 assert(
false &&
"Unknown memory access method");
4606 " progbuf=%s, sysbus=%s, abstract=%s", access_type, args.
address,
4628 if (args.
count == 1) {
4657 PRIx64, (uint32_t)t_addr, (uint32_t)
value);
4683 while (next_address < end_address) {
4691 for (uint32_t i = (next_address - args.
address) / args.
size; i < args.
count; i++) {
4697 uint32_t sbvalue[4] = { 0 };
4698 if (args.
size > 12) {
4705 if (args.
size > 8) {
4711 if (args.
size > 4) {
4719 if (args.
size > 2) {
4720 sbvalue[0] |= ((uint32_t)p[2]) << 16;
4721 sbvalue[0] |= ((uint32_t)p[3]) << 24;
4724 sbvalue[0] |= ((uint32_t)p[1]) << 8;
4731 next_address += args.
size;
4743 if (dmi_busy_encountered)
4766 if (next_address < args.
address) {
4769 " - buggy sbautoincrement in hw?", next_address);
4785 sberror, sbaddress);
4786 if (sbaddress < args.
address) {
4790 " - buggy sbautoincrement in hw?", next_address);
4884 const uint8_t *
const curr_buff =
buffer + (address_on_target - *address_p);
4885 *address_p = address_on_target;
4886 if (*address_p == end_address) {
4904 const unsigned int writes_per_element =
size > 4 ? 2 : 1;
4911 end_address - start_address);
4917 if (writes_per_element == 2)
4923 return batch_end_address;
4946 uint32_t abstractcs;
4953 if (cmderr ==
CMDERR_NONE && !dmi_busy_encountered) {
4956 *address_p = end_address;
4958 }
else if (cmderr ==
CMDERR_BUSY || dmi_busy_encountered) {
4962 if (dmi_busy_encountered)
5027 args.write_buffer, args.size) !=
ERROR_OK)
5032 for (
target_addr_t next_addr_on_target = addr_on_target; addr_on_target != end_addr;
5033 addr_on_target = next_addr_on_target) {
5034 const uint8_t *
const curr_buff = args.write_buffer + (addr_on_target - args.address);
5036 end_addr, args.size, curr_buff) !=
ERROR_OK) {
5043 assert(next_addr_on_target - addr_on_target > 0);
5044 assert(next_addr_on_target - args.address <= (
target_addr_t)args.size * args.count);
5068 return r->impebreak;
5074 return r->progbufsize;
5173 unsigned int hawindow_count = (dm->
hart_count + 31) / 32;
5174 uint32_t *hawindow = calloc(hawindow_count,
sizeof(uint32_t));
5179 unsigned int total_selected = 0;
5180 unsigned int selected_index = 0;
5185 unsigned int index = info_013->
index;
5187 if (
info->prepped) {
5189 hawindow[index / 32] |= 1 << (index % 32);
5190 info->prepped =
false;
5192 selected_index = index;
5196 if (total_selected == 0) {
5200 }
else if (total_selected == 1) {
5211 for (
unsigned int i = 0; i < hawindow_count; i++) {
5252 for (
size_t i = 0; i < 256; ++i) {
5268 dmcontrol, dmstatus);
5279 uint32_t t_dmstatus;
5284 t_dmstatus = dmstatus;
5419 uint32_t run_program = 0;
5482 step ?
"single-step" :
"resume");
5502 for (
size_t i = 0; i < 256; ++i) {
5518 step ?
"single-step" :
"resume", dmstatus);
5522 " cancelling the resume request (dmcontrol.resumereq <- 0)");
5531 " trying to recover from a failed single-step, by requesting halt");
5545 uint32_t abstractcs;
bool riscv_batch_was_batch_busy(const struct riscv_batch *batch)
uint32_t riscv_batch_get_dmi_read_op(const struct riscv_batch *batch, size_t key)
struct riscv_batch * riscv_batch_alloc(struct target *target, size_t scans)
void riscv_batch_add_nop(struct riscv_batch *batch)
void riscv_batch_add_dmi_write(struct riscv_batch *batch, uint32_t address, uint32_t data, bool read_back, enum riscv_scan_delay_class delay_class)
size_t riscv_batch_available_scans(struct riscv_batch *batch)
uint32_t riscv_batch_get_dmi_read_data(const struct riscv_batch *batch, size_t key)
size_t riscv_batch_finished_scans(const struct riscv_batch *batch)
void riscv_batch_free(struct riscv_batch *batch)
size_t riscv_batch_add_dmi_read(struct riscv_batch *batch, uint32_t address, enum riscv_scan_delay_class delay_class)
int riscv_batch_run_from(struct riscv_batch *batch, size_t start_idx, const struct riscv_scan_delays *delays, bool resets_delays, size_t reset_delays_after)
static int riscv_scan_increase_delay(struct riscv_scan_delays *delays, enum riscv_scan_delay_class delay_class)
@ RISCV_DELAY_ABSTRACT_COMMAND
@ RISCV_DELAY_SYSBUS_READ
@ RISCV_DELAY_SYSBUS_WRITE
static size_t riscv_batch_add_dm_read(struct riscv_batch *batch, uint32_t address, enum riscv_scan_delay_class delay_type)
static void riscv_scan_set_delay(struct riscv_scan_delays *delays, enum riscv_scan_delay_class delay_class, unsigned int delay)
static unsigned int riscv_scan_get_delay(const struct riscv_scan_delays *delays, enum riscv_scan_delay_class delay_class)
static void riscv_batch_add_dm_write(struct riscv_batch *batch, uint32_t address, uint32_t data, bool read_back, enum riscv_scan_delay_class delay_type)
static const char * riscv_scan_delay_class_name(enum riscv_scan_delay_class delay_class)
bool buf_eq(const void *_buf1, const void *_buf2, unsigned int size)
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.
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define DM_ABSTRACTAUTO_AUTOEXECDATA_OFFSET
#define AC_ACCESS_REGISTER_TRANSFER
#define AC_ACCESS_REGISTER_POSTEXEC
#define CSR_DCSR_MPRVEN_ENABLED
#define DM_DMCONTROL_ACKHAVERESET
#define DM_DMSTATUS_ANYHAVERESET
#define CSR_DCSR_CAUSE_GROUP
#define DM_DMSTATUS_ALLHALTED
#define DM_SBCS_SBACCESS64
#define DM_SBCS_SBVERSION
#define DM_DMCONTROL_RESUMEREQ
#define DM_ABSTRACTCS_BUSY
#define DM_DMSTATUS_ALLRESUMEACK
#define DM_DMCONTROL_HARTSELLO_LENGTH
#define DM_SBCS_SBBUSYERROR
#define DM_DMCONTROL_HASEL_SINGLE
#define DM_ABSTRACTCS_CMDERR
#define DM_HARTINFO_DATASIZE
#define AC_ACCESS_REGISTER_REGNO
#define CSR_DCSR_EBREAKVU
#define DM_ABSTRACTCS_PROGBUFSIZE
#define DM_DMCONTROL_HASEL_MULTIPLE
#define CSR_DCSR_CAUSE_STEP
#define DM_DMSTATUS_ALLUNAVAIL
#define DM_ABSTRACTCS_DATACOUNT
#define DTM_DMI_DATA_OFFSET
#define DM_DMSTATUS_AUTHENTICATED
#define DM_SBCS_SBAUTOINCREMENT
#define DM_SBCS_SBERROR_NONE
#define AC_ACCESS_MEMORY_WRITE
#define DM_DMCONTROL_HARTSELLO
#define DM_DMCONTROL_NDMRESET
#define AC_ACCESS_REGISTER_WRITE
#define DM_DMSTATUS_ALLRUNNING
#define DTM_DMI_OP_OFFSET
#define CSR_DCSR_CAUSE_HALTREQ
#define AC_ACCESS_MEMORY_CMDTYPE
#define DM_HARTINFO_DATAACCESS
#define DTM_DTMCS_VERSION
#define DTM_DMI_OP_FAILED
#define DM_DMSTATUS_IMPEBREAK
#define DM_DMSTATUS_ANYNONEXISTENT
#define DM_DMCONTROL_DMACTIVE
#define CSR_DCSR_EBREAKVS
#define DM_DMCONTROL_HASEL
@ AC_ACCESS_MEMORY_ORDINAL
@ AC_QUICK_ACCESS_ORDINAL
@ AC_ACCESS_REGISTER_ORDINAL
#define DTM_DMI_ADDRESS_OFFSET
#define DM_SBCS_SBACCESS8
#define DTM_DTMCS_DMIRESET
#define DM_DMCONTROL_HARTSELHI_LENGTH
#define AC_ACCESS_REGISTER_AARSIZE
#define CSR_DCSR_CAUSE_EBREAK
#define DM_DMSTATUS_VERSION
#define DM_DMSTATUS_AUTHBUSY
#define DM_DMCONTROL_HARTSELHI
#define AC_ACCESS_MEMORY_AAMPOSTINCREMENT
#define DM_SBCS_SBACCESS16
#define DM_SBCS_SBREADONADDR
#define DM_DMSTATUS_ALLHAVERESET
#define DM_SBCS_SBACCESS32
#define AC_ACCESS_MEMORY_AAMSIZE
#define DM_SBCS_SBREADONDATA
#define DM_DMSTATUS_ALLNONEXISTENT
#define CSR_DCSR_CAUSE_TRIGGER
#define DM_HARTINFO_DATAADDR
#define DM_DMCONTROL_HALTREQ
#define DM_DMCS2_GROUPTYPE
#define DTM_DMI_DATA_LENGTH
#define CSR_DCSR_CAUSE_RESETHALTREQ
#define DM_ABSTRACTAUTO_AUTOEXECDATA
#define AC_ACCESS_MEMORY_AAMVIRTUAL
#define DM_SBCS_SBACCESS128
#define DTM_DMI_OP_LENGTH
#define DTM_DMI_OP_SUCCESS
#define DM_DMSTATUS_ANYRUNNING
#define DM_COMMAND_CMDTYPE
unsigned int riscv_debug_reg_to_s(char *buf, enum riscv_debug_reg_ordinal reg_ordinal, struct riscv_debug_reg_ctx context, uint64_t value, enum riscv_debug_reg_show show)
This function is used to fill a buffer with a decoded string representation of register's value.
@ RISCV_DEBUG_REG_HIDE_UNNAMED_0
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.
enum esirisc_reg_num number
static uint64_t set_field(uint64_t reg, 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 struct device_config config
const char * jtag_tap_name(const struct jtag_tap *tap)
struct jtag_tap * jtag_tap_next_enabled(struct jtag_tap *p)
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)
static int list_empty(const struct list_head *head)
#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)
void log_printf_lf(enum log_levels level, const char *file, unsigned int line, const char *function, const char *format,...)
#define LOG_TARGET_INFO(target, fmt_str,...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define ERROR_NOT_IMPLEMENTED
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(target, fmt_str,...)
#define LOG_ERROR(expr ...)
#define ERROR_TIMEOUT_REACHED
#define LOG_LEVEL_IS(FOO)
#define LOG_DEBUG(expr ...)
static uint32_t fmv_d_x(unsigned int dest, unsigned int src) __attribute__((unused))
static uint32_t csrr(unsigned int rd, unsigned int csr) __attribute__((unused))
static uint32_t vsetvl(unsigned int rd, unsigned int rs1, unsigned int rs2) __attribute__((unused))
static uint32_t vmv_x_s(unsigned int rd, unsigned int vs2) __attribute__((unused))
static uint32_t fsd(unsigned int src, unsigned int base, int16_t offset) __attribute__((unused))
static uint32_t fmv_x_w(unsigned int dest, unsigned int src) __attribute__((unused))
static uint32_t fmv_w_x(unsigned int dest, unsigned int src) __attribute__((unused))
static uint32_t vslide1down_vx(unsigned int vd, unsigned int vs2, unsigned int rs1, bool vm) __attribute__((unused))
static uint32_t auipc(unsigned int dest) __attribute__((unused))
static uint32_t sw(unsigned int src, unsigned int base, int16_t offset) __attribute__((unused))
static uint32_t fmv_x_d(unsigned int dest, unsigned int src) __attribute__((unused))
static uint32_t fld(unsigned int dest, unsigned int base, int16_t offset) __attribute__((unused))
int riscv_program_fence_i(struct riscv_program *p)
int riscv_program_write(struct riscv_program *program)
int riscv_program_fence_rw_rw(struct riscv_program *p)
int riscv_program_store(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int16_t offset, unsigned int size)
int riscv_program_addi(struct riscv_program *p, enum gdb_regno d, enum gdb_regno s, int16_t u)
int riscv_program_insert(struct riscv_program *p, riscv_insn_t i)
int riscv_program_load(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int16_t offset, unsigned int size)
int riscv_program_csrr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno csr)
int riscv_program_init(struct riscv_program *p, struct target *target)
int riscv_program_csrw(struct riscv_program *p, enum gdb_regno s, enum gdb_regno csr)
int riscv_program_ebreak(struct riscv_program *p)
int riscv_program_exec(struct riscv_program *p, struct target *t)
Add ebreak and execute the program.
#define RISCV013_MAX_PROGBUF_SIZE
@ RISCV_PROGBUF_EXEC_RESULT_EXCEPTION
static int step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
static int riscv013_write_progbuf(struct target *target, unsigned int index, riscv_insn_t d)
static int register_write_abstract(struct target *target, enum gdb_regno number, riscv_reg_t value)
static int dmi_write(struct target *target, uint32_t address, uint32_t value)
static void batch_fill_sb_write_address(const struct target *target, struct riscv_batch *batch, target_addr_t address, enum riscv_scan_delay_class sbaddr0_delay)
static int read_word_from_dm_data_regs(struct target *target, const struct riscv_mem_access_args args, uint32_t index)
static int scratch_write64(struct target *target, scratch_mem_t *scratch, uint64_t value)
static int examine_dm(struct target *target)
static riscv_reg_t abstract_data_get_from_batch(struct riscv_batch *batch, unsigned int index, unsigned int size_bits)
static int examine_progbuf(struct target *target)
static int write_memory_bus_v1(struct target *target, const struct riscv_mem_access_args args)
static struct mem_access_result mem_access_result(enum mem_access_result_enum value)
static int csr_write_progbuf(struct target *target, enum gdb_regno number, riscv_reg_t value)
static struct mem_access_result read_memory_progbuf_inner(struct target *target, const struct riscv_mem_access_args args)
Read the requested memory, taking care to minimize the number of reads and re-read the data only if a...
static int read_memory_progbuf_inner_run_and_process_batch(struct target *target, struct riscv_batch *batch, const struct riscv_mem_access_args args, uint32_t start_index, uint32_t elements_to_read, uint32_t *elements_read)
This function reads a batch of elements from memory.
static int riscv013_step_current_hart(struct target *target)
static void riscv013_fill_dmi_read(const struct target *target, uint8_t *buf, uint32_t a)
static int riscv013_step_or_resume_current_hart(struct target *target, bool step)
static int write_memory_progbuf_startup(struct target *target, target_addr_t *address_p, const uint8_t *buffer, uint32_t size)
This function is used to start the memory-writing pipeline.
static uint32_t sb_sbaccess(unsigned int size_bytes)
int riscv013_set_register_buf(struct target *target, enum gdb_regno regno, const uint8_t *value)
static dm013_info_t * get_dm(struct target *target)
Return the DM structure for this target.
static struct mem_access_result access_memory_progbuf(struct target *target, const struct riscv_mem_access_args args)
static int read_memory_bus_word(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
static int dm_write(struct target *target, uint32_t address, uint32_t value)
static void abstract_data_write_fill_batch(struct riscv_batch *batch, riscv_reg_t value, unsigned int index, unsigned int size_bits)
Queue scans into a batch that write the value to abstract data registers: data[index] (and data[index...
static unsigned int register_size(struct target *target, enum gdb_regno number)
Return register size in bits.
static int cleanup_after_register_access(struct target *target, riscv_reg_t mstatus, enum gdb_regno regno)
static int riscv013_on_step_or_resume(struct target *target, bool step)
static int vl_write_progbuf(struct target *target, riscv_reg_t value)
static int riscv013_on_step(struct target *target)
static struct mem_access_result write_memory_progbuf_inner(struct target *target, const struct riscv_mem_access_args args)
static int abstract_cmd_batch_check_and_clear_cmderr(struct target *target, const struct riscv_batch *batch, size_t abstractcs_read_key, uint32_t *cmderr)
static struct mem_access_result read_memory_abstract(struct target *target, const struct riscv_mem_access_args args)
static target_addr_t write_memory_progbuf_fill_batch(struct riscv_batch *batch, target_addr_t start_address, target_addr_t end_address, uint32_t size, const uint8_t *buffer)
This function fills the batch with DMI writes (but does not execute the batch).
bool is_mem_access_failed(struct mem_access_result status)
static int fpr_read_progbuf(struct target *target, uint64_t *value, enum gdb_regno number)
static int select_prepped_harts(struct target *target)
#define CMDERR_NOT_SUPPORTED
static struct mem_access_result access_memory_abstract(struct target *target, const struct riscv_mem_access_args args)
static bool has_sufficient_progbuf(struct target *target, unsigned int size)
static int fpr_write_progbuf(struct target *target, enum gdb_regno number, riscv_reg_t value)
static int csr_read_progbuf(struct target *target, uint64_t *value, enum gdb_regno number)
static void riscv013_dm_free(struct target *target)
static int read_memory_progbuf_inner_extract_batch_data(struct target *target, const struct riscv_batch *batch, uint32_t start_index, uint32_t elements_to_read, uint32_t *elements_read, const struct riscv_mem_access_args args)
This function extracts the data from the batch.
static struct mem_access_result mem_should_skip_abstract(struct target *target, const struct riscv_mem_access_args args)
static int register_read_direct(struct target *target, riscv_reg_t *value, enum gdb_regno number)
Actually read registers from the target right now.
static int scratch_reserve(struct target *target, scratch_mem_t *scratch, struct riscv_program *program, unsigned int size_bytes)
Find some scratch memory to be used with the given program.
static void riscv013_fill_dm_nop(const struct target *target, uint8_t *buf)
struct target_type riscv013_target
static int wait_for_idle(struct target *target, uint32_t *abstractcs)
static void ac_cache_insert(struct ac_cache *cache, uint32_t command)
static int dm013_select_hart(struct target *target, int hart_index)
static int is_vector_reg(enum gdb_regno gdb_regno)
static int dm_read(struct target *target, uint32_t *value, uint32_t address)
static int register_read_progbuf(struct target *target, uint64_t *value, enum gdb_regno number)
This function reads a register by writing a program to program buffer and executing it.
static int sb_write_address(struct target *target, target_addr_t address, enum riscv_scan_delay_class sbaddr0_delay)
static int examine(struct target *target)
static int restore_privilege_from_virt2phys_mode(struct target *target, riscv_reg_t mstatus, riscv_reg_t mstatus_old, riscv_reg_t dcsr, riscv_reg_t dcsr_old)
static void mark_command_as_unsupported(struct target *target, uint32_t command)
static int reset_dm(struct target *target)
static int ac_cache_elem_comparator(const void *p_lhs, const void *p_rhs)
static int deassert_reset(struct target *target)
static void select_dmi(struct jtag_tap *tap)
static struct mem_access_result mem_should_skip_progbuf(struct target *target, const struct riscv_mem_access_args args)
int riscv013_set_register(struct target *target, enum gdb_regno rid, riscv_reg_t value)
bool is_mem_access_ok(struct mem_access_result status)
static int riscv013_halt_go(struct target *target)
static int vtype_write_progbuf(struct target *target, riscv_reg_t value)
static int cleanup_after_vector_access(struct target *target, riscv_reg_t mstatus, riscv_reg_t vtype, riscv_reg_t vl)
static OOCD_LIST_HEAD(dm_list)
static int assert_reset(struct target *target)
static int write_memory_progbuf_run_batch(struct target *target, struct riscv_batch *batch, target_addr_t *address_p, target_addr_t end_address, uint32_t size, const uint8_t *buffer)
This function runs the batch of writes and updates address_p with the address of the next write.
static int batch_run(struct target *target, struct riscv_batch *batch)
static int riscv013_execute_progbuf(struct target *target, uint32_t *cmderr)
static uint32_t __attribute__((unused))
static int write_memory_progbuf_handle_busy(struct target *target, target_addr_t *address_p, target_addr_t end_address, uint32_t size, const uint8_t *buffer)
This function attempts to restore the pipeline after a busy on abstract access or a DMI busy by readi...
static int register_write_progbuf(struct target *target, enum gdb_regno number, riscv_reg_t value)
This function writes a register by writing a program to program buffer and executing it.
@ MEM_ACCESS_RESULT_TYPE_OK
@ MEM_ACCESS_RESULT_TYPE_ENUM_SIZE
@ MEM_ACCESS_RESULT_TYPE_SKIPPED
@ MEM_ACCESS_RESULT_TYPE_FAILED
@ MEM_ACCESS_RESULT_TYPE_DISABLED
static int riscv013_invalidate_cached_progbuf(struct target *target)
static int handle_became_unavailable(struct target *target, enum riscv_hart_state previous_riscv_state)
static int read_memory_progbuf_inner_fill_progbuf(struct target *target, uint32_t increment, uint32_t size)
static int read_memory_bus_v0(struct target *target, const struct riscv_mem_access_args args)
static struct mem_access_result read_memory_progbuf(struct target *target, const struct riscv_mem_access_args args)
Read the requested memory, silently handling memory access errors.
static void log_debug_reg(struct target *target, enum riscv_debug_reg_ordinal reg, riscv_reg_t value, const char *file, unsigned int line, const char *func)
static int register_read_abstract_with_size(struct target *target, riscv_reg_t *value, enum gdb_regno number, unsigned int size)
int riscv013_get_register(struct target *target, riscv_reg_t *value, enum gdb_regno rid)
static struct mem_access_result read_memory_progbuf_inner_one(struct target *target, const struct riscv_mem_access_args args)
Only need to save/restore one GPR to read a single word, and the progbuf program doesn't need to incr...
static void riscv013_fill_dmi_write(const struct target *target, uint8_t *buf, uint32_t a, uint32_t d)
static enum riscv_halt_reason riscv013_halt_reason(struct target *target)
bool is_mem_access_skipped(struct mem_access_result status)
static unsigned int get_sbaadress_reg_count(const struct target *target)
static int dmstatus_read(struct target *target, uint32_t *dmstatus, bool authenticated)
#define ABSTRACT_COMMAND_BATCH_SIZE
#define RISCV013_INFO(r)
Since almost everything can be accomplish by scanning the dbus register, all functions here assume db...
static int batch_run_timeout(struct target *target, struct riscv_batch *batch)
static int riscv013_access_memory(struct target *target, const struct riscv_mem_access_args args)
static riscv_insn_t riscv013_read_progbuf(struct target *target, unsigned int index)
static int write_abstract_arg(struct target *target, unsigned int index, riscv_reg_t value, unsigned int size_bits)
static uint32_t riscv013_get_dmi_address(const struct target *target, uint32_t address)
static int dmi_read(struct target *target, uint32_t *value, uint32_t address)
static int wait_for_idle_if_needed(struct target *target)
static int read_memory_bus_v1(struct target *target, const struct riscv_mem_access_args args)
Read the requested memory using the system bus interface.
static int set_group(struct target *target, bool *supported, unsigned int group, enum grouptype grouptype)
static int read_memory_progbuf_inner_startup(struct target *target, target_addr_t address, uint32_t increment, uint32_t index)
This function is used to start the memory-reading pipeline.
static int sba_supports_access(struct target *target, unsigned int size_bytes)
static size_t abstract_cmd_fill_batch(struct riscv_batch *batch, uint32_t command)
static int set_dcsr_ebreak(struct target *target, bool step)
static int init_target(struct command_context *cmd_ctx, struct target *target)
static struct mem_access_result access_memory_sysbus(struct target *target, const struct riscv_mem_access_args args)
static bool dcsr_ebreak_config_equals_reset_value(const struct target *target)
static int is_fpu_reg(enum gdb_regno gdb_regno)
static int dm_read_exec(struct target *target, uint32_t *value, uint32_t address)
static unsigned int riscv013_data_bits(struct target *target)
static int riscv013_resume_prep(struct target *target)
static void abstract_data_read_fill_batch(struct riscv_batch *batch, unsigned int index, unsigned int size_bits)
Queue scans into a batch that read the value from abstract data registers: data[index] (and data[inde...
static int scratch_read64(struct target *target, scratch_mem_t *scratch, uint64_t *value)
const char * mem_access_result_to_str(struct mem_access_result status)
static bool is_command_unsupported(struct target *target, uint32_t command)
static int internal_register_write64_progbuf_scratch(struct target *target, struct riscv_program *program, riscv_reg_t value)
This function is used to write a 64-bit value to a register by executing a program.
static int read_memory_progbuf_inner_ensure_forward_progress(struct target *target, const struct riscv_mem_access_args args, uint32_t start_index)
read_memory_progbuf_inner_startup() must be called before calling this function with the address argu...
static struct mem_access_result write_memory_abstract(struct target *target, const struct riscv_mem_access_args args)
static int prep_for_register_access(struct target *target, riscv_reg_t *orig_mstatus, enum gdb_regno regno)
static int execute_autofence(struct target *target)
static int dm013_select_target(struct target *target)
static struct mem_access_result read_word_from_s1(struct target *target, const struct riscv_mem_access_args args, uint32_t index)
static riscv013_info_t * get_info(const struct target *target)
static void decrement_reset_delays_counter(struct target *target, size_t finished_scans)
static int read_abstract_arg(struct target *target, riscv_reg_t *value, unsigned int index, unsigned int size_bits)
static int riscv013_authdata_write(struct target *target, uint32_t value, unsigned int index)
#define HART_INDEX_UNKNOWN
static int riscv013_authdata_read(struct target *target, uint32_t *value, unsigned int index)
static int riscv013_get_hart_state(struct target *target, enum riscv_hart_state *state)
static void set_buffer_and_log_read(const struct riscv_mem_access_args args, uint32_t index, uint64_t value)
static uint32_t abstract_memory_size(unsigned int width)
uint32_t riscv013_access_register_command(struct target *target, uint32_t number, unsigned int size, uint32_t flags)
static int register_write_direct(struct target *target, enum gdb_regno number, riscv_reg_t value)
Immediately write the new value to the requested register.
static int internal_register_read64_progbuf_scratch(struct target *target, struct riscv_program *program, riscv_reg_t *value)
This function is used to read a 64-bit value from a register by executing a program.
static int halt_set_dcsr_ebreak(struct target *target)
static int riscv013_halt_prep(struct target *target)
static uint32_t access_memory_command(struct target *target, bool virtual, unsigned int width, bool postincrement, bool is_write)
static int riscv013_clear_abstract_error(struct target *target)
static int write_memory_progbuf_fill_progbuf(struct target *target, uint32_t size)
static target_addr_t sb_read_address(struct target *target)
int riscv013_get_register_buf(struct target *target, uint8_t *value, enum gdb_regno regno)
static struct riscv_debug_reg_ctx get_riscv_debug_reg_ctx(const struct target *target)
#define HART_INDEX_MULTIPLE
static void reset_learned_delays(struct target *target)
static void log_memory_access64(target_addr_t address, uint64_t value, unsigned int size_bytes, bool is_read)
static int modify_privilege_for_virt2phys_mode(struct target *target, riscv_reg_t *mstatus, riscv_reg_t *mstatus_old, riscv_reg_t *dcsr, riscv_reg_t *dcsr_old)
static int write_memory_bus_v0(struct target *target, const struct riscv_mem_access_args args)
static unsigned int riscv013_get_dmi_address_bits(const struct target *target)
static int riscv013_resume_go(struct target *target)
static struct ac_cache ac_cache_construct(void)
static int write_memory_progbuf_teardown(struct target *target)
This function reverts the changes made by write_memory_progbuf_startup()
static void log_memory_access(target_addr_t address, uint32_t *sbvalue, unsigned int size_bytes, bool is_read)
static int read_memory_progbuf_inner_try_to_read(struct target *target, const struct riscv_mem_access_args args, uint32_t *elements_read, uint32_t index, uint32_t loop_count)
#define LIST_OF_MEM_ACCESS_RESULTS
#define LOG_DEBUG_REG(t, r, v)
static int sample_memory_bus_v1(struct target *target, struct riscv_sample_buf *buf, const riscv_sample_config_t *config, int64_t until_ms)
static uint32_t set_dmcontrol_hartsel(uint32_t initial, int hart_index)
static struct mem_access_result write_memory_progbuf(struct target *target, const struct riscv_mem_access_args args)
static int read_memory_progbuf_inner_on_dmi_busy(struct target *target, uint32_t start_index, uint32_t next_start_index, const struct riscv_mem_access_args args)
This function attempts to restore the pipeline after a dmi busy.
static bool check_dbgbase_exists(struct target *target)
int riscv013_execute_abstract_command(struct target *target, uint32_t command, uint32_t *cmderr)
static void deinit_target(struct target *target)
static int wait_for_authbusy(struct target *target, uint32_t *dmstatus)
static int read_sbcs_nonbusy(struct target *target, uint32_t *sbcs)
static int tick(struct target *target)
static int register_read_abstract(struct target *target, riscv_reg_t *value, enum gdb_regno number)
static int read_memory_progbuf_inner_on_ac_busy(struct target *target, uint32_t start_index, uint32_t *elements_read, const struct riscv_mem_access_args args)
This function attempts to restore the pipeline after a busy on abstract access.
enum riscv_debug_reg_ordinal get_cmdtype(uint32_t command)
static void log_memory_access128(target_addr_t address, uint64_t value_h, uint64_t value_l, bool is_read)
static unsigned int riscv013_get_progbufsize(const struct target *target)
static COMMAND_HELPER(riscv013_print_info, struct target *target)
static int try_set_vsew(struct target *target, unsigned int *debug_vsew)
static int increase_ac_busy_delay(struct target *target)
static int prep_for_vector_access(struct target *target, riscv_reg_t *orig_mstatus, riscv_reg_t *orig_vtype, riscv_reg_t *orig_vl, unsigned int *debug_vl, unsigned int *debug_vsew)
static uint32_t read_memory_progbuf_inner_fill_batch(struct riscv_batch *batch, uint32_t count, uint32_t size)
static int increase_dmi_busy_delay(struct target *target)
static bool riscv013_get_impebreak(const struct target *target)
static struct mem_access_result mem_should_skip_sysbus(struct target *target, const struct riscv_mem_access_args args)
static int sample_memory(struct target *target, struct riscv_sample_buf *buf, riscv_sample_config_t *config, int64_t until_ms)
static bool ac_cache_contains(const struct ac_cache *cache, uint32_t command)
static void ac_cache_free(struct ac_cache *cache)
static int scratch_release(struct target *target, scratch_mem_t *scratch)
static void log_mem_access_result(struct target *target, bool success, enum riscv_mem_access_method method, bool is_read)
static int write_memory_progbuf_try_to_write(struct target *target, target_addr_t *address_p, target_addr_t end_address, uint32_t size, const uint8_t *buffer)
int riscv013_reg_examine_all(struct target *target)
This function assumes target's DM to be initialized (target is able to access DMs registers,...
int riscv013_reg_save(struct target *target, enum gdb_regno regid)
This function is used to save the value of a register in cache.
unsigned int riscv_xlen(const struct target *target)
struct scan_field select_dbus
bool riscv_supports_extension(const struct target *target, char letter)
void select_dmi_via_bscan(struct jtag_tap *tap)
int riscv_halt(struct target *target)
int riscv_get_hart_state(struct target *target, enum riscv_hart_state *state)
bool riscv_virt2phys_mode_is_hw(const struct target *target)
uint8_t bscan_tunnel_ir_width
int dtmcs_scan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr)
int riscv_openocd_poll(struct target *target)
int riscv_get_command_timeout_sec(void)
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 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))
#define RISCV013_DTMCS_ABITS_MIN
@ RISCV_MEM_ACCESS_SYSBUS
@ RISCV_MEM_ACCESS_PROGBUF
@ RISCV_MEM_ACCESS_ABSTRACT
@ RISCV_STATE_UNAVAILABLE
@ RISCV_STATE_NON_EXISTENT
#define RISCV013_DTMCS_ABITS_MAX
static bool riscv_mem_access_is_write(const struct riscv_mem_access_args args)
static bool riscv_mem_access_is_read(const struct riscv_mem_access_args args)
static struct riscv_private_config * riscv_private_config(const struct target *target)
#define RISCV_BATCH_ALLOC_SIZE
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.
int riscv_reg_write(struct target *target, enum gdb_regno regid, riscv_reg_t value)
This function is used to change the value of a register.
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.
struct list_head target_list
uint32_t progbuf_cache[16]
bool abstract_cmd_maybe_busy
unsigned int abs_chain_position
uint8_t * cur_instr
current instruction
unsigned int ir_length
size of instruction register
unsigned int abs_chain_position
bool enabled
Is this TAP currently enabled?
enum mem_access_result_enum value
struct ac_cache ac_not_supported_cache
riscv_addr_t progbuf_address
struct riscv_debug_reg_ctx::@124 XLEN
const uint8_t * write_buffer
enum riscv_progbuf_exec_result execution_result
unsigned int instruction_count
unsigned int custom_number
const uint8_t * out_value
A pointer to value to be scanned into the device.
riscv_addr_t debug_address
riscv_addr_t hart_address
struct working_area * area
memory_space_t memory_space
This holds methods shared between all instances of a given target type.
const char * name
Name of this type of target.
enum target_debug_reason debug_reason
struct reg_cache * reg_cache
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_examine_one(struct target *target)
Examine the specified target, letting it perform any Initialisation that requires JTAG access.
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
bool target_has_event_action(const struct target *target, enum target_event event)
Returns true only if the target has a handler for the specified event.
void target_handle_event(struct target *target, enum target_event e)
#define ERROR_TARGET_NOT_HALTED
static bool target_was_examined(const struct target *target)
@ TARGET_EVENT_RESET_ASSERT
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static struct ublast_lowlevel_priv info