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

Subversion Repositories or1k

[/] [or1k/] [tags/] [tn_m001/] [or1ksim/] [sim-config.c] - Blame information for rev 664

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

powered by: WebSVN 2.1.0

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