26 #define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
27 #define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
30 #define CSR_BPCONTROL_X (1<<0)
31 #define CSR_BPCONTROL_W (1<<1)
32 #define CSR_BPCONTROL_R (1<<2)
33 #define CSR_BPCONTROL_U (1<<3)
34 #define CSR_BPCONTROL_S (1<<4)
35 #define CSR_BPCONTROL_H (1<<5)
36 #define CSR_BPCONTROL_M (1<<6)
37 #define CSR_BPCONTROL_BPMATCH (0xf<<7)
38 #define CSR_BPCONTROL_BPACTION (0xff<<11)
40 #define DEBUG_ROM_START 0x800
41 #define DEBUG_ROM_RESUME (DEBUG_ROM_START + 4)
42 #define DEBUG_ROM_EXCEPTION (DEBUG_ROM_START + 8)
43 #define DEBUG_RAM_START 0x400
45 #define SETHALTNOT 0x10c
49 #define DTMCONTROL 0x10
50 #define DTMCONTROL_DBUS_RESET (1<<16)
51 #define DTMCONTROL_IDLE (7<<10)
52 #define DTMCONTROL_ADDRBITS (0xf<<4)
53 #define DTMCONTROL_VERSION (0xf)
56 #define DBUS_OP_START 0
57 #define DBUS_OP_SIZE 2
68 #define DBUS_DATA_START 2
69 #define DBUS_DATA_SIZE 34
70 #define DBUS_ADDRESS_START 36
80 #define DMCONTROL 0x10
81 #define DMCONTROL_INTERRUPT (((uint64_t)1)<<33)
82 #define DMCONTROL_HALTNOT (((uint64_t)1)<<32)
83 #define DMCONTROL_BUSERROR (7<<19)
84 #define DMCONTROL_SERIAL (3<<16)
85 #define DMCONTROL_AUTOINCREMENT (1<<15)
86 #define DMCONTROL_ACCESS (7<<12)
87 #define DMCONTROL_HARTID (0x3ff<<2)
88 #define DMCONTROL_NDRESET (1<<1)
89 #define DMCONTROL_FULLRESET 1
92 #define DMINFO_ABUSSIZE (0x7fU<<25)
93 #define DMINFO_SERIALCOUNT (0xf<<21)
94 #define DMINFO_ACCESS128 (1<<20)
95 #define DMINFO_ACCESS64 (1<<19)
96 #define DMINFO_ACCESS32 (1<<18)
97 #define DMINFO_ACCESS16 (1<<17)
98 #define DMINFO_ACCESS8 (1<<16)
99 #define DMINFO_DRAMSIZE (0x3f<<10)
100 #define DMINFO_AUTHENTICATED (1<<5)
101 #define DMINFO_AUTHBUSY (1<<4)
102 #define DMINFO_AUTHTYPE (3<<2)
103 #define DMINFO_VERSION 3
107 #define DBUS_ADDRESS_UNKNOWN 0xffff
110 #define DRAM_CACHE_SIZE 16
225 .vpn_shift = {12, 22},
226 .vpn_mask = {0x3ff, 0x3ff},
227 .pte_ppn_shift = {10, 20},
228 .pte_ppn_mask = {0x3ff, 0xfff},
229 .pa_ppn_shift = {12, 22},
230 .pa_ppn_mask = {0x3ff, 0xfff},
238 .vpn_shift = {12, 21, 30},
239 .vpn_mask = {0x1ff, 0x1ff, 0x1ff},
240 .pte_ppn_shift = {10, 19, 28},
241 .pte_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
242 .pa_ppn_shift = {12, 21, 30},
243 .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
251 .vpn_shift = {12, 21, 30, 39},
252 .vpn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ff},
253 .pte_ppn_shift = {10, 19, 28, 37},
254 .pte_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
255 .pa_ppn_shift = {12, 21, 30, 39},
256 .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
268 if (r->sample_buf.used + 5 < r->sample_buf.size) {
273 r->sample_buf.buf[r->sample_buf.used++] = now & 0xff;
274 r->sample_buf.buf[r->sample_buf.used++] = (now >> 8) & 0xff;
275 r->sample_buf.buf[r->sample_buf.used++] = (now >> 16) & 0xff;
276 r->sample_buf.buf[r->sample_buf.used++] = (now >> 24) & 0xff;
297 uint8_t tunneled_dr_width[4] = {32};
298 uint8_t out_value[5] = {0};
299 uint8_t in_value[5] = {0};
313 tunneled_ir[2].
out_value = tunneled_ir_width;
326 tunneled_dr[2].
out_value = tunneled_dr_width;
340 tunneled_ir[1].
out_value = tunneled_ir_width;
353 tunneled_dr[1].
out_value = tunneled_dr_width;
366 LOG_ERROR(
"failed jtag scan: %d", retval);
372 LOG_DEBUG(
"DTMCS: 0x%x -> 0x%x", out, in);
401 LOG_ERROR(
"failed jtag scan: %d", retval);
406 LOG_DEBUG(
"DTMCONTROL: 0x%x -> 0x%x", out, in);
414 LOG_ERROR(
"Target has not been initialized");
419 switch (
info->dtm_version) {
435 LOG_ERROR(
"Failed to allocate RISC-V target structure.");
447 info->cmd_ctx = cmd_ctx;
496 if (tt &&
info &&
info->version_specific)
515 free(
info->reg_names);
539 const uint32_t bpcontrol_x = 1<<0;
540 const uint32_t bpcontrol_w = 1<<1;
541 const uint32_t bpcontrol_r = 1<<2;
542 const uint32_t bpcontrol_u = 1<<3;
543 const uint32_t bpcontrol_s = 1<<4;
544 const uint32_t bpcontrol_h = 1<<5;
545 const uint32_t bpcontrol_m = 1<<6;
546 const uint32_t bpcontrol_bpmatch = 0xf << 7;
547 const uint32_t bpcontrol_bpaction = 0xff << 11;
549 if (tdata1 & (bpcontrol_r | bpcontrol_w | bpcontrol_x)) {
558 !!(r->misa &
BIT(
'U' -
'A')));
560 !!(r->misa &
BIT(
'S' -
'A')));
562 !!(r->misa &
BIT(
'H' -
'A')));
563 tdata1 |= bpcontrol_m;
564 tdata1 =
set_field(tdata1, bpcontrol_bpmatch, 0);
565 tdata1 =
set_field(tdata1, bpcontrol_bpaction, 0);
572 LOG_DEBUG(
"tdata1=0x%" PRIx64, tdata1_rb);
574 if (tdata1 != tdata1_rb) {
575 LOG_DEBUG(
"Trigger doesn't support what we need; After writing 0x%"
576 PRIx64
" to tdata1 it contains 0x%" PRIx64,
604 if (r->misa & (1 << (
'S' -
'A')))
606 if (r->misa & (1 << (
'U' -
'A')))
622 LOG_DEBUG(
"tdata1=0x%" PRIx64, tdata1_rb);
624 if (tdata1 != tdata1_rb) {
625 LOG_DEBUG(
"Trigger doesn't support what we need; After writing 0x%"
626 PRIx64
" to tdata1 it contains 0x%" PRIx64,
654 if (r->misa & (1 << (
'H' -
'A')))
656 if (r->misa & (1 << (
'S' -
'A')))
658 if (r->misa & (1 << (
'U' -
'A')))
674 LOG_DEBUG(
"tdata1=0x%" PRIx64, tdata1_rb);
676 if (tdata1 != tdata1_rb) {
677 LOG_DEBUG(
"Trigger doesn't support what we need; After writing 0x%"
678 PRIx64
" to tdata1 it contains 0x%" PRIx64,
701 for (i = 0; i < r->trigger_count; i++) {
702 if (r->trigger_unique_id[i] != -1)
739 if (i >= r->trigger_count) {
740 LOG_ERROR(
"Couldn't find an available hardware trigger.");
752 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
755 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
757 if (access_size <=
size && address % access_size == 0)
761 unsigned int offset_head = address % access_size;
762 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
763 uint8_t helper_buf[n_blocks * access_size];
770 memcpy(helper_buf + offset_head,
buffer,
size);
779 uint32_t
size, uint8_t *
buffer, uint32_t access_size)
782 assert(access_size == 1 || access_size == 2 || access_size == 4 || access_size == 8);
784 if (access_size <=
size && address % access_size == 0)
788 unsigned int offset_head = address % access_size;
789 unsigned int n_blocks = ((
size + offset_head) <= access_size) ? 1 : 2;
790 uint8_t helper_buf[n_blocks * access_size];
797 memcpy(
buffer, helper_buf + offset_head,
size);
810 unsigned int preferred_size =
size;
811 while (address % preferred_size != 0)
820 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
821 if (access_size == preferred_size)
842 unsigned int preferred_size =
size;
843 while (address % preferred_size != 0)
852 for (
unsigned int access_size = 8; access_size > 0; access_size /= 2) {
853 if (access_size == preferred_size)
889 uint8_t buff[4] = { 0 };
893 LOG_ERROR(
"Failed to write %d-byte breakpoint instruction at 0x%"
905 LOG_INFO(
"OpenOCD only supports hardware and software breakpoints.");
921 for (i = 0; i < r->trigger_count; i++) {
925 if (i >= r->trigger_count) {
926 LOG_ERROR(
"Couldn't find the hardware resources used by hardware "
940 r->trigger_unique_id[i] = -1;
952 LOG_ERROR(
"Failed to restore instruction for %d-byte breakpoint at "
965 LOG_INFO(
"OpenOCD only supports hardware and software breakpoints.");
1035 const uint8_t
length = 4;
1041 LOG_ERROR(
"Failed to read instruction at dpc 0x%" PRIx64, dpc);
1045 uint32_t instruction = 0;
1047 for (
int i = 0; i <
length; i++) {
1049 instruction += (
buffer[i] << 8 * i);
1051 LOG_DEBUG(
"Full instruction is %x", instruction);
1055 uint8_t opcode = instruction & 0x7F;
1061 rs1 = (instruction & 0xf8000) >> 15;
1065 LOG_DEBUG(
"%x is store instruction", instruction);
1066 imm = ((instruction & 0xf80) >> 7) | ((instruction & 0xfe000000) >> 20);
1068 LOG_DEBUG(
"%x is load instruction", instruction);
1069 imm = (instruction & 0xfff00000) >> 20;
1072 if (imm & (1 << 11))
1075 LOG_DEBUG(
"memory address=0x%" PRIx64, mem_addr);
1077 LOG_DEBUG(
"%x is not a RV32I load or store", instruction);
1083 if (wp->
address == mem_addr) {
1084 *hit_watchpoint = wp;
1101 int handle_breakpoints)
1104 return tt->
step(
target, current, address, handle_breakpoints);
1111 LOG_DEBUG(
"handle_breakpoints=%d", handle_breakpoints);
1123 LOG_DEBUG(
"Target was already examined.");
1131 LOG_DEBUG(
"dtmcontrol=0x%x", dtmcontrol);
1175 LOG_DEBUG(
"[%s] Hart is already halted (reason=%d).",
1208 if (!r->is_halted) {
1230 if (!r->is_halted) {
1299 LOG_DEBUG(
"[%s] hart requested resume, but was already resumed",
1319 if (r->manual_hwbp_set) {
1324 for (
unsigned int t = 0; t < r->trigger_count; t++) {
1362 if (r->manual_hwbp_set) {
1367 for (
unsigned int t = 0; t < r->trigger_count; t++) {
1368 if (
state[t] != 0) {
1442 if (!r->is_halted) {
1444 result = tt->
resume(
target, current, address, handle_breakpoints,
1470 int handle_breakpoints,
1471 int debug_execution,
1474 LOG_DEBUG(
"handle_breakpoints=%d", handle_breakpoints);
1481 if (
resume_prep(t, current, address, handle_breakpoints,
1491 if (
resume_go(t, current, address, handle_breakpoints,
1519 int handle_breakpoints,
int debug_execution)
1522 debug_execution,
false);
1535 LOG_ERROR(
"Failed to read priv register.");
1541 LOG_ERROR(
"Failed to read mstatus register.");
1546 LOG_DEBUG(
"SATP/MMU ignored in Machine mode (mstatus=0x%" PRIx64
").", mstatus);
1599 LOG_ERROR(
"No translation or protection." \
1600 " (satp: 0x%" PRIx64
")", satp_value);
1603 LOG_ERROR(
"The translation mode is not supported." \
1604 " (satp: 0x%" PRIx64
")", satp_value);
1610 assert(xlen >=
info->va_bits);
1613 if (masked_msbs != 0 && masked_msbs !=
mask) {
1615 "for %s mode.",
virtual,
info->name);
1621 i =
info->level - 1;
1623 uint64_t vpn =
virtual >>
info->vpn_shift[i];
1624 vpn &=
info->vpn_mask[i];
1626 (vpn <<
info->pte_shift);
1628 assert(
info->pte_shift <= 3);
1629 int retval = r->read_memory(
target, pte_address,
1634 if (
info->pte_shift == 2)
1663 while (i < info->level) {
1664 ppn_value = pte >>
info->pte_ppn_shift[i];
1665 ppn_value &=
info->pte_ppn_mask[i];
1667 info->pa_ppn_shift[i]);
1668 *physical |= (ppn_value <<
info->pa_ppn_shift[i]);
1713 address = physical_addr;
1741 address = physical_addr;
1751 return "riscv:rv32";
1753 return "riscv:rv64";
1760 struct reg **reg_list[],
int *reg_list_size,
1764 LOG_DEBUG(
"[%s] {%d} reg_class=%d, read=%d",
1768 LOG_ERROR(
"Target not initialized. Return ERROR_FAIL.");
1775 switch (reg_class) {
1777 *reg_list_size = 33;
1783 LOG_ERROR(
"Unsupported reg_class: %d", reg_class);
1787 *reg_list = calloc(*reg_list_size,
sizeof(
struct reg *));
1791 for (
int i = 0; i < *reg_list_size; i++) {
1808 struct reg **reg_list[],
int *reg_list_size,
1816 struct reg **reg_list[],
int *reg_list_size,
1831 struct mem_param *mem_params,
int num_reg_params,
1833 target_addr_t exit_point,
unsigned int timeout_ms,
void *arch_info)
1837 if (num_mem_params > 0) {
1838 LOG_ERROR(
"Memory parameters are not supported for RISC-V algorithms.");
1852 LOG_DEBUG(
"saved_pc=0x%" PRIx64, saved_pc);
1854 uint64_t saved_regs[32];
1855 for (
int i = 0; i < num_reg_params; i++) {
1856 LOG_DEBUG(
"save %s", reg_params[i].reg_name);
1859 LOG_ERROR(
"Couldn't find register named '%s'", reg_params[i].reg_name);
1863 if (r->
size != reg_params[i].
size) {
1864 LOG_ERROR(
"Register %s is %d bits instead of %d bits.",
1865 reg_params[i].reg_name, r->
size, reg_params[i].
size);
1870 LOG_ERROR(
"Only GPRs can be use as argument registers.");
1886 uint64_t current_mstatus;
1887 uint8_t mstatus_bytes[8] = { 0 };
1897 reg_mstatus->
type->
get(reg_mstatus);
1903 reg_mstatus->
type->
set(reg_mstatus, mstatus_bytes);
1914 if (now -
start > timeout_ms) {
1915 LOG_ERROR(
"Algorithm timed out after %" PRId64
" ms.", now -
start);
1930 for (
unsigned int i = 0; i <
ARRAY_SIZE(regnums); i++) {
1952 if (exit_point && final_pc != exit_point) {
1953 LOG_ERROR(
"PC ended up at 0x%" PRIx64
" instead of 0x%"
1961 reg_mstatus->
type->
set(reg_mstatus, mstatus_bytes);
1964 uint8_t buf[8] = { 0 };
1969 for (
int i = 0; i < num_reg_params; i++) {
1979 LOG_DEBUG(
"restore %s", reg_params[i].reg_name);
2001 static const uint8_t riscv32_crc_code[] = {
2002 #include "../../../contrib/loaders/checksum/riscv32_crc.inc"
2004 static const uint8_t riscv64_crc_code[] = {
2005 #include "../../../contrib/loaders/checksum/riscv64_crc.inc"
2008 static const uint8_t *crc_code;
2011 unsigned int crc_code_size;
2013 crc_code = riscv32_crc_code;
2014 crc_code_size =
sizeof(riscv32_crc_code);
2016 crc_code = riscv64_crc_code;
2017 crc_code_size =
sizeof(riscv64_crc_code);
2020 if (
count < crc_code_size * 4) {
2031 if (crc_algorithm->
address + crc_algorithm->
size > address &&
2044 crc_algorithm->
address, retval);
2055 unsigned int timeout = 20000 * (1 + (
count / (1024 * 1024)));
2065 LOG_ERROR(
"error executing RISC-V CRC algorithm");
2072 LOG_DEBUG(
"checksum=0x%" PRIx32
", result=%d", *checksum, retval);
2112 switch (halt_reason) {
2140 if (!r->sample_buf.buf || !r->sample_config.enabled)
2143 LOG_DEBUG(
"buf used/size: %d/%d", r->sample_buf.used, r->sample_buf.size);
2148 if (r->sample_memory) {
2149 result = r->sample_memory(
target, &r->sample_buf, &r->sample_config,
2157 for (
unsigned int i = 0; i <
ARRAY_SIZE(r->sample_config.bucket); i++) {
2158 if (r->sample_config.bucket[i].enabled &&
2159 r->sample_buf.used + 1 + r->sample_config.bucket[i].size_bytes < r->sample_buf.size) {
2161 r->sample_buf.buf[r->sample_buf.used] = i;
2163 target, r->sample_config.bucket[i].address,
2164 r->sample_config.bucket[i].size_bytes, 1,
2165 r->sample_buf.buf + r->sample_buf.used + 1);
2167 r->sample_buf.used += 1 + r->sample_config.bucket[i].size_bytes;
2177 LOG_INFO(
"Turning off memory sampling because it failed.");
2178 r->sample_config.enabled =
false;
2187 int halted_hart = -1;
2190 unsigned int should_remain_halted = 0;
2191 unsigned int should_resume = 0;
2217 should_remain_halted++;
2228 should_remain_halted++;
2237 LOG_DEBUG(
"should_remain_halted=%d, should_resume=%d",
2238 should_remain_halted, should_resume);
2239 if (should_remain_halted && should_resume) {
2240 LOG_WARNING(
"%d harts should remain halted, and %d should resume.",
2241 should_remain_halted, should_resume);
2243 if (should_remain_halted) {
2246 }
else if (should_resume) {
2274 LOG_DEBUG(
" hart %d halted", halted_hart);
2338 LOG_ERROR(
"Command takes exactly 1 parameter");
2355 LOG_ERROR(
"Command takes exactly 1 parameter");
2372 int progbuf_cnt = 0;
2374 int abstract_cnt = 0;
2382 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
2383 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0) {
2385 }
else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0) {
2387 }
else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0) {
2391 "Must be one of: 'progbuf', 'sysbus' or 'abstract'.",
CMD_ARGV[i]);
2395 if (progbuf_cnt > 1 || sysbus_cnt > 1 || abstract_cnt > 1) {
2396 LOG_ERROR(
"Syntax error - duplicate arguments to `riscv set_mem_access`.");
2403 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
2404 if (strcmp(
"progbuf",
CMD_ARGV[i]) == 0)
2406 else if (strcmp(
"sysbus",
CMD_ARGV[i]) == 0)
2408 else if (strcmp(
"abstract",
CMD_ARGV[i]) == 0)
2413 r->mem_access_progbuf_warn =
true;
2414 r->mem_access_sysbus_warn =
true;
2415 r->mem_access_abstract_warn =
true;
2423 LOG_ERROR(
"Command takes exactly 1 parameter");
2432 char *args = strdup(tcl_arg);
2437 char *arg = strtok(args,
",");
2439 unsigned int low = 0;
2440 unsigned int high = 0;
2443 char *dash = strchr(arg,
'-');
2444 char *equals = strchr(arg,
'=');
2447 if (!dash && !equals) {
2449 if (sscanf(arg,
"%u%n", &
low, &pos) != 1 || pos != strlen(arg)) {
2450 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
2454 }
else if (dash && !equals) {
2458 if (sscanf(arg,
"%u%n", &
low, &pos) != 1 || pos != strlen(arg)) {
2459 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
2463 if (sscanf(dash,
"%u%n", &high, &pos) != 1 || pos != strlen(dash)) {
2464 LOG_ERROR(
"Failed to parse single register number from '%s'.", dash);
2469 LOG_ERROR(
"Incorrect range encountered [%u, %u].",
low, high);
2473 }
else if (!dash && equals) {
2477 if (sscanf(arg,
"%u%n", &
low, &pos) != 1 || pos != strlen(arg)) {
2478 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
2483 name = calloc(1, strlen(equals) + strlen(
reg_type) + 2);
2485 LOG_ERROR(
"Failed to allocate register name.");
2494 if (sscanf(equals,
"%[_a-zA-Z0-9]%n",
name + strlen(
reg_type) + 1, &pos) != 1 || pos != strlen(equals)) {
2495 LOG_ERROR(
"Failed to parse register name from '%s'.", equals);
2501 LOG_ERROR(
"Invalid argument '%s'.", arg);
2506 high = high >
low ? high :
low;
2508 if (high > max_val) {
2509 LOG_ERROR(
"Cannot expose %s register number %u, maximum allowed value is %u.",
reg_type, high, max_val);
2518 if ((entry->
low <= high) && (low <= entry->high)) {
2521 "Register %u has already been exposed previously",
reg_type,
low);
2523 LOG_WARNING(
"Overlapping register ranges - Register range starting from %u overlaps "
2524 "with already exposed register/range at %u.",
low, entry->
low);
2537 LOG_ERROR(
"Failed to allocate range list.");
2548 arg = strtok(
NULL,
",");
2558 LOG_ERROR(
"Command expects parameters");
2566 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
2578 LOG_ERROR(
"Command expects parameters");
2586 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
2597 unsigned int index = 0;
2603 LOG_ERROR(
"Command takes at most one parameter");
2619 if (r->authdata_read) {
2626 LOG_ERROR(
"authdata_read is not implemented for this target.");
2634 unsigned int index = 0;
2649 if (!r->authdata_write) {
2650 LOG_ERROR(
"authdata_write is not implemented for this target.");
2654 return r->authdata_write(
target, value, index);
2677 uint32_t address, value;
2684 LOG_ERROR(
"dmi_read is not implemented for this target.");
2693 LOG_ERROR(
"Command takes exactly 2 arguments");
2700 uint32_t address, value;
2705 return r->dmi_write(
target, address, value);
2707 LOG_ERROR(
"dmi_write is not implemented for this target.");
2717 LOG_ERROR(
"Command takes at most one argument");
2726 r->reset_delays_wait = wait;
2733 LOG_ERROR(
"Command takes exactly 2 arguments");
2740 if (!strcmp(
CMD_ARGV[0],
"idcode"))
2742 else if (!strcmp(
CMD_ARGV[0],
"dtmcs"))
2744 else if (!strcmp(
CMD_ARGV[0],
"dmi"))
2755 LOG_ERROR(
"Command takes at most one argument");
2759 if (!strcmp(
CMD_ARGV[0],
"normal")) {
2761 }
else if (!strcmp(
CMD_ARGV[0],
"reversed")) {
2777 LOG_ERROR(
"Command takes at most two arguments");
2786 LOG_INFO(
"Nested Tap based Bscan Tunnel Selected");
2788 LOG_INFO(
"Simple Register based Bscan Tunnel Selected");
2790 LOG_INFO(
"Invalid Tunnel type selected ! : selecting default Nested Tap Type");
2800 LOG_ERROR(
"Command takes exactly 1 parameter");
2810 LOG_ERROR(
"Command takes exactly 1 parameter");
2820 LOG_ERROR(
"Command takes exactly 1 parameter");
2830 LOG_ERROR(
"Command takes exactly 1 parameter");
2841 snprintf(full_key,
sizeof(full_key),
"%s.%s", section, key);
2855 riscv_print_info_line(
CMD,
"hart",
"trigger_count",
2867 .handler = handle_info,
2870 .help =
"Displays some information OpenOCD detected about the target."
2873 .name =
"set_command_timeout_sec",
2874 .handler = riscv_set_command_timeout_sec,
2877 .help =
"Set the wall-clock timeout (in seconds) for individual commands"
2880 .name =
"set_reset_timeout_sec",
2881 .handler = riscv_set_reset_timeout_sec,
2884 .help =
"Set the wall-clock timeout (in seconds) after reset is deasserted"
2887 .name =
"set_mem_access",
2888 .handler = riscv_set_mem_access,
2890 .usage =
"method1 [method2] [method3]",
2891 .help =
"Set which memory access methods shall be used and in which order "
2892 "of priority. Method can be one of: 'progbuf', 'sysbus' or 'abstract'."
2895 .name =
"set_enable_virtual",
2896 .handler = riscv_set_enable_virtual,
2899 .help =
"When on, memory accesses are performed on physical or virtual "
2900 "memory depending on the current system configuration. "
2901 "When off (default), all memory accessses are performed on physical memory."
2904 .name =
"expose_csrs",
2905 .handler = riscv_set_expose_csrs,
2907 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...",
2908 .help =
"Configure a list of inclusive ranges for CSRs to expose in "
2909 "addition to the standard ones. This must be executed before "
2913 .name =
"expose_custom",
2914 .handler = riscv_set_expose_custom,
2916 .usage =
"n0[-m0|=name0][,n1[-m1|=name1]]...",
2917 .help =
"Configure a list of inclusive ranges for custom registers to "
2918 "expose. custom0 is accessed as abstract register number 0xc000, "
2919 "etc. This must be executed before `init`."
2922 .name =
"authdata_read",
2923 .handler = riscv_authdata_read,
2926 .help =
"Return the 32-bit value read from authdata or authdata0 "
2927 "(index=0), or authdata1 (index=1)."
2930 .name =
"authdata_write",
2931 .handler = riscv_authdata_write,
2933 .usage =
"[index] value",
2934 .help =
"Write the 32-bit value to authdata or authdata0 (index=0), "
2935 "or authdata1 (index=1)."
2939 .handler = riscv_dmi_read,
2942 .help =
"Perform a 32-bit DMI read at address, returning the value."
2945 .name =
"dmi_write",
2946 .handler = riscv_dmi_write,
2948 .usage =
"address value",
2949 .help =
"Perform a 32-bit DMI write of value at address."
2952 .name =
"reset_delays",
2953 .handler = riscv_reset_delays,
2956 .help =
"OpenOCD learns how many Run-Test/Idle cycles are required "
2957 "between scans to avoid encountering the target being busy. This "
2958 "command resets those learned values after `wait` scans. It's only "
2959 "useful for testing OpenOCD itself."
2962 .name =
"resume_order",
2963 .handler = riscv_resume_order,
2965 .usage =
"normal|reversed",
2966 .help =
"Choose the order that harts are resumed in when `hasel` is not "
2967 "supported. Normal order is from lowest hart index to highest. "
2968 "Reversed order is from highest hart index to lowest."
2972 .handler = riscv_set_ir,
2974 .usage =
"[idcode|dtmcs|dmi] value",
2975 .help =
"Set IR value for specified JTAG register."
2978 .name =
"use_bscan_tunnel",
2979 .handler = riscv_use_bscan_tunnel,
2981 .usage =
"value [type]",
2982 .help =
"Enable or disable use of a BSCAN tunnel to reach DM. Supply "
2983 "the width of the DM transport TAP's instruction register to "
2984 "enable. Supply a value of 0 to disable. Pass A second argument "
2985 "(optional) to indicate Bscan Tunnel Type {0:(default) NESTED_TAP , "
2989 .name =
"set_enable_virt2phys",
2990 .handler = riscv_set_enable_virt2phys,
2993 .help =
"When on (default), enable translation from virtual address to "
2997 .name =
"set_ebreakm",
2998 .handler = riscv_set_ebreakm,
3001 .help =
"Control dcsr.ebreakm. When off, M-mode ebreak instructions "
3002 "don't trap to OpenOCD. Defaults to on."
3005 .name =
"set_ebreaks",
3006 .handler = riscv_set_ebreaks,
3009 .help =
"Control dcsr.ebreaks. When off, S-mode ebreak instructions "
3010 "don't trap to OpenOCD. Defaults to on."
3013 .name =
"set_ebreaku",
3014 .handler = riscv_set_ebreaku,
3017 .help =
"Control dcsr.ebreaku. When off, U-mode ebreak instructions "
3018 "don't trap to OpenOCD. Defaults to on."
3041 .help =
"RISC-V Command Group",
3048 .help =
"ARM Command Group",
3067 return r->data_bits(
target);
3125 memset(r, 0,
sizeof(*r));
3160 LOG_DEBUG(
"[%s] hart requested resume, but was already resumed",
3178 LOG_ERROR(
"Hart isn't halted before single step!");
3188 LOG_ERROR(
"Hart was not halted after single step!");
3198 if (letter >=
'a' && letter <=
'z')
3200 else if (letter >=
'A' && letter <=
'Z')
3204 return r->misa &
BIT(num);
3216 if (!r->select_current_hart)
3220 r->current_hartid = hartid;
3221 LOG_DEBUG(
"setting hartid to %d, was %d", hartid, previous_hartid);
3242 return r->current_hartid;
3250 if (!r || !r->hart_count)
3252 return r->hart_count(
target);
3312 assert(r->set_register);
3324 int result = r->set_register(
target, regid,
value);
3329 LOG_DEBUG(
"[%s] wrote 0x%" PRIx64
" to %s valid=%d",
3362 int result = r->get_register(
target,
value, regid);
3375 assert(r->is_halted);
3376 return r->is_halted(
target);
3388 return r->halt_reason(
target);
3394 return r->debug_buffer_size;
3400 r->write_debug_buffer(
target, index, insn);
3407 return r->read_debug_buffer(
target, index);
3413 return r->execute_debug_buffer(
target);
3419 r->fill_dmi_write_u64(
target, buf, a, d);
3425 r->fill_dmi_read_u64(
target, buf, a);
3431 r->fill_dmi_nop_u64(
target, buf);
3437 return r->dmi_write_u64_bits(
target);
3451 if (r->triggers_enumerated)
3454 r->triggers_enumerated =
true;
3462 LOG_DEBUG(
"[%s] Cannot access tselect register. "
3464 r->trigger_count = 0;
3469 r->trigger_count = t;
3474 uint64_t tselect_rb;
3481 if (tselect_rb != t)
3517 static char buf[32];
3692 sprintf(buf,
"gdb_regno_%d", regno);
3704 if (!r->get_register_buf) {
3705 LOG_ERROR(
"Reading register %s not supported on this RISC-V target.",
3748 r->manual_hwbp_set =
true;
3758 if (!r->set_register_buf) {
3759 LOG_ERROR(
"Writing register %s not supported on this RISC-V target.",
3787 return (
int) (((
struct csr_info *)p1)->number) - (
int) (((
struct csr_info *)p2)->number);
3808 LOG_DEBUG(
"create register cache for %d registers",
3816 const unsigned int max_reg_name_len = 12;
3817 free(
info->reg_names);
3820 if (!
info->reg_names)
3822 char *reg_name =
info->reg_names;
3825 .
name =
"org.gnu.gdb.riscv.cpu"
3828 .
name =
"org.gnu.gdb.riscv.fpu"
3831 .
name =
"org.gnu.gdb.riscv.csr"
3834 .
name =
"org.gnu.gdb.riscv.vector"
3837 .
name =
"org.gnu.gdb.riscv.virtual"
3840 .
name =
"org.gnu.gdb.riscv.custom"
3847 {
"float", &type_ieee_single, single_double_fields + 1},
3848 {
"double", &type_ieee_double,
NULL},
3851 .
fields = single_double_fields
3857 { .reg_type_union = &single_double_union }
3880 info->vector_uint8.type = &type_uint8;
3881 info->vector_uint8.count =
info->vlenb;
3883 info->type_uint8_vector.id =
"bytes";
3885 info->type_uint8_vector.reg_type_vector = &
info->vector_uint8;
3887 info->vector_uint16.type = &type_uint16;
3888 info->vector_uint16.count =
info->vlenb / 2;
3890 info->type_uint16_vector.id =
"shorts";
3892 info->type_uint16_vector.reg_type_vector = &
info->vector_uint16;
3894 info->vector_uint32.type = &type_uint32;
3895 info->vector_uint32.count =
info->vlenb / 4;
3897 info->type_uint32_vector.id =
"words";
3899 info->type_uint32_vector.reg_type_vector = &
info->vector_uint32;
3901 info->vector_uint64.type = &type_uint64;
3902 info->vector_uint64.count =
info->vlenb / 8;
3904 info->type_uint64_vector.id =
"longs";
3906 info->type_uint64_vector.reg_type_vector = &
info->vector_uint64;
3908 info->vector_uint128.type = &type_uint128;
3909 info->vector_uint128.count =
info->vlenb / 16;
3911 info->type_uint128_vector.id =
"quads";
3913 info->type_uint128_vector.reg_type_vector = &
info->vector_uint128;
3915 info->vector_fields[0].name =
"b";
3916 info->vector_fields[0].type = &
info->type_uint8_vector;
3917 if (
info->vlenb >= 2) {
3918 info->vector_fields[0].next =
info->vector_fields + 1;
3919 info->vector_fields[1].name =
"s";
3920 info->vector_fields[1].type = &
info->type_uint16_vector;
3922 info->vector_fields[0].next =
NULL;
3924 if (
info->vlenb >= 4) {
3925 info->vector_fields[1].next =
info->vector_fields + 2;
3926 info->vector_fields[2].name =
"w";
3927 info->vector_fields[2].type = &
info->type_uint32_vector;
3929 info->vector_fields[1].next =
NULL;
3931 if (
info->vlenb >= 8) {
3932 info->vector_fields[2].next =
info->vector_fields + 3;
3933 info->vector_fields[3].name =
"l";
3934 info->vector_fields[3].type = &
info->type_uint64_vector;
3936 info->vector_fields[2].next =
NULL;
3938 if (
info->vlenb >= 16) {
3939 info->vector_fields[3].next =
info->vector_fields + 4;
3940 info->vector_fields[4].name =
"q";
3941 info->vector_fields[4].type = &
info->type_uint128_vector;
3943 info->vector_fields[3].next =
NULL;
3945 info->vector_fields[4].next =
NULL;
3947 info->vector_union.fields =
info->vector_fields;
3950 info->type_vector.id =
"riscv_vector";
3952 info->type_vector.reg_type_union = &
info->vector_union;
3955 #define DECLARE_CSR(name, number) { number, #name },
3961 unsigned int csr_info_index = 0;
3963 int custom_within_range = 0;
3966 if (!shared_reg_info)
4092 r->
group =
"general";
4096 sprintf(reg_name,
"pc");
4097 r->
group =
"general";
4225 sprintf(reg_name,
"csr%d", csr_number);
4234 switch (csr_number) {
4344 if ((entry->
low <= csr_number) && (csr_number <= entry->high)) {
4350 LOG_DEBUG(
"Exposing additional CSR %d (name=%s)",
4351 csr_number, entry->
name ? entry->
name : reg_name);
4359 sprintf(reg_name,
"priv");
4360 r->
group =
"general";
4361 r->
feature = &feature_virtual;
4369 r->
group =
"vector";
4379 unsigned int custom_number =
range->low + custom_within_range;
4381 r->
group =
"custom";
4388 sprintf(reg_name,
"custom%d", custom_number);
4395 LOG_DEBUG(
"Exposing additional custom register %d (name=%s)",
4398 custom_within_range++;
4399 if (custom_within_range >
range->high -
range->low) {
4400 custom_within_range = 0;
4407 reg_name += strlen(reg_name) + 1;
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
char * buf_to_hex_str(const void *_buf, unsigned int buf_len)
void * buf_cpy(const void *from, void *_to, unsigned int size)
Copies size bits out of from and into to.
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.
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static int halted(struct target *target, const char *label)
#define CSR_MCONTROL6_LOAD
#define CSR_MCONTROL6_ACTION
#define CSR_MCONTROL6_EXECUTE
#define CSR_MCONTROL6_STORE
#define CSR_MCONTROL6_MATCH
#define CSR_MHPMCOUNTER17H
#define CSR_HPMCOUNTER25H
#define CSR_MHPMCOUNTER7H
#define CSR_MHPMCOUNTER27H
#define CSR_HPMCOUNTER22H
#define CSR_MHPMCOUNTER18H
#define CSR_MHPMCOUNTER21H
#define CSR_HPMCOUNTER15H
#define MCONTROL_ACTION_DEBUG_MODE
#define CSR_HPMCOUNTER12H
#define CSR_HPMCOUNTER19H
#define CSR_MHPMCOUNTER28H
#define CSR_MHPMCOUNTER9H
#define CSR_MHPMCOUNTER29H
#define CSR_MHPMCOUNTER10H
#define CSR_MHPMCOUNTER11H
#define MCONTROL_TYPE(xlen)
#define CSR_MHPMCOUNTER12H
#define CSR_HPMCOUNTER31H
#define CSR_MHPMCOUNTER25H
#define CSR_MHPMCOUNTER26H
#define CSR_HPMCOUNTER27H
#define CSR_HPMCOUNTER17H
#define CSR_MHPMCOUNTER5H
#define CSR_HPMCOUNTER21H
#define CSR_MHPMCOUNTER24H
#define CSR_HPMCOUNTER18H
#define CSR_MHPMCOUNTER8H
#define CSR_MHPMCOUNTER3H
#define CSR_HPMCOUNTER14H
#define CSR_MHPMCOUNTER20H
#define CSR_HPMCOUNTER28H
#define CSR_MHPMCOUNTER31H
#define MCONTROL_MATCH_EQUAL
#define CSR_MHPMCOUNTER6H
#define CSR_HPMCOUNTER16H
#define CSR_MHPMCOUNTER23H
#define CSR_HPMCOUNTER20H
#define CSR_MHPMCOUNTER15H
#define MCONTROL_DMODE(xlen)
#define CSR_HPMCOUNTER23H
#define CSR_HPMCOUNTER30H
#define CSR_MHPMCOUNTER14H
#define CSR_HPMCOUNTER13H
#define CSR_MHPMCOUNTER13H
#define CSR_HPMCOUNTER26H
#define CSR_MHPMCOUNTER4H
#define CSR_HPMCOUNTER11H
#define CSR_HPMCOUNTER24H
#define CSR_MHPMCOUNTER22H
#define CSR_HPMCOUNTER29H
#define CSR_HPMCOUNTER10H
#define CSR_MHPMCOUNTER19H
#define CSR_MHPMCOUNTER16H
#define CSR_MHPMCOUNTER30H
enum esirisc_reg_num number
static struct esp_usb_jtag * priv
static uint16_t direction
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_first_entry(ptr, type, member)
static int list_empty(const struct list_head *head)
#define list_for_each_entry_safe(p, n, h, field)
#define list_for_each_entry(p, h, field)
static void list_rotate_left(struct list_head *h)
list_rotate_left - rotate the list to the left
static void INIT_LIST_HEAD(struct list_head *list)
#define ERROR_NOT_IMPLEMENTED
#define LOG_WARNING(expr ...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
static uint32_t ebreak(void) __attribute__((unused))
static uint32_t ebreak_c(void) __attribute__((unused))
struct reg * register_get_by_name(struct reg_cache *first, const char *name, bool search_all)
void register_cache_invalidate(struct reg_cache *cache)
Marks the contents of the register cache as invalid (and clean).
struct target_type riscv011_target
struct target_type riscv013_target
int riscv_reset_timeout_sec
static int halt_finish(struct target *target)
const char * gdb_regno_name(enum gdb_regno regno)
static int resume_go(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Resume all the harts that have been prepped, as close to instantaneous as possible.
static struct scan_field _bscan_tunnel_data_register_select_dmi[]
static int riscv_create_target(struct target *target, Jim_Interp *interp)
static int remove_trigger(struct target *target, struct trigger *trigger)
struct scan_field select_idcode
static bool riscv_enable_virt2phys
static int set_debug_reason(struct target *target, enum riscv_halt_reason halt_reason)
static int old_or_new_riscv_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
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.
static struct scan_field select_user4
static bscan_tunnel_type_t bscan_tunnel_type
static int oldriscv_step(struct target *target, int current, uint32_t address, int handle_breakpoints)
static int riscv_halt_go_all_harts(struct target *target)
struct scan_field select_dbus
int riscv_set_current_hartid(struct target *target, int hartid)
static int maybe_add_trigger_t6(struct target *target, struct trigger *trigger, uint64_t tdata1)
static int riscv_target_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
static int riscv_step_rtos_hart(struct target *target)
static int riscv_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
static struct reg_arch_type riscv_reg_arch_type
static uint32_t bscan_tunnel_data_register_select_dmi_num_fields
static const struct command_registration riscv_command_handlers[]
int riscv_write_debug_buffer(struct target *target, int index, riscv_insn_t insn)
bool riscv_is_halted(struct target *target)
int riscv_read_by_any_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Read one memory item using any memory access size that will work.
static int riscv_read_phys_memory(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, uint8_t *buffer)
int riscv_init_registers(struct target *target)
static int riscv_write_phys_memory(struct target *target, target_addr_t phys_address, uint32_t size, uint32_t count, const uint8_t *buffer)
int riscv_halt(struct target *target)
static int riscv_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
static int add_trigger(struct target *target, struct trigger *trigger)
static int riscv_address_translate(struct target *target, target_addr_t virtual, target_addr_t *physical)
static int register_set(struct reg *reg, uint8_t *buf)
int riscv_write_by_any_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Write one memory item using any memory access size that will work.
static void trigger_from_watchpoint(struct trigger *trigger, const struct watchpoint *watchpoint)
static uint8_t bscan_tunneled_ir_width[4]
static const virt2phys_info_t sv32
static int riscv_init_target(struct command_context *cmd_ctx, struct target *target)
static int old_or_new_riscv_poll(struct target *target)
static int riscv_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
void riscv_fill_dmi_nop_u64(struct target *target, char *buf)
static int riscv_mmu(struct target *target, int *enabled)
static int riscv_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
void riscv_add_bscan_tunneled_scan(struct target *target, struct scan_field *field, riscv_bscan_tunneled_scan_context_t *ctxt)
static int resume_prep(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Get everything ready to resume.
static void riscv_sample_buf_maybe_add_timestamp(struct target *target, bool before)
COMMAND_HELPER(riscv_print_info_line, const char *section, const char *key, unsigned int value)
static int maybe_add_trigger_t2(struct target *target, struct trigger *trigger, uint64_t tdata1)
static int enable_triggers(struct target *target, riscv_reg_t *state)
static void riscv_free_registers(struct target *target)
static const virt2phys_info_t sv48
int riscv_current_hartid(const struct target *target)
int riscv_select_current_hart(struct target *target)
#define get_field(reg, mask)
static struct scan_field _bscan_tunnel_nested_tap_select_dmi[]
int riscv_execute_debug_buffer(struct target *target)
size_t riscv_debug_buffer_size(struct target *target)
static uint32_t dtmcontrol_scan(struct target *target, uint32_t out)
struct target_type riscv_target
struct scan_field select_dtmcontrol
#define DTMCONTROL_VERSION
static const struct command_registration riscv_exec_command_handlers[]
static void riscv_info_init(struct target *target, struct riscv_info *r)
static uint8_t ir_dtmcontrol[4]
static int riscv_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution, bool single_hart)
static int riscv_get_gdb_reg_list_internal(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class, bool read)
uint32_t dtmcontrol_scan_via_bscan(struct target *target, uint32_t out)
static int riscv_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
static int riscv_resume_prep_all_harts(struct target *target)
static bool gdb_regno_cacheable(enum gdb_regno regno, bool write)
If write is true: return true iff we are guaranteed that the register will contain exactly the value ...
static int maybe_add_trigger_t1(struct target *target, struct trigger *trigger, uint64_t tdata1)
static enum riscv_halt_reason riscv_halt_reason(struct target *target, int hartid)
int riscv_openocd_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
static int cmp_csr_info(const void *p1, const void *p2)
static uint8_t ir_user4[4]
int riscv_openocd_poll(struct target *target)
static unsigned int riscv_xlen_nonconst(struct target *target)
int riscv_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
static int oldriscv_poll(struct target *target)
static int riscv_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
void select_dmi_via_bscan(struct target *target)
static int halt_go(struct target *target)
static int riscv_assert_reset(struct target *target)
static int read_by_given_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer, uint32_t access_size)
Read one memory item of given "size".
static uint32_t bscan_tunnel_nested_tap_select_dmi_num_fields
static int halt_prep(struct target *target)
static uint8_t ir_dbus[4]
static unsigned int riscv_data_bits(struct target *target)
static int register_get(struct reg *reg)
COMMAND_HANDLER(riscv_set_command_timeout_sec)
int riscv_dmi_write_u64_bits(struct target *target)
bool riscv_enable_virtual
static void riscv_deinit_target(struct target *target)
static const char * riscv_get_gdb_arch(const struct target *target)
bool riscv_supports_extension(struct target *target, char letter)
static int riscv_examine(struct target *target)
void riscv_fill_dmi_write_u64(struct target *target, char *buf, int a, uint64_t d)
static int riscv_resume_go_all_harts(struct target *target)
void riscv_fill_dmi_read_u64(struct target *target, char *buf, int a)
static int sample_memory(struct target *target)
int riscv_get_register(struct target *target, riscv_reg_t *value, enum gdb_regno regid)
Get register, from the cache if it's in there.
static int riscv_arch_state(struct target *target)
static int riscv_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
static struct scan_field * bscan_tunnel_nested_tap_select_dmi
int riscv_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
static void riscv_invalidate_register_cache(struct target *target)
static int riscv_get_gdb_reg_list_noread(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
static struct target_type * get_target_type(struct target *target)
static struct scan_field * bscan_tunnel_data_register_select_dmi
static void trigger_from_breakpoint(struct trigger *trigger, const struct breakpoint *breakpoint)
static const uint8_t bscan_zero[4]
static int riscv_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
riscv_insn_t riscv_read_debug_buffer(struct target *target, int index)
static int write_by_given_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer, uint32_t access_size)
Write one memory item of given "size".
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
static uint8_t ir_idcode[4]
static int riscv_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical)
static enum @119 resume_order
static int resume_finish(struct target *target)
static int parse_ranges(struct list_head *ranges, const char *tcl_arg, const char *reg_type, unsigned int max_val)
#define set_field(reg, mask, val)
static int disable_triggers(struct target *target, riscv_reg_t *state)
static const virt2phys_info_t sv39
static int riscv_deassert_reset(struct target *target)
static const uint8_t bscan_one[4]
#define RISCV_SAMPLE_BUF_TIMESTAMP_BEFORE
static struct riscv_info * riscv_info(const struct target *target) __attribute__((unused))
void riscv_semihosting_init(struct target *target)
Initialize RISC-V semihosting.
@ RISCV_MEM_ACCESS_UNSPECIFIED
@ RISCV_MEM_ACCESS_SYSBUS
@ RISCV_MEM_ACCESS_PROGBUF
@ RISCV_MEM_ACCESS_ABSTRACT
#define RISCV_NUM_MEM_ACCESS_METHODS
enum semihosting_result riscv_semihosting(struct target *target, int *retval)
Check for and process a semihosting request using the ARM protocol).
#define RISCV_SATP_PPN(xlen)
#define RISCV_MAX_TRIGGERS
#define RISCV_SAMPLE_BUF_TIMESTAMP_AFTER
#define RISCV_COMMON_MAGIC
#define DEFAULT_COMMAND_TIMEOUT_SEC
@ BSCAN_TUNNEL_NESTED_TAP
@ BSCAN_TUNNEL_DATA_REGISTER
#define DEFAULT_RESET_TIMEOUT_SEC
#define RISCV_SATP_MODE(xlen)
size_t size
Size of the control block search area.
const struct command_registration semihosting_common_handlers[]
const struct command_registration smp_command_handlers[]
#define foreach_smp_target(pos, head)
#define foreach_smp_target_direction(forward, pos, head)
enum breakpoint_type type
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
unsigned int ir_length
size of instruction register
int(* get)(struct reg *reg)
int(* set)(struct reg *reg, uint8_t *buf)
struct reg_data_type_union_field * fields
struct reg_feature * feature
struct reg_data_type * reg_data_type
const struct reg_arch_type * type
struct scan_field tunneled_dr[4]
uint8_t tunneled_dr_width
struct list_head expose_custom
int mem_access_methods[RISCV_NUM_MEM_ACCESS_METHODS]
bool mem_access_abstract_warn
bool mem_access_sysbus_warn
struct list_head expose_csr
bool mem_access_progbuf_warn
unsigned int common_magic
enum riscv_halt_reason(* halt_reason)(struct target *target)
int trigger_unique_id[RISCV_MAX_HWBPS]
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.
This holds methods shared between all instances of a given target type.
int(* write_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Target memory write callback.
const char * name
Name of this type of target.
int(* deassert_reset)(struct target *target)
The implementation is responsible for polling the target such that target->state reflects the state c...
int(* init_target)(struct command_context *cmd_ctx, struct target *target)
void(* deinit_target)(struct target *target)
Free all the resources allocated by the target.
int(* halt)(struct target *target)
int(* assert_reset)(struct target *target)
int(* resume)(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
int(* arch_state)(struct target *target)
int(* step)(struct target *target, int current, target_addr_t address, int handle_breakpoints)
int(* poll)(struct target *target)
int(* examine)(struct target *target)
This method is used to perform target setup that requires JTAG access.
int(* virt2phys)(struct target *target, target_addr_t address, target_addr_t *physical)
enum target_debug_reason debug_reason
struct reg_cache * reg_cache
struct list_head * smp_targets
struct target_type * type
struct watchpoint * watchpoints
int target_call_event_callbacks(struct target *target, enum target_event event)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
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.
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
struct target * get_current_target(struct command_context *cmd_ctx)
#define ERROR_TARGET_NOT_HALTED
static bool target_was_examined(const struct target *target)
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define TARGET_DEFAULT_POLLING_INTERVAL
#define ERROR_TARGET_TIMEOUT
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
static void h_u32_to_le(uint8_t *buf, uint32_t val)
#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 low
static struct ublast_lowlevel_priv info