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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_1_x/] [or1ksim/] [sim-config.c] - Blame information for rev 1308

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

powered by: WebSVN 2.1.0

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