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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_69/] [or1ksim/] [sim-config.c] - Blame information for rev 823

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

powered by: WebSVN 2.1.0

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