1 /* This file is part of SIS (SPARC instruction simulator)
3 Copyright (C) 1995-2024 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/>. */
19 /* This must come before any other includes. */
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_t last_load_addr
;
70 run_sim(struct pstate
*sregs
, uint64_t icount
, int dis
)
74 sregs
->starttime
= get_time();
76 if (sregs
->err_mode
) icount
= 0;
77 deb
= dis
|| sregs
->histlen
|| sregs
->bptnum
;
81 mexc
= memory_iread (sregs
->pc
, &sregs
->inst
, &sregs
->hold
);
85 sregs
->pc
= sregs
->npc
;
86 sregs
->npc
= sregs
->npc
+ 4;
89 if (ext_irl
) irq
= check_interrupts(sregs
);
92 sregs
->trap
= I_ACC_EXC
;
95 if ((sregs
->bphit
= check_bpt(sregs
)) != 0) {
100 sregs
->histbuf
[sregs
->histind
].addr
= sregs
->pc
;
101 sregs
->histbuf
[sregs
->histind
].time
= ebase
.simtime
;
103 if (sregs
->histind
>= sregs
->histlen
)
107 printf(" %8" PRIu64
" ", ebase
.simtime
);
108 dis_mem(sregs
->pc
, 1, &dinfo
);
111 dispatch_instruction(sregs
);
117 sregs
->err_mode
= execute_trap(sregs
);
118 if (sregs
->err_mode
) {
119 error_mode(sregs
->pc
);
125 if (ctrl_c
|| (sregs
->tlimit
<= ebase
.simtime
)) {
127 if (sregs
->tlimit
<= ebase
.simtime
) sregs
->tlimit
= -1;
130 sregs
->tottime
+= get_time() - sregs
->starttime
;
141 static int ATTRIBUTE_PRINTF (3, 4)
142 fprintf_styled (void *stream
, enum disassembler_style style
,
143 const char *fmt
, ...)
146 FILE *out
= (FILE *) stream
;
149 va_start (args
, fmt
);
150 ret
= vfprintf (out
, fmt
, args
);
157 main(int argc
, char **argv
)
166 char *cmdq
[HIST_LEN
];
172 for (i
= 0; i
< 64; i
++)
174 printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version
);
175 printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
176 while (stat
< argc
) {
177 if (argv
[stat
][0] == '-') {
178 if (strcmp(argv
[stat
], "-v") == 0) {
180 } else if (strcmp(argv
[stat
], "-c") == 0) {
181 if ((stat
+ 1) < argc
) {
183 cfile
= argv
[++stat
];
185 } else if (strcmp(argv
[stat
], "-nfp") == 0)
187 else if (strcmp(argv
[stat
], "-ift") == 0)
189 else if (strcmp(argv
[stat
], "-wrp") == 0)
191 else if (strcmp(argv
[stat
], "-rom8") == 0)
193 else if (strcmp(argv
[stat
], "-uben") == 0)
195 else if (strcmp(argv
[stat
], "-uart1") == 0) {
196 if ((stat
+ 1) < argc
)
197 strcpy(uart_dev1
, argv
[++stat
]);
198 } else if (strcmp(argv
[stat
], "-uart2") == 0) {
199 if ((stat
+ 1) < argc
)
200 strcpy(uart_dev2
, argv
[++stat
]);
201 } else if (strcmp(argv
[stat
], "-freq") == 0) {
202 if ((stat
+ 1) < argc
)
203 freq
= VAL(argv
[++stat
]);
204 } else if (strcmp(argv
[stat
], "-sparclite") == 0) {
207 } else if (strcmp(argv
[stat
], "-era") == 0) {
210 } else if (strcmp(argv
[stat
], "-dumbio") == 0) {
213 printf("unknown option %s\n", argv
[stat
]);
223 printf("FPU disabled\n");
226 printf("ERA ECC emulation enabled\n");
230 INIT_DISASSEMBLE_INFO(dinfo
, stdout
, (fprintf_ftype
) fprintf
,
231 (fprintf_styled_ftype
) fprintf_styled
);
232 #ifdef HOST_LITTLE_ENDIAN
233 dinfo
.endian
= BFD_ENDIAN_LITTLE
;
235 dinfo
.endian
= BFD_ENDIAN_BIG
;
239 termsave
= fcntl(0, F_GETFL
, 0);
248 last_load_addr
= bfd_load(argv
[lfile
]);
254 bacmd
= (char *) malloc(256);
255 strcpy(bacmd
, "batch ");
256 strcat(bacmd
, cfile
);
257 exec_cmd(&sregs
, bacmd
);
261 if (cmdq
[cmdi
] != 0) {
263 remove_history(cmdq
[cmdi
]);
265 remove_history(cmdi
);
270 cmdq
[cmdi
] = readline("sis> ");
271 if (cmdq
[cmdi
] && *cmdq
[cmdi
])
272 add_history(cmdq
[cmdi
]);
274 stat
= exec_cmd(&sregs
, cmdq
[cmdi
]);
283 printf("\b\bInterrupt!\n");
284 ATTRIBUTE_FALLTHROUGH
;
286 printf(" Stopped at time %" PRIu64
" (%.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(" %8" PRIu64
" ", ebase
.simtime
);
297 dis_mem(sregs
.pc
, 1, &dinfo
);
305 cmdi
= (cmdi
+ 1) & (HIST_LEN
- 1);