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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [sim-config.c] - Blame information for rev 240

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

Line No. Rev Author Line
1 7 jrydberg
/* config.c -- Simulator configuration
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Simulator configuration. Eventually this one will be a lot bigger. */
21
 
22 239 markom
#include <stdlib.h>
23 7 jrydberg
#include "sim-config.h"
24 30 lampret
#include "abstract.h"
25 103 lampret
#include "spr_defs.h"
26 230 erez
#include "pic.h"
27 7 jrydberg
 
28
struct config config;
29
 
30
void init_defconfig()
31
{
32 239 markom
  unsigned long val;
33
 
34
  memset(&config, 0, sizeof(config));
35
  config.dc.tagtype = NONE/*VIRTUAL*/;
36
  config.ic.tagtype = NONE/*VIRTUAL*/;
37
  config.bp.bpb_sim = 1;
38
  config.bp.btic_sim = 1;
39
  config.clkcycle_ns = 4; /* 4 for 4ns (250MHz) */
40
  config.uarts[0].rxfile = "/tmp/uart0.rx";
41
  config.uarts[0].txfile = "/tmp/uart0.tx";
42
  config.uarts[0].baseaddr = 0x80000000;
43
  config.uarts[0].jitter = -1; /* Async behavior */
44
  config.dmas[0].baseaddr = 0x90000000;
45
  config.dmas[0].irq = INT_DMA;
46
  config.simdebug = 0;
47
  config.profile = 0;
48
  config.iprompt = 0;
49
  config.dependstats = 1;
50
  config.dependency = 1;
51
  config.history = 1;
52
  config.superscalar = 1;
53
  config.slp = 1;
54
  config.profile = 0;
55 240 markom
  strcpy(config.mc.memory_table_file, "sim.mem");
56 103 lampret
 
57 239 markom
  mtspr(SPR_VR, SPR_VR_VER & 0x1200);
58 103 lampret
 
59 239 markom
  val = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP |
60
  SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP |
61
  SPR_UPR_PMP | SPR_UPR_TTP;
62 103 lampret
 
63 239 markom
  mtspr(SPR_UPR, val);
64 103 lampret
}
65
 
66
int parse_args(int argc, char *argv[])
67
{
68 239 markom
  unsigned long val;
69
 
70
  argv++; argc--;
71
  while (argc) {
72
    if (argc && (*argv[0] != '-')) {
73
      config.filename = argv[0];
74
      argc--;
75
      argv++;
76
    } else
77
    if (strcmp(*argv, "-initmem") == 0) {  /* (CZ) */
78
      char *pattern,*s;
79
      if(!--argc)
80
        return 1;
81
      pattern = *(++argv);
82
      if(!strcmp(pattern,"random"))
83
        config.random_mem = 1;
84
      else
85
        {
86
          val = strtol(pattern,&s,0);
87
          if(*s)
88
            return 1;
89
          config.pattern_mem = val;
90
        }
91
    } else
92
    if (strcmp(*argv, "-nosrv") == 0) {  /* (CZ) */
93
      config.inhibit_server = 1;
94
      argv++; argc--;
95
    } else
96
    if (strcmp(*argv, "-srv") == 0) {  /* (CZ) */
97
      char *s;
98
      if(!--argc)
99
        return 1;
100
      config.server_port = strtol(*(++argv),&s,10);
101
      if(*s)
102
        return 1;
103
      argv++; argc--;
104
    } else
105
    if (strcmp(*argv, "-i") == 0) {
106
      config.iprompt = 1;
107
      argv++; argc--;
108
    } else
109
    if (strcmp(*argv, "-v") == 0) {
110
      version();
111
      exit(0);
112
    } else
113
    if (strcmp(*argv, "-bpb") == 0) {
114
      config.bp.bpb_sim = 0;
115
      argv++; argc--;
116
    } else
117
    if (strcmp(*argv, "-hazards") == 0) {
118
      config.dependstats = 0;
119
      config.dependency = 0;
120
      argv++; argc--;
121
    } else
122
    if (strcmp(*argv, "-history") == 0) {
123
      config.history = 0;
124
      argv++; argc--;
125
    } else
126
    if (strcmp(*argv, "-superscalar") == 0) {
127
      config.superscalar = 0;
128
      argv++; argc--;
129
    } else
130
    if (strcmp(*argv, "-fast") == 0) {
131
      config.superscalar = 0;
132
      config.history = 0;
133
      config.dependstats = 0;
134
      config.dependency = 0;
135
      config.bp.bpb_sim = 0;
136
      config.bp.btic_sim = 0;
137
      config.slp = 0;
138
      argv++; argc--;
139
    } else
140
    if (strcmp(*argv, "-btic") == 0) {
141
      config.bp.btic_sim = 0;
142
      argv++; argc--;
143
    } else
144
    if (strcmp(*argv, "-upr") == 0) {
145
      argv++; argc--;
146
      val = strtoul(*argv, NULL, 0);
147
      mtspr(SPR_UPR, val);
148
      argv++; argc--;
149
    } else
150
    if (strcmp(*argv, "-ver") == 0) {
151
      argv++; argc--;
152
      val = strtoul(*argv, NULL, 0);
153
      setsprbits(SPR_VR, SPR_VR_VER, val);
154
      argv++; argc--;
155
    } else
156
    if (strcmp(*argv, "-rev") == 0) {
157
      argv++; argc--;
158
      val = strtoul(*argv, NULL, 0);
159
      setsprbits(SPR_VR, SPR_VR_REV, val);
160
      argv++; argc--;
161
    } else
162
    if (strcmp(*argv, "-profile") == 0) {
163
      config.profile = 1;
164
      argv++; argc--;
165
    } else {
166
      printf("Unknown option: %s\n", *argv);
167
      return 1;
168
    }
169
  }
170
 
171
  if (!argc)
172
    return 0;
173
 
174
  return 0;
175
}
176 123 markom
 
177 239 markom
void print_config()
178
{
179
  printf("Machine initialization...\n");
180
  if (testsprbits(SPR_UPR, SPR_UPR_DCP))
181
    printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
182
  else
183
    printf("No data cache.\n");
184
  if (testsprbits(SPR_UPR, SPR_UPR_ICP))
185
    printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
186
  else
187
    printf("No instruction cache.\n");
188
  if (config.bp.bpb_sim)
189
    printf("BPB simulation on.\n");
190
  else
191
    printf("BPB simulation off.\n");
192
  if (config.bp.btic_sim)
193
    printf("BTIC simulation on.\n");
194
  else
195
    printf("BTIC simulation off.\n");
196
  printf("Clock cycle: %d ns\n", config.clkcycle_ns);
197
  /*printf("RAM: 0x%x to 0x%x (%d KB)\n\n", config.ram.startaddr, config.ram.endaddr);
198
    (config.ram.endaddr - config.ram.startaddr) / 1024); MM170901 different memory scheme.  */
199
 
200
  if (config.simdebug)
201
    printf("simdebug on, ");
202
  else
203
    printf("simdebug off, ");
204
  if (config.iprompt)
205
    printf("interactive prompt on\n");
206
  else
207
    printf("interactive prompt off\n");
208
}
209 123 markom
 
210
 
211 239 markom
char memory_file[256] = "sim.mem";
212 123 markom
 
213 239 markom
char *sections[] = {
214
  "",
215
  "mc"
216
};
217
 
218
/* Parameter definitions */
219
struct config_params {
220
  int section;
221
  char *name;
222
  char *type;
223
  void *addr;
224
} config_params[] = {
225
  {1, "memory_table_file", "%255s", (void *)(&config.mc.memory_table_file[0])},
226
  {1, "enable",            "%i",    (void *)(&config.mc.enable)},
227
  {1, "POC",               "%i",    (void *)(&config.mc.POC)}
228
};
229
 
230
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
231
   The syntax of script file is:
232
   param = value
233
   section x
234
     data
235
     param = value
236
   end
237
 
238
   Example:
239
   section mc
240
     memory_table_file = sim.mem
241
     enable = 1
242
     POC = 0x47892344
243
   end
244
 
245
 */
246
 
247
void read_script_file (char *filename)
248
{
249
        FILE *f;
250
        unsigned long memory_needed = 0;
251
        char *home = getenv("HOME");
252
        char ctmp[STR_SIZE];
253
        int local = 1;
254
        int section = 0;
255
 
256
        sprintf(ctmp, "%s/.or1k/%s", home, filename);
257
        if ((f = fopen (filename, "rt")) != NULL
258
                        || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
259
                unsigned long start, length;
260
                char type[STR_SIZE];
261
                int nparam;
262
                int rd, wd;
263
                printf ("Reading script file from '%s':\n", local ? filename : ctmp);
264
    while (!feof(f)) {
265
      char param[STR_SIZE];
266
      if (fscanf(f, "%s ", &param) != 1) break;
267
      /* Is this a sections? */
268
      if (strcmp (param, "section") == 0) {
269
        int i;
270
        section = 0;
271
        if (fscanf (f, "%s\n", &param) != 1) {
272
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
273
          exit (-1);
274
        }
275
        for (i = 1; i < sizeof(sections) / sizeof(char *); i++)
276
          if (strcmp (sections[i], param) == 0) {
277
            section = i;
278
            break;
279
          }
280
        if (!section) {
281
          fprintf (stderr, "%s: WARNING: Unknown section: %s; ignoring.\n", local ? filename : ctmp, param);
282
          /* just skip section */
283
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
284
        }
285
      } else if (strcmp (param, "end") == 0) {
286
        section = 0;
287
      } else {
288
        int i, found = -1;
289
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
290
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
291
            found = i;
292
            break;
293
          }
294
        if (found < 0) {
295
          fprintf (stderr, "%s: WARNING: Invalid parameter: %s; ignoring.\n", local ? filename : ctmp, param);
296
          fscanf (f, "%s\n", &param);
297
          continue;
298
        }
299
 
300
        /* Parse parameter value */
301
        {
302
          char fmt[8];
303
          sprintf (fmt, "= %s\n", config_params[found].type);
304
          fscanf (f, fmt, config_params[found].addr);
305
        }
306
      }
307
    }
308
                fclose (f);
309
                printf ("\n");
310
        } else {
311
                fprintf (stderr, "Cannot read script file from '%s',\nneither '%s'; assuming standard configuration.\n", filename, ctmp);
312 103 lampret
        }
313
 
314 239 markom
        /* Initialize memory table.  */
315 240 markom
        sim_read_memory_table (config.mc.memory_table_file);
316 7 jrydberg
}

powered by: WebSVN 2.1.0

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