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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [sim-config.c] - Rev 261

Go to most recent revision | Compare with Previous | Blame | View Log

/* config.c -- Simulator configuration
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
/* Simulator configuration. Eventually this one will be a lot bigger. */
 
#include <stdlib.h>
#include "sim-config.h"
#include "abstract.h"
#include "spr_defs.h"
#include "pic.h"
 
struct config config;
 
void init_defconfig()
{
  unsigned long val;
 
  memset(&config, 0, sizeof(config));
  config.dc.tagtype = NONE/*VIRTUAL*/;
  config.ic.tagtype = NONE/*VIRTUAL*/;
  config.bp.bpb_sim = 1;
  config.bp.btic_sim = 1;
  config.clkcycle_ns = 4; /* 4 for 4ns (250MHz) */
  strcpy (config.uarts[0].rxfile, "/tmp/uart0.rx");
  strcpy (config.uarts[0].txfile, "/tmp/uart0.tx");
  config.uarts[0].baseaddr = 0x80000000;
  config.uarts[0].jitter = -1; /* Async behavior */
  config.dmas[0].baseaddr = 0x90000000;
  config.dmas[0].irq = INT_DMA;
	config.ethernets[0].baseaddr = 0x88000000;
	config.ethernets[0].dma = 0;
	config.ethernets[0].tx_channel = 0;
	config.ethernets[0].rx_channel = 1;
	config.ethernets[0].rxfile = "/tmp/eth0.rx";
	config.ethernets[0].txfile = "/tmp/eth0.tx";
  config.simdebug = 0;
  config.profile = 0;
  config.iprompt = 0;
  config.dependstats = 1;
  config.dependency = 1;
  config.history = 1;
  config.superscalar = 1;
  config.slp = 1;
  config.profile = 0;
 
  config.mc.enabled = 0;
  strcpy(config.mc.memory_table_file, "sim.mem");
 
  mtspr(SPR_VR, SPR_VR_VER & 0x1200);
 
  val = 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_PMP | SPR_UPR_TTP;
 
  mtspr(SPR_UPR, val);
}
 
int parse_args(int argc, char *argv[])
{
  unsigned long val;
 
  argv++; argc--;
  while (argc) {
    if (argc && (*argv[0] != '-')) {
      config.filename = argv[0];
      argc--;
      argv++;
    } else
    if (strcmp(*argv, "-initmem") == 0) {  /* (CZ) */
      char *pattern,*s;
      if(!--argc)
        return 1;
      pattern = *(++argv);
      if(!strcmp(pattern,"random"))
        config.random_mem = 1;
      else
        {
          val = strtol(pattern,&s,0);
          if(*s)
            return 1;
          config.pattern_mem = val;
        }
    } else
    if (strcmp(*argv, "-nosrv") == 0) {  /* (CZ) */
      config.inhibit_server = 1;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-srv") == 0) {  /* (CZ) */
      char *s;
      if(!--argc)
        return 1;
      config.server_port = strtol(*(++argv),&s,10);
      if(*s)
        return 1;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-i") == 0) {
      config.iprompt = 1;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-v") == 0) {
      version();
      exit(0);
    } else
    if (strcmp(*argv, "-bpb") == 0) {
      config.bp.bpb_sim = 0;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-hazards") == 0) {
      config.dependstats = 0;
      config.dependency = 0;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-history") == 0) {
      config.history = 0;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-superscalar") == 0) {
      config.superscalar = 0;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-fast") == 0) {
      config.superscalar = 0;
      config.history = 0;
      config.dependstats = 0;
      config.dependency = 0;
      config.bp.bpb_sim = 0;
      config.bp.btic_sim = 0;
      config.slp = 0;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-btic") == 0) {
      config.bp.btic_sim = 0;
      argv++; argc--;
    } else
    if (strcmp(*argv, "-upr") == 0) {
      argv++; argc--;
      val = strtoul(*argv, NULL, 0);
      mtspr(SPR_UPR, val);
      argv++; argc--;
    } else
    if (strcmp(*argv, "-ver") == 0) {
      argv++; argc--;
      val = strtoul(*argv, NULL, 0);
      setsprbits(SPR_VR, SPR_VR_VER, val);
      argv++; argc--;
    } else
    if (strcmp(*argv, "-rev") == 0) {
      argv++; argc--;
      val = strtoul(*argv, NULL, 0);
      setsprbits(SPR_VR, SPR_VR_REV, val);
      argv++; argc--;
    } else
    if (strcmp(*argv, "-profile") == 0) {
      config.profile = 1;
      argv++; argc--;
    } else {
      printf("Unknown option: %s\n", *argv);
      return 1;
    }
  }
 
  if (!argc)
    return 0;
 
  return 0;
}
 
void print_config()
{
  printf("Machine initialization...\n");
  if (testsprbits(SPR_UPR, SPR_UPR_DCP))
    printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
  else
    printf("No data cache.\n");
  if (testsprbits(SPR_UPR, SPR_UPR_ICP))
    printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
  else
    printf("No instruction cache.\n");
  if (config.bp.bpb_sim)
    printf("BPB simulation on.\n");
  else
    printf("BPB simulation off.\n");
  if (config.bp.btic_sim)
    printf("BTIC simulation on.\n");
  else
    printf("BTIC simulation off.\n");
  printf("Clock cycle: %d ns\n", config.clkcycle_ns);
  /*printf("RAM: 0x%x to 0x%x (%d KB)\n\n", config.ram.startaddr, config.ram.endaddr);
    (config.ram.endaddr - config.ram.startaddr) / 1024); MM170901 different memory scheme.  */
 
  if (config.simdebug)
    printf("simdebug on, ");
  else
    printf("simdebug off, ");
  if (config.iprompt)
    printf("interactive prompt on\n");
  else
    printf("interactive prompt off\n");
}
 
void change_device ();
void end_device ();
void uart_baseaddr ();
void uart_rxfile ();
void uart_txfile ();
void uart_jitter ();
void dma_baseaddr ();
void dma_irq ();
 
char memory_file[256] = "sim.mem";
 
#define SF_SUBSECTIONS 1
#define SF_REQUIRED    2
 
struct section {
  char *name;
  int flags;
} sections[] = {
  {"",       0},
  {"mc",     0},
  {"uart",   0},
  {"dma",    0}
};
 
unsigned long tempL;
unsigned long tempUL;
char tempS[STR_SIZE];
 
#define CPF_SUBSECTION 1
#define CPF_SUBFIELD   2
 
/* Parameter definitions */
struct config_params {
  int section;
  char *name;
  char *type;
  void (*func)();
  void *addr;
} config_params[] = {
  {1, "enabled",            "= %i",        NULL,          (void *)(&config.mc.enabled)},
  {1, "baseaddr",           "= 0x%x",      NULL,          (void *)(&config.mc.baseaddr)},
  {1, "memory_table_file",  "= \"%255s\"", NULL,          (void *)(&config.mc.memory_table_file[0])},
  {1, "POC",                "= 0x%x",      NULL,          (void *)(&config.mc.POC)},
 
  {2, "enabled",            "= %i",        NULL,          (void *)(&config.uarts_enabled)},
  {2, "nuarts",             "= %i",        NULL,          (void *)(&config.nuarts)},
  {2, "device",             "%i",          change_device, (void *)(&tempL)},
  {2, "enddevice",          "",            end_device,    NULL},
  {2, "baseaddr",           "= 0x%x",      uart_baseaddr, (void *)(&tempUL)},
  {2, "jitter",             "= %i",        uart_jitter,   (void *)(&tempL)},
  {2, "rxfile",             "= \"%255s\"", uart_rxfile,   (void *)(&tempS[0])},
  {2, "txfile",             "= \"%255s\"", uart_txfile,   (void *)(&tempS[0])},
 
  {3, "enabled",            "= %i",        NULL,          (void *)(&config.dmas_enabled)},
  {3, "ndmas",              "= %i",        NULL,          (void *)(&config.ndmas)},
  {3, "device",             "%i",          change_device, (void *)(&tempL)},
  {3, "enddevice",          "",            end_device,    NULL},
  {3, "baseaddr",           "= 0x%x",      dma_baseaddr,  (void *)(&tempUL)},
  {3, "irq",                "= %i",        dma_baseaddr,  (void *)(&tempL)}
};
 
int current_device = -1;
void change_device () {
  current_device = tempL;
}
 
void end_device () {
  current_device = -1;
}
 
void uart_baseaddr () {
  if (current_device >= 0 && current_device < config.nuarts)
    config.uarts[current_device].baseaddr = tempUL;
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
  }
}
 
void uart_jitter () {
  if (current_device >= 0 && current_device < config.nuarts)
    config.uarts[current_device].jitter = tempL;
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
  }
}
 
void uart_rxfile () {
  if (current_device >= 0 && current_device < config.nuarts)
    strcpy (config.uarts[current_device].rxfile, tempS);
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
  }
}
 
void uart_txfile () {
  if (current_device >= 0 && current_device < config.nuarts)
    strcpy (config.uarts[current_device].txfile, tempS);
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
  }
}
 
void dma_baseaddr () {
  if (current_device >= 0 && current_device < config.ndmas)
    config.dmas[current_device].baseaddr = tempUL;
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
  }
}
 
void dma_irq () {
  if (current_device >= 0 && current_device < config.ndmas)
    config.dmas[current_device].irq = tempL;
  else {
    fprintf (stderr, "ERROR: invalid device number.");
    exit (-1);
  }
}
 
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
   The syntax of script file is:
   param = value
   section x
     data
     param = value
   end
 
   Example:
   section mc
     memory_table_file = sim.mem
     enable = 1
     POC = 0x47892344
   end
 
 */
 
void read_script_file (char *filename)
{  
	FILE *f;
	unsigned long memory_needed = 0;
	char *home = getenv("HOME");
	char ctmp[STR_SIZE];
	int local = 1;
	int section = 0;
 
	sprintf(ctmp, "%s/.or1k/%s", home, filename);
	if ((f = fopen (filename, "rt")) != NULL
			|| home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
		unsigned long start, length;
		char type[STR_SIZE];
		int nparam;
		int rd, wd;
		printf ("Reading script file from '%s':\n", local ? filename : ctmp);
    while (!feof(f)) {
      char param[STR_SIZE];
      if (fscanf(f, "%s ", &param) != 1) break;
      /* Is this a sections? */
      if (strcmp (param, "section") == 0) {
        int i;
        section = 0;
        if (fscanf (f, "%s\n", &param) != 1) {
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
          exit (-1);
        }
        for (i = 1; i < sizeof(sections) / sizeof(char *); i++)
          if (strcmp (sections[i].name, param) == 0) {
            section = i;
            break;
          }
        if (!section) {
          fprintf (stderr, "%s: WARNING: Unknown section: %s; ignoring.\n", local ? filename : ctmp, param);
          /* just skip section */
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
        }
      } else if (strcmp (param, "end") == 0) {
        section = 0;
      } else if (strcmp (param, "/*") == 0) {
        char c0 = 0, c1 = 0;
        while (c0 != '*' && c1 != '/') {
          c0 = c1;
          c1 = fgetc(f);
          if (feof(f)) {
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
            exit (-1);
          }
        }
      } else {
        int i, found = -1;        
        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) {
            found = i;
            break;
          }
        if (found < 0) {
          fprintf (stderr, "%s: WARNING: Invalid parameter: %s; ignoring.\n", local ? filename : ctmp, param);
          while (fgetc(f) != '\n' || feof(f));          
          continue;
        }
 
        /* Parse parameter value */
        {
          char fmt[STR_SIZE];
          if (config_params[found].type[0]) {
            sprintf (fmt, "%s\n", config_params[found].type);
            fscanf (f, fmt, config_params[found].addr);
          }
        }
      }
    }
		fclose (f);
	} else {
		fprintf (stderr, "Cannot read script file from '%s',\nneither '%s'; assuming standard configuration.\n", filename, ctmp);
	}
 
	/* Initialize memory table.  */
	sim_read_memory_table (config.mc.memory_table_file);
}
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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