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 645

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

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

powered by: WebSVN 2.1.0

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