1 /* Remote debugging with the XLNT Designs, Inc (XDI) NetROM.
2 Copyright 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
6 15050 Avenue of Science, Suite 106
10 Adapted from work done at Cygnus Support in remote-nindy.c,
11 later merged in by Stan Shebs at Cygnus.
13 This file is part of GDB.
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.
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.
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, Boston, MA 02111-1307, USA. */
34 /* Default ports used to talk with the NetROM. */
36 #define DEFAULT_NETROM_LOAD_PORT 1236
37 #define DEFAULT_NETROM_CONTROL_PORT 1237
39 static void nrom_close PARAMS ((int quitting));
43 static void nrom_passthru PARAMS ((char *, int));
45 /* We talk to the NetROM over these sockets. */
47 static serial_t load_desc = NULL;
48 static serial_t ctrl_desc = NULL;
50 static int load_port = DEFAULT_NETROM_LOAD_PORT;
51 static int control_port = DEFAULT_NETROM_CONTROL_PORT;
53 static char nrom_hostname[100];
55 /* Forward data declaration. */
57 extern struct target_ops nrom_ops;
59 /* Scan input from the remote system, until STRING is found. Print chars that
73 c = SERIAL_READCHAR (ctrl_desc, 5);
86 fputc_unfiltered (c, gdb_stdout);
101 open_socket (name, port)
108 sprintf (sockname, "%s:%d", name, port);
109 desc = SERIAL_OPEN (sockname);
111 perror_with_name (sockname);
119 SERIAL_CLOSE (load_desc);
123 /* Download a file specified in ARGS to the netROM. */
126 nrom_load (args, fromtty)
130 int fd, rd_amt, fsize;
133 char *downloadstring = "download 0\n";
134 struct cleanup *old_chain;
136 /* Tell the netrom to get ready to download. */
137 if (SERIAL_WRITE (ctrl_desc, downloadstring, strlen (downloadstring)))
138 error ("nrom_load: control_send() of `%s' failed", downloadstring);
140 expect ("Waiting for a connection...\n");
142 load_desc = open_socket (nrom_hostname, load_port);
144 old_chain = make_cleanup (load_cleanup, 0);
146 pbfd = bfd_openr (args, 0);
150 make_cleanup (bfd_close, pbfd);
152 if (!bfd_check_format (pbfd, bfd_object))
153 error ("\"%s\": not in executable format: %s",
154 args, bfd_errmsg (bfd_get_error ()));
156 for (section = pbfd->sections; section; section = section->next)
158 if (bfd_get_section_flags (pbfd, section) & SEC_ALLOC)
160 bfd_vma section_address;
161 unsigned long section_size;
162 const char *section_name;
164 section_name = bfd_get_section_name (pbfd, section);
165 section_address = bfd_get_section_vma (pbfd, section);
166 section_size = bfd_section_size (pbfd, section);
168 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
172 printf_filtered ("[Loading section %s at %x (%d bytes)]\n",
173 section_name, section_address,
178 while (section_size > 0)
183 count = min (section_size, 1024);
185 bfd_get_section_contents (pbfd, section, buffer, fptr,
188 SERIAL_WRITE (load_desc, buffer, count);
189 section_address += count;
191 section_size -= count;
194 else /* BSS and such */
196 printf_filtered ("[section %s: not loading]\n",
203 error ("\"%s\": Could not open", args);
205 do_cleanups (old_chain);
208 /* Open a connection to the remote NetROM devices. */
211 nrom_open (name, from_tty)
217 if (!name || strchr (name, '/') || strchr (name, ':'))
219 "To open a NetROM connection, you must specify the hostname\n\
220 or IP address of the NetROM device you wish to use.");
222 strcpy (nrom_hostname, name);
224 target_preopen (from_tty);
226 unpush_target (&nrom_ops);
228 ctrl_desc = open_socket (nrom_hostname, control_port);
230 push_target (&nrom_ops);
233 printf_filtered ("Connected to NetROM device \"%s\"\n", nrom_hostname);
236 /* Close out all files and local state before this target loses control. */
239 nrom_close (quitting)
243 SERIAL_CLOSE (load_desc);
245 SERIAL_CLOSE (ctrl_desc);
248 /* Pass arguments directly to the NetROM. */
251 nrom_passthru (args, fromtty)
257 sprintf (buf, "%s\n", args);
258 if (SERIAL_WRITE (ctrl_desc, buf, strlen (buf)))
259 error ("nrom_reset: control_send() of `%s'failed", args);
265 unpush_target (&nrom_ops);
266 generic_mourn_inferior ();
269 /* Define the target vector. */
271 struct target_ops nrom_ops = {
272 "nrom", /* to_shortname */
273 "Remote XDI `NetROM' target", /* to_longname */
274 "Remote debug using a NetROM over Ethernet", /* to_doc */
275 nrom_open, /* to_open */
276 nrom_close, /* to_close */
277 NULL, /* to_attach */
278 NULL, /* to_detach */
279 NULL, /* to_resume */
281 NULL, /* to_fetch_registers */
282 NULL, /* to_store_registers */
283 NULL, /* to_prepare_to_store */
284 NULL, /* to_xfer_memory */
285 NULL, /* to_files_info */
286 NULL, /* to_insert_breakpoint */
287 NULL, /* to_remove_breakpoint */
288 NULL, /* to_terminal_init */
289 NULL, /* to_terminal_inferior */
290 NULL, /* to_terminal_ours_for_output */
291 NULL, /* to_terminal_ours */
292 NULL, /* to_terminal_info */
293 nrom_kill, /* to_kill */
294 nrom_load, /* to_load */
295 NULL, /* to_lookup_symbol */
296 NULL, /* to_create_inferior */
297 nrom_mourn, /* to_mourn_inferior */
298 NULL, /* to_can_run */
299 0, /* to_notice_signals */
300 0, /* to_thread_alive */
302 download_stratum, /* to_stratum */
304 1, /* to_has_all_memory */
305 1, /* to_has_memory */
306 1, /* to_has_stack */
307 1, /* to_has_registers */
308 0, /* to_has_execution */
310 NULL, /* sections_end */
311 OPS_MAGIC /* to_magic */
315 _initialize_remote_nrom ()
317 add_target (&nrom_ops);
320 add_set_cmd ("nrom_load_port", no_class, var_zinteger, (char *)&load_port,
321 "Set the port to use for NetROM downloads\n", &setlist),
325 add_set_cmd ("nrom_control_port", no_class, var_zinteger, (char *)&control_port,
326 "Set the port to use for NetROM debugger services\n", &setlist),
329 add_cmd ("nrom", no_class, nrom_passthru,
330 "Pass arguments as command to NetROM",