Commit | Line | Data |
---|---|---|
d195bc9f MK |
1 | /* Native-dependent code for OpenBSD/powerpc. |
2 | ||
7b6bb8da | 3 | Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
0fb0cc75 | 4 | Free Software Foundation, Inc. |
d195bc9f MK |
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
d195bc9f MK |
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 | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
d195bc9f MK |
20 | |
21 | #include "defs.h" | |
0ae4f2cb | 22 | #include "gdbcore.h" |
d195bc9f MK |
23 | #include "inferior.h" |
24 | #include "regcache.h" | |
25 | ||
8599da2d | 26 | #include "gdb_assert.h" |
d195bc9f MK |
27 | #include <stddef.h> |
28 | #include <sys/types.h> | |
29 | #include <sys/ptrace.h> | |
0ae4f2cb MK |
30 | #include <sys/signal.h> |
31 | #include <machine/frame.h> | |
32 | #include <machine/pcb.h> | |
d195bc9f MK |
33 | #include <machine/reg.h> |
34 | ||
c79ac407 | 35 | #include "ppc-tdep.h" |
d195bc9f | 36 | #include "ppcobsd-tdep.h" |
65d034bc | 37 | #include "inf-ptrace.h" |
0ae4f2cb | 38 | #include "bsd-kvm.h" |
d195bc9f | 39 | |
8599da2d MK |
40 | /* OpenBSD/powerpc didn't have PT_GETFPREGS/PT_SETFPREGS until release |
41 | 4.0. On older releases the floating-point registers are handled by | |
42 | PT_GETREGS/PT_SETREGS, but fpscr wasn't available.. */ | |
43 | ||
44 | #ifdef PT_GETFPREGS | |
45 | ||
46 | /* Returns true if PT_GETFPREGS fetches this register. */ | |
47 | ||
48 | static int | |
206988c4 | 49 | getfpregs_supplies (struct gdbarch *gdbarch, int regnum) |
8599da2d | 50 | { |
206988c4 | 51 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
8599da2d MK |
52 | |
53 | /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating | |
54 | point registers. Traditionally, GDB's register set has still | |
55 | listed the floating point registers for such machines, so this | |
56 | code is harmless. However, the new E500 port actually omits the | |
57 | floating point registers entirely from the register set --- they | |
58 | don't even have register numbers assigned to them. | |
59 | ||
60 | It's not clear to me how best to update this code, so this assert | |
61 | will alert the first person to encounter the NetBSD/E500 | |
62 | combination to the problem. */ | |
206988c4 | 63 | gdb_assert (ppc_floating_point_unit_p (gdbarch)); |
8599da2d MK |
64 | |
65 | return ((regnum >= tdep->ppc_fp0_regnum | |
66 | && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs) | |
67 | || regnum == tdep->ppc_fpscr_regnum); | |
68 | } | |
69 | ||
70 | #endif /* PT_GETFPREGS */ | |
d195bc9f MK |
71 | |
72 | /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this | |
73 | for all registers. */ | |
74 | ||
65d034bc | 75 | static void |
28439f5e PA |
76 | ppcobsd_fetch_registers (struct target_ops *ops, |
77 | struct regcache *regcache, int regnum) | |
d195bc9f MK |
78 | { |
79 | struct reg regs; | |
80 | ||
81 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 82 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 83 | perror_with_name (_("Couldn't get registers")); |
d195bc9f | 84 | |
56be3814 | 85 | ppc_supply_gregset (&ppcobsd_gregset, regcache, -1, |
8599da2d MK |
86 | ®s, sizeof regs); |
87 | #ifndef PT_GETFPREGS | |
56be3814 | 88 | ppc_supply_fpregset (&ppcobsd_gregset, regcache, -1, |
8599da2d MK |
89 | ®s, sizeof regs); |
90 | #endif | |
91 | ||
92 | #ifdef PT_GETFPREGS | |
206988c4 MD |
93 | if (regnum == -1 |
94 | || getfpregs_supplies (get_regcache_arch (regcache), regnum)) | |
8599da2d MK |
95 | { |
96 | struct fpreg fpregs; | |
97 | ||
98 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
99 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | |
100 | perror_with_name (_("Couldn't get floating point status")); | |
101 | ||
56be3814 | 102 | ppc_supply_fpregset (&ppcobsd_fpregset, regcache, -1, |
8599da2d MK |
103 | &fpregs, sizeof fpregs); |
104 | } | |
105 | #endif | |
d195bc9f MK |
106 | } |
107 | ||
108 | /* Store register REGNUM back into the inferior. If REGNUM is -1, do | |
109 | this for all registers. */ | |
110 | ||
65d034bc | 111 | static void |
28439f5e PA |
112 | ppcobsd_store_registers (struct target_ops *ops, |
113 | struct regcache *regcache, int regnum) | |
d195bc9f MK |
114 | { |
115 | struct reg regs; | |
116 | ||
117 | if (ptrace (PT_GETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 118 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 119 | perror_with_name (_("Couldn't get registers")); |
d195bc9f | 120 | |
56be3814 | 121 | ppc_collect_gregset (&ppcobsd_gregset, regcache, |
8599da2d MK |
122 | regnum, ®s, sizeof regs); |
123 | #ifndef PT_GETFPREGS | |
56be3814 | 124 | ppc_collect_fpregset (&ppcobsd_gregset, regcache, |
8599da2d MK |
125 | regnum, ®s, sizeof regs); |
126 | #endif | |
d195bc9f MK |
127 | |
128 | if (ptrace (PT_SETREGS, PIDGET (inferior_ptid), | |
9f8e0089 | 129 | (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
e2e0b3e5 | 130 | perror_with_name (_("Couldn't write registers")); |
8599da2d MK |
131 | |
132 | #ifdef PT_GETFPREGS | |
206988c4 MD |
133 | if (regnum == -1 |
134 | || getfpregs_supplies (get_regcache_arch (regcache), regnum)) | |
8599da2d MK |
135 | { |
136 | struct fpreg fpregs; | |
137 | ||
138 | if (ptrace (PT_GETFPREGS, PIDGET (inferior_ptid), | |
139 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | |
140 | perror_with_name (_("Couldn't get floating point status")); | |
141 | ||
56be3814 | 142 | ppc_collect_fpregset (&ppcobsd_fpregset, regcache, |
8599da2d MK |
143 | regnum, &fpregs, sizeof fpregs); |
144 | ||
145 | if (ptrace (PT_SETFPREGS, PIDGET (inferior_ptid), | |
146 | (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | |
147 | perror_with_name (_("Couldn't write floating point status")); | |
148 | } | |
149 | #endif | |
d195bc9f MK |
150 | } |
151 | \f | |
152 | ||
0ae4f2cb MK |
153 | static int |
154 | ppcobsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
155 | { | |
40a6adc1 MD |
156 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
157 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
0ae4f2cb MK |
158 | struct switchframe sf; |
159 | struct callframe cf; | |
160 | int i, regnum; | |
161 | ||
162 | /* The following is true for OpenBSD 3.7: | |
163 | ||
164 | The pcb contains %r1 (the stack pointer) at the point of the | |
165 | context switch in cpu_switch(). At that point we have a stack | |
166 | frame as described by `struct switchframe', and below that a call | |
167 | frame as described by `struct callframe'. From this information | |
168 | we reconstruct the register state as it would look when we are in | |
169 | cpu_switch(). */ | |
170 | ||
171 | /* The stack pointer shouldn't be zero. */ | |
172 | if (pcb->pcb_sp == 0) | |
173 | return 0; | |
174 | ||
175 | read_memory (pcb->pcb_sp, (gdb_byte *)&sf, sizeof sf); | |
40a6adc1 | 176 | regcache_raw_supply (regcache, gdbarch_sp_regnum (gdbarch), &sf.sp); |
0ae4f2cb MK |
177 | regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr); |
178 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2); | |
179 | for (i = 0, regnum = tdep->ppc_gp0_regnum + 13; i < 19; i++, regnum++) | |
180 | regcache_raw_supply (regcache, regnum, &sf.fixreg[i]); | |
181 | ||
182 | read_memory (sf.sp, (gdb_byte *)&cf, sizeof cf); | |
40a6adc1 | 183 | regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch), &cf.lr); |
0ae4f2cb MK |
184 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30); |
185 | regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31); | |
186 | ||
187 | return 1; | |
188 | } | |
189 | \f | |
190 | ||
d195bc9f MK |
191 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
192 | void _initialize_ppcobsd_nat (void); | |
193 | ||
194 | void | |
195 | _initialize_ppcobsd_nat (void) | |
196 | { | |
65d034bc MK |
197 | struct target_ops *t; |
198 | ||
199 | /* Add in local overrides. */ | |
200 | t = inf_ptrace_target (); | |
201 | t->to_fetch_registers = ppcobsd_fetch_registers; | |
202 | t->to_store_registers = ppcobsd_store_registers; | |
203 | add_target (t); | |
204 | ||
d195bc9f MK |
205 | /* General-purpose registers. */ |
206 | ppcobsd_reg_offsets.r0_offset = offsetof (struct reg, gpr); | |
f2db237a AM |
207 | ppcobsd_reg_offsets.gpr_size = 4; |
208 | ppcobsd_reg_offsets.xr_size = 4; | |
d195bc9f MK |
209 | ppcobsd_reg_offsets.pc_offset = offsetof (struct reg, pc); |
210 | ppcobsd_reg_offsets.ps_offset = offsetof (struct reg, ps); | |
211 | ppcobsd_reg_offsets.cr_offset = offsetof (struct reg, cnd); | |
212 | ppcobsd_reg_offsets.lr_offset = offsetof (struct reg, lr); | |
213 | ppcobsd_reg_offsets.ctr_offset = offsetof (struct reg, cnt); | |
214 | ppcobsd_reg_offsets.xer_offset = offsetof (struct reg, xer); | |
215 | ppcobsd_reg_offsets.mq_offset = offsetof (struct reg, mq); | |
216 | ||
217 | /* Floating-point registers. */ | |
218 | ppcobsd_reg_offsets.f0_offset = offsetof (struct reg, fpr); | |
219 | ppcobsd_reg_offsets.fpscr_offset = -1; | |
8599da2d MK |
220 | #ifdef PT_GETFPREGS |
221 | ppcobsd_fpreg_offsets.f0_offset = offsetof (struct fpreg, fpr); | |
222 | ppcobsd_fpreg_offsets.fpscr_offset = offsetof (struct fpreg, fpscr); | |
f2db237a | 223 | ppcobsd_fpreg_offsets.fpscr_size = 4; |
8599da2d | 224 | #endif |
d195bc9f MK |
225 | |
226 | /* AltiVec registers. */ | |
227 | ppcobsd_reg_offsets.vr0_offset = offsetof (struct vreg, vreg); | |
228 | ppcobsd_reg_offsets.vscr_offset = offsetof (struct vreg, vscr); | |
229 | ppcobsd_reg_offsets.vrsave_offset = offsetof (struct vreg, vrsave); | |
0ae4f2cb MK |
230 | |
231 | /* Support debugging kernel virtual memory images. */ | |
232 | bsd_kvm_add_target (ppcobsd_supply_pcb); | |
d195bc9f | 233 | } |