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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [sim-config.c] - Blame information for rev 672

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

powered by: WebSVN 2.1.0

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