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 427

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 427 markom
#define WARNING(s) fprintf (stderr, "WARNING: config.%s: %s\n", sections[section].name, (s))
29 424 markom
#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 427 markom
            fprintf (stderr, "WARNING: config.%s: %s\n", sections[section], tmp);
211 424 markom
            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 425 markom
void immu_enabled ();
289
void immu_nsets ();
290
void immu_nways ();
291
void immu_pagesize ();
292
void immu_entrysize ();
293
void immu_ustates ();
294
void dmmu_enabled ();
295
void dmmu_nsets ();
296
void dmmu_nways ();
297
void dmmu_pagesize ();
298
void dmmu_entrysize ();
299
void dmmu_ustates ();
300 424 markom
 
301
unsigned long tempL;
302
unsigned long tempUL;
303
char tempS[STR_SIZE];
304
 
305
#define CPF_SUBSECTION 1
306
#define CPF_SUBFIELD   2
307
 
308
struct section sections[] = {
309
  {"?",      0},  /* 0  */
310
  {"mc",     0},
311
  {"uart",   0},
312
  {"dma",    0},
313
  {"memory", 0},
314
  {"cpu",    0},
315
  {"sim",    0},
316
  {"debug",  0},
317
  {"VAPI",   0},
318
  {"ethernet",0},
319 425 markom
  {"tick",   0},   /* 10 */
320
  {"immu",   0},
321
  {"dmmu",   0}
322 424 markom
};
323
 
324
/* *INDENT-OFF* */
325
 
326
/* Parameter definitions */
327
struct config_params {
328
  int section;
329
  int attr;
330
  char *name;
331
  char *type;
332
  void (*func)();
333
  void *addr;
334
} config_params[] = {
335
{1, 0, "enabled",            "=%i",         NULL,          (void *)(&config.mc.enabled)},
336
{1, 0, "baseaddr",           "=0x%x",       NULL,          (void *)(&config.mc.baseaddr)},
337
{1, 0, "POC",                "=0x%x",       NULL,          (void *)(&config.mc.POC)},
338
 
339
{2, 0, "enabled",            "=%i",         NULL,          (void *)(&config.uarts_enabled)},
340
{2, 0, "nuarts",             "=%i",         uart_nuarts,   (void *)(&tempL)},
341
{2, 0, "device",             "%i",          change_device, (void *)(&tempL)},
342
{2, 0, "enddevice",          "",            end_device,    NULL},
343
{2, 0, "baseaddr",           "=0x%x",       uart_baseaddr, (void *)(&tempUL)},
344
{2, 0, "irq",                "=%i",         uart_irq,      (void *)(&tempL)},
345
{2, 0, "16550",              "=%i",         uart_16550,    (void *)(&tempL)},
346
{2, 0, "jitter",             "=%i",         uart_jitter,   (void *)(&tempL)},
347
{2, 0, "rxfile",             "=\"%s\"",     uart_rxfile,   (void *)(&tempS[0])},
348
{2, 0, "txfile",             "=\"%s\"",     uart_txfile,   (void *)(&tempS[0])},
349
{2, 0, "vapi_id",            "=0x%x",       uart_vapi_id,  (void *)(&tempUL)},
350
 
351
{3, 0, "enabled",            "=%i",         NULL,          (void *)(&config.dmas_enabled)},
352
{3, 0, "ndmas",              "=%i",         dma_ndmas,     (void *)(&tempL)},
353
{3, 0, "device",             "%i",          change_device, (void *)(&tempL)},
354
{3, 0, "enddevice",          "",            end_device,    NULL},
355
{3, 0, "baseaddr",           "=0x%x",       dma_baseaddr,  (void *)(&tempUL)},
356
{3, 0, "irq",                "=%i",         dma_baseaddr,  (void *)(&tempL)},
357
{3, 0, "vapi_id",            "=0x%x",       dma_vapi_id,   (void *)(&tempUL)},
358
 
359
{4, 0, "random_seed",        "=%i",         NULL,          (void *)(&config.memory.random_seed)},
360
{4, 0, "pattern",            "=%i",         NULL,          (void *)(&config.memory.pattern)},
361
{4, 0, "type",               "=%s ",        memory_type,   (void *)(&tempS[0])},
362
{4, 0, "nmemories",          "=%i",         memory_nmemories,(void *)(&tempL)},
363
{4, 0, "device",             "%i",          change_device, (void *)(&tempL)},
364
{4, 0, "enddevice",          "",            end_device,    NULL},
365
{4, 0, "ce",                 "=%i",         memory_ce,     (void *)(&tempL)},
366
{4, 0, "baseaddr",           "=0x%x",       memory_baseaddr,(void *)(&tempUL)},
367
{4, 0, "size",               "=0x%x",       memory_size,   (void *)(&tempUL)},
368 427 markom
{4, 0, "name",               "=\"%s\"",     memory_name,   (void *)(&tempS[0])},
369
{4, 0, "log",                "=\"%s\"",     memory_log,    (void *)(&tempS[0])},
370 424 markom
{4, 0, "delayr",             "=%i",         memory_delayr, (void *)(&tempL)},
371
{4, 0, "delayw",             "=%i",         memory_delayw, (void *)(&tempL)},
372
 
373
{5, 0, "ver",                "=0x%x",       NULL,          (void *)(&config.cpu.ver)},
374
{5, 0, "rev",                "=0x%x",       NULL,          (void *)(&config.cpu.rev)},
375
{5, 0, "upr",                "=0x%x",       NULL,          (void *)(&config.cpu.upr)},
376
{5, 0, "hazards",            "=%i",         NULL,          (void *)(&config.cpu.hazards)},
377
{5, 0, "superscalar",        "=%i",         NULL,          (void *)(&config.cpu.superscalar)},
378
{5, 0, "dependstats",        "=%i",         NULL,          (void *)(&config.cpu.dependstats)},
379
{5, 0, "slp",                "=%i",         NULL,          (void *)(&config.cpu.slp)},
380
{5, 0, "bpb",                "=%i",         NULL,          (void *)(&config.cpu.bpb)},
381
{5, 0, "btic",               "=%i",         NULL,          (void *)(&config.cpu.btic)},
382
 
383
{6, 0, "debug",              "=%i",         NULL,          (void *)(&config.sim.debug)},
384
{6, 0, "iprompt",            "=%i",         NULL,          (void *)(&config.sim.iprompt)},
385
{6, 0, "verbose",            "=%i",         NULL,          (void *)(&config.sim.verbose)},
386
{6, 0, "profile",            "=%i",         NULL,          (void *)(&config.sim.profile)},
387
{6, 0, "prof_fn",            "=\"%s\"",     NULL,          (void *)(&config.sim.prof_fn[0])},
388
{6, 0, "history",            "=%i",         NULL,          (void *)(&config.sim.history)},
389
{6, 0, "exe_log",            "=%i",         NULL,          (void *)(&config.sim.exe_log)},
390
{6, 0, "exe_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.exe_log_fn[0])},
391
 
392
{7, 0, "enabled",            "=%i",         NULL,          (void *)(&config.debug.enabled)},
393
{7, 0, "gdb_enabled",        "=%i",         NULL,          (void *)(&config.debug.gdb_enabled)},
394
{7, 0, "server_port",        "=%i",         NULL,          (void *)(&config.debug.server_port)},
395
 
396
{8, 0, "enabled",            "=%i",         NULL,          (void *)(&config.vapi.enabled)},
397
{8, 0, "server_port",        "=%i",         NULL,          (void *)(&config.vapi.server_port)},
398
{8, 0, "log_enabled",        "=%i",         NULL,          (void *)(&config.vapi.log_enabled)},
399
{8, 0, "log_device_id",      "=%i",         NULL,          (void *)(&config.vapi.log_device_id)},
400
{8, 0, "vapi_log_fn",        "=\"%s\"",     NULL,          (void *)(&config.vapi.vapi_fn[0])},
401
 
402
{9, 0, "enabled",            "=%i",         NULL,          (void *)(&config.ethernets_enabled)},
403
{9, 0, "nethernets",         "=%i",         eth_nethernets,(void *)(&tempL)},
404
{9, 0, "device",             "%i",          change_device, (void *)(&tempL)},
405
{9, 0, "enddevice",          "",            end_device,    NULL},
406
{9, 0, "baseaddr",           "=0x%x",       eth_baseaddr,  (void *)(&tempUL)},
407
{9, 0, "dma",                "=%i",         eth_dma,       (void *)(&tempL)},
408
{9, 0, "rx_channel",         "=%i",         eth_rx_channel,(void *)(&tempL)},
409
{9, 0, "tx_channel",         "=%i",         eth_tx_channel,(void *)(&tempL)},
410
{9, 0, "rxfile",             "=\"%s\"",     eth_rxfile,    (void *)(&tempS[0])},
411
{9, 0, "txfile",             "=\"%s\"",     eth_txfile,    (void *)(&tempS[0])},
412
{9, 0, "vapi_id",            "=0x%x",       eth_vapi_id,   (void *)(&tempUL)},
413
 
414
{10,0, "enabled",            "=%i",         NULL,          (void *)(&config.tick.enabled)},
415
{10,0, "irq",                "=%i",         NULL,          (void *)(&config.tick.irq)},
416 425 markom
 
417
{11,0, "enabled",            "=%i",         immu_enabled,  (void *)(&tempL)},
418
{11,0, "nsets",              "=%i",         immu_nsets,    (void *)(&tempL)},
419
{11,0, "nways",              "=%i",         immu_nways,    (void *)(&tempL)},
420
{11,0, "pagesize",           "=%i",         immu_pagesize, (void *)(&tempL)},
421
{11,0, "entrysize",          "=%i",         immu_entrysize,(void *)(&tempL)},
422
{11,0, "ustates",            "=%i",         immu_ustates,  (void *)(&tempL)},
423
 
424
{12,0, "enabled",            "=%i",         dmmu_enabled,  (void *)(&tempL)},
425
{12,0, "nsets",              "=%i",         dmmu_nsets,    (void *)(&tempL)},
426
{12,0, "nways",              "=%i",         dmmu_nways,    (void *)(&tempL)},
427
{12,0, "pagesize",           "=%i",         dmmu_pagesize, (void *)(&tempL)},
428
{12,0, "entrysize",          "=%i",         dmmu_entrysize,(void *)(&tempL)},
429
{12,0, "ustates",            "=%i",         dmmu_ustates,  (void *)(&tempL)}
430 424 markom
};
431
 
432
/* *INDENT-ON* */
433
 
434
int current_device = -1;
435
void change_device () {
436
  current_device = tempL;
437
}
438
 
439
void end_device () {
440
  current_device = -1;
441
}
442
 
443
void uart_nuarts () {
444
  if (tempL >= 0 && tempL < MAX_UARTS)
445
    config.nuarts = tempL;
446
  else
447
    ERROR("invalid number of devices.");
448
}
449
 
450
void uart_baseaddr () {
451
  if (current_device >= 0 && current_device < config.nuarts)
452
    config.uarts[current_device].baseaddr = tempUL;
453
  else
454
    ERROR("invalid device number.");
455
}
456
 
457
void uart_jitter () {
458
  if (current_device >= 0 && current_device < config.nuarts)
459
    config.uarts[current_device].jitter = tempL;
460
  else
461
    ERROR("invalid device number.");
462
}
463
 
464
void uart_irq () {
465
  if (current_device >= 0 && current_device < config.nuarts)
466
    config.uarts[current_device].irq = tempL;
467
  else
468
    ERROR("invalid device number.");
469
}
470
 
471
void uart_16550 () {
472
  if (current_device >= 0 && current_device < config.nuarts)
473
    config.uarts[current_device].uart16550 = tempL;
474
  else
475
    ERROR("invalid device number.");
476
}
477
 
478
void uart_rxfile () {
479
  if (current_device >= 0 && current_device < config.nuarts)
480
    strcpy (config.uarts[current_device].rxfile, tempS);
481
  else
482
    ERROR("invalid device number.");
483
}
484
 
485
void uart_txfile () {
486
  if (current_device >= 0 && current_device < config.nuarts)
487
    strcpy (config.uarts[current_device].txfile, tempS);
488
  else
489
    ERROR("invalid device number.");
490
}
491
 
492
void uart_vapi_id () {
493
  if (current_device >= 0 && current_device < config.nuarts)
494
    config.uarts[current_device].vapi_id = tempUL;
495
  else
496
    ERROR("invalid device number.");
497
}
498
 
499
void dma_ndmas () {
500
  if (tempL >= 0 && tempL < MAX_DMAS)
501
    config.ndmas = tempL;
502
  else
503
    ERROR("invalid number of devices.");
504
}
505
 
506
void dma_baseaddr () {
507
  if (current_device >= 0 && current_device < config.ndmas)
508
    config.dmas[current_device].baseaddr = tempUL;
509
  else
510
    ERROR("invalid device number.");
511
}
512
 
513
void dma_irq () {
514
  if (current_device >= 0 && current_device < config.ndmas)
515
    config.dmas[current_device].irq = tempL;
516
  else
517
    ERROR("invalid device number.");
518
}
519
 
520
void dma_vapi_id () {
521
  if (current_device >= 0 && current_device < config.ndmas)
522
    config.dmas[current_device].vapi_id = tempUL;
523
  else
524
    ERROR("invalid device number.");
525
}
526
 
527
void memory_nmemories () {
528
  if (tempL >= 0 && tempL < MAX_MEMORIES)
529
    config.memory.nmemories = tempL;
530
  else
531
    ERROR("invalid number of devices.");
532
}
533
 
534
void memory_type () {
535
  if (strcmp (tempS, "unknown") == 0)
536
    config.memory.type = MT_UNKNOWN;
537
  else if (strcmp (tempS, "random") == 0)
538
    config.memory.type = MT_RANDOM;
539
  else if (strcmp (tempS, "pattern") == 0)
540
    config.memory.type = MT_PATTERN;
541
  else if (strcmp (tempS, "zero") == 0) {
542
    config.memory.type = MT_PATTERN;
543
    config.memory.pattern = 0;
544
  } else {
545
    char tmp[200];
546
    sprintf (tmp, "invalid memory type '%s'.\n", tempS);
547
    ERROR(tmp);
548
  }
549
}
550
 
551
void memory_ce () {
552
  if (current_device >= 0 && current_device < config.memory.nmemories)
553
    config.memory.table[current_device].ce = tempL;
554
  else
555
    ERROR("invalid device number.");
556
}
557
 
558
void memory_baseaddr () {
559
  if (current_device >= 0 && current_device < config.memory.nmemories)
560
    config.memory.table[current_device].baseaddr = tempUL;
561
  else
562
    ERROR("invalid device number.");
563
}
564
 
565
void memory_size () {
566
  if (current_device >= 0 && current_device < config.memory.nmemories)
567
    config.memory.table[current_device].size = tempUL;
568
  else
569
    ERROR("invalid device number.");
570
}
571
 
572
void memory_name () {
573
  if (current_device >= 0 && current_device < config.memory.nmemories)
574
    strcpy (config.memory.table[current_device].name, tempS);
575
  else
576
    ERROR("invalid device number.");
577
}
578
 
579
void memory_log () {
580
  if (current_device >= 0 && current_device < config.memory.nmemories)
581
    strcpy (config.memory.table[current_device].log, tempS);
582
  else
583
    ERROR("invalid device number.");
584
}
585
 
586
void memory_delayr () {
587
  if (current_device >= 0 && current_device < config.memory.nmemories)
588
    config.memory.table[current_device].delayr = tempL;
589
  else
590
    ERROR("invalid device number.");
591
}
592
 
593
void memory_delayw () {
594
  if (current_device >= 0 && current_device < config.memory.nmemories)
595
    config.memory.table[current_device].delayw = tempL;
596
  else
597
    ERROR("invalid device number.");
598
}
599
 
600
void eth_nethernets () {
601
  if (tempL >= 0 && tempL < MAX_ETHERNETS)
602
    config.nethernets = tempL;
603
  else
604
    ERROR("invalid number of devices.");
605
}
606
 
607
void eth_baseaddr () {
608
  if (current_device >= 0 && current_device < config.nethernets)
609
    config.ethernets[current_device].baseaddr = tempUL;
610
  else
611
    ERROR("invalid device number.");
612
}
613
 
614
void eth_dma () {
615
  if (current_device >= 0 && current_device < config.nethernets)
616
    config.ethernets[current_device].dma = tempL;
617
  else
618
    ERROR("invalid device number.");
619
}
620
 
621
void eth_rx_channel () {
622
  if (current_device >= 0 && current_device < config.nethernets)
623
    config.ethernets[current_device].rx_channel = tempL;
624
  else
625
    ERROR("invalid device number.");
626
}
627
 
628
void eth_tx_channel () {
629
  if (current_device >= 0 && current_device < config.nethernets)
630
    config.ethernets[current_device].rx_channel = tempL;
631
  else
632
    ERROR("invalid device number.");
633
}
634
 
635
void eth_rxfile () {
636
  if (current_device >= 0 && current_device < config.nethernets)
637
    strcpy (config.ethernets[current_device].rxfile, tempS);
638
  else
639
    ERROR("invalid device number.");
640
}
641
 
642
void eth_txfile () {
643
  if (current_device >= 0 && current_device < config.nethernets)
644
    strcpy (config.ethernets[current_device].txfile, tempS);
645
  else
646
    ERROR("invalid device number.");
647
}
648
 
649
void eth_vapi_id () {
650
  if (current_device >= 0 && current_device < config.nethernets)
651
    config.ethernets[current_device].vapi_id = tempUL;
652
  else
653 425 markom
    ERROR("invalid device number.");
654 424 markom
}
655
 
656 425 markom
int is_power2 (int x) {
657
  while (!(x & 1))
658
    x >>= 1;
659
  return x == 1;
660
}
661 424 markom
 
662 425 markom
void immu_enabled () {
663
  setsprbits (SPR_UPR, SPR_UPR_IMP, tempL & 1);
664
}
665 424 markom
 
666 425 markom
void dmmu_enabled () {
667
  setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1);
668
}
669
 
670
void immu_nsets () {
671
  if (is_power2(tempL) && tempL <= 256)
672
    config.immu.nsets = tempL;
673
  else
674
    ERROR("value of power two and lower or equal than 256 expected.");
675
}
676
 
677
void dmmu_nsets () {
678
  if (is_power2(tempL) && tempL <= 256)
679
    config.dmmu.nsets = tempL;
680
  else
681
    ERROR("value of power two and lower or equal than 256 expected.");
682
}
683
 
684
void immu_nways () {
685
  if (tempL >= 1 && tempL <= 4)
686
    config.immu.nways = tempL;
687
  else
688
    ERROR("value 1, 2, 3 or 4 expected.");
689
}
690
 
691
void dmmu_nways () {
692
  if (tempL >= 1 && tempL <= 4)
693
    config.dmmu.nways = tempL;
694
  else
695
    ERROR("value 1, 2, 3 or 4 expected.");
696
}
697
 
698
void immu_pagesize () {
699
  if (is_power2(tempL))
700
    config.immu.pagesize = tempL;
701
  else
702
    ERROR("value of power two expected.");
703
}
704
 
705
void dmmu_pagesize () {
706
  if (is_power2(tempL))
707
    config.dmmu.pagesize = tempL;
708
  else
709
    ERROR("value of power two expected.");
710
}
711
 
712
void immu_entrysize () {
713
  if (is_power2(tempL))
714
    config.immu.entrysize = tempL;
715
  else
716
    ERROR("value of power two expected.");
717
}
718
 
719
void dmmu_entrysize () {
720
  if (is_power2(tempL))
721
    config.dmmu.entrysize = tempL;
722
  else
723
    ERROR("value of power two expected.");
724
}
725
 
726
void immu_ustates () {
727
  if (tempL >= 2 && tempL <= 4)
728
    config.immu.ustates = tempL;
729
  else
730
    ERROR("invalid USTATE.");
731
}
732
 
733
void dmmu_ustates () {
734
  if (tempL >= 2 && tempL <= 4)
735
    config.dmmu.ustates = tempL;
736
  else
737
    ERROR("invalid USTATE.");
738
}
739
 
740 424 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
741
   The syntax of script file is:
742
   param = value
743
   section x
744
     data
745
     param = value
746
   end
747
 
748
   Example:
749
   section mc
750
     memory_table_file = sim.mem
751
     enable = 1
752
     POC = 0x47892344
753
   end
754
 
755
 */
756
 
757
void read_script_file (char *filename)
758
{
759
  FILE *f;
760
  unsigned long memory_needed = 0;
761
  char *home = getenv("HOME");
762
  char ctmp[STR_SIZE];
763
  int local = 1;
764
  section = 0;
765
 
766
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
767
  if ((f = fopen (filename, "rt")) != NULL
768
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
769
    unsigned long start, length;
770
    char type[STR_SIZE];
771
    int nparam;
772
    int rd, wd;
773
    if (config.sim.verbose)
774
      printf ("Reading script file from '%s':\n", local ? filename : ctmp);
775
    while (!feof(f)) {
776
      char param[STR_SIZE];
777
      if (fscanf(f, "%s ", &param) != 1) break;
778
      /* Is this a sections? */
779
      if (strcmp (param, "section") == 0) {
780
        int i;
781
        section = 0;
782
        if (fscanf (f, "%s\n", &param) != 1) {
783
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
784
          exit (1);
785
        }
786
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
787
          if (strcmp (sections[i].name, param) == 0) {
788
            section = i;
789
            break;
790
          }
791
        if (!section) {
792
          char tmp[200];
793
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
794
          WARNING(tmp);
795
          /* just skip section */
796
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
797
        }
798
      } else if (strcmp (param, "end") == 0) {
799
        section = 0;
800
      } else if (strncmp (param, "/*", 2) == 0) {
801
        char c0 = 0, c1 = 0;
802
        while (c0 != '*' || c1 != '/') {
803
          c0 = c1;
804
          c1 = fgetc(f);
805
          if (feof(f)) {
806
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
807
            exit (1);
808
          }
809
        }
810
      } else {
811
        int i, found = -1;
812
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
813
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
814
            found = i;
815
            break;
816
          }
817
        if (found < 0) {
818
          char tmp[200];
819
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
820
          WARNING(tmp);
821
          while (fgetc(f) != '\n' || feof(f));
822
          continue;
823
        }
824
 
825
        /* Parse parameter value */
826
        {
827
          if (config_params[found].type[0])
828
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
829
              exit (1);
830
        }
831
        if (config_params[found].func)
832
          config_params[found].func();
833
      }
834
    }
835
    fclose (f);
836
    runtime.sim.script_file_specified = 1;
837
  } else
838
    if (config.sim.verbose)
839
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
840
}
841
 
842
/* Utility for execution of set sim command.  */
843
static int set_config (char *s)
844
{
845
  char *sec, *item, *params;
846
  int noparams = 0, i, noitem = 0;
847
  while (*s && isblank (*s)) s++;
848
  sec = s;
849
  printf ("s:%s\n", s);
850
  while (*s && *s != ' ') s++;
851
  if (!(*s)) noitem = 1;
852
  *s = 0;
853
  printf ("sec:%s\n", sec);
854
  section = 0;
855
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
856
    if (strcmp (sections[i].name, sec) == 0) {
857
      section = i;
858
      break;
859
    }
860
 
861
  if (!section) return 1;
862
  if (noitem) return 2;
863
 
864
  item = ++s;
865
 
866
  while (*s && *s != ' ') s++;
867
  if (!(*s)) {
868
    noparams = 1;
869
    params = "";
870
  } else
871
    params = s + 1;
872
  *s = 0;
873
  printf ("item:%s\n", item);
874
  printf ("params:%s\n", params);
875
  {
876
    int i, found = -1;
877
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
878
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
879
        found = i;
880
        break;
881
      }
882
    if (found < 0) return 2;
883
 
884
    /* Parse parameter value */
885
    if (config_params[found].type[0])
886
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
887
        return 3;
888
    if (config_params[found].func)
889
      config_params[found].func();
890
  }
891
  return 0;
892
}
893
 
894
/* Executes set sim command, displays error.  */
895
void set_config_command(char *s)
896
{
897
  int i;
898
  switch (set_config (s)) {
899
    case 1:
900
      printf ("Invalid or missing section name.  One of valid sections must be specified:\n");
901
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
902
        printf ("%s ", sections[i].name);
903
      printf ("\n");
904
      break;
905
    case 2:
906
      printf ("Invalid or missing item name.  One of valid items must be specified:\n");
907
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
908
        if (config_params[i].section == section)
909
          printf ("%s ", config_params[i].name);
910
      printf ("\n");
911
      break;
912
    case 3:
913
      printf ("Invalid parameters specified.\n");
914
      break;
915
  }
916
}

powered by: WebSVN 2.1.0

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