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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_69/] [or1ksim/] [sim-config.c] - Blame information for rev 551

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

powered by: WebSVN 2.1.0

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