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