aubinator: Track the current field's starting dword offset.
[mesa.git] / src / intel / tools / decoder.h
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 #ifndef DECODER_H
25 #define DECODER_H
26
27 #include <stdint.h>
28 #include <stdbool.h>
29
30 #include "common/gen_device_info.h"
31
32 struct gen_spec;
33 struct gen_group;
34 struct gen_field;
35
36 static inline uint32_t gen_make_gen(uint32_t major, uint32_t minor)
37 {
38 return (major << 8) | minor;
39 }
40
41 struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name);
42 struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);
43 struct gen_spec *gen_spec_load_from_path(const struct gen_device_info *devinfo,
44 const char *path);
45 uint32_t gen_spec_get_gen(struct gen_spec *spec);
46 struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const uint32_t *p);
47 struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t offset);
48 int gen_group_get_length(struct gen_group *group, const uint32_t *p);
49 const char *gen_group_get_name(struct gen_group *group);
50 uint32_t gen_group_get_opcode(struct gen_group *group);
51 struct gen_enum *gen_spec_find_enum(struct gen_spec *spec, const char *name);
52
53 struct gen_field_iterator {
54 struct gen_group *group;
55 const char *name;
56 char value[128];
57 const uint32_t *p;
58 int dword; /**< current field starts at &p[dword] */
59 int i;
60 bool print_colors;
61 };
62
63 struct gen_group {
64 struct gen_spec *spec;
65 char *name;
66 int nfields;
67 struct gen_field **fields;
68 uint32_t group_offset, group_count;
69
70 uint32_t opcode_mask;
71 uint32_t opcode;
72
73 /* Register specific */
74 uint32_t register_offset;
75 };
76
77 struct gen_value {
78 char *name;
79 uint64_t value;
80 };
81
82 struct gen_enum {
83 char *name;
84 int nvalues;
85 struct gen_value **values;
86 };
87
88 struct gen_type {
89 enum {
90 GEN_TYPE_UNKNOWN,
91 GEN_TYPE_INT,
92 GEN_TYPE_UINT,
93 GEN_TYPE_BOOL,
94 GEN_TYPE_FLOAT,
95 GEN_TYPE_ADDRESS,
96 GEN_TYPE_OFFSET,
97 GEN_TYPE_STRUCT,
98 GEN_TYPE_UFIXED,
99 GEN_TYPE_SFIXED,
100 GEN_TYPE_MBO,
101 GEN_TYPE_ENUM
102 } kind;
103
104 /* Struct definition for GEN_TYPE_STRUCT */
105 union {
106 struct gen_group *gen_struct;
107 struct gen_enum *gen_enum;
108 struct {
109 /* Integer and fractional sizes for GEN_TYPE_UFIXED and GEN_TYPE_SFIXED */
110 int i, f;
111 };
112 };
113 };
114
115 struct gen_field {
116 char *name;
117 int start, end;
118 struct gen_type type;
119 bool has_default;
120 uint32_t default_value;
121
122 struct gen_enum inline_enum;
123 };
124
125 void gen_field_iterator_init(struct gen_field_iterator *iter,
126 struct gen_group *group,
127 const uint32_t *p,
128 bool print_colors);
129
130 bool gen_field_iterator_next(struct gen_field_iterator *iter);
131
132 #endif /* DECODER_H */