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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [sim-config.c] - Blame information for rev 713

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

powered by: WebSVN 2.1.0

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