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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [or1ksim/] [sim-config.c] - Blame information for rev 1520

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

powered by: WebSVN 2.1.0

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