GDB (xrefs)

/tmp/gdb-8.1/gdb/ppc-nbsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for NetBSD/powerpc.
2
3 Copyright (C) 2002-2018 Free Software Foundation, Inc.
4
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23
24 #include <sys/types.h>
25 #include <sys/ptrace.h>
26 #include <machine/reg.h>
27 #include <machine/frame.h>
28 #include <machine/pcb.h>
29
30 #include "gdbcore.h"
31 #include "inferior.h"
32 #include "regcache.h"
33
34 #include "ppc-tdep.h"
35 #include "ppc-nbsd-tdep.h"
36 #include "bsd-kvm.h"
37 #include "inf-ptrace.h"
38
39 /* Returns true if PT_GETREGS fetches this register. */
40
41 static int
42 getregs_supplies (struct gdbarch *gdbarch, int regnum)
43 {
44 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
45
46 return ((regnum >= tdep->ppc_gp0_regnum
47 && regnum < tdep->ppc_gp0_regnum + ppc_num_gprs)
48 || regnum == tdep->ppc_lr_regnum
49 || regnum == tdep->ppc_cr_regnum
50 || regnum == tdep->ppc_xer_regnum
51 || regnum == tdep->ppc_ctr_regnum
52 || regnum == gdbarch_pc_regnum (gdbarch));
53 }
54
55 /* Like above, but for PT_GETFPREGS. */
56
57 static int
58 getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
59 {
60 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
61
62 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
63 point registers. Traditionally, GDB's register set has still
64 listed the floating point registers for such machines, so this
65 code is harmless. However, the new E500 port actually omits the
66 floating point registers entirely from the register set --- they
67 don't even have register numbers assigned to them.
68
69 It's not clear to me how best to update this code, so this assert
70 will alert the first person to encounter the NetBSD/E500
71 combination to the problem. */
72 gdb_assert (ppc_floating_point_unit_p (gdbarch));
73
74 return ((regnum >= tdep->ppc_fp0_regnum
75 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs)
76 || regnum == tdep->ppc_fpscr_regnum);
77 }
78
79 static void
80 ppcnbsd_fetch_inferior_registers (struct target_ops *ops,
81 struct regcache *regcache, int regnum)
82 {
83 struct gdbarch *gdbarch = regcache->arch ();
84 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
85
86 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
87 {
88 struct reg regs;
89
90 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
91 perror_with_name (_("Couldn't get registers"));
92
93 ppc_supply_gregset (&ppcnbsd_gregset, regcache,
94 regnum, &regs, sizeof regs);
95 }
96
97 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
98 {
99 struct fpreg fpregs;
100
101 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
102 perror_with_name (_("Couldn't get FP registers"));
103
104 ppc_supply_fpregset (&ppcnbsd_fpregset, regcache,
105 regnum, &fpregs, sizeof fpregs);
106 }
107 }
108
109 static void
110 ppcnbsd_store_inferior_registers (struct target_ops *ops,
111 struct regcache *regcache, int regnum)
112 {
113 struct gdbarch *gdbarch = regcache->arch ();
114 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
115
116 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
117 {
118 struct reg regs;
119
120 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
121 perror_with_name (_("Couldn't get registers"));
122
123 ppc_collect_gregset (&ppcnbsd_gregset, regcache,
124 regnum, &regs, sizeof regs);
125
126 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
127 perror_with_name (_("Couldn't write registers"));
128 }
129
130 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
131 {
132 struct fpreg fpregs;
133
134 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
135 perror_with_name (_("Couldn't get FP registers"));
136
137 ppc_collect_fpregset (&ppcnbsd_fpregset, regcache,
138 regnum, &fpregs, sizeof fpregs);
139
140 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
141 perror_with_name (_("Couldn't set FP registers"));
142 }
143 }
144
145 static int
146 ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
147 {
148 struct switchframe sf;
149 struct callframe cf;
150 struct gdbarch *gdbarch = regcache->arch ();
151 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
152 int i;
153
154 /* The stack pointer shouldn't be zero. */
155 if (pcb->pcb_sp == 0)
156 return 0;
157
158 read_memory (pcb->pcb_sp, (gdb_byte *)&sf, sizeof sf);
159 regcache_raw_supply (regcache, tdep->ppc_cr_regnum, &sf.cr);
160 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 2, &sf.fixreg2);
161 for (i = 0 ; i < 19 ; i++)
162 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 13 + i,
163 &sf.fixreg[i]);
164
165 read_memory(sf.sp, (gdb_byte *)&cf, sizeof(cf));
166 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 30, &cf.r30);
167 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 31, &cf.r31);
168 regcache_raw_supply (regcache, tdep->ppc_gp0_regnum + 1, &cf.sp);
169
170 read_memory(cf.sp, (gdb_byte *)&cf, sizeof(cf));
171 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr);
172 regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch), &cf.lr);
173
174 return 1;
175 }
176
177 void
178 _initialize_ppcnbsd_nat (void)
179 {
180 struct target_ops *t;
181
182 /* Support debugging kernel virtual memory images. */
183 bsd_kvm_add_target (ppcnbsd_supply_pcb);
184
185 /* Add in local overrides. */
186 t = inf_ptrace_target ();
187 t->to_fetch_registers = ppcnbsd_fetch_inferior_registers;
188 t->to_store_registers = ppcnbsd_store_inferior_registers;
189 add_target (t);
190 }
gdbarch
Definition: gdbarch.c:127
add_target
void add_target(struct target_ops *t)
Definition: target.c:395
ptid_get_pid
int ptid_get_pid(const ptid_t &ptid)
Definition: ptid.c:47
pid
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:1824
gdbarch_tdep::ppc_lr_regnum
int ppc_lr_regnum
Definition: ppc-tdep.h:231
ppc_num_fprs
Definition: ppc-tdep.h:284
ppc_supply_fpregset
void ppc_supply_fpregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *fpregs, size_t len)
Definition: rs6000-tdep.c:561
gdbarch_tdep::ppc_fpscr_regnum
int ppc_fpscr_regnum
Definition: ppc-tdep.h:241
regcache_get_ptid
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
ppc-tdep.h
gdbarch_tdep
Definition: aarch64-tdep.h:55
_
#define _(String)
Definition: gdb_locale.h:35
ppc-nbsd-tdep.h
inf_ptrace_target
struct target_ops * inf_ptrace_target(void)
Definition: inf-ptrace.c:676
defs.h
gdbarch_tdep::ppc_cr_regnum
int ppc_cr_regnum
Definition: ppc-tdep.h:230
gdbarch_tdep
struct gdbarch_tdep * gdbarch_tdep(struct gdbarch *gdbarch)
Definition: gdbarch.c:1491
ptrace
PTRACE_TYPE_RET ptrace()
_initialize_ppcnbsd_nat
void _initialize_ppcnbsd_nat(void)
Definition: ppc-nbsd-nat.c:178
ppcnbsd_fpregset
const struct regset ppcnbsd_fpregset
Definition: ppc-nbsd-tdep.c:48
ppcnbsd_gregset
const struct regset ppcnbsd_gregset
Definition: ppc-nbsd-tdep.c:42
ppcnbsd_fetch_inferior_registers
static void ppcnbsd_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: ppc-nbsd-nat.c:80
ppc_collect_gregset
void ppc_collect_gregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *gregs, size_t len)
Definition: rs6000-tdep.c:675
inf-ptrace.h
target_ops
Definition: target.h:412
regcache.h
bsd-kvm.h
gdbarch_tdep::ppc_gp0_regnum
int ppc_gp0_regnum
Definition: ppc-tdep.h:227
inferior.h
ppcnbsd_store_inferior_registers
static void ppcnbsd_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regnum)
Definition: ppc-nbsd-nat.c:110
ppc_collect_fpregset
void ppc_collect_fpregset(const struct regset *regset, const struct regcache *regcache, int regnum, void *fpregs, size_t len)
Definition: rs6000-tdep.c:726
regnum
int regnum
Definition: aarch64-tdep.c:77
read_memory
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:258
reg
Definition: regdef.h:22
gdb_assert
#define gdb_assert(expr)
Definition: gdb_assert.h:32
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
gdbarch_tdep::ppc_ctr_regnum
int ppc_ctr_regnum
Definition: ppc-tdep.h:232
target_ops::to_fetch_registers
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:457
perror_with_name
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
gdbcore.h
getfpregs_supplies
static int getfpregs_supplies(struct gdbarch *gdbarch, int regnum)
Definition: ppc-nbsd-nat.c:58
gdbarch_tdep::ppc_xer_regnum
int ppc_xer_regnum
Definition: ppc-tdep.h:233
regcache::arch
gdbarch * arch() const
Definition: regcache.c:221
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
regcache
Definition: regcache.h:232
gdbarch_pc_regnum
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2163
PTRACE_TYPE_ARG3
#define PTRACE_TYPE_ARG3
Definition: config.h:642
bsd_kvm_add_target
void bsd_kvm_add_target(int(*supply_pcb)(struct regcache *, struct pcb *))
Definition: bsd-kvm.c:354
getregs_supplies
static int getregs_supplies(struct gdbarch *gdbarch, int regnum)
Definition: ppc-nbsd-nat.c:42
ppcnbsd_supply_pcb
static int ppcnbsd_supply_pcb(struct regcache *regcache, struct pcb *pcb)
Definition: ppc-nbsd-nat.c:146
target_ops::to_store_registers
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459
ppc_floating_point_unit_p
int ppc_floating_point_unit_p(struct gdbarch *gdbarch)
Definition: rs6000-tdep.c:218
gdbarch_tdep::ppc_fp0_regnum
int ppc_fp0_regnum
Definition: ppc-tdep.h:240
ppc_supply_gregset
void ppc_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t len)
Definition: rs6000-tdep.c:511
ppc_num_gprs
Definition: ppc-tdep.h:283