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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [sim-config.c] - Blame information for rev 1382

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 1382 nogj
int log2 (int x) {
581
  int log=-1;
582
  while (x)
583
  {
584
    x >>= 1;
585
    log++;
586
  }
587
  return log;
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
 
878
/* Outputs C structure of current config to file */
879
void output_cfg (FILE *f)
880
{
881
  int i, comma;
882
  fprintf (f, "/* This file was automatically generated by or1ksim,\n"
883
              "   using --output-cfg switch (cfg file '%s'). */\n"
884
  "const static struct config config = {\n", runtime.sim.script_fn);
885
 
886 731 ivang
  fprintf (f, "  tick:{enabled:%i},\n", config.tick.enabled);
887 645 markom
 
888
  fprintf (f, "  memory:{pattern:%i, random_seed:%i, type:%s, nmemories:%i, table:{", config.memory.pattern, config.memory.random_seed,
889
    config.memory.type == MT_UNKNOWN ? "MT_UNKNOWN" : config.memory.type == MT_PATTERN ? "MT_PATTERN" : "MT_RANDOM", config.memory.nmemories);
890
  comma = 0;
891
  for (i = 0; i < config.memory.nmemories; i++) {
892 1308 phoenix
    fprintf (f, "%s\n    {ce:%i, baseaddr:0x%08lx, size:0x%08lx, name:\"%s\", log:\"%s\", delayr:%i, delayw:%i}",
893 645 markom
      comma ? "," :"", config.memory.table[i].ce, config.memory.table[i].baseaddr, config.memory.table[i].size, config.memory.table[i].name,
894
      config.memory.table[i].log, config.memory.table[i].delayr, config.memory.table[i].delayw);
895
    comma = 1;
896
  }
897
  fprintf (f, "}},\n");
898
 
899
  fprintf (f, "  immu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
900
    config.immu.enabled, config.immu.nways, config.immu.nsets, config.immu.pagesize, config.immu.entrysize, config.immu.ustates,
901
    config.immu.missdelay, config.immu.hitdelay);
902
 
903
  fprintf (f, "  dmmu:{enabled:%i, nways:%i, nsets:%i, pagesize:%i, entrysize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
904
    config.dmmu.enabled, config.dmmu.nways, config.dmmu.nsets, config.dmmu.pagesize, config.dmmu.entrysize, config.dmmu.ustates,
905
    config.dmmu.missdelay, config.dmmu.hitdelay);
906
 
907
  fprintf (f, "  ic:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i, missdelay:%i, hitdelay:%i},\n",
908
    config.ic.enabled, config.ic.nways, config.ic.nsets, config.ic.blocksize, config.ic.ustates,
909
    config.ic.missdelay, config.ic.hitdelay);
910
 
911
  fprintf (f, "  dc:{enabled:%i, nways:%i, nsets:%i, blocksize:%i, ustates:%i,\n"
912
    "    load_missdelay:%i, load_hitdelay:%i, store_missdelay:%i, store_hitdelay:%i},\n",
913
    config.dc.enabled, config.dc.nways, config.dc.nsets, config.dc.blocksize, config.dc.ustates,
914
    config.dc.load_missdelay, config.dc.load_hitdelay, config.dc.store_missdelay, config.dc.store_hitdelay);
915
 
916
  fprintf (f, "  bpb:{enabled:%i, sbp_bnf_fwd:%i, sbp_bf_fwd:%i, btic:%i, missdelay:%i, hitdelay:%i},\n",
917
    config.bpb.enabled, config.bpb.sbp_bnf_fwd, config.bpb.sbp_bf_fwd, config.bpb.btic, config.bpb.missdelay, config.bpb.hitdelay);
918
 
919 1308 phoenix
  fprintf (f, "  cpu:{upr:0x%08lx, ver:0x%04lx, rev:0x%04lx, superscalar:%i, hazards:%i, dependstats:%i,\n"
920 732 ivang
    "    sr:0x%08x},\n",
921 645 markom
    config.cpu.upr, config.cpu.ver, config.cpu.rev, config.cpu.superscalar, config.cpu.hazards, config.cpu.dependstats,
922 732 ivang
    config.cpu.sr);
923 645 markom
 
924
  fprintf (f, "  sim:{debug:%i, verbose:%i, profile:%i, prof_fn:\"%s\", mprofile:%i, mprof_fn:\"%s\",\n",
925
    config.sim.debug, config.sim.verbose, config.sim.profile, config.sim.prof_fn, config.sim.mprofile, config.sim.mprof_fn);
926
 
927 1308 phoenix
  fprintf (f, "    history:%i, exe_log:%i, exe_log_fn:\"%s\", clkcycle_ps:%li,\n",
928 645 markom
    config.sim.history, config.sim.exe_log, config.sim.exe_log_fn, config.sim.clkcycle_ps);
929
 
930
  fprintf (f, "    spr_log:%i, spr_log_fn:\"%s\"},\n",
931
    config.sim.spr_log, config.sim.spr_log_fn);
932
 
933 1308 phoenix
  fprintf (f, "  debug:{enabled:%i, gdb_enabled:%i, server_port:%i, vapi_id:0x%08lx},\n",
934 645 markom
    config.debug.enabled, config.debug.gdb_enabled, config.debug.server_port, config.debug.vapi_id);
935
 
936
  fprintf (f, "  vapi:{enabled:%i, server_port:%i, log_enabled:%i, hide_device_id:%i, vapi_fn:\"%s\"},\n",
937
    config.vapi.enabled, config.vapi.server_port, config.vapi.log_enabled, config.vapi.hide_device_id, config.vapi.vapi_fn);
938
 
939
  fprintf (f, "  pm:{enabled:%i}\n",
940
    config.pm.enabled);
941
 
942
  fprintf (f, "};\n");
943
}

powered by: WebSVN 2.1.0

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