* Makefile.in (m68k-tdep.o, m68klinux-tdep.o): Update
[deliverable/binutils-gdb.git] / gdb / m68klinux-tdep.c
CommitLineData
0a595803
AS
1/* Motorola m68k target-dependent support for GNU/Linux.
2
d0b45d99 3 Copyright 1996, 1998, 2000, 2001, 2002, 2003 Free Software Foundation,
0a595803
AS
4 Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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. */
22
23#include "defs.h"
24#include "gdbcore.h"
8de307e0
AS
25#include "doublest.h"
26#include "floatformat.h"
0a595803
AS
27#include "frame.h"
28#include "target.h"
d0b45d99
AS
29#include "gdb_string.h"
30#include "gdbtypes.h"
55809acb 31#include "osabi.h"
eb2e12d7
AS
32#include "regcache.h"
33#include "objfiles.h"
34#include "symtab.h"
d0b45d99 35#include "m68k-tdep.h"
0a595803 36\f
eb2e12d7
AS
37/* Offsets (in target ints) into jmp_buf. */
38
39#define M68K_LINUX_JB_ELEMENT_SIZE 4
40#define M68K_LINUX_JB_PC 7
41
0a595803
AS
42/* Check whether insn1 and insn2 are parts of a signal trampoline. */
43
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)
49
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))
55
8de307e0
AS
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. */
0a595803 59
eb2e12d7
AS
60static int
61m68k_linux_pc_in_sigtramp (CORE_ADDR pc, char *name)
0a595803
AS
62{
63 CORE_ADDR sp;
64 char buf[12];
65 unsigned long insn0, insn1, insn2;
66
67 if (read_memory_nobpt (pc - 4, buf, sizeof (buf)))
68 return 0;
69 insn1 = extract_unsigned_integer (buf + 4, 4);
70 insn2 = extract_unsigned_integer (buf + 8, 4);
71 if (IS_SIGTRAMP (insn1, insn2))
72 return 1;
73 if (IS_RT_SIGTRAMP (insn1, insn2))
74 return 2;
75
76 insn0 = extract_unsigned_integer (buf, 4);
77 if (IS_SIGTRAMP (insn0, insn1))
78 return 1;
79 if (IS_RT_SIGTRAMP (insn0, insn1))
80 return 2;
81
55809acb
AS
82 insn0 = ((insn0 << 16) & 0xffffffff) | (insn1 >> 16);
83 insn1 = ((insn1 << 16) & 0xffffffff) | (insn2 >> 16);
0a595803
AS
84 if (IS_SIGTRAMP (insn0, insn1))
85 return 1;
86 if (IS_RT_SIGTRAMP (insn0, insn1))
87 return 2;
88
89 return 0;
90}
91
8de307e0
AS
92/* From <asm/sigcontext.h>. */
93static int m68k_linux_sigcontext_reg_offset[M68K_NUM_REGS] =
0a595803 94{
8de307e0
AS
95 2 * 4, /* %d0 */
96 3 * 4, /* %d1 */
97 -1, /* %d2 */
98 -1, /* %d3 */
99 -1, /* %d4 */
100 -1, /* %d5 */
101 -1, /* %d6 */
102 -1, /* %d7 */
103 4 * 4, /* %a0 */
104 5 * 4, /* %a1 */
105 -1, /* %a2 */
106 -1, /* %a3 */
107 -1, /* %a4 */
108 -1, /* %a5 */
109 -1, /* %fp */
110 1 * 4, /* %sp */
111 5 * 4 + 2, /* %sr */
112 6 * 4 + 2, /* %pc */
113 8 * 4, /* %fp0 */
114 11 * 4, /* %fp1 */
115 -1, /* %fp2 */
116 -1, /* %fp3 */
117 -1, /* %fp4 */
118 -1, /* %fp5 */
119 -1, /* %fp6 */
120 -1, /* %fp7 */
121 14 * 4, /* %fpcr */
122 15 * 4, /* %fpsr */
123 16 * 4 /* %fpiaddr */
124};
125
126/* From <asm/ucontext.h>. */
127static int m68k_linux_ucontext_reg_offset[M68K_NUM_REGS] =
128{
129 6 * 4, /* %d0 */
130 7 * 4, /* %d1 */
131 8 * 4, /* %d2 */
132 9 * 4, /* %d3 */
133 10 * 4, /* %d4 */
134 11 * 4, /* %d5 */
135 12 * 4, /* %d6 */
136 13 * 4, /* %d7 */
137 14 * 4, /* %a0 */
138 15 * 4, /* %a1 */
139 16 * 4, /* %a2 */
140 17 * 4, /* %a3 */
141 18 * 4, /* %a4 */
142 19 * 4, /* %a5 */
143 20 * 4, /* %fp */
144 21 * 4, /* %sp */
145 23 * 4, /* %sr */
146 22 * 4, /* %pc */
147 27 * 4, /* %fp0 */
148 30 * 4, /* %fp1 */
149 33 * 4, /* %fp2 */
150 36 * 4, /* %fp3 */
151 39 * 4, /* %fp4 */
152 42 * 4, /* %fp5 */
153 45 * 4, /* %fp6 */
154 48 * 4, /* %fp7 */
155 24 * 4, /* %fpcr */
156 25 * 4, /* %fpsr */
157 26 * 4 /* %fpiaddr */
158};
159
160
161/* Get info about saved registers in sigtramp. */
162
163static struct m68k_sigtramp_info
164m68k_linux_get_sigtramp_info (struct frame_info *next_frame)
165{
166 CORE_ADDR sp;
167 char buf[4];
168 struct m68k_sigtramp_info info;
169
170 frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
171 sp = extract_unsigned_integer (buf, 4);
0a595803
AS
172
173 /* Get sigcontext address, it is the third parameter on the stack. */
8de307e0
AS
174 info.sigcontext_addr = read_memory_unsigned_integer (sp + 8, 4);
175
176 if (m68k_linux_pc_in_sigtramp (frame_pc_unwind (next_frame), 0) == 2)
177 info.sc_reg_offset = m68k_linux_ucontext_reg_offset;
0a595803 178 else
8de307e0
AS
179 info.sc_reg_offset = m68k_linux_sigcontext_reg_offset;
180 return info;
0a595803
AS
181}
182
8de307e0
AS
183/* Extract from an array REGBUF containing the (raw) register state, a
184 function return value of TYPE, and copy that, in virtual format,
185 into VALBUF. */
0a595803 186
8de307e0
AS
187static void
188m68k_linux_extract_return_value (struct type *type, struct regcache *regcache,
189 void *valbuf)
0a595803 190{
8de307e0
AS
191 int len = TYPE_LENGTH (type);
192 char buf[M68K_MAX_REGISTER_SIZE];
d0b45d99 193
8de307e0
AS
194 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
195 && TYPE_NFIELDS (type) == 1)
196 {
197 m68k_linux_extract_return_value (TYPE_FIELD_TYPE (type, 0), regcache,
198 valbuf);
199 return;
200 }
55809acb 201
d0b45d99
AS
202 if (TYPE_CODE (type) == TYPE_CODE_FLT)
203 {
8de307e0
AS
204 regcache_raw_read (regcache, M68K_FP0_REGNUM, buf);
205 convert_typed_floating (buf, builtin_type_m68881_ext, valbuf, type);
d0b45d99
AS
206 }
207 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
8de307e0 208 regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf);
d0b45d99 209 else
8de307e0
AS
210 {
211 if (len <= 4)
212 {
213 regcache_raw_read (regcache, M68K_D0_REGNUM, buf);
214 memcpy (valbuf, buf + (4 - len), len);
215 }
216 else if (len <= 8)
217 {
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));
222 }
223 else
224 internal_error (__FILE__, __LINE__,
225 "Cannot extract return value of %d bytes long.", len);
226 }
d0b45d99
AS
227}
228
8de307e0
AS
229/* Write into the appropriate registers a function return value stored
230 in VALBUF of type TYPE, given in virtual format. */
55809acb
AS
231
232static void
8de307e0
AS
233m68k_linux_store_return_value (struct type *type, struct regcache *regcache,
234 const void *valbuf)
d0b45d99 235{
8de307e0
AS
236 int len = TYPE_LENGTH (type);
237
238 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
239 && TYPE_NFIELDS (type) == 1)
240 {
241 m68k_linux_store_return_value (TYPE_FIELD_TYPE (type, 0), regcache,
242 valbuf);
243 return;
244 }
245
d0b45d99
AS
246 if (TYPE_CODE (type) == TYPE_CODE_FLT)
247 {
8de307e0
AS
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);
d0b45d99 251 }
8de307e0
AS
252 else if (TYPE_CODE (type) == TYPE_CODE_PTR)
253 regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf);
d0b45d99
AS
254 else
255 {
8de307e0
AS
256 if (len <= 4)
257 regcache_raw_write_part (regcache, M68K_D0_REGNUM,
258 4 - len, len, valbuf);
259 else if (len <= 8)
260 {
261 regcache_raw_write_part (regcache, M68K_D1_REGNUM, 8 - len,
262 len - 4, valbuf);
263 regcache_raw_write (regcache, M68K_D0_REGNUM,
264 (char *) valbuf + (len - 4));
265 }
266 else
267 internal_error (__FILE__, __LINE__,
268 "Cannot store return value of %d bytes long.", len);
d0b45d99
AS
269 }
270}
271
55809acb
AS
272/* Extract from an array REGBUF containing the (raw) register state
273 the address in which a function should return its structure value,
274 as a CORE_ADDR. */
275
276static CORE_ADDR
8de307e0 277m68k_linux_extract_struct_value_address (struct regcache *regcache)
d0b45d99 278{
8de307e0
AS
279 char buf[4];
280
281 regcache_cooked_read (regcache, M68K_A0_REGNUM, buf);
282 return extract_unsigned_integer (buf, 4);
0a595803 283}
55809acb
AS
284
285static void
286m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
287{
eb2e12d7
AS
288 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
289
290 tdep->jb_pc = M68K_LINUX_JB_PC;
291 tdep->jb_elt_size = M68K_LINUX_JB_ELEMENT_SIZE;
8de307e0 292 tdep->get_sigtramp_info = m68k_linux_get_sigtramp_info;
eb2e12d7 293
8de307e0
AS
294 set_gdbarch_extract_return_value (gdbarch, m68k_linux_extract_return_value);
295 set_gdbarch_store_return_value (gdbarch, m68k_linux_store_return_value);
296 set_gdbarch_extract_struct_value_address (gdbarch,
297 m68k_linux_extract_struct_value_address);
eb2e12d7
AS
298
299 set_gdbarch_pc_in_sigtramp (gdbarch, m68k_linux_pc_in_sigtramp);
300
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);
55809acb
AS
304}
305
306void
307_initialize_m68k_linux_tdep (void)
308{
309 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_LINUX,
310 m68k_linux_init_abi);
311}
This page took 0.100875 seconds and 4 git commands to generate.