]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/sparc64nbsd-nat.c
7d554cf60897df46053a714978e1e0be298d4eea
[thirdparty/binutils-gdb.git] / gdb / sparc64nbsd-nat.c
1 /* Native-dependent code for NetBSD/sparc64.
2
3 Copyright 2003, 2004 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include "defs.h"
23 #include "regcache.h"
24
25 #include "sparc64-tdep.h"
26 #include "sparc-nat.h"
27
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. */
31
32 static void
33 sparc64nbsd_supply_gregset (const struct sparc_gregset *gregset,
34 struct regcache *regcache,
35 int regnum, const void *gregs)
36 {
37 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
38
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
45 static void
46 sparc64nbsd_collect_gregset (const struct sparc_gregset *gregset,
47 const struct regcache *regcache,
48 int regnum, void *gregs)
49 {
50 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
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
58 static void
59 sparc64nbsd_supply_fpregset (struct regcache *regcache,
60 int regnum, const void *fpregs)
61 {
62 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
63
64 if (sparc32)
65 sparc32_supply_fpregset (regcache, regnum, fpregs);
66 else
67 sparc64_supply_fpregset (regcache, regnum, fpregs);
68 }
69
70 static void
71 sparc64nbsd_collect_fpregset (const struct regcache *regcache,
72 int regnum, void *fpregs)
73 {
74 int sparc32 = (gdbarch_ptr_bit (current_gdbarch) == 32);
75
76 if (sparc32)
77 sparc32_collect_fpregset (regcache, regnum, fpregs);
78 else
79 sparc64_collect_fpregset (regcache, regnum, fpregs);
80 }
81
82 /* Determine whether `gregset_t' contains register REGNUM. */
83
84 static int
85 sparc64nbsd_gregset_supplies_p (int regnum)
86 {
87 if (gdbarch_ptr_bit (current_gdbarch) == 32)
88 return sparc32_gregset_supplies_p (regnum);
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;
105 }
106
107 /* Determine whether `fpregset_t' contains register REGNUM. */
108
109 static int
110 sparc64nbsd_fpregset_supplies_p (int regnum)
111 {
112 if (gdbarch_ptr_bit (current_gdbarch) == 32)
113 return sparc32_fpregset_supplies_p (regnum);
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;
125 }
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
135 static int
136 sparc64nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
137 {
138 int regnum;
139
140 /* The following is true for NetBSD 1.6.2:
141
142 The pcb contains %sp and %pc, %psr and %wim. From this information
143 we reconstruct the register state as it would look when we just
144 returned from cpu_switch(). */
145
146 /* The stack pointer shouldn't be zero. */
147 if (pcb->pcb_sp == 0)
148 return 0;
149
150 regcache_raw_supply (regcache, SPARC_SP_REGNUM, &pcb->pcb_sp);
151 regcache_raw_supply (regcache, SPARC64_PC_REGNUM, &pcb->pcb_pc);
152
153 sparc_supply_rwindow (regcache, pcb->pcb_sp, -1);
154
155 return 1;
156 }
157
158 \f
159 /* Provide a prototype to silence -Wmissing-prototypes. */
160 void _initialize_sparc64nbsd_nat (void);
161
162 void
163 _initialize_sparc64nbsd_nat (void)
164 {
165 sparc_supply_gregset = sparc64nbsd_supply_gregset;
166 sparc_collect_gregset = sparc64nbsd_collect_gregset;
167 sparc_supply_fpregset = sparc64nbsd_supply_fpregset;
168 sparc_collect_fpregset = sparc64nbsd_collect_fpregset;
169 sparc_gregset_supplies_p = sparc64nbsd_gregset_supplies_p;
170 sparc_fpregset_supplies_p = sparc64nbsd_fpregset_supplies_p;
171
172 /* Support debugging kernel virtual memory images. */
173 bsd_kvm_add_target (sparc64nbsd_supply_pcb);
174 }