* gdb/testsuite: Initial creation of gdb/testsuite.
[deliverable/binutils-gdb.git] / gdb / remote-sim.c
CommitLineData
ec25d19b
SC
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
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, 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 */
37extern struct target_ops sim_ops; /* Forward declaration */
38
39int
40sim_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
a944e79a 48static void
ec25d19b
SC
49store_register(regno)
50int 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 }
ec25d19b
SC
61}
62
63
64/*
65 * Download a file specified in 'args', to the sim.
66 */
67static void
68sim_load(args,fromtty)
69char *args;
70int 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. */
122void
123sim_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
a944e79a 144static void
ec25d19b
SC
145sim_open (name, from_tty)
146 char *name;
147 int from_tty;
148{
149 if(name == 0)
150 {
151 name = "";
152 }
ec25d19b
SC
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
a944e79a 160static void
ec25d19b
SC
161sim_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. */
a944e79a 169void
ec25d19b
SC
170sim_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);
a944e79a 177
ec25d19b
SC
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
186int
187sim_wait (status)
188 WAITTYPE *status;
189{
190 WSETSTOP(*status, sim_stop_signal());
191 return 0;
192}
193
194
195
196static void
197fetch_register(regno)
198int regno;
199{
200 if (regno == -1)
201 {
202 for (regno = 0; regno < NUM_REGS; regno++)
203 fetch_register(regno);
204 }
205 else
206 {
207 char buf[MAX_REGISTER_RAW_SIZE];
208 sim_fetch_register(regno, buf);
209 supply_register(regno, buf);
210 }
211}
212
213
214int
215sim_xfer_inferior_memory(memaddr, myaddr, len, write, target)
216 CORE_ADDR memaddr;
217 char *myaddr;
218 int len;
219 int write;
220 struct target_ops *target; /* ignored */
221{
222 if (write)
223 {
224 sim_write(memaddr, myaddr, len);
225 }
226 else
227 {
228 sim_read(memaddr, myaddr, len);
229 }
230 return len;
231}
232
233
234/* This routine is run as a hook, just before the main command loop is
235 entered. If gdb is configured for the H8, but has not had its
236 target specified yet, this will loop prompting the user to do so.
237*/
238
239void
240sim_before_main_loop ()
241{
242 push_target (&sim_ops);
243}
244
245
a944e79a 246static void rem_resume(a,b)
ec25d19b
SC
247{
248 sim_resume(a,b);
ec25d19b
SC
249}
250
a944e79a 251void
ec25d19b
SC
252pstore()
253{
ec25d19b
SC
254}
255/* Define the target subroutine names */
256
257struct target_ops sim_ops =
258{
259 "sim", "simulator",
260 "Use the simulator",
261 sim_open, sim_close,
262 0, sim_detach, rem_resume, sim_wait, /* attach */
263 fetch_register, store_register,
264 pstore,
265 sim_xfer_inferior_memory,
266 0,
267 0, 0, /* Breakpoints */
268 0, 0, 0, 0, 0, /* Terminal handling */
269 pstore,
270 sim_load,
271 0, /* lookup_symbol */
272 sim_create_inferior, /* create_inferior */
273 pstore, /* mourn_inferior FIXME */
274 0, /* can_run */
275 0, /* notice_signals */
276 process_stratum, 0, /* next */
277 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
278 0,0, /* Section pointers */
279 OPS_MAGIC, /* Always the last thing */
280};
281
282/***********************************************************************/
283
284void
285_initialize_remote_sim ()
286{
287 add_target (&sim_ops);
288}
289
290
This page took 0.041467 seconds and 4 git commands to generate.