aubinator: Add a new tool called Aubinator to the src/intel/tools folder.
[mesa.git] / src / intel / tools / disasm.c
1 /*
2 * Copyright © 2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <stdlib.h>
25
26 #include "brw_context.h"
27 #include "brw_inst.h"
28 #include "brw_eu.h"
29
30 #include "gen_disasm.h"
31
32 uint64_t INTEL_DEBUG;
33
34 struct gen_disasm {
35 struct brw_device_info devinfo;
36 };
37
38 void
39 gen_disasm_disassemble(struct gen_disasm *disasm, void *assembly, int start, int end, FILE *out)
40 {
41 struct brw_device_info *devinfo = &disasm->devinfo;
42 bool dump_hex = false;
43
44 for (int offset = start; offset < end;) {
45 brw_inst *insn = assembly + offset;
46 brw_inst uncompacted;
47 bool compacted = brw_inst_cmpt_control(devinfo, insn);
48 if (0)
49 fprintf(out, "0x%08x: ", offset);
50
51 if (compacted) {
52 brw_compact_inst *compacted = (void *)insn;
53 if (dump_hex) {
54 fprintf(out, "0x%08x 0x%08x ",
55 ((uint32_t *)insn)[1],
56 ((uint32_t *)insn)[0]);
57 }
58
59 brw_uncompact_instruction(devinfo, &uncompacted, compacted);
60 insn = &uncompacted;
61 offset += 8;
62 } else {
63 if (dump_hex) {
64 fprintf(out, "0x%08x 0x%08x 0x%08x 0x%08x ",
65 ((uint32_t *)insn)[3],
66 ((uint32_t *)insn)[2],
67 ((uint32_t *)insn)[1],
68 ((uint32_t *)insn)[0]);
69 }
70 offset += 16;
71 }
72
73 brw_disassemble_inst(out, devinfo, insn, compacted);
74
75 /* Simplistic, but efficient way to terminate disasm */
76 if (brw_inst_opcode(devinfo, insn) == BRW_OPCODE_SEND ||
77 brw_inst_opcode(devinfo, insn) == BRW_OPCODE_SENDC)
78 if (brw_inst_eot(devinfo, insn))
79 break;
80 if (brw_inst_opcode(devinfo, insn) == 0)
81 break;
82
83 }
84 }
85
86 struct gen_disasm *
87 gen_disasm_create(int pciid)
88 {
89 struct gen_disasm *gd;
90 const struct brw_device_info *dev_info = NULL;
91
92 gd = malloc(sizeof *gd);
93 if (gd == NULL)
94 return NULL;
95
96 dev_info = brw_get_device_info(pciid);
97
98 gd->devinfo.gen = dev_info->gen;
99 gd->devinfo.is_cherryview = dev_info->is_cherryview;
100 gd->devinfo.is_g4x = dev_info->is_g4x;
101
102 brw_init_compaction_tables(&gd->devinfo);
103
104 return gd;
105 }
106
107 void
108 gen_disasm_destroy(struct gen_disasm *disasm)
109 {
110 free(disasm);
111 }