Tue Sep 28 09:45:38 1993 Peter Schauer (pes@regent.e-technik.tu-muenchen.de)
[deliverable/binutils-gdb.git] / gdb / remote-udi.c
index b796e90003b85b87205847dfa684dacff9eb4518..27023265fb61dabd0bca45294ac3ce719f7dbc92 100644 (file)
@@ -45,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.  */
@@ -67,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 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;
@@ -186,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
@@ -272,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");
 
@@ -306,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,
@@ -460,7 +436,10 @@ udi_wait (status)
        {
        case UDIStdoutReady:
          if (UDIGetStdout (sbuf, (UDISizeT)SBUF_MAX, &CountDone))
-           error ("UDIGetStdout() 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;
@@ -469,11 +448,22 @@ udi_wait (status)
          fwrite (sbuf, 1, CountDone, stderr);
          fflush(stderr);
          continue;
+
        case UDIStdinNeeded:
-         scanf ("%s", sbuf);
-         i = strlen (sbuf);
-         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.  */
@@ -568,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
@@ -1038,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);
@@ -1074,6 +1064,11 @@ download(load_arg_string, from_tty)
          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,
@@ -1135,6 +1130,8 @@ download(load_arg_string, from_tty)
              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 */
@@ -1476,12 +1473,13 @@ 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.\n\
This page took 0.027618 seconds and 4 git commands to generate.