Move gdb/signals.h to common-defs.h
[deliverable/binutils-gdb.git] / gdb / ppcfbsd-nat.c
1 /* Native-dependent code for PowerPC's running FreeBSD, for GDB.
2
3 Copyright (C) 2013-2014 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 3 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, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "inferior.h"
23 #include "regcache.h"
24
25 #include "gdb_assert.h"
26 #include <sys/types.h>
27 #include <sys/procfs.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>
33
34 #include "fbsd-nat.h"
35 #include "gregset.h"
36 #include "ppc-tdep.h"
37 #include "ppcfbsd-tdep.h"
38 #include "inf-ptrace.h"
39 #include "bsd-kvm.h"
40
41 /* Fill GDB's register array with the general-purpose register values
42 in *GREGSETP. */
43
44 void
45 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
46 {
47 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
48
49 ppc_supply_gregset (regset, regcache, -1, gregsetp, sizeof (*gregsetp));
50 }
51
52 /* Fill register REGNO (if a gpr) in *GREGSETP with the value in GDB's
53 register array. If REGNO is -1 do it for all registers. */
54
55 void
56 fill_gregset (const struct regcache *regcache,
57 gdb_gregset_t *gregsetp, int regno)
58 {
59 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
60
61 if (regno == -1)
62 memset (gregsetp, 0, sizeof (*gregsetp));
63 ppc_collect_gregset (regset, regcache, regno, gregsetp, sizeof (*gregsetp));
64 }
65
66 /* Fill GDB's register array with the floating-point register values
67 in *FPREGSETP. */
68
69 void
70 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t * fpregsetp)
71 {
72 const struct regset *regset = ppc_fbsd_fpregset ();
73
74 ppc_supply_fpregset (regset, regcache, -1,
75 fpregsetp, sizeof (*fpregsetp));
76 }
77
78 /* Fill register REGNO in *FGREGSETP with the value in GDB's
79 register array. If REGNO is -1 do it for all registers. */
80
81 void
82 fill_fpregset (const struct regcache *regcache,
83 gdb_fpregset_t *fpregsetp, int regno)
84 {
85 const struct regset *regset = ppc_fbsd_fpregset ();
86
87 ppc_collect_fpregset (regset, regcache, regno,
88 fpregsetp, sizeof (*fpregsetp));
89 }
90
91 /* Returns true if PT_GETFPREGS fetches this register. */
92
93 static int
94 getfpregs_supplies (struct gdbarch *gdbarch, int regno)
95 {
96 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
97
98 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
99 point registers. Traditionally, GDB's register set has still
100 listed the floating point registers for such machines, so this
101 code is harmless. However, the new E500 port actually omits the
102 floating point registers entirely from the register set --- they
103 don't even have register numbers assigned to them.
104
105 It's not clear to me how best to update this code, so this assert
106 will alert the first person to encounter the NetBSD/E500
107 combination to the problem. */
108
109 gdb_assert (ppc_floating_point_unit_p (gdbarch));
110
111 return ((regno >= tdep->ppc_fp0_regnum
112 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
113 || regno == tdep->ppc_fpscr_regnum);
114 }
115
116 /* Fetch register REGNO from the child process. If REGNO is -1, do it
117 for all registers. */
118
119 static void
120 ppcfbsd_fetch_inferior_registers (struct target_ops *ops,
121 struct regcache *regcache, int regno)
122 {
123 gdb_gregset_t regs;
124
125 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
126 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
127 perror_with_name (_("Couldn't get registers"));
128
129 supply_gregset (regcache, &regs);
130
131 if (regno == -1 || getfpregs_supplies (get_regcache_arch (regcache), regno))
132 {
133 const struct regset *fpregset = ppc_fbsd_fpregset ();
134 gdb_fpregset_t fpregs;
135
136 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
137 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
138 perror_with_name (_("Couldn't get FP registers"));
139
140 ppc_supply_fpregset (fpregset, regcache, regno, &fpregs, sizeof fpregs);
141 }
142 }
143
144 /* Store register REGNO back into the child process. If REGNO is -1,
145 do this for all registers. */
146
147 static void
148 ppcfbsd_store_inferior_registers (struct target_ops *ops,
149 struct regcache *regcache, int regno)
150 {
151 gdb_gregset_t regs;
152
153 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid),
154 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
155 perror_with_name (_("Couldn't get registers"));
156
157 fill_gregset (regcache, &regs, regno);
158
159 if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid),
160 (PTRACE_TYPE_ARG3) &regs, 0) == -1)
161 perror_with_name (_("Couldn't write registers"));
162
163 if (regno == -1 || getfpregs_supplies (get_regcache_arch (regcache), regno))
164 {
165 gdb_fpregset_t fpregs;
166
167 if (ptrace (PT_GETFPREGS, ptid_get_pid (inferior_ptid),
168 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
169 perror_with_name (_("Couldn't get FP registers"));
170
171 fill_fpregset (regcache, &fpregs, regno);
172
173 if (ptrace (PT_SETFPREGS, ptid_get_pid (inferior_ptid),
174 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
175 perror_with_name (_("Couldn't set FP registers"));
176 }
177 }
178
179 /* Architecture specific function that reconstructs the
180 register state from PCB (Process Control Block) and supplies it
181 to REGCACHE. */
182
183 static int
184 ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
185 {
186 struct gdbarch *gdbarch = get_regcache_arch (regcache);
187 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
188 int i, regnum;
189
190 /* The stack pointer shouldn't be zero. */
191 if (pcb->pcb_sp == 0)
192 return 0;
193
194 regcache_raw_supply (regcache, gdbarch_sp_regnum (gdbarch), &pcb->pcb_sp);
195 regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &pcb->pcb_cr);
196 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &pcb->pcb_lr);
197 for (i = 0, regnum = tdep->ppc_gp0_regnum + 14; i < 20; i++, regnum++)
198 regcache_raw_supply (regcache, regnum, &pcb->pcb_context[i]);
199
200 return 1;
201 }
202
203 /* Provide a prototype to silence -Wmissing-prototypes. */
204
205 void _initialize_ppcfbsd_nat (void);
206
207 void
208 _initialize_ppcfbsd_nat (void)
209 {
210 struct target_ops *t;
211
212 /* Add in local overrides. */
213 t = inf_ptrace_target ();
214 t->to_fetch_registers = ppcfbsd_fetch_inferior_registers;
215 t->to_store_registers = ppcfbsd_store_inferior_registers;
216 t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
217 t->to_find_memory_regions = fbsd_find_memory_regions;
218 t->to_make_corefile_notes = fbsd_make_corefile_notes;
219 add_target (t);
220
221 /* Support debugging kernel virtual memory images. */
222 bsd_kvm_add_target (ppcfbsd_supply_pcb);
223 }
This page took 0.042415 seconds and 4 git commands to generate.