1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, 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
= default_insn_bit_size
;
47 int insn_specifying_widths
= 0;
48 const char *global_name_prefix
= "";
49 const char *global_uname_prefix
= "";
51 int code
= generate_calls
;
53 int generate_expanded_instructions
;
54 int icache_size
= 1024;
57 /****************************************************************/
60 /* Semantic functions */
63 print_semantic_function_formal(lf
*file
)
66 if ((code
& generate_with_icache
))
67 nr
= lf_printf(file
, "SIM_DESC sd,\n %sidecode_cache *cache_entry,\n address_word cia",
69 else if (generate_smp
)
70 nr
= lf_printf(file
, "sim_cpu *cpu,\n %sinstruction_word instruction,\n address_word cia",
73 nr
= lf_printf(file
, "SIM_DESC sd,\n %sinstruction_word instruction,\n address_word cia",
79 print_semantic_function_actual(lf
*file
)
82 if ((code
& generate_with_icache
))
83 nr
= lf_printf(file
, "sd, cache_entry, cia");
84 else if (generate_smp
)
85 nr
= lf_printf(file
, "cpu, instruction, cia");
87 nr
= lf_printf(file
, "sd, instruction, cia");
92 print_semantic_function_type(lf
*file
)
95 nr
= lf_printf(file
, "address_word");
100 /* Idecode functions */
103 print_icache_function_formal(lf
*file
)
107 nr
+= lf_printf(file
, "sim_cpu *cpu,\n");
109 nr
+= lf_printf(file
, "SIM_DESC sd,\n");
110 nr
+= lf_printf(file
, " %sinstruction_word instruction,\n", global_name_prefix
);
111 nr
+= lf_printf(file
, " address_word cia,\n");
112 nr
+= lf_printf(file
, " %sidecode_cache *cache_entry", global_name_prefix
);
117 print_icache_function_actual(lf
*file
)
121 nr
= lf_printf(file
, "cpu, instruction, cia, cache_entry");
123 nr
= lf_printf(file
, "sd, instruction, cia, cache_entry");
128 print_icache_function_type(lf
*file
)
131 if ((code
& generate_with_semantic_icache
))
132 nr
= print_semantic_function_type(file
);
134 nr
= lf_printf(file
, "%sidecode_semantic *", global_name_prefix
);
142 print_insn_bits(lf
*file
, insn_bits
*bits
)
147 nr
+= print_insn_bits(file
, bits
->last
);
148 nr
+= lf_putchr(file
, '_');
149 nr
+= lf_putstr(file
, bits
->field
->val_string
);
150 if (bits
->opcode
->is_boolean
&& bits
->value
== 0)
151 nr
+= lf_putint(file
, bits
->opcode
->boolean_constant
);
152 else if (!bits
->opcode
->is_boolean
) {
153 if (bits
->opcode
->last
< bits
->field
->last
)
154 nr
+= lf_putint(file
, bits
->value
<< (bits
->field
->last
- bits
->opcode
->last
));
156 nr
+= lf_putint(file
, bits
->value
);
162 print_function_name(lf
*file
,
163 const char *basename
,
164 insn_bits
*expanded_bits
,
165 lf_function_name_prefixes prefix
)
170 case function_name_prefix_semantics
:
171 nr
+= lf_putstr(file
, global_name_prefix
);
172 nr
+= lf_putstr(file
, "semantic_");
174 case function_name_prefix_idecode
:
175 nr
+= lf_putstr(file
, global_name_prefix
);
176 nr
+= lf_printf(file
, "idecode_");
178 case function_name_prefix_itable
:
179 nr
+= lf_putstr(file
, "itable_");
181 case function_name_prefix_icache
:
182 nr
+= lf_putstr(file
, global_name_prefix
);
183 nr
+= lf_putstr(file
, "icache_");
189 /* the function name */
200 nr
+= lf_putchr(file
, '_');
203 nr
+= lf_putchr(file
, *pos
);
210 if (generate_expanded_instructions
)
211 nr
+= print_insn_bits(file
, expanded_bits
);
218 print_my_defines(lf
*file
,
219 insn_bits
*expanded_bits
,
220 table_entry
*file_entry
)
222 /* #define MY_INDEX xxxxx */
223 lf_indent_suppress(file
);
224 lf_printf(file
, "#undef MY_INDEX\n");
225 lf_indent_suppress(file
);
226 lf_printf(file
, "#define MY_INDEX ");
227 print_function_name(file
,
228 file_entry
->fields
[insn_name
],
230 function_name_prefix_itable
);
231 lf_printf(file
, "\n");
232 /* #define MY_PREFIX xxxxxx */
233 lf_indent_suppress(file
);
234 lf_printf(file
, "#undef MY_PREFIX\n");
235 lf_indent_suppress(file
);
236 lf_printf(file
, "#define MY_PREFIX ");
237 print_function_name(file
,
238 file_entry
->fields
[insn_name
],
240 function_name_prefix_none
);
241 lf_printf(file
, "\n");
246 print_itrace(lf
*file
,
247 table_entry
*file_entry
,
250 const char *object
= idecode
? "DECODE" : "INSN";
251 lf_printf(file
, "\n");
252 lf_indent_suppress(file
);
253 lf_printf(file
, "#if defined(WITH_TRACE)\n");
254 lf_printf(file
, "/* trace the instructions execution if enabled */\n");
255 lf_printf(file
, "if (TRACE_%s_P (CPU)) {\n", object
);
256 lf_printf(file
, " trace_printf (CPU,\n");
257 lf_printf(file
, " \"%s:%d:0x%%08lx:%%s\\n\", %s, %s);\n",
258 filter_filename(file_entry
->file_name
),
261 "itable[MY_INDEX].name");
262 lf_printf(file
, "}\n");
263 lf_indent_suppress(file
);
264 lf_printf(file
, "#endif\n");
268 /****************************************************************/
272 gen_semantics_h(insn_table
*table
,
276 lf_printf(file
, "typedef ");
277 print_semantic_function_type(file
);
278 lf_printf(file
, " %sidecode_semantic\n(", global_name_prefix
);
279 print_semantic_function_formal(file
);
280 lf_printf(file
, ");\n");
281 lf_printf(file
, "\n");
282 if ((code
& generate_calls
)) {
283 if (generate_expanded_instructions
)
284 insn_table_traverse_tree(table
,
288 print_semantic_declaration
, /* leaf */
292 insn_table_traverse_insn(table
,
294 print_semantic_declaration
);
298 lf_print__this_file_is_empty(file
);
304 gen_semantics_c(insn_table
*table
,
305 cache_table
*cache_rules
,
309 if ((code
& generate_calls
)) {
310 lf_printf(file
, "\n");
311 lf_printf(file
, "#include \"sim-main.h\"\n");
312 lf_printf(file
, "#include \"%sidecode.h\"\n", global_name_prefix
);
313 lf_printf(file
, "#include \"%ssemantics.h\"\n", global_name_prefix
);
314 lf_printf(file
, "#include \"%ssupport.h\"\n", global_name_prefix
);
315 lf_printf(file
, "\n");
316 if (generate_expanded_instructions
)
317 insn_table_traverse_tree(table
,
321 print_semantic_definition
, /* leaf */
325 insn_table_traverse_insn(table
,
327 print_semantic_definition
);
331 lf_print__this_file_is_empty(file
);
336 /****************************************************************/
340 gen_icache_h(insn_table
*table
,
344 lf_printf(file
, "typedef ");
345 print_icache_function_type(file
);
346 lf_printf(file
, " %sidecode_icache\n(", global_name_prefix
);
347 print_icache_function_formal(file
);
348 lf_printf(file
, ");\n");
349 lf_printf(file
, "\n");
350 if ((code
& generate_calls
)
351 && (code
& generate_with_icache
)) {
352 insn_table_traverse_function(table
,
354 print_icache_internal_function_declaration
);
355 if (generate_expanded_instructions
)
356 insn_table_traverse_tree(table
,
360 print_icache_declaration
, /* leaf */
364 insn_table_traverse_insn(table
,
366 print_icache_declaration
);
370 lf_print__this_file_is_empty(file
);
375 gen_icache_c(insn_table
*table
,
376 cache_table
*cache_rules
,
380 /* output `internal' invalid/floating-point unavailable functions
382 if ((code
& generate_calls
)
383 && (code
& generate_with_icache
)) {
384 lf_printf(file
, "\n");
385 lf_printf(file
, "#include \"cpu.h\"\n");
386 lf_printf(file
, "#include \"idecode.h\"\n");
387 lf_printf(file
, "#include \"semantics.h\"\n");
388 lf_printf(file
, "#include \"icache.h\"\n");
389 lf_printf(file
, "#include \"support.h\"\n");
390 lf_printf(file
, "\n");
391 insn_table_traverse_function(table
,
393 print_icache_internal_function_definition
);
394 lf_printf(file
, "\n");
395 if (generate_expanded_instructions
)
396 insn_table_traverse_tree(table
,
400 print_icache_definition
, /* leaf */
404 insn_table_traverse_insn(table
,
406 print_icache_definition
);
410 lf_print__this_file_is_empty(file
);
415 /****************************************************************/
423 cache_table
*cache_rules
= NULL
;
424 lf_file_references file_references
= lf_include_references
;
425 decode_table
*decode_rules
= NULL
;
426 filter
*filters
= NULL
;
427 insn_table
*instructions
= NULL
;
428 char *real_file_name
= NULL
;
434 printf(" igen <config-opts> ... <input-opts>... <output-opts>...\n");
435 printf("Config options:\n");
436 printf(" -F <filter-flag> eg -F 32 to include 32bit instructions\n");
437 printf(" -I <icache-size> Specify size of cracking cache\n");
438 printf(" -B <bit-size> Set the number of bits in an instruction\n");
439 printf(" -H <high-bit> Set the number of the high (msb) instruction bit\n");
440 printf(" -N <nr-cpus> Specify the max number of cpus the simulation will support\n");
441 printf(" -T <mechanism> Override the decode mechanism specified by the decode rules\n");
442 printf(" -P <prefix> Prepend all functions with the specified prefix\n");
443 printf(" -G <gen-option> Any of the following options:\n");
444 printf(" field-widths - instruction table specifies widths (not ofsesets)\n");
445 printf(" jumps - use jumps instead of function calls\n");
446 printf(" duplicate - expand (duplicate) semantic functions\n");
447 printf(" omit-line-numbers - do not include line nr info in output\n");
448 printf(" direct-access - use #defines to directly access values\n");
449 printf(" icache - generate an instruction cracking cache\n");
450 printf(" semantic-icache - include semantic code in cracking functions\n");
451 printf(" insn-in-icache - save original instruction when cracking\n");
452 printf(" default-nia-minus-one - instead of cia + insn-size\n");
453 printf(" conditional-issue - conditionally issue each instruction\n");
454 printf(" validate-slot - perform slot verification as part of decode\n");
456 printf("Input options:\n");
457 printf(" -o <decode-rules>\n");
458 printf(" -k <cache-rules>\n");
459 printf(" -i <instruction-table>\n");
461 printf("Output options:\n");
462 printf(" -n <real-name> Specify the real name of the next output file\n");
463 printf(" -h Generate header file\n");
464 printf(" -c <output-file> output icache\n");
465 printf(" -d <output-file> output idecode\n");
466 printf(" -e <output-file> output engine\n");
467 printf(" -f <output-file> output support functions\n");
468 printf(" -m <output-file> output model\n");
469 printf(" -s <output-file> output schematic\n");
470 printf(" -t <output-file> output itable\n");
473 while ((ch
= getopt(argc
, argv
,
474 "F:I:B:H:N:T:P:G:o:k:i:n:hc:d:e:m:s:t:f:"))
476 fprintf(stderr
, "\t-%c %s\n", ch
, (optarg
? optarg
: ""));
481 filters
= new_filter(optarg
, filters
);
485 icache_size
= a2i(optarg
);
486 code
|= generate_with_icache
;
490 insn_bit_size
= a2i(optarg
);
491 ASSERT(insn_bit_size
> 0 && insn_bit_size
<= max_insn_bit_size
492 && (hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0));
496 hi_bit_nr
= a2i(optarg
);
497 ASSERT(hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0);
501 generate_smp
= a2i(optarg
);
505 force_decode_gen_type(optarg
);
511 global_name_prefix
= strdup(optarg
);
512 chp
= strdup(optarg
);
513 global_uname_prefix
= chp
;
516 *chp
= toupper(*chp
);
523 if (strcmp(optarg
, "jumps") == 0) {
524 code
&= ~generate_calls
;
525 code
|= generate_jumps
;
527 else if (strcmp(optarg
, "field-widths") == 0) {
528 insn_specifying_widths
= 1;
530 else if (strcmp(optarg
, "duplicate") == 0) {
531 generate_expanded_instructions
= 1;
533 else if (strcmp(optarg
, "omit-line-numbers") == 0) {
534 file_references
= lf_omit_references
;
536 else if (strcmp(optarg
, "direct-access") == 0) {
537 code
|= generate_with_direct_access
;
539 else if (strcmp(optarg
, "icache") == 0) {
541 else if (strcmp(optarg
, "semantic-icache") == 0) {
542 code
|= generate_with_icache
;
543 code
|= generate_with_semantic_icache
;
545 else if (strcmp(optarg
, "insn-in-icache") == 0) {
546 code
|= generate_with_icache
;
547 code
|= generate_with_insn_in_icache
;
549 else if (strcmp(optarg
, "default-nia-minus-one") == 0) {
550 code
|= generate_with_semantic_returning_modified_nia_only
;
552 else if (strcmp(optarg
, "conditional-issue") == 0) {
553 code
|= generate_with_semantic_conditional_issue
;
555 else if (strcmp(optarg
, "verify-slot") == 0) {
556 code
|= generate_with_idecode_slot_verification
;
559 error("Unknown option %s", optarg
);
563 if (decode_rules
== NULL
|| cache_rules
== NULL
) {
564 fprintf(stderr
, "Must specify decode and cache tables\n");
567 instructions
= load_insn_table(optarg
, decode_rules
, filters
);
568 fprintf(stderr
, "\texpanding ...\n");
569 insn_table_expand_insns(instructions
);
572 decode_rules
= load_decode_table(optarg
, hi_bit_nr
);
575 cache_rules
= load_cache_table(optarg
, hi_bit_nr
);
578 real_file_name
= strdup(optarg
);
591 lf
*file
= lf_open(optarg
, real_file_name
, file_references
,
592 (is_header
? lf_is_h
: lf_is_c
),
594 lf_print__file_start(file
);
595 ASSERT(instructions
!= NULL
);
599 gen_semantics_h(instructions
, file
, code
);
601 gen_semantics_c(instructions
, cache_rules
, file
, code
);
605 gen_idecode_h(file
, instructions
, cache_rules
);
607 gen_idecode_c(file
, instructions
, cache_rules
);
611 gen_engine_h(file
, instructions
, cache_rules
);
613 gen_engine_c(file
, instructions
, cache_rules
);
617 gen_model_h(instructions
, file
);
619 gen_model_c(instructions
, file
);
623 gen_itable_h(instructions
, file
);
625 gen_itable_c(instructions
, file
);
629 gen_support_h(instructions
, file
);
631 gen_support_c(instructions
, file
);
635 gen_icache_h(instructions
, file
, code
);
637 gen_icache_c(instructions
, cache_rules
, file
, code
);
640 lf_print__file_finish(file
);
644 real_file_name
= NULL
;
647 error("unknown option\n");