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 %sinstruction_address cia",
68 global_name_prefix
, global_name_prefix
);
69 else if (generate_smp
)
70 nr
= lf_printf(file
, "sim_cpu *cpu,\n %sinstruction_word instruction,\n %sinstruction_address cia",
71 global_name_prefix
, global_name_prefix
);
73 nr
= lf_printf(file
, "SIM_DESC sd,\n %sinstruction_word instruction,\n %sinstruction_address cia",
74 global_name_prefix
, global_name_prefix
);
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
, "%sinstruction_address", global_name_prefix
);
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
, " %sinstruction_address cia,\n", global_name_prefix
);
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 */
201 nr
+= lf_putchr(file
, '_');
204 nr
+= lf_putchr(file
, *pos
);
211 if (generate_expanded_instructions
)
212 nr
+= print_insn_bits(file
, expanded_bits
);
219 print_my_defines(lf
*file
,
220 insn_bits
*expanded_bits
,
221 table_entry
*file_entry
)
223 /* #define MY_INDEX xxxxx */
224 lf_indent_suppress(file
);
225 lf_printf(file
, "#undef MY_INDEX\n");
226 lf_indent_suppress(file
);
227 lf_printf(file
, "#define MY_INDEX ");
228 print_function_name(file
,
229 file_entry
->fields
[insn_name
],
231 function_name_prefix_itable
);
232 lf_printf(file
, "\n");
233 /* #define MY_PREFIX xxxxxx */
234 lf_indent_suppress(file
);
235 lf_printf(file
, "#undef MY_PREFIX\n");
236 lf_indent_suppress(file
);
237 lf_printf(file
, "#define MY_PREFIX ");
238 print_function_name(file
,
239 file_entry
->fields
[insn_name
],
241 function_name_prefix_none
);
242 lf_printf(file
, "\n");
247 print_itrace(lf
*file
,
248 table_entry
*file_entry
,
251 const char *phase
= (idecode
) ? "DECODE" : "INSN";
252 const char *phase_lc
= (idecode
) ? "decode" : "insn";
253 lf_printf(file
, "\n");
254 lf_indent_suppress(file
);
255 lf_printf(file
, "#if defined(WITH_TRACE)\n");
256 lf_printf(file
, "/* trace the instructions execution if enabled */\n");
257 lf_printf(file
, "if (TRACE_%s_P (CPU)) {\n", phase
);
258 lf_printf(file
, " trace_one_insn (SD, CPU, %s, TRACE_LINENUM_P (CPU),\n",
259 (code
& generate_with_semantic_delayed_branch
) ? "cia.ip" : "cia");
261 lf_printf(file
, " itable[MY_INDEX].file, MY_INDEX, \"%s\",\n", phase_lc
);
262 lf_printf(file
, " itable[MY_INDEX].name);\n");
264 lf_printf(file
, "}\n");
265 lf_indent_suppress(file
);
266 lf_printf(file
, "#endif\n");
270 /****************************************************************/
274 gen_semantics_h(insn_table
*table
,
278 lf_printf(file
, "typedef ");
279 print_semantic_function_type(file
);
280 lf_printf(file
, " %sidecode_semantic\n(", global_name_prefix
);
281 print_semantic_function_formal(file
);
282 lf_printf(file
, ");\n");
283 lf_printf(file
, "\n");
284 if ((code
& generate_calls
)) {
285 if (generate_expanded_instructions
)
286 insn_table_traverse_tree(table
,
290 print_semantic_declaration
, /* leaf */
294 insn_table_traverse_insn(table
,
296 print_semantic_declaration
);
300 lf_print__this_file_is_empty(file
);
306 gen_semantics_c(insn_table
*table
,
307 cache_table
*cache_rules
,
311 if ((code
& generate_calls
)) {
312 lf_printf(file
, "\n");
313 lf_printf(file
, "#include \"sim-main.h\"\n");
314 lf_printf(file
, "#include \"%sidecode.h\"\n", global_name_prefix
);
315 lf_printf(file
, "#include \"%ssemantics.h\"\n", global_name_prefix
);
316 lf_printf(file
, "#include \"%ssupport.h\"\n", global_name_prefix
);
317 lf_printf(file
, "\n");
318 if (generate_expanded_instructions
)
319 insn_table_traverse_tree(table
,
323 print_semantic_definition
, /* leaf */
327 insn_table_traverse_insn(table
,
329 print_semantic_definition
);
333 lf_print__this_file_is_empty(file
);
338 /****************************************************************/
342 gen_icache_h(insn_table
*table
,
346 lf_printf(file
, "typedef ");
347 print_icache_function_type(file
);
348 lf_printf(file
, " %sidecode_icache\n(", global_name_prefix
);
349 print_icache_function_formal(file
);
350 lf_printf(file
, ");\n");
351 lf_printf(file
, "\n");
352 if ((code
& generate_calls
)
353 && (code
& generate_with_icache
)) {
354 insn_table_traverse_function(table
,
356 print_icache_internal_function_declaration
);
357 if (generate_expanded_instructions
)
358 insn_table_traverse_tree(table
,
362 print_icache_declaration
, /* leaf */
366 insn_table_traverse_insn(table
,
368 print_icache_declaration
);
372 lf_print__this_file_is_empty(file
);
377 gen_icache_c(insn_table
*table
,
378 cache_table
*cache_rules
,
382 /* output `internal' invalid/floating-point unavailable functions
384 if ((code
& generate_calls
)
385 && (code
& generate_with_icache
)) {
386 lf_printf(file
, "\n");
387 lf_printf(file
, "#include \"cpu.h\"\n");
388 lf_printf(file
, "#include \"idecode.h\"\n");
389 lf_printf(file
, "#include \"semantics.h\"\n");
390 lf_printf(file
, "#include \"icache.h\"\n");
391 lf_printf(file
, "#include \"support.h\"\n");
392 lf_printf(file
, "\n");
393 insn_table_traverse_function(table
,
395 print_icache_internal_function_definition
);
396 lf_printf(file
, "\n");
397 if (generate_expanded_instructions
)
398 insn_table_traverse_tree(table
,
402 print_icache_definition
, /* leaf */
406 insn_table_traverse_insn(table
,
408 print_icache_definition
);
412 lf_print__this_file_is_empty(file
);
417 /****************************************************************/
425 cache_table
*cache_rules
= NULL
;
426 lf_file_references file_references
= lf_include_references
;
427 decode_table
*decode_rules
= NULL
;
428 filter
*filters
= NULL
;
429 insn_table
*instructions
= NULL
;
430 char *real_file_name
= NULL
;
436 printf(" igen <config-opts> ... <input-opts>... <output-opts>...\n");
437 printf("Config options:\n");
438 printf(" -F <filter-flag> eg -F 32 to include 32bit instructions\n");
439 printf(" -I <icache-size> Specify size of cracking cache\n");
440 printf(" -B <bit-size> Set the number of bits in an instruction\n");
441 printf(" -H <high-bit> Set the number of the high (msb) instruction bit\n");
442 printf(" -N <nr-cpus> Specify the max number of cpus the simulation will support\n");
443 printf(" -T <mechanism> Override the decode mechanism specified by the decode rules\n");
444 printf(" -P <prefix> Prepend all functions with the specified prefix\n");
445 printf(" -G <gen-option> Any of the following options:\n");
446 printf(" field-widths - instruction table specifies widths (not ofsesets)\n");
447 printf(" jumps - use jumps instead of function calls\n");
448 printf(" duplicate - expand (duplicate) semantic functions\n");
449 printf(" omit-line-numbers - do not include line nr info in output\n");
450 printf(" direct-access - use #defines to directly access values\n");
451 printf(" icache - generate an instruction cracking cache\n");
452 printf(" semantic-icache - include semantic code in cracking functions\n");
453 printf(" insn-in-icache - save original instruction when cracking\n");
454 printf(" default-nia-minus-one - instead of cia + insn-size\n");
455 printf(" delayed-branch - instead of cia + insn-size\n");
456 printf(" conditional-issue - conditionally issue each instruction\n");
457 printf(" validate-slot - perform slot verification as part of decode\n");
459 printf("Input options:\n");
460 printf(" -o <decode-rules>\n");
461 printf(" -k <cache-rules>\n");
462 printf(" -i <instruction-table>\n");
464 printf("Output options:\n");
465 printf(" -n <real-name> Specify the real name of the next output file\n");
466 printf(" -h Generate header file\n");
467 printf(" -c <output-file> output icache\n");
468 printf(" -d <output-file> output idecode\n");
469 printf(" -e <output-file> output engine\n");
470 printf(" -f <output-file> output support functions\n");
471 printf(" -m <output-file> output model\n");
472 printf(" -s <output-file> output schematic\n");
473 printf(" -t <output-file> output itable\n");
476 while ((ch
= getopt(argc
, argv
,
477 "F:I:B:H:N:T:P:G:o:k:i:n:hc:d:e:m:s:t:f:"))
479 fprintf(stderr
, "\t-%c %s\n", ch
, (optarg
? optarg
: ""));
484 filters
= new_filter(optarg
, filters
);
488 icache_size
= a2i(optarg
);
489 code
|= generate_with_icache
;
493 insn_bit_size
= a2i(optarg
);
494 ASSERT(insn_bit_size
> 0 && insn_bit_size
<= max_insn_bit_size
495 && (hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0));
499 hi_bit_nr
= a2i(optarg
);
500 ASSERT(hi_bit_nr
== insn_bit_size
-1 || hi_bit_nr
== 0);
504 generate_smp
= a2i(optarg
);
508 force_decode_gen_type(optarg
);
514 global_name_prefix
= strdup(optarg
);
515 chp
= strdup(optarg
);
516 global_uname_prefix
= chp
;
519 *chp
= toupper(*chp
);
526 if (strcmp(optarg
, "jumps") == 0) {
527 code
&= ~generate_calls
;
528 code
|= generate_jumps
;
530 else if (strcmp(optarg
, "field-widths") == 0) {
531 insn_specifying_widths
= 1;
533 else if (strcmp(optarg
, "duplicate") == 0) {
534 generate_expanded_instructions
= 1;
536 else if (strcmp(optarg
, "omit-line-numbers") == 0) {
537 file_references
= lf_omit_references
;
539 else if (strcmp(optarg
, "direct-access") == 0) {
540 code
|= generate_with_direct_access
;
542 else if (strcmp(optarg
, "icache") == 0) {
544 else if (strcmp(optarg
, "semantic-icache") == 0) {
545 code
|= generate_with_icache
;
546 code
|= generate_with_semantic_icache
;
548 else if (strcmp(optarg
, "insn-in-icache") == 0) {
549 code
|= generate_with_icache
;
550 code
|= generate_with_insn_in_icache
;
552 else if (strcmp(optarg
, "default-nia-minus-one") == 0) {
553 code
|= generate_with_semantic_returning_modified_nia_only
;
554 code
&= ~generate_with_semantic_delayed_branch
;
556 else if (strcmp(optarg
, "delayed-branch") == 0) {
557 code
|= generate_with_semantic_delayed_branch
;
558 code
&= ~generate_with_semantic_returning_modified_nia_only
;
560 else if (strcmp(optarg
, "conditional-issue") == 0) {
561 code
|= generate_with_semantic_conditional_issue
;
563 else if (strcmp(optarg
, "verify-slot") == 0) {
564 code
|= generate_with_idecode_slot_verification
;
567 error("Unknown option %s", optarg
);
571 if (decode_rules
== NULL
|| cache_rules
== NULL
) {
572 fprintf(stderr
, "Must specify decode and cache tables\n");
575 instructions
= load_insn_table(optarg
, decode_rules
, filters
);
576 fprintf(stderr
, "\texpanding ...\n");
577 insn_table_expand_insns(instructions
);
580 decode_rules
= load_decode_table(optarg
, hi_bit_nr
);
583 cache_rules
= load_cache_table(optarg
, hi_bit_nr
);
586 real_file_name
= strdup(optarg
);
599 lf
*file
= lf_open(optarg
, real_file_name
, file_references
,
600 (is_header
? lf_is_h
: lf_is_c
),
602 lf_print__file_start(file
);
603 ASSERT(instructions
!= NULL
);
607 gen_semantics_h(instructions
, file
, code
);
609 gen_semantics_c(instructions
, cache_rules
, file
, code
);
613 gen_idecode_h(file
, instructions
, cache_rules
);
615 gen_idecode_c(file
, instructions
, cache_rules
);
619 gen_engine_h(file
, instructions
, cache_rules
);
621 gen_engine_c(file
, instructions
, cache_rules
);
625 gen_model_h(instructions
, file
);
627 gen_model_c(instructions
, file
);
631 gen_itable_h(instructions
, file
);
633 gen_itable_c(instructions
, file
);
637 gen_support_h(instructions
, file
);
639 gen_support_c(instructions
, file
);
643 gen_icache_h(instructions
, file
, code
);
645 gen_icache_c(instructions
, cache_rules
, file
, code
);
648 lf_print__file_finish(file
);
652 real_file_name
= NULL
;
655 error("unknown option\n");