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 294

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

powered by: WebSVN 2.1.0

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