2a3f331cb96e7aac72734ff8987004a2f72aba76
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
);
123 dispatch_instruction(sregs
);
128 sregs
->err_mode
= execute_trap(sregs
);
137 sregs
->tottime
+= time(NULL
) - sregs
->starttime
;
141 error_mode(sregs
->pc
);
146 (*sim_callback
->printf_filtered
) (sim_callback
,
147 "HW BP hit at %x\n", sregs
->pc
);
158 sim_set_callbacks (sd
, ptr
)
183 (*sim_callback
->printf_filtered
) (sim_callback
, "\n SIS - SPARC instruction simulator %s\n", sis_version
);
184 (*sim_callback
->printf_filtered
) (sim_callback
, " Bug-reports to Jiri Gaisler ESA/ESTEC (jgais@wd.estec.esa.nl)\n");
187 while (stat
< argc
) {
188 if (argv
[stat
][0] == '-') {
189 if (strcmp(argv
[stat
], "-v") == 0) {
192 if (strcmp(argv
[stat
], "-nfp") == 0) {
193 (*sim_callback
->printf_filtered
) (sim_callback
, "no FPU\n");
196 if (strcmp(argv
[stat
], "-ift") == 0) {
199 if (strcmp(argv
[stat
], "-sparclite") == 0) {
200 (*sim_callback
->printf_filtered
) (sim_callback
, "simulating Sparclite\n");
203 if (strcmp(argv
[stat
], "-wrp") == 0) {
206 if (strcmp(argv
[stat
], "-rom8") == 0) {
209 if (strcmp(argv
[stat
], "-uart1") == 0) {
210 if ((stat
+ 1) < argc
)
211 strcpy(uart_dev1
, argv
[++stat
]);
213 if (strcmp(argv
[stat
], "-uart2") == 0) {
214 if ((stat
+ 1) < argc
)
215 strcpy(uart_dev2
, argv
[++stat
]);
217 if (strcmp(argv
[stat
], "-nogdb") == 0) {
218 (*sim_callback
->printf_filtered
) (sim_callback
, "disabling GDB trap handling for breakpoints\n");
221 if (strcmp(argv
[stat
], "-freq") == 0)
222 if ((stat
+ 1) < argc
) {
223 freq
= VAL(argv
[++stat
]);
224 (*sim_callback
->printf_filtered
) (sim_callback
, " ERC32 freq %d Mhz\n", freq
);
227 bfd_load(argv
[stat
]);
231 termsave
= fcntl(0, F_GETFL
, 0);
232 INIT_DISASSEMBLE_INFO(dinfo
, stdout
,(fprintf_ftype
)fprintf
);
233 dinfo
.endian
= BFD_ENDIAN_BIG
;
241 /* Fudge our descriptor for now. */
246 sim_close(sd
, quitting
)
252 fcntl(0, F_SETFL
, termsave
);
256 /* For communication from sim_load to sim_create_inferior. */
257 static bfd_vma start_address
;
260 sim_load(sd
, prog
, abfd
, from_tty
)
266 start_address
= bfd_load (prog
);
271 sim_create_inferior(sd
, argv
, env
)
279 sregs
.pc
= start_address
& ~3;
280 sregs
.npc
= sregs
.pc
+ 4;
285 sim_store_register(sd
, regno
, value
)
288 unsigned char *value
;
290 /* FIXME: Review the computation of regval. */
291 int regval
= (value
[0] << 24) | (value
[1] << 16) | (value
[2] << 8) | value
[3];
292 set_regi(&sregs
, regno
, regval
);
297 sim_fetch_register(sd
, regno
, buf
)
302 get_regi(&sregs
, regno
, buf
);
306 sim_write(sd
, mem
, buf
, length
)
312 return (sis_memory_write(mem
, buf
, length
));
316 sim_read(sd
, mem
, buf
, length
)
322 return (sis_memory_read(mem
, buf
, length
));
326 sim_info(sd
, verbose
)
336 sim_stop_reason(sd
, reason
, sigrc
)
338 enum sim_stop
* reason
;
344 *reason
= sim_stopped
;
350 *reason
= sim_stopped
;
358 *reason
= sim_exited
;
364 /* Flush all register windows out to the stack. Starting after the invalid
365 window, flush all windows up to, and including the current window. This
366 allows GDB to do backtraces and look at local variables for frames that
367 are still in the register windows. Note that strictly speaking, this
368 behavior is *wrong* for several reasons. First, it doesn't use the window
369 overflow handlers. It therefore assumes standard frame layouts and window
370 handling policies. Second, it changes system state behind the back of the
371 target program. I expect this to mainly pose problems when debugging trap
385 /* Keep current window handy */
387 cwp
= sregs
.psr
& PSR_CWP
;
389 /* Calculate the invalid window from the wim. */
391 for (invwin
= 0; invwin
<= PSR_CWP
; invwin
++)
392 if ((sregs
.wim
>> invwin
) & 1)
395 /* Start saving with the window after the invalid window. */
397 invwin
= (invwin
- 1) & PSR_CWP
;
399 for (win
= invwin
; ; win
= (win
- 1) & PSR_CWP
)
404 sp
= sregs
.r
[(win
* 16 + 14) & 0x7f];
406 for (i
= 0; i
< 16; i
++)
407 memory_write (11, sp
+ 4 * i
, &sregs
.r
[(win
* 16 + 16 + i
) & 0x7f], 2,
416 sim_resume(SIM_DESC sd
, int step
, int siggnal
)
418 simstat
= run_sim(&sregs
, 1, 0, 0);
420 if (sis_gdb_break
) flush_windows ();
427 /* FIXME: unfinished */
428 sim_resume (sd
, 0, 0);
433 sim_kill(SIM_DESC sd
)
438 sim_do_command(sd
, cmd
)
442 exec_cmd(&sregs
, cmd
);
445 #if 0 /* FIXME: These shouldn't exist. */
448 sim_insert_breakpoint(int addr
)
450 if (sregs
.bptnum
< BPT_MAX
) {
451 sregs
.bpts
[sregs
.bptnum
] = addr
& ~0x3;
454 (*sim_callback
->printf_filtered
) (sim_callback
, "inserted HW BP at %x\n", addr
);
461 sim_remove_breakpoint(int addr
)
465 while ((i
< sregs
.bptnum
) && (sregs
.bpts
[i
] != addr
))
467 if (addr
== sregs
.bpts
[i
]) {
468 for (; i
< sregs
.bptnum
- 1; i
++)
469 sregs
.bpts
[i
] = sregs
.bpts
[i
+ 1];
472 (*sim_callback
->printf_filtered
) (sim_callback
, "removed HW BP at %x\n", addr
);
This page took 0.039637 seconds and 4 git commands to generate.