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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [sim-config.c] - Diff between revs 293 and 294

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

Rev 293 Rev 294
/* config.c -- Simulator configuration
/* config.c -- Simulator configuration
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
 
 
This file is part of OpenRISC 1000 Architectural Simulator.
This file is part of OpenRISC 1000 Architectural Simulator.
 
 
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
/* Simulator configuration. Eventually this one will be a lot bigger. */
/* Simulator configuration. Eventually this one will be a lot bigger. */
 
 
#include <stdlib.h>
#include <stdlib.h>
#include "sim-config.h"
#include "sim-config.h"
#include "abstract.h"
#include "abstract.h"
#include "spr_defs.h"
#include "spr_defs.h"
#include "pic.h"
#include "pic.h"
 
 
struct config config;
struct config config;
 
 
void init_defconfig()
void init_defconfig()
{
{
  unsigned long val;
  unsigned long val;
 
 
  memset(&config, 0, sizeof(config));
  memset(&config, 0, sizeof(config));
  /* Sim */
  /* Sim */
  config.script_file = "sim.cfg";
  config.script_file = "sim.cfg";
  config.sim.fprof = 0;
 
  strcpy (config.sim.prof_fn, "sim.profile");
  config.sim.exe_log = 0;
 
  config.sim.fexe_log = 0;
 
  strcpy (config.sim.exe_log_fn, "executed.log");
 
 
  config.sim.debug = 0;
  config.sim.debug = 0;
  config.sim.profile = 0;
 
  config.sim.verbose = 1;
  config.sim.verbose = 1;
  config.sim.iprompt = 0;
  config.sim.iprompt = 0;
 
 
 
  config.sim.profile = 0;
 
  config.sim.fprof = 0;
 
  strcpy (config.sim.prof_fn, "sim.profile");
 
 
  /* Memory */
  /* Memory */
  config.memory.type = MT_PATTERN;
  config.memory.type = MT_PATTERN;
  config.memory.pattern = 0;
  config.memory.pattern = 0;
  config.memory.random_seed = -1;  /* Generate new seed */
  config.memory.random_seed = -1;  /* Generate new seed */
  strcpy(config.memory.memory_table_file, "simmem.cfg");
  strcpy(config.memory.memory_table_file, "simmem.cfg");
 
 
  /* Memory Controller */
  /* Memory Controller */
  config.mc.enabled = 0;
  config.mc.enabled = 0;
 
 
  /* Uarts */
  /* Uarts */
  config.nuarts = 0;
  config.nuarts = 0;
  config.uarts_enabled = 0;
  config.uarts_enabled = 0;
 
 
  /* DMAs */
  /* DMAs */
  config.ndmas = 0;
  config.ndmas = 0;
  config.dmas_enabled = 0;
  config.dmas_enabled = 0;
 
 
  /* CPU */
  /* CPU */
  config.cpu.superscalar = 0;
  config.cpu.superscalar = 0;
  config.cpu.history = 0;
  config.cpu.history = 0;
  config.cpu.hazards = 0;
  config.cpu.hazards = 0;
  config.cpu.dependstats = 0;
  config.cpu.dependstats = 0;
  config.cpu.dependency = 0;
  config.cpu.dependency = 0;
  config.cpu.slp = 0;
  config.cpu.slp = 0;
  config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP
  config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP
                 | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP
                 | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP
                 | SPR_UPR_PMP | SPR_UPR_TTP;
                 | SPR_UPR_PMP | SPR_UPR_TTP;
 
 
  /* Debug */
  /* Debug */
  config.debug.enabled = 0;
  config.debug.enabled = 0;
  config.debug.gdb_enabled = 0;
  config.debug.gdb_enabled = 0;
  config.debug.server_port = 0;
  config.debug.server_port = 0;
 
 
  /* VAPI */
  /* VAPI */
  config.vapi.enabled = 0;
  config.vapi.enabled = 0;
 
 
  /* Old */
  /* Old */
  config.dc.tagtype = NONE/*VIRTUAL*/;
  config.dc.tagtype = NONE/*VIRTUAL*/;
  config.ic.tagtype = NONE/*VIRTUAL*/;
  config.ic.tagtype = NONE/*VIRTUAL*/;
  config.clkcycle_ns = 4; /* 4 for 4ns (250MHz) */
  config.clkcycle_ns = 4; /* 4 for 4ns (250MHz) */
  config.ethernets[0].baseaddr = 0x88000000;
  config.ethernets[0].baseaddr = 0x88000000;
  config.ethernets[0].dma = 0;
  config.ethernets[0].dma = 0;
  config.ethernets[0].tx_channel = 0;
  config.ethernets[0].tx_channel = 0;
  config.ethernets[0].rx_channel = 1;
  config.ethernets[0].rx_channel = 1;
  config.ethernets[0].rxfile = "/tmp/eth0.rx";
  config.ethernets[0].rxfile = "/tmp/eth0.rx";
  config.ethernets[0].txfile = "/tmp/eth0.tx";
  config.ethernets[0].txfile = "/tmp/eth0.tx";
}
}
 
 
int parse_args(int argc, char *argv[])
int parse_args(int argc, char *argv[])
{
{
  unsigned long val;
  unsigned long val;
 
 
  argv++; argc--;
  argv++; argc--;
  while (argc) {
  while (argc) {
    if (argc && (*argv[0] != '-')) {
    if (argc && (*argv[0] != '-')) {
      config.filename = argv[0];
      config.filename = argv[0];
      argc--;
      argc--;
      argv++;
      argv++;
    } else
    } else
    if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
    if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
      argv++; argc--;
      argv++; argc--;
      config.script_file = argv[0];
      config.script_file = argv[0];
      argv++; argc--;
      argv++; argc--;
    } else
    } else
    if (strcmp(*argv, "--nosrv") == 0) {  /* (CZ) */
    if (strcmp(*argv, "--nosrv") == 0) {  /* (CZ) */
      config.debug.gdb_enabled = 0;
      config.debug.gdb_enabled = 0;
      argv++; argc--;
      argv++; argc--;
    } else
    } else
    if (strcmp(*argv, "--srv") == 0) {  /* (CZ) */
    if (strcmp(*argv, "--srv") == 0) {  /* (CZ) */
      char *s;
      char *s;
      if(!--argc)
      if(!--argc)
        return 1;
        return 1;
      config.debug.enabled = 1;
      config.debug.enabled = 1;
      config.debug.gdb_enabled = 0;
      config.debug.gdb_enabled = 0;
      config.debug.server_port = strtol(*(++argv),&s,10);
      config.debug.server_port = strtol(*(++argv),&s,10);
      if(*s)
      if(*s)
        return 1;
        return 1;
      argv++; argc--;
      argv++; argc--;
    } else
    } else
    if (strcmp(*argv, "-i") == 0) {
    if (strcmp(*argv, "-i") == 0) {
      config.sim.iprompt = 1;
      config.sim.iprompt = 1;
      argv++; argc--;
      argv++; argc--;
    } else
    } else
    if (strcmp(*argv, "-v") == 0) {
    if (strcmp(*argv, "-v") == 0) {
      version();
      version();
      exit(0);
      exit(0);
    } else
    } else
    if (strcmp(*argv, "--profile") == 0) {
    if (strcmp(*argv, "--profile") == 0) {
      config.sim.profile = 1;
      config.sim.profile = 1;
      argv++; argc--;
      argv++; argc--;
    } else {
    } else {
      printf("Unknown option: %s\n", *argv);
      printf("Unknown option: %s\n", *argv);
      return 1;
      return 1;
    }
    }
  }
  }
 
 
  if (!argc)
  if (!argc)
    return 0;
    return 0;
 
 
  return 0;
  return 0;
}
}
 
 
 
#define CNV(x) ((isblank(x) || (x) == 0) ? ' ' : (x))
 
 
 
/* Substitute for less powerful fscanf */
 
int fscanf_ex (FILE *f, char *fmt, void *buf) {
 
  char tmp[STR_SIZE];
 
  char ch;
 
  int i = 0;
 
  while (*fmt) {
 
    switch (*fmt) {
 
      case '%':
 
        while(*fmt != 0 && !isalpha (*fmt))
 
          tmp[i++] = *(fmt++);
 
        tmp[i++] = *(fmt++);
 
        if (tmp[i - 1] == 's') {
 
          char *cbuf = (char *)buf;
 
          i = 0;
 
          while (ch = fgetc (f), isblank(ch))
 
            if (feof (f)) return 1;
 
          ungetc (ch, f);
 
          while ((*(cbuf++) = ch = fgetc (f), CNV(ch) ) != *fmt) {
 
            if (feof (f)) return 1;
 
            if (++i >= STR_SIZE) {
 
              fprintf (stderr, "ERROR: string too long.\n");
 
              return 1;
 
            }
 
          }
 
          *(--cbuf) = 0;
 
          fmt++;
 
        } else {
 
          tmp[i++] = 0;
 
          fscanf (f, tmp, buf);
 
        }
 
        break;
 
      default:
 
        while ((ch = fgetc (f)) != *fmt) {
 
          if (!isblank (ch))
 
            fprintf (stderr, "WARNING: unexpected char '%c' (expecting '%c')\n", ch, *fmt);
 
          if (feof (f)) return 1;
 
        }
 
        fmt++;
 
        break;
 
    }
 
  }
 
  return 0;
 
}
 
 
void print_config()
void print_config()
{
{
  printf("Machine initialization...\n");
  printf("Machine initialization...\n");
  if (testsprbits(SPR_UPR, SPR_UPR_DCP))
  if (testsprbits(SPR_UPR, SPR_UPR_DCP))
    printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
    printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
  else
  else
    printf("No data cache.\n");
    printf("No data cache.\n");
  if (testsprbits(SPR_UPR, SPR_UPR_ICP))
  if (testsprbits(SPR_UPR, SPR_UPR_ICP))
    printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
    printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
  else
  else
    printf("No instruction cache.\n");
    printf("No instruction cache.\n");
  /*if (config.cpu.bpb_sim)
  /*if (config.cpu.bpb_sim)
    printf("BPB simulation on.\n");
    printf("BPB simulation on.\n");
  else
  else
    printf("BPB simulation off.\n");
    printf("BPB simulation off.\n");
  if (config.cpu.btic_sim)
  if (config.cpu.btic_sim)
    printf("BTIC simulation on.\n");
    printf("BTIC simulation on.\n");
  else
  else
    printf("BTIC simulation off.\n");*/
    printf("BTIC simulation off.\n");*/
  printf("Clock cycle: %d ns\n", config.clkcycle_ns);
  printf("Clock cycle: %d ns\n", config.clkcycle_ns);
 
 
  if (config.sim.debug)
  if (config.sim.debug)
    printf("simdebug on, ");
    printf("simdebug on, ");
  else
  else
    printf("simdebug off, ");
    printf("simdebug off, ");
  if (config.sim.iprompt)
  if (config.sim.iprompt)
    printf("interactive prompt on\n");
    printf("interactive prompt on\n");
  else
  else
    printf("interactive prompt off\n");
    printf("interactive prompt off\n");
}
}
 
 
void change_device ();
void change_device ();
void end_device ();
void end_device ();
void uart_baseaddr ();
void uart_baseaddr ();
void uart_rxfile ();
void uart_rxfile ();
void uart_txfile ();
void uart_txfile ();
void uart_jitter ();
void uart_jitter ();
void dma_baseaddr ();
void dma_baseaddr ();
void dma_irq ();
void dma_irq ();
void memory_type ();
void memory_type ();
 
 
char memory_file[256] = "sim.mem";
char memory_file[256] = "sim.mem";
 
 
struct section {
struct section {
  char *name;
  char *name;
  int flags;
  int flags;
} sections[] = {
} sections[] = {
  {"",       0},
  {"",       0},
  {"mc",     0},
  {"mc",     0},
  {"uart",   0},
  {"uart",   0},
  {"dma",    0},
  {"dma",    0},
  {"memory", 0},
  {"memory", 0},
  {"cpu",    0},
  {"cpu",    0},
  {"sim",    0},
  {"sim",    0},
  {"debug",  0},
  {"debug",  0},
  {"VAPI",   0}
  {"VAPI",   0}
};
};
 
 
unsigned long tempL;
unsigned long tempL;
unsigned long tempUL;
unsigned long tempUL;
char tempS[STR_SIZE];
char tempS[STR_SIZE];
 
 
#define CPF_SUBSECTION 1
#define CPF_SUBSECTION 1
#define CPF_SUBFIELD   2
#define CPF_SUBFIELD   2
 
 
/* Parameter definitions */
/* Parameter definitions */
struct config_params {
struct config_params {
  int section;
  int section;
  char *name;
  char *name;
  char *type;
  char *type;
  void (*func)();
  void (*func)();
  void *addr;
  void *addr;
} config_params[] = {
} config_params[] = {
  {1, "enabled",            "= %i",        NULL,          (void *)(&config.mc.enabled)},
  {1, "enabled",            "=%i",         NULL,          (void *)(&config.mc.enabled)},
  {1, "baseaddr",           "= 0x%x",      NULL,          (void *)(&config.mc.baseaddr)},
  {1, "baseaddr",           "=0x%x",       NULL,          (void *)(&config.mc.baseaddr)},
  {1, "POC",                "= 0x%x",      NULL,          (void *)(&config.mc.POC)},
  {1, "POC",                "=0x%x",       NULL,          (void *)(&config.mc.POC)},
 
 
  {2, "enabled",            "= %i",        NULL,          (void *)(&config.uarts_enabled)},
  {2, "enabled",            "=%i",         NULL,          (void *)(&config.uarts_enabled)},
  {2, "nuarts",             "= %i",        NULL,          (void *)(&config.nuarts)},
  {2, "nuarts",             "=%i",         NULL,          (void *)(&config.nuarts)},
  {2, "device",             "%i",          change_device, (void *)(&tempL)},
  {2, "device",             "%i",          change_device, (void *)(&tempL)},
  {2, "enddevice",          "",            end_device,    NULL},
  {2, "enddevice",          "",            end_device,    NULL},
  {2, "baseaddr",           "= 0x%x",      uart_baseaddr, (void *)(&tempUL)},
  {2, "baseaddr",           "=0x%x",       uart_baseaddr, (void *)(&tempUL)},
  {2, "jitter",             "= %i",        uart_jitter,   (void *)(&tempL)},
  {2, "jitter",             "= %i",        uart_jitter,   (void *)(&tempL)},
  {2, "rxfile",             "= \"%255s\"", uart_rxfile,   (void *)(&tempS[0])},
  {2, "rxfile",             "=\"%s\"",     uart_rxfile,   (void *)(&tempS[0])},
  {2, "txfile",             "= \"%255s\"", uart_txfile,   (void *)(&tempS[0])},
  {2, "txfile",             "=\"%s\"",     uart_txfile,   (void *)(&tempS[0])},
 
 
  {3, "enabled",            "= %i",        NULL,          (void *)(&config.dmas_enabled)},
  {3, "enabled",            "=%i",         NULL,          (void *)(&config.dmas_enabled)},
  {3, "ndmas",              "= %i",        NULL,          (void *)(&config.ndmas)},
  {3, "ndmas",              "=%i",         NULL,          (void *)(&config.ndmas)},
  {3, "device",             "%i",          change_device, (void *)(&tempL)},
  {3, "device",             "%i",          change_device, (void *)(&tempL)},
  {3, "enddevice",          "",            end_device,    NULL},
  {3, "enddevice",          "",            end_device,    NULL},
  {3, "baseaddr",           "= 0x%x",      dma_baseaddr,  (void *)(&tempUL)},
  {3, "baseaddr",           "=0x%x",       dma_baseaddr,  (void *)(&tempUL)},
  {3, "irq",                "= %i",        dma_baseaddr,  (void *)(&tempL)},
  {3, "irq",                "=%i",         dma_baseaddr,  (void *)(&tempL)},
 
 
  {4, "memory_table_file",  "= \"%255s\"", NULL,          (void *)(&config.memory.memory_table_file[0])},
  {4, "memory_table_file",  "=\"%s\"",     NULL,          (void *)(&config.memory.memory_table_file[0])},
  {4, "random_seed",        "= %i",        NULL,          (void *)(&config.memory.random_seed)},
  {4, "random_seed",        "= %i",        NULL,          (void *)(&config.memory.random_seed)},
  {4, "pattern",            "= %i",        NULL,          (void *)(&config.memory.pattern)},
  {4, "pattern",            "= %i",        NULL,          (void *)(&config.memory.pattern)},
  {4, "type",               "= %255s",     memory_type,   (void *)(&tempS[0])},
  {4, "type",               "=%s ",        memory_type,   (void *)(&tempS[0])},
 
 
  {5, "ver",                "= 0x%x",      NULL,          (void *)(&config.cpu.ver)},
  {5, "ver",                "=0x%x",       NULL,          (void *)(&config.cpu.ver)},
  {5, "rev",                "= 0x%x",      NULL,          (void *)(&config.cpu.rev)},
  {5, "rev",                "=0x%x",       NULL,          (void *)(&config.cpu.rev)},
  {5, "upr",                "= 0x%x",      NULL,          (void *)(&config.cpu.upr)},
  {5, "upr",                "=0x%x",       NULL,          (void *)(&config.cpu.upr)},
  {5, "hazards",            "= %i",        NULL,          (void *)(&config.cpu.hazards)},
  {5, "hazards",            "=%i",         NULL,          (void *)(&config.cpu.hazards)},
  {5, "history",            "= %i",        NULL,          (void *)(&config.cpu.history)},
  {5, "history",            "=%i",         NULL,          (void *)(&config.cpu.history)},
  {5, "superscalar",        "= %i",        NULL,          (void *)(&config.cpu.superscalar)},
  {5, "superscalar",        "=%i",         NULL,          (void *)(&config.cpu.superscalar)},
  {5, "dependstats",        "= %i",        NULL,          (void *)(&config.cpu.dependstats)},
  {5, "dependstats",        "=%i",         NULL,          (void *)(&config.cpu.dependstats)},
  {5, "dependency",         "= %i",        NULL,          (void *)(&config.cpu.dependency)},
  {5, "dependency",         "=%i",         NULL,          (void *)(&config.cpu.dependency)},
  {5, "slp",                "= %i",        NULL,          (void *)(&config.cpu.slp)},
  {5, "slp",                "=%i",         NULL,          (void *)(&config.cpu.slp)},
  {5, "bpb",                "= %i",        NULL,          (void *)(&config.cpu.bpb)},
  {5, "bpb",                "=%i",         NULL,          (void *)(&config.cpu.bpb)},
  {5, "btic_sim",           "= %i",        NULL,          (void *)(&config.cpu.btic_sim)},
  {5, "btic_sim",           "=%i",         NULL,          (void *)(&config.cpu.btic_sim)},
 
 
  {6, "debug",              "= %i",        NULL,          (void *)(&config.sim.debug)},
  {6, "debug",              "= %i",        NULL,          (void *)(&config.sim.debug)},
  {6, "prof_fn",            "= \"%255s\"", NULL,          (void *)(&config.sim.prof_fn[0])},
 
  {6, "profile",            "= %i",        NULL,          (void *)(&config.sim.profile)},
 
  {6, "iprompt",            "= %i",        NULL,          (void *)(&config.sim.iprompt)},
  {6, "iprompt",            "= %i",        NULL,          (void *)(&config.sim.iprompt)},
  {6, "verbose",            "= %i",        NULL,          (void *)(&config.sim.verbose)},
  {6, "verbose",            "= %i",        NULL,          (void *)(&config.sim.verbose)},
 
  {6, "profile",            "=%i",         NULL,          (void *)(&config.sim.profile)},
 
  {6, "prof_fn",            "=\"%s\"",     NULL,          (void *)(&config.sim.prof_fn[0])},
 
 
 
  {6, "exe_log",            "=%i",         NULL,          (void *)(&config.sim.exe_log)},
 
  {6, "exe_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.exe_log_fn[0])},
 
 
  {7, "enabled",            "= %i",        NULL,          (void *)(&config.debug.enabled)},
  {7, "enabled",            "=%i",         NULL,          (void *)(&config.debug.enabled)},
  {7, "gdb_enabled",        "= %i",        NULL,          (void *)(&config.debug.gdb_enabled)},
  {7, "gdb_enabled",        "=%i",         NULL,          (void *)(&config.debug.gdb_enabled)},
  {7, "server_port",        "= %i",        NULL,          (void *)(&config.debug.server_port)},
  {7, "server_port",        "=%i",         NULL,          (void *)(&config.debug.server_port)},
 
 
  {8, "enabled",            "= %i",        NULL,          (void *)(&config.vapi.enabled)}
  {8, "enabled",            "=%i",         NULL,          (void *)(&config.vapi.enabled)}
};
};
 
 
int current_device = -1;
int current_device = -1;
void change_device () {
void change_device () {
  current_device = tempL;
  current_device = tempL;
}
}
 
 
void end_device () {
void end_device () {
  current_device = -1;
  current_device = -1;
}
}
 
 
void uart_baseaddr () {
void uart_baseaddr () {
  if (current_device >= 0 && current_device < config.nuarts)
  if (current_device >= 0 && current_device < config.nuarts)
    config.uarts[current_device].baseaddr = tempUL;
    config.uarts[current_device].baseaddr = tempUL;
  else {
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
    exit (-1);
  }
  }
}
}
 
 
void uart_jitter () {
void uart_jitter () {
  if (current_device >= 0 && current_device < config.nuarts)
  if (current_device >= 0 && current_device < config.nuarts)
    config.uarts[current_device].jitter = tempL;
    config.uarts[current_device].jitter = tempL;
  else {
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
    exit (-1);
  }
  }
}
}
 
 
void uart_rxfile () {
void uart_rxfile () {
  if (current_device >= 0 && current_device < config.nuarts)
  if (current_device >= 0 && current_device < config.nuarts)
    strcpy (config.uarts[current_device].rxfile, tempS);
    strcpy (config.uarts[current_device].rxfile, tempS);
  else {
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
    exit (-1);
  }
  }
}
}
 
 
void uart_txfile () {
void uart_txfile () {
  if (current_device >= 0 && current_device < config.nuarts)
  if (current_device >= 0 && current_device < config.nuarts)
    strcpy (config.uarts[current_device].txfile, tempS);
    strcpy (config.uarts[current_device].txfile, tempS);
  else {
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
    exit (-1);
  }
  }
}
}
 
 
void dma_baseaddr () {
void dma_baseaddr () {
  if (current_device >= 0 && current_device < config.ndmas)
  if (current_device >= 0 && current_device < config.ndmas)
    config.dmas[current_device].baseaddr = tempUL;
    config.dmas[current_device].baseaddr = tempUL;
  else {
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
    exit (-1);
  }
  }
}
}
 
 
void dma_irq () {
void dma_irq () {
  if (current_device >= 0 && current_device < config.ndmas)
  if (current_device >= 0 && current_device < config.ndmas)
    config.dmas[current_device].irq = tempL;
    config.dmas[current_device].irq = tempL;
  else {
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
    exit (-1);
  }
  }
}
}
 
 
void memory_type () {
void memory_type () {
  if (strcmp (tempS, "unknown") == 0)
  if (strcmp (tempS, "unknown") == 0)
    config.memory.type = MT_UNKNOWN;
    config.memory.type = MT_UNKNOWN;
  else if (strcmp (tempS, "random") == 0)
  else if (strcmp (tempS, "random") == 0)
    config.memory.type = MT_RANDOM;
    config.memory.type = MT_RANDOM;
  else if (strcmp (tempS, "pattern") == 0)
  else if (strcmp (tempS, "pattern") == 0)
    config.memory.type = MT_PATTERN;
    config.memory.type = MT_PATTERN;
  else if (strcmp (tempS, "zero") == 0) {
  else if (strcmp (tempS, "zero") == 0) {
    config.memory.type = MT_PATTERN;
    config.memory.type = MT_PATTERN;
    config.memory.pattern = 0;
    config.memory.pattern = 0;
  } else {
  } else {
    fprintf (stderr, "ERROR: invalid memory type '%s'.\n", tempS);
    fprintf (stderr, "ERROR: invalid memory type '%s'.\n", tempS);
    exit (-1);
    exit (-1);
  }
  }
}
}
 
 
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
   The syntax of script file is:
   The syntax of script file is:
   param = value
   param = value
   section x
   section x
     data
     data
     param = value
     param = value
   end
   end
 
 
   Example:
   Example:
   section mc
   section mc
     memory_table_file = sim.mem
     memory_table_file = sim.mem
     enable = 1
     enable = 1
     POC = 0x47892344
     POC = 0x47892344
   end
   end
 
 
 */
 */
 
 
void read_script_file (char *filename)
void read_script_file (char *filename)
{
{
  FILE *f;
  FILE *f;
  unsigned long memory_needed = 0;
  unsigned long memory_needed = 0;
  char *home = getenv("HOME");
  char *home = getenv("HOME");
  char ctmp[STR_SIZE];
  char ctmp[STR_SIZE];
  int local = 1;
  int local = 1;
  int section = 0;
  int section = 0;
 
 
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
  if ((f = fopen (filename, "rt")) != NULL
  if ((f = fopen (filename, "rt")) != NULL
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
    unsigned long start, length;
    unsigned long start, length;
    char type[STR_SIZE];
    char type[STR_SIZE];
    int nparam;
    int nparam;
    int rd, wd;
    int rd, wd;
    printf ("Reading script file from '%s':\n", local ? filename : ctmp);
    printf ("Reading script file from '%s':\n", local ? filename : ctmp);
    while (!feof(f)) {
    while (!feof(f)) {
      char param[STR_SIZE];
      char param[STR_SIZE];
      if (fscanf(f, "%s ", &param) != 1) break;
      if (fscanf(f, "%s ", &param) != 1) break;
      /* Is this a sections? */
      /* Is this a sections? */
      if (strcmp (param, "section") == 0) {
      if (strcmp (param, "section") == 0) {
        int i;
        int i;
        section = 0;
        section = 0;
        if (fscanf (f, "%s\n", &param) != 1) {
        if (fscanf (f, "%s\n", &param) != 1) {
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
          exit (-1);
          exit (-1);
        }
        }
        for (i = 1; i < sizeof(sections) / sizeof(char *); i++)
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
          if (strcmp (sections[i].name, param) == 0) {
          if (strcmp (sections[i].name, param) == 0) {
            section = i;
            section = i;
            break;
            break;
          }
          }
        if (!section) {
        if (!section) {
          fprintf (stderr, "%s: WARNING: Unknown section: %s; ignoring.\n", local ? filename : ctmp, param);
          fprintf (stderr, "%s: WARNING: Unknown section: %s; ignoring.\n", local ? filename : ctmp, param);
          /* just skip section */
          /* just skip section */
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
        }
        }
      } else if (strcmp (param, "end") == 0) {
      } else if (strcmp (param, "end") == 0) {
        section = 0;
        section = 0;
      } else if (strncmp (param, "/*", 2) == 0) {
      } else if (strncmp (param, "/*", 2) == 0) {
        char c0 = 0, c1 = 0;
        char c0 = 0, c1 = 0;
        while (c0 != '*' || c1 != '/') {
        while (c0 != '*' || c1 != '/') {
          c0 = c1;
          c0 = c1;
          c1 = fgetc(f);
          c1 = fgetc(f);
          if (feof(f)) {
          if (feof(f)) {
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
            exit (-1);
            exit (-1);
          }
          }
        }
        }
      } else {
      } else {
        int i, found = -1;
        int i, found = -1;
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
            found = i;
            found = i;
            break;
            break;
          }
          }
        if (found < 0) {
        if (found < 0) {
          fprintf (stderr, "%s: WARNING: Invalid parameter: %s; ignoring.\n", local ? filename : ctmp, param);
          fprintf (stderr, "%s: WARNING: Invalid parameter: %s; ignoring.\n", local ? filename : ctmp, param);
          while (fgetc(f) != '\n' || feof(f));
          while (fgetc(f) != '\n' || feof(f));
          continue;
          continue;
        }
        }
 
 
        /* Parse parameter value */
        /* Parse parameter value */
        {
        {
          char fmt[STR_SIZE];
          if (config_params[found].type[0])
          if (config_params[found].type[0]) {
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr))
            sprintf (fmt, "%s\n", config_params[found].type);
              exit (1);
            fscanf (f, fmt, config_params[found].addr);
 
          }
 
        }
        }
        if (config_params[found].func)
        if (config_params[found].func)
          config_params[found].func();
          config_params[found].func();
      }
      }
    }
    }
    fclose (f);
    fclose (f);
  } else {
  } else {
    fprintf (stderr, "Cannot read script file from '%s',\nneither '%s'; assuming standard configuration.\n", filename, ctmp);
    fprintf (stderr, "Cannot read script file from '%s',\nneither '%s'; assuming standard configuration.\n", filename, ctmp);
  }
  }
 
 
  /* Initialize memory table.  */
  /* Initialize memory table.  */
  sim_read_memory_table (config.memory.memory_table_file);
  sim_read_memory_table (config.memory.memory_table_file);
}
}
 
 

powered by: WebSVN 2.1.0

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