GDB (xrefs)
Loading...
Searching...
No Matches
m68k-linux-tdep.c
Go to the documentation of this file.
1/* Motorola m68k target-dependent support for GNU/Linux.
2
3 Copyright (C) 1996-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "gdbcore.h"
22#include "frame.h"
23#include "target.h"
24#include "gdbtypes.h"
25#include "osabi.h"
26#include "regcache.h"
27#include "objfiles.h"
28#include "symtab.h"
29#include "m68k-tdep.h"
30#include "trad-frame.h"
31#include "frame-unwind.h"
32#include "glibc-tdep.h"
33#include "solib-svr4.h"
34#include "auxv.h"
35#include "observable.h"
36#include "elf/common.h"
37#include "linux-tdep.h"
38#include "regset.h"
39
40/* Offsets (in target ints) into jmp_buf. */
41
42#define M68K_LINUX_JB_ELEMENT_SIZE 4
43#define M68K_LINUX_JB_PC 7
44
45/* Check whether insn1 and insn2 are parts of a signal trampoline. */
46
47#define IS_SIGTRAMP(insn1, insn2) \
48 (/* addaw #20,sp; moveq #119,d0; trap #0 */ \
49 (insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
50 /* moveq #119,d0; trap #0 */ \
51 || insn1 == 0x70774e40)
52
53#define IS_RT_SIGTRAMP(insn1, insn2) \
54 (/* movel #173,d0; trap #0 */ \
55 (insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
56 /* moveq #82,d0; notb d0; trap #0 */ \
57 || (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
58
59/* Return non-zero if THIS_FRAME corresponds to a signal trampoline. For
60 the sake of m68k_linux_get_sigtramp_info we also distinguish between
61 non-RT and RT signal trampolines. */
62
63static int
65{
66 struct gdbarch *gdbarch = get_frame_arch (this_frame);
67 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
68 gdb_byte buf[12];
69 unsigned long insn0, insn1, insn2;
70 CORE_ADDR pc = get_frame_pc (this_frame);
71
72 if (!safe_frame_unwind_memory (this_frame, pc - 4, {buf, sizeof (buf)}))
73 return 0;
74 insn1 = extract_unsigned_integer (buf + 4, 4, byte_order);
75 insn2 = extract_unsigned_integer (buf + 8, 4, byte_order);
76 if (IS_SIGTRAMP (insn1, insn2))
77 return 1;
78 if (IS_RT_SIGTRAMP (insn1, insn2))
79 return 2;
80
81 insn0 = extract_unsigned_integer (buf, 4, byte_order);
82 if (IS_SIGTRAMP (insn0, insn1))
83 return 1;
84 if (IS_RT_SIGTRAMP (insn0, insn1))
85 return 2;
86
87 insn0 = ((insn0 << 16) & 0xffffffff) | (insn1 >> 16);
88 insn1 = ((insn1 << 16) & 0xffffffff) | (insn2 >> 16);
89 if (IS_SIGTRAMP (insn0, insn1))
90 return 1;
91 if (IS_RT_SIGTRAMP (insn0, insn1))
92 return 2;
93
94 return 0;
95}
96
97/* From <asm/sigcontext.h>. */
99{
100 2 * 4, /* %d0 */
101 3 * 4, /* %d1 */
102 -1, /* %d2 */
103 -1, /* %d3 */
104 -1, /* %d4 */
105 -1, /* %d5 */
106 -1, /* %d6 */
107 -1, /* %d7 */
108 4 * 4, /* %a0 */
109 5 * 4, /* %a1 */
110 -1, /* %a2 */
111 -1, /* %a3 */
112 -1, /* %a4 */
113 -1, /* %a5 */
114 -1, /* %fp */
115 1 * 4, /* %sp */
116 6 * 4, /* %sr */
117 6 * 4 + 2, /* %pc */
118 8 * 4, /* %fp0 */
119 11 * 4, /* %fp1 */
120 -1, /* %fp2 */
121 -1, /* %fp3 */
122 -1, /* %fp4 */
123 -1, /* %fp5 */
124 -1, /* %fp6 */
125 -1, /* %fp7 */
126 14 * 4, /* %fpcr */
127 15 * 4, /* %fpsr */
128 16 * 4 /* %fpiaddr */
129};
130
132{
133 2 * 4, /* %d0 */
134 3 * 4, /* %d1 */
135 -1, /* %d2 */
136 -1, /* %d3 */
137 -1, /* %d4 */
138 -1, /* %d5 */
139 -1, /* %d6 */
140 -1, /* %d7 */
141 4 * 4, /* %a0 */
142 5 * 4, /* %a1 */
143 -1, /* %a2 */
144 -1, /* %a3 */
145 -1, /* %a4 */
146 6 * 4, /* %a5 */
147 -1, /* %fp */
148 1 * 4, /* %sp */
149 7 * 4, /* %sr */
150 7 * 4 + 2, /* %pc */
151 -1, /* %fp0 */
152 -1, /* %fp1 */
153 -1, /* %fp2 */
154 -1, /* %fp3 */
155 -1, /* %fp4 */
156 -1, /* %fp5 */
157 -1, /* %fp6 */
158 -1, /* %fp7 */
159 -1, /* %fpcr */
160 -1, /* %fpsr */
161 -1 /* %fpiaddr */
162};
163
164/* From <asm/ucontext.h>. */
166{
167 6 * 4, /* %d0 */
168 7 * 4, /* %d1 */
169 8 * 4, /* %d2 */
170 9 * 4, /* %d3 */
171 10 * 4, /* %d4 */
172 11 * 4, /* %d5 */
173 12 * 4, /* %d6 */
174 13 * 4, /* %d7 */
175 14 * 4, /* %a0 */
176 15 * 4, /* %a1 */
177 16 * 4, /* %a2 */
178 17 * 4, /* %a3 */
179 18 * 4, /* %a4 */
180 19 * 4, /* %a5 */
181 20 * 4, /* %fp */
182 21 * 4, /* %sp */
183 23 * 4, /* %sr */
184 22 * 4, /* %pc */
185 27 * 4, /* %fp0 */
186 30 * 4, /* %fp1 */
187 33 * 4, /* %fp2 */
188 36 * 4, /* %fp3 */
189 39 * 4, /* %fp4 */
190 42 * 4, /* %fp5 */
191 45 * 4, /* %fp6 */
192 48 * 4, /* %fp7 */
193 24 * 4, /* %fpcr */
194 25 * 4, /* %fpsr */
195 26 * 4 /* %fpiaddr */
196};
197
198
199/* Get info about saved registers in sigtramp. */
200
202{
203 /* Address of sigcontext. */
205
206 /* Offset of registers in `struct sigcontext'. */
208};
209
210/* Nonzero if running on uClinux. */
212
213static void
215{
216 /* Record that we will need to re-evaluate whether we are running on a
217 uClinux or normal GNU/Linux target (see m68k_linux_get_sigtramp_info). */
219}
220
221static struct m68k_linux_sigtramp_info
223{
224 struct gdbarch *gdbarch = get_frame_arch (this_frame);
225 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
226 CORE_ADDR sp;
227 struct m68k_linux_sigtramp_info info;
228
229 /* Determine whether we are running on a uClinux or normal GNU/Linux
230 target so we can use the correct sigcontext layouts. */
231 if (target_is_uclinux == -1)
233
235
236 /* Get sigcontext address, it is the third parameter on the stack. */
237 info.sigcontext_addr = read_memory_unsigned_integer (sp + 8, 4, byte_order);
238
239 if (m68k_linux_pc_in_sigtramp (this_frame) == 2)
240 info.sc_reg_offset = m68k_linux_ucontext_reg_offset;
241 else
242 info.sc_reg_offset = (target_is_uclinux
245 return info;
246}
247
248/* Signal trampolines. */
249
250static struct trad_frame_cache *
252 void **this_cache)
253{
254 struct frame_id this_id;
255 struct trad_frame_cache *cache;
256 struct gdbarch *gdbarch = get_frame_arch (this_frame);
257 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
258 struct m68k_linux_sigtramp_info info;
259 gdb_byte buf[4];
260 int i;
261
262 if (*this_cache)
263 return (struct trad_frame_cache *) *this_cache;
264
265 cache = trad_frame_cache_zalloc (this_frame);
266
267 /* FIXME: cagney/2004-05-01: This is is long standing broken code.
268 The frame ID's code address should be the start-address of the
269 signal trampoline and not the current PC within that
270 trampoline. */
271 get_frame_register (this_frame, M68K_SP_REGNUM, buf);
272 /* See the end of m68k_push_dummy_call. */
273 this_id = frame_id_build (extract_unsigned_integer (buf, 4, byte_order)
274 - 4 + 8, get_frame_pc (this_frame));
275 trad_frame_set_id (cache, this_id);
276
277 info = m68k_linux_get_sigtramp_info (this_frame);
278
279 for (i = 0; i < M68K_NUM_REGS; i++)
280 if (info.sc_reg_offset[i] != -1)
281 trad_frame_set_reg_addr (cache, i,
282 info.sigcontext_addr + info.sc_reg_offset[i]);
283
284 *this_cache = cache;
285 return cache;
286}
287
288static void
290 void **this_cache,
291 struct frame_id *this_id)
292{
293 struct trad_frame_cache *cache =
295 trad_frame_get_id (cache, this_id);
296}
297
298static struct value *
300 void **this_cache,
301 int regnum)
302{
303 /* Make sure we've initialized the cache. */
304 struct trad_frame_cache *cache =
307}
308
309static int
312 void **this_prologue_cache)
313{
315}
316
327
328/* Register maps for supply/collect regset functions. */
329
331 {
332 { 7, M68K_D1_REGNUM, 4 }, /* d1 ... d7 */
333 { 7, M68K_A0_REGNUM, 4 }, /* a0 ... a6 */
334 { 1, M68K_D0_REGNUM, 4 },
335 { 1, M68K_SP_REGNUM, 4 },
336 { 1, REGCACHE_MAP_SKIP, 4 }, /* orig_d0 (skip) */
337 { 1, M68K_PS_REGNUM, 4 },
338 { 1, M68K_PC_REGNUM, 4 },
339 /* Ignore 16-bit fields 'fmtvec' and '__fill'. */
340 { 0 }
341 };
342
343#define M68K_LINUX_GREGS_SIZE (20 * 4)
344
346 {
347 { 8, M68K_FP0_REGNUM, 12 }, /* fp0 ... fp7 */
348 { 1, M68K_FPC_REGNUM, 4 },
349 { 1, M68K_FPS_REGNUM, 4 },
350 { 1, M68K_FPI_REGNUM, 4 },
351 { 0 }
352 };
353
354#define M68K_LINUX_FPREGS_SIZE (27 * 4)
355
356/* Register sets. */
357
363
369
370/* Iterate over core file register note sections. */
371
372static void
375 void *cb_data,
376 const struct regcache *regcache)
377{
379 NULL, cb_data);
381 &m68k_linux_fpregset, NULL, cb_data);
382}
383
384static void
386{
387 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
388
389 linux_init_abi (info, gdbarch, 0);
390
391 tdep->jb_pc = M68K_LINUX_JB_PC;
393
394 /* GNU/Linux uses a calling convention that's similar to SVR4. It
395 returns integer values in %d0/%d1, pointer values in %a0 and
396 floating values in %fp0, just like SVR4, but uses %a1 to pass the
397 address to store a structure value. It also returns small
398 structures in registers instead of memory. */
401 tdep->struct_return = reg_struct_return;
402
404
406
407 /* Shared library handling. */
408
409 /* GNU/Linux uses SVR4-style shared libraries. */
412
413 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
415
417
418 /* Core file support. */
421
422 /* Enable TLS support. */
425}
426
428void
int regnum
@ reg_struct_return
Definition arm-tdep.h:86
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition corefile.c:306
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
enum unwind_stop_reason default_frame_unwind_stop_reason(frame_info_ptr this_frame, void **this_cache)
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1399
CORE_ADDR get_frame_pc(frame_info_ptr frame)
Definition frame.c:2712
void get_frame_register(frame_info_ptr frame, int regnum, gdb_byte *buf)
Definition frame.c:1263
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition frame.c:736
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
bool safe_frame_unwind_memory(frame_info_ptr this_frame, CORE_ADDR addr, gdb::array_view< gdb_byte > buffer)
Definition frame.c:3017
@ SIGTRAMP_FRAME
Definition frame.h:198
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
void set_gdbarch_skip_trampoline_code(struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype *skip_trampoline_code)
void set_gdbarch_decr_pc_after_break(struct gdbarch *gdbarch, CORE_ADDR decr_pc_after_break)
Definition gdbarch.c:2913
void set_gdbarch_fetch_tls_load_module_address(struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address)
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype *skip_solib_resolver)
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype *iterate_over_regset_sections)
void iterate_over_regset_sections_cb(const char *sect_name, int supply_size, int collect_size, const struct regset *regset, const char *human_name, void *cb_data)
Definition gdbarch.h:104
CORE_ADDR glibc_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition glibc-tdep.c:38
link_map_offsets * linux_ilp32_fetch_link_map_offsets()
void linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch, int num_disp_step_buffers)
int linux_is_uclinux(void)
Definition linux-tdep.c:429
static struct trad_frame_cache * m68k_linux_sigtramp_frame_cache(frame_info_ptr this_frame, void **this_cache)
static const struct regcache_map_entry m68k_linux_fpregmap[]
static void m68k_linux_sigtramp_frame_this_id(frame_info_ptr this_frame, void **this_cache, struct frame_id *this_id)
static int m68k_linux_ucontext_reg_offset[M68K_NUM_REGS]
#define M68K_LINUX_FPREGS_SIZE
#define M68K_LINUX_GREGS_SIZE
static int m68k_linux_sigtramp_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_prologue_cache)
static int m68k_linux_pc_in_sigtramp(frame_info_ptr this_frame)
static int m68k_linux_sigcontext_reg_offset[M68K_NUM_REGS]
#define M68K_LINUX_JB_ELEMENT_SIZE
static void m68k_linux_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static void m68k_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
static const struct regset m68k_linux_fpregset
#define IS_SIGTRAMP(insn1, insn2)
static void m68k_linux_inferior_created(inferior *inf)
void _initialize_m68k_linux_tdep()
static int target_is_uclinux
static struct value * m68k_linux_sigtramp_frame_prev_register(frame_info_ptr this_frame, void **this_cache, int regnum)
static struct m68k_linux_sigtramp_info m68k_linux_get_sigtramp_info(frame_info_ptr this_frame)
static const struct frame_unwind m68k_linux_sigtramp_frame_unwind
static const struct regcache_map_entry m68k_linux_gregmap[]
#define IS_RT_SIGTRAMP(insn1, insn2)
static int m68k_uclinux_sigcontext_reg_offset[M68K_NUM_REGS]
static const struct regset m68k_linux_gregset
#define M68K_LINUX_JB_PC
void m68k_svr4_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition m68k-tdep.c:1102
@ M68K_PC_REGNUM
Definition m68k-tdep.h:41
@ M68K_FP0_REGNUM
Definition m68k-tdep.h:42
@ M68K_PS_REGNUM
Definition m68k-tdep.h:40
@ M68K_A0_REGNUM
Definition m68k-tdep.h:35
@ M68K_D0_REGNUM
Definition m68k-tdep.h:31
@ M68K_A1_REGNUM
Definition m68k-tdep.h:36
@ M68K_FPS_REGNUM
Definition m68k-tdep.h:44
@ M68K_FPI_REGNUM
Definition m68k-tdep.h:45
@ M68K_FPC_REGNUM
Definition m68k-tdep.h:43
@ M68K_D1_REGNUM
Definition m68k-tdep.h:32
@ M68K_SP_REGNUM
Definition m68k-tdep.h:39
#define M68K_NUM_REGS
Definition m68k-tdep.h:49
CORE_ADDR find_solib_trampoline_target(frame_info_ptr frame, CORE_ADDR pc)
Definition minsyms.c:1554
observable< inferior * > inferior_created
void gdbarch_register_osabi(enum bfd_architecture arch, unsigned long machine, enum gdb_osabi osabi, void(*init_osabi)(struct gdbarch_info, struct gdbarch *))
Definition osabi.c:146
@ GDB_OSABI_LINUX
Definition osabi.h:32
void regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition regcache.c:1273
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition regcache.c:1251
@ REGCACHE_MAP_SKIP
Definition regcache.h:121
void set_solib_svr4_fetch_link_map_offsets(struct gdbarch *gdbarch, struct link_map_offsets *(*flmo)(void))
CORE_ADDR svr4_fetch_objfile_link_map(struct objfile *objfile)
Definition gnu-nat.c:153
Definition regcache.h:111
struct frame_id this_id
Definition trad-frame.c:35
frame_info_ptr this_frame
Definition trad-frame.c:32
Definition value.h:130
struct trad_frame_cache * trad_frame_cache_zalloc(frame_info_ptr this_frame)
Definition trad-frame.c:39
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition trad-frame.c:110
void trad_frame_get_id(struct trad_frame_cache *this_trad_cache, struct frame_id *this_id)
Definition trad-frame.c:227
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition trad-frame.c:220
struct value * trad_frame_get_register(struct trad_frame_cache *this_trad_cache, frame_info_ptr this_frame, int regnum)
Definition trad-frame.c:211