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 261

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 jrydberg
/* 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 239 markom
#include <stdlib.h>
23 7 jrydberg
#include "sim-config.h"
24 30 lampret
#include "abstract.h"
25 103 lampret
#include "spr_defs.h"
26 230 erez
#include "pic.h"
27 7 jrydberg
 
28
struct config config;
29
 
30
void init_defconfig()
31
{
32 239 markom
  unsigned long val;
33
 
34
  memset(&config, 0, sizeof(config));
35
  config.dc.tagtype = NONE/*VIRTUAL*/;
36
  config.ic.tagtype = NONE/*VIRTUAL*/;
37
  config.bp.bpb_sim = 1;
38
  config.bp.btic_sim = 1;
39
  config.clkcycle_ns = 4; /* 4 for 4ns (250MHz) */
40 261 markom
  strcpy (config.uarts[0].rxfile, "/tmp/uart0.rx");
41
  strcpy (config.uarts[0].txfile, "/tmp/uart0.tx");
42 239 markom
  config.uarts[0].baseaddr = 0x80000000;
43
  config.uarts[0].jitter = -1; /* Async behavior */
44
  config.dmas[0].baseaddr = 0x90000000;
45
  config.dmas[0].irq = INT_DMA;
46 257 erez
        config.ethernets[0].baseaddr = 0x88000000;
47
        config.ethernets[0].dma = 0;
48
        config.ethernets[0].tx_channel = 0;
49
        config.ethernets[0].rx_channel = 1;
50
        config.ethernets[0].rxfile = "/tmp/eth0.rx";
51
        config.ethernets[0].txfile = "/tmp/eth0.tx";
52 239 markom
  config.simdebug = 0;
53
  config.profile = 0;
54
  config.iprompt = 0;
55
  config.dependstats = 1;
56
  config.dependency = 1;
57
  config.history = 1;
58
  config.superscalar = 1;
59
  config.slp = 1;
60
  config.profile = 0;
61 261 markom
 
62
  config.mc.enabled = 0;
63 240 markom
  strcpy(config.mc.memory_table_file, "sim.mem");
64 103 lampret
 
65 239 markom
  mtspr(SPR_VR, SPR_VR_VER & 0x1200);
66 103 lampret
 
67 239 markom
  val = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP |
68
  SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP |
69
  SPR_UPR_PMP | SPR_UPR_TTP;
70 103 lampret
 
71 239 markom
  mtspr(SPR_UPR, val);
72 103 lampret
}
73
 
74
int parse_args(int argc, char *argv[])
75
{
76 239 markom
  unsigned long val;
77
 
78
  argv++; argc--;
79
  while (argc) {
80
    if (argc && (*argv[0] != '-')) {
81
      config.filename = argv[0];
82
      argc--;
83
      argv++;
84 242 markom
    } else
85 239 markom
    if (strcmp(*argv, "-initmem") == 0) {  /* (CZ) */
86
      char *pattern,*s;
87
      if(!--argc)
88
        return 1;
89
      pattern = *(++argv);
90
      if(!strcmp(pattern,"random"))
91
        config.random_mem = 1;
92
      else
93
        {
94
          val = strtol(pattern,&s,0);
95
          if(*s)
96
            return 1;
97
          config.pattern_mem = val;
98
        }
99
    } else
100
    if (strcmp(*argv, "-nosrv") == 0) {  /* (CZ) */
101
      config.inhibit_server = 1;
102
      argv++; argc--;
103
    } else
104
    if (strcmp(*argv, "-srv") == 0) {  /* (CZ) */
105
      char *s;
106
      if(!--argc)
107
        return 1;
108
      config.server_port = strtol(*(++argv),&s,10);
109
      if(*s)
110
        return 1;
111
      argv++; argc--;
112
    } else
113
    if (strcmp(*argv, "-i") == 0) {
114
      config.iprompt = 1;
115
      argv++; argc--;
116
    } else
117
    if (strcmp(*argv, "-v") == 0) {
118
      version();
119
      exit(0);
120
    } else
121
    if (strcmp(*argv, "-bpb") == 0) {
122
      config.bp.bpb_sim = 0;
123
      argv++; argc--;
124
    } else
125
    if (strcmp(*argv, "-hazards") == 0) {
126
      config.dependstats = 0;
127
      config.dependency = 0;
128
      argv++; argc--;
129
    } else
130
    if (strcmp(*argv, "-history") == 0) {
131
      config.history = 0;
132
      argv++; argc--;
133
    } else
134
    if (strcmp(*argv, "-superscalar") == 0) {
135
      config.superscalar = 0;
136
      argv++; argc--;
137
    } else
138
    if (strcmp(*argv, "-fast") == 0) {
139
      config.superscalar = 0;
140
      config.history = 0;
141
      config.dependstats = 0;
142
      config.dependency = 0;
143
      config.bp.bpb_sim = 0;
144
      config.bp.btic_sim = 0;
145
      config.slp = 0;
146
      argv++; argc--;
147
    } else
148
    if (strcmp(*argv, "-btic") == 0) {
149
      config.bp.btic_sim = 0;
150
      argv++; argc--;
151
    } else
152
    if (strcmp(*argv, "-upr") == 0) {
153
      argv++; argc--;
154
      val = strtoul(*argv, NULL, 0);
155
      mtspr(SPR_UPR, val);
156
      argv++; argc--;
157
    } else
158
    if (strcmp(*argv, "-ver") == 0) {
159
      argv++; argc--;
160
      val = strtoul(*argv, NULL, 0);
161
      setsprbits(SPR_VR, SPR_VR_VER, val);
162
      argv++; argc--;
163
    } else
164
    if (strcmp(*argv, "-rev") == 0) {
165
      argv++; argc--;
166
      val = strtoul(*argv, NULL, 0);
167
      setsprbits(SPR_VR, SPR_VR_REV, val);
168
      argv++; argc--;
169
    } else
170
    if (strcmp(*argv, "-profile") == 0) {
171
      config.profile = 1;
172
      argv++; argc--;
173
    } else {
174
      printf("Unknown option: %s\n", *argv);
175
      return 1;
176
    }
177
  }
178
 
179
  if (!argc)
180
    return 0;
181
 
182
  return 0;
183
}
184 123 markom
 
185 239 markom
void print_config()
186
{
187
  printf("Machine initialization...\n");
188
  if (testsprbits(SPR_UPR, SPR_UPR_DCP))
189
    printf("Data cache tag: %s\n", config.dc.tagtype == VIRTUAL ? "virtual" : "physical");
190
  else
191
    printf("No data cache.\n");
192
  if (testsprbits(SPR_UPR, SPR_UPR_ICP))
193
    printf("Insn cache tag: %s\n", config.ic.tagtype == VIRTUAL ? "virtual" : "physical");
194
  else
195
    printf("No instruction cache.\n");
196
  if (config.bp.bpb_sim)
197
    printf("BPB simulation on.\n");
198
  else
199
    printf("BPB simulation off.\n");
200
  if (config.bp.btic_sim)
201
    printf("BTIC simulation on.\n");
202
  else
203
    printf("BTIC simulation off.\n");
204
  printf("Clock cycle: %d ns\n", config.clkcycle_ns);
205
  /*printf("RAM: 0x%x to 0x%x (%d KB)\n\n", config.ram.startaddr, config.ram.endaddr);
206
    (config.ram.endaddr - config.ram.startaddr) / 1024); MM170901 different memory scheme.  */
207
 
208
  if (config.simdebug)
209
    printf("simdebug on, ");
210
  else
211
    printf("simdebug off, ");
212
  if (config.iprompt)
213
    printf("interactive prompt on\n");
214
  else
215
    printf("interactive prompt off\n");
216
}
217 123 markom
 
218 261 markom
void change_device ();
219
void end_device ();
220
void uart_baseaddr ();
221
void uart_rxfile ();
222
void uart_txfile ();
223
void uart_jitter ();
224
void dma_baseaddr ();
225
void dma_irq ();
226 123 markom
 
227 239 markom
char memory_file[256] = "sim.mem";
228 123 markom
 
229 261 markom
#define SF_SUBSECTIONS 1
230
#define SF_REQUIRED    2
231
 
232
struct section {
233
  char *name;
234
  int flags;
235
} sections[] = {
236
  {"",       0},
237
  {"mc",     0},
238
  {"uart",   0},
239
  {"dma",    0}
240 239 markom
};
241
 
242 261 markom
unsigned long tempL;
243
unsigned long tempUL;
244
char tempS[STR_SIZE];
245
 
246
#define CPF_SUBSECTION 1
247
#define CPF_SUBFIELD   2
248
 
249 239 markom
/* Parameter definitions */
250
struct config_params {
251
  int section;
252
  char *name;
253
  char *type;
254 261 markom
  void (*func)();
255
  void *addr;
256 239 markom
} config_params[] = {
257 261 markom
  {1, "enabled",            "= %i",        NULL,          (void *)(&config.mc.enabled)},
258
  {1, "baseaddr",           "= 0x%x",      NULL,          (void *)(&config.mc.baseaddr)},
259
  {1, "memory_table_file",  "= \"%255s\"", NULL,          (void *)(&config.mc.memory_table_file[0])},
260
  {1, "POC",                "= 0x%x",      NULL,          (void *)(&config.mc.POC)},
261
 
262
  {2, "enabled",            "= %i",        NULL,          (void *)(&config.uarts_enabled)},
263
  {2, "nuarts",             "= %i",        NULL,          (void *)(&config.nuarts)},
264
  {2, "device",             "%i",          change_device, (void *)(&tempL)},
265
  {2, "enddevice",          "",            end_device,    NULL},
266
  {2, "baseaddr",           "= 0x%x",      uart_baseaddr, (void *)(&tempUL)},
267
  {2, "jitter",             "= %i",        uart_jitter,   (void *)(&tempL)},
268
  {2, "rxfile",             "= \"%255s\"", uart_rxfile,   (void *)(&tempS[0])},
269
  {2, "txfile",             "= \"%255s\"", uart_txfile,   (void *)(&tempS[0])},
270
 
271
  {3, "enabled",            "= %i",        NULL,          (void *)(&config.dmas_enabled)},
272
  {3, "ndmas",              "= %i",        NULL,          (void *)(&config.ndmas)},
273
  {3, "device",             "%i",          change_device, (void *)(&tempL)},
274
  {3, "enddevice",          "",            end_device,    NULL},
275
  {3, "baseaddr",           "= 0x%x",      dma_baseaddr,  (void *)(&tempUL)},
276
  {3, "irq",                "= %i",        dma_baseaddr,  (void *)(&tempL)}
277 239 markom
};
278
 
279 261 markom
int current_device = -1;
280
void change_device () {
281
  current_device = tempL;
282
}
283
 
284
void end_device () {
285
  current_device = -1;
286
}
287
 
288
void uart_baseaddr () {
289
  if (current_device >= 0 && current_device < config.nuarts)
290
    config.uarts[current_device].baseaddr = tempUL;
291
  else {
292
    fprintf (stderr, "ERROR: invalid device number.");
293
    exit (-1);
294
  }
295
}
296
 
297
void uart_jitter () {
298
  if (current_device >= 0 && current_device < config.nuarts)
299
    config.uarts[current_device].jitter = tempL;
300
  else {
301
    fprintf (stderr, "ERROR: invalid device number.");
302
    exit (-1);
303
  }
304
}
305
 
306
void uart_rxfile () {
307
  if (current_device >= 0 && current_device < config.nuarts)
308
    strcpy (config.uarts[current_device].rxfile, tempS);
309
  else {
310
    fprintf (stderr, "ERROR: invalid device number.");
311
    exit (-1);
312
  }
313
}
314
 
315
void uart_txfile () {
316
  if (current_device >= 0 && current_device < config.nuarts)
317
    strcpy (config.uarts[current_device].txfile, tempS);
318
  else {
319
    fprintf (stderr, "ERROR: invalid device number.");
320
    exit (-1);
321
  }
322
}
323
 
324
void dma_baseaddr () {
325
  if (current_device >= 0 && current_device < config.ndmas)
326
    config.dmas[current_device].baseaddr = tempUL;
327
  else {
328
    fprintf (stderr, "ERROR: invalid device number.");
329
    exit (-1);
330
  }
331
}
332
 
333
void dma_irq () {
334
  if (current_device >= 0 && current_device < config.ndmas)
335
    config.dmas[current_device].irq = tempL;
336
  else {
337
    fprintf (stderr, "ERROR: invalid device number.");
338
    exit (-1);
339
  }
340
}
341
 
342 239 markom
/* Read environment from a script file. Does not fail - assumes defaukt configuration instead.
343
   The syntax of script file is:
344
   param = value
345
   section x
346
     data
347
     param = value
348
   end
349
 
350
   Example:
351
   section mc
352
     memory_table_file = sim.mem
353
     enable = 1
354
     POC = 0x47892344
355
   end
356
 
357
 */
358
 
359
void read_script_file (char *filename)
360
{
361
        FILE *f;
362
        unsigned long memory_needed = 0;
363
        char *home = getenv("HOME");
364
        char ctmp[STR_SIZE];
365
        int local = 1;
366
        int section = 0;
367
 
368
        sprintf(ctmp, "%s/.or1k/%s", home, filename);
369
        if ((f = fopen (filename, "rt")) != NULL
370
                        || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) {
371
                unsigned long start, length;
372
                char type[STR_SIZE];
373
                int nparam;
374
                int rd, wd;
375
                printf ("Reading script file from '%s':\n", local ? filename : ctmp);
376
    while (!feof(f)) {
377
      char param[STR_SIZE];
378
      if (fscanf(f, "%s ", &param) != 1) break;
379
      /* Is this a sections? */
380
      if (strcmp (param, "section") == 0) {
381
        int i;
382
        section = 0;
383
        if (fscanf (f, "%s\n", &param) != 1) {
384
          fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp);
385
          exit (-1);
386
        }
387
        for (i = 1; i < sizeof(sections) / sizeof(char *); i++)
388 261 markom
          if (strcmp (sections[i].name, param) == 0) {
389 239 markom
            section = i;
390
            break;
391
          }
392
        if (!section) {
393
          fprintf (stderr, "%s: WARNING: Unknown section: %s; ignoring.\n", local ? filename : ctmp, param);
394
          /* just skip section */
395
          while (fscanf (f, "%s\n", &param) != 1 && strcmp (param, "end"));
396
        }
397
      } else if (strcmp (param, "end") == 0) {
398
        section = 0;
399 261 markom
      } else if (strcmp (param, "/*") == 0) {
400
        char c0 = 0, c1 = 0;
401
        while (c0 != '*' && c1 != '/') {
402
          c0 = c1;
403
          c1 = fgetc(f);
404
          if (feof(f)) {
405
            fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp);
406
            exit (-1);
407
          }
408
        }
409 239 markom
      } else {
410
        int i, found = -1;
411
        for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++)
412
          if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) {
413
            found = i;
414
            break;
415
          }
416
        if (found < 0) {
417
          fprintf (stderr, "%s: WARNING: Invalid parameter: %s; ignoring.\n", local ? filename : ctmp, param);
418 261 markom
          while (fgetc(f) != '\n' || feof(f));
419 239 markom
          continue;
420
        }
421
 
422
        /* Parse parameter value */
423
        {
424 261 markom
          char fmt[STR_SIZE];
425
          if (config_params[found].type[0]) {
426
            sprintf (fmt, "%s\n", config_params[found].type);
427
            fscanf (f, fmt, config_params[found].addr);
428
          }
429 239 markom
        }
430
      }
431
    }
432
                fclose (f);
433
        } else {
434
                fprintf (stderr, "Cannot read script file from '%s',\nneither '%s'; assuming standard configuration.\n", filename, ctmp);
435 103 lampret
        }
436
 
437 239 markom
        /* Initialize memory table.  */
438 240 markom
        sim_read_memory_table (config.mc.memory_table_file);
439 7 jrydberg
}

powered by: WebSVN 2.1.0

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