1 /* Motorola m68k target-dependent support for GNU/Linux.
3 Copyright 1996, 1998, 2000, 2001, 2002, 2003 Free Software Foundation,
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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
26 #include "floatformat.h"
29 #include "gdb_string.h"
35 #include "m68k-tdep.h"
37 /* Offsets (in target ints) into jmp_buf. */
39 #define M68K_LINUX_JB_ELEMENT_SIZE 4
40 #define M68K_LINUX_JB_PC 7
42 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
44 #define IS_SIGTRAMP(insn1, insn2) \
45 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
46 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
47 /* moveq #119,d0; trap #0 */ \
48 || insn1 == 0x70774e40)
50 #define IS_RT_SIGTRAMP(insn1, insn2) \
51 (/* movel #173,d0; trap #0 */ \
52 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
53 /* moveq #82,d0; notb d0; trap #0 */ \
54 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
56 /* Return non-zero if PC points into the signal trampoline. For the
57 sake of m68k_linux_get_sigtramp_info we also distinguish between
58 non-RT and RT signal trampolines. */
61 m68k_linux_pc_in_sigtramp (CORE_ADDR pc, char *name)
65 unsigned long insn0, insn1, insn2;
67 if (read_memory_nobpt (pc - 4, buf, sizeof (buf)))
69 insn1 = extract_unsigned_integer (buf + 4, 4);
70 insn2 = extract_unsigned_integer (buf + 8, 4);
71 if (IS_SIGTRAMP (insn1, insn2))
73 if (IS_RT_SIGTRAMP (insn1, insn2))
76 insn0 = extract_unsigned_integer (buf, 4);
77 if (IS_SIGTRAMP (insn0, insn1))
79 if (IS_RT_SIGTRAMP (insn0, insn1))
82 insn0 = ((insn0 << 16) & 0xffffffff) | (insn1 >> 16);
83 insn1 = ((insn1 << 16) & 0xffffffff) | (insn2 >> 16);
84 if (IS_SIGTRAMP (insn0, insn1))
86 if (IS_RT_SIGTRAMP (insn0, insn1))
92 /* From <asm/sigcontext.h>. */
93 static int m68k_linux_sigcontext_reg_offset[M68K_NUM_REGS] =
123 16 * 4 /* %fpiaddr */
126 /* From <asm/ucontext.h>. */
127 static int m68k_linux_ucontext_reg_offset[M68K_NUM_REGS] =
157 26 * 4 /* %fpiaddr */
161 /* Get info about saved registers in sigtramp. */
163 static struct m68k_sigtramp_info
164 m68k_linux_get_sigtramp_info (struct frame_info *next_frame)
168 struct m68k_sigtramp_info info;
170 frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
171 sp = extract_unsigned_integer (buf, 4);
173 /* Get sigcontext address, it is the third parameter on the stack. */
174 info.sigcontext_addr = read_memory_unsigned_integer (sp + 8, 4);
176 if (m68k_linux_pc_in_sigtramp (frame_pc_unwind (next_frame), 0) == 2)
177 info.sc_reg_offset = m68k_linux_ucontext_reg_offset;
179 info.sc_reg_offset = m68k_linux_sigcontext_reg_offset;
183 /* Extract from an array REGBUF containing the (raw) register state, a
184 function return value of TYPE, and copy that, in virtual format,
188 m68k_linux_extract_return_value (struct type *type, struct regcache *regcache,
191 int len = TYPE_LENGTH (type);
192 char buf[M68K_MAX_REGISTER_SIZE];
194 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
195 && TYPE_NFIELDS (type) == 1)
197 m68k_linux_extract_return_value (TYPE_FIELD_TYPE (type, 0), regcache,
202 if (TYPE_CODE (type) == TYPE_CODE_FLT)
204 regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
205 convert_typed_floating (buf, builtin_type_m68881_ext, valbuf, type);
207 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
208 regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
213 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
214 memcpy (valbuf, buf + (4 - len), len);
218 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
219 memcpy (valbuf, buf + (8 - len), len - 4);
220 regcache_raw_read (regcache, M68K_D1_REGNUM,
221 (char *) valbuf + (len - 4));
224 internal_error (__FILE__, __LINE__,
225 "Cannot extract return value of %d bytes long.", len);
229 /* Write into the appropriate registers a function return value stored
230 in VALBUF of type TYPE, given in virtual format. */
233 m68k_linux_store_return_value (struct type *type, struct regcache *regcache,
236 int len = TYPE_LENGTH (type);
238 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
239 && TYPE_NFIELDS (type) == 1)
241 m68k_linux_store_return_value (TYPE_FIELD_TYPE (type, 0), regcache,
246 if (TYPE_CODE (type) == TYPE_CODE_FLT)
248 char buf[M68K_MAX_REGISTER_SIZE];
249 convert_typed_floating (valbuf, type, buf, builtin_type_m68881_ext);
250 regcache_raw_write (regcache, M68K_FP0_REGNUM, buf);
252 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
253 regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
257 regcache_raw_write_part (regcache, M68K_D0_REGNUM,
258 4 - len, len, valbuf);
261 regcache_raw_write_part (regcache, M68K_D1_REGNUM, 8 - len,
263 regcache_raw_write (regcache, M68K_D0_REGNUM,
264 (char *) valbuf + (len - 4));
267 internal_error (__FILE__, __LINE__,
268 "Cannot store return value of %d bytes long.", len);
272 /* Extract from an array REGBUF containing the (raw) register state
273 the address in which a function should return its structure value,
277 m68k_linux_extract_struct_value_address (struct regcache *regcache)
281 regcache_cooked_read (regcache, M68K_A0_REGNUM, buf);
282 return extract_unsigned_integer (buf, 4);
286 m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
288 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
290 tdep->jb_pc = M68K_LINUX_JB_PC;
291 tdep->jb_elt_size = M68K_LINUX_JB_ELEMENT_SIZE;
292 tdep->get_sigtramp_info = m68k_linux_get_sigtramp_info;
293 tdep->struct_return = reg_struct_return;
295 set_gdbarch_extract_return_value (gdbarch, m68k_linux_extract_return_value);
296 set_gdbarch_store_return_value (gdbarch, m68k_linux_store_return_value);
297 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, m68k_linux_extract_struct_value_address);
299 set_gdbarch_pc_in_sigtramp (gdbarch, m68k_linux_pc_in_sigtramp);
301 /* Shared library handling. */
302 set_gdbarch_in_solib_call_trampoline (gdbarch, in_plt_section);
303 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
307 _initialize_m68k_linux_tdep (void)
309 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_LINUX,
310 m68k_linux_init_abi);