OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [ppc/] [gen-semantics.c] - Diff between revs 834 and 842

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 834 Rev 842
/*  This file is part of the program psim.
/*  This file is part of the program psim.
 
 
    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
    Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
 
 
    This program is free software; you can redistribute it and/or modify
    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
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
    */
    */
 
 
 
 
 
 
#include "misc.h"
#include "misc.h"
#include "lf.h"
#include "lf.h"
#include "table.h"
#include "table.h"
#include "filter.h"
#include "filter.h"
 
 
#include "ld-decode.h"
#include "ld-decode.h"
#include "ld-cache.h"
#include "ld-cache.h"
#include "ld-insn.h"
#include "ld-insn.h"
 
 
#include "igen.h"
#include "igen.h"
 
 
#include "gen-semantics.h"
#include "gen-semantics.h"
#include "gen-icache.h"
#include "gen-icache.h"
#include "gen-idecode.h"
#include "gen-idecode.h"
 
 
 
 
static void
static void
print_semantic_function_header(lf *file,
print_semantic_function_header(lf *file,
                               const char *basename,
                               const char *basename,
                               insn_bits *expanded_bits,
                               insn_bits *expanded_bits,
                               int is_function_definition)
                               int is_function_definition)
{
{
  int indent;
  int indent;
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_print_function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_EXTERN_SEMANTICS",
  lf_print_function_type(file, SEMANTIC_FUNCTION_TYPE, "PSIM_EXTERN_SEMANTICS",
                         (is_function_definition ? "\n" : " "));
                         (is_function_definition ? "\n" : " "));
  indent = print_function_name(file,
  indent = print_function_name(file,
                               basename,
                               basename,
                               expanded_bits,
                               expanded_bits,
                               function_name_prefix_semantics);
                               function_name_prefix_semantics);
  if (is_function_definition)
  if (is_function_definition)
    lf_indent(file, +indent);
    lf_indent(file, +indent);
  else
  else
    lf_printf(file, "\n");
    lf_printf(file, "\n");
  lf_printf(file, "(%s)", SEMANTIC_FUNCTION_FORMAL);
  lf_printf(file, "(%s)", SEMANTIC_FUNCTION_FORMAL);
  if (is_function_definition)
  if (is_function_definition)
    lf_indent(file, -indent);
    lf_indent(file, -indent);
  else
  else
    lf_printf(file, ";");
    lf_printf(file, ";");
  lf_printf(file, "\n");
  lf_printf(file, "\n");
}
}
 
 
void
void
print_semantic_declaration(insn_table *entry,
print_semantic_declaration(insn_table *entry,
                           lf *file,
                           lf *file,
                           void *data,
                           void *data,
                           insn *instruction,
                           insn *instruction,
                           int depth)
                           int depth)
{
{
  if (generate_expanded_instructions) {
  if (generate_expanded_instructions) {
    ASSERT(entry->nr_insn == 1);
    ASSERT(entry->nr_insn == 1);
    print_semantic_function_header(file,
    print_semantic_function_header(file,
                                   instruction->file_entry->fields[insn_name],
                                   instruction->file_entry->fields[insn_name],
                                   entry->expanded_bits,
                                   entry->expanded_bits,
                                   0/* is not function definition*/);
                                   0/* is not function definition*/);
  }
  }
  else {
  else {
    print_semantic_function_header(file,
    print_semantic_function_header(file,
                                   instruction->file_entry->fields[insn_name],
                                   instruction->file_entry->fields[insn_name],
                                   NULL,
                                   NULL,
                                   0/* is not function definition*/);
                                   0/* is not function definition*/);
  }
  }
}
}
 
 
 
 


/* generate the semantics.c file */
/* generate the semantics.c file */
 
 
 
 
void
void
print_idecode_illegal(lf *file,
print_idecode_illegal(lf *file,
                      const char *result)
                      const char *result)
{
{
  if ((code & generate_jumps))
  if ((code & generate_jumps))
    lf_printf(file, "goto %s_illegal;\n", (code & generate_with_icache) ? "icache" : "semantic");
    lf_printf(file, "goto %s_illegal;\n", (code & generate_with_icache) ? "icache" : "semantic");
  else if ((code & generate_with_icache))
  else if ((code & generate_with_icache))
    lf_printf(file, "%s icache_illegal(%s);\n", result, ICACHE_FUNCTION_ACTUAL);
    lf_printf(file, "%s icache_illegal(%s);\n", result, ICACHE_FUNCTION_ACTUAL);
  else
  else
    lf_printf(file, "%s semantic_illegal(%s);\n", result, SEMANTIC_FUNCTION_ACTUAL);
    lf_printf(file, "%s semantic_illegal(%s);\n", result, SEMANTIC_FUNCTION_ACTUAL);
}
}
 
 
 
 
void
void
print_semantic_body(lf *file,
print_semantic_body(lf *file,
                    insn *instruction,
                    insn *instruction,
                    insn_bits *expanded_bits,
                    insn_bits *expanded_bits,
                    opcode_field *opcodes)
                    opcode_field *opcodes)
{
{
  print_itrace(file, instruction->file_entry, 0/*put_value_in_cache*/);
  print_itrace(file, instruction->file_entry, 0/*put_value_in_cache*/);
 
 
  /* validate the instruction, if a cache this has already been done */
  /* validate the instruction, if a cache this has already been done */
  if (!(code & generate_with_icache))
  if (!(code & generate_with_icache))
    print_idecode_validate(file, instruction, opcodes);
    print_idecode_validate(file, instruction, opcodes);
 
 
  /* generate the profiling call - this is delayed until after the
  /* generate the profiling call - this is delayed until after the
     instruction has been verified */
     instruction has been verified */
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_printf(file, "/* monitoring: */\n");
  lf_printf(file, "/* monitoring: */\n");
  lf_printf(file, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE) {\n");
  lf_printf(file, "if (WITH_MON & MONITOR_INSTRUCTION_ISSUE) {\n");
  lf_printf(file, "  mon_issue(");
  lf_printf(file, "  mon_issue(");
  print_function_name(file,
  print_function_name(file,
                      instruction->file_entry->fields[insn_name],
                      instruction->file_entry->fields[insn_name],
                      NULL,
                      NULL,
                      function_name_prefix_itable);
                      function_name_prefix_itable);
  lf_printf(file, ", processor, cia);\n");
  lf_printf(file, ", processor, cia);\n");
  lf_printf(file, "}\n");
  lf_printf(file, "}\n");
 
 
  /* generate the code (or at least something */
  /* generate the code (or at least something */
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_printf(file, "/* semantics: */\n");
  lf_printf(file, "/* semantics: */\n");
  lf_printf(file, "nia = cia + %d;\n", insn_bit_size / 8);
  lf_printf(file, "nia = cia + %d;\n", insn_bit_size / 8);
  if (instruction->file_entry->annex != NULL) {
  if (instruction->file_entry->annex != NULL) {
    /* true code */
    /* true code */
    table_entry_print_cpp_line_nr(file, instruction->file_entry);
    table_entry_print_cpp_line_nr(file, instruction->file_entry);
    lf_printf(file, "{\n");
    lf_printf(file, "{\n");
    lf_indent(file, +2);
    lf_indent(file, +2);
    lf_print__c_code(file, instruction->file_entry->annex);
    lf_print__c_code(file, instruction->file_entry->annex);
    lf_indent(file, -2);
    lf_indent(file, -2);
    lf_printf(file, "}\n");
    lf_printf(file, "}\n");
    lf_print__internal_reference(file);
    lf_print__internal_reference(file);
  }
  }
  else if (it_is("nop", instruction->file_entry->fields[insn_flags])) {
  else if (it_is("nop", instruction->file_entry->fields[insn_flags])) {
    lf_print__internal_reference(file);
    lf_print__internal_reference(file);
  }
  }
  else {
  else {
    /* abort so it is implemented now */
    /* abort so it is implemented now */
    table_entry_print_cpp_line_nr(file, instruction->file_entry);
    table_entry_print_cpp_line_nr(file, instruction->file_entry);
    lf_putstr(file, "error(\"%s:%d:0x%08lx:%s unimplemented\\n\",\n");
    lf_putstr(file, "error(\"%s:%d:0x%08lx:%s unimplemented\\n\",\n");
    lf_printf(file, "      itable[MY_INDEX].file, itable[MY_INDEX].line_nr, (long)cia, itable[MY_INDEX].name);\n");
    lf_printf(file, "      itable[MY_INDEX].file, itable[MY_INDEX].line_nr, (long)cia, itable[MY_INDEX].name);\n");
    lf_print__internal_reference(file);
    lf_print__internal_reference(file);
  }
  }
}
}
 
 
static void
static void
print_c_semantic(lf *file,
print_c_semantic(lf *file,
                 insn *instruction,
                 insn *instruction,
                 insn_bits *expanded_bits,
                 insn_bits *expanded_bits,
                 opcode_field *opcodes,
                 opcode_field *opcodes,
                 cache_table *cache_rules)
                 cache_table *cache_rules)
{
{
 
 
  lf_printf(file, "{\n");
  lf_printf(file, "{\n");
  lf_indent(file, +2);
  lf_indent(file, +2);
 
 
  print_my_defines(file, expanded_bits, instruction->file_entry);
  print_my_defines(file, expanded_bits, instruction->file_entry);
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  print_icache_body(file,
  print_icache_body(file,
                    instruction,
                    instruction,
                    expanded_bits,
                    expanded_bits,
                    cache_rules,
                    cache_rules,
                    ((code & generate_with_direct_access)
                    ((code & generate_with_direct_access)
                     ? define_variables
                     ? define_variables
                     : declare_variables),
                     : declare_variables),
                    ((code & generate_with_icache)
                    ((code & generate_with_icache)
                     ? get_values_from_icache
                     ? get_values_from_icache
                     : do_not_use_icache));
                     : do_not_use_icache));
 
 
  lf_printf(file, "unsigned_word nia;\n");
  lf_printf(file, "unsigned_word nia;\n");
  print_semantic_body(file,
  print_semantic_body(file,
                      instruction,
                      instruction,
                      expanded_bits,
                      expanded_bits,
                      opcodes);
                      opcodes);
  lf_printf(file, "return nia;\n");
  lf_printf(file, "return nia;\n");
 
 
  /* generate something to clean up any #defines created for the cache */
  /* generate something to clean up any #defines created for the cache */
  if (code & generate_with_direct_access)
  if (code & generate_with_direct_access)
    print_icache_body(file,
    print_icache_body(file,
                      instruction,
                      instruction,
                      expanded_bits,
                      expanded_bits,
                      cache_rules,
                      cache_rules,
                      undef_variables,
                      undef_variables,
                      ((code & generate_with_icache)
                      ((code & generate_with_icache)
                       ? get_values_from_icache
                       ? get_values_from_icache
                       : do_not_use_icache));
                       : do_not_use_icache));
 
 
  lf_indent(file, -2);
  lf_indent(file, -2);
  lf_printf(file, "}\n");
  lf_printf(file, "}\n");
}
}
 
 
static void
static void
print_c_semantic_function(lf *file,
print_c_semantic_function(lf *file,
                          insn *instruction,
                          insn *instruction,
                          insn_bits *expanded_bits,
                          insn_bits *expanded_bits,
                          opcode_field *opcodes,
                          opcode_field *opcodes,
                          cache_table *cache_rules)
                          cache_table *cache_rules)
{
{
  /* build the semantic routine to execute the instruction */
  /* build the semantic routine to execute the instruction */
  print_semantic_function_header(file,
  print_semantic_function_header(file,
                                 instruction->file_entry->fields[insn_name],
                                 instruction->file_entry->fields[insn_name],
                                 expanded_bits,
                                 expanded_bits,
                                 1/*is-function-definition*/);
                                 1/*is-function-definition*/);
  print_c_semantic(file,
  print_c_semantic(file,
                   instruction,
                   instruction,
                   expanded_bits,
                   expanded_bits,
                   opcodes,
                   opcodes,
                   cache_rules);
                   cache_rules);
}
}
 
 
void
void
print_semantic_definition(insn_table *entry,
print_semantic_definition(insn_table *entry,
                          lf *file,
                          lf *file,
                          void *data,
                          void *data,
                          insn *instruction,
                          insn *instruction,
                          int depth)
                          int depth)
{
{
  cache_table *cache_rules = (cache_table*)data;
  cache_table *cache_rules = (cache_table*)data;
  if (generate_expanded_instructions) {
  if (generate_expanded_instructions) {
    ASSERT(entry->nr_insn == 1
    ASSERT(entry->nr_insn == 1
           && entry->opcode == NULL
           && entry->opcode == NULL
           && entry->parent != NULL
           && entry->parent != NULL
           && entry->parent->opcode != NULL);
           && entry->parent->opcode != NULL);
    ASSERT(entry->nr_insn == 1
    ASSERT(entry->nr_insn == 1
           && entry->opcode == NULL
           && entry->opcode == NULL
           && entry->parent != NULL
           && entry->parent != NULL
           && entry->parent->opcode != NULL
           && entry->parent->opcode != NULL
           && entry->parent->opcode_rule != NULL);
           && entry->parent->opcode_rule != NULL);
    print_c_semantic_function(file,
    print_c_semantic_function(file,
                              entry->insns,
                              entry->insns,
                              entry->expanded_bits,
                              entry->expanded_bits,
                              entry->parent->opcode,
                              entry->parent->opcode,
                              cache_rules);
                              cache_rules);
  }
  }
  else {
  else {
    print_c_semantic_function(file, instruction,
    print_c_semantic_function(file, instruction,
                              NULL, NULL,
                              NULL, NULL,
                              cache_rules);
                              cache_rules);
  }
  }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.