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 306

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

powered by: WebSVN 2.1.0

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