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"
33 #include "m68k-tdep.h"
35 /* Offsets (in target ints) into jmp_buf. */
37 #define M68K_LINUX_JB_ELEMENT_SIZE 4
38 #define M68K_LINUX_JB_PC 7
40 /* Check whether insn1 and insn2 are parts of a signal trampoline. */
42 #define IS_SIGTRAMP(insn1, insn2) \
43 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
44 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
45 /* moveq #119,d0; trap #0 */ \
46 || insn1 == 0x70774e40)
48 #define IS_RT_SIGTRAMP(insn1, insn2) \
49 (/* movel #173,d0; trap #0 */ \
50 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
51 /* moveq #82,d0; notb d0; trap #0 */ \
52 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
54 /* Return non-zero if PC points into the signal trampoline. For the sake
55 of m68k_linux_frame_saved_pc we also distinguish between non-RT and RT
56 signal trampolines. */
59 m68k_linux_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
63 unsigned long insn0
, insn1
, insn2
;
65 if (read_memory_nobpt (pc
- 4, buf
, sizeof (buf
)))
67 insn1
= extract_unsigned_integer (buf
+ 4, 4);
68 insn2
= extract_unsigned_integer (buf
+ 8, 4);
69 if (IS_SIGTRAMP (insn1
, insn2
))
71 if (IS_RT_SIGTRAMP (insn1
, insn2
))
74 insn0
= extract_unsigned_integer (buf
, 4);
75 if (IS_SIGTRAMP (insn0
, insn1
))
77 if (IS_RT_SIGTRAMP (insn0
, insn1
))
80 insn0
= ((insn0
<< 16) & 0xffffffff) | (insn1
>> 16);
81 insn1
= ((insn1
<< 16) & 0xffffffff) | (insn2
>> 16);
82 if (IS_SIGTRAMP (insn0
, insn1
))
84 if (IS_RT_SIGTRAMP (insn0
, insn1
))
90 /* Offset to saved PC in sigcontext, from <asm/sigcontext.h>. */
91 #define SIGCONTEXT_PC_OFFSET 26
93 /* Offset to saved PC in ucontext, from <asm/ucontext.h>. */
94 #define UCONTEXT_PC_OFFSET 88
96 /* Get saved user PC for sigtramp from sigcontext or ucontext. */
99 m68k_linux_sigtramp_saved_pc (struct frame_info
*frame
)
101 CORE_ADDR sigcontext_addr
;
102 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
103 int ptrbytes
= TARGET_PTR_BIT
/ TARGET_CHAR_BIT
;
104 int sigcontext_offs
= (2 * TARGET_INT_BIT
) / TARGET_CHAR_BIT
;
106 /* Get sigcontext address, it is the third parameter on the stack. */
107 if (get_next_frame (frame
))
109 = read_memory_unsigned_integer (get_frame_base (get_next_frame (frame
))
115 = read_memory_unsigned_integer (read_register (SP_REGNUM
)
119 /* Don't cause a memory_error when accessing sigcontext in case the
120 stack layout has changed or the stack is corrupt. */
121 if (m68k_linux_pc_in_sigtramp (get_frame_pc (frame
), 0) == 2)
122 target_read_memory (sigcontext_addr
+ UCONTEXT_PC_OFFSET
, buf
, ptrbytes
);
124 target_read_memory (sigcontext_addr
+ SIGCONTEXT_PC_OFFSET
, buf
, ptrbytes
);
125 return extract_unsigned_integer (buf
, ptrbytes
);
128 /* Return the saved program counter for FRAME. */
131 m68k_linux_frame_saved_pc (struct frame_info
*frame
)
133 if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
134 return m68k_linux_sigtramp_saved_pc (frame
);
136 return read_memory_unsigned_integer (get_frame_base (frame
) + 4, 4);
139 /* The following definitions are appropriate when using the ELF
140 format, where floating point values are returned in fp0, pointer
141 values in a0 and other values in d0. */
143 /* Extract from an array REGBUF containing the (raw) register state a
144 function return value of type TYPE, and copy that, in virtual
145 format, into VALBUF. */
148 m68k_linux_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
150 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
152 REGISTER_CONVERT_TO_VIRTUAL (FP0_REGNUM
, type
,
153 regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
156 else if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
157 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (M68K_A0_REGNUM
),
161 regbuf
+ (TYPE_LENGTH (type
) >= 4 ? 0 : 4 - TYPE_LENGTH (type
)),
165 /* Write into appropriate registers a function return value of type
166 TYPE, given in virtual format. */
169 m68k_linux_store_return_value (struct type
*type
, char *valbuf
)
171 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
173 char raw_buffer
[REGISTER_RAW_SIZE (FP0_REGNUM
)];
174 REGISTER_CONVERT_TO_RAW (type
, FP0_REGNUM
, valbuf
, raw_buffer
);
175 deprecated_write_register_bytes (REGISTER_BYTE (FP0_REGNUM
),
176 raw_buffer
, TYPE_LENGTH (type
));
180 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
181 deprecated_write_register_bytes (REGISTER_BYTE (M68K_A0_REGNUM
),
182 valbuf
, TYPE_LENGTH (type
));
183 deprecated_write_register_bytes (0, valbuf
, TYPE_LENGTH (type
));
187 /* Extract from an array REGBUF containing the (raw) register state
188 the address in which a function should return its structure value,
192 m68k_linux_extract_struct_value_address (char *regbuf
)
194 return *(CORE_ADDR
*) (regbuf
+ REGISTER_BYTE (M68K_A0_REGNUM
));
198 m68k_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
200 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
202 tdep
->jb_pc
= M68K_LINUX_JB_PC
;
203 tdep
->jb_elt_size
= M68K_LINUX_JB_ELEMENT_SIZE
;
205 set_gdbarch_deprecated_frame_saved_pc (gdbarch
,
206 m68k_linux_frame_saved_pc
);
207 set_gdbarch_deprecated_extract_return_value (gdbarch
,
208 m68k_linux_extract_return_value
);
209 set_gdbarch_deprecated_store_return_value (gdbarch
,
210 m68k_linux_store_return_value
);
211 set_gdbarch_deprecated_extract_struct_value_address (gdbarch
,
212 m68k_linux_extract_struct_value_address
);
214 set_gdbarch_pc_in_sigtramp (gdbarch
, m68k_linux_pc_in_sigtramp
);
216 /* Shared library handling. */
217 set_gdbarch_in_solib_call_trampoline (gdbarch
, in_plt_section
);
218 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
222 _initialize_m68k_linux_tdep (void)
224 gdbarch_register_osabi (bfd_arch_m68k
, 0, GDB_OSABI_LINUX
,
225 m68k_linux_init_abi
);