Add multi-sim support to simulator.
This commit is contained in:
parent
70c8abdb4c
commit
687f3f1cef
@ -1,3 +1,81 @@
|
||||
Tue Sep 9 03:30:26 1997 Andrew Cagney <cagney@b1.cygnus.com>
|
||||
|
||||
* igen.c (gen_run_c): New function. Generate sim_engine_run that
|
||||
looks at the currently selected architecture.
|
||||
|
||||
* gen-engine.c, gen-idecode.c: Add multi-sim support - generate
|
||||
one engine per model.
|
||||
|
||||
* gen-semantics.c, gen-icache.c gen-support.c:
|
||||
Update.
|
||||
|
||||
* ld-insn.h, ld-insn-h (load_insn_table): Rewrite. table.h only
|
||||
returns a line at a time. Parse multi-word instructions. Add
|
||||
multi-sim support.
|
||||
|
||||
* table.h, table.c: Simplify. Only parse a single line at a time.
|
||||
ld-insn can handle the rest.
|
||||
|
||||
* filter.h, filter.c (filter_parse, filter_add, filter_is_subset,
|
||||
filter_is_common, filter_is_member, filter_next): New filter
|
||||
operations.
|
||||
(dump_filter): Ditto.
|
||||
|
||||
* gen.h, gen.c: New file. Takes the insn table and turns it into
|
||||
a set of decode tables and semantic functions.
|
||||
|
||||
* ld-insn.c: Copy generator code from here.
|
||||
* gen.c: To here.
|
||||
|
||||
Fri Aug 8 11:43:45 1997 Andrew Cagney <cagney@b1.cygnus.com>
|
||||
|
||||
* misc.h (NZALLOC): Allocate an N element array of TYPE.
|
||||
|
||||
* table.h, table.c: Simplify table parser so that it only
|
||||
understands colon delimited lines and code blocks.
|
||||
(table_read): Parse '{' ... '}' as a code block.
|
||||
(table_print_code): New function, print out a code block to file.
|
||||
(main): Add suport for standalone testing.
|
||||
|
||||
* ld-insn.h, ld-insn.c:
|
||||
|
||||
|
||||
Mon Sep 1 11:41:12 1997 Andrew Cagney <cagney@b1.cygnus.com>
|
||||
|
||||
* gen-idecode.c (error_leaf_contains_multiple_insn): Make static.
|
||||
(print_jump_definition, print_jump, print_jump_internal_function,
|
||||
print_jump_insn, print_jump_until_stop_body): Delete, moved to
|
||||
sim-engine.c
|
||||
|
||||
* igen.c (print_itrace_format): Delete unused variable chp.
|
||||
(gen-engine.h): Include.
|
||||
|
||||
* table.c (current_file_name, current_line_entry,
|
||||
current_line_entry): Make static.
|
||||
|
||||
Wed Aug 6 12:31:17 1997 Andrew Cagney <cagney@b1.cygnus.com>
|
||||
|
||||
* configure.in: Define AR_FOR_BUILD, AR_FLAGS_FOR_BUILD,
|
||||
RANLIB_FOR_BUILD and CFLAGS_FOR_BUILD.
|
||||
* configure.in: Include simulator common/aclocal.m4.
|
||||
* configure.in: Add --enable-sim-warnings option.
|
||||
* configure: Re-generate.
|
||||
|
||||
* Makefile.in: Use.
|
||||
|
||||
* Makefile.in (tmp-filter): New rule.
|
||||
(igen.o, tmp-table, tmp-ld-decode, tmp-ld-cache, tmp-ld-insn,
|
||||
ld-decode.o, ld-cache.o, ld-insn.o): Fix dependencies.
|
||||
|
||||
* gen.h, gen.c: New files.
|
||||
|
||||
* Makefile.in (gen.o, tmp-gen): New rules, update all
|
||||
dependencies.
|
||||
|
||||
Tue Jun 24 11:46:45 1997 Andrew Cagney <cagney@b1.cygnus.com>
|
||||
|
||||
* ld-insn.c (load_insn_table): Accept %s as a function type.
|
||||
|
||||
Thu Jun 5 17:14:32 1997 Andrew Cagney <cagney@b1.cygnus.com>
|
||||
|
||||
* igen.c (print_itrace_prefix): Move printing of insn prefix to
|
||||
|
246
sim/igen/gen-itable.c
Normal file
246
sim/igen/gen-itable.c
Normal file
@ -0,0 +1,246 @@
|
||||
/* 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.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "misc.h"
|
||||
#include "lf.h"
|
||||
#include "table.h"
|
||||
#include "filter.h"
|
||||
#include "igen.h"
|
||||
|
||||
#include "ld-insn.h"
|
||||
#include "ld-decode.h"
|
||||
|
||||
#include "gen.h"
|
||||
|
||||
#include "gen-itable.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static void
|
||||
itable_h_insn (lf *file,
|
||||
insn_table *entry,
|
||||
insn_entry *instruction,
|
||||
void *data)
|
||||
{
|
||||
lf_print__line_ref (file, instruction->line);
|
||||
lf_printf (file, " ");
|
||||
print_function_name (file,
|
||||
instruction->name,
|
||||
instruction->format_name,
|
||||
NULL,
|
||||
NULL,
|
||||
function_name_prefix_itable);
|
||||
lf_printf (file, ",\n");
|
||||
}
|
||||
|
||||
|
||||
/* print the list of all the different options */
|
||||
|
||||
static void
|
||||
itable_print_enum (lf *file,
|
||||
filter *set,
|
||||
char *name)
|
||||
{
|
||||
char *elem;
|
||||
lf_printf (file, "typedef enum {\n");
|
||||
lf_indent (file, +2);
|
||||
for (elem = filter_next (set, "");
|
||||
elem != NULL;
|
||||
elem = filter_next (set, elem))
|
||||
{
|
||||
lf_printf (file, "%sitable_%s_%s,\n",
|
||||
options.prefix.itable.name, name, elem);
|
||||
if (strlen (options.prefix.itable.name) > 0)
|
||||
{
|
||||
lf_indent_suppress (file);
|
||||
lf_printf (file, "#define itable_%s_%s %sitable_%s_%s\n",
|
||||
name, elem, options.prefix.itable.name, name, elem);
|
||||
}
|
||||
}
|
||||
lf_printf (file, "nr_%sitable_%ss,", options.prefix.itable.name, name);
|
||||
|
||||
lf_indent (file, -2);
|
||||
lf_printf (file, "\n} %sitable_%ss;\n", options.prefix.itable.name, name);
|
||||
if (strlen (options.prefix.itable.name) > 0)
|
||||
{
|
||||
lf_indent_suppress (file);
|
||||
lf_printf (file, "#define itable_%ss %sitable_%ss\n",
|
||||
name, options.prefix.itable.name, name);
|
||||
lf_indent_suppress (file);
|
||||
lf_printf (file, "#define nr_itable_%ss nr_%sitable_%ss\n",
|
||||
name, options.prefix.itable.name, name);
|
||||
}
|
||||
lf_printf (file, "\n");
|
||||
}
|
||||
|
||||
extern void
|
||||
gen_itable_h (lf *file,
|
||||
insn_table *isa)
|
||||
{
|
||||
|
||||
/* output an enumerated type for each instruction */
|
||||
lf_printf (file, "typedef enum {\n");
|
||||
insn_table_traverse_insn (file, isa, itable_h_insn, NULL);
|
||||
lf_printf (file, " nr_%sitable_entries,\n", options.prefix.itable.name);
|
||||
lf_printf (file, "} %sitable_index;\n", options.prefix.itable.name);
|
||||
lf_printf (file, "\n");
|
||||
|
||||
/* output an enumeration type for each flag */
|
||||
itable_print_enum (file, isa->flags, "flag");
|
||||
|
||||
/* output an enumeration of all the possible options */
|
||||
itable_print_enum (file, isa->options, "option");
|
||||
|
||||
/* output an enumeration of all the processor models */
|
||||
itable_print_enum (file, isa->model->processors, "processor");
|
||||
|
||||
/* output the table that contains the actual instruction info */
|
||||
lf_printf (file, "typedef struct _%sitable_instruction_info {\n",
|
||||
options.prefix.itable.name);
|
||||
lf_printf (file, " %sitable_index nr;\n", options.prefix.itable.name);
|
||||
lf_printf (file, " char *format;\n");
|
||||
lf_printf (file, " char *form;\n");
|
||||
lf_printf (file, " char *flags;\n");
|
||||
lf_printf (file, " char flag[nr_%sitable_flags];\n",
|
||||
options.prefix.itable.name);
|
||||
lf_printf (file, " char *options;\n");
|
||||
lf_printf (file, " char option[nr_%sitable_options];\n",
|
||||
options.prefix.itable.name);
|
||||
lf_printf (file, " char *processors;\n");
|
||||
lf_printf (file, " char processor[nr_%sitable_processors];\n",
|
||||
options.prefix.itable.name);
|
||||
lf_printf (file, " char *name;\n");
|
||||
lf_printf (file, " char *file;\n");
|
||||
lf_printf (file, " int line_nr;\n");
|
||||
lf_printf (file, "} %sitable_info;\n", options.prefix.itable.name);
|
||||
lf_printf (file, "\n");
|
||||
lf_printf (file, "extern %sitable_info %sitable[nr_%sitable_entries];\n",
|
||||
options.prefix.itable.name, options.prefix.itable.name,
|
||||
options.prefix.itable.name);
|
||||
if (strlen (options.prefix.itable.name) > 0)
|
||||
{
|
||||
lf_indent_suppress (file);
|
||||
lf_printf (file, "#define itable %sitable\n",
|
||||
options.prefix.itable.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
static void
|
||||
itable_print_set (lf *file,
|
||||
filter *set,
|
||||
filter *members)
|
||||
{
|
||||
char *elem;
|
||||
lf_printf (file, "\"");
|
||||
elem = filter_next (members, "");
|
||||
if (elem != NULL)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
lf_printf (file, "%s", elem);
|
||||
elem = filter_next (members, elem);
|
||||
if (elem == NULL)
|
||||
break;
|
||||
lf_printf (file, ",");
|
||||
}
|
||||
}
|
||||
lf_printf (file, "\",\n");
|
||||
|
||||
lf_printf(file, "{");
|
||||
for (elem = filter_next (set, "");
|
||||
elem != NULL;
|
||||
elem = filter_next (set, elem))
|
||||
{
|
||||
if (filter_is_member (members, elem))
|
||||
{
|
||||
lf_printf (file, " 1,");
|
||||
}
|
||||
else
|
||||
{
|
||||
lf_printf (file, " 0,");
|
||||
}
|
||||
|
||||
}
|
||||
lf_printf(file, " },\n");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
itable_c_insn (lf *file,
|
||||
insn_table *isa,
|
||||
insn_entry *instruction,
|
||||
void *data)
|
||||
{
|
||||
lf_printf (file, "{ ");
|
||||
lf_indent (file, +2);
|
||||
print_function_name (file,
|
||||
instruction->name,
|
||||
instruction->format_name,
|
||||
NULL,
|
||||
NULL,
|
||||
function_name_prefix_itable);
|
||||
lf_printf (file, ",\n");
|
||||
lf_printf (file, "\"");
|
||||
print_insn_words (file, instruction);
|
||||
lf_printf (file, "\",\n");
|
||||
lf_printf (file, "\"%s\",\n", instruction->format_name);
|
||||
|
||||
itable_print_set (file, isa->flags, instruction->flags);
|
||||
itable_print_set (file, isa->options, instruction->options);
|
||||
itable_print_set (file, isa->model->processors, instruction->processors);
|
||||
|
||||
lf_printf(file, "\"%s\",\n", instruction->name);
|
||||
lf_printf(file, "\"%s\",\n",
|
||||
filter_filename (instruction->line->file_name));
|
||||
lf_printf(file, "%d,\n", instruction->line->line_nr);
|
||||
lf_printf(file, "},\n");
|
||||
lf_indent (file, -2);
|
||||
}
|
||||
|
||||
|
||||
extern void
|
||||
gen_itable_c (lf *file,
|
||||
insn_table *isa)
|
||||
{
|
||||
/* leader */
|
||||
lf_printf(file, "#include \"%sitable.h\"\n", options.prefix.itable.name);
|
||||
lf_printf(file, "\n");
|
||||
|
||||
/* FIXME - output model data??? */
|
||||
/* FIXME - output assembler data??? */
|
||||
|
||||
/* output the table that contains the actual instruction info */
|
||||
lf_printf(file, "%sitable_info %sitable[nr_%sitable_entries] = {\n",
|
||||
options.prefix.itable.name,
|
||||
options.prefix.itable.name,
|
||||
options.prefix.itable.name);
|
||||
insn_table_traverse_insn (file, isa, itable_c_insn, NULL);
|
||||
|
||||
lf_printf(file, "};\n");
|
||||
}
|
@ -24,66 +24,75 @@
|
||||
#include "lf.h"
|
||||
#include "table.h"
|
||||
#include "filter.h"
|
||||
|
||||
#include "ld-decode.h"
|
||||
#include "ld-cache.h"
|
||||
#include "ld-insn.h"
|
||||
|
||||
#include "igen.h"
|
||||
|
||||
#include "ld-insn.h"
|
||||
#include "ld-decode.h"
|
||||
|
||||
#include "gen.h"
|
||||
|
||||
#include "gen-semantics.h"
|
||||
#include "gen-icache.h"
|
||||
#include "gen-idecode.h"
|
||||
|
||||
|
||||
static void
|
||||
print_semantic_function_header(lf *file,
|
||||
const char *basename,
|
||||
insn_bits *expanded_bits,
|
||||
int is_function_definition)
|
||||
print_semantic_function_header (lf *file,
|
||||
const char *basename,
|
||||
const char *format_name,
|
||||
opcode_bits *expanded_bits,
|
||||
int is_function_definition,
|
||||
int nr_prefetched_words)
|
||||
{
|
||||
int indent;
|
||||
lf_printf(file, "\n");
|
||||
lf_print_function_type_function(file, print_semantic_function_type, "EXTERN_SEMANTICS",
|
||||
(is_function_definition ? "\n" : " "));
|
||||
indent = print_function_name(file,
|
||||
basename,
|
||||
expanded_bits,
|
||||
function_name_prefix_semantics);
|
||||
lf_print__function_type_function (file, print_semantic_function_type,
|
||||
"EXTERN_SEMANTICS",
|
||||
(is_function_definition ? "\n" : " "));
|
||||
indent = print_function_name (file,
|
||||
basename,
|
||||
format_name,
|
||||
NULL,
|
||||
expanded_bits,
|
||||
function_name_prefix_semantics);
|
||||
if (is_function_definition)
|
||||
lf_indent(file, +indent);
|
||||
{
|
||||
indent += lf_printf (file, " ");
|
||||
lf_indent (file, +indent);
|
||||
}
|
||||
else
|
||||
lf_printf(file, "\n");
|
||||
lf_printf(file, "(");
|
||||
print_semantic_function_formal(file);
|
||||
lf_printf(file, ")");
|
||||
{
|
||||
lf_printf (file, "\n");
|
||||
}
|
||||
lf_printf (file, "(");
|
||||
lf_indent (file, +1);
|
||||
print_semantic_function_formal (file, nr_prefetched_words);
|
||||
lf_indent (file, -1);
|
||||
lf_printf (file, ")");
|
||||
if (is_function_definition)
|
||||
lf_indent(file, -indent);
|
||||
{
|
||||
lf_indent (file, -indent);
|
||||
}
|
||||
else
|
||||
lf_printf(file, ";");
|
||||
lf_printf(file, "\n");
|
||||
{
|
||||
lf_printf (file, ";");
|
||||
}
|
||||
lf_printf (file, "\n");
|
||||
}
|
||||
|
||||
void
|
||||
print_semantic_declaration(insn_table *entry,
|
||||
lf *file,
|
||||
void *data,
|
||||
insn *instruction,
|
||||
int depth)
|
||||
print_semantic_declaration (lf *file,
|
||||
insn_entry *insn,
|
||||
opcode_bits *expanded_bits,
|
||||
insn_opcodes *opcodes,
|
||||
int nr_prefetched_words)
|
||||
{
|
||||
if (generate_expanded_instructions) {
|
||||
ASSERT(entry->nr_insn == 1);
|
||||
print_semantic_function_header(file,
|
||||
instruction->file_entry->fields[insn_name],
|
||||
entry->expanded_bits,
|
||||
0/* is not function definition*/);
|
||||
}
|
||||
else {
|
||||
print_semantic_function_header(file,
|
||||
instruction->file_entry->fields[insn_name],
|
||||
NULL,
|
||||
0/* is not function definition*/);
|
||||
}
|
||||
print_semantic_function_header (file,
|
||||
insn->name,
|
||||
insn->format_name,
|
||||
expanded_bits,
|
||||
0/* is not function definition*/,
|
||||
nr_prefetched_words);
|
||||
}
|
||||
|
||||
|
||||
@ -92,226 +101,277 @@ print_semantic_declaration(insn_table *entry,
|
||||
|
||||
|
||||
void
|
||||
print_idecode_invalid(lf *file,
|
||||
const char *result,
|
||||
invalid_type type)
|
||||
print_idecode_invalid (lf *file,
|
||||
const char *result,
|
||||
invalid_type type)
|
||||
{
|
||||
const char *name;
|
||||
switch (type) {
|
||||
default: name = "unknown"; break;
|
||||
case invalid_illegal: name = "illegal"; break;
|
||||
case invalid_fp_unavailable: name = "fp_unavailable"; break;
|
||||
case invalid_wrong_slot: name = "wrong_slot"; break;
|
||||
}
|
||||
if ((code & generate_jumps))
|
||||
lf_printf(file, "goto %s_%s;\n",
|
||||
(code & generate_with_icache) ? "icache" : "semantic",
|
||||
name);
|
||||
else if ((code & generate_with_icache)) {
|
||||
lf_printf(file, "%s %sicache_%s(", result, global_name_prefix, name);
|
||||
print_icache_function_actual(file);
|
||||
lf_printf(file, ");\n");
|
||||
}
|
||||
else {
|
||||
lf_printf(file, "%s %ssemantic_%s(", result, global_name_prefix, name);
|
||||
print_semantic_function_actual(file);
|
||||
lf_printf(file, ");\n");
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
default: name = "unknown"; break;
|
||||
case invalid_illegal: name = "illegal"; break;
|
||||
case invalid_fp_unavailable: name = "fp_unavailable"; break;
|
||||
case invalid_wrong_slot: name = "wrong_slot"; break;
|
||||
}
|
||||
if (options.gen.code == generate_jumps)
|
||||
{
|
||||
lf_printf (file, "goto %s_%s;\n",
|
||||
(options.gen.icache ? "icache" : "semantic"),
|
||||
name);
|
||||
}
|
||||
else if (options.gen.icache)
|
||||
{
|
||||
lf_printf (file, "%s %sicache_%s (", result, options.prefix.global.name, name);
|
||||
print_icache_function_actual (file, 0);
|
||||
lf_printf (file, ");\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
lf_printf (file, "%s %ssemantic_%s (", result, options.prefix.global.name, name);
|
||||
print_semantic_function_actual (file, 0);
|
||||
lf_printf (file, ");\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
print_semantic_body(lf *file,
|
||||
insn *instruction,
|
||||
insn_bits *expanded_bits,
|
||||
opcode_field *opcodes)
|
||||
print_semantic_body (lf *file,
|
||||
insn_entry *instruction,
|
||||
opcode_bits *expanded_bits,
|
||||
insn_opcodes *opcodes)
|
||||
{
|
||||
print_itrace(file, instruction->file_entry, 0/*put_value_in_cache*/);
|
||||
|
||||
print_itrace (file, instruction, 0/*put_value_in_cache*/);
|
||||
|
||||
/* validate the instruction, if a cache this has already been done */
|
||||
if (!(code & generate_with_icache))
|
||||
print_idecode_validate(file, instruction, opcodes);
|
||||
|
||||
if (!options.gen.icache)
|
||||
{
|
||||
print_idecode_validate (file, instruction, opcodes);
|
||||
}
|
||||
|
||||
/* generate the profiling call - this is delayed until after the
|
||||
instruction has been verified */
|
||||
lf_printf(file, "\n");
|
||||
lf_indent_suppress(file);
|
||||
lf_printf(file, "#if defined(WITH_MON)\n");
|
||||
lf_printf(file, "/* monitoring: */\n");
|
||||
lf_printf(file, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE) {\n");
|
||||
lf_printf(file, " mon_issue(");
|
||||
print_function_name(file,
|
||||
instruction->file_entry->fields[insn_name],
|
||||
NULL,
|
||||
function_name_prefix_itable);
|
||||
lf_printf(file, ", cpu, cia);\n");
|
||||
lf_printf(file, "}\n");
|
||||
lf_indent_suppress(file);
|
||||
lf_printf(file, "#endif\n");
|
||||
lf_printf(file, "\n");
|
||||
|
||||
/* determine the new instruction address */
|
||||
lf_printf(file, "/* keep the next instruction address handy */\n");
|
||||
if ((code & generate_with_semantic_returning_modified_nia_only))
|
||||
lf_printf(file, "nia = -1;\n");
|
||||
else if ((code & generate_with_semantic_delayed_branch)) {
|
||||
lf_printf(file, "nia.ip = cia.dp; /* instruction pointer */\n");
|
||||
lf_printf(file, "nia.dp = cia.dp + %d; /* delayed-slot pointer */\n",
|
||||
insn_bit_size / 8);
|
||||
}
|
||||
else
|
||||
lf_printf(file, "nia = cia + %d;\n", insn_bit_size / 8);
|
||||
|
||||
/* if conditional, generate code to verify that the instruction
|
||||
should be issued */
|
||||
if (it_is("c", instruction->file_entry->fields[insn_options])
|
||||
|| (code & generate_with_semantic_conditional_issue)) {
|
||||
lf_printf(file, "\n");
|
||||
lf_printf(file, "/* execute only if conditional passes */\n");
|
||||
lf_printf(file, "if (IS_CONDITION_OK) {\n");
|
||||
lf_indent(file, +2);
|
||||
/* FIXME - need to log a conditional failure */
|
||||
{
|
||||
lf_printf (file, "\n");
|
||||
lf_indent_suppress (file);
|
||||
lf_printf (file, "#if defined (WITH_MON)\n");
|
||||
lf_printf (file, "/* monitoring: */\n");
|
||||
lf_printf (file, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE)\n");
|
||||
lf_printf (file, " mon_issue (");
|
||||
print_function_name (file,
|
||||
instruction->name,
|
||||
instruction->format_name,
|
||||
NULL,
|
||||
NULL,
|
||||
function_name_prefix_itable);
|
||||
lf_printf (file, ", cpu, cia);\n");
|
||||
lf_indent_suppress (file);
|
||||
lf_printf (file, "#endif\n");
|
||||
lf_printf (file, "\n");
|
||||
}
|
||||
|
||||
/* Architecture expects r0 to be zero. Instead of having to check
|
||||
every read to see if it is refering to r0 just zap the r0
|
||||
register */
|
||||
if ((code & generate_with_semantic_zero_r0))
|
||||
/* determine the new instruction address */
|
||||
{
|
||||
lf_printf(file, "/* keep the next instruction address handy */\n");
|
||||
if (options.gen.nia == nia_is_invalid)
|
||||
{
|
||||
lf_printf(file, "nia = %sINVALID_INSTRUCTION_ADDRESS;\n",
|
||||
options.prefix.global.uname);
|
||||
}
|
||||
else
|
||||
{
|
||||
int nr_immeds = instruction->nr_words - 1;
|
||||
if (options.gen.delayed_branch)
|
||||
{
|
||||
if (nr_immeds > 0)
|
||||
{
|
||||
lf_printf (file, "cia.dp += %d * %d; %s\n",
|
||||
options.insn_bit_size / 8, nr_immeds,
|
||||
"/* skip dp immeds */");
|
||||
}
|
||||
lf_printf (file, "nia.ip = cia.dp; %s\n",
|
||||
"/* instruction pointer */");
|
||||
lf_printf (file, "nia.dp = cia.dp + %d; %s\n",
|
||||
options.insn_bit_size / 8,
|
||||
"/* delayed-slot pointer */");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nr_immeds > 0)
|
||||
{
|
||||
lf_printf (file, "nia = cia + %d * (%d + 1); %s\n",
|
||||
options.insn_bit_size / 8, nr_immeds,
|
||||
"/* skip immeds as well */");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
lf_printf (file, "nia = cia + %d;\n",
|
||||
options.insn_bit_size / 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if conditional, generate code to verify that the instruction
|
||||
should be issued */
|
||||
if (filter_is_member (instruction->options, "c")
|
||||
|| options.gen.conditional_issue)
|
||||
{
|
||||
lf_printf (file, "\n");
|
||||
lf_printf (file, "GPR(0) = 0;\n");
|
||||
lf_printf (file, "/* execute only if conditional passes */\n");
|
||||
lf_printf (file, "if (IS_CONDITION_OK)\n");
|
||||
lf_printf (file, " {\n");
|
||||
lf_indent (file, +4);
|
||||
/* FIXME - need to log a conditional failure */
|
||||
}
|
||||
|
||||
|
||||
/* Architecture expects a REG to be zero. Instead of having to
|
||||
check every read to see if it is refering to that REG just zap it
|
||||
at the start of every instruction */
|
||||
if (options.gen.zero_reg)
|
||||
{
|
||||
lf_printf (file, "\n");
|
||||
lf_printf (file, "GPR(%d) = 0;\n", options.gen.zero_reg_nr);
|
||||
}
|
||||
|
||||
/* generate the code (or at least something */
|
||||
lf_printf(file, "\n");
|
||||
lf_printf(file, "/* semantics: */\n");
|
||||
if (instruction->file_entry->annex != NULL) {
|
||||
/* true code */
|
||||
table_entry_print_cpp_line_nr(file, instruction->file_entry);
|
||||
lf_printf(file, "{\n");
|
||||
lf_indent(file, +2);
|
||||
lf_print__c_code(file, instruction->file_entry->annex);
|
||||
lf_indent(file, -2);
|
||||
lf_printf(file, "}\n");
|
||||
lf_print__internal_reference(file);
|
||||
}
|
||||
else if (it_is("nop", instruction->file_entry->fields[insn_flags])) {
|
||||
lf_print__internal_reference(file);
|
||||
}
|
||||
else {
|
||||
/* abort so it is implemented now */
|
||||
table_entry_print_cpp_line_nr(file, instruction->file_entry);
|
||||
lf_printf(file, "sim_engine_abort (SD, CPU, cia, \"%s:%d:0x%%08lx:%%s unimplemented\\n\",\n",
|
||||
filter_filename(instruction->file_entry->file_name),
|
||||
instruction->file_entry->line_nr);
|
||||
if ((code & generate_with_semantic_delayed_branch))
|
||||
lf_printf(file, " (long)cia.ip,\n");
|
||||
else
|
||||
lf_printf(file, " (long)cia,\n");
|
||||
lf_printf(file, " itable[MY_INDEX].name);\n");
|
||||
lf_print__internal_reference(file);
|
||||
}
|
||||
|
||||
lf_printf (file, "\n");
|
||||
lf_printf (file, "/* semantics: */\n");
|
||||
if (instruction->code != NULL)
|
||||
{
|
||||
/* true code */
|
||||
lf_printf (file, "{\n");
|
||||
lf_indent (file, +2);
|
||||
lf_print__line_ref (file, instruction->code->line);
|
||||
table_print_code (file, instruction->code);
|
||||
lf_indent (file, -2);
|
||||
lf_printf (file, "}\n");
|
||||
lf_print__internal_ref (file);
|
||||
}
|
||||
else if (filter_is_member (instruction->options, "nop"))
|
||||
{
|
||||
lf_print__internal_ref (file);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* abort so it is implemented now */
|
||||
lf_print__line_ref (file, instruction->line);
|
||||
lf_printf (file, "sim_engine_abort (SD, CPU, cia, \"%s:%d:0x%%08lx:%%s unimplemented\\n\",\n",
|
||||
filter_filename (instruction->line->file_name),
|
||||
instruction->line->line_nr);
|
||||
if (options.gen.delayed_branch)
|
||||
{
|
||||
lf_printf (file, " (long)cia.ip,\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
lf_printf (file, " (long)cia,\n");
|
||||
}
|
||||
lf_printf (file, " %sitable[MY_INDEX].name);\n",
|
||||
options.prefix.itable.name);
|
||||
lf_print__internal_ref (file);
|
||||
}
|
||||
|
||||
/* Close off the conditional execution */
|
||||
if (it_is("c", instruction->file_entry->fields[insn_options])
|
||||
|| (code & generate_with_semantic_conditional_issue)) {
|
||||
lf_indent(file, -2);
|
||||
lf_printf(file, "}\n");
|
||||
}
|
||||
if (filter_is_member (instruction->options, "c")
|
||||
|| options.gen.conditional_issue)
|
||||
{
|
||||
lf_indent (file, -4);
|
||||
lf_printf (file, " }\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_c_semantic(lf *file,
|
||||
insn *instruction,
|
||||
insn_bits *expanded_bits,
|
||||
opcode_field *opcodes,
|
||||
cache_table *cache_rules)
|
||||
print_c_semantic (lf *file,
|
||||
insn_entry *instruction,
|
||||
opcode_bits *expanded_bits,
|
||||
insn_opcodes *opcodes,
|
||||
cache_entry *cache_rules,
|
||||
int nr_prefetched_words)
|
||||
{
|
||||
|
||||
lf_printf(file, "{\n");
|
||||
lf_indent(file, +2);
|
||||
|
||||
print_my_defines(file, expanded_bits, instruction->file_entry);
|
||||
lf_printf(file, "\n");
|
||||
print_icache_body(file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
cache_rules,
|
||||
((code & generate_with_direct_access)
|
||||
? define_variables
|
||||
: declare_variables),
|
||||
((code & generate_with_icache)
|
||||
? get_values_from_icache
|
||||
: do_not_use_icache));
|
||||
|
||||
lf_printf(file, "%sinstruction_address nia;\n", global_name_prefix);
|
||||
print_semantic_body(file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
opcodes);
|
||||
lf_printf(file, "return nia;\n");
|
||||
|
||||
|
||||
lf_printf (file, "{\n");
|
||||
lf_indent (file, +2);
|
||||
|
||||
print_my_defines (file,
|
||||
instruction->name,
|
||||
instruction->format_name,
|
||||
expanded_bits);
|
||||
lf_printf (file, "\n");
|
||||
print_icache_body (file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
cache_rules,
|
||||
(options.gen.direct_access
|
||||
? define_variables
|
||||
: declare_variables),
|
||||
(options.gen.icache
|
||||
? get_values_from_icache
|
||||
: do_not_use_icache),
|
||||
nr_prefetched_words);
|
||||
|
||||
lf_printf (file, "%sinstruction_address nia;\n", options.prefix.global.name);
|
||||
print_semantic_body (file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
opcodes);
|
||||
lf_printf (file, "return nia;\n");
|
||||
|
||||
/* generate something to clean up any #defines created for the cache */
|
||||
if (code & generate_with_direct_access)
|
||||
print_icache_body(file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
cache_rules,
|
||||
undef_variables,
|
||||
((code & generate_with_icache)
|
||||
? get_values_from_icache
|
||||
: do_not_use_icache));
|
||||
|
||||
lf_indent(file, -2);
|
||||
lf_printf(file, "}\n");
|
||||
if (options.gen.direct_access)
|
||||
{
|
||||
print_icache_body (file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
cache_rules,
|
||||
undef_variables,
|
||||
(options.gen.icache
|
||||
? get_values_from_icache
|
||||
: do_not_use_icache),
|
||||
nr_prefetched_words);
|
||||
}
|
||||
|
||||
lf_indent (file, -2);
|
||||
lf_printf (file, "}\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_c_semantic_function(lf *file,
|
||||
insn *instruction,
|
||||
insn_bits *expanded_bits,
|
||||
opcode_field *opcodes,
|
||||
cache_table *cache_rules)
|
||||
print_c_semantic_function (lf *file,
|
||||
insn_entry *instruction,
|
||||
opcode_bits *expanded_bits,
|
||||
insn_opcodes *opcodes,
|
||||
cache_entry *cache_rules,
|
||||
int nr_prefetched_words)
|
||||
{
|
||||
/* build the semantic routine to execute the instruction */
|
||||
print_semantic_function_header(file,
|
||||
instruction->file_entry->fields[insn_name],
|
||||
expanded_bits,
|
||||
1/*is-function-definition*/);
|
||||
print_c_semantic(file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
opcodes,
|
||||
cache_rules);
|
||||
print_semantic_function_header (file,
|
||||
instruction->name,
|
||||
instruction->format_name,
|
||||
expanded_bits,
|
||||
1/*is-function-definition*/,
|
||||
nr_prefetched_words);
|
||||
print_c_semantic (file,
|
||||
instruction,
|
||||
expanded_bits,
|
||||
opcodes,
|
||||
cache_rules,
|
||||
nr_prefetched_words);
|
||||
}
|
||||
|
||||
void
|
||||
print_semantic_definition(insn_table *entry,
|
||||
lf *file,
|
||||
void *data,
|
||||
insn *instruction,
|
||||
int depth)
|
||||
print_semantic_definition (lf *file,
|
||||
insn_entry *insn,
|
||||
opcode_bits *expanded_bits,
|
||||
insn_opcodes *opcodes,
|
||||
cache_entry *cache_rules,
|
||||
int nr_prefetched_words)
|
||||
{
|
||||
cache_table *cache_rules = (cache_table*)data;
|
||||
if (generate_expanded_instructions) {
|
||||
ASSERT(entry->nr_insn == 1
|
||||
&& entry->opcode == NULL
|
||||
&& entry->parent != NULL
|
||||
&& entry->parent->opcode != NULL);
|
||||
ASSERT(entry->nr_insn == 1
|
||||
&& entry->opcode == NULL
|
||||
&& entry->parent != NULL
|
||||
&& entry->parent->opcode != NULL
|
||||
&& entry->parent->opcode_rule != NULL);
|
||||
print_c_semantic_function(file,
|
||||
entry->insns,
|
||||
entry->expanded_bits,
|
||||
entry->parent->opcode,
|
||||
cache_rules);
|
||||
}
|
||||
else {
|
||||
print_c_semantic_function(file, instruction,
|
||||
NULL, NULL,
|
||||
cache_rules);
|
||||
}
|
||||
print_c_semantic_function (file,
|
||||
insn,
|
||||
expanded_bits,
|
||||
opcodes,
|
||||
cache_rules,
|
||||
nr_prefetched_words);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,146 +23,160 @@
|
||||
#include "table.h"
|
||||
#include "filter.h"
|
||||
|
||||
#include "ld-decode.h"
|
||||
#include "ld-cache.h"
|
||||
#include "ld-insn.h"
|
||||
|
||||
#include "igen.h"
|
||||
|
||||
#include "ld-insn.h"
|
||||
#include "ld-decode.h"
|
||||
|
||||
#include "gen.h"
|
||||
|
||||
#include "gen-semantics.h"
|
||||
#include "gen-support.h"
|
||||
|
||||
static void
|
||||
print_support_function_name(lf *file,
|
||||
table_entry *function,
|
||||
int is_function_definition)
|
||||
print_support_function_name (lf *file,
|
||||
function_entry *function,
|
||||
int is_function_definition)
|
||||
{
|
||||
if (it_is("internal", function->fields[insn_flags])) {
|
||||
lf_print_function_type_function(file, print_semantic_function_type, "INLINE_SUPPORT",
|
||||
(is_function_definition ? "\n" : " "));
|
||||
print_function_name(file,
|
||||
function->fields[function_name],
|
||||
NULL,
|
||||
function_name_prefix_semantics);
|
||||
lf_printf(file, "\n(");
|
||||
print_semantic_function_formal(file);
|
||||
lf_printf(file, ")");
|
||||
if (!is_function_definition)
|
||||
lf_printf(file, ";");
|
||||
lf_printf(file, "\n");
|
||||
}
|
||||
else {
|
||||
/* map the name onto a globally valid name */
|
||||
if (!is_function_definition && strcmp(global_name_prefix, "") != 0) {
|
||||
lf_indent_suppress(file);
|
||||
lf_printf(file, "#define %s %s%s\n",
|
||||
function->fields[function_name],
|
||||
global_name_prefix,
|
||||
function->fields[function_name]);
|
||||
if (function->is_internal)
|
||||
{
|
||||
lf_print__function_type_function (file, print_semantic_function_type,
|
||||
"INLINE_SUPPORT",
|
||||
(is_function_definition ? "\n" : " "));
|
||||
print_function_name (file,
|
||||
function->name,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
function_name_prefix_semantics);
|
||||
lf_printf (file, "\n(");
|
||||
lf_indent (file, +1);
|
||||
print_semantic_function_formal (file, 0);
|
||||
lf_indent (file, -1);
|
||||
lf_printf (file, ")");
|
||||
if (!is_function_definition)
|
||||
lf_printf (file, ";");
|
||||
lf_printf (file, "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* map the name onto a globally valid name */
|
||||
if (!is_function_definition
|
||||
&& strcmp (options.prefix.global.name, "") != 0)
|
||||
{
|
||||
lf_indent_suppress (file);
|
||||
lf_printf (file, "#define %s %s%s\n",
|
||||
function->name,
|
||||
options.prefix.global.name,
|
||||
function->name);
|
||||
}
|
||||
lf_print__function_type (file,
|
||||
function->type,
|
||||
"INLINE_SUPPORT",
|
||||
(is_function_definition ? "\n" : " "));
|
||||
lf_printf (file, "%s%s\n(",
|
||||
options.prefix.global.name,
|
||||
function->name);
|
||||
if (options.gen.smp)
|
||||
lf_printf (file,
|
||||
"sim_cpu *cpu, %sinstruction_address cia, int MY_INDEX",
|
||||
options.prefix.global.name);
|
||||
else
|
||||
lf_printf (file,
|
||||
"SIM_DESC sd, %sinstruction_address cia, int MY_INDEX",
|
||||
options.prefix.global.name);
|
||||
if (function->param != NULL
|
||||
&& strlen (function->param) > 0)
|
||||
lf_printf (file, ", %s", function->param);
|
||||
lf_printf (file, ")%s", (is_function_definition ? "\n" : ";\n"));
|
||||
}
|
||||
lf_print_function_type(file,
|
||||
function->fields[function_type],
|
||||
"INLINE_SUPPORT",
|
||||
(is_function_definition ? "\n" : " "));
|
||||
lf_printf(file, "%s%s\n(",
|
||||
global_name_prefix,
|
||||
function->fields[function_name]);
|
||||
if (generate_smp)
|
||||
lf_printf(file, "sim_cpu *cpu");
|
||||
else
|
||||
lf_printf(file, "SIM_DESC sd");
|
||||
if (strcmp(function->fields[function_param], "") != 0)
|
||||
lf_printf(file, ", %s", function->fields[function_param]);
|
||||
lf_printf(file, ")%s", (is_function_definition ? "\n" : ";\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
support_h_function(insn_table *entry,
|
||||
lf *file,
|
||||
void *data,
|
||||
table_entry *function)
|
||||
support_h_function (lf *file,
|
||||
function_entry *function,
|
||||
void *data)
|
||||
{
|
||||
ASSERT(function->fields[function_type] != NULL);
|
||||
ASSERT(function->fields[function_param] != NULL);
|
||||
print_support_function_name(file,
|
||||
function,
|
||||
0/*!is_definition*/);
|
||||
ASSERT (function->type != NULL);
|
||||
print_support_function_name (file,
|
||||
function,
|
||||
0/*!is_definition*/);
|
||||
lf_printf(file, "\n");
|
||||
}
|
||||
|
||||
|
||||
extern void
|
||||
gen_support_h(insn_table *table,
|
||||
lf *file)
|
||||
gen_support_h (lf *file,
|
||||
insn_table *table)
|
||||
{
|
||||
/* output the definition of `_SD'*/
|
||||
if (generate_smp) {
|
||||
lf_printf(file, "#define _SD cpu\n");
|
||||
lf_printf(file, "#define SD cpu->sd\n");
|
||||
lf_printf(file, "#define CPU cpu\n");
|
||||
}
|
||||
else {
|
||||
lf_printf(file, "#define _SD sd\n");
|
||||
lf_printf(file, "#define SD sd\n");
|
||||
lf_printf(file, "#define CPU (&sd->cpu)\n");
|
||||
}
|
||||
if (options.gen.smp)
|
||||
{
|
||||
lf_printf(file, "#define _SD cpu, cia, MY_INDEX\n");
|
||||
lf_printf(file, "#define SD CPU_STATE (cpu)\n");
|
||||
lf_printf(file, "#define CPU cpu\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
lf_printf(file, "#define _SD sd, cia, MY_INDEX\n");
|
||||
lf_printf(file, "#define SD sd\n");
|
||||
lf_printf(file, "#define CPU (STATE_CPU (sd, 0))\n");
|
||||
}
|
||||
lf_printf(file, "\n");
|
||||
/* output a declaration for all functions */
|
||||
insn_table_traverse_function(table,
|
||||
file, NULL,
|
||||
support_h_function);
|
||||
function_entry_traverse (file, table->functions,
|
||||
support_h_function,
|
||||
NULL);
|
||||
lf_printf(file, "\n");
|
||||
lf_printf(file, "#if defined(SUPPORT_INLINE)\n");
|
||||
lf_printf(file, "# if ((SUPPORT_INLINE & INCLUDE_MODULE)\\\n");
|
||||
lf_printf(file, " && (SUPPORT_INLINE & INCLUDED_BY_MODULE))\n");
|
||||
lf_printf(file, "# include \"%ssupport.c\"\n", global_name_prefix);
|
||||
lf_printf(file, "# include \"%ssupport.c\"\n", options.prefix.global.name);
|
||||
lf_printf(file, "# endif\n");
|
||||
lf_printf(file, "#endif\n");
|
||||
}
|
||||
|
||||
static void
|
||||
support_c_function(insn_table *table,
|
||||
lf *file,
|
||||
void *data,
|
||||
table_entry *function)
|
||||
support_c_function (lf *file,
|
||||
function_entry *function,
|
||||
void *data)
|
||||
{
|
||||
ASSERT (function->fields[function_type] != NULL);
|
||||
ASSERT (function->type != NULL);
|
||||
print_support_function_name (file,
|
||||
function,
|
||||
1/*!is_definition*/);
|
||||
table_entry_print_cpp_line_nr (file, function);
|
||||
lf_printf (file, "{\n");
|
||||
lf_indent (file, +2);
|
||||
if (function->annex == NULL)
|
||||
error ("%s:%d: Function without body (or null statement)",
|
||||
function->file_name,
|
||||
function->line_nr);
|
||||
lf_print__c_code (file, function->annex);
|
||||
if (it_is ("internal", function->fields[insn_flags]))
|
||||
if (function->code == NULL)
|
||||
error (function->line,
|
||||
"Function without body (or null statement)");
|
||||
lf_print__line_ref (file, function->code->line);
|
||||
table_print_code (file, function->code);
|
||||
if (function->is_internal)
|
||||
{
|
||||
lf_printf (file, "sim_io_error (sd, \"Internal function must longjump\\n\");\n");
|
||||
lf_printf (file, "return cia;\n");
|
||||
}
|
||||
lf_indent (file, -2);
|
||||
lf_printf (file, "}\n");
|
||||
lf_print__internal_reference (file);
|
||||
lf_print__internal_ref (file);
|
||||
lf_printf (file, "\n");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gen_support_c(insn_table *table,
|
||||
lf *file)
|
||||
gen_support_c (lf *file,
|
||||
insn_table *table)
|
||||
{
|
||||
lf_printf(file, "#include \"sim-main.h\"\n");
|
||||
lf_printf(file, "#include \"%sidecode.h\"\n", global_name_prefix);
|
||||
lf_printf(file, "#include \"%ssupport.h\"\n", global_name_prefix);
|
||||
lf_printf(file, "#include \"%sidecode.h\"\n", options.prefix.idecode.name);
|
||||
lf_printf(file, "#include \"%sitable.h\"\n", options.prefix.itable.name);
|
||||
lf_printf(file, "#include \"%ssupport.h\"\n", options.prefix.support.name);
|
||||
lf_printf(file, "\n");
|
||||
|
||||
/* output a definition (c-code) for all functions */
|
||||
insn_table_traverse_function(table,
|
||||
file, NULL,
|
||||
support_c_function);
|
||||
function_entry_traverse (file, table->functions,
|
||||
support_c_function,
|
||||
NULL);
|
||||
}
|
||||
|
1498
sim/igen/gen.c
Normal file
1498
sim/igen/gen.c
Normal file
File diff suppressed because it is too large
Load Diff
1568
sim/igen/igen.c
1568
sim/igen/igen.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user