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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [sim-config.c] - Blame information for rev 1432

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

powered by: WebSVN 2.1.0

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