1 /* This file is part of the program psim.
3 Copyright 1994, 1995, 1996, 1997, 2003 Andrew Cagney
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.
33 #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 */
114 nr
+= lf_putchr(file
, '_');
117 nr
+= lf_putchr(file
, *pos
);
124 if (generate_expanded_instructions
)
125 nr
+= print_insn_bits(file
, expanded_bits
);
132 print_my_defines(lf
*file
,
133 insn_bits
*expanded_bits
,
134 table_entry
*file_entry
)
136 /* #define MY_INDEX xxxxx */
137 lf_indent_suppress(file
);
138 lf_printf(file
, "#undef MY_INDEX\n");
139 lf_indent_suppress(file
);
140 lf_printf(file
, "#define MY_INDEX ");
141 print_function_name(file
,
142 file_entry
->fields
[insn_name
],
144 function_name_prefix_itable
);
145 lf_printf(file
, "\n");
146 /* #define MY_PREFIX xxxxxx */
147 lf_indent_suppress(file
);
148 lf_printf(file
, "#undef MY_PREFIX\n");
149 lf_indent_suppress(file
);
150 lf_printf(file
, "#define MY_PREFIX ");
151 print_function_name(file
,
152 file_entry
->fields
[insn_name
],
154 function_name_prefix_none
);
155 lf_printf(file
, "\n");
160 print_itrace(lf
*file
,
161 table_entry
*file_entry
,
164 lf_print__external_reference(file
, file_entry
->line_nr
, file_entry
->file_name
);
165 lf_printf(file
, "ITRACE(trace_%s, (\"%s %s\\n\"));\n",
166 (idecode
? "idecode" : "semantics"),
167 (idecode
? "idecode" : "semantics"),
168 file_entry
->fields
[insn_name
]);
169 lf_print__internal_reference(file
);
173 /****************************************************************/
177 gen_semantics_h(insn_table
*table
,
181 lf_printf(file
, "typedef %s idecode_semantic\n(%s);\n",
182 SEMANTIC_FUNCTION_TYPE
,
183 SEMANTIC_FUNCTION_FORMAL
);
184 lf_printf(file
, "\n");
185 if ((code
& generate_calls
)) {
186 lf_printf(file
, "extern int option_mpc860c0;\n");
187 lf_printf(file
, "#define PAGE_SIZE 0x1000\n");
188 lf_printf(file
, "\n");
189 lf_printf(file
, "PSIM_EXTERN_SEMANTICS(void)\n");
190 lf_printf(file
, "semantic_init(device* root);\n");
191 lf_printf(file
, "\n");
192 if (generate_expanded_instructions
)
193 insn_table_traverse_tree(table
,
197 print_semantic_declaration
, /* leaf */
201 insn_table_traverse_insn(table
,
203 print_semantic_declaration
);
207 lf_print__this_file_is_empty(file
);
213 gen_semantics_c(insn_table
*table
,
214 cache_table
*cache_rules
,
218 if ((code
& generate_calls
)) {
219 lf_printf(file
, "\n");
220 lf_printf(file
, "#include \"cpu.h\"\n");
221 lf_printf(file
, "#include \"idecode.h\"\n");
222 lf_printf(file
, "#include \"semantics.h\"\n");
223 lf_printf(file
, "#ifdef HAVE_COMMON_FPU\n");
224 lf_printf(file
, "#include \"sim-inline.h\"\n");
225 lf_printf(file
, "#include \"sim-fpu.h\"\n");
226 lf_printf(file
, "#endif\n");
227 lf_printf(file
, "#include \"support.h\"\n");
228 lf_printf(file
, "\n");
229 lf_printf(file
, "int option_mpc860c0 = 0;\n");
230 lf_printf(file
, "\n");
231 lf_printf(file
, "PSIM_EXTERN_SEMANTICS(void)\n");
232 lf_printf(file
, "semantic_init(device* root)\n");
233 lf_printf(file
, "{\n");
234 lf_printf(file
, " option_mpc860c0 = 0;\n");
235 lf_printf(file
, " if (tree_find_property(root, \"/options/mpc860c0\"))\n");
236 lf_printf(file
, " option_mpc860c0 = tree_find_integer_property(root, \"/options/mpc860c0\");\n");
237 lf_printf(file
, " option_mpc860c0 *= 4; /* convert word count to byte count */\n");
238 lf_printf(file
, "}\n");
239 lf_printf(file
, "\n");
240 if (generate_expanded_instructions
)
241 insn_table_traverse_tree(table
,
245 print_semantic_definition
, /* leaf */
249 insn_table_traverse_insn(table
,
251 print_semantic_definition
);
255 lf_print__this_file_is_empty(file
);
260 /****************************************************************/
264 gen_icache_h(insn_table
*table
,
268 lf_printf(file
, "typedef %s idecode_icache\n(%s);\n",
269 ICACHE_FUNCTION_TYPE
,
270 ICACHE_FUNCTION_FORMAL
);
271 lf_printf(file
, "\n");
272 if ((code
& generate_calls
)
273 && (code
& generate_with_icache
)) {
274 insn_table_traverse_function(table
,
276 print_icache_internal_function_declaration
);
277 if (generate_expanded_instructions
)
278 insn_table_traverse_tree(table
,
282 print_icache_declaration
, /* leaf */
286 insn_table_traverse_insn(table
,
288 print_icache_declaration
);
292 lf_print__this_file_is_empty(file
);
297 gen_icache_c(insn_table
*table
,
298 cache_table
*cache_rules
,
302 /* output `internal' invalid/floating-point unavailable functions
304 if ((code
& generate_calls
)
305 && (code
& generate_with_icache
)) {
306 lf_printf(file
, "\n");
307 lf_printf(file
, "#include \"cpu.h\"\n");
308 lf_printf(file
, "#include \"idecode.h\"\n");
309 lf_printf(file
, "#include \"semantics.h\"\n");
310 lf_printf(file
, "#include \"icache.h\"\n");
311 lf_printf(file
, "#ifdef HAVE_COMMON_FPU\n");
312 lf_printf(file
, "#include \"sim-inline.h\"\n");
313 lf_printf(file
, "#include \"sim-fpu.h\"\n");
314 lf_printf(file
, "#endif\n");
315 lf_printf(file
, "#include \"support.h\"\n");
316 lf_printf(file
, "\n");
317 insn_table_traverse_function(table
,
319 print_icache_internal_function_definition
);
320 lf_printf(file
, "\n");
321 if (generate_expanded_instructions
)
322 insn_table_traverse_tree(table
,
326 print_icache_definition
, /* leaf */
330 insn_table_traverse_insn(table
,
332 print_icache_definition
);
336 lf_print__this_file_is_empty(file
);
341 /****************************************************************/
349 cache_table
*cache_rules
= NULL
;
350 lf_file_references file_references
= lf_include_references
;
351 decode_table
*decode_rules
= NULL
;
352 filter
*filters
= NULL
;
353 insn_table
*instructions
= NULL
;
354 table_include
*includes
= NULL
;
355 char *real_file_name
= NULL
;
361 printf(" igen <config-opts> ... <input-opts>... <output-opts>...\n");
362 printf("Config options:\n");
363 printf(" -F <filter-out-flag> eg -F 64 to skip 64bit instructions\n");
364 printf(" -E Expand (duplicate) semantic functions\n");
365 printf(" -I <icache-size> Generate cracking cache version\n");
366 printf(" -C Include semantics in cache functions\n");
367 printf(" -S Include insn (instruction) in icache\n");
368 printf(" -R Use defines to reference cache vars\n");
369 printf(" -L Supress line numbering in output files\n");
370 printf(" -B <bit-size> Set the number of bits in an instruction\n");
371 printf(" -H <high-bit> Set the nr of the high (msb bit)\n");
372 printf(" -N <nr-cpus> Specify the max number of cpus the simulation will support\n");
373 printf(" -J Use jumps instead of function calls\n");
374 printf(" -T <mechanism> Override the mechanism used to decode an instruction\n");
375 printf(" using <mechanism> instead of what was specified in the\n");
376 printf(" decode-rules input file\n");
378 printf("Input options (ucase version also dumps loaded table):\n");
379 printf(" -o <decode-rules>\n");
380 printf(" -k <cache-rules>\n");
381 printf(" -i <instruction-table>\n");
383 printf("Output options:\n");
384 printf(" -n <real-name> Specify the real name of for the next output file\n");
385 printf(" -h Generate header file\n");
386 printf(" -c <output-file> output icache\n");
387 printf(" -d <output-file> output idecode\n");
388 printf(" -m <output-file> output model\n");
389 printf(" -s <output-file> output schematic\n");
390 printf(" -t <output-file> output itable\n");
391 printf(" -f <output-file> output support functions\n");
394 while ((ch
= getopt(argc
, argv
,
395 "F:EI:RSLJT:CB:H:N:o:k:i:n:hc:d:m:s:t:f:"))
397 fprintf(stderr
, "\t-%c %s\n", ch
, (optarg
? optarg
: ""));
400 code
|= generate_with_icache
;
401 code
|= generate_with_semantic_icache
;
404 code
|= generate_with_icache
;
405 code
|= generate_with_insn_in_icache
;
408 file_references
= lf_omit_references
;
411 generate_expanded_instructions
= 1;
417 if (strncmp (optarg
, "no-", strlen ("no-")) == 0)
419 argp
= optarg
+ strlen ("no-");
422 else if (strncmp (optarg
, "!", strlen ("!")) == 0)
424 argp
= optarg
+ strlen ("no-");
432 if (strncmp (argp
, "gen-icache", strlen ("gen-icache")) == 0)
434 switch (argp
[strlen ("gen-icache")])
437 icache_size
= atoi (argp
+ strlen ("gen-icache") + 1);
438 code
|= generate_with_icache
;
441 code
|= generate_with_icache
;
444 error (NULL
, "Expecting -Ggen-icache or -Ggen-icache=<N>\n");
450 table_include
**dir
= &includes
;
451 while ((*dir
) != NULL
)
453 (*dir
) = ZALLOC (table_include
);
454 (*dir
)->dir
= strdup (optarg
);
458 generate_smp
= a2i(optarg
);
461 code
|= generate_with_direct_access
;
464 insn_bit_size
= a2i(optarg
);
465 ASSERT(insn_bit_size
> 0 && insn_bit_size
<= max_insn_bit_size
466 && (hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0));
469 hi_bit_nr
= a2i(optarg
);
470 ASSERT(hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0);
473 filters
= new_filter(optarg
, filters
);
476 code
&= ~generate_calls
;
477 code
|= generate_jumps
;
480 force_decode_gen_type(optarg
);
483 if (decode_rules
== NULL
) {
484 fprintf(stderr
, "Must specify decode tables\n");
487 instructions
= load_insn_table(optarg
, decode_rules
, filters
, includes
,
489 fprintf(stderr
, "\texpanding ...\n");
490 insn_table_expand_insns(instructions
);
493 decode_rules
= load_decode_table(optarg
, hi_bit_nr
);
496 cache_rules
= load_cache_table(optarg
, hi_bit_nr
);
499 real_file_name
= strdup(optarg
);
511 lf
*file
= lf_open(optarg
, real_file_name
, file_references
,
512 (is_header
? lf_is_h
: lf_is_c
),
514 lf_print__file_start(file
);
515 ASSERT(instructions
!= NULL
);
519 gen_semantics_h(instructions
, file
, code
);
521 gen_semantics_c(instructions
, cache_rules
, file
, code
);
525 gen_idecode_h(file
, instructions
, cache_rules
);
527 gen_idecode_c(file
, instructions
, cache_rules
);
531 gen_model_h(instructions
, file
);
533 gen_model_c(instructions
, file
);
537 gen_itable_h(instructions
, file
);
539 gen_itable_c(instructions
, file
);
543 gen_support_h(instructions
, file
);
545 gen_support_c(instructions
, file
);
549 gen_icache_h(instructions
, file
, code
);
551 gen_icache_c(instructions
, cache_rules
, file
, code
);
554 lf_print__file_finish(file
);
558 real_file_name
= NULL
;
561 error("unknown option\n");