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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_42/] [or1ksim/] [sim-config.c] - Blame information for rev 723

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

powered by: WebSVN 2.1.0

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