1 /* Motorola m68k target-dependent support for GNU/Linux.
3 Copyright (C) 1996-2014 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
23 #include "floatformat.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"
38 #include "elf/common.h"
39 #include "linux-tdep.h"
41 /* Offsets (in target ints) into jmp_buf. */
43 #define M68K_LINUX_JB_ELEMENT_SIZE 4
44 #define M68K_LINUX_JB_PC 7
46 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
48 #define IS_SIGTRAMP(insn1, insn2) \
49 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
50 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
51 /* moveq #119,d0; trap #0 */ \
52 || insn1 == 0x70774e40)
54 #define IS_RT_SIGTRAMP(insn1, insn2) \
55 (/* movel #173,d0; trap #0 */ \
56 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
57 /* moveq #82,d0; notb d0; trap #0 */ \
58 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
60 /* Return non-zero if THIS_FRAME corresponds to a signal trampoline. For
61 the sake of m68k_linux_get_sigtramp_info we also distinguish between
62 non-RT and RT signal trampolines. */
65 m68k_linux_pc_in_sigtramp (struct frame_info
*this_frame
)
67 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
68 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
70 unsigned long insn0
, insn1
, insn2
;
71 CORE_ADDR pc
= get_frame_pc (this_frame
);
73 if (!safe_frame_unwind_memory (this_frame
, pc
- 4, buf
, sizeof (buf
)))
75 insn1
= extract_unsigned_integer (buf
+ 4, 4, byte_order
);
76 insn2
= extract_unsigned_integer (buf
+ 8, 4, byte_order
);
77 if (IS_SIGTRAMP (insn1
, insn2
))
79 if (IS_RT_SIGTRAMP (insn1
, insn2
))
82 insn0
= extract_unsigned_integer (buf
, 4, byte_order
);
83 if (IS_SIGTRAMP (insn0
, insn1
))
85 if (IS_RT_SIGTRAMP (insn0
, insn1
))
88 insn0
= ((insn0
<< 16) & 0xffffffff) | (insn1
>> 16);
89 insn1
= ((insn1
<< 16) & 0xffffffff) | (insn2
>> 16);
90 if (IS_SIGTRAMP (insn0
, insn1
))
92 if (IS_RT_SIGTRAMP (insn0
, insn1
))
98 /* From <asm/sigcontext.h>. */
99 static int m68k_linux_sigcontext_reg_offset
[M68K_NUM_REGS
] =
129 16 * 4 /* %fpiaddr */
132 static int m68k_uclinux_sigcontext_reg_offset
[M68K_NUM_REGS
] =
165 /* From <asm/ucontext.h>. */
166 static int m68k_linux_ucontext_reg_offset
[M68K_NUM_REGS
] =
196 26 * 4 /* %fpiaddr */
200 /* Get info about saved registers in sigtramp. */
202 struct m68k_linux_sigtramp_info
204 /* Address of sigcontext. */
205 CORE_ADDR sigcontext_addr
;
207 /* Offset of registers in `struct sigcontext'. */
211 /* Nonzero if running on uClinux. */
212 static int target_is_uclinux
;
215 m68k_linux_inferior_created (struct target_ops
*objfile
, int from_tty
)
217 /* Record that we will need to re-evaluate whether we are running on a
218 uClinux or normal GNU/Linux target (see m68k_linux_get_sigtramp_info). */
219 target_is_uclinux
= -1;
222 static struct m68k_linux_sigtramp_info
223 m68k_linux_get_sigtramp_info (struct frame_info
*this_frame
)
225 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
226 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
228 struct m68k_linux_sigtramp_info info
;
230 /* Determine whether we are running on a uClinux or normal GNU/Linux
231 target so we can use the correct sigcontext layouts. */
232 if (target_is_uclinux
== -1)
233 target_is_uclinux
= linux_is_uclinux ();
235 sp
= get_frame_register_unsigned (this_frame
, M68K_SP_REGNUM
);
237 /* Get sigcontext address, it is the third parameter on the stack. */
238 info
.sigcontext_addr
= read_memory_unsigned_integer (sp
+ 8, 4, byte_order
);
240 if (m68k_linux_pc_in_sigtramp (this_frame
) == 2)
241 info
.sc_reg_offset
= m68k_linux_ucontext_reg_offset
;
243 info
.sc_reg_offset
= (target_is_uclinux
244 ? m68k_uclinux_sigcontext_reg_offset
245 : m68k_linux_sigcontext_reg_offset
);
249 /* Signal trampolines. */
251 static struct trad_frame_cache
*
252 m68k_linux_sigtramp_frame_cache (struct frame_info
*this_frame
,
255 struct frame_id this_id
;
256 struct trad_frame_cache
*cache
;
257 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
258 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
259 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
260 struct m68k_linux_sigtramp_info info
;
267 cache
= trad_frame_cache_zalloc (this_frame
);
269 /* FIXME: cagney/2004-05-01: This is is long standing broken code.
270 The frame ID's code address should be the start-address of the
271 signal trampoline and not the current PC within that
273 get_frame_register (this_frame
, M68K_SP_REGNUM
, buf
);
274 /* See the end of m68k_push_dummy_call. */
275 this_id
= frame_id_build (extract_unsigned_integer (buf
, 4, byte_order
)
276 - 4 + 8, get_frame_pc (this_frame
));
277 trad_frame_set_id (cache
, this_id
);
279 info
= m68k_linux_get_sigtramp_info (this_frame
);
281 for (i
= 0; i
< M68K_NUM_REGS
; i
++)
282 if (info
.sc_reg_offset
[i
] != -1)
283 trad_frame_set_reg_addr (cache
, i
,
284 info
.sigcontext_addr
+ info
.sc_reg_offset
[i
]);
291 m68k_linux_sigtramp_frame_this_id (struct frame_info
*this_frame
,
293 struct frame_id
*this_id
)
295 struct trad_frame_cache
*cache
=
296 m68k_linux_sigtramp_frame_cache (this_frame
, this_cache
);
297 trad_frame_get_id (cache
, this_id
);
300 static struct value
*
301 m68k_linux_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
305 /* Make sure we've initialized the cache. */
306 struct trad_frame_cache
*cache
=
307 m68k_linux_sigtramp_frame_cache (this_frame
, this_cache
);
308 return trad_frame_get_register (cache
, this_frame
, regnum
);
312 m68k_linux_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
313 struct frame_info
*this_frame
,
314 void **this_prologue_cache
)
316 return m68k_linux_pc_in_sigtramp (this_frame
);
319 static const struct frame_unwind m68k_linux_sigtramp_frame_unwind
=
322 default_frame_unwind_stop_reason
,
323 m68k_linux_sigtramp_frame_this_id
,
324 m68k_linux_sigtramp_frame_prev_register
,
326 m68k_linux_sigtramp_frame_sniffer
330 m68k_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
332 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
334 linux_init_abi (info
, gdbarch
);
336 tdep
->jb_pc
= M68K_LINUX_JB_PC
;
337 tdep
->jb_elt_size
= M68K_LINUX_JB_ELEMENT_SIZE
;
339 /* GNU/Linux uses a calling convention that's similar to SVR4. It
340 returns integer values in %d0/%d1, pointer values in %a0 and
341 floating values in %fp0, just like SVR4, but uses %a1 to pass the
342 address to store a structure value. It also returns small
343 structures in registers instead of memory. */
344 m68k_svr4_init_abi (info
, gdbarch
);
345 tdep
->struct_value_regnum
= M68K_A1_REGNUM
;
346 tdep
->struct_return
= reg_struct_return
;
348 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
350 frame_unwind_append_unwinder (gdbarch
, &m68k_linux_sigtramp_frame_unwind
);
352 /* Shared library handling. */
354 /* GNU/Linux uses SVR4-style shared libraries. */
355 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
356 svr4_ilp32_fetch_link_map_offsets
);
358 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
359 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
361 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
363 /* Enable TLS support. */
364 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
365 svr4_fetch_objfile_link_map
);
367 set_gdbarch_get_siginfo_type (gdbarch
, linux_get_siginfo_type
);
370 /* Provide a prototype to silence -Wmissing-prototypes. */
371 extern initialize_file_ftype _initialize_m68k_linux_tdep
;
374 _initialize_m68k_linux_tdep (void)
376 gdbarch_register_osabi (bfd_arch_m68k
, 0, GDB_OSABI_LINUX
,
377 m68k_linux_init_abi
);
378 observer_attach_inferior_created (m68k_linux_inferior_created
);