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 1076

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

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

powered by: WebSVN 2.1.0

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