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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [or1ksim/] [sim-config.c] - Blame information for rev 1358

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

Line No. Rev Author Line
1 1358 nogj
/* sim-config.c -- Simulator configuration
2 645 markom
   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 805 markom
#include <limits.h>
24 1308 phoenix
#include <string.h>
25
#include <ctype.h>
26
 
27 1350 nogj
#include "config.h"
28
 
29
#ifdef HAVE_INTTYPES_H
30
#include <inttypes.h>
31
#endif
32
 
33
#include "port.h"
34
#include "arch.h"
35 645 markom
#include "sim-config.h"
36
#include "abstract.h"
37
#include "sprs.h"
38
#include "spr_defs.h"
39
#include "pic.h"
40 1344 nogj
#include "opcode/or32.h"
41 645 markom
#include "stats.h"
42
#include "icache_model.h"
43
#include "dcache_model.h"
44
 
45
#include "profiler.h"
46
#include "mprofiler.h"
47 897 markom
#include "cuc.h"
48 645 markom
 
49 1358 nogj
#include "debug.h"
50
 
51
#define WARNING(s) fprintf (stderr, "WARNING: config.%s: %s\n", cur_section->name, (s))
52 645 markom
#define MERROR(s) {fprintf (stderr, "ERROR: %s\n", s); if (runtime.sim.init) exit (1);}
53
 
54
#if !FAST_SIM
55
struct config config;
56
#endif
57
struct runtime runtime;
58
 
59 1358 nogj
struct config_section *cur_section;
60 645 markom
 
61 1358 nogj
struct config_section *sections = NULL;
62
 
63 645 markom
void init_defconfig()
64
{
65
  int i;
66
 
67
#if !FAST_SIM
68
  memset(&config, 0, sizeof(config));
69
  /* Sim */
70
  config.sim.exe_log = 0;
71 672 markom
  config.sim.exe_log_type = EXE_LOG_HARDWARE;
72
  config.sim.exe_log_start = 0;
73
  config.sim.exe_log_end = 0;
74
  config.sim.exe_log_marker = 0;
75 645 markom
  config.sim.spr_log = 0;
76
  strcpy (config.sim.exe_log_fn, "executed.log");
77
  strcpy (config.sim.spr_log_fn, "spr.log");
78 1098 markom
  config.sim.profile = 0;
79
  config.sim.mprofile = 0;
80 645 markom
 
81
  config.sim.debug = 0;
82
  config.sim.verbose = 1;
83
 
84
  strcpy (config.sim.prof_fn, "sim.profile");
85
  strcpy (config.sim.mprof_fn, "sim.mprofile");
86 823 ivang
  strcpy (config.sim.fstdout, "stdout.txt");
87 645 markom
  strcpy (runtime.sim.script_fn, "(default)");
88
  config.sim.clkcycle_ps = 4000; /* 4000 for 4ns (250MHz) */
89 805 markom
  if (config.sim.clkcycle_ps) config.sim.system_kfreq = (long)((1000000000.0 / (double)config.sim.clkcycle_ps));
90
  else config.sim.system_kfreq = INT_MAX;
91
  if (config.sim.system_kfreq <= 0) config.sim.system_kfreq = 1;
92 645 markom
 
93
  /* Memory */
94
  config.memory.type = MT_UNKNOWN;
95
  config.memory.pattern = 0;
96
  config.memory.random_seed = -1;  /* Generate new seed */
97
  for (i = 0; i < MAX_MEMORIES; i++)
98
    config.memory.table[i].ce = -1;     /* memory is disabled by default */
99
 
100
  /* IMMU & DMMU*/
101
  config.immu.enabled = 0;
102 856 markom
  config.immu.hitdelay = 1;
103
  config.immu.missdelay = 1;
104 645 markom
  config.dmmu.enabled = 0;
105 856 markom
  config.dmmu.hitdelay = 1;
106
  config.dmmu.missdelay = 1;
107 645 markom
 
108
  /* IC & DC */
109
  config.ic.enabled = 0;
110 856 markom
  config.ic.hitdelay = 1;
111
  config.ic.missdelay = 1;
112 645 markom
  config.ic.nways = 0;
113
  config.ic.nsets = 0;
114
  config.ic.ustates = 0;
115
  config.dc.enabled = 0;
116 856 markom
  config.dc.load_hitdelay = 2;
117
  config.dc.load_missdelay = 2;
118 645 markom
  config.dc.nways = 0;
119
  config.dc.nsets = 0;
120
  config.dc.ustates = 0;
121
  config.dc.store_hitdelay = 0;
122
  config.dc.store_missdelay = 0;
123 876 rherveille
 
124 645 markom
  /* Memory Controller */
125
  config.mc.enabled = 0;
126
 
127
  /* Uarts */
128
  config.nuarts = 0;
129
 
130
  /* DMAs */
131
  config.ndmas = 0;
132
 
133
  /* VGAs */
134
  config.nvgas = 0;
135
 
136
  /* Frame buffer */
137
  config.fb.enabled = 0;
138
 
139
  /* CPU */
140
  config.cpu.superscalar = 0;
141
  config.sim.history = 0;
142
  config.cpu.hazards = 0;
143
  config.cpu.dependstats = 0;
144
  config.cpu.sbuf_len = 0;
145
  config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP
146
                 | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP
147
                 | SPR_UPR_PMP | SPR_UPR_TTP;
148 912 lampret
  config.cpu.sr = 0x00008001;
149 645 markom
 
150
  /* Debug */
151
  config.debug.enabled = 0;
152
  config.debug.gdb_enabled = 0;
153
  config.debug.server_port = 0;
154
 
155
  /* VAPI */
156
  config.vapi.enabled = 0;
157
  strcpy (config.vapi.vapi_fn, "vapi.log");
158
 
159
  /* Ethernet */
160
  config.nethernets = 0;
161
 
162
  /* GPIO */
163
  config.ngpios = 0;
164
 
165
  /* PM */
166
  config.pm.enabled = 0;
167 897 markom
 
168
  /* CUC */
169
  strcpy (config.cuc.timings_fn, "virtex.tim");
170
  config.cuc.memory_order = MO_STRONG;
171
  config.cuc.calling_convention = 1;
172
  config.cuc.enable_bursts = 1;
173
  config.cuc.no_multicycle = 1;
174 970 simons
 
175
  /* Test */
176
  config.test.enabled = 0;
177
 
178 645 markom
#endif
179
 
180
  /* Configure runtime */
181
  memset(&runtime, 0, sizeof(runtime));
182
 
183
  /* Sim */
184
  runtime.sim.fexe_log = NULL;
185
  runtime.sim.fspr_log = NULL;
186
  runtime.sim.iprompt = 0;
187
  runtime.sim.fprof = NULL;
188
  runtime.sim.fmprof = NULL;
189
  runtime.sim.init = 1;
190 998 markom
  runtime.sim.fout = stdout;
191 645 markom
  runtime.sim.script_file_specified = 0;
192 883 markom
  runtime.simcmd.profile = 0;
193
  runtime.simcmd.mprofile = 0;
194 645 markom
 
195
  /* VAPI */
196
  runtime.vapi.vapi_file = NULL;
197
  runtime.vapi.enabled = 0;
198
}
199
 
200
int parse_args(int argc, char *argv[])
201
{
202
  argv++; argc--;
203
  while (argc) {
204 847 markom
    if (strcmp(*argv, "profiler") == 0) {
205
      exit (main_profiler (argc, argv));
206
    } else
207
    if (strcmp(*argv, "mprofiler") == 0) {
208
      exit (main_mprofiler (argc, argv));
209
    } else
210
    if (*argv[0] != '-') {
211 645 markom
      runtime.sim.filename = argv[0];
212
      argc--;
213
      argv++;
214
    } else
215
#if !FAST_SIM /* Constant cfg */
216
    if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
217
      argv++; argc--;
218
      if (argv[0]) {
219
        read_script_file(argv[0]);
220
        argv++; argc--;
221
      } else {
222
        fprintf(stderr, "Configure filename not specified!\n");
223
        return 1;
224
      }
225
    } else
226
#endif
227
    if (strcmp(*argv, "--nosrv") == 0) {  /* (CZ) */
228
      config.debug.gdb_enabled = 0;
229
      argv++; argc--;
230
    } else
231
    if (strcmp(*argv, "--srv") == 0) {  /* (CZ) */
232
      char *s;
233
      if(!--argc)
234
        return 1;
235
      config.debug.enabled = 1;
236 1205 phoenix
      config.debug.gdb_enabled = 1;
237 645 markom
      config.debug.server_port = strtol(*(++argv),&s,10);
238
      if(*s)
239
        return 1;
240
      argv++; argc--;
241
    } else
242
    if (strcmp(*argv, "-i") == 0) {
243
      runtime.sim.iprompt = 1;
244
      argv++; argc--;
245
    } else
246
    if (strcmp(*argv, "-v") == 0) {
247
      version();
248
      exit(0);
249
    } else
250
#if !FAST_SIM
251 883 markom
    if (strcmp(*argv, "--enable-profile") == 0) {
252
      runtime.simcmd.profile = 1;
253 645 markom
      argv++; argc--;
254
    } else
255 883 markom
    if (strcmp(*argv, "--enable-mprofile") == 0) {
256
      runtime.simcmd.mprofile = 1;
257 645 markom
      argv++; argc--;
258
    } else
259
#endif
260
    if (strcmp(*argv, "--output-cfg") == 0) {
261
      runtime.sim.output_cfg = 1;
262
      argv++; argc--;
263
    } else {
264
      fprintf(stderr, "Unknown option: %s\n", *argv);
265
      return 1;
266
    }
267
  }
268
 
269
  if (!argc)
270
    return 0;
271
 
272
  return 0;
273
}
274
 
275
void print_config()
276
{
277
  if (config.sim.verbose) {
278
    char temp[20];
279 997 markom
    PRINTF("Verbose on, ");
280 645 markom
    if (config.sim.debug)
281 997 markom
      PRINTF("simdebug on, ");
282 645 markom
    else
283 997 markom
      PRINTF("simdebug off, ");
284 645 markom
    if (runtime.sim.iprompt)
285 997 markom
      PRINTF("interactive prompt on\n");
286 645 markom
    else
287 997 markom
      PRINTF("interactive prompt off\n");
288 645 markom
 
289 997 markom
    PRINTF("Machine initialization...\n");
290 645 markom
    generate_time_pretty (temp, config.sim.clkcycle_ps);
291 997 markom
    PRINTF("Clock cycle: %s\n", temp);
292 645 markom
    if (testsprbits(SPR_UPR, SPR_UPR_DCP))
293 997 markom
      PRINTF("Data cache present.\n");
294 645 markom
    else
295 997 markom
      PRINTF("No data cache.\n");
296 645 markom
    if (testsprbits(SPR_UPR, SPR_UPR_ICP))
297 997 markom
      PRINTF("Insn cache tag present.\n");
298 645 markom
    else
299 997 markom
      PRINTF("No instruction cache.\n");
300 645 markom
    if (config.bpb.enabled)
301 997 markom
      PRINTF("BPB simulation on.\n");
302 645 markom
    else
303 997 markom
      PRINTF("BPB simulation off.\n");
304 645 markom
    if (config.bpb.btic)
305 997 markom
      PRINTF("BTIC simulation on.\n");
306 645 markom
    else
307 997 markom
      PRINTF("BTIC simulation off.\n");
308 645 markom
  }
309
}
310
 
311
#if !FAST_SIM
312 1358 nogj
struct config_param {
313
  char *name;
314
  enum param_t type;
315
  void (*func)(union param_val, void *dat);
316
  struct config_param *next;
317 645 markom
};
318
 
319 1358 nogj
/* FIXME: These will be removed */
320
int current_device = -1;
321
void change_device (union param_val val, void *dat) {
322
  current_device = val.int_val;
323
}
324 645 markom
 
325 1358 nogj
void end_device (union param_val val, void *dat) {
326
  current_device = -1;
327
}
328 645 markom
 
329 1358 nogj
void base_include (union param_val val, void *dat) {
330
  read_script_file (val.str_val);
331
  cur_section = NULL;
332
}
333 645 markom
 
334 1358 nogj
/*----------------------------------------------[ Simulator configuration ]---*/
335
void sim_debug (union param_val val, void *dat) {
336
  config.sim.debug = val.int_val;
337
}
338 645 markom
 
339 1358 nogj
void sim_verbose (union param_val val, void *dat) {
340
  config.sim.verbose = val.int_val;
341
}
342 645 markom
 
343 1358 nogj
void sim_profile (union param_val val, void *dat) {
344
  config.sim.profile = val.int_val;
345
}
346 645 markom
 
347 1358 nogj
void sim_prof_fn (union param_val val, void *dat) {
348
  strcpy(config.sim.prof_fn, val.str_val);
349
}
350 876 rherveille
 
351 1358 nogj
void sim_mprofile (union param_val val, void *dat) {
352
  config.sim.mprofile = val.int_val;
353 645 markom
}
354
 
355 1358 nogj
void sim_mprof_fn (union param_val val, void *dat) {
356
  strcpy(config.sim.mprof_fn, val.str_val);
357 645 markom
}
358
 
359 1358 nogj
void sim_history (union param_val val, void *dat) {
360
  config.sim.history = val.int_val;
361 645 markom
}
362
 
363 1358 nogj
void sim_exe_log (union param_val val, void *dat) {
364
  config.sim.exe_log = val.int_val;
365 645 markom
}
366
 
367 1358 nogj
void sim_exe_log_type (union param_val val, void *dat) {
368
  if (strcmp (val.str_val, "default") == 0)
369 672 markom
    config.sim.exe_log_type = EXE_LOG_HARDWARE;
370 1358 nogj
  else if (strcmp (val.str_val, "hardware") == 0)
371 672 markom
    config.sim.exe_log_type = EXE_LOG_HARDWARE;
372 1358 nogj
  else if (strcmp (val.str_val, "simple") == 0)
373 675 markom
    config.sim.exe_log_type = EXE_LOG_SIMPLE;
374 1358 nogj
  else if (strcmp (val.str_val, "software") == 0) {
375 672 markom
    config.sim.exe_log_type = EXE_LOG_SOFTWARE;
376
  } else {
377
    char tmp[200];
378 1358 nogj
    sprintf (tmp, "invalid execute log type '%s'.\n", val.str_val);
379
    CONFIG_ERROR(tmp);
380 672 markom
  }
381
}
382
 
383 1358 nogj
void sim_exe_log_start (union param_val val, void *dat) {
384
  config.sim.exe_log_start = val.int_val;
385 645 markom
}
386
 
387 1358 nogj
void sim_exe_log_end (union param_val val, void *dat) {
388
  config.sim.exe_log_end = val.int_val;
389 645 markom
}
390
 
391 1358 nogj
void sim_exe_log_marker (union param_val val, void *dat) {
392
  config.sim.exe_log_marker = val.int_val;
393 645 markom
}
394
 
395 1358 nogj
void sim_exe_log_fn (union param_val val, void *dat) {
396
  strcpy(config.sim.exe_log_fn, val.str_val);
397 645 markom
}
398
 
399 1358 nogj
void sim_clkcycle (union param_val val, void *dat) {
400
  int len = strlen (val.str_val);
401
  int pos = len - 1;
402
  long time;
403
  if (len < 2) goto err;
404
  if (val.str_val[pos--] != 's') goto err;
405
  switch (val.str_val[pos--]) {
406
    case 'p': time = 1; break;
407
    case 'n': time = 1000; break;
408
    case 'u': time = 1000000; break;
409
    case 'm': time = 1000000000; break;
410
  default:
411
    goto err;
412
  }
413
  val.str_val[pos + 1] = 0;
414
  config.sim.clkcycle_ps = time * atol (val.str_val);
415
  return;
416
err:
417
  CONFIG_ERROR("invalid time format.");
418 645 markom
}
419
 
420 1358 nogj
void sim_stdout (union param_val val, void *dat) {
421
  strcpy(config.sim.fstdout, val.str_val);
422 645 markom
}
423
 
424 1358 nogj
void sim_spr_log (union param_val val, void *dat) {
425
  config.sim.spr_log = val.int_val;
426 645 markom
}
427
 
428 1358 nogj
void sim_spr_log_fn (union param_val val, void *dat) {
429
  strcpy(config.sim.spr_log_fn, val.str_val);
430 645 markom
}
431
 
432 1358 nogj
void reg_sim_sec (void) {
433
  struct config_section *sec = reg_config_sec("sim", NULL, NULL);
434 645 markom
 
435 1358 nogj
  reg_config_param(sec, "debug", paramt_int, sim_debug);
436
  reg_config_param(sec, "verbose", paramt_int, sim_verbose);
437
  reg_config_param(sec, "profile", paramt_int, sim_profile);
438
  reg_config_param(sec, "prof_fn", paramt_str, sim_prof_fn);
439
  reg_config_param(sec, "mprofile", paramt_int, sim_mprofile);
440
  reg_config_param(sec, "mprof_fn", paramt_str, sim_mprof_fn);
441
  reg_config_param(sec, "history", paramt_int, sim_history);
442
  reg_config_param(sec, "exe_log", paramt_int, sim_exe_log);
443
  reg_config_param(sec, "exe_log_type", paramt_word, sim_exe_log_type);
444
  reg_config_param(sec, "exe_log_start", paramt_int, sim_exe_log_start);
445
  reg_config_param(sec, "exe_log_end", paramt_int, sim_exe_log_end);
446
  reg_config_param(sec, "exe_log_marker", paramt_int, sim_exe_log_marker);
447
  reg_config_param(sec, "exe_log_fn", paramt_str, sim_exe_log_fn);
448
  reg_config_param(sec, "spr_log", paramt_int, sim_spr_log);
449
  reg_config_param(sec, "spr_log_fn", paramt_str, sim_spr_log_fn);
450
  reg_config_param(sec, "clkcycle", paramt_word, sim_clkcycle);
451
  reg_config_param(sec, "stdout", paramt_str, sim_stdout);
452 645 markom
}
453
 
454 1358 nogj
/*-------------------------------------------------[ Memory configuration ]---*/
455
void memory_random_seed(union param_val val, void *dat) {
456
  config.memory.random_seed = val.int_val;
457 645 markom
}
458
 
459 1358 nogj
void memory_pattern(union param_val val, void *dat) {
460
  config.memory.pattern = val.int_val;
461 645 markom
}
462
 
463 1358 nogj
void memory_nmemories (union param_val val, void *dat) {
464
  if (val.int_val >= 0 && val.int_val < MAX_MEMORIES)
465
    config.memory.nmemories = val.int_val;
466 645 markom
  else
467 1358 nogj
    CONFIG_ERROR("invalid number of devices.");
468 645 markom
}
469
 
470 1358 nogj
void memory_type (union param_val val, void *dat) {
471
  if (strcmp (val.str_val, "unknown") == 0)
472 645 markom
    config.memory.type = MT_UNKNOWN;
473 1358 nogj
  else if (strcmp (val.str_val, "random") == 0)
474 645 markom
    config.memory.type = MT_RANDOM;
475 1358 nogj
  else if (strcmp (val.str_val, "pattern") == 0)
476 645 markom
    config.memory.type = MT_PATTERN;
477 1358 nogj
  else if (strcmp (val.str_val, "zero") == 0) {
478 645 markom
    config.memory.type = MT_PATTERN;
479
    config.memory.pattern = 0;
480
  } else {
481
    char tmp[200];
482 1358 nogj
    sprintf (tmp, "invalid memory type '%s'.\n", val.str_val);
483
    CONFIG_ERROR(tmp);
484 645 markom
  }
485
}
486
 
487 1358 nogj
void memory_ce (union param_val val, void *dat) {
488 645 markom
  if (current_device >= 0 && current_device < config.memory.nmemories)
489 1358 nogj
    config.memory.table[current_device].ce = val.int_val;
490 645 markom
  else
491 1358 nogj
    CONFIG_ERROR("invalid device number.");
492 645 markom
}
493
 
494 1358 nogj
void memory_baseaddr (union param_val val, void *dat) {
495 645 markom
  if (current_device >= 0 && current_device < config.memory.nmemories)
496 1358 nogj
    config.memory.table[current_device].baseaddr = val.addr_val;
497 645 markom
  else
498 1358 nogj
    CONFIG_ERROR("invalid device number.");
499 645 markom
}
500
 
501 1358 nogj
void memory_size (union param_val val, void *dat) {
502 645 markom
  if (current_device >= 0 && current_device < config.memory.nmemories)
503 1358 nogj
    config.memory.table[current_device].size = val.int_val;
504 645 markom
  else
505 1358 nogj
    CONFIG_ERROR("invalid device number.");
506 645 markom
}
507
 
508 1358 nogj
void memory_name (union param_val val, void *dat) {
509 645 markom
  if (current_device >= 0 && current_device < config.memory.nmemories)
510 1358 nogj
    strcpy (config.memory.table[current_device].name, val.str_val);
511 645 markom
  else
512 1358 nogj
    CONFIG_ERROR("invalid device number.");
513 645 markom
}
514
 
515 1358 nogj
void memory_log (union param_val val, void *dat) {
516 645 markom
  if (current_device >= 0 && current_device < config.memory.nmemories)
517 1358 nogj
    strcpy (config.memory.table[current_device].log, val.str_val);
518 645 markom
  else
519 1358 nogj
    CONFIG_ERROR("invalid device number.");
520 645 markom
}
521
 
522 1358 nogj
void memory_delayr (union param_val val, void *dat) {
523 645 markom
  if (current_device >= 0 && current_device < config.memory.nmemories)
524 1358 nogj
    config.memory.table[current_device].delayr = val.int_val;
525 645 markom
  else
526 1358 nogj
    CONFIG_ERROR("invalid device number.");
527 645 markom
}
528
 
529 1358 nogj
void memory_delayw (union param_val val, void *dat) {
530 645 markom
  if (current_device >= 0 && current_device < config.memory.nmemories)
531 1358 nogj
    config.memory.table[current_device].delayw = val.int_val;
532 645 markom
  else
533 1358 nogj
    CONFIG_ERROR("invalid device number.");
534 645 markom
}
535
 
536 1358 nogj
void reg_memory_sec(void) {
537
  struct config_section *sec = reg_config_sec("memory", NULL, NULL);
538 645 markom
 
539 1358 nogj
  reg_config_param(sec, "random_seed", paramt_int, memory_random_seed);
540
  reg_config_param(sec, "pattern", paramt_int, memory_pattern);
541
  reg_config_param(sec, "type", paramt_word, memory_type);
542
  reg_config_param(sec, "nmemories", paramt_int, memory_nmemories);
543
  reg_config_param(sec, "device", paramt_int, change_device);
544
  reg_config_param(sec, "enddevice", paramt_none, end_device);
545
  reg_config_param(sec, "ce", paramt_int, memory_ce);
546
  reg_config_param(sec, "baseaddr", paramt_addr, memory_baseaddr);
547
  reg_config_param(sec, "size", paramt_int, memory_size);
548
  reg_config_param(sec, "name", paramt_str, memory_name);
549
  reg_config_param(sec, "log", paramt_str, memory_log);
550
  reg_config_param(sec, "delayr", paramt_int, memory_delayr);
551
  reg_config_param(sec, "delayw", paramt_int, memory_delayw);
552 645 markom
}
553
 
554 1358 nogj
/*----------------------------------------------------[ CPU configuration ]---*/
555
void cpu_ver (union param_val val, void *dat) {
556
  config.cpu.ver = val.int_val;
557 645 markom
}
558
 
559 1358 nogj
void cpu_rev (union param_val val, void *dat) {
560
  config.cpu.rev = val.int_val;
561 645 markom
}
562
 
563 1358 nogj
void cpu_upr (union param_val val, void *dat) {
564
  config.cpu.upr = val.int_val;
565 725 ivang
}
566
 
567 1358 nogj
void cpu_sr (union param_val val, void *dat) {
568
  config.cpu.sr = val.int_val;
569 645 markom
}
570
 
571 1358 nogj
void cpu_hazards (union param_val val, void *dat) {
572
  config.cpu.hazards = val.int_val;
573 645 markom
}
574
 
575 1358 nogj
void cpu_superscalar (union param_val val, void *dat) {
576
  config.cpu.superscalar = val.int_val;
577 645 markom
}
578
 
579 1358 nogj
void cpu_dependstats (union param_val val, void *dat) {
580
  config.cpu.dependstats = val.int_val;
581 645 markom
}
582
 
583 1358 nogj
void cpu_sbuf_len (union param_val val, void *dat) {
584
  if (val.int_val >= MAX_SBUF_LEN) {
585
    config.cpu.sbuf_len = MAX_SBUF_LEN - 1;
586
    WARNING("sbuf_len too large; truncated.");
587
  } else if (val.int_val < 0) {
588
    config.cpu.sbuf_len = 0;
589
    WARNING("sbuf_len negative; disabled.");
590
  } else
591
    config.cpu.sbuf_len = val.int_val;
592 723 ivang
}
593
 
594 1358 nogj
void reg_cpu_sec(void)
595
{
596
  struct config_section *sec = reg_config_sec("cpu", NULL, NULL);
597 723 ivang
 
598 1358 nogj
  reg_config_param(sec, "ver", paramt_int, cpu_ver);
599
  reg_config_param(sec, "rev", paramt_int, cpu_rev);
600
  reg_config_param(sec, "upr", paramt_int, cpu_upr);
601
  reg_config_param(sec, "sr", paramt_int, cpu_sr);
602
  reg_config_param(sec, "hazards", paramt_int, cpu_hazards);
603
  reg_config_param(sec, "superscalar", paramt_int, cpu_superscalar);
604
  reg_config_param(sec, "dependstats", paramt_int, cpu_dependstats);
605
  reg_config_param(sec, "sbuf_len", paramt_int, cpu_sbuf_len);
606 645 markom
}
607
 
608
int is_power2 (int x) {
609
  while (!(x & 1))
610
    x >>= 1;
611
  return x == 1;
612
}
613
 
614 1358 nogj
void reg_config_secs(void)
615
{
616
  reg_config_param(reg_config_sec("base", NULL, NULL), "include", paramt_str,
617
                   base_include);
618 645 markom
 
619 1358 nogj
  reg_sim_sec();
620
  reg_cpu_sec();
621
  reg_memory_sec();
622
  reg_mc_sec();
623
  reg_uart_sec();
624
  reg_dma_sec();
625
  reg_debug_sec();
626
  reg_vapi_sec();
627
  reg_ethernet_sec();
628
  reg_immu_sec();
629
  reg_dmmu_sec();
630
  reg_ic_sec();
631
  reg_dc_sec();
632
  reg_gpio_sec();
633
  reg_bpb_sec();
634
  reg_pm_sec();
635
  reg_vga_sec();
636
  reg_fb_sec();
637
  reg_kbd_sec();
638
  reg_ata_sec();
639
  reg_cuc_sec();
640
  reg_test_sec();
641 645 markom
}
642
 
643 1358 nogj
void reg_config_param(struct config_section *sec, const char *param,
644
                      enum param_t type,
645
                      void (*param_cb)(union param_val, void *))
646
{
647
  struct config_param *new = malloc(sizeof(struct config_param));
648 645 markom
 
649 1358 nogj
  if(!new) {
650
    fprintf(stderr, "Out-of-memory\n");
651
    exit(1);
652
  }
653 645 markom
 
654 1358 nogj
  if(!(new->name = strdup(param))) {
655
    fprintf(stderr, "Out-of-memory\n");
656
    exit(1);
657
  }
658 645 markom
 
659 1358 nogj
  new->func = param_cb;
660
  new->type = type;
661 645 markom
 
662 1358 nogj
  new->next = sec->params;
663
  sec->params = new;
664 645 markom
}
665
 
666 1358 nogj
struct config_section *reg_config_sec(const char *section,
667
                                      void *(*sec_start)(void),
668
                                      void (*sec_end)(void *))
669
{
670
  struct config_section *new = malloc(sizeof(struct config_section));
671 645 markom
 
672 1358 nogj
  if(!new) {
673
    fprintf(stderr, "Out-of-memory\n");
674
    exit(1);
675
  }
676 645 markom
 
677 1358 nogj
  if(!(new->name = strdup(section))) {
678
    fprintf(stderr, "Out-of-memory\n");
679
    exit(1);
680 645 markom
  }
681
 
682 1358 nogj
  new->next = sections;
683
  new->sec_start = sec_start;
684
  new->sec_end = sec_end;
685
  new->params = NULL;
686 645 markom
 
687 1358 nogj
  sections = new;
688 645 markom
 
689 1358 nogj
  return new;
690 645 markom
}
691
 
692 1358 nogj
static void switch_param(char *param, struct config_param *cur_param)
693
{
694
  char *end_p;
695
  union param_val val;
696 645 markom
 
697 1358 nogj
    /* Skip over an = sign if it exists */
698
  if(*param == '=') {
699
    param++;
700
    while(*param && isspace(*param)) param++;
701 645 markom
  }
702
 
703 1358 nogj
  switch (cur_param->type) {
704
  case paramt_int:
705
    val.int_val = strtol(param, NULL, 0);
706
  case paramt_addr:
707
    val.addr_val = strtoul(param, NULL, 0);
708
    break;
709
  case paramt_str:
710
    if(*param != '"') {
711
      CONFIG_ERROR("String value expected\n");
712
      return;
713
    }
714 645 markom
 
715 1358 nogj
    param++;
716
    end_p = param;
717
    while(*end_p && (*end_p != '"')) end_p++;
718
    *end_p = '\0';
719
    val.str_val = param;
720
    break;
721
  case paramt_word:
722
    end_p = param;
723
    while(*end_p && !isspace(*end_p)) end_p++;
724
    *end_p = '\0';
725
    val.str_val = param;
726
    break;
727
  case paramt_none:
728
    break;
729
  }
730 645 markom
 
731 1358 nogj
  cur_param->func(val, cur_section->dat);
732 645 markom
}
733
 
734
/* Read environment from a script file. Does not fail - assumes default configuration instead.
735
   The syntax of script file is:
736
   param = value
737
   section x
738
     data
739
     param = value
740
   end
741
 
742
   Example:
743
   section mc
744
     memory_table_file = sim.mem
745
     enable = 1
746
     POC = 0x47892344
747
   end
748
 
749
 */
750
 
751
void read_script_file (char *filename)
752
{
753
  FILE *f;
754
  char *home = getenv("HOME");
755
  char ctmp[STR_SIZE];
756
  int local = 1;
757 1358 nogj
  cur_section = NULL;
758 645 markom
 
759
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
760
  if ((f = fopen (filename, "rt")) != NULL
761
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
762
    if (config.sim.verbose && !runtime.sim.output_cfg)
763 997 markom
      PRINTF ("Reading script file from '%s'...\n", local ? filename : ctmp);
764 645 markom
    strcpy (runtime.sim.script_fn, local ? filename : ctmp);
765
 
766
    while (!feof(f)) {
767
      char param[STR_SIZE];
768 1308 phoenix
      if (fscanf(f, "%s ", param) != 1) break;
769 1358 nogj
      /* Is this a section? */
770 645 markom
      if (strcmp (param, "section") == 0) {
771 1358 nogj
        struct config_section *cur;
772
        cur_section = NULL;
773 1308 phoenix
        if (fscanf (f, "%s\n", param) != 1) {
774 645 markom
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
775
          exit (1);
776
        }
777 1358 nogj
        for (cur = sections; cur; cur = cur->next)
778
          if (strcmp (cur->name, param) == 0) {
779
            cur_section = cur;
780 645 markom
            break;
781
          }
782 1358 nogj
        if (!cur) {
783
          fprintf (stderr, "WARNING: config: Unknown section: %s; ignoring.", param);
784 645 markom
          /* just skip section */
785 1308 phoenix
          while (fscanf (f, "%s\n", param) != 1 && strcmp (param, "end"));
786 1358 nogj
        } else {
787
          cur->dat = NULL;
788
          if (cur->sec_start)
789
            cur->dat = cur->sec_start();
790 645 markom
        }
791
      } else if (strcmp (param, "end") == 0) {
792 1358 nogj
        if(cur_section->sec_end)
793
          cur_section->sec_end(cur_section->dat);
794
        cur_section = NULL;
795 645 markom
      } else if (strncmp (param, "/*", 2) == 0) {
796
        char c0 = 0, c1 = 0;
797
        while (c0 != '*' || c1 != '/') {
798
          c0 = c1;
799
          c1 = fgetc(f);
800
          if (feof(f)) {
801
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
802
            exit (1);
803
          }
804
        }
805
      } else {
806 1358 nogj
        struct config_param *cur_param;
807
        char *cur_p;
808
        for (cur_param = cur_section->params; cur_param; cur_param = cur_param->next)
809
          if (strcmp (cur_param->name, param) == 0) {
810 645 markom
            break;
811
          }
812 1358 nogj
        if (!cur_param) {
813 645 markom
          char tmp[200];
814
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
815
          WARNING(tmp);
816
          while (fgetc(f) != '\n' || feof(f));
817
          continue;
818
        }
819
 
820 1358 nogj
        if(cur_param->type == paramt_none)
821
          continue;
822
 
823 645 markom
        /* Parse parameter value */
824 1358 nogj
        cur_p = fgets (param, STR_SIZE, f);
825
 
826
        while(*cur_p && isspace(*cur_p)) cur_p++;
827
 
828
        switch_param(cur_p, cur_param);
829 645 markom
      }
830
    }
831
    fclose (f);
832
    runtime.sim.script_file_specified = 1;
833
  } else
834
    if (config.sim.verbose)
835
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
836
}
837
 
838
/* Utility for execution of set sim command.  */
839 1353 nogj
static int set_config (int argc, char **argv)
840 645 markom
{
841 1358 nogj
  struct config_section *cur;
842
  struct config_param *cur_param;
843 1353 nogj
 
844
  if (argc < 2) return 1;
845
 
846
  PRINTF ("sec:%s\n", argv[1]);
847 1358 nogj
  cur_section = NULL;
848
  for (cur = sections; cur; cur = cur->next)
849
    if (strcmp (cur->name, argv[1]) == 0) {
850
      cur_section = cur;
851 645 markom
      break;
852
    }
853
 
854 1358 nogj
  if (!cur_section) return 1;
855 1353 nogj
 
856
  if (argc < 3) return 2;
857 645 markom
 
858 1353 nogj
  PRINTF ("item:%s\n", argv[2]);
859 645 markom
  {
860 1358 nogj
    for (cur_param = cur->params; cur_param; cur_param = cur_param->next)
861
      if (strcmp (cur_param->name, argv[2]) == 0) {
862 645 markom
        break;
863
      }
864 1358 nogj
    if (!cur_param) return 2;
865 645 markom
 
866
    /* Parse parameter value */
867 1358 nogj
    if (cur_param->type) {
868 1353 nogj
      if (argc < 4) return 3;
869
      PRINTF ("params:%s\n", argv[3]);
870
    }
871 1358 nogj
 
872
    switch_param(argv[3], cur_param);
873 645 markom
  }
874
  return 0;
875
}
876
 
877
/* Executes set sim command, displays error.  */
878 1353 nogj
void set_config_command(int argc, char **argv)
879 645 markom
{
880 1358 nogj
  struct config_section *cur;
881
  struct config_param *cur_param;
882 1353 nogj
 
883
  switch (set_config (argc, argv)) {
884 645 markom
    case 1:
885 997 markom
      PRINTF ("Invalid or missing section name.  One of valid sections must be specified:\n");
886 1358 nogj
      for (cur = sections; cur; cur = cur->next)
887
        PRINTF ("%s ", cur->name);
888 997 markom
      PRINTF ("\n");
889 645 markom
      break;
890
    case 2:
891 997 markom
      PRINTF ("Invalid or missing item name.  One of valid items must be specified:\n");
892 1358 nogj
      for (cur_param = cur_section->params; cur_param; cur_param = cur_param->next)
893
        PRINTF ("%s ", cur_param->name);
894 997 markom
      PRINTF ("\n");
895 645 markom
      break;
896
    case 3:
897 997 markom
      PRINTF ("Invalid parameters specified.\n");
898 645 markom
      break;
899
  }
900
}
901
#endif /* !FAST_SIM */
902
 
903
/* Outputs C structure of current config to file */
904
void output_cfg (FILE *f)
905
{
906
  int i, comma;
907
  fprintf (f, "/* This file was automatically generated by or1ksim,\n"
908
              "   using --output-cfg switch (cfg file '%s'). */\n"
909
  "const static struct config config = {\n", runtime.sim.script_fn);
910
 
911 731 ivang
  fprintf (f, "  tick:{enabled:%i},\n", config.tick.enabled);
912 645 markom
  fprintf (f, "  nuarts:%i, uarts:{", config.nuarts);
913
  comma = 0;
914
  for (i = 0; i < config.nuarts; i++) {
915 1308 phoenix
    fprintf (f, "%s\n    {channel:\"%s\", jitter:%i, baseaddr:0x%08lx, irq:%i, vapi_id:0x%08lx, uart16550:%i}",
916 1076 rprescott
      comma ? "," :"", config.uarts[i].channel, config.uarts[i].jitter, config.uarts[i].baseaddr, config.uarts[i].irq,
917 645 markom
      config.uarts[i].vapi_id, config.uarts[i].uart16550);
918
    comma = 1;
919
  }
920
  fprintf (f, "},\n");
921
 
922
  fprintf (f, "  ndmas:%i, dmas:{", config.ndmas);
923
  comma = 0;
924
  for (i = 0; i < config.ndmas; i++) {
925 1308 phoenix
    fprintf (f, "%s\n    {baseaddr:0x%08lx, irq:%i, vapi_id:0x%08lx}",
926 645 markom
      comma ? "," :"", config.dmas[i].baseaddr, config.dmas[i].irq, config.dmas[i].vapi_id);
927
    comma = 1;
928
  }
929
  fprintf (f, "},\n");
930
 
931
  fprintf (f, "  nethernets:%i, ethernets:{", config.nethernets);
932
  comma = 0;
933
  for (i = 0; i < config.nethernets; i++) {
934 1308 phoenix
    fprintf (f, "%s\n    {baseaddr:0x%08lx, dma:%i, tx_channel:0x%08x, rx_channel:0x%08x, rxfile:\"%s\", txfile:\"%s\", vapi_id:0x%08lx}",
935 645 markom
      comma ? "," :"", config.ethernets[i].baseaddr, config.ethernets[i].dma, config.ethernets[i].tx_channel, config.ethernets[i].rx_channel,
936 889 ivang
      config.ethernets[i].rxfile, config.ethernets[i].txfile, config.ethernets[i].base_vapi_id);
937 645 markom
    comma = 1;
938
  }
939
  fprintf (f, "},\n");
940
 
941
  fprintf (f, "  ngpios:%i, gpios:{", config.ngpios);
942
  comma = 0;
943
  for (i = 0; i < config.ngpios; i++) {
944 1308 phoenix
    fprintf (f, "%s\n    {baseaddr:0x%08lx, irq:%i, base_vapi_id:0x%08lx}",
945 645 markom
      comma ? "," :"", config.gpios[i].baseaddr, config.gpios[i].irq, config.gpios[i].base_vapi_id);
946
    comma = 1;
947
  }
948
  fprintf (f, "},\n");
949
 
950 1308 phoenix
  fprintf (f, "  mc:{enabled:%i, baseaddr:0x%08lx, POC:%i},\n", config.mc.enabled, config.mc.baseaddr, config.mc.POC);
951 645 markom
  fprintf (f, "  memory:{pattern:%i, random_seed:%i, type:%s, nmemories:%i, table:{", config.memory.pattern, config.memory.random_seed,
952
    config.memory.type == MT_UNKNOWN ? "MT_UNKNOWN" : config.memory.type == MT_PATTERN ? "MT_PATTERN" : "MT_RANDOM", config.memory.nmemories);
953
  comma = 0;
954
  for (i = 0; i < config.memory.nmemories; i++) {
955 1308 phoenix
    fprintf (f, "%s\n    {ce:%i, baseaddr:0x%08lx, size:0x%08lx, name:\"%s\", log:\"%s\", delayr:%i, delayw:%i}",
956 645 markom
      comma ? "," :"", config.memory.table[i].ce, config.memory.table[i].baseaddr, config.memory.table[i].size, config.memory.table[i].name,
957
      config.memory.table[i].log, config.memory.table[i].delayr, config.memory.table[i].delayw);
958
    comma = 1;
959
  }
960
  fprintf (f, "}},\n");
961
 
962
  fprintf (f, "  immu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
963
    config.immu.enabled, config.immu.nways, config.immu.nsets, config.immu.pagesize, config.immu.entrysize, config.immu.ustates,
964
    config.immu.missdelay, config.immu.hitdelay);
965
 
966
  fprintf (f, "  dmmu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
967
    config.dmmu.enabled, config.dmmu.nways, config.dmmu.nsets, config.dmmu.pagesize, config.dmmu.entrysize, config.dmmu.ustates,
968
    config.dmmu.missdelay, config.dmmu.hitdelay);
969
 
970
  fprintf (f, "  ic:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
971
    config.ic.enabled, config.ic.nways, config.ic.nsets, config.ic.blocksize, config.ic.ustates,
972
    config.ic.missdelay, config.ic.hitdelay);
973
 
974
  fprintf (f, "  dc:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i,\n"
975
    "    load_missdelay:%i, load_hitdelay:%i, store_missdelay:%i, store_hitdelay:%i},\n",
976
    config.dc.enabled, config.dc.nways, config.dc.nsets, config.dc.blocksize, config.dc.ustates,
977
    config.dc.load_missdelay, config.dc.load_hitdelay, config.dc.store_missdelay, config.dc.store_hitdelay);
978
 
979
  fprintf (f, "  bpb:{enabled:%i, sbp_bnf_fwd:%i, sbp_bf_fwd:%i, btic:%i, missdelay:%i, hitdelay:%i},\n",
980
    config.bpb.enabled, config.bpb.sbp_bnf_fwd, config.bpb.sbp_bf_fwd, config.bpb.btic, config.bpb.missdelay, config.bpb.hitdelay);
981
 
982 1308 phoenix
  fprintf (f, "  cpu:{upr:0x%08lx, ver:0x%04lx, rev:0x%04lx, superscalar:%i, hazards:%i, dependstats:%i,\n"
983 732 ivang
    "    sr:0x%08x},\n",
984 645 markom
    config.cpu.upr, config.cpu.ver, config.cpu.rev, config.cpu.superscalar, config.cpu.hazards, config.cpu.dependstats,
985 732 ivang
    config.cpu.sr);
986 645 markom
 
987
  fprintf (f, "  sim:{debug:%i, verbose:%i, profile:%i, prof_fn:\"%s\", mprofile:%i, mprof_fn:\"%s\",\n",
988
    config.sim.debug, config.sim.verbose, config.sim.profile, config.sim.prof_fn, config.sim.mprofile, config.sim.mprof_fn);
989
 
990 1308 phoenix
  fprintf (f, "    history:%i, exe_log:%i, exe_log_fn:\"%s\", clkcycle_ps:%li,\n",
991 645 markom
    config.sim.history, config.sim.exe_log, config.sim.exe_log_fn, config.sim.clkcycle_ps);
992
 
993
  fprintf (f, "    spr_log:%i, spr_log_fn:\"%s\"},\n",
994
    config.sim.spr_log, config.sim.spr_log_fn);
995
 
996 1308 phoenix
  fprintf (f, "  debug:{enabled:%i, gdb_enabled:%i, server_port:%i, vapi_id:0x%08lx},\n",
997 645 markom
    config.debug.enabled, config.debug.gdb_enabled, config.debug.server_port, config.debug.vapi_id);
998
 
999
  fprintf (f, "  vapi:{enabled:%i, server_port:%i, log_enabled:%i, hide_device_id:%i, vapi_fn:\"%s\"},\n",
1000
    config.vapi.enabled, config.vapi.server_port, config.vapi.log_enabled, config.vapi.hide_device_id, config.vapi.vapi_fn);
1001
 
1002
  fprintf (f, "  pm:{enabled:%i}\n",
1003
    config.pm.enabled);
1004
 
1005
  fprintf (f, "};\n");
1006
}

powered by: WebSVN 2.1.0

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