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