binutils-gdb/sim/ppc/igen.c

491 lines
13 KiB
C
Raw Normal View History

1995-11-02 03:32:38 +08:00
/* This file is part of the program psim.
Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
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.
*/
1996-07-23 23:42:42 +08:00
1995-11-02 03:32:38 +08:00
#include <getopt.h>
#include "misc.h"
#include "lf.h"
1996-07-23 23:42:42 +08:00
#include "table.h"
#include "config.h"
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
#include "filter.h"
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
#include "ld-decode.h"
#include "ld-cache.h"
#include "ld-insn.h"
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
#include "igen.h"
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
#include "gen-model.h"
#include "gen-icache.h"
#include "gen-itable.h"
#include "gen-idecode.h"
#include "gen-semantics.h"
#include "gen-support.h"
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
int hi_bit_nr;
int insn_bit_size = max_insn_bit_size;
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
igen_code code = generate_calls;
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
int generate_expanded_instructions;
1997-01-28 05:34:50 +08:00
int icache_size = 1024;
1996-07-23 23:42:42 +08:00
int generate_smp;
1995-11-02 03:32:38 +08:00
/****************************************************************/
1996-07-23 23:42:42 +08:00
static int
print_insn_bits(lf *file, insn_bits *bits)
1995-11-02 03:32:38 +08:00
{
1996-07-23 23:42:42 +08:00
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));
1995-11-02 03:32:38 +08:00
else
1996-07-23 23:42:42 +08:00
nr += lf_putint(file, bits->value);
1995-11-02 03:32:38 +08:00
}
1996-07-23 23:42:42 +08:00
return nr;
}
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
extern int
print_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;
1995-11-02 03:32:38 +08:00
}
1996-07-23 23:42:42 +08:00
/* the function name */
{
const char *pos;
for (pos = basename;
*pos != '\0';
pos++) {
switch (*pos) {
case '/':
case '-':
break;
case ' ':
nr += lf_putchr(file, '_');
break;
default:
nr += lf_putchr(file, *pos);
break;
}
}
1996-03-23 23:02:42 +08:00
}
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
/* the suffix */
if (generate_expanded_instructions)
nr += print_insn_bits(file, expanded_bits);
1995-11-02 03:32:38 +08:00
1996-07-23 23:42:42 +08:00
return nr;
1995-11-02 03:32:38 +08:00
}
1996-07-23 23:42:42 +08:00
void
1997-01-28 05:34:50 +08:00
print_my_defines(lf *file,
insn_bits *expanded_bits,
table_entry *file_entry)
1995-11-02 03:32:38 +08:00
{
1997-01-28 05:34:50 +08:00
/* #define MY_INDEX xxxxx */
1996-07-23 23:42:42 +08:00
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);
1995-11-02 03:32:38 +08:00
lf_printf(file, "\n");
1997-01-28 05:34:50 +08:00
/* #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");
1995-11-02 03:32:38 +08:00
}
1996-07-23 23:42:42 +08:00
void
print_itrace(lf *file,
table_entry *file_entry,
int idecode)
1995-11-02 03:32:38 +08:00
{
1996-07-23 23:42:42 +08:00
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);
1995-11-02 03:32:38 +08:00
}
/****************************************************************/
1995-11-14 00:07:30 +08:00
static void
1996-07-23 23:42:42 +08:00
gen_semantics_h(insn_table *table,
lf *file,
igen_code generate)
{
1996-07-23 23:42:42 +08:00
lf_printf(file, "typedef %s idecode_semantic\n(%s);\n",
SEMANTIC_FUNCTION_TYPE,
SEMANTIC_FUNCTION_FORMAL);
1995-11-16 06:53:59 +08:00
lf_printf(file, "\n");
1996-07-23 23:42:42 +08:00
if ((code & generate_calls)) {
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);
1995-11-16 06:53:59 +08:00
}
1996-07-23 23:42:42 +08:00
else {
lf_print__this_file_is_empty(file);
1995-11-16 06:53:59 +08:00
}
1996-07-23 23:42:42 +08:00
}
1995-11-16 06:53:59 +08:00
1995-11-13 09:27:21 +08:00
1996-07-23 23:42:42 +08:00
static void
gen_semantics_c(insn_table *table,
cache_table *cache_rules,
lf *file,
igen_code generate)
{
if ((code & generate_calls)) {
1995-11-16 06:53:59 +08:00
lf_printf(file, "\n");
1996-07-23 23:42:42 +08:00
lf_printf(file, "#include \"cpu.h\"\n");
lf_printf(file, "#include \"idecode.h\"\n");
lf_printf(file, "#include \"semantics.h\"\n");
lf_printf(file, "#include \"support.h\"\n");
1995-11-16 06:53:59 +08:00
lf_printf(file, "\n");
1996-07-23 23:42:42 +08:00
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);
1995-11-16 06:53:59 +08:00
}
1996-07-23 23:42:42 +08:00
else {
lf_print__this_file_is_empty(file);
1995-11-16 06:53:59 +08:00
}
}
1996-07-23 23:42:42 +08:00
/****************************************************************/
1995-11-13 09:27:21 +08:00
static void
1996-07-23 23:42:42 +08:00
gen_icache_h(insn_table *table,
lf *file,
igen_code generate)
1995-11-13 09:27:21 +08:00
{
1996-07-23 23:42:42 +08:00
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 */
NULL); /* padding */
else
insn_table_traverse_insn(table,
file, NULL,
print_icache_declaration);
1995-11-13 09:27:21 +08:00
}
else {
1996-07-23 23:42:42 +08:00
lf_print__this_file_is_empty(file);
1995-11-13 09:27:21 +08:00
}
}
1996-07-23 23:42:42 +08:00
static void
gen_icache_c(insn_table *table,
cache_table *cache_rules,
lf *file,
igen_code generate)
{
1996-07-23 23:42:42 +08:00
/* output `internal' invalid/floating-point unavailable functions
where needed */
if ((code & generate_calls)
&& (code & generate_with_icache)) {
1995-11-16 06:53:59 +08:00
lf_printf(file, "\n");
1996-07-23 23:42:42 +08:00
lf_printf(file, "#include \"cpu.h\"\n");
lf_printf(file, "#include \"idecode.h\"\n");
lf_printf(file, "#include \"semantics.h\"\n");
lf_printf(file, "#include \"icache.h\"\n");
lf_printf(file, "#include \"support.h\"\n");
1995-11-16 06:53:59 +08:00
lf_printf(file, "\n");
1996-07-23 23:42:42 +08:00
insn_table_traverse_function(table,
file, NULL,
print_icache_internal_function_definition);
1995-11-17 03:02:52 +08:00
lf_printf(file, "\n");
1996-07-23 23:42:42 +08:00
if (generate_expanded_instructions)
insn_table_traverse_tree(table,
file, cache_rules,
1,
NULL, /* start */
print_icache_definition, /* leaf */
NULL, /* end */
NULL); /* padding */
else
insn_table_traverse_insn(table,
file, cache_rules,
print_icache_definition);
1995-11-16 06:53:59 +08:00
}
1996-07-23 23:42:42 +08:00
else {
lf_print__this_file_is_empty(file);
}
1995-11-02 03:32:38 +08:00
}
1996-07-23 23:42:42 +08:00
1995-11-02 03:32:38 +08:00
/****************************************************************/
int
main(int argc,
char **argv,
char **envp)
{
1996-07-23 23:42:42 +08:00
cache_table *cache_rules = NULL;
lf_file_references file_references = lf_include_references;
decode_table *decode_rules = NULL;
filter *filters = NULL;
1995-11-02 03:32:38 +08:00
insn_table *instructions = NULL;
char *real_file_name = NULL;
1996-07-23 23:42:42 +08:00
int is_header = 0;
1995-11-02 03:32:38 +08:00
int ch;
if (argc == 1) {
printf("Usage:\n");
printf(" igen <config-opts> ... <input-opts>... <output-opts>...\n");
printf("Config options:\n");
1996-07-23 23:42:42 +08:00
printf(" -F <filter-out-flag> eg -F 64 to skip 64bit instructions\n");
printf(" -E Expand (duplicate) semantic functions\n");
printf(" -I <icache-size> Generate cracking cache version\n");
1997-01-28 05:34:50 +08:00
printf(" -C Include semantics in cache functions\n");
printf(" -S Include insn (instruction) in icache\n");
printf(" -R Use defines to reference cache vars\n");
1996-07-23 23:42:42 +08:00
printf(" -L Supress line numbering in output files\n");
printf(" -B <bit-size> Set the number of bits in an instruction\n");
printf(" -H <high-bit> Set the nr of the high (msb bit)\n");
printf(" -N <nr-cpus> Specify the max number of cpus the simulation will support\n");
printf(" -J Use jumps instead of function calls\n");
printf("\n");
printf("Input options (ucase version also dumps loaded table):\n");
1996-07-23 23:42:42 +08:00
printf(" -o <opcode-rules>\n");
printf(" -k <cache-rules>\n");
printf(" -i <instruction-table>\n");
printf("\n");
printf("Output options:\n");
1996-07-23 23:42:42 +08:00
printf(" -n <real-name> Specify the real name of for the next output file\n");
printf(" -h Generate header file\n");
printf(" -c <output-file> output icache\n");
printf(" -d <output-file> output idecode\n");
printf(" -m <output-file> output model\n");
printf(" -s <output-file> output schematic\n");
printf(" -t <output-file> output itable\n");
printf(" -f <output-file> output support functions\n");
1995-11-02 03:32:38 +08:00
}
while ((ch = getopt(argc, argv,
1997-01-28 05:34:50 +08:00
"F:EI:RSLJCB:H:N:o:k:i:n:hc:d:m:s:t:f:"))
1996-07-23 23:42:42 +08:00
!= -1) {
1995-11-02 03:32:38 +08:00
fprintf(stderr, "\t-%c %s\n", ch, (optarg ? optarg : ""));
switch(ch) {
1996-07-23 23:42:42 +08:00
case 'C':
code |= generate_with_icache;
code |= generate_with_semantic_icache;
1997-01-28 05:34:50 +08:00
break;
case 'S':
code |= generate_with_icache;
code |= generate_with_insn_in_icache;
1996-07-23 23:42:42 +08:00
break;
case 'L':
file_references = lf_omit_references;
break;
case 'E':
generate_expanded_instructions = 1;
1995-11-02 03:32:38 +08:00
break;
1996-07-23 23:42:42 +08:00
case 'I':
icache_size = a2i(optarg);
code |= generate_with_icache;
1995-11-02 03:32:38 +08:00
break;
1996-07-23 23:42:42 +08:00
case 'N':
generate_smp = a2i(optarg);
1995-11-02 03:32:38 +08:00
break;
case 'R':
1997-01-28 05:34:50 +08:00
code |= generate_with_direct_access;
break;
1996-07-23 23:42:42 +08:00
case 'B':
insn_bit_size = a2i(optarg);
ASSERT(insn_bit_size > 0 && insn_bit_size <= max_insn_bit_size
&& (hi_bit_nr == insn_bit_size-1 || hi_bit_nr == 0));
break;
1996-07-23 23:42:42 +08:00
case 'H':
hi_bit_nr = a2i(optarg);
1996-07-23 23:42:42 +08:00
ASSERT(hi_bit_nr == insn_bit_size-1 || hi_bit_nr == 0);
break;
case 'F':
filters = new_filter(optarg, filters);
break;
case 'J':
code &= ~generate_calls;
code |= generate_jumps;
break;
1995-11-02 03:32:38 +08:00
case 'i':
1996-07-23 23:42:42 +08:00
if (decode_rules == NULL || cache_rules == NULL) {
fprintf(stderr, "Must specify decode and cache tables\n");
exit (1);
}
instructions = load_insn_table(optarg, decode_rules, filters);
1995-11-02 03:32:38 +08:00
fprintf(stderr, "\texpanding ...\n");
insn_table_expand_insns(instructions);
break;
case 'o':
1996-07-23 23:42:42 +08:00
decode_rules = load_decode_table(optarg, hi_bit_nr);
1995-11-02 03:32:38 +08:00
break;
case 'k':
1996-07-23 23:42:42 +08:00
cache_rules = load_cache_table(optarg, hi_bit_nr);
1995-11-02 03:32:38 +08:00
break;
case 'n':
real_file_name = strdup(optarg);
break;
1996-07-23 23:42:42 +08:00
case 'h':
is_header = 1;
break;
1995-11-02 03:32:38 +08:00
case 's':
case 'd':
case 'm':
1995-11-02 03:32:38 +08:00
case 't':
1996-07-23 23:42:42 +08:00
case 'f':
case 'c':
1995-11-02 03:32:38 +08:00
{
1996-07-23 23:42:42 +08:00
lf *file = lf_open(optarg, real_file_name, file_references,
(is_header ? lf_is_h : lf_is_c),
argv[0]);
lf_print__file_start(file);
1995-11-02 03:32:38 +08:00
ASSERT(instructions != NULL);
switch (ch) {
case 's':
1996-07-23 23:42:42 +08:00
if(is_header)
gen_semantics_h(instructions, file, code);
else
gen_semantics_c(instructions, cache_rules, file, code);
1995-11-02 03:32:38 +08:00
break;
case 'd':
1996-07-23 23:42:42 +08:00
if (is_header)
gen_idecode_h(file, instructions, cache_rules);
else
gen_idecode_c(file, instructions, cache_rules);
break;
case 'm':
1996-07-23 23:42:42 +08:00
if (is_header)
gen_model_h(instructions, file);
else
gen_model_c(instructions, file);
1995-11-02 03:32:38 +08:00
break;
case 't':
1996-07-23 23:42:42 +08:00
if (is_header)
gen_itable_h(instructions, file);
else
gen_itable_c(instructions, file);
break;
case 'f':
if (is_header)
gen_support_h(instructions, file);
else
gen_support_c(instructions, file);
1995-11-02 03:32:38 +08:00
break;
1996-07-23 23:42:42 +08:00
case 'c':
if (is_header)
gen_icache_h(instructions, file, code);
else
gen_icache_c(instructions, cache_rules, file, code);
1995-11-02 03:32:38 +08:00
break;
}
1996-07-23 23:42:42 +08:00
lf_print__file_finish(file);
1995-11-02 03:32:38 +08:00
lf_close(file);
1996-07-23 23:42:42 +08:00
is_header = 0;
1995-11-02 03:32:38 +08:00
}
real_file_name = NULL;
break;
default:
error("unknown option\n");
}
}
return 0;
}