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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_68/] [or1ksim/] [sim-config.c] - Blame information for rev 479

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

powered by: WebSVN 2.1.0

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