GDB (API)
/home/stan/gdb/src/gdb/mips-linux-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for GNU/Linux on MIPS processors.
00002 
00003    Copyright (C) 2001-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "gdbcore.h"
00022 #include "target.h"
00023 #include "solib-svr4.h"
00024 #include "osabi.h"
00025 #include "mips-tdep.h"
00026 #include "gdb_string.h"
00027 #include "gdb_assert.h"
00028 #include "frame.h"
00029 #include "regcache.h"
00030 #include "trad-frame.h"
00031 #include "tramp-frame.h"
00032 #include "gdbtypes.h"
00033 #include "objfiles.h"
00034 #include "solib.h"
00035 #include "solib-svr4.h"
00036 #include "solist.h"
00037 #include "symtab.h"
00038 #include "target-descriptions.h"
00039 #include "regset.h"
00040 #include "mips-linux-tdep.h"
00041 #include "glibc-tdep.h"
00042 #include "linux-tdep.h"
00043 #include "xml-syscall.h"
00044 #include "gdb_signals.h"
00045 
00046 static struct target_so_ops mips_svr4_so_ops;
00047 
00048 /* This enum represents the signals' numbers on the MIPS
00049    architecture.  It just contains the signal definitions which are
00050    different from the generic implementation.
00051 
00052    It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
00053    from the Linux kernel tree.  */
00054 
00055 enum
00056   {
00057     MIPS_LINUX_SIGEMT = 7,
00058     MIPS_LINUX_SIGBUS = 10,
00059     MIPS_LINUX_SIGSYS = 12,
00060     MIPS_LINUX_SIGUSR1 = 16,
00061     MIPS_LINUX_SIGUSR2 = 17,
00062     MIPS_LINUX_SIGCHLD = 18,
00063     MIPS_LINUX_SIGCLD = MIPS_LINUX_SIGCHLD,
00064     MIPS_LINUX_SIGPWR = 19,
00065     MIPS_LINUX_SIGWINCH = 20,
00066     MIPS_LINUX_SIGURG = 21,
00067     MIPS_LINUX_SIGIO = 22,
00068     MIPS_LINUX_SIGPOLL = MIPS_LINUX_SIGIO,
00069     MIPS_LINUX_SIGSTOP = 23,
00070     MIPS_LINUX_SIGTSTP = 24,
00071     MIPS_LINUX_SIGCONT = 25,
00072     MIPS_LINUX_SIGTTIN = 26,
00073     MIPS_LINUX_SIGTTOU = 27,
00074     MIPS_LINUX_SIGVTALRM = 28,
00075     MIPS_LINUX_SIGPROF = 29,
00076     MIPS_LINUX_SIGXCPU = 30,
00077     MIPS_LINUX_SIGXFSZ = 31,
00078 
00079     MIPS_LINUX_SIGRTMIN = 32,
00080     MIPS_LINUX_SIGRT64 = 64,
00081     MIPS_LINUX_SIGRTMAX = 127,
00082   };
00083 
00084 /* Figure out where the longjmp will land.
00085    We expect the first arg to be a pointer to the jmp_buf structure
00086    from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
00087    at.  The pc is copied into PC.  This routine returns 1 on
00088    success.  */
00089 
00090 #define MIPS_LINUX_JB_ELEMENT_SIZE 4
00091 #define MIPS_LINUX_JB_PC 0
00092 
00093 static int
00094 mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
00095 {
00096   CORE_ADDR jb_addr;
00097   struct gdbarch *gdbarch = get_frame_arch (frame);
00098   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00099   gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
00100 
00101   jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
00102 
00103   if (target_read_memory ((jb_addr
00104                            + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE),
00105                           buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
00106     return 0;
00107 
00108   *pc = extract_unsigned_integer (buf,
00109                                   gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
00110                                   byte_order);
00111 
00112   return 1;
00113 }
00114 
00115 /* Transform the bits comprising a 32-bit register to the right size
00116    for regcache_raw_supply().  This is needed when mips_isa_regsize()
00117    is 8.  */
00118 
00119 static void
00120 supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
00121 {
00122   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00123   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00124   gdb_byte buf[MAX_REGISTER_SIZE];
00125   store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
00126                         extract_signed_integer (addr, 4, byte_order));
00127   regcache_raw_supply (regcache, regnum, buf);
00128 }
00129 
00130 /* Unpack an elf_gregset_t into GDB's register cache.  */
00131 
00132 void
00133 mips_supply_gregset (struct regcache *regcache,
00134                      const mips_elf_gregset_t *gregsetp)
00135 {
00136   int regi;
00137   const mips_elf_greg_t *regp = *gregsetp;
00138   char zerobuf[MAX_REGISTER_SIZE];
00139   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00140 
00141   memset (zerobuf, 0, MAX_REGISTER_SIZE);
00142 
00143   for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
00144     supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
00145 
00146   if (mips_linux_restart_reg_p (gdbarch))
00147     supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);
00148 
00149   supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
00150   supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);
00151 
00152   supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
00153                     regp + EF_CP0_EPC);
00154   supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
00155                     regp + EF_CP0_BADVADDR);
00156   supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
00157   supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
00158                     regp + EF_CP0_CAUSE);
00159 
00160   /* Fill the inaccessible zero register with zero.  */
00161   regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
00162 }
00163 
00164 static void
00165 mips_supply_gregset_wrapper (const struct regset *regset,
00166                              struct regcache *regcache,
00167                              int regnum, const void *gregs, size_t len)
00168 {
00169   gdb_assert (len == sizeof (mips_elf_gregset_t));
00170 
00171   mips_supply_gregset (regcache, (const mips_elf_gregset_t *)gregs);
00172 }
00173 
00174 /* Pack our registers (or one register) into an elf_gregset_t.  */
00175 
00176 void
00177 mips_fill_gregset (const struct regcache *regcache,
00178                    mips_elf_gregset_t *gregsetp, int regno)
00179 {
00180   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00181   int regaddr, regi;
00182   mips_elf_greg_t *regp = *gregsetp;
00183   void *dst;
00184 
00185   if (regno == -1)
00186     {
00187       memset (regp, 0, sizeof (mips_elf_gregset_t));
00188       for (regi = 1; regi < 32; regi++)
00189         mips_fill_gregset (regcache, gregsetp, regi);
00190       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
00191       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
00192       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
00193       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
00194       mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
00195       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
00196       mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
00197       return;
00198    }
00199 
00200   if (regno > 0 && regno < 32)
00201     {
00202       dst = regp + regno + EF_REG0;
00203       regcache_raw_collect (regcache, regno, dst);
00204       return;
00205     }
00206 
00207   if (regno == mips_regnum (gdbarch)->lo)
00208      regaddr = EF_LO;
00209   else if (regno == mips_regnum (gdbarch)->hi)
00210     regaddr = EF_HI;
00211   else if (regno == mips_regnum (gdbarch)->pc)
00212     regaddr = EF_CP0_EPC;
00213   else if (regno == mips_regnum (gdbarch)->badvaddr)
00214     regaddr = EF_CP0_BADVADDR;
00215   else if (regno == MIPS_PS_REGNUM)
00216     regaddr = EF_CP0_STATUS;
00217   else if (regno == mips_regnum (gdbarch)->cause)
00218     regaddr = EF_CP0_CAUSE;
00219   else if (mips_linux_restart_reg_p (gdbarch)
00220            && regno == MIPS_RESTART_REGNUM)
00221     regaddr = EF_REG0;
00222   else
00223     regaddr = -1;
00224 
00225   if (regaddr != -1)
00226     {
00227       dst = regp + regaddr;
00228       regcache_raw_collect (regcache, regno, dst);
00229     }
00230 }
00231 
00232 static void
00233 mips_fill_gregset_wrapper (const struct regset *regset,
00234                            const struct regcache *regcache,
00235                            int regnum, void *gregs, size_t len)
00236 {
00237   gdb_assert (len == sizeof (mips_elf_gregset_t));
00238 
00239   mips_fill_gregset (regcache, (mips_elf_gregset_t *)gregs, regnum);
00240 }
00241 
00242 /* Likewise, unpack an elf_fpregset_t.  */
00243 
00244 void
00245 mips_supply_fpregset (struct regcache *regcache,
00246                       const mips_elf_fpregset_t *fpregsetp)
00247 {
00248   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00249   int regi;
00250   char zerobuf[MAX_REGISTER_SIZE];
00251 
00252   memset (zerobuf, 0, MAX_REGISTER_SIZE);
00253 
00254   for (regi = 0; regi < 32; regi++)
00255     regcache_raw_supply (regcache,
00256                          gdbarch_fp0_regnum (gdbarch) + regi,
00257                          *fpregsetp + regi);
00258 
00259   regcache_raw_supply (regcache,
00260                        mips_regnum (gdbarch)->fp_control_status,
00261                        *fpregsetp + 32);
00262 
00263   /* FIXME: how can we supply FCRIR?  The ABI doesn't tell us.  */
00264   regcache_raw_supply (regcache,
00265                        mips_regnum (gdbarch)->fp_implementation_revision,
00266                        zerobuf);
00267 }
00268 
00269 static void
00270 mips_supply_fpregset_wrapper (const struct regset *regset,
00271                               struct regcache *regcache,
00272                               int regnum, const void *gregs, size_t len)
00273 {
00274   gdb_assert (len == sizeof (mips_elf_fpregset_t));
00275 
00276   mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *)gregs);
00277 }
00278 
00279 /* Likewise, pack one or all floating point registers into an
00280    elf_fpregset_t.  */
00281 
00282 void
00283 mips_fill_fpregset (const struct regcache *regcache,
00284                     mips_elf_fpregset_t *fpregsetp, int regno)
00285 {
00286   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00287   char *to;
00288 
00289   if ((regno >= gdbarch_fp0_regnum (gdbarch))
00290       && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
00291     {
00292       to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
00293       regcache_raw_collect (regcache, regno, to);
00294     }
00295   else if (regno == mips_regnum (gdbarch)->fp_control_status)
00296     {
00297       to = (char *) (*fpregsetp + 32);
00298       regcache_raw_collect (regcache, regno, to);
00299     }
00300   else if (regno == -1)
00301     {
00302       int regi;
00303 
00304       for (regi = 0; regi < 32; regi++)
00305         mips_fill_fpregset (regcache, fpregsetp,
00306                             gdbarch_fp0_regnum (gdbarch) + regi);
00307       mips_fill_fpregset (regcache, fpregsetp,
00308                           mips_regnum (gdbarch)->fp_control_status);
00309     }
00310 }
00311 
00312 static void
00313 mips_fill_fpregset_wrapper (const struct regset *regset,
00314                             const struct regcache *regcache,
00315                             int regnum, void *gregs, size_t len)
00316 {
00317   gdb_assert (len == sizeof (mips_elf_fpregset_t));
00318 
00319   mips_fill_fpregset (regcache, (mips_elf_fpregset_t *)gregs, regnum);
00320 }
00321 
00322 /* Support for 64-bit ABIs.  */
00323 
00324 /* Figure out where the longjmp will land.
00325    We expect the first arg to be a pointer to the jmp_buf structure
00326    from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
00327    at.  The pc is copied into PC.  This routine returns 1 on
00328    success.  */
00329 
00330 /* Details about jmp_buf.  */
00331 
00332 #define MIPS64_LINUX_JB_PC 0
00333 
00334 static int
00335 mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
00336 {
00337   CORE_ADDR jb_addr;
00338   struct gdbarch *gdbarch = get_frame_arch (frame);
00339   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00340   void *buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
00341   int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
00342 
00343   jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
00344 
00345   if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
00346                           buf,
00347                           gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
00348     return 0;
00349 
00350   *pc = extract_unsigned_integer (buf,
00351                                   gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
00352                                   byte_order);
00353 
00354   return 1;
00355 }
00356 
00357 /* Register set support functions.  These operate on standard 64-bit
00358    regsets, but work whether the target is 32-bit or 64-bit.  A 32-bit
00359    target will still use the 64-bit format for PTRACE_GETREGS.  */
00360 
00361 /* Supply a 64-bit register.  */
00362 
00363 static void
00364 supply_64bit_reg (struct regcache *regcache, int regnum,
00365                   const gdb_byte *buf)
00366 {
00367   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00368   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
00369       && register_size (gdbarch, regnum) == 4)
00370     regcache_raw_supply (regcache, regnum, buf + 4);
00371   else
00372     regcache_raw_supply (regcache, regnum, buf);
00373 }
00374 
00375 /* Unpack a 64-bit elf_gregset_t into GDB's register cache.  */
00376 
00377 void
00378 mips64_supply_gregset (struct regcache *regcache,
00379                        const mips64_elf_gregset_t *gregsetp)
00380 {
00381   int regi;
00382   const mips64_elf_greg_t *regp = *gregsetp;
00383   gdb_byte zerobuf[MAX_REGISTER_SIZE];
00384   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00385 
00386   memset (zerobuf, 0, MAX_REGISTER_SIZE);
00387 
00388   for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
00389     supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
00390                       (const gdb_byte *) (regp + regi));
00391 
00392   if (mips_linux_restart_reg_p (gdbarch))
00393     supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
00394                       (const gdb_byte *) (regp + MIPS64_EF_REG0));
00395 
00396   supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
00397                     (const gdb_byte *) (regp + MIPS64_EF_LO));
00398   supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
00399                     (const gdb_byte *) (regp + MIPS64_EF_HI));
00400 
00401   supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
00402                     (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
00403   supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
00404                     (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
00405   supply_64bit_reg (regcache, MIPS_PS_REGNUM,
00406                     (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
00407   supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
00408                     (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
00409 
00410   /* Fill the inaccessible zero register with zero.  */
00411   regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
00412 }
00413 
00414 static void
00415 mips64_supply_gregset_wrapper (const struct regset *regset,
00416                                struct regcache *regcache,
00417                                int regnum, const void *gregs, size_t len)
00418 {
00419   gdb_assert (len == sizeof (mips64_elf_gregset_t));
00420 
00421   mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *)gregs);
00422 }
00423 
00424 /* Pack our registers (or one register) into a 64-bit elf_gregset_t.  */
00425 
00426 void
00427 mips64_fill_gregset (const struct regcache *regcache,
00428                      mips64_elf_gregset_t *gregsetp, int regno)
00429 {
00430   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00431   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00432   int regaddr, regi;
00433   mips64_elf_greg_t *regp = *gregsetp;
00434   void *dst;
00435 
00436   if (regno == -1)
00437     {
00438       memset (regp, 0, sizeof (mips64_elf_gregset_t));
00439       for (regi = 1; regi < 32; regi++)
00440         mips64_fill_gregset (regcache, gregsetp, regi);
00441       mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
00442       mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
00443       mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
00444       mips64_fill_gregset (regcache, gregsetp,
00445                            mips_regnum (gdbarch)->badvaddr);
00446       mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
00447       mips64_fill_gregset (regcache, gregsetp,  mips_regnum (gdbarch)->cause);
00448       mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
00449       return;
00450    }
00451 
00452   if (regno > 0 && regno < 32)
00453     regaddr = regno + MIPS64_EF_REG0;
00454   else if (regno == mips_regnum (gdbarch)->lo)
00455     regaddr = MIPS64_EF_LO;
00456   else if (regno == mips_regnum (gdbarch)->hi)
00457     regaddr = MIPS64_EF_HI;
00458   else if (regno == mips_regnum (gdbarch)->pc)
00459     regaddr = MIPS64_EF_CP0_EPC;
00460   else if (regno == mips_regnum (gdbarch)->badvaddr)
00461     regaddr = MIPS64_EF_CP0_BADVADDR;
00462   else if (regno == MIPS_PS_REGNUM)
00463     regaddr = MIPS64_EF_CP0_STATUS;
00464   else if (regno == mips_regnum (gdbarch)->cause)
00465     regaddr = MIPS64_EF_CP0_CAUSE;
00466   else if (mips_linux_restart_reg_p (gdbarch)
00467            && regno == MIPS_RESTART_REGNUM)
00468     regaddr = MIPS64_EF_REG0;
00469   else
00470     regaddr = -1;
00471 
00472   if (regaddr != -1)
00473     {
00474       gdb_byte buf[MAX_REGISTER_SIZE];
00475       LONGEST val;
00476 
00477       regcache_raw_collect (regcache, regno, buf);
00478       val = extract_signed_integer (buf, register_size (gdbarch, regno),
00479                                     byte_order);
00480       dst = regp + regaddr;
00481       store_signed_integer (dst, 8, byte_order, val);
00482     }
00483 }
00484 
00485 static void
00486 mips64_fill_gregset_wrapper (const struct regset *regset,
00487                              const struct regcache *regcache,
00488                              int regnum, void *gregs, size_t len)
00489 {
00490   gdb_assert (len == sizeof (mips64_elf_gregset_t));
00491 
00492   mips64_fill_gregset (regcache, (mips64_elf_gregset_t *)gregs, regnum);
00493 }
00494 
00495 /* Likewise, unpack an elf_fpregset_t.  */
00496 
00497 void
00498 mips64_supply_fpregset (struct regcache *regcache,
00499                         const mips64_elf_fpregset_t *fpregsetp)
00500 {
00501   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00502   int regi;
00503 
00504   /* See mips_linux_o32_sigframe_init for a description of the
00505      peculiar FP register layout.  */
00506   if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
00507     for (regi = 0; regi < 32; regi++)
00508       {
00509         const gdb_byte *reg_ptr
00510           = (const gdb_byte *) (*fpregsetp + (regi & ~1));
00511         if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
00512           reg_ptr += 4;
00513         regcache_raw_supply (regcache,
00514                              gdbarch_fp0_regnum (gdbarch) + regi,
00515                              reg_ptr);
00516       }
00517   else
00518     for (regi = 0; regi < 32; regi++)
00519       regcache_raw_supply (regcache,
00520                            gdbarch_fp0_regnum (gdbarch) + regi,
00521                            (const char *) (*fpregsetp + regi));
00522 
00523   supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
00524                     (const gdb_byte *) (*fpregsetp + 32));
00525 
00526   /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
00527      include it - but the result of PTRACE_GETFPREGS does.  The best we
00528      can do is to assume that its value is present.  */
00529   supply_32bit_reg (regcache,
00530                     mips_regnum (gdbarch)->fp_implementation_revision,
00531                     (const gdb_byte *) (*fpregsetp + 32) + 4);
00532 }
00533 
00534 static void
00535 mips64_supply_fpregset_wrapper (const struct regset *regset,
00536                                 struct regcache *regcache,
00537                                 int regnum, const void *gregs, size_t len)
00538 {
00539   gdb_assert (len == sizeof (mips64_elf_fpregset_t));
00540 
00541   mips64_supply_fpregset (regcache, (const mips64_elf_fpregset_t *)gregs);
00542 }
00543 
00544 /* Likewise, pack one or all floating point registers into an
00545    elf_fpregset_t.  */
00546 
00547 void
00548 mips64_fill_fpregset (const struct regcache *regcache,
00549                       mips64_elf_fpregset_t *fpregsetp, int regno)
00550 {
00551   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00552   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00553   gdb_byte *to;
00554 
00555   if ((regno >= gdbarch_fp0_regnum (gdbarch))
00556       && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
00557     {
00558       /* See mips_linux_o32_sigframe_init for a description of the
00559          peculiar FP register layout.  */
00560       if (register_size (gdbarch, regno) == 4)
00561         {
00562           int regi = regno - gdbarch_fp0_regnum (gdbarch);
00563 
00564           to = (gdb_byte *) (*fpregsetp + (regi & ~1));
00565           if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
00566             to += 4;
00567           regcache_raw_collect (regcache, regno, to);
00568         }
00569       else
00570         {
00571           to = (gdb_byte *) (*fpregsetp + regno
00572                              - gdbarch_fp0_regnum (gdbarch));
00573           regcache_raw_collect (regcache, regno, to);
00574         }
00575     }
00576   else if (regno == mips_regnum (gdbarch)->fp_control_status)
00577     {
00578       gdb_byte buf[MAX_REGISTER_SIZE];
00579       LONGEST val;
00580 
00581       regcache_raw_collect (regcache, regno, buf);
00582       val = extract_signed_integer (buf, register_size (gdbarch, regno),
00583                                     byte_order);
00584       to = (gdb_byte *) (*fpregsetp + 32);
00585       store_signed_integer (to, 4, byte_order, val);
00586     }
00587   else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
00588     {
00589       gdb_byte buf[MAX_REGISTER_SIZE];
00590       LONGEST val;
00591 
00592       regcache_raw_collect (regcache, regno, buf);
00593       val = extract_signed_integer (buf, register_size (gdbarch, regno),
00594                                     byte_order);
00595       to = (gdb_byte *) (*fpregsetp + 32) + 4;
00596       store_signed_integer (to, 4, byte_order, val);
00597     }
00598   else if (regno == -1)
00599     {
00600       int regi;
00601 
00602       for (regi = 0; regi < 32; regi++)
00603         mips64_fill_fpregset (regcache, fpregsetp,
00604                               gdbarch_fp0_regnum (gdbarch) + regi);
00605       mips64_fill_fpregset (regcache, fpregsetp,
00606                             mips_regnum (gdbarch)->fp_control_status);
00607       mips64_fill_fpregset (regcache, fpregsetp,
00608                             mips_regnum (gdbarch)->fp_implementation_revision);
00609     }
00610 }
00611 
00612 static void
00613 mips64_fill_fpregset_wrapper (const struct regset *regset,
00614                               const struct regcache *regcache,
00615                               int regnum, void *gregs, size_t len)
00616 {
00617   gdb_assert (len == sizeof (mips64_elf_fpregset_t));
00618 
00619   mips64_fill_fpregset (regcache, (mips64_elf_fpregset_t *)gregs, regnum);
00620 }
00621 
00622 static const struct regset *
00623 mips_linux_regset_from_core_section (struct gdbarch *gdbarch,
00624                                      const char *sect_name, size_t sect_size)
00625 {
00626   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00627   mips_elf_gregset_t gregset;
00628   mips_elf_fpregset_t fpregset;
00629   mips64_elf_gregset_t gregset64;
00630   mips64_elf_fpregset_t fpregset64;
00631 
00632   if (strcmp (sect_name, ".reg") == 0)
00633     {
00634       if (sect_size == sizeof (gregset))
00635         {
00636           if (tdep->gregset == NULL)
00637             tdep->gregset = regset_alloc (gdbarch,
00638                                           mips_supply_gregset_wrapper,
00639                                           mips_fill_gregset_wrapper);
00640           return tdep->gregset;
00641         }
00642       else if (sect_size == sizeof (gregset64))
00643         {
00644           if (tdep->gregset64 == NULL)
00645             tdep->gregset64 = regset_alloc (gdbarch,
00646                                             mips64_supply_gregset_wrapper,
00647                                             mips64_fill_gregset_wrapper);
00648           return tdep->gregset64;
00649         }
00650       else
00651         {
00652           warning (_("wrong size gregset struct in core file"));
00653         }
00654     }
00655   else if (strcmp (sect_name, ".reg2") == 0)
00656     {
00657       if (sect_size == sizeof (fpregset))
00658         {
00659           if (tdep->fpregset == NULL)
00660             tdep->fpregset = regset_alloc (gdbarch,
00661                                            mips_supply_fpregset_wrapper,
00662                                            mips_fill_fpregset_wrapper);
00663           return tdep->fpregset;
00664         }
00665       else if (sect_size == sizeof (fpregset64))
00666         {
00667           if (tdep->fpregset64 == NULL)
00668             tdep->fpregset64 = regset_alloc (gdbarch,
00669                                              mips64_supply_fpregset_wrapper,
00670                                              mips64_fill_fpregset_wrapper);
00671           return tdep->fpregset64;
00672         }
00673       else
00674         {
00675           warning (_("wrong size fpregset struct in core file"));
00676         }
00677     }
00678 
00679   return NULL;
00680 }
00681 
00682 static const struct target_desc *
00683 mips_linux_core_read_description (struct gdbarch *gdbarch,
00684                                   struct target_ops *target,
00685                                   bfd *abfd)
00686 {
00687   asection *section = bfd_get_section_by_name (abfd, ".reg");
00688   if (! section)
00689     return NULL;
00690 
00691   switch (bfd_section_size (abfd, section))
00692     {
00693     case sizeof (mips_elf_gregset_t):
00694       return mips_tdesc_gp32;
00695 
00696     case sizeof (mips64_elf_gregset_t):
00697       return mips_tdesc_gp64;
00698 
00699     default:
00700       return NULL;
00701     }
00702 }
00703 
00704 
00705 /* Check the code at PC for a dynamic linker lazy resolution stub.
00706    GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
00707    section uniformly since version 2.15.  If the pc is in that section,
00708    then we are in such a stub.  Before that ".stub" was used in 32-bit
00709    ELF binaries, however we do not bother checking for that since we
00710    have never had and that case should be extremely rare these days.
00711    Instead we pattern-match on the code generated by GNU ld.  They look
00712    like this:
00713 
00714    lw t9,0x8010(gp)
00715    addu t7,ra
00716    jalr t9,ra
00717    addiu t8,zero,INDEX
00718 
00719    (with the appropriate doubleword instructions for N64).  As any lazy
00720    resolution stubs in microMIPS binaries will always be in a
00721    ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
00722 
00723 static int
00724 mips_linux_in_dynsym_stub (CORE_ADDR pc)
00725 {
00726   gdb_byte buf[28], *p;
00727   ULONGEST insn, insn1;
00728   int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64);
00729   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
00730 
00731   if (in_mips_stubs_section (pc))
00732     return 1;
00733 
00734   read_memory (pc - 12, buf, 28);
00735 
00736   if (n64)
00737     {
00738       /* ld t9,0x8010(gp) */
00739       insn1 = 0xdf998010;
00740     }
00741   else
00742     {
00743       /* lw t9,0x8010(gp) */
00744       insn1 = 0x8f998010;
00745     }
00746 
00747   p = buf + 12;
00748   while (p >= buf)
00749     {
00750       insn = extract_unsigned_integer (p, 4, byte_order);
00751       if (insn == insn1)
00752         break;
00753       p -= 4;
00754     }
00755   if (p < buf)
00756     return 0;
00757 
00758   insn = extract_unsigned_integer (p + 4, 4, byte_order);
00759   if (n64)
00760     {
00761       /* daddu t7,ra */
00762       if (insn != 0x03e0782d)
00763         return 0;
00764     }
00765   else
00766     {
00767       /* addu t7,ra */
00768       if (insn != 0x03e07821)
00769         return 0;
00770     }
00771 
00772   insn = extract_unsigned_integer (p + 8, 4, byte_order);
00773   /* jalr t9,ra */
00774   if (insn != 0x0320f809)
00775     return 0;
00776 
00777   insn = extract_unsigned_integer (p + 12, 4, byte_order);
00778   if (n64)
00779     {
00780       /* daddiu t8,zero,0 */
00781       if ((insn & 0xffff0000) != 0x64180000)
00782         return 0;
00783     }
00784   else
00785     {
00786       /* addiu t8,zero,0 */
00787       if ((insn & 0xffff0000) != 0x24180000)
00788         return 0;
00789     }
00790 
00791   return 1;
00792 }
00793 
00794 /* Return non-zero iff PC belongs to the dynamic linker resolution
00795    code, a PLT entry, or a lazy binding stub.  */
00796 
00797 static int
00798 mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
00799 {
00800   /* Check whether PC is in the dynamic linker.  This also checks
00801      whether it is in the .plt section, used by non-PIC executables.  */
00802   if (svr4_in_dynsym_resolve_code (pc))
00803     return 1;
00804 
00805   /* Likewise for the stubs.  They live in the .MIPS.stubs section these
00806      days, so we check if the PC is within, than fall back to a pattern
00807      match.  */
00808   if (mips_linux_in_dynsym_stub (pc))
00809     return 1;
00810 
00811   return 0;
00812 }
00813 
00814 /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
00815    and glibc_skip_solib_resolver in glibc-tdep.c.  The normal glibc
00816    implementation of this triggers at "fixup" from the same objfile as
00817    "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
00818    "__dl_runtime_resolve" directly.  An unresolved lazy binding
00819    stub will point to _dl_runtime_resolve, which will first call
00820    __dl_runtime_resolve, and then pass control to the resolved
00821    function.  */
00822 
00823 static CORE_ADDR
00824 mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
00825 {
00826   struct minimal_symbol *resolver;
00827 
00828   resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
00829 
00830   if (resolver && SYMBOL_VALUE_ADDRESS (resolver) == pc)
00831     return frame_unwind_caller_pc (get_current_frame ());
00832 
00833   return glibc_skip_solib_resolver (gdbarch, pc);
00834 }
00835 
00836 /* Signal trampoline support.  There are four supported layouts for a
00837    signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
00838    n64 rt_sigframe.  We handle them all independently; not the most
00839    efficient way, but simplest.  First, declare all the unwinders.  */
00840 
00841 static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
00842                                           struct frame_info *this_frame,
00843                                           struct trad_frame_cache *this_cache,
00844                                           CORE_ADDR func);
00845 
00846 static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
00847                                              struct frame_info *this_frame,
00848                                              struct trad_frame_cache *this_cache,
00849                                              CORE_ADDR func);
00850 
00851 #define MIPS_NR_LINUX 4000
00852 #define MIPS_NR_N64_LINUX 5000
00853 #define MIPS_NR_N32_LINUX 6000
00854 
00855 #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
00856 #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
00857 #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
00858 #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
00859 
00860 #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
00861 #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
00862 #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
00863 #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
00864 #define MIPS_INST_SYSCALL 0x0000000c
00865 
00866 static const struct tramp_frame mips_linux_o32_sigframe = {
00867   SIGTRAMP_FRAME,
00868   4,
00869   {
00870     { MIPS_INST_LI_V0_SIGRETURN, -1 },
00871     { MIPS_INST_SYSCALL, -1 },
00872     { TRAMP_SENTINEL_INSN, -1 }
00873   },
00874   mips_linux_o32_sigframe_init
00875 };
00876 
00877 static const struct tramp_frame mips_linux_o32_rt_sigframe = {
00878   SIGTRAMP_FRAME,
00879   4,
00880   {
00881     { MIPS_INST_LI_V0_RT_SIGRETURN, -1 },
00882     { MIPS_INST_SYSCALL, -1 },
00883     { TRAMP_SENTINEL_INSN, -1 } },
00884   mips_linux_o32_sigframe_init
00885 };
00886 
00887 static const struct tramp_frame mips_linux_n32_rt_sigframe = {
00888   SIGTRAMP_FRAME,
00889   4,
00890   {
00891     { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 },
00892     { MIPS_INST_SYSCALL, -1 },
00893     { TRAMP_SENTINEL_INSN, -1 }
00894   },
00895   mips_linux_n32n64_sigframe_init
00896 };
00897 
00898 static const struct tramp_frame mips_linux_n64_rt_sigframe = {
00899   SIGTRAMP_FRAME,
00900   4,
00901   {
00902     { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 },
00903     { MIPS_INST_SYSCALL, -1 },
00904     { TRAMP_SENTINEL_INSN, -1 }
00905   },
00906   mips_linux_n32n64_sigframe_init
00907 };
00908 
00909 /* *INDENT-OFF* */
00910 /* The unwinder for o32 signal frames.  The legacy structures look
00911    like this:
00912 
00913    struct sigframe {
00914      u32 sf_ass[4];            [argument save space for o32]
00915      u32 sf_code[2];           [signal trampoline or fill]
00916      struct sigcontext sf_sc;
00917      sigset_t sf_mask;
00918    };
00919 
00920    Pre-2.6.12 sigcontext:
00921 
00922    struct sigcontext {
00923         unsigned int       sc_regmask;          [Unused]
00924         unsigned int       sc_status;
00925         unsigned long long sc_pc;
00926         unsigned long long sc_regs[32];
00927         unsigned long long sc_fpregs[32];
00928         unsigned int       sc_ownedfp;
00929         unsigned int       sc_fpc_csr;
00930         unsigned int       sc_fpc_eir;          [Unused]
00931         unsigned int       sc_used_math;
00932         unsigned int       sc_ssflags;          [Unused]
00933         [Alignment hole of four bytes]
00934         unsigned long long sc_mdhi;
00935         unsigned long long sc_mdlo;
00936 
00937         unsigned int       sc_cause;            [Unused]
00938         unsigned int       sc_badvaddr;         [Unused]
00939 
00940         unsigned long      sc_sigset[4];        [kernel's sigset_t]
00941    };
00942 
00943    Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
00944 
00945    struct sigcontext {
00946         unsigned int       sc_regmask;          [Unused]
00947         unsigned int       sc_status;           [Unused]
00948         unsigned long long sc_pc;
00949         unsigned long long sc_regs[32];
00950         unsigned long long sc_fpregs[32];
00951         unsigned int       sc_acx;
00952         unsigned int       sc_fpc_csr;
00953         unsigned int       sc_fpc_eir;          [Unused]
00954         unsigned int       sc_used_math;
00955         unsigned int       sc_dsp;
00956         [Alignment hole of four bytes]
00957         unsigned long long sc_mdhi;
00958         unsigned long long sc_mdlo;
00959         unsigned long      sc_hi1;
00960         unsigned long      sc_lo1;
00961         unsigned long      sc_hi2;
00962         unsigned long      sc_lo2;
00963         unsigned long      sc_hi3;
00964         unsigned long      sc_lo3;
00965    };
00966 
00967    The RT signal frames look like this:
00968 
00969    struct rt_sigframe {
00970      u32 rs_ass[4];            [argument save space for o32]
00971      u32 rs_code[2]            [signal trampoline or fill]
00972      struct siginfo rs_info;
00973      struct ucontext rs_uc;
00974    };
00975 
00976    struct ucontext {
00977      unsigned long     uc_flags;
00978      struct ucontext  *uc_link;
00979      stack_t           uc_stack;
00980      [Alignment hole of four bytes]
00981      struct sigcontext uc_mcontext;
00982      sigset_t          uc_sigmask;
00983    };  */
00984 /* *INDENT-ON* */
00985 
00986 #define SIGFRAME_SIGCONTEXT_OFFSET   (6 * 4)
00987 
00988 #define RTSIGFRAME_SIGINFO_SIZE      128
00989 #define STACK_T_SIZE                 (3 * 4)
00990 #define UCONTEXT_SIGCONTEXT_OFFSET   (2 * 4 + STACK_T_SIZE + 4)
00991 #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
00992                                       + RTSIGFRAME_SIGINFO_SIZE \
00993                                       + UCONTEXT_SIGCONTEXT_OFFSET)
00994 
00995 #define SIGCONTEXT_PC       (1 * 8)
00996 #define SIGCONTEXT_REGS     (2 * 8)
00997 #define SIGCONTEXT_FPREGS   (34 * 8)
00998 #define SIGCONTEXT_FPCSR    (66 * 8 + 4)
00999 #define SIGCONTEXT_DSPCTL   (68 * 8 + 0)
01000 #define SIGCONTEXT_HI       (69 * 8)
01001 #define SIGCONTEXT_LO       (70 * 8)
01002 #define SIGCONTEXT_CAUSE    (71 * 8 + 0)
01003 #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
01004 #define SIGCONTEXT_HI1      (71 * 8 + 0)
01005 #define SIGCONTEXT_LO1      (71 * 8 + 4)
01006 #define SIGCONTEXT_HI2      (72 * 8 + 0)
01007 #define SIGCONTEXT_LO2      (72 * 8 + 4)
01008 #define SIGCONTEXT_HI3      (73 * 8 + 0)
01009 #define SIGCONTEXT_LO3      (73 * 8 + 4)
01010 
01011 #define SIGCONTEXT_REG_SIZE 8
01012 
01013 static void
01014 mips_linux_o32_sigframe_init (const struct tramp_frame *self,
01015                               struct frame_info *this_frame,
01016                               struct trad_frame_cache *this_cache,
01017                               CORE_ADDR func)
01018 {
01019   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01020   int ireg;
01021   CORE_ADDR frame_sp = get_frame_sp (this_frame);
01022   CORE_ADDR sigcontext_base;
01023   const struct mips_regnum *regs = mips_regnum (gdbarch);
01024   CORE_ADDR regs_base;
01025 
01026   if (self == &mips_linux_o32_sigframe)
01027     sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
01028   else
01029     sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;
01030 
01031   /* I'm not proud of this hack.  Eventually we will have the
01032      infrastructure to indicate the size of saved registers on a
01033      per-frame basis, but right now we don't; the kernel saves eight
01034      bytes but we only want four.  Use regs_base to access any
01035      64-bit fields.  */
01036   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
01037     regs_base = sigcontext_base + 4;
01038   else
01039     regs_base = sigcontext_base;
01040 
01041   if (mips_linux_restart_reg_p (gdbarch))
01042     trad_frame_set_reg_addr (this_cache,
01043                              (MIPS_RESTART_REGNUM
01044                               + gdbarch_num_regs (gdbarch)),
01045                              regs_base + SIGCONTEXT_REGS);
01046 
01047   for (ireg = 1; ireg < 32; ireg++)
01048     trad_frame_set_reg_addr (this_cache,
01049                              (ireg + MIPS_ZERO_REGNUM
01050                               + gdbarch_num_regs (gdbarch)),
01051                              (regs_base + SIGCONTEXT_REGS
01052                               + ireg * SIGCONTEXT_REG_SIZE));
01053 
01054   /* The way that floating point registers are saved, unfortunately,
01055      depends on the architecture the kernel is built for.  For the r3000 and
01056      tx39, four bytes of each register are at the beginning of each of the
01057      32 eight byte slots.  For everything else, the registers are saved
01058      using double precision; only the even-numbered slots are initialized,
01059      and the high bits are the odd-numbered register.  Assume the latter
01060      layout, since we can't tell, and it's much more common.  Which bits are
01061      the "high" bits depends on endianness.  */
01062   for (ireg = 0; ireg < 32; ireg++)
01063     if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
01064       trad_frame_set_reg_addr (this_cache,
01065                                ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
01066                                (sigcontext_base + SIGCONTEXT_FPREGS + 4
01067                                 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
01068     else
01069       trad_frame_set_reg_addr (this_cache,
01070                                ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
01071                                (sigcontext_base + SIGCONTEXT_FPREGS
01072                                 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
01073 
01074   trad_frame_set_reg_addr (this_cache,
01075                            regs->pc + gdbarch_num_regs (gdbarch),
01076                            regs_base + SIGCONTEXT_PC);
01077 
01078   trad_frame_set_reg_addr (this_cache,
01079                            (regs->fp_control_status
01080                             + gdbarch_num_regs (gdbarch)),
01081                            sigcontext_base + SIGCONTEXT_FPCSR);
01082 
01083   if (regs->dspctl != -1)
01084     trad_frame_set_reg_addr (this_cache,
01085                              regs->dspctl + gdbarch_num_regs (gdbarch),
01086                              sigcontext_base + SIGCONTEXT_DSPCTL);
01087 
01088   trad_frame_set_reg_addr (this_cache,
01089                            regs->hi + gdbarch_num_regs (gdbarch),
01090                            regs_base + SIGCONTEXT_HI);
01091   trad_frame_set_reg_addr (this_cache,
01092                            regs->lo + gdbarch_num_regs (gdbarch),
01093                            regs_base + SIGCONTEXT_LO);
01094 
01095   if (regs->dspacc != -1)
01096     {
01097       trad_frame_set_reg_addr (this_cache,
01098                                regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
01099                                sigcontext_base + SIGCONTEXT_HI1);
01100       trad_frame_set_reg_addr (this_cache,
01101                                regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
01102                                sigcontext_base + SIGCONTEXT_LO1);
01103       trad_frame_set_reg_addr (this_cache,
01104                                regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
01105                                sigcontext_base + SIGCONTEXT_HI2);
01106       trad_frame_set_reg_addr (this_cache,
01107                                regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
01108                                sigcontext_base + SIGCONTEXT_LO2);
01109       trad_frame_set_reg_addr (this_cache,
01110                                regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
01111                                sigcontext_base + SIGCONTEXT_HI3);
01112       trad_frame_set_reg_addr (this_cache,
01113                                regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
01114                                sigcontext_base + SIGCONTEXT_LO3);
01115     }
01116   else
01117     {
01118       trad_frame_set_reg_addr (this_cache,
01119                                regs->cause + gdbarch_num_regs (gdbarch),
01120                                sigcontext_base + SIGCONTEXT_CAUSE);
01121       trad_frame_set_reg_addr (this_cache,
01122                                regs->badvaddr + gdbarch_num_regs (gdbarch),
01123                                sigcontext_base + SIGCONTEXT_BADVADDR);
01124     }
01125 
01126   /* Choice of the bottom of the sigframe is somewhat arbitrary.  */
01127   trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
01128 }
01129 
01130 /* *INDENT-OFF* */
01131 /* For N32/N64 things look different.  There is no non-rt signal frame.
01132 
01133   struct rt_sigframe_n32 {
01134     u32 rs_ass[4];                  [ argument save space for o32 ]
01135     u32 rs_code[2];                 [ signal trampoline or fill ]
01136     struct siginfo rs_info;
01137     struct ucontextn32 rs_uc;
01138   };
01139 
01140   struct ucontextn32 {
01141     u32                 uc_flags;
01142     s32                 uc_link;
01143     stack32_t           uc_stack;
01144     struct sigcontext   uc_mcontext;
01145     sigset_t            uc_sigmask;   [ mask last for extensibility ]
01146   };
01147 
01148   struct rt_sigframe {
01149     u32 rs_ass[4];                  [ argument save space for o32 ]
01150     u32 rs_code[2];                 [ signal trampoline ]
01151     struct siginfo rs_info;
01152     struct ucontext rs_uc;
01153   };
01154 
01155   struct ucontext {
01156     unsigned long     uc_flags;
01157     struct ucontext  *uc_link;
01158     stack_t           uc_stack;
01159     struct sigcontext uc_mcontext;
01160     sigset_t          uc_sigmask;   [ mask last for extensibility ]
01161   };
01162 
01163   And the sigcontext is different (this is for both n32 and n64):
01164 
01165   struct sigcontext {
01166     unsigned long long sc_regs[32];
01167     unsigned long long sc_fpregs[32];
01168     unsigned long long sc_mdhi;
01169     unsigned long long sc_hi1;
01170     unsigned long long sc_hi2;
01171     unsigned long long sc_hi3;
01172     unsigned long long sc_mdlo;
01173     unsigned long long sc_lo1;
01174     unsigned long long sc_lo2;
01175     unsigned long long sc_lo3;
01176     unsigned long long sc_pc;
01177     unsigned int       sc_fpc_csr;
01178     unsigned int       sc_used_math;
01179     unsigned int       sc_dsp;
01180     unsigned int       sc_reserved;
01181   };
01182 
01183   That is the post-2.6.12 definition of the 64-bit sigcontext; before
01184   then, there were no hi1-hi3 or lo1-lo3.  Cause and badvaddr were
01185   included too.  */
01186 /* *INDENT-ON* */
01187 
01188 #define N32_STACK_T_SIZE                STACK_T_SIZE
01189 #define N64_STACK_T_SIZE                (2 * 8 + 4)
01190 #define N32_UCONTEXT_SIGCONTEXT_OFFSET  (2 * 4 + N32_STACK_T_SIZE + 4)
01191 #define N64_UCONTEXT_SIGCONTEXT_OFFSET  (2 * 8 + N64_STACK_T_SIZE + 4)
01192 #define N32_SIGFRAME_SIGCONTEXT_OFFSET  (SIGFRAME_SIGCONTEXT_OFFSET \
01193                                          + RTSIGFRAME_SIGINFO_SIZE \
01194                                          + N32_UCONTEXT_SIGCONTEXT_OFFSET)
01195 #define N64_SIGFRAME_SIGCONTEXT_OFFSET  (SIGFRAME_SIGCONTEXT_OFFSET \
01196                                          + RTSIGFRAME_SIGINFO_SIZE \
01197                                          + N64_UCONTEXT_SIGCONTEXT_OFFSET)
01198 
01199 #define N64_SIGCONTEXT_REGS     (0 * 8)
01200 #define N64_SIGCONTEXT_FPREGS   (32 * 8)
01201 #define N64_SIGCONTEXT_HI       (64 * 8)
01202 #define N64_SIGCONTEXT_HI1      (65 * 8)
01203 #define N64_SIGCONTEXT_HI2      (66 * 8)
01204 #define N64_SIGCONTEXT_HI3      (67 * 8)
01205 #define N64_SIGCONTEXT_LO       (68 * 8)
01206 #define N64_SIGCONTEXT_LO1      (69 * 8)
01207 #define N64_SIGCONTEXT_LO2      (70 * 8)
01208 #define N64_SIGCONTEXT_LO3      (71 * 8)
01209 #define N64_SIGCONTEXT_PC       (72 * 8)
01210 #define N64_SIGCONTEXT_FPCSR    (73 * 8 + 0)
01211 #define N64_SIGCONTEXT_DSPCTL   (74 * 8 + 0)
01212 
01213 #define N64_SIGCONTEXT_REG_SIZE 8
01214 
01215 static void
01216 mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
01217                                  struct frame_info *this_frame,
01218                                  struct trad_frame_cache *this_cache,
01219                                  CORE_ADDR func)
01220 {
01221   struct gdbarch *gdbarch = get_frame_arch (this_frame);
01222   int ireg;
01223   CORE_ADDR frame_sp = get_frame_sp (this_frame);
01224   CORE_ADDR sigcontext_base;
01225   const struct mips_regnum *regs = mips_regnum (gdbarch);
01226 
01227   if (self == &mips_linux_n32_rt_sigframe)
01228     sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
01229   else
01230     sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;
01231 
01232   if (mips_linux_restart_reg_p (gdbarch))
01233     trad_frame_set_reg_addr (this_cache,
01234                              (MIPS_RESTART_REGNUM
01235                               + gdbarch_num_regs (gdbarch)),
01236                              sigcontext_base + N64_SIGCONTEXT_REGS);
01237 
01238   for (ireg = 1; ireg < 32; ireg++)
01239     trad_frame_set_reg_addr (this_cache,
01240                              (ireg + MIPS_ZERO_REGNUM
01241                               + gdbarch_num_regs (gdbarch)),
01242                              (sigcontext_base + N64_SIGCONTEXT_REGS
01243                               + ireg * N64_SIGCONTEXT_REG_SIZE));
01244 
01245   for (ireg = 0; ireg < 32; ireg++)
01246     trad_frame_set_reg_addr (this_cache,
01247                              ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
01248                              (sigcontext_base + N64_SIGCONTEXT_FPREGS
01249                               + ireg * N64_SIGCONTEXT_REG_SIZE));
01250 
01251   trad_frame_set_reg_addr (this_cache,
01252                            regs->pc + gdbarch_num_regs (gdbarch),
01253                            sigcontext_base + N64_SIGCONTEXT_PC);
01254 
01255   trad_frame_set_reg_addr (this_cache,
01256                            (regs->fp_control_status
01257                             + gdbarch_num_regs (gdbarch)),
01258                            sigcontext_base + N64_SIGCONTEXT_FPCSR);
01259 
01260   trad_frame_set_reg_addr (this_cache,
01261                            regs->hi + gdbarch_num_regs (gdbarch),
01262                            sigcontext_base + N64_SIGCONTEXT_HI);
01263   trad_frame_set_reg_addr (this_cache,
01264                            regs->lo + gdbarch_num_regs (gdbarch),
01265                            sigcontext_base + N64_SIGCONTEXT_LO);
01266 
01267   if (regs->dspacc != -1)
01268     {
01269       trad_frame_set_reg_addr (this_cache,
01270                                regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
01271                                sigcontext_base + N64_SIGCONTEXT_HI1);
01272       trad_frame_set_reg_addr (this_cache,
01273                                regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
01274                                sigcontext_base + N64_SIGCONTEXT_LO1);
01275       trad_frame_set_reg_addr (this_cache,
01276                                regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
01277                                sigcontext_base + N64_SIGCONTEXT_HI2);
01278       trad_frame_set_reg_addr (this_cache,
01279                                regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
01280                                sigcontext_base + N64_SIGCONTEXT_LO2);
01281       trad_frame_set_reg_addr (this_cache,
01282                                regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
01283                                sigcontext_base + N64_SIGCONTEXT_HI3);
01284       trad_frame_set_reg_addr (this_cache,
01285                                regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
01286                                sigcontext_base + N64_SIGCONTEXT_LO3);
01287     }
01288   if (regs->dspctl != -1)
01289     trad_frame_set_reg_addr (this_cache,
01290                              regs->dspctl + gdbarch_num_regs (gdbarch),
01291                              sigcontext_base + N64_SIGCONTEXT_DSPCTL);
01292 
01293   /* Choice of the bottom of the sigframe is somewhat arbitrary.  */
01294   trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
01295 }
01296 
01297 /* Implement the "write_pc" gdbarch method.  */
01298 
01299 static void
01300 mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
01301 {
01302   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01303 
01304   mips_write_pc (regcache, pc);
01305 
01306   /* Clear the syscall restart flag.  */
01307   if (mips_linux_restart_reg_p (gdbarch))
01308     regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
01309 }
01310 
01311 /* Return 1 if MIPS_RESTART_REGNUM is usable.  */
01312 
01313 int
01314 mips_linux_restart_reg_p (struct gdbarch *gdbarch)
01315 {
01316   /* If we do not have a target description with registers, then
01317      MIPS_RESTART_REGNUM will not be included in the register set.  */
01318   if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
01319     return 0;
01320 
01321   /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
01322      either be GPR-sized or missing.  */
01323   return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
01324 }
01325 
01326 /* When FRAME is at a syscall instruction, return the PC of the next
01327    instruction to be executed.  */
01328 
01329 static CORE_ADDR
01330 mips_linux_syscall_next_pc (struct frame_info *frame)
01331 {
01332   CORE_ADDR pc = get_frame_pc (frame);
01333   ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
01334 
01335   /* If we are about to make a sigreturn syscall, use the unwinder to
01336      decode the signal frame.  */
01337   if (v0 == MIPS_NR_sigreturn
01338       || v0 == MIPS_NR_rt_sigreturn
01339       || v0 == MIPS_NR_N64_rt_sigreturn
01340       || v0 == MIPS_NR_N32_rt_sigreturn)
01341     return frame_unwind_caller_pc (get_current_frame ());
01342 
01343   return pc + 4;
01344 }
01345 
01346 /* Return the current system call's number present in the
01347    v0 register.  When the function fails, it returns -1.  */
01348 
01349 static LONGEST
01350 mips_linux_get_syscall_number (struct gdbarch *gdbarch,
01351                                ptid_t ptid)
01352 {
01353   struct regcache *regcache = get_thread_regcache (ptid);
01354   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01355   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
01356   int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
01357   /* The content of a register */
01358   gdb_byte buf[8];
01359   /* The result */
01360   LONGEST ret;
01361 
01362   /* Make sure we're in a known ABI */
01363   gdb_assert (tdep->mips_abi == MIPS_ABI_O32
01364               || tdep->mips_abi == MIPS_ABI_N32
01365               || tdep->mips_abi == MIPS_ABI_N64);
01366 
01367   gdb_assert (regsize <= sizeof (buf));
01368 
01369   /* Getting the system call number from the register.
01370      syscall number is in v0 or $2.  */
01371   regcache_cooked_read (regcache, MIPS_V0_REGNUM, buf);
01372 
01373   ret = extract_signed_integer (buf, regsize, byte_order);
01374 
01375   return ret;
01376 }
01377 
01378 /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
01379    gdbarch.h.  */
01380 
01381 static int
01382 mips_gdb_signal_to_target (struct gdbarch *gdbarch,
01383                            enum gdb_signal signal)
01384 {
01385   switch (signal)
01386     {
01387     case GDB_SIGNAL_EMT:
01388       return MIPS_LINUX_SIGEMT;
01389 
01390     case GDB_SIGNAL_BUS:
01391       return MIPS_LINUX_SIGBUS;
01392 
01393     case GDB_SIGNAL_SYS:
01394       return MIPS_LINUX_SIGSYS;
01395 
01396     case GDB_SIGNAL_USR1:
01397       return MIPS_LINUX_SIGUSR1;
01398 
01399     case GDB_SIGNAL_USR2:
01400       return MIPS_LINUX_SIGUSR2;
01401 
01402     case GDB_SIGNAL_CHLD:
01403       return MIPS_LINUX_SIGCHLD;
01404 
01405     case GDB_SIGNAL_PWR:
01406       return MIPS_LINUX_SIGPWR;
01407 
01408     case GDB_SIGNAL_WINCH:
01409       return MIPS_LINUX_SIGWINCH;
01410 
01411     case GDB_SIGNAL_URG:
01412       return MIPS_LINUX_SIGURG;
01413 
01414     case GDB_SIGNAL_IO:
01415       return MIPS_LINUX_SIGIO;
01416 
01417     case GDB_SIGNAL_POLL:
01418       return MIPS_LINUX_SIGPOLL;
01419 
01420     case GDB_SIGNAL_STOP:
01421       return MIPS_LINUX_SIGSTOP;
01422 
01423     case GDB_SIGNAL_TSTP:
01424       return MIPS_LINUX_SIGTSTP;
01425 
01426     case GDB_SIGNAL_CONT:
01427       return MIPS_LINUX_SIGCONT;
01428 
01429     case GDB_SIGNAL_TTIN:
01430       return MIPS_LINUX_SIGTTIN;
01431 
01432     case GDB_SIGNAL_TTOU:
01433       return MIPS_LINUX_SIGTTOU;
01434 
01435     case GDB_SIGNAL_VTALRM:
01436       return MIPS_LINUX_SIGVTALRM;
01437 
01438     case GDB_SIGNAL_PROF:
01439       return MIPS_LINUX_SIGPROF;
01440 
01441     case GDB_SIGNAL_XCPU:
01442       return MIPS_LINUX_SIGXCPU;
01443 
01444     case GDB_SIGNAL_XFSZ:
01445       return MIPS_LINUX_SIGXFSZ;
01446 
01447     /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
01448        therefore we have to handle it here.  */
01449     case GDB_SIGNAL_REALTIME_32:
01450       return MIPS_LINUX_SIGRTMIN;
01451     }
01452 
01453   if (signal >= GDB_SIGNAL_REALTIME_33
01454       && signal <= GDB_SIGNAL_REALTIME_63)
01455     {
01456       int offset = signal - GDB_SIGNAL_REALTIME_33;
01457 
01458       return MIPS_LINUX_SIGRTMIN + 1 + offset;
01459     }
01460   else if (signal >= GDB_SIGNAL_REALTIME_64
01461            && signal <= GDB_SIGNAL_REALTIME_127)
01462     {
01463       int offset = signal - GDB_SIGNAL_REALTIME_64;
01464 
01465       return MIPS_LINUX_SIGRT64 + offset;
01466     }
01467 
01468   return linux_gdb_signal_to_target (gdbarch, signal);
01469 }
01470 
01471 /* Translate signals based on MIPS signal values.
01472    Adapted from gdb/common/signals.c.  */
01473 
01474 static enum gdb_signal
01475 mips_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
01476 {
01477   switch (signal)
01478     {
01479     case MIPS_LINUX_SIGEMT:
01480       return GDB_SIGNAL_EMT;
01481 
01482     case MIPS_LINUX_SIGBUS:
01483       return GDB_SIGNAL_BUS;
01484 
01485     case MIPS_LINUX_SIGSYS:
01486       return GDB_SIGNAL_SYS;
01487 
01488     case MIPS_LINUX_SIGUSR1:
01489       return GDB_SIGNAL_USR1;
01490 
01491     case MIPS_LINUX_SIGUSR2:
01492       return GDB_SIGNAL_USR2;
01493 
01494     case MIPS_LINUX_SIGCHLD:
01495       return GDB_SIGNAL_CHLD;
01496 
01497     case MIPS_LINUX_SIGPWR:
01498       return GDB_SIGNAL_PWR;
01499 
01500     case MIPS_LINUX_SIGWINCH:
01501       return GDB_SIGNAL_WINCH;
01502 
01503     case MIPS_LINUX_SIGURG:
01504       return GDB_SIGNAL_URG;
01505 
01506     /* No way to differentiate between SIGIO and SIGPOLL.
01507        Therefore, we just handle the first one.  */
01508     case MIPS_LINUX_SIGIO:
01509       return GDB_SIGNAL_IO;
01510 
01511     case MIPS_LINUX_SIGSTOP:
01512       return GDB_SIGNAL_STOP;
01513 
01514     case MIPS_LINUX_SIGTSTP:
01515       return GDB_SIGNAL_TSTP;
01516 
01517     case MIPS_LINUX_SIGCONT:
01518       return GDB_SIGNAL_CONT;
01519 
01520     case MIPS_LINUX_SIGTTIN:
01521       return GDB_SIGNAL_TTIN;
01522 
01523     case MIPS_LINUX_SIGTTOU:
01524       return GDB_SIGNAL_TTOU;
01525 
01526     case MIPS_LINUX_SIGVTALRM:
01527       return GDB_SIGNAL_VTALRM;
01528 
01529     case MIPS_LINUX_SIGPROF:
01530       return GDB_SIGNAL_PROF;
01531 
01532     case MIPS_LINUX_SIGXCPU:
01533       return GDB_SIGNAL_XCPU;
01534 
01535     case MIPS_LINUX_SIGXFSZ:
01536       return GDB_SIGNAL_XFSZ;
01537     }
01538 
01539   if (signal >= MIPS_LINUX_SIGRTMIN && signal <= MIPS_LINUX_SIGRTMAX)
01540     {
01541       /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
01542          the MIPS block to the respective GDB_SIGNAL_REALTIME blocks.  */
01543       int offset = signal - MIPS_LINUX_SIGRTMIN;
01544 
01545       if (offset == 0)
01546         return GDB_SIGNAL_REALTIME_32;
01547       else if (offset < 32)
01548         return (enum gdb_signal) (offset - 1
01549                                   + (int) GDB_SIGNAL_REALTIME_33);
01550       else
01551         return (enum gdb_signal) (offset - 32
01552                                   + (int) GDB_SIGNAL_REALTIME_64);
01553     }
01554 
01555   return linux_gdb_signal_from_target (gdbarch, signal);
01556 }
01557 
01558 /* Initialize one of the GNU/Linux OS ABIs.  */
01559 
01560 static void
01561 mips_linux_init_abi (struct gdbarch_info info,
01562                      struct gdbarch *gdbarch)
01563 {
01564   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
01565   enum mips_abi abi = mips_abi (gdbarch);
01566   struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
01567 
01568   linux_init_abi (info, gdbarch);
01569 
01570   /* Get the syscall number from the arch's register.  */
01571   set_gdbarch_get_syscall_number (gdbarch, mips_linux_get_syscall_number);
01572 
01573   switch (abi)
01574     {
01575       case MIPS_ABI_O32:
01576         set_gdbarch_get_longjmp_target (gdbarch,
01577                                         mips_linux_get_longjmp_target);
01578         set_solib_svr4_fetch_link_map_offsets
01579           (gdbarch, svr4_ilp32_fetch_link_map_offsets);
01580         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
01581         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
01582         set_xml_syscall_file_name ("syscalls/mips-o32-linux.xml");
01583         break;
01584       case MIPS_ABI_N32:
01585         set_gdbarch_get_longjmp_target (gdbarch,
01586                                         mips_linux_get_longjmp_target);
01587         set_solib_svr4_fetch_link_map_offsets
01588           (gdbarch, svr4_ilp32_fetch_link_map_offsets);
01589         set_gdbarch_long_double_bit (gdbarch, 128);
01590         /* These floatformats should probably be renamed.  MIPS uses
01591            the same 128-bit IEEE floating point format that IA-64 uses,
01592            except that the quiet/signalling NaN bit is reversed (GDB
01593            does not distinguish between quiet and signalling NaNs).  */
01594         set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
01595         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
01596         set_xml_syscall_file_name ("syscalls/mips-n32-linux.xml");
01597         break;
01598       case MIPS_ABI_N64:
01599         set_gdbarch_get_longjmp_target (gdbarch,
01600                                         mips64_linux_get_longjmp_target);
01601         set_solib_svr4_fetch_link_map_offsets
01602           (gdbarch, svr4_lp64_fetch_link_map_offsets);
01603         set_gdbarch_long_double_bit (gdbarch, 128);
01604         /* These floatformats should probably be renamed.  MIPS uses
01605            the same 128-bit IEEE floating point format that IA-64 uses,
01606            except that the quiet/signalling NaN bit is reversed (GDB
01607            does not distinguish between quiet and signalling NaNs).  */
01608         set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
01609         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
01610         set_xml_syscall_file_name ("syscalls/mips-n64-linux.xml");
01611         break;
01612       default:
01613         break;
01614     }
01615 
01616   set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
01617 
01618   set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
01619 
01620   /* Enable TLS support.  */
01621   set_gdbarch_fetch_tls_load_module_address (gdbarch,
01622                                              svr4_fetch_objfile_link_map);
01623 
01624   /* Initialize this lazily, to avoid an initialization order
01625      dependency on solib-svr4.c's _initialize routine.  */
01626   if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
01627     {
01628       mips_svr4_so_ops = svr4_so_ops;
01629       mips_svr4_so_ops.in_dynsym_resolve_code
01630         = mips_linux_in_dynsym_resolve_code;
01631     }
01632   set_solib_ops (gdbarch, &mips_svr4_so_ops);
01633 
01634   set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
01635 
01636   set_gdbarch_core_read_description (gdbarch,
01637                                      mips_linux_core_read_description);
01638 
01639   set_gdbarch_regset_from_core_section (gdbarch,
01640                                         mips_linux_regset_from_core_section);
01641 
01642   set_gdbarch_gdb_signal_from_target (gdbarch,
01643                                       mips_gdb_signal_from_target);
01644 
01645   set_gdbarch_gdb_signal_to_target (gdbarch,
01646                                     mips_gdb_signal_to_target);
01647 
01648   tdep->syscall_next_pc = mips_linux_syscall_next_pc;
01649 
01650   if (tdesc_data)
01651     {
01652       const struct tdesc_feature *feature;
01653 
01654       /* If we have target-described registers, then we can safely
01655          reserve a number for MIPS_RESTART_REGNUM (whether it is
01656          described or not).  */
01657       gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
01658       set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
01659       set_gdbarch_num_pseudo_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
01660 
01661       /* If it's present, then assign it to the reserved number.  */
01662       feature = tdesc_find_feature (info.target_desc,
01663                                     "org.gnu.gdb.mips.linux");
01664       if (feature != NULL)
01665         tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
01666                                  "restart");
01667     }
01668 }
01669 
01670 /* Provide a prototype to silence -Wmissing-prototypes.  */
01671 extern initialize_file_ftype _initialize_mips_linux_tdep;
01672 
01673 void
01674 _initialize_mips_linux_tdep (void)
01675 {
01676   const struct bfd_arch_info *arch_info;
01677 
01678   for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
01679        arch_info != NULL;
01680        arch_info = arch_info->next)
01681     {
01682       gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
01683                               GDB_OSABI_LINUX,
01684                               mips_linux_init_abi);
01685     }
01686 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines