1 /* This file is part of the program psim.
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 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", (idecode) ? "DECODE" : "INSN");
256 lf_printf(file, " trace_one_insn (SD, CPU, \"%s\", %d, %d, %s, itable[MY_INDEX].name);\n",
257 filter_filename(file_entry->file_name),
260 (code & generate_with_semantic_delayed_branch) ? "cia.ip" : "cia");
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(" delayed-branch - instead of cia + insn-size\n");
454 printf(" conditional-issue - conditionally issue each instruction\n");
455 printf(" validate-slot - perform slot verification as part of decode\n");
457 printf("Input options:\n");
458 printf(" -o <decode-rules>\n");
459 printf(" -k <cache-rules>\n");
460 printf(" -i <instruction-table>\n");
462 printf("Output options:\n");
463 printf(" -n <real-name> Specify the real name of the next output file\n");
464 printf(" -h Generate header file\n");
465 printf(" -c <output-file> output icache\n");
466 printf(" -d <output-file> output idecode\n");
467 printf(" -e <output-file> output engine\n");
468 printf(" -f <output-file> output support functions\n");
469 printf(" -m <output-file> output model\n");
470 printf(" -s <output-file> output schematic\n");
471 printf(" -t <output-file> output itable\n");
474 while ((ch = getopt(argc, argv,
475 "F:I:B:H:N:T:P:G:o:k:i:n:hc:d:e:m:s:t:f:"))
477 fprintf(stderr, "\t-%c %s\n", ch, (optarg ? optarg : ""));
482 filters = new_filter(optarg, filters);
486 icache_size = a2i(optarg);
487 code |= generate_with_icache;
491 insn_bit_size = a2i(optarg);
492 ASSERT(insn_bit_size > 0 && insn_bit_size <= max_insn_bit_size
493 && (hi_bit_nr == insn_bit_size-1 || hi_bit_nr == 0));
497 hi_bit_nr = a2i(optarg);
498 ASSERT(hi_bit_nr == insn_bit_size-1 || hi_bit_nr == 0);
502 generate_smp = a2i(optarg);
506 force_decode_gen_type(optarg);
512 global_name_prefix = strdup(optarg);
513 chp = strdup(optarg);
514 global_uname_prefix = chp;
517 *chp = toupper(*chp);
524 if (strcmp(optarg, "jumps") == 0) {
525 code &= ~generate_calls;
526 code |= generate_jumps;
528 else if (strcmp(optarg, "field-widths") == 0) {
529 insn_specifying_widths = 1;
531 else if (strcmp(optarg, "duplicate") == 0) {
532 generate_expanded_instructions = 1;
534 else if (strcmp(optarg, "omit-line-numbers") == 0) {
535 file_references = lf_omit_references;
537 else if (strcmp(optarg, "direct-access") == 0) {
538 code |= generate_with_direct_access;
540 else if (strcmp(optarg, "icache") == 0) {
542 else if (strcmp(optarg, "semantic-icache") == 0) {
543 code |= generate_with_icache;
544 code |= generate_with_semantic_icache;
546 else if (strcmp(optarg, "insn-in-icache") == 0) {
547 code |= generate_with_icache;
548 code |= generate_with_insn_in_icache;
550 else if (strcmp(optarg, "default-nia-minus-one") == 0) {
551 code |= generate_with_semantic_returning_modified_nia_only;
552 code &= ~generate_with_semantic_delayed_branch;
554 else if (strcmp(optarg, "delayed-branch") == 0) {
555 code |= generate_with_semantic_delayed_branch;
556 code &= ~generate_with_semantic_returning_modified_nia_only;
558 else if (strcmp(optarg, "conditional-issue") == 0) {
559 code |= generate_with_semantic_conditional_issue;
561 else if (strcmp(optarg, "verify-slot") == 0) {
562 code |= generate_with_idecode_slot_verification;
565 error("Unknown option %s", optarg);
569 if (decode_rules == NULL || cache_rules == NULL) {
570 fprintf(stderr, "Must specify decode and cache tables\n");
573 instructions = load_insn_table(optarg, decode_rules, filters);
574 fprintf(stderr, "\texpanding ...\n");
575 insn_table_expand_insns(instructions);
578 decode_rules = load_decode_table(optarg, hi_bit_nr);
581 cache_rules = load_cache_table(optarg, hi_bit_nr);
584 real_file_name = strdup(optarg);
597 lf *file = lf_open(optarg, real_file_name, file_references,
598 (is_header ? lf_is_h : lf_is_c),
600 lf_print__file_start(file);
601 ASSERT(instructions != NULL);
605 gen_semantics_h(instructions, file, code);
607 gen_semantics_c(instructions, cache_rules, file, code);
611 gen_idecode_h(file, instructions, cache_rules);
613 gen_idecode_c(file, instructions, cache_rules);
617 gen_engine_h(file, instructions, cache_rules);
619 gen_engine_c(file, instructions, cache_rules);
623 gen_model_h(instructions, file);
625 gen_model_c(instructions, file);
629 gen_itable_h(instructions, file);
631 gen_itable_c(instructions, file);
635 gen_support_h(instructions, file);
637 gen_support_c(instructions, file);
641 gen_icache_h(instructions, file, code);
643 gen_icache_c(instructions, cache_rules, file, code);
646 lf_print__file_finish(file);
650 real_file_name = NULL;
653 error("unknown option\n");