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"
34 #define VAL(x) strtol(x,(char **)NULL,0)
36 /* Structures and functions from readline library */
43 extern char * readline (char *prompt
);
44 extern void using_history (void);
45 extern void add_history (char *string
);
46 extern HIST_ENTRY
*remove_history (int which
);
50 /* Command history buffer length - MUST be binary */
53 extern struct disassemble_info dinfo
;
54 extern struct pstate sregs
;
55 extern struct estate ebase
;
63 extern int sis_verbose
;
64 extern char *sis_version
;
65 extern struct estate ebase
;
66 extern struct evcell evbuf
[];
67 extern struct irqcell irqarr
[];
68 extern int irqpend
, ext_irl
;
72 extern char uart_dev1
[];
73 extern char uart_dev2
[];
74 extern uint32 last_load_addr
;
81 run_sim(sregs
, icount
, dis
)
86 int irq
, mexc
, deb
, asi
;
88 sregs
->starttime
= get_time();
90 if (sregs
->err_mode
) icount
= 0;
91 deb
= dis
|| sregs
->histlen
|| sregs
->bptnum
;
95 if (sregs
->psr
& 0x080)
99 mexc
= memory_read(asi
, sregs
->pc
, &sregs
->inst
, 2, &sregs
->hold
);
103 sregs
->pc
= sregs
->npc
;
104 sregs
->npc
= sregs
->npc
+ 4;
107 if (ext_irl
) irq
= check_interrupts(sregs
);
110 sregs
->trap
= I_ACC_EXC
;
113 if ((sregs
->bphit
= check_bpt(sregs
)) != 0) {
117 if (sregs
->histlen
) {
118 sregs
->histbuf
[sregs
->histind
].addr
= sregs
->pc
;
119 sregs
->histbuf
[sregs
->histind
].time
= ebase
.simtime
;
121 if (sregs
->histind
>= sregs
->histlen
)
125 printf(" %8u ", ebase
.simtime
);
126 dis_mem(sregs
->pc
, 1, &dinfo
);
129 dispatch_instruction(sregs
);
135 sregs
->err_mode
= execute_trap(sregs
);
136 if (sregs
->err_mode
) {
137 error_mode(sregs
->pc
);
143 if (ctrl_c
|| (sregs
->tlimit
<= ebase
.simtime
)) {
145 if (sregs
->tlimit
<= ebase
.simtime
) sregs
->tlimit
= -1;
148 sregs
->tottime
+= get_time() - sregs
->starttime
;
171 char *cmdq
[HIST_LEN
];
176 for (i
= 0; i
< 64; i
++)
178 printf("\n SIS - SPARC instruction simulator %s, copyright Jiri Gaisler 1995\n", sis_version
);
179 printf(" Bug-reports to jgais@wd.estec.esa.nl\n\n");
180 while (stat
< argc
) {
181 if (argv
[stat
][0] == '-') {
182 if (strcmp(argv
[stat
], "-v") == 0) {
184 } else if (strcmp(argv
[stat
], "-c") == 0) {
185 if ((stat
+ 1) < argc
) {
187 cfile
= argv
[++stat
];
189 } else if (strcmp(argv
[stat
], "-nfp") == 0)
191 else if (strcmp(argv
[stat
], "-ift") == 0)
193 else if (strcmp(argv
[stat
], "-wrp") == 0)
195 else if (strcmp(argv
[stat
], "-rom8") == 0)
197 else if (strcmp(argv
[stat
], "-uben") == 0)
199 else if (strcmp(argv
[stat
], "-uart1") == 0) {
200 if ((stat
+ 1) < argc
)
201 strcpy(uart_dev1
, argv
[++stat
]);
202 } else if (strcmp(argv
[stat
], "-uart2") == 0) {
203 if ((stat
+ 1) < argc
)
204 strcpy(uart_dev2
, argv
[++stat
]);
205 } else if (strcmp(argv
[stat
], "-freq") == 0) {
206 if ((stat
+ 1) < argc
)
207 freq
= VAL(argv
[++stat
]);
208 } else if (strcmp(argv
[stat
], "-sparclite") == 0) {
211 } else if (strcmp(argv
[stat
], "-era") == 0) {
214 } else if (strcmp(argv
[stat
], "-dumbio") == 0) {
217 printf("unknown option %s\n", argv
[stat
]);
222 last_load_addr
= bfd_load(argv
[stat
]);
227 printf("FPU disabled\n");
230 printf("ERA ECC emulation enabled\n");
234 INIT_DISASSEMBLE_INFO(dinfo
, stdout
, (fprintf_ftype
) fprintf
);
235 dinfo
.endian
= BFD_ENDIAN_BIG
;
237 termsave
= fcntl(0, F_GETFL
, 0);
249 bacmd
= (char *) malloc(256);
250 strcpy(bacmd
, "batch ");
251 strcat(bacmd
, cfile
);
252 exec_cmd(&sregs
, bacmd
);
256 if (cmdq
[cmdi
] != 0) {
258 remove_history(cmdq
[cmdi
]);
260 remove_history(cmdi
);
265 cmdq
[cmdi
] = readline("sis> ");
266 if (cmdq
[cmdi
] && *cmdq
[cmdi
])
267 add_history(cmdq
[cmdi
]);
269 stat
= exec_cmd(&sregs
, cmdq
[cmdi
]);
278 printf("\b\bInterrupt!\n");
280 printf(" Stopped at time %d (%.3f ms)\n", ebase
.simtime
,
281 ((double) ebase
.simtime
/ (double) sregs
.freq
) / 1000.0);
284 printf("breakpoint at 0x%08x reached\n", sregs
.pc
);
288 printf("IU in error mode (%d)\n", sregs
.trap
);
290 printf(" %8d ", ebase
.simtime
);
291 dis_mem(sregs
.pc
, 1, &dinfo
);
299 cmdi
= (cmdi
+ 1) & (HIST_LEN
- 1);
This page took 0.036919 seconds and 5 git commands to generate.