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 1765

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