1 /* Motorola m68k target-dependent support for GNU/Linux.
3 Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2007
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
26 #include "floatformat.h"
29 #include "gdb_string.h"
35 #include "m68k-tdep.h"
36 #include "trad-frame.h"
37 #include "frame-unwind.h"
38 #include "glibc-tdep.h"
39 #include "solib-svr4.h"
42 #include "elf/common.h"
44 /* Offsets (in target ints) into jmp_buf. */
46 #define M68K_LINUX_JB_ELEMENT_SIZE 4
47 #define M68K_LINUX_JB_PC 7
49 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
51 #define IS_SIGTRAMP(insn1, insn2) \
52 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
53 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
54 /* moveq #119,d0; trap #0 */ \
55 || insn1 == 0x70774e40)
57 #define IS_RT_SIGTRAMP(insn1, insn2) \
58 (/* movel #173,d0; trap #0 */ \
59 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
60 /* moveq #82,d0; notb d0; trap #0 */ \
61 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
63 /* Return non-zero if PC points into the signal trampoline. For the
64 sake of m68k_linux_get_sigtramp_info we also distinguish between
65 non-RT and RT signal trampolines. */
68 m68k_linux_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
72 unsigned long insn0
, insn1
, insn2
;
74 if (read_memory_nobpt (pc
- 4, buf
, sizeof (buf
)))
76 insn1
= extract_unsigned_integer (buf
+ 4, 4);
77 insn2
= extract_unsigned_integer (buf
+ 8, 4);
78 if (IS_SIGTRAMP (insn1
, insn2
))
80 if (IS_RT_SIGTRAMP (insn1
, insn2
))
83 insn0
= extract_unsigned_integer (buf
, 4);
84 if (IS_SIGTRAMP (insn0
, insn1
))
86 if (IS_RT_SIGTRAMP (insn0
, insn1
))
89 insn0
= ((insn0
<< 16) & 0xffffffff) | (insn1
>> 16);
90 insn1
= ((insn1
<< 16) & 0xffffffff) | (insn2
>> 16);
91 if (IS_SIGTRAMP (insn0
, insn1
))
93 if (IS_RT_SIGTRAMP (insn0
, insn1
))
99 /* From <asm/sigcontext.h>. */
100 static int m68k_linux_sigcontext_reg_offset
[M68K_NUM_REGS
] =
130 16 * 4 /* %fpiaddr */
133 static int m68k_uclinux_sigcontext_reg_offset
[M68K_NUM_REGS
] =
166 /* From <asm/ucontext.h>. */
167 static int m68k_linux_ucontext_reg_offset
[M68K_NUM_REGS
] =
197 26 * 4 /* %fpiaddr */
201 /* Get info about saved registers in sigtramp. */
203 struct m68k_linux_sigtramp_info
205 /* Address of sigcontext. */
206 CORE_ADDR sigcontext_addr
;
208 /* Offset of registers in `struct sigcontext'. */
212 /* Nonzero if running on uClinux. */
213 static int target_is_uclinux
;
216 m68k_linux_inferior_created (struct target_ops
*objfile
, int from_tty
)
218 /* Record that we will need to re-evaluate whether we are running on
219 a uClinux or normal Linux target (see m68k_linux_get_sigtramp_info). */
220 target_is_uclinux
= -1;
223 static struct m68k_linux_sigtramp_info
224 m68k_linux_get_sigtramp_info (struct frame_info
*next_frame
)
228 struct m68k_linux_sigtramp_info info
;
230 if (target_is_uclinux
== -1)
232 /* Determine whether we are running on a uClinux or normal Linux
233 target so we can use the correct sigcontext layouts. */
238 = target_auxv_search (¤t_target
, AT_NULL
, &dummy
) > 0
239 && target_auxv_search (¤t_target
, AT_PAGESZ
, &dummy
) == 0;
242 frame_unwind_register (next_frame
, M68K_SP_REGNUM
, buf
);
243 sp
= extract_unsigned_integer (buf
, 4);
245 /* Get sigcontext address, it is the third parameter on the stack. */
246 info
.sigcontext_addr
= read_memory_unsigned_integer (sp
+ 8, 4);
248 if (m68k_linux_pc_in_sigtramp (frame_pc_unwind (next_frame
), 0) == 2)
249 info
.sc_reg_offset
= m68k_linux_ucontext_reg_offset
;
252 = target_is_uclinux
? m68k_uclinux_sigcontext_reg_offset
253 : m68k_linux_sigcontext_reg_offset
;
257 /* Signal trampolines. */
259 static struct trad_frame_cache
*
260 m68k_linux_sigtramp_frame_cache (struct frame_info
*next_frame
,
263 struct frame_id this_id
;
264 struct trad_frame_cache
*cache
;
265 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
266 struct m68k_linux_sigtramp_info info
;
273 cache
= trad_frame_cache_zalloc (next_frame
);
275 /* FIXME: cagney/2004-05-01: This is is long standing broken code.
276 The frame ID's code address should be the start-address of the
277 signal trampoline and not the current PC within that
279 frame_unwind_register (next_frame
, M68K_SP_REGNUM
, buf
);
280 /* See the end of m68k_push_dummy_call. */
281 this_id
= frame_id_build (extract_unsigned_integer (buf
, 4) - 4 + 8,
282 frame_pc_unwind (next_frame
));
283 trad_frame_set_id (cache
, this_id
);
285 info
= m68k_linux_get_sigtramp_info (next_frame
);
287 for (i
= 0; i
< M68K_NUM_REGS
; i
++)
288 if (info
.sc_reg_offset
[i
] != -1)
289 trad_frame_set_reg_addr (cache
, i
,
290 info
.sigcontext_addr
+ info
.sc_reg_offset
[i
]);
297 m68k_linux_sigtramp_frame_this_id (struct frame_info
*next_frame
,
299 struct frame_id
*this_id
)
301 struct trad_frame_cache
*cache
=
302 m68k_linux_sigtramp_frame_cache (next_frame
, this_cache
);
303 trad_frame_get_id (cache
, this_id
);
307 m68k_linux_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
309 int regnum
, int *optimizedp
,
310 enum lval_type
*lvalp
,
312 int *realnump
, gdb_byte
*valuep
)
314 /* Make sure we've initialized the cache. */
315 struct trad_frame_cache
*cache
=
316 m68k_linux_sigtramp_frame_cache (next_frame
, this_cache
);
317 trad_frame_get_register (cache
, next_frame
, regnum
, optimizedp
, lvalp
,
318 addrp
, realnump
, valuep
);
321 static const struct frame_unwind m68k_linux_sigtramp_frame_unwind
=
324 m68k_linux_sigtramp_frame_this_id
,
325 m68k_linux_sigtramp_frame_prev_register
328 static const struct frame_unwind
*
329 m68k_linux_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
331 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
334 find_pc_partial_function (pc
, &name
, NULL
, NULL
);
335 if (m68k_linux_pc_in_sigtramp (pc
, name
))
336 return &m68k_linux_sigtramp_frame_unwind
;
342 m68k_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
344 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
346 tdep
->jb_pc
= M68K_LINUX_JB_PC
;
347 tdep
->jb_elt_size
= M68K_LINUX_JB_ELEMENT_SIZE
;
349 /* GNU/Linux uses a calling convention that's similar to SVR4. It
350 returns integer values in %d0/%d1, pointer values in %a0 and
351 floating values in %fp0, just like SVR4, but uses %a1 to pass the
352 address to store a structure value. It also returns small
353 structures in registers instead of memory. */
354 m68k_svr4_init_abi (info
, gdbarch
);
355 tdep
->struct_value_regnum
= M68K_A1_REGNUM
;
356 tdep
->struct_return
= reg_struct_return
;
358 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
360 frame_unwind_append_sniffer (gdbarch
, m68k_linux_sigtramp_frame_sniffer
);
362 /* Shared library handling. */
364 /* GNU/Linux uses SVR4-style shared libraries. */
365 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
366 svr4_ilp32_fetch_link_map_offsets
);
368 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
369 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
371 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
373 /* Enable TLS support. */
374 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
375 svr4_fetch_objfile_link_map
);
379 _initialize_m68k_linux_tdep (void)
381 gdbarch_register_osabi (bfd_arch_m68k
, 0, GDB_OSABI_LINUX
,
382 m68k_linux_init_abi
);
383 observer_attach_inferior_created (m68k_linux_inferior_created
);