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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [sim/] [ppc/] [gen-icache.c] - Diff between revs 835 and 841

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

Rev 835 Rev 841
/*  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-idecode.h"
#include "gen-idecode.h"
#include "gen-icache.h"
#include "gen-icache.h"
 
 
 
 
 
 
static void
static void
print_icache_function_header(lf *file,
print_icache_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)
{
{
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", " ");
  lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", " ");
  print_function_name(file,
  print_function_name(file,
                      basename,
                      basename,
                      expanded_bits,
                      expanded_bits,
                      function_name_prefix_icache);
                      function_name_prefix_icache);
  lf_printf(file, "\n(%s)", ICACHE_FUNCTION_FORMAL);
  lf_printf(file, "\n(%s)", ICACHE_FUNCTION_FORMAL);
  if (!is_function_definition)
  if (!is_function_definition)
    lf_printf(file, ";");
    lf_printf(file, ";");
  lf_printf(file, "\n");
  lf_printf(file, "\n");
}
}
 
 
 
 
void
void
print_icache_declaration(insn_table *entry,
print_icache_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_icache_function_header(file,
    print_icache_function_header(file,
                                 entry->insns->file_entry->fields[insn_name],
                                 entry->insns->file_entry->fields[insn_name],
                                 entry->expanded_bits,
                                 entry->expanded_bits,
                                 0/* is not function definition */);
                                 0/* is not function definition */);
  }
  }
  else {
  else {
    print_icache_function_header(file,
    print_icache_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 */);
  }
  }
}
}
 
 
 
 
 
 
static void
static void
print_icache_extraction(lf *file,
print_icache_extraction(lf *file,
                        insn *instruction,
                        insn *instruction,
                        const char *entry_name,
                        const char *entry_name,
                        const char *entry_type,
                        const char *entry_type,
                        const char *entry_expression,
                        const char *entry_expression,
                        const char *original_name,
                        const char *original_name,
                        const char *file_name,
                        const char *file_name,
                        int line_nr,
                        int line_nr,
                        insn_field *cur_field,
                        insn_field *cur_field,
                        insn_bits *bits,
                        insn_bits *bits,
                        icache_decl_type what_to_declare,
                        icache_decl_type what_to_declare,
                        icache_body_type what_to_do,
                        icache_body_type what_to_do,
                        const char *reason)
                        const char *reason)
{
{
  const char *expression;
  const char *expression;
  ASSERT(entry_name != NULL);
  ASSERT(entry_name != NULL);
 
 
  /* Define a storage area for the cache element */
  /* Define a storage area for the cache element */
  if (what_to_declare == undef_variables) {
  if (what_to_declare == undef_variables) {
    /* We've finished with the value - destory it */
    /* We've finished with the value - destory it */
    lf_indent_suppress(file);
    lf_indent_suppress(file);
    lf_printf(file, "#undef %s\n", entry_name);
    lf_printf(file, "#undef %s\n", entry_name);
    return;
    return;
  }
  }
  else if (what_to_declare == define_variables) {
  else if (what_to_declare == define_variables) {
    lf_indent_suppress(file);
    lf_indent_suppress(file);
    lf_printf(file, "#define %s ", entry_name);
    lf_printf(file, "#define %s ", entry_name);
  }
  }
  else {
  else {
    if (file_name != NULL)
    if (file_name != NULL)
      lf_print__external_reference(file, line_nr, file_name);
      lf_print__external_reference(file, line_nr, file_name);
    lf_printf(file, "%s const %s UNUSED = ",
    lf_printf(file, "%s const %s UNUSED = ",
              entry_type == NULL ? "unsigned" : entry_type,
              entry_type == NULL ? "unsigned" : entry_type,
              entry_name);
              entry_name);
  }
  }
 
 
  /* define a value for that storage area as determined by what is in
  /* define a value for that storage area as determined by what is in
     the cache */
     the cache */
  if (bits != NULL
  if (bits != NULL
      && strcmp(entry_name, cur_field->val_string) == 0
      && strcmp(entry_name, cur_field->val_string) == 0
      && ((bits->opcode->is_boolean && bits->value == 0)
      && ((bits->opcode->is_boolean && bits->value == 0)
          || (!bits->opcode->is_boolean))) {
          || (!bits->opcode->is_boolean))) {
    /* The simple field has been made constant (as a result of
    /* The simple field has been made constant (as a result of
       expanding instructions or similar).  Remember that for a
       expanding instructions or similar).  Remember that for a
       boolean field, value is either 0 (implying the required
       boolean field, value is either 0 (implying the required
       boolean_constant) or nonzero (implying some other value and
       boolean_constant) or nonzero (implying some other value and
       handled later below) - Define the variable accordingly */
       handled later below) - Define the variable accordingly */
    expression = "constant field";
    expression = "constant field";
    ASSERT(bits->field == cur_field);
    ASSERT(bits->field == cur_field);
    ASSERT(entry_type == NULL);
    ASSERT(entry_type == NULL);
    if (bits->opcode->is_boolean)
    if (bits->opcode->is_boolean)
      lf_printf(file, "%d", bits->opcode->boolean_constant);
      lf_printf(file, "%d", bits->opcode->boolean_constant);
    else if (bits->opcode->last < bits->field->last)
    else if (bits->opcode->last < bits->field->last)
      lf_printf(file, "%d",
      lf_printf(file, "%d",
                bits->value << (bits->field->last - bits->opcode->last));
                bits->value << (bits->field->last - bits->opcode->last));
    else
    else
      lf_printf(file, "%d", bits->value);
      lf_printf(file, "%d", bits->value);
  }
  }
  else if (bits != NULL
  else if (bits != NULL
           && original_name != NULL
           && original_name != NULL
           && strncmp(entry_name,
           && strncmp(entry_name,
                      original_name, strlen(original_name)) == 0
                      original_name, strlen(original_name)) == 0
           && strncmp(entry_name + strlen(original_name),
           && strncmp(entry_name + strlen(original_name),
                      "_is_", strlen("_is_")) == 0
                      "_is_", strlen("_is_")) == 0
           && ((bits->opcode->is_boolean
           && ((bits->opcode->is_boolean
                && (atol(entry_name + strlen(original_name) + strlen("_is_"))
                && (atol(entry_name + strlen(original_name) + strlen("_is_"))
                    == bits->opcode->boolean_constant))
                    == bits->opcode->boolean_constant))
               || (!bits->opcode->is_boolean))) {
               || (!bits->opcode->is_boolean))) {
    expression = "constant compare";
    expression = "constant compare";
    /* An entry, derived from ORIGINAL_NAME, is testing to see of the
    /* An entry, derived from ORIGINAL_NAME, is testing to see of the
       ORIGINAL_NAME has a specific constant value.  That value
       ORIGINAL_NAME has a specific constant value.  That value
       matching a boolean or constant field */
       matching a boolean or constant field */
    if (bits->opcode->is_boolean)
    if (bits->opcode->is_boolean)
      lf_printf(file, "%d /* %s == %d */",
      lf_printf(file, "%d /* %s == %d */",
                bits->value == 0,
                bits->value == 0,
                original_name,
                original_name,
                bits->opcode->boolean_constant);
                bits->opcode->boolean_constant);
    else if (bits->opcode->last < bits->field->last)
    else if (bits->opcode->last < bits->field->last)
      lf_printf(file, "%d /* %s == %d */",
      lf_printf(file, "%d /* %s == %d */",
                (atol(entry_name + strlen(original_name) + strlen("_is_"))
                (atol(entry_name + strlen(original_name) + strlen("_is_"))
                 == (bits->value << (bits->field->last - bits->opcode->last))),
                 == (bits->value << (bits->field->last - bits->opcode->last))),
                original_name,
                original_name,
                (bits->value << (bits->field->last - bits->opcode->last)));
                (bits->value << (bits->field->last - bits->opcode->last)));
    else
    else
      lf_printf(file, "%d /* %s == %d */",
      lf_printf(file, "%d /* %s == %d */",
                (atol(entry_name + strlen(original_name) + strlen("_is_"))
                (atol(entry_name + strlen(original_name) + strlen("_is_"))
                 == bits->value),
                 == bits->value),
                original_name,
                original_name,
                bits->value);
                bits->value);
  }
  }
  else {
  else {
    /* put the field in the local variable, possibly also enter it
    /* put the field in the local variable, possibly also enter it
       into the cache */
       into the cache */
    expression = "extraction";
    expression = "extraction";
    /* handle the cache */
    /* handle the cache */
    if ((what_to_do & get_values_from_icache)
    if ((what_to_do & get_values_from_icache)
        || (what_to_do & put_values_in_icache)) {
        || (what_to_do & put_values_in_icache)) {
      lf_printf(file, "cache_entry->crack.%s.%s",
      lf_printf(file, "cache_entry->crack.%s.%s",
                instruction->file_entry->fields[insn_form],
                instruction->file_entry->fields[insn_form],
                entry_name);
                entry_name);
      if (what_to_do & put_values_in_icache) /* also put it in the cache? */
      if (what_to_do & put_values_in_icache) /* also put it in the cache? */
        lf_printf(file, " = ");
        lf_printf(file, " = ");
    }
    }
    if ((what_to_do & put_values_in_icache)
    if ((what_to_do & put_values_in_icache)
        || what_to_do == do_not_use_icache) {
        || what_to_do == do_not_use_icache) {
      if (cur_field != NULL && strcmp(entry_name, cur_field->val_string) == 0)
      if (cur_field != NULL && strcmp(entry_name, cur_field->val_string) == 0)
        lf_printf(file, "EXTRACTED32(instruction, %d, %d)",
        lf_printf(file, "EXTRACTED32(instruction, %d, %d)",
                  i2target(hi_bit_nr, cur_field->first),
                  i2target(hi_bit_nr, cur_field->first),
                  i2target(hi_bit_nr, cur_field->last));
                  i2target(hi_bit_nr, cur_field->last));
      else if (entry_expression != NULL)
      else if (entry_expression != NULL)
        lf_printf(file, "%s", entry_expression);
        lf_printf(file, "%s", entry_expression);
      else
      else
        lf_printf(file, "eval_%s", entry_name);
        lf_printf(file, "eval_%s", entry_name);
    }
    }
  }
  }
 
 
  if (!((what_to_declare == define_variables)
  if (!((what_to_declare == define_variables)
        || (what_to_declare == undef_variables)))
        || (what_to_declare == undef_variables)))
    lf_printf(file, ";");
    lf_printf(file, ";");
  if (reason != NULL)
  if (reason != NULL)
    lf_printf(file, " /* %s - %s */", reason, expression);
    lf_printf(file, " /* %s - %s */", reason, expression);
  lf_printf(file, "\n");
  lf_printf(file, "\n");
}
}
 
 
 
 
void
void
print_icache_body(lf *file,
print_icache_body(lf *file,
                  insn *instruction,
                  insn *instruction,
                  insn_bits *expanded_bits,
                  insn_bits *expanded_bits,
                  cache_table *cache_rules,
                  cache_table *cache_rules,
                  icache_decl_type what_to_declare,
                  icache_decl_type what_to_declare,
                  icache_body_type what_to_do)
                  icache_body_type what_to_do)
{
{
  insn_field *cur_field;
  insn_field *cur_field;
 
 
  /* extract instruction fields */
  /* extract instruction fields */
  lf_printf(file, "/* extraction: %s ",
  lf_printf(file, "/* extraction: %s ",
            instruction->file_entry->fields[insn_format]);
            instruction->file_entry->fields[insn_format]);
  switch (what_to_declare) {
  switch (what_to_declare) {
  case define_variables:
  case define_variables:
    lf_printf(file, "#define");
    lf_printf(file, "#define");
    break;
    break;
  case declare_variables:
  case declare_variables:
    lf_printf(file, "declare");
    lf_printf(file, "declare");
    break;
    break;
  case undef_variables:
  case undef_variables:
    lf_printf(file, "#undef");
    lf_printf(file, "#undef");
    break;
    break;
  }
  }
  lf_printf(file, " ");
  lf_printf(file, " ");
  switch (what_to_do) {
  switch (what_to_do) {
  case get_values_from_icache:
  case get_values_from_icache:
    lf_printf(file, "get-values-from-icache");
    lf_printf(file, "get-values-from-icache");
    break;
    break;
  case put_values_in_icache:
  case put_values_in_icache:
    lf_printf(file, "put-values-in-icache");
    lf_printf(file, "put-values-in-icache");
    break;
    break;
  case both_values_and_icache:
  case both_values_and_icache:
    lf_printf(file, "get-values-from-icache|put-values-in-icache");
    lf_printf(file, "get-values-from-icache|put-values-in-icache");
    break;
    break;
  case do_not_use_icache:
  case do_not_use_icache:
    lf_printf(file, "do-not-use-icache");
    lf_printf(file, "do-not-use-icache");
    break;
    break;
  }
  }
  lf_printf(file, " */\n");
  lf_printf(file, " */\n");
 
 
  for (cur_field = instruction->fields->first;
  for (cur_field = instruction->fields->first;
       cur_field->first < insn_bit_size;
       cur_field->first < insn_bit_size;
       cur_field = cur_field->next) {
       cur_field = cur_field->next) {
    if (cur_field->is_string) {
    if (cur_field->is_string) {
      insn_bits *bits;
      insn_bits *bits;
      int found_rule = 0;
      int found_rule = 0;
      /* find any corresponding value */
      /* find any corresponding value */
      for (bits = expanded_bits;
      for (bits = expanded_bits;
           bits != NULL;
           bits != NULL;
           bits = bits->last) {
           bits = bits->last) {
        if (bits->field == cur_field)
        if (bits->field == cur_field)
          break;
          break;
      }
      }
      /* try the cache rule table for what to do */
      /* try the cache rule table for what to do */
      {
      {
        cache_table *cache_rule;
        cache_table *cache_rule;
        for (cache_rule = cache_rules;
        for (cache_rule = cache_rules;
             cache_rule != NULL;
             cache_rule != NULL;
             cache_rule = cache_rule->next) {
             cache_rule = cache_rule->next) {
          if (strcmp(cur_field->val_string, cache_rule->field_name) == 0) {
          if (strcmp(cur_field->val_string, cache_rule->field_name) == 0) {
            found_rule = 1;
            found_rule = 1;
            if (cache_rule->type == scratch_value
            if (cache_rule->type == scratch_value
                && ((what_to_do & put_values_in_icache)
                && ((what_to_do & put_values_in_icache)
                    || what_to_do == do_not_use_icache))
                    || what_to_do == do_not_use_icache))
              print_icache_extraction(file,
              print_icache_extraction(file,
                                      instruction,
                                      instruction,
                                      cache_rule->derived_name,
                                      cache_rule->derived_name,
                                      cache_rule->type_def,
                                      cache_rule->type_def,
                                      cache_rule->expression,
                                      cache_rule->expression,
                                      cache_rule->field_name,
                                      cache_rule->field_name,
                                      cache_rule->file_entry->file_name,
                                      cache_rule->file_entry->file_name,
                                      cache_rule->file_entry->line_nr,
                                      cache_rule->file_entry->line_nr,
                                      cur_field,
                                      cur_field,
                                      bits,
                                      bits,
                                      what_to_declare,
                                      what_to_declare,
                                      do_not_use_icache,
                                      do_not_use_icache,
                                      "icache scratch");
                                      "icache scratch");
            else if (cache_rule->type == compute_value
            else if (cache_rule->type == compute_value
                     && ((what_to_do & get_values_from_icache)
                     && ((what_to_do & get_values_from_icache)
                         || what_to_do == do_not_use_icache))
                         || what_to_do == do_not_use_icache))
              print_icache_extraction(file,
              print_icache_extraction(file,
                                      instruction,
                                      instruction,
                                      cache_rule->derived_name,
                                      cache_rule->derived_name,
                                      cache_rule->type_def,
                                      cache_rule->type_def,
                                      cache_rule->expression,
                                      cache_rule->expression,
                                      cache_rule->field_name,
                                      cache_rule->field_name,
                                      cache_rule->file_entry->file_name,
                                      cache_rule->file_entry->file_name,
                                      cache_rule->file_entry->line_nr,
                                      cache_rule->file_entry->line_nr,
                                      cur_field,
                                      cur_field,
                                      bits,
                                      bits,
                                      what_to_declare,
                                      what_to_declare,
                                      do_not_use_icache,
                                      do_not_use_icache,
                                      "semantic compute");
                                      "semantic compute");
            else if (cache_rule->type == cache_value
            else if (cache_rule->type == cache_value
                     && ((what_to_declare != undef_variables)
                     && ((what_to_declare != undef_variables)
                         || !(what_to_do & put_values_in_icache)))
                         || !(what_to_do & put_values_in_icache)))
              print_icache_extraction(file,
              print_icache_extraction(file,
                                      instruction,
                                      instruction,
                                      cache_rule->derived_name,
                                      cache_rule->derived_name,
                                      cache_rule->type_def,
                                      cache_rule->type_def,
                                      cache_rule->expression,
                                      cache_rule->expression,
                                      cache_rule->field_name,
                                      cache_rule->field_name,
                                      cache_rule->file_entry->file_name,
                                      cache_rule->file_entry->file_name,
                                      cache_rule->file_entry->line_nr,
                                      cache_rule->file_entry->line_nr,
                                      cur_field,
                                      cur_field,
                                      bits,
                                      bits,
                                      ((what_to_do & put_values_in_icache)
                                      ((what_to_do & put_values_in_icache)
                                       ? declare_variables
                                       ? declare_variables
                                       : what_to_declare),
                                       : what_to_declare),
                                      what_to_do,
                                      what_to_do,
                                      "in icache");
                                      "in icache");
          }
          }
        }
        }
      }
      }
      /* No rule at all, assume that this is needed in the semantic
      /* No rule at all, assume that this is needed in the semantic
         function (when values are extracted from the icache) and
         function (when values are extracted from the icache) and
         hence must be put into the cache */
         hence must be put into the cache */
      if (found_rule == 0
      if (found_rule == 0
          && ((what_to_declare != undef_variables)
          && ((what_to_declare != undef_variables)
              || !(what_to_do & put_values_in_icache)))
              || !(what_to_do & put_values_in_icache)))
        print_icache_extraction(file,
        print_icache_extraction(file,
                                instruction,
                                instruction,
                                cur_field->val_string,
                                cur_field->val_string,
                                NULL, NULL, NULL, /* type, exp, orig */
                                NULL, NULL, NULL, /* type, exp, orig */
                                instruction->file_entry->file_name,
                                instruction->file_entry->file_name,
                                instruction->file_entry->line_nr,
                                instruction->file_entry->line_nr,
                                cur_field,
                                cur_field,
                                bits,
                                bits,
                                ((what_to_do & put_values_in_icache)
                                ((what_to_do & put_values_in_icache)
                                 ? declare_variables
                                 ? declare_variables
                                 : what_to_declare),
                                 : what_to_declare),
                                what_to_do,
                                what_to_do,
                                "default in icache");
                                "default in icache");
      /* any thing else ... */
      /* any thing else ... */
    }
    }
  }
  }
 
 
  lf_print__internal_reference(file);
  lf_print__internal_reference(file);
 
 
  if ((code & generate_with_insn_in_icache)) {
  if ((code & generate_with_insn_in_icache)) {
    lf_printf(file, "\n");
    lf_printf(file, "\n");
    print_icache_extraction(file,
    print_icache_extraction(file,
                            instruction,
                            instruction,
                            "insn",
                            "insn",
                            "instruction_word",
                            "instruction_word",
                            "instruction",
                            "instruction",
                            NULL, /* origin */
                            NULL, /* origin */
                            NULL, 0, /* file_name & line_nr */
                            NULL, 0, /* file_name & line_nr */
                            NULL, NULL,
                            NULL, NULL,
                            what_to_declare,
                            what_to_declare,
                            what_to_do,
                            what_to_do,
                            NULL);
                            NULL);
  }
  }
}
}
 
 
 
 
 
 
typedef struct _icache_tree icache_tree;
typedef struct _icache_tree icache_tree;
struct _icache_tree {
struct _icache_tree {
  char *name;
  char *name;
  icache_tree *next;
  icache_tree *next;
  icache_tree *children;
  icache_tree *children;
};
};
 
 
static icache_tree *
static icache_tree *
icache_tree_insert(icache_tree *tree,
icache_tree_insert(icache_tree *tree,
                   char *name)
                   char *name)
{
{
  icache_tree *new_tree;
  icache_tree *new_tree;
  /* find it */
  /* find it */
  icache_tree **ptr_to_cur_tree = &tree->children;
  icache_tree **ptr_to_cur_tree = &tree->children;
  icache_tree *cur_tree = *ptr_to_cur_tree;
  icache_tree *cur_tree = *ptr_to_cur_tree;
  while (cur_tree != NULL
  while (cur_tree != NULL
         && strcmp(cur_tree->name, name) < 0) {
         && strcmp(cur_tree->name, name) < 0) {
    ptr_to_cur_tree = &cur_tree->next;
    ptr_to_cur_tree = &cur_tree->next;
    cur_tree = *ptr_to_cur_tree;
    cur_tree = *ptr_to_cur_tree;
  }
  }
  ASSERT(cur_tree == NULL
  ASSERT(cur_tree == NULL
         || strcmp(cur_tree->name, name) >= 0);
         || strcmp(cur_tree->name, name) >= 0);
  /* already in the tree */
  /* already in the tree */
  if (cur_tree != NULL
  if (cur_tree != NULL
      && strcmp(cur_tree->name, name) == 0)
      && strcmp(cur_tree->name, name) == 0)
    return cur_tree;
    return cur_tree;
  /* missing, insert it */
  /* missing, insert it */
  ASSERT(cur_tree == NULL
  ASSERT(cur_tree == NULL
         || strcmp(cur_tree->name, name) > 0);
         || strcmp(cur_tree->name, name) > 0);
  new_tree = ZALLOC(icache_tree);
  new_tree = ZALLOC(icache_tree);
  new_tree->name = name;
  new_tree->name = name;
  new_tree->next = cur_tree;
  new_tree->next = cur_tree;
  *ptr_to_cur_tree = new_tree;
  *ptr_to_cur_tree = new_tree;
  return new_tree;
  return new_tree;
}
}
 
 
 
 
static icache_tree *
static icache_tree *
insn_table_cache_fields(insn_table *table)
insn_table_cache_fields(insn_table *table)
{
{
  icache_tree *tree = ZALLOC(icache_tree);
  icache_tree *tree = ZALLOC(icache_tree);
  insn *instruction;
  insn *instruction;
  for (instruction = table->insns;
  for (instruction = table->insns;
       instruction != NULL;
       instruction != NULL;
       instruction = instruction->next) {
       instruction = instruction->next) {
    insn_field *field;
    insn_field *field;
    icache_tree *form =
    icache_tree *form =
      icache_tree_insert(tree,
      icache_tree_insert(tree,
                         instruction->file_entry->fields[insn_form]);
                         instruction->file_entry->fields[insn_form]);
    for (field = instruction->fields->first;
    for (field = instruction->fields->first;
         field != NULL;
         field != NULL;
         field = field->next) {
         field = field->next) {
      if (field->is_string)
      if (field->is_string)
        icache_tree_insert(form, field->val_string);
        icache_tree_insert(form, field->val_string);
    }
    }
  }
  }
  return tree;
  return tree;
}
}
 
 
 
 
 
 
extern void
extern void
print_icache_struct(insn_table *instructions,
print_icache_struct(insn_table *instructions,
                    cache_table *cache_rules,
                    cache_table *cache_rules,
                    lf *file)
                    lf *file)
{
{
  icache_tree *tree = insn_table_cache_fields(instructions);
  icache_tree *tree = insn_table_cache_fields(instructions);
 
 
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_printf(file, "#define WITH_IDECODE_CACHE_SIZE %d\n",
  lf_printf(file, "#define WITH_IDECODE_CACHE_SIZE %d\n",
            (code & generate_with_icache) ? icache_size : 0);
            (code & generate_with_icache) ? icache_size : 0);
  lf_printf(file, "\n");
  lf_printf(file, "\n");
 
 
  /* create an instruction cache if being used */
  /* create an instruction cache if being used */
  if ((code & generate_with_icache)) {
  if ((code & generate_with_icache)) {
    icache_tree *form;
    icache_tree *form;
    lf_printf(file, "typedef struct _idecode_cache {\n");
    lf_printf(file, "typedef struct _idecode_cache {\n");
    lf_printf(file, "  unsigned_word address;\n");
    lf_printf(file, "  unsigned_word address;\n");
    lf_printf(file, "  void *semantic;\n");
    lf_printf(file, "  void *semantic;\n");
    lf_printf(file, "  union {\n");
    lf_printf(file, "  union {\n");
    for (form = tree->children;
    for (form = tree->children;
         form != NULL;
         form != NULL;
         form = form->next) {
         form = form->next) {
      icache_tree *field;
      icache_tree *field;
      lf_printf(file, "    struct {\n");
      lf_printf(file, "    struct {\n");
      if (code & generate_with_insn_in_icache)
      if (code & generate_with_insn_in_icache)
        lf_printf(file, "      instruction_word insn;\n");
        lf_printf(file, "      instruction_word insn;\n");
      for (field = form->children;
      for (field = form->children;
           field != NULL;
           field != NULL;
           field = field->next) {
           field = field->next) {
        cache_table *cache_rule;
        cache_table *cache_rule;
        int found_rule = 0;
        int found_rule = 0;
        for (cache_rule = cache_rules;
        for (cache_rule = cache_rules;
             cache_rule != NULL;
             cache_rule != NULL;
             cache_rule = cache_rule->next) {
             cache_rule = cache_rule->next) {
          if (strcmp(field->name, cache_rule->field_name) == 0) {
          if (strcmp(field->name, cache_rule->field_name) == 0) {
            found_rule = 1;
            found_rule = 1;
            if (cache_rule->derived_name != NULL)
            if (cache_rule->derived_name != NULL)
              lf_printf(file, "      %s %s; /* %s */\n",
              lf_printf(file, "      %s %s; /* %s */\n",
                        (cache_rule->type_def == NULL
                        (cache_rule->type_def == NULL
                         ? "unsigned"
                         ? "unsigned"
                         : cache_rule->type_def),
                         : cache_rule->type_def),
                        cache_rule->derived_name,
                        cache_rule->derived_name,
                        cache_rule->field_name);
                        cache_rule->field_name);
          }
          }
        }
        }
        if (!found_rule)
        if (!found_rule)
          lf_printf(file, "      unsigned %s;\n", field->name);
          lf_printf(file, "      unsigned %s;\n", field->name);
      }
      }
      lf_printf(file, "    } %s;\n", form->name);
      lf_printf(file, "    } %s;\n", form->name);
    }
    }
    lf_printf(file, "  } crack;\n");
    lf_printf(file, "  } crack;\n");
    lf_printf(file, "} idecode_cache;\n");
    lf_printf(file, "} idecode_cache;\n");
  }
  }
  else {
  else {
    /* alernativly, since no cache, emit a dummy definition for
    /* alernativly, since no cache, emit a dummy definition for
       idecode_cache so that code refering to the type can still compile */
       idecode_cache so that code refering to the type can still compile */
    lf_printf(file, "typedef void idecode_cache;\n");
    lf_printf(file, "typedef void idecode_cache;\n");
  }
  }
  lf_printf(file, "\n");
  lf_printf(file, "\n");
}
}
 
 
 
 
 
 
static void
static void
print_icache_function(lf *file,
print_icache_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)
{
{
  int indent;
  int indent;
 
 
  /* generate code to enter decoded instruction into the icache */
  /* generate code to enter decoded instruction into the icache */
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", "\n");
  lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "EXTERN_ICACHE", "\n");
  indent = print_function_name(file,
  indent = print_function_name(file,
                               instruction->file_entry->fields[insn_name],
                               instruction->file_entry->fields[insn_name],
                               expanded_bits,
                               expanded_bits,
                               function_name_prefix_icache);
                               function_name_prefix_icache);
  lf_indent(file, +indent);
  lf_indent(file, +indent);
  lf_printf(file, "(%s)\n", ICACHE_FUNCTION_FORMAL);
  lf_printf(file, "(%s)\n", ICACHE_FUNCTION_FORMAL);
  lf_indent(file, -indent);
  lf_indent(file, -indent);
 
 
  /* function header */
  /* function header */
  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);
  print_itrace(file, instruction->file_entry, 1/*putting-value-in-cache*/);
  print_itrace(file, instruction->file_entry, 1/*putting-value-in-cache*/);
 
 
  print_idecode_validate(file, instruction, opcodes);
  print_idecode_validate(file, instruction, opcodes);
 
 
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_printf(file, "{\n");
  lf_printf(file, "{\n");
  lf_indent(file, +2);
  lf_indent(file, +2);
  if ((code & generate_with_semantic_icache))
  if ((code & generate_with_semantic_icache))
    lf_printf(file, "unsigned_word nia;\n");
    lf_printf(file, "unsigned_word nia;\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_semantic_icache)
                    ((code & generate_with_semantic_icache)
                     ? both_values_and_icache
                     ? both_values_and_icache
                     : put_values_in_icache));
                     : put_values_in_icache));
 
 
  lf_printf(file, "\n");
  lf_printf(file, "\n");
  lf_printf(file, "cache_entry->address = cia;\n");
  lf_printf(file, "cache_entry->address = cia;\n");
  lf_printf(file, "cache_entry->semantic = ");
  lf_printf(file, "cache_entry->semantic = ");
  print_function_name(file,
  print_function_name(file,
                      instruction->file_entry->fields[insn_name],
                      instruction->file_entry->fields[insn_name],
                      expanded_bits,
                      expanded_bits,
                      function_name_prefix_semantics);
                      function_name_prefix_semantics);
  lf_printf(file, ";\n");
  lf_printf(file, ";\n");
  lf_printf(file, "\n");
  lf_printf(file, "\n");
 
 
  if ((code & generate_with_semantic_icache)) {
  if ((code & generate_with_semantic_icache)) {
    lf_printf(file, "/* semantic routine */\n");
    lf_printf(file, "/* semantic routine */\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");
  }
  }
 
 
  if (!(code & generate_with_semantic_icache)) {
  if (!(code & generate_with_semantic_icache)) {
    lf_printf(file, "/* return the function proper */\n");
    lf_printf(file, "/* return the function proper */\n");
    lf_printf(file, "return ");
    lf_printf(file, "return ");
    print_function_name(file,
    print_function_name(file,
                        instruction->file_entry->fields[insn_name],
                        instruction->file_entry->fields[insn_name],
                        expanded_bits,
                        expanded_bits,
                        function_name_prefix_semantics);
                        function_name_prefix_semantics);
    lf_printf(file, ";\n");
    lf_printf(file, ";\n");
  }
  }
 
 
  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_semantic_icache)
                      ((code & generate_with_semantic_icache)
                       ? both_values_and_icache
                       ? both_values_and_icache
                       : put_values_in_icache));
                       : put_values_in_icache));
 
 
  lf_indent(file, -2);
  lf_indent(file, -2);
  lf_printf(file, "}\n");
  lf_printf(file, "}\n");
  lf_indent(file, -2);
  lf_indent(file, -2);
  lf_printf(file, "}\n");
  lf_printf(file, "}\n");
}
}
 
 
 
 
void
void
print_icache_definition(insn_table *entry,
print_icache_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_icache_function(file,
    print_icache_function(file,
                          entry->insns,
                          entry->insns,
                          entry->expanded_bits,
                          entry->expanded_bits,
                          entry->opcode,
                          entry->opcode,
                          cache_rules);
                          cache_rules);
  }
  }
  else {
  else {
    print_icache_function(file,
    print_icache_function(file,
                          instruction,
                          instruction,
                          NULL,
                          NULL,
                          NULL,
                          NULL,
                          cache_rules);
                          cache_rules);
  }
  }
}
}
 
 
 
 
 
 
void
void
print_icache_internal_function_declaration(insn_table *table,
print_icache_internal_function_declaration(insn_table *table,
                                           lf *file,
                                           lf *file,
                                           void *data,
                                           void *data,
                                           table_entry *function)
                                           table_entry *function)
{
{
  ASSERT((code & generate_with_icache) != 0);
  ASSERT((code & generate_with_icache) != 0);
  if (it_is("internal", function->fields[insn_flags])) {
  if (it_is("internal", function->fields[insn_flags])) {
    lf_printf(file, "\n");
    lf_printf(file, "\n");
    lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE",
    lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE",
                           "\n");
                           "\n");
    print_function_name(file,
    print_function_name(file,
                        function->fields[insn_name],
                        function->fields[insn_name],
                        NULL,
                        NULL,
                        function_name_prefix_icache);
                        function_name_prefix_icache);
    lf_printf(file, "\n(%s);\n", ICACHE_FUNCTION_FORMAL);
    lf_printf(file, "\n(%s);\n", ICACHE_FUNCTION_FORMAL);
  }
  }
}
}
 
 
 
 
void
void
print_icache_internal_function_definition(insn_table *table,
print_icache_internal_function_definition(insn_table *table,
                                          lf *file,
                                          lf *file,
                                          void *data,
                                          void *data,
                                          table_entry *function)
                                          table_entry *function)
{
{
  ASSERT((code & generate_with_icache) != 0);
  ASSERT((code & generate_with_icache) != 0);
  if (it_is("internal", function->fields[insn_flags])) {
  if (it_is("internal", function->fields[insn_flags])) {
    lf_printf(file, "\n");
    lf_printf(file, "\n");
    lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE",
    lf_print_function_type(file, ICACHE_FUNCTION_TYPE, "PSIM_INLINE_ICACHE",
                           "\n");
                           "\n");
    print_function_name(file,
    print_function_name(file,
                        function->fields[insn_name],
                        function->fields[insn_name],
                        NULL,
                        NULL,
                        function_name_prefix_icache);
                        function_name_prefix_icache);
    lf_printf(file, "\n(%s)\n", ICACHE_FUNCTION_FORMAL);
    lf_printf(file, "\n(%s)\n", ICACHE_FUNCTION_FORMAL);
    lf_printf(file, "{\n");
    lf_printf(file, "{\n");
    lf_indent(file, +2);
    lf_indent(file, +2);
    lf_printf(file, "/* semantic routine */\n");
    lf_printf(file, "/* semantic routine */\n");
    table_entry_print_cpp_line_nr(file, function);
    table_entry_print_cpp_line_nr(file, function);
    if ((code & generate_with_semantic_icache)) {
    if ((code & generate_with_semantic_icache)) {
      lf_print__c_code(file, function->annex);
      lf_print__c_code(file, function->annex);
      lf_printf(file, "error(\"Internal function must longjump\\n\");\n");
      lf_printf(file, "error(\"Internal function must longjump\\n\");\n");
      lf_printf(file, "return 0;\n");
      lf_printf(file, "return 0;\n");
    }
    }
    else {
    else {
      lf_printf(file, "return ");
      lf_printf(file, "return ");
      print_function_name(file,
      print_function_name(file,
                          function->fields[insn_name],
                          function->fields[insn_name],
                          NULL,
                          NULL,
                          function_name_prefix_semantics);
                          function_name_prefix_semantics);
      lf_printf(file, ";\n");
      lf_printf(file, ";\n");
    }
    }
 
 
    lf_print__internal_reference(file);
    lf_print__internal_reference(file);
    lf_indent(file, -2);
    lf_indent(file, -2);
    lf_printf(file, "}\n");
    lf_printf(file, "}\n");
  }
  }
}
}
 
 

powered by: WebSVN 2.1.0

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