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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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