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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_62/] [or1ksim/] [sim-config.c] - Blame information for rev 1344

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

powered by: WebSVN 2.1.0

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