gdb/nios2-linux-tdep.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Target-dependent code for GNU/Linux on Nios II.
  2.    Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3.    Contributed by Mentor Graphics, Inc.

  4.    This file is part of GDB.

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

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

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

  15. #include "defs.h"
  16. #include "frame.h"
  17. #include "osabi.h"
  18. #include "solib-svr4.h"
  19. #include "trad-frame.h"
  20. #include "tramp-frame.h"
  21. #include "symtab.h"
  22. #include "regset.h"
  23. #include "regcache.h"
  24. #include "linux-tdep.h"
  25. #include "glibc-tdep.h"
  26. #include "nios2-tdep.h"

  27. #include "features/nios2-linux.c"

  28. /* Core file and register set support.  */

  29. /* Map from the normal register enumeration order to the order that
  30.    registers appear in core files, which corresponds to the order
  31.    of the register slots in the kernel's struct pt_regs.  */

  32. static const int reg_offsets[NIOS2_NUM_REGS] =
  33. {
  34.   -189, 10, 11, 12, 13, 14,        /* r0 - r7 */
  35.   01234567,        /* r8 - r15 */
  36.   23, 24, 25, 26, 27, 28, 29, 30,        /* r16 - r23 */
  37.   -1, -1, 19, 18, 17, 21, -1, 16,        /* et bt gp sp fp ea sstatus ra */
  38.   21,                                        /* pc */
  39.   -1, 20, -1, -1, -1, -1, -1, -1,        /* status estatus ...  */
  40.   -1, -1, -1, -1, -1, -1, -1, -1
  41. };

  42. /* General register set size.  Should match sizeof (struct pt_regs) +
  43.    sizeof (struct switch_stack) from the NIOS2 Linux kernel patch.  */

  44. #define NIOS2_GREGS_SIZE (4 * 34)

  45. /* Implement the supply_regset hook for core files.  */

  46. static void
  47. nios2_supply_gregset (const struct regset *regset,
  48.                       struct regcache *regcache,
  49.                       int regnum, const void *gregs_buf, size_t len)
  50. {
  51.   const gdb_byte *gregs = gregs_buf;
  52.   int regno;
  53.   static const gdb_byte zero_buf[4] = {0, 0, 0, 0};

  54.   for (regno = NIOS2_Z_REGNUM; regno <= NIOS2_MPUACC_REGNUM; regno++)
  55.     if (regnum == -1 || regnum == regno)
  56.       {
  57.         if (reg_offsets[regno] != -1)
  58.           regcache_raw_supply (regcache, regno,
  59.                                gregs + 4 * reg_offsets[regno]);
  60.         else
  61.           regcache_raw_supply (regcache, regno, zero_buf);
  62.       }
  63. }

  64. /* Implement the collect_regset hook for core files.  */

  65. static void
  66. nios2_collect_gregset (const struct regset *regset,
  67.                        const struct regcache *regcache,
  68.                        int regnum, void *gregs_buf, size_t len)
  69. {
  70.   gdb_byte *gregs = gregs_buf;
  71.   int regno;

  72.   for (regno = NIOS2_Z_REGNUM; regno <= NIOS2_MPUACC_REGNUM; regno++)
  73.     if (regnum == -1 || regnum == regno)
  74.       {
  75.         if (reg_offsets[regno] != -1)
  76.           regcache_raw_collect (regcache, regno,
  77.                                 gregs + 4 * reg_offsets[regno]);
  78.       }
  79. }

  80. static const struct regset nios2_core_regset =
  81. {
  82.   NULL,
  83.   nios2_supply_gregset,
  84.   nios2_collect_gregset
  85. };

  86. /* Iterate over core file register note sections.  */

  87. static void
  88. nios2_iterate_over_regset_sections (struct gdbarch *gdbarch,
  89.                                     iterate_over_regset_sections_cb *cb,
  90.                                     void *cb_data,
  91.                                     const struct regcache *regcache)
  92. {
  93.   cb (".reg", NIOS2_GREGS_SIZE, &nios2_core_regset, NULL, cb_data);
  94. }

  95. /* Initialize a trad-frame cache corresponding to the tramp-frame.
  96.    FUNC is the address of the instruction TRAMP[0] in memory.  */

  97. static void
  98. nios2_linux_rt_sigreturn_init (const struct tramp_frame *self,
  99.                                struct frame_info *next_frame,
  100.                                struct trad_frame_cache *this_cache,
  101.                                CORE_ADDR func)
  102. {
  103.   CORE_ADDR base = func + 41 * 4;
  104.   int i;

  105.   for (i = 0; i < 23; i++)
  106.     trad_frame_set_reg_addr (this_cache, i + 1, base + i * 4);
  107.   trad_frame_set_reg_addr (this_cache, NIOS2_RA_REGNUM, base + 23 * 4);
  108.   trad_frame_set_reg_addr (this_cache, NIOS2_FP_REGNUM, base + 24 * 4);
  109.   trad_frame_set_reg_addr (this_cache, NIOS2_GP_REGNUM, base + 25 * 4);
  110.   trad_frame_set_reg_addr (this_cache, NIOS2_PC_REGNUM, base + 27 * 4);
  111.   trad_frame_set_reg_addr (this_cache, NIOS2_SP_REGNUM, base + 28 * 4);

  112.   /* Save a frame ID.  */
  113.   trad_frame_set_id (this_cache, frame_id_build (base, func));
  114. }

  115. static struct tramp_frame nios2_linux_rt_sigreturn_tramp_frame =
  116. {
  117.   SIGTRAMP_FRAME,
  118.   4,
  119.   {
  120.     { 0x00800004 | (139 << 6), -1 },  /* movi r2,__NR_rt_sigreturn */
  121.     { 0x003b683a, -1 },               /* trap */
  122.     { TRAMP_SENTINEL_INSN }
  123.   },
  124.   nios2_linux_rt_sigreturn_init
  125. };

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

  128. static CORE_ADDR
  129. nios2_linux_syscall_next_pc (struct frame_info *frame)
  130. {
  131.   CORE_ADDR pc = get_frame_pc (frame);
  132.   ULONGEST syscall_nr = get_frame_register_unsigned (frame, NIOS2_R2_REGNUM);

  133.   /* If we are about to make a sigreturn syscall, use the unwinder to
  134.      decode the signal frame.  */
  135.   if (syscall_nr == 139 /* rt_sigreturn */)
  136.     return frame_unwind_caller_pc (frame);

  137.   return pc + NIOS2_OPCODE_SIZE;
  138. }

  139. /* Hook function for gdbarch_register_osabi.  */

  140. static void
  141. nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  142. {
  143.   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

  144.   linux_init_abi (info, gdbarch);

  145.   /* Shared library handling.  */
  146.   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  147.   set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);

  148.   set_solib_svr4_fetch_link_map_offsets (gdbarch,
  149.                                          svr4_ilp32_fetch_link_map_offsets);
  150.   /* Enable TLS support.  */
  151.   set_gdbarch_fetch_tls_load_module_address (gdbarch,
  152.                                              svr4_fetch_objfile_link_map);
  153.   /* Core file support.  */
  154.   set_gdbarch_iterate_over_regset_sections
  155.     (gdbarch, nios2_iterate_over_regset_sections);
  156.   /* Linux signal frame unwinders.  */
  157.   tramp_frame_prepend_unwinder (gdbarch,
  158.                                 &nios2_linux_rt_sigreturn_tramp_frame);

  159.   tdep->syscall_next_pc = nios2_linux_syscall_next_pc;

  160.   /* Index of target address word in glibc jmp_buf.  */
  161.   tdep->jb_pc = 10;
  162. }

  163. /* Provide a prototype to silence -Wmissing-prototypes.  */

  164. extern initialize_file_ftype _initialize_nios2_linux_tdep;

  165. void
  166. _initialize_nios2_linux_tdep (void)
  167. {
  168.   gdbarch_register_osabi (bfd_arch_nios2, 0, GDB_OSABI_LINUX,
  169.                           nios2_linux_init_abi);

  170.   initialize_tdesc_nios2_linux ();
  171. }