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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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