Skip to content

Commit 42be17a

Browse files
authored
Add idle count to debug output. (#337)
Few other minor cleanups/debug improvements. Change-Id: I370a86ddc17a2d888afa178448125661e12caf72
1 parent b911e07 commit 42be17a

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

src/target/riscv/batch.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@
99
#define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
1010
#define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
1111

12-
static void dump_field(const struct scan_field *field);
12+
static void dump_field(int idle, const struct scan_field *field);
1313

1414
struct riscv_batch *riscv_batch_alloc(struct target *target, size_t scans, size_t idle)
1515
{
1616
scans += 4;
17-
struct riscv_batch *out = malloc(sizeof(*out));
18-
memset(out, 0, sizeof(*out));
17+
struct riscv_batch *out = calloc(1, sizeof(*out));
1918
out->target = target;
2019
out->allocated_scans = scans;
21-
out->used_scans = 0;
2220
out->idle_count = idle;
2321
out->data_out = malloc(sizeof(*out->data_out) * (scans) * sizeof(uint64_t));
2422
out->data_in = malloc(sizeof(*out->data_in) * (scans) * sizeof(uint64_t));
2523
out->fields = malloc(sizeof(*out->fields) * (scans));
2624
out->last_scan = RISCV_SCAN_TYPE_INVALID;
2725
out->read_keys = malloc(sizeof(*out->read_keys) * (scans));
28-
out->read_keys_used = 0;
2926
return out;
3027
}
3128

@@ -65,7 +62,7 @@ int riscv_batch_run(struct riscv_batch *batch)
6562
}
6663

6764
for (size_t i = 0; i < batch->used_scans; ++i)
68-
dump_field(batch->fields + i);
65+
dump_field(batch->idle_count, batch->fields + i);
6966

7067
return ERROR_OK;
7168
}
@@ -96,7 +93,7 @@ size_t riscv_batch_add_dmi_read(struct riscv_batch *batch, unsigned address)
9693
batch->used_scans++;
9794

9895
/* FIXME We get the read response back on the next scan. For now I'm
99-
* just sticking a NOP in there, but this should be coelesced away. */
96+
* just sticking a NOP in there, but this should be coalesced away. */
10097
riscv_batch_add_nop(batch);
10198

10299
batch->read_keys[batch->read_keys_used] = batch->used_scans - 1;
@@ -132,7 +129,7 @@ void riscv_batch_add_nop(struct riscv_batch *batch)
132129
batch->used_scans++;
133130
}
134131

135-
void dump_field(const struct scan_field *field)
132+
void dump_field(int idle, const struct scan_field *field)
136133
{
137134
static const char * const op_string[] = {"-", "r", "w", "?"};
138135
static const char * const status_string[] = {"+", "?", "F", "b"};
@@ -154,13 +151,13 @@ void dump_field(const struct scan_field *field)
154151

155152
log_printf_lf(LOG_LVL_DEBUG,
156153
__FILE__, __LINE__, __PRETTY_FUNCTION__,
157-
"%db %s %08x @%02x -> %s %08x @%02x",
158-
field->num_bits,
154+
"%db %di %s %08x @%02x -> %s %08x @%02x",
155+
field->num_bits, idle,
159156
op_string[out_op], out_data, out_address,
160157
status_string[in_op], in_data, in_address);
161158
} else {
162159
log_printf_lf(LOG_LVL_DEBUG,
163-
__FILE__, __LINE__, __PRETTY_FUNCTION__, "%db %s %08x @%02x -> ?",
164-
field->num_bits, op_string[out_op], out_data, out_address);
160+
__FILE__, __LINE__, __PRETTY_FUNCTION__, "%db %di %s %08x @%02x -> ?",
161+
field->num_bits, idle, op_string[out_op], out_data, out_address);
165162
}
166163
}

src/target/riscv/riscv-013.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static void decode_dmi(char *text, unsigned address, unsigned data)
357357
}
358358
}
359359

360-
static void dump_field(const struct scan_field *field)
360+
static void dump_field(int idle, const struct scan_field *field)
361361
{
362362
static const char * const op_string[] = {"-", "r", "w", "?"};
363363
static const char * const status_string[] = {"+", "?", "F", "b"};
@@ -377,8 +377,8 @@ static void dump_field(const struct scan_field *field)
377377

378378
log_printf_lf(LOG_LVL_DEBUG,
379379
__FILE__, __LINE__, "scan",
380-
"%db %s %08x @%02x -> %s %08x @%02x",
381-
field->num_bits,
380+
"%db %di %s %08x @%02x -> %s %08x @%02x",
381+
field->num_bits, idle,
382382
op_string[out_op], out_data, out_address,
383383
status_string[in_op], in_data, in_address);
384384

@@ -498,7 +498,7 @@ static dmi_status_t dmi_scan(struct target *target, uint32_t *address_in,
498498
if (address_in)
499499
*address_in = buf_get_u32(in, DTM_DMI_ADDRESS_OFFSET, info->abits);
500500

501-
dump_field(&field);
501+
dump_field(idle_count, &field);
502502

503503
return buf_get_u32(in, DTM_DMI_OP_OFFSET, DTM_DMI_OP_LENGTH);
504504
}
@@ -697,7 +697,24 @@ static int wait_for_idle(struct target *target, uint32_t *abstractcs)
697697
static int execute_abstract_command(struct target *target, uint32_t command)
698698
{
699699
RISCV013_INFO(info);
700-
LOG_DEBUG("command=0x%x", command);
700+
if (debug_level >= LOG_LVL_DEBUG) {
701+
switch (get_field(command, DMI_COMMAND_CMDTYPE)) {
702+
case 0:
703+
LOG_DEBUG("command=0x%x; access register, size=%d, postexec=%d, "
704+
"transfer=%d, write=%d, regno=0x%x",
705+
command,
706+
8 << get_field(command, AC_ACCESS_REGISTER_SIZE),
707+
get_field(command, AC_ACCESS_REGISTER_POSTEXEC),
708+
get_field(command, AC_ACCESS_REGISTER_TRANSFER),
709+
get_field(command, AC_ACCESS_REGISTER_WRITE),
710+
get_field(command, AC_ACCESS_REGISTER_REGNO));
711+
break;
712+
default:
713+
LOG_DEBUG("command=0x%x", command);
714+
break;
715+
}
716+
}
717+
701718
dmi_write(target, DMI_COMMAND, command);
702719

703720
uint32_t abstractcs = 0;
@@ -2326,6 +2343,8 @@ static int read_memory_progbuf(struct target *target, target_addr_t address,
23262343
uint8_t *buffer_i = buffer;
23272344

23282345
for (uint32_t i = 0; i < count; i++, address_i += size_i, buffer_i += size_i) {
2346+
/* TODO: This is much slower than it needs to be because we end up
2347+
* writing the address to read for every word we read. */
23292348
result = read_memory_progbuf_inner(target, address_i, size_i, count_i, buffer_i);
23302349

23312350
/* The read of a single word failed, so we will just return 0 for that instead */

0 commit comments

Comments
 (0)