* gdb.c++/psmang.exp: Doc fix.
[deliverable/binutils-gdb.git] / gdb / dve3900-rom.c
index c76da776d60a306d8f4623fb00aaf10c5c9f28d0..c8834e927956dff6629307a1ca2665b1e0bc34f1 100644 (file)
@@ -1,22 +1,23 @@
 /* Remote debugging interface for Densan DVE-R3900 ROM monitor for
    GDB, the GNU debugger.
 /* Remote debugging interface for Densan DVE-R3900 ROM monitor for
    GDB, the GNU debugger.
-   Copyright 1997 Free Software Foundation, Inc.
+   Copyright 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
 
 
-This file is part of GDB.
+   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 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.
+   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.  */
+   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 "gdbcore.h"
 
 #include "defs.h"
 #include "gdbcore.h"
@@ -27,10 +28,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "command.h"
 #include "gdb_string.h"
 #include <time.h>
 #include "command.h"
 #include "gdb_string.h"
 #include <time.h>
+#include "regcache.h"
 
 /* Type of function passed to bfd_map_over_sections.  */
 
 
 /* Type of function passed to bfd_map_over_sections.  */
 
-typedef void (*section_map_func) PARAMS ((bfd *abfd, asection *sect, PTR obj));
+typedef void (*section_map_func) (bfd * abfd, asection * sect, PTR obj);
 
 /* Packet escape character used by Densan monitor.  */
 
 
 /* Packet escape character used by Densan monitor.  */
 
@@ -43,54 +45,49 @@ typedef void (*section_map_func) PARAMS ((bfd *abfd, asection *sect, PTR obj));
 
 /* External functions.  */
 
 
 /* External functions.  */
 
-extern void report_transfer_performance PARAMS ((unsigned long,
-                                                time_t, time_t));
+extern void report_transfer_performance (unsigned long, time_t, time_t);
 
 /* Certain registers are "bitmapped", in that the monitor can only display
    them or let the user modify them as a series of named bitfields.
    This structure describes a field in a bitmapped register.  */
 
 struct bit_field
 
 /* Certain registers are "bitmapped", in that the monitor can only display
    them or let the user modify them as a series of named bitfields.
    This structure describes a field in a bitmapped register.  */
 
 struct bit_field
-{
-  char *prefix;                /* string appearing before the value */
-  char *suffix;                /* string appearing after the value */
-  char *user_name;     /* name used by human when entering field value */
-  int  length;         /* number of bits in the field */
-  int  start;          /* starting (least significant) bit number of field */
-};
-        
+  {
+    char *prefix;              /* string appearing before the value */
+    char *suffix;              /* string appearing after the value */
+    char *user_name;           /* name used by human when entering field value */
+    int length;                        /* number of bits in the field */
+    int start;                 /* starting (least significant) bit number of field */
+  };
+
 /* Local functions for register manipulation.  */
 
 /* Local functions for register manipulation.  */
 
-static void r3900_supply_register PARAMS ((char *regname, int regnamelen,
-                                          char *val, int vallen));
-static void fetch_bad_vaddr PARAMS ((void));
-static unsigned long fetch_fields PARAMS ((struct bit_field *bf));
-static void fetch_bitmapped_register PARAMS ((int regno,
-                                                  struct bit_field *bf));
-static void r3900_fetch_registers PARAMS ((int regno));
-static void store_bitmapped_register PARAMS ((int regno,
-                                                   struct bit_field *bf));
-static void r3900_store_registers PARAMS ((int regno));
+static void r3900_supply_register (char *regname, int regnamelen,
+                                  char *val, int vallen);
+static void fetch_bad_vaddr (void);
+static unsigned long fetch_fields (struct bit_field *bf);
+static void fetch_bitmapped_register (int regno, struct bit_field *bf);
+static void r3900_fetch_registers (int regno);
+static void store_bitmapped_register (int regno, struct bit_field *bf);
+static void r3900_store_registers (int regno);
 
 /* Local functions for fast binary loading.  */
 
 
 /* Local functions for fast binary loading.  */
 
-static void write_long PARAMS ((char *buf, long n));
-static void write_long_le PARAMS ((char *buf, long n));
-static int  debug_readchar PARAMS ((int hex));
-static void debug_write PARAMS ((unsigned char *buf, int buflen));
-static void ignore_packet PARAMS ((void));
-static void send_packet PARAMS ((char type, unsigned char *buf, int buflen,
-                                int seq));
-static void process_read_request PARAMS ((unsigned char *buf, int buflen));
-static void count_section PARAMS ((bfd *abfd, asection *s,
-                                  unsigned int *section_count));
-static void load_section PARAMS ((bfd *abfd, asection *s,
-                                 unsigned int *data_count));
-static void r3900_load PARAMS ((char *filename, int from_tty));
+static void write_long (char *buf, long n);
+static void write_long_le (char *buf, long n);
+static int debug_readchar (int hex);
+static void debug_write (unsigned char *buf, int buflen);
+static void ignore_packet (void);
+static void send_packet (char type, unsigned char *buf, int buflen, int seq);
+static void process_read_request (unsigned char *buf, int buflen);
+static void count_section (bfd * abfd, asection * s,
+                          unsigned int *section_count);
+static void load_section (bfd * abfd, asection * s, unsigned int *data_count);
+static void r3900_load (char *filename, int from_tty);
 
 /* Miscellaneous local functions.  */
 
 
 /* Miscellaneous local functions.  */
 
-static void r3900_open PARAMS ((char *args, int from_tty));
+static void r3900_open (char *args, int from_tty);
 
 
 /* Pointers to static functions in monitor.c for fetching and storing
 
 
 /* Pointers to static functions in monitor.c for fetching and storing
@@ -99,13 +96,13 @@ static void r3900_open PARAMS ((char *args, int from_tty));
    format, and those that can't be modified at all.  In those cases
    we have to use our own functions to fetch and store their values.  */
 
    format, and those that can't be modified at all.  In those cases
    we have to use our own functions to fetch and store their values.  */
 
-static void (*orig_monitor_fetch_registers) PARAMS ((int regno));
-static void (*orig_monitor_store_registers) PARAMS ((int regno));
+static void (*orig_monitor_fetch_registers) (int regno);
+static void (*orig_monitor_store_registers) (int regno);
 
 /* Pointer to static function in monitor. for loading programs.
    We use this function for loading S-records via the serial link.  */
 
 
 /* Pointer to static function in monitor. for loading programs.
    We use this function for loading S-records via the serial link.  */
 
-static void (*orig_monitor_load) PARAMS ((char *file, int from_tty));
+static void (*orig_monitor_load) (char *file, int from_tty);
 
 /* This flag is set if a fast ethernet download should be used.  */
 
 
 /* This flag is set if a fast ethernet download should be used.  */
 
@@ -116,43 +113,178 @@ static int ethernet = 0;
    different names than GDB does, and don't support all the registers
    either.  */
 
    different names than GDB does, and don't support all the registers
    either.  */
 
-static char *r3900_regnames[NUM_REGS] =
+static char *r3900_regnames[] =
 {
 {
-  "r0",   "r1",   "r2",   "r3",   "r4",   "r5",   "r6",   "r7",
-  "r8",   "r9",   "r10",  "r11",  "r12",  "r13",  "r14",  "r15",
-  "r16",  "r17",  "r18",  "r19",  "r20",  "r21",  "r22",  "r23",
-  "r24",  "r25",  "r26",  "r27",  "r28",  "r29",  "r30",  "r31",
-
-  "S",                 /* PS_REGNUM */
-  "l",         /* LO_REGNUM */
-  "h",         /* HI_REGNUM */
-  "B",         /* BADVADDR_REGNUM */
-  "Pcause",    /* CAUSE_REGNUM */
-  "p"          /* PC_REGNUM */
+  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
+  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
+  "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
+  "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
+
+  "S",                         /* PS_REGNUM */
+  "l",                         /* LO_REGNUM */
+  "h",                         /* HI_REGNUM */
+  "B",                         /* BADVADDR_REGNUM */
+  "Pcause",                    /* CAUSE_REGNUM */
+  "p"                          /* PC_REGNUM */
 };
 
 
 /* Table of register names produced by monitor's register dump command.  */
 
 static struct reg_entry
 };
 
 
 /* Table of register names produced by monitor's register dump command.  */
 
 static struct reg_entry
+  {
+    char *name;
+    int regno;
+  }
+reg_table[] =
 {
 {
-  char *name;
-  int regno;
-} reg_table[] =
-{
-  { "r0_zero", 0 },  { "r1_at",   1 },  { "r2_v0",   2 },  { "r3_v1",   3 },
-  { "r4_a0",   4 },  { "r5_a1",   5 },  { "r6_a2",   6 },  { "r7_a3",   7 },
-  { "r8_t0",   8 },  { "r9_t1",   9 },  { "r10_t2", 10 },  { "r11_t3", 11 },
-  { "r12_t4", 12 },  { "r13_t5", 13 },  { "r14_t6", 14 },  { "r15_t7", 15 },
-  { "r16_s0", 16 },  { "r17_s1", 17 },  { "r18_s2", 18 },  { "r19_s3", 19 },
-  { "r20_s4", 20 },  { "r21_s5", 21 },  { "r22_s6", 22 },  { "r23_s7", 23 },
-  { "r24_t8", 24 },  { "r25_t9", 25 },  { "r26_k0", 26 },  { "r27_k1", 27 },
-  { "r28_gp", 28 },  { "r29_sp", 29 },  { "r30_fp", 30 },  { "r31_ra", 31 },
-  { "HI",     HI_REGNUM },
-  { "LO",     LO_REGNUM },
-  { "PC",     PC_REGNUM },
-  { "BadV",   BADVADDR_REGNUM },
-  { NULL,     0 }
+  {
+    "r0_zero", 0
+  }
+  ,
+  {
+    "r1_at", 1
+  }
+  ,
+  {
+    "r2_v0", 2
+  }
+  ,
+  {
+    "r3_v1", 3
+  }
+  ,
+  {
+    "r4_a0", 4
+  }
+  ,
+  {
+    "r5_a1", 5
+  }
+  ,
+  {
+    "r6_a2", 6
+  }
+  ,
+  {
+    "r7_a3", 7
+  }
+  ,
+  {
+    "r8_t0", 8
+  }
+  ,
+  {
+    "r9_t1", 9
+  }
+  ,
+  {
+    "r10_t2", 10
+  }
+  ,
+  {
+    "r11_t3", 11
+  }
+  ,
+  {
+    "r12_t4", 12
+  }
+  ,
+  {
+    "r13_t5", 13
+  }
+  ,
+  {
+    "r14_t6", 14
+  }
+  ,
+  {
+    "r15_t7", 15
+  }
+  ,
+  {
+    "r16_s0", 16
+  }
+  ,
+  {
+    "r17_s1", 17
+  }
+  ,
+  {
+    "r18_s2", 18
+  }
+  ,
+  {
+    "r19_s3", 19
+  }
+  ,
+  {
+    "r20_s4", 20
+  }
+  ,
+  {
+    "r21_s5", 21
+  }
+  ,
+  {
+    "r22_s6", 22
+  }
+  ,
+  {
+    "r23_s7", 23
+  }
+  ,
+  {
+    "r24_t8", 24
+  }
+  ,
+  {
+    "r25_t9", 25
+  }
+  ,
+  {
+    "r26_k0", 26
+  }
+  ,
+  {
+    "r27_k1", 27
+  }
+  ,
+  {
+    "r28_gp", 28
+  }
+  ,
+  {
+    "r29_sp", 29
+  }
+  ,
+  {
+    "r30_fp", 30
+  }
+  ,
+  {
+    "r31_ra", 31
+  }
+  ,
+  {
+    "HI", HI_REGNUM
+  }
+  ,
+  {
+    "LO", LO_REGNUM
+  }
+  ,
+  {
+    "PC", PC_REGNUM
+  }
+  ,
+  {
+    "BadV", BADVADDR_REGNUM
+  }
+  ,
+  {
+    NULL, 0
+  }
 };
 
 
 };
 
 
@@ -162,91 +294,87 @@ static struct reg_entry
    cache register that the monitor displays.  Register fields that should
    be ignored have a length of zero in the tables below.  */
 
    cache register that the monitor displays.  Register fields that should
    be ignored have a length of zero in the tables below.  */
 
-static struct bit_field status_fields [] =
+static struct bit_field status_fields[] =
 {
   /* Status register portion */
 {
   /* Status register portion */
-  { "SR[<CU=", " ",    "cu",   4, 28 },
-  { "RE=",     " ",    "re",   1, 25 },
-  { "BEV=",    " ",    "bev",  1, 22 },
-  { "TS=",     " ",    "ts",   1, 21 },
-  { "Nmi=",    " ",    "nmi",  1, 20 },
-  { "INT=",    " ",    "int",  6, 10 },
-  { "SW=",     ">]",   "sw",   2,  8 },
-  { "[<KUO=",  " ",    "kuo",  1,  5 },
-  { "IEO=",    " ",    "ieo",  1,  4 },
-  { "KUP=",    " ",    "kup",  1,  3 },
-  { "IEP=",    " ",    "iep",  1,  2 },
-  { "KUC=",    " ",    "kuc",  1,  1 },
-  { "IEC=",    ">]",   "iec",  1,  0 },
+  {"SR[<CU=", " ", "cu", 4, 28},
+  {"RE=", " ", "re", 1, 25},
+  {"BEV=", " ", "bev", 1, 22},
+  {"TS=", " ", "ts", 1, 21},
+  {"Nmi=", " ", "nmi", 1, 20},
+  {"INT=", " ", "int", 6, 10},
+  {"SW=", ">]", "sw", 2, 8},
+  {"[<KUO=", " ", "kuo", 1, 5},
+  {"IEO=", " ", "ieo", 1, 4},
+  {"KUP=", " ", "kup", 1, 3},
+  {"IEP=", " ", "iep", 1, 2},
+  {"KUC=", " ", "kuc", 1, 1},
+  {"IEC=", ">]", "iec", 1, 0},
 
   /* Cache register portion (dummy for parsing only) */
 
   /* Cache register portion (dummy for parsing only) */
-  { "CR[<IalO="," ",   "ialo", 0, 13 },
-  { "DalO=",   " ",    "dalo", 0, 12 },
-  { "IalP=",   " ",    "ialp", 0, 11 },
-  { "DalP=",   " ",    "dalp", 0, 10 },
-  { "IalC=",   " ",    "ialc", 0,  9 },
-  { "DalC=",   ">] ",  "dalc", 0,  8 },
-
-  { NULL,      NULL,   0,  0 }         /* end of table marker */
+  {"CR[<IalO=", " ", "ialo", 0, 13},
+  {"DalO=", " ", "dalo", 0, 12},
+  {"IalP=", " ", "ialp", 0, 11},
+  {"DalP=", " ", "dalp", 0, 10},
+  {"IalC=", " ", "ialc", 0, 9},
+  {"DalC=", ">] ", "dalc", 0, 8},
+
+  {NULL, NULL, 0, 0}           /* end of table marker */
 };
 
 
 };
 
 
-#if 0  /* FIXME: Enable when we add support for modifying cache register.  */
-static struct bit_field cache_fields [] =
+#if 0                          /* FIXME: Enable when we add support for modifying cache register.  */
+static struct bit_field cache_fields[] =
 {
   /* Status register portion (dummy for parsing only) */
 {
   /* Status register portion (dummy for parsing only) */
-  { "SR[<CU=", " ",    "cu",   0, 28 },
-  { "RE=",     " ",    "re",   0, 25 },
-  { "BEV=",    " ",    "bev",  0, 22 },
-  { "TS=",     " ",    "ts",   0, 21 },
-  { "Nmi=",    " ",    "nmi",  0, 20 },
-  { "INT=",    " ",    "int",  0, 10 },
-  { "SW=",     ">]",   "sw",   0,  8 },
-  { "[<KUO=",  " ",    "kuo",  0,  5 },
-  { "IEO=",    " ",    "ieo",  0,  4 },
-  { "KUP=",    " ",    "kup",  0,  3 },
-  { "IEP=",    " ",    "iep",  0,  2 },
-  { "KUC=",    " ",    "kuc",  0,  1 },
-  { "IEC=",    ">]",   "iec",  0,  0 },
+  {"SR[<CU=", " ", "cu", 0, 28},
+  {"RE=", " ", "re", 0, 25},
+  {"BEV=", " ", "bev", 0, 22},
+  {"TS=", " ", "ts", 0, 21},
+  {"Nmi=", " ", "nmi", 0, 20},
+  {"INT=", " ", "int", 0, 10},
+  {"SW=", ">]", "sw", 0, 8},
+  {"[<KUO=", " ", "kuo", 0, 5},
+  {"IEO=", " ", "ieo", 0, 4},
+  {"KUP=", " ", "kup", 0, 3},
+  {"IEP=", " ", "iep", 0, 2},
+  {"KUC=", " ", "kuc", 0, 1},
+  {"IEC=", ">]", "iec", 0, 0},
 
   /* Cache register portion  */
 
   /* Cache register portion  */
-  { "CR[<IalO="," ",   "ialo", 1, 13 },
-  { "DalO=",   " ",    "dalo", 1, 12 },
-  { "IalP=",   " ",    "ialp", 1, 11 },
-  { "DalP=",   " ",    "dalp", 1, 10 },
-  { "IalC=",   " ",    "ialc", 1,  9 },
-  { "DalC=",   ">] ",  "dalc", 1,  8 },
-
-  { NULL,      NULL,   NULL,   0,  0 }         /* end of table marker */
+  {"CR[<IalO=", " ", "ialo", 1, 13},
+  {"DalO=", " ", "dalo", 1, 12},
+  {"IalP=", " ", "ialp", 1, 11},
+  {"DalP=", " ", "dalp", 1, 10},
+  {"IalC=", " ", "ialc", 1, 9},
+  {"DalC=", ">] ", "dalc", 1, 8},
+
+  {NULL, NULL, NULL, 0, 0}     /* end of table marker */
 };
 #endif
 
 
 };
 #endif
 
 
-static struct bit_field cause_fields[] = 
+static struct bit_field cause_fields[] =
 {
 {
-  { "<BD=",    " ",    "bd",   1, 31 },
-  { "CE=",     " ",    "ce",   2, 28 },
-  { "IP=",     " ",    "ip",   6, 10 },
-  { "SW=",     " ",    "sw",   2,  8 },
-  { "EC=",     ">]" ,  "ec",   5,  2 },
+  {"<BD=", " ", "bd", 1, 31},
+  {"CE=", " ", "ce", 2, 28},
+  {"IP=", " ", "ip", 6, 10},
+  {"SW=", " ", "sw", 2, 8},
+  {"EC=", ">]", "ec", 5, 2},
 
 
-  { NULL,      NULL,   NULL,   0,  0 }         /* end of table marker */
+  {NULL, NULL, NULL, 0, 0}     /* end of table marker */
 };
 
 
 /* The monitor prints register values in the form
 
 };
 
 
 /* The monitor prints register values in the form
 
-       regname = xxxx xxxx
+   regname = xxxx xxxx
 
    We look up the register name in a table, and remove the embedded space in
    the hex value before passing it to monitor_supply_register.  */
 
 static void
 
    We look up the register name in a table, and remove the embedded space in
    the hex value before passing it to monitor_supply_register.  */
 
 static void
-r3900_supply_register (regname, regnamelen, val, vallen)
-     char *regname;
-     int regnamelen;
-     char *val;
-     int vallen;
+r3900_supply_register (char *regname, int regnamelen, char *val, int vallen)
 {
   int regno = -1;
   int i;
 {
   int regno = -1;
   int i;
@@ -285,39 +413,38 @@ r3900_supply_register (regname, regnamelen, val, vallen)
    you modify it.  */
 
 static void
    you modify it.  */
 
 static void
-fetch_bad_vaddr()
+fetch_bad_vaddr (void)
 {
   char buf[20];
 
   monitor_printf ("xB\r");
   monitor_expect ("BadV=", NULL, 0);
 {
   char buf[20];
 
   monitor_printf ("xB\r");
   monitor_expect ("BadV=", NULL, 0);
-  monitor_expect_prompt (buf, sizeof(buf));
+  monitor_expect_prompt (buf, sizeof (buf));
   monitor_supply_register (BADVADDR_REGNUM, buf);
 }
 
   monitor_supply_register (BADVADDR_REGNUM, buf);
 }
 
-    
+
 /* Read a series of bit fields from the monitor, and return their
    combined binary value.  */
 
 static unsigned long
 /* Read a series of bit fields from the monitor, and return their
    combined binary value.  */
 
 static unsigned long
-fetch_fields (bf)
-     struct bit_field *bf;
+fetch_fields (struct bit_field *bf)
 {
   char buf[20];
   unsigned long val = 0;
   unsigned long bits;
 
 {
   char buf[20];
   unsigned long val = 0;
   unsigned long bits;
 
-  for ( ; bf->prefix != NULL; bf++)
+  for (; bf->prefix != NULL; bf++)
     {
     {
-      monitor_expect (bf->prefix, NULL, 0);            /* get prefix */
+      monitor_expect (bf->prefix, NULL, 0);    /* get prefix */
       monitor_expect (bf->suffix, buf, sizeof (buf));  /* hex value, suffix */
       if (bf->length != 0)
       monitor_expect (bf->suffix, buf, sizeof (buf));  /* hex value, suffix */
       if (bf->length != 0)
-        {
+       {
          bits = strtoul (buf, NULL, 16);       /* get field value */
          bits &= ((1 << bf->length) - 1);      /* mask out useless bits */
          bits = strtoul (buf, NULL, 16);       /* get field value */
          bits &= ((1 << bf->length) - 1);      /* mask out useless bits */
-         val |= bits << bf->start;             /* insert into register */
+         val |= bits << bf->start;     /* insert into register */
        }
        }
-         
+
     }
 
   return val;
     }
 
   return val;
@@ -325,14 +452,19 @@ fetch_fields (bf)
 
 
 static void
 
 
 static void
-fetch_bitmapped_register (regno, bf)
-     int regno;
-     struct bit_field *bf;
+fetch_bitmapped_register (int regno, struct bit_field *bf)
 {
   unsigned long val;
   unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
 {
   unsigned long val;
   unsigned char regbuf[MAX_REGISTER_RAW_SIZE];
+  char *regname = NULL;
 
 
-  monitor_printf ("x%s\r", r3900_regnames[regno]);
+  if (regno >= sizeof (r3900_regnames) / sizeof (r3900_regnames[0]))
+    internal_error (__FILE__, __LINE__,
+                    "fetch_bitmapped_register: regno out of bounds");
+  else
+    regname = r3900_regnames[regno];
+
+  monitor_printf ("x%s\r", regname);
   val = fetch_fields (bf);
   monitor_printf (".\r");
   monitor_expect_prompt (NULL, 0);
   val = fetch_fields (bf);
   monitor_printf (".\r");
   monitor_expect_prompt (NULL, 0);
@@ -351,8 +483,7 @@ fetch_bitmapped_register (regno, bf)
    a very unusual fashion by the monitor, and must be handled specially.  */
 
 static void
    a very unusual fashion by the monitor, and must be handled specially.  */
 
 static void
-r3900_fetch_registers (regno)
-     int regno;
+r3900_fetch_registers (int regno)
 {
   switch (regno)
     {
 {
   switch (regno)
     {
@@ -374,29 +505,34 @@ r3900_fetch_registers (regno)
 /* Write the new value of the bitmapped register to the monitor.  */
 
 static void
 /* Write the new value of the bitmapped register to the monitor.  */
 
 static void
-store_bitmapped_register (regno, bf)
-     int regno;
-     struct bit_field *bf;
+store_bitmapped_register (int regno, struct bit_field *bf)
 {
   unsigned long oldval, newval;
 {
   unsigned long oldval, newval;
+  char *regname = NULL;
+
+  if (regno >= sizeof (r3900_regnames) / sizeof (r3900_regnames[0]))
+    internal_error (__FILE__, __LINE__,
+                    "fetch_bitmapped_register: regno out of bounds");
+  else
+    regname = r3900_regnames[regno];
 
   /* Fetch the current value of the register.  */
 
   /* Fetch the current value of the register.  */
-  monitor_printf ("x%s\r", r3900_regnames[regno]);
+  monitor_printf ("x%s\r", regname);
   oldval = fetch_fields (bf);
   newval = read_register (regno);
 
   /* To save time, write just the fields that have changed.  */
   oldval = fetch_fields (bf);
   newval = read_register (regno);
 
   /* To save time, write just the fields that have changed.  */
-  for ( ; bf->prefix != NULL; bf++)
+  for (; bf->prefix != NULL; bf++)
     {
       if (bf->length != 0)
     {
       if (bf->length != 0)
-        {
+       {
          unsigned long oldbits, newbits, mask;
 
          mask = (1 << bf->length) - 1;
          oldbits = (oldval >> bf->start) & mask;
          newbits = (newval >> bf->start) & mask;
          if (oldbits != newbits)
          unsigned long oldbits, newbits, mask;
 
          mask = (1 << bf->length) - 1;
          oldbits = (oldval >> bf->start) & mask;
          newbits = (newval >> bf->start) & mask;
          if (oldbits != newbits)
-           monitor_printf ("%s %x ", bf->user_name, newbits);
+           monitor_printf ("%s %lx ", bf->user_name, newbits);
        }
     }
 
        }
     }
 
@@ -406,8 +542,7 @@ store_bitmapped_register (regno, bf)
 
 
 static void
 
 
 static void
-r3900_store_registers (regno)
-     int regno;
+r3900_store_registers (int regno)
 {
   switch (regno)
     {
 {
   switch (regno)
     {
@@ -426,9 +561,7 @@ r3900_store_registers (regno)
 /* Write a 4-byte integer to the buffer in big-endian order.  */
 
 static void
 /* Write a 4-byte integer to the buffer in big-endian order.  */
 
 static void
-write_long (buf, n)
-     char *buf;
-     long n;
+write_long (char *buf, long n)
 {
   buf[0] = (n >> 24) & 0xff;
   buf[1] = (n >> 16) & 0xff;
 {
   buf[0] = (n >> 24) & 0xff;
   buf[1] = (n >> 16) & 0xff;
@@ -440,9 +573,7 @@ write_long (buf, n)
 /* Write a 4-byte integer to the buffer in little-endian order.  */
 
 static void
 /* Write a 4-byte integer to the buffer in little-endian order.  */
 
 static void
-write_long_le (buf, n)
-     char *buf;
-     long n;
+write_long_le (char *buf, long n)
 {
   buf[0] = n & 0xff;
   buf[1] = (n >> 8) & 0xff;
 {
   buf[0] = n & 0xff;
   buf[1] = (n >> 8) & 0xff;
@@ -456,10 +587,9 @@ write_long_le (buf, n)
    character in hexadecimal; otherwise, print it in ASCII.  */
 
 static int
    character in hexadecimal; otherwise, print it in ASCII.  */
 
 static int
-debug_readchar (hex)
-     int hex;
+debug_readchar (int hex)
 {
 {
-  char buf [10];
+  char buf[10];
   int c = monitor_readchar ();
 
   if (remote_debug > 0)
   int c = monitor_readchar ();
 
   if (remote_debug > 0)
@@ -468,7 +598,7 @@ debug_readchar (hex)
        sprintf (buf, "[%02x]", c & 0xff);
       else if (c == '\0')
        strcpy (buf, "\\0");
        sprintf (buf, "[%02x]", c & 0xff);
       else if (c == '\0')
        strcpy (buf, "\\0");
-      else 
+      else
        {
          buf[0] = c;
          buf[1] = '\0';
        {
          buf[0] = c;
          buf[1] = '\0';
@@ -483,9 +613,7 @@ debug_readchar (hex)
    print the sent buffer in hex.  */
 
 static void
    print the sent buffer in hex.  */
 
 static void
-debug_write (buf, buflen)
-     unsigned char *buf;
-     int buflen;
+debug_write (unsigned char *buf, int buflen)
 {
   char s[10];
 
 {
   char s[10];
 
@@ -507,21 +635,21 @@ debug_write (buf, buflen)
    when its console is in "communications interface" mode.   A packet
    is of this form:
 
    when its console is in "communications interface" mode.   A packet
    is of this form:
 
-      start of packet flag (one byte: 0xdc)
-      packet type (one byte)
-      length (low byte)
-      length (high byte)
-      data (length bytes)
+   start of packet flag (one byte: 0xdc)
+   packet type (one byte)
+   length (low byte)
+   length (high byte)
+   data (length bytes)
 
    The last two bytes of the data field are a checksum, but we don't
    bother to verify it.
 
    The last two bytes of the data field are a checksum, but we don't
    bother to verify it.
-*/
+ */
 
 static void
 
 static void
-ignore_packet ()
+ignore_packet (void)
 {
   int c;
 {
   int c;
-  int len;  
+  int len;
 
   /* Ignore lots of trash (messages about section addresses, for example)
      until we see the start of a packet.  */
 
   /* Ignore lots of trash (messages about section addresses, for example)
      until we see the start of a packet.  */
@@ -535,12 +663,12 @@ ignore_packet ()
     error ("Packet header byte not found; %02x seen instead.", c);
 
   /* Read the packet type and length.  */
     error ("Packet header byte not found; %02x seen instead.", c);
 
   /* Read the packet type and length.  */
-  c = debug_readchar (1);                      /* type */
+  c = debug_readchar (1);      /* type */
 
 
-  c = debug_readchar (1);                      /* low byte of length */
+  c = debug_readchar (1);      /* low byte of length */
   len = c & 0xff;
 
   len = c & 0xff;
 
-  c = debug_readchar (1);                      /* high byte of length */
+  c = debug_readchar (1);      /* high byte of length */
   len += (c & 0xff) << 8;
 
   /* Ignore the rest of the packet.  */
   len += (c & 0xff) << 8;
 
   /* Ignore the rest of the packet.  */
@@ -554,13 +682,10 @@ ignore_packet ()
    The 'p' packet is a special case.  This is a packet we send
    in response to a read ('r') packet from the monitor.  This function
    appends a one-byte sequence number to the data field of such a packet.
    The 'p' packet is a special case.  This is a packet we send
    in response to a read ('r') packet from the monitor.  This function
    appends a one-byte sequence number to the data field of such a packet.
-*/
+ */
 
 static void
 
 static void
-send_packet (type, buf, buflen, seq)
-     char type;
-     unsigned char *buf;
-     int buflen, seq;
+send_packet (char type, unsigned char *buf, int buflen, int seq)
 {
   unsigned char hdr[4];
   int len = buflen;
 {
   unsigned char hdr[4];
   int len = buflen;
@@ -604,7 +729,7 @@ send_packet (type, buf, buflen, seq)
            sum += tmp << 8;
        }
       if (type == 'p')
            sum += tmp << 8;
        }
       if (type == 'p')
-        {
+       {
          if (buflen & 1)
            sum += (seq & 0xff);
          else
          if (buflen & 1)
            sum += (seq & 0xff);
          else
@@ -612,7 +737,7 @@ send_packet (type, buf, buflen, seq)
        }
       sum = (sum & 0xffff) + ((sum >> 16) & 0xffff);
       sum += (sum >> 16) & 1;
        }
       sum = (sum & 0xffff) + ((sum >> 16) & 0xffff);
       sum += (sum >> 16) & 1;
-      sum = ~sum;  
+      sum = ~sum;
 
       hdr[0] = (sum >> 8) & 0xff;
       hdr[1] = sum & 0xff;
 
       hdr[0] = (sum >> 8) & 0xff;
       hdr[1] = sum & 0xff;
@@ -633,9 +758,7 @@ send_packet (type, buf, buflen, seq)
  */
 
 static void
  */
 
 static void
-process_read_request (buf, buflen)
-     unsigned char *buf;
-     int buflen;
+process_read_request (unsigned char *buf, int buflen)
 {
   unsigned char len[4];
   int i, chunk;
 {
   unsigned char len[4];
   int i, chunk;
@@ -671,10 +794,7 @@ process_read_request (buf, buflen)
 /* Count loadable sections (helper function for r3900_load).  */
 
 static void
 /* Count loadable sections (helper function for r3900_load).  */
 
 static void
-count_section (abfd, s, section_count)
-     bfd      *abfd;
-     asection *s;
-     unsigned int *section_count;
+count_section (bfd *abfd, asection *s, unsigned int *section_count)
 {
   if (s->flags & SEC_LOAD && bfd_section_size (abfd, s) != 0)
     (*section_count)++;
 {
   if (s->flags & SEC_LOAD && bfd_section_size (abfd, s) != 0)
     (*section_count)++;
@@ -688,42 +808,39 @@ count_section (abfd, s, section_count)
    packets containing read requests, but rather than respond
    to them in an general way, we expect them to following
    a certain pattern.
    packets containing read requests, but rather than respond
    to them in an general way, we expect them to following
    a certain pattern.
-   
+
    For example, we know that the monitor will start loading by
    issuing an 8-byte read request for the binary file header.
    We know this is coming and ignore the actual contents
    of the read request packet.
    For example, we know that the monitor will start loading by
    issuing an 8-byte read request for the binary file header.
    We know this is coming and ignore the actual contents
    of the read request packet.
-*/
+ */
 
 static void
 
 static void
-load_section (abfd, s, data_count)
-     bfd      *abfd;
-     asection *s;
-     unsigned int *data_count;
+load_section (bfd *abfd, asection *s, unsigned int *data_count)
 {
   if (s->flags & SEC_LOAD)
     {
       bfd_size_type section_size = bfd_section_size (abfd, s);
 {
   if (s->flags & SEC_LOAD)
     {
       bfd_size_type section_size = bfd_section_size (abfd, s);
-      bfd_vma       section_base = bfd_section_lma  (abfd, s);
+      bfd_vma section_base = bfd_section_lma (abfd, s);
       unsigned char *buffer;
       unsigned char header[8];
 
       /* Don't output zero-length sections.  */
       if (section_size == 0)
       unsigned char *buffer;
       unsigned char header[8];
 
       /* Don't output zero-length sections.  */
       if (section_size == 0)
-        return;
+       return;
       if (data_count)
        *data_count += section_size;
 
       /* Print some fluff about the section being loaded.  */
       printf_filtered ("Loading section %s, size 0x%lx lma ",
       if (data_count)
        *data_count += section_size;
 
       /* Print some fluff about the section being loaded.  */
       printf_filtered ("Loading section %s, size 0x%lx lma ",
-                      bfd_section_name (abfd, s), (long)section_size);
+                      bfd_section_name (abfd, s), (long) section_size);
       print_address_numeric (section_base, 1, gdb_stdout);
       printf_filtered ("\n");
       gdb_flush (gdb_stdout);
 
       /* Write the section header (location and size).  */
       print_address_numeric (section_base, 1, gdb_stdout);
       printf_filtered ("\n");
       gdb_flush (gdb_stdout);
 
       /* Write the section header (location and size).  */
-      write_long (&header[0], (long)section_base);
-      write_long (&header[4], (long)section_size);
+      write_long (&header[0], (long) section_base);
+      write_long (&header[4], (long) section_size);
       process_read_request (header, sizeof (header));
 
       /* Read the section contents into a buffer, write it out,
       process_read_request (header, sizeof (header));
 
       /* Read the section contents into a buffer, write it out,
@@ -731,8 +848,8 @@ load_section (abfd, s, data_count)
       buffer = (unsigned char *) xmalloc (section_size);
       bfd_get_section_contents (abfd, s, buffer, 0, section_size);
       process_read_request (buffer, section_size);
       buffer = (unsigned char *) xmalloc (section_size);
       bfd_get_section_contents (abfd, s, buffer, 0, section_size);
       process_read_request (buffer, section_size);
-      free (buffer);
-  }
+      xfree (buffer);
+    }
 }
 
 
 }
 
 
@@ -740,12 +857,12 @@ load_section (abfd, s, data_count)
    we can use the "Rm" command to do a fast binary load.  The format
    of the download data is:
 
    we can use the "Rm" command to do a fast binary load.  The format
    of the download data is:
 
-       number of sections (4 bytes)
-       starting address (4 bytes)
-       repeat for each section:
-           location address (4 bytes)
-           section size (4 bytes)
-           binary data
+   number of sections (4 bytes)
+   starting address (4 bytes)
+   repeat for each section:
+   location address (4 bytes)
+   section size (4 bytes)
+   binary data
 
    The 4-byte fields are all in big-endian order.
 
 
    The 4-byte fields are all in big-endian order.
 
@@ -755,9 +872,7 @@ load_section (abfd, s, data_count)
  */
 
 static void
  */
 
 static void
-r3900_load (filename, from_tty) 
-    char *filename;
-    int from_tty;
+r3900_load (char *filename, int from_tty)
 {
   bfd *abfd;
   unsigned int data_count = 0;
 {
   bfd *abfd;
   unsigned int data_count = 0;
@@ -794,13 +909,13 @@ r3900_load (filename, from_tty)
   monitor_printf ("Rm\r");
   ignore_packet ();
   send_packet ('a', "", 0, 0);
   monitor_printf ("Rm\r");
   ignore_packet ();
   send_packet ('a', "", 0, 0);
-  
+
   /* Output the fast load header (number of sections and starting address).  */
   bfd_map_over_sections ((bfd *) abfd, (section_map_func) count_section,
                         &section_count);
   /* Output the fast load header (number of sections and starting address).  */
   bfd_map_over_sections ((bfd *) abfd, (section_map_func) count_section,
                         &section_count);
-  write_long (&buffer[0], (long)section_count);
+  write_long (&buffer[0], (long) section_count);
   if (exec_bfd)
   if (exec_bfd)
-    write_long (&buffer[4], (long)bfd_get_start_address (exec_bfd));
+    write_long (&buffer[4], (long) bfd_get_start_address (exec_bfd));
   else
     write_long (&buffer[4], 0);
   process_read_request (buffer, sizeof (buffer));
   else
     write_long (&buffer[4], 0);
   process_read_request (buffer, sizeof (buffer));
@@ -819,14 +934,14 @@ r3900_load (filename, from_tty)
   monitor_expect_prompt (NULL, 0);
 
   /* Print start address and download performance information.  */
   monitor_expect_prompt (NULL, 0);
 
   /* Print start address and download performance information.  */
-  printf_filtered ("Start address 0x%lx\n", (long)bfd_get_start_address (abfd));
+  printf_filtered ("Start address 0x%lx\n", (long) bfd_get_start_address (abfd));
   report_transfer_performance (data_count, start_time, end_time);
 
   /* Finally, make the PC point at the start address */
   if (exec_bfd)
     write_pc (bfd_get_start_address (exec_bfd));
 
   report_transfer_performance (data_count, start_time, end_time);
 
   /* Finally, make the PC point at the start address */
   if (exec_bfd)
     write_pc (bfd_get_start_address (exec_bfd));
 
-  inferior_pid = 0;             /* No process now */
+  inferior_ptid = null_ptid;           /* No process now */
 
   /* This is necessary because many things were based on the PC at the
      time that we attached to the monitor, which is no longer valid
 
   /* This is necessary because many things were based on the PC at the
      time that we attached to the monitor, which is no longer valid
@@ -839,27 +954,27 @@ r3900_load (filename, from_tty)
 
 
 /* Commands to send to the monitor when first connecting:
 
 
 /* Commands to send to the monitor when first connecting:
-    * The bare carriage return forces a prompt from the monitor
-      (monitor doesn't prompt immediately after a reset).
-    * The "vconsx" switches the monitor back to interactive mode
-      in case an aborted download had left it in packet mode.
-    * The "Xtr" command causes subsequent "t" (trace) commands to display
-      the general registers only.
-    * The "Xxr" command does the same thing for the "x" (examine
-      registers) command.
-    * The "bx" command clears all breakpoints.
-*/
-
-static char *r3900_inits[] = {"\r", "vconsx\r", "Xtr\r", "Xxr\r", "bx\r", NULL};
-static char *dummy_inits[] = { NULL };
+   * The bare carriage return forces a prompt from the monitor
+   (monitor doesn't prompt immediately after a reset).
+   * The "vconsx" switches the monitor back to interactive mode
+   in case an aborted download had left it in packet mode.
+   * The "Xtr" command causes subsequent "t" (trace) commands to display
+   the general registers only.
+   * The "Xxr" command does the same thing for the "x" (examine
+   registers) command.
+   * The "bx" command clears all breakpoints.
+ */
+
+static char *r3900_inits[] =
+{"\r", "vconsx\r", "Xtr\r", "Xxr\r", "bx\r", NULL};
+static char *dummy_inits[] =
+{NULL};
 
 static struct target_ops r3900_ops;
 static struct monitor_ops r3900_cmds;
 
 static void
 
 static struct target_ops r3900_ops;
 static struct monitor_ops r3900_cmds;
 
 static void
-r3900_open (args, from_tty)
-     char *args;
-     int from_tty;
+r3900_open (char *args, int from_tty)
 {
   char buf[64];
   int i;
 {
   char buf[64];
   int i;
@@ -883,49 +998,49 @@ r3900_open (args, from_tty)
   ethernet = 0;
   monitor_printf ("v\r");
   if (monitor_expect ("console device :", NULL, 0) != -1)
   ethernet = 0;
   monitor_printf ("v\r");
   if (monitor_expect ("console device :", NULL, 0) != -1)
-      if (monitor_expect ("\n", buf, sizeof (buf)) != -1)
-       if (strstr (buf, "ethernet") != NULL)
-         ethernet = 1;
+    if (monitor_expect ("\n", buf, sizeof (buf)) != -1)
+      if (strstr (buf, "ethernet") != NULL)
+       ethernet = 1;
   monitor_expect_prompt (NULL, 0);
 }
 
 void
   monitor_expect_prompt (NULL, 0);
 }
 
 void
-_initialize_r3900_rom ()
+_initialize_r3900_rom (void)
 {
   r3900_cmds.flags = MO_NO_ECHO_ON_OPEN |
 {
   r3900_cmds.flags = MO_NO_ECHO_ON_OPEN |
-                    MO_ADDR_BITS_REMOVE |
-                    MO_CLR_BREAK_USES_ADDR |
-                    MO_GETMEM_READ_SINGLE |
-                    MO_PRINT_PROGRAM_OUTPUT;
+    MO_ADDR_BITS_REMOVE |
+    MO_CLR_BREAK_USES_ADDR |
+    MO_GETMEM_READ_SINGLE |
+    MO_PRINT_PROGRAM_OUTPUT;
 
   r3900_cmds.init = dummy_inits;
   r3900_cmds.cont = "g\r";
   r3900_cmds.step = "t\r";
 
   r3900_cmds.init = dummy_inits;
   r3900_cmds.cont = "g\r";
   r3900_cmds.step = "t\r";
-  r3900_cmds.set_break = "b %A\r";             /* COREADDR */
-  r3900_cmds.clr_break = "b %A,0\r";           /* COREADDR */
-  r3900_cmds.fill = "fx %A s %x %x\r";         /* COREADDR, len, val */
+  r3900_cmds.set_break = "b %A\r";     /* COREADDR */
+  r3900_cmds.clr_break = "b %A,0\r";   /* COREADDR */
+  r3900_cmds.fill = "fx %A s %x %x\r"; /* COREADDR, len, val */
 
   r3900_cmds.setmem.cmdb = "sx %A %x\r";       /* COREADDR, val */
   r3900_cmds.setmem.cmdw = "sh %A %x\r";       /* COREADDR, val */
   r3900_cmds.setmem.cmdl = "sw %A %x\r";       /* COREADDR, val */
 
 
   r3900_cmds.setmem.cmdb = "sx %A %x\r";       /* COREADDR, val */
   r3900_cmds.setmem.cmdw = "sh %A %x\r";       /* COREADDR, val */
   r3900_cmds.setmem.cmdl = "sw %A %x\r";       /* COREADDR, val */
 
-  r3900_cmds.getmem.cmdb = "sx %A\r";          /* COREADDR */
-  r3900_cmds.getmem.cmdw = "sh %A\r";          /* COREADDR */
-  r3900_cmds.getmem.cmdl = "sw %A\r";          /* COREADDR */
+  r3900_cmds.getmem.cmdb = "sx %A\r";  /* COREADDR */
+  r3900_cmds.getmem.cmdw = "sh %A\r";  /* COREADDR */
+  r3900_cmds.getmem.cmdl = "sw %A\r";  /* COREADDR */
   r3900_cmds.getmem.resp_delim = " : ";
   r3900_cmds.getmem.term = " ";
   r3900_cmds.getmem.term_cmd = ".\r";
 
   r3900_cmds.getmem.resp_delim = " : ";
   r3900_cmds.getmem.term = " ";
   r3900_cmds.getmem.term_cmd = ".\r";
 
-  r3900_cmds.setreg.cmd = "x%s %x\r";          /* regname, val */
+  r3900_cmds.setreg.cmd = "x%s %x\r";  /* regname, val */
 
 
-  r3900_cmds.getreg.cmd = "x%s\r";             /* regname */
+  r3900_cmds.getreg.cmd = "x%s\r";     /* regname */
   r3900_cmds.getreg.resp_delim = "=";
   r3900_cmds.getreg.term = " ";
   r3900_cmds.getreg.term_cmd = ".\r";
 
   r3900_cmds.dump_registers = "x\r";
   r3900_cmds.register_pattern =
   r3900_cmds.getreg.resp_delim = "=";
   r3900_cmds.getreg.term = " ";
   r3900_cmds.getreg.term_cmd = ".\r";
 
   r3900_cmds.dump_registers = "x\r";
   r3900_cmds.register_pattern =
-       "\\([a-zA-Z0-9_]+\\) *=\\([0-9a-f]+ [0-9a-f]+\\b\\)";
+    "\\([a-zA-Z0-9_]+\\) *=\\([0-9a-f]+ [0-9a-f]+\\b\\)";
   r3900_cmds.supply_register = r3900_supply_register;
   /* S-record download, via "keyboard port".  */
   r3900_cmds.load = "r0\r";
   r3900_cmds.supply_register = r3900_supply_register;
   /* S-record download, via "keyboard port".  */
   r3900_cmds.load = "r0\r";
This page took 0.039018 seconds and 4 git commands to generate.