GDB (API)
/home/stan/gdb/src/gdb/hppanbsd-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for NetBSD/hppa
00002 
00003    Copyright (C) 2008-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 "osabi.h"
00022 #include "regcache.h"
00023 #include "regset.h"
00024 
00025 #include "trad-frame.h"
00026 #include "tramp-frame.h"
00027 
00028 #include "gdb_assert.h"
00029 #include "gdb_string.h"
00030 
00031 #include "hppa-tdep.h"
00032 #include "hppabsd-tdep.h"
00033 
00034 /* From <machine/mcontext.h>.  */
00035 static int hppanbsd_mc_reg_offset[] =
00036 {
00037   /* r0 ... r31 */
00038       -1,   1 * 4,   2 * 4,   3 * 4,
00039    4 * 4,   5 * 4,   6 * 4,   7 * 4,
00040    8 * 4,   9 * 4,  10 * 4,  11 * 4, 
00041   12 * 4,  13 * 4,  14 * 4,  15 * 4,
00042   16 * 4,  17 * 4,  18 * 4,  19 * 4,
00043   20 * 4,  21 * 4,  22 * 4,  23 * 4,
00044   24 * 4,  25 * 4,  26 * 4,  27 * 4,
00045   28 * 4,  29 * 4,  30 * 4,  31 * 4,
00046 
00047   32 * 4,       /* HPPA_SAR_REGNUM */
00048   35 * 4,       /* HPPA_PCOQ_HEAD_REGNUM */
00049   33 * 4,       /* HPPA_PCSQ_HEAD_REGNUM */
00050   36 * 4,       /* HPPA_PCOQ_TAIL_REGNUM */
00051   34 * 4,       /* HPPA_PCSQ_TAIL_REGNUM */
00052   -1,           /* HPPA_EIEM_REGNUM */
00053   -1,           /* HPPA_IIR_REGNUM */
00054   -1,           /* HPPA_ISR_REGNUM */
00055   -1,           /* HPPA_IOR_REGNUM */
00056   0 * 4,        /* HPPA_IPSW_REGNUM */
00057   -1,           /* spare? */
00058   41 * 4,       /* HPPA_SR4_REGNUM */
00059   37 * 4,       /* sr0 */
00060   38 * 4,       /* sr1 */
00061   39 * 4,       /* sr2 */
00062   40 * 4,       /* sr3 */
00063 
00064   /* more tbd */
00065 };
00066 
00067 static void hppanbsd_sigtramp_cache_init (const struct tramp_frame *,
00068                                          struct frame_info *,
00069                                          struct trad_frame_cache *,
00070                                          CORE_ADDR);
00071 
00072 static const struct tramp_frame hppanbsd_sigtramp_si4 =
00073 {
00074   SIGTRAMP_FRAME,
00075   4,
00076   {
00077     { 0xc7d7c012, -1 }, /*      bb,>=,n %arg3, 30, 1f           */
00078     { 0xd6e01c1e, -1 }, /*       depwi 0,31,2,%arg3             */
00079     { 0x0ee81093, -1 }, /*      ldw 4(%arg3), %r19              */
00080     { 0x0ee01097, -1 }, /*      ldw 0(%arg3), %arg3             */
00081                         /* 1:                                   */
00082     { 0xe8404000, -1 }, /*      blr %r0, %rp                    */
00083     { 0xeae0c002, -1 }, /*      bv,n %r0(%arg3)                 */
00084     { 0x08000240, -1 }, /*       nop                            */
00085 
00086     { 0x0803025a, -1 }, /*      copy %r3, %arg0                 */
00087     { 0x20200801, -1 }, /*      ldil -40000000, %r1             */
00088     { 0xe420e008, -1 }, /*      be,l 4(%sr7, %r1), %sr0, %r31   */
00089     { 0x34160268, -1 }, /*       ldi 134, %t1 ; SYS_setcontext  */
00090 
00091     { 0x081c025a, -1 }, /*      copy ret0, %arg0                */
00092     { 0x20200801, -1 }, /*      ldil -40000000, %r1             */
00093     { 0xe420e008, -1 }, /*      be,l 4(%sr7, %r1), %sr0, %r31   */
00094     { 0x34160002, -1 }, /*       ldi 1, %t1 ; SYS_exit          */
00095     { TRAMP_SENTINEL_INSN, -1 }
00096   },
00097   hppanbsd_sigtramp_cache_init
00098 };
00099 
00100 
00101 static void
00102 hppanbsd_sigtramp_cache_init (const struct tramp_frame *self,
00103                              struct frame_info *this_frame,
00104                              struct trad_frame_cache *this_cache,
00105                              CORE_ADDR func)
00106 {
00107   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00108   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00109   CORE_ADDR sp = get_frame_register_unsigned (this_frame, HPPA_SP_REGNUM);
00110   CORE_ADDR base;
00111   int *reg_offset;
00112   int num_regs;
00113   int i;
00114 
00115   reg_offset = hppanbsd_mc_reg_offset;
00116   num_regs = ARRAY_SIZE (hppanbsd_mc_reg_offset);
00117 
00118   /* frame pointer */
00119   base = sp - 0x280;
00120   /* offsetof(struct sigframe_siginfo, sf_uc) = 128 */
00121   base += 128;
00122   /* offsetof(ucontext_t, uc_mcontext) == 40 */
00123   base += 40;
00124 
00125   for (i = 0; i < num_regs; i++)
00126     if (reg_offset[i] != -1)
00127       trad_frame_set_reg_addr (this_cache, i, base + reg_offset[i]);
00128 
00129   /* Construct the frame ID using the function start.  */
00130   trad_frame_set_id (this_cache, frame_id_build (sp, func));
00131 }
00132 
00133 /* Core file support.  */
00134 
00135 /* Sizeof `struct reg' in <machine/reg.h>.  */
00136 #define HPPANBSD_SIZEOF_GREGS   (44 * 4)
00137 
00138 static int hppanbsd_reg_offset[] =
00139 {
00140   /* r0 ... r31 */
00141       -1,   1 * 4,   2 * 4,   3 * 4,
00142    4 * 4,   5 * 4,   6 * 4,   7 * 4,
00143    8 * 4,   9 * 4,  10 * 4,  11 * 4, 
00144   12 * 4,  13 * 4,  14 * 4,  15 * 4,
00145   16 * 4,  17 * 4,  18 * 4,  19 * 4,
00146   20 * 4,  21 * 4,  22 * 4,  23 * 4,
00147   24 * 4,  25 * 4,  26 * 4,  27 * 4,
00148   28 * 4,  29 * 4,  30 * 4,  31 * 4,
00149 
00150   32 * 4,       /* HPPA_SAR_REGNUM */
00151   35 * 4,       /* HPPA_PCOQ_HEAD_REGNUM */
00152   33 * 4,       /* HPPA_PCSQ_HEAD_REGNUM */
00153   36 * 4,       /* HPPA_PCOQ_TAIL_REGNUM */
00154   34 * 4,       /* HPPA_PCSQ_TAIL_REGNUM */
00155   -1,           /* HPPA_EIEM_REGNUM */
00156   -1,           /* HPPA_IIR_REGNUM */
00157   -1,           /* HPPA_ISR_REGNUM */
00158   -1,           /* HPPA_IOR_REGNUM */
00159   0 * 4,        /* HPPA_IPSW_REGNUM */
00160 };
00161 
00162 /* Supply register REGNUM from the buffer specified by GREGS and LEN
00163    in the general-purpose register set REGSET to register cache
00164    REGCACHE.  If REGNUM is -1, do this for all registers in REGSET.  */
00165 
00166 static void
00167 hppanbsd_supply_gregset (const struct regset *regset,
00168                          struct regcache *regcache,
00169                          int regnum, const void *gregs, size_t len)
00170 {
00171   const gdb_byte *regs = gregs;
00172   int i;
00173 
00174   gdb_assert (len >= HPPANBSD_SIZEOF_GREGS);
00175 
00176   for (i = 0; i < ARRAY_SIZE (hppanbsd_reg_offset); i++)
00177     if (hppanbsd_reg_offset[i] != -1)
00178       if (regnum == -1 || regnum == i)
00179         regcache_raw_supply (regcache, i, regs + hppanbsd_reg_offset[i]);
00180 }
00181 
00182 /* NetBSD/hppa register set.  */
00183 
00184 static struct regset hppanbsd_gregset =
00185 {
00186   NULL,
00187   hppanbsd_supply_gregset
00188 };
00189 
00190 /* Return the appropriate register set for the core section identified
00191    by SECT_NAME and SECT_SIZE.  */
00192 
00193 static const struct regset *
00194 hppanbsd_regset_from_core_section (struct gdbarch *gdbarch,
00195                                   const char *sect_name, size_t sect_size)
00196 {
00197   if (strcmp (sect_name, ".reg") == 0 && sect_size >= HPPANBSD_SIZEOF_GREGS)
00198     return &hppanbsd_gregset;
00199 
00200   return NULL;
00201 }
00202 
00203 static void
00204 hppanbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00205 {
00206   /* Obviously NetBSD is BSD-based.  */
00207   hppabsd_init_abi (info, gdbarch);
00208 
00209   /* Core file support.  */
00210   set_gdbarch_regset_from_core_section
00211     (gdbarch, hppanbsd_regset_from_core_section);
00212 
00213   tramp_frame_prepend_unwinder (gdbarch, &hppanbsd_sigtramp_si4);
00214 }
00215 
00216 
00217 /* Provide a prototype to silence -Wmissing-prototypes.  */
00218 extern initialize_file_ftype _initialize_hppanbsd_tdep;
00219 
00220 void
00221 _initialize_hppanbsd_tdep (void)
00222 {
00223   gdbarch_register_osabi (bfd_arch_hppa, 0, GDB_OSABI_NETBSD_ELF,
00224                           hppanbsd_init_abi);
00225 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines