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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [remote-rdi.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
/* GDB interface to ARM RDI library.
/* GDB interface to ARM RDI library.
   Copyright 1997, 1998 Free Software Foundation, Inc.
   Copyright 1997, 1998 Free Software Foundation, Inc.
 
 
   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 "gdb_string.h"
#include "gdb_string.h"
#include <fcntl.h>
#include <fcntl.h>
#include "frame.h"
#include "frame.h"
#include "inferior.h"
#include "inferior.h"
#include "bfd.h"
#include "bfd.h"
#include "symfile.h"
#include "symfile.h"
#include "target.h"
#include "target.h"
#include "gdb_wait.h"
#include "gdb_wait.h"
#include "gdbcmd.h"
#include "gdbcmd.h"
#include "objfiles.h"
#include "objfiles.h"
#include "gdb-stabs.h"
#include "gdb-stabs.h"
#include "gdbthread.h"
#include "gdbthread.h"
#include "gdbcore.h"
#include "gdbcore.h"
#include "breakpoint.h"
#include "breakpoint.h"
 
 
#ifdef USG
#ifdef USG
#include <sys/types.h>
#include <sys/types.h>
#endif
#endif
 
 
#include <signal.h>
#include <signal.h>
 
 
#include "rdi-share/ardi.h"
#include "rdi-share/ardi.h"
#include "rdi-share/adp.h"
#include "rdi-share/adp.h"
#include "rdi-share/hsys.h"
#include "rdi-share/hsys.h"
 
 
extern int isascii PARAMS ((int));
extern int isascii PARAMS ((int));
 
 
/* Prototypes for local functions */
/* Prototypes for local functions */
 
 
static void arm_rdi_files_info PARAMS ((struct target_ops * ignore));
static void arm_rdi_files_info PARAMS ((struct target_ops * ignore));
 
 
static int arm_rdi_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
static int arm_rdi_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
                                        int len, int should_write,
                                        int len, int should_write,
                                        struct target_ops * target));
                                        struct target_ops * target));
 
 
static void arm_rdi_prepare_to_store PARAMS ((void));
static void arm_rdi_prepare_to_store PARAMS ((void));
 
 
static void arm_rdi_fetch_registers PARAMS ((int regno));
static void arm_rdi_fetch_registers PARAMS ((int regno));
 
 
static void arm_rdi_resume PARAMS ((int pid, int step,
static void arm_rdi_resume PARAMS ((int pid, int step,
                                    enum target_signal siggnal));
                                    enum target_signal siggnal));
 
 
static int arm_rdi_start_remote PARAMS ((char *dummy));
static int arm_rdi_start_remote PARAMS ((char *dummy));
 
 
static void arm_rdi_open PARAMS ((char *name, int from_tty));
static void arm_rdi_open PARAMS ((char *name, int from_tty));
 
 
static void arm_rdi_create_inferior PARAMS ((char *exec_file, char *args,
static void arm_rdi_create_inferior PARAMS ((char *exec_file, char *args,
                                             char **env));
                                             char **env));
 
 
static void arm_rdi_close PARAMS ((int quitting));
static void arm_rdi_close PARAMS ((int quitting));
 
 
static void arm_rdi_store_registers PARAMS ((int regno));
static void arm_rdi_store_registers PARAMS ((int regno));
 
 
static void arm_rdi_mourn PARAMS ((void));
static void arm_rdi_mourn PARAMS ((void));
 
 
static void arm_rdi_send PARAMS ((char *buf));
static void arm_rdi_send PARAMS ((char *buf));
 
 
static int arm_rdi_wait PARAMS ((int pid, struct target_waitstatus * status));
static int arm_rdi_wait PARAMS ((int pid, struct target_waitstatus * status));
 
 
static void arm_rdi_kill PARAMS ((void));
static void arm_rdi_kill PARAMS ((void));
 
 
static void arm_rdi_detach PARAMS ((char *args, int from_tty));
static void arm_rdi_detach PARAMS ((char *args, int from_tty));
 
 
static void arm_rdi_interrupt PARAMS ((int signo));
static void arm_rdi_interrupt PARAMS ((int signo));
 
 
static void arm_rdi_interrupt_twice PARAMS ((int signo));
static void arm_rdi_interrupt_twice PARAMS ((int signo));
 
 
static void interrupt_query PARAMS ((void));
static void interrupt_query PARAMS ((void));
 
 
static int arm_rdi_insert_breakpoint PARAMS ((CORE_ADDR, char *));
static int arm_rdi_insert_breakpoint PARAMS ((CORE_ADDR, char *));
 
 
static int arm_rdi_remove_breakpoint PARAMS ((CORE_ADDR, char *));
static int arm_rdi_remove_breakpoint PARAMS ((CORE_ADDR, char *));
 
 
static char *rdi_error_message PARAMS ((int err));
static char *rdi_error_message PARAMS ((int err));
 
 
static enum target_signal rdi_error_signal PARAMS ((int err));
static enum target_signal rdi_error_signal PARAMS ((int err));
 
 
/* Global variables.  */
/* Global variables.  */
 
 
struct target_ops arm_rdi_ops;
struct target_ops arm_rdi_ops;
 
 
static struct Dbg_ConfigBlock gdb_config;
static struct Dbg_ConfigBlock gdb_config;
 
 
static struct Dbg_HostosInterface gdb_hostif;
static struct Dbg_HostosInterface gdb_hostif;
 
 
static int max_load_size;
static int max_load_size;
 
 
static int execute_status;
static int execute_status;
 
 
/* Send heatbeat packets? */
/* Send heatbeat packets? */
static int rdi_heartbeat = 0;
static int rdi_heartbeat = 0;
 
 
/* Target has ROM at address 0. */
/* Target has ROM at address 0. */
static int rom_at_zero = 0;
static int rom_at_zero = 0;
 
 
/* Enable logging? */
/* Enable logging? */
static int log_enable = 0;
static int log_enable = 0;
 
 
/* Name of the log file. Default is "rdi.log". */
/* Name of the log file. Default is "rdi.log". */
static char *log_filename;
static char *log_filename;
 
 
/* A little list of breakpoints that have been set.  */
/* A little list of breakpoints that have been set.  */
 
 
static struct local_bp_list_entry
static struct local_bp_list_entry
  {
  {
    CORE_ADDR addr;
    CORE_ADDR addr;
    PointHandle point;
    PointHandle point;
    struct local_bp_list_entry *next;
    struct local_bp_list_entry *next;
  }
  }
 *local_bp_list;
 *local_bp_list;


 
 
/* Stub for catch_errors.  */
/* Stub for catch_errors.  */
 
 
static int
static int
arm_rdi_start_remote (dummy)
arm_rdi_start_remote (dummy)
     char *dummy;
     char *dummy;
{
{
  return 1;
  return 1;
}
}
 
 
/* Helper callbacks for the "host interface" structure.  RDI functions call
/* Helper callbacks for the "host interface" structure.  RDI functions call
   these to forward output from the target system and so forth.  */
   these to forward output from the target system and so forth.  */
 
 
void
void
voiddummy ()
voiddummy ()
{
{
  fprintf_unfiltered (gdb_stdout, "void dummy\n");
  fprintf_unfiltered (gdb_stdout, "void dummy\n");
}
}
 
 
static void
static void
myprint (arg, format, ap)
myprint (arg, format, ap)
     PTR arg;
     PTR arg;
     const char *format;
     const char *format;
     va_list ap;
     va_list ap;
{
{
  vfprintf_unfiltered (gdb_stdout, format, ap);
  vfprintf_unfiltered (gdb_stdout, format, ap);
}
}
 
 
static void
static void
mywritec (arg, c)
mywritec (arg, c)
     PTR arg;
     PTR arg;
     int c;
     int c;
{
{
  if (isascii (c))
  if (isascii (c))
    fputc_unfiltered (c, gdb_stdout);
    fputc_unfiltered (c, gdb_stdout);
}
}
 
 
static int
static int
mywrite (arg, buffer, len)
mywrite (arg, buffer, len)
     PTR arg;
     PTR arg;
     char const *buffer;
     char const *buffer;
     int len;
     int len;
{
{
  int i;
  int i;
  char *e;
  char *e;
 
 
  e = (char *) buffer;
  e = (char *) buffer;
  for (i = 0; i < len; i++)
  for (i = 0; i < len; i++)
    {
    {
      if (isascii ((int) *e))
      if (isascii ((int) *e))
        {
        {
          fputc_unfiltered ((int) *e, gdb_stdout);
          fputc_unfiltered ((int) *e, gdb_stdout);
          e++;
          e++;
        }
        }
    }
    }
 
 
  return len;
  return len;
}
}
 
 
static void
static void
mypause (arg)
mypause (arg)
     PTR arg;
     PTR arg;
{
{
}
}
 
 
/* These last two are tricky as we have to handle the special case of
/* These last two are tricky as we have to handle the special case of
   being interrupted more carefully */
   being interrupted more carefully */
 
 
static int
static int
myreadc (arg)
myreadc (arg)
     PTR arg;
     PTR arg;
{
{
  return fgetc (stdin);
  return fgetc (stdin);
}
}
 
 
static char *
static char *
mygets (arg, buffer, len)
mygets (arg, buffer, len)
     PTR arg;
     PTR arg;
     char *buffer;
     char *buffer;
     int len;
     int len;
{
{
  return fgets (buffer, len, stdin);
  return fgets (buffer, len, stdin);
}
}
 
 
/* Prevent multiple calls to angel_RDI_close().  */
/* Prevent multiple calls to angel_RDI_close().  */
static int closed_already = 1;
static int closed_already = 1;
 
 
/* Open a connection to a remote debugger.  NAME is the filename used
/* Open a connection to a remote debugger.  NAME is the filename used
   for communication.  */
   for communication.  */
 
 
static void
static void
arm_rdi_open (name, from_tty)
arm_rdi_open (name, from_tty)
     char *name;
     char *name;
     int from_tty;
     int from_tty;
{
{
  int rslt, i;
  int rslt, i;
  unsigned long arg1, arg2;
  unsigned long arg1, arg2;
  char *openArgs = NULL;
  char *openArgs = NULL;
  char *devName = NULL;
  char *devName = NULL;
  char *p;
  char *p;
 
 
  if (name == NULL)
  if (name == NULL)
    error ("To open an RDI connection, you need to specify what serial\n\
    error ("To open an RDI connection, you need to specify what serial\n\
device is attached to the remote system (e.g. /dev/ttya).");
device is attached to the remote system (e.g. /dev/ttya).");
 
 
  /* split name after whitespace, pass tail as arg to open command */
  /* split name after whitespace, pass tail as arg to open command */
 
 
  devName = xstrdup (name);
  devName = xstrdup (name);
  p = strchr (devName, ' ');
  p = strchr (devName, ' ');
  if (p)
  if (p)
    {
    {
      *p = '\0';
      *p = '\0';
      ++p;
      ++p;
 
 
      while (*p == ' ')
      while (*p == ' ')
        ++p;
        ++p;
 
 
      openArgs = p;
      openArgs = p;
    }
    }
 
 
  /* Make the basic low-level connection.  */
  /* Make the basic low-level connection.  */
 
 
  arm_rdi_close (0);
  arm_rdi_close (0);
  rslt = Adp_OpenDevice (devName, openArgs, rdi_heartbeat);
  rslt = Adp_OpenDevice (devName, openArgs, rdi_heartbeat);
 
 
  if (rslt != adp_ok)
  if (rslt != adp_ok)
    error ("Could not open device \"%s\"", name);
    error ("Could not open device \"%s\"", name);
 
 
  gdb_config.bytesex = 2 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? 1 : 0);
  gdb_config.bytesex = 2 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? 1 : 0);
  gdb_config.fpe = 1;
  gdb_config.fpe = 1;
  gdb_config.rditype = 2;
  gdb_config.rditype = 2;
  gdb_config.heartbeat_on = 1;
  gdb_config.heartbeat_on = 1;
  gdb_config.flags = 2;
  gdb_config.flags = 2;
 
 
  gdb_hostif.dbgprint = myprint;
  gdb_hostif.dbgprint = myprint;
  gdb_hostif.dbgpause = mypause;
  gdb_hostif.dbgpause = mypause;
  gdb_hostif.dbgarg = NULL;
  gdb_hostif.dbgarg = NULL;
  gdb_hostif.writec = mywritec;
  gdb_hostif.writec = mywritec;
  gdb_hostif.readc = myreadc;
  gdb_hostif.readc = myreadc;
  gdb_hostif.write = mywrite;
  gdb_hostif.write = mywrite;
  gdb_hostif.gets = mygets;
  gdb_hostif.gets = mygets;
  gdb_hostif.hostosarg = NULL;
  gdb_hostif.hostosarg = NULL;
  gdb_hostif.reset = voiddummy;
  gdb_hostif.reset = voiddummy;
 
 
  rslt = angel_RDI_open (10, &gdb_config, &gdb_hostif, NULL);
  rslt = angel_RDI_open (10, &gdb_config, &gdb_hostif, NULL);
  if (rslt == RDIError_BigEndian || rslt == RDIError_LittleEndian)
  if (rslt == RDIError_BigEndian || rslt == RDIError_LittleEndian)
    ;                           /* do nothing, this is the expected return */
    ;                           /* do nothing, this is the expected return */
  else if (rslt)
  else if (rslt)
    {
    {
      printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
      Adp_CloseDevice ();
      Adp_CloseDevice ();
      error ("RID_open failed\n");
      error ("RID_open failed\n");
    }
    }
 
 
  rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  rslt = angel_RDI_info (RDIInfo_Points, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_Points, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  rslt = angel_RDI_info (RDIInfo_CoPro, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_CoPro, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  rslt = angel_RDI_info (RDIInfo_SemiHosting, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_SemiHosting, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
 
 
  rslt = angel_RDI_info (RDIInfo_GetLoadSize, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_GetLoadSize, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  max_load_size = arg1;
  max_load_size = arg1;
 
 
  push_target (&arm_rdi_ops);
  push_target (&arm_rdi_ops);
 
 
  target_fetch_registers (-1);
  target_fetch_registers (-1);
 
 
  rslt = angel_RDI_open (1, &gdb_config, NULL, NULL);
  rslt = angel_RDI_open (1, &gdb_config, NULL, NULL);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
    }
    }
 
 
  arg1 = rom_at_zero ? 0x0 : 0x13b;
  arg1 = rom_at_zero ? 0x0 : 0x13b;
 
 
  rslt = angel_RDI_info (RDIVector_Catch, &arg1, &arg2);
  rslt = angel_RDI_info (RDIVector_Catch, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
 
 
  arg1 = (unsigned long) "";
  arg1 = (unsigned long) "";
  rslt = angel_RDI_info (RDISet_Cmdline, &arg1, &arg2);
  rslt = angel_RDI_info (RDISet_Cmdline, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
 
 
  /* Clear out any existing records of breakpoints.  */
  /* Clear out any existing records of breakpoints.  */
  {
  {
    struct local_bp_list_entry *entry, *preventry = NULL;
    struct local_bp_list_entry *entry, *preventry = NULL;
 
 
    for (entry = local_bp_list; entry != NULL; entry = entry->next)
    for (entry = local_bp_list; entry != NULL; entry = entry->next)
      {
      {
        if (preventry)
        if (preventry)
          free (preventry);
          free (preventry);
      }
      }
  }
  }
 
 
  printf_filtered ("Connected to ARM RDI target.\n");
  printf_filtered ("Connected to ARM RDI target.\n");
  closed_already = 0;
  closed_already = 0;
  inferior_pid = 42;
  inferior_pid = 42;
}
}
 
 
/* Start an inferior process and set inferior_pid to its pid.
/* Start an inferior process and set inferior_pid to its pid.
   EXEC_FILE is the file to run.
   EXEC_FILE is the file to run.
   ARGS is a string containing the arguments to the program.
   ARGS is a string containing the arguments to the program.
   ENV is the environment vector to pass.  Errors reported with error().
   ENV is the environment vector to pass.  Errors reported with error().
   On VxWorks and various standalone systems, we ignore exec_file.  */
   On VxWorks and various standalone systems, we ignore exec_file.  */
/* This is called not only when we first attach, but also when the
/* This is called not only when we first attach, but also when the
   user types "run" after having attached.  */
   user types "run" after having attached.  */
 
 
static void
static void
arm_rdi_create_inferior (exec_file, args, env)
arm_rdi_create_inferior (exec_file, args, env)
     char *exec_file;
     char *exec_file;
     char *args;
     char *args;
     char **env;
     char **env;
{
{
  int len, rslt;
  int len, rslt;
  unsigned long arg1, arg2;
  unsigned long arg1, arg2;
  char *arg_buf;
  char *arg_buf;
  CORE_ADDR entry_point;
  CORE_ADDR entry_point;
 
 
  if (exec_file == 0 || exec_bfd == 0)
  if (exec_file == 0 || exec_bfd == 0)
    error ("No executable file specified.");
    error ("No executable file specified.");
 
 
  entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd);
  entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd);
 
 
  arm_rdi_kill ();
  arm_rdi_kill ();
  remove_breakpoints ();
  remove_breakpoints ();
  init_wait_for_inferior ();
  init_wait_for_inferior ();
 
 
  len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10;
  len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10;
  arg_buf = (char *) alloca (len);
  arg_buf = (char *) alloca (len);
  arg_buf[0] = '\0';
  arg_buf[0] = '\0';
  strcat (arg_buf, exec_file);
  strcat (arg_buf, exec_file);
  strcat (arg_buf, " ");
  strcat (arg_buf, " ");
  strcat (arg_buf, args);
  strcat (arg_buf, args);
 
 
  inferior_pid = 42;
  inferior_pid = 42;
  insert_breakpoints ();        /* Needed to get correct instruction in cache */
  insert_breakpoints ();        /* Needed to get correct instruction in cache */
 
 
  if (env != NULL)
  if (env != NULL)
    {
    {
      while (*env)
      while (*env)
        {
        {
          if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
          if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0)
            {
            {
              unsigned long top_of_memory;
              unsigned long top_of_memory;
              char *end_of_num;
              char *end_of_num;
 
 
              /* Set up memory limit */
              /* Set up memory limit */
              top_of_memory = strtoul (*env + sizeof ("MEMSIZE=") - 1,
              top_of_memory = strtoul (*env + sizeof ("MEMSIZE=") - 1,
                                       &end_of_num, 0);
                                       &end_of_num, 0);
              printf_filtered ("Setting top-of-memory to 0x%lx\n",
              printf_filtered ("Setting top-of-memory to 0x%lx\n",
                               top_of_memory);
                               top_of_memory);
 
 
              rslt = angel_RDI_info (RDIInfo_SetTopMem, &top_of_memory, &arg2);
              rslt = angel_RDI_info (RDIInfo_SetTopMem, &top_of_memory, &arg2);
              if (rslt)
              if (rslt)
                {
                {
                  printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
                  printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
                }
                }
            }
            }
          env++;
          env++;
        }
        }
    }
    }
 
 
  arg1 = (unsigned long) arg_buf;
  arg1 = (unsigned long) arg_buf;
  rslt = angel_RDI_info (RDISet_Cmdline, /* &arg1 */ (unsigned long *) arg_buf, &arg2);
  rslt = angel_RDI_info (RDISet_Cmdline, /* &arg1 */ (unsigned long *) arg_buf, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
 
 
  proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0);
  proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0);
}
}
 
 
/* This takes a program previously attached to and detaches it.  After
/* This takes a program previously attached to and detaches it.  After
   this is done, GDB can be used to debug some other program.  We
   this is done, GDB can be used to debug some other program.  We
   better not have left any breakpoints in the target program or it'll
   better not have left any breakpoints in the target program or it'll
   die when it hits one.  */
   die when it hits one.  */
 
 
static void
static void
arm_rdi_detach (args, from_tty)
arm_rdi_detach (args, from_tty)
     char *args;
     char *args;
     int from_tty;
     int from_tty;
{
{
  pop_target ();
  pop_target ();
}
}
 
 
/* Clean up connection to a remote debugger.  */
/* Clean up connection to a remote debugger.  */
 
 
static void
static void
arm_rdi_close (quitting)
arm_rdi_close (quitting)
     int quitting;
     int quitting;
{
{
  int rslt;
  int rslt;
 
 
  if (!closed_already)
  if (!closed_already)
    {
    {
      rslt = angel_RDI_close ();
      rslt = angel_RDI_close ();
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_close: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_close: %s\n", rdi_error_message (rslt));
        }
        }
      closed_already = 1;
      closed_already = 1;
      inferior_pid = 0;
      inferior_pid = 0;
      Adp_CloseDevice ();
      Adp_CloseDevice ();
      generic_mourn_inferior ();
      generic_mourn_inferior ();
    }
    }
}
}


/* Tell the remote machine to resume.  */
/* Tell the remote machine to resume.  */
 
 
static void
static void
arm_rdi_resume (pid, step, siggnal)
arm_rdi_resume (pid, step, siggnal)
     int pid, step;
     int pid, step;
     enum target_signal siggnal;
     enum target_signal siggnal;
{
{
  int rslt;
  int rslt;
  PointHandle point;
  PointHandle point;
 
 
  if (0 /* turn on when hardware supports single-stepping */ )
  if (0 /* turn on when hardware supports single-stepping */ )
    {
    {
      rslt = angel_RDI_step (1, &point);
      rslt = angel_RDI_step (1, &point);
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_step: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_step: %s\n", rdi_error_message (rslt));
        }
        }
    }
    }
  else
  else
    {
    {
      char handle[4];
      char handle[4];
      CORE_ADDR pc;
      CORE_ADDR pc;
 
 
      if (step)
      if (step)
        {
        {
          pc = read_register (PC_REGNUM);
          pc = read_register (PC_REGNUM);
          pc = arm_get_next_pc (pc);
          pc = arm_get_next_pc (pc);
          arm_rdi_insert_breakpoint (pc, handle);
          arm_rdi_insert_breakpoint (pc, handle);
        }
        }
      execute_status = rslt = angel_RDI_execute (&point);
      execute_status = rslt = angel_RDI_execute (&point);
      if (rslt == RDIError_BreakpointReached)
      if (rslt == RDIError_BreakpointReached)
        ;
        ;
      else if (rslt)
      else if (rslt)
        {
        {
          printf_filtered ("RDI_execute: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_execute: %s\n", rdi_error_message (rslt));
        }
        }
      if (step)
      if (step)
        {
        {
          arm_rdi_remove_breakpoint (pc, handle);
          arm_rdi_remove_breakpoint (pc, handle);
        }
        }
    }
    }
}
}


/* Send ^C to target to halt it.  Target will respond, and send us a
/* Send ^C to target to halt it.  Target will respond, and send us a
   packet.  */
   packet.  */
 
 
static void
static void
arm_rdi_interrupt (signo)
arm_rdi_interrupt (signo)
     int signo;
     int signo;
{
{
}
}
 
 
static void (*ofunc) ();
static void (*ofunc) ();
 
 
/* The user typed ^C twice.  */
/* The user typed ^C twice.  */
static void
static void
arm_rdi_interrupt_twice (signo)
arm_rdi_interrupt_twice (signo)
     int signo;
     int signo;
{
{
}
}
 
 
/* Ask the user what to do when an interrupt is received.  */
/* Ask the user what to do when an interrupt is received.  */
 
 
static void
static void
interrupt_query ()
interrupt_query ()
{
{
}
}
 
 
/* Wait until the remote machine stops, then return, storing status in
/* Wait until the remote machine stops, then return, storing status in
   STATUS just as `wait' would.  Returns "pid" (though it's not clear
   STATUS just as `wait' would.  Returns "pid" (though it's not clear
   what, if anything, that means in the case of this target).  */
   what, if anything, that means in the case of this target).  */
 
 
static int
static int
arm_rdi_wait (pid, status)
arm_rdi_wait (pid, status)
     int pid;
     int pid;
     struct target_waitstatus *status;
     struct target_waitstatus *status;
{
{
  status->kind = (execute_status == RDIError_NoError ?
  status->kind = (execute_status == RDIError_NoError ?
                  TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED);
                  TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED);
 
 
  /* convert stopped code from target into right signal */
  /* convert stopped code from target into right signal */
  status->value.sig = rdi_error_signal (execute_status);
  status->value.sig = rdi_error_signal (execute_status);
 
 
  return inferior_pid;
  return inferior_pid;
}
}
 
 
/* Read the remote registers into the block REGS.  */
/* Read the remote registers into the block REGS.  */
 
 
/* ARGSUSED */
/* ARGSUSED */
static void
static void
arm_rdi_fetch_registers (regno)
arm_rdi_fetch_registers (regno)
     int regno;
     int regno;
{
{
  int rslt, rdi_regmask;
  int rslt, rdi_regmask;
  unsigned long rawreg, rawregs[32];
  unsigned long rawreg, rawregs[32];
  char cookedreg[4];
  char cookedreg[4];
 
 
  if (regno == -1)
  if (regno == -1)
    {
    {
      rslt = angel_RDI_CPUread (255, 0x27fff, rawregs);
      rslt = angel_RDI_CPUread (255, 0x27fff, rawregs);
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt));
        }
        }
 
 
      for (regno = 0; regno < 15; regno++)
      for (regno = 0; regno < 15; regno++)
        {
        {
          store_unsigned_integer (cookedreg, 4, rawregs[regno]);
          store_unsigned_integer (cookedreg, 4, rawregs[regno]);
          supply_register (regno, (char *) cookedreg);
          supply_register (regno, (char *) cookedreg);
        }
        }
      store_unsigned_integer (cookedreg, 4, rawregs[15]);
      store_unsigned_integer (cookedreg, 4, rawregs[15]);
      supply_register (PS_REGNUM, (char *) cookedreg);
      supply_register (PS_REGNUM, (char *) cookedreg);
      arm_rdi_fetch_registers (PC_REGNUM);
      arm_rdi_fetch_registers (PC_REGNUM);
    }
    }
  else
  else
    {
    {
      if (regno == PC_REGNUM)
      if (regno == PC_REGNUM)
        rdi_regmask = RDIReg_PC;
        rdi_regmask = RDIReg_PC;
      else if (regno == PS_REGNUM)
      else if (regno == PS_REGNUM)
        rdi_regmask = RDIReg_CPSR;
        rdi_regmask = RDIReg_CPSR;
      else if (regno < 0 || regno > 15)
      else if (regno < 0 || regno > 15)
        {
        {
          rawreg = 0;
          rawreg = 0;
          supply_register (regno, (char *) &rawreg);
          supply_register (regno, (char *) &rawreg);
          return;
          return;
        }
        }
      else
      else
        rdi_regmask = 1 << regno;
        rdi_regmask = 1 << regno;
 
 
      rslt = angel_RDI_CPUread (255, rdi_regmask, &rawreg);
      rslt = angel_RDI_CPUread (255, rdi_regmask, &rawreg);
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt));
        }
        }
      store_unsigned_integer (cookedreg, 4, rawreg);
      store_unsigned_integer (cookedreg, 4, rawreg);
      supply_register (regno, (char *) cookedreg);
      supply_register (regno, (char *) cookedreg);
    }
    }
}
}
 
 
static void
static void
arm_rdi_prepare_to_store ()
arm_rdi_prepare_to_store ()
{
{
  /* Nothing to do.  */
  /* Nothing to do.  */
}
}
 
 
/* Store register REGNO, or all registers if REGNO == -1, from the contents
/* Store register REGNO, or all registers if REGNO == -1, from the contents
   of REGISTERS.  FIXME: ignores errors.  */
   of REGISTERS.  FIXME: ignores errors.  */
 
 
static void
static void
arm_rdi_store_registers (regno)
arm_rdi_store_registers (regno)
     int regno;
     int regno;
{
{
  int rslt, rdi_regmask;
  int rslt, rdi_regmask;
 
 
  /* These need to be able to take 'floating point register' contents */
  /* These need to be able to take 'floating point register' contents */
  unsigned long rawreg[3], rawerreg[3];
  unsigned long rawreg[3], rawerreg[3];
 
 
  if (regno == -1)
  if (regno == -1)
    {
    {
      for (regno = 0; regno < NUM_REGS; regno++)
      for (regno = 0; regno < NUM_REGS; regno++)
        arm_rdi_store_registers (regno);
        arm_rdi_store_registers (regno);
    }
    }
  else
  else
    {
    {
      read_register_gen (regno, (char *) rawreg);
      read_register_gen (regno, (char *) rawreg);
      /* RDI manipulates data in host byte order, so convert now. */
      /* RDI manipulates data in host byte order, so convert now. */
      store_unsigned_integer (rawerreg, 4, rawreg[0]);
      store_unsigned_integer (rawerreg, 4, rawreg[0]);
 
 
      if (regno == PC_REGNUM)
      if (regno == PC_REGNUM)
        rdi_regmask = RDIReg_PC;
        rdi_regmask = RDIReg_PC;
      else if (regno == PS_REGNUM)
      else if (regno == PS_REGNUM)
        rdi_regmask = RDIReg_CPSR;
        rdi_regmask = RDIReg_CPSR;
      else if (regno < 0 || regno > 15)
      else if (regno < 0 || regno > 15)
        return;
        return;
      else
      else
        rdi_regmask = 1 << regno;
        rdi_regmask = 1 << regno;
 
 
      rslt = angel_RDI_CPUwrite (255, rdi_regmask, rawerreg);
      rslt = angel_RDI_CPUwrite (255, rdi_regmask, rawerreg);
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_CPUwrite: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_CPUwrite: %s\n", rdi_error_message (rslt));
        }
        }
    }
    }
}
}


/* Read or write LEN bytes from inferior memory at MEMADDR,
/* Read or write LEN bytes from inferior memory at MEMADDR,
   transferring to or from debugger address MYADDR.  Write to inferior
   transferring to or from debugger address MYADDR.  Write to inferior
   if SHOULD_WRITE is nonzero.  Returns length of data written or
   if SHOULD_WRITE is nonzero.  Returns length of data written or
   read; 0 for error.  */
   read; 0 for error.  */
 
 
/* ARGSUSED */
/* ARGSUSED */
static int
static int
arm_rdi_xfer_memory (memaddr, myaddr, len, should_write, target)
arm_rdi_xfer_memory (memaddr, myaddr, len, should_write, target)
     CORE_ADDR memaddr;
     CORE_ADDR memaddr;
     char *myaddr;
     char *myaddr;
     int len;
     int len;
     int should_write;
     int should_write;
     struct target_ops *target; /* ignored */
     struct target_ops *target; /* ignored */
{
{
  int rslt, i;
  int rslt, i;
 
 
  if (should_write)
  if (should_write)
    {
    {
      rslt = angel_RDI_write (myaddr, memaddr, &len);
      rslt = angel_RDI_write (myaddr, memaddr, &len);
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_write: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_write: %s\n", rdi_error_message (rslt));
        }
        }
    }
    }
  else
  else
    {
    {
      rslt = angel_RDI_read (memaddr, myaddr, &len);
      rslt = angel_RDI_read (memaddr, myaddr, &len);
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_read: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_read: %s\n", rdi_error_message (rslt));
          len = 0;
          len = 0;
        }
        }
    }
    }
  return len;
  return len;
}
}


/* Display random info collected from the target.  */
/* Display random info collected from the target.  */
 
 
static void
static void
arm_rdi_files_info (ignore)
arm_rdi_files_info (ignore)
     struct target_ops *ignore;
     struct target_ops *ignore;
{
{
  char *file = "nothing";
  char *file = "nothing";
  int rslt;
  int rslt;
  unsigned long arg1, arg2;
  unsigned long arg1, arg2;
 
 
  rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  if (arg1 & (1 << 15))
  if (arg1 & (1 << 15))
    printf_filtered ("Target supports Thumb code.\n");
    printf_filtered ("Target supports Thumb code.\n");
  if (arg1 & (1 << 14))
  if (arg1 & (1 << 14))
    printf_filtered ("Target can do profiling.\n");
    printf_filtered ("Target can do profiling.\n");
  if (arg1 & (1 << 4))
  if (arg1 & (1 << 4))
    printf_filtered ("Target is real hardware.\n");
    printf_filtered ("Target is real hardware.\n");
 
 
  rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  printf_filtered ("Target can%s single-step.\n", (arg1 & 0x4 ? "" : "not"));
  printf_filtered ("Target can%s single-step.\n", (arg1 & 0x4 ? "" : "not"));
 
 
  rslt = angel_RDI_info (RDIInfo_Icebreaker, &arg1, &arg2);
  rslt = angel_RDI_info (RDIInfo_Icebreaker, &arg1, &arg2);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt));
    }
    }
  else
  else
    printf_filtered ("Target includes an EmbeddedICE.\n");
    printf_filtered ("Target includes an EmbeddedICE.\n");
}
}


static void
static void
arm_rdi_kill ()
arm_rdi_kill ()
{
{
  int rslt;
  int rslt;
 
 
  rslt = angel_RDI_open (1, &gdb_config, NULL, NULL);
  rslt = angel_RDI_open (1, &gdb_config, NULL, NULL);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt));
    }
    }
}
}
 
 
static void
static void
arm_rdi_mourn_inferior ()
arm_rdi_mourn_inferior ()
{
{
  /* We remove the inserted breakpoints in case the user wants to
  /* We remove the inserted breakpoints in case the user wants to
     issue another target and load commands to rerun his application;
     issue another target and load commands to rerun his application;
     This is something that wouldn't work on a native target, for instance,
     This is something that wouldn't work on a native target, for instance,
     as the process goes away when the inferior exits, but it works with
     as the process goes away when the inferior exits, but it works with
     some remote targets like this one.  That is why this is done here. */
     some remote targets like this one.  That is why this is done here. */
  remove_breakpoints();
  remove_breakpoints();
  unpush_target (&arm_rdi_ops);
  unpush_target (&arm_rdi_ops);
  generic_mourn_inferior ();
  generic_mourn_inferior ();
}
}


/* While the RDI library keeps track of its own breakpoints, we need
/* While the RDI library keeps track of its own breakpoints, we need
   to remember "handles" so that we can delete them later.  Since
   to remember "handles" so that we can delete them later.  Since
   breakpoints get used for stepping, be careful not to leak memory
   breakpoints get used for stepping, be careful not to leak memory
   here.  */
   here.  */
 
 
static int
static int
arm_rdi_insert_breakpoint (addr, contents_cache)
arm_rdi_insert_breakpoint (addr, contents_cache)
     CORE_ADDR addr;
     CORE_ADDR addr;
     char *contents_cache;
     char *contents_cache;
{
{
  int rslt;
  int rslt;
  PointHandle point;
  PointHandle point;
  struct local_bp_list_entry *entry;
  struct local_bp_list_entry *entry;
  int type = RDIPoint_EQ;
  int type = RDIPoint_EQ;
 
 
  if (arm_pc_is_thumb (addr) || arm_pc_is_thumb_dummy (addr))
  if (arm_pc_is_thumb (addr) || arm_pc_is_thumb_dummy (addr))
    type |= RDIPoint_16Bit;
    type |= RDIPoint_16Bit;
  rslt = angel_RDI_setbreak (addr, type, 0, &point);
  rslt = angel_RDI_setbreak (addr, type, 0, &point);
  if (rslt)
  if (rslt)
    {
    {
      printf_filtered ("RDI_setbreak: %s\n", rdi_error_message (rslt));
      printf_filtered ("RDI_setbreak: %s\n", rdi_error_message (rslt));
    }
    }
  entry =
  entry =
    (struct local_bp_list_entry *) xmalloc (sizeof (struct local_bp_list_entry));
    (struct local_bp_list_entry *) xmalloc (sizeof (struct local_bp_list_entry));
  entry->addr = addr;
  entry->addr = addr;
  entry->point = point;
  entry->point = point;
  entry->next = local_bp_list;
  entry->next = local_bp_list;
  local_bp_list = entry;
  local_bp_list = entry;
  return rslt;
  return rslt;
}
}
 
 
static int
static int
arm_rdi_remove_breakpoint (addr, contents_cache)
arm_rdi_remove_breakpoint (addr, contents_cache)
     CORE_ADDR addr;
     CORE_ADDR addr;
     char *contents_cache;
     char *contents_cache;
{
{
  int rslt;
  int rslt;
  PointHandle point;
  PointHandle point;
  struct local_bp_list_entry *entry, *preventry;
  struct local_bp_list_entry *entry, *preventry;
 
 
  for (entry = local_bp_list; entry != NULL; entry = entry->next)
  for (entry = local_bp_list; entry != NULL; entry = entry->next)
    {
    {
      if (entry->addr == addr)
      if (entry->addr == addr)
        {
        {
          break;
          break;
        }
        }
      preventry = entry;
      preventry = entry;
    }
    }
  if (entry)
  if (entry)
    {
    {
      rslt = angel_RDI_clearbreak (entry->point);
      rslt = angel_RDI_clearbreak (entry->point);
      if (rslt)
      if (rslt)
        {
        {
          printf_filtered ("RDI_clearbreak: %s\n", rdi_error_message (rslt));
          printf_filtered ("RDI_clearbreak: %s\n", rdi_error_message (rslt));
        }
        }
      /* Delete the breakpoint entry locally.  */
      /* Delete the breakpoint entry locally.  */
      if (entry == local_bp_list)
      if (entry == local_bp_list)
        {
        {
          local_bp_list = entry->next;
          local_bp_list = entry->next;
        }
        }
      else
      else
        {
        {
          preventry->next = entry->next;
          preventry->next = entry->next;
        }
        }
      free (entry);
      free (entry);
    }
    }
  return 0;
  return 0;
}
}


static char *
static char *
rdi_error_message (err)
rdi_error_message (err)
     int err;
     int err;
{
{
  switch (err)
  switch (err)
    {
    {
    case RDIError_NoError:
    case RDIError_NoError:
      return "no error";
      return "no error";
    case RDIError_Reset:
    case RDIError_Reset:
      return "debuggee reset";
      return "debuggee reset";
    case RDIError_UndefinedInstruction:
    case RDIError_UndefinedInstruction:
      return "undefined instruction";
      return "undefined instruction";
    case RDIError_SoftwareInterrupt:
    case RDIError_SoftwareInterrupt:
      return "SWI trapped";
      return "SWI trapped";
    case RDIError_PrefetchAbort:
    case RDIError_PrefetchAbort:
      return "prefetch abort, execution ran into unmapped memory?";
      return "prefetch abort, execution ran into unmapped memory?";
    case RDIError_DataAbort:
    case RDIError_DataAbort:
      return "data abort, no memory at specified address?";
      return "data abort, no memory at specified address?";
    case RDIError_AddressException:
    case RDIError_AddressException:
      return "address exception, access >26bit in 26bit mode";
      return "address exception, access >26bit in 26bit mode";
    case RDIError_IRQ:
    case RDIError_IRQ:
      return "IRQ, interrupt trapped";
      return "IRQ, interrupt trapped";
    case RDIError_FIQ:
    case RDIError_FIQ:
      return "FIQ, fast interrupt trapped";
      return "FIQ, fast interrupt trapped";
    case RDIError_Error:
    case RDIError_Error:
      return "a miscellaneous type of error";
      return "a miscellaneous type of error";
    case RDIError_BranchThrough0:
    case RDIError_BranchThrough0:
      return "branch through location 0";
      return "branch through location 0";
    case RDIError_NotInitialised:
    case RDIError_NotInitialised:
      return "internal error, RDI_open not called first";
      return "internal error, RDI_open not called first";
    case RDIError_UnableToInitialise:
    case RDIError_UnableToInitialise:
      return "internal error, target world is broken";
      return "internal error, target world is broken";
    case RDIError_WrongByteSex:
    case RDIError_WrongByteSex:
      return "See Operator: WrongByteSex";
      return "See Operator: WrongByteSex";
    case RDIError_UnableToTerminate:
    case RDIError_UnableToTerminate:
      return "See Operator: Unable to Terminate";
      return "See Operator: Unable to Terminate";
    case RDIError_BadInstruction:
    case RDIError_BadInstruction:
      return "bad instruction, illegal to execute this instruction";
      return "bad instruction, illegal to execute this instruction";
    case RDIError_IllegalInstruction:
    case RDIError_IllegalInstruction:
      return "illegal instruction, the effect of executing it is undefined";
      return "illegal instruction, the effect of executing it is undefined";
    case RDIError_BadCPUStateSetting:
    case RDIError_BadCPUStateSetting:
      return "internal error, tried to set SPSR of user mode";
      return "internal error, tried to set SPSR of user mode";
    case RDIError_UnknownCoPro:
    case RDIError_UnknownCoPro:
      return "unknown co-processor";
      return "unknown co-processor";
    case RDIError_UnknownCoProState:
    case RDIError_UnknownCoProState:
      return "cannot execute co-processor request";
      return "cannot execute co-processor request";
    case RDIError_BadCoProState:
    case RDIError_BadCoProState:
      return "recognizably broken co-processor request";
      return "recognizably broken co-processor request";
    case RDIError_BadPointType:
    case RDIError_BadPointType:
      return "internal error, bad point yype";
      return "internal error, bad point yype";
    case RDIError_UnimplementedType:
    case RDIError_UnimplementedType:
      return "internal error, unimplemented type";
      return "internal error, unimplemented type";
    case RDIError_BadPointSize:
    case RDIError_BadPointSize:
      return "internal error, bad point size";
      return "internal error, bad point size";
    case RDIError_UnimplementedSize:
    case RDIError_UnimplementedSize:
      return "internal error, unimplemented size";
      return "internal error, unimplemented size";
    case RDIError_NoMorePoints:
    case RDIError_NoMorePoints:
      return "last break/watch point was used";
      return "last break/watch point was used";
    case RDIError_BreakpointReached:
    case RDIError_BreakpointReached:
      return "breakpoint reached";
      return "breakpoint reached";
    case RDIError_WatchpointAccessed:
    case RDIError_WatchpointAccessed:
      return "watchpoint accessed";
      return "watchpoint accessed";
    case RDIError_NoSuchPoint:
    case RDIError_NoSuchPoint:
      return "attempted to clear non-existent break/watch point";
      return "attempted to clear non-existent break/watch point";
    case RDIError_ProgramFinishedInStep:
    case RDIError_ProgramFinishedInStep:
      return "end of the program reached while stepping";
      return "end of the program reached while stepping";
    case RDIError_UserInterrupt:
    case RDIError_UserInterrupt:
      return "you pressed Escape";
      return "you pressed Escape";
    case RDIError_CantSetPoint:
    case RDIError_CantSetPoint:
      return "no more break/watch points available";
      return "no more break/watch points available";
    case RDIError_IncompatibleRDILevels:
    case RDIError_IncompatibleRDILevels:
      return "incompatible RDI levels";
      return "incompatible RDI levels";
    case RDIError_LittleEndian:
    case RDIError_LittleEndian:
      return "debuggee is little endian";
      return "debuggee is little endian";
    case RDIError_BigEndian:
    case RDIError_BigEndian:
      return "debuggee is big endian";
      return "debuggee is big endian";
    case RDIError_SoftInitialiseError:
    case RDIError_SoftInitialiseError:
      return "recoverable error in RDI initialization";
      return "recoverable error in RDI initialization";
    case RDIError_InsufficientPrivilege:
    case RDIError_InsufficientPrivilege:
      return "internal error, supervisor state not accessible to monitor";
      return "internal error, supervisor state not accessible to monitor";
    case RDIError_UnimplementedMessage:
    case RDIError_UnimplementedMessage:
      return "internal error, unimplemented message";
      return "internal error, unimplemented message";
    case RDIError_UndefinedMessage:
    case RDIError_UndefinedMessage:
      return "internal error, undefined message";
      return "internal error, undefined message";
    default:
    default:
      return "undefined error message, should reset target";
      return "undefined error message, should reset target";
    }
    }
}
}
 
 
/* Convert the ARM error messages to signals that GDB knows about.  */
/* Convert the ARM error messages to signals that GDB knows about.  */
 
 
static enum target_signal
static enum target_signal
rdi_error_signal (err)
rdi_error_signal (err)
     int err;
     int err;
{
{
  switch (err)
  switch (err)
    {
    {
    case RDIError_NoError:
    case RDIError_NoError:
      return 0;
      return 0;
    case RDIError_Reset:
    case RDIError_Reset:
      return TARGET_SIGNAL_TERM;        /* ??? */
      return TARGET_SIGNAL_TERM;        /* ??? */
    case RDIError_UndefinedInstruction:
    case RDIError_UndefinedInstruction:
      return TARGET_SIGNAL_ILL;
      return TARGET_SIGNAL_ILL;
    case RDIError_SoftwareInterrupt:
    case RDIError_SoftwareInterrupt:
    case RDIError_PrefetchAbort:
    case RDIError_PrefetchAbort:
    case RDIError_DataAbort:
    case RDIError_DataAbort:
      return TARGET_SIGNAL_TRAP;
      return TARGET_SIGNAL_TRAP;
    case RDIError_AddressException:
    case RDIError_AddressException:
      return TARGET_SIGNAL_SEGV;
      return TARGET_SIGNAL_SEGV;
    case RDIError_IRQ:
    case RDIError_IRQ:
    case RDIError_FIQ:
    case RDIError_FIQ:
      return TARGET_SIGNAL_TRAP;
      return TARGET_SIGNAL_TRAP;
    case RDIError_Error:
    case RDIError_Error:
      return TARGET_SIGNAL_TERM;
      return TARGET_SIGNAL_TERM;
    case RDIError_BranchThrough0:
    case RDIError_BranchThrough0:
      return TARGET_SIGNAL_TRAP;
      return TARGET_SIGNAL_TRAP;
    case RDIError_NotInitialised:
    case RDIError_NotInitialised:
    case RDIError_UnableToInitialise:
    case RDIError_UnableToInitialise:
    case RDIError_WrongByteSex:
    case RDIError_WrongByteSex:
    case RDIError_UnableToTerminate:
    case RDIError_UnableToTerminate:
      return TARGET_SIGNAL_UNKNOWN;
      return TARGET_SIGNAL_UNKNOWN;
    case RDIError_BadInstruction:
    case RDIError_BadInstruction:
    case RDIError_IllegalInstruction:
    case RDIError_IllegalInstruction:
      return TARGET_SIGNAL_ILL;
      return TARGET_SIGNAL_ILL;
    case RDIError_BadCPUStateSetting:
    case RDIError_BadCPUStateSetting:
    case RDIError_UnknownCoPro:
    case RDIError_UnknownCoPro:
    case RDIError_UnknownCoProState:
    case RDIError_UnknownCoProState:
    case RDIError_BadCoProState:
    case RDIError_BadCoProState:
    case RDIError_BadPointType:
    case RDIError_BadPointType:
    case RDIError_UnimplementedType:
    case RDIError_UnimplementedType:
    case RDIError_BadPointSize:
    case RDIError_BadPointSize:
    case RDIError_UnimplementedSize:
    case RDIError_UnimplementedSize:
    case RDIError_NoMorePoints:
    case RDIError_NoMorePoints:
      return TARGET_SIGNAL_UNKNOWN;
      return TARGET_SIGNAL_UNKNOWN;
    case RDIError_BreakpointReached:
    case RDIError_BreakpointReached:
    case RDIError_WatchpointAccessed:
    case RDIError_WatchpointAccessed:
      return TARGET_SIGNAL_TRAP;
      return TARGET_SIGNAL_TRAP;
    case RDIError_NoSuchPoint:
    case RDIError_NoSuchPoint:
    case RDIError_ProgramFinishedInStep:
    case RDIError_ProgramFinishedInStep:
      return TARGET_SIGNAL_UNKNOWN;
      return TARGET_SIGNAL_UNKNOWN;
    case RDIError_UserInterrupt:
    case RDIError_UserInterrupt:
      return TARGET_SIGNAL_INT;
      return TARGET_SIGNAL_INT;
    case RDIError_IncompatibleRDILevels:
    case RDIError_IncompatibleRDILevels:
    case RDIError_LittleEndian:
    case RDIError_LittleEndian:
    case RDIError_BigEndian:
    case RDIError_BigEndian:
    case RDIError_SoftInitialiseError:
    case RDIError_SoftInitialiseError:
    case RDIError_InsufficientPrivilege:
    case RDIError_InsufficientPrivilege:
    case RDIError_UnimplementedMessage:
    case RDIError_UnimplementedMessage:
    case RDIError_UndefinedMessage:
    case RDIError_UndefinedMessage:
    default:
    default:
      return TARGET_SIGNAL_UNKNOWN;
      return TARGET_SIGNAL_UNKNOWN;
    }
    }
}
}


/* Define the target operations structure.  */
/* Define the target operations structure.  */
 
 
static void
static void
init_rdi_ops ()
init_rdi_ops ()
{
{
  arm_rdi_ops.to_shortname = "rdi";
  arm_rdi_ops.to_shortname = "rdi";
  arm_rdi_ops.to_longname = "ARM RDI";
  arm_rdi_ops.to_longname = "ARM RDI";
  arm_rdi_ops.to_doc = "Use a remote ARM-based computer; via the RDI library.\n\
  arm_rdi_ops.to_doc = "Use a remote ARM-based computer; via the RDI library.\n\
Specify the serial device it is connected to (e.g. /dev/ttya).";
Specify the serial device it is connected to (e.g. /dev/ttya).";
  arm_rdi_ops.to_open = arm_rdi_open;
  arm_rdi_ops.to_open = arm_rdi_open;
  arm_rdi_ops.to_close = arm_rdi_close;
  arm_rdi_ops.to_close = arm_rdi_close;
  arm_rdi_ops.to_detach = arm_rdi_detach;
  arm_rdi_ops.to_detach = arm_rdi_detach;
  arm_rdi_ops.to_resume = arm_rdi_resume;
  arm_rdi_ops.to_resume = arm_rdi_resume;
  arm_rdi_ops.to_wait = arm_rdi_wait;
  arm_rdi_ops.to_wait = arm_rdi_wait;
  arm_rdi_ops.to_fetch_registers = arm_rdi_fetch_registers;
  arm_rdi_ops.to_fetch_registers = arm_rdi_fetch_registers;
  arm_rdi_ops.to_store_registers = arm_rdi_store_registers;
  arm_rdi_ops.to_store_registers = arm_rdi_store_registers;
  arm_rdi_ops.to_prepare_to_store = arm_rdi_prepare_to_store;
  arm_rdi_ops.to_prepare_to_store = arm_rdi_prepare_to_store;
  arm_rdi_ops.to_xfer_memory = arm_rdi_xfer_memory;
  arm_rdi_ops.to_xfer_memory = arm_rdi_xfer_memory;
  arm_rdi_ops.to_files_info = arm_rdi_files_info;
  arm_rdi_ops.to_files_info = arm_rdi_files_info;
  arm_rdi_ops.to_insert_breakpoint = arm_rdi_insert_breakpoint;
  arm_rdi_ops.to_insert_breakpoint = arm_rdi_insert_breakpoint;
  arm_rdi_ops.to_remove_breakpoint = arm_rdi_remove_breakpoint;
  arm_rdi_ops.to_remove_breakpoint = arm_rdi_remove_breakpoint;
  arm_rdi_ops.to_kill = arm_rdi_kill;
  arm_rdi_ops.to_kill = arm_rdi_kill;
  arm_rdi_ops.to_load = generic_load;
  arm_rdi_ops.to_load = generic_load;
  arm_rdi_ops.to_create_inferior = arm_rdi_create_inferior;
  arm_rdi_ops.to_create_inferior = arm_rdi_create_inferior;
  arm_rdi_ops.to_mourn_inferior = arm_rdi_mourn_inferior;
  arm_rdi_ops.to_mourn_inferior = arm_rdi_mourn_inferior;
  arm_rdi_ops.to_stratum = process_stratum;
  arm_rdi_ops.to_stratum = process_stratum;
  arm_rdi_ops.to_has_all_memory = 1;
  arm_rdi_ops.to_has_all_memory = 1;
  arm_rdi_ops.to_has_memory = 1;
  arm_rdi_ops.to_has_memory = 1;
  arm_rdi_ops.to_has_stack = 1;
  arm_rdi_ops.to_has_stack = 1;
  arm_rdi_ops.to_has_registers = 1;
  arm_rdi_ops.to_has_registers = 1;
  arm_rdi_ops.to_has_execution = 1;
  arm_rdi_ops.to_has_execution = 1;
  arm_rdi_ops.to_magic = OPS_MAGIC;
  arm_rdi_ops.to_magic = OPS_MAGIC;
}
}
 
 
static void
static void
rdilogfile_command (char *arg, int from_tty)
rdilogfile_command (char *arg, int from_tty)
{
{
  if (!arg || strlen (arg) == 0)
  if (!arg || strlen (arg) == 0)
    {
    {
      printf_filtered ("rdi log file is '%s'\n", log_filename);
      printf_filtered ("rdi log file is '%s'\n", log_filename);
      return;
      return;
    }
    }
 
 
  if (log_filename)
  if (log_filename)
    free (log_filename);
    free (log_filename);
 
 
  log_filename = xstrdup (arg);
  log_filename = xstrdup (arg);
 
 
  Adp_SetLogfile (log_filename);
  Adp_SetLogfile (log_filename);
}
}
 
 
static void
static void
rdilogenable_command (char *args, int from_tty)
rdilogenable_command (char *args, int from_tty)
{
{
  if (!args || strlen (args) == 0)
  if (!args || strlen (args) == 0)
    {
    {
      printf_filtered ("rdi log is %s\n", log_enable ? "enabled" : "disabled");
      printf_filtered ("rdi log is %s\n", log_enable ? "enabled" : "disabled");
      return;
      return;
    }
    }
 
 
  if (!strcasecmp (args, "1") ||
  if (!strcasecmp (args, "1") ||
      !strcasecmp (args, "y") ||
      !strcasecmp (args, "y") ||
      !strcasecmp (args, "yes") ||
      !strcasecmp (args, "yes") ||
      !strcasecmp (args, "on") ||
      !strcasecmp (args, "on") ||
      !strcasecmp (args, "t") ||
      !strcasecmp (args, "t") ||
      !strcasecmp (args, "true"))
      !strcasecmp (args, "true"))
    Adp_SetLogEnable (log_enable = 1);
    Adp_SetLogEnable (log_enable = 1);
  else if (!strcasecmp (args, "0") ||
  else if (!strcasecmp (args, "0") ||
           !strcasecmp (args, "n") ||
           !strcasecmp (args, "n") ||
           !strcasecmp (args, "no") ||
           !strcasecmp (args, "no") ||
           !strcasecmp (args, "off") ||
           !strcasecmp (args, "off") ||
           !strcasecmp (args, "f") ||
           !strcasecmp (args, "f") ||
           !strcasecmp (args, "false"))
           !strcasecmp (args, "false"))
    Adp_SetLogEnable (log_enable = 0);
    Adp_SetLogEnable (log_enable = 0);
  else
  else
    printf_filtered ("rdilogenable: unrecognized argument '%s'\n"
    printf_filtered ("rdilogenable: unrecognized argument '%s'\n"
                     "              try y or n\n", args);
                     "              try y or n\n", args);
}
}
 
 
void
void
_initialize_remote_rdi ()
_initialize_remote_rdi ()
{
{
  init_rdi_ops ();
  init_rdi_ops ();
  add_target (&arm_rdi_ops);
  add_target (&arm_rdi_ops);
 
 
  log_filename = xstrdup ("rdi.log");
  log_filename = xstrdup ("rdi.log");
  Adp_SetLogfile (log_filename);
  Adp_SetLogfile (log_filename);
  Adp_SetLogEnable (log_enable);
  Adp_SetLogEnable (log_enable);
 
 
  add_cmd ("rdilogfile", class_maintenance,
  add_cmd ("rdilogfile", class_maintenance,
           rdilogfile_command,
           rdilogfile_command,
           "Set filename for ADP packet log.\n\
           "Set filename for ADP packet log.\n\
This file is used to log Angel Debugger Protocol packets.\n\
This file is used to log Angel Debugger Protocol packets.\n\
With a single argument, sets the logfile name to that value.\n\
With a single argument, sets the logfile name to that value.\n\
Without an argument, shows the current logfile name.\n\
Without an argument, shows the current logfile name.\n\
See also: rdilogenable\n",
See also: rdilogenable\n",
           &maintenancelist);
           &maintenancelist);
 
 
  add_cmd ("rdilogenable", class_maintenance,
  add_cmd ("rdilogenable", class_maintenance,
           rdilogenable_command,
           rdilogenable_command,
           "Set enable logging of ADP packets.\n\
           "Set enable logging of ADP packets.\n\
This will log ADP packets exchanged between gdb and the\n\
This will log ADP packets exchanged between gdb and the\n\
rdi target device.\n\
rdi target device.\n\
An argument of 1,t,true,y,yes will enable.\n\
An argument of 1,t,true,y,yes will enable.\n\
An argument of 0,f,false,n,no will disabled.\n\
An argument of 0,f,false,n,no will disabled.\n\
Withough an argument, it will display current state.\n",
Withough an argument, it will display current state.\n",
           &maintenancelist);
           &maintenancelist);
 
 
  add_show_from_set
  add_show_from_set
    (add_set_cmd ("rdiromatzero", no_class,
    (add_set_cmd ("rdiromatzero", no_class,
                  var_boolean, (char *) &rom_at_zero,
                  var_boolean, (char *) &rom_at_zero,
                  "Set target has ROM at addr 0.\n\
                  "Set target has ROM at addr 0.\n\
A true value disables vector catching, false enables vector catching.\n\
A true value disables vector catching, false enables vector catching.\n\
This is evaluated at the time the 'target rdi' command is executed\n",
This is evaluated at the time the 'target rdi' command is executed\n",
                  &setlist),
                  &setlist),
     &showlist);
     &showlist);
 
 
  add_show_from_set
  add_show_from_set
    (add_set_cmd ("rdiheartbeat", no_class,
    (add_set_cmd ("rdiheartbeat", no_class,
                  var_boolean, (char *) &rdi_heartbeat,
                  var_boolean, (char *) &rdi_heartbeat,
                  "Set enable for ADP heartbeat packets.\n\
                  "Set enable for ADP heartbeat packets.\n\
I don't know why you would want this. If you enable them,\n\
I don't know why you would want this. If you enable them,\n\
it will confuse ARM and EPI JTAG interface boxes as well\n\
it will confuse ARM and EPI JTAG interface boxes as well\n\
as the Angel Monitor.\n",
as the Angel Monitor.\n",
                  &setlist),
                  &setlist),
     &showlist);
     &showlist);
}
}
 
 
/* A little dummy to make linking with the library succeed. */
/* A little dummy to make linking with the library succeed. */
 
 
int
int
Fail ()
Fail ()
{
{
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

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