| 1 | /* Target-dependent code for FreeBSD/sparc64. |
| 2 | |
| 3 | Copyright (C) 2003, 2004, 2005, 2007 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 2 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, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | Boston, MA 02110-1301, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "frame.h" |
| 24 | #include "frame-unwind.h" |
| 25 | #include "gdbcore.h" |
| 26 | #include "osabi.h" |
| 27 | #include "regcache.h" |
| 28 | #include "regset.h" |
| 29 | #include "target.h" |
| 30 | #include "trad-frame.h" |
| 31 | |
| 32 | #include "gdb_assert.h" |
| 33 | #include "gdb_string.h" |
| 34 | |
| 35 | #include "sparc64-tdep.h" |
| 36 | #include "solib-svr4.h" |
| 37 | |
| 38 | /* From <machine/reg.h>. */ |
| 39 | const struct sparc_gregset sparc64fbsd_gregset = |
| 40 | { |
| 41 | 26 * 8, /* "tstate" */ |
| 42 | 25 * 8, /* %pc */ |
| 43 | 24 * 8, /* %npc */ |
| 44 | 28 * 8, /* %y */ |
| 45 | 16 * 8, /* %fprs */ |
| 46 | -1, |
| 47 | 1 * 8, /* %g1 */ |
| 48 | -1, /* %l0 */ |
| 49 | 8 /* sizeof (%y) */ |
| 50 | }; |
| 51 | \f |
| 52 | |
| 53 | static void |
| 54 | sparc64fbsd_supply_gregset (const struct regset *regset, |
| 55 | struct regcache *regcache, |
| 56 | int regnum, const void *gregs, size_t len) |
| 57 | { |
| 58 | sparc64_supply_gregset (&sparc64fbsd_gregset, regcache, regnum, gregs); |
| 59 | } |
| 60 | |
| 61 | static void |
| 62 | sparc64fbsd_collect_gregset (const struct regset *regset, |
| 63 | const struct regcache *regcache, |
| 64 | int regnum, void *gregs, size_t len) |
| 65 | { |
| 66 | sparc64_collect_gregset (&sparc64fbsd_gregset, regcache, regnum, gregs); |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | sparc64fbsd_supply_fpregset (const struct regset *regset, |
| 71 | struct regcache *regcache, |
| 72 | int regnum, const void *fpregs, size_t len) |
| 73 | { |
| 74 | sparc64_supply_fpregset (regcache, regnum, fpregs); |
| 75 | } |
| 76 | |
| 77 | static void |
| 78 | sparc64fbsd_collect_fpregset (const struct regset *regset, |
| 79 | const struct regcache *regcache, |
| 80 | int regnum, void *fpregs, size_t len) |
| 81 | { |
| 82 | sparc64_collect_fpregset (regcache, regnum, fpregs); |
| 83 | } |
| 84 | \f |
| 85 | |
| 86 | /* Signal trampolines. */ |
| 87 | |
| 88 | static int |
| 89 | sparc64fbsd_pc_in_sigtramp (CORE_ADDR pc, char *name) |
| 90 | { |
| 91 | return (name && strcmp (name, "__sigtramp") == 0); |
| 92 | } |
| 93 | |
| 94 | static struct sparc_frame_cache * |
| 95 | sparc64fbsd_sigtramp_frame_cache (struct frame_info *next_frame, |
| 96 | void **this_cache) |
| 97 | { |
| 98 | struct sparc_frame_cache *cache; |
| 99 | CORE_ADDR addr, mcontext_addr, sp; |
| 100 | LONGEST fprs; |
| 101 | int regnum; |
| 102 | |
| 103 | if (*this_cache) |
| 104 | return *this_cache; |
| 105 | |
| 106 | cache = sparc_frame_cache (next_frame, this_cache); |
| 107 | gdb_assert (cache == *this_cache); |
| 108 | |
| 109 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); |
| 110 | |
| 111 | /* The third argument is a pointer to an instance of `ucontext_t', |
| 112 | which has a member `uc_mcontext' that contains the saved |
| 113 | registers. */ |
| 114 | addr = frame_unwind_register_unsigned (next_frame, SPARC_O2_REGNUM); |
| 115 | mcontext_addr = addr + 64; |
| 116 | |
| 117 | /* The following registers travel in the `mc_local' slots of |
| 118 | `mcontext_t'. */ |
| 119 | addr = mcontext_addr + 16 * 8; |
| 120 | cache->saved_regs[SPARC64_FPRS_REGNUM].addr = addr + 0 * 8; |
| 121 | cache->saved_regs[SPARC64_FSR_REGNUM].addr = addr + 1 * 8; |
| 122 | |
| 123 | /* The following registers travel in the `mc_in' slots of |
| 124 | `mcontext_t'. */ |
| 125 | addr = mcontext_addr + 24 * 8; |
| 126 | cache->saved_regs[SPARC64_NPC_REGNUM].addr = addr + 0 * 8; |
| 127 | cache->saved_regs[SPARC64_PC_REGNUM].addr = addr + 1 * 8; |
| 128 | cache->saved_regs[SPARC64_STATE_REGNUM].addr = addr + 2 * 8; |
| 129 | cache->saved_regs[SPARC64_Y_REGNUM].addr = addr + 4 * 8; |
| 130 | |
| 131 | /* The `global' and `out' registers travel in the `mc_global' and |
| 132 | `mc_out' slots of `mcontext_t', except for %g0. Since %g0 is |
| 133 | always zero, keep the identity encoding. */ |
| 134 | for (regnum = SPARC_G1_REGNUM, addr = mcontext_addr + 8; |
| 135 | regnum <= SPARC_O7_REGNUM; regnum++, addr += 8) |
| 136 | cache->saved_regs[regnum].addr = addr; |
| 137 | |
| 138 | /* The `local' and `in' registers have been saved in the register |
| 139 | save area. */ |
| 140 | addr = cache->saved_regs[SPARC_SP_REGNUM].addr; |
| 141 | sp = get_frame_memory_unsigned (next_frame, addr, 8); |
| 142 | for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS; |
| 143 | regnum <= SPARC_I7_REGNUM; regnum++, addr += 8) |
| 144 | cache->saved_regs[regnum].addr = addr; |
| 145 | |
| 146 | /* The floating-point registers are only saved if the FEF bit in |
| 147 | %fprs has been set. */ |
| 148 | |
| 149 | #define FPRS_FEF (1 << 2) |
| 150 | |
| 151 | addr = cache->saved_regs[SPARC64_FPRS_REGNUM].addr; |
| 152 | fprs = get_frame_memory_unsigned (next_frame, addr, 8); |
| 153 | if (fprs & FPRS_FEF) |
| 154 | { |
| 155 | for (regnum = SPARC_F0_REGNUM, addr = mcontext_addr + 32 * 8; |
| 156 | regnum <= SPARC_F31_REGNUM; regnum++, addr += 4) |
| 157 | cache->saved_regs[regnum].addr = addr; |
| 158 | |
| 159 | for (regnum = SPARC64_F32_REGNUM; |
| 160 | regnum <= SPARC64_F62_REGNUM; regnum++, addr += 8) |
| 161 | cache->saved_regs[regnum].addr = addr; |
| 162 | } |
| 163 | |
| 164 | return cache; |
| 165 | } |
| 166 | |
| 167 | static void |
| 168 | sparc64fbsd_sigtramp_frame_this_id (struct frame_info *next_frame, |
| 169 | void **this_cache, |
| 170 | struct frame_id *this_id) |
| 171 | { |
| 172 | struct sparc_frame_cache *cache = |
| 173 | sparc64fbsd_sigtramp_frame_cache (next_frame, this_cache); |
| 174 | |
| 175 | (*this_id) = frame_id_build (cache->base, cache->pc); |
| 176 | } |
| 177 | |
| 178 | static void |
| 179 | sparc64fbsd_sigtramp_frame_prev_register (struct frame_info *next_frame, |
| 180 | void **this_cache, |
| 181 | int regnum, int *optimizedp, |
| 182 | enum lval_type *lvalp, |
| 183 | CORE_ADDR *addrp, |
| 184 | int *realnump, gdb_byte *valuep) |
| 185 | { |
| 186 | struct sparc_frame_cache *cache = |
| 187 | sparc64fbsd_sigtramp_frame_cache (next_frame, this_cache); |
| 188 | |
| 189 | trad_frame_get_prev_register (next_frame, cache->saved_regs, regnum, |
| 190 | optimizedp, lvalp, addrp, realnump, valuep); |
| 191 | } |
| 192 | |
| 193 | static const struct frame_unwind sparc64fbsd_sigtramp_frame_unwind = |
| 194 | { |
| 195 | SIGTRAMP_FRAME, |
| 196 | sparc64fbsd_sigtramp_frame_this_id, |
| 197 | sparc64fbsd_sigtramp_frame_prev_register |
| 198 | }; |
| 199 | |
| 200 | static const struct frame_unwind * |
| 201 | sparc64fbsd_sigtramp_frame_sniffer (struct frame_info *next_frame) |
| 202 | { |
| 203 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
| 204 | char *name; |
| 205 | |
| 206 | find_pc_partial_function (pc, &name, NULL, NULL); |
| 207 | if (sparc64fbsd_pc_in_sigtramp (pc, name)) |
| 208 | return &sparc64fbsd_sigtramp_frame_unwind; |
| 209 | |
| 210 | return NULL; |
| 211 | } |
| 212 | \f |
| 213 | |
| 214 | static void |
| 215 | sparc64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
| 216 | { |
| 217 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 218 | |
| 219 | tdep->gregset = regset_alloc (gdbarch, sparc64fbsd_supply_gregset, |
| 220 | sparc64fbsd_collect_gregset); |
| 221 | tdep->sizeof_gregset = 256; |
| 222 | |
| 223 | tdep->fpregset = regset_alloc (gdbarch, sparc64fbsd_supply_fpregset, |
| 224 | sparc64fbsd_collect_fpregset); |
| 225 | tdep->sizeof_fpregset = 272; |
| 226 | |
| 227 | frame_unwind_append_sniffer (gdbarch, sparc64fbsd_sigtramp_frame_sniffer); |
| 228 | |
| 229 | sparc64_init_abi (info, gdbarch); |
| 230 | |
| 231 | /* FreeBSD/sparc64 has SVR4-style shared libraries. */ |
| 232 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
| 233 | set_solib_svr4_fetch_link_map_offsets |
| 234 | (gdbarch, svr4_lp64_fetch_link_map_offsets); |
| 235 | } |
| 236 | |
| 237 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
| 238 | void _initialize_sparc64fbsd_tdep (void); |
| 239 | |
| 240 | void |
| 241 | _initialize_sparc64fbsd_tdep (void) |
| 242 | { |
| 243 | gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9, |
| 244 | GDB_OSABI_FREEBSD_ELF, sparc64fbsd_init_abi); |
| 245 | } |