* hppa-tdep.c (hppa_push_arguments): Allocate enough space for
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
1 /* Remote debugging interface for generalized simulator
2 Copyright 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Steve Chamberlain
4 (sac@cygnus.com).
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22 #include "defs.h"
23 #include "inferior.h"
24 #include "wait.h"
25 #include "value.h"
26 #include <string.h>
27 #include <ctype.h>
28 #include <fcntl.h>
29 #include <signal.h>
30 #include <setjmp.h>
31 #include <errno.h>
32 #include "terminal.h"
33 #include "target.h"
34 #include "gdbcore.h"
35
36 /* Forward data declarations */
37 extern struct target_ops sim_ops; /* Forward declaration */
38
39 int
40 sim_write_inferior_memory (memaddr, myaddr, len)
41 CORE_ADDR memaddr;
42 unsigned char *myaddr;
43 int len;
44 {
45 return sim_write(memaddr, myaddr, len);
46 }
47
48 static void
49 store_register(regno)
50 int regno;
51 {
52 if (regno == -1)
53 {
54 for (regno = 0; regno < NUM_REGS; regno++)
55 store_register(regno);
56 }
57 else
58 {
59 sim_store_register(regno, read_register(regno));
60 }
61 }
62
63
64 /*
65 * Download a file specified in 'args', to the sim.
66 */
67 static void
68 sim_load(args,fromtty)
69 char *args;
70 int fromtty;
71 {
72 bfd *abfd;
73 asection *s;
74
75 inferior_pid = 0;
76 abfd = bfd_openr(args, (char*)0);
77
78 if (!abfd)
79 {
80 printf_filtered("Unable to open file %s\n", args);
81 return;
82 }
83
84 if (bfd_check_format(abfd, bfd_object) ==0)
85 {
86 printf_filtered("File is not an object file\n");
87 return ;
88 }
89
90 s = abfd->sections;
91 while (s != (asection *)NULL)
92 {
93 if (s->flags & SEC_LOAD)
94 {
95 int i;
96 int delta = 4096;
97 char *buffer = xmalloc(delta);
98 printf_filtered("%s\t: 0x%4x .. 0x%4x ",
99 s->name, s->vma, s->vma + s->_raw_size);
100 for (i = 0; i < s->_raw_size; i+= delta)
101 {
102 int sub_delta = delta;
103 if (sub_delta > s->_raw_size - i)
104 sub_delta = s->_raw_size - i ;
105
106 bfd_get_section_contents(abfd, s, buffer, i, sub_delta);
107 sim_write_inferior_memory(s->vma + i, buffer, sub_delta);
108 printf_filtered("*");
109 fflush(stdout);
110 }
111 printf_filtered( "\n");
112 free(buffer);
113 }
114 s = s->next;
115 }
116
117 sim_store_register(PC_REGNUM, abfd->start_address);
118 }
119
120 /* This is called not only when we first attach, but also when the
121 user types "run" after having attached. */
122 void
123 sim_create_inferior (execfile, args, env)
124 char *execfile;
125 char *args;
126 char **env;
127 {
128 int entry_pt;
129
130 if (args && *args)
131 error ("Can't pass arguments to remote sim process.");
132
133 if (execfile == 0 || exec_bfd == 0)
134 error ("No exec file specified");
135
136 entry_pt = (int) bfd_get_start_address (exec_bfd);
137 init_wait_for_inferior ();
138 insert_breakpoints ();
139 proceed(entry_pt, -1, 0);
140 }
141
142
143
144 static void
145 sim_open (name, from_tty)
146 char *name;
147 int from_tty;
148 {
149 if(name == 0)
150 {
151 name = "";
152 }
153 push_target (&sim_ops);
154 target_fetch_registers(-1);
155 printf_filtered("Connected to the simulator.\n");
156 }
157
158 /* Close out all files and local state before this target loses control. */
159
160 static void
161 sim_close (quitting)
162 int quitting;
163 {
164 }
165
166 /* Terminate the open connection to the remote debugger.
167 Use this when you want to detach and do something else
168 with your gdb. */
169 void
170 sim_detach (args,from_tty)
171 char *args;
172 int from_tty;
173 {
174 pop_target(); /* calls sim_close to do the real work */
175 if (from_tty)
176 printf_filtered ("Ending remote %s debugging\n", target_shortname);
177
178 }
179
180 /* Tell the remote machine to resume. */
181
182
183 /* Wait until the remote machine stops, then return,
184 storing status in STATUS just as `wait' would. */
185
186 int
187 sim_wait (status)
188 WAITTYPE *status;
189 {
190 WSETSTOP(*status, sim_stop_signal());
191 return 0;
192 }
193
194 static void
195 fetch_register(regno)
196 int regno;
197 {
198 if (regno == -1)
199 {
200 for (regno = 0; regno < NUM_REGS; regno++)
201 fetch_register(regno);
202 }
203 else
204 {
205 char buf[MAX_REGISTER_RAW_SIZE];
206
207 sim_fetch_register(regno, buf);
208 supply_register(regno, buf);
209 }
210 }
211
212
213 int
214 sim_xfer_inferior_memory(memaddr, myaddr, len, write, target)
215 CORE_ADDR memaddr;
216 char *myaddr;
217 int len;
218 int write;
219 struct target_ops *target; /* ignored */
220 {
221 if (write)
222 {
223 sim_write(memaddr, myaddr, len);
224 }
225 else
226 {
227 sim_read(memaddr, myaddr, len);
228 }
229 return len;
230 }
231
232
233 /* This routine is run as a hook, just before the main command loop is
234 entered. If gdb is configured for the H8, but has not had its
235 target specified yet, this will loop prompting the user to do so.
236 */
237
238 void
239 sim_before_main_loop ()
240 {
241 push_target (&sim_ops);
242 }
243
244
245 static void rem_resume(a,b)
246 {
247 sim_resume(a,b);
248 }
249
250 void
251 pstore()
252 {
253 }
254 /* Define the target subroutine names */
255
256 struct target_ops sim_ops =
257 {
258 "sim", "simulator",
259 "Use the simulator",
260 sim_open, sim_close,
261 0, sim_detach, rem_resume, sim_wait, /* attach */
262 fetch_register, store_register,
263 pstore,
264 sim_xfer_inferior_memory,
265 0,
266 0, 0, /* Breakpoints */
267 0, 0, 0, 0, 0, /* Terminal handling */
268 pstore,
269 sim_load,
270 0, /* lookup_symbol */
271 sim_create_inferior, /* create_inferior */
272 pstore, /* mourn_inferior FIXME */
273 0, /* can_run */
274 0, /* notice_signals */
275 process_stratum, 0, /* next */
276 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
277 0,0, /* Section pointers */
278 OPS_MAGIC, /* Always the last thing */
279 };
280
281 /***********************************************************************/
282
283 void
284 _initialize_remote_sim ()
285 {
286 add_target (&sim_ops);
287 }
288
289
This page took 0.034697 seconds and 4 git commands to generate.