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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_1_x/] [or1ksim/] [sim-config.c] - Blame information for rev 847

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

powered by: WebSVN 2.1.0

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