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