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 541

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

powered by: WebSVN 2.1.0

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