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 3 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, see <http://www.gnu.org/licenses/>.
29 #include <sys/fcntl.h>
32 #include "sim-config.h"
35 #define VAL(x) strtol(x,(char **)NULL,0)
37 /* Structures and functions from readline library */
39 #include "readline/readline.h"
40 #include "readline/history.h"
42 /* Command history buffer length - MUST be binary */
45 extern struct disassemble_info dinfo
;
46 extern struct pstate sregs
;
47 extern struct estate ebase
;
55 extern int sis_verbose
;
56 extern char *sis_version
;
57 extern struct estate ebase
;
58 extern struct evcell evbuf
[];
59 extern struct irqcell irqarr
[];
60 extern int irqpend
, ext_irl
;
64 extern char uart_dev1
[];
65 extern char uart_dev2
[];
66 extern uint32 last_load_addr
;
73 run_sim(sregs
, icount
, dis
)
78 int irq
, mexc
, deb
, asi
;
80 sregs
->starttime
= get_time();
82 if (sregs
->err_mode
) icount
= 0;
83 deb
= dis
|| sregs
->histlen
|| sregs
->bptnum
;
87 if (sregs
->psr
& 0x080)
91 mexc
= memory_read(asi
, sregs
->pc
, &sregs
->inst
, 2, &sregs
->hold
);
95 sregs
->pc
= sregs
->npc
;
96 sregs
->npc
= sregs
->npc
+ 4;
99 if (ext_irl
) irq
= check_interrupts(sregs
);
102 sregs
->trap
= I_ACC_EXC
;
105 if ((sregs
->bphit
= check_bpt(sregs
)) != 0) {
109 if (sregs
->histlen
) {
110 sregs
->histbuf
[sregs
->histind
].addr
= sregs
->pc
;
111 sregs
->histbuf
[sregs
->histind
].time
= ebase
.simtime
;
113 if (sregs
->histind
>= sregs
->histlen
)
117 printf(" %8" PRIu64
" ", ebase
.simtime
);
118 dis_mem(sregs
->pc
, 1, &dinfo
);
121 dispatch_instruction(sregs
);
127 sregs
->err_mode
= execute_trap(sregs
);
128 if (sregs
->err_mode
) {
129 error_mode(sregs
->pc
);
135 if (ctrl_c
|| (sregs
->tlimit
<= ebase
.simtime
)) {
137 if (sregs
->tlimit
<= ebase
.simtime
) sregs
->tlimit
= -1;
140 sregs
->tottime
+= get_time() - sregs
->starttime
;
163 char *cmdq
[HIST_LEN
];
169 for (i
= 0; i
< 64; i
++)
171 printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version
);
172 printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
173 while (stat
< argc
) {
174 if (argv
[stat
][0] == '-') {
175 if (strcmp(argv
[stat
], "-v") == 0) {
177 } else if (strcmp(argv
[stat
], "-c") == 0) {
178 if ((stat
+ 1) < argc
) {
180 cfile
= argv
[++stat
];
182 } else if (strcmp(argv
[stat
], "-nfp") == 0)
184 else if (strcmp(argv
[stat
], "-ift") == 0)
186 else if (strcmp(argv
[stat
], "-wrp") == 0)
188 else if (strcmp(argv
[stat
], "-rom8") == 0)
190 else if (strcmp(argv
[stat
], "-uben") == 0)
192 else if (strcmp(argv
[stat
], "-uart1") == 0) {
193 if ((stat
+ 1) < argc
)
194 strcpy(uart_dev1
, argv
[++stat
]);
195 } else if (strcmp(argv
[stat
], "-uart2") == 0) {
196 if ((stat
+ 1) < argc
)
197 strcpy(uart_dev2
, argv
[++stat
]);
198 } else if (strcmp(argv
[stat
], "-freq") == 0) {
199 if ((stat
+ 1) < argc
)
200 freq
= VAL(argv
[++stat
]);
201 } else if (strcmp(argv
[stat
], "-sparclite") == 0) {
204 } else if (strcmp(argv
[stat
], "-era") == 0) {
207 } else if (strcmp(argv
[stat
], "-dumbio") == 0) {
209 } else if (strcmp(argv
[stat
], "-v") == 0) {
212 printf("unknown option %s\n", argv
[stat
]);
222 printf("FPU disabled\n");
225 printf("ERA ECC emulation enabled\n");
229 INIT_DISASSEMBLE_INFO(dinfo
, stdout
, (fprintf_ftype
) fprintf
);
230 dinfo
.endian
= BFD_ENDIAN_BIG
;
232 termsave
= fcntl(0, F_GETFL
, 0);
240 last_load_addr
= bfd_load(argv
[lfile
]);
246 bacmd
= (char *) malloc(256);
247 strcpy(bacmd
, "batch ");
248 strcat(bacmd
, cfile
);
249 exec_cmd(&sregs
, bacmd
);
253 if (cmdq
[cmdi
] != 0) {
255 remove_history(cmdq
[cmdi
]);
257 remove_history(cmdi
);
262 cmdq
[cmdi
] = readline("sis> ");
263 if (cmdq
[cmdi
] && *cmdq
[cmdi
])
264 add_history(cmdq
[cmdi
]);
266 stat
= exec_cmd(&sregs
, cmdq
[cmdi
]);
275 printf("\b\bInterrupt!\n");
277 printf(" Stopped at time %" PRIu64
" (%.3f ms)\n", ebase
.simtime
,
278 ((double) ebase
.simtime
/ (double) sregs
.freq
) / 1000.0);
281 printf("breakpoint at 0x%08x reached\n", sregs
.pc
);
285 printf("IU in error mode (%d)\n", sregs
.trap
);
287 printf(" %8" PRIu64
" ", ebase
.simtime
);
288 dis_mem(sregs
.pc
, 1, &dinfo
);
296 cmdi
= (cmdi
+ 1) & (HIST_LEN
- 1);
This page took 0.034947 seconds and 4 git commands to generate.