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

Subversion Repositories eco32

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

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
  initInstrTable();
178
  timerInit();
179
  if (console) {
180
    displayInit();
181
    keyboardInit();
182
  }
183 246 hellwig
  serialInit(numSerials, connectTerminals);
184 8 hellwig
  diskInit(diskName);
185
  outputInit(outputName);
186 25 hellwig
  shutdownInit();
187 8 hellwig
  if (graphics) {
188
    graphInit();
189
  }
190 91 hellwig
  memoryInit(memSize * M, progName, loadAddr, romName);
191 8 hellwig
  mmuInit();
192
  if (progName != NULL) {
193 91 hellwig
    initialPC = 0xC0000000 | loadAddr;
194 8 hellwig
  } else {
195
    initialPC = 0xC0000000 | ROM_BASE;
196
  }
197
  cpuInit(initialPC);
198
  if (!interactive) {
199
    cPrintf("Start executing...\n");
200
    strcpy(command, "c\n");
201
    execCommand(command);
202
  } else {
203
    while (1) {
204
      line = cGetLine("ECO32 > ");
205
      if (*line == '\0') {
206
        break;
207
      }
208
      cAddHist(line);
209
      if (execCommand(line)) {
210
        break;
211
      }
212
    }
213
  }
214
  cpuExit();
215
  mmuExit();
216
  memoryExit();
217
  timerExit();
218
  displayExit();
219
  keyboardExit();
220 246 hellwig
  serialExit();
221 8 hellwig
  diskExit();
222
  outputExit();
223 25 hellwig
  shutdownExit();
224 8 hellwig
  graphExit();
225
  cPrintf("ECO32 Simulator finished\n");
226
  cExit();
227
  return 0;
228
}

powered by: WebSVN 2.1.0

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