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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_34/] [or1ksim/] [cuc/] [load.c] - Diff between revs 1062 and 1308

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 1062 Rev 1308
Line 19... Line 19...
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdarg.h>
#include <assert.h>
#include <assert.h>
 
#include <string.h>
 
 
 
#include "abstract.h"
#include "sim-config.h"
#include "sim-config.h"
#include "cuc.h"
#include "cuc.h"
#include "opcode/or32.h"
#include "opcode/or32.h"
#include "insn.h"
#include "insn.h"
 
 
Line 65... Line 68...
int reloc[MAX_INSNS];
int reloc[MAX_INSNS];
 
 
/* Prints out instructions */
/* Prints out instructions */
void print_cuc_insns (char *s, int verbose)
void print_cuc_insns (char *s, int verbose)
{
{
  int i, j;
 
  PRINTF ("****************** %s ******************\n", s);
  PRINTF ("****************** %s ******************\n", s);
  print_insns (0, insn, num_insn,verbose);
  print_insns (0, insn, num_insn,verbose);
  PRINTF ("\n\n");
  PRINTF ("\n\n");
}
}
 
 
Line 135... Line 137...
}
}
 
 
/* Convert local variables (uses stack frame -- r1) to internal values */
/* Convert local variables (uses stack frame -- r1) to internal values */
void detect_locals ()
void detect_locals ()
{
{
  int stack[MAX_STACK];
  int stack[CUC_MAX_STACK];
  int i, can_remove_stack = 1;
  int i, can_remove_stack = 1;
  int real_stack_size = 0;
  int real_stack_size = 0;
 
 
  for (i = 0; i < MAX_STACK; i++) stack[i] = -1;
  for (i = 0; i < CUC_MAX_STACK; i++) stack[i] = -1;
 
 
  for (i = 0; i < num_insn; i++) {
  for (i = 0; i < num_insn; i++) {
    /* sw off (r1),rx */
    /* sw off (r1),rx */
    if (insn[i].index == II_SW
    if (insn[i].index == II_SW
      && (insn[i].opt[0] & OPT_CONST)
      && (insn[i].opt[0] & OPT_CONST)
      && insn[i].op[1] == 1 && (insn[i].opt[1] & OPT_REGISTER)) {
      && insn[i].op[1] == 1 && (insn[i].opt[1] & OPT_REGISTER)) {
 
 
      if (insn[i].op[0] < MAX_STACK/* && insn[i].op[1] >= 4*/) { /* Convert to normal move */
      if (insn[i].op[0] < CUC_MAX_STACK/* && insn[i].op[1] >= 4*/) { /* Convert to normal move */
        stack[insn[i].op[0]] = i;
        stack[insn[i].op[0]] = i;
        insn[i].type &= IT_INDELAY | IT_BBSTART;
        insn[i].type &= IT_INDELAY | IT_BBSTART;
        change_insn_type (&insn[i], II_ADD);
        change_insn_type (&insn[i], II_ADD);
        insn[i].op[0] = -1; insn[i].opt[0] = OPT_REGISTER | OPT_DEST;
        insn[i].op[0] = -1; insn[i].opt[0] = OPT_REGISTER | OPT_DEST;
        insn[i].op[1] = insn[i].op[2]; insn[i].opt[1] = insn[i].opt[2];
        insn[i].op[1] = insn[i].op[2]; insn[i].opt[1] = insn[i].opt[2];
Line 160... Line 162...
    /* lw rx,off (r1) */
    /* lw rx,off (r1) */
    } else if (insn[i].index == II_LW
    } else if (insn[i].index == II_LW
      && (insn[i].opt[1] & OPT_CONST)
      && (insn[i].opt[1] & OPT_CONST)
      && insn[i].op[2] == 1 && (insn[i].opt[2] & OPT_REGISTER)) {
      && insn[i].op[2] == 1 && (insn[i].opt[2] & OPT_REGISTER)) {
 
 
      if (insn[i].op[1] < MAX_STACK && stack[insn[i].op[1]] >= 0) { /* Convert to normal move */
      if (insn[i].op[1] < CUC_MAX_STACK && stack[insn[i].op[1]] >= 0) { /* Convert to normal move */
        insn[i].type &= IT_INDELAY | IT_BBSTART;
        insn[i].type &= IT_INDELAY | IT_BBSTART;
        change_insn_type (&insn[i], II_ADD);
        change_insn_type (&insn[i], II_ADD);
        insn[i].op[1] = stack[insn[i].op[1]]; insn[i].opt[1] = OPT_REF;
        insn[i].op[1] = stack[insn[i].op[1]]; insn[i].opt[1] = OPT_REF;
        insn[i].op[2] = 0; insn[i].opt[2] = OPT_CONST;
        insn[i].op[2] = 0; insn[i].opt[2] = OPT_CONST;
      } else can_remove_stack = 0;
      } else can_remove_stack = 0;
Line 198... Line 200...
  strcpy (insn->disasm, disassembled);
  strcpy (insn->disasm, disassembled);
  insn->dep = NULL;
  insn->dep = NULL;
  for (i = 0; i < MAX_OPERANDS; i++) insn->opt[i] = OPT_NONE;
  for (i = 0; i < MAX_OPERANDS; i++) insn->opt[i] = OPT_NONE;
 
 
  if (index < 0) {
  if (index < 0) {
    fprintf (stderr, "Invalid opcode 0x%08x!\n", data);
    fprintf (stderr, "Invalid opcode 0x%08lx!\n", data);
    exit (1);
    exit (1);
  }
  }
  opcode = &or32_opcodes[index];
  opcode = &or32_opcodes[index];
 
 
  for (s = opcode->args; *s != '\0'; ++s) {
  for (s = opcode->args; *s != '\0'; ++s) {
Line 408... Line 410...
 
 
/* Loads function from file into global array insn.
/* Loads function from file into global array insn.
   Function returns nonzero if function cannot be converted. */
   Function returns nonzero if function cannot be converted. */
int cuc_load (char *in_fn)
int cuc_load (char *in_fn)
{
{
  int i, j, in_delay;
  int i, j;
  FILE *fi;
  FILE *fi;
  int func_return = 0;
  int func_return = 0;
  num_insn = 0;
  num_insn = 0;
 
 
  log ("Loading filename %s\n", in_fn);
  log ("Loading filename %s\n", in_fn);
Line 421... Line 423...
    exit (1);
    exit (1);
  }
  }
  /* Read in the function and decode the instructions */
  /* Read in the function and decode the instructions */
  for (i = 0;; i++) {
  for (i = 0;; i++) {
    unsigned long data;
    unsigned long data;
    extern char *disassembled;
 
    const char *name;
    const char *name;
 
 
    if (fscanf (fi, "%08x\n", &data) != 1) break;
    if (fscanf (fi, "%08lx\n", &data) != 1) break;
 
 
    /* build params */
    /* build params */
    name = build_insn (data, &insn[i]);
    name = build_insn (data, &insn[i]);
    if (func_return) func_return++;
    if (func_return) func_return++;
    //PRINTF ("%s\n", name);
    //PRINTF ("%s\n", name);
Line 463... Line 464...
      }
      }
    } else {
    } else {
      insn[i].index = -1;
      insn[i].index = -1;
      for (j = 0; j < sizeof (conv) / sizeof (cuc_conv); j++)
      for (j = 0; j < sizeof (conv) / sizeof (cuc_conv); j++)
        if (strcmp (conv[j].from, name) == 0) {
        if (strcmp (conv[j].from, name) == 0) {
          const int x = conv[j].to;
 
          if (conv[j].to & II_SIGNED) insn[i].type |= IT_SIGNED;
          if (conv[j].to & II_SIGNED) insn[i].type |= IT_SIGNED;
          if (conv[j].to & II_MEM) insn[i].type |= IT_MEMORY | IT_VOLATILE;
          if (conv[j].to & II_MEM) insn[i].type |= IT_MEMORY | IT_VOLATILE;
          change_insn_type (&insn[i], conv[j].to & II_MASK);
          change_insn_type (&insn[i], conv[j].to & II_MASK);
          break;
          break;
        }
        }

powered by: WebSVN 2.1.0

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