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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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