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 1372

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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