gdb/mips-linux-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for GNU/Linux on MIPS processors.

  2.    Copyright (C) 2001-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "gdbcore.h"
  16. #include "target.h"
  17. #include "solib-svr4.h"
  18. #include "osabi.h"
  19. #include "mips-tdep.h"
  20. #include "frame.h"
  21. #include "regcache.h"
  22. #include "trad-frame.h"
  23. #include "tramp-frame.h"
  24. #include "gdbtypes.h"
  25. #include "objfiles.h"
  26. #include "solib.h"
  27. #include "solist.h"
  28. #include "symtab.h"
  29. #include "target-descriptions.h"
  30. #include "regset.h"
  31. #include "mips-linux-tdep.h"
  32. #include "glibc-tdep.h"
  33. #include "linux-tdep.h"
  34. #include "xml-syscall.h"
  35. #include "gdb_signals.h"

  36. static struct target_so_ops mips_svr4_so_ops;

  37. /* This enum represents the signals' numbers on the MIPS
  38.    architecture.  It just contains the signal definitions which are
  39.    different from the generic implementation.

  40.    It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
  41.    from the Linux kernel tree.  */

  42. enum
  43.   {
  44.     MIPS_LINUX_SIGEMT = 7,
  45.     MIPS_LINUX_SIGBUS = 10,
  46.     MIPS_LINUX_SIGSYS = 12,
  47.     MIPS_LINUX_SIGUSR1 = 16,
  48.     MIPS_LINUX_SIGUSR2 = 17,
  49.     MIPS_LINUX_SIGCHLD = 18,
  50.     MIPS_LINUX_SIGCLD = MIPS_LINUX_SIGCHLD,
  51.     MIPS_LINUX_SIGPWR = 19,
  52.     MIPS_LINUX_SIGWINCH = 20,
  53.     MIPS_LINUX_SIGURG = 21,
  54.     MIPS_LINUX_SIGIO = 22,
  55.     MIPS_LINUX_SIGPOLL = MIPS_LINUX_SIGIO,
  56.     MIPS_LINUX_SIGSTOP = 23,
  57.     MIPS_LINUX_SIGTSTP = 24,
  58.     MIPS_LINUX_SIGCONT = 25,
  59.     MIPS_LINUX_SIGTTIN = 26,
  60.     MIPS_LINUX_SIGTTOU = 27,
  61.     MIPS_LINUX_SIGVTALRM = 28,
  62.     MIPS_LINUX_SIGPROF = 29,
  63.     MIPS_LINUX_SIGXCPU = 30,
  64.     MIPS_LINUX_SIGXFSZ = 31,

  65.     MIPS_LINUX_SIGRTMIN = 32,
  66.     MIPS_LINUX_SIGRT64 = 64,
  67.     MIPS_LINUX_SIGRTMAX = 127,
  68.   };

  69. /* Figure out where the longjmp will land.
  70.    We expect the first arg to be a pointer to the jmp_buf structure
  71.    from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
  72.    at.  The pc is copied into PC.  This routine returns 1 on
  73.    success.  */

  74. #define MIPS_LINUX_JB_ELEMENT_SIZE 4
  75. #define MIPS_LINUX_JB_PC 0

  76. static int
  77. mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  78. {
  79.   CORE_ADDR jb_addr;
  80.   struct gdbarch *gdbarch = get_frame_arch (frame);
  81.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  82.   gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];

  83.   jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);

  84.   if (target_read_memory ((jb_addr
  85.                            + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE),
  86.                           buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
  87.     return 0;

  88.   *pc = extract_unsigned_integer (buf,
  89.                                   gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
  90.                                   byte_order);

  91.   return 1;
  92. }

  93. /* Transform the bits comprising a 32-bit register to the right size
  94.    for regcache_raw_supply().  This is needed when mips_isa_regsize()
  95.    is 8.  */

  96. static void
  97. supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
  98. {
  99.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  100.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  101.   gdb_byte buf[MAX_REGISTER_SIZE];
  102.   store_signed_integer (buf, register_size (gdbarch, regnum), byte_order,
  103.                         extract_signed_integer (addr, 4, byte_order));
  104.   regcache_raw_supply (regcache, regnum, buf);
  105. }

  106. /* Unpack an elf_gregset_t into GDB's register cache.  */

  107. void
  108. mips_supply_gregset (struct regcache *regcache,
  109.                      const mips_elf_gregset_t *gregsetp)
  110. {
  111.   int regi;
  112.   const mips_elf_greg_t *regp = *gregsetp;
  113.   char zerobuf[MAX_REGISTER_SIZE];
  114.   struct gdbarch *gdbarch = get_regcache_arch (regcache);

  115.   memset (zerobuf, 0, MAX_REGISTER_SIZE);

  116.   for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
  117.     supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);

  118.   if (mips_linux_restart_reg_p (gdbarch))
  119.     supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);

  120.   supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
  121.   supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);

  122.   supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
  123.                     regp + EF_CP0_EPC);
  124.   supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
  125.                     regp + EF_CP0_BADVADDR);
  126.   supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
  127.   supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
  128.                     regp + EF_CP0_CAUSE);

  129.   /* Fill the inaccessible zero register with zero.  */
  130.   regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
  131. }

  132. static void
  133. mips_supply_gregset_wrapper (const struct regset *regset,
  134.                              struct regcache *regcache,
  135.                              int regnum, const void *gregs, size_t len)
  136. {
  137.   gdb_assert (len == sizeof (mips_elf_gregset_t));

  138.   mips_supply_gregset (regcache, (const mips_elf_gregset_t *)gregs);
  139. }

  140. /* Pack our registers (or one register) into an elf_gregset_t.  */

  141. void
  142. mips_fill_gregset (const struct regcache *regcache,
  143.                    mips_elf_gregset_t *gregsetp, int regno)
  144. {
  145.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  146.   int regaddr, regi;
  147.   mips_elf_greg_t *regp = *gregsetp;
  148.   void *dst;

  149.   if (regno == -1)
  150.     {
  151.       memset (regp, 0, sizeof (mips_elf_gregset_t));
  152.       for (regi = 1; regi < 32; regi++)
  153.         mips_fill_gregset (regcache, gregsetp, regi);
  154.       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
  155.       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
  156.       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
  157.       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
  158.       mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
  159.       mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
  160.       mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
  161.       return;
  162.    }

  163.   if (regno > 0 && regno < 32)
  164.     {
  165.       dst = regp + regno + EF_REG0;
  166.       regcache_raw_collect (regcache, regno, dst);
  167.       return;
  168.     }

  169.   if (regno == mips_regnum (gdbarch)->lo)
  170.      regaddr = EF_LO;
  171.   else if (regno == mips_regnum (gdbarch)->hi)
  172.     regaddr = EF_HI;
  173.   else if (regno == mips_regnum (gdbarch)->pc)
  174.     regaddr = EF_CP0_EPC;
  175.   else if (regno == mips_regnum (gdbarch)->badvaddr)
  176.     regaddr = EF_CP0_BADVADDR;
  177.   else if (regno == MIPS_PS_REGNUM)
  178.     regaddr = EF_CP0_STATUS;
  179.   else if (regno == mips_regnum (gdbarch)->cause)
  180.     regaddr = EF_CP0_CAUSE;
  181.   else if (mips_linux_restart_reg_p (gdbarch)
  182.            && regno == MIPS_RESTART_REGNUM)
  183.     regaddr = EF_REG0;
  184.   else
  185.     regaddr = -1;

  186.   if (regaddr != -1)
  187.     {
  188.       dst = regp + regaddr;
  189.       regcache_raw_collect (regcache, regno, dst);
  190.     }
  191. }

  192. static void
  193. mips_fill_gregset_wrapper (const struct regset *regset,
  194.                            const struct regcache *regcache,
  195.                            int regnum, void *gregs, size_t len)
  196. {
  197.   gdb_assert (len == sizeof (mips_elf_gregset_t));

  198.   mips_fill_gregset (regcache, (mips_elf_gregset_t *)gregs, regnum);
  199. }

  200. /* Likewise, unpack an elf_fpregset_t.  */

  201. void
  202. mips_supply_fpregset (struct regcache *regcache,
  203.                       const mips_elf_fpregset_t *fpregsetp)
  204. {
  205.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  206.   int regi;
  207.   char zerobuf[MAX_REGISTER_SIZE];

  208.   memset (zerobuf, 0, MAX_REGISTER_SIZE);

  209.   for (regi = 0; regi < 32; regi++)
  210.     regcache_raw_supply (regcache,
  211.                          gdbarch_fp0_regnum (gdbarch) + regi,
  212.                          *fpregsetp + regi);

  213.   regcache_raw_supply (regcache,
  214.                        mips_regnum (gdbarch)->fp_control_status,
  215.                        *fpregsetp + 32);

  216.   /* FIXME: how can we supply FCRIR?  The ABI doesn't tell us.  */
  217.   regcache_raw_supply (regcache,
  218.                        mips_regnum (gdbarch)->fp_implementation_revision,
  219.                        zerobuf);
  220. }

  221. static void
  222. mips_supply_fpregset_wrapper (const struct regset *regset,
  223.                               struct regcache *regcache,
  224.                               int regnum, const void *gregs, size_t len)
  225. {
  226.   gdb_assert (len == sizeof (mips_elf_fpregset_t));

  227.   mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *)gregs);
  228. }

  229. /* Likewise, pack one or all floating point registers into an
  230.    elf_fpregset_t.  */

  231. void
  232. mips_fill_fpregset (const struct regcache *regcache,
  233.                     mips_elf_fpregset_t *fpregsetp, int regno)
  234. {
  235.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  236.   char *to;

  237.   if ((regno >= gdbarch_fp0_regnum (gdbarch))
  238.       && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
  239.     {
  240.       to = (char *) (*fpregsetp + regno - gdbarch_fp0_regnum (gdbarch));
  241.       regcache_raw_collect (regcache, regno, to);
  242.     }
  243.   else if (regno == mips_regnum (gdbarch)->fp_control_status)
  244.     {
  245.       to = (char *) (*fpregsetp + 32);
  246.       regcache_raw_collect (regcache, regno, to);
  247.     }
  248.   else if (regno == -1)
  249.     {
  250.       int regi;

  251.       for (regi = 0; regi < 32; regi++)
  252.         mips_fill_fpregset (regcache, fpregsetp,
  253.                             gdbarch_fp0_regnum (gdbarch) + regi);
  254.       mips_fill_fpregset (regcache, fpregsetp,
  255.                           mips_regnum (gdbarch)->fp_control_status);
  256.     }
  257. }

  258. static void
  259. mips_fill_fpregset_wrapper (const struct regset *regset,
  260.                             const struct regcache *regcache,
  261.                             int regnum, void *gregs, size_t len)
  262. {
  263.   gdb_assert (len == sizeof (mips_elf_fpregset_t));

  264.   mips_fill_fpregset (regcache, (mips_elf_fpregset_t *)gregs, regnum);
  265. }

  266. /* Support for 64-bit ABIs.  */

  267. /* Figure out where the longjmp will land.
  268.    We expect the first arg to be a pointer to the jmp_buf structure
  269.    from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
  270.    at.  The pc is copied into PC.  This routine returns 1 on
  271.    success.  */

  272. /* Details about jmp_buf.  */

  273. #define MIPS64_LINUX_JB_PC 0

  274. static int
  275. mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  276. {
  277.   CORE_ADDR jb_addr;
  278.   struct gdbarch *gdbarch = get_frame_arch (frame);
  279.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  280.   void *buf = alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
  281.   int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;

  282.   jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);

  283.   if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
  284.                           buf,
  285.                           gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
  286.     return 0;

  287.   *pc = extract_unsigned_integer (buf,
  288.                                   gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
  289.                                   byte_order);

  290.   return 1;
  291. }

  292. /* Register set support functions.  These operate on standard 64-bit
  293.    regsets, but work whether the target is 32-bit or 64-bitA 32-bit
  294.    target will still use the 64-bit format for PTRACE_GETREGS.  */

  295. /* Supply a 64-bit register.  */

  296. static void
  297. supply_64bit_reg (struct regcache *regcache, int regnum,
  298.                   const gdb_byte *buf)
  299. {
  300.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  301.   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
  302.       && register_size (gdbarch, regnum) == 4)
  303.     regcache_raw_supply (regcache, regnum, buf + 4);
  304.   else
  305.     regcache_raw_supply (regcache, regnum, buf);
  306. }

  307. /* Unpack a 64-bit elf_gregset_t into GDB's register cache.  */

  308. void
  309. mips64_supply_gregset (struct regcache *regcache,
  310.                        const mips64_elf_gregset_t *gregsetp)
  311. {
  312.   int regi;
  313.   const mips64_elf_greg_t *regp = *gregsetp;
  314.   gdb_byte zerobuf[MAX_REGISTER_SIZE];
  315.   struct gdbarch *gdbarch = get_regcache_arch (regcache);

  316.   memset (zerobuf, 0, MAX_REGISTER_SIZE);

  317.   for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
  318.     supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
  319.                       (const gdb_byte *) (regp + regi));

  320.   if (mips_linux_restart_reg_p (gdbarch))
  321.     supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
  322.                       (const gdb_byte *) (regp + MIPS64_EF_REG0));

  323.   supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
  324.                     (const gdb_byte *) (regp + MIPS64_EF_LO));
  325.   supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
  326.                     (const gdb_byte *) (regp + MIPS64_EF_HI));

  327.   supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
  328.                     (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
  329.   supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
  330.                     (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
  331.   supply_64bit_reg (regcache, MIPS_PS_REGNUM,
  332.                     (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
  333.   supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
  334.                     (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));

  335.   /* Fill the inaccessible zero register with zero.  */
  336.   regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
  337. }

  338. static void
  339. mips64_supply_gregset_wrapper (const struct regset *regset,
  340.                                struct regcache *regcache,
  341.                                int regnum, const void *gregs, size_t len)
  342. {
  343.   gdb_assert (len == sizeof (mips64_elf_gregset_t));

  344.   mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *)gregs);
  345. }

  346. /* Pack our registers (or one register) into a 64-bit elf_gregset_t.  */

  347. void
  348. mips64_fill_gregset (const struct regcache *regcache,
  349.                      mips64_elf_gregset_t *gregsetp, int regno)
  350. {
  351.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  352.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  353.   int regaddr, regi;
  354.   mips64_elf_greg_t *regp = *gregsetp;
  355.   void *dst;

  356.   if (regno == -1)
  357.     {
  358.       memset (regp, 0, sizeof (mips64_elf_gregset_t));
  359.       for (regi = 1; regi < 32; regi++)
  360.         mips64_fill_gregset (regcache, gregsetp, regi);
  361.       mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
  362.       mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
  363.       mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
  364.       mips64_fill_gregset (regcache, gregsetp,
  365.                            mips_regnum (gdbarch)->badvaddr);
  366.       mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
  367.       mips64_fill_gregset (regcache, gregsetp,  mips_regnum (gdbarch)->cause);
  368.       mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
  369.       return;
  370.    }

  371.   if (regno > 0 && regno < 32)
  372.     regaddr = regno + MIPS64_EF_REG0;
  373.   else if (regno == mips_regnum (gdbarch)->lo)
  374.     regaddr = MIPS64_EF_LO;
  375.   else if (regno == mips_regnum (gdbarch)->hi)
  376.     regaddr = MIPS64_EF_HI;
  377.   else if (regno == mips_regnum (gdbarch)->pc)
  378.     regaddr = MIPS64_EF_CP0_EPC;
  379.   else if (regno == mips_regnum (gdbarch)->badvaddr)
  380.     regaddr = MIPS64_EF_CP0_BADVADDR;
  381.   else if (regno == MIPS_PS_REGNUM)
  382.     regaddr = MIPS64_EF_CP0_STATUS;
  383.   else if (regno == mips_regnum (gdbarch)->cause)
  384.     regaddr = MIPS64_EF_CP0_CAUSE;
  385.   else if (mips_linux_restart_reg_p (gdbarch)
  386.            && regno == MIPS_RESTART_REGNUM)
  387.     regaddr = MIPS64_EF_REG0;
  388.   else
  389.     regaddr = -1;

  390.   if (regaddr != -1)
  391.     {
  392.       gdb_byte buf[MAX_REGISTER_SIZE];
  393.       LONGEST val;

  394.       regcache_raw_collect (regcache, regno, buf);
  395.       val = extract_signed_integer (buf, register_size (gdbarch, regno),
  396.                                     byte_order);
  397.       dst = regp + regaddr;
  398.       store_signed_integer (dst, 8, byte_order, val);
  399.     }
  400. }

  401. static void
  402. mips64_fill_gregset_wrapper (const struct regset *regset,
  403.                              const struct regcache *regcache,
  404.                              int regnum, void *gregs, size_t len)
  405. {
  406.   gdb_assert (len == sizeof (mips64_elf_gregset_t));

  407.   mips64_fill_gregset (regcache, (mips64_elf_gregset_t *)gregs, regnum);
  408. }

  409. /* Likewise, unpack an elf_fpregset_t.  */

  410. void
  411. mips64_supply_fpregset (struct regcache *regcache,
  412.                         const mips64_elf_fpregset_t *fpregsetp)
  413. {
  414.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  415.   int regi;

  416.   /* See mips_linux_o32_sigframe_init for a description of the
  417.      peculiar FP register layout.  */
  418.   if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
  419.     for (regi = 0; regi < 32; regi++)
  420.       {
  421.         const gdb_byte *reg_ptr
  422.           = (const gdb_byte *) (*fpregsetp + (regi & ~1));
  423.         if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
  424.           reg_ptr += 4;
  425.         regcache_raw_supply (regcache,
  426.                              gdbarch_fp0_regnum (gdbarch) + regi,
  427.                              reg_ptr);
  428.       }
  429.   else
  430.     for (regi = 0; regi < 32; regi++)
  431.       regcache_raw_supply (regcache,
  432.                            gdbarch_fp0_regnum (gdbarch) + regi,
  433.                            (const char *) (*fpregsetp + regi));

  434.   supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
  435.                     (const gdb_byte *) (*fpregsetp + 32));

  436.   /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
  437.      include it - but the result of PTRACE_GETFPREGS does.  The best we
  438.      can do is to assume that its value is present.  */
  439.   supply_32bit_reg (regcache,
  440.                     mips_regnum (gdbarch)->fp_implementation_revision,
  441.                     (const gdb_byte *) (*fpregsetp + 32) + 4);
  442. }

  443. static void
  444. mips64_supply_fpregset_wrapper (const struct regset *regset,
  445.                                 struct regcache *regcache,
  446.                                 int regnum, const void *gregs, size_t len)
  447. {
  448.   gdb_assert (len == sizeof (mips64_elf_fpregset_t));

  449.   mips64_supply_fpregset (regcache, (const mips64_elf_fpregset_t *)gregs);
  450. }

  451. /* Likewise, pack one or all floating point registers into an
  452.    elf_fpregset_t.  */

  453. void
  454. mips64_fill_fpregset (const struct regcache *regcache,
  455.                       mips64_elf_fpregset_t *fpregsetp, int regno)
  456. {
  457.   struct gdbarch *gdbarch = get_regcache_arch (regcache);
  458.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  459.   gdb_byte *to;

  460.   if ((regno >= gdbarch_fp0_regnum (gdbarch))
  461.       && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
  462.     {
  463.       /* See mips_linux_o32_sigframe_init for a description of the
  464.          peculiar FP register layout.  */
  465.       if (register_size (gdbarch, regno) == 4)
  466.         {
  467.           int regi = regno - gdbarch_fp0_regnum (gdbarch);

  468.           to = (gdb_byte *) (*fpregsetp + (regi & ~1));
  469.           if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
  470.             to += 4;
  471.           regcache_raw_collect (regcache, regno, to);
  472.         }
  473.       else
  474.         {
  475.           to = (gdb_byte *) (*fpregsetp + regno
  476.                              - gdbarch_fp0_regnum (gdbarch));
  477.           regcache_raw_collect (regcache, regno, to);
  478.         }
  479.     }
  480.   else if (regno == mips_regnum (gdbarch)->fp_control_status)
  481.     {
  482.       gdb_byte buf[MAX_REGISTER_SIZE];
  483.       LONGEST val;

  484.       regcache_raw_collect (regcache, regno, buf);
  485.       val = extract_signed_integer (buf, register_size (gdbarch, regno),
  486.                                     byte_order);
  487.       to = (gdb_byte *) (*fpregsetp + 32);
  488.       store_signed_integer (to, 4, byte_order, val);
  489.     }
  490.   else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
  491.     {
  492.       gdb_byte buf[MAX_REGISTER_SIZE];
  493.       LONGEST val;

  494.       regcache_raw_collect (regcache, regno, buf);
  495.       val = extract_signed_integer (buf, register_size (gdbarch, regno),
  496.                                     byte_order);
  497.       to = (gdb_byte *) (*fpregsetp + 32) + 4;
  498.       store_signed_integer (to, 4, byte_order, val);
  499.     }
  500.   else if (regno == -1)
  501.     {
  502.       int regi;

  503.       for (regi = 0; regi < 32; regi++)
  504.         mips64_fill_fpregset (regcache, fpregsetp,
  505.                               gdbarch_fp0_regnum (gdbarch) + regi);
  506.       mips64_fill_fpregset (regcache, fpregsetp,
  507.                             mips_regnum (gdbarch)->fp_control_status);
  508.       mips64_fill_fpregset (regcache, fpregsetp,
  509.                             mips_regnum (gdbarch)->fp_implementation_revision);
  510.     }
  511. }

  512. static void
  513. mips64_fill_fpregset_wrapper (const struct regset *regset,
  514.                               const struct regcache *regcache,
  515.                               int regnum, void *gregs, size_t len)
  516. {
  517.   gdb_assert (len == sizeof (mips64_elf_fpregset_t));

  518.   mips64_fill_fpregset (regcache, (mips64_elf_fpregset_t *)gregs, regnum);
  519. }

  520. static const struct regset mips_linux_gregset =
  521.   {
  522.     NULL, mips_supply_gregset_wrapper, mips_fill_gregset_wrapper
  523.   };

  524. static const struct regset mips64_linux_gregset =
  525.   {
  526.     NULL, mips64_supply_gregset_wrapper, mips64_fill_gregset_wrapper
  527.   };

  528. static const struct regset mips_linux_fpregset =
  529.   {
  530.     NULL, mips_supply_fpregset_wrapper, mips_fill_fpregset_wrapper
  531.   };

  532. static const struct regset mips64_linux_fpregset =
  533.   {
  534.     NULL, mips64_supply_fpregset_wrapper, mips64_fill_fpregset_wrapper
  535.   };

  536. static void
  537. mips_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  538.                                          iterate_over_regset_sections_cb *cb,
  539.                                          void *cb_data,
  540.                                          const struct regcache *regcache)
  541. {
  542.   if (register_size (gdbarch, MIPS_ZERO_REGNUM) == 4)
  543.     {
  544.       cb (".reg", sizeof (mips_elf_gregset_t), &mips_linux_gregset,
  545.           NULL, cb_data);
  546.       cb (".reg2", sizeof (mips_elf_fpregset_t), &mips_linux_fpregset,
  547.           NULL, cb_data);
  548.     }
  549.   else
  550.     {
  551.       cb (".reg", sizeof (mips64_elf_gregset_t), &mips64_linux_gregset,
  552.           NULL, cb_data);
  553.       cb (".reg2", sizeof (mips64_elf_fpregset_t), &mips64_linux_fpregset,
  554.           NULL, cb_data);
  555.     }
  556. }

  557. static const struct target_desc *
  558. mips_linux_core_read_description (struct gdbarch *gdbarch,
  559.                                   struct target_ops *target,
  560.                                   bfd *abfd)
  561. {
  562.   asection *section = bfd_get_section_by_name (abfd, ".reg");
  563.   if (! section)
  564.     return NULL;

  565.   switch (bfd_section_size (abfd, section))
  566.     {
  567.     case sizeof (mips_elf_gregset_t):
  568.       return mips_tdesc_gp32;

  569.     case sizeof (mips64_elf_gregset_t):
  570.       return mips_tdesc_gp64;

  571.     default:
  572.       return NULL;
  573.     }
  574. }


  575. /* Check the code at PC for a dynamic linker lazy resolution stub.
  576.    GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
  577.    section uniformly since version 2.15.  If the pc is in that section,
  578.    then we are in such a stub.  Before that ".stub" was used in 32-bit
  579.    ELF binaries, however we do not bother checking for that since we
  580.    have never had and that case should be extremely rare these days.
  581.    Instead we pattern-match on the code generated by GNU ld.  They look
  582.    like this:

  583.    lw t9,0x8010(gp)
  584.    addu t7,ra
  585.    jalr t9,ra
  586.    addiu t8,zero,INDEX

  587.    (with the appropriate doubleword instructions for N64).  As any lazy
  588.    resolution stubs in microMIPS binaries will always be in a
  589.    ".MIPS.stubs" section we only ever verify standard MIPS patterns. */

  590. static int
  591. mips_linux_in_dynsym_stub (CORE_ADDR pc)
  592. {
  593.   gdb_byte buf[28], *p;
  594.   ULONGEST insn, insn1;
  595.   int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64);
  596.   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());

  597.   if (in_mips_stubs_section (pc))
  598.     return 1;

  599.   read_memory (pc - 12, buf, 28);

  600.   if (n64)
  601.     {
  602.       /* ld t9,0x8010(gp) */
  603.       insn1 = 0xdf998010;
  604.     }
  605.   else
  606.     {
  607.       /* lw t9,0x8010(gp) */
  608.       insn1 = 0x8f998010;
  609.     }

  610.   p = buf + 12;
  611.   while (p >= buf)
  612.     {
  613.       insn = extract_unsigned_integer (p, 4, byte_order);
  614.       if (insn == insn1)
  615.         break;
  616.       p -= 4;
  617.     }
  618.   if (p < buf)
  619.     return 0;

  620.   insn = extract_unsigned_integer (p + 4, 4, byte_order);
  621.   if (n64)
  622.     {
  623.       /* daddu t7,ra */
  624.       if (insn != 0x03e0782d)
  625.         return 0;
  626.     }
  627.   else
  628.     {
  629.       /* addu t7,ra */
  630.       if (insn != 0x03e07821)
  631.         return 0;
  632.     }

  633.   insn = extract_unsigned_integer (p + 8, 4, byte_order);
  634.   /* jalr t9,ra */
  635.   if (insn != 0x0320f809)
  636.     return 0;

  637.   insn = extract_unsigned_integer (p + 12, 4, byte_order);
  638.   if (n64)
  639.     {
  640.       /* daddiu t8,zero,0 */
  641.       if ((insn & 0xffff0000) != 0x64180000)
  642.         return 0;
  643.     }
  644.   else
  645.     {
  646.       /* addiu t8,zero,0 */
  647.       if ((insn & 0xffff0000) != 0x24180000)
  648.         return 0;
  649.     }

  650.   return 1;
  651. }

  652. /* Return non-zero iff PC belongs to the dynamic linker resolution
  653.    code, a PLT entry, or a lazy binding stub.  */

  654. static int
  655. mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
  656. {
  657.   /* Check whether PC is in the dynamic linker.  This also checks
  658.      whether it is in the .plt section, used by non-PIC executables.  */
  659.   if (svr4_in_dynsym_resolve_code (pc))
  660.     return 1;

  661.   /* Likewise for the stubs.  They live in the .MIPS.stubs section these
  662.      days, so we check if the PC is within, than fall back to a pattern
  663.      match.  */
  664.   if (mips_linux_in_dynsym_stub (pc))
  665.     return 1;

  666.   return 0;
  667. }

  668. /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
  669.    and glibc_skip_solib_resolver in glibc-tdep.c.  The normal glibc
  670.    implementation of this triggers at "fixup" from the same objfile as
  671.    "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
  672.    "__dl_runtime_resolve" directly.  An unresolved lazy binding
  673.    stub will point to _dl_runtime_resolve, which will first call
  674.    __dl_runtime_resolve, and then pass control to the resolved
  675.    function.  */

  676. static CORE_ADDR
  677. mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
  678. {
  679.   struct bound_minimal_symbol resolver;

  680.   resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);

  681.   if (resolver.minsym && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
  682.     return frame_unwind_caller_pc (get_current_frame ());

  683.   return glibc_skip_solib_resolver (gdbarch, pc);
  684. }

  685. /* Signal trampoline support.  There are four supported layouts for a
  686.    signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
  687.    n64 rt_sigframe.  We handle them all independently; not the most
  688.    efficient way, but simplest.  First, declare all the unwinders.  */

  689. static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
  690.                                           struct frame_info *this_frame,
  691.                                           struct trad_frame_cache *this_cache,
  692.                                           CORE_ADDR func);

  693. static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
  694.                                              struct frame_info *this_frame,
  695.                                              struct trad_frame_cache *this_cache,
  696.                                              CORE_ADDR func);

  697. static int mips_linux_sigframe_validate (const struct tramp_frame *self,
  698.                                          struct frame_info *this_frame,
  699.                                          CORE_ADDR *pc);

  700. static int micromips_linux_sigframe_validate (const struct tramp_frame *self,
  701.                                               struct frame_info *this_frame,
  702.                                               CORE_ADDR *pc);

  703. #define MIPS_NR_LINUX 4000
  704. #define MIPS_NR_N64_LINUX 5000
  705. #define MIPS_NR_N32_LINUX 6000

  706. #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
  707. #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
  708. #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
  709. #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211

  710. #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
  711. #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
  712. #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
  713. #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
  714. #define MIPS_INST_SYSCALL 0x0000000c

  715. #define MICROMIPS_INST_LI_V0 0x3040
  716. #define MICROMIPS_INST_POOL32A 0x0000
  717. #define MICROMIPS_INST_SYSCALL 0x8b7c

  718. static const struct tramp_frame mips_linux_o32_sigframe = {
  719.   SIGTRAMP_FRAME,
  720.   4,
  721.   {
  722.     { MIPS_INST_LI_V0_SIGRETURN, -1 },
  723.     { MIPS_INST_SYSCALL, -1 },
  724.     { TRAMP_SENTINEL_INSN, -1 }
  725.   },
  726.   mips_linux_o32_sigframe_init,
  727.   mips_linux_sigframe_validate
  728. };

  729. static const struct tramp_frame mips_linux_o32_rt_sigframe = {
  730.   SIGTRAMP_FRAME,
  731.   4,
  732.   {
  733.     { MIPS_INST_LI_V0_RT_SIGRETURN, -1 },
  734.     { MIPS_INST_SYSCALL, -1 },
  735.     { TRAMP_SENTINEL_INSN, -1 } },
  736.   mips_linux_o32_sigframe_init,
  737.   mips_linux_sigframe_validate
  738. };

  739. static const struct tramp_frame mips_linux_n32_rt_sigframe = {
  740.   SIGTRAMP_FRAME,
  741.   4,
  742.   {
  743.     { MIPS_INST_LI_V0_N32_RT_SIGRETURN, -1 },
  744.     { MIPS_INST_SYSCALL, -1 },
  745.     { TRAMP_SENTINEL_INSN, -1 }
  746.   },
  747.   mips_linux_n32n64_sigframe_init,
  748.   mips_linux_sigframe_validate
  749. };

  750. static const struct tramp_frame mips_linux_n64_rt_sigframe = {
  751.   SIGTRAMP_FRAME,
  752.   4,
  753.   {
  754.     { MIPS_INST_LI_V0_N64_RT_SIGRETURN, -1 },
  755.     { MIPS_INST_SYSCALL, -1 },
  756.     { TRAMP_SENTINEL_INSN, -1 }
  757.   },
  758.   mips_linux_n32n64_sigframe_init,
  759.   mips_linux_sigframe_validate
  760. };

  761. static const struct tramp_frame micromips_linux_o32_sigframe = {
  762.   SIGTRAMP_FRAME,
  763.   2,
  764.   {
  765.     { MICROMIPS_INST_LI_V0, -1 },
  766.     { MIPS_NR_sigreturn, -1 },
  767.     { MICROMIPS_INST_POOL32A, -1 },
  768.     { MICROMIPS_INST_SYSCALL, -1 },
  769.     { TRAMP_SENTINEL_INSN, -1 }
  770.   },
  771.   mips_linux_o32_sigframe_init,
  772.   micromips_linux_sigframe_validate
  773. };

  774. static const struct tramp_frame micromips_linux_o32_rt_sigframe = {
  775.   SIGTRAMP_FRAME,
  776.   2,
  777.   {
  778.     { MICROMIPS_INST_LI_V0, -1 },
  779.     { MIPS_NR_rt_sigreturn, -1 },
  780.     { MICROMIPS_INST_POOL32A, -1 },
  781.     { MICROMIPS_INST_SYSCALL, -1 },
  782.     { TRAMP_SENTINEL_INSN, -1 }
  783.   },
  784.   mips_linux_o32_sigframe_init,
  785.   micromips_linux_sigframe_validate
  786. };

  787. static const struct tramp_frame micromips_linux_n32_rt_sigframe = {
  788.   SIGTRAMP_FRAME,
  789.   2,
  790.   {
  791.     { MICROMIPS_INST_LI_V0, -1 },
  792.     { MIPS_NR_N32_rt_sigreturn, -1 },
  793.     { MICROMIPS_INST_POOL32A, -1 },
  794.     { MICROMIPS_INST_SYSCALL, -1 },
  795.     { TRAMP_SENTINEL_INSN, -1 }
  796.   },
  797.   mips_linux_n32n64_sigframe_init,
  798.   micromips_linux_sigframe_validate
  799. };

  800. static const struct tramp_frame micromips_linux_n64_rt_sigframe = {
  801.   SIGTRAMP_FRAME,
  802.   2,
  803.   {
  804.     { MICROMIPS_INST_LI_V0, -1 },
  805.     { MIPS_NR_N64_rt_sigreturn, -1 },
  806.     { MICROMIPS_INST_POOL32A, -1 },
  807.     { MICROMIPS_INST_SYSCALL, -1 },
  808.     { TRAMP_SENTINEL_INSN, -1 }
  809.   },
  810.   mips_linux_n32n64_sigframe_init,
  811.   micromips_linux_sigframe_validate
  812. };

  813. /* *INDENT-OFF* */
  814. /* The unwinder for o32 signal frames.  The legacy structures look
  815.    like this:

  816.    struct sigframe {
  817.      u32 sf_ass[4];            [argument save space for o32]
  818.      u32 sf_code[2];           [signal trampoline or fill]
  819.      struct sigcontext sf_sc;
  820.      sigset_t sf_mask;
  821.    };

  822.    Pre-2.6.12 sigcontext:

  823.    struct sigcontext {
  824.         unsigned int       sc_regmask;          [Unused]
  825.         unsigned int       sc_status;
  826.         unsigned long long sc_pc;
  827.         unsigned long long sc_regs[32];
  828.         unsigned long long sc_fpregs[32];
  829.         unsigned int       sc_ownedfp;
  830.         unsigned int       sc_fpc_csr;
  831.         unsigned int       sc_fpc_eir;          [Unused]
  832.         unsigned int       sc_used_math;
  833.         unsigned int       sc_ssflags;          [Unused]
  834.         [Alignment hole of four bytes]
  835.         unsigned long long sc_mdhi;
  836.         unsigned long long sc_mdlo;

  837.         unsigned int       sc_cause;            [Unused]
  838.         unsigned int       sc_badvaddr;         [Unused]

  839.         unsigned long      sc_sigset[4];        [kernel's sigset_t]
  840.    };

  841.    Post-2.6.12 sigcontext (SmartMIPS/DSP support added):

  842.    struct sigcontext {
  843.         unsigned int       sc_regmask;          [Unused]
  844.         unsigned int       sc_status;           [Unused]
  845.         unsigned long long sc_pc;
  846.         unsigned long long sc_regs[32];
  847.         unsigned long long sc_fpregs[32];
  848.         unsigned int       sc_acx;
  849.         unsigned int       sc_fpc_csr;
  850.         unsigned int       sc_fpc_eir;          [Unused]
  851.         unsigned int       sc_used_math;
  852.         unsigned int       sc_dsp;
  853.         [Alignment hole of four bytes]
  854.         unsigned long long sc_mdhi;
  855.         unsigned long long sc_mdlo;
  856.         unsigned long      sc_hi1;
  857.         unsigned long      sc_lo1;
  858.         unsigned long      sc_hi2;
  859.         unsigned long      sc_lo2;
  860.         unsigned long      sc_hi3;
  861.         unsigned long      sc_lo3;
  862.    };

  863.    The RT signal frames look like this:

  864.    struct rt_sigframe {
  865.      u32 rs_ass[4];            [argument save space for o32]
  866.      u32 rs_code[2]            [signal trampoline or fill]
  867.      struct siginfo rs_info;
  868.      struct ucontext rs_uc;
  869.    };

  870.    struct ucontext {
  871.      unsigned long     uc_flags;
  872.      struct ucontext  *uc_link;
  873.      stack_t           uc_stack;
  874.      [Alignment hole of four bytes]
  875.      struct sigcontext uc_mcontext;
  876.      sigset_t          uc_sigmask;
  877.    };  */
  878. /* *INDENT-ON* */

  879. #define SIGFRAME_SIGCONTEXT_OFFSET   (6 * 4)

  880. #define RTSIGFRAME_SIGINFO_SIZE      128
  881. #define STACK_T_SIZE                 (3 * 4)
  882. #define UCONTEXT_SIGCONTEXT_OFFSET   (2 * 4 + STACK_T_SIZE + 4)
  883. #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
  884.                                       + RTSIGFRAME_SIGINFO_SIZE \
  885.                                       + UCONTEXT_SIGCONTEXT_OFFSET)

  886. #define SIGCONTEXT_PC       (1 * 8)
  887. #define SIGCONTEXT_REGS     (2 * 8)
  888. #define SIGCONTEXT_FPREGS   (34 * 8)
  889. #define SIGCONTEXT_FPCSR    (66 * 8 + 4)
  890. #define SIGCONTEXT_DSPCTL   (68 * 8 + 0)
  891. #define SIGCONTEXT_HI       (69 * 8)
  892. #define SIGCONTEXT_LO       (70 * 8)
  893. #define SIGCONTEXT_CAUSE    (71 * 8 + 0)
  894. #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
  895. #define SIGCONTEXT_HI1      (71 * 8 + 0)
  896. #define SIGCONTEXT_LO1      (71 * 8 + 4)
  897. #define SIGCONTEXT_HI2      (72 * 8 + 0)
  898. #define SIGCONTEXT_LO2      (72 * 8 + 4)
  899. #define SIGCONTEXT_HI3      (73 * 8 + 0)
  900. #define SIGCONTEXT_LO3      (73 * 8 + 4)

  901. #define SIGCONTEXT_REG_SIZE 8

  902. static void
  903. mips_linux_o32_sigframe_init (const struct tramp_frame *self,
  904.                               struct frame_info *this_frame,
  905.                               struct trad_frame_cache *this_cache,
  906.                               CORE_ADDR func)
  907. {
  908.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  909.   int ireg;
  910.   CORE_ADDR frame_sp = get_frame_sp (this_frame);
  911.   CORE_ADDR sigcontext_base;
  912.   const struct mips_regnum *regs = mips_regnum (gdbarch);
  913.   CORE_ADDR regs_base;

  914.   if (self == &mips_linux_o32_sigframe
  915.       || self == &micromips_linux_o32_sigframe)
  916.     sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
  917.   else
  918.     sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;

  919.   /* I'm not proud of this hack.  Eventually we will have the
  920.      infrastructure to indicate the size of saved registers on a
  921.      per-frame basis, but right now we don't; the kernel saves eight
  922.      bytes but we only want four.  Use regs_base to access any
  923.      64-bit fields.  */
  924.   if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  925.     regs_base = sigcontext_base + 4;
  926.   else
  927.     regs_base = sigcontext_base;

  928.   if (mips_linux_restart_reg_p (gdbarch))
  929.     trad_frame_set_reg_addr (this_cache,
  930.                              (MIPS_RESTART_REGNUM
  931.                               + gdbarch_num_regs (gdbarch)),
  932.                              regs_base + SIGCONTEXT_REGS);

  933.   for (ireg = 1; ireg < 32; ireg++)
  934.     trad_frame_set_reg_addr (this_cache,
  935.                              (ireg + MIPS_ZERO_REGNUM
  936.                               + gdbarch_num_regs (gdbarch)),
  937.                              (regs_base + SIGCONTEXT_REGS
  938.                               + ireg * SIGCONTEXT_REG_SIZE));

  939.   /* The way that floating point registers are saved, unfortunately,
  940.      depends on the architecture the kernel is built for.  For the r3000 and
  941.      tx39, four bytes of each register are at the beginning of each of the
  942.      32 eight byte slots.  For everything else, the registers are saved
  943.      using double precision; only the even-numbered slots are initialized,
  944.      and the high bits are the odd-numbered register.  Assume the latter
  945.      layout, since we can't tell, and it's much more common.  Which bits are
  946.      the "high" bits depends on endianness.  */
  947.   for (ireg = 0; ireg < 32; ireg++)
  948.     if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
  949.       trad_frame_set_reg_addr (this_cache,
  950.                                ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
  951.                                (sigcontext_base + SIGCONTEXT_FPREGS + 4
  952.                                 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
  953.     else
  954.       trad_frame_set_reg_addr (this_cache,
  955.                                ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
  956.                                (sigcontext_base + SIGCONTEXT_FPREGS
  957.                                 + (ireg & ~1) * SIGCONTEXT_REG_SIZE));

  958.   trad_frame_set_reg_addr (this_cache,
  959.                            regs->pc + gdbarch_num_regs (gdbarch),
  960.                            regs_base + SIGCONTEXT_PC);

  961.   trad_frame_set_reg_addr (this_cache,
  962.                            (regs->fp_control_status
  963.                             + gdbarch_num_regs (gdbarch)),
  964.                            sigcontext_base + SIGCONTEXT_FPCSR);

  965.   if (regs->dspctl != -1)
  966.     trad_frame_set_reg_addr (this_cache,
  967.                              regs->dspctl + gdbarch_num_regs (gdbarch),
  968.                              sigcontext_base + SIGCONTEXT_DSPCTL);

  969.   trad_frame_set_reg_addr (this_cache,
  970.                            regs->hi + gdbarch_num_regs (gdbarch),
  971.                            regs_base + SIGCONTEXT_HI);
  972.   trad_frame_set_reg_addr (this_cache,
  973.                            regs->lo + gdbarch_num_regs (gdbarch),
  974.                            regs_base + SIGCONTEXT_LO);

  975.   if (regs->dspacc != -1)
  976.     {
  977.       trad_frame_set_reg_addr (this_cache,
  978.                                regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
  979.                                sigcontext_base + SIGCONTEXT_HI1);
  980.       trad_frame_set_reg_addr (this_cache,
  981.                                regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
  982.                                sigcontext_base + SIGCONTEXT_LO1);
  983.       trad_frame_set_reg_addr (this_cache,
  984.                                regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
  985.                                sigcontext_base + SIGCONTEXT_HI2);
  986.       trad_frame_set_reg_addr (this_cache,
  987.                                regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
  988.                                sigcontext_base + SIGCONTEXT_LO2);
  989.       trad_frame_set_reg_addr (this_cache,
  990.                                regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
  991.                                sigcontext_base + SIGCONTEXT_HI3);
  992.       trad_frame_set_reg_addr (this_cache,
  993.                                regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
  994.                                sigcontext_base + SIGCONTEXT_LO3);
  995.     }
  996.   else
  997.     {
  998.       trad_frame_set_reg_addr (this_cache,
  999.                                regs->cause + gdbarch_num_regs (gdbarch),
  1000.                                sigcontext_base + SIGCONTEXT_CAUSE);
  1001.       trad_frame_set_reg_addr (this_cache,
  1002.                                regs->badvaddr + gdbarch_num_regs (gdbarch),
  1003.                                sigcontext_base + SIGCONTEXT_BADVADDR);
  1004.     }

  1005.   /* Choice of the bottom of the sigframe is somewhat arbitrary.  */
  1006.   trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
  1007. }

  1008. /* *INDENT-OFF* */
  1009. /* For N32/N64 things look different.  There is no non-rt signal frame.

  1010.   struct rt_sigframe_n32 {
  1011.     u32 rs_ass[4];                  [ argument save space for o32 ]
  1012.     u32 rs_code[2];                 [ signal trampoline or fill ]
  1013.     struct siginfo rs_info;
  1014.     struct ucontextn32 rs_uc;
  1015.   };

  1016.   struct ucontextn32 {
  1017.     u32                 uc_flags;
  1018.     s32                 uc_link;
  1019.     stack32_t           uc_stack;
  1020.     struct sigcontext   uc_mcontext;
  1021.     sigset_t            uc_sigmask;   [ mask last for extensibility ]
  1022.   };

  1023.   struct rt_sigframe {
  1024.     u32 rs_ass[4];                  [ argument save space for o32 ]
  1025.     u32 rs_code[2];                 [ signal trampoline ]
  1026.     struct siginfo rs_info;
  1027.     struct ucontext rs_uc;
  1028.   };

  1029.   struct ucontext {
  1030.     unsigned long     uc_flags;
  1031.     struct ucontext  *uc_link;
  1032.     stack_t           uc_stack;
  1033.     struct sigcontext uc_mcontext;
  1034.     sigset_t          uc_sigmask;   [ mask last for extensibility ]
  1035.   };

  1036.   And the sigcontext is different (this is for both n32 and n64):

  1037.   struct sigcontext {
  1038.     unsigned long long sc_regs[32];
  1039.     unsigned long long sc_fpregs[32];
  1040.     unsigned long long sc_mdhi;
  1041.     unsigned long long sc_hi1;
  1042.     unsigned long long sc_hi2;
  1043.     unsigned long long sc_hi3;
  1044.     unsigned long long sc_mdlo;
  1045.     unsigned long long sc_lo1;
  1046.     unsigned long long sc_lo2;
  1047.     unsigned long long sc_lo3;
  1048.     unsigned long long sc_pc;
  1049.     unsigned int       sc_fpc_csr;
  1050.     unsigned int       sc_used_math;
  1051.     unsigned int       sc_dsp;
  1052.     unsigned int       sc_reserved;
  1053.   };

  1054.   That is the post-2.6.12 definition of the 64-bit sigcontext; before
  1055.   then, there were no hi1-hi3 or lo1-lo3.  Cause and badvaddr were
  1056.   included too.  */
  1057. /* *INDENT-ON* */

  1058. #define N32_STACK_T_SIZE                STACK_T_SIZE
  1059. #define N64_STACK_T_SIZE                (2 * 8 + 4)
  1060. #define N32_UCONTEXT_SIGCONTEXT_OFFSET  (2 * 4 + N32_STACK_T_SIZE + 4)
  1061. #define N64_UCONTEXT_SIGCONTEXT_OFFSET  (2 * 8 + N64_STACK_T_SIZE + 4)
  1062. #define N32_SIGFRAME_SIGCONTEXT_OFFSET        (SIGFRAME_SIGCONTEXT_OFFSET \
  1063.                                          + RTSIGFRAME_SIGINFO_SIZE \
  1064.                                          + N32_UCONTEXT_SIGCONTEXT_OFFSET)
  1065. #define N64_SIGFRAME_SIGCONTEXT_OFFSET        (SIGFRAME_SIGCONTEXT_OFFSET \
  1066.                                          + RTSIGFRAME_SIGINFO_SIZE \
  1067.                                          + N64_UCONTEXT_SIGCONTEXT_OFFSET)

  1068. #define N64_SIGCONTEXT_REGS     (0 * 8)
  1069. #define N64_SIGCONTEXT_FPREGS   (32 * 8)
  1070. #define N64_SIGCONTEXT_HI       (64 * 8)
  1071. #define N64_SIGCONTEXT_HI1      (65 * 8)
  1072. #define N64_SIGCONTEXT_HI2      (66 * 8)
  1073. #define N64_SIGCONTEXT_HI3      (67 * 8)
  1074. #define N64_SIGCONTEXT_LO       (68 * 8)
  1075. #define N64_SIGCONTEXT_LO1      (69 * 8)
  1076. #define N64_SIGCONTEXT_LO2      (70 * 8)
  1077. #define N64_SIGCONTEXT_LO3      (71 * 8)
  1078. #define N64_SIGCONTEXT_PC       (72 * 8)
  1079. #define N64_SIGCONTEXT_FPCSR    (73 * 8 + 0)
  1080. #define N64_SIGCONTEXT_DSPCTL   (74 * 8 + 0)

  1081. #define N64_SIGCONTEXT_REG_SIZE 8

  1082. static void
  1083. mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
  1084.                                  struct frame_info *this_frame,
  1085.                                  struct trad_frame_cache *this_cache,
  1086.                                  CORE_ADDR func)
  1087. {
  1088.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1089.   int ireg;
  1090.   CORE_ADDR frame_sp = get_frame_sp (this_frame);
  1091.   CORE_ADDR sigcontext_base;
  1092.   const struct mips_regnum *regs = mips_regnum (gdbarch);

  1093.   if (self == &mips_linux_n32_rt_sigframe
  1094.       || self == &micromips_linux_n32_rt_sigframe)
  1095.     sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
  1096.   else
  1097.     sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;

  1098.   if (mips_linux_restart_reg_p (gdbarch))
  1099.     trad_frame_set_reg_addr (this_cache,
  1100.                              (MIPS_RESTART_REGNUM
  1101.                               + gdbarch_num_regs (gdbarch)),
  1102.                              sigcontext_base + N64_SIGCONTEXT_REGS);

  1103.   for (ireg = 1; ireg < 32; ireg++)
  1104.     trad_frame_set_reg_addr (this_cache,
  1105.                              (ireg + MIPS_ZERO_REGNUM
  1106.                               + gdbarch_num_regs (gdbarch)),
  1107.                              (sigcontext_base + N64_SIGCONTEXT_REGS
  1108.                               + ireg * N64_SIGCONTEXT_REG_SIZE));

  1109.   for (ireg = 0; ireg < 32; ireg++)
  1110.     trad_frame_set_reg_addr (this_cache,
  1111.                              ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
  1112.                              (sigcontext_base + N64_SIGCONTEXT_FPREGS
  1113.                               + ireg * N64_SIGCONTEXT_REG_SIZE));

  1114.   trad_frame_set_reg_addr (this_cache,
  1115.                            regs->pc + gdbarch_num_regs (gdbarch),
  1116.                            sigcontext_base + N64_SIGCONTEXT_PC);

  1117.   trad_frame_set_reg_addr (this_cache,
  1118.                            (regs->fp_control_status
  1119.                             + gdbarch_num_regs (gdbarch)),
  1120.                            sigcontext_base + N64_SIGCONTEXT_FPCSR);

  1121.   trad_frame_set_reg_addr (this_cache,
  1122.                            regs->hi + gdbarch_num_regs (gdbarch),
  1123.                            sigcontext_base + N64_SIGCONTEXT_HI);
  1124.   trad_frame_set_reg_addr (this_cache,
  1125.                            regs->lo + gdbarch_num_regs (gdbarch),
  1126.                            sigcontext_base + N64_SIGCONTEXT_LO);

  1127.   if (regs->dspacc != -1)
  1128.     {
  1129.       trad_frame_set_reg_addr (this_cache,
  1130.                                regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
  1131.                                sigcontext_base + N64_SIGCONTEXT_HI1);
  1132.       trad_frame_set_reg_addr (this_cache,
  1133.                                regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
  1134.                                sigcontext_base + N64_SIGCONTEXT_LO1);
  1135.       trad_frame_set_reg_addr (this_cache,
  1136.                                regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
  1137.                                sigcontext_base + N64_SIGCONTEXT_HI2);
  1138.       trad_frame_set_reg_addr (this_cache,
  1139.                                regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
  1140.                                sigcontext_base + N64_SIGCONTEXT_LO2);
  1141.       trad_frame_set_reg_addr (this_cache,
  1142.                                regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
  1143.                                sigcontext_base + N64_SIGCONTEXT_HI3);
  1144.       trad_frame_set_reg_addr (this_cache,
  1145.                                regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
  1146.                                sigcontext_base + N64_SIGCONTEXT_LO3);
  1147.     }
  1148.   if (regs->dspctl != -1)
  1149.     trad_frame_set_reg_addr (this_cache,
  1150.                              regs->dspctl + gdbarch_num_regs (gdbarch),
  1151.                              sigcontext_base + N64_SIGCONTEXT_DSPCTL);

  1152.   /* Choice of the bottom of the sigframe is somewhat arbitrary.  */
  1153.   trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
  1154. }

  1155. /* Implement struct tramp_frame's "validate" method for standard MIPS code.  */

  1156. static int
  1157. mips_linux_sigframe_validate (const struct tramp_frame *self,
  1158.                               struct frame_info *this_frame,
  1159.                               CORE_ADDR *pc)
  1160. {
  1161.   return mips_pc_is_mips (*pc);
  1162. }

  1163. /* Implement struct tramp_frame's "validate" method for microMIPS code.  */

  1164. static int
  1165. micromips_linux_sigframe_validate (const struct tramp_frame *self,
  1166.                                    struct frame_info *this_frame,
  1167.                                    CORE_ADDR *pc)
  1168. {
  1169.   if (mips_pc_is_micromips (get_frame_arch (this_frame), *pc))
  1170.     {
  1171.       *pc = mips_unmake_compact_addr (*pc);
  1172.       return 1;
  1173.     }
  1174.   else
  1175.     return 0;
  1176. }

  1177. /* Implement the "write_pc" gdbarch method.  */

  1178. static void
  1179. mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
  1180. {
  1181.   struct gdbarch *gdbarch = get_regcache_arch (regcache);

  1182.   mips_write_pc (regcache, pc);

  1183.   /* Clear the syscall restart flag.  */
  1184.   if (mips_linux_restart_reg_p (gdbarch))
  1185.     regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
  1186. }

  1187. /* Return 1 if MIPS_RESTART_REGNUM is usable.  */

  1188. int
  1189. mips_linux_restart_reg_p (struct gdbarch *gdbarch)
  1190. {
  1191.   /* If we do not have a target description with registers, then
  1192.      MIPS_RESTART_REGNUM will not be included in the register set.  */
  1193.   if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
  1194.     return 0;

  1195.   /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
  1196.      either be GPR-sized or missing.  */
  1197.   return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
  1198. }

  1199. /* When FRAME is at a syscall instruction, return the PC of the next
  1200.    instruction to be executed.  */

  1201. static CORE_ADDR
  1202. mips_linux_syscall_next_pc (struct frame_info *frame)
  1203. {
  1204.   CORE_ADDR pc = get_frame_pc (frame);
  1205.   ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);

  1206.   /* If we are about to make a sigreturn syscall, use the unwinder to
  1207.      decode the signal frame.  */
  1208.   if (v0 == MIPS_NR_sigreturn
  1209.       || v0 == MIPS_NR_rt_sigreturn
  1210.       || v0 == MIPS_NR_N64_rt_sigreturn
  1211.       || v0 == MIPS_NR_N32_rt_sigreturn)
  1212.     return frame_unwind_caller_pc (get_current_frame ());

  1213.   return pc + 4;
  1214. }

  1215. /* Return the current system call's number present in the
  1216.    v0 register.  When the function fails, it returns -1.  */

  1217. static LONGEST
  1218. mips_linux_get_syscall_number (struct gdbarch *gdbarch,
  1219.                                ptid_t ptid)
  1220. {
  1221.   struct regcache *regcache = get_thread_regcache (ptid);
  1222.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  1223.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1224.   int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
  1225.   /* The content of a register */
  1226.   gdb_byte buf[8];
  1227.   /* The result */
  1228.   LONGEST ret;

  1229.   /* Make sure we're in a known ABI */
  1230.   gdb_assert (tdep->mips_abi == MIPS_ABI_O32
  1231.               || tdep->mips_abi == MIPS_ABI_N32
  1232.               || tdep->mips_abi == MIPS_ABI_N64);

  1233.   gdb_assert (regsize <= sizeof (buf));

  1234.   /* Getting the system call number from the register.
  1235.      syscall number is in v0 or $2.  */
  1236.   regcache_cooked_read (regcache, MIPS_V0_REGNUM, buf);

  1237.   ret = extract_signed_integer (buf, regsize, byte_order);

  1238.   return ret;
  1239. }

  1240. /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
  1241.    gdbarch.h.  */

  1242. static int
  1243. mips_gdb_signal_to_target (struct gdbarch *gdbarch,
  1244.                            enum gdb_signal signal)
  1245. {
  1246.   switch (signal)
  1247.     {
  1248.     case GDB_SIGNAL_EMT:
  1249.       return MIPS_LINUX_SIGEMT;

  1250.     case GDB_SIGNAL_BUS:
  1251.       return MIPS_LINUX_SIGBUS;

  1252.     case GDB_SIGNAL_SYS:
  1253.       return MIPS_LINUX_SIGSYS;

  1254.     case GDB_SIGNAL_USR1:
  1255.       return MIPS_LINUX_SIGUSR1;

  1256.     case GDB_SIGNAL_USR2:
  1257.       return MIPS_LINUX_SIGUSR2;

  1258.     case GDB_SIGNAL_CHLD:
  1259.       return MIPS_LINUX_SIGCHLD;

  1260.     case GDB_SIGNAL_PWR:
  1261.       return MIPS_LINUX_SIGPWR;

  1262.     case GDB_SIGNAL_WINCH:
  1263.       return MIPS_LINUX_SIGWINCH;

  1264.     case GDB_SIGNAL_URG:
  1265.       return MIPS_LINUX_SIGURG;

  1266.     case GDB_SIGNAL_IO:
  1267.       return MIPS_LINUX_SIGIO;

  1268.     case GDB_SIGNAL_POLL:
  1269.       return MIPS_LINUX_SIGPOLL;

  1270.     case GDB_SIGNAL_STOP:
  1271.       return MIPS_LINUX_SIGSTOP;

  1272.     case GDB_SIGNAL_TSTP:
  1273.       return MIPS_LINUX_SIGTSTP;

  1274.     case GDB_SIGNAL_CONT:
  1275.       return MIPS_LINUX_SIGCONT;

  1276.     case GDB_SIGNAL_TTIN:
  1277.       return MIPS_LINUX_SIGTTIN;

  1278.     case GDB_SIGNAL_TTOU:
  1279.       return MIPS_LINUX_SIGTTOU;

  1280.     case GDB_SIGNAL_VTALRM:
  1281.       return MIPS_LINUX_SIGVTALRM;

  1282.     case GDB_SIGNAL_PROF:
  1283.       return MIPS_LINUX_SIGPROF;

  1284.     case GDB_SIGNAL_XCPU:
  1285.       return MIPS_LINUX_SIGXCPU;

  1286.     case GDB_SIGNAL_XFSZ:
  1287.       return MIPS_LINUX_SIGXFSZ;

  1288.     /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
  1289.        therefore we have to handle it here.  */
  1290.     case GDB_SIGNAL_REALTIME_32:
  1291.       return MIPS_LINUX_SIGRTMIN;
  1292.     }

  1293.   if (signal >= GDB_SIGNAL_REALTIME_33
  1294.       && signal <= GDB_SIGNAL_REALTIME_63)
  1295.     {
  1296.       int offset = signal - GDB_SIGNAL_REALTIME_33;

  1297.       return MIPS_LINUX_SIGRTMIN + 1 + offset;
  1298.     }
  1299.   else if (signal >= GDB_SIGNAL_REALTIME_64
  1300.            && signal <= GDB_SIGNAL_REALTIME_127)
  1301.     {
  1302.       int offset = signal - GDB_SIGNAL_REALTIME_64;

  1303.       return MIPS_LINUX_SIGRT64 + offset;
  1304.     }

  1305.   return linux_gdb_signal_to_target (gdbarch, signal);
  1306. }

  1307. /* Translate signals based on MIPS signal values.
  1308.    Adapted from gdb/common/signals.c.  */

  1309. static enum gdb_signal
  1310. mips_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
  1311. {
  1312.   switch (signal)
  1313.     {
  1314.     case MIPS_LINUX_SIGEMT:
  1315.       return GDB_SIGNAL_EMT;

  1316.     case MIPS_LINUX_SIGBUS:
  1317.       return GDB_SIGNAL_BUS;

  1318.     case MIPS_LINUX_SIGSYS:
  1319.       return GDB_SIGNAL_SYS;

  1320.     case MIPS_LINUX_SIGUSR1:
  1321.       return GDB_SIGNAL_USR1;

  1322.     case MIPS_LINUX_SIGUSR2:
  1323.       return GDB_SIGNAL_USR2;

  1324.     case MIPS_LINUX_SIGCHLD:
  1325.       return GDB_SIGNAL_CHLD;

  1326.     case MIPS_LINUX_SIGPWR:
  1327.       return GDB_SIGNAL_PWR;

  1328.     case MIPS_LINUX_SIGWINCH:
  1329.       return GDB_SIGNAL_WINCH;

  1330.     case MIPS_LINUX_SIGURG:
  1331.       return GDB_SIGNAL_URG;

  1332.     /* No way to differentiate between SIGIO and SIGPOLL.
  1333.        Therefore, we just handle the first one.  */
  1334.     case MIPS_LINUX_SIGIO:
  1335.       return GDB_SIGNAL_IO;

  1336.     case MIPS_LINUX_SIGSTOP:
  1337.       return GDB_SIGNAL_STOP;

  1338.     case MIPS_LINUX_SIGTSTP:
  1339.       return GDB_SIGNAL_TSTP;

  1340.     case MIPS_LINUX_SIGCONT:
  1341.       return GDB_SIGNAL_CONT;

  1342.     case MIPS_LINUX_SIGTTIN:
  1343.       return GDB_SIGNAL_TTIN;

  1344.     case MIPS_LINUX_SIGTTOU:
  1345.       return GDB_SIGNAL_TTOU;

  1346.     case MIPS_LINUX_SIGVTALRM:
  1347.       return GDB_SIGNAL_VTALRM;

  1348.     case MIPS_LINUX_SIGPROF:
  1349.       return GDB_SIGNAL_PROF;

  1350.     case MIPS_LINUX_SIGXCPU:
  1351.       return GDB_SIGNAL_XCPU;

  1352.     case MIPS_LINUX_SIGXFSZ:
  1353.       return GDB_SIGNAL_XFSZ;
  1354.     }

  1355.   if (signal >= MIPS_LINUX_SIGRTMIN && signal <= MIPS_LINUX_SIGRTMAX)
  1356.     {
  1357.       /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
  1358.          the MIPS block to the respective GDB_SIGNAL_REALTIME blocks.  */
  1359.       int offset = signal - MIPS_LINUX_SIGRTMIN;

  1360.       if (offset == 0)
  1361.         return GDB_SIGNAL_REALTIME_32;
  1362.       else if (offset < 32)
  1363.         return (enum gdb_signal) (offset - 1
  1364.                                   + (int) GDB_SIGNAL_REALTIME_33);
  1365.       else
  1366.         return (enum gdb_signal) (offset - 32
  1367.                                   + (int) GDB_SIGNAL_REALTIME_64);
  1368.     }

  1369.   return linux_gdb_signal_from_target (gdbarch, signal);
  1370. }

  1371. /* Initialize one of the GNU/Linux OS ABIs.  */

  1372. static void
  1373. mips_linux_init_abi (struct gdbarch_info info,
  1374.                      struct gdbarch *gdbarch)
  1375. {
  1376.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  1377.   enum mips_abi abi = mips_abi (gdbarch);
  1378.   struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;

  1379.   linux_init_abi (info, gdbarch);

  1380.   /* Get the syscall number from the arch's register.  */
  1381.   set_gdbarch_get_syscall_number (gdbarch, mips_linux_get_syscall_number);

  1382.   switch (abi)
  1383.     {
  1384.       case MIPS_ABI_O32:
  1385.         set_gdbarch_get_longjmp_target (gdbarch,
  1386.                                         mips_linux_get_longjmp_target);
  1387.         set_solib_svr4_fetch_link_map_offsets
  1388.           (gdbarch, svr4_ilp32_fetch_link_map_offsets);
  1389.         tramp_frame_prepend_unwinder (gdbarch, &micromips_linux_o32_sigframe);
  1390.         tramp_frame_prepend_unwinder (gdbarch,
  1391.                                       &micromips_linux_o32_rt_sigframe);
  1392.         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
  1393.         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
  1394.         set_xml_syscall_file_name (gdbarch, "syscalls/mips-o32-linux.xml");
  1395.         break;
  1396.       case MIPS_ABI_N32:
  1397.         set_gdbarch_get_longjmp_target (gdbarch,
  1398.                                         mips_linux_get_longjmp_target);
  1399.         set_solib_svr4_fetch_link_map_offsets
  1400.           (gdbarch, svr4_ilp32_fetch_link_map_offsets);
  1401.         set_gdbarch_long_double_bit (gdbarch, 128);
  1402.         /* These floatformats should probably be renamed.  MIPS uses
  1403.            the same 128-bit IEEE floating point format that IA-64 uses,
  1404.            except that the quiet/signalling NaN bit is reversed (GDB
  1405.            does not distinguish between quiet and signalling NaNs).  */
  1406.         set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
  1407.         tramp_frame_prepend_unwinder (gdbarch,
  1408.                                       &micromips_linux_n32_rt_sigframe);
  1409.         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
  1410.         set_xml_syscall_file_name (gdbarch, "syscalls/mips-n32-linux.xml");
  1411.         break;
  1412.       case MIPS_ABI_N64:
  1413.         set_gdbarch_get_longjmp_target (gdbarch,
  1414.                                         mips64_linux_get_longjmp_target);
  1415.         set_solib_svr4_fetch_link_map_offsets
  1416.           (gdbarch, svr4_lp64_fetch_link_map_offsets);
  1417.         set_gdbarch_long_double_bit (gdbarch, 128);
  1418.         /* These floatformats should probably be renamed.  MIPS uses
  1419.            the same 128-bit IEEE floating point format that IA-64 uses,
  1420.            except that the quiet/signalling NaN bit is reversed (GDB
  1421.            does not distinguish between quiet and signalling NaNs).  */
  1422.         set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
  1423.         tramp_frame_prepend_unwinder (gdbarch,
  1424.                                       &micromips_linux_n64_rt_sigframe);
  1425.         tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
  1426.         set_xml_syscall_file_name (gdbarch, "syscalls/mips-n64-linux.xml");
  1427.         break;
  1428.       default:
  1429.         break;
  1430.     }

  1431.   set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);

  1432.   set_gdbarch_software_single_step (gdbarch, mips_software_single_step);

  1433.   /* Enable TLS support.  */
  1434.   set_gdbarch_fetch_tls_load_module_address (gdbarch,
  1435.                                              svr4_fetch_objfile_link_map);

  1436.   /* Initialize this lazily, to avoid an initialization order
  1437.      dependency on solib-svr4.c's _initialize routine.  */
  1438.   if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
  1439.     {
  1440.       mips_svr4_so_ops = svr4_so_ops;
  1441.       mips_svr4_so_ops.in_dynsym_resolve_code
  1442.         = mips_linux_in_dynsym_resolve_code;
  1443.     }
  1444.   set_solib_ops (gdbarch, &mips_svr4_so_ops);

  1445.   set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);

  1446.   set_gdbarch_core_read_description (gdbarch,
  1447.                                      mips_linux_core_read_description);

  1448.   set_gdbarch_iterate_over_regset_sections
  1449.     (gdbarch, mips_linux_iterate_over_regset_sections);

  1450.   set_gdbarch_gdb_signal_from_target (gdbarch,
  1451.                                       mips_gdb_signal_from_target);

  1452.   set_gdbarch_gdb_signal_to_target (gdbarch,
  1453.                                     mips_gdb_signal_to_target);

  1454.   tdep->syscall_next_pc = mips_linux_syscall_next_pc;

  1455.   if (tdesc_data)
  1456.     {
  1457.       const struct tdesc_feature *feature;

  1458.       /* If we have target-described registers, then we can safely
  1459.          reserve a number for MIPS_RESTART_REGNUM (whether it is
  1460.          described or not).  */
  1461.       gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
  1462.       set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
  1463.       set_gdbarch_num_pseudo_regs (gdbarch, MIPS_RESTART_REGNUM + 1);

  1464.       /* If it's present, then assign it to the reserved number.  */
  1465.       feature = tdesc_find_feature (info.target_desc,
  1466.                                     "org.gnu.gdb.mips.linux");
  1467.       if (feature != NULL)
  1468.         tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
  1469.                                  "restart");
  1470.     }
  1471. }

  1472. /* Provide a prototype to silence -Wmissing-prototypes.  */
  1473. extern initialize_file_ftype _initialize_mips_linux_tdep;

  1474. void
  1475. _initialize_mips_linux_tdep (void)
  1476. {
  1477.   const struct bfd_arch_info *arch_info;

  1478.   for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
  1479.        arch_info != NULL;
  1480.        arch_info = arch_info->next)
  1481.     {
  1482.       gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
  1483.                               GDB_OSABI_LINUX,
  1484.                               mips_linux_init_abi);
  1485.     }
  1486. }