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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [or1ksim/] [sim-config.c] - Blame information for rev 568

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
}
855 424 markom
 
856 425 markom
void dmmu_enabled () {
857
  setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1);
858
}
859
 
860
void immu_nsets () {
861
  if (is_power2(tempL) && tempL <= 256)
862
    config.immu.nsets = tempL;
863
  else
864 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
865 425 markom
}
866
 
867
void dmmu_nsets () {
868
  if (is_power2(tempL) && tempL <= 256)
869
    config.dmmu.nsets = tempL;
870
  else
871 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
872 425 markom
}
873
 
874
void immu_nways () {
875
  if (tempL >= 1 && tempL <= 4)
876
    config.immu.nways = tempL;
877
  else
878
    ERROR("value 1, 2, 3 or 4 expected.");
879
}
880
 
881
void dmmu_nways () {
882
  if (tempL >= 1 && tempL <= 4)
883
    config.dmmu.nways = tempL;
884
  else
885
    ERROR("value 1, 2, 3 or 4 expected.");
886
}
887
 
888
void immu_pagesize () {
889
  if (is_power2(tempL))
890
    config.immu.pagesize = tempL;
891
  else
892 428 markom
    ERROR("value of power of two expected.");
893 425 markom
}
894
 
895
void dmmu_pagesize () {
896
  if (is_power2(tempL))
897
    config.dmmu.pagesize = tempL;
898
  else
899 428 markom
    ERROR("value of power of two expected.");
900 425 markom
}
901
 
902
void immu_entrysize () {
903
  if (is_power2(tempL))
904
    config.immu.entrysize = tempL;
905
  else
906 428 markom
    ERROR("value of power of two expected.");
907 425 markom
}
908
 
909
void dmmu_entrysize () {
910
  if (is_power2(tempL))
911
    config.dmmu.entrysize = tempL;
912
  else
913 428 markom
    ERROR("value of power of two expected.");
914 425 markom
}
915
 
916
void immu_ustates () {
917
  if (tempL >= 2 && tempL <= 4)
918
    config.immu.ustates = tempL;
919
  else
920
    ERROR("invalid USTATE.");
921
}
922
 
923
void dmmu_ustates () {
924
  if (tempL >= 2 && tempL <= 4)
925
    config.dmmu.ustates = tempL;
926
  else
927
    ERROR("invalid USTATE.");
928
}
929
 
930 428 markom
void ic_enabled () {
931
  setsprbits (SPR_UPR, SPR_UPR_ICP, tempL & 1);
932
}
933
 
934
void ic_nsets () {
935
  if (is_power2(tempL) && tempL <= MAX_IC_SETS)
936
    config.ic.nsets = tempL;
937
  else {
938
    char tmp[200];
939
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_IC_SETS);
940
    ERROR(tmp);
941
  }
942
}
943
 
944
void ic_nways () {
945
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
946
    config.ic.nways = tempL;
947
  else
948
    ERROR("value 1, 2, 3 or 4 expected.");
949
}
950
 
951
void ic_blocksize () {
952
  if (is_power2(tempL))
953
    config.ic.blocksize = tempL;
954
  else
955
    ERROR("value of power of two expected.");
956
}
957
 
958
void ic_ustates () {
959
  if (tempL >= 2 && tempL <= 4)
960
    config.ic.ustates = tempL;
961
  else
962
    ERROR("invalid USTATE.");
963
}
964
 
965
void ic_tagtype () {
966
  if (strcmp (tempS, "none") == 0)
967
    config.ic.tagtype = CT_NONE;
968
  else if (strcmp (tempS, "physical") == 0)
969
    config.ic.tagtype = CT_PHYSICAL;
970
  else if (strcmp (tempS, "virtual") == 0)
971
    config.ic.tagtype = CT_VIRTUAL;
972
  else {
973
    char tmp[200];
974
    sprintf (tmp, "invalid cache type '%s'.\n", tempS);
975
    ERROR(tmp);
976
  }
977
}
978
 
979
void dc_enabled () {
980
  setsprbits (SPR_UPR, SPR_UPR_DCP, tempL & 1);
981
}
982
 
983
void dc_nsets () {
984
  if (is_power2(tempL) && tempL <= MAX_DC_SETS)
985
    config.dc.nsets = tempL;
986
  else {
987
    char tmp[200];
988
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
989
    ERROR(tmp);
990
  }
991
}
992
 
993
void dc_nways () {
994
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
995
    config.dc.nways = tempL;
996
  else
997
    ERROR("value 1, 2, 3 or 4 expected.");
998
}
999
 
1000
void dc_blocksize () {
1001
  if (is_power2(tempL))
1002
    config.dc.blocksize = tempL;
1003
  else
1004
    ERROR("value of power of two expected.");
1005
}
1006
 
1007
void dc_ustates () {
1008
  if (tempL >= 2 && tempL <= 4)
1009
    config.dc.ustates = tempL;
1010
  else
1011
    ERROR("invalid USTATE.");
1012
}
1013
 
1014
void dc_tagtype () {
1015
  if (strcmp (tempS, "none") == 0)
1016
    config.dc.tagtype = CT_NONE;
1017
  else if (strcmp (tempS, "physical") == 0)
1018
    config.dc.tagtype = CT_PHYSICAL;
1019
  else if (strcmp (tempS, "virtual") == 0)
1020
    config.dc.tagtype = CT_VIRTUAL;
1021
  else {
1022
    char tmp[200];
1023
    sprintf (tmp, "invalid cache type '%s'.\n", tempS);
1024
    ERROR(tmp);
1025
  }
1026
}
1027
 
1028 424 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
1029
   The syntax of script file is:
1030
   param = value
1031
   section x
1032
     data
1033
     param = value
1034
   end
1035
 
1036
   Example:
1037
   section mc
1038
     memory_table_file = sim.mem
1039
     enable = 1
1040
     POC = 0x47892344
1041
   end
1042
 
1043
 */
1044
 
1045
void read_script_file (char *filename)
1046
{
1047
  FILE *f;
1048
  unsigned long memory_needed = 0;
1049
  char *home = getenv("HOME");
1050
  char ctmp[STR_SIZE];
1051
  int local = 1;
1052
  section = 0;
1053
 
1054
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
1055
  if ((f = fopen (filename, "rt")) != NULL
1056
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
1057
    unsigned long start, length;
1058
    char type[STR_SIZE];
1059
    int nparam;
1060
    int rd, wd;
1061 549 markom
    if (config.sim.verbose && !runtime.sim.output_cfg)
1062 428 markom
      printf ("Reading script file from '%s'...\n", local ? filename : ctmp);
1063 549 markom
    strcpy (runtime.sim.script_fn, local ? filename : ctmp);
1064
 
1065 424 markom
    while (!feof(f)) {
1066
      char param[STR_SIZE];
1067
      if (fscanf(f, "%s ", &param) != 1) break;
1068
      /* Is this a sections? */
1069
      if (strcmp (param, "section") == 0) {
1070
        int i;
1071
        section = 0;
1072
        if (fscanf (f, "%s\n", &param) != 1) {
1073
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
1074
          exit (1);
1075
        }
1076
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1077
          if (strcmp (sections[i].name, param) == 0) {
1078
            section = i;
1079
            break;
1080
          }
1081
        if (!section) {
1082
          char tmp[200];
1083
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
1084
          WARNING(tmp);
1085
          /* just skip section */
1086
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
1087
        }
1088
      } else if (strcmp (param, "end") == 0) {
1089
        section = 0;
1090
      } else if (strncmp (param, "/*", 2) == 0) {
1091
        char c0 = 0, c1 = 0;
1092
        while (c0 != '*' || c1 != '/') {
1093
          c0 = c1;
1094
          c1 = fgetc(f);
1095
          if (feof(f)) {
1096
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
1097
            exit (1);
1098
          }
1099
        }
1100
      } else {
1101
        int i, found = -1;
1102
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1103
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
1104
            found = i;
1105
            break;
1106
          }
1107
        if (found < 0) {
1108
          char tmp[200];
1109
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
1110
          WARNING(tmp);
1111
          while (fgetc(f) != '\n' || feof(f));
1112
          continue;
1113
        }
1114
 
1115
        /* Parse parameter value */
1116
        {
1117
          if (config_params[found].type[0])
1118
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
1119
              exit (1);
1120
        }
1121
        if (config_params[found].func)
1122
          config_params[found].func();
1123
      }
1124
    }
1125
    fclose (f);
1126
    runtime.sim.script_file_specified = 1;
1127
  } else
1128
    if (config.sim.verbose)
1129
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
1130
}
1131
 
1132
/* Utility for execution of set sim command.  */
1133
static int set_config (char *s)
1134
{
1135
  char *sec, *item, *params;
1136
  int noparams = 0, i, noitem = 0;
1137 434 markom
  while (*s && isspace (*s)) s++;
1138 424 markom
  sec = s;
1139
  printf ("s:%s\n", s);
1140
  while (*s && *s != ' ') s++;
1141
  if (!(*s)) noitem = 1;
1142
  *s = 0;
1143
  printf ("sec:%s\n", sec);
1144
  section = 0;
1145
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1146
    if (strcmp (sections[i].name, sec) == 0) {
1147
      section = i;
1148
      break;
1149
    }
1150
 
1151
  if (!section) return 1;
1152
  if (noitem) return 2;
1153
 
1154
  item = ++s;
1155
 
1156
  while (*s && *s != ' ') s++;
1157
  if (!(*s)) {
1158
    noparams = 1;
1159
    params = "";
1160
  } else
1161
    params = s + 1;
1162
  *s = 0;
1163
  printf ("item:%s\n", item);
1164
  printf ("params:%s\n", params);
1165
  {
1166
    int i, found = -1;
1167
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1168
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
1169
        found = i;
1170
        break;
1171
      }
1172
    if (found < 0) return 2;
1173
 
1174
    /* Parse parameter value */
1175
    if (config_params[found].type[0])
1176
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
1177
        return 3;
1178
    if (config_params[found].func)
1179
      config_params[found].func();
1180
  }
1181
  return 0;
1182
}
1183
 
1184
/* Executes set sim command, displays error.  */
1185
void set_config_command(char *s)
1186
{
1187
  int i;
1188
  switch (set_config (s)) {
1189
    case 1:
1190
      printf ("Invalid or missing section name.  One of valid sections must be specified:\n");
1191
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1192
        printf ("%s ", sections[i].name);
1193
      printf ("\n");
1194
      break;
1195
    case 2:
1196
      printf ("Invalid or missing item name.  One of valid items must be specified:\n");
1197
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1198
        if (config_params[i].section == section)
1199
          printf ("%s ", config_params[i].name);
1200
      printf ("\n");
1201
      break;
1202
    case 3:
1203
      printf ("Invalid parameters specified.\n");
1204
      break;
1205
  }
1206
}
1207 551 markom
#endif /* !FAST_SIM */
1208 549 markom
 
1209
/* Outputs C structure of current config to file */
1210
void output_cfg (FILE *f)
1211
{
1212
  int i, comma;
1213
  fprintf (f, "/* This file was automatically generated by or1ksim,\n"
1214
              "   using --output-cfg switch (cfg file '%s'). */\n"
1215
  "const static struct config config = {\n", runtime.sim.script_fn);
1216
 
1217
  fprintf (f, "  tick:{enabled:%i, irq:%i},\n", config.tick.enabled, config.tick.irq);
1218
  fprintf (f, "  nuarts:%i, uarts:{", config.nuarts);
1219
  comma = 0;
1220
  for (i = 0; i < config.nuarts; i++) {
1221
    fprintf (f, "%s\n    {rxfile:\"%s\", txfile:\"%s\", jitter:%i, baseaddr:0x%08x, irq:%i, vapi_id:0x%08x, uart16550:%i}",
1222
      comma ? "," :"", config.uarts[i].rxfile, config.uarts[i].txfile, config.uarts[i].jitter, config.uarts[i].baseaddr, config.uarts[i].irq,
1223
      config.uarts[i].vapi_id, config.uarts[i].uart16550);
1224
    comma = 1;
1225
  }
1226
  fprintf (f, "},\n");
1227
 
1228
  fprintf (f, "  ndmas:%i, dmas:{", config.ndmas);
1229
  comma = 0;
1230
  for (i = 0; i < config.ndmas; i++) {
1231
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, vapi_id:0x%08x}",
1232
      comma ? "," :"", config.dmas[i].baseaddr, config.dmas[i].irq, config.dmas[i].vapi_id);
1233
    comma = 1;
1234
  }
1235
  fprintf (f, "},\n");
1236
 
1237
  fprintf (f, "  nethernets:%i, ethernets:{", config.nethernets);
1238
  comma = 0;
1239
  for (i = 0; i < config.nethernets; i++) {
1240
    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}",
1241
      comma ? "," :"", config.ethernets[i].baseaddr, config.ethernets[i].dma, config.ethernets[i].tx_channel, config.ethernets[i].rx_channel,
1242
      config.ethernets[i].rxfile, config.ethernets[i].txfile, config.ethernets[i].vapi_id);
1243
    comma = 1;
1244
  }
1245
  fprintf (f, "},\n");
1246
 
1247
  fprintf (f, "  ngpios:%i, gpios:{", config.ngpios);
1248
  comma = 0;
1249
  for (i = 0; i < config.ngpios; i++) {
1250
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, base_vapi_id:0x%08x}",
1251
      comma ? "," :"", config.gpios[i].baseaddr, config.gpios[i].irq, config.gpios[i].base_vapi_id);
1252
    comma = 1;
1253
  }
1254
  fprintf (f, "},\n");
1255
 
1256
  fprintf (f, "  mc:{enabled:%i, baseaddr:%i, POC:%i},\n", config.mc.enabled, config.mc.baseaddr, config.mc.POC);
1257
  fprintf (f, "  memory:{pattern:%i, random_seed:%i, type:%s, nmemories:%i, table:{", config.memory.pattern, config.memory.random_seed,
1258
    config.memory.type == MT_UNKNOWN ? "MT_UNKNOWN" : config.memory.type == MT_PATTERN ? "MT_PATTERN" : "MT_RANDOM", config.memory.nmemories);
1259
  comma = 0;
1260
  for (i = 0; i < config.memory.nmemories; i++) {
1261
    fprintf (f, "%s\n    {ce:%i, baseaddr:0x%08x, size:0x%08x, name:\"%s\", log:\"%s\", delayr:%i, delayw:%i}",
1262
      comma ? "," :"", config.memory.table[i].ce, config.memory.table[i].baseaddr, config.memory.table[i].size, config.memory.table[i].name,
1263
      config.memory.table[i].log, config.memory.table[i].delayr, config.memory.table[i].delayw);
1264
    comma = 1;
1265
  }
1266
  fprintf (f, "}},\n");
1267
 
1268
  fprintf (f, "  immu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1269
    config.immu.enabled, config.immu.nways, config.immu.nsets, config.immu.pagesize, config.immu.entrysize, config.immu.ustates,
1270
    config.immu.missdelay, config.immu.hitdelay);
1271
 
1272
  fprintf (f, "  dmmu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1273
    config.dmmu.enabled, config.dmmu.nways, config.dmmu.nsets, config.dmmu.pagesize, config.dmmu.entrysize, config.dmmu.ustates,
1274
    config.dmmu.missdelay, config.dmmu.hitdelay);
1275
 
1276
  fprintf (f, "  ic:{enabled:%i, tagtype:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1277
    config.ic.enabled, config.ic.tagtype, config.ic.nways, config.ic.nsets, config.ic.blocksize, config.ic.ustates,
1278
    config.ic.missdelay, config.ic.hitdelay);
1279
 
1280 557 markom
  fprintf (f, "  dc:{enabled:%i, tagtype:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i,\n"
1281
    "    load_missdelay:%i, load_hitdelay:%i, store_missdelay:%i, store_hitdelay:%i},\n",
1282 549 markom
    config.dc.enabled, config.dc.tagtype, config.dc.nways, config.dc.nsets, config.dc.blocksize, config.dc.ustates,
1283
    config.dc.load_missdelay, config.dc.load_hitdelay, config.dc.store_missdelay, config.dc.store_hitdelay);
1284
 
1285
  fprintf (f, "  bpb:{enabled:%i, sbp_bnf_fwd:%i, sbp_bf_fwd:%i, btic:%i, missdelay:%i, hitdelay:%i},\n",
1286
    config.bpb.enabled, config.bpb.sbp_bnf_fwd, config.bpb.sbp_bf_fwd, config.bpb.btic, config.bpb.missdelay, config.bpb.hitdelay);
1287
 
1288 557 markom
  fprintf (f, "  cpu:{upr:0x%08x, ver:0x%04x, rev:0x%04x, superscalar:%i, hazards:%i, dependstats:%i,\n"
1289
    "    raw_range:%i, sr:0x%08x},\n",
1290
    config.cpu.upr, config.cpu.ver, config.cpu.rev, config.cpu.superscalar, config.cpu.hazards, config.cpu.dependstats,
1291
    config.cpu.raw_range, config.cpu.sr);
1292 549 markom
 
1293 551 markom
  fprintf (f, "  sim:{debug:%i, verbose:%i, profile:%i, prof_fn:\"%s\", mprofile:%i, mprof_fn:\"%s\",\n",
1294
    config.sim.debug, config.sim.verbose, config.sim.profile, config.sim.prof_fn, config.sim.mprofile, config.sim.mprof_fn);
1295 549 markom
 
1296
  fprintf (f, "    history:%i, exe_log:%i, exe_log_fn:\"%s\", clkcycle_ps:%i},\n",
1297
    config.sim.history, config.sim.exe_log, config.sim.exe_log_fn, config.sim.clkcycle_ps);
1298
 
1299
  fprintf (f, "  debug:{enabled:%i, gdb_enabled:%i, server_port:%i, vapi_id:0x%08x},\n",
1300
    config.debug.enabled, config.debug.gdb_enabled, config.debug.server_port, config.debug.vapi_id);
1301
 
1302 557 markom
  fprintf (f, "  vapi:{enabled:%i, server_port:%i, log_enabled:%i, hide_device_id:%i, vapi_fn:\"%s\"},\n",
1303 549 markom
    config.vapi.enabled, config.vapi.server_port, config.vapi.log_enabled, config.vapi.hide_device_id, config.vapi.vapi_fn);
1304 557 markom
 
1305
  fprintf (f, "  pm:{enabled:%i}\n",
1306
    config.pm.enabled);
1307 549 markom
 
1308
  fprintf (f, "};\n");
1309
}

powered by: WebSVN 2.1.0

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