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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [sim-config.c] - Blame information for rev 549

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

powered by: WebSVN 2.1.0

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