]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* |
2 | * This file is part of SIS. | |
3 | * | |
4 | * SIS, SPARC instruction simulator. Copyright (C) 1995 Jiri Gaisler, European | |
5 | * Space Agency | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify it under | |
8 | * the terms of the GNU General Public License as published by the Free | |
3fd725ef | 9 | * Software Foundation; either version 3 of the License, or (at your option) |
c906108c SS |
10 | * any later version. |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 | * more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along with | |
51b318de | 18 | * this program; if not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
19 | * |
20 | */ | |
21 | ||
22 | #include "config.h" | |
23 | #include <signal.h> | |
24 | #include <string.h> | |
25 | #ifdef HAVE_STDLIB_H | |
26 | #include <stdlib.h> | |
27 | #endif | |
28 | #include <stdio.h> | |
c906108c SS |
29 | #include <sys/fcntl.h> |
30 | #include "sis.h" | |
31 | #include <dis-asm.h> | |
32 | #include "sim-config.h" | |
638fcdad | 33 | #include <inttypes.h> |
c906108c | 34 | |
c906108c SS |
35 | #define VAL(x) strtol(x,(char **)NULL,0) |
36 | ||
37 | /* Structures and functions from readline library */ | |
38 | ||
5634e839 JG |
39 | #include "readline/readline.h" |
40 | #include "readline/history.h" | |
c906108c SS |
41 | |
42 | /* Command history buffer length - MUST be binary */ | |
43 | #define HIST_LEN 64 | |
44 | ||
45 | extern struct disassemble_info dinfo; | |
46 | extern struct pstate sregs; | |
47 | extern struct estate ebase; | |
48 | ||
49 | extern int ctrl_c; | |
50 | extern int nfp; | |
51 | extern int ift; | |
52 | extern int wrp; | |
53 | extern int rom8; | |
54 | extern int uben; | |
55 | extern int sis_verbose; | |
56 | extern char *sis_version; | |
57 | extern struct estate ebase; | |
58 | extern struct evcell evbuf[]; | |
59 | extern struct irqcell irqarr[]; | |
60 | extern int irqpend, ext_irl; | |
61 | extern int termsave; | |
62 | extern int sparclite; | |
63 | extern int dumbio; | |
64 | extern char uart_dev1[]; | |
65 | extern char uart_dev2[]; | |
66 | extern uint32 last_load_addr; | |
67 | ||
68 | #ifdef ERA | |
69 | extern int era; | |
70 | #endif | |
71 | ||
72 | int | |
73 | run_sim(sregs, icount, dis) | |
74 | struct pstate *sregs; | |
94110024 | 75 | uint64 icount; |
c906108c SS |
76 | int dis; |
77 | { | |
78 | int irq, mexc, deb, asi; | |
79 | ||
96d67095 | 80 | sregs->starttime = get_time(); |
c906108c SS |
81 | init_stdio(); |
82 | if (sregs->err_mode) icount = 0; | |
83 | deb = dis || sregs->histlen || sregs->bptnum; | |
84 | irq = 0; | |
85 | while (icount > 0) { | |
86 | ||
87 | if (sregs->psr & 0x080) | |
88 | asi = 9; | |
89 | else | |
90 | asi = 8; | |
91 | mexc = memory_read(asi, sregs->pc, &sregs->inst, 2, &sregs->hold); | |
92 | sregs->icnt = 1; | |
93 | if (sregs->annul) { | |
94 | sregs->annul = 0; | |
95 | sregs->pc = sregs->npc; | |
96 | sregs->npc = sregs->npc + 4; | |
97 | } else { | |
98 | sregs->fhold = 0; | |
99 | if (ext_irl) irq = check_interrupts(sregs); | |
100 | if (!irq) { | |
101 | if (mexc) { | |
102 | sregs->trap = I_ACC_EXC; | |
103 | } else { | |
104 | if (deb) { | |
105 | if ((sregs->bphit = check_bpt(sregs)) != 0) { | |
106 | restore_stdio(); | |
107 | return (BPT_HIT); | |
108 | } | |
109 | if (sregs->histlen) { | |
110 | sregs->histbuf[sregs->histind].addr = sregs->pc; | |
111 | sregs->histbuf[sregs->histind].time = ebase.simtime; | |
112 | sregs->histind++; | |
113 | if (sregs->histind >= sregs->histlen) | |
114 | sregs->histind = 0; | |
115 | } | |
116 | if (dis) { | |
638fcdad | 117 | printf(" %8" PRIu64 " ", ebase.simtime); |
c906108c SS |
118 | dis_mem(sregs->pc, 1, &dinfo); |
119 | } | |
120 | } | |
121 | dispatch_instruction(sregs); | |
122 | icount--; | |
123 | } | |
124 | } | |
125 | if (sregs->trap) { | |
126 | irq = 0; | |
127 | sregs->err_mode = execute_trap(sregs); | |
128 | if (sregs->err_mode) { | |
129 | error_mode(sregs->pc); | |
130 | icount = 0; | |
131 | } | |
132 | } | |
133 | } | |
134 | advance_time(sregs); | |
135 | if (ctrl_c || (sregs->tlimit <= ebase.simtime)) { | |
136 | icount = 0; | |
137 | if (sregs->tlimit <= ebase.simtime) sregs->tlimit = -1; | |
138 | } | |
139 | } | |
96d67095 | 140 | sregs->tottime += get_time() - sregs->starttime; |
c906108c SS |
141 | restore_stdio(); |
142 | if (sregs->err_mode) | |
143 | return (ERROR); | |
144 | if (ctrl_c) { | |
145 | ctrl_c = 0; | |
146 | return (CTRL_C); | |
147 | } | |
148 | return (TIME_OUT); | |
149 | } | |
150 | ||
151 | int | |
152 | main(argc, argv) | |
153 | int argc; | |
154 | char **argv; | |
155 | { | |
156 | ||
157 | int cont = 1; | |
158 | int stat = 1; | |
159 | int freq = 14; | |
160 | int copt = 0; | |
161 | ||
162 | char *cfile, *bacmd; | |
163 | char *cmdq[HIST_LEN]; | |
164 | int cmdi = 0; | |
165 | int i; | |
e26473a1 | 166 | int lfile = 0; |
c906108c SS |
167 | |
168 | cfile = 0; | |
169 | for (i = 0; i < 64; i++) | |
170 | cmdq[i] = 0; | |
14e1f957 | 171 | printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version); |
c906108c SS |
172 | printf(" Bug-reports to [email protected]\n\n"); |
173 | while (stat < argc) { | |
174 | if (argv[stat][0] == '-') { | |
175 | if (strcmp(argv[stat], "-v") == 0) { | |
176 | sis_verbose = 1; | |
177 | } else if (strcmp(argv[stat], "-c") == 0) { | |
178 | if ((stat + 1) < argc) { | |
179 | copt = 1; | |
180 | cfile = argv[++stat]; | |
181 | } | |
182 | } else if (strcmp(argv[stat], "-nfp") == 0) | |
183 | nfp = 1; | |
184 | else if (strcmp(argv[stat], "-ift") == 0) | |
185 | ift = 1; | |
186 | else if (strcmp(argv[stat], "-wrp") == 0) | |
187 | wrp = 1; | |
188 | else if (strcmp(argv[stat], "-rom8") == 0) | |
189 | rom8 = 1; | |
190 | else if (strcmp(argv[stat], "-uben") == 0) | |
191 | uben = 1; | |
192 | else if (strcmp(argv[stat], "-uart1") == 0) { | |
193 | if ((stat + 1) < argc) | |
194 | strcpy(uart_dev1, argv[++stat]); | |
195 | } else if (strcmp(argv[stat], "-uart2") == 0) { | |
196 | if ((stat + 1) < argc) | |
197 | strcpy(uart_dev2, argv[++stat]); | |
198 | } else if (strcmp(argv[stat], "-freq") == 0) { | |
199 | if ((stat + 1) < argc) | |
200 | freq = VAL(argv[++stat]); | |
201 | } else if (strcmp(argv[stat], "-sparclite") == 0) { | |
202 | sparclite = 1; | |
203 | #ifdef ERA | |
204 | } else if (strcmp(argv[stat], "-era") == 0) { | |
205 | era = 1; | |
206 | #endif | |
207 | } else if (strcmp(argv[stat], "-dumbio") == 0) { | |
208 | dumbio = 1; | |
638fcdad JG |
209 | } else if (strcmp(argv[stat], "-v") == 0) { |
210 | sis_verbose += 1; | |
c906108c SS |
211 | } else { |
212 | printf("unknown option %s\n", argv[stat]); | |
213 | usage(); | |
214 | exit(1); | |
215 | } | |
216 | } else { | |
e26473a1 | 217 | lfile = stat; |
c906108c SS |
218 | } |
219 | stat++; | |
220 | } | |
221 | if (nfp) | |
222 | printf("FPU disabled\n"); | |
223 | #ifdef ERA | |
224 | if (era) | |
225 | printf("ERA ECC emulation enabled\n"); | |
226 | #endif | |
227 | sregs.freq = freq; | |
228 | ||
229 | INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf); | |
230 | dinfo.endian = BFD_ENDIAN_BIG; | |
231 | ||
232 | termsave = fcntl(0, F_GETFL, 0); | |
233 | using_history(); | |
234 | init_signals(); | |
235 | ebase.simtime = 0; | |
236 | reset_all(); | |
237 | init_bpt(&sregs); | |
238 | init_sim(); | |
e26473a1 JG |
239 | if (lfile) |
240 | last_load_addr = bfd_load(argv[lfile]); | |
c906108c SS |
241 | #ifdef STAT |
242 | reset_stat(&sregs); | |
243 | #endif | |
244 | ||
245 | if (copt) { | |
246 | bacmd = (char *) malloc(256); | |
247 | strcpy(bacmd, "batch "); | |
248 | strcat(bacmd, cfile); | |
249 | exec_cmd(&sregs, bacmd); | |
250 | } | |
251 | while (cont) { | |
252 | ||
253 | if (cmdq[cmdi] != 0) { | |
254 | #if 0 | |
255 | remove_history(cmdq[cmdi]); | |
256 | #else | |
257 | remove_history(cmdi); | |
258 | #endif | |
259 | free(cmdq[cmdi]); | |
260 | cmdq[cmdi] = 0; | |
261 | } | |
262 | cmdq[cmdi] = readline("sis> "); | |
263 | if (cmdq[cmdi] && *cmdq[cmdi]) | |
264 | add_history(cmdq[cmdi]); | |
265 | if (cmdq[cmdi]) | |
266 | stat = exec_cmd(&sregs, cmdq[cmdi]); | |
267 | else { | |
268 | puts("\n"); | |
269 | exit(0); | |
270 | } | |
271 | switch (stat) { | |
272 | case OK: | |
273 | break; | |
274 | case CTRL_C: | |
275 | printf("\b\bInterrupt!\n"); | |
276 | case TIME_OUT: | |
638fcdad | 277 | printf(" Stopped at time %" PRIu64 " (%.3f ms)\n", ebase.simtime, |
c906108c SS |
278 | ((double) ebase.simtime / (double) sregs.freq) / 1000.0); |
279 | break; | |
280 | case BPT_HIT: | |
281 | printf("breakpoint at 0x%08x reached\n", sregs.pc); | |
282 | sregs.bphit = 1; | |
283 | break; | |
284 | case ERROR: | |
285 | printf("IU in error mode (%d)\n", sregs.trap); | |
286 | stat = 0; | |
638fcdad | 287 | printf(" %8" PRIu64 " ", ebase.simtime); |
c906108c SS |
288 | dis_mem(sregs.pc, 1, &dinfo); |
289 | break; | |
290 | default: | |
291 | break; | |
292 | } | |
293 | ctrl_c = 0; | |
294 | stat = OK; | |
295 | ||
296 | cmdi = (cmdi + 1) & (HIST_LEN - 1); | |
297 | ||
298 | } | |
299 | return 0; | |
300 | } | |
301 |