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 426

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

powered by: WebSVN 2.1.0

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