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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc1/] [or1ksim/] [sim-config.c] - Blame information for rev 1718

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

powered by: WebSVN 2.1.0

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