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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [main.c] - Blame information for rev 275

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 hellwig
/*
2
 * main.c -- ECO32 simulator
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
#include "common.h"
11
#include "console.h"
12
#include "error.h"
13
#include "command.h"
14
#include "instr.h"
15
#include "cpu.h"
16 275 hellwig
#include "trace.h"
17 8 hellwig
#include "mmu.h"
18
#include "memory.h"
19
#include "timer.h"
20
#include "dspkbd.h"
21 246 hellwig
#include "serial.h"
22 8 hellwig
#include "disk.h"
23
#include "output.h"
24 25 hellwig
#include "shutdown.h"
25 8 hellwig
#include "graph.h"
26
 
27
 
28
static void usage(char *myself) {
29
  fprintf(stderr, "Usage: %s\n", myself);
30 244 hellwig
  fprintf(stderr, "    [-i]           set interactive mode\n");
31
  fprintf(stderr, "    [-m <n>]       install n MB of RAM (1-%d)\n",
32 8 hellwig
          RAM_SIZE_MAX / M);
33 244 hellwig
  fprintf(stderr, "    [-l <prog>]    set program file name\n");
34
  fprintf(stderr, "    [-a <addr>]    set program load address\n");
35
  fprintf(stderr, "    [-r <rom>]     set ROM image file name\n");
36
  fprintf(stderr, "    [-d <disk>]    set disk image file name\n");
37
  fprintf(stderr, "    [-s <n>]       install n serial lines (0-%d)\n",
38 246 hellwig
          MAX_NSERIALS);
39 244 hellwig
  fprintf(stderr, "    [-t <k>]       connect terminal to line k (0-%d)\n",
40 246 hellwig
          MAX_NSERIALS - 1);
41 244 hellwig
  fprintf(stderr, "    [-g]           install graphics controller\n");
42
  fprintf(stderr, "    [-c]           install console\n");
43
  fprintf(stderr, "    [-o <file>]    bind output device to file\n");
44 8 hellwig
  fprintf(stderr, "The options -l and -r are mutually exclusive.\n");
45
  fprintf(stderr, "If both are omitted, interactive mode is assumed.\n");
46 244 hellwig
  fprintf(stderr, "Unconnected serial lines can be accessed by opening\n");
47
  fprintf(stderr, "their corresponding pseudo terminal (path is shown).\n");
48 8 hellwig
  exit(1);
49
}
50
 
51
 
52
int main(int argc, char *argv[]) {
53 243 hellwig
  int i, j;
54 8 hellwig
  char *argp;
55
  char *endp;
56
  Bool interactive;
57
  int memSize;
58
  char *progName;
59 91 hellwig
  unsigned int loadAddr;
60 8 hellwig
  char *romName;
61
  char *diskName;
62 246 hellwig
  int numSerials;
63
  Bool connectTerminals[MAX_NSERIALS];
64 8 hellwig
  Bool graphics;
65
  Bool console;
66
  char *outputName;
67
  Word initialPC;
68
  char command[20];
69
  char *line;
70
 
71
  interactive = false;
72
  memSize = RAM_SIZE_DFL / M;
73
  progName = NULL;
74 91 hellwig
  loadAddr = 0;
75 8 hellwig
  romName = NULL;
76
  diskName = NULL;
77 246 hellwig
  numSerials = 0;
78
  for (j = 0; j < MAX_NSERIALS; j++) {
79
    connectTerminals[j] = false;
80 243 hellwig
  }
81 8 hellwig
  graphics = false;
82
  console = false;
83
  outputName = NULL;
84
  for (i = 1; i < argc; i++) {
85
    argp = argv[i];
86
    if (*argp != '-') {
87
      usage(argv[0]);
88
    }
89
    argp++;
90
    switch (*argp) {
91
      case 'i':
92
        interactive = true;
93
        break;
94
      case 'm':
95
        if (i == argc - 1) {
96
          usage(argv[0]);
97
        }
98
        memSize = strtol(argv[++i], &endp, 10);
99
        if (*endp != '\0' ||
100
            memSize <= 0 ||
101
            memSize > RAM_SIZE_MAX / M) {
102
          usage(argv[0]);
103
        }
104
        break;
105
      case 'l':
106
        if (i == argc - 1 || progName != NULL || romName != NULL) {
107
          usage(argv[0]);
108
        }
109
        progName = argv[++i];
110
        break;
111 91 hellwig
      case 'a':
112
        if (i == argc - 1) {
113
          usage(argv[0]);
114
        }
115
        loadAddr = strtoul(argv[++i], &endp, 0);
116
        if (*endp != '\0') {
117
          usage(argv[0]);
118
        }
119
        break;
120 8 hellwig
      case 'r':
121
        if (i == argc - 1 || romName != NULL || progName != NULL) {
122
          usage(argv[0]);
123
        }
124
        romName = argv[++i];
125
        break;
126
      case 'd':
127
        if (i == argc - 1 || diskName != NULL) {
128
          usage(argv[0]);
129
        }
130
        diskName = argv[++i];
131
        break;
132 244 hellwig
      case 's':
133 8 hellwig
        if (i == argc - 1) {
134
          usage(argv[0]);
135
        }
136 246 hellwig
        numSerials = strtol(argv[++i], &endp, 10);
137 8 hellwig
        if (*endp != '\0' ||
138 246 hellwig
            numSerials < 0 ||
139
            numSerials > MAX_NSERIALS) {
140 8 hellwig
          usage(argv[0]);
141
        }
142
        break;
143 244 hellwig
      case 't':
144 243 hellwig
        if (i == argc - 1) {
145
          usage(argv[0]);
146
        }
147
        j = strtol(argv[++i], &endp, 10);
148
        if (*endp != '\0' ||
149
            j < 0 ||
150 246 hellwig
            j > MAX_NSERIALS - 1) {
151 243 hellwig
          usage(argv[0]);
152
        }
153 246 hellwig
        connectTerminals[j] = true;
154 243 hellwig
        break;
155 8 hellwig
      case 'g':
156
        graphics = true;
157
        break;
158
      case 'c':
159
        console = true;
160
        break;
161
      case 'o':
162
        if (i == argc - 1 || outputName != NULL) {
163
          usage(argv[0]);
164
        }
165
        outputName = argv[++i];
166
        break;
167
      default:
168
        usage(argv[0]);
169
    }
170
  }
171
  cInit();
172
  cPrintf("ECO32 Simulator started\n");
173
  if (progName == NULL && romName == NULL && !interactive) {
174
    cPrintf("Neither a program to load nor a system ROM was\n");
175
    cPrintf("specified, so interactive mode is assumed.\n");
176
    interactive = true;
177
  }
178 250 hellwig
  for (j = MAX_NSERIALS - 1; j >= 0; j--) {
179
    if (connectTerminals[j] && j >= numSerials) {
180
      /* user wants a terminal on a line which is not installed */
181
      numSerials = j + 1;
182
      cPrintf("Serial lines 0..%d automatically installed.\n", j);
183
      break;
184
    }
185
  }
186 8 hellwig
  initInstrTable();
187
  timerInit();
188
  if (console) {
189
    displayInit();
190
    keyboardInit();
191
  }
192 246 hellwig
  serialInit(numSerials, connectTerminals);
193 8 hellwig
  diskInit(diskName);
194
  outputInit(outputName);
195 25 hellwig
  shutdownInit();
196 8 hellwig
  if (graphics) {
197
    graphInit();
198
  }
199 91 hellwig
  memoryInit(memSize * M, progName, loadAddr, romName);
200 8 hellwig
  mmuInit();
201 275 hellwig
  traceInit();
202 8 hellwig
  if (progName != NULL) {
203 91 hellwig
    initialPC = 0xC0000000 | loadAddr;
204 8 hellwig
  } else {
205
    initialPC = 0xC0000000 | ROM_BASE;
206
  }
207
  cpuInit(initialPC);
208
  if (!interactive) {
209
    cPrintf("Start executing...\n");
210
    strcpy(command, "c\n");
211
    execCommand(command);
212
  } else {
213
    while (1) {
214
      line = cGetLine("ECO32 > ");
215
      if (*line == '\0') {
216
        break;
217
      }
218
      cAddHist(line);
219
      if (execCommand(line)) {
220
        break;
221
      }
222
    }
223
  }
224
  cpuExit();
225 275 hellwig
  traceExit();
226 8 hellwig
  mmuExit();
227
  memoryExit();
228
  timerExit();
229
  displayExit();
230
  keyboardExit();
231 246 hellwig
  serialExit();
232 8 hellwig
  diskExit();
233
  outputExit();
234 25 hellwig
  shutdownExit();
235 8 hellwig
  graphExit();
236
  cPrintf("ECO32 Simulator finished\n");
237
  cExit();
238
  return 0;
239
}

powered by: WebSVN 2.1.0

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