1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
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.
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.
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.
32 #include "ld-decode.h"
38 #include "gen-model.h"
39 #include "gen-icache.h"
40 #include "gen-itable.h"
41 #include "gen-idecode.h"
42 #include "gen-semantics.h"
43 #include "gen-support.h"
46 int insn_bit_size
= max_insn_bit_size
;
48 igen_code code
= generate_calls
;
50 int generate_expanded_instructions
;
51 int icache_size
= 1024;
54 /****************************************************************/
57 print_insn_bits(lf
*file
, insn_bits
*bits
)
62 nr
+= print_insn_bits(file
, bits
->last
);
63 nr
+= lf_putchr(file
, '_');
64 nr
+= lf_putstr(file
, bits
->field
->val_string
);
65 if (bits
->opcode
->is_boolean
&& bits
->value
== 0)
66 nr
+= lf_putint(file
, bits
->opcode
->boolean_constant
);
67 else if (!bits
->opcode
->is_boolean
) {
68 if (bits
->opcode
->last
< bits
->field
->last
)
69 nr
+= lf_putint(file
, bits
->value
<< (bits
->field
->last
- bits
->opcode
->last
));
71 nr
+= lf_putint(file
, bits
->value
);
77 print_function_name(lf
*file
,
79 insn_bits
*expanded_bits
,
80 lf_function_name_prefixes prefix
)
85 case function_name_prefix_semantics
:
86 nr
+= lf_putstr(file
, "semantic_");
88 case function_name_prefix_idecode
:
89 nr
+= lf_printf(file
, "idecode_");
91 case function_name_prefix_itable
:
92 nr
+= lf_putstr(file
, "itable_");
94 case function_name_prefix_icache
:
95 nr
+= lf_putstr(file
, "icache_");
101 /* the function name */
112 nr
+= lf_putchr(file
, '_');
115 nr
+= lf_putchr(file
, *pos
);
122 if (generate_expanded_instructions
)
123 nr
+= print_insn_bits(file
, expanded_bits
);
130 print_my_defines(lf
*file
,
131 insn_bits
*expanded_bits
,
132 table_entry
*file_entry
)
134 /* #define MY_INDEX xxxxx */
135 lf_indent_suppress(file
);
136 lf_printf(file
, "#undef MY_INDEX\n");
137 lf_indent_suppress(file
);
138 lf_printf(file
, "#define MY_INDEX ");
139 print_function_name(file
,
140 file_entry
->fields
[insn_name
],
142 function_name_prefix_itable
);
143 lf_printf(file
, "\n");
144 /* #define MY_PREFIX xxxxxx */
145 lf_indent_suppress(file
);
146 lf_printf(file
, "#undef MY_PREFIX\n");
147 lf_indent_suppress(file
);
148 lf_printf(file
, "#define MY_PREFIX ");
149 print_function_name(file
,
150 file_entry
->fields
[insn_name
],
152 function_name_prefix_none
);
153 lf_printf(file
, "\n");
158 print_itrace(lf
*file
,
159 table_entry
*file_entry
,
162 lf_print__external_reference(file
, file_entry
->line_nr
, file_entry
->file_name
);
163 lf_printf(file
, "ITRACE(trace_%s, (\"%s %s\\n\"));\n",
164 (idecode
? "idecode" : "semantics"),
165 (idecode
? "idecode" : "semantics"),
166 file_entry
->fields
[insn_name
]);
167 lf_print__internal_reference(file
);
171 /****************************************************************/
175 gen_semantics_h(insn_table
*table
,
179 lf_printf(file
, "typedef %s idecode_semantic\n(%s);\n",
180 SEMANTIC_FUNCTION_TYPE
,
181 SEMANTIC_FUNCTION_FORMAL
);
182 lf_printf(file
, "\n");
183 if ((code
& generate_calls
)) {
184 if (generate_expanded_instructions
)
185 insn_table_traverse_tree(table
,
189 print_semantic_declaration
, /* leaf */
193 insn_table_traverse_insn(table
,
195 print_semantic_declaration
);
199 lf_print__this_file_is_empty(file
);
205 gen_semantics_c(insn_table
*table
,
206 cache_table
*cache_rules
,
210 if ((code
& generate_calls
)) {
211 lf_printf(file
, "\n");
212 lf_printf(file
, "#include \"cpu.h\"\n");
213 lf_printf(file
, "#include \"idecode.h\"\n");
214 lf_printf(file
, "#include \"semantics.h\"\n");
215 lf_printf(file
, "#include \"support.h\"\n");
216 lf_printf(file
, "\n");
217 if (generate_expanded_instructions
)
218 insn_table_traverse_tree(table
,
222 print_semantic_definition
, /* leaf */
226 insn_table_traverse_insn(table
,
228 print_semantic_definition
);
232 lf_print__this_file_is_empty(file
);
237 /****************************************************************/
241 gen_icache_h(insn_table
*table
,
245 lf_printf(file
, "typedef %s idecode_icache\n(%s);\n",
246 ICACHE_FUNCTION_TYPE
,
247 ICACHE_FUNCTION_FORMAL
);
248 lf_printf(file
, "\n");
249 if ((code
& generate_calls
)
250 && (code
& generate_with_icache
)) {
251 insn_table_traverse_function(table
,
253 print_icache_internal_function_declaration
);
254 if (generate_expanded_instructions
)
255 insn_table_traverse_tree(table
,
259 print_icache_declaration
, /* leaf */
263 insn_table_traverse_insn(table
,
265 print_icache_declaration
);
269 lf_print__this_file_is_empty(file
);
274 gen_icache_c(insn_table
*table
,
275 cache_table
*cache_rules
,
279 /* output `internal' invalid/floating-point unavailable functions
281 if ((code
& generate_calls
)
282 && (code
& generate_with_icache
)) {
283 lf_printf(file
, "\n");
284 lf_printf(file
, "#include \"cpu.h\"\n");
285 lf_printf(file
, "#include \"idecode.h\"\n");
286 lf_printf(file
, "#include \"semantics.h\"\n");
287 lf_printf(file
, "#include \"icache.h\"\n");
288 lf_printf(file
, "#include \"support.h\"\n");
289 lf_printf(file
, "\n");
290 insn_table_traverse_function(table
,
292 print_icache_internal_function_definition
);
293 lf_printf(file
, "\n");
294 if (generate_expanded_instructions
)
295 insn_table_traverse_tree(table
,
299 print_icache_definition
, /* leaf */
303 insn_table_traverse_insn(table
,
305 print_icache_definition
);
309 lf_print__this_file_is_empty(file
);
314 /****************************************************************/
322 cache_table
*cache_rules
= NULL
;
323 lf_file_references file_references
= lf_include_references
;
324 decode_table
*decode_rules
= NULL
;
325 filter
*filters
= NULL
;
326 insn_table
*instructions
= NULL
;
327 char *real_file_name
= NULL
;
333 printf(" igen <config-opts> ... <input-opts>... <output-opts>...\n");
334 printf("Config options:\n");
335 printf(" -F <filter-out-flag> eg -F 64 to skip 64bit instructions\n");
336 printf(" -E Expand (duplicate) semantic functions\n");
337 printf(" -I <icache-size> Generate cracking cache version\n");
338 printf(" -C Include semantics in cache functions\n");
339 printf(" -S Include insn (instruction) in icache\n");
340 printf(" -R Use defines to reference cache vars\n");
341 printf(" -L Supress line numbering in output files\n");
342 printf(" -B <bit-size> Set the number of bits in an instruction\n");
343 printf(" -H <high-bit> Set the nr of the high (msb bit)\n");
344 printf(" -N <nr-cpus> Specify the max number of cpus the simulation will support\n");
345 printf(" -J Use jumps instead of function calls\n");
347 printf("Input options (ucase version also dumps loaded table):\n");
348 printf(" -o <opcode-rules>\n");
349 printf(" -k <cache-rules>\n");
350 printf(" -i <instruction-table>\n");
352 printf("Output options:\n");
353 printf(" -n <real-name> Specify the real name of for the next output file\n");
354 printf(" -h Generate header file\n");
355 printf(" -c <output-file> output icache\n");
356 printf(" -d <output-file> output idecode\n");
357 printf(" -m <output-file> output model\n");
358 printf(" -s <output-file> output schematic\n");
359 printf(" -t <output-file> output itable\n");
360 printf(" -f <output-file> output support functions\n");
363 while ((ch
= getopt(argc
, argv
,
364 "F:EI:RSLJCB:H:N:o:k:i:n:hc:d:m:s:t:f:"))
366 fprintf(stderr
, "\t-%c %s\n", ch
, (optarg
? optarg
: ""));
369 code
|= generate_with_icache
;
370 code
|= generate_with_semantic_icache
;
373 code
|= generate_with_icache
;
374 code
|= generate_with_insn_in_icache
;
377 file_references
= lf_omit_references
;
380 generate_expanded_instructions
= 1;
383 icache_size
= a2i(optarg
);
384 code
|= generate_with_icache
;
387 generate_smp
= a2i(optarg
);
390 code
|= generate_with_direct_access
;
393 insn_bit_size
= a2i(optarg
);
394 ASSERT(insn_bit_size
> 0 && insn_bit_size
<= max_insn_bit_size
395 && (hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0));
398 hi_bit_nr
= a2i(optarg
);
399 ASSERT(hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0);
402 filters
= new_filter(optarg
, filters
);
405 code
&= ~generate_calls
;
406 code
|= generate_jumps
;
409 if (decode_rules
== NULL
|| cache_rules
== NULL
) {
410 fprintf(stderr
, "Must specify decode and cache tables\n");
413 instructions
= load_insn_table(optarg
, decode_rules
, filters
);
414 fprintf(stderr
, "\texpanding ...\n");
415 insn_table_expand_insns(instructions
);
418 decode_rules
= load_decode_table(optarg
, hi_bit_nr
);
421 cache_rules
= load_cache_table(optarg
, hi_bit_nr
);
424 real_file_name
= strdup(optarg
);
436 lf
*file
= lf_open(optarg
, real_file_name
, file_references
,
437 (is_header
? lf_is_h
: lf_is_c
),
439 lf_print__file_start(file
);
440 ASSERT(instructions
!= NULL
);
444 gen_semantics_h(instructions
, file
, code
);
446 gen_semantics_c(instructions
, cache_rules
, file
, code
);
450 gen_idecode_h(file
, instructions
, cache_rules
);
452 gen_idecode_c(file
, instructions
, cache_rules
);
456 gen_model_h(instructions
, file
);
458 gen_model_c(instructions
, file
);
462 gen_itable_h(instructions
, file
);
464 gen_itable_c(instructions
, file
);
468 gen_support_h(instructions
, file
);
470 gen_support_c(instructions
, file
);
474 gen_icache_h(instructions
, file
, code
);
476 gen_icache_c(instructions
, cache_rules
, file
, code
);
479 lf_print__file_finish(file
);
483 real_file_name
= NULL
;
486 error("unknown option\n");