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 556

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

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

powered by: WebSVN 2.1.0

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