GDB (xrefs)
/tmp/gdb-7.10/gdb/nios2-linux-tdep.c
Go to the documentation of this file.
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 
5  This file is part of GDB.
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "frame.h"
22 #include "osabi.h"
23 #include "solib-svr4.h"
24 #include "trad-frame.h"
25 #include "tramp-frame.h"
26 #include "symtab.h"
27 #include "regset.h"
28 #include "regcache.h"
29 #include "linux-tdep.h"
30 #include "glibc-tdep.h"
31 #include "nios2-tdep.h"
32 
33 #include "features/nios2-linux.c"
34 
35 /* Core file and register set support. */
36 
37 /* Map from the normal register enumeration order to the order that
38  registers appear in core files, which corresponds to the order
39  of the register slots in the kernel's struct pt_regs. */
40 
41 static const int reg_offsets[NIOS2_NUM_REGS] =
42 {
43  -1, 8, 9, 10, 11, 12, 13, 14, /* r0 - r7 */
44  0, 1, 2, 3, 4, 5, 6, 7, /* r8 - r15 */
45  23, 24, 25, 26, 27, 28, 29, 30, /* r16 - r23 */
46  -1, -1, 19, 18, 17, 21, -1, 16, /* et bt gp sp fp ea sstatus ra */
47  21, /* pc */
48  -1, 20, -1, -1, -1, -1, -1, -1, /* status estatus ... */
49  -1, -1, -1, -1, -1, -1, -1, -1
50 };
51 
52 /* General register set size. Should match sizeof (struct pt_regs) +
53  sizeof (struct switch_stack) from the NIOS2 Linux kernel patch. */
54 
55 #define NIOS2_GREGS_SIZE (4 * 34)
56 
57 /* Implement the supply_regset hook for core files. */
58 
59 static void
61  struct regcache *regcache,
62  int regnum, const void *gregs_buf, size_t len)
63 {
64  const gdb_byte *gregs = gregs_buf;
65  int regno;
66  static const gdb_byte zero_buf[4] = {0, 0, 0, 0};
67 
68  for (regno = NIOS2_Z_REGNUM; regno <= NIOS2_MPUACC_REGNUM; regno++)
69  if (regnum == -1 || regnum == regno)
70  {
71  if (reg_offsets[regno] != -1)
72  regcache_raw_supply (regcache, regno,
73  gregs + 4 * reg_offsets[regno]);
74  else
75  regcache_raw_supply (regcache, regno, zero_buf);
76  }
77 }
78 
79 /* Implement the collect_regset hook for core files. */
80 
81 static void
83  const struct regcache *regcache,
84  int regnum, void *gregs_buf, size_t len)
85 {
86  gdb_byte *gregs = gregs_buf;
87  int regno;
88 
89  for (regno = NIOS2_Z_REGNUM; regno <= NIOS2_MPUACC_REGNUM; regno++)
90  if (regnum == -1 || regnum == regno)
91  {
92  if (reg_offsets[regno] != -1)
93  regcache_raw_collect (regcache, regno,
94  gregs + 4 * reg_offsets[regno]);
95  }
96 }
97 
98 static const struct regset nios2_core_regset =
99 {
100  NULL,
103 };
104 
105 /* Iterate over core file register note sections. */
106 
107 static void
110  void *cb_data,
111  const struct regcache *regcache)
112 {
113  cb (".reg", NIOS2_GREGS_SIZE, &nios2_core_regset, NULL, cb_data);
114 }
115 
116 /* Initialize a trad-frame cache corresponding to the tramp-frame.
117  FUNC is the address of the instruction TRAMP[0] in memory.
118 
119  This ABI is not documented. It corresponds to rt_setup_ucontext in
120  the kernel arch/nios2/kernel/signal.c file.
121 
122  The key points are:
123  - The kernel creates a trampoline at the hard-wired address 0x1044.
124  - The stack pointer points to an object of type struct rt_sigframe.
125  The definition of this structure is not exported from the kernel.
126  The register save area is located at offset 152 bytes (as determined
127  by inspection of the stack contents in the debugger), and the
128  registers are saved as r1-r23, ra, fp, gp, ea, sp.
129 
130  This interface was implemented with kernel version 3.19 (the first
131  official mainline kernel). Older unofficial kernel versions used
132  incompatible conventions; we do not support those here. */
133 
134 #define NIOS2_SIGRETURN_TRAMP_ADDR 0x1044
135 #define NIOS2_SIGRETURN_REGSAVE_OFFSET 152
136 
137 static void
139  struct frame_info *next_frame,
140  struct trad_frame_cache *this_cache,
141  CORE_ADDR func)
142 {
145  int i;
146 
147  for (i = 0; i < 23; i++)
148  trad_frame_set_reg_addr (this_cache, i + 1, base + i * 4);
149  trad_frame_set_reg_addr (this_cache, NIOS2_RA_REGNUM, base + 23 * 4);
150  trad_frame_set_reg_addr (this_cache, NIOS2_FP_REGNUM, base + 24 * 4);
151  trad_frame_set_reg_addr (this_cache, NIOS2_GP_REGNUM, base + 25 * 4);
152  trad_frame_set_reg_addr (this_cache, NIOS2_PC_REGNUM, base + 27 * 4);
153  trad_frame_set_reg_addr (this_cache, NIOS2_SP_REGNUM, base + 28 * 4);
154 
155  /* Save a frame ID. */
156  trad_frame_set_id (this_cache, frame_id_build (base, func));
157 }
158 
159 static struct tramp_frame nios2_linux_rt_sigreturn_tramp_frame =
160 {
162  4,
163  {
164  { 0x00800004 | (139 << 6), -1 }, /* movi r2,__NR_rt_sigreturn */
165  { 0x003b683a, -1 }, /* trap */
167  },
169 };
170 
171 /* When FRAME is at a syscall instruction, return the PC of the next
172  instruction to be executed. */
173 
174 static CORE_ADDR
176 {
177  CORE_ADDR pc = get_frame_pc (frame);
179 
180  /* If we are about to make a sigreturn syscall, use the unwinder to
181  decode the signal frame. */
182  if (syscall_nr == 139 /* rt_sigreturn */)
183  return frame_unwind_caller_pc (frame);
184 
185  return pc + NIOS2_OPCODE_SIZE;
186 }
187 
188 /* Hook function for gdbarch_register_osabi. */
189 
190 static void
192 {
193  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
194 
195  linux_init_abi (info, gdbarch);
196 
197  /* Shared library handling. */
200 
203  /* Enable TLS support. */
206  /* Core file support. */
209  /* Linux signal frame unwinders. */
211  &nios2_linux_rt_sigreturn_tramp_frame);
212 
214 
215  /* Index of target address word in glibc jmp_buf. */
216  tdep->jb_pc = 10;
217 }
218 
219 /* Provide a prototype to silence -Wmissing-prototypes. */
220 
222 
223 void
225 {
226  gdbarch_register_osabi (bfd_arch_nios2, 0, GDB_OSABI_LINUX,
228 
230 }
CORE_ADDR(* syscall_next_pc)(struct frame_info *frame)
Definition: arm-tdep.h:206
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition: trad-frame.c:119
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:554
static void nios2_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2217
bfd_vma CORE_ADDR
Definition: common-types.h:41
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype fetch_tls_load_module_address)
Definition: gdbarch.c:2822
#define TRAMP_SENTINEL_INSN
Definition: tramp-frame.h:44
static const int reg_offsets[NIOS2_NUM_REGS]
static void initialize_tdesc_nios2_linux(void)
Definition: nios2-linux.c:10
CORE_ADDR frame_unwind_caller_pc(struct frame_info *this_frame)
Definition: frame.c:870
void(* func)(char *)
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype skip_trampoline_code)
Definition: gdbarch.c:3084
CORE_ADDR glibc_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: glibc-tdep.c:38
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition: trad-frame.c:164
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: linux-tdep.c:2427
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3149
#define NIOS2_OPCODE_SIZE
Definition: nios2-tdep.h:63
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
Definition: solib-svr4.c:1573
Definition: regset.h:34
static void nios2_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
void initialize_file_ftype(void)
Definition: defs.h:281
CORE_ADDR find_solib_trampoline_target(struct frame_info *frame, CORE_ADDR pc)
Definition: minsyms.c:1394
#define NIOS2_NUM_REGS
Definition: nios2-tdep.h:60
#define NIOS2_R2_REGNUM
Definition: nios2-tdep.h:25
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3108
#define NIOS2_SP_REGNUM
Definition: nios2-tdep.h:31
int regnum
Definition: aarch64-tdep.c:69
void( iterate_over_regset_sections_cb)(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:98
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1194
#define NIOS2_Z_REGNUM
Definition: nios2-tdep.h:24
#define NIOS2_GREGS_SIZE
initialize_file_ftype _initialize_nios2_linux_tdep
bfd_byte gdb_byte
Definition: common-types.h:38
static void nios2_linux_rt_sigreturn_init(const struct tramp_frame *self, struct frame_info *next_frame, struct trad_frame_cache *this_cache, CORE_ADDR func)
#define NIOS2_GP_REGNUM
Definition: nios2-tdep.h:30
void tramp_frame_prepend_unwinder(struct gdbarch *gdbarch, const struct tramp_frame *tramp_frame)
Definition: tramp-frame.c:145
static void nios2_collect_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs_buf, size_t len)
#define NIOS2_RA_REGNUM
Definition: nios2-tdep.h:35
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1041
static CORE_ADDR nios2_linux_syscall_next_pc(struct frame_info *frame)
unsigned long long ULONGEST
Definition: common-types.h:53
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1071
static void nios2_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs_buf, size_t len)
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3398
#define NIOS2_PC_REGNUM
Definition: nios2-tdep.h:36
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype skip_solib_resolver)
Definition: gdbarch.c:3101
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition: osabi.c:148
#define NIOS2_FP_REGNUM
Definition: nios2-tdep.h:32
#define NIOS2_SIGRETURN_REGSAVE_OFFSET
#define NIOS2_MPUACC_REGNUM
Definition: nios2-tdep.h:53
const ULONGEST const LONGEST len
Definition: target.h:309