1 /* Native-dependent code for PowerPC's running FreeBSD, for GDB.
3 Copyright (C) 2013-2015 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 <sys/types.h>
26 #include <sys/procfs.h>
27 #include <sys/ptrace.h>
28 #include <sys/signal.h>
29 #include <machine/frame.h>
30 #include <machine/pcb.h>
31 #include <machine/reg.h>
36 #include "ppcfbsd-tdep.h"
37 #include "inf-ptrace.h"
40 /* Fill GDB's register array with the general-purpose register values
44 supply_gregset (struct regcache
*regcache
, const gdb_gregset_t
*gregsetp
)
46 const struct regset
*regset
= ppc_fbsd_gregset (sizeof (long));
48 ppc_supply_gregset (regset
, regcache
, -1, gregsetp
, sizeof (*gregsetp
));
51 /* Fill register REGNO (if a gpr) in *GREGSETP with the value in GDB's
52 register array. If REGNO is -1 do it for all registers. */
55 fill_gregset (const struct regcache
*regcache
,
56 gdb_gregset_t
*gregsetp
, int regno
)
58 const struct regset
*regset
= ppc_fbsd_gregset (sizeof (long));
61 memset (gregsetp
, 0, sizeof (*gregsetp
));
62 ppc_collect_gregset (regset
, regcache
, regno
, gregsetp
, sizeof (*gregsetp
));
65 /* Fill GDB's register array with the floating-point register values
69 supply_fpregset (struct regcache
*regcache
, const gdb_fpregset_t
* fpregsetp
)
71 const struct regset
*regset
= ppc_fbsd_fpregset ();
73 ppc_supply_fpregset (regset
, regcache
, -1,
74 fpregsetp
, sizeof (*fpregsetp
));
77 /* Fill register REGNO in *FGREGSETP with the value in GDB's
78 register array. If REGNO is -1 do it for all registers. */
81 fill_fpregset (const struct regcache
*regcache
,
82 gdb_fpregset_t
*fpregsetp
, int regno
)
84 const struct regset
*regset
= ppc_fbsd_fpregset ();
86 ppc_collect_fpregset (regset
, regcache
, regno
,
87 fpregsetp
, sizeof (*fpregsetp
));
90 /* Returns true if PT_GETFPREGS fetches this register. */
93 getfpregs_supplies (struct gdbarch
*gdbarch
, int regno
)
95 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
97 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
98 point registers. Traditionally, GDB's register set has still
99 listed the floating point registers for such machines, so this
100 code is harmless. However, the new E500 port actually omits the
101 floating point registers entirely from the register set --- they
102 don't even have register numbers assigned to them.
104 It's not clear to me how best to update this code, so this assert
105 will alert the first person to encounter the NetBSD/E500
106 combination to the problem. */
108 gdb_assert (ppc_floating_point_unit_p (gdbarch
));
110 return ((regno
>= tdep
->ppc_fp0_regnum
111 && regno
< tdep
->ppc_fp0_regnum
+ ppc_num_fprs
)
112 || regno
== tdep
->ppc_fpscr_regnum
);
115 /* Fetch register REGNO from the child process. If REGNO is -1, do it
116 for all registers. */
119 ppcfbsd_fetch_inferior_registers (struct target_ops
*ops
,
120 struct regcache
*regcache
, int regno
)
124 if (ptrace (PT_GETREGS
, ptid_get_pid (inferior_ptid
),
125 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
126 perror_with_name (_("Couldn't get registers"));
128 supply_gregset (regcache
, ®s
);
130 if (regno
== -1 || getfpregs_supplies (get_regcache_arch (regcache
), regno
))
132 const struct regset
*fpregset
= ppc_fbsd_fpregset ();
133 gdb_fpregset_t fpregs
;
135 if (ptrace (PT_GETFPREGS
, ptid_get_pid (inferior_ptid
),
136 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
137 perror_with_name (_("Couldn't get FP registers"));
139 ppc_supply_fpregset (fpregset
, regcache
, regno
, &fpregs
, sizeof fpregs
);
143 /* Store register REGNO back into the child process. If REGNO is -1,
144 do this for all registers. */
147 ppcfbsd_store_inferior_registers (struct target_ops
*ops
,
148 struct regcache
*regcache
, int regno
)
152 if (ptrace (PT_GETREGS
, ptid_get_pid (inferior_ptid
),
153 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
154 perror_with_name (_("Couldn't get registers"));
156 fill_gregset (regcache
, ®s
, regno
);
158 if (ptrace (PT_SETREGS
, ptid_get_pid (inferior_ptid
),
159 (PTRACE_TYPE_ARG3
) ®s
, 0) == -1)
160 perror_with_name (_("Couldn't write registers"));
162 if (regno
== -1 || getfpregs_supplies (get_regcache_arch (regcache
), regno
))
164 gdb_fpregset_t fpregs
;
166 if (ptrace (PT_GETFPREGS
, ptid_get_pid (inferior_ptid
),
167 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
168 perror_with_name (_("Couldn't get FP registers"));
170 fill_fpregset (regcache
, &fpregs
, regno
);
172 if (ptrace (PT_SETFPREGS
, ptid_get_pid (inferior_ptid
),
173 (PTRACE_TYPE_ARG3
) &fpregs
, 0) == -1)
174 perror_with_name (_("Couldn't set FP registers"));
178 /* Architecture specific function that reconstructs the
179 register state from PCB (Process Control Block) and supplies it
183 ppcfbsd_supply_pcb (struct regcache
*regcache
, struct pcb
*pcb
)
185 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
186 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
189 /* The stack pointer shouldn't be zero. */
190 if (pcb
->pcb_sp
== 0)
193 regcache_raw_supply (regcache
, gdbarch_sp_regnum (gdbarch
), &pcb
->pcb_sp
);
194 regcache_raw_supply (regcache
, tdep
->ppc_cr_regnum
, &pcb
->pcb_cr
);
195 regcache_raw_supply (regcache
, tdep
->ppc_lr_regnum
, &pcb
->pcb_lr
);
196 for (i
= 0, regnum
= tdep
->ppc_gp0_regnum
+ 14; i
< 20; i
++, regnum
++)
197 regcache_raw_supply (regcache
, regnum
, &pcb
->pcb_context
[i
]);
202 /* Provide a prototype to silence -Wmissing-prototypes. */
204 void _initialize_ppcfbsd_nat (void);
207 _initialize_ppcfbsd_nat (void)
209 struct target_ops
*t
;
211 /* Add in local overrides. */
212 t
= inf_ptrace_target ();
213 t
->to_fetch_registers
= ppcfbsd_fetch_inferior_registers
;
214 t
->to_store_registers
= ppcfbsd_store_inferior_registers
;
215 t
->to_pid_to_exec_file
= fbsd_pid_to_exec_file
;
216 t
->to_find_memory_regions
= fbsd_find_memory_regions
;
219 /* Support debugging kernel virtual memory images. */
220 bsd_kvm_add_target (ppcfbsd_supply_pcb
);