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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [sim-config.c] - Blame information for rev 1561

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

powered by: WebSVN 2.1.0

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