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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [cr16/] [gencode.c] - Diff between revs 227 and 816

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

Rev 227 Rev 816
/* Simulation code for the CR16 processor.
/* Simulation code for the CR16 processor.
   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
   Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
   Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
 
 
   This file is part of GDB, the GNU debugger.
   This file is part of GDB, the GNU debugger.
 
 
   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 3, or (at your option)
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
   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, see <http://www.gnu.org/licenses/>.  */
   along with this program. If not, see <http://www.gnu.org/licenses/>.  */
 
 
 
 
#include "config.h"
#include "config.h"
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <limits.h>
#include <limits.h>
#include "ansidecl.h"
#include "ansidecl.h"
#include "opcode/cr16.h"
#include "opcode/cr16.h"
 
 
static void write_header PARAMS ((void));
static void write_header PARAMS ((void));
static void write_opcodes PARAMS ((void));
static void write_opcodes PARAMS ((void));
static void write_template PARAMS ((void));
static void write_template PARAMS ((void));
 
 
int
int
main (int argc, char *argv[])
main (int argc, char *argv[])
{
{
  if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
  if ((argc > 1) && (strcmp (argv[1],"-h") == 0))
    write_header();
    write_header();
  else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
  else if ((argc > 1) && (strcmp (argv[1],"-t") == 0))
    write_template ();
    write_template ();
  else
  else
    write_opcodes();
    write_opcodes();
  return 0;
  return 0;
}
}
 
 
 
 
static void
static void
write_header ()
write_header ()
{
{
  int i = 0;
  int i = 0;
 
 
  /* Start searching from end of instruction table.  */
  /* Start searching from end of instruction table.  */
  const inst *instruction = &cr16_instruction[NUMOPCODES - 1];
  const inst *instruction = &cr16_instruction[NUMOPCODES - 1];
 
 
  /* Loop over instruction table until a full match is found.  */
  /* Loop over instruction table until a full match is found.  */
  for ( ; i < NUMOPCODES; i++)
  for ( ; i < NUMOPCODES; i++)
  {
  {
   printf("void OP_%X_%X PARAMS ((void));\t\t/* %s */\n",cr16_instruction[i].match, (32 - cr16_instruction[i].match_bits), cr16_instruction[i].mnemonic);
   printf("void OP_%X_%X PARAMS ((void));\t\t/* %s */\n",cr16_instruction[i].match, (32 - cr16_instruction[i].match_bits), cr16_instruction[i].mnemonic);
  }
  }
}
}
 
 
 
 
/* write_template creates a file all required functions,
/* write_template creates a file all required functions,
   ready to be filled out.  */
   ready to be filled out.  */
 
 
static void
static void
write_template ()
write_template ()
{
{
  int i = 0,j, k, flags;
  int i = 0,j, k, flags;
 
 
  printf ("#include \"cr16_sim.h\"\n");
  printf ("#include \"cr16_sim.h\"\n");
  printf ("#include \"simops.h\"\n\n");
  printf ("#include \"simops.h\"\n\n");
 
 
  for ( ; i < NUMOPCODES; i++)
  for ( ; i < NUMOPCODES; i++)
    {
    {
      if (cr16_instruction[i].size != 0)
      if (cr16_instruction[i].size != 0)
{
{
  printf("/* %s */\nvoid\nOP_%X_%X ()\n{\n",cr16_instruction[i].mnemonic,cr16_instruction[i].match,(32 - cr16_instruction[i].match_bits));
  printf("/* %s */\nvoid\nOP_%X_%X ()\n{\n",cr16_instruction[i].mnemonic,cr16_instruction[i].match,(32 - cr16_instruction[i].match_bits));
 
 
  /* count operands.  */
  /* count operands.  */
  j = 0;
  j = 0;
  for (k=0;k<5;k++)
  for (k=0;k<5;k++)
    {
    {
      if (cr16_instruction[i].operands[k].op_type == dummy)
      if (cr16_instruction[i].operands[k].op_type == dummy)
                break;
                break;
              else
              else
                j++;
                j++;
    }
    }
  switch (j)
  switch (j)
    {
    {
    case 0:
    case 0:
      printf ("printf(\"   %s\\n\");\n",cr16_instruction[i].mnemonic);
      printf ("printf(\"   %s\\n\");\n",cr16_instruction[i].mnemonic);
      break;
      break;
    case 1:
    case 1:
      printf ("printf(\"   %s\\t%%x\\n\",OP[0]);\n",cr16_instruction[i].mnemonic);
      printf ("printf(\"   %s\\t%%x\\n\",OP[0]);\n",cr16_instruction[i].mnemonic);
      break;
      break;
    case 2:
    case 2:
      printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",cr16_instruction[i].mnemonic);
      printf ("printf(\"   %s\\t%%x,%%x\\n\",OP[0],OP[1]);\n",cr16_instruction[i].mnemonic);
      break;
      break;
    case 3:
    case 3:
      printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",cr16_instruction[i].mnemonic);
      printf ("printf(\"   %s\\t%%x,%%x,%%x\\n\",OP[0],OP[1],OP[2]);\n",cr16_instruction[i].mnemonic);
      break;
      break;
    default:
    default:
      fprintf (stderr,"Too many operands: %d\n",j);
      fprintf (stderr,"Too many operands: %d\n",j);
    }
    }
  printf ("}\n\n");
  printf ("}\n\n");
}
}
    }
    }
}
}
 
 
 
 
long Opcodes[512];
long Opcodes[512];
static int curop=0;
static int curop=0;
 
 
check_opcodes( long op)
check_opcodes( long op)
{
{
  int i;
  int i;
 
 
  for (i=0;i<curop;i++)
  for (i=0;i<curop;i++)
    if (Opcodes[i] == op)
    if (Opcodes[i] == op)
      fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
      fprintf(stderr,"DUPLICATE OPCODES: %x\n",op);
}
}
 
 
 
 
static void
static void
write_opcodes ()
write_opcodes ()
{
{
  int i = 0, j = 0, k;
  int i = 0, j = 0, k;
 
 
  /* write out opcode table.  */
  /* write out opcode table.  */
  printf ("#include \"cr16_sim.h\"\n");
  printf ("#include \"cr16_sim.h\"\n");
  printf ("#include \"simops.h\"\n\n");
  printf ("#include \"simops.h\"\n\n");
  printf ("struct simops Simops[] = {\n");
  printf ("struct simops Simops[] = {\n");
 
 
  for (i = NUMOPCODES-1; i >= 0; --i)
  for (i = NUMOPCODES-1; i >= 0; --i)
    {
    {
      if (cr16_instruction[i].size != 0)
      if (cr16_instruction[i].size != 0)
{
{
           printf ("  { \"%s\", %ld, %d, %d, %d, \"OP_%X_%X\", OP_%X_%X, ",
           printf ("  { \"%s\", %ld, %d, %d, %d, \"OP_%X_%X\", OP_%X_%X, ",
                    cr16_instruction[i].mnemonic, cr16_instruction[i].size,
                    cr16_instruction[i].mnemonic, cr16_instruction[i].size,
                    cr16_instruction[i].match_bits, cr16_instruction[i].match,
                    cr16_instruction[i].match_bits, cr16_instruction[i].match,
                     cr16_instruction[i].flags, ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)),
                     cr16_instruction[i].flags, ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)),
             (32 - cr16_instruction[i].match_bits),
             (32 - cr16_instruction[i].match_bits),
                     ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)), (32 - cr16_instruction[i].match_bits));
                     ((BIN(cr16_instruction[i].match, cr16_instruction[i].match_bits))>>(cr16_instruction[i].match_bits)), (32 - cr16_instruction[i].match_bits));
 
 
  j = 0;
  j = 0;
  for (k=0;k<5;k++)
  for (k=0;k<5;k++)
    {
    {
      if (cr16_instruction[i].operands[k].op_type == dummy)
      if (cr16_instruction[i].operands[k].op_type == dummy)
                break;
                break;
              else
              else
                j++;
                j++;
    }
    }
  printf ("%d, ",j);
  printf ("%d, ",j);
 
 
  j = 0;
  j = 0;
  for (k=0;k<4;k++)
  for (k=0;k<4;k++)
    {
    {
      int optype = cr16_instruction[i].operands[k].op_type;
      int optype = cr16_instruction[i].operands[k].op_type;
      int shift = cr16_instruction[i].operands[k].shift;
      int shift = cr16_instruction[i].operands[k].shift;
      if (j == 0)
      if (j == 0)
        printf ("{");
        printf ("{");
      else
      else
        printf (", ");
        printf (", ");
      printf ("{");
      printf ("{");
      printf ("%d,%d",optype, shift);
      printf ("%d,%d",optype, shift);
      printf ("}");
      printf ("}");
      j = 1;
      j = 1;
   }
   }
 if (j)
 if (j)
  printf ("}");
  printf ("}");
 printf ("},\n");
 printf ("},\n");
        }
        }
    }
    }
  printf (" { \"NULL\",1,8,0,0,\"OP_0_20\",OP_0_20,0,{0,0,0}},\n};\n");
  printf (" { \"NULL\",1,8,0,0,\"OP_0_20\",OP_0_20,0,{0,0,0}},\n};\n");
}
}
 
 

powered by: WebSVN 2.1.0

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