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 624

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

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

powered by: WebSVN 2.1.0

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