* Makefile.in (SUBDIRS): Add mswin so that make cleanup cleans up
authorStu Grossman <grossman@cygnus>
Sat, 19 Apr 1997 01:42:34 +0000 (01:42 +0000)
committerStu Grossman <grossman@cygnus>
Sat, 19 Apr 1997 01:42:34 +0000 (01:42 +0000)
that directory.
* defs.h utils.c (error warning):  Make message be const.
* main.c (fputs_unfiltered):  Only send gdb_stdout and gdb_stderr
to hook.  Otherwise send it to fputs.
* monitor.c monitor.h (monitor_get_dev_name):  New function.  Does
the obvious.
* remote-e7000.c:  Remove debugify stuff.  Change printf, fprintf
to _filtered forms to make output appear in GUIs.  Replace all
uses of SERIAL_READCHAR with readchar, which has better error
checking.
* (e7000_parse_device):  Add prototype.
* (readchar):  Improve doc.  Handle random serial errors.
* (expect):  Disable notice_quit code.  It's busted.  Remove
serial error handling (it's now handled in readchar).  Remove
remote_debug echoing.  That's handled in readchar as well.
* (e7000_parse_device):  Remove serial_flag arg.  It's not
necessary.
* (e7000_open):  Split into two pieces.  Second part is
e7000_start_remote, and is error protected.  Now, when we connect
to the target, we setup the initial frame and registers so that
the user gets an immediate indication of where the target is.
* (gch):  Remove debug output.  That's handled by readchar.
* (e7000_read_inferior_memory):  Handle errors better.
* (_initialize_remote_e7000):  Get rid of `<xxx>' things from
command names.  They show up when doing completion and confuse
things horribly.
* ser-e7kpc.c:  Remove the last seven months of brain damage.  Get
rid of the DLL's since we can access the device directly from Win32s
and Win95.  Get rid of debugify crud.
* serial.c:  Remove debugify cruft.
* (serial_logchar serial_log_command serial_write serial_readchar
serial_send_break serial_close):  Merge common functionality into
serial_logchar.  Clean up rest of routines.
* sparclet-rom.c:  Disembowel.  Leave only download routine.
Download routine now switches to remote target automatically.
* top.c (disconnect):  Only define if SIGHUP is defined.  Cleans
up MSVC/Win32 problem.
* utils.c (gdb_flush):  Don't call hook unless it's for gdb_stdout
or gdb_stderr.
* config/sh/tm-sh.h:  Define TARGET_SH for WinGDB.
* config/sparc/tm-sparclet.h:  Remove override for prompt.

gdb/ChangeLog
gdb/Makefile.in
gdb/config/sh/tm-sh.h
gdb/config/sparc/tm-sparclet.h
gdb/ser-e7kpc.c
gdb/serial.c
gdb/sparclet-rom.c
gdb/top.c
gdb/utils.c

index fbc1aec..7400b94 100644 (file)
@@ -1,3 +1,48 @@
+Fri Apr 18 17:25:10 1997  Stu Grossman  (grossman@critters.cygnus.com)
+
+       * Makefile.in (SUBDIRS):  Add mswin so that make cleanup cleans up
+       that directory.
+       * defs.h utils.c (error warning):  Make message be const.
+       * main.c (fputs_unfiltered):  Only send gdb_stdout and gdb_stderr
+       to hook.  Otherwise send it to fputs.
+       * monitor.c monitor.h (monitor_get_dev_name):  New function.  Does
+       the obvious.
+       * remote-e7000.c:  Remove debugify stuff.  Change printf, fprintf
+       to _filtered forms to make output appear in GUIs.  Replace all
+       uses of SERIAL_READCHAR with readchar, which has better error
+       checking.
+       * (e7000_parse_device):  Add prototype.
+       * (readchar):  Improve doc.  Handle random serial errors.
+       * (expect):  Disable notice_quit code.  It's busted.  Remove
+       serial error handling (it's now handled in readchar).  Remove
+       remote_debug echoing.  That's handled in readchar as well.
+       * (e7000_parse_device):  Remove serial_flag arg.  It's not
+       necessary.
+       * (e7000_open):  Split into two pieces.  Second part is
+       e7000_start_remote, and is error protected.  Now, when we connect
+       to the target, we setup the initial frame and registers so that
+       the user gets an immediate indication of where the target is.
+       * (gch):  Remove debug output.  That's handled by readchar.
+       * (e7000_read_inferior_memory):  Handle errors better.
+       * (_initialize_remote_e7000):  Get rid of `<xxx>' things from
+       command names.  They show up when doing completion and confuse
+       things horribly.
+       * ser-e7kpc.c:  Remove the last seven months of brain damage.  Get
+       rid of the DLL's since we can access the device directly from Win32s
+       and Win95.  Get rid of debugify crud.
+       * serial.c:  Remove debugify cruft.
+       * (serial_logchar serial_log_command serial_write serial_readchar
+       serial_send_break serial_close):  Merge common functionality into
+       serial_logchar.  Clean up rest of routines.
+       * sparclet-rom.c:  Disembowel.  Leave only download routine.
+       Download routine now switches to remote target automatically.
+       * top.c (disconnect):  Only define if SIGHUP is defined.  Cleans
+       up MSVC/Win32 problem.
+       * utils.c (gdb_flush):  Don't call hook unless it's for gdb_stdout
+       or gdb_stderr.
+       * config/sh/tm-sh.h:  Define TARGET_SH for WinGDB.
+       * config/sparc/tm-sparclet.h:  Remove override for prompt.
+
 Fri Apr 18 13:38:19 1997  Doug Evans  <dje@canuck.cygnus.com>
 
        * remote-sim.c (gdbsim_open): Only pass -E to sim_open if
index fb73139..224f7c3 100644 (file)
@@ -490,7 +490,7 @@ NTSOBS = standalone.o
 
 NTSSTART = kdb-start.o
 
-SUBDIRS = doc testsuite nlm
+SUBDIRS = doc testsuite nlm mswin
 
 # For now, shortcut the "configure GDB for fewer languages" stuff.
 YYFILES = c-exp.tab.c java-exp.tab.c f-exp.tab.c m2-exp.tab.c
index a92cedc..0fe3b5e 100644 (file)
@@ -281,3 +281,6 @@ extern CORE_ADDR sh_push_return_address   PARAMS ((CORE_ADDR, CORE_ADDR));
 #define REGISTER_SIZE 4
 
 #define COERCE_FLOAT_TO_DOUBLE 1
+
+/* Need this for WinGDB.  See gdb/mswin/{regdoc.h, gdbwin.c, gui.cpp}.  */
+#define TARGET_SH
index 520123f..bc43083 100644 (file)
@@ -105,10 +105,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #undef PRINT_REGISTER_HOOK
 #define PRINT_REGISTER_HOOK(regno)
 
-/* Override the standard gdb prompt when compiled for this target.  */
-    
-#define DEFAULT_PROMPT  "(gdbslet) "
-
 /* Offsets into jmp_buf.  Not defined by Sun, but at least documented in a
    comment in <machine/setjmp.h>! */
 
index 4982b8c..b0976df 100644 (file)
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
-
-/*#define DEBUGIFY*/
-#include "debugify.h"
-
-#define RMT_DBG(x) if (remote_debug) printf_unfiltered x
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
+#if defined __GO32__ || defined _WIN32
+#include "defs.h"
+#include "serial.h"
+#include "gdb_string.h"
 
-#if defined(__GO32__) || defined(_WIN32)
-#if defined(_WIN32)
-/* we define the 32-bit calls which thunk to 16-bit dll calls 
- */
-#include "win-e7kpc.h"
-#include "target.h"
+/* MSVC uses strnicmp instead of strncasecmp */
 #ifdef _MSC_VER
-/* msvc uses strnicmp instead of strncasecmp */
 #define strncasecmp strnicmp
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
 #define W32SUT_32
-#include "windefs.h"
-#include "w32sut.h"
+#include <w32sut.h>
 #endif
-#include "gdbwin.h"
 
-#else
+#ifdef __GO32__
 #include <sys/dos.h>
-#include "defs.h"
-#endif /* _WIN32 */
-#include "serial.h"
-
+#endif
 
 static int e7000pc_open PARAMS ((serial_t scb, const char *name));
 static void e7000pc_raw PARAMS ((serial_t scb));
@@ -99,107 +89,24 @@ static unsigned long pon;
 static unsigned long irqtop;
 static unsigned long board_at;
 
-#ifdef _WIN32
-/* These routines are normally part of the go32 dos extender.
- * We redefine them here to be calls into their Windoze equivs. */
-static void dosmemget(int offset, int length, void *buffer);
-static void dosmemput(const void *buffer, int length, int offset);
-
-/* dll entry points for w32se7kpc.dll; call kernel32 to thunk for us */
-typedef BOOL (APIENTRY * PUTREGISTER) (
-       HANDLE hModule,
-        LPCSTR lpsz16BitDLL,
-       LPCSTR lpszInitName,
-       LPCSTR lpszProcName,
-       UT32PROC * ppfn32Thunk,
-       FARPROC pfnUT32Callback,
-       LPVOID lpBuff
-       );
-
-/* dll entry points for w95e7kpc.dll and w31e7kpc.dll */
-HANDLE hWine7kpc = 0;
-
-typedef int (APIENTRY * PWIN_LOAD_E7KPC) (void);
-typedef void (APIENTRY * PWIN_UNLOAD_E7KPC) (void);
-typedef void (APIENTRY * PWIN_MEM_GET) (unsigned char *buf, int len, int offset);
-typedef void (APIENTRY * PWIN_MEM_PUT) (unsigned char *buf, int len, int offset);
-typedef void (APIENTRY * PWIN_REMOTE_DEBUG) (int val);
-
-PWIN_LOAD_E7KPC pwin_load_e7kpc=NULL;
-PWIN_UNLOAD_E7KPC pwin_unload_e7kpc=NULL;
-PWIN_MEM_GET pwin_mem_get=NULL;
-PWIN_MEM_PUT pwin_mem_put=NULL;
-PWIN_REMOTE_DEBUG pwin_remote_debug=NULL;
-
-static int last_remote_debug = 0;
-static int wine7kpc_loaded = 0;
-static void win_unload_e7kpc (void);
-
-static int win_load_e7kpc (void)
-{
-    if (pwin_load_e7kpc && !wine7kpc_loaded)
-    {
-      wine7kpc_loaded = pwin_load_e7kpc();
-      if (wine7kpc_loaded)
-         make_final_cleanup(win_unload_e7kpc, 0);
-    }
-    return wine7kpc_loaded;
-}
-
-static void win_unload_e7kpc (void)
-{
-    DBG(("win_unload_e7kpc\n"));
-    if (pwin_unload_e7kpc && wine7kpc_loaded)
-      pwin_unload_e7kpc();
-    wine7kpc_loaded = 0;
-}
-
-static void win_mem_get (unsigned char *buf, int offset, int len)
-{
-    DBG(("win_mem_get(&buf=<x%x> offset=<x%x> len=<%d>)\n", buf, offset, len));
-    if (remote_debug!=last_remote_debug && pwin_remote_debug)
-    {
-       pwin_remote_debug(remote_debug);
-        last_remote_debug=remote_debug;
-    }
-    if (pwin_mem_get) 
-    {
-        pwin_mem_get (buf, offset, len);
-    }
-}
-
-static void win_mem_put (unsigned char *buf, int offset, int len)
-{
-    DBG(("win_mem_put(buf=<%s> offset=<x%x> len=<%d>)\n", buf, offset, len));
-    if (remote_debug!=last_remote_debug && pwin_remote_debug)
-    {
-       pwin_remote_debug(remote_debug);
-        last_remote_debug=remote_debug;
-    }
-    if (pwin_mem_put)
-      pwin_mem_put (buf, offset, len);
-}
-
-static void dosmemget(int offset, int length, void *buffer)
-{
-    win_mem_get(buffer, offset, length);
-}
-
-static void dosmemput(const void *buffer, int length, int offset)
-{
-    win_mem_put((unsigned char*)buffer, offset, length);
-}
-
-#endif /* _WIN32 */
+#ifdef __GO32__
 
 #define SET_BYTE(x,y)   { char _buf = y;dosmemput(&_buf,1, x);}
 #define SET_WORD(x,y)   { short _buf = y;dosmemput(&_buf,2, x);}
 #define GET_BYTE(x)     ( dosmemget(x,1,&bb), bb)
 #define GET_WORD(x)     ( dosmemget(x,2,&sb), sb)
-
 static unsigned char bb;
 static unsigned short sb;
 
+#else /* win32 */
+
+#define SET_BYTE(x,y)   *(volatile unsigned char *)(x) = (y)
+#define SET_WORD(x,y)   *(volatile unsigned short *)(x) = (y)
+#define GET_BYTE(x)     (*(volatile unsigned char *)(x))
+#define GET_WORD(x)     (*(volatile unsigned short *)(x))
+#define dosmemget(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
+#define dosmemput(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
+#endif
 
 static struct sw 
 {
@@ -212,19 +119,51 @@ static struct sw
   {0x17, 0xdc000},
   0};
 
+#ifndef __GO32__
+/* Get the base of the data segment.  This is needed to calculate the offset
+   between data segment addresses and the base of linear memory, which is where
+   device registers reside.  Note that this is really only necessary for
+   Win32s, since Win95 and NT keep the data segment at linear 0.  */
+
+static unsigned long
+get_ds_base (void)
+{
+  unsigned short dsval;
+  LDT_ENTRY ldt;
+  unsigned long dsbase;
+
+  __asm
+    {
+      mov dsval,ds
+    }
+
+  dsbase = 0;
+
+  GetThreadSelectorEntry (GetCurrentThread(), dsval, &ldt);
+
+  dsbase = ldt.HighWord.Bits.BaseHi << 24 | ldt.HighWord.Bits.BaseMid << 16
+            | ldt.BaseLow;
+
+  return dsbase;
+}
+#else /* !__GO32__ */
+#define get_ds_base() 0
+#endif /* __GO32__ */ 
+
 static int
 e7000pc_init ()
 {
-  /* Look around in memory for the board's signature */
-
   int try;
+  unsigned long dsbase;
   
-  DBG(("e7000pc_init()\n"));
-  for (try = 0; sigs[try].sw; try++)
+  dsbase = get_ds_base ();
 
+  /* Look around in memory for the board's signature */
+
+  for (try = 0; sigs[try].sw; try++)
     {
       int val;
-      board_at = sigs[try].addr;
+      board_at = sigs[try].addr - dsbase;
       fa = board_at + OFF_FA;
       fb = board_at + OFF_FB;
       cpd = board_at + OFF_CPD;
@@ -233,32 +172,27 @@ e7000pc_init ()
       pon = board_at + OFF_PON;              
       irqtop = board_at + OFF_IRQTOP;
       irqtod = board_at + OFF_IRQTOD;
-
-      RMT_DBG(("e7000pc_init: looking for board's signature, try=%d\n", try));
-
+      
       val = GET_WORD (ready);
 
       if (val == (0xaaa0  | sigs[try].sw))
        {
-         if (GET_BYTE (pon) & 0xf)
+         if (GET_WORD (pon) & 0xf)
            {
-             SET_BYTE(fa, 0);
-             SET_BYTE (fb, 0);
+             SET_WORD (fa, 0);
+             SET_WORD (fb, 0);
 
-             SET_BYTE (irqtop, 1); /* Disable interrupts from e7000 */
+             SET_WORD (irqtop, 1); /* Disable interrupts from e7000 */
              SET_WORD (ready, 1);
-              DBG(("Yippie!  Connected :-)\n"));
              printf_filtered ("\nConnected to the E7000PC at address 0x%x\n", 
                               sigs[try].addr);
              return 1;       
            }
-          DBG(("Bummer!  e7000pc not on :-(\n"));
          error ("The E7000 PC board is working, but the E7000 is turned off.\n");
          return 0;
        }
     }
 
-  DBG(("Bummer!  Can't connect :-(\n"));
   error ("GDB cannot connect to the E7000 PC board, check that it is installed\n\
 and that the switch settings are correct.  Some other DOS programs can \n\
 stop the board from working.  Try starting from a very minimal boot, \n\
@@ -271,32 +205,29 @@ its I/O space, remove other unneeded cards, etc etc\n");
 static int pbuf_size;
 static int pbuf_index;
 
-static 
-int 
-e7000_get ()
+/* Return next byte from cdp.  If no more, then return -1.  */
+
+static int 
+e7000_get (void)
 {
   static char pbuf[1000];
   char tmp[1000];
   int x;
-  DBG(("e7000_get()\n"));
+
   if (pbuf_index < pbuf_size) 
     {
       x = pbuf[pbuf_index++];
     }
-  else if ((GET_BYTE (fb)  & 1))
+  else if ((GET_WORD (fb) & 1))
     {
       int i;
-      pbuf_size = GET_WORD(cdp + 2);
+      pbuf_size = GET_WORD (cdp + 2);
 
       dosmemget (cdp + 8, pbuf_size + 1, tmp);
 
       /* Tell the E7000 we've eaten */
-      SET_BYTE(fb,0);  
+      SET_WORD (fb, 0);        
       /* Swap it around */
-/* FIXME!  We get in an infinite loop inside e7000_open...
- * This is called from dosasync_readchar
- * called from remote-e7000.c trying to sync up.
- */
       for (i = 0; i < pbuf_size; i++) 
        {
          pbuf[i] = tmp[i^1];
@@ -311,6 +242,9 @@ e7000_get ()
   return x;
 }
 
+/* Works just like read(), except that it takes a TIMEOUT in seconds.  Note
+   that TIMEOUT == 0 is a poll, and TIMEOUT == -1 means wait forever. */
+
 static int
 dosasync_read (fd, buf, len, timeout)
      int fd;
@@ -323,7 +257,6 @@ dosasync_read (fd, buf, len, timeout)
   long then;
   int i = 0;
 
-  DBG(("dosasync_read(fd=x%x,buf,len=x%x,timeout=x%x)\n",fd,len,timeout));
   /* Then look for some more if we're still hungry */
   time (&now);
   then = now + timeout;
@@ -332,7 +265,7 @@ dosasync_read (fd, buf, len, timeout)
       int ch = e7000_get();
       
       /* While there's room in the buffer, and we've already
-       * read the stuff in, suck it over */
+        read the stuff in, suck it over */
       if (ch != -1) 
        {
          buf[i++] = ch;
@@ -347,14 +280,10 @@ dosasync_read (fd, buf, len, timeout)
 
       time (&now);
 
-      if (timeout == 0 || (now >= then && timeout > 0))
+      if (timeout == 0)
+       return i;
+      if (now >= then && timeout > 0)
        {
-/* We timeout here but return i anyway...  
- * were we supposed to send a TIMEOUT ?
- * While syncing, len = 1 and timeout=1..
- * so always take this path and return 1 char. 
- */
-         DBG(("timeout; read x%x chars\n", i));
          return i;
        }
     }
@@ -370,8 +299,6 @@ dosasync_write (fd, buf, len)
 {
   int i;
   char dummy[1000];  
-
-  DBG(("dosasync_write(fd=x%x,buf=x%x,len=x%x)\n",fd,buf,len));
   
   /* Construct copy locally */
   ((short *)dummy)[0] = CMD_CI;
@@ -384,119 +311,33 @@ dosasync_write (fd, buf, len)
     }
 
   /* Wait for the card to get ready */
-  while ((GET_BYTE(fa) & 1) != 0)
-    ;
+  while (GET_WORD (fa) & 1) ;
 
   /* Blast onto the ISA card */
   dosmemput (dummy, 8 + len + 1,  cpd);
 
-  SET_BYTE(fa, 1);
-  SET_BYTE(irqtod, 1); /* Interrupt the E7000 */
+  SET_WORD (fa, 1);
+  SET_WORD (irqtod, 1); /* Interrupt the E7000 */
 
   return len;
 }
 
-
-#ifdef _WIN32
-static int 
-load_wine7kpc(void)
-{
-  char dll[64];
-
-  DBG(("load_wine7kpc()\n"));
-  if (win_host()==winnt)
-    {
-        printf_filtered( "e7000pc not supported on this host.\n" );
-        return 0;
-    }
-  if (win_host()==win32s)
-      strcpy(dll, "w31e7kpc.Dll");
-  else if (win_host()==win95)
-      strcpy(dll, "w95e7kpc.Dll");
-  else return 0;
-
-  /* load dll for windows support of e7000pc */
-  DBG(("LoadLibrary(%s)\n",dll));
-  hWine7kpc = LoadLibrary (dll);
-  if (!hWine7kpc)
-    {
-        DBG(("LoadLibrary(%s) failed\n",dll));
-        printf_filtered( "Error: unable to load %s.\n",dll);
-        return 0;
-    }
-  pwin_load_e7kpc = (PWIN_LOAD_E7KPC) GetProcAddress (hWine7kpc, "win_load_e7kpc");
-  if (!pwin_load_e7kpc)
-    {
-        DBG(("!pwin_load_e7kpc\n"));
-        printf_filtered( "Error: unable to resolve win_load_e7kpc.\n" );
-        return 0;
-    }
-  pwin_unload_e7kpc = (PWIN_UNLOAD_E7KPC) GetProcAddress (hWine7kpc, "win_unload_e7kpc");
-  if (!pwin_unload_e7kpc)
-    {
-        DBG(("!pwin_unload_e7kpc\n"));
-        printf_filtered( "Error: unable to resolve win_unload_e7kpc.\n" );
-        return 0;
-    }
-  pwin_mem_get = (PWIN_MEM_GET) GetProcAddress (hWine7kpc, "win_mem_get");
-  if (!pwin_mem_get)
-    {
-        DBG(("!pwin_mem_get\n"));
-        printf_filtered( "Error: unable to resolve win_mem_get.\n" );
-        return 0;
-    }
-  pwin_mem_put= (PWIN_MEM_PUT) GetProcAddress (hWine7kpc, "win_mem_put");
-  if (!pwin_mem_put)
-    {
-        DBG(("!pwin_mem_put\n"));
-        printf_filtered( "Error: unable to resolve win_mem_put.\n" );
-        return 0;
-    }
-  pwin_remote_debug= (PWIN_REMOTE_DEBUG) GetProcAddress (hWine7kpc, "win_remote_debug");
-  if (!pwin_remote_debug)
-    {
-        DBG(("!pwin_remote_debug\n"));
-        printf_filtered( "Error: unable to resolve win_remote_debug.\n" );
-        return 0;
-    }
-  DBG(("load_wine7kpc Done! :-)\n"));
-  return 1;
-}
-#endif /* _WIN32 */
-
 static int
 e7000pc_open (scb, name)
      serial_t scb;
      const char *name;
 {
-  DBG(("e7000pc_open\n"));
   if (strncasecmp (name, "pc", 2) != 0)
     {
       errno = ENOENT;
       return -1;
     }
-#ifdef _WIN32
-  if (!load_wine7kpc()) /* load windows dll for e7kpc support */
-    {
-        DBG(("Error! load_wine7kpc failed\n"));
-        printf_filtered("Failed to initialize dll for e7000pc support.\n" );
-        return -1;
-    }
-  if (win_load_e7kpc () != 0)
-    {
-      errno = ENOENT;
-      return -1;
-    }
-#endif /* _WIN32 */
+
   scb->fd = e7000pc_init ();
 
   if (!scb->fd)
-  {
-    DBG(("Error! !scb->fd\n"));
     return -1;
-  }
 
-  DBG(("e7000pc_open done! :-)\n"));
   return 0;
 }
 
@@ -521,12 +362,8 @@ e7000pc_readchar (scb, timeout)
 {
   char buf;
 
- DBG(("e7000pc_readchar\n"));
  top:
 
-  /* FIXME!  How does dosasync_read ever return 0?
-   * it always goes thru the loop once, so i>0
-   */
   if (dosasync_read (scb->fd, &buf, 1, timeout))
     {
       if (buf == 0) goto top;
@@ -548,7 +385,6 @@ e7000pc_get_tty_state (scb)
      serial_t scb;
 {
   struct e7000pc_ttystate *state;
-  DBG(("e7000pc_get_tty_state\n"));
 
   state = (struct e7000pc_ttystate *) xmalloc (sizeof *state);
 
@@ -595,7 +431,6 @@ e7000pc_write (scb, str, len)
      const char *str;
      int len;
 {
-  DBG(("e7000pc_write(scb,str=%s,len=x%x)\n",str,len));
   dosasync_write (scb->fd, str, len);
 
   return 0;
@@ -605,10 +440,6 @@ static void
 e7000pc_close (scb)
      serial_t scb;
 {
-  DBG(("e7000pc_close\n"));
-#ifdef _WIN32
-  win_unload_e7kpc ();
-#endif
 }
 
 static struct serial_ops e7000pc_ops =
@@ -642,4 +473,4 @@ _initialize_ser_e7000pc ()
 {
 
 }
-#endif /* defined(__GO32__) || defined(_WIN32) */
+#endif
index cefd742..e9e682e 100644 (file)
@@ -23,10 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "gdb_string.h"
 #include "gdbcmd.h"
 
-/*#define DEBUGIFY*/
-#include "debugify.h"
-
-
 /* Linked list of serial I/O handlers */
 
 static struct serial_ops *serial_ops_list = NULL;
@@ -46,7 +42,7 @@ static char *serial_logfile = NULL;
 static FILE *serial_logfp = NULL;
 
 static struct serial_ops *serial_interface_lookup PARAMS ((char *));
-static void serial_logchar PARAMS ((int ch, int timeout));
+static void serial_logchar PARAMS ((int chtype, int ch, int timeout));
 static char logbase_hex[] = "hex";
 static char logbase_octal[] = "octal";
 static char logbase_ascii[] = "ascii";
@@ -54,37 +50,26 @@ static char *logbase_enums[] = {logbase_hex, logbase_octal, logbase_ascii, NULL}
 static char *serial_logbase = logbase_ascii;
 
 \f
-static int serial_reading = 0;
-static int serial_writing = 0;
-
-void
-serial_log_command (cmd)
-     const char *cmd;
-{
-  if (!serial_logfp)
-    return;
+static int serial_current_type = 0;
 
-  if (serial_reading || serial_writing)
-    {
-      fputc_unfiltered ('\n', serial_logfp);
-      serial_reading = 0;
-      serial_writing = 0;
-    }
-  fprintf_unfiltered (serial_logfp, "c %s\n", cmd);
-  /* Make sure that the log file is as up-to-date as possible,
-     in case we are getting ready to dump core or something. */
-  fflush (serial_logfp);
-}
+/* Log char CH of type CHTYPE, with TIMEOUT */
 
 /* Define bogus char to represent a BREAK.  Should be careful to choose a value
    that can't be confused with a normal char, or an error code.  */
 #define SERIAL_BREAK 1235
 
 static void
-serial_logchar (ch, timeout)
+serial_logchar (chtype, ch, timeout)
+     int chtype;
      int ch;
      int timeout;
 {
+  if (chtype != serial_current_type)
+    {
+      fprintf_unfiltered (serial_logfp, "\n%c ", chtype);
+      serial_current_type = chtype;
+    }
+
   if (serial_logbase != logbase_ascii)
     fputc_unfiltered (' ', serial_logfp);
 
@@ -119,7 +104,24 @@ serial_logchar (ch, timeout)
          case '\v':    fputs_unfiltered ("\\v", serial_logfp); break;  
          default:      fprintf_unfiltered (serial_logfp, isprint (ch) ? "%c" : "\\x%02x", ch & 0xFF); break;
          }
-       }
+    }
+}
+
+void
+serial_log_command (cmd)
+     const char *cmd;
+{
+  if (!serial_logfp)
+    return;
+
+  serial_current_type = 'c';
+
+  fputs_unfiltered (serial_logfp, "\nc ");
+  fputs_unfiltered (serial_logfp, cmd);
+
+  /* Make sure that the log file is as up-to-date as possible,
+     in case we are getting ready to dump core or something. */
+  gdb_flush (serial_logfp);
 }
 
 int
@@ -128,28 +130,18 @@ serial_write (scb, str, len)
      const char *str;
      int len;
 {
-  int count;
-
   if (serial_logfp != NULL)
     {
-      if (serial_reading)
-       {
-         fputc_unfiltered ('\n', serial_logfp);
-         serial_reading = 0;
-       }
-      if (!serial_writing)
-       {
-         fputs_unfiltered ("w ", serial_logfp);
-         serial_writing = 1;
-       }
+      int count;
+
       for (count = 0; count < len; count++)
-       {
-         serial_logchar (str[count] & 0xff, 0);
-       }
+       serial_logchar ('w', str[count] & 0xff, 0);
+
       /* Make sure that the log file is as up-to-date as possible,
         in case we are getting ready to dump core or something. */
-      fflush (serial_logfp);
+      gdb_flush (serial_logfp);
     }
+
   return (scb -> ops -> write (scb, str, len));
 }
 
@@ -163,21 +155,13 @@ serial_readchar (scb, timeout)
   ch = scb -> ops -> readchar (scb, timeout);
   if (serial_logfp != NULL)
     {
-      if (serial_writing)
-       {
-         fputc_unfiltered ('\n', serial_logfp);
-         serial_writing = 0;
-       }
-      if (!serial_reading)
-       {
-         fputs_unfiltered ("r ", serial_logfp);
-         serial_reading = 1;
-       }
-      serial_logchar (ch, timeout);
+      serial_logchar ('r', ch, timeout);
+
       /* Make sure that the log file is as up-to-date as possible,
         in case we are getting ready to dump core or something. */
-      fflush (serial_logfp);
+      gdb_flush (serial_logfp);
     }
+
   return (ch);
 }
 
@@ -186,22 +170,8 @@ serial_send_break (scb)
      serial_t scb;
 {
   if (serial_logfp != NULL)
-    {
-      if (serial_reading)
-       {
-         fputc_unfiltered ('\n', serial_logfp);
-         serial_reading = 0;
-       }
-      if (!serial_writing)
-       {
-         fputs_unfiltered ("w ", serial_logfp);
-         serial_writing = 1;
-       }
-      serial_logchar (SERIAL_BREAK, 0);
-      /* Make sure that the log file is as up-to-date as possible,
-        in case we are getting ready to dump core or something. */
-      fflush (serial_logfp);
-    }
+    serial_logchar ('w', SERIAL_BREAK, 0);
+
   return (scb -> ops -> send_break (scb));
 }
 
@@ -210,13 +180,11 @@ serial_interface_lookup (name)
      char *name;
 {
   struct serial_ops *ops;
-  DBG(("serial_interface_lookup(%s)\n",name));
 
   for (ops = serial_ops_list; ops; ops = ops->next)
     if (strcmp (name, ops->name) == 0)
       return ops;
 
-  DBG(("serial_interface_lookup: %s not found!\n",name));
   return NULL;
 }
 
@@ -237,12 +205,10 @@ serial_open (name)
   serial_t scb;
   struct serial_ops *ops;
 
-  DBG(("serial_open\n"));
   for (scb = scb_base; scb; scb = scb->next)
     if (scb->name && strcmp (scb->name, name) == 0)
       {
        scb->refcnt++;
-        DBG(("serial_open: scb %s found\n", name));
        return scb;
       }
 
@@ -256,10 +222,7 @@ serial_open (name)
     ops = serial_interface_lookup ("hardwire");
 
   if (!ops)
-  {
-    DBG(("serial_open: !ops; returning NULL\n"));
     return NULL;
-  }
 
   scb = (serial_t)xmalloc (sizeof (struct _serial_t));
 
@@ -271,7 +234,6 @@ serial_open (name)
   if (scb->ops->open(scb, name))
     {
       free (scb);
-      DBG(("serial_open: scb->ops->open failed!\n"));
       return NULL;
     }
 
@@ -284,15 +246,11 @@ serial_open (name)
 
   if (serial_logfile != NULL)
     {
-      serial_logfp = fopen (serial_logfile, "w");
+      serial_logfp = gdb_fopen (serial_logfile, "w");
       if (serial_logfp == NULL)
-       {
-          DBG(("serial_open: unable to open serial logfile %s!\n",serial_logfile));
-         perror_with_name (serial_logfile);
-       }
+       perror_with_name (serial_logfile);
     }
 
-  DBG(("serial_open: Done! :-)\n"));
   return scb;
 }
 
@@ -302,7 +260,6 @@ serial_fdopen (fd)
 {
   serial_t scb;
   struct serial_ops *ops;
-  DBG(("serial_fdopen\n"));
 
   for (scb = scb_base; scb; scb = scb->next)
     if (scb->fd == fd)
@@ -336,7 +293,7 @@ serial_fdopen (fd)
 }
 
 void
-serial_close(scb, really_close)
+serial_close (scb, really_close)
      serial_t scb;
      int really_close;
 {
@@ -346,13 +303,10 @@ serial_close(scb, really_close)
 
   if (serial_logfp)
     {
-      if (serial_reading || serial_writing)
-       {
-         fputc_unfiltered ('\n', serial_logfp);
-         serial_reading = 0;
-         serial_writing = 0;
-       }
-      fclose (serial_logfp);
+      fputs_unfiltered ("\nEnd of log\n", serial_logfp);
+      serial_current_type = 0;
+
+      fclose (serial_logfp);   /* XXX - What if serial_logfp == stdout or stderr? */
       serial_logfp = NULL;
     }
 
@@ -428,7 +382,6 @@ connect_command (args, fromtty)
   char cur_esc = 0;
   serial_ttystate ttystate;
   serial_t port_desc;          /* TTY port */
-  DBG(("connect_command\n"));
 
   dont_repeat();
 
@@ -546,8 +499,6 @@ serial_printf (va_alist)
 void
 _initialize_serial ()
 {
-  struct cmd_list_element *cmd;
-
 #if 0
   add_com ("connect", class_obscure, connect_command,
           "Connect the terminal directly up to the command monitor.\n\
index b4ca50d..2942c7c 100644 (file)
@@ -26,164 +26,164 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "srec.h"
 #include "symtab.h"
 #include "symfile.h" /* for generic_load */
+#include <time.h>
 
-#if 0  /* Do we really need all this Unix stuff here? */
-#if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY)
-#define HAVE_SGTTY
-#endif
+static struct target_ops sparclet_ops;
 
-#ifdef HAVE_SGTTY
-#include <sys/ioctl.h>
-#endif
+static void sparclet_open PARAMS ((char *args, int from_tty));
 
-#include <sys/types.h> /* Needed by file.h on Sys V */
-#include <sys/file.h>
-#include <signal.h>
-#include <sys/stat.h>
-#endif /* Unix stuff */
+/* This array of registers need to match the indexes used by GDB.
+   This exists because the various ROM monitors use different strings
+   than does GDB, and don't necessarily support all the registers
+   either. So, typing "info reg sp" becomes a "r30".  */
 
-#define USE_GENERIC_LOAD
-#define USE_SW_BREAKS
+/*PSR 0x00000080  impl ver icc AW LE EE EC EF PIL S PS ET CWP  WIM
+                0x0  0x0 0x0  0  0  0  0  0 0x0 1  0  0 0x00 0x2
+                                                             0000010
+       INS        LOCALS       OUTS      GLOBALS
+ 0  0x00000000  0x00000000  0x00000000  0x00000000
+ 1  0x00000000  0x00000000  0x00000000  0x00000000
+ 2  0x00000000  0x00000000  0x00000000  0x00000000
+ 3  0x00000000  0x00000000  0x00000000  0x00000000
+ 4  0x00000000  0x00000000  0x00000000  0x00000000
+ 5  0x00000000  0x00001000  0x00000000  0x00000000
+ 6  0x00000000  0x00000000  0x123f0000  0x00000000
+ 7  0x00000000  0x00000000  0x00000000  0x00000000
+pc:  0x12010000 0x00000000    unimp
+npc: 0x12010004 0x00001000    unimp     0x1000
+tbr: 0x00000000
+y:   0x00000000
+*/
+/* these correspond to the offsets from tm-* files from config directories */
 
-static struct target_ops sparclet_ops;
+/* is wim part of psr?? */
+/* monitor wants lower case */
+static char *sparclet_regnames[NUM_REGS] = REGISTER_NAMES;
 
-static void sparclet_open PARAMS ((char *args, int from_tty));
 
-#ifdef USE_GENERIC_LOAD
+/* Function: sparclet_supply_register
+   Just returns with no action.
+   This function is required, because parse_register_dump (monitor.c)
+   expects to be able to call it.  If we don't supply something, it will
+   call a null pointer and core-dump.  Since this function does not 
+   actually do anything, GDB will request the registers individually.  */
 
 static void
-sparclet_load_gen (filename, from_tty) 
-    char *filename;
-    int from_tty;
+sparclet_supply_register (regname, regnamelen, val, vallen)
+     char *regname;
+     int regnamelen;
+     char *val;
+     int vallen;
 {
-  extern int inferior_pid;
-
-  generic_load (filename, from_tty);
-  /* Finally, make the PC point at the start address */
-  if (exec_bfd)
-    write_pc (bfd_get_start_address (exec_bfd));
-
-  inferior_pid = 0;             /* No process now */
+  return;
 }
 
-#endif
-
-#ifdef USE_XMODEM_LOAD
-
 static void
-sparclet_xmodem_load (desc, file, hashmark)
+sparclet_load (desc, file, hashmark)
      serial_t desc;
      char *file;
      int hashmark;
 {
   bfd *abfd;
   asection *s;
-  char *buffer;
   int i;
+  CORE_ADDR load_offset;
+  time_t start_time, end_time;
+  unsigned long data_count = 0;
+
+  /* enable user to specify address for downloading as 2nd arg to load */
+
+  i = sscanf(file, "%*s 0x%lx", &load_offset);
+  if (i >= 1 ) 
+    {
+      char *p;
+
+      for (p = file; *p != '\000' && !isspace (*p); p++);
+
+      *p = '\000';
+    }
+  else
+    load_offset = 0;
 
-  buffer = alloca (XMODEM_PACKETSIZE);
   abfd = bfd_openr (file, 0);
   if (!abfd)
     {
       printf_filtered ("Unable to open file %s\n", file);
       return;
     }
+
   if (bfd_check_format (abfd, bfd_object) == 0)
     {
       printf_filtered ("File is not an object file\n");
       return;
     }
+  
+  start_time = time (NULL);
+
   for (s = abfd->sections; s; s = s->next)
     if (s->flags & SEC_LOAD)
       {
        bfd_size_type section_size;
-       printf_filtered ("%s\t: 0x%4x .. 0x%4x  ", s->name, s->vma,
-                        s->vma + s->_raw_size);
-       gdb_flush (gdb_stdout);
-       monitor_printf (current_monitor->load, s->vma);
-       if (current_monitor->loadresp)
-         monitor_expect (current_monitor->loadresp, NULL, 0);
-       xmodem_init_xfer (desc);
+       bfd_vma vma;
+
+       vma = bfd_get_section_vma (abfd, s) + load_offset;
        section_size = bfd_section_size (abfd, s);
-       for (i = 0; i < section_size; i += XMODEM_DATASIZE)
+
+       data_count += section_size;
+
+       printf_filtered ("%s\t: 0x%4x .. 0x%4x  ",
+                        bfd_get_section_name (abfd, s), vma,
+                        vma + section_size);
+       gdb_flush (gdb_stdout);
+
+       monitor_printf ("load c r %x %x\r", vma, section_size);
+
+       monitor_expect ("load: loading ", NULL, 0);
+       monitor_expect ("\r", NULL, 0);
+
+       for (i = 0; i < section_size; i += 2048)
          {
            int numbytes;
-           numbytes = min (XMODEM_DATASIZE, section_size - i);
-           bfd_get_section_contents (abfd, s, buffer + XMODEM_DATAOFFSET, i,
-                                     numbytes);
-           xmodem_send_packet (desc, buffer, numbytes, hashmark);
+           char buf[2048];
+
+           numbytes = min (sizeof buf, section_size - i);
+
+           bfd_get_section_contents (abfd, s, buf, i, numbytes);
+
+           SERIAL_WRITE (desc, buf, numbytes);
+
            if (hashmark)
              {
                putchar_unfiltered ('#');
                gdb_flush (gdb_stdout);
              }
          }                     /* Per-packet (or S-record) loop */
-       xmodem_finish_xfer (desc);
+
        monitor_expect_prompt (NULL, 0);
+
        putchar_unfiltered ('\n');
       }                                /* Loadable sections */
-  if (hashmark) 
-    putchar_unfiltered ('\n');
-}
 
-static void
-sparclet_load (desc, file, hashmark)
-     serial_t desc;
-     char *file;
-     int hashmark;
-{
-???
-}
-#endif /* USE_XMODEM_LOAD */
+  monitor_printf ("reg pc %x\r", bfd_get_start_address (abfd));
+  monitor_expect_prompt (NULL, 0);
+  monitor_printf ("reg npc %x\r", bfd_get_start_address (abfd) + 4);
+  monitor_expect_prompt (NULL, 0);
 
-/* This array of registers need to match the indexes used by GDB.
-   This exists because the various ROM monitors use different strings
-   than does GDB, and don't necessarily support all the registers
-   either. So, typing "info reg sp" becomes a "r30".  */
+  monitor_printf ("run\r");
 
-/*PSR 0x00000080  impl ver icc AW LE EE EC EF PIL S PS ET CWP  WIM
-                0x0  0x0 0x0  0  0  0  0  0 0x0 1  0  0 0x00 0x2
-                                                             0000010
-       INS        LOCALS       OUTS      GLOBALS
- 0  0x00000000  0x00000000  0x00000000  0x00000000
- 1  0x00000000  0x00000000  0x00000000  0x00000000
- 2  0x00000000  0x00000000  0x00000000  0x00000000
- 3  0x00000000  0x00000000  0x00000000  0x00000000
- 4  0x00000000  0x00000000  0x00000000  0x00000000
- 5  0x00000000  0x00001000  0x00000000  0x00000000
- 6  0x00000000  0x00000000  0x123f0000  0x00000000
- 7  0x00000000  0x00000000  0x00000000  0x00000000
-pc:  0x12010000 0x00000000    unimp
-npc: 0x12010004 0x00001000    unimp     0x1000
-tbr: 0x00000000
-y:   0x00000000
-*/
-/* these correspond to the offsets from tm-* files from config directories */
+  end_time = time (NULL);
 
-/* is wim part of psr?? */
-/* monitor wants lower case */
-static char *sparclet_regnames[NUM_REGS] = REGISTER_NAMES;
+  if (hashmark) 
+    putchar_unfiltered ('\n');
 
+  report_transfer_performance (data_count, start_time, end_time);
 
-/* Function: sparclet_supply_register
-   Just returns with no action.
-   This function is required, because parse_register_dump (monitor.c)
-   expects to be able to call it.  If we don't supply something, it will
-   call a null pointer and core-dump.  Since this function does not 
-   actually do anything, GDB will request the registers individually.  */
+  pop_target ();
+  push_remote_target (monitor_get_dev_name (), 1);
 
-static void
-sparclet_supply_register (regname, regnamelen, val, vallen)
-     char *regname;
-     int regnamelen;
-     char *val;
-     int vallen;
-{
-  return;
+  return_to_top_level (RETURN_QUIT);
 }
 
-
-
 /* Define the monitor command strings. Since these are passed directly
    through to a printf style function, we may include formatting
    strings. We also need a CR or LF on the end.  */
@@ -248,16 +248,9 @@ static struct monitor_ops sparclet_cmds =
   "reg\r",                     /* dump_registers */
   "\\(\\w+\\)=\\([0-9a-fA-F]+\\)",     /* register_pattern */
   sparclet_supply_register,    /* supply_register */
-#ifdef USE_GENERIC_LOAD
-  NULL,                                /* load_routine (defaults to SRECs) */
-  NULL,                                /* download command */
+  sparclet_load,               /* load_routine */
+  NULL,                                /* download command (srecs on console) */
   NULL,                                /* load response */
-#else
-  NULL,                                /* load_routine (defaults to SRECs) */
-  /* load [c|a] [s | f | r [addr count]] */
-  "load c s\r",                        /* download command (srecs on console) */
-  "load: ",                    /* load response */
-#endif
   "monitor>",                  /* monitor command prompt */
   /* yikes!  gdb core dumps without this delimitor!! */
   "\r",                                /* end-of-command delimitor */
@@ -291,14 +284,9 @@ _initialize_sparclet ()
   init_monitor_ops (&sparclet_ops);
   sparclet_ops.to_shortname = "sparclet"; /* for the target command */
   sparclet_ops.to_longname = "SPARC Sparclet monitor";
-#ifdef USE_GENERIC_LOAD
-  sparclet_ops.to_load = sparclet_load_gen; /* FIXME - should go back and try "do" */
-#endif
-#ifdef USE_SW_BREAKS
   /* use SW breaks; target only supports 2 HW breakpoints */
   sparclet_ops.to_insert_breakpoint = memory_insert_breakpoint; 
   sparclet_ops.to_remove_breakpoint = memory_remove_breakpoint; 
-#endif
 
   sparclet_ops.to_doc = 
     "Use a board running the Sparclet debug monitor.\n\
index de2069a..736b966 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -67,8 +67,6 @@ static void init_signals PARAMS ((void));
 static void stop_sig PARAMS ((int));
 #endif
 
-static void disconnect PARAMS ((int));
-
 static char * line_completion_function PARAMS ((char *, int, char *, int));
 
 static char * readline_line_completion_function PARAMS ((char *, int));
@@ -155,9 +153,11 @@ static void complete_command PARAMS ((char *, int));
 
 static void do_nothing PARAMS ((int));
 
+#ifdef SIGHUP
 static int quit_cover PARAMS ((char *));
 
 static void disconnect PARAMS ((int));
+#endif
 
 static void source_cleanup PARAMS ((FILE *));
 
@@ -571,6 +571,7 @@ catch_errors (func, args, errstring, mask)
 
 /* Handler for SIGHUP.  */
 
+#ifdef SIGHUP
 static void
 disconnect (signo)
 int signo;
@@ -592,6 +593,7 @@ char *s;
   quit_command((char *)0, 0);
   return 0;
 }
+#endif /* defined SIGHUP */
 \f
 /* Line number we are currently in in a file which is being sourced.  */
 static int source_line_number;
@@ -1929,8 +1931,10 @@ init_signals ()
      a handler for SIGQUIT, when we call exec it will set the signal
      to SIG_DFL for us.  */
   signal (SIGQUIT, do_nothing);
+#ifdef SIGHUP
   if (signal (SIGHUP, do_nothing) != SIG_IGN)
     signal (SIGHUP, disconnect);
+#endif
   signal (SIGFPE, float_handler);
 
 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
index abb7d11..52cc863 100644 (file)
@@ -72,7 +72,8 @@ set_width_command PARAMS ((char *, int, struct cmd_list_element *));
 /* Chain of cleanup actions established with make_cleanup,
    to be executed if an error happens.  */
 
-static struct cleanup *cleanup_chain;
+static struct cleanup *cleanup_chain; /* cleaned up after a failed command */
+static struct cleanup *final_cleanup_chain; /* cleaned up when gdb exits */
 
 /* Nonzero if we have job control. */
 
@@ -134,14 +135,30 @@ make_cleanup (function, arg)
      void (*function) PARAMS ((PTR));
      PTR arg;
 {
+    return make_my_cleanup (&cleanup_chain, function, arg);
+}
+
+struct cleanup *
+make_final_cleanup (function, arg)
+     void (*function) PARAMS ((PTR));
+     PTR arg;
+{
+    return make_my_cleanup (&final_cleanup_chain, function, arg);
+}
+struct cleanup *
+make_my_cleanup (pmy_chain, function, arg)
+     struct cleanup **pmy_chain;
+     void (*function) PARAMS ((PTR));
+     PTR arg;
+{
   register struct cleanup *new
     = (struct cleanup *) xmalloc (sizeof (struct cleanup));
-  register struct cleanup *old_chain = cleanup_chain;
+  register struct cleanup *old_chain = *pmy_chain;
 
-  new->next = cleanup_chain;
+  new->next = *pmy_chain;
   new->function = function;
   new->arg = arg;
-  cleanup_chain = new;
+  *pmy_chain = new;
 
   return old_chain;
 }
@@ -153,10 +170,25 @@ void
 do_cleanups (old_chain)
      register struct cleanup *old_chain;
 {
+    do_my_cleanups (&cleanup_chain, old_chain);
+}
+
+void
+do_final_cleanups (old_chain)
+     register struct cleanup *old_chain;
+{
+    do_my_cleanups (&final_cleanup_chain, old_chain);
+}
+
+void
+do_my_cleanups (pmy_chain, old_chain)
+     register struct cleanup **pmy_chain;
+     register struct cleanup *old_chain;
+{
   register struct cleanup *ptr;
-  while ((ptr = cleanup_chain) != old_chain)
+  while ((ptr = *pmy_chain) != old_chain)
     {
-      cleanup_chain = ptr->next;       /* Do this first incase recursion */
+      *pmy_chain = ptr->next;  /* Do this first incase recursion */
       (*ptr->function) (ptr->arg);
       free (ptr);
     }
@@ -169,10 +201,25 @@ void
 discard_cleanups (old_chain)
      register struct cleanup *old_chain;
 {
+    discard_my_cleanups (&cleanup_chain, old_chain);
+}
+
+void
+discard_final_cleanups (old_chain)
+     register struct cleanup *old_chain;
+{
+    discard_my_cleanups (&final_cleanup_chain, old_chain);
+}
+
+void
+discard_my_cleanups (pmy_chain, old_chain)
+     register struct cleanup **pmy_chain;
+     register struct cleanup *old_chain;
+{
   register struct cleanup *ptr;
-  while ((ptr = cleanup_chain) != old_chain)
+  while ((ptr = *pmy_chain) != old_chain)
     {
-      cleanup_chain = ptr->next;
+      *pmy_chain = ptr->next;
       free ((PTR)ptr);
     }
 }
@@ -181,9 +228,22 @@ discard_cleanups (old_chain)
 struct cleanup *
 save_cleanups ()
 {
-  struct cleanup *old_chain = cleanup_chain;
+    return save_my_cleanups (&cleanup_chain);
+}
+
+struct cleanup *
+save_final_cleanups ()
+{
+    return save_my_cleanups (&final_cleanup_chain);
+}
+
+struct cleanup *
+save_my_cleanups (pmy_chain)
+    struct cleanup **pmy_chain;
+{
+  struct cleanup *old_chain = *pmy_chain;
 
-  cleanup_chain = 0;
+  *pmy_chain = 0;
   return old_chain;
 }
 
@@ -192,7 +252,22 @@ void
 restore_cleanups (chain)
      struct cleanup *chain;
 {
-  cleanup_chain = chain;
+    restore_my_cleanups (&cleanup_chain, chain);
+}
+
+void
+restore_final_cleanups (chain)
+     struct cleanup *chain;
+{
+    restore_my_cleanups (&final_cleanup_chain, chain);
+}
+
+void
+restore_my_cleanups (pmy_chain, chain)
+     struct cleanup **pmy_chain;
+     struct cleanup *chain;
+{
+  *pmy_chain = chain;
 }
 
 /* This function is useful for cleanups.
@@ -253,7 +328,7 @@ warning_begin ()
 /* VARARGS */
 void
 #ifdef ANSI_PROTOTYPES
-warning (char *string, ...)
+warning (const char *string, ...)
 #else
 warning (va_alist)
      va_dcl
@@ -300,7 +375,7 @@ error_begin ()
 
 #ifdef ANSI_PROTOTYPES
 NORETURN void
-error (char *string, ...)
+error (const char *string, ...)
 #else
 void
 error (va_alist)
@@ -394,10 +469,8 @@ fatal_dump_core (va_alist)
   fprintf_unfiltered (gdb_stderr, "\n");
   va_end (args);
 
-#ifndef _WIN32
   signal (SIGQUIT, SIG_DFL);
   kill (getpid (), SIGQUIT);
-#endif
   /* We should never get here, but just in case...  */
   exit (1);
 }
@@ -533,8 +606,9 @@ quit ()
 }
 
 
-#if defined(__GO32__) || defined(_WIN32)
+#if defined(__GO32__) || defined (_WIN32)
 
+#ifndef _MSC_VER
 /* In the absence of signals, poll keyboard for a quit.
    Called from #define QUIT pollquit() in xm-go32.h. */
 
@@ -543,7 +617,6 @@ pollquit()
 {
   if (kbhit ())
     {
-#ifndef _WIN32
       int k = getkey ();
       if (k == 1) {
        quit_flag = 1;
@@ -556,22 +629,42 @@ pollquit()
       else 
        {
          /* We just ignore it */
+         /* FIXME!! Don't think this actually works! */
          fprintf_unfiltered (gdb_stderr, "CTRL-A to quit, CTRL-B to quit harder\n");
        }
-#else
-      abort ();
-#endif
     }
 }
+#else /* !_MSC_VER */
+
+/* This above code is not valid for wingdb unless
+ * getkey and kbhit were to be rewritten.
+ * Windows translates all keyboard and mouse events 
+ * into a message which is appended to the message 
+ * queue for the process.
+ */
+void
+pollquit()
+{
+  int k = win32pollquit();
+  if (k == 1)
+  {
+    quit_flag = 1;
+    quit ();
+  }
+  else if (k == 2)
+  {
+    immediate_quit = 1;
+    quit ();
+  }
+}
+#endif /* !_MSC_VER */
 
 
-#endif
-#if defined(__GO32__) || defined(_WIN32)
+#ifndef _MSC_VER
 void notice_quit()
 {
   if (kbhit ())
     {
-#ifndef _WIN32
       int k = getkey ();
       if (k == 1) {
        quit_flag = 1;
@@ -584,17 +677,27 @@ void notice_quit()
        {
          fprintf_unfiltered (gdb_stderr, "CTRL-A to quit, CTRL-B to quit harder\n");
        }
-#else
-      abort ();
-#endif
     }
 }
+#else /* !_MSC_VER */
+
+void notice_quit()
+{
+  int k = win32pollquit();
+  if (k == 1)
+    quit_flag = 1;
+  else if (k == 2)
+    immediate_quit = 1;
+}
+#endif /* !_MSC_VER */
+
 #else
 void notice_quit()
 {
   /* Done by signals */
 }
-#endif
+#endif /* defined(__GO32__) || defined(_WIN32) */
+
 /* Control C comes here */
 
 void
@@ -1327,7 +1430,9 @@ void
 gdb_flush (stream)
      FILE *stream;
 {
-  if (flush_hook)
+  if (flush_hook
+      && (stream == gdb_stdout
+         || stream == gdb_stderr))
     {
       flush_hook (stream);
       return;
@@ -1884,7 +1989,7 @@ initialize_utils ()
   lines_per_page = 24;
   chars_per_line = 80;
 
-#if !defined MPW && !defined _WIN32
+#if !defined (MPW) && !defined (_WIN32)
   /* No termcap under MPW, although might be cool to do something
      by looking at worksheet or console window sizes. */
   /* Initialize the screen height and width from termcap.  */
@@ -2287,18 +2392,20 @@ floatformat_from_doublest (fmt, from, to)
 }
 
 /* temporary storage using circular buffer */
-#define MAXCELLS 16
+#define NUMCELLS 16
 #define CELLSIZE 32
-char* 
+static char*
 get_cell()
 {
-  static char buf[MAXCELLS][CELLSIZE];
+  static char buf[NUMCELLS][CELLSIZE];
   static int cell=0;
-  if (++cell>MAXCELLS) cell=0;
+  if (++cell>=NUMCELLS) cell=0;
   return buf[cell];
 }
 
 /* print routines to handle variable size regs, etc */
+static int thirty_two = 32;    /* eliminate warning from compiler on 32-bit systems */
+
 char* 
 paddr(addr)
   t_addr addr;
@@ -2308,7 +2415,7 @@ paddr(addr)
     {
       case 8:
         sprintf(paddr_str,"%08x%08x",
-               (unsigned long)(addr>>32),(unsigned long)(addr&0xffffffff));
+               (unsigned long)(addr>>thirty_two),(unsigned long)(addr&0xffffffff));
        break;
       case 4:
         sprintf(paddr_str,"%08x",(unsigned long)addr);
@@ -2331,7 +2438,7 @@ preg(reg)
     {
       case 8:
         sprintf(preg_str,"%08x%08x",
-               (unsigned long)(reg>>32),(unsigned long)(reg&0xffffffff));
+               (unsigned long)(reg>>thirty_two),(unsigned long)(reg&0xffffffff));
        break;
       case 4:
         sprintf(preg_str,"%08x",(unsigned long)reg);
@@ -2345,3 +2452,60 @@ preg(reg)
   return preg_str;
 }
 
+char*
+paddr_nz(addr)
+  t_addr addr;
+{
+  char *paddr_str=get_cell();
+  switch (sizeof(t_addr))
+    {
+      case 8:
+       {
+         unsigned long high = (unsigned long)(addr>>thirty_two);
+         if (high == 0)
+           sprintf(paddr_str,"%x", (unsigned long)(addr&0xffffffff));
+         else
+           sprintf(paddr_str,"%x%08x",
+                   high, (unsigned long)(addr&0xffffffff));
+         break;
+       }
+      case 4:
+        sprintf(paddr_str,"%x",(unsigned long)addr);
+       break;
+      case 2:
+        sprintf(paddr_str,"%x",(unsigned short)(addr&0xffff));
+       break;
+      default:
+        sprintf(paddr_str,"%x",addr);
+    }
+  return paddr_str;
+}
+
+char*
+preg_nz(reg)
+  t_reg reg;
+{
+  char *preg_str=get_cell();
+  switch (sizeof(t_reg))
+    {
+      case 8:
+       {
+         unsigned long high = (unsigned long)(reg>>thirty_two);
+         if (high == 0)
+           sprintf(preg_str,"%x", (unsigned long)(reg&0xffffffff));
+         else
+           sprintf(preg_str,"%x%08x",
+                   high, (unsigned long)(reg&0xffffffff));
+         break;
+       }
+      case 4:
+        sprintf(preg_str,"%x",(unsigned long)reg);
+       break;
+      case 2:
+        sprintf(preg_str,"%x",(unsigned short)(reg&0xffff));
+       break;
+      default:
+        sprintf(preg_str,"%x",reg);
+    }
+  return preg_str;
+}