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) {
459 memset(&
info->learned_delays, 0,
sizeof(
info->learned_delays));
465 if (r->reset_delays_wait < 0) {
466 assert(r->reset_delays_wait == -1);
469 if ((
size_t)r->reset_delays_wait >= finished_scans) {
470 r->reset_delays_wait -= finished_scans;
473 r->reset_delays_wait = -1;
475 "resetting learned delays (reset_delays_wait counter expired)");
485 base =
info->dm->base;
539 uint32_t next_dm = 0;
540 unsigned int count = 1;
545 uint32_t current_dm = next_dm;
556 if (next_dm >>
info->abits) {
558 "which is the width of the DMI bus address. This is a HW bug",
578 if (dmstatus_version != 2 && dmstatus_version != 3) {
579 LOG_ERROR(
"OpenOCD only supports Debug Module version 2 (0.13) and 3 (1.0), not "
580 "%" PRId32
" (dmstatus=0x%" PRIx32
"). This error might be caused by a JTAG "
581 "signal issue. Try reducing the JTAG clock speed.",
584 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
585 "(dmstatus=0x%x). Use `riscv authdata_read` and "
586 "`riscv authdata_write` commands to authenticate.", *dmstatus);
621 LOG_ERROR(
"BUG: Target %s is not assigned to any RISC-V debug module",
634 "potentially unrecoverable error detected - could not read abstractcs");
645 "Timed out after %ds waiting for busy to go low (abstractcs=0x%" PRIx32
"). "
646 "Increase the timeout with riscv set_command_timeout_sec.",
652 "BUG: dm->abstract_cmd_maybe_busy had not been set when starting an abstract command.");
664 #define ABSTRACT_COMMAND_BATCH_SIZE 2
677 const struct riscv_batch *batch,
size_t abstractcs_read_key,
681 abstractcs_read_key);
695 LOG_ERROR(
"BUG: Target %s is not assigned to any RISC-V debug module",
706 "Abstract Command execution failed (abstractcs.cmderr = %" PRIx32
").",
726 assert(
false &&
"Unknown command type value");
734 "command 0x%" PRIx32
" as not supported",
command);
736 command, __FILE__, __LINE__, __func__);
772 abstractcs_read_key, cmderr);
790 unsigned int size_bits)
792 assert(size_bits >= 32);
793 assert(size_bits % 32 == 0);
794 const unsigned int size_in_words = size_bits / 32;
795 const unsigned int offset = index * size_in_words;
796 for (
unsigned int i = 0; i < size_in_words; ++i) {
803 unsigned int index,
unsigned int size_bits)
805 assert(size_bits >= 32);
806 assert(size_bits % 32 == 0);
807 const unsigned int size_in_words = size_bits / 32;
808 assert(size_in_words *
sizeof(uint32_t) <=
sizeof(
riscv_reg_t));
810 for (
unsigned int i = 0; i < size_in_words; ++i) {
818 unsigned int index,
unsigned int size_bits)
821 assert(size_bits >= 32);
822 assert(size_bits % 32 == 0);
823 const unsigned char size_in_words = size_bits / 32;
842 riscv_reg_t value,
unsigned int index,
unsigned int size_bits)
844 assert(size_bits % 32 == 0);
845 const unsigned int size_in_words = size_bits / 32;
846 assert(value <= UINT32_MAX || size_in_words > 1);
847 const unsigned int offset = index * size_in_words;
849 for (
unsigned int i = 0; i < size_in_words; ++i) {
862 unsigned int offset = index * size_bits / 32;
880 unsigned int size, uint32_t flags)
928 PRIx32
" is cached as not supported",
command);
930 command, __FILE__, __LINE__, __func__);
980 assert(size_bits % 32 == 0);
981 const unsigned int size_in_words = size_bits / 32;
982 const unsigned int batch_size = size_in_words
997 abstractcs_read_key, &cmderr);
1033 unsigned int width,
bool postincrement,
bool is_write)
1054 if (
info->progbufsize < 1) {
1086 if (written == (uint32_t)
info->progbuf_address) {
1088 info->progbuf_address);
1093 info->progbuf_address);
1123 assert(orig_mstatus);
1138 "The target must be halted to modify and then restore mstatus");
1146 if ((new_mstatus & field_mask) != 0)
1149 new_mstatus =
set_field(new_mstatus, field_mask, 1);
1192 unsigned int size_bytes)
1195 while (alignment < size_bytes)
1203 if (
info->dataaccess == 1) {
1206 if (
info->dataaddr & (1<<11))
1225 scratch->
hart_address = (
info->progbuf_address + program_size + alignment - 1) &
1229 info->progbufsize)) {
1246 "a work area with 'configure -work-area-phys'.", size_bytes);
1267 *value |= ((uint64_t)v) << 32;
1275 *value |= ((uint64_t)v) << 32;
1674 "Increase the timeout with riscv set_command_timeout_sec.",
1696 original_dcsr = dcsr;
1704 if (dcsr != original_dcsr &&
1707 info->dcsr_ebreak_is_set =
true;
1740 if (
info->haltgroup_supported) {
1746 "Some harts may be unexpectedly halted.");
1762 if (
info->haltgroup_supported) {
1768 "Some harts may be unexpectedly halted.",
target->
smp);
1789 free(
info->version_specific);
1798 assert(
group <= 31);
1823 uint32_t abstractcs;
1841 assert(dm &&
"DM is expected to be already allocated.");
1842 assert(!dm->
was_reset &&
"Attempt to reset an already-reset debug module.");
1871 "Increase the timeout with 'riscv set_command_timeout_sec'.",
1893 "Increase the timeout with 'riscv set_command_timeout_sec'.",
1949 for (
int i = 0; i < max_hart_count; ++i) {
2004 uint32_t dtmcontrol;
2034 if (
info->abits == 0) {
2036 "dtmcs.abits is zero. Check JTAG connectivity/board power");
2048 "lower than the minimum:");
2075 if (dmstatus_version != 2 && dmstatus_version != 3) {
2090 "(dmstatus=0x%x). Use `riscv authdata_read` and "
2091 "`riscv authdata_write` commands to authenticate.", dmstatus);
2099 uint32_t abstractcs;
2106 info->datacount,
info->progbufsize);
2112 "target. Memory may not always appear consistent. "
2113 "(progbufsize=%d, impebreak=%d)",
info->progbufsize,
2125 const bool hart_halted_at_examine_start = state_at_examine_start ==
RISCV_STATE_HALTED;
2126 if (!hart_halted_at_examine_start) {
2130 info->index, __func__);
2157 if (
info->haltgroup_supported)
2193 uint32_t before, after;
2226 for (
unsigned int i = 0; i < r->num_enabled_mem_access_methods; i++) {
2273 riscv_print_info_line(
CMD,
"dm",
"abits",
info->abits);
2274 riscv_print_info_line(
CMD,
"dm",
"progbufsize",
info->progbufsize);
2293 unsigned int encoded_vsew =
2302 if (encoded_vsew == 3 && r->vsew64_supported ==
YNM_MAYBE) {
2309 r->vsew64_supported =
YNM_NO;
2313 r->vsew64_supported =
YNM_YES;
2315 *debug_vsew = encoded_vsew == 3 ? 64 : 32;
2321 unsigned int *debug_vl,
unsigned int *debug_vsew)
2323 assert(orig_mstatus);
2332 "Unable to access vector register: target not halted");
2373 unsigned int debug_vl, debug_vsew;
2376 &debug_vl, &debug_vsew) !=
ERROR_OK)
2385 for (
unsigned int i = 0; i < debug_vl; i++) {
2404 buf_set_u64(value, debug_vsew * i, debug_vsew, v);
2407 "Failed to execute vmv/vslide1down while reading %s",
2420 const uint8_t *value)
2428 unsigned int debug_vl, debug_vsew;
2431 &debug_vl, &debug_vsew) !=
ERROR_OK)
2443 for (
unsigned int i = 0; i < debug_vl; i++) {
2460 switch (size_bytes) {
2490 const uint32_t values[] = {(uint32_t)
address, (uint32_t)(
address >> 32), 0, 0};
2492 assert(reg_count > 0);
2496 for (
unsigned int i = reg_count - 1; i > 0; --i)
2521 r->reset_delays_wait >= 0,
2522 r->reset_delays_wait);
2528 const size_t finished_scans = batch->
used_scans;
2544 size_t finished_scans = 0;
2552 &
info->learned_delays,
2553 r->reset_delays_wait >= 0,
2554 r->reset_delays_wait);
2558 assert(new_finished_scans >= finished_scans);
2560 finished_scans = new_finished_scans;
2581 "The target is either really slow or broken. You could increase "
2582 "the timeout with riscv set_command_timeout_sec.",
2590 switch (size_bytes) {
2613 if (sbasize == 0 || sbasize > 64) {
2624 uint32_t sbcs_valid =
false;
2626 uint32_t sbaddress0 = 0;
2627 bool sbaddress0_valid =
false;
2628 uint32_t sbaddress1 = 0;
2629 bool sbaddress1_valid =
false;
2632 const unsigned int repeat = 5;
2634 unsigned int enabled_count = 0;
2636 if (
config->bucket[i].enabled)
2647 target, 1 + enabled_count * 5 * repeat);
2651 unsigned int result_bytes = 0;
2652 for (
unsigned int n = 0; n < repeat; n++) {
2654 if (
config->bucket[i].enabled) {
2657 config->bucket[i].size_bytes);
2662 if (enabled_count == 1)
2665 if (!sbcs_valid || sbcs_write != sbcs) {
2673 (!sbaddress1_valid ||
2674 sbaddress1 !=
config->bucket[i].address >> 32)) {
2675 sbaddress1 =
config->bucket[i].address >> 32;
2678 sbaddress1_valid =
true;
2680 if (!sbaddress0_valid ||
2681 sbaddress0 != (
config->bucket[i].address & 0xffffffff)) {
2682 sbaddress0 =
config->bucket[i].address;
2686 sbaddress0_valid =
true;
2688 if (
config->bucket[i].size_bytes > 4)
2693 result_bytes += 1 +
config->bucket[i].size_bytes;
2698 if (buf->
used + result_bytes >= buf->
size) {
2744 unsigned int read_count = 0;
2745 for (
unsigned int n = 0; n < repeat; n++) {
2747 if (
config->bucket[i].enabled) {
2750 if (
config->bucket[i].size_bytes > 4)
2756 buf->
used += 1 +
config->bucket[i].size_bytes;
2789 info->dcsr_ebreak_is_set =
false;
2836 "(due to target becoming unavailable).");
2840 info->dcsr_ebreak_is_set =
false;
2847 if (!
info->dcsr_ebreak_is_set &&
2879 generic_info->dmi_read = &
dmi_read;
2884 generic_info->print_info = &riscv013_print_info;
2889 generic_info->tick = &
tick;
2891 if (!generic_info->version_specific) {
2893 if (!generic_info->version_specific)
2899 info->progbufsize = -1;
2953 if (
config->dcsr_ebreak_fields[i])
2968 uint32_t control = 0;
2976 if (hartsel_changed) {
2997 "dmstatus=0x%x (allunavail=%s, allhavereset=%s); "
2998 "Increase the timeout with riscv set_command_timeout_sec.",
3102 uint64_t value_l,
bool is_read)
3108 sprintf(fmt,
"M[0x%" TARGET_PRIxADDR "] %ss 0x%%016" PRIx64
"%%016" PRIx64,
3109 address, is_read ?
"read" :
"write");
3114 unsigned int size_bytes,
bool is_read)
3121 address, is_read ?
"read" :
"write", size_bytes * 2);
3122 switch (size_bytes) {
3130 value &= 0xffffffffUL;
3140 unsigned int size_bytes,
bool is_read)
3142 if (size_bytes == 16) {
3143 uint64_t value_h = ((uint64_t)sbvalue[3] << 32) | sbvalue[2];
3144 uint64_t value_l = ((uint64_t)sbvalue[1] << 32) | sbvalue[0];
3147 uint64_t value = ((uint64_t)sbvalue[1] << 32) | sbvalue[0];
3158 uint32_t sbvalue[4] = { 0 };
3161 for (
int i = (
size - 1) / 4; i >= 0; i--) {
3197 "Increase the timeout with riscv set_command_timeout_sec.",
3209 assert(mstatus_old);
3223 *mstatus_old = *mstatus;
3236 if (*mstatus != *mstatus_old &&
3244 if (*dcsr != *dcsr_old &&
3258 if (mstatus != mstatus_old &&
3263 if (dcsr != dcsr_old &&
3284 uint32_t access = 0;
3286 const int DM_SBCS_SBSINGLEREAD_OFFSET = 20;
3287 const uint32_t DM_SBCS_SBSINGLEREAD = (0x1U << DM_SBCS_SBSINGLEREAD_OFFSET);
3289 const int DM_SBCS_SBAUTOREAD_OFFSET = 15;
3290 const uint32_t DM_SBCS_SBAUTOREAD = (0x1U << DM_SBCS_SBAUTOREAD_OFFSET);
3293 if (args.
count == 1) {
3294 for (uint32_t i = 0; i < args.
count; i++) {
3300 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
3309 t_buffer += args.
size;
3310 cur_addr += args.
size;
3324 access =
set_field(access, DM_SBCS_SBAUTOREAD, 1);
3325 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
3330 while (cur_addr < fin_addr) {
3332 PRIx64, args.
size, args.
count, cur_addr);
3338 cur_addr += args.
size;
3339 t_buffer += args.
size;
3342 if (cur_addr == fin_addr && args.
count != 1) {
3365 const uint32_t increment = args.
increment;
3370 if (increment !=
size && increment != 0) {
3389 while (next_address < end_address) {
3392 if (increment ==
size)
3412 uint32_t sbvalue[4] = {0};
3421 for (uint32_t j = size_in_words - 1; j > 0; --j)
3432 for (
size_t k = 0; k <= last_key; ++k) {
3442 uint32_t sbcs_read = 0;
3493 next_address = end_address;
3514 snprintf(msg, 60,
"%s to %s memory via %s.",
3515 success ?
"Succeeded" :
"Failed",
3516 is_read ?
"read" :
"write",
3522 warn = r->mem_access_warn[method];
3523 r->mem_access_warn[method] =
false;
3540 #define LIST_OF_MEM_ACCESS_RESULTS \
3541 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_OK, OK, "ok") \
3542 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_DISABLED, DISABLED, "disabled") \
3543 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED, SKIPPED, "skipped") \
3544 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_ABSTRACT_ACCESS_CMDERR, \
3545 SKIPPED, "skipped (abstract access cmderr)") \
3546 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGBUF_NOT_PRESENT, \
3547 SKIPPED, "skipped (progbuf not present)") \
3548 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGBUF_INSUFFICIENT, \
3549 SKIPPED, "skipped (insufficient progbuf)") \
3550 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_UNSUPPORTED_ACCESS_SIZE, \
3551 SKIPPED, "skipped (unsupported access size)") \
3552 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_XLEN_TOO_SHORT, \
3553 SKIPPED, "skipped (xlen too short)") \
3554 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_TARGET_NOT_HALTED, \
3555 SKIPPED, "skipped (target not halted)") \
3556 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_TOO_LARGE_ADDRESS, \
3557 SKIPPED, "skipped (address too large)") \
3558 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_UNSUPPORTED_INCREMENT_SIZE, \
3559 SKIPPED, "skipped (increment size not supported)") \
3560 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_TARGET_SELECT_FAILED, \
3561 SKIPPED, "skipped (dm target select failed)") \
3562 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_FENCE_EXEC_FAILED, \
3563 SKIPPED, "skipped (fence execution failed)") \
3564 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_SYSBUS_ACCESS_FAILED, \
3565 SKIPPED, "skipped (sysbus access failed)") \
3566 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_REG_SAVE_FAILED, \
3567 SKIPPED, "skipped (register save failed)") \
3568 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_UNKNOWN_SYSBUS_VERSION, \
3569 SKIPPED, "skipped (unknown sysbus version)") \
3570 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGRAM_WRITE_FAILED, \
3571 SKIPPED, "skipped (program write failed)") \
3572 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PROGBUF_FILL_FAILED, \
3573 SKIPPED, "skipped (progbuf fill failed)") \
3574 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_WRITE_ABSTRACT_ARG_FAILED, \
3575 SKIPPED, "skipped (abstract command argument write failed)") \
3576 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_SKIPPED_PRIV_MOD_FAILED, \
3577 SKIPPED, "skipped (privilege modification failed)") \
3578 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED, FAILED, "failed") \
3579 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_DM_ACCESS_FAILED, \
3580 FAILED, "failed (DM register access failed)") \
3581 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PRIV_MOD_FAILED, \
3582 FAILED, "failed (privilege modification failed)") \
3583 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_REG_READ_FAILED, \
3584 FAILED, "failed (register read failed)") \
3585 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PROGBUF_STARTUP_FAILED, \
3586 FAILED, "failed (progbuf startup failed)") \
3587 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PROGBUF_INNER_FAILED, \
3588 FAILED, "failed (progbuf inner failed)") \
3589 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_PROGBUF_TEARDOWN_FAILED, \
3590 FAILED, "failed (progbuf teardown failed)") \
3591 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_EXECUTE_ABSTRACT_FAILED, \
3592 FAILED, "failed (execute abstract failed)") \
3593 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_NO_FORWARD_PROGRESS, \
3594 FAILED, "failed (no forward progress)") \
3595 MEM_ACCESS_RESULT_HANDLER(MEM_ACCESS_FAILED_FENCE_EXEC_FAILED, \
3596 FAILED, "failed (fence execution failed)") \
3599 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) name,
3603 #undef MEM_ACCESS_RESULT_HANDLER
3613 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3614 case name: return MEM_ACCESS_RESULT_TYPE_##kind \
3615 == MEM_ACCESS_RESULT_TYPE_OK;
3620 #undef MEM_ACCESS_RESULT_HANDLER
3623 assert(
false &&
"Unknown memory access status");
3629 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3630 case name: return MEM_ACCESS_RESULT_TYPE_##kind \
3631 == MEM_ACCESS_RESULT_TYPE_FAILED;
3636 #undef MEM_ACCESS_RESULT_HANDLER
3639 assert(
false &&
"Unknown memory access status");
3645 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3646 case name: return MEM_ACCESS_RESULT_TYPE_##kind \
3647 == MEM_ACCESS_RESULT_TYPE_SKIPPED;
3652 #undef MEM_ACCESS_RESULT_HANDLER
3654 assert(
false &&
"Unknown memory access status");
3660 #define MEM_ACCESS_RESULT_HANDLER(name, kind, msg) \
3662 static const char *
const table[] = {
3665 #undef MEM_ACCESS_RESULT_HANDLER
3668 return table[
status.value];
3681 const char *
const access_type =
3686 "- progbuf not present", access_type);
3691 "insufficient progbuf size.", access_type);
3696 "target not halted.", access_type);
3701 "XLEN (%d) is too short for %d-bit memory args.",
3705 if (args.size > 8) {
3707 "unsupported size.", access_type);
3727 const char *
const access_type = is_read ?
"read" :
"write";
3731 "unsupported size.", access_type);
3735 if ((
sizeof(args.address) * 8 > sbasize)
3736 && (args.address >> sbasize)) {
3738 "sba only supports %u-bit address.", access_type, sbasize);
3741 if (is_read && args.increment != args.size
3743 || args.increment != 0)) {
3745 "sba %ss only support (size == increment) or also "
3746 "size==0 for sba v1.", access_type, access_type);
3759 const char *
const access_type = is_read ?
"read" :
"write";
3760 if (args.size > 8) {
3764 "unsupported size: %d bits", access_type, args.size * 8);
3770 "abstract access only supports %u-bit address.",
3774 if (is_read && args.size != args.increment) {
3776 "abstract command %ss only support (size == increment).",
3777 access_type, access_type);
3793 memset(args.read_buffer, 0, args.count * args.size);
3796 unsigned int width = args.size << 3;
3799 width,
true,
false);
3801 if (!use_aampostincrement)
3808 width,
false,
false);
3811 uint8_t *p = args.read_buffer;
3813 bool updateaddr =
true;
3814 unsigned int width32 =
MAX(
width, 32);
3815 for (uint32_t c = 0; c < args.count; c++) {
3829 if (use_aampostincrement && result !=
ERROR_OK &&
3832 "read command, but without aampostincrement");
3833 use_aampostincrement =
false;
3835 width,
false,
false);
3852 if (use_aampostincrement)
3873 unsigned int width = args.size << 3;
3878 if (!use_aampostincrement)
3885 width,
false,
true);
3888 const uint8_t *p = args.write_buffer;
3889 bool updateaddr =
true;
3890 for (uint32_t c = 0; c < args.count; c++) {
3912 if (use_aampostincrement && result !=
ERROR_OK &&
3915 "write command, but without aampostincrement");
3916 use_aampostincrement =
false;
3918 width,
false,
true);
3928 if (use_aampostincrement)
3956 if ( increment == 0 &&
3984 goto clear_abstractauto_and_fail;
3986 uint32_t abstractcs;
3988 goto clear_abstractauto_and_fail;
4000 goto clear_abstractauto_and_fail;
4002 clear_abstractauto_and_fail:
4016 uint32_t start_index, uint32_t *elements_read,
4032 uint32_t index_on_target;
4040 index_on_target = counter;
4046 index_on_target = (address_on_target - args.
address) /
4054 const uint32_t min_index_on_target = start_index + 2;
4055 if (index_on_target < min_index_on_target) {
4058 }
else if (index_on_target == min_index_on_target) {
4061 const uint32_t next_index = (index_on_target - 2);
4062 *elements_read = next_index - start_index;
4075 uint32_t start_index, uint32_t next_start_index,
4081 PRIu32
", %" PRIu32
")", start_index, next_start_index);
4082 if (start_index == next_start_index)
4096 uint32_t start_index, uint32_t elements_to_read, uint32_t *elements_read,
4101 const bool two_reads_per_element = args.
size > 4;
4102 const uint32_t reads_per_element = (two_reads_per_element ? 2 : 1);
4104 assert(elements_to_read <= UINT32_MAX / reads_per_element);
4105 const uint32_t nreads = elements_to_read * reads_per_element;
4106 for (uint32_t curr_idx = start_index, read = 0; read < nreads; ++read) {
4109 *elements_read = curr_idx - start_index;
4114 "Batch memory read encountered DMI_STATUS_FAILED on read %"
4124 curr_idx * args.
size;
4130 const bool is_odd_read = read % 2;
4132 if (two_reads_per_element && !is_odd_read) {
4136 const bool is_second_read = two_reads_per_element;
4143 *elements_read = elements_to_read;
4155 uint32_t start_index, uint32_t elements_to_read, uint32_t *elements_read)
4168 uint32_t abstractcs;
4172 uint32_t elements_to_extract_from_batch;
4178 PRIu32
", %" PRIu32
")", start_index, start_index + elements_to_read);
4179 elements_to_extract_from_batch = elements_to_read;
4184 &elements_to_extract_from_batch, args)
4195 elements_to_extract_from_batch, elements_read, args) !=
ERROR_OK)
4206 const uint32_t one_reg_used[] = {
DM_DATA0};
4207 const uint32_t reads_per_element =
size > 4 ? 2 : 1;
4208 const uint32_t *
const used_regs =
size > 4 ? two_regs_used : one_reg_used;
4210 const uint32_t end =
MIN(batch_capacity,
count);
4212 for (uint32_t j = 0; j < end; ++j) {
4217 for (uint32_t i = 0; i < reads_per_element; ++i)
4226 uint32_t index, uint32_t loop_count)
4235 loop_count - index, args.
size);
4238 args, index, elements_to_read, elements_read);
4253 "Executing one loop iteration to ensure forward progress (index=%"
4254 PRIu32
")", start_index);
4257 uint8_t *
const curr_buffer_address = args.
read_buffer +
4258 start_index * args.
size;
4261 .address = curr_target_address,
4265 uint32_t elements_read;
4270 if (elements_read != 1) {
4271 assert(elements_read == 0);
4282 uint32_t index, uint64_t value)
4300 assert(args.
size <= 8);
4303 args.
size > 4 ? 64 : 32);
4323 uint32_t increment, uint32_t
size)
4325 const bool is_repeated_read = increment == 0;
4339 if (is_repeated_read) {
4366 assert(args.count > 1 &&
"If count == 1, read_memory_progbuf_inner_one must be called");
4369 args.increment, args.size) !=
ERROR_OK)
4385 const uint32_t loop_count = args.count - 2;
4387 for (uint32_t index = 0; index < loop_count;) {
4388 uint32_t elements_read;
4394 if (elements_read == 0) {
4402 index += elements_read;
4403 assert(index <= loop_count);
4462 memset(args.read_buffer, 0, args.count * args.size);
4467 return (args.count == 1) ?
4483 const char *
const access_type = is_read ?
"reading" :
"writing";
4486 args.size, args.address);
4496 &mstatus, &mstatus_old, &dcsr, &dcsr_old) !=
ERROR_OK)
4504 mstatus, mstatus_old, dcsr, dcsr_old) !=
ERROR_OK)
4531 }
else if (sbver == 1) {
4540 MEM_ACCESS_OK : MEM_ACCESS_SKIPPED_SYSBUS_ACCESS_FAILED);
4553 const char *
const access_type = is_read ?
"reading" :
"writing";
4556 args.size, args.address);
4568 const char *
const access_type = is_read ?
"read" :
"write";
4576 "memory %s: %d", access_type, args.
size);
4587 for (
unsigned int i = 0; i < r->num_enabled_mem_access_methods; ++i) {
4601 assert(
false &&
"Unknown memory access method");
4616 " progbuf=%s, sysbus=%s, abstract=%s", access_type, args.
address,
4638 if (args.
count == 1) {
4667 PRIx64, (uint32_t)t_addr, (uint32_t)
value);
4693 while (next_address < end_address) {
4701 for (uint32_t i = (next_address - args.
address) / args.
size; i < args.
count; i++) {
4707 uint32_t sbvalue[4] = { 0 };
4708 if (args.
size > 12) {
4715 if (args.
size > 8) {
4721 if (args.
size > 4) {
4729 if (args.
size > 2) {
4730 sbvalue[0] |= ((uint32_t)p[2]) << 16;
4731 sbvalue[0] |= ((uint32_t)p[3]) << 24;
4734 sbvalue[0] |= ((uint32_t)p[1]) << 8;
4741 next_address += args.
size;
4753 if (dmi_busy_encountered)
4776 if (next_address < args.
address) {
4779 " - buggy sbautoincrement in hw?", next_address);
4795 sberror, sbaddress);
4796 if (sbaddress < args.
address) {
4800 " - buggy sbautoincrement in hw?", next_address);
4894 const uint8_t *
const curr_buff =
buffer + (address_on_target - *address_p);
4895 *address_p = address_on_target;
4896 if (*address_p == end_address) {
4914 const unsigned int writes_per_element =
size > 4 ? 2 : 1;
4921 end_address - start_address);
4927 if (writes_per_element == 2)
4933 return batch_end_address;
4956 uint32_t abstractcs;
4963 if (cmderr ==
CMDERR_NONE && !dmi_busy_encountered) {
4966 *address_p = end_address;
4968 }
else if (cmderr ==
CMDERR_BUSY || dmi_busy_encountered) {
4972 if (dmi_busy_encountered)
5037 args.write_buffer, args.size) !=
ERROR_OK)
5042 for (
target_addr_t next_addr_on_target = addr_on_target; addr_on_target != end_addr;
5043 addr_on_target = next_addr_on_target) {
5044 const uint8_t *
const curr_buff = args.write_buffer + (addr_on_target - args.address);
5046 end_addr, args.size, curr_buff) !=
ERROR_OK) {
5053 assert(next_addr_on_target - addr_on_target > 0);
5054 assert(next_addr_on_target - args.address <= (
target_addr_t)args.size * args.count);
5078 return r->impebreak;
5084 return r->progbufsize;
5189 unsigned int hawindow_count = (dm->
hart_count + 31) / 32;
5190 uint32_t *hawindow = calloc(hawindow_count,
sizeof(uint32_t));
5195 unsigned int total_selected = 0;
5196 unsigned int selected_index = 0;
5201 unsigned int index = info_013->
index;
5203 if (
info->prepped) {
5205 hawindow[index / 32] |= 1 << (index % 32);
5206 info->prepped =
false;
5208 selected_index = index;
5212 if (total_selected == 0) {
5216 }
else if (total_selected == 1) {
5227 for (
unsigned int i = 0; i < hawindow_count; i++) {
5268 for (
size_t i = 0; i < 256; ++i) {
5284 dmcontrol, dmstatus);
5295 uint32_t t_dmstatus;
5300 t_dmstatus = dmstatus;
5433 uint32_t run_program = 0;
5496 step ?
"single-step" :
"resume");
5516 for (
size_t i = 0; i < 256; ++i) {
5532 step ?
"single-step" :
"resume", dmstatus);
5536 " cancelling the resume request (dmcontrol.resumereq <- 0)");
5545 " trying to recover from a failed single-step, by requesting halt");
5559 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 int arch_state(struct target *target)
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