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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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