gdb/sh-linux-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for GNU/Linux Super-H.

  2.    Copyright (C) 2005-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 "osabi.h"

  16. #include "solib-svr4.h"
  17. #include "symtab.h"

  18. #include "trad-frame.h"
  19. #include "tramp-frame.h"

  20. #include "glibc-tdep.h"
  21. #include "sh-tdep.h"
  22. #include "linux-tdep.h"

  23. #define REGSx16(base) \
  24.   {(base),      0}, \
  25.   {(base) +  1, 4}, \
  26.   {(base) +  2, 8}, \
  27.   {(base) +  3, 12}, \
  28.   {(base) +  4, 16}, \
  29.   {(base) +  5, 20}, \
  30.   {(base) +  6, 24}, \
  31.   {(base) +  7, 28}, \
  32.   {(base) +  8, 32}, \
  33.   {(base) +  9, 36}, \
  34.   {(base) + 10, 40}, \
  35.   {(base) + 11, 44}, \
  36.   {(base) + 12, 48}, \
  37.   {(base) + 13, 52}, \
  38.   {(base) + 14, 56}, \
  39.   {(base) + 15, 60}

  40. /* Describe the contents of the .reg section of the core file.  */

  41. static const struct sh_corefile_regmap gregs_table[] =
  42. {
  43.   REGSx16 (R0_REGNUM),
  44.   {PC_REGNUM,   64},
  45.   {PR_REGNUM,   68},
  46.   {SR_REGNUM,   72},
  47.   {GBR_REGNUM,  76},
  48.   {MACH_REGNUM, 80},
  49.   {MACL_REGNUM, 84},
  50.   {-1 /* Terminator.  */, 0}
  51. };

  52. /* Describe the contents of the .reg2 section of the core file.  */

  53. static const struct sh_corefile_regmap fpregs_table[] =
  54. {
  55.   REGSx16 (FR0_REGNUM),
  56.   /* REGSx16 xfp_regs omitted.  */
  57.   {FPSCR_REGNUM, 128},
  58.   {FPUL_REGNUM,  132},
  59.   {-1 /* Terminator.  */, 0}
  60. };

  61. /* SH signal handler frame support.  */

  62. static void
  63. sh_linux_sigtramp_cache (struct frame_info *this_frame,
  64.                          struct trad_frame_cache *this_cache,
  65.                          CORE_ADDR func, int regs_offset)
  66. {
  67.   int i;
  68.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  69.   CORE_ADDR base = get_frame_register_unsigned (this_frame,
  70.                                                 gdbarch_sp_regnum (gdbarch));
  71.   CORE_ADDR regs = base + regs_offset;

  72.   for (i = 0; i < 18; i++)
  73.     trad_frame_set_reg_addr (this_cache, i, regs + i * 4);

  74.   trad_frame_set_reg_addr (this_cache, SR_REGNUM, regs + 18 * 4);
  75.   trad_frame_set_reg_addr (this_cache, GBR_REGNUM, regs + 19 * 4);
  76.   trad_frame_set_reg_addr (this_cache, MACH_REGNUM, regs + 20 * 4);
  77.   trad_frame_set_reg_addr (this_cache, MACL_REGNUM, regs + 21 * 4);

  78.   /* Restore FP state if we have an FPU.  */
  79.   if (gdbarch_fp0_regnum (gdbarch) != -1)
  80.     {
  81.       CORE_ADDR fpregs = regs + 22 * 4;
  82.       for (i = FR0_REGNUM; i <= FP_LAST_REGNUM; i++)
  83.         trad_frame_set_reg_addr (this_cache, i, fpregs + i * 4);
  84.       trad_frame_set_reg_addr (this_cache, FPSCR_REGNUM, fpregs + 32 * 4);
  85.       trad_frame_set_reg_addr (this_cache, FPUL_REGNUM, fpregs + 33 * 4);
  86.     }

  87.   /* Save a frame ID.  */
  88.   trad_frame_set_id (this_cache, frame_id_build (base, func));
  89. }

  90. /* Implement struct tramp_frame "init" callbacks for signal
  91.    trampolines on 32-bit SH.  */

  92. static void
  93. sh_linux_sigreturn_init (const struct tramp_frame *self,
  94.                          struct frame_info *this_frame,
  95.                          struct trad_frame_cache *this_cache,
  96.                          CORE_ADDR func)
  97. {
  98.   /* SH 32-bit sigframe: sigcontext at start of sigframe,
  99.      registers start after a single 'oldmask' word.  */
  100.   sh_linux_sigtramp_cache (this_frame, this_cache, func, 4);
  101. }

  102. static void
  103. sh_linux_rt_sigreturn_init (const struct tramp_frame *self,
  104.                             struct frame_info *this_frame,
  105.                             struct trad_frame_cache *this_cache,
  106.                             CORE_ADDR func)
  107. {
  108.   /* SH 32-bit rt_sigframe: starts with a siginfo (128 bytes), then
  109.      we can find sigcontext embedded within a ucontext (offset 20 bytes).
  110.      Then registers start after a single 'oldmask' word.  */
  111.   sh_linux_sigtramp_cache (this_frame, this_cache, func,
  112.                            128 /* sizeof (struct siginfo)  */
  113.                            + 20 /* offsetof (struct ucontext, uc_mcontext) */
  114.                            + 4 /* oldmask word at start of sigcontext */);
  115. }

  116. /* Instruction patterns.  */
  117. #define SH_MOVW     0x9305
  118. #define SH_TRAP     0xc300
  119. #define SH_OR_R0_R0 0x200b

  120. /* SH sigreturn syscall numbers.  */
  121. #define SH_NR_SIGRETURN 0x0077
  122. #define SH_NR_RT_SIGRETURN 0x00ad

  123. static struct tramp_frame sh_linux_sigreturn_tramp_frame = {
  124.   SIGTRAMP_FRAME,
  125.   2,
  126.   {
  127.     { SH_MOVW, 0xffff },
  128.     { SH_TRAP, 0xff00 }, /* #imm argument part filtered out.  */
  129.     { SH_OR_R0_R0, 0xffff },
  130.     { SH_OR_R0_R0, 0xffff },
  131.     { SH_OR_R0_R0, 0xffff },
  132.     { SH_OR_R0_R0, 0xffff },
  133.     { SH_OR_R0_R0, 0xffff },
  134.     { SH_NR_SIGRETURN, 0xffff },
  135.     { TRAMP_SENTINEL_INSN }
  136.   },
  137.   sh_linux_sigreturn_init
  138. };

  139. static struct tramp_frame sh_linux_rt_sigreturn_tramp_frame = {
  140.   SIGTRAMP_FRAME,
  141.   2,
  142.   {
  143.     { SH_MOVW, 0xffff },
  144.     { SH_TRAP, 0xff00 }, /* #imm argument part filtered out.  */
  145.     { SH_OR_R0_R0, 0xffff },
  146.     { SH_OR_R0_R0, 0xffff },
  147.     { SH_OR_R0_R0, 0xffff },
  148.     { SH_OR_R0_R0, 0xffff },
  149.     { SH_OR_R0_R0, 0xffff },
  150.     { SH_NR_RT_SIGRETURN, 0xffff },
  151.     { TRAMP_SENTINEL_INSN }
  152.   },
  153.   sh_linux_rt_sigreturn_init
  154. };

  155. static void
  156. sh_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  157. {
  158.   linux_init_abi (info, gdbarch);

  159.   /* GNU/Linux uses SVR4-style shared libraries.  */
  160.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  161.   set_solib_svr4_fetch_link_map_offsets
  162.     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
  163.   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);

  164.   set_gdbarch_fetch_tls_load_module_address (gdbarch,
  165.                                              svr4_fetch_objfile_link_map);

  166.   /* Core files and signal handler frame unwinding are supported for
  167.      32-bit SH only, at present.  */
  168.   if (info.bfd_arch_info->mach != bfd_mach_sh5)
  169.     {
  170.       struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  171.       /* Remember regset characteristics.  The sizes should match
  172.          elf_gregset_t and elf_fpregset_t from Linux.  */
  173.       tdep->core_gregmap = (struct sh_corefile_regmap *)gregs_table;
  174.       tdep->sizeof_gregset = 92;
  175.       tdep->core_fpregmap = (struct sh_corefile_regmap *)fpregs_table;
  176.       tdep->sizeof_fpregset = 136;

  177.       tramp_frame_prepend_unwinder (gdbarch, &sh_linux_sigreturn_tramp_frame);
  178.       tramp_frame_prepend_unwinder (gdbarch, &sh_linux_rt_sigreturn_tramp_frame);
  179.     }
  180. }

  181. /* Provide a prototype to silence -Wmissing-prototypes.  */
  182. extern void _initialize_sh_linux_tdep (void);

  183. void
  184. _initialize_sh_linux_tdep (void)
  185. {
  186.   gdbarch_register_osabi (bfd_arch_sh, 0, GDB_OSABI_LINUX, sh_linux_init_abi);
  187. }