Skip to content

Commit

Permalink
target/riscv: dump_field() shouldn't always decode
Browse files Browse the repository at this point in the history
Sometimes, the value from of some DMI scans has no meaning (e.g. when
`op` is read). Such values should not be decoded.

Change-Id: I415f06a5a80f2fc8fb8ab3f79132bdf0602c8ad6
Signed-off-by: Evgeniy Naydanov <[email protected]>
  • Loading branch information
en-sc committed Nov 7, 2023
1 parent 585f5db commit 3f11a27
Showing 1 changed file with 48 additions and 12 deletions.
60 changes: 48 additions & 12 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,36 @@ static unsigned int decode_dm(char *text, unsigned int address, unsigned int dat
unsigned int address;
enum riscv_debug_reg_ordinal ordinal;
} description[] = {
{DM_DMCONTROL, DM_DMCONTROL_ORDINAL},
{DM_DMSTATUS, DM_DMSTATUS_ORDINAL},
{DM_DMCONTROL, DM_DMCONTROL_ORDINAL},
{DM_HARTINFO, DM_HARTINFO_ORDINAL},
{DM_HAWINDOWSEL, DM_HAWINDOWSEL_ORDINAL},
{DM_HAWINDOW, DM_HAWINDOW_ORDINAL},
{DM_ABSTRACTCS, DM_ABSTRACTCS_ORDINAL},
{DM_COMMAND, DM_COMMAND_ORDINAL},
{DM_SBCS, DM_SBCS_ORDINAL}
{DM_ABSTRACTAUTO, DM_ABSTRACTAUTO_ORDINAL},
{DM_CONFSTRPTR0, DM_CONFSTRPTR0_ORDINAL},
{DM_CONFSTRPTR1, DM_CONFSTRPTR1_ORDINAL},
{DM_CONFSTRPTR2, DM_CONFSTRPTR2_ORDINAL},
{DM_CONFSTRPTR3, DM_CONFSTRPTR3_ORDINAL},
{DM_NEXTDM, DM_NEXTDM_ORDINAL},
{DM_DATA0, DM_DATA0_ORDINAL},
{DM_PROGBUF0, DM_PROGBUF0_ORDINAL},
{DM_AUTHDATA, DM_AUTHDATA_ORDINAL},
{DM_DMCS2, DM_DMCS2_ORDINAL},
{DM_HALTSUM0, DM_HALTSUM0_ORDINAL},
{DM_HALTSUM1, DM_HALTSUM1_ORDINAL},
{DM_HALTSUM2, DM_HALTSUM2_ORDINAL},
{DM_HALTSUM3, DM_HALTSUM3_ORDINAL},
{DM_SBCS, DM_SBCS_ORDINAL},
{DM_SBADDRESS0, DM_SBADDRESS0_ORDINAL},
{DM_SBADDRESS1, DM_SBADDRESS1_ORDINAL},
{DM_SBADDRESS2, DM_SBADDRESS2_ORDINAL},
{DM_SBADDRESS3, DM_SBADDRESS3_ORDINAL},
{DM_SBDATA0, DM_SBDATA0_ORDINAL},
{DM_SBDATA1, DM_SBDATA1_ORDINAL},
{DM_SBDATA2, DM_SBDATA2_ORDINAL},
{DM_SBDATA3, DM_SBDATA2_ORDINAL}
};

for (unsigned i = 0; i < ARRAY_SIZE(description); i++) {
Expand Down Expand Up @@ -371,7 +396,7 @@ static unsigned int decode_dmi(struct target *target, char *text, unsigned int a
return decode_dm(text, address - dm->base, data);
}

static void dump_field(struct target *target, int idle, const struct scan_field *field)
static void dump_field(struct target *target, int idle, const struct scan_field *field, bool decode_in)
{
static const char * const op_string[] = {"-", "r", "w", "?"};
static const char * const status_string[] = {"+", "?", "F", "b"};
Expand All @@ -390,18 +415,29 @@ static void dump_field(struct target *target, int idle, const struct scan_field
unsigned int in_address = in >> DTM_DMI_ADDRESS_OFFSET;

log_printf_lf(LOG_LVL_DEBUG,
__FILE__, __LINE__, "scan",
__FILE__, __LINE__, __PRETTY_FUNCTION__,
"%db %s %08x @%02x -> %s %08x @%02x; %di",
field->num_bits, op_string[out_op], out_data, out_address,
status_string[in_op], in_data, in_address, idle);

char out_text[decode_dmi(target, NULL, out_address, out_data) + 1];
unsigned int out_len = decode_dmi(target, out_text, out_address, out_data);
char in_text[decode_dmi(target, NULL, in_address, in_data) + 1];
unsigned int in_len = decode_dmi(target, in_text, in_address, in_data);
if (in_text[0] || out_text[0]) {
log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, "scan", "%.*s -> %.*s",
out_len, out_text, in_len, in_text);
const bool decode_out = out_op == DTM_DMI_OP_WRITE;
char out_decoded[decode_dmi(target, NULL, out_address, out_data) + 1];
const char *out_text = "";
if (decode_out)
out_text = decode_dmi(target, out_decoded, out_address, out_data)
? out_decoded
: "<no decoding available>";

char in_decoded[decode_dmi(target, NULL, in_address, in_data) + 1];
const char *in_text = "";
if (decode_in)
in_text = decode_dmi(target, in_decoded, in_address, in_data)
? in_decoded
: "<no decoding available>";

if (decode_out || decode_in) {
log_printf_lf(LOG_LVL_DEBUG, __FILE__, __LINE__, __PRETTY_FUNCTION__,
"%s -> %s", out_text, in_text);
}
}

Expand Down Expand Up @@ -542,7 +578,7 @@ static dmi_status_t dmi_scan(struct target *target, uint32_t *address_in,

if (address_in)
*address_in = buf_get_u32(in, DTM_DMI_ADDRESS_OFFSET, info->abits);
dump_field(target, idle_count, &field);
dump_field(target, idle_count, &field, /*decode_in*/ data_in);
return buf_get_u32(in, DTM_DMI_OP_OFFSET, DTM_DMI_OP_LENGTH);
}

Expand Down

0 comments on commit 3f11a27

Please sign in to comment.