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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_67/] [or1ksim/] [sim-config.c] - Blame information for rev 1373

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

powered by: WebSVN 2.1.0

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