GDB (API)
/home/stan/gdb/src/gdb/m68kbsd-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for Motorola 68000 BSD's.
00002 
00003    Copyright (C) 2004-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "arch-utils.h"
00022 #include "frame.h"
00023 #include "osabi.h"
00024 #include "regcache.h"
00025 #include "regset.h"
00026 #include "trad-frame.h"
00027 #include "tramp-frame.h"
00028 #include "gdbtypes.h"
00029 
00030 #include "gdb_assert.h"
00031 #include "gdb_string.h"
00032 
00033 #include "m68k-tdep.h"
00034 #include "solib-svr4.h"
00035 
00036 /* Core file support.  */
00037 
00038 /* Sizeof `struct reg' in <machine/reg.h>.  */
00039 #define M68KBSD_SIZEOF_GREGS    (18 * 4)
00040 
00041 /* Sizeof `struct fpreg' in <machine/reg.h.  */
00042 #define M68KBSD_SIZEOF_FPREGS   (((8 * 3) + 3) * 4)
00043 
00044 int
00045 m68kbsd_fpreg_offset (struct gdbarch *gdbarch, int regnum)
00046 {
00047   int fp_len = TYPE_LENGTH (gdbarch_register_type (gdbarch, regnum));
00048   
00049   if (regnum >= M68K_FPC_REGNUM)
00050     return 8 * fp_len + (regnum - M68K_FPC_REGNUM) * 4;
00051 
00052   return (regnum - M68K_FP0_REGNUM) * fp_len;
00053 }
00054 
00055 /* Supply register REGNUM from the buffer specified by FPREGS and LEN
00056    in the floating-point register set REGSET to register cache
00057    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
00058 
00059 static void
00060 m68kbsd_supply_fpregset (const struct regset *regset,
00061                          struct regcache *regcache,
00062                          int regnum, const void *fpregs, size_t len)
00063 {
00064   struct gdbarch *gdbarch = get_regcache_arch (regcache);
00065   const gdb_byte *regs = fpregs;
00066   int i;
00067 
00068   gdb_assert (len >= M68KBSD_SIZEOF_FPREGS);
00069 
00070   for (i = M68K_FP0_REGNUM; i <= M68K_PC_REGNUM; i++)
00071     {
00072       if (regnum == i || regnum == -1)
00073         regcache_raw_supply (regcache, i,
00074                              regs + m68kbsd_fpreg_offset (gdbarch, i));
00075     }
00076 }
00077 
00078 /* Supply register REGNUM from the buffer specified by GREGS and LEN
00079    in the general-purpose register set REGSET to register cache
00080    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
00081 
00082 static void
00083 m68kbsd_supply_gregset (const struct regset *regset,
00084                         struct regcache *regcache,
00085                         int regnum, const void *gregs, size_t len)
00086 {
00087   const gdb_byte *regs = gregs;
00088   int i;
00089 
00090   gdb_assert (len >= M68KBSD_SIZEOF_GREGS);
00091 
00092   for (i = M68K_D0_REGNUM; i <= M68K_PC_REGNUM; i++)
00093     {
00094       if (regnum == i || regnum == -1)
00095         regcache_raw_supply (regcache, i, regs + i * 4);
00096     }
00097 
00098   if (len >= M68KBSD_SIZEOF_GREGS + M68KBSD_SIZEOF_FPREGS)
00099     {
00100       regs += M68KBSD_SIZEOF_GREGS;
00101       len -= M68KBSD_SIZEOF_GREGS;
00102       m68kbsd_supply_fpregset (regset, regcache, regnum, regs, len);
00103     }
00104 }
00105 
00106 /* Motorola 68000 register sets.  */
00107 
00108 static struct regset m68kbsd_gregset =
00109 {
00110   NULL,
00111   m68kbsd_supply_gregset
00112 };
00113 
00114 static struct regset m68kbsd_fpregset =
00115 {
00116   NULL,
00117   m68kbsd_supply_fpregset
00118 };
00119 
00120 /* Return the appropriate register set for the core section identified
00121    by SECT_NAME and SECT_SIZE.  */
00122 
00123 static const struct regset *
00124 m68kbsd_regset_from_core_section (struct gdbarch *gdbarch,
00125                                   const char *sect_name, size_t sect_size)
00126 {
00127   if (strcmp (sect_name, ".reg") == 0 && sect_size >= M68KBSD_SIZEOF_GREGS)
00128     return &m68kbsd_gregset;
00129 
00130   if (strcmp (sect_name, ".reg2") == 0 && sect_size >= M68KBSD_SIZEOF_FPREGS)
00131     return &m68kbsd_fpregset;
00132 
00133   return NULL;
00134 }
00135 
00136 
00137 /* Signal trampolines.  */
00138 
00139 static void
00140 m68kobsd_sigtramp_cache_init (const struct tramp_frame *self,
00141                               struct frame_info *this_frame,
00142                               struct trad_frame_cache *this_cache,
00143                               CORE_ADDR func)
00144 {
00145   CORE_ADDR addr, base, pc;
00146   int regnum;
00147 
00148   base = get_frame_register_unsigned (this_frame, M68K_SP_REGNUM);
00149 
00150   /* The 'addql #4,%sp' instruction at offset 8 adjusts the stack
00151      pointer.  Adjust the frame base accordingly.  */
00152   pc = get_frame_register_unsigned (this_frame, M68K_PC_REGNUM);
00153   if ((pc - func) > 8)
00154     base -= 4;
00155 
00156   /* Get frame pointer, stack pointer, program counter and processor
00157      state from `struct sigcontext'.  */
00158   addr = get_frame_memory_unsigned (this_frame, base + 8, 4);
00159   trad_frame_set_reg_addr (this_cache, M68K_FP_REGNUM, addr + 8);
00160   trad_frame_set_reg_addr (this_cache, M68K_SP_REGNUM, addr + 12);
00161   trad_frame_set_reg_addr (this_cache, M68K_PC_REGNUM, addr + 20);
00162   trad_frame_set_reg_addr (this_cache, M68K_PS_REGNUM, addr + 24);
00163 
00164   /* The sc_ap member of `struct sigcontext' points to additional
00165      hardware state.  Here we find the missing registers.  */
00166   addr = get_frame_memory_unsigned (this_frame, addr + 16, 4) + 4;
00167   for (regnum = M68K_D0_REGNUM; regnum < M68K_FP_REGNUM; regnum++, addr += 4)
00168     trad_frame_set_reg_addr (this_cache, regnum, addr);
00169 
00170   /* Construct the frame ID using the function start.  */
00171   trad_frame_set_id (this_cache, frame_id_build (base, func));
00172 }
00173 
00174 static const struct tramp_frame m68kobsd_sigtramp = {
00175   SIGTRAMP_FRAME,
00176   2,
00177   {
00178     { 0x206f, -1 }, { 0x000c, -1},      /* moveal %sp@(12),%a0 */
00179     { 0x4e90, -1 },                     /* jsr %a0@ */
00180     { 0x588f, -1 },                     /* addql #4,%sp */
00181     { 0x4e41, -1 },                     /* trap #1 */
00182     { 0x2f40, -1 }, { 0x0004, -1 },     /* moveal %d0,%sp@(4) */
00183     { 0x7001, -1 },                     /* moveq #SYS_exit,%d0 */
00184     { 0x4e40, -1 },                     /* trap #0 */
00185     { TRAMP_SENTINEL_INSN, -1 }
00186   },
00187   m68kobsd_sigtramp_cache_init
00188 };
00189 
00190 
00191 static void
00192 m68kbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00193 {
00194   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00195 
00196   tdep->jb_pc = 5;
00197   tdep->jb_elt_size = 4;
00198 
00199   set_gdbarch_decr_pc_after_break (gdbarch, 2);
00200 
00201   set_gdbarch_regset_from_core_section
00202     (gdbarch, m68kbsd_regset_from_core_section);
00203 }
00204 
00205 /* OpenBSD and NetBSD a.out.  */
00206 
00207 static void
00208 m68kbsd_aout_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00209 {
00210   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00211 
00212   m68kbsd_init_abi (info, gdbarch);
00213 
00214   tdep->struct_return = reg_struct_return;
00215 
00216   tramp_frame_prepend_unwinder (gdbarch, &m68kobsd_sigtramp);
00217 }
00218 
00219 /* NetBSD ELF.  */
00220 
00221 static void
00222 m68kbsd_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00223 {
00224   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00225 
00226   m68kbsd_init_abi (info, gdbarch);
00227 
00228   /* NetBSD ELF uses the SVR4 ABI.  */
00229   m68k_svr4_init_abi (info, gdbarch);
00230   tdep->struct_return = pcc_struct_return;
00231 
00232   /* NetBSD ELF uses SVR4-style shared libraries.  */
00233   set_solib_svr4_fetch_link_map_offsets
00234     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
00235 }
00236 
00237 
00238 static enum gdb_osabi
00239 m68kbsd_aout_osabi_sniffer (bfd *abfd)
00240 {
00241   if (strcmp (bfd_get_target (abfd), "a.out-m68k-netbsd") == 0
00242       || strcmp (bfd_get_target (abfd), "a.out-m68k4k-netbsd") == 0)
00243     return GDB_OSABI_NETBSD_AOUT;
00244 
00245   return GDB_OSABI_UNKNOWN;
00246 }
00247 
00248 static enum gdb_osabi
00249 m68kbsd_core_osabi_sniffer (bfd *abfd)
00250 {
00251   if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
00252     return GDB_OSABI_NETBSD_AOUT;
00253 
00254   return GDB_OSABI_UNKNOWN;
00255 }
00256 
00257 
00258 /* Provide a prototype to silence -Wmissing-prototypes.  */
00259 void _initialize_m68kbsd_tdep (void);
00260 
00261 void
00262 _initialize_m68kbsd_tdep (void)
00263 {
00264   gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_aout_flavour,
00265                                   m68kbsd_aout_osabi_sniffer);
00266 
00267   /* BFD doesn't set a flavour for NetBSD style a.out core files.  */
00268   gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_unknown_flavour,
00269                                   m68kbsd_core_osabi_sniffer);
00270 
00271   gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_AOUT,
00272                           m68kbsd_aout_init_abi);
00273   gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_NETBSD_ELF,
00274                           m68kbsd_elf_init_abi);
00275 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines