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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_62/] [or1ksim/] [sim-config.c] - Blame information for rev 1375

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

powered by: WebSVN 2.1.0

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