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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_66/] [or1ksim/] [sim-config.c] - Blame information for rev 876

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

powered by: WebSVN 2.1.0

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