2 * Copyright © 2008 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
31 #include "gen8_instruction.h"
33 static const struct option longopts[] = {
37 static struct brw_program *
38 read_program (FILE *input)
41 struct brw_program *program;
42 struct brw_program_instruction *entry, **prev;
46 program = malloc (sizeof (struct brw_program));
47 program->first = NULL;
48 prev = &program->first;
49 while ((c = getc (input)) != EOF) {
51 if (fscanf (input, "x%x", &inst[n]) == 1) {
54 entry = malloc (sizeof (struct brw_program_instruction));
55 memcpy (&entry->insn, inst, 4 * sizeof (uint32_t));
67 static struct brw_program *
68 read_program_binary (FILE *input)
72 struct brw_program *program;
73 struct brw_program_instruction *entry, **prev;
77 program = malloc (sizeof (struct brw_program));
78 program->first = NULL;
79 prev = &program->first;
80 while ((c = getc (input)) != EOF) {
82 if (fscanf (input, "x%2x", &temp) == 1) {
83 inst[n++] = (uint8_t)temp;
85 entry = malloc (sizeof (struct brw_program_instruction));
86 memcpy (&entry->insn, inst, 16 * sizeof (uint8_t));
98 static void usage(void)
100 fprintf(stderr, "usage: intel-gen4disasm [options] inputfile\n");
101 fprintf(stderr, "\t-b, --binary C style binary output\n");
102 fprintf(stderr, "\t-o, --output {outputfile} Specify output file\n");
103 fprintf(stderr, "\t-g, --gen <4|5|6|7|8> Specify GPU generation\n");
106 int main(int argc, char **argv)
108 struct brw_program *program;
110 FILE *output = stdout;
111 char *input_filename = NULL;
112 char *output_file = NULL;
113 int byte_array_input = 0;
116 struct brw_program_instruction *inst;
118 while ((o = getopt_long(argc, argv, "o:bg:", longopts, NULL)) != -1) {
121 if (strcmp(optarg, "-") != 0)
122 output_file = optarg;
125 byte_array_input = 1;
128 gen = strtol(optarg, NULL, 10);
130 if (gen < 4 || gen > 8) {
148 if (strcmp(argv[0], "-") != 0) {
149 input_filename = argv[0];
150 input = fopen(input_filename, "r");
152 perror("Couldn't open input file");
156 if (byte_array_input)
157 program = read_program_binary (input);
159 program = read_program (input);
163 output = fopen (output_file, "w");
164 if (output == NULL) {
165 perror("Couldn't open output file");
170 for (inst = program->first; inst; inst = inst->next)
172 gen8_disassemble(output, &inst->insn.gen8, gen);
174 brw_disasm (output, &inst->insn.gen, gen);