* i386.h: Correct opcode values for fsubp, fsubrp, fdivp, and
[deliverable/binutils-gdb.git] / gdb / gdbserver / low-sim.c
CommitLineData
33ef0f93
MA
1/* Low level interface to simulators, for the remote server for GDB.
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "bfd.h"
22#include "server.h"
23#include "callback.h" /* GDB simulator callback interface */
24#include "remote-sim.h" /* GDB simulator interface */
25
26extern host_callback default_callback; /* in callback.c */
27
28char registers[REGISTER_BYTES];
29
30int target_byte_order; /* used by simulator */
31
32/* This version of "load" should be usable for any simulator that
33 does not support loading itself. */
34
35static void
36generic_load (loadfile_bfd)
37 bfd *loadfile_bfd;
38{
39 asection *s;
40
41 for (s = loadfile_bfd->sections; s; s = s->next)
42 {
43 if (s->flags & SEC_LOAD)
44 {
45 bfd_size_type size;
46
47 size = bfd_get_section_size_before_reloc (s);
48 if (size > 0)
49 {
50 char *buffer;
51 bfd_vma vma;
52
53 buffer = xmalloc (size);
54 vma = bfd_get_section_vma (loadfile_bfd, s);
55
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),
60 (unsigned long) size,
61 (unsigned long) vma); /* chops high 32 bits. FIXME!! */
62
63 bfd_get_section_contents (loadfile_bfd, s, buffer, 0, size);
64
65 write_inferior_memory (vma, buffer, size);
66 free (buffer);
67 }
68 }
69 }
70
71 fprintf (stderr, "Start address 0x%lx\n",
72 (unsigned long)loadfile_bfd->start_address);
73
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!! */
77}
78
79int
80create_inferior (program, allargs)
81 char *program;
82 char **allargs;
83{
84 bfd *abfd;
85 int pid = 0;
86
87 abfd = bfd_openr (program, 0);
88 if (!abfd)
89 {
90 fprintf (stderr, "gdbserver: can't open %s: %s\n",
91 program, bfd_errmsg (bfd_get_error ()));
92 exit (1);
93 }
94
95 if (!bfd_check_format (abfd, bfd_object))
96 {
97 fprintf (stderr, "gdbserver: unknown load format for %s: %s\n",
98 program, bfd_errmsg (bfd_get_error ()));
99 exit (1);
100 }
101
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;
105
106 sim_set_callbacks (&default_callback);
107 default_callback.init (&default_callback);
108
109 /* Should concatenate args here. FIXME!! */
110 sim_open (allargs[0]);
111
112 /* Load program. */
113 if (sim_load (allargs[0], 0) != 0)
114 generic_load (abfd);
115
116 return pid;
117}
118
119/* Kill the inferior process. Make us have no inferior. */
120
121void
122kill_inferior ()
123{
124 sim_close (0);
125 default_callback.shutdown (&default_callback);
126}
127
128/* Fetch one register. */
129
130static void
131fetch_register (regno)
132 int regno;
133{
134 sim_fetch_register (regno, &registers[REGISTER_BYTE (regno)]);
135}
136
137/* Fetch all registers, or just one, from the child process. */
138
139void
140fetch_inferior_registers (regno)
141 int regno;
142{
143 if (regno == -1 || regno == 0)
144 for (regno = 0; regno < NUM_REGS/*-NUM_FREGS*/; regno++)
145 fetch_register (regno);
146 else
147 fetch_register (regno);
148}
149
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). */
153
154void
155store_inferior_registers (regno)
156 int regno;
157{
158 if (regno == -1)
159 {
160 for (regno = 0; regno < NUM_REGS; regno++)
161 store_inferior_registers (regno);
162 }
163 else
164 sim_store_register (regno, &registers[REGISTER_BYTE (regno)]);
165}
166
167/* Return nonzero if the given thread is still alive. */
168int
169mythread_alive (pid)
170 int pid;
171{
172 return 1;
173}
174
175/* Wait for process, returns status */
176
177unsigned char
178mywait (status)
179 char *status;
180{
181 int sigrc;
182 enum sim_stop reason;
183
184 sim_stop_reason (&reason, &sigrc);
185 switch (reason)
186 {
187 case sim_exited:
188 fprintf (stderr, "\nChild exited with retcode = %x \n", sigrc);
189 *status = 'W';
190 return sigrc;
191
192#if 0
193 case sim_stopped:
194 fprintf (stderr, "\nChild terminated with signal = %x \n", sigrc);
195 *status = 'X';
196 return sigrc;
197#endif
198
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);
202 *status = 'T';
203 return (unsigned char) sigrc;
204 }
205}
206
207/* Resume execution of the inferior process.
208 If STEP is nonzero, single-step it.
209 If SIGNAL is nonzero, give it that signal. */
210
211void
212myresume (step, signo)
213 int step;
214 int signo;
215{
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);
219}
220
221/* Copy LEN bytes from inferior's memory starting at MEMADDR
222 to debugger memory starting at MYADDR. */
223
224void
225read_inferior_memory (memaddr, myaddr, len)
226 CORE_ADDR memaddr;
227 char *myaddr;
228 int len;
229{
230 sim_read (memaddr, myaddr, len);
231}
232
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. */
237
238int
239write_inferior_memory (memaddr, myaddr, len)
240 CORE_ADDR memaddr;
241 char *myaddr;
242 int len;
243{
244 sim_write (memaddr, myaddr, len); /* should check for error. FIXME!! */
245 return 0;
246}
247
248#if 0
249void
250initialize ()
251{
252 inferior_pid = 0;
253}
254
255int
256have_inferior_p ()
257{
258 return inferior_pid != 0;
259}
260#endif
This page took 0.034865 seconds and 4 git commands to generate.