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