OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [remote-nrom.c] - Diff between revs 105 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 105 Rev 1765
/* Remote debugging with the XLNT Designs, Inc (XDI) NetROM.
/* Remote debugging with the XLNT Designs, Inc (XDI) NetROM.
   Copyright 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
   Copyright 1990, 1991, 1992, 1995 Free Software Foundation, Inc.
   Contributed by:
   Contributed by:
   Roger Moyers
   Roger Moyers
   XLNT Designs, Inc.
   XLNT Designs, Inc.
   15050 Avenue of Science, Suite 106
   15050 Avenue of Science, Suite 106
   San Diego, CA  92128
   San Diego, CA  92128
   (619)487-9320
   (619)487-9320
   roger@xlnt.com
   roger@xlnt.com
   Adapted from work done at Cygnus Support in remote-nindy.c,
   Adapted from work done at Cygnus Support in remote-nindy.c,
   later merged in by Stan Shebs at Cygnus.
   later merged in by Stan Shebs at Cygnus.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */
   Boston, MA 02111-1307, USA.  */
 
 
#include "defs.h"
#include "defs.h"
#include "gdbcmd.h"
#include "gdbcmd.h"
#include "serial.h"
#include "serial.h"
#include "target.h"
#include "target.h"
 
 
/* Default ports used to talk with the NetROM.  */
/* Default ports used to talk with the NetROM.  */
 
 
#define DEFAULT_NETROM_LOAD_PORT    1236
#define DEFAULT_NETROM_LOAD_PORT    1236
#define DEFAULT_NETROM_CONTROL_PORT 1237
#define DEFAULT_NETROM_CONTROL_PORT 1237
 
 
static void nrom_close PARAMS ((int quitting));
static void nrom_close PARAMS ((int quitting));
 
 
/* New commands.  */
/* New commands.  */
 
 
static void nrom_passthru PARAMS ((char *, int));
static void nrom_passthru PARAMS ((char *, int));
 
 
/* We talk to the NetROM over these sockets.  */
/* We talk to the NetROM over these sockets.  */
 
 
static serial_t load_desc = NULL;
static serial_t load_desc = NULL;
static serial_t ctrl_desc = NULL;
static serial_t ctrl_desc = NULL;
 
 
static int load_port = DEFAULT_NETROM_LOAD_PORT;
static int load_port = DEFAULT_NETROM_LOAD_PORT;
static int control_port = DEFAULT_NETROM_CONTROL_PORT;
static int control_port = DEFAULT_NETROM_CONTROL_PORT;
 
 
static char nrom_hostname[100];
static char nrom_hostname[100];
 
 
/* Forward data declaration. */
/* Forward data declaration. */
 
 
extern struct target_ops nrom_ops;
extern struct target_ops nrom_ops;
 
 
/* Scan input from the remote system, until STRING is found.  Print chars that
/* Scan input from the remote system, until STRING is found.  Print chars that
   don't match.  */
   don't match.  */
 
 
static int
static int
expect (string)
expect (string)
     char *string;
     char *string;
{
{
  char *p = string;
  char *p = string;
  int c;
  int c;
 
 
  immediate_quit = 1;
  immediate_quit = 1;
 
 
  while (1)
  while (1)
    {
    {
      c = SERIAL_READCHAR (ctrl_desc, 5);
      c = SERIAL_READCHAR (ctrl_desc, 5);
 
 
      if (c == *p++)
      if (c == *p++)
        {
        {
          if (*p == '\0')
          if (*p == '\0')
            {
            {
              immediate_quit = 0;
              immediate_quit = 0;
 
 
              return 0;
              return 0;
            }
            }
        }
        }
      else
      else
        {
        {
          fputc_unfiltered (c, gdb_stdout);
          fputc_unfiltered (c, gdb_stdout);
          p = string;
          p = string;
          if (c == *p)
          if (c == *p)
            p++;
            p++;
        }
        }
    }
    }
}
}
 
 
static void
static void
nrom_kill ()
nrom_kill ()
{
{
  nrom_close (0);
  nrom_close (0);
}
}
 
 
static serial_t
static serial_t
open_socket (name, port)
open_socket (name, port)
     char *name;
     char *name;
     int port;
     int port;
{
{
  char sockname[100];
  char sockname[100];
  serial_t desc;
  serial_t desc;
 
 
  sprintf (sockname, "%s:%d", name, port);
  sprintf (sockname, "%s:%d", name, port);
  desc = SERIAL_OPEN (sockname);
  desc = SERIAL_OPEN (sockname);
  if (!desc)
  if (!desc)
    perror_with_name (sockname);
    perror_with_name (sockname);
 
 
  return desc;
  return desc;
}
}
 
 
static void
static void
load_cleanup ()
load_cleanup ()
{
{
  SERIAL_CLOSE (load_desc);
  SERIAL_CLOSE (load_desc);
  load_desc = NULL;
  load_desc = NULL;
}
}
 
 
/* Download a file specified in ARGS to the netROM.  */
/* Download a file specified in ARGS to the netROM.  */
 
 
static void
static void
nrom_load (args, fromtty)
nrom_load (args, fromtty)
     char *args;
     char *args;
     int fromtty;
     int fromtty;
{
{
  int fd, rd_amt, fsize;
  int fd, rd_amt, fsize;
  bfd *pbfd;
  bfd *pbfd;
  asection *section;
  asection *section;
  char *downloadstring = "download 0\n";
  char *downloadstring = "download 0\n";
  struct cleanup *old_chain;
  struct cleanup *old_chain;
 
 
  /* Tell the netrom to get ready to download. */
  /* Tell the netrom to get ready to download. */
  if (SERIAL_WRITE (ctrl_desc, downloadstring, strlen (downloadstring)))
  if (SERIAL_WRITE (ctrl_desc, downloadstring, strlen (downloadstring)))
    error ("nrom_load: control_send() of `%s' failed", downloadstring);
    error ("nrom_load: control_send() of `%s' failed", downloadstring);
 
 
  expect ("Waiting for a connection...\n");
  expect ("Waiting for a connection...\n");
 
 
  load_desc = open_socket (nrom_hostname, load_port);
  load_desc = open_socket (nrom_hostname, load_port);
 
 
  old_chain = make_cleanup (load_cleanup, 0);
  old_chain = make_cleanup (load_cleanup, 0);
 
 
  pbfd = bfd_openr (args, 0);
  pbfd = bfd_openr (args, 0);
 
 
  if (pbfd)
  if (pbfd)
    {
    {
      make_cleanup (bfd_close, pbfd);
      make_cleanup (bfd_close, pbfd);
 
 
      if (!bfd_check_format (pbfd, bfd_object))
      if (!bfd_check_format (pbfd, bfd_object))
        error ("\"%s\": not in executable format: %s",
        error ("\"%s\": not in executable format: %s",
               args, bfd_errmsg (bfd_get_error ()));
               args, bfd_errmsg (bfd_get_error ()));
 
 
      for (section = pbfd->sections; section; section = section->next)
      for (section = pbfd->sections; section; section = section->next)
        {
        {
          if (bfd_get_section_flags (pbfd, section) & SEC_ALLOC)
          if (bfd_get_section_flags (pbfd, section) & SEC_ALLOC)
            {
            {
              bfd_vma section_address;
              bfd_vma section_address;
              unsigned long section_size;
              unsigned long section_size;
              const char *section_name;
              const char *section_name;
 
 
              section_name = bfd_get_section_name (pbfd, section);
              section_name = bfd_get_section_name (pbfd, section);
              section_address = bfd_get_section_vma (pbfd, section);
              section_address = bfd_get_section_vma (pbfd, section);
              section_size = bfd_section_size (pbfd, section);
              section_size = bfd_section_size (pbfd, section);
 
 
              if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
              if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
                {
                {
                  file_ptr fptr;
                  file_ptr fptr;
 
 
                  printf_filtered ("[Loading section %s at %x (%d bytes)]\n",
                  printf_filtered ("[Loading section %s at %x (%d bytes)]\n",
                                   section_name, section_address,
                                   section_name, section_address,
                                   section_size);
                                   section_size);
 
 
                  fptr = 0;
                  fptr = 0;
 
 
                  while (section_size > 0)
                  while (section_size > 0)
                    {
                    {
                      char buffer[1024];
                      char buffer[1024];
                      int count;
                      int count;
 
 
                      count = min (section_size, 1024);
                      count = min (section_size, 1024);
 
 
                      bfd_get_section_contents (pbfd, section, buffer, fptr,
                      bfd_get_section_contents (pbfd, section, buffer, fptr,
                                                count);
                                                count);
 
 
                      SERIAL_WRITE (load_desc, buffer, count);
                      SERIAL_WRITE (load_desc, buffer, count);
                      section_address += count;
                      section_address += count;
                      fptr += count;
                      fptr += count;
                      section_size -= count;
                      section_size -= count;
                    }
                    }
                }
                }
              else
              else
                /* BSS and such */
                /* BSS and such */
                {
                {
                  printf_filtered ("[section %s: not loading]\n",
                  printf_filtered ("[section %s: not loading]\n",
                                   section_name);
                                   section_name);
                }
                }
            }
            }
        }
        }
    }
    }
  else
  else
    error ("\"%s\": Could not open", args);
    error ("\"%s\": Could not open", args);
 
 
  do_cleanups (old_chain);
  do_cleanups (old_chain);
}
}
 
 
/* Open a connection to the remote NetROM devices.  */
/* Open a connection to the remote NetROM devices.  */
 
 
static void
static void
nrom_open (name, from_tty)
nrom_open (name, from_tty)
     char *name;
     char *name;
     int from_tty;
     int from_tty;
{
{
  int errn;
  int errn;
 
 
  if (!name || strchr (name, '/') || strchr (name, ':'))
  if (!name || strchr (name, '/') || strchr (name, ':'))
    error (
    error (
            "To open a NetROM connection, you must specify the hostname\n\
            "To open a NetROM connection, you must specify the hostname\n\
or IP address of the NetROM device you wish to use.");
or IP address of the NetROM device you wish to use.");
 
 
  strcpy (nrom_hostname, name);
  strcpy (nrom_hostname, name);
 
 
  target_preopen (from_tty);
  target_preopen (from_tty);
 
 
  unpush_target (&nrom_ops);
  unpush_target (&nrom_ops);
 
 
  ctrl_desc = open_socket (nrom_hostname, control_port);
  ctrl_desc = open_socket (nrom_hostname, control_port);
 
 
  push_target (&nrom_ops);
  push_target (&nrom_ops);
 
 
  if (from_tty)
  if (from_tty)
    printf_filtered ("Connected to NetROM device \"%s\"\n", nrom_hostname);
    printf_filtered ("Connected to NetROM device \"%s\"\n", nrom_hostname);
}
}
 
 
/* Close out all files and local state before this target loses control. */
/* Close out all files and local state before this target loses control. */
 
 
static void
static void
nrom_close (quitting)
nrom_close (quitting)
     int quitting;
     int quitting;
{
{
  if (load_desc)
  if (load_desc)
    SERIAL_CLOSE (load_desc);
    SERIAL_CLOSE (load_desc);
  if (ctrl_desc)
  if (ctrl_desc)
    SERIAL_CLOSE (ctrl_desc);
    SERIAL_CLOSE (ctrl_desc);
}
}
 
 
/* Pass arguments directly to the NetROM. */
/* Pass arguments directly to the NetROM. */
 
 
static void
static void
nrom_passthru (args, fromtty)
nrom_passthru (args, fromtty)
     char *args;
     char *args;
     int fromtty;
     int fromtty;
{
{
  char buf[1024];
  char buf[1024];
 
 
  sprintf (buf, "%s\n", args);
  sprintf (buf, "%s\n", args);
  if (SERIAL_WRITE (ctrl_desc, buf, strlen (buf)))
  if (SERIAL_WRITE (ctrl_desc, buf, strlen (buf)))
    error ("nrom_reset: control_send() of `%s'failed", args);
    error ("nrom_reset: control_send() of `%s'failed", args);
}
}
 
 
static void
static void
nrom_mourn ()
nrom_mourn ()
{
{
  unpush_target (&nrom_ops);
  unpush_target (&nrom_ops);
  generic_mourn_inferior ();
  generic_mourn_inferior ();
}
}
 
 
/* Define the target vector. */
/* Define the target vector. */
 
 
struct target_ops nrom_ops;
struct target_ops nrom_ops;
 
 
static void
static void
init_nrom_ops (void)
init_nrom_ops (void)
{
{
  nrom_ops.to_shortname = "nrom";
  nrom_ops.to_shortname = "nrom";
  nrom_ops.to_longname = "Remote XDI `NetROM' target";
  nrom_ops.to_longname = "Remote XDI `NetROM' target";
  nrom_ops.to_doc = "Remote debug using a NetROM over Ethernet";
  nrom_ops.to_doc = "Remote debug using a NetROM over Ethernet";
  nrom_ops.to_open = nrom_open;
  nrom_ops.to_open = nrom_open;
  nrom_ops.to_close = nrom_close;
  nrom_ops.to_close = nrom_close;
  nrom_ops.to_attach = NULL;
  nrom_ops.to_attach = NULL;
  nrom_ops.to_post_attach = NULL;
  nrom_ops.to_post_attach = NULL;
  nrom_ops.to_require_attach = NULL;
  nrom_ops.to_require_attach = NULL;
  nrom_ops.to_detach = NULL;
  nrom_ops.to_detach = NULL;
  nrom_ops.to_require_detach = NULL;
  nrom_ops.to_require_detach = NULL;
  nrom_ops.to_resume = NULL;
  nrom_ops.to_resume = NULL;
  nrom_ops.to_wait = NULL;
  nrom_ops.to_wait = NULL;
  nrom_ops.to_post_wait = NULL;
  nrom_ops.to_post_wait = NULL;
  nrom_ops.to_fetch_registers = NULL;
  nrom_ops.to_fetch_registers = NULL;
  nrom_ops.to_store_registers = NULL;
  nrom_ops.to_store_registers = NULL;
  nrom_ops.to_prepare_to_store = NULL;
  nrom_ops.to_prepare_to_store = NULL;
  nrom_ops.to_xfer_memory = NULL;
  nrom_ops.to_xfer_memory = NULL;
  nrom_ops.to_files_info = NULL;
  nrom_ops.to_files_info = NULL;
  nrom_ops.to_insert_breakpoint = NULL;
  nrom_ops.to_insert_breakpoint = NULL;
  nrom_ops.to_remove_breakpoint = NULL;
  nrom_ops.to_remove_breakpoint = NULL;
  nrom_ops.to_terminal_init = NULL;
  nrom_ops.to_terminal_init = NULL;
  nrom_ops.to_terminal_inferior = NULL;
  nrom_ops.to_terminal_inferior = NULL;
  nrom_ops.to_terminal_ours_for_output = NULL;
  nrom_ops.to_terminal_ours_for_output = NULL;
  nrom_ops.to_terminal_ours = NULL;
  nrom_ops.to_terminal_ours = NULL;
  nrom_ops.to_terminal_info = NULL;
  nrom_ops.to_terminal_info = NULL;
  nrom_ops.to_kill = nrom_kill;
  nrom_ops.to_kill = nrom_kill;
  nrom_ops.to_load = nrom_load;
  nrom_ops.to_load = nrom_load;
  nrom_ops.to_lookup_symbol = NULL;
  nrom_ops.to_lookup_symbol = NULL;
  nrom_ops.to_create_inferior = NULL;
  nrom_ops.to_create_inferior = NULL;
  nrom_ops.to_post_startup_inferior = NULL;
  nrom_ops.to_post_startup_inferior = NULL;
  nrom_ops.to_acknowledge_created_inferior = NULL;
  nrom_ops.to_acknowledge_created_inferior = NULL;
  nrom_ops.to_clone_and_follow_inferior = NULL;
  nrom_ops.to_clone_and_follow_inferior = NULL;
  nrom_ops.to_post_follow_inferior_by_clone = NULL;
  nrom_ops.to_post_follow_inferior_by_clone = NULL;
  nrom_ops.to_insert_fork_catchpoint = NULL;
  nrom_ops.to_insert_fork_catchpoint = NULL;
  nrom_ops.to_remove_fork_catchpoint = NULL;
  nrom_ops.to_remove_fork_catchpoint = NULL;
  nrom_ops.to_insert_vfork_catchpoint = NULL;
  nrom_ops.to_insert_vfork_catchpoint = NULL;
  nrom_ops.to_remove_vfork_catchpoint = NULL;
  nrom_ops.to_remove_vfork_catchpoint = NULL;
  nrom_ops.to_has_forked = NULL;
  nrom_ops.to_has_forked = NULL;
  nrom_ops.to_has_vforked = NULL;
  nrom_ops.to_has_vforked = NULL;
  nrom_ops.to_can_follow_vfork_prior_to_exec = NULL;
  nrom_ops.to_can_follow_vfork_prior_to_exec = NULL;
  nrom_ops.to_post_follow_vfork = NULL;
  nrom_ops.to_post_follow_vfork = NULL;
  nrom_ops.to_insert_exec_catchpoint = NULL;
  nrom_ops.to_insert_exec_catchpoint = NULL;
  nrom_ops.to_remove_exec_catchpoint = NULL;
  nrom_ops.to_remove_exec_catchpoint = NULL;
  nrom_ops.to_has_execd = NULL;
  nrom_ops.to_has_execd = NULL;
  nrom_ops.to_reported_exec_events_per_exec_call = NULL;
  nrom_ops.to_reported_exec_events_per_exec_call = NULL;
  nrom_ops.to_has_exited = NULL;
  nrom_ops.to_has_exited = NULL;
  nrom_ops.to_mourn_inferior = nrom_mourn;
  nrom_ops.to_mourn_inferior = nrom_mourn;
  nrom_ops.to_can_run = NULL;
  nrom_ops.to_can_run = NULL;
  nrom_ops.to_notice_signals = 0;
  nrom_ops.to_notice_signals = 0;
  nrom_ops.to_thread_alive = 0;
  nrom_ops.to_thread_alive = 0;
  nrom_ops.to_stop = 0;
  nrom_ops.to_stop = 0;
  nrom_ops.to_pid_to_exec_file = NULL;
  nrom_ops.to_pid_to_exec_file = NULL;
  nrom_ops.to_core_file_to_sym_file = NULL;
  nrom_ops.to_core_file_to_sym_file = NULL;
  nrom_ops.to_stratum = download_stratum;
  nrom_ops.to_stratum = download_stratum;
  nrom_ops.DONT_USE = NULL;
  nrom_ops.DONT_USE = NULL;
  nrom_ops.to_has_all_memory = 1;
  nrom_ops.to_has_all_memory = 1;
  nrom_ops.to_has_memory = 1;
  nrom_ops.to_has_memory = 1;
  nrom_ops.to_has_stack = 1;
  nrom_ops.to_has_stack = 1;
  nrom_ops.to_has_registers = 1;
  nrom_ops.to_has_registers = 1;
  nrom_ops.to_has_execution = 0;
  nrom_ops.to_has_execution = 0;
  nrom_ops.to_sections = NULL;
  nrom_ops.to_sections = NULL;
  nrom_ops.to_sections_end = NULL;
  nrom_ops.to_sections_end = NULL;
  nrom_ops.to_magic = OPS_MAGIC;
  nrom_ops.to_magic = OPS_MAGIC;
};
};
 
 
void
void
_initialize_remote_nrom ()
_initialize_remote_nrom ()
{
{
  init_nrom_ops ();
  init_nrom_ops ();
  add_target (&nrom_ops);
  add_target (&nrom_ops);
 
 
  add_show_from_set (
  add_show_from_set (
  add_set_cmd ("nrom_load_port", no_class, var_zinteger, (char *) &load_port,
  add_set_cmd ("nrom_load_port", no_class, var_zinteger, (char *) &load_port,
               "Set the port to use for NetROM downloads\n", &setlist),
               "Set the port to use for NetROM downloads\n", &setlist),
                      &showlist);
                      &showlist);
 
 
  add_show_from_set (
  add_show_from_set (
                      add_set_cmd ("nrom_control_port", no_class, var_zinteger, (char *) &control_port,
                      add_set_cmd ("nrom_control_port", no_class, var_zinteger, (char *) &control_port,
            "Set the port to use for NetROM debugger services\n", &setlist),
            "Set the port to use for NetROM debugger services\n", &setlist),
                      &showlist);
                      &showlist);
 
 
  add_cmd ("nrom", no_class, nrom_passthru,
  add_cmd ("nrom", no_class, nrom_passthru,
           "Pass arguments as command to NetROM",
           "Pass arguments as command to NetROM",
           &cmdlist);
           &cmdlist);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.