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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [sim-config.c] - Blame information for rev 557

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

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

powered by: WebSVN 2.1.0

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