34 bool step,
bool use_hasel);
75 #define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
76 #define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
78 #define CSR_DCSR_CAUSE_SWBP 1
79 #define CSR_DCSR_CAUSE_TRIGGER 2
80 #define CSR_DCSR_CAUSE_DEBUGINT 3
81 #define CSR_DCSR_CAUSE_STEP 4
82 #define CSR_DCSR_CAUSE_HALT 5
83 #define CSR_DCSR_CAUSE_GROUP 6
85 #define RISCV013_INFO(r) riscv013_info_t *r = get_info(target)
108 #define CMDERR_NONE 0
109 #define CMDERR_BUSY 1
110 #define CMDERR_NOT_SUPPORTED 2
111 #define CMDERR_EXCEPTION 3
112 #define CMDERR_HALT_RESUME 4
113 #define CMDERR_OTHER 7
148 uint32_t progbuf_cache[16];
223 assert(
info->version_specific);
224 return info->version_specific;
267 target_entry = calloc(1,
sizeof(*target_entry));
292 static void decode_dmi(
char *text,
unsigned int address,
unsigned int data)
294 static const struct {
295 unsigned int address;
365 text += strlen(text);
373 static const char *
const op_string[] = {
"-",
"r",
"w",
"?"};
374 static const char *
const status_string[] = {
"+",
"?",
"F",
"b"};
390 __FILE__, __LINE__,
"scan",
391 "%ub %s %08x @%02x -> %s %08x @%02x; %di",
392 field->
num_bits, op_string[out_op], out_data, out_address,
393 status_string[in_op], in_data, in_address, idle);
399 if (in_text[0] || out_text[0]) {
439 LOG_ERROR(
"failed jtag scan: %d", retval);
444 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
452 info->dmi_busy_delay +=
info->dmi_busy_delay / 10 + 1;
453 LOG_DEBUG(
"dtmcs_idle=%d, dmi_busy_delay=%d, ac_busy_delay=%d",
454 info->dtmcs_idle,
info->dmi_busy_delay,
455 info->ac_busy_delay);
465 uint32_t *data_in,
dmi_op_t op, uint32_t address_out, uint32_t data_out,
471 size_t num_bytes = (
num_bits + 7) / 8;
472 uint8_t in[num_bytes];
473 uint8_t out[num_bytes];
481 if (r->reset_delays_wait >= 0) {
482 r->reset_delays_wait--;
483 if (r->reset_delays_wait < 0) {
484 info->dmi_busy_delay = 0;
485 info->ac_busy_delay = 0;
489 memset(in, 0, num_bytes);
490 memset(out, 0, num_bytes);
492 assert(
info->abits != 0);
511 int idle_count =
info->dmi_busy_delay;
513 idle_count +=
info->ac_busy_delay;
557 bool *dmi_busy_encountered,
int dmi_op, uint32_t address,
558 uint32_t data_out,
int timeout_sec,
bool exec,
bool ensure_success)
565 if (dmi_busy_encountered)
566 *dmi_busy_encountered =
false;
594 if (dmi_busy_encountered)
595 *dmi_busy_encountered =
true;
612 if (ensure_success) {
621 if (dmi_busy_encountered)
622 *dmi_busy_encountered =
true;
627 LOG_ERROR(
"Failed %s (NOP) at 0x%x; value=0x%x, status=%d",
628 op_name, address, *data_in,
status);
630 LOG_ERROR(
"Failed %s (NOP) at 0x%x; status=%d", op_name, address,
645 bool *dmi_busy_encountered,
int dmi_op, uint32_t address,
646 uint32_t data_out,
bool exec,
bool ensure_success)
651 LOG_ERROR(
"DMI operation didn't complete in %d seconds. The target is "
652 "either really slow or broken. You could increase the "
653 "timeout with riscv set_command_timeout_sec.",
676 uint32_t value,
bool ensure_success)
682 bool authenticated,
unsigned int timeout_sec)
689 if (dmstatus_version != 2 && dmstatus_version != 3) {
690 LOG_ERROR(
"OpenOCD only supports Debug Module version 2 (0.13) and 3 (1.0), not "
691 "%d (dmstatus=0x%x). This error might be caused by a JTAG "
692 "signal issue. Try reducing the JTAG clock speed.",
695 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
696 "(dmstatus=0x%x). Use `riscv authdata_read` and "
697 "`riscv authdata_write` commands to authenticate.", *dmstatus);
713 info->ac_busy_delay +=
info->ac_busy_delay / 10 + 1;
714 LOG_DEBUG(
"dtmcs_idle=%d, dmi_busy_delay=%d, ac_busy_delay=%d",
715 info->dtmcs_idle,
info->dmi_busy_delay,
716 info->ac_busy_delay);
748 const char *errors[8] = {
758 LOG_ERROR(
"Abstract command ended in error '%s' (abstractcs=0x%x)",
759 errors[
info->cmderr], *abstractcs);
762 LOG_ERROR(
"Timed out after %ds waiting for busy to go low (abstractcs=0x%x). "
763 "Increase the timeout with riscv set_command_timeout_sec.",
777 LOG_DEBUG(
"command=0x%x; access register, size=%d, postexec=%d, "
778 "transfer=%d, write=%d, regno=0x%x",
795 uint32_t abstractcs = 0;
810 unsigned int size_bits)
814 unsigned int offset = index * size_bits / 32;
817 LOG_ERROR(
"Unsupported size: %d bits", size_bits);
821 value |= ((uint64_t) v) << 32;
833 unsigned int offset = index * size_bits / 32;
836 LOG_ERROR(
"Unsupported size: %d bits", size_bits);
851 unsigned int size, uint32_t flags)
898 !
info->abstract_read_fpr_supported)
901 !
info->abstract_read_csr_supported)
914 info->abstract_read_fpr_supported =
false;
915 LOG_INFO(
"Disabling abstract command reads from FPRs.");
917 info->abstract_read_csr_supported =
false;
918 LOG_INFO(
"Disabling abstract command reads from CSRs.");
931 uint64_t value,
unsigned int size)
936 !
info->abstract_write_fpr_supported)
939 !
info->abstract_write_csr_supported)
953 info->abstract_write_fpr_supported =
false;
954 LOG_INFO(
"Disabling abstract command writes to FPRs.");
956 info->abstract_write_csr_supported =
false;
957 LOG_INFO(
"Disabling abstract command writes to CSRs.");
993 unsigned int width,
bool postincrement,
bool write)
1014 if (
info->progbufsize < 1) {
1016 LOG_INFO(
"No program buffer present.");
1050 if (written == (uint32_t)
info->progbuf_address) {
1051 LOG_INFO(
"progbuf is writable at 0x%" PRIx64,
1052 info->progbuf_address);
1056 LOG_INFO(
"progbuf is not writeable at 0x%" PRIx64,
1057 info->progbuf_address);
1105 uint64_t mstatus,
int regno)
1136 unsigned int size_bytes)
1139 while (alignment < size_bytes)
1147 if (
info->dataaccess == 1) {
1150 if (
info->dataaddr & (1<<11))
1169 scratch->
hart_address = (
info->progbuf_address + program_size + alignment - 1) &
1173 info->progbufsize)) {
1189 LOG_ERROR(
"Couldn't find %d bytes of scratch RAM to use. Please configure "
1190 "a work area with 'configure -work-area-phys'.", size_bytes);
1211 *value |= ((uint64_t) v) << 32;
1219 *value |= ((uint64_t) v) << 32;
1227 (((uint64_t)
buffer[1]) << 8) |
1228 (((uint64_t)
buffer[2]) << 16) |
1229 (((uint64_t)
buffer[3]) << 24) |
1230 (((uint64_t)
buffer[4]) << 32) |
1231 (((uint64_t)
buffer[5]) << 40) |
1232 (((uint64_t)
buffer[6]) << 48) |
1233 (((uint64_t)
buffer[7]) << 56);
1288 return info->progbufsize + r->impebreak >=
size;
1319 bool use_scratch =
false;
1422 bool use_scratch =
false;
1506 LOG_ERROR(
"Timed out after %ds waiting for authbusy to go low (dmstatus=0x%x). "
1507 "Increase the timeout with riscv set_command_timeout_sec.",
1526 free(
info->version_specific);
1549 LOG_WARNING(
"Couldn't read vlenb for %s; vector register access won't work.",
1556 LOG_INFO(
"Vector support with vlenb=%d", r->vlenb);
1566 LOG_DEBUG(
"dtmcontrol=0x%x", dtmcontrol);
1572 if (dtmcontrol == 0) {
1573 LOG_ERROR(
"dtmcontrol is 0. Check JTAG connectivity/board power.");
1577 LOG_ERROR(
"Unsupported DTM version %d. (dtmcontrol=0x%x)",
1606 LOG_ERROR(
"Debug Module did not become active. dmcontrol=0x%x",
1616 LOG_DEBUG(
"dmstatus: 0x%08x", dmstatus);
1618 if (dmstatus_version != 2 && dmstatus_version != 3) {
1627 info->hartsellen = 0;
1628 while (hartsel & 1) {
1643 LOG_ERROR(
"Debugger is not authenticated to target Debug Module. "
1644 "(dmstatus=0x%x). Use `riscv authdata_read` and "
1645 "`riscv authdata_write` commands to authenticate.", dmstatus);
1657 uint32_t abstractcs;
1663 LOG_INFO(
"datacount=%d progbufsize=%d",
info->datacount,
info->progbufsize);
1669 LOG_WARNING(
"We won't be able to execute fence instructions on this "
1670 "target. Memory may not always appear consistent. "
1671 "(progbufsize=%d, impebreak=%d)",
info->progbufsize,
1676 LOG_ERROR(
"set_enable_virtual is not available on this target. It "
1677 "requires a program buffer size of at least 4. (progbufsize=%d) "
1678 "Use `riscv set_enable_virtual off` to continue."
1679 ,
info->progbufsize);
1685 r->current_hartid = i;
1720 LOG_ERROR(
"Fatal: Hart %d failed to halt during examine()", r->current_hartid);
1727 r->debug_buffer_size =
info->progbufsize;
1736 LOG_ERROR(
"Fatal: Failed to read MISA from hart %d.", r->current_hartid);
1751 LOG_DEBUG(
" hart %d: XLEN=%d, misa=0x%" PRIx64, r->current_hartid, r->xlen,
1760 bool haltgroup_supported;
1763 if (haltgroup_supported)
1767 LOG_INFO(
"Core %d could not be made part of halt group %d.",
1774 LOG_INFO(
"Examined RISC-V core; found %d harts",
1776 LOG_INFO(
" hart %d: XLEN=%d, misa=0x%" PRIx64, r->current_hartid, r->xlen,
1784 LOG_ERROR(
"Spec 0.13 only has a single authdata register.");
1797 LOG_ERROR(
"Spec 0.13 only has a single authdata register.");
1801 uint32_t before, after;
1812 LOG_INFO(
"authdata_write resulted in successful authentication");
1842 int method = r->mem_access_methods[i];
1867 LOG_ERROR(
"Unable to determine supported data bits on this target. Assuming 32 bits.");
1888 riscv_print_info_line(
CMD,
"dm",
"abits",
info->abits);
1889 riscv_print_info_line(
CMD,
"dm",
"progbufsize",
info->progbufsize);
1906 uint64_t *vl,
unsigned int *debug_vl)
1911 unsigned int encoded_vsew;
1951 uint8_t *value,
int regno)
1967 unsigned int debug_vl;
1980 for (
unsigned int i = 0; i < debug_vl; i++) {
2010 int regno,
const uint8_t *value)
2026 unsigned int debug_vl;
2037 for (
unsigned int i = 0; i < debug_vl; i++) {
2059 switch (size_bytes) {
2076 bool ensure_success)
2088 false, ensure_success);
2095 if (r->reset_delays_wait >= 0) {
2097 if (r->reset_delays_wait <= 0) {
2099 info->dmi_busy_delay = 0;
2100 info->ac_busy_delay = 0;
2109 switch (size_bytes) {
2133 LOG_ERROR(
"Memory sampling is only implemented for sbasize <= 64.");
2138 LOG_ERROR(
"Memory sampling is only implemented for SBA version 1.");
2143 uint32_t sbcs_valid =
false;
2145 uint32_t sbaddress0 = 0;
2146 bool sbaddress0_valid =
false;
2147 uint32_t sbaddress1 = 0;
2148 bool sbaddress1_valid =
false;
2151 const unsigned int repeat = 5;
2153 unsigned int enabled_count = 0;
2155 if (
config->bucket[i].enabled)
2166 target, 1 + enabled_count * 5 * repeat,
2167 info->dmi_busy_delay +
info->bus_master_read_delay);
2171 unsigned int result_bytes = 0;
2172 for (
unsigned int n = 0; n < repeat; n++) {
2174 if (
config->bucket[i].enabled) {
2176 LOG_ERROR(
"Hardware does not support SBA access for %d-byte memory sampling.",
2177 config->bucket[i].size_bytes);
2182 if (enabled_count == 1)
2185 if (!sbcs_valid || sbcs_write != sbcs) {
2192 (!sbaddress1_valid ||
2193 sbaddress1 !=
config->bucket[i].address >> 32)) {
2194 sbaddress1 =
config->bucket[i].address >> 32;
2196 sbaddress1_valid =
true;
2198 if (!sbaddress0_valid ||
2199 sbaddress0 != (
config->bucket[i].address & 0xffffffff)) {
2200 sbaddress0 =
config->bucket[i].address;
2202 sbaddress0_valid =
true;
2204 if (
config->bucket[i].size_bytes > 4)
2207 result_bytes += 1 +
config->bucket[i].size_bytes;
2212 if (buf->
used + result_bytes >= buf->
size) {
2227 info->bus_master_read_delay +=
info->bus_master_read_delay / 10 + 1;
2239 unsigned int read = 0;
2240 for (
unsigned int n = 0; n < repeat; n++) {
2242 if (
config->bucket[i].enabled) {
2245 if (
config->bucket[i].size_bytes > 4)
2251 buf->
used += 1 +
config->bucket[i].size_bytes;
2302 generic_info->dmi_read = &
dmi_read;
2307 generic_info->print_info = &riscv013_print_info;
2308 if (!generic_info->version_specific) {
2310 if (!generic_info->version_specific)
2316 info->progbufsize = -1;
2318 info->dmi_busy_delay = 0;
2319 info->bus_master_read_delay = 0;
2320 info->bus_master_write_delay = 0;
2321 info->ac_busy_delay = 0;
2328 info->abstract_read_csr_supported =
true;
2329 info->abstract_write_csr_supported =
true;
2330 info->abstract_read_fpr_supported =
true;
2331 info->abstract_write_fpr_supported =
true;
2367 uint32_t control =
set_hartsel(control_base, r->current_hartid);
2395 uint32_t control = 0, control_haltreq;
2402 int dmi_busy_delay =
info->dmi_busy_delay;
2413 index = r->current_hartid;
2416 LOG_DEBUG(
"Waiting for hart %d to come out of reset.", index);
2421 LOG_ERROR(
"Hart %d didn't complete a DMI read coming out of "
2422 "reset in %ds; Increase the timeout with riscv "
2423 "set_reset_timeout_sec.",
2437 LOG_ERROR(
"Hart %d didn't leave reset in %ds; "
2439 "Increase the timeout with riscv set_reset_timeout_sec.",
2456 info->dmi_busy_delay = dmi_busy_delay;
2471 LOG_DEBUG(
"Unable to execute pre-fence");
2478 unsigned int size_bytes,
bool read)
2485 address, read ?
"read" :
"write", size_bytes * 2);
2486 switch (size_bytes) {
2494 value &= 0xffffffffUL;
2513 for (
int i = (
size - 1) / 4; i >= 0; i--) {
2548 LOG_ERROR(
"Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
2549 "Increase the timeout with riscv set_command_timeout_sec.",
2567 *mstatus_old = *mstatus;
2578 if (*mstatus != *mstatus_old)
2590 if (
size != increment) {
2591 LOG_ERROR(
"sba v0 reads only support size==increment");
2595 LOG_DEBUG(
"System Bus Access: size: %d\tcount:%d\tstart address: 0x%08"
2597 uint8_t *t_buffer =
buffer;
2600 uint32_t access = 0;
2602 const int DM_SBCS_SBSINGLEREAD_OFFSET = 20;
2603 const uint32_t DM_SBCS_SBSINGLEREAD = (0x1U << DM_SBCS_SBSINGLEREAD_OFFSET);
2605 const int DM_SBCS_SBAUTOREAD_OFFSET = 15;
2606 const uint32_t DM_SBCS_SBAUTOREAD = (0x1U << DM_SBCS_SBAUTOREAD_OFFSET);
2610 for (uint32_t i = 0; i <
count; i++) {
2616 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
2617 LOG_DEBUG(
"\r\nread_memory: sab: access: 0x%08x", access);
2623 LOG_DEBUG(
"\r\nread_memory: sab: value: 0x%08x", value);
2632 LOG_DEBUG(
"reading block until final address 0x%" PRIx64, fin_addr);
2640 access =
set_field(access, DM_SBCS_SBAUTOREAD, 1);
2641 access =
set_field(access, DM_SBCS_SBSINGLEREAD, 1);
2643 LOG_DEBUG(
"\r\naccess: 0x%08x", access);
2646 while (cur_addr < fin_addr) {
2647 LOG_DEBUG(
"\r\nsab:autoincrement: \r\n size: %d\tcount:%d\taddress: 0x%08"
2658 if (cur_addr == fin_addr &&
count != 1) {
2679 if (increment !=
size && increment != 0) {
2680 LOG_ERROR(
"sba v1 reads only support increment of size or 0");
2688 while (next_address < end_address) {
2691 if (increment ==
size)
2702 if (
info->bus_master_read_delay) {
2705 LOG_ERROR(
"Failed to scan idle sequence");
2716 for (uint32_t i = (next_address - address) /
size; i <
count - 1; i++) {
2717 for (
int j = (
size - 1) / 4; j >= 0; j--) {
2719 unsigned int attempt = 0;
2721 if (attempt++ > 100) {
2736 if (next_read != address - 1) {
2740 next_read = address + i *
size + j * 4;
2744 uint32_t sbcs_read = 0;
2747 unsigned int attempt = 0;
2749 if (attempt++ > 100) {
2791 info->bus_master_read_delay +=
info->bus_master_read_delay / 10 + 1;
2797 next_address = end_address;
2817 snprintf(msg, 60,
"%s to %s memory via %s.",
2818 success ?
"Succeeded" :
"Failed",
2819 read ?
"read" :
"write",
2826 warn = r->mem_access_progbuf_warn;
2827 r->mem_access_progbuf_warn =
false;
2830 warn = r->mem_access_sysbus_warn;
2831 r->mem_access_sysbus_warn =
false;
2834 warn = r->mem_access_abstract_warn;
2835 r->mem_access_abstract_warn =
false;
2846 uint32_t
size,
bool read,
char **skip_reason)
2848 assert(skip_reason);
2851 LOG_DEBUG(
"Skipping mem %s via progbuf - insufficient progbuf size.",
2852 read ?
"read" :
"write");
2853 *skip_reason =
"skipped (insufficient progbuf)";
2857 LOG_DEBUG(
"Skipping mem %s via progbuf - target not halted.",
2858 read ?
"read" :
"write");
2859 *skip_reason =
"skipped (target not halted)";
2863 LOG_DEBUG(
"Skipping mem %s via progbuf - XLEN (%d) is too short for %d-bit memory access.",
2865 *skip_reason =
"skipped (XLEN too short)";
2869 LOG_DEBUG(
"Skipping mem %s via progbuf - unsupported size.",
2870 read ?
"read" :
"write");
2871 *skip_reason =
"skipped (unsupported size)";
2875 LOG_DEBUG(
"Skipping mem %s via progbuf - progbuf only supports %u-bit address.",
2877 *skip_reason =
"skipped (too large address)";
2885 uint32_t
size, uint32_t increment,
bool read,
char **skip_reason)
2887 assert(skip_reason);
2891 LOG_DEBUG(
"Skipping mem %s via system bus - unsupported size.",
2892 read ?
"read" :
"write");
2893 *skip_reason =
"skipped (unsupported size)";
2897 if ((
sizeof(address) * 8 > sbasize) && (address >> sbasize)) {
2898 LOG_DEBUG(
"Skipping mem %s via system bus - sba only supports %u-bit address.",
2899 read ?
"read" :
"write", sbasize);
2900 *skip_reason =
"skipped (too large address)";
2904 LOG_DEBUG(
"Skipping mem read via system bus - "
2905 "sba reads only support size==increment or also size==0 for sba v1.");
2906 *skip_reason =
"skipped (unsupported increment)";
2914 uint32_t
size, uint32_t increment,
bool read,
char **skip_reason)
2916 assert(skip_reason);
2921 LOG_DEBUG(
"Skipping mem %s via abstract access - unsupported size: %d bits",
2922 read ?
"read" :
"write",
size * 8);
2923 *skip_reason =
"skipped (unsupported size)";
2927 LOG_DEBUG(
"Skipping mem %s via abstract access - abstract access only supports %u-bit address.",
2929 *skip_reason =
"skipped (too large address)";
2932 if (read &&
size != increment) {
2933 LOG_ERROR(
"Skipping mem read via abstract access - "
2934 "abstract command reads only support size==increment.");
2935 *skip_reason =
"skipped (unsupported increment)";
2953 bool use_aampostincrement =
info->has_aampostincrement !=
YNM_NO;
2968 bool updateaddr =
true;
2969 unsigned int width32 = (
width < 32) ? 32 :
width;
2970 for (uint32_t c = 0; c <
count; c++) {
2976 LOG_ERROR(
"Failed to write arg1 during read_memory_abstract().");
2988 if (new_address == address +
size) {
2989 LOG_DEBUG(
"aampostincrement is supported on this target.");
2992 LOG_WARNING(
"Buggy aampostincrement! Address not incremented correctly.");
3000 LOG_DEBUG(
"aampostincrement is not supported on this target.");
3031 bool use_aampostincrement =
info->has_aampostincrement !=
YNM_NO;
3043 const uint8_t *p =
buffer;
3044 bool updateaddr =
true;
3045 for (uint32_t c = 0; c <
count; c++) {
3050 LOG_ERROR(
"Failed to write arg0 during write_memory_abstract().");
3059 LOG_ERROR(
"Failed to write arg1 during write_memory_abstract().");
3071 if (new_address == address +
size) {
3072 LOG_DEBUG(
"aampostincrement is supported on this target.");
3075 LOG_WARNING(
"Buggy aampostincrement! Address not incremented correctly.");
3083 LOG_DEBUG(
"aampostincrement is not supported on this target.");
3116 if (increment == 0 &&
3147 unsigned int index = 2;
3148 while (index <
count) {
3150 LOG_DEBUG(
"i=%d, count=%d, read_addr=0x%" PRIx64, index,
count, read_addr);
3160 info->dmi_busy_delay +
info->ac_busy_delay);
3164 unsigned int reads = 0;
3165 for (
unsigned int j = index; j <
count; j++) {
3180 uint32_t abstractcs;
3188 unsigned int next_index;
3189 unsigned int ignore_last = 0;
3190 switch (
info->cmderr) {
3192 LOG_DEBUG(
"successful (partial?) memory read");
3193 next_index = index + reads;
3196 LOG_DEBUG(
"memory read resulted in busy response");
3203 uint32_t dmi_data0, dmi_data1 = 0;
3217 if (increment == 0) {
3220 next_index = counter;
3222 uint64_t next_read_addr;
3225 next_index = (next_read_addr - address) / increment;
3232 uint64_t value64 = (((uint64_t)dmi_data1) << 32) | dmi_data0;
3249 LOG_DEBUG(
"error when reading memory, abstractcs=0x%08lx", (
long)abstractcs);
3258 unsigned int read = 0;
3260 for (
unsigned int j = index - 2; j < index + reads; j++) {
3262 LOG_DEBUG(
"index=%d, reads=%d, next_index=%d, ignore_last=%d, j=%d",
3263 index, reads, next_index, ignore_last, j);
3264 if (j + 3 + ignore_last > next_index)
3279 LOG_WARNING(
"Batch memory read encountered DMI error %d. "
3280 "Falling back on slower reads.",
status);
3288 LOG_WARNING(
"Batch memory read encountered DMI error %d. "
3289 "Falling back on slower reads.",
status);
3312 uint32_t dmi_data0, dmi_data1 = 0;
3317 uint64_t value64 = (((uint64_t)dmi_data1) << 32) | dmi_data0;
3343 uint64_t mstatus = 0;
3344 uint64_t mstatus_old = 0;
3352 goto restore_mstatus;
3374 goto restore_mstatus;
3380 goto restore_mstatus;
3382 goto restore_mstatus;
3386 goto restore_mstatus;
3405 if (mstatus != mstatus_old)
3419 LOG_ERROR(
"XLEN (%d) is too short for %d-bit memory read.",
3439 uint64_t mstatus = 0;
3440 uint64_t mstatus_old = 0;
3499 uint32_t count_i = 1;
3500 uint8_t *buffer_i =
buffer;
3502 for (uint32_t i = 0; i <
count; i++, address_i += increment, buffer_i +=
size) {
3524 if (mstatus != mstatus_old)
3538 LOG_ERROR(
"BUG: Unsupported size for memory read: %d",
size);
3546 char *progbuf_result =
"disabled";
3547 char *sysbus_result =
"disabled";
3548 char *abstract_result =
"disabled";
3551 int method = r->mem_access_methods[i];
3560 progbuf_result =
"failed";
3571 sysbus_result =
"failed";
3579 abstract_result =
"failed";
3591 LOG_ERROR(
" progbuf=%s, sysbus=%s, abstract=%s", progbuf_result, sysbus_result, abstract_result);
3599 LOG_DEBUG(
"System Bus Access: size: %d\tcount:%d\tstart address: 0x%08"
3615 LOG_DEBUG(
"\r\naccess: 0x%08" PRIx64, access);
3616 LOG_DEBUG(
"\r\nwrite_memory:SAB: ONE OFF: value 0x%08" PRIx64, value);
3626 LOG_DEBUG(
"\r\naccess: 0x%08" PRIx64, access);
3633 t_addr = address +
offset;
3637 LOG_DEBUG(
"SAB:autoincrement: expected address: 0x%08x value: 0x%08x"
3638 PRIx64, (uint32_t)t_addr, (uint32_t)value);
3662 while (next_address < end_address) {
3669 info->dmi_busy_delay +
info->bus_master_write_delay);
3673 for (uint32_t i = (next_address - address) /
size; i <
count; i++) {
3681 ((uint32_t) p[12]) |
3682 (((uint32_t) p[13]) << 8) |
3683 (((uint32_t) p[14]) << 16) |
3684 (((uint32_t) p[15]) << 24));
3689 (((uint32_t) p[9]) << 8) |
3690 (((uint32_t) p[10]) << 16) |
3691 (((uint32_t) p[11]) << 24));
3695 (((uint32_t) p[5]) << 8) |
3696 (((uint32_t) p[6]) << 16) |
3697 (((uint32_t) p[7]) << 24));
3698 uint32_t value = p[0];
3700 value |= ((uint32_t) p[2]) << 16;
3701 value |= ((uint32_t) p[3]) << 24;
3704 value |= ((uint32_t) p[1]) << 8;
3708 next_address +=
size;
3719 bool dmi_busy_encountered;
3723 if (dmi_busy_encountered)
3724 LOG_DEBUG(
"DMI busy encountered during system bus write.");
3730 LOG_ERROR(
"Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
3731 "Increase the timeout with riscv set_command_timeout_sec.",
3741 LOG_DEBUG(
"Sbbusyerror encountered during system bus write.");
3745 info->bus_master_write_delay +=
info->bus_master_write_delay / 10 + 1;
3752 if (next_address < address) {
3755 " - buggy sbautoincrement in hw?", next_address);
3771 sberror, sbaddress);
3772 if (sbaddress < address) {
3776 " - buggy sbautoincrement in hw?", next_address);
3794 LOG_ERROR(
"XLEN (%d) is too short for %d-bit memory write.",
3803 uint64_t mstatus = 0;
3804 uint64_t mstatus_old = 0;
3839 LOG_ERROR(
"write_memory_progbuf(): Unsupported size: %d",
size);
3855 bool setup_needed =
true;
3856 LOG_DEBUG(
"writing until final address 0x%016" PRIx64, fin_addr);
3857 while (cur_addr < fin_addr) {
3858 LOG_DEBUG(
"transferring burst starting at address 0x%016" PRIx64,
3864 info->dmi_busy_delay +
info->ac_busy_delay);
3869 unsigned int start = (cur_addr - address) /
size;
3870 for (
unsigned int i =
start; i <
count; ++i) {
3909 setup_needed =
false;
3928 uint32_t abstractcs;
3929 bool dmi_busy_encountered;
3930 result =
dmi_op(
target, &abstractcs, &dmi_busy_encountered,
3939 LOG_DEBUG(
"successful (partial?) memory write");
3942 LOG_DEBUG(
"Memory write resulted in abstract command busy response.");
3943 else if (dmi_busy_encountered)
3944 LOG_DEBUG(
"Memory write resulted in DMI busy response.");
3952 setup_needed =
true;
3954 LOG_ERROR(
"error when writing memory, abstractcs=0x%08lx", (
long)abstractcs);
3970 if (mstatus != mstatus_old)
3984 LOG_ERROR(
"BUG: Unsupported size for memory write: %d",
size);
3992 char *progbuf_result =
"disabled";
3993 char *sysbus_result =
"disabled";
3994 char *abstract_result =
"disabled";
3997 int method = r->mem_access_methods[i];
4006 progbuf_result =
"failed";
4017 sysbus_result =
"failed";
4025 abstract_result =
"failed";
4037 LOG_ERROR(
" progbuf=%s, sysbus=%s, abstract=%s", progbuf_result, sysbus_result, abstract_result);
4098 LOG_DEBUG(
"[%d] writing 0x%" PRIx64
" to register %s",
4106 uint64_t actual_value;
4109 if (value != actual_value) {
4110 LOG_ERROR(
"Written PC (0x%" PRIx64
") does not match read back "
4111 "value (0x%" PRIx64
")", value, actual_value);
4141 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4162 unsigned int hawindow_count = (dm->
hart_count + 31) / 32;
4163 uint32_t hawindow[hawindow_count];
4165 memset(hawindow, 0,
sizeof(uint32_t) * hawindow_count);
4168 unsigned int total_selected = 0;
4173 unsigned int index =
info->index;
4177 hawindow[index / 32] |= 1 << (index % 32);
4185 if (total_selected <= 1) {
4190 for (
unsigned int i = 0; i < hawindow_count; i++) {
4208 bool use_hasel =
false;
4213 LOG_DEBUG(
"halting hart %d", r->current_hartid);
4219 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4221 for (
size_t i = 0; i < 256; ++i)
4232 LOG_ERROR(
"unable to halt hart %d", r->current_hartid);
4233 LOG_ERROR(
" dmcontrol=0x%08x", dmcontrol);
4234 LOG_ERROR(
" dmstatus =0x%08x", dmstatus);
4260 bool use_hasel =
false;
4298 LOG_INFO(
"Hart %d unexpectedly reset!", hartid);
4344 LOG_ERROR(
" dcsr=0x%016lx", (
long)dcsr);
4358 LOG_DEBUG(
"cache hit for 0x%" PRIx32
" @%d", data, index);
4372 uint32_t run_program = 0;
4437 bool step,
bool use_hasel)
4440 LOG_DEBUG(
"resuming hart %d (for step?=%d)", r->current_hartid,
step);
4442 LOG_ERROR(
"Hart %d is not halted!", r->current_hartid);
4450 dmcontrol =
set_hartsel(dmcontrol, r->current_hartid);
4457 for (
size_t i = 0; i < 256; ++i) {
4472 LOG_ERROR(
"unable to resume hart %d", r->current_hartid);
4475 LOG_ERROR(
" dmstatus =0x%08x", dmstatus);
4490 uint32_t abstractcs;
4496 LOG_ERROR(
"abstractcs.busy is not going low after %d seconds "
4497 "(abstractcs=0x%x). The target is either really slow or "
4498 "broken. You could increase the timeout with riscv "
4499 "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 int address)
uint32_t riscv_batch_get_dmi_read_op(struct riscv_batch *batch, size_t key)
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 int address, uint64_t data)
void riscv_batch_free(struct riscv_batch *batch)
bool riscv_batch_full(struct riscv_batch *batch)
void buffer_shr(void *_buf, unsigned int buf_len, unsigned int count)
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
static void buf_set_u64(uint8_t *_buffer, unsigned int first, unsigned int num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
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
void jtag_add_runtest(unsigned 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,...
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_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 int 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 fmv_d_x(unsigned int dest, unsigned int src) __attribute__((unused))
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 fmv_x_w(unsigned int dest, unsigned int src) __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_w_x(unsigned int dest, unsigned int src) __attribute__((unused))
static uint32_t auipc(unsigned int dest) __attribute__((unused))
static uint32_t fmv_x_d(unsigned int dest, unsigned int src) __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 register_write_abstract(struct target *target, uint32_t number, uint64_t value, unsigned int size)
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 register_read_abstract(struct target *target, uint64_t *value, uint32_t number, unsigned int size)
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 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 dm013_info_t * get_dm(struct target *target)
Return the DM structure for this target.
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
static int dmstatus_read_timeout(struct target *target, uint32_t *dmstatus, bool authenticated, unsigned int timeout_sec)
static bool has_sufficient_progbuf(struct target *target, unsigned int size)
#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 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 int scratch_reserve(struct target *target, scratch_mem_t *scratch, struct riscv_program *program, unsigned int size_bytes)
Find some scratch memory to be used with the given program.
static 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 void log_memory_access(target_addr_t address, uint64_t value, unsigned int size_bytes, bool read)
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 prep_for_register_access(struct target *target, uint64_t *mstatus, int regno)
static riscv_reg_t read_abstract_arg(struct target *target, unsigned int index, unsigned int size_bits)
static int modify_privilege(struct target *target, uint64_t *mstatus, uint64_t *mstatus_old)
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 int riscv013_hart_count(struct target *target)
static uint32_t dtmcontrol_scan(struct target *target, uint32_t out)
static void decode_dmi(char *text, unsigned int address, unsigned int data)
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 riscv013_write_debug_buffer(struct target *target, unsigned int index, riscv_insn_t d)
static int dmstatus_read(struct target *target, uint32_t *dmstatus, bool authenticated)
static int write_abstract_arg(struct target *target, unsigned int index, riscv_reg_t value, unsigned int size_bits)
static int dmi_read(struct target *target, uint32_t *value, uint32_t address)
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 unsigned int riscv013_data_bits(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 uint32_t access_memory_command(struct target *target, bool virtual, unsigned int width, bool postincrement, bool write)
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 riscv013_authdata_read(struct target *target, uint32_t *value, unsigned int index)
static uint32_t abstract_memory_size(unsigned int width)
static int is_vector_reg(uint32_t gdb_regno)
static int riscv013_halt_prep(struct target *target)
#define CSR_DCSR_CAUSE_DEBUGINT
static int set_haltgroup(struct target *target, bool *supported)
static target_addr_t sb_read_address(struct target *target)
static int prep_for_vector_access(struct target *target, uint64_t *vtype, uint64_t *vl, unsigned int *debug_vl)
static unsigned int register_size(struct target *target, unsigned int number)
Return register size in bits.
static int register_write_direct(struct target *target, unsigned int number, uint64_t value)
Immediately write the new value to the requested register.
static riscv_insn_t riscv013_read_debug_buffer(struct target *target, unsigned int index)
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 COMMAND_HELPER(riscv013_print_info, struct target *target)
static uint32_t access_register_command(struct target *target, uint32_t number, unsigned int size, uint32_t flags)
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 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)
#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
unsigned int riscv_xlen(const struct target *target)
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)
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]
unsigned int abs_chain_position
unsigned int abs_chain_position
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
unsigned int custom_number
This structure defines a single scan field in the scan.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
unsigned int num_bits
The number of bits this field specifies.
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