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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_69/] [or1ksim/] [sim-config.c] - Blame information for rev 490

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 428 markom
#include "icache_model.h"
28
#include "dcache_model.h"
29 424 markom
 
30 427 markom
#define WARNING(s) fprintf (stderr, "WARNING: config.%s: %s\n", sections[section].name, (s))
31 428 markom
#define ERROR(s) {fprintf (stderr, "ERROR: config.%s:%s\n", sections[section].name, s); if (runtime.sim.init) exit (1);}
32
#define MERROR(s) {fprintf (stderr, "ERROR: %s\n", s); if (runtime.sim.init) exit (1);}
33 424 markom
 
34
struct config config;
35
struct runtime runtime;
36
 
37
int section = 0;
38
extern struct section {
39
  char *name;
40
  int flags;
41
} sections[];
42
 
43
void init_defconfig()
44
{
45
  int i;
46
 
47
  memset(&config, 0, sizeof(config));
48
  memset(&runtime, 0, sizeof(runtime));
49
  /* Sim */
50
  config.sim.exe_log = 0;
51
  runtime.sim.fexe_log = NULL;
52
  strcpy (config.sim.exe_log_fn, "executed.log");
53
 
54
  config.sim.debug = 0;
55
  config.sim.verbose = 1;
56
  config.sim.iprompt = 0;
57
 
58
  config.sim.profile = 0;
59
  runtime.sim.fprof = NULL;
60
  strcpy (config.sim.prof_fn, "sim.profile");
61
  runtime.sim.init = 1;
62
  runtime.sim.script_file_specified = 0;
63 433 markom
  config.sim.clkcycle_ps = 4000; /* 4000 for 4ns (250MHz) */
64 424 markom
 
65
  /* Memory */
66
  config.memory.type = MT_PATTERN;
67
  config.memory.pattern = 0;
68
  config.memory.random_seed = -1;  /* Generate new seed */
69
  for (i = 0; i < MAX_MEMORIES; i++) {
70
    config.memory.table[i].ce = -1;     /* memory is disabled by default */
71
  }
72
 
73 428 markom
  /* IMMU & DMMU*/
74
  config.immu.enabled = 0;
75
  config.dmmu.enabled = 0;
76
 
77
  /* IC & DC */
78
  config.ic.enabled = 0;
79
  config.ic.tagtype = CT_PHYSICAL/*CT_VIRTUAL*/;
80
  config.dc.enabled = 0;
81
  config.dc.tagtype = CT_PHYSICAL/*CT_VIRTUAL*/;
82
 
83 424 markom
  /* Memory Controller */
84
  config.mc.enabled = 0;
85
 
86
  /* Uarts */
87
  config.nuarts = 0;
88
  config.uarts_enabled = 0;
89
 
90
  /* DMAs */
91
  config.ndmas = 0;
92
  config.dmas_enabled = 0;
93
 
94
  /* CPU */
95
  config.cpu.superscalar = 0;
96
  config.sim.history = 0;
97
  config.cpu.hazards = 0;
98
  config.cpu.dependstats = 0;
99
  config.cpu.slp = 0;
100
  config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP
101
                 | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP
102
                 | SPR_UPR_PMP | SPR_UPR_TTP;
103
 
104
  /* Debug */
105
  config.debug.enabled = 0;
106
  config.debug.gdb_enabled = 0;
107
  config.debug.server_port = 0;
108
 
109
  /* VAPI */
110
  config.vapi.enabled = 0;
111
  strcpy (config.vapi.vapi_fn, "vapi.log");
112
  runtime.vapi.vapi_file = NULL;
113
 
114
  /* Ethernet */
115
  config.ethernets_enabled = 0;
116
 
117 444 erez
  /* GPIO */
118
  config.gpios_enabled = 0;
119
 
120 424 markom
  /* Tick timer */
121
  config.tick.enabled = 0;
122
}
123
 
124
int parse_args(int argc, char *argv[])
125
{
126
  unsigned long val;
127
 
128
  argv++; argc--;
129
  while (argc) {
130
    if (argc && (*argv[0] != '-')) {
131
      runtime.sim.filename = argv[0];
132
      argc--;
133
      argv++;
134
    } else
135
    if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) {
136
      argv++; argc--;
137 481 markom
      if (argv[0]) {
138
        read_script_file(argv[0]);
139
        argv++; argc--;
140
      } else {
141
        fprintf(stderr, "Configure filename not specified!\n");
142
        return 1;
143
      }
144 424 markom
    } else
145
    if (strcmp(*argv, "--nosrv") == 0) {  /* (CZ) */
146
      config.debug.gdb_enabled = 0;
147
      argv++; argc--;
148
    } else
149
    if (strcmp(*argv, "--srv") == 0) {  /* (CZ) */
150
      char *s;
151
      if(!--argc)
152
        return 1;
153
      config.debug.enabled = 1;
154
      config.debug.gdb_enabled = 0;
155
      config.debug.server_port = strtol(*(++argv),&s,10);
156
      if(*s)
157
        return 1;
158
      argv++; argc--;
159
    } else
160
    if (strcmp(*argv, "-i") == 0) {
161
      config.sim.iprompt = 1;
162
      argv++; argc--;
163
    } else
164
    if (strcmp(*argv, "-v") == 0) {
165
      version();
166
      exit(0);
167
    } else
168
    if (strcmp(*argv, "--profile") == 0) {
169
      config.sim.profile = 1;
170
      argv++; argc--;
171
    } else {
172 481 markom
      fprintf(stderr, "Unknown option: %s\n", *argv);
173 424 markom
      return 1;
174
    }
175
  }
176
 
177
  if (!argc)
178
    return 0;
179
 
180
  return 0;
181
}
182
 
183 434 markom
#define CNV(x) ((isspace(x) || (x) == 0) ? ' ' : (x))
184 424 markom
 
185
/* Substitute for less powerful fscanf */
186
int fscanf_ex (FILE *f, char *fmt, void *buf, char *str) {
187
  char tmp[STR_SIZE];
188
  char ch;
189
  int i = 0;
190
  while (*fmt) {
191
    switch (*fmt) {
192
      case '%':
193
        while(*fmt != 0 && !isalpha (*fmt))
194
          tmp[i++] = *(fmt++);
195
        tmp[i++] = *(fmt++);
196
        if (tmp[i - 1] == 's') {
197
          char *cbuf = (char *)buf;
198
          i = 0;
199 434 markom
          while (ch = (f ? fgetc (f) : *str++), isspace(ch))
200 424 markom
            if (f ? feof (f) : *str) return 1;
201 479 markom
          if (f)
202 424 markom
            ungetc (ch, f);
203
          else
204
            str--;
205
          while ((*(cbuf++) = ch = (f ? fgetc (f) : *str++), CNV(ch) ) != *fmt) {
206
            if ((f ? feof (f) : *str)) return 1;
207
            if (++i >= STR_SIZE) {
208
              fprintf (stderr, "ERROR: string too long.\n");
209
              return 1;
210
            }
211
          }
212
          *(--cbuf) = 0;
213
          fmt++;
214
        } else {
215
          tmp[i++] = 0;
216
          if (f)
217
            fscanf (f, tmp, buf);
218
          else
219
            sscanf (str, tmp, buf);
220
        }
221
        break;
222
      default:
223
        while ((ch = (f ? fgetc (f) : *str++)) != *fmt) {
224 434 markom
          if (!isspace (ch)) {
225 424 markom
            char tmp[200];
226
            sprintf (tmp, "unexpected char '%c' (expecting '%c')\n", ch, *fmt);
227 427 markom
            fprintf (stderr, "WARNING: config.%s: %s\n", sections[section], tmp);
228 424 markom
            WARNING(tmp);
229
          }
230
          if ((f ? feof (f) : *str)) return 1;
231
        }
232
        fmt++;
233
        break;
234
    }
235
  }
236
  return 0;
237
}
238
 
239
void print_config()
240
{
241
  if (config.sim.verbose) {
242 433 markom
    char temp[20];
243 424 markom
    printf("Verbose on, ");
244
    if (config.sim.debug)
245
      printf("simdebug on, ");
246
    else
247
      printf("simdebug off, ");
248
    if (config.sim.iprompt)
249
      printf("interactive prompt on\n");
250
    else
251
      printf("interactive prompt off\n");
252
 
253
    printf("Machine initialization...\n");
254 433 markom
    generate_time_pretty (temp, config.sim.clkcycle_ps);
255
    printf("Clock cycle: %s\n", temp);
256 424 markom
    if (testsprbits(SPR_UPR, SPR_UPR_DCP))
257 428 markom
      printf("Data cache tag: %s\n", config.dc.tagtype == CT_VIRTUAL ? "virtual" : "physical");
258 424 markom
    else
259
      printf("No data cache.\n");
260
    if (testsprbits(SPR_UPR, SPR_UPR_ICP))
261 428 markom
      printf("Insn cache tag: %s\n", config.ic.tagtype == CT_VIRTUAL ? "virtual" : "physical");
262 424 markom
    else
263
      printf("No instruction cache.\n");
264
    if (config.cpu.bpb)
265
      printf("BPB simulation on.\n");
266
    else
267
      printf("BPB simulation off.\n");
268
    if (config.cpu.btic)
269
      printf("BTIC simulation on.\n");
270
    else
271
      printf("BTIC simulation off.\n");
272
  }
273
}
274
 
275
/* Forward declarations of functions */
276 433 markom
void sim_clkcycle ();
277 424 markom
void change_device ();
278
void end_device ();
279
void uart_nuarts ();
280
void uart_baseaddr ();
281
void uart_rxfile ();
282
void uart_txfile ();
283
void uart_jitter ();
284
void uart_irq ();
285
void uart_16550 ();
286
void uart_vapi_id ();
287
void dma_ndmas ();
288
void dma_baseaddr ();
289
void dma_irq ();
290
void dma_vapi_id ();
291
void memory_type ();
292
void memory_nmemories ();
293
void memory_ce ();
294
void memory_baseaddr ();
295
void memory_size ();
296
void memory_name ();
297
void memory_log ();
298
void memory_delayr ();
299
void memory_delayw ();
300
void eth_nethernets ();
301
void eth_baseaddr ();
302
void eth_dma ();
303
void eth_rx_channel ();
304
void eth_tx_channel ();
305
void eth_rxfile ();
306
void eth_txfile ();
307
void eth_vapi_id ();
308 444 erez
void gpio_ngpios ();
309
void gpio_baseaddr ();
310
void gpio_irq ();
311 477 erez
void gpio_base_vapi_id ();
312 425 markom
void immu_enabled ();
313
void immu_nsets ();
314
void immu_nways ();
315
void immu_pagesize ();
316
void immu_entrysize ();
317
void immu_ustates ();
318
void dmmu_enabled ();
319
void dmmu_nsets ();
320
void dmmu_nways ();
321
void dmmu_pagesize ();
322
void dmmu_entrysize ();
323
void dmmu_ustates ();
324 428 markom
void ic_enabled ();
325
void ic_nsets ();
326
void ic_nways ();
327
void ic_blocksize ();
328
void ic_ustates ();
329
void ic_tagtype ();
330
void dc_enabled ();
331
void dc_nsets ();
332
void dc_nways ();
333
void dc_blocksize ();
334
void dc_ustates ();
335
void dc_tagtype ();
336 424 markom
 
337
unsigned long tempL;
338
unsigned long tempUL;
339
char tempS[STR_SIZE];
340
 
341
#define CPF_SUBSECTION 1
342
#define CPF_SUBFIELD   2
343
 
344
struct section sections[] = {
345
  {"?",      0},  /* 0  */
346
  {"mc",     0},
347
  {"uart",   0},
348
  {"dma",    0},
349
  {"memory", 0},
350
  {"cpu",    0},
351
  {"sim",    0},
352
  {"debug",  0},
353
  {"VAPI",   0},
354
  {"ethernet",0},
355 425 markom
  {"tick",   0},   /* 10 */
356
  {"immu",   0},
357 428 markom
  {"dmmu",   0},
358
  {"ic",     0},
359 444 erez
  {"dc",     0},
360
  {"gpio",   0}
361 424 markom
};
362
 
363
/* *INDENT-OFF* */
364
 
365
/* Parameter definitions */
366
struct config_params {
367
  int section;
368
  int attr;
369
  char *name;
370
  char *type;
371
  void (*func)();
372
  void *addr;
373
} config_params[] = {
374
{1, 0, "enabled",            "=%i",         NULL,          (void *)(&config.mc.enabled)},
375
{1, 0, "baseaddr",           "=0x%x",       NULL,          (void *)(&config.mc.baseaddr)},
376
{1, 0, "POC",                "=0x%x",       NULL,          (void *)(&config.mc.POC)},
377
 
378
{2, 0, "enabled",            "=%i",         NULL,          (void *)(&config.uarts_enabled)},
379
{2, 0, "nuarts",             "=%i",         uart_nuarts,   (void *)(&tempL)},
380
{2, 0, "device",             "%i",          change_device, (void *)(&tempL)},
381
{2, 0, "enddevice",          "",            end_device,    NULL},
382
{2, 0, "baseaddr",           "=0x%x",       uart_baseaddr, (void *)(&tempUL)},
383
{2, 0, "irq",                "=%i",         uart_irq,      (void *)(&tempL)},
384
{2, 0, "16550",              "=%i",         uart_16550,    (void *)(&tempL)},
385
{2, 0, "jitter",             "=%i",         uart_jitter,   (void *)(&tempL)},
386
{2, 0, "rxfile",             "=\"%s\"",     uart_rxfile,   (void *)(&tempS[0])},
387
{2, 0, "txfile",             "=\"%s\"",     uart_txfile,   (void *)(&tempS[0])},
388
{2, 0, "vapi_id",            "=0x%x",       uart_vapi_id,  (void *)(&tempUL)},
389
 
390
{3, 0, "enabled",            "=%i",         NULL,          (void *)(&config.dmas_enabled)},
391
{3, 0, "ndmas",              "=%i",         dma_ndmas,     (void *)(&tempL)},
392
{3, 0, "device",             "%i",          change_device, (void *)(&tempL)},
393
{3, 0, "enddevice",          "",            end_device,    NULL},
394
{3, 0, "baseaddr",           "=0x%x",       dma_baseaddr,  (void *)(&tempUL)},
395 444 erez
{3, 0, "irq",                "=%i",         dma_irq,       (void *)(&tempL)},
396 424 markom
{3, 0, "vapi_id",            "=0x%x",       dma_vapi_id,   (void *)(&tempUL)},
397
 
398
{4, 0, "random_seed",        "=%i",         NULL,          (void *)(&config.memory.random_seed)},
399
{4, 0, "pattern",            "=%i",         NULL,          (void *)(&config.memory.pattern)},
400
{4, 0, "type",               "=%s ",        memory_type,   (void *)(&tempS[0])},
401
{4, 0, "nmemories",          "=%i",         memory_nmemories,(void *)(&tempL)},
402
{4, 0, "device",             "%i",          change_device, (void *)(&tempL)},
403
{4, 0, "enddevice",          "",            end_device,    NULL},
404
{4, 0, "ce",                 "=%i",         memory_ce,     (void *)(&tempL)},
405
{4, 0, "baseaddr",           "=0x%x",       memory_baseaddr,(void *)(&tempUL)},
406
{4, 0, "size",               "=0x%x",       memory_size,   (void *)(&tempUL)},
407 427 markom
{4, 0, "name",               "=\"%s\"",     memory_name,   (void *)(&tempS[0])},
408
{4, 0, "log",                "=\"%s\"",     memory_log,    (void *)(&tempS[0])},
409 424 markom
{4, 0, "delayr",             "=%i",         memory_delayr, (void *)(&tempL)},
410
{4, 0, "delayw",             "=%i",         memory_delayw, (void *)(&tempL)},
411
 
412
{5, 0, "ver",                "=0x%x",       NULL,          (void *)(&config.cpu.ver)},
413
{5, 0, "rev",                "=0x%x",       NULL,          (void *)(&config.cpu.rev)},
414
{5, 0, "upr",                "=0x%x",       NULL,          (void *)(&config.cpu.upr)},
415
{5, 0, "hazards",            "=%i",         NULL,          (void *)(&config.cpu.hazards)},
416
{5, 0, "superscalar",        "=%i",         NULL,          (void *)(&config.cpu.superscalar)},
417
{5, 0, "dependstats",        "=%i",         NULL,          (void *)(&config.cpu.dependstats)},
418
{5, 0, "slp",                "=%i",         NULL,          (void *)(&config.cpu.slp)},
419
{5, 0, "bpb",                "=%i",         NULL,          (void *)(&config.cpu.bpb)},
420
{5, 0, "btic",               "=%i",         NULL,          (void *)(&config.cpu.btic)},
421
 
422
{6, 0, "debug",              "=%i",         NULL,          (void *)(&config.sim.debug)},
423
{6, 0, "iprompt",            "=%i",         NULL,          (void *)(&config.sim.iprompt)},
424
{6, 0, "verbose",            "=%i",         NULL,          (void *)(&config.sim.verbose)},
425
{6, 0, "profile",            "=%i",         NULL,          (void *)(&config.sim.profile)},
426
{6, 0, "prof_fn",            "=\"%s\"",     NULL,          (void *)(&config.sim.prof_fn[0])},
427
{6, 0, "history",            "=%i",         NULL,          (void *)(&config.sim.history)},
428
{6, 0, "exe_log",            "=%i",         NULL,          (void *)(&config.sim.exe_log)},
429
{6, 0, "exe_log_fn",         "=\"%s\"",     NULL,          (void *)(&config.sim.exe_log_fn[0])},
430 433 markom
{6, 0, "clkcycle",           "=%s ",        sim_clkcycle,  (void *)(&tempS[0])},
431 424 markom
 
432
{7, 0, "enabled",            "=%i",         NULL,          (void *)(&config.debug.enabled)},
433
{7, 0, "gdb_enabled",        "=%i",         NULL,          (void *)(&config.debug.gdb_enabled)},
434
{7, 0, "server_port",        "=%i",         NULL,          (void *)(&config.debug.server_port)},
435 439 erez
{7, 0, "vapi_id",            "=0x%x",       NULL,          (void *)(&config.debug.vapi_id)},
436 424 markom
 
437
{8, 0, "enabled",            "=%i",         NULL,          (void *)(&config.vapi.enabled)},
438
{8, 0, "server_port",        "=%i",         NULL,          (void *)(&config.vapi.server_port)},
439
{8, 0, "log_enabled",        "=%i",         NULL,          (void *)(&config.vapi.log_enabled)},
440 477 erez
{8, 0, "hide_device_id",     "=%i",         NULL,          (void *)(&config.vapi.hide_device_id)},
441 424 markom
{8, 0, "vapi_log_fn",        "=\"%s\"",     NULL,          (void *)(&config.vapi.vapi_fn[0])},
442
 
443
{9, 0, "enabled",            "=%i",         NULL,          (void *)(&config.ethernets_enabled)},
444
{9, 0, "nethernets",         "=%i",         eth_nethernets,(void *)(&tempL)},
445
{9, 0, "device",             "%i",          change_device, (void *)(&tempL)},
446
{9, 0, "enddevice",          "",            end_device,    NULL},
447
{9, 0, "baseaddr",           "=0x%x",       eth_baseaddr,  (void *)(&tempUL)},
448
{9, 0, "dma",                "=%i",         eth_dma,       (void *)(&tempL)},
449
{9, 0, "rx_channel",         "=%i",         eth_rx_channel,(void *)(&tempL)},
450
{9, 0, "tx_channel",         "=%i",         eth_tx_channel,(void *)(&tempL)},
451
{9, 0, "rxfile",             "=\"%s\"",     eth_rxfile,    (void *)(&tempS[0])},
452
{9, 0, "txfile",             "=\"%s\"",     eth_txfile,    (void *)(&tempS[0])},
453
{9, 0, "vapi_id",            "=0x%x",       eth_vapi_id,   (void *)(&tempUL)},
454
 
455
{10,0, "enabled",            "=%i",         NULL,          (void *)(&config.tick.enabled)},
456
{10,0, "irq",                "=%i",         NULL,          (void *)(&config.tick.irq)},
457 425 markom
 
458
{11,0, "enabled",            "=%i",         immu_enabled,  (void *)(&tempL)},
459
{11,0, "nsets",              "=%i",         immu_nsets,    (void *)(&tempL)},
460
{11,0, "nways",              "=%i",         immu_nways,    (void *)(&tempL)},
461
{11,0, "pagesize",           "=%i",         immu_pagesize, (void *)(&tempL)},
462
{11,0, "entrysize",          "=%i",         immu_entrysize,(void *)(&tempL)},
463
{11,0, "ustates",            "=%i",         immu_ustates,  (void *)(&tempL)},
464
 
465
{12,0, "enabled",            "=%i",         dmmu_enabled,  (void *)(&tempL)},
466
{12,0, "nsets",              "=%i",         dmmu_nsets,    (void *)(&tempL)},
467
{12,0, "nways",              "=%i",         dmmu_nways,    (void *)(&tempL)},
468
{12,0, "pagesize",           "=%i",         dmmu_pagesize, (void *)(&tempL)},
469
{12,0, "entrysize",          "=%i",         dmmu_entrysize,(void *)(&tempL)},
470 428 markom
{12,0, "ustates",            "=%i",         dmmu_ustates,  (void *)(&tempL)},
471
 
472
{13,0, "enabled",            "=%i",         ic_enabled,    (void *)(&tempL)},
473
{13,0, "nsets",              "=%i",         ic_nsets,      (void *)(&tempL)},
474
{13,0, "nways",              "=%i",         ic_nways,      (void *)(&tempL)},
475
{13,0, "blocksize",          "=%i",         ic_blocksize,  (void *)(&tempL)},
476
{13,0, "ustates",            "=%i",         ic_ustates,    (void *)(&tempL)},
477
{13,0, "tagtype",            "=%s ",        ic_tagtype,    (void *)(&tempS)},
478
 
479
{14,0, "enabled",            "=%i",         dc_enabled,    (void *)(&tempL)},
480
{14,0, "nsets",              "=%i",         dc_nsets,      (void *)(&tempL)},
481
{14,0, "nways",              "=%i",         dc_nways,      (void *)(&tempL)},
482
{14,0, "blocksize",          "=%i",         dc_blocksize,  (void *)(&tempL)},
483
{14,0, "ustates",            "=%i",         dc_ustates,    (void *)(&tempL)},
484 444 erez
{14,0, "tagtype",            "=%s ",        dc_tagtype,    (void *)(&tempS)},
485
 
486
{15,0, "enabled",            "=%i",         NULL,          (void *)(&config.gpios_enabled)},
487
{15,0, "ngpios",             "=%i",         gpio_ngpios,    (void *)(&tempL)},
488
{15,0, "device",             "%i",          change_device, (void *)(&tempL)},
489
{15,0, "baseaddr",           "=0x%x",       gpio_baseaddr, (void *)(&tempUL)},
490
{15,0, "irq",                "=%i",         gpio_irq,      (void *)(&tempL)},
491 477 erez
{15,0, "base_vapi_id",       "=0x%x",       gpio_base_vapi_id,   (void *)(&tempUL)}
492 424 markom
};
493
 
494
/* *INDENT-ON* */
495
 
496
int current_device = -1;
497
void change_device () {
498
  current_device = tempL;
499
}
500
 
501
void end_device () {
502
  current_device = -1;
503
}
504
 
505 433 markom
void sim_clkcycle () {
506
  int len = strlen (tempS);
507
  int pos = len - 1;
508
  long time;
509
  if (len < 2) goto err;
510
  if (tempS[pos--] != 's') goto err;
511
  switch (tempS[pos--]) {
512
    case 'p': time = 1; break;
513
    case 'n': time = 1000; break;
514
    case 'u': time = 1000000; break;
515
    case 'm': time = 1000000000; break;
516
  default:
517
    goto err;
518
  }
519 490 markom
  tempS[pos + 1] = 0;
520 433 markom
  config.sim.clkcycle_ps = time * atol (tempS);
521
  return;
522
err:
523
  ERROR("invalid time format.");
524
}
525
 
526 424 markom
void uart_nuarts () {
527
  if (tempL >= 0 && tempL < MAX_UARTS)
528
    config.nuarts = tempL;
529
  else
530
    ERROR("invalid number of devices.");
531
}
532
 
533
void uart_baseaddr () {
534
  if (current_device >= 0 && current_device < config.nuarts)
535
    config.uarts[current_device].baseaddr = tempUL;
536
  else
537
    ERROR("invalid device number.");
538
}
539
 
540
void uart_jitter () {
541
  if (current_device >= 0 && current_device < config.nuarts)
542
    config.uarts[current_device].jitter = tempL;
543
  else
544
    ERROR("invalid device number.");
545
}
546
 
547
void uart_irq () {
548
  if (current_device >= 0 && current_device < config.nuarts)
549
    config.uarts[current_device].irq = tempL;
550
  else
551
    ERROR("invalid device number.");
552
}
553
 
554
void uart_16550 () {
555
  if (current_device >= 0 && current_device < config.nuarts)
556
    config.uarts[current_device].uart16550 = tempL;
557
  else
558
    ERROR("invalid device number.");
559
}
560
 
561
void uart_rxfile () {
562
  if (current_device >= 0 && current_device < config.nuarts)
563
    strcpy (config.uarts[current_device].rxfile, tempS);
564
  else
565
    ERROR("invalid device number.");
566
}
567
 
568
void uart_txfile () {
569
  if (current_device >= 0 && current_device < config.nuarts)
570
    strcpy (config.uarts[current_device].txfile, tempS);
571
  else
572
    ERROR("invalid device number.");
573
}
574
 
575
void uart_vapi_id () {
576
  if (current_device >= 0 && current_device < config.nuarts)
577
    config.uarts[current_device].vapi_id = tempUL;
578
  else
579
    ERROR("invalid device number.");
580
}
581
 
582
void dma_ndmas () {
583
  if (tempL >= 0 && tempL < MAX_DMAS)
584
    config.ndmas = tempL;
585
  else
586
    ERROR("invalid number of devices.");
587
}
588
 
589
void dma_baseaddr () {
590
  if (current_device >= 0 && current_device < config.ndmas)
591
    config.dmas[current_device].baseaddr = tempUL;
592
  else
593
    ERROR("invalid device number.");
594
}
595
 
596
void dma_irq () {
597
  if (current_device >= 0 && current_device < config.ndmas)
598
    config.dmas[current_device].irq = tempL;
599
  else
600
    ERROR("invalid device number.");
601
}
602
 
603
void dma_vapi_id () {
604
  if (current_device >= 0 && current_device < config.ndmas)
605
    config.dmas[current_device].vapi_id = tempUL;
606
  else
607
    ERROR("invalid device number.");
608
}
609
 
610
void memory_nmemories () {
611
  if (tempL >= 0 && tempL < MAX_MEMORIES)
612
    config.memory.nmemories = tempL;
613
  else
614
    ERROR("invalid number of devices.");
615
}
616
 
617
void memory_type () {
618
  if (strcmp (tempS, "unknown") == 0)
619
    config.memory.type = MT_UNKNOWN;
620
  else if (strcmp (tempS, "random") == 0)
621
    config.memory.type = MT_RANDOM;
622
  else if (strcmp (tempS, "pattern") == 0)
623
    config.memory.type = MT_PATTERN;
624
  else if (strcmp (tempS, "zero") == 0) {
625
    config.memory.type = MT_PATTERN;
626
    config.memory.pattern = 0;
627
  } else {
628
    char tmp[200];
629
    sprintf (tmp, "invalid memory type '%s'.\n", tempS);
630
    ERROR(tmp);
631
  }
632
}
633
 
634
void memory_ce () {
635
  if (current_device >= 0 && current_device < config.memory.nmemories)
636
    config.memory.table[current_device].ce = tempL;
637
  else
638
    ERROR("invalid device number.");
639
}
640
 
641
void memory_baseaddr () {
642
  if (current_device >= 0 && current_device < config.memory.nmemories)
643
    config.memory.table[current_device].baseaddr = tempUL;
644
  else
645
    ERROR("invalid device number.");
646
}
647
 
648
void memory_size () {
649
  if (current_device >= 0 && current_device < config.memory.nmemories)
650
    config.memory.table[current_device].size = tempUL;
651
  else
652
    ERROR("invalid device number.");
653
}
654
 
655
void memory_name () {
656
  if (current_device >= 0 && current_device < config.memory.nmemories)
657
    strcpy (config.memory.table[current_device].name, tempS);
658
  else
659
    ERROR("invalid device number.");
660
}
661
 
662
void memory_log () {
663
  if (current_device >= 0 && current_device < config.memory.nmemories)
664
    strcpy (config.memory.table[current_device].log, tempS);
665
  else
666
    ERROR("invalid device number.");
667
}
668
 
669
void memory_delayr () {
670
  if (current_device >= 0 && current_device < config.memory.nmemories)
671
    config.memory.table[current_device].delayr = tempL;
672
  else
673
    ERROR("invalid device number.");
674
}
675
 
676
void memory_delayw () {
677
  if (current_device >= 0 && current_device < config.memory.nmemories)
678
    config.memory.table[current_device].delayw = tempL;
679
  else
680
    ERROR("invalid device number.");
681
}
682
 
683
void eth_nethernets () {
684
  if (tempL >= 0 && tempL < MAX_ETHERNETS)
685
    config.nethernets = tempL;
686
  else
687
    ERROR("invalid number of devices.");
688
}
689
 
690
void eth_baseaddr () {
691
  if (current_device >= 0 && current_device < config.nethernets)
692
    config.ethernets[current_device].baseaddr = tempUL;
693
  else
694
    ERROR("invalid device number.");
695
}
696
 
697
void eth_dma () {
698
  if (current_device >= 0 && current_device < config.nethernets)
699
    config.ethernets[current_device].dma = tempL;
700
  else
701
    ERROR("invalid device number.");
702
}
703
 
704
void eth_rx_channel () {
705
  if (current_device >= 0 && current_device < config.nethernets)
706
    config.ethernets[current_device].rx_channel = tempL;
707
  else
708
    ERROR("invalid device number.");
709
}
710
 
711
void eth_tx_channel () {
712
  if (current_device >= 0 && current_device < config.nethernets)
713
    config.ethernets[current_device].rx_channel = tempL;
714
  else
715
    ERROR("invalid device number.");
716
}
717
 
718
void eth_rxfile () {
719
  if (current_device >= 0 && current_device < config.nethernets)
720
    strcpy (config.ethernets[current_device].rxfile, tempS);
721
  else
722
    ERROR("invalid device number.");
723
}
724
 
725
void eth_txfile () {
726
  if (current_device >= 0 && current_device < config.nethernets)
727
    strcpy (config.ethernets[current_device].txfile, tempS);
728
  else
729
    ERROR("invalid device number.");
730
}
731
 
732
void eth_vapi_id () {
733
  if (current_device >= 0 && current_device < config.nethernets)
734
    config.ethernets[current_device].vapi_id = tempUL;
735
  else
736 425 markom
    ERROR("invalid device number.");
737 424 markom
}
738
 
739 444 erez
void gpio_ngpios () {
740
  if (tempL >= 0 && tempL < MAX_GPIOS)
741
    config.ngpios = tempL;
742
  else
743
    ERROR("invalid number of devices.");
744
}
745
 
746
void gpio_baseaddr () {
747
  if (current_device >= 0 && current_device < config.ngpios)
748
    config.gpios[current_device].baseaddr = tempUL;
749
  else
750
    ERROR("invalid device number.");
751
}
752
 
753
void gpio_irq () {
754
  if (current_device >= 0 && current_device < config.ngpios)
755
    config.gpios[current_device].irq = tempL;
756
  else
757
    ERROR("invalid device number.");
758
}
759
 
760 477 erez
void gpio_base_vapi_id () {
761 444 erez
  if (current_device >= 0 && current_device < config.ngpios)
762 477 erez
    config.gpios[current_device].base_vapi_id = tempUL;
763 444 erez
  else
764
    ERROR("invalid device number.");
765
}
766
 
767 425 markom
int is_power2 (int x) {
768
  while (!(x & 1))
769
    x >>= 1;
770
  return x == 1;
771
}
772 424 markom
 
773 425 markom
void immu_enabled () {
774
  setsprbits (SPR_UPR, SPR_UPR_IMP, tempL & 1);
775
}
776 424 markom
 
777 425 markom
void dmmu_enabled () {
778
  setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1);
779
}
780
 
781
void immu_nsets () {
782
  if (is_power2(tempL) && tempL <= 256)
783
    config.immu.nsets = tempL;
784
  else
785 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
786 425 markom
}
787
 
788
void dmmu_nsets () {
789
  if (is_power2(tempL) && tempL <= 256)
790
    config.dmmu.nsets = tempL;
791
  else
792 428 markom
    ERROR("value of power of two and lower or equal than 256 expected.");
793 425 markom
}
794
 
795
void immu_nways () {
796
  if (tempL >= 1 && tempL <= 4)
797
    config.immu.nways = tempL;
798
  else
799
    ERROR("value 1, 2, 3 or 4 expected.");
800
}
801
 
802
void dmmu_nways () {
803
  if (tempL >= 1 && tempL <= 4)
804
    config.dmmu.nways = tempL;
805
  else
806
    ERROR("value 1, 2, 3 or 4 expected.");
807
}
808
 
809
void immu_pagesize () {
810
  if (is_power2(tempL))
811
    config.immu.pagesize = tempL;
812
  else
813 428 markom
    ERROR("value of power of two expected.");
814 425 markom
}
815
 
816
void dmmu_pagesize () {
817
  if (is_power2(tempL))
818
    config.dmmu.pagesize = tempL;
819
  else
820 428 markom
    ERROR("value of power of two expected.");
821 425 markom
}
822
 
823
void immu_entrysize () {
824
  if (is_power2(tempL))
825
    config.immu.entrysize = tempL;
826
  else
827 428 markom
    ERROR("value of power of two expected.");
828 425 markom
}
829
 
830
void dmmu_entrysize () {
831
  if (is_power2(tempL))
832
    config.dmmu.entrysize = tempL;
833
  else
834 428 markom
    ERROR("value of power of two expected.");
835 425 markom
}
836
 
837
void immu_ustates () {
838
  if (tempL >= 2 && tempL <= 4)
839
    config.immu.ustates = tempL;
840
  else
841
    ERROR("invalid USTATE.");
842
}
843
 
844
void dmmu_ustates () {
845
  if (tempL >= 2 && tempL <= 4)
846
    config.dmmu.ustates = tempL;
847
  else
848
    ERROR("invalid USTATE.");
849
}
850
 
851 428 markom
void ic_enabled () {
852
  setsprbits (SPR_UPR, SPR_UPR_ICP, tempL & 1);
853
}
854
 
855
void ic_nsets () {
856
  if (is_power2(tempL) && tempL <= MAX_IC_SETS)
857
    config.ic.nsets = tempL;
858
  else {
859
    char tmp[200];
860
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_IC_SETS);
861
    ERROR(tmp);
862
  }
863
}
864
 
865
void ic_nways () {
866
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
867
    config.ic.nways = tempL;
868
  else
869
    ERROR("value 1, 2, 3 or 4 expected.");
870
}
871
 
872
void ic_blocksize () {
873
  if (is_power2(tempL))
874
    config.ic.blocksize = tempL;
875
  else
876
    ERROR("value of power of two expected.");
877
}
878
 
879
void ic_ustates () {
880
  if (tempL >= 2 && tempL <= 4)
881
    config.ic.ustates = tempL;
882
  else
883
    ERROR("invalid USTATE.");
884
}
885
 
886
void ic_tagtype () {
887
  if (strcmp (tempS, "none") == 0)
888
    config.ic.tagtype = CT_NONE;
889
  else if (strcmp (tempS, "physical") == 0)
890
    config.ic.tagtype = CT_PHYSICAL;
891
  else if (strcmp (tempS, "virtual") == 0)
892
    config.ic.tagtype = CT_VIRTUAL;
893
  else {
894
    char tmp[200];
895
    sprintf (tmp, "invalid cache type '%s'.\n", tempS);
896
    ERROR(tmp);
897
  }
898
}
899
 
900
void dc_enabled () {
901
  setsprbits (SPR_UPR, SPR_UPR_DCP, tempL & 1);
902
}
903
 
904
void dc_nsets () {
905
  if (is_power2(tempL) && tempL <= MAX_DC_SETS)
906
    config.dc.nsets = tempL;
907
  else {
908
    char tmp[200];
909
    sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
910
    ERROR(tmp);
911
  }
912
}
913
 
914
void dc_nways () {
915
  if (tempL >= 1 && tempL <= MAX_IC_WAYS)
916
    config.dc.nways = tempL;
917
  else
918
    ERROR("value 1, 2, 3 or 4 expected.");
919
}
920
 
921
void dc_blocksize () {
922
  if (is_power2(tempL))
923
    config.dc.blocksize = tempL;
924
  else
925
    ERROR("value of power of two expected.");
926
}
927
 
928
void dc_ustates () {
929
  if (tempL >= 2 && tempL <= 4)
930
    config.dc.ustates = tempL;
931
  else
932
    ERROR("invalid USTATE.");
933
}
934
 
935
void dc_tagtype () {
936
  if (strcmp (tempS, "none") == 0)
937
    config.dc.tagtype = CT_NONE;
938
  else if (strcmp (tempS, "physical") == 0)
939
    config.dc.tagtype = CT_PHYSICAL;
940
  else if (strcmp (tempS, "virtual") == 0)
941
    config.dc.tagtype = CT_VIRTUAL;
942
  else {
943
    char tmp[200];
944
    sprintf (tmp, "invalid cache type '%s'.\n", tempS);
945
    ERROR(tmp);
946
  }
947
}
948
 
949 424 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
950
   The syntax of script file is:
951
   param = value
952
   section x
953
     data
954
     param = value
955
   end
956
 
957
   Example:
958
   section mc
959
     memory_table_file = sim.mem
960
     enable = 1
961
     POC = 0x47892344
962
   end
963
 
964
 */
965
 
966
void read_script_file (char *filename)
967
{
968
  FILE *f;
969
  unsigned long memory_needed = 0;
970
  char *home = getenv("HOME");
971
  char ctmp[STR_SIZE];
972
  int local = 1;
973
  section = 0;
974
 
975
  sprintf(ctmp, "%s/.or1k/%s", home, filename);
976
  if ((f = fopen (filename, "rt")) != NULL
977
      || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
978
    unsigned long start, length;
979
    char type[STR_SIZE];
980
    int nparam;
981
    int rd, wd;
982
    if (config.sim.verbose)
983 428 markom
      printf ("Reading script file from '%s'...\n", local ? filename : ctmp);
984 424 markom
    while (!feof(f)) {
985
      char param[STR_SIZE];
986
      if (fscanf(f, "%s ", &param) != 1) break;
987
      /* Is this a sections? */
988
      if (strcmp (param, "section") == 0) {
989
        int i;
990
        section = 0;
991
        if (fscanf (f, "%s\n", &param) != 1) {
992
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
993
          exit (1);
994
        }
995
        for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
996
          if (strcmp (sections[i].name, param) == 0) {
997
            section = i;
998
            break;
999
          }
1000
        if (!section) {
1001
          char tmp[200];
1002
          sprintf (tmp, "Unknown section: %s; ignoring.", param);
1003
          WARNING(tmp);
1004
          /* just skip section */
1005
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
1006
        }
1007
      } else if (strcmp (param, "end") == 0) {
1008
        section = 0;
1009
      } else if (strncmp (param, "/*", 2) == 0) {
1010
        char c0 = 0, c1 = 0;
1011
        while (c0 != '*' || c1 != '/') {
1012
          c0 = c1;
1013
          c1 = fgetc(f);
1014
          if (feof(f)) {
1015
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
1016
            exit (1);
1017
          }
1018
        }
1019
      } else {
1020
        int i, found = -1;
1021
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1022
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
1023
            found = i;
1024
            break;
1025
          }
1026
        if (found < 0) {
1027
          char tmp[200];
1028
          sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param);
1029
          WARNING(tmp);
1030
          while (fgetc(f) != '\n' || feof(f));
1031
          continue;
1032
        }
1033
 
1034
        /* Parse parameter value */
1035
        {
1036
          if (config_params[found].type[0])
1037
            if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0))
1038
              exit (1);
1039
        }
1040
        if (config_params[found].func)
1041
          config_params[found].func();
1042
      }
1043
    }
1044
    fclose (f);
1045
    runtime.sim.script_file_specified = 1;
1046
  } else
1047
    if (config.sim.verbose)
1048
      fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp);
1049
}
1050
 
1051
/* Utility for execution of set sim command.  */
1052
static int set_config (char *s)
1053
{
1054
  char *sec, *item, *params;
1055
  int noparams = 0, i, noitem = 0;
1056 434 markom
  while (*s && isspace (*s)) s++;
1057 424 markom
  sec = s;
1058
  printf ("s:%s\n", s);
1059
  while (*s && *s != ' ') s++;
1060
  if (!(*s)) noitem = 1;
1061
  *s = 0;
1062
  printf ("sec:%s\n", sec);
1063
  section = 0;
1064
  for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1065
    if (strcmp (sections[i].name, sec) == 0) {
1066
      section = i;
1067
      break;
1068
    }
1069
 
1070
  if (!section) return 1;
1071
  if (noitem) return 2;
1072
 
1073
  item = ++s;
1074
 
1075
  while (*s && *s != ' ') s++;
1076
  if (!(*s)) {
1077
    noparams = 1;
1078
    params = "";
1079
  } else
1080
    params = s + 1;
1081
  *s = 0;
1082
  printf ("item:%s\n", item);
1083
  printf ("params:%s\n", params);
1084
  {
1085
    int i, found = -1;
1086
    for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1087
      if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) {
1088
        found = i;
1089
        break;
1090
      }
1091
    if (found < 0) return 2;
1092
 
1093
    /* Parse parameter value */
1094
    if (config_params[found].type[0])
1095
      if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params))
1096
        return 3;
1097
    if (config_params[found].func)
1098
      config_params[found].func();
1099
  }
1100
  return 0;
1101
}
1102
 
1103
/* Executes set sim command, displays error.  */
1104
void set_config_command(char *s)
1105
{
1106
  int i;
1107
  switch (set_config (s)) {
1108
    case 1:
1109
      printf ("Invalid or missing section name.  One of valid sections must be specified:\n");
1110
      for (i = 1; i < sizeof(sections) / sizeof(struct section); i++)
1111
        printf ("%s ", sections[i].name);
1112
      printf ("\n");
1113
      break;
1114
    case 2:
1115
      printf ("Invalid or missing item name.  One of valid items must be specified:\n");
1116
      for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
1117
        if (config_params[i].section == section)
1118
          printf ("%s ", config_params[i].name);
1119
      printf ("\n");
1120
      break;
1121
    case 3:
1122
      printf ("Invalid parameters specified.\n");
1123
      break;
1124
  }
1125
}

powered by: WebSVN 2.1.0

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