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 889

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

powered by: WebSVN 2.1.0

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