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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [sim-config.c] - Blame information for rev 631

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

powered by: WebSVN 2.1.0

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