* configure.tgt (hppa*-*-bsd*, hppa*-*-osf*, m68*-*-sunos4*,
[deliverable/binutils-gdb.git] / gdb / remote-nrom.c
CommitLineData
c906108c
SS
1/* Remote debugging with the XLNT Designs, Inc (XDI) NetROM.
2 Copyright 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
3 Contributed by:
c5aa993b
JM
4 Roger Moyers
5 XLNT Designs, Inc.
6 15050 Avenue of Science, Suite 106
7 San Diego, CA 92128
8 (619)487-9320
9 roger@xlnt.com
c906108c
SS
10 Adapted from work done at Cygnus Support in remote-nindy.c,
11 later merged in by Stan Shebs at Cygnus.
12
c5aa993b 13 This file is part of GDB.
c906108c 14
c5aa993b
JM
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
c906108c 19
c5aa993b
JM
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
c906108c 24
c5aa993b
JM
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
c906108c
SS
29
30#include "defs.h"
31#include "gdbcmd.h"
32#include "serial.h"
33#include "target.h"
34
35/* Default ports used to talk with the NetROM. */
36
37#define DEFAULT_NETROM_LOAD_PORT 1236
38#define DEFAULT_NETROM_CONTROL_PORT 1237
39
a14ed312 40static void nrom_close (int quitting);
c906108c
SS
41
42/* New commands. */
43
a14ed312 44static void nrom_passthru (char *, int);
c906108c
SS
45
46/* We talk to the NetROM over these sockets. */
47
48static serial_t load_desc = NULL;
49static serial_t ctrl_desc = NULL;
50
51static int load_port = DEFAULT_NETROM_LOAD_PORT;
52static int control_port = DEFAULT_NETROM_CONTROL_PORT;
53
54static char nrom_hostname[100];
55
56/* Forward data declaration. */
57
58extern struct target_ops nrom_ops;
59
60/* Scan input from the remote system, until STRING is found. Print chars that
61 don't match. */
62
63static int
fba45db2 64expect (char *string)
c906108c
SS
65{
66 char *p = string;
67 int c;
68
8edbea78 69 immediate_quit++;
c906108c
SS
70
71 while (1)
72 {
73 c = SERIAL_READCHAR (ctrl_desc, 5);
74
75 if (c == *p++)
76 {
77 if (*p == '\0')
78 {
8edbea78 79 immediate_quit--;
c906108c
SS
80 return 0;
81 }
82 }
83 else
84 {
85 fputc_unfiltered (c, gdb_stdout);
86 p = string;
87 if (c == *p)
88 p++;
89 }
90 }
91}
92
93static void
fba45db2 94nrom_kill (void)
c906108c
SS
95{
96 nrom_close (0);
97}
98
99static serial_t
fba45db2 100open_socket (char *name, int port)
c906108c
SS
101{
102 char sockname[100];
103 serial_t desc;
104
105 sprintf (sockname, "%s:%d", name, port);
106 desc = SERIAL_OPEN (sockname);
107 if (!desc)
108 perror_with_name (sockname);
109
110 return desc;
111}
112
113static void
fba45db2 114load_cleanup (void)
c906108c
SS
115{
116 SERIAL_CLOSE (load_desc);
117 load_desc = NULL;
118}
119
120/* Download a file specified in ARGS to the netROM. */
121
122static void
fba45db2 123nrom_load (char *args, int fromtty)
c906108c
SS
124{
125 int fd, rd_amt, fsize;
126 bfd *pbfd;
127 asection *section;
128 char *downloadstring = "download 0\n";
129 struct cleanup *old_chain;
130
131 /* Tell the netrom to get ready to download. */
132 if (SERIAL_WRITE (ctrl_desc, downloadstring, strlen (downloadstring)))
133 error ("nrom_load: control_send() of `%s' failed", downloadstring);
134
135 expect ("Waiting for a connection...\n");
136
137 load_desc = open_socket (nrom_hostname, load_port);
138
139 old_chain = make_cleanup (load_cleanup, 0);
140
141 pbfd = bfd_openr (args, 0);
142
143 if (pbfd)
144 {
145 make_cleanup (bfd_close, pbfd);
146
c5aa993b 147 if (!bfd_check_format (pbfd, bfd_object))
c906108c
SS
148 error ("\"%s\": not in executable format: %s",
149 args, bfd_errmsg (bfd_get_error ()));
150
c5aa993b 151 for (section = pbfd->sections; section; section = section->next)
c906108c
SS
152 {
153 if (bfd_get_section_flags (pbfd, section) & SEC_ALLOC)
154 {
155 bfd_vma section_address;
156 unsigned long section_size;
157 const char *section_name;
158
159 section_name = bfd_get_section_name (pbfd, section);
160 section_address = bfd_get_section_vma (pbfd, section);
161 section_size = bfd_section_size (pbfd, section);
162
163 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
164 {
165 file_ptr fptr;
166
167 printf_filtered ("[Loading section %s at %x (%d bytes)]\n",
168 section_name, section_address,
169 section_size);
170
171 fptr = 0;
172
173 while (section_size > 0)
174 {
175 char buffer[1024];
176 int count;
c5aa993b 177
c906108c
SS
178 count = min (section_size, 1024);
179
180 bfd_get_section_contents (pbfd, section, buffer, fptr,
181 count);
182
183 SERIAL_WRITE (load_desc, buffer, count);
184 section_address += count;
185 fptr += count;
186 section_size -= count;
187 }
188 }
c5aa993b
JM
189 else
190 /* BSS and such */
c906108c
SS
191 {
192 printf_filtered ("[section %s: not loading]\n",
193 section_name);
194 }
195 }
196 }
197 }
198 else
199 error ("\"%s\": Could not open", args);
200
201 do_cleanups (old_chain);
202}
203
204/* Open a connection to the remote NetROM devices. */
205
206static void
fba45db2 207nrom_open (char *name, int from_tty)
c906108c
SS
208{
209 int errn;
210
211 if (!name || strchr (name, '/') || strchr (name, ':'))
212 error (
c5aa993b 213 "To open a NetROM connection, you must specify the hostname\n\
c906108c
SS
214or IP address of the NetROM device you wish to use.");
215
216 strcpy (nrom_hostname, name);
217
218 target_preopen (from_tty);
219
220 unpush_target (&nrom_ops);
221
222 ctrl_desc = open_socket (nrom_hostname, control_port);
223
224 push_target (&nrom_ops);
225
226 if (from_tty)
227 printf_filtered ("Connected to NetROM device \"%s\"\n", nrom_hostname);
228}
229
230/* Close out all files and local state before this target loses control. */
231
232static void
fba45db2 233nrom_close (int quitting)
c906108c
SS
234{
235 if (load_desc)
236 SERIAL_CLOSE (load_desc);
237 if (ctrl_desc)
238 SERIAL_CLOSE (ctrl_desc);
239}
240
241/* Pass arguments directly to the NetROM. */
242
243static void
fba45db2 244nrom_passthru (char *args, int fromtty)
c906108c
SS
245{
246 char buf[1024];
247
248 sprintf (buf, "%s\n", args);
249 if (SERIAL_WRITE (ctrl_desc, buf, strlen (buf)))
250 error ("nrom_reset: control_send() of `%s'failed", args);
251}
252
253static void
fba45db2 254nrom_mourn (void)
c5aa993b 255{
c906108c
SS
256 unpush_target (&nrom_ops);
257 generic_mourn_inferior ();
258}
259
260/* Define the target vector. */
261
c5aa993b 262struct target_ops nrom_ops;
c906108c 263
c5aa993b
JM
264static void
265init_nrom_ops (void)
c906108c 266{
c5aa993b
JM
267 nrom_ops.to_shortname = "nrom";
268 nrom_ops.to_longname = "Remote XDI `NetROM' target";
269 nrom_ops.to_doc = "Remote debug using a NetROM over Ethernet";
270 nrom_ops.to_open = nrom_open;
271 nrom_ops.to_close = nrom_close;
272 nrom_ops.to_attach = NULL;
c906108c 273 nrom_ops.to_post_attach = NULL;
c5aa993b
JM
274 nrom_ops.to_require_attach = NULL;
275 nrom_ops.to_detach = NULL;
276 nrom_ops.to_require_detach = NULL;
277 nrom_ops.to_resume = NULL;
278 nrom_ops.to_wait = NULL;
279 nrom_ops.to_post_wait = NULL;
280 nrom_ops.to_fetch_registers = NULL;
281 nrom_ops.to_store_registers = NULL;
282 nrom_ops.to_prepare_to_store = NULL;
283 nrom_ops.to_xfer_memory = NULL;
284 nrom_ops.to_files_info = NULL;
285 nrom_ops.to_insert_breakpoint = NULL;
286 nrom_ops.to_remove_breakpoint = NULL;
287 nrom_ops.to_terminal_init = NULL;
288 nrom_ops.to_terminal_inferior = NULL;
289 nrom_ops.to_terminal_ours_for_output = NULL;
290 nrom_ops.to_terminal_ours = NULL;
291 nrom_ops.to_terminal_info = NULL;
292 nrom_ops.to_kill = nrom_kill;
293 nrom_ops.to_load = nrom_load;
294 nrom_ops.to_lookup_symbol = NULL;
295 nrom_ops.to_create_inferior = NULL;
c906108c
SS
296 nrom_ops.to_post_startup_inferior = NULL;
297 nrom_ops.to_acknowledge_created_inferior = NULL;
298 nrom_ops.to_clone_and_follow_inferior = NULL;
299 nrom_ops.to_post_follow_inferior_by_clone = NULL;
300 nrom_ops.to_insert_fork_catchpoint = NULL;
301 nrom_ops.to_remove_fork_catchpoint = NULL;
302 nrom_ops.to_insert_vfork_catchpoint = NULL;
303 nrom_ops.to_remove_vfork_catchpoint = NULL;
304 nrom_ops.to_has_forked = NULL;
305 nrom_ops.to_has_vforked = NULL;
306 nrom_ops.to_can_follow_vfork_prior_to_exec = NULL;
c5aa993b 307 nrom_ops.to_post_follow_vfork = NULL;
c906108c
SS
308 nrom_ops.to_insert_exec_catchpoint = NULL;
309 nrom_ops.to_remove_exec_catchpoint = NULL;
310 nrom_ops.to_has_execd = NULL;
311 nrom_ops.to_reported_exec_events_per_exec_call = NULL;
312 nrom_ops.to_has_exited = NULL;
c5aa993b
JM
313 nrom_ops.to_mourn_inferior = nrom_mourn;
314 nrom_ops.to_can_run = NULL;
315 nrom_ops.to_notice_signals = 0;
316 nrom_ops.to_thread_alive = 0;
317 nrom_ops.to_stop = 0;
c906108c
SS
318 nrom_ops.to_pid_to_exec_file = NULL;
319 nrom_ops.to_core_file_to_sym_file = NULL;
c5aa993b
JM
320 nrom_ops.to_stratum = download_stratum;
321 nrom_ops.DONT_USE = NULL;
322 nrom_ops.to_has_all_memory = 1;
323 nrom_ops.to_has_memory = 1;
324 nrom_ops.to_has_stack = 1;
325 nrom_ops.to_has_registers = 1;
326 nrom_ops.to_has_execution = 0;
327 nrom_ops.to_sections = NULL;
328 nrom_ops.to_sections_end = NULL;
329 nrom_ops.to_magic = OPS_MAGIC;
c906108c
SS
330};
331
332void
fba45db2 333_initialize_remote_nrom (void)
c906108c 334{
c5aa993b 335 init_nrom_ops ();
c906108c
SS
336 add_target (&nrom_ops);
337
338 add_show_from_set (
c5aa993b
JM
339 add_set_cmd ("nrom_load_port", no_class, var_zinteger, (char *) &load_port,
340 "Set the port to use for NetROM downloads\n", &setlist),
341 &showlist);
c906108c
SS
342
343 add_show_from_set (
c5aa993b
JM
344 add_set_cmd ("nrom_control_port", no_class, var_zinteger, (char *) &control_port,
345 "Set the port to use for NetROM debugger services\n", &setlist),
346 &showlist);
c906108c
SS
347
348 add_cmd ("nrom", no_class, nrom_passthru,
349 "Pass arguments as command to NetROM",
350 &cmdlist);
351}
This page took 0.095577 seconds and 4 git commands to generate.