1999-04-16 09:35:26 +08:00
|
|
|
|
/* Motorola m68k native support for Linux
|
2001-03-06 16:22:02 +08:00
|
|
|
|
Copyright 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
This file is part of GDB.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
Boston, MA 02111-1307, USA. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
#include "frame.h"
|
|
|
|
|
#include "inferior.h"
|
|
|
|
|
#include "language.h"
|
|
|
|
|
#include "gdbcore.h"
|
2001-03-01 09:39:22 +08:00
|
|
|
|
#include "regcache.h"
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
#ifdef USG
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/dir.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <sys/user.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/procfs.h>
|
|
|
|
|
|
|
|
|
|
#include <sys/file.h>
|
|
|
|
|
#include "gdb_stat.h"
|
|
|
|
|
|
|
|
|
|
#include "floatformat.h"
|
|
|
|
|
|
|
|
|
|
#include "target.h"
|
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
/* This table must line up with REGISTER_NAMES in tm-m68k.h */
|
1999-07-08 04:19:36 +08:00
|
|
|
|
static const int regmap[] =
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
PT_D0, PT_D1, PT_D2, PT_D3, PT_D4, PT_D5, PT_D6, PT_D7,
|
|
|
|
|
PT_A0, PT_A1, PT_A2, PT_A3, PT_A4, PT_A5, PT_A6, PT_USP,
|
|
|
|
|
PT_SR, PT_PC,
|
|
|
|
|
/* PT_FP0, ..., PT_FP7 */
|
|
|
|
|
21, 24, 27, 30, 33, 36, 39, 42,
|
|
|
|
|
/* PT_FPCR, PT_FPSR, PT_FPIAR */
|
|
|
|
|
45, 46, 47
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* BLOCKEND is the value of u.u_ar0, and points to the place where GS
|
|
|
|
|
is stored. */
|
|
|
|
|
|
|
|
|
|
int
|
2000-07-30 09:48:28 +08:00
|
|
|
|
m68k_linux_register_u_addr (int blockend, int regnum)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
1999-07-08 04:19:36 +08:00
|
|
|
|
return (blockend + 4 * regmap[regnum]);
|
1999-04-16 09:35:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 02:39:12 +08:00
|
|
|
|
/* Given a pointer to a general register set in /proc format
|
|
|
|
|
(elf_gregset_t *), unpack the register contents and supply
|
|
|
|
|
them as gdb's idea of the current register values. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Note both m68k-tdep.c and m68klinux-nat.c contain definitions
|
|
|
|
|
for supply_gregset and supply_fpregset. The definitions
|
|
|
|
|
in m68k-tdep.c are valid if USE_PROC_FS is defined. Otherwise,
|
|
|
|
|
the definitions in m68klinux-nat.c will be used. This is a
|
|
|
|
|
bit of a hack. The supply_* routines do not belong in
|
|
|
|
|
*_tdep.c files. But, there are several lynx ports that currently
|
1999-07-08 04:19:36 +08:00
|
|
|
|
depend on these definitions. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
|
|
|
|
#ifndef USE_PROC_FS
|
|
|
|
|
|
2000-05-26 Michael Snyder <msnyder@seadog.cygnus.com>
* gregset.h: New file. Typedefs for gdb_gregset_t and
gdb_fpregset_t, prototypes for supply_gregset and friends.
* procfs.c: Include gregset.h. Delete local prototypes for
supply_gregset etc., and local typedef gdb_gregset_t etc.
* sol-thread.c: Include gregset.h, delete local prototypes,
add appropriate casts to gdb_gregset_t.
* uw-thread.c, lin-thread.c, core-sol2.c, core-regset.c,
sparc-tdep.c, ptx4-nat.c, ppc-linux-nat.c, mipsv4-nat.c,
m88k-nat.c, m68klinux-nat.c, m68k-tdep.c, irix5-nat.c,
irix4-nat.c, ia64-linux-nat.c, i386v4-nat.c, cxux-nat.c,
arm-linux-nat.c, alpha-nat.c: Include gregset.h.
* config/nm-linux.h: Define GDB_GREGSET_T, GDB_FPREGET_T.
* config/sparc/tm-sun4sol2.h: Ditto.
2000-05-27 07:22:41 +08:00
|
|
|
|
/* Prototypes for supply_gregset etc. */
|
|
|
|
|
#include "gregset.h"
|
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
void
|
2001-07-12 02:39:12 +08:00
|
|
|
|
supply_gregset (elf_gregset_t *gregsetp)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
int regi;
|
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
for (regi = D0_REGNUM; regi <= SP_REGNUM; regi++)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
supply_register (regi, (char *) (*gregsetp + regmap[regi]));
|
|
|
|
|
supply_register (PS_REGNUM, (char *) (*gregsetp + PT_SR));
|
|
|
|
|
supply_register (PC_REGNUM, (char *) (*gregsetp + PT_PC));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Given a pointer to a floating point register set in /proc format
|
1999-07-08 04:19:36 +08:00
|
|
|
|
(fpregset_t *), unpack the register contents and supply them as gdb's
|
|
|
|
|
idea of the current floating point register values. */
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
void
|
2001-07-12 02:39:12 +08:00
|
|
|
|
supply_fpregset (elf_fpregset_t *fpregsetp)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
int regi;
|
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
for (regi = FP0_REGNUM; regi < FPC_REGNUM; regi++)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
supply_register (regi, (char *) &fpregsetp->fpregs[(regi - FP0_REGNUM) * 3]);
|
|
|
|
|
supply_register (FPC_REGNUM, (char *) &fpregsetp->fpcntl[0]);
|
|
|
|
|
supply_register (FPS_REGNUM, (char *) &fpregsetp->fpcntl[1]);
|
|
|
|
|
supply_register (FPI_REGNUM, (char *) &fpregsetp->fpcntl[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
2001-07-12 02:39:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Interpreting register set info found in core files. */
|
|
|
|
|
|
|
|
|
|
/* Provide registers to GDB from a core file.
|
|
|
|
|
|
|
|
|
|
(We can't use the generic version of this function in
|
|
|
|
|
core-regset.c, because we need to use elf_gregset_t instead of
|
|
|
|
|
gregset_t.)
|
|
|
|
|
|
|
|
|
|
CORE_REG_SECT points to an array of bytes, which are the contents
|
|
|
|
|
of a `note' from a core file which BFD thinks might contain
|
|
|
|
|
register contents. CORE_REG_SIZE is its size.
|
|
|
|
|
|
|
|
|
|
WHICH says which register set corelow suspects this is:
|
|
|
|
|
0 --- the general-purpose register set, in elf_gregset_t format
|
|
|
|
|
2 --- the floating-point register set, in elf_fpregset_t format
|
|
|
|
|
|
|
|
|
|
REG_ADDR isn't used on Linux. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
|
|
|
|
|
int which, CORE_ADDR reg_addr)
|
|
|
|
|
{
|
|
|
|
|
elf_gregset_t gregset;
|
|
|
|
|
elf_fpregset_t fpregset;
|
|
|
|
|
|
|
|
|
|
switch (which)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
if (core_reg_size != sizeof (gregset))
|
|
|
|
|
warning ("Wrong size gregset in core file.");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memcpy (&gregset, core_reg_sect, sizeof (gregset));
|
|
|
|
|
supply_gregset (&gregset);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
if (core_reg_size != sizeof (fpregset))
|
|
|
|
|
warning ("Wrong size fpregset in core file.");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
|
|
|
|
|
supply_fpregset (&fpregset);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* We've covered all the kinds of registers we know about here,
|
|
|
|
|
so this must be something we wouldn't know what to do with
|
|
|
|
|
anyway. Just ignore it. */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-04-16 09:35:26 +08:00
|
|
|
|
|
1999-07-08 04:19:36 +08:00
|
|
|
|
|
1999-04-16 09:35:26 +08:00
|
|
|
|
int
|
2000-07-30 09:48:28 +08:00
|
|
|
|
kernel_u_size (void)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
return (sizeof (struct user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return non-zero if PC points into the signal trampoline. */
|
|
|
|
|
|
|
|
|
|
int
|
2000-07-30 09:48:28 +08:00
|
|
|
|
in_sigtramp (CORE_ADDR pc)
|
1999-04-16 09:35:26 +08:00
|
|
|
|
{
|
|
|
|
|
CORE_ADDR sp;
|
|
|
|
|
char buf[TARGET_SHORT_BIT / TARGET_CHAR_BIT];
|
|
|
|
|
int insn;
|
|
|
|
|
|
|
|
|
|
sp = read_register (SP_REGNUM);
|
|
|
|
|
if (pc - 2 < sp)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (read_memory_nobpt (pc, buf, sizeof (buf)))
|
|
|
|
|
return 0;
|
|
|
|
|
insn = extract_unsigned_integer (buf, sizeof (buf));
|
1999-07-08 04:19:36 +08:00
|
|
|
|
if (insn == 0xdefc /* addaw #,sp */
|
|
|
|
|
|| insn == 0x7077 /* moveq #119,d0 */
|
|
|
|
|
|| insn == 0x4e40 /* trap #0 */
|
|
|
|
|
|| insn == 0x203c /* movel #,d0 */ )
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (read_memory_nobpt (pc - 2, buf, sizeof (buf)))
|
|
|
|
|
return 0;
|
|
|
|
|
insn = extract_unsigned_integer (buf, sizeof (buf));
|
1999-07-08 04:19:36 +08:00
|
|
|
|
if (insn == 0xdefc /* addaw #,sp */
|
|
|
|
|
|| insn == 0x7077 /* moveq #119,d0 */
|
|
|
|
|
|| insn == 0x4e40 /* trap #0 */
|
|
|
|
|
|| insn == 0x203c /* movel #,d0 */ )
|
1999-04-16 09:35:26 +08:00
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-12 02:39:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Register that we are able to handle Linux ELF core file formats. */
|
|
|
|
|
|
|
|
|
|
static struct core_fns linux_elf_core_fns =
|
|
|
|
|
{
|
|
|
|
|
bfd_target_elf_flavour, /* core_flavour */
|
|
|
|
|
default_check_format, /* check_format */
|
|
|
|
|
default_core_sniffer, /* core_sniffer */
|
|
|
|
|
fetch_core_registers, /* core_read_registers */
|
|
|
|
|
NULL /* next */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_initialize_m68k_linux_nat ()
|
|
|
|
|
{
|
|
|
|
|
add_core_fns (&linux_elf_core_fns);
|
|
|
|
|
}
|