Commit | Line | Data |
---|---|---|
d4f1c49e DE |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1997, 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 | ||
22 | ||
23 | #include <getopt.h> | |
24 | ||
25 | #include "misc.h" | |
26 | #include "lf.h" | |
27 | #include "table.h" | |
28 | #include "config.h" | |
d4f1c49e DE |
29 | #include "filter.h" |
30 | ||
687f3f1c AC |
31 | #include "igen.h" |
32 | ||
33 | #include "ld-insn.h" | |
d4f1c49e DE |
34 | #include "ld-decode.h" |
35 | #include "ld-cache.h" | |
d4f1c49e | 36 | |
687f3f1c | 37 | #include "gen.h" |
d4f1c49e DE |
38 | |
39 | #include "gen-model.h" | |
40 | #include "gen-icache.h" | |
41 | #include "gen-itable.h" | |
42 | #include "gen-idecode.h" | |
43 | #include "gen-semantics.h" | |
687f3f1c | 44 | #include "gen-engine.h" |
d4f1c49e | 45 | #include "gen-support.h" |
687f3f1c | 46 | #include "gen-engine.h" |
d4f1c49e | 47 | |
d4f1c49e DE |
48 | |
49 | /****************************************************************/ | |
50 | ||
51 | ||
52 | /* Semantic functions */ | |
53 | ||
54 | int | |
687f3f1c AC |
55 | print_semantic_function_formal (lf *file, |
56 | int nr_prefetched_words) | |
d4f1c49e | 57 | { |
687f3f1c AC |
58 | int nr = 0; |
59 | int word_nr; | |
60 | if (options.gen.icache || nr_prefetched_words < 0) | |
61 | { | |
62 | nr += lf_printf (file, "SIM_DESC sd,\n"); | |
63 | nr += lf_printf (file, "%sidecode_cache *cache_entry,\n", | |
64 | options.prefix.global.name); | |
65 | nr += lf_printf (file, "%sinstruction_address cia", | |
66 | options.prefix.global.name); | |
67 | } | |
68 | else if (options.gen.smp) | |
69 | { | |
70 | nr += lf_printf (file, "sim_cpu *cpu,\n"); | |
71 | for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++) | |
72 | { | |
73 | nr += lf_printf (file, "%sinstruction_word instruction_%d,\n", | |
74 | options.prefix.global.name, | |
75 | word_nr); | |
76 | } | |
77 | nr += lf_printf (file, "%sinstruction_address cia", | |
78 | options.prefix.global.name); | |
79 | } | |
d4f1c49e | 80 | else |
687f3f1c AC |
81 | { |
82 | nr += lf_printf (file, "SIM_DESC sd,\n"); | |
83 | for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++) | |
84 | { | |
85 | nr += lf_printf (file, "%sinstruction_word instruction_%d,\n", | |
86 | options.prefix.global.name, | |
87 | word_nr); | |
88 | } | |
89 | nr += lf_printf (file, "%sinstruction_address cia", | |
90 | options.prefix.global.name); | |
91 | } | |
d4f1c49e DE |
92 | return nr; |
93 | } | |
94 | ||
95 | int | |
687f3f1c AC |
96 | print_semantic_function_actual (lf *file, |
97 | int nr_prefetched_words) | |
d4f1c49e | 98 | { |
687f3f1c AC |
99 | int nr = 0; |
100 | int word_nr; | |
101 | if (options.gen.icache || nr_prefetched_words < 0) | |
102 | { | |
103 | nr += lf_printf (file, "sd, cache_entry, cia"); | |
104 | } | |
d4f1c49e | 105 | else |
687f3f1c AC |
106 | { |
107 | if (options.gen.smp) | |
108 | nr += lf_printf (file, "cpu"); | |
109 | else | |
110 | nr += lf_printf (file, "sd"); | |
111 | for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++) | |
112 | nr += lf_printf (file, ", instruction_%d", word_nr); | |
113 | nr += lf_printf (file, ", cia"); | |
114 | } | |
d4f1c49e DE |
115 | return nr; |
116 | } | |
117 | ||
118 | int | |
687f3f1c | 119 | print_semantic_function_type (lf *file) |
d4f1c49e | 120 | { |
687f3f1c AC |
121 | int nr = 0; |
122 | nr += lf_printf (file, "%sinstruction_address", | |
123 | options.prefix.global.name); | |
d4f1c49e DE |
124 | return nr; |
125 | } | |
126 | ||
127 | ||
128 | /* Idecode functions */ | |
129 | ||
130 | int | |
687f3f1c AC |
131 | print_icache_function_formal (lf *file, |
132 | int nr_prefetched_words) | |
d4f1c49e DE |
133 | { |
134 | int nr = 0; | |
687f3f1c AC |
135 | int word_nr; |
136 | if (options.gen.smp) | |
137 | nr += lf_printf (file, "sim_cpu *cpu,\n"); | |
d4f1c49e | 138 | else |
687f3f1c AC |
139 | nr += lf_printf (file, "SIM_DESC sd,\n"); |
140 | for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++) | |
141 | nr += lf_printf (file, " %sinstruction_word instruction_%d,\n", | |
142 | options.prefix.global.name, word_nr); | |
143 | nr += lf_printf (file, " %sinstruction_address cia,\n", | |
144 | options.prefix.global.name); | |
145 | nr += lf_printf (file, " %sidecode_cache *cache_entry", | |
146 | options.prefix.global.name); | |
d4f1c49e DE |
147 | return nr; |
148 | } | |
149 | ||
150 | int | |
687f3f1c AC |
151 | print_icache_function_actual (lf *file, |
152 | int nr_prefetched_words) | |
d4f1c49e | 153 | { |
687f3f1c AC |
154 | int nr = 0; |
155 | int word_nr; | |
156 | if (options.gen.smp) | |
157 | nr += lf_printf (file, "cpu"); | |
d4f1c49e | 158 | else |
687f3f1c AC |
159 | nr += lf_printf (file, "sd"); |
160 | for (word_nr = 0; word_nr < nr_prefetched_words; word_nr++) | |
161 | nr += lf_printf (file, ", instruction_%d", word_nr); | |
162 | nr += lf_printf (file, ", cia, cache_entry"); | |
d4f1c49e DE |
163 | return nr; |
164 | } | |
165 | ||
166 | int | |
687f3f1c | 167 | print_icache_function_type (lf *file) |
d4f1c49e DE |
168 | { |
169 | int nr; | |
687f3f1c AC |
170 | if (options.gen.semantic_icache) |
171 | { | |
172 | nr = print_semantic_function_type (file); | |
173 | } | |
d4f1c49e | 174 | else |
687f3f1c AC |
175 | { |
176 | nr = lf_printf (file, "%sidecode_semantic *", | |
177 | options.prefix.global.name); | |
178 | } | |
d4f1c49e DE |
179 | return nr; |
180 | } | |
181 | ||
182 | ||
183 | /* Function names */ | |
184 | ||
185 | static int | |
687f3f1c AC |
186 | print_opcode_bits (lf *file, |
187 | opcode_bits *bits) | |
d4f1c49e DE |
188 | { |
189 | int nr = 0; | |
190 | if (bits == NULL) | |
191 | return nr; | |
687f3f1c AC |
192 | nr += lf_putchr (file, '_'); |
193 | nr += lf_putstr (file, bits->field->val_string); | |
d4f1c49e | 194 | if (bits->opcode->is_boolean && bits->value == 0) |
687f3f1c | 195 | nr += lf_putint (file, bits->opcode->boolean_constant); |
d4f1c49e DE |
196 | else if (!bits->opcode->is_boolean) { |
197 | if (bits->opcode->last < bits->field->last) | |
687f3f1c | 198 | nr += lf_putint (file, bits->value << (bits->field->last - bits->opcode->last)); |
d4f1c49e | 199 | else |
687f3f1c | 200 | nr += lf_putint (file, bits->value); |
d4f1c49e | 201 | } |
687f3f1c AC |
202 | nr += print_opcode_bits (file, bits->next); |
203 | return nr; | |
204 | } | |
205 | ||
206 | static int | |
207 | print_c_name (lf *file, | |
208 | const char *name) | |
209 | { | |
210 | int nr = 0; | |
211 | const char *pos; | |
212 | for (pos = name; *pos != '\0'; pos++) | |
213 | { | |
214 | switch (*pos) | |
215 | { | |
216 | case '/': | |
217 | case '-': | |
218 | break; | |
219 | case ' ': | |
220 | case '.': | |
221 | nr += lf_putchr (file, '_'); | |
222 | break; | |
223 | default: | |
224 | nr += lf_putchr (file, *pos); | |
225 | break; | |
226 | } | |
227 | } | |
d4f1c49e DE |
228 | return nr; |
229 | } | |
230 | ||
231 | extern int | |
687f3f1c AC |
232 | print_function_name (lf *file, |
233 | const char *basename, | |
234 | const char *format_name, | |
235 | const char *model_name, | |
236 | opcode_bits *expanded_bits, | |
237 | lf_function_name_prefixes prefix) | |
d4f1c49e DE |
238 | { |
239 | int nr = 0; | |
240 | /* the prefix */ | |
687f3f1c AC |
241 | switch (prefix) |
242 | { | |
243 | case function_name_prefix_semantics: | |
244 | nr += lf_printf (file, "%s", options.prefix.semantics.name); | |
245 | nr += lf_printf (file, "semantic_"); | |
246 | break; | |
247 | case function_name_prefix_idecode: | |
248 | nr += lf_printf (file, "%s", options.prefix.idecode.name); | |
249 | nr += lf_printf (file, "idecode_"); | |
250 | break; | |
251 | case function_name_prefix_itable: | |
252 | nr += lf_printf (file, "%sitable_", options.prefix.itable.name); | |
253 | break; | |
254 | case function_name_prefix_icache: | |
255 | nr += lf_printf (file, "%s", options.prefix.icache.name); | |
256 | nr += lf_printf (file, "icache_"); | |
257 | break; | |
258 | case function_name_prefix_engine: | |
259 | nr += lf_printf (file, "%s", options.prefix.engine.name); | |
260 | nr += lf_printf (file, "engine_"); | |
261 | default: | |
262 | break; | |
263 | } | |
264 | ||
265 | if (model_name != NULL) | |
266 | { | |
267 | nr += print_c_name (file, model_name); | |
268 | nr += lf_printf (file, "_"); | |
269 | } | |
d4f1c49e | 270 | |
6a4c8f1e AC |
271 | /* the function name */ |
272 | nr += print_c_name (file, basename); | |
273 | ||
687f3f1c AC |
274 | /* the format name if available */ |
275 | if (format_name != NULL) | |
276 | { | |
687f3f1c | 277 | nr += lf_printf (file, "_"); |
4410c4b9 | 278 | nr += print_c_name (file, format_name); |
d4f1c49e | 279 | } |
d4f1c49e DE |
280 | |
281 | /* the suffix */ | |
687f3f1c | 282 | nr += print_opcode_bits (file, expanded_bits); |
d4f1c49e DE |
283 | |
284 | return nr; | |
285 | } | |
286 | ||
287 | ||
288 | void | |
efe4f1cb | 289 | print_my_defines (lf *file, |
687f3f1c AC |
290 | const char *basename, |
291 | const char *format_name, | |
292 | opcode_bits *expanded_bits) | |
d4f1c49e DE |
293 | { |
294 | /* #define MY_INDEX xxxxx */ | |
efe4f1cb AC |
295 | lf_indent_suppress (file); |
296 | lf_printf (file, "#undef MY_INDEX\n"); | |
297 | lf_indent_suppress (file); | |
298 | lf_printf (file, "#define MY_INDEX "); | |
299 | print_function_name (file, | |
687f3f1c | 300 | basename, format_name, NULL, |
efe4f1cb AC |
301 | NULL, |
302 | function_name_prefix_itable); | |
303 | lf_printf (file, "\n"); | |
d4f1c49e | 304 | /* #define MY_PREFIX xxxxxx */ |
efe4f1cb | 305 | lf_indent_suppress (file); |
687f3f1c AC |
306 | lf_printf (file, "#undef "); |
307 | print_function_name (file, | |
308 | basename, format_name, NULL, | |
309 | expanded_bits, | |
310 | function_name_prefix_none); | |
311 | lf_printf (file, "\n"); | |
312 | lf_indent_suppress (file); | |
efe4f1cb AC |
313 | lf_printf (file, "#undef MY_PREFIX\n"); |
314 | lf_indent_suppress (file); | |
315 | lf_printf (file, "#define MY_PREFIX "); | |
316 | print_function_name (file, | |
687f3f1c | 317 | basename, format_name, NULL, |
efe4f1cb AC |
318 | expanded_bits, |
319 | function_name_prefix_none); | |
320 | lf_printf (file, "\n"); | |
687f3f1c AC |
321 | /* #define MY_NAME xxxxxx */ |
322 | lf_indent_suppress (file); | |
323 | lf_indent_suppress (file); | |
324 | lf_printf (file, "#undef MY_NAME\n"); | |
325 | lf_indent_suppress (file); | |
326 | lf_printf (file, "#define MY_NAME \""); | |
327 | print_function_name (file, | |
328 | basename, format_name, NULL, | |
329 | expanded_bits, | |
330 | function_name_prefix_none); | |
331 | lf_printf (file, "\"\n"); | |
efe4f1cb AC |
332 | } |
333 | ||
334 | ||
335 | static int | |
336 | print_itrace_prefix (lf *file, | |
efe4f1cb AC |
337 | const char *phase_lc) |
338 | { | |
339 | const char *prefix = "trace_one_insn ("; | |
340 | int indent = strlen (prefix); | |
d5cecca9 | 341 | lf_printf (file, "%sSD, CPU, %s, TRACE_LINENUM_P (CPU), \\\n", |
687f3f1c | 342 | prefix, (options.gen.delayed_branch ? "cia.ip" : "cia")); |
efe4f1cb | 343 | lf_indent (file, +indent); |
d5cecca9 AC |
344 | lf_printf (file, "%sitable[MY_INDEX].file, \\\n", options.prefix.itable.name); |
345 | lf_printf (file, "%sitable[MY_INDEX].line_nr, \\\n", options.prefix.itable.name); | |
346 | lf_printf (file, "\"%s\", \\\n", phase_lc); | |
687f3f1c | 347 | lf_printf (file, "\"%%-18s - "); |
efe4f1cb AC |
348 | return indent; |
349 | } | |
350 | ||
351 | ||
352 | static void | |
353 | print_itrace_format (lf *file, | |
687f3f1c | 354 | insn_mnemonic_entry *assembler) |
efe4f1cb AC |
355 | { |
356 | /* pass=1 is fmt string; pass=2 is is arguments */ | |
357 | int pass; | |
efe4f1cb AC |
358 | /* print the format string */ |
359 | for (pass = 1; pass <= 2; pass++) | |
360 | { | |
361 | const char *chp = assembler->format; | |
362 | chp++; /* skip the leading quote */ | |
363 | /* prefix the format with the insn `name' */ | |
687f3f1c | 364 | if (pass == 2) |
efe4f1cb | 365 | { |
d5cecca9 | 366 | lf_printf (file, ", \\\n"); |
687f3f1c | 367 | lf_printf (file, "%sitable[MY_INDEX].name", options.prefix.itable.name); |
efe4f1cb AC |
368 | } |
369 | /* write out the format/args */ | |
370 | while (*chp != '\0') | |
371 | { | |
372 | if (chp[0] == '\\' && (chp[1] == '<' || chp[1] == '>')) | |
373 | { | |
374 | if (pass == 1) | |
375 | lf_putchr (file, chp[1]); | |
376 | chp += 2; | |
377 | } | |
378 | else if (chp[0] == '<' || chp[0] == '%') | |
379 | { | |
380 | /* parse [ "%" ... ] "<" [ func "#" ] param ">" */ | |
381 | const char *fmt; | |
382 | const char *func; | |
383 | int strlen_func; | |
384 | const char *param; | |
385 | int strlen_param; | |
386 | /* the "%" ... "<" format */ | |
387 | fmt = chp; | |
388 | while (chp[0] != '<' && chp[0] != '\0') | |
389 | chp++; | |
390 | if (chp[0] != '<') | |
687f3f1c | 391 | error (assembler->line, "Missing `<' after `%%'\n"); |
efe4f1cb AC |
392 | chp++; |
393 | /* [ "func" # ] OR "param" */ | |
394 | func = chp; | |
395 | param = chp; | |
396 | while (chp[0] != '>' && chp[0] != '#' && chp[0] != '\0') | |
397 | chp++; | |
398 | strlen_func = chp - func; | |
399 | if (chp[0] == '#') | |
400 | { | |
401 | chp++; | |
402 | param = chp; | |
403 | while (chp[0] != '>' && chp[0] != '\0') | |
404 | chp++; | |
405 | } | |
406 | strlen_param = chp - param; | |
407 | if (chp[0] != '>') | |
687f3f1c | 408 | error (assembler->line, "Missing closing `>' in assembler string\n"); |
efe4f1cb AC |
409 | chp++; |
410 | /* now process it */ | |
411 | if (pass == 2) | |
d5cecca9 | 412 | lf_printf (file, ", \\\n"); |
efe4f1cb AC |
413 | if (strncmp (fmt, "<", 1) == 0) |
414 | /* implicit long int format */ | |
415 | { | |
416 | if (pass == 1) | |
417 | lf_printf (file, "%%ld"); | |
418 | else | |
419 | { | |
420 | lf_printf (file, "(long) "); | |
421 | lf_write (file, param, strlen_param); | |
422 | } | |
423 | } | |
424 | else if (strncmp (fmt, "%<", 2) == 0) | |
425 | /* explicit format */ | |
426 | { | |
427 | if (pass == 1) | |
428 | lf_printf (file, "%%"); | |
429 | else | |
430 | lf_write (file, param, strlen_param); | |
431 | } | |
432 | else if (strncmp (fmt, "%s<", 3) == 0) | |
433 | /* string format */ | |
434 | { | |
435 | if (pass == 1) | |
436 | lf_printf (file, "%%s"); | |
437 | else | |
438 | { | |
687f3f1c | 439 | lf_printf (file, "%sstr_", options.prefix.global.name); |
efe4f1cb | 440 | lf_write (file, func, strlen_func); |
a2ab5e65 | 441 | lf_printf (file, " (SD_, "); |
efe4f1cb AC |
442 | lf_write (file, param, strlen_param); |
443 | lf_printf (file, ")"); | |
444 | } | |
445 | } | |
446 | else if (strncmp (fmt, "%lx<", 4) == 0) | |
447 | /* simple hex */ | |
448 | { | |
449 | if (pass == 1) | |
450 | lf_printf (file, "%%lx"); | |
451 | else | |
452 | { | |
453 | lf_printf (file, "(unsigned long) "); | |
454 | lf_write (file, param, strlen_param); | |
455 | } | |
456 | } | |
457 | else if (strncmp (fmt, "%08lx<", 6) == 0) | |
458 | /* simple hex */ | |
459 | { | |
460 | if (pass == 1) | |
461 | lf_printf (file, "%%08lx"); | |
462 | else | |
463 | { | |
464 | lf_printf (file, "(unsigned long) "); | |
465 | lf_write (file, param, strlen_param); | |
466 | } | |
467 | } | |
468 | else | |
687f3f1c | 469 | error (assembler->line, "Unknown assembler string format\n"); |
efe4f1cb AC |
470 | } |
471 | else | |
472 | { | |
473 | if (pass == 1) | |
474 | lf_putchr (file, chp[0]); | |
475 | chp += 1; | |
476 | } | |
477 | } | |
478 | } | |
479 | lf_printf (file, ");\n"); | |
d4f1c49e DE |
480 | } |
481 | ||
482 | ||
483 | void | |
efe4f1cb | 484 | print_itrace (lf *file, |
687f3f1c | 485 | insn_entry *insn, |
efe4f1cb | 486 | int idecode) |
d4f1c49e | 487 | { |
d5cecca9 AC |
488 | /* NB: Here we escape each eoln. This is so that the the compiler |
489 | treats a trace function call as a single line. Consequently any | |
490 | errors in the line are refered back to the same igen assembler | |
491 | source line */ | |
d0adfefd MM |
492 | const char *phase = (idecode) ? "DECODE" : "INSN"; |
493 | const char *phase_lc = (idecode) ? "decode" : "insn"; | |
efe4f1cb AC |
494 | lf_printf (file, "\n"); |
495 | lf_indent_suppress (file); | |
496 | lf_printf (file, "#if defined (WITH_TRACE)\n"); | |
497 | lf_printf (file, "/* trace the instructions execution if enabled */\n"); | |
8782bfcf | 498 | lf_printf (file, "if (TRACE_%s_P (CPU))\n", phase); |
687f3f1c | 499 | if (insn->mnemonics != NULL) |
efe4f1cb | 500 | { |
687f3f1c | 501 | insn_mnemonic_entry *assembler = insn->mnemonics; |
efe4f1cb | 502 | int is_first = 1; |
d5cecca9 AC |
503 | lf_printf (file, " {\n"); |
504 | lf_indent (file, +4); | |
efe4f1cb AC |
505 | do |
506 | { | |
507 | if (assembler->condition != NULL) | |
508 | { | |
509 | int indent; | |
510 | lf_printf (file, "%sif (%s)\n", | |
511 | is_first ? "" : "else ", | |
512 | assembler->condition); | |
513 | lf_indent (file, +2); | |
d5cecca9 | 514 | lf_print__line_ref (file, assembler->line); |
687f3f1c | 515 | indent = print_itrace_prefix (file, phase_lc); |
efe4f1cb | 516 | print_itrace_format (file, assembler); |
d5cecca9 | 517 | lf_print__internal_ref (file); |
efe4f1cb AC |
518 | lf_indent (file, -indent); |
519 | lf_indent (file, -2); | |
520 | if (assembler->next == NULL) | |
687f3f1c | 521 | error (assembler->line, "Missing final unconditional assembler\n"); |
efe4f1cb AC |
522 | } |
523 | else | |
524 | { | |
525 | int indent; | |
526 | if (!is_first) | |
527 | { | |
528 | lf_printf (file, "else\n"); | |
529 | lf_indent (file, +2); | |
530 | } | |
d5cecca9 | 531 | lf_print__line_ref (file, assembler->line); |
687f3f1c | 532 | indent = print_itrace_prefix (file, phase_lc); |
efe4f1cb | 533 | print_itrace_format (file, assembler); |
d5cecca9 | 534 | lf_print__internal_ref (file); |
efe4f1cb AC |
535 | lf_indent (file, -indent); |
536 | if (!is_first) | |
537 | lf_indent (file, -2); | |
538 | if (assembler->next != NULL) | |
687f3f1c | 539 | error (assembler->line, "Unconditional assembler is not last\n"); |
efe4f1cb AC |
540 | } |
541 | is_first = 0; | |
542 | assembler = assembler->next; | |
543 | } | |
544 | while (assembler != NULL); | |
d5cecca9 AC |
545 | lf_indent (file, -4); |
546 | lf_printf (file, " }\n"); | |
efe4f1cb AC |
547 | } |
548 | else | |
549 | { | |
d5cecca9 AC |
550 | int indent; |
551 | lf_indent (file, +2); | |
552 | lf_print__line_ref (file, insn->line); | |
553 | indent = print_itrace_prefix (file, phase_lc); | |
554 | lf_printf (file, "?\", \\\n"); | |
687f3f1c | 555 | lf_printf (file, "itable[MY_INDEX].name);\n"); |
d5cecca9 | 556 | lf_print__internal_ref (file); |
efe4f1cb | 557 | lf_indent (file, -indent); |
d5cecca9 | 558 | lf_indent (file, -2); |
efe4f1cb | 559 | } |
efe4f1cb AC |
560 | lf_indent_suppress (file); |
561 | lf_printf (file, "#endif\n"); | |
d4f1c49e DE |
562 | } |
563 | ||
564 | ||
687f3f1c AC |
565 | void |
566 | print_sim_engine_abort (lf *file, | |
567 | const char *message) | |
568 | { | |
569 | lf_printf (file, "sim_engine_abort (SD, CPU, cia, "); | |
570 | lf_printf (file, "\"%s\"", message); | |
571 | lf_printf (file, ");\n"); | |
572 | } | |
573 | ||
574 | ||
d4f1c49e DE |
575 | /****************************************************************/ |
576 | ||
577 | ||
578 | static void | |
687f3f1c AC |
579 | gen_semantics_h (lf *file, |
580 | insn_list *semantics, | |
581 | int max_nr_words) | |
d4f1c49e | 582 | { |
687f3f1c AC |
583 | int word_nr; |
584 | insn_list *semantic; | |
585 | for (word_nr = -1; word_nr <= max_nr_words; word_nr++) | |
586 | { | |
587 | lf_printf (file, "typedef "); | |
588 | print_semantic_function_type (file); | |
589 | lf_printf (file, " %sidecode_semantic", | |
590 | options.prefix.global.name); | |
591 | if (word_nr >= 0) | |
592 | lf_printf (file, "_%d", word_nr); | |
593 | lf_printf (file, "\n("); | |
594 | lf_indent (file, +1); | |
595 | print_semantic_function_formal (file, word_nr); | |
596 | lf_indent (file, -1); | |
597 | lf_printf (file, ");\n"); | |
598 | lf_printf (file, "\n"); | |
599 | } | |
600 | switch (options.gen.code) | |
601 | { | |
602 | case generate_calls: | |
603 | for (semantic = semantics; semantic != NULL; semantic = semantic->next) | |
604 | { | |
605 | /* Ignore any special/internal instructions */ | |
606 | if (semantic->insn->nr_words == 0) | |
607 | continue; | |
608 | print_semantic_declaration (file, | |
609 | semantic->insn, | |
610 | semantic->expanded_bits, | |
611 | semantic->opcodes, | |
612 | semantic->nr_prefetched_words); | |
613 | } | |
614 | break; | |
615 | case generate_jumps: | |
616 | lf_print__this_file_is_empty (file, "generating jumps"); | |
617 | break; | |
618 | } | |
d4f1c49e DE |
619 | } |
620 | ||
621 | ||
622 | static void | |
687f3f1c AC |
623 | gen_semantics_c (lf *file, |
624 | insn_list *semantics, | |
625 | cache_entry *cache_rules) | |
d4f1c49e | 626 | { |
687f3f1c AC |
627 | if (options.gen.code == generate_calls) |
628 | { | |
629 | insn_list *semantic; | |
630 | lf_printf (file, "\n"); | |
631 | lf_printf (file, "#include \"sim-main.h\"\n"); | |
632 | lf_printf (file, "#include \"%sitable.h\"\n", | |
633 | options.prefix.itable.name); | |
634 | lf_printf (file, "#include \"%sidecode.h\"\n", | |
635 | options.prefix.idecode.name); | |
636 | lf_printf (file, "#include \"%ssemantics.h\"\n", | |
637 | options.prefix.semantics.name); | |
638 | lf_printf (file, "#include \"%ssupport.h\"\n", | |
639 | options.prefix.support.name); | |
640 | lf_printf (file, "\n"); | |
641 | for (semantic = semantics; semantic != NULL; semantic = semantic->next) | |
642 | { | |
643 | /* Ignore any special/internal instructions */ | |
644 | if (semantic->insn->nr_words == 0) | |
645 | continue; | |
646 | print_semantic_definition (file, | |
647 | semantic->insn, | |
648 | semantic->expanded_bits, | |
649 | semantic->opcodes, | |
650 | cache_rules, | |
651 | semantic->nr_prefetched_words); | |
652 | } | |
653 | } | |
654 | else | |
655 | { | |
656 | lf_print__this_file_is_empty (file, "generating jump engine"); | |
657 | } | |
d4f1c49e DE |
658 | } |
659 | ||
660 | ||
661 | /****************************************************************/ | |
662 | ||
663 | ||
664 | static void | |
687f3f1c AC |
665 | gen_icache_h (lf *file, |
666 | insn_list *semantic, | |
667 | function_entry *functions, | |
668 | int max_nr_words) | |
d4f1c49e | 669 | { |
687f3f1c AC |
670 | int word_nr; |
671 | for (word_nr = 0; word_nr <= max_nr_words; word_nr++) | |
672 | { | |
673 | lf_printf (file, "typedef "); | |
674 | print_icache_function_type(file); | |
675 | lf_printf (file, " %sidecode_icache_%d\n(", | |
676 | options.prefix.global.name, | |
677 | word_nr); | |
678 | print_icache_function_formal(file, word_nr); | |
679 | lf_printf (file, ");\n"); | |
680 | lf_printf (file, "\n"); | |
681 | } | |
682 | if (options.gen.code == generate_calls | |
683 | && options.gen.icache) | |
684 | { | |
685 | function_entry_traverse (file, functions, | |
686 | print_icache_internal_function_declaration, | |
687 | NULL); | |
688 | while (semantic != NULL) | |
689 | { | |
690 | print_icache_declaration (file, | |
691 | semantic->insn, | |
692 | semantic->expanded_bits, | |
693 | semantic->opcodes, | |
694 | semantic->nr_prefetched_words); | |
695 | semantic = semantic->next; | |
696 | } | |
697 | } | |
698 | else | |
699 | { | |
700 | lf_print__this_file_is_empty (file, "generating jump engine"); | |
701 | } | |
d4f1c49e DE |
702 | } |
703 | ||
704 | static void | |
687f3f1c AC |
705 | gen_icache_c (lf *file, |
706 | insn_list *semantic, | |
707 | function_entry *functions, | |
708 | cache_entry *cache_rules) | |
d4f1c49e DE |
709 | { |
710 | /* output `internal' invalid/floating-point unavailable functions | |
711 | where needed */ | |
687f3f1c AC |
712 | if (options.gen.code == generate_calls |
713 | && options.gen.icache) | |
714 | { | |
715 | lf_printf (file, "\n"); | |
716 | lf_printf (file, "#include \"cpu.h\"\n"); | |
717 | lf_printf (file, "#include \"idecode.h\"\n"); | |
718 | lf_printf (file, "#include \"semantics.h\"\n"); | |
719 | lf_printf (file, "#include \"icache.h\"\n"); | |
720 | lf_printf (file, "#include \"support.h\"\n"); | |
721 | lf_printf (file, "\n"); | |
722 | function_entry_traverse (file, functions, | |
723 | print_icache_internal_function_definition, | |
724 | NULL); | |
725 | lf_printf (file, "\n"); | |
726 | while (semantic != NULL) | |
727 | { | |
728 | print_icache_definition (file, | |
729 | semantic->insn, | |
730 | semantic->expanded_bits, | |
731 | semantic->opcodes, | |
732 | cache_rules, | |
733 | semantic->nr_prefetched_words); | |
734 | semantic = semantic->next; | |
735 | } | |
736 | } | |
737 | else | |
738 | { | |
739 | lf_print__this_file_is_empty (file, "generating jump engine"); | |
740 | } | |
741 | } | |
742 | ||
743 | ||
744 | /****************************************************************/ | |
745 | ||
746 | ||
747 | static void | |
748 | gen_idecode_h (lf *file, | |
749 | gen_table *gen, | |
750 | insn_table *insns, | |
751 | cache_entry *cache_rules) | |
752 | { | |
753 | lf_printf (file, "typedef unsigned%d %sinstruction_word;\n", | |
754 | options.insn_bit_size, options.prefix.global.name); | |
755 | if (options.gen.delayed_branch) | |
756 | { | |
757 | lf_printf (file, "typedef struct _%sinstruction_address {\n", | |
758 | options.prefix.global.name); | |
759 | lf_printf (file, " address_word ip; /* instruction pointer */\n"); | |
760 | lf_printf (file, " address_word dp; /* delayed-slot pointer */\n"); | |
761 | lf_printf (file, "} %sinstruction_address;\n", options.prefix.global.name); | |
762 | } | |
763 | else | |
764 | { | |
765 | lf_printf (file, "typedef address_word %sinstruction_address;\n", | |
766 | options.prefix.global.name); | |
767 | ||
768 | } | |
769 | if (options.gen.nia == nia_is_invalid | |
770 | && strlen (options.prefix.global.uname) > 0) | |
771 | { | |
772 | lf_indent_suppress (file); | |
773 | lf_printf (file, "#define %sINVALID_INSTRUCTION_ADDRESS ", | |
774 | options.prefix.global.uname); | |
775 | lf_printf (file, "INVALID_INSTRUCTION_ADDRESS\n"); | |
776 | } | |
777 | lf_printf (file, "\n"); | |
778 | print_icache_struct (file, insns, cache_rules); | |
779 | lf_printf (file, "\n"); | |
780 | if (options.gen.icache) | |
781 | { | |
782 | ERROR ("FIXME - idecode with icache suffering from bit-rot"); | |
783 | } | |
784 | else | |
785 | { | |
786 | gen_list *entry; | |
787 | for (entry = gen->tables; entry != NULL; entry = entry->next) | |
788 | { | |
789 | print_idecode_issue_function_header (file, | |
790 | entry->processor, | |
791 | 0/*is definition*/, | |
792 | 1/*ALWAYS ONE WORD*/); | |
793 | } | |
794 | } | |
795 | } | |
796 | ||
797 | ||
798 | static void | |
799 | gen_idecode_c (lf *file, | |
800 | gen_table *gen, | |
801 | insn_table *isa, | |
802 | cache_entry *cache_rules) | |
803 | { | |
804 | /* the intro */ | |
805 | lf_printf (file, "#include \"sim-main.h\"\n"); | |
806 | lf_printf (file, "#include \"%sidecode.h\"\n", options.prefix.global.name); | |
807 | lf_printf (file, "#include \"%ssemantics.h\"\n", options.prefix.global.name); | |
808 | lf_printf (file, "#include \"%sicache.h\"\n", options.prefix.global.name); | |
809 | lf_printf (file, "#include \"%ssupport.h\"\n", options.prefix.global.name); | |
810 | lf_printf (file, "\n"); | |
811 | lf_printf (file, "\n"); | |
812 | ||
813 | print_idecode_globals (file); | |
814 | lf_printf (file, "\n"); | |
815 | ||
816 | switch (options.gen.code) | |
817 | { | |
818 | case generate_calls: | |
819 | { | |
820 | gen_list *entry; | |
821 | for (entry = gen->tables; entry != NULL; entry = entry->next) | |
822 | { | |
823 | print_idecode_lookups (file, entry->table, cache_rules); | |
824 | ||
825 | /* output the main idecode routine */ | |
826 | if (!options.gen.icache) | |
827 | { | |
828 | print_idecode_issue_function_header (file, | |
829 | entry->processor, | |
830 | 1/*is definition*/, | |
831 | 1/*ALWAYS ONE WORD*/); | |
832 | lf_printf (file, "{\n"); | |
833 | lf_indent (file, +2); | |
834 | lf_printf (file, "%sinstruction_address nia;\n", | |
835 | options.prefix.global.name); | |
836 | print_idecode_body (file, entry->table, "nia ="); | |
837 | lf_printf (file, "return nia;"); | |
838 | lf_indent (file, -2); | |
839 | lf_printf (file, "}\n"); | |
840 | } | |
841 | } | |
842 | break; | |
843 | } | |
844 | case generate_jumps: | |
845 | { | |
846 | lf_print__this_file_is_empty (file, "generating a jump engine"); | |
847 | break; | |
848 | } | |
849 | } | |
d4f1c49e DE |
850 | } |
851 | ||
852 | ||
853 | /****************************************************************/ | |
854 | ||
855 | ||
687f3f1c AC |
856 | static void |
857 | gen_run_c (lf *file, | |
858 | gen_table *gen) | |
859 | { | |
860 | gen_list *entry; | |
861 | lf_printf (file, "#include \"sim-main.h\"\n"); | |
862 | lf_printf (file, "#include \"engine.h\"\n"); | |
863 | lf_printf (file, "#include \"bfd.h\"\n"); | |
864 | lf_printf (file, "\n"); | |
865 | lf_printf (file, "void\n"); | |
866 | lf_printf (file, "sim_engine_run (SIM_DESC sd,\n"); | |
867 | lf_printf (file, " int next_cpu_nr,\n"); | |
868 | lf_printf (file, " int siggnal)\n"); | |
869 | lf_printf (file, "{\n"); | |
870 | lf_indent (file, +2); | |
06042536 | 871 | if (options.gen.multi_sim) |
687f3f1c | 872 | { |
06042536 AC |
873 | lf_printf (file, "int mach;\n"); |
874 | lf_printf (file, "if (STATE_ARCHITECTURE (sd) == NULL)\n"); | |
875 | lf_printf (file, " mach = 0;\n"); | |
876 | lf_printf (file, "else\n"); | |
877 | lf_printf (file, " mach = STATE_ARCHITECTURE (sd)->mach;\n"); | |
878 | lf_printf (file, "switch (mach)\n"); | |
879 | lf_printf (file, " {\n"); | |
880 | lf_indent (file, +2); | |
881 | for (entry = gen->tables; entry != NULL; entry = entry->next) | |
882 | { | |
883 | lf_printf (file, "case bfd_mach_%s:\n", entry->processor); | |
884 | lf_indent (file, +2); | |
885 | print_function_name (file, | |
886 | "run", | |
887 | NULL, /* format name */ | |
888 | entry->processor, | |
889 | NULL, /* expanded bits */ | |
890 | function_name_prefix_engine); | |
891 | lf_printf (file, " (sd, next_cpu_nr, siggnal);\n"); | |
892 | lf_printf (file, "break;\n"); | |
893 | lf_indent (file, -2); | |
894 | } | |
895 | lf_printf (file, "default:\n"); | |
687f3f1c | 896 | lf_indent (file, +2); |
06042536 AC |
897 | lf_printf (file, "sim_engine_abort (sd, NULL, NULL_CIA,\n"); |
898 | lf_printf (file, " \"sim_engine_run - unknown machine\");\n"); | |
899 | lf_printf (file, "break;\n"); | |
900 | lf_indent (file, -2); | |
901 | lf_indent (file, -2); | |
902 | lf_printf (file, " }\n"); | |
903 | } | |
904 | else | |
905 | { | |
687f3f1c AC |
906 | print_function_name (file, |
907 | "run", | |
908 | NULL, /* format name */ | |
06042536 | 909 | NULL, /* NO processor */ |
687f3f1c AC |
910 | NULL, /* expanded bits */ |
911 | function_name_prefix_engine); | |
912 | lf_printf (file, " (sd, next_cpu_nr, siggnal);\n"); | |
687f3f1c | 913 | } |
687f3f1c AC |
914 | lf_indent (file, -2); |
915 | lf_printf (file, "}\n"); | |
916 | } | |
917 | ||
687f3f1c AC |
918 | /****************************************************************/ |
919 | ||
920 | static gen_table * | |
921 | do_gen (insn_table *isa, | |
922 | decode_table *decode_rules) | |
923 | { | |
924 | gen_table *gen; | |
925 | if (decode_rules == NULL) | |
926 | error (NULL, "Must specify a decode table\n"); | |
927 | if (isa == NULL) | |
928 | error (NULL, "Must specify an instruction table\n"); | |
929 | if (decode_table_max_word_nr (decode_rules) > 0) | |
930 | options.gen.multi_word = decode_table_max_word_nr (decode_rules); | |
931 | gen = make_gen_tables (isa, decode_rules); | |
932 | gen_tables_expand_insns (gen); | |
933 | gen_tables_expand_semantics (gen); | |
934 | return gen; | |
935 | } | |
936 | ||
937 | /****************************************************************/ | |
938 | ||
939 | igen_options options; | |
940 | ||
d4f1c49e | 941 | int |
687f3f1c AC |
942 | main (int argc, |
943 | char **argv, | |
944 | char **envp) | |
d4f1c49e | 945 | { |
687f3f1c | 946 | cache_entry *cache_rules = NULL; |
d4f1c49e DE |
947 | lf_file_references file_references = lf_include_references; |
948 | decode_table *decode_rules = NULL; | |
687f3f1c AC |
949 | insn_table *isa = NULL; |
950 | gen_table *gen = NULL; | |
d4f1c49e DE |
951 | char *real_file_name = NULL; |
952 | int is_header = 0; | |
953 | int ch; | |
687f3f1c | 954 | lf *standard_out = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "igen"); |
d4f1c49e | 955 | |
687f3f1c | 956 | INIT_OPTIONS (options); |
d4f1c49e | 957 | |
687f3f1c AC |
958 | if (argc == 1) |
959 | { | |
960 | printf ("Usage:\n"); | |
961 | printf ("\n"); | |
962 | printf (" igen <config-opts> ... <input-opts>... <output-opts>...\n"); | |
963 | printf ("\n"); | |
964 | printf ("Config options:\n"); | |
965 | printf ("\n"); | |
966 | printf (" -B <bit-size>\n"); | |
967 | printf ("\t Set the number of bits in an instruction (depreciated).\n"); | |
968 | printf ("\t This option can now be set directly in the instruction table.\n"); | |
969 | printf ("\n"); | |
970 | printf (" -D <data-structure>\n"); | |
971 | printf ("\t Dump the specified data structure to stdout. Valid structures include:\n"); | |
972 | printf ("\t processor-names - list the names of all the processors (models)\n"); | |
973 | printf ("\n"); | |
974 | printf (" -F <filter-list>\n"); | |
975 | printf ("\t Filter out any instructions with a non-empty flags field that contains\n"); | |
976 | printf ("\t a flag not listed in the <filter-list>.\n"); | |
977 | printf ("\n"); | |
978 | printf (" -H <high-bit>\n"); | |
979 | printf ("\t Set the number of the high (most significant) instruction bit (depreciated).\n"); | |
980 | printf ("\t This option can now be set directly in the instruction table.\n"); | |
981 | printf ("\n"); | |
e2880fad AC |
982 | printf (" -I <directory>\n"); |
983 | printf ("\t Add <directory> to the list of directories searched when opening a file\n"); | |
687f3f1c AC |
984 | printf ("\n"); |
985 | printf (" -M <model-list>\n"); | |
986 | printf ("\t Filter out any instructions that do not support at least one of the listed\n"); | |
987 | printf ("\t models (An instructions with no model information is considered to support\n"); | |
e2880fad | 988 | printf ("\t all models.).\n"); |
687f3f1c AC |
989 | printf ("\n"); |
990 | printf (" -N <nr-cpus>\n"); | |
991 | printf ("\t Generate a simulator supporting <nr-cpus>\n"); | |
992 | printf ("\t Specify `-N 0' to disable generation of the SMP. Specifying `-N 1' will\n"); | |
993 | printf ("\t still generate an SMP enabled simulator but will only support one CPU.\n"); | |
994 | printf ("\n"); | |
995 | printf (" -T <mechanism>\n"); | |
996 | printf ("\t Override the decode mechanism specified by the decode rules\n"); | |
997 | printf ("\n"); | |
998 | printf (" -P <prefix>\n"); | |
999 | printf ("\t Prepend global names (except itable) with the string <prefix>.\n"); | |
1000 | printf ("\t Specify -P <module>=<prefix> to set the <modules> prefix.\n"); | |
1001 | printf ("\n"); | |
1002 | printf (" -Werror\n"); | |
1003 | printf ("\t Make warnings errors\n"); | |
8782bfcf AC |
1004 | printf (" -Wnodiscard\n"); |
1005 | printf ("\t Suppress warnings about discarded instructions\n"); | |
687f3f1c AC |
1006 | printf ("\n"); |
1007 | printf (" -G [!]<gen-option>\n"); | |
1008 | printf ("\t Any of the following options:\n"); | |
1009 | printf ("\n"); | |
1010 | printf ("\t decode-duplicate - Override the decode rules, forcing the duplication of\n"); | |
1011 | printf ("\t semantic functions\n"); | |
1012 | printf ("\t decode-combine - Combine any duplicated entries within a table\n"); | |
1013 | printf ("\t decode-zero-reserved - Override the decode rules, forcing reserved bits to be\n"); | |
1014 | printf ("\t treated as zero.\n"); | |
1015 | printf ("\t decode-switch-is-goto - Overfide the padded-switch code type as a goto-switch\n"); | |
1016 | printf ("\n"); | |
1017 | printf ("\t gen-conditional-issue - conditionally issue each instruction\n"); | |
1018 | printf ("\t gen-delayed-branch - need both cia and nia passed around\n"); | |
1019 | printf ("\t gen-direct-access - use #defines to directly access values\n"); | |
1020 | printf ("\t gen-zero-r<N> - arch assumes GPR(<N>) == 0, keep it that way\n"); | |
e2880fad AC |
1021 | printf ("\t gen-icache[=<N> - generate an instruction cracking cache of size <N>\n"); |
1022 | printf ("\t Default size is %d\n", options.gen.icache_size); | |
687f3f1c AC |
1023 | printf ("\t gen-insn-in-icache - save original instruction when cracking\n"); |
1024 | printf ("\t gen-multi-sim - generate multiple simulators - one per model\n"); | |
1025 | printf ("\t By default, a single simulator that will\n"); | |
1026 | printf ("\t execute any instruction is generated\n"); | |
1027 | printf ("\t gen-multi-word - generate code allowing for multi-word insns\n"); | |
1028 | printf ("\t gen-semantic-icache - include semantic code in cracking functions\n"); | |
1029 | printf ("\t gen-slot-verification - perform slot verification as part of decode\n"); | |
1030 | printf ("\t gen-nia-invalid - NIA defaults to nia_invalid\n"); | |
1031 | printf ("\t gen-nia-void - do not compute/return NIA\n"); | |
1032 | printf ("\n"); | |
1033 | printf ("\t trace-combine - report combined entries a rule application\n"); | |
1034 | printf ("\t trace-entries - report entries after a rules application\n"); | |
1035 | printf ("\t trace-rule-rejection - report each rule as rejected\n"); | |
1036 | printf ("\t trace-rule-selection - report each rule as selected\n"); | |
1037 | printf ("\n"); | |
1038 | printf ("\t field-widths - instruction formats specify widths (depreciated)\n"); | |
1039 | printf ("\t By default, an instruction format specifies bit\n"); | |
1040 | printf ("\t positions\n"); | |
1041 | printf ("\t This option can now be set directly in the\n"); | |
1042 | printf ("\t instruction table\n"); | |
1043 | printf ("\t jumps - use jumps instead of function calls\n"); | |
1044 | printf ("\t omit-line-numbers - do not include line number information in the output\n"); | |
1045 | printf ("\n"); | |
1046 | printf ("Input options:\n"); | |
1047 | printf ("\n"); | |
1048 | printf (" -k <cache-rules> (depreciated)\n"); | |
1049 | printf (" -o <decode-rules>\n"); | |
1050 | printf (" -i <instruction-table>\n"); | |
1051 | printf ("\n"); | |
1052 | printf ("Output options:\n"); | |
1053 | printf ("\n"); | |
1054 | printf (" -x Perform expansion (required)\n"); | |
1055 | printf (" -n <real-name> Specify the real name of the next output file\n"); | |
1056 | printf (" -h Generate the header (.h) file rather than the body (.c)\n"); | |
1057 | printf (" -c <output-file> output icache\n"); | |
1058 | printf (" -d <output-file> output idecode\n"); | |
1059 | printf (" -e <output-file> output engine\n"); | |
1060 | printf (" -f <output-file> output support functions\n"); | |
1061 | printf (" -m <output-file> output model\n"); | |
1062 | printf (" -r <output-file> output multi-sim run\n"); | |
1063 | printf (" -s <output-file> output schematic\n"); | |
1064 | printf (" -t <output-file> output itable\n"); | |
1065 | } | |
1066 | ||
d4f1c49e | 1067 | while ((ch = getopt(argc, argv, |
687f3f1c AC |
1068 | "B:D:F:G:H:I:M:N:P:T:W:o:k:i:n:hc:d:e:m:r:s:t:f:x")) |
1069 | != -1) | |
1070 | { | |
1071 | fprintf (stderr, " -%c ", ch); | |
1072 | if (optarg) | |
1073 | fprintf (stderr, "%s ", optarg); | |
1074 | fprintf (stderr, "\\\n"); | |
1075 | ||
1076 | switch(ch) | |
1077 | { | |
1078 | ||
1079 | case 'M': | |
1080 | filter_parse (&options.model_filter, optarg); | |
1081 | break; | |
d4f1c49e | 1082 | |
687f3f1c AC |
1083 | case 'D': |
1084 | if (strcmp (optarg, "processor-names")) | |
1085 | { | |
1086 | char *processor; | |
1087 | for (processor = filter_next (options.model_filter, ""); | |
1088 | processor != NULL; | |
1089 | processor = filter_next (options.model_filter, processor)) | |
1090 | lf_printf (standard_out, "%s\n", processor); | |
1091 | } | |
1092 | else | |
1093 | error (NULL, "Unknown data structure %s, not dumped\n", optarg); | |
1094 | break; | |
d4f1c49e | 1095 | |
687f3f1c AC |
1096 | case 'F': |
1097 | filter_parse (&options.flags_filter, optarg); | |
1098 | break; | |
1099 | ||
1100 | case 'I': | |
e2880fad AC |
1101 | { |
1102 | table_include **dir = &options.include; | |
1103 | while ((*dir) != NULL) | |
1104 | dir = &(*dir)->next; | |
1105 | (*dir) = ZALLOC (table_include); | |
1106 | (*dir)->dir = strdup (optarg); | |
1107 | } | |
687f3f1c AC |
1108 | break; |
1109 | ||
1110 | case 'B': | |
1111 | options.insn_bit_size = a2i (optarg); | |
1112 | if (options.insn_bit_size <= 0 | |
1113 | || options.insn_bit_size > max_insn_bit_size) | |
1114 | { | |
1115 | error (NULL, "Instruction bitsize must be in range 1..%d\n", | |
1116 | max_insn_bit_size); | |
1117 | } | |
1118 | if (options.hi_bit_nr != options.insn_bit_size - 1 | |
1119 | && options.hi_bit_nr != 0) | |
1120 | { | |
1121 | error (NULL, "Conflict betweem hi-bit-nr and insn-bit-size\n"); | |
1122 | } | |
1123 | break; | |
1124 | ||
1125 | case 'H': | |
1126 | options.hi_bit_nr = a2i (optarg); | |
1127 | if (options.hi_bit_nr != options.insn_bit_size - 1 | |
1128 | && options.hi_bit_nr != 0) | |
1129 | { | |
1130 | error (NULL, "Conflict between hi-bit-nr and insn-bit-size\n"); | |
1131 | } | |
1132 | break; | |
1133 | ||
1134 | case 'N': | |
1135 | options.gen.smp = a2i (optarg); | |
1136 | break; | |
1137 | ||
1138 | case 'P': | |
1139 | { | |
1140 | igen_prefix_name *names; | |
1141 | char *chp; | |
1142 | chp = strchr (optarg, '='); | |
1143 | if (chp == NULL) | |
1144 | { | |
1145 | names = &options.prefix.global; | |
1146 | chp = optarg; | |
1147 | } | |
1148 | else | |
1149 | { | |
1150 | chp = chp + 1; /* skip `=' */ | |
1151 | if (strncmp (optarg, "global=", chp - optarg) == 0) | |
1152 | { | |
1153 | names = &options.prefix.global; | |
1154 | } | |
1155 | if (strncmp (optarg, "engine=", chp - optarg) == 0) | |
1156 | { | |
1157 | names = &options.prefix.engine; | |
1158 | } | |
1159 | if (strncmp (optarg, "icache=", chp - optarg) == 0) | |
1160 | { | |
1161 | names = &options.prefix.icache; | |
1162 | } | |
1163 | if (strncmp (optarg, "idecode=", chp - optarg) == 0) | |
1164 | { | |
1165 | names = &options.prefix.idecode; | |
1166 | } | |
1167 | if (strncmp (optarg, "itable=", chp - optarg) == 0) | |
1168 | { | |
1169 | names = &options.prefix.itable; | |
1170 | } | |
1171 | if (strncmp (optarg, "semantics=", chp - optarg) == 0) | |
1172 | { | |
1173 | names = &options.prefix.semantics; | |
1174 | } | |
1175 | if (strncmp (optarg, "support=", chp - optarg) == 0) | |
1176 | { | |
1177 | names = &options.prefix.support; | |
1178 | } | |
1179 | else | |
1180 | { | |
1181 | names = NULL; | |
1182 | error (NULL, "Prefix `%s' unreconized\n", optarg); | |
1183 | } | |
1184 | } | |
1185 | names->name = strdup (chp); | |
1186 | names->uname = strdup (chp); | |
1187 | chp = names->uname; | |
1188 | while (*chp) { | |
1189 | if (islower(*chp)) | |
1190 | *chp = toupper(*chp); | |
1191 | chp++; | |
1192 | } | |
1193 | if (names == &options.prefix.global) | |
1194 | { | |
1195 | options.prefix.engine = options.prefix.global; | |
1196 | options.prefix.icache = options.prefix.global; | |
1197 | options.prefix.idecode = options.prefix.global; | |
1198 | /* options.prefix.itable = options.prefix.global; */ | |
1199 | options.prefix.semantics = options.prefix.global; | |
1200 | options.prefix.support = options.prefix.global; | |
1201 | } | |
1202 | break; | |
1203 | } | |
1204 | ||
1205 | case 'W': | |
1206 | { | |
1207 | if (strcmp (optarg, "error") == 0) | |
1208 | options.warning = error; | |
8782bfcf AC |
1209 | else if (strcmp (optarg, "nodiscard") == 0) |
1210 | options.warn.discard = 0; | |
1211 | else if (strcmp (optarg, "discard") == 0) | |
1212 | options.warn.discard = 1; | |
687f3f1c AC |
1213 | else |
1214 | error (NULL, "Unknown -W argument `%s'\n", optarg); | |
1215 | break; | |
1216 | } | |
1217 | ||
1218 | ||
1219 | case 'G': | |
e2880fad AC |
1220 | { |
1221 | int enable_p; | |
1222 | char *argp; | |
1223 | if (strncmp (optarg, "no-", strlen ("no-")) == 0) | |
1224 | { | |
1225 | argp = optarg + strlen ("no-"); | |
1226 | enable_p = 0; | |
1227 | } | |
1228 | else if (strncmp (optarg, "!", strlen ("!")) == 0) | |
1229 | { | |
1230 | argp = optarg + strlen ("no-"); | |
1231 | enable_p = 0; | |
1232 | } | |
1233 | else | |
1234 | { | |
1235 | argp = optarg; | |
1236 | enable_p = 1; | |
1237 | } | |
1238 | if (strcmp (argp, "decode-duplicate") == 0) | |
1239 | { | |
1240 | options.decode.duplicate = enable_p; | |
1241 | } | |
1242 | else if (strcmp (argp, "decode-combine") == 0) | |
1243 | { | |
1244 | options.decode.combine = enable_p; | |
1245 | } | |
1246 | else if (strcmp (argp, "decode-zero-reserved") == 0) | |
1247 | { | |
1248 | options.decode.zero_reserved = enable_p; | |
1249 | } | |
1250 | ||
1251 | else if (strcmp (argp, "gen-conditional-issue") == 0) | |
1252 | { | |
1253 | options.gen.conditional_issue = enable_p; | |
1254 | } | |
1255 | else if (strcmp (argp, "conditional-issue") == 0) | |
1256 | { | |
1257 | options.gen.conditional_issue = enable_p; | |
1258 | options.warning (NULL, "Option conditional-issue replaced by gen-conditional-issue\n"); | |
1259 | } | |
1260 | else if (strcmp (argp, "gen-delayed-branch") == 0) | |
1261 | { | |
1262 | options.gen.delayed_branch = enable_p; | |
1263 | } | |
1264 | else if (strcmp (argp, "delayed-branch") == 0) | |
1265 | { | |
1266 | options.gen.delayed_branch = enable_p; | |
1267 | options.warning (NULL, "Option delayed-branch replaced by gen-delayed-branch\n"); | |
1268 | } | |
1269 | else if (strcmp (argp, "gen-direct-access") == 0) | |
1270 | { | |
1271 | options.gen.direct_access = enable_p; | |
1272 | } | |
1273 | else if (strcmp (argp, "direct-access") == 0) | |
1274 | { | |
1275 | options.gen.direct_access = enable_p; | |
1276 | options.warning (NULL, "Option direct-access replaced by gen-direct-access\n"); | |
1277 | } | |
1278 | else if (strncmp (argp, "gen-zero-r", strlen ("gen-zero-r")) == 0) | |
1279 | { | |
1280 | options.gen.zero_reg = enable_p; | |
1281 | options.gen.zero_reg_nr = atoi (argp + strlen ("gen-zero-r")); | |
1282 | } | |
1283 | else if (strncmp (argp, "zero-r", strlen ("zero-r")) == 0) | |
1284 | { | |
1285 | options.gen.zero_reg = enable_p; | |
1286 | options.gen.zero_reg_nr = atoi (argp + strlen ("zero-r")); | |
1287 | options.warning (NULL, "Option zero-r<N> replaced by gen-zero-r<N>\n"); | |
1288 | } | |
1289 | else if (strncmp (argp, "gen-icache", strlen ("gen-icache")) == 0) | |
1290 | { | |
1291 | switch (argp[strlen ("gen-icache")]) | |
1292 | { | |
1293 | case '=': | |
1294 | options.gen.icache_size = atoi (argp + strlen ("gen-icache") + 1); | |
1295 | /* fall through */ | |
1296 | case '\0': | |
1297 | options.gen.icache = enable_p; | |
1298 | break; | |
1299 | default: | |
1300 | error (NULL, "Expecting -Ggen-icache or -Ggen-icache=<N>\n"); | |
1301 | } | |
1302 | } | |
1303 | else if (strcmp (argp, "gen-insn-in-icache") == 0) | |
1304 | { | |
1305 | options.gen.insn_in_icache = enable_p; | |
1306 | } | |
1307 | else if (strcmp (argp, "gen-multi-sim") == 0) | |
1308 | { | |
1309 | options.gen.multi_sim = enable_p; | |
1310 | } | |
1311 | else if (strcmp (argp, "gen-multi-word") == 0) | |
1312 | { | |
1313 | options.gen.multi_word = enable_p; | |
1314 | } | |
1315 | else if (strcmp (argp, "gen-semantic-icache") == 0) | |
1316 | { | |
1317 | options.gen.semantic_icache = enable_p; | |
1318 | } | |
1319 | else if (strcmp (argp, "gen-slot-verification") == 0) | |
1320 | { | |
1321 | options.gen.slot_verification = enable_p; | |
1322 | } | |
1323 | else if (strcmp (argp, "verify-slot") == 0) | |
1324 | { | |
1325 | options.gen.slot_verification = enable_p; | |
1326 | options.warning (NULL, "Option verify-slot replaced by gen-slot-verification\n"); | |
1327 | } | |
1328 | else if (strcmp (argp, "gen-nia-invalid") == 0) | |
1329 | { | |
1330 | options.gen.nia = nia_is_invalid; | |
1331 | } | |
1332 | else if (strcmp (argp, "default-nia-minus-one") == 0) | |
1333 | { | |
1334 | options.gen.nia = nia_is_invalid; | |
1335 | options.warning (NULL, "Option default-nia-minus-one replaced by gen-nia-invalid\n"); | |
1336 | } | |
1337 | else if (strcmp (argp, "gen-nia-void") == 0) | |
1338 | { | |
1339 | options.gen.nia = nia_is_void; | |
1340 | } | |
1341 | else if (strcmp (argp, "trace-combine") == 0) | |
1342 | { | |
1343 | options.trace.combine = enable_p; | |
1344 | } | |
1345 | else if (strcmp (argp, "trace-entries") == 0) | |
1346 | { | |
1347 | options.trace.entries = enable_p; | |
1348 | } | |
1349 | else if (strcmp (argp, "trace-rule-rejection") == 0) | |
1350 | { | |
1351 | options.trace.rule_rejection = enable_p; | |
1352 | } | |
1353 | else if (strcmp (argp, "trace-rule-selection") == 0) | |
1354 | { | |
1355 | options.trace.rule_selection = enable_p; | |
1356 | } | |
1357 | else if (strcmp (argp, "jumps") == 0) | |
1358 | { | |
1359 | options.gen.code = generate_jumps; | |
1360 | } | |
1361 | else if (strcmp (argp, "field-widths") == 0) | |
1362 | { | |
1363 | options.insn_specifying_widths = enable_p; | |
1364 | } | |
1365 | else if (strcmp (argp, "omit-line-numbers") == 0) | |
1366 | { | |
1367 | file_references = lf_omit_references; | |
1368 | } | |
1369 | else | |
1370 | { | |
1371 | error (NULL, "Unknown option %s\n", optarg); | |
1372 | } | |
1373 | break; | |
1374 | } | |
1375 | ||
687f3f1c AC |
1376 | case 'i': |
1377 | isa = load_insn_table (optarg, cache_rules); | |
1378 | if (isa->illegal_insn == NULL) | |
1379 | error (NULL, "illegal-instruction missing from insn table\n"); | |
1380 | break; | |
d4f1c49e | 1381 | |
687f3f1c AC |
1382 | case 'x': |
1383 | gen = do_gen (isa, decode_rules); | |
1384 | break; | |
d4f1c49e | 1385 | |
687f3f1c AC |
1386 | case 'o': |
1387 | decode_rules = load_decode_table (optarg); | |
1388 | break; | |
d4f1c49e | 1389 | |
687f3f1c AC |
1390 | case 'k': |
1391 | if (isa != NULL) | |
1392 | error (NULL, "Cache file must appear before the insn file\n"); | |
1393 | cache_rules = load_cache_table (optarg); | |
1394 | break; | |
d4f1c49e | 1395 | |
687f3f1c AC |
1396 | case 'n': |
1397 | real_file_name = strdup(optarg); | |
1398 | break; | |
d4f1c49e | 1399 | |
687f3f1c AC |
1400 | case 'h': |
1401 | is_header = 1; | |
d4f1c49e | 1402 | break; |
687f3f1c AC |
1403 | |
1404 | case 'c': | |
d4f1c49e | 1405 | case 'd': |
d4f1c49e | 1406 | case 'e': |
687f3f1c | 1407 | case 'f': |
d4f1c49e | 1408 | case 'm': |
687f3f1c AC |
1409 | case 'r': |
1410 | case 's': | |
d4f1c49e | 1411 | case 't': |
687f3f1c AC |
1412 | { |
1413 | lf *file = lf_open(optarg, real_file_name, file_references, | |
1414 | (is_header ? lf_is_h : lf_is_c), | |
1415 | argv[0]); | |
1416 | if (gen == NULL && ch != 't' && ch != 'm' && ch != 'f') | |
1417 | { | |
1418 | options.warning (NULL, "Explicitly generate tables with -x option\n"); | |
1419 | gen = do_gen (isa, decode_rules); | |
1420 | } | |
1421 | lf_print__file_start(file); | |
1422 | switch (ch) | |
1423 | { | |
1424 | case 'm': | |
1425 | if (is_header) | |
1426 | gen_model_h (file, isa); | |
1427 | else | |
1428 | gen_model_c (file, isa); | |
1429 | break; | |
1430 | case 't': | |
1431 | if (is_header) | |
1432 | gen_itable_h (file, isa); | |
1433 | else | |
1434 | gen_itable_c (file, isa); | |
1435 | break; | |
1436 | case 'f': | |
1437 | if (is_header) | |
1438 | gen_support_h (file, isa); | |
1439 | else | |
1440 | gen_support_c (file, isa); | |
1441 | break; | |
1442 | case 'r': | |
1443 | if (is_header) | |
1444 | options.warning (NULL, "-hr option ignored\n"); | |
1445 | else | |
1446 | gen_run_c (file, gen); | |
1447 | break; | |
1448 | case 's': | |
1449 | if(is_header) | |
1450 | gen_semantics_h (file, gen->semantics, isa->max_nr_words); | |
1451 | else | |
1452 | gen_semantics_c (file, gen->semantics, isa->caches); | |
1453 | break; | |
1454 | case 'd': | |
1455 | if (is_header) | |
1456 | gen_idecode_h (file, gen, isa, cache_rules); | |
1457 | else | |
1458 | gen_idecode_c (file, gen, isa, cache_rules); | |
1459 | break; | |
1460 | case 'e': | |
1461 | if (is_header) | |
1462 | gen_engine_h (file, gen, isa, cache_rules); | |
1463 | else | |
1464 | gen_engine_c (file, gen, isa, cache_rules); | |
1465 | break; | |
1466 | case 'c': | |
1467 | if (is_header) | |
1468 | gen_icache_h (file, | |
1469 | gen->semantics, | |
1470 | isa->functions, | |
1471 | isa->max_nr_words); | |
1472 | else | |
1473 | gen_icache_c (file, | |
1474 | gen->semantics, | |
1475 | isa->functions, | |
1476 | cache_rules); | |
1477 | break; | |
1478 | } | |
1479 | lf_print__file_finish(file); | |
1480 | lf_close(file); | |
1481 | is_header = 0; | |
1482 | } | |
1483 | real_file_name = NULL; | |
1484 | break; | |
1485 | default: | |
1486 | ERROR ("Bad switch"); | |
d4f1c49e | 1487 | } |
d4f1c49e | 1488 | } |
687f3f1c | 1489 | return (0); |
d4f1c49e | 1490 | } |