gdb: microblaze: delete useless stubs
[deliverable/binutils-gdb.git] / gdb / nios2-linux-tdep.c
index fe29e7a72666bfc8ef27842b4b0beab672a23eca..0a837b0a0931bdd644d083eb4fcce5855ea65839 100644 (file)
@@ -1,5 +1,5 @@
 /* Target-dependent code for GNU/Linux on Nios II.
-   Copyright (C) 2012-2013 Free Software Foundation, Inc.
+   Copyright (C) 2012-2015 Free Software Foundation, Inc.
    Contributed by Mentor Graphics, Inc.
 
    This file is part of GDB.
@@ -19,8 +19,6 @@
 
 #include "defs.h"
 #include "frame.h"
-#include "gdb_assert.h"
-#include <string.h>
 #include "osabi.h"
 #include "solib-svr4.h"
 #include "trad-frame.h"
@@ -51,6 +49,11 @@ static const int reg_offsets[NIOS2_NUM_REGS] =
   -1, -1, -1, -1, -1, -1, -1, -1
 };
 
+/* General register set size.  Should match sizeof (struct pt_regs) +
+   sizeof (struct switch_stack) from the NIOS2 Linux kernel patch.  */
+
+#define NIOS2_GREGS_SIZE (4 * 34)
+
 /* Implement the supply_regset hook for core files.  */
 
 static void
@@ -73,55 +76,63 @@ nios2_supply_gregset (const struct regset *regset,
       }
 }
 
-static struct regset nios2_core_regset =
+/* Implement the collect_regset hook for core files.  */
+
+static void
+nios2_collect_gregset (const struct regset *regset,
+                      const struct regcache *regcache,
+                      int regnum, void *gregs_buf, size_t len)
+{
+  gdb_byte *gregs = gregs_buf;
+  int regno;
+
+  for (regno = NIOS2_Z_REGNUM; regno <= NIOS2_MPUACC_REGNUM; regno++)
+    if (regnum == -1 || regnum == regno)
+      {
+       if (reg_offsets[regno] != -1)
+         regcache_raw_collect (regcache, regno,
+                               gregs + 4 * reg_offsets[regno]);
+      }
+}
+
+static const struct regset nios2_core_regset =
 {
   NULL,
   nios2_supply_gregset,
-  NULL,
-  NULL
+  nios2_collect_gregset
 };
 
-/* Implement the regset_from_core_section gdbarch method.  */
+/* Iterate over core file register note sections.  */
 
-static const struct regset *
-nios2_regset_from_core_section (struct gdbarch *gdbarch,
-                                const char *sect_name, size_t sect_size)
+static void
+nios2_iterate_over_regset_sections (struct gdbarch *gdbarch,
+                                   iterate_over_regset_sections_cb *cb,
+                                   void *cb_data,
+                                   const struct regcache *regcache)
 {
-  if (strcmp (sect_name, ".reg") == 0)
-    return &nios2_core_regset;
-
-  return NULL;
+  cb (".reg", NIOS2_GREGS_SIZE, &nios2_core_regset, NULL, cb_data);
 }
 
 /* Initialize a trad-frame cache corresponding to the tramp-frame.
-   FUNC is the address of the instruction TRAMP[0] in memory.  */
+   FUNC is the address of the instruction TRAMP[0] in memory.
 
-static void
-nios2_linux_sigreturn_init (const struct tramp_frame *self,
-                           struct frame_info *next_frame,
-                           struct trad_frame_cache *this_cache,
-                           CORE_ADDR func)
-{
-  CORE_ADDR base = func + 16;
-  int i;
+   This ABI is not documented.  It corresponds to rt_setup_ucontext in
+   the kernel arch/nios2/kernel/signal.c file.
 
-  for (i = 0; i < 8; i++)
-    trad_frame_set_reg_addr (this_cache, i + 8, base + i * 4);
-  for (i = 0; i < 7; i++)
-    trad_frame_set_reg_addr (this_cache, i + 1, base + (i + 8) * 4);
-  trad_frame_set_reg_addr (this_cache, NIOS2_RA_REGNUM, base + 16 * 4);
-  trad_frame_set_reg_addr (this_cache, NIOS2_FP_REGNUM, base + 17 * 4);
-  trad_frame_set_reg_addr (this_cache, NIOS2_SP_REGNUM, base + 18 * 4);
-  trad_frame_set_reg_addr (this_cache, NIOS2_GP_REGNUM, base + 19 * 4);
-  trad_frame_set_reg_addr (this_cache, NIOS2_ESTATUS_REGNUM, base + 20 * 4);
-  trad_frame_set_reg_addr (this_cache, NIOS2_PC_REGNUM, base + 21 * 4);
+   The key points are:
+   - The kernel creates a trampoline at the hard-wired address 0x1044.
+   - The stack pointer points to an object of type struct rt_sigframe.
+     The definition of this structure is not exported from the kernel.
+     The register save area is located at offset 152 bytes (as determined
+     by inspection of the stack contents in the debugger), and the
+     registers are saved as r1-r23, ra, fp, gp, ea, sp.
 
-  /* Save a frame ID.  */
-  trad_frame_set_id (this_cache, frame_id_build (base, func));
-}
+   This interface was implemented with kernel version 3.19 (the first
+   official mainline kernel).  Older unofficial kernel versions used
+   incompatible conventions; we do not support those here.  */
 
-/* Initialize a trad-frame cache corresponding to the tramp-frame.
-   FUNC is the address of the instruction TRAMP[0] in memory.  */
+#define NIOS2_SIGRETURN_TRAMP_ADDR 0x1044
+#define NIOS2_SIGRETURN_REGSAVE_OFFSET 152
 
 static void
 nios2_linux_rt_sigreturn_init (const struct tramp_frame *self,
@@ -129,7 +140,8 @@ nios2_linux_rt_sigreturn_init (const struct tramp_frame *self,
                               struct trad_frame_cache *this_cache,
                               CORE_ADDR func)
 {
-  CORE_ADDR base = func + 41 * 4;
+  CORE_ADDR sp = get_frame_register_unsigned (next_frame, NIOS2_SP_REGNUM);
+  CORE_ADDR base = sp + NIOS2_SIGRETURN_REGSAVE_OFFSET;
   int i;
 
   for (i = 0; i < 23; i++)
@@ -144,24 +156,12 @@ nios2_linux_rt_sigreturn_init (const struct tramp_frame *self,
   trad_frame_set_id (this_cache, frame_id_build (base, func));
 }
 
-static struct tramp_frame nios2_linux_sigreturn_tramp_frame =
-{
-  SIGTRAMP_FRAME,
-  4,
-  {
-    { 0x00800004 | (119 << 6), -1 },  /* movi r2,__NR_sigreturn */
-    { 0x003b683a, -1 },               /* trap */
-    { TRAMP_SENTINEL_INSN }
-  },
-  nios2_linux_sigreturn_init
-};
-
 static struct tramp_frame nios2_linux_rt_sigreturn_tramp_frame =
 {
   SIGTRAMP_FRAME,
   4,
   {
-    { 0x00800004 | (173 << 6), -1 },  /* movi r2,__NR_rt_sigreturn */
+    { 0x00800004 | (139 << 6), -1 },  /* movi r2,__NR_rt_sigreturn */
     { 0x003b683a, -1 },               /* trap */
     { TRAMP_SENTINEL_INSN }
   },
@@ -179,8 +179,7 @@ nios2_linux_syscall_next_pc (struct frame_info *frame)
 
   /* If we are about to make a sigreturn syscall, use the unwinder to
      decode the signal frame.  */
-  if (syscall_nr == 119 /* sigreturn */
-      || syscall_nr == 173 /* rt_sigreturn */)
+  if (syscall_nr == 139 /* rt_sigreturn */)
     return frame_unwind_caller_pc (frame);
 
   return pc + NIOS2_OPCODE_SIZE;
@@ -205,11 +204,9 @@ nios2_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_fetch_tls_load_module_address (gdbarch,
                                              svr4_fetch_objfile_link_map);
   /* Core file support.  */
-  set_gdbarch_regset_from_core_section (gdbarch,
-                                        nios2_regset_from_core_section);
+  set_gdbarch_iterate_over_regset_sections
+    (gdbarch, nios2_iterate_over_regset_sections);
   /* Linux signal frame unwinders.  */
-  tramp_frame_prepend_unwinder (gdbarch,
-                                &nios2_linux_sigreturn_tramp_frame);
   tramp_frame_prepend_unwinder (gdbarch,
                                 &nios2_linux_rt_sigreturn_tramp_frame);
 
This page took 0.025053 seconds and 4 git commands to generate.