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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_49/] [or1ksim/] [sim-config.c] - Blame information for rev 599

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
 
502
{11, "enabled",           "=%i",         immu_enabled,  (void *)(&tempL), 0},
503
{11, "nsets",             "=%i",         immu_nsets,    (void *)(&tempL), 0},
504
{11, "nways",             "=%i",         immu_nways,    (void *)(&tempL), 0},
505
{11, "pagesize",          "=%i",         immu_pagesize, (void *)(&tempL), 0},
506
{11, "entrysize",         "=%i",         immu_entrysize,(void *)(&tempL), 0},
507
{11, "ustates",           "=%i",         immu_ustates,  (void *)(&tempL), 0},
508
{11, "missdelay",         "=%i",         NULL,          (void *)(&config.immu.missdelay), 0},
509
{11, "hitdelay",          "=%i",         NULL,          (void *)(&config.immu.hitdelay), 0},
510
 
511
{12, "enabled",           "=%i",         dmmu_enabled,  (void *)(&tempL), 0},
512
{12, "nsets",             "=%i",         dmmu_nsets,    (void *)(&tempL), 0},
513
{12, "nways",             "=%i",         dmmu_nways,    (void *)(&tempL), 0},
514
{12, "pagesize",          "=%i",         dmmu_pagesize, (void *)(&tempL), 0},
515
{12, "entrysize",         "=%i",         dmmu_entrysize,(void *)(&tempL), 0},
516
{12, "ustates",           "=%i",         dmmu_ustates,  (void *)(&tempL), 0},
517
{12, "missdelay",         "=%i",         NULL,          (void *)(&config.dmmu.missdelay), 0},
518
{12, "hitdelay",          "=%i",         NULL,          (void *)(&config.dmmu.hitdelay), 0},
519
 
520
{13, "enabled",           "=%i",         ic_enabled,    (void *)(&tempL), 0},
521
{13, "nsets",             "=%i",         ic_nsets,      (void *)(&tempL), 0},
522
{13, "nways",             "=%i",         ic_nways,      (void *)(&tempL), 0},
523
{13, "blocksize",         "=%i",         ic_blocksize,  (void *)(&tempL), 0},
524
{13, "ustates",           "=%i",         ic_ustates,    (void *)(&tempL), 0},
525
{13, "tagtype",           "=%s ",        ic_tagtype,    (void *)(&tempS), 0},
526
{13, "missdelay",         "=%i",         NULL,          (void *)(&config.ic.missdelay), 0},
527
{13, "hitdelay",          "=%i",         NULL,          (void *)(&config.ic.hitdelay), 0},
528
 
529
{14, "enabled",           "=%i",         dc_enabled,    (void *)(&tempL), 0},
530
{14, "nsets",             "=%i",         dc_nsets,      (void *)(&tempL), 0},
531
{14, "nways",             "=%i",         dc_nways,      (void *)(&tempL), 0},
532
{14, "blocksize",         "=%i",         dc_blocksize,  (void *)(&tempL), 0},
533
{14, "ustates",           "=%i",         dc_ustates,    (void *)(&tempL), 0},
534
{14, "tagtype",           "=%s ",        dc_tagtype,    (void *)(&tempS), 0},
535
{14, "load_missdelay",    "=%i",         NULL,          (void *)(&config.dc.load_missdelay), 0},
536
{14, "load_hitdelay",     "=%i",         NULL,          (void *)(&config.dc.load_hitdelay), 0},
537
{14, "store_missdelay",   "=%i",         NULL,          (void *)(&config.dc.store_missdelay), 0},
538
{14, "store_hitdelay",    "=%i",         NULL,          (void *)(&config.dc.store_hitdelay), 0},
539
 
540
{15, "ngpios",            "=%i",         gpio_ngpios,   (void *)(&tempL), CPF_GLOBAL},
541
{15, "device",            "%i",          change_device, (void *)(&tempL), 0},
542
{15, "baseaddr",          "=0x%x",       gpio_baseaddr, (void *)(&tempUL), 0},
543
{15, "irq",               "=%i",         gpio_irq,      (void *)(&tempL), 0},
544
{15, "base_vapi_id",      "=0x%x",       gpio_base_vapi_id,   (void *)(&tempUL), 0},
545
{15, "enddevice",         "",            end_device,    NULL, 0},
546
 
547
{16, "enabled",           "=%i",         NULL,          (void *)(&config.bpb.enabled), 0},
548
{16, "btic",              "=%i",         NULL,          (void *)(&config.bpb.btic), 0},
549
{16, "sbp_bnf_fwd",       "=%i",         NULL,          (void *)(&config.bpb.sbp_bnf_fwd), 0},
550
{16, "sbp_bf_fwd",        "=%i",         NULL,          (void *)(&config.bpb.sbp_bf_fwd), 0},
551
{16, "missdelay",         "=%i",         NULL,          (void *)(&config.bpb.missdelay), 0},
552 557 markom
{16, "hitdelay",          "=%i",         NULL,          (void *)(&config.bpb.hitdelay), 0},
553
 
554
{17, "enabled",           "=%i",         NULL,          (void *)(&config.pm.enabled), 0}
555 424 markom
};
556
 
557
/* *INDENT-ON* */
558
 
559
int current_device = -1;
560
void change_device () {
561
  current_device = tempL;
562
}
563
 
564
void end_device () {
565
  current_device = -1;
566
}
567
 
568 568 markom
void base_include () {
569
  read_script_file (tempS);
570
  section = 0;
571
}
572
 
573 433 markom
void sim_clkcycle () {
574
  int len = strlen (tempS);
575
  int pos = len - 1;
576
  long time;
577
  if (len < 2) goto err;
578
  if (tempS[pos--] != 's') goto err;
579
  switch (tempS[pos--]) {
580
    case 'p': time = 1; break;
581
    case 'n': time = 1000; break;
582
    case 'u': time = 1000000; break;
583
    case 'm': time = 1000000000; break;
584
  default:
585
    goto err;
586
  }
587 490 markom
  tempS[pos + 1] = 0;
588 433 markom
  config.sim.clkcycle_ps = time * atol (tempS);
589
  return;
590
err:
591
  ERROR("invalid time format.");
592
}
593
 
594 424 markom
void uart_nuarts () {
595
  if (tempL >= 0 && tempL < MAX_UARTS)
596
    config.nuarts = tempL;
597
  else
598
    ERROR("invalid number of devices.");
599
}
600
 
601
void uart_baseaddr () {
602
  if (current_device >= 0 && current_device < config.nuarts)
603
    config.uarts[current_device].baseaddr = tempUL;
604
  else
605
    ERROR("invalid device number.");
606
}
607
 
608
void uart_jitter () {
609
  if (current_device >= 0 && current_device < config.nuarts)
610
    config.uarts[current_device].jitter = tempL;
611
  else
612
    ERROR("invalid device number.");
613
}
614
 
615
void uart_irq () {
616
  if (current_device >= 0 && current_device < config.nuarts)
617
    config.uarts[current_device].irq = tempL;
618
  else
619
    ERROR("invalid device number.");
620
}
621
 
622
void uart_16550 () {
623
  if (current_device >= 0 && current_device < config.nuarts)
624
    config.uarts[current_device].uart16550 = tempL;
625
  else
626
    ERROR("invalid device number.");
627
}
628
 
629
void uart_rxfile () {
630
  if (current_device >= 0 && current_device < config.nuarts)
631
    strcpy (config.uarts[current_device].rxfile, tempS);
632
  else
633
    ERROR("invalid device number.");
634
}
635
 
636
void uart_txfile () {
637
  if (current_device >= 0 && current_device < config.nuarts)
638
    strcpy (config.uarts[current_device].txfile, tempS);
639
  else
640
    ERROR("invalid device number.");
641
}
642
 
643
void uart_vapi_id () {
644
  if (current_device >= 0 && current_device < config.nuarts)
645
    config.uarts[current_device].vapi_id = tempUL;
646
  else
647
    ERROR("invalid device number.");
648
}
649
 
650
void dma_ndmas () {
651
  if (tempL >= 0 && tempL < MAX_DMAS)
652
    config.ndmas = tempL;
653
  else
654
    ERROR("invalid number of devices.");
655
}
656
 
657
void dma_baseaddr () {
658
  if (current_device >= 0 && current_device < config.ndmas)
659
    config.dmas[current_device].baseaddr = tempUL;
660
  else
661
    ERROR("invalid device number.");
662
}
663
 
664
void dma_irq () {
665
  if (current_device >= 0 && current_device < config.ndmas)
666
    config.dmas[current_device].irq = tempL;
667
  else
668
    ERROR("invalid device number.");
669
}
670
 
671
void dma_vapi_id () {
672
  if (current_device >= 0 && current_device < config.ndmas)
673
    config.dmas[current_device].vapi_id = tempUL;
674
  else
675
    ERROR("invalid device number.");
676
}
677
 
678
void memory_nmemories () {
679
  if (tempL >= 0 && tempL < MAX_MEMORIES)
680
    config.memory.nmemories = tempL;
681
  else
682
    ERROR("invalid number of devices.");
683
}
684
 
685
void memory_type () {
686
  if (strcmp (tempS, "unknown") == 0)
687
    config.memory.type = MT_UNKNOWN;
688
  else if (strcmp (tempS, "random") == 0)
689
    config.memory.type = MT_RANDOM;
690
  else if (strcmp (tempS, "pattern") == 0)
691
    config.memory.type = MT_PATTERN;
692
  else if (strcmp (tempS, "zero") == 0) {
693
    config.memory.type = MT_PATTERN;
694
    config.memory.pattern = 0;
695
  } else {
696
    char tmp[200];
697
    sprintf (tmp, "invalid memory type '%s'.\n", tempS);
698
    ERROR(tmp);
699
  }
700
}
701
 
702
void memory_ce () {
703
  if (current_device >= 0 && current_device < config.memory.nmemories)
704
    config.memory.table[current_device].ce = tempL;
705
  else
706
    ERROR("invalid device number.");
707
}
708
 
709
void memory_baseaddr () {
710
  if (current_device >= 0 && current_device < config.memory.nmemories)
711
    config.memory.table[current_device].baseaddr = tempUL;
712
  else
713
    ERROR("invalid device number.");
714
}
715
 
716
void memory_size () {
717
  if (current_device >= 0 && current_device < config.memory.nmemories)
718
    config.memory.table[current_device].size = tempUL;
719
  else
720
    ERROR("invalid device number.");
721
}
722
 
723
void memory_name () {
724
  if (current_device >= 0 && current_device < config.memory.nmemories)
725
    strcpy (config.memory.table[current_device].name, tempS);
726
  else
727
    ERROR("invalid device number.");
728
}
729
 
730
void memory_log () {
731
  if (current_device >= 0 && current_device < config.memory.nmemories)
732
    strcpy (config.memory.table[current_device].log, tempS);
733
  else
734
    ERROR("invalid device number.");
735
}
736
 
737
void memory_delayr () {
738
  if (current_device >= 0 && current_device < config.memory.nmemories)
739
    config.memory.table[current_device].delayr = tempL;
740
  else
741
    ERROR("invalid device number.");
742
}
743
 
744
void memory_delayw () {
745
  if (current_device >= 0 && current_device < config.memory.nmemories)
746
    config.memory.table[current_device].delayw = tempL;
747
  else
748
    ERROR("invalid device number.");
749
}
750
 
751 535 markom
void cpu_raw_range () {
752
  if (config.cpu.raw_range >= RAW_RANGE) {
753
    config.cpu.raw_range = RAW_RANGE - 1;
754
    WARNING("raw range too large; truncated.");
755
  } else if (config.cpu.raw_range < 0) {
756
    config.cpu.raw_range = 0;
757
    WARNING("raw range negative; disabled.");
758
  }
759
}
760
 
761 424 markom
void eth_nethernets () {
762
  if (tempL >= 0 && tempL < MAX_ETHERNETS)
763
    config.nethernets = tempL;
764
  else
765
    ERROR("invalid number of devices.");
766
}
767
 
768
void eth_baseaddr () {
769
  if (current_device >= 0 && current_device < config.nethernets)
770
    config.ethernets[current_device].baseaddr = tempUL;
771
  else
772
    ERROR("invalid device number.");
773
}
774
 
775
void eth_dma () {
776
  if (current_device >= 0 && current_device < config.nethernets)
777
    config.ethernets[current_device].dma = tempL;
778
  else
779
    ERROR("invalid device number.");
780
}
781
 
782
void eth_rx_channel () {
783
  if (current_device >= 0 && current_device < config.nethernets)
784
    config.ethernets[current_device].rx_channel = tempL;
785
  else
786
    ERROR("invalid device number.");
787
}
788
 
789
void eth_tx_channel () {
790
  if (current_device >= 0 && current_device < config.nethernets)
791
    config.ethernets[current_device].rx_channel = tempL;
792
  else
793
    ERROR("invalid device number.");
794
}
795
 
796
void eth_rxfile () {
797
  if (current_device >= 0 && current_device < config.nethernets)
798
    strcpy (config.ethernets[current_device].rxfile, tempS);
799
  else
800
    ERROR("invalid device number.");
801
}
802
 
803
void eth_txfile () {
804
  if (current_device >= 0 && current_device < config.nethernets)
805
    strcpy (config.ethernets[current_device].txfile, tempS);
806
  else
807
    ERROR("invalid device number.");
808
}
809
 
810
void eth_vapi_id () {
811
  if (current_device >= 0 && current_device < config.nethernets)
812
    config.ethernets[current_device].vapi_id = tempUL;
813
  else
814 425 markom
    ERROR("invalid device number.");
815 424 markom
}
816
 
817 444 erez
void gpio_ngpios () {
818
  if (tempL >= 0 && tempL < MAX_GPIOS)
819
    config.ngpios = tempL;
820
  else
821
    ERROR("invalid number of devices.");
822
}
823
 
824
void gpio_baseaddr () {
825
  if (current_device >= 0 && current_device < config.ngpios)
826
    config.gpios[current_device].baseaddr = tempUL;
827
  else
828
    ERROR("invalid device number.");
829
}
830
 
831
void gpio_irq () {
832
  if (current_device >= 0 && current_device < config.ngpios)
833
    config.gpios[current_device].irq = tempL;
834
  else
835
    ERROR("invalid device number.");
836
}
837
 
838 477 erez
void gpio_base_vapi_id () {
839 444 erez
  if (current_device >= 0 && current_device < config.ngpios)
840 477 erez
    config.gpios[current_device].base_vapi_id = tempUL;
841 444 erez
  else
842
    ERROR("invalid device number.");
843
}
844
 
845 425 markom
int is_power2 (int x) {
846
  while (!(x & 1))
847
    x >>= 1;
848
  return x == 1;
849
}
850 424 markom
 
851 425 markom
void immu_enabled () {
852
  setsprbits (SPR_UPR, SPR_UPR_IMP, tempL & 1);
853 572 simons
  config.immu.enabled = tempL;
854 425 markom
}
855 424 markom
 
856 425 markom
void dmmu_enabled () {
857
  setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1);
858 572 simons
  config.dmmu.enabled = tempL;
859 425 markom
}
860
 
861
void immu_nsets () {
862
  if (is_power2(tempL) && tempL <= 256)
863
    config.immu.nsets = tempL;
864
  else
865 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
866 425 markom
}
867
 
868
void dmmu_nsets () {
869
  if (is_power2(tempL) && tempL <= 256)
870
    config.dmmu.nsets = tempL;
871
  else
872 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
873 425 markom
}
874
 
875
void immu_nways () {
876
  if (tempL >= 1 && tempL <= 4)
877
    config.immu.nways = tempL;
878
  else
879
    ERROR("value 1, 2, 3 or 4 expected.");
880
}
881
 
882
void dmmu_nways () {
883
  if (tempL >= 1 && tempL <= 4)
884
    config.dmmu.nways = tempL;
885
  else
886
    ERROR("value 1, 2, 3 or 4 expected.");
887
}
888
 
889
void immu_pagesize () {
890
  if (is_power2(tempL))
891
    config.immu.pagesize = tempL;
892
  else
893 428 markom
    ERROR("value of power of two expected.");
894 425 markom
}
895
 
896
void dmmu_pagesize () {
897
  if (is_power2(tempL))
898
    config.dmmu.pagesize = tempL;
899
  else
900 428 markom
    ERROR("value of power of two expected.");
901 425 markom
}
902
 
903
void immu_entrysize () {
904
  if (is_power2(tempL))
905
    config.immu.entrysize = tempL;
906
  else
907 428 markom
    ERROR("value of power of two expected.");
908 425 markom
}
909
 
910
void dmmu_entrysize () {
911
  if (is_power2(tempL))
912
    config.dmmu.entrysize = tempL;
913
  else
914 428 markom
    ERROR("value of power of two expected.");
915 425 markom
}
916
 
917
void immu_ustates () {
918
  if (tempL >= 2 && tempL <= 4)
919
    config.immu.ustates = tempL;
920
  else
921
    ERROR("invalid USTATE.");
922
}
923
 
924
void dmmu_ustates () {
925
  if (tempL >= 2 && tempL <= 4)
926
    config.dmmu.ustates = tempL;
927
  else
928
    ERROR("invalid USTATE.");
929
}
930
 
931 428 markom
void ic_enabled () {
932 574 markom
  config.ic.enabled = tempL;
933 428 markom
  setsprbits (SPR_UPR, SPR_UPR_ICP, tempL & 1);
934
}
935
 
936
void ic_nsets () {
937
  if (is_power2(tempL) && tempL <= MAX_IC_SETS)
938
    config.ic.nsets = tempL;
939
  else {
940
    char tmp[200];
941
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_IC_SETS);
942
    ERROR(tmp);
943
  }
944
}
945
 
946
void ic_nways () {
947
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
948
    config.ic.nways = tempL;
949
  else
950
    ERROR("value 1, 2, 3 or 4 expected.");
951
}
952
 
953
void ic_blocksize () {
954
  if (is_power2(tempL))
955
    config.ic.blocksize = tempL;
956
  else
957
    ERROR("value of power of two expected.");
958
}
959
 
960
void ic_ustates () {
961
  if (tempL >= 2 && tempL <= 4)
962
    config.ic.ustates = tempL;
963
  else
964
    ERROR("invalid USTATE.");
965
}
966
 
967
void ic_tagtype () {
968
  if (strcmp (tempS, "none") == 0)
969
    config.ic.tagtype = CT_NONE;
970
  else if (strcmp (tempS, "physical") == 0)
971
    config.ic.tagtype = CT_PHYSICAL;
972
  else if (strcmp (tempS, "virtual") == 0)
973
    config.ic.tagtype = CT_VIRTUAL;
974
  else {
975
    char tmp[200];
976
    sprintf (tmp, "invalid cache type '%s'.\n", tempS);
977
    ERROR(tmp);
978
  }
979
}
980
 
981
void dc_enabled () {
982 574 markom
  config.dc.enabled = tempL;
983 428 markom
  setsprbits (SPR_UPR, SPR_UPR_DCP, tempL & 1);
984
}
985
 
986
void dc_nsets () {
987
  if (is_power2(tempL) && tempL <= MAX_DC_SETS)
988
    config.dc.nsets = tempL;
989
  else {
990
    char tmp[200];
991
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
992
    ERROR(tmp);
993
  }
994
}
995
 
996
void dc_nways () {
997
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
998
    config.dc.nways = tempL;
999
  else
1000
    ERROR("value 1, 2, 3 or 4 expected.");
1001
}
1002
 
1003
void dc_blocksize () {
1004
  if (is_power2(tempL))
1005
    config.dc.blocksize = tempL;
1006
  else
1007
    ERROR("value of power of two expected.");
1008
}
1009
 
1010
void dc_ustates () {
1011
  if (tempL >= 2 && tempL <= 4)
1012
    config.dc.ustates = tempL;
1013
  else
1014
    ERROR("invalid USTATE.");
1015
}
1016
 
1017
void dc_tagtype () {
1018
  if (strcmp (tempS, "none") == 0)
1019
    config.dc.tagtype = CT_NONE;
1020
  else if (strcmp (tempS, "physical") == 0)
1021
    config.dc.tagtype = CT_PHYSICAL;
1022
  else if (strcmp (tempS, "virtual") == 0)
1023
    config.dc.tagtype = CT_VIRTUAL;
1024
  else {
1025
    char tmp[200];
1026
    sprintf (tmp, "invalid cache type '%s'.\n", tempS);
1027
    ERROR(tmp);
1028
  }
1029
}
1030
 
1031 424 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
1032
   The syntax of script file is:
1033
   param = value
1034
   section x
1035
     data
1036
     param = value
1037
   end
1038
 
1039
   Example:
1040
   section mc
1041
     memory_table_file = sim.mem
1042
     enable = 1
1043
     POC = 0x47892344
1044
   end
1045
 
1046
 */
1047
 
1048
void read_script_file (char *filename)
1049
{
1050
  FILE *f;
1051
  unsigned long memory_needed = 0;
1052
  char *home = getenv("HOME");
1053
  char ctmp[STR_SIZE];
1054
  int local = 1;
1055
  section = 0;
1056
 
1057
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
1058
  if ((f = fopen (filename, "rt")) != NULL
1059
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
1060
    unsigned long start, length;
1061
    char type[STR_SIZE];
1062
    int nparam;
1063
    int rd, wd;
1064 549 markom
    if (config.sim.verbose && !runtime.sim.output_cfg)
1065 428 markom
      printf ("Reading script file from '%s'...\n", local ? filename : ctmp);
1066 549 markom
    strcpy (runtime.sim.script_fn, local ? filename : ctmp);
1067
 
1068 424 markom
    while (!feof(f)) {
1069
      char param[STR_SIZE];
1070
      if (fscanf(f, "%s ", &param) != 1) break;
1071
      /* Is this a sections? */
1072
      if (strcmp (param, "section") == 0) {
1073
        int i;
1074
        section = 0;
1075
        if (fscanf (f, "%s\n", &param) != 1) {
1076
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
1077
          exit (1);
1078
        }
1079
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1080
          if (strcmp (sections[i].name, param) == 0) {
1081
            section = i;
1082
            break;
1083
          }
1084
        if (!section) {
1085
          char tmp[200];
1086
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
1087
          WARNING(tmp);
1088
          /* just skip section */
1089
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
1090
        }
1091
      } else if (strcmp (param, "end") == 0) {
1092
        section = 0;
1093
      } else if (strncmp (param, "/*", 2) == 0) {
1094
        char c0 = 0, c1 = 0;
1095
        while (c0 != '*' || c1 != '/') {
1096
          c0 = c1;
1097
          c1 = fgetc(f);
1098
          if (feof(f)) {
1099
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
1100
            exit (1);
1101
          }
1102
        }
1103
      } else {
1104
        int i, found = -1;
1105
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1106
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
1107
            found = i;
1108
            break;
1109
          }
1110
        if (found < 0) {
1111
          char tmp[200];
1112
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
1113
          WARNING(tmp);
1114
          while (fgetc(f) != '\n' || feof(f));
1115
          continue;
1116
        }
1117
 
1118
        /* Parse parameter value */
1119
        {
1120
          if (config_params[found].type[0])
1121
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
1122
              exit (1);
1123
        }
1124
        if (config_params[found].func)
1125
          config_params[found].func();
1126
      }
1127
    }
1128
    fclose (f);
1129
    runtime.sim.script_file_specified = 1;
1130
  } else
1131
    if (config.sim.verbose)
1132
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
1133
}
1134
 
1135
/* Utility for execution of set sim command.  */
1136
static int set_config (char *s)
1137
{
1138
  char *sec, *item, *params;
1139
  int noparams = 0, i, noitem = 0;
1140 434 markom
  while (*s && isspace (*s)) s++;
1141 424 markom
  sec = s;
1142
  printf ("s:%s\n", s);
1143
  while (*s && *s != ' ') s++;
1144
  if (!(*s)) noitem = 1;
1145
  *s = 0;
1146
  printf ("sec:%s\n", sec);
1147
  section = 0;
1148
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1149
    if (strcmp (sections[i].name, sec) == 0) {
1150
      section = i;
1151
      break;
1152
    }
1153
 
1154
  if (!section) return 1;
1155
  if (noitem) return 2;
1156
 
1157
  item = ++s;
1158
 
1159
  while (*s && *s != ' ') s++;
1160
  if (!(*s)) {
1161
    noparams = 1;
1162
    params = "";
1163
  } else
1164
    params = s + 1;
1165
  *s = 0;
1166
  printf ("item:%s\n", item);
1167
  printf ("params:%s\n", params);
1168
  {
1169
    int i, found = -1;
1170
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1171
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
1172
        found = i;
1173
        break;
1174
      }
1175
    if (found < 0) return 2;
1176
 
1177
    /* Parse parameter value */
1178
    if (config_params[found].type[0])
1179
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
1180
        return 3;
1181
    if (config_params[found].func)
1182
      config_params[found].func();
1183
  }
1184
  return 0;
1185
}
1186
 
1187
/* Executes set sim command, displays error.  */
1188
void set_config_command(char *s)
1189
{
1190
  int i;
1191
  switch (set_config (s)) {
1192
    case 1:
1193
      printf ("Invalid or missing section name.  One of valid sections must be specified:\n");
1194
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1195
        printf ("%s ", sections[i].name);
1196
      printf ("\n");
1197
      break;
1198
    case 2:
1199
      printf ("Invalid or missing item name.  One of valid items must be specified:\n");
1200
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1201
        if (config_params[i].section == section)
1202
          printf ("%s ", config_params[i].name);
1203
      printf ("\n");
1204
      break;
1205
    case 3:
1206
      printf ("Invalid parameters specified.\n");
1207
      break;
1208
  }
1209
}
1210 551 markom
#endif /* !FAST_SIM */
1211 549 markom
 
1212
/* Outputs C structure of current config to file */
1213
void output_cfg (FILE *f)
1214
{
1215
  int i, comma;
1216
  fprintf (f, "/* This file was automatically generated by or1ksim,\n"
1217
              "   using --output-cfg switch (cfg file '%s'). */\n"
1218
  "const static struct config config = {\n", runtime.sim.script_fn);
1219
 
1220 599 simons
  fprintf (f, "  tick:{enabled:%i},\n", config.tick.enabled);
1221 549 markom
  fprintf (f, "  nuarts:%i, uarts:{", config.nuarts);
1222
  comma = 0;
1223
  for (i = 0; i < config.nuarts; i++) {
1224
    fprintf (f, "%s\n    {rxfile:\"%s\", txfile:\"%s\", jitter:%i, baseaddr:0x%08x, irq:%i, vapi_id:0x%08x, uart16550:%i}",
1225
      comma ? "," :"", config.uarts[i].rxfile, config.uarts[i].txfile, config.uarts[i].jitter, config.uarts[i].baseaddr, config.uarts[i].irq,
1226
      config.uarts[i].vapi_id, config.uarts[i].uart16550);
1227
    comma = 1;
1228
  }
1229
  fprintf (f, "},\n");
1230
 
1231
  fprintf (f, "  ndmas:%i, dmas:{", config.ndmas);
1232
  comma = 0;
1233
  for (i = 0; i < config.ndmas; i++) {
1234
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, vapi_id:0x%08x}",
1235
      comma ? "," :"", config.dmas[i].baseaddr, config.dmas[i].irq, config.dmas[i].vapi_id);
1236
    comma = 1;
1237
  }
1238
  fprintf (f, "},\n");
1239
 
1240
  fprintf (f, "  nethernets:%i, ethernets:{", config.nethernets);
1241
  comma = 0;
1242
  for (i = 0; i < config.nethernets; i++) {
1243
    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}",
1244
      comma ? "," :"", config.ethernets[i].baseaddr, config.ethernets[i].dma, config.ethernets[i].tx_channel, config.ethernets[i].rx_channel,
1245
      config.ethernets[i].rxfile, config.ethernets[i].txfile, config.ethernets[i].vapi_id);
1246
    comma = 1;
1247
  }
1248
  fprintf (f, "},\n");
1249
 
1250
  fprintf (f, "  ngpios:%i, gpios:{", config.ngpios);
1251
  comma = 0;
1252
  for (i = 0; i < config.ngpios; i++) {
1253
    fprintf (f, "%s\n    {baseaddr:0x%08x, irq:%i, base_vapi_id:0x%08x}",
1254
      comma ? "," :"", config.gpios[i].baseaddr, config.gpios[i].irq, config.gpios[i].base_vapi_id);
1255
    comma = 1;
1256
  }
1257
  fprintf (f, "},\n");
1258
 
1259
  fprintf (f, "  mc:{enabled:%i, baseaddr:%i, POC:%i},\n", config.mc.enabled, config.mc.baseaddr, config.mc.POC);
1260
  fprintf (f, "  memory:{pattern:%i, random_seed:%i, type:%s, nmemories:%i, table:{", config.memory.pattern, config.memory.random_seed,
1261
    config.memory.type == MT_UNKNOWN ? "MT_UNKNOWN" : config.memory.type == MT_PATTERN ? "MT_PATTERN" : "MT_RANDOM", config.memory.nmemories);
1262
  comma = 0;
1263
  for (i = 0; i < config.memory.nmemories; i++) {
1264
    fprintf (f, "%s\n    {ce:%i, baseaddr:0x%08x, size:0x%08x, name:\"%s\", log:\"%s\", delayr:%i, delayw:%i}",
1265
      comma ? "," :"", config.memory.table[i].ce, config.memory.table[i].baseaddr, config.memory.table[i].size, config.memory.table[i].name,
1266
      config.memory.table[i].log, config.memory.table[i].delayr, config.memory.table[i].delayw);
1267
    comma = 1;
1268
  }
1269
  fprintf (f, "}},\n");
1270
 
1271
  fprintf (f, "  immu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1272
    config.immu.enabled, config.immu.nways, config.immu.nsets, config.immu.pagesize, config.immu.entrysize, config.immu.ustates,
1273
    config.immu.missdelay, config.immu.hitdelay);
1274
 
1275
  fprintf (f, "  dmmu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1276
    config.dmmu.enabled, config.dmmu.nways, config.dmmu.nsets, config.dmmu.pagesize, config.dmmu.entrysize, config.dmmu.ustates,
1277
    config.dmmu.missdelay, config.dmmu.hitdelay);
1278
 
1279
  fprintf (f, "  ic:{enabled:%i, tagtype:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
1280
    config.ic.enabled, config.ic.tagtype, config.ic.nways, config.ic.nsets, config.ic.blocksize, config.ic.ustates,
1281
    config.ic.missdelay, config.ic.hitdelay);
1282
 
1283 557 markom
  fprintf (f, "  dc:{enabled:%i, tagtype:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i,\n"
1284
    "    load_missdelay:%i, load_hitdelay:%i, store_missdelay:%i, store_hitdelay:%i},\n",
1285 549 markom
    config.dc.enabled, config.dc.tagtype, config.dc.nways, config.dc.nsets, config.dc.blocksize, config.dc.ustates,
1286
    config.dc.load_missdelay, config.dc.load_hitdelay, config.dc.store_missdelay, config.dc.store_hitdelay);
1287
 
1288
  fprintf (f, "  bpb:{enabled:%i, sbp_bnf_fwd:%i, sbp_bf_fwd:%i, btic:%i, missdelay:%i, hitdelay:%i},\n",
1289
    config.bpb.enabled, config.bpb.sbp_bnf_fwd, config.bpb.sbp_bf_fwd, config.bpb.btic, config.bpb.missdelay, config.bpb.hitdelay);
1290
 
1291 557 markom
  fprintf (f, "  cpu:{upr:0x%08x, ver:0x%04x, rev:0x%04x, superscalar:%i, hazards:%i, dependstats:%i,\n"
1292
    "    raw_range:%i, sr:0x%08x},\n",
1293
    config.cpu.upr, config.cpu.ver, config.cpu.rev, config.cpu.superscalar, config.cpu.hazards, config.cpu.dependstats,
1294
    config.cpu.raw_range, config.cpu.sr);
1295 549 markom
 
1296 551 markom
  fprintf (f, "  sim:{debug:%i, verbose:%i, profile:%i, prof_fn:\"%s\", mprofile:%i, mprof_fn:\"%s\",\n",
1297
    config.sim.debug, config.sim.verbose, config.sim.profile, config.sim.prof_fn, config.sim.mprofile, config.sim.mprof_fn);
1298 549 markom
 
1299
  fprintf (f, "    history:%i, exe_log:%i, exe_log_fn:\"%s\", clkcycle_ps:%i},\n",
1300
    config.sim.history, config.sim.exe_log, config.sim.exe_log_fn, config.sim.clkcycle_ps);
1301
 
1302
  fprintf (f, "  debug:{enabled:%i, gdb_enabled:%i, server_port:%i, vapi_id:0x%08x},\n",
1303
    config.debug.enabled, config.debug.gdb_enabled, config.debug.server_port, config.debug.vapi_id);
1304
 
1305 557 markom
  fprintf (f, "  vapi:{enabled:%i, server_port:%i, log_enabled:%i, hide_device_id:%i, vapi_fn:\"%s\"},\n",
1306 549 markom
    config.vapi.enabled, config.vapi.server_port, config.vapi.log_enabled, config.vapi.hide_device_id, config.vapi.vapi_fn);
1307 557 markom
 
1308
  fprintf (f, "  pm:{enabled:%i}\n",
1309
    config.pm.enabled);
1310 549 markom
 
1311
  fprintf (f, "};\n");
1312
}

powered by: WebSVN 2.1.0

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