* breakpoint.c, breakpoint.h (breakpoint_init_inferior): New function
[deliverable/binutils-gdb.git] / gdb / remote-udi.c
index 681854c0f491dfb49fa457d76d77858834c8e3d7..27023265fb61dabd0bca45294ac3ce719f7dbc92 100644 (file)
@@ -27,12 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  - Originally written by Daniel Mann at AMD for MiniMON and gdb 3.91.6.
  - David Wood (wood@lab.ultra.nyu.edu) at New York University adapted this
        file to gdb 3.95.  I was unable to get this working on sun3os4
-       with termio, only with sgtty.  Because we are only attempting to
-       use this module to debug our kernel, which is already loaded when
-       gdb is started up, I did not code up the file downloading facilities.  
-       As a result this module has only the stubs to download files. 
-       You should get tagged at compile time if you need to make any 
-       changes/additions.
+       with termio, only with sgtty.
  - Daniel Mann at AMD took the 3.95 adaptions above and replaced
        MiniMON interface with UDI-p interface.   */
  
@@ -50,6 +45,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "29k-share/udi/udiproc.h"
 #include "gdbcmd.h"
 #include "bfd.h"
+#include "gdbcore.h" /* For download function */
 
 /* access the register store directly, without going through
    the normal handler functions. This avoids an extra data copy.  */
@@ -57,7 +53,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 static int kiodebug;
 extern int stop_soon_quietly;           /* for wait_for_inferior */
 extern struct value *call_function_by_hand();
-static void udi_resume PARAMS ((int step, int sig));
+static void udi_resume PARAMS ((int pid, int step, int sig));
 static void udi_fetch_registers PARAMS ((int regno));
 static void udi_load PARAMS ((char *args, int from_tty));
 static void fetch_register PARAMS ((int regno));
@@ -72,18 +68,11 @@ static int udi_read_inferior_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
                                             int len));
 static void download PARAMS ((char *load_arg_string, int from_tty));
 char   CoffFileName[100] = "";
-/*
- * Processor types. 
- */
-#define TYPE_UNKNOWN    0
-#define TYPE_A29000     1
-#define TYPE_A29030     2
-#define TYPE_A29050     3
-static  char *processor_name[] = { "Unknown", "Am29000", "Am29030", "Am29050" };
-static  int processor_type=TYPE_UNKNOWN;
-#define FREEZE_MODE     (read_register(CPS_REGNUM) && 0x400)
-#define USE_SHADOW_PC  ((processor_type == TYPE_A29050) && FREEZE_MODE) 
 
+#define FREEZE_MODE     (read_register(CPS_REGNUM) & 0x400)
+#define USE_SHADOW_PC  ((processor_type == a29k_freeze_mode) && FREEZE_MODE)
+
+/* FIXME: Replace with `set remotedebug'.  Also, seems not to be used.  */
 #define LLOG_FILE "udi.log"
 #if defined (LOG_FILE)
 FILE *log_file;
@@ -130,22 +119,6 @@ typedef    struct  bkpt_entry_str
 static bkpt_entry_t    bkpt_table[BKPT_TABLE_SIZE];
 extern char    dfe_errmsg[];           /* error string */
 
-/* Called when SIGALRM signal sent due to alarm() timeout.  */
-#ifndef HAVE_TERMIO
-
-volatile int n_alarms;
-
-static void
-udi_timer ()
-{
-#if 0
-  if (kiodebug)
-    printf ("udi_timer called\n");
-#endif
-  n_alarms++;
-}
-#endif /* HAVE_TERMIO */
-
 /* malloc'd name of the program on the remote system.  */
 static char *prog_name = NULL;
 
@@ -207,8 +180,14 @@ udi_create_inferior (execfile, args, env)
 static void
 udi_mourn()
 {
-        pop_target ();                /* Pop back to no-child state */
-        generic_mourn_inferior ();
+#if 0
+  /* Requiring "target udi" each time you run is a major pain.  I suspect
+     this was just blindy copied from remote.c, in which "target" and
+     "run" are combined.  Having a udi target without an inferior seems
+     to work between "target udi" and "run", so why not now?  */
+  pop_target ();                /* Pop back to no-child state */
+#endif
+  generic_mourn_inferior ();
 }
 
 /******************************************************************** UDI_OPEN
@@ -238,6 +217,11 @@ udi_open (name, from_tty)
 
   target_preopen(from_tty);
 
+  entry.Offset = 0;
+
+  for (cnt = 0; cnt < BKPT_TABLE_SIZE; cnt++)
+    bkpt_table[cnt].Type = 0;
+
   if (udi_config_id)
     free (udi_config_id);
 
@@ -251,19 +235,6 @@ udi_open (name, from_tty)
 
   push_target (&udi_ops);
 
-#ifndef HAVE_TERMIO
-#ifndef NO_SIGINTERRUPT
-  /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
-     the read.  */
-  if (siginterrupt (SIGALRM, 1) != 0)
-    error ("udi_open: siginterrupt() %s", safe_strerror(errno));
-#endif
-
-  /* Set up read timeout timer.  */
-  if ((void (*)) signal (SIGALRM, udi_timer) == (void (*)) -1)
-    error ("udi_open: signal() %s", safe_strerror(errno));
-#endif
-
 #if defined (LOG_FILE)
   log_file = fopen (LOG_FILE, "w");
   if (log_file == NULL)
@@ -301,31 +272,8 @@ udi_open (name, from_tty)
        }
     }
 
-  /* Determine the processor revision level */
-  prl = (unsigned int)read_register (CFG_REGNUM) >> 24;
-  if ((prl&0xe0) == 0)
-    {
-      fprintf_filtered (stderr,
-                       "Remote debugging Am29000 rev %c\n",'A'+(prl&0x1f));
-      processor_type = TYPE_A29000;
-    }
-  else if ((prl&0xe0) == 0x40)       /* 29030 = 0x4* */
-    {
-      fprintf_filtered (stderr,
-                       "Remote debugging Am2903* rev %c\n",'A'+(prl&0x1f));
-      processor_type = TYPE_A29030;
-    }
-  else if ((prl&0xe0) == 0x20)       /* 29050 = 0x2* */
-    {
-      fprintf_filtered (stderr,
-                       "Remote debugging Am29050 rev %c\n",'A'+(prl&0x1f));
-      processor_type = TYPE_A29050;
-    }
-  else
-    {
-      processor_type = TYPE_UNKNOWN;
-      fprintf_filtered (stderr,"WARNING: processor type unknown.\n");
-    }
+  a29k_get_processor_type ();
+
   if (UDICreateProcess (&PId))
      fprintf(stderr, "UDICreateProcess() failed\n");
 
@@ -335,9 +283,8 @@ udi_open (name, from_tty)
     error ("UDICapabilities() failed");
   if (from_tty)
     {
-      printf_filtered ("Remote debugging an %s connected via UDI socket,\n\
+      printf_filtered ("Connected via UDI socket,\n\
  DFE-IPC version %x.%x.%x  TIP-IPC version %x.%x.%x  TIP version %x.%x.%x\n %s\n",
-                      processor_name[processor_type],
                       (DFEIPCId>>8)&0xf, (DFEIPCId>>4)&0xf, DFEIPCId&0xf,
                       (TIPIPCId>>8)&0xf, (TIPIPCId>>4)&0xf, TIPIPCId&0xf,
                       (TargetId>>8)&0xf, (TargetId>>4)&0xf, TargetId&0xf,
@@ -391,6 +338,7 @@ udi_attach (args, from_tty)
   UDISizeT     Size = 4;
   UDICount     CountDone;
   UDIBool      HostEndian = 0;
+  UDIError     err;
 
   if (udi_session_id < 0)
       error ("UDI connection not opened yet, use the 'target udi' command.\n");
@@ -399,9 +347,9 @@ udi_attach (args, from_tty)
       printf ("Attaching to remote program %s...\n", prog_name);
 
   UDIStop();
-  From.Space = 11;
-  From.Offset = UDI29KSpecialRegs;
-  if(UDIRead(From, &PC_adds, Count, Size, &CountDone, HostEndian))
+  From.Space = UDI29KSpecialRegs;
+  From.Offset = 11;
+  if (err = UDIRead(From, &PC_adds, Count, Size, &CountDone, HostEndian))
     error ("UDIRead failed in udi_attach");
   printf ("Remote process is now halted, pc1 = 0x%x.\n", PC_adds);
 }
@@ -431,8 +379,8 @@ udi_detach (args,from_tty)
 ** Tell the remote machine to resume.  */
 
 static void
-udi_resume (step, sig)
-     int step, sig;
+udi_resume (pid, step, sig)
+     int pid, step, sig;
 {
   UDIError tip_error;
   UDIUInt32 Steps = 1;
@@ -488,7 +436,10 @@ udi_wait (status)
        {
        case UDIStdoutReady:
          if (UDIGetStdout (sbuf, (UDISizeT)SBUF_MAX, &CountDone))
-           error ("UDIGetStdin() failed in udi_wait");
+           /* This is said to happen if the program tries to output
+              a whole bunch of output (more than SBUF_MAX, I would
+              guess).  It doesn't seem to happen with the simulator.  */
+           warning ("UDIGetStdout() failed in udi_wait");
          fwrite (sbuf, 1, CountDone, stdout);
          fflush(stdout);
          continue;
@@ -497,10 +448,25 @@ udi_wait (status)
          fwrite (sbuf, 1, CountDone, stderr);
          fflush(stderr);
          continue;
+
        case UDIStdinNeeded:
-         printf("DEBUG: stdin requested ... continue\n");
-         /*    UDIPutStdin(sbuf, (UDISizeT)i, &CountDone); */
-         continue;
+         {
+           int ch;
+           i = 0;
+           do
+             {
+               ch = getchar ();
+               if (ch == EOF)
+                 break;
+               sbuf[i++] = ch;
+             } while (i < SBUF_MAX && ch != '\n');
+           UDIPutStdin (sbuf, (UDISizeT)i, &CountDone);
+           continue;
+         }
+
+       case UDIRunning:
+         /* In spite of the fact that we told UDIWait to wait forever, it will
+            return spuriously sometimes.  */
        case UDIStdinModeX:
          continue;
        default:
@@ -569,14 +535,11 @@ udi_wait (status)
     case UDINotExecuting:
       WSETSTOP ((*status), SIGTERM);
       break;
-    case UDIRunning:
-      WSETSTOP ((*status), SIGILL);
-      break;
     case UDIStopped:
       WSETSTOP ((*status), SIGTSTP);
       break;
     case UDIWarned:
-      WSETSTOP ((*status), SIGLOST);
+      WSETSTOP ((*status), SIGURG);
       break;
     case UDIStepped:
     case UDIBreak:
@@ -595,7 +558,7 @@ udi_wait (status)
 
   timeout = old_timeout;       /* Restore original timeout value */
   immediate_quit = old_immediate_quit;
-  return 0;
+  return inferior_pid;
 }
 
 /********************************************************** UDI_FETCH_REGISTERS
@@ -612,6 +575,7 @@ int regno;
   UDISizeT     Size = 4;
   UDICount     CountDone;
   UDIBool      HostEndian = 0;
+  UDIError     err;
   int          i;
 
   if (regno >= 0)  {
@@ -625,7 +589,7 @@ int regno;
   From.Offset = 1;
   To = (UDIUInt32 *)&registers[4 * GR1_REGNUM];
   Count = 1;
-  if (UDIRead(From, To, Count, Size, &CountDone, HostEndian))
+  if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
     error("UDIRead() failed in udi_fetch_registers");
 
   register_valid[GR1_REGNUM] = 1;
@@ -638,7 +602,7 @@ int regno;
   From.Offset = 64;
   To = (UDIUInt32 *)&registers[4 * GR64_REGNUM];
   Count = 32;
-  if (UDIRead(From, To, Count, Size, &CountDone, HostEndian))
+  if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
     error("UDIRead() failed in udi_fetch_registers");
 
   for (i = GR64_REGNUM; i < GR64_REGNUM + 32; i++)
@@ -652,7 +616,7 @@ int regno;
   From.Offset = 96;
   To = (UDIUInt32 *)&registers[4 * GR96_REGNUM];
   Count = 32;
-  if (UDIRead(From, To, Count, Size, &CountDone, HostEndian))
+  if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
     error("UDIRead() failed in udi_fetch_registers");
 
   for (i = GR96_REGNUM; i < GR96_REGNUM + 32; i++)
@@ -664,7 +628,7 @@ int regno;
   From.Offset = 0;
   To = (UDIUInt32 *)&registers[4 * LR0_REGNUM];
   Count = 128;
-  if (UDIRead(From, To, Count, Size, &CountDone, HostEndian))
+  if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
     error("UDIRead() failed in udi_fetch_registers");
 
   for (i = LR0_REGNUM; i < LR0_REGNUM + 128; i++)
@@ -676,7 +640,7 @@ int regno;
   From.Offset = 0;
   To = (UDIUInt32 *)&registers[4 * SR_REGNUM(0)];
   Count = 15;
-  if (UDIRead(From, To, Count, Size, &CountDone, HostEndian))
+  if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
     error("UDIRead() failed in udi_fetch_registers");
 
   for (i = SR_REGNUM(0); i < SR_REGNUM(0) + 15; i++)
@@ -693,7 +657,7 @@ int regno;
     From.Offset = 128;
     To = (UDIUInt32 *)&registers[4 * SR_REGNUM(128)];
     Count = 135-128 + 1;
-    if (UDIRead(From, To, Count, Size, &CountDone, HostEndian))
+    if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
       error("UDIRead() failed in udi_fetch_registers");
 
     for (i = SR_REGNUM(128); i < SR_REGNUM(128) + 135-128+1; i++)
@@ -1028,9 +992,9 @@ download(load_arg_string, from_tty)
        {
          token++;
 
-         if (strcmp (token, "ms") == 0)
+         if (STREQ (token, "ms"))
            stack_sizes[1] = atol (strtok (NULL, " \t"));
-         else if (strcmp (token, "rs") == 0)
+         else if (STREQ (token, "rs"))
            stack_sizes[0] = atol (strtok (NULL, " \t"));
          else
            {
@@ -1064,7 +1028,7 @@ download(load_arg_string, from_tty)
        }
     }
 
-  pbfd = bfd_openr (filename, 0);
+  pbfd = bfd_openr (filename, gnutarget);
 
   if (!pbfd) 
     perror_with_name (filename);
@@ -1087,19 +1051,24 @@ download(load_arg_string, from_tty)
          const char *section_name;
 
          section_name = bfd_get_section_name (pbfd, section);
-         if (strcmp (section_name, ".text") == 0 && !load_text)
+         if (STREQ (section_name, ".text") && !load_text)
            continue;
-         else if (strcmp (section_name, ".data") == 0 && !load_data)
+         else if (STREQ (section_name, ".data") && !load_data)
            continue;
-         else if (strcmp (section_name, ".bss") == 0 && !load_bss)
+         else if (STREQ (section_name, ".bss") && !load_bss)
            continue;
-         else if (strcmp (section_name, ".lit") == 0 && !load_lit)
+         else if (STREQ (section_name, ".lit") && !load_lit)
            continue;
 
          To.Offset = bfd_get_section_vma (pbfd, section);
          section_size = bfd_section_size (pbfd, section);
          section_end = To.Offset + section_size;
 
+         if (section_size == 0)
+           /* This is needed at least in the BSS case, where the code
+              below starts writing before it even checks the size.  */
+           continue;
+
          printf("[Loading section %s at %x (%d bytes)]\n",
                 section_name,
                 To.Offset,
@@ -1158,30 +1127,42 @@ download(load_arg_string, from_tty)
          else                  /* BSS */
            {
              UDIResource From;
-             char zero = 0;
+             unsigned long zero = 0;
 
              /* Write a zero byte at the vma */
+             /* FIXME: Broken for sections of 1-3 bytes (we test for
+                zero above).  */
              err = UDIWrite ((UDIHostMemPtr)&zero,     /* From */
                              To,                       /* To */
                              (UDICount)1,              /* Count */
-                             (UDISizeT)1,              /* Size */
+                             (UDISizeT)4,              /* Size */
                              &Count,                   /* CountDone */
                              (UDIBool)0);              /* HostEndian */
              if (err)
                error ("UDIWrite failed, error = %d", err);
 
              From = To;
-             To.Offset++;
+             To.Offset+=4;
 
              /* Now, duplicate it for the length of the BSS */
              err = UDICopy (From,                      /* From */
                             To,                        /* To */
-                            (UDICount)section_size - 1, /* Count */
-                            (UDISizeT)1,               /* Size */
+                            (UDICount)(section_size/4 - 1), /* Count */
+                            (UDISizeT)4,               /* Size */
                             &Count,                    /* CountDone */
                             (UDIBool)1);               /* Direction */
              if (err)
-               error ("UDICopy failed, error = %d", err);
+               {
+                 char message[100];
+                 int xerr;
+
+                 xerr = UDIGetErrorMsg(err, 100, message, &Count);
+                 if (!xerr)
+                   fprintf (stderr, "Error is %s\n", message);
+                 else
+                   fprintf (stderr, "xerr is %d\n", xerr);
+                 error ("UDICopy failed, error = %d", err);
+               }
            }
 
        }
@@ -1259,6 +1240,7 @@ udi_read_inferior_memory(memaddr, myaddr, len)
   UDISizeT     Size = 1;
   UDICount     CountDone = 0;
   UDIBool      HostEndian = 0;
+  UDIError     err;
   
   From.Space = udi_memory_space(memaddr);      
   To = (UDIUInt32*)myaddr;
@@ -1267,8 +1249,8 @@ udi_read_inferior_memory(memaddr, myaddr, len)
   {    Count = len - nread;
        if (Count > MAXDATA) Count = MAXDATA;
        From.Offset = memaddr + nread;
-        if(UDIRead(From, To, Count, Size, &CountDone, HostEndian))
-       {  error("UDIWrite() failed in udi_read_inferrior_memory");
+        if(err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
+       {  error("UDIRead() failed in udi_read_inferrior_memory");
           break;       
        }
        else
@@ -1302,6 +1284,7 @@ fetch_register (regno)
   UDISizeT     Size = 4;
   UDICount     CountDone;
   UDIBool      HostEndian = 0;
+  UDIError     err;
   int                  result;
 
   if (regno == GR1_REGNUM)
@@ -1342,7 +1325,7 @@ fetch_register (regno)
       From.Offset = regnum_to_srnum(regno); 
     }
 
-  if (UDIRead(From, &To, Count, Size, &CountDone, HostEndian))
+  if (err = UDIRead(From, &To, Count, Size, &CountDone, HostEndian))
     error("UDIRead() failed in udi_fetch_registers");
 
   supply_register(regno, (char *) &To);
@@ -1490,15 +1473,34 @@ void  convert16() {;}
 void  convert32() {;}
 FILE* EchoFile = 0;            /* used for debugging */
 int   QuietMode = 0;           /* used for debugging */
+\f
+/* Target_ops vector.  Not static because there does not seem to be
+   any portable way to do a forward declaration of a static variable.
+   The RS/6000 doesn't like "extern" followed by "static"; SunOS
+   /bin/cc doesn't like "static" twice.  */
 
-/****************************************************************************/
-/* 
- *  Define the target subroutine names 
- */
-static struct target_ops udi_ops = {
+struct target_ops udi_ops = {
         "udi",
        "Remote UDI connected TIP",
-       "Remote debug an AMD 29k using UDI socket connection to TIP process",
+       "Remote debug an AMD 29k using UDI socket connection to TIP process.\n\
+Arguments are\n\
+`configuration-id AF_INET hostname port-number'\n\
+    To connect via the network, where hostname and port-number specify the\n\
+    host and port where you can connect via UDI.\n\
+    configuration-id is unused.\n\
+\n\
+`configuration-id AF_UNIX socket-name tip-program'\n\
+    To connect using a local connection to the \"tip.exe\" program which is\n\
+    supplied by AMD.  If socket-name specifies an AF_UNIX socket then the\n\
+    tip program must already be started; connect to it using that socket.\n\
+    If not, start up tip-program, which should be the name of the tip\n\
+    program.  If appropriate, the PATH environment variable is searched.\n\
+    configuration-id is unused.\n\
+\n\
+`configuration-id'\n\
+    Look up the configuration in ./udi_soc or /etc/udi_soc, which\n\
+    are files containing lines in the above formats.  configuration-id is\n\
+    used to pick which line of the file to use.",
         udi_open,
        udi_close,
         udi_attach,
This page took 0.029551 seconds and 4 git commands to generate.