1 /* This file is part of SIS (SPARC instruction simulator)
3 Copyright (C) 1995-2021 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 last_load_addr
;
70 run_sim(struct pstate
*sregs
, uint64 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
;
142 main(int argc
, char **argv
)
151 char *cmdq
[HIST_LEN
];
157 for (i
= 0; i
< 64; i
++)
159 printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version
);
160 printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
161 while (stat
< argc
) {
162 if (argv
[stat
][0] == '-') {
163 if (strcmp(argv
[stat
], "-v") == 0) {
165 } else if (strcmp(argv
[stat
], "-c") == 0) {
166 if ((stat
+ 1) < argc
) {
168 cfile
= argv
[++stat
];
170 } else if (strcmp(argv
[stat
], "-nfp") == 0)
172 else if (strcmp(argv
[stat
], "-ift") == 0)
174 else if (strcmp(argv
[stat
], "-wrp") == 0)
176 else if (strcmp(argv
[stat
], "-rom8") == 0)
178 else if (strcmp(argv
[stat
], "-uben") == 0)
180 else if (strcmp(argv
[stat
], "-uart1") == 0) {
181 if ((stat
+ 1) < argc
)
182 strcpy(uart_dev1
, argv
[++stat
]);
183 } else if (strcmp(argv
[stat
], "-uart2") == 0) {
184 if ((stat
+ 1) < argc
)
185 strcpy(uart_dev2
, argv
[++stat
]);
186 } else if (strcmp(argv
[stat
], "-freq") == 0) {
187 if ((stat
+ 1) < argc
)
188 freq
= VAL(argv
[++stat
]);
189 } else if (strcmp(argv
[stat
], "-sparclite") == 0) {
192 } else if (strcmp(argv
[stat
], "-era") == 0) {
195 } else if (strcmp(argv
[stat
], "-dumbio") == 0) {
198 printf("unknown option %s\n", argv
[stat
]);
208 printf("FPU disabled\n");
211 printf("ERA ECC emulation enabled\n");
215 INIT_DISASSEMBLE_INFO(dinfo
, stdout
, (fprintf_ftype
) fprintf
);
216 #ifdef HOST_LITTLE_ENDIAN
217 dinfo
.endian
= BFD_ENDIAN_LITTLE
;
219 dinfo
.endian
= BFD_ENDIAN_BIG
;
223 termsave
= fcntl(0, F_GETFL
, 0);
232 last_load_addr
= bfd_load(argv
[lfile
]);
238 bacmd
= (char *) malloc(256);
239 strcpy(bacmd
, "batch ");
240 strcat(bacmd
, cfile
);
241 exec_cmd(&sregs
, bacmd
);
245 if (cmdq
[cmdi
] != 0) {
247 remove_history(cmdq
[cmdi
]);
249 remove_history(cmdi
);
254 cmdq
[cmdi
] = readline("sis> ");
255 if (cmdq
[cmdi
] && *cmdq
[cmdi
])
256 add_history(cmdq
[cmdi
]);
258 stat
= exec_cmd(&sregs
, cmdq
[cmdi
]);
267 printf("\b\bInterrupt!\n");
269 printf(" Stopped at time %" PRIu64
" (%.3f ms)\n", ebase
.simtime
,
270 ((double) ebase
.simtime
/ (double) sregs
.freq
) / 1000.0);
273 printf("breakpoint at 0x%08x reached\n", sregs
.pc
);
277 printf("IU in error mode (%d)\n", sregs
.trap
);
279 printf(" %8" PRIu64
" ", ebase
.simtime
);
280 dis_mem(sregs
.pc
, 1, &dinfo
);
288 cmdi
= (cmdi
+ 1) & (HIST_LEN
- 1);
This page took 0.036167 seconds and 5 git commands to generate.