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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [sim-config.c] - Blame information for rev 648

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 647 markom
{19, "baseaddr",          "=0x%x",       NULL,          (void *)(&config.fb.baseaddr), 0},
624 645 markom
{19, "refresh_rate",      "=%i",         NULL,          (void *)(&config.fb.refresh_rate), 0},
625
{19, "filename",          "=\"%s\"",     NULL,          (void *)(&config.fb.filename), 0}
626
};
627
 
628
/* *INDENT-ON* */
629
 
630
int current_device = -1;
631
void change_device () {
632
  current_device = tempL;
633
}
634
 
635
void end_device () {
636
  current_device = -1;
637
}
638
 
639
void base_include () {
640
  read_script_file (tempS);
641
  section = 0;
642
}
643
 
644
void sim_clkcycle () {
645
  int len = strlen (tempS);
646
  int pos = len - 1;
647
  long time;
648
  if (len < 2) goto err;
649
  if (tempS[pos--] != 's') goto err;
650
  switch (tempS[pos--]) {
651
    case 'p': time = 1; break;
652
    case 'n': time = 1000; break;
653
    case 'u': time = 1000000; break;
654
    case 'm': time = 1000000000; break;
655
  default:
656
    goto err;
657
  }
658
  tempS[pos + 1] = 0;
659
  config.sim.clkcycle_ps = time * atol (tempS);
660
  return;
661
err:
662
  ERROR("invalid time format.");
663
}
664
 
665
void uart_nuarts () {
666
  if (tempL >= 0 && tempL < MAX_UARTS)
667
    config.nuarts = tempL;
668
  else
669
    ERROR("invalid number of devices.");
670
}
671
 
672
void uart_baseaddr () {
673
  if (current_device >= 0 && current_device < config.nuarts)
674
    config.uarts[current_device].baseaddr = tempUL;
675
  else
676
    ERROR("invalid device number.");
677
}
678
 
679
void uart_jitter () {
680
  if (current_device >= 0 && current_device < config.nuarts)
681
    config.uarts[current_device].jitter = tempL;
682
  else
683
    ERROR("invalid device number.");
684
}
685
 
686
void uart_irq () {
687
  if (current_device >= 0 && current_device < config.nuarts)
688
    config.uarts[current_device].irq = tempL;
689
  else
690
    ERROR("invalid device number.");
691
}
692
 
693
void uart_16550 () {
694
  if (current_device >= 0 && current_device < config.nuarts)
695
    config.uarts[current_device].uart16550 = tempL;
696
  else
697
    ERROR("invalid device number.");
698
}
699
 
700
void uart_rxfile () {
701
  if (current_device >= 0 && current_device < config.nuarts)
702
    strcpy (config.uarts[current_device].rxfile, tempS);
703
  else
704
    ERROR("invalid device number.");
705
}
706
 
707
void uart_txfile () {
708
  if (current_device >= 0 && current_device < config.nuarts)
709
    strcpy (config.uarts[current_device].txfile, tempS);
710
  else
711
    ERROR("invalid device number.");
712
}
713
 
714
void uart_vapi_id () {
715
  if (current_device >= 0 && current_device < config.nuarts)
716
    config.uarts[current_device].vapi_id = tempUL;
717
  else
718
    ERROR("invalid device number.");
719
}
720
 
721
void dma_ndmas () {
722
  if (tempL >= 0 && tempL < MAX_DMAS)
723
    config.ndmas = tempL;
724
  else
725
    ERROR("invalid number of devices.");
726
}
727
 
728
void dma_baseaddr () {
729
  if (current_device >= 0 && current_device < config.ndmas)
730
    config.dmas[current_device].baseaddr = tempUL;
731
  else
732
    ERROR("invalid device number.");
733
}
734
 
735
void dma_irq () {
736
  if (current_device >= 0 && current_device < config.ndmas)
737
    config.dmas[current_device].irq = tempL;
738
  else
739
    ERROR("invalid device number.");
740
}
741
 
742
void dma_vapi_id () {
743
  if (current_device >= 0 && current_device < config.ndmas)
744
    config.dmas[current_device].vapi_id = tempUL;
745
  else
746
    ERROR("invalid device number.");
747
}
748
 
749
void memory_nmemories () {
750
  if (tempL >= 0 && tempL < MAX_MEMORIES)
751
    config.memory.nmemories = tempL;
752
  else
753
    ERROR("invalid number of devices.");
754
}
755
 
756
void memory_type () {
757
  if (strcmp (tempS, "unknown") == 0)
758
    config.memory.type = MT_UNKNOWN;
759
  else if (strcmp (tempS, "random") == 0)
760
    config.memory.type = MT_RANDOM;
761
  else if (strcmp (tempS, "pattern") == 0)
762
    config.memory.type = MT_PATTERN;
763
  else if (strcmp (tempS, "zero") == 0) {
764
    config.memory.type = MT_PATTERN;
765
    config.memory.pattern = 0;
766
  } else {
767
    char tmp[200];
768
    sprintf (tmp, "invalid memory type '%s'.\n", tempS);
769
    ERROR(tmp);
770
  }
771
}
772
 
773
void memory_ce () {
774
  if (current_device >= 0 && current_device < config.memory.nmemories)
775
    config.memory.table[current_device].ce = tempL;
776
  else
777
    ERROR("invalid device number.");
778
}
779
 
780
void memory_baseaddr () {
781
  if (current_device >= 0 && current_device < config.memory.nmemories)
782
    config.memory.table[current_device].baseaddr = tempUL;
783
  else
784
    ERROR("invalid device number.");
785
}
786
 
787
void memory_size () {
788
  if (current_device >= 0 && current_device < config.memory.nmemories)
789
    config.memory.table[current_device].size = tempUL;
790
  else
791
    ERROR("invalid device number.");
792
}
793
 
794
void memory_name () {
795
  if (current_device >= 0 && current_device < config.memory.nmemories)
796
    strcpy (config.memory.table[current_device].name, tempS);
797
  else
798
    ERROR("invalid device number.");
799
}
800
 
801
void memory_log () {
802
  if (current_device >= 0 && current_device < config.memory.nmemories)
803
    strcpy (config.memory.table[current_device].log, tempS);
804
  else
805
    ERROR("invalid device number.");
806
}
807
 
808
void memory_delayr () {
809
  if (current_device >= 0 && current_device < config.memory.nmemories)
810
    config.memory.table[current_device].delayr = tempL;
811
  else
812
    ERROR("invalid device number.");
813
}
814
 
815
void memory_delayw () {
816
  if (current_device >= 0 && current_device < config.memory.nmemories)
817
    config.memory.table[current_device].delayw = tempL;
818
  else
819
    ERROR("invalid device number.");
820
}
821
 
822
void cpu_raw_range () {
823
  if (config.cpu.raw_range >= RAW_RANGE) {
824
    config.cpu.raw_range = RAW_RANGE - 1;
825
    WARNING("raw range too large; truncated.");
826
  } else if (config.cpu.raw_range < 0) {
827
    config.cpu.raw_range = 0;
828
    WARNING("raw range negative; disabled.");
829
  }
830
}
831
 
832
void cpu_sbuf_len () {
833
  if (config.cpu.sbuf_len >= MAX_SBUF_LEN) {
834
    config.cpu.sbuf_len = MAX_SBUF_LEN - 1;
835
    WARNING("sbuf_len too large; truncated.");
836
  } else if (config.cpu.sbuf_len < 0) {
837
    config.cpu.sbuf_len = 0;
838
    WARNING("sbuf_len negative; disabled.");
839
  }
840
}
841
 
842
void eth_nethernets () {
843
  if (tempL >= 0 && tempL < MAX_ETHERNETS)
844
    config.nethernets = tempL;
845
  else
846
    ERROR("invalid number of devices.");
847
}
848
 
849
void eth_baseaddr () {
850
  if (current_device >= 0 && current_device < config.nethernets)
851
    config.ethernets[current_device].baseaddr = tempUL;
852
  else
853
    ERROR("invalid device number.");
854
}
855
 
856
void eth_dma () {
857
  if (current_device >= 0 && current_device < config.nethernets)
858
    config.ethernets[current_device].dma = tempL;
859
  else
860
    ERROR("invalid device number.");
861
}
862
 
863
void eth_rx_channel () {
864
  if (current_device >= 0 && current_device < config.nethernets)
865
    config.ethernets[current_device].rx_channel = tempL;
866
  else
867
    ERROR("invalid device number.");
868
}
869
 
870
void eth_tx_channel () {
871
  if (current_device >= 0 && current_device < config.nethernets)
872
    config.ethernets[current_device].rx_channel = tempL;
873
  else
874
    ERROR("invalid device number.");
875
}
876
 
877
void eth_rxfile () {
878
  if (current_device >= 0 && current_device < config.nethernets)
879
    strcpy (config.ethernets[current_device].rxfile, tempS);
880
  else
881
    ERROR("invalid device number.");
882
}
883
 
884
void eth_txfile () {
885
  if (current_device >= 0 && current_device < config.nethernets)
886
    strcpy (config.ethernets[current_device].txfile, tempS);
887
  else
888
    ERROR("invalid device number.");
889
}
890
 
891
void eth_vapi_id () {
892
  if (current_device >= 0 && current_device < config.nethernets)
893
    config.ethernets[current_device].vapi_id = tempUL;
894
  else
895
    ERROR("invalid device number.");
896
}
897
 
898
void gpio_ngpios () {
899
  if (tempL >= 0 && tempL < MAX_GPIOS)
900
    config.ngpios = tempL;
901
  else
902
    ERROR("invalid number of devices.");
903
}
904
 
905
void gpio_baseaddr () {
906
  if (current_device >= 0 && current_device < config.ngpios)
907
    config.gpios[current_device].baseaddr = tempUL;
908
  else
909
    ERROR("invalid device number.");
910
}
911
 
912
void gpio_irq () {
913
  if (current_device >= 0 && current_device < config.ngpios)
914
    config.gpios[current_device].irq = tempL;
915
  else
916
    ERROR("invalid device number.");
917
}
918
 
919
void gpio_base_vapi_id () {
920
  if (current_device >= 0 && current_device < config.ngpios)
921
    config.gpios[current_device].base_vapi_id = tempUL;
922
  else
923
    ERROR("invalid device number.");
924
}
925
 
926
int is_power2 (int x) {
927
  while (!(x & 1))
928
    x >>= 1;
929
  return x == 1;
930
}
931
 
932
void immu_enabled () {
933
  setsprbits (SPR_UPR, SPR_UPR_IMP, tempL & 1);
934
  config.immu.enabled = tempL;
935
}
936
 
937
void dmmu_enabled () {
938
  setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1);
939
  config.dmmu.enabled = tempL;
940
}
941
 
942
void immu_nsets () {
943
  if (is_power2(tempL) && tempL <= 256)
944
    config.immu.nsets = tempL;
945
  else
946
    ERROR("value of power of two and lower or equal than 256 expected.");
947
}
948
 
949
void dmmu_nsets () {
950
  if (is_power2(tempL) && tempL <= 256)
951
    config.dmmu.nsets = tempL;
952
  else
953
    ERROR("value of power of two and lower or equal than 256 expected.");
954
}
955
 
956
void immu_nways () {
957
  if (tempL >= 1 && tempL <= 4)
958
    config.immu.nways = tempL;
959
  else
960
    ERROR("value 1, 2, 3 or 4 expected.");
961
}
962
 
963
void dmmu_nways () {
964
  if (tempL >= 1 && tempL <= 4)
965
    config.dmmu.nways = tempL;
966
  else
967
    ERROR("value 1, 2, 3 or 4 expected.");
968
}
969
 
970
void immu_pagesize () {
971
  if (is_power2(tempL))
972
    config.immu.pagesize = tempL;
973
  else
974
    ERROR("value of power of two expected.");
975
}
976
 
977
void dmmu_pagesize () {
978
  if (is_power2(tempL))
979
    config.dmmu.pagesize = tempL;
980
  else
981
    ERROR("value of power of two expected.");
982
}
983
 
984
void immu_entrysize () {
985
  if (is_power2(tempL))
986
    config.immu.entrysize = tempL;
987
  else
988
    ERROR("value of power of two expected.");
989
}
990
 
991
void dmmu_entrysize () {
992
  if (is_power2(tempL))
993
    config.dmmu.entrysize = tempL;
994
  else
995
    ERROR("value of power of two expected.");
996
}
997
 
998
void immu_ustates () {
999
  if (tempL >= 2 && tempL <= 4)
1000
    config.immu.ustates = tempL;
1001
  else
1002
    ERROR("invalid USTATE.");
1003
}
1004
 
1005
void dmmu_ustates () {
1006
  if (tempL >= 2 && tempL <= 4)
1007
    config.dmmu.ustates = tempL;
1008
  else
1009
    ERROR("invalid USTATE.");
1010
}
1011
 
1012
void ic_enabled () {
1013
  config.ic.enabled = tempL;
1014
  setsprbits (SPR_UPR, SPR_UPR_ICP, tempL & 1);
1015
}
1016
 
1017
void ic_nsets () {
1018
  if (is_power2(tempL) && tempL <= MAX_IC_SETS)
1019
    config.ic.nsets = tempL;
1020
  else {
1021
    char tmp[200];
1022
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_IC_SETS);
1023
    ERROR(tmp);
1024
  }
1025
}
1026
 
1027
void ic_nways () {
1028
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
1029
    config.ic.nways = tempL;
1030
  else
1031
    ERROR("value 1, 2, 3 or 4 expected.");
1032
}
1033
 
1034
void ic_blocksize () {
1035
  if (is_power2(tempL))
1036
    config.ic.blocksize = tempL;
1037
  else
1038
    ERROR("value of power of two expected.");
1039
}
1040
 
1041
void ic_ustates () {
1042
  if (tempL >= 2 && tempL <= 4)
1043
    config.ic.ustates = tempL;
1044
  else
1045
    ERROR("invalid USTATE.");
1046
}
1047
 
1048
void dc_enabled () {
1049
  config.dc.enabled = tempL;
1050
  setsprbits (SPR_UPR, SPR_UPR_DCP, tempL & 1);
1051
}
1052
 
1053
void dc_nsets () {
1054
  if (is_power2(tempL) && tempL <= MAX_DC_SETS)
1055
    config.dc.nsets = tempL;
1056
  else {
1057
    char tmp[200];
1058
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
1059
    ERROR(tmp);
1060
  }
1061
}
1062
 
1063
void dc_nways () {
1064
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
1065
    config.dc.nways = tempL;
1066
  else
1067
    ERROR("value 1, 2, 3 or 4 expected.");
1068
}
1069
 
1070
void dc_blocksize () {
1071
  if (is_power2(tempL))
1072
    config.dc.blocksize = tempL;
1073
  else
1074
    ERROR("value of power of two expected.");
1075
}
1076
 
1077
void dc_ustates () {
1078
  if (tempL >= 2 && tempL <= 4)
1079
    config.dc.ustates = tempL;
1080
  else
1081
    ERROR("invalid USTATE.");
1082
}
1083
 
1084
void vga_nvgas () {
1085
  if (tempL >= 0 && tempL < MAX_VGAS)
1086
    config.nvgas = tempL;
1087
  else
1088
    ERROR("invalid number of devices.");
1089
}
1090
 
1091
void vga_baseaddr () {
1092
  if (current_device >= 0 && current_device < config.nvgas)
1093
    config.vgas[current_device].baseaddr = tempUL;
1094
  else
1095
    ERROR("invalid device number.");
1096
}
1097
 
1098
void vga_irq () {
1099
  if (current_device >= 0 && current_device < config.nvgas)
1100
    config.vgas[current_device].irq = tempL;
1101
  else
1102
    ERROR("invalid device number.");
1103
}
1104
 
1105
void vga_refresh_rate () {
1106
  if (current_device >= 0 && current_device < config.nvgas)
1107
    config.vgas[current_device].refresh_rate = tempUL;
1108
  else
1109
    ERROR("invalid device number.");
1110
}
1111
 
1112
void vga_filename () {
1113
  if (current_device >= 0 && current_device < config.nvgas)
1114
    strcpy (config.vgas[current_device].filename, tempS);
1115
  else
1116
    ERROR("invalid device number.");
1117
}
1118
 
1119
/* Read environment from a script file. Does not fail - assumes default configuration instead.
1120
   The syntax of script file is:
1121
   param = value
1122
   section x
1123
     data
1124
     param = value
1125
   end
1126
 
1127
   Example:
1128
   section mc
1129
     memory_table_file = sim.mem
1130
     enable = 1
1131
     POC = 0x47892344
1132
   end
1133
 
1134
 */
1135
 
1136
void read_script_file (char *filename)
1137
{
1138
  FILE *f;
1139
  unsigned long memory_needed = 0;
1140
  char *home = getenv("HOME");
1141
  char ctmp[STR_SIZE];
1142
  int local = 1;
1143
  section = 0;
1144
 
1145
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
1146
  if ((f = fopen (filename, "rt")) != NULL
1147
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
1148
    unsigned long start, length;
1149
    char type[STR_SIZE];
1150
    int nparam;
1151
    int rd, wd;
1152
    if (config.sim.verbose && !runtime.sim.output_cfg)
1153
      printf ("Reading script file from '%s'...\n", local ? filename : ctmp);
1154
    strcpy (runtime.sim.script_fn, local ? filename : ctmp);
1155
 
1156
    while (!feof(f)) {
1157
      char param[STR_SIZE];
1158
      if (fscanf(f, "%s ", &param) != 1) break;
1159
      /* Is this a sections? */
1160
      if (strcmp (param, "section") == 0) {
1161
        int i;
1162
        section = 0;
1163
        if (fscanf (f, "%s\n", &param) != 1) {
1164
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
1165
          exit (1);
1166
        }
1167
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1168
          if (strcmp (sections[i].name, param) == 0) {
1169
            section = i;
1170
            break;
1171
          }
1172
        if (!section) {
1173
          char tmp[200];
1174
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
1175
          WARNING(tmp);
1176
          /* just skip section */
1177
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
1178
        }
1179
      } else if (strcmp (param, "end") == 0) {
1180
        section = 0;
1181
      } else if (strncmp (param, "/*", 2) == 0) {
1182
        char c0 = 0, c1 = 0;
1183
        while (c0 != '*' || c1 != '/') {
1184
          c0 = c1;
1185
          c1 = fgetc(f);
1186
          if (feof(f)) {
1187
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
1188
            exit (1);
1189
          }
1190
        }
1191
      } else {
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, param) == 0) {
1195
            found = i;
1196
            break;
1197
          }
1198
        if (found < 0) {
1199
          char tmp[200];
1200
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
1201
          WARNING(tmp);
1202
          while (fgetc(f) != '\n' || feof(f));
1203
          continue;
1204
        }
1205
 
1206
        /* Parse parameter value */
1207
        {
1208
          if (config_params[found].type[0])
1209
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
1210
              exit (1);
1211
        }
1212
        if (config_params[found].func)
1213
          config_params[found].func();
1214
      }
1215
    }
1216
    fclose (f);
1217
    runtime.sim.script_file_specified = 1;
1218
  } else
1219
    if (config.sim.verbose)
1220
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
1221
}
1222
 
1223
/* Utility for execution of set sim command.  */
1224
static int set_config (char *s)
1225
{
1226
  char *sec, *item, *params;
1227
  int noparams = 0, i, noitem = 0;
1228
  while (*s && isspace (*s)) s++;
1229
  sec = s;
1230
  printf ("s:%s\n", s);
1231
  while (*s && *s != ' ') s++;
1232
  if (!(*s)) noitem = 1;
1233
  *s = 0;
1234
  printf ("sec:%s\n", sec);
1235
  section = 0;
1236
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1237
    if (strcmp (sections[i].name, sec) == 0) {
1238
      section = i;
1239
      break;
1240
    }
1241
 
1242
  if (!section) return 1;
1243
  if (noitem) return 2;
1244
 
1245
  item = ++s;
1246
 
1247
  while (*s && *s != ' ') s++;
1248
  if (!(*s)) {
1249
    noparams = 1;
1250
    params = "";
1251
  } else
1252
    params = s + 1;
1253
  *s = 0;
1254
  printf ("item:%s\n", item);
1255
  printf ("params:%s\n", params);
1256
  {
1257
    int i, found = -1;
1258
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1259
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
1260
        found = i;
1261
        break;
1262
      }
1263
    if (found < 0) return 2;
1264
 
1265
    /* Parse parameter value */
1266
    if (config_params[found].type[0])
1267
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
1268
        return 3;
1269
    if (config_params[found].func)
1270
      config_params[found].func();
1271
  }
1272
  return 0;
1273
}
1274
 
1275
/* Executes set sim command, displays error.  */
1276
void set_config_command(char *s)
1277
{
1278
  int i;
1279
  switch (set_config (s)) {
1280
    case 1:
1281
      printf ("Invalid or missing section name.  One of valid sections must be specified:\n");
1282
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1283
        printf ("%s ", sections[i].name);
1284
      printf ("\n");
1285
      break;
1286
    case 2:
1287
      printf ("Invalid or missing item name.  One of valid items must be specified:\n");
1288
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1289
        if (config_params[i].section == section)
1290
          printf ("%s ", config_params[i].name);
1291
      printf ("\n");
1292
      break;
1293
    case 3:
1294
      printf ("Invalid parameters specified.\n");
1295
      break;
1296
  }
1297
}
1298
#endif /* !FAST_SIM */
1299
 
1300
/* Outputs C structure of current config to file */
1301
void output_cfg (FILE *f)
1302
{
1303
  int i, comma;
1304
  fprintf (f, "/* This file was automatically generated by or1ksim,\n"
1305
              "   using --output-cfg switch (cfg file '%s'). */\n"
1306
  "const static struct config config = {\n", runtime.sim.script_fn);
1307
 
1308
  fprintf (f, "  tick:{enabled:%i},\n", config.tick.enabled);
1309
  fprintf (f, "  nuarts:%i, uarts:{", config.nuarts);
1310
  comma = 0;
1311
  for (i = 0; i < config.nuarts; i++) {
1312
    fprintf (f, "%s\n    {rxfile:\"%s\", txfile:\"%s\", jitter:%i, baseaddr:0x%08x, irq:%i, vapi_id:0x%08x, uart16550:%i}",
1313
      comma ? "," :"", config.uarts[i].rxfile, config.uarts[i].txfile, config.uarts[i].jitter, config.uarts[i].baseaddr, config.uarts[i].irq,
1314
      config.uarts[i].vapi_id, config.uarts[i].uart16550);
1315
    comma = 1;
1316
  }
1317
  fprintf (f, "},\n");
1318
 
1319
  fprintf (f, "  ndmas:%i, dmas:{", config.ndmas);
1320
  comma = 0;
1321
  for (i = 0; i < config.ndmas; i++) {
1322
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, vapi_id:0x%08x}",
1323
      comma ? "," :"", config.dmas[i].baseaddr, config.dmas[i].irq, config.dmas[i].vapi_id);
1324
    comma = 1;
1325
  }
1326
  fprintf (f, "},\n");
1327
 
1328
  fprintf (f, "  nethernets:%i, ethernets:{", config.nethernets);
1329
  comma = 0;
1330
  for (i = 0; i < config.nethernets; i++) {
1331
    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}",
1332
      comma ? "," :"", config.ethernets[i].baseaddr, config.ethernets[i].dma, config.ethernets[i].tx_channel, config.ethernets[i].rx_channel,
1333
      config.ethernets[i].rxfile, config.ethernets[i].txfile, config.ethernets[i].vapi_id);
1334
    comma = 1;
1335
  }
1336
  fprintf (f, "},\n");
1337
 
1338
  fprintf (f, "  ngpios:%i, gpios:{", config.ngpios);
1339
  comma = 0;
1340
  for (i = 0; i < config.ngpios; i++) {
1341
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, base_vapi_id:0x%08x}",
1342
      comma ? "," :"", config.gpios[i].baseaddr, config.gpios[i].irq, config.gpios[i].base_vapi_id);
1343
    comma = 1;
1344
  }
1345
  fprintf (f, "},\n");
1346
 
1347
  fprintf (f, "  mc:{enabled:%i, baseaddr:%i, POC:%i},\n", config.mc.enabled, config.mc.baseaddr, config.mc.POC);
1348
  fprintf (f, "  memory:{pattern:%i, random_seed:%i, type:%s, nmemories:%i, table:{", config.memory.pattern, config.memory.random_seed,
1349
    config.memory.type == MT_UNKNOWN ? "MT_UNKNOWN" : config.memory.type == MT_PATTERN ? "MT_PATTERN" : "MT_RANDOM", config.memory.nmemories);
1350
  comma = 0;
1351
  for (i = 0; i < config.memory.nmemories; i++) {
1352
    fprintf (f, "%s\n    {ce:%i, baseaddr:0x%08x, size:0x%08x, name:\"%s\", log:\"%s\", delayr:%i, delayw:%i}",
1353
      comma ? "," :"", config.memory.table[i].ce, config.memory.table[i].baseaddr, config.memory.table[i].size, config.memory.table[i].name,
1354
      config.memory.table[i].log, config.memory.table[i].delayr, config.memory.table[i].delayw);
1355
    comma = 1;
1356
  }
1357
  fprintf (f, "}},\n");
1358
 
1359
  fprintf (f, "  immu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1360
    config.immu.enabled, config.immu.nways, config.immu.nsets, config.immu.pagesize, config.immu.entrysize, config.immu.ustates,
1361
    config.immu.missdelay, config.immu.hitdelay);
1362
 
1363
  fprintf (f, "  dmmu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1364
    config.dmmu.enabled, config.dmmu.nways, config.dmmu.nsets, config.dmmu.pagesize, config.dmmu.entrysize, config.dmmu.ustates,
1365
    config.dmmu.missdelay, config.dmmu.hitdelay);
1366
 
1367
  fprintf (f, "  ic:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1368
    config.ic.enabled, config.ic.nways, config.ic.nsets, config.ic.blocksize, config.ic.ustates,
1369
    config.ic.missdelay, config.ic.hitdelay);
1370
 
1371
  fprintf (f, "  dc:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i,\n"
1372
    "    load_missdelay:%i, load_hitdelay:%i, store_missdelay:%i, store_hitdelay:%i},\n",
1373
    config.dc.enabled, config.dc.nways, config.dc.nsets, config.dc.blocksize, config.dc.ustates,
1374
    config.dc.load_missdelay, config.dc.load_hitdelay, config.dc.store_missdelay, config.dc.store_hitdelay);
1375
 
1376
  fprintf (f, "  bpb:{enabled:%i, sbp_bnf_fwd:%i, sbp_bf_fwd:%i, btic:%i, missdelay:%i, hitdelay:%i},\n",
1377
    config.bpb.enabled, config.bpb.sbp_bnf_fwd, config.bpb.sbp_bf_fwd, config.bpb.btic, config.bpb.missdelay, config.bpb.hitdelay);
1378
 
1379
  fprintf (f, "  cpu:{upr:0x%08x, ver:0x%04x, rev:0x%04x, superscalar:%i, hazards:%i, dependstats:%i,\n"
1380
    "    raw_range:%i, sr:0x%08x},\n",
1381
    config.cpu.upr, config.cpu.ver, config.cpu.rev, config.cpu.superscalar, config.cpu.hazards, config.cpu.dependstats,
1382
    config.cpu.raw_range, config.cpu.sr);
1383
 
1384
  fprintf (f, "  sim:{debug:%i, verbose:%i, profile:%i, prof_fn:\"%s\", mprofile:%i, mprof_fn:\"%s\",\n",
1385
    config.sim.debug, config.sim.verbose, config.sim.profile, config.sim.prof_fn, config.sim.mprofile, config.sim.mprof_fn);
1386
 
1387
  fprintf (f, "    history:%i, exe_log:%i, exe_log_fn:\"%s\", clkcycle_ps:%i,\n",
1388
    config.sim.history, config.sim.exe_log, config.sim.exe_log_fn, config.sim.clkcycle_ps);
1389
 
1390
  fprintf (f, "    spr_log:%i, spr_log_fn:\"%s\"},\n",
1391
    config.sim.spr_log, config.sim.spr_log_fn);
1392
 
1393
  fprintf (f, "  debug:{enabled:%i, gdb_enabled:%i, server_port:%i, vapi_id:0x%08x},\n",
1394
    config.debug.enabled, config.debug.gdb_enabled, config.debug.server_port, config.debug.vapi_id);
1395
 
1396
  fprintf (f, "  vapi:{enabled:%i, server_port:%i, log_enabled:%i, hide_device_id:%i, vapi_fn:\"%s\"},\n",
1397
    config.vapi.enabled, config.vapi.server_port, config.vapi.log_enabled, config.vapi.hide_device_id, config.vapi.vapi_fn);
1398
 
1399
  fprintf (f, "  pm:{enabled:%i}\n",
1400
    config.pm.enabled);
1401
 
1402
  fprintf (f, "};\n");
1403
}

powered by: WebSVN 2.1.0

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