aubinator: Use fprintf for output.
[mesa.git] / src / intel / tools / aubinator.c
1 /*
2 * Copyright © 2016 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 <stdio.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <getopt.h>
28
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <string.h>
32 #include <signal.h>
33 #include <errno.h>
34 #include <inttypes.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <sys/wait.h>
38 #include <sys/mman.h>
39
40 #include "util/macros.h"
41
42 #include "decoder.h"
43 #include "intel_aub.h"
44 #include "gen_disasm.h"
45
46 /* Below is the only command missing from intel_aub.h in libdrm
47 * So, reuse intel_aub.h from libdrm and #define the
48 * AUB_MI_BATCH_BUFFER_END as below
49 */
50 #define AUB_MI_BATCH_BUFFER_END (0x0500 << 16)
51
52 #define CSI "\e["
53 #define BLUE_HEADER CSI "0;44m"
54 #define GREEN_HEADER CSI "1;42m"
55 #define NORMAL CSI "0m"
56
57 /* options */
58
59 static bool option_full_decode = true;
60 static bool option_print_offsets = true;
61 static enum { COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER } option_color;
62
63 /* state */
64
65 uint16_t pci_id = 0;
66 char *input_file = NULL, *xml_path = NULL;
67 struct gen_spec *spec;
68 struct gen_disasm *disasm;
69
70 uint64_t gtt_size, gtt_end;
71 void *gtt;
72 uint64_t general_state_base;
73 uint64_t surface_state_base;
74 uint64_t dynamic_state_base;
75 uint64_t instruction_base;
76 uint64_t instruction_bound;
77
78 FILE *outfile;
79
80 static inline uint32_t
81 field(uint32_t value, int start, int end)
82 {
83 uint32_t mask;
84
85 mask = ~0U >> (31 - end + start);
86
87 return (value >> start) & mask;
88 }
89
90 struct brw_instruction;
91
92 static inline int
93 valid_offset(uint32_t offset)
94 {
95 return offset < gtt_end;
96 }
97
98 static void
99 print_dword_val(struct gen_field_iterator *iter, uint64_t offset,
100 int *dword_num)
101 {
102 struct gen_field *f;
103
104 f = iter->group->fields[iter->i - 1];
105 const int dword = f->start / 32;
106
107 if (*dword_num != dword) {
108 fprintf(outfile, "0x%08"PRIx64": 0x%08x : Dword %d\n",
109 offset + 4 * dword, iter->p[dword], dword);
110 *dword_num = dword;
111 }
112 }
113
114 static char *
115 print_iterator_values(struct gen_field_iterator *iter, int *idx)
116 {
117 char *token = NULL;
118 if (strstr(iter->value, "struct") == NULL) {
119 if (strlen(iter->description) > 0) {
120 fprintf(outfile, " %s: %s (%s)\n",
121 iter->name, iter->value, iter->description);
122 } else {
123 fprintf(outfile, " %s: %s\n", iter->name, iter->value);
124 }
125 } else {
126 token = strtok(iter->value, " ");
127 if (token != NULL) {
128 token = strtok(NULL, " ");
129 *idx = atoi(strtok(NULL, ">"));
130 } else {
131 token = NULL;
132 }
133 fprintf(outfile, " %s:<struct %s>\n", iter->name, token);
134 }
135 return token;
136 }
137
138 static void
139 decode_group(struct gen_spec *spec, struct gen_group *strct,
140 const uint32_t *p, int starting_dword,
141 bool print_dword_headers)
142 {
143 struct gen_field_iterator iter;
144 char *token = NULL;
145 int idx = 0, dword_num = 0;
146 uint64_t offset = 0;
147
148 if (option_print_offsets)
149 offset = (void *) p - gtt;
150 else
151 offset = 0;
152
153 gen_field_iterator_init(&iter, strct, p,
154 option_color == COLOR_ALWAYS);
155 while (gen_field_iterator_next(&iter)) {
156 idx = 0;
157 print_dword_val(&iter, offset, &dword_num);
158 if (dword_num >= starting_dword)
159 token = print_iterator_values(&iter, &idx);
160 if (token != NULL) {
161 fprintf(outfile, "0x%08"PRIx64": 0x%08x : Dword %d\n",
162 offset + 4 * idx, p[idx], idx);
163 struct gen_group *struct_val = gen_spec_find_struct(spec, token);
164 decode_group(spec, struct_val, &p[idx], 0, false);
165 token = NULL;
166 }
167 }
168 }
169
170 static void
171 decode_structure(struct gen_spec *spec, struct gen_group *strct,
172 const uint32_t *p)
173 {
174 decode_group(spec, strct, p, 0, false);
175 }
176
177 static void
178 dump_binding_table(struct gen_spec *spec, uint32_t offset)
179 {
180 uint32_t *pointers, i;
181 uint64_t start;
182 struct gen_group *surface_state;
183
184 surface_state = gen_spec_find_struct(spec, "RENDER_SURFACE_STATE");
185 if (surface_state == NULL) {
186 fprintf(outfile, "did not find RENDER_SURFACE_STATE info\n");
187 return;
188 }
189
190 start = surface_state_base + offset;
191 pointers = gtt + start;
192 for (i = 0; i < 16; i++) {
193 if (pointers[i] == 0)
194 continue;
195 start = pointers[i] + surface_state_base;
196 if (!valid_offset(start)) {
197 fprintf(outfile, "pointer %u: %08x <not valid>\n",
198 i, pointers[i]);
199 continue;
200 } else {
201 fprintf(outfile, "pointer %u: %08x\n", i, pointers[i]);
202 }
203
204 decode_structure(spec, surface_state, gtt + start);
205 }
206 }
207
208 static void
209 handle_3dstate_index_buffer(struct gen_spec *spec, uint32_t *p)
210 {
211 void *start;
212 uint32_t length, i, type, size;
213
214 start = gtt + p[2];
215 type = (p[1] >> 8) & 3;
216 size = 1 << type;
217 length = p[4] / size;
218 if (length > 10)
219 length = 10;
220
221 fprintf(outfile, "\t");
222
223 for (i = 0; i < length; i++) {
224 switch (type) {
225 case 0:
226 fprintf(outfile, "%3d ", ((uint8_t *)start)[i]);
227 break;
228 case 1:
229 fprintf(outfile, "%3d ", ((uint16_t *)start)[i]);
230 break;
231 case 2:
232 fprintf(outfile, "%3d ", ((uint32_t *)start)[i]);
233 break;
234 }
235 }
236 if (length < p[4] / size)
237 fprintf(outfile, "...\n");
238 else
239 fprintf(outfile, "\n");
240 }
241
242 static inline uint64_t
243 get_address(struct gen_spec *spec, uint32_t *p)
244 {
245 /* Addresses are always guaranteed to be page-aligned and sometimes
246 * hardware packets have extra stuff stuffed in the bottom 12 bits.
247 */
248 uint64_t addr = p[0] & ~0xfffu;
249
250 if (gen_spec_get_gen(spec) >= gen_make_gen(8,0)) {
251 /* On Broadwell and above, we have 48-bit addresses which consume two
252 * dwords. Some packets require that these get stored in a "canonical
253 * form" which means that bit 47 is sign-extended through the upper
254 * bits. In order to correctly handle those aub dumps, we need to mask
255 * off the top 16 bits.
256 */
257 addr |= ((uint64_t)p[1] & 0xffff) << 32;
258 }
259
260 return addr;
261 }
262
263 static inline uint64_t
264 get_offset(uint32_t *p, uint32_t start, uint32_t end)
265 {
266 assert(start <= end);
267 assert(end < 64);
268
269 uint64_t mask = (~0ull >> (64 - (end - start + 1))) << start;
270
271 uint64_t offset = p[0];
272 if (end >= 32)
273 offset |= (uint64_t) p[1] << 32;
274
275 return offset & mask;
276 }
277
278 static void
279 handle_state_base_address(struct gen_spec *spec, uint32_t *p)
280 {
281 if (gen_spec_get_gen(spec) >= gen_make_gen(8,0)) {
282 if (p[1] & 1)
283 general_state_base = get_address(spec, &p[1]);
284 if (p[4] & 1)
285 surface_state_base = get_address(spec, &p[4]);
286 if (p[6] & 1)
287 dynamic_state_base = get_address(spec, &p[6]);
288 if (p[10] & 1)
289 instruction_base = get_address(spec, &p[10]);
290 if (p[15] & 1)
291 instruction_bound = p[15] & 0xfff;
292 } else {
293 if (p[2] & 1)
294 surface_state_base = get_address(spec, &p[2]);
295 if (p[3] & 1)
296 dynamic_state_base = get_address(spec, &p[3]);
297 if (p[5] & 1)
298 instruction_base = get_address(spec, &p[5]);
299 if (p[9] & 1)
300 instruction_bound = get_address(spec, &p[9]);
301 }
302 }
303
304 static void
305 dump_samplers(struct gen_spec *spec, uint32_t offset)
306 {
307 uint32_t i;
308 uint64_t start;
309 struct gen_group *sampler_state;
310
311 sampler_state = gen_spec_find_struct(spec, "SAMPLER_STATE");
312
313 start = dynamic_state_base + offset;
314 for (i = 0; i < 4; i++) {
315 fprintf(outfile, "sampler state %d\n", i);
316 decode_structure(spec, sampler_state, gtt + start + i * 16);
317 }
318 }
319
320 static void
321 handle_media_interface_descriptor_load(struct gen_spec *spec, uint32_t *p)
322 {
323 int i, length = p[2] / 32;
324 struct gen_group *descriptor_structure;
325 uint32_t *descriptors;
326 uint64_t start;
327 struct brw_instruction *insns;
328
329 descriptor_structure =
330 gen_spec_find_struct(spec, "INTERFACE_DESCRIPTOR_DATA");
331 if (descriptor_structure == NULL) {
332 fprintf(outfile, "did not find INTERFACE_DESCRIPTOR_DATA info\n");
333 return;
334 }
335
336 start = dynamic_state_base + p[3];
337 descriptors = gtt + start;
338 for (i = 0; i < length; i++, descriptors += 8) {
339 fprintf(outfile, "descriptor %u: %08x\n", i, *descriptors);
340 decode_structure(spec, descriptor_structure, descriptors);
341
342 start = instruction_base + descriptors[0];
343 if (!valid_offset(start)) {
344 fprintf(outfile, "kernel: %08"PRIx64" <not valid>\n", start);
345 continue;
346 } else {
347 fprintf(outfile, "kernel: %08"PRIx64"\n", start);
348 }
349
350 insns = (struct brw_instruction *) (gtt + start);
351 gen_disasm_disassemble(disasm, insns, 0, stdout);
352
353 dump_samplers(spec, descriptors[3] & ~0x1f);
354 dump_binding_table(spec, descriptors[4] & ~0x1f);
355 }
356 }
357
358 /* Heuristic to determine whether a uint32_t is probably actually a float
359 * (http://stackoverflow.com/a/2953466)
360 */
361
362 static bool
363 probably_float(uint32_t bits)
364 {
365 int exp = ((bits & 0x7f800000U) >> 23) - 127;
366 uint32_t mant = bits & 0x007fffff;
367
368 /* +- 0.0 */
369 if (exp == -127 && mant == 0)
370 return true;
371
372 /* +- 1 billionth to 1 billion */
373 if (-30 <= exp && exp <= 30)
374 return true;
375
376 /* some value with only a few binary digits */
377 if ((mant & 0x0000ffff) == 0)
378 return true;
379
380 return false;
381 }
382
383 static void
384 handle_3dstate_vertex_buffers(struct gen_spec *spec, uint32_t *p)
385 {
386 uint32_t *end, *s, *dw, *dwend;
387 uint64_t offset;
388 int n, i, count, stride;
389
390 end = (p[0] & 0xff) + p + 2;
391 for (s = &p[1], n = 0; s < end; s += 4, n++) {
392 if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
393 offset = *(uint64_t *) &s[1];
394 dwend = gtt + offset + s[3];
395 } else {
396 offset = s[1];
397 dwend = gtt + s[2] + 1;
398 }
399
400 stride = field(s[0], 0, 11);
401 count = 0;
402 fprintf(outfile, "vertex buffer %d, size %d\n", n, s[3]);
403 for (dw = gtt + offset, i = 0; dw < dwend && i < 256; dw++) {
404 if (count == 0 && count % (8 * 4) == 0)
405 fprintf(outfile, " ");
406
407 if (probably_float(*dw))
408 fprintf(outfile, " %8.2f", *(float *) dw);
409 else
410 fprintf(outfile, " 0x%08x", *dw);
411
412 i++;
413 count += 4;
414
415 if (count == stride) {
416 fprintf(outfile, "\n");
417 count = 0;
418 } else if (count % (8 * 4) == 0) {
419 fprintf(outfile, "\n");
420 } else {
421 fprintf(outfile, " ");
422 }
423 }
424 if (count > 0 && count % (8 * 4) != 0)
425 fprintf(outfile, "\n");
426 }
427 }
428
429 static void
430 handle_3dstate_vs(struct gen_spec *spec, uint32_t *p)
431 {
432 uint64_t start;
433 struct brw_instruction *insns;
434 int vs_enable;
435
436 if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
437 start = get_offset(&p[1], 6, 63);
438 vs_enable = p[7] & 1;
439 } else {
440 start = get_offset(&p[1], 6, 31);
441 vs_enable = p[5] & 1;
442 }
443
444 if (vs_enable) {
445 fprintf(outfile, "instruction_base %08"PRIx64", start %08"PRIx64"\n",
446 instruction_base, start);
447
448 insns = (struct brw_instruction *) (gtt + instruction_base + start);
449 gen_disasm_disassemble(disasm, insns, 0, stdout);
450 }
451 }
452
453 static void
454 handle_3dstate_hs(struct gen_spec *spec, uint32_t *p)
455 {
456 uint64_t start;
457 struct brw_instruction *insns;
458 int hs_enable;
459
460 if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
461 start = get_offset(&p[3], 6, 63);
462 } else {
463 start = get_offset(&p[3], 6, 31);
464 }
465
466 hs_enable = p[2] & 0x80000000;
467
468 if (hs_enable) {
469 fprintf(outfile, "instruction_base %08"PRIx64", start %08"PRIx64"\n",
470 instruction_base, start);
471
472 insns = (struct brw_instruction *) (gtt + instruction_base + start);
473 gen_disasm_disassemble(disasm, insns, 0, stdout);
474 }
475 }
476
477 static void
478 handle_3dstate_constant(struct gen_spec *spec, uint32_t *p)
479 {
480 int i, j, length;
481 uint32_t *dw;
482 float *f;
483
484 for (i = 0; i < 4; i++) {
485 length = (p[1 + i / 2] >> (i & 1) * 16) & 0xffff;
486 f = (float *) (gtt + p[3 + i * 2] + dynamic_state_base);
487 dw = (uint32_t *) f;
488 for (j = 0; j < length * 8; j++) {
489 if (probably_float(dw[j]))
490 fprintf(outfile, " %04.3f", f[j]);
491 else
492 fprintf(outfile, " 0x%08x", dw[j]);
493
494 if ((j & 7) == 7)
495 fprintf(outfile, "\n");
496 }
497 }
498 }
499
500 static void
501 handle_3dstate_ps(struct gen_spec *spec, uint32_t *p)
502 {
503 uint32_t mask = ~((1 << 6) - 1);
504 uint64_t start;
505 struct brw_instruction *insns;
506 static const char unused[] = "unused";
507 static const char *pixel_type[3] = {"8 pixel", "16 pixel", "32 pixel"};
508 const char *k0, *k1, *k2;
509 uint32_t k_mask, k1_offset, k2_offset;
510
511 if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
512 k_mask = p[6] & 7;
513 k1_offset = 8;
514 k2_offset = 10;
515 } else {
516 k_mask = p[4] & 7;
517 k1_offset = 6;
518 k2_offset = 7;
519 }
520
521 #define DISPATCH_8 1
522 #define DISPATCH_16 2
523 #define DISPATCH_32 4
524
525 switch (k_mask) {
526 case DISPATCH_8:
527 k0 = pixel_type[0];
528 k1 = unused;
529 k2 = unused;
530 break;
531 case DISPATCH_16:
532 k0 = pixel_type[1];
533 k1 = unused;
534 k2 = unused;
535 break;
536 case DISPATCH_8 | DISPATCH_16:
537 k0 = pixel_type[0];
538 k1 = unused;
539 k2 = pixel_type[1];
540 break;
541 case DISPATCH_32:
542 k0 = pixel_type[2];
543 k1 = unused;
544 k2 = unused;
545 break;
546 case DISPATCH_16 | DISPATCH_32:
547 k0 = unused;
548 k1 = pixel_type[2];
549 k2 = pixel_type[1];
550 break;
551 case DISPATCH_8 | DISPATCH_16 | DISPATCH_32:
552 k0 = pixel_type[0];
553 k1 = pixel_type[2];
554 k2 = pixel_type[1];
555 break;
556 default:
557 k0 = unused;
558 k1 = unused;
559 k2 = unused;
560 break;
561 }
562
563 start = instruction_base + (p[1] & mask);
564 fprintf(outfile, " Kernel[0] %s\n", k0);
565 if (k0 != unused) {
566 insns = (struct brw_instruction *) (gtt + start);
567 gen_disasm_disassemble(disasm, insns, 0, stdout);
568 }
569
570 start = instruction_base + (p[k1_offset] & mask);
571 fprintf(outfile, " Kernel[1] %s\n", k1);
572 if (k1 != unused) {
573 insns = (struct brw_instruction *) (gtt + start);
574 gen_disasm_disassemble(disasm, insns, 0, stdout);
575 }
576
577 start = instruction_base + (p[k2_offset] & mask);
578 fprintf(outfile, " Kernel[2] %s\n", k2);
579 if (k2 != unused) {
580 insns = (struct brw_instruction *) (gtt + start);
581 gen_disasm_disassemble(disasm, insns, 0, stdout);
582 }
583 }
584
585 static void
586 handle_3dstate_binding_table_pointers(struct gen_spec *spec, uint32_t *p)
587 {
588 dump_binding_table(spec, p[1]);
589 }
590
591 static void
592 handle_3dstate_sampler_state_pointers(struct gen_spec *spec, uint32_t *p)
593 {
594 dump_samplers(spec, p[1]);
595 }
596
597 static void
598 handle_3dstate_viewport_state_pointers_cc(struct gen_spec *spec, uint32_t *p)
599 {
600 uint64_t start;
601 struct gen_group *cc_viewport;
602
603 cc_viewport = gen_spec_find_struct(spec, "CC_VIEWPORT");
604
605 start = dynamic_state_base + (p[1] & ~0x1fu);
606 for (uint32_t i = 0; i < 4; i++) {
607 fprintf(outfile, "viewport %d\n", i);
608 decode_structure(spec, cc_viewport, gtt + start + i * 8);
609 }
610 }
611
612 static void
613 handle_3dstate_viewport_state_pointers_sf_clip(struct gen_spec *spec,
614 uint32_t *p)
615 {
616 uint64_t start;
617 struct gen_group *sf_clip_viewport;
618
619 sf_clip_viewport = gen_spec_find_struct(spec, "SF_CLIP_VIEWPORT");
620
621 start = dynamic_state_base + (p[1] & ~0x3fu);
622 for (uint32_t i = 0; i < 4; i++) {
623 fprintf(outfile, "viewport %d\n", i);
624 decode_structure(spec, sf_clip_viewport, gtt + start + i * 64);
625 }
626 }
627
628 static void
629 handle_3dstate_blend_state_pointers(struct gen_spec *spec, uint32_t *p)
630 {
631 uint64_t start;
632 struct gen_group *blend_state;
633
634 blend_state = gen_spec_find_struct(spec, "BLEND_STATE");
635
636 start = dynamic_state_base + (p[1] & ~0x3fu);
637 decode_structure(spec, blend_state, gtt + start);
638 }
639
640 static void
641 handle_3dstate_cc_state_pointers(struct gen_spec *spec, uint32_t *p)
642 {
643 uint64_t start;
644 struct gen_group *cc_state;
645
646 cc_state = gen_spec_find_struct(spec, "COLOR_CALC_STATE");
647
648 start = dynamic_state_base + (p[1] & ~0x3fu);
649 decode_structure(spec, cc_state, gtt + start);
650 }
651
652 static void
653 handle_3dstate_scissor_state_pointers(struct gen_spec *spec, uint32_t *p)
654 {
655 uint64_t start;
656 struct gen_group *scissor_rect;
657
658 scissor_rect = gen_spec_find_struct(spec, "SCISSOR_RECT");
659
660 start = dynamic_state_base + (p[1] & ~0x1fu);
661 decode_structure(spec, scissor_rect, gtt + start);
662 }
663
664 static void
665 handle_load_register_imm(struct gen_spec *spec, uint32_t *p)
666 {
667 struct gen_group *reg = gen_spec_find_register(spec, p[1]);
668
669 if (reg != NULL) {
670 fprintf(outfile, "register %s (0x%x): 0x%x\n",
671 reg->name, reg->register_offset, p[2]);
672 decode_structure(spec, reg, &p[2]);
673 }
674 }
675
676 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
677
678 #define STATE_BASE_ADDRESS 0x61010000
679
680 #define MEDIA_INTERFACE_DESCRIPTOR_LOAD 0x70020000
681
682 #define _3DSTATE_INDEX_BUFFER 0x780a0000
683 #define _3DSTATE_VERTEX_BUFFERS 0x78080000
684
685 #define _3DSTATE_VS 0x78100000
686 #define _3DSTATE_GS 0x78110000
687 #define _3DSTATE_HS 0x781b0000
688 #define _3DSTATE_DS 0x781d0000
689
690 #define _3DSTATE_CONSTANT_VS 0x78150000
691 #define _3DSTATE_CONSTANT_GS 0x78160000
692 #define _3DSTATE_CONSTANT_PS 0x78170000
693 #define _3DSTATE_CONSTANT_HS 0x78190000
694 #define _3DSTATE_CONSTANT_DS 0x781A0000
695
696 #define _3DSTATE_PS 0x78200000
697
698 #define _3DSTATE_BINDING_TABLE_POINTERS_VS 0x78260000
699 #define _3DSTATE_BINDING_TABLE_POINTERS_HS 0x78270000
700 #define _3DSTATE_BINDING_TABLE_POINTERS_DS 0x78280000
701 #define _3DSTATE_BINDING_TABLE_POINTERS_GS 0x78290000
702 #define _3DSTATE_BINDING_TABLE_POINTERS_PS 0x782a0000
703
704 #define _3DSTATE_SAMPLER_STATE_POINTERS_VS 0x782b0000
705 #define _3DSTATE_SAMPLER_STATE_POINTERS_GS 0x782e0000
706 #define _3DSTATE_SAMPLER_STATE_POINTERS_PS 0x782f0000
707
708 #define _3DSTATE_VIEWPORT_STATE_POINTERS_CC 0x78230000
709 #define _3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP 0x78210000
710 #define _3DSTATE_BLEND_STATE_POINTERS 0x78240000
711 #define _3DSTATE_CC_STATE_POINTERS 0x780e0000
712 #define _3DSTATE_SCISSOR_STATE_POINTERS 0x780f0000
713
714 #define _MI_LOAD_REGISTER_IMM 0x11000000
715
716 struct custom_handler {
717 uint32_t opcode;
718 void (*handle)(struct gen_spec *spec, uint32_t *p);
719 } custom_handlers[] = {
720 { STATE_BASE_ADDRESS, handle_state_base_address },
721 { MEDIA_INTERFACE_DESCRIPTOR_LOAD, handle_media_interface_descriptor_load },
722 { _3DSTATE_VERTEX_BUFFERS, handle_3dstate_vertex_buffers },
723 { _3DSTATE_INDEX_BUFFER, handle_3dstate_index_buffer },
724 { _3DSTATE_VS, handle_3dstate_vs },
725 { _3DSTATE_GS, handle_3dstate_vs },
726 { _3DSTATE_DS, handle_3dstate_vs },
727 { _3DSTATE_HS, handle_3dstate_hs },
728 { _3DSTATE_CONSTANT_VS, handle_3dstate_constant },
729 { _3DSTATE_CONSTANT_GS, handle_3dstate_constant },
730 { _3DSTATE_CONSTANT_PS, handle_3dstate_constant },
731 { _3DSTATE_CONSTANT_HS, handle_3dstate_constant },
732 { _3DSTATE_CONSTANT_DS, handle_3dstate_constant },
733 { _3DSTATE_PS, handle_3dstate_ps },
734
735 { _3DSTATE_BINDING_TABLE_POINTERS_VS, handle_3dstate_binding_table_pointers },
736 { _3DSTATE_BINDING_TABLE_POINTERS_HS, handle_3dstate_binding_table_pointers },
737 { _3DSTATE_BINDING_TABLE_POINTERS_DS, handle_3dstate_binding_table_pointers },
738 { _3DSTATE_BINDING_TABLE_POINTERS_GS, handle_3dstate_binding_table_pointers },
739 { _3DSTATE_BINDING_TABLE_POINTERS_PS, handle_3dstate_binding_table_pointers },
740
741 { _3DSTATE_SAMPLER_STATE_POINTERS_VS, handle_3dstate_sampler_state_pointers },
742 { _3DSTATE_SAMPLER_STATE_POINTERS_GS, handle_3dstate_sampler_state_pointers },
743 { _3DSTATE_SAMPLER_STATE_POINTERS_PS, handle_3dstate_sampler_state_pointers },
744
745 { _3DSTATE_VIEWPORT_STATE_POINTERS_CC, handle_3dstate_viewport_state_pointers_cc },
746 { _3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP, handle_3dstate_viewport_state_pointers_sf_clip },
747 { _3DSTATE_BLEND_STATE_POINTERS, handle_3dstate_blend_state_pointers },
748 { _3DSTATE_CC_STATE_POINTERS, handle_3dstate_cc_state_pointers },
749 { _3DSTATE_SCISSOR_STATE_POINTERS, handle_3dstate_scissor_state_pointers },
750 { _MI_LOAD_REGISTER_IMM, handle_load_register_imm }
751 };
752
753 static void
754 parse_commands(struct gen_spec *spec, uint32_t *cmds, int size, int engine)
755 {
756 uint32_t *p, *end = cmds + size / 4;
757 unsigned int length, i;
758 struct gen_group *inst;
759
760 for (p = cmds; p < end; p += length) {
761 inst = gen_spec_find_instruction(spec, p);
762 if (inst == NULL) {
763 fprintf(outfile, "unknown instruction %08x\n", p[0]);
764 length = (p[0] & 0xff) + 2;
765 continue;
766 }
767 length = gen_group_get_length(inst, p);
768
769 const char *color, *reset_color = NORMAL;
770 uint64_t offset;
771
772 if (option_full_decode) {
773 if ((p[0] & 0xffff0000) == AUB_MI_BATCH_BUFFER_START ||
774 (p[0] & 0xffff0000) == AUB_MI_BATCH_BUFFER_END)
775 color = GREEN_HEADER;
776 else
777 color = BLUE_HEADER;
778 } else
779 color = NORMAL;
780
781 if (option_color == COLOR_NEVER) {
782 color = "";
783 reset_color = "";
784 }
785
786 if (option_print_offsets)
787 offset = (void *) p - gtt;
788 else
789 offset = 0;
790
791 fprintf(outfile, "%s0x%08"PRIx64": 0x%08x: %-80s%s\n",
792 color, offset, p[0],
793 gen_group_get_name(inst), reset_color);
794
795 if (option_full_decode) {
796 decode_group(spec, inst, p, 1, true);
797
798 for (i = 0; i < ARRAY_LENGTH(custom_handlers); i++) {
799 if (gen_group_get_opcode(inst) == custom_handlers[i].opcode)
800 custom_handlers[i].handle(spec, p);
801 }
802 }
803
804 if ((p[0] & 0xffff0000) == AUB_MI_BATCH_BUFFER_START) {
805 uint64_t start = get_address(spec, &p[1]);
806
807 if (p[0] & (1 << 22)) {
808 /* MI_BATCH_BUFFER_START with "2nd Level Batch Buffer" set acts
809 * like a subroutine call. Commands that come afterwards get
810 * processed once the 2nd level batch buffer returns with
811 * MI_BATCH_BUFFER_END.
812 */
813 parse_commands(spec, gtt + start, gtt_end - start, engine);
814 } else {
815 /* MI_BATCH_BUFFER_START with "2nd Level Batch Buffer" unset acts
816 * like a goto. Nothing after it will ever get processed. In
817 * order to prevent the recursion from growing, we just reset the
818 * loop and continue;
819 */
820 p = gtt + start;
821 /* We don't know where secondaries end so use the GTT end */
822 end = gtt + gtt_end;
823 length = 0;
824 continue;
825 }
826 } else if ((p[0] & 0xffff0000) == AUB_MI_BATCH_BUFFER_END) {
827 break;
828 }
829 }
830 }
831
832 #define GEN_ENGINE_RENDER 1
833 #define GEN_ENGINE_BLITTER 2
834
835 static void
836 handle_trace_block(uint32_t *p)
837 {
838 int operation = p[1] & AUB_TRACE_OPERATION_MASK;
839 int type = p[1] & AUB_TRACE_TYPE_MASK;
840 int address_space = p[1] & AUB_TRACE_ADDRESS_SPACE_MASK;
841 uint64_t offset = p[3];
842 uint32_t size = p[4];
843 int header_length = p[0] & 0xffff;
844 uint32_t *data = p + header_length + 2;
845 int engine = GEN_ENGINE_RENDER;
846
847 if (gen_spec_get_gen(spec) >= gen_make_gen(8,0))
848 offset += (uint64_t) p[5] << 32;
849
850 switch (operation) {
851 case AUB_TRACE_OP_DATA_WRITE:
852 if (address_space != AUB_TRACE_MEMTYPE_GTT)
853 break;
854 if (gtt_size < offset + size) {
855 fprintf(stderr, "overflow gtt space: %s\n", strerror(errno));
856 exit(EXIT_FAILURE);
857 }
858 memcpy((char *) gtt + offset, data, size);
859 if (gtt_end < offset + size)
860 gtt_end = offset + size;
861 break;
862 case AUB_TRACE_OP_COMMAND_WRITE:
863 switch (type) {
864 case AUB_TRACE_TYPE_RING_PRB0:
865 engine = GEN_ENGINE_RENDER;
866 break;
867 case AUB_TRACE_TYPE_RING_PRB2:
868 engine = GEN_ENGINE_BLITTER;
869 break;
870 default:
871 fprintf(outfile, "command write to unknown ring %d\n", type);
872 break;
873 }
874
875 parse_commands(spec, data, size, engine);
876 gtt_end = 0;
877 break;
878 }
879 }
880
881 static void
882 handle_trace_header(uint32_t *p)
883 {
884 /* The intel_aubdump tool from IGT is kind enough to put a PCI-ID= tag in
885 * the AUB header comment. If the user hasn't specified a hardware
886 * generation, try to use the one from the AUB file.
887 */
888 uint32_t *end = p + (p[0] & 0xffff) + 2;
889 int aub_pci_id = 0;
890 if (end > &p[12] && p[12] > 0)
891 sscanf((char *)&p[13], "PCI-ID=%i", &aub_pci_id);
892
893 if (pci_id == 0)
894 pci_id = aub_pci_id;
895
896 struct gen_device_info devinfo;
897 if (!gen_get_device_info(pci_id, &devinfo)) {
898 fprintf(stderr, "can't find device information: pci_id=0x%x\n", pci_id);
899 exit(EXIT_FAILURE);
900 }
901
902 if (xml_path == NULL)
903 spec = gen_spec_load(&devinfo);
904 else
905 spec = gen_spec_load_from_path(&devinfo, xml_path);
906 disasm = gen_disasm_create(pci_id);
907
908 if (spec == NULL || disasm == NULL)
909 exit(EXIT_FAILURE);
910
911 fprintf(outfile, "%sAubinator: Intel AUB file decoder.%-80s%s\n",
912 GREEN_HEADER, "", NORMAL);
913
914 if (input_file)
915 fprintf(outfile, "File name: %s\n", input_file);
916
917 if (aub_pci_id)
918 fprintf(outfile, "PCI ID: 0x%x\n", aub_pci_id);
919
920 char app_name[33];
921 strncpy(app_name, (char *)&p[2], 32);
922 app_name[32] = 0;
923 fprintf(outfile, "Application name: %s\n", app_name);
924
925 fprintf(outfile, "Decoding as: %s\n", gen_get_device_name(pci_id));
926
927 /* Throw in a new line before the first batch */
928 fprintf(outfile, "\n");
929 }
930
931 struct aub_file {
932 FILE *stream;
933
934 uint32_t *map, *end, *cursor;
935 uint32_t *mem_end;
936 };
937
938 static struct aub_file *
939 aub_file_open(const char *filename)
940 {
941 struct aub_file *file;
942 struct stat sb;
943 int fd;
944
945 file = calloc(1, sizeof *file);
946 fd = open(filename, O_RDONLY);
947 if (fd == -1) {
948 fprintf(stderr, "open %s failed: %s\n", filename, strerror(errno));
949 exit(EXIT_FAILURE);
950 }
951
952 if (fstat(fd, &sb) == -1) {
953 fprintf(stderr, "stat failed: %s\n", strerror(errno));
954 exit(EXIT_FAILURE);
955 }
956
957 file->map = mmap(NULL, sb.st_size,
958 PROT_READ, MAP_SHARED, fd, 0);
959 if (file->map == MAP_FAILED) {
960 fprintf(stderr, "mmap failed: %s\n", strerror(errno));
961 exit(EXIT_FAILURE);
962 }
963
964 file->cursor = file->map;
965 file->end = file->map + sb.st_size / 4;
966
967 return file;
968 }
969
970 static struct aub_file *
971 aub_file_stdin(void)
972 {
973 struct aub_file *file;
974
975 file = calloc(1, sizeof *file);
976 file->stream = stdin;
977
978 return file;
979 }
980
981 #define TYPE(dw) (((dw) >> 29) & 7)
982 #define OPCODE(dw) (((dw) >> 23) & 0x3f)
983 #define SUBOPCODE(dw) (((dw) >> 16) & 0x7f)
984
985 #define MAKE_HEADER(type, opcode, subopcode) \
986 (((type) << 29) | ((opcode) << 23) | ((subopcode) << 16))
987
988 #define TYPE_AUB 0x7
989
990 /* Classic AUB opcodes */
991 #define OPCODE_AUB 0x01
992 #define SUBOPCODE_HEADER 0x05
993 #define SUBOPCODE_BLOCK 0x41
994 #define SUBOPCODE_BMP 0x1e
995
996 /* Newer version AUB opcode */
997 #define OPCODE_NEW_AUB 0x2e
998 #define SUBOPCODE_VERSION 0x00
999 #define SUBOPCODE_REG_WRITE 0x03
1000 #define SUBOPCODE_MEM_POLL 0x05
1001 #define SUBOPCODE_MEM_WRITE 0x06
1002
1003 #define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) )
1004
1005 struct {
1006 const char *name;
1007 uint32_t gen;
1008 } device_map[] = {
1009 { "bwr", MAKE_GEN(4, 0) },
1010 { "cln", MAKE_GEN(4, 0) },
1011 { "blc", MAKE_GEN(4, 0) },
1012 { "ctg", MAKE_GEN(4, 0) },
1013 { "el", MAKE_GEN(4, 0) },
1014 { "il", MAKE_GEN(4, 0) },
1015 { "sbr", MAKE_GEN(6, 0) },
1016 { "ivb", MAKE_GEN(7, 0) },
1017 { "lrb2", MAKE_GEN(0, 0) },
1018 { "hsw", MAKE_GEN(7, 5) },
1019 { "vlv", MAKE_GEN(7, 0) },
1020 { "bdw", MAKE_GEN(8, 0) },
1021 { "skl", MAKE_GEN(9, 0) },
1022 { "chv", MAKE_GEN(8, 0) },
1023 { "bxt", MAKE_GEN(9, 0) }
1024 };
1025
1026 enum {
1027 AUB_ITEM_DECODE_OK,
1028 AUB_ITEM_DECODE_FAILED,
1029 AUB_ITEM_DECODE_NEED_MORE_DATA,
1030 };
1031
1032 static int
1033 aub_file_decode_batch(struct aub_file *file)
1034 {
1035 uint32_t *p, h, device, data_type, *new_cursor;
1036 int header_length, bias;
1037
1038 if (file->end - file->cursor < 1)
1039 return AUB_ITEM_DECODE_NEED_MORE_DATA;
1040
1041 p = file->cursor;
1042 h = *p;
1043 header_length = h & 0xffff;
1044
1045 switch (OPCODE(h)) {
1046 case OPCODE_AUB:
1047 bias = 2;
1048 break;
1049 case OPCODE_NEW_AUB:
1050 bias = 1;
1051 break;
1052 default:
1053 fprintf(outfile, "unknown opcode %d at %td/%td\n",
1054 OPCODE(h), file->cursor - file->map,
1055 file->end - file->map);
1056 return AUB_ITEM_DECODE_FAILED;
1057 }
1058
1059 new_cursor = p + header_length + bias;
1060 if ((h & 0xffff0000) == MAKE_HEADER(TYPE_AUB, OPCODE_AUB, SUBOPCODE_BLOCK)) {
1061 if (file->end - file->cursor < 4)
1062 return AUB_ITEM_DECODE_NEED_MORE_DATA;
1063 new_cursor += p[4] / 4;
1064 }
1065
1066 if (new_cursor > file->end)
1067 return AUB_ITEM_DECODE_NEED_MORE_DATA;
1068
1069 switch (h & 0xffff0000) {
1070 case MAKE_HEADER(TYPE_AUB, OPCODE_AUB, SUBOPCODE_HEADER):
1071 handle_trace_header(p);
1072 break;
1073 case MAKE_HEADER(TYPE_AUB, OPCODE_AUB, SUBOPCODE_BLOCK):
1074 handle_trace_block(p);
1075 break;
1076 case MAKE_HEADER(TYPE_AUB, OPCODE_AUB, SUBOPCODE_BMP):
1077 break;
1078 case MAKE_HEADER(TYPE_AUB, OPCODE_NEW_AUB, SUBOPCODE_VERSION):
1079 fprintf(outfile, "version block: dw1 %08x\n", p[1]);
1080 device = (p[1] >> 8) & 0xff;
1081 fprintf(outfile, " device %s\n", device_map[device].name);
1082 break;
1083 case MAKE_HEADER(TYPE_AUB, OPCODE_NEW_AUB, SUBOPCODE_REG_WRITE):
1084 fprintf(outfile, "register write block: (dwords %d)\n", h & 0xffff);
1085 fprintf(outfile, " reg 0x%x, data 0x%x\n", p[1], p[5]);
1086 break;
1087 case MAKE_HEADER(TYPE_AUB, OPCODE_NEW_AUB, SUBOPCODE_MEM_WRITE):
1088 fprintf(outfile, "memory write block (dwords %d):\n", h & 0xffff);
1089 fprintf(outfile, " address 0x%"PRIx64"\n", *(uint64_t *) &p[1]);
1090 data_type = (p[3] >> 20) & 0xff;
1091 if (data_type != 0)
1092 fprintf(outfile, " data type 0x%x\n", data_type);
1093 fprintf(outfile, " address space 0x%x\n", (p[3] >> 28) & 0xf);
1094 break;
1095 case MAKE_HEADER(TYPE_AUB, OPCODE_NEW_AUB, SUBOPCODE_MEM_POLL):
1096 fprintf(outfile, "memory poll block (dwords %d):\n", h & 0xffff);
1097 break;
1098 default:
1099 fprintf(outfile, "unknown block type=0x%x, opcode=0x%x, "
1100 "subopcode=0x%x (%08x)\n", TYPE(h), OPCODE(h), SUBOPCODE(h), h);
1101 break;
1102 }
1103 file->cursor = new_cursor;
1104
1105 return AUB_ITEM_DECODE_OK;
1106 }
1107
1108 static int
1109 aub_file_more_stuff(struct aub_file *file)
1110 {
1111 return file->cursor < file->end || (file->stream && !feof(file->stream));
1112 }
1113
1114 #define AUB_READ_BUFFER_SIZE (4096)
1115 #define MAX(a, b) ((a) < (b) ? (b) : (a))
1116
1117 static void
1118 aub_file_data_grow(struct aub_file *file)
1119 {
1120 size_t old_size = (file->mem_end - file->map) * 4;
1121 size_t new_size = MAX(old_size * 2, AUB_READ_BUFFER_SIZE);
1122 uint32_t *new_start = realloc(file->map, new_size);
1123
1124 file->cursor = new_start + (file->cursor - file->map);
1125 file->end = new_start + (file->end - file->map);
1126 file->map = new_start;
1127 file->mem_end = file->map + (new_size / 4);
1128 }
1129
1130 static bool
1131 aub_file_data_load(struct aub_file *file)
1132 {
1133 size_t r;
1134
1135 if (file->stream == NULL)
1136 return false;
1137
1138 /* First remove any consumed data */
1139 if (file->cursor > file->map) {
1140 memmove(file->map, file->cursor,
1141 (file->end - file->cursor) * 4);
1142 file->end -= file->cursor - file->map;
1143 file->cursor = file->map;
1144 }
1145
1146 /* Then load some new data in */
1147 if ((file->mem_end - file->end) < (AUB_READ_BUFFER_SIZE / 4))
1148 aub_file_data_grow(file);
1149
1150 r = fread(file->end, 1, (file->mem_end - file->end) * 4, file->stream);
1151 file->end += r / 4;
1152
1153 return r != 0;
1154 }
1155
1156 static void
1157 setup_pager(void)
1158 {
1159 int fds[2];
1160 pid_t pid;
1161
1162 if (!isatty(1))
1163 return;
1164
1165 if (pipe(fds) == -1)
1166 return;
1167
1168 pid = fork();
1169 if (pid == -1)
1170 return;
1171
1172 if (pid == 0) {
1173 close(fds[1]);
1174 dup2(fds[0], 0);
1175 execlp("less", "less", "-FRSi", NULL);
1176 }
1177
1178 close(fds[0]);
1179 dup2(fds[1], 1);
1180 close(fds[1]);
1181 }
1182
1183 static void
1184 print_help(const char *progname, FILE *file)
1185 {
1186 fprintf(file,
1187 "Usage: %s [OPTION]... [FILE]\n"
1188 "Decode aub file contents from either FILE or the standard input.\n\n"
1189 "A valid --gen option must be provided.\n\n"
1190 " --help display this help and exit\n"
1191 " --gen=platform decode for given platform (ivb, byt, hsw, bdw, chv, skl, kbl or bxt)\n"
1192 " --headers decode only command headers\n"
1193 " --color[=WHEN] colorize the output; WHEN can be 'auto' (default\n"
1194 " if omitted), 'always', or 'never'\n"
1195 " --no-pager don't launch pager\n"
1196 " --no-offsets don't print instruction offsets\n"
1197 " --xml=DIR load hardware xml description from directory DIR\n",
1198 progname);
1199 }
1200
1201 int main(int argc, char *argv[])
1202 {
1203 struct aub_file *file;
1204 int c, i;
1205 bool help = false, pager = true;
1206 const struct {
1207 const char *name;
1208 int pci_id;
1209 } gens[] = {
1210 { "ivb", 0x0166 }, /* Intel(R) Ivybridge Mobile GT2 */
1211 { "hsw", 0x0416 }, /* Intel(R) Haswell Mobile GT2 */
1212 { "byt", 0x0155 }, /* Intel(R) Bay Trail */
1213 { "bdw", 0x1616 }, /* Intel(R) HD Graphics 5500 (Broadwell GT2) */
1214 { "chv", 0x22B3 }, /* Intel(R) HD Graphics (Cherryview) */
1215 { "skl", 0x1912 }, /* Intel(R) HD Graphics 530 (Skylake GT2) */
1216 { "kbl", 0x591D }, /* Intel(R) Kabylake GT2 */
1217 { "bxt", 0x0A84 } /* Intel(R) HD Graphics (Broxton) */
1218 };
1219 const struct option aubinator_opts[] = {
1220 { "help", no_argument, (int *) &help, true },
1221 { "no-pager", no_argument, (int *) &pager, false },
1222 { "no-offsets", no_argument, (int *) &option_print_offsets, false },
1223 { "gen", required_argument, NULL, 'g' },
1224 { "headers", no_argument, (int *) &option_full_decode, false },
1225 { "color", required_argument, NULL, 'c' },
1226 { "xml", required_argument, NULL, 'x' },
1227 { NULL, 0, NULL, 0 }
1228 };
1229
1230 outfile = stdout;
1231
1232 i = 0;
1233 while ((c = getopt_long(argc, argv, "", aubinator_opts, &i)) != -1) {
1234 switch (c) {
1235 case 'g':
1236 for (i = 0; i < ARRAY_SIZE(gens); i++) {
1237 if (!strcmp(optarg, gens[i].name)) {
1238 pci_id = gens[i].pci_id;
1239 break;
1240 }
1241 }
1242 if (i == ARRAY_SIZE(gens)) {
1243 fprintf(stderr, "can't parse gen: '%s', expected ivb, byt, hsw, "
1244 "bdw, chv, skl, kbl or bxt\n", optarg);
1245 exit(EXIT_FAILURE);
1246 }
1247 break;
1248 case 'c':
1249 if (optarg == NULL || strcmp(optarg, "always") == 0)
1250 option_color = COLOR_ALWAYS;
1251 else if (strcmp(optarg, "never") == 0)
1252 option_color = COLOR_NEVER;
1253 else if (strcmp(optarg, "auto") == 0)
1254 option_color = COLOR_AUTO;
1255 else {
1256 fprintf(stderr, "invalid value for --color: %s", optarg);
1257 exit(EXIT_FAILURE);
1258 }
1259 break;
1260 case 'x':
1261 xml_path = strdup(optarg);
1262 break;
1263 default:
1264 break;
1265 }
1266 }
1267
1268 if (help || argc == 1) {
1269 print_help(argv[0], stderr);
1270 exit(0);
1271 }
1272
1273 if (optind < argc)
1274 input_file = argv[optind];
1275
1276 /* Do this before we redirect stdout to pager. */
1277 if (option_color == COLOR_AUTO)
1278 option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER;
1279
1280 if (isatty(1) && pager)
1281 setup_pager();
1282
1283 if (input_file == NULL)
1284 file = aub_file_stdin();
1285 else
1286 file = aub_file_open(input_file);
1287
1288 /* mmap a terabyte for our gtt space. */
1289 gtt_size = 1ull << 40;
1290 gtt = mmap(NULL, gtt_size, PROT_READ | PROT_WRITE,
1291 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
1292 if (gtt == MAP_FAILED) {
1293 fprintf(stderr, "failed to alloc gtt space: %s\n", strerror(errno));
1294 exit(EXIT_FAILURE);
1295 }
1296
1297 while (aub_file_more_stuff(file)) {
1298 switch (aub_file_decode_batch(file)) {
1299 case AUB_ITEM_DECODE_OK:
1300 break;
1301 case AUB_ITEM_DECODE_NEED_MORE_DATA:
1302 if (!file->stream) {
1303 file->cursor = file->end;
1304 break;
1305 }
1306 if (aub_file_more_stuff(file) && !aub_file_data_load(file)) {
1307 fprintf(stderr, "failed to load data from stdin\n");
1308 exit(EXIT_FAILURE);
1309 }
1310 break;
1311 default:
1312 fprintf(stderr, "failed to parse aubdump data\n");
1313 exit(EXIT_FAILURE);
1314 }
1315 }
1316
1317
1318 fflush(stdout);
1319 /* close the stdout which is opened to write the output */
1320 close(1);
1321 free(xml_path);
1322
1323 wait(NULL);
1324
1325 return EXIT_SUCCESS;
1326 }