GDB (xrefs)
/tmp/gdb-7.10/gdb/m68klinux-tdep.c
Go to the documentation of this file.
1 /* Motorola m68k target-dependent support for GNU/Linux.
2 
3  Copyright (C) 1996-2015 Free Software Foundation, 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 "gdbcore.h"
22 #include "doublest.h"
23 #include "floatformat.h"
24 #include "frame.h"
25 #include "target.h"
26 #include "gdbtypes.h"
27 #include "osabi.h"
28 #include "regcache.h"
29 #include "objfiles.h"
30 #include "symtab.h"
31 #include "m68k-tdep.h"
32 #include "trad-frame.h"
33 #include "frame-unwind.h"
34 #include "glibc-tdep.h"
35 #include "solib-svr4.h"
36 #include "auxv.h"
37 #include "observer.h"
38 #include "elf/common.h"
39 #include "linux-tdep.h"
40 #include "regset.h"
41 
42 /* Offsets (in target ints) into jmp_buf. */
43 
44 #define M68K_LINUX_JB_ELEMENT_SIZE 4
45 #define M68K_LINUX_JB_PC 7
46 
47 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
48 
49 #define IS_SIGTRAMP(insn1, insn2) \
50  (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
51  (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
52  /* moveq #119,d0; trap #0 */ \
53  || insn1 == 0x70774e40)
54 
55 #define IS_RT_SIGTRAMP(insn1, insn2) \
56  (/* movel #173,d0; trap #0 */ \
57  (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
58  /* moveq #82,d0; notb d0; trap #0 */ \
59  || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
60 
61 /* Return non-zero if THIS_FRAME corresponds to a signal trampoline. For
62  the sake of m68k_linux_get_sigtramp_info we also distinguish between
63  non-RT and RT signal trampolines. */
64 
65 static int
67 {
68  struct gdbarch *gdbarch = get_frame_arch (this_frame);
69  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
70  gdb_byte buf[12];
71  unsigned long insn0, insn1, insn2;
72  CORE_ADDR pc = get_frame_pc (this_frame);
73 
74  if (!safe_frame_unwind_memory (this_frame, pc - 4, buf, sizeof (buf)))
75  return 0;
76  insn1 = extract_unsigned_integer (buf + 4, 4, byte_order);
77  insn2 = extract_unsigned_integer (buf + 8, 4, byte_order);
78  if (IS_SIGTRAMP (insn1, insn2))
79  return 1;
80  if (IS_RT_SIGTRAMP (insn1, insn2))
81  return 2;
82 
83  insn0 = extract_unsigned_integer (buf, 4, byte_order);
84  if (IS_SIGTRAMP (insn0, insn1))
85  return 1;
86  if (IS_RT_SIGTRAMP (insn0, insn1))
87  return 2;
88 
89  insn0 = ((insn0 << 16) & 0xffffffff) | (insn1 >> 16);
90  insn1 = ((insn1 << 16) & 0xffffffff) | (insn2 >> 16);
91  if (IS_SIGTRAMP (insn0, insn1))
92  return 1;
93  if (IS_RT_SIGTRAMP (insn0, insn1))
94  return 2;
95 
96  return 0;
97 }
98 
99 /* From <asm/sigcontext.h>. */
101 {
102  2 * 4, /* %d0 */
103  3 * 4, /* %d1 */
104  -1, /* %d2 */
105  -1, /* %d3 */
106  -1, /* %d4 */
107  -1, /* %d5 */
108  -1, /* %d6 */
109  -1, /* %d7 */
110  4 * 4, /* %a0 */
111  5 * 4, /* %a1 */
112  -1, /* %a2 */
113  -1, /* %a3 */
114  -1, /* %a4 */
115  -1, /* %a5 */
116  -1, /* %fp */
117  1 * 4, /* %sp */
118  6 * 4, /* %sr */
119  6 * 4 + 2, /* %pc */
120  8 * 4, /* %fp0 */
121  11 * 4, /* %fp1 */
122  -1, /* %fp2 */
123  -1, /* %fp3 */
124  -1, /* %fp4 */
125  -1, /* %fp5 */
126  -1, /* %fp6 */
127  -1, /* %fp7 */
128  14 * 4, /* %fpcr */
129  15 * 4, /* %fpsr */
130  16 * 4 /* %fpiaddr */
131 };
132 
134 {
135  2 * 4, /* %d0 */
136  3 * 4, /* %d1 */
137  -1, /* %d2 */
138  -1, /* %d3 */
139  -1, /* %d4 */
140  -1, /* %d5 */
141  -1, /* %d6 */
142  -1, /* %d7 */
143  4 * 4, /* %a0 */
144  5 * 4, /* %a1 */
145  -1, /* %a2 */
146  -1, /* %a3 */
147  -1, /* %a4 */
148  6 * 4, /* %a5 */
149  -1, /* %fp */
150  1 * 4, /* %sp */
151  7 * 4, /* %sr */
152  7 * 4 + 2, /* %pc */
153  -1, /* %fp0 */
154  -1, /* %fp1 */
155  -1, /* %fp2 */
156  -1, /* %fp3 */
157  -1, /* %fp4 */
158  -1, /* %fp5 */
159  -1, /* %fp6 */
160  -1, /* %fp7 */
161  -1, /* %fpcr */
162  -1, /* %fpsr */
163  -1 /* %fpiaddr */
164 };
165 
166 /* From <asm/ucontext.h>. */
168 {
169  6 * 4, /* %d0 */
170  7 * 4, /* %d1 */
171  8 * 4, /* %d2 */
172  9 * 4, /* %d3 */
173  10 * 4, /* %d4 */
174  11 * 4, /* %d5 */
175  12 * 4, /* %d6 */
176  13 * 4, /* %d7 */
177  14 * 4, /* %a0 */
178  15 * 4, /* %a1 */
179  16 * 4, /* %a2 */
180  17 * 4, /* %a3 */
181  18 * 4, /* %a4 */
182  19 * 4, /* %a5 */
183  20 * 4, /* %fp */
184  21 * 4, /* %sp */
185  23 * 4, /* %sr */
186  22 * 4, /* %pc */
187  27 * 4, /* %fp0 */
188  30 * 4, /* %fp1 */
189  33 * 4, /* %fp2 */
190  36 * 4, /* %fp3 */
191  39 * 4, /* %fp4 */
192  42 * 4, /* %fp5 */
193  45 * 4, /* %fp6 */
194  48 * 4, /* %fp7 */
195  24 * 4, /* %fpcr */
196  25 * 4, /* %fpsr */
197  26 * 4 /* %fpiaddr */
198 };
199 
200 
201 /* Get info about saved registers in sigtramp. */
202 
204 {
205  /* Address of sigcontext. */
207 
208  /* Offset of registers in `struct sigcontext'. */
210 };
211 
212 /* Nonzero if running on uClinux. */
213 static int target_is_uclinux;
214 
215 static void
217 {
218  /* Record that we will need to re-evaluate whether we are running on a
219  uClinux or normal GNU/Linux target (see m68k_linux_get_sigtramp_info). */
220  target_is_uclinux = -1;
221 }
222 
223 static struct m68k_linux_sigtramp_info
225 {
226  struct gdbarch *gdbarch = get_frame_arch (this_frame);
227  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
228  CORE_ADDR sp;
229  struct m68k_linux_sigtramp_info info;
230 
231  /* Determine whether we are running on a uClinux or normal GNU/Linux
232  target so we can use the correct sigcontext layouts. */
233  if (target_is_uclinux == -1)
235 
236  sp = get_frame_register_unsigned (this_frame, M68K_SP_REGNUM);
237 
238  /* Get sigcontext address, it is the third parameter on the stack. */
239  info.sigcontext_addr = read_memory_unsigned_integer (sp + 8, 4, byte_order);
240 
241  if (m68k_linux_pc_in_sigtramp (this_frame) == 2)
243  else
247  return info;
248 }
249 
250 /* Signal trampolines. */
251 
252 static struct trad_frame_cache *
254  void **this_cache)
255 {
256  struct frame_id this_id;
257  struct trad_frame_cache *cache;
258  struct gdbarch *gdbarch = get_frame_arch (this_frame);
259  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
260  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
261  struct m68k_linux_sigtramp_info info;
262  gdb_byte buf[4];
263  int i;
264 
265  if (*this_cache)
266  return *this_cache;
267 
268  cache = trad_frame_cache_zalloc (this_frame);
269 
270  /* FIXME: cagney/2004-05-01: This is is long standing broken code.
271  The frame ID's code address should be the start-address of the
272  signal trampoline and not the current PC within that
273  trampoline. */
274  get_frame_register (this_frame, M68K_SP_REGNUM, buf);
275  /* See the end of m68k_push_dummy_call. */
276  this_id = frame_id_build (extract_unsigned_integer (buf, 4, byte_order)
277  - 4 + 8, get_frame_pc (this_frame));
278  trad_frame_set_id (cache, this_id);
279 
280  info = m68k_linux_get_sigtramp_info (this_frame);
281 
282  for (i = 0; i < M68K_NUM_REGS; i++)
283  if (info.sc_reg_offset[i] != -1)
284  trad_frame_set_reg_addr (cache, i,
285  info.sigcontext_addr + info.sc_reg_offset[i]);
286 
287  *this_cache = cache;
288  return cache;
289 }
290 
291 static void
293  void **this_cache,
294  struct frame_id *this_id)
295 {
296  struct trad_frame_cache *cache =
297  m68k_linux_sigtramp_frame_cache (this_frame, this_cache);
298  trad_frame_get_id (cache, this_id);
299 }
300 
301 static struct value *
303  void **this_cache,
304  int regnum)
305 {
306  /* Make sure we've initialized the cache. */
307  struct trad_frame_cache *cache =
308  m68k_linux_sigtramp_frame_cache (this_frame, this_cache);
309  return trad_frame_get_register (cache, this_frame, regnum);
310 }
311 
312 static int
314  struct frame_info *this_frame,
315  void **this_prologue_cache)
316 {
317  return m68k_linux_pc_in_sigtramp (this_frame);
318 }
319 
320 static const struct frame_unwind m68k_linux_sigtramp_frame_unwind =
321 {
326  NULL,
328 };
329 
330 /* Register maps for supply/collect regset functions. */
331 
332 static const struct regcache_map_entry m68k_linux_gregmap[] =
333  {
334  { 7, M68K_D1_REGNUM, 4 }, /* d1 ... d7 */
335  { 7, M68K_A0_REGNUM, 4 }, /* a0 ... a6 */
336  { 1, M68K_D0_REGNUM, 4 },
337  { 1, M68K_SP_REGNUM, 4 },
338  { 1, REGCACHE_MAP_SKIP, 4 }, /* orig_d0 (skip) */
339  { 1, M68K_PS_REGNUM, 4 },
340  { 1, M68K_PC_REGNUM, 4 },
341  /* Ignore 16-bit fields 'fmtvec' and '__fill'. */
342  { 0 }
343  };
344 
345 #define M68K_LINUX_GREGS_SIZE (20 * 4)
346 
347 static const struct regcache_map_entry m68k_linux_fpregmap[] =
348  {
349  { 8, M68K_FP0_REGNUM, 12 }, /* fp0 ... fp7 */
350  { 1, M68K_FPC_REGNUM, 4 },
351  { 1, M68K_FPS_REGNUM, 4 },
352  { 1, M68K_FPI_REGNUM, 4 },
353  { 0 }
354  };
355 
356 #define M68K_LINUX_FPREGS_SIZE (27 * 4)
357 
358 /* Register sets. */
359 
360 static const struct regset m68k_linux_gregset =
361  {
364  };
365 
366 static const struct regset m68k_linux_fpregset =
367  {
370  };
371 
372 /* Iterate over core file register note sections. */
373 
374 static void
377  void *cb_data,
378  const struct regcache *regcache)
379 {
380  cb (".reg", M68K_LINUX_GREGS_SIZE, &m68k_linux_gregset, NULL, cb_data);
381  cb (".reg2", M68K_LINUX_FPREGS_SIZE, &m68k_linux_fpregset, NULL, cb_data);
382 }
383 
384 static void
386 {
387  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
388 
389  linux_init_abi (info, gdbarch);
390 
391  tdep->jb_pc = M68K_LINUX_JB_PC;
393 
394  /* GNU/Linux uses a calling convention that's similar to SVR4. It
395  returns integer values in %d0/%d1, pointer values in %a0 and
396  floating values in %fp0, just like SVR4, but uses %a1 to pass the
397  address to store a structure value. It also returns small
398  structures in registers instead of memory. */
399  m68k_svr4_init_abi (info, gdbarch);
402 
403  set_gdbarch_decr_pc_after_break (gdbarch, 2);
404 
405  frame_unwind_append_unwinder (gdbarch, &m68k_linux_sigtramp_frame_unwind);
406 
407  /* Shared library handling. */
408 
409  /* GNU/Linux uses SVR4-style shared libraries. */
412 
413  /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
415 
417 
418  /* Core file support. */
421 
422  /* Enable TLS support. */
425 }
426 
427 /* Provide a prototype to silence -Wmissing-prototypes. */
429 
430 void
432 {
433  gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_LINUX,
436 }
void m68k_svr4_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: m68k-tdep.c:1065
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
static const struct regcache_map_entry m68k_linux_gregmap[]
static int m68k_uclinux_sigcontext_reg_offset[M68K_NUM_REGS]
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
int linux_is_uclinux(void)
Definition: linux-tdep.c:368
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 IS_RT_SIGTRAMP(insn1, insn2)
#define M68K_LINUX_GREGS_SIZE
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
static void m68k_linux_inferior_created(struct target_ops *objfile, int from_tty)
static struct trad_frame_cache * m68k_linux_sigtramp_frame_cache(struct frame_info *this_frame, void **this_cache)
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition: trad-frame.c:164
#define M68K_NUM_REGS
Definition: m68k-tdep.h:47
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition: regcache.c:1149
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: linux-tdep.c:2427
initialize_file_ftype _initialize_m68k_linux_tdep
struct link_map_offsets * svr4_ilp32_fetch_link_map_offsets(void)
Definition: solib-svr4.c:3149
static struct value * m68k_linux_sigtramp_frame_prev_register(struct frame_info *this_frame, void **this_cache, int regnum)
#define M68K_LINUX_JB_ELEMENT_SIZE
#define IS_SIGTRAMP(insn1, insn2)
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1402
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:78
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
Definition: solib-svr4.c:1573
#define M68K_LINUX_JB_PC
Definition: regset.h:34
struct observer * observer_attach_inferior_created(observer_inferior_created_ftype *f)
void trad_frame_get_id(struct trad_frame_cache *this_trad_cache, struct frame_id *this_id)
Definition: trad-frame.c:171
static int m68k_linux_pc_in_sigtramp(struct frame_info *this_frame)
#define M68K_LINUX_FPREGS_SIZE
enum struct_return struct_return
Definition: arm-tdep.h:197
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
int safe_frame_unwind_memory(struct frame_info *this_frame, CORE_ADDR addr, gdb_byte *buf, int len)
Definition: frame.c:2525
void set_gdbarch_decr_pc_after_break(struct gdbarch *gdbarch, CORE_ADDR decr_pc_after_break)
Definition: gdbarch.c:2764
static const struct regcache_map_entry m68k_linux_fpregmap[]
static void m68k_linux_sigtramp_frame_this_id(struct frame_info *this_frame, void **this_cache, struct frame_id *this_id)
static struct m68k_linux_sigtramp_info m68k_linux_get_sigtramp_info(struct frame_info *this_frame)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
Definition: solib-svr4.c:3108
static int target_is_uclinux
void regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition: regcache.c:1162
static void m68k_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
struct trad_frame_cache * trad_frame_cache_zalloc(struct frame_info *this_frame)
Definition: trad-frame.c:36
static int m68k_linux_ucontext_reg_offset[M68K_NUM_REGS]
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
struct frame_info * this_frame
Definition: trad-frame.c:29
size_t jb_elt_size
Definition: aarch64-tdep.h:83
Definition: value.c:172
static void m68k_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
bfd_byte gdb_byte
Definition: common-types.h:38
static int m68k_linux_sigcontext_reg_offset[M68K_NUM_REGS]
void get_frame_register(struct frame_info *frame, int regnum, gdb_byte *buf)
Definition: frame.c:1085
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
Definition: frame-unwind.c:180
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:321
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3398
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype skip_solib_resolver)
Definition: gdbarch.c:3101
struct value * trad_frame_get_register(struct trad_frame_cache *this_trad_cache, struct frame_info *this_frame, int regnum)
Definition: trad-frame.c:155
enum bfd_endian byte_order
Definition: gdbarch.c:128
static int m68k_linux_sigtramp_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache)
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
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2535
Definition: regcache.h:167
int struct_value_regnum
Definition: m68k-tdep.h:80