0cd655517630a8b2e5a8ae39aa461d971fd3a409
1 /* This file is part of SIS (SPARC instruction simulator)
3 Copyright (C) 1995-2021 Free Software Foundation, Inc.
4 Contributed by Jiri Gaisler, European Space Agency
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* This must come before any other includes. */
26 #include <sys/fcntl.h>
28 #include "libiberty.h"
31 #include "sim-config.h"
34 #include "gdb/signals.h"
38 extern struct disassemble_info dinfo
;
39 extern struct pstate sregs
;
40 extern struct estate ebase
;
48 extern int sis_verbose
;
49 extern char *sis_version
;
50 extern struct estate ebase
;
51 extern struct evcell evbuf
[];
52 extern struct irqcell irqarr
[];
53 extern int irqpend
, ext_irl
;
56 extern int sparclite_board
;
58 extern char uart_dev1
[], uart_dev2
[];
60 int sis_gdb_break
= 1;
62 host_callback
*sim_callback
;
65 run_sim(struct pstate
*sregs
, uint64 icount
, int dis
)
70 (*sim_callback
->printf_filtered
) (sim_callback
, "resuming at %x\n",
73 sregs
->starttime
= get_time();
75 if ((sregs
->pc
!= 0) && (ebase
.simtime
== 0))
77 while (!sregs
->err_mode
& (icount
> 0)) {
83 if (sregs
->psr
& 0x080)
88 #if 0 /* DELETE ME! for debugging purposes only */
90 if (sregs
->pc
== 0 || sregs
->npc
== 0)
91 printf ("bogus pc or npc\n");
93 mexc
= memory_iread (sregs
->pc
, &sregs
->inst
, &sregs
->hold
);
94 #if 0 /* DELETE ME! for debugging purposes only */
96 printf("pc %x, np %x, sp %x, fp %x, wm %x, cw %x, i %08x\n",
97 sregs
->pc
, sregs
->npc
,
98 sregs
->r
[(((sregs
->psr
& 7) << 4) + 14) & 0x7f],
99 sregs
->r
[(((sregs
->psr
& 7) << 4) + 30) & 0x7f],
107 sregs
->pc
= sregs
->npc
;
108 sregs
->npc
= sregs
->npc
+ 4;
110 if (ext_irl
) irq
= check_interrupts(sregs
);
113 sregs
->trap
= I_ACC_EXC
;
115 if ((sis_gdb_break
) && (sregs
->inst
== 0x91d02001)) {
117 (*sim_callback
->printf_filtered
) (sim_callback
,
118 "SW BP hit at %x\n", sregs
->pc
);
124 dispatch_instruction(sregs
);
130 sregs
->err_mode
= execute_trap(sregs
);
139 sregs
->tottime
+= get_time() - sregs
->starttime
;
143 error_mode(sregs
->pc
);
148 (*sim_callback
->printf_filtered
) (sim_callback
,
149 "HW BP hit at %x\n", sregs
->pc
);
160 sim_open (SIM_OPEN_KIND kind
, struct host_callback_struct
*callback
,
161 struct bfd
*abfd
, char * const *argv
)
168 sim_callback
= callback
;
170 argc
= countargv (argv
);
171 while (stat
< argc
) {
172 if (argv
[stat
][0] == '-') {
173 if (strcmp(argv
[stat
], "-v") == 0) {
176 if (strcmp(argv
[stat
], "-nfp") == 0) {
179 if (strcmp(argv
[stat
], "-ift") == 0) {
182 if (strcmp(argv
[stat
], "-sparclite") == 0) {
185 if (strcmp(argv
[stat
], "-sparclite-board") == 0) {
188 if (strcmp(argv
[stat
], "-dumbio") == 0) {
191 if (strcmp(argv
[stat
], "-wrp") == 0) {
194 if (strcmp(argv
[stat
], "-rom8") == 0) {
197 if (strcmp(argv
[stat
], "-uben") == 0) {
200 if (strcmp(argv
[stat
], "-uart1") == 0) {
201 if ((stat
+ 1) < argc
)
202 strcpy(uart_dev1
, argv
[++stat
]);
204 if (strcmp(argv
[stat
], "-uart2") == 0) {
205 if ((stat
+ 1) < argc
)
206 strcpy(uart_dev2
, argv
[++stat
]);
208 if (strcmp(argv
[stat
], "-nogdb") == 0) {
211 if (strcmp(argv
[stat
], "-freq") == 0) {
212 if ((stat
+ 1) < argc
) {
213 freq
= strtol(argv
[++stat
], (char **)NULL
, 0);
216 if (strncmp(argv
[stat
], "--sysroot=", sizeof("--sysroot=") - 1) == 0) {
217 /* Ignore until we start to support this. */
219 (*sim_callback
->printf_filtered
) (sim_callback
,
220 "unknown option %s\n",
224 bfd_load(argv
[stat
]);
229 (*sim_callback
->printf_filtered
) (sim_callback
, "\n SIS - SPARC instruction simulator %s\n", sis_version
);
230 (*sim_callback
->printf_filtered
) (sim_callback
, " Bug-reports to Jiri Gaisler ESA/ESTEC (jgais@wd.estec.esa.nl)\n");
232 (*sim_callback
->printf_filtered
) (sim_callback
, "no FPU\n");
234 (*sim_callback
->printf_filtered
) (sim_callback
, "simulating Sparclite\n");
236 (*sim_callback
->printf_filtered
) (sim_callback
, "dumb IO (no input, dumb output)\n");
237 if (sis_gdb_break
== 0)
238 (*sim_callback
->printf_filtered
) (sim_callback
, "disabling GDB trap handling for breakpoints\n");
240 (*sim_callback
->printf_filtered
) (sim_callback
, " ERC32 freq %d Mhz\n", freq
);
243 sregs
.freq
= freq
? freq
: 15;
245 termsave
= fcntl(0, F_GETFL
, 0);
247 INIT_DISASSEMBLE_INFO(dinfo
, stdout
,(fprintf_ftype
)fprintf
);
248 #ifdef HOST_LITTLE_ENDIAN
249 dinfo
.endian
= BFD_ENDIAN_LITTLE
;
251 dinfo
.endian
= BFD_ENDIAN_BIG
;
259 /* Fudge our descriptor for now. */
264 sim_close(SIM_DESC sd
, int quitting
)
269 fcntl(0, F_SETFL
, termsave
);
274 sim_load(SIM_DESC sd
, const char *prog
, bfd
*abfd
, int from_tty
)
281 sim_create_inferior(SIM_DESC sd
, bfd
*abfd
, char * const *argv
,
284 bfd_vma start_address
= 0;
286 start_address
= bfd_get_start_address (abfd
);
291 sregs
.pc
= start_address
& ~3;
292 sregs
.npc
= sregs
.pc
+ 4;
297 sim_store_register(SIM_DESC sd
, int regno
, unsigned char *value
, int length
)
301 regval
= (value
[0] << 24) | (value
[1] << 16)
302 | (value
[2] << 8) | value
[3];
303 set_regi(&sregs
, regno
, regval
);
309 sim_fetch_register(SIM_DESC sd
, int regno
, unsigned char *buf
, int length
)
311 get_regi(&sregs
, regno
, buf
);
316 sim_write (SIM_DESC sd
, SIM_ADDR mem
, const unsigned char *buf
, int length
)
320 for (i
= 0; i
< length
; i
++) {
321 sis_memory_write ((mem
+ i
) ^ EBT
, &buf
[i
], 1);
327 sim_read (SIM_DESC sd
, SIM_ADDR mem
, unsigned char *buf
, int length
)
331 for (i
= 0; i
< length
; i
++) {
332 sis_memory_read ((mem
+ i
) ^ EBT
, &buf
[i
], 1);
338 sim_info(SIM_DESC sd
, int verbose
)
346 sim_stop_reason(SIM_DESC sd
, enum sim_stop
*reason
, int *sigrc
)
351 *reason
= sim_stopped
;
352 *sigrc
= GDB_SIGNAL_INT
;
357 *reason
= sim_stopped
;
358 *sigrc
= GDB_SIGNAL_TRAP
;
362 *reason
= sim_exited
;
368 /* Flush all register windows out to the stack. Starting after the invalid
369 window, flush all windows up to, and including the current window. This
370 allows GDB to do backtraces and look at local variables for frames that
371 are still in the register windows. Note that strictly speaking, this
372 behavior is *wrong* for several reasons. First, it doesn't use the window
373 overflow handlers. It therefore assumes standard frame layouts and window
374 handling policies. Second, it changes system state behind the back of the
375 target program. I expect this to mainly pose problems when debugging trap
387 /* Keep current window handy */
389 cwp
= sregs
.psr
& PSR_CWP
;
391 /* Calculate the invalid window from the wim. */
393 for (invwin
= 0; invwin
<= PSR_CWP
; invwin
++)
394 if ((sregs
.wim
>> invwin
) & 1)
397 /* Start saving with the window after the invalid window. */
399 invwin
= (invwin
- 1) & PSR_CWP
;
401 for (win
= invwin
; ; win
= (win
- 1) & PSR_CWP
)
406 sp
= sregs
.r
[(win
* 16 + 14) & 0x7f];
408 if (sis_verbose
> 2) {
409 uint32 fp
= sregs
.r
[(win
* 16 + 30) & 0x7f];
410 printf("flush_window: win %d, sp %x, fp %x\n", win
, sp
, fp
);
414 for (i
= 0; i
< 16; i
++)
415 memory_write (11, sp
+ 4 * i
, &sregs
.r
[(win
* 16 + 16 + i
) & 0x7f], 2,
424 sim_resume(SIM_DESC sd
, int step
, int siggnal
)
426 simstat
= run_sim(&sregs
, UINT64_MAX
, 0);
428 if (sis_gdb_break
) flush_windows ();
432 sim_do_command(SIM_DESC sd
, const char *cmd
)
434 exec_cmd(&sregs
, cmd
);
438 sim_complete_command (SIM_DESC sd
, const char *text
, const char *word
)
444 sim_memory_map (SIM_DESC sd
)
449 #if 0 /* FIXME: These shouldn't exist. */
452 sim_insert_breakpoint(int addr
)
454 if (sregs
.bptnum
< BPT_MAX
) {
455 sregs
.bpts
[sregs
.bptnum
] = addr
& ~0x3;
458 (*sim_callback
->printf_filtered
) (sim_callback
, "inserted HW BP at %x\n", addr
);
465 sim_remove_breakpoint(int addr
)
469 while ((i
< sregs
.bptnum
) && (sregs
.bpts
[i
] != addr
))
471 if (addr
== sregs
.bpts
[i
]) {
472 for (; i
< sregs
.bptnum
- 1; i
++)
473 sregs
.bpts
[i
] = sregs
.bpts
[i
+ 1];
476 (*sim_callback
->printf_filtered
) (sim_callback
, "removed HW BP at %x\n", addr
);
This page took 0.038207 seconds and 3 git commands to generate.