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,
 
 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 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 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);
 
 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 halts_discovered = 0;
 
 2191         unsigned should_remain_halted = 0;
 
 2192         unsigned should_resume = 0;
 
 2219                         should_remain_halted++;
 
 2230                     should_remain_halted++;
 
 2239         LOG_DEBUG(
"should_remain_halted=%d, should_resume=%d",
 
 2240                   should_remain_halted, should_resume);
 
 2241         if (should_remain_halted && should_resume) {
 
 2242             LOG_WARNING(
"%d harts should remain halted, and %d should resume.",
 
 2243                         should_remain_halted, should_resume);
 
 2245         if (should_remain_halted) {
 
 2248         } 
else if (should_resume) {
 
 2276         LOG_DEBUG(
"  hart %d halted", halted_hart);
 
 2340         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2357         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2375     LOG_WARNING(
"`riscv set_prefer_sba` is deprecated. Please use `riscv set_mem_access` instead.");
 
 2377         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2394     r->mem_access_progbuf_warn = 
true;
 
 2395     r->mem_access_sysbus_warn = 
true;
 
 2396     r->mem_access_abstract_warn = 
true;
 
 2405     int progbuf_cnt = 0;
 
 2407     int abstract_cnt = 0;
 
 2415     for (
unsigned int i = 0; i < 
CMD_ARGC; i++) {
 
 2416         if (strcmp(
"progbuf", 
CMD_ARGV[i]) == 0) {
 
 2418         } 
else if (strcmp(
"sysbus", 
CMD_ARGV[i]) == 0) {
 
 2420         } 
else if (strcmp(
"abstract", 
CMD_ARGV[i]) == 0) {
 
 2424                 "Must be one of: 'progbuf', 'sysbus' or 'abstract'.", 
CMD_ARGV[i]);
 
 2428     if (progbuf_cnt > 1 || sysbus_cnt > 1 || abstract_cnt > 1) {
 
 2429         LOG_ERROR(
"Syntax error - duplicate arguments to `riscv set_mem_access`.");
 
 2436     for (
unsigned int i = 0; i < 
CMD_ARGC; i++) {
 
 2437         if (strcmp(
"progbuf", 
CMD_ARGV[i]) == 0)
 
 2439         else if (strcmp(
"sysbus", 
CMD_ARGV[i]) == 0)
 
 2441         else if (strcmp(
"abstract", 
CMD_ARGV[i]) == 0)
 
 2446     r->mem_access_progbuf_warn = 
true;
 
 2447     r->mem_access_sysbus_warn = 
true;
 
 2448     r->mem_access_abstract_warn = 
true;
 
 2456         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2465     char *args = strdup(tcl_arg);
 
 2470     char *arg = strtok(args, 
",");
 
 2476         char *dash = strchr(arg, 
'-');
 
 2477         char *equals = strchr(arg, 
'=');
 
 2480         if (!dash && !equals) {
 
 2482             if (sscanf(arg, 
"%u%n", &
low, &pos) != 1 || pos != strlen(arg)) {
 
 2483                 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
 
 2487         } 
else if (dash && !equals) {
 
 2491             if (sscanf(arg, 
"%u%n", &
low, &pos) != 1 || pos != strlen(arg)) {
 
 2492                 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
 
 2496             if (sscanf(dash, 
"%u%n", &high, &pos) != 1 || pos != strlen(dash)) {
 
 2497                 LOG_ERROR(
"Failed to parse single register number from '%s'.", dash);
 
 2502                 LOG_ERROR(
"Incorrect range encountered [%u, %u].", 
low, high);
 
 2506         } 
else if (!dash && equals) {
 
 2510             if (sscanf(arg, 
"%u%n", &
low, &pos) != 1 || pos != strlen(arg)) {
 
 2511                 LOG_ERROR(
"Failed to parse single register number from '%s'.", arg);
 
 2516             name = calloc(1, strlen(equals) + strlen(
reg_type) + 2);
 
 2518                 LOG_ERROR(
"Failed to allocate register name.");
 
 2527             if (sscanf(equals, 
"%[_a-zA-Z0-9]%n", 
name + strlen(
reg_type) + 1, &pos) != 1 || pos != strlen(equals)) {
 
 2528                 LOG_ERROR(
"Failed to parse register name from '%s'.", equals);
 
 2534             LOG_ERROR(
"Invalid argument '%s'.", arg);
 
 2539         high = high > 
low ? high : 
low;
 
 2541         if (high > max_val) {
 
 2542             LOG_ERROR(
"Cannot expose %s register number %u, maximum allowed value is %u.", 
reg_type, high, max_val);
 
 2551             if ((entry->
low <= high) && (low <= entry->high)) {
 
 2554                             "Register %u has already been exposed previously", 
reg_type, 
low);
 
 2556                     LOG_WARNING(
"Overlapping register ranges - Register range starting from %u overlaps " 
 2557                             "with already exposed register/range at %u.", 
low, entry->
low);
 
 2570             LOG_ERROR(
"Failed to allocate range list.");
 
 2581         arg = strtok(
NULL, 
",");
 
 2591         LOG_ERROR(
"Command expects parameters");
 
 2599     for (
unsigned int i = 0; i < 
CMD_ARGC; i++) {
 
 2611         LOG_ERROR(
"Command expects parameters");
 
 2619     for (
unsigned int i = 0; i < 
CMD_ARGC; i++) {
 
 2630     unsigned int index = 0;
 
 2636         LOG_ERROR(
"Command takes at most one parameter");
 
 2652     if (r->authdata_read) {
 
 2659         LOG_ERROR(
"authdata_read is not implemented for this target.");
 
 2667     unsigned int index = 0;
 
 2682     if (!r->authdata_write) {
 
 2683         LOG_ERROR(
"authdata_write is not implemented for this target.");
 
 2687     return r->authdata_write(
target, value, index);
 
 2710         uint32_t address, value;
 
 2717         LOG_ERROR(
"dmi_read is not implemented for this target.");
 
 2726         LOG_ERROR(
"Command takes exactly 2 arguments");
 
 2733     uint32_t address, value;
 
 2738         return r->dmi_write(
target, address, value);
 
 2740         LOG_ERROR(
"dmi_write is not implemented for this target.");
 
 2747     LOG_WARNING(
"Command \"riscv test_sba_config_reg\" is deprecated. " 
 2748         "It will be removed in a future OpenOCD version.");
 
 2751         LOG_ERROR(
"Command takes exactly 4 arguments");
 
 2761     bool run_sbbusyerror_test;
 
 2768     if (r->test_sba_config_reg) {
 
 2769         return r->test_sba_config_reg(
target, legal_address, num_words,
 
 2770                 illegal_address, run_sbbusyerror_test);
 
 2772         LOG_ERROR(
"test_sba_config_reg is not implemented for this target.");
 
 2782         LOG_ERROR(
"Command takes at most one argument");
 
 2791     r->reset_delays_wait = wait;
 
 2798         LOG_ERROR(
"Command takes exactly 2 arguments");
 
 2805     if (!strcmp(
CMD_ARGV[0], 
"idcode"))
 
 2807     else if (!strcmp(
CMD_ARGV[0], 
"dtmcs"))
 
 2809     else if (!strcmp(
CMD_ARGV[0], 
"dmi"))
 
 2820         LOG_ERROR(
"Command takes at most one argument");
 
 2824     if (!strcmp(
CMD_ARGV[0], 
"normal")) {
 
 2826     } 
else if (!strcmp(
CMD_ARGV[0], 
"reversed")) {
 
 2842         LOG_ERROR(
"Command takes at most two arguments");
 
 2851         LOG_INFO(
"Nested Tap based Bscan Tunnel Selected");
 
 2853         LOG_INFO(
"Simple Register based Bscan Tunnel Selected");
 
 2855         LOG_INFO(
"Invalid Tunnel type selected ! : selecting default Nested Tap Type");
 
 2865         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2875         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2885         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2895         LOG_ERROR(
"Command takes exactly 1 parameter");
 
 2906     snprintf(full_key, 
sizeof(full_key), 
"%s.%s", section, key);
 
 2920     riscv_print_info_line(
CMD, 
"hart", 
"trigger_count",
 
 2932         .handler = handle_info,
 
 2935         .help = 
"Displays some information OpenOCD detected about the target." 
 2938         .name = 
"set_command_timeout_sec",
 
 2939         .handler = riscv_set_command_timeout_sec,
 
 2942         .help = 
"Set the wall-clock timeout (in seconds) for individual commands" 
 2945         .name = 
"set_reset_timeout_sec",
 
 2946         .handler = riscv_set_reset_timeout_sec,
 
 2949         .help = 
"Set the wall-clock timeout (in seconds) after reset is deasserted" 
 2952         .name = 
"set_prefer_sba",
 
 2953         .handler = riscv_set_prefer_sba,
 
 2956         .help = 
"When on, prefer to use System Bus Access to access memory. " 
 2957             "When off (default), prefer to use the Program Buffer to access memory." 
 2960         .name = 
"set_mem_access",
 
 2961         .handler = riscv_set_mem_access,
 
 2963         .usage = 
"method1 [method2] [method3]",
 
 2964         .help = 
"Set which memory access methods shall be used and in which order " 
 2965             "of priority. Method can be one of: 'progbuf', 'sysbus' or 'abstract'." 
 2968         .name = 
"set_enable_virtual",
 
 2969         .handler = riscv_set_enable_virtual,
 
 2972         .help = 
"When on, memory accesses are performed on physical or virtual " 
 2973                 "memory depending on the current system configuration. " 
 2974                 "When off (default), all memory accessses are performed on physical memory." 
 2977         .name = 
"expose_csrs",
 
 2978         .handler = riscv_set_expose_csrs,
 
 2980         .usage = 
"n0[-m0|=name0][,n1[-m1|=name1]]...",
 
 2981         .help = 
"Configure a list of inclusive ranges for CSRs to expose in " 
 2982                 "addition to the standard ones. This must be executed before " 
 2986         .name = 
"expose_custom",
 
 2987         .handler = riscv_set_expose_custom,
 
 2989         .usage = 
"n0[-m0|=name0][,n1[-m1|=name1]]...",
 
 2990         .help = 
"Configure a list of inclusive ranges for custom registers to " 
 2991             "expose. custom0 is accessed as abstract register number 0xc000, " 
 2992             "etc. This must be executed before `init`." 
 2995         .name = 
"authdata_read",
 
 2996         .handler = riscv_authdata_read,
 
 2999         .help = 
"Return the 32-bit value read from authdata or authdata0 " 
 3000                 "(index=0), or authdata1 (index=1)." 
 3003         .name = 
"authdata_write",
 
 3004         .handler = riscv_authdata_write,
 
 3006         .usage = 
"[index] value",
 
 3007         .help = 
"Write the 32-bit value to authdata or authdata0 (index=0), " 
 3008                 "or authdata1 (index=1)." 
 3012         .handler = riscv_dmi_read,
 
 3015         .help = 
"Perform a 32-bit DMI read at address, returning the value." 
 3018         .name = 
"dmi_write",
 
 3019         .handler = riscv_dmi_write,
 
 3021         .usage = 
"address value",
 
 3022         .help = 
"Perform a 32-bit DMI write of value at address." 
 3025         .name = 
"test_sba_config_reg",
 
 3026         .handler = riscv_test_sba_config_reg,
 
 3028         .usage = 
"legal_address num_words " 
 3029             "illegal_address run_sbbusyerror_test[on/off]",
 
 3030         .help = 
"Perform a series of tests on the SBCS register. " 
 3031             "Inputs are a legal, 128-byte aligned address and a number of words to " 
 3032             "read/write starting at that address (i.e., address range [legal address, " 
 3033             "legal_address+word_size*num_words) must be legally readable/writable), " 
 3034             "an illegal, 128-byte aligned address for error flag/handling cases, " 
 3035             "and whether sbbusyerror test should be run." 
 3038         .name = 
"reset_delays",
 
 3039         .handler = riscv_reset_delays,
 
 3042         .help = 
"OpenOCD learns how many Run-Test/Idle cycles are required " 
 3043             "between scans to avoid encountering the target being busy. This " 
 3044             "command resets those learned values after `wait` scans. It's only " 
 3045             "useful for testing OpenOCD itself." 
 3048         .name = 
"resume_order",
 
 3049         .handler = riscv_resume_order,
 
 3051         .usage = 
"normal|reversed",
 
 3052         .help = 
"Choose the order that harts are resumed in when `hasel` is not " 
 3053             "supported. Normal order is from lowest hart index to highest. " 
 3054             "Reversed order is from highest hart index to lowest." 
 3058         .handler = riscv_set_ir,
 
 3060         .usage = 
"[idcode|dtmcs|dmi] value",
 
 3061         .help = 
"Set IR value for specified JTAG register." 
 3064         .name = 
"use_bscan_tunnel",
 
 3065         .handler = riscv_use_bscan_tunnel,
 
 3067         .usage = 
"value [type]",
 
 3068         .help = 
"Enable or disable use of a BSCAN tunnel to reach DM.  Supply " 
 3069             "the width of the DM transport TAP's instruction register to " 
 3070             "enable.  Supply a value of 0 to disable. Pass A second argument " 
 3071             "(optional) to indicate Bscan Tunnel Type {0:(default) NESTED_TAP , " 
 3075         .name = 
"set_enable_virt2phys",
 
 3076         .handler = riscv_set_enable_virt2phys,
 
 3079         .help = 
"When on (default), enable translation from virtual address to " 
 3083         .name = 
"set_ebreakm",
 
 3084         .handler = riscv_set_ebreakm,
 
 3087         .help = 
"Control dcsr.ebreakm. When off, M-mode ebreak instructions " 
 3088             "don't trap to OpenOCD. Defaults to on." 
 3091         .name = 
"set_ebreaks",
 
 3092         .handler = riscv_set_ebreaks,
 
 3095         .help = 
"Control dcsr.ebreaks. When off, S-mode ebreak instructions " 
 3096             "don't trap to OpenOCD. Defaults to on." 
 3099         .name = 
"set_ebreaku",
 
 3100         .handler = riscv_set_ebreaku,
 
 3103         .help = 
"Control dcsr.ebreaku. When off, U-mode ebreak instructions " 
 3104             "don't trap to OpenOCD. Defaults to on." 
 3127         .help = 
"RISC-V Command Group",
 
 3134         .help = 
"ARM Command Group",
 
 3150         return r->data_bits(
target);
 
 3208     memset(r, 0, 
sizeof(*r));
 
 3243         LOG_DEBUG(
"[%s] hart requested resume, but was already resumed",
 
 3261         LOG_ERROR(
"Hart isn't halted before single step!");
 
 3271         LOG_ERROR(
"Hart was not halted after single step!");
 
 3281     if (letter >= 
'a' && letter <= 
'z')
 
 3283     else if (letter >= 
'A' && letter <= 
'Z')
 
 3287     return r->misa & 
BIT(num);
 
 3299     if (!r->select_current_hart)
 
 3303     r->current_hartid = hartid;
 
 3304     LOG_DEBUG(
"setting hartid to %d, was %d", hartid, previous_hartid);
 
 3325     return r->current_hartid;
 
 3333     if (!r || !r->hart_count)
 
 3335     return r->hart_count(
target);
 
 3395     assert(r->set_register);
 
 3407     int result = r->set_register(
target, regid, 
value);
 
 3412     LOG_DEBUG(
"[%s] wrote 0x%" PRIx64 
" to %s valid=%d",
 
 3445     int result = r->get_register(
target, 
value, regid);
 
 3458     assert(r->is_halted);
 
 3459     return r->is_halted(
target);
 
 3471     return r->halt_reason(
target);
 
 3477     return r->debug_buffer_size;
 
 3483     r->write_debug_buffer(
target, index, insn);
 
 3490     return r->read_debug_buffer(
target, index);
 
 3496     return r->execute_debug_buffer(
target);
 
 3502     r->fill_dmi_write_u64(
target, buf, a, d);
 
 3508     r->fill_dmi_read_u64(
target, buf, a);
 
 3514     r->fill_dmi_nop_u64(
target, buf);
 
 3520     return r->dmi_write_u64_bits(
target);
 
 3534     if (r->triggers_enumerated)
 
 3537     r->triggers_enumerated = 
true;  
 
 3545         LOG_DEBUG(
"[%s] Cannot access tselect register. " 
 3547         r->trigger_count = 0;
 
 3552         r->trigger_count = t;
 
 3557         uint64_t tselect_rb;
 
 3564         if (tselect_rb != t)
 
 3600     static char buf[32];
 
 3775                 sprintf(buf, 
"gdb_regno_%d", regno);
 
 3787         if (!r->get_register_buf) {
 
 3788             LOG_ERROR(
"Reading register %s not supported on this RISC-V target.",
 
 3831         r->manual_hwbp_set = 
true;
 
 3841         if (!r->set_register_buf) {
 
 3842             LOG_ERROR(
"Writing register %s not supported on this RISC-V target.",
 
 3870     return (
int) (((
struct csr_info *)p1)->number) - (
int) (((
struct csr_info *)p2)->number);
 
 3891     LOG_DEBUG(
"create register cache for %d registers",
 
 3899     const unsigned int max_reg_name_len = 12;
 
 3900     free(
info->reg_names);
 
 3903     if (!
info->reg_names)
 
 3905     char *reg_name = 
info->reg_names;
 
 3908         .
name = 
"org.gnu.gdb.riscv.cpu" 
 3911         .
name = 
"org.gnu.gdb.riscv.fpu" 
 3914         .
name = 
"org.gnu.gdb.riscv.csr" 
 3917         .
name = 
"org.gnu.gdb.riscv.vector" 
 3920         .
name = 
"org.gnu.gdb.riscv.virtual" 
 3923         .
name = 
"org.gnu.gdb.riscv.custom" 
 3930         {
"float", &type_ieee_single, single_double_fields + 1},
 
 3931         {
"double", &type_ieee_double, 
NULL},
 
 3934         .
fields = single_double_fields
 
 3940         .reg_type_union = &single_double_union
 
 3963     info->vector_uint8.type = &type_uint8;
 
 3964     info->vector_uint8.count = 
info->vlenb;
 
 3966     info->type_uint8_vector.id = 
"bytes";
 
 3968     info->type_uint8_vector.reg_type_vector = &
info->vector_uint8;
 
 3970     info->vector_uint16.type = &type_uint16;
 
 3971     info->vector_uint16.count = 
info->vlenb / 2;
 
 3973     info->type_uint16_vector.id = 
"shorts";
 
 3975     info->type_uint16_vector.reg_type_vector = &
info->vector_uint16;
 
 3977     info->vector_uint32.type = &type_uint32;
 
 3978     info->vector_uint32.count = 
info->vlenb / 4;
 
 3980     info->type_uint32_vector.id = 
"words";
 
 3982     info->type_uint32_vector.reg_type_vector = &
info->vector_uint32;
 
 3984     info->vector_uint64.type = &type_uint64;
 
 3985     info->vector_uint64.count = 
info->vlenb / 8;
 
 3987     info->type_uint64_vector.id = 
"longs";
 
 3989     info->type_uint64_vector.reg_type_vector = &
info->vector_uint64;
 
 3991     info->vector_uint128.type = &type_uint128;
 
 3992     info->vector_uint128.count = 
info->vlenb / 16;
 
 3994     info->type_uint128_vector.id = 
"quads";
 
 3996     info->type_uint128_vector.reg_type_vector = &
info->vector_uint128;
 
 3998     info->vector_fields[0].name = 
"b";
 
 3999     info->vector_fields[0].type = &
info->type_uint8_vector;
 
 4000     if (
info->vlenb >= 2) {
 
 4001         info->vector_fields[0].next = 
info->vector_fields + 1;
 
 4002         info->vector_fields[1].name = 
"s";
 
 4003         info->vector_fields[1].type = &
info->type_uint16_vector;
 
 4005         info->vector_fields[0].next = 
NULL;
 
 4007     if (
info->vlenb >= 4) {
 
 4008         info->vector_fields[1].next = 
info->vector_fields + 2;
 
 4009         info->vector_fields[2].name = 
"w";
 
 4010         info->vector_fields[2].type = &
info->type_uint32_vector;
 
 4012         info->vector_fields[1].next = 
NULL;
 
 4014     if (
info->vlenb >= 8) {
 
 4015         info->vector_fields[2].next = 
info->vector_fields + 3;
 
 4016         info->vector_fields[3].name = 
"l";
 
 4017         info->vector_fields[3].type = &
info->type_uint64_vector;
 
 4019         info->vector_fields[2].next = 
NULL;
 
 4021     if (
info->vlenb >= 16) {
 
 4022         info->vector_fields[3].next = 
info->vector_fields + 4;
 
 4023         info->vector_fields[4].name = 
"q";
 
 4024         info->vector_fields[4].type = &
info->type_uint128_vector;
 
 4026         info->vector_fields[3].next = 
NULL;
 
 4028     info->vector_fields[4].next = 
NULL;
 
 4030     info->vector_union.fields = 
info->vector_fields;
 
 4033     info->type_vector.id = 
"riscv_vector";
 
 4035     info->type_vector.reg_type_union = &
info->vector_union;
 
 4038 #define DECLARE_CSR(name, number) { number, #name }, 
 4044     unsigned csr_info_index = 0;
 
 4046     int custom_within_range = 0;
 
 4049     if (!shared_reg_info)
 
 4175             r->
group = 
"general";
 
 4179             sprintf(reg_name, 
"pc");
 
 4180             r->
group = 
"general";
 
 4308                 sprintf(reg_name, 
"csr%d", csr_number);
 
 4317             switch (csr_number) {
 
 4427                     if ((entry->
low <= csr_number) && (csr_number <= entry->high)) {
 
 4433                         LOG_DEBUG(
"Exposing additional CSR %d (name=%s)",
 
 4434                                 csr_number, entry->
name ? entry->
name : reg_name);
 
 4442             sprintf(reg_name, 
"priv");
 
 4443             r->
group = 
"general";
 
 4444             r->
feature = &feature_virtual;
 
 4452             r->
group = 
"vector";
 
 4462             unsigned custom_number = 
range->low + custom_within_range;
 
 4464             r->
group = 
"custom";
 
 4471             sprintf(reg_name, 
"custom%d", custom_number);
 
 4478             LOG_DEBUG(
"Exposing additional custom register %d (name=%s)",
 
 4481             custom_within_range++;
 
 4482             if (custom_within_range > 
range->high - 
range->low) {
 
 4483                 custom_within_range = 0;
 
 4490             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 buf_len)
 
void * buf_cpy(const void *from, void *_to, unsigned size)
Copies size bits out of from and into to.
 
static void buf_set_u64(uint8_t *_buffer, unsigned first, unsigned num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
 
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
 
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
 
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
 
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)
list_add - add a new entry
 
#define list_first_entry(ptr, type, member)
list_first_entry - get the first element from a list
 
static int list_empty(const struct list_head *head)
list_empty - tests whether a list is empty
 
#define list_for_each_entry(pos, head, member)
list_for_each_entry - iterate over list of given type
 
#define list_for_each_entry_safe(pos, n, head, member)
list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
 
static void list_rotate_left(struct list_head *head)
list_rotate_left - rotate the list to the left
 
static void INIT_LIST_HEAD(struct list_head *list)
INIT_LIST_HEAD - Initialize a list_head structure.
 
#define ERROR_NOT_IMPLEMENTED
 
#define LOG_WARNING(expr ...)
 
#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 enum @112 resume_order
 
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)
 
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 unsigned riscv_xlen_nonconst(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)
 
unsigned riscv_xlen(const struct target *target)
 
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 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, int timeout_ms, void *arch_info)
 
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)
 
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)
 
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 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 const char * riscv_get_gdb_arch(struct target *target)
 
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[]
 
#define foreach_smp_target(pos, head)
 
#define foreach_smp_target_direction(forward, pos, head)
 
enum breakpoint_type type
 
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.
 
int num_bits
The number of bits this field specifies.
 
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
 
const uint8_t * out_value
A pointer to value to be scanned into the device.
 
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_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_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, int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
 
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
 
#define TARGET_DEFAULT_POLLING_INTERVAL
 
static const char * target_name(struct target *target)
Returns the instance-specific name of the specified target.
 
#define ERROR_TARGET_TIMEOUT
 
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
 
static bool target_was_examined(struct target *target)
 
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