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. */
27 #include "gdb_string.h"
30 #include "m68k-tdep.h"
32 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
34 #define IS_SIGTRAMP(insn1, insn2) \
35 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
36 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
37 /* moveq #119,d0; trap #0 */ \
38 || insn1 == 0x70774e40)
40 #define IS_RT_SIGTRAMP(insn1, insn2) \
41 (/* movel #173,d0; trap #0 */ \
42 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
43 /* moveq #82,d0; notb d0; trap #0 */ \
44 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
46 /* Return non-zero if PC points into the signal trampoline. For the sake
47 of m68k_linux_frame_saved_pc we also distinguish between non-RT and RT
48 signal trampolines. */
51 m68k_linux_in_sigtramp (CORE_ADDR pc)
55 unsigned long insn0, insn1, insn2;
57 if (read_memory_nobpt (pc - 4, buf, sizeof (buf)))
59 insn1 = extract_unsigned_integer (buf + 4, 4);
60 insn2 = extract_unsigned_integer (buf + 8, 4);
61 if (IS_SIGTRAMP (insn1, insn2))
63 if (IS_RT_SIGTRAMP (insn1, insn2))
66 insn0 = extract_unsigned_integer (buf, 4);
67 if (IS_SIGTRAMP (insn0, insn1))
69 if (IS_RT_SIGTRAMP (insn0, insn1))
72 insn0 = ((insn0 << 16) & 0xffffffff) | (insn1 >> 16);
73 insn1 = ((insn1 << 16) & 0xffffffff) | (insn2 >> 16);
74 if (IS_SIGTRAMP (insn0, insn1))
76 if (IS_RT_SIGTRAMP (insn0, insn1))
82 /* Offset to saved PC in sigcontext, from <asm/sigcontext.h>. */
83 #define SIGCONTEXT_PC_OFFSET 26
85 /* Offset to saved PC in ucontext, from <asm/ucontext.h>. */
86 #define UCONTEXT_PC_OFFSET 88
88 /* Get saved user PC for sigtramp from sigcontext or ucontext. */
91 m68k_linux_sigtramp_saved_pc (struct frame_info *frame)
93 CORE_ADDR sigcontext_addr;
94 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
95 int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
96 int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
98 /* Get sigcontext address, it is the third parameter on the stack. */
99 if (get_next_frame (frame))
101 = read_memory_unsigned_integer (get_frame_base (get_next_frame (frame))
107 = read_memory_unsigned_integer (read_register (SP_REGNUM)
111 /* Don't cause a memory_error when accessing sigcontext in case the
112 stack layout has changed or the stack is corrupt. */
113 if (m68k_linux_in_sigtramp (get_frame_pc (frame)) == 2)
114 target_read_memory (sigcontext_addr + UCONTEXT_PC_OFFSET, buf, ptrbytes);
116 target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
117 return extract_unsigned_integer (buf, ptrbytes);
120 /* Return the saved program counter for FRAME. */
123 m68k_linux_frame_saved_pc (struct frame_info *frame)
125 if (get_frame_type (frame) == SIGTRAMP_FRAME)
126 return m68k_linux_sigtramp_saved_pc (frame);
128 return read_memory_unsigned_integer (get_frame_base (frame) + 4, 4);
131 /* The following definitions are appropriate when using the ELF
132 format, where floating point values are returned in fp0, pointer
133 values in a0 and other values in d0. */
135 /* Extract from an array REGBUF containing the (raw) register state a
136 function return value of type TYPE, and copy that, in virtual
137 format, into VALBUF. */
140 m68k_linux_extract_return_value (struct type *type, char *regbuf, char *valbuf)
142 if (TYPE_CODE (type) == TYPE_CODE_FLT)
144 REGISTER_CONVERT_TO_VIRTUAL (FP0_REGNUM, type,
145 regbuf + REGISTER_BYTE (FP0_REGNUM),
148 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
149 memcpy (valbuf, regbuf + REGISTER_BYTE (M68K_A0_REGNUM),
153 regbuf + (TYPE_LENGTH (type) >= 4 ? 0 : 4 - TYPE_LENGTH (type)),
157 /* Write into appropriate registers a function return value of type
158 TYPE, given in virtual format. */
161 m68k_linux_store_return_value (struct type *type, char *valbuf)
163 if (TYPE_CODE (type) == TYPE_CODE_FLT)
165 char raw_buffer[REGISTER_RAW_SIZE (FP0_REGNUM)];
166 REGISTER_CONVERT_TO_RAW (type, FP0_REGNUM, valbuf, raw_buffer);
167 deprecated_write_register_bytes (REGISTER_BYTE (FP0_REGNUM),
168 raw_buffer, TYPE_LENGTH (type));
172 if (TYPE_CODE (type) == TYPE_CODE_PTR)
173 deprecated_write_register_bytes (REGISTER_BYTE (M68K_A0_REGNUM),
174 valbuf, TYPE_LENGTH (type));
175 deprecated_write_register_bytes (0, valbuf, TYPE_LENGTH (type));
179 /* Extract from an array REGBUF containing the (raw) register state
180 the address in which a function should return its structure value,
184 m68k_linux_extract_struct_value_address (char *regbuf)
186 return *(CORE_ADDR *) (regbuf + REGISTER_BYTE (M68K_A0_REGNUM));
190 m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
192 set_gdbarch_deprecated_frame_saved_pc (gdbarch,
193 m68k_linux_frame_saved_pc);
194 set_gdbarch_deprecated_extract_return_value (gdbarch,
195 m68k_linux_extract_return_value);
196 set_gdbarch_deprecated_store_return_value (gdbarch,
197 m68k_linux_store_return_value);
198 set_gdbarch_deprecated_extract_struct_value_address (gdbarch,
199 m68k_linux_extract_struct_value_address);
203 _initialize_m68k_linux_tdep (void)
205 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_LINUX,
206 m68k_linux_init_abi);