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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_40/] [or1ksim/] [sim-config.c] - Blame information for rev 1369

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

powered by: WebSVN 2.1.0

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