aubinator: Style fixes.
[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,
40 int end, FILE *out)
41 {
42 struct brw_device_info *devinfo = &disasm->devinfo;
43 bool dump_hex = false;
44
45 for (int offset = start; offset < end;) {
46 brw_inst *insn = assembly + offset;
47 brw_inst uncompacted;
48 bool compacted = brw_inst_cmpt_control(devinfo, insn);
49 if (0)
50 fprintf(out, "0x%08x: ", offset);
51
52 if (compacted) {
53 brw_compact_inst *compacted = (void *)insn;
54 if (dump_hex) {
55 fprintf(out, "0x%08x 0x%08x ",
56 ((uint32_t *)insn)[1],
57 ((uint32_t *)insn)[0]);
58 }
59
60 brw_uncompact_instruction(devinfo, &uncompacted, compacted);
61 insn = &uncompacted;
62 offset += 8;
63 } else {
64 if (dump_hex) {
65 fprintf(out, "0x%08x 0x%08x 0x%08x 0x%08x ",
66 ((uint32_t *)insn)[3],
67 ((uint32_t *)insn)[2],
68 ((uint32_t *)insn)[1],
69 ((uint32_t *)insn)[0]);
70 }
71 offset += 16;
72 }
73
74 brw_disassemble_inst(out, devinfo, insn, compacted);
75
76 /* Simplistic, but efficient way to terminate disasm */
77 if (brw_inst_opcode(devinfo, insn) == BRW_OPCODE_SEND ||
78 brw_inst_opcode(devinfo, insn) == BRW_OPCODE_SENDC)
79 if (brw_inst_eot(devinfo, insn))
80 break;
81 if (brw_inst_opcode(devinfo, insn) == 0)
82 break;
83
84 }
85 }
86
87 struct gen_disasm *
88 gen_disasm_create(int pciid)
89 {
90 struct gen_disasm *gd;
91 const struct brw_device_info *dev_info = NULL;
92
93 gd = malloc(sizeof *gd);
94 if (gd == NULL)
95 return NULL;
96
97 dev_info = brw_get_device_info(pciid);
98
99 gd->devinfo.gen = dev_info->gen;
100 gd->devinfo.is_cherryview = dev_info->is_cherryview;
101 gd->devinfo.is_g4x = dev_info->is_g4x;
102
103 brw_init_compaction_tables(&gd->devinfo);
104
105 return gd;
106 }
107
108 void
109 gen_disasm_destroy(struct gen_disasm *disasm)
110 {
111 free(disasm);
112 }