Commit | Line | Data |
---|---|---|
feaee4bd AC |
1 | /* The IGEN simulator generator for GDB, the GNU Debugger. |
2 | ||
e2882c85 | 3 | Copyright 2002-2018 Free Software Foundation, Inc. |
feaee4bd AC |
4 | |
5 | Contributed by Andrew Cagney. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
4744ac1b | 11 | the Free Software Foundation; either version 3 of the License, or |
feaee4bd AC |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
4744ac1b | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
feaee4bd | 21 | |
c906108c SS |
22 | |
23 | /* Instruction decode table: | |
24 | ||
25 | <decode-rule> ::= | |
26 | { <option> } | |
27 | ":" [ <first> ] | |
28 | ":" [ <last> ] | |
29 | ":" [ <force-first> ] | |
30 | ":" [ <force-last> ] | |
31 | ":" [ <constant-field-names> ] | |
32 | ":" [ <word-nr> ] | |
33 | ":" [ <format-names> ] | |
34 | ":" [ <model-names> ] | |
35 | ":" [ <constant> ] | |
36 | ":" [ <path> { "," <path> } ] | |
37 | { ":" <special-mask> | |
38 | ":" [ "!" ] <special-value> | |
39 | ":" <word-nr> } | |
40 | <nl> | |
41 | ; | |
42 | ||
43 | ||
44 | <path> ::= <int> "," <int> ;; | |
45 | ||
46 | <option> ::= | |
47 | <reserved-options> | |
48 | | <code-options> | |
49 | | <optimize-options> | |
50 | | <decode-options> | |
51 | | <constant> | |
52 | | <search-options> | |
53 | ; | |
54 | ||
55 | <reserved-options> ::= "zero-reserved" ; | |
56 | <gen-options> ::= "array" | "switch" | "padded-switch" | "goto-switch" ; | |
57 | <optimize-options> ::= "duplicate" | "combine" | |
58 | <decode-options> ::= "normal" | "boolean" ; | |
59 | <search-options> ::= "constants" | "variables" | "mixed" | |
60 | ||
61 | Ignore the below: | |
62 | ||
63 | ||
64 | The instruction decode table contains rules that dictate how igen | |
65 | is going to firstly break down the opcode table and secondly | |
66 | ||
67 | The table that follows is used by gen to construct a decision tree | |
68 | that can identify each possible instruction. Gen then outputs this | |
69 | decision tree as (according to config) a table or switch statement | |
70 | as the function idecode. | |
71 | ||
72 | In parallel to this, as mentioned above, WITH_EXPANDED_SEMANTICS | |
73 | determines of the semantic functions themselves should be expanded | |
74 | in a similar way. | |
75 | ||
76 | <first> | |
77 | <last> | |
78 | ||
79 | Range of bits (within the instruction) that should be searched for | |
80 | an instruction field. Within such ranges, gen looks for opcodes | |
81 | (constants), registers (strings) and reserved bits (slash) and | |
82 | according to the rules that follows includes or excludes them from | |
83 | a possible instruction field. | |
84 | ||
85 | <force_first> | |
86 | <force_last> | |
87 | ||
88 | If an instruction field was found, enlarge the field size so that | |
89 | it is forced to at least include bits starting from <force_first> | |
90 | (<force_last>). To stop this occuring, use <force_first> = <last> | |
91 | + 1 and <force_last> = <first> - 1. | |
92 | ||
93 | <force_reserved> | |
94 | ||
95 | Treat `/' (reserved) fields as a constant (zero) instead of | |
96 | variable when looking for an instruction field. | |
97 | ||
98 | <force_expansion> | |
99 | ||
100 | Treat any contained register (string) fields as constant when | |
101 | determining the instruction field. For the instruction decode (and | |
102 | controled by IDECODE_EXPAND_SEMANTICS) this forces the expansion of | |
103 | what would otherwize be non constant bits of an instruction. | |
104 | ||
105 | <use_switch> | |
106 | ||
107 | Should this table be expanded using a switch statement (val 1) and | |
108 | if so, should it be padded with entries so as to force the compiler | |
109 | to generate a jump table (val 2). Or a branch table (val 3). | |
110 | ||
111 | <special_mask> | |
112 | <special_value> | |
113 | <special_rule> | |
114 | <special_constant> | |
115 | ||
116 | Special rule to fine tune how specific (or groups) of instructions | |
117 | are expanded. The applicability of the rule is determined by | |
118 | ||
119 | <special_mask> != 0 && (instruction> & <special_mask>) == <special_value> | |
120 | ||
121 | Where <instruction> is obtained by looking only at constant fields | |
122 | with in an instructions spec. When determining an expansion, the | |
123 | rule is only considered when a node contains a single instruction. | |
124 | <special_rule> can be any of: | |
125 | ||
126 | 0: for this instruction, expand by earlier rules | |
127 | 1: expand bits <force_low> .. <force_hi> only | |
128 | 2: boolean expansion of only zero/non-zero cases | |
129 | 3: boolean expansion of equality of special constant | |
130 | ||
131 | */ | |
132 | ||
133 | ||
4e0bf4c4 AC |
134 | typedef enum |
135 | { | |
c906108c SS |
136 | normal_decode_rule, |
137 | boolean_rule, | |
4e0bf4c4 AC |
138 | } |
139 | decode_special_type; | |
c906108c SS |
140 | |
141 | ||
4e0bf4c4 AC |
142 | typedef enum |
143 | { | |
c906108c SS |
144 | invalid_gen, |
145 | array_gen, | |
146 | switch_gen, | |
147 | padded_switch_gen, | |
148 | goto_switch_gen, | |
4e0bf4c4 AC |
149 | } |
150 | decode_gen_type; | |
c906108c SS |
151 | |
152 | ||
4e0bf4c4 AC |
153 | enum |
154 | { | |
c906108c SS |
155 | decode_cond_mask_field, |
156 | decode_cond_value_field, | |
157 | decode_cond_word_nr_field, | |
158 | nr_decode_cond_fields, | |
159 | }; | |
160 | ||
161 | typedef struct _decode_path decode_path; | |
4e0bf4c4 AC |
162 | struct _decode_path |
163 | { | |
c906108c SS |
164 | int opcode_nr; |
165 | decode_path *parent; | |
166 | }; | |
167 | ||
168 | typedef struct _decode_path_list decode_path_list; | |
4e0bf4c4 AC |
169 | struct _decode_path_list |
170 | { | |
c906108c SS |
171 | decode_path *path; |
172 | decode_path_list *next; | |
173 | }; | |
174 | ||
175 | ||
176 | typedef struct _decode_cond decode_cond; | |
4e0bf4c4 AC |
177 | struct _decode_cond |
178 | { | |
c906108c SS |
179 | int word_nr; |
180 | int mask[max_insn_bit_size]; | |
181 | int value[max_insn_bit_size]; | |
182 | int is_equal; | |
183 | decode_cond *next; | |
184 | }; | |
185 | ||
4e0bf4c4 AC |
186 | typedef enum |
187 | { | |
c906108c SS |
188 | decode_find_mixed, |
189 | decode_find_constants, | |
190 | decode_find_strings, | |
4e0bf4c4 AC |
191 | } |
192 | decode_search_type; | |
c906108c | 193 | |
4e0bf4c4 AC |
194 | enum |
195 | { | |
c906108c SS |
196 | decode_options_field, |
197 | decode_first_field, | |
198 | decode_last_field, | |
199 | decode_force_first_field, | |
200 | decode_force_last_field, | |
201 | decode_constant_field_names_field, | |
202 | decode_word_nr_field, | |
203 | decode_format_names_field, | |
204 | decode_model_names_field, | |
205 | decode_paths_field, | |
206 | nr_decode_fields, | |
207 | min_nr_decode_fields = decode_last_field + 1, | |
208 | }; | |
209 | ||
210 | ||
211 | typedef struct _decode_table decode_table; | |
4e0bf4c4 AC |
212 | struct _decode_table |
213 | { | |
c906108c SS |
214 | line_ref *line; |
215 | decode_special_type type; | |
216 | decode_gen_type gen; | |
217 | decode_search_type search; | |
218 | int first; | |
219 | int last; | |
220 | int force_first; | |
221 | int force_last; | |
222 | filter *constant_field_names; | |
223 | int word_nr; | |
224 | /* if a boolean */ | |
225 | unsigned constant; | |
226 | /* options */ | |
227 | int with_zero_reserved; | |
228 | int with_duplicates; | |
229 | int with_combine; | |
230 | /* conditions on the rule being applied */ | |
231 | decode_path_list *paths; | |
232 | filter *format_names; | |
233 | filter *model_names; | |
234 | decode_cond *conditions; | |
235 | decode_table *next; | |
236 | }; | |
237 | ||
238 | ||
4e0bf4c4 | 239 | extern decode_table *load_decode_table (char *file_name); |
c906108c | 240 | |
4e0bf4c4 | 241 | extern int decode_table_max_word_nr (decode_table *rule); |
c906108c SS |
242 | |
243 | extern void dump_decode_rule | |
4e0bf4c4 | 244 | (lf *file, char *prefix, decode_table *rule, char *suffix); |