1 /* This file is part of SIS (SPARC instruction simulator)
3 Copyright (C) 1995-2019 Free Software Foundation, Inc.
4 Contributed by Jiri Gaisler, European Space Agency
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include <sys/fcntl.h>
29 #include "sim-config.h"
32 #define VAL(x) strtol(x,(char **)NULL,0)
34 /* Structures and functions from readline library */
36 #include "readline/readline.h"
37 #include "readline/history.h"
39 /* Command history buffer length - MUST be binary */
42 extern struct disassemble_info dinfo
;
43 extern struct pstate sregs
;
44 extern struct estate ebase
;
52 extern int sis_verbose
;
53 extern char *sis_version
;
54 extern struct estate ebase
;
55 extern struct evcell evbuf
[];
56 extern struct irqcell irqarr
[];
57 extern int irqpend
, ext_irl
;
61 extern char uart_dev1
[];
62 extern char uart_dev2
[];
63 extern uint32 last_load_addr
;
70 run_sim(sregs
, icount
, dis
)
77 sregs
->starttime
= get_time();
79 if (sregs
->err_mode
) icount
= 0;
80 deb
= dis
|| sregs
->histlen
|| sregs
->bptnum
;
84 mexc
= memory_iread (sregs
->pc
, &sregs
->inst
, &sregs
->hold
);
88 sregs
->pc
= sregs
->npc
;
89 sregs
->npc
= sregs
->npc
+ 4;
92 if (ext_irl
) irq
= check_interrupts(sregs
);
95 sregs
->trap
= I_ACC_EXC
;
98 if ((sregs
->bphit
= check_bpt(sregs
)) != 0) {
102 if (sregs
->histlen
) {
103 sregs
->histbuf
[sregs
->histind
].addr
= sregs
->pc
;
104 sregs
->histbuf
[sregs
->histind
].time
= ebase
.simtime
;
106 if (sregs
->histind
>= sregs
->histlen
)
110 printf(" %8" PRIu64
" ", ebase
.simtime
);
111 dis_mem(sregs
->pc
, 1, &dinfo
);
114 dispatch_instruction(sregs
);
120 sregs
->err_mode
= execute_trap(sregs
);
121 if (sregs
->err_mode
) {
122 error_mode(sregs
->pc
);
128 if (ctrl_c
|| (sregs
->tlimit
<= ebase
.simtime
)) {
130 if (sregs
->tlimit
<= ebase
.simtime
) sregs
->tlimit
= -1;
133 sregs
->tottime
+= get_time() - sregs
->starttime
;
156 char *cmdq
[HIST_LEN
];
162 for (i
= 0; i
< 64; i
++)
164 printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version
);
165 printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
166 while (stat
< argc
) {
167 if (argv
[stat
][0] == '-') {
168 if (strcmp(argv
[stat
], "-v") == 0) {
170 } else if (strcmp(argv
[stat
], "-c") == 0) {
171 if ((stat
+ 1) < argc
) {
173 cfile
= argv
[++stat
];
175 } else if (strcmp(argv
[stat
], "-nfp") == 0)
177 else if (strcmp(argv
[stat
], "-ift") == 0)
179 else if (strcmp(argv
[stat
], "-wrp") == 0)
181 else if (strcmp(argv
[stat
], "-rom8") == 0)
183 else if (strcmp(argv
[stat
], "-uben") == 0)
185 else if (strcmp(argv
[stat
], "-uart1") == 0) {
186 if ((stat
+ 1) < argc
)
187 strcpy(uart_dev1
, argv
[++stat
]);
188 } else if (strcmp(argv
[stat
], "-uart2") == 0) {
189 if ((stat
+ 1) < argc
)
190 strcpy(uart_dev2
, argv
[++stat
]);
191 } else if (strcmp(argv
[stat
], "-freq") == 0) {
192 if ((stat
+ 1) < argc
)
193 freq
= VAL(argv
[++stat
]);
194 } else if (strcmp(argv
[stat
], "-sparclite") == 0) {
197 } else if (strcmp(argv
[stat
], "-era") == 0) {
200 } else if (strcmp(argv
[stat
], "-dumbio") == 0) {
203 printf("unknown option %s\n", argv
[stat
]);
213 printf("FPU disabled\n");
216 printf("ERA ECC emulation enabled\n");
220 INIT_DISASSEMBLE_INFO(dinfo
, stdout
, (fprintf_ftype
) fprintf
);
221 #ifdef HOST_LITTLE_ENDIAN
222 dinfo
.endian
= BFD_ENDIAN_LITTLE
;
224 dinfo
.endian
= BFD_ENDIAN_BIG
;
227 termsave
= fcntl(0, F_GETFL
, 0);
235 last_load_addr
= bfd_load(argv
[lfile
]);
241 bacmd
= (char *) malloc(256);
242 strcpy(bacmd
, "batch ");
243 strcat(bacmd
, cfile
);
244 exec_cmd(&sregs
, bacmd
);
248 if (cmdq
[cmdi
] != 0) {
250 remove_history(cmdq
[cmdi
]);
252 remove_history(cmdi
);
257 cmdq
[cmdi
] = readline("sis> ");
258 if (cmdq
[cmdi
] && *cmdq
[cmdi
])
259 add_history(cmdq
[cmdi
]);
261 stat
= exec_cmd(&sregs
, cmdq
[cmdi
]);
270 printf("\b\bInterrupt!\n");
272 printf(" Stopped at time %" PRIu64
" (%.3f ms)\n", ebase
.simtime
,
273 ((double) ebase
.simtime
/ (double) sregs
.freq
) / 1000.0);
276 printf("breakpoint at 0x%08x reached\n", sregs
.pc
);
280 printf("IU in error mode (%d)\n", sregs
.trap
);
282 printf(" %8" PRIu64
" ", ebase
.simtime
);
283 dis_mem(sregs
.pc
, 1, &dinfo
);
291 cmdi
= (cmdi
+ 1) & (HIST_LEN
- 1);