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