diff -urN gdb-4.16-orig/bfd/configure.in gdb-4.16/bfd/configure.in
--- gdb-4.16-orig/bfd/configure.in	Mon Apr 22 21:30:05 1996
+++ gdb-4.16/bfd/configure.in	Tue Oct 27 16:46:27 1998
@@ -141,56 +141,56 @@
   hppa*-*-bsd*)		COREFILE="hpux-core.o hppabsd-core.o"
 			COREFLAG="-DHPUX_CORE -DHPPABSD_CORE" ;;
 changequote(,)dnl
-  i[345]86-sequent-bsd*)
+  i[3456]86-sequent-bsd*)
 changequote([,])dnl
 	COREFILE=trad-core.o;
 	AC_DEFINE(TRAD_HEADER,"hosts/symmetry.h")
 	;;
 changequote(,)dnl
-  i[345]86-sequent-sysv4*) ;;
-  i[345]86-sequent-sysv*)
+  i[3456]86-sequent-sysv4*) ;;
+  i[3456]86-sequent-sysv*)
 changequote([,])dnl
 	COREFILE=trad-core.o
 	AC_DEFINE(TRAD_HEADER,"hosts/symmetry.h")
 	;;
 changequote(,)dnl
-  i[345]86-*-bsd* | i[345]86-*-freebsd*)
+  i[3456]86-*-bsd* | i[3456]86-*-freebsd*)
 changequote([,])dnl
 	COREFILE=trad-core.o
 	AC_DEFINE(TRAD_HEADER,"hosts/i386bsd.h")
 	;;
 changequote(,)dnl
-  i[345]86-*-netbsd*)
+  i[3456]86-*-netbsd*)
 changequote([,])dnl
 	COREFILE=netbsd-core.o
 	;;
 changequote(,)dnl
-  i[345]86-esix-sysv3*)
+  i[3456]86-esix-sysv3*)
 changequote([,])dnl
 	COREFILE=trad-core.o
 	AC_DEFINE(TRAD_HEADER,"hosts/esix.h")
 	;;
 changequote(,)dnl
-  i[345]86-*-sco* | i[345]86-*-isc*)
+  i[3456]86-*-sco* | i[3456]86-*-isc*)
 changequote([,])dnl
 	COREFILE=trad-core.o
 	AC_DEFINE(TRAD_HEADER,"hosts/i386sco.h")
 	;;
 changequote(,)dnl
-  i[345]86-*-mach3*)
+  i[3456]86-*-mach3*)
 changequote([,])dnl
 	COREFILE=trad-core.o
 	AC_DEFINE(TRAD_HEADER,"hosts/i386mach3.h")
 	;;
 changequote(,)dnl
-  i[345]86-*-linux*)
+  i[3456]86-*-linux*)
 changequote([,])dnl
 	COREFILE=trad-core.o
 	AC_DEFINE(TRAD_HEADER,"hosts/i386linux.h")
 	;;
 changequote(,)dnl
-  i[345]86-*-isc*)	COREFILE=trad-core.o ;;
-  i[345]86-*-aix*)	COREFILE=aix386-core.o ;;
+  i[3456]86-*-isc*)	COREFILE=trad-core.o ;;
+  i[3456]86-*-aix*)	COREFILE=aix386-core.o ;;
 changequote([,])dnl
   i860-*-mach3* | i860-*-osf1*)
 	COREFILE=trad-core.o
diff -urN gdb-4.16-orig/configure.in gdb-4.16/configure.in
--- gdb-4.16-orig/configure.in	Mon Apr 22 21:52:25 1996
+++ gdb-4.16/configure.in	Tue Oct 27 16:46:27 1998
@@ -108,15 +108,15 @@
   mips*-sgi-irix3*)       host_makefile_frag=config/mh-sysv ;;
   mips*-*-sysv4*)	  host_makefile_frag=config/mh-sysv4 ;;
   mips*-*-sysv*)	  host_makefile_frag=config/mh-riscos ;;
-  i[345]86-ncr-sysv4.3)   host_makefile_frag=config/mh-ncrsvr43 ;;
-  i[345]86-ncr-sysv4*)    host_makefile_frag=config/mh-ncr3000 ;;
-  i[345]86-*-sco3.2v5*)   host_makefile_frag=config/mh-sysv ;;
-  i[345]86-*-sco*)        host_makefile_frag=config/mh-sco ;;
-  i[345]86-*-isc*)	  host_makefile_frag=config/mh-sysv ;;
-  i[345]86-*-linux*)      host_makefile_frag=config/mh-linux ;;
-  i[345]86-*-solaris2*)   host_makefile_frag=config/mh-sysv4 ;;
-  i[345]86-*-aix*)	  host_makefile_frag=config/mh-aix386 ;;
-  i[345]86-*-go32*)	  host_makefile_frag=config/mh-go32 ;;
+  i[3456]86-ncr-sysv4.3)   host_makefile_frag=config/mh-ncrsvr43 ;;
+  i[3456]86-ncr-sysv4*)    host_makefile_frag=config/mh-ncr3000 ;;
+  i[3456]86-*-sco3.2v5*)   host_makefile_frag=config/mh-sysv ;;
+  i[3456]86-*-sco*)        host_makefile_frag=config/mh-sco ;;
+  i[3456]86-*-isc*)	  host_makefile_frag=config/mh-sysv ;;
+  i[3456]86-*-linux*)      host_makefile_frag=config/mh-linux ;;
+  i[3456]86-*-solaris2*)   host_makefile_frag=config/mh-sysv4 ;;
+  i[3456]86-*-aix*)	  host_makefile_frag=config/mh-aix386 ;;
+  i[3456]86-*-go32*)	  host_makefile_frag=config/mh-go32 ;;
   vax-*-ultrix2*)         host_makefile_frag=config/mh-vaxult2 ;;
   *-*-solaris2*)          host_makefile_frag=config/mh-solaris ;;
   m68k-sun-sunos*)	  host_makefile_frag=config/mh-sun3 ;;
diff -urN gdb-4.16-orig/gdb/ChangeLog gdb-4.16/gdb/ChangeLog
--- gdb-4.16-orig/gdb/ChangeLog	Mon Apr 22 21:34:43 1996
+++ gdb-4.16/gdb/ChangeLog	Tue Oct 27 16:46:27 1998
@@ -1,3 +1,25 @@
+Sun Apr 27 20:42:12 1997  Kenneth Albanowski  <kjahds@kjahds.com>
+	* config/m68k/tm-m68kpalmos.h: ints are 16 bits, registers 32
+	* remote-palmos.c: write_memory now works
+
+Fri Mar 28 16:32:13 1997  Kenneth Albanowski  <kjahds@kjahds.com>
+
+	* remote-palmos.c config/m68k/m68kpalmos.mt: Removed
+	dependency on pilot-link library.
+	* ser-unix.c: added support for baud rates above 38400
+
+Sun Mar 23 17:14:35 1997  Kenneth Albanowski  <kjahds@kjahds.com>
+
+	* *palmos*: Renamed to *m68kpalmos*
+	* remote-palmos.c: New file.
+
+Wed Mar  5 21:41:51 1997  Kresten Krab Thorup  <krab@california.daimi.aau.dk>
+
+	* config/m68k/palmos.mt, config/m68k/tm-palmos.h: New files.
+
+	* m68k-tdep.c (m68k_saved_pc_after_call): Added support for
+	MAC_SYSCALL_TRAP style systraps.
+
 Mon Apr 22 20:17:01 1996  Fred Fish  <fnf@cygnus.com>
 
 	* Makefile.in (VERSION): Bump version number to 4.16
diff -urN gdb-4.16-orig/gdb/Makefile.in gdb-4.16/gdb/Makefile.in
--- gdb-4.16-orig/gdb/Makefile.in	Mon Apr 22 21:43:08 1996
+++ gdb-4.16/gdb/Makefile.in	Tue Oct 27 16:46:27 1998
@@ -873,7 +873,7 @@
 	procfs.c pyr-tdep.c pyr-xdep.c \
 	remote-adapt.c remote-array.c remote-bug.c remote-e7000.c remote-eb.c \
 	remote-es.c remote-hms.c remote-mips.c \
-	remote-mm.c remote-nindy.c remote-os9k.c remote-rdp.c remote-sim.c \
+	remote-mm.c remote-nindy.c remote-os9k.c remote-palmos.c remote-rdp.c remote-sim.c \
 	remote-st.c remote-utils.c dcache.c \
 	remote-udi.c remote-vx.c remote-vx29k.c \
 	rs6000-nat.c rs6000-tdep.c \
@@ -1337,6 +1337,10 @@
 	symfile.h
 
 remote-os9k.o: remote-os9k.c $(defs_h) $(gdbcore_h) $(wait_h) \
+	$(command_h) monitor.h $(remote_utils_h) $(symtab_h) symfile.h \
+	objfiles.h gdb-stabs.h gdb_string.h
+
+remote-palmos.o: remote-palmos.c $(defs_h) $(gdbcore_h) $(wait_h) \
 	$(command_h) monitor.h $(remote_utils_h) $(symtab_h) symfile.h \
 	objfiles.h gdb-stabs.h gdb_string.h
 
diff -urN gdb-4.16-orig/gdb/config/m68k/m68kpalmos.mt gdb-4.16/gdb/config/m68k/m68kpalmos.mt
--- gdb-4.16-orig/gdb/config/m68k/m68kpalmos.mt	Wed Dec 31 16:00:00 1969
+++ gdb-4.16/gdb/config/m68k/m68kpalmos.mt	Tue Oct 27 16:46:27 1998
@@ -0,0 +1,6 @@
+# Target: Motorola 680x0 running PalmOS
+TDEPFILES= coff-solib.o m68k-tdep.o
+
+TM_FILE= tm-m68kpalmos.h
+
+REMOTE_OBS = dcache.o remote-palmos.o remote.o
diff -urN gdb-4.16-orig/gdb/config/m68k/tm-m68kpalmos.h gdb-4.16/gdb/config/m68k/tm-m68kpalmos.h
--- gdb-4.16-orig/gdb/config/m68k/tm-m68kpalmos.h	Wed Dec 31 16:00:00 1969
+++ gdb-4.16/gdb/config/m68k/tm-m68kpalmos.h	Tue Oct 27 16:46:27 1998
@@ -0,0 +1,56 @@
+/* Target machine definitions for m68k PalmOS.
+   Copyright (C) 1986, 1987, 1989, 1993, 1995 Free Software Foundation, Inc.
+
+This file is part of GDB.
+
+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
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+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.  */
+
+/* The definitions here are appropriate for several embedded m68k-based
+   targets, including IDP (rom68k), BCC (cpu32bug), and EST's emulator.  */
+
+/* GCC is probably the only compiler used on this configuration.  So
+   get this right even if the code which detects gcc2_compiled. is
+   still broken.  */
+
+#define BELIEVE_PCC_PROMOTION 1
+
+/* The target system handles breakpoints.  */
+
+#define DECR_PC_AFTER_BREAK 2
+
+/* No float registers.  */
+
+/*#define NUM_REGS 18*/
+
+#include "m68k/tm-m68k.h"
+
+#define TARGET_INT_BIT 16
+#define TARGET_PTR_BIT 32
+
+#undef REGISTER_VIRTUAL_TYPE
+#define REGISTER_VIRTUAL_TYPE(N)                                \
+ (((unsigned)(N) - FP0_REGNUM) < 8 ? builtin_type_double :      \
+ (N) == PC_REGNUM || (N) == FP_REGNUM || (N) == SP_REGNUM ?     \
+ lookup_pointer_type (builtin_type_void) : builtin_type_long)
+
+/* FIXME, should do GET_LONGJMP_TARGET for newlib.  */
+
+#ifdef __GNUC__
+#define MAC_SYSCALL_TRAP \
+   ({ static long addr = 0; \
+      addr != 0 ? addr : (addr = read_memory_integer ((32+15)*4, 4)); })
+#else
+#define MAC_SYSCALL_TRAP read_memory_integer ((32+15)*4, 4)
+#endif
diff -urN gdb-4.16-orig/gdb/configure gdb-4.16/gdb/configure
--- gdb-4.16-orig/gdb/configure	Mon Apr 22 21:34:51 1996
+++ gdb-4.16/gdb/configure	Tue Oct 27 16:46:27 1998
@@ -2069,6 +2069,7 @@
 m68*-monitor-*)         gdb_target=monitor ;;
 m68*-est-*)		gdb_target=monitor ;;
 m68*-*-aout*)		gdb_target=monitor ;;
+m68*-palmos-coff*)              gdb_target=m68kpalmos ;;
 m68*-*-coff*)		gdb_target=monitor ;;
 m68*-*-elf*)		gdb_target=monitor ;;
 m68*-*-lynxos*)		gdb_target=m68klynx
diff -urN gdb-4.16-orig/gdb/configure.in gdb-4.16/gdb/configure.in
--- gdb-4.16-orig/gdb/configure.in	Mon Apr 22 21:34:51 1996
+++ gdb-4.16/gdb/configure.in	Tue Oct 27 16:46:27 1998
@@ -385,6 +385,7 @@
 m68*-bull-sysv*)	gdb_target=dpx2 ;;
 m68*-hp-bsd*)		gdb_target=hp300bsd ;;
 m68*-hp-hpux*)		gdb_target=hp300hpux ;;
+m68*-palmos-coff*)		gdb_target=m68kpalmos ;;
 m68*-altos-*)		gdb_target=altos ;;
 m68*-att-*)		gdb_target=3b1 ;;
 m68*-cisco*-*)		gdb_target=cisco ;;
diff -urN gdb-4.16-orig/gdb/gdbserver/configure.in gdb-4.16/gdb/gdbserver/configure.in
--- gdb-4.16-orig/gdb/gdbserver/configure.in	Mon Apr 24 18:07:43 1995
+++ gdb-4.16/gdb/gdbserver/configure.in	Tue Oct 27 16:46:27 1998
@@ -20,7 +20,7 @@
 
 c[12])			gdb_host_cpu=convex ;;
 hppa*)			gdb_host_cpu=pa ;;
-i[345]86)		gdb_host_cpu=i386 ;;
+i[3456]86)		gdb_host_cpu=i386 ;;
 m68*)			gdb_host_cpu=m68k ;;
 np1)			gdb_host_cpu=gould ;;
 pyramid)		gdb_host_cpu=pyr ;;
@@ -41,23 +41,23 @@
 hppa*-hp-bsd*)		gdb_host=hppabsd ;;
 hppa*-hp-hpux*)		gdb_host=hppahpux ;;
 
-i[345]86-ncr-*)		gdb_host=ncr3000 ;;
-i[345]86-sequent-*)	gdb_host=symmetry ;;
+i[3456]86-ncr-*)		gdb_host=ncr3000 ;;
+i[3456]86-sequent-*)	gdb_host=symmetry ;;
 
-i[345]86-*-bsd*)	gdb_host=i386bsd ;;
-i[345]86-*-lynxos*)	gdb_host=i386lynx ;;
-i[345]86-*-go32)	gdb_host=go32
+i[3456]86-*-bsd*)	gdb_host=i386bsd ;;
+i[3456]86-*-lynxos*)	gdb_host=i386lynx ;;
+i[3456]86-*-go32)	gdb_host=go32
 			gdb_serial_driver=ser-go32.c
 			;;
-i[345]86-*-linux*)	gdb_host=linux ;;
-i[345]86-*-mach)	gdb_host=i386mach ;;
-i[345]86-*-sco3.2v4*)	gdb_host=i386sco4 ;;
-i[345]86-*-sco*)	gdb_host=i386sco ;;
-i[345]86-*-solaris*)	gdb_host=i386sol2 ;;
-i[345]86-*-sunos*)	gdb_host=sun386 ;;
-i[345]86-*-sysv3.2)	gdb_host=i386v32 ;;
-i[345]86-*-sysv4*)	gdb_host=i386v4 ;;
-i[345]86-*-sysv*)	gdb_host=i386v ;;
+i[3456]86-*-linux*)	gdb_host=linux ;;
+i[3456]86-*-mach)	gdb_host=i386mach ;;
+i[3456]86-*-sco3.2v4*)	gdb_host=i386sco4 ;;
+i[3456]86-*-sco*)	gdb_host=i386sco ;;
+i[3456]86-*-solaris*)	gdb_host=i386sol2 ;;
+i[3456]86-*-sunos*)	gdb_host=sun386 ;;
+i[3456]86-*-sysv3.2)	gdb_host=i386v32 ;;
+i[3456]86-*-sysv4*)	gdb_host=i386v4 ;;
+i[3456]86-*-sysv*)	gdb_host=i386v ;;
 
 m680[01]0-sun-sunos3*)	gdb_host=sun2os3 ;;
 m680[01]0-sun-sunos4*)	gdb_host=sun2os4 ;;
@@ -131,7 +131,7 @@
 
 c[12])			gdb_target_cpu=convex ;;
 hppa*)			gdb_target_cpu=pa ;;
-i[345]86)		gdb_target_cpu=i386 ;;
+i[3456]86)		gdb_target_cpu=i386 ;;
 m68*)			gdb_target_cpu=m68k ;;
 np1)			gdb_target_cpu=gould ;;
 pn)			gdb_target_cpu=gould ;;
@@ -167,22 +167,22 @@
 hppa*-*-bsd*)		gdb_target=hppabsd ;;
 hppa*-*-hpux*)		gdb_target=hppahpux ;;
 
-i[345]86-sequent-*)	gdb_target=symmetry ;;
-i[345]86-ncr-*)		gdb_target=ncr3000 ;;
+i[3456]86-sequent-*)	gdb_target=symmetry ;;
+i[3456]86-ncr-*)		gdb_target=ncr3000 ;;
 
-i[345]86-*-aout)	gdb_target=i386aout ;;
-i[345]86-*-coff)	gdb_target=i386v ;;
-i[345]86-*-elf)		gdb_target=i386v ;;
-
-i[345]86-*-bsd*)	gdb_target=i386bsd ;;
-i[345]86-*-lynxos*)	gdb_target=i386lynx ;;
-i[345]86-*-go32)	gdb_target=i386aout ;;
-i[345]86-*-solaris*)	gdb_target=i386sol2 ;;
-i[345]86-*-sunos*)	gdb_target=sun386 ;;
-i[345]86-*-sysv4*)	gdb_target=i386v4 ;;
-i[345]86-*-sco*)	gdb_target=i386v ;;
-i[345]86-*-sysv*)	gdb_target=i386v ;;
-i[345]86-*-linux*)	gdb_target=linux ;;
+i[3456]86-*-aout)	gdb_target=i386aout ;;
+i[3456]86-*-coff)	gdb_target=i386v ;;
+i[3456]86-*-elf)		gdb_target=i386v ;;
+
+i[3456]86-*-bsd*)	gdb_target=i386bsd ;;
+i[3456]86-*-lynxos*)	gdb_target=i386lynx ;;
+i[3456]86-*-go32)	gdb_target=i386aout ;;
+i[3456]86-*-solaris*)	gdb_target=i386sol2 ;;
+i[3456]86-*-sunos*)	gdb_target=sun386 ;;
+i[3456]86-*-sysv4*)	gdb_target=i386v4 ;;
+i[3456]86-*-sco*)	gdb_target=i386v ;;
+i[3456]86-*-sysv*)	gdb_target=i386v ;;
+i[3456]86-*-linux*)	gdb_target=linux ;;
 
 i960-*-bout)		gdb_target=vxworks960 ;;
 i960-*-coff)		gdb_target=nindy960 ;;
diff -urN gdb-4.16-orig/gdb/m68k-tdep.c gdb-4.16/gdb/m68k-tdep.c
--- gdb-4.16-orig/gdb/m68k-tdep.c	Tue Aug  1 20:19:07 1995
+++ gdb-4.16/gdb/m68k-tdep.c	Tue Oct 27 16:46:27 1998
@@ -504,6 +504,11 @@
     return read_memory_integer (read_register (SP_REGNUM) + 4, 4);
   else
 #endif /* SYSCALL_TRAP */
+#ifdef MAC_SYSCALL_TRAP
+  if (frame->pc == MAC_SYSCALL_TRAP)
+    return read_memory_integer (read_register (SP_REGNUM) + 2, 4) + 2;
+  else
+#endif /* MAC_SYSCALL_TRAP */
     return read_memory_integer (read_register (SP_REGNUM), 4);
 }
 
diff -urN gdb-4.16-orig/gdb/remote-palmos.c gdb-4.16/gdb/remote-palmos.c
--- gdb-4.16-orig/gdb/remote-palmos.c	Wed Dec 31 16:00:00 1969
+++ gdb-4.16/gdb/remote-palmos.c	Tue Oct 27 16:46:27 1998
@@ -0,0 +1,1159 @@
+/* Remote target communications for serial-line targets in custom GDB protocol
+   Copyright 1988, 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
+   
+   Written by Kenneth Albanowski <kjahds@kjahds.com>, derived (with
+   assistance from Palm Computing, Inc.) from work by
+   
+     Kenneth Albanowski,
+     Donald Jeff Dionne <jeff@RyeHam.ee.ryerson.ca>,
+     Kresten Krab Thorup <krab@daimi.aau.dk>,
+     and whoever wrote remote.c and xmodem.c.
+
+This file is part of GDB.
+
+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
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+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.  */
+
+#include "defs.h"
+#include "gdb_string.h"
+#include <fcntl.h>
+#include "frame.h"
+#include "inferior.h"
+#include "bfd.h"
+#include "symfile.h"
+#include "target.h"
+#include "wait.h"
+/*#include "terminal.h"*/
+#include "gdbcmd.h"
+#include "objfiles.h"
+#include "gdb-stabs.h"
+#include "thread.h"
+
+#include "dcache.h"
+
+#ifdef USG
+#include <sys/types.h>
+#endif
+
+#include <signal.h>
+#include "serial.h"
+#include "xmodem.h"
+
+/* Prototypes for local functions */
+
+static int remote_write_bytes PARAMS ((CORE_ADDR memaddr,
+				       char *myaddr, int len));
+
+static int remote_read_bytes PARAMS ((CORE_ADDR memaddr,
+				      char *myaddr, int len));
+
+static void remote_files_info PARAMS ((struct target_ops *ignore));
+
+static int remote_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
+				       int len, int should_write,
+				       struct target_ops *target));
+
+static void remote_prepare_to_store PARAMS ((void));
+
+static void remote_fetch_registers PARAMS ((int regno));
+
+static void remote_resume PARAMS ((int pid, int step,
+				   enum target_signal siggnal));
+
+static int remote_start_remote PARAMS ((char *dummy));
+
+static void remote_open PARAMS ((char *name, int from_tty));
+
+static void extended_remote_open PARAMS ((char *name, int from_tty));
+
+static void remote_open_1 PARAMS ((char *, int, struct target_ops *));
+
+static void remote_close PARAMS ((int quitting));
+
+static void remote_store_registers PARAMS ((int regno));
+
+static void remote_mourn PARAMS ((void));
+
+static void extended_remote_restart PARAMS ((void));
+
+static void extended_remote_mourn PARAMS ((void));
+
+static void extended_remote_create_inferior PARAMS ((char *, char *, char **));
+
+static void remote_mourn_1 PARAMS ((struct target_ops *));
+
+static int getpkt PARAMS ((char **buf, int forever));
+
+static int putpkt PARAMS ((char *buf, int len));
+
+static void remote_send PARAMS ((char *buf));
+
+static int readchar PARAMS ((int timeout));
+
+static int remote_wait PARAMS ((int pid, struct target_waitstatus *status));
+
+static void remote_kill PARAMS ((void));
+
+static int tohex PARAMS ((int nib));
+
+static int fromhex PARAMS ((int a));
+
+static void remote_detach PARAMS ((char *args, int from_tty));
+
+static void remote_interrupt PARAMS ((int signo));
+
+static void remote_interrupt_twice PARAMS ((int signo));
+
+static void interrupt_query PARAMS ((void));
+
+static void remote_insert_wbreakpoint PARAMS ((CORE_ADDR addr));
+
+static void remote_remove_wbreakpoint PARAMS ((void));
+
+extern struct target_ops palmos_ops;	/* Forward decl */
+
+/* This was 5 seconds, which is a long time to sit and wait.
+   Unless this is going though some terminal server or multiplexer or
+   other form of hairy serial connection, I would think 2 seconds would
+   be plenty.  */
+
+static int remote_timeout = 2;
+
+static CORE_ADDR text_addr=0, data_addr=0, bss_addr=0;
+/*static struct Pilot_state state;*/
+
+#define MAX_BREAKS 5
+
+static struct {
+	unsigned long address;
+	int on;
+} breakpoint[MAX_BREAKS + 1];
+
+static char regs[REGISTER_BYTES];
+
+/* Portable memory access macros */
+
+#define get_long(ptr) ((((unsigned char*)(ptr))[0] << 24) | \
+                       (((unsigned char*)(ptr))[1] << 16) | \
+                       (((unsigned char*)(ptr))[2] << 8)  | \
+                       (((unsigned char*)(ptr))[3] << 0))
+
+#define get_treble(ptr) ((((unsigned char*)(ptr))[0] << 16) | \
+                         (((unsigned char*)(ptr))[1] << 8)  | \
+                         (((unsigned char*)(ptr))[2] << 0))
+
+#define get_short(ptr) ((((unsigned char*)(ptr))[0] << 8)  | \
+                        (((unsigned char*)(ptr))[1] << 0))
+
+#define get_byte(ptr) (((unsigned char*)(ptr))[0])
+
+#define set_long(ptr,val) ((((unsigned char*)(ptr))[0] = ((val) >> 24) & 0xff), \
+                          (((unsigned char*)(ptr))[1] = ((val) >> 16) & 0xff), \
+                          (((unsigned char*)(ptr))[2] = ((val) >> 8) & 0xff), \
+                          (((unsigned char*)(ptr))[3] = ((val) >> 0) & 0xff))
+
+#define set_treble(ptr,val) ((((unsigned char*)(ptr))[0] = ((val) >> 16) & 0xff), \
+                             (((unsigned char*)(ptr))[1] = ((val) >> 8) & 0xff), \
+                             (((unsigned char*)(ptr))[2] = ((val) >> 0) & 0xff))
+
+#define set_short(ptr,val) ((((unsigned char*)(ptr))[0] = ((val) >> 8) & 0xff), \
+                            (((unsigned char*)(ptr))[1] = ((val) >> 0) & 0xff))
+
+#define set_byte(ptr,val) (((unsigned char*)(ptr))[0]=(val))
+
+/* Following CRC code borrowed from xmodem.c */
+
+#define CRC16 0x1021		/* Generator polynomial (X^16 + X^12 + X^5 + 1) */
+
+static unsigned short *crctab;
+
+/* Call this to init the fast CRC-16 calculation table.  */
+
+static void
+crcinit ()
+{
+  static int crctab_inited = 0;
+  int val;
+
+  if (crctab_inited == 1)
+    return;
+
+  crctab = xmalloc (256 * sizeof (short));
+
+  for (val = 0; val <= 255; val++)
+    {
+      int i;
+      unsigned int crc;
+
+      crc = val << 8;
+
+      for (i = 0; i < 8; ++i)
+	{
+	  crc <<= 1;
+
+	  if (crc & 0x10000)
+	    crc ^= CRC16;
+	}
+
+      crctab [val] = crc;
+    }
+
+  crctab_inited = 1;
+}
+
+/* Calculate a CRC-16 for the LEN byte message pointed at by P.  */
+
+static unsigned short
+docrc (p, len)
+     unsigned char *p;
+     int len;
+{
+  unsigned short crc = 0;
+
+  while (len-- > 0)
+    crc = (crc << 8) ^ crctab [(crc >> 8) ^ *p++];
+
+  return crc;
+}
+
+  
+static void
+get_offsets ()
+{
+  struct section_offsets *offs;
+  
+  if (symfile_objfile == NULL)
+    return;
+    
+  if ((text_addr == 0) && (data_addr==0) && (bss_addr==0))
+    return;
+
+  offs = (struct section_offsets *) alloca (sizeof (struct section_offsets)
+					    + symfile_objfile->num_sections
+					    * sizeof (offs->offsets));
+  memcpy (offs, symfile_objfile->section_offsets,
+	  sizeof (struct section_offsets)
+	  + symfile_objfile->num_sections
+	  * sizeof (offs->offsets));
+
+  ANOFFSET (offs, SECT_OFF_TEXT) = text_addr;
+
+  /* This is a temporary kludge to force data and bss to use the same offsets
+     because that's what nlmconv does now.  The real solution requires changes
+     to the stub and remote.c that I don't have time to do right now.  */
+
+  ANOFFSET (offs, SECT_OFF_DATA) = data_addr;
+  ANOFFSET (offs, SECT_OFF_BSS) = data_addr;
+
+  objfile_relocate (symfile_objfile, offs);
+}
+
+/* Stub for catch_errors.  */
+
+static int
+remote_start_remote (dummy)
+     char *dummy;
+{
+     struct target_waitstatus status;
+  immediate_quit = 1;		/* Allow user to interrupt it */
+  
+  /*remote_wait(0,&status); /* Wait for remote to halt, hopefully fetching
+                             offsets in the process */
+
+  /*get_offsets ();		/* Get text, data & bss offsets */
+
+  immediate_quit = 0;
+
+  start_remote ();		/* Initialize gdb process mechanisms */
+  return 1;
+}
+
+/* Open a connection to a remote debugger.
+   NAME is the filename used for communication.  */
+
+static void
+remote_open (name, from_tty)
+     char *name;
+     int from_tty;
+{
+  remote_open_1 (name, from_tty, &palmos_ops);
+}
+
+/* Generic code for opening a connection to a remote target.  */
+static DCACHE *remote_dcache;
+
+static serial_t remote_desc = NULL;
+static int startup = 1;
+
+static void
+remote_open_1 (name, from_tty, target)
+     char *name;
+     int from_tty;
+     struct target_ops *target;
+{
+  if (name == 0)
+    error ("To open a remote debug connection, you need to specify what serial\n\
+device is attached to the remote system (e.g. /dev/ttya).");
+
+  target_preopen (from_tty);
+
+  unpush_target (target);
+
+  remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
+
+  remote_desc = SERIAL_OPEN(name);
+  if (!remote_desc)
+    perror_with_name(name);
+    
+  if (baud_rate == -1)
+    baud_rate = 57600;
+
+  if (baud_rate != -1)
+    {
+    if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
+       {
+       SERIAL_CLOSE (remote_desc);
+       perror_with_name (name);
+      }
+  }
+  
+  SERIAL_RAW (remote_desc);
+  
+  crcinit();
+  
+  if (from_tty)
+    {
+      puts_filtered ("Remote debugging under PalmOS using ");
+      puts_filtered (name);
+      puts_filtered ("\n");
+      startup = 1;
+    }
+  push_target (target);	/* Switch to using remote target now */
+
+  inferior_pid = 42000;
+  /* Start the remote connection; if error (0), discard this target.
+     In particular, if the user quits, be sure to discard it
+     (we'd be in an inconsistent state otherwise).  */
+  if (!catch_errors (remote_start_remote, (char *)0, 
+		     "Couldn't establish connection to remote target\n", RETURN_MASK_ALL))
+    pop_target();
+}
+
+/* Clean up connection to a remote debugger.  */
+
+/* ARGSUSED */
+static void
+remote_close (quitting)
+     int quitting;
+{
+  if (remote_desc)
+    SERIAL_CLOSE(remote_desc);
+  remote_desc = NULL;
+}
+
+/* This takes a program previously attached to and detaches it.  After
+   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
+   die when it hits one.  */
+
+static void
+remote_detach (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  pop_target ();
+
+  if (from_tty)
+    puts_filtered ("Ending remote debugging.\n");
+}
+
+static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
+int last_sent_step;
+
+static void
+remote_resume (pid, step, siggnal)
+     int pid, step;
+     enum target_signal siggnal;
+{
+   unsigned long sr;
+   unsigned short ins;
+   char buffer[90];
+   
+   buffer[0] = 0x07;
+   buffer[1] = 0;
+   memcpy(buffer+2, regs+REGISTER_BYTE(0), 60);    /* D0-D7, A0-A6 */
+   sr = get_long(regs+REGISTER_BYTE(16));
+   
+   if (step) {
+     remote_read_bytes (get_long(regs+REGISTER_BYTE(17)),
+				 (void *)&ins,
+				 2);
+
+     if (get_short(&ins) == 0x4e4f) {
+       remote_insert_wbreakpoint(get_long(regs+REGISTER_BYTE(17)) + 4);
+       sr &= 0x7FFF;
+     } else {
+       sr |= 0x8000;
+     }
+   } else {
+     sr &= 0x7FFF;
+   }
+
+   if (sr & 0x2000)
+     memcpy(buffer+66, regs+REGISTER_BYTE(15), 4); /* Store SSP */
+   else
+     memcpy(buffer+62, regs+REGISTER_BYTE(15), 4); /* Store USP */
+   memcpy(buffer+70, regs+REGISTER_BYTE(17), 4);   /* Store PC */
+   set_short(buffer+74, sr);   /* Store SR */
+   
+   memset(buffer+76, 0, 14); /* Zero out watch parameters */
+   
+   dcache_flush (remote_dcache);
+              
+   last_sent_signal = siggnal;
+   last_sent_step = step;
+   
+   putpkt(buffer, 90);
+}
+
+static void (*ofunc)();
+
+static void
+remote_interrupt (signo)
+     int signo;
+{
+  char buffer[10];
+  signal (signo, remote_interrupt_twice);
+  
+  fputs_filtered ("Sending query. (Press Ctrl-C again to give up)\n", gdb_stdout);
+  
+  buffer[0] = 0;
+  buffer[1] = 0;
+  putpkt(buffer, 2);
+}
+
+static void
+remote_interrupt_twice (signo)
+     int signo;
+{
+  signal (signo, ofunc);
+  
+  interrupt_query ();
+
+  signal (signo, remote_interrupt);
+}
+
+/* Ask the user what to do when an interrupt is received.  */
+
+static void
+interrupt_query ()
+{
+  target_terminal_ours ();
+
+  if (query ("Interrupted while waiting for the program.\n\
+Give up (and stop debugging it)? "))
+    {
+      target_mourn_inferior ();
+      return_to_top_level (RETURN_QUIT);
+    }
+
+  target_terminal_inferior ();
+}
+
+static long computeSignal( long exceptionVector )
+{
+  long sigval;
+
+  switch (exceptionVector) {
+    case 2 : sigval = 10; break; /* bus error           */
+    case 3 : sigval = 10; break; /* address error       */
+    case 4 : sigval = 4;  break; /* illegal instruction */
+    case 5 : sigval = 8;  break; /* zero divide         */
+    case 6 : sigval = 8; break; /* chk instruction     */
+    case 7 : sigval = 8; break; /* trapv instruction   */
+    case 8 : sigval = 11; break; /* privilege violation */
+    case 9 : sigval = 5;  break; /* trace trap          */
+    case 10: sigval = 4;  break; /* line 1010 emulator  */
+    case 11: sigval = 4;  break; /* line 1111 emulator  */
+
+      /* Coprocessor protocol violation.  Using a standard MMU or FPU
+	 this cannot be triggered by software.  Call it a SIGBUS.  */
+    case 13: sigval = 10;  break;
+
+    case 31: sigval = 2;  break; /* interrupt           */
+    case 32: sigval = 5;  break; /* breakpoint          */
+
+      /* This is a trap #8 instruction.  Apparently it is someone's software
+	 convention for some sort of SIGFPE condition.  Whose?  How many
+	 people are being screwed by having this code the way it is?
+	 Is there a clean solution?  */
+    case 40: sigval = 8;  break; /* floating point err  */
+
+    case 48: sigval = 8;  break; /* floating point err  */
+    case 49: sigval = 8;  break; /* floating point err  */
+    case 50: sigval = 8;  break; /* zero divide         */
+    case 51: sigval = 8;  break; /* underflow           */
+    case 52: sigval = 8;  break; /* operand error       */
+    case 53: sigval = 8;  break; /* overflow            */
+    case 54: sigval = 8;  break; /* NAN                 */
+    default: 
+      sigval = 7;         /* "software generated"*/
+  }
+  return (sigval);
+}
+
+/* If nonzero, ignore the next kill.  */
+int kill_kludge;
+
+/* Read a single character from the remote end. */
+
+static int
+readchar (timeout)
+     int timeout;
+     {
+       int ch;
+       
+       ch = SERIAL_READCHAR (remote_desc, timeout);
+         
+       switch (ch)
+         {
+         case SERIAL_EOF:
+          error ("Remote connection closed");
+         case SERIAL_ERROR:
+         perror_with_name ("Remote communication error");
+       case SERIAL_TIMEOUT:
+       return ch;
+     default:
+        return ch;
+      }
+}
+
+/* Wait until the remote machine stops, then return,
+   storing status in STATUS just as `wait' would.
+   Returns "pid" (though it's not clear what, if anything, that
+   means in the case of this target).  */
+
+static int
+remote_wait (pid, status)
+     int pid;
+     struct target_waitstatus *status;
+{
+  char * buf;
+  int len;
+  int thread_num = -1;
+  unsigned long ins;
+  
+  if (startup) {
+    fputs_filtered ("Waiting... (Press Ctrl-C to connect to halted machine)\n", gdb_stdout);
+    startup = 0;
+  }
+  	
+  status->kind = TARGET_WAITKIND_EXITED;
+    status->value.integer = 0;
+	    
+	while (1) {
+	   ofunc = (void (*)()) signal (SIGINT, remote_interrupt);
+  	   len = getpkt(&buf, 1);
+  	   signal (SIGINT, ofunc);
+  	   
+  	   if (len<10) /* Reception failed, skip */
+  	     continue;
+  	   
+  	   if ((buf[3] != 0) || (buf[4] != 0) || (buf[5] != 0))
+  	     /* Not a debugging packet, skip */
+  	     continue;
+  	   
+	  if (buf[10] == (char)0x7F) { /* Message */
+	      int i;
+	      for (i=12;i<len;i++) {
+	        if (buf[i] == '\r')
+	          buf[i] = '\n';
+	      }
+	      buf[len] = 0;
+              if (target_output_hook)
+	       target_output_hook (buf+12);
+	      else
+	        fputs_filtered (buf+12, gdb_stdout);
+	      continue;
+	  }
+	  else if (buf[10] == (char)0x80) { /* Break & state */
+	    unsigned long sr;
+	    int i;
+
+#define State_exception 14
+#define State_D0 16
+#define State_D1 20
+#define State_D2 24
+#define State_D3 28
+#define State_A0 48
+#define State_USP 76
+#define State_SSP 80
+#define State_PC 84
+#define State_SR 88
+#define State_INS State_SR+30
+#define Breakpoint_0 State_SR+2+30
+
+	    
+	    status->kind = TARGET_WAITKIND_STOPPED;
+	    status->value.sig = computeSignal(get_short(buf+State_exception)/4);
+	    
+	    memcpy(regs+REGISTER_BYTE(0), buf+State_D0, 60); /* D0-D7, A0-A6 */
+	    
+	    sr = get_short(buf+State_SR);
+	    if (sr & 0x2000) /* Check supervisor bit */
+	      memcpy(regs+REGISTER_BYTE(15), buf+State_SSP, 4); /* SSP */
+	    else
+	      memcpy(regs+REGISTER_BYTE(15), buf+State_USP, 4); /* USP */
+	    
+	    set_long(regs+REGISTER_BYTE(16), sr); /* SR */
+	    memcpy(regs+REGISTER_BYTE(17), buf+State_PC, 4); /* PC */
+	    
+	    for (i=0;i<6;i++) {
+	      breakpoint[i].address = get_long(buf+Breakpoint_0+i*6);
+	      breakpoint[i].on = get_byte(buf+Breakpoint_0+4+i*6);
+	    }
+
+	    if (get_long(buf+State_PC) == breakpoint[MAX_BREAKS].address) {
+	      remote_remove_wbreakpoint();
+	    }
+	    
+	    if ((get_short(buf+State_exception) == 40 *4) &&
+		(get_long(buf+State_D3) == 0x12BEEF34)) {
+
+#if 0
+  	      puts_filtered ("Got target position.\n");
+#endif
+	      text_addr = get_long(buf+State_D0);
+	      bss_addr =  get_long(buf+State_D1);
+	      data_addr = get_long(buf+State_D2);
+              remote_insert_wbreakpoint(get_long(buf+State_A0) + 4);
+	      get_offsets();
+              remote_resume(0,0,TARGET_SIGNAL_0);
+	      stop_soon_quietly = 0;
+              continue;
+	    }
+	    break;
+	    
+	  }
+  	  puts_filtered ("Unknown packet received.\n");
+	}
+	return inferior_pid;
+}
+
+/* Number of bytes of registers this stub implements.  */
+static int register_bytes_found;
+
+/* Read the remote registers into the block REGS.  */
+/* Currently we just read all the registers, so we don't use regno.  */
+/* ARGSUSED */
+static void
+remote_fetch_registers (regno)
+     int regno;
+{
+  int i;
+  unsigned long sr;
+  
+  for (i = 0; i < NUM_REGS; i++)
+      supply_register (i, &regs[REGISTER_BYTE(i)]);
+}
+
+/* Prepare to store registers.  Since we may send them all (using a
+   'G' request), we have to read out the ones we don't want to change
+   first.  */
+
+static void 
+remote_prepare_to_store ()
+{
+  /* no-op, registers are automatic retrieved */
+  return;
+}
+
+/* Store register REGNO, or all registers if REGNO == -1, from the contents
+   of REGISTERS.  FIXME: ignores errors.  */
+
+static void
+remote_store_registers (regno)
+     int regno;
+{
+  int i;
+  for (i = 0; i < NUM_REGS; i++)
+      if ((regno==-1) || (i == regno))
+          memcpy(&regs[REGISTER_BYTE(i)], &registers[REGISTER_BYTE(i)], 4);
+}
+
+/* 
+   Use of the data cache *used* to be disabled because it loses for looking at
+   and changing hardware I/O ports and the like.  Accepting `volatile'
+   would perhaps be one way to fix it.  Another idea would be to use the
+   executable file for the text segment (for all SEC_CODE sections?
+   For all SEC_READONLY sections?).  This has problems if you want to
+   actually see what the memory contains (e.g. self-modifying code,
+   clobbered memory, user downloaded the wrong thing).  
+
+   Because it speeds so much up, it's now enabled, if you're playing
+   with registers you turn it of (set remotecache 0)
+*/
+
+/* Read a word from remote address ADDR and return it.
+   This goes through the data cache.  */
+
+#if 0	/* unused? */
+static int
+remote_fetch_word (addr)
+     CORE_ADDR addr;
+{
+  return dcache_fetch (remote_dcache, addr);
+}
+
+/* Write a word WORD into remote address ADDR.
+   This goes through the data cache.  */
+
+static void
+remote_store_word (addr, word)
+     CORE_ADDR addr;
+     int word;
+{
+  dcache_poke (remote_dcache, addr, word);
+}
+#endif	/* 0 (unused?) */
+
+
+/* Write memory data directly to the remote machine.
+   This does not inform the data cache; the data cache uses this.
+   MEMADDR is the address in the remote memory space.
+   MYADDR is the address of the buffer in our space.
+   LEN is the number of bytes.
+
+   Returns number of bytes transferred, or 0 for error.  */
+
+static int
+remote_write_bytes (memaddr, myaddr, len)
+     CORE_ADDR memaddr;
+     char *myaddr;
+     int len;
+{
+	char buffer[280];
+	char * ret;
+	int l;
+	unsigned long todo, done;
+	
+	printf("wanting to write %d bytes at %d\n", len, memaddr);
+	
+	done = 0;
+	while (done < len) {
+	  todo = (len-done);
+	  if (todo > 256)
+	    todo = 256;
+	  
+	  buffer[0] = 0x02;
+	  buffer[1] = 0;
+	  set_long(buffer+2, memaddr + done);
+	  set_short(buffer+6, todo);
+	  
+	  memcpy(buffer+8, myaddr+done, todo);
+	  
+	  putpkt(buffer, 8 + todo);
+	  
+	  if (getpkt(&ret, 0) != 12) {
+	    break;
+	  }
+	  done += todo;
+	}
+	printf("Actually wrote %d bytes\n", done);
+	return done;
+}
+
+/* Read memory data directly from the remote machine.
+   This does not use the data cache; the data cache uses this.
+   MEMADDR is the address in the remote memory space.
+   MYADDR is the address of the buffer in our space.
+   LEN is the number of bytes.
+
+   Returns number of bytes transferred, or 0 for error.  */
+
+static int
+remote_read_bytes (memaddr, myaddr, len)
+     CORE_ADDR memaddr;
+     char *myaddr;
+     int len;
+{
+	char buffer[8];
+	char * ret;
+	unsigned long todo, done;
+	
+	done = 0;
+	while (done < len) {
+	  todo = (len-done);
+	  if (todo > 256)
+	    todo = 256;
+	  
+	  buffer[0] = 0x01;
+	  buffer[1] = 0;
+	  set_long(buffer+2, memaddr + done);
+	  set_short(buffer+6, todo);
+	  
+	  putpkt(buffer, 8);
+	  
+	  if (getpkt(&ret, 0) == todo+12) {
+	    memcpy(myaddr+done, ret+12, todo);
+	  } else {
+	    break;
+	  }
+	  done += todo;
+	}
+	return done;
+}
+
+/* Read or write LEN bytes from inferior memory at MEMADDR, transferring
+   to or from debugger address MYADDR.  Write to inferior if SHOULD_WRITE is
+   nonzero.  Returns length of data written or read; 0 for error.  */
+
+/* ARGSUSED */
+static int
+remote_xfer_memory(memaddr, myaddr, len, should_write, target)
+     CORE_ADDR memaddr;
+     char *myaddr;
+     int len;
+     int should_write;
+     struct target_ops *target;			/* ignored */
+{
+  return dcache_xfer_memory (remote_dcache, memaddr, myaddr, len, should_write);
+}
+
+   
+#if 0
+/* Enable after 4.12.  */
+
+void
+remote_search (len, data, mask, startaddr, increment, lorange, hirange
+	       addr_found, data_found)
+     int len;
+     char *data;
+     char *mask;
+     CORE_ADDR startaddr;
+     int increment;
+     CORE_ADDR lorange;
+     CORE_ADDR hirange;
+     CORE_ADDR *addr_found;
+     char *data_found;
+{
+}
+#endif /* 0 */
+
+static void
+remote_files_info (ignore)
+     struct target_ops *ignore;
+{
+  puts_filtered ("Debugging a target over a serial line.\n");
+}
+
+static unsigned char transid = 0x11;
+
+/* Send a packet to the remote machine.
+   The data of the packet is in BUF.  */
+
+static int
+putpkt (buf, len)
+     char *buf;
+     int len;
+{
+  static unsigned char buffer[0xffff];
+  int i;
+  
+  buffer[0] = 0xBE;
+  buffer[1] = 0xEF;
+  buffer[2] = 0xED;
+  buffer[3] = 0;
+  buffer[4] = 0;
+  buffer[5] = 0;
+  buffer[6] = len >> 8;
+  buffer[7] = len & 0xff;
+  buffer[8] = ++transid;
+  buffer[9] = 0;
+  for (i=0;i<9;i++)
+    buffer[9] += buffer[i];
+  
+  memcpy(buffer+10, buf, len);
+  
+  set_short(buffer+len+10, docrc(buffer, len+10));
+  
+  /*printf("Sending: ");
+  for (i=0;i<len+12;i++) {
+     printf("%.2X ", buffer[i]);
+  }
+  printf("!\n");*/
+   
+  if (SERIAL_WRITE(remote_desc, buffer, len+12))
+         perror_with_name ("putpkt: write failed");
+}
+
+/* Read a packet from the remote machine, with error checking,
+   and store it in BUF.  BUF is expected to be of size PBUFSIZ.
+   If FOREVER, wait forever rather than timing out; this is used
+   while the target is executing user code.  */
+
+static int
+getpkt (buf, forever)
+     char **buf;
+     int forever;
+{
+  static unsigned char buffer[0xffff];
+  int state = 0;
+  int c;
+  int i;
+  unsigned int src, dest, type, len, csum, crc;
+  
+  while(1) {
+    c = readchar(-1);
+    if (c == SERIAL_TIMEOUT) {
+       if (!forever)
+          return 0;
+    }
+    
+    buffer[state] = c;
+    
+    switch (state) {
+    	case 0:
+    	    if (c == 0xBE) state++; else state=0;
+    	    break;
+    	case 1:
+    	    if  (c == 0xEF) state++; else state=0; 
+    	    break;
+    	case 2:
+    	    if  (c == 0xED) state++; else state=0;
+    	    break;
+    	case 3:
+    	case 4:
+    	case 5:
+    	case 6:
+    	case 7:
+    	case 8:
+    	    state++;
+    	    break;
+    	case 9:
+    	    csum = 0;
+    	    for (i=0;i<9;i++)
+    	      csum += buffer[i];
+    	    if ((csum & 0xff) == c) {
+    	      len = (buffer[6] << 8) | buffer[7];
+    	      state++;
+    	    }
+    	    else
+    	      state=0;
+    	    break;
+    	default:
+    	    if (state >= 10) {
+    	      if (state < 10+len) {
+    	        state++;
+    	      } 
+    	      else if (state == 10+len) {
+    	        crc = c;
+    	        state++;
+    	      } else if (state == 11+len) {
+    	        unsigned long mycrc = docrc(buffer,len+10);
+    	        crc = (crc<<8)|c;
+    	        if ((crc & 0xffff) == mycrc) {
+    	           *buf = buffer;
+    	           return len+10;
+    	        } else 
+    	          state = 0;
+    	      } else
+    	        state = 0;
+    	    } else
+    	      state = 0;
+       }
+       
+  }
+}
+
+static void
+remote_kill ()
+{
+  char buffer[96];
+
+  /* For some mysterious reason, wait_for_inferior calls kill instead of
+     mourn after it gets TARGET_WAITKIND_SIGNALLED.  Work around it.  */
+  if (kill_kludge)
+    {
+      kill_kludge = 0;
+      target_mourn_inferior ();
+      return;
+    }
+    
+  /* Warm boot the Pilot */
+  
+  buffer[0] = 0x0A;
+  buffer[1] = 0;
+  set_short(buffer+2, 0xA08C); /* SysReboot */
+  set_long(buffer+4, 0); /*D0*/
+  set_long(buffer+8, 0); /*A0*/
+  set_short(buffer+12, 0); /* No parameters */
+  
+  putpkt(buffer, 14);
+
+  /* Don't wait for it to die.  I'm not really sure it matters whether
+     we do or not.  For the existing stubs, kill is a noop.  */
+  target_mourn_inferior ();
+}
+
+static void
+remote_mourn ()
+{
+  unpush_target (&palmos_ops);
+  generic_mourn_inferior ();
+}
+
+
+
+/* Note: we must use native breakpoint support, as code segments are in
+   write-protected memory, and thus cannot easily have breaks written
+   over them. */
+
+/* Send breakpoint structure to the Pilot. Return non-zero on error */
+
+static int
+set_breakpoints()
+{
+  int i;
+  char buffer[90];
+  char * ret;
+  
+  buffer[0] = 0x0c;
+  buffer[1] = 0;
+  
+  for(i=0;i<6;i++) {
+    set_long(buffer+2+i*6, breakpoint[i].address);
+    set_byte(buffer+2+4+i*6, breakpoint[i].on);
+    set_byte(buffer+2+5+i*6, 0);
+  }
+  
+  putpkt(buffer, 38);
+  
+  if (i = getpkt(&ret, 0)) {
+    return ((unsigned char)ret[10] != (unsigned char)0x8c) || (i != 12);
+  }
+  return 1;
+}
+
+static int
+remote_insert_breakpoint (addr, contents_cache)
+     CORE_ADDR addr;
+     char *contents_cache;
+{
+  int i;
+  for (i=0;i<MAX_BREAKS;i++)
+    if (breakpoint[i].on == 0)
+      break;
+  if (i < MAX_BREAKS) {
+    breakpoint[i].address = addr;
+    breakpoint[i].on = 1;
+    return set_breakpoints();
+  } else {
+        fprintf_filtered (gdb_stderr,
+        "Too many break points, break point not installed\n");
+       return (1);
+  }                            
+}
+
+static int
+remote_remove_breakpoint (addr, contents_cache)
+     CORE_ADDR addr;
+     char *contents_cache;
+{
+  int i;
+  for (i=0;i<MAX_BREAKS;i++)
+    if (breakpoint[i].on && breakpoint[i].address == addr)
+      break;
+  if (i<MAX_BREAKS) {
+    breakpoint[i].address = 0;
+    breakpoint[i].on = 0;
+    return set_breakpoints();
+  }
+  
+  return 0;
+}
+
+static void
+remote_insert_wbreakpoint (addr)
+     CORE_ADDR addr;
+{
+  breakpoint[MAX_BREAKS].address = addr;
+  breakpoint[MAX_BREAKS].on = 1;
+#if 0
+  stop_soon_quietly = 1;  /* gdb is making a mess of this stuff */
+  stop_after_trap = 1;
+#endif
+  set_breakpoints();
+}
+
+static void
+remote_remove_wbreakpoint ()
+{
+  breakpoint[MAX_BREAKS].address = 0;
+  breakpoint[MAX_BREAKS].on = 0;
+  set_breakpoints();
+}
+
+
+/* Define the target subroutine names */
+
+struct target_ops palmos_ops = {
+  "pilot",			/* to_shortname */
+  "Remote serial target in PalmOS/Pilot-specific protocol",	/* to_longname */
+  "Use Palm Pilot via a serial line, using a PalmOS-specific protocol.\n\
+Specify the serial device it is connected to (e.g. /dev/ttya).",  /* to_doc */
+  remote_open,			/* to_open */
+  remote_close,			/* to_close */
+  NULL,				/* to_attach */
+  remote_detach,		/* to_detach */
+  remote_resume,		/* to_resume */
+  remote_wait,			/* to_wait */
+  remote_fetch_registers,	/* to_fetch_registers */
+  remote_store_registers,	/* to_store_registers */
+  remote_prepare_to_store,	/* to_prepare_to_store */
+  remote_xfer_memory,		/* to_xfer_memory */
+  remote_files_info,		/* to_files_info */
+  remote_insert_breakpoint,	/* to_insert_breakpoint */
+  remote_remove_breakpoint,	/* to_remove_breakpoint */
+  NULL,				/* to_terminal_init */
+  NULL,				/* to_terminal_inferior */
+  NULL,				/* to_terminal_ours_for_output */
+  NULL,				/* to_terminal_ours */
+  NULL,				/* to_terminal_info */
+  remote_kill,			/* to_kill */
+  generic_load,			/* to_load */
+  NULL,				/* to_lookup_symbol */
+  NULL,				/* to_create_inferior */
+  remote_mourn,			/* to_mourn_inferior */
+  0,				/* to_can_run */
+  0,				/* to_notice_signals */
+  0,				/* to_thread_alive */
+  0,				/* to_stop */
+  process_stratum,		/* to_stratum */
+  NULL,				/* to_next */
+  1,				/* to_has_all_memory */
+  1,				/* to_has_memory */
+  1,				/* to_has_stack */
+  1,				/* to_has_registers */
+  1,				/* to_has_execution */
+  NULL,				/* sections */
+  NULL,				/* sections_end */
+  OPS_MAGIC			/* to_magic */
+};
+
+void
+_initialize_pilot ()
+{
+  add_target (&palmos_ops);
+}
diff -urN gdb-4.16-orig/gdb/ser-unix.c gdb-4.16/gdb/ser-unix.c
--- gdb-4.16-orig/gdb/ser-unix.c	Thu Sep 28 17:13:39 1995
+++ gdb-4.16/gdb/ser-unix.c	Tue Oct 27 16:46:27 1998
@@ -579,6 +579,18 @@
   {9600, B9600},
   {19200, B19200},
   {38400, B38400},
+#ifdef B57600
+  {57600, B57600},
+#endif
+#ifdef B115200
+  {115200, B115200},
+#endif
+#ifdef B230400
+  {230400, B230400},
+#endif
+#ifdef B460800
+  {460800, B460800},
+#endif
   {-1, -1},
 };
 
diff -urN gdb-4.16-orig/mmalloc/ChangeLog gdb-4.16/mmalloc/ChangeLog
--- gdb-4.16-orig/mmalloc/ChangeLog	Sun Apr  7 21:44:24 1996
+++ gdb-4.16/mmalloc/ChangeLog	Thu Apr 23 12:19:59 1998
@@ -1,3 +1,101 @@
+Thu Apr 23 12:19:22 1998  Philippe De Muyter  <phdm@macqel.be>
+
+        * mmalloc.h: Include sys/types.h and stdio.h #ifndef HAVE_STDDEF_H.
+        * mmprivate.h: Do not handle HAVE_STDDEF_H here, since we include
+        mmalloc.h.
+
+Mon Feb  7 13:06:45 1997  Philippe De Muyter  <phdm@macqel.be>
+
+        * mmalloc/detach.c: Do not include fcntl.h.
+
+Thu Aug 28 13:15:07 1997  Andrew Cagney  <cagney@b1.cygnus.com>
+
+	* mrealloc.c (realloc): Store result in local variable before
+ 	returning it.  Makes debugging much easier at negligible cost.
+
+Tue Feb  4 16:30:59 1997  Ian Lance Taylor  <ian@cygnus.com>
+
+	* mvalloc.c (cache_pagesize): Rename from pagesize, so that if we
+	are building mm.o, it does not conflict with the variable of the
+	same name in mmap-sup.c.
+
+Sat Dec 28 12:48:32 1996  Fred Fish  <fnf@cygnus.com>
+
+	* Makefile.in (mm.o): New target that combines all the functions
+	into a single object module.  This avoids client programs picking
+ 	up part of the allocation routines from mmalloc and part from libc,
+ 	which can lead to undefined behavior.
+	(CFILES): Add mm.c
+	(TARGETOBJS): Define to be either the individual objects or the
+	single combined object.
+	(TARGETLIB): Create the archive using TARGETOBJS.
+	* mm.c: New file that simply #includes the other source C files.
+	
+Thu Oct  3 15:45:23 1996  Jason Molenda  (crash@godzilla.cygnus.co.jp)
+
+	* Makefile.in (maintainer-clean): Depend on distclean, remove
+	duplication.
+
+Tue Sep 10 17:52:06 1996  Fred Fish  <fnf@cygnus.com>
+
+	* mmcheck.c (checkhdr): Add prototype.
+	(mfree_check): Ditto.
+	(mmalloc_check): Ditto.
+	(mrealloc_check): Ditto.
+	* mmtrace.c (tr_break): Ditto.
+	(tr_freehook): Ditto.
+	(tr_mallochook): Ditto.
+	(tr_reallochook): Ditto.
+	* sbrk-sup.c (sbrk_morecore): Ditto.
+
+Wed Sep  4 18:02:45 1996  Stu Grossman  (grossman@critters.cygnus.com)
+
+	* configure configure.in:  Don't default CC to cc.  It causes problems
+	when starting a compile in the mmalloc directory.
+
+Wed Jul 24 00:53:34 1996  Fred Fish  <fnf@cygnus.com>
+
+	* mmalloc.h (mmalloc_findbase): Add prototype.
+
+Fri Jul 12 18:35:34 1996  Fred Fish  <fnf@cygnus.com>
+
+	* mmap-sup.c (mmalloc_findbase): Change to not require /dev/zero
+	if MMAP_ANONYMOUS is available.
+
+Wed Jul 10 23:53:42 1996  Fred Fish  <fnf@cygnus.com>
+
+	* detach.c (mmalloc_detach): Fix bug in computation of negative
+	brk value.
+	* mmcheck.c (mmcheckf): Renamed from mmcheck and new FORCE argument
+	added.  Replaced hack that always allowed checking routines to be
+ 	installed and enforce restriction that they have to be installed
+	prior to allocating any memory on the used heap or the FORCE argument
+	has to be non-NULL.
+	(mmcheck): New function that calls mmcheckf with FORCE set to zero,
+	for backwards compatibility.
+	* mmalloc.c (malloc): Store result in local variable before
+	returning it.  Makes debugging much easier at negligible cost.
+	* mmalloc.h (mmcheckf): Declare.
+	* attach.c (reuse): Call mmcheckf rather than mmcheck.
+	* mmap-sup.c (__mmalloc_mmap_morecore): Improve to allow mmap
+	to select a base mapping address if none is otherwise given.
+	(mmalloc_findbase): New function that user can call to find
+	an available mapping address of a given size.
+	
+Tue Jun 25 22:54:06 1996  Jason Molenda  (crash@godzilla.cygnus.co.jp)
+
+	* Makefile.in (bindir, libdir, datadir, mandir, infodir, includedir):
+	Use autoconf-set values.
+	(docdir): Removed.
+	* configure.in (AC_PREREQ): autoconf 2.5 or higher.
+	* configure: Rebuilt.
+
+Tue May 28 13:51:22 1996  Fred Fish  <fnf@cygnus.com>
+
+	From: Thomas A Peterson <tap@src.honeywell.com>
+	* Makefile.in (install-info): Apply patch to install
+	mmalloc.info from srcdir if not found in build dir.
+
 Sun Apr  7 20:55:30 1996  Fred Fish  <fnf@rtl.cygnus.com>
 
 	From: Miles Bader  <miles@gnu.ai.mit.edu>
diff -urN gdb-4.16-orig/mmalloc/Makefile.in gdb-4.16/mmalloc/Makefile.in
--- gdb-4.16-orig/mmalloc/Makefile.in	Sun Apr  7 21:44:26 1996
+++ gdb-4.16/mmalloc/Makefile.in	Sat Dec 28 14:33:49 1996
@@ -29,11 +29,11 @@
 prefix =	@prefix@
 exec_prefix =	@exec_prefix@
 
-bindir =	$(exec_prefix)/bin
-libdir =	$(exec_prefix)/lib
+bindir =	@bindir@
+libdir =	@libdir@
 
-datadir =	$(prefix)/lib
-mandir =	$(prefix)/man
+datadir =	@datadir@
+mandir =	@mandir@
 man1dir =	$(mandir)/man1
 man2dir =	$(mandir)/man2
 man3dir =	$(mandir)/man3
@@ -43,9 +43,8 @@
 man7dir =	$(mandir)/man7
 man8dir =	$(mandir)/man8
 man9dir =	$(mandir)/man9
-infodir =	$(prefix)/info
-includedir =	$(prefix)/include
-docdir =	$(datadir)/doc
+infodir =	@infodir@
+includedir =	@includedir@
 
 SHELL =		/bin/sh
 
@@ -72,7 +71,7 @@
 
 CFILES =	mcalloc.c mfree.c mmalloc.c mmcheck.c mmemalign.c mmstats.c \
 		mmtrace.c mrealloc.c mvalloc.c mmap-sup.c attach.c detach.c \
-		keys.c sbrk-sup.c
+		keys.c sbrk-sup.c mm.c
 
 HFILES =	mmalloc.h
 
@@ -82,8 +81,13 @@
 
 DEFS =		@DEFS@
 
+# The current default is to build a single object module with all the mmalloc
+# functions.  To build a more traditional library, flip this macro definition.
+#TARGETOBJS =	$(OFILES)
+TARGETOBJS =	mm.o
+
 .c.o:
-	$(CC) -c $(CFLAGS) $(DEFS) -I. -I$(srcdir)/../include $<
+		$(CC) -c $(CFLAGS) $(DEFS) -I. -I$(srcdir)/../include $<
 
 # Do we want/need any config overrides?
 #	 
@@ -106,6 +110,7 @@
 	rm -f mmalloc.?? mmalloc.??s mmalloc.log mmalloc.aux mmalloc.toc
 
 install-info: info
+	if test ! -f mmalloc.info ; then cd $(srcdir); fi; \
 	$(INSTALL_DATA) mmalloc.info $(infodir)/mmalloc.info
 
 check: test1.c
@@ -120,13 +125,16 @@
 		$(RANLIB) $(libdir)/$(TARGETLIB).n
 		mv -f $(libdir)/$(TARGETLIB).n $(libdir)/$(TARGETLIB)
 
-$(TARGETLIB):	$(OFILES)
+$(TARGETLIB):	$(TARGETOBJS)
 		$(RM) -rf $@
-		$(AR) $(AR_FLAGS) $@ $(OFILES)
+		$(AR) $(AR_FLAGS) $@ $(TARGETOBJS)
 		$(RANLIB) $@
 
 $(OFILES) :	$(HFILES) Makefile
 
+mm.o:		$(HFILES) $(CFILES)
+		$(CC) -c $(CFLAGS) $(DEFS) -I. -I$(srcdir)/../include $(srcdir)/mm.c
+
 .always.:
 # Do nothing.
 
@@ -186,12 +194,10 @@
 		rm -f config.cache config.log config.status
 		rm -f Makefile depend
 
-maintainer-clean realclean:	clean 
+maintainer-clean realclean: distclean clean
 		@echo "This command is intended for maintainers to use;"
 		@echo "it deletes files that may require special tools to rebuild."
-		rm -f config.cache config.log config.status
 		rm -f mmalloc.info
-		rm -f Makefile depend
 
 force:
 
diff -urN gdb-4.16-orig/mmalloc/attach.c gdb-4.16/mmalloc/attach.c
--- gdb-4.16-orig/mmalloc/attach.c	Tue Aug  1 20:39:23 1995
+++ gdb-4.16/mmalloc/attach.c	Thu Jul 11 00:36:17 1996
@@ -163,10 +163,10 @@
    certainly will be at a different address if the process reusing the
    mapped region is from a different executable.
 
-   Also note that if the heap being remapped previously used the mmcheck()
+   Also note that if the heap being remapped previously used the mmcheckf()
    routines, we need to update the hooks since their target functions
    will have certainly moved if the executable has changed in any way.
-   We do this by calling mmcheck() internally.
+   We do this by calling mmcheckf() internally.
 
    Returns a pointer to the malloc descriptor if successful, or NULL if
    unsuccessful for some reason. */
@@ -192,7 +192,7 @@
 	  mdp -> morecore = __mmalloc_mmap_morecore;
 	  if (mdp -> mfree_hook != NULL)
 	    {
-	      mmcheck ((PTR) mdp, (void (*) PARAMS ((void))) NULL);
+	      mmcheckf ((PTR) mdp, (void (*) PARAMS ((void))) NULL, 1);
 	    }
 	}
     }
diff -urN gdb-4.16-orig/mmalloc/configure gdb-4.16/mmalloc/configure
--- gdb-4.16-orig/mmalloc/configure	Sun Apr  7 21:44:27 1996
+++ gdb-4.16/mmalloc/configure	Wed Sep  4 18:06:12 1996
@@ -1,8 +1,8 @@
 #! /bin/sh
 
 # Guess values for system-dependent variables and create Makefiles.
-# Generated automatically using autoconf version 2.8 
-# Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
+# Generated automatically using autoconf version 2.10 
+# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
 #
 # This configure script is free software; the Free Software Foundation
 # gives unlimited permission to copy, distribute and modify it.
@@ -330,7 +330,7 @@
     verbose=yes ;;
 
   -version | --version | --versio | --versi | --vers)
-    echo "configure generated by autoconf version 2.8"
+    echo "configure generated by autoconf version 2.10"
     exit 0 ;;
 
   -with-* | --with-*)
@@ -513,7 +513,6 @@
 
 
 
-CC=${CC-cc}
 # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
@@ -600,7 +599,7 @@
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:604: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:603: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
@@ -867,11 +866,11 @@
   ac_cv_c_cross=yes
 else
 cat > conftest.$ac_ext <<EOF
-#line 871 "configure"
+#line 870 "configure"
 #include "confdefs.h"
 main(){return(0);}
 EOF
-{ (eval echo configure:875: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
+{ (eval echo configure:874: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
 if test -s conftest && (./conftest; exit) 2>/dev/null; then
   ac_cv_c_cross=no
 else
@@ -891,12 +890,14 @@
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 895 "configure"
+#line 894 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
 char $ac_func();
 
 int main() { return 0; }
@@ -913,7 +914,7 @@
 
 ; return 0; }
 EOF
-if { (eval echo configure:917: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
+if { (eval echo configure:918: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -943,7 +944,7 @@
   ac_cv_func_mmap=no
 else
 cat > conftest.$ac_ext <<EOF
-#line 947 "configure"
+#line 948 "configure"
 #include "confdefs.h"
 
 /* Thanks to Mike Haertel and Jim Avera for this test. */
@@ -1012,7 +1013,7 @@
 }
 
 EOF
-{ (eval echo configure:1016: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
+{ (eval echo configure:1017: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }
 if test -s conftest && (./conftest; exit) 2>/dev/null; then
   ac_cv_func_mmap=yes
 else
@@ -1045,13 +1046,13 @@
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 1049 "configure"
+#line 1050 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1055: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1056: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   :
@@ -1060,13 +1061,13 @@
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 1064 "configure"
+#line 1065 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1070: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1071: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   :
@@ -1094,12 +1095,12 @@
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1098 "configure"
+#line 1099 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1103: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1104: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1212,7 +1213,7 @@
     echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
     exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
   -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
-    echo "$CONFIG_STATUS generated by autoconf version 2.8"
+    echo "$CONFIG_STATUS generated by autoconf version 2.10"
     exit 0 ;;
   -help | --help | --hel | --he | --h)
     echo "\$ac_cs_usage"; exit 0 ;;
diff -urN gdb-4.16-orig/mmalloc/configure.in gdb-4.16/mmalloc/configure.in
--- gdb-4.16-orig/mmalloc/configure.in	Sun Apr  7 21:44:29 1996
+++ gdb-4.16/mmalloc/configure.in	Wed Sep  4 18:06:13 1996
@@ -1,8 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_PREREQ(2.3)dnl
+AC_PREREQ(2.5)dnl
 AC_INIT(mmalloc.c)
 
-CC=${CC-cc}
 AC_PROG_CC
 AC_PROG_INSTALL
 AC_CHECK_TOOL(AR, ar)
diff -urN gdb-4.16-orig/mmalloc/detach.c gdb-4.16/mmalloc/detach.c
--- gdb-4.16-orig/mmalloc/detach.c	Tue Aug  1 20:39:26 1995
+++ gdb-4.16/mmalloc/detach.c	Fri Feb  6 12:46:04 1998
@@ -21,7 +21,6 @@
 Boston, MA 02111-1307, USA.  */
 
 #include <sys/types.h>
-#include <fcntl.h> /* After sys/types.h, at least for dpx/2.  */
 #include "mmprivate.h"
 
 /* Terminate access to a mmalloc managed region by unmapping all memory pages
@@ -52,9 +51,10 @@
       /* Now unmap all the pages associated with this region by asking for a
 	 negative increment equal to the current size of the region. */
       
-      if ((mtemp.morecore (&mtemp, mtemp.base - mtemp.top)) == NULL)
+      if ((mtemp.morecore (&mtemp, mtemp.base - mtemp.breakval)) == NULL)
 	{
-	  /* Update the original malloc descriptor with any changes */
+	  /* Deallocating failed.  Update the original malloc descriptor
+	     with any changes */
 	  *(struct mdesc *) md = mtemp;
 	}
       else
diff -urN gdb-4.16-orig/mmalloc/mm.c gdb-4.16/mmalloc/mm.c
--- gdb-4.16-orig/mmalloc/mm.c	Wed Dec 31 16:00:00 1969
+++ gdb-4.16/mmalloc/mm.c	Sat Dec 28 14:33:53 1996
@@ -0,0 +1,37 @@
+/* Build the entire mmalloc library as a single object module. This
+   avoids having clients pick up part of their allocation routines
+   from mmalloc and part from libc, which results in undefined
+   behavior.  It should also still be possible to build the library
+   as a standard library with multiple objects.
+
+   Copyright 1996 Free Software Foundation
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+#include "mcalloc.c"
+#include "mfree.c"
+#include "mmalloc.c"
+#include "mmcheck.c"
+#include "mmemalign.c"
+#include "mmstats.c"
+#include "mmtrace.c"
+#include "mrealloc.c"
+#include "mvalloc.c"
+#include "mmap-sup.c"
+#include "attach.c"
+#include "detach.c"
+#include "keys.c"
+#include "sbrk-sup.c"
diff -urN gdb-4.16-orig/mmalloc/mmalloc.c gdb-4.16/mmalloc/mmalloc.c
--- gdb-4.16-orig/mmalloc/mmalloc.c	Tue Aug  1 20:39:33 1995
+++ gdb-4.16/mmalloc/mmalloc.c	Thu Jul 11 00:36:21 1996
@@ -330,5 +330,8 @@
 malloc (size)
   size_t size;
 {
-  return (mmalloc ((PTR) NULL, size));
+  PTR result;
+
+  result = mmalloc ((PTR) NULL, size);
+  return (result);
 }
diff -urN gdb-4.16-orig/mmalloc/mmalloc.h gdb-4.16/mmalloc/mmalloc.h
--- gdb-4.16-orig/mmalloc/mmalloc.h	Fri Mar 29 22:00:03 1996
+++ gdb-4.16/mmalloc/mmalloc.h	Thu Apr 23 12:20:11 1998
@@ -1,12 +1,11 @@
 #ifndef MMALLOC_H
 #define MMALLOC_H 1
 
-/*  FIXME:  If <stddef.h> doesn't exist, you'll need to do something
-            to define size_t before including this file.  Like upgrading
-            to a system with an ANSI C environment. */
-
 #ifdef HAVE_STDDEF_H
 #  include <stddef.h>
+#else
+#  include <sys/types.h>   /* for size_t */
+#  include <stdio.h>       /* for NULL */
 #endif
 
 #include "ansidecl.h"
@@ -40,6 +39,8 @@
 
 extern int mmcheck PARAMS ((PTR, void (*) (void)));
 
+extern int mmcheckf PARAMS ((PTR, void (*) (void), int));
+
 /* Pick up the current statistics. (see FIXME elsewhere) */
 
 extern struct mstats mmstats PARAMS ((PTR));
@@ -55,5 +56,7 @@
 extern int mmalloc_errno PARAMS ((PTR));
 
 extern int mmtrace PARAMS ((void));
+
+extern PTR mmalloc_findbase PARAMS ((int));
 
 #endif  /* MMALLOC_H */
diff -urN gdb-4.16-orig/mmalloc/mmalloc.info gdb-4.16/mmalloc/mmalloc.info
--- gdb-4.16-orig/mmalloc/mmalloc.info	Mon Apr 22 21:51:37 1996
+++ gdb-4.16/mmalloc/mmalloc.info	Thu Apr 23 16:08:26 1998
@@ -1,5 +1,5 @@
-This is Info file ./mmalloc.info, produced by Makeinfo-1.55 from the
-input file mmalloc.texi.
+This is Info file ./mmalloc.info, produced by Makeinfo version 1.68
+from the input file mmalloc.texi.
 
 START-INFO-DIR-ENTRY
 * Mmalloc: (mmalloc).		The GNU mapped-malloc package.
@@ -210,10 +210,10 @@
 
 
 Tag Table:
-Node: Top955
-Node: Overview1389
-Node: Implementation2417
-Node: Compatibility3810
-Node: Functions4884
+Node: Top963
+Node: Overview1397
+Node: Implementation2425
+Node: Compatibility3818
+Node: Functions4892
 
 End Tag Table
diff -urN gdb-4.16-orig/mmalloc/mmap-sup.c gdb-4.16/mmalloc/mmap-sup.c
--- gdb-4.16-orig/mmalloc/mmap-sup.c	Tue Aug  1 20:39:35 1995
+++ gdb-4.16/mmalloc/mmap-sup.c	Fri Jul 12 22:24:46 1996
@@ -104,13 +104,29 @@
 	  /* FIXME:  Test results of lseek() and write() */
 	  lseek (mdp -> fd, foffset + mapbytes - 1, SEEK_SET);
 	  write (mdp -> fd, &buf, 1);
-	  mapto = mmap (mdp -> top, mapbytes, PROT_READ | PROT_WRITE,
-			MAP_SHARED | MAP_FIXED, mdp -> fd, foffset);
-	  if (mapto == mdp -> top)
+	  if (mdp -> base == 0)
 	    {
-	      mdp -> top = moveto;
-	      result = (PTR) mdp -> breakval;
-	      mdp -> breakval += size;
+	      /* Let mmap pick the map start address */
+	      mapto = mmap (0, mapbytes, PROT_READ | PROT_WRITE,
+			    MAP_SHARED, mdp -> fd, foffset);
+	      if (mapto != (caddr_t) -1)
+		{
+		  mdp -> base = mdp -> breakval = mapto;
+		  mdp -> top = mdp -> base + mapbytes;
+		  result = (PTR) mdp -> breakval;
+		  mdp -> breakval += size;
+		}
+	    }
+	  else
+	    {
+	      mapto = mmap (mdp -> top, mapbytes, PROT_READ | PROT_WRITE,
+			    MAP_SHARED | MAP_FIXED, mdp -> fd, foffset);
+	      if (mapto == mdp -> top)
+		{
+		  mdp -> top = moveto;
+		  result = (PTR) mdp -> breakval;
+		  mdp -> breakval += size;
+		}
 	    }
 	}
       else
@@ -133,6 +149,53 @@
   base = mmap (mdp -> base, mdp -> top - mdp -> base,
 	       PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
 	       mdp -> fd, 0);
+  return ((PTR) base);
+}
+
+PTR
+mmalloc_findbase (size)
+  int size;
+{
+  int fd;
+  int flags;
+  caddr_t base = NULL;
+
+#ifdef MAP_ANONYMOUS
+  flags = MAP_SHARED | MAP_ANONYMOUS;
+  fd = -1;
+#else
+#ifdef MAP_FILE
+  flags = MAP_SHARED | MAP_FILE;
+#else
+  flags = MAP_SHARED;
+#endif
+  fd = open ("/dev/zero", O_RDWR);
+  if (fd != -1)
+    {
+      return ((PTR) NULL);
+    }
+#endif
+  base = mmap (0, size, PROT_READ | PROT_WRITE, flags, fd, 0);
+  if (base != (caddr_t) -1)
+    {
+      munmap (base, (size_t) size);
+    }
+  if (fd != -1)
+    {
+      close (fd);
+    }
+  if (base == 0)
+    {
+      /* Don't allow mapping at address zero.  We use that value
+	 to signal an error return, and besides, it is useful to
+	 catch NULL pointers if it is unmapped.  Instead start
+	 at the next page boundary. */
+      base = (caddr_t) getpagesize ();
+    }
+  else if (base == (caddr_t) -1)
+    {
+      base = NULL;
+    }
   return ((PTR) base);
 }
 
diff -urN gdb-4.16-orig/mmalloc/mmcheck.c gdb-4.16/mmalloc/mmcheck.c
--- gdb-4.16-orig/mmalloc/mmcheck.c	Tue Aug  1 20:39:37 1995
+++ gdb-4.16/mmalloc/mmcheck.c	Tue Sep 10 17:53:25 1996
@@ -51,6 +51,11 @@
     unsigned long int magic;	/* Magic number to check header integrity.  */
   };
 
+static void checkhdr PARAMS ((struct mdesc *, CONST struct hdr *));
+static void mfree_check PARAMS ((PTR, PTR));
+static PTR mmalloc_check PARAMS ((PTR, size_t));
+static PTR mrealloc_check PARAMS ((PTR, PTR, size_t));
+
 /* Check the magicword and magicbyte, and if either is corrupted then
    call the emergency abort function specified for the heap in use. */
 
@@ -145,13 +150,20 @@
    that is allocated prior to installation of the hooks is subsequently
    reallocated or freed after installation of the hooks, it is guaranteed
    to trigger a memory corruption error.  We do this by checking the state
-   of the MMALLOC_INITIALIZED flag.
+   of the MMALLOC_INITIALIZED flag.  If the FORCE argument is non-zero, this
+   checking is disabled and it is allowed to install the checking hooks at any
+   time.  This is useful on systems where the C runtime makes one or more
+   malloc calls before the user code had a chance to call mmcheck or mmcheckf,
+   but never calls free with these values.  Thus if we are certain that only
+   values obtained from mallocs after an mmcheck/mmcheckf will ever be passed
+   to free(), we can go ahead and force installation of the useful checking
+   hooks.
 
    However, we can call this function at any time after the initial call,
    to update the function pointers to the checking routines and to the
    user defined corruption handler routine, as long as these function pointers
    have been previously extablished by the initial call.  Note that we
-   do this automatically when remapping an previously used heap, to ensure
+   do this automatically when remapping a previously used heap, to ensure
    that the hooks get updated to the correct values, although the corruption
    handler pointer gets set back to the default.  The application can then
    call mmcheck to use a different corruption handler if desired.
@@ -159,9 +171,10 @@
    Returns non-zero if checking is successfully enabled, zero otherwise. */
 
 int
-mmcheck (md, func)
+mmcheckf (md, func, force)
   PTR md;
   void (*func) PARAMS ((void));
+  int force;
 {
   struct mdesc *mdp;
   int rtnval;
@@ -177,7 +190,7 @@
      have hooks that were previously installed, then allow the hooks to be
      initialized or updated. */
 
-  if (1 /* FIXME: Always allow installation for now. */ ||
+  if (force ||
       !(mdp -> flags & MMALLOC_INITIALIZED) ||
       (mdp -> mfree_hook != NULL))
     {
@@ -192,5 +205,19 @@
       rtnval = 0;
     }
 
+  return (rtnval);
+}
+
+/* This routine is for backwards compatibility only, in case there are
+   still callers to the original mmcheck function. */
+
+int
+mmcheck (md, func)
+  PTR md;
+  void (*func) PARAMS ((void));
+{
+  int rtnval;
+
+  rtnval = mmcheckf (md, func, 0);
   return (rtnval);
 }
diff -urN gdb-4.16-orig/mmalloc/mmprivate.h gdb-4.16/mmalloc/mmprivate.h
--- gdb-4.16-orig/mmalloc/mmprivate.h	Mon Nov  6 14:15:01 1995
+++ gdb-4.16/mmalloc/mmprivate.h	Thu Apr 23 12:20:12 1998
@@ -36,12 +36,6 @@
 #  endif
 #endif
 
-#ifdef HAVE_STDDEF_H
-#  include <stddef.h>
-#else
-#  include <sys/types.h>   /* hope for the best -- ANSI C is your friend */
-#endif
-
 #ifndef MIN
 #  define MIN(A, B) ((A) < (B) ? (A) : (B))
 #endif
@@ -299,7 +293,7 @@
 
 #define MMALLOC_DEVZERO		(1 << 0)	/* Have mapped to /dev/zero */
 #define MMALLOC_INITIALIZED	(1 << 1)	/* Initialized mmalloc */
-#define MMALLOC_MMCHECK_USED	(1 << 2)	/* mmcheck() called already */
+#define MMALLOC_MMCHECK_USED	(1 << 2)	/* mmcheckf() called already */
 
 /* Internal version of `mfree' used in `morecore'. */
 
diff -urN gdb-4.16-orig/mmalloc/mmtrace.c gdb-4.16/mmalloc/mmtrace.c
--- gdb-4.16-orig/mmalloc/mmtrace.c	Tue Aug  1 20:39:43 1995
+++ gdb-4.16/mmalloc/mmtrace.c	Tue Sep 10 17:53:28 1996
@@ -25,6 +25,11 @@
 #include <stdio.h>
 #include "mmprivate.h"
 
+static void tr_break PARAMS ((void));
+static void tr_freehook PARAMS ((PTR, PTR));
+static PTR tr_mallochook PARAMS ((PTR, size_t));
+static PTR tr_reallochook PARAMS ((PTR, PTR, size_t));
+
 #ifndef	__GNU_LIBRARY__
 extern char *getenv ();
 #endif
@@ -138,7 +143,7 @@
 {
 #if 0	/* FIXME!  This is disabled for now until we figure out how to
 	   maintain a stack of hooks per heap, since we might have other
-	   hooks (such as set by mmcheck) active also. */
+	   hooks (such as set by mmcheck/mmcheckf) active also. */
   char *mallfile;
 
   mallfile = getenv (mallenv);
diff -urN gdb-4.16-orig/mmalloc/mrealloc.c gdb-4.16/mmalloc/mrealloc.c
--- gdb-4.16-orig/mmalloc/mrealloc.c	Tue Aug  1 20:39:45 1995
+++ gdb-4.16/mmalloc/mrealloc.c	Fri Aug 29 23:56:31 1997
@@ -156,5 +156,8 @@
   PTR ptr;
   size_t size;
 {
-  return (mrealloc ((PTR) NULL, ptr, size));
+  PTR result;
+
+  result = mrealloc ((PTR) NULL, ptr, size);
+  return (result);
 }
diff -urN gdb-4.16-orig/mmalloc/mvalloc.c gdb-4.16/mmalloc/mvalloc.c
--- gdb-4.16-orig/mmalloc/mvalloc.c	Sat Feb  3 17:17:14 1996
+++ gdb-4.16/mmalloc/mvalloc.c	Tue Feb  4 13:33:04 1997
@@ -23,7 +23,7 @@
    elsewhere, not clutter up this file with lots of kluges to try to figure
    it out. */
 
-static size_t pagesize;
+static size_t cache_pagesize;
 extern int getpagesize PARAMS ((void));
 
 PTR
@@ -31,12 +31,12 @@
   PTR md;
   size_t size;
 {
-  if (pagesize == 0)
+  if (cache_pagesize == 0)
     {
-      pagesize = getpagesize ();
+      cache_pagesize = getpagesize ();
     }
 
-  return (mmemalign (md, pagesize, size));
+  return (mmemalign (md, cache_pagesize, size));
 }
 
 
diff -urN gdb-4.16-orig/mmalloc/sbrk-sup.c gdb-4.16/mmalloc/sbrk-sup.c
--- gdb-4.16-orig/mmalloc/sbrk-sup.c	Tue Aug  1 20:39:48 1995
+++ gdb-4.16/mmalloc/sbrk-sup.c	Tue Sep 10 17:53:30 1996
@@ -23,7 +23,8 @@
 
 #include "mmprivate.h"
 
-extern PTR sbrk ();
+static PTR sbrk_morecore PARAMS ((struct mdesc *, int));
+extern PTR sbrk PARAMS ((int));
 
 /* The mmalloc() package can use a single implicit malloc descriptor
    for mmalloc/mrealloc/mfree operations which do not supply an explicit
diff -urN gdb-4.16-orig/readline/configure.in gdb-4.16/readline/configure.in
--- gdb-4.16-orig/readline/configure.in	Sun Apr  7 22:17:28 1996
+++ gdb-4.16/readline/configure.in	Tue Oct 27 16:46:27 1998
@@ -14,7 +14,7 @@
 
 case "${host}" in
   *-*-irix*)		host_makefile_frag=config/mh-sysv; files=sysdep-irix.h;;
-  i[345]86-ncr-sysv4*)	host_makefile_frag=config/mh-ncr3000 ;;
+  i[3456]86-ncr-sysv4*)	host_makefile_frag=config/mh-ncr3000 ;;
 # Using sysdep-norm.h is harmful because termio.h defines VWERASE even though
 # c_cc is too small for it (VWERASE is for termios).
 # The problem with _POSIX_SOURCE is said not to be a problem after all.
@@ -25,17 +25,17 @@
   m88*-harris-cxux7*)	host_makefile_frag=config/mh-sysv4 ; files=sysdep-cxux7.h ;;
   *-*-sysv4*)		host_makefile_frag=config/mh-sysv4 ; files=sysdep-sysv4.h ;;
   *-*-solaris2*)	host_makefile_frag=config/mh-sysv4 ;;
-  i[345]86-*-sco3.2v[45]*)	host_makefile_frag=config/mh-sco4; files=sysdep-sco.h ;;
-  i[345]86-*-sco*)	host_makefile_frag=config/mh-sco; files=sysdep-sco.h ;;
+  i[3456]86-*-sco3.2v[45]*)	host_makefile_frag=config/mh-sco4; files=sysdep-sco.h ;;
+  i[3456]86-*-sco*)	host_makefile_frag=config/mh-sco; files=sysdep-sco.h ;;
 # Don't use this; ISC 4.0 only supports POSIX features if you link with
 # -lcposix.  No thanks.
-#  i[345]86-*-isc*)	host_makefile_frag=config/mh-isc ;;
-  i[345]86-*-isc*)	host_makefile_frag=config/mh-sysv ;;
+#  i[3456]86-*-isc*)	host_makefile_frag=config/mh-isc ;;
+  i[3456]86-*-isc*)	host_makefile_frag=config/mh-sysv ;;
   *-*-go32)		host_makefile_frag=config/mh-go32 ;;
   m68k-apollo-sysv*)	host_makefile_frag=config/mh-apollo68v ;;    
   *-*-sysv*)		host_makefile_frag=config/mh-sysv ;;
   *-*-m88kbcs*)		host_makefile_frag=config/mh-sysv ;;
-  i[345]86-*-linux*)	host_makefile_frag=config/mh-posix ;;
+  i[3456]86-*-linux*)	host_makefile_frag=config/mh-posix ;;
   powerpc-ibm-aix*)	host_makefile_frag=config/mh-sysv; files=sysdep-aix.h ;;
   rs6000-ibm-aix*)	host_makefile_frag=config/mh-sysv; files=sysdep-aix.h ;;
   rs6000-bull-bosx*)	host_makefile_frag=config/mh-sysv; files=sysdep-aix.h ;;
