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 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/>.
27 #include <sys/fcntl.h>
29 #include "libiberty.h"
32 #include "sim-config.h"
34 #include "gdb/remote-sim.h"
35 #include "gdb/signals.h"
39 extern struct disassemble_info dinfo
;
40 extern struct pstate sregs
;
41 extern struct estate ebase
;
49 extern int sis_verbose
;
50 extern char *sis_version
;
51 extern struct estate ebase
;
52 extern struct evcell evbuf
[];
53 extern struct irqcell irqarr
[];
54 extern int irqpend
, ext_irl
;
57 extern int sparclite_board
;
59 extern char uart_dev1
[], uart_dev2
[];
61 int sis_gdb_break
= 1;
63 host_callback
*sim_callback
;
66 run_sim(sregs
, icount
, dis
)
74 (*sim_callback
->printf_filtered
) (sim_callback
, "resuming at %x\n",
77 sregs
->starttime
= get_time();
79 if ((sregs
->pc
!= 0) && (ebase
.simtime
== 0))
81 while (!sregs
->err_mode
& (icount
> 0)) {
87 if (sregs
->psr
& 0x080)
92 #if 0 /* DELETE ME! for debugging purposes only */
94 if (sregs
->pc
== 0 || sregs
->npc
== 0)
95 printf ("bogus pc or npc\n");
97 mexc
= memory_iread (sregs
->pc
, &sregs
->inst
, &sregs
->hold
);
98 #if 0 /* DELETE ME! for debugging purposes only */
100 printf("pc %x, np %x, sp %x, fp %x, wm %x, cw %x, i %08x\n",
101 sregs
->pc
, sregs
->npc
,
102 sregs
->r
[(((sregs
->psr
& 7) << 4) + 14) & 0x7f],
103 sregs
->r
[(((sregs
->psr
& 7) << 4) + 30) & 0x7f],
111 sregs
->pc
= sregs
->npc
;
112 sregs
->npc
= sregs
->npc
+ 4;
114 if (ext_irl
) irq
= check_interrupts(sregs
);
117 sregs
->trap
= I_ACC_EXC
;
119 if ((sis_gdb_break
) && (sregs
->inst
== 0x91d02001)) {
121 (*sim_callback
->printf_filtered
) (sim_callback
,
122 "SW BP hit at %x\n", sregs
->pc
);
128 dispatch_instruction(sregs
);
134 sregs
->err_mode
= execute_trap(sregs
);
143 sregs
->tottime
+= get_time() - sregs
->starttime
;
147 error_mode(sregs
->pc
);
152 (*sim_callback
->printf_filtered
) (sim_callback
,
153 "HW BP hit at %x\n", sregs
->pc
);
164 sim_open (kind
, callback
, abfd
, argv
)
166 struct host_callback_struct
*callback
;
175 sim_callback
= callback
;
179 while (stat
< argc
) {
180 if (argv
[stat
][0] == '-') {
181 if (strcmp(argv
[stat
], "-v") == 0) {
184 if (strcmp(argv
[stat
], "-nfp") == 0) {
187 if (strcmp(argv
[stat
], "-ift") == 0) {
190 if (strcmp(argv
[stat
], "-sparclite") == 0) {
193 if (strcmp(argv
[stat
], "-sparclite-board") == 0) {
196 if (strcmp(argv
[stat
], "-dumbio") == 0) {
199 if (strcmp(argv
[stat
], "-wrp") == 0) {
202 if (strcmp(argv
[stat
], "-rom8") == 0) {
205 if (strcmp(argv
[stat
], "-uben") == 0) {
208 if (strcmp(argv
[stat
], "-uart1") == 0) {
209 if ((stat
+ 1) < argc
)
210 strcpy(uart_dev1
, argv
[++stat
]);
212 if (strcmp(argv
[stat
], "-uart2") == 0) {
213 if ((stat
+ 1) < argc
)
214 strcpy(uart_dev2
, argv
[++stat
]);
216 if (strcmp(argv
[stat
], "-nogdb") == 0) {
219 if (strcmp(argv
[stat
], "-freq") == 0) {
220 if ((stat
+ 1) < argc
) {
221 freq
= strtol(argv
[++stat
], (char **)NULL
, 0);
224 if (strncmp(argv
[stat
], "--sysroot=", sizeof("--sysroot=") - 1) == 0) {
225 /* Ignore until we start to support this. */
227 (*sim_callback
->printf_filtered
) (sim_callback
,
228 "unknown option %s\n",
232 bfd_load(argv
[stat
]);
237 (*sim_callback
->printf_filtered
) (sim_callback
, "\n SIS - SPARC instruction simulator %s\n", sis_version
);
238 (*sim_callback
->printf_filtered
) (sim_callback
, " Bug-reports to Jiri Gaisler ESA/ESTEC (jgais@wd.estec.esa.nl)\n");
240 (*sim_callback
->printf_filtered
) (sim_callback
, "no FPU\n");
242 (*sim_callback
->printf_filtered
) (sim_callback
, "simulating Sparclite\n");
244 (*sim_callback
->printf_filtered
) (sim_callback
, "dumb IO (no input, dumb output)\n");
245 if (sis_gdb_break
== 0)
246 (*sim_callback
->printf_filtered
) (sim_callback
, "disabling GDB trap handling for breakpoints\n");
248 (*sim_callback
->printf_filtered
) (sim_callback
, " ERC32 freq %d Mhz\n", freq
);
251 sregs
.freq
= freq
? freq
: 15;
252 termsave
= fcntl(0, F_GETFL
, 0);
253 INIT_DISASSEMBLE_INFO(dinfo
, stdout
,(fprintf_ftype
)fprintf
);
254 #ifdef HOST_LITTLE_ENDIAN
255 dinfo
.endian
= BFD_ENDIAN_LITTLE
;
257 dinfo
.endian
= BFD_ENDIAN_BIG
;
265 /* Fudge our descriptor for now. */
270 sim_close(sd
, quitting
)
276 fcntl(0, F_SETFL
, termsave
);
281 sim_load(sd
, prog
, abfd
, from_tty
)
292 sim_create_inferior(sd
, abfd
, argv
, env
)
298 bfd_vma start_address
= 0;
300 start_address
= bfd_get_start_address (abfd
);
305 sregs
.pc
= start_address
& ~3;
306 sregs
.npc
= sregs
.pc
+ 4;
311 sim_store_register(sd
, regno
, value
, length
)
314 unsigned char *value
;
319 regval
= (value
[0] << 24) | (value
[1] << 16)
320 | (value
[2] << 8) | value
[3];
321 set_regi(&sregs
, regno
, regval
);
327 sim_fetch_register(sd
, regno
, buf
, length
)
333 get_regi(&sregs
, regno
, buf
);
338 sim_write (SIM_DESC sd
, SIM_ADDR mem
, const unsigned char *buf
, int length
)
342 for (i
= 0; i
< length
; i
++) {
343 sis_memory_write ((mem
+ i
) ^ EBT
, &buf
[i
], 1);
349 sim_read (SIM_DESC sd
, SIM_ADDR mem
, unsigned char *buf
, int length
)
353 for (i
= 0; i
< length
; i
++) {
354 sis_memory_read ((mem
+ i
) ^ EBT
, &buf
[i
], 1);
360 sim_info(sd
, verbose
)
370 sim_stop_reason(sd
, reason
, sigrc
)
372 enum sim_stop
* reason
;
378 *reason
= sim_stopped
;
379 *sigrc
= GDB_SIGNAL_INT
;
384 *reason
= sim_stopped
;
385 *sigrc
= GDB_SIGNAL_TRAP
;
389 *reason
= sim_exited
;
395 /* Flush all register windows out to the stack. Starting after the invalid
396 window, flush all windows up to, and including the current window. This
397 allows GDB to do backtraces and look at local variables for frames that
398 are still in the register windows. Note that strictly speaking, this
399 behavior is *wrong* for several reasons. First, it doesn't use the window
400 overflow handlers. It therefore assumes standard frame layouts and window
401 handling policies. Second, it changes system state behind the back of the
402 target program. I expect this to mainly pose problems when debugging trap
414 /* Keep current window handy */
416 cwp
= sregs
.psr
& PSR_CWP
;
418 /* Calculate the invalid window from the wim. */
420 for (invwin
= 0; invwin
<= PSR_CWP
; invwin
++)
421 if ((sregs
.wim
>> invwin
) & 1)
424 /* Start saving with the window after the invalid window. */
426 invwin
= (invwin
- 1) & PSR_CWP
;
428 for (win
= invwin
; ; win
= (win
- 1) & PSR_CWP
)
433 sp
= sregs
.r
[(win
* 16 + 14) & 0x7f];
435 if (sis_verbose
> 2) {
436 uint32 fp
= sregs
.r
[(win
* 16 + 30) & 0x7f];
437 printf("flush_window: win %d, sp %x, fp %x\n", win
, sp
, fp
);
441 for (i
= 0; i
< 16; i
++)
442 memory_write (11, sp
+ 4 * i
, &sregs
.r
[(win
* 16 + 16 + i
) & 0x7f], 2,
451 sim_resume(SIM_DESC sd
, int step
, int siggnal
)
453 simstat
= run_sim(&sregs
, UINT64_MAX
, 0);
455 if (sis_gdb_break
) flush_windows ();
459 sim_do_command(sd
, cmd
)
463 exec_cmd(&sregs
, cmd
);
467 sim_complete_command (SIM_DESC sd
, const char *text
, const char *word
)
472 #if 0 /* FIXME: These shouldn't exist. */
475 sim_insert_breakpoint(int addr
)
477 if (sregs
.bptnum
< BPT_MAX
) {
478 sregs
.bpts
[sregs
.bptnum
] = addr
& ~0x3;
481 (*sim_callback
->printf_filtered
) (sim_callback
, "inserted HW BP at %x\n", addr
);
488 sim_remove_breakpoint(int addr
)
492 while ((i
< sregs
.bptnum
) && (sregs
.bpts
[i
] != addr
))
494 if (addr
== sregs
.bpts
[i
]) {
495 for (; i
< sregs
.bptnum
- 1; i
++)
496 sregs
.bpts
[i
] = sregs
.bpts
[i
+ 1];
499 (*sim_callback
->printf_filtered
) (sim_callback
, "removed HW BP at %x\n", addr
);
This page took 0.047909 seconds and 4 git commands to generate.