return (struct v3d_type) { .kind = V3D_TYPE_BOOL };
else if (strcmp(s, "float") == 0)
return (struct v3d_type) { .kind = V3D_TYPE_FLOAT };
+ else if (strcmp(s, "f187") == 0)
+ return (struct v3d_type) { .kind = V3D_TYPE_F187 };
else if (strcmp(s, "address") == 0)
return (struct v3d_type) { .kind = V3D_TYPE_ADDRESS };
else if (strcmp(s, "offset") == 0)
ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser);
for (i = 0; atts[i]; i += 2) {
- if (strcmp(atts[i], "name") == 0)
+ if (strcmp(atts[i], "shortname") == 0)
+ name = atts[i + 1];
+ else if (strcmp(atts[i], "name") == 0 && !name)
name = atts[i + 1];
else if (strcmp(atts[i], "gen") == 0)
ver = atts[i + 1];
ctx->parse_depth++;
}
+static int
+field_offset_compare(const void *a, const void *b)
+{
+ return ((*(const struct v3d_field **)a)->start -
+ (*(const struct v3d_field **)b)->start);
+}
+
static void
end_element(void *data, const char *name)
{
else if (strcmp(name, "register") == 0)
spec->registers[spec->nregisters++] = group;
+ /* Sort the fields in increasing offset order. The XML might
+ * be specified in any order, but we'll want to iterate from
+ * the bottom.
+ */
+ qsort(group->fields, group->nfields, sizeof(*group->fields),
+ field_offset_compare);
+
assert(spec->ncommands < ARRAY_SIZE(spec->commands));
assert(spec->nstructs < ARRAY_SIZE(spec->structs));
assert(spec->nregisters < ARRAY_SIZE(spec->registers));
struct parser_context ctx;
void *buf;
uint8_t *text_data = NULL;
- uint32_t text_offset = 0, text_length = 0, total_length;
+ uint32_t text_offset = 0, text_length = 0;
+ ASSERTED uint32_t total_length;
for (int i = 0; i < ARRAY_SIZE(genxml_files_table); i++) {
if (i != 0) {
void
v3d_field_iterator_init(struct v3d_field_iterator *iter,
struct v3d_group *group,
- const uint8_t *p,
- bool print_colors)
+ const uint8_t *p)
{
memset(iter, 0, sizeof(*iter));
iter->group = group;
iter->p = p;
- iter->print_colors = print_colors;
}
static const char *
iter->field = iter->group->fields[iter->field_iter++];
if (iter->field->name)
- strncpy(iter->name, iter->field->name, sizeof(iter->name));
+ snprintf(iter->name, sizeof(iter->name), "%s", iter->field->name);
else
memset(iter->name, 0, sizeof(iter->name));
iter->offset = iter_group_offset_bits(iter, iter->group_iter) / 8 +
}
bool
-v3d_field_iterator_next(struct v3d_field_iterator *iter)
+v3d_field_iterator_next(struct clif_dump *clif, struct v3d_field_iterator *iter)
{
if (!iter_advance_field(iter))
return false;
enum_name = v3d_get_enum_name(&iter->field->inline_enum, value);
break;
}
- case V3D_TYPE_BOOL: {
- const char *true_string =
- iter->print_colors ? "\e[0;35mtrue\e[0m" : "true";
+ case V3D_TYPE_BOOL:
snprintf(iter->value, sizeof(iter->value), "%s",
__gen_unpack_uint(iter->p, s, e) ?
- true_string : "false");
+ "1 /* true */" : "0 /* false */");
break;
- }
case V3D_TYPE_FLOAT:
snprintf(iter->value, sizeof(iter->value), "%f",
__gen_unpack_float(iter->p, s, e));
break;
- case V3D_TYPE_ADDRESS:
+
+ case V3D_TYPE_F187:
+ snprintf(iter->value, sizeof(iter->value), "%f",
+ __gen_unpack_f187(iter->p, s, e));
+ break;
+
+ case V3D_TYPE_ADDRESS: {
+ uint32_t addr =
+ __gen_unpack_uint(iter->p, s, e) << (31 - (e - s));
+ struct clif_bo *bo = clif_lookup_bo(clif, addr);
+ if (bo) {
+ snprintf(iter->value, sizeof(iter->value),
+ "[%s+0x%08x] /* 0x%08x */",
+ bo->name, addr - bo->offset, addr);
+ } else if (addr) {
+ snprintf(iter->value, sizeof(iter->value),
+ "/* XXX: BO unknown */ 0x%08x", addr);
+ } else {
+ snprintf(iter->value, sizeof(iter->value),
+ "[null]");
+ }
+
+ break;
+ }
+
case V3D_TYPE_OFFSET:
snprintf(iter->value, sizeof(iter->value), "0x%08"PRIx64,
__gen_unpack_uint(iter->p, s, e) << (31 - (e - s)));
iter->field->type.v3d_struct->name);
break;
case V3D_TYPE_SFIXED:
- snprintf(iter->value, sizeof(iter->value), "%f",
- __gen_unpack_sfixed(iter->p, s, e,
- iter->field->type.f));
+ if (clif->pretty) {
+ snprintf(iter->value, sizeof(iter->value), "%f",
+ __gen_unpack_sfixed(iter->p, s, e,
+ iter->field->type.f));
+ } else {
+ snprintf(iter->value, sizeof(iter->value), "%u",
+ (unsigned)__gen_unpack_uint(iter->p, s, e));
+ }
break;
case V3D_TYPE_UFIXED:
- snprintf(iter->value, sizeof(iter->value), "%f",
- __gen_unpack_ufixed(iter->p, s, e,
- iter->field->type.f));
+ if (clif->pretty) {
+ snprintf(iter->value, sizeof(iter->value), "%f",
+ __gen_unpack_ufixed(iter->p, s, e,
+ iter->field->type.f));
+ } else {
+ snprintf(iter->value, sizeof(iter->value), "%u",
+ (unsigned)__gen_unpack_uint(iter->p, s, e));
+ }
break;
case V3D_TYPE_MBO:
break;
void
v3d_print_group(struct clif_dump *clif, struct v3d_group *group,
- uint64_t offset, const uint8_t *p, bool color)
+ uint64_t offset, const uint8_t *p)
{
struct v3d_field_iterator iter;
- v3d_field_iterator_init(&iter, group, p, color);
- while (v3d_field_iterator_next(&iter)) {
- fprintf(clif->out, " %s: %s\n", iter.name, iter.value);
+ v3d_field_iterator_init(&iter, group, p);
+ while (v3d_field_iterator_next(clif, &iter)) {
+ /* Clif parsing uses the packet name, and expects no
+ * sub-id.
+ */
+ if (strcmp(iter.field->name, "sub-id") == 0 ||
+ strcmp(iter.field->name, "unused") == 0 ||
+ strcmp(iter.field->name, "Pad") == 0)
+ continue;
+
+ if (clif->pretty) {
+ fprintf(clif->out, " %s: %s\n",
+ iter.name, iter.value);
+ } else {
+ fprintf(clif->out, " /* %30s: */ %s\n",
+ iter.name, iter.value);
+ }
if (iter.struct_desc) {
uint64_t struct_offset = offset + iter.offset;
v3d_print_group(clif, iter.struct_desc,
struct_offset,
- &p[iter.offset], color);
+ &p[iter.offset]);
}
}
}