aubinator: Add a new tool called Aubinator to the src/intel/tools folder.
The Aubinator tool is designed to help the driver developers in debugging the driver functionality by decoding the data in the .aub files. Primary Authors of this tool are Damien Lespiau <damien.lespiau at intel.com> and Kristian Høgsberg Kristensen <krh at bitplanet.net>. v2: Review comments are incorporated by Sirisha Gandikota as below: 1) Make Makefile.am more crisp, reuse intel_aub.h from libdrm (per Emil) 2) Aubinator will use platform name instead of GEN number (per Matt) 3) Disassmebler gets created based on pciid rather then GEN number (per Matt) 4) Other formatting comments (per Ken, Matt and Emil) Signed-off-by: Sirisha Gandikota <Sirisha.Gandikota@intel.com> Acked-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Ben Widawsky <ben@bwidawsk.net>
This commit is contained in:

committed by
Kenneth Graunke

parent
eb1a0ddfd5
commit
3e218ad7f8
@@ -2741,6 +2741,7 @@ AC_CONFIG_FILES([Makefile
|
||||
src/intel/Makefile
|
||||
src/intel/genxml/Makefile
|
||||
src/intel/isl/Makefile
|
||||
src/intel/tools/Makefile
|
||||
src/intel/vulkan/Makefile
|
||||
src/loader/Makefile
|
||||
src/mapi/Makefile
|
||||
|
@@ -83,6 +83,10 @@ if HAVE_EGL
|
||||
SUBDIRS += egl
|
||||
endif
|
||||
|
||||
if HAVE_INTEL_DRIVERS
|
||||
SUBDIRS += intel/tools
|
||||
endif
|
||||
|
||||
## Requires the i965 compiler (part of mesa) and wayland-drm
|
||||
if HAVE_INTEL_VULKAN
|
||||
SUBDIRS += intel/vulkan
|
||||
|
64
src/intel/tools/Makefile.am
Normal file
64
src/intel/tools/Makefile.am
Normal file
@@ -0,0 +1,64 @@
|
||||
# Copyright © 2016 Intel Corporation
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice (including the next
|
||||
# paragraph) shall be included in all copies or substantial portions of the
|
||||
# Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
# The gallium includes are for the util/u_math.h include from main/macros.h
|
||||
AM_CPPFLAGS = \
|
||||
$(INTEL_CFLAGS) \
|
||||
$(VALGRIND_CFLAGS) \
|
||||
$(DEFINES) \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/src \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src/mapi \
|
||||
-I$(top_srcdir)/src/mesa \
|
||||
-I$(top_srcdir)/src/mesa/drivers/dri/common \
|
||||
-I$(top_srcdir)/src/mesa/drivers/dri/i965 \
|
||||
-I$(top_srcdir)/src/gallium/auxiliary \
|
||||
-I$(top_srcdir)/src/gallium/include \
|
||||
-I$(top_builddir)/src/intel \
|
||||
-I$(top_srcdir)/src/intel
|
||||
|
||||
aubinator_DEPS = \
|
||||
$(top_builddir)/src/mesa/drivers/dri/i965/libi965_compiler.la \
|
||||
$(top_builddir)/src/util/libmesautil.la \
|
||||
$(PER_GEN_LIBS) \
|
||||
$(PTHREAD_LIBS) \
|
||||
$(DLOPEN_LIBS) \
|
||||
-lm
|
||||
|
||||
noinst_PROGRAMS = aubinator
|
||||
|
||||
aubinator_SOURCES = \
|
||||
aubinator.c \
|
||||
decoder.c \
|
||||
decoder.h \
|
||||
disasm.c \
|
||||
gen_disasm.h
|
||||
|
||||
aubinator_LDADD = \
|
||||
$(aubinator_DEPS) \
|
||||
$(EXPAT_LIBS)
|
||||
|
||||
aubinator_CFLAGS = \
|
||||
$(AM_CFLAGS) \
|
||||
$(EXPAT_CFLAGS) \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src
|
1066
src/intel/tools/aubinator.c
Normal file
1066
src/intel/tools/aubinator.c
Normal file
File diff suppressed because it is too large
Load Diff
518
src/intel/tools/decoder.c
Normal file
518
src/intel/tools/decoder.c
Normal file
@@ -0,0 +1,518 @@
|
||||
/*
|
||||
* Copyright © 2016 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <expat.h>
|
||||
|
||||
#include <util/macros.h>
|
||||
|
||||
#include "decoder.h"
|
||||
|
||||
#define XML_BUFFER_SIZE 4096
|
||||
|
||||
#define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) )
|
||||
|
||||
struct gen_spec {
|
||||
uint32_t gen;
|
||||
|
||||
int ncommands;
|
||||
struct gen_group *commands[256];
|
||||
int nstructs;
|
||||
struct gen_group *structs[256];
|
||||
int nregisters;
|
||||
struct gen_group *registers[256];
|
||||
};
|
||||
|
||||
struct gen_group {
|
||||
char *name;
|
||||
int nfields;
|
||||
struct gen_field **fields;
|
||||
|
||||
uint32_t opcode_mask;
|
||||
uint32_t opcode;
|
||||
};
|
||||
|
||||
struct gen_type {
|
||||
enum {
|
||||
GEN_TYPE_UNKNOWN,
|
||||
GEN_TYPE_INT,
|
||||
GEN_TYPE_UINT,
|
||||
GEN_TYPE_BOOL,
|
||||
GEN_TYPE_FLOAT,
|
||||
GEN_TYPE_ADDRESS,
|
||||
GEN_TYPE_OFFSET,
|
||||
GEN_TYPE_STRUCT,
|
||||
GEN_TYPE_UFIXED,
|
||||
GEN_TYPE_SFIXED,
|
||||
GEN_TYPE_MBO
|
||||
} kind;
|
||||
|
||||
/* Struct definition for GEN_TYPE_STRUCT */
|
||||
struct gen_group *gen_struct;
|
||||
|
||||
/* Integer and fractional sizes for GEN_TYPE_UFIXED and GEN_TYPE_SFIXED */
|
||||
int i, f;
|
||||
};
|
||||
|
||||
struct gen_field {
|
||||
char *name;
|
||||
int start, end;
|
||||
struct gen_type type;
|
||||
bool has_default;
|
||||
uint32_t default_value;
|
||||
};
|
||||
|
||||
struct location {
|
||||
const char *filename;
|
||||
int line_number;
|
||||
};
|
||||
|
||||
struct parser_context {
|
||||
XML_Parser parser;
|
||||
int foo;
|
||||
struct location loc;
|
||||
const char *platform;
|
||||
|
||||
struct gen_group *group;
|
||||
|
||||
int nfields;
|
||||
struct gen_field *fields[128];
|
||||
|
||||
struct gen_spec *spec;
|
||||
};
|
||||
|
||||
const char *
|
||||
gen_group_get_name(struct gen_group *group)
|
||||
{
|
||||
return group->name;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
gen_group_get_opcode(struct gen_group *group)
|
||||
{
|
||||
return group->opcode;
|
||||
}
|
||||
|
||||
struct gen_group *
|
||||
gen_spec_find_struct(struct gen_spec *spec, const char *name)
|
||||
{
|
||||
for (int i = 0; i < spec->nstructs; i++)
|
||||
if (strcmp(spec->structs[i]->name, name) == 0)
|
||||
return spec->structs[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
gen_spec_get_gen(struct gen_spec *spec)
|
||||
{
|
||||
return spec->gen;
|
||||
}
|
||||
|
||||
static void __attribute__((noreturn))
|
||||
fail(struct location *loc, const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, msg);
|
||||
fprintf(stderr, "%s:%d: error: ",
|
||||
loc->filename, loc->line_number);
|
||||
vfprintf(stderr, msg, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void *
|
||||
fail_on_null(void *p)
|
||||
{
|
||||
if (p == NULL) {
|
||||
fprintf(stderr, "aubinator: out of memory\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *
|
||||
xstrdup(const char *s)
|
||||
{
|
||||
return fail_on_null(strdup(s));
|
||||
}
|
||||
|
||||
static void *
|
||||
zalloc(size_t s)
|
||||
{
|
||||
return calloc(s, 1);
|
||||
}
|
||||
|
||||
static void *
|
||||
xzalloc(size_t s)
|
||||
{
|
||||
return fail_on_null(zalloc(s));
|
||||
}
|
||||
|
||||
static struct gen_group *
|
||||
create_group(struct parser_context *ctx, const char *name, const char **atts)
|
||||
{
|
||||
struct gen_group *group;
|
||||
|
||||
group = xzalloc(sizeof(*group));
|
||||
if (name)
|
||||
group->name = xstrdup(name);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
mask(int start, int end)
|
||||
{
|
||||
uint64_t v;
|
||||
|
||||
v = ~0ULL >> (63 - end + start);
|
||||
|
||||
return v << start;
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
field(uint64_t value, int start, int end)
|
||||
{
|
||||
return (value & mask(start, end)) >> start;
|
||||
}
|
||||
|
||||
static struct gen_type
|
||||
string_to_type(struct parser_context *ctx, const char *s)
|
||||
{
|
||||
int i, f;
|
||||
struct gen_group *g;
|
||||
|
||||
if (strcmp(s, "int") == 0)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_INT };
|
||||
else if (strcmp(s, "uint") == 0)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_UINT };
|
||||
else if (strcmp(s, "bool") == 0)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_BOOL };
|
||||
else if (strcmp(s, "float") == 0)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_FLOAT };
|
||||
else if (strcmp(s, "address") == 0)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_ADDRESS };
|
||||
else if (strcmp(s, "offset") == 0)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_OFFSET };
|
||||
else if (sscanf(s, "u%d.%d", &i, &f) == 2)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_UFIXED, .i = i, .f = f };
|
||||
else if (sscanf(s, "s%d.%d", &i, &f) == 2)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_SFIXED, .i = i, .f = f };
|
||||
else if (g = gen_spec_find_struct(ctx->spec, s), g != NULL)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_STRUCT, .gen_struct = g };
|
||||
else if (strcmp(s, "mbo") == 0)
|
||||
return (struct gen_type) { .kind = GEN_TYPE_MBO };
|
||||
else
|
||||
fail(&ctx->loc, "invalid type: %s", s);
|
||||
}
|
||||
|
||||
static struct gen_field *
|
||||
create_field(struct parser_context *ctx, const char **atts)
|
||||
{
|
||||
struct gen_field *field;
|
||||
char *p;
|
||||
int i;
|
||||
|
||||
field = xzalloc(sizeof(*field));
|
||||
|
||||
for (i = 0; atts[i]; i += 2) {
|
||||
if (strcmp(atts[i], "name") == 0)
|
||||
field->name = xstrdup(atts[i + 1]);
|
||||
else if (strcmp(atts[i], "start") == 0)
|
||||
field->start = strtoul(atts[i + 1], &p, 0);
|
||||
else if (strcmp(atts[i], "end") == 0)
|
||||
field->end = strtoul(atts[i + 1], &p, 0);
|
||||
else if (strcmp(atts[i], "type") == 0)
|
||||
field->type = string_to_type(ctx, atts[i + 1]);
|
||||
else if (strcmp(atts[i], "default") == 0 &&
|
||||
field->start >= 16 && field->end <= 31) {
|
||||
field->has_default = true;
|
||||
field->default_value = strtoul(atts[i + 1], &p, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
static void
|
||||
start_element(void *data, const char *element_name, const char **atts)
|
||||
{
|
||||
struct parser_context *ctx = data;
|
||||
int i;
|
||||
const char *name = NULL;
|
||||
const char *gen = NULL;
|
||||
|
||||
ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser);
|
||||
|
||||
for (i = 0; atts[i]; i += 2) {
|
||||
if (strcmp(atts[i], "name") == 0)
|
||||
name = atts[i + 1];
|
||||
else if (strcmp(atts[i], "gen") == 0)
|
||||
gen = atts[i + 1];
|
||||
}
|
||||
|
||||
if (strcmp(element_name, "genxml") == 0) {
|
||||
if (name == NULL)
|
||||
fail(&ctx->loc, "no platform name given");
|
||||
if (gen == NULL)
|
||||
fail(&ctx->loc, "no gen given");
|
||||
|
||||
ctx->platform = xstrdup(name);
|
||||
int major, minor;
|
||||
int n = sscanf(gen, "%d.%d", &major, &minor);
|
||||
if (n == 0)
|
||||
fail(&ctx->loc, "invalid gen given: %s", gen);
|
||||
if (n == 1)
|
||||
minor = 0;
|
||||
|
||||
ctx->spec->gen = MAKE_GEN(major, minor);
|
||||
} else if (strcmp(element_name, "instruction") == 0 ||
|
||||
strcmp(element_name, "struct") == 0 ||
|
||||
strcmp(element_name, "register") == 0) {
|
||||
ctx->group = create_group(ctx, name, atts);
|
||||
} else if (strcmp(element_name, "group") == 0) {
|
||||
} else if (strcmp(element_name, "field") == 0) {
|
||||
ctx->fields[ctx->nfields++] = create_field(ctx, atts);
|
||||
} else if (strcmp(element_name, "enum") == 0) {
|
||||
} else if (strcmp(element_name, "value") == 0) {
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
end_element(void *data, const char *name)
|
||||
{
|
||||
struct parser_context *ctx = data;
|
||||
|
||||
if (strcmp(name, "instruction") == 0 ||
|
||||
strcmp(name, "struct") == 0 ||
|
||||
strcmp(name, "register") == 0) {
|
||||
size_t size = ctx->nfields * sizeof(ctx->fields[0]);
|
||||
struct gen_group *group = ctx->group;
|
||||
|
||||
group->fields = xzalloc(size);
|
||||
group->nfields = ctx->nfields;
|
||||
memcpy(group->fields, ctx->fields, size);
|
||||
ctx->nfields = 0;
|
||||
ctx->group = NULL;
|
||||
|
||||
for (int i = 0; i < group->nfields; i++) {
|
||||
if (group->fields[i]->start >= 16 &&
|
||||
group->fields[i]->end <= 31 &&
|
||||
group->fields[i]->has_default) {
|
||||
group->opcode_mask |=
|
||||
mask(group->fields[i]->start, group->fields[i]->end);
|
||||
group->opcode |=
|
||||
group->fields[i]->default_value << group->fields[i]->start;
|
||||
}
|
||||
}
|
||||
|
||||
struct gen_spec *spec = ctx->spec;
|
||||
if (strcmp(name, "instruction") == 0)
|
||||
spec->commands[spec->ncommands++] = group;
|
||||
else if (strcmp(name, "struct") == 0)
|
||||
spec->structs[spec->nstructs++] = group;
|
||||
else if (strcmp(name, "register") == 0)
|
||||
spec->registers[spec->nregisters++] = group;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
character_data(void *data, const XML_Char *s, int len)
|
||||
{
|
||||
}
|
||||
|
||||
struct gen_spec *
|
||||
gen_spec_load(const char *filename)
|
||||
{
|
||||
struct parser_context ctx;
|
||||
void *buf;
|
||||
int len;
|
||||
FILE *input;
|
||||
|
||||
input = fopen(filename, "r");
|
||||
printf("xml filename = %s\n", filename);
|
||||
if (input == NULL) {
|
||||
fprintf(stderr, "failed to open xml description\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
memset(&ctx, 0, sizeof ctx);
|
||||
ctx.parser = XML_ParserCreate(NULL);
|
||||
XML_SetUserData(ctx.parser, &ctx);
|
||||
if (ctx.parser == NULL) {
|
||||
fprintf(stderr, "failed to create parser\n");
|
||||
fclose(input);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XML_SetElementHandler(ctx.parser, start_element, end_element);
|
||||
XML_SetCharacterDataHandler(ctx.parser, character_data);
|
||||
ctx.loc.filename = filename;
|
||||
|
||||
ctx.spec = xzalloc(sizeof(*ctx.spec));
|
||||
|
||||
do {
|
||||
buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);
|
||||
len = fread(buf, 1, XML_BUFFER_SIZE, input);
|
||||
if (len < 0) {
|
||||
fprintf(stderr, "fread: %m\n");
|
||||
fclose(input);
|
||||
return NULL;
|
||||
}
|
||||
if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
|
||||
fprintf(stderr,
|
||||
"Error parsing XML at line %ld col %ld: %s\n",
|
||||
XML_GetCurrentLineNumber(ctx.parser),
|
||||
XML_GetCurrentColumnNumber(ctx.parser),
|
||||
XML_ErrorString(XML_GetErrorCode(ctx.parser)));
|
||||
fclose(input);
|
||||
return NULL;
|
||||
}
|
||||
} while (len > 0);
|
||||
|
||||
XML_ParserFree(ctx.parser);
|
||||
fclose(input);
|
||||
|
||||
return ctx.spec;
|
||||
}
|
||||
|
||||
struct gen_group *
|
||||
gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p)
|
||||
{
|
||||
/* FIXME: Make sure the opcodes put out are correct */
|
||||
for (int i = 0; i < spec->ncommands; i++) {
|
||||
uint32_t opcode = *p & spec->commands[i]->opcode_mask;
|
||||
if (opcode == spec->commands[i]->opcode)
|
||||
return spec->commands[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
gen_group_get_length(struct gen_group *group, const uint32_t *p)
|
||||
{
|
||||
uint32_t h = p[0];
|
||||
uint32_t type = field(h, 29, 31);
|
||||
|
||||
switch (type) {
|
||||
case 0: /* MI */ {
|
||||
uint32_t opcode = field(h, 23, 28);
|
||||
if (opcode < 16)
|
||||
return 1;
|
||||
else
|
||||
return field(h, 0, 7) + 2;
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: /* Render */ {
|
||||
uint32_t subtype = field(h, 27, 28);
|
||||
switch (subtype) {
|
||||
case 0:
|
||||
return field(h, 0, 7) + 2;
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
case 3:
|
||||
return field(h, 0, 7) + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unreachable("bad opcode");
|
||||
}
|
||||
|
||||
void
|
||||
gen_field_iterator_init(struct gen_field_iterator *iter,
|
||||
struct gen_group *group, const uint32_t *p)
|
||||
{
|
||||
iter->group = group;
|
||||
iter->p = p;
|
||||
iter->i = 0;
|
||||
}
|
||||
|
||||
bool
|
||||
gen_field_iterator_next(struct gen_field_iterator *iter)
|
||||
{
|
||||
struct gen_field *f;
|
||||
union {
|
||||
uint32_t dw;
|
||||
float f;
|
||||
} v;
|
||||
|
||||
if (iter->i == iter->group->nfields)
|
||||
return false;
|
||||
|
||||
f = iter->group->fields[iter->i++];
|
||||
iter->name = f->name;
|
||||
v.dw = iter->p[f->start / 32];
|
||||
switch (f->type.kind) {
|
||||
case GEN_TYPE_UNKNOWN:
|
||||
case GEN_TYPE_INT:
|
||||
snprintf(iter->value, sizeof(iter->value),
|
||||
"%ld", field(v.dw, f->start, f->end));
|
||||
break;
|
||||
case GEN_TYPE_UINT:
|
||||
snprintf(iter->value, sizeof(iter->value),
|
||||
"%lu", field(v.dw, f->start, f->end));
|
||||
break;
|
||||
case GEN_TYPE_BOOL:
|
||||
snprintf(iter->value, sizeof(iter->value),
|
||||
"%s", field(v.dw, f->start, f->end) ? "true" : "false");
|
||||
break;
|
||||
case GEN_TYPE_FLOAT:
|
||||
snprintf(iter->value, sizeof(iter->value), "%f", v.f);
|
||||
break;
|
||||
case GEN_TYPE_ADDRESS:
|
||||
case GEN_TYPE_OFFSET:
|
||||
snprintf(iter->value, sizeof(iter->value),
|
||||
"0x%08lx", field(v.dw, f->start, f->end));
|
||||
break;
|
||||
case GEN_TYPE_STRUCT:
|
||||
/* FIXME: Make iterator decode the struct recursively */
|
||||
snprintf(iter->value, sizeof(iter->value),
|
||||
"<struct %s>", f->type.gen_struct->name);
|
||||
break;
|
||||
case GEN_TYPE_UFIXED:
|
||||
snprintf(iter->value, sizeof(iter->value),
|
||||
"%f", (float) field(v.dw, f->start, f->end) / (1 << f->type.f));
|
||||
break;
|
||||
case GEN_TYPE_SFIXED:
|
||||
/* FIXME: Sign extend extracted field. */
|
||||
snprintf(iter->value, sizeof(iter->value), "%s", "foo");
|
||||
break;
|
||||
case GEN_TYPE_MBO:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
57
src/intel/tools/decoder.h
Normal file
57
src/intel/tools/decoder.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright © 2016 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct gen_spec;
|
||||
struct gen_group;
|
||||
struct gen_field;
|
||||
|
||||
static inline uint32_t gen_make_gen(uint32_t major, uint32_t minor)
|
||||
{
|
||||
return (major << 8) | minor;
|
||||
}
|
||||
|
||||
struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name);
|
||||
struct gen_spec *gen_spec_load(const char *filename);
|
||||
uint32_t gen_spec_get_gen(struct gen_spec *spec);
|
||||
struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p);
|
||||
int gen_group_get_length(struct gen_group *group, const uint32_t *p);
|
||||
const char *gen_group_get_name(struct gen_group *group);
|
||||
uint32_t gen_group_get_opcode(struct gen_group *group);
|
||||
|
||||
struct gen_field_iterator {
|
||||
struct gen_group *group;
|
||||
const char *name;
|
||||
char value[128];
|
||||
uint32_t *p;
|
||||
int i;
|
||||
};
|
||||
|
||||
void gen_field_iterator_init(struct gen_field_iterator *iter,
|
||||
struct gen_group *group, const uint32_t *p);
|
||||
|
||||
bool gen_field_iterator_next(struct gen_field_iterator *iter);
|
111
src/intel/tools/disasm.c
Normal file
111
src/intel/tools/disasm.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright © 2014 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "brw_context.h"
|
||||
#include "brw_inst.h"
|
||||
#include "brw_eu.h"
|
||||
|
||||
#include "gen_disasm.h"
|
||||
|
||||
uint64_t INTEL_DEBUG;
|
||||
|
||||
struct gen_disasm {
|
||||
struct brw_device_info devinfo;
|
||||
};
|
||||
|
||||
void
|
||||
gen_disasm_disassemble(struct gen_disasm *disasm, void *assembly, int start, int end, FILE *out)
|
||||
{
|
||||
struct brw_device_info *devinfo = &disasm->devinfo;
|
||||
bool dump_hex = false;
|
||||
|
||||
for (int offset = start; offset < end;) {
|
||||
brw_inst *insn = assembly + offset;
|
||||
brw_inst uncompacted;
|
||||
bool compacted = brw_inst_cmpt_control(devinfo, insn);
|
||||
if (0)
|
||||
fprintf(out, "0x%08x: ", offset);
|
||||
|
||||
if (compacted) {
|
||||
brw_compact_inst *compacted = (void *)insn;
|
||||
if (dump_hex) {
|
||||
fprintf(out, "0x%08x 0x%08x ",
|
||||
((uint32_t *)insn)[1],
|
||||
((uint32_t *)insn)[0]);
|
||||
}
|
||||
|
||||
brw_uncompact_instruction(devinfo, &uncompacted, compacted);
|
||||
insn = &uncompacted;
|
||||
offset += 8;
|
||||
} else {
|
||||
if (dump_hex) {
|
||||
fprintf(out, "0x%08x 0x%08x 0x%08x 0x%08x ",
|
||||
((uint32_t *)insn)[3],
|
||||
((uint32_t *)insn)[2],
|
||||
((uint32_t *)insn)[1],
|
||||
((uint32_t *)insn)[0]);
|
||||
}
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
brw_disassemble_inst(out, devinfo, insn, compacted);
|
||||
|
||||
/* Simplistic, but efficient way to terminate disasm */
|
||||
if (brw_inst_opcode(devinfo, insn) == BRW_OPCODE_SEND ||
|
||||
brw_inst_opcode(devinfo, insn) == BRW_OPCODE_SENDC)
|
||||
if (brw_inst_eot(devinfo, insn))
|
||||
break;
|
||||
if (brw_inst_opcode(devinfo, insn) == 0)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct gen_disasm *
|
||||
gen_disasm_create(int pciid)
|
||||
{
|
||||
struct gen_disasm *gd;
|
||||
const struct brw_device_info *dev_info = NULL;
|
||||
|
||||
gd = malloc(sizeof *gd);
|
||||
if (gd == NULL)
|
||||
return NULL;
|
||||
|
||||
dev_info = brw_get_device_info(pciid);
|
||||
|
||||
gd->devinfo.gen = dev_info->gen;
|
||||
gd->devinfo.is_cherryview = dev_info->is_cherryview;
|
||||
gd->devinfo.is_g4x = dev_info->is_g4x;
|
||||
|
||||
brw_init_compaction_tables(&gd->devinfo);
|
||||
|
||||
return gd;
|
||||
}
|
||||
|
||||
void
|
||||
gen_disasm_destroy(struct gen_disasm *disasm)
|
||||
{
|
||||
free(disasm);
|
||||
}
|
35
src/intel/tools/gen_disasm.h
Normal file
35
src/intel/tools/gen_disasm.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright © 2014 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef GEN_DISASM_H
|
||||
#define GEN_DISASM_H
|
||||
|
||||
struct gen_disasm;
|
||||
|
||||
struct gen_disasm *gen_disasm_create(int pciid);
|
||||
void gen_disasm_disassemble(struct gen_disasm *disasm,
|
||||
void *assembly, int start, int end, FILE *out);
|
||||
|
||||
void gen_disasm_destroy(struct gen_disasm *disasm);
|
||||
|
||||
#endif /* GEN_DISASM_H */
|
Reference in New Issue
Block a user