34 bool step,
bool use_hasel);
69 uint32_t num_words,
target_addr_t illegal_address,
bool run_sbbusyerror_test);
71 uint32_t write_size, uint32_t sbcs);
73 uint32_t *rd_buf, uint32_t read_size, uint32_t sbcs);
82 #define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
83 #define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
85 #define CSR_DCSR_CAUSE_SWBP 1
86 #define CSR_DCSR_CAUSE_TRIGGER 2
87 #define CSR_DCSR_CAUSE_DEBUGINT 3
88 #define CSR_DCSR_CAUSE_STEP 4
89 #define CSR_DCSR_CAUSE_HALT 5
90 #define CSR_DCSR_CAUSE_GROUP 6
92 #define RISCV013_INFO(r) riscv013_info_t *r = get_info(target)
115 #define CMDERR_NONE 0
116 #define CMDERR_BUSY 1
117 #define CMDERR_NOT_SUPPORTED 2
118 #define CMDERR_EXCEPTION 3
119 #define CMDERR_HALT_RESUME 4
120 #define CMDERR_OTHER 7
155 uint32_t progbuf_cache[16];
230 assert(
info->version_specific);
231 return info->version_specific;
274 target_entry = calloc(1,
sizeof(*target_entry));
299 static void decode_dmi(
char *text,
unsigned address,
unsigned data)
301 static const struct {
372 text += strlen(text);
380 static const char *
const op_string[] = {
"-",
"r",
"w",
"?"};
381 static const char *
const status_string[] = {
"+",
"?",
"F",
"b"};
397 __FILE__, __LINE__,
"scan",
398 "%db %s %08x @%02x -> %s %08x @%02x; %di",
399 field->
num_bits, op_string[out_op], out_data, out_address,
400 status_string[in_op], in_data, in_address, idle);
406 if (in_text[0] || out_text[0]) {
446 LOG_ERROR(
"failed jtag scan: %d", retval);
451 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
459 info->dmi_busy_delay +=
info->dmi_busy_delay / 10 + 1;
460 LOG_DEBUG(
"dtmcs_idle=%d, dmi_busy_delay=%d, ac_busy_delay=%d",
461 info->dtmcs_idle,
info->dmi_busy_delay,
462 info->ac_busy_delay);
472 uint32_t *data_in,
dmi_op_t op, uint32_t address_out, uint32_t data_out,
478 size_t num_bytes = (
num_bits + 7) / 8;
479 uint8_t in[num_bytes];
480 uint8_t out[num_bytes];
488 if (r->reset_delays_wait >= 0) {
489 r->reset_delays_wait--;
490 if (r->reset_delays_wait < 0) {
491 info->dmi_busy_delay = 0;
492 info->ac_busy_delay = 0;
496 memset(in, 0, num_bytes);
497 memset(out, 0, num_bytes);
499 assert(
info->abits != 0);
518 int idle_count =
info->dmi_busy_delay;
520 idle_count +=
info->ac_busy_delay;
564 bool *dmi_busy_encountered,
int dmi_op, uint32_t address,
565 uint32_t data_out,
int timeout_sec,
bool exec,
bool ensure_success)
572 if (dmi_busy_encountered)
573 *dmi_busy_encountered =
false;
601 if (dmi_busy_encountered)
602 *dmi_busy_encountered =
true;
618 if (ensure_success) {
627 if (dmi_busy_encountered)
628 *dmi_busy_encountered =
true;
633 LOG_ERROR(
"Failed %s (NOP) at 0x%x; value=0x%x, status=%d",
634 op_name, address, *data_in,
status);
636 LOG_ERROR(
"Failed %s (NOP) at 0x%x; status=%d", op_name, address,
650 bool *dmi_busy_encountered,
int dmi_op, uint32_t address,
651 uint32_t data_out,
bool exec,
bool ensure_success)
656 LOG_ERROR(
"DMI operation didn't complete in %d seconds. The target is "
657 "either really slow or broken. You could increase the "
658 "timeout with riscv set_command_timeout_sec.",
681 uint32_t value,
bool ensure_success)
687 bool authenticated,
unsigned timeout_sec)
694 if (dmstatus_version != 2 && dmstatus_version != 3) {
695 LOG_ERROR(
"OpenOCD only supports Debug Module version 2 (0.13) and 3 (1.0), not "
696 "%d (dmstatus=0x%x). This error might be caused by a JTAG "
697 "signal issue. Try reducing the JTAG clock speed.",
700 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
701 "(dmstatus=0x%x). Use `riscv authdata_read` and "
702 "`riscv authdata_write` commands to authenticate.", *dmstatus);
718 info->ac_busy_delay +=
info->ac_busy_delay / 10 + 1;
719 LOG_DEBUG(
"dtmcs_idle=%d, dmi_busy_delay=%d, ac_busy_delay=%d",
720 info->dtmcs_idle,
info->dmi_busy_delay,
721 info->ac_busy_delay);
753 const char *errors[8] = {
763 LOG_ERROR(
"Abstract command ended in error '%s' (abstractcs=0x%x)",
764 errors[
info->cmderr], *abstractcs);
767 LOG_ERROR(
"Timed out after %ds waiting for busy to go low (abstractcs=0x%x). "
768 "Increase the timeout with riscv set_command_timeout_sec.",
782 LOG_DEBUG(
"command=0x%x; access register, size=%d, postexec=%d, "
783 "transfer=%d, write=%d, regno=0x%x",
800 uint32_t abstractcs = 0;
819 unsigned offset = index * size_bits / 32;
822 LOG_ERROR(
"Unsupported size: %d bits", size_bits);
826 value |= ((uint64_t) v) << 32;
838 unsigned offset = index * size_bits / 32;
841 LOG_ERROR(
"Unsupported size: %d bits", size_bits);
856 unsigned size, uint32_t flags)
903 !
info->abstract_read_fpr_supported)
906 !
info->abstract_read_csr_supported)
919 info->abstract_read_fpr_supported =
false;
920 LOG_INFO(
"Disabling abstract command reads from FPRs.");
922 info->abstract_read_csr_supported =
false;
923 LOG_INFO(
"Disabling abstract command reads from CSRs.");
936 uint64_t value,
unsigned size)
941 !
info->abstract_write_fpr_supported)
944 !
info->abstract_write_csr_supported)
958 info->abstract_write_fpr_supported =
false;
959 LOG_INFO(
"Disabling abstract command writes to FPRs.");
961 info->abstract_write_csr_supported =
false;
962 LOG_INFO(
"Disabling abstract command writes to CSRs.");
998 unsigned width,
bool postincrement,
bool write)
1019 if (
info->progbufsize < 1) {
1021 LOG_INFO(
"No program buffer present.");
1055 if (written == (uint32_t)
info->progbuf_address) {
1056 LOG_INFO(
"progbuf is writable at 0x%" PRIx64,
1057 info->progbuf_address);
1061 LOG_INFO(
"progbuf is not writeable at 0x%" PRIx64,
1062 info->progbuf_address);
1110 uint64_t mstatus,
int regno)
1141 unsigned size_bytes)
1144 while (alignment < size_bytes)
1152 if (
info->dataaccess == 1) {
1155 if (
info->dataaddr & (1<<11))
1174 scratch->
hart_address = (
info->progbuf_address + program_size + alignment - 1) &
1178 info->progbufsize)) {
1194 LOG_ERROR(
"Couldn't find %d bytes of scratch RAM to use. Please configure "
1195 "a work area with 'configure -work-area-phys'.", size_bytes);
1216 *value |= ((uint64_t) v) << 32;
1224 *value |= ((uint64_t) v) << 32;
1232 (((uint64_t)
buffer[1]) << 8) |
1233 (((uint64_t)
buffer[2]) << 16) |
1234 (((uint64_t)
buffer[3]) << 24) |
1235 (((uint64_t)
buffer[4]) << 32) |
1236 (((uint64_t)
buffer[5]) << 40) |
1237 (((uint64_t)
buffer[6]) << 48) |
1238 (((uint64_t)
buffer[7]) << 56);
1293 return info->progbufsize + r->impebreak >=
size;
1324 bool use_scratch =
false;
1427 bool use_scratch =
false;
1511 LOG_ERROR(
"Timed out after %ds waiting for authbusy to go low (dmstatus=0x%x). "
1512 "Increase the timeout with riscv set_command_timeout_sec.",
1531 free(
info->version_specific);
1554 LOG_WARNING(
"Couldn't read vlenb for %s; vector register access won't work.",
1561 LOG_INFO(
"Vector support with vlenb=%d", r->vlenb);
1571 LOG_DEBUG(
"dtmcontrol=0x%x", dtmcontrol);
1577 if (dtmcontrol == 0) {
1578 LOG_ERROR(
"dtmcontrol is 0. Check JTAG connectivity/board power.");
1582 LOG_ERROR(
"Unsupported DTM version %d. (dtmcontrol=0x%x)",
1611 LOG_ERROR(
"Debug Module did not become active. dmcontrol=0x%x",
1621 LOG_DEBUG(
"dmstatus: 0x%08x", dmstatus);
1623 if (dmstatus_version != 2 && dmstatus_version != 3) {
1632 info->hartsellen = 0;
1633 while (hartsel & 1) {
1648 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
1649 "(dmstatus=0x%x). Use `riscv authdata_read` and "
1650 "`riscv authdata_write` commands to authenticate.", dmstatus);
1662 uint32_t abstractcs;
1668 LOG_INFO(
"datacount=%d progbufsize=%d",
info->datacount,
info->progbufsize);
1674 LOG_WARNING(
"We won't be able to execute fence instructions on this "
1675 "target. Memory may not always appear consistent. "
1676 "(progbufsize=%d, impebreak=%d)",
info->progbufsize,
1681 LOG_ERROR(
"set_enable_virtual is not available on this target. It "
1682 "requires a program buffer size of at least 4. (progbufsize=%d) "
1683 "Use `riscv set_enable_virtual off` to continue."
1684 ,
info->progbufsize);
1690 r->current_hartid = i;
1725 LOG_ERROR(
"Fatal: Hart %d failed to halt during examine()", r->current_hartid);
1732 r->debug_buffer_size =
info->progbufsize;
1741 LOG_ERROR(
"Fatal: Failed to read MISA from hart %d.", r->current_hartid);
1756 LOG_DEBUG(
" hart %d: XLEN=%d, misa=0x%" PRIx64, r->current_hartid, r->xlen,
1765 bool haltgroup_supported;
1768 if (haltgroup_supported)
1772 LOG_INFO(
"Core %d could not be made part of halt group %d.",
1779 LOG_INFO(
"Examined RISC-V core; found %d harts",
1781 LOG_INFO(
" hart %d: XLEN=%d, misa=0x%" PRIx64, r->current_hartid, r->xlen,
1789 LOG_ERROR(
"Spec 0.13 only has a single authdata register.");
1802 LOG_ERROR(
"Spec 0.13 only has a single authdata register.");
1806 uint32_t before, after;
1817 LOG_INFO(
"authdata_write resulted in successful authentication");
1847 int method = r->mem_access_methods[i];
1872 LOG_ERROR(
"Unable to determine supported data bits on this target. Assuming 32 bits.");
1893 riscv_print_info_line(
CMD,
"dm",
"abits",
info->abits);
1894 riscv_print_info_line(
CMD,
"dm",
"progbufsize",
info->progbufsize);
1911 uint64_t *vl,
unsigned *debug_vl)
1916 unsigned encoded_vsew;
1956 uint8_t *value,
int regno)
1985 for (
unsigned i = 0; i < debug_vl; i++) {
2015 int regno,
const uint8_t *value)
2042 for (
unsigned i = 0; i < debug_vl; i++) {
2064 switch (size_bytes) {
2081 bool ensure_success)
2093 false, ensure_success);
2100 if (r->reset_delays_wait >= 0) {
2102 if (r->reset_delays_wait <= 0) {
2104 info->dmi_busy_delay = 0;
2105 info->ac_busy_delay = 0;
2114 switch (size_bytes) {
2138 LOG_ERROR(
"Memory sampling is only implemented for sbasize <= 64.");
2143 LOG_ERROR(
"Memory sampling is only implemented for SBA version 1.");
2148 uint32_t sbcs_valid =
false;
2150 uint32_t sbaddress0 = 0;
2151 bool sbaddress0_valid =
false;
2152 uint32_t sbaddress1 = 0;
2153 bool sbaddress1_valid =
false;
2156 const unsigned int repeat = 5;
2158 unsigned int enabled_count = 0;
2160 if (
config->bucket[i].enabled)
2171 target, 1 + enabled_count * 5 * repeat,
2172 info->dmi_busy_delay +
info->bus_master_read_delay);
2176 unsigned int result_bytes = 0;
2177 for (
unsigned int n = 0; n < repeat; n++) {
2179 if (
config->bucket[i].enabled) {
2181 LOG_ERROR(
"Hardware does not support SBA access for %d-byte memory sampling.",
2182 config->bucket[i].size_bytes);
2187 if (enabled_count == 1)
2190 if (!sbcs_valid || sbcs_write != sbcs) {
2197 (!sbaddress1_valid ||
2198 sbaddress1 !=
config->bucket[i].address >> 32)) {
2199 sbaddress1 =
config->bucket[i].address >> 32;
2201 sbaddress1_valid =
true;
2203 if (!sbaddress0_valid ||
2204 sbaddress0 != (
config->bucket[i].address & 0xffffffff)) {
2205 sbaddress0 =
config->bucket[i].address;
2207 sbaddress0_valid =
true;
2209 if (
config->bucket[i].size_bytes > 4)
2212 result_bytes += 1 +
config->bucket[i].size_bytes;
2217 if (buf->
used + result_bytes >= buf->
size) {
2232 info->bus_master_read_delay +=
info->bus_master_read_delay / 10 + 1;
2244 unsigned int read = 0;
2245 for (
unsigned int n = 0; n < repeat; n++) {
2247 if (
config->bucket[i].enabled) {
2250 if (
config->bucket[i].size_bytes > 4)
2256 buf->
used += 1 +
config->bucket[i].size_bytes;
2307 generic_info->dmi_read = &
dmi_read;
2313 generic_info->print_info = &riscv013_print_info;
2314 if (!generic_info->version_specific) {
2316 if (!generic_info->version_specific)
2322 info->progbufsize = -1;
2324 info->dmi_busy_delay = 0;
2325 info->bus_master_read_delay = 0;
2326 info->bus_master_write_delay = 0;
2327 info->ac_busy_delay = 0;
2334 info->abstract_read_csr_supported =
true;
2335 info->abstract_write_csr_supported =
true;
2336 info->abstract_read_fpr_supported =
true;
2337 info->abstract_write_fpr_supported =
true;
2373 uint32_t control =
set_hartsel(control_base, r->current_hartid);
2401 uint32_t control = 0, control_haltreq;
2408 int dmi_busy_delay =
info->dmi_busy_delay;
2419 index = r->current_hartid;
2422 LOG_DEBUG(
"Waiting for hart %d to come out of reset.", index);
2427 LOG_ERROR(
"Hart %d didn't complete a DMI read coming out of "
2428 "reset in %ds; Increase the timeout with riscv "
2429 "set_reset_timeout_sec.",
2443 LOG_ERROR(
"Hart %d didn't leave reset in %ds; "
2445 "Increase the timeout with riscv set_reset_timeout_sec.",
2462 info->dmi_busy_delay = dmi_busy_delay;
2477 LOG_DEBUG(
"Unable to execute pre-fence");
2484 unsigned size_bytes,
bool read)
2491 address, read ?
"read" :
"write", size_bytes * 2);
2492 switch (size_bytes) {
2500 value &= 0xffffffffUL;
2519 for (
int i = (
size - 1) / 4; i >= 0; i--) {
2554 LOG_ERROR(
"Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
2555 "Increase the timeout with riscv set_command_timeout_sec.",
2573 *mstatus_old = *mstatus;
2584 if (*mstatus != *mstatus_old)
2596 if (
size != increment) {
2597 LOG_ERROR(
"sba v0 reads only support size==increment");
2601 LOG_DEBUG(
"System Bus Access: size: %d\tcount:%d\tstart address: 0x%08"
2603 uint8_t *t_buffer =
buffer;
2606 uint32_t access = 0;
2608 const int DM_SBCS_SBSINGLEREAD_OFFSET = 20;
2609 const uint32_t DM_SBCS_SBSINGLEREAD = (0x1U << DM_SBCS_SBSINGLEREAD_OFFSET);
2611 const int DM_SBCS_SBAUTOREAD_OFFSET = 15;
2612 const uint32_t DM_SBCS_SBAUTOREAD = (0x1U << DM_SBCS_SBAUTOREAD_OFFSET);
2616 for (uint32_t i = 0; i <
count; i++) {
2622 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
2623 LOG_DEBUG(
"\r\nread_memory: sab: access: 0x%08x", access);
2629 LOG_DEBUG(
"\r\nread_memory: sab: value: 0x%08x", value);
2638 LOG_DEBUG(
"reading block until final address 0x%" PRIx64, fin_addr);
2646 access =
set_field(access, DM_SBCS_SBAUTOREAD, 1);
2647 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
2649 LOG_DEBUG(
"\r\naccess: 0x%08x", access);
2652 while (cur_addr < fin_addr) {
2653 LOG_DEBUG(
"\r\nsab:autoincrement: \r\n size: %d\tcount:%d\taddress: 0x%08"
2664 if (cur_addr == fin_addr &&
count != 1) {
2685 if (increment !=
size && increment != 0) {
2686 LOG_ERROR(
"sba v1 reads only support increment of size or 0");
2694 while (next_address < end_address) {
2697 if (increment ==
size)
2708 if (
info->bus_master_read_delay) {
2711 LOG_ERROR(
"Failed to scan idle sequence");
2722 for (uint32_t i = (next_address - address) /
size; i <
count - 1; i++) {
2723 for (
int j = (
size - 1) / 4; j >= 0; j--) {
2725 unsigned attempt = 0;
2727 if (attempt++ > 100) {
2742 if (next_read != address - 1) {
2746 next_read = address + i *
size + j * 4;
2750 uint32_t sbcs_read = 0;
2753 unsigned attempt = 0;
2755 if (attempt++ > 100) {
2797 info->bus_master_read_delay +=
info->bus_master_read_delay / 10 + 1;
2803 next_address = end_address;
2823 snprintf(msg, 60,
"%s to %s memory via %s.",
2824 success ?
"Succeeded" :
"Failed",
2825 read ?
"read" :
"write",
2832 warn = r->mem_access_progbuf_warn;
2833 r->mem_access_progbuf_warn =
false;
2836 warn = r->mem_access_sysbus_warn;
2837 r->mem_access_sysbus_warn =
false;
2840 warn = r->mem_access_abstract_warn;
2841 r->mem_access_abstract_warn =
false;
2852 uint32_t
size,
bool read,
char **skip_reason)
2854 assert(skip_reason);
2857 LOG_DEBUG(
"Skipping mem %s via progbuf - insufficient progbuf size.",
2858 read ?
"read" :
"write");
2859 *skip_reason =
"skipped (insufficient progbuf)";
2863 LOG_DEBUG(
"Skipping mem %s via progbuf - target not halted.",
2864 read ?
"read" :
"write");
2865 *skip_reason =
"skipped (target not halted)";
2869 LOG_DEBUG(
"Skipping mem %s via progbuf - XLEN (%d) is too short for %d-bit memory access.",
2871 *skip_reason =
"skipped (XLEN too short)";
2875 LOG_DEBUG(
"Skipping mem %s via progbuf - unsupported size.",
2876 read ?
"read" :
"write");
2877 *skip_reason =
"skipped (unsupported size)";
2881 LOG_DEBUG(
"Skipping mem %s via progbuf - progbuf only supports %u-bit address.",
2883 *skip_reason =
"skipped (too large address)";
2891 uint32_t
size, uint32_t increment,
bool read,
char **skip_reason)
2893 assert(skip_reason);
2897 LOG_DEBUG(
"Skipping mem %s via system bus - unsupported size.",
2898 read ?
"read" :
"write");
2899 *skip_reason =
"skipped (unsupported size)";
2903 if ((
sizeof(address) * 8 > sbasize) && (address >> sbasize)) {
2904 LOG_DEBUG(
"Skipping mem %s via system bus - sba only supports %u-bit address.",
2905 read ?
"read" :
"write", sbasize);
2906 *skip_reason =
"skipped (too large address)";
2910 LOG_DEBUG(
"Skipping mem read via system bus - "
2911 "sba reads only support size==increment or also size==0 for sba v1.");
2912 *skip_reason =
"skipped (unsupported increment)";
2920 uint32_t
size, uint32_t increment,
bool read,
char **skip_reason)
2922 assert(skip_reason);
2927 LOG_DEBUG(
"Skipping mem %s via abstract access - unsupported size: %d bits",
2928 read ?
"read" :
"write",
size * 8);
2929 *skip_reason =
"skipped (unsupported size)";
2933 LOG_DEBUG(
"Skipping mem %s via abstract access - abstract access only supports %u-bit address.",
2935 *skip_reason =
"skipped (too large address)";
2938 if (read &&
size != increment) {
2939 LOG_ERROR(
"Skipping mem read via abstract access - "
2940 "abstract command reads only support size==increment.");
2941 *skip_reason =
"skipped (unsupported increment)";
2959 bool use_aampostincrement =
info->has_aampostincrement !=
YNM_NO;
2974 bool updateaddr =
true;
2975 unsigned int width32 = (
width < 32) ? 32 :
width;
2976 for (uint32_t c = 0; c <
count; c++) {
2982 LOG_ERROR(
"Failed to write arg1 during read_memory_abstract().");
2994 if (new_address == address +
size) {
2995 LOG_DEBUG(
"aampostincrement is supported on this target.");
2998 LOG_WARNING(
"Buggy aampostincrement! Address not incremented correctly.");
3006 LOG_DEBUG(
"aampostincrement is not supported on this target.");
3037 bool use_aampostincrement =
info->has_aampostincrement !=
YNM_NO;
3049 const uint8_t *p =
buffer;
3050 bool updateaddr =
true;
3051 for (uint32_t c = 0; c <
count; c++) {
3056 LOG_ERROR(
"Failed to write arg0 during write_memory_abstract().");
3065 LOG_ERROR(
"Failed to write arg1 during write_memory_abstract().");
3077 if (new_address == address +
size) {
3078 LOG_DEBUG(
"aampostincrement is supported on this target.");
3081 LOG_WARNING(
"Buggy aampostincrement! Address not incremented correctly.");
3089 LOG_DEBUG(
"aampostincrement is not supported on this target.");
3122 if (increment == 0 &&
3154 while (index <
count) {
3156 LOG_DEBUG(
"i=%d, count=%d, read_addr=0x%" PRIx64, index,
count, read_addr);
3166 info->dmi_busy_delay +
info->ac_busy_delay);
3171 for (
unsigned j = index; j <
count; j++) {
3186 uint32_t abstractcs;
3194 unsigned next_index;
3195 unsigned ignore_last = 0;
3196 switch (
info->cmderr) {
3198 LOG_DEBUG(
"successful (partial?) memory read");
3199 next_index = index + reads;
3202 LOG_DEBUG(
"memory read resulted in busy response");
3209 uint32_t dmi_data0, dmi_data1 = 0;
3223 if (increment == 0) {
3226 next_index = counter;
3228 uint64_t next_read_addr;
3231 next_index = (next_read_addr - address) / increment;
3238 uint64_t value64 = (((uint64_t)dmi_data1) << 32) | dmi_data0;
3255 LOG_DEBUG(
"error when reading memory, abstractcs=0x%08lx", (
long)abstractcs);
3266 for (
unsigned j = index - 2; j < index + reads; j++) {
3268 LOG_DEBUG(
"index=%d, reads=%d, next_index=%d, ignore_last=%d, j=%d",
3269 index, reads, next_index, ignore_last, j);
3270 if (j + 3 + ignore_last > next_index)
3285 LOG_WARNING(
"Batch memory read encountered DMI error %d. "
3286 "Falling back on slower reads.",
status);
3294 LOG_WARNING(
"Batch memory read encountered DMI error %d. "
3295 "Falling back on slower reads.",
status);
3318 uint32_t dmi_data0, dmi_data1 = 0;
3323 uint64_t value64 = (((uint64_t)dmi_data1) << 32) | dmi_data0;
3349 uint64_t mstatus = 0;
3350 uint64_t mstatus_old = 0;
3358 goto restore_mstatus;
3380 goto restore_mstatus;
3386 goto restore_mstatus;
3388 goto restore_mstatus;
3392 goto restore_mstatus;
3411 if (mstatus != mstatus_old)
3425 LOG_ERROR(
"XLEN (%d) is too short for %d-bit memory read.",
3445 uint64_t mstatus = 0;
3446 uint64_t mstatus_old = 0;
3454 uint64_t s0, s1, s2;
3505 uint32_t count_i = 1;
3506 uint8_t *buffer_i =
buffer;
3508 for (uint32_t i = 0; i <
count; i++, address_i += increment, buffer_i +=
size) {
3530 if (mstatus != mstatus_old)
3544 LOG_ERROR(
"BUG: Unsupported size for memory read: %d",
size);
3552 char *progbuf_result =
"disabled";
3553 char *sysbus_result =
"disabled";
3554 char *abstract_result =
"disabled";
3557 int method = r->mem_access_methods[i];
3566 progbuf_result =
"failed";
3577 sysbus_result =
"failed";
3585 abstract_result =
"failed";
3597 LOG_ERROR(
" progbuf=%s, sysbus=%s, abstract=%s", progbuf_result, sysbus_result, abstract_result);
3605 LOG_DEBUG(
"System Bus Access: size: %d\tcount:%d\tstart address: 0x%08"
3621 LOG_DEBUG(
"\r\naccess: 0x%08" PRIx64, access);
3622 LOG_DEBUG(
"\r\nwrite_memory:SAB: ONE OFF: value 0x%08" PRIx64, value);
3632 LOG_DEBUG(
"\r\naccess: 0x%08" PRIx64, access);
3639 t_addr = address +
offset;
3643 LOG_DEBUG(
"SAB:autoincrement: expected address: 0x%08x value: 0x%08x"
3644 PRIx64, (uint32_t)t_addr, (uint32_t)value);
3668 while (next_address < end_address) {
3675 info->dmi_busy_delay +
info->bus_master_write_delay);
3679 for (uint32_t i = (next_address - address) /
size; i <
count; i++) {
3687 ((uint32_t) p[12]) |
3688 (((uint32_t) p[13]) << 8) |
3689 (((uint32_t) p[14]) << 16) |
3690 (((uint32_t) p[15]) << 24));
3695 (((uint32_t) p[9]) << 8) |
3696 (((uint32_t) p[10]) << 16) |
3697 (((uint32_t) p[11]) << 24));
3701 (((uint32_t) p[5]) << 8) |
3702 (((uint32_t) p[6]) << 16) |
3703 (((uint32_t) p[7]) << 24));
3704 uint32_t value = p[0];
3706 value |= ((uint32_t) p[2]) << 16;
3707 value |= ((uint32_t) p[3]) << 24;
3710 value |= ((uint32_t) p[1]) << 8;
3714 next_address +=
size;
3725 bool dmi_busy_encountered;
3729 if (dmi_busy_encountered)
3730 LOG_DEBUG(
"DMI busy encountered during system bus write.");
3736 LOG_ERROR(
"Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
3737 "Increase the timeout with riscv set_command_timeout_sec.",
3747 LOG_DEBUG(
"Sbbusyerror encountered during system bus write.");
3751 info->bus_master_write_delay +=
info->bus_master_write_delay / 10 + 1;
3758 if (next_address < address) {
3761 " - buggy sbautoincrement in hw?", next_address);
3777 sberror, sbaddress);
3778 if (sbaddress < address) {
3782 " - buggy sbautoincrement in hw?", next_address);
3800 LOG_ERROR(
"XLEN (%d) is too short for %d-bit memory write.",
3809 uint64_t mstatus = 0;
3810 uint64_t mstatus_old = 0;
3845 LOG_ERROR(
"write_memory_progbuf(): Unsupported size: %d",
size);
3861 bool setup_needed =
true;
3862 LOG_DEBUG(
"writing until final address 0x%016" PRIx64, fin_addr);
3863 while (cur_addr < fin_addr) {
3864 LOG_DEBUG(
"transferring burst starting at address 0x%016" PRIx64,
3870 info->dmi_busy_delay +
info->ac_busy_delay);
3875 unsigned start = (cur_addr - address) /
size;
3915 setup_needed =
false;
3934 uint32_t abstractcs;
3935 bool dmi_busy_encountered;
3936 result =
dmi_op(
target, &abstractcs, &dmi_busy_encountered,
3945 LOG_DEBUG(
"successful (partial?) memory write");
3948 LOG_DEBUG(
"Memory write resulted in abstract command busy response.");
3949 else if (dmi_busy_encountered)
3950 LOG_DEBUG(
"Memory write resulted in DMI busy response.");
3958 setup_needed =
true;
3960 LOG_ERROR(
"error when writing memory, abstractcs=0x%08lx", (
long)abstractcs);
3976 if (mstatus != mstatus_old)
3990 LOG_ERROR(
"BUG: Unsupported size for memory write: %d",
size);
3998 char *progbuf_result =
"disabled";
3999 char *sysbus_result =
"disabled";
4000 char *abstract_result =
"disabled";
4003 int method = r->mem_access_methods[i];
4012 progbuf_result =
"failed";
4023 sysbus_result =
"failed";
4031 abstract_result =
"failed";
4043 LOG_ERROR(
" progbuf=%s, sysbus=%s, abstract=%s", progbuf_result, sysbus_result, abstract_result);
4104 LOG_DEBUG(
"[%d] writing 0x%" PRIx64
" to register %s",
4112 uint64_t actual_value;
4115 if (value != actual_value) {
4116 LOG_ERROR(
"Written PC (0x%" PRIx64
") does not match read back "
4117 "value (0x%" PRIx64
")", value, actual_value);
4147 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4168 unsigned hawindow_count = (dm->
hart_count + 31) / 32;
4169 uint32_t hawindow[hawindow_count];
4171 memset(hawindow, 0,
sizeof(uint32_t) * hawindow_count);
4174 unsigned total_selected = 0;
4179 unsigned index =
info->index;
4183 hawindow[index / 32] |= 1 << (index % 32);
4191 if (total_selected <= 1) {
4196 for (
unsigned i = 0; i < hawindow_count; i++) {
4214 bool use_hasel =
false;
4219 LOG_DEBUG(
"halting hart %d", r->current_hartid);
4225 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4227 for (
size_t i = 0; i < 256; ++i)
4238 LOG_ERROR(
"unable to halt hart %d", r->current_hartid);
4239 LOG_ERROR(
" dmcontrol=0x%08x", dmcontrol);
4240 LOG_ERROR(
" dmstatus =0x%08x", dmstatus);
4266 bool use_hasel =
false;
4304 LOG_INFO(
"Hart %d unexpectedly reset!", hartid);
4350 LOG_ERROR(
" dcsr=0x%016lx", (
long)dcsr);
4364 LOG_DEBUG(
"cache hit for 0x%" PRIx32
" @%d", data, index);
4378 uint32_t run_program = 0;
4424 else if (sbaccess64)
4426 else if (sbaccess32)
4428 else if (sbaccess16)
4446 else if (sbaccess64)
4448 else if (sbaccess32)
4458 LOG_INFO(
"Testing System Bus Access as defined by RISC-V Debug Spec v0.13");
4460 uint32_t tests_failed = 0;
4468 uint32_t sbcs = sbcs_orig;
4473 if (max_sbaccess == -1) {
4474 LOG_ERROR(
"System Bus Access not supported in this config.");
4479 LOG_ERROR(
"System Bus Access unsupported SBVERSION (%d). Only version 1 is supported.",
4485 assert(num_sbdata_regs);
4487 uint32_t rd_buf[num_sbdata_regs];
4494 uint32_t test_patterns[4] = {0xdeadbeef, 0xfeedbabe, 0x12345678, 0x08675309};
4495 for (uint32_t sbaccess = 0; sbaccess <= (uint32_t)max_sbaccess; sbaccess++) {
4499 uint32_t compare_mask = (sbaccess == 0) ? 0xff : (sbaccess == 1) ? 0xffff : 0xffffffff;
4501 for (uint32_t i = 0; i < num_words; i++) {
4502 uint32_t
addr = legal_address + (i << sbaccess);
4503 uint32_t wr_data[num_sbdata_regs];
4504 for (uint32_t j = 0; j < num_sbdata_regs; j++)
4505 wr_data[j] = test_patterns[j] + i;
4509 for (uint32_t i = 0; i < num_words; i++) {
4510 uint32_t
addr = legal_address + (i << sbaccess);
4512 for (uint32_t j = 0; j < num_sbdata_regs; j++) {
4513 if (((test_patterns[j]+i)&compare_mask) != (rd_buf[j]&compare_mask)) {
4514 LOG_ERROR(
"System Bus Access Test 1: Error reading non-autoincremented address %x,"
4515 "expected val = %x, read val = %x",
addr, test_patterns[j]+i, rd_buf[j]);
4516 test_passed =
false;
4523 LOG_INFO(
"System Bus Access Test 1: Simple write/read test PASSED.");
4532 for (uint32_t sbaccess = 0; sbaccess <= (uint32_t)max_sbaccess; sbaccess++) {
4538 curr_addr = legal_address;
4539 for (uint32_t i = 0; i < num_words; i++) {
4540 prev_addr = curr_addr;
4543 if ((curr_addr - prev_addr != (uint32_t)(1 << sbaccess)) && (i != 0)) {
4544 LOG_ERROR(
"System Bus Access Test 2: Error with address auto-increment, sbaccess = %x.", sbaccess);
4545 test_passed =
false;
4559 curr_addr = legal_address;
4560 for (uint32_t i = 0; i < num_words; i++) {
4561 prev_addr = curr_addr;
4564 if ((curr_addr - prev_addr != (uint32_t)(1 << sbaccess)) && (i != 0)) {
4565 LOG_ERROR(
"System Bus Access Test 2: Error with address auto-increment, sbaccess = %x", sbaccess);
4566 test_passed =
false;
4572 LOG_ERROR(
"System Bus Access Test 2: Error reading auto-incremented address,"
4573 "expected val = %x, read val = %x.", i, val);
4574 test_passed =
false;
4580 LOG_INFO(
"System Bus Access Test 2: Address auto-increment test PASSED.");
4591 LOG_INFO(
"System Bus Access Test 3: Illegal address read test PASSED.");
4593 LOG_ERROR(
"System Bus Access Test 3: Illegal address read test FAILED, unable to clear to 0.");
4595 LOG_ERROR(
"System Bus Access Test 3: Illegal address read test FAILED, unable to set error code.");
4607 LOG_INFO(
"System Bus Access Test 4: Illegal address write test PASSED.");
4609 LOG_ERROR(
"System Bus Access Test 4: Illegal address write test FAILED, unable to clear to 0.");
4613 LOG_ERROR(
"System Bus Access Test 4: Illegal address write test FAILED, unable to set error code.");
4621 LOG_INFO(
"System Bus Access Test 5: SBCS sbaccess error test PASSED, all sbaccess sizes supported.");
4633 LOG_INFO(
"System Bus Access Test 5: SBCS sbaccess error test PASSED.");
4635 LOG_ERROR(
"System Bus Access Test 5: SBCS sbaccess error test FAILED, unable to clear to 0.");
4639 LOG_ERROR(
"System Bus Access Test 5: SBCS sbaccess error test FAILED, unable to set error code.");
4655 LOG_INFO(
"System Bus Access Test 6: SBCS address alignment error test PASSED");
4657 LOG_ERROR(
"System Bus Access Test 6: SBCS address alignment error test FAILED, unable to clear to 0.");
4661 LOG_ERROR(
"System Bus Access Test 6: SBCS address alignment error test FAILED, unable to set error code.");
4667 if (run_sbbusyerror_test) {
4671 for (
int i = 0; i < 16; i++)
4674 for (
int i = 0; i < 16; i++)
4683 LOG_INFO(
"System Bus Access Test 7: SBCS sbbusyerror test PASSED.");
4685 LOG_ERROR(
"System Bus Access Test 7: SBCS sbbusyerror test FAILED, unable to clear to 0.");
4689 LOG_ERROR(
"System Bus Access Test 7: SBCS sbbusyerror test FAILED, unable to set error code.");
4694 if (tests_failed == 0) {
4698 LOG_ERROR(
"%d TESTS FAILED", tests_failed);
4705 uint32_t *
write_data, uint32_t write_size, uint32_t sbcs)
4710 uint32_t masked_addr;
4719 for (uint32_t i = 0; i < sba_size/32; i++) {
4720 masked_addr = (
addr >> 32*i) & 0xffffffff;
4730 for (
int i = write_size-1; i >= 0; i--)
4735 uint32_t *rd_buf, uint32_t read_size, uint32_t sbcs)
4740 uint32_t masked_addr;
4750 for (
int i = sba_size/32-1; i >= 0; i--) {
4751 masked_addr = (
addr >> 32*i) & 0xffffffff;
4761 for (uint32_t i = 0; i < read_size; i++)
4797 bool step,
bool use_hasel)
4800 LOG_DEBUG(
"resuming hart %d (for step?=%d)", r->current_hartid,
step);
4802 LOG_ERROR(
"Hart %d is not halted!", r->current_hartid);
4810 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4817 for (
size_t i = 0; i < 256; ++i) {
4832 LOG_ERROR(
"unable to resume hart %d", r->current_hartid);
4835 LOG_ERROR(
" dmstatus =0x%08x", dmstatus);
4850 uint32_t abstractcs;
4856 LOG_ERROR(
"abstractcs.busy is not going low after %d seconds "
4857 "(abstractcs=0x%x). The target is either really slow or "
4858 "broken. You could increase the timeout with riscv "
4859 "set_command_timeout_sec.",
uint32_t riscv_batch_get_dmi_read_data(struct riscv_batch *batch, size_t key)
size_t riscv_batch_add_dmi_read(struct riscv_batch *batch, unsigned address)
size_t riscv_batch_available_scans(struct riscv_batch *batch)
struct riscv_batch * riscv_batch_alloc(struct target *target, size_t scans, size_t idle)
int riscv_batch_run(struct riscv_batch *batch)
void riscv_batch_add_dmi_write(struct riscv_batch *batch, unsigned address, uint64_t data)
unsigned riscv_batch_get_dmi_read_op(struct riscv_batch *batch, size_t key)
void riscv_batch_free(struct riscv_batch *batch)
bool riscv_batch_full(struct riscv_batch *batch)
void buffer_shr(void *_buf, unsigned buf_len, unsigned count)
static void buf_set_u64(uint8_t *_buffer, unsigned first, unsigned num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned 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 first, unsigned 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 first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
static int halted(struct target *target, const char *label)
#define DM_ABSTRACTAUTO_AUTOEXECDATA_OFFSET
#define AC_ACCESS_REGISTER_TRANSFER
#define AC_ACCESS_REGISTER_POSTEXEC
#define DM_DMCONTROL_ACKHAVERESET
#define DM_DMSTATUS_ANYHAVERESET
#define DM_DMSTATUS_CONFSTRPTRVALID
#define DM_DMSTATUS_ALLHALTED
#define DM_SBCS_SBACCESS64
#define DM_SBCS_SBVERSION
#define DM_DMCONTROL_RESUMEREQ
#define DM_DMCONTROL_HARTSELHI_OFFSET
#define DM_ABSTRACTCS_BUSY
#define DM_DMSTATUS_ALLRESUMEACK
#define DM_DMCONTROL_HARTSELLO_LENGTH
#define DM_SBCS_SBBUSYERROR
#define DM_ABSTRACTCS_CMDERR
#define DM_HARTINFO_DATASIZE
#define AC_ACCESS_REGISTER_REGNO
#define DM_ABSTRACTCS_PROGBUFSIZE
#define DM_DMSTATUS_ALLUNAVAIL
#define DM_ABSTRACTCS_DATACOUNT
#define DTM_DMI_DATA_OFFSET
#define DM_DMSTATUS_AUTHENTICATED
#define DM_SBCS_SBAUTOINCREMENT
#define AC_ACCESS_MEMORY_WRITE
#define DM_DMCONTROL_HARTSELLO
#define DM_DMCONTROL_NDMRESET
#define AC_ACCESS_REGISTER_WRITE
#define DM_DMSTATUS_ALLRUNNING
#define DM_DMCONTROL_HARTRESET
#define DTM_DMI_OP_OFFSET
#define AC_ACCESS_MEMORY_CMDTYPE
#define DM_HARTINFO_DATAACCESS
#define DTM_DTMCS_VERSION
#define DM_DMSTATUS_IMPEBREAK
#define DM_DMSTATUS_ANYNONEXISTENT
#define DM_DMCONTROL_DMACTIVE
#define DM_DMSTATUS_HASRESETHALTREQ
#define DM_DMSTATUS_ANYRESUMEACK
#define DM_DMCONTROL_HASEL
#define DTM_DMI_ADDRESS_OFFSET
#define DM_SBCS_SBACCESS8
#define DTM_DTMCS_DMIRESET
#define DM_DMCONTROL_HARTSELHI_LENGTH
#define DM_DMSTATUS_ANYUNAVAIL
#define AC_ACCESS_REGISTER_AARSIZE
#define DM_DMSTATUS_VERSION
#define DM_DMSTATUS_ANYHALTED
#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 DTM_DTMCS_DMISTAT
#define AC_ACCESS_MEMORY_AAMSIZE
#define DM_SBCS_SBREADONDATA
#define DM_DMSTATUS_ALLNONEXISTENT
#define DM_HARTINFO_DATAADDR
#define DM_DMCONTROL_HALTREQ
#define DTM_DMI_DATA_LENGTH
#define AC_ACCESS_MEMORY_AAMVIRTUAL
#define DM_DMCONTROL_HARTSELLO_OFFSET
#define DM_SBCS_SBACCESS128
#define DTM_DMI_OP_LENGTH
#define DM_DMSTATUS_ANYRUNNING
#define DM_COMMAND_CMDTYPE
enum esirisc_reg_num number
const char * gdb_regno_name(enum gdb_regno regno)
static struct device_config config
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap_state_t state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
void jtag_add_runtest(int num_cycles, tap_state_t state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
The JTAG interface can be implemented with a software or hardware fifo.
static void list_add(struct list_head *new, struct list_head *head)
list_add - add a new entry
#define list_for_each_entry(pos, head, member)
list_for_each_entry - iterate over list of given type
static void INIT_LIST_HEAD(struct list_head *list)
INIT_LIST_HEAD - Initialize a list_head structure.
void log_printf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format,...)
#define ERROR_NOT_IMPLEMENTED
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define ERROR_TIMEOUT_REACHED
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static uint32_t fsd(unsigned int src, unsigned int base, uint16_t offset) __attribute__((unused))
static uint32_t csrr(unsigned int rd, unsigned int csr) __attribute__((unused))
static uint32_t sw(unsigned int src, unsigned int base, uint16_t offset) __attribute__((unused))
static uint32_t vmv_x_s(unsigned int rd, unsigned int vs2) __attribute__((unused))
static uint32_t fld(unsigned int dest, unsigned int base, uint16_t offset) __attribute__((unused))
static uint32_t vsetvli(unsigned int dest, unsigned int src, uint16_t imm) __attribute__((unused))
static uint32_t vslide1down_vx(unsigned int vd, unsigned int vs2, unsigned int rs1, unsigned int vm) __attribute__((unused))
static uint32_t fmv_x_d(unsigned dest, unsigned src) __attribute__((unused))
static uint32_t fmv_w_x(unsigned dest, unsigned src) __attribute__((unused))
static uint32_t fmv_d_x(unsigned dest, unsigned src) __attribute__((unused))
static uint32_t fmv_x_w(unsigned dest, unsigned src) __attribute__((unused))
static uint32_t auipc(unsigned int dest) __attribute__((unused))
int riscv_program_fence_i(struct riscv_program *p)
int riscv_program_lbr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
int riscv_program_write(struct riscv_program *program)
int riscv_program_fence(struct riscv_program *p)
int riscv_program_csrrsi(struct riscv_program *p, enum gdb_regno d, unsigned int z, enum gdb_regno csr)
int riscv_program_addi(struct riscv_program *p, enum gdb_regno d, enum gdb_regno s, int16_t u)
int riscv_program_ldr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
int riscv_program_insert(struct riscv_program *p, riscv_insn_t i)
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_lhr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
int riscv_program_ebreak(struct riscv_program *p)
int riscv_program_swr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
int riscv_program_lwr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
int riscv_program_sdr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
int riscv_program_shr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
int riscv_program_exec(struct riscv_program *p, struct target *t)
Add ebreak and execute the program.
int riscv_program_csrrci(struct riscv_program *p, enum gdb_regno d, unsigned int z, enum gdb_regno csr)
int riscv_program_sbr(struct riscv_program *p, enum gdb_regno d, enum gdb_regno b, int offset)
static int step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
static int dmi_write(struct target *target, uint32_t address, uint32_t value)
static int dmi_read_exec(struct target *target, uint32_t *value, uint32_t address)
static int scratch_write64(struct target *target, scratch_mem_t *scratch, uint64_t value)
static int is_fpu_reg(uint32_t gdb_regno)
static void increase_dmi_busy_delay(struct target *target)
static int riscv013_step_or_resume_current_hart(struct target *target, bool step, bool use_hasel)
static int dmi_write_exec(struct target *target, uint32_t address, uint32_t value, bool ensure_success)
static int maybe_execute_fence_i(struct target *target)
static int examine_progbuf(struct target *target)
#define CSR_DCSR_CAUSE_GROUP
static int register_read(struct target *target, uint64_t *value, uint32_t number)
Read register value from the target.
static int riscv013_execute_debug_buffer(struct target *target)
static int riscv013_step_current_hart(struct target *target)
static uint32_t set_hartsel(uint32_t initial, uint32_t index)
static riscv_insn_t riscv013_read_debug_buffer(struct target *target, unsigned index)
static void dump_field(int idle, const struct scan_field *field)
static void select_dmi(struct target *target)
static uint32_t sb_sbaccess(unsigned int size_bytes)
static int riscv013_select_current_hart(struct target *target)
static int register_read_direct(struct target *target, uint64_t *value, uint32_t number)
Actually read registers from the target right now.
static riscv_reg_t read_abstract_arg(struct target *target, unsigned index, unsigned size_bits)
static dm013_info_t * get_dm(struct target *target)
Return the DM structure for this target.
static uint32_t access_register_command(struct target *target, uint32_t number, unsigned size, uint32_t flags)
static int write_memory_progbuf(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int read_memory_bus_word(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
static int cleanup_after_vector_access(struct target *target, uint64_t vtype, uint64_t vl)
static int riscv013_set_register_buf(struct target *target, int regno, const uint8_t *value)
static int riscv013_on_step_or_resume(struct target *target, bool step)
static int read_memory_progbuf_inner(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment)
Read the requested memory, taking care to execute every read exactly once, even if cmderr=busy is enc...
static int execute_fence(struct target *target)
static int riscv013_on_step(struct target *target)
static int select_prepped_harts(struct target *target, bool *use_hasel)
static int read_memory_progbuf(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment)
Read the requested memory, silently handling memory access errors.
static void log_mem_access_result(struct target *target, bool success, int method, bool read)
#define CMDERR_NOT_SUPPORTED
#define CSR_DCSR_CAUSE_STEP
static int riscv013_dmi_write_u64_bits(struct target *target)
static void riscv013_clear_abstract_error(struct target *target)
static int register_write_direct(struct target *target, unsigned number, uint64_t value)
Immediately write the new value to the requested register.
static int read_memory_progbuf_one(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
static int riscv013_get_register_buf(struct target *target, uint8_t *value, int regno)
static bool mem_should_skip_sysbus(struct target *target, target_addr_t address, uint32_t size, uint32_t increment, bool read, char **skip_reason)
struct target_type riscv013_target
static int wait_for_idle(struct target *target, uint32_t *abstractcs)
static bool mem_should_skip_progbuf(struct target *target, target_addr_t address, uint32_t size, bool read, char **skip_reason)
static int write_memory_bus_v0(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int examine(struct target *target)
static int deassert_reset(struct target *target)
static int get_max_sbaccess(struct target *target)
#define CSR_DCSR_CAUSE_SWBP
static int cleanup_after_register_access(struct target *target, uint64_t mstatus, int regno)
static int register_read_abstract(struct target *target, uint64_t *value, uint32_t number, unsigned size)
static int prep_for_register_access(struct target *target, uint64_t *mstatus, int regno)
static int modify_privilege(struct target *target, uint64_t *mstatus, uint64_t *mstatus_old)
static bool has_sufficient_progbuf(struct target *target, unsigned size)
static LIST_HEAD(dm_list)
static int riscv013_halt_go(struct target *target)
static int assert_reset(struct target *target)
static bool riscv013_is_halted(struct target *target)
static uint32_t __attribute__((unused))
#define get_field(reg, mask)
Since almost everything can be accomplish by scanning the dbus register, all functions here assume db...
static int sb_write_address(struct target *target, target_addr_t address, bool ensure_success)
static void increase_ac_busy_delay(struct target *target)
static unsigned riscv013_data_bits(struct target *target)
static unsigned register_size(struct target *target, unsigned number)
Return register size in bits.
static int riscv013_hart_count(struct target *target)
static uint32_t dtmcontrol_scan(struct target *target, uint32_t out)
static int discover_vlenb(struct target *target)
static enum riscv_halt_reason riscv013_halt_reason(struct target *target)
static int read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment)
static uint32_t get_num_sbdata_regs(struct target *target)
static int dmstatus_read(struct target *target, uint32_t *dmstatus, bool authenticated)
static int dmi_read(struct target *target, uint32_t *value, uint32_t address)
static uint32_t abstract_memory_size(unsigned width)
static int sba_supports_access(struct target *target, unsigned int size_bytes)
static int dmi_op_timeout(struct target *target, uint32_t *data_in, bool *dmi_busy_encountered, int dmi_op, uint32_t address, uint32_t data_out, int timeout_sec, bool exec, bool ensure_success)
static int init_target(struct command_context *cmd_ctx, struct target *target)
static int arch_state(struct target *target)
static int riscv013_resume_prep(struct target *target)
static int scratch_read64(struct target *target, scratch_mem_t *scratch, uint64_t *value)
static int riscv013_set_register(struct target *target, int regid, uint64_t value)
static int write_memory_bus_v1(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static riscv013_info_t * get_info(const struct target *target)
static int riscv013_test_sba_config_reg(struct target *target, target_addr_t legal_address, uint32_t num_words, target_addr_t illegal_address, bool run_sbbusyerror_test)
static void riscv013_fill_dmi_nop_u64(struct target *target, char *buf)
static int riscv013_on_halt(struct target *target)
static int riscv013_authdata_write(struct target *target, uint32_t value, unsigned int index)
static int write_abstract_arg(struct target *target, unsigned index, riscv_reg_t value, unsigned size_bits)
static int riscv013_authdata_read(struct target *target, uint32_t *value, unsigned int index)
static int is_vector_reg(uint32_t gdb_regno)
static void write_memory_sba_simple(struct target *target, target_addr_t addr, uint32_t *write_data, uint32_t write_size, uint32_t sbcs)
static int riscv013_halt_prep(struct target *target)
#define CSR_DCSR_CAUSE_DEBUGINT
static void log_memory_access(target_addr_t address, uint64_t value, unsigned size_bytes, bool read)
static int set_haltgroup(struct target *target, bool *supported)
static target_addr_t sb_read_address(struct target *target)
static int scratch_reserve(struct target *target, scratch_mem_t *scratch, struct riscv_program *program, unsigned size_bytes)
Find some scratch memory to be used with the given program.
static int riscv013_write_debug_buffer(struct target *target, unsigned index, riscv_insn_t d)
static int riscv013_resume_go(struct target *target)
static int read_memory_abstract(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment)
#define CSR_DCSR_CAUSE_TRIGGER
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 int dmi_op(struct target *target, uint32_t *data_in, bool *dmi_busy_encountered, int dmi_op, uint32_t address, uint32_t data_out, bool exec, bool ensure_success)
static int batch_run(const struct target *target, struct riscv_batch *batch)
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 uint32_t access_memory_command(struct target *target, bool virtual, unsigned width, bool postincrement, bool write)
static COMMAND_HELPER(riscv013_print_info, struct target *target)
static void read_memory_sba_simple(struct target *target, target_addr_t addr, uint32_t *rd_buf, uint32_t read_size, uint32_t sbcs)
static int prep_for_vector_access(struct target *target, uint64_t *vtype, uint64_t *vl, unsigned *debug_vl)
static int write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int read_memory_bus_v1(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment)
Read the requested memory using the system bus interface.
static void decode_dmi(char *text, unsigned address, unsigned data)
static int register_write_abstract(struct target *target, uint32_t number, uint64_t value, unsigned size)
static int read_memory_bus_v0(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment)
static void riscv013_fill_dmi_write_u64(struct target *target, char *buf, int a, uint64_t d)
#define set_field(reg, mask, val)
static int sample_memory(struct target *target, struct riscv_sample_buf *buf, riscv_sample_config_t *config, int64_t until_ms)
static void riscv013_fill_dmi_read_u64(struct target *target, char *buf, int a)
static int dmstatus_read_timeout(struct target *target, uint32_t *dmstatus, bool authenticated, unsigned timeout_sec)
#define CSR_DCSR_CAUSE_HALT
static int write_memory_abstract(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
static int scratch_release(struct target *target, scratch_mem_t *scratch)
static dmi_status_t dmi_scan(struct target *target, uint32_t *address_in, uint32_t *data_in, dmi_op_t op, uint32_t address_out, uint32_t data_out, bool exec)
exec: If this is set, assume the scan results in an execution, so more run-test/idle cycles may be re...
static bool mem_should_skip_abstract(struct target *target, target_addr_t address, uint32_t size, uint32_t increment, bool read, char **skip_reason)
static int execute_abstract_command(struct target *target, uint32_t command)
static int riscv013_get_register(struct target *target, riscv_reg_t *value, int rid)
int riscv_reset_timeout_sec
int riscv_set_register(struct target *target, enum gdb_regno regid, riscv_reg_t value)
This function is called when the debug user wants to change the value of a register.
struct scan_field select_dbus
bool riscv_is_halted(struct target *target)
int riscv_init_registers(struct target *target)
int riscv_halt(struct target *target)
unsigned riscv_xlen(const struct target *target)
void riscv_add_bscan_tunneled_scan(struct target *target, struct scan_field *field, riscv_bscan_tunneled_scan_context_t *ctxt)
int riscv_current_hartid(const struct target *target)
int riscv_select_current_hart(struct target *target)
struct scan_field select_dtmcontrol
uint32_t dtmcontrol_scan_via_bscan(struct target *target, uint32_t out)
int riscv_openocd_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
int riscv_openocd_poll(struct target *target)
void select_dmi_via_bscan(struct target *target)
bool riscv_enable_virtual
bool riscv_supports_extension(struct target *target, char letter)
int riscv_enumerate_triggers(struct target *target)
Count triggers, and initialize trigger_count for each hart.
int riscv_command_timeout_sec
int riscv_count_harts(struct target *target)
int bscan_tunnel_ir_width
#define RISCV_SAMPLE_BUF_TIMESTAMP_BEFORE
static struct riscv_info * riscv_info(const struct target *target) __attribute__((unused))
@ RISCV_MEM_ACCESS_UNSPECIFIED
@ RISCV_MEM_ACCESS_SYSBUS
@ RISCV_MEM_ACCESS_PROGBUF
@ RISCV_MEM_ACCESS_ABSTRACT
#define RISCV_NUM_MEM_ACCESS_METHODS
size_t size
Size of the control block search area.
struct list_head target_list
uint32_t progbuf_cache[16]
bool abstract_write_fpr_supported
yes_no_maybe_t has_aampostincrement
bool abstract_write_csr_supported
yes_no_maybe_t progbuf_writable
unsigned int bus_master_read_delay
bool abstract_read_csr_supported
bool abstract_read_fpr_supported
unsigned int ac_busy_delay
unsigned int dmi_busy_delay
riscv_addr_t progbuf_address
This structure defines a single scan field in the scan.
int num_bits
The number of bits this field specifies.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
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
bool target_has_event_action(struct target *target, enum target_event event)
Returns true only if the target has a handler for the specified event.
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
void target_handle_event(struct target *target, enum target_event e)
static void write_data(FILE *f, const void *data, size_t len)
@ TARGET_EVENT_RESET_ASSERT
static const char * target_name(struct target *target)
Returns the instance-specific name of the specified target.
static void target_set_examined(struct target *target)
Sets the examined flag for the given 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