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 263

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

powered by: WebSVN 2.1.0

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