34 bool step,
bool use_hasel);
76 #define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
77 #define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
79 #define CSR_DCSR_CAUSE_SWBP 1
80 #define CSR_DCSR_CAUSE_TRIGGER 2
81 #define CSR_DCSR_CAUSE_DEBUGINT 3
82 #define CSR_DCSR_CAUSE_STEP 4
83 #define CSR_DCSR_CAUSE_HALT 5
84 #define CSR_DCSR_CAUSE_GROUP 6
86 #define RISCV013_INFO(r) riscv013_info_t *r = get_info(target)
109 #define CMDERR_NONE 0
110 #define CMDERR_BUSY 1
111 #define CMDERR_NOT_SUPPORTED 2
112 #define CMDERR_EXCEPTION 3
113 #define CMDERR_HALT_RESUME 4
114 #define CMDERR_OTHER 7
149 uint32_t progbuf_cache[16];
224 assert(
info->version_specific);
225 return info->version_specific;
268 target_entry = calloc(1,
sizeof(*target_entry));
293 static void decode_dmi(
char *text,
unsigned address,
unsigned data)
295 static const struct {
366 text += strlen(text);
374 static const char *
const op_string[] = {
"-",
"r",
"w",
"?"};
375 static const char *
const status_string[] = {
"+",
"?",
"F",
"b"};
391 __FILE__, __LINE__,
"scan",
392 "%db %s %08x @%02x -> %s %08x @%02x; %di",
393 field->
num_bits, op_string[out_op], out_data, out_address,
394 status_string[in_op], in_data, in_address, idle);
400 if (in_text[0] || out_text[0]) {
440 LOG_ERROR(
"failed jtag scan: %d", retval);
445 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
453 info->dmi_busy_delay +=
info->dmi_busy_delay / 10 + 1;
454 LOG_DEBUG(
"dtmcs_idle=%d, dmi_busy_delay=%d, ac_busy_delay=%d",
455 info->dtmcs_idle,
info->dmi_busy_delay,
456 info->ac_busy_delay);
466 uint32_t *data_in,
dmi_op_t op, uint32_t address_out, uint32_t data_out,
472 size_t num_bytes = (
num_bits + 7) / 8;
473 uint8_t in[num_bytes];
474 uint8_t out[num_bytes];
482 if (r->reset_delays_wait >= 0) {
483 r->reset_delays_wait--;
484 if (r->reset_delays_wait < 0) {
485 info->dmi_busy_delay = 0;
486 info->ac_busy_delay = 0;
490 memset(in, 0, num_bytes);
491 memset(out, 0, num_bytes);
493 assert(
info->abits != 0);
512 int idle_count =
info->dmi_busy_delay;
514 idle_count +=
info->ac_busy_delay;
558 bool *dmi_busy_encountered,
int dmi_op, uint32_t address,
559 uint32_t data_out,
int timeout_sec,
bool exec,
bool ensure_success)
566 if (dmi_busy_encountered)
567 *dmi_busy_encountered =
false;
595 if (dmi_busy_encountered)
596 *dmi_busy_encountered =
true;
613 if (ensure_success) {
622 if (dmi_busy_encountered)
623 *dmi_busy_encountered =
true;
628 LOG_ERROR(
"Failed %s (NOP) at 0x%x; value=0x%x, status=%d",
629 op_name, address, *data_in,
status);
631 LOG_ERROR(
"Failed %s (NOP) at 0x%x; status=%d", op_name, address,
646 bool *dmi_busy_encountered,
int dmi_op, uint32_t address,
647 uint32_t data_out,
bool exec,
bool ensure_success)
652 LOG_ERROR(
"DMI operation didn't complete in %d seconds. The target is "
653 "either really slow or broken. You could increase the "
654 "timeout with riscv set_command_timeout_sec.",
677 uint32_t value,
bool ensure_success)
683 bool authenticated,
unsigned timeout_sec)
690 if (dmstatus_version != 2 && dmstatus_version != 3) {
691 LOG_ERROR(
"OpenOCD only supports Debug Module version 2 (0.13) and 3 (1.0), not "
692 "%d (dmstatus=0x%x). This error might be caused by a JTAG "
693 "signal issue. Try reducing the JTAG clock speed.",
696 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
697 "(dmstatus=0x%x). Use `riscv authdata_read` and "
698 "`riscv authdata_write` commands to authenticate.", *dmstatus);
714 info->ac_busy_delay +=
info->ac_busy_delay / 10 + 1;
715 LOG_DEBUG(
"dtmcs_idle=%d, dmi_busy_delay=%d, ac_busy_delay=%d",
716 info->dtmcs_idle,
info->dmi_busy_delay,
717 info->ac_busy_delay);
749 const char *errors[8] = {
759 LOG_ERROR(
"Abstract command ended in error '%s' (abstractcs=0x%x)",
760 errors[
info->cmderr], *abstractcs);
763 LOG_ERROR(
"Timed out after %ds waiting for busy to go low (abstractcs=0x%x). "
764 "Increase the timeout with riscv set_command_timeout_sec.",
778 LOG_DEBUG(
"command=0x%x; access register, size=%d, postexec=%d, "
779 "transfer=%d, write=%d, regno=0x%x",
796 uint32_t abstractcs = 0;
815 unsigned offset = index * size_bits / 32;
818 LOG_ERROR(
"Unsupported size: %d bits", size_bits);
822 value |= ((uint64_t) v) << 32;
834 unsigned offset = index * size_bits / 32;
837 LOG_ERROR(
"Unsupported size: %d bits", size_bits);
852 unsigned size, uint32_t flags)
899 !
info->abstract_read_fpr_supported)
902 !
info->abstract_read_csr_supported)
915 info->abstract_read_fpr_supported =
false;
916 LOG_INFO(
"Disabling abstract command reads from FPRs.");
918 info->abstract_read_csr_supported =
false;
919 LOG_INFO(
"Disabling abstract command reads from CSRs.");
932 uint64_t value,
unsigned size)
937 !
info->abstract_write_fpr_supported)
940 !
info->abstract_write_csr_supported)
954 info->abstract_write_fpr_supported =
false;
955 LOG_INFO(
"Disabling abstract command writes to FPRs.");
957 info->abstract_write_csr_supported =
false;
958 LOG_INFO(
"Disabling abstract command writes to CSRs.");
994 unsigned width,
bool postincrement,
bool write)
1015 if (
info->progbufsize < 1) {
1017 LOG_INFO(
"No program buffer present.");
1051 if (written == (uint32_t)
info->progbuf_address) {
1052 LOG_INFO(
"progbuf is writable at 0x%" PRIx64,
1053 info->progbuf_address);
1057 LOG_INFO(
"progbuf is not writeable at 0x%" PRIx64,
1058 info->progbuf_address);
1106 uint64_t mstatus,
int regno)
1137 unsigned size_bytes)
1140 while (alignment < size_bytes)
1148 if (
info->dataaccess == 1) {
1151 if (
info->dataaddr & (1<<11))
1170 scratch->
hart_address = (
info->progbuf_address + program_size + alignment - 1) &
1174 info->progbufsize)) {
1190 LOG_ERROR(
"Couldn't find %d bytes of scratch RAM to use. Please configure "
1191 "a work area with 'configure -work-area-phys'.", size_bytes);
1212 *value |= ((uint64_t) v) << 32;
1220 *value |= ((uint64_t) v) << 32;
1228 (((uint64_t)
buffer[1]) << 8) |
1229 (((uint64_t)
buffer[2]) << 16) |
1230 (((uint64_t)
buffer[3]) << 24) |
1231 (((uint64_t)
buffer[4]) << 32) |
1232 (((uint64_t)
buffer[5]) << 40) |
1233 (((uint64_t)
buffer[6]) << 48) |
1234 (((uint64_t)
buffer[7]) << 56);
1289 return info->progbufsize + r->impebreak >=
size;
1320 bool use_scratch =
false;
1423 bool use_scratch =
false;
1507 LOG_ERROR(
"Timed out after %ds waiting for authbusy to go low (dmstatus=0x%x). "
1508 "Increase the timeout with riscv set_command_timeout_sec.",
1527 free(
info->version_specific);
1550 LOG_WARNING(
"Couldn't read vlenb for %s; vector register access won't work.",
1557 LOG_INFO(
"Vector support with vlenb=%d", r->vlenb);
1567 LOG_DEBUG(
"dtmcontrol=0x%x", dtmcontrol);
1573 if (dtmcontrol == 0) {
1574 LOG_ERROR(
"dtmcontrol is 0. Check JTAG connectivity/board power.");
1578 LOG_ERROR(
"Unsupported DTM version %d. (dtmcontrol=0x%x)",
1607 LOG_ERROR(
"Debug Module did not become active. dmcontrol=0x%x",
1617 LOG_DEBUG(
"dmstatus: 0x%08x", dmstatus);
1619 if (dmstatus_version != 2 && dmstatus_version != 3) {
1628 info->hartsellen = 0;
1629 while (hartsel & 1) {
1644 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
1645 "(dmstatus=0x%x). Use `riscv authdata_read` and "
1646 "`riscv authdata_write` commands to authenticate.", dmstatus);
1658 uint32_t abstractcs;
1664 LOG_INFO(
"datacount=%d progbufsize=%d",
info->datacount,
info->progbufsize);
1670 LOG_WARNING(
"We won't be able to execute fence instructions on this "
1671 "target. Memory may not always appear consistent. "
1672 "(progbufsize=%d, impebreak=%d)",
info->progbufsize,
1677 LOG_ERROR(
"set_enable_virtual is not available on this target. It "
1678 "requires a program buffer size of at least 4. (progbufsize=%d) "
1679 "Use `riscv set_enable_virtual off` to continue."
1680 ,
info->progbufsize);
1686 r->current_hartid = i;
1721 LOG_ERROR(
"Fatal: Hart %d failed to halt during examine()", r->current_hartid);
1728 r->debug_buffer_size =
info->progbufsize;
1737 LOG_ERROR(
"Fatal: Failed to read MISA from hart %d.", r->current_hartid);
1752 LOG_DEBUG(
" hart %d: XLEN=%d, misa=0x%" PRIx64, r->current_hartid, r->xlen,
1761 bool haltgroup_supported;
1764 if (haltgroup_supported)
1768 LOG_INFO(
"Core %d could not be made part of halt group %d.",
1775 LOG_INFO(
"Examined RISC-V core; found %d harts",
1777 LOG_INFO(
" hart %d: XLEN=%d, misa=0x%" PRIx64, r->current_hartid, r->xlen,
1785 LOG_ERROR(
"Spec 0.13 only has a single authdata register.");
1798 LOG_ERROR(
"Spec 0.13 only has a single authdata register.");
1802 uint32_t before, after;
1813 LOG_INFO(
"authdata_write resulted in successful authentication");
1843 int method = r->mem_access_methods[i];
1868 LOG_ERROR(
"Unable to determine supported data bits on this target. Assuming 32 bits.");
1889 riscv_print_info_line(
CMD,
"dm",
"abits",
info->abits);
1890 riscv_print_info_line(
CMD,
"dm",
"progbufsize",
info->progbufsize);
1907 uint64_t *vl,
unsigned *debug_vl)
1912 unsigned encoded_vsew;
1952 uint8_t *value,
int regno)
1981 for (
unsigned i = 0; i < debug_vl; i++) {
2011 int regno,
const uint8_t *value)
2038 for (
unsigned i = 0; i < debug_vl; i++) {
2060 switch (size_bytes) {
2077 bool ensure_success)
2089 false, ensure_success);
2096 if (r->reset_delays_wait >= 0) {
2098 if (r->reset_delays_wait <= 0) {
2100 info->dmi_busy_delay = 0;
2101 info->ac_busy_delay = 0;
2110 switch (size_bytes) {
2134 LOG_ERROR(
"Memory sampling is only implemented for sbasize <= 64.");
2139 LOG_ERROR(
"Memory sampling is only implemented for SBA version 1.");
2144 uint32_t sbcs_valid =
false;
2146 uint32_t sbaddress0 = 0;
2147 bool sbaddress0_valid =
false;
2148 uint32_t sbaddress1 = 0;
2149 bool sbaddress1_valid =
false;
2152 const unsigned int repeat = 5;
2154 unsigned int enabled_count = 0;
2156 if (
config->bucket[i].enabled)
2167 target, 1 + enabled_count * 5 * repeat,
2168 info->dmi_busy_delay +
info->bus_master_read_delay);
2172 unsigned int result_bytes = 0;
2173 for (
unsigned int n = 0; n < repeat; n++) {
2175 if (
config->bucket[i].enabled) {
2177 LOG_ERROR(
"Hardware does not support SBA access for %d-byte memory sampling.",
2178 config->bucket[i].size_bytes);
2183 if (enabled_count == 1)
2186 if (!sbcs_valid || sbcs_write != sbcs) {
2193 (!sbaddress1_valid ||
2194 sbaddress1 !=
config->bucket[i].address >> 32)) {
2195 sbaddress1 =
config->bucket[i].address >> 32;
2197 sbaddress1_valid =
true;
2199 if (!sbaddress0_valid ||
2200 sbaddress0 != (
config->bucket[i].address & 0xffffffff)) {
2201 sbaddress0 =
config->bucket[i].address;
2203 sbaddress0_valid =
true;
2205 if (
config->bucket[i].size_bytes > 4)
2208 result_bytes += 1 +
config->bucket[i].size_bytes;
2213 if (buf->
used + result_bytes >= buf->
size) {
2228 info->bus_master_read_delay +=
info->bus_master_read_delay / 10 + 1;
2240 unsigned int read = 0;
2241 for (
unsigned int n = 0; n < repeat; n++) {
2243 if (
config->bucket[i].enabled) {
2246 if (
config->bucket[i].size_bytes > 4)
2252 buf->
used += 1 +
config->bucket[i].size_bytes;
2303 generic_info->dmi_read = &
dmi_read;
2308 generic_info->print_info = &riscv013_print_info;
2309 if (!generic_info->version_specific) {
2311 if (!generic_info->version_specific)
2317 info->progbufsize = -1;
2319 info->dmi_busy_delay = 0;
2320 info->bus_master_read_delay = 0;
2321 info->bus_master_write_delay = 0;
2322 info->ac_busy_delay = 0;
2329 info->abstract_read_csr_supported =
true;
2330 info->abstract_write_csr_supported =
true;
2331 info->abstract_read_fpr_supported =
true;
2332 info->abstract_write_fpr_supported =
true;
2368 uint32_t control =
set_hartsel(control_base, r->current_hartid);
2396 uint32_t control = 0, control_haltreq;
2403 int dmi_busy_delay =
info->dmi_busy_delay;
2414 index = r->current_hartid;
2417 LOG_DEBUG(
"Waiting for hart %d to come out of reset.", index);
2422 LOG_ERROR(
"Hart %d didn't complete a DMI read coming out of "
2423 "reset in %ds; Increase the timeout with riscv "
2424 "set_reset_timeout_sec.",
2438 LOG_ERROR(
"Hart %d didn't leave reset in %ds; "
2440 "Increase the timeout with riscv set_reset_timeout_sec.",
2457 info->dmi_busy_delay = dmi_busy_delay;
2472 LOG_DEBUG(
"Unable to execute pre-fence");
2479 unsigned size_bytes,
bool read)
2486 address, read ?
"read" :
"write", size_bytes * 2);
2487 switch (size_bytes) {
2495 value &= 0xffffffffUL;
2514 for (
int i = (
size - 1) / 4; i >= 0; i--) {
2549 LOG_ERROR(
"Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
2550 "Increase the timeout with riscv set_command_timeout_sec.",
2568 *mstatus_old = *mstatus;
2579 if (*mstatus != *mstatus_old)
2591 if (
size != increment) {
2592 LOG_ERROR(
"sba v0 reads only support size==increment");
2596 LOG_DEBUG(
"System Bus Access: size: %d\tcount:%d\tstart address: 0x%08"
2598 uint8_t *t_buffer =
buffer;
2601 uint32_t access = 0;
2603 const int DM_SBCS_SBSINGLEREAD_OFFSET = 20;
2604 const uint32_t DM_SBCS_SBSINGLEREAD = (0x1U << DM_SBCS_SBSINGLEREAD_OFFSET);
2606 const int DM_SBCS_SBAUTOREAD_OFFSET = 15;
2607 const uint32_t DM_SBCS_SBAUTOREAD = (0x1U << DM_SBCS_SBAUTOREAD_OFFSET);
2611 for (uint32_t i = 0; i <
count; i++) {
2617 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
2618 LOG_DEBUG(
"\r\nread_memory: sab: access: 0x%08x", access);
2624 LOG_DEBUG(
"\r\nread_memory: sab: value: 0x%08x", value);
2633 LOG_DEBUG(
"reading block until final address 0x%" PRIx64, fin_addr);
2641 access =
set_field(access, DM_SBCS_SBAUTOREAD, 1);
2642 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
2644 LOG_DEBUG(
"\r\naccess: 0x%08x", access);
2647 while (cur_addr < fin_addr) {
2648 LOG_DEBUG(
"\r\nsab:autoincrement: \r\n size: %d\tcount:%d\taddress: 0x%08"
2659 if (cur_addr == fin_addr &&
count != 1) {
2680 if (increment !=
size && increment != 0) {
2681 LOG_ERROR(
"sba v1 reads only support increment of size or 0");
2689 while (next_address < end_address) {
2692 if (increment ==
size)
2703 if (
info->bus_master_read_delay) {
2706 LOG_ERROR(
"Failed to scan idle sequence");
2717 for (uint32_t i = (next_address - address) /
size; i <
count - 1; i++) {
2718 for (
int j = (
size - 1) / 4; j >= 0; j--) {
2720 unsigned attempt = 0;
2722 if (attempt++ > 100) {
2737 if (next_read != address - 1) {
2741 next_read = address + i *
size + j * 4;
2745 uint32_t sbcs_read = 0;
2748 unsigned attempt = 0;
2750 if (attempt++ > 100) {
2792 info->bus_master_read_delay +=
info->bus_master_read_delay / 10 + 1;
2798 next_address = end_address;
2818 snprintf(msg, 60,
"%s to %s memory via %s.",
2819 success ?
"Succeeded" :
"Failed",
2820 read ?
"read" :
"write",
2827 warn = r->mem_access_progbuf_warn;
2828 r->mem_access_progbuf_warn =
false;
2831 warn = r->mem_access_sysbus_warn;
2832 r->mem_access_sysbus_warn =
false;
2835 warn = r->mem_access_abstract_warn;
2836 r->mem_access_abstract_warn =
false;
2847 uint32_t
size,
bool read,
char **skip_reason)
2849 assert(skip_reason);
2852 LOG_DEBUG(
"Skipping mem %s via progbuf - insufficient progbuf size.",
2853 read ?
"read" :
"write");
2854 *skip_reason =
"skipped (insufficient progbuf)";
2858 LOG_DEBUG(
"Skipping mem %s via progbuf - target not halted.",
2859 read ?
"read" :
"write");
2860 *skip_reason =
"skipped (target not halted)";
2864 LOG_DEBUG(
"Skipping mem %s via progbuf - XLEN (%d) is too short for %d-bit memory access.",
2866 *skip_reason =
"skipped (XLEN too short)";
2870 LOG_DEBUG(
"Skipping mem %s via progbuf - unsupported size.",
2871 read ?
"read" :
"write");
2872 *skip_reason =
"skipped (unsupported size)";
2876 LOG_DEBUG(
"Skipping mem %s via progbuf - progbuf only supports %u-bit address.",
2878 *skip_reason =
"skipped (too large address)";
2886 uint32_t
size, uint32_t increment,
bool read,
char **skip_reason)
2888 assert(skip_reason);
2892 LOG_DEBUG(
"Skipping mem %s via system bus - unsupported size.",
2893 read ?
"read" :
"write");
2894 *skip_reason =
"skipped (unsupported size)";
2898 if ((
sizeof(address) * 8 > sbasize) && (address >> sbasize)) {
2899 LOG_DEBUG(
"Skipping mem %s via system bus - sba only supports %u-bit address.",
2900 read ?
"read" :
"write", sbasize);
2901 *skip_reason =
"skipped (too large address)";
2905 LOG_DEBUG(
"Skipping mem read via system bus - "
2906 "sba reads only support size==increment or also size==0 for sba v1.");
2907 *skip_reason =
"skipped (unsupported increment)";
2915 uint32_t
size, uint32_t increment,
bool read,
char **skip_reason)
2917 assert(skip_reason);
2922 LOG_DEBUG(
"Skipping mem %s via abstract access - unsupported size: %d bits",
2923 read ?
"read" :
"write",
size * 8);
2924 *skip_reason =
"skipped (unsupported size)";
2928 LOG_DEBUG(
"Skipping mem %s via abstract access - abstract access only supports %u-bit address.",
2930 *skip_reason =
"skipped (too large address)";
2933 if (read &&
size != increment) {
2934 LOG_ERROR(
"Skipping mem read via abstract access - "
2935 "abstract command reads only support size==increment.");
2936 *skip_reason =
"skipped (unsupported increment)";
2954 bool use_aampostincrement =
info->has_aampostincrement !=
YNM_NO;
2969 bool updateaddr =
true;
2970 unsigned int width32 = (
width < 32) ? 32 :
width;
2971 for (uint32_t c = 0; c <
count; c++) {
2977 LOG_ERROR(
"Failed to write arg1 during read_memory_abstract().");
2989 if (new_address == address +
size) {
2990 LOG_DEBUG(
"aampostincrement is supported on this target.");
2993 LOG_WARNING(
"Buggy aampostincrement! Address not incremented correctly.");
3001 LOG_DEBUG(
"aampostincrement is not supported on this target.");
3032 bool use_aampostincrement =
info->has_aampostincrement !=
YNM_NO;
3044 const uint8_t *p =
buffer;
3045 bool updateaddr =
true;
3046 for (uint32_t c = 0; c <
count; c++) {
3051 LOG_ERROR(
"Failed to write arg0 during write_memory_abstract().");
3060 LOG_ERROR(
"Failed to write arg1 during write_memory_abstract().");
3072 if (new_address == address +
size) {
3073 LOG_DEBUG(
"aampostincrement is supported on this target.");
3076 LOG_WARNING(
"Buggy aampostincrement! Address not incremented correctly.");
3084 LOG_DEBUG(
"aampostincrement is not supported on this target.");
3117 if (increment == 0 &&
3149 while (index <
count) {
3151 LOG_DEBUG(
"i=%d, count=%d, read_addr=0x%" PRIx64, index,
count, read_addr);
3161 info->dmi_busy_delay +
info->ac_busy_delay);
3166 for (
unsigned j = index; j <
count; j++) {
3181 uint32_t abstractcs;
3189 unsigned next_index;
3190 unsigned ignore_last = 0;
3191 switch (
info->cmderr) {
3193 LOG_DEBUG(
"successful (partial?) memory read");
3194 next_index = index + reads;
3197 LOG_DEBUG(
"memory read resulted in busy response");
3204 uint32_t dmi_data0, dmi_data1 = 0;
3218 if (increment == 0) {
3221 next_index = counter;
3223 uint64_t next_read_addr;
3226 next_index = (next_read_addr - address) / increment;
3233 uint64_t value64 = (((uint64_t)dmi_data1) << 32) | dmi_data0;
3250 LOG_DEBUG(
"error when reading memory, abstractcs=0x%08lx", (
long)abstractcs);
3261 for (
unsigned j = index - 2; j < index + reads; j++) {
3263 LOG_DEBUG(
"index=%d, reads=%d, next_index=%d, ignore_last=%d, j=%d",
3264 index, reads, next_index, ignore_last, j);
3265 if (j + 3 + ignore_last > next_index)
3280 LOG_WARNING(
"Batch memory read encountered DMI error %d. "
3281 "Falling back on slower reads.",
status);
3289 LOG_WARNING(
"Batch memory read encountered DMI error %d. "
3290 "Falling back on slower reads.",
status);
3313 uint32_t dmi_data0, dmi_data1 = 0;
3318 uint64_t value64 = (((uint64_t)dmi_data1) << 32) | dmi_data0;
3344 uint64_t mstatus = 0;
3345 uint64_t mstatus_old = 0;
3353 goto restore_mstatus;
3375 goto restore_mstatus;
3381 goto restore_mstatus;
3383 goto restore_mstatus;
3387 goto restore_mstatus;
3406 if (mstatus != mstatus_old)
3420 LOG_ERROR(
"XLEN (%d) is too short for %d-bit memory read.",
3440 uint64_t mstatus = 0;
3441 uint64_t mstatus_old = 0;
3500 uint32_t count_i = 1;
3501 uint8_t *buffer_i =
buffer;
3503 for (uint32_t i = 0; i <
count; i++, address_i += increment, buffer_i +=
size) {
3525 if (mstatus != mstatus_old)
3539 LOG_ERROR(
"BUG: Unsupported size for memory read: %d",
size);
3547 char *progbuf_result =
"disabled";
3548 char *sysbus_result =
"disabled";
3549 char *abstract_result =
"disabled";
3552 int method = r->mem_access_methods[i];
3561 progbuf_result =
"failed";
3572 sysbus_result =
"failed";
3580 abstract_result =
"failed";
3592 LOG_ERROR(
" progbuf=%s, sysbus=%s, abstract=%s", progbuf_result, sysbus_result, abstract_result);
3600 LOG_DEBUG(
"System Bus Access: size: %d\tcount:%d\tstart address: 0x%08"
3616 LOG_DEBUG(
"\r\naccess: 0x%08" PRIx64, access);
3617 LOG_DEBUG(
"\r\nwrite_memory:SAB: ONE OFF: value 0x%08" PRIx64, value);
3627 LOG_DEBUG(
"\r\naccess: 0x%08" PRIx64, access);
3634 t_addr = address +
offset;
3638 LOG_DEBUG(
"SAB:autoincrement: expected address: 0x%08x value: 0x%08x"
3639 PRIx64, (uint32_t)t_addr, (uint32_t)value);
3663 while (next_address < end_address) {
3670 info->dmi_busy_delay +
info->bus_master_write_delay);
3674 for (uint32_t i = (next_address - address) /
size; i <
count; i++) {
3682 ((uint32_t) p[12]) |
3683 (((uint32_t) p[13]) << 8) |
3684 (((uint32_t) p[14]) << 16) |
3685 (((uint32_t) p[15]) << 24));
3690 (((uint32_t) p[9]) << 8) |
3691 (((uint32_t) p[10]) << 16) |
3692 (((uint32_t) p[11]) << 24));
3696 (((uint32_t) p[5]) << 8) |
3697 (((uint32_t) p[6]) << 16) |
3698 (((uint32_t) p[7]) << 24));
3699 uint32_t value = p[0];
3701 value |= ((uint32_t) p[2]) << 16;
3702 value |= ((uint32_t) p[3]) << 24;
3705 value |= ((uint32_t) p[1]) << 8;
3709 next_address +=
size;
3720 bool dmi_busy_encountered;
3724 if (dmi_busy_encountered)
3725 LOG_DEBUG(
"DMI busy encountered during system bus write.");
3731 LOG_ERROR(
"Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
3732 "Increase the timeout with riscv set_command_timeout_sec.",
3742 LOG_DEBUG(
"Sbbusyerror encountered during system bus write.");
3746 info->bus_master_write_delay +=
info->bus_master_write_delay / 10 + 1;
3753 if (next_address < address) {
3756 " - buggy sbautoincrement in hw?", next_address);
3772 sberror, sbaddress);
3773 if (sbaddress < address) {
3777 " - buggy sbautoincrement in hw?", next_address);
3795 LOG_ERROR(
"XLEN (%d) is too short for %d-bit memory write.",
3804 uint64_t mstatus = 0;
3805 uint64_t mstatus_old = 0;
3840 LOG_ERROR(
"write_memory_progbuf(): Unsupported size: %d",
size);
3856 bool setup_needed =
true;
3857 LOG_DEBUG(
"writing until final address 0x%016" PRIx64, fin_addr);
3858 while (cur_addr < fin_addr) {
3859 LOG_DEBUG(
"transferring burst starting at address 0x%016" PRIx64,
3865 info->dmi_busy_delay +
info->ac_busy_delay);
3870 unsigned start = (cur_addr - address) /
size;
3910 setup_needed =
false;
3929 uint32_t abstractcs;
3930 bool dmi_busy_encountered;
3931 result =
dmi_op(
target, &abstractcs, &dmi_busy_encountered,
3940 LOG_DEBUG(
"successful (partial?) memory write");
3943 LOG_DEBUG(
"Memory write resulted in abstract command busy response.");
3944 else if (dmi_busy_encountered)
3945 LOG_DEBUG(
"Memory write resulted in DMI busy response.");
3953 setup_needed =
true;
3955 LOG_ERROR(
"error when writing memory, abstractcs=0x%08lx", (
long)abstractcs);
3971 if (mstatus != mstatus_old)
3985 LOG_ERROR(
"BUG: Unsupported size for memory write: %d",
size);
3993 char *progbuf_result =
"disabled";
3994 char *sysbus_result =
"disabled";
3995 char *abstract_result =
"disabled";
3998 int method = r->mem_access_methods[i];
4007 progbuf_result =
"failed";
4018 sysbus_result =
"failed";
4026 abstract_result =
"failed";
4038 LOG_ERROR(
" progbuf=%s, sysbus=%s, abstract=%s", progbuf_result, sysbus_result, abstract_result);
4099 LOG_DEBUG(
"[%d] writing 0x%" PRIx64
" to register %s",
4107 uint64_t actual_value;
4110 if (value != actual_value) {
4111 LOG_ERROR(
"Written PC (0x%" PRIx64
") does not match read back "
4112 "value (0x%" PRIx64
")", value, actual_value);
4142 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4163 unsigned hawindow_count = (dm->
hart_count + 31) / 32;
4164 uint32_t hawindow[hawindow_count];
4166 memset(hawindow, 0,
sizeof(uint32_t) * hawindow_count);
4169 unsigned total_selected = 0;
4174 unsigned index =
info->index;
4178 hawindow[index / 32] |= 1 << (index % 32);
4186 if (total_selected <= 1) {
4191 for (
unsigned i = 0; i < hawindow_count; i++) {
4209 bool use_hasel =
false;
4214 LOG_DEBUG(
"halting hart %d", r->current_hartid);
4220 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4222 for (
size_t i = 0; i < 256; ++i)
4233 LOG_ERROR(
"unable to halt hart %d", r->current_hartid);
4234 LOG_ERROR(
" dmcontrol=0x%08x", dmcontrol);
4235 LOG_ERROR(
" dmstatus =0x%08x", dmstatus);
4261 bool use_hasel =
false;
4299 LOG_INFO(
"Hart %d unexpectedly reset!", hartid);
4345 LOG_ERROR(
" dcsr=0x%016lx", (
long)dcsr);
4359 LOG_DEBUG(
"cache hit for 0x%" PRIx32
" @%d", data, index);
4373 uint32_t run_program = 0;
4438 bool step,
bool use_hasel)
4441 LOG_DEBUG(
"resuming hart %d (for step?=%d)", r->current_hartid,
step);
4443 LOG_ERROR(
"Hart %d is not halted!", r->current_hartid);
4451 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4458 for (
size_t i = 0; i < 256; ++i) {
4473 LOG_ERROR(
"unable to resume hart %d", r->current_hartid);
4476 LOG_ERROR(
" dmstatus =0x%08x", dmstatus);
4491 uint32_t abstractcs;
4497 LOG_ERROR(
"abstractcs.busy is not going low after %d seconds "
4498 "(abstractcs=0x%x). The target is either really slow or "
4499 "broken. You could increase the timeout with riscv "
4500 "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)
#define list_for_each_entry(p, h, field)
static void INIT_LIST_HEAD(struct list_head *list)
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)
#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 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 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 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 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
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.
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)
@ TARGET_EVENT_RESET_ASSERT
static const char * target_name(const 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