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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_65/] [or1ksim/] [sim-config.c] - Blame information for rev 1778

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

powered by: WebSVN 2.1.0

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