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

Subversion Repositories eco32

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

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
#include "term.h"
21
#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 243 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 243 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, "       [-t <n>]         connect n terminals (0-%d)\n",
37 8 hellwig
          MAX_NTERMS);
38 243 hellwig
  fprintf(stderr, "       [-n <k>]         no terminal on line k (0-%d)\n",
39
          MAX_NTERMS - 1);
40
  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 243 hellwig
  fprintf(stderr, "The option -n leaves the specified serial line ");
46
  fprintf(stderr, "unconnected.\nIt can be accessed from within another ");
47
  fprintf(stderr, "process by opening\nthe corresponding pseudo terminal ");
48
  fprintf(stderr, "(path will be shown here).\n");
49 8 hellwig
  exit(1);
50
}
51
 
52
 
53
int main(int argc, char *argv[]) {
54 243 hellwig
  int i, j;
55 8 hellwig
  char *argp;
56
  char *endp;
57
  Bool interactive;
58
  int memSize;
59
  char *progName;
60 91 hellwig
  unsigned int loadAddr;
61 8 hellwig
  char *romName;
62
  char *diskName;
63
  int numTerms;
64 243 hellwig
  Bool hasTerm[MAX_NTERMS];
65 8 hellwig
  Bool graphics;
66
  Bool console;
67
  char *outputName;
68
  Word initialPC;
69
  char command[20];
70
  char *line;
71
 
72
  interactive = false;
73
  memSize = RAM_SIZE_DFL / M;
74
  progName = NULL;
75 91 hellwig
  loadAddr = 0;
76 8 hellwig
  romName = NULL;
77
  diskName = NULL;
78
  numTerms = 0;
79 243 hellwig
  for (j = 0; j < MAX_NTERMS; j++) {
80
    hasTerm[j] = true;
81
  }
82 8 hellwig
  graphics = false;
83
  console = false;
84
  outputName = NULL;
85
  for (i = 1; i < argc; i++) {
86
    argp = argv[i];
87
    if (*argp != '-') {
88
      usage(argv[0]);
89
    }
90
    argp++;
91
    switch (*argp) {
92
      case 'i':
93
        interactive = true;
94
        break;
95
      case 'm':
96
        if (i == argc - 1) {
97
          usage(argv[0]);
98
        }
99
        memSize = strtol(argv[++i], &endp, 10);
100
        if (*endp != '\0' ||
101
            memSize <= 0 ||
102
            memSize > RAM_SIZE_MAX / M) {
103
          usage(argv[0]);
104
        }
105
        break;
106
      case 'l':
107
        if (i == argc - 1 || progName != NULL || romName != NULL) {
108
          usage(argv[0]);
109
        }
110
        progName = argv[++i];
111
        break;
112 91 hellwig
      case 'a':
113
        if (i == argc - 1) {
114
          usage(argv[0]);
115
        }
116
        loadAddr = strtoul(argv[++i], &endp, 0);
117
        if (*endp != '\0') {
118
          usage(argv[0]);
119
        }
120
        break;
121 8 hellwig
      case 'r':
122
        if (i == argc - 1 || romName != NULL || progName != NULL) {
123
          usage(argv[0]);
124
        }
125
        romName = argv[++i];
126
        break;
127
      case 'd':
128
        if (i == argc - 1 || diskName != NULL) {
129
          usage(argv[0]);
130
        }
131
        diskName = argv[++i];
132
        break;
133
      case 't':
134
        if (i == argc - 1) {
135
          usage(argv[0]);
136
        }
137
        numTerms = strtol(argv[++i], &endp, 10);
138
        if (*endp != '\0' ||
139
            numTerms < 0 ||
140
            numTerms > MAX_NTERMS) {
141
          usage(argv[0]);
142
        }
143
        break;
144 243 hellwig
      case 'n':
145
        if (i == argc - 1) {
146
          usage(argv[0]);
147
        }
148
        j = strtol(argv[++i], &endp, 10);
149
        if (*endp != '\0' ||
150
            j < 0 ||
151
            j > MAX_NTERMS - 1) {
152
          usage(argv[0]);
153
        }
154
        hasTerm[j] = false;
155
        break;
156 8 hellwig
      case 'g':
157
        graphics = true;
158
        break;
159
      case 'c':
160
        console = true;
161
        break;
162
      case 'o':
163
        if (i == argc - 1 || outputName != NULL) {
164
          usage(argv[0]);
165
        }
166
        outputName = argv[++i];
167
        break;
168
      default:
169
        usage(argv[0]);
170
    }
171
  }
172
  cInit();
173
  cPrintf("ECO32 Simulator started\n");
174
  if (progName == NULL && romName == NULL && !interactive) {
175
    cPrintf("Neither a program to load nor a system ROM was\n");
176
    cPrintf("specified, so interactive mode is assumed.\n");
177
    interactive = true;
178
  }
179
  initInstrTable();
180
  timerInit();
181
  if (console) {
182
    displayInit();
183
    keyboardInit();
184
  }
185 243 hellwig
  termInit(numTerms, hasTerm);
186 8 hellwig
  diskInit(diskName);
187
  outputInit(outputName);
188 25 hellwig
  shutdownInit();
189 8 hellwig
  if (graphics) {
190
    graphInit();
191
  }
192 91 hellwig
  memoryInit(memSize * M, progName, loadAddr, romName);
193 8 hellwig
  mmuInit();
194
  if (progName != NULL) {
195 91 hellwig
    initialPC = 0xC0000000 | loadAddr;
196 8 hellwig
  } else {
197
    initialPC = 0xC0000000 | ROM_BASE;
198
  }
199
  cpuInit(initialPC);
200
  if (!interactive) {
201
    cPrintf("Start executing...\n");
202
    strcpy(command, "c\n");
203
    execCommand(command);
204
  } else {
205
    while (1) {
206
      line = cGetLine("ECO32 > ");
207
      if (*line == '\0') {
208
        break;
209
      }
210
      cAddHist(line);
211
      if (execCommand(line)) {
212
        break;
213
      }
214
    }
215
  }
216
  cpuExit();
217
  mmuExit();
218
  memoryExit();
219
  timerExit();
220
  displayExit();
221
  keyboardExit();
222
  termExit();
223
  diskExit();
224
  outputExit();
225 25 hellwig
  shutdownExit();
226 8 hellwig
  graphExit();
227
  cPrintf("ECO32 Simulator finished\n");
228
  cExit();
229
  return 0;
230
}

powered by: WebSVN 2.1.0

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