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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_69/] [or1ksim/] [sim-config.c] - Blame information for rev 633

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

Line No. Rev Author Line
1 424 markom
/* 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
#include <stdlib.h>
23
#include "sim-config.h"
24
#include "abstract.h"
25 518 markom
#include "sprs.h"
26 424 markom
#include "spr_defs.h"
27
#include "pic.h"
28 535 markom
#include "stats.h"
29 428 markom
#include "icache_model.h"
30
#include "dcache_model.h"
31 424 markom
 
32 632 ivang
#include "profiler.h"
33
#include "mprofiler.h"
34
 
35 427 markom
#define WARNING(s) fprintf (stderr, "WARNING: config.%s: %s\n", sections[section].name, (s))
36 428 markom
#define ERROR(s) {fprintf (stderr, "ERROR: config.%s:%s\n", sections[section].name, s); if (runtime.sim.init) exit (1);}
37
#define MERROR(s) {fprintf (stderr, "ERROR: %s\n", s); if (runtime.sim.init) exit (1);}
38 424 markom
 
39 551 markom
#if !FAST_SIM
40 424 markom
struct config config;
41 551 markom
#endif
42 424 markom
struct runtime runtime;
43
 
44
int section = 0;
45
extern struct section {
46
  char *name;
47
  int flags;
48
} sections[];
49
 
50
void init_defconfig()
51
{
52
  int i;
53 551 markom
 
54
#if !FAST_SIM
55 424 markom
  memset(&config, 0, sizeof(config));
56
  /* Sim */
57
  config.sim.exe_log = 0;
58 624 ivang
  config.sim.spr_log = 0;
59 424 markom
  strcpy (config.sim.exe_log_fn, "executed.log");
60 624 ivang
  strcpy (config.sim.spr_log_fn, "spr.log");
61
 
62 424 markom
  config.sim.debug = 0;
63
  config.sim.verbose = 1;
64
 
65 632 ivang
  config.sim.profile_mode = 0;
66
  config.sim.mprofile_mode = 0;
67
  config.sim.mprofile_group = 2;
68 424 markom
  strcpy (config.sim.prof_fn, "sim.profile");
69 547 markom
  strcpy (config.sim.mprof_fn, "sim.mprofile");
70 549 markom
  strcpy (runtime.sim.script_fn, "(default)");
71 433 markom
  config.sim.clkcycle_ps = 4000; /* 4000 for 4ns (250MHz) */
72 424 markom
 
73
  /* Memory */
74 554 markom
  config.memory.type = MT_UNKNOWN;
75 424 markom
  config.memory.pattern = 0;
76
  config.memory.random_seed = -1;  /* Generate new seed */
77 551 markom
  for (i = 0; i < MAX_MEMORIES; i++)
78 424 markom
    config.memory.table[i].ce = -1;     /* memory is disabled by default */
79
 
80 428 markom
  /* IMMU & DMMU*/
81
  config.immu.enabled = 0;
82 541 markom
  config.immu.hitdelay = 0;
83
  config.immu.missdelay = 0;
84 428 markom
  config.dmmu.enabled = 0;
85 541 markom
  config.dmmu.hitdelay = 0;
86
  config.dmmu.missdelay = 0;
87 428 markom
 
88
  /* IC & DC */
89
  config.ic.enabled = 0;
90 541 markom
  config.ic.hitdelay = 0;
91
  config.ic.missdelay = 0;
92 631 simons
  config.ic.nways = 0;
93
  config.ic.nsets = 0;
94
  config.ic.ustates = 0;
95 428 markom
  config.dc.enabled = 0;
96 541 markom
  config.dc.load_hitdelay = 0;
97
  config.dc.load_missdelay = 0;
98 631 simons
  config.dc.nways = 0;
99
  config.dc.nsets = 0;
100
  config.dc.ustates = 0;
101 541 markom
  config.dc.store_hitdelay = 0;
102
  config.dc.store_missdelay = 0;
103 428 markom
 
104 424 markom
  /* Memory Controller */
105
  config.mc.enabled = 0;
106
 
107
  /* Uarts */
108
  config.nuarts = 0;
109
 
110
  /* DMAs */
111
  config.ndmas = 0;
112
 
113
  /* CPU */
114
  config.cpu.superscalar = 0;
115
  config.sim.history = 0;
116
  config.cpu.hazards = 0;
117
  config.cpu.dependstats = 0;
118 626 markom
  config.cpu.raw_range = 0;
119
  config.cpu.sbuf_len = 0;
120 424 markom
  config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP
121
                 | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP
122
                 | SPR_UPR_PMP | SPR_UPR_TTP;
123 556 markom
  config.cpu.sr = 0x00008003;
124 424 markom
 
125
  /* Debug */
126
  config.debug.enabled = 0;
127
  config.debug.gdb_enabled = 0;
128
  config.debug.server_port = 0;
129
 
130
  /* VAPI */
131
  config.vapi.enabled = 0;
132
  strcpy (config.vapi.vapi_fn, "vapi.log");
133
 
134
  /* Ethernet */
135 549 markom
  config.nethernets = 0;
136 424 markom
 
137 444 erez
  /* GPIO */
138 549 markom
  config.ngpios = 0;
139
 
140 424 markom
  /* Tick timer */
141
  config.tick.enabled = 0;
142 557 markom
 
143
  /* PM */
144
  config.pm.enabled = 0;
145 551 markom
#endif
146
 
147
  /* Configure runtime */
148
  memset(&runtime, 0, sizeof(runtime));
149
 
150
  /* Sim */
151
  runtime.sim.fexe_log = NULL;
152 624 ivang
  runtime.sim.fspr_log = NULL;
153 551 markom
  runtime.sim.iprompt = 0;
154
  runtime.sim.fprof = NULL;
155
  runtime.sim.fmprof = NULL;
156
  runtime.sim.init = 1;
157
  runtime.sim.script_file_specified = 0;
158
 
159
  /* VAPI */
160
  runtime.vapi.vapi_file = NULL;
161
  runtime.vapi.enabled = 0;
162 424 markom
}
163
 
164
int parse_args(int argc, char *argv[])
165
{
166
  unsigned long val;
167
 
168
  argv++; argc--;
169
  while (argc) {
170
    if (argc && (*argv[0] != '-')) {
171
      runtime.sim.filename = argv[0];
172
      argc--;
173
      argv++;
174
    } else
175 551 markom
#if !FAST_SIM /* Constant cfg */
176 424 markom
    if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
177
      argv++; argc--;
178 481 markom
      if (argv[0]) {
179
        read_script_file(argv[0]);
180
        argv++; argc--;
181
      } else {
182
        fprintf(stderr, "Configure filename not specified!\n");
183
        return 1;
184
      }
185 424 markom
    } else
186 551 markom
#endif
187 424 markom
    if (strcmp(*argv, "--nosrv") == 0) {  /* (CZ) */
188
      config.debug.gdb_enabled = 0;
189
      argv++; argc--;
190
    } else
191
    if (strcmp(*argv, "--srv") == 0) {  /* (CZ) */
192
      char *s;
193
      if(!--argc)
194
        return 1;
195
      config.debug.enabled = 1;
196
      config.debug.gdb_enabled = 0;
197
      config.debug.server_port = strtol(*(++argv),&s,10);
198
      if(*s)
199
        return 1;
200
      argv++; argc--;
201
    } else
202
    if (strcmp(*argv, "-i") == 0) {
203 551 markom
      runtime.sim.iprompt = 1;
204 424 markom
      argv++; argc--;
205
    } else
206
    if (strcmp(*argv, "-v") == 0) {
207
      version();
208
      exit(0);
209
    } else
210 551 markom
#if !FAST_SIM
211 424 markom
    if (strcmp(*argv, "--profile") == 0) {
212
      config.sim.profile = 1;
213
      argv++; argc--;
214 632 ivang
      if (argv[0][0] != '-') {
215
        if ((argv[0][0] == 'c') || (argv[0][1] == 'c')) config.sim.profile_mode |= PROF_CUMULATIVE;
216
        if ((argv[0][0] == 'q') || (argv[0][1] == 'q')) config.sim.profile_mode |= PROF_QUIET;
217
        argv++; argc--;
218
      }
219 547 markom
    } else
220 632 ivang
    if (strcmp(*argv, "--mprofile_d") == 0) {
221 547 markom
      config.sim.mprofile = 1;
222 632 ivang
      config.sim.mprofile_mode = MODE_DETAIL;
223 547 markom
      argv++; argc--;
224 549 markom
    } else
225 632 ivang
    if (strcmp(*argv, "--mprofile_p") == 0) {
226
      config.sim.mprofile = 1;
227
      config.sim.mprofile_mode = MODE_PRETTY;
228
      argv++; argc--;
229
    } else
230
    if (strcmp(*argv, "--mprofile_a") == 0) {
231
      config.sim.mprofile = 1;
232
      config.sim.mprofile_mode = MODE_ACCESS;
233
      argv++; argc--;
234
    } else
235
    if (strcmp(*argv, "--mprofile_w") == 0) {
236
      config.sim.mprofile = 1;
237
      config.sim.mprofile_mode = MODE_WIDTH;
238
      argv++; argc--;
239
    } else
240
    if (!strcmp(argv[0], "-g") || !strcmp(argv[0], "--group")) {
241
      argv++; argc--;
242
      config.sim.mprofile_group = strtoul(argv[0], NULL, 0);
243
      argv++; argc--;
244 633 ivang
    } else
245 551 markom
#endif
246 549 markom
    if (strcmp(*argv, "--output-cfg") == 0) {
247
      runtime.sim.output_cfg = 1;
248
      argv++; argc--;
249 424 markom
    } else {
250 481 markom
      fprintf(stderr, "Unknown option: %s\n", *argv);
251 424 markom
      return 1;
252
    }
253
  }
254
 
255
  if (!argc)
256
    return 0;
257
 
258
  return 0;
259
}
260
 
261 551 markom
#if !FAST_SIM
262 434 markom
#define CNV(x) ((isspace(x) || (x) == 0) ? ' ' : (x))
263 424 markom
 
264
/* Substitute for less powerful fscanf */
265 549 markom
int fscanf_ex (FILE *f, char *fmt, void *buf, char *str)
266
{
267 424 markom
  char tmp[STR_SIZE];
268
  char ch;
269
  int i = 0;
270
  while (*fmt) {
271
    switch (*fmt) {
272
      case '%':
273
        while(*fmt != 0 && !isalpha (*fmt))
274
          tmp[i++] = *(fmt++);
275
        tmp[i++] = *(fmt++);
276
        if (tmp[i - 1] == 's') {
277
          char *cbuf = (char *)buf;
278
          i = 0;
279 434 markom
          while (ch = (f ? fgetc (f) : *str++), isspace(ch))
280 424 markom
            if (f ? feof (f) : *str) return 1;
281 479 markom
          if (f)
282 424 markom
            ungetc (ch, f);
283
          else
284
            str--;
285
          while ((*(cbuf++) = ch = (f ? fgetc (f) : *str++), CNV(ch) ) != *fmt) {
286
            if ((f ? feof (f) : *str)) return 1;
287
            if (++i >= STR_SIZE) {
288
              fprintf (stderr, "ERROR: string too long.\n");
289
              return 1;
290
            }
291
          }
292
          *(--cbuf) = 0;
293
          fmt++;
294
        } else {
295
          tmp[i++] = 0;
296
          if (f)
297
            fscanf (f, tmp, buf);
298
          else
299
            sscanf (str, tmp, buf);
300
        }
301
        break;
302
      default:
303
        while ((ch = (f ? fgetc (f) : *str++)) != *fmt) {
304 434 markom
          if (!isspace (ch)) {
305 424 markom
            char tmp[200];
306
            sprintf (tmp, "unexpected char '%c' (expecting '%c')\n", ch, *fmt);
307 427 markom
            fprintf (stderr, "WARNING: config.%s: %s\n", sections[section], tmp);
308 424 markom
            WARNING(tmp);
309
          }
310
          if ((f ? feof (f) : *str)) return 1;
311
        }
312
        fmt++;
313
        break;
314
    }
315
  }
316
  return 0;
317
}
318 551 markom
#endif /* !FAST_SIM */
319 424 markom
 
320
void print_config()
321
{
322
  if (config.sim.verbose) {
323 433 markom
    char temp[20];
324 424 markom
    printf("Verbose on, ");
325
    if (config.sim.debug)
326
      printf("simdebug on, ");
327
    else
328
      printf("simdebug off, ");
329 551 markom
    if (runtime.sim.iprompt)
330 424 markom
      printf("interactive prompt on\n");
331
    else
332
      printf("interactive prompt off\n");
333
 
334
    printf("Machine initialization...\n");
335 433 markom
    generate_time_pretty (temp, config.sim.clkcycle_ps);
336
    printf("Clock cycle: %s\n", temp);
337 424 markom
    if (testsprbits(SPR_UPR, SPR_UPR_DCP))
338 631 simons
      printf("Data cache present.\n");
339 424 markom
    else
340
      printf("No data cache.\n");
341
    if (testsprbits(SPR_UPR, SPR_UPR_ICP))
342 631 simons
      printf("Insn cache tag present.\n");
343 424 markom
    else
344
      printf("No instruction cache.\n");
345 541 markom
    if (config.bpb.enabled)
346 424 markom
      printf("BPB simulation on.\n");
347
    else
348
      printf("BPB simulation off.\n");
349 541 markom
    if (config.bpb.btic)
350 424 markom
      printf("BTIC simulation on.\n");
351
    else
352
      printf("BTIC simulation off.\n");
353
  }
354
}
355
 
356 551 markom
#if !FAST_SIM
357 424 markom
/* Forward declarations of functions */
358 568 markom
void base_include ();
359 433 markom
void sim_clkcycle ();
360 424 markom
void change_device ();
361
void end_device ();
362
void uart_nuarts ();
363
void uart_baseaddr ();
364
void uart_rxfile ();
365
void uart_txfile ();
366
void uart_jitter ();
367
void uart_irq ();
368
void uart_16550 ();
369
void uart_vapi_id ();
370
void dma_ndmas ();
371
void dma_baseaddr ();
372
void dma_irq ();
373
void dma_vapi_id ();
374
void memory_type ();
375
void memory_nmemories ();
376
void memory_ce ();
377
void memory_baseaddr ();
378
void memory_size ();
379
void memory_name ();
380
void memory_log ();
381
void memory_delayr ();
382
void memory_delayw ();
383 535 markom
void cpu_raw_range ();
384 626 markom
void cpu_sbuf_len ();
385 424 markom
void eth_nethernets ();
386
void eth_baseaddr ();
387
void eth_dma ();
388
void eth_rx_channel ();
389
void eth_tx_channel ();
390
void eth_rxfile ();
391
void eth_txfile ();
392
void eth_vapi_id ();
393 444 erez
void gpio_ngpios ();
394
void gpio_baseaddr ();
395
void gpio_irq ();
396 477 erez
void gpio_base_vapi_id ();
397 425 markom
void immu_enabled ();
398
void immu_nsets ();
399
void immu_nways ();
400
void immu_pagesize ();
401
void immu_entrysize ();
402
void immu_ustates ();
403
void dmmu_enabled ();
404
void dmmu_nsets ();
405
void dmmu_nways ();
406
void dmmu_pagesize ();
407
void dmmu_entrysize ();
408
void dmmu_ustates ();
409 428 markom
void ic_enabled ();
410
void ic_nsets ();
411
void ic_nways ();
412
void ic_blocksize ();
413
void ic_ustates ();
414
void dc_enabled ();
415
void dc_nsets ();
416
void dc_nways ();
417
void dc_blocksize ();
418
void dc_ustates ();
419 424 markom
 
420
unsigned long tempL;
421
unsigned long tempUL;
422
char tempS[STR_SIZE];
423
 
424
#define CPF_SUBSECTION 1
425
#define CPF_SUBFIELD   2
426 549 markom
#define CPF_GLOBAL     4   /* Not part of the substructure (group) in config */
427 424 markom
 
428
struct section sections[] = {
429 568 markom
  {"base",   0},   /* 0  */
430 424 markom
  {"mc",     0},
431
  {"uart",   0},
432
  {"dma",    0},
433
  {"memory", 0},
434 541 markom
  {"cpu",    0},   /* 5  */
435 424 markom
  {"sim",    0},
436
  {"debug",  0},
437
  {"VAPI",   0},
438
  {"ethernet",0},
439 425 markom
  {"tick",   0},   /* 10 */
440
  {"immu",   0},
441 428 markom
  {"dmmu",   0},
442
  {"ic",     0},
443 444 erez
  {"dc",     0},
444 541 markom
  {"gpio",   0},   /* 15 */
445 557 markom
  {"bpb",    0},
446
  {"pm",     0}
447 424 markom
};
448
 
449
/* *INDENT-OFF* */
450
 
451
/* Parameter definitions */
452
struct config_params {
453
  int section;
454
  char *name;
455
  char *type;
456
  void (*func)();
457
  void *addr;
458 549 markom
  int attr;
459 424 markom
} config_params[] = {
460 568 markom
{0, "include",            "\"%s\"",      base_include,  (void *)(&tempS), 0},
461
 
462 549 markom
{1, "enabled",            "=%i",         NULL,          (void *)(&config.mc.enabled), 0},
463
{1, "baseaddr",           "=0x%x",       NULL,          (void *)(&config.mc.baseaddr), 0},
464
{1, "POC",                "=0x%x",       NULL,          (void *)(&config.mc.POC), 0},
465
 
466
{2, "nuarts",             "=%i",         uart_nuarts,   (void *)(&tempL), CPF_GLOBAL},
467
{2, "device",             "%i",          change_device, (void *)(&tempL), 0},
468
{2, "enddevice",          "",            end_device,    NULL, 0},
469
{2, "baseaddr",           "=0x%x",       uart_baseaddr, (void *)(&tempUL), 0},
470
{2, "irq",                "=%i",         uart_irq,      (void *)(&tempL), 0},
471
{2, "16550",              "=%i",         uart_16550,    (void *)(&tempL), 0},
472
{2, "jitter",             "=%i",         uart_jitter,   (void *)(&tempL), 0},
473
{2, "rxfile",             "=\"%s\"",     uart_rxfile,   (void *)(&tempS[0]), 0},
474
{2, "txfile",             "=\"%s\"",     uart_txfile,   (void *)(&tempS[0]), 0},
475
{2, "vapi_id",            "=0x%x",       uart_vapi_id,  (void *)(&tempUL), 0},
476 424 markom
 
477 549 markom
{3, "ndmas",              "=%i",         dma_ndmas,     (void *)(&tempL), CPF_GLOBAL},
478
{3, "device",             "%i",          change_device, (void *)(&tempL), 0},
479
{3, "enddevice",          "",            end_device,    NULL, 0},
480
{3, "baseaddr",           "=0x%x",       dma_baseaddr,  (void *)(&tempUL), 0},
481
{3, "irq",                "=%i",         dma_irq,       (void *)(&tempL), 0},
482
{3, "vapi_id",            "=0x%x",       dma_vapi_id,   (void *)(&tempUL), 0},
483 424 markom
 
484 549 markom
{4, "random_seed",        "=%i",         NULL,          (void *)(&config.memory.random_seed), 0},
485
{4, "pattern",            "=%i",         NULL,          (void *)(&config.memory.pattern), 0},
486
{4, "type",               "=%s ",        memory_type,   (void *)(&tempS[0]), 0},
487
{4, "nmemories",          "=%i",         memory_nmemories,(void *)(&tempL), CPF_GLOBAL},
488
{4, "device",             "%i",          change_device, (void *)(&tempL), 0},
489
{4, "enddevice",          "",            end_device,    NULL, 0},
490
{4, "ce",                 "=%i",         memory_ce,     (void *)(&tempL), 0},
491
{4, "baseaddr",           "=0x%x",       memory_baseaddr,(void *)(&tempUL), 0},
492
{4, "size",               "=0x%x",       memory_size,   (void *)(&tempUL), 0},
493
{4, "name",               "=\"%s\"",     memory_name,   (void *)(&tempS[0]), 0},
494
{4, "log",                "=\"%s\"",     memory_log,    (void *)(&tempS[0]), 0},
495
{4, "delayr",             "=%i",         memory_delayr, (void *)(&tempL), 0},
496
{4, "delayw",             "=%i",         memory_delayw, (void *)(&tempL), 0},
497 424 markom
 
498 549 markom
{5, "ver",                "=0x%x",       NULL,          (void *)(&config.cpu.ver), 0},
499
{5, "rev",                "=0x%x",       NULL,          (void *)(&config.cpu.rev), 0},
500
{5, "upr",                "=0x%x",       NULL,          (void *)(&config.cpu.upr), 0},
501 557 markom
{5, "sr",                 "=0x%x",       NULL,          (void *)(&config.cpu.sr), 0},
502 549 markom
{5, "hazards",            "=%i",         NULL,          (void *)(&config.cpu.hazards), 0},
503
{5, "superscalar",        "=%i",         NULL,          (void *)(&config.cpu.superscalar), 0},
504
{5, "dependstats",        "=%i",         NULL,          (void *)(&config.cpu.dependstats), 0},
505
{5, "raw_range",          "=%i",         cpu_raw_range, (void *)(&config.cpu.raw_range), 0},
506 626 markom
{5, "sbuf_len",           "=%i",         cpu_sbuf_len,  (void *)(&config.cpu.sbuf_len), 0},
507 549 markom
 
508
{6, "debug",              "=%i",         NULL,          (void *)(&config.sim.debug), 0},
509
{6, "verbose",            "=%i",         NULL,          (void *)(&config.sim.verbose), 0},
510
{6, "profile",            "=%i",         NULL,          (void *)(&config.sim.profile), 0},
511
{6, "prof_fn",            "=\"%s\"",     NULL,          (void *)(&config.sim.prof_fn[0]), 0},
512
{6, "mprofile",           "=%i",         NULL,          (void *)(&config.sim.mprofile), 0},
513
{6, "mprof_fn",           "=\"%s\"",     NULL,          (void *)(&config.sim.mprof_fn[0]), 0},
514
{6, "history",            "=%i",         NULL,          (void *)(&config.sim.history), 0},
515
{6, "exe_log",            "=%i",         NULL,          (void *)(&config.sim.exe_log), 0},
516
{6, "exe_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.exe_log_fn[0]), 0},
517 624 ivang
{6, "spr_log",            "=%i",         NULL,          (void *)(&config.sim.spr_log), 0},
518
{6, "spr_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.spr_log_fn[0]), 0},
519 549 markom
{6, "clkcycle",           "=%s ",        sim_clkcycle,  (void *)(&tempS[0]), 0},
520 424 markom
 
521 549 markom
{7, "enabled",            "=%i",         NULL,          (void *)(&config.debug.enabled), 0},
522
{7, "gdb_enabled",        "=%i",         NULL,          (void *)(&config.debug.gdb_enabled), 0},
523
{7, "server_port",        "=%i",         NULL,          (void *)(&config.debug.server_port), 0},
524
{7, "vapi_id",            "=0x%x",       NULL,          (void *)(&config.debug.vapi_id), 0},
525
 
526
{8, "enabled",            "=%i",         NULL,          (void *)(&config.vapi.enabled), 0},
527
{8, "server_port",        "=%i",         NULL,          (void *)(&config.vapi.server_port), 0},
528
{8, "log_enabled",        "=%i",         NULL,          (void *)(&config.vapi.log_enabled), 0},
529
{8, "hide_device_id",     "=%i",         NULL,          (void *)(&config.vapi.hide_device_id), 0},
530
{8, "vapi_log_fn",        "=\"%s\"",     NULL,          (void *)(&config.vapi.vapi_fn[0]), 0},
531
 
532
{9, "nethernets",         "=%i",         eth_nethernets,(void *)(&tempL), CPF_GLOBAL},
533
{9, "device",             "%i",          change_device, (void *)(&tempL), 0},
534
{9, "enddevice",          "",            end_device,    NULL, 0},
535
{9, "baseaddr",           "=0x%x",       eth_baseaddr,  (void *)(&tempUL), 0},
536
{9, "dma",                "=%i",         eth_dma,       (void *)(&tempL), 0},
537
{9, "rx_channel",         "=%i",         eth_rx_channel,(void *)(&tempL), 0},
538
{9, "tx_channel",         "=%i",         eth_tx_channel,(void *)(&tempL), 0},
539
{9, "rxfile",             "=\"%s\"",     eth_rxfile,    (void *)(&tempS[0]), 0},
540
{9, "txfile",             "=\"%s\"",     eth_txfile,    (void *)(&tempS[0]), 0},
541
{9, "vapi_id",            "=0x%x",       eth_vapi_id,   (void *)(&tempUL), 0},
542
 
543
{10, "enabled",           "=%i",         NULL,          (void *)(&config.tick.enabled), 0},
544
 
545
{11, "enabled",           "=%i",         immu_enabled,  (void *)(&tempL), 0},
546
{11, "nsets",             "=%i",         immu_nsets,    (void *)(&tempL), 0},
547
{11, "nways",             "=%i",         immu_nways,    (void *)(&tempL), 0},
548
{11, "pagesize",          "=%i",         immu_pagesize, (void *)(&tempL), 0},
549
{11, "entrysize",         "=%i",         immu_entrysize,(void *)(&tempL), 0},
550
{11, "ustates",           "=%i",         immu_ustates,  (void *)(&tempL), 0},
551
{11, "missdelay",         "=%i",         NULL,          (void *)(&config.immu.missdelay), 0},
552
{11, "hitdelay",          "=%i",         NULL,          (void *)(&config.immu.hitdelay), 0},
553
 
554
{12, "enabled",           "=%i",         dmmu_enabled,  (void *)(&tempL), 0},
555
{12, "nsets",             "=%i",         dmmu_nsets,    (void *)(&tempL), 0},
556
{12, "nways",             "=%i",         dmmu_nways,    (void *)(&tempL), 0},
557
{12, "pagesize",          "=%i",         dmmu_pagesize, (void *)(&tempL), 0},
558
{12, "entrysize",         "=%i",         dmmu_entrysize,(void *)(&tempL), 0},
559
{12, "ustates",           "=%i",         dmmu_ustates,  (void *)(&tempL), 0},
560
{12, "missdelay",         "=%i",         NULL,          (void *)(&config.dmmu.missdelay), 0},
561
{12, "hitdelay",          "=%i",         NULL,          (void *)(&config.dmmu.hitdelay), 0},
562
 
563
{13, "enabled",           "=%i",         ic_enabled,    (void *)(&tempL), 0},
564
{13, "nsets",             "=%i",         ic_nsets,      (void *)(&tempL), 0},
565
{13, "nways",             "=%i",         ic_nways,      (void *)(&tempL), 0},
566
{13, "blocksize",         "=%i",         ic_blocksize,  (void *)(&tempL), 0},
567
{13, "ustates",           "=%i",         ic_ustates,    (void *)(&tempL), 0},
568
{13, "missdelay",         "=%i",         NULL,          (void *)(&config.ic.missdelay), 0},
569
{13, "hitdelay",          "=%i",         NULL,          (void *)(&config.ic.hitdelay), 0},
570
 
571
{14, "enabled",           "=%i",         dc_enabled,    (void *)(&tempL), 0},
572
{14, "nsets",             "=%i",         dc_nsets,      (void *)(&tempL), 0},
573
{14, "nways",             "=%i",         dc_nways,      (void *)(&tempL), 0},
574
{14, "blocksize",         "=%i",         dc_blocksize,  (void *)(&tempL), 0},
575
{14, "ustates",           "=%i",         dc_ustates,    (void *)(&tempL), 0},
576
{14, "load_missdelay",    "=%i",         NULL,          (void *)(&config.dc.load_missdelay), 0},
577
{14, "load_hitdelay",     "=%i",         NULL,          (void *)(&config.dc.load_hitdelay), 0},
578
{14, "store_missdelay",   "=%i",         NULL,          (void *)(&config.dc.store_missdelay), 0},
579
{14, "store_hitdelay",    "=%i",         NULL,          (void *)(&config.dc.store_hitdelay), 0},
580
 
581
{15, "ngpios",            "=%i",         gpio_ngpios,   (void *)(&tempL), CPF_GLOBAL},
582
{15, "device",            "%i",          change_device, (void *)(&tempL), 0},
583
{15, "baseaddr",          "=0x%x",       gpio_baseaddr, (void *)(&tempUL), 0},
584
{15, "irq",               "=%i",         gpio_irq,      (void *)(&tempL), 0},
585
{15, "base_vapi_id",      "=0x%x",       gpio_base_vapi_id,   (void *)(&tempUL), 0},
586
{15, "enddevice",         "",            end_device,    NULL, 0},
587
 
588
{16, "enabled",           "=%i",         NULL,          (void *)(&config.bpb.enabled), 0},
589
{16, "btic",              "=%i",         NULL,          (void *)(&config.bpb.btic), 0},
590
{16, "sbp_bnf_fwd",       "=%i",         NULL,          (void *)(&config.bpb.sbp_bnf_fwd), 0},
591
{16, "sbp_bf_fwd",        "=%i",         NULL,          (void *)(&config.bpb.sbp_bf_fwd), 0},
592
{16, "missdelay",         "=%i",         NULL,          (void *)(&config.bpb.missdelay), 0},
593 557 markom
{16, "hitdelay",          "=%i",         NULL,          (void *)(&config.bpb.hitdelay), 0},
594
 
595
{17, "enabled",           "=%i",         NULL,          (void *)(&config.pm.enabled), 0}
596 424 markom
};
597
 
598
/* *INDENT-ON* */
599
 
600
int current_device = -1;
601
void change_device () {
602
  current_device = tempL;
603
}
604
 
605
void end_device () {
606
  current_device = -1;
607
}
608
 
609 568 markom
void base_include () {
610
  read_script_file (tempS);
611
  section = 0;
612
}
613
 
614 433 markom
void sim_clkcycle () {
615
  int len = strlen (tempS);
616
  int pos = len - 1;
617
  long time;
618
  if (len < 2) goto err;
619
  if (tempS[pos--] != 's') goto err;
620
  switch (tempS[pos--]) {
621
    case 'p': time = 1; break;
622
    case 'n': time = 1000; break;
623
    case 'u': time = 1000000; break;
624
    case 'm': time = 1000000000; break;
625
  default:
626
    goto err;
627
  }
628 490 markom
  tempS[pos + 1] = 0;
629 433 markom
  config.sim.clkcycle_ps = time * atol (tempS);
630
  return;
631
err:
632
  ERROR("invalid time format.");
633
}
634
 
635 424 markom
void uart_nuarts () {
636
  if (tempL >= 0 && tempL < MAX_UARTS)
637
    config.nuarts = tempL;
638
  else
639
    ERROR("invalid number of devices.");
640
}
641
 
642
void uart_baseaddr () {
643
  if (current_device >= 0 && current_device < config.nuarts)
644
    config.uarts[current_device].baseaddr = tempUL;
645
  else
646
    ERROR("invalid device number.");
647
}
648
 
649
void uart_jitter () {
650
  if (current_device >= 0 && current_device < config.nuarts)
651
    config.uarts[current_device].jitter = tempL;
652
  else
653
    ERROR("invalid device number.");
654
}
655
 
656
void uart_irq () {
657
  if (current_device >= 0 && current_device < config.nuarts)
658
    config.uarts[current_device].irq = tempL;
659
  else
660
    ERROR("invalid device number.");
661
}
662
 
663
void uart_16550 () {
664
  if (current_device >= 0 && current_device < config.nuarts)
665
    config.uarts[current_device].uart16550 = tempL;
666
  else
667
    ERROR("invalid device number.");
668
}
669
 
670
void uart_rxfile () {
671
  if (current_device >= 0 && current_device < config.nuarts)
672
    strcpy (config.uarts[current_device].rxfile, tempS);
673
  else
674
    ERROR("invalid device number.");
675
}
676
 
677
void uart_txfile () {
678
  if (current_device >= 0 && current_device < config.nuarts)
679
    strcpy (config.uarts[current_device].txfile, tempS);
680
  else
681
    ERROR("invalid device number.");
682
}
683
 
684
void uart_vapi_id () {
685
  if (current_device >= 0 && current_device < config.nuarts)
686
    config.uarts[current_device].vapi_id = tempUL;
687
  else
688
    ERROR("invalid device number.");
689
}
690
 
691
void dma_ndmas () {
692
  if (tempL >= 0 && tempL < MAX_DMAS)
693
    config.ndmas = tempL;
694
  else
695
    ERROR("invalid number of devices.");
696
}
697
 
698
void dma_baseaddr () {
699
  if (current_device >= 0 && current_device < config.ndmas)
700
    config.dmas[current_device].baseaddr = tempUL;
701
  else
702
    ERROR("invalid device number.");
703
}
704
 
705
void dma_irq () {
706
  if (current_device >= 0 && current_device < config.ndmas)
707
    config.dmas[current_device].irq = tempL;
708
  else
709
    ERROR("invalid device number.");
710
}
711
 
712
void dma_vapi_id () {
713
  if (current_device >= 0 && current_device < config.ndmas)
714
    config.dmas[current_device].vapi_id = tempUL;
715
  else
716
    ERROR("invalid device number.");
717
}
718
 
719
void memory_nmemories () {
720
  if (tempL >= 0 && tempL < MAX_MEMORIES)
721
    config.memory.nmemories = tempL;
722
  else
723
    ERROR("invalid number of devices.");
724
}
725
 
726
void memory_type () {
727
  if (strcmp (tempS, "unknown") == 0)
728
    config.memory.type = MT_UNKNOWN;
729
  else if (strcmp (tempS, "random") == 0)
730
    config.memory.type = MT_RANDOM;
731
  else if (strcmp (tempS, "pattern") == 0)
732
    config.memory.type = MT_PATTERN;
733
  else if (strcmp (tempS, "zero") == 0) {
734
    config.memory.type = MT_PATTERN;
735
    config.memory.pattern = 0;
736
  } else {
737
    char tmp[200];
738
    sprintf (tmp, "invalid memory type '%s'.\n", tempS);
739
    ERROR(tmp);
740
  }
741
}
742
 
743
void memory_ce () {
744
  if (current_device >= 0 && current_device < config.memory.nmemories)
745
    config.memory.table[current_device].ce = tempL;
746
  else
747
    ERROR("invalid device number.");
748
}
749
 
750
void memory_baseaddr () {
751
  if (current_device >= 0 && current_device < config.memory.nmemories)
752
    config.memory.table[current_device].baseaddr = tempUL;
753
  else
754
    ERROR("invalid device number.");
755
}
756
 
757
void memory_size () {
758
  if (current_device >= 0 && current_device < config.memory.nmemories)
759
    config.memory.table[current_device].size = tempUL;
760
  else
761
    ERROR("invalid device number.");
762
}
763
 
764
void memory_name () {
765
  if (current_device >= 0 && current_device < config.memory.nmemories)
766
    strcpy (config.memory.table[current_device].name, tempS);
767
  else
768
    ERROR("invalid device number.");
769
}
770
 
771
void memory_log () {
772
  if (current_device >= 0 && current_device < config.memory.nmemories)
773
    strcpy (config.memory.table[current_device].log, tempS);
774
  else
775
    ERROR("invalid device number.");
776
}
777
 
778
void memory_delayr () {
779
  if (current_device >= 0 && current_device < config.memory.nmemories)
780
    config.memory.table[current_device].delayr = tempL;
781
  else
782
    ERROR("invalid device number.");
783
}
784
 
785
void memory_delayw () {
786
  if (current_device >= 0 && current_device < config.memory.nmemories)
787
    config.memory.table[current_device].delayw = tempL;
788
  else
789
    ERROR("invalid device number.");
790
}
791
 
792 535 markom
void cpu_raw_range () {
793
  if (config.cpu.raw_range >= RAW_RANGE) {
794
    config.cpu.raw_range = RAW_RANGE - 1;
795
    WARNING("raw range too large; truncated.");
796
  } else if (config.cpu.raw_range < 0) {
797
    config.cpu.raw_range = 0;
798
    WARNING("raw range negative; disabled.");
799
  }
800
}
801
 
802 626 markom
void cpu_sbuf_len () {
803
  if (config.cpu.sbuf_len >= MAX_SBUF_LEN) {
804
    config.cpu.sbuf_len = MAX_SBUF_LEN - 1;
805
    WARNING("sbuf_len too large; truncated.");
806
  } else if (config.cpu.sbuf_len < 0) {
807
    config.cpu.sbuf_len = 0;
808
    WARNING("sbuf_len negative; disabled.");
809
  }
810
}
811
 
812 424 markom
void eth_nethernets () {
813
  if (tempL >= 0 && tempL < MAX_ETHERNETS)
814
    config.nethernets = tempL;
815
  else
816
    ERROR("invalid number of devices.");
817
}
818
 
819
void eth_baseaddr () {
820
  if (current_device >= 0 && current_device < config.nethernets)
821
    config.ethernets[current_device].baseaddr = tempUL;
822
  else
823
    ERROR("invalid device number.");
824
}
825
 
826
void eth_dma () {
827
  if (current_device >= 0 && current_device < config.nethernets)
828
    config.ethernets[current_device].dma = tempL;
829
  else
830
    ERROR("invalid device number.");
831
}
832
 
833
void eth_rx_channel () {
834
  if (current_device >= 0 && current_device < config.nethernets)
835
    config.ethernets[current_device].rx_channel = tempL;
836
  else
837
    ERROR("invalid device number.");
838
}
839
 
840
void eth_tx_channel () {
841
  if (current_device >= 0 && current_device < config.nethernets)
842
    config.ethernets[current_device].rx_channel = tempL;
843
  else
844
    ERROR("invalid device number.");
845
}
846
 
847
void eth_rxfile () {
848
  if (current_device >= 0 && current_device < config.nethernets)
849
    strcpy (config.ethernets[current_device].rxfile, tempS);
850
  else
851
    ERROR("invalid device number.");
852
}
853
 
854
void eth_txfile () {
855
  if (current_device >= 0 && current_device < config.nethernets)
856
    strcpy (config.ethernets[current_device].txfile, tempS);
857
  else
858
    ERROR("invalid device number.");
859
}
860
 
861
void eth_vapi_id () {
862
  if (current_device >= 0 && current_device < config.nethernets)
863
    config.ethernets[current_device].vapi_id = tempUL;
864
  else
865 425 markom
    ERROR("invalid device number.");
866 424 markom
}
867
 
868 444 erez
void gpio_ngpios () {
869
  if (tempL >= 0 && tempL < MAX_GPIOS)
870
    config.ngpios = tempL;
871
  else
872
    ERROR("invalid number of devices.");
873
}
874
 
875
void gpio_baseaddr () {
876
  if (current_device >= 0 && current_device < config.ngpios)
877
    config.gpios[current_device].baseaddr = tempUL;
878
  else
879
    ERROR("invalid device number.");
880
}
881
 
882
void gpio_irq () {
883
  if (current_device >= 0 && current_device < config.ngpios)
884
    config.gpios[current_device].irq = tempL;
885
  else
886
    ERROR("invalid device number.");
887
}
888
 
889 477 erez
void gpio_base_vapi_id () {
890 444 erez
  if (current_device >= 0 && current_device < config.ngpios)
891 477 erez
    config.gpios[current_device].base_vapi_id = tempUL;
892 444 erez
  else
893
    ERROR("invalid device number.");
894
}
895
 
896 425 markom
int is_power2 (int x) {
897
  while (!(x & 1))
898
    x >>= 1;
899
  return x == 1;
900
}
901 424 markom
 
902 425 markom
void immu_enabled () {
903
  setsprbits (SPR_UPR, SPR_UPR_IMP, tempL & 1);
904 572 simons
  config.immu.enabled = tempL;
905 425 markom
}
906 424 markom
 
907 425 markom
void dmmu_enabled () {
908
  setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1);
909 572 simons
  config.dmmu.enabled = tempL;
910 425 markom
}
911
 
912
void immu_nsets () {
913
  if (is_power2(tempL) && tempL <= 256)
914
    config.immu.nsets = tempL;
915
  else
916 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
917 425 markom
}
918
 
919
void dmmu_nsets () {
920
  if (is_power2(tempL) && tempL <= 256)
921
    config.dmmu.nsets = tempL;
922
  else
923 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
924 425 markom
}
925
 
926
void immu_nways () {
927
  if (tempL >= 1 && tempL <= 4)
928
    config.immu.nways = tempL;
929
  else
930
    ERROR("value 1, 2, 3 or 4 expected.");
931
}
932
 
933
void dmmu_nways () {
934
  if (tempL >= 1 && tempL <= 4)
935
    config.dmmu.nways = tempL;
936
  else
937
    ERROR("value 1, 2, 3 or 4 expected.");
938
}
939
 
940
void immu_pagesize () {
941
  if (is_power2(tempL))
942
    config.immu.pagesize = tempL;
943
  else
944 428 markom
    ERROR("value of power of two expected.");
945 425 markom
}
946
 
947
void dmmu_pagesize () {
948
  if (is_power2(tempL))
949
    config.dmmu.pagesize = tempL;
950
  else
951 428 markom
    ERROR("value of power of two expected.");
952 425 markom
}
953
 
954
void immu_entrysize () {
955
  if (is_power2(tempL))
956
    config.immu.entrysize = tempL;
957
  else
958 428 markom
    ERROR("value of power of two expected.");
959 425 markom
}
960
 
961
void dmmu_entrysize () {
962
  if (is_power2(tempL))
963
    config.dmmu.entrysize = tempL;
964
  else
965 428 markom
    ERROR("value of power of two expected.");
966 425 markom
}
967
 
968
void immu_ustates () {
969
  if (tempL >= 2 && tempL <= 4)
970
    config.immu.ustates = tempL;
971
  else
972
    ERROR("invalid USTATE.");
973
}
974
 
975
void dmmu_ustates () {
976
  if (tempL >= 2 && tempL <= 4)
977
    config.dmmu.ustates = tempL;
978
  else
979
    ERROR("invalid USTATE.");
980
}
981
 
982 428 markom
void ic_enabled () {
983 574 markom
  config.ic.enabled = tempL;
984 428 markom
  setsprbits (SPR_UPR, SPR_UPR_ICP, tempL & 1);
985
}
986
 
987
void ic_nsets () {
988
  if (is_power2(tempL) && tempL <= MAX_IC_SETS)
989
    config.ic.nsets = tempL;
990
  else {
991
    char tmp[200];
992
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_IC_SETS);
993
    ERROR(tmp);
994
  }
995
}
996
 
997
void ic_nways () {
998
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
999
    config.ic.nways = tempL;
1000
  else
1001
    ERROR("value 1, 2, 3 or 4 expected.");
1002
}
1003
 
1004
void ic_blocksize () {
1005
  if (is_power2(tempL))
1006
    config.ic.blocksize = tempL;
1007
  else
1008
    ERROR("value of power of two expected.");
1009
}
1010
 
1011
void ic_ustates () {
1012
  if (tempL >= 2 && tempL <= 4)
1013
    config.ic.ustates = tempL;
1014
  else
1015
    ERROR("invalid USTATE.");
1016
}
1017
 
1018
void dc_enabled () {
1019 574 markom
  config.dc.enabled = tempL;
1020 428 markom
  setsprbits (SPR_UPR, SPR_UPR_DCP, tempL & 1);
1021
}
1022
 
1023
void dc_nsets () {
1024
  if (is_power2(tempL) && tempL <= MAX_DC_SETS)
1025
    config.dc.nsets = tempL;
1026
  else {
1027
    char tmp[200];
1028
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
1029
    ERROR(tmp);
1030
  }
1031
}
1032
 
1033
void dc_nways () {
1034
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
1035
    config.dc.nways = tempL;
1036
  else
1037
    ERROR("value 1, 2, 3 or 4 expected.");
1038
}
1039
 
1040
void dc_blocksize () {
1041
  if (is_power2(tempL))
1042
    config.dc.blocksize = tempL;
1043
  else
1044
    ERROR("value of power of two expected.");
1045
}
1046
 
1047
void dc_ustates () {
1048
  if (tempL >= 2 && tempL <= 4)
1049
    config.dc.ustates = tempL;
1050
  else
1051
    ERROR("invalid USTATE.");
1052
}
1053
 
1054 424 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
1055
   The syntax of script file is:
1056
   param = value
1057
   section x
1058
     data
1059
     param = value
1060
   end
1061
 
1062
   Example:
1063
   section mc
1064
     memory_table_file = sim.mem
1065
     enable = 1
1066
     POC = 0x47892344
1067
   end
1068
 
1069
 */
1070
 
1071
void read_script_file (char *filename)
1072
{
1073
  FILE *f;
1074
  unsigned long memory_needed = 0;
1075
  char *home = getenv("HOME");
1076
  char ctmp[STR_SIZE];
1077
  int local = 1;
1078
  section = 0;
1079
 
1080
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
1081
  if ((f = fopen (filename, "rt")) != NULL
1082
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
1083
    unsigned long start, length;
1084
    char type[STR_SIZE];
1085
    int nparam;
1086
    int rd, wd;
1087 549 markom
    if (config.sim.verbose && !runtime.sim.output_cfg)
1088 428 markom
      printf ("Reading script file from '%s'...\n", local ? filename : ctmp);
1089 549 markom
    strcpy (runtime.sim.script_fn, local ? filename : ctmp);
1090
 
1091 424 markom
    while (!feof(f)) {
1092
      char param[STR_SIZE];
1093
      if (fscanf(f, "%s ", &param) != 1) break;
1094
      /* Is this a sections? */
1095
      if (strcmp (param, "section") == 0) {
1096
        int i;
1097
        section = 0;
1098
        if (fscanf (f, "%s\n", &param) != 1) {
1099
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
1100
          exit (1);
1101
        }
1102
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1103
          if (strcmp (sections[i].name, param) == 0) {
1104
            section = i;
1105
            break;
1106
          }
1107
        if (!section) {
1108
          char tmp[200];
1109
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
1110
          WARNING(tmp);
1111
          /* just skip section */
1112
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
1113
        }
1114
      } else if (strcmp (param, "end") == 0) {
1115
        section = 0;
1116
      } else if (strncmp (param, "/*", 2) == 0) {
1117
        char c0 = 0, c1 = 0;
1118
        while (c0 != '*' || c1 != '/') {
1119
          c0 = c1;
1120
          c1 = fgetc(f);
1121
          if (feof(f)) {
1122
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
1123
            exit (1);
1124
          }
1125
        }
1126
      } else {
1127
        int i, found = -1;
1128
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1129
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
1130
            found = i;
1131
            break;
1132
          }
1133
        if (found < 0) {
1134
          char tmp[200];
1135
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
1136
          WARNING(tmp);
1137
          while (fgetc(f) != '\n' || feof(f));
1138
          continue;
1139
        }
1140
 
1141
        /* Parse parameter value */
1142
        {
1143
          if (config_params[found].type[0])
1144
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
1145
              exit (1);
1146
        }
1147
        if (config_params[found].func)
1148
          config_params[found].func();
1149
      }
1150
    }
1151
    fclose (f);
1152
    runtime.sim.script_file_specified = 1;
1153
  } else
1154
    if (config.sim.verbose)
1155
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
1156
}
1157
 
1158
/* Utility for execution of set sim command.  */
1159
static int set_config (char *s)
1160
{
1161
  char *sec, *item, *params;
1162
  int noparams = 0, i, noitem = 0;
1163 434 markom
  while (*s && isspace (*s)) s++;
1164 424 markom
  sec = s;
1165
  printf ("s:%s\n", s);
1166
  while (*s && *s != ' ') s++;
1167
  if (!(*s)) noitem = 1;
1168
  *s = 0;
1169
  printf ("sec:%s\n", sec);
1170
  section = 0;
1171
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1172
    if (strcmp (sections[i].name, sec) == 0) {
1173
      section = i;
1174
      break;
1175
    }
1176
 
1177
  if (!section) return 1;
1178
  if (noitem) return 2;
1179
 
1180
  item = ++s;
1181
 
1182
  while (*s && *s != ' ') s++;
1183
  if (!(*s)) {
1184
    noparams = 1;
1185
    params = "";
1186
  } else
1187
    params = s + 1;
1188
  *s = 0;
1189
  printf ("item:%s\n", item);
1190
  printf ("params:%s\n", params);
1191
  {
1192
    int i, found = -1;
1193
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1194
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
1195
        found = i;
1196
        break;
1197
      }
1198
    if (found < 0) return 2;
1199
 
1200
    /* Parse parameter value */
1201
    if (config_params[found].type[0])
1202
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
1203
        return 3;
1204
    if (config_params[found].func)
1205
      config_params[found].func();
1206
  }
1207
  return 0;
1208
}
1209
 
1210
/* Executes set sim command, displays error.  */
1211
void set_config_command(char *s)
1212
{
1213
  int i;
1214
  switch (set_config (s)) {
1215
    case 1:
1216
      printf ("Invalid or missing section name.  One of valid sections must be specified:\n");
1217
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1218
        printf ("%s ", sections[i].name);
1219
      printf ("\n");
1220
      break;
1221
    case 2:
1222
      printf ("Invalid or missing item name.  One of valid items must be specified:\n");
1223
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1224
        if (config_params[i].section == section)
1225
          printf ("%s ", config_params[i].name);
1226
      printf ("\n");
1227
      break;
1228
    case 3:
1229
      printf ("Invalid parameters specified.\n");
1230
      break;
1231
  }
1232
}
1233 551 markom
#endif /* !FAST_SIM */
1234 549 markom
 
1235
/* Outputs C structure of current config to file */
1236
void output_cfg (FILE *f)
1237
{
1238
  int i, comma;
1239
  fprintf (f, "/* This file was automatically generated by or1ksim,\n"
1240
              "   using --output-cfg switch (cfg file '%s'). */\n"
1241
  "const static struct config config = {\n", runtime.sim.script_fn);
1242
 
1243 599 simons
  fprintf (f, "  tick:{enabled:%i},\n", config.tick.enabled);
1244 549 markom
  fprintf (f, "  nuarts:%i, uarts:{", config.nuarts);
1245
  comma = 0;
1246
  for (i = 0; i < config.nuarts; i++) {
1247
    fprintf (f, "%s\n    {rxfile:\"%s\", txfile:\"%s\", jitter:%i, baseaddr:0x%08x, irq:%i, vapi_id:0x%08x, uart16550:%i}",
1248
      comma ? "," :"", config.uarts[i].rxfile, config.uarts[i].txfile, config.uarts[i].jitter, config.uarts[i].baseaddr, config.uarts[i].irq,
1249
      config.uarts[i].vapi_id, config.uarts[i].uart16550);
1250
    comma = 1;
1251
  }
1252
  fprintf (f, "},\n");
1253
 
1254
  fprintf (f, "  ndmas:%i, dmas:{", config.ndmas);
1255
  comma = 0;
1256
  for (i = 0; i < config.ndmas; i++) {
1257
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, vapi_id:0x%08x}",
1258
      comma ? "," :"", config.dmas[i].baseaddr, config.dmas[i].irq, config.dmas[i].vapi_id);
1259
    comma = 1;
1260
  }
1261
  fprintf (f, "},\n");
1262
 
1263
  fprintf (f, "  nethernets:%i, ethernets:{", config.nethernets);
1264
  comma = 0;
1265
  for (i = 0; i < config.nethernets; i++) {
1266
    fprintf (f, "%s\n    {baseaddr:0x%08x, dma:%i, tx_channel:0x%08x, rx_channel:0x%08x, rxfile:\"%s\", txfile:\"%s\", vapi_id:0x%08x}",
1267
      comma ? "," :"", config.ethernets[i].baseaddr, config.ethernets[i].dma, config.ethernets[i].tx_channel, config.ethernets[i].rx_channel,
1268
      config.ethernets[i].rxfile, config.ethernets[i].txfile, config.ethernets[i].vapi_id);
1269
    comma = 1;
1270
  }
1271
  fprintf (f, "},\n");
1272
 
1273
  fprintf (f, "  ngpios:%i, gpios:{", config.ngpios);
1274
  comma = 0;
1275
  for (i = 0; i < config.ngpios; i++) {
1276
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, base_vapi_id:0x%08x}",
1277
      comma ? "," :"", config.gpios[i].baseaddr, config.gpios[i].irq, config.gpios[i].base_vapi_id);
1278
    comma = 1;
1279
  }
1280
  fprintf (f, "},\n");
1281
 
1282
  fprintf (f, "  mc:{enabled:%i, baseaddr:%i, POC:%i},\n", config.mc.enabled, config.mc.baseaddr, config.mc.POC);
1283
  fprintf (f, "  memory:{pattern:%i, random_seed:%i, type:%s, nmemories:%i, table:{", config.memory.pattern, config.memory.random_seed,
1284
    config.memory.type == MT_UNKNOWN ? "MT_UNKNOWN" : config.memory.type == MT_PATTERN ? "MT_PATTERN" : "MT_RANDOM", config.memory.nmemories);
1285
  comma = 0;
1286
  for (i = 0; i < config.memory.nmemories; i++) {
1287
    fprintf (f, "%s\n    {ce:%i, baseaddr:0x%08x, size:0x%08x, name:\"%s\", log:\"%s\", delayr:%i, delayw:%i}",
1288
      comma ? "," :"", config.memory.table[i].ce, config.memory.table[i].baseaddr, config.memory.table[i].size, config.memory.table[i].name,
1289
      config.memory.table[i].log, config.memory.table[i].delayr, config.memory.table[i].delayw);
1290
    comma = 1;
1291
  }
1292
  fprintf (f, "}},\n");
1293
 
1294
  fprintf (f, "  immu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1295
    config.immu.enabled, config.immu.nways, config.immu.nsets, config.immu.pagesize, config.immu.entrysize, config.immu.ustates,
1296
    config.immu.missdelay, config.immu.hitdelay);
1297
 
1298
  fprintf (f, "  dmmu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1299
    config.dmmu.enabled, config.dmmu.nways, config.dmmu.nsets, config.dmmu.pagesize, config.dmmu.entrysize, config.dmmu.ustates,
1300
    config.dmmu.missdelay, config.dmmu.hitdelay);
1301
 
1302 631 simons
  fprintf (f, "  ic:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1303
    config.ic.enabled, config.ic.nways, config.ic.nsets, config.ic.blocksize, config.ic.ustates,
1304 549 markom
    config.ic.missdelay, config.ic.hitdelay);
1305
 
1306 631 simons
  fprintf (f, "  dc:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i,\n"
1307 557 markom
    "    load_missdelay:%i, load_hitdelay:%i, store_missdelay:%i, store_hitdelay:%i},\n",
1308 631 simons
    config.dc.enabled, config.dc.nways, config.dc.nsets, config.dc.blocksize, config.dc.ustates,
1309 549 markom
    config.dc.load_missdelay, config.dc.load_hitdelay, config.dc.store_missdelay, config.dc.store_hitdelay);
1310
 
1311
  fprintf (f, "  bpb:{enabled:%i, sbp_bnf_fwd:%i, sbp_bf_fwd:%i, btic:%i, missdelay:%i, hitdelay:%i},\n",
1312
    config.bpb.enabled, config.bpb.sbp_bnf_fwd, config.bpb.sbp_bf_fwd, config.bpb.btic, config.bpb.missdelay, config.bpb.hitdelay);
1313
 
1314 557 markom
  fprintf (f, "  cpu:{upr:0x%08x, ver:0x%04x, rev:0x%04x, superscalar:%i, hazards:%i, dependstats:%i,\n"
1315
    "    raw_range:%i, sr:0x%08x},\n",
1316
    config.cpu.upr, config.cpu.ver, config.cpu.rev, config.cpu.superscalar, config.cpu.hazards, config.cpu.dependstats,
1317
    config.cpu.raw_range, config.cpu.sr);
1318 549 markom
 
1319 551 markom
  fprintf (f, "  sim:{debug:%i, verbose:%i, profile:%i, prof_fn:\"%s\", mprofile:%i, mprof_fn:\"%s\",\n",
1320
    config.sim.debug, config.sim.verbose, config.sim.profile, config.sim.prof_fn, config.sim.mprofile, config.sim.mprof_fn);
1321 549 markom
 
1322 624 ivang
  fprintf (f, "    history:%i, exe_log:%i, exe_log_fn:\"%s\", clkcycle_ps:%i,\n",
1323 549 markom
    config.sim.history, config.sim.exe_log, config.sim.exe_log_fn, config.sim.clkcycle_ps);
1324
 
1325 624 ivang
  fprintf (f, "    spr_log:%i, spr_log_fn:\"%s\"},\n",
1326
    config.sim.spr_log, config.sim.spr_log_fn);
1327
 
1328 549 markom
  fprintf (f, "  debug:{enabled:%i, gdb_enabled:%i, server_port:%i, vapi_id:0x%08x},\n",
1329
    config.debug.enabled, config.debug.gdb_enabled, config.debug.server_port, config.debug.vapi_id);
1330
 
1331 557 markom
  fprintf (f, "  vapi:{enabled:%i, server_port:%i, log_enabled:%i, hide_device_id:%i, vapi_fn:\"%s\"},\n",
1332 549 markom
    config.vapi.enabled, config.vapi.server_port, config.vapi.log_enabled, config.vapi.hide_device_id, config.vapi.vapi_fn);
1333 557 markom
 
1334
  fprintf (f, "  pm:{enabled:%i}\n",
1335
    config.pm.enabled);
1336 549 markom
 
1337
  fprintf (f, "};\n");
1338
}

powered by: WebSVN 2.1.0

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