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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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