2 * This file is part of SIS.
4 * SIS, SPARC instruction simulator. Copyright (C) 1995 Jiri Gaisler, European
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
9 * Software Foundation; either version 2 of the License, or (at your option)
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
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 675
19 * Mass Ave, Cambridge, MA 02139, USA.
31 #include <sys/fcntl.h>
34 #include "sim-config.h"
36 #define VAL(x) strtol(x,(char **)NULL,0)
38 /* Structures and functions from readline library */
45 extern char * readline PARAMS ((char *prompt));
46 extern void using_history PARAMS ((void));
47 extern void add_history PARAMS ((char *string));
48 extern HIST_ENTRY *remove_history PARAMS ((int which));
52 /* Command history buffer length - MUST be binary */
55 extern struct disassemble_info dinfo;
56 extern struct pstate sregs;
57 extern struct estate ebase;
65 extern int sis_verbose;
66 extern char *sis_version;
67 extern struct estate ebase;
68 extern struct evcell evbuf[];
69 extern struct irqcell irqarr[];
70 extern int irqpend, ext_irl;
74 extern char uart_dev1[];
75 extern char uart_dev2[];
76 extern uint32 last_load_addr;
83 run_sim(sregs, icount, dis)
88 int irq, mexc, deb, asi;
90 sregs->starttime = time(NULL);
92 if (sregs->err_mode) icount = 0;
93 deb = dis || sregs->histlen || sregs->bptnum;
97 if (sregs->psr & 0x080)
101 mexc = memory_read(asi, sregs->pc, &sregs->inst, 2, &sregs->hold);
105 sregs->pc = sregs->npc;
106 sregs->npc = sregs->npc + 4;
109 if (ext_irl) irq = check_interrupts(sregs);
112 sregs->trap = I_ACC_EXC;
115 if ((sregs->bphit = check_bpt(sregs)) != 0) {
119 if (sregs->histlen) {
120 sregs->histbuf[sregs->histind].addr = sregs->pc;
121 sregs->histbuf[sregs->histind].time = ebase.simtime;
123 if (sregs->histind >= sregs->histlen)
127 printf(" %8u ", ebase.simtime);
128 dis_mem(sregs->pc, 1, &dinfo);
131 dispatch_instruction(sregs);
137 sregs->err_mode = execute_trap(sregs);
138 if (sregs->err_mode) {
139 error_mode(sregs->pc);
145 if (ctrl_c || (sregs->tlimit <= ebase.simtime)) {
147 if (sregs->tlimit <= ebase.simtime) sregs->tlimit = -1;
150 sregs->tottime += time(NULL) - sregs->starttime;
173 char *cmdq[HIST_LEN];
178 for (i = 0; i < 64; i++)
180 printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version);
181 printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
182 while (stat < argc) {
183 if (argv[stat][0] == '-') {
184 if (strcmp(argv[stat], "-v") == 0) {
186 } else if (strcmp(argv[stat], "-c") == 0) {
187 if ((stat + 1) < argc) {
189 cfile = argv[++stat];
191 } else if (strcmp(argv[stat], "-nfp") == 0)
193 else if (strcmp(argv[stat], "-ift") == 0)
195 else if (strcmp(argv[stat], "-wrp") == 0)
197 else if (strcmp(argv[stat], "-rom8") == 0)
199 else if (strcmp(argv[stat], "-uben") == 0)
201 else if (strcmp(argv[stat], "-uart1") == 0) {
202 if ((stat + 1) < argc)
203 strcpy(uart_dev1, argv[++stat]);
204 } else if (strcmp(argv[stat], "-uart2") == 0) {
205 if ((stat + 1) < argc)
206 strcpy(uart_dev2, argv[++stat]);
207 } else if (strcmp(argv[stat], "-freq") == 0) {
208 if ((stat + 1) < argc)
209 freq = VAL(argv[++stat]);
210 } else if (strcmp(argv[stat], "-sparclite") == 0) {
213 } else if (strcmp(argv[stat], "-era") == 0) {
216 } else if (strcmp(argv[stat], "-dumbio") == 0) {
219 printf("unknown option %s\n", argv[stat]);
224 last_load_addr = bfd_load(argv[stat]);
229 printf("FPU disabled\n");
232 printf("ERA ECC emulation enabled\n");
236 INIT_DISASSEMBLE_INFO(dinfo, stdout, (fprintf_ftype) fprintf);
237 dinfo.endian = BFD_ENDIAN_BIG;
239 termsave = fcntl(0, F_GETFL, 0);
251 bacmd = (char *) malloc(256);
252 strcpy(bacmd, "batch ");
253 strcat(bacmd, cfile);
254 exec_cmd(&sregs, bacmd);
258 if (cmdq[cmdi] != 0) {
260 remove_history(cmdq[cmdi]);
262 remove_history(cmdi);
267 cmdq[cmdi] = readline("sis> ");
268 if (cmdq[cmdi] && *cmdq[cmdi])
269 add_history(cmdq[cmdi]);
271 stat = exec_cmd(&sregs, cmdq[cmdi]);
280 printf("\b\bInterrupt!\n");
282 printf(" Stopped at time %d (%.3f ms)\n", ebase.simtime,
283 ((double) ebase.simtime / (double) sregs.freq) / 1000.0);
286 printf("breakpoint at 0x%08x reached\n", sregs.pc);
290 printf("IU in error mode (%d)\n", sregs.trap);
292 printf(" %8d ", ebase.simtime);
293 dis_mem(sregs.pc, 1, &dinfo);
301 cmdi = (cmdi + 1) & (HIST_LEN - 1);