Remove unnecessary function prototypes.
[deliverable/binutils-gdb.git] / gdb / ppc-nbsd-nat.c
CommitLineData
def18405
MK
1/* Native-dependent code for NetBSD/powerpc.
2
61baf725 3 Copyright (C) 2002-2017 Free Software Foundation, Inc.
def18405 4
485721b1 5 Contributed by Wasabi Systems, Inc.
e42180d7
C
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
e42180d7
C
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e42180d7 21
0baeab03
PA
22#include "defs.h"
23
e42180d7
C
24#include <sys/types.h>
25#include <sys/ptrace.h>
26#include <machine/reg.h>
69e9e646
NW
27#include <machine/frame.h>
28#include <machine/pcb.h>
e42180d7 29
69e9e646 30#include "gdbcore.h"
def18405 31#include "inferior.h"
69e9e646 32#include "regcache.h"
def18405 33
485721b1 34#include "ppc-tdep.h"
03b62bbb 35#include "ppc-nbsd-tdep.h"
def18405 36#include "bsd-kvm.h"
5bf970f9
AC
37#include "inf-ptrace.h"
38
485721b1 39/* Returns true if PT_GETREGS fetches this register. */
def18405 40
485721b1 41static int
206988c4 42getregs_supplies (struct gdbarch *gdbarch, int regnum)
e42180d7 43{
206988c4 44 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
485721b1 45
def18405
MK
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
206988c4 52 || regnum == gdbarch_pc_regnum (gdbarch));
e42180d7
C
53}
54
485721b1 55/* Like above, but for PT_GETFPREGS. */
def18405 56
485721b1 57static int
206988c4 58getfpregs_supplies (struct gdbarch *gdbarch, int regnum)
e42180d7 59{
206988c4 60 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e42180d7 61
383f0f5b
JB
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. */
206988c4 72 gdb_assert (ppc_floating_point_unit_p (gdbarch));
383f0f5b 73
def18405
MK
74 return ((regnum >= tdep->ppc_fp0_regnum
75 && regnum < tdep->ppc_fp0_regnum + ppc_num_fprs)
76 || regnum == tdep->ppc_fpscr_regnum);
485721b1 77}
e42180d7 78
5bf970f9 79static void
28439f5e
PA
80ppcnbsd_fetch_inferior_registers (struct target_ops *ops,
81 struct regcache *regcache, int regnum)
e42180d7 82{
206988c4 83 struct gdbarch *gdbarch = get_regcache_arch (regcache);
bcc0c096 84 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
206988c4
MD
85
86 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
485721b1
JT
87 {
88 struct reg regs;
89
bcc0c096 90 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 91 perror_with_name (_("Couldn't get registers"));
485721b1 92
56be3814 93 ppc_supply_gregset (&ppcnbsd_gregset, regcache,
def18405 94 regnum, &regs, sizeof regs);
485721b1
JT
95 }
96
206988c4 97 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
485721b1
JT
98 {
99 struct fpreg fpregs;
100
bcc0c096 101 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
e2e0b3e5 102 perror_with_name (_("Couldn't get FP registers"));
485721b1 103
56be3814 104 ppc_supply_fpregset (&ppcnbsd_fpregset, regcache,
def18405 105 regnum, &fpregs, sizeof fpregs);
485721b1 106 }
e42180d7
C
107}
108
5bf970f9 109static void
28439f5e
PA
110ppcnbsd_store_inferior_registers (struct target_ops *ops,
111 struct regcache *regcache, int regnum)
e42180d7 112{
206988c4 113 struct gdbarch *gdbarch = get_regcache_arch (regcache);
bcc0c096 114 pid_t pid = ptid_get_pid (regcache_get_ptid (regcache));
206988c4
MD
115
116 if (regnum == -1 || getregs_supplies (gdbarch, regnum))
485721b1
JT
117 {
118 struct reg regs;
119
bcc0c096 120 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 121 perror_with_name (_("Couldn't get registers"));
485721b1 122
56be3814 123 ppc_collect_gregset (&ppcnbsd_gregset, regcache,
def18405 124 regnum, &regs, sizeof regs);
485721b1 125
bcc0c096 126 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
e2e0b3e5 127 perror_with_name (_("Couldn't write registers"));
485721b1
JT
128 }
129
206988c4 130 if (regnum == -1 || getfpregs_supplies (gdbarch, regnum))
485721b1
JT
131 {
132 struct fpreg fpregs;
133
bcc0c096 134 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
e2e0b3e5 135 perror_with_name (_("Couldn't get FP registers"));
485721b1 136
56be3814 137 ppc_collect_fpregset (&ppcnbsd_fpregset, regcache,
def18405
MK
138 regnum, &fpregs, sizeof fpregs);
139
bcc0c096 140 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
e2e0b3e5 141 perror_with_name (_("Couldn't set FP registers"));
485721b1 142 }
e42180d7 143}
69e9e646
NW
144
145static int
146ppcnbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
147{
148 struct switchframe sf;
149 struct callframe cf;
40a6adc1
MD
150 struct gdbarch *gdbarch = get_regcache_arch (regcache);
151 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
69e9e646
NW
152 int i;
153
154 /* The stack pointer shouldn't be zero. */
155 if (pcb->pcb_sp == 0)
156 return 0;
157
def18405 158 read_memory (pcb->pcb_sp, (gdb_byte *)&sf, sizeof sf);
69e9e646
NW
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
def18405 165 read_memory(sf.sp, (gdb_byte *)&cf, sizeof(cf));
69e9e646
NW
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
def18405 170 read_memory(cf.sp, (gdb_byte *)&cf, sizeof(cf));
69e9e646 171 regcache_raw_supply (regcache, tdep->ppc_lr_regnum, &cf.lr);
40a6adc1 172 regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch), &cf.lr);
69e9e646
NW
173
174 return 1;
175}
176
69e9e646
NW
177void
178_initialize_ppcnbsd_nat (void)
179{
5bf970f9 180 struct target_ops *t;
def18405 181
69e9e646
NW
182 /* Support debugging kernel virtual memory images. */
183 bsd_kvm_add_target (ppcnbsd_supply_pcb);
def18405 184
5bf970f9
AC
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);
69e9e646 190}
This page took 1.842013 seconds and 4 git commands to generate.