1 /* Low level interface to simulators, for the remote server for GDB.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
4 This file is part of GDB.
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 2 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "callback.h" /* GDB simulator callback interface */
24 #include "remote-sim.h" /* GDB simulator interface */
26 extern host_callback default_callback
; /* in callback.c */
28 char registers
[REGISTER_BYTES
];
30 int target_byte_order
; /* used by simulator */
32 /* This version of "load" should be usable for any simulator that
33 does not support loading itself. */
36 generic_load (loadfile_bfd
)
41 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
43 if (s
->flags
& SEC_LOAD
)
47 size
= bfd_get_section_size_before_reloc (s
);
53 buffer
= xmalloc (size
);
54 vma
= bfd_get_section_vma (loadfile_bfd
, s
);
56 /* Is this really necessary? I guess it gives the user something
57 to look at during a long download. */
58 fprintf (stderr
, "Loading section %s, size 0x%lx vma 0x%lx\n",
59 bfd_get_section_name (loadfile_bfd
, s
),
61 (unsigned long) vma
); /* chops high 32 bits. FIXME!! */
63 bfd_get_section_contents (loadfile_bfd
, s
, buffer
, 0, size
);
65 write_inferior_memory (vma
, buffer
, size
);
71 fprintf (stderr
, "Start address 0x%lx\n",
72 (unsigned long)loadfile_bfd
->start_address
);
74 /* We were doing this in remote-mips.c, I suspect it is right
75 for other targets too. */
76 /* write_pc (loadfile_bfd->start_address); */ /* FIXME!! */
80 create_inferior (program
, allargs
)
87 abfd
= bfd_openr (program
, 0);
90 fprintf (stderr
, "gdbserver: can't open %s: %s\n",
91 program
, bfd_errmsg (bfd_get_error ()));
95 if (!bfd_check_format (abfd
, bfd_object
))
97 fprintf (stderr
, "gdbserver: unknown load format for %s: %s\n",
98 program
, bfd_errmsg (bfd_get_error ()));
102 /* This must be set before sim_open is called, because gdb assumes that
103 the simulator endianness is known immediately after the sim_open call. */
104 target_byte_order
= bfd_big_endian (abfd
) ? 4321 : 1234;
106 sim_set_callbacks (&default_callback
);
107 default_callback
.init (&default_callback
);
109 /* Should concatenate args here. FIXME!! */
110 sim_open (allargs
[0]);
113 if (sim_load (allargs
[0], 0) != 0)
119 /* Kill the inferior process. Make us have no inferior. */
125 default_callback
.shutdown (&default_callback
);
128 /* Fetch one register. */
131 fetch_register (regno
)
134 sim_fetch_register (regno
, ®isters
[REGISTER_BYTE (regno
)]);
137 /* Fetch all registers, or just one, from the child process. */
140 fetch_inferior_registers (regno
)
143 if (regno
== -1 || regno
== 0)
144 for (regno
= 0; regno
< NUM_REGS
/*-NUM_FREGS*/; regno
++)
145 fetch_register (regno
);
147 fetch_register (regno
);
150 /* Store our register values back into the inferior.
151 If REGNO is -1, do this for all registers.
152 Otherwise, REGNO specifies which register (so we can save time). */
155 store_inferior_registers (regno
)
160 for (regno
= 0; regno
< NUM_REGS
; regno
++)
161 store_inferior_registers (regno
);
164 sim_store_register (regno
, ®isters
[REGISTER_BYTE (regno
)]);
167 /* Return nonzero if the given thread is still alive. */
175 /* Wait for process, returns status */
182 enum sim_stop reason
;
184 sim_stop_reason (&reason
, &sigrc
);
188 fprintf (stderr
, "\nChild exited with retcode = %x \n", sigrc
);
194 fprintf (stderr
, "\nChild terminated with signal = %x \n", sigrc
);
199 default: /* should this be sim_signalled or sim_stopped? FIXME!! */
200 fprintf (stderr
, "\nChild received signal = %x \n", sigrc
);
201 fetch_inferior_registers (0);
203 return (unsigned char) sigrc
;
207 /* Resume execution of the inferior process.
208 If STEP is nonzero, single-step it.
209 If SIGNAL is nonzero, give it that signal. */
212 myresume (step
, signo
)
216 /* Should be using target_signal_to_host() or signal numbers in target.h
217 to convert GDB signal number to target signal number. */
218 sim_resume (step
, signo
);
221 /* Copy LEN bytes from inferior's memory starting at MEMADDR
222 to debugger memory starting at MYADDR. */
225 read_inferior_memory (memaddr
, myaddr
, len
)
230 sim_read (memaddr
, myaddr
, len
);
233 /* Copy LEN bytes of data from debugger memory at MYADDR
234 to inferior's memory at MEMADDR.
235 On failure (cannot write the inferior)
236 returns the value of errno. */
239 write_inferior_memory (memaddr
, myaddr
, len
)
244 sim_write (memaddr
, myaddr
, len
); /* should check for error. FIXME!! */
258 return inferior_pid
!= 0;