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

Subversion Repositories eco32

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

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

powered by: WebSVN 2.1.0

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