6f1332408aa541f03c767e965e9de40d12a47114
2 * This file is part of SIS.
4 * SIS, SPARC instruction simulator V1.6 Copyright (C) 1995 Jiri Gaisler,
5 * European Space Agency
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 2 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, write to the Free Software Foundation, Inc., 675
19 * Mass Ave, Cambridge, MA 02139, USA.
26 #include <sys/fcntl.h>
31 #include "remote-sim.h"
37 #define VAL(x) strtol(x,(char *)NULL,0)
39 extern char **buildargv(char *input
);
41 extern struct disassemble_info dinfo
;
42 extern struct pstate sregs
;
43 extern struct estate ebase
;
50 extern int sis_verbose
;
51 extern char *sis_version
;
52 extern struct estate ebase
;
53 extern struct evcell evbuf
[];
54 extern struct irqcell irqarr
[];
55 extern int irqpend
, ext_irl
;
58 extern char uart_dev1
[], uart_dev2
[];
60 int sis_gdb_break
= 1;
62 host_callback
*sim_callback
;
64 run_sim(sregs
, go
, icount
, dis
)
73 (*sim_callback
->printf_filtered
) (sim_callback
, "resuming at %x\n",
76 sregs
->starttime
= time(NULL
);
77 while ((!sregs
->err_mode
& (go
|| (icount
> 0))) &&
78 ((sregs
->bptnum
== 0) || !(sregs
->bphit
= check_bpt(sregs
)))) {
84 check_interrupts(sregs
);
86 sregs
->err_mode
= execute_trap(sregs
);
88 if (sregs
->psr
& 0x080)
93 mexc
= memory_read(sregs
->asi
, sregs
->pc
, &sregs
->inst
, &sregs
->hold
);
97 sregs
->pc
= sregs
->npc
;
98 sregs
->npc
= sregs
->npc
+ 4;
101 sregs
->trap
= I_ACC_EXC
;
103 if (sregs
->histlen
) {
104 sregs
->histbuf
[sregs
->histind
].addr
= sregs
->pc
;
105 sregs
->histbuf
[sregs
->histind
].time
= ebase
.simtime
;
107 if (sregs
->histind
>= sregs
->histlen
)
111 printf(" %8d ", ebase
.simtime
);
112 dis_mem(sregs
->pc
, 1, &dinfo
);
114 if ((sis_gdb_break
) && (sregs
->inst
== 0x91d02001)) {
116 (*sim_callback
->printf_filtered
) (sim_callback
,
117 "SW BP hit at %x\n", sregs
->pc
);
120 dispatch_instruction(sregs
);
125 sregs
->err_mode
= execute_trap(sregs
);
134 sregs
->tottime
+= time(NULL
) - sregs
->starttime
;
138 error_mode(sregs
->pc
);
143 (*sim_callback
->printf_filtered
) (sim_callback
,
144 "HW BP hit at %x\n", sregs
->pc
);
155 sim_set_callbacks (ptr
)
179 (*sim_callback
->printf_filtered
) (sim_callback
, "\n SIS - SPARC instruction simulator %s\n", sis_version
);
180 (*sim_callback
->printf_filtered
) (sim_callback
, " Bug-reports to Jiri Gaisler ESA/ESTEC (jgais@wd.estec.esa.nl)\n");
181 argv
= buildargv(args
);
185 while (stat
< argc
) {
186 if (argv
[stat
][0] == '-') {
187 if (strcmp(argv
[stat
], "-v") == 0) {
190 if (strcmp(argv
[stat
], "-nfp") == 0) {
191 (*sim_callback
->printf_filtered
) (sim_callback
, "no FPU\n");
194 if (strcmp(argv
[stat
], "-ift") == 0) {
197 if (strcmp(argv
[stat
], "-sparclite") == 0) {
198 (*sim_callback
->printf_filtered
) (sim_callback
, "simulating Sparclite\n");
201 if (strcmp(argv
[stat
], "-wrp") == 0) {
204 if (strcmp(argv
[stat
], "-rom8") == 0) {
207 if (strcmp(argv
[stat
], "-uart1") == 0) {
208 if ((stat
+ 1) < argc
)
209 strcpy(uart_dev1
, argv
[++stat
]);
211 if (strcmp(argv
[stat
], "-uart2") == 0) {
212 if ((stat
+ 1) < argc
)
213 strcpy(uart_dev2
, argv
[++stat
]);
215 if (strcmp(argv
[stat
], "-nogdb") == 0) {
216 (*sim_callback
->printf_filtered
) (sim_callback
, "disabling GDB trap handling for breakpoints\n");
219 if (strcmp(argv
[stat
], "-freq") == 0)
220 if ((stat
+ 1) < argc
) {
221 freq
= VAL(argv
[++stat
]);
222 (*sim_callback
->printf_filtered
) (sim_callback
, " ERC32 freq %d Mhz\n", freq
);
225 bfd_load(argv
[stat
]);
230 termsave
= fcntl(0, F_GETFL
, 0);
231 INIT_DISASSEMBLE_INFO(dinfo
, stdout
,(fprintf_ftype
)fprintf
);
241 sim_close(int quitting
)
245 fcntl(0, F_SETFL
, termsave
);
249 /* Return non-zero if the caller should handle the load. Zero if
250 we have loaded the image. */
252 int sim_load
PARAMS ((char *prog
, int from_tty
));
255 sim_load(prog
, from_tty
)
263 void sim_create_inferior
PARAMS ((SIM_ADDR start_address
, char **argv
, char **env
));
266 sim_create_inferior(start_address
, argv
, env
)
267 SIM_ADDR start_address
;
274 sregs
.pc
= start_address
& ~3;
275 sregs
.npc
= sregs
.pc
+ 4;
280 sim_store_register(regno
, value
)
282 unsigned char *value
;
284 /* FIXME: Review the computation of regval. */
285 int regval
= (value
[0] << 24) | (value
[1] << 16) | (value
[2] << 8) | value
[3];
286 set_regi(&sregs
, regno
, regval
);
291 sim_fetch_register(regno
, buf
)
295 get_regi(&sregs
, regno
, buf
);
299 sim_write(mem
, buf
, length
)
304 return (sis_memory_write(mem
, buf
, length
));
307 int sim_read
PARAMS ((SIM_ADDR mem
, unsigned char *buf
, int length
));
310 sim_read(mem
, buf
, length
)
315 return (sis_memory_read(mem
, buf
, length
));
319 sim_info(int verbose
)
329 sim_stop_reason(enum sim_stop
* reason
, int *sigrc
)
334 *reason
= sim_stopped
;
340 *reason
= sim_stopped
;
348 *reason
= sim_exited
;
354 /* Flush all register windows out to the stack. Starting after the invalid
355 window, flush all windows up to, and including the current window. This
356 allows GDB to do backtraces and look at local variables for frames that
357 are still in the register windows. Note that strictly speaking, this
358 behavior is *wrong* for several reasons. First, it doesn't use the window
359 overflow handlers. It therefore assumes standard frame layouts and window
360 handling policies. Second, it changes system state behind the back of the
361 target program. I expect this to mainly pose problems when debugging trap
375 /* Keep current window handy */
377 cwp
= sregs
.psr
& PSR_CWP
;
379 /* Calculate the invalid window from the wim. */
381 for (invwin
= 0; invwin
<= PSR_CWP
; invwin
++)
382 if ((sregs
.wim
>> invwin
) & 1)
385 /* Start saving with the window after the invalid window. */
387 invwin
= (invwin
- 1) & PSR_CWP
;
389 for (win
= invwin
; ; win
= (win
- 1) & PSR_CWP
)
394 sp
= sregs
.r
[(win
* 16 + 14) & 0x7f];
396 for (i
= 0; i
< 16; i
++)
397 memory_write (11, sp
+ 4 * i
, &sregs
.r
[(win
* 16 + 16 + i
) & 0x7f], 2,
406 sim_resume(int step
, int siggnal
)
408 simstat
= run_sim(&sregs
, 1, 0, 0);
410 if (sis_gdb_break
) flush_windows ();
416 /* FIXME: unfinished */
430 exec_cmd(&sregs
, cmd
);
433 #if 0 /* FIXME: These shouldn't exist. */
436 sim_insert_breakpoint(int addr
)
438 if (sregs
.bptnum
< BPT_MAX
) {
439 sregs
.bpts
[sregs
.bptnum
] = addr
& ~0x3;
442 (*sim_callback
->printf_filtered
) (sim_callback
, "inserted HW BP at %x\n", addr
);
449 sim_remove_breakpoint(int addr
)
453 while ((i
< sregs
.bptnum
) && (sregs
.bpts
[i
] != addr
))
455 if (addr
== sregs
.bpts
[i
]) {
456 for (; i
< sregs
.bptnum
- 1; i
++)
457 sregs
.bpts
[i
] = sregs
.bpts
[i
+ 1];
460 (*sim_callback
->printf_filtered
) (sim_callback
, "removed HW BP at %x\n", addr
);
This page took 0.039201 seconds and 4 git commands to generate.