#include "defs.h"
#include "gdbcore.h"
#include "doublest.h"
#include "floatformat.h"
#include "frame.h"
#include "target.h"
#include "gdb_string.h"
#include "gdbtypes.h"
#include "osabi.h"
#include "regcache.h"
#include "objfiles.h"
#include "symtab.h"
#include "m68k-tdep.h"
#include "trad-frame.h"
#include "frame-unwind.h"
#include "glibc-tdep.h"
#include "solib-svr4.h"
#define M68K_LINUX_JB_ELEMENT_SIZE 4
#define M68K_LINUX_JB_PC 7
#define IS_SIGTRAMP(insn1, insn2) \
( \
(insn1 == 0xdefc0014 && insn2 == 0x70774e40) \
\
|| insn1 == 0x70774e40)
#define IS_RT_SIGTRAMP(insn1, insn2) \
( \
(insn1 == 0x203c0000 && insn2 == 0x00ad4e40) \
\
|| (insn1 == 0x70524600 && (insn2 >> 16) == 0x4e40))
static int
m68k_linux_pc_in_sigtramp (CORE_ADDR pc, char *name)
{
CORE_ADDR sp;
char buf[12];
unsigned long insn0, insn1, insn2;
if (deprecated_read_memory_nobpt (pc - 4, buf, sizeof (buf)))
return 0;
insn1 = extract_unsigned_integer (buf + 4, 4);
insn2 = extract_unsigned_integer (buf + 8, 4);
if (IS_SIGTRAMP (insn1, insn2))
return 1;
if (IS_RT_SIGTRAMP (insn1, insn2))
return 2;
insn0 = extract_unsigned_integer (buf, 4);
if (IS_SIGTRAMP (insn0, insn1))
return 1;
if (IS_RT_SIGTRAMP (insn0, insn1))
return 2;
insn0 = ((insn0 << 16) & 0xffffffff) | (insn1 >> 16);
insn1 = ((insn1 << 16) & 0xffffffff) | (insn2 >> 16);
if (IS_SIGTRAMP (insn0, insn1))
return 1;
if (IS_RT_SIGTRAMP (insn0, insn1))
return 2;
return 0;
}
static int m68k_linux_sigcontext_reg_offset[M68K_NUM_REGS] =
{
2 * 4,
3 * 4,
-1,
-1,
-1,
-1,
-1,
-1,
4 * 4,
5 * 4,
-1,
-1,
-1,
-1,
-1,
1 * 4,
5 * 4 + 2,
6 * 4 + 2,
8 * 4,
11 * 4,
-1,
-1,
-1,
-1,
-1,
-1,
14 * 4,
15 * 4,
16 * 4
};
static int m68k_linux_ucontext_reg_offset[M68K_NUM_REGS] =
{
6 * 4,
7 * 4,
8 * 4,
9 * 4,
10 * 4,
11 * 4,
12 * 4,
13 * 4,
14 * 4,
15 * 4,
16 * 4,
17 * 4,
18 * 4,
19 * 4,
20 * 4,
21 * 4,
23 * 4,
22 * 4,
27 * 4,
30 * 4,
33 * 4,
36 * 4,
39 * 4,
42 * 4,
45 * 4,
48 * 4,
24 * 4,
25 * 4,
26 * 4
};
struct m68k_linux_sigtramp_info
{
CORE_ADDR sigcontext_addr;
int *sc_reg_offset;
};
static struct m68k_linux_sigtramp_info
m68k_linux_get_sigtramp_info (struct frame_info *next_frame)
{
CORE_ADDR sp;
char buf[4];
struct m68k_linux_sigtramp_info info;
frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
sp = extract_unsigned_integer (buf, 4);
info.sigcontext_addr = read_memory_unsigned_integer (sp + 8, 4);
if (m68k_linux_pc_in_sigtramp (frame_pc_unwind (next_frame), 0) == 2)
info.sc_reg_offset = m68k_linux_ucontext_reg_offset;
else
info.sc_reg_offset = m68k_linux_sigcontext_reg_offset;
return info;
}
static struct trad_frame_cache *
m68k_linux_sigtramp_frame_cache (struct frame_info *next_frame,
void **this_cache)
{
struct frame_id this_id;
struct trad_frame_cache *cache;
struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
struct m68k_linux_sigtramp_info info;
char buf[4];
int i;
if (*this_cache)
return *this_cache;
cache = trad_frame_cache_zalloc (next_frame);
frame_unwind_register (next_frame, M68K_SP_REGNUM, buf);
this_id = frame_id_build (extract_unsigned_integer (buf, 4) - 4 + 8,
frame_pc_unwind (next_frame));
trad_frame_set_id (cache, this_id);
info = m68k_linux_get_sigtramp_info (next_frame);
for (i = 0; i < M68K_NUM_REGS; i++)
if (info.sc_reg_offset[i] != -1)
trad_frame_set_reg_addr (cache, i,
info.sigcontext_addr + info.sc_reg_offset[i]);
*this_cache = cache;
return cache;
}
static void
m68k_linux_sigtramp_frame_this_id (struct frame_info *next_frame,
void **this_cache,
struct frame_id *this_id)
{
struct trad_frame_cache *cache =
m68k_linux_sigtramp_frame_cache (next_frame, this_cache);
trad_frame_get_id (cache, this_id);
}
static void
m68k_linux_sigtramp_frame_prev_register (struct frame_info *next_frame,
void **this_cache,
int regnum, enum opt_state *optimizedp,
enum lval_type *lvalp,
CORE_ADDR *addrp,
int *realnump, void *valuep)
{
struct trad_frame_cache *cache =
m68k_linux_sigtramp_frame_cache (next_frame, this_cache);
trad_frame_get_register (cache, next_frame, regnum, optimizedp, lvalp,
addrp, realnump, valuep);
}
static const struct frame_unwind m68k_linux_sigtramp_frame_unwind =
{
SIGTRAMP_FRAME,
m68k_linux_sigtramp_frame_this_id,
m68k_linux_sigtramp_frame_prev_register
};
static const struct frame_unwind *
m68k_linux_sigtramp_frame_sniffer (struct frame_info *next_frame)
{
CORE_ADDR pc = frame_pc_unwind (next_frame);
char *name;
find_pc_partial_function (pc, &name, NULL, NULL);
if (m68k_linux_pc_in_sigtramp (pc, name))
return &m68k_linux_sigtramp_frame_unwind;
return NULL;
}
static void
m68k_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
tdep->jb_pc = M68K_LINUX_JB_PC;
tdep->jb_elt_size = M68K_LINUX_JB_ELEMENT_SIZE;
m68k_svr4_init_abi (info, gdbarch);
tdep->struct_value_regnum = M68K_A1_REGNUM;
tdep->struct_return = reg_struct_return;
frame_unwind_append_sniffer (gdbarch, m68k_linux_sigtramp_frame_sniffer);
set_solib_svr4_fetch_link_map_offsets (gdbarch,
svr4_ilp32_fetch_link_map_offsets);
set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
}
void
_initialize_m68k_linux_tdep (void)
{
gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_LINUX,
m68k_linux_init_abi);
}