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"
40 #define VAL(x) strtol(x,(char **)NULL,0)
42 /* Structures and functions from readline library */
49 extern char * readline
PARAMS ((char *prompt
));
50 extern void using_history
PARAMS ((void));
51 extern void add_history
PARAMS ((char *string
));
52 extern HIST_ENTRY
*remove_history
PARAMS ((int which
));
56 /* Command history buffer length - MUST be binary */
59 extern struct disassemble_info dinfo
;
60 extern struct pstate sregs
;
61 extern struct estate ebase
;
69 extern int sis_verbose
;
70 extern char *sis_version
;
71 extern struct estate ebase
;
72 extern struct evcell evbuf
[];
73 extern struct irqcell irqarr
[];
74 extern int irqpend
, ext_irl
;
78 extern char uart_dev1
[];
79 extern char uart_dev2
[];
80 extern uint32 last_load_addr
;
87 run_sim(sregs
, icount
, dis
)
92 int irq
, mexc
, deb
, asi
;
94 sregs
->starttime
= time(NULL
);
96 if (sregs
->err_mode
) icount
= 0;
97 deb
= dis
|| sregs
->histlen
|| sregs
->bptnum
;
101 if (sregs
->psr
& 0x080)
105 mexc
= memory_read(asi
, sregs
->pc
, &sregs
->inst
, 2, &sregs
->hold
);
109 sregs
->pc
= sregs
->npc
;
110 sregs
->npc
= sregs
->npc
+ 4;
113 if (ext_irl
) irq
= check_interrupts(sregs
);
116 sregs
->trap
= I_ACC_EXC
;
119 if ((sregs
->bphit
= check_bpt(sregs
)) != 0) {
123 if (sregs
->histlen
) {
124 sregs
->histbuf
[sregs
->histind
].addr
= sregs
->pc
;
125 sregs
->histbuf
[sregs
->histind
].time
= ebase
.simtime
;
127 if (sregs
->histind
>= sregs
->histlen
)
131 printf(" %8u ", ebase
.simtime
);
132 dis_mem(sregs
->pc
, 1, &dinfo
);
135 dispatch_instruction(sregs
);
141 sregs
->err_mode
= execute_trap(sregs
);
142 if (sregs
->err_mode
) {
143 error_mode(sregs
->pc
);
149 if (ctrl_c
|| (sregs
->tlimit
<= ebase
.simtime
)) {
151 if (sregs
->tlimit
<= ebase
.simtime
) sregs
->tlimit
= -1;
154 sregs
->tottime
+= time(NULL
) - sregs
->starttime
;
177 char *cmdq
[HIST_LEN
];
182 for (i
= 0; i
< 64; i
++)
184 printf("\n SIS - SPARC intruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version
);
185 printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
186 while (stat
< argc
) {
187 if (argv
[stat
][0] == '-') {
188 if (strcmp(argv
[stat
], "-v") == 0) {
190 } else if (strcmp(argv
[stat
], "-c") == 0) {
191 if ((stat
+ 1) < argc
) {
193 cfile
= argv
[++stat
];
195 } else if (strcmp(argv
[stat
], "-nfp") == 0)
197 else if (strcmp(argv
[stat
], "-ift") == 0)
199 else if (strcmp(argv
[stat
], "-wrp") == 0)
201 else if (strcmp(argv
[stat
], "-rom8") == 0)
203 else if (strcmp(argv
[stat
], "-uben") == 0)
205 else if (strcmp(argv
[stat
], "-uart1") == 0) {
206 if ((stat
+ 1) < argc
)
207 strcpy(uart_dev1
, argv
[++stat
]);
208 } else if (strcmp(argv
[stat
], "-uart2") == 0) {
209 if ((stat
+ 1) < argc
)
210 strcpy(uart_dev2
, argv
[++stat
]);
211 } else if (strcmp(argv
[stat
], "-freq") == 0) {
212 if ((stat
+ 1) < argc
)
213 freq
= VAL(argv
[++stat
]);
214 } else if (strcmp(argv
[stat
], "-sparclite") == 0) {
217 } else if (strcmp(argv
[stat
], "-era") == 0) {
220 } else if (strcmp(argv
[stat
], "-dumbio") == 0) {
223 printf("unknown option %s\n", argv
[stat
]);
228 last_load_addr
= bfd_load(argv
[stat
]);
233 printf("FPU disabled\n");
236 printf("ERA ECC emulation enabled\n");
240 INIT_DISASSEMBLE_INFO(dinfo
, stdout
, (fprintf_ftype
) fprintf
);
241 dinfo
.endian
= BFD_ENDIAN_BIG
;
243 termsave
= fcntl(0, F_GETFL
, 0);
255 bacmd
= (char *) malloc(256);
256 strcpy(bacmd
, "batch ");
257 strcat(bacmd
, cfile
);
258 exec_cmd(&sregs
, bacmd
);
262 if (cmdq
[cmdi
] != 0) {
264 remove_history(cmdq
[cmdi
]);
266 remove_history(cmdi
);
271 cmdq
[cmdi
] = readline("sis> ");
272 if (cmdq
[cmdi
] && *cmdq
[cmdi
])
273 add_history(cmdq
[cmdi
]);
275 stat
= exec_cmd(&sregs
, cmdq
[cmdi
]);
284 printf("\b\bInterrupt!\n");
286 printf(" Stopped at time %d (%.3f ms)\n", ebase
.simtime
,
287 ((double) ebase
.simtime
/ (double) sregs
.freq
) / 1000.0);
290 printf("breakpoint at 0x%08x reached\n", sregs
.pc
);
294 printf("IU in error mode (%d)\n", sregs
.trap
);
296 printf(" %8d ", ebase
.simtime
);
297 dis_mem(sregs
.pc
, 1, &dinfo
);
305 cmdi
= (cmdi
+ 1) & (HIST_LEN
- 1);