GDB (API)
/home/stan/gdb/src/gdb/irix5-nat.c
Go to the documentation of this file.
00001 /* Native support for the SGI Iris running IRIX version 5, for GDB.
00002 
00003    Copyright (C) 1988-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
00006    and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
00007    Implemented for Irix 4.x by Garrett A. Wollman.
00008    Modified for Irix 5.x by Ian Lance Taylor.
00009 
00010    This file is part of GDB.
00011 
00012    This program is free software; you can redistribute it and/or modify
00013    it under the terms of the GNU General Public License as published by
00014    the Free Software Foundation; either version 3 of the License, or
00015    (at your option) any later version.
00016 
00017    This program is distributed in the hope that it will be useful,
00018    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020    GNU General Public License for more details.
00021 
00022    You should have received a copy of the GNU General Public License
00023    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00024 
00025 #include "defs.h"
00026 #include "inferior.h"
00027 #include "gdbcore.h"
00028 #include "target.h"
00029 #include "regcache.h"
00030 #include "procfs.h"
00031 
00032 #include "gdb_string.h"
00033 #include <sys/time.h>
00034 #include <sys/procfs.h>
00035 #include <setjmp.h>             /* For JB_XXX.  */
00036 
00037 /* Prototypes for supply_gregset etc.  */
00038 #include "gregset.h"
00039 #include "mips-tdep.h"
00040 
00041 static void fetch_core_registers (struct regcache *, char *,
00042                                   unsigned int, int, CORE_ADDR);
00043 
00044 
00045 /*
00046  * See the comment in m68k-tdep.c regarding the utility of these functions.
00047  *
00048  * These definitions are from the MIPS SVR4 ABI, so they may work for
00049  * any MIPS SVR4 target.
00050  */
00051 
00052 void
00053 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
00054 {
00055   int regi;
00056   const greg_t *regp = &(*gregsetp)[0];
00057   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00058   int gregoff = sizeof (greg_t) - mips_isa_regsize (gdbarch);
00059   static char zerobuf[32] = {0};
00060 
00061   for (regi = 0; regi <= CTX_RA; regi++)
00062     regcache_raw_supply (regcache, regi,
00063                          (const char *) (regp + regi) + gregoff);
00064 
00065   regcache_raw_supply (regcache, mips_regnum (gdbarch)->pc,
00066                        (const char *) (regp + CTX_EPC) + gregoff);
00067   regcache_raw_supply (regcache, mips_regnum (gdbarch)->hi,
00068                        (const char *) (regp + CTX_MDHI) + gregoff);
00069   regcache_raw_supply (regcache, mips_regnum (gdbarch)->lo,
00070                        (const char *) (regp + CTX_MDLO) + gregoff);
00071   regcache_raw_supply (regcache, mips_regnum (gdbarch)->cause,
00072                        (const char *) (regp + CTX_CAUSE) + gregoff);
00073 
00074   /* Fill inaccessible registers with zero.  */
00075   regcache_raw_supply (regcache, mips_regnum (gdbarch)->badvaddr, zerobuf);
00076 }
00077 
00078 void
00079 fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno)
00080 {
00081   int regi, size;
00082   greg_t *regp = &(*gregsetp)[0];
00083   gdb_byte buf[MAX_REGISTER_SIZE];
00084   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00085   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00086 
00087   /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
00088      executable, we have to sign extend the registers to 64 bits before
00089      filling in the gregset structure.  */
00090 
00091   for (regi = 0; regi <= CTX_RA; regi++)
00092     if ((regno == -1) || (regno == regi))
00093       {
00094         size = register_size (gdbarch, regi);
00095         regcache_raw_collect (regcache, regi, buf);
00096         *(regp + regi) = extract_signed_integer (buf, size, byte_order);
00097       }
00098 
00099   if ((regno == -1) || (regno == mips_regnum (gdbarch)->pc))
00100     {
00101       regi = mips_regnum (gdbarch)->pc;
00102       size = register_size (gdbarch, regi);
00103       regcache_raw_collect (regcache, regi, buf);
00104       *(regp + CTX_EPC) = extract_signed_integer (buf, size, byte_order);
00105     }
00106 
00107   if ((regno == -1) || (regno == mips_regnum (gdbarch)->cause))
00108     {
00109       regi = mips_regnum (gdbarch)->cause;
00110       size = register_size (gdbarch, regi);
00111       regcache_raw_collect (regcache, regi, buf);
00112       *(regp + CTX_CAUSE) = extract_signed_integer (buf, size, byte_order);
00113     }
00114 
00115   if ((regno == -1) || (regno == mips_regnum (gdbarch)->hi))
00116     {
00117       regi = mips_regnum (gdbarch)->hi;
00118       size = register_size (gdbarch, regi);
00119       regcache_raw_collect (regcache, regi, buf);
00120       *(regp + CTX_MDHI) = extract_signed_integer (buf, size, byte_order);
00121     }
00122 
00123   if ((regno == -1) || (regno == mips_regnum (gdbarch)->lo))
00124     {
00125       regi = mips_regnum (gdbarch)->lo;
00126       size = register_size (gdbarch, regi);
00127       regcache_raw_collect (regcache, regi, buf);
00128       *(regp + CTX_MDLO) = extract_signed_integer (buf, size, byte_order);
00129     }
00130 }
00131 
00132 /*
00133  * Now we do the same thing for floating-point registers.
00134  * We don't bother to condition on gdbarch_fp0_regnum since any
00135  * reasonable MIPS configuration has an R3010 in it.
00136  *
00137  * Again, see the comments in m68k-tdep.c.
00138  */
00139 
00140 void
00141 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
00142 {
00143   int regi;
00144   static char zerobuf[32] = {0};
00145   char fsrbuf[8];
00146   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00147 
00148   /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs.  */
00149 
00150   for (regi = 0; regi < 32; regi++)
00151     regcache_raw_supply (regcache, gdbarch_fp0_regnum (gdbarch) + regi,
00152                          (const char *) &fpregsetp->__fp_r.__fp_regs[regi]);
00153 
00154   /* We can't supply the FSR register directly to the regcache,
00155      because there is a size issue: On one hand, fpregsetp->fp_csr
00156      is 32bits long, while the regcache expects a 64bits long value.
00157      So we use a buffer of the correct size and copy into it the register
00158      value at the proper location.  */
00159   memset (fsrbuf, 0, 4);
00160   memcpy (fsrbuf + 4, &fpregsetp->__fp_csr, 4);
00161 
00162   regcache_raw_supply (regcache,
00163                        mips_regnum (gdbarch)->fp_control_status, fsrbuf);
00164 
00165   /* FIXME: how can we supply FCRIR?  SGI doesn't tell us.  */
00166   regcache_raw_supply (regcache,
00167                        mips_regnum (gdbarch)->fp_implementation_revision,
00168                        zerobuf);
00169 }
00170 
00171 void
00172 fill_fpregset (const struct regcache *regcache,
00173                fpregset_t *fpregsetp, int regno)
00174 {
00175   int regi;
00176   char *from, *to;
00177   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00178 
00179   /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs.  */
00180 
00181   for (regi = gdbarch_fp0_regnum (gdbarch);
00182        regi < gdbarch_fp0_regnum (gdbarch) + 32; regi++)
00183     {
00184       if ((regno == -1) || (regno == regi))
00185         {
00186           const int fp0_regnum = gdbarch_fp0_regnum (gdbarch);
00187 
00188           to = (char *) &(fpregsetp->__fp_r.__fp_regs[regi - fp0_regnum]);
00189           regcache_raw_collect (regcache, regi, to);
00190         }
00191     }
00192 
00193   if (regno == -1
00194       || regno == mips_regnum (gdbarch)->fp_control_status)
00195     {
00196       char fsrbuf[8];
00197 
00198       /* We can't fill the FSR register directly from the regcache,
00199          because there is a size issue: On one hand, fpregsetp->fp_csr
00200          is 32bits long, while the regcache expects a 64bits long buffer.
00201          So we use a buffer of the correct size and copy the register
00202          value from that buffer.  */
00203       regcache_raw_collect (regcache,
00204                             mips_regnum (gdbarch)->fp_control_status, fsrbuf);
00205 
00206       memcpy (&fpregsetp->__fp_csr, fsrbuf + 4, 4);
00207     }
00208 }
00209 
00210 
00211 /* Provide registers to GDB from a core file.
00212 
00213    CORE_REG_SECT points to an array of bytes, which were obtained from
00214    a core file which BFD thinks might contain register contents. 
00215    CORE_REG_SIZE is its size.
00216 
00217    Normally, WHICH says which register set corelow suspects this is:
00218      0 --- the general-purpose register set
00219      2 --- the floating-point register set
00220    However, for Irix 5, WHICH isn't used.
00221 
00222    REG_ADDR is also unused.  */
00223 
00224 static void
00225 fetch_core_registers (struct regcache *regcache,
00226                       char *core_reg_sect, unsigned core_reg_size,
00227                       int which, CORE_ADDR reg_addr)
00228 {
00229   char *srcp = core_reg_sect;
00230   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00231   int regsize = mips_isa_regsize (gdbarch);
00232   int regno;
00233 
00234   /* If regsize is 8, this is a N32 or N64 core file.
00235      If regsize is 4, this is an O32 core file.  */
00236   if (core_reg_size != regsize * gdbarch_num_regs (gdbarch))
00237     {
00238       warning (_("wrong size gregset struct in core file"));
00239       return;
00240     }
00241 
00242   for (regno = 0; regno < gdbarch_num_regs (gdbarch); regno++)
00243     {
00244       regcache_raw_supply (regcache, regno, srcp);
00245       srcp += regsize;
00246     }
00247 }
00248 
00249 /* Register that we are able to handle irix5 core file formats.
00250    This really is bfd_target_unknown_flavour.  */
00251 
00252 static struct core_fns irix5_core_fns =
00253 {
00254   bfd_target_unknown_flavour,           /* core_flavour */
00255   default_check_format,                 /* check_format */
00256   default_core_sniffer,                 /* core_sniffer */
00257   fetch_core_registers,                 /* core_read_registers */
00258   NULL                                  /* next */
00259 };
00260 
00261 /* Provide a prototype to silence -Wmissing-prototypes.  */
00262 extern initialize_file_ftype _initialize_irix5_nat;
00263 
00264 void
00265 _initialize_irix5_nat (void)
00266 {
00267   struct target_ops *t;
00268 
00269   t = procfs_target ();
00270   procfs_use_watchpoints (t);
00271   add_target (t);
00272 
00273   deprecated_add_core_fns (&irix5_core_fns);
00274 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines