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

Subversion Repositories or1k

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

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
void uart_rxfile ();
369
void uart_txfile ();
370
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
{2, "rxfile",             "=\"%s\"",     uart_rxfile,   (void *)(&tempS[0]), 0},
507
{2, "txfile",             "=\"%s\"",     uart_txfile,   (void *)(&tempS[0]), 0},
508
{2, "vapi_id",            "=0x%x",       uart_vapi_id,  (void *)(&tempUL), 0},
509
 
510
{3, "ndmas",              "=%i",         dma_ndmas,     (void *)(&tempL), CPF_GLOBAL},
511
{3, "device",             "%i",          change_device, (void *)(&tempL), 0},
512
{3, "enddevice",          "",            end_device,    NULL, 0},
513
{3, "baseaddr",           "=0x%x",       dma_baseaddr,  (void *)(&tempUL), 0},
514
{3, "irq",                "=%i",         dma_irq,       (void *)(&tempL), 0},
515
{3, "vapi_id",            "=0x%x",       dma_vapi_id,   (void *)(&tempUL), 0},
516
 
517
{4, "random_seed",        "=%i",         NULL,          (void *)(&config.memory.random_seed), 0},
518
{4, "pattern",            "=%i",         NULL,          (void *)(&config.memory.pattern), 0},
519
{4, "type",               "=%s ",        memory_type,   (void *)(&tempS[0]), 0},
520
{4, "nmemories",          "=%i",         memory_nmemories,(void *)(&tempL), CPF_GLOBAL},
521
{4, "device",             "%i",          change_device, (void *)(&tempL), 0},
522
{4, "enddevice",          "",            end_device,    NULL, 0},
523
{4, "ce",                 "=%i",         memory_ce,     (void *)(&tempL), 0},
524
{4, "baseaddr",           "=0x%x",       memory_baseaddr,(void *)(&tempUL), 0},
525
{4, "size",               "=0x%x",       memory_size,   (void *)(&tempUL), 0},
526
{4, "name",               "=\"%s\"",     memory_name,   (void *)(&tempS[0]), 0},
527
{4, "log",                "=\"%s\"",     memory_log,    (void *)(&tempS[0]), 0},
528
{4, "delayr",             "=%i",         memory_delayr, (void *)(&tempL), 0},
529
{4, "delayw",             "=%i",         memory_delayw, (void *)(&tempL), 0},
530
 
531
{5, "ver",                "=0x%x",       NULL,          (void *)(&config.cpu.ver), 0},
532
{5, "rev",                "=0x%x",       NULL,          (void *)(&config.cpu.rev), 0},
533
{5, "upr",                "=0x%x",       NULL,          (void *)(&config.cpu.upr), 0},
534
{5, "sr",                 "=0x%x",       NULL,          (void *)(&config.cpu.sr), 0},
535
{5, "hazards",            "=%i",         NULL,          (void *)(&config.cpu.hazards), 0},
536
{5, "superscalar",        "=%i",         NULL,          (void *)(&config.cpu.superscalar), 0},
537
{5, "dependstats",        "=%i",         NULL,          (void *)(&config.cpu.dependstats), 0},
538
{5, "sbuf_len",           "=%i",         cpu_sbuf_len,  (void *)(&config.cpu.sbuf_len), 0},
539
 
540
{6, "debug",              "=%i",         NULL,          (void *)(&config.sim.debug), 0},
541
{6, "verbose",            "=%i",         NULL,          (void *)(&config.sim.verbose), 0},
542
{6, "profile",            "=%i",         NULL,          (void *)(&config.sim.profile), 0},
543
{6, "prof_fn",            "=\"%s\"",     NULL,          (void *)(&config.sim.prof_fn[0]), 0},
544
{6, "mprofile",           "=%i",         NULL,          (void *)(&config.sim.mprofile), 0},
545
{6, "mprof_fn",           "=\"%s\"",     NULL,          (void *)(&config.sim.mprof_fn[0]), 0},
546
{6, "history",            "=%i",         NULL,          (void *)(&config.sim.history), 0},
547
{6, "exe_log",            "=%i",         NULL,          (void *)(&config.sim.exe_log), 0},
548 672 markom
{6, "exe_log_type",       "=%s ",        sim_exe_log_type, (void *)(&tempS[0]), 0},
549
{6, "exe_log_start",      "=%i",         NULL,          (void *)(&config.sim.exe_log_start), 0},
550
{6, "exe_log_end",        "=%i",         NULL,          (void *)(&config.sim.exe_log_end), 0},
551
{6, "exe_log_marker",     "=%i",         NULL,          (void *)(&config.sim.exe_log_marker), 0},
552 645 markom
{6, "exe_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.exe_log_fn[0]), 0},
553
{6, "spr_log",            "=%i",         NULL,          (void *)(&config.sim.spr_log), 0},
554
{6, "spr_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.spr_log_fn[0]), 0},
555
{6, "clkcycle",           "=%s ",        sim_clkcycle,  (void *)(&tempS[0]), 0},
556 823 ivang
{6, "stdout",             "=\"%s\"",     NULL,          (void *)(&config.sim.fstdout[0]), 0},
557 645 markom
 
558
{7, "enabled",            "=%i",         NULL,          (void *)(&config.debug.enabled), 0},
559
{7, "gdb_enabled",        "=%i",         NULL,          (void *)(&config.debug.gdb_enabled), 0},
560
{7, "server_port",        "=%i",         NULL,          (void *)(&config.debug.server_port), 0},
561
{7, "vapi_id",            "=0x%x",       NULL,          (void *)(&config.debug.vapi_id), 0},
562
 
563
{8, "enabled",            "=%i",         NULL,          (void *)(&config.vapi.enabled), 0},
564
{8, "server_port",        "=%i",         NULL,          (void *)(&config.vapi.server_port), 0},
565
{8, "log_enabled",        "=%i",         NULL,          (void *)(&config.vapi.log_enabled), 0},
566
{8, "hide_device_id",     "=%i",         NULL,          (void *)(&config.vapi.hide_device_id), 0},
567
{8, "vapi_log_fn",        "=\"%s\"",     NULL,          (void *)(&config.vapi.vapi_fn[0]), 0},
568
 
569
{9, "nethernets",         "=%i",         eth_nethernets,(void *)(&tempL), CPF_GLOBAL},
570
{9, "device",             "%i",          change_device, (void *)(&tempL), 0},
571 734 ivang
{9, "irq",                "=%i",         eth_irq,       (void *)(&tempUL), 15},
572 645 markom
{9, "enddevice",          "",            end_device,    NULL, 0},
573
{9, "baseaddr",           "=0x%x",       eth_baseaddr,  (void *)(&tempUL), 0},
574
{9, "dma",                "=%i",         eth_dma,       (void *)(&tempL), 0},
575 726 ivang
{9, "rtx_type",           "=%i",         eth_rtx_type,  (void *)(&tempUL), 0},
576 645 markom
{9, "rx_channel",         "=%i",         eth_rx_channel,(void *)(&tempL), 0},
577
{9, "tx_channel",         "=%i",         eth_tx_channel,(void *)(&tempL), 0},
578
{9, "rxfile",             "=\"%s\"",     eth_rxfile,    (void *)(&tempS[0]), 0},
579
{9, "txfile",             "=\"%s\"",     eth_txfile,    (void *)(&tempS[0]), 0},
580 723 ivang
{9, "sockif",             "=\"%s\"",     eth_sockif,    (void *)(&tempS[0]), 0},
581 645 markom
{9, "vapi_id",            "=0x%x",       eth_vapi_id,   (void *)(&tempUL), 0},
582 731 ivang
 
583 645 markom
{11, "enabled",           "=%i",         immu_enabled,  (void *)(&tempL), 0},
584
{11, "nsets",             "=%i",         immu_nsets,    (void *)(&tempL), 0},
585
{11, "nways",             "=%i",         immu_nways,    (void *)(&tempL), 0},
586
{11, "pagesize",          "=%i",         immu_pagesize, (void *)(&tempL), 0},
587
{11, "entrysize",         "=%i",         immu_entrysize,(void *)(&tempL), 0},
588
{11, "ustates",           "=%i",         immu_ustates,  (void *)(&tempL), 0},
589
{11, "missdelay",         "=%i",         NULL,          (void *)(&config.immu.missdelay), 0},
590
{11, "hitdelay",          "=%i",         NULL,          (void *)(&config.immu.hitdelay), 0},
591
 
592
{12, "enabled",           "=%i",         dmmu_enabled,  (void *)(&tempL), 0},
593
{12, "nsets",             "=%i",         dmmu_nsets,    (void *)(&tempL), 0},
594
{12, "nways",             "=%i",         dmmu_nways,    (void *)(&tempL), 0},
595
{12, "pagesize",          "=%i",         dmmu_pagesize, (void *)(&tempL), 0},
596
{12, "entrysize",         "=%i",         dmmu_entrysize,(void *)(&tempL), 0},
597
{12, "ustates",           "=%i",         dmmu_ustates,  (void *)(&tempL), 0},
598
{12, "missdelay",         "=%i",         NULL,          (void *)(&config.dmmu.missdelay), 0},
599
{12, "hitdelay",          "=%i",         NULL,          (void *)(&config.dmmu.hitdelay), 0},
600 876 rherveille
 
601 645 markom
{13, "enabled",           "=%i",         ic_enabled,    (void *)(&tempL), 0},
602
{13, "nsets",             "=%i",         ic_nsets,      (void *)(&tempL), 0},
603
{13, "nways",             "=%i",         ic_nways,      (void *)(&tempL), 0},
604
{13, "blocksize",         "=%i",         ic_blocksize,  (void *)(&tempL), 0},
605
{13, "ustates",           "=%i",         ic_ustates,    (void *)(&tempL), 0},
606
{13, "missdelay",         "=%i",         NULL,          (void *)(&config.ic.missdelay), 0},
607
{13, "hitdelay",          "=%i",         NULL,          (void *)(&config.ic.hitdelay), 0},
608
 
609
{14, "enabled",           "=%i",         dc_enabled,    (void *)(&tempL), 0},
610
{14, "nsets",             "=%i",         dc_nsets,      (void *)(&tempL), 0},
611
{14, "nways",             "=%i",         dc_nways,      (void *)(&tempL), 0},
612
{14, "blocksize",         "=%i",         dc_blocksize,  (void *)(&tempL), 0},
613
{14, "ustates",           "=%i",         dc_ustates,    (void *)(&tempL), 0},
614
{14, "load_missdelay",    "=%i",         NULL,          (void *)(&config.dc.load_missdelay), 0},
615
{14, "load_hitdelay",     "=%i",         NULL,          (void *)(&config.dc.load_hitdelay), 0},
616
{14, "store_missdelay",   "=%i",         NULL,          (void *)(&config.dc.store_missdelay), 0},
617
{14, "store_hitdelay",    "=%i",         NULL,          (void *)(&config.dc.store_hitdelay), 0},
618
 
619
{15, "ngpios",            "=%i",         gpio_ngpios,   (void *)(&tempL), CPF_GLOBAL},
620
{15, "device",            "%i",          change_device, (void *)(&tempL), 0},
621
{15, "baseaddr",          "=0x%x",       gpio_baseaddr, (void *)(&tempUL), 0},
622
{15, "irq",               "=%i",         gpio_irq,      (void *)(&tempL), 0},
623
{15, "base_vapi_id",      "=0x%x",       gpio_base_vapi_id,   (void *)(&tempUL), 0},
624
{15, "enddevice",         "",            end_device,    NULL, 0},
625 876 rherveille
 
626 645 markom
{16, "enabled",           "=%i",         NULL,          (void *)(&config.bpb.enabled), 0},
627
{16, "btic",              "=%i",         NULL,          (void *)(&config.bpb.btic), 0},
628
{16, "sbp_bnf_fwd",       "=%i",         NULL,          (void *)(&config.bpb.sbp_bnf_fwd), 0},
629
{16, "sbp_bf_fwd",        "=%i",         NULL,          (void *)(&config.bpb.sbp_bf_fwd), 0},
630
{16, "missdelay",         "=%i",         NULL,          (void *)(&config.bpb.missdelay), 0},
631
{16, "hitdelay",          "=%i",         NULL,          (void *)(&config.bpb.hitdelay), 0},
632
 
633
{17, "enabled",           "=%i",         NULL,          (void *)(&config.pm.enabled), 0},
634
 
635
{18, "nvgas",             "=%i",         vga_nvgas,     (void *)(&tempL), CPF_GLOBAL},
636
{18, "device",            "%i",          change_device, (void *)(&tempL), 0},
637
{18, "baseaddr",          "=0x%x",       vga_baseaddr,  (void *)(&tempUL), 0},
638
{18, "irq",               "=%i",         vga_irq,       (void *)(&tempL), 0},
639
{18, "refresh_rate",      "=%i",         vga_refresh_rate, (void *)(&tempUL), 0},
640
{18, "filename",          "=\"%s\"",     vga_filename,  (void *)(&tempS[0]), 0},
641
{18, "enddevice",         "",            end_device,    NULL, 0},
642
 
643
{19, "enabled",           "=%i",         NULL,          (void *)(&config.fb.enabled), 0},
644 647 markom
{19, "baseaddr",          "=0x%x",       NULL,          (void *)(&config.fb.baseaddr), 0},
645 645 markom
{19, "refresh_rate",      "=%i",         NULL,          (void *)(&config.fb.refresh_rate), 0},
646 664 markom
{19, "filename",          "=\"%s\"",     NULL,          (void *)(&config.fb.filename), 0},
647
 
648
{20, "enabled",           "=%i",         NULL,          (void *)(&config.kbd.enabled), 0},
649
{20, "baseaddr",          "=0x%x",       NULL,          (void *)(&config.kbd.baseaddr), 0},
650
{20, "irq",               "=%i",         NULL,          (void *)(&config.kbd.irq), 0},
651 876 rherveille
{20, "rxfile",            "=\"%s\"",     NULL,          (void *)(&config.kbd.rxfile), 0},
652
 
653
{21, "natas",             "=%i",         ata_natas,     (void *)(&tempL ), CPF_GLOBAL},
654
{21, "device",            "%i",          change_device, (void *)(&tempL ), 0},
655
{21, "baseaddr",          "=0x%x",       ata_baseaddr,  (void *)(&tempUL), 0},
656
{21, "irq",               "=%i",         ata_irq,       (void *)(&tempL ), 0},
657
{21, "dev_type0",         "=%i",         ata_dev_type0, (void *)(&tempL ), 0},
658
{21, "dev_file0",         "=\"%s\"",     ata_dev_file0, (void *)(&tempS ), 0},
659
{21, "dev_size0",         "=%i",         ata_dev_size0, (void *)(&tempUL), 0},
660
{21, "dev_packet0",       "=%i",         ata_dev_packet0, (void *)(&tempL ), 0},
661
{21, "dev_type1",         "=%i",         ata_dev_type1, (void *)(&tempL ), 0},
662
{21, "dev_file1",         "=\"%s\"",     ata_dev_file1, (void *)(&tempS ), 0},
663
{21, "dev_size1",         "=%i",         ata_dev_size1, (void *)(&tempUL), 0},
664
{21, "dev_packet1",       "=%i",         ata_dev_packet1, (void *)(&tempL ), 0},
665
{21, "enddevice",         "",            end_device,    NULL, 0},
666 897 markom
 
667
{22, "calling_convention","=%i",         NULL,          (void *)&config.cuc.calling_convention, 0},
668
{22, "enable_bursts",     "=%i",         NULL,          (void *)&config.cuc.enable_bursts, 0},
669
{22, "no_multicycle",     "=%i",         NULL,          (void *)&config.cuc.no_multicycle, 0},
670
{22, "memory_order",      "=%s ",        cuc_memory_order, (void *)&tempS, 0},
671 970 simons
{22, "timings_fn",        "=\"%s\"",     NULL,          (void *)config.cuc.timings_fn},
672
 
673
{23, "enabled",           "=%i",         NULL,          (void *)(&config.test.enabled), 0},
674
{23, "baseaddr",          "=0x%x",       NULL,          (void *)(&config.test.baseaddr), 0}
675 645 markom
};
676
 
677
/* *INDENT-ON* */
678
 
679
int current_device = -1;
680
void change_device () {
681
  current_device = tempL;
682
}
683
 
684
void end_device () {
685
  current_device = -1;
686
}
687
 
688
void base_include () {
689
  read_script_file (tempS);
690
  section = 0;
691
}
692
 
693
void sim_clkcycle () {
694
  int len = strlen (tempS);
695
  int pos = len - 1;
696
  long time;
697
  if (len < 2) goto err;
698
  if (tempS[pos--] != 's') goto err;
699
  switch (tempS[pos--]) {
700
    case 'p': time = 1; break;
701
    case 'n': time = 1000; break;
702
    case 'u': time = 1000000; break;
703
    case 'm': time = 1000000000; break;
704
  default:
705
    goto err;
706
  }
707
  tempS[pos + 1] = 0;
708
  config.sim.clkcycle_ps = time * atol (tempS);
709
  return;
710
err:
711
  ERROR("invalid time format.");
712
}
713
 
714 672 markom
void sim_exe_log_type () {
715
  if (strcmp (tempS, "default") == 0)
716
    config.sim.exe_log_type = EXE_LOG_HARDWARE;
717
  else if (strcmp (tempS, "hardware") == 0)
718
    config.sim.exe_log_type = EXE_LOG_HARDWARE;
719 675 markom
  else if (strcmp (tempS, "simple") == 0)
720
    config.sim.exe_log_type = EXE_LOG_SIMPLE;
721 672 markom
  else if (strcmp (tempS, "software") == 0) {
722
    config.sim.exe_log_type = EXE_LOG_SOFTWARE;
723
  } else {
724
    char tmp[200];
725
    sprintf (tmp, "invalid execute log type '%s'.\n", tempS);
726
    ERROR(tmp);
727
  }
728
}
729
 
730 645 markom
void uart_nuarts () {
731
  if (tempL >= 0 && tempL < MAX_UARTS)
732
    config.nuarts = tempL;
733
  else
734
    ERROR("invalid number of devices.");
735
}
736
 
737
void uart_baseaddr () {
738
  if (current_device >= 0 && current_device < config.nuarts)
739
    config.uarts[current_device].baseaddr = tempUL;
740
  else
741
    ERROR("invalid device number.");
742
}
743
 
744
void uart_jitter () {
745
  if (current_device >= 0 && current_device < config.nuarts)
746
    config.uarts[current_device].jitter = tempL;
747
  else
748
    ERROR("invalid device number.");
749
}
750
 
751
void uart_irq () {
752
  if (current_device >= 0 && current_device < config.nuarts)
753
    config.uarts[current_device].irq = tempL;
754
  else
755
    ERROR("invalid device number.");
756
}
757
 
758
void uart_16550 () {
759
  if (current_device >= 0 && current_device < config.nuarts)
760
    config.uarts[current_device].uart16550 = tempL;
761
  else
762
    ERROR("invalid device number.");
763
}
764
 
765
void uart_rxfile () {
766
  if (current_device >= 0 && current_device < config.nuarts)
767
    strcpy (config.uarts[current_device].rxfile, tempS);
768
  else
769
    ERROR("invalid device number.");
770
}
771
 
772
void uart_txfile () {
773
  if (current_device >= 0 && current_device < config.nuarts)
774
    strcpy (config.uarts[current_device].txfile, tempS);
775
  else
776
    ERROR("invalid device number.");
777
}
778
 
779
void uart_vapi_id () {
780
  if (current_device >= 0 && current_device < config.nuarts)
781
    config.uarts[current_device].vapi_id = tempUL;
782
  else
783
    ERROR("invalid device number.");
784
}
785
 
786
void dma_ndmas () {
787
  if (tempL >= 0 && tempL < MAX_DMAS)
788
    config.ndmas = tempL;
789
  else
790
    ERROR("invalid number of devices.");
791
}
792
 
793
void dma_baseaddr () {
794
  if (current_device >= 0 && current_device < config.ndmas)
795
    config.dmas[current_device].baseaddr = tempUL;
796
  else
797
    ERROR("invalid device number.");
798
}
799
 
800
void dma_irq () {
801
  if (current_device >= 0 && current_device < config.ndmas)
802
    config.dmas[current_device].irq = tempL;
803
  else
804
    ERROR("invalid device number.");
805
}
806
 
807
void dma_vapi_id () {
808
  if (current_device >= 0 && current_device < config.ndmas)
809
    config.dmas[current_device].vapi_id = tempUL;
810
  else
811
    ERROR("invalid device number.");
812
}
813
 
814
void memory_nmemories () {
815
  if (tempL >= 0 && tempL < MAX_MEMORIES)
816
    config.memory.nmemories = tempL;
817
  else
818
    ERROR("invalid number of devices.");
819
}
820
 
821
void memory_type () {
822
  if (strcmp (tempS, "unknown") == 0)
823
    config.memory.type = MT_UNKNOWN;
824
  else if (strcmp (tempS, "random") == 0)
825
    config.memory.type = MT_RANDOM;
826
  else if (strcmp (tempS, "pattern") == 0)
827
    config.memory.type = MT_PATTERN;
828
  else if (strcmp (tempS, "zero") == 0) {
829
    config.memory.type = MT_PATTERN;
830
    config.memory.pattern = 0;
831
  } else {
832
    char tmp[200];
833
    sprintf (tmp, "invalid memory type '%s'.\n", tempS);
834
    ERROR(tmp);
835
  }
836
}
837
 
838
void memory_ce () {
839
  if (current_device >= 0 && current_device < config.memory.nmemories)
840
    config.memory.table[current_device].ce = tempL;
841
  else
842
    ERROR("invalid device number.");
843
}
844
 
845
void memory_baseaddr () {
846
  if (current_device >= 0 && current_device < config.memory.nmemories)
847
    config.memory.table[current_device].baseaddr = tempUL;
848
  else
849
    ERROR("invalid device number.");
850
}
851
 
852
void memory_size () {
853
  if (current_device >= 0 && current_device < config.memory.nmemories)
854
    config.memory.table[current_device].size = tempUL;
855
  else
856
    ERROR("invalid device number.");
857
}
858
 
859
void memory_name () {
860
  if (current_device >= 0 && current_device < config.memory.nmemories)
861
    strcpy (config.memory.table[current_device].name, tempS);
862
  else
863
    ERROR("invalid device number.");
864
}
865
 
866
void memory_log () {
867
  if (current_device >= 0 && current_device < config.memory.nmemories)
868
    strcpy (config.memory.table[current_device].log, tempS);
869
  else
870
    ERROR("invalid device number.");
871
}
872
 
873
void memory_delayr () {
874
  if (current_device >= 0 && current_device < config.memory.nmemories)
875
    config.memory.table[current_device].delayr = tempL;
876
  else
877
    ERROR("invalid device number.");
878
}
879
 
880
void memory_delayw () {
881
  if (current_device >= 0 && current_device < config.memory.nmemories)
882
    config.memory.table[current_device].delayw = tempL;
883
  else
884
    ERROR("invalid device number.");
885
}
886
 
887
void cpu_sbuf_len () {
888
  if (config.cpu.sbuf_len >= MAX_SBUF_LEN) {
889
    config.cpu.sbuf_len = MAX_SBUF_LEN - 1;
890
    WARNING("sbuf_len too large; truncated.");
891
  } else if (config.cpu.sbuf_len < 0) {
892
    config.cpu.sbuf_len = 0;
893
    WARNING("sbuf_len negative; disabled.");
894
  }
895
}
896
 
897
void eth_nethernets () {
898
  if (tempL >= 0 && tempL < MAX_ETHERNETS)
899
    config.nethernets = tempL;
900
  else
901
    ERROR("invalid number of devices.");
902
}
903
 
904
void eth_baseaddr () {
905
  if (current_device >= 0 && current_device < config.nethernets)
906
    config.ethernets[current_device].baseaddr = tempUL;
907
  else
908
    ERROR("invalid device number.");
909
}
910
 
911
void eth_dma () {
912
  if (current_device >= 0 && current_device < config.nethernets)
913
    config.ethernets[current_device].dma = tempL;
914
  else
915
    ERROR("invalid device number.");
916
}
917
 
918 725 ivang
void eth_rtx_type () {
919
  if (current_device >= 0 && current_device < config.nethernets)
920
    config.ethernets[current_device].rtx_type = tempUL;
921
  else
922
    ERROR("invalid device number.");
923
}
924
 
925 645 markom
void eth_rx_channel () {
926
  if (current_device >= 0 && current_device < config.nethernets)
927
    config.ethernets[current_device].rx_channel = tempL;
928
  else
929
    ERROR("invalid device number.");
930
}
931
 
932
void eth_tx_channel () {
933
  if (current_device >= 0 && current_device < config.nethernets)
934
    config.ethernets[current_device].rx_channel = tempL;
935
  else
936
    ERROR("invalid device number.");
937
}
938
 
939
void eth_rxfile () {
940
  if (current_device >= 0 && current_device < config.nethernets)
941
    strcpy (config.ethernets[current_device].rxfile, tempS);
942
  else
943
    ERROR("invalid device number.");
944
}
945
 
946
void eth_txfile () {
947
  if (current_device >= 0 && current_device < config.nethernets)
948
    strcpy (config.ethernets[current_device].txfile, tempS);
949
  else
950
    ERROR("invalid device number.");
951
}
952
 
953 723 ivang
void eth_sockif () {
954
  if (current_device >= 0 && current_device < config.nethernets)
955
    strcpy (config.ethernets[current_device].sockif, tempS);
956
  else
957
    ERROR("invalid device number.");
958
}
959
 
960
void eth_irq () {
961
  if (current_device >= 0 && current_device < config.nethernets)
962
    config.ethernets[current_device].irq = tempUL;
963
  else
964
    ERROR("invalid device number.");
965
}
966
 
967 645 markom
void eth_vapi_id () {
968
  if (current_device >= 0 && current_device < config.nethernets)
969 889 ivang
    config.ethernets[current_device].base_vapi_id = tempUL;
970 645 markom
  else
971
    ERROR("invalid device number.");
972
}
973
 
974
void gpio_ngpios () {
975
  if (tempL >= 0 && tempL < MAX_GPIOS)
976
    config.ngpios = tempL;
977
  else
978
    ERROR("invalid number of devices.");
979
}
980
 
981
void gpio_baseaddr () {
982
  if (current_device >= 0 && current_device < config.ngpios)
983
    config.gpios[current_device].baseaddr = tempUL;
984
  else
985
    ERROR("invalid device number.");
986
}
987
 
988
void gpio_irq () {
989
  if (current_device >= 0 && current_device < config.ngpios)
990
    config.gpios[current_device].irq = tempL;
991
  else
992
    ERROR("invalid device number.");
993
}
994
 
995
void gpio_base_vapi_id () {
996
  if (current_device >= 0 && current_device < config.ngpios)
997
    config.gpios[current_device].base_vapi_id = tempUL;
998
  else
999
    ERROR("invalid device number.");
1000
}
1001
 
1002
int is_power2 (int x) {
1003
  while (!(x & 1))
1004
    x >>= 1;
1005
  return x == 1;
1006
}
1007
 
1008
void immu_enabled () {
1009
  setsprbits (SPR_UPR, SPR_UPR_IMP, tempL & 1);
1010
  config.immu.enabled = tempL;
1011
}
1012
 
1013
void dmmu_enabled () {
1014
  setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1);
1015
  config.dmmu.enabled = tempL;
1016
}
1017
 
1018
void immu_nsets () {
1019
  if (is_power2(tempL) && tempL <= 256)
1020
    config.immu.nsets = tempL;
1021
  else
1022
    ERROR("value of power of two and lower or equal than 256 expected.");
1023
}
1024
 
1025
void dmmu_nsets () {
1026
  if (is_power2(tempL) && tempL <= 256)
1027
    config.dmmu.nsets = tempL;
1028
  else
1029
    ERROR("value of power of two and lower or equal than 256 expected.");
1030
}
1031
 
1032
void immu_nways () {
1033
  if (tempL >= 1 && tempL <= 4)
1034
    config.immu.nways = tempL;
1035
  else
1036
    ERROR("value 1, 2, 3 or 4 expected.");
1037
}
1038
 
1039
void dmmu_nways () {
1040
  if (tempL >= 1 && tempL <= 4)
1041
    config.dmmu.nways = tempL;
1042
  else
1043
    ERROR("value 1, 2, 3 or 4 expected.");
1044
}
1045
 
1046
void immu_pagesize () {
1047
  if (is_power2(tempL))
1048
    config.immu.pagesize = tempL;
1049
  else
1050
    ERROR("value of power of two expected.");
1051
}
1052
 
1053
void dmmu_pagesize () {
1054
  if (is_power2(tempL))
1055
    config.dmmu.pagesize = tempL;
1056
  else
1057
    ERROR("value of power of two expected.");
1058
}
1059
 
1060
void immu_entrysize () {
1061
  if (is_power2(tempL))
1062
    config.immu.entrysize = tempL;
1063
  else
1064
    ERROR("value of power of two expected.");
1065
}
1066
 
1067
void dmmu_entrysize () {
1068
  if (is_power2(tempL))
1069
    config.dmmu.entrysize = tempL;
1070
  else
1071
    ERROR("value of power of two expected.");
1072
}
1073
 
1074
void immu_ustates () {
1075
  if (tempL >= 2 && tempL <= 4)
1076
    config.immu.ustates = tempL;
1077
  else
1078
    ERROR("invalid USTATE.");
1079
}
1080
 
1081
void dmmu_ustates () {
1082
  if (tempL >= 2 && tempL <= 4)
1083
    config.dmmu.ustates = tempL;
1084
  else
1085
    ERROR("invalid USTATE.");
1086
}
1087
 
1088
void ic_enabled () {
1089
  config.ic.enabled = tempL;
1090
  setsprbits (SPR_UPR, SPR_UPR_ICP, tempL & 1);
1091
}
1092
 
1093
void ic_nsets () {
1094
  if (is_power2(tempL) && tempL <= MAX_IC_SETS)
1095
    config.ic.nsets = tempL;
1096
  else {
1097
    char tmp[200];
1098
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_IC_SETS);
1099
    ERROR(tmp);
1100
  }
1101
}
1102
 
1103
void ic_nways () {
1104
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
1105
    config.ic.nways = tempL;
1106
  else
1107
    ERROR("value 1, 2, 3 or 4 expected.");
1108
}
1109
 
1110
void ic_blocksize () {
1111
  if (is_power2(tempL))
1112
    config.ic.blocksize = tempL;
1113
  else
1114
    ERROR("value of power of two expected.");
1115
}
1116
 
1117
void ic_ustates () {
1118
  if (tempL >= 2 && tempL <= 4)
1119
    config.ic.ustates = tempL;
1120
  else
1121
    ERROR("invalid USTATE.");
1122
}
1123
 
1124
void dc_enabled () {
1125
  config.dc.enabled = tempL;
1126
  setsprbits (SPR_UPR, SPR_UPR_DCP, tempL & 1);
1127
}
1128
 
1129
void dc_nsets () {
1130
  if (is_power2(tempL) && tempL <= MAX_DC_SETS)
1131
    config.dc.nsets = tempL;
1132
  else {
1133
    char tmp[200];
1134
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
1135
    ERROR(tmp);
1136
  }
1137
}
1138
 
1139
void dc_nways () {
1140
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
1141
    config.dc.nways = tempL;
1142
  else
1143
    ERROR("value 1, 2, 3 or 4 expected.");
1144
}
1145
 
1146
void dc_blocksize () {
1147
  if (is_power2(tempL))
1148
    config.dc.blocksize = tempL;
1149
  else
1150
    ERROR("value of power of two expected.");
1151
}
1152
 
1153
void dc_ustates () {
1154
  if (tempL >= 2 && tempL <= 4)
1155
    config.dc.ustates = tempL;
1156
  else
1157
    ERROR("invalid USTATE.");
1158
}
1159
 
1160
void vga_nvgas () {
1161
  if (tempL >= 0 && tempL < MAX_VGAS)
1162
    config.nvgas = tempL;
1163
  else
1164
    ERROR("invalid number of devices.");
1165
}
1166
 
1167
void vga_baseaddr () {
1168
  if (current_device >= 0 && current_device < config.nvgas)
1169
    config.vgas[current_device].baseaddr = tempUL;
1170
  else
1171
    ERROR("invalid device number.");
1172
}
1173
 
1174
void vga_irq () {
1175
  if (current_device >= 0 && current_device < config.nvgas)
1176
    config.vgas[current_device].irq = tempL;
1177
  else
1178
    ERROR("invalid device number.");
1179
}
1180
 
1181
void vga_refresh_rate () {
1182
  if (current_device >= 0 && current_device < config.nvgas)
1183
    config.vgas[current_device].refresh_rate = tempUL;
1184
  else
1185
    ERROR("invalid device number.");
1186
}
1187
 
1188
void vga_filename () {
1189
  if (current_device >= 0 && current_device < config.nvgas)
1190
    strcpy (config.vgas[current_device].filename, tempS);
1191
  else
1192
    ERROR("invalid device number.");
1193
}
1194
 
1195 876 rherveille
 
1196
void ata_natas () {
1197
  if (tempL >= 0 && tempL < MAX_ATAS)
1198
    config.natas = tempL;
1199
  else
1200
    ERROR("invalid number of devices.");
1201
}
1202
 
1203
void ata_baseaddr () {
1204
  if (current_device >= 0 && current_device < config.natas)
1205
    config.atas[current_device].baseaddr = tempUL;
1206
  else
1207
    ERROR("invalid device number.");
1208
}
1209
 
1210
void ata_irq () {
1211
  if (current_device >= 0 && current_device < config.natas)
1212
    config.atas[current_device].irq = tempL;
1213
  else
1214
    ERROR("invalid device number.");
1215
}
1216
 
1217
void ata_dev_type0 () {
1218
  if (current_device >= 0 && current_device < config.natas)
1219
    config.atas[current_device].dev_type0 = tempL;
1220
  else
1221
    ERROR("invalid device number.");
1222
}
1223
 
1224
void ata_dev_file0 () {
1225
  if (current_device >= 0 && current_device < config.natas)
1226
    strcpy (config.atas[current_device].dev_file0, tempS);
1227
  else
1228
    ERROR("invalid device number.");
1229
}
1230
 
1231
void ata_dev_size0 () {
1232
  if (current_device >= 0 && current_device < config.natas)
1233
    config.atas[current_device].dev_size0 = tempUL;
1234
  else
1235
    ERROR("invalid device number.");
1236
}
1237
 
1238
void ata_dev_packet0 () {
1239
  if (current_device >= 0 && current_device < config.natas)
1240
    config.atas[current_device].dev_packet0 = tempL;
1241
  else
1242
    ERROR("invalid device number.");
1243
}
1244
 
1245
void ata_dev_type1 () {
1246
  if (current_device >= 0 && current_device < config.natas)
1247
    config.atas[current_device].dev_type1 = tempL;
1248
  else
1249
    ERROR("invalid device number.");
1250
}
1251
 
1252
void ata_dev_file1 () {
1253
  if (current_device >= 0 && current_device < config.natas)
1254
    strcpy (config.atas[current_device].dev_file1, tempS);
1255
  else
1256
    ERROR("invalid device number.");
1257
}
1258
 
1259
void ata_dev_size1 () {
1260
  if (current_device >= 0 && current_device < config.natas)
1261
    config.atas[current_device].dev_size1 = tempUL;
1262
  else
1263
    ERROR("invalid device number.");
1264
}
1265
 
1266
void ata_dev_packet1 () {
1267
  if (current_device >= 0 && current_device < config.natas)
1268
    config.atas[current_device].dev_packet1 = tempL;
1269
  else
1270
    ERROR("invalid device number.");
1271
}
1272
 
1273 897 markom
void cuc_memory_order () {
1274
  if (strcmp (tempS, "none") == 0)
1275
    config.cuc.memory_order = MO_NONE;
1276
  else if (strcmp (tempS, "weak") == 0)
1277
    config.cuc.memory_order = MO_WEAK;
1278
  else if (strcmp (tempS, "strong") == 0)
1279
    config.cuc.memory_order = MO_STRONG;
1280
  else if (strcmp (tempS, "exact") == 0) {
1281
    config.cuc.memory_order = MO_EXACT;
1282
  } else {
1283
    char tmp[200];
1284
    sprintf (tmp, "invalid memory order '%s'.\n", tempS);
1285
    ERROR(tmp);
1286
  }
1287
}
1288 876 rherveille
 
1289 645 markom
/* Read environment from a script file. Does not fail - assumes default configuration instead.
1290
   The syntax of script file is:
1291
   param = value
1292
   section x
1293
     data
1294
     param = value
1295
   end
1296
 
1297
   Example:
1298
   section mc
1299
     memory_table_file = sim.mem
1300
     enable = 1
1301
     POC = 0x47892344
1302
   end
1303
 
1304
 */
1305
 
1306
void read_script_file (char *filename)
1307
{
1308
  FILE *f;
1309
  unsigned long memory_needed = 0;
1310
  char *home = getenv("HOME");
1311
  char ctmp[STR_SIZE];
1312
  int local = 1;
1313
  section = 0;
1314
 
1315
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
1316
  if ((f = fopen (filename, "rt")) != NULL
1317
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
1318
    unsigned long start, length;
1319
    char type[STR_SIZE];
1320
    int nparam;
1321
    int rd, wd;
1322
    if (config.sim.verbose && !runtime.sim.output_cfg)
1323 997 markom
      PRINTF ("Reading script file from '%s'...\n", local ? filename : ctmp);
1324 645 markom
    strcpy (runtime.sim.script_fn, local ? filename : ctmp);
1325
 
1326
    while (!feof(f)) {
1327
      char param[STR_SIZE];
1328
      if (fscanf(f, "%s ", &param) != 1) break;
1329
      /* Is this a sections? */
1330
      if (strcmp (param, "section") == 0) {
1331
        int i;
1332
        section = 0;
1333
        if (fscanf (f, "%s\n", &param) != 1) {
1334
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
1335
          exit (1);
1336
        }
1337
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1338
          if (strcmp (sections[i].name, param) == 0) {
1339
            section = i;
1340
            break;
1341
          }
1342
        if (!section) {
1343
          char tmp[200];
1344
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
1345
          WARNING(tmp);
1346
          /* just skip section */
1347
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
1348
        }
1349
      } else if (strcmp (param, "end") == 0) {
1350
        section = 0;
1351
      } else if (strncmp (param, "/*", 2) == 0) {
1352
        char c0 = 0, c1 = 0;
1353
        while (c0 != '*' || c1 != '/') {
1354
          c0 = c1;
1355
          c1 = fgetc(f);
1356
          if (feof(f)) {
1357
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
1358
            exit (1);
1359
          }
1360
        }
1361
      } else {
1362
        int i, found = -1;
1363
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1364
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
1365
            found = i;
1366
            break;
1367
          }
1368
        if (found < 0) {
1369
          char tmp[200];
1370
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
1371
          WARNING(tmp);
1372
          while (fgetc(f) != '\n' || feof(f));
1373
          continue;
1374
        }
1375
 
1376
        /* Parse parameter value */
1377
        {
1378
          if (config_params[found].type[0])
1379
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
1380
              exit (1);
1381
        }
1382
        if (config_params[found].func)
1383
          config_params[found].func();
1384
      }
1385
    }
1386
    fclose (f);
1387
    runtime.sim.script_file_specified = 1;
1388
  } else
1389
    if (config.sim.verbose)
1390
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
1391
}
1392
 
1393
/* Utility for execution of set sim command.  */
1394
static int set_config (char *s)
1395
{
1396
  char *sec, *item, *params;
1397
  int noparams = 0, i, noitem = 0;
1398
  while (*s && isspace (*s)) s++;
1399
  sec = s;
1400 997 markom
  PRINTF ("s:%s\n", s);
1401 645 markom
  while (*s && *s != ' ') s++;
1402
  if (!(*s)) noitem = 1;
1403
  *s = 0;
1404 997 markom
  PRINTF ("sec:%s\n", sec);
1405 645 markom
  section = 0;
1406
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1407
    if (strcmp (sections[i].name, sec) == 0) {
1408
      section = i;
1409
      break;
1410
    }
1411
 
1412
  if (!section) return 1;
1413
  if (noitem) return 2;
1414
 
1415
  item = ++s;
1416
 
1417
  while (*s && *s != ' ') s++;
1418
  if (!(*s)) {
1419
    noparams = 1;
1420
    params = "";
1421
  } else
1422
    params = s + 1;
1423
  *s = 0;
1424 997 markom
  PRINTF ("item:%s\n", item);
1425
  PRINTF ("params:%s\n", params);
1426 645 markom
  {
1427
    int i, found = -1;
1428
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1429
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
1430
        found = i;
1431
        break;
1432
      }
1433
    if (found < 0) return 2;
1434
 
1435
    /* Parse parameter value */
1436
    if (config_params[found].type[0])
1437
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
1438
        return 3;
1439
    if (config_params[found].func)
1440
      config_params[found].func();
1441
  }
1442
  return 0;
1443
}
1444
 
1445
/* Executes set sim command, displays error.  */
1446
void set_config_command(char *s)
1447
{
1448
  int i;
1449
  switch (set_config (s)) {
1450
    case 1:
1451 997 markom
      PRINTF ("Invalid or missing section name.  One of valid sections must be specified:\n");
1452 645 markom
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1453 997 markom
        PRINTF ("%s ", sections[i].name);
1454
      PRINTF ("\n");
1455 645 markom
      break;
1456
    case 2:
1457 997 markom
      PRINTF ("Invalid or missing item name.  One of valid items must be specified:\n");
1458 645 markom
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1459
        if (config_params[i].section == section)
1460 997 markom
          PRINTF ("%s ", config_params[i].name);
1461
      PRINTF ("\n");
1462 645 markom
      break;
1463
    case 3:
1464 997 markom
      PRINTF ("Invalid parameters specified.\n");
1465 645 markom
      break;
1466
  }
1467
}
1468
#endif /* !FAST_SIM */
1469
 
1470
/* Outputs C structure of current config to file */
1471
void output_cfg (FILE *f)
1472
{
1473
  int i, comma;
1474
  fprintf (f, "/* This file was automatically generated by or1ksim,\n"
1475
              "   using --output-cfg switch (cfg file '%s'). */\n"
1476
  "const static struct config config = {\n", runtime.sim.script_fn);
1477
 
1478 731 ivang
  fprintf (f, "  tick:{enabled:%i},\n", config.tick.enabled);
1479 645 markom
  fprintf (f, "  nuarts:%i, uarts:{", config.nuarts);
1480
  comma = 0;
1481
  for (i = 0; i < config.nuarts; i++) {
1482
    fprintf (f, "%s\n    {rxfile:\"%s\", txfile:\"%s\", jitter:%i, baseaddr:0x%08x, irq:%i, vapi_id:0x%08x, uart16550:%i}",
1483
      comma ? "," :"", config.uarts[i].rxfile, config.uarts[i].txfile, config.uarts[i].jitter, config.uarts[i].baseaddr, config.uarts[i].irq,
1484
      config.uarts[i].vapi_id, config.uarts[i].uart16550);
1485
    comma = 1;
1486
  }
1487
  fprintf (f, "},\n");
1488
 
1489
  fprintf (f, "  ndmas:%i, dmas:{", config.ndmas);
1490
  comma = 0;
1491
  for (i = 0; i < config.ndmas; i++) {
1492
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, vapi_id:0x%08x}",
1493
      comma ? "," :"", config.dmas[i].baseaddr, config.dmas[i].irq, config.dmas[i].vapi_id);
1494
    comma = 1;
1495
  }
1496
  fprintf (f, "},\n");
1497
 
1498
  fprintf (f, "  nethernets:%i, ethernets:{", config.nethernets);
1499
  comma = 0;
1500
  for (i = 0; i < config.nethernets; i++) {
1501
    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}",
1502
      comma ? "," :"", config.ethernets[i].baseaddr, config.ethernets[i].dma, config.ethernets[i].tx_channel, config.ethernets[i].rx_channel,
1503 889 ivang
      config.ethernets[i].rxfile, config.ethernets[i].txfile, config.ethernets[i].base_vapi_id);
1504 645 markom
    comma = 1;
1505
  }
1506
  fprintf (f, "},\n");
1507
 
1508
  fprintf (f, "  ngpios:%i, gpios:{", config.ngpios);
1509
  comma = 0;
1510
  for (i = 0; i < config.ngpios; i++) {
1511
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, base_vapi_id:0x%08x}",
1512
      comma ? "," :"", config.gpios[i].baseaddr, config.gpios[i].irq, config.gpios[i].base_vapi_id);
1513
    comma = 1;
1514
  }
1515
  fprintf (f, "},\n");
1516
 
1517
  fprintf (f, "  mc:{enabled:%i, baseaddr:%i, POC:%i},\n", config.mc.enabled, config.mc.baseaddr, config.mc.POC);
1518
  fprintf (f, "  memory:{pattern:%i, random_seed:%i, type:%s, nmemories:%i, table:{", config.memory.pattern, config.memory.random_seed,
1519
    config.memory.type == MT_UNKNOWN ? "MT_UNKNOWN" : config.memory.type == MT_PATTERN ? "MT_PATTERN" : "MT_RANDOM", config.memory.nmemories);
1520
  comma = 0;
1521
  for (i = 0; i < config.memory.nmemories; i++) {
1522
    fprintf (f, "%s\n    {ce:%i, baseaddr:0x%08x, size:0x%08x, name:\"%s\", log:\"%s\", delayr:%i, delayw:%i}",
1523
      comma ? "," :"", config.memory.table[i].ce, config.memory.table[i].baseaddr, config.memory.table[i].size, config.memory.table[i].name,
1524
      config.memory.table[i].log, config.memory.table[i].delayr, config.memory.table[i].delayw);
1525
    comma = 1;
1526
  }
1527
  fprintf (f, "}},\n");
1528
 
1529
  fprintf (f, "  immu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1530
    config.immu.enabled, config.immu.nways, config.immu.nsets, config.immu.pagesize, config.immu.entrysize, config.immu.ustates,
1531
    config.immu.missdelay, config.immu.hitdelay);
1532
 
1533
  fprintf (f, "  dmmu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1534
    config.dmmu.enabled, config.dmmu.nways, config.dmmu.nsets, config.dmmu.pagesize, config.dmmu.entrysize, config.dmmu.ustates,
1535
    config.dmmu.missdelay, config.dmmu.hitdelay);
1536
 
1537
  fprintf (f, "  ic:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1538
    config.ic.enabled, config.ic.nways, config.ic.nsets, config.ic.blocksize, config.ic.ustates,
1539
    config.ic.missdelay, config.ic.hitdelay);
1540
 
1541
  fprintf (f, "  dc:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i,\n"
1542
    "    load_missdelay:%i, load_hitdelay:%i, store_missdelay:%i, store_hitdelay:%i},\n",
1543
    config.dc.enabled, config.dc.nways, config.dc.nsets, config.dc.blocksize, config.dc.ustates,
1544
    config.dc.load_missdelay, config.dc.load_hitdelay, config.dc.store_missdelay, config.dc.store_hitdelay);
1545
 
1546
  fprintf (f, "  bpb:{enabled:%i, sbp_bnf_fwd:%i, sbp_bf_fwd:%i, btic:%i, missdelay:%i, hitdelay:%i},\n",
1547
    config.bpb.enabled, config.bpb.sbp_bnf_fwd, config.bpb.sbp_bf_fwd, config.bpb.btic, config.bpb.missdelay, config.bpb.hitdelay);
1548
 
1549
  fprintf (f, "  cpu:{upr:0x%08x, ver:0x%04x, rev:0x%04x, superscalar:%i, hazards:%i, dependstats:%i,\n"
1550 732 ivang
    "    sr:0x%08x},\n",
1551 645 markom
    config.cpu.upr, config.cpu.ver, config.cpu.rev, config.cpu.superscalar, config.cpu.hazards, config.cpu.dependstats,
1552 732 ivang
    config.cpu.sr);
1553 645 markom
 
1554
  fprintf (f, "  sim:{debug:%i, verbose:%i, profile:%i, prof_fn:\"%s\", mprofile:%i, mprof_fn:\"%s\",\n",
1555
    config.sim.debug, config.sim.verbose, config.sim.profile, config.sim.prof_fn, config.sim.mprofile, config.sim.mprof_fn);
1556
 
1557
  fprintf (f, "    history:%i, exe_log:%i, exe_log_fn:\"%s\", clkcycle_ps:%i,\n",
1558
    config.sim.history, config.sim.exe_log, config.sim.exe_log_fn, config.sim.clkcycle_ps);
1559
 
1560
  fprintf (f, "    spr_log:%i, spr_log_fn:\"%s\"},\n",
1561
    config.sim.spr_log, config.sim.spr_log_fn);
1562
 
1563
  fprintf (f, "  debug:{enabled:%i, gdb_enabled:%i, server_port:%i, vapi_id:0x%08x},\n",
1564
    config.debug.enabled, config.debug.gdb_enabled, config.debug.server_port, config.debug.vapi_id);
1565
 
1566
  fprintf (f, "  vapi:{enabled:%i, server_port:%i, log_enabled:%i, hide_device_id:%i, vapi_fn:\"%s\"},\n",
1567
    config.vapi.enabled, config.vapi.server_port, config.vapi.log_enabled, config.vapi.hide_device_id, config.vapi.vapi_fn);
1568
 
1569
  fprintf (f, "  pm:{enabled:%i}\n",
1570
    config.pm.enabled);
1571
 
1572
  fprintf (f, "};\n");
1573
}

powered by: WebSVN 2.1.0

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