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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [sim-config.c] - Blame information for rev 394

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 jrydberg
/* config.c -- Simulator configuration
2
   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 239 markom
#include <stdlib.h>
23 7 jrydberg
#include "sim-config.h"
24 30 lampret
#include "abstract.h"
25 103 lampret
#include "spr_defs.h"
26 230 erez
#include "pic.h"
27 7 jrydberg
 
28 355 markom
#define WARNING(s) fprintf (stderr, "WARNING: config.%s: %s\n", sections[section], s)
29 361 markom
#define ERROR(s) {fprintf (stderr, "ERROR: %s\n", s); if (runtime.sim.init) exit (1);}
30 355 markom
 
31 7 jrydberg
struct config config;
32 361 markom
struct runtime runtime;
33
 
34 355 markom
int section = 0;
35
extern struct section {
36
  char *name;
37
  int flags;
38
} sections[];
39 7 jrydberg
 
40
void init_defconfig()
41
{
42 239 markom
  unsigned long val;
43
 
44
  memset(&config, 0, sizeof(config));
45 361 markom
  memset(&runtime, 0, sizeof(runtime));
46 263 markom
  /* Sim */
47 294 markom
  config.sim.exe_log = 0;
48 361 markom
  runtime.sim.fexe_log = NULL;
49 294 markom
  strcpy (config.sim.exe_log_fn, "executed.log");
50
 
51 264 markom
  config.sim.debug = 0;
52 293 markom
  config.sim.verbose = 1;
53 264 markom
  config.sim.iprompt = 0;
54 263 markom
 
55 294 markom
  config.sim.profile = 0;
56 361 markom
  runtime.sim.fprof = NULL;
57 294 markom
  strcpy (config.sim.prof_fn, "sim.profile");
58 361 markom
  runtime.sim.init = 1;
59
  runtime.sim.script_file_specified = 0;
60 294 markom
 
61 262 markom
  /* Memory */
62
  config.memory.type = MT_PATTERN;
63
  config.memory.pattern = 0;
64
  config.memory.random_seed = -1;  /* Generate new seed */
65
  strcpy(config.memory.memory_table_file, "simmem.cfg");
66 263 markom
 
67
  /* Memory Controller */
68
  config.mc.enabled = 0;
69
 
70
  /* Uarts */
71
  config.nuarts = 0;
72
  config.uarts_enabled = 0;
73
 
74
  /* DMAs */
75
  config.ndmas = 0;
76
  config.dmas_enabled = 0;
77
 
78
  /* CPU */
79
  config.cpu.superscalar = 0;
80 394 markom
  config.sim.history = 0;
81 263 markom
  config.cpu.hazards = 0;
82
  config.cpu.dependstats = 0;
83
  config.cpu.slp = 0;
84
  config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP
85
                 | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP
86
                 | SPR_UPR_PMP | SPR_UPR_TTP;
87 264 markom
 
88 269 markom
  /* Debug */
89
  config.debug.enabled = 0;
90
  config.debug.gdb_enabled = 0;
91
  config.debug.server_port = 0;
92 293 markom
 
93
  /* VAPI */
94
  config.vapi.enabled = 0;
95 355 markom
  strcpy (config.vapi.vapi_fn, "vapi.log");
96 361 markom
  runtime.vapi.vapi_file = NULL;
97 304 markom
 
98
  /* Ethernet */
99
  config.ethernets_enabled = 0;
100 332 markom
 
101
  /* Tick timer */
102
  config.tick.enabled = 0;
103 269 markom
 
104 262 markom
  /* Old */
105 326 lampret
  config.dc.tagtype = PHYSICAL/*VIRTUAL*/;
106
  config.ic.tagtype = PHYSICAL/*VIRTUAL*/;
107 239 markom
  config.clkcycle_ns = 4; /* 4 for 4ns (250MHz) */
108 103 lampret
}
109
 
110
int parse_args(int argc, char *argv[])
111
{
112 239 markom
  unsigned long val;
113
 
114
  argv++; argc--;
115
  while (argc) {
116
    if (argc && (*argv[0] != '-')) {
117 361 markom
      runtime.sim.filename = argv[0];
118 239 markom
      argc--;
119
      argv++;
120 242 markom
    } else
121 263 markom
    if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
122
      argv++; argc--;
123 361 markom
      read_script_file(argv[0]);
124 263 markom
      argv++; argc--;
125
    } else
126
    if (strcmp(*argv, "--nosrv") == 0) {  /* (CZ) */
127 269 markom
      config.debug.gdb_enabled = 0;
128 239 markom
      argv++; argc--;
129
    } else
130 263 markom
    if (strcmp(*argv, "--srv") == 0) {  /* (CZ) */
131 239 markom
      char *s;
132
      if(!--argc)
133
        return 1;
134 269 markom
      config.debug.enabled = 1;
135
      config.debug.gdb_enabled = 0;
136
      config.debug.server_port = strtol(*(++argv),&s,10);
137 239 markom
      if(*s)
138
        return 1;
139
      argv++; argc--;
140
    } else
141
    if (strcmp(*argv, "-i") == 0) {
142 264 markom
      config.sim.iprompt = 1;
143 239 markom
      argv++; argc--;
144
    } else
145
    if (strcmp(*argv, "-v") == 0) {
146
      version();
147
      exit(0);
148
    } else
149 263 markom
    if (strcmp(*argv, "--profile") == 0) {
150 264 markom
      config.sim.profile = 1;
151 239 markom
      argv++; argc--;
152
    } else {
153
      printf("Unknown option: %s\n", *argv);
154
      return 1;
155
    }
156
  }
157
 
158
  if (!argc)
159
    return 0;
160
 
161
  return 0;
162
}
163 123 markom
 
164 294 markom
#define CNV(x) ((isblank(x) || (x) == 0) ? ' ' : (x))
165
 
166
/* Substitute for less powerful fscanf */
167 361 markom
int fscanf_ex (FILE *f, char *fmt, void *buf, char *str) {
168 294 markom
  char tmp[STR_SIZE];
169
  char ch;
170
  int i = 0;
171
  while (*fmt) {
172
    switch (*fmt) {
173
      case '%':
174
        while(*fmt != 0 && !isalpha (*fmt))
175
          tmp[i++] = *(fmt++);
176
        tmp[i++] = *(fmt++);
177
        if (tmp[i - 1] == 's') {
178
          char *cbuf = (char *)buf;
179
          i = 0;
180 361 markom
          while (ch = (f ? fgetc (f) : *str++), isblank(ch))
181
            if (f ? feof (f) : *str) return 1;
182
          if (f)
183
            ungetc (ch, f);
184
          else
185
            str--;
186
          while ((*(cbuf++) = ch = (f ? fgetc (f) : *str++), CNV(ch) ) != *fmt) {
187
            if ((f ? feof (f) : *str)) return 1;
188 294 markom
            if (++i >= STR_SIZE) {
189
              fprintf (stderr, "ERROR: string too long.\n");
190
              return 1;
191
            }
192
          }
193
          *(--cbuf) = 0;
194
          fmt++;
195
        } else {
196
          tmp[i++] = 0;
197 361 markom
          if (f)
198
            fscanf (f, tmp, buf);
199
          else
200
            sscanf (str, tmp, buf);
201 294 markom
        }
202
        break;
203
      default:
204 361 markom
        while ((ch = (f ? fgetc (f) : *str++)) != *fmt) {
205 355 markom
          if (!isblank (ch)) {
206
            char tmp[200];
207
            sprintf (tmp, "unexpected char '%c' (expecting '%c')\n", ch, *fmt);
208
            WARNING(tmp);
209
          }
210 361 markom
          if ((f ? feof (f) : *str)) return 1;
211 294 markom
        }
212
        fmt++;
213
        break;
214
    }
215
  }
216
  return 0;
217
}
218
 
219 239 markom
void print_config()
220
{
221 361 markom
  if (config.sim.verbose) {
222
    printf("Verbose on, ");
223
    if (config.sim.debug)
224
      printf("simdebug on, ");
225
    else
226
      printf("simdebug off, ");
227
    if (config.sim.iprompt)
228
      printf("interactive prompt on\n");
229
    else
230
      printf("interactive prompt off\n");
231
 
232
    printf("Machine initialization...\n");
233
    printf("Clock cycle: %d ns\n", config.clkcycle_ns);
234
    if (testsprbits(SPR_UPR, SPR_UPR_DCP))
235
      printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
236
    else
237
      printf("No data cache.\n");
238
    if (testsprbits(SPR_UPR, SPR_UPR_ICP))
239
      printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
240
    else
241
      printf("No instruction cache.\n");
242
    if (config.cpu.bpb)
243
      printf("BPB simulation on.\n");
244
    else
245
      printf("BPB simulation off.\n");
246
    if (config.cpu.btic)
247
      printf("BTIC simulation on.\n");
248
    else
249
      printf("BTIC simulation off.\n");
250
  }
251 239 markom
}
252 123 markom
 
253 261 markom
void change_device ();
254
void end_device ();
255
void uart_baseaddr ();
256
void uart_rxfile ();
257
void uart_txfile ();
258
void uart_jitter ();
259 333 markom
void uart_irq ();
260 341 markom
void uart_16550 ();
261 320 erez
void uart_vapi_id ();
262 261 markom
void dma_baseaddr ();
263
void dma_irq ();
264 320 erez
void dma_vapi_id ();
265 262 markom
void memory_type ();
266 306 markom
void eth_baseaddr ();
267
void eth_dma ();
268 310 markom
void eth_rx_channel ();
269
void eth_tx_channel ();
270
void eth_rxfile ();
271
void eth_txfile ();
272 320 erez
void eth_vapi_id ();
273 123 markom
 
274 305 markom
unsigned long tempL;
275
unsigned long tempUL;
276
char tempS[STR_SIZE];
277 123 markom
 
278 305 markom
#define CPF_SUBSECTION 1
279
#define CPF_SUBFIELD   2
280
 
281 355 markom
struct section sections[] = {
282
  {"?",      0},  /* 0  */
283 261 markom
  {"mc",     0},
284
  {"uart",   0},
285 262 markom
  {"dma",    0},
286 263 markom
  {"memory", 0},
287 264 markom
  {"cpu",    0},
288 269 markom
  {"sim",    0},
289 293 markom
  {"debug",  0},
290 304 markom
  {"VAPI",   0},
291 332 markom
  {"ethernet",0},
292
  {"tick",   0}   /* 10 */
293 239 markom
};
294
 
295 305 markom
/* *INDENT-OFF* */
296 261 markom
 
297 239 markom
/* Parameter definitions */
298
struct config_params {
299
  int section;
300 361 markom
  int attr;
301 239 markom
  char *name;
302
  char *type;
303 261 markom
  void (*func)();
304
  void *addr;
305 239 markom
} config_params[] = {
306 361 markom
{1, 0, "enabled",            "=%i",         NULL,          (void *)(&config.mc.enabled)},
307
{1, 0, "baseaddr",           "=0x%x",       NULL,          (void *)(&config.mc.baseaddr)},
308
{1, 0, "POC",                "=0x%x",       NULL,          (void *)(&config.mc.POC)},
309
 
310
{2, 0, "enabled",            "=%i",         NULL,          (void *)(&config.uarts_enabled)},
311
{2, 0, "nuarts",             "=%i",         NULL,          (void *)(&config.nuarts)},
312
{2, 0, "device",             "%i",          change_device, (void *)(&tempL)},
313
{2, 0, "enddevice",          "",            end_device,    NULL},
314
{2, 0, "baseaddr",           "=0x%x",       uart_baseaddr, (void *)(&tempUL)},
315
{2, 0, "irq",                "=%i",         uart_irq,      (void *)(&tempL)},
316
{2, 0, "16550",              "=%i",         uart_16550,    (void *)(&tempL)},
317
{2, 0, "jitter",             "=%i",         uart_jitter,   (void *)(&tempL)},
318
{2, 0, "rxfile",             "=\"%s\"",     uart_rxfile,   (void *)(&tempS[0])},
319
{2, 0, "txfile",             "=\"%s\"",     uart_txfile,   (void *)(&tempS[0])},
320
{2, 0, "vapi_id",            "=0x%x",       uart_vapi_id,  (void *)(&tempUL)},
321
 
322
{3, 0, "enabled",            "=%i",         NULL,          (void *)(&config.dmas_enabled)},
323
{3, 0, "ndmas",              "=%i",         NULL,          (void *)(&config.ndmas)},
324
{3, 0, "device",             "%i",          change_device, (void *)(&tempL)},
325
{3, 0, "enddevice",          "",            end_device,    NULL},
326
{3, 0, "baseaddr",           "=0x%x",       dma_baseaddr,  (void *)(&tempUL)},
327
{3, 0, "irq",                "=%i",         dma_baseaddr,  (void *)(&tempL)},
328
{3, 0, "vapi_id",            "=0x%x",       dma_vapi_id,   (void *)(&tempUL)},
329
 
330
{4, 0, "memory_table_file",  "=\"%s\"",     NULL,          (void *)(&config.memory.memory_table_file[0])},
331
{4, 0, "random_seed",        "=%i",         NULL,          (void *)(&config.memory.random_seed)},
332
{4, 0, "pattern",            "=%i",         NULL,          (void *)(&config.memory.pattern)},
333
{4, 0, "type",               "=%s ",        memory_type,   (void *)(&tempS[0])},
334
 
335
{5, 0, "ver",                "=0x%x",       NULL,          (void *)(&config.cpu.ver)},
336
{5, 0, "rev",                "=0x%x",       NULL,          (void *)(&config.cpu.rev)},
337
{5, 0, "upr",                "=0x%x",       NULL,          (void *)(&config.cpu.upr)},
338
{5, 0, "hazards",            "=%i",         NULL,          (void *)(&config.cpu.hazards)},
339
{5, 0, "superscalar",        "=%i",         NULL,          (void *)(&config.cpu.superscalar)},
340
{5, 0, "dependstats",        "=%i",         NULL,          (void *)(&config.cpu.dependstats)},
341
{5, 0, "slp",                "=%i",         NULL,          (void *)(&config.cpu.slp)},
342
{5, 0, "bpb",                "=%i",         NULL,          (void *)(&config.cpu.bpb)},
343
{5, 0, "btic",               "=%i",         NULL,          (void *)(&config.cpu.btic)},
344
 
345
{6, 0, "debug",              "=%i",         NULL,          (void *)(&config.sim.debug)},
346
{6, 0, "iprompt",            "=%i",         NULL,          (void *)(&config.sim.iprompt)},
347
{6, 0, "verbose",            "=%i",         NULL,          (void *)(&config.sim.verbose)},
348
{6, 0, "profile",            "=%i",         NULL,          (void *)(&config.sim.profile)},
349
{6, 0, "prof_fn",            "=\"%s\"",     NULL,          (void *)(&config.sim.prof_fn[0])},
350 394 markom
{6, 0, "history",            "=%i",         NULL,          (void *)(&config.sim.history)},
351 361 markom
{6, 0, "exe_log",            "=%i",         NULL,          (void *)(&config.sim.exe_log)},
352
{6, 0, "exe_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.exe_log_fn[0])},
353
 
354
{7, 0, "enabled",            "=%i",         NULL,          (void *)(&config.debug.enabled)},
355
{7, 0, "gdb_enabled",        "=%i",         NULL,          (void *)(&config.debug.gdb_enabled)},
356
{7, 0, "server_port",        "=%i",         NULL,          (void *)(&config.debug.server_port)},
357
 
358
{8, 0, "enabled",            "=%i",         NULL,          (void *)(&config.vapi.enabled)},
359
{8, 0, "server_port",        "=%i",         NULL,          (void *)(&config.vapi.server_port)},
360
{8, 0, "log_enabled",        "=%i",         NULL,          (void *)(&config.vapi.log_enabled)},
361
{8, 0, "vapi_log_fn",        "=\"%s\"",     NULL,          (void *)(&config.vapi.vapi_fn[0])},
362
 
363
{9, 0, "enabled",            "=%i",         NULL,          (void *)(&config.ethernets_enabled)},
364
{9, 0, "nethernets",         "=%i",         NULL,          (void *)(&config.nethernets)},
365
{9, 0, "device",             "%i",          change_device, (void *)(&tempL)},
366
{9, 0, "enddevice",          "",            end_device,    NULL},
367
{9, 0, "baseaddr",           "=0x%x",       eth_baseaddr,  (void *)(&tempUL)},
368
{9, 0, "dma",                "=%i",         eth_dma,       (void *)(&tempL)},
369
{9, 0, "rx_channel",         "=%i",         eth_rx_channel,(void *)(&tempL)},
370
{9, 0, "tx_channel",         "=%i",         eth_tx_channel,(void *)(&tempL)},
371
{9, 0, "rxfile",             "=\"%s\"",     eth_rxfile,    (void *)(&tempS[0])},
372
{9, 0, "txfile",             "=\"%s\"",     eth_txfile,    (void *)(&tempS[0])},
373
{9, 0, "vapi_id",            "=0x%x",       eth_vapi_id,   (void *)(&tempUL)},
374
 
375
{10,0, "enabled",            "=%i",         NULL,          (void *)(&config.tick.enabled)},
376
{10,0, "irq",                "=%i",         NULL,          (void *)(&config.tick.irq)},
377 239 markom
};
378
 
379 305 markom
/* *INDENT-ON* */
380
 
381 261 markom
int current_device = -1;
382
void change_device () {
383
  current_device = tempL;
384
}
385
 
386
void end_device () {
387
  current_device = -1;
388
}
389
 
390
void uart_baseaddr () {
391
  if (current_device >= 0 && current_device < config.nuarts)
392
    config.uarts[current_device].baseaddr = tempUL;
393 355 markom
  else
394
    ERROR("invalid device number.");
395 261 markom
}
396
 
397
void uart_jitter () {
398
  if (current_device >= 0 && current_device < config.nuarts)
399
    config.uarts[current_device].jitter = tempL;
400 355 markom
  else
401
    ERROR("invalid device number.");
402 261 markom
}
403
 
404 341 markom
void uart_irq () {
405 261 markom
  if (current_device >= 0 && current_device < config.nuarts)
406 341 markom
    config.uarts[current_device].irq = tempL;
407 355 markom
  else
408
    ERROR("invalid device number.");
409 261 markom
}
410
 
411 341 markom
void uart_16550 () {
412 261 markom
  if (current_device >= 0 && current_device < config.nuarts)
413 341 markom
    config.uarts[current_device].uart16550 = tempL;
414 355 markom
  else
415
    ERROR("invalid device number.");
416 261 markom
}
417
 
418 341 markom
void uart_rxfile () {
419 313 markom
  if (current_device >= 0 && current_device < config.nuarts)
420 341 markom
    strcpy (config.uarts[current_device].rxfile, tempS);
421 355 markom
  else
422
    ERROR("invalid device number.");
423 313 markom
}
424
 
425 341 markom
void uart_txfile () {
426 332 markom
  if (current_device >= 0 && current_device < config.nuarts)
427 341 markom
    strcpy (config.uarts[current_device].txfile, tempS);
428 355 markom
  else
429
    ERROR("invalid device number.");
430 332 markom
}
431
 
432 341 markom
void uart_vapi_id () {
433
  if (current_device >= 0 && current_device < config.nuarts)
434
    config.uarts[current_device].vapi_id = tempUL;
435 355 markom
  else
436
    ERROR("invalid device number.");
437 341 markom
}
438
 
439 261 markom
void dma_baseaddr () {
440
  if (current_device >= 0 && current_device < config.ndmas)
441
    config.dmas[current_device].baseaddr = tempUL;
442 355 markom
  else
443
    ERROR("invalid device number.");
444 261 markom
}
445
 
446
void dma_irq () {
447
  if (current_device >= 0 && current_device < config.ndmas)
448
    config.dmas[current_device].irq = tempL;
449 355 markom
  else
450
    ERROR("invalid device number.");
451 261 markom
}
452
 
453 313 markom
void dma_vapi_id () {
454
  if (current_device >= 0 && current_device < config.ndmas)
455
    config.dmas[current_device].vapi_id = tempUL;
456 355 markom
  else
457
    ERROR("invalid device number.");
458 313 markom
}
459
 
460 262 markom
void memory_type () {
461 269 markom
  if (strcmp (tempS, "unknown") == 0)
462
    config.memory.type = MT_UNKNOWN;
463
  else if (strcmp (tempS, "random") == 0)
464 262 markom
    config.memory.type = MT_RANDOM;
465
  else if (strcmp (tempS, "pattern") == 0)
466
    config.memory.type = MT_PATTERN;
467
  else if (strcmp (tempS, "zero") == 0) {
468
    config.memory.type = MT_PATTERN;
469
    config.memory.pattern = 0;
470
  } else {
471 355 markom
    char tmp[200];
472
    sprintf (tmp, "invalid memory type '%s'.\n", tempS);
473
    ERROR(tmp);
474 262 markom
  }
475
}
476
 
477 304 markom
void eth_baseaddr () {
478
  if (current_device >= 0 && current_device < config.nethernets)
479
    config.ethernets[current_device].baseaddr = tempUL;
480 355 markom
  else
481
    ERROR("invalid device number.");
482 304 markom
}
483
 
484
void eth_dma () {
485
  if (current_device >= 0 && current_device < config.nethernets)
486 306 markom
    config.ethernets[current_device].dma = tempL;
487 355 markom
  else
488
    ERROR("invalid device number.");
489 304 markom
}
490
 
491 310 markom
void eth_rx_channel () {
492
  if (current_device >= 0 && current_device < config.nethernets)
493
    config.ethernets[current_device].rx_channel = tempL;
494 355 markom
  else
495
    ERROR("invalid device number.");
496 310 markom
}
497
 
498
void eth_tx_channel () {
499
  if (current_device >= 0 && current_device < config.nethernets)
500
    config.ethernets[current_device].rx_channel = tempL;
501 355 markom
  else
502
    ERROR("invalid device number.");
503 310 markom
}
504
 
505
void eth_rxfile () {
506
  if (current_device >= 0 && current_device < config.nethernets)
507
    strcpy (config.ethernets[current_device].rxfile, tempS);
508 355 markom
  else
509
    ERROR("invalid device number.");
510 310 markom
}
511
 
512
void eth_txfile () {
513
  if (current_device >= 0 && current_device < config.nethernets)
514 323 erez
    strcpy (config.ethernets[current_device].txfile, tempS);
515 355 markom
  else
516
    ERROR("invalid device number.");
517 310 markom
}
518
 
519 313 markom
void eth_vapi_id () {
520
  if (current_device >= 0 && current_device < config.nethernets)
521
    config.ethernets[current_device].vapi_id = tempUL;
522 355 markom
  else
523
    ERROR("nvalid device number.");
524 313 markom
}
525
 
526
 
527
 
528 239 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
529
   The syntax of script file is:
530
   param = value
531
   section x
532
     data
533
     param = value
534
   end
535
 
536
   Example:
537
   section mc
538
     memory_table_file = sim.mem
539
     enable = 1
540
     POC = 0x47892344
541
   end
542
 
543
 */
544
 
545
void read_script_file (char *filename)
546
{
547 263 markom
  FILE *f;
548
  unsigned long memory_needed = 0;
549
  char *home = getenv("HOME");
550
  char ctmp[STR_SIZE];
551
  int local = 1;
552 355 markom
  section = 0;
553
 
554 263 markom
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
555
  if ((f = fopen (filename, "rt")) != NULL
556
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
557
    unsigned long start, length;
558
    char type[STR_SIZE];
559
    int nparam;
560
    int rd, wd;
561 308 markom
    if (config.sim.verbose)
562
      printf ("Reading script file from '%s':\n", local ? filename : ctmp);
563 239 markom
    while (!feof(f)) {
564
      char param[STR_SIZE];
565
      if (fscanf(f, "%s ", &param) != 1) break;
566
      /* Is this a sections? */
567
      if (strcmp (param, "section") == 0) {
568
        int i;
569
        section = 0;
570
        if (fscanf (f, "%s\n", &param) != 1) {
571
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
572 355 markom
          exit (1);
573 239 markom
        }
574 294 markom
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
575 261 markom
          if (strcmp (sections[i].name, param) == 0) {
576 239 markom
            section = i;
577
            break;
578
          }
579
        if (!section) {
580 355 markom
          char tmp[200];
581
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
582
          WARNING(tmp);
583 239 markom
          /* just skip section */
584
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
585
        }
586
      } else if (strcmp (param, "end") == 0) {
587
        section = 0;
588 264 markom
      } else if (strncmp (param, "/*", 2) == 0) {
589 261 markom
        char c0 = 0, c1 = 0;
590 264 markom
        while (c0 != '*' || c1 != '/') {
591 261 markom
          c0 = c1;
592
          c1 = fgetc(f);
593
          if (feof(f)) {
594
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
595 355 markom
            exit (1);
596 261 markom
          }
597
        }
598 239 markom
      } else {
599
        int i, found = -1;
600
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
601
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
602
            found = i;
603
            break;
604
          }
605
        if (found < 0) {
606 355 markom
          char tmp[200];
607
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
608
          WARNING(tmp);
609 294 markom
          while (fgetc(f) != '\n' || feof(f));
610 239 markom
          continue;
611
        }
612
 
613
        /* Parse parameter value */
614
        {
615 294 markom
          if (config_params[found].type[0])
616 361 markom
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
617 294 markom
              exit (1);
618 239 markom
        }
619 262 markom
        if (config_params[found].func)
620
          config_params[found].func();
621 239 markom
      }
622
    }
623 263 markom
    fclose (f);
624 308 markom
  } else
625
    if (config.sim.verbose)
626
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'; assuming standard configuration.\n", filename, ctmp);
627 103 lampret
 
628 263 markom
  /* Initialize memory table.  */
629
  sim_read_memory_table (config.memory.memory_table_file);
630 361 markom
  runtime.sim.script_file_specified = 1;
631 7 jrydberg
}
632 361 markom
 
633
/* Utility for execution of set sim command.  */
634
static int set_config (char *s)
635
{
636
  char *sec, *item, *params;
637
  int noparams = 0, i, noitem = 0;
638
  while (*s && isblank (*s)) s++;
639
  sec = s;
640
  printf ("s:%s\n", s);
641
  while (*s && *s != ' ') s++;
642
  if (!(*s)) noitem = 1;
643
  *s = 0;
644
  printf ("sec:%s\n", sec);
645
  section = 0;
646
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
647
    if (strcmp (sections[i].name, sec) == 0) {
648
      section = i;
649
      break;
650
    }
651
 
652
  if (!section) return 1;
653
  if (noitem) return 2;
654
 
655
  item = ++s;
656
 
657
  while (*s && *s != ' ') s++;
658
  if (!(*s)) {
659
    noparams = 1;
660
    params = "";
661
  } else
662
    params = s + 1;
663
  *s = 0;
664
  printf ("item:%s\n", item);
665
  printf ("params:%s\n", params);
666
  {
667
    int i, found = -1;
668
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
669
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
670
        found = i;
671
        break;
672
      }
673
    if (found < 0) return 2;
674
 
675
    /* Parse parameter value */
676
    if (config_params[found].type[0])
677
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
678
        return 3;
679
    if (config_params[found].func)
680
      config_params[found].func();
681
  }
682
  return 0;
683
}
684
 
685
/* Executes set sim command, displays error.  */
686
void set_config_command(char *s)
687
{
688
  int i;
689
  switch (set_config (s)) {
690
    case 1:
691
      printf ("Invalid or missing section name.  One of valid sections must be specified:\n");
692
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
693
        printf ("%s ", sections[i].name);
694
      printf ("\n");
695
      break;
696
    case 2:
697
      printf ("Invalid or missing item name.  One of valid items must be specified:\n");
698
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
699
        if (config_params[i].section == section)
700
          printf ("%s ", config_params[i].name);
701
      printf ("\n");
702
      break;
703
    case 3:
704
      printf ("Invalid parameters specified.\n");
705
      break;
706
  }
707
}

powered by: WebSVN 2.1.0

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