Path modification
[deliverable/binutils-gdb.git] / gdb / remote-z8k.c
1 /* Remote debugging interface for Zilog Z8000 simulator
2 Copyright 1992,1993 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 #include "../../sim/sim.h"
36
37 /* External data declarations */
38 extern int stop_soon_quietly; /* for wait_for_inferior */
39
40 /* Forward data declarations */
41 extern struct target_ops sim_ops; /* Forward declaration */
42
43 void sim_store_register();
44 void sim_set_oc();
45
46
47 int
48 sim_write_inferior_memory (memaddr, myaddr, len)
49 CORE_ADDR memaddr;
50 unsigned char *myaddr;
51 int len;
52 {
53 sim_write(memaddr, myaddr, len);
54 return 1;
55 }
56
57 static void
58 store_register(regno)
59 int regno;
60 {
61 if (regno == -1)
62 {
63 for (regno = 0; regno < 16; regno++)
64 {
65 store_register(regno);
66 }
67 }
68 else
69 {
70 sim_store_register(regno,read_register(regno));
71 }
72 }
73
74
75
76 void
77 sim_kill(arg,from_tty)
78 char *arg;
79 int from_tty;
80 {
81
82 }
83
84
85
86 /*
87 * Download a file specified in 'args', to the sim.
88 */
89 static void
90 sim_load(args,fromtty)
91 char *args;
92 int fromtty;
93 {
94 bfd *abfd;
95 asection *s;
96
97 inferior_pid = 0;
98 abfd = bfd_openr(args,"coff-z8k");
99
100 if (!abfd)
101 {
102 printf_filtered("Unable to open file %s\n", args);
103 return;
104 }
105
106 if (bfd_check_format(abfd, bfd_object) ==0)
107 {
108 printf_filtered("File is not an object file\n");
109 return ;
110 }
111
112 s = abfd->sections;
113 while (s != (asection *)NULL)
114 {
115 if (s->flags & SEC_LOAD)
116 {
117 int i;
118 int delta = 4096;
119 char *buffer = xmalloc(delta);
120 printf_filtered("%s\t: 0x%4x .. 0x%4x ",
121 s->name, s->vma, s->vma + s->_raw_size);
122 for (i = 0; i < s->_raw_size; i+= delta)
123 {
124 int sub_delta = delta;
125 if (sub_delta > s->_raw_size - i)
126 sub_delta = s->_raw_size - i ;
127
128 bfd_get_section_contents(abfd, s, buffer, i, sub_delta);
129 sim_write_inferior_memory(s->vma + i, buffer, sub_delta);
130 printf_filtered("*");
131 fflush(stdout);
132 }
133 printf_filtered( "\n");
134 free(buffer);
135 }
136 s = s->next;
137 }
138
139 sim_set_pc(abfd->start_address);
140 }
141
142 /* This is called not only when we first attach, but also when the
143 user types "run" after having attached. */
144 static void
145 sim_create_inferior (execfile, args, env)
146 char *execfile;
147 char *args;
148 char **env;
149 {
150 int entry_pt;
151
152 if (args && *args)
153 error ("Can't pass arguments to remote sim process.");
154
155 if (execfile == 0 || exec_bfd == 0)
156 error ("No exec file specified");
157
158 entry_pt = (int) bfd_get_start_address (exec_bfd);
159
160 sim_kill(NULL,NULL);
161 sim_clear_breakpoints();
162 init_wait_for_inferior ();
163 insert_breakpoints ();
164 proceed(entry_pt, -1, 0);
165 }
166
167
168
169 static void
170 sim_open (name, from_tty)
171 char *name;
172 int from_tty;
173 {
174 if(name == 0)
175 {
176 name = "";
177 }
178
179 /* Clear any break points */
180 sim_clear_breakpoints();
181
182 push_target (&sim_ops);
183 target_fetch_registers(-1);
184
185 printf_filtered("Connected to the Z8000 Simulator.\n");
186 }
187
188 /* Close out all files and local state before this target loses control. */
189
190 static void
191 sim_close (quitting)
192 int quitting;
193 {
194 sim_clear_breakpoints();
195 }
196
197 /* Terminate the open connection to the remote debugger.
198 Use this when you want to detach and do something else
199 with your gdb. */
200 static void
201 sim_detach (args,from_tty)
202 char *args;
203 int from_tty;
204 {
205 sim_clear_breakpoints();
206
207 pop_target(); /* calls sim_close to do the real work */
208 if (from_tty)
209 printf_filtered ("Ending remote %s debugging\n", target_shortname);
210 }
211
212 /* Tell the remote machine to resume. */
213
214
215 /* Wait until the remote machine stops, then return,
216 storing status in STATUS just as `wait' would. */
217
218 int
219 sim_wait (status)
220 WAITTYPE *status;
221 {
222 *status = sim_stop_signal();
223 return 0;
224 }
225
226
227 /* Get ready to modify the registers array. On machines which store
228 individual registers, this doesn't need to do anything. On machines
229 which store all the registers in one fell swoop, this makes sure
230 that registers contains all the registers from the program being
231 debugged. */
232
233 static void
234 sim_prepare_to_store ()
235 {
236 /* Do nothing, since we can store individual regs */
237 }
238
239
240 static void
241 fetch_register(regno)
242 int regno;
243 {
244 if (regno == -1)
245 {
246 for (regno = 0; regno < 16; regno++)
247 fetch_register(regno);
248 }
249 else {
250 char buf[MAX_REGISTER_RAW_SIZE];
251 sim_fetch_register(regno, buf);
252 supply_register(regno, buf);
253 }
254 }
255
256 /* Write a word WORD into remote address ADDR.
257 This goes through the data cache. */
258
259 void
260 sim_store_word (addr, word)
261 CORE_ADDR addr;
262 int word;
263 {
264 /* dcache_poke (addr, word);*/
265 }
266
267 int
268 sim_xfer_inferior_memory(memaddr, myaddr, len, write, target)
269 CORE_ADDR memaddr;
270 char *myaddr;
271 int len;
272 int write;
273 struct target_ops *target; /* ignored */
274 {
275 if (write)
276 {
277 sim_write(memaddr, myaddr, len);
278
279 }
280 else
281 {
282 sim_read(memaddr, myaddr, len);
283 }
284 return len;
285 }
286
287 void
288 sim_files_info ()
289 {
290 char *file = "nothing";
291 if (exec_bfd)
292 file = bfd_get_filename(exec_bfd);
293
294 printf_filtered("\tAttached to %s running on the z8k simulator\n",file);
295 }
296
297 /* This routine is run as a hook, just before the main command loop is
298 entered. If gdb is configured for the H8, but has not had its
299 target specified yet, this will loop prompting the user to do so.
300 */
301
302 void
303 sim_before_main_loop ()
304 {
305 push_target (&sim_ops);
306 }
307
308
309 /* Clear the sims notion of what the break points are */
310 static void
311 sim_mourn()
312 {
313 sim_clear_breakpoints();
314 generic_mourn_inferior ();
315 }
316
317 static void rem_resume(a,b)
318 int a;
319 int b;
320 {
321 sim_resume(a,b);
322 }
323
324 /* Define the target subroutine names */
325
326 struct target_ops sim_ops =
327 {
328 "sim", "Remote SIM monitor",
329 "Use the Z8000 simulator",
330 sim_open, sim_close,
331 0, sim_detach, rem_resume, sim_wait, /* attach */
332 fetch_register, store_register,
333 sim_prepare_to_store,
334 sim_xfer_inferior_memory,
335 sim_files_info,
336 0, 0, /* Breakpoints */
337 0, 0, 0, 0, 0, /* Terminal handling */
338 sim_kill, /* FIXME, kill */
339 sim_load,
340 0, /* lookup_symbol */
341 sim_create_inferior, /* create_inferior */
342 sim_mourn, /* mourn_inferior FIXME */
343 0, /* can_run */
344 0, /* notice_signals */
345 process_stratum, 0, /* next */
346 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
347 0,0, /* Section pointers */
348 OPS_MAGIC, /* Always the last thing */
349 };
350
351
352
353
354
355
356 /***********************************************************************/
357
358 void
359 _initialize_remote_sim ()
360 {
361 extern int sim_z8001_mode;
362 sim_z8001_mode = z8001_mode;
363 add_target (&sim_ops);
364 }
365
366
This page took 0.036906 seconds and 5 git commands to generate.