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
;
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_define_my_index(lf
*file
,
131 table_entry
*file_entry
)
133 lf_indent_suppress(file
);
134 lf_printf(file
, "#undef MY_INDEX\n");
135 lf_indent_suppress(file
);
136 lf_printf(file
, "#define MY_INDEX ");
137 print_function_name(file
,
138 file_entry
->fields
[insn_name
],
140 function_name_prefix_itable
);
141 lf_printf(file
, "\n");
146 print_itrace(lf
*file
,
147 table_entry
*file_entry
,
150 lf_print__external_reference(file
, file_entry
->line_nr
, file_entry
->file_name
);
151 lf_printf(file
, "ITRACE(trace_%s, (\"%s %s\\n\"));\n",
152 (idecode
? "idecode" : "semantics"),
153 (idecode
? "idecode" : "semantics"),
154 file_entry
->fields
[insn_name
]);
155 lf_print__internal_reference(file
);
159 /****************************************************************/
163 gen_semantics_h(insn_table
*table
,
167 lf_printf(file
, "typedef %s idecode_semantic\n(%s);\n",
168 SEMANTIC_FUNCTION_TYPE
,
169 SEMANTIC_FUNCTION_FORMAL
);
170 lf_printf(file
, "\n");
171 if ((code
& generate_calls
)) {
172 if (generate_expanded_instructions
)
173 insn_table_traverse_tree(table
,
177 print_semantic_declaration
, /* leaf */
181 insn_table_traverse_insn(table
,
183 print_semantic_declaration
);
187 lf_print__this_file_is_empty(file
);
193 gen_semantics_c(insn_table
*table
,
194 cache_table
*cache_rules
,
198 if ((code
& generate_calls
)) {
199 lf_printf(file
, "\n");
200 lf_printf(file
, "#include \"cpu.h\"\n");
201 lf_printf(file
, "#include \"idecode.h\"\n");
202 lf_printf(file
, "#include \"semantics.h\"\n");
203 lf_printf(file
, "#include \"support.h\"\n");
204 lf_printf(file
, "\n");
205 if (generate_expanded_instructions
)
206 insn_table_traverse_tree(table
,
210 print_semantic_definition
, /* leaf */
214 insn_table_traverse_insn(table
,
216 print_semantic_definition
);
220 lf_print__this_file_is_empty(file
);
225 /****************************************************************/
229 gen_icache_h(insn_table
*table
,
233 lf_printf(file
, "typedef %s idecode_icache\n(%s);\n",
234 ICACHE_FUNCTION_TYPE
,
235 ICACHE_FUNCTION_FORMAL
);
236 lf_printf(file
, "\n");
237 if ((code
& generate_calls
)
238 && (code
& generate_with_icache
)) {
239 insn_table_traverse_function(table
,
241 print_icache_internal_function_declaration
);
242 if (generate_expanded_instructions
)
243 insn_table_traverse_tree(table
,
247 print_icache_declaration
, /* leaf */
251 insn_table_traverse_insn(table
,
253 print_icache_declaration
);
257 lf_print__this_file_is_empty(file
);
262 gen_icache_c(insn_table
*table
,
263 cache_table
*cache_rules
,
267 /* output `internal' invalid/floating-point unavailable functions
269 if ((code
& generate_calls
)
270 && (code
& generate_with_icache
)) {
271 lf_printf(file
, "\n");
272 lf_printf(file
, "#include \"cpu.h\"\n");
273 lf_printf(file
, "#include \"idecode.h\"\n");
274 lf_printf(file
, "#include \"semantics.h\"\n");
275 lf_printf(file
, "#include \"icache.h\"\n");
276 lf_printf(file
, "#include \"support.h\"\n");
277 lf_printf(file
, "\n");
278 insn_table_traverse_function(table
,
280 print_icache_internal_function_definition
);
281 lf_printf(file
, "\n");
282 if (generate_expanded_instructions
)
283 insn_table_traverse_tree(table
,
287 print_icache_definition
, /* leaf */
291 insn_table_traverse_insn(table
,
293 print_icache_definition
);
297 lf_print__this_file_is_empty(file
);
302 /****************************************************************/
310 cache_table
*cache_rules
= NULL
;
311 lf_file_references file_references
= lf_include_references
;
312 decode_table
*decode_rules
= NULL
;
313 filter
*filters
= NULL
;
314 insn_table
*instructions
= NULL
;
315 char *real_file_name
= NULL
;
321 printf(" igen <config-opts> ... <input-opts>... <output-opts>...\n");
322 printf("Config options:\n");
323 printf(" -F <filter-out-flag> eg -F 64 to skip 64bit instructions\n");
324 printf(" -C Include semantics in cache functions\n");
325 printf(" -E Expand (duplicate) semantic functions\n");
326 printf(" -I <icache-size> Generate cracking cache version\n");
327 printf(" -R Use defines to reference cache vars\n");
328 printf(" -L Supress line numbering in output files\n");
329 printf(" -B <bit-size> Set the number of bits in an instruction\n");
330 printf(" -H <high-bit> Set the nr of the high (msb bit)\n");
331 printf(" -N <nr-cpus> Specify the max number of cpus the simulation will support\n");
332 printf(" -J Use jumps instead of function calls\n");
334 printf("Input options (ucase version also dumps loaded table):\n");
335 printf(" -o <opcode-rules>\n");
336 printf(" -k <cache-rules>\n");
337 printf(" -i <instruction-table>\n");
339 printf("Output options:\n");
340 printf(" -n <real-name> Specify the real name of for the next output file\n");
341 printf(" -h Generate header file\n");
342 printf(" -c <output-file> output icache\n");
343 printf(" -d <output-file> output idecode\n");
344 printf(" -m <output-file> output model\n");
345 printf(" -s <output-file> output schematic\n");
346 printf(" -t <output-file> output itable\n");
347 printf(" -f <output-file> output support functions\n");
350 while ((ch
= getopt(argc
, argv
,
351 "F:EI:RLJCB:H:N:o:k:i:n:hc:d:m:s:t:f:"))
353 fprintf(stderr
, "\t-%c %s\n", ch
, (optarg
? optarg
: ""));
356 code
|= generate_with_icache
;
357 code
|= generate_with_semantic_icache
;
358 if (icache_size
== 0)
362 file_references
= lf_omit_references
;
365 generate_expanded_instructions
= 1;
368 icache_size
= a2i(optarg
);
369 code
|= generate_with_icache
;
372 generate_smp
= a2i(optarg
);
375 code
|= generate_with_icache
;
376 code
|= generate_with_direct_access_icache
;
377 if (icache_size
== 0)
381 insn_bit_size
= a2i(optarg
);
382 ASSERT(insn_bit_size
> 0 && insn_bit_size
<= max_insn_bit_size
383 && (hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0));
386 hi_bit_nr
= a2i(optarg
);
387 ASSERT(hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0);
390 filters
= new_filter(optarg
, filters
);
393 code
&= ~generate_calls
;
394 code
|= generate_jumps
;
397 if (decode_rules
== NULL
|| cache_rules
== NULL
) {
398 fprintf(stderr
, "Must specify decode and cache tables\n");
401 instructions
= load_insn_table(optarg
, decode_rules
, filters
);
402 fprintf(stderr
, "\texpanding ...\n");
403 insn_table_expand_insns(instructions
);
406 decode_rules
= load_decode_table(optarg
, hi_bit_nr
);
409 cache_rules
= load_cache_table(optarg
, hi_bit_nr
);
412 real_file_name
= strdup(optarg
);
424 lf
*file
= lf_open(optarg
, real_file_name
, file_references
,
425 (is_header
? lf_is_h
: lf_is_c
),
427 lf_print__file_start(file
);
428 ASSERT(instructions
!= NULL
);
432 gen_semantics_h(instructions
, file
, code
);
434 gen_semantics_c(instructions
, cache_rules
, file
, code
);
438 gen_idecode_h(file
, instructions
, cache_rules
);
440 gen_idecode_c(file
, instructions
, cache_rules
);
444 gen_model_h(instructions
, file
);
446 gen_model_c(instructions
, file
);
450 gen_itable_h(instructions
, file
);
452 gen_itable_c(instructions
, file
);
456 gen_support_h(instructions
, file
);
458 gen_support_c(instructions
, file
);
462 gen_icache_h(instructions
, file
, code
);
464 gen_icache_c(instructions
, cache_rules
, file
, code
);
467 lf_print__file_finish(file
);
471 real_file_name
= NULL
;
474 error("unknown option\n");