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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_67/] [or1ksim/] [sim-config.c] - Blame information for rev 1765

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

powered by: WebSVN 2.1.0

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