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