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 734

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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