14 #define DTM_DMI_MAX_ADDRESS_LENGTH ((1<<DTM_DTMCS_ABITS_LENGTH)-1)
15 #define DMI_SCAN_MAX_BIT_LENGTH (DTM_DMI_MAX_ADDRESS_LENGTH + DTM_DMI_DATA_LENGTH + DTM_DMI_OP_LENGTH)
17 #define DMI_SCAN_BUF_SIZE (DIV_ROUND_UP(DMI_SCAN_MAX_BIT_LENGTH, 8))
20 #define BATCH_RESERVED_SCANS 1
36 LOG_ERROR(
"Failed to allocate struct riscv_batch");
58 LOG_ERROR(
"Failed to allocate data_out in RISC-V batch.");
63 LOG_ERROR(
"Failed to allocate data_in in RISC-V batch.");
68 LOG_ERROR(
"Failed to allocate fields in RISC-V batch.");
73 LOG_ERROR(
"Failed to allocate delay_classes in RISC-V batch.");
79 LOG_ERROR(
"Failed to allocate bscan_ctxt in RISC-V batch.");
85 LOG_ERROR(
"Failed to allocate read_keys in RISC-V batch.");
136 if (new_delay <= batch->last_scan_delay)
146 size_t reset_delays_after)
149 assert(scan_idx < batch->used_scans);
150 const bool delays_were_reset = resets_delays
151 && (scan_idx >= reset_delays_after);
155 return delays_were_reset ? 0 : delay;
159 uint32_t
address, uint32_t data)
161 static const struct {
177 .DXLEN = { .value = 0, .is_set =
false },
178 .abits = { .value = 0, .is_set =
false },
190 uint32_t
address, uint32_t data)
193 char *
const decoded = malloc(
size);
199 LOG_DEBUG(
"%s: %s", write ?
"write" :
"read", decoded);
205 size_t reset_delays_after)
219 bool last_scan_was_read =
false;
220 uint32_t last_scan_address = (uint32_t)(-1) ;
231 for (
size_t i = start_idx; i < batch->
used_scans; ++i) {
232 static const char *
const op_string[] = {
"-",
"r",
"w",
"?"};
233 const unsigned int delay =
get_delay(batch, i, delays, resets_delays,
245 static const char *
const status_string[] = {
255 LOG_DEBUG(
"%db %s %08" PRIx32
" @%02" PRIx32
256 " -> %s %08" PRIx32
" @%02" PRIx32
"; %ui",
257 field->
num_bits, op_string[out_op], out_data, out_address,
258 status_string[in_op], in_data, in_address, delay);
262 last_scan_address, in_data);
264 LOG_DEBUG(
"%db %s %08" PRIx32
" @%02" PRIx32
" -> ?; %ui",
265 field->
num_bits, op_string[out_op], out_data, out_address,
274 last_scan_address = out_address;
280 size_t reset_delays_after)
283 assert(start_idx < batch->used_scans);
294 unsigned int delay = 0 ;
295 for (
size_t i = start_idx; i < batch->
used_scans; ++i) {
302 delay =
get_delay(batch, i, delays, resets_delays,
319 for (
size_t i = start_idx; i < batch->
used_scans; ++i) {
320 if ((batch->
fields + i)->in_value)
325 log_batch(batch, start_idx, delays, resets_delays, reset_delays_after);
391 assert(key < batch->read_keys_used);
393 assert(index < batch->used_scans);
401 assert(key < batch->read_keys_used);
403 assert(index < batch->used_scans);
453 size_t first_busy = 0;
bool riscv_batch_was_batch_busy(const struct riscv_batch *batch)
uint32_t riscv_batch_get_dmi_read_op(const struct riscv_batch *batch, size_t key)
struct riscv_batch * riscv_batch_alloc(struct target *target, size_t scans)
void riscv_batch_add_nop(struct riscv_batch *batch)
static unsigned int get_delay(const struct riscv_batch *batch, size_t scan_idx, const struct riscv_scan_delays *delays, bool resets_delays, size_t reset_delays_after)
static void log_batch(const struct riscv_batch *batch, size_t start_idx, const struct riscv_scan_delays *delays, bool resets_delays, size_t reset_delays_after)
static unsigned int decode_dmi(const struct riscv_batch *batch, char *text, uint32_t address, uint32_t data)
#define DMI_SCAN_BUF_SIZE
#define BATCH_RESERVED_SCANS
void riscv_batch_add_dmi_write(struct riscv_batch *batch, uint32_t address, uint32_t data, bool read_back, enum riscv_scan_delay_class delay_class)
size_t riscv_batch_available_scans(struct riscv_batch *batch)
uint32_t riscv_batch_get_dmi_read_data(const struct riscv_batch *batch, size_t key)
static void log_dmi_decoded(const struct riscv_batch *batch, bool write, uint32_t address, uint32_t data)
size_t riscv_batch_finished_scans(const struct riscv_batch *batch)
static unsigned int get_dmi_scan_length(const struct target *target)
#define DMI_SCAN_MAX_BIT_LENGTH
static bool riscv_batch_was_scan_busy(const struct riscv_batch *batch, size_t scan_idx)
void riscv_batch_free(struct riscv_batch *batch)
size_t riscv_batch_add_dmi_read(struct riscv_batch *batch, uint32_t address, enum riscv_scan_delay_class delay_class)
int riscv_batch_run_from(struct riscv_batch *batch, size_t start_idx, const struct riscv_scan_delays *delays, bool resets_delays, size_t reset_delays_after)
bool riscv_batch_full(struct riscv_batch *batch)
#define DTM_DMI_MAX_ADDRESS_LENGTH
static void add_idle_before_batch(const struct riscv_batch *batch, size_t start_idx, const struct riscv_scan_delays *delays)
static unsigned int riscv_scan_get_delay(const struct riscv_scan_delays *delays, enum riscv_scan_delay_class delay_class)
@ RISCV_SCAN_TYPE_INVALID
void buffer_shr(void *_buf, unsigned int buf_len, unsigned int count)
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static 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.
#define DTM_DMI_DATA_OFFSET
#define DTM_DMI_OP_OFFSET
#define DTM_DMI_ADDRESS_OFFSET
#define DTM_DMI_DATA_LENGTH
#define DTM_DMI_OP_LENGTH
#define DTM_DMI_OP_SUCCESS
unsigned int riscv_debug_reg_to_s(char *buf, enum riscv_debug_reg_ordinal reg_ordinal, struct riscv_debug_reg_ctx context, uint64_t value, enum riscv_debug_reg_show show)
This function is used to fill a buffer with a decoded string representation of register's value.
@ RISCV_DEBUG_REG_HIDE_ALL_0
uint32_t size
Size of dw_spi_transaction::buffer.
uint32_t address
Starting address. Sector aligned.
static uint64_t get_field(uint64_t reg, uint64_t mask)
void jtag_add_runtest(unsigned int num_cycles, enum tap_state state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, enum tap_state state)
Generate a DR SCAN using the fields passed to the function.
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(target, fmt_str,...)
#define LOG_ERROR(expr ...)
#define LOG_LEVEL_IS(FOO)
#define LOG_DEBUG(expr ...)
void riscv_add_bscan_tunneled_scan(struct jtag_tap *tap, const struct scan_field *field, riscv_bscan_tunneled_scan_context_t *ctxt)
unsigned int riscv_get_dmi_address_bits(const struct target *target)
uint8_t bscan_tunnel_ir_width
void riscv_fill_dmi_write(const struct target *target, uint8_t *buf, uint32_t a, uint32_t d)
uint32_t riscv_get_dmi_address(const struct target *target, uint32_t dm_address)
void riscv_fill_dm_nop(const struct target *target, uint8_t *buf)
void riscv_fill_dmi_read(const struct target *target, uint8_t *buf, uint32_t a)
riscv_bscan_tunneled_scan_context_t * bscan_ctxt
enum riscv_scan_type last_scan
enum riscv_scan_delay_class * delay_classes
unsigned int last_scan_delay
struct scan_field * fields
struct riscv_debug_reg_ctx::@123 XLEN
struct riscv_debug_reg_ctx::@124 abits
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.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.