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 897

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

powered by: WebSVN 2.1.0

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