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 1549

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

powered by: WebSVN 2.1.0

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