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 424

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

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

powered by: WebSVN 2.1.0

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