2006-12-06 Jim Blandy <jimb@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / sparc64nbsd-nat.c
CommitLineData
386c036b
MK
1/* Native-dependent code for NetBSD/sparc64.
2
197e01b6 3 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
9ce5c36a
JT
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
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
9ce5c36a
JT
21
22#include "defs.h"
90f3cecd 23#include "regcache.h"
1b9445c2 24#include "target.h"
9ce5c36a 25
386c036b
MK
26#include "sparc64-tdep.h"
27#include "sparc-nat.h"
9ce5c36a 28
386c036b
MK
29/* NetBSD is different from the other OSes that support both SPARC and
30 UltraSPARC in that the result of ptrace(2) depends on whether the
31 traced process is 32-bit or 64-bit. */
9ce5c36a 32
386c036b
MK
33static void
34sparc64nbsd_supply_gregset (const struct sparc_gregset *gregset,
35 struct regcache *regcache,
36 int regnum, const void *gregs)
37{
38 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
9ce5c36a 39
386c036b
MK
40 if (sparc32)
41 sparc32_supply_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
42 else
43 sparc64_supply_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
44}
45
46static void
47sparc64nbsd_collect_gregset (const struct sparc_gregset *gregset,
48 const struct regcache *regcache,
49 int regnum, void *gregs)
50{
51 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
52
53 if (sparc32)
54 sparc32_collect_gregset (&sparc32nbsd_gregset, regcache, regnum, gregs);
55 else
56 sparc64_collect_gregset (&sparc64nbsd_gregset, regcache, regnum, gregs);
57}
58
59static void
60sparc64nbsd_supply_fpregset (struct regcache *regcache,
61 int regnum, const void *fpregs)
62{
63 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
64
65 if (sparc32)
66 sparc32_supply_fpregset (regcache, regnum, fpregs);
67 else
68 sparc64_supply_fpregset (regcache, regnum, fpregs);
69}
70
71static void
72sparc64nbsd_collect_fpregset (const struct regcache *regcache,
73 int regnum, void *fpregs)
9ce5c36a 74{
386c036b
MK
75 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
76
77 if (sparc32)
78 sparc32_collect_fpregset (regcache, regnum, fpregs);
79 else
80 sparc64_collect_fpregset (regcache, regnum, fpregs);
9ce5c36a
JT
81}
82
386c036b
MK
83/* Determine whether `gregset_t' contains register REGNUM. */
84
9ce5c36a 85static int
386c036b 86sparc64nbsd_gregset_supplies_p (int regnum)
9ce5c36a 87{
386c036b
MK
88 if (gdbarch_ptr_bit (current_gdbarch) == 32)
89 return sparc32_gregset_supplies_p (regnum);
90
91 /* Integer registers. */
92 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM)
93 || (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM)
94 || (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_L7_REGNUM)
95 || (regnum >= SPARC_I0_REGNUM && regnum <= SPARC_I7_REGNUM))
96 return 1;
97
98 /* Control registers. */
99 if (regnum == SPARC64_PC_REGNUM
100 || regnum == SPARC64_NPC_REGNUM
101 || regnum == SPARC64_STATE_REGNUM
102 || regnum == SPARC64_Y_REGNUM)
103 return 1;
104
105 return 0;
9ce5c36a
JT
106}
107
386c036b
MK
108/* Determine whether `fpregset_t' contains register REGNUM. */
109
110static int
111sparc64nbsd_fpregset_supplies_p (int regnum)
9ce5c36a 112{
386c036b
MK
113 if (gdbarch_ptr_bit (current_gdbarch) == 32)
114 return sparc32_fpregset_supplies_p (regnum);
115
116 /* Floating-point registers. */
117 if ((regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
118 || (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM))
119 return 1;
120
121 /* Control registers. */
122 if (regnum == SPARC64_FSR_REGNUM)
123 return 1;
124
125 return 0;
9ce5c36a 126}
90f3cecd
MK
127\f
128
129/* Support for debugging kernel virtual memory images. */
130
131#include <sys/types.h>
132#include <machine/pcb.h>
133
134#include "bsd-kvm.h"
135
136static int
137sparc64nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
138{
139 int regnum;
140
141 /* The following is true for NetBSD 1.6.2:
142
143 The pcb contains %sp and %pc, %psr and %wim. From this information
144 we reconstruct the register state as it would look when we just
145 returned from cpu_switch(). */
146
147 /* The stack pointer shouldn't be zero. */
148 if (pcb->pcb_sp == 0)
149 return 0;
150
151 regcache_raw_supply (regcache, SPARC_SP_REGNUM, &pcb->pcb_sp);
152 regcache_raw_supply (regcache, SPARC64_PC_REGNUM, &pcb->pcb_pc);
153
154 sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
155
156 return 1;
157}
9ce5c36a 158
386c036b
MK
159\f
160/* Provide a prototype to silence -Wmissing-prototypes. */
90f3cecd 161void _initialize_sparc64nbsd_nat (void);
386c036b 162
9ce5c36a 163void
90f3cecd 164_initialize_sparc64nbsd_nat (void)
9ce5c36a 165{
386c036b
MK
166 sparc_supply_gregset = sparc64nbsd_supply_gregset;
167 sparc_collect_gregset = sparc64nbsd_collect_gregset;
168 sparc_supply_fpregset = sparc64nbsd_supply_fpregset;
169 sparc_collect_fpregset = sparc64nbsd_collect_fpregset;
170 sparc_gregset_supplies_p = sparc64nbsd_gregset_supplies_p;
171 sparc_fpregset_supplies_p = sparc64nbsd_fpregset_supplies_p;
90f3cecd 172
1b9445c2
MK
173 /* We've got nothing to add to the generic SPARC target. */
174 add_target (sparc_target ());
175
90f3cecd
MK
176 /* Support debugging kernel virtual memory images. */
177 bsd_kvm_add_target (sparc64nbsd_supply_pcb);
9ce5c36a 178}
This page took 0.561667 seconds and 4 git commands to generate.