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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [sim-config.c] - Blame information for rev 805

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

powered by: WebSVN 2.1.0

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