* Makefile.in (ALLDEPFILES): Remove sparc-linux-nat.c and
[deliverable/binutils-gdb.git] / gdb / sparc64nbsd-tdep.c
CommitLineData
386c036b
MK
1/* Target-dependent code for NetBSD/sparc64.
2
3 Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
4 Based on code contributed by Wasabi Systems, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23#include "defs.h"
24#include "frame.h"
25#include "frame-unwind.h"
26#include "gdbcore.h"
27#include "osabi.h"
28#include "regcache.h"
29#include "symtab.h"
30#include "solib-svr4.h"
31#include "trad-frame.h"
32
33#include "gdb_assert.h"
34#include "gdb_string.h"
35
36#include "sparc64-tdep.h"
37#include "nbsd-tdep.h"
38
39/* From <machine/reg.h>. */
40const struct sparc_gregset sparc64nbsd_gregset =
41{
42 0 * 8, /* "tstate" */
43 1 * 8, /* %pc */
44 2 * 8, /* %npc */
45 3 * 8, /* %y */
46 -1, /* %fprs */
47 -1,
48 5 * 8, /* %g1 */
49 -1, /* %l0 */
50 4 /* sizeof (%y) */
51};
52
53/* Size of `struct reg' and `struct fpreg'. */
54static const int sparc64nbsd_sizeof_struct_reg = 160;
55static const int sparc64nbsd_sizeof_struct_fpreg = 272;
56
57static void
58fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which,
59 CORE_ADDR ignore)
60{
61 switch (which)
62 {
63 case 0: /* Integer registers */
64 if (core_reg_size != sparc64nbsd_sizeof_struct_reg)
65 warning ("Wrong size register set in core file.");
66 else
67 sparc64_supply_gregset (&sparc64nbsd_gregset, current_regcache,
68 -1, core_reg_sect);
69 break;
70
71 case 2: /* Floating pointer registers */
72 if (core_reg_size != sparc64nbsd_sizeof_struct_fpreg)
73 warning ("Wrong size FP register set in core file.");
74 else
75 sparc64_supply_fpregset (current_regcache, -1, core_reg_sect);
76 break;
77
78 default:
79 /* Don't know what kind of register request this is; just ignore it. */
80 break;
81 }
82}
83
84static struct core_fns sparc64nbsd_core_fns =
85{
86 bfd_target_elf_flavour, /* core_flavour */
87 default_check_format, /* check_format */
88 default_core_sniffer, /* core_sniffer */
89 fetch_core_registers, /* core_read_registers */
90 NULL
91};
92\f
93/* Signal trampolines. */
94
95/* The following variables describe the location of an on-stack signal
96 trampoline. The current values correspond to the memory layout for
97 NetBSD 1.3 and up. These shouldn't be necessary for NetBSD 2.0 and
98 up, since NetBSD uses signal trampolines provided by libc now. */
99
100static const CORE_ADDR sparc64nbsd_sigtramp_start = 0xffffffffffffdee4ULL;
101static const CORE_ADDR sparc64nbsd_sigtramp_end = 0xffffffffffffe000ULL;
102
103static int
104sparc64nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name)
105{
106 if (pc >= sparc64nbsd_sigtramp_start && pc < sparc64nbsd_sigtramp_end)
107 return 1;
108
109 return nbsd_pc_in_sigtramp (pc, name);
110}
111
112static struct sparc_frame_cache *
113sparc64nbsd_sigcontext_frame_cache (struct frame_info *next_frame,
114 void **this_cache)
115{
116 struct sparc_frame_cache *cache;
117 CORE_ADDR addr, sigcontext_addr, sp;
118 LONGEST fprs;
119 int regnum, delta;
120
121 if (*this_cache)
122 return *this_cache;
123
124 cache = sparc_frame_cache (next_frame, this_cache);
125 gdb_assert (cache == *this_cache);
126
127 /* The registers are saved in bits and pieces scattered all over the
128 place. The code below records their location on the assumption
129 that the part of the signal trampoline that saves the state has
130 been executed. */
131
132 /* If we couldn't find the frame's function, we're probably dealing
133 with an on-stack signal trampoline. */
134 if (cache->pc == 0)
135 {
136 cache->pc = sparc64nbsd_sigtramp_start;
137
138 /* Since we couldn't find the frame's function, the cache was
139 initialized under the assumption that we're frameless. */
140 cache->frameless_p = 0;
141 addr = frame_unwind_register_unsigned (next_frame, SPARC_FP_REGNUM);
142 cache->base = addr;
143 }
144
145 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
146
147 /* We find the appropriate instance of `struct sigcontext' at a
148 fixed offset in the signal frame. */
149 sigcontext_addr = cache->base + BIAS + 128 + 8;
150
151 cache->saved_regs[SPARC_SP_REGNUM].addr = sigcontext_addr + 8;
152 cache->saved_regs[SPARC64_PC_REGNUM].addr = sigcontext_addr + 16;
153 cache->saved_regs[SPARC64_NPC_REGNUM].addr = sigcontext_addr + 24;
154 cache->saved_regs[SPARC64_STATE_REGNUM].addr = sigcontext_addr + 32;
155 cache->saved_regs[SPARC_G1_REGNUM].addr = sigcontext_addr + 40;
156 cache->saved_regs[SPARC_O0_REGNUM].addr = sigcontext_addr + 48;
157
158 /* The remaining `global' registers and %y are saved in the `local'
159 registers. */
160 delta = SPARC_L0_REGNUM - SPARC_G0_REGNUM;
161 for (regnum = SPARC_G2_REGNUM; regnum <= SPARC_G7_REGNUM; regnum++)
162 cache->saved_regs[regnum].realreg = regnum + delta;
163 cache->saved_regs[SPARC64_Y_REGNUM].realreg = SPARC_L1_REGNUM;
164
165 /* The remaining `out' registers can be found in the current frame's
166 `in' registers. */
167 delta = SPARC_I0_REGNUM - SPARC_O0_REGNUM;
168 for (regnum = SPARC_O1_REGNUM; regnum <= SPARC_O5_REGNUM; regnum++)
169 cache->saved_regs[regnum].realreg = regnum + delta;
170 cache->saved_regs[SPARC_O7_REGNUM].realreg = SPARC_I7_REGNUM;
171
172 /* The `local' and `in' registers have been saved in the register
173 save area. */
174 addr = cache->saved_regs[SPARC_SP_REGNUM].addr;
175 sp = get_frame_memory_unsigned (next_frame, addr, 8);
176 for (regnum = SPARC_L0_REGNUM, addr = sp + BIAS;
177 regnum <= SPARC_I7_REGNUM; regnum++, addr += 8)
178 cache->saved_regs[regnum].addr = addr;
179
180 /* TODO: Handle the floating-point registers. */
181
182 return cache;
183}
184
185static void
186sparc64nbsd_sigcontext_frame_this_id (struct frame_info *next_frame,
187 void **this_cache,
188 struct frame_id *this_id)
189{
190 struct sparc_frame_cache *cache =
191 sparc64nbsd_sigcontext_frame_cache (next_frame, this_cache);
192
193 (*this_id) = frame_id_build (cache->base, cache->pc);
194}
195
196static void
197sparc64nbsd_sigcontext_frame_prev_register (struct frame_info *next_frame,
198 void **this_cache,
199 int regnum, int *optimizedp,
200 enum lval_type *lvalp,
201 CORE_ADDR *addrp,
202 int *realnump, void *valuep)
203{
204 struct sparc_frame_cache *cache =
205 sparc64nbsd_sigcontext_frame_cache (next_frame, this_cache);
206
207 trad_frame_prev_register (next_frame, cache->saved_regs, regnum,
208 optimizedp, lvalp, addrp, realnump, valuep);
209}
210
211static const struct frame_unwind sparc64nbsd_sigcontext_frame_unwind =
212{
213 SIGTRAMP_FRAME,
214 sparc64nbsd_sigcontext_frame_this_id,
215 sparc64nbsd_sigcontext_frame_prev_register
216};
217
218static const struct frame_unwind *
219sparc64nbsd_sigtramp_frame_sniffer (struct frame_info *next_frame)
220{
221 CORE_ADDR pc = frame_pc_unwind (next_frame);
222 char *name;
223
224 find_pc_partial_function (pc, &name, NULL, NULL);
225 if (sparc64nbsd_pc_in_sigtramp (pc, name))
226 {
227 if (name == NULL || strncmp (name, "__sigtramp_sigcontext", 21))
228 return &sparc64nbsd_sigcontext_frame_unwind;
229 }
230
231 return NULL;
232}
233\f
234
235static void
236sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
237{
238 set_gdbarch_pc_in_sigtramp (gdbarch, sparc64nbsd_pc_in_sigtramp);
239 frame_unwind_append_sniffer (gdbarch, sparc64nbsd_sigtramp_frame_sniffer);
240
241 sparc64_init_abi (info, gdbarch);
242
243 set_solib_svr4_fetch_link_map_offsets
244 (gdbarch, nbsd_lp64_solib_svr4_fetch_link_map_offsets);
245}
246
247\f
248/* Provide a prototype to silence -Wmissing-prototypes. */
249void _initialize_sparc64nbsd_tdep (void);
250
251void
252_initialize_sparc64nbsd_tdep (void)
253{
254 gdbarch_register_osabi (bfd_arch_sparc, bfd_mach_sparc_v9,
255 GDB_OSABI_NETBSD_ELF, sparc64nbsd_init_abi);
256
257 add_core_fns (&sparc64nbsd_core_fns);
258}
This page took 0.045052 seconds and 4 git commands to generate.