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 269

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 263 markom
  /* Sim */
36
  config.script_file = "sim.cfg";
37 264 markom
  config.sim.fprof = 0;
38
  strcpy (config.sim.prof_fn, "sim.profile");
39
  config.sim.debug = 0;
40
  config.sim.profile = 0;
41
  config.sim.iprompt = 0;
42 263 markom
 
43 262 markom
  /* Memory */
44
  config.memory.type = MT_PATTERN;
45
  config.memory.pattern = 0;
46
  config.memory.random_seed = -1;  /* Generate new seed */
47
  strcpy(config.memory.memory_table_file, "simmem.cfg");
48 263 markom
 
49
  /* Memory Controller */
50
  config.mc.enabled = 0;
51
 
52
  /* Uarts */
53
  config.nuarts = 0;
54
  config.uarts_enabled = 0;
55
 
56
  /* DMAs */
57
  config.ndmas = 0;
58
  config.dmas_enabled = 0;
59
 
60
  /* CPU */
61
  config.cpu.superscalar = 0;
62
  config.cpu.history = 0;
63
  config.cpu.hazards = 0;
64
  config.cpu.dependstats = 0;
65
  config.cpu.dependency = 0;
66
  config.cpu.slp = 0;
67
  config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP
68
                 | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP
69
                 | SPR_UPR_PMP | SPR_UPR_TTP;
70 264 markom
 
71 269 markom
  /* Debug */
72
  config.debug.enabled = 0;
73
  config.debug.gdb_enabled = 0;
74
  config.debug.server_port = 0;
75
 
76 262 markom
  /* Old */
77 239 markom
  config.dc.tagtype = NONE/*VIRTUAL*/;
78
  config.ic.tagtype = NONE/*VIRTUAL*/;
79
  config.clkcycle_ns = 4; /* 4 for 4ns (250MHz) */
80 263 markom
  config.ethernets[0].baseaddr = 0x88000000;
81
  config.ethernets[0].dma = 0;
82
  config.ethernets[0].tx_channel = 0;
83
  config.ethernets[0].rx_channel = 1;
84
  config.ethernets[0].rxfile = "/tmp/eth0.rx";
85
  config.ethernets[0].txfile = "/tmp/eth0.tx";
86 103 lampret
}
87
 
88
int parse_args(int argc, char *argv[])
89
{
90 239 markom
  unsigned long val;
91
 
92
  argv++; argc--;
93
  while (argc) {
94
    if (argc && (*argv[0] != '-')) {
95
      config.filename = argv[0];
96
      argc--;
97
      argv++;
98 242 markom
    } else
99 263 markom
    if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
100
      argv++; argc--;
101
      config.script_file = argv[0];
102
      argv++; argc--;
103
    } else
104
    if (strcmp(*argv, "--nosrv") == 0) {  /* (CZ) */
105 269 markom
      config.debug.gdb_enabled = 0;
106 239 markom
      argv++; argc--;
107
    } else
108 263 markom
    if (strcmp(*argv, "--srv") == 0) {  /* (CZ) */
109 239 markom
      char *s;
110
      if(!--argc)
111
        return 1;
112 269 markom
      config.debug.enabled = 1;
113
      config.debug.gdb_enabled = 0;
114
      config.debug.server_port = strtol(*(++argv),&s,10);
115 239 markom
      if(*s)
116
        return 1;
117
      argv++; argc--;
118
    } else
119
    if (strcmp(*argv, "-i") == 0) {
120 264 markom
      config.sim.iprompt = 1;
121 239 markom
      argv++; argc--;
122
    } else
123
    if (strcmp(*argv, "-v") == 0) {
124
      version();
125
      exit(0);
126
    } else
127 263 markom
    if (strcmp(*argv, "--profile") == 0) {
128 264 markom
      config.sim.profile = 1;
129 239 markom
      argv++; argc--;
130
    } else {
131
      printf("Unknown option: %s\n", *argv);
132
      return 1;
133
    }
134
  }
135
 
136
  if (!argc)
137
    return 0;
138
 
139
  return 0;
140
}
141 123 markom
 
142 239 markom
void print_config()
143
{
144
  printf("Machine initialization...\n");
145
  if (testsprbits(SPR_UPR, SPR_UPR_DCP))
146
    printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
147
  else
148
    printf("No data cache.\n");
149
  if (testsprbits(SPR_UPR, SPR_UPR_ICP))
150
    printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
151
  else
152
    printf("No instruction cache.\n");
153 264 markom
  /*if (config.cpu.bpb_sim)
154 239 markom
    printf("BPB simulation on.\n");
155
  else
156
    printf("BPB simulation off.\n");
157 264 markom
  if (config.cpu.btic_sim)
158 239 markom
    printf("BTIC simulation on.\n");
159
  else
160 264 markom
    printf("BTIC simulation off.\n");*/
161 239 markom
  printf("Clock cycle: %d ns\n", config.clkcycle_ns);
162
 
163 264 markom
  if (config.sim.debug)
164 239 markom
    printf("simdebug on, ");
165
  else
166
    printf("simdebug off, ");
167 264 markom
  if (config.sim.iprompt)
168 239 markom
    printf("interactive prompt on\n");
169
  else
170
    printf("interactive prompt off\n");
171
}
172 123 markom
 
173 261 markom
void change_device ();
174
void end_device ();
175
void uart_baseaddr ();
176
void uart_rxfile ();
177
void uart_txfile ();
178
void uart_jitter ();
179
void dma_baseaddr ();
180
void dma_irq ();
181 262 markom
void memory_type ();
182 123 markom
 
183 239 markom
char memory_file[256] = "sim.mem";
184 123 markom
 
185 261 markom
struct section {
186
  char *name;
187
  int flags;
188
} sections[] = {
189
  {"",       0},
190
  {"mc",     0},
191
  {"uart",   0},
192 262 markom
  {"dma",    0},
193 263 markom
  {"memory", 0},
194 264 markom
  {"cpu",    0},
195 269 markom
  {"sim",    0},
196
  {"debug",  0}
197 239 markom
};
198
 
199 261 markom
unsigned long tempL;
200
unsigned long tempUL;
201
char tempS[STR_SIZE];
202
 
203
#define CPF_SUBSECTION 1
204
#define CPF_SUBFIELD   2
205
 
206 239 markom
/* Parameter definitions */
207
struct config_params {
208
  int section;
209
  char *name;
210
  char *type;
211 261 markom
  void (*func)();
212
  void *addr;
213 239 markom
} config_params[] = {
214 261 markom
  {1, "enabled",            "= %i",        NULL,          (void *)(&config.mc.enabled)},
215
  {1, "baseaddr",           "= 0x%x",      NULL,          (void *)(&config.mc.baseaddr)},
216
  {1, "POC",                "= 0x%x",      NULL,          (void *)(&config.mc.POC)},
217
 
218
  {2, "enabled",            "= %i",        NULL,          (void *)(&config.uarts_enabled)},
219
  {2, "nuarts",             "= %i",        NULL,          (void *)(&config.nuarts)},
220
  {2, "device",             "%i",          change_device, (void *)(&tempL)},
221
  {2, "enddevice",          "",            end_device,    NULL},
222
  {2, "baseaddr",           "= 0x%x",      uart_baseaddr, (void *)(&tempUL)},
223
  {2, "jitter",             "= %i",        uart_jitter,   (void *)(&tempL)},
224
  {2, "rxfile",             "= \"%255s\"", uart_rxfile,   (void *)(&tempS[0])},
225
  {2, "txfile",             "= \"%255s\"", uart_txfile,   (void *)(&tempS[0])},
226
 
227
  {3, "enabled",            "= %i",        NULL,          (void *)(&config.dmas_enabled)},
228
  {3, "ndmas",              "= %i",        NULL,          (void *)(&config.ndmas)},
229
  {3, "device",             "%i",          change_device, (void *)(&tempL)},
230
  {3, "enddevice",          "",            end_device,    NULL},
231
  {3, "baseaddr",           "= 0x%x",      dma_baseaddr,  (void *)(&tempUL)},
232 262 markom
  {3, "irq",                "= %i",        dma_baseaddr,  (void *)(&tempL)},
233
 
234
  {4, "memory_table_file",  "= \"%255s\"", NULL,          (void *)(&config.memory.memory_table_file[0])},
235
  {4, "random_seed",        "= %i",        NULL,          (void *)(&config.memory.random_seed)},
236
  {4, "pattern",            "= %i",        NULL,          (void *)(&config.memory.pattern)},
237
  {4, "type",               "= %255s",     memory_type,   (void *)(&tempS[0])},
238 263 markom
 
239
  {5, "ver",                "= 0x%x",      NULL,          (void *)(&config.cpu.ver)},
240 264 markom
  {5, "rev",                "= 0x%x",      NULL,          (void *)(&config.cpu.rev)},
241 263 markom
  {5, "upr",                "= 0x%x",      NULL,          (void *)(&config.cpu.upr)},
242 264 markom
  {5, "hazards",            "= %i",        NULL,          (void *)(&config.cpu.hazards)},
243
  {5, "history",            "= %i",        NULL,          (void *)(&config.cpu.history)},
244 263 markom
  {5, "superscalar",        "= %i",        NULL,          (void *)(&config.cpu.superscalar)},
245
  {5, "dependstats",        "= %i",        NULL,          (void *)(&config.cpu.dependstats)},
246
  {5, "dependency",         "= %i",        NULL,          (void *)(&config.cpu.dependency)},
247 264 markom
  {5, "slp",                "= %i",        NULL,          (void *)(&config.cpu.slp)},
248
  {5, "bpb",                "= %i",        NULL,          (void *)(&config.cpu.bpb)},
249
  {5, "btic_sim",           "= %i",        NULL,          (void *)(&config.cpu.btic_sim)},
250
 
251
  {6, "debug",              "= %i",        NULL,          (void *)(&config.sim.debug)},
252
  {6, "prof_fn",            "= \"%255s\"", NULL,          (void *)(&config.sim.prof_fn[0])},
253
  {6, "profile",            "= %i",        NULL,          (void *)(&config.sim.profile)},
254 269 markom
  {6, "iprompt",            "= %i",        NULL,          (void *)(&config.sim.iprompt)},
255
 
256
  {7, "enabled",            "= %i",        NULL,          (void *)(&config.debug.enabled)},
257
  {7, "gdb_enabled",        "= %i",        NULL,          (void *)(&config.debug.gdb_enabled)},
258
  {7, "server_port",        "= %i",        NULL,          (void *)(&config.debug.server_port)}
259 239 markom
};
260
 
261 261 markom
int current_device = -1;
262
void change_device () {
263
  current_device = tempL;
264
}
265
 
266
void end_device () {
267
  current_device = -1;
268
}
269
 
270
void uart_baseaddr () {
271
  if (current_device >= 0 && current_device < config.nuarts)
272
    config.uarts[current_device].baseaddr = tempUL;
273
  else {
274
    fprintf (stderr, "ERROR: invalid device number.");
275
    exit (-1);
276
  }
277
}
278
 
279
void uart_jitter () {
280
  if (current_device >= 0 && current_device < config.nuarts)
281
    config.uarts[current_device].jitter = tempL;
282
  else {
283
    fprintf (stderr, "ERROR: invalid device number.");
284
    exit (-1);
285
  }
286
}
287
 
288
void uart_rxfile () {
289
  if (current_device >= 0 && current_device < config.nuarts)
290
    strcpy (config.uarts[current_device].rxfile, tempS);
291
  else {
292
    fprintf (stderr, "ERROR: invalid device number.");
293
    exit (-1);
294
  }
295
}
296
 
297
void uart_txfile () {
298
  if (current_device >= 0 && current_device < config.nuarts)
299
    strcpy (config.uarts[current_device].txfile, tempS);
300
  else {
301
    fprintf (stderr, "ERROR: invalid device number.");
302
    exit (-1);
303
  }
304
}
305
 
306
void dma_baseaddr () {
307
  if (current_device >= 0 && current_device < config.ndmas)
308
    config.dmas[current_device].baseaddr = tempUL;
309
  else {
310
    fprintf (stderr, "ERROR: invalid device number.");
311
    exit (-1);
312
  }
313
}
314
 
315
void dma_irq () {
316
  if (current_device >= 0 && current_device < config.ndmas)
317
    config.dmas[current_device].irq = tempL;
318
  else {
319
    fprintf (stderr, "ERROR: invalid device number.");
320
    exit (-1);
321
  }
322
}
323
 
324 262 markom
void memory_type () {
325 269 markom
  if (strcmp (tempS, "unknown") == 0)
326
    config.memory.type = MT_UNKNOWN;
327
  else if (strcmp (tempS, "random") == 0)
328 262 markom
    config.memory.type = MT_RANDOM;
329
  else if (strcmp (tempS, "pattern") == 0)
330
    config.memory.type = MT_PATTERN;
331
  else if (strcmp (tempS, "zero") == 0) {
332
    config.memory.type = MT_PATTERN;
333
    config.memory.pattern = 0;
334
  } else {
335 269 markom
    fprintf (stderr, "ERROR: invalid memory type '%s'.\n", tempS);
336 262 markom
    exit (-1);
337
  }
338
}
339
 
340 239 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
341
   The syntax of script file is:
342
   param = value
343
   section x
344
     data
345
     param = value
346
   end
347
 
348
   Example:
349
   section mc
350
     memory_table_file = sim.mem
351
     enable = 1
352
     POC = 0x47892344
353
   end
354
 
355
 */
356
 
357
void read_script_file (char *filename)
358
{
359 263 markom
  FILE *f;
360
  unsigned long memory_needed = 0;
361
  char *home = getenv("HOME");
362
  char ctmp[STR_SIZE];
363
  int local = 1;
364
  int section = 0;
365 239 markom
 
366 263 markom
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
367
  if ((f = fopen (filename, "rt")) != NULL
368
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
369
    unsigned long start, length;
370
    char type[STR_SIZE];
371
    int nparam;
372
    int rd, wd;
373
    printf ("Reading script file from '%s':\n", local ? filename : ctmp);
374 239 markom
    while (!feof(f)) {
375
      char param[STR_SIZE];
376
      if (fscanf(f, "%s ", &param) != 1) break;
377
      /* Is this a sections? */
378
      if (strcmp (param, "section") == 0) {
379
        int i;
380
        section = 0;
381
        if (fscanf (f, "%s\n", &param) != 1) {
382
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
383
          exit (-1);
384
        }
385
        for (i = 1; i < sizeof(sections) / sizeof(char *); i++)
386 261 markom
          if (strcmp (sections[i].name, param) == 0) {
387 239 markom
            section = i;
388
            break;
389
          }
390
        if (!section) {
391
          fprintf (stderr, "%s: WARNING: Unknown section: %s; ignoring.\n", local ? filename : ctmp, param);
392
          /* just skip section */
393
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
394
        }
395
      } else if (strcmp (param, "end") == 0) {
396
        section = 0;
397 264 markom
      } else if (strncmp (param, "/*", 2) == 0) {
398 261 markom
        char c0 = 0, c1 = 0;
399 264 markom
        while (c0 != '*' || c1 != '/') {
400 261 markom
          c0 = c1;
401
          c1 = fgetc(f);
402
          if (feof(f)) {
403
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
404
            exit (-1);
405
          }
406
        }
407 239 markom
      } else {
408
        int i, found = -1;
409
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
410
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
411
            found = i;
412
            break;
413
          }
414
        if (found < 0) {
415
          fprintf (stderr, "%s: WARNING: Invalid parameter: %s; ignoring.\n", local ? filename : ctmp, param);
416 261 markom
          while (fgetc(f) != '\n' || feof(f));
417 239 markom
          continue;
418
        }
419
 
420
        /* Parse parameter value */
421
        {
422 261 markom
          char fmt[STR_SIZE];
423
          if (config_params[found].type[0]) {
424
            sprintf (fmt, "%s\n", config_params[found].type);
425
            fscanf (f, fmt, config_params[found].addr);
426
          }
427 239 markom
        }
428 262 markom
        if (config_params[found].func)
429
          config_params[found].func();
430 239 markom
      }
431
    }
432 263 markom
    fclose (f);
433
  } else {
434
    fprintf (stderr, "Cannot read script file from '%s',\nneither '%s'; assuming standard configuration.\n", filename, ctmp);
435
  }
436 103 lampret
 
437 263 markom
  /* Initialize memory table.  */
438
  sim_read_memory_table (config.memory.memory_table_file);
439 7 jrydberg
}

powered by: WebSVN 2.1.0

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