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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_69/] [or1ksim/] [sim-config.c] - Blame information for rev 1361

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

powered by: WebSVN 2.1.0

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