GDB (xrefs)
Loading...
Searching...
No Matches
ppc-fbsd-nat.c
Go to the documentation of this file.
1/* Native-dependent code for PowerPC's running FreeBSD, for GDB.
2
3 Copyright (C) 2013-2023 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 <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>
32
33#include "fbsd-nat.h"
34#include "gregset.h"
35#include "ppc-tdep.h"
36#include "ppc-fbsd-tdep.h"
37#include "inf-ptrace.h"
38#include "bsd-kvm.h"
39
41{
42 void fetch_registers (struct regcache *, int) override;
43 void store_registers (struct regcache *, int) override;
44};
45
47
48/* Fill GDB's register array with the general-purpose register values
49 in *GREGSETP. */
50
51void
53{
54 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
55
56 ppc_supply_gregset (regset, regcache, -1, gregsetp, sizeof (*gregsetp));
57}
58
59/* Fill register REGNO (if a gpr) in *GREGSETP with the value in GDB's
60 register array. If REGNO is -1 do it for all registers. */
61
62void
64 gdb_gregset_t *gregsetp, int regno)
65{
66 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
67
68 if (regno == -1)
69 memset (gregsetp, 0, sizeof (*gregsetp));
70 ppc_collect_gregset (regset, regcache, regno, gregsetp, sizeof (*gregsetp));
71}
72
73/* Fill GDB's register array with the floating-point register values
74 in *FPREGSETP. */
75
76void
77supply_fpregset (struct regcache *regcache, const gdb_fpregset_t * fpregsetp)
78{
79 const struct regset *regset = ppc_fbsd_fpregset ();
80
82 fpregsetp, sizeof (*fpregsetp));
83}
84
85/* Fill register REGNO in *FGREGSETP with the value in GDB's
86 register array. If REGNO is -1 do it for all registers. */
87
88void
90 gdb_fpregset_t *fpregsetp, int regno)
91{
92 const struct regset *regset = ppc_fbsd_fpregset ();
93
95 fpregsetp, sizeof (*fpregsetp));
96}
97
98/* Returns true if PT_GETFPREGS fetches this register. */
99
100static int
102{
103 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
104
105 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
106 point registers. Traditionally, GDB's register set has still
107 listed the floating point registers for such machines, so this
108 code is harmless. However, the new E500 port actually omits the
109 floating point registers entirely from the register set --- they
110 don't even have register numbers assigned to them.
111
112 It's not clear to me how best to update this code, so this assert
113 will alert the first person to encounter the NetBSD/E500
114 combination to the problem. */
115
116 gdb_assert (ppc_floating_point_unit_p (gdbarch));
117
118 return ((regno >= tdep->ppc_fp0_regnum
119 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
120 || regno == tdep->ppc_fpscr_regnum);
121}
122
123/* Fetch register REGNO from the child process. If REGNO is -1, do it
124 for all registers. */
125
126void
128{
129 gdb_gregset_t regs;
130 pid_t pid = regcache->ptid ().lwp ();
131
132 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
133 perror_with_name (_("Couldn't get registers"));
134
135 supply_gregset (regcache, &regs);
136
137 if (regno == -1 || getfpregs_supplies (regcache->arch (), regno))
138 {
139 const struct regset *fpregset = ppc_fbsd_fpregset ();
140 gdb_fpregset_t fpregs;
141
142 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
143 perror_with_name (_("Couldn't get FP registers"));
144
145 ppc_supply_fpregset (fpregset, regcache, regno, &fpregs, sizeof fpregs);
146 }
147}
148
149/* Store register REGNO back into the child process. If REGNO is -1,
150 do this for all registers. */
151
152void
154{
155 gdb_gregset_t regs;
156 pid_t pid = regcache->ptid ().lwp ();
157
158 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
159 perror_with_name (_("Couldn't get registers"));
160
161 fill_gregset (regcache, &regs, regno);
162
163 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
164 perror_with_name (_("Couldn't write registers"));
165
166 if (regno == -1 || getfpregs_supplies (regcache->arch (), regno))
167 {
168 gdb_fpregset_t fpregs;
169
170 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
171 perror_with_name (_("Couldn't get FP registers"));
172
173 fill_fpregset (regcache, &fpregs, regno);
174
175 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
176 perror_with_name (_("Couldn't set FP registers"));
177 }
178}
179
180/* Architecture specific function that reconstructs the
181 register state from PCB (Process Control Block) and supplies it
182 to REGCACHE. */
183
184static int
185ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
186{
187 struct gdbarch *gdbarch = regcache->arch ();
188 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
189 int i, regnum;
190
191 /* The stack pointer shouldn't be zero. */
192 if (pcb->pcb_sp == 0)
193 return 0;
194
195 regcache->raw_supply (gdbarch_sp_regnum (gdbarch), &pcb->pcb_sp);
196 regcache->raw_supply (tdep->ppc_cr_regnum, &pcb->pcb_cr);
197 regcache->raw_supply (tdep->ppc_lr_regnum, &pcb->pcb_lr);
198 for (i = 0, regnum = tdep->ppc_gp0_regnum + 14; i < 20; i++, regnum++)
199 regcache->raw_supply (regnum, &pcb->pcb_context[i]);
200
201 return 1;
202}
203
205void
207{
209
210 /* Support debugging kernel virtual memory images. */
212}
int regnum
void bsd_kvm_add_target(int(*supply_pcb)(struct regcache *, struct pcb *))
Definition bsd-kvm.c:380
bool fetch_register_set(struct regcache *regcache, int regnum, int fetch_op, const struct regset *regset, int regbase, void *regs, size_t size)
Definition fbsd-nat.c:2336
gdbarch * arch() const
Definition regcache.c:231
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
ptid_t ptid() const
Definition regcache.h:408
#define ptrace(request, pid, addr, data)
Definition gdb_ptrace.h:141
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2037
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1791
GDB_FPREGSET_T gdb_fpregset_t
Definition gregset.h:35
GDB_GREGSET_T gdb_gregset_t
Definition gregset.h:34
void add_inf_child_target(inf_child_target *target)
Definition inf-child.c:418
#define PTRACE_TYPE_ARG3
static ppc_fbsd_nat_target the_ppc_fbsd_nat_target
void supply_gregset(struct regcache *regcache, const gdb_gregset_t *gregsetp)
void fill_gregset(const struct regcache *regcache, gdb_gregset_t *gregsetp, int regno)
void supply_fpregset(struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
static int getfpregs_supplies(struct gdbarch *gdbarch, int regno)
void fill_fpregset(const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regno)
static int ppcfbsd_supply_pcb(struct regcache *regcache, struct pcb *pcb)
void _initialize_ppcfbsd_nat()
const struct regset * ppc_fbsd_gregset(int wordsize)
const struct regset * ppc_fbsd_fpregset(void)
void ppc_collect_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
void ppc_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
int ppc_floating_point_unit_p(struct gdbarch *gdbarch)
void ppc_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
@ ppc_num_fprs
Definition ppc-tdep.h:319
void ppc_collect_fpregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *fpregs, size_t len)
void store_registers(struct regcache *, int) override
void fetch_registers(struct regcache *, int) override