📄 igen.c
字号:
/* This file is part of the program psim. Copyright 1994, 1995, 1996, 1997, 2003 Andrew Cagney This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <getopt.h>#include "misc.h"#include "lf.h"#include "table.h"#include "config.h"#include "filter.h"#include "ld-cache.h"#include "ld-decode.h"#include "ld-insn.h"#include "igen.h"#include "gen-model.h"#include "gen-icache.h"#include "gen-itable.h"#include "gen-idecode.h"#include "gen-semantics.h"#include "gen-support.h"int hi_bit_nr;int insn_bit_size = max_insn_bit_size;igen_code code = generate_calls;int generate_expanded_instructions;int icache_size = 1024;int generate_smp;/****************************************************************/static intprint_insn_bits(lf *file, insn_bits *bits){ int nr = 0; if (bits == NULL) return nr; nr += print_insn_bits(file, bits->last); nr += lf_putchr(file, '_'); nr += lf_putstr(file, bits->field->val_string); if (bits->opcode->is_boolean && bits->value == 0) nr += lf_putint(file, bits->opcode->boolean_constant); else if (!bits->opcode->is_boolean) { if (bits->opcode->last < bits->field->last) nr += lf_putint(file, bits->value << (bits->field->last - bits->opcode->last)); else nr += lf_putint(file, bits->value); } return nr;}extern intprint_function_name(lf *file, const char *basename, insn_bits *expanded_bits, lf_function_name_prefixes prefix){ int nr = 0; /* the prefix */ switch (prefix) { case function_name_prefix_semantics: nr += lf_putstr(file, "semantic_"); break; case function_name_prefix_idecode: nr += lf_printf(file, "idecode_"); break; case function_name_prefix_itable: nr += lf_putstr(file, "itable_"); break; case function_name_prefix_icache: nr += lf_putstr(file, "icache_"); break; default: break; } /* the function name */ { const char *pos; for (pos = basename; *pos != '\0'; pos++) { switch (*pos) { case '/': case '-': case '(': case ')': break; case ' ': nr += lf_putchr(file, '_'); break; default: nr += lf_putchr(file, *pos); break; } } } /* the suffix */ if (generate_expanded_instructions) nr += print_insn_bits(file, expanded_bits); return nr;}voidprint_my_defines(lf *file, insn_bits *expanded_bits, table_entry *file_entry){ /* #define MY_INDEX xxxxx */ lf_indent_suppress(file); lf_printf(file, "#undef MY_INDEX\n"); lf_indent_suppress(file); lf_printf(file, "#define MY_INDEX "); print_function_name(file, file_entry->fields[insn_name], NULL, function_name_prefix_itable); lf_printf(file, "\n"); /* #define MY_PREFIX xxxxxx */ lf_indent_suppress(file); lf_printf(file, "#undef MY_PREFIX\n"); lf_indent_suppress(file); lf_printf(file, "#define MY_PREFIX "); print_function_name(file, file_entry->fields[insn_name], expanded_bits, function_name_prefix_none); lf_printf(file, "\n");}voidprint_itrace(lf *file, table_entry *file_entry, int idecode){ lf_print__external_reference(file, file_entry->line_nr, file_entry->file_name); lf_printf(file, "ITRACE(trace_%s, (\"%s %s\\n\"));\n", (idecode ? "idecode" : "semantics"), (idecode ? "idecode" : "semantics"), file_entry->fields[insn_name]); lf_print__internal_reference(file);}/****************************************************************/static voidgen_semantics_h(insn_table *table, lf *file, igen_code generate){ lf_printf(file, "typedef %s idecode_semantic\n(%s);\n", SEMANTIC_FUNCTION_TYPE, SEMANTIC_FUNCTION_FORMAL); lf_printf(file, "\n"); if ((code & generate_calls)) { lf_printf(file, "extern int option_mpc860c0;\n"); lf_printf(file, "#define PAGE_SIZE 0x1000\n"); lf_printf(file, "\n"); lf_printf(file, "PSIM_EXTERN_SEMANTICS(void)\n"); lf_printf(file, "semantic_init(device* root);\n"); lf_printf(file, "\n"); if (generate_expanded_instructions) insn_table_traverse_tree(table, file, NULL, 1, NULL, /* start */ print_semantic_declaration, /* leaf */ NULL, /* end */ NULL); /* padding */ else insn_table_traverse_insn(table, file, NULL, print_semantic_declaration); } else { lf_print__this_file_is_empty(file); }}static voidgen_semantics_c(insn_table *table, cache_table *cache_rules, lf *file, igen_code generate){ if ((code & generate_calls)) { lf_printf(file, "\n"); lf_printf(file, "#include \"cpu.h\"\n"); lf_printf(file, "#include \"idecode.h\"\n"); lf_printf(file, "#include \"semantics.h\"\n"); lf_printf(file, "#ifdef HAVE_COMMON_FPU\n"); lf_printf(file, "#include \"sim-inline.h\"\n"); lf_printf(file, "#include \"sim-fpu.h\"\n"); lf_printf(file, "#endif\n"); lf_printf(file, "#include \"support.h\"\n"); lf_printf(file, "\n"); lf_printf(file, "int option_mpc860c0 = 0;\n"); lf_printf(file, "\n"); lf_printf(file, "PSIM_EXTERN_SEMANTICS(void)\n"); lf_printf(file, "semantic_init(device* root)\n"); lf_printf(file, "{\n"); lf_printf(file, " option_mpc860c0 = 0;\n"); lf_printf(file, " if (tree_find_property(root, \"/options/mpc860c0\"))\n"); lf_printf(file, " option_mpc860c0 = tree_find_integer_property(root, \"/options/mpc860c0\");\n"); lf_printf(file, " option_mpc860c0 *= 4; /* convert word count to byte count */\n"); lf_printf(file, "}\n"); lf_printf(file, "\n"); if (generate_expanded_instructions) insn_table_traverse_tree(table, file, cache_rules, 1, NULL, /* start */ print_semantic_definition, /* leaf */ NULL, /* end */ NULL); /* padding */ else insn_table_traverse_insn(table, file, cache_rules, print_semantic_definition); } else { lf_print__this_file_is_empty(file); }}/****************************************************************/static voidgen_icache_h(insn_table *table, lf *file, igen_code generate){ lf_printf(file, "typedef %s idecode_icache\n(%s);\n", ICACHE_FUNCTION_TYPE, ICACHE_FUNCTION_FORMAL); lf_printf(file, "\n"); if ((code & generate_calls) && (code & generate_with_icache)) { insn_table_traverse_function(table, file, NULL, print_icache_internal_function_declaration); if (generate_expanded_instructions) insn_table_traverse_tree(table, file, NULL, 1, NULL, /* start */ print_icache_declaration, /* leaf */ NULL, /* end */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -