]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/remote-mips.c
Add new infrun.h header.
[thirdparty/binutils-gdb.git] / gdb / remote-mips.c
index babbf19407dc780368dc6d1274a4f99f57883c67..7f0d957471cdbc588aa8053e3a11fa6605679c70 100644 (file)
@@ -1,6 +1,6 @@
 /* Remote debugging interface for MIPS remote debugging protocol.
 
-   Copyright (C) 1993-2004, 2006-2012 Free Software Foundation, Inc.
+   Copyright (C) 1993-2014 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.  Written by Ian Lance Taylor
    <ian@cygnus.com>.
@@ -22,6 +22,7 @@
 
 #include "defs.h"
 #include "inferior.h"
+#include "infrun.h"
 #include "bfd.h"
 #include "symfile.h"
 #include "gdbcmd.h"
 #include "serial.h"
 #include "target.h"
 #include "exceptions.h"
-#include "gdb_string.h"
-#include "gdb_stat.h"
+#include <string.h>
+#include <sys/stat.h>
 #include "gdb_usleep.h"
 #include "regcache.h"
 #include <ctype.h>
 #include "mips-tdep.h"
 #include "gdbthread.h"
+#include "gdb_bfd.h"
 \f
 
 /* Breakpoint types.  Values 0, 1, and 2 must agree with the watch
@@ -62,7 +64,7 @@ static int mips_receive_trailer (unsigned char *trlr, int *pgarbage,
                                 int *pch, int timeout);
 
 static int mips_cksum (const unsigned char *hdr,
-                      const unsigned char *data, int len);
+                      const char *data, int len);
 
 static void mips_send_packet (const char *s, int get_ack);
 
@@ -83,36 +85,36 @@ static void ddb_open (char *name, int from_tty);
 
 static void lsi_open (char *name, int from_tty);
 
-static void mips_close (int quitting);
-
-static void mips_detach (struct target_ops *ops, char *args, int from_tty);
+static void mips_close (struct target_ops *self);
 
 static int mips_map_regno (struct gdbarch *, int);
 
 static void mips_set_register (int regno, ULONGEST value);
 
-static void mips_prepare_to_store (struct regcache *regcache);
+static void mips_prepare_to_store (struct target_ops *self,
+                                  struct regcache *regcache);
 
 static int mips_fetch_word (CORE_ADDR addr, unsigned int *valp);
 
 static int mips_store_word (CORE_ADDR addr, unsigned int value,
                            int *old_contents);
 
-static int mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
-                            int write, 
-                            struct mem_attrib *attrib,
-                            struct target_ops *target);
+static enum target_xfer_status mips_xfer_memory (gdb_byte *readbuf,
+                                                const gdb_byte *writebuf,
+                                                ULONGEST memaddr,
+                                                ULONGEST len,
+                                                ULONGEST *xfered_len);
 
 static void mips_files_info (struct target_ops *ignore);
 
 static void mips_mourn_inferior (struct target_ops *ops);
 
-static int pmon_makeb64 (unsigned long v, char *p, int n, int *chksum);
+static int pmon_makeb64 (unsigned long v, char *p, int n, unsigned int *chksum);
 
-static int pmon_zeroset (int recsize, char **buff, int *amount,
+static int pmon_zeroset (int recsize, char **buff, unsigned int *amount,
                         unsigned int *chksum);
 
-static int pmon_checkset (int recsize, char **buff, int *value);
+static int pmon_checkset (int recsize, char **buff, unsigned int *value);
 
 static void pmon_make_fastrec (char **outbuf, unsigned char *inbuf,
                               int *inptr, int inamount, int *recsize,
@@ -128,7 +130,7 @@ static void pmon_download (char *buffer, int length);
 
 static void pmon_load_fast (char *file);
 
-static void mips_load (char *file, int from_tty);
+static void mips_load (struct target_ops *self, char *file, int from_tty);
 
 static int mips_make_srec (char *buffer, int type, CORE_ADDR memaddr,
                           unsigned char *myaddr, int len);
@@ -487,17 +489,11 @@ static void ATTRIBUTE_NORETURN
 mips_error (char *string,...)
 {
   va_list args;
-
-  va_start (args, string);
+  char *fmt;
 
   target_terminal_ours ();
   wrap_here ("");              /* Force out any buffered output.  */
   gdb_flush (gdb_stdout);
-  if (error_pre_print)
-    fputs_filtered (error_pre_print, gdb_stderr);
-  vfprintf_filtered (gdb_stderr, string, args);
-  fprintf_filtered (gdb_stderr, "\n");
-  va_end (args);
   gdb_flush (gdb_stderr);
 
   /* Clean up in such a way that mips_close won't try to talk to the
@@ -505,11 +501,16 @@ mips_error (char *string,...)
      it).  */
   close_ports ();
 
-  printf_unfiltered ("Ending remote MIPS debugging.\n");
   if (!ptid_equal (inferior_ptid, null_ptid))
     target_mourn_inferior ();
 
-  deprecated_throw_reason (RETURN_ERROR);
+  fmt = concat (_("Ending remote MIPS debugging: "),
+               string, (char *) NULL);
+  make_cleanup (xfree, fmt);
+
+  va_start (args, string);
+  throw_verror (TARGET_CLOSE_ERROR, fmt, args);
+  va_end (args);
 }
 
 /* putc_readable - print a character, displaying non-printable chars in
@@ -587,6 +588,7 @@ mips_expect_timeout (const char *string, int timeout)
     }
 
   immediate_quit++;
+  QUIT;
   while (1)
     {
       int c;
@@ -822,12 +824,13 @@ mips_receive_trailer (unsigned char *trlr, int *pgarbage,
 }
 
 /* Get the checksum of a packet.  HDR points to the packet header.
-   DATA points to the packet data.  LEN is the length of DATA.  */
+   DATASTR points to the packet data.  LEN is the length of DATASTR.  */
 
 static int
-mips_cksum (const unsigned char *hdr, const unsigned char *data, int len)
+mips_cksum (const unsigned char *hdr, const char *datastr, int len)
 {
   const unsigned char *p;
+  const unsigned char *data = (const unsigned char *) datastr;
   int c;
   int cksum;
 
@@ -870,7 +873,7 @@ mips_send_packet (const char *s, int get_ack)
 
   memcpy (packet + HDR_LENGTH, s, len);
 
-  cksum = mips_cksum (packet, packet + HDR_LENGTH, len);
+  cksum = mips_cksum (packet, (char *) packet + HDR_LENGTH, len);
   packet[HDR_LENGTH + len + TRLR_INDX_CSUM1] = TRLR_SET_CSUM1 (cksum);
   packet[HDR_LENGTH + len + TRLR_INDX_CSUM2] = TRLR_SET_CSUM2 (cksum);
   packet[HDR_LENGTH + len + TRLR_INDX_CSUM3] = TRLR_SET_CSUM3 (cksum);
@@ -974,8 +977,7 @@ mips_send_packet (const char *s, int get_ack)
 
          /* If the checksum does not match the trailer checksum, this
             is a bad packet; ignore it.  */
-         if (mips_cksum (hdr, (unsigned char *) NULL, 0)
-             != TRLR_GET_CKSUM (trlr))
+         if (mips_cksum (hdr, NULL, 0) != TRLR_GET_CKSUM (trlr))
            continue;
 
          if (remote_debug > 0)
@@ -1140,7 +1142,7 @@ mips_receive_packet (char *buff, int throw_error, int timeout)
       ack[HDR_INDX_LEN1] = HDR_SET_LEN1 (0, 0, mips_receive_seq);
       ack[HDR_INDX_SEQ] = HDR_SET_SEQ (0, 0, mips_receive_seq);
 
-      cksum = mips_cksum (ack, (unsigned char *) NULL, 0);
+      cksum = mips_cksum (ack, NULL, 0);
 
       ack[HDR_LENGTH + TRLR_INDX_CSUM1] = TRLR_SET_CSUM1 (cksum);
       ack[HDR_LENGTH + TRLR_INDX_CSUM2] = TRLR_SET_CSUM2 (cksum);
@@ -1181,7 +1183,7 @@ mips_receive_packet (char *buff, int throw_error, int timeout)
   ack[HDR_INDX_LEN1] = HDR_SET_LEN1 (0, 0, mips_receive_seq);
   ack[HDR_INDX_SEQ] = HDR_SET_SEQ (0, 0, mips_receive_seq);
 
-  cksum = mips_cksum (ack, (unsigned char *) NULL, 0);
+  cksum = mips_cksum (ack, NULL, 0);
 
   ack[HDR_LENGTH + TRLR_INDX_CSUM1] = TRLR_SET_CSUM1 (cksum);
   ack[HDR_LENGTH + TRLR_INDX_CSUM2] = TRLR_SET_CSUM2 (cksum);
@@ -1240,7 +1242,7 @@ mips_request (int cmd,
              int timeout,
              char *buff)
 {
-  int addr_size = gdbarch_addr_bit (target_gdbarch) / 8;
+  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
   char myBuff[DATA_MAXLEN + 1];
   char response_string[17];
   int len;
@@ -1384,13 +1386,19 @@ mips_exit_debug (void)
       mips_request ('x', 0, 0, NULL, mips_receive_wait, NULL);
       mips_need_reply = 0;
       if (!mips_expect (" break!"))
-       return -1;
+       {
+         do_cleanups (old_cleanups);
+         return -1;
+       }
     }
   else
     mips_request ('x', 0, 0, &err, mips_receive_wait, NULL);
 
   if (!mips_expect (mips_monitor_prompt))
-    return -1;
+    {
+      do_cleanups (old_cleanups);
+      return -1;
+    }
 
   do_cleanups (old_cleanups);
 
@@ -1404,7 +1412,7 @@ static void
 mips_initialize (void)
 {
   int err;
-  struct cleanup *old_cleanups = make_cleanup (mips_initialize_cleanups, NULL);
+  struct cleanup *old_cleanups;
   int j;
 
   /* What is this code doing here?  I don't see any way it can happen, and
@@ -1417,6 +1425,8 @@ mips_initialize (void)
       return;
     }
 
+  old_cleanups = make_cleanup (mips_initialize_cleanups, NULL);
+
   mips_wait_flag = 0;
   mips_initializing = 1;
 
@@ -1541,6 +1551,7 @@ common_open (struct target_ops *ops, char *name, int from_tty,
   char *remote_name = 0;
   char *local_name = 0;
   char **argv;
+  struct cleanup *cleanup;
 
   if (name == 0)
     error (_("\
@@ -1556,7 +1567,7 @@ seen from the board via TFTP, specify that name as the third parameter.\n"));
   /* Parse the serial port name, the optional TFTP name, and the
      optional local TFTP name.  */
   argv = gdb_buildargv (name);
-  make_cleanup_freeargv (argv);
+  cleanup = make_cleanup_freeargv (argv);
 
   serial_port_name = xstrdup (argv[0]);
   if (argv[1])                 /* Remote TFTP name specified?  */
@@ -1651,8 +1662,10 @@ seen from the board via TFTP, specify that name as the third parameter.\n"));
   reinit_frame_cache ();
   registers_changed ();
   stop_pc = regcache_read_pc (get_current_regcache ());
-  print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC);
+  print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC, 1);
   xfree (serial_port_name);
+
+  do_cleanups (cleanup);
 }
 
 /* Open a connection to an IDT board.  */
@@ -1661,10 +1674,10 @@ static void
 mips_open (char *name, int from_tty)
 {
   const char *monitor_prompt = NULL;
-  if (gdbarch_bfd_arch_info (target_gdbarch) != NULL
-      && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_mips)
+  if (gdbarch_bfd_arch_info (target_gdbarch ()) != NULL
+      && gdbarch_bfd_arch_info (target_gdbarch ())->arch == bfd_arch_mips)
     {
-    switch (gdbarch_bfd_arch_info (target_gdbarch)->mach)
+    switch (gdbarch_bfd_arch_info (target_gdbarch ())->mach)
       {
       case bfd_mach_mips4100:
       case bfd_mach_mips4300:
@@ -1721,7 +1734,7 @@ lsi_open (char *name, int from_tty)
 /* Close a connection to the remote board.  */
 
 static void
-mips_close (int quitting)
+mips_close (struct target_ops *self)
 {
   if (mips_is_open)
     {
@@ -1737,14 +1750,12 @@ mips_close (int quitting)
 /* Detach from the remote board.  */
 
 static void
-mips_detach (struct target_ops *ops, char *args, int from_tty)
+mips_detach (struct target_ops *ops, const char *args, int from_tty)
 {
   if (args)
     error (_("Argument given to \"detach\" when remotely debugging."));
 
-  pop_target ();
-
-  mips_close (1);
+  unpush_target (ops);
 
   if (from_tty)
     printf_unfiltered ("Ending remote MIPS debugging.\n");
@@ -1792,7 +1803,7 @@ mips_signal_from_protocol (int sig)
 static void
 mips_set_register (int regno, ULONGEST value)
 {
-  char buf[MAX_REGISTER_SIZE];
+  gdb_byte buf[MAX_REGISTER_SIZE];
   struct regcache *regcache = get_current_regcache ();
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
@@ -2056,7 +2067,7 @@ mips_fetch_registers (struct target_ops *ops,
    registers, so this function doesn't have to do anything.  */
 
 static void
-mips_prepare_to_store (struct regcache *regcache)
+mips_prepare_to_store (struct target_ops *self, struct regcache *regcache)
 {
 }
 
@@ -2132,24 +2143,23 @@ mips_store_word (CORE_ADDR addr, unsigned int val, int *old_contents)
   return 0;
 }
 
-/* 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.  Note that protocol gives us the correct value
-   for a longword, since it transfers values in ASCII.  We want the
-   byte values, so we have to swap the longword values.  */
+/* Helper for mips_xfer_partial that handles memory transfers.
+   Arguments are like target_xfer_partial.  Note that the protocol
+   gives us the correct value for a longword, since it transfers
+   values in ASCII.  We want the byte values, so we have to swap the
+   longword values.  */
 
 static int mask_address_p = 1;
 
-static int
-mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
-                 struct mem_attrib *attrib, struct target_ops *target)
+static enum target_xfer_status
+mips_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf,
+                 ULONGEST memaddr, ULONGEST len, ULONGEST *xfered_len)
 {
-  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
   int i;
   CORE_ADDR addr;
   int count;
-  char *buffer;
+  gdb_byte *buffer;
   int status;
 
   /* PMON targets do not cope well with 64 bit addresses.  Mask the
@@ -2164,7 +2174,7 @@ mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
   /* Allocate buffer of that many longwords.  */
   buffer = alloca (count * 4);
 
-  if (write)
+  if (writebuf != NULL)
     {
       /* Fill start and end extra bytes of buffer with existing data.  */
       if (addr != memaddr || len < 4)
@@ -2172,7 +2182,7 @@ mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
          unsigned int val;
 
          if (mips_fetch_word (addr, &val))
-           return 0;
+           return TARGET_XFER_E_IO;
 
          /* Need part of initial word -- fetch it.  */
          store_unsigned_integer (&buffer[0], 4, byte_order, val);
@@ -2185,7 +2195,7 @@ mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
          /* Need part of last word -- fetch it.  FIXME: we do this even
             if we don't need it.  */
          if (mips_fetch_word (addr + (count - 1) * 4, &val))
-           return 0;
+           return TARGET_XFER_E_IO;
 
          store_unsigned_integer (&buffer[(count - 1) * 4],
                                  4, byte_order, val);
@@ -2193,7 +2203,7 @@ mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
 
       /* Copy data to be written over corresponding part of buffer.  */
 
-      memcpy ((char *) buffer + (memaddr & 3), myaddr, len);
+      memcpy ((char *) buffer + (memaddr & 3), writebuf, len);
 
       /* Write the entire buffer.  */
 
@@ -2210,10 +2220,7 @@ mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
              gdb_flush (gdb_stdout);
            }
          if (status)
-           {
-             errno = status;
-             return 0;
-           }
+           return TARGET_XFER_E_IO;
          /* FIXME: Do we want a QUIT here?  */
        }
       if (count >= 256)
@@ -2227,18 +2234,38 @@ mips_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
          unsigned int val;
 
          if (mips_fetch_word (addr, &val))
-           return 0;
+           return TARGET_XFER_E_IO;
 
          store_unsigned_integer (&buffer[i * 4], 4, byte_order, val);
          QUIT;
        }
 
       /* Copy appropriate bytes out of the buffer.  */
-      memcpy (myaddr, buffer + (memaddr & 3), len);
+      memcpy (readbuf, buffer + (memaddr & 3), len);
     }
   return len;
 }
 
+/* Target to_xfer_partial implementation.  */
+
+static enum target_xfer_status
+mips_xfer_partial (struct target_ops *ops, enum target_object object,
+                  const char *annex, gdb_byte *readbuf,
+                  const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+                  ULONGEST *xfered_len)
+{
+  switch (object)
+    {
+    case TARGET_OBJECT_MEMORY:
+      return mips_xfer_memory (readbuf, writebuf, offset, len, xfered_len);
+
+    default:
+      return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
+                                           readbuf, writebuf, offset, len,
+                                           xfered_len);
+    }
+}
+
 /* Print info on this target.  */
 
 static void
@@ -2280,8 +2307,7 @@ Give up (and stop debugging it)? ")))
 
          printf_unfiltered ("Ending remote MIPS debugging.\n");
          target_mourn_inferior ();
-
-         deprecated_throw_reason (RETURN_QUIT);
+         quit ();
        }
 
       target_terminal_inferior ();
@@ -2355,27 +2381,27 @@ mips_mourn_inferior (struct target_ops *ops)
    target contents.  */
 
 static int
-mips_insert_breakpoint (struct gdbarch *gdbarch,
+mips_insert_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
                        struct bp_target_info *bp_tgt)
 {
   if (monitor_supports_breakpoints)
     return mips_set_breakpoint (bp_tgt->placed_address, MIPS_INSN32_SIZE,
                                BREAK_FETCH);
   else
-    return memory_insert_breakpoint (gdbarch, bp_tgt);
+    return memory_insert_breakpoint (ops, gdbarch, bp_tgt);
 }
 
 /* Remove a breakpoint.  */
 
 static int
-mips_remove_breakpoint (struct gdbarch *gdbarch,
+mips_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
                        struct bp_target_info *bp_tgt)
 {
   if (monitor_supports_breakpoints)
     return mips_clear_breakpoint (bp_tgt->placed_address, MIPS_INSN32_SIZE,
                                  BREAK_FETCH);
   else
-    return memory_remove_breakpoint (gdbarch, bp_tgt);
+    return memory_remove_breakpoint (ops, gdbarch, bp_tgt);
 }
 
 /* Tell whether this target can support a hardware breakpoint.  CNT
@@ -2383,7 +2409,8 @@ mips_remove_breakpoint (struct gdbarch *gdbarch,
    implements the target_can_use_hardware_watchpoint macro.  */
 
 static int
-mips_can_use_watchpoint (int type, int cnt, int othertype)
+mips_can_use_watchpoint (struct target_ops *self,
+                        int type, int cnt, int othertype)
 {
   return cnt < MAX_LSI_BREAKPOINTS && strcmp (target_shortname, "lsi") == 0;
 }
@@ -2417,7 +2444,8 @@ calculate_mask (CORE_ADDR addr, int len)
    watchpoint.  */
 
 static int
-mips_insert_watchpoint (CORE_ADDR addr, int len, int type,
+mips_insert_watchpoint (struct target_ops *self,
+                       CORE_ADDR addr, int len, int type,
                        struct expression *cond)
 {
   if (mips_set_breakpoint (addr, len, type))
@@ -2429,7 +2457,8 @@ mips_insert_watchpoint (CORE_ADDR addr, int len, int type,
 /* Remove a watchpoint.  */
 
 static int
-mips_remove_watchpoint (CORE_ADDR addr, int len, int type,
+mips_remove_watchpoint (struct target_ops *self,
+                       CORE_ADDR addr, int len, int type,
                        struct expression *cond)
 {
   if (mips_clear_breakpoint (addr, len, type))
@@ -2442,7 +2471,7 @@ mips_remove_watchpoint (CORE_ADDR addr, int len, int type,
    if not.  */
 
 static int
-mips_stopped_by_watchpoint (void)
+mips_stopped_by_watchpoint (struct target_ops *ops)
 {
   return hit_watchpoint;
 }
@@ -2477,7 +2506,7 @@ static int
 mips_check_lsi_error (CORE_ADDR addr, int rerrflg)
 {
   struct lsi_error *err;
-  const char *saddr = paddress (target_gdbarch, addr);
+  const char *saddr = paddress (target_gdbarch (), addr);
 
   if (rerrflg == 0)            /* no error */
     return 0;
@@ -2545,13 +2574,13 @@ mips_common_breakpoint (%s): Unknown error: 0x%x\n",
 static int
 mips_common_breakpoint (int set, CORE_ADDR addr, int len, enum break_type type)
 {
-  int addr_size = gdbarch_addr_bit (target_gdbarch) / 8;
+  int addr_size = gdbarch_addr_bit (target_gdbarch ()) / 8;
   char buf[DATA_MAXLEN + 1];
   char cmd, rcmd;
   int rpid, rerrflg, rresponse, rlen;
   int nfields;
 
-  addr = gdbarch_addr_bits_remove (target_gdbarch, addr);
+  addr = gdbarch_addr_bits_remove (target_gdbarch (), addr);
 
   if (mips_monitor == MON_LSI)
     {
@@ -2579,7 +2608,7 @@ mips_common_breakpoint (int set, CORE_ADDR addr, int len, enum break_type type)
            {
              warning (_("\
 mips_common_breakpoint: Attempt to clear bogus breakpoint at %s"),
-                      paddress (target_gdbarch, addr));
+                      paddress (target_gdbarch (), addr));
              return 1;
            }
 
@@ -2730,7 +2759,7 @@ mips_common_breakpoint: Attempt to clear bogus breakpoint at %s"),
          if (rresponse != 22)  /* invalid argument */
            fprintf_unfiltered (gdb_stderr, "\
 mips_common_breakpoint (%s):  Got error: 0x%x\n",
-                               paddress (target_gdbarch, addr), rresponse);
+                               paddress (target_gdbarch (), addr), rresponse);
          return 1;
        }
     }
@@ -2763,7 +2792,7 @@ send_srec (char *srec, int len, CORE_ADDR addr)
        case 0x15:              /* NACK */
          fprintf_unfiltered (gdb_stderr,
                              "Download got a NACK at byte %s!  Retrying.\n",
-                             paddress (target_gdbarch, addr));
+                             paddress (target_gdbarch (), addr));
          continue;
        default:
          error (_("Download got unexpected ack char: 0x%x, retrying."),
@@ -2779,24 +2808,28 @@ mips_load_srec (char *args)
 {
   bfd *abfd;
   asection *s;
-  char *buffer, srec[1024];
+  char srec[1024];
+  bfd_byte *buffer;
   unsigned int i;
   unsigned int srec_frame = 200;
   int reclen;
+  struct cleanup *cleanup;
   static int hashmark = 1;
 
   buffer = alloca (srec_frame * 2 + 256);
 
-  abfd = bfd_openr (args, 0);
+  abfd = gdb_bfd_open (args, NULL, -1);
   if (!abfd)
     {
       printf_filtered ("Unable to open file %s\n", args);
       return;
     }
 
+  cleanup = make_cleanup_bfd_unref (abfd);
   if (bfd_check_format (abfd, bfd_object) == 0)
     {
       printf_filtered ("File is not an object file\n");
+      do_cleanups (cleanup);
       return;
     }
 
@@ -2850,6 +2883,7 @@ mips_load_srec (char *args)
   send_srec (srec, reclen, abfd->start_address);
 
   serial_flush_input (mips_desc);
+  do_cleanups (cleanup);
 }
 
 /*
@@ -2968,7 +3002,7 @@ static char encoding[] =
    characters written into the buffer.  */
 
 static int
-pmon_makeb64 (unsigned long v, char *p, int n, int *chksum)
+pmon_makeb64 (unsigned long v, char *p, int n, unsigned int *chksum)
 {
   int count = (n / 6);
 
@@ -3016,7 +3050,8 @@ pmon_makeb64 (unsigned long v, char *p, int n, int *chksum)
    escape sequence into the data stream.  */
 
 static int
-pmon_zeroset (int recsize, char **buff, int *amount, unsigned int *chksum)
+pmon_zeroset (int recsize, char **buff,
+             unsigned int *amount, unsigned int *chksum)
 {
   int count;
 
@@ -3042,7 +3077,7 @@ pmon_zeroset (int recsize, char **buff, int *amount, unsigned int *chksum)
    the record elements added by this call.  */
 
 static int
-pmon_checkset (int recsize, char **buff, int *value)
+pmon_checkset (int recsize, char **buff, unsigned int *value)
 {
   int count;
 
@@ -3366,20 +3401,23 @@ pmon_load_fast (char *file)
   int bintotal = 0;
   int final = 0;
   int finished = 0;
+  struct cleanup *cleanup;
 
   buffer = (char *) xmalloc (MAXRECSIZE + 1);
   binbuf = (unsigned char *) xmalloc (BINCHUNK);
 
-  abfd = bfd_openr (file, 0);
+  abfd = gdb_bfd_open (file, NULL, -1);
   if (!abfd)
     {
       printf_filtered ("Unable to open file %s\n", file);
       return;
     }
+  cleanup = make_cleanup_bfd_unref (abfd);
 
   if (bfd_check_format (abfd, bfd_object) == 0)
     {
       printf_filtered ("File is not an object file\n");
+      do_cleanups (cleanup);
       return;
     }
 
@@ -3503,13 +3541,14 @@ pmon_load_fast (char *file)
       pmon_end_download (final, bintotal);
     }
 
+  do_cleanups (cleanup);
   return;
 }
 
 /* mips_load -- download a file.  */
 
 static void
-mips_load (char *file, int from_tty)
+mips_load (struct target_ops *self, char *file, int from_tty)
 {
   struct regcache *regcache;
 
@@ -3602,7 +3641,7 @@ _initialize_remote_mips (void)
   mips_ops.to_fetch_registers = mips_fetch_registers;
   mips_ops.to_store_registers = mips_store_registers;
   mips_ops.to_prepare_to_store = mips_prepare_to_store;
-  mips_ops.deprecated_xfer_memory = mips_xfer_memory;
+  mips_ops.to_xfer_partial = mips_xfer_partial;
   mips_ops.to_files_info = mips_files_info;
   mips_ops.to_insert_breakpoint = mips_insert_breakpoint;
   mips_ops.to_remove_breakpoint = mips_remove_breakpoint;