1 /* Native-dependent code for OpenBSD/powerpc.
3 Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "gdb_assert.h"
27 #include <sys/types.h>
28 #include <sys/ptrace.h>
29 #include <sys/signal.h>
30 #include <machine/frame.h>
31 #include <machine/pcb.h>
32 #include <machine/reg.h>
35 #include "ppcobsd-tdep.h"
36 #include "inf-ptrace.h"
39 /* OpenBSD/powerpc didn't have PT_GETFPREGS/PT_SETFPREGS until release
40 4.0. On older releases the floating-point registers are handled by
41 PT_GETREGS/PT_SETREGS, but fpscr wasn't available.. */
45 /* Returns true if PT_GETFPREGS fetches this register. */
48 getfpregs_supplies (struct gdbarch
*gdbarch
, int regnum
)
50 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
52 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
53 point registers. Traditionally, GDB's register set has still
54 listed the floating point registers for such machines, so this
55 code is harmless. However, the new E500 port actually omits the
56 floating point registers entirely from the register set --- they
57 don't even have register numbers assigned to them.
59 It's not clear to me how best to update this code, so this assert
60 will alert the first person to encounter the NetBSD/E500
61 combination to the problem. */
62 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
64 return ((regnum
>= tdep
->ppc_fp0_regnum
65 && regnum
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
66 || regnum
== tdep
->ppc_fpscr_regnum
);
69 #endif /* PT_GETFPREGS */
71 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this
75 ppcobsd_fetch_registers (struct target_ops
*ops
,
76 struct regcache
*regcache
, int regnum
)
80 if (ptrace (PT_GETREGS
, ptid_get_pid (inferior_ptid
),
81 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
82 perror_with_name (_("Couldn't get registers"));
84 ppc_supply_gregset (&ppcobsd_gregset
, regcache
, -1,
87 ppc_supply_fpregset (&ppcobsd_gregset
, regcache
, -1,
93 || getfpregs_supplies (get_regcache_arch (regcache
), regnum
))
97 if (ptrace (PT_GETFPREGS
, ptid_get_pid (inferior_ptid
),
98 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
99 perror_with_name (_("Couldn't get floating point status"));
101 ppc_supply_fpregset (&ppcobsd_fpregset
, regcache
, -1,
102 &fpregs
, sizeof fpregs
);
107 /* Store register REGNUM back into the inferior. If REGNUM is -1, do
108 this for all registers. */
111 ppcobsd_store_registers (struct target_ops
*ops
,
112 struct regcache
*regcache
, int regnum
)
116 if (ptrace (PT_GETREGS
, ptid_get_pid (inferior_ptid
),
117 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
118 perror_with_name (_("Couldn't get registers"));
120 ppc_collect_gregset (&ppcobsd_gregset
, regcache
,
121 regnum
, ®s
, sizeof regs
);
123 ppc_collect_fpregset (&ppcobsd_gregset
, regcache
,
124 regnum
, ®s
, sizeof regs
);
127 if (ptrace (PT_SETREGS
, ptid_get_pid (inferior_ptid
),
128 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
129 perror_with_name (_("Couldn't write registers"));
133 || getfpregs_supplies (get_regcache_arch (regcache
), regnum
))
137 if (ptrace (PT_GETFPREGS
, ptid_get_pid (inferior_ptid
),
138 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
139 perror_with_name (_("Couldn't get floating point status"));
141 ppc_collect_fpregset (&ppcobsd_fpregset
, regcache
,
142 regnum
, &fpregs
, sizeof fpregs
);
144 if (ptrace (PT_SETFPREGS
, ptid_get_pid (inferior_ptid
),
145 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
146 perror_with_name (_("Couldn't write floating point status"));
153 ppcobsd_supply_pcb (struct regcache
*regcache
, struct pcb
*pcb
)
155 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
156 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
157 struct switchframe sf
;
161 /* The following is true for OpenBSD 3.7:
163 The pcb contains %r1 (the stack pointer) at the point of the
164 context switch in cpu_switch(). At that point we have a stack
165 frame as described by `struct switchframe', and below that a call
166 frame as described by `struct callframe'. From this information
167 we reconstruct the register state as it would look when we are in
170 /* The stack pointer shouldn't be zero. */
171 if (pcb
->pcb_sp
== 0)
174 read_memory (pcb
->pcb_sp
, (gdb_byte
*)&sf
, sizeof sf
);
175 regcache_raw_supply (regcache
, gdbarch_sp_regnum (gdbarch
), &sf
.sp
);
176 regcache_raw_supply (regcache
, tdep
->ppc_cr_regnum
, &sf
.cr
);
177 regcache_raw_supply (regcache
, tdep
->ppc_gp0_regnum
+ 2, &sf
.fixreg2
);
178 for (i
= 0, regnum
= tdep
->ppc_gp0_regnum
+ 13; i
< 19; i
++, regnum
++)
179 regcache_raw_supply (regcache
, regnum
, &sf
.fixreg
[i
]);
181 read_memory (sf
.sp
, (gdb_byte
*)&cf
, sizeof cf
);
182 regcache_raw_supply (regcache
, gdbarch_pc_regnum (gdbarch
), &cf
.lr
);
183 regcache_raw_supply (regcache
, tdep
->ppc_gp0_regnum
+ 30, &cf
.r30
);
184 regcache_raw_supply (regcache
, tdep
->ppc_gp0_regnum
+ 31, &cf
.r31
);
190 /* Provide a prototype to silence -Wmissing-prototypes. */
191 void _initialize_ppcobsd_nat (void);
194 _initialize_ppcobsd_nat (void)
196 struct target_ops
*t
;
198 /* Add in local overrides. */
199 t
= inf_ptrace_target ();
200 t
->to_fetch_registers
= ppcobsd_fetch_registers
;
201 t
->to_store_registers
= ppcobsd_store_registers
;
204 /* General-purpose registers. */
205 ppcobsd_reg_offsets
.r0_offset
= offsetof (struct reg
, gpr
);
206 ppcobsd_reg_offsets
.gpr_size
= 4;
207 ppcobsd_reg_offsets
.xr_size
= 4;
208 ppcobsd_reg_offsets
.pc_offset
= offsetof (struct reg
, pc
);
209 ppcobsd_reg_offsets
.ps_offset
= offsetof (struct reg
, ps
);
210 ppcobsd_reg_offsets
.cr_offset
= offsetof (struct reg
, cnd
);
211 ppcobsd_reg_offsets
.lr_offset
= offsetof (struct reg
, lr
);
212 ppcobsd_reg_offsets
.ctr_offset
= offsetof (struct reg
, cnt
);
213 ppcobsd_reg_offsets
.xer_offset
= offsetof (struct reg
, xer
);
214 ppcobsd_reg_offsets
.mq_offset
= offsetof (struct reg
, mq
);
216 /* Floating-point registers. */
217 ppcobsd_reg_offsets
.f0_offset
= offsetof (struct reg
, fpr
);
218 ppcobsd_reg_offsets
.fpscr_offset
= -1;
220 ppcobsd_fpreg_offsets
.f0_offset
= offsetof (struct fpreg
, fpr
);
221 ppcobsd_fpreg_offsets
.fpscr_offset
= offsetof (struct fpreg
, fpscr
);
222 ppcobsd_fpreg_offsets
.fpscr_size
= 4;
225 /* AltiVec registers. */
226 ppcobsd_reg_offsets
.vr0_offset
= offsetof (struct vreg
, vreg
);
227 ppcobsd_reg_offsets
.vscr_offset
= offsetof (struct vreg
, vscr
);
228 ppcobsd_reg_offsets
.vrsave_offset
= offsetof (struct vreg
, vrsave
);
230 /* Support debugging kernel virtual memory images. */
231 bsd_kvm_add_target (ppcobsd_supply_pcb
);
This page took 0.034076 seconds and 4 git commands to generate.